• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

4.6. Patterns

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 device-dependent.


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.

4.6.1. General Properties of Patterns

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.


4.6.2. Tiling Patterns

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

Table 4.25. Additional entries specific to a type 1 pattern dictionary
KEYTYPEVALUE
Typename(Optional) The type of PDF object that this dictionary describes; if present, must be Pattern for a pattern dictionary.
PatternTypeinteger(Required) A code identifying the type of pattern that this dictionary describes; must be 1 for a tiling pattern.
PaintTypeinteger(Required) A code that determines how the color of the pattern cell is to be specified:
  1. Colored tiling pattern. The pattern's content stream specifies the colors used to paint the pattern cell. When the content stream begins execution, the current color is the one that was initially in effect in the pattern's parent content stream. (This is similar to the definition of the pattern matrix; see Section 4.6.1, “General Properties of Patterns.”)

  2. Uncolored tiling pattern. The pattern's content stream does not specify any color information. Instead, the entire pattern cell is painted with a separately specified color each time the pattern is used. Essentially, the content stream describes a stencil through which the current color is to be poured. The content stream must not invoke operators that specify colors or other color-related parameters in the graphics state; otherwise, an error occurs (see Section 4.5.7, “Color Operators”). The content stream may paint an image mask, however, since it does not specify any color information (see “Stencil Masking” on page 322).

TilingTypeinteger(Required) A code that controls adjustments to the spacing of tiles relative to the device pixel grid:
  1. Constant spacing. Pattern cells are spaced consistently—that is, by a multiple of a device pixel. To achieve this, the application may need to distort the pattern cell slightly by making small adjustments to XStep, YStep, and the transformation matrix. The amount of distortion does not exceed 1 device pixel.

  2. No distortion. The pattern cell is not distorted, but the spacing between pattern cells may vary by as much as 1 device pixel, both horizontally and vertically, when the pattern is painted. This achieves the spacing requested by XStep and YStep on average but not necessarily for each individual pattern cell.

  3. Constant spacing and faster tiling. Pattern cells are spaced consistently as in tiling type 1 but with additional distortion permitted to enable a more efficient implementation.

Bboxrectangle(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.
XStepnumber(Required) The desired horizontal spacing between pattern cells, measured in the pattern coordinate system.
YStepnumber(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.
Resourcesdictionary(Required) A resource dictionary containing all of the named resources required by the pattern's content stream (see Section 3.7.2, “Resource Dictionaries”).
Matrixarray(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 device-dependent parameters in the graphics state (see Table 4.3 on page 182) because it may result in incorrect output.


Colored Tiling Patterns

A colored tiling pattern is a pattern whose color is self-contained. 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.

Example 4.23.

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 lower-left 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 lower-right 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.

Uncolored Tiling Patterns

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.

Example 4.24.

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.7478-0.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 lower-left 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 lower-right 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


					  

4.6.3. Shading Patterns

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.

Table 4.26. Entries in a type 2 pattern dictionary
KEYTYPEVALUE
TYPEname(Optional) The type of PDF object that this dictionary describes; if present, must be Pattern for a pattern dictionary.
PatternTypeinteger(Required) A code identifying the type of pattern that this dictionary describes; must be 2 for a shading pattern.
Shadingdictionary 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.
Matrixarray(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].
ExtGStatedictionary(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.

Shading Operator

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.


Table 4.27. Shading operator
OPERANDSOPERATORDESCRIPTION
namesh(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 time-consuming.


Shading Dictionaries

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:

  • Function-based 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 three-dimensional spheres and cones.

  • Free-form Gouraud-shaded triangle meshes (type 4) define a common construct used by many three-dimensional applications to represent complex colored and shaded shapes. Vertices are specified in free-form geometry.

  • Lattice-form Gouraud-shaded 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.

  • Tensor-product 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.


Table 4.28. Entries common to all shading dictionaries
KEYTYPEVALUE
ShadingTypeinteger(Required) The shading type:
   1Function-based shading
   2Axial shading
   3Radial shading
   4Free-form Gouraud-shaded triangle mesh
   5Lattice-form Gouraud-shaded triangle mesh
   6Coons patch mesh
   7Tensor-product patch mesh
ColorSpacename or array(Required) The color space in which color values are expressed. This may be any device, CIE-based, or special color space except a Pattern space. See “Color Space: Special Considerations” on page 178 for further information.
Backgroundarray(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.

BBoxrectangle(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.
AntiAliasboolean(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. Anti-aliasing 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. Anti-aliasing 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.


Color Space: Special Considerations

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 device-dependent. (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 CIE-based 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 device-independent 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 CIE-based 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.

Shading Types

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.

Type 1 (Function-Based) Shadings

In type 1 (function-based) 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.


Table 4.29. Additional entries specific to a type 1 shading dictionary
KEYTYPEVALUE
Domainarray(Optional) An array of four numbers [xmin xmax ymin ymax] specifying the rectangular domain of coordinates over which the color function(s) are defined. Default value: [0.0 1.0 0.0 1.0].
Matrixarray(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 1-inch square with lower-left 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].
Functionfunction(Required) A 2-in, n-out function or an array of n 2-in, 1-out 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

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.


Table 4.30. Additional entries specific to a type 2 shading dictionary
KEYTYPEVALUE
Coordsarray(Required) An array of four numbers [x0 y0 x1 y1 ] specifying the starting and ending coordinates of the axis, expressed in the shading's target coordinate space.
Domainarray(Optional) An array of two numbers [t0 t1] 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].
Functionfunction(Required) A 1-in, n-out function or an array of n 1-in, 1-out 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.
Extendarray(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 (x0, y0) and (x1, y1) 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 (x0, y0) and (x1, y1) 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 = t0 + (t1t0) × x'.

  • For x' < 0, if the first element of the Extend array is true, then t = t0 ; 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 = t1 ; 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

Type 3 (radial) shadings define a color blend that varies between two circles. Shadings of this type are commonly used to depict three-dimensional 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.


Table 4.31. Additional entries specific to a type 3 shading dictionary
KEYTYPEVALUE
Coordsarray(Required) An array of six numbers [x0 y0 r0 x1 y1 r1] specifying the centers and radii of the starting and ending circles, expressed in the shading's target coordinate space. The radii r0 and r1 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.
Domainarray(Optional) An array of two numbers [t0 t1] 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].
Functionfunction(Required) A 1-in, n-out function or an array of n 1-in, 1-out 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.
Extendarray(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 t0 to t1, 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 = t0, s = 0.0). Blend circles extending beyond the ending circle are painted in the color defined for the ending circle (t = t1, 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.

Note the following points:

  • 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 leaf-covered 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”).

Example 4.25.

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


					  

Example 4.26.

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 (Free-Form Gouraud-Shaded Triangle Meshes)

Type 4 shadings (free-form Gouraud-shaded triangle meshes) are commonly used to represent complex colored and shaded three-dimensional 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).

Table 4.32. Additional entries specific to a type 4 shading dictionary
KEYTYPEVALUE
BitsPerCoordinateinteger(Required) The number of bits used to represent each vertex coordinate. Valid values are 1, 2, 4, 8, 12, 16, 24, and 32.
BitsPerComponentinteger(Required) The number of bits used to represent each color component. Valid values are 1, 2, 4, 8, 12, and 16.
BitsPerFlaginteger(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.
Decodearray(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:

[xmin xmax ymin ymax c1,min c1,max…cn,min cn,max]

Note that only one pair of c values should be specified if a Function entry is present.
Functionfunction(Optional) A 1-in, n-out function or an array of n 1-in, 1-out 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:


where

f is the vertex's edge flag (discussed below)

x and y are its horizontal and vertical coordinates

c1cn 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 c1 = cn .

The edge flag associated with each vertex determines the way it connects to the other vertices of the triangle mesh. A vertex va with an edge flag value fa … 0 begins a new triangle, unconnected to any other. At least two more vertices (vb and vc) must be provided, but their edge flags are ignored. These three vertices define a triangle (va, vb, vc), as shown in Figure 4.16.

Figure 4.16. Starting a new triangle in a free-form Gouraud-shaded triangle mesh


Subsequent triangles are defined by a single new vertex combined with two vertices of the preceding triangle. Given triangle (va, vb, vc), where vertex va precedes vertex vb in the data stream and vb precedes vc, a new vertex vd can form a new triangle on side vbc or side vac, as shown in Figure 4.17. (Side vab is assumed to be shared with a preceding triangle and therefore is not available for continuing the mesh.) If the edge flag is fd … 1 (side vbc), the next vertex forms the triangle (vb, vc, vd); if the edge flag is fd … 2 (side vac), the next vertex forms the triangle (va, vc, vd). An edge flag of fd … 0 would start a new triangle, as described above.

Figure 4.17. Connecting triangles in a free-form Gouraud-shaded triangle mesh


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:

  1. (fa = fb = fc = 0)

  2. (fd = 1)

  3. (fc = 1)

  4. (ff = 1)

  5. (fg = 1)

  6. (fh = 1)

  7. (fi = 2)

  8. (fi = 2)

  9. (fk = 2)

  10. (fl = 1)

  11. (fm = 1)

Figure 4.18. Varying the value of the edge flag to create different shapes


Mesh 2 again begins with triangle 1 and uses the following edge flags:

  1. (fa = fb = fc = 0)

  2. (fd = 1)

  3. (fc = 2)

  4. (ff = 2)

  5. (fg = 2)

  6. (fh = 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 higher-order to lower-order 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 (Lattice-Form Gouraud-Shaded Triangle Meshes)

Type 5 shadings (lattice-form Gouraud-shaded triangle meshes) are similar to type 4, but instead of using free-form 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).

Figure 4.19. Lattice-form triangle meshes


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

c1cn are its color components

Table 4.33. Additional entries specific to a type 5 shading dictionary
KEYTYPEVALUE
BitsPerCoordinateinteger(Required) The number of bits used to represent each vertex coordinate. Valid values are 1, 2, 4, 8, 12, 16, 24, and 32.
BitsPerComponentinteger(Required) The number of bits used to represent each color component. Valid values are 1, 2, 4, 8, 12, and 16.
VerticesPerRowinteger(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.
Decodearray(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:

[xmin xmax ymin ymax c1,min c1,max…cn,min cn,max]

Note that only one pair of c values should be specified if a Function entry is present.
Functionfunction(Optional) A 1-in, n-out function or an array of n 1-in, 1-out 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 c1cn .

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 (Free-Form Gouraud-Shaded Triangle Meshes)” on page 186 for further details on the format of the vertex data.

Type 6 Shadings (Coons Patch Meshes)

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 four-sided 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.

    Figure 4.20. Coordinate mapping from a unit square to a four-sided Coons patch

The sides of the patch are given by four cubic Bézier curves, C1, C2, D1, and D2, 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 SC is defined by


Along the v axis, the surface SD 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.

Figure 4.21. Painted area and boundary of a Coons patch


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).

Table 4.34. Additional entries specific to a type 6 shading dictionary
KEYTYPEVALUE
BitsPerCoordinateinteger(Required) The number of bits used to represent each geometric coordinate. Valid values are 1, 2, 4, 8, 12, 16, 24, and 32.
BitsPerComponentinteger(Required) The number of bits used to represent each color component. Valid values are 1, 2, 4, 8, 12, and 16.
BitsPerFlaginteger(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.
Decodearray(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:

[xmin xmaxymin ymaxc1,min c1,max…cn,min cn,max]

Note that only one pair of c values should be specified if a Function entry is present.
Functionfunction(Optional) A 1-in, n-out function or an array of n 1-in, 1-out 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 (Free-Form Gouraud-Shaded Triangle Meshes))” on page 186 for further details on the format of the data.

As in free-form 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, x1 y1 x2 y2x12 y12, 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 C1, C2, D1, and D2 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, c1 is the color at coordinates (x1, y1), c2 at (x4, y4), c3 at (x7, y7), and c4 at (x10, y10), as shown in the figure.

Figure 4.22. Color values and edge flags in Coons patch meshes


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.

Figure 4.23. Edge connections in a Coons patch mesh


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 c1cn . 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.

Table 4.35. Data values in a Coons patch mesh
EDGE FLAGNEXT SET OF DATA VALUES
f = 0x1 y1 x2 y2 x3 y3 x4 y4 x5 y5 x6 y6

x7 y7 x8 y8 x9 y9 x10 y10 x11 y11 x12 y12

c1 c2 c3 c4

New patch; no implicit values
f = 1x5 y5 x6 y6 x7 y7 x8 y8 x9 y9 x10 y10 x11 y11 x12 y12 c3 c4
 Implicit values:
 (x1, y1) = (x4, y4) previous

(x2, y2) = (x5, y5) previous

(x3, y3) = (x6, y6) previous

(x4, y4) = (x7, y7) previous
c1 = c2 previous c2 = c3 previous
f = 2x5 y5 x6 y6 x7 y7 x8 y8 x9 y9 x10 y10 x11 y11 x12 y12 c3 c4
 Implicit values:
 (x1, y1) = (x7, y7) previous

(x2, y2) = (x8, y8) previous

(x3, y3) = (x9, y9) previous

(x4, y4) = (x10, y10) previous
c1 = c3 previous c2 = c4 previous
f = 3x5 y5 x6 y6 x7 y7 x8 y8 x9 y9 x10 y10 x11 y11 x12 y12 c3 c4
 Implicit values:
 (x1, y1) = (x10, y10) previous

(x2, y2) = (x11, y11) previous

(x3, y3) = (x12, y12) previous

(x4, y4) = (x1, y1) previous
c1 = c4 previous c2 = c1 previous


Type 7 Shadings (Tensor-Product Patch Meshes)

Type 7 shadings (tensor-product patch meshes) are identical to type 6, except that they are based on a bicubic tensor-product 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 tensor-product 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 tensor-product patch mapping is controlled by the location and shape of four cubic Bézier curves marking the boundaries of the patch. However, the tensor-product patch has four additional, “internal” control points to adjust the mapping. The 16 control points can be arranged in a 4-by-4 array indexed by row and column, as follows (see Figure 4.24):

Figure 4.24. Control points in a tensor-product patch


p03p13p23p33
p02p12p22p32
p01p11p21p31
p00p10p20p30


As in a Coons patch mesh, the geometry of the tensor-product 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 pij is the control point in column i and row j of the tensor, and Bi and Bj are the Bernstein polynomials


Since each point pij is actually a pair of coordinates (xij, yij), the surface can also be expressed as


The geometry of the tensor-product 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 (p00p30) and top (p03p33) 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 p00p03, the trajectory of the ending point is defined by points p30p33, and those of the two intermediate control points by p10p13 and p20p23 . 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 tensor-product patch (type 7) in which the four internal control points (p11, p12, p21, p22) are implicitly defined by the boundary curves. The values of the internal control points are given by these equations:


In the more general tensor-product patch, the values of these four points are unrestricted.

The coordinates of the control points in a tensor-product patch are actually specified in the shading's data stream in the following order:

4567
314158
213169
1121110


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 (Free-Form Gouraud-Shaded Triangle Meshes) on page 286 for further details on the format of the data.

Table 4.36. Data values in a tensor-product patch mesh
EDGE FLAGNEXT SET OF DATA VALUES
f = 0x00 y00 x01 y01 x02 y02 x03 y03 x13 y13 x23 y23 x33 y33 x32 y32

x31 y31 x30 y30 x20 y20 x10 y10 x11 y11 x12 y12 x22 y22 x21 y21

c00 c03 c33 c30

New patch; no implicit values
f = 1x13 y13 x23 y23 x33 y33 x32 y32 x31 y31 x30 y30

x20 y20 x10 y10 x11 y11 x12 y12 x22 y22 x21 y21

c33 c30

Implicit values:
(x00, y00) = (x03, y03) previous

(x01, y01) = (x13, y13) previous

(x02, y02) = (x23, y23) previous

(x03, y03) = (x33, y33) previous
c00 = c03 previous c03 = c33 previous
f = 2x13 y13 x23 y23 x33 y33 x32 y32 x31 y31 x30 y30

x20 y20 x10 y10 x11 y11 x12 y12 x22 y22 x21 y21

c33 c30

Implicit values:
(x00, y00) = (x33, y33) previous

(x01, y01) = (x32, y32) previous

(x02, y02) = (x31, y31) previous

(x03, y03) = (x30, y30) previous
c00 = c33 previous c03 = c30 previous
f = 3x13 y13 x23 y23 x33 y33 x32 y32 x31 y31 x30 y30

x20 y20 x10 y10 x11 y11 x12 y12 x22 y22 x21 y21

c33 c30

Implicit values:
(x00, y00) = (x30, y30) previous

(x01, y01) = (x20, y20) previous

(x02, y02) = (x10, y10) previous

(x03, y03) = (x00, y00) previous
c00 = c30 previous c03 = c00 previous


  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint