Repository navigation
PDF20 Spec 08 Graphics State
Part of: PDF20-Spec-08-Graphics
Navigation: PDF20-Spec-08-Coordinate | PDF20-Spec-Index | PDF20-Spec-08-Graphics-Objects
8.3
Coordinate systems
8.3.1 General Coordinate systems define the canvas on which all painting occurs. They determine the position, orientation, and size of the text, graphics, and images that appear on a page. This subclause describes each of the coordinate systems used in PDF, how they are related, and how transformations among them are specified. NOTE
The coordinate systems discussed in this subclause apply to two-dimensional graphics. PDF 1.6 introduced the ability to display 3D artwork, in which objects are described in a threedimensional coordinate system, as described in 13.6.5, "Coordinate systems for 3D".
8.3.2 Coordinate spaces 8.3.2.1
General
Paths and positions shall be defined in terms of pairs of coordinates on the Cartesian plane. A coordinate pair is a pair of real numbers x and y that locate a point horizontally and vertically within a two-dimensional coordinate space. A coordinate space is determined by the following properties with respect to the current page: •
The location of the origin
•
The orientation of the x and y axes
•
The lengths of the units along each axis
PDF defines several coordinate spaces in which the coordinates specifying graphics objects shall be interpreted. The following subclauses describe these spaces and the relationships among them. Transformations among coordinate spaces shall be defined by transformation matrices, which can specify any linear mapping of two-dimensional coordinates, including translation, scaling, rotation, reflection, and skewing. Transformation matrices are discussed in 8.3.3, "Common transformations" © ISO 2020 – All rights reserved
149
ISO 32000-2:2020(E)
and 8.3.4, "Transformation matrices".
8.3.2.2
Device space
The contents of a page ultimately appear on a raster output device such as a display or a printer. Such devices vary greatly in the built-in coordinate systems they use to address pixels within their imageable areas. A particular device’s coordinate system is called its device space. The origin of the device space on different devices can fall in different places on the output page; on displays, the origin can vary depending on the window system. Because the paper or other output medium moves through different printers and imagesetters in different directions, the axes of their device spaces may be oriented differently. For instance, vertical (y) coordinates may increase from the top of the page to the bottom on some devices and from bottom to top on others. Finally, different devices have different resolutions; some even have resolutions that differ in the horizontal and vertical directions. NOTE EXAMPLE
If coordinates in a PDF file were specified in device space, the file would be device-dependent and would appear differently on different devices. Images specified in the typical device spaces of a 72-pixel-per-inch display and a 600-dot-per-inch printer would differ in size by more than a factor of 8; an 8-inch line segment on the display would appear less than 1 inch long on the printer. "Figure 10 — Device space" shows how the same graphics object, specified in device space, can appear drastically different when rendered on different output devices.
Figure 10 — Device space
8.3.2.3
User space
To avoid the device-dependent effects of specifying objects in device space, PDF defines a deviceindependent coordinate system that always bears the same relationship to the current page, regardless of the output device on which printing or displaying occurs. This device-independent coordinate system is called user space. The user space coordinate system shall be initialised to a default state for each page of a document. The CropBox entry in the page dictionary shall specify the rectangle of user space corresponding to the visible area of the intended output medium (display window or printed page). The positive x axis extends horizontally to the right and the positive y axis vertically upward, as in standard mathematical practice (subject to alteration by the Rotate entry in the page dictionary). The length of a unit along both the x and y axes is set by the UserUnit entry (PDF 1.6) in the page dictionary (see "Table 31 — Entries in a page object"). If that entry is not present or supported, the default value of 1 ⁄ 72 inch is used. This coordinate system is called default user space. 150
© ISO 2020 – All rights reserved
ISO 32000-2:2020(E)
NOTE 1
In the PostScript language, the origin of default user space always corresponds to the lower-left corner of the output medium. While this convention is common in PDF documents as well, it is not required; the page dictionary’s CropBox entry can specify any rectangle of default user space to be made visible on the medium.
NOTE 2
The default for the size of the unit in default user space (1 ⁄ 72 inch) is approximately the same as a point, a unit widely used in the printing industry. It is not exactly the same, however; there is no universal definition of a point.
Conceptually, user space is an infinite plane. Only a small portion of this plane corresponds to the imageable area of the output device: a rectangular region defined by the CropBox entry in the page dictionary. The region of default user space that is viewed or printed can be different for each page and is described in 14.11.2, "Page boundaries". Coordinates in user space (as in any other coordinate space) may be specified as either integers or real numbers, and the unit size in default user space does not constrain positions to any arbitrary grid. The resolution of coordinates in user space is not related to the resolution of pixels in device space. The transformation from user space to device space is defined by the current transformation matrix (CTM), an element of the PDF graphics state (see 8.4, "Graphics state"). A PDF reader may adjust the CTM for the native resolution of a particular output device, maintaining the device-independence of the PDF page description. "Figure 11 — User space" shows how this allows an object specified in user space to appear the same regardless of the device on which it is rendered. The default user space provides a consistent, dependable starting place for PDF page descriptions regardless of the output device used. If necessary, a PDF content stream may modify user space to be more suitable to its needs by applying the coordinate transformation operator, cm (see 8.4.4, "Graphics state operators"). Thus, what might appear to be absolute coordinates in a content stream are not absolute with respect to the current page because they are expressed in a coordinate system that can slide around and shrink or expand. Coordinate system transformation not only enhances deviceindependence but is a useful tool in its own right. EXAMPLE
A content stream originally composed to occupy an entire page can be incorporated without change as an element of another page by shrinking the coordinate system in which it is drawn.
Figure 11 — User space © ISO 2020 – All rights reserved
151
ISO 32000-2:2020(E)
8.3.2.4
Other coordinate spaces
In addition to device space and user space, PDF uses a variety of other coordinate spaces for specialised purposes: •
The coordinates of text shall be specified in text space. The transformation from text space to user space shall be defined by a text matrix in combination with several text-related parameters in the graphics state (see 9.4.2, "Text-positioning operators").
•
Character glyphs in a font shall be defined in glyph space ("see 9.2.4, "Glyph positioning and metrics"). The transformation from glyph space to text space shall be defined by the font matrix. For most types of fonts, this matrix shall be predefined to map 1000 units of glyph space to 1 unit of text space; for Type 3 fonts, the font matrix shall be given explicitly in the font dictionary ("see 9.6.4, "Type 3 fonts").
•
All sampled images shall be defined in image space. The transformation from image space to user space shall be predefined and cannot be changed. All images shall be 1 unit wide by 1 unit high in user space, regardless of the number of samples in the image. To be painted, an image shall be mapped to a region of the page by temporarily altering the CTM.
•
A form XObject (discussed in 8.10, "Form XObjects") is a self-contained content stream that can be treated as a graphical element within another content stream. The space in which it is defined is called form space. The transformation from form space to user space shall be specified by a form matrix contained in the form XObject.
•
PDF 1.2 defined a type of colour known as a pattern, discussed in 8.7, "Patterns". A pattern shall be defined either by a content stream that shall be invoked repeatedly to tile an area or by a shading whose colour is a function of position. The space in which a pattern is defined is called pattern space. The transformation from pattern space to user space shall be specified by a pattern matrix contained in the pattern.
•
PDF 1.6 embedded 3D artwork, which is described in three-dimensional coordinates (see 13.6.5, "Coordinate systems for 3D") that are projected into an annotation’s target coordinate system (see 13.6.2, "3D Annotations").
8.3.2.5
Relationships among coordinate spaces
"Figure 12 — Relationships among coordinate systems" shows the relationships among the coordinate spaces described above. Each arrow in the figure represents a transformation from one coordinate space to another. PDF allows modifications to many of these transformations.
152
© ISO 2020 – All rights reserved
ISO 32000-2:2020(E)
Figure 12 — Relationships among coordinate systems Because PDF coordinate spaces are defined relative to one another, changes made to one transformation can affect the appearance of objects defined in several coordinate spaces. EXAMPLE
A change in the CTM, which defines the transformation from user space to device space, affects forms, text, images, and patterns, since they are all upstream from user space.
8.3.3 Common transformations A transformation matrix specifies the relationship between two coordinate spaces. By modifying a transformation matrix, objects can be scaled, rotated, translated, or transformed in other ways. A transformation matrix in PDF shall be specified by six numbers, usually in the form of an array containing six elements. In its most general form, this array is denoted [a b c d e f]; it can represent any linear transformation from one coordinate system to another. This subclause lists the arrays that specify the most common transformations; 8.3.4, "Transformation matrices", discusses more mathematical details of transformations, including information on specifying transformations that are combinations of those listed here: •
Translations shall be specified as [ 1 0 0 1 𝑡𝑥 𝑡𝑦 ], where tx and ty shall be the distances to translate the origin of the coordinate system in the horizontal and vertical dimensions, respectively.
•
Scaling shall be obtained by [ 𝑠𝑥 0 0 𝑠𝑦 0 0]. This scales the coordinates so that 1 unit in the horizontal and vertical dimensions of the new coordinate system is the same size as sx and sy units, respectively, in the previous coordinate system.
•
Rotations shall be produced by [rc rs -rs rc 0 0], where rc = cos(q) and rs = sin(q) which has the effect of rotating the coordinate system axes by an angle q counter clockwise.
•
Skew shall be specified by [1 wx wy 1 0 0], where wx = tan(a) and wy = tan(b) which skews the x axis by an angle a and the y axis by an angle b.
"Figure 13 — Effects of coordinate transformations" shows examples of each transformation. The directions of translation, rotation, and skew shown in the figure correspond to positive values of the array elements.
© ISO 2020 – All rights reserved
153
ISO 32000-2:2020(E)
Figure 13 — Effects of coordinate transformations NOTE 1
If several transformations are combined, the order in which they are applied is significant. For example, first scaling and then translating the x axis is not the same as first translating and then scaling it. In general, to obtain the expected results, transformations need to be done in the following order: Translate, Rotate, Scale or skew.
"Figure 14 — Effect of transformation order" shows the effect of the order in which transformations are applied. The figure shows two sequences of transformations applied to a coordinate system. After each successive transformation, an outline of the letter n is drawn.
Figure 14 — Effect of transformation order NOTE 2
The following transformations are shown in the figure: a translation of 10 units in the x direction and 20 units in the y direction; a rotation of 30 degrees; a scaling by a factor of 3 in the x direction In the figure, the axes are shown with a dash pattern having a 2-unit dash and a 2-unit gap. In addition, the original (untransformed) axes are shown in a lighter colour for reference. Notice that the scale-rotate-translate ordering results in a distortion of the coordinate system, leaving
154
© ISO 2020 – All rights reserved
ISO 32000-2:2020(E)
the x and y axes no longer perpendicular; the recommended translate-rotate-scale ordering results in no distortion.
8.3.4 Transformation matrices This subclause discusses the mathematics of transformation matrices. To understand the mathematics of coordinate transformations in PDF, it is vital to remember two points: •
Transformations alter coordinate systems, not graphics objects. All objects painted before a transformation is applied shall be unaffected by the transformation. Objects painted after the transformation is applied shall be interpreted in the transformed coordinate system.
•
Transformation matrices specify the transformation from the new (transformed) coordinate system to the original (untransformed) coordinate system. All coordinates used after the transformation shall be expressed in the transformed coordinate system. PDF applies the transformation matrix to find the equivalent coordinates in the untransformed coordinate system.
NOTE 1
Many computer graphics textbooks consider transformations of graphics objects rather than of coordinate systems. Although either approach is correct and self-consistent, some details of the calculations differ depending on which point of view is taken.
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 can be 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, in most cases in PDF it shall be specified as the six-element array [a b c d e f]. Coordinate transformations shall be expressed as matrix multiplications: [𝑥 ′
𝑦′
1] = [𝑥
𝑦
a b 0 1] × [c d 0] e f 1
Because PDF transformation matrices specify the conversion from the transformed coordinate system to the original (untransformed) coordinate system, x′ and y′ in this equation shall be the coordinates in the untransformed coordinate system, and x and y shall be the coordinates in the transformed system. The multiplication is carried out as follows: 𝑥′ = a × 𝑥 + c × 𝑦 + e 𝑦′ = b × 𝑥 + d × 𝑦 + 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 equivalent matrix representing the © ISO 2020 – All rights reserved
155
ISO 32000-2:2020(E)
composite transformation. NOTE 2
Matrix multiplication is not commutative — the order in which matrices are multiplied is significant. Consider a sequence of two transformations: a scaling transformation 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 specifying the scaling and MC the current transformation matrix, which transforms user space to device space. Recalling that coordinates are always specified in the transformed space, the correct order of transformations first converts the scaled coordinates to default user space and then converts 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 shall be multiplied before (premultiplied with) the existing transformation matrix. This result is true in general for PDF: when a sequence of transformations is carried 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): 𝑀′ = 𝑀𝑇 × 𝑀 NOTE 3
Navigation: PDF20-Spec-08-Coordinate | PDF20-Spec-Index | PDF20-Spec-08-Graphics-Objects