googlefonts / ufo2ft

A bridge from UFOs to FontTools objects (and therefore, OTFs and TTFs).
MIT License
151 stars 43 forks source link

Kern writer fails when script tag not in `unicodedata.ot_tag_to_script` #575

Closed simoncozens closed 2 years ago

simoncozens commented 2 years ago

The following OpenType script tags:

return None when passed to unicodedata.ot_tag_to_script. (byzm/math/musc are considered Common script, so there's no sensible Unicode script tag to map them to, and Jamo should be manually mapped to 'Hang' but it isn't.)

This means that if any of them appear in a languagesystem statement, ast.getScriptLanguageSystems returns a dictionary with None keys:

https://github.com/googlefonts/ufo2ft/blob/0ee84954455cb3f451b32ab8df8509cefe025c72/Lib/ufo2ft/featureWriters/ast.py#L36-L38

and that means that _groupScriptsByTagAndDirection passes None to unicodedata.script_horizontal_direction

https://github.com/googlefonts/ufo2ft/blob/0ee84954455cb3f451b32ab8df8509cefe025c72/Lib/ufo2ft/featureWriters/kernFeatureWriter.py#L339-L340

and that causes a KeyError in the kern writer.

As a workaround, all of these are left-to-right when used as a primary script, so if we get a None, we might want to just force the direction to be LTR.

anthrotype commented 2 years ago

Jamo should be manually mapped to 'Hang' but it isn't

should we update fontTools/unicodedata/OTTags.py's SCRIPT_EXCEPTIONS list to add this manual mapping?

simoncozens commented 2 years ago

Yes.

anthrotype commented 2 years ago

Re: "jamo", I read in the OT spec that it's sort of deprecated, https://docs.microsoft.com/en-gb/typography/opentype/spec/scripttags

Hangul Jamo 'jamo' Use of this tag is not recommended. Fonts supporting Unicode conjoining jamo characters should use 'hang' instead.

IIUC, we want ot_tag_to_script("jamo") == "Hang", correct? But we don't also want ot_tags_from_script("Hang") == ["jamo", "hang"] (like it does for ["dev2", "deva"], etc.) ... but just ["hang"], ignoring the (supposedly deprecated?) "jamo" OT script tag.

simoncozens commented 2 years ago

Yeah, I think that's right.