adobe-type-tools / opentype-svg

Tools and sample files for making OpenType-SVG fonts
MIT License
212 stars 17 forks source link

support cid-keyed OTF #4

Closed hatchzo closed 6 years ago

hatchzo commented 6 years ago

The "addSVGtable.py" doesn't seem to support cid-keyed OTF.

Actually, the script adds SVG table into the font exactly and GID value are specified to bind SVG data with their parent B/W glyphs.

CID-keyed CFF is used to Japanese or CK OTF development in common, and CID will correspond with GID entirely in most cases.

However in some particular cases, for example, a subset font that is developed as a portion of Adobe CJK glyph collection, it will not have CID=GID mapping.

The key/val in SVG table seems to be specified as a toggle to show up a color glyph, it will make a conflict if cid-keyed font have an inconsistent CID/GID mapping.

kenlunde commented 6 years ago

The best way to describe this request is for the addSVGtable.py script to support CID-keyed fonts whose CIDs do not equal GIDs, particularly when the SVG glyphs correspond to CIDs that do not equal GIDs.

miguelsousa commented 6 years ago

@kenlunde got it. What the correct way to identify such difference? The fonts will have a specific ROS?

kenlunde commented 6 years ago

Yes, the presence of /Registry, /Ordering, and /Supplement (aka ROS) values in the 'CFF ' table is the best indicator that you're dealing with a CID-keyed font.

miguelsousa commented 6 years ago

@kenlunde my question was, how do I distinguish between a CID-keyed font whose CID=GID from a CID-keyed font whose CID!=GID ?

kenlunde commented 6 years ago

Use tx -4 <CID-keyed font> for this. The moment that "tag" (aka GID) does not equal "cid" (aka CID), you're dealing with such a font.

miguelsousa commented 6 years ago

@kenlunde I don't want to call tx from addSVGtable.py. Any other suggestions?

kenlunde commented 6 years ago

The only place where CIDs are recorded in an OpenType/CFF font is the 'CFF ' table, so if you cannot call tx to check this, perhaps the best course of action is to simply assume that CID!=GID, meaning that all CID-keyed fonts are treated the same regardless of whether CID=GID or CID!=GID.

miguelsousa commented 6 years ago

I know I need to check the CFF table. I plan to do that using fonttools, since addSVGtable already depends on it. My questions were for trying to understand which parts of the CFF table I need to pay close attention to. Anyways, I'll figure it out.

miguelsousa commented 6 years ago

@hatchzo I made some tests with fonts I got from @kenlunde and as far as I can tell addSVGtable.py is working correctly with CJK fonts, even with those whose CIDs are different from GIDs.

Here's a test I ran using SourceHanSansJP-Heavy.otf:

python fonts2svg.py -c ff0000 -g cid00364,cid00621 SourceHanSansJP-Heavy.otf
python addSVGtable.py -s SVGs SourceHanSansJP-Heavy.otf

As you can see from the image below, the SVG artwork got associated with the expected glyphs.

screen shot 2018-02-16 at 17 47 09

So the only issue I see is the inconvenience of having to zero-pad the CID references. I can change the scripts in this repository to handle unpadded CID references. Would this be helpful to you?

hatchzo commented 6 years ago

OK, I will test new addSVGtable.py this week. Thanks!!