Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to parse font from byte array #150

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
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