aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/llgcode/draw2d/draw2dimg/ftgc.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/llgcode/draw2d/draw2dimg/ftgc.go')
-rw-r--r--vendor/github.com/llgcode/draw2d/draw2dimg/ftgc.go24
1 files changed, 13 insertions, 11 deletions
diff --git a/vendor/github.com/llgcode/draw2d/draw2dimg/ftgc.go b/vendor/github.com/llgcode/draw2d/draw2dimg/ftgc.go
index abaf7e5..c07e1da 100644
--- a/vendor/github.com/llgcode/draw2d/draw2dimg/ftgc.go
+++ b/vendor/github.com/llgcode/draw2d/draw2dimg/ftgc.go
@@ -4,7 +4,6 @@
package draw2dimg
import (
- "errors"
"image"
"image/color"
"log"
@@ -35,6 +34,8 @@ type GraphicContext struct {
painter Painter
fillRasterizer *raster.Rasterizer
strokeRasterizer *raster.Rasterizer
+ FontCache draw2d.FontCache
+ glyphCache draw2dbase.GlyphCache
glyphBuf *truetype.GlyphBuf
DPI int
}
@@ -74,6 +75,8 @@ func NewGraphicContextWithPainter(img draw.Image, painter Painter) *GraphicConte
painter,
raster.NewRasterizer(width, height),
raster.NewRasterizer(width, height),
+ draw2d.GetGlobalFontCache(),
+ draw2dbase.NewGlyphCache(),
&truetype.GlyphBuf{},
dpi,
}
@@ -136,7 +139,7 @@ func (gc *GraphicContext) FillStringAt(text string, x, y float64) (width float64
if hasPrev {
x += fUnitsToFloat64(f.Kern(fixed.Int26_6(gc.Current.Scale), prev, index))
}
- glyph := draw2dbase.FetchGlyph(gc, fontName, r)
+ glyph := gc.glyphCache.Fetch(gc, fontName, r)
x += glyph.Fill(gc, x, y)
prev, hasPrev = index, true
}
@@ -163,7 +166,7 @@ func (gc *GraphicContext) StrokeStringAt(text string, x, y float64) (width float
if hasPrev {
x += fUnitsToFloat64(f.Kern(fixed.Int26_6(gc.Current.Scale), prev, index))
}
- glyph := draw2dbase.FetchGlyph(gc, fontName, r)
+ glyph := gc.glyphCache.Fetch(gc, fontName, r)
x += glyph.Stroke(gc, x, y)
prev, hasPrev = index, true
}
@@ -171,16 +174,15 @@ func (gc *GraphicContext) StrokeStringAt(text string, x, y float64) (width float
}
func (gc *GraphicContext) loadCurrentFont() (*truetype.Font, error) {
- font := draw2d.GetFont(gc.Current.FontData)
- if font == nil {
- font = draw2d.GetFont(draw2dbase.DefaultFontData)
+ font, err := gc.FontCache.Load(gc.Current.FontData)
+ if err != nil {
+ font, err = gc.FontCache.Load(draw2dbase.DefaultFontData)
}
- if font == nil {
- return nil, errors.New("No font set, and no default font available.")
+ if font != nil {
+ gc.SetFont(font)
+ gc.SetFontSize(gc.Current.FontSize)
}
- gc.SetFont(font)
- gc.SetFontSize(gc.Current.FontSize)
- return font, nil
+ return font, err
}
// p is a truetype.Point measured in FUnits and positive Y going upwards.