Skip to content

Commit

Permalink
Move features_from_tttable to Font
Browse files Browse the repository at this point in the history
  • Loading branch information
kojiishi committed Apr 5, 2024
1 parent c57373e commit 24ec82c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
28 changes: 1 addition & 27 deletions east_asian_spacing/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,37 +151,11 @@ def dump_table_entries(font,
sum_data + sum_gap, sum_data, sum_gap, len(entries)),
file=out_file)

@staticmethod
def features_from_tttable(tttable):
if tttable is None:
return
table = tttable.table
if not table or not table.FeatureList:
return
feature_records = table.FeatureList.FeatureRecord
script_records = table.ScriptList.ScriptRecord
for script_record in script_records:
script_tag = script_record.ScriptTag
lang_sys_records = []
if script_record.Script.DefaultLangSys:
lang_sys_records.append(
("dflt", script_record.Script.DefaultLangSys))
lang_sys_records = itertools.chain(
lang_sys_records,
((lang_sys_record.LangSysTag, lang_sys_record.LangSys)
for lang_sys_record in script_record.Script.LangSysRecord))
for lang_tag, lang_sys in lang_sys_records:
feature_indices = getattr(lang_sys, "FeatureIndex", None)
if not feature_indices:
yield (script_tag, lang_tag, ())
yield (script_tag, lang_tag, (feature_records[i].FeatureTag
for i in feature_indices))

@staticmethod
def dump_features(font, face_index, tag, out_file=sys.stdout):
ttfont = font.ttfonts[face_index]
tttable = ttfont.get(tag)
for script_tag, lang_tag, feature_tags in Dump.features_from_tttable(
for script_tag, lang_tag, feature_tags in Font.features_from_tttable(
tttable):
features = ",".join(
feature_tags) if feature_tags else "(no features)"
Expand Down
26 changes: 26 additions & 0 deletions east_asian_spacing/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,32 @@ def raise_require_language(self):
key=lambda t: t[0] +
("" if t[1] is None else t[1]))))

@staticmethod
def features_from_tttable(tttable):
if tttable is None:
return
table = tttable.table
if not table or not table.FeatureList:
return
feature_records = table.FeatureList.FeatureRecord
script_records = table.ScriptList.ScriptRecord
for script_record in script_records:
script_tag = script_record.ScriptTag
lang_sys_records = []
if script_record.Script.DefaultLangSys:
lang_sys_records.append(
("dflt", script_record.Script.DefaultLangSys))
lang_sys_records = itertools.chain(
lang_sys_records,
((lang_sys_record.LangSysTag, lang_sys_record.LangSys)
for lang_sys_record in script_record.Script.LangSysRecord))
for lang_tag, lang_sys in lang_sys_records:
feature_indices = getattr(lang_sys, "FeatureIndex", None)
if not feature_indices:
yield (script_tag, lang_tag, ())
yield (script_tag, lang_tag, (feature_records[i].FeatureTag
for i in feature_indices))

@staticmethod
def _has_ottable_feature(ottable, feature_tag):
if not ottable or not ottable.FeatureList:
Expand Down

0 comments on commit 24ec82c

Please sign in to comment.