Skip to content

Commit

Permalink
Derive scripts from glyphs, not languagesystems
Browse files Browse the repository at this point in the history
  • Loading branch information
madig committed Oct 18, 2022
1 parent 2ffc9b1 commit 5cc1dd7
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions Lib/ufo2ft/featureWriters/kernFeatureWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,6 @@ def _addPairToLookup(self, lookup, pair, rtl=False):
self._makePairPosRule(pair, rtl=rtl, quantization=self.options.quantization)
)

def knownScriptsPerCodepoint(self, uv):
if not self.context.knownScripts:
# If there are no languagesystems, consider everything common;
# it'll all end in DFLT/dflt anyway
return COMMON_SCRIPT
return [
x
for x in unicodedata.script_extension(chr(uv))
if x in self.context.knownScripts or x in DFLT_SCRIPTS
]

def _makeKerningLookups(self):
marks = self.context.gdefClasses.mark
lookups = {}
Expand All @@ -469,7 +458,7 @@ def _makeKerningLookups(self):
dirGlyphs = classifyGlyphs(unicodeScriptDirection, cmap, gsub)
self._intersectPairs("directions", dirGlyphs)

scriptGlyphs = classifyGlyphs(self.knownScriptsPerCodepoint, cmap, gsub)
scriptGlyphs = classifyGlyphs(script_extensions_for_codepoint, cmap, gsub)
self._intersectPairs("scripts", scriptGlyphs)
bidiGlyphs = classifyGlyphs(unicodeBidiType, cmap, gsub)
self._intersectPairs("bidiTypes", bidiGlyphs)
Expand Down Expand Up @@ -554,6 +543,8 @@ def _registerLookups(self, feature, lookups):
for uniscript in lookups.keys():
for ot2script in unicodedata.ot_tags_from_script(uniscript):
otscript2uniscript[ot2script] = uniscript
if ot2script != "DFLT" and not any(script == ot2script for script, _ in scripts):
scripts.append((ot2script, ["dflt"]))

for script, langs in sorted(scripts):
if script not in otscript2uniscript:
Expand All @@ -571,3 +562,7 @@ def _registerLookups(self, feature, lookups):
lookups_for_this_script.extend(lookups[dflt_script].values())
lookups_for_this_script.extend(lookups[uniscript].values())
addLookupReferences(feature, lookups_for_this_script, script, langs)


def script_extensions_for_codepoint(uv: int) -> set[str]:
return unicodedata.script_extension(chr(uv))

0 comments on commit 5cc1dd7

Please sign in to comment.