From e27b7eb187a87b0a2c1e945e7941b1f9dc5561dc Mon Sep 17 00:00:00 2001 From: Sean Wilkerson Date: Mon, 23 Dec 2024 13:45:07 -0700 Subject: [PATCH] Make FontFace's glyphs public --- font.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/font.go b/font.go index aff21fae..d090ad42 100644 --- a/font.go +++ b/font.go @@ -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 { @@ -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) {