diff --git a/text/v2/gotext.go b/text/v2/gotext.go index 3445538e6..c471aed12 100644 --- a/text/v2/gotext.go +++ b/text/v2/gotext.go @@ -179,7 +179,7 @@ func MustParseTag(str string) Tag { // Metrics implements Face. func (g *GoTextFace) Metrics() Metrics { - scale := float64(g.SizeInPoints) / float64(g.Source.f.Font.Upem()) + scale := g.Source.scale(g.SizeInPoints) var m Metrics if h, ok := g.Source.f.FontHExtents(); ok { diff --git a/text/v2/gotextfacesource.go b/text/v2/gotextfacesource.go index 5047a8f1e..19f900aaa 100644 --- a/text/v2/gotextfacesource.go +++ b/text/v2/gotextfacesource.go @@ -178,7 +178,7 @@ func (g *GoTextFaceSource) shape(text string, face *GoTextFace) (shaping.Output, } scaledSegs := make([]api.Segment, len(segs)) - scale := fixed26_6ToFloat32(out.Size) / float32(out.Face.Font.Upem()) + scale := float32(g.scale(fixed26_6ToFloat64(out.Size))) for i, seg := range segs { scaledSegs[i] = seg for j := range seg.Args { @@ -214,3 +214,7 @@ func (g *GoTextFaceSource) shape(text string, face *GoTextFace) (shaping.Output, return out, gs } + +func (g *GoTextFaceSource) scale(sizeInPoints float64) float64 { + return sizeInPoints / float64(g.f.Upem()) +}