strokefont: More object-oriented approach.

Now we have one class for each broad class of stroked font.  I think
this will be easier to manage.
This commit is contained in:
Ben Harris 2017-08-12 09:25:56 +01:00
parent 2c5fc3b5bc
commit f43c450449

View File

@ -5,53 +5,52 @@ from math import radians
from psMat import translate
from sys import argv
chisel = fontforge.contour()
chisel.moveTo(-50, 0)
chisel.lineTo(28, 45)
chisel.lineTo(50, 0)
chisel.lineTo(-28, -45)
chisel.closed = True
class Stroker(object):
def __init__(self, fontname):
self.fontname = fontname
def modify_font(self, f):
f.strokedfont = False
for g in f.glyphs():
g.stroke(*self.nib)
g.removeOverlap()
g.addExtrema()
g.transform(translate(0, self.vshift))
f.fontname = self.fontname
return f
class Plotter(Stroker):
def __init__(self, penwidth, weight):
self.nib = ['circular', penwidth, 'round', 'round']
self.vshift = penwidth / 2.0
super(Plotter, self).__init__("BedsteadPlotter-" + weight)
class Chiseltip(Stroker):
def __init__(self, fontname):
chisel = fontforge.contour()
chisel.moveTo(-50, 0)
chisel.lineTo(28, 45)
chisel.lineTo(50, 0)
chisel.lineTo(-28, -45)
chisel.closed = True
self.nib = ['polygonal', chisel]
self.vshift = 45
super(Chiseltip, self).__init__(fontname)
modes = {
'plotter-thin': {
'nib': ['circular', 10, 'round', 'round'],
'vshift': 5,
'fontname': "BedsteadPlotter-Thin",
},
'plotter-light': {
'nib': ['circular', 50, 'round', 'round'],
'vshift': 25,
'fontname': "BedsteadPlotter-Light",
},
'plotter-medium': {
'nib': ['circular', 100, 'round', 'round'],
'vshift': 50,
'fontname': "BedsteadPlotter-Medium",
},
'plotter-bold': {
'nib': ['circular', 150, 'round', 'round'],
'vshift': 75,
'fontname': "BedsteadPlotter-Bold",
},
'chiseltip': {
'nib': ['polygonal', chisel],
'vshift': 45,
'fontname': "BedsteadChiseltip",
},
'plotter-thin': Plotter(10, "Thin"),
'plotter-light': Plotter(50, "Light"),
'plotter-medium': Plotter(100, "Medium"),
'plotter-bold': Plotter(150, "Bold"),
'chiseltip': Chiseltip("BedsteadChiseltip"),
}
mode = modes[argv[1]]
f = fontforge.open(argv[2])
f.strokedfont = False
mode.modify_font(f)
for g in f.glyphs():
g.stroke(*mode['nib'])
g.removeOverlap()
g.addExtrema()
g.transform(translate(0, mode['vshift']))
f.fontname = mode['fontname']
f.save(argv[3])