| 1 |
|
| 2 |
|
| 3 |
import re |
| 4 |
import argparse |
| 5 |
import fontforge |
| 6 |
|
| 7 |
argparser = argparse.ArgumentParser(description= |
| 8 |
"Generate a small-caps variant of a font out of a source \ |
| 9 |
for older programs that do not support OpenType features.") |
| 10 |
argparser.add_argument( |
| 11 |
'input', |
| 12 |
help='Input font source, e.g. "/some/path/Bla.sfdir"') |
| 13 |
argparser.add_argument( |
| 14 |
'output', |
| 15 |
help='Output font file, e.g. "/some/path/Bla.otf"') |
| 16 |
argparser.add_argument( |
| 17 |
'version', |
| 18 |
help='Version string to embed into the font file, e.g. "v1.1"') |
| 19 |
args = argparser.parse_args() |
| 20 |
|
| 21 |
font = fontforge.open(args.input) |
| 22 |
font.version = args.version |
| 23 |
font.encoding = 'UnicodeFull' |
| 24 |
|
| 25 |
for glyph in font: |
| 26 |
|
| 27 |
|
| 28 |
match = re.search("^([a-z].*)\.sc$", glyph) |
| 29 |
|
| 30 |
if match: |
| 31 |
lowercase_glyph = match.group(1) |
| 32 |
smallcaps_replacement = glyph |
| 33 |
|
| 34 |
font.selection.select(smallcaps_replacement) |
| 35 |
font.copy() |
| 36 |
font.selection.select(lowercase_glyph) |
| 37 |
font.paste() |
| 38 |
|
| 39 |
font.generate(args.output) |