diff --git a/context.go b/context.go index 1ddb09f..8babfbb 100644 --- a/context.go +++ b/context.go @@ -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 } diff --git a/util.go b/util.go index 0806235..0d9ef4b 100644 --- a/util.go +++ b/util.go @@ -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