From f43c450449ea4e94e138737db46aa11a5f3f7bcd Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sat, 12 Aug 2017 09:25:56 +0100 Subject: [PATCH] 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. --- strokefont.py | 77 +++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/strokefont.py b/strokefont.py index 1a81c9e..e659510 100644 --- a/strokefont.py +++ b/strokefont.py @@ -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]) -- 2.30.2