single GetFontName implementation that serialize font size properly

This commit is contained in:
Piotr Kowalczuk 2018-08-20 12:17:57 +02:00
parent 587a55234c
commit bdf3a69827
4 changed files with 11 additions and 13 deletions

2
.gitignore vendored
View File

@ -21,3 +21,5 @@ _test*
**/core*[0-9]
.private
go.sum

View File

@ -41,6 +41,13 @@ type ContextStack struct {
Previous *ContextStack
}
// GetFontName gets the current FontData with fontSize as a string
func (cs *ContextStack) GetFontName() string {
fontData := cs.FontData
return fmt.Sprintf("%s:%d:%d:%9.2f", fontData.Name, fontData.Family, fontData.Style, cs.FontSize)
}
/**
* Create a new Graphic context from an image
*/
@ -198,6 +205,5 @@ func (gc *StackGraphicContext) Restore() {
}
func (gc *StackGraphicContext) GetFontName() string {
fontData := gc.Current.FontData
return fmt.Sprintf("%s:%d:%d:%d", fontData.Name, fontData.Family, fontData.Style, gc.Current.FontSize)
return gc.Current.GetFontName()
}

View File

@ -4,8 +4,7 @@
package draw2dsvg
import (
"fmt"
"github.com/golang/freetype/truetype"
"github.com/golang/freetype/truetype"
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d/draw2dbase"
"golang.org/x/image/font"
@ -401,12 +400,3 @@ func (gc *GraphicContext) drawGlyph(glyph truetype.Index, dx, dy float64) error
func (gc *GraphicContext) recalc() {
gc.Current.Scale = gc.Current.FontSize * float64(gc.DPI) * (64.0 / 72.0)
}
///////////////////////////////////////
// TODO implement following methods (or remove if not neccesary)
// GetFontName gets the current FontData with fontSize as a string
func (gc *GraphicContext) GetFontName() string {
fontData := gc.Current.FontData
return fmt.Sprintf("%s:%d:%d:%d", fontData.Name, fontData.Family, fontData.Style, gc.Current.FontSize)
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB