summaryrefslogtreecommitdiff
path: root/scripts/lib
diff options
context:
space:
mode:
authorJames Godfrey-Kittle <jamesgk@google.com>2015-04-08 16:14:56 -0700
committerJames Godfrey-Kittle <jamesgk@google.com>2015-04-16 12:16:33 -0700
commit56ad4064e8eeff6c320952daef8767188ae7fa63 (patch)
tree5907c6682cb65a0c2ad778605376e95ba8dc436b /scripts/lib
parent40f2f9fdaa46d1773ebc805150da70c9acfeac3e (diff)
Update scripts based on 03/31 delivery.
Diffstat (limited to 'scripts/lib')
-rw-r--r--scripts/lib/fontbuild/Build.py5
-rw-r--r--scripts/lib/fontbuild/anchors.py33
-rw-r--r--scripts/lib/fontbuild/generateGlyph.py42
-rw-r--r--scripts/lib/fontbuild/instanceNames.py27
-rw-r--r--scripts/lib/fontbuild/italics.py5
-rwxr-xr-xscripts/lib/fontbuild/markFeature.py67
-rwxr-xr-xscripts/lib/fontbuild/mkmkFeature.py16
7 files changed, 154 insertions, 41 deletions
diff --git a/scripts/lib/fontbuild/Build.py b/scripts/lib/fontbuild/Build.py
index 5c6ffca..0e1e35d 100644
--- a/scripts/lib/fontbuild/Build.py
+++ b/scripts/lib/fontbuild/Build.py
@@ -29,7 +29,7 @@ class FontProject:
self.diacriticList = [line.strip() for line in diacriticList if not line.startswith("#")]
self.ot_classes = open(self.basedir + "/" + self.config.get("res","ot_classesfile")).read()
self.ot_kerningclasses = open(self.basedir + "/" + self.config.get("res","ot_kerningclassesfile")).read()
- self.ot_features = open(self.basedir + "/" + self.config.get("res","ot_featuresfile")).read()
+ #self.ot_features = open(self.basedir + "/" + self.config.get("res","ot_featuresfile")).read()
adobeGlyphList = open(self.basedir + "/" + self.config.get("res", "agl_glyphlistfile")).readlines()
self.adobeGlyphList = dict([line.split(";") for line in adobeGlyphList if not line.startswith("#")])
@@ -126,7 +126,8 @@ class FontProject:
elif g.name != ".notdef":
italicizeGlyph(f, g, 10, stemWidth=stemWidth)
removeGlyphOverlap(g)
- g.width += 10
+ if g.width != 0:
+ g.width += 10
if swapSuffixes != None:
for swap in swapSuffixes:
diff --git a/scripts/lib/fontbuild/anchors.py b/scripts/lib/fontbuild/anchors.py
index d82ffa7..fe3e280 100644
--- a/scripts/lib/fontbuild/anchors.py
+++ b/scripts/lib/fontbuild/anchors.py
@@ -13,6 +13,37 @@ def getAnchorByName(g,anchorName):
return a
+def moveMarkAnchors(f, g, anchorName, accentName, dx, dy):
+ if "top"==anchorName:
+ anchors = f[accentName].anchors
+ for anchor in anchors:
+ if "mkmktop_acc" == anchor.name:
+ anchor2 = Anchor()
+ #print anchor.x, dx, anchor.y, dy
+ anchor2.name = "top"
+ anchor2.x = anchor.x + int(dx)
+ anchor2.y = anchor.y + int(dy)
+ g.anchors.append(anchor2)
+
+ elif "bottom"==anchorName:
+ anchors = f[accentName].anchors
+ for anchor in anchors:
+ if "mkmkbottom_acc" == anchor.name:
+ for n in range(len(g.anchors)):
+ if g.anchors[n].name == "bottom":
+ del g.anchors[n]
+ break
+ anchor2 = Anchor()
+ #print anchor.x, dx, anchor.y, dy
+ anchor2.name = "bottom"
+ anchor2.x = anchor.x + int(dx)
+ anchor2.y = anchor.y + int(dy)
+ for anc in anchors:
+ if "top" == anc.name:
+ anchor2.x = anc.x + int(dx)
+ g.anchors.append(anchor2)
+
+
def alignComponentToAnchor(f,glyphName,baseName,accentName,anchorName):
g = getGlyph(glyphName,f)
base = getGlyph(baseName,f)
@@ -26,6 +57,8 @@ def alignComponentToAnchor(f,glyphName,baseName,accentName,anchorName):
offset = (a1.x - a2.x, a1.y - a2.y)
c = getComponentByName(f, g, accentName)
c.offset = offset
+ moveMarkAnchors(f, g, anchorName, accentName, offset.x, offset.y)
+
def alignComponentsToAnchors(f,glyphName,baseName,accentNames):
for a in accentNames:
diff --git a/scripts/lib/fontbuild/generateGlyph.py b/scripts/lib/fontbuild/generateGlyph.py
index 4794fd8..4702631 100644
--- a/scripts/lib/fontbuild/generateGlyph.py
+++ b/scripts/lib/fontbuild/generateGlyph.py
@@ -16,6 +16,43 @@ def parseComposite(composite):
return (glyphName, baseName, accentNames, offset)
+def copyMarkAnchors(f, g, srcname, width):
+ anchors = f[srcname].anchors
+ for anchor in anchors:
+ if "top_dd" == anchor.name:
+ anchor1 = Anchor(anchor)
+ anchor1.x += width
+ g.anchors.append(anchor1)
+ if "bottom_dd" == anchor.name:
+ anchor1 = Anchor(anchor)
+ anchor1.x += width
+ g.anchors.append(anchor1)
+ if "top0315" == anchor.name:
+ anchor1 = Anchor(anchor)
+ anchor1.x += width
+ g.anchors.append(anchor1)
+ if "top" == anchor.name:
+ if g.unicode == None:
+ continue
+ if g.unicode > 0x02B0:
+ continue
+ parenttop_present = 0
+ for anc in g.anchors:
+ if anc.name == "parent_top":
+ parenttop_present = 1
+ if parenttop_present:
+ continue
+ anchor1 = Anchor(anchor)
+ anchor1.name = "parent_top"
+# anchor1.x += width
+ g.anchors.append(anchor1)
+
+ # if "rhotichook" == anchor.name:
+ # anchor1 = Anchor(anchor)
+ # anchor1.x += width
+ # g.anchors.append(anchor1)
+
+
def generateGlyph(f,gname,glyphList={}):
glyphName, baseName, accentNames, offset = parseComposite(gname)
@@ -34,11 +71,12 @@ def generateGlyph(f,gname,glyphList={}):
"anchor not found in glyph '%s'" % (gname, e, baseName))
return
g = f[glyphName]
- if len(accentNames) > 0:
- alignComponentsToAnchors(f, glyphName, baseName, accentNames)
+ copyMarkAnchors(f, g, baseName, offset[1] + offset[0])
if offset[0] != 0 or offset[1] != 0:
g.width += offset[1] + offset[0]
g.move((offset[0], 0))
+ if len(accentNames) > 0:
+ alignComponentsToAnchors(f, glyphName, baseName, accentNames)
else:
print ("Existing glyph '%s' found in font, ignoring composition "
"rule '%s'" % (glyphName, gname))
diff --git a/scripts/lib/fontbuild/instanceNames.py b/scripts/lib/fontbuild/instanceNames.py
index 253779c..a05f5e4 100644
--- a/scripts/lib/fontbuild/instanceNames.py
+++ b/scripts/lib/fontbuild/instanceNames.py
@@ -17,7 +17,7 @@ class InstanceNames:
def __init__(self,names):
if type(names) == type(" "):
names = names.split("/")
-
+ #print names
self.longfamily = names[0]
self.longstyle = names[1]
self.shortstyle = names[2]
@@ -84,21 +84,29 @@ class InstanceNames:
flFont.weight = self.weight
flFont.weight_code = self._getWeightCode(self.weight)
flFont.width = self.width
+ if len(self.italic):
+ flFont.italic_angle = -12
fn = flFont.fontnames
fn.clean()
- fn.append(NameRecord(0,1,0,0, "Font data copyright %s %s" %(self.foundry, self.year) ))
- fn.append(NameRecord(0,3,1,1033, "Font data copyright %s %s" %(self.foundry, self.year) ))
+ #fn.append(NameRecord(0,1,0,0, "Font data copyright %s %s" %(self.foundry, self.year) ))
+ #fn.append(NameRecord(0,3,1,1033, "Font data copyright %s %s" %(self.foundry, self.year) ))
+ fn.append(NameRecord(0,1,0,0, "Copyright %s %s Inc. All Rights Reserved." %(self.year, self.foundry) ))
+ fn.append(NameRecord(0,3,1,1033, "Copyright %s %s Inc. All Rights Reserved." %(self.year, self.foundry) ))
fn.append(NameRecord(1,1,0,0, self.longfamily ))
fn.append(NameRecord(1,3,1,1033, self.shortfamily ))
fn.append(NameRecord(2,1,0,0, self.longstyle ))
fn.append(NameRecord(2,3,1,1033, self.longstyle ))
- fn.append(NameRecord(3,1,0,0, "%s:%s:%s" %(self.foundry, self.longfamily, self.year) ))
- fn.append(NameRecord(3,3,1,1033, "%s:%s:%s" %(self.foundry, self.longfamily, self.year) ))
+ #fn.append(NameRecord(3,1,0,0, "%s:%s:%s" %(self.foundry, self.longfamily, self.year) ))
+ #fn.append(NameRecord(3,3,1,1033, "%s:%s:%s" %(self.foundry, self.longfamily, self.year) ))
+ fn.append(NameRecord(3,1,0,0, "%s:%s:%s" %(self.foundry, self.fullname, self.year) ))
+ fn.append(NameRecord(3,3,1,1033, "%s:%s:%s" %(self.foundry, self.fullname, self.year) ))
fn.append(NameRecord(4,1,0,0, self.fullname ))
fn.append(NameRecord(4,3,1,1033, self.fullname ))
- fn.append(NameRecord(5,1,0,0, "Version %s%s; %s" %(self.version, self.build, self.year) ))
- fn.append(NameRecord(5,3,1,1033, "Version %s%s; %s" %(self.version, self.build, self.year) ))
+ #fn.append(NameRecord(5,1,0,0, "Version %s%s; %s" %(self.version, self.build, self.year) ))
+ #fn.append(NameRecord(5,3,1,1033, "Version %s%s; %s" %(self.version, self.build, self.year) ))
+ fn.append(NameRecord(5,1,0,0, "Version %s; %s" %(self.version, self.year) ))
+ fn.append(NameRecord(5,3,1,1033, "Version %s; %s" %(self.version, self.year) ))
fn.append(NameRecord(6,1,0,0, self.postscript ))
fn.append(NameRecord(6,3,1,1033, self.postscript ))
fn.append(NameRecord(7,1,0,0, "%s is a trademark of %s." %(self.longfamily, self.foundry) ))
@@ -131,7 +139,7 @@ class InstanceNames:
return self._getSubstyle(r"Italic|Oblique|Obliq")
def _getWeight(self):
- w = self._getSubstyle(r"Extrabold|Superbold|Super|Fat|Bold|Semibold|Demibold|Medium|Light|Thin")
+ w = self._getSubstyle(r"Extrabold|Superbold|Super|Fat|Black|Bold|Semibold|Demibold|Medium|Light|Thin")
if w == "":
w = "Regular"
return w
@@ -143,6 +151,7 @@ class InstanceNames:
return w
def _getStyleCode(self):
+ #print "shortstyle:", self.shortstyle
styleCode = 0
if self.shortstyle == "Bold":
styleCode = 32
@@ -166,7 +175,7 @@ class InstanceNames:
elif weight == "Semibold":
return 600
elif weight == "Black":
- return 800
+ return 900
elif weight == "Fat":
return 900
diff --git a/scripts/lib/fontbuild/italics.py b/scripts/lib/fontbuild/italics.py
index 86bdc53..77e205a 100644
--- a/scripts/lib/fontbuild/italics.py
+++ b/scripts/lib/fontbuild/italics.py
@@ -6,6 +6,8 @@ import math
from alignpoints import alignCorners
def italicizeGlyph(f, g, angle=10, stemWidth=185):
+ unic = g.unicode #save unicode
+
glyph = f[g.name]
slope = np.tanh(math.pi * angle / 180)
@@ -23,6 +25,9 @@ def italicizeGlyph(f, g, angle=10, stemWidth=185):
transformFLGlyphMembers(f[g.name], m)
+ if unic > 0xFFFF: #restore unicode
+ g.unicode = unic
+
def italicize(glyph, angle=12, stemWidth=180, xoffset=-50):
CURVE_CORRECTION_WEIGHT = .03
diff --git a/scripts/lib/fontbuild/markFeature.py b/scripts/lib/fontbuild/markFeature.py
index e2e36c1..f3ba7c4 100755
--- a/scripts/lib/fontbuild/markFeature.py
+++ b/scripts/lib/fontbuild/markFeature.py
@@ -9,9 +9,12 @@ def GetAliaseName(gname):
return aliases[i][0]
return None
-def CreateAccNameList(font, acc_anchor_name):
+def CreateAccNameList(font, acc_anchor_name, bCombAccentOnly = True):
+ #combrange = range(0x0300,0x0370) + range(0x1AB0,0x1ABF) + range(0x1DC0,0x1DE0)
lst = []
for g in font:
+ if bCombAccentOnly and g.width != 0: #((g.unicode < 0x0300) or (g.unicode > 0x362)):
+ continue
for anchor in g.anchors:
if acc_anchor_name == anchor.name:
lst.append(g.name)
@@ -39,7 +42,7 @@ def CreateGlyphList(font, acc_list, anchor_name):
break
return g_list
-def Create_mark_lookup(accent_g_list, base_g_list, lookupname, acc_class):
+def Create_mark_lookup(accent_g_list, base_g_list, lookupname, acc_class, lookAliases = True):
txt = "lookup " + lookupname + " {\n"
for acc in accent_g_list:
@@ -47,10 +50,11 @@ def Create_mark_lookup(accent_g_list, base_g_list, lookupname, acc_class):
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"
+ if (lookAliases):
+ base2 = GetAliaseName(base[0])
+ if (None == base2):
+ continue
+ txt += " pos base " + base2 + " <anchor " + `base[1]` + " " + `base[2]` + "> mark " + acc_class + ";\n"
txt += "} " + lookupname + ";\n"
@@ -58,27 +62,40 @@ def Create_mark_lookup(accent_g_list, base_g_list, lookupname, acc_class):
##### main ##############
def GenerateFeature_mark(font):
+
+ combination_anchor_list = [
+ ["top", "_marktop", True, True],
+ ["bottom", "_markbottom", True, True],
+ ["top_dd", "_marktop_dd", True, False],
+ ["bottom_dd", "_markbottom_dd", True, False],
+ ["rhotichook", "_markrhotichook", False, False],
+ ["top0315", "_marktop0315", False, False],
+ ["parent_top", "_markparent_top", False, False],
+ ["parenthesses.w1", "_markparenthesses.w1", False, False],
+ ["parenthesses.w2", "_markparenthesses.w2", False, False],
+ ["parenthesses.w3", "_markparenthesses.w3", False, False]
+ ]
+
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")
+ for n in range(len(combination_anchor_list)):
+
+ accent_name_list = []
+ accent_mark_list = []
+ base_mark_list = []
+
+ anchors_pair = combination_anchor_list[n]
+ anchor_name = anchors_pair[0]
+ acc_anchor_name = anchors_pair[1]
+ comb_accent_only = anchors_pair[2]
+ expand_to_composits = anchors_pair[3]
+ lookupname = "mark"+`n+1`
+ classname = "@MC_" + anchor_name
+
+ accent_name_list = CreateAccNameList(font, acc_anchor_name, comb_accent_only)
+ 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, lookupname, classname, expand_to_composits)
text += "} mark;\n"
diff --git a/scripts/lib/fontbuild/mkmkFeature.py b/scripts/lib/fontbuild/mkmkFeature.py
index a839dae..7a05077 100755
--- a/scripts/lib/fontbuild/mkmkFeature.py
+++ b/scripts/lib/fontbuild/mkmkFeature.py
@@ -29,9 +29,9 @@ def CreateGlyphList(font, acc_list, anchor_name):
break
return g_list
-def Create_mkmk1(accent_g_list, base_g_list, lookupname):
+def Create_mkmk1(accent_g_list, base_g_list, lookupname, acc_class):
txt = "lookup " + lookupname + " {\n"
- acc_class = "@MC_mkmk"
+ #acc_class = "@MC_mkmk"
for acc in accent_g_list:
txt += " markClass " + acc[0] + " <anchor " + `acc[1]` + " " + `acc[2]` + "> " + acc_class +";\n"
@@ -55,7 +55,17 @@ def GenerateFeature_mkmk(font):
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 += Create_mkmk1(accent_mark_list, base_mark_list, "mkmk1", "@MC_mkmk_top")
+
+ accent_name_list = []
+ accent_mark_list = []
+ base_mark_list = []
+ anchor_name = "mkmkbottom_acc"
+ acc_anchor_name = "_markbottom"
+ 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, "mkmk2", "@MC_mkmk_bottom")
text += "} mkmk;\n"