跳转至

9.9 嵌入式字体程序

9.9 Embedded Font Programs

字体程序可以作为数据嵌入到PDF文件中的PDF流对象中。

注 1

这种流对象也称为字体文件,这是为了类比与来自符合规范的写入者之外的外部源的字体程序。

字体程序受版权保护,版权持有者可以对字体程序的使用施加条件。这些权限要么记录在字体程序中,要么作为单独许可证的一部分。一个条件可能是禁止嵌入字体程序,在这种情况下,它不应被纳入PDF文件。字体程序可能允许仅用于查看和打印文档,但不能用于创建使用该字体的新文本或修改文本(无论是在同一文档还是其他文档中)。后者的操作需要执行操作的用户拥有该字体程序的许可副本,而不是从PDF文件中提取的副本。如果没有明确的相反信息,嵌入的字体程序应仅用于查看和打印文档,不得用于任何其他用途。

表格126总结了字体程序应如何嵌入PDF文件,具体取决于字体程序的表示形式。键应是字体描述符中用于引用字体文件流的名称;如果存在,子类型应是字体文件流字典中Subtype键的值。具体字体程序表示形式的更多细节见下文。

表格126 – 不同字体类型的嵌入字体组织
子类型 描述
FontFile Type 1字体程序,以Adobe Type 1字体格式中描述的原始(非紧凑)格式表示。此条目可能出现在Type1MMType1字体字典的字体描述符中。
FontFile2 (PDF 1.1)TrueType字体程序,按照TrueType参考手册中的描述。此条目可能出现在TrueType字体字典或(PDF 1.3)CIDFontType2 CIDFont字典的字体描述符中。
FontFile3 Type1C (PDF 1.2)Type 1等效字体程序,采用紧凑字体格式(CFF)表示,按照Adobe技术笔记#5176,紧凑字体格式规范中的描述。此条目可能出现在Type1MMType1字体字典的字体描述符中。
FontFile3 CIDFontType0C (PDF 1.3)Type 0 CIDFont程序,以紧凑字体格式(CFF)表示,按照Adobe技术笔记#5176,紧凑字体格式规范中的描述。此条目可能出现在CIDFontType0 CIDFont字典的字体描述符中。
FontFile3 OpenType (PDF 1.6)OpenType®字体程序,按照OpenType规范v.1.4(见参考书目)中的描述。OpenType是TrueType的扩展,允许包含使用紧凑字体格式(CFF)的字体程序。
一个具有OpenType子类型的FontFile3条目可能出现在以下类型的字体字典的字体描述符中:

  • TrueType字体字典或CIDFontType2 CIDFont字典,如果嵌入的字体程序包含“glyf”表。除了“glyf”表外,字体程序还必须包含以下表: “head”、 “hhea”、 “hmtx”、 “loca”和“maxp”。如果字体指令要求,还必须包括“cvt ”(注意尾部空格)、 “fpgm”和“prep”表。
  • CIDFontType0 CIDFont字典,如果嵌入的字体程序包含一个“CFF ”表(注意尾部空格),且其Top DICT使用CIDFont操作符(这等同于子类型CIDFontType0C)。除了“CFF ”表外,字体程序还必须包含“cmap”表。
  • Type1字体字典或CIDFontType0 CIDFont字典,如果嵌入的字体程序包含没有CIDFont操作符的“CFF ”表。除了“CFF ”表外,字体程序还必须包含“cmap”表。

OpenType规范描述了一组必需的表格;然而,并非所有表格都在字体文件中是必需的,如每种字体字典中可以包含此条目的情况所描述。

某些可选表格(如用于高级行布局的表格)的缺失可能会阻止编辑包含该字体的文本。

字体文件的流字典应包含流的正常条目,如LengthFilter(见表格5),以及表127中列出的附加条目。

表格127 – 嵌入字体流字典中的附加条目
类型
Length1 整数 (适用于Type 1和TrueType字体) Type 1字体程序的明文部分的字节长度,或整个TrueType字体程序的字节长度,前提是它已使用流的Filter条目(如果有)指定的过滤器解码。
Length2 整数 (适用于Type 1字体) Type 1字体程序的加密部分的字节长度,前提是它已使用流的Filter条目指定的过滤器解码。
Length3 整数 (适用于Type 1字体) Type 1字体程序的固定内容部分的字节长度,前提是它已使用流的Filter条目指定的过滤器解码。如果Length3为0,则表示FontFile字体程序中未包含512个零和cleartomark操作符,这些内容应由符合规范的读取器添加。
Subtype 名称 (如果引用自FontFile3,则为必需;PDF 1.2) 一个名称,指定嵌入字体程序的格式。该名称应为Type1C(表示Type 1紧凑字体)、CIDFontType0C(表示Type 0紧凑CIDFont),或OpenType(表示OpenType字体)。
Metadata (可选;PDF 1.4) 一个元数据流,包含嵌入字体程序的元数据(见14.3.2,“元数据流”)。

注 2

标准的Type 1字体程序,按照Adobe Type 1字体格式规范的描述,包含三个部分:明文部分(使用PostScript语法编写)、加密部分和固定内容部分。固定内容部分包含512个ASCII零,后面是cleartomark操作符,可能还会跟随其他数据。尽管标准Type 1字体的加密部分可以是二进制格式或ASCII十六进制格式,PDF仅支持二进制格式。然而,整个字体程序可以使用任何过滤器进行编码。

示例

下面的代码展示了一个嵌入的标准Type 1字体的结构。

12 0 obj
    <<  /Filter /ASCII85Decode
        /Length 41116
        /Length1 2526
        /Length2 32393
        /Length3 570
    >>
stream
,p>`rDKJj'E+LaU0eP.@+AH9dBOu$hFD55nC
… 省略数据 …
JJQ&Nt')<=^p&mGf(%:%h1%9c//K(/*o=.C>UXkbVGTrr~>
endstream
endobj

正如在表格126中所述,Type 1等效字体程序或Type 0 CIDFont程序可以采用紧凑字体格式(CFF)表示。在这种情况下,Length1Length2Length3条目不需要,并且不得存在。尽管CFF允许将多个字体或CIDFont程序打包成一个文件,但PDF中的嵌入式CFF字体文件应只包含一个字体或CIDFont(根据关联的字体字典适用)。

根据Adobe Type 1字体格式规范,Type 1字体程序可能包含一个PaintType条目,指定字形轮廓是填充还是描边。对于嵌入PDF文件的字体,必须忽略此条目;填充或描边字形轮廓的决定完全由PDF文本渲染模式参数决定(见9.3.6,“文本渲染模式”)。这也适用于Type 1紧凑字体和Type 0紧凑CIDFonts。

TrueType字体程序可以作为字体或CIDFont的一部分使用。尽管两种情况的基本字体文件格式相同,但对于字体程序中应包含哪些信息,有不同的要求。以下TrueType表格如果在原始TrueType字体程序中存在,则必须始终存在:“head”、“hhea”、“loca”、“maxp”、“cvt”、“prep”、“glyf”、“hmtx”和“fpgm”。如果与简单字体字典一起使用,字体程序还必须包含一个cmap表,定义一个或多个编码,详见9.6.6.4,“TrueType字体的编码”。如果与CIDFont字典一起使用,则不需要cmap表,并且不得存在,因为字符代码到字形描述的映射是单独提供的。

“vhea”和“vmtx”表格指定的垂直度量永远不能被符合规范的读取器使用。指定垂直度量的唯一方法应通过CIDFont字典中的DW2W2条目。

注 3

从PDF 1.6开始,字体程序可以使用OpenType格式嵌入,这是TrueType格式的扩展,允许包含使用紧凑字体格式(CFF)的字体程序。它还允许包含描述字形替换、字距调整和基线调整的数据。除了渲染字形外,符合规范的读取器还可以使用OpenType字体中的数据进行高级行布局,自动替换连字,为用户提供替代字形的选择,并处理复杂的书写脚本。

符合规范的读取器查找OpenType字体中的字形描述的过程应如下:

  • 对于使用“CFF”表的Type 1字体,过程应如9.6.6.2中所述,“Type 1字体的编码”。
  • 对于使用“glyf”表的TrueType字体,过程应如9.6.6.4中所述,“TrueType字体的编码”。由于此过程有时会产生模糊结果,符合规范的写入器应使用Type 0字体,并使用Identity-H编码,将字形索引作为字符代码,而不是使用简单字体,详见表格118之后的内容。
  • 对于使用“CFF”表的CIDFontType0字体,过程应如9.7.4.2中关于嵌入式Type 0 CIDFonts的讨论所述,“CIDFonts中的字形选择”。
  • 对于使用“glyf”表的CIDFontType2字体,过程应如9.7.4.2中关于嵌入式Type 2 CIDFonts的讨论所述,“CIDFonts中的字形选择”。

9.6.4中所述,“字体子集”,嵌入的字体程序可以仅包含PDF文档中使用的字形子集。这可以通过字体描述符中的CharSetCIDSet条目的存在来指示,该条目引用字体文件。

A font program may be embedded in a PDF file as data contained in a PDF stream object.

NOTE 1

Such a stream object is also called a font file by analogy with font programs that are available from sources external to the conforming writer.

Font programs are subject to copyright, and the copyright owner may impose conditions under which a font program may be used. These permissions are recorded either in the font program or as part of a separate license. One of the conditions may be that the font program cannot be embedded, in which case it should not be incorporated into a PDF file. A font program may allow embedding for the sole purpose of viewing and printing the document but not for creating new or modified text that uses the font (in either the same document or other documents). The latter operation would require the user performing the operation to have a licensed copy of the font program, not a copy extracted from the PDF file. In the absence of explicit information to the contrary, embedded font programs shall be used only to view and print the document and not for any other purposes.

Table 126 summarizes the ways in which font programs shall be embedded in a PDF file, depending on the representation of the font program. The key shall be the name used in the font descriptor to refer to the font file stream; the subtype shall be the value of the Subtype key, if present, in the font file stream dictionary. Further details of specific font program representations are given below.

Table 126 – Embedded font organization for various font types
Key Subtype Description
FontFile Type 1 font program, in the original (noncompact) format described in Adobe Type 1 Font Format. This entry may appear in the font descriptor for a Type1 or MMType1 font dictionary.
FontFile2 (PDF 1.1) TrueType font program, as described in the TrueType Reference Manual. This entry may appear in the font descriptor for a TrueType font dictionary or (PDF 1.3) for a CIDFontType2 CIDFont dictionary.
FontFile3 Type1C (PDF 1.2) Type 1–equivalent font program represented in the Compact Font Format (CFF), as described in Adobe Technical Note #5176, The Compact Font Format Specification. This entry may appear in the font descriptor for a Type1 or MMType1 font dictionary.
FontFile3 CIDFontType0C (PDF 1.3) Type 0 CIDFont program represented in the Compact Font Format (CFF), as described in Adobe Technical Note #5176, The Compact Font Format Specification. This entry may appear in the font descriptor for a CIDFontType0 CIDFont dictionary.
FontFile3 OpenType (PDF 1.6) OpenType® font program, as described in the OpenType Specification v.1.4 (see the Bibliography). OpenType is an extension of TrueType that allows inclusion of font programs that use the Compact Font Format (CFF).
A FontFile3 entry with an OpenType subtype may appear in the font descriptor for these types of font dictionaries:
- A TrueType font dictionary or a CIDFontType2 CIDFont dictionary, if the embedded font program contains a “glyf” table. In addition to the “glyf” table, the font program must include these tables: “head”, “hhea”, “hmtx”, “loca”, and “maxp”. The “cvt ” (notice the trailing SPACE), “fpgm”, and “prep” tables must also be included if they are required by the font instructions. - A CIDFontType0 CIDFont dictionary, if the embedded font program contains a “CFF ” table (notice the trailing SPACE) with a Top DICT that uses CIDFont operators (this is equivalent to subtype CIDFontType0C). In addition to the “CFF ” table, the font program must include the “cmap” table. - A Type1 font dictionary or CIDFontType0 CIDFont dictionary, if the embedded font program contains a “CFF ” table without CIDFont operators. In addition to the “CFF ” table, the font program must include the “cmap” table.

The OpenType Specification describes a set of required tables; however, not all tables are required in the font file, as described for each type of font dictionary that can include this entry.

NOTE

The absence of some optional tables (such as those used for advanced line layout) may prevent editing of text containing the font.

The stream dictionary for a font file shall contain the normal entries for a stream, such as Length and Filter (listed in Table 5), plus the additional entries listed in Table 127.

Table 127 – Additional entries in an embedded font stream dictionary
Key Type Value
Length1 integer (Required for Type 1 and TrueType fonts) The length in bytes of the clear-text portion of the Type 1 font program, or the entire TrueType font program, after it has been decoded using the filters specified by the stream’s Filter entry, if any.
Length2 integer (Required for Type 1 fonts) The length in bytes of the encrypted portion of the Type 1 font program after it has been decoded using the filters specified by the stream’s Filter entry.
Length3 integer (Required for Type 1 fonts) The length in bytes of the fixed-content portion of the Type 1 font program after it has been decoded using the filters specified by the stream’s Filter entry. If Length3 is 0, it indicates that the 512 zeros and cleartomark have not been included in the FontFile font program and shall be added by the conforming reader.
Subtype name (Required if referenced from FontFile3; PDF 1.2) A name specifying the format of the embedded font program. The name shall be Type1C for Type 1 compact fonts, CIDFontType0C for Type 0 compact CIDFonts, or OpenType for OpenType fonts.
Metadata stream (Optional; PDF 1.4) A metadata stream containing metadata for the embedded font program (see 14.3.2, "Metadata Streams").

NOTE 2

A standard Type 1 font program, as described in the Adobe Type 1 Font Format specification, consists of three parts: a clear-text portion (written using PostScript syntax), an encrypted portion, and a fixed-content portion. The fixed-content portion contains 512 ASCII zeros followed by a cleartomark operator, and perhaps followed by additional data. Although the encrypted portion of a standard Type 1 font may be in binary or ASCII hexadecimal format, PDF supports only the binary format. However, the entire font program may be encoded using any filters.

EXAMPLE

This code shows the structure of an embedded standard Type 1 font.

12 0 obj
    <<  /Filter /ASCII85Decode
        /Length 41116
        /Length1 2526
        /Length2 32393
        /Length3 570
    >>
stream
,p>`rDKJj'E+LaU0eP.@+AH9dBOu$hFD55nC
… Omitted data …
JJQ&Nt')<=^p&mGf(%:%h1%9c//K(/*o=.C>UXkbVGTrr~>
endstream
endobj

As noted in Table 126, a Type 1–equivalent font program or a Type 0 CIDFont program may be represented in the Compact Font Format (CFF). The Length1, Length2, and Length3 entries are not needed in that case and shall not be present. Although CFF enables multiple font or CIDFont programs to be bundled together in a single file, an embedded CFF font file in PDF shall consist of exactly one font or CIDFont (as appropriate for the associated font dictionary).

According to the Adobe Type 1 Font Format specification, a Type 1 font program may contain a PaintType entry specifying whether the glyphs’ outlines are to be filled or stroked. For fonts embedded in a PDF file, this entry shall be ignored; the decision whether to fill or stroke glyph outlines is entirely determined by the PDF text rendering mode parameter (see 9.3.6, "Text Rendering Mode"). This shall also applies to Type 1 compact fonts and Type 0 compact CIDFonts.

A TrueType font program may be used as part of either a font or a CIDFont. Although the basic font file format is the same in both cases, there are different requirements for what information shall be present in the font program. These TrueType tables shall always be present if present in the original TrueType font program: “head”, “hhea”, “loca”, “maxp”, “cvt”, “prep”, “glyf”, “hmtx”, and “fpgm”. If used with a simple font dictionary, the font program shall additionally contain a cmap table defining one or more encodings, as discussed in 9.6.6.4, "Encodings for TrueType Fonts". If used with a CIDFont dictionary, the cmap table is not needed and shall not be present, since the mapping from character codes to glyph descriptions is provided separately.

The “vhea” and “vmtx” tables that specify vertical metrics shall never be used by a conforming reader. The only way to specify vertical metrics in PDF shall be by means of the DW2 and W2 entries in a CIDFont dictionary.

NOTE 3

Beginning with PDF 1.6, font programs may be embedded using the OpenType format, which is an extension of the TrueType format that allows inclusion of font programs using the Compact Font Format (CFF). It also allows inclusion of data to describe glyph substitutions, kerning, and baseline adjustments. In addition to rendering glyphs, conforming readers may use the data in OpenType fonts to do advanced line layout, automatically substitute ligatures, provide selections of alternate glyphs to users, and handle complex writing scripts.

The process of finding glyph descriptions in OpenType fonts by a conforming reader shall be the following:

  • For Type 1 fonts using “CFF” tables, the process shall be as described in 9.6.6.2, "Encodings for Type 1 Fonts".
  • For TrueType fonts using “glyf” tables, the process shall be as described in 9.6.6.4, "Encodings for TrueType Fonts". Since this process sometimes produces ambiguous results, conforming writers, instead of using a simple font, shall use a Type 0 font with an Identity-H encoding and use the glyph indices as character codes, as described following Table 118.
  • For CIDFontType0 fonts using “CFF” tables, the process shall be as described in the discussion of embedded Type 0 CIDFonts in 9.7.4.2, "Glyph Selection in CIDFonts".
  • For CIDFontType2 fonts using “glyf” tables, the process shall be as described in the discussion of embedded Type 2 CIDFonts in 9.7.4.2, "Glyph Selection in CIDFonts".

As discussed in 9.6.4, "Font Subsets", an embedded font program may contain only the subset of glyphs that are used in the PDF document. This may be indicated by the presence of a CharSet or CIDSet entry in the font descriptor that refers to the font file.