10.6 扫描转换详细信息¶
Scan Conversion Details
10.6.1 概述¶
General
渲染的最后一步是 扫描转换。符合要求的读取器执行扫描转换算法,在输出设备的光栅内存中绘制图形、文本和图像。
注意
扫描转换算法的具体细节并未作为 PDF 的一部分定义。不同的实现可能以不同的方式执行扫描转换;适用于某一设备的技术可能不适用于另一个设备。然而,了解扫描转换的基本原理仍然很有用,特别是在创建用于显示器查看的 PDF 文件时。在显示器的低分辨率下,即使是一个像素宽度的变化,也可能对绘制形状的外观产生显著影响。
大多数扫描转换的细节不受程序控制,但有一些是可以控制的;用于控制它们的参数将在这里描述。
The final step of rendering shall be scan conversion. The conforming reader executes a scan conversion algorithm to paint graphics, text, and images in the raster memory of the output device.
NOTE
The specifics of the scan conversion algorithm are not defined as part of PDF. Different implementations may perform scan conversion in different ways; techniques that are appropriate for one device may be inappropriate for another. Still, it is useful to have a general understanding of how scan conversion works, particularly when creating PDF files intended for viewing on a display. At the low resolutions typical of displays, variations of even one pixel’s width can have a noticeable effect on the appearance of painted shapes.
Most scan conversion details are not under program control, but a few are; the parameters for controlling them are described here.
10.6.2 平整度公差¶
Flatness Tolerance
平坦度容差 控制在设备像素中,数学上正确的路径与由直线段构造的近似路径之间的最大允许距离,如图 54 所示。平坦度可以作为 i 运算符的操作数(见表 57),或者作为图形状态参数字典中 FL 条目的值(见[表 58])。它应为正数。
注意 1
较小的值会提供更高的精度,但计算量较大。
注意 2
尽管图中为了清晰说明夸大了曲线和简化路径之间的差异,但平坦度容差的目的是控制曲线渲染的精度,而不是绘制内切多边形。如果参数值大到足以出现可见的直线段,则结果是不可预测的。
The flatness tolerance controls the maximum permitted distance in device pixels between the mathematically correct path and an approximation constructed from straight line segments, as shown in Figure 54. Flatness may be specified as the operand of the i operator (see Table 57) or as the value of the FL entry in a graphics state parameter dictionary (see Table 58). It shall be a positive number.
NOTE 1
Smaller values yield greater precision at the cost of more computation.
NOTE 2
Although the figure exaggerates the difference between the curved and flattened paths for the sake of clarity, the purpose of the flatness tolerance is to control the precision of curve rendering, not to draw inscribed polygons. If the parameter’s value is large enough to cause visible straight line segments to appear, the result is unpredictable.
10.6.3 平滑度公差¶
Smoothness Tolerance
平滑度容差(PDF 1.3)控制平滑着色(类型 2 图案和 sh 运算符)的质量,因此间接控制渲染性能。平滑度是通过分段线性插值近似的着色与真实(可能是非线性)着色函数之间的可允许颜色误差。误差应针对每个颜色分量进行测量,并使用最大独立误差。可允许的误差(或容差)应表示为颜色分量范围的一个分数,从 0.0 到 1.0。因此,平滑度容差为 0.1 表示每个颜色分量的容差为 10%。平滑度可以作为图形状态参数字典中 SM 条目的值来指定(见[表 58])。
示例
每个输出设备可能对可达到的最大和最小容差有内部限制。在高质量的彩色设备上,将平滑度设置为 1.0 可能会导致内部平滑度为 0.5,而在相同设备上将其设置为 0.0 时,如果该误差在设备上不可察觉,可能会导致内部平滑度为 0.01。
注意 1
平滑度容差还可能与颜色转换的精度相互作用。在由采样函数定义的颜色转换情况下,转换函数是未知的。因此,误差可能以过低的频率进行采样,在这种情况下,平滑度容差定义的精度无法得到保证。然而,在大多数情况下,如果转换函数是平滑和连续的,精度应该在规定的容差范围内。
注意 2
平滑度容差的效果类似于平坦度容差。然而,平坦度是以设备相关的像素宽度单位进行测量的,而平滑度则是作为颜色分量范围的一个分数来测量的。
The smoothness tolerance (PDF 1.3) controls the quality of smooth shading (type 2 patterns and the sh operator) and thus indirectly controls the rendering performance. Smoothness is the allowable colour error between a shading approximated by piecewise linear interpolation and the true value of a (possibly nonlinear) shading function. The error shall be measured for each colour component, and the maximum independent error shall be used. The allowable error (or tolerance) shall be expressed as a fraction of the range of the colour component, from 0.0 to 1.0. Thus, a smoothness tolerance of 0.1 represents a tolerance of 10 percent in each colour component. Smoothness may be specified as the value of the SM entry in a graphics state parameter dictionary (see Table 58).
EXAMPLE
Each output device may have internal limits on the maximum and minimum tolerances attainable. setting smoothness to 1.0 may result in an internal smoothness of 0.5 on a high-quality colour device, while setting it to 0.0 on the same device may result in an internal smoothness of 0.01 if an error of that magnitude is imperceptible on the device.
NOTE 1
The smoothness tolerance may also interact with the accuracy of colour conversion. In the case of a colour conversion defined by a sampled function, the conversion function is unknown. Thus the error may be sampled at too low a frequency, in which case the accuracy defined by the smoothness tolerance cannot be guaranteed. In most cases, however, where the conversion function is smooth and continuous, the accuracy should be within the specified tolerance.
NOTE 2
The effect of the smoothness tolerance is similar to that of the flatness tolerance. However, that flatness is measured in device-dependent units of pixel width, whereas smoothness is measured as a fraction of colour component range.
10.6.4 扫描转换规则¶
Scan Conversion Rules
以下规则决定了绘制操作影响哪些设备像素。所有对坐标和像素的引用均在设备空间中。形状是要用当前颜色或图像绘制的路径。其坐标被映射到设备空间,但不会四舍五入到设备像素边界。在此级别,曲线已被展平为直线序列,所有的“内外”计算已完成。
像素边界总是落在设备空间中的整数坐标上。像素是一个方形区域,通过其左下角的水平和垂直最小坐标来标识。该区域是半开的,意味着它包括其下边界,但不包括上边界。更精确地说,对于任何实数坐标为 (x, y) 的点,设 i = floor(x) 且 j = floor(y),包含该点的像素为 (i, j)。该像素的区域定义为点集合 (x', y'),使得 i ≤ x' < i + 1 且 j ≤ y' < j + 1。像素和形状一样,要通过填充和描边操作绘制的形状也被视为半开区域,包括它们“底部”边界,但不包括“顶部”边界。
一个形状应通过绘制与该形状相交的任何像素来进行扫描转换,无论交集有多小。这确保了无论形状与设备像素网格的相对位置如何,都不会因为不利的放置导致形状消失,这在其他可能的扫描转换规则中可能发生。被绘制的像素覆盖的区域应始终至少与原始形状的区域一样大。该规则适用于填充操作和具有非零宽度的描边。零宽度描边可以以实现定义的方式进行,可能会绘制比该规则所暗示的像素更少。
注意 1
通常,两个区域的交集定义为它们内部的交集。然而,在扫描转换的情况下,填充区域被认为与其边界通过的每个像素相交,即使填充区域的内部是空的。
示例
一个零宽度或零高度的矩形绘制出一条宽度为 1 像素的线。
由采样图像绘制的设备空间区域的确定方式与填充形状类似,但并不完全相同。符合规范的阅读器将图像的源矩形转换到设备空间,并定义一个半开区域,就像填充操作一样。然而,只有那些中心位于该区域内的像素才会被绘制。该像素中心的位置——换句话说,坐标值具有 ½ 小数部分的点——应被映射回源空间以确定如何着色该像素。不得对像素区域进行平均;
注意 2
如果源图像的分辨率高于设备空间的分辨率,则可能不会使用一些源样本。
对于裁剪,裁剪区域包括通过填充操作所包含的像素集合。后续的绘制操作应影响裁剪区域所定义的像素集合与要绘制区域的像素集合的交集。
字符字形的扫描转换可能由与前述不同的算法执行。
注意 3
该字体渲染算法使用字形描述中的提示和专门针对字形光栅化的技术。
The following rules determine which device pixels a painting operation affects. All references to coordinates and pixels are in device space. A shape is a path to be painted with the current colour or with an image. Its coordinates are mapped into device space but not rounded to device pixel boundaries. At this level, curves have been flattened to sequences of straight lines, and all “insideness” computations have been performed.
Pixel boundaries always fall on integer coordinates in device space. A pixel is a square region identified by the location of its corner with minimum horizontal and vertical coordinates. The region is half-open, meaning that it includes its lower but not its upper boundaries. More precisely, for any point whose real-number coordinates are (x, y), let i = floor(x) and j = floor(y). The pixel that contains this point is the one identified as (i, j). The region belonging to that pixel is defined to be the set of points (x', y') such that i ≤ x' < i + 1 and j ≤ y' < j + 1. Like pixels, shapes to be painted by filling and stroking operations are also treated as half-open regions that include the boundaries along their “floor” sides, but not along their “ceiling” sides.
A shape shall be scan-converted by painting any pixel whose square region intersects the shape, no matter how small the intersection is. This ensures that no shape ever disappears as a result of unfavourable placement relative to the device pixel grid, as might happen with other possible scan conversion rules. The area covered by painted pixels shall always be at least as large as the area of the original shape. This rule applies both to fill operations and to strokes with nonzero width. Zero-width strokes may be done in an implementation-defined manner that may include fewer pixels than the rule implies.
NOTE 1
Normally, the intersection of two regions is defined as the intersection of their interiors. However, for purposes of scan conversion, a filling region is considered to intersect every pixel through which its boundary passes, even if the interior of the filling region is empty.
EXAMPLE
A zero-width or zero-height rectangle paints a line 1 pixel wide.
The region of device space to be painted by a sampled image is determined similarly to that of a filled shape, though not identically. The conforming reader transforms the image’s source rectangle into device space and defines a half-open region, just as for fill operations. However, only those pixels whose centres lie within the region shall be painted. The position of the centre of such a pixel—in other words, the point whose coordinate values have fractional parts of one-half—shall be mapped back into source space to determine how to colour the pixel. There shall not be averaging over the pixel area;
NOTE 2
If the resolution of the source image is higher than that of device space, some source samples may not be used.
For clipping, the clipping region consists of the set of pixels that would be included by a fill operation. Subsequent painting operations shall affect a region that is the intersection of the set of pixels defined by the clipping region with the set of pixels for the region to be painted.
Scan conversion of character glyphs may be performed by a different algorithm from the preceding one.
NOTE 3
That font rendering algorithm uses hints in the glyph descriptions and techniques that are specialized to glyph rasterization.
10.6.5 自动描边调整¶
Automatic Stroke Adjustment
当沿路径绘制描边时,扫描转换算法可能会因为光栅化效应而产生厚度不均的线条。通常,线条宽度和端点坐标在转换到设备空间后是任意实数,并没有量化为设备像素。给定宽度的线条可以与不同数量的设备像素相交,具体取决于它的位置。图 55 说明了这种效应。
为了获得最佳效果,补偿光栅化效应以产生均匀厚度的描边非常重要。尤其在低分辨率显示应用中,这一点尤其重要。为满足这一需求,PDF 1.2 提供了一个可选的自动描边调整功能。当启用描边调整时,描边的线宽和坐标应根据需要自动调整,以产生均匀厚度的线条。线条的厚度应尽可能接近请求的线宽,误差不超过半个像素。
如果启用了描边调整,且请求的线宽转换到设备空间后小于半个像素,则描边应呈现为单像素宽的线条。
注意
这是设备分辨率下可以渲染的最细线条。它等同于将线宽设置为 0 时产生的效果(参见 10.6.4,“扫描转换规则”)。
由于自动描边调整可能对线条的外观产生显著影响,PDF 提供了控制是否执行调整的方法。这可以通过图形状态中的描边调整参数来指定,设置方法是通过图形状态参数字典中的 SA 项(参见 8.4.5,“图形状态参数字典”)。
When a stroke is drawn along a path, the scan conversion algorithm may produce lines of nonuniform thickness because of rasterization effects. In general, the line width and the coordinates of the endpoints, transformed into device space, are arbitrary real numbers not quantized to device pixels. A line of a given width can intersect with different numbers of device pixels, depending on where it is positioned. Figure 55 illustrates this effect.
For best results, it is important to compensate for the rasterization effects to produce strokes of uniform thickness. This is especially important in low-resolution display applications. To meet this need, PDF 1.2 provides an optional automatic stroke adjustment feature. When stroke adjustment is enabled, the line width and the coordinates of a stroke shall automatically be adjusted as necessary to produce lines of uniform thickness. The thickness shall be as near as possible to the requested line width—no more than half a pixel different.
If stroke adjustment is enabled and the requested line width, transformed into device space, is less than half a pixel, the stroke shall be rendered as a single-pixel line.
NOTE
This is the thinnest line that can be rendered at device resolution. It is equivalent to the effect produced by setting the line width to 0 (see 10.6.4, "Scan Conversion Rules").
Because automatic stroke adjustment can have a substantial effect on the appearance of lines, PDF provides means to control whether the adjustment shall be performed. This may be specified with the stroke adjustment parameter in the graphics state, set by means of the SA entry in a graphics state parameter dictionary (see 8.4.5, "Graphics State Parameter Dictionaries").