Dusted off - made to work to some extent

This commit is contained in:
2026-02-18 03:34:17 +01:00
parent 4ce505ffea
commit 9c0cf9e5fb
8 changed files with 55 additions and 38 deletions

View File

@@ -18,6 +18,7 @@ def run(path, font_name):
font.fontname = font_name
# noinspection SpellCheckingInspection
font.familyname = 'Hershey'
print(os.listdir(os.path.join(svg_folder, font_name)))
for svg in os.listdir(os.path.join(svg_folder, font_name)):
if svg[-4:] == '.svg':
match = re.match(r'ascii(\d+)_l(-?[\d.]+)_r(-?[\d.]+).svg', svg)
@@ -26,18 +27,29 @@ def run(path, font_name):
glyph = font.createMappedChar(character)
# Import the outlines *before* setting the bearings. Otherwise, everything will be reset.
glyph.importOutlines(os.path.join(svg_folder, font_name, svg))
print("and then?", os.path.join(svg_folder, font_name, svg))
glyph.importOutlines(os.path.join(svg_folder, font_name, svg)) # SILENT CRASH
glyph.stroke('circular', stroke_size, 'round', 'round')
# glyph.correctDirection()
glyph.removeOverlap()
glyph.correctDirection()
glyph.simplify()
glyph.left_side_bearing = float(match.group(2))
glyph.round()
glyph.removeOverlap()
#glyph.stroke('circular', stroke_size, 'round', 'round')
# glyph.correctDirection()
#glyph.removeOverlap()
#glyph.simplify()
glyph.left_side_bearing = int(round(float(match.group(2))))
# Compensate for the stroke with on the right side bearing
glyph.right_side_bearing = float(match.group(3)) - stroke_size
glyph.right_side_bearing = int(round(float(match.group(3)) - stroke_size))
else:
print(f'Not a SVG file: {os.path.join(svg_folder, font_name, svg)}')
# Assumes ttf folder exists
print("Done gen, writing")
ttf_folder = os.path.join(path, 'ttf')
font.generate(os.path.join(ttf_folder, font_name + '.ttf'))