summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md45
-rw-r--r--scripts/build-v2.py9
-rw-r--r--scripts/lib/fontbuild/Build.py103
-rw-r--r--scripts/lib/fontbuild/kerning.py112
-rwxr-xr-xscripts/lib/fontbuild/markFeature.py132
-rwxr-xr-xscripts/lib/fontbuild/mkmkFeature.py87
6 files changed, 99 insertions, 389 deletions
diff --git a/README.md b/README.md
index 039db7e..08681f6 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,8 @@ cd $HOME/roboto-src
```bash
git clone https://github.com/google/roboto.git
git clone https://github.com/behdad/fonttools.git
+git clone https://github.com/googlei18n/cu2qu.git
+git clone https://github.com/jamesgk/ufo2ft.git
git clone https://github.com/robofab-developers/robofab.git
git clone https://github.com/typesupply/feaTools.git
git clone https://github.com/typemytype/booleanOperations.git
@@ -39,11 +41,7 @@ via:
sudo apt-get install cython
```
-##### For OTF generation:
-
-```bash
-git clone https://github.com/typesupply/ufo2fdk.git
-```
+##### For OTF/TTF generation:
To build the FDK yourself:
@@ -59,12 +57,6 @@ If you're not building the FDK yourself, download the pre-built version
[here](http://www.adobe.com/devnet/opentype/afdko.html) and unzip it into the
current directory.
-##### For TTF generation, on Ubuntu:
-
-```bash
-sudo apt-get install fontforge python-fontforge
-```
-
##### For post-production:
```bash
@@ -85,6 +77,10 @@ You can install the necessary modules at the sytem level:
```bash
cd fonttools
sudo python setup.py install
+cd ../cu2qu
+sudo python setup.py install
+cd ../ufo2ft
+sudo python setup.py install
cd ../robofab
sudo python setup.py install
cd ../feaTools
@@ -100,6 +96,8 @@ Or set `$PYTHONPATH` locally before running `make`:
```bash
PYTHONPATH="$PYTHONPATH:$HOME/roboto-src/fonttools/Lib"
+PYTHONPATH="$PYTHONPATH:$HOME/roboto-src/cu2qu/Lib"
+PYTHONPATH="$PYTHONPATH:$HOME/roboto-src/ufo2ft/Lib"
PYTHONPATH="$PYTHONPATH:$HOME/roboto-src/robofab/Lib"
PYTHONPATH="$PYTHONPATH:$HOME/roboto-src/feaTools/Lib"
PYTHONPATH="$PYTHONPATH:$HOME/roboto-src/booleanOperations/Lib"
@@ -107,18 +105,6 @@ PYTHONPATH="$PYTHONPATH:$HOME/roboto-src/booleanOperations/Lib"
##### For OTF generation:
-```bash
-cd ufo2fdk
-sudo python setup.py install
-cd ..
-```
-
-Or:
-
-```bash
-PYTHONPATH="$PYTHONPATH:$HOME/roboto-src/ufo2fdk/Lib"
-```
-
If building the FDK yourself, follow the instructions in `afdko/FDK/FDK Build Notes.txt`:
```bash
@@ -201,10 +187,11 @@ The Roboto build toolchain depends on:
glyph overlap removal.
- (requires Cython to install: http://cython.org/)
-## OTF Generation
+## OTF/TTF Generation
OTF generation depends on:
-- ufo2fdk (https://github.com/typesupply/ufo2fdk)
+- ufo2ft (https://github.com/jamesgk/ufo2ft)
+- cu2qu (https://github.com/googlei18n/cu2qu)
- Open-source portions of the AFDKO
(https://github.com/adobe-type-tools/afdko/releases)
@@ -213,14 +200,6 @@ the variety which includes closed-source tools
(http://www.adobe.com/devnet/opentype/afdko.html), though these closed-source
portions are not used to build Roboto.
-## TTF Generation
-TTF generation depends on:
-
-- FontForge (https://github.com/fontforge/fontforge)
-
-Whose Python interface should be available on Ubuntu by default via `apt-get
-install fontforge python-fontforge`.
-
## Post-Production
Post-production scripts (most of the code outside of the `fontbuild` directory,
e.g. for testing output) depend on:
diff --git a/scripts/build-v2.py b/scripts/build-v2.py
index 58842d6..0ef86e9 100644
--- a/scripts/build-v2.py
+++ b/scripts/build-v2.py
@@ -91,8 +91,7 @@ proj = FontProject(rg.font, BASEDIR, "res/roboto.cfg", th.ffont)
FAMILYNAME = "Roboto"
proj.buildOTF = True
-#proj.autohintOTF = True
-proj.buildTTF = True
+#proj.compatible = True
proj.generateFont(th.font, "%s/Thin/Regular/Th"%FAMILYNAME)
proj.generateFont(Mix([th, rg], 0.45), "%s/Light/Regular/Lt"%FAMILYNAME)
@@ -119,6 +118,10 @@ proj.generateFont(Mix([rg, bd], RPoint(1.125, 1.0)),
"%s/Black Italic/Bold Italic/Bk"%FAMILYNAME,
italic=True, stemWidth=290)
+# unfortunately some condensed forms (*.cn) of glyphs are not compatible with
+# their original forms, so we can't convert all fonts together compatibly
+proj.generateTTFs()
+
thcn1 = Master(condenseFont(th.font, .84, 40))
cn1 = Master(rg.ffont.addDiff(thcn1.ffont, th.ffont))
bdcn1 = Master(bd.ffont.addDiff(thcn1.ffont, th.ffont))
@@ -143,4 +146,4 @@ proj.generateFont(Mix([cn1, bdcn1], RPoint(0.75, 0.75)),
"%s Condensed/Bold Italic/Bold Italic/Rg"%FAMILYNAME,
italic=True, swapSuffixes=[".cn"], stemWidth=240)
-sys.exit(0)
+proj.generateTTFs()
diff --git a/scripts/lib/fontbuild/Build.py b/scripts/lib/fontbuild/Build.py
index 5d92705..be0b79c 100644
--- a/scripts/lib/fontbuild/Build.py
+++ b/scripts/lib/fontbuild/Build.py
@@ -13,23 +13,24 @@
# limitations under the License.
+import ConfigParser
+import os
+import sys
+
from booleanOperations import BooleanOperationManager
+from cu2qu.rf import fonts_to_quadratic
+from fontTools.misc.transform import Transform
from robofab.world import OpenFont
-from fontbuild.mix import Mix,Master,narrowFLGlyph
+from ufo2ft import compileOTF, compileTTF
+
+from fontbuild.decomposeGlyph import decomposeGlyph
+from fontbuild.features import readFeatureFile, writeFeatureFile
+from fontbuild.generateGlyph import generateGlyph
from fontbuild.instanceNames import setNamesRF
from fontbuild.italics import italicizeGlyph
-from fontbuild.convertCurves import glyphCurvesToQuadratic
+from fontbuild.markFeature import RobotoFeatureCompiler
from fontbuild.mitreGlyph import mitreGlyph
-from fontbuild.generateGlyph import generateGlyph
-from fontTools.misc.transform import Transform
-from fontbuild.kerning import makeKernFeature
-from fontbuild.features import readFeatureFile, writeFeatureFile
-from fontbuild.markFeature import GenerateFeature_mark
-from fontbuild.mkmkFeature import GenerateFeature_mkmk
-from fontbuild.decomposeGlyph import decomposeGlyph
-import ConfigParser
-import os
-import sys
+from fontbuild.mix import Mix,Master,narrowFLGlyph
class FontProject:
@@ -66,8 +67,8 @@ class FontProject:
self.buildnumber = self.loadBuildNumber()
self.buildOTF = False
- self.autohintOTF = False
- self.buildTTF = False
+ self.compatible = False
+ self.generatedFonts = []
def loadBuildNumber(self):
@@ -153,33 +154,49 @@ class FontProject:
setNamesRF(f, n, foundry=self.config.get('main', 'foundry'),
version=self.config.get('main', 'version'))
- cleanCurves(f)
+ if not self.compatible:
+ cleanCurves(f)
deleteGlyphs(f, self.deleteList)
if kern:
log(">> Generating kern classes")
readFeatureFile(f, self.ot_kerningclasses)
- makeKernFeature(f, self.ot_kerningclasses)
log(">> Generating font files")
- GenerateFeature_mark(f)
- GenerateFeature_mkmk(f)
ufoName = self.generateOutputPath(f, "ufo")
f.save(ufoName)
+ self.generatedFonts.append(ufoName)
if self.buildOTF:
log(">> Generating OTF file")
newFont = OpenFont(ufoName)
otfName = self.generateOutputPath(f, "otf")
- builtSuccessfully = saveOTF(newFont, otfName, autohint=self.autohintOTF)
- if not builtSuccessfully:
- sys.exit(1)
+ saveOTF(newFont, otfName)
+
+ def generateTTFs(self):
+ """Build TTF for each font generated since last call to generateTTFs."""
- if self.buildTTF:
- log(">> Generating TTF file")
- import fontforge
- otFont = fontforge.open(otfName)
- otFont.generate(self.generateOutputPath(f, "ttf"))
+ fonts = [OpenFont(ufo) for ufo in self.generatedFonts]
+ self.generatedFonts = []
+
+ log(">> Converting curves to quadratic")
+ # using a slightly higher max error (e.g. 0.0025 em), dots will have
+ # fewer control points and look noticeably different
+ max_err = 0.002
+ if self.compatible:
+ fonts_to_quadratic(*fonts, max_err_em=max_err, dump_report=True)
+ else:
+ for font in fonts:
+ fonts_to_quadratic(font, max_err_em=max_err, dump_report=True)
+
+ log(">> Generating TTF files")
+ for font in fonts:
+ ttfName = self.generateOutputPath(font, "ttf")
+ log(os.path.basename(ttfName))
+ for glyph in font:
+ for contour in glyph:
+ contour.reverseContour()
+ saveOTF(font, ttfName, truetype=True)
def transformGlyphMembers(g, m):
@@ -264,30 +281,12 @@ def removeGlyphOverlap(glyph):
manager.union(contours, glyph.getPointPen())
-def saveOTF(font, destFile, autohint=False):
- """Save a RoboFab font as an OTF binary using ufo2fdk.
-
- Returns True on success, False otherwise.
- """
-
- from ufo2fdk import OTFCompiler
-
- # glyphs with multiple unicode values must be split up, due to FontTool's
- # use of a name -> UV dictionary during cmap compilation
- for glyph in font:
- if len(glyph.unicodes) > 1:
- newUV = glyph.unicodes.pop()
- newGlyph = font.newGlyph("uni%04X" % newUV)
- newGlyph.appendComponent(glyph.name)
- newGlyph.unicode = newUV
- newGlyph.width = glyph.width
-
- compiler = OTFCompiler()
- reports = compiler.compile(font, destFile, autohint=autohint)
- if autohint:
- print reports["autohint"]
- print reports["makeotf"]
+def saveOTF(font, destFile, truetype=False):
+ """Save a RoboFab font as an OTF binary using ufo2fdk."""
- successMsg = ("makeotfexe [NOTE] Wrote new font file '%s'." %
- os.path.basename(destFile))
- return successMsg in reports["makeotf"]
+ if truetype:
+ compiler = compileTTF
+ else:
+ compiler = compileOTF
+ otf = compiler(font, featureCompilerClass=RobotoFeatureCompiler)
+ otf.save(destFile)
diff --git a/scripts/lib/fontbuild/kerning.py b/scripts/lib/fontbuild/kerning.py
deleted file mode 100644
index c93e303..0000000
--- a/scripts/lib/fontbuild/kerning.py
+++ /dev/null
@@ -1,112 +0,0 @@
-# Copyright 2015 Google Inc. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-from feaTools import parser
-from feaTools.writers.baseWriter import AbstractFeatureWriter
-
-
-class KernFeatureWriter(AbstractFeatureWriter):
- """Generates a kerning feature based on glyph class definitions.
-
- Uses the kerning rules contained in an RFont's kerning attribute, as well as
- glyph classes from parsed OTF text. Class-based rules are set based on the
- existing rules for their key glyphs.
- """
-
- def __init__(self, font):
- self.kerning = font.kerning
- self.leftClasses = []
- self.rightClasses = []
- self.classSizes = {}
-
- def write(self, linesep="\n"):
- """Write kern feature."""
-
- # maintain collections of different rule types
- leftClassKerning, rightClassKerning, classPairKerning = {}, {}, {}
- for leftName, leftContents in self.leftClasses:
- leftKey = leftContents[0]
-
- # collect rules with two classes
- for rightName, rightContents in self.rightClasses:
- rightKey = rightContents[0]
- pair = leftKey, rightKey
- kerningVal = self.kerning[pair]
- if kerningVal is None:
- continue
- classPairKerning[leftName, rightName] = kerningVal
- self.kerning.remove(pair)
-
- # collect rules with left class and right glyph
- for pair, kerningVal in self.kerning.getLeft(leftKey):
- leftClassKerning[leftName, pair[1]] = kerningVal
- self.kerning.remove(pair)
-
- # collect rules with left glyph and right class
- for rightName, rightContents in self.rightClasses:
- rightKey = rightContents[0]
- for pair, kerningVal in self.kerning.getRight(rightKey):
- rightClassKerning[pair[0], rightName] = kerningVal
- self.kerning.remove(pair)
-
- # write the feature
- self.ruleCount = 0
- lines = ["feature kern {"]
- lines.append(self._writeKerning(self.kerning, linesep))
- lines.append(self._writeKerning(leftClassKerning, linesep, True))
- lines.append(self._writeKerning(rightClassKerning, linesep, True))
- lines.append(self._writeKerning(classPairKerning, linesep))
- lines.append("} kern;")
- return linesep.join(lines)
-
- def _writeKerning(self, kerning, linesep, enum=False):
- """Write kerning rules for a mapping of pairs to values."""
-
- lines = []
- enum = "enum " if enum else ""
- pairs = kerning.items()
- pairs.sort()
- for (left, right), val in pairs:
- if enum:
- rulesAdded = (self.classSizes.get(left, 1) *
- self.classSizes.get(right, 1))
- else:
- rulesAdded = 1
- self.ruleCount += rulesAdded
- if self.ruleCount > 1024:
- lines.append(" subtable;")
- self.ruleCount = rulesAdded
- lines.append(" %spos %s %s %d;" % (enum, left, right, val))
- return linesep.join(lines)
-
- def classDefinition(self, name, contents):
- """Store a class definition as either a left- or right-hand class."""
-
- if not name.startswith("@_"):
- return
- info = (name, contents)
- if name.endswith("_L"):
- self.leftClasses.append(info)
- elif name.endswith("_R"):
- self.rightClasses.append(info)
- self.classSizes[name] = len(contents)
-
-
-def makeKernFeature(font, text):
- """Add a kern feature to the font, using a KernFeatureWriter."""
-
- writer = KernFeatureWriter(font)
- parser.parseFeatures(writer, text)
- font.features.text += writer.write()
diff --git a/scripts/lib/fontbuild/markFeature.py b/scripts/lib/fontbuild/markFeature.py
index b617ef6..945cef0 100755
--- a/scripts/lib/fontbuild/markFeature.py
+++ b/scripts/lib/fontbuild/markFeature.py
@@ -13,105 +13,33 @@
# limitations under the License.
-from fontbuild.features import updateFeature
-
-
-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, 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)
- return lst
-
-def CreateAccGlyphList(font, acc_list, acc_anchor_name):
- g_list = []
- for g in font:
- 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:
- 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, lookAliases = True):
- txt = "lookup " + lookupname + " {\n"
-
- for acc in accent_g_list:
- txt += " markClass " + acc[0] + " <anchor " + `int(acc[1])` + " " + `int(acc[2])` + "> " + acc_class +";\n"
-
- for base in base_g_list:
- txt += " pos base " + base[0] + " <anchor " + `int(base[1])` + " " + `int(base[2])` + "> mark " + acc_class + ";\n"
- if (lookAliases):
- base2 = GetAliaseName(base[0])
- if (None == base2):
- continue
- txt += " pos base " + base2 + " <anchor " + `int(base[1])` + " " + `int(base[2])` + "> mark " + acc_class + ";\n"
-
- txt += "} " + lookupname + ";\n"
-
- return txt
-
-##### 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"
-
- 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"
-
- updateFeature(font, "mark", text)
+from ufo2ft.kernFeatureWriter import KernFeatureWriter
+from ufo2ft.makeotfParts import FeatureOTFCompiler
+
+
+class RobotoFeatureCompiler(FeatureOTFCompiler):
+ def precompile(self):
+ self.overwriteFeatures = True
+
+ def setupAnchorPairs(self):
+ self.anchorPairs = [
+ ["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]]
+
+ self.mkmkAnchorPairs = [
+ ["mkmktop", "_marktop"],
+ ["mkmkbottom_acc", "_markbottom"]]
+
+ def setupAliases(self):
+ self.aliases = [
+ ["a", "uni0430"], ["e", "uni0435"], ["p", "uni0440"],
+ ["c", "uni0441"], ["x", "uni0445"], ["s", "uni0455"],
+ ["i", "uni0456"], ["psi", "uni0471"]]
diff --git a/scripts/lib/fontbuild/mkmkFeature.py b/scripts/lib/fontbuild/mkmkFeature.py
deleted file mode 100755
index 16f9313..0000000
--- a/scripts/lib/fontbuild/mkmkFeature.py
+++ /dev/null
@@ -1,87 +0,0 @@
-# Copyright 2015 Google Inc. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-from fontbuild.features import updateFeature
-
-
-def CreateAccNameList(font, acc_anchor_name):
- lst = []
- for g in font:
- 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:
- 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:
- 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, acc_class):
- txt = "lookup " + lookupname + " {\n"
- #acc_class = "@MC_mkmk"
- for acc in accent_g_list:
- txt += " markClass " + acc[0] + " <anchor " + `int(acc[1])` + " " + `int(acc[2])` + "> " + acc_class +";\n"
-
- for base in base_g_list:
- txt += " pos mark " + base[0] + " <anchor " + `int(base[1])` + " " + `int(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", "@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"
-
- updateFeature(font, "mkmk", text)