summaryrefslogtreecommitdiff
path: root/scripts/lib/fontbuild
diff options
context:
space:
mode:
authorRoozbeh Pournader <roozbeh@google.com>2014-07-31 18:04:58 -0700
committerRoozbeh Pournader <roozbeh@google.com>2014-07-31 18:04:58 -0700
commit8f7caa4ca489caca851ec0d8426d7857b6d7a051 (patch)
treecfd797651152bf7c8d75f0e8e02abd665266dcce /scripts/lib/fontbuild
parenteea9030fef36f1ff05e0d7dc7b28c9cc26dcd53f (diff)
Updated build scripts based on July 28 deliveries from ParaType.
Diffstat (limited to 'scripts/lib/fontbuild')
-rw-r--r--scripts/lib/fontbuild/Build.py39
-rwxr-xr-xscripts/lib/fontbuild/features.py16
-rwxr-xr-xscripts/lib/fontbuild/markFeature.py93
-rwxr-xr-xscripts/lib/fontbuild/mkmkFeature.py69
4 files changed, 214 insertions, 3 deletions
diff --git a/scripts/lib/fontbuild/Build.py b/scripts/lib/fontbuild/Build.py
index cc858d3..6afc08f 100644
--- a/scripts/lib/fontbuild/Build.py
+++ b/scripts/lib/fontbuild/Build.py
@@ -7,6 +7,9 @@ from fontbuild.mitreGlyph import mitreGlyph
from fontbuild.generateGlyph import generateGlyph
from fontTools.misc.transform import Transform
from fontbuild.kerning import generateFLKernClassesFromOTString
+from fontbuild.features import CreateFeaFile
+from fontbuild.markFeature import GenerateFeature_mark
+from fontbuild.mkmkFeature import GenerateFeature_mkmk
import ConfigParser
import os
@@ -34,6 +37,8 @@ class FontProject:
self.deleteList = self.config.get("glyphs","delete").split()
self.buildnumber = self.loadBuildNumber()
+ self.buldVFBandFEA = False
+
def loadBuildNumber(self):
versionFile = open(self.basedir + "/" + self.config.get("main","buildnumberfile"), "r+")
@@ -137,17 +142,45 @@ class FontProject:
build=self.buildnumber)
cleanCurves(f)
deleteGlyphs(f,self.deleteList)
+
if kern:
+ log(">> Generating kern classes")
generateFLKernClassesFromOTString(f,self.ot_kerningclasses)
- log(">> Generating font files")
+ kern = f.MakeKernFeature()
+ kern_exist = False
+ for fea_id in range (len(f.features)):
+ if "kern" == f.features[fea_id].tag:
+ f.features[fea_id] = kern
+ kern_exist = True
+ if (False == kern_exist):
+ f.features.append(kern)
+
directoryName = n[0].replace(" ","")
+
+ if self.buldVFBandFEA:
+ log(">> Generating VFB files")
+ directoryPath = "%s/%s/%sVFB"%(self.basedir,self.builddir,directoryName)
+ if not os.path.exists(directoryPath):
+ os.makedirs(directoryPath)
+ flName = "%s/%s.vfb"%(directoryPath,f.font_name)
+ fl.GenerateFont(fl.ifont,ftFONTLAB,flName)
+
+ log(">> Generating font files")
directoryPath = "%s/%s/%sTTF"%(self.basedir,self.builddir,directoryName)
if not os.path.exists(directoryPath):
- os.makedirs(directoryPath)
+ os.makedirs(directoryPath)
ttfName = "%s/%s.ttf"%(directoryPath,f.font_name)
fl.GenerateFont(fl.ifont,ftTRUETYPE,ttfName)
+
+ if self.buldVFBandFEA:
+ log(">> Generating FEA files")
+ GenerateFeature_mark(f)
+ GenerateFeature_mkmk(f)
+ feaName = "%s/%s.fea"%(directoryPath,f.font_name)
+ CreateFeaFile(f, feaName)
+
f.modified = 0
- fl.Close(index)
+ #fl.Close(index)
def transformGlyphMembers(g, m):
g.width = int(g.width * m.a)
diff --git a/scripts/lib/fontbuild/features.py b/scripts/lib/fontbuild/features.py
new file mode 100755
index 0000000..0e89a57
--- /dev/null
+++ b/scripts/lib/fontbuild/features.py
@@ -0,0 +1,16 @@
+import string
+from FL import *
+
+def CreateFeaFile(font, path):
+ fea_text = font.ot_classes
+ for cls in font.classes:
+ text = "@" + cls + "];\n"
+ text = string.replace(text, ":", "= [")
+ text = string.replace(text, "\'", "")
+ fea_text += text
+ for fea in font.features:
+ fea_text += fea.value
+ fea_text = string.replace(fea_text, "\r\n", "\n")
+ fout = open(path, "w")
+ fout.write(fea_text)
+ fout.close() \ No newline at end of file
diff --git a/scripts/lib/fontbuild/markFeature.py b/scripts/lib/fontbuild/markFeature.py
new file mode 100755
index 0000000..9d7401a
--- /dev/null
+++ b/scripts/lib/fontbuild/markFeature.py
@@ -0,0 +1,93 @@
+from FL import *
+
+aliases = [["uni0430", "a"], ["uni0435", "e"], ["uni0440", "p"], ["uni0441", "c"], ["uni0445", "x"], ["uni0455", "s"], ["uni0456", "i"], ["uni0471", "psi"]]
+
+def GetAliaseName(gname):
+ for i in range (len(aliases)):
+ if (gname == aliases[i][1]):
+ return aliases[i][0]
+ return None
+
+def CreateAccNameList(font, acc_anchor_name):
+ lst = []
+ for g in font.glyphs:
+ for anchor in g.anchors:
+ if acc_anchor_name == anchor.name:
+ lst.append(g.name)
+ return lst
+
+def CreateAccGlyphList(font, acc_list, acc_anchor_name):
+ g_list = []
+ for g in font.glyphs:
+ if g.name in acc_list:
+ for anchor in g.anchors:
+ if acc_anchor_name == anchor.name:
+ g_list.append([g.name, anchor.x, anchor.y])
+ break
+ return g_list
+
+
+def CreateGlyphList(font, acc_list, anchor_name):
+ g_list = []
+ for g in font.glyphs:
+ if g.name in acc_list:
+ continue
+ for anchor in g.anchors:
+ if anchor_name == anchor.name:
+ g_list.append([g.name, anchor.x, anchor.y])
+ break
+ return g_list
+
+def Create_mark_lookup(accent_g_list, base_g_list, lookupname, acc_class):
+ txt = "lookup " + lookupname + " {\n"
+
+ for acc in accent_g_list:
+ txt += " markClass " + acc[0] + " <anchor " + `acc[1]` + " " + `acc[2]` + "> " + acc_class +";\n"
+
+ for base in base_g_list:
+ txt += " pos base " + base[0] + " <anchor " + `base[1]` + " " + `base[2]` + "> mark " + acc_class + ";\n"
+ base2 = GetAliaseName(base[0])
+ if (None == base2):
+ continue
+ txt += " pos base " + base2 + " <anchor " + `base[1]` + " " + `base[2]` + "> mark " + acc_class + ";\n"
+
+ txt += "} " + lookupname + ";\n"
+
+ return txt
+
+##### main ##############
+def GenerateFeature_mark(font):
+ text = "feature mark {\n"
+
+ accent_name_list = []
+ accent_mark_list = []
+ base_mark_list = []
+ anchor_name = "top"
+ acc_anchor_name = "_mark" + anchor_name
+ accent_name_list = CreateAccNameList(font, acc_anchor_name)
+ accent_mark_list = CreateAccGlyphList(font, accent_name_list, acc_anchor_name)
+ base_mark_list = CreateGlyphList(font, accent_name_list, anchor_name)
+ text += Create_mark_lookup(accent_mark_list, base_mark_list, "mark1", "@MC_top")
+
+ accent_name_list = []
+ accent_mark_list = []
+ base_mark_list = []
+ anchor_name = "bottom"
+ acc_anchor_name = "_mark" + anchor_name
+ accent_name_list = CreateAccNameList(font, acc_anchor_name)
+ accent_mark_list = CreateAccGlyphList(font, accent_name_list, acc_anchor_name)
+ base_mark_list = CreateGlyphList(font, accent_name_list, anchor_name)
+ text += Create_mark_lookup(accent_mark_list, base_mark_list, "mark2", "@MC_bottom")
+
+
+ text += "} mark;\n"
+ mark = Feature("mark", text)
+
+ not_exist = True
+ for n in range(len(font.features)):
+ if ('mark' == font.features[n].tag):
+ font.features[n] = mark
+ not_exist = False
+
+ if (not_exist):
+ font.features.append(mark)
diff --git a/scripts/lib/fontbuild/mkmkFeature.py b/scripts/lib/fontbuild/mkmkFeature.py
new file mode 100755
index 0000000..b7281c6
--- /dev/null
+++ b/scripts/lib/fontbuild/mkmkFeature.py
@@ -0,0 +1,69 @@
+from FL import *
+
+def CreateAccNameList(font, acc_anchor_name):
+ lst = []
+ for g in font.glyphs:
+ for anchor in g.anchors:
+ if acc_anchor_name == anchor.name:
+ lst.append(g.name)
+ return lst
+
+def CreateAccGlyphList(font, acc_list, acc_anchor_name):
+ g_list = []
+ for g in font.glyphs:
+ if g.name in acc_list:
+ for anchor in g.anchors:
+ if acc_anchor_name == anchor.name:
+ g_list.append([g.name, anchor.x, anchor.y])
+ break
+ return g_list
+
+
+def CreateGlyphList(font, acc_list, anchor_name):
+ g_list = []
+ for g in font.glyphs:
+ for anchor in g.anchors:
+ if anchor_name == anchor.name:
+ g_list.append([g.name, anchor.x, anchor.y])
+ break
+ return g_list
+
+def Create_mkmk1(accent_g_list, base_g_list, lookupname):
+ txt = "lookup " + lookupname + " {\n"
+ acc_class = "@MC_mkmk"
+ for acc in accent_g_list:
+ txt += " markClass " + acc[0] + " <anchor " + `acc[1]` + " " + `acc[2]` + "> " + acc_class +";\n"
+
+ for base in base_g_list:
+ txt += " pos mark " + base[0] + " <anchor " + `base[1]` + " " + `base[2]` + "> mark " + acc_class + ";\n"
+
+ txt += "} " + lookupname + ";\n"
+
+ return txt
+
+
+##### main ##############
+def GenerateFeature_mkmk(font):
+ text = "feature mkmk {\n"
+
+ accent_name_list = []
+ accent_mark_list = []
+ base_mark_list = []
+ anchor_name = "mkmktop"
+ acc_anchor_name = "_marktop"
+ accent_name_list = CreateAccNameList(font, acc_anchor_name)
+ accent_mark_list = CreateAccGlyphList(font, accent_name_list, acc_anchor_name)
+ base_mark_list = CreateGlyphList(font, accent_name_list, anchor_name)
+ text += Create_mkmk1(accent_mark_list, base_mark_list, "mkmk1")
+
+ text += "} mkmk;\n"
+ mkmk = Feature("mkmk", text)
+
+ not_exist = True
+ for n in range(len(font.features)):
+ if ('mkmk' == font.features[n].tag):
+ font.features[n] = mkmk
+ not_exist = False
+
+ if (not_exist):
+ font.features.append(mkmk)