summaryrefslogtreecommitdiff
path: root/scripts/lib/fontbuild/generateGlyph.py
diff options
context:
space:
mode:
authorChristian Robertson <robertsonc@google.com>2014-05-19 16:09:20 -0700
committerChristian Robertson <robertsonc@google.com>2014-05-19 16:09:20 -0700
commit7051939fa74b5f8f453be605f5dc3b4c23e1d1d9 (patch)
tree65cb31b34a64b2b07f9f6fd1bcb58d9a4945a92d /scripts/lib/fontbuild/generateGlyph.py
Importing Roboto 2.0
Diffstat (limited to 'scripts/lib/fontbuild/generateGlyph.py')
-rwxr-xr-xscripts/lib/fontbuild/generateGlyph.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/scripts/lib/fontbuild/generateGlyph.py b/scripts/lib/fontbuild/generateGlyph.py
new file mode 100755
index 0000000..f2214f0
--- /dev/null
+++ b/scripts/lib/fontbuild/generateGlyph.py
@@ -0,0 +1,48 @@
+from anchors import alignComponentsToAnchors
+from FL import *
+
+def parseComposite(composite):
+ c = composite.split("=")
+ d = c[1].split("/")
+ glyphName = d[0]
+ if len(d) == 1:
+ 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 ]
+ return (glyphName, baseName, accentNames, offset)
+
+def shiftGlyphMembers(g, x):
+ g.Shift(Point(x,0))
+ for c in g.components:
+ c.deltas[0].x = c.deltas[0].x + x
+
+def generateGlyph(f,gname):
+ if gname.find("_") != -1:
+ generateString = gname
+ g = f.GenerateGlyph(generateString)
+ if f.FindGlyph(g.name) == -1:
+ f.glyphs.append(g)
+ return g
+ else:
+ glyphName, baseName, accentNames, offset = parseComposite(gname)
+ components = [baseName] + [i[0] for i in accentNames]
+ if len(components) == 1:
+ components.append("NONE")
+ generateString = "%s=%s" %("+".join(components), glyphName)
+ g = f.GenerateGlyph(generateString)
+ if f.FindGlyph(g.name) == -1:
+ f.glyphs.append(g)
+ g1 = f.glyphs[f.FindGlyph(g.name)]
+ if len(accentNames) > 0:
+ alignComponentsToAnchors(f,glyphName,baseName,accentNames)
+ if (offset[0] != 0 or offset[1] != 0):
+ g1.width += offset[1] + offset[0]
+ shiftGlyphMembers(g1,offset[0])
+ return g
+
+# generateGlyph(fl.font,"A+ogonek=Aogonek")
+# fl.UpdateFont() \ No newline at end of file