diff options
Diffstat (limited to 'misc/tools/postprocess-designspace.py')
-rw-r--r-- | misc/tools/postprocess-designspace.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/misc/tools/postprocess-designspace.py b/misc/tools/postprocess-designspace.py index 8dae2b571..745e73570 100644 --- a/misc/tools/postprocess-designspace.py +++ b/misc/tools/postprocess-designspace.py @@ -6,6 +6,8 @@ from datetime import datetime sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'tools'))) from common import getGitHash, getVersion +from postprocess_instance_ufo import ufo_set_wws + def update_version(ufo): version = getVersion() @@ -24,6 +26,7 @@ def update_version(ufo): ufo.info.openTypeNameUniqueID = "%s-%s:%d:%s" % (psFamily, psStyle, now.year, buildtag) ufo.info.openTypeHeadCreated = now.strftime("%Y/%m/%d %H:%M:%S") + def fix_opsz_range(designspace): # TODO: find extremes by looking at the source for a in designspace.axes: @@ -33,6 +36,7 @@ def fix_opsz_range(designspace): break return designspace + def fix_wght_range(designspace): for a in designspace.axes: if a.tag == "wght": @@ -41,6 +45,7 @@ def fix_wght_range(designspace): break return designspace + def should_decompose_glyph(g): # A trivial glyph is one that does not use components or where component transformation # does not include mirroring (i.e. "flipped"). @@ -58,12 +63,14 @@ def should_decompose_glyph(g): return True return False + def find_glyphs_to_decompose(designspace): source = designspace.sources[int(len(designspace.sources)/2)] print("find_glyphs_to_decompose sourcing from %r" % source.name) ufo = defcon.Font(source.path) return sorted([g.name for g in ufo if should_decompose_glyph(g)]) + def set_ufo_filter(ufo, **filter_dict): filters = ufo.lib.setdefault("com.github.googlei18n.ufo2ft.filters", []) for i in range(len(filters)): @@ -72,24 +79,27 @@ def set_ufo_filter(ufo, **filter_dict): return filters.append(filter_dict) -def update_source_ufo(ufo_file, weight, glyphs_to_decompose): - print(f"update {os.path.basename(ufo_file)} (weight={weight})") + +def update_source_ufo(ufo_file, glyphs_to_decompose): + print(f"update {os.path.basename(ufo_file)}") ufo = defcon.Font(ufo_file) update_version(ufo) set_ufo_filter(ufo, name="decomposeComponents", include=glyphs_to_decompose) + ufo_set_wws(ufo) # Fix missing WWS entries for Display fonts ufo.save(ufo_file) + def update_sources(designspace): glyphs_to_decompose = find_glyphs_to_decompose(designspace) #print("glyphs marked to be decomposed: %s" % ', '.join(glyphs_to_decompose)) sources = [source for source in designspace.sources] # sources = [s for s in sources if s.name == "Inter Thin"] # DEBUG - source_files = list(set([(s.path, s.location["Weight"]) for s in sources])) + source_files = list(set([s.path for s in sources])) with Pool(len(source_files)) as p: - p.starmap(update_source_ufo, - [(t[0], t[1], glyphs_to_decompose) for t in source_files]) + p.starmap(update_source_ufo, [(path, glyphs_to_decompose) for path in source_files]) return designspace + def main(argv): designspace_file = argv[1] designspace = DesignSpaceDocument.fromfile(designspace_file) @@ -98,5 +108,6 @@ def main(argv): designspace = update_sources(designspace) designspace.write(designspace_file) + if __name__ == '__main__': main(sys.argv) |