2 %%Creator: Eric Gisin <egisin@waterloo.csnet>
3 %%Title: Print font catalog
4 % Copyright (c) 1986 Eric Gisin
5 % Copyright (C) 1992 Aladdin Enterprises, Menlo Park, CA
6 % Modified to print all 256 encoded characters.
7 % Copyright (C) 1993 Aladdin Enterprises, Menlo Park, CA
8 % Modified to print unencoded characters.
9 % Copyright (C) 1994 Aladdin Enterprises, Menlo Park, CA
10 % Modified to always create 256-element Encoding vectors.
11 % Copyright (C) 1995 Aladdin Enterprises, Menlo Park, CA
12 % Modified to print more than 128 unencoded characters.
13 % Copyright (C) 1996 Aladdin Enterprises, Menlo Park, CA
14 % Modified to leave a slightly wider left margin, because many H-P
15 % printers can't print in the leftmost 1/4" of the page.
16 % Modified to print unencoded characters in any font that has CharStrings.
17 % Copyright (C) 1999 Aladdin Enterprises, Menlo Park, CA
18 % Modified to sort unencoded characters.
19 % Copyright (C) 2000 Aladdin Enterprises, Menlo Park, CA
20 % Modified to print CIDFonts as well as fonts.
21 % O(N^2) sorting replaced with O(N log N).
22 % Copyright transferred 2000/09/15 to artofcode LLC. Send any questions to
23 % bug-gs@ghostscript.com.
25 % $Id: prfont.ps,v 1.7 2005/09/01 22:04:37 stefan Exp $
27 % Example usages at bottom of file
30 /min { 2 copy gt { exch } if pop } bind def
32 /T6 /Times-Roman findfont 6 scalefont def
35 /Base 16 def % char code output base
36 /TempEncoding [ 256 { /.notdef } repeat ] def
38 % Sort an array. Code used by permission of the author, Aladdin Enterprises.
39 /sort { % <array> <lt-proc> sort <array>
40 % Heapsort (algorithm 5.2.3H, Knuth vol. 2, p. 146),
41 % modified for 0-origin indexing. */
56 r 0 eq { recs 0 R put exit } if
60 /j j dup add 1 add def
62 recs j get recs j 1 add get LT { /j j 1 add def } if
64 j r gt { recs i R put exit } if
65 R recs j get LT not { recs i R put exit } if
72 % do single character of page
73 % output to rectangle ll=(0,-24) ur=(36,24)
74 /DoGlyph { % C, N, W set
76 % print code name, width and char name
78 N /.notdef ne {0 -20 moveto N Temp cvs show} if
79 0 -12 moveto C Base Temp cvrs show ( ) show
80 W 0.0005 add Temp cvs 0 5 getinterval show
82 % print char with reference lines
85 0 0 moveto F24 setfont N glyphshow
87 0 -6 moveto 0 24 lineto
88 W -6 moveto W 24 lineto
89 -3 0 moveto W 3 add 0 lineto
95 /N F /Encoding get C get def
96 /S (_) dup 0 C put def
97 /W F setfont S stringwidth pop def
100 /CIDTemp 20 string def
105 matrix currentmatrix nulldevice setmatrix
106 0 0 moveto N glyphshow currentpoint pop
113 /Times-Roman findfont 18 scalefont setfont
114 36 10.5 Inch moveto FName Temp cvs show ( ) show ((24 point)) show
117 % print one block of characters
118 /DoBlock { % firstcode lastcode
119 /FirstCode 2 index def
122 /Xn I FirstCode sub 16 mod def /Yn I FirstCode sub 16 idiv def
124 Xn 35 mul 24 add Yn -56 mul 9.5 Inch add translate
130 % print a line of character
131 /DoCharLine { % firstcode lastcode
132 1 exch { (_) dup 0 3 index put show pop } for
134 /DoCIDLine { % firstcode lastcode
135 1 exch { glyphshow } for
138 % initialize variables
139 /InitDoFont { % fontname font
141 /FName exch def % font name
142 /F24 F 24 scalefont def
145 /Namestring1 128 string def
146 /Namestring2 128 string def
149 % print pages of unencoded characters
150 /DoUnencoded { % glyphs
152 /Count Unencoded length def
154 % Print the unencoded characters in blocks of 128.
156 0 128 Unencoded length 1 sub
157 { /BlockStart 1 index def
158 dup 128 add Unencoded length .min 1 index sub
159 Unencoded 3 1 roll getinterval TempEncoding copy
160 /BlockEncoding exch def
161 /BlockCount BlockEncoding length def
165 { 1 index /FID eq { pop pop } { 2 index 3 1 roll put } ifelse }
166 forall dup /Encoding TempEncoding put
169 /F24 F 24 scalefont def
173 DoTitle (, unencoded characters) show
174 BlockStart dup BlockCount 1 sub add DoBlock
175 F 10 scalefont setfont
177 0 32 BlockCount 1 sub {
178 0 -0.4 Inch rmoveto gsave
179 dup 31 add BlockCount 1 sub .min
180 exch BlockStart add exch BlockStart add DoLine
189 % print font sample pages
191 dup findfont InitDoFont
193 /DoLine {DoCharLine} def
195 % Display the first 128 encoded characters.
197 DoTitle (, characters 0-127) show
199 F 10 scalefont setfont
200 36 2.0 Inch moveto 0 31 DoLine
201 36 1.6 Inch moveto 32 63 DoLine
202 36 1.2 Inch moveto 64 95 DoLine
203 36 0.8 Inch moveto 96 127 DoLine
206 % Display the second 128 encoded characters.
208 DoTitle (, characters 128-255) show
210 F 10 scalefont setfont
211 36 2.0 Inch moveto 128 159 DoLine
212 36 1.6 Inch moveto 160 191 DoLine
213 36 1.2 Inch moveto 192 223 DoLine
214 36 0.8 Inch moveto 224 255 DoLine
219 % Find and display the unencoded characters.
221 /Encoded F /Encoding get length dict def
222 F /Encoding get { true Encoded 3 1 roll put } forall
224 { pop dup Encoded exch known { pop } if }
226 exch Namestring1 cvs exch Namestring2 cvs lt
234 % print CIDFont sample pages
236 dup /CIDFont findresource InitDoFont
238 /DoLine {DoCIDLine} def
240 [ 0 1 F /CIDCount get 1 sub { } for ] DoUnencoded
244 % /Times-Roman DoFont % Test (less than a minute)
245 % /Hershey-Gothic-English DoFont % Test (8 minutes)
247 % Do a complete catalog
248 % FontDirectory {pop DoFont} forall % All fonts (quite a long time)