prfont.ps 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. %!
  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 (ghost@aladdin.com)
  6. % Modified to print all 256 encoded characters.
  7. % Copyright (C) 1993 Aladdin Enterprises, Menlo Park, CA (ghost@aladdin.com)
  8. % Modified to print unencoded characters.
  9. % Copyright (C) 1994 Aladdin Enterprises, Menlo Park, CA (ghost@aladdin.com)
  10. % Modified to always create 256-element Encoding vectors.
  11. % Copyright (C) 1995 Aladdin Enterprises, Menlo Park, CA (ghost@aladdin.com)
  12. % Modified to print more than 128 unencoded characters.
  13. % Copyright (C) 1996 Aladdin Enterprises, Menlo Park, CA (ghost@aladdin.com)
  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 (ghost@aladdin.com)
  18. % Modified to sort unencoded characters.
  19. % Copyright (C) 2000 Aladdin Enterprises, Menlo Park, CA (ghost@aladdin.com)
  20. % Modified to print CIDFonts as well as fonts.
  21. % O(N^2) sorting replaced with O(N log N).
  22. % $Id: prfont.ps,v 1.2 2000/03/21 06:39:49 lpd Exp $
  23. % Example usages at bottom of file
  24. /#copies 1 def
  25. /min { 2 copy gt { exch } if pop } bind def
  26. /T6 /Times-Roman findfont 6 scalefont def
  27. /Temp 64 string def
  28. /Inch {72 mul} def
  29. /Base 16 def % char code output base
  30. /TempEncoding [ 256 { /.notdef } repeat ] def
  31. % Sort an array. Code used by permission of the author, Aladdin Enterprises.
  32. /sort { % <array> <lt-proc> sort <array>
  33. % Heapsort (algorithm 5.2.3H, Knuth vol. 2, p. 146),
  34. % modified for 0-origin indexing. */
  35. 10 dict begin
  36. /LT exch def
  37. /recs exch def
  38. /N recs length def
  39. N 1 gt {
  40. /l N 2 idiv def
  41. /r N 1 sub def {
  42. l 0 gt {
  43. /l l 1 sub def
  44. /R recs l get def
  45. } {
  46. /R recs r get def
  47. recs r recs 0 get put
  48. /r r 1 sub def
  49. r 0 eq { recs 0 R put exit } if
  50. } ifelse
  51. /j l def {
  52. /i j def
  53. /j j dup add 1 add def
  54. j r lt {
  55. recs j get recs j 1 add get LT { /j j 1 add def } if
  56. } if
  57. j r gt { recs i R put exit } if
  58. R recs j get LT not { recs i R put exit } if
  59. recs i recs j get put
  60. } loop
  61. } loop
  62. } if recs end
  63. } def
  64. % do single character of page
  65. % output to rectangle ll=(0,-24) ur=(36,24)
  66. /DoGlyph { % C, N, W set
  67. % print code name, width and char name
  68. T6 setfont
  69. N /.notdef ne {0 -20 moveto N Temp cvs show} if
  70. 0 -12 moveto C Base Temp cvrs show ( ) show
  71. W 0.0005 add Temp cvs 0 5 getinterval show
  72. % print char with reference lines
  73. N /.notdef ne {
  74. 3 0 translate
  75. 0 0 moveto F24 setfont N glyphshow
  76. /W W 24 mul def
  77. 0 -6 moveto 0 24 lineto
  78. W -6 moveto W 24 lineto
  79. -3 0 moveto W 3 add 0 lineto
  80. 0 setlinewidth stroke
  81. } if
  82. } def
  83. /DoChar {
  84. /C exch def
  85. /N F /Encoding get C get def
  86. /S (_) dup 0 C put def
  87. /W F setfont S stringwidth pop def
  88. DoGlyph
  89. } def
  90. /CIDTemp 20 string def
  91. /DoCID {
  92. /N exch def
  93. /C N def
  94. /W F setfont gsave
  95. matrix currentmatrix nulldevice setmatrix
  96. 0 0 moveto N glyphshow currentpoint pop
  97. grestore def
  98. DoGlyph
  99. } def
  100. % print page title
  101. /DoTitle {
  102. /Times-Roman findfont 18 scalefont setfont
  103. 36 10.5 Inch moveto FName Temp cvs show ( ) show ((24 point)) show
  104. } def
  105. % print one block of characters
  106. /DoBlock { % firstcode lastcode
  107. /FirstCode 2 index def
  108. 1 exch {
  109. /I exch def
  110. /Xn I FirstCode sub 16 mod def /Yn I FirstCode sub 16 idiv def
  111. gsave
  112. Xn 35 mul 24 add Yn -56 mul 9.5 Inch add translate
  113. I DoCode
  114. grestore
  115. } for
  116. } def
  117. % print a line of character
  118. /DoCharLine { % firstcode lastcode
  119. 1 exch { (_) dup 0 3 index put show pop } for
  120. } def
  121. /DoCIDLine { % firstcode lastcode
  122. 1 exch { glyphshow } for
  123. } def
  124. % initialize variables
  125. /InitDoFont { % fontname font
  126. /F exch def % font
  127. /FName exch def % font name
  128. /F24 F 24 scalefont def
  129. /Line0 96 string def
  130. /Line1 96 string def
  131. /Namestring1 128 string def
  132. /Namestring2 128 string def
  133. } def
  134. % print pages of unencoded characters
  135. /DoUnencoded { % glyphs
  136. /Unencoded exch def
  137. /Count Unencoded length def
  138. % Print the unencoded characters in blocks of 128.
  139. 0 128 Unencoded length 1 sub
  140. { /BlockStart 1 index def
  141. dup 128 add Unencoded length min 1 index sub
  142. Unencoded 3 1 roll getinterval TempEncoding copy
  143. /BlockEncoding exch def
  144. /BlockCount BlockEncoding length def
  145. save
  146. F /Encoding known {
  147. F length dict F
  148. { 1 index /FID eq { pop pop } { 2 index 3 1 roll put } ifelse }
  149. forall dup /Encoding TempEncoding put
  150. /* exch definefont
  151. /F exch def
  152. /F24 F 24 scalefont def
  153. /BlockStart 0 def
  154. } if
  155. DoTitle (, unencoded characters) show
  156. BlockStart dup BlockCount 1 sub add DoBlock
  157. F 10 scalefont setfont
  158. 36 2.4 Inch moveto
  159. 0 32 BlockCount 32 sub 224 min {
  160. 0 -0.4 Inch rmoveto gsave
  161. dup 31 add BlockCount 1 sub min
  162. exch BlockStart add exch BlockStart add DoLine
  163. grestore
  164. } for
  165. showpage
  166. restore
  167. } for
  168. } def
  169. % print font sample pages
  170. /DoFont {
  171. dup findfont InitDoFont
  172. /DoCode {DoChar} def
  173. /DoLine {DoCharLine} def
  174. % Display the first 128 encoded characters.
  175. DoTitle (, characters 0-127) show
  176. 0 127 DoBlock
  177. F 10 scalefont setfont
  178. 36 2.0 Inch moveto 0 63 DoLine
  179. 36 1.5 Inch moveto 64 127 DoLine
  180. showpage
  181. % Display the second 128 encoded characters.
  182. DoTitle (, characters 128-255) show
  183. 128 255 DoBlock
  184. F 10 scalefont setfont
  185. 36 2.0 Inch moveto 128 191 DoLine
  186. 36 1.5 Inch moveto 192 255 DoLine
  187. showpage
  188. F /CharStrings known
  189. {
  190. % Find and display the unencoded characters.
  191. /Encoded F /Encoding get length dict def
  192. F /Encoding get { true Encoded 3 1 roll put } forall
  193. [ F /CharStrings get
  194. { pop dup Encoded exch known { pop } if }
  195. forall ] {
  196. exch Namestring1 cvs exch Namestring2 cvs lt
  197. } sort DoUnencoded
  198. }
  199. if
  200. } def
  201. % print CIDFont sample pages
  202. /DoCIDFont {
  203. dup /CIDFont findresource InitDoFont
  204. /DoCode {DoCID} def
  205. /DoLine {DoCIDLine} def
  206. [ 0 1 F /CIDCount get 1 sub { } for ] DoUnencoded
  207. } def
  208. % Do font samples
  209. % /Times-Roman DoFont % Test (less than a minute)
  210. % /Hershey-Gothic-English DoFont % Test (8 minutes)
  211. % Do a complete catalog
  212. % FontDirectory {pop DoFont} forall % All fonts (quite a long time)