Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add strict flag for MathGlyph objects #41

Merged
merged 3 commits into from
Jun 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions Lib/ufoProcessor/ufoOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import collections
import traceback

from fontTools.designspaceLib import DesignSpaceDocument, SourceDescriptor, InstanceDescriptor, AxisDescriptor, RuleDescriptor, processRules
from fontTools.designspaceLib import DesignSpaceDocument, processRules
from fontTools.ufoLib import fontInfoAttributesVersion1, fontInfoAttributesVersion2, fontInfoAttributesVersion3
from fontTools.misc import plistlib

Expand Down Expand Up @@ -145,13 +145,14 @@ class UFOOperator(object):
mathGlyphClass = MathGlyph
mathKerningClass = MathKerning

def __init__(self, pathOrObject=None, ufoVersion=3, useVarlib=True, extrapolate=False, debug=False):
def __init__(self, pathOrObject=None, ufoVersion=3, useVarlib=True, extrapolate=False, strict=False, debug=False):
self.ufoVersion = ufoVersion
self.useVarlib = useVarlib
self._fontsLoaded = False
self.fonts = {}
self.roundGeometry = False
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
Expand Down Expand Up @@ -379,7 +380,7 @@ def getCharacterMapping(self, discreteLocation=None):
# return a unicode -> glyphname map for the default of the system or discreteLocation
characterMap = {}
defaultSourceDescriptor = self.findDefault(discreteLocation=discreteLocation)
if not defaultSourceDescriptor:
if not defaultSourceDescriptor:
print("no defaultSourceDescriptor")
return {}
defaultFont = self.fonts.get(defaultSourceDescriptor.name)
Expand Down Expand Up @@ -825,9 +826,9 @@ def getGlyphMutator(self, glyphName, decomposeComponents=False, **discreteLocati
if hasattr(b, "toMathGlyph"):
# note: calling toMathGlyph ignores the mathGlyphClass preference
# maybe the self.mathGlyphClass is not necessary?
new.append((a, b.toMathGlyph()))
new.append((a, b.toMathGlyph(strict=self.strict)))
else:
new.append((a, self.mathGlyphClass(b)))
new.append((a, self.mathGlyphClass(b, strict=self.strict)))
thing = None
thisBias = self.newDefaultLocation(bend=True, discreteLocation=discreteLocation)
try:
Expand Down Expand Up @@ -1010,9 +1011,9 @@ def collectSourcesForGlyph(self, glyphName, decomposeComponents=False, discreteL
sourceName=sourceDescriptor.name,
)
if hasattr(processThis, "toMathGlyph"):
processThis = processThis.toMathGlyph()
processThis = processThis.toMathGlyph(strict=self.strict)
else:
processThis = self.mathGlyphClass(processThis)
processThis = self.mathGlyphClass(processThis, strict=self.strict)
continuous, discrete = self.splitLocation(loc)
items.append((continuous, processThis, sourceInfo))
empties.append((thisIsDefault, foundEmpty))
Expand Down Expand Up @@ -1409,11 +1410,11 @@ def _copyFontInfo(self, sourceInfo, targetInfo):
print(doc.glyphsInCache())

print(doc.clipThisLocation(dict(width=(-1000, 2000))))
#print(doc.clipThisLocation(dict(optical=1, weight=5000)))
#print(doc.clipThisLocation(dict(optical=1, weight=5000)))

print('newDefaultLocation()', doc.newDefaultLocation(discreteLocation={'countedItems': 3.0, 'outlined': 1.0}))
print('newDefaultLocation()', doc.newDefaultLocation())
print("findDefaultFont()", doc.findDefaultFont().path)
print("findDefaultFont()", doc.findDefaultFont(discreteLocation={'countedItems': 3.0, 'outlined': 1.0}).path)
print("findDefaultFont()", doc.findDefaultFont(discreteLocation={'countedItems': 3.0, 'outlined': 1.0}).path)
print("getNeutralFont()", doc.getNeutralFont().path)
print("getNeutralFont()", doc.getNeutralFont(discreteLocation={'countedItems': 3.0, 'outlined': 1.0}).path)
print("getNeutralFont()", doc.getNeutralFont(discreteLocation={'countedItems': 3.0, 'outlined': 1.0}).path)