hajimehoshi / ebiten

Ebitengine - A dead simple 2D game engine for Go
https://ebitengine.org
Apache License 2.0
10.74k stars 649 forks source link

text: enable to render emojis #2649

Open huyangv opened 1 year ago

huyangv commented 1 year ago

Ebitengine Version

2.5.2

Operating System

Go Version (go version)

1.19.4

What steps will reproduce the problem?

I tried to draw some emojis using a font pack that could parse emoji, but the result was blank, and if I used a font that didn't contain emojis, the result was a box。 The fonts I've tried to include emoticon characters are as follows: 1 AppleColorEmoji_2x.ttf 2 NotoColorEmoji-Regular.ttf

I saw in another issue that truetype was recommended for loading Noto characters, and in fact that's exactly what I did。

What is the expected result?

strings: ♈♏😁0123456789

image

And result : (use AppleColorEmoji_2x.ttf)

image

(use NotoColorEmoji-Regular.ttf)

image

(use other ttf-no emoji)

image

What happens instead?

see result.

Anything else you feel useful to add?

No response

hajimehoshi commented 1 year ago

This is an issue in golang.org/x/image/font, rather than Ebitengine. I am not sure this is solvable.

hajimehoshi commented 1 year ago

I changed this issue a request rather than a bug.

tinne26 commented 1 year ago

To be more specific, see https://pkg.go.dev/golang.org/x/image/font/sfnt#pkg-variables ErrColoredGlyph (sfnt doesn't support colored glyphs like most emojis).

My take is that even if we used a library that supported colored glyphs, this would complicate the text package models quite a bit, and text is already pretty complex as it is. With Ebitengine being a game engine, not a general application development framework, focusing on creating a way to combine regular *ebiten.Images with text may be a more productive approach.

In practice, it's really hard to draw a reasonable line somewhere between minimal text support and universal browser-like text layout. There are too many features and possibilities, and most of them make a lot of sense in isolation and certain use-cases, but very few are actually relevant in a range of cases wide enough to justify going out the way to cover for them.

If you want to expand explaining what's your use case, I'm sure we can give more context on the topic, because if it's something like a text editor, emojis will be the least of your problems.

hajimehoshi commented 1 year ago

I think using https://pkg.go.dev/github.com/go-text/typesetting@v0.0.0-20230618175549-b5753034b590/opentype/api#GlyphSVG would solve this issue, but this is not easy.