home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / postscri / 6447 < prev    next >
Encoding:
Text File  |  1993-01-25  |  7.4 KB  |  277 lines

  1. Newsgroups: comp.lang.postscript
  2. Path: sparky!uunet!destroyer!gatech!purdue!mentor.cc.purdue.edu!ab
  3. From: ab@mentor.cc.purdue.edu (Allen Braunsdorf)
  4. Subject: Re: SUMMARY: How can I tell if a PS file is in color?
  5. Message-ID: <C1F32I.3tz@mentor.cc.purdue.edu>
  6. Summary: solution in PS
  7. Organization: Purdue UNIX Group
  8. References: <C17uJr.F8B@mentor.cc.purdue.edu> <C19nEy.49G@mentor.cc.purdue.edu>
  9. Date: Mon, 25 Jan 1993 15:59:04 GMT
  10. Lines: 265
  11.  
  12.  
  13.  
  14. Here's the promised bit of code to test for color being used in a
  15. PostScript job.  The instructions are for using it with GhostScript.
  16. You could use it in any two-way situation, but the procedure's a little
  17. different.
  18.  
  19. It hasn't been tested a lot, but it's based on a piece of code I use
  20. often, so it should be OK.  Tell me if you have any trouble.  As often
  21. with my stuff, the documentation is longer than the program. :-)
  22.  
  23. ab
  24.  
  25. #    This is a shell archive.
  26. #    Remove everything above and including the cut line.
  27. #    Then run the rest of the file through sh.
  28. #----cut here-----cut here-----cut here-----cut here----#
  29. #!/bin/sh
  30. # shar:    Shell Archiver
  31. #    Run the following text with /bin/sh to create:
  32. #    README
  33. #    colorpdict.ps
  34. #    level2
  35. # This archive created: Mon Jan 25 10:47:49 1993
  36. # By:    Allen Braunsdorf (Purdue UNIX Group)
  37. echo shar: extracting README '(3686 characters)'
  38. sed 's/^XX//' << \SHAR_EOF > README
  39. XXWhat's Here
  40. XX
  41. XXEnclosed you should find this file (README) the Level 1 version
  42. XX(colorpdict.ps) and the Level 2 version (level2).  If you aren't
  43. XXsure which version to use, just use the Level 1 one.
  44. XX
  45. XXMove whichever one you want to colorpdict.ps in your PostScript
  46. XXtools directory.  (What you don't have one? :-) )
  47. XX
  48. XX
  49. XXHow to Use It
  50. XX
  51. XXTo use this from GhostScript, run gs without any arguments (so it
  52. XXgoes interactive).
  53. XX
  54. XXThen you need to load the new dictionary:
  55. XX
  56. XX    (colorpdict.ps) run
  57. XX
  58. XXThe operand to run is the pathname to the PostScript file that came
  59. XXwith this.  If it's not in the current directory, you'll need to
  60. XXsay where it is.
  61. XX
  62. XXThen you need to install the new functions:
  63. XX
  64. XX    colorpdict begin please
  65. XX
  66. XXThen run the code you want to check:
  67. XX
  68. XX    (foo.ps) run
  69. XX
  70. XXIf it ever tries to draw in color, you'll see the message "Non-gray
  71. XXcolor encountered" in the interactive window.  If you didn't, it
  72. XXdidn't.  The message will only be printed once to save time.
  73. XX
  74. XXIn fact, when the message is printed, the checking routine is
  75. XXneutered.  It's still there, it just doesn't work.  To re-enable
  76. XXit, type:
  77. XX
  78. XX    please
  79. XX
  80. XXwhich will make it work again.  That's why you had to type please
  81. XXwhen you began the dictionary.  (Not just 'cause we're so polite.)
  82. XX
  83. XXTo get rid of the checking functions:
  84. XX
  85. XX    end
  86. XX
  87. XXWhich will put you back in the state you were after you loaded the
  88. XXdictionary.  If you begin it again, be sure to say please. :-)
  89. XX
  90. XX
  91. XXHow It Works
  92. XX
  93. XXYou might be wondering how this thing works.  It's not very hard,
  94. XXbut you need to understand some basic PostScript concepts.  If you
  95. XXfind you don't really grok something, please consult a reference
  96. XXtext.
  97. XX
  98. XXFirst you'll see that we construct an array full of literal names.
  99. XXThese are the names that we want to redefine.
  100. XX
  101. XXThen we build a dictionary with enough entries for those new
  102. XXfunctions, 2 other functions, and (in the Level 1 version) as many
  103. XXentries as userdict has.  The last is so the program we run has
  104. XXroom to work if it needs it.  In Level 2 PostScript, dictionaries
  105. XXwon't fill up, so that's not necessary.
  106. XX
  107. XXWe begin this dictionary so all our definitions will be in it.
  108. XX
  109. XXNext we do a forall on the array we made above.  This makes a
  110. XXprocedure for all the names in the array.  That procedure performs
  111. XXcolorp before it does whatever that name is currently assigned to.
  112. XXIt'll work if they aren't operators as well.  To see a sample
  113. XXdefinition, type:
  114. XX
  115. XX    /stroke load ==
  116. XX
  117. XXwhen the dictionary is in effect.  Load the dictionary again if
  118. XXyou want to see what happens if it redefines things twice.
  119. XX
  120. XXThen we define please, which installs the checking function as
  121. XXcolorp.  Note that colorp destroys itself if it sees color.  This
  122. XXkeeps it from printing a zillion messages on the screen.
  123. XX
  124. XX
  125. XXBUGS
  126. XX
  127. XXThis version doesn't trap image calls.  In Level 1, images should
  128. XXbe grayscale anyway.  In general, there should be few images in a
  129. XXdocument and you can probably scope those out by hand.  Maybe I'll
  130. XXfix that later.
  131. XX
  132. XXThe prototype function insists on using the systemdict version of
  133. XXexec.  This was to get around worrying about how to bind exec if
  134. XXit wasn't an operator.  (Who redefines exec anyway? :-) )
  135. XX
  136. XXWhen please is executed, colorp is defined in the current dictionary.
  137. XXThat's probably OK.  When colorp redefines itself, it also does it in
  138. XXthe current dictionary, which might be a problem.  In general, this
  139. XXwill only cause extra messages to be printed and should not make it
  140. XXfail.
  141. XX
  142. XXOf course this won't work if the tested program has its own definition
  143. XXfor colorp or insists on using graphics routines from systemdict.
  144. XX
  145. XX
  146. XXQuestions?
  147. XX
  148. XXQuestions, problems, or (heaven forfend!) bugs can be sent to me
  149. XXat the address below.  Have fun!
  150. XX
  151. XXAllen B (ab@nova.cc.purdue.edu)
  152. SHAR_EOF
  153. if test 3686 -ne "`wc -c README`"
  154. then
  155. echo shar: error transmitting README '(should have been 3686 characters)'
  156. fi
  157. echo shar: extracting colorpdict.ps '(728 characters)'
  158. sed 's/^XX//' << \SHAR_EOF > colorpdict.ps
  159. XX%!
  160. XX%%Title: colorpdict 1.0 (for Level 1 PS)
  161. XX%%Creator: ab@nova.cc.purdue.edu
  162. XX%%EndComments
  163. XX
  164. XX% put operators with graphic output here:
  165. XX[
  166. XX    /fill
  167. XX    /eofill
  168. XX    /stroke
  169. XX    /imagemask
  170. XX    /show
  171. XX    /ashow
  172. XX    /widthshow
  173. XX    /awidthshow
  174. XX    /kshow
  175. XX]
  176. XX% When encoutered, the currentrgbcolor will be checked
  177. XX% (You should only include operators that actually mark the page.)
  178. XX
  179. XXdup length 2 add userdict maxlength add dict /colorpdict exch def
  180. XXcolorpdict begin
  181. XX
  182. XX{
  183. XX    [
  184. XX        /colorp cvx
  185. XX        2 index load
  186. XX        dup type /arraytype eq {
  187. XX            systemdict begin
  188. XX            /exec load
  189. XX            end
  190. XX        } if
  191. XX    ] cvx def
  192. XX} forall
  193. XX
  194. XX/please
  195. XX{
  196. XX    /colorp
  197. XX    {
  198. XX        currentrgbcolor 2 index ne 3 1 roll ne or {
  199. XX            (Non-gray color encountered\n) print flush
  200. XX            /colorp null cvx def
  201. XX        } if
  202. XX    } bind def
  203. XX} def
  204. XX
  205. XXend
  206. SHAR_EOF
  207. if test 728 -ne "`wc -c colorpdict.ps`"
  208. then
  209. echo shar: error transmitting colorpdict.ps '(should have been 728 characters)'
  210. fi
  211. echo shar: extracting level2 '(802 characters)'
  212. sed 's/^XX//' << \SHAR_EOF > level2
  213. XX%!
  214. XX%%Title: colorpdict 1.0 (for Level 2 PS)
  215. XX%%Creator: ab@nova.cc.purdue.edu
  216. XX%%EndComments
  217. XX
  218. XX% put operators with graphic output here:
  219. XX[
  220. XX    /fill
  221. XX    /eofill
  222. XX    /stroke
  223. XX    /ufill
  224. XX    /ueofill
  225. XX    /ustroke
  226. XX    /rectfill
  227. XX    /rectstroke
  228. XX    /imagemask
  229. XX    /show
  230. XX    /ashow
  231. XX    /widthshow
  232. XX    /awidthshow
  233. XX    /xshow
  234. XX    /xyshow
  235. XX    /yshow
  236. XX    /glyphshow
  237. XX    /cshow
  238. XX    /kshow
  239. XX]
  240. XX% When encoutered, the currentrgbcolor will be checked
  241. XX% (You should only include operators that actually mark the page.)
  242. XX
  243. XXdup length 2 add dict /colorpdict exch def
  244. XXcolorpdict begin
  245. XX
  246. XX{
  247. XX    [
  248. XX        /colorp cvx
  249. XX        2 index load
  250. XX        dup type /arraytype eq {
  251. XX            systemdict begin
  252. XX            /exec load
  253. XX            end
  254. XX        } if
  255. XX    ] cvx def
  256. XX} forall
  257. XX
  258. XX/please
  259. XX{
  260. XX    /colorp
  261. XX    {
  262. XX        currentrgbcolor 2 index ne 3 1 roll ne or {
  263. XX            (Non-gray color encountered\n) print flush
  264. XX            /colorp null cvx def
  265. XX        } if
  266. XX    } bind def
  267. XX} def
  268. XX
  269. XXend
  270. SHAR_EOF
  271. if test 802 -ne "`wc -c level2`"
  272. then
  273. echo shar: error transmitting level2 '(should have been 802 characters)'
  274. fi
  275. #    End of shell archive
  276. exit 0
  277.