baseline.ps 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. %
  2. % Stuff used to draw or set text along a baseline specified by parametric equations
  3. % for x and y.
  4. %
  5. /left -1 def
  6. /center 0 def
  7. /right 1 def
  8. /baselinedict 50 dict def
  9. /newbaseline {
  10. baselinedict begin
  11. /g' exch bind def
  12. /f' exch bind def
  13. /g exch bind def
  14. /f exch bind def
  15. counttomark 2 eq {/hoffset exch def} if
  16. /res exch def
  17. /t 0 def
  18. /s 0 def
  19. /voffset false def
  20. cleartomark
  21. end
  22. } bind def
  23. /drawfunnytext {
  24. baselinedict begin
  25. /t exch def
  26. /mode exch def
  27. /str exch def
  28. mode left eq {
  29. /leftstring emptystring def
  30. /rightstring str def
  31. } if
  32. mode right eq {
  33. /leftstring str reversestring def
  34. /rightstring emptystring def
  35. } if
  36. mode center eq {
  37. str splitstring
  38. /rightstring exch def
  39. /leftstring exch reversestring def
  40. } if
  41. gsave currentpoint translate leftstring left t baselineshow grestore
  42. gsave currentpoint translate rightstring right t baselineshow grestore
  43. /t 0 def
  44. /s 0 def
  45. /voffset false def
  46. cleartomark
  47. end
  48. } bind def
  49. /setfunnytext {
  50. baselinedict begin
  51. /vpos exch def
  52. /hpos exch def
  53. /str exch def
  54. voffset vpos ne {
  55. /voffset vpos def
  56. /t 0 def
  57. /s hoffset def
  58. } if
  59. gsave
  60. hoffset voffset translate
  61. 0 0 moveto
  62. /ds hpos s sub def
  63. /dt ds t f' dup mul t g' dup mul add sqrt res mul div def
  64. /s s ds add def
  65. /t t dt add def
  66. str right t baselineshow
  67. grestore
  68. end
  69. } bind def
  70. baselinedict begin
  71. /f {} bind def
  72. /g {pop 0} bind def
  73. /f' {pop 1} bind def
  74. /g' {pop 0} bind def
  75. /s 0 def
  76. /t 0 def
  77. /res 72 def
  78. /onecharstring ( ) def
  79. /emptystring () def
  80. /baselineshow {
  81. /t exch def
  82. /mode exch def
  83. /str exch def
  84. gsave
  85. t f res mul t g res mul translate
  86. 0 0 moveto
  87. t g' t f' atan rotate
  88. {
  89. mode right eq {pop} if
  90. grestore gsave
  91. onecharstring 0 3 -1 roll put onecharstring stringwidth pop
  92. /ds exch mode mul def
  93. /dt ds t f' dup mul t g' dup mul add sqrt res mul div def
  94. /t t dt add def
  95. /s s ds add def
  96. t f res mul t g res mul translate
  97. 0 0 moveto
  98. t g' t f' atan rotate
  99. mode left eq {pop} if
  100. } str kshow
  101. grestore
  102. } bind def
  103. /reversestring {
  104. /str1 exch def
  105. /str2 str1 length string def
  106. /i 0 def
  107. /n str1 length 1 sub def
  108. {
  109. str1 n get str2 exch i exch put
  110. /i i 1 add def
  111. /n n 1 sub def
  112. n 0 lt {exit} if
  113. } loop
  114. str2
  115. } bind def
  116. /splitstring {
  117. /str1 exch def
  118. /len str1 stringwidth pop def
  119. /s 0 def
  120. /n 0 def
  121. str1 length {
  122. str1 n get onecharstring exch 0 exch put
  123. /s onecharstring stringwidth pop s add def
  124. s len 2 div ge {exit} if
  125. /n n 1 add def
  126. } repeat
  127. str1 0 n 1 add getinterval
  128. str1 n str1 length n sub getinterval
  129. } bind def
  130. end