-
Notifications
You must be signed in to change notification settings - Fork 0
/
fontforge-update-90.txt
106 lines (84 loc) · 3.19 KB
/
fontforge-update-90.txt
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#fontforge scripts
#ff script1. rotate all chinese fonts
Open('C:\\Users\\Administrator\\Documents\\LXGWWenKaiMonoGB-Light-Bruce.sfd');
Select(11904,1114370);
Rotate(90)
Save('C:\\Users\\Administrator\\Documents\\newfont.sfd');
Quit(0);
不能用这个脚本 会导致长宽有问题,
要用UI open 字体 call script 选ff,然后使用Select(11904,1114370);,然后用界面的transform rotate 90 whiteshin, 默认勾选 Transform Width Too 和 Transform simple positioning features & Kern pair 然后click OK.
如果fontforge 闪退,则从新进入 recover yes to All, 然后肉眼查看fail 在哪个字了,从断开的字开始做Select 再次执行。
完了之后记得改font 信息。做完保存为 newfont.sfd文件。
#fontforge python scripts
#py script. vertical center.
import logging
# 配置日志格式和级别
logging.basicConfig(filename='c:\\log1.txt', level=logging.INFO)
thisfont =fontforge.open('C:\\Users\Administrator\\Documents\\newfont.sfd') #Open a font
# change all fonts vertical center
startglyph = 11904
endglyph = 1114370
# 外层循环每次处理10000个字符的范围
chunk_size = 10000
for outer_start in range(startglyph, endglyph + 1, chunk_size):
outer_end = min(outer_start + chunk_size - 1, endglyph)
for i in range(outer_start, outer_end + 1):
try:
ytop = thisfont[i].boundingBox()[-1] # counted from baseline, excluding descent!
ybot = thisfont[i].boundingBox()[1] # same note as above
translation_y = (thisfont.ascent - thisfont.descent - (ytop + ybot)) / 2
if translation_y != 0:
thisfont[i].transform(psMat.translate(0, translation_y))
logging.info("%d complete", i)
else:
logging.info("%d no change", i)
except Exception as e:
logging.info("%d Error skip", i)
thisfont.save('C:\\Users\Administrator\\Documents\\newtryvcenter.sfd') #and save it.
thisfont.quit()
logging.info("all complete.")
上述python 脚本保存成一个pytest.txt 要用powershell或者cmd到 fontforge的目录 bin/fontforge.exe -lang=py -script pytest.txt 执行,一般不会出错,然后可以用powershell查看get-content c:\log1.txt -wait 看进度.
#ff script2. 水平居中,同时把中文书名号,中式括号等转回来, 把中文双引但引替换成 中式括号
Open('C:\\Users\\Administrator\\Documents\\newtryvcenter.sfd');
Select(11904,1114370);
CenterInWidth();
Select(12296,12315)
Rotate(-90);
Select(65288);
Rotate(-90);
Select(65289);
Rotate(-90);
Select(65306);
Rotate(-90);
Select(65339);
Rotate(-90);
Select(65341);
Rotate(-90);
Select(65371);
Rotate(-90);
Select(65373);
Rotate(-90);
Select(65378);
Rotate(-90);
Select(65379);
Rotate(-90);
Select(12300);
Copy();
Select(8220);
Paste();
Select(12301);
Copy();
Select(8221);
Paste();
Select(12302);
Copy();
Select(8216);
Paste();
Select(12303);
Copy();
Select(8217);
Paste();
Save();
Quit(0);
上述保存为fftest.txt 执行 bin/fontforge.exe -lang=ff -script fftest.txt
执行完进UI 打开newtryvcenter.sfd 然后generate font 生成字体。