Add method to parse font from byte array
This commit is contained in:
parent
4dc34561c6
commit
2da7851151
@ -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
|
||||||
}
|
}
|
||||||
|
8
util.go
8
util.go
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user