From 16df0bea5fe8ce0a4ea871d409f589b298567a97 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 1 Jan 2018 22:45:26 +0100 Subject: Update vendor --- vendor/github.com/llgcode/draw2d/draw2dgl/gc.go | 26 +++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'vendor/github.com/llgcode/draw2d/draw2dgl/gc.go') diff --git a/vendor/github.com/llgcode/draw2d/draw2dgl/gc.go b/vendor/github.com/llgcode/draw2d/draw2dgl/gc.go index d512ccc..7253170 100644 --- a/vendor/github.com/llgcode/draw2d/draw2dgl/gc.go +++ b/vendor/github.com/llgcode/draw2d/draw2dgl/gc.go @@ -1,7 +1,6 @@ package draw2dgl import ( - "errors" "image" "image/color" "image/draw" @@ -125,8 +124,10 @@ type GraphicContext struct { painter *Painter fillRasterizer *raster.Rasterizer strokeRasterizer *raster.Rasterizer + FontCache draw2d.FontCache + glyphCache draw2dbase.GlyphCache glyphBuf *truetype.GlyphBuf - DPI int + DPI int } // NewGraphicContext creates a new Graphic context from an image. @@ -136,6 +137,8 @@ func NewGraphicContext(width, height int) *GraphicContext { NewPainter(), raster.NewRasterizer(width, height), raster.NewRasterizer(width, height), + draw2d.GetGlobalFontCache(), + draw2dbase.NewGlyphCache(), &truetype.GlyphBuf{}, 92, } @@ -143,16 +146,15 @@ func NewGraphicContext(width, height int) *GraphicContext { } 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 } func (gc *GraphicContext) drawGlyph(glyph truetype.Index, dx, dy float64) error { @@ -217,7 +219,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 } @@ -283,7 +285,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 } -- cgit v1.2.3