File: rmfleuroninstructions.py

package info (click to toggle)
fonts-junicode 2%2Bgit20230104%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 114,100 kB
  • sloc: python: 162; sh: 119; xml: 18; makefile: 16
file content (40 lines) | stat: -rw-r--r-- 1,555 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from fontTools import ttLib
from fontTools.ttLib import ttFont, tables
import argparse

# ttfautohint goes crazy trying to hint the very complicated outlines of the
# fleurons in the font, and generates more than 90,000 bytes of completely
# useless code. This tiny program deletes the instructions for those glyphs.

fleurons = ["uniE270", "uniE27D", "uniE670", "uniE67D", "uniE68A", "uniE736",
            "uniE8B0", "uniE8B1", "uniEF90", "uniEF91", "uniEF92", "uniEF93",
            "uniEF98", "uniEF99", "uniEF94", "uniEF95", "uniEF96", "uniEF97",
            "uniEF9A", "uniEF9B", "uniEF9C", "uniF018", "uniF019", "uniF014",
            "uniEF9F", "uniF011", "uniF01D", "uniF01E", "uniF01B", "uni2619",
            "uni261A", "uni261B", "uni261C", "uni261D", "uni261E", "uni261F",
            "uni2740", "uni2766", "uni2767", "uniF19F" ]

argparser = argparse.ArgumentParser(prog='xgridfit',
                                    description='Remove instructions for fleurons in a font.')
argparser.add_argument("inputfile", help='Font to process.')
argparser.add_argument("outputfile", nargs="?", help="Font to output.")
args = argparser.parse_args()
inputfile    = args.inputfile
outputfile   = args.outputfile
if not outputfile:
    outputfile = inputfile

thisFont = ttLib.TTFont(inputfile)
print("Processing " + inputfile)
altered = False

for f in fleurons:
    try:
        glyph = thisFont['glyf'][f]
        glyph.program.fromAssembly("")
        altered = True
    except Exception:
        pass

if altered:
    thisFont.save(outputfile, 1)