-
Notifications
You must be signed in to change notification settings - Fork 1
/
enclose.py
executable file
·53 lines (46 loc) · 1.53 KB
/
enclose.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env fontforge
import fontforge, psMat
from sys import argv, stderr
from re import search
from math import pi
if len(argv) < 4:
stderr.write("Usage: "+argv[0]+" encloser enclosed [...] outfile\n")
quit(1)
fontforge.setPrefs('CoverageFormatsAllowed', 1)
srcFont = fontforge.open(argv[1])
addFonts = []
for i in range(2, len(argv)-1):
addFonts += [fontforge.open(argv[i])]
proportionalFlag = (search('proportional', argv[0]) is not None)
verticalFlag = (search('vert', argv[0]) is not None)
for srcGlyph in srcFont.glyphs():
if srcGlyph.isWorthOutputting():
gNum = srcGlyph.unicode
for addFont in addFonts:
try:
if addFont[gNum + 0x8000].isWorthOutputting():
addFont.selection.select(("encoding",), gNum + 0x8000)
addFont.copy()
srcFont.selection.select(("encoding",), gNum)
srcFont.pasteInto()
srcFont.correctDirection()
if proportionalFlag:
for glyph in srcFont.selection.byGlyphs:
if verticalFlag:
glyph.transform(psMat.translate(0, srcFont.descent))
if glyph.color != 0xffff00: glyph.transform(psMat.rotate(pi / 2))
glyph.left_side_bearing = 50
glyph.right_side_bearing = 50
if verticalFlag:
w = glyph.width
glyph.transform(psMat.rotate(-pi / 2))
glyph.transform(psMat.translate(0, srcFont.ascent))
glyph.width = srcFont.em
glyph.vwidth = w
break
except TypeError:
pass
else:
stderr.write("Glyph ID " + str(gNum & 0x7fff) + " not found\n")
srcGlyph.removeOverlap()
srcFont.generate(argv[-1])