diff --git a/text/v2/gotext.go b/text/v2/gotext.go index c99bc8dff..7a8351e67 100644 --- a/text/v2/gotext.go +++ b/text/v2/gotext.go @@ -332,7 +332,7 @@ func (g *GoTextFace) glyphImage(glyph glyph, origin fixed.Point26_6) (*ebiten.Im origin.Y = adjustGranularity(origin.Y, g) } - b := segmentsToBounds(glyph.scaledSegments) + b := glyph.bounds subpixelOffset := fixed.Point26_6{ X: (origin.X + b.Min.X) & ((1 << 6) - 1), Y: (origin.Y + b.Min.Y) & ((1 << 6) - 1), diff --git a/text/v2/gotextfacesource.go b/text/v2/gotextfacesource.go index 58051eb9f..92cd96150 100644 --- a/text/v2/gotextfacesource.go +++ b/text/v2/gotextfacesource.go @@ -24,6 +24,7 @@ import ( "github.com/go-text/typesetting/language" "github.com/go-text/typesetting/opentype/api" "github.com/go-text/typesetting/shaping" + "golang.org/x/image/math/fixed" ) type goTextOutputCacheKey struct { @@ -41,6 +42,7 @@ type glyph struct { startIndex int endIndex int scaledSegments []api.Segment + bounds fixed.Rectangle26_6 } type goTextOutputCacheValue struct { @@ -193,6 +195,7 @@ func (g *GoTextFaceSource) shape(text string, face *GoTextFace) (shaping.Output, startIndex: indices[gl.ClusterIndex], endIndex: indices[gl.ClusterIndex+gl.RuneCount], scaledSegments: scaledSegs, + bounds: segmentsToBounds(scaledSegs), } } g.outputCache[key] = &goTextOutputCacheValue{