Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _makeMarkClass(cls, markClasses, accentName, x, y, className):
""" Make a MarkClassDefinition statement given the accent name,
position, class name, and pre-existing mark classes.
Return None if a mark class with the same name and anchor already
exists. Or create new mark class with unique name when different.
"""
glyphs = ast.GlyphName(accentName)
anchor = cls._makeAnchorFormatA(x, y)
className = ast.makeFeaClassName(className)
markClass = markClasses.get(className)
if markClass is None:
markClass = ast.MarkClass(className)
markClasses[className] = markClass
else:
if accentName in markClass.glyphs:
mcdef = markClass.glyphs[accentName]
if cls._anchorsAreEqual(anchor, mcdef.anchor):
logger.debug(
"Glyph %s already defined in markClass @%s",
accentName,
className,
)
return None
def _makeMarkLigPosRule(cls, baseName, points, markClass):
""" Return a MarkLigPosStatement for given ligature glyph, list of
anchor points, and a markClass.
"""
ligature = ast.GlyphName(baseName)
marks = []
for x, y in points:
anchor = cls._makeAnchorFormatA(x, y)
marks.append([(anchor, markClass)])
return ast.MarkLigPosStatement(ligature, marks)
def _makeMarkPosRule(cls, ruleType, baseName, x, y, markClass):
""" Return a MarkBasePosStatement for given rule type (either "base" or
"mark"), glyph name, anchor and markClass name.
"""
base = ast.GlyphName(baseName)
anchor = cls._makeAnchorFormatA(x, y)
marks = [(anchor, markClass)]
if ruleType == "base":
return ast.MarkBasePosStatement(base, marks)
elif ruleType == "mark":
return ast.MarkMarkPosStatement(base, marks)
else:
raise AssertionError(ruleType)
if glyphName in markClass.glyphs:
mcdef = markClass.glyphs[glyphName]
if self._anchorsAreEqual(anchor, mcdef.anchor):
self.log.debug(
"Glyph %s already defined in markClass @%s",
glyphName,
className,
)
return None
else:
# same mark glyph defined with different anchors for the
# same markClass; make a new unique markClass definition
newClassName = ast.makeFeaClassName(className, markClasses)
markClass = ast.MarkClass(newClassName)
markClasses[newClassName] = markClass
glyphName = ast.GlyphName(glyphName)
mcdef = ast.MarkClassDefinition(markClass, anchor, glyphName)
markClass.addDefinition(mcdef)
return mcdef
def __init__(self, side1, side2, value, directions=None, bidiTypes=None):
if isinstance(side1, basestring):
self.side1 = ast.GlyphName(side1)
elif isinstance(side1, ast.GlyphClassDefinition):
self.side1 = ast.GlyphClassName(side1)
else:
raise AssertionError(side1)
if isinstance(side2, basestring):
self.side2 = ast.GlyphName(side2)
elif isinstance(side2, ast.GlyphClassDefinition):
self.side2 = ast.GlyphClassName(side2)
else:
raise AssertionError(side2)
self.value = value
self.directions = directions or set()
self.bidiTypes = bidiTypes or set()
def asAST(self):
marks = self._marksAsAST()
return self.Statement(ast.GlyphName(self.name), marks)