Compare commits

...

2 Commits

Author SHA1 Message Date
Hajime Hoshi
df821f0177 ebiten: add a warning about StrictContextRestoration
Updates #3089
2024-09-10 01:42:48 +09:00
Hajime Hoshi
e058bb6fd3 all: update go-text
Unfortunately this adds a breaking change to (*GoTextFaceSource).UnsafeInternal.

Updates #3082
2024-09-09 23:29:49 +09:00
8 changed files with 75 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/purego v0.8.0-alpha.5
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/go-mp3 v0.3.4
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/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/go-text/typesetting v0.1.1 h1:bGAesCuo85nXnEN5LmFMVGAGpGkCPtHrZLi//qD7EJo=
github.com/go-text/typesetting v0.1.1/go.mod h1:d22AnmeKq/on0HNv73UFriMKc4Ez6EqZAofLhAzpSzI=
github.com/go-text/typesetting-utils v0.0.0-20231211103740-d9332ae51f04 h1:zBx+p/W2aQYtNuyZNcTfinWvXBQwYtDfme051PR/lAY=
github.com/go-text/typesetting v0.1.1-0.20240522210117-2c045476f496 h1:zgx3rOyOdRoA2GXWpfJkH7Zg248ookseRifdn9VSp5g=
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-20240317173224-1986cbe96c66 h1:GUrm65PQPlhFSKjLPGOZNPNxLCybjzjYBzjfoBGaDUY=
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/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.5 h1:gtIcN2INlD2qlfUiECuvbI0moNIoANgIY7MwgW4cFGE=

1
run.go
View File

@ -301,6 +301,7 @@ type RunGameOptions struct {
// StrictContextRestration indicates whether the context lost should be restored strictly by Ebitengine or not.
//
// StrictContextRestration is available only on Android. Otherwise, StrictContextRestration is ignored.
// Thus, StrictContextRestration should be used with mobile.SetGameWithOptions, rather than RunGameWithOptions.
//
// In Android, Ebitengien uses `GLSurfaceView`'s `setPreserveEGLContextOnPause(true)`.
// This works in most cases, but it is still possible that the context is lost in some minor cases.

View File

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

View File

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

View File

@ -19,7 +19,7 @@ import (
"image/draw"
"math"
"github.com/go-text/typesetting/opentype/api"
"github.com/go-text/typesetting/font/opentype"
"golang.org/x/image/math/fixed"
gvector "golang.org/x/image/vector"
@ -27,7 +27,7 @@ import (
"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 {
return fixed.Rectangle26_6{}
}
@ -40,9 +40,9 @@ func segmentsToBounds(segs []api.Segment) fixed.Rectangle26_6 {
for _, seg := range segs {
n := 1
switch seg.Op {
case api.SegmentOpQuadTo:
case opentype.SegmentOpQuadTo:
n = 2
case api.SegmentOpCubeTo:
case opentype.SegmentOpCubeTo:
n = 3
}
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 {
return nil
}
@ -97,16 +97,16 @@ func segmentsToImage(segs []api.Segment, subpixelOffset fixed.Point26_6, glyphBo
rast.DrawOp = draw.Src
for _, seg := range segs {
switch seg.Op {
case api.SegmentOpMoveTo:
case opentype.SegmentOpMoveTo:
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)
case api.SegmentOpQuadTo:
case opentype.SegmentOpQuadTo:
rast.QuadTo(
seg.Args[0].X+biasX, seg.Args[0].Y+biasY,
seg.Args[1].X+biasX, seg.Args[1].Y+biasY,
)
case api.SegmentOpCubeTo:
case opentype.SegmentOpCubeTo:
rast.CubeTo(
seg.Args[0].X+biasX, seg.Args[0].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)
}
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 {
switch seg.Op {
case api.SegmentOpMoveTo:
case opentype.SegmentOpMoveTo:
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)
case api.SegmentOpQuadTo:
case opentype.SegmentOpQuadTo:
path.QuadTo(
seg.Args[0].X+x, seg.Args[0].Y+y,
seg.Args[1].X+x, seg.Args[1].Y+y,
)
case api.SegmentOpCubeTo:
case opentype.SegmentOpCubeTo:
path.CubicTo(
seg.Args[0].X+x, seg.Args[0].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.
//
// 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 {
s.copyCheck()
return s.f.f

View File

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