diff options
author | Vasudev Kamath <kamathvasudev@gmail.com> | 2016-01-17 10:24:04 +0530 |
---|---|---|
committer | Vasudev Kamath <kamathvasudev@gmail.com> | 2016-01-17 10:24:04 +0530 |
commit | dbfdc17c919fbe0c0da0b11ad80977d415d52e9e (patch) | |
tree | be487e0e58e17959036e6104542f57213ffc1f1a /scripts/lib/fontbuild/Build.py | |
parent | 1352cf875dbb8a46fb0b4bf25a15b6870cf83a19 (diff) | |
parent | dbeb1d1913b5e0b1609af63caa02c2785f832a26 (diff) |
Merge tag 'upstream/0_20160106'
Upstream version 0~20160106
# gpg: Signature made Sunday 17 January 2016 10:24:04 AM IST using RSA key ID 87700B7E
# gpg: Good signature from "Vasudev Kamath <kamathvasudev@gmail.com>" [ultimate]
# gpg: aka "Vasudev Kamath (Debian Maint) <kamathvasudev@gmail.com>" [ultimate]
# gpg: aka "Vasudev Kamath <vasudev@copyninja.info>" [ultimate]
Diffstat (limited to 'scripts/lib/fontbuild/Build.py')
-rw-r--r-- | scripts/lib/fontbuild/Build.py | 118 |
1 files changed, 54 insertions, 64 deletions
diff --git a/scripts/lib/fontbuild/Build.py b/scripts/lib/fontbuild/Build.py index d1e870a..a4e5bac 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, RobotoKernWriter 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): @@ -120,18 +121,8 @@ class FontProject: if g.name == "uniFFFD": continue - - # if i < 24: - # continue - # if i > 86: - # for i,g in enumerate(fl.font.glyphs): - # fl.UpdateGlyph(i) - # # break - # assert False - - # print g.name - # if self.thinfont != None: - # narrowFLGlyph(g,self.thinfont.getGlyph(g.name),factor=narrowAmmount) + + removeGlyphOverlap(g) if g.name in self.lessItalic: italicizeGlyph(f, g, 9, stemWidth=stemWidth) @@ -163,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_stats=True) + else: + for font in fonts: + fonts_to_quadratic([font], max_err_em=max_err, dump_stats=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): @@ -274,30 +281,13 @@ 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, + kernWriter=RobotoKernWriter) + otf.save(destFile) |