跳转至

9.5 字体数据结构简介

9.5 Introduction to Font Data Structures

在 PDF 中,字体通过字典来表示,该字典指定了字体的类型PostScript 名称编码方式,以及当字体程序不可用时可用于替代的信息。此外,字体程序可以选择嵌入到 PDF 文件中,作为流对象存储。

字体类型由字体字典中的 Subtype 条目区分。表 110 列出了 PDF 支持的字体类型。其中,Type 0 字体称为 复合字体(composite fonts),其余字体类型称为简单字体(simple fonts)。
除了普通字体,PDF 还支持两类与字体相关的对象:CIDFontsCMaps(详见 9.7.2 “CID-Keyed Fonts Overview”)。虽然 CIDFont 也是字形的集合,但其不能直接使用,而必须作为 Type 0 字体的一部分。


表 110 – 字体类型
类型 Subtype 值 描述
Type 0 Type0 (PDF 1.2) 复合字体——由后代 CIDFont 组成的字体(详见 9.7 “复合字体”)
Type 1 Type1 使用 Type 1 字体技术定义字形的字体(详见 [9.6.2] “Type 1 字体”)
  MMType1 多主字体(Multiple Master Font)——Type 1 字体的扩展,可从单一字体生成多种不同的字型风格(详见 9.6.2.3 “多主字体”)
Type 3 Type3 使用 PDF 图形操作符流定义字形的字体(详见 9.6.5 “Type 3 字体”)
True Type TrueType 基于 TrueType 字体格式的字体(详见 9.6.3 “TrueType 字体”)
CIDFont CIDFontType0 (PDF 1.2) 基于 Type 1 字体技术的 CIDFont(详见 9.7.4 “CIDFonts”)
  CIDFontType2 (PDF 1.2) 基于 TrueType 字体技术的 CIDFont(详见 9.7.4 “CIDFonts”)


字体字典与 CIDFont 字典

对于所有字体类型,术语 字体字典(font dictionary)指的是 PDF 字典对象,包含有关字体的各种信息;类似地,CIDFont 字典 包含有关 CIDFont 的信息。
Type 3 字体 外,该字典与定义字体字形的字体程序是分开的。字体程序可以嵌入到 PDF 文件中(作为流对象),或从外部来源获取。

注意 1

这里的术语与 PostScript 语言中的术语有所不同。在 PostScript 中,字体字典是由字体程序解析后直接生成的数据结构。
在 PDF 中,字体程序始终被视为一个独立文件,即使其内容嵌入到了 PDF 文件中。
只有当需要时,专门的字体解释器才会解析该字体程序;它的内容不会以 PDF 对象的形式直接呈现。

注意 2

大多数字体程序(以及相关的字体对象,如 CIDFonts 和 CMaps)符合外部规范,如 Adobe Type 1 Font Format。本标准不包含这些外部规范的详细信息,相关信息请参考附录中的参考文献。

注意 3

最稳定、最可预测的结果通常出现在所有用于文本显示的字体程序嵌入到 PDF 文件时。
接下来的子章节将详细描述如何嵌入字体。
如果 PDF 文件引用了未嵌入的字体,则渲染效果取决于阅读器环境中字体的可用性
本标准规定了一些外部字体引用的约定,但字体命名、字体替换及字形选择的某些细节取决于具体实现,在不同的 PDF 阅读器、PDF 生成器及操作系统环境中可能会有所不同。

A font shall be represented in PDF as a dictionary specifying the type of font, its PostScript name, its encoding, and information that can be used to provide a substitute when the font program is not available. Optionally, the font program may be embedded as a stream object in the PDF file.

The font types are distinguished by the Subtype entry in the font dictionary. Table 110 lists the font types defined in PDF. Type 0 fonts are called composite fonts; other types of fonts are called simple fonts. In addition to fonts, PDF supports two classes of font-related objects, called CIDFonts and CMaps, described in 9.7.2, "CID-Keyed Fonts Overview". CIDFonts are listed in Table 110 because, like fonts, they are collections of glyphs; however, a CIDFont shall not be used directly but only as a component of a Type 0 font.

Table 110 – Font types
Type Subtype Value Description
Type 0 Type0 (PDF 1.2) A composite font—a font composed of glyphs from a descendant CIDFont (see 9.7, "Composite Fonts")
Type 1 Type1 A font that defines glyph shapes using Type 1 font technology (see [9.6.2], "Type 1 Fonts").
  MMType1 A multiple master font—an extension of the Type 1 font that allows the generation of a wide variety of typeface styles from a single font (see 9.6.2.3, "Multiple Master Fonts")
Type 3 Type3 A font that defines glyphs with streams of PDF graphics operators (see 9.6.5, "Type 3 Fonts")
True Type TrueType A font based on the TrueType font format (see 9.6.3, "TrueType Fonts")
CIDFont CIDFontType0 (PDF 1.2) A CIDFont whose glyph descriptions are based on Type 1 font technology (see 9.7.4, "CIDFonts")
  CIDFontType2 (PDF 1.2) A CIDFont whose glyph descriptions are based on TrueType font technology (see 9.7.4, "CIDFonts")

For all font types, the term font dictionary refers to a PDF dictionary containing information about the font; likewise, a CIDFont dictionary contains information about a CIDFont. Except for Type 3, this dictionary is distinct from the font program that defines the font’s glyphs. That font program may be embedded in the PDF file as a stream object or be obtained from some external source.

NOTE 1

This terminology differs from that used in the PostScript language. In PostScript, a font dictionary is a PostScript data structure that is created as a direct result of interpreting a font program. In PDF, a font program is always treated as if it were a separate file, even when its content is embedded in the PDF file. The font program is interpreted by a specialized font interpreter when necessary; its contents never materialize as PDF objects.

NOTE 2

Most font programs (and related programs, such as CIDFonts and CMaps) conform to external specifications, such as the Adobe Type 1 Font Format. This standard does not include those specifications. See the Bibliography for more information about the specifications mentioned in this clause.

NOTE 3

The most predictable and dependable results are produced when all font programs used to show text are embedded in the PDF file. The following sub-clauses describe precisely how to do so. If a PDF file refers to font programs that are not embedded, the results depend on the availability of fonts in the conforming reader’s environment. The following sub-clauses specify some conventions for referring to external font programs. However, some details of font naming, font substitution, and glyph selection are implementation-dependent and may vary among different conforming readers, writers and operating system environments.