Skip to content

Commit

Permalink
Merge pull request #67 from LettError/issue_66
Browse files Browse the repository at this point in the history
Issue 66 & 65
  • Loading branch information
LettError authored Nov 11, 2024
2 parents 3d4befa + d8b1159 commit a0c1ce9
Showing 1 changed file with 45 additions and 18 deletions.
63 changes: 45 additions & 18 deletions Lib/ufoProcessor/ufoOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ def __init__(self, pathOrObject=None, ufoVersion=3, useVarlib=True, extrapolate=
self.mutedAxisNames = None # list of axisname that need to be muted
self.strict = strict
self.debug = debug
self.logger = None
self.extrapolate = extrapolate # if true allow extrapolation
self.logger = None
self.doc = None
Expand All @@ -207,17 +206,22 @@ def __init__(self, pathOrObject=None, ufoVersion=3, useVarlib=True, extrapolate=
else:
self.doc = DesignSpaceDocument()
if self.debug:
docBaseName = os.path.splitext(self.doc.path)[0]
logPath = f"{docBaseName}_log.txt"
self.logger = Logger(path=logPath, rootDirectory=None)
self.logger.time()
self.logger.info(f"## {self.doc.path}")
self.logger.info(f"\tUFO version: {self.ufoVersion}")
self.logger.info(f"\tround Geometry: {self.roundGeometry}")
if self.useVarlib:
self.logger.info(f"\tinterpolating with varlib")
else:
self.logger.info(f"\tinterpolating with mutatorMath")
self.startLog()

def startLog(self):
# so we can call it later
self.debug = True
docBaseName = os.path.splitext(self.doc.path)[0]
logPath = f"{docBaseName}_log.txt"
self.logger = Logger(path=logPath, rootDirectory=None)
self.logger.time()
self.logger.info(f"## {self.doc.path}")
self.logger.info(f"\tUFO version: {self.ufoVersion}")
self.logger.info(f"\tround Geometry: {self.roundGeometry}")
if self.useVarlib:
self.logger.info(f"\tinterpolating with varlib")
else:
self.logger.info(f"\tinterpolating with mutatorMath")

def _instantiateFont(self, path):
""" Return a instance of a font object with all the given subclasses"""
Expand Down Expand Up @@ -388,11 +392,11 @@ def getAxis(self, axisName):

# loading and updating fonts
def loadFonts(self, reload=False):
self.glyphNames = list({glyphname for font in self.fonts.values() for glyphname in font.keys()})
# Load the fonts and find the default candidate based on the info flag
self.glyphNames = list({glyphname for font in self.fonts.values() for glyphname in font.keys()})
if self._fontsLoaded and not reload:
if self.debug:
self.logger.info("\t\t-- loadFonts requested, but fonts are loaded already and no reload requested")
self.logger.info("\t\t-- loadFonts called, but fonts are loaded already and no reload requested")
return
actions = []
if self.debug:
Expand Down Expand Up @@ -589,6 +593,7 @@ def findDefaultFont(self, discreteLocation=None):

def splitLocation(self, location):
# split a location in a continouous and a discrete part
# Note: discrete can be None
discreteAxes = [a.name for a in self.getOrderedDiscreteAxes()]
continuous = {}
discrete = {}
Expand Down Expand Up @@ -1266,6 +1271,17 @@ def getLocationType(self, location):
locHorizontal, locVertical = self.splitAnisotropic(loc)
return anisotropic, continuousLocation, discreteLocation, locHorizontal, locVertical

def collectSkippedGlyphs(self):
# return a list of all the glyphnames listed in public.skipExportGlyphs
names = []
for fontPath, fontObj in self.fonts.items():
for name in fontObj.lib.get('public.skipExportGlyphs', []):
if name not in names:
names.append(name)
if self.debug:
self.logger.info(f"collectSkippedGlyphs: {names}")
return names

def makeInstance(self, instanceDescriptor,
doRules=None,
glyphNames=None,
Expand All @@ -1280,6 +1296,7 @@ def makeInstance(self, instanceDescriptor,
# hmm getFullDesignLocation does not support anisotropc locations?
fullDesignLocation = instanceDescriptor.getFullDesignLocation(self.doc)
anisotropic, continuousLocation, discreteLocation, locHorizontal, locVertical = self.getLocationType(fullDesignLocation)
self.loadFonts()

if not self.extrapolate:
# Axis values are in userspace, so this needs to happen before bending
Expand Down Expand Up @@ -1359,7 +1376,9 @@ def makeInstance(self, instanceDescriptor,
if 'public.glyphOrder' not in font.lib.keys():
# should be the glyphorder from the default, yes?
font.lib['public.glyphOrder'] = selectedGlyphNames

# remove skippable glyphs
toSkip = self.collectSkippedGlyphs()
selectedGlyphNames = [name for name in selectedGlyphNames if name not in toSkip]
for glyphName in selectedGlyphNames:
glyphMutator, unicodes = self.getGlyphMutator(glyphName, decomposeComponents=decomposeComponents, discreteLocation=discreteLocation)
if glyphMutator is None:
Expand Down Expand Up @@ -1425,12 +1444,14 @@ def makeInstance(self, instanceDescriptor,

def locationToDescriptiveString(self, loc):
# make a nice descriptive string from the location
# Check if the discrete location is None.
t = []
cl, dl = self.splitLocation(loc)
for continuousAxis in sorted(cl.keys()):
t.append(f'{continuousAxis}_{cl[continuousAxis]}')
for discreteAxis in sorted(dl.keys()):
t.append(f'{discreteAxis}_{dl[discreteAxis]}')
if dl is not None:
for discreteAxis in sorted(dl.keys()):
t.append(f'{discreteAxis}_{dl[discreteAxis]}')
return '_'.join(t)

def pathForInstance(self, instanceDescriptor):
Expand All @@ -1448,6 +1469,7 @@ def makeOneInstance(self, location,
# make one instance for this location. This is a shortcut for making an
# instanceDescriptor. So it makes some assumptions about the font names.
# Otherwise all the geometry will be exactly what it needs to be.
self.loadFonts()
continuousLocation, discreteLocation = self.splitLocation(location)
defaultFont = self.findDefaultFont(discreteLocation=discreteLocation)
if defaultFont is not None:
Expand Down Expand Up @@ -1524,6 +1546,7 @@ def getLocationsForFont(self, fontObj):
# @memoize
def makeFontProportions(self, location, bend=False, roundGeometry=True):
"""Calculate the basic font proportions for this location, to map out expectations for drawing"""
self.loadFonts()
continuousLocation, discreteLocation = self.splitLocation(location)
infoMutator = self.getInfoMutator(discreteLocation=discreteLocation)
data = dict(unitsPerEm=1000, ascender=750, descender=-250, xHeight=500)
Expand Down Expand Up @@ -1557,8 +1580,8 @@ def makeOneGlyph(self, glyphName, location, decomposeComponents=True, useVarlib=
Returns: a mathglyph, results are cached
"""
self.loadFonts()
continuousLocation, discreteLocation = self.splitLocation(location)

bend=False #
if not self.extrapolate:
# Axis values are in userspace, so this needs to happen *after* clipping.
Expand Down Expand Up @@ -1609,6 +1632,7 @@ def makeOneInfo(self, location, roundGeometry=False, clip=False):
"""
if self.debug:
self.logger.info(f"\t\t\tmakeOneInfo for {location}")
self.loadFonts()
bend = False
anisotropic, continuousLocation, discreteLocation, locHorizontal, locVertical = self.getLocationType(location)
# so we can take the math object that comes out of the calculation
Expand Down Expand Up @@ -1639,6 +1663,7 @@ def makeOneKerning(self, location, pairs=None):
"""
if self.debug:
self.logger.info(f"\t\t\tmakeOneKerning for {location}")
self.loadFonts()
bend = False
kerningObject = None
anisotropic, continuousLocation, discreteLocation, locHorizontal, locVertical = self.getLocationType(location)
Expand Down Expand Up @@ -1853,3 +1878,5 @@ def _copyFontInfo(self, sourceInfo, targetInfo):

for instanceDescriptor in doc.instances:
print('path for instancedescriptor', doc.pathForInstance(instanceDescriptor))

doc.collectSkippedGlyphs()

0 comments on commit a0c1ce9

Please sign in to comment.