home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume22 / psutils / part01 / showchar < prev   
Encoding:
Text File  |  1991-09-04  |  2.4 KB  |  116 lines

  1. #!/bin/sh
  2. # showchar: show character with information
  3. # usage:
  4. #       showchar Font-Name Char-Name | lpr -Pprinter
  5.  
  6. if [ $# != 2 ]; then
  7.         echo "Usage: `basename $0` Font-Name Char-Name" >&2
  8.         exit 1
  9. fi
  10.  
  11. cat <<EOF
  12. %!
  13. % Get character metrics and bounding box for $1
  14. /ns 30 string def
  15. /fname /$1 def
  16. /cname /$2 def
  17. /fn fname findfont 1000 scalefont def
  18. /thin 0.7 def
  19. /reduction 2.0 def
  20.  
  21. /sn { ns cvs show } def
  22. /sc { (\()show exch sn (,)show sn (\))show } def
  23.  
  24. /Times-Roman findfont 10 scalefont setfont
  25.  
  26. 72 288 translate % one inch in
  27. newpath 0 0 moveto
  28. gsave   % print character name
  29.    0 432 rmoveto
  30.    ($2 from font $1 displayed on `date` by `basename $0` 1.00 (C) AJCD 1991)
  31.    show 
  32. grestore
  33.  
  34. gsave
  35.    thin setlinewidth  % cross hairs
  36.    -9 0 rmoveto 18 0 rlineto
  37.    -9 -9 rmoveto 0 18 rlineto
  38.    stroke  % position info
  39.    -9 -9 moveto ((0,0)) stringwidth pop neg 0 rmoveto
  40.    ((0,0)) show
  41. grestore
  42.  
  43. % create encoding with a single character at all positions
  44. /MyEncoding 256 array def
  45.  
  46. 0 1 255 { % fill out with notdefs
  47.    MyEncoding exch cname put
  48. } for
  49.  
  50. fn dup length dict begin
  51.   {1 index /FID ne {def} {pop pop} ifelse} forall
  52.   /Encoding MyEncoding def
  53.   currentdict
  54. end /newfont exch definefont
  55. /fn exch def
  56. /en MyEncoding def
  57.  
  58. gsave  % draw character (enlarged)
  59.   .75 setgray
  60.   fn 1 reduction div scalefont setfont
  61.   (\000) show
  62. grestore
  63.  
  64. % show character info
  65. fn /Metrics known {
  66.    dup fn /Metrics get exch get 
  67.    dup type /arraytype eq {
  68.       dup length 2 eq
  69.       {1 get} {2 get} ifelse
  70.    } if
  71. } {
  72.    gsave
  73.       fn setfont (\000) stringwidth pop round
  74.    grestore
  75. } ifelse
  76. gsave   % show width
  77.    thin setlinewidth
  78.    dup reduction div 0 rlineto
  79.    gsave
  80.       1 1 rmoveto 0 sc
  81.    grestore
  82.    -4 -3 rlineto 0 6 rmoveto 4 -3 rlineto
  83.    stroke
  84. grestore
  85.  
  86. gsave
  87.    gsave  % get bounding box
  88.       fn setfont
  89.       (\000) true charpath flattenpath pathbbox
  90.    grestore
  91.    thin setlinewidth
  92.    3 index reduction div  % put coords on top of stack
  93.    3 index reduction div
  94.    3 index reduction div
  95.    3 index reduction div
  96.    3 index 3 index moveto
  97.    gsave  % llx lly
  98.       0 -9 rmoveto 7 index 7 index sc
  99.    grestore
  100.    1 index 3 index lineto
  101.    gsave  % urx lly
  102.       0 -9 rmoveto 5 index 7 index sc
  103.    grestore
  104.    1 index 1 index lineto
  105.    gsave  % urx ury
  106.       0 9 rmoveto 5 index 5 index sc
  107.    grestore
  108.    3 index 1 index lineto
  109.    gsave  % llx ury
  110.       0 9 rmoveto 7 index 5 index sc
  111.    grestore
  112.    closepath stroke
  113. grestore
  114. showpage
  115. EOF
  116.