Merge pull request #1 from TomPethtel/feature/bits-and-bytes

Add method to parse font from byte array
This commit is contained in:
Tom Pethtel 2020-01-18 22:21:01 -05:00 committed by GitHub
commit 47a8d5a4f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 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 { func (dc *Context) FontHeight() float64 {
return dc.fontHeight return dc.fontHeight
} }

View File

@ -134,6 +134,14 @@ func LoadFontFace(path string, points float64) (font.Face, error) {
if err != nil { if err != nil {
return nil, err 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) f, err := truetype.Parse(fontBytes)
if err != nil { if err != nil {
return nil, err return nil, err