hexops / mach

zig game engine & graphics toolkit
https://machengine.org
Other
3.34k stars 159 forks source link

freetype: need to support png support for some emoji font #466

Open mitchellh opened 2 years ago

mitchellh commented 2 years ago

I'm still using my own freetype zig fork for now and haven't had time to contribute (sorry!) but I ran into this and I think you will too. Some Emoji fonts such as Noto (Google) use embedded pngs which require freetype to be built with png support.

This is a bit of a can of worms so I'll explain it all here so you can avoid the footguns:

  1. Freetype will require libpng
  2. libpng will require zlib
  3. Freetype by default (and current Mach config) compiles in its own vendored zlib sources. So doing step 2 will result in duplicate symbols. You'll want to set FT_CONFIG_OPTION_SYSTEM_ZLIB=1 for freetype and link in zlib that you used for step 2.

libpng and zlib are both easy to build with Zig.

To test it all works, you'll need to load a glyph from a png font, Noto works well.

slimsag commented 2 years ago

Embedded PNGs in fonts! I had no idea, that's nasty :/ I agree we should fix this in the freetype bindings as you suggest.

In Mach itself, we're hoping to render glyphs ourselves on the GPU using freetype just to extract beziers - I was hoping we could use Noto too but I guess we'll need to find a fallback approach for whichever glyphs only have pre-rendered PNGs. Crazy.

mitchellh commented 2 years ago

Yeah Noto not only uses embedded PNGs, but they're fixed at a single resolution. Right now I'm putting them at full resolution into a texture atlas and downsampling in a shader, but I might move to downsampling a bit on the CPU since its a bit wasteful how large they are.

slimsag commented 2 years ago

https://github.com/adobe-fonts/noto-emoji-svg looks interesting?

mitchellh commented 2 years ago

Maybe! I haven’t used SVG fonts yet, I’ve only read about them in the FT docs. I know that FT doesn’t include any SVG renderer but you can get the SVG data and probably pass that into a shader. Might be easier to just rasterize the SVG on CPU and then put that in a texture though.