add Painter Arg
This commit is contained in:
parent
fda5c8e713
commit
f7dc650faa
4 changed files with 24 additions and 6 deletions
|
@ -39,8 +39,6 @@ func NewGraphicContext(img draw.Image) *ImageGraphicContext {
|
|||
switch selectImage := img.(type) {
|
||||
case *image.RGBA:
|
||||
painter = raster.NewRGBAPainter(selectImage)
|
||||
//case *image.NRGBA:
|
||||
// painter = NewNRGBAPainter(selectImage)
|
||||
default:
|
||||
panic("Image type not supported")
|
||||
}
|
||||
|
@ -62,6 +60,26 @@ func NewGraphicContext(img draw.Image) *ImageGraphicContext {
|
|||
return gc
|
||||
}
|
||||
|
||||
// Create a new Graphic context from an image and a Painter (see Freetype-go)
|
||||
func NewGraphicContextWithPainter(img draw.Image, painter Painter) *ImageGraphicContext {
|
||||
width, height := img.Bounds().Dx(), img.Bounds().Dy()
|
||||
dpi := 92
|
||||
ftContext := freetype.NewContext()
|
||||
ftContext.SetDPI(dpi)
|
||||
ftContext.SetClip(img.Bounds())
|
||||
ftContext.SetDst(img)
|
||||
gc := &ImageGraphicContext{
|
||||
NewStackGraphicContext(),
|
||||
img,
|
||||
painter,
|
||||
raster.NewRasterizer(width, height),
|
||||
raster.NewRasterizer(width, height),
|
||||
ftContext,
|
||||
dpi,
|
||||
}
|
||||
return gc
|
||||
}
|
||||
|
||||
func (gc *ImageGraphicContext) SetDPI(dpi int) {
|
||||
gc.DPI = dpi
|
||||
gc.freetype.SetDPI(dpi)
|
||||
|
|
Loading…
Reference in a new issue