From 8b5f2c40e043ac354b74481919d25b85f1136d41 Mon Sep 17 00:00:00 2001 From: James Godfrey-Kittle Date: Thu, 19 Nov 2015 15:23:24 -0800 Subject: [italics] Work around RoboFab-related issues This is (hopefully) a temporary hack until a more robust solution to the issue is found. Basically the problem is that RoboFab pens do float-to-float comparisons to decide whether to remove duplicate points from contours, and breaks with BooleanOperations output (which can include point coordinates with very small fractional components). The italicizing code assumes certain behavior from RoboFab pens and can't handle duplicate points being kept. --- scripts/lib/fontbuild/Build.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'scripts/lib/fontbuild/Build.py') diff --git a/scripts/lib/fontbuild/Build.py b/scripts/lib/fontbuild/Build.py index d1e870a..5d92705 100644 --- a/scripts/lib/fontbuild/Build.py +++ b/scripts/lib/fontbuild/Build.py @@ -120,18 +120,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) -- cgit v1.2.3 From 21ef39becd62519e32accdf2f07554571fc46bfa Mon Sep 17 00:00:00 2001 From: James Godfrey-Kittle Date: Wed, 14 Oct 2015 11:28:53 -0700 Subject: Fix import order in Build.py --- scripts/lib/fontbuild/Build.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'scripts/lib/fontbuild/Build.py') diff --git a/scripts/lib/fontbuild/Build.py b/scripts/lib/fontbuild/Build.py index 5d92705..f29c727 100644 --- a/scripts/lib/fontbuild/Build.py +++ b/scripts/lib/fontbuild/Build.py @@ -13,23 +13,25 @@ # limitations under the License. +import ConfigParser +import os +import sys + from booleanOperations import BooleanOperationManager +from fontTools.misc.transform import Transform from robofab.world import OpenFont -from fontbuild.mix import Mix,Master,narrowFLGlyph -from fontbuild.instanceNames import setNamesRF -from fontbuild.italics import italicizeGlyph + from fontbuild.convertCurves import glyphCurvesToQuadratic -from fontbuild.mitreGlyph import mitreGlyph +from fontbuild.decomposeGlyph import decomposeGlyph +from fontbuild.features import readFeatureFile, writeFeatureFile from fontbuild.generateGlyph import generateGlyph -from fontTools.misc.transform import Transform +from fontbuild.instanceNames import setNamesRF +from fontbuild.italics import italicizeGlyph from fontbuild.kerning import makeKernFeature -from fontbuild.features import readFeatureFile, writeFeatureFile from fontbuild.markFeature import GenerateFeature_mark +from fontbuild.mitreGlyph import mitreGlyph +from fontbuild.mix import Mix,Master,narrowFLGlyph from fontbuild.mkmkFeature import GenerateFeature_mkmk -from fontbuild.decomposeGlyph import decomposeGlyph -import ConfigParser -import os -import sys class FontProject: -- cgit v1.2.3 From e8c9488af391731a94e9c47b63e926f3d7e14c6e Mon Sep 17 00:00:00 2001 From: James Godfrey-Kittle Date: Tue, 3 Nov 2015 13:28:11 -0800 Subject: Generate TTFs with ufo2ft --- scripts/lib/fontbuild/Build.py | 74 +++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 44 deletions(-) (limited to 'scripts/lib/fontbuild/Build.py') diff --git a/scripts/lib/fontbuild/Build.py b/scripts/lib/fontbuild/Build.py index f29c727..34a672e 100644 --- a/scripts/lib/fontbuild/Build.py +++ b/scripts/lib/fontbuild/Build.py @@ -18,20 +18,19 @@ import os import sys from booleanOperations import BooleanOperationManager +from convert_curves import fonts_to_quadratic from fontTools.misc.transform import Transform from robofab.world import OpenFont +from ufo2ft import compileOTF, compileTTF -from fontbuild.convertCurves import glyphCurvesToQuadratic 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.kerning import makeKernFeature -from fontbuild.markFeature import GenerateFeature_mark +from fontbuild.markFeature import RobotoFeatureCompiler from fontbuild.mitreGlyph import mitreGlyph from fontbuild.mix import Mix,Master,narrowFLGlyph -from fontbuild.mkmkFeature import GenerateFeature_mkmk class FontProject: @@ -68,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): @@ -155,33 +154,38 @@ 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) - if self.buildTTF: - log(">> Generating TTF file") - import fontforge - otFont = fontforge.open(otfName) - otFont.generate(self.generateOutputPath(f, "ttf")) + def generateTTFs(self): + """Build TTF for each font generated since last call to generateTTFs.""" + + fonts = [OpenFont(ufo) for ufo in self.generatedFonts] + log(">> Converting curves to quadratic") + fonts_to_quadratic(fonts, self.compatible) + + log(">> Generating TTF files") + for font in fonts: + ttfName = self.generateOutputPath(font, "ttf") + log(os.path.basename(ttfName)) + saveOTF(font, ttfName, truetype=True) + self.generatedFonts = [] def transformGlyphMembers(g, m): @@ -266,30 +270,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) -- cgit v1.2.3 From d1d422cd292addb4b59e85e2af1971635f1d923c Mon Sep 17 00:00:00 2001 From: James Godfrey-Kittle Date: Thu, 19 Nov 2015 16:13:57 -0800 Subject: Update curve conversion calls based on upstream --- scripts/lib/fontbuild/Build.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'scripts/lib/fontbuild/Build.py') diff --git a/scripts/lib/fontbuild/Build.py b/scripts/lib/fontbuild/Build.py index 34a672e..a8451f0 100644 --- a/scripts/lib/fontbuild/Build.py +++ b/scripts/lib/fontbuild/Build.py @@ -18,7 +18,7 @@ import os import sys from booleanOperations import BooleanOperationManager -from convert_curves import fonts_to_quadratic +from cu2qu.rf import fonts_to_quadratic from fontTools.misc.transform import Transform from robofab.world import OpenFont from ufo2ft import compileOTF, compileTTF @@ -177,15 +177,20 @@ class FontProject: """Build TTF for each font generated since last call to generateTTFs.""" fonts = [OpenFont(ufo) for ufo in self.generatedFonts] + self.generatedFonts = [] + log(">> Converting curves to quadratic") - fonts_to_quadratic(fonts, self.compatible) + if self.compatible: + fonts_to_quadratic(*fonts, dump_report=True) + else: + for font in fonts: + fonts_to_quadratic(font, dump_report=True) log(">> Generating TTF files") for font in fonts: ttfName = self.generateOutputPath(font, "ttf") log(os.path.basename(ttfName)) saveOTF(font, ttfName, truetype=True) - self.generatedFonts = [] def transformGlyphMembers(g, m): -- cgit v1.2.3 From 09eb72c1feecd1c997c8cccc47532440717e4a5f Mon Sep 17 00:00:00 2001 From: James Godfrey-Kittle Date: Fri, 20 Nov 2015 17:24:29 -0800 Subject: Change error bound when converting curves This is a small change which passes the threshold at which dots will have eight points instead of four, which makes a noticeable difference in shape. --- scripts/lib/fontbuild/Build.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'scripts/lib/fontbuild/Build.py') diff --git a/scripts/lib/fontbuild/Build.py b/scripts/lib/fontbuild/Build.py index a8451f0..041a7ec 100644 --- a/scripts/lib/fontbuild/Build.py +++ b/scripts/lib/fontbuild/Build.py @@ -180,11 +180,14 @@ class FontProject: self.generatedFonts = [] log(">> Converting curves to quadratic") + # using a slightly higher max error (e.g. 0.0025), dots will have fewer + # control points and look noticeably different + max_err = 0.002 if self.compatible: - fonts_to_quadratic(*fonts, dump_report=True) + fonts_to_quadratic(*fonts, max_err=max_err, dump_report=True) else: for font in fonts: - fonts_to_quadratic(font, dump_report=True) + fonts_to_quadratic(font, max_err=max_err, dump_report=True) log(">> Generating TTF files") for font in fonts: -- cgit v1.2.3 From 5b0dcd91995fe60d235bde7c7bb6bdbf0b910e81 Mon Sep 17 00:00:00 2001 From: James Godfrey-Kittle Date: Mon, 23 Nov 2015 18:54:25 -0800 Subject: Reverse contours before generating TTFs The UFOs store contours in ccw order, and the TrueType spec seems to say they should be cw. The old binaries are cw. --- scripts/lib/fontbuild/Build.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'scripts/lib/fontbuild/Build.py') diff --git a/scripts/lib/fontbuild/Build.py b/scripts/lib/fontbuild/Build.py index 041a7ec..5bb0ed6 100644 --- a/scripts/lib/fontbuild/Build.py +++ b/scripts/lib/fontbuild/Build.py @@ -193,6 +193,9 @@ class FontProject: 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) -- cgit v1.2.3 From 7d38014a38dae2303960adac770cd1399f7af032 Mon Sep 17 00:00:00 2001 From: James Godfrey-Kittle Date: Tue, 24 Nov 2015 15:03:18 -0800 Subject: Another update to curve conversion calls cu2qu is a new library without a currently well-defined API, so these calls have changed and will probably change again. --- scripts/lib/fontbuild/Build.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'scripts/lib/fontbuild/Build.py') diff --git a/scripts/lib/fontbuild/Build.py b/scripts/lib/fontbuild/Build.py index 5bb0ed6..be0b79c 100644 --- a/scripts/lib/fontbuild/Build.py +++ b/scripts/lib/fontbuild/Build.py @@ -180,14 +180,14 @@ class FontProject: self.generatedFonts = [] log(">> Converting curves to quadratic") - # using a slightly higher max error (e.g. 0.0025), dots will have fewer - # control points and look noticeably different + # 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=max_err, dump_report=True) + fonts_to_quadratic(*fonts, max_err_em=max_err, dump_report=True) else: for font in fonts: - fonts_to_quadratic(font, max_err=max_err, dump_report=True) + fonts_to_quadratic(font, max_err_em=max_err, dump_report=True) log(">> Generating TTF files") for font in fonts: -- cgit v1.2.3 From 5397958ba23710b7146b9351d06ce96da66a19bd Mon Sep 17 00:00:00 2001 From: James Godfrey-Kittle Date: Fri, 11 Dec 2015 11:57:25 -0800 Subject: Update calls to cu2qu This is hopefully the last time we have to do this. In response to https://github.com/googlei18n/cu2qu/commit/56f36a1b2ab673c25ac81756d5c251909a7d41e2 --- scripts/lib/fontbuild/Build.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/lib/fontbuild/Build.py') diff --git a/scripts/lib/fontbuild/Build.py b/scripts/lib/fontbuild/Build.py index be0b79c..cf07d55 100644 --- a/scripts/lib/fontbuild/Build.py +++ b/scripts/lib/fontbuild/Build.py @@ -184,10 +184,10 @@ class FontProject: # 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) + 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_report=True) + fonts_to_quadratic([font], max_err_em=max_err, dump_stats=True) log(">> Generating TTF files") for font in fonts: -- cgit v1.2.3 From db517c3b0639140ebd1516d2669a29d612da1c0b Mon Sep 17 00:00:00 2001 From: James Godfrey-Kittle Date: Fri, 11 Dec 2015 14:59:36 -0800 Subject: Update calls to ufo2ft Due to changes in https://github.com/jamesgk/ufo2ft/commit/6c46f7050bfdd346c33c1312f07830c48fcc07f2 --- scripts/lib/fontbuild/Build.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'scripts/lib/fontbuild/Build.py') diff --git a/scripts/lib/fontbuild/Build.py b/scripts/lib/fontbuild/Build.py index cf07d55..a4e5bac 100644 --- a/scripts/lib/fontbuild/Build.py +++ b/scripts/lib/fontbuild/Build.py @@ -28,7 +28,7 @@ from fontbuild.features import readFeatureFile, writeFeatureFile from fontbuild.generateGlyph import generateGlyph from fontbuild.instanceNames import setNamesRF from fontbuild.italics import italicizeGlyph -from fontbuild.markFeature import RobotoFeatureCompiler +from fontbuild.markFeature import RobotoFeatureCompiler, RobotoKernWriter from fontbuild.mitreGlyph import mitreGlyph from fontbuild.mix import Mix,Master,narrowFLGlyph @@ -288,5 +288,6 @@ def saveOTF(font, destFile, truetype=False): compiler = compileTTF else: compiler = compileOTF - otf = compiler(font, featureCompilerClass=RobotoFeatureCompiler) + otf = compiler(font, featureCompilerClass=RobotoFeatureCompiler, + kernWriter=RobotoKernWriter) otf.save(destFile) -- cgit v1.2.3