[comp.lang.postscript] Postscript Shape filling

dhesi@helios.misemi (dhesi) (03/23/88)

	I am trying to print pattern filled shapes so that
in cases where they overlap, the overlapping section contains
all of the fillpatterns of the individual shapes.  Presently,
the shape drawn last obscures all other patterns. Anybody ?

geof@imagen.UUCP (Geoffrey Cooper) (03/26/88)

In article <253@helios.misemi>, dhesi@helios.misemi (dhesi) writes:
> 
> 	I am trying to print pattern filled shapes so that
> in cases where they overlap, the overlapping section contains
> all of the fillpatterns of the individual shapes. 

What you are trying to do is somewhat awkward in PostScript, because you
are requesting an operation (so-called "transparent" colors) that is not
in the imaging model for the language.  In PostScript, all colors
("ink"s) are opaque.

There are two basic techniques for generating blending of textures in
PostScript.  The simplest, which might not be powerful enough for you,
is to use the CLIP operator to segment each shape, and then laboriously
draw out the texture using stroke and fill operations.  Since you have
arranged to only put down ink exactly where you wanted it, the apparent
texture acts transparently.  This is reasonable only when the textures
involved are very simple, such as a cross-hatch pattern.  Even so, see
the technique below:

Example:

Let us assume that procedures "a" and "b" append paths for two objects
to the current path.  In this case they are circles.

	/a { 200 200 100 0 360 arc closepath } def
	/b { 300 200 100 0 360 arc closepath } def
	/colora { 0 setlinewidth % vertical cross-hatch
		  0 2 1000 { 0 moveto 0 1000 rlineto stroke } for } def
	/colorb { 0 setlinewidth % horizontal cross-hatch
		  0 2 1000 { 0 exch moveto 1000 0 rlineto stroke } for } def
	gsave a clip newpath colora grestore
	gsave b clip newpath colorb grestore
	showpage

For more complex textures and more general blending of colors, you want
to paint each object in its own color/gray, then use the clip operator
to isolate intersections of the objects.  Obviously you have to be
careful, or you will have (#objects)^2 tests for intersection (or
2^#objects, if you count multiple intersections).  But for simple
drawings of complex patterns, or for situations where you know which
objects are intersecting, this is a good technique.  Note that it
allows for arbitrary choice of the intersection fill, which gives it
applicability to true color drawings.

Example:
	/colora { 60 0 { pop } setscreen .5 setgray } def
	/colorb { 60 0 { exch pop } setscreen .5 setgray } def
	/colorc { 60 45 { pop } setscreen .5 setgray } def
	colora a fill
	colorb b fill
	colorc a clip newpath b clip fill

The second technique is probably the faster of the two, from an
execution point of view.  It is also more flexible.

- Geof Cooper
  IMAGEN
-- 
{decwrl,sun,saber}!imagen!geof