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

Open
opened 2022-08-20 17:54:43 +00:00 by mitchellh · 4 comments
mitchellh commented 2022-08-20 17:54:43 +00:00 (Migrated from github.com)

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.

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.
emidoots commented 2022-08-20 18:09:57 +00:00 (Migrated from github.com)

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.

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 2022-08-20 18:11:19 +00:00 (Migrated from github.com)

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.

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.
emidoots commented 2022-08-20 18:25:37 +00:00 (Migrated from github.com)
https://github.com/adobe-fonts/noto-emoji-svg looks interesting?
mitchellh commented 2022-08-20 18:31:20 +00:00 (Migrated from github.com)

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.

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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
hexops/mach#466
No description provided.