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

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