diff --git a/draw2dbase/text.go b/draw2dbase/text.go index 2a5f04e..dd05889 100644 --- a/draw2dbase/text.go +++ b/draw2dbase/text.go @@ -29,7 +29,6 @@ func loadCurrentFont(gc draw2d.GraphicContext) (*truetype.Font, error) { } gc.SetFont(font) gc.SetFontSize(gc.GetFontSize()) - recalc(gc) return font, nil } @@ -116,9 +115,9 @@ func GetStringBounds(gc draw2d.GraphicContext, s string) (left, top, right, bott return left, top, right, bottom } -// recalc recalculates scale and bounds values from the font size, screen +// Recalc recalculates scale and bounds values from the font size, screen // resolution and font metrics, and invalidates the glyph cache. -func recalc(gc draw2d.GraphicContext) { +func Recalc(gc draw2d.GraphicContext) { gc.SetScale(gc.GetFontSize() * float64(gc.GetDPI()) * (64.0 / 72.0)) } diff --git a/draw2dgl/gc.go b/draw2dgl/gc.go index aab3cb0..97aea20 100644 --- a/draw2dgl/gc.go +++ b/draw2dgl/gc.go @@ -173,6 +173,7 @@ func (gc *GraphicContext) StrokeStringAt(text string, x, y float64) (width float func (gc *GraphicContext) SetDPI(dpi int) { gc.DPI = dpi + draw2dbase.Recalc(gc) } func (gc *GraphicContext) GetDPI() int { @@ -182,6 +183,7 @@ func (gc *GraphicContext) GetDPI() int { // SetFontSize sets the font size in points (as in ``a 12 point font''). func (gc *GraphicContext) SetFontSize(fontSize float64) { gc.Current.FontSize = fontSize + draw2dbase.Recalc(gc) } //TODO diff --git a/draw2dimg/ftgc.go b/draw2dimg/ftgc.go index 470adbc..1611c9c 100644 --- a/draw2dimg/ftgc.go +++ b/draw2dimg/ftgc.go @@ -145,6 +145,7 @@ func (gc *GraphicContext) StrokeStringAt(text string, x, y float64) (cursor floa func (gc *GraphicContext) SetDPI(dpi int) { gc.DPI = dpi + draw2dbase.Recalc(gc) } func (gc *GraphicContext) GetDPI() int { @@ -154,6 +155,7 @@ func (gc *GraphicContext) GetDPI() int { // SetFontSize sets the font size in points (as in ``a 12 point font''). func (gc *GraphicContext) SetFontSize(fontSize float64) { gc.Current.FontSize = fontSize + draw2dbase.Recalc(gc) } func (gc *GraphicContext) paint(rasterizer *raster.Rasterizer, color color.Color) {