trofftable.ps 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. %
  2. % Prologue for building troff width tables. The gsave/grestore pairs are
  3. % for hardcopy.
  4. %
  5. /slowdown 25 def
  6. /flagduplicates false def
  7. /ascenderheight -1 def
  8. /descenderdepth 0 def
  9. /octalescapes 256 def
  10. /startcomments 256 def
  11. /currentfontdict null def
  12. /scratchstring 512 string def
  13. /Print {
  14. scratchstring cvs print flush
  15. slowdown {1 pop} repeat
  16. } def
  17. /ReEncode { % vector fontname ReEncode -
  18. dup
  19. findfont dup length dict begin
  20. {1 index /FID ne {def}{pop pop} ifelse} forall
  21. /Encoding 3 -1 roll def
  22. currentdict
  23. end
  24. definefont pop
  25. } bind def
  26. /SelectFont { % fontname SelectFont -
  27. findfont
  28. dup /PaintType get 0 eq {
  29. /scaling 1 def
  30. unitwidth resolution 72.0 div mul
  31. }{
  32. /scaling resolution 72 div def
  33. unitwidth
  34. } ifelse
  35. scalefont
  36. /currentfontdict exch def
  37. } def
  38. /ChangeMetrics {DpostPrologue begin addmetrics end} def
  39. /NamedInPrologue {
  40. dup
  41. DpostPrologue exch known {
  42. DpostPrologue exch get type /nametype eq {
  43. (named in prologue\n) Print
  44. } if
  45. }{pop} ifelse
  46. } def
  47. /SetAscender {
  48. /str exch def
  49. gsave
  50. currentfontdict setfont
  51. newpath
  52. 0 0 moveto
  53. str false charpath flattenpath pathbbox
  54. /descenderdepth 4 -1 roll .5 mul def
  55. exch pop exch pop
  56. newpath
  57. 0 0 moveto
  58. str 0 1 getinterval false charpath flattenpath pathbbox
  59. 4 1 roll pop pop pop
  60. dup 3 1 roll sub .25 mul add
  61. /ascenderheight exch def
  62. grestore
  63. } def
  64. /GetAscender {
  65. ascenderheight descenderdepth ge {
  66. gsave
  67. currentfontdict setfont
  68. newpath
  69. 0 0 moveto
  70. ( ) dup 0 4 -1 roll put
  71. false charpath flattenpath pathbbox
  72. exch pop 3 -1 roll pop
  73. ascenderheight gt {2}{0} ifelse
  74. exch descenderdepth lt {1}{0} ifelse
  75. or
  76. grestore
  77. }{0} ifelse
  78. } def
  79. /GetWidth {
  80. gsave
  81. currentfontdict setfont
  82. ( ) dup 0 4 -1 roll put
  83. stringwidth pop scaling mul round cvi
  84. grestore
  85. } def
  86. /GetCode {
  87. 256 3 1 roll % last unprintable match
  88. 0 3 -1 roll {
  89. 2 index eq {
  90. dup 127 and 32 ge {exit} if
  91. 3 -1 roll pop
  92. dup 3 1 roll
  93. } if
  94. 1 add
  95. } forall
  96. exch pop
  97. dup 255 gt {pop}{exch pop} ifelse
  98. } def
  99. /BuildFontCharset {
  100. 0 2 charset length 2 sub {
  101. /i exch def
  102. /chcode -1 def
  103. /chname null def
  104. /key charset i get def
  105. /val charset i 1 add get def
  106. val type /integertype eq {
  107. /chcode val def
  108. /chname currentfontdict /Encoding get chcode get def
  109. } if
  110. val type /nametype eq {
  111. /chname val def
  112. /chcode currentfontdict /Encoding get chname GetCode def
  113. } if
  114. val type /stringtype eq {/chcode 0 def} if
  115. chcode 0 lt chcode 255 gt or {
  116. chcode 0 lt {(syntaxerror: )}{(undefinedname: )} ifelse
  117. Print key Print (\t) Print val Print (\n) Print
  118. quit
  119. } if
  120. val type /stringtype eq {
  121. key Print
  122. (\t) Print val Print
  123. (\n) Print
  124. }{
  125. chcode octalescapes ge key (---) eq and {
  126. (\\0) Print chcode 8 ( ) cvrs Print
  127. }{key Print} ifelse
  128. (\t) Print chcode GetWidth Print
  129. (\t) Print chcode GetAscender Print
  130. (\t) Print chcode Print
  131. chcode startcomments ge {
  132. (\t# ) Print chname Print
  133. } if
  134. (\n) Print
  135. chcode octalescapes ge (---) key ne and {
  136. key (\\0) anchorsearch not {
  137. pop
  138. (\\0) Print chcode 8 ( ) cvrs Print
  139. (\t"\n) Print
  140. }{pop pop} ifelse
  141. } if
  142. } ifelse
  143. } for
  144. } def
  145. /BuildDescCharset {
  146. /DescDict 512 dict def
  147. /Characters 0 def
  148. 0 1 charset length 1 sub {
  149. /i exch def
  150. /key charset i get def
  151. key length 2 eq {
  152. DescDict key cvn known {
  153. flagduplicates { % for debugging
  154. (<<<duplicated character: ) Print
  155. key Print
  156. (>>>\n) Print
  157. } if
  158. }{
  159. DescDict key cvn 1 put
  160. key Print
  161. /Characters Characters 1 add def
  162. Characters 20 mod 0 eq {(\n)}{( )} ifelse Print
  163. } ifelse
  164. } if
  165. } for
  166. } def