9.3 文本状态参数和操作¶
Text State Parameters and Operators
9.3.1 概述¶
General
文本状态(text state) 包括那些只影响文本的图形状态参数。文本状态中有九个参数(见表104)。
参数 | 描述 |
---|---|
字符间距(Character spacing) | |
字间距(Word spacing) | |
水平缩放(Horizontal scaling) | |
行距(Leading) | |
字体(Text font) | |
字体大小(Text font size) | |
渲染模式(Text rendering mode) | |
文本提升(Text rise) | |
文本击穿(Text knockout) |
除了前面描述的
文本击穿参数
文本状态操作符可能出现在文本对象之外,它们设置的值在单个内容流中的文本对象之间保留。像其他图形状态参数一样,这些参数应在每页开始时初始化为其默认值。
Operands | Operator | Description |
---|---|---|
charSpace | Tc | 设置字符间距 |
wordSpace | Tw | 设置单词间距 |
scale | Tz | 设置水平缩放 |
leading | TL | 设置文本行距 |
font size | Tf | 设置文本字体 |
render | Tr | 设置文本渲染模式 |
rise | Ts | 设置文本提升 |
这些参数中的一些是用未缩放(unscaled)的文本空间单位来表示的。这意味着它们应该在一个坐标系中指定,这个坐标系由文本矩阵
The text state comprises those graphics state parameters that only affect text. There are nine parameters in the text state (see Table 104).
Parameter | Description |
---|---|
Character spacing | |
Word spacing | |
Horizontal scaling | |
Leading | |
Text font | |
Text font size | |
Text rendering mode | |
Text rise | |
Text knockout |
Except for the previously described
The text knockout parameter,
The text state operators may appear outside text objects, and the values they set are retained across text objects in a single content stream. Like other graphics state parameters, these parameters shall be initialized to their default values at the beginning of each page.
Operands | Operator | Description |
---|---|---|
charSpace | Tc | Set the character spacing, |
wordSpace | Tw | Set the word spacing, |
scale | Tz | Set the horizontal scaling, |
leading | TL | Set the text leading, |
font size | Tf | Set the text font, |
render | Tr | Set the text rendering mode, |
rise | Ts | Set the text rise, |
Some of these parameters are expressed in unscaled text space units. This means that they shall be specified in a coordinate system that shall be defined by the text matrix,
9.3.2 字符间距¶
Character Spacing
字符间距参数
The character-spacing parameter,
9.3.3 字间距¶
Word Spacing
单词间距的工作原理与字符间距相同,但仅适用于ASCII空格字符(20h)。单词间距参数
单词间距应用于字符串中每个单字节字符代码32(即空格字符)的实例,当使用简单字体或复合字体且该字体将代码32定义为单字节代码时。它不应用于多字节代码中字节值32的出现。
Word spacing works the same way as character spacing but shall apply only to the ASCII SPACE character (20h). The word-spacing parameter,
Word spacing shall be applied to every occurrence of the single-byte character code 32 in a string when using a simple font or a composite font that defines code 32 as a single-byte code. It shall not apply to occurrences of the byte value 32 in multiple-byte codes.
9.3.4 水平扩展¶
Horizontal Scaling
水平缩放参数
The horizontal scaling parameter,
9.3.5 引导¶
Leading
行距参数
行距参数由 TD, T*, ', 和 " 操作符使用;其效果的精确描述请见表108。此参数应用于文本空间中的垂直坐标,与书写模式无关。
The leading parameter,
The leading parameter shall be used by the TD, T*, ', and " operators; see Table 108 for a precise description of its effects. This parameter shall apply to the vertical coordinate in text space, independently of the writing mode.
9.3.6 文本渲染模式¶
Text Rendering Mode
文本渲染模式
注意
文本渲染模式见表 106。在示例中,描边颜色为黑色,填充颜色为浅灰色。对于裁剪模式(4 到 7),在字形上绘制了一系列线条,以显示裁剪发生的位置。
对于 Type 3 字体中显示的文本,仅当文本渲染模式的值为 3 时才会产生影响(参见 9.6.5,“Type 3 字体”)。
如果文本渲染模式要求填充,则应使用图形状态中的当前非描边颜色;如果要求描边,则应使用当前描边颜色。在既进行填充又进行描边的模式下,其效果应当如同每个字形轮廓先填充再描边,各自独立执行。如果某些字形重叠,效果应等同于逐个填充和描边,呈现为堆叠的不透明字形,而不是所有字形先填充后再整体描边。在透明成像模型中,这些填充和描边的组合模式还需要进一步考虑,详见 11.7.4.4,“特殊路径绘制注意事项”。
裁剪模式的行为需要进一步说明。如果在文本渲染模式设置为裁剪模式的情况下执行 BT 操作符,或在文本对象内将其设置为裁剪模式,则字形轮廓将开始累积。字形会一直累积,直到文本对象由 ET 操作符结束;在此之前,不得将文本渲染模式更改回非裁剪模式。
模式 | 示例 | 描述 |
---|---|---|
0 | ![]() |
填充文本。 |
1 | ![]() |
描边文本。 |
2 | ![]() |
先填充,再描边文本。 |
3 | 既不填充也不描边文本(不可见)。 | |
4 | ![]() |
填充文本并添加到路径进行裁剪(参见 9.3.6,“文本渲染模式”)。 |
5 | ![]() |
描边文本并添加到路径进行裁剪。 |
6 | ![]() |
先填充,再描边文本,并添加到路径进行裁剪。 |
7 | ![]() |
将文本添加到路径进行裁剪。 |
在文本对象结束时,所有累积的字形轮廓(如果有)应合并为单一路径,将各个字形轮廓视为该路径的子路径,并应用非零环绕数规则(参见 8.5.3.3.2,“非零环绕数规则”)。图形状态中的当前裁剪路径应设置为该路径与先前裁剪路径的交集。与路径对象类似,此裁剪操作应在文本对象的所有填充和描边操作完成之后执行,并保持有效,直到通过 Q 操作符恢复先前的裁剪路径。
如果未显示任何字形,或显示的唯一字形没有轮廓(例如 ASCII 空格字符(20h)),则不会发生裁剪。
The text rendering mode,
!!! note "NOTE"
The text rendering modes are shown in [Table 106](#table106). In the examples, a stroke colour of black and a fill colour of light gray are used. For the clipping modes (4 to 7), a series of lines has been drawn through the glyphs to show where the clipping occurs.
Only a value of 3 for text rendering mode shall have any effect on text displayed in a Type 3 font (see 9.6.5, "Type 3 Fonts").
If the text rendering mode calls for filling, the current nonstroking colour in the graphics state shall be used; if it calls for stroking, the current stroking colour shall be used. In modes that perform both filling and stroking, the effect shall be as if each glyph outline were filled and then stroked in separate operations. If any of the glyphs overlap, the result shall be equivalent to filling and stroking them one at a time, producing the appearance of stacked opaque glyphs, rather than first filling and then stroking them all at once. In the transparent imaging model, these combined filling and stroking modes shall be subject to further considerations; see 11.7.4.4, "Special Path-Painting Considerations".
The behaviour of the clipping modes requires further explanation. Glyph outlines shall begin accumulating if a BT operator is executed while the text rendering mode is set to a clipping mode or if it is set to a clipping mode within a text object. Glyphs shall accumulate until the text object is ended by an ET operator; the text rendering mode shall not be changed back to a nonclipping mode before that point.
Mode | Example | Description |
---|---|---|
0 | ![]() |
Fill text. |
1 | ![]() |
Stroke text. |
2 | ![]() |
Fill, then stroke text. |
3 | Neither fill nor stroke text (invisible). | |
4 | ![]() |
Fill text and add to path for clipping (see 9.3.6, "Text Rendering Mode,"). |
5 | ![]() |
Stroke text and add to path for clipping. |
6 | ![]() |
Fill, then stroke text and add to path for clipping. |
7 | ![]() |
Add text to path for clipping. |
At the end of the text object, the accumulated glyph outlines, if any, shall be combined into a single path, treating the individual outlines as subpaths of that path and applying the nonzero winding number rule (see 8.5.3.3.2, "Nonzero Winding Number Rule"). The current clipping path in the graphics state shall be set to the intersection of this path with the previous clipping path. As is the case for path objects, this clipping shall occur after all filling and stroking operations for the text object have occurred. It remains in effect until a previous clipping path is restored by an invocation of the Q operator.
If no glyphs are shown or if the only glyphs shown have no outlines (for example, if they are ASCII SPACE characters (20h)), no clipping shall occur.
9.3.7 文本升降¶
Text Rise
文本升降
注意
调整基线位置对于绘制上标或下标非常有用。将文本升降设为 0 可恢复基线的默认位置。
Text rise,
NOTE
Adjustments to the baseline are useful for drawing superscripts or subscripts. The default location of the baseline can be restored by setting the text rise to 0.
9.3.8 文本镂空(切割)¶
Text Knockout
文本敲除参数
文本敲除参数 (
如果该参数为 false,则文本对象中的每个字形都会被视为独立的基本对象;当字形重叠时,它们会相互混合。
如果该参数为 true,则文本对象中的所有字形会被整体视为一个单一的基本对象;当字形重叠时,后面的字形会覆盖(“敲除”)前面的字形。此行为等效于将整个文本对象视为非隔离敲除透明组(参见 11.4.6,“敲除组”)。透明度参数将单独应用于每个字形,而不是应用于整个隐式透明组:
- 图形状态参数(包括透明度参数)将继承自文本对象所在的上下文,且不会被保存和恢复。透明度参数不会在透明组的开始处被重置(如同显式调用透明组 XObject 时那样)。在文本对象内部修改的图形状态参数将在文本对象结束后继续生效。
- 在文本对象的隐式透明组完全计算完毕后,该组的最终结果将使用Normal 混合模式,并采用 1.0 的 Alpha 和软蒙版值,与背景进行合成。
The text knockout parameter,
If the parameter is false, each glyph in a text object shall be treated as a separate elementary object; when glyphs overlap, they shall composite with one another.
If the parameter is true, all glyphs in the text object shall be treated together as a single elementary object; when glyphs overlap, later glyphs shall overwrite (“knock out”) earlier ones in the area of overlap. This behaviour is equivalent to treating the entire text object as if it were a non-isolated knockout transparency group; see 11.4.6, "Knockout Groups". Transparency parameters shall be applied to the glyphs individually rather than to the implicit transparency group as a whole:
- Graphics state parameters, including transparency parameters, shall be inherited from the context in which the text object appears. They shall not be saved and restored. The transparency parameters shall not be reset at the beginning of the transparency group (as they are when a transparency group XObject is explicitly invoked). Changes made to graphics state parameters within the text object shall persist beyond the end of the text object.
- After the implicit transparency group for the text object has been completely evaluated, the group results shall be composited with the backdrop, using the Normal blend mode and alpha and soft mask values of 1.0.