|
@@ -14,21 +14,23 @@
|
|
|
|
|
|
|
|
|
import re
|
|
|
-from anchors import alignComponentsToAnchors
|
|
|
from string import find
|
|
|
|
|
|
+from anchors import alignComponentsToAnchors, getAnchorByName
|
|
|
+
|
|
|
+
|
|
|
def parseComposite(composite):
|
|
|
c = composite.split("=")
|
|
|
d = c[1].split("/")
|
|
|
glyphName = d[0]
|
|
|
if len(d) == 1:
|
|
|
- offset = [0,0]
|
|
|
+ offset = [0, 0]
|
|
|
else:
|
|
|
offset = [int(i) for i in d[1].split(",")]
|
|
|
accentString = c[0]
|
|
|
accents = accentString.split("+")
|
|
|
baseName = accents.pop(0)
|
|
|
- accentNames = [i.split(":") for i in accents ]
|
|
|
+ accentNames = [i.split(":") for i in accents]
|
|
|
return (glyphName, baseName, accentNames, offset)
|
|
|
|
|
|
|
|
@@ -38,11 +40,7 @@ def copyMarkAnchors(f, g, srcname, width):
|
|
|
[0x430, 0x435, 0x440, 0x441, 0x445, 0x455, 0x456, 0x471])
|
|
|
|
|
|
for anchor in f[srcname].anchors:
|
|
|
- if "top_dd" == anchor.name:
|
|
|
- g.appendAnchor(anchor.name, (anchor.x + width, anchor.y))
|
|
|
- if "bottom_dd" == anchor.name:
|
|
|
- g.appendAnchor(anchor.name, (anchor.x + width, anchor.y))
|
|
|
- if "top0315" == anchor.name:
|
|
|
+ if anchor.name in ("top_dd", "bottom_dd", "top0315"):
|
|
|
g.appendAnchor(anchor.name, (anchor.x + width, anchor.y))
|
|
|
|
|
|
if ("top" == anchor.name and
|
|
@@ -59,8 +57,7 @@ def copyMarkAnchors(f, g, srcname, width):
|
|
|
if any(a.name == "top" for a in g.anchors):
|
|
|
return
|
|
|
|
|
|
- anchor_parent_top = next(
|
|
|
- (a for a in g.anchors if a.name == "parent_top"), None)
|
|
|
+ anchor_parent_top = getAnchorByName(g, "parent_top")
|
|
|
if anchor_parent_top is not None:
|
|
|
g.appendAnchor("top", anchor_parent_top.position)
|
|
|
|
|
@@ -75,25 +72,25 @@ def generateGlyph(f,gname,glyphList={}):
|
|
|
g.width += f[componentName].width
|
|
|
setUnicodeValue(g, glyphList)
|
|
|
|
|
|
- else:
|
|
|
- if not f.has_key(glyphName):
|
|
|
- try:
|
|
|
- f.compileGlyph(glyphName, baseName, accentNames)
|
|
|
- except KeyError as e:
|
|
|
- print ("KeyError raised for composition rule '%s', likely %s "
|
|
|
- "anchor not found in glyph '%s'" % (gname, e, baseName))
|
|
|
- return
|
|
|
- g = f[glyphName]
|
|
|
- setUnicodeValue(g, glyphList)
|
|
|
- copyMarkAnchors(f, g, baseName, offset[1] + offset[0])
|
|
|
- if len(accentNames) > 0:
|
|
|
- alignComponentsToAnchors(f, glyphName, baseName, accentNames)
|
|
|
- if offset[0] != 0 or offset[1] != 0:
|
|
|
- g.width += offset[1] + offset[0]
|
|
|
- g.move((offset[0], 0), anchors=False)
|
|
|
- else:
|
|
|
- print ("Existing glyph '%s' found in font, ignoring composition "
|
|
|
- "rule '%s'" % (glyphName, gname))
|
|
|
+ else:
|
|
|
+ if f.has_key(glyphName):
|
|
|
+ print('Existing glyph "%s" found in font, ignoring composition '
|
|
|
+ 'rule "%s"' % (glyphName, gname))
|
|
|
+ return
|
|
|
+ try:
|
|
|
+ f.compileGlyph(glyphName, baseName, accentNames)
|
|
|
+ except KeyError as e:
|
|
|
+ print('KeyError raised for composition rule "%s", likely "%s" '
|
|
|
+ 'anchor not found in glyph "%s"' % (gname, e, baseName))
|
|
|
+ return
|
|
|
+ g = f[glyphName]
|
|
|
+ setUnicodeValue(g, glyphList)
|
|
|
+ copyMarkAnchors(f, g, baseName, offset[1] + offset[0])
|
|
|
+ if len(accentNames) > 0:
|
|
|
+ alignComponentsToAnchors(f, glyphName, baseName, accentNames)
|
|
|
+ if offset[0] != 0 or offset[1] != 0:
|
|
|
+ g.width += offset[1] + offset[0]
|
|
|
+ g.move((offset[0], 0), anchors=False)
|
|
|
|
|
|
|
|
|
def setUnicodeValue(glyph, glyphList):
|