You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

261 lines
7.0 KiB

1 month ago
  1. %!
  2. %%Creator: Eric Gisin <egisin@waterloo.csnet>
  3. %%Title: Print font catalog
  4. % Copyright (C) 2001-2023 Artifex Software, Inc.
  5. % All Rights Reserved.
  6. %
  7. % This software is provided AS-IS with no warranty, either express or
  8. % implied.
  9. %
  10. % This software is distributed under license and may not be copied,
  11. % modified or distributed except as expressly authorized under the terms
  12. % of the license contained in the file LICENSE in this distribution.
  13. %
  14. % Refer to licensing information at http://www.artifex.com or contact
  15. % Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  16. % CA 94129, USA, for further information.
  17. %
  18. % Copyright (c) 1986 Eric Gisin
  19. % Copyright (C) 1992 Aladdin Enterprises, Menlo Park, CA
  20. % Modified to print all 256 encoded characters.
  21. % Copyright (C) 1993 Aladdin Enterprises, Menlo Park, CA
  22. % Modified to print unencoded characters.
  23. % Copyright (C) 1994 Aladdin Enterprises, Menlo Park, CA
  24. % Modified to always create 256-element Encoding vectors.
  25. % Copyright (C) 1995 Aladdin Enterprises, Menlo Park, CA
  26. % Modified to print more than 128 unencoded characters.
  27. % Copyright (C) 1996 Aladdin Enterprises, Menlo Park, CA
  28. % Modified to leave a slightly wider left margin, because many H-P
  29. % printers can't print in the leftmost 1/4" of the page.
  30. % Modified to print unencoded characters in any font that has CharStrings.
  31. % Copyright (C) 1999 Aladdin Enterprises, Menlo Park, CA
  32. % Modified to sort unencoded characters.
  33. % Copyright (C) 2000 Aladdin Enterprises, Menlo Park, CA
  34. % Modified to print CIDFonts as well as fonts.
  35. % O(N^2) sorting replaced with O(N log N).
  36. % Copyright transferred 2000/09/15 to Artifex Software, Inc. Send any questions to
  37. % bug-gs@ghostscript.com.
  38. % Example usages at bottom of file
  39. /#copies 1 def
  40. /min { 2 copy gt { exch } if pop } bind def
  41. /T6 /Times-Roman findfont 6 scalefont def
  42. /Temp 64 string def
  43. /Inch {72 mul} def
  44. /Base 16 def % char code output base
  45. /TempEncoding [ 256 { /.notdef } repeat ] def
  46. % Sort an array. Code used by permission of the author, Aladdin Enterprises.
  47. /sort { % <array> <lt-proc> sort <array>
  48. % Heapsort (algorithm 5.2.3H, Knuth vol. 2, p. 146),
  49. % modified for 0-origin indexing. */
  50. 10 dict begin
  51. /LT exch def
  52. /recs exch def
  53. /N recs length def
  54. N 1 gt {
  55. /l N 2 idiv def
  56. /r N 1 sub def {
  57. l 0 gt {
  58. /l l 1 sub def
  59. /R recs l get def
  60. } {
  61. /R recs r get def
  62. recs r recs 0 get put
  63. /r r 1 sub def
  64. r 0 eq { recs 0 R put exit } if
  65. } ifelse
  66. /j l def {
  67. /i j def
  68. /j j dup add 1 add def
  69. j r lt {
  70. recs j get recs j 1 add get LT { /j j 1 add def } if
  71. } if
  72. j r gt { recs i R put exit } if
  73. R recs j get LT not { recs i R put exit } if
  74. recs i recs j get put
  75. } loop
  76. } loop
  77. } if recs end
  78. } def
  79. % do single character of page
  80. % output to rectangle ll=(0,-24) ur=(36,24)
  81. /DoGlyph { % C, N, W set
  82. % print code name, width and char name
  83. T6 setfont
  84. N /.notdef ne {0 -20 moveto N Temp cvs show} if
  85. 0 -12 moveto C Base Temp cvrs show ( ) show
  86. W 0.0005 add Temp cvs 0 5 getinterval show
  87. % print char with reference lines
  88. N /.notdef ne {
  89. 3 0 translate
  90. 0 0 moveto F24 setfont N glyphshow
  91. /W W 24 mul def
  92. 0 -6 moveto 0 24 lineto
  93. W -6 moveto W 24 lineto
  94. -3 0 moveto W 3 add 0 lineto
  95. 0 setlinewidth stroke
  96. } if
  97. } def
  98. /DoChar {
  99. /C exch def
  100. /N F /Encoding get C get def
  101. /S (_) dup 0 C put def
  102. /W F setfont S stringwidth pop def
  103. DoGlyph
  104. } def
  105. /CIDTemp 20 string def
  106. /DoCID {
  107. /N exch def
  108. /C N def
  109. /W F setfont gsave
  110. matrix currentmatrix nulldevice setmatrix
  111. 0 0 moveto N glyphshow currentpoint pop
  112. grestore def
  113. DoGlyph
  114. } def
  115. % print page title
  116. /DoTitle {
  117. /Times-Roman findfont 18 scalefont setfont
  118. 36 10.5 Inch moveto FName Temp cvs show ( ) show ((24 point)) show
  119. } def
  120. % print one block of characters
  121. /DoBlock { % firstcode lastcode
  122. /FirstCode 2 index def
  123. 1 exch {
  124. /I exch def
  125. /Xn I FirstCode sub 16 mod def /Yn I FirstCode sub 16 idiv def
  126. gsave
  127. Xn 35 mul 24 add Yn -56 mul 9.5 Inch add translate
  128. I DoCode
  129. grestore
  130. } for
  131. } def
  132. % print a line of character
  133. /DoCharLine { % firstcode lastcode
  134. 1 exch { (_) dup 0 3 index put show pop } for
  135. } def
  136. /DoCIDLine { % firstcode lastcode
  137. 1 exch { glyphshow } for
  138. } def
  139. % initialize variables
  140. /InitDoFont { % fontname font
  141. /F exch def % font
  142. /FName exch def % font name
  143. /F24 F 24 scalefont def
  144. /Line0 96 string def
  145. /Line1 96 string def
  146. /Namestring1 128 string def
  147. /Namestring2 128 string def
  148. } def
  149. % print pages of unencoded characters
  150. /DoUnencoded { % glyphs
  151. /Unencoded exch def
  152. /Count Unencoded length def
  153. % Print the unencoded characters in blocks of 128.
  154. 0 128 Unencoded length 1 sub
  155. { /BlockStart 1 index def
  156. dup 128 add Unencoded length min 1 index sub
  157. Unencoded 3 1 roll getinterval TempEncoding copy
  158. /BlockEncoding exch def
  159. /BlockCount BlockEncoding length def
  160. save
  161. F /Encoding known {
  162. F length dict F
  163. { 1 index /FID eq { pop pop } { 2 index 3 1 roll put } ifelse }
  164. forall dup /Encoding TempEncoding put
  165. /* exch definefont
  166. /F exch def
  167. /F24 F 24 scalefont def
  168. /BlockStart 0 def
  169. } if
  170. DoTitle (, unencoded characters) show
  171. BlockStart dup BlockCount 1 sub add DoBlock
  172. F 10 scalefont setfont
  173. 36 2.4 Inch moveto
  174. 0 32 BlockCount 1 sub {
  175. 0 -0.4 Inch rmoveto gsave
  176. dup 31 add BlockCount 1 sub min
  177. exch BlockStart add exch BlockStart add DoLine
  178. grestore
  179. } for
  180. showpage
  181. restore
  182. } for
  183. } def
  184. % print font sample pages
  185. /DoFont {
  186. dup findfont InitDoFont
  187. /DoCode {DoChar} def
  188. /DoLine {DoCharLine} def
  189. % Display the first 128 encoded characters.
  190. DoTitle (, characters 0-127) show
  191. 0 127 DoBlock
  192. F 10 scalefont setfont
  193. 36 2.0 Inch moveto 0 31 DoLine
  194. 36 1.6 Inch moveto 32 63 DoLine
  195. 36 1.2 Inch moveto 64 95 DoLine
  196. 36 0.8 Inch moveto 96 127 DoLine
  197. showpage
  198. % Display the second 128 encoded characters.
  199. DoTitle (, characters 128-255) show
  200. 128 255 DoBlock
  201. F 10 scalefont setfont
  202. 36 2.0 Inch moveto 128 159 DoLine
  203. 36 1.6 Inch moveto 160 191 DoLine
  204. 36 1.2 Inch moveto 192 223 DoLine
  205. 36 0.8 Inch moveto 224 255 DoLine
  206. showpage
  207. F /CharStrings known
  208. {
  209. % Find and display the unencoded characters.
  210. /Encoded F /Encoding get length dict def
  211. F /Encoding get { true Encoded 3 1 roll put } forall
  212. [ F /CharStrings get
  213. { pop dup Encoded exch known { pop } if }
  214. forall ] {
  215. exch Namestring1 cvs exch Namestring2 cvs lt
  216. } sort DoUnencoded
  217. }
  218. if
  219. } def
  220. % print CIDFont sample pages
  221. /DoCIDFont {
  222. dup /CIDFont findresource InitDoFont
  223. /DoCode {DoCID} def
  224. /DoLine {DoCIDLine} def
  225. [ 0 1 F /CIDCount get 1 sub { } for ] DoUnencoded
  226. } def
  227. % Do font samples
  228. % /Times-Roman DoFont % Test (less than a minute)
  229. % /Hershey-Gothic-English DoFont % Test (8 minutes)
  230. % Do a complete catalog
  231. % FontDirectory {pop DoFont} forall % All fonts (quite a long time)