Debian Codegraph @

texmf-dist/doc/fonts/xcharter/altSRB.py

raw
1 #!/usr/bin/env python
2
3 import os, sys
4
5 # Run this in the root directory containing afm files and a texmf branch
6 # Before running, all encoding files a_* should be renamed to xch_*
7 # and the corresponding changes applied to xcharter.map
8 encfiles=set()
9 enclst=[]
10 enclstt1=[]
11 enclstly1=[]
12 enclstot1=[]
13 encfilest1=set()
14 encfilesly1=set()
15 encfilesot1=set()
16 newlines=[]
17 afmcmds=[]
18 vflst=[]
19 tmfv = sys.argv[1]
20 with open(tmfv+"/fonts/map/dvips/xcharter/XCharter.map",'r') as f:
21 for line in f:
22 if "-sc-" in line:
23 tmp = line.split()
24 enc=tmp[4][2:] # omit <[
25 if (enc[-4:]==".enc") and (enc[:4]=="xch_"):
26 if "-ly1-" in line:
27 enclstly1.append(enc)
28 elif "-ot1-" in line:
29 enclstot1.append(enc)
30 else:
31 enclstt1.append(enc)
32 h=tmp[5][1:-4] # psfile, without .pfb or <
33 a=tmp[0][:-6] # name of vf
34 vflst.append(a)
35 s="afm2tfm "+h+" -T "+tmfv+"/fonts/enc/dvips/xcharter/"+enc+" -v "+a+" "+tmp[0]
36 afmcmds.append(s)
37
38 encfilest1=set(enclstt1)
39 encfilesly1=set(enclstly1)
40 encfilesot1=set(enclstot1)
41 for f in sorted(encfilest1):
42 with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'r') as g:
43 tmp = g.read()
44 k=tmp.find('/thorn')+6
45 s=tmp[k:]
46 if '/.notdef' in s:
47 s=s.replace('/.notdef','/SSsmall')
48 with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'w') as g:
49 g.write(tmp[:k]+s)
50 for f in sorted(encfilesly1):
51 with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'r') as g:
52 tmp = g.read()
53 k=tmp.find('/cedilla')+8
54 s=tmp[k:]
55 j=s.find('/')
56 if s[j:j+8]=='/.notdef':
57 s=s[:j]+'/SSsmall'+s[j+8:]
58 with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'w') as g:
59 g.write(tmp[:k]+s)
60 # We've modified the encoding files
61 # Now regenerate the --base and vpl
62
63 with open(tmfv+"/fonts/map/dvips/xcharter/XCharter.map",'r') as f:
64 for line in f:
65 if "-tosf-" in line:
66 tmp = line.split()
67 enc=tmp[4][2:]
68 if (enc[-4:]==".enc") and (enc[:4]=="xch_"):
69 enc=enc[:3]+"1"+enc[3:]
70 enclst.append(enc)
71 tmp[0]="XCharter1"+tmp[0][8:]
72 tmp[2]=tmp[2][:8]+"1"+tmp[2][8:] # encoding name
73 tmp[4]="<["+enc # encoding file, prefixed by <[
74 newlines.append(' '.join(tmp))
75 h=tmp[5][1:-4] # psfile, without .pfb or <
76 a=tmp[0]
77 if a[-6:]=="--base":
78 a=tmp[0][:-6] # name of vf
79 vflst.append(a)
80 s="afm2tfm "+h+" -T "+tmfv+"/fonts/enc/dvips/xcharter/"+enc+" -v "+a+" "+tmp[0]
81 afmcmds.append(s)
82
83 #print newlines
84 encfiles=set(enclst)
85 #print sorted(encfiles)
86 #sys.exit()
87 for f in sorted(encfiles):
88 f0=f[:3]+f[4:] # remove "1"
89 os.system("/bin/cp -fp "+tmfv+"/fonts/enc/dvips/xcharter/"+f0+" "+tmfv+"/fonts/enc/dvips/xcharter/"+f)
90 with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'r') as g:
91 tmp = g.read()
92 tmp=tmp.replace("AutoEnc","AutoEnc1")
93 tmp=tmp.replace("one.oldstyle","one.Alt.oldstyle")
94 with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'w') as g:
95 g.write(tmp)
96
97 #Finally, write the afmcmds and update mapfile
98 for j in range(len(vflst)):
99 a=vflst[j]
100 s=afmcmds[j]
101 print s
102 if os.system(s)==0:
103 if os.system("vptovf "+a)==0:
104 os.system("/bin/mv -f "+a+".tfm "+tmfv+"/fonts/tfm/public/xcharter")
105 os.system("/bin/mv -f "+a+"--base.tfm "+tmfv+"/fonts/tfm/public/xcharter")
106 os.system("/bin/mv -f "+a+".vf "+tmfv+"/fonts/vf/public/xcharter")
107
108 with open(tmfv+"/fonts/map/dvips/xcharter/XCharter.map",'a+') as f:
109 for s in newlines:
110 f.write(s+'\n')