跳转至

12.9 测量属性

12.9 Measurement Properties

PDF 文档,例如由 CAD 软件创建的文档,可能包含旨在表示现实世界物体的图形。这些文档的用户通常需要有关相应现实世界物体的比例和测量单位及其与 PDF 用户空间中单位的关系的信息。

这些信息使符合要求的阅读器的用户能够执行测量,从而获得文档创建者所期望的单位结果。在此上下文中,测量是一个标准函数的结果,该函数输入为一组 n 个坐标对

\[\left \{ (x_{_0},y_{_0}),\dots ,(x_{_{n-1}},y_{_{n-1}}) \right \}\]

并根据测量类型输出一个数字。例如,距离测量等同于

\[ \sum_{i=1}^{n-2}\sqrt{(x_i-x_{i+1})^2+(y_i-y_{i+1})^2}\]

对于 \(n\ge2\)

从 PDF 1.6 开始,这些信息可以存储在一个度量字典中(参见 表 261)。度量字典提供与文档中的矩形区域(称为 视口)相关的测量单位的信息。

视口(PDF 1.6)是页面上的一个矩形区域。页面字典中的可选 VP 条目(参见 表 30)应指定一个视口字典数组,其条目应如 表 260 所示。视口允许在页面的不同区域使用不同的测量比例(由 Measure 条目指定),如果需要的话。

VP 数组中的字典应按绘制顺序排列。由于视口可能重叠,为了确定页面上任何一点要使用的视口,应检查数组中的字典,从最后一个字典开始,按反向顺序遍历,并选择第一个 BBox 条目包含该点的视口。

NOTE 1

任何可能涉及多个视口的测量,例如指定两点之间的距离,应使用第一个点所在视口中指定的信息。

表 260 – 视口字典中的条目
类型
Type 名称 (可选) 该字典描述的 PDF 对象的类型;视口字典的值应为 Viewport
BBox 矩形 (必需) 以默认用户空间坐标指定的矩形,表示页面上视口的位置。
矩形的两个坐标对应以规范化形式指定;即,先指定左下角,再指定右上角,参考测量坐标系统。此顺序确定了测量坐标系统的方向(即,x 和 y 轴的正方向),该坐标系统可能与页面的旋转不同。
该矩形的坐标独立于测量坐标系统的原点,后者由 Measure 中的 O 条目指定(参见 表 262)。
Name 文本字符串 (可选) 视口的描述性文本字符串或标题,供用户界面使用。
Measure 字典 (可选) 一个度量字典(参见 表 261),指定应适用于视口内容的测量比例和单位。

度量字典应为页面区域指定一个替代坐标系统。与视口字典一起,它应提供将页面坐标系统中的坐标转换为测量坐标系统中的坐标所需的信息。度量字典应提供格式化结果值的必要信息,以便在图形用户界面中呈现。

表 261 显示了度量字典中的条目。PDF 1.6 只定义了一种坐标系统类型,直角坐标系,该类型通过 Subtype 条目的值 RL 指定,定义为 x 和 y 轴垂直且具有线性增量单位的坐标系统(分别向右和向上)。可以使用其他子类型,以提供使用其他类型坐标系统的灵活性。

表 261 – 度量字典中的条目
类型
Type 名称 (可选) 该字典描述的 PDF 对象类型;对于度量字典,应为 Measure
Subtype 名称 (可选) 一个名称,指定用于测量的坐标系统类型。
默认值:RL,表示直角坐标系

表 262 显示了直角度量字典中的附加条目。该字典中的许多条目应为 数字格式数组,这些数组包含 数字格式字典(参见 表 263)。每个数字格式字典应表示一个特定的测量单位(例如英里或英尺)。它应包含有关如何以文本形式表示每个单位以及计算单位数量的因子的信息。

数字格式数组指定在表达特定测量时应使用的所有单位。每个数组应包含一个或多个数字格式字典,按粒度递减顺序排列。如果一种测量单位 X 比另一种测量单位 Y 大,则 X 的粒度比 Y 大。数组中的所有元素应包含文本字符串,按顺序连接在一起,指定单位如何显示。

NOTE 2

例如,1.4505 英里的测量值可以表示为“1.4505 mi”,这将需要一个表示英里的数字格式字典,或者表示为“1 mi 2,378 ft 7 ⅝ in”,这将需要三个字典(分别为英里、英尺和英寸)。

EXAMPLE 1

一个指定英尺的数字格式字典应排在指定英寸的字典之前。

表 262 – 直角度量字典中的附加条目
类型
R 文本字符串 (必需) 表达与此字典对应区域中绘图比例的文本字符串。应使用公认的单位缩写,既可以与此字典中的数字格式数组匹配,也可以使用常用比例的单位缩写。
示例 1    建筑绘图中常见的比例是“¼ in = 1 ft”,表示默认用户空间中的 ¼ 英寸等于现实世界中的 1 英尺。
如果 x 和 y 方向的比例不同,应指定两种比例。
示例 2    “in X 1 cm = 1 m, in Y 1 cm = 30 m”。
X 数组 (必需) 用于沿 x 轴的变化测量的数字格式数组,如果 Y 不存在,则也用于沿 y 轴的测量。数组中的第一个元素应包含将默认用户空间单位转换为测量坐标系统中该轴上最大单位的比例因子。
x 和 y 轴的方向是在测量坐标系统中,并且与页面的旋转无关。这些方向应由包含视口的 BBox 条目确定(参见 表 260)。
Y 数组 (当 x 和 y 比例具有不同的单位或转换因子时必需) 用于沿 y 轴的变化测量的数字格式数组。数组中的第一个元素应包含将默认用户空间单位转换为测量坐标系统中 y 轴上最大单位的比例因子。
D 数组 (必需) 用于任何方向上距离测量的数字格式数组。数组中的第一个元素应指定从 X 中第一个元素表示的单位转换到最大距离单位的比例。应使用 X、Y(如果存在)和 CYX(如果 Y 存在)中的比例因子,将默认用户空间转换为适当的单位,然后应用距离函数。
A 数组 (必需) 用于面积测量的数字格式数组。数组中的第一个元素应指定从 X 中第一个元素表示的单位的平方转换到最大面积单位的比例。应使用 X、Y(如果存在)和 CYX(如果 Y 存在)中的比例因子,将默认用户空间转换为适当的单位,然后应用面积函数。
T 数组 (可选) 用于角度测量的数字格式数组。数组中的第一个元素应指定从度数转换到最大角度单位的比例。应使用 CYX 中的比例因子(如果存在),将默认用户空间转换为适当的单位,然后应用角度函数。
S 数组 (可选) 用于测量线斜率的数字格式数组。数组中的第一个元素应指定从 Y 中第一个元素除以 X 中第一个元素表示的单位转换到最大斜率单位的比例。应使用 X、Y(如果存在)和 CYX(如果 Y 存在)中的比例因子,将默认用户空间转换为适当的单位,然后应用斜率函数。
O 数组 (可选) 一个包含两个数字的数组,用于指定测量坐标系统的原点位置,采用默认用户空间坐标。x 和 y 增加的方向将由视口的 BBox 条目确定(参见 表 260)。
默认值:视口 BBox 条目中矩形的第一个坐标对(左下角)。
CYX 数字 (可选;仅在 Y 存在时有意义) 一个因子,用于将 y 轴上的最大单位转换为 x 轴上的最大单位。它将在计算(距离、面积和角度)中使用,当单位等效时;如果未指定,则这些计算可能无法执行(例如,x 表示时间而 y 表示温度的情况)。其他计算(x 的变化、y 的变化和斜率)不需要此值。

XY 条目在测量字典中应为数字格式数组,分别指定用于 x 和 y 方向的测量单位以及用户空间单位与指定单位之间的比率。仅当 x 和 y 测量使用不同单位或具有不同比率时,Y 才会出现;在这种情况下,应使用 CYX 条目在适当时将 y 值转换为 x 值。

表 263 – 数字格式字典中的条目
类型
类型 名称 (可选) 此字典描述的 PDF 对象的类型;对于数字格式字典,应为 NumberFormat
U 文本字符串 (必需) 一个文本字符串,指定在用户界面中显示该字典表示的单位的标签;该标签应使用公认的缩写。
C 数字 (必需) 用于将前一个数字格式数组元素中的部分单位值乘以,得到此字典单位值的转换因子。 当此条目位于数组中的第一个数字格式字典时,它的意义(即应乘以的内容)取决于哪个矩形测量字典中的条目引用该数字格式数组(见表 262)。
F 名称 (可选;仅对数字格式数组中的最后一个字典有意义) 一个名称,指示是否以及如何显示通过 C 条目转换到此字典单位的分数值。有效值应为:
D   显示为十进制,精度由 D 条目指定。
F   显示为分数,分母由 D 条目指定。
R   无分数部分;四舍五入到最接近的整数单位。
T   无分数部分;截断以得到整数单位。
默认值:D
D 整数 (可选;仅对数字格式数组中的最后一个字典有意义) 一个正整数,指定分数值的精度或分母:
F 的值为 D 时,此条目应为十进制显示的精度;它应为 10 的倍数。低位零可以被截断,除非 FDtrue。默认值:100(百分位,对应于两个小数位)。
F 的值为 F 时,此条目应为分数显示的分母。除非 FDtrue,否则该分数可以被约简。默认值:16。
FD 布尔值 (可选;仅对数字格式数组中的最后一个字典有意义) 如果 true,则根据 D 条目格式化的分数值可能不会减少其分母或截断低位零。
默认值:false
RT 文本字符串 (可选) 用于在显示数字值时千位之间添加的文本。如果为空字符串,则不添加任何文本。
默认值:逗号 (2Ch)。
RD 文本字符串 (可选) 用于显示数字值的小数位置的文本。如果为空字符串,则使用默认值。
默认值:句点 (2Eh)。
PS 文本字符串 (可选) 将连接到 U 标签左侧的文本。如果为空字符串,则不添加任何文本。
默认值:一个 ASCII 空格字符 (20h)。
SS 文本字符串 (可选) 将连接到 U 标签右侧的文本。如果为空字符串,则不添加任何文本。
默认值:一个 ASCII 空格字符 (20h)。
O 名称 (可选) 指示 U 标签相对于计算单位值的位置的名称。有效值应为:
S   标签是值的后缀。
P   标签是值的前缀。
在考虑此条目之前,PSSS 指定的字符应连接。
默认值:S

要使用数字格式数组创建一个包含适当格式化单位的文本字符串,以便在用户界面中显示,应用以下算法:

算法:使用数字格式数组创建格式化文本字符串

a) 引用数字格式数组的矩形测量字典中的条目(见表 262)决定了初始测量值的含义。例如,X 条目指定用户空间单位,T 条目指定角度。

b) 将之前指定的值乘以数组中第一个数字格式字典的 C 条目,该条目将测量值转换为数组中指定的最大粒度单位。根据需要应用 RT 的值。

c) 如果结果没有非零的分数部分,则在添加了 PSSS 的空格后,按照 O 指定的顺序连接 U 条目指定的标签。格式化完成。

d) 如果存在非零分数部分且数组中没有更多元素,则按照最后一个字典中的 RDFDFD 条目的规定格式化分数部分。在添加了 PSSS 的空格后,按照 O 指定的顺序连接 U 条目指定的标签。格式化完成。

e) 如果存在非零分数部分且数组中有更多元素,则进入数组中的下一个数字格式字典。将其 C 条目乘以前一步的分数结果。根据需要应用 RT 的值。然后继续第 3 步。

此过程中的元素连接假定为从左到右的顺序。使用从右到左语言的文档可以根据需要修改此过程及条目的含义,以生成正确的结果。

示例 2

以下示例展示了一个测量字典,指定 x 或 y 的变化以英里为单位表达;距离以英里、英尺和英寸表示;面积以英亩表示。给定一个样本距离为 1.4505 英里的比例单位,应用数字格式数组后生成的格式化文本为 “1 mi 2,378 ft 7 ⅝ in”。

<</Type /Measure
    /Subtype /RL
    /R (1in = 0.1 mi)
    /X [ <</U (mi)                    % x 偏移量以英里为单位表示
            /C .00139                 % 从用户空间单位转换为英里
            /D 100000
        ]
    /D [<< /U (mi) /C 1 >>            % 距离:初始单位为英里;不需要转换
        << /U (ft) /C 5280 >>         % 从英里到英尺的转换
        << /U (in) /C 12              % 从英尺到英寸的转换
            /F /F /D 8 >>              % 英寸的分数四舍五入到最接近的 1/8
        ]
    /A [<</U (acres)                  % 面积:以英亩为单位
            /C 640 >>                  % 从平方英里到英亩的转换
        ]
>>

PDF documents, such as those created by CAD software, may contain graphics that are intended to represent real-world objects. Users of such documents often require information about the scale and units of measurement of the corresponding real-world objects and their relationship to units in PDF user space.

This information enables users of conforming readers to perform measurements that yield results in the units intended by the creator of the document. A measurement in this context is the result of a canonical function that takes as input a set of n coordinate pairs

\[\left \{ (x_{_0},y_{_0}),\dots ,(x_{_{n-1}},y_{_{n-1}}) \right \}\]

and produces a single number as output depending on the type of measurement. For example, distance measurement is equivalent to

\[ \sum_{i=1}^{n-2}\sqrt{(x_i-x_{i+1})^2+(y_i-y_{i+1})^2}\]

for \(n\ge2\).

Beginning with PDF 1.6, such information may be stored in a measure dictionary (see Table 261). Measure dictionaries provide information about measurement units associated with a rectangular area of the document known as a viewport.

A viewport (PDF 1.6) is a rectangular region of a page. The optional VP entry in a page dictionary (see Table 30) shall specify an array of viewport dictionaries, whose entries shall be as shown in Table 260. Viewports allow different measurement scales (specified by the Measure entry) to be used in different areas of a page, if necessary.

The dictionaries in the VP array shall be in drawing order. Since viewports might overlap, to determine the viewport to use for any point on a page, the dictionaries in the array shall be examined, starting with the last one and iterating in reverse, and the first one whose BBox entry contains the point shall be chosen.

NOTE 1

Any measurement that potentially involves multiple viewports, such as one specifying the distance between two points, shall use the information specified in the viewport of the first point.

Table 260 – Entries in a viewport dictionary
Key Type Value
Type name (Optional) The type of PDF object that this dictionary describes; shall be Viewport for a viewport dictionary.
BBox rectangle (Required) A rectangle in default user space coordinates specifying the location of the viewport on the page.
The two coordinate pairs of the rectangle shall be specified in normalized form; that is, lower-left followed by upper-right, relative to the measuring coordinate system. This ordering shall determine the orientation of the measuring coordinate system (that is, the direction of the positive x and y axes) in this viewport, which may have a different rotation from the page.
The coordinates of this rectangle are independent of the origin of the measuring coordinate system, specified in the O entry (see Table 262) of the measurement dictionary specified by Measure.
Name text string (Optional) A descriptive text string or title of the viewport, intended for use in a user interface.
Measure dictionary (Optional) A measure dictionary (see Table 261) that specifies the scale and units that shall apply to measurements taken on the contents within the viewport.

A measure dictionary shall specify an alternate coordinate system for a region of a page. Along with the viewport dictionary, it shall provide the information needed to convert coordinates in the page’s coordinate system to coordinates in the measuring coordinate system. The measure dictionary shall provide information for formatting the resulting values into textual form for presentation in a graphical user interface.

Table 261 shows the entries in a measure dictionary. PDF 1.6 defines only a single type of coordinate system, a rectilinear coordinate system, that shall be specified by the value RL for the Subtype entry, which is defined as one in which the x and y axes are perpendicular and have units that increment linearly (to the right and up, respectively). Other subtypes may be used, providing the flexibility to measure using other types of coordinate systems.

Table 261 – Entries in a measure dictionary
Key Type Value
Type name (Optional) The type of PDF object that this dictionary describes; shall be Measure for a measure dictionary.
Subtype name (Optional) A name specifying the type of coordinate system to use for measuring.
Default value: RL, which specifies a rectilinear coordinate system

Table 262 shows the additional entries in a rectilinear measure dictionary. Many of the entries in this dictionary shall be number format arrays, which are arrays of number format dictionaries (see Table 263). Each number format dictionary shall represent a specific unit of measurement (such as miles or feet). It shall contain information about how each unit shall be expressed in text and factors for calculating the number of units.

Number format arrays specify all the units that shall be used when expressing a specific measurement. Each array shall contain one or more number format dictionaries, in descending order of granularity. If one unit of measurement X is larger than one unit of measurement Y then X has a larger order of granularity than Y. All the elements in the array shall contain text strings that, concatenated together, specify how the units shall be displayed.

NOTE 2

For example, a measurement of 1.4505 miles might be expressed as “1.4505 mi”, which would require one number format dictionary for miles, or as “1 mi 2,378 ft 7 ⅝ in”, which would require three dictionaries (for miles, feet, and inches).

EXAMPLE 1

A number format dictionary specifying feet should precede one specifying inches.

Table 262 – Additional entries in a rectilinear measure dictionary
Key Type Value
R text string (Required) A text string expressing the scale ratio of the drawing in the region corresponding to this dictionary. Universally recognized unit abbreviations should be used, either matching those of the number format arrays in this dictionary or those of commonly used scale ratios.
EXAMPLE 1    a common scale in architectural drawings is “¼ in = 1 ft”, indicating that ¼ inches in default user space is equivalent to 1 foot in real-world measurements.
If the scale ratio differs in the x and y directions, both scales should be specified.
EXAMPLE 2     “in X 1 cm = 1 m, in Y 1 cm = 30 m”.
X array (Required) A number format array for measurement of change along the x axis and, if Y is not present, along the y axis as well. The first element in the array shall contain the scale factor for converting from default user space units to the largest units in the measuring coordinate system along that axis.
The directions of the x and y axes are in the measuring coordinate system and are independent of the page rotation. These directions shall be determined by the BBox entry of the containing viewport (see Table 260).
Y array (Required when the x and y scales have different units or conversion factors) A number format array for measurement of change along the y axis. The first element in the array shall contain the scale factor for converting from default user space units to the largest units in the measuring coordinate system along the y axis.
D array (Required) A number format array for measurement of distance in any direction. The first element in the array shall specify the conversion to the largest distance unit from units represented by the first element in X. The scale factors from X, Y (if present) and CYX (if Y is present) shall be used to convert from default user space to the appropriate units before applying the distance function.
A array (Required) A number format array for measurement of area. The first element in the array shall specify the conversion to the largest area unit from units represented by the first element in X, squared. The scale factors from X, Y (if present) and CYX (if Y is present) shall be used to convert from default user space to the appropriate units before applying the area function.
T array (Optional) A number format array for measurement of angles. The first element in the array shall specify the conversion to the largest angle unit from degrees. The scale factor from CYX (if present) shall be used to convert from default user space to the appropriate units before applying the angle function.
S array (Optional) A number format array for measurement of the slope of a line. The first element in the array shall specify the conversion to the largest slope unit from units represented by the first element in Y divided by the first element in X. The scale factors from X, Y (if present) and CYX (if Y is present) shall be used to convert from default user space to the appropriate units before applying the slope function.
O array (Optional) An array of two numbers that shall specify the origin of the measurement coordinate system in default user space coordinates. The directions by which x and y increase in value from this origin shall be determined by the viewport’s BBox entry (see Table 260).
Default value: the first coordinate pair (lower-left corner) of the rectangle specified by the viewport’s BBox entry.
CYX number (Optional; meaningful only when Y is present) A factor that shall be used to convert the largest units along the y axis to the largest units along the x axis. It shall be used for calculations (distance, area, and angle) where the units are be equivalent; if not specified, these calculations may not be performed (which would be the case in situations such as x representing time and y representing temperature). Other calculations (change in x, change in y, and slope) shall not require this value.

The X and Y entries in a measure dictionary shall be number format arrays that shall specify the units used for measurements in the x and y directions, respectively, and the ratio between user space units and the specified units. Y is present only when the x and y measurements are in different units or have different ratios; in this case, the CYX entry shall be used to convert y values to x values when appropriate.

Table 263 – Entries in a number format dictionary
Key Type Value
Type name (Optional) The type of PDF object that this dictionary describes; shall be NumberFormat for a number format dictionary.
U text string (Required) A text string specifying a label for displaying the units represented by this dictionary in a user interface; the label should use a universally recognized abbreviation.
C number (Required) The conversion factor used to multiply a value in partial units of the previous number format array element to obtain a value in the units of this dictionary. When this entry is in the first number format dictionary in the array, its meaning (that is, what it shall be multiplied by) depends on which entry in the rectilinear measure dictionary (see Table 262) references the number format array.
F name (Optional; meaningful only for the last dictionary in a number format array) A name indicating whether and in what manner to display a fractional value from the result of converting to the units of this dictionary by means of the C entry. Valid values shall be:
D   Show as decimal to the precision specified by the D entry.
F   Show as a fraction with denominator specified by the D entry.
R   No fractional part; round to the nearest whole unit.
T   No fractional part; truncate to achieve whole units.
Default value: D.
D integer (Optional; meaningful only for the last dictionary in a number format array) A positive integer that shall specify the precision or denominator of a fractional amount:
When the value of F is D, this entry shall be the precision of a decimal display; it shall be a multiple of 10. Low-order zeros may be truncated unless FD is true. Default value: 100 (hundredths, corresponding to two decimal digits).
When the value of F is F, this entry shall be the denominator of a fractional display. The fraction may be reduced unless the value of FD is true. Default value: 16.
FD boolean (Optional; meaningful only for the last dictionary in a number format array) If true, a fractional value formatted according to the D entry may not have its denominator reduced or low-order zeros truncated.
Default value: false.
RT text string (Optional) Text that shall be used between orders of thousands in display of numerical values. An empty string indicates that no text shall be added.
Default value: COMMA (2Ch).
RD text string (Optional) Text that shall be used as the decimal position in displaying numerical values. An empty string indicates that the default shall be used.
Default value: PERIOD (2Eh).
PS artext stringay (Optional) Text that shall be concatenated to the left of the label specified by U. An empty string indicates that no text shall be added.
Default value: A single ASCII SPACE character (20h).
SS text string (Optional) Text that shall be concatenated after the label specified by U. An empty string indicates that no text shall be added.
Default value: A single ASCII SPACE character (20h).
O name (Optional) A name indicating the position of the label specified by U with respect to the calculated unit value. Valid values shall be:
S   The label is a suffix to the value.
P   The label is a prefix to the value.
The characters specified by PS and SS shall be concatenated before considering this entry.
Default value: S.

To use a number format array to create a text string containing the appropriately formatted units for display in a user interface, apply the following algorithm:

Algorithm: Use of a number format array to create a formatted text string

a) The entry in the rectilinear measure dictionary (see Table 262) that references the number format array determines the meaning of the initial measurement value. For example, the X entry specifies user space units, and the T entry specifies degrees.

b) Multiply the value specified previously by the C entry of the first number format dictionary in the array, which converts the measurement to units of the largest granularity specified in the array. Apply the value of RT as appropriate.

c) If the result contains no nonzero fractional portion, concatenate the label specified by the U entry in the order specified by O, after adding spacing from PS and SS. The formatting is then complete.

d) If there is a nonzero fractional portion and no more elements in the array, format the fractional portion as specified by the RD, F, D, and FD entries of the last dictionary. Concatenate the label specified by the U entry in the order specified by O, after adding spacing from PS and SS. The formatting is then complete.

e) If there is a nonzero fractional portion and more elements in the array, proceed to the next number format dictionary in the array. Multiply its C entry by the fractional result from the previous step. Apply the value of RT as appropriate. Then proceed to step 3.

The concatenation of elements in this process assumes left-to-right order. Documents using right-to-left languages may modify the process and the meaning of the entries as appropriate to produce the correct results.

EXAMPLE 2

The following example shows a measure dictionary that specifies that changes in x or y are expressed in miles; distances are expressed in miles, feet, and inches; and area is expressed in acres. Given a sample distance in scaled units of 1.4505 miles, the formatted text produced by applying the number format array would be “1 mi 2,378 ft 7 ⅝ in”.

<</Type /Measure
    /Subtype /RL
    /R (1in = 0.1 mi)
    /X [ <</U (mi)                    % x offset represented in miles
            /C .00139                 % Conversion from user space units to miles
            /D 100000
        ]
    /D [<< /U (mi) /C 1 >>            % Distance: initial unit is miles; no conversion needed
        << /U (ft) /C 5280 >>         % Conversion from miles to feet
        << /U (in) /C 12              % Conversion from feet to inches
           /F /F /D 8 >>              % Fractions of inches rounded to nearest 1/8
        ]
    /A [<</U (acres)                  % Area: measured in acres
           /C 640 >>                  % Conversion from square miles to acres
        ]
>>