home *** CD-ROM | disk | FTP | other *** search
/ Computer Buyer 1996 May / buyer-0596.iso / business / design / dwk3 / libs / des_sty.pre < prev   
Text File  |  1995-04-20  |  18KB  |  563 lines

  1. %#BeginStyles: 30
  2. %----------------------------------------------------------------------
  3. %       DES_STY.PRE      v1.08
  4. % This file contains some postscript procedures for use as fill styles
  5. % or line styles. A PostScript programmer should be able to add new
  6. % styles to this file and access them from within GST ArtWork.
  7. %----------------------------------------------------------------------
  8. % The first line in the file gives an approximate number for the total 
  9. % number of fill styles and line styles defined here. 
  10. % The value given there should be greater than or equal to the actual number
  11. % of styles defined in the file. Excessive over-estimates waste memory.
  12. %----------------------------------------------------------------------
  13. % Each fill style is bracketed with %%BeginFill and %%EndFill
  14. % lines: these must not have any leading spaces. The BeginFill keyword
  15. % is followed by a colon, then a number of key=value pairs. 
  16. % Each keyword may be up to 20 characters, and the values must be integers.
  17. % The first keyword is the procedure name, and the value is used by
  18. % the program to refer to that procedure. The remaining keywords
  19. % are descriptions of the parameters, along with their default values.
  20. % An ampersand (&) character in the keyword name causes the following
  21. % character to be underlined when displayed on the dialog box, and that
  22. % character can then be used as a keyboard shortcut.
  23. % A %%Comment line may optionally follow the %%BeginFill line; the text
  24. % from the comment line will be displayed on the dialog box when that
  25. % style is selected in the listbox.
  26. % The actual postscript procedure name starts with a hash character (#) 
  27. % followed by the fill style name.
  28. %----------------------------------------------------------------------
  29. % example:
  30. %   %%BeginFill: WireMesh=106 &Width(pt)=28 &Height(pt)=28
  31. %   %%Comment: The background (between the wires) is transparent.
  32. %
  33. % The fill style 'WireMesh' has two parameters, width and height. 
  34. % On the dialog box, Alt-W selects the width, and Alt-H selects the height.
  35. % it's name is shown in the listbox as WireMesh, and the comment 
  36. % about a transparent background appears on the form.
  37. %
  38. % The postscript procedure #WireMesh is called, with the width is pushed 
  39. % onto the stack, followed by the height. The procedure is expected to 
  40. % remove them from the stack itself.
  41. %----------------------------------------------------------------------
  42. % Line style procedures are bracketed with %%BeginLine and %%EndLine 
  43. % in a similar manner. The line thickness, colour, end and corner styles,
  44. % and mitre limit from the main form are all initialised for postscript 
  45. % before the procedure is called.
  46. % The postscript procedure name for a line style starts with an underline
  47. % character, followed by the line style name.
  48. %----------------------------------------------------------------------
  49. % The procedures at the top, bracketed with %%BeginCommon and %%EndCommon
  50. % are all sent to the printer if any of the line styles or fill styles
  51. % are used.
  52. %----------------------------------------------------------------------
  53. % The section between %%BeginScreens and EndScreens defines the special
  54. % postscript halftone screens, and is only transmitted to the printer if
  55. % a fill styles uses one of the screens.
  56. %----------------------------------------------------------------------
  57.  
  58.  
  59. %----------------------------------------------------------------------
  60.  
  61. %%BeginCommon
  62.  
  63. %----- support routines for 'user defined' postscript styles -----%
  64.  
  65. %validate: range-check a value, leave on stack with name for 'def'
  66. /validate {             % value min max
  67.   2 copy 4 index        % value min max min max value
  68.   lt                    % value min max min bool
  69.   exch 4 index          % value min max bool min value
  70.   gt or                 % value min max bool
  71.   { 
  72.     add 2 div           % replace value with mid-range
  73.     exch pop
  74.   }{
  75.     pop pop             % discard min & max
  76.   } ifelse
  77. } bd
  78.  
  79. /mm { 39.37 mul } bd       % convert mm to internal units
  80. /pt { 1000 mul 72 div } bd       % convert pt to internal units
  81.  
  82. %rand01: return a random number in range 0 to 1
  83. /rand01 { rand bignum div dup truncate sub abs } bd
  84.  
  85. % random: min max : returns number in given range
  86. /random { 1 index sub rand01 mul add } bd
  87.  
  88. % randpos: translate to random position
  89. /randpos { Left Right random Bottom Top random translate } bd
  90.  
  91. %---- chain: for special line styles -----%
  92.  
  93. /chainmove {
  94.   dup /PosY ed dup /SegY ed /PathY ed    
  95.   dup /PosX ed dup /SegX ed /PathX ed    
  96.   /Part 0 def
  97. } bd
  98.  
  99. /rect_to_polar {   % dy dx -> rect_to_polar -> theta len
  100.   2 copy
  101.   0 ne exch 0 ne or {
  102.     2 copy atan 3 1 roll
  103.     dup mul exch dup mul add sqrt
  104.   }if
  105. }bd
  106.  
  107. /chainline2 {
  108.   /EndY ed /EndX ed 
  109.   EndY PosY sub EndX PosX sub 
  110.   rect_to_polar 
  111.   /Len ed /Theta ed
  112.   /Num Len BlockLen div def
  113.   /Whole Num round cvi def   
  114.   Num 2.7 gt {        % if a fair number, scale to fit
  115.     /BlockLen2 BlockLen Num mul Whole div def
  116.     /Part 0 def
  117.   }{
  118.     /BlockLen2 BlockLen def 
  119.     /Part Num Whole sub def
  120.   } ifelse
  121.  
  122.   Whole 1 ge {
  123.     matrix currentmatrix        % save transformation matrix
  124.     PosX PosY translate
  125.     Theta rotate                % transform to fit path
  126.     BlockLen2 BlockWid scale
  127.     .05 setlinewidth wif        % set line width & winding fill
  128.     newpath                     % initialise path to empty
  129.     .5 1 Whole {                % loop per block on path
  130.       /Pos ed
  131.       gs Pos 0 translate newpath DrawBlock gr
  132.       Pos .5 add 0 moveto       % set current point at end of block
  133.     } for
  134.     setmatrix                   % restore transformation matrix
  135.     currentpoint                % pick up end point of final block in current space
  136.     /PosY ed /PosX ed           % and remember it
  137.   } if
  138.   /SegX EndX def
  139.   /SegY EndY def
  140. } bd
  141.  
  142. /chainline {
  143.   2 copy /EndY ed /EndX ed 
  144.   Part 0.5 gt {                   % if there's any gap at end of last segment
  145.     EndY SegY sub EndX SegX sub 
  146.     rect_to_polar 
  147.     /Len ed /Theta ed           % get this segment length
  148.     Len BlockLen 2 mul gt       % if this segment is a long one
  149.     {  
  150.                                
  151.        PosX PosY       % stack current end point
  152.        % transform an identity matrix to match tile's transformation
  153.        BlockLen BlockWid Theta SegX SegY
  154.        matrix translate rotate scale
  155.        itransform      % calculate point's inverse transformation: x y
  156.  
  157.        2 copy %for debugging: x y x y
  158.  
  159.        % if ((abs(x) < abs(y)) or (x >= 0) treat as a sharp corner
  160.        exch dup        % y x x
  161.        0 ge 3 1 roll   % bool y x
  162.        abs exch abs    % bool abs(x) abs(y)
  163.        lt or {
  164.  
  165.          % debug code:
  166.          % PosX PosY SegX SegY Part break
  167.          
  168.  
  169.          % sharp corner: simply adjust start point
  170.          /PosX SegX def
  171.          /PosY SegY def
  172.        } if
  173.  
  174.        pop pop % debugging, pop spare x & y
  175.  
  176.     }if
  177.   }if
  178.   chainline2                    % do rest of line up to original endpoint
  179. } bd
  180.  
  181. /chain {        % blocklength blockwidth proc
  182.  /DrawBlock ed      
  183.  1 25 validate mm /BlockWid ed
  184.  1 25 validate mm /BlockLen ed   
  185.  setcolour
  186.  Print? {       % if printing this separation...
  187.    gs 
  188.      flatp
  189.        {chainmove} 
  190.        {chainline} 
  191.        {error} 
  192.        {PathX PathY chainline} 
  193.      pathforall
  194.    gr
  195.  } if
  196. } bd    
  197. %%EndCommon
  198.  
  199. %---------------------------------------------------------------------------
  200.  
  201. %%BeginScreens=Default,Dot,Ellipse,Line,Propeller,Square Dots,Square Grid,Triangle,Diamond,White dot
  202.  
  203. /Screens [
  204.   {}          % to be replaced by default during setup
  205.  
  206.   { dup mul exch dup mul add 1 exch sub } bind % Dot: simple black dot
  207.  
  208.   { dup 5 mul 8 div mul exch dup mul exch add sqrt 1 exch sub } bind % Ellipse
  209.  
  210.   { exch pop abs 1 exch sub } bind % Line (horiz at 0 degrees)
  211.  
  212.   { 2 copy .001 add atan cvi 72 mod 72 sub abs 72 div 3 1 roll
  213.     dup mul exch dup mul add 1 exch sub add 2 div } bind % Propellor (5 blade)
  214.  
  215.   { abs exch abs 2 copy gt {exch} if pop 2 mul 1 sub } bind % Square Dots
  216.  
  217.   { abs exch abs 2 copy gt {exch} if pop 2 mul 1 exch sub } bind % Square Grid
  218.  
  219.   { 2 exch sub exch abs 2 mul sub 3 div } bind % Triangle
  220.  
  221.   { abs exch abs add 1 exch sub } bind % Diamond
  222.  
  223.   { dup mul exch dup mul add 1 sub } bind % White dot
  224. ] def
  225.  
  226.  
  227. /setscr { 
  228.   exch AngleFix add exch % adjust angle if landscape
  229.   Screens exch get      % convert screen number to procedure
  230.   setscreen             % and select the halftone screen
  231.   % use default transfer function for special effects
  232.   % as the normalise function only works for default screen setup
  233.   {?Negative DefTran}settransfer  
  234. } bd
  235.  
  236. %%EndScreens
  237.  
  238. %---------------------------------------------------------------------------
  239.  
  240.  
  241. %%BeginFill: Grass=100 &Blades=100 S&mallest(mm)=5 &Largest(mm)=10 
  242. %%Comment: random blades of grass - colour1->background colour2->outline
  243. /#Grass {
  244.   5 25 validate mm /MaxN ed
  245.   mm 2 mm MaxN 1 sub validate /MinN ed
  246.   1 250 validate /N ed
  247.  
  248.   gs _fill gr           % fill background
  249.   setcolour             % set colour for foreground
  250.   0 setlinewidth
  251.  
  252.   clipper
  253.     N { 
  254.       gs 
  255.         randpos
  256.         MinN MaxN random 10 div dup 
  257.         rand01 .5 sub mul exch neg scale
  258.         np 0 0 m 0 4 1 9 4 10 c 2 7 2 4 2 0 c
  259.         gs cp 0 _fill gr ~stroke 
  260.       gr
  261.     } repeat
  262.   gr
  263. } bd
  264. %%EndFill
  265.  
  266.  
  267. %%BeginFill: Leaves=101 &Number=100 S&mallest(mm)=5 &Largest(mm)=20
  268. %%Comment: random leaf shapes
  269. /#Leaves {
  270.   5 25 validate mm /MaxN ed
  271.   mm 2 mm MaxN 1 sub validate /MinN ed
  272.   1 250 validate /N ed
  273.  
  274.   GradFillDict begin
  275.   grad_common_init
  276.   /GradType 0 def
  277.  
  278.   clipper                            % clip to path
  279.     N {                                 % loop N times
  280.       gs
  281.         rand01 grad_common_middle       % random colour within range
  282.         randpos                         % translate to random position
  283.         MinN MaxN random dup scale      % set scale for leaf
  284.         0 360 random rotate             % and rotation
  285.         np 0 0 m 0 .5 .5 1 1 1 c 1 .5 .5 0 0 0 c cp ~fill
  286.       gr
  287.     } repeat
  288.   gr
  289.   end
  290. } bd
  291. %%EndFill
  292.  
  293.  
  294. %%BeginFill: Bricks=102 &Width(pt)=24 &Height(pt)=6 &Mortar(pt)=1 
  295. %%Comment: colour1->bricks, colour2->mortar
  296. /#Bricks {
  297.   0 4 validate  pt /Lw ed
  298.   3 36 validate pt /Bheight ed
  299.   6 72 validate pt /Bwidth ed
  300.  
  301.   Lw setlinewidth
  302.  
  303.   gs _fill gr           % start by plain filling background with first colour
  304.   setcolour             % now select second colour for detail
  305.  
  306.   clipper 
  307.     Left Top translate
  308.     % insert commands to fill area from (0,0) to (Width,Height)
  309.     /Flag? false def
  310.     0 Bheight Height abs {
  311.       pop
  312.       np 0 0 m Width 0 l ~stroke
  313.       Flag? { Bwidth 2 div }{ 0 }ifelse
  314.       Bwidth Width {
  315.         /X ed
  316.         np X 0 m X Bheight l ~stroke
  317.       } for
  318.       /Flag? Flag? not def
  319.       0 Bheight translate
  320.     } for
  321.   gr
  322. } bd
  323. %%EndFill
  324.  
  325. %%BeginFill: Hatching=103 &Angle=45 Mi&nDist(pt)=2 &MaxDist(pt)=6 &Linewidth(pt)=1 
  326. %%Comment: only uses colour1
  327. /#Hatching {
  328.   1 6 validate pt /Lw ed
  329.   pt Lw 36 pt validate /MaxN ed
  330.   pt Lw MaxN validate /MinN ed
  331.   /Theta ed
  332.   Lw setlinewidth
  333.   setcolour             
  334.   gs Theta rotate clipper
  335.     Left Top translate
  336.     % insert commands to fill area from (0,0) to (Width,Height)
  337.     /Y 0 def
  338.     { 
  339.       np 0 Y m Width Y l ~stroke
  340.       /Y Y MinN MaxN random add def
  341.       Y Height abs ge { exit } if
  342.     } loop
  343.   gr gr
  344.   setcolour
  345. } bd
  346. %%EndFill
  347.  
  348. %%BeginFill: GraphMetric=104
  349. %%Comment: cm and mm graph paper; only uses colour1
  350. /#GraphMetric {  % no parameters
  351.   setcolour
  352.   clipper
  353.     Left Top translate
  354.     2 setlinewidth
  355.     0 1 mm Width { /X ed np X 0 m X Height l ~stroke } for
  356.     0 1 mm Height { /Y ed np 0 Y m Width Y l ~stroke } for
  357.     7 setlinewidth
  358.     5 mm 10 mm Width { /X ed np X 0 m X Height l ~stroke } for
  359.     5 mm 10 mm Height { /Y ed np 0 Y m Width Y l ~stroke } for
  360.     14 setlinewidth
  361.     0 10 mm Width { /X ed np X 0 m X Height l ~stroke } for
  362.     0 10 mm Height { /Y ed np 0 Y m Width Y l ~stroke } for
  363.   gr
  364.   setcolour
  365. } bd
  366. %%EndFill
  367.  
  368. %%BeginFill: GraphPaper=105
  369. %%Comment: inches graph paper; only uses colour1
  370. /#GraphPaper {  % no parameters
  371.   setcolour
  372.   clipper
  373.     Left Top translate
  374.     2 setlinewidth
  375.     0 100 Width { /X ed np X 0 m X Height l ~stroke } for
  376.     0 100 Height { /Y ed np 0 Y m Width Y l ~stroke } for
  377.     7 setlinewidth
  378.     500 1000 Width { /X ed np X 0 m X Height l ~stroke } for
  379.     500 1000 Height { /Y ed np 0 Y m Width Y l ~stroke } for
  380.     14 setlinewidth
  381.     0 1000 Width { /X ed np X 0 m X Height l ~stroke } for
  382.     0 1000 Height { /Y ed np 0 Y m Width Y l ~stroke } for
  383.   gr
  384.   setcolour
  385. } bd
  386. %%EndFill
  387.  
  388. %%BeginFill: Squares=106
  389. %%Comment: quarter inch squares; only uses colour1
  390. /#Squares {  % no parameters
  391.   setcolour
  392.   clipper
  393.     Left Top translate
  394.     2 setlinewidth
  395.     0 250 Width { /X ed np X 0 m X Height l ~stroke } for
  396.     0 250 Height abs { /Y ed np 0 Y m Width Y l ~stroke } for
  397.   gr
  398.   setcolour
  399. } bd
  400. %%EndFill
  401.  
  402. %%BeginFill: Rough=107 lo=0 hi=255
  403. %%Comment: rough pseudo-random texture
  404. /#Rough {  
  405.   /MaxN exch def /MinN exch def
  406.   setcolour
  407.   clipper
  408.     Left Top translate
  409.     Width Height scale
  410.         100 100 8 [ 100 0 0 -100 0 100 ] 
  411.         { 1 string dup 0 MinN MaxN random cvi put } 
  412.         image
  413.   gr
  414.   setcolour
  415. } bd
  416. %%EndFill
  417.  
  418. %----------------------------------------------------------------------------
  419.  
  420. %%BeginLine: Neon=200 &Width(pt)=5 
  421. %%Comment: neon-light effect (doesn't work in colour)
  422. /_Neon {
  423.   2 12 validate pt /Lw ed
  424.   setcolour     % pick up (and ignore) line colour
  425.   gs Lw setlinewidth 50 _stroke gr
  426.   gs Lw 2 div setlinewidth 100 _stroke gr
  427.   gs 10 setlinewidth 0 _stroke gr
  428. } bd
  429. %%EndLine
  430.  
  431. %%BeginLine: Calligraphic=202 &Penfactor=5 &Angle=30
  432. %%Comment: Maximum line width is defined on the main form.
  433. /_Calligraphic {
  434.   /Theta ed 
  435.   2 20 validate 
  436.   /PenScale ed 
  437.   setcolour
  438.   gs currentlinewidth Theta rotate 1 1 PenScale div scale setlinewidth ~stroke gr
  439. } bd
  440. %%EndLine
  441.  
  442. %%BeginLine: TripleLine=203
  443. %%Comment: works best if line width >= 4pt
  444. /_TripleLine {
  445.   setcolour 
  446.   Print? { % if printing this separation...
  447.     gs stroke gr currentlinewidth dup
  448.     gs .75 mul setlinewidth 1 setgray stroke gr
  449.     gs .4 mul setlinewidth stroke gr
  450.   } if
  451. } bd
  452. %%EndLine
  453.  
  454. %%BeginLine: Dingbats=205 &Pointsize=14 &Dingbat=118
  455. /_Dingbats {
  456.   dup 128 gt { 161 254 validate }{ 33 126 validate } ifelse /DingChar ed
  457.   5 72 validate pt 
  458.   40 div dup % convert to MM for chain
  459.   tempstr 0 DingChar put
  460.   gs 
  461.   /Dingfont /ZapfDingbats findfont def
  462.   { 
  463.     Dingfont 1 scalefont setfont
  464.     -.5 -.5 moveto tempstr show
  465.   } chain 
  466.   gr
  467. } bd
  468. %%EndLine
  469.  
  470.  
  471. %%BeginLine: DoubleLine=206 
  472. %%Comment: This draws a thin white line down the middle
  473. /_DoubleLine { 
  474.   setcolour 
  475.   Print? {    % if printing this separation...
  476.     gs stroke gr
  477.     gs currentlinewidth 3 div setlinewidth 
  478.     1 setgray stroke gr
  479.   } if 
  480. } bd
  481. %%EndLine
  482.  
  483. %%BeginLine: Charcoal=207 &Lightest(%)=25 &Darkest(%)=75 &Width(pt)=7
  484. %%Comment: Drawn in black
  485. /randdot { pop pop rand01 .5 sub } bd
  486. /_Charcoal { % light dark width
  487.   2 12 validate pt /Lw ed
  488.   10 100 validate /Dark ed
  489.   0 Dark 2 sub validate /Light ed
  490.   Dark Light sub log 3 mul /Delta ed
  491.   Light Delta Dark { 
  492.      /N exch def
  493.      N 100 add 10 div N 5 add { randdot } setscreen
  494.      100 N sub 100 Light sub div Lw mul setlinewidth 
  495.      gs N _stroke gr
  496.   } for
  497. } bd
  498. %%EndLine
  499.  
  500. %%BeginLine: Dots=208 &Length(mm)=4 &Width(mm)=4
  501. /_Dots { { 0 0 .5 0 360 arc fill } chain } bd
  502. %%EndLine
  503.  
  504. %%BeginLine: Triangles=209 &Length(mm)=4 &Width(mm)=4
  505. /_Triangles { { -.5 .5 m .5 0 l -.5 -.5 l cp fill } chain } bd
  506. %%EndLine
  507.  
  508. %%BeginLine: TrianglesReversed=210 &Length(mm)=4 &Width(mm)=4
  509. /_TrianglesReversed { { .5 .5 m -.5 0 l .5 -.5 l cp fill } chain } bd
  510. %%EndLine
  511.  
  512. %%BeginLine: StarsFilled=211 &Length(mm)=4 &Width(mm)=4
  513. /_StarsFilled { { -.45 .15 m .45 .15 l -.35 -.45 l 0 .45 l .3 -.45 l cp fill } chain } bd
  514. %%EndLine
  515.    
  516. %%BeginLine: Circles=212 &Length(mm)=4 &Width(mm)=4
  517. /_Circles { { 0 0 .5 0 360 arc stroke } chain } bd
  518. %%EndLine
  519.  
  520. %%BeginLine: StarsHollow=214 &Length(mm)=4 &Width(mm)=4
  521. /_StarsHollow { { -.45 .15 m .45 .15 l -.35 -.45 l 0 .45 l .3 -.45 l cp stroke } chain } bd
  522. %%EndLine
  523.    
  524. %%BeginLine: Zigzags=215 &Length(mm)=4 &Width(mm)=4
  525. /_Zigzags { { -.5 0 m 0 .5 l 0 -.5 l .5 0 l stroke } chain } bd
  526. %%EndLine
  527.  
  528. %%BeginLine: GreekKey=216 &Length(mm)=4 &Width(mm)=4
  529. /_GreekKey { { -.5 0 m -.5 .4 l .3 .4 l .3 -.25 l -.1 -.25 l -.1 0 l 
  530. .1 0 l .1 .25 l -.3 .25 l -.3 -.4 l .5 -.4 l .5 0 l stroke } chain } bd
  531. %%EndLine
  532.  
  533. %%BeginLine: Hearts=217 &Length(mm)=4 &Width(mm)=4
  534. /_Hearts { { 0 -.5 m -.4 -.1 l -.5 0 -.5 .1 -.4 .3 c -.3 .4 -.1 .4 0 .2 c
  535. .1 .4 .3 .4 .4 .3 c .5 .2 .5 0 .4 -.1 c cp fill } chain } bd
  536. %%EndLine
  537.  
  538. %%BeginLine: Diamonds=218 &Length(mm)=4 &Width(mm)=4
  539. /_Diamonds { { -.5 0 m 0 .5 l .5 0 l 0 -.5 l cp fill } chain } bd
  540. %%EndLine
  541.  
  542. %%BeginLine: Rope=219 &Length(mm)=4 &Width(mm)=4
  543. /_Rope { { -.8 .3 m -.6 .5 0 .5 .2 .3 c .8 -.3 l 
  544. .6 -.5 0 -.5 -.2 -.3 c cp gs 0 _fill gr stroke } chain } bd
  545. %%EndLine
  546.  
  547. %%BeginLine: Waves=220 &Length(mm)=4 &Width(mm)=4 &Number=2
  548. /_Waves { 
  549.   1 5 validate /N ed
  550.   { gs np 0 -.5 translate 1 1 N div scale
  551.     N{ 
  552.       -.5 .5 m -.35 1.15 -.15 1.15 0 .5 c 
  553.       .15 -.15 .35 -.15 .5 .5 c 
  554.       0 1 translate 
  555.     }repeat
  556.     stroke gr 
  557.   } chain 
  558. } bd
  559. %%EndLine
  560.  
  561.  
  562.  
  563.