fix draw2dgl compil' error

This commit is contained in:
llgcode 2017-12-11 11:02:06 +01:00
parent f3e35015aa
commit 647da9ceaa
1 changed files with 13 additions and 11 deletions

View File

@ -1,7 +1,6 @@
package draw2dgl package draw2dgl
import ( import (
"errors"
"image" "image"
"image/color" "image/color"
"image/draw" "image/draw"
@ -125,6 +124,8 @@ type GraphicContext struct {
painter *Painter painter *Painter
fillRasterizer *raster.Rasterizer fillRasterizer *raster.Rasterizer
strokeRasterizer *raster.Rasterizer strokeRasterizer *raster.Rasterizer
FontCache draw2d.FontCache
glyphCache draw2dbase.GlyphCache
glyphBuf *truetype.GlyphBuf glyphBuf *truetype.GlyphBuf
DPI int DPI int
} }
@ -136,6 +137,8 @@ func NewGraphicContext(width, height int) *GraphicContext {
NewPainter(), NewPainter(),
raster.NewRasterizer(width, height), raster.NewRasterizer(width, height),
raster.NewRasterizer(width, height), raster.NewRasterizer(width, height),
draw2d.GetGlobalFontCache(),
draw2dbase.NewGlyphCache(),
&truetype.GlyphBuf{}, &truetype.GlyphBuf{},
92, 92,
} }
@ -143,16 +146,15 @@ func NewGraphicContext(width, height int) *GraphicContext {
} }
func (gc *GraphicContext) loadCurrentFont() (*truetype.Font, error) { func (gc *GraphicContext) loadCurrentFont() (*truetype.Font, error) {
font := draw2d.GetFont(gc.Current.FontData) font, err := gc.FontCache.Load(gc.Current.FontData)
if font == nil { if err != nil {
font = draw2d.GetFont(draw2dbase.DefaultFontData) font, err = gc.FontCache.Load(draw2dbase.DefaultFontData)
} }
if font == nil { if font != nil {
return nil, errors.New("No font set, and no default font available.") gc.SetFont(font)
gc.SetFontSize(gc.Current.FontSize)
} }
gc.SetFont(font) return font, err
gc.SetFontSize(gc.Current.FontSize)
return font, nil
} }
func (gc *GraphicContext) drawGlyph(glyph truetype.Index, dx, dy float64) error { 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 { if hasPrev {
x += fUnitsToFloat64(f.Kern(fixed.Int26_6(gc.Current.Scale), prev, index)) 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) x += glyph.Fill(gc, x, y)
prev, hasPrev = index, true prev, hasPrev = index, true
} }
@ -283,7 +285,7 @@ func (gc *GraphicContext) StrokeStringAt(text string, x, y float64) (width float
if hasPrev { if hasPrev {
x += fUnitsToFloat64(f.Kern(fixed.Int26_6(gc.Current.Scale), prev, index)) 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) x += glyph.Stroke(gc, x, y)
prev, hasPrev = index, true prev, hasPrev = index, true
} }