font-kit icon indicating copy to clipboard operation
font-kit copied to clipboard

Colored emojis

Open RazrFalcon opened this issue 6 years ago • 9 comments

How to retrieve a colored emoji from a font?

We have Loader::outline, but for emojis we have to return an SVG? I have no idea how this is implemented in existing software...

RazrFalcon avatar May 05 '19 18:05 RazrFalcon

This is going to depend a lot on the platform. On Windows, you get colored outline layers from the COLR table. On macOS and Android, it's essentially bitmap PNG's embedded into the font. The OpenType standard also has a provision for svg but I don't think it's widely used (ie I don't think any platform provides it).

I think the best general approach is to use the bitmap rasterize loader interface with an RGBA format. Then there's potential fine-tuning to do to match the platform's representation more closely, but this should be a reasonable start.

See this helpful page on color fonts from FontLab for more information about the differences between platforms in color font handling.

raphlinus avatar May 05 '19 21:05 raphlinus

Is there a way to check what format is used in a font? I've tried FontForge, but it could not open NotoColorEmoji.ttf.

Anyway, in my case, SVG is enough. Bitmap one will make stuff too complicated. Moreover, I'm not sure if font-kit supports bitmap fonts at all.

RazrFalcon avatar May 06 '19 07:05 RazrFalcon

FontTools’ ttx can list font tables or dump them to XML representation. In case of Noto Color Emoji, it uses bitmaps in the CDBT table.

khaledhosny avatar May 08 '19 10:05 khaledhosny

@khaledhosny Thanks. I will try it out.

RazrFalcon avatar May 08 '19 10:05 RazrFalcon

So I think there are three features we want from font-kit:

  • A method that specifies the type of a glyph outline. This can be at least an OpenType outline, a CFF2 outline, a bitmap, an SVG, or a series of outlines with a COLR table.

  • The ability to fetch the text of an SVG glyph. SVG parsing, rendering, etc. seems out of scope of font-kit.

  • The ability to enumerate outline colors, for COLR.

I don't see the need for special support for bitmaps, given that we already have a function to rasterize a glyph. In the case of a bitmap glyph, that function should already be doing a plain old image blit.

pcwalton avatar Jan 10 '20 06:01 pcwalton

Here you can view the support status of all platforms: https://www.colorfonts.wtf/ image

yisibl avatar Feb 06 '21 02:02 yisibl

@RazrFalcon Were you able to make something work?

samyak-jain avatar Feb 19 '21 23:02 samyak-jain

@samyak-jain No.

RazrFalcon avatar Feb 20 '21 14:02 RazrFalcon

@raphlinus Is this feature out of scope for this crate? If not, let me know if there's any way I can contribute.

samyak-jain avatar Feb 21 '21 13:02 samyak-jain