Debian Codegraph @

texmf-dist/doc/fonts/xcharter/altone.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 t2aligs='''% LIGKERN hyphen hyphen =: endash ; endash hyphen =: emdash ;
9 % LIGKERN quoteleft quoteleft =: quotedblleft ;
10 % LIGKERN quoteright quoteright =: quotedblright ;
11 % LIGKERN comma comma =: quotedblbase ; less less =: guillemotleft ;
12 % LIGKERN greater greater =: guillemotright ;
13 % LIGKERN f f =: ff ; f i =: fi ; f l =: fl ; ff i =: ffi ; ff l =: ffl ;
14 '''
15 encfiles=set()
16 enclst=[]
17 enclstt1=[]
18 enclstts1=[]
19 enclstly1=[]
20 enclstot1=[]
21 encfilest1=set()
22 encfilests1=set()
23 encfilesly1=set()
24 encfilesot1=set()
25 newlines=[]
26 afmcmds=[]
27 vflst=[]
28 tmfv = sys.argv[1]
29 with open(tmfv+"/fonts/map/dvips/xcharter/XCharter.map",'r') as f:
30 for line in f:
31 if "-sc-" in line:
32 tmp = line.split()
33 enc=tmp[4][2:] # omit <[
34 if (enc[-4:]==".enc") and (enc[:4]=="xch_"):
35 if "-ly1-" in line:
36 enclstly1.append(enc)
37 elif "-ot1-" in line:
38 enclstot1.append(enc)
39 elif "-t1-" in line:
40 enclstt1.append(enc)
41 elif "-ts1-" in line:
42 enclstts1.append(enc)
43 else:
44 continue
45 h=tmp[5][1:-4] # psfile, without .pfb or <
46 a=tmp[0][:-6] # name of vf
47 vflst.append(a)
48 s="/Library/TeX/texbin/afm2tfm "+h+" -T "+tmfv+"/fonts/enc/dvips/xcharter/"+enc+" -v "+a+" "+tmp[0]
49 afmcmds.append(s)
50
51 encfilest1=set(enclstt1)
52 encfilests1=set(enclstts1)
53 encfilesly1=set(enclstly1)
54 encfilesot1=set(enclstot1)
55 for f in sorted(encfilest1):
56 with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'r') as g:
57 tmp = g.read()
58 k=tmp.find('/thorn')+6
59 s=tmp[k:]
60 if '/.notdef' in s:
61 s=s.replace('/.notdef','/SSsmall')
62 with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'w') as g:
63 g.write(tmp[:k]+s)
64 for f in sorted(encfilesly1):
65 with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'r') as g:
66 tmp = g.read()
67 k=tmp.find('/cedilla')+8
68 s=tmp[k:]
69 j=s.find('/')
70 if s[j:j+8]=='/.notdef':
71 s=s[:j]+'/SSsmall'+s[j+8:]
72 with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'w') as g:
73 g.write(tmp[:k]+s)
74 # We've modified the encoding files
75 # Now regenerate the --base and vpl
76
77 with open(tmfv+"/fonts/map/dvips/xcharter/XCharter.map",'r') as f:
78 for line in f:
79 if ("osf-" in line) or ("-ts1" in line):
80 tmp = line.split()
81 enc=tmp[4][2:]
82 if (enc[-4:]==".enc") and (enc[:4]=="xch_"):
83 enc=enc[:3]+"1"+enc[3:]
84 enclst.append(enc)
85 tmp[0]="XCharter1"+tmp[0][8:]
86 tmp[2]=tmp[2][:8]+"1"+tmp[2][8:] # encoding name
87 tmp[4]="<["+enc # encoding file, prefixed by <[
88 newlines.append(' '.join(tmp))
89 h=tmp[5][1:-4] # psfile, without .pfb or <
90 a=tmp[0]
91 if a[-6:]=="--base":
92 a=tmp[0][:-6] # name of vf
93 vflst.append(a)
94 s="afm2tfm "+h+" -T "+tmfv+"/fonts/enc/dvips/xcharter/"+enc+" -v "+a+" "+tmp[0]
95 afmcmds.append(s)
96
97 #print(newlines)
98 encfiles=set(enclst)
99 #print sorted(encfiles)
100 #sys.exit()
101 for f in sorted(encfiles):
102 f0=f[:3]+f[4:] # remove "1"
103 os.system("/bin/cp -fp "+tmfv+"/fonts/enc/dvips/xcharter/"+f0+" "+tmfv+"/fonts/enc/dvips/xcharter/"+f)
104 with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'r') as g:
105 tmp = g.read()
106 tmp=tmp.replace("AutoEnc","AutoEnc1")
107 tmp=tmp.replace("one.oldstyle","one.Alt.oldstyle")
108 tmp=tmp.replace("one.tosf","one.Alt.tosf")
109 tmp=tmp.replace("/Thorn /.notdef","/Thorn /uni1E9E.ss01")
110 tmp=tmp.replace("/cedilla /.notdef","/cedilla /uni1E9E.ss01")
111 with open(tmfv+"/fonts/enc/dvips/xcharter/"+f,'w') as g:
112 g.write(t2aligs)
113 g.write(tmp)
114 print('++++++++++++++++++++++++++++++++')
115 # Write the afmcmds and update mapfile
116 for j in range(len(vflst)):
117 a=vflst[j]
118 s=afmcmds[j]
119 print(s)
120 if os.system(s)==0:
121 if os.system("vptovf "+a)==0:
122 os.system("/bin/mv -f "+a+".tfm "+tmfv+"/fonts/tfm/public/xcharter")
123 os.system("/bin/mv -f "+a+"--base.tfm "+tmfv+"/fonts/tfm/public/xcharter")
124 os.system("/bin/mv -f "+a+".vf "+tmfv+"/fonts/vf/public/xcharter")
125
126 # Get rid of 12 spurious vf files
127 #os.system("cd "+tmfv+"/fonts/vf/public/xcharter;/bin/rm -f XCharter1-*osf*.vf")
128
129 with open(tmfv+"/fonts/map/dvips/xcharter/XCharter.map",'a+') as f:
130 for s in newlines:
131 f.write(s+'\n')