PDFlib 8 Windows COM/.NET Tutorial
PDFlib 8 Windows COM/.NET Tutorial
PDFlib 8 Windows COM/.NET Tutorial
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
3.5 Working with Color<br />
Note The <strong>PDFlib</strong> API Reference contains a detailed list of supported color spaces with descriptions.<br />
Cookbook Code samples regarding color issues can be found in the color category of the <strong>PDFlib</strong> Cookbook.<br />
For an overview of using color spaces, see the Cookbook topic color/starter_color.<br />
3.5.1 Patterns and Smooth Shadings<br />
As an alternative to solid colors, patterns and shadings are special kinds of colors which<br />
can be used to fill or stroke arbitrary objects.<br />
Patterns. A pattern is defined by an arbitrary number of painting operations which<br />
are grouped into a single entity. This group of objects can be used to fill or stroke arbitrary<br />
other objects by replicating (or tiling) the group over the entire area to be filled or<br />
the path to be stroked. Working with patterns involves the following steps:<br />
> First, the pattern must be defined between begin_pattern( ) and end_pattern( ). Most<br />
graphics operators can be used to define a pattern.<br />
> The pattern handle returned by begin_pattern( ) can be used to set the pattern as the<br />
current color using setcolor( ).<br />
Depending on the painttype parameter of begin_pattern( ) the pattern definition may or<br />
may not include its own color specification. If painttype is 1, the pattern definition must<br />
contain its own color specification and will always look the same; if painttype is 2, the<br />
pattern definition must not include any color specification. Instead, the current fill or<br />
stroke color will be applied when the pattern is used for filling or stroking.<br />
Note Patterns can also be defined based on a smooth shading (see below).<br />
Cookbook Full code samples can be found in the Cookbook topics graphics/fill_pattern and<br />
images/tiling_pattern.<br />
Smooth shadings. Smooth shadings, also called color blends or gradients, provide a<br />
continuous transition from one color to another. Both colors must be specified in the<br />
same color space. <strong>PDFlib</strong> supports two different kinds of geometry for smooth shadings:<br />
> axial shadings are defined along a line;<br />
> radial shadings are defined between two circles.<br />
Shadings are defined as a transition between two colors. The first color is always taken<br />
to be the current fill color; the second color is provided in the c1, c2, c3, and c4 parameters<br />
of shading( ). These numerical values will be interpreted in the first color’s color space<br />
according to the description of setcolor( ).<br />
Calling shading( ) will return a handle to a shading object which can be used in two<br />
ways:<br />
> Fill an area with shfill( ). This method can be used when the geometry of the object to<br />
be filled is the same as the geometry of the shading. Contrary to its name this function<br />
will not only fill the interior of the object, but also affects the exterior. This behavior<br />
can be modified with clip( ).<br />
> Define a shading pattern to be used for filling more complex objects. This involves<br />
calling shading_pattern( ) to create a pattern based on the shading, and using this pattern<br />
to fill or stroke arbitrary objects.<br />
80 Chapter 3: Creating PDF Documents (Edition for <strong>COM</strong>, .<strong>NET</strong>, and REALbasic)