all: update go-text

Unfortunately this adds a breaking change to (*GoTextFaceSource).UnsafeInternal.

Updates #3082
This commit is contained in:
Hajime Hoshi 2024-09-09 23:07:30 +09:00
parent 15dfb02f9f
commit e058bb6fd3
7 changed files with 74 additions and 72 deletions

2
go.mod
View File

@ -8,7 +8,7 @@ require (
github.com/ebitengine/oto/v3 v3.3.0-alpha.4 github.com/ebitengine/oto/v3 v3.3.0-alpha.4
github.com/ebitengine/purego v0.8.0-alpha.5 github.com/ebitengine/purego v0.8.0-alpha.5
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f
github.com/go-text/typesetting v0.1.1 github.com/go-text/typesetting v0.1.1-0.20240522210117-2c045476f496
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.5 github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.5
github.com/hajimehoshi/go-mp3 v0.3.4 github.com/hajimehoshi/go-mp3 v0.3.4
github.com/jakecoffman/cp v1.2.1 github.com/jakecoffman/cp v1.2.1

6
go.sum
View File

@ -8,9 +8,9 @@ github.com/ebitengine/purego v0.8.0-alpha.5 h1:M0+PSgsdVNczTB8ijX89HmYqCfb2HUuBE
github.com/ebitengine/purego v0.8.0-alpha.5/go.mod h1:SQ56/omnSL8DdaBSKswoBvsMjgaWQyxyeMtb48sOskI= github.com/ebitengine/purego v0.8.0-alpha.5/go.mod h1:SQ56/omnSL8DdaBSKswoBvsMjgaWQyxyeMtb48sOskI=
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f h1:ysqRe+lvUiL0dH5XzkH0Bz68bFMPJ4f5Si4L/HD9SGk= github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f h1:ysqRe+lvUiL0dH5XzkH0Bz68bFMPJ4f5Si4L/HD9SGk=
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f/go.mod h1:i/ebyRRv/IoHixuZ9bElZnXbmfoUVPGQpdsJ4sVuX38= github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f/go.mod h1:i/ebyRRv/IoHixuZ9bElZnXbmfoUVPGQpdsJ4sVuX38=
github.com/go-text/typesetting v0.1.1 h1:bGAesCuo85nXnEN5LmFMVGAGpGkCPtHrZLi//qD7EJo= github.com/go-text/typesetting v0.1.1-0.20240522210117-2c045476f496 h1:zgx3rOyOdRoA2GXWpfJkH7Zg248ookseRifdn9VSp5g=
github.com/go-text/typesetting v0.1.1/go.mod h1:d22AnmeKq/on0HNv73UFriMKc4Ez6EqZAofLhAzpSzI= github.com/go-text/typesetting v0.1.1-0.20240522210117-2c045476f496/go.mod h1:2+owI/sxa73XA581LAzVuEBZ3WEEV2pXeDswCH/3i1I=
github.com/go-text/typesetting-utils v0.0.0-20231211103740-d9332ae51f04 h1:zBx+p/W2aQYtNuyZNcTfinWvXBQwYtDfme051PR/lAY= github.com/go-text/typesetting-utils v0.0.0-20240317173224-1986cbe96c66 h1:GUrm65PQPlhFSKjLPGOZNPNxLCybjzjYBzjfoBGaDUY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.5 h1:gtIcN2INlD2qlfUiECuvbI0moNIoANgIY7MwgW4cFGE= github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.5 h1:gtIcN2INlD2qlfUiECuvbI0moNIoANgIY7MwgW4cFGE=

View File

@ -20,9 +20,8 @@ import (
"fmt" "fmt"
"github.com/go-text/typesetting/di" "github.com/go-text/typesetting/di"
"github.com/go-text/typesetting/font"
glanguage "github.com/go-text/typesetting/language" glanguage "github.com/go-text/typesetting/language"
"github.com/go-text/typesetting/opentype/api/font"
"github.com/go-text/typesetting/opentype/loader"
"github.com/go-text/typesetting/shaping" "github.com/go-text/typesetting/shaping"
"golang.org/x/image/math/fixed" "golang.org/x/image/math/fixed"
"golang.org/x/text/language" "golang.org/x/text/language"
@ -89,7 +88,7 @@ func (g *GoTextFace) SetVariation(tag Tag, value float32) {
g.variations = append(g.variations, font.Variation{}) g.variations = append(g.variations, font.Variation{})
copy(g.variations[idx+1:], g.variations[idx:]) copy(g.variations[idx+1:], g.variations[idx:])
g.variations[idx] = font.Variation{ g.variations[idx] = font.Variation{
Tag: loader.Tag(tag), Tag: font.Tag(tag),
Value: value, Value: value,
} }
g.variationsString = "" g.variationsString = ""
@ -136,7 +135,7 @@ func (g *GoTextFace) SetFeature(tag Tag, value uint32) {
g.features = append(g.features, shaping.FontFeature{}) g.features = append(g.features, shaping.FontFeature{})
copy(g.features[idx+1:], g.features[idx:]) copy(g.features[idx+1:], g.features[idx:])
g.features[idx] = shaping.FontFeature{ g.features[idx] = shaping.FontFeature{
Tag: loader.Tag(tag), Tag: font.Tag(tag),
Value: value, Value: value,
} }
g.featuresString = "" g.featuresString = ""

View File

@ -20,10 +20,8 @@ import (
"sync" "sync"
"github.com/go-text/typesetting/font" "github.com/go-text/typesetting/font"
"github.com/go-text/typesetting/font/opentype"
"github.com/go-text/typesetting/language" "github.com/go-text/typesetting/language"
"github.com/go-text/typesetting/opentype/api"
ofont "github.com/go-text/typesetting/opentype/api/font"
"github.com/go-text/typesetting/opentype/loader"
"github.com/go-text/typesetting/shaping" "github.com/go-text/typesetting/shaping"
"golang.org/x/image/math/fixed" "golang.org/x/image/math/fixed"
@ -44,7 +42,7 @@ type glyph struct {
shapingGlyph *shaping.Glyph shapingGlyph *shaping.Glyph
startIndex int startIndex int
endIndex int endIndex int
scaledSegments []api.Segment scaledSegments []opentype.Segment
bounds fixed.Rectangle26_6 bounds fixed.Rectangle26_6
} }
@ -55,7 +53,7 @@ type goTextOutputCacheValue struct {
} }
type goTextGlyphImageCacheKey struct { type goTextGlyphImageCacheKey struct {
gid api.GID gid opentype.GID
xoffset fixed.Int26_6 xoffset fixed.Int26_6
yoffset fixed.Int26_6 yoffset fixed.Int26_6
variations string variations string
@ -63,7 +61,7 @@ type goTextGlyphImageCacheKey struct {
// GoTextFaceSource is a source of a GoTextFace. This can be shared by multiple GoTextFace objects. // GoTextFaceSource is a source of a GoTextFace. This can be shared by multiple GoTextFace objects.
type GoTextFaceSource struct { type GoTextFaceSource struct {
f font.Face f *font.Face
metadata Metadata metadata Metadata
outputCache map[goTextOutputCacheKey]*goTextOutputCacheValue outputCache map[goTextOutputCacheKey]*goTextOutputCacheValue
@ -101,18 +99,18 @@ func NewGoTextFaceSource(source io.Reader) (*GoTextFaceSource, error) {
return nil, err return nil, err
} }
l, err := loader.NewLoader(src) l, err := opentype.NewLoader(src)
if err != nil { if err != nil {
return nil, err return nil, err
} }
f, err := ofont.NewFont(l) f, err := font.NewFont(l)
if err != nil { if err != nil {
return nil, err return nil, err
} }
s := &GoTextFaceSource{ s := &GoTextFaceSource{
f: &ofont.Face{Font: f}, f: font.NewFace(f),
} }
s.addr = s s.addr = s
s.metadata = metadataFromLoader(l) s.metadata = metadataFromLoader(l)
@ -127,19 +125,19 @@ func NewGoTextFaceSourcesFromCollection(source io.Reader) ([]*GoTextFaceSource,
return nil, err return nil, err
} }
ls, err := loader.NewLoaders(src) ls, err := opentype.NewLoaders(src)
if err != nil { if err != nil {
return nil, err return nil, err
} }
sources := make([]*GoTextFaceSource, len(ls)) sources := make([]*GoTextFaceSource, len(ls))
for i, l := range ls { for i, l := range ls {
f, err := ofont.NewFont(l) f, err := font.NewFont(l)
if err != nil { if err != nil {
return nil, err return nil, err
} }
s := &GoTextFaceSource{ s := &GoTextFaceSource{
f: &ofont.Face{Font: f}, f: &font.Face{Font: f},
} }
s.addr = s s.addr = s
s.metadata = metadataFromLoader(l) s.metadata = metadataFromLoader(l)
@ -160,9 +158,12 @@ func (g *GoTextFaceSource) Metadata() Metadata {
} }
// UnsafeInternal returns its font.Face. // UnsafeInternal returns its font.Face.
// The return value type is any since github.com/go-text/typesettings's API is now unstable.
// //
// This is unsafe since this might make internal cache states out of sync. // UnsafeInternal is unsafe since this might make internal cache states out of sync.
func (g *GoTextFaceSource) UnsafeInternal() font.Face { //
// UnsafeInternal might have breaking changes even in the same major version.
func (g *GoTextFaceSource) UnsafeInternal() any {
return g.f return g.f
} }
@ -220,22 +221,22 @@ func (g *GoTextFaceSource) shape(text string, face *GoTextFace) ([]shaping.Outpu
for _, gl := range out.Glyphs { for _, gl := range out.Glyphs {
gl := gl gl := gl
var segs []api.Segment var segs []opentype.Segment
switch data := g.f.GlyphData(gl.GlyphID).(type) { switch data := g.f.GlyphData(gl.GlyphID).(type) {
case api.GlyphOutline: case font.GlyphOutline:
if out.Direction.IsSideways() { if out.Direction.IsSideways() {
data.Sideways(fixed26_6ToFloat32(-gl.YOffset) / fixed26_6ToFloat32(out.Size) * float32(f.Upem())) data.Sideways(fixed26_6ToFloat32(-gl.YOffset) / fixed26_6ToFloat32(out.Size) * float32(f.Upem()))
} }
segs = data.Segments segs = data.Segments
case api.GlyphSVG: case font.GlyphSVG:
segs = data.Outline.Segments segs = data.Outline.Segments
case api.GlyphBitmap: case font.GlyphBitmap:
if data.Outline != nil { if data.Outline != nil {
segs = data.Outline.Segments segs = data.Outline.Segments
} }
} }
scaledSegs := make([]api.Segment, len(segs)) scaledSegs := make([]opentype.Segment, len(segs))
scale := float32(g.scale(fixed26_6ToFloat64(out.Size))) scale := float32(g.scale(fixed26_6ToFloat64(out.Size)))
for i, seg := range segs { for i, seg := range segs {
scaledSegs[i] = seg scaledSegs[i] = seg
@ -293,9 +294,9 @@ func (g *GoTextFaceSource) getOrCreateGlyphImage(goTextFace *GoTextFace, key goT
} }
type singleFontmap struct { type singleFontmap struct {
face font.Face face *font.Face
} }
func (s *singleFontmap) ResolveFace(r rune) font.Face { func (s *singleFontmap) ResolveFace(r rune) *font.Face {
return s.face return s.face
} }

View File

@ -19,7 +19,7 @@ import (
"image/draw" "image/draw"
"math" "math"
"github.com/go-text/typesetting/opentype/api" "github.com/go-text/typesetting/font/opentype"
"golang.org/x/image/math/fixed" "golang.org/x/image/math/fixed"
gvector "golang.org/x/image/vector" gvector "golang.org/x/image/vector"
@ -27,7 +27,7 @@ import (
"github.com/hajimehoshi/ebiten/v2/vector" "github.com/hajimehoshi/ebiten/v2/vector"
) )
func segmentsToBounds(segs []api.Segment) fixed.Rectangle26_6 { func segmentsToBounds(segs []opentype.Segment) fixed.Rectangle26_6 {
if len(segs) == 0 { if len(segs) == 0 {
return fixed.Rectangle26_6{} return fixed.Rectangle26_6{}
} }
@ -40,9 +40,9 @@ func segmentsToBounds(segs []api.Segment) fixed.Rectangle26_6 {
for _, seg := range segs { for _, seg := range segs {
n := 1 n := 1
switch seg.Op { switch seg.Op {
case api.SegmentOpQuadTo: case opentype.SegmentOpQuadTo:
n = 2 n = 2
case api.SegmentOpCubeTo: case opentype.SegmentOpCubeTo:
n = 3 n = 3
} }
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
@ -75,7 +75,7 @@ func segmentsToBounds(segs []api.Segment) fixed.Rectangle26_6 {
} }
} }
func segmentsToImage(segs []api.Segment, subpixelOffset fixed.Point26_6, glyphBounds fixed.Rectangle26_6) *ebiten.Image { func segmentsToImage(segs []opentype.Segment, subpixelOffset fixed.Point26_6, glyphBounds fixed.Rectangle26_6) *ebiten.Image {
if len(segs) == 0 { if len(segs) == 0 {
return nil return nil
} }
@ -97,16 +97,16 @@ func segmentsToImage(segs []api.Segment, subpixelOffset fixed.Point26_6, glyphBo
rast.DrawOp = draw.Src rast.DrawOp = draw.Src
for _, seg := range segs { for _, seg := range segs {
switch seg.Op { switch seg.Op {
case api.SegmentOpMoveTo: case opentype.SegmentOpMoveTo:
rast.MoveTo(seg.Args[0].X+biasX, seg.Args[0].Y+biasY) rast.MoveTo(seg.Args[0].X+biasX, seg.Args[0].Y+biasY)
case api.SegmentOpLineTo: case opentype.SegmentOpLineTo:
rast.LineTo(seg.Args[0].X+biasX, seg.Args[0].Y+biasY) rast.LineTo(seg.Args[0].X+biasX, seg.Args[0].Y+biasY)
case api.SegmentOpQuadTo: case opentype.SegmentOpQuadTo:
rast.QuadTo( rast.QuadTo(
seg.Args[0].X+biasX, seg.Args[0].Y+biasY, seg.Args[0].X+biasX, seg.Args[0].Y+biasY,
seg.Args[1].X+biasX, seg.Args[1].Y+biasY, seg.Args[1].X+biasX, seg.Args[1].Y+biasY,
) )
case api.SegmentOpCubeTo: case opentype.SegmentOpCubeTo:
rast.CubeTo( rast.CubeTo(
seg.Args[0].X+biasX, seg.Args[0].Y+biasY, seg.Args[0].X+biasX, seg.Args[0].Y+biasY,
seg.Args[1].X+biasX, seg.Args[1].Y+biasY, seg.Args[1].X+biasX, seg.Args[1].Y+biasY,
@ -125,19 +125,19 @@ func segmentsToImage(segs []api.Segment, subpixelOffset fixed.Point26_6, glyphBo
return ebiten.NewImageFromImage(dst) return ebiten.NewImageFromImage(dst)
} }
func appendVectorPathFromSegments(path *vector.Path, segs []api.Segment, x, y float32) { func appendVectorPathFromSegments(path *vector.Path, segs []opentype.Segment, x, y float32) {
for _, seg := range segs { for _, seg := range segs {
switch seg.Op { switch seg.Op {
case api.SegmentOpMoveTo: case opentype.SegmentOpMoveTo:
path.MoveTo(seg.Args[0].X+x, seg.Args[0].Y+y) path.MoveTo(seg.Args[0].X+x, seg.Args[0].Y+y)
case api.SegmentOpLineTo: case opentype.SegmentOpLineTo:
path.LineTo(seg.Args[0].X+x, seg.Args[0].Y+y) path.LineTo(seg.Args[0].X+x, seg.Args[0].Y+y)
case api.SegmentOpQuadTo: case opentype.SegmentOpQuadTo:
path.QuadTo( path.QuadTo(
seg.Args[0].X+x, seg.Args[0].Y+y, seg.Args[0].X+x, seg.Args[0].Y+y,
seg.Args[1].X+x, seg.Args[1].Y+y, seg.Args[1].X+x, seg.Args[1].Y+y,
) )
case api.SegmentOpCubeTo: case opentype.SegmentOpCubeTo:
path.CubicTo( path.CubicTo(
seg.Args[0].X+x, seg.Args[0].Y+y, seg.Args[0].X+x, seg.Args[0].Y+y,
seg.Args[1].X+x, seg.Args[1].Y+y, seg.Args[1].X+x, seg.Args[1].Y+y,

View File

@ -79,7 +79,9 @@ func (s *GoXFace) Metrics() Metrics {
// UnsafeInternal returns its internal font.Face. // UnsafeInternal returns its internal font.Face.
// //
// This is unsafe since this might make internal cache states out of sync. // UnsafeInternal is unsafe since this might make internal cache states out of sync.
//
// UnsafeInternal might have breaking changes even in the same major version.
func (s *GoXFace) UnsafeInternal() font.Face { func (s *GoXFace) UnsafeInternal() font.Face {
s.copyCheck() s.copyCheck()
return s.f.f return s.f.f

View File

@ -15,8 +15,8 @@
package text package text
import ( import (
"github.com/go-text/typesetting/opentype/api/metadata" "github.com/go-text/typesetting/font"
"github.com/go-text/typesetting/opentype/loader" "github.com/go-text/typesetting/font/opentype"
) )
// Metadata represents a font face's metadata. // Metadata represents a font face's metadata.
@ -27,47 +27,47 @@ type Metadata struct {
Stretch Stretch Stretch Stretch
} }
func metadataFromLoader(l *loader.Loader) Metadata { func metadataFromLoader(l *opentype.Loader) Metadata {
f, a, _ := metadata.Describe(l, nil) d, _ := font.Describe(l, nil)
return Metadata{ return Metadata{
Family: f, Family: d.Family,
Style: Style(a.Style), Style: Style(d.Aspect.Style),
Weight: Weight(a.Weight), Weight: Weight(d.Aspect.Weight),
Stretch: Stretch(a.Stretch), Stretch: Stretch(d.Aspect.Stretch),
} }
} }
type Style uint8 type Style uint8
const ( const (
StyleNormal Style = Style(metadata.StyleNormal) StyleNormal Style = Style(font.StyleNormal)
StyleItalic Style = Style(metadata.StyleItalic) StyleItalic Style = Style(font.StyleItalic)
) )
type Weight float32 type Weight float32
const ( const (
WeightThin Weight = Weight(metadata.WeightThin) WeightThin Weight = Weight(font.WeightThin)
WeightExtraLight Weight = Weight(metadata.WeightExtraLight) WeightExtraLight Weight = Weight(font.WeightExtraLight)
WeightLight Weight = Weight(metadata.WeightLight) WeightLight Weight = Weight(font.WeightLight)
WeightNormal Weight = Weight(metadata.WeightNormal) WeightNormal Weight = Weight(font.WeightNormal)
WeightMedium Weight = Weight(metadata.WeightMedium) WeightMedium Weight = Weight(font.WeightMedium)
WeightSemibold Weight = Weight(metadata.WeightSemibold) WeightSemibold Weight = Weight(font.WeightSemibold)
WeightBold Weight = Weight(metadata.WeightBold) WeightBold Weight = Weight(font.WeightBold)
WeightExtraBold Weight = Weight(metadata.WeightExtraBold) WeightExtraBold Weight = Weight(font.WeightExtraBold)
WeightBlack Weight = Weight(metadata.WeightBlack) WeightBlack Weight = Weight(font.WeightBlack)
) )
type Stretch float32 type Stretch float32
const ( const (
StretchUltraCondensed Stretch = Stretch(metadata.StretchUltraCondensed) StretchUltraCondensed Stretch = Stretch(font.StretchUltraCondensed)
StretchExtraCondensed Stretch = Stretch(metadata.StretchExtraCondensed) StretchExtraCondensed Stretch = Stretch(font.StretchExtraCondensed)
StretchCondensed Stretch = Stretch(metadata.StretchCondensed) StretchCondensed Stretch = Stretch(font.StretchCondensed)
StretchSemiCondensed Stretch = Stretch(metadata.StretchSemiCondensed) StretchSemiCondensed Stretch = Stretch(font.StretchSemiCondensed)
StretchNormal Stretch = Stretch(metadata.StretchNormal) StretchNormal Stretch = Stretch(font.StretchNormal)
StretchSemiExpanded Stretch = Stretch(metadata.StretchSemiExpanded) StretchSemiExpanded Stretch = Stretch(font.StretchSemiExpanded)
StretchExpanded Stretch = Stretch(metadata.StretchExpanded) StretchExpanded Stretch = Stretch(font.StretchExpanded)
StretchExtraExpanded Stretch = Stretch(metadata.StretchExtraExpanded) StretchExtraExpanded Stretch = Stretch(font.StretchExtraExpanded)
StretchUltraExpanded Stretch = Stretch(metadata.StretchUltraExpanded) StretchUltraExpanded Stretch = Stretch(font.StretchUltraExpanded)
) )