go-text / typesetting

High quality text shaping in pure Go.
Other
88 stars 11 forks source link

Issue in parsing some bitmap fonts #74

Closed andydotxyz closed 1 year ago

andydotxyz commented 1 year ago

On using the note sans colour emoji font (https://fonts.google.com/noto/specimen/Noto+Color+Emoji) I get a font loaded that claims to be SVG format, but the data slice is nil for standard emoji character lookup.

I am not sure if it should be reporting PNG or SVG, but the data being nil meant I could not guess ;).

whereswaldon commented 1 year ago

@andydotxyz We use this exact font in some Gio examples and it reports PNG data. Here's the place where we decode that. I can't explain why go-text would give you different results for the same font.

andydotxyz commented 1 year ago

Yeah it is a bit strange. The following code demos it:

func Test_Format(t *testing.T) {
    text := "😀"
    data, _ := os.Open("/Users/andy/Downloads/Noto_Color_Emoji/NotoColorEmoji-Regular.ttf")
    f, _ := font.ParseTTF(data)
    in := shaping.Input{
        Text:     []rune(text),
        RunStart: 0,
        RunEnd:   len(text),
        Face:     f,
        Size:     fixed.I(24),
    }
    out := (&shaping.HarfbuzzShaper{}).Shape(in)

    if f.GlyphData(out.Glyphs[0].GlyphID).(api.GlyphBitmap).Format != api.PNG {
        t.Error("Wrong format reported")
    }
}
benoitkugler commented 1 year ago

@andydotxyz I've just run the above test with NotoColorEmoji-Regular.ttf (sha1sum: d7002ca4983e7f129683d056fe14d5fe43060f54), and I've found no issue !

Some precision:

Could you check you have the same sha1sum and runes and glyphs numbers ? (Perhaps I somehow didn't download the proper font )

andydotxyz commented 1 year ago

Thanks, I was chasing the wrong thread. It was indeed an SVG font so no error with being not PNG. Once ascertained casting to GlyphSVG instead of GlyphBitmap did indeed reveal a Source field with the content as expected.

Sorry for the confusion.

benoitkugler commented 1 year ago

Thanks, I was chasing the wrong thread. It was indeed an SVG font so no error with being not PNG. Once ascertained casting to GlyphSVG instead of GlyphBitmap did indeed reveal a Source field with the content as expected.

Sorry for the confusion.

No worries, thank you for double checking that. Should we close this issue ?

andydotxyz commented 1 year ago

Oops sorry :)