Constitutional Crisis: Fix typos and formatting errors
[ccbib.git] / psutils / getafm.sh
blob1c6cd21cf77dabc5673a6327b90c9d0be8b5a787
1 #!/bin/sh
3 if [ $# -ne 1 ]; then
4 echo "usage: $0 font-name | gsnd - >font-name.afm" >&2
5 exit 1
6 fi
8 cat << EOF
9 %!
10 % produce .afm for $1
11 % (c) 1993 by Robert Joop <rj@rainbow.in-berlin.de>
12 % inspired by two other versions of this theme which are
13 % getafm 1.00 (c) AJCD
14 % and getafm.ps by an unknown author,
15 % modified by J. Daniel Smith <dsmith@mailhost.aa.cad.slb.com>
17 % Metrics dictionary code added by AJCD, 7/6/93
19 /getafmdict 100 dict dup begin
21 /buf 256 string def
22 /buf2 16 string def
24 /prany % dict dictname printname -> dict
26 2 index 2 index cvn known
28 print % printname
29 ( ) print
30 1 index exch cvn get =
33 (Comment /FontInfo contains no /) print
34 2 copy eq
36 = % printname
37 pop % dictname
40 exch
41 print % dictname
42 (, therefore no ) print
43 = % printname
45 ifelse
47 ifelse
49 bind def
51 /printfontname
53 (FontName)dup prany
55 bind def
57 /printfontinfo
59 dup /FontInfo known
61 dup /FontInfo get
62 (FullName)dup prany
63 (FamilyName)dup prany
64 (Weight)dup prany
65 (ItalicAngle)dup prany
66 (isFixedPitch)(IsFixedPitch) prany
67 (UnderlinePosition)dup prany
68 (UnderlineThickness)dup prany
69 (Version)(version) prany
70 (Notice)dup prany
71 pop
74 (Comment Font lacks a /FontInfo!)=
76 ifelse
78 bind def
80 /prbbox % llx lly urx ury -> -
82 4 1 roll 3 1 roll exch % swap top 4 elements
83 4 { ( ) print buf cvs print } repeat
85 bind def
87 /getbbox % fontdict chardict character -> fontdict chardict llx lly urx ury
89 gsave
90 2 index setfont 0 0 moveto
91 false charpath flattenpath pathbbox
92 grestore
94 bind def
96 /printmiscinfo
98 dup /FontBBox known
100 (FontBBox) print
101 dup /FontBBox get aload pop prbbox ()=
104 (Comment missing required /FontBBox)=
105 quit
107 ifelse
108 2 copy exch get
109 dup /H known
110 1 index /x known and
111 1 index /d known and
112 1 index /p known and
113 dup /looksRoman exch def
115 (CapHeight ) print
116 (H) getbbox
117 ceiling cvi = pop pop pop
118 (XHeight ) print
119 (x) getbbox
120 ceiling cvi = pop pop pop
121 (Ascender ) print
122 (d) getbbox
123 ceiling cvi = pop pop pop
124 (Descender ) print
125 (p) getbbox
126 pop pop floor cvi = pop
129 (Comment font doesn't contain H, x, d and p; therefore no CapHeight, XHeight, Ascender and Descender)=
131 ifelse
133 dup /Encoding get
135 [ (ISOLatin1Encoding) /ISOLatin1Encoding ]
136 [ (AdobeStandardEncoding) /StandardEncoding ]
139 aload pop dup where
141 exch get 2 index eq
143 (EncodingScheme ) print
144 buf cvs =
149 ifelse
152 pop pop
154 ifelse
156 forall
159 bind def
161 /printcharmetric
163 % chardictname fontdict charnamedict encoding charindex charname
165 4 index dup length dict dup begin exch
167 1 index /FID ne
168 2 index /UniqueID ne
171 1 index /Encoding eq { 256 array copy } if
174 { pop pop }
175 ifelse
177 forall
179 dup /Encoding get 32 3 index put
180 /f2 exch definefont
181 setfont
183 (C ) print
184 1 index buf cvs print
186 ( ; WX ) print
187 % Metrics entries are:
188 % 1 number: which is the character width
189 % an array of 2 numbers: which are the left sidebearing and width
190 % an array of 4 numbers: x & y left sidebearing, width and height
191 dup 5 index % /charname fontdict
192 dup /Metrics known {
193 /Metrics get exch 2 copy known {
194 get dup type /arraytype eq {
195 dup length 2 eq
196 {1 get} {2 get} ifelse
197 } if
198 round cvi buf cvs print
200 pop pop ( ) stringwidth pop round cvi buf cvs print
201 } ifelse
203 pop pop ( ) stringwidth pop round cvi buf cvs print
204 } ifelse
206 ( ; N ) print
207 dup buf cvs print
209 ( ; B) print
210 gsave
211 newpath 0 0 moveto
212 ( ) true charpath flattenpath pathbbox
213 grestore
214 2 { ceiling cvi 4 1 roll } repeat
215 2 { floor cvi 4 1 roll } repeat
216 prbbox
218 looksRoman
221 [ /f [ /i /f /l ] ]
222 [ /ff [ /i /l ] ]
225 aload pop 1 index 3 index eq
228 1 index buf cvs
229 length
230 1 index buf2 cvs dup length
231 2 index add
233 4 2 roll putinterval
234 buf 0
235 3 -1 roll getinterval
236 dup cvn
237 7 index
238 exch known
240 exch
241 ( ; L ) print
242 buf2 cvs print
243 ( ) print
244 print
247 pop pop
249 ifelse
251 forall
252 pop
255 pop pop
257 ifelse
259 forall
264 ( ;)=
266 bind def
268 /printcharmetrics
270 (StartCharMetrics ) print
271 2 copy exch get length 1 sub buf cvs =
273 256 dict dup begin
274 1 index /Encoding get
275 { null def }
276 forall
278 % chardictname fontdict charnamedict
279 1 index /Encoding get
280 0 1 255
282 % encoding index
283 2 copy get
284 dup /.notdef eq { pop } { printcharmetric } ifelse
285 pop % index
286 } for
289 3 index 5 index get
292 dup /.notdef eq
293 { pop }
295 % chardictname fontdict charnamedict encoding charindex charname
296 dup 4 index exch known
297 { pop }
298 { printcharmetric }
299 ifelse
301 ifelse
303 forall
304 % charnamedict encoding index
305 pop pop pop
307 (EndCharMetrics)=
309 bind def
311 /printfontmetrics
313 (StartFontMetrics 3.0)=
314 (Comment Produced by getafm 3.0 (which is by rj@rainbow.in-berlin.de))=
316 printfontname
317 printfontinfo
318 printmiscinfo
319 printcharmetrics
321 (EndFontMetrics)=
323 bind def
325 end def
327 /getafm
329 getafmdict begin
330 save exch
331 findfont 1000 scalefont
333 null
334 [ /CharDefs /CharData /CharProcs /CharStrings ]
336 2 index 1 index known { exch } if
339 forall
340 dup null eq
342 (can't find dictionary with character data!)=
343 quit
346 exch % dictname fontdict
348 printfontmetrics
350 pop pop
351 restore
354 bind def
356 /$1 getafm