When operators such as S (stroke), f (fill), and Tj (show text) paint an area of the page with the current color, they ordinarily apply a single color that covers the area uniformly. However, it is also possible to apply “paint” that consists of a repeating graphical figure or a smoothly varying color gradient instead of a simple color. Such a repeating figure or smooth gradient is called a pattern. Patterns are quite general, and have many uses; for example, they can be used to create various graphical textures, such as weaves, brick walls, sunbursts, and similar geometrical and chromatic effects. (See implementation note 49 in Appendix H.)
Patterns come in two varieties:
Tiling patterns consist of a small graphical figure (called a pattern cell) that is replicated at fixed horizontal and vertical intervals to fill the area to be painted. The graphics objects to use for tiling are described by a content stream.
Shading patterns define a gradient fill that produces a smooth transition between colors across the area. The color to use is specified as a function of position using any of a variety of methods.
Note
The ability to paint with patterns is a feature of PDF 1.2 (tiling patterns) and PDF 1.3 (shading patterns). With some effort, it is possible to achieve a limited form of tiling patterns in PDF 1.1 by defining them as character glyphs in a special font and painting them repeatedly with the Tj operator. Another technique, defining patterns as halftone screens, is not recommended because the effects produced are devicedependent.
Patterns are specified in a special family of color spaces named Pattern. These spaces use pattern objects as the equivalent of color values instead of the numeric component values used with other spaces. A pattern object may be a dictionary or a stream, depending on the type of pattern; the term pattern dictionary is used generically throughout this section to refer to either a dictionary object or the dictionary portion of a stream object. (Those pattern objects that are streams are specifically identified as such in the descriptions of particular pattern types; unless otherwise stated, they are understood to be simple dictionaries instead.) This section describes Pattern color spaces and the specification of color values within them. See Section 4.5, “Color Spaces,” for information about color spaces and color values in general and Section 7.5.6, “Patterns and Transparency,” for further discussion of the treatment of patterns in the transparent imaging model.
A pattern dictionary contains descriptive information defining the appearance and properties of a pattern. All pattern dictionaries contain an entry named PatternType, whose value identifies the kind of pattern the dictionary describes: type 1 for a tiling pattern or type 2 for a shading pattern. The remaining contents of the dictionary depend on the pattern type and are detailed below in the sections on individual pattern types.
All patterns are treated as colors; a Pattern color space is established with the CS or cs operator just like other color spaces, and a particular pattern is installed as the current color with the SCN or scn operator (see Table 4.24 on page 259).
A pattern's appearance is described with respect to its own internal coordinate system. Every pattern has a pattern matrix, a transformation matrix that maps the pattern's internal coordinate system to the default coordinate system of the pattern's parent content stream (the content stream in which the pattern is defined as a resource). The concatenation of the pattern matrix with that of the parent content stream establishes the pattern coordinate space, within which all graphics objects in the pattern are interpreted.
For example, if a pattern is used on a page, the pattern appears in the Pattern subdictionary of that page's resource dictionary, and the pattern matrix maps pattern space to the default (initial) coordinate space of the page. Changes to the page's transformation matrix that occur within the page's content stream, such as rotation and scaling, have no effect on the pattern; it maintains its original relationship to the page no matter where on the page it is used. Similarly, if a pattern is used within a form XObject (see Section 4.9, “Form XObjects”), the pattern matrix maps pattern space to the form's default user space (that is, the form coordinate space at the time the form is painted with the Do operator). A pattern may be used within another pattern; the inner pattern's matrix defines its relationship to the pattern space of the outer pattern.
Note
PostScript allows a pattern to be defined in one context but used in another. For example, a pattern might be defined on a page (that is, its pattern matrix maps the pattern coordinate space to the user space of the page) but be used in a form on that page, so that its relationship to the page is independent of each individual placement of the form. PDF does not support this feature; in PDF, all patterns are local to the context in which they are defined.
A tiling pattern consists of a small graphical figure called a pattern cell. Painting with the pattern replicates the cell at fixed horizontal and vertical intervals to fill an area. The effect is as if the figure were painted on the surface of a clear glass tile, identical copies of which were then laid down in an array covering the area and trimmed to its boundaries. This process is called tiling the area.
The pattern cell can include graphical elements such as filled areas, text, and sampled images. Its shape need not be rectangular, and the spacing of tiles can differ from the dimensions of the cell itself. When performing painting operations such as S (stroke) or f (fill), the application paints the cell on the current page as many times as necessary to fill an area. The order in which individual tiles (instances of the cell) are painted is unspecified and unpredictable; it is inadvisable for the figures on adjacent tiles to overlap.
The appearance of the pattern cell is defined by a content stream containing the painting operators needed to paint one instance of the cell. Besides the usual entries common to all streams (see Table 3.4 on page 38), this stream's dictionary has the additional entries listed in Table 4.25
KEY  TYPE  VALUE 

Type  name  (Optional) The type of PDF object that this dictionary describes; if present, must be Pattern for a pattern dictionary. 
PatternType  integer  (Required) A code identifying the type of pattern that this dictionary describes; must be 1 for a tiling pattern. 
PaintType  integer  (Required) A code that determines how the color of the pattern cell is to be specified:

TilingType  integer  (Required) A code that controls adjustments to the spacing of tiles relative to the device pixel grid:

Bbox  rectangle  (Required) An array of four numbers in the pattern coordinate system giving the coordinates of the left, bottom, right, and top edges, respectively, of the pattern cell's bounding box. These boundaries are used to clip the pattern cell. 
XStep  number  (Required) The desired horizontal spacing between pattern cells, measured in the pattern coordinate system. 
YStep  number  (Required) The desired vertical spacing between pattern cells, measured in the pattern coordinate system. Note that XStep and YStep may differ from the dimensions of the pattern cell implied by the BBox entry. This allows tiling with irregularly shaped figures. XStep and YStep may be either positive or negative but not zero. 
Resources  dictionary  (Required) A resource dictionary containing all of the named resources required by the pattern's content stream (see Section 3.7.2, “Resource Dictionaries”). 
Matrix  array  (Optional) An array of six numbers specifying the pattern matrix (see Section 4.6.1, “General Properties of Patterns”). Default value: the identity matrix [1 0 0 1 0 0]. 
The pattern dictionary's BBox, XStep, and YStep values are interpreted in the pattern coordinate system, and the graphics objects in the pattern's content stream are defined with respect to that coordinate system. The placement of pattern cells in the tiling is based on the location of one key pattern cell, which is then displaced by multiples of XStep and YStep to replicate the pattern. The origin of the key pattern cell coincides with the origin of the pattern coordinate system. The phase of the tiling can be controlled by the translation components of the Matrix entry in the pattern dictionary.
The first step in painting with a tiling pattern is to establish the pattern as the current color in the graphics state. Subsequent painting operations tile the painted areas with the pattern cell described by the pattern's content stream. To obtain the pattern cell, the application performs these steps:
1.  Saves the current graphics state (as if by invoking the q operator) 
2.  Installs the graphics state that was in effect at the beginning of the pattern's parent content stream, with the current transformation matrix altered by the pattern matrix as described in Section 4.6.1, “General Properties of Patterns” 
3.  Paints the graphics objects specified in the pattern's content stream 
4.  Restores the saved graphics state (as if by invoking the q operator) 
Note
The pattern's content stream should not set any of the devicedependent parameters in the graphics state (see Table 4.3 on page 182) because it may result in incorrect output.
A colored tiling pattern is a pattern whose color is selfcontained. In the course of painting the pattern cell, the pattern's content stream explicitly sets the color of each graphical element it paints. A single pattern cell can contain elements that are painted different colors; it can also contain sampled grayscale or color images. This type of pattern is identified by a pattern type of 1 and a paint type of 1 in the pattern dictionary.
When the current color space is a Pattern space, a colored tiling pattern can be selected as the current color by supplying its name as the single operand to the SCN or scn operator. This name must be the key of an entry in the Pattern subdictionary of the current resource dictionary (see Section 3.7.2, “Resource Dictionaries”), whose value is the stream object representing the pattern. Since the pattern defines its own color information, no additional operands representing color components are specified to SCN or scn. For example, if P1 is the name of a pattern resource in the current resource dictionary, the following code establishes it as the current nonstroking color:
/Pattern cs
/P1 scn
Subsequent executions of nonstroking painting operators, such as f (fill), Tj (show text), or Do (paint external object) with an image mask, use the designated pattern to tile the areas to be painted.
Example 4.23 defines a page (object 5) that paints three circles and a triangle using a colored tiling pattern (object 15) over a yellow background. The pattern consists of the symbols for the four suits of playing cards (spades, hearts, diamonds, and clubs), which are character glyphs taken from the ZapfDingbats font (see Section D.4, “ZapfDingbats Set and Encoding”); the pattern's content stream specifies the color of each glyph. Plate 8 shows the results.
Code View:
Scroll
/
Show All 5 0 obj % Page object << /Type/Page /Parent 2 0 R /Resources 10 0 R /Contents 30 0 R /CropBox [0 0 225 225] >> endobj 10 0 obj % Resource dictionary for page << /Pattern<</P1 150 R>> >> endobj 15 0 obj % Pattern definition << /Type /Pattern /PatternType 1 % Tiling pattern /PaintType 1 % Colored /TilingType 2 /BBox[0 0 100 100] /XStep 100 /YStep 100 /Resources 16 0 R /Matrix [0.40.00.00.40.00.0] /Length 183 >> stream BT % Begin text object /F1 1 Tf % Set text font and size 64 0 0 64 7.1771 2.4414 Tm % Set text matrix 0 Tc % Set character spacing 0 Tw % Set word spacing 1.00.00.0 rg % Set nonstroking color to red (\001)Tj % Show spade glyph 0.7478 0.007 TD % Move text position 0.0 1.0 0.0 rg % Set nonstroking color to green (\002) Tj % Show heart glyph 0.7323 0.7813 TD % Move text position 0.0 0.0 1.0 rg % Set nonstroking color to blue (\003) Tj % Show diamond glyph 0.6913 0.007 TD % Move text position 0.0 0.0 0.0 rg % Set nonstroking color to black (\004) Tj % Show club glyph ET % End text object endstream endobj 16 0 obj % Resource dictionary for pattern << /Font<</F120 0 R>> >> endobj 20 0 obj % Font for pattern << /Type /Font /Subtype /Type1 /Encoding 21 0 R /BaseFont /ZapfDingbats >> endobj 21 0 obj % Font encoding << /Type /Encoding /Differences[1 /a109 /a110 /a111 /a112] >> endobj 30 0 obj % Contents of page << /Length 1252 >> stream 0.0 G % Set stroking color to black 1.0 1.0 0.0 rg % Set nonstroking color to yellow 25 175 175 150 re % Construct rectangular path f % Fill path /Patterncs % Set pattern color space /P1 scn % Set pattern as nonstroking color 99.92 49.92 m % Start new path 99.92 77.52 77.52 99.92 49.92 99.92 c % Construct lowerleft circle 22.32 99.92 0.08 77.52 0.08 49.92 c 0.08 22.32 22.32 0.08 49.92 0.08 c 77.52 0.08 99.92 22.32 99.92 49.92 c B % Fill and stroke path 224.9649.92m % Start new path 224.96 77.52 202.56 99.92 174.96 99.92 % Construct lowerright circle 147.36 99.92 124.96 77.52 124.96 49.92 c 124.96 22.32 147.36 0.08 174.96 0.08 c 202.56 0.08 224.96 22.32 224.96 49.92 c B % Fill and stroke path 87.56 201.70 m % Start new path 63.66 187.90 55.46 157.32 69.26 133.40 c % Construct upper circle 83.06 109.50 113.66 101.30 137.56 115.10 c 161.46 128.90 169.66 159.50 155.86 183.40 c 142.06 207.30 111.46 215.50 87.56 201.70 c B % Fill and stroke path 50 50 m % Start new path 175 50 l % Construct triangular path 112.5 158.253 l b % Close, fill, and stroke path endstream endobj 
Several features of Example 4.23 are noteworthy:
The three circles and the triangle are painted with the same pattern. The pattern cells align, even though the circles and triangle are not aligned with respect to the pattern cell. For example, the position of the blue diamonds varies relative to the three circles.
The pattern cell does not completely cover the tile: it leaves the spaces between the glyphs unpainted. When the tiling pattern is used as a color, the existing background (the yellow rectangle) shows through these unpainted areas.
An uncolored tiling pattern is a pattern that has no inherent color: the color must be specified separately whenever the pattern is used. It provides a way to tile different regions of the page with pattern cells having the same shape but different colors. This type of pattern is identified by a pattern type of 1 and a paint type of 2 in the pattern dictionary. The pattern's content stream does not explicitly specify any colors; it can paint an image mask (see “Stencil Masking” on page 322) but no other kind of image.
A Pattern color space representing an uncolored tiling pattern requires a parameter: an object identifying the underlying color space in which the actual color of the pattern is to be specified. The underlying color space is given as the second element of the array that defines the Pattern color space. For example, the array
[/Pattern /DeviceRGB]
defines a Pattern color space with DeviceRGB as its underlying color space.
Note
The underlying color space cannot be another Pattern color space.
Operands supplied to the SCN or scn operator in such a color space must include a color value in the underlying color space, specified by one or more numeric color components, as well as the name of a pattern object representing an uncolored tiling pattern. For example, if the current resource dictionary (see Section 3.7.2, “Resource Dictionaries”) defines Cs3 as the name of a ColorSpace resource whose value is the Pattern color space shown above and P2 as a Pattern resource denoting an uncolored tiling pattern, the code
/Cs3 cs
0.30 0.75 0.21 /P2 scn
establishes Cs3 as the current nonstroking color space and P2 as the current nonstroking color, to be painted in the color represented by the specified components in the DeviceRGB color space. Subsequent executions of nonstroking painting operators, such as f (fill), Tj (show text), and Do (paint external object) with an image mask, use the designated pattern and color to tile the areas to be painted. The same pattern can be used repeatedly with a different color each time.
Example 4.24 is similar to Example 4.23 on page 167, except that it uses an uncolored tiling pattern to paint the three circles and the triangle, each in a different color (see Plate 9). To do so, it supplies four operands each time it invokes the scn operator: three numbers denoting the color components in the underlying DeviceRGB color space, along with the name of the pattern.
Code View:
Scroll
/
Show All 5 0 obj % Page object << /Type/Page /Parent 2 0 R /Resources 10 0 R /Contents 30 0 R /CropBox[0 0 225 225] >> endobj 10 0 obj % Resource dictionary for page << /ColorSpace << /Cs12 12 0 R>> /Pattern <</P1 15 0 R>> >> endobj 12 0 obj % Color space [/Pattern /DeviceRGB] endobj 150obj % Pattern definition << /Type/Pattern /PatternType1 % Tiling pattern /PaintType2 % Uncolored /TilingType2 /BBox [0 0 100 100] /XStep100 /YStep100 /Resources16 0 R /Matrix[0.4 0.0 0.0 0.4 0.0 0.0] /Length127 >> stream BT % Begin text object /F1 1Tf % Set text font and size 6400647.17712.4414Tm % Set text matrix 0Tc % Set character spacing 0Tw % Set word spacing (\001)Tj % Show spade glyph 0.74780.007TD % Move text position (\002)Tj % Show heart glyph 0.73230.7813TD % Move text position (\003)Tj % Show diamond glyph 0.69130.007TD % Move text position (\004)Tj % Show club glyph ET % End text object endstream endobj 160obj % Resource dictionary for pattern << /Font<</F120 0 R>> >> endobj 200obj % Font for pattern << /Type/Font /Subtype/Type1 /Encoding21 0 R /BaseFont/ZapfDingbats >> endobj 21 0 obj % Font encoding << /Type/Encoding /Differences [1/a 109/a 110/a 111/a112] >> endobj 300obj % Contents of page << /Length1316>> stream 0.0 G % Set stroking color to black 1.0 1.0 0.0 rg % Set nonstroking color to yellow 25 175 175 150 re % Construct rectangular path f % Fill path /Cs12 cs % Set pattern color space 0.77 0.20 0.00/P1 scn % Set nonstroking color and pattern 99.92 49.92 m % Start new path 99.92 77.52 77.52 99.92 49.92 99.92 c % Construct lowerleft circle 22.32 99.92 0.08 77.52 0.08 49.92 c 0.08 22.32 22.32 0.08 49.92 0.08 c 77.52 0.08 99.92 22.32 99.92 49.92 c B % Fill and stroke path 0.2 0.8 0.4/P1 scn % Change nonstroking color 224.96 49.92 m % Start new path 224.96 77.52 202.56 99.92 174.96 99.92 c % Construct lowerright circle 147.36 99.92 124.96 77.52 124.96 49.92 c 124.96 22.32 147.36 0.08 174.96 0.08 c 202.56 0.08 224.96 22.32 224.96 49.92 c B % Fill and stroke path 0.3 0.7 1.0/P1 scn % Change nonstroking color 87.56 201.70 m % Start new path 63.66 187.90 55.46 157.30 69.26 133.40 c % Construct upper circle 83.06 109.50 113.66 101.30 137.56 115.10 c 161.46 128.90 169.66 159.50 155.86 183.40 c 142.06 207.30 111.46 215.50 87.56 201.70 c B % Fill and stroke path 0.5 0.2 1.0/P1 scn % Change nonstroking color 50 50 m % Start new path 175 50 l % Construct triangular path 112.5 158.253 l b % Close, fill, and stroke path endstream endobj 
Shading patterns (PDF 1.3) provide a smooth transition between colors across an area to be painted, independent of the resolution of any particular output device and without specifying the number of steps in the color transition. Patterns of this type are described by pattern dictionaries with a pattern type of 2. Table 4.26 shows the contents of this type of dictionary.
KEY  TYPE  VALUE 

TYPE  name  (Optional) The type of PDF object that this dictionary describes; if present, must be Pattern for a pattern dictionary. 
PatternType  integer  (Required) A code identifying the type of pattern that this dictionary describes; must be 2 for a shading pattern. 
Shading  dictionary or stream  (Required) A shading object (see below) defining the shading pattern's gradient fill. The contents of the dictionary consist of the entries in Table 4.28 and those in one of Tables 4.29 to 4.34. 
Matrix  array  (Optional) An array of six numbers specifying the pattern matrix (see Section 4.6.1, “General Properties of Patterns”). Default value: the identity matrix [100 100]. 
ExtGState  dictionary  (Optional) A graphics state parameter dictionary (see Section 4.3.4, “Graphics State Parameter Dictionaries”) containing graphics state parameters to be put into effect temporarily while the shading pattern is painted. Any parameters that are not so specified are inherited from the graphics state that was in effect at the beginning of the content stream in which the pattern is defined as a resource. 
The most significant entry is Shading, whose value is a shading object defining the properties of the shading pattern's gradient fill. This is a complex “paint” that determines the type of color transition the shading pattern produces when painted across an area. A shading object may be a dictionary or a stream, depending on the type of shading; the term shading dictionary is used generically throughout this section to refer to either a dictionary object or the dictionary portion of a stream object. (Those shading objects that are streams are specifically identified as such in the descriptions of particular shading types; unless otherwise stated, they are understood to be simple dictionaries instead.)
By setting a shading pattern as the current color in the graphics state, a PDF content stream can use it with painting operators such as f (fill), S (stroke), Tj (show text), or Do (paint external object) with an image mask to paint a path, character glyph, or mask with a smooth color transition. When a shading is used in this way, the geometry of the gradient fill is independent of that of the object being painted.
When the area to be painted is a relatively simple shape whose geometry is the same as that of the gradient fill itself, the sh operator can be used instead of the usual painting operators. sh accepts a shading dictionary as an operand and applies the corresponding gradient fill directly to current user space. This operator does not require the creation of a pattern dictionary or a path and works without reference to the current color in the graphics state. Table 4.27 describes the sh operator.
Note
Patterns defined by type 2 pattern dictionaries do not tile. To create a tiling pattern containing a gradient fill, invoke the sh operator from within the content stream of a type 1 (tiling) pattern.
OPERANDS  OPERATOR  DESCRIPTION 

name  sh  (PDF 1.3) Paint the shape and color shading described by a shading dictionary, subject to the current clipping path. The current color in the graphics state is neither used nor altered. The effect is different from that of painting a path using a shading pattern as the current color.
name is the name of a shading dictionary resource in the Shading subdictionary of the current resource dictionary (see Section 3.7.2, “Resource Dictionaries”). All coordinates in the shading dictionary are interpreted relative to the current user space. (By contrast, when a shading dictionary is used in a type 2 pattern, the coordinates are expressed in pattern space.) All colors are interpreted in the color space identified by the shading dictionary's ColorSpace entry (see Table 4.28). The Background entry, if present, is ignored. This operator should be applied only to bounded or geometrically defined shadings. If applied to an unbounded shading, it paints the shading's gradient fill across the entire clipping region, which may be timeconsuming. 
A shading dictionary specifies details of a particular gradient fill, including the type of shading to be used, the geometry of the area to be shaded, and the geometry of the gradient fill. Various shading types are available, depending on the value of the dictionary's ShadingType entry:
Functionbased shadings (type 1) define the color of every point in the domain using a mathematical function (not necessarily smooth or continuous).
Axial shadings (type 2) define a color blend along a line between two points, optionally extended beyond the boundary points by continuing the boundary colors.
Radial shadings (type 3) define a blend between two circles, optionally extended beyond the boundary circles by continuing the boundary colors. This type of shading is commonly used to represent threedimensional spheres and cones.
Freeform Gouraudshaded triangle meshes (type 4) define a common construct used by many threedimensional applications to represent complex colored and shaded shapes. Vertices are specified in freeform geometry.
Latticeform Gouraudshaded triangle meshes (type 5) are based on the same geometrical construct as type 4 but with vertices specified as a pseudorectangular lattice.
Coons patch meshes (type 6) construct a shading from one or more color patches, each bounded by four cubic Bézier curves.
Tensorproduct patch meshes (type 7) are similar to type 6 but with additional control points in each patch, affording greater control over color mapping.
Table 4.28 shows the entries that all shading dictionaries share in common; entries specific to particular shading types are described in the relevant sections below.
Note
The term target coordinate space, used in many of the following descriptions, refers to the coordinate space into which a shading is painted. For shadings used with a type 2 pattern dictionary, this is the pattern coordinate space, discussed in Section 4.6.1, “General Properties of Patterns.” For shadings used directly with the sh operator, it is the current user space.
KEY  TYPE  VALUE  

ShadingType  integer  (Required) The shading type:  
1  Functionbased shading  
2  Axial shading  
3  Radial shading  
4  Freeform Gouraudshaded triangle mesh  
5  Latticeform Gouraudshaded triangle mesh  
6  Coons patch mesh  
7  Tensorproduct patch mesh  
ColorSpace  name or array  (Required) The color space in which color values are expressed. This may be any device, CIEbased, or special color space except a Pattern space. See “Color Space: Special Considerations” on page 178 for further information.  
Background  array  (Optional) An array of color components appropriate to the color space, specifying a single background color value. If present, this color is used, before any painting operation involving the shading, to fill those portions of the area to be painted that lie outside the bounds of the shading object. In the opaque imaging model, the effect is as if the painting operation were performed twice: first with the background color and then with the shading.
Note The background color is applied only when the shading is used as part of a shading pattern, not when it is painted directly with the sh operator.  
BBox  rectangle  (Optional) An array of four numbers giving the left, bottom, right, and top coordinates, respectively, of the shading's bounding box. The coordinates are interpreted in the shading's target coordinate space. If present, this bounding box is applied as a temporary clipping boundary when the shading is painted, in addition to the current clipping path and any other clipping boundaries in effect at that time.  
AntiAlias  boolean  (Optional) A flag indicating whether to filter the shading function to prevent aliasing artifacts. The shading operators sample shading functions at a rate determined by the resolution of the output device. Aliasing can occur if the function is not smooth—that is, if it has a high spatial frequency relative to the sampling rate. Antialiasing can be computationally expensive and is usually unnecessary, since most shading functions are smooth enough or are sampled at a high enough frequency to avoid aliasing effects. Antialiasing may not be implemented on some output devices, in which case this flag is ignored. Default value: false. 
Shading types 4 to 7 are defined by a stream containing descriptive data characterizing the shading's gradient fill. In these cases, the shading dictionary is also a stream dictionary and can contain any of the standard entries common to all streams (see Table 3.4 on page 38). In particular, it always includes a Length entry, which is required for all streams.
In addition, some shading dictionaries also include a Function entry whose value is a function object (dictionary or stream) defining how colors vary across the area to be shaded. In such cases, the shading dictionary usually defines the geometry of the shading, and the function defines the color transitions across that geometry. The function is required for some types of shading and optional for others. Functions are described in detail in Section 3.9, “Functions.”
Note
Discontinuous color transitions, or those with high spatial frequency, may exhibit aliasing effects when painted at low effective resolutions.
Conceptually, a shading determines a color value for each individual point within the area to be painted. In practice, however, the shading may actually be used to compute color values only for some subset of the points in the target area, with the colors of the intervening points determined by interpolation between the ones computed. Consumer applications are free to use this strategy as long as the interpolated color values approximate those defined by the shading to within the smoothness tolerance specified in the graphics state (see Section 6.5.2, “Smoothness Tolerance”). The ColorSpace entry common to all shading dictionaries not only defines the color space in which the shading specifies its color values but also determines the color space in which color interpolation is performed.
Note
Some shading types (4 to 7) perform interpolation on a parametric value supplied as input to the shading's color function, as described in the relevant sections below. This form of interpolation is conceptually distinct from the interpolation described here, which operates on the output color values produced by the color function and takes place within the shading's target color space.
Gradient fills between colors defined by most shadings are implemented using a variety of interpolation algorithms, and these algorithms are sensitive to the characteristics of the color space. Linear interpolation, for example, may have observably different results when applied in a DeviceCMYK color space than in a Lab color space, even if the starting and ending colors are perceptually identical. The difference arises because the two color spaces are not linear relative to each other. Shadings are rendered according to the following rules:
If ColorSpace is a device color space different from the native color space of the output device, color values in the shading are converted to the native color space using the standard conversion formulas described in Section 6.2, “Conversions among Device Color Spaces.” To optimize performance, these conversions may take place at any time (before or after any interpolation on the color values in the shading). Thus, shadings defined with device color spaces may have color gradient fills that are less accurate and somewhat devicedependent. (This does not apply to axial and radial shadings—shading types 2 and 3—because those shading types perform gradient fill calculations on a single variable and then convert to parametric colors.)
If ColorSpace is a CIEbased color space, all gradient fill calculations are performed in that space. Conversion to device colors occurs only after all interpolation calculations have been performed. Thus, the color gradients are deviceindependent for the colors generated at each point.
If ColorSpace is a Separation or DeviceN color space and the specified colorants are supported, no color conversion calculations are needed. If the specified colorants are not supported (so that the space's alternate color space must be used), gradient fill calculations are performed in the designated Separation or DeviceN color space before conversion to the alternate space. Thus, nonlinear tint transformation functions are accommodated for the best possible representation of the shading.
If ColorSpace is an Indexed color space, all color values specified in the shading are immediately converted to the base color space. Depending on whether the base color space is a device or CIEbased space, gradient fill calculations are performed as stated above. Interpolation never occurs in an Indexed color space, which is quantized and therefore inappropriate for calculations that assume a continuous range of colors. For similar reasons, an Indexed color space is not allowed in any shading whose color values are generated by a function; this rule applies to any shading dictionary that contains a Function entry.
In addition to the entries listed in Table 4.28, all shading dictionaries have entries specific to the type of shading they represent, as indicated by the value of their ShadingType entry. The following sections describe the available shading types and the dictionary entries specific to each.
In type 1 (functionbased) shadings, the color at every point in the domain is defined by a specified mathematical function. The function need not be smooth or continuous. This type is the most general of the available shading types and is useful for shadings that cannot be adequately described with any of the other types. Table 4.29 shows the shading dictionary entries specific to this type of shading, in addition to those common to all shading dictionaries (Table 4.28).
Note
This type of shading cannot be used with an Indexed color space.
KEY  TYPE  VALUE 

Domain  array  (Optional) An array of four numbers [x_{min} x_{max} y_{min} y_{max}] specifying the rectangular domain of coordinates over which the color function(s) are defined. Default value: [0.0 1.0 0.0 1.0]. 
Matrix  array  (Optional) An array of six numbers specifying a transformation matrix mapping the coordinate space specified by the Domain entry into the shading's target coordinate space. For example, to map the domain rectangle [0.0 1.0 0.0 1.0] to a 1inch square with lowerleft corner at coordinates (100, 100) in default user space, the Matrix value would be [72 0 0 72 100 100]. Default value: the identity matrix [1 0 0 1 0 0]. 
Function  function  (Required) A 2in, nout function or an array of n 2in, 1out functions (where n is the number of color components in the shading dictionary's color space). Each function's domain must be a superset of that of the shading dictionary. If the value returned by the function for a given color component is out of range, it is adjusted to the nearest valid value. 
The domain rectangle (Domain) establishes an internal coordinate space for the shading that is independent of the target coordinate space in which it is to be painted. The color function(s) (Function) specify the color of the shading at each point within this domain rectangle. The transformation matrix (Matrix) then maps the domain rectangle into a corresponding rectangle or parallelogram in the target coordinate space. Points within the shading's bounding box (BBox) that fall outside this transformed domain rectangle are painted with the shading's background color (Background); if the shading dictionary has no Background entry, such points are left unpainted. If the function is undefined at any point within the declared domain rectangle, an error may occur, even if the corresponding transformed point falls outside the shading's bounding box.
Type 2 (axial) shadings define a color blend that varies along a linear axis between two endpoints and extends indefinitely perpendicular to that axis. The shading may optionally be extended beyond either or both endpoints by continuing the boundary colors indefinitely. Table 4.30 shows the shading dictionary entries specific to this type of shading, in addition to those common to all shading dictionaries (Table 4.28).
Note
This type of shading cannot be used with an Indexed color space.
KEY  TYPE  VALUE 

Coords  array  (Required) An array of four numbers [x_{0} y_{0} x_{1} y_{1} ] specifying the starting and ending coordinates of the axis, expressed in the shading's target coordinate space. 
Domain  array  (Optional) An array of two numbers [t_{0} t_{1}] specifying the limiting values of a parametric variable t. The variable is considered to vary linearly between these two values as the color gradient varies between the starting and ending points of the axis. The variable t becomes the input argument to the color function(s). Default value: [0.0 1.0]. 
Function  function  (Required) A 1in, nout function or an array of n 1in, 1out functions (where n is the number of color components in the shading dictionary's color space). The function(s) are called with values of the parametric variable t in the domain defined by the Domain entry. Each function's domain must be a superset of that of the shading dictionary. If the value returned by the function for a given color component is out of range, it is adjusted to the nearest valid value. 
Extend  array  (Optional) An array of two boolean values specifying whether to extend the shading beyond the starting and ending points of the axis, respectively. Default value: [false false]. 
The color blend is accomplished by linearly mapping each point (x, y) along the axis between the endpoints (x_{0}, y_{0}) and (x_{1}, y_{1}) to a corresponding point in the domain specified by the shading dictionary's Domain entry. The points (0, 0) and (1, 0) in the domain correspond respectively to (x_{0}, y_{0}) and (x_{1}, y_{1}) on the axis. Since all points along a line in domain space perpendicular to the line from (0, 0) to (1, 0) have the same color, only the new value of x needs to be computed:
The value of the parametric variable t is then determined from x ' as follows:
For 0 ≤ x' ≤ 1, t = t_{0} + (t_{1} − t_{0}) × x'.
For x' < 0, if the first element of the Extend array is true, then t = t_{0} ; otherwise, t is undefined and the point is left unpainted.
For x' > 1, if the second element of the Extend array is true, then t = t_{1} ; otherwise, t is undefined and the point is left unpainted.
The resulting value of t is passed as input to the function(s) defined by the shading dictionary's Function entry, yielding the component values of the color with which to paint the point (x, y).
Plate 10 shows three examples of the use of an axial shading to fill a rectangle and display text. The area to be filled extends beyond the shading's bounding box. The shading is the same in all three cases, except for the values of the Background and Extend entries in the shading dictionary. In the first example, the shading is not extended at either end and no background color is specified; therefore, the shading is clipped to its bounding box at both ends. The second example still has no background color specified, but the shading is extended at both ends; the result is to fill the remaining portions of the filled area with the colors defined at the ends of the shading. In the third example, the shading is extended at both ends and a background color is specified; therefore, the background color is used for the portions of the filled area beyond the ends of the shading.
Type 3 (radial) shadings define a color blend that varies between two circles. Shadings of this type are commonly used to depict threedimensional spheres and cones. Shading dictionaries for this type of shading contain the entries shown in Table 4.31, as well as those common to all shading dictionaries (Table 4.28).
Note
This type of shading cannot be used with an Indexed color space.
KEY  TYPE  VALUE 

Coords  array  (Required) An array of six numbers [x_{0} y_{0} r_{0} x_{1} y_{1} r_{1}] specifying the centers and radii of the starting and ending circles, expressed in the shading's target coordinate space. The radii r_{0} and r_{1} must both be greater than or equal to 0. If one radius is 0, the corresponding circle is treated as a point; if both are 0, nothing is painted. 
Domain  array  (Optional) An array of two numbers [t_{0} t_{1}] specifying the limiting values of a parametric variable t. The variable is considered to vary linearly between these two values as the color gradient varies between the starting and ending circles. The variable t becomes the input argument to the color function(s). Default value: [0.0 1.0]. 
Function  function  (Required) A 1in, nout function or an array of n 1in, 1out functions (where n is the number of color components in the shading dictionary's color space). The function(s) are called with values of the parametric variable t in the domain defined by the shading dictionary's Domain entry. Each function's domain must be a superset of that of the shading dictionary. If the value returned by the function for a given color component is out of range, it is adjusted to the nearest valid value. 
Extend  array  (Optional) An array of two boolean values specifying whether to extend the shading beyond the starting and ending circles, respectively. Default value: [false false]. 
The color blend is based on a family of blend circles interpolated between the starting and ending circles that are defined by the shading dictionary's Coords entry. The blend circles are defined in terms of a subsidiary parametric variable
which varies linearly between 0.0 and 1.0 as t varies across the domain from t_{0} to t_{1}, as specified by the dictionary's Domain entry. The center and radius of each blend circle are given by the following parametric equations:
Each value of s between 0.0 and 1.0 determines a corresponding value of t, which is passed as the input argument to the function(s) defined by the shading dictionary's Function entry. This yields the component values of the color with which to fill the corresponding blend circle. For values of s not lying between 0.0 and 1.0, the boolean elements of the shading dictionary's Extend array determine whether and how the shading is extended. If the first of the two elements is true, the shading is extended beyond the defined starting circle to values of s less than 0.0; if the second element is true, the shading is extended beyond the defined ending circle to s values greater than 1.0.
Note that either of the starting and ending circles may be larger than the other. If the shading is extended at the smaller end, the family of blend circles continues as far as that value of s for which the radius of the blend circle r (s) … 0. If the shading is extended at the larger end, the blend circles continue as far as that s value for which r (s) is large enough to encompass the shading's entire bounding box (BBox). Extending the shading can thus cause painting to extend beyond the areas defined by the two circles themselves. The two examples in the rightmost column of Plate 11 depict the results of extending the shading at the smaller and larger ends, respectively.
Conceptually, all of the blend circles are painted in order of increasing values of s, from smallest to largest. Blend circles extending beyond the starting circle are painted in the same color defined by the shading dictionary's Function entry for the starting circle (t = t_{0}, s = 0.0). Blend circles extending beyond the ending circle are painted in the color defined for the ending circle (t = t_{1}, s = 1.0). The painting is opaque, with the color of each circle completely overlaying those preceding it. Therefore, if a point lies within more than one blend circle, its final color is that of the last of the enclosing circles to be painted, corresponding to the greatest value of s.
If one of the starting and ending circles entirely contains the other, the shading depicts a sphere, as in Plates 12 and 13. In Plate 12, the inner circle has zero radius; it is the starting circle in the figure on the left and the ending circle in the figure on the right. Neither shading is extended at either the smaller or larger end. In Plate 13, the inner circle in both figures has a nonzero radius and the shading is extended at the larger end. In each plate, a background color is specified for the figure on the right but not for the figure on the left.
If neither circle contains the other, the shading depicts a cone. If the starting circle is larger, the cone appears to point out of the page. If the ending circle is larger, the cone appears to point into the page (see Plate 11).
Example 4.25 paints the leafcovered branch shown in Plate 14. Each leaf is filled with the same radial shading (object number 5). The color function (object 10) is a stitching function (described in Section 3.9.3, “Type 3 (Stitching) Functions”) whose two subfunctions (objects 11 and 12) are both exponential interpolation functions (see Section 3.9.2, “Type 2 (Exponential Interpolation) Functions”). Each leaf is drawn as a path and then filled with the shading, using code such as that shown in Example 4.26 (where the name Sh1 is associated with object 5 by the Shading subdictionary of the current resource dictionary; see Section 3.7.2, “Resource Dictionaries”).
Code View:
Scroll
/
Show All 50obj % Shading dictionary << /ShadingType3 /ColorSpace/DeviceCMYK /Coords[0.0 0.0 0.096 0.0 0.0 1.000] % Concentric circles /Function10 0 R /Extend[truetrue] >> endobj 100obj % Color function << /FunctionType3 /Domain[0.0 1.0] /Functions[11 0 R12 0 R] /Bounds[0.708] /Encode[1.0 0.0 0.0 1.0] >> endobj 110obj % First subfunction << /FunctionType2 /Domain[0.0 1.0] /C0[0.929 0.357 1.000 0.298] /C1[0.631 0.278 1.000 0.027] /N1.048 >> endobj 120obj % Second subfunction << /FunctionType2 /Domain[0.0 1.0] /C0[0.929 0.357 1.000 0.298] /C1[0.941 0.400 1.000 0.102] /N1.374 >> endobj 
Code View:
Scroll
/
Show All 316.789 140.311 m % Move to start of leaf 303.222 146.388 282.966 136.518 279.122 121.983 c % Curved segment 277.322 120.182 l % Straight line 285.125 122.688 291.441 121.716 298.156 119.386 c % Curved segment 336.448 119.386 l % Straight line 331.072 128.643 323.346 137.376 316.789 140.311 c % Curved segment Wn % Set clipping path q % Save graphics state 27.7843 0.0000 0.0000 27.7843 310.2461 121.1521 cm % Set matrix /Sh1sh % Paint shading Q % Restore graphics state 
Type 4 shadings (freeform Gouraudshaded triangle meshes) are commonly used to represent complex colored and shaded threedimensional shapes. The area to be shaded is defined by a path composed entirely of triangles. The color at each vertex of the triangles is specified, and a technique known as Gouraud interpolation is used to color the interiors. The interpolation functions defining the shading may be linear or nonlinear. Table 4.32 shows the entries specific to this type of shading dictionary, in addition to those common to all shading dictionaries (Table 4.28) and stream dictionaries (Table 3.4 on page 38).
KEY  TYPE  VALUE 

BitsPerCoordinate  integer  (Required) The number of bits used to represent each vertex coordinate. Valid values are 1, 2, 4, 8, 12, 16, 24, and 32. 
BitsPerComponent  integer  (Required) The number of bits used to represent each color component. Valid values are 1, 2, 4, 8, 12, and 16. 
BitsPerFlag  integer  (Required) The number of bits used to represent the edge flag for each vertex (see below). Valid values of BitsPerFlag are 2, 4, and 8, but only the least significant 2 bits in each flag value are used. Valid values for the edge flag are 0, 1, and 2. 
Decode  array  (Required) An array of numbers specifying how to map vertex coordinates and color components into the appropriate ranges of values. The decoding method is similar to that used in image dictionaries (see “Decode Arrays” on page 316). The ranges are specified as follows:
Note that only one pair of c values should be specified if a Function entry is present. 
Function  function  (Optional) A 1in, nout function or an array of n 1in, 1out functions (where n is the number of color components in the shading dictionary's color space). If this entry is present, the color data for each vertex must be specified by a single parametric variable rather than by n separate color components. The designated function(s) are called with each interpolated value of the parametric variable to determine the actual color at each point. Each input value is forced into the range interval specified for the corresponding color component in the shading dictionary's Decode array. Each function's domain must be a superset of that interval. If the value returned by the function for a given color component is out of range, it is adjusted to the nearest valid value. This entry may not be used with an Indexed color space. 
Unlike shading types 1 to 3, types 4 to 7 are represented as streams. Each stream contains a sequence of vertex coordinates and color data that defines the triangle mesh. In a type 4 shading, each vertex is specified by the following values, in the order shown:
f is the vertex's edge flag (discussed below)
x and y are its horizontal and vertical coordinates
c_{1} … c_{n} are its color components
All vertex coordinates are expressed in the shading's target coordinate space. If the shading dictionary includes a Function entry, only a single parametric value, t, is permitted for each vertex in place of the color components c_{1} = c_{n} .
The edge flag associated with each vertex determines the way it connects to the other vertices of the triangle mesh. A vertex v_{a} with an edge flag value f_{a} … 0 begins a new triangle, unconnected to any other. At least two more vertices (v_{b} and v_{c}) must be provided, but their edge flags are ignored. These three vertices define a triangle (v_{a}, v_{b}, v_{c}), as shown in Figure 4.16.
Subsequent triangles are defined by a single new vertex combined with two vertices of the preceding triangle. Given triangle (v_{a}, v_{b}, v_{c}), where vertex v_{a} precedes vertex v_{b} in the data stream and v_{b} precedes v_{c}, a new vertex v_{d} can form a new triangle on side v_{bc} or side v_{ac}, as shown in Figure 4.17. (Side v_{ab} is assumed to be shared with a preceding triangle and therefore is not available for continuing the mesh.) If the edge flag is f_{d} … 1 (side v_{bc}), the next vertex forms the triangle (v_{b}, v_{c}, v_{d}); if the edge flag is f_{d} … 2 (side v_{ac}), the next vertex forms the triangle (v_{a}, v_{c}, v_{d}). An edge flag of f_{d} … 0 would start a new triangle, as described above.
Complex shapes can be created by using the edge flags to control the edge on which subsequent triangles are formed. Figure 4.18 shows two simple examples. Mesh 1 begins with triangle 1 and uses the following edge flags to draw each succeeding triangle:
(f_{a} = f_{b} = f_{c} = 0)
(f_{d} = 1)
(f_{c} = 1)
(f_{f} = 1)
(f_{g} = 1)
(f_{h} = 1)
(f_{i} = 2)
(f_{i} = 2)
(f_{k} = 2)
(f_{l} = 1)
(f_{m} = 1)
Mesh 2 again begins with triangle 1 and uses the following edge flags:
(f_{a} = f_{b} = f_{c} = 0)
(f_{d} = 1)
(f_{c} = 2)
(f_{f} = 2)
(f_{g} = 2)
(f_{h} = 2)
The stream must provide vertex data for a whole number of triangles with appropriate edge flags; otherwise, an error occurs.
The data for each vertex consists of the following items, reading in sequence from higherorder to lowerorder bit positions:
An edge flag, expressed in BitsPerFlag bits
A pair of horizontal and vertical coordinates, expressed in BitsPerCoordinate bits each
A set of n color components (where n is the number of components in the shading's color space), expressed in BitsPerComponent bits each, in the order expected by the sc operator
Each set of vertex data must occupy a whole number of bytes. If the total number of bits required is not divisible by 8, the last data byte for each vertex is padded at the end with extra bits, which are ignored. The coordinates and color values are decoded according to the Decode array in the same way as in an image dictionary (see “Decode Arrays” on page 316).
If the shading dictionary contains a Function entry, the color data for each vertex must be specified by a single parametric value t rather than by n separate color components. All linear interpolation within the triangle mesh is done using the t values. After interpolation, the results are passed to the function(s) specified in the Function entry to determine the color at each point.
Type 5 shadings (latticeform Gouraudshaded triangle meshes) are similar to type 4, but instead of using freeform geometry, their vertices are arranged in a pseudorectangular lattice, which is topologically equivalent to a rectangular grid. The vertices are organized into rows, which need not be geometrically linear (see Figure 4.19).
Table 4.33 shows the shading dictionary entries specific to this type of shading, in addition to those common to all shading dictionaries (Table 4.28) and stream dictionaries (Table 3.4 on page 38).
The data stream for a type 5 shading has the same format as for type 4, except that type 5 does not use edge flags to define the geometry of the triangle mesh. The data for each vertex thus consists of the following values, in the order shown:
where
x and y are the vertex's horizontal and vertical coordinates
c_{1} … c_{n} are its color components
KEY  TYPE  VALUE 

BitsPerCoordinate  integer  (Required) The number of bits used to represent each vertex coordinate. Valid values are 1, 2, 4, 8, 12, 16, 24, and 32. 
BitsPerComponent  integer  (Required) The number of bits used to represent each color component. Valid values are 1, 2, 4, 8, 12, and 16. 
VerticesPerRow  integer  (Required) The number of vertices in each row of the lattice; the value must be greater than or equal to 2. The number of rows need not be specified. 
Decode  array  (Required) An array of numbers specifying how to map vertex coordinates and color components into the appropriate ranges of values. The decoding method is similar to that used in image dictionaries (see “Decode Arrays” on page 316). The ranges are specified as follows:
Note that only one pair of c values should be specified if a Function entry is present. 
Function  function  (Optional) A 1in, nout function or an array of n 1in, 1out functions (where n is the number of color components in the shading dictionary's color space). If this entry is present, the color data for each vertex must be specified by a single parametric variable rather than by n separate color components. The designated function(s) are called with each interpolated value of the parametric variable to determine the actual color at each point. Each input value is forced into the range interval specified for the corresponding color component in the shading dictionary's Decode array. Each function's domain must be a superset of that interval. If the value returned by the function for a given color component is out of range, it is adjusted to the nearest valid value. This entry cannot be used with an Indexed color space. 
All vertex coordinates are expressed in the shading's target coordinate space. If the shading dictionary includes a Function entry, only a single parametric value, t, is permitted for each vertex in place of the color components c_{1} … c_{n} .
The VerticesPerRow entry in the shading dictionary gives the number of vertices in each row of the lattice. All of the vertices in a row are specified sequentially, followed by those for the next row. Given m rows of k vertices each, the triangles of the mesh are constructed using the following triplets of vertices, as shown in Figure 4.19:
See “Type 4 Shadings (FreeForm GouraudShaded Triangle Meshes)” on page 186 for further details on the format of the vertex data.
Type 6 shadings (Coons patch meshes) are constructed from one or more color patches, each bounded by four cubic Bézier curves. Degenerate Bézier curves are allowed and are useful for certain graphical effects. At least one complete patch must be specified.
A Coons patch generally has two independent aspects:
Colors are specified for each corner of the unit square, and bilinear interpolation is used to fill in colors over the entire unit square (see the upper figure in Plate 15).
Coordinates are mapped from the unit square into a foursided patch whose sides are not necessarily linear (see the lower figure in Plate 15). The mapping is continuous: the corners of the unit square map to corners of the patch and the sides of the unit square map to sides of the patch, as shown in Figure 4.20.
The sides of the patch are given by four cubic Bézier curves, C_{1}, C_{2}, D_{1}, and D_{2}, defined over a pair of parametric variables, u and v, that vary horizontally and vertically across the unit square. The four corners of the Coons patch satisfy the following equations:
Two surfaces can be described that are linear interpolations between the boundary curves. Along the u axis, the surface S_{C} is defined by
Along the v axis, the surface S_{D} is given by
A third surface is the bilinear interpolation of the four corners:
The coordinate mapping for the shading is given by the surface S, defined as
This defines the geometry of each patch. A patch mesh is constructed from a sequence of one or more such colored patches.
Patches can sometimes appear to fold over on themselves—for example, if a boundary curve intersects itself. As the value of parameter u or v increases in parameter space, the location of the corresponding pixels in device space may change direction so that new pixels are mapped onto previous pixels already mapped. If more than one point (u, v) in parameter space is mapped to the same point in device space, the point selected is the one with the largest value of v. If multiple points have the same v, the one with the largest value of u is selected. If one patch overlaps another, the patch that appears later in the data stream paints over the earlier one.
Note also that the patch is a control surface rather than a painting geometry. The outline of a projected square (that is, the painted area) might not be the same as the patch boundary if, for example, the patch folds over on itself, as shown in Figure 4.21.
Table 4.34 shows the shading dictionary entries specific to this type of shading, in addition to those common to all shading dictionaries (Table 4.28) and stream dictionaries (Table 3.4 on page 38).
KEY  TYPE  VALUE 

BitsPerCoordinate  integer  (Required) The number of bits used to represent each geometric coordinate. Valid values are 1, 2, 4, 8, 12, 16, 24, and 32. 
BitsPerComponent  integer  (Required) The number of bits used to represent each color component. Valid values are 1, 2, 4, 8, 12, and 16. 
BitsPerFlag  integer  (Required) The number of bits used to represent the edge flag for each patch (see below). Valid values of BitsPerFlag are 2, 4, and 8, but only the least significant 2 bits in each flag value are used. Valid values for the edge flag are 0, 1, 2, and 3. 
Decode  array  (Required) An array of numbers specifying how to map coordinates and color components into the appropriate ranges of values. The decoding method is similar to that used in image dictionaries (see “Decode Arrays” on page 316). The ranges are specified as follows:
Note that only one pair of c values should be specified if a Function entry is present. 
Function  function  (Optional) A 1in, nout function or an array of n 1in, 1out functions (where n is the number of color components in the shading dictionary's color space). If this entry is present, the color data for each vertex must be specified by a single parametric variable rather than by n separate color components. The designated function(s) are called with each interpolated value of the parametric variable to determine the actual color at each point. Each input value is forced into the range interval specified for the corresponding color component in the shading dictionary's Decode array. Each function's domain must be a superset of that interval. If the value returned by the function for a given color component is out of range, it is adjusted to the nearest valid value. This entry may not be used with an Indexed color space. 
The data stream provides a sequence of Bézier control points and color values that define the shape and colors of each patch. All of a patch's control points are given first, followed by the color values for its corners. Note that this differs from a triangle mesh (shading types 4 and 5), in which the coordinates and color of each vertex are given together. All control point coordinates are expressed in the shading's target coordinate space. See “Type 4 Shadings (FreeForm GouraudShaded Triangle Meshes))” on page 186 for further details on the format of the data.
As in freeform triangle meshes (type 4), each patch has an edge flag that indicates which edge, if any, it shares with the previous patch. An edge flag of 0 begins a new patch, unconnected to any other. This must be followed by 12 pairs of coordinates, x_{1} y_{1} x_{2} y_{2} … x_{12} y_{12}, which specify the Bézier control points that define the four boundary curves. Figure 4.22 shows how these control points correspond to the cubic Bézier curves C_{1}, C_{2}, D_{1}, and D_{2} identified in Figure 4.20 on page 194. Color values are given for the four corners of the patch, in the same order as the control points corresponding to the corners. Thus, c_{1} is the color at coordinates (x_{1}, y_{1}), c_{2} at (x_{4}, y_{4}), c_{3} at (x_{7}, y_{7}), and c_{4} at (x_{10}, y_{10}), as shown in the figure.
Figure 4.22 also shows how nonzero values of the edge flag (f = 1, 2, or 3) connect a new patch to one of the edges of the previous patch. In this case, some of the previous patch's control points serve implicitly as control points for the new patch as well (see Figure 4.23), and therefore are not explicitly repeated in the data stream. Table 4.35 summarizes the required data values for various values of the edge flag.
If the shading dictionary contains a Function entry, the color data for each corner of a patch must be specified by a single parametric value t rather than by n separate color components c_{1} … c_{n} . All linear interpolation within the mesh is done using the t values. After interpolation, the results are passed to the function(s) specified in the Function entry to determine the color at each point.
EDGE FLAG  NEXT SET OF DATA VALUES  

f = 0  x_{1}
y_{1}
x_{2}
y_{2}
x_{3}
y_{3}
x_{4}
y_{4}
x_{5}
y_{5}
x_{6}
y_{6}
x_{7} y_{7} x_{8} y_{8} x_{9} y_{9} x_{10} y_{10} x_{11} y_{11} x_{12} y_{12} c_{1} c_{2} c_{3} c_{4} New patch; no implicit values  
f = 1  x_{5} y_{5} x_{6} y_{6} x_{7} y_{7} x_{8} y_{8} x_{9} y_{9} x_{10} y_{10} x_{11} y_{11} x_{12} y_{12} c_{3} c_{4}  
Implicit values:  
(x_{1}, y_{1}) = (x_{4}, y_{4}) previous
(x_{2}, y_{2}) = (x_{5}, y_{5}) previous (x_{3}, y_{3}) = (x_{6}, y_{6}) previous (x_{4}, y_{4}) = (x_{7}, y_{7}) previous  c_{1} = c_{2} previous c_{2} = c_{3} previous  
f = 2  x_{5} y_{5} x_{6} y_{6} x_{7} y_{7} x_{8} y_{8} x_{9} y_{9} x_{10} y_{10} x_{11} y_{11} x_{12} y_{12} c_{3} c_{4}  
Implicit values:  
(x_{1}, y_{1}) = (x_{7}, y_{7}) previous
(x_{2}, y_{2}) = (x_{8}, y_{8}) previous (x_{3}, y_{3}) = (x_{9}, y_{9}) previous (x_{4}, y_{4}) = (x_{10}, y_{10}) previous  c_{1} = c_{3} previous c_{2} = c_{4} previous  
f = 3  x_{5} y_{5} x_{6} y_{6} x_{7} y_{7} x_{8} y_{8} x_{9} y_{9} x_{10} y_{10} x_{11} y_{11} x_{12} y_{12} c_{3} c_{4}  
Implicit values:  
(x_{1}, y_{1}) = (x_{10}, y_{10}) previous
(x_{2}, y_{2}) = (x_{11}, y_{11}) previous (x_{3}, y_{3}) = (x_{12}, y_{12}) previous (x_{4}, y_{4}) = (x_{1}, y_{1}) previous  c_{1} = c_{4} previous c_{2} = c_{1} previous 
Type 7 shadings (tensorproduct patch meshes) are identical to type 6, except that they are based on a bicubic tensorproduct patch defined by 16 control points instead of the 12 control points that define a Coons patch. The shading dictionaries representing the two patch types differ only in the value of the ShadingType entry and in the number of control points specified for each patch in the data stream. Although the Coons patch is more concise and easier to use, the tensorproduct patch affords greater control over color mapping.
Note
The data format for type 7 shadings (as for types 4 through 6) is the same in PDF as it is in PostScript. However, the numbering and order of control points was described incorrectly in the first printing of the PostScript Language Reference, Third Edition. That description has been corrected here.
Like the Coons patch mapping, the tensorproduct patch mapping is controlled by the location and shape of four cubic Bézier curves marking the boundaries of the patch. However, the tensorproduct patch has four additional, “internal” control points to adjust the mapping. The 16 control points can be arranged in a 4by4 array indexed by row and column, as follows (see Figure 4.24):
p_{03}  p_{13}  p_{23}  p_{33} 
p_{02}  p_{12}  p_{22}  p_{32} 
p_{01}  p_{11}  p_{21}  p_{31} 
p_{00}  p_{10}  p_{20}  p_{30} 
As in a Coons patch mesh, the geometry of the tensorproduct patch is described by a surface defined over a pair of parametric variables, u and v, which vary horizontally and vertically across the unit square. The surface is defined by the equation
where p_{ij} is the control point in column i and row j of the tensor, and B_{i} and B_{j} are the Bernstein polynomials
Since each point p_{ij} is actually a pair of coordinates (x_{ij}, y_{ij}), the surface can also be expressed as
The geometry of the tensorproduct patch can be visualized in terms of a cubic Bézier curve moving from the bottom boundary of the patch to the top. At the bottom and top, the control points of this curve coincide with those of the patch's bottom (p_{00} … p_{30}) and top (p_{03} … p_{33}) boundary curves, respectively. As the curve moves from the bottom edge of the patch to the top, each of its four control points follows a trajectory that is in turn a cubic Bézier curve defined by the four control points in the corresponding column of the array. That is, the starting point of the moving curve follows the trajectory defined by control points p_{00} … p_{03}, the trajectory of the ending point is defined by points p_{30} … p_{33}, and those of the two intermediate control points by p_{10} … p_{13} and p_{20} … p_{23} . Equivalently, the patch can be considered to be traced by a cubic Bézier curve moving from the left edge to the right, with its control points following the trajectories defined by the rows of the coordinate array instead of the columns.
The Coons patch (type 6) is actually a special case of the tensorproduct patch (type 7) in which the four internal control points (p_{11}, p_{12}, p_{21}, p_{22}) are implicitly defined by the boundary curves. The values of the internal control points are given by these equations:
In the more general tensorproduct patch, the values of these four points are unrestricted.
The coordinates of the control points in a tensorproduct patch are actually specified in the shading's data stream in the following order:
4  5  6  7 
3  14  15  8 
2  13  16  9 
1  12  11  10 
All control point coordinates are expressed in the shading's target coordinate space. These are followed by the color values for the four corners of the patch, in the same order as the corners themselves. If the patch's edge flag f is 0, all 16 control points and four corner colors must be explicitly specified in the data stream. If f is 1, 2, or 3, the control points and colors for the patch's shared edge are implicitly understood to be the same as those along the specified edge of the previous patch and are not repeated in the data stream. Table 4.36 summarizes the data values for various values of the edge flag f, expressed in terms of the row and column indices used in Figure 4.24 above. See “Type 4 Shadings (FreeForm GouraudShaded Triangle Meshes)” on page 286 for further details on the format of the data.
EDGE FLAG  NEXT SET OF DATA VALUES  

f = 0  x_{00}
y_{00}
x_{01}
y_{01}
x_{02}
y_{02}
x_{03}
y_{03}
x_{13}
y_{13}
x_{23}
y_{23}
x_{33}
y_{33}
x_{32}
y_{32}
x_{31} y_{31} x_{30} y_{30} x_{20} y_{20} x_{10} y_{10} x_{11} y_{11} x_{12} y_{12} x_{22} y_{22} x_{21} y_{21} c_{00} c_{03} c_{33} c_{30} New patch; no implicit values  
f = 1  x_{13}
y_{13}
x_{23}
y_{23}
x_{33}
y_{33}
x_{32}
y_{32}
x_{31}
y_{31}
x_{30}
y_{30}
x_{20} y_{20} x_{10} y_{10} x_{11} y_{11} x_{12} y_{12} x_{22} y_{22} x_{21} y_{21} c_{33} c_{30} Implicit values:  
(x_{00}, y_{00}) = (x_{03}, y_{03}) previous
(x_{01}, y_{01}) = (x_{13}, y_{13}) previous (x_{02}, y_{02}) = (x_{23}, y_{23}) previous (x_{03}, y_{03}) = (x_{33}, y_{33}) previous  c_{00} = c_{03} previous c_{03} = c_{33} previous  
f = 2  x_{13}
y_{13}
x_{23}
y_{23}
x_{33}
y_{33}
x_{32}
y_{32}
x_{31}
y_{31}
x_{30}
y_{30}
x_{20} y_{20} x_{10} y_{10} x_{11} y_{11} x_{12} y_{12} x_{22} y_{22} x_{21} y_{21} c_{33} c_{30} Implicit values:  
(x_{00}, y_{00}) = (x_{33}, y_{33}) previous
(x_{01}, y_{01}) = (x_{32}, y_{32}) previous (x_{02}, y_{02}) = (x_{31}, y_{31}) previous (x_{03}, y_{03}) = (x_{30}, y_{30}) previous  c_{00} = c_{33} previous c_{03} = c_{30} previous  
f = 3  x_{13}
y_{13}
x_{23}
y_{23}
x_{33}
y_{33}
x_{32}
y_{32}
x_{31}
y_{31}
x_{30}
y_{30}
x_{20} y_{20} x_{10} y_{10} x_{11} y_{11} x_{12} y_{12} x_{22} y_{22} x_{21} y_{21} c_{33} c_{30} Implicit values:  
(x_{00}, y_{00}) = (x_{30}, y_{30}) previous
(x_{01}, y_{01}) = (x_{20}, y_{20}) previous (x_{02}, y_{02}) = (x_{10}, y_{10}) previous (x_{03}, y_{03}) = (x_{00}, y_{00}) previous  c_{00} = c_{30} previous c_{03} = c_{00} previous 