def run(options): # Set the current dir to the design space dir, so that relative paths in # the design space file will work. dsDir, dsFile = os.path.split(os.path.abspath(options.dsPath)) os.chdir(dsDir) options.dsPath = dsFile dsPath, newInstancesList = readDesignSpaceFile(options) if not dsPath: return version = 3 if len(newInstancesList) == 1: logger.info("Building 1 instance...") else: logger.info("Building %s instances..." % len(newInstancesList)) ufoProcessorBuild(documentPath=dsPath, outputUFOFormatVersion=version, roundGeometry=(not options.no_round), logger=logger) if (dsPath != options.dsPath) and os.path.exists(dsPath): os.remove(dsPath) logger.info("Built %s instances." % len(newInstancesList)) # Remove glyph.lib and font.lib (except for "public.glyphOrder") for instancePath in newInstancesList: postProcessInstance(instancePath, options) if options.doNormalize: logger.info("Applying UFO normalization...") for instancePath in newInstancesList: normalizeUFO(instancePath, outputPath=None, onlyModified=True, writeModTimes=False) if options.doAutoHint or options.doOverlapRemoval: logger.info("Applying post-processing...") # Apply autohint and checkoutlines, if requested. for instancePath in newInstancesList: # make new instance font. updateInstance(options, instancePath) # checkoutlinesufo does ufotools.validateLayers() if not options.doOverlapRemoval: for instancePath in newInstancesList: # make sure that that there are no old glyphs left in the # processed glyphs folder validateLayers(instancePath) # The defcon library renames glyphs. Need to fix them again if options.doOverlapRemoval or options.doAutoHint: for instancePath in newInstancesList: if options.doNormalize: normalizeUFO(instancePath, outputPath=None, onlyModified=False, writeModTimes=False)
def run(options): # Set the current dir to the design space dir, so that relative paths in # the design space file will work. dsDir, dsFile = os.path.split(os.path.abspath(options.dsPath)) os.chdir(dsDir) options.dsPath = dsFile dsPath, newInstancesList = readDesignSpaceFile(options) if not dsPath: return if len(newInstancesList) == 1: logger.info("Building 1 instance...") else: logger.info("Building %s instances..." % len(newInstancesList)) ufoProcessorBuild(documentPath=dsPath, outputUFOFormatVersion=options.ufo_version, roundGeometry=(not options.no_round), logger=logger) if (dsPath != options.dsPath) and os.path.exists(dsPath): os.remove(dsPath) logger.info("Built %s instances." % len(newInstancesList)) # Remove glyph.lib and font.lib (except for "public.glyphOrder") for instancePath in newInstancesList: postProcessInstance(instancePath, options) if options.doNormalize: logger.info("Applying UFO normalization...") for instancePath in newInstancesList: normalizeUFO(instancePath, outputPath=None, onlyModified=True, writeModTimes=False) if options.doAutoHint or options.doOverlapRemoval: logger.info("Applying post-processing...") # Apply autohint and checkoutlines, if requested. for instancePath in newInstancesList: # make new instance font. updateInstance(options, instancePath) # checkoutlinesufo does ufotools.validateLayers() if not options.doOverlapRemoval: for instancePath in newInstancesList: # make sure that that there are no old glyphs left in the # processed glyphs folder validateLayers(instancePath) # The defcon library renames glyphs. Need to fix them again if options.doOverlapRemoval or options.doAutoHint: for instancePath in newInstancesList: if options.doNormalize: normalizeUFO(instancePath, outputPath=None, onlyModified=False, writeModTimes=False)
def run(options): ds_doc = DesignSpaceDocument.fromfile(options.dsPath) # can still have a successful read but useless DSD (no sources, no # instances, sources non-existent, other conditions validateDesignspaceDoc(ds_doc, options) copy_features = any(src.copyFeatures for src in ds_doc.sources) features_store = {} if not copy_features: # '<features copy="1"/>' is NOT set in any of masters. # Collect the contents of 'features.fea' of any existing # instances so that they can be restored later. features_store = collect_features_content(ds_doc.instances, options.indexList) # Set the current dir to the design space dir, so that relative paths in # the design space file will work. dsDir, dsFile = os.path.split(os.path.abspath(options.dsPath)) os.chdir(dsDir) options.dsPath = dsFile if options.indexList: dsPath = filterDesignspaceInstances(ds_doc, options) else: dsPath = dsFile newInstancesList = [inst.path for inst in ds_doc.instances] newInstancesCount = len(newInstancesList) if newInstancesCount == 1: logger.info("Building 1 instance...") else: logger.info("Building %s instances..." % newInstancesCount) ufoProcessorBuild(documentPath=dsPath, outputUFOFormatVersion=options.ufo_version, roundGeometry=(not options.no_round), logger=logger) if (dsPath != options.dsPath) and os.path.exists(dsPath): os.remove(dsPath) logger.info("Built %s instances." % newInstancesCount) # Remove glyph.lib and font.lib (except for "public.glyphOrder") for instancePath in newInstancesList: postProcessInstance(instancePath, options) if options.doNormalize: logger.info("Applying UFO normalization...") for instancePath in newInstancesList: normalizeUFO(instancePath, outputPath=None, onlyModified=True, writeModTimes=False) if options.doAutoHint or options.doOverlapRemoval: logger.info("Applying post-processing...") # Apply autohint and checkoutlines, if requested. for instancePath in newInstancesList: # make new instance font. updateInstance(instancePath, options) # checkoutlinesufo does ufotools.validateLayers() if not options.doOverlapRemoval: for instancePath in newInstancesList: # make sure that there are no old glyphs left in the # processed glyphs folder validateLayers(instancePath) # The defcon library renames glyphs. Need to fix them again if options.doOverlapRemoval or options.doAutoHint: for instancePath in newInstancesList: if options.doNormalize: normalizeUFO(instancePath, outputPath=None, onlyModified=False, writeModTimes=False) # Restore the contents of the instances' 'features.fea' files for fea_pth, fea_cntnts in features_store.items(): with open(fea_pth, 'w') as fp: fp.write(fea_cntnts)
def run(options): ds_doc = DesignSpaceDocument.fromfile(options.dsPath) # can still have a successful read but useless DSD (no sources, no # instances, sources non-existent, other conditions validateDesignspaceDoc(ds_doc, options) copy_features = any(src.copyFeatures for src in ds_doc.sources) features_store = {} if not copy_features: # '<features copy="1"/>' is NOT set in any of masters. # Collect the contents of 'features.fea' of any existing # instances so that they can be restored later. features_store = collect_features_content(ds_doc.instances, options.indexList) # Set the current dir to the design space dir, so that relative paths in # the design space file will work. dsDir, dsFile = os.path.split(os.path.abspath(options.dsPath)) os.chdir(dsDir) options.dsPath = dsFile if options.indexList: dsPath = filterDesignspaceInstances(ds_doc, options) else: dsPath = dsFile newInstancesList = [inst.path for inst in ds_doc.instances] newInstancesCount = len(newInstancesList) icnt_str = f'instance{"" if newInstancesCount == 1 else "s"}' tool_str = "fontTools.varlib" if options.useVarlib else "MutatorMath" info_str = f"Building {newInstancesCount} {icnt_str} with {tool_str}..." logger.info(info_str) ufoProcessorBuild(documentPath=dsPath, outputUFOFormatVersion=options.ufo_version, roundGeometry=(not options.no_round), logger=logger, useVarlib=options.useVarlib) # Remove temporary designspace file if (dsPath != options.dsPath) and os.path.exists(dsPath): os.remove(dsPath) logger.info("Built %s instances." % newInstancesCount) # Remove glyph.lib and font.lib (except for "public.glyphOrder") pool = multiprocessing.Pool(os.cpu_count() - 1) pool.starmap(postProcessInstance, [(instancePath, options) for instancePath in newInstancesList]) if options.doNormalize: logger.info("Applying UFO normalization...") args = zip(newInstancesList) kwargs = repeat( { 'outputPath': None, 'onlyModified': True, 'writeModTimes': False }, newInstancesCount) starmap_kwargs(pool, normalizeUFO, args, kwargs) if options.doAutoHint or options.doOverlapRemoval: logger.info("Applying post-processing...") # Apply autohint and checkoutlines, if requested. # make new instance font. pool.starmap(updateInstance, [(instancePath, options) for instancePath in newInstancesList]) # checkoutlinesufo does ufotools.validateLayers() if not options.doOverlapRemoval: # make sure that there are no old glyphs left in the # processed glyphs folder pool.map(validateLayers, newInstancesList) # The defcon library renames glyphs. Need to fix them again if options.doOverlapRemoval or options.doAutoHint: if options.doNormalize: args = zip(newInstancesList) kwargs = repeat( { 'outputPath': None, 'onlyModified': False, 'writeModTimes': False }, newInstancesCount) starmap_kwargs(pool, normalizeUFO, args, kwargs) pool.close() pool.join() # Restore the contents of the instances' 'features.fea' files for fea_pth, fea_cntnts in features_store.items(): with open(fea_pth, 'w') as fp: fp.write(fea_cntnts)