text/v2: refactoring

This commit is contained in:
Hajime Hoshi 2023-11-15 12:34:02 +09:00
parent 5354ccc44f
commit 4694b78d54
2 changed files with 6 additions and 2 deletions

View File

@ -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 {

View File

@ -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())
}