summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/fonts/xcharter/altone.py
blob: e79b3da3a8c89ca730d148713242ca0042d7263d (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
#!/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
encfiles=set()
enclst=[]
enclstt1=[]
enclstly1=[]
encfilest1=set()
encfilesly1=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)
				else:
					enclstt1.append(enc)
				h=tmp[5][1:-4] # psfile, without .pfb or <
				a=tmp[0][:-6] # name of vf
				vflst.append(a)
				s="/usr/texbin/afm2tfm "+h+" -T "+tmfv+"/fonts/enc/dvips/xcharter/"+enc+" -v "+a+" "+tmp[0]
				afmcmds.append(s)
					
encfilest1=set(enclstt1)
encfilesly1=set(enclstly1)
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][:-6] # name of vf
				vflst.append(a)
				s="/usr/texbin/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(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("/usr/texbin/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')