go-text / typesetting

High quality text shaping in pure Go.
Other
101 stars 10 forks source link

parse ttc font file error #39

Closed chindev2012 closed 1 year ago

chindev2012 commented 1 year ago

In fyne v2.3.0

2022/12/29 08:56:07 Fyne error: font load error 2022/12/29 08:56:07 Cause: unsupported font format 2022/12/29 08:56:07 At: C:/Users/xxx/go/pkg/mod/fyne.io/fyne/v2@v2.3.0/internal/painter/font.go:150 panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x4ec pc=0xc3bfe0]

goroutine 1 [running, locked to thread]: github.com/benoitkugler/textlayout/fonts/truetype.(Font).Upem(0xc000050000?) C:/Users/xxx/go/pkg/mod/github.com/benoitkugler/textlayout@v0.3.0/fonts/truetype/metrics.go:34 github.com/benoitkugler/textlayout/harfbuzz.NewFont({0x1377778?, 0x0}) C:/Users/xxx/go/pkg/mod/github.com/benoitkugler/textlayout@v0.3.0/harfbuzz/fonts.go:98 +0x9c github.com/go-text/typesetting/shaping.(HarfbuzzShaper).Shape(0xc0016af7e8, {{0xc0003507c8, 0x1, 0x1}, 0x0, 0x1, 0x0, {0x1377778, 0x0}, 0x340, ...}) C:/Users/xxx/go/pkg/mod/github.com/go-text/typesetting@v0.0.0-20221212183139-1eb938670a1f/shaping/shaper.go:77 +0x1d6

Example Code

package main

import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/app" "fyne.io/fyne/v2/widget" "os" )

func init(){ os.Setenv("FYNE_FONT", "C:\windows\fonts\msyh.ttc") }

func main() { a := app.New() w := a.NewWindow("demo") w.Resize(fyne.Size{300, 200}) w.CenterOnScreen() w.SetContent(widget.NewLabel("Hello World!")) w.ShowAndRun() }

benoitkugler commented 1 year ago

Hi ! Thank you for the bug report. The issue here is that collections (.ttc) are not yet supported.

@andydotxyz Does Fyne have plans to support them ? From the go-text side, we would simply need to expose the truetype.Load function, which already support collections. However, it requires an (integer) index to select the actual face to use, which in turn probably requires API change on Fyne side.
(This would be the only change required, since, even for collections, truetype.Load returns a (slice of) Face, which are fully compatible with the current typesetting pipeline.)

andydotxyz commented 1 year ago

I did a little more testing and earlier versions of Go are able to build with 1.17 set. This is so strange. I guess we would have known if this was not possible as our CI tests with 1.14 over the entire code base ;).

With that in mind I don't have a reason to hold it back. But I do worry about the mismatch of documented behaviour vs actual in the Go tooling!

benoitkugler commented 1 year ago

@andydotxyz I think you meant to reply in #40 right ?

andydotxyz commented 1 year ago

Thanks! I could not find where I posted this comment :) (changing timezones can be problematic for sensible discourse!)

whereswaldon commented 1 year ago

We actually support loading font collections as of #49, so I'm going to close this.