Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down