home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / vrac / pslwgs15.zip / PSLWCMYK.PSF < prev    next >
Text File  |  1994-12-10  |  12KB  |  324 lines

  1. *ps_lw_cmyk
  2.  
  3. % ** Start user custom prolog for portrait orientation with linewidth
  4. %    and CMYK color control by AutoCAD color number.
  5.  
  6. ;% Set up a small dictionary for our own use
  7. /UserPrologDict 50 dict def UserPrologDict begin
  8. ;
  9. ;% Save our version in case PSFILLs care
  10. /LGP_version 1.5 def
  11.  
  12. % The following section sets up the mapping of AutoCAD color numbers
  13. %  to line widths.
  14.  
  15. % Note that the linewidths specified below are _minimums_.  Explicit
  16. %     linewidths (for example, a polyline with width) that are larger
  17. %     than the minimum override the minimum.  Also note that if the
  18. %     coordinate system is distorted, lines in the shorter direction
  19. %     will be thicker than the minimum (for example, a block inserted
  20. %     with X and Y scale factors that are not equal in magnitude).  On
  21. %     a system with fewer dots per inch in one direction than the other
  22. %     this should work, but I haven't tested it.
  23.  
  24. % An array containing the desired line width in inches for any of the
  25. %     first sixteen colors.  May be expanded or contracted if desired.
  26. %     Colors that are not covered in this array are mapped to the
  27. %     width specified for the last entry in the array.
  28.  
  29. /LGP_colortowidth
  30.   [
  31.     0.001          % Color 1 (red)
  32.     0.001          % Color 2 (yellow)
  33.     0.001          % Color 3 (green)
  34.     0.001          % Color 4 (cyan)
  35.     0.001          % Color 5 (blue)
  36.     0.001          % Color 6 (magenta)
  37.     0.001          % Color 7 (white)
  38.     0.001          % Color 8
  39.     0.001          % Color 9
  40.     0.001          % Color 10
  41.     0.001          % Color 11
  42.     0.001          % Color 12
  43.     0.001          % Color 13
  44.     0.001          % Color 14
  45.     0.001          % Color 15
  46.   ] def
  47.  
  48. % Now the map of AutoCAD color numbers to output colors, using the
  49. % CMYK (Cyan-Magenta-Yellow-blacK) model.
  50.  
  51. % Each line should have four numbers between the square brackets
  52. %  on that line.  The first number should range from 1 (maximum amount of
  53. %  cyan) to 0 (no cyan); the second number should range from 1 (maximum
  54. %  amount of magenta) to 0 (no magenta); the third number should range
  55. %  from 1 (maximum amount of yellow) to 0 (no yellow); and the fourth
  56. %  number should range from 1 (maximum amount of black) to 0 (no black).
  57. %  For example, black is formed by [ 0 0 0 1], white is formed by
  58. %  [ 0 0 0 0 ], and cyan is formed by [ 1 0 0 0 ].
  59.  
  60. % The original entries in this array map each of the first fifteen colors
  61. %  to reasonable approximations of themselves (assuming AutoCAD is in 16
  62. %  color mode with no color customization).
  63.  
  64. % This array must have at least as many entries as LGP_colortowidth.  If it
  65. %  has more entries than LGP_colortowidth, the extra entries are ignored.
  66. %  Colors that are not covered in this array are mapped to the RGB color
  67. %  specified for the last used entry in the array.
  68.  
  69. /LGP_ACADcolortoPScolor
  70.   [
  71.     [  0.00 1.00 1.00 0.00  ]          % Color 1 (red)
  72.     [  0.00 0.00 1.00 0.00  ]          % Color 2 (yellow)
  73.     [  1.00 0.00 1.00 0.00  ]          % Color 3 (green)
  74.     [  1.00 0.00 0.00 0.00  ]          % Color 4 (cyan)
  75.     [  1.00 1.00 0.00 0.00  ]          % Color 5 (blue)
  76.     [  0.00 1.00 0.00 0.00  ]          % Color 6 (magenta)
  77.     [  0.00 0.00 0.00 0.00  ]          % Color 7 (white)
  78.     [  0.00 0.00 0.00 0.50  ]          % Color 8
  79.     [  0.00 0.67 0.67 0.33  ]          % Color 9
  80.     [  0.00 0.00 0.67 0.33  ]          % Color 10 
  81.     [  0.67 0.00 0.67 0.33  ]          % Color 11
  82.     [  0.67 0.00 0.00 0.33  ]          % Color 12
  83.     [  0.67 0.67 0.00 0.33  ]          % Color 13
  84.     [  0.00 0.67 0.00 0.33  ]          % Color 14
  85.     [  0.00 0.00 0.00 0.33  ]          % Color 15
  86.   ] def
  87.  
  88. ;% Set up an alias for the function that sets the current color
  89. ;%  values for the PostScript interpreter.  This allows the code section
  90. ;%  to be independent of the color model.
  91.  
  92. /LGP_setcolor { setcmykcolor } bind def
  93.  
  94. ;%  START THE CODE SECTION
  95. ;
  96. ;% First some preliminary stuff
  97. ;
  98. ;% A routine to find the square root of the sum of the squares of the top
  99. ;%  two numbers of the stack
  100. ;
  101. ;%     num1 num2 LGP_SqrtSumSquares sqrt(num1*num1 + num2*num2)
  102. ;
  103. /LGP_SqrtSumSquares { dup mul exch dup mul add sqrt } bind def
  104. ;
  105. % A routine to find the minimum non-zero magnitude of either the X scale
  106. %     factor or the Y scale factor of a given transformation matrix.
  107. %     Assumes at least one of the scale factor magnitudes is non-zero.
  108. ;
  109. ;%     CTM LGP_MinScaleMag (minimum scale factor, dots per unit)
  110. ;
  111. /LGP_MinScaleMag { 
  112. ;  % Get the elements of the matrix
  113.    aload
  114. ;  % Discard the original matrix and the translation entries
  115.    pop pop pop 
  116. ;  % Arrange the stack to get the X coefficents and Y coefficients
  117. ;  %     together
  118.    4 1 roll exch 4 -1 roll
  119. ;  % Find the magnitude of the vector defined by the Y coefficients
  120.    LGP_SqrtSumSquares
  121. ;  % Bring the X coefficients to the top of the stack
  122.    3 1 roll
  123. ;  % Find the magnitude of the vector defined by the X coefficients
  124.    LGP_SqrtSumSquares
  125. ;  % Copy the two magnitudes
  126.    2 copy
  127. ;  % If the Y magnitude is greater than the X magnitude ...
  128.    gt
  129. ;  % Swap the X and Y magnitudes
  130.    { exch } if
  131. ;  % If the minimum magnitude, now one down in the stack, is zero
  132. ;  %  then swap so the maximum (assumed non-zero) magnitude
  133. ;  %  is one down in the stack
  134.    exch dup 0.0 ne { exch } if
  135. ;  % The maximum magnitude is on top of the stack, discard it
  136.    pop
  137. ;  % Leaving the minimum magnitude on the stack
  138. } bind def
  139. ;
  140. ;% Get the dot-pitches per inch for this printer (accounting for
  141. ;%     the possibility that it may be different in X and Y directions;
  142. ;%     we pick the minimum)
  143. ;
  144. /LGP_printerdotsperinch matrix defaultmatrix LGP_MinScaleMag 72 mul def
  145. ;
  146. ;% Convert the array of line widths in inches to line widths in dots
  147. ;
  148. LGP_colortowidth { LGP_printerdotsperinch mul } forall
  149.   LGP_colortowidth astore /LGP_colortowidth def
  150. ;
  151. ;% Initialize the current minimum and desired line widths in current dots.
  152. ;%     These numbers are arbitrary and will be overriden immediately.
  153. ;
  154. /LGP_minwidth 1 def
  155. /LGP_desiredwidth 1 def
  156. ;
  157. ;% Set up an array in which to simulate a stack of values of
  158. ;%     LGP_desirewidth (and, not incidentally, load it with a dummy
  159. ;%     value to be removed at the final "grestore" of the EPS file)
  160. ;
  161. /LGP_dw_stack [ LGP_desiredwidth ] def
  162. ;
  163. end
  164. ;
  165. ;% Now the routines that really DO things.
  166. ;
  167. ;% A "front end" for the stroke function.  Sets the line width to
  168. ;%     the desired line width before stroking, so the line width
  169. ;%     will always be the desired value no matter what machinations
  170. ;%     have gone on with the scale.  NOTE that this procedure and
  171. ;%     the binding that follows it MUST precede the "front end"
  172. ;%     for the setlinewidth procedure
  173. ;
  174. /LGP_strokefrontend {
  175.   UserPrologDict begin
  176. ; % Get the current desired line width in dots
  177.   LGP_desiredwidth
  178. ; % Get the current scale factor in dots per unit
  179.   matrix currentmatrix LGP_MinScaleMag
  180. ; % Divide desired line width in dots by dots per unit to get units
  181.   div 
  182.   setlinewidth
  183.   end
  184. } bind def
  185. ;
  186. ;% Bind our front end to the original stroke function for speed
  187. ;
  188. /stroke { LGP_strokefrontend stroke } bind def
  189. ;
  190. ;% A front end for the setlinewidth function.  If the requested line
  191. ;%     width in inches is greater than LGP_minwidth, sets the line
  192. ;%     width to the requested value and sets LGP_desiredwidth to the
  193. ;%     requested line width in dots.  If the requested line width
  194. ;%     is less than LGP_minwidth, uses LGP_minwidth instead.
  195. ;%     NOTE that this front end and the binding that follows MUST
  196. ;%     follow the stroke front end and its binding.
  197. ;
  198. ;%     num setlinewidth -
  199. ;
  200. /LGP_setlwfrontend {
  201.   UserPrologDict begin
  202. ; % Get the current scale factor in dots per unit
  203.   matrix currentmatrix LGP_MinScaleMag
  204. ; % Save copies of the current dots per unit and requested linewidth
  205.   2 copy
  206. ; % And convert the requested line width (in units) to dots
  207.   mul
  208. ; % Compare the requested line width to the current minimum line width
  209.   dup LGP_minwidth gt
  210. ;   % Here the requested line width is greater than our minimum
  211.     {
  212. ;     % Set the current desired line width in dots
  213.       /LGP_desiredwidth exch def
  214. ;     % Discard the extra copy of the current inches per unit, leaving
  215. ;     %   the requested line width in units on the stack
  216.       pop
  217.     }
  218. ;   % Here the requested line width is less than our minimum
  219.     {
  220. ;     % Discard the requested line width in dots
  221.       pop
  222. ;     % Get our minimum line width in dots and save a copy
  223.       LGP_minwidth dup
  224. ;     % Save the current desired line width in dots
  225.       /LGP_desiredwidth exch def
  226. ;     % Convert the desired line width in dots to units
  227.       exch div
  228. ;     % Discard the originally requested line width, leaving our
  229. ;     %   minimum line width in units on the stack
  230.       exch pop
  231.     }
  232.   ifelse
  233.   end
  234. } bind def
  235. ;
  236. ;% Bind the setlinewidth front end to the setlinewidth function for speed
  237. ;
  238. /setlinewidth { LGP_setlwfrontend setlinewidth } bind def
  239. ;
  240. ;% A routine to set desired line width and color or gray scale whenever
  241. ;%     AutoCAD changes colors.  Doesn't actually set the line width (just
  242. ;%     saves it in LGP_desiredwidth and LGP_minwidth), does actually
  243. ;%     set the color or gray scale
  244. ;
  245. ;%     (color number) (red value) (green value) (blue value) ACADColor -
  246. ;
  247. /ACADColor {
  248.   UserPrologDict begin
  249. ; % Discard the RGB values of the color
  250.   pop pop pop
  251. ; % If the color number is greater than the number of elements in the
  252. ; %    array, use the highest number that's covered in the array
  253.   dup LGP_colortowidth length gt { pop LGP_colortowidth length } if
  254. ; % Convert the color number into a zero-based array index
  255.   1 sub
  256. ; % Save the index for later (for the gray scale array)
  257.   dup
  258. ; % Get the desired line width in dots and save it both as the minimum
  259. ; %     and the desired value
  260.   LGP_colortowidth exch get /LGP_minwidth exch dup /LGP_desiredwidth exch
  261.   def def
  262. ; % Get the desired color or gray scale value array ...
  263.   LGP_ACADcolortoPScolor exch get 
  264. ; % Extract the elements of the array and discard the array
  265.   aload pop
  266. ; % Implement the new color or gray scale
  267.   LGP_setcolor
  268.   end
  269. } bind def
  270. ;
  271. ;% A "front end" for the gsave function.  Simulates pushing LGP_desiredwidth
  272. ;%     on a stack (really an array).  In effect, LGP_desiredwidth is saved
  273. ;%     along with the graphics state.
  274. ;
  275. /LGP_gsavefrontend {
  276.   UserPrologDict begin
  277. ; % Put the name of our array on the stack
  278.   /LGP_dw_stack
  279. ; % Start an array
  280.   [
  281. ; % Put the array itself on the stack, unload its elements onto the stack,
  282. ; %     and discard the array that "aload" leaves on top
  283.   LGP_dw_stack aload pop
  284. ; % Put the current value of LGP_desiredwidth on the stack
  285.   LGP_desiredwidth
  286. ; % End the array and save it
  287.   ] def
  288.   end
  289. } bind def
  290. ;
  291. ;% Bind our front end to the original gsave function for speed
  292. ;
  293. /gsave { LGP_gsavefrontend gsave} bind def
  294. ;
  295. ;% A "front end" for the grestore function.  Simulates popping
  296. ;%     LGP_desiredwidth from a stack (really an array).  In effect,
  297. ;%     LGP_desiredwidth is restored along with the graphics state
  298. ;
  299. /LGP_grestorefrontend {
  300.   UserPrologDict begin
  301. ; % Put the name of our array on the stack
  302.   /LGP_dw_stack
  303. ; % Start an array
  304.   [
  305. ; % Put the array itself on the stack, unload its elements onto the stack,
  306. ; %     and discard the array that "aload" leaves on top
  307.   LGP_dw_stack aload pop
  308. ; % Store the last value in the array into LGP_desiredwidth
  309.   /LGP_desiredwidth exch def
  310. ; % End the array and save it
  311.   ] def
  312.   end
  313. } bind def
  314. ;
  315. ;% Bind our front end to the original grestore function for speed
  316. ;
  317. /grestore { LGP_grestorefrontend grestore} bind def
  318. ;
  319. ;% If the setstrokeadjust procedure is available, activate stroke adjustment
  320. ;
  321. /setstrokeadjust where { pop true setstrokeadjust } if
  322.  
  323. % ** End user custom prolog
  324.