diff options
Diffstat (limited to 'misc/pylib/fontbuild')
-rw-r--r-- | misc/pylib/fontbuild/.gitignore | 1 | ||||
-rw-r--r-- | misc/pylib/fontbuild/Build.pyx (renamed from misc/pylib/fontbuild/Build.py) | 39 | ||||
-rw-r--r-- | misc/pylib/fontbuild/alignpoints.pyx (renamed from misc/pylib/fontbuild/alignpoints.py) | 13 | ||||
-rw-r--r-- | misc/pylib/fontbuild/convertCurves.pyx (renamed from misc/pylib/fontbuild/convertCurves.py) | 0 | ||||
-rw-r--r-- | misc/pylib/fontbuild/decomposeGlyph.pyx (renamed from misc/pylib/fontbuild/decomposeGlyph.py) | 0 | ||||
-rw-r--r-- | misc/pylib/fontbuild/italics.pyx (renamed from misc/pylib/fontbuild/italics.py) | 16 | ||||
-rw-r--r-- | misc/pylib/fontbuild/mitreGlyph.pyx (renamed from misc/pylib/fontbuild/mitreGlyph.py) | 0 | ||||
-rw-r--r-- | misc/pylib/fontbuild/mix.pyx (renamed from misc/pylib/fontbuild/mix.py) | 2 | ||||
-rw-r--r-- | misc/pylib/fontbuild/setup.py | 19 |
9 files changed, 58 insertions, 32 deletions
diff --git a/misc/pylib/fontbuild/.gitignore b/misc/pylib/fontbuild/.gitignore new file mode 100644 index 000000000..064a8d8ef --- /dev/null +++ b/misc/pylib/fontbuild/.gitignore @@ -0,0 +1 @@ +*.c diff --git a/misc/pylib/fontbuild/Build.py b/misc/pylib/fontbuild/Build.pyx index 5e88b384d..939122658 100644 --- a/misc/pylib/fontbuild/Build.py +++ b/misc/pylib/fontbuild/Build.pyx @@ -18,6 +18,7 @@ import os import sys from booleanOperations import BooleanOperationManager + from cu2qu.ufo import fonts_to_quadratic from fontTools.misc.transform import Transform from robofab.world import OpenFont @@ -201,25 +202,25 @@ class FontProject: saveOTF(font, ttfName, self.glyphOrder, truetype=True) -def transformGlyphMembers(g, m): - g.width = int(g.width * m.a) - g.Transform(m) - for a in g.anchors: - p = Point(a.p) - p.Transform(m) - a.p = p - for c in g.components: - # Assumes that components have also been individually transformed - p = Point(0,0) - d = Point(c.deltas[0]) - d.Transform(m) - p.Transform(m) - d1 = d - p - c.deltas[0].x = d1.x - c.deltas[0].y = d1.y - s = Point(c.scale) - s.Transform(m) - #c.scale = s +# def transformGlyphMembers(g, m): +# g.width = int(g.width * m.a) +# g.Transform(m) +# for a in g.anchors: +# p = Point(a.p) +# p.Transform(m) +# a.p = p +# for c in g.components: +# # Assumes that components have also been individually transformed +# p = Point(0,0) +# d = Point(c.deltas[0]) +# d.Transform(m) +# p.Transform(m) +# d1 = d - p +# c.deltas[0].x = d1.x +# c.deltas[0].y = d1.y +# s = Point(c.scale) +# s.Transform(m) +# #c.scale = s def swapContours(f,gName1,gName2): diff --git a/misc/pylib/fontbuild/alignpoints.py b/misc/pylib/fontbuild/alignpoints.pyx index f49f24d95..363aeef85 100644 --- a/misc/pylib/fontbuild/alignpoints.py +++ b/misc/pylib/fontbuild/alignpoints.pyx @@ -108,13 +108,18 @@ def findCorner(pp, nn): # print "parallel lines", np.arctan2(prev[1],prev[0]), np.arctan2(next[1],next[0]) # print prev, next assert 0, "parallel lines" - if glyph.name is None: - # Never happens, but here to fix a bug in Python 2.7 with -OO - print '' + # if glyph.name is None: + # # Never happens, but here to fix a bug in Python 2.7 with -OO + # print '' return lineIntersect(pStart, pEnd, nStart, nEnd) -def lineIntersect((x1,y1),(x2,y2),(x3,y3),(x4,y4)): +def lineIntersect(p1, p2, p3, p4): + x1, y1 = p1 + x2, y2 = p2 + x3, y3 = p3 + x4, y4 = p4 + x12 = x1 - x2 x34 = x3 - x4 y12 = y1 - y2 diff --git a/misc/pylib/fontbuild/convertCurves.py b/misc/pylib/fontbuild/convertCurves.pyx index b6efd5ca2..b6efd5ca2 100644 --- a/misc/pylib/fontbuild/convertCurves.py +++ b/misc/pylib/fontbuild/convertCurves.pyx diff --git a/misc/pylib/fontbuild/decomposeGlyph.py b/misc/pylib/fontbuild/decomposeGlyph.pyx index 0470fa60b..0470fa60b 100644 --- a/misc/pylib/fontbuild/decomposeGlyph.py +++ b/misc/pylib/fontbuild/decomposeGlyph.pyx diff --git a/misc/pylib/fontbuild/italics.py b/misc/pylib/fontbuild/italics.pyx index 91e658c74..522336197 100644 --- a/misc/pylib/fontbuild/italics.py +++ b/misc/pylib/fontbuild/italics.pyx @@ -59,8 +59,8 @@ def italicize(glyph, angle=12, stemWidth=180, xoffset=-50): ga, subsegments = segmentGlyph(glyph,25) va, e = glyphToMesh(ga) n = len(va) - grad = mapEdges(lambda a,(p,n): normalize(p-a), va, e) - cornerWeights = mapEdges(lambda a,(p,n): normalize(p-a).dot(normalize(a-n)), grad, e)[:,0].reshape((-1,1)) + grad = mapEdges(lambda a, pn: normalize(pn[0]-a), va, e) + cornerWeights = mapEdges(lambda a, pn: normalize(pn[0]-a).dot(normalize(a-pn[1])), grad, e)[:,0].reshape((-1,1)) smooth = np.ones((n,1)) * CURVE_CORRECTION_WEIGHT controlPoints = findControlPointsInMesh(glyph, va, subsegments) @@ -182,7 +182,7 @@ def findControlPointsInMesh(glyph, va, subsegments): def recompose(v, grad, e, smooth=1, P=None, distance=None): n = len(v) if distance == None: - distance = mapEdges(lambda a,(p,n): norm(p - a), v, e) + distance = mapEdges(lambda a, pn: norm(pn[0] - a), v, e) if (P == None): P = mP(v,e) P += np.identity(n) * smooth @@ -233,7 +233,7 @@ def getNormal(a,b,c): def edgeNormals(v,e): "Assumes a mesh where each vertex has exactly least two edges" - return mapEdges(lambda a,(p,n) : getNormal(a,p,n),v,e) + return mapEdges(lambda a, pn : getNormal(a,pn[0],pn[1]),v,e) def rangePrevNext(count): @@ -268,10 +268,10 @@ def copyGradDetails(a,b,e,scale=15): def copyMeshDetails(va,vb,e,scale=5,smooth=.01): - gradA = mapEdges(lambda a,(p,n): normalize(p-a), va, e) - gradB = mapEdges(lambda a,(p,n): normalize(p-a), vb, e) + gradA = mapEdges(lambda a, pn: normalize(pn[0]-a), va, e) + gradB = mapEdges(lambda a, pn: normalize(pn[0]-a), vb, e) grad = copyGradDetails(gradA, gradB, e, scale) - grad = mapEdges(lambda a,(p,n): normalize(a), grad, e) + grad = mapEdges(lambda a, pn: normalize(a), grad, e) return recompose(vb, grad, e, smooth=smooth) @@ -282,7 +282,7 @@ def condenseGlyph(glyph, scale=.8, stemWidth=185): normals = edgeNormals(va,e) cn = va.dot(np.array([[scale, 0],[0,1]])) - grad = mapEdges(lambda a,(p,n): normalize(p-a), cn, e) + grad = mapEdges(lambda a, pn: normalize(pn[0]-a), cn, e) # ograd = mapEdges(lambda a,(p,n): normalize(p-a), va, e) cn[:,0] -= normals[:,0] * stemWidth * .5 * (1 - scale) diff --git a/misc/pylib/fontbuild/mitreGlyph.py b/misc/pylib/fontbuild/mitreGlyph.pyx index d0834ed84..d0834ed84 100644 --- a/misc/pylib/fontbuild/mitreGlyph.py +++ b/misc/pylib/fontbuild/mitreGlyph.pyx diff --git a/misc/pylib/fontbuild/mix.py b/misc/pylib/fontbuild/mix.pyx index 5e5388b3e..7fb1fa320 100644 --- a/misc/pylib/fontbuild/mix.py +++ b/misc/pylib/fontbuild/mix.pyx @@ -269,7 +269,7 @@ class Mix: def getFGlyph(self, master, gname): if isinstance(master.font, Mix): - return font.mixGlyphs(gname) + return master.font.mixGlyphs(gname) return master.ffont.getGlyph(gname) def getGlyphMasters(self,gname): diff --git a/misc/pylib/fontbuild/setup.py b/misc/pylib/fontbuild/setup.py new file mode 100644 index 000000000..871c12655 --- /dev/null +++ b/misc/pylib/fontbuild/setup.py @@ -0,0 +1,19 @@ +from distutils.core import setup +from distutils.extension import Extension +from Cython.Distutils import build_ext + +ext_modules = [ + Extension("decomposeGlyph", ["decomposeGlyph.pyx"]), + Extension("alignpoints", ["alignpoints.pyx"]), + Extension("Build", ["Build.pyx"]), + Extension("convertCurves", ["convertCurves.pyx"]), + Extension("mitreGlyph", ["mitreGlyph.pyx"]), + Extension("mix", ["mix.pyx"]), + Extension("italics", ["italics.pyx"]), +] + +setup( + name = 'copy', + cmdclass = {'build_ext': build_ext}, + ext_modules = ext_modules +) |