Skip to content

Commit

Permalink
Re-use helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
khaledhosny committed Jan 21, 2024
1 parent 68d49a8 commit eba8fab
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions Lib/ufo2ft/featureWriters/kernFeatureWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def unicodeBidiType(uv):
return None


def script_direction(script: str) -> str:
if script == COMMON_SCRIPT:
return "Auto"
return script_horizontal_direction(script, "LTR")


@dataclass(frozen=True, order=False)
class KerningPair:
__slots__ = ("side1", "side2", "value")
Expand Down Expand Up @@ -723,9 +729,7 @@ def _makeSplitScriptKernLookups(self, lookups, pairs, ignoreMarks=True, suffix="
pair.value,
)
continue
directions = {
script_horizontal_direction(script, "LTR") for script in scripts
}
directions = {script_direction(script) for script in scripts}
assert len(directions) == 1
scriptIsRtl = directions == {"RTL"}
# Numbers are always shaped LTR even in RTL scripts:
Expand Down Expand Up @@ -785,10 +789,10 @@ def _registerLookups(
lookupsLTR: list[ast.LookupBlock] = []
lookupsRTL: list[ast.LookupBlock] = []
for script, scriptLookups in sorted(lookups.items()):
if script != COMMON_SCRIPT and script not in DIST_ENABLED_SCRIPTS:
if script_horizontal_direction(script, "LTR") == "LTR":
if script not in DIST_ENABLED_SCRIPTS:
if script_direction(script) == "LTR":
lookupsLTR.extend(scriptLookups.values())
elif script_horizontal_direction(script, "LTR") == "RTL":
elif script_direction(script) == "RTL":
lookupsRTL.extend(scriptLookups.values())
dfltLookups.extend(
lkp for lkp in (lookupsLTR or lookupsRTL) if lkp not in dfltLookups
Expand Down Expand Up @@ -860,11 +864,6 @@ def partitionByScript(
"""Split a potentially mixed-script pair into pairs that make sense based
on the dominant script, and yield each combination with its dominant script."""

def script_direction(script: str) -> str:
if script == COMMON_SCRIPT:
return "Auto"
return script_horizontal_direction(script, "LTR")

side1Directions: dict[str, set[str]] = {}
side2Directions: dict[str, set[str]] = {}
resolvedScripts: dict[str, set[str]] = {}
Expand Down

0 comments on commit eba8fab

Please sign in to comment.