Skip to content

Commit

Permalink
Merge pull request #330 from Seanld/public-glyphs
Browse files Browse the repository at this point in the history
Make FontFace's glyphs public
  • Loading branch information
tdewolff authored Dec 23, 2024
2 parents 95f003d + e27b7eb commit a4892b4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions font.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,14 @@ func (face *FontFace) LineHeight() float64 {
return metrics.Ascent + metrics.Descent
}

func (face *FontFace) Glyphs(s string) []text.Glyph {
ppem := face.PPEM(DefaultResolution)
return face.Font.shaper.Shape(s, ppem, face.Direction, face.Script, face.Language, face.Font.features, face.Font.variations)
}

// TextWidth returns the width of a given string in millimeters.
func (face *FontFace) TextWidth(s string) float64 {
ppem := face.PPEM(DefaultResolution)
glyphs := face.Font.shaper.Shape(s, ppem, face.Direction, face.Script, face.Language, face.Font.features, face.Font.variations)
return face.textWidth(glyphs)
return face.textWidth(face.Glyphs(s))
}

func (face *FontFace) textWidth(glyphs []text.Glyph) float64 {
Expand Down Expand Up @@ -740,8 +743,7 @@ func (face *FontFace) Decorate(width float64) *Path {
// ToPath converts a string to its glyph paths.
func (face *FontFace) ToPath(s string) (*Path, float64, error) {
ppem := face.PPEM(DefaultResolution)
glyphs := face.Font.shaper.Shape(s, ppem, face.Direction, face.Script, face.Language, face.Font.features, face.Font.variations)
return face.toPath(glyphs, ppem)
return face.toPath(face.Glyphs(s), ppem)
}

func (face *FontFace) toPath(glyphs []text.Glyph, ppem uint16) (*Path, float64, error) {
Expand Down

0 comments on commit a4892b4

Please sign in to comment.