home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / GhostScript / !GhostScr / 6_01 / lib / prfont.ps < prev    next >
Text File  |  2000-03-29  |  6KB  |  223 lines

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