Add method to parse font from byte array

This commit is contained in:
Tom Pethtel 2020-01-18 22:20:21 -05:00
parent 4dc34561c6
commit 2da7851151
2 changed files with 17 additions and 0 deletions

View File

@ -703,6 +703,15 @@ func (dc *Context) LoadFontFace(path string, points float64) error {
return err
}
func (dc *Context) LoadFontFaceFromBytes(fontData []byte, points float64) error {
face, err := LoadFontFaceFromBytes(fontData, points)
if err == nil {
dc.fontFace = face
dc.fontHeight = points * 72 / 96
}
return err
}
func (dc *Context) FontHeight() float64 {
return dc.fontHeight
}

View File

@ -134,6 +134,14 @@ func LoadFontFace(path string, points float64) (font.Face, error) {
if err != nil {
return nil, err
}
face, err := LoadFontFaceFromBytes(fontBytes, points)
if err != nil {
return nil, err
}
return face, nil
}
func LoadFontFaceFromBytes(fontBytes []byte, points float64) (font.Face, error) {
f, err := truetype.Parse(fontBytes)
if err != nil {
return nil, err