home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / PSUTILS / SHOWCHAR < prev    next >
Text File  |  1993-10-27  |  3KB  |  119 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 242 translate % one inch in, 3 1/2 inch up
  27. newpath 0 0 moveto
  28. gsave   % print character name
  29.    0 468 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 0} {dup 2 get exch 3 get} ifelse
  70.    } {
  71.       round 0
  72.    } ifelse
  73. } {
  74.    gsave
  75.       fn setfont (\000) stringwidth round exch round exch
  76.    grestore
  77. } ifelse
  78. gsave   % show width
  79.    thin setlinewidth
  80.    2 copy
  81.    reduction div exch reduction div exch rlineto
  82.    gsave
  83.       1 1 rmoveto sc
  84.    grestore
  85.    -4 -3 rlineto 0 6 rmoveto 4 -3 rlineto
  86.    stroke
  87. grestore
  88.  
  89. gsave
  90.    gsave  % get bounding box
  91.       fn setfont
  92.       (\000) true charpath flattenpath pathbbox
  93.    grestore
  94.    thin setlinewidth
  95.    3 index reduction div  % put coords on top of stack
  96.    3 index reduction div
  97.    3 index reduction div
  98.    3 index reduction div
  99.    3 index 3 index moveto
  100.    gsave  % llx lly
  101.       0 -9 rmoveto 7 index 7 index sc
  102.    grestore
  103.    1 index 3 index lineto
  104.    gsave  % urx lly
  105.       0 -9 rmoveto 5 index 7 index sc
  106.    grestore
  107.    1 index 1 index lineto
  108.    gsave  % urx ury
  109.       0 9 rmoveto 5 index 5 index sc
  110.    grestore
  111.    3 index 1 index lineto
  112.    gsave  % llx ury
  113.       0 9 rmoveto 7 index 5 index sc
  114.    grestore
  115.    closepath stroke
  116. grestore
  117. showpage
  118. EOF
  119.