Skip to content

Commit

Permalink
move constant logic out of the for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed Jan 11, 2024
1 parent c66430d commit 1ac9908
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions Lib/ufo2ft/_compilers/baseCompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ def _compileNeededSources(self, designSpaceDoc):
# Disable GPOS compaction while building masters because the compaction
# will be undone anyway by varLib merge and then done again on the final VF
gpos_compact_value = self.ftConfig.pop(GPOS_COMPRESSION_LEVEL, None)
# we want to rename glyphs only on the final VF and skip postprocessing masters
save_production_names, self.useProductionNames = self.useProductionNames, False
save_postprocessor, self.postProcessorClass = self.postProcessorClass, None
# skip per-master feature compilation if we are building variable features
save_skip_features, self.skipFeatureCompilation = (
self.skipFeatureCompilation,
can_optimize_features,
)
try:
# Compile all needed sources in each interpolable subspace to make sure
# they're all compatible; that also ensures that sub-vfs within the same
Expand All @@ -285,19 +293,12 @@ def _compileNeededSources(self, designSpaceDoc):
if not subDoc.sources:
continue

save_production_names = self.useProductionNames
self.useProductionNames = False
save_postprocessor = self.postProcessorClass
self.postProcessorClass = None
self.skipFeatureCompilation = can_optimize_features

ttfDesignSpace = self.compile_designspace(subDoc)

if gpos_compact_value is not None:
# the VF will inherit the config from the base TTF master
baseTtf = getDefaultMasterFont(ttfDesignSpace)
baseTtf.cfg[GPOS_COMPRESSION_LEVEL] = gpos_compact_value
self.postProcessorClass = save_postprocessor
self.useProductionNames = save_production_names

# Stick TTFs back into original big DS
for ttfSource, glyphSet in zip(ttfDesignSpace.sources, self.glyphSets):
Expand All @@ -308,8 +309,12 @@ def _compileNeededSources(self, designSpaceDoc):
sourcesByName[ttfSource.name].font = ttfSource.font
originalGlyphsets[ttfSource.name] = glyphSet
finally:
# can restore self to its original state
if gpos_compact_value is not None:
self.ftConfig[GPOS_COMPRESSION_LEVEL] = gpos_compact_value
self.postProcessorClass = save_postprocessor
self.useProductionNames = save_production_names
self.skipFeatureCompilation = save_skip_features

return (
vfNameToBaseUfo,
Expand Down

0 comments on commit 1ac9908

Please sign in to comment.