home *** CD-ROM | disk | FTP | other *** search
/ swCHIP 1991 January / swCHIP_95-1.bin / utility / gs333ini / gs3.33 / printafm.ps < prev    next >
Text File  |  1995-12-09  |  3KB  |  138 lines

  1. %!
  2. % written by James Clark <jjc@jclark.uucp>
  3. % print an afm file on the standard output
  4. % usage is `fontname printafm' eg `/Times-Roman printafm'
  5.  
  6. % From the `dvitops' distribution, which included this notice:
  7. % dvitops is not copyrighted; you can do with it exactly as you please.
  8. % I would, however, ask that if you make improvements or modifications,
  9. % you ask me before distributing them to others.
  10.  
  11. % Altered by d.love@dl.ac.uk to produce input for Rokicki's afm2tfm,
  12. % which groks the format of the Adobe AFMs.
  13.  
  14. % Modified by L. Peter Deutsch 9/14/93:
  15. %   uses Ghostscript's =only procedure to replace 'buf cvs print'.
  16.  
  17. /onechar 1 string def
  18.  
  19. % c toupper - c
  20. /toupper {
  21.     dup dup 8#141 ge exch 8#172 le and { 
  22.         8#40 sub
  23.     } if
  24. } bind def
  25.  
  26. % printcharmetrics -
  27.  
  28. /printcharmetrics {
  29.     (StartCharMetrics ) print
  30.     currentfont /CharStrings get dup length exch /.notdef known { 1 sub } if =
  31.     currentfont 1000 scalefont setfont 0 0 moveto
  32.     /e currentfont /Encoding get def
  33.     0 1 255 {
  34.         dup e exch get
  35.         dup /.notdef ne {
  36.             exch dup printmetric
  37.         } {
  38.             pop pop
  39.         } ifelse
  40.     } for
  41.     % s contains an entry for each name in the original encoding vector
  42.     /s 256 dict def
  43.     e {
  44.         s exch true put
  45.     } forall
  46.     % v is the new encoding vector
  47.     /v 256 array def
  48.     0 1 255 {
  49.         v exch /.notdef put
  50.     } for
  51.     % fill up v with names in CharStrings
  52.     /i 0 def
  53.     currentfont /CharStrings get {
  54.         pop
  55.         i 255 le {
  56.             v i 3 -1 roll put
  57.             /i i 1 add def
  58.         } {
  59.             pop
  60.         } ifelse
  61.     } forall
  62.     % define a new font with v as its encoding vector
  63.     currentfont maxlength dict /f exch def
  64.     currentfont {
  65.         exch dup dup /FID ne exch /Encoding ne and { 
  66.             exch f 3 1 roll put
  67.         } { 
  68.             pop pop 
  69.         } ifelse
  70.     } forall
  71.     f /Encoding v put
  72.     f /FontName /temp put
  73.     % make this new font the current font
  74.     /temp f definefont setfont
  75.     % print a entry for each character not in old vector
  76.     /e currentfont /Encoding get def
  77.     0 1 255 {
  78.         dup e exch get
  79.         dup dup /.notdef ne exch s exch known not and { 
  80.             exch -1 printmetric
  81.         } { 
  82.             pop pop
  83.         } ifelse
  84.     } for
  85.     (EndCharMetrics) =
  86. } bind def
  87.  
  88. % name actual_code normal_code printmetric -
  89.  
  90. /printmetric {
  91.     /saved save def
  92.     (C ) print =only
  93.     ( ; WX ) print
  94.     onechar 0 3 -1 roll put
  95.     onechar stringwidth pop round cvi =only
  96.     ( ; N ) print =only
  97.     ( ; B ) print
  98.     onechar false charpath flattenpath mark pathbbox counttomark {
  99.         counttomark -1 roll
  100.         round cvi =only
  101.         ( ) print
  102.     } repeat pop
  103.     (;) =
  104.     saved restore
  105. } bind def
  106.  
  107. % fontname printafm -
  108.  
  109. /printafm {
  110.     findfont gsave setfont
  111.     (StartFontMetrics 2.0) =
  112.     (FontName ) print currentfont /FontName get =
  113.  
  114.         % Print the FontInfo
  115.  
  116.     currentfont /FontInfo get {
  117.         exch
  118.         =string cvs dup dup 0 get 0 exch toupper put print
  119.         ( ) print =
  120.     } forall
  121.  
  122.         % Print the FontBBox
  123.  
  124.     (FontBBox) print
  125.     currentfont /FontBBox get {
  126.         ( ) print round cvi =only
  127.     } forall
  128.     (\n) print
  129.  
  130.     printcharmetrics
  131.     (EndFontMetrics) =
  132.     grestore
  133. } bind def
  134.  
  135.  
  136.  
  137. /Times-Roman printafm
  138.