summaryrefslogtreecommitdiff
path: root/fonts/xcharter/doc/altone.py
blob: 0f89240d09c4bd40c71eb2f414f656a67312438b (plain)
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
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python

import os, sys

# Run this in the root directory containing afm files and a texmf branch
# Before running, all encoding files a_* should be renamed to xch_*
# and the corresponding changes applied to xcharter.map
t2aligs='''% LIGKERN hyphen hyphen =: endash ; endash hyphen =: emdash ;
% LIGKERN quoteleft quoteleft =: quotedblleft ;
% LIGKERN quoteright quoteright =: quotedblright ;
% LIGKERN comma comma =: quotedblbase ; less less =: guillemotleft ;
% LIGKERN greater greater =: guillemotright ;
% LIGKERN f f =: ff ; f i =: fi ; f l =: fl ; ff i =: ffi ; ff l =: ffl ;
'''
encfiles=set()
enclst=[]
enclstt1=[]
enclstly1=[]
enclstot1=[]
encfilest1=set()
encfilesly1=set()
encfilesot1=set()
newlines=[]
afmcmds=[]
vflst=[]
tmfv = sys.argv[1]
with open(tmfv+"/fonts/map/dvips/xcharter/XCharter.map",'r') as f:
	for line in f:
		if "-sc-" in line:
			tmp = line.split()
			enc=tmp[4][2:] # omit <[
			if (enc[-4:]==".enc") and (enc[:4]=="xch_"):
				if "-ly1-" in line:
					enclstly1.append(enc)
				elif "-ot1-" in line:
					enclstot1.append(enc)
				else:
					enclstt1.append(enc)
				h=tmp[5][1:-4] # psfile, without .pfb or <
				a=tmp[0][:-6] # name of vf
				vflst.append(a)
				s="/Library/TeX/texbin/afm2tfm "+h+" -T "+tmfv+"/fonts/enc/dvips/xcharter/"+enc+" -v "+a+" "+tmp[0]
				afmcmds.append(s)
					
encfilest1=set(enclstt1)
encfilesly1=set(enclstly1)
encfilesot1=set(enclstot1)
for f in sorted(encfilest1):
	with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'r') as g:
		tmp = g.read()
		k=tmp.find('/thorn')+6
		s=tmp[k:]
		if '/.notdef' in s:
			s=s.replace('/.notdef','/SSsmall')
	with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'w') as g:
		g.write(tmp[:k]+s)
for f in sorted(encfilesly1):
	with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'r') as g:
		tmp = g.read()
		k=tmp.find('/cedilla')+8
		s=tmp[k:]
		j=s.find('/')
		if s[j:j+8]=='/.notdef':
			s=s[:j]+'/SSsmall'+s[j+8:]
	with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'w') as g:
		g.write(tmp[:k]+s)
# We've modified the encoding files
# Now regenerate the --base and vpl

with open(tmfv+"/fonts/map/dvips/xcharter/XCharter.map",'r') as f:
	for line in f:
		if "-tosf-" in line:
			tmp = line.split()
			enc=tmp[4][2:]
			if (enc[-4:]==".enc") and (enc[:4]=="xch_"):
				enc=enc[:3]+"1"+enc[3:]
				enclst.append(enc)
				tmp[0]="XCharter1"+tmp[0][8:]
				tmp[2]=tmp[2][:8]+"1"+tmp[2][8:] # encoding name
				tmp[4]="<["+enc # encoding file, prefixed by <[
				newlines.append(' '.join(tmp))
				h=tmp[5][1:-4] # psfile, without .pfb or <
				a=tmp[0]
				if a[-6:]=="--base":
					a=tmp[0][:-6] # name of vf
				vflst.append(a)
				s="afm2tfm "+h+" -T "+tmfv+"/fonts/enc/dvips/xcharter/"+enc+" -v "+a+" "+tmp[0]
				afmcmds.append(s)
			
#print newlines
encfiles=set(enclst)
#print sorted(encfiles)
#sys.exit()
for f in sorted(encfiles):
	f0=f[:3]+f[4:] # remove "1"
	os.system("/bin/cp -fp "+tmfv+"/fonts/enc/dvips/xcharter/"+f0+" "+tmfv+"/fonts/enc/dvips/xcharter/"+f)
	with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'r') as g:
		tmp = g.read()
		tmp=tmp.replace("AutoEnc","AutoEnc1")
		tmp=tmp.replace("one.oldstyle","one.Alt.oldstyle")
	with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'w') as g:
		g.write(t2aligs)
		g.write(tmp)

#Finally, write the afmcmds and update mapfile
for j in range(len(vflst)):
	a=vflst[j]
	s=afmcmds[j]
	print s
	if os.system(s)==0:
		if os.system("vptovf "+a)==0:
			os.system("/bin/mv -f "+a+".tfm "+tmfv+"/fonts/tfm/public/xcharter")
			os.system("/bin/mv -f "+a+"--base.tfm "+tmfv+"/fonts/tfm/public/xcharter")
			os.system("/bin/mv -f "+a+".vf "+tmfv+"/fonts/vf/public/xcharter")
		
with open(tmfv+"/fonts/map/dvips/xcharter/XCharter.map",'a+') as f:
	for s in newlines:
		f.write(s+'\n')