rougier / freetype-py

Python binding for the freetype library
Other
298 stars 88 forks source link

feature request: expose FreeType's COLRv1 API #165

Closed anthrotype closed 11 months ago

anthrotype commented 1 year ago

It would be nice if freetype-py added support for FT_Get_Color_Glyph_Paint and friends, as defined in https://freetype.org/freetype2/docs/reference/ft2-layer_management.html

HinTak commented 1 year ago

@anthrotype I think you have write access yourself - just add it yourself, something similar to the others, with a "try ... except pass" to allow old freetype to continue to work: https://github.com/rougier/freetype-py/blob/894fd770149e63faa74677eccc1c825118c40850/freetype/raw.py#L102

Out of the 200+ routines, only about 160 are listed, the last time I counted. Basically you add them as you need them... also, while you are at it, please add an example.

HinTak commented 1 year ago

I have a partial pull to add OT-SVG support to freetype-py. I'll put it out when I finish an example. Maybe you can have a look to see about adding COLR stuff yourself.

HinTak commented 1 year ago

The OT-SVG addition plus example is now at https://github.com/rougier/freetype-py/pull/174 .

HinTak commented 1 year ago

OT-SVG support and example merged. Have a look to get some idea about what you might need to do to add another color font format. (And the last of the 4, as that)

HinTak commented 1 year ago

Posted to otspec list, duplicate with some edit here.

Anyway, just checking how much work it would get freetype-py (python binding of freetype) to work with COLR v1 over the weekend, after committing the ot-svg support. It seems that you can draw with python with all 4 kinds of emojis (Apple's sbix, google's CBLC+friends, Adobe/Mozilla's OT-SVG, and Microsoft COLRv0; the last one soon with an extra line I need to push out soon). Freetype currently has a preference of SVG over COLRv0/COLRv1 if both are present, and COLRv1 support isn't anywhere near complete yet, so no point in adding the python binding yet.

Ie. I'll push a single line plus some comments soon, and that would allow COLRv0 emojis to work (and all 4 kind of them), with the emoji-cairo example.

But Freetype itself's support for COLRv1 isn't complete yet (it only started to land a few months ago), and you actually need both freetype 2.13.1 (latest, not 2.13.0) as well as my ot-svg code - the two of which, together, allows you to disable SVG if both SVG and COLR (v0/v1) are present, to see that COLRv1 is not working.

In other words, this cannot be done any time soon, AFAIC, and you also need latest freetype with some not-yet-done improvements (more recent than current...).

I'll put the COLRv0 required line into the emoji example soon, plus some comments about making to work with OT-SVG emoji also. (It works but requires importing my ot-svg-example as a python module)

HinTak commented 11 months ago

Code and basic example in https://github.com/rougier/freetype-py/pull/176 merged. If you want anything else/further, just do it yourself.