home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / psroff / part03 / showfont.sh < prev    next >
Encoding:
Text File  |  1989-10-17  |  3.1 KB  |  177 lines

  1. :
  2. #@(#)showfont 1.3 89/08/25
  3. # Shell script to dump postscript fonts with widths into a pretty table
  4.  
  5. (
  6. cat << !END!
  7. %! PS-Adobe 1.0
  8. %%Title: showfont -- displays the font metrics in a pretty one page table
  9. %%Creator: Ken Marchant
  10. %%CreationDate: March 1989
  11. %%Pages: atend
  12. %%
  13. !END!
  14.  
  15. if [ -r $1 ]
  16. then
  17.     cat $1
  18.     shift
  19. fi
  20. cat << !END!
  21.  
  22. /FONTname ($1) def
  23.  
  24. %%  Setup functions used and etc...
  25.  
  26. /rowmove {
  27.   /I exch def 
  28.   I 16 mod 30 mul 72 add
  29.   680 I 16 idiv 30 mul sub
  30.   moveto 
  31. } def
  32.  
  33. /widths 259 array def
  34. /heights 259 array def
  35. /lbear 259 array def
  36. /rbear 259 array def
  37. /tmp 1 string def
  38. .5 setlinewidth
  39.  
  40. /Helvetica findfont 9 scalefont setfont
  41.  
  42. %% Draw the grid around the cells 
  43. %% and add the hex labels to the outside of the box
  44.  
  45. 0 1 16
  46. {
  47.     /i exch def
  48.     /j i 30 mul def
  49.     %% vertical lines
  50.     j 62 add dup 220 moveto
  51.     700 lineto
  52.     stroke
  53.  
  54.     %% horizontal lines
  55.     j 220 add dup 62 exch moveto
  56.     542 exch lineto
  57.     stroke
  58.  
  59.     i 16 ge { clear exit } if
  60.  
  61.     %% hex across the top
  62.     j 77 add dup 705 moveto
  63.     i 16 (   ) cvrs show
  64.  
  65.     %% hex along the sides
  66.     50 670 j sub 12 add moveto 
  67.     i 16 (   ) cvrs show
  68. }
  69. for
  70.  
  71. /myscale {
  72.     2 mul 
  73.     % 10 mul round cvi 10 div
  74.     round cvi
  75. } def
  76.  
  77. /irmove {
  78.     CY add exch
  79.     CX add exch moveto
  80. } def
  81.  
  82. %% Print out the headings in the font to be displayed and Times-Roman
  83.  
  84. /Times-Roman findfont 18 scalefont setfont
  85. 295 FONTname stringwidth pop .5 mul sub 750 moveto FONTname show
  86.  
  87. FONTname findfont 18 scalefont setfont
  88. 295 FONTname stringwidth pop .5 mul sub 730 moveto FONTname show
  89.  
  90.  
  91. %% loop thru all the charcters and display in 18 point
  92. %% insert the character widths into the widths array
  93.         0 1 258 
  94.         { 
  95.          newpath
  96.          /i exch def
  97.          i rowmove
  98.          i 255 gt {
  99.          i 256 eq { /tmp (ff) def } if
  100.          i 257 eq { /tmp (ffi) def } if
  101.          i 258 eq { /tmp (ffl) def } if
  102.          } {
  103.          /tmp 1 string def
  104.          tmp 0 i put
  105.          } ifelse
  106.          tmp show 
  107.          widths i tmp stringwidth pop dup /width exch def 
  108.          myscale put 
  109.  
  110.          %    Set current point again.
  111.          i rowmove
  112.          /curx currentpoint pop def
  113.  
  114.          % retrieve bounding box info.
  115.          tmp false charpath flattenpath pathbbox
  116.          /ury exch def
  117.          /urx exch def
  118.          /lly exch def
  119.          /llx exch def
  120.  
  121.          % calc left bearing as leftx - curx
  122.  
  123.          lbear i llx curx sub myscale put
  124.  
  125.          % calc height as upper y - lower y
  126.  
  127.          heights i ury lly sub myscale put
  128.  
  129.          % calc right bearing as width - upper x
  130.  
  131.          rbear i width urx curx sub sub myscale put
  132.  
  133.         } 
  134.         for 
  135.  
  136. %% display the widths in the widths array
  137.  
  138.     /Helvetica-Narrow findfont 5 scalefont setfont
  139.  
  140.         0 1 258 
  141.         { 
  142.          /i exch def
  143.  
  144.          i rowmove
  145.  
  146.          currentpoint /CY exch def /CX exch def
  147.  
  148.          2 -8 irmove
  149.          widths i get (       ) cvs show 
  150.  
  151.          -9 4 irmove
  152.          heights i get (       ) cvs show 
  153.  
  154.          -9 -8 irmove 
  155.          lbear i get (       ) cvs show 
  156.  
  157.          12 -8 irmove
  158.          rbear i get (       ) cvs show
  159.  
  160.          -9 15 irmove
  161.          i 8 (   ) cvrs show
  162.  
  163.          1 15 irmove
  164.          i 10 (   ) cvrs show
  165.  
  166.          12 15 irmove
  167.          i 16 (   ) cvrs show
  168.         }
  169.         for
  170.  
  171.     showpage
  172.  
  173. %%Pages: 1
  174. !END!
  175. echo '\004'
  176. ) | rlp -dgate!AppleLaser
  177.