You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
5.8 KiB

1 month ago
  1. %!
  2. % Copyright (C) 2001-2023 Artifex Software, Inc.
  3. % All Rights Reserved.
  4. %
  5. % This software is provided AS-IS with no warranty, either express or
  6. % implied.
  7. %
  8. % This software is distributed under license and may not be copied,
  9. % modified or distributed except as expressly authorized under the terms
  10. % of the license contained in the file LICENSE in this distribution.
  11. %
  12. % Refer to licensing information at http://www.artifex.com or contact
  13. % Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  14. % CA 94129, USA, for further information.
  15. %
  16. % uninfo.ps: Utilities for "printing" PostScript items, especially dictionaries
  17. % Usage:
  18. % (prefix-string) dict unprint
  19. % Maximum Print-Width
  20. /HSpwidth 80 def
  21. % any HScvs string
  22. /HScvs {
  23. % Number-Syntax
  24. dup type % stack: any /anytype
  25. dup /integertype eq 1 index /realtype eq or { pop
  26. 16 string cvs
  27. }{
  28. % Logical-Type
  29. dup /booleantype eq { pop
  30. 5 string cvs
  31. }{
  32. % Identifiers
  33. dup /nametype eq { pop
  34. dup length 1 add string
  35. dup 0 (/) putinterval
  36. exch 1 index 1 1 index length 1 sub getinterval cvs pop
  37. }{
  38. % Strings
  39. dup /stringtype eq { pop
  40. % ------- Compute Length
  41. 2 1 index { % stack: str len item
  42. dup 32 lt 1 index 126 gt or { % need 4
  43. pop 4 add
  44. }{
  45. dup 40 eq 1 index 41 eq or 1 index 92 eq or {
  46. pop 2 add
  47. }{
  48. pop 1 add
  49. } ifelse
  50. } ifelse
  51. } forall
  52. % ------- Allocate & Fill String
  53. string dup 0 (\() putinterval 1
  54. 3 -1 roll { % outstr pos item
  55. dup 32 lt 1 index 126 gt or {
  56. dup 7 le {
  57. 2 index 2 index (\\00) putinterval
  58. 8 3 index 3 index 3 add 1 getinterval cvrs
  59. }{
  60. dup 63 le {
  61. 2 index 2 index (\\0) putinterval
  62. 8 3 index 3 index 2 add 2 getinterval cvrs
  63. }{
  64. 2 index 2 index (\\) putinterval
  65. 8 3 index 3 index 1 add 3 getinterval cvrs
  66. } ifelse
  67. } ifelse
  68. pop 4 add
  69. }{
  70. dup 40 eq 1 index 41 eq or 1 index 92 eq or {
  71. 2 index 2 index (\\) putinterval
  72. exch 1 add exch
  73. } if
  74. 2 index exch 2 index exch put
  75. 1 add
  76. } ifelse
  77. } forall
  78. 1 index exch (\)) putinterval
  79. }{ exch pop
  80. dup length 1 add string
  81. dup 0 (-) putinterval
  82. exch 1 index 1 1 index length 1 sub getinterval cvs pop
  83. dup dup length 4 sub (-) putinterval
  84. 0 1 index length 3 sub getinterval
  85. } ifelse
  86. } ifelse
  87. } ifelse
  88. } ifelse
  89. } bind def
  90. % int HSpindent - indent-spaces
  91. /HSpindent {
  92. dup 0 gt {
  93. 1 1 3 -1 roll { pop ( ) print } for
  94. }{
  95. pop
  96. } ifelse
  97. } bind def
  98. % indent array HSaprint -> Print an Array
  99. /HSaprint {
  100. dup type /arraytype eq {
  101. ( [) print
  102. exch 1 add dup 1 add
  103. 3 -1 roll { % rind pos item
  104. HScvs dup length % rind pos str len
  105. dup 3 index add HSpwidth ge {
  106. (\n) print
  107. 3 index HSpindent
  108. 3 -1 roll pop
  109. 2 index add
  110. exch
  111. }{
  112. ( ) print
  113. 2 index add 1 add
  114. 3 -1 roll pop
  115. exch
  116. } ifelse
  117. print
  118. } forall
  119. ( ]) print
  120. pop pop
  121. }{
  122. ( ) print
  123. HScvs print pop
  124. } ifelse
  125. (\n) print
  126. } bind def
  127. % dict HSdnames dict names (creates sorted name-strings)
  128. /HSdnames {
  129. % Build namelist, stack: dic
  130. dup length 0 eq {
  131. []
  132. }{
  133. [ 1 index {
  134. pop dup type /nametype eq {
  135. dup length string cvs
  136. }{
  137. pop
  138. } ifelse
  139. } forall
  140. ]
  141. % Sort the namelist, stack: dic nam
  142. 0 1 2 index length 2 sub { % stack: dic nam I
  143. 2 copy get % stack: pre dic nam I nam[I]
  144. 1 index 1 add 1 4 index length 1 sub { % stack: dic nam I nam[I] J
  145. 3 index 1 index get % dic nam I S[I] J S[J]
  146. 2 index 1 index gt { % swap them
  147. 4 index 2 index 4 index put
  148. 4 index 4 index 2 index put
  149. 3 1 roll
  150. } if
  151. pop pop
  152. } for
  153. pop pop
  154. } for
  155. } ifelse
  156. } bind def
  157. % string:prefix dict:which unprint
  158. /unprint {
  159. HSdnames % pre dic nam
  160. % compute the maximum length
  161. 0 1 index { % pre dic nam maxlen nam[I]
  162. length 2 copy lt { exch } if pop
  163. } forall
  164. % Print out all the items, stack: pre dic nam maxlen
  165. (\n) print
  166. exch { % pre dic maxlen nam[I]
  167. % no prefix yet, -> flush right
  168. 3 index length 0 eq {
  169. dup length 2 index exch sub HSpindent
  170. }{
  171. 3 index print (/) print
  172. } ifelse
  173. % print the name
  174. dup print
  175. % prefix: fill up with blanks
  176. 3 index length 0 ne {
  177. dup length 2 index exch sub HSpindent
  178. } if
  179. % now print the item itself, stack: pre dic maxlen nam[I]
  180. 2 index 1 index cvn get dup type % stack: pre dic maxlen nam[i] item typ
  181. % Dict-Syntax
  182. dup /dicttype eq { pop % stack: pre dic maxlen nam[i] item
  183. ( ) print dup HScvs print
  184. 4 index length 0 eq { % brand new prefix
  185. 2 index string 0 1 5 index 1 sub { 1 index exch 32 put } for
  186. dup 4 index 4 index length sub 5 -1 roll putinterval
  187. }{
  188. 4 index length 1 add 2 index length add string
  189. dup 0 7 index putinterval
  190. dup 6 index length (/) putinterval
  191. dup 6 index length 1 add 5 -1 roll putinterval
  192. } ifelse
  193. exch unprint
  194. }{
  195. 3 -1 roll pop % tack: pre dic maxlen item typ
  196. % Array-Syntax
  197. dup /arraytype eq { pop % stack: pre dic maxlen item
  198. 3 index length dup 0 ne { 1 add } if 2 index add
  199. exch HSaprint
  200. }{ pop
  201. ( ) print
  202. HScvs print
  203. (\n) print
  204. } ifelse
  205. } ifelse
  206. } forall
  207. pop pop length -1 eq { (\n) print } if
  208. } bind def
  209. /currentpagedevice where { % check for currentpagedevice
  210. /currentpagedevice get exec () exch unprint
  211. } if