mirror of
https://bjh21.me.uk/bedstead/.git
synced 2026-07-09 21:43:06 -04:00
Now we have one class for each broad class of stroked font. I think this will be easier to manage.
57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
from __future__ import print_function
|
|
|
|
import fontforge
|
|
from math import radians
|
|
from psMat import translate
|
|
from sys import argv
|
|
|
|
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': 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])
|
|
|
|
mode.modify_font(f)
|
|
|
|
f.save(argv[3])
|
|
|