robotools / compositor

A basic OpenType GSUB and GPOS layout engine.
MIT License
31 stars 11 forks source link

Fixing support for Stylistic Set names #4

Closed andyclymer closed 9 years ago

andyclymer commented 9 years ago

When I added this feature to Compositor I had misinterpreted how Stylistic Set names are arranged in the table — Stylistic Set names are not sequential starting from ID 256, the names are instead arranged to match the order of the features (i.e. Stylistic Set 4 could be the first Stylistic Set in the font’s features and would be named at ID 256, Stylistic Set 10 could be the second feature at ID 257, etc.)

The correct Name ID for each Stylistic Set is compiled into the table as a parameter of the Stylistic Set’s FeatureRecord:

font = TTFont(fontPath)
gsub = font[“GSUB"]
for featureRecord in gsub.table.FeatureList.FeatureRecord:
    params = featureRecord.Feature.FeatureParams
        if hasattr(params, "UINameID"):
        print featureRecord.FeatureTag, params.UINameID

There is support for calling a feature’s UINameID parameter in Behdad Esfahbod’s fork of FontTools, but not in the version on SourceForge (and this patch is built to not cause an error with the SourceForge version).

The table loading order in the Compositor font had to change to make this work, loadCMAP() and loadFeatures() had to come before loadInfo() so that the GSUB table would already be loaded by the time the names were unpacked. I don’t believe it looks like this will cause any problem, however.

benkiel commented 9 years ago

This is causing Compositor to now throw a AttributeError: 'NoneType' object has no attribute 'FeatureList'. Looking into why...

andyclymer commented 9 years ago

Ah! I think I know why, line 105 in init.py needs to check if there was a gsub table before it asks for the FeatureList. I can make a fix.