summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Andersson <rasmus@notion.se>2018-01-24 06:13:38 +0300
committerRasmus Andersson <rasmus@notion.se>2018-01-24 06:13:38 +0300
commit57238c6c829bd35b5632d414b44d503124d94d49 (patch)
treee502efd3e71d42e679dcc25576dce435bb526806
parent0d7d370104a61ca831b8b04bba9348aed45ae6c5 (diff)
downloadinter-57238c6c829bd35b5632d414b44d503124d94d49.tar.xz
Fixes an issue where some overlapping contours would not be flattened during compilation. This increases build time by about 50% (29s -> 43s on my machine for regular) and increases the size of the unhinted regular OTF file by about 20 kBv2.5-beta
-rw-r--r--misc/pylib/fontbuild/Build.pyx39
1 files changed, 24 insertions, 15 deletions
diff --git a/misc/pylib/fontbuild/Build.pyx b/misc/pylib/fontbuild/Build.pyx
index 8e028ef74..81407d97f 100644
--- a/misc/pylib/fontbuild/Build.pyx
+++ b/misc/pylib/fontbuild/Build.pyx
@@ -278,11 +278,18 @@ def generateGlyphs(f, glyphNames, glyphList={}):
for glyphName in glyphNames:
generateGlyph(f, glyphName, glyphList)
+
+def deleteGlyphs(f, deleteList):
+ for name in deleteList:
+ if f.has_key(name):
+ f.removeGlyph(name)
+
+
def cleanCurves(f):
log(">> Removing overlaps")
for g in f:
- # if len(g.components) > 0:
- # decomposeGlyph(f, g)
+ if len(g.components) > 0:
+ decomposeGlyph(f, g)
removeGlyphOverlap(g)
# log(">> Mitring sharp corners")
@@ -294,20 +301,22 @@ def cleanCurves(f):
# glyphCurvesToQuadratic(g)
-def deleteGlyphs(f, deleteList):
- for name in deleteList:
- if f.has_key(name):
- f.removeGlyph(name)
-
-
-def removeGlyphOverlap(glyph):
+def removeGlyphOverlap(g):
"""Remove overlaps in contours from a glyph."""
- #TODO(jamesgk) verify overlaps exist first, as per library's recommendation
- contours = glyph.contours
- if len(contours) > 1:
- manager = BooleanOperationManager()
- glyph.clearContours()
- manager.union(contours, glyph.getPointPen())
+ # Note: Although it theoretically would be more efficient to first check
+ # if contours has overlap before applying clipping, boolean ops and
+ # re-drawing the shapes, the booleanOperations library's getIntersections
+ # function adds more overhead in the real world, compared to bluntly
+ # computing the union for every single glyph.
+ #
+ # If we can find a really cheap/efficient way to check if there's any
+ # overlap, then we should do that before going ahead and computing the
+ # union. Keep in mind that some glyphs have just a single contour that
+ # intersects itself, for instance "e".
+
+ contours = g.contours
+ g.clearContours()
+ BooleanOperationManager.union(contours, g.getPointPen())
def saveOTF(font, destFile, glyphOrder, truetype=False):