Skip to content

Commit

Permalink
Update to the latest breaking API changes in go-text
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Sep 30, 2024
1 parent 3f50cad commit 517e48f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ require (
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a
github.com/go-ole/go-ole v1.2.6
github.com/go-text/render v0.1.1-0.20240418202334-dd62631dae9b
github.com/go-text/typesetting v0.1.0
github.com/go-text/render v0.2.0
github.com/go-text/typesetting v0.2.0
github.com/godbus/dbus/v5 v5.1.0
github.com/jackmordaunt/icns/v2 v2.2.6
github.com/jeandeaual/go-locale v0.0.0-20240223122105-ce5225dcaa49
Expand Down
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a h1:vxnBhFDDT+
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-text/render v0.1.1-0.20240418202334-dd62631dae9b h1:daoFn+Aw8EIQZO9kYWwHL01FqwwpCl2nTeVEYbsgRHk=
github.com/go-text/render v0.1.1-0.20240418202334-dd62631dae9b/go.mod h1:jqEuNMenrmj6QRnkdpeaP0oKGFLDNhDkVKwGjsWWYU4=
github.com/go-text/typesetting v0.1.0 h1:vioSaLPYcHwPEPLT7gsjCGDCoYSbljxoHJzMnKwVvHw=
github.com/go-text/typesetting v0.1.0/go.mod h1:d22AnmeKq/on0HNv73UFriMKc4Ez6EqZAofLhAzpSzI=
github.com/go-text/typesetting-utils v0.0.0-20240329101916-eee87fb235a3 h1:levTnuLLUmpavLGbJYLJA7fQnKeS7P1eCdAlM+vReXk=
github.com/go-text/render v0.2.0 h1:LBYoTmp5jYiJ4NPqDc2pz17MLmA3wHw1dZSVGcOdeAc=
github.com/go-text/render v0.2.0/go.mod h1:CkiqfukRGKJA5vZZISkjSYrcdtgKQWRa2HIzvwNN5SU=
github.com/go-text/typesetting v0.2.0 h1:fbzsgbmk04KiWtE+c3ZD4W2nmCRzBqrqQOvYlwAOdho=
github.com/go-text/typesetting v0.2.0/go.mod h1:2+owI/sxa73XA581LAzVuEBZ3WEEV2pXeDswCH/3i1I=
github.com/go-text/typesetting-utils v0.0.0-20240317173224-1986cbe96c66 h1:GUrm65PQPlhFSKjLPGOZNPNxLCybjzjYBzjfoBGaDUY=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Expand Down
31 changes: 15 additions & 16 deletions internal/painter/font.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/go-text/typesetting/font"
"github.com/go-text/typesetting/fontscan"
"github.com/go-text/typesetting/language"
"github.com/go-text/typesetting/opentype/api/metadata"
"github.com/go-text/typesetting/shaping"
"golang.org/x/image/math/fixed"

Expand Down Expand Up @@ -44,7 +43,7 @@ func loadMap() {
}
}

func lookupLangFont(family string, aspect metadata.Aspect) font.Face {
func lookupLangFont(family string, aspect font.Aspect) *font.Face {
mapLock.Lock()
defer mapLock.Unlock()
load.Do(loadMap)
Expand All @@ -57,7 +56,7 @@ func lookupLangFont(family string, aspect metadata.Aspect) font.Face {
return fm.ResolveFaceForLang(l)
}

func lookupRuneFont(r rune, family string, aspect metadata.Aspect) font.Face {
func lookupRuneFont(r rune, family string, aspect font.Aspect) *font.Face {
mapLock.Lock()
defer mapLock.Unlock()
load.Do(loadMap)
Expand All @@ -72,18 +71,18 @@ func lookupRuneFont(r rune, family string, aspect metadata.Aspect) font.Face {
func lookupFaces(theme, fallback, emoji fyne.Resource, family string, style fyne.TextStyle) (faces *dynamicFontMap) {
f1 := loadMeasureFont(theme)
if theme == fallback {
faces = &dynamicFontMap{family: family, faces: []font.Face{f1}}
faces = &dynamicFontMap{family: family, faces: []*font.Face{f1}}
} else {
f2 := loadMeasureFont(fallback)
faces = &dynamicFontMap{family: family, faces: []font.Face{f1, f2}}
faces = &dynamicFontMap{family: family, faces: []*font.Face{f1, f2}}
}

aspect := metadata.Aspect{Style: metadata.StyleNormal}
aspect := font.Aspect{Style: font.StyleNormal}
if style.Italic {
aspect.Style = metadata.StyleItalic
aspect.Style = font.StyleItalic
}
if style.Bold {
aspect.Weight = metadata.WeightBold
aspect.Weight = font.WeightBold
}

if emoji != nil {
Expand All @@ -107,7 +106,7 @@ func CachedFontFace(style fyne.TextStyle, source fyne.Resource, o fyne.CanvasObj
if face == nil {
face = loadMeasureFont(theme.TextFont())
}
faces := &dynamicFontMap{family: source.Name(), faces: []font.Face{face}}
faces := &dynamicFontMap{family: source.Name(), faces: []*font.Face{face}}

val = &FontCacheItem{Fonts: faces}
fontCustomCache.Store(source, val)
Expand Down Expand Up @@ -145,10 +144,10 @@ func CachedFontFace(style fyne.TextStyle, source fyne.Resource, o fyne.CanvasObj
f1 := loadMeasureFont(th)

if th == fallback {
faces = &dynamicFontMap{family: fontscan.SansSerif, faces: []font.Face{f1}}
faces = &dynamicFontMap{family: fontscan.SansSerif, faces: []*font.Face{f1}}
} else {
f2 := loadMeasureFont(fallback)
faces = &dynamicFontMap{family: fontscan.SansSerif, faces: []font.Face{f1, f2}}
faces = &dynamicFontMap{family: fontscan.SansSerif, faces: []*font.Face{f1, f2}}
}
default:
faces = lookupFaces(font1, theme.DefaultTextFont(), emoji, fontscan.SansSerif, style)
Expand Down Expand Up @@ -192,7 +191,7 @@ func DrawString(dst draw.Image, s string, color color.Color, f shaping.Fontmap,
})
}

func loadMeasureFont(data fyne.Resource) font.Face {
func loadMeasureFont(data fyne.Resource) *font.Face {
loaded, err := font.ParseTTF(bytes.NewReader(data.Content()))
if err != nil {
fyne.LogError("font load error", err)
Expand Down Expand Up @@ -353,19 +352,19 @@ type noopLogger struct{}
func (n noopLogger) Printf(string, ...interface{}) {}

type dynamicFontMap struct {
faces []font.Face
faces []*font.Face
family string
}

func (d *dynamicFontMap) ResolveFace(r rune) font.Face {
func (d *dynamicFontMap) ResolveFace(r rune) *font.Face {

for _, f := range d.faces {
if _, ok := f.NominalGlyph(r); ok {
return f
}
}

toAdd := lookupRuneFont(r, d.family, metadata.Aspect{})
toAdd := lookupRuneFont(r, d.family, font.Aspect{})
if toAdd != nil {
d.addFace(toAdd)
return toAdd
Expand All @@ -374,6 +373,6 @@ func (d *dynamicFontMap) ResolveFace(r rune) font.Face {
return d.faces[0]
}

func (d *dynamicFontMap) addFace(f font.Face) {
func (d *dynamicFontMap) addFace(f *font.Face) {
d.faces = append(d.faces, f)
}
4 changes: 2 additions & 2 deletions internal/test/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package test

import "github.com/go-text/typesetting/font"

type FontMap []font.Face
type FontMap []*font.Face

func (f FontMap) ResolveFace(r rune) font.Face {
func (f FontMap) ResolveFace(r rune) *font.Face {
if len(f) == 1 {
return f[0]
}
Expand Down

0 comments on commit 517e48f

Please sign in to comment.