aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/llgcode/draw2d/draw2dgl/gc.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-01-01 22:45:26 +0100
committerDimitri Sokolyuk <demon@dim13.org>2018-01-01 22:45:26 +0100
commit16df0bea5fe8ce0a4ea871d409f589b298567a97 (patch)
treef2f18a2c6773d86a895d075bf8f1a374d48406c4 /vendor/github.com/llgcode/draw2d/draw2dgl/gc.go
parent500caaeda74dd9c660279036293f4b2997cf0b03 (diff)
Update vendor
Diffstat (limited to 'vendor/github.com/llgcode/draw2d/draw2dgl/gc.go')
-rw-r--r--vendor/github.com/llgcode/draw2d/draw2dgl/gc.go26
1 files changed, 14 insertions, 12 deletions
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
}