diff --git a/build.py b/build.py index e958b4a..571041b 100755 --- a/build.py +++ b/build.py @@ -520,6 +520,22 @@ def drop_mac_names(dir: str): run(f"ftcli name del-mac-names -r {dir}") +def rename_glyph_name(font: TTFont, old_glyph_name: str, new_glyph_name: str, post_extra_names: bool = True): + glyph_names = font.getGlyphOrder() + modified = False + for i, _ in enumerate(glyph_names): + if glyph_names[i] == old_glyph_name: + glyph_names[i] = new_glyph_name + print(f"{old_glyph_name} renamed to {new_glyph_name}") + modified = True + if modified: + font.setGlyphOrder(glyph_names) + + if post_extra_names: + index = font['post'].extraNames.index(old_glyph_name) + font['post'].extraNames[index] = new_glyph_name + + def get_unique_identifier( postscript_name: str, freeze_config_str: str, @@ -853,6 +869,11 @@ def main(): ] for input_file in input_files: font = TTFont(input_file) + + # fix auto rename by FontLab + rename_glyph_name(font, "uni2047.liga", "question_question.liga") + rename_glyph_name(font, "uni00A0", "nbspace") + font.save( input_file.replace(build_option.src_dir, build_option.output_variable) ) diff --git a/source/py/feature.py b/source/py/feature.py index a9f9d31..270e80f 100644 --- a/source/py/feature.py +++ b/source/py/feature.py @@ -9,6 +9,7 @@ def get_freeze_config_str(feature_freeze, enable_liga): result += "-calt;" return result + def freeze_feature(font, calt, moving_rules=[], config={}): # check feature list feature_record = font["GSUB"].table.FeatureList.FeatureRecord @@ -20,7 +21,9 @@ def freeze_feature(font, calt, moving_rules=[], config={}): if calt: calt_features = [ - feature.Feature for feature in feature_record if feature.FeatureTag == "calt" + feature.Feature + for feature in feature_record + if feature.FeatureTag == "calt" ] else: for feature in feature_record: @@ -48,7 +51,9 @@ def freeze_feature(font, calt, moving_rules=[], config={}): glyph_dict = font["glyf"].glyphs hmtx_dict = font["hmtx"].metrics for index in target_feature.LookupListIndex: - lookup_subtable = font["GSUB"].table.LookupList.Lookup[index].SubTable[0] + lookup_subtable = ( + font["GSUB"].table.LookupList.Lookup[index].SubTable[0] + ) if not lookup_subtable or "mapping" not in lookup_subtable.__dict__: continue for old_key, new_key in lookup_subtable.mapping.items():