Merge pull request #146 from piotrkowalczuk/get-font-name-proper-font-size-serialization

GetFontName serialize font size properly
thanks @piotrkowalczuk
This commit is contained in:
llgcode 2018-08-25 15:34:48 +02:00 committed by GitHub
commit f52c8a71af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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