PDF Reference sixth edition, Adobe Portable Document Format Version 1.7 (book 1) — page 8

290
CHAPTER 4
Graphics
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; un-
less 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 col-
or 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 sec-
tions on individual pattern types.
291
SECTION 4.6
Patterns
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 287).
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 pat-
tern’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 con-
tent stream establishes the pattern coordinate space, within which all graphics ob-
jects in the pattern are interpreted.
For example, if a pattern is used on a page, the pattern appears in the Pattern sub-
dictionary 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 rota-
tion and scaling, have no effect on the pattern; it maintains its original relation-
ship 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 ma-
trix maps pattern space to the form’s default user space (that is, the form co-
ordinate 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.
292
CHAPTER 4
Graphics
The pattern cell can include graphical elements such as filled areas, text, and sam-
pled 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 fig-
ures 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 en-
tries common to all streams (see Table 3.4 on page 62), 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
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 de-
scribes; 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:
1
Colored tiling pattern. The pattern’s content stream specifies the col-
ors used to paint the pattern cell. When the content stream begins ex-
ecution, 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 Pat-
terns.”)
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 col-
or 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
350).
293
SECTION 4.6
Patterns
KEY
TYPE
VALUE
TilingType
integer
(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 distor-
tion 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 neces-
sarily 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.
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 Dic-
tionaries”).
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 pat-
tern 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
294
CHAPTER 4
Graphics
in the tiling is based on the location of one key pattern cell, which is then dis-
placed 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 cur-
rent 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 212) 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 subdic-
tionary of the current resource dictionary (see Section 3.7.2, “Resource Diction-
aries”), whose value is the stream object representing the pattern. Since the
295
SECTION 4.6
Patterns
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 pat-
tern 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, dia-
monds, and clubs), which are character glyphs taken from the ZapfDingbats font
(see Section D.5, “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 15 0 R >>
>>
endobj
296
CHAPTER 4
Graphics
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.4
0.0
0.0
0.4
0.0
0.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.0
0.0
0.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 << /F1 20 0 R >>
>>
endobj
20 0 obj
% Font for pattern
<< /Type /Font
/Subtype /Type1
/Encoding 21 0 R
/BaseFont /ZapfDingbats
>>
endobj
297
SECTION 4.6
Patterns
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
/Pattern cs
% 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.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
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
298
CHAPTER 4
Graphics
Several features of Example 4.23 are noteworthy:
The three circles and the triangle are painted with the same pattern. The pat-
tern cells align, even though the circles and triangle are not aligned with re-
spect 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 dif-
ferent 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 speci-
fy any colors; it can paint an image mask (see “Stencil Masking” on page 350) but
no other kind of image.
A Pattern color space representing an uncolored tiling pattern requires a parame-
ter: 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 un-
colored 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
299
SECTION 4.6
Patterns
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 non-
stroking color, to be painted in the color represented by the specified components
in the DeviceRGB color space. Subsequent executions of nonstroking painting op-
erators, such as f (fill), Tj (show text), and Do (paint external object) with an im-
age 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 295, except that it uses an uncol-
ored 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
300
CHAPTER 4
Graphics
15 0 obj
% Pattern definition
<< /Type /Pattern
/PatternType 1
% Tiling pattern
/PaintType 2
% Uncolored
/TilingType 2
/BBox [ 0 0 100 100 ]
/XStep 100
/YStep 100
/Resources 16 0 R
/Matrix [ 0.4
0.0
0.0
0.4
0.0
0.0 ]
/Length 127
>>
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
( \001 ) Tj
% Show spade glyph
0.7478 −0.007 TD
% Move text position
( \002 ) Tj
% Show heart glyph
−0.7323 0.7813 TD
% Move text position
( \003 ) Tj
% Show diamond glyph
0.6913 0.007 TD
% Move text position
( \004 ) Tj
% Show club glyph
ET
% End text object
endstream
endobj
16 0 obj
% Resource dictionary for pattern
<< /Font << /F1 20 0 R >>
>>
endobj
20 0 obj
% Font for pattern
<< /Type /Font
/Subtype /Type1
/Encoding 21 0 R
/BaseFont /ZapfDingbats
>>
endobj
301
SECTION 4.6
Patterns
21 0 obj
% Font encoding
<< /Type /Encoding
/Differences [ 1 /a109 /a110 /a111 /a112 ]
>>
endobj
30 0 obj
% Contents of page
<< /Length 1316 >>
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
302
CHAPTER 4
Graphics
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
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 de-
scribes; must be 2 for a shading pattern.
Shading
dictionary
(Required) A shading object (see below) defining the shading pattern’s gradi-
or stream
ent 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
[ 1
0 0 1 0 0 ].
ExtGState
dictionary
(Optional) A graphics state parameter dictionary (see Section 4.3.4, “Graph-
ics State Parameter Dictionaries”) containing graphics state parameters to be
put into effect temporarily while the shading pattern is painted. Any parame-
ters 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 paint-
ed 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.)
303
SECTION 4.6
Patterns
By setting a shading pattern as the current color in the graphics state, a PDF con-
tent 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 opera-
tor does not require the creation of a pattern dictionary or a path and works with-
out 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
OPERANDS OPERATOR DESCRIPTION
name
sh
(PDF 1.3) Paint the shape and color shading described by a shading dictionary, sub-
ject 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 co-
ordinates 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 shad-
ings. If applied to an unbounded shading, it paints the shading’s gradient fill across
the entire clipping region, which may be time-consuming.
304
CHAPTER 4
Graphics
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 geome-
try of the gradient fill. Various shading types are available, depending on the val-
ue 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 ex-
tended 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 pseudo-
rectangular 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.
305
SECTION 4.6
Patterns
TABLE 4.28 Entries common to all shading dictionaries
KEY
TYPE
VALUE
ShadingType
integer
(Required) The shading type:
1
Function-based shading
2
Axial shading
3
Radial shading
4
Free-form Gouraud-shaded triangle mesh
5
Lattice-form Gouraud-shaded triangle mesh
6
Coons patch mesh
7
Tensor-product patch mesh
ColorSpace
name or
(Required) The color space in which color values are expressed. This may be
array
any device, CIE-based, or special color space except a Pattern space. See
“Color Space: Special Considerations” on page 306 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, be-
fore 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. Anti-aliasing can be computationally expensive and is usu-
ally 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.
306
CHAPTER 4
Graphics
Shading types 4 to 7 are defined by a stream containing descriptive data charac-
terizing 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 62). In particular, it always includes a Length en-
try, 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 geom-
etry 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 ex-
hibit 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, “Smooth-
ness 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 sup-
plied 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 char-
acteristics of the color space. Linear interpolation, for example, may have observ-
ably 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
307
SECTION 4.6
Patterns
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, “Con-
versions among Device Color Spaces.” To optimize performance, these conver-
sions 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—be-
cause 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 per-
formed in that space. Conversion to device colors occurs only after all interpo-
lation 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 colo-
rants are supported, no color conversion calculations are needed. If the speci-
fied 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, non-
linear 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 as-
sume 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
308
CHAPTER 4
Graphics
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
KEY
TYPE
VALUE
Domain
array
(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 ].
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 co-
ordinate 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 iden-
tity matrix [ 1 0 0 1 0 0 ].
Function
function
(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 val-
ue returned by the function for a given color component is out of range, it is ad-
justed 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
309
SECTION 4.6
Patterns
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 corre-
sponding 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 be-
tween two endpoints and extends indefinitely perpendicular to that axis. The
shading may optionally be extended beyond either or both endpoints by continu-
ing the boundary colors indefinitely. Table 4.30 shows the shading dictionary en-
tries 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
KEY
TYPE
VALUE
Coords
array
(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.
Domain
array
(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). De-
fault value: [ 0.0
1.0 ].
Function
function
(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 de-
fined 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 (x0 , y0 ) and (x1 , y1 ) to a corresponding point in the
310
CHAPTER 4
Graphics
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:
(
x1
-
x0
)
×
(
x x0
)
+
(
y1
-
y0
)
×
(
y y0
)
x
= ----------------------------------------------------------------------------------------------------
(x
-
x0
)2
+
(
y1
-
y0
)2
1
The value of the parametric variable t is then determined from x ′ as follows:
For 0 ≤ x ′ ≤ 1, t = t0 + (t1 t0 ) × 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 ; other-
wise, 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 shad-
ing 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 re-
sult 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).
311
SECTION 4.6
Patterns
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
KEY
TYPE
VALUE
Coords
array
(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 coor-
dinate 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.
Domain
array
(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 ].
Function
function
(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 de-
fined 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 val-
ue.
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
t
-
t0
s
= --------------
t1
-
t0
312
CHAPTER 4
Graphics
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:
xc(s)
=
x0
+
s
×
(
x1
x0
)
yc(s)
=
y0
+
s
×
(
y1
y0
)
r(s)
=
r0
+
s
×
(
r1
r0
)
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 dictio-
nary’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 cir-
cle 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 pre-
ceding it. Therefore, if a point lies within more than one blend circle, its final col-
or is that of the last of the enclosing circles to be painted, corresponding to the
greatest value of s.
313
SECTION 4.6
Patterns
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 ra-
dius; 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 spec-
ified 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
5 0 obj
% Shading dictionary
<< /ShadingType 3
/ColorSpace /DeviceCMYK
/Coords [ 0.0 0.0 0.096 0.0 0.0 1.0 00]
% Concentric circles
/Function 10 0 R
/Extend [ true true ]
>>
endobj
10 0 obj
% Color function
<< /FunctionType 3
/Domain [ 0.0 1.0 ]
/Functions [ 11 0 R 12 0 R ]
/Bounds [ 0.708 ]
/Encode [ 1.0 0.0 0.0 1.0 ]
>>
endobj
314
CHAPTER 4
Graphics
11 0 obj
% First subfunction
<< /FunctionType 2
/Domain [ 0.0 1.0 ]
/C0 [ 0.929 0.357 1.000 0.298 ]
/C1 [ 0.631 0.278 1.000 0.027 ]
/N 1.048
>>
endobj
12 0 obj
% Second subfunction
<< /FunctionType 2
/Domain [ 0.0 1.0 ]
/C0 [ 0.929 0.357 1.000 0.298 ]
/C1 [ 0.941 0.400 1.000 0.102 ]
/N 1.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
W n
% Set clipping path
q
% Save graphics state
27.7843 0.0000 0.0000 −27.7843 310.2461 121.1521
cm
% Set matrix
/Sh1 sh
% 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 dic-
tionaries (Table 4.28) and stream dictionaries (Table 3.4 on page 62).
315
SECTION 4.6
Patterns
TABLE 4.32 Additional entries specific to a type 4 shading dictionary
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 ver-
tex (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 344). 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.
Function
function
(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 re-
turned 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 x y c1 cn
316
CHAPTER 4
Graphics
where
f is the vertex’s edge flag (discussed below)
x and y are its horizontal and vertical coordinates
c1 cn 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.
fa=0
(Start new triangle)
Previous
v
a
triangle
vb
vc
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 verti-
ces 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.
317
SECTION 4.6
Patterns
fd =0
fd =1
fd =2
va
va
va
vd
One new
vertex
vb
vc
vb
vc
vb
vc
vd
One new
Three new
vertex
vd
vertices
ve
vf
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 suc-
ceeding triangle:
1
(
fa
=
fb
=
fc
=
0
)
7
(
fi
=
2
)
2
(
fd
=
1
)
8
(
fj
=
2
)
3
(
fe
=
1
)
9
(
fk
=
2
)
4
(
ff
=
1
)
10
(
fl
=
1
)
5
(
fg
=
1
)
11
(
fm
=
1
)
6
(
fh
=
1
)
Mesh 2 again begins with triangle 1 and uses the following edge flags:
1
(
fa
=
fb
=
fc
=
0
)
4
(
ff
=
2
)
2
(
fd
=
1
)
5
(
fg
=
2
)
3
(
fe
=
2
)
6
(
fh
=
2
)
The stream must provide vertex data for a whole number of triangles with appro-
priate edge flags; otherwise, an error occurs.
318
CHAPTER 4
Graphics
va
vc
ve
vg
va
vc
vh
vh = va
1
3
5
1
2
vd
4
vf
6
6
vb
2
vb
vh
vg
vd
vm
vk
11
9
7
5
3
vm = vb
10
8
4
vl
vj
vi
vf
ve
vk = vd
Mesh 1
Mesh 2
FIGURE 4.18 Varying the value of the edge flag to create different shapes
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 344).
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.
319
SECTION 4.6
Patterns
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).
(i, j)
(i, j+1)
(i+1, j)
(i+1, j+1)
Ideal lattice
Pseudorectangular lattice
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 dic-
tionaries (Table 3.4 on page 62).
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:
x y c1 cn
where
x and y are the vertex’s horizontal and vertical coordinates
c1 cn are its color components
320
CHAPTER 4
Graphics
TABLE 4.33 Additional entries specific to a type 5 shading dictionary
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 344). 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.
Function
function
(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 re-
turned 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 c1 cn .
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
321
SECTION 4.6
Patterns
of the mesh are constructed using the following triplets of vertices, as shown in
Figure 4.19:
(Vi,j, Vi,j+1,
Vi+1j)
for 0 ≤ i m - 2, 0 ≤ j k - 2
,
(Vi,j+1,
Vi+1j,
Vi+1j+1)
,
,
See “Type 4 Shadings (Free-Form Gouraud-Shaded Triangle Meshes)” on page
314 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 interpola-
tion 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.
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:
C1(0) = D1(0)
C1(1) = D2(0)
C2(0) = D1(1)
C2(1) = D2(1)
322
CHAPTER 4
Graphics
C2
D2
v
D1
C1
u
FIGURE 4.20 Coordinate mapping from a unit square to a four-sided Coons patch
Two surfaces can be described that are linear interpolations between the bound-
ary curves. Along the u axis, the surface SC is defined by
SC(u, v)
=
(1 - v C1(u)+ v× C2
(u
)
Along the v axis, the surface SD is given by
SD(u, v)
=
(1 - u D1(v)+ u× D2
(v
)
A third surface is the bilinear interpolation of the four corners:
SB(u, v)
=
(1-v)
×
[
(1-u C1
(0
) + u× C1
(1
)]
+
v
×
[
(1-u C2
(0
) + u× C2
(1
)]
The coordinate mapping for the shading is given by the surface S, defined as
S = SC+ SD SB
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
323
SECTION 4.6
Patterns
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.
Appearance
Painted area
Patch boundary
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 dic-
tionaries (Table 3.4 on page 62).
324
CHAPTER 4
Graphics
TABLE 4.34 Additional entries specific to a type 6 shading dictionary
KEY
TYPE
VALUE
BitsPerCoordinate
integer
(Required) The number of bits used to represent each geometric coordi-
nate. 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 344). 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.
Function
function
(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 re-
turned 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-
325
SECTION 4.6
Patterns
Shaded Triangle Meshes)” on page 314 for further details on the format of the da-
ta.
As in free-form triangle meshes (type 4), each patch has an edge flag that indi-
cates 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 co-
ordinates, x1 y1 x2 y2 x12 y12 , which specify the Bézier control points that
define the four boundary curves. Figure 4.22 shows how these control points cor-
respond to the cubic Bézier curves C1 , C2 , D1 , and D2 identified in Figure 4.20 on
page 322. Color values are given for the four corners of the patch, in the same or-
der as the control points corresponding to the corners. Thus, c1 is the color at co-
ordinates (x1 , y1 ), c2 at (x4 , y4 ), c3 at (x7 , y7 ), and c4 at (x10 , y10 ), as shown in the
figure.
Use this side when next f = 1.
5
c
3
C2
c2
7
4
6
3
8
This side already attached
to previous patch. Start a
D1
D2
Use this side when next f = 2.
new patch when next f = 0.
9
12
2
10
1
c4
c1
C
1
11
Use this side when next f = 3.
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.
326
CHAPTER 4
Graphics
Patch B
fB = 1
2
1
4
c2
c1
3
5
c
c1
3
4
c
7
2
1
6
3
8
2
Patch B
When fB = 0, start a new patch.
fB = 2
Patch A
12
9
3
2
1
10
4
c4
c1
c2
11
3
c1
c2
4
1
2
Patch B
fB = 3
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 sepa-
rate color components c1 cn . 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.
327
SECTION 4.6
Patterns
TABLE 4.35 Data values in a Coons patch mesh
EDGE FLAG
NEXT SET OF DATA VALUES
f = 0
x1 y1 x2 y2 x3 y3 x4 y4 x5 y5 x6 y6
x7 y7 x8 y8 x9 y9 x10 y10 x11 y
x12 y12
11
c
c2 c3 c4
1
New patch; no implicit values
f = 1
x5 y5 x6 y6 x7 y7 x8 y8 x9
y
x
y10 x11 y11 x12 y12
9
10
c
c4
3
Implicit values:
(x1 , y1 ) = (x4 , y4 ) previous
c1 = c2 previous
(x2 , y2 ) = (x5 , y5 ) previous
c2 = c3 previous
(x3 , y3 ) = (x6 , y6 ) previous
(x4 , y4 ) = (x7 , y7 ) previous
f = 2
x5 y5 x6 y6 x7 y7 x8 y8 x9
y
x
y10 x11 y11 x12 y12
9
10
c
3 c4
Implicit values:
(x1 , y1 ) = (x7 , y7 ) previous
c1 = c3 previous
(x2 , y2 ) = (x8 , y8 ) previous
c2 = c4 previous
(x3 , y3 ) = (x9 , y9 ) previous
(x4 , y4 ) = (x10 , y10 ) previous
f = 3
x5 y5 x6 y6 x7 y7 x8 y8 x9
y
x
y10 x11 y11 x12 y12
9
10
c
3 c4
Implicit values:
(x1 , y1 ) = (x10 , y10 ) previous
c1 = c4 previous
(x2 , y2 ) = (x11 , y11 ) previous
c2 = c1 previous
(x3 , y3 ) = (x12 , y12 ) previous
(x4 , y4 ) = (x1 , y1 ) 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 in-
stead 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.
328
CHAPTER 4
Graphics
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):
p03
p13
p23
p33
p02
p12
p22
p32
p01
p11
p21
p31
p00
p10
p20
p30
p13
p03
p33
p23
p32
p02
p12
p22
p11
p21
p01
p10
p31
p30
p00
p20
FIGURE 4.24 Control points in a tensor-product patch
329
SECTION 4.6
Patterns
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 hori-
zontally and vertically across the unit square. The surface is defined by the equa-
tion
3
3
S (u, v)
=
pij × Bi(u)× Bj(v)
i=0
j= 0
where pij is the control point in column i and row j of the tensor, and Bi and Bj are
the Bernstein polynomials
B0(t)
=
(1-t)3
B1(t)
=
3t
×
(1-t)2
B2(t)
=
3t2
×(1-t)
B3(t)
=
t3
Since each point pij is actually a pair of coordinates (xij , yij ), the surface can also
be expressed as
3
3
x(u, v)
=
xij × Bi(u Bj (v)
i=0
j= 0
3
3
y(u, v)
=
yij × Bi(u Bj (v)
i= 0
j
=0
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 (p00 p30 ) and top (p03 p33 ) 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
p00 p03 , the trajectory of the ending point is defined by points p30 p33 , and
330
CHAPTER 4
Graphics
those of the two intermediate control points by p10 p13 and p20 p23 . Equiva-
lently, 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 giv-
en by these equations:
p11
=
1⁄9
×
[
-4
×
p00
+
6
×
(
p01
+
p10
)
2
×
(
p03
+
p30
)
+
3
×
(
p31
+
p13
)
1
×
p33
]
p12
=
1⁄9
×
[
-4
×
p03
+
6
×
(
p02
+
p13
)
2
×
(
p00
+
p33
)
+
3
×
(
p32
+
p10
)
p30
]
p21
=
1⁄9
×
[
-4
×
p30
+
6
×
(
p31
+
p20
)
2
×
(
p33
+
p00
)
+
3
×
(
p01
+
p23
)
1
×
p03
]
p22
=
1⁄9
×
[
-4
×
p33
+
6
×
(
p32
+
p23
)
2
×
(
p30
+
p03
)
+
3
×
(
p02
+
p20
)
1
×
p00
]
In the more general tensor-product patch, the values of these four points are un-
restricted.
The coordinates of the control points in a tensor-product patch are actually spec-
ified 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 (Free-Form

Была ли эта страница вам полезна?
Да!Нет
4 посетителя считают эту страницу полезной.
Большое спасибо!
Ваше мнение очень важно для нас.

Нет комментариевНе стесняйтесь поделиться с нами вашим ценным мнением.

Текст

Политика конфиденциальности