diff options
author | James Godfrey-Kittle <jamesgk@google.com> | 2015-01-25 16:07:18 -0800 |
---|---|---|
committer | James Godfrey-Kittle <jamesgk@google.com> | 2015-04-16 12:16:27 -0700 |
commit | 4ee04b9735ff0d252124816c3413d37eddf204fe (patch) | |
tree | 62e6cb712329ba23a01c00624cd6ce2223a12f5f /scripts/lib/fontbuild | |
parent | 68a71223632aa384d09b2cb27e61830faeec46e6 (diff) |
Remove references to FL (stub out missing methods)
Diffstat (limited to 'scripts/lib/fontbuild')
-rw-r--r-- | scripts/lib/fontbuild/Build.py | 150 | ||||
-rw-r--r-- | scripts/lib/fontbuild/anchors.py | 23 | ||||
-rw-r--r-- | scripts/lib/fontbuild/convertCurves.py | 1 | ||||
-rw-r--r-- | scripts/lib/fontbuild/decomposeGlyph.py | 3 | ||||
-rwxr-xr-x | scripts/lib/fontbuild/features.py | 1 | ||||
-rw-r--r-- | scripts/lib/fontbuild/generateGlyph.py | 43 | ||||
-rw-r--r-- | scripts/lib/fontbuild/instanceNames.py | 7 | ||||
-rw-r--r-- | scripts/lib/fontbuild/italics.py | 8 | ||||
-rw-r--r-- | scripts/lib/fontbuild/kerning.py | 1 | ||||
-rwxr-xr-x | scripts/lib/fontbuild/markFeature.py | 2 | ||||
-rw-r--r-- | scripts/lib/fontbuild/mitreGlyph.py | 5 | ||||
-rw-r--r-- | scripts/lib/fontbuild/mix.py | 147 | ||||
-rwxr-xr-x | scripts/lib/fontbuild/mkmkFeature.py | 2 | ||||
-rw-r--r-- | scripts/lib/fontbuild/removeGlyphOverlap.py | 3 | ||||
-rw-r--r-- | scripts/lib/fontbuild/sortGlyphs.py | 3 |
15 files changed, 180 insertions, 219 deletions
diff --git a/scripts/lib/fontbuild/Build.py b/scripts/lib/fontbuild/Build.py index 6afc08f..ed5eed5 100644 --- a/scripts/lib/fontbuild/Build.py +++ b/scripts/lib/fontbuild/Build.py @@ -1,6 +1,5 @@ -from FL import * from fontbuild.mix import Mix,Master,narrowFLGlyph -from fontbuild.instanceNames import setNames +from fontbuild.instanceNames import setNamesRF from fontbuild.italics import italicizeGlyph from fontbuild.convertCurves import glyphCurvesToQuadratic from fontbuild.mitreGlyph import mitreGlyph @@ -10,6 +9,9 @@ from fontbuild.kerning import generateFLKernClassesFromOTString from fontbuild.features import CreateFeaFile from fontbuild.markFeature import GenerateFeature_mark from fontbuild.mkmkFeature import GenerateFeature_mkmk +from fontbuild.decomposeGlyph import decomposeGlyph +from fontbuild.removeGlyphOverlap import removeGlyphOverlap +from fontbuild.sortGlyphs import sortGlyphsByUnicode import ConfigParser import os @@ -67,13 +69,10 @@ class FontProject: if isinstance( mix, Mix): f = mix.generateFont(self.basefont) else: - f = Font(mix) - fl.Add(f) - index = fl.ifont - fl.CallCommand(33239) # Sort glyphs by unicode + f = mix + sortGlyphsByUnicode(f) if italic == True: log(">> Italicizing") - fl.UpdateFont(fl.ifont) tweakAmmount = .085 narrowAmmount = .93 if names.find("Thin") != -1: @@ -81,7 +80,7 @@ class FontProject: if names.find("Condensed") != -1: narrowAmmount = .96 i = 0 - for g in f.glyphs: + for g in f: i += 1 if i % 10 == 0: print g.name @@ -101,61 +100,58 @@ class FontProject: # narrowFLGlyph(g,self.thinfont.getGlyph(g.name),factor=narrowAmmount) if g.name != "eight" or g.name != "Q": - g.RemoveOverlap() - + removeGlyphOverlap(g) + # not sure why FontLab sometimes refuses, seems to work if called twice - - if (g.name in self.lessItalic): - italicizeGlyph(g, 9, stemWidth=stemWidth) + + if g.name in self.lessItalic: + italicizeGlyph(f, g, 9, stemWidth=stemWidth) elif g.name != ".notdef": - italicizeGlyph(g, 10, stemWidth=stemWidth) - g.RemoveOverlap() + italicizeGlyph(f, g, 10, stemWidth=stemWidth) + removeGlyphOverlap(g) g.width += 10 - fl.UpdateGlyph(i-1) - + if swapSuffixes != None: for swap in swapSuffixes: - swapList = [g.name for g in f.glyphs if g.name.endswith(swap)] + swapList = [g.name for g in f if g.name.endswith(swap)] for gname in swapList: print gname swapGlyphs(f, gname.replace(swap,""), gname) for gname in self.predecompose: - g = f[f.FindGlyph(gname)] - if g != None: - g.Decompose() + if f.has_key(gname): + decomposeGlyph(f[gname]) log(">> Generating glyphs") generateGlyphs(f, self.diacriticList) log(">> Copying features") f.ot_classes = self.ot_classes - copyFeatures(self.basefont,f) - fl.UpdateFont(index) + copyFeatures(self.basefont, f) log(">> Decomposing") for gname in self.decompose: - g = f[f.FindGlyph(gname)] - if g != None: - g.Decompose() - g.Decompose() + if f.has_key(gname): + decomposeGlyph(f[gname]) + decomposeGlyph(f[gname]) - setNames(f, n, foundry=self.config.get('main','foundry'), - version=self.config.get('main','version'), - build=self.buildnumber) + setNamesRF(f, n, foundry=self.config.get('main', 'foundry'), + version=self.config.get('main', 'version')) cleanCurves(f) - deleteGlyphs(f,self.deleteList) - - if kern: - log(">> Generating kern classes") - generateFLKernClassesFromOTString(f,self.ot_kerningclasses) - kern = f.MakeKernFeature() - kern_exist = False - for fea_id in range (len(f.features)): - if "kern" == f.features[fea_id].tag: - f.features[fea_id] = kern - kern_exist = True - if (False == kern_exist): - f.features.append(kern) - - directoryName = n[0].replace(" ","") + deleteGlyphs(f, self.deleteList) + +# if kern: +# log(">> Generating kern classes") +# generateFLKernClassesFromOTString(f, self.ot_kerningclasses) +# kern = f.MakeKernFeature() +# kern_exist = False +# for fea_id in range (len(f.features)): +# if "kern" == f.features[fea_id].tag: +# f.features[fea_id] = kern +# kern_exist = True +# if False == kern_exist: +# f.features.append(kern) + + directoryName = n[0].replace(" ", "") + fontName = "%s-%s" % (f.info.familyName.replace(" ", ""), + f.info.styleName.replace(" ", "")) if self.buldVFBandFEA: log(">> Generating VFB files") @@ -169,18 +165,16 @@ class FontProject: directoryPath = "%s/%s/%sTTF"%(self.basedir,self.builddir,directoryName) if not os.path.exists(directoryPath): os.makedirs(directoryPath) - ttfName = "%s/%s.ttf"%(directoryPath,f.font_name) - fl.GenerateFont(fl.ifont,ftTRUETYPE,ttfName) - + ufoName = "%s/%s.ufo" % (directoryPath, fontName) + f.save(ufoName) + if self.buldVFBandFEA: log(">> Generating FEA files") GenerateFeature_mark(f) GenerateFeature_mkmk(f) feaName = "%s/%s.fea"%(directoryPath,f.font_name) CreateFeaFile(f, feaName) - - f.modified = 0 - #fl.Close(index) + def transformGlyphMembers(g, m): g.width = int(g.width * m.a) @@ -204,21 +198,22 @@ def transformGlyphMembers(g, m): def swapGlyphs(f,gName1,gName2): try: - g1 = f.glyphs[f.FindGlyph(gName1)] - g2 = f.glyphs[f.FindGlyph(gName2)] - except IndexError: - log("swapGlyphs failed for %s %s"%(gName1, gName2)) + g1 = f[gName1] + g2 = f[gName2] + except KeyError: + log("swapGlyphs failed for %s %s" % (gName1, gName2)) return - g3 = Glyph(g1) - - g1.Clear() - g1.Insert(g2) - g1.SetMetrics(g2.GetMetrics()) - - g2.Clear() - g2.Insert(g3) - g2.SetMetrics(g3.GetMetrics()) - + g3 = g1.copy() + + g1.clear() + g1.appendGlyph(g2) + g1.width = g2.width + + g2.clear() + g2.appendGlyph(g3) + g2.width = g3.width + + def log(msg): print msg @@ -226,12 +221,8 @@ def log(msg): # f.ot_classes = ot_classes def copyFeatures(f1, f2): - for ft in f1.features: - t = Feature(ft.tag, ft.value) - f2.features.append(t) - #f2.ot_classes = f1.ot_classes - f2.classes = [] - f2.classes = f1.classes + f2.features.text = f2.features.text + def generateGlyphs(f, glyphNames): log(">> Generating diacritics") @@ -242,9 +233,8 @@ def generateGlyphs(f, glyphNames): def cleanCurves(f): log(">> Removing overlaps") - for g in f.glyphs: - g.UnselectAll() - g.RemoveOverlap() + for g in f: + removeGlyphOverlap(g) log(">> Mitring sharp corners") # for g in f.glyphs: @@ -253,11 +243,9 @@ def cleanCurves(f): log(">> Converting curves to quadratic") # for g in f.glyphs: # glyphCurvesToQuadratic(g) - -def deleteGlyphs(f,deleteList): - fl.Unselect() + + +def deleteGlyphs(f, deleteList): for name in deleteList: - glyphIndex = f.FindGlyph(name) - if glyphIndex != -1: - del f.glyphs[glyphIndex] - fl.UpdateFont() + if f.has_key(name): + f.removeGlyph(name) diff --git a/scripts/lib/fontbuild/anchors.py b/scripts/lib/fontbuild/anchors.py index 7cc3869..d82ffa7 100644 --- a/scripts/lib/fontbuild/anchors.py +++ b/scripts/lib/fontbuild/anchors.py @@ -1,18 +1,10 @@ -#import numpy as np -from FL import * +def getGlyph(gname, font): + return font[gname] if font.has_key(gname) else None -def getGlyph(gname,font): - index = font.FindGlyph(gname) - if index != -1: - return font.glyphs[index] - else: - return None - -def getComponentByName(f,g,componentName): - componentIndex = f.FindGlyph(componentName) +def getComponentByName(f, g, componentName): for c in g.components: - if c.index == componentIndex: + if c.baseGlyph == componentName: return c def getAnchorByName(g,anchorName): @@ -31,10 +23,9 @@ def alignComponentToAnchor(f,glyphName,baseName,accentName,anchorName): a2 = getAnchorByName(accent,"_" + anchorName) if a1 == None or a2 == None: return - offset = a1.p - a2.p - c = getComponentByName(f,g,accentName) - c.deltas[0].x = offset.x - c.deltas[0].y = offset.y + offset = (a1.x - a2.x, a1.y - a2.y) + c = getComponentByName(f, g, accentName) + c.offset = offset def alignComponentsToAnchors(f,glyphName,baseName,accentNames): for a in accentNames: diff --git a/scripts/lib/fontbuild/convertCurves.py b/scripts/lib/fontbuild/convertCurves.py index e900a73..606e0b4 100644 --- a/scripts/lib/fontbuild/convertCurves.py +++ b/scripts/lib/fontbuild/convertCurves.py @@ -9,7 +9,6 @@ exactly two off curve points. import numpy from numpy import array,cross,dot from fontTools.misc import bezierTools -from FL import * def calcIntersect(a,b,c,d): numpy.seterr(all='raise') diff --git a/scripts/lib/fontbuild/decomposeGlyph.py b/scripts/lib/fontbuild/decomposeGlyph.py new file mode 100644 index 0000000..16f9a3d --- /dev/null +++ b/scripts/lib/fontbuild/decomposeGlyph.py @@ -0,0 +1,3 @@ +def decomposeGlyph(glyph): + #TODO(jamesgk@google.com) + pass diff --git a/scripts/lib/fontbuild/features.py b/scripts/lib/fontbuild/features.py index 0e89a57..1f210ea 100755 --- a/scripts/lib/fontbuild/features.py +++ b/scripts/lib/fontbuild/features.py @@ -1,5 +1,4 @@ import string
-from FL import *
def CreateFeaFile(font, path):
fea_text = font.ot_classes
diff --git a/scripts/lib/fontbuild/generateGlyph.py b/scripts/lib/fontbuild/generateGlyph.py index f2214f0..2b29ada 100644 --- a/scripts/lib/fontbuild/generateGlyph.py +++ b/scripts/lib/fontbuild/generateGlyph.py @@ -1,5 +1,5 @@ from anchors import alignComponentsToAnchors -from FL import * + def parseComposite(composite): c = composite.split("=") @@ -15,34 +15,33 @@ def parseComposite(composite): accentNames = [i.split(":") for i in accents ] return (glyphName, baseName, accentNames, offset) -def shiftGlyphMembers(g, x): - g.Shift(Point(x,0)) - for c in g.components: - c.deltas[0].x = c.deltas[0].x + x def generateGlyph(f,gname): if gname.find("_") != -1: + + #TODO(jamesgk@google.com) handle underscores + return + generateString = gname - g = f.GenerateGlyph(generateString) + g = f.generateGlyph(generateString) if f.FindGlyph(g.name) == -1: f.glyphs.append(g) return g else: glyphName, baseName, accentNames, offset = parseComposite(gname) - components = [baseName] + [i[0] for i in accentNames] - if len(components) == 1: - components.append("NONE") - generateString = "%s=%s" %("+".join(components), glyphName) - g = f.GenerateGlyph(generateString) - if f.FindGlyph(g.name) == -1: - f.glyphs.append(g) - g1 = f.glyphs[f.FindGlyph(g.name)] + if not f.has_key(glyphName): + try: + f.compileGlyph(glyphName, baseName, accentNames) + except KeyError as e: + print ("KeyError raised for composition rule '%s', likely %s " + "anchor not found in glyph '%s'" % (gname, e, baseName)) + return + g = f[glyphName] if len(accentNames) > 0: - alignComponentsToAnchors(f,glyphName,baseName,accentNames) - if (offset[0] != 0 or offset[1] != 0): - g1.width += offset[1] + offset[0] - shiftGlyphMembers(g1,offset[0]) - return g - -# generateGlyph(fl.font,"A+ogonek=Aogonek") -# fl.UpdateFont()
\ No newline at end of file + alignComponentsToAnchors(f, glyphName, baseName, accentNames) + if offset[0] != 0 or offset[1] != 0: + g.width += offset[1] + offset[0] + g.move((offset[0], 0)) + else: + print ("Existing glyph '%s' found in font, ignoring composition " + "rule '%s'" % (glyphName, gname)) diff --git a/scripts/lib/fontbuild/instanceNames.py b/scripts/lib/fontbuild/instanceNames.py index 96827c8..bb7f52c 100644 --- a/scripts/lib/fontbuild/instanceNames.py +++ b/scripts/lib/fontbuild/instanceNames.py @@ -177,8 +177,9 @@ def setNames(f,names,foundry="",version="1.0",build="0000"): i = InstanceNames(names) i.setFLNames(f) -def setNamesRF(f,names,foundry=""): + +def setNamesRF(f, names, foundry="", version="1.0"): InstanceNames.foundry = foundry i = InstanceNames(names) - i.setRFNames(f) -
\ No newline at end of file + version, versionMinor = [int(num) for num in version.split(".")] + i.setRFNames(f, version=version, versionMinor=versionMinor) diff --git a/scripts/lib/fontbuild/italics.py b/scripts/lib/fontbuild/italics.py index 8e12619..d32630a 100644 --- a/scripts/lib/fontbuild/italics.py +++ b/scripts/lib/fontbuild/italics.py @@ -1,16 +1,14 @@ from fontTools.misc.transform import Transform -from robofab.world import CurrentFont from robofab.world import RFont from time import clock import numpy as np import math from alignpoints import alignCorners -def italicizeGlyph(g, angle=10, stemWidth=185): - f = CurrentFont() +def italicizeGlyph(f, g, angle=10, stemWidth=185): glyph = f[g.name] - slope = np.tanh([math.pi * angle / 180]) - + slope = np.tanh([math.pi * angle / 180])[0] + # determine how far on the x axis the glyph should slide # to compensate for the slant. -600 is a magic number # that assumes a 2048 unit em square diff --git a/scripts/lib/fontbuild/kerning.py b/scripts/lib/fontbuild/kerning.py index cdece40..def733b 100644 --- a/scripts/lib/fontbuild/kerning.py +++ b/scripts/lib/fontbuild/kerning.py @@ -1,5 +1,4 @@ import re -from FL import * def markKernClassesLR(f): for i in range(len(f.classes)): diff --git a/scripts/lib/fontbuild/markFeature.py b/scripts/lib/fontbuild/markFeature.py index 9d7401a..4eb2b32 100755 --- a/scripts/lib/fontbuild/markFeature.py +++ b/scripts/lib/fontbuild/markFeature.py @@ -1,5 +1,3 @@ -from FL import *
-
aliases = [["uni0430", "a"], ["uni0435", "e"], ["uni0440", "p"], ["uni0441", "c"], ["uni0445", "x"], ["uni0455", "s"], ["uni0456", "i"], ["uni0471", "psi"]]
def GetAliaseName(gname):
diff --git a/scripts/lib/fontbuild/mitreGlyph.py b/scripts/lib/fontbuild/mitreGlyph.py index ab68e4e..94cf84a 100644 --- a/scripts/lib/fontbuild/mitreGlyph.py +++ b/scripts/lib/fontbuild/mitreGlyph.py @@ -6,7 +6,6 @@ maxAngle : Maximum angle in radians at which nodes will be mitred. The default """ -from FL import * import math def getContours(g): @@ -115,7 +114,3 @@ def mitreGlyph(g,mitreSize,maxAngle): if needsMitring: g.Clear() g.Insert(nodes) - -fl.SetUndo() -mitreGlyph(fl.glyph,8.,.9) -fl.UpdateGlyph()
\ No newline at end of file diff --git a/scripts/lib/fontbuild/mix.py b/scripts/lib/fontbuild/mix.py index 06c62dc..507a5dd 100644 --- a/scripts/lib/fontbuild/mix.py +++ b/scripts/lib/fontbuild/mix.py @@ -1,6 +1,9 @@ -from FL import * from numpy import array, append import copy +from robofab.objects.objectsRF import RPoint +from robofab.world import OpenFont +from decomposeGlyph import decomposeGlyph + class FFont: "Font wrapper for floating point operations" @@ -17,24 +20,23 @@ class FFont: self.vstems = list(f.vstems) elif f != None: self.copyFromFont(f) - - def copyFromFont(self,f): - for g in f.glyphs: + + def copyFromFont(self, f): + for g in f: self.glyphs[g.name] = FGlyph(g) - self.hstems = [s for s in f.stem_snap_h[0]] - self.vstems = [s for s in f.stem_snap_v[0]] - - - def copyToFont(self,f): - for g in f.glyphs: + self.hstems = [s for s in f.info.postscriptStemSnapH] + self.vstems = [s for s in f.info.postscriptStemSnapV] + + def copyToFont(self, f): + for g in f: try: gF = self.glyphs[g.name] gF.copyToGlyph(g) except: print "Copy to glyph failed for" + g.name - f.stem_snap_h[0] = self.hstems - f.stem_snap_v[0] = self.vstems - + f.info.postscriptStemSnapH = self.hstems + f.info.postscriptStemSnapV = self.vstems + def getGlyph(self, gname): try: return self.glyphs[gname] @@ -59,10 +61,10 @@ class FGlyph: "provides a temporary floating point compatible glyph data structure" def __init__(self, g=None): - self.nodes = [] + self.contours = [] self.width = 0. self.components = [] - self.kerning = [] +# self.kerning = [] self.anchors = [] if g != None: self.copyFromGlyph(g) @@ -74,27 +76,27 @@ class FGlyph: self.width = len(valuesX) valuesX.append(g.width) for c in g.components: - self.components.append((len(valuesX),len(valuesY))) - valuesX.append(c.scale.x) - valuesY.append(c.scale.y) - valuesX.append(c.delta.x) - valuesY.append(c.delta.y) - + self.components.append((len(valuesX), len(valuesY))) + valuesX.append(c.scale[0]) + valuesY.append(c.scale[1]) + valuesX.append(c.offset[0]) + valuesY.append(c.offset[1]) + for a in g.anchors: self.anchors.append((len(valuesX), len(valuesY))) valuesX.append(a.x) valuesY.append(a.y) - - for i in range(len(g.nodes)): - self.nodes.append([]) - for j in range (len(g.nodes[i])): - self.nodes[i].append( (len(valuesX), len(valuesY)) ) - valuesX.append(g.nodes[i][j].x) - valuesY.append(g.nodes[i][j].y) - - for k in g.kerning: - self.kerning.append(KerningPair(k)) - + + for i in range(len(g)): + self.contours.append([]) + for j in range (len(g[i].points)): + self.contours[i].append((len(valuesX), len(valuesY))) + valuesX.append(g[i].points[j].x) + valuesY.append(g[i].points[j].y) + +# for k in g.kerning: +# self.kerning.append(KerningPair(k)) + self.dataX = array(valuesX) self.dataY = array(valuesY) @@ -102,24 +104,26 @@ class FGlyph: g.width = self._derefX(self.width) if len(g.components) == len(self.components): for i in range(len(self.components)): - g.components[i].scale.x = self._derefX( self.components[i][0] + 0) - g.components[i].scale.y = self._derefY( self.components[i][1] + 0) - g.components[i].deltas[0].x = self._derefX( self.components[i][0] + 1) - g.components[i].deltas[0].y = self._derefY( self.components[i][1] + 1) - g.kerning = [] + g.components[i].scale[0] = self._derefX(self.components[i][0] + 0) + g.components[i].scale[1] = self._derefY(self.components[i][1] + 0) + g.components[i].offset[0] = self._derefX(self.components[i][0] + 1) + g.components[i].offset[1] = self._derefY(self.components[i][1] + 1) +# g.kerning = [] if len(g.anchors) == len(self.anchors): for i in range(len(self.anchors)): g.anchors[i].x = self._derefX( self.anchors[i][0]) g.anchors[i].y = self._derefY( self.anchors[i][1]) - for k in self.kerning: - g.kerning.append(KerningPair(k)) - for i in range( len(g.nodes)) : - for j in range (len(g.nodes[i])): - g.nodes[i][j].x = self._derefX( self.nodes[i][j][0] ) - g.nodes[i][j].y = self._derefY( self.nodes[i][j][1] ) - - def isCompatible(self,g): - return len(self.dataX) == len(g.dataX) and len(self.dataY) == len(g.dataY) and len(g.nodes) == len(self.nodes) +# for k in self.kerning: +# g.kerning.append(KerningPair(k)) + for i in range(len(g)) : + for j in range (len(g[i].points)): + g[i].points[j].x = self._derefX(self.contours[i][j][0]) + g[i].points[j].y = self._derefY(self.contours[i][j][1]) + + def isCompatible(self, g): + return (len(self.dataX) == len(g.dataX) and + len(self.dataY) == len(g.dataY) and + len(g.contours) == len(self.contours)) def __add__(self,g): if self.isCompatible(g): @@ -170,15 +174,15 @@ class FGlyph: gF.dataX += (g.dataX - gF.dataX) * v.x gF.dataY += (g.dataY - gF.dataY) * v.y - gF.kerning = interpolateKerns(self,g,v) +# gF.kerning = interpolateKerns(self, g, v) return gF def copy(self): ng = FGlyph() - ng.nodes = list(self.nodes) + ng.contours = list(self.contours) ng.width = self.width ng.components = list(self.components) - ng.kerning = list(self.kerning) +# ng.kerning = list(self.kerning) ng.anchors = list(self.anchors) ng.dataX = self.dataX.copy() ng.dataY = self.dataY.copy() @@ -198,10 +202,9 @@ class FGlyph: class Master: - - - def __init__(self,font=None,v=0,ifont=None, kernlist=None, overlay=None): - if isinstance(font,FFont): + + def __init__(self, font=None, v=0, kernlist=None, overlay=None): + if isinstance(font, FFont): self.font = None self.ffont = font elif isinstance(font,str): @@ -210,10 +213,9 @@ class Master: self.font = font else: self.font = font - self.ifont = ifont self.ffont = FFont(font) if isinstance(v,float) or isinstance(v,int): - self.v = Point(v,v) + self.v = RPoint(v, v) else: self.v = v if kernlist != None: @@ -226,34 +228,19 @@ class Master: #TODO implement class based kerning / external kerning file def openFont(self, path, overlayPath=None): - fl.Open(path,True) - self.ifont = fl.ifont - for g in fl.font.glyphs: + self.font = OpenFont(path) + for g in self.font: size = len(g) csize = len(g.components) if (size > 0 and csize > 0): - g.Decompose() + decomposeGlyph(g) - self.ifont = fl.ifont - self.font = fl.font if overlayPath != None: - fl.Open(overlayPath,True) - ifont = self.ifont + overlayFont = OpenFont(overlayPath) font = self.font - overlayIfont = fl.ifont - overlayFont = fl.font + for overlayGlyph in overlayFont: + font.insertGlyph(overlayGlyph) - for overlayGlyph in overlayFont.glyphs: - glyphIndex = font.FindGlyph(overlayGlyph.name) - if glyphIndex != -1: - oldGlyph = Glyph(font.glyphs[glyphIndex]) - kernlist = [KerningPair(k) for k in oldGlyph.kerning] - font.glyphs[glyphIndex] = Glyph(overlayGlyph) - font.glyphs[glyphIndex].kerning = kernlist - else: - font.glyphs.append(overlayGlyph) - fl.UpdateFont(ifont) - fl.Close(overlayIfont) self.ffont = FFont(self.font) @@ -261,7 +248,7 @@ class Mix: def __init__(self,masters,v): self.masters = masters if isinstance(v,float) or isinstance(v,int): - self.v = Point(v,v) + self.v = RPoint(v,v) else: self.v = v @@ -282,9 +269,9 @@ class Mix: return ffont def generateFont(self, baseFont): - newFont = Font(baseFont) + newFont = baseFont.copy() #self.mixStems(newFont) todo _ fix stems code - for g in newFont.glyphs: + for g in newFont: gF = self.mixGlyphs(g.name) if gF == None: g.mark = True @@ -338,4 +325,4 @@ def interpolateKerns(gA,gB,v): if matchedKern != None: kernValue = interpolate(kA.value, matchedKern.value, v.x) kerns.append(KerningPair(kA.key,kernValue)) - return kerns
\ No newline at end of file + return kerns diff --git a/scripts/lib/fontbuild/mkmkFeature.py b/scripts/lib/fontbuild/mkmkFeature.py index b7281c6..cfc722e 100755 --- a/scripts/lib/fontbuild/mkmkFeature.py +++ b/scripts/lib/fontbuild/mkmkFeature.py @@ -1,5 +1,3 @@ -from FL import *
-
def CreateAccNameList(font, acc_anchor_name):
lst = []
for g in font.glyphs:
diff --git a/scripts/lib/fontbuild/removeGlyphOverlap.py b/scripts/lib/fontbuild/removeGlyphOverlap.py new file mode 100644 index 0000000..02e3a93 --- /dev/null +++ b/scripts/lib/fontbuild/removeGlyphOverlap.py @@ -0,0 +1,3 @@ +def removeGlyphOverlap(glyph): + #TODO(jamesgk@google.com) + pass diff --git a/scripts/lib/fontbuild/sortGlyphs.py b/scripts/lib/fontbuild/sortGlyphs.py new file mode 100644 index 0000000..26dcb65 --- /dev/null +++ b/scripts/lib/fontbuild/sortGlyphs.py @@ -0,0 +1,3 @@ +def sortGlyphsByUnicode(font): + #TODO(jamesgk@google.com + pass |