PDF Reference sixth edition, Adobe Portable Document Format Version 1.7 (book 1) — page 6
208
CHAPTER 4
Graphics
PDF represents coordinates in a two-dimensional space. The point (x, y) in such
a space can be expressed in vector form as [ x y 1 ]. The constant third element of
this vector (1) is needed so that the vector can be used with 3-by-3 matrices in the
calculations described below.
The transformation between two coordinate systems is represented by a 3-by-3
transformation matrix written as follows:
a b
0
c d
0
e f
1
Because a transformation matrix has only six elements that can be changed, it is
usually specified in PDF as the six-element array [ a b c d e f ].
Coordinate transformations are expressed as matrix multiplications:
a b
0
[x′ y′
1]
=
[x y 1]
×
c d
0
e f
1
Because PDF transformation matrices specify the conversion from the trans-
formed coordinate system to the original (untransformed) coordinate system, x ′
and y ′ in this equation are the coordinates in the untransformed coordinate sys-
tem, and x and y are the coordinates in the transformed system. The multiplica-
tion is carried out as follows:
x′
= a×x+c×y+e
y′
= b×x+d×y+f
If a series of transformations is carried out, the matrices representing each of the
individual transformations can be multiplied together to produce a single equiva-
lent matrix representing the composite transformation.
Matrix multiplication is not commutative—the order in which matrices are mul-
tiplied is significant. Consider a sequence of two transformations: a scaling trans-
formation applied to the user space coordinate system, followed by a conversion
from the resulting scaled user space to device space. Let MS be the matrix specify-
ing the scaling and MC the current transformation matrix, which transforms user
209
SECTION 4.2
Coordinate Systems
space to device space. Recalling that coordinates are always specified in the trans-
formed space, the correct order of transformations must first convert the scaled
coordinates to default user space and then the default user space coordinates to
device space. This can be expressed as
XD = XU × MC = (XS × MS)× MC = XS × (MS × MC)
where
XD denotes the coordinates in device space
XU denotes the coordinates in default user space
XS denotes the coordinates in scaled user space
This shows that when a new transformation is concatenated with an existing one,
the matrix representing it must be multiplied before (premultiplied with) the
existing transformation matrix.
This result is true in general for PDF: when a sequence of transformations is car-
ried out, the matrix representing the combined transformation (M ′) is calculated
by premultiplying the matrix representing the additional transformation (MT )
with the one representing all previously existing transformations (M):
M′ = MT × M
Note: When rendering graphics objects, it is sometimes necessary for an application
to perform the inverse of a transformation—that is, to find the user space coordi-
nates that correspond to a given pair of device space coordinates. Not all transfor-
mations are invertible, however. For example, if a matrix contains a, b, c, and d
elements that are all zero, all user coordinates map to the same device coordinates
and there is no unique inverse transformation. Such noninvertible transformations
are not very useful and generally arise from unintended operations, such as scaling
by 0. Use of a noninvertible matrix when painting graphics objects can result in un-
predictable behavior.
210
CHAPTER 4
Graphics
4.3
Graphics State
A PDF consumer application maintains an internal data structure called the
graphics state that holds current graphics control parameters. These parameters
define the global framework within which the graphics operators execute. For ex-
ample, the f (fill) operator implicitly uses the current color parameter, and the S
(stroke) operator additionally uses the current line width parameter from the
graphics state.
The graphics state is initialized at the beginning of each page with the values
specified in Tables 4.2 and 4.3. Table 4.2 lists those graphics state parameters that
are device-independent and are appropriate to specify in page descriptions. The
parameters listed in Table 4.3 control details of the rendering (scan conversion)
process and are device-dependent; a page description that is intended to be de-
vice-independent should not modify these parameters.
TABLE 4.2 Device-independent graphics state parameters
PARAMETER
TYPE
VALUE
CTM
array
The current transformation matrix, which maps positions from user
coordinates to device coordinates (see Section 4.2, “Coordinate Sys-
tems”). This matrix is modified by each application of the coordi-
nate transformation operator, cm. Initial value: a matrix that
transforms default user coordinates to device coordinates.
clipping path
(internal)
The current clipping path, which defines the boundary against
which all output is to be cropped (see Section 4.4.3, “Clipping Path
Operators”). Initial value: the boundary of the entire imageable
portion of the output page.
color space
name or array
The current color space in which color values are to be interpreted
(see Section 4.5, “Color Spaces”). There are two separate color space
parameters: one for stroking and one for all other painting opera-
tions. Initial value: DeviceGray.
color
(various)
The current color to be used during painting operations (see Section
4.5, “Color Spaces”). The type and interpretation of this parameter
depend on the current color space; for most color spaces, a color
value consists of one to four numbers. There are two separate color
parameters: one for stroking and one for all other painting opera-
tions. Initial value: black.
211
SECTION 4.3
Graphics State
PARAMETER
TYPE
VALUE
text state
(various)
A set of nine graphics state parameters that pertain only to the
painting of text. These include parameters that select the font, scale
the glyphs to an appropriate size, and accomplish other effects. The
text state parameters are described in Section
5.2,
“Text State
Parameters and Operators.”
line width
number
The thickness, in user space units, of paths to be stroked (see “Line
Width” on page 215). Initial value: 1.0.
line cap
integer
A code specifying the shape of the endpoints for any open path that
is stroked (see “Line Cap Style” on page 216). Initial value: 0, for
square butt caps.
line join
integer
A code specifying the shape of joints between connected segments
of a stroked path (see “Line Join Style” on page 216). Initial value: 0,
for mitered joins.
miter limit
number
The maximum length of mitered line joins for stroked paths (see
“Miter Limit” on page 217). This parameter limits the length of
“spikes” produced when line segments join at sharp angles. Initial
value: 10.0, for a miter cutoff below approximately 11.5 degrees.
dash pattern
array and number
A description of the dash pattern to be used when paths are stroked
(see “Line Dash Pattern” on page 217). Initial value: a solid line.
rendering intent
name
The rendering intent to be used when converting CIE-based colors
to device colors (see “Rendering Intents” on page 260). Initial value:
RelativeColorimetric.
stroke adjustment
boolean
(PDF 1.2) A flag specifying whether to compensate for possible ras-
terization effects when stroking a path with a line width that is
small relative to the pixel resolution of the output device (see Sec-
tion 6.5.4, “Automatic Stroke Adjustment”). Note that this is consid-
ered a device-independent parameter, even though the details of its
effects are device-dependent. Initial value: false.
blend mode
name or array
(PDF 1.4) The current blend mode to be used in the transparent
imaging model (see Sections 7.2.4, “Blend Mode,” and 7.5.2, “Speci-
fying Blending Color Space and Blend Mode”). This parameter is
implicitly reset to its initial value at the beginning of execution of a
transparency group XObject
(see Section
7.5.5,
“Transparency
Group XObjects”). Initial value: Normal.
212
CHAPTER 4
Graphics
PARAMETER
TYPE
VALUE
soft mask
dictionary
(PDF 1.4) A soft-mask dictionary (see “Soft-Mask Dictionaries” on
or name
page 552) specifying the mask shape or mask opacity values to be
used in the transparent imaging model (see “Source Shape and
Opacity” on page 526 and “Mask Shape and Opacity” on page 550),
or the name None if no such mask is specified. This parameter is
implicitly reset to its initial value at the beginning of execution of a
transparency group XObject
(see Section
7.5.5,
“Transparency
Group XObjects”). Initial value: None.
alpha constant
number
(PDF 1.4) The constant shape or constant opacity value to be used
in the transparent imaging model (see “Source Shape and Opacity”
on page 526 and “Constant Shape and Opacity” on page 551). There
are two separate alpha constant parameters: one for stroking and
one for all other painting operations. This parameter is implicitly
reset to its initial value at the beginning of execution of a transpar-
ency group XObject
(see Section
7.5.5,
“Transparency Group
XObjects”). Initial value: 1.0.
alpha source
boolean
(PDF 1.4) A flag specifying whether the current soft mask and al-
pha constant parameters are to be interpreted as shape values (true)
or opacity values (false). This flag also governs the interpretation of
the SMask entry, if any, in an image dictionary (see Section 4.8.4,
“Image Dictionaries”). Initial value: false.
TABLE 4.3
Device-dependent graphics state parameters
PARAMETER
TYPE
VALUE
overprint
boolean
(PDF 1.2) A flag specifying (on output devices that support the
overprint control feature) whether painting in one set of colorants
should cause the corresponding areas of other colorants to be
erased (false) or left unchanged (true); see Section 4.5.6, “Overprint
Control.” In PDF 1.3, there are two separate overprint parameters:
one for stroking and one for all other painting operations. Initial
value: false.
overprint mode
number
(PDF 1.3) A code specifying whether a color component value of 0
in a DeviceCMYK color space should erase that component (0) or
leave it unchanged (1) when overprinting (see Section 4.5.6, “Over-
print Control”). Initial value: 0.
213
SECTION 4.3
Graphics State
PARAMETER
TYPE
VALUE
black generation
function or name
(PDF 1.2) A function that calculates the level of the black color
component to use when converting RGB colors to CMYK (see Sec-
tion 6.2.3, “Conversion from DeviceRGB to DeviceCMYK”). Initial
value: installation-dependent.
undercolor removal
function or name
(PDF 1.2) A function that calculates the reduction in the levels of
the cyan, magenta, and yellow color components to compensate for
the amount of black added by black generation (see Section 6.2.3,
“Conversion from DeviceRGB to DeviceCMYK”). Initial value: in-
stallation-dependent.
transfer
function,
(PDF 1.2) A function that adjusts device gray or color component
array, or name
levels to compensate for nonlinear response in a particular output
device
(see Section
6.3,
“Transfer Functions”). Initial value:
installation-dependent.
halftone
dictionary,
(PDF 1.2) A halftone screen for gray and color rendering, specified
stream, or name
as a halftone dictionary or stream (see Section 6.4, “Halftones”).
Initial value: installation-dependent.
flatness
number
The precision with which curves are to be rendered on the output
device (see Section 6.5.1, “Flatness Tolerance”). The value of this
parameter gives the maximum error tolerance, measured in output
device pixels; smaller numbers give smoother curves at the expense
of more computation and memory use. Initial value: 1.0.
smoothness
number
(PDF 1.3) The precision with which color gradients are to be ren-
dered on the output device (see Section 6.5.2, “Smoothness Toler-
ance”). The value of this parameter gives the maximum error
tolerance, expressed as a fraction of the range of each color compo-
nent; smaller numbers give smoother color transitions at the
expense of more computation and memory use. Initial value:
installation-dependent.
Some graphics state parameters are set with specific PDF operators, some are set
by including a particular entry in a graphics state parameter dictionary, and some
can be specified either way. The current line width, for example, can be set either
with the w operator or (in PDF 1.3) with the LW entry in a graphics state parame-
ter dictionary, whereas the current color is set only with specific operators, and
the current halftone is set only with a graphics state parameter dictionary. It is
expected that all future graphics state parameters will be specified with new
entries in the graphics state parameter dictionary rather than with new operators.
214
CHAPTER 4
Graphics
In general, the operators that set graphics state parameters simply store them un-
changed for later use by the painting operators. However, some parameters have
special properties or behavior:
• Most parameters must be of the correct type or have values that fall within a
certain range.
• Parameters that are numeric values, such as the current color, line width, and
miter limit, are forced into valid range, if necessary. However, they are not ad-
justed to reflect capabilities of the raster output device, such as resolution or
number of distinguishable colors. Painting operators perform such adjust-
ments, but the adjusted values are not stored back into the graphics state.
• Paths are internal objects that are not directly represented in PDF.
Note: As indicated in Tables 4.2 and 4.3, some of the parameters—color space, color,
and overprint—have two values, one used for stroking (of paths and text objects)
and one for all other painting operations. The two parameter values can be set inde-
pendently, allowing for operations such as combined filling and stroking of the same
path with different colors. Except where noted, a term such as current color should
be interpreted to refer to whichever color parameter applies to the operation being
performed. When necessary, the individual color parameters are distinguished ex-
plicitly as the stroking color and the nonstroking color.
4.3.1
Graphics State Stack
A well-structured PDF document typically contains many graphical elements
that are essentially independent of each other and sometimes nested to multiple
levels. The graphics state stack allows these elements to make local changes to the
graphics state without disturbing the graphics state of the surrounding environ-
ment. The stack is a LIFO (last in, first out) data structure in which the contents
of the graphics state can be saved and later restored using the following operators:
• The q operator pushes a copy of the entire graphics state onto the stack.
• The Q operator restores the entire graphics state to its former value by popping
it from the stack.
215
SECTION 4.3
Graphics State
These operators can be used to encapsulate a graphical element so that it can
modify parameters of the graphics state and later restore them to their previous
values. Occurrences of the q and Q operators must be balanced within a given
content stream (or within the sequence of streams specified in a page dictionary’s
Contents array).
4.3.2
Details of Graphics State Parameters
This section gives details of several of the device-independent graphics state pa-
rameters listed in Table 4.2.
Line Width
The line width parameter specifies the thickness of the line used to stroke a path.
It is a non-negative number expressed in user space units; stroking a path entails
painting all points whose perpendicular distance from the path in user space is
less than or equal to half the line width. The effect produced in device space
depends on the current transformation matrix (CTM) in effect at the time the
path is stroked. If the CTM specifies scaling by different factors in the horizontal
and vertical dimensions, the thickness of stroked lines in device space will vary
according to their orientation. The actual line width achieved can differ from the
requested width by as much as 2 device pixels, depending on the positions of lines
with respect to the pixel grid. Automatic stroke adjustment can be used to ensure
uniform line width; see Section 6.5.4, “Automatic Stroke Adjustment.”
A line width of 0 denotes the thinnest line that can be rendered at device resolu-
tion: 1 device pixel wide. However, some devices cannot reproduce 1-pixel lines,
and on high-resolution devices, they are nearly invisible. Since the results of ren-
dering such zero-width lines are device-dependent, their use is not recommend-
ed.
216
CHAPTER 4
Graphics
Line Cap Style
The line cap style specifies the shape to be used at the ends of open subpaths (and
dashes, if any) when they are stroked. Table 4.4 shows the possible values.
TABLE 4.4 Line cap styles
STYLE
APPEARANCE
DESCRIPTION
0
Butt cap. The stroke is squared off at the endpoint of the path. There is no
projection beyond the end of the path.
1
Round cap. A semicircular arc with a diameter equal to the line width is
drawn around the endpoint and filled in.
2
Projecting square cap. The stroke continues beyond the endpoint of the path
for a distance equal to half the line width and is squared off.
Line Join Style
The line join style specifies the shape to be used at the corners of paths that are
stroked. Table 4.5 shows the possible values. Join styles are significant only at
points where consecutive segments of a path connect at an angle; segments that
meet or intersect fortuitously receive no special treatment.
TABLE 4.5 Line join styles
STYLE
APPEARANCE
DESCRIPTION
0
Miter join. The outer edges of the strokes for the two segments are extended
until they meet at an angle, as in a picture frame. If the segments meet at too
sharp an angle (as defined by the miter limit parameter—see
“Miter Limit,”
above), a bevel join is used instead.
1
Round join. An arc of a circle with a diameter equal to the line width is drawn
around the point where the two segments meet, connecting the outer edges of
the strokes for the two segments. This pieslice-shaped figure is filled in, pro-
ducing a rounded corner.
2
Bevel join. The two segments are
finished with butt caps (see “Line Cap Style”
on
page 216) and the resulting notch beyond the ends of the segments is filled
with a triangle.
217
SECTION 4.3
Graphics State
Note: The definition of round join was changed in PDF 1.5. In rare cases, the imple-
mentation of the previous specification could produce unexpected results.
Miter Limit
When two line segments meet at a sharp angle and mitered joins have been spec-
ified as the line join style, it is possible for the miter to extend far beyond the
thickness of the line stroking the path. The miter limit imposes a maximum on
the ratio of the miter length to the line width (see Figure 4.7). When the limit is
exceeded, the join is converted from a miter to a bevel.
The ratio of miter length to line width is directly related to the angle ϕ between
the segments in user space by the following formula:
miterLength
= ----------
--------
lineWidth
⎛
⎞
sin
--
⎝
2⎠
For example, a miter limit of 1.414 converts miters to bevels for ϕ less than 90
degrees, a limit of 2.0 converts them for ϕ less than 60 degrees, and a limit of 10.0
converts them for ϕ less than approximately 11.5 degrees.
Miter
length
j
Line width
FIGURE 4.7 Miter length
Line Dash Pattern
The line dash pattern controls the pattern of dashes and gaps used to stroke paths.
It is specified by a dash array and a dash phase. The dash array’s elements are
numbers that specify the lengths of alternating dashes and gaps; the numbers
must be nonnegative and not all zero. The dash phase specifies the distance into
218
CHAPTER 4
Graphics
the dash pattern at which to start the dash. The elements of both the dash array
and the dash phase are expressed in user space units.
Before beginning to stroke a path, the dash array is cycled through, adding up the
lengths of dashes and gaps. When the accumulated length equals the value speci-
fied by the dash phase, stroking of the path begins, and the dash array is used cy-
clically from that point onward. Table 4.6 shows examples of line dash patterns.
As can be seen from the table, an empty dash array and zero phase can be used to
restore the dash pattern to a solid line.
TABLE 4.6 Examples of line dash patterns
DASH ARRAY
APPEARANCE
DESCRIPTION
AND PHASE
[ ]
0
No dash; solid, unbroken lines
[ 3 ]
0
3 units on, 3 units off, …
[ 2 ]
1
1 on, 2 off, 2 on, 2 off, …
[ 2
1 ] 0
2 on, 1 off, 2 on, 1 off, …
[ 3
5 ] 6
2 off, 3 on, 5 off, 3 on, 5 off, …
[ 2
3 ] 11
1 on, 3 off, 2 on, 3 off, 2 on, …
Dashed lines wrap around curves and corners just as solid stroked lines do. The
ends of each dash are treated with the current line cap style, and corners within
dashes are treated with the current line join style. A stroking operation takes no
measures to coordinate the dash pattern with features of the path; it simply dis-
penses dashes and gaps along the path in the pattern defined by the dash array.
When a path consisting of several subpaths is stroked, each subpath is treated in-
dependently—that is, the dash pattern is restarted and the dash phase is reapplied
to it at the beginning of each subpath.
4.3.3
Graphics State Operators
Table 4.7 shows the operators that set the values of parameters in the graphics
state. (See also the color operators listed in Table 4.24 and the text state operators
in Table 5.2 on page 398.)
219
SECTION 4.3
Graphics State
TABLE 4.7 Graphics state operators
OPERANDS
OPERATOR
DESCRIPTION
—
q
Save the current graphics state on the graphics state stack (see “Graphics
State Stack” on page 214).
—
Q
Restore the graphics state by removing the most recently saved state from
the stack and making it the current state (see “Graphics State Stack” on
page 214).
a b c d e
f
cm
Modify the current transformation matrix (CTM) by concatenating the
specified matrix (see Section 4.2.1, “Coordinate Spaces”). Although the
operands specify a matrix, they are written as six separate numbers, not as
an array.
lineWidth
w
Set the line width in the graphics state (see “Line Width” on page 215).
lineCap
J
Set the line cap style in the graphics state (see “Line Cap Style” on page
216).
lineJoin
j
Set the line join style in the graphics state (see “Line Join Style” on page
216).
miterLimit
M
Set the miter limit in the graphics state (see “Miter Limit” on page 217).
dashArray
dashPhase
d
Set the line dash pattern in the graphics state (see “Line Dash Pattern” on
page 217).
intent
ri
(PDF 1.1) Set the color rendering intent in the graphics state (see “Render-
ing Intents” on page 260).
flatness
i
Set the flatness tolerance in the graphics state (see Section 6.5.1, “Flatness
Tolerance”). flatness is a number in the range 0 to 100; a value of 0 speci-
fies the output device’s default flatness tolerance.
dictName
gs
(PDF 1.2) Set the specified parameters in the graphics state. dictName is
the name of a graphics state parameter dictionary in the ExtGState subdic-
tionary of the current resource dictionary (see the next section).
4.3.4
Graphics State Parameter Dictionaries
While some parameters in the graphics state can be set with individual operators,
as shown in Table 4.7, others cannot. The latter can only be set with the generic
graphics state operator gs (PDF 1.2). The operand supplied to this operator is the
220
CHAPTER 4
Graphics
name of a graphics state parameter dictionary whose contents specify the values of
one or more graphics state parameters. This name is looked up in the ExtGState
subdictionary of the current resource dictionary. (The name ExtGState, for
extended graphics state, is a vestige of earlier versions of PDF.)
Note: The graphics state parameter dictionary is also used by type 2 patterns, which
do not have a content stream in which the graphics state operators could be invoked
(see Section 4.6.3, “Shading Patterns”).
Each entry in the parameter dictionary specifies the value of an individual graph-
ics state parameter, as shown in Table 4.8. All entries need not be present for ev-
ery invocation of the gs operator; the supplied parameter dictionary may include
any combination of parameter entries. The results of gs are cumulative; parame-
ter values established in previous invocations persist until explicitly overridden.
Note that some parameters appear in both Tables 4.7 and 4.8; these parameters
can be set either with individual graphics state operators or with gs. It is expected
that any future extensions to the graphics state will be implemented by adding
new entries to the graphics state parameter dictionary rather than by introducing
new graphics state operators.
TABLE 4.8 Entries in a graphics state parameter dictionary
KEY
TYPE
DESCRIPTION
Type
name
(Optional) The type of PDF object that this dictionary describes; must be
ExtGState for a graphics state parameter dictionary.
LW
number
(Optional; PDF 1.3) The line width (see “Line Width” on page 215).
LC
integer
(Optional; PDF 1.3) The line cap style (see “Line Cap Style” on page 216).
LJ
integer
(Optional; PDF 1.3) The line join style (see “Line Join Style” on page 216).
ML
number
(Optional; PDF 1.3) The miter limit (see “Miter Limit” on page 217).
D
array
(Optional; PDF 1.3) The line dash pattern, expressed as an array of the form
[ dashArray dashPhase ], where dashArray is itself an array and dashPhase is an
integer (see “Line Dash Pattern” on page 217).
RI
name
(Optional; PDF 1.3) The name of the rendering intent (see “Rendering
Intents” on page 260).
221
SECTION 4.3
Graphics State
KEY
TYPE
DESCRIPTION
OP
boolean
(Optional) A flag specifying whether to apply overprint (see Section 4.5.6,
“Overprint Control”). In PDF 1.2 and earlier, there is a single overprint
parameter that applies to all painting operations. Beginning with PDF 1.3,
there are two separate overprint parameters: one for stroking and one for all
other painting operations. Specifying an OP entry sets both parameters un-
less there is also an op entry in the same graphics state parameter dictionary,
in which case the OP entry sets only the overprint parameter for stroking.
op
boolean
(Optional; PDF 1.3) A flag specifying whether to apply overprint (see Section
4.5.6, “Overprint Control”) for painting operations other than stroking. If
this entry is absent, the OP entry, if any, sets this parameter.
OPM
integer
(Optional; PDF 1.3) The overprint mode (see Section 4.5.6, “Overprint Con-
trol”).
Font
array
(Optional; PDF 1.3) An array of the form [ font size ], where font is an indirect
reference to a font dictionary and size is a number expressed in text space
units. These two objects correspond to the operands of the Tf operator (see
Section 5.2, “Text State Parameters and Operators”); however, the first oper-
and is an indirect object reference instead of a resource name.
BG
function
(Optional) The black-generation function, which maps the interval [ 0.0 1.0 ]
to the interval [ 0.0 1.0 ] (see Section 6.2.3, “Conversion from DeviceRGB to
DeviceCMYK”).
BG2
function or name
(Optional; PDF 1.3) Same as BG except that the value may also be the name
Default, denoting the black-generation function that was in effect at the start
of the page. If both BG and BG2 are present in the same graphics state param-
eter dictionary, BG2 takes precedence.
UCR
function
(Optional) The undercolor-removal function, which maps the interval
[ 0.0
1.0 ] to the interval [ −1.0 1.0 ] (see Section 6.2.3, “Conversion from
DeviceRGB to DeviceCMYK”).
UCR2
function or name
(Optional; PDF 1.3) Same as UCR except that the value may also be the name
Default, denoting the undercolor-removal function that was in effect at the
start of the page. If both UCR and UCR2 are present in the same graphics state
parameter dictionary, UCR2 takes precedence.
222
CHAPTER 4
Graphics
KEY
TYPE
DESCRIPTION
TR
function, array, or
(Optional) The transfer function, which maps the interval [ 0.0 1.0 ] to the in-
name
terval [ 0.0
1.0 ] (see Section 6.3, “Transfer Functions”). The value is either a
single function (which applies to all process colorants) or an array of four
functions (which apply to the process colorants individually). The name
Identity may be used to represent the identity function.
TR2
function, array, or
(Optional; PDF 1.3) Same as TR except that the value may also be the name
name
Default, denoting the transfer function that was in effect at the start of the
page. If both TR and TR2 are present in the same graphics state parameter dic-
tionary, TR2 takes precedence.
HT
dictionary, stream,
(Optional) The halftone dictionary or stream (see Section 6.4, “Halftones”) or
or name
the name Default, denoting the halftone that was in effect at the start of the
page.
FL
number
(Optional; PDF 1.3) The flatness tolerance (see Section 6.5.1, “Flatness Toler-
ance”).
SM
number
(Optional; PDF 1.3) The smoothness tolerance (see Section 6.5.2, “Smooth-
ness Tolerance”).
SA
boolean
(Optional) A flag specifying whether to apply automatic stroke adjustment
(see Section 6.5.4, “Automatic Stroke Adjustment”).
BM
name or array
(Optional; PDF 1.4) The current blend mode to be used in the transparent
imaging model (see Sections 7.2.4, “Blend Mode,” and 7.5.2, “Specifying
Blending Color Space and Blend Mode”).
SMask
dictionary or name
(Optional; PDF 1.4) The current soft mask, specifying the mask shape or
mask opacity values to be used in the transparent imaging model (see
“Source Shape and Opacity” on page 526 and “Mask Shape and Opacity” on
page 550).
Note: Although the current soft mask is sometimes referred to as a “soft clip,”
altering it with the gs operator completely replaces the old value with the new
one, rather than intersecting the two as is done with the current clipping path
parameter (see Section 4.4.3, “Clipping Path Operators”).
CA
number
(Optional; PDF 1.4) The current stroking alpha constant, specifying the con-
stant shape or constant opacity value to be used for stroking operations in the
transparent imaging model (see “Source Shape and Opacity” on page 526 and
“Constant Shape and Opacity” on page 551).
ca
number
(Optional; PDF 1.4) Same as CA, but for nonstroking operations.
223
SECTION 4.3
Graphics State
KEY
TYPE
DESCRIPTION
AIS
boolean
(Optional; PDF 1.4) The alpha source flag (“alpha is shape”), specifying
whether the current soft mask and alpha constant are to be interpreted as
shape values (true) or opacity values (false).
TK
boolean
(Optional; PDF 1.4) The text knockout flag, which determines the behavior of
overlapping glyphs within a text object in the transparent imaging model (see
Section 5.2.7, “Text Knockout”).
Example 4.1 shows two graphics state parameter dictionaries. In the first, auto-
matic stroke adjustment is turned on, and the dictionary includes a transfer func-
tion that inverts its value, f (x) = 1 − x. In the second, overprint is turned off, and
the dictionary includes a parabolic transfer function, f (x) = (2x − 1) 2, with a sam-
ple of 21 values. The domain of the transfer function, [ 0.0 1.0 ], is mapped to
[ 0 20 ], and the range of the sample values, [ 0 255 ], is mapped to the range of
the transfer function, [ 0.0 1.0 ].
Example 4.1
10 0 obj
% Page object
<< /Type /Page
/Parent 5 0 R
/Resources 20 0 R
/Contents 40 0 R
>>
endobj
20 0 obj
% Resource dictionary for page
<< /ProcSet [ /PDF /Text ]
/Font << /F1 25 0 R >>
/ExtGState << /GS1 30 0 R
/GS2 35 0 R
>>
>>
endobj
30 0 obj
% First graphics state parameter dictionary
<< /Type /ExtGState
/SA true
/TR 31 0 R
>>
endobj
224
CHAPTER 4
Graphics
31 0 obj
% First transfer function
<< /FunctionType 0
/Domain [ 0.0 1.0 ]
/Range [ 0.0 1.0 ]
/Size
2
/BitsPerSample 8
/Length 7
/Filter
/ASCIIHexDecode
>>
stream
01 00 >
endstream
endobj
35 0 obj
% Second graphics state parameter dictionary
<< /Type /ExtGState
/OP false
/TR 36 0 R
>>
endobj
36 0 obj
% Second transfer function
<< /FunctionType 0
/Domain [ 0.0 1.0 ]
/Range [ 0.0 1.0 ]
/Size
21
/BitsPerSample 8
/Length 63
/Filter
/ASCIIHexDecode
>>
stream
FF CE A3 7C 5B 3F 28 16 0A
02 00
02 0A 16 28 3F 5B 7C A3 CE FF >
endstream
endobj
4.4
Path Construction and Painting
Paths define shapes, trajectories, and regions of all sorts. They are used to draw
lines, define the shapes of filled areas, and specify boundaries for clipping other
graphics. The graphics state includes a current clipping path that defines the clip-
ping boundary for the current page. At the beginning of each page, the clipping
path is initialized to include the entire page.
225
SECTION 4.4
Path Construction and Painting
A path is composed of straight and curved line segments, which may connect to
one another or may be disconnected. A pair of segments are said to connect only
if they are defined consecutively, with the second segment starting where the first
one ends. Thus, the order in which the segments of a path are defined is signifi-
cant. Nonconsecutive segments that meet or intersect fortuitously are not consid-
ered to connect.
A path is made up of one or more disconnected subpaths, each comprising a se-
quence of connected segments. The topology of the path is unrestricted: it may be
concave or convex, may contain multiple subpaths representing disjoint areas,
and may intersect itself in arbitrary ways. The h operator explicitly connects the
end of a subpath back to its starting point; such a subpath is said to be closed. A
subpath that has not been explicitly closed is open.
As discussed in Section 4.1, “Graphics Objects,” a path object is defined by a se-
quence of operators to construct the path, followed by one or more operators to
paint the path or to use it as a clipping boundary. PDF path operators fall into
three categories:
• Path construction operators (Section 4.4.1) define the geometry of a path. A
path is constructed by sequentially applying one or more of these operators.
• Path-painting operators (Section 4.4.2) end a path object, usually causing the
object to be painted on the current page in any of a variety of ways.
• Clipping path operators (Section 4.4.3), invoked immediately before a path-
painting operator, cause the path object also to be used for clipping of sub-
sequent graphics objects.
4.4.1
Path Construction Operators
A page description begins with an empty path and builds up its definition by in-
voking one or more path construction operators to add segments to it. The path
construction operators may be invoked in any sequence, but the first one invoked
must be m or re to begin a new subpath. The path definition concludes with the
application of a path-painting operator such as S, f, or b (see Section 4.4.2, “Path-
Painting Operators”); this operator may optionally be preceded by one of the
clipping path operators W or W* (Section 4.4.3, “Clipping Path Operators”). Note
that the path construction operators do not place any marks on the page; only the
painting operators do that. A path definition is not complete until a path-painting
operator has been applied to it.
226
CHAPTER 4
Graphics
The path currently under construction is called the current path. In PDF (unlike
PostScript), the current path is not part of the graphics state and is not saved and
restored along with the other graphics state parameters. PDF paths are strictly in-
ternal objects with no explicit representation. Once a path has been painted, it is
no longer defined; there is then no current path until a new one is begun with the
m or re operator.
The trailing endpoint of the segment most recently added to the current path is
referred to as the current point. If the current path is empty, the current point is
undefined. Most operators that add a segment to the current path start at the cur-
rent point; if the current point is undefined, an error is generated.
Table 4.9 shows the path construction operators. All operands are numbers de-
noting coordinates in user space.
TABLE 4.9 Path construction operators
OPERANDS
OPERATOR
DESCRIPTION
x y
m
Begin a new subpath by moving the current point to coordinates
(x, y), omitting any connecting line segment. If the previous path
construction operator in the current path was also m, the new m
overrides it; no vestige of the previous m operation remains in the
path.
x y
l (lowercase L)
Append a straight line segment from the current point to the point
(x, y). The new current point is (x, y).
x1 y1 x2 y2 x3 y3
c
Append a cubic Bézier curve to the current path. The curve extends
from the current point to the point (x3 , y3 ), using (x1 , y1 ) and
(x2 , y2 ) as the Bézier control points (see “Cubic Bézier Curves,” be-
low). The new current point is (x3 , y3 ).
x2 y2 x3 y3
v
Append a cubic Bézier curve to the current path. The curve extends
from the current point to the point (x3 , y3 ), using the current point
and (x2 , y2 ) as the Bézier control points (see “Cubic Bézier Curves,”
below). The new current point is (x3 , y3 ).
x1 y1 x3 y3
y
Append a cubic Bézier curve to the current path. The curve extends
from the current point to the point (x3 , y3 ), using (x1 , y1 ) and
(x3 , y3 ) as the Bézier control points (see “Cubic Bézier Curves,” be-
low). The new current point is (x3 , y3 ).
227
SECTION 4.4
Path Construction and Painting
OPERANDS
OPERATOR
DESCRIPTION
—
h
Close the current subpath by appending a straight line segment
from the current point to the starting point of the subpath. If the
current subpath is already closed, h does nothing.
This operator terminates the current subpath. Appending another
segment to the current path begins a new subpath, even if the new
segment begins at the endpoint reached by the h operation.
x
y width height
re
Append a rectangle to the current path as a complete subpath, with
lower-left corner (x, y) and dimensions width and height in user
space. The operation
x y width height re
is equivalent to
x y m
( x + width ) y l
( x + width )
( y + height ) l
x ( y + height ) l
h
Cubic Bézier Curves
Curved path segments are specified as cubic Bézier curves. Such curves are de-
fined by four points: the two endpoints (the current point P0 and the final point
P3 ) and two control points P1 and P2 . Given the coordinates of the four points, the
curve is generated by varying the parameter t from 0.0 to 1.0 in the following
equation:
R (t)
=
(1-t)3P0
+
3t(1 - t)2P1
+
3t2(1 - t)P2
+
t3P3
When t = 0.0, the value of the function R (t) coincides with the current point P0 ;
when t = 1.0, R (t) coincides with the final point P3 . Intermediate values of t gen-
erate intermediate points along the curve. The curve does not, in general, pass
through the two control points P1 and P2 .
228
CHAPTER 4
Graphics
Cubic Bézier curves have two useful properties:
• The curve can be very quickly split into smaller pieces for rapid rendering.
• The curve is contained within the convex hull of the four points defining the
curve, most easily visualized as the polygon obtained by stretching a rubber
band around the outside of the four points. This property allows rapid testing
of whether the curve lies completely outside the visible region, and hence does
not have to be rendered.
The Bibliography lists several books that describe cubic Bézier curves in more
depth.
The most general PDF operator for constructing curved path segments is the c
operator, which specifies the coordinates of points P1 , P2 , and P3 explicitly, as
shown in Figure 4.8. (The starting point, P0 , is defined implicitly by the current
point.)
P2 (x2, y2)
P1 (x1, y1)
P3 (x3, y3)
P0 (current point)
x1 y1 x2 y2 x3 y3 c
FIGURE 4.8 Cubic Bézier curve generated by the c operator
229
SECTION 4.4
Path Construction and Painting
Two more operators, v and y, each specify one of the two control points implic-
itly (see Figure 4.9). In both of these cases, one control point and the final point
of the curve are supplied as operands; the other control point is implied:
• For the v operator, the first control point coincides with initial point of the
curve.
• For the y operator, the second control point coincides with final point of the
curve.
(x2 , y2 )
(x1 , y1 )
(x3 , y3 )
(x3 , y3 )
Current point
Current point
x2 y2 x3 y3 v
x1 y1 x3 y3 y
FIGURE 4.9 Cubic Bézier curves generated by the v and y operators
4.4.2
Path-Painting Operators
The path-painting operators end a path object, causing it to be painted on the
current page in the manner that the operator specifies. The principal path-
painting operators are S (for stroking) and f (for filling). Variants of these opera-
tors combine stroking and filling in a single operation or apply different rules for
determining the area to be filled. Table 4.10 lists all the path-painting operators.
230
CHAPTER 4
Graphics
TABLE 4.10 Path-painting operators
OPERANDS
OPERATOR
DESCRIPTION
—
S
Stroke the path.
—
s
Close and stroke the path. This operator has the same effect as the sequence h S.
—
f
Fill the path, using the nonzero winding number rule to determine the region to fill
(see “Nonzero Winding Number Rule” on page 232). Any subpaths that are open
are implicitly closed before being filled.
—
F
Equivalent to f; included only for compatibility. Although PDF consumer applica-
tions must be able to accept this operator, PDF producer applications should use f
instead.
—
f*
Fill the path, using the even-odd rule to determine the region to fill (see “Even-Odd
Rule” on page 233).
—
B
Fill and then stroke the path, using the nonzero winding number rule to determine
the region to fill. This operator produces the same result as constructing two identi-
cal path objects, painting the first with f and the second with S. Note, however, that
the filling and stroking portions of the operation consult different values of several
graphics state parameters, such as the current color. See also “Special Path-Painting
Considerations” on page 569.
—
B*
Fill and then stroke the path, using the even-odd rule to determine the region to fill.
This operator produces the same result as B, except that the path is filled as if with
f* instead of f. See also “Special Path-Painting Considerations” on page 569.
—
b
Close, fill, and then stroke the path, using the nonzero winding number rule to de-
termine the region to fill. This operator has the same effect as the sequence h B. See
also “Special Path-Painting Considerations” on page 569.
—
b*
Close, fill, and then stroke the path, using the even-odd rule to determine the re-
gion to fill. This operator has the same effect as the sequence h B*. See also “Special
Path-Painting Considerations” on page 569.
—
n
End the path object without filling or stroking it. This operator is a path-painting
no-op, used primarily for the side effect of changing the current clipping path (see
Section 4.4.3, “Clipping Path Operators”).
231
SECTION 4.4
Path Construction and Painting
Stroking
The S operator paints a line along the current path. The stroked line follows each
straight or curved segment in the path, centered on the segment with sides paral-
lel to it. Each of the path’s subpaths is treated separately.
The results of the S operator depend on the current settings of various parameters
in the graphics state (see Section 4.3, “Graphics State,” for further information on
these parameters):
• The width of the stroked line is determined by the current line width parameter
(“Line Width” on page 215).
• The color or pattern of the line is determined by the current color and color
space for stroking operations.
• The line can be painted either solid or with a dash pattern, as specified by the
current line dash pattern (“Line Dash Pattern” on page 217).
• If a subpath is open, the unconnected ends are treated according to the current
line cap style, which may be butt, rounded, or square (“Line Cap Style” on page
216).
• Wherever two consecutive segments are connected, the joint between them is
treated according to the current line join style, which may be mitered, rounded,
or beveled (“Line Join Style” on page 216). Mitered joins are also subject to the
current miter limit (“Miter Limit” on page 217).
Note: Points at which unconnected segments happen to meet or intersect receive
no special treatment. In particular, using an explicit l operator to give the appear-
ance of closing a subpath, rather than using h, may result in a messy corner, be-
cause line caps are applied instead of a line join.
• The stroke adjustment parameter (PDF 1.2) specifies that coordinates and line
widths be adjusted automatically to produce strokes of uniform thickness
despite rasterization effects (Section 6.5.4, “Automatic Stroke Adjustment”).
If a subpath is degenerate (consists of a single-point closed path or of two or
more points at the same coordinates), the S operator paints it only if round line
caps have been specified, producing a filled circle centered at the single point. If
butt or projecting square line caps have been specified, S produces no output, be-
cause the orientation of the caps would be indeterminate. (This rule applies only
to zero-length subpaths of the path being stroked, and not to zero-length dashes
232
CHAPTER 4
Graphics
in a dash pattern. In the latter case, the line caps are always painted, since their
orientation is determined by the direction of the underlying path.) A single-
point open subpath (specified by a trailing m operator) produces no output.
Filling
The f operator uses the current nonstroking color to paint the entire region en-
closed by the current path. If the path consists of several disconnected subpaths, f
paints the insides of all subpaths, considered together. Any subpaths that are open
are implicitly closed before being filled.
If a subpath is degenerate (consists of a single-point closed path or of two or more
points at the same coordinates), f paints the single device pixel lying under that
point; the result is device-dependent and not generally useful. A single-point
open subpath (specified by a trailing m operator) produces no output.
For a simple path, it is intuitively clear what region lies inside. However, for a
more complex path—for example, a path that intersects itself or has one subpath
that encloses another—it is not always obvious which points lie inside the path.
The path machinery uses one of two rules for determining which points lie inside
a path: the nonzero winding number rule and the even-odd rule, both discussed in
detail below.
The nonzero winding number rule is more versatile than the even-odd rule and is
the standard rule the f operator uses. Similarly, the W operator uses this rule to
determine the inside of the current clipping path. The even-odd rule is occasion-
ally useful for special effects or for compatibility with other graphics systems; the
f* and W* operators invoke this rule.
Nonzero Winding Number Rule
The nonzero winding number rule determines whether a given point is inside a
path by conceptually drawing a ray from that point to infinity in any direction
and then examining the places where a segment of the path crosses the ray. Start-
ing with a count of 0, the rule adds 1 each time a path segment crosses the ray
from left to right and subtracts 1 each time a segment crosses from right to left.
After counting all the crossings, if the result is 0, the point is outside the path;
otherwise, it is inside.
233
SECTION 4.4
Path Construction and Painting
Note: The method just described does not specify what to do if a path segment coin-
cides with or is tangent to the chosen ray. Since the direction of the ray is arbitrary,
the rule simply chooses a ray that does not encounter such problem intersections.
For simple convex paths, the nonzero winding number rule defines the inside
and outside as one would intuitively expect. The more interesting cases are those
involving complex or self-intersecting paths like the ones shown in Figure 4.10.
For a path consisting of a five-pointed star, drawn with five connected straight
line segments intersecting each other, the rule considers the inside to be the en-
tire area enclosed by the star, including the pentagon in the center. For a path
composed of two concentric circles, the areas enclosed by both circles are consid-
ered to be inside, provided that both are drawn in the same direction. If the circles
are drawn in opposite directions, only the doughnut shape between them is in-
side, according to the rule; the doughnut hole is outside.
FIGURE 4.10 Nonzero winding number rule
Even-Odd Rule
An alternative to the nonzero winding number rule is the even-odd rule. This rule
determines whether a point is inside a path by drawing a ray from that point in
any direction and simply counting the number of path segments that cross the
ray, regardless of direction. If this number is odd, the point is inside; if even, the
point is outside. This yields the same results as the nonzero winding number rule
for paths with simple shapes, but produces different results for more complex
shapes.
Figure 4.11 shows the effects of applying the even-odd rule to complex paths. For
the five-pointed star, the rule considers the triangular points to be inside the path,
234
CHAPTER 4
Graphics
but not the pentagon in the center. For the two concentric circles, only the dough-
nut shape between the two circles is considered inside, regardless of the direc-
tions in which the circles are drawn.
FIGURE 4.11 Even-odd rule
4.4.3
Clipping Path Operators
The graphics state contains a current clipping path that limits the regions of the
page affected by painting operators. The closed subpaths of this path define the
area that can be painted. Marks falling inside this area are applied to the page;
those falling outside it are not. (“Filling” on page 232 discusses precisely what is
considered to be inside a path.)
Note: In the context of the transparent imaging model (PDF 1.4), the current clipping
path constrains an object’s shape (see Section 7.1, “Overview of Transparency”). The
effective shape is the intersection of the object’s intrinsic shape with the clipping path;
the source shape value is 0.0 outside this intersection. Similarly, the shape of a trans-
parency group (defined as the union of the shapes of its constituent objects) is influ-
enced both by the clipping path in effect when each of the objects is painted and by the
one in effect at the time the group’s results are painted onto its backdrop.
The initial clipping path includes the entire page. A clipping path operator (W or
W*, shown in Table 4.11) may appear after the last path construction operator
and before the path-painting operator that terminates a path object. Although the
clipping path operator appears before the painting operator, it does not alter the
clipping path at the point where it appears. Rather, it modifies the effect of the
succeeding painting operator. After the path has been painted, the clipping path
in the graphics state is set to the intersection of the current clipping path and the
newly constructed path.
235
SECTION 4.5
Color Spaces
TABLE 4.11 Clipping path operators
OPERANDS OPERATOR DESCRIPTION
—
W
Modify the current clipping path by intersecting it with the current path, using the
nonzero winding number rule to determine which regions lie inside the clipping
path.
—
W*
Modify the current clipping path by intersecting it with the current path, using the
even-odd rule to determine which regions lie inside the clipping path.
Note: In addition to path objects, text objects can also be used for clipping; see Sec-
tion 5.2.5, “Text Rendering Mode.”
The n operator (see Table 4.10) is a no-op path-painting operator; it causes no
marks to be placed on the page, but can be used with a clipping path operator to
establish a new clipping path. That is, after a path has been constructed, the se-
quence W n intersects that path with the current clipping path to establish a new
clipping path.
There is no way to enlarge the current clipping path or to set a new clipping path
without reference to the current one. However, since the clipping path is part of
the graphics state, its effect can be localized to specific graphics objects by en-
closing the modification of the clipping path and the painting of those objects
between a pair of q and Q operators (see Section 4.3.1, “Graphics State Stack”).
Execution of the Q operator causes the clipping path to revert to the value that
was saved by the q operator before the clipping path was modified.
4.5
Color Spaces
PDF includes powerful facilities for specifying the colors of graphics objects to be
painted on the current page. The color facilities are divided into two parts:
• Color specification. A PDF file can specify abstract colors in a device-
independent way. Colors can be described in any of a variety of color systems,
or color spaces. Some color spaces are related to device color representation
(grayscale, RGB, CMYK), others to human visual perception (CIE-based). Cer-
tain special features are also modeled as color spaces: patterns, color mapping,
separations, and high-fidelity and multitone color.
236
CHAPTER 4
Graphics
• Color rendering. The application reproduces colors on the raster output device
by a multiple-step process that includes some combination of color conversion,
gamma correction, halftoning, and scan conversion. Some aspects of this pro-
cess use information that is specified in PDF. However, unlike the facilities for
color specification, the color-rendering facilities are device-dependent and or-
dinarily should not be included in a page description.
Figures 4.12 and 4.13 on pages 238 and 239 illustrate the division between PDF’s
(device-independent) color specification and (device-dependent) color-render-
ing facilities. This section describes the color specification features, covering
everything that most PDF documents need to specify colors. The facilities for
controlling color rendering are described in Chapter 6; a PDF document should
use these facilities only to configure or calibrate an output device or to achieve
special device-dependent effects.
4.5.1
Color Values
As described in Section 4.4.2, “Path-Painting Operators,” marks placed on the
page by operators such as f and S have a color that is determined by the current
color parameter of the graphics state. A color value consists of one or more color
components, which are usually numbers. For example, a gray level can be speci-
fied by a single number ranging from 0.0 (black) to 1.0 (white). Full color values
can be specified in any of several ways; a common method uses three numeric
values to specify red, green, and blue components.
Color values are interpreted according to the current color space, another pa-
rameter of the graphics state. A PDF content stream first selects a color space by
invoking the CS operator (for the stroking color) or the cs operator (for the non-
stroking color). It then selects color values within that color space with the SC
operator (stroking) or the sc operator (nonstroking). There are also conve-
nience operators—G, g, RG, rg, K, and k—that select both a color space and a
color value within it in a single step. Table 4.24 on page 287 lists all the color-
setting operators.
Sampled images (see Section 4.8, “Images”) specify the color values of individual
samples with respect to a color space designated by the image object itself. While
these values are independent of the current color space and color parameters in
the graphics state, all later stages of color processing treat them in exactly the
same way as color values specified with the SC or sc operator.
237
SECTION 4.5
Color Spaces
4.5.2
Color Space Families
Color spaces can be classified into color space families. Spaces within a family
share the same general characteristics; they are distinguished by parameter values
supplied at the time the space is specified. The families fall into three broad cate-
gories:
• Device color spaces directly specify colors or shades of gray that the output
device is to produce. They provide a variety of color specification methods,
including grayscale, RGB (red-green-blue), and CMYK (cyan-magenta-yellow-
black), corresponding to the color space families DeviceGray, DeviceRGB, and
DeviceCMYK. Since each of these families consists of just a single color space
with no parameters, they are often loosely referred to as the DeviceGray,
DeviceRGB, and DeviceCMYK color spaces.
• CIE-based color spaces are based on an international standard for color specifi-
cation created by the Commission Internationale de l’Éclairage (International
Commission on Illumination). These spaces specify colors in a way that is in-
dependent of the characteristics of any particular output device. Color space
families in this category include CalGray, CalRGB, Lab, and ICCBased. Individu-
al color spaces within these families are specified by means of dictionaries con-
taining the parameter values needed to define the space.
• Special color spaces add features or properties to an underlying color space.
They include facilities for patterns, color mapping, separations, and high-
fidelity and multitone color. The corresponding color space families are
Pattern, Indexed, Separation, and DeviceN. Individual color spaces within
these families are specified by means of additional parameters.
Table 4.12 summarizes the color space families supported by PDF. (See imple-
mentation note 47 in Appendix H.)
TABLE 4.12 Color space families
DEVICE
CIE-BASED
SPECIAL
DeviceGray (PDF 1.1)
CalGray (PDF 1.1)
Indexed (PDF 1.1)
DeviceRGB (PDF 1.1)
CalRGB (PDF 1.1)
Pattern (PDF 1.2)
DeviceCMYK (PDF 1.1)
Lab (PDF 1.1)
Separation (PDF 1.2)
ICCBased (PDF 1.3)
DeviceN (PDF 1.3)
238
CHAPTER 4
Graphics
Sources of
Color spaces
color values
Color values
A, B, C
CalRGB
sc, SC, sh,
BI, Do (image XObject)
A
CIE-
CalGray
based
sc, SC, sh,
Conversion
BI, Do (image XObject)
to internal
X, Y, Z
color
A, B, C
X, Y, Z
spaces
Lab
values
sc, SC, sh,
BI, Do (image XObject)
n
components
ICCBased
scn, SCN, sh,
BI, Do (image XObject)
Another
DefaultRGB
(3-component)
R, G, B
color space
DeviceRGB
rg, RG, sc, SC, sh,
BI, Do (image XObject)
Another
DefaultCMYK
(4-component)
Device
C, M, Y, K
color space
DeviceCMYK
color
k, K, sc, SC, sh,
spaces
BI, Do (image XObject)
Another
DefaultGray
(1-component)
gray
color space
DeviceGray
g, G, sc, SC, sh,
BI, Do (image XObject)
Alternative
Another
color
color space
transform
tint
Separation
scn, SCN, sh,
BI, Do (image XObject)
Alternative
Another
color
color space
n
transform
Special
components
color
DeviceN
scn, SCN, sh,
spaces
BI, Do (image XObject)
index
Table
Another
Indexed
sc, SC, sh,
lookup
color space
BI, Do (image XObject)
pattern
Another
Pattern
color space
scn, SCN
Pattern
dictionary
FIGURE 4.12 Color specification
239
SECTION 4.5
Color Spaces
Conversion
R, G, B
Device color values
X, Y, Z
from CIE-based
(depending on
C, M, Y, K
to device
results of
color space
gray
conversion)
(not specified by PDF)
R, G, B
Component(s)
of device’s
process
color model
Conversion
from input
Device’s
device color
process
C, M, Y, K
space to
colorant(s)
device’s
process color
model
Transfer
Halftones
functions
gray
(per
(per
component)
component)
UCR, BG
Any single
tint
device
colorant
n
components
Any n device
colorants
TR, HT
HT
FIGURE 4.13 Color rendering
240
CHAPTER 4
Graphics
A color space is defined by an array object whose first element is a name object
identifying the color space family. The remaining array elements, if any, are
parameters that further characterize the color space; their number and types vary
according to the particular family. For families that do not require parameters,
the color space can be specified simply by the family name itself instead of an
array.
A color space can be specified in two principal ways:
• Within a content stream, the CS or cs operator establishes the current color
space parameter in the graphics state. The operand is always a name object,
which either identifies one of the color spaces that need no additional parame-
ters (DeviceGray, DeviceRGB, DeviceCMYK, or some cases of Pattern) or is used
as a key in the ColorSpace subdictionary of the current resource dictionary (see
Section 3.7.2, “Resource Dictionaries”). In the latter case, the value of the dic-
tionary entry is in turn a color space array or name. A color space array is never
permitted inline within a content stream.
• Outside a content stream, certain objects, such as image XObjects, specify a
color space as an explicit parameter, often associated with the key ColorSpace.
In this case, the color space array or name is always defined directly as a PDF
object, not by an entry in the ColorSpace resource subdictionary. This conven-
tion also applies when color spaces are defined in terms of other color spaces.
The following operators set the current color space and current color parameters
in the graphics state:
• CS sets the stroking color space; cs sets the nonstroking color space.
• SC and SCN set the stroking color; sc and scn set the nonstroking color. De-
pending on the color space, these operators require one or more operands, each
specifying one component of the color value.
• G, RG, and K set the stroking color space implicitly and the stroking color as
specified by the operands; g, rg, and k do the same for the nonstroking color
space and color.
241
SECTION 4.5
Color Spaces
4.5.3
Device Color Spaces
The device color spaces enable a page description to specify color values that are
directly related to their representation on an output device. Color values in these
spaces map directly (or by simple conversions) to the application of device colo-
rants, such as quantities of ink or intensities of display phosphors. This enables a
PDF document to control colors precisely for a particular device, but the results
may not be consistent from one device to another.
Output devices form colors either by adding light sources together or by subtract-
ing light from an illuminating source. Computer displays and film recorders typi-
cally add colors; printing inks typically subtract them. These two ways of forming
colors give rise to two complementary methods of color specification, called ad-
ditive and subtractive color (see Plate 1). The most widely used forms of these two
types of color specification are known as RGB and CMYK, respectively, for the
names of the primary colors on which they are based. They correspond to the fol-
lowing device color spaces:
• DeviceGray controls the intensity of achromatic light, on a scale from black to
white.
• DeviceRGB controls the intensities of red, green, and blue light, the three addi-
tive primary colors used in displays.
• DeviceCMYK controls the concentrations of cyan, magenta, yellow, and black
inks, the four subtractive process colors used in printing.
Although the notion of explicit color spaces is a PDF 1.1 feature, the operators for
specifying colors in the device color spaces—G, g, RG, rg, K, and k—are available
in all versions of PDF. Beginning with PDF 1.2, colors specified in device color
spaces can optionally be remapped systematically into other color spaces; see
“Default Color Spaces” on page 257.
Note: In the transparent imaging model (PDF 1.4), the use of device color spaces is
subject to special treatment within a transparency group whose group color space is
CIE-based (see Sections 7.3, “Transparency Groups,” and 7.5.5, “Transparency
Group XObjects”). In particular, the device color space operators should be used
only if device color spaces have been remapped to CIE-based spaces by means of the
default color space mechanism. Otherwise, the results are implementation-
dependent and unpredictable.
242
CHAPTER 4
Graphics
DeviceGray Color Space
Black, white, and intermediate shades of gray are special cases of full color. A
grayscale value is represented by a single number in the range 0.0 to 1.0, where
0.0 corresponds to black, 1.0 to white, and intermediate values to different gray
levels. Example 4.2 shows alternative ways to select the DeviceGray color space
and a specific gray level within that space for stroking operations.
Example 4.2
/DeviceGray CS
% Set DeviceGray color space
gray SC
% Set gray level
gray G
% Set both in one operation
The CS and SC operators select the current stroking color space and current
stroking color separately; G sets them in combination. (The cs, sc, and g opera-
tors perform the same functions for nonstroking operations.) Setting either cur-
rent color space to DeviceGray initializes the corresponding current color to 0.0.
DeviceRGB Color Space
Colors in the DeviceRGB color space are specified according to the additive RGB
(red-green-blue) color model, in which color values are defined by three compo-
nents representing the intensities of the additive primary colorants red, green,
and blue. Each component is specified by a number in the range 0.0 to 1.0, where
0.0 denotes the complete absence of a primary component and 1.0 denotes maxi-
mum intensity. If all three components have equal intensity, the perceived result
theoretically is a pure gray on the scale from black to white. If the intensities are
not all equal, the result is some color other than a pure gray.
Example 4.3 shows alternative ways to select the DeviceRGB color space and a
specific color within that space for stroking operations.
Example 4.3
/DeviceRGB CS
% Set DeviceRGB color space
red green blue SC
% Set color
red green blue RG
% Set both in one operation
243
SECTION 4.5
Color Spaces
The CS and SC operators select the current stroking color space and current
stroking color separately; RG sets them in combination. (The cs, sc, and rg opera-
tors perform the same functions for nonstroking operations.) Setting either cur-
rent color space to DeviceRGB initializes the red, green, and blue components of
the corresponding current color to 0.0.
DeviceCMYK Color Space
The DeviceCMYK color space allows colors to be specified according to the sub-
tractive CMYK (cyan-magenta-yellow-black) model typical of printers and other
paper-based output devices. In theory, each of the three standard process colorants
used in printing (cyan, magenta, and yellow) absorbs one of the additive primary
colors (red, green, and blue, respectively). Black, a fourth standard process colo-
rant, absorbs all of the additive primaries in equal amounts. The four components
in a DeviceCMYK color value represent the concentrations of these process colo-
rants. Each component is specified by a number in the range 0.0 to 1.0, where 0.0
denotes the complete absence of a process colorant (that is, absorbs none of the
corresponding additive primary) and 1.0 denotes maximum concentration (ab-
sorbs as much as possible of the additive primary). Note that the sense of these
numbers is opposite to that of RGB color components.
Example 4.4 shows alternative ways to select the DeviceCMYK color space and a
specific color within that space for stroking operations.
Example 4.4
/DeviceCMYK CS
% Set DeviceCMYK color space
cyan magenta yellow black SC
% Set color
cyan magenta yellow black K
% Set both in one operation
The CS and SC operators select the current stroking color space and current strok-
ing color separately; K sets them in combination. (The cs, sc, and k operators per-
form the same functions for nonstroking operations.) Setting either current color
space to DeviceCMYK initializes the cyan, magenta, and yellow components of the
corresponding current color to 0.0 and the black component to 1.0.
244
CHAPTER 4
Graphics
4.5.4
CIE-Based Color Spaces
Calibrated color in PDF is defined in terms of an international standard used in
the graphic arts, television, and printing industries. CIE-based color spaces enable
a page description to specify color values in a way that is related to human visual
perception. The goal is for the same color specification to produce consistent re-
sults on different output devices, within the limitations of each device; Plate 2 il-
lustrates the kind of variation in color reproduction that can result from the use
of uncalibrated color on different devices. PDF 1.1 supports three CIE-based col-
or space families, named CalGray, CalRGB, and Lab; PDF 1.3 adds a fourth, named
ICCBased.
Note: In PDF 1.1, a color space family named CalCMYK was partially defined, with
the expectation that its definition would be completed in a future version. However,
this is no longer being considered. PDF 1.3 and later versions support calibrated
four-component color spaces by means of ICC profiles (see “ICCBased Color Spaces”
on page 252). PDF consumer applications should ignore CalCMYK color space at-
tributes and render colors specified in this family as if they had been specified using
DeviceCMYK.
The details of the CIE colorimetric system and the theory on which it is based are
beyond the scope of this book; see the Bibliography for sources of further in-
formation. The semantics of CIE-based color spaces are defined in terms of the
relationship between the space’s components and the tristimulus values X, Y, and
Z of the CIE 1931 XYZ space. The CalRGB and Lab color spaces (PDF 1.1) are
special cases of three-component CIE-based color spaces, known as CIE-based
ABC color spaces. These spaces are defined in terms of a two-stage, nonlinear
transformation of the CIE 1931 XYZ space. The formulation of such color spaces
models a simple zone theory of color vision, consisting of a nonlinear trichro-
matic first stage combined with a nonlinear opponent-color second stage. This
formulation allows colors to be digitized with minimum loss of fidelity, an impor-
tant consideration in sampled images.
Color values in a CIE-based ABC color space have three components, arbitrarily
named A, B, and C. The first stage transforms these components by first forcing
their values to a specified range, then applying decoding functions, and then mul-
tiplying the results by a 3-by-3 matrix, producing three intermediate components
arbitrarily named L, M, and N. The second stage transforms these intermediate
components in a similar fashion, producing the final X, Y, and Z components of
the CIE 1931 XYZ space (see Figure 4.14).
245
SECTION 4.5
Color Spaces
Decode ABC
Decode LMN
A
L
X
Matrix ABC
Matrix LMN
B
M
Y
C
N
Z
FIGURE 4.14 Component transformations in a CIE-based ABC color space
Color spaces in the CIE-based families are defined by an array
[ name dictionary ]
where name is the name of the family and dictionary is a dictionary containing
parameters that further characterize the space. The entries in this dictionary have
specific interpretations that depend on the color space; some entries are required
and some are optional. See the sections on specific color space families, below, for
details.
Setting the current stroking or nonstroking color space to any CIE-based color
space initializes all components of the corresponding current color to 0.0 (unless
the range of valid values for a given component does not include 0.0, in which
case the nearest valid value is substituted.)
Note: The model and terminology used here—CIE-based ABC (above) and CIE-
based A (below)—are derived from the PostScript language, which supports these
color space families in their full generality. PDF supports specific useful cases of CIE-
based ABC and CIE-based A spaces; most others can be represented as ICCBased
spaces.
CalGray Color Spaces
A CalGray color space (PDF 1.1) is a special case of a single-component CIE-
based color space, known as a CIE-based A color space. This type of space is the
one-dimensional (and usually achromatic) analog of CIE-based ABC spaces.
Color values in a CIE-based A space have a single component, arbitrarily named
A. Figure 4.15 illustrates the transformations of the A component to X, Y, and Z
components of the CIE 1931 XYZ space.
246
CHAPTER 4
Graphics
Decode A
Decode LMN
L
X
Matrix A
Matrix LMN
A
M
Y
N
Z
FIGURE 4.15 Component transformations in a CIE-based A color space
A CalGray color space is a CIE-based A color space with only one transformation
stage instead of two. In this type of space, A represents the gray component of a
calibrated gray space. This component must be in the range 0.0 to 1.0. The decod-
ing function (denoted by “Decode A” in Figure 4.15) is a gamma function whose
coefficient is specified by the Gamma entry in the color space dictionary (see Ta-
ble 4.13). The transformation matrix denoted by “Matrix A” in the figure is de-
rived from the dictionary’s WhitePoint entry, as described below. Since there is no
second transformation stage, “Decode LMN” and “Matrix LMN” are implicitly
taken to be identity transformations.
TABLE 4.13 Entries in a CalGray color space dictionary
KEY
TYPE
VALUE
WhitePoint
array
(Required) An array of three numbers [ XW YW ZW ] specifying the tri-
stimulus value, in the CIE 1931 XYZ space, of the diffuse white point; see
“CalRGB Color Spaces,” below, for further discussion. The numbers XW and
ZW must be positive, and YW must be equal to 1.0.
BlackPoint
array
(Optional) An array of three numbers [ XB YB ZB ] specifying the tristimulus
value, in the CIE 1931 XYZ space, of the diffuse black point; see “CalRGB
Color Spaces,” below, for further discussion. All three of these numbers must
be non-negative. Default value: [ 0.0 0.0 0.0 ].
Gamma
number
(Optional) A number G defining the gamma for the gray (A) component. G
must be positive and is generally greater than or equal to 1. Default value: 1.
247
SECTION 4.5
Color Spaces
The transformation defined by the Gamma and WhitePoint entries is
X = L = XW × AG
Y = M = YW × AG
Z = N = ZW × AG
In other words, the A component is first decoded by the gamma function, and the
result is multiplied by the components of the white point to obtain the L, M, and
N components of the intermediate representation. Since there is no second stage,
the L, M, and N components are also the X, Y, and Z components of the final rep-
resentation.
The following examples illustrate interesting and useful special cases of CalGray
spaces. Example 4.5 establishes a space consisting of the Y dimension of the CIE
1931 XYZ space with the CCIR XA/11-recommended D65 white point.
Example 4.5
[
/CalGray
<< /WhitePoint [ 0.9505 1.0000 1.0890 ] >>
]
Example
4.6 establishes a calibrated gray space with the CCIR XA/11-
recommended D65 white point and opto-electronic transfer function.
Example 4.6
[
/CalGray
<< /WhitePoint [ 0.9505 1.0000 1.0890 ]
/Gamma 2.222
>>
]
CalRGB Color Spaces
A CalRGB color space is a CIE-based ABC color space with only one transforma-
tion stage instead of two. In this type of space, A, B, and C represent calibrated
red, green, and blue color values. These three color components must be in the
range 0.0 to 1.0; component values falling outside that range are adjusted to the
nearest valid value without error indication. The decoding functions (denoted by
“Decode ABC” in Figure 4.14 on page 245) are gamma functions whose coeffi-
248
CHAPTER 4
Graphics
cients are specified by the Gamma entry in the color space dictionary (see Table
4.14). The transformation matrix denoted by “Matrix ABC” in Figure 4.14 is de-
fined by the dictionary’s Matrix entry. Since there is no second transformation
stage, “Decode LMN” and “Matrix LMN” are implicitly taken to be identity trans-
formations.
TABLE 4.14 Entries in a CalRGB color space dictionary
KEY
TYPE
VALUE
WhitePoint
array
(Required) An array of three numbers [ XW YW ZW ] specifying the tristimulus value,
in the CIE 1931 XYZ space, of the diffuse white point; see below for further discus-
sion. The numbers XW and ZW must be positive, and YW must be equal to 1.0.
BlackPoint
array
(Optional) An array of three numbers [ XB YB ZB ] specifying the tristimulus value, in
the CIE 1931 XYZ space, of the diffuse black point; see below for further discussion.
All three of these numbers must be non-negative. Default value: [ 0.0 0.0 0.0 ].
Gamma
array
(Optional) An array of three numbers [ GR GG GB ] specifying the gamma for the red,
green, and blue (A, B, and C) components of the color space. Default value:
[ 1.0
1.0
1.0 ].
Matrix
array
(Optional) An array of nine numbers [ XA YA ZA XB YB ZB XC YC ZC ] specifying
the linear interpretation of the decoded A, B, and C components of the color space
with respect to the final XYZ representation. Default value: the identity matrix
[ 1
0 0 0 1 0 0 0 1 ].
The WhitePoint and BlackPoint entries in the color space dictionary control the
overall effect of the CIE-based gamut mapping function described in Section 6.1,
“CIE-Based Color to Device Color.” Typically, the colors specified by WhitePoint
and BlackPoint are mapped to the nearly lightest and nearly darkest achromatic
colors that the output device is capable of rendering in a way that preserves color
appearance and visual contrast.
WhitePoint is assumed to represent the diffuse achromatic highlight, not a specu-
lar highlight. Specular highlights, achromatic or otherwise, are often reproduced
lighter than the diffuse highlight. BlackPoint is assumed to represent the diffuse
achromatic shadow; its value is typically limited by the dynamic range of the in-
put device. In images produced by a photographic system, the values of
WhitePoint and BlackPoint vary with exposure, system response, and artistic in-
tent; hence, their values are image-dependent.
Большое спасибо!
Ваше мнение очень важно для нас.

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