nothings / stb

stb single-file public domain libraries for C/C++
https://twitter.com/nothings
Other
26.88k stars 7.72k forks source link

stb_truetype.h: Implement support for Embedded Bitmaps. #512

Open kphillisjr opened 7 years ago

kphillisjr commented 7 years ago

This is mostly a request be able to support glyphs from TrueType fonts that use Bitmap data.

Test Data:

Note: Windows 10 Anniversary Update has been updated to fully support all of these Tables, and can be used to check how each glyph is supposed to be rendered. More information over this topic can be found at: https://msdn.microsoft.com/en-us/library/windows/desktop/mt765165(v=vs.85).aspx. Files.

nothings commented 7 years ago

I definitely have 0 interest in supporting bitmap fonts in stb_truetype.

pabloko commented 3 years ago

Hello, i don't usually refloat old issues, but writing here as it may help someone.

Support for COLR+CPAL fonts is already mostly supported by stb_truetype in its current state. stb_truetype can obtain all the needed glyph layers for the emojis, but does not parse the colr (glyph layers) and cpal (color palettes) tables, but doing it would be fairly trivial as defined in the links.

Luckily, if you implement a shaper like HarfBuzz (wich i stongly recommend), it comes with opentype methods to enumerate COLR layers for given codepoint (see hb_ot_color_glyph_get_layers) and CPAL palettes (see hb_ot_color_palette_get_count and hb_ot_color_palette_get_colors) image Displaying: original glyph asociated to the codepoint, Final mix colored with CPAL, and COLR layers associated to the codepoint

As a side note, atlas baker methods on stb_truetype rely on enumerating glyphs by codepoint, but fonts can contain glyphs not associated to a codepoint (ligatures, emoji layers...) so its better to implement your own baking that export glyphs by its id, instead by its associated codepoint, and also thats what HarfBuzz expects in order to build ligatures and replacements, or have the layers available for compositing. Heres a sample of SegoeUIEmoji atlas containing every glyph in the font, if you use bakefont you will notice emoji separated layers aren't there.

Other color fonts can be supported thru HarfBuzz but you would have to provide your own rendering for bitmap/png/svg... wich is outside the scope of stb_truetype, so i fully understand the author's disinterest on color fonts, but given that this library already does the hard stuff, maybe a simple COLR/CPAL parser would be usuful for people that dont want to bring a shaper library but at least match DirectWrite's color capabilities.

@nothings if you're open for a PR i'd gladly add this api