THPDFFontDecoder 记录
保存一个已加载 PDF 字体的解析结果:解码表和宽度度量,由字体解码回退链构建
声明
THPDFFontDecoder= record
FontKey: AnsiString; // resource key (e.g. /F1) for diagnostics
Subtype: AnsiString; // Type0, Type1, TrueType, CIDFontType2
Strategies: THPDFFontStrategies; // which fallbacks are populated
ToUnicodeMap: THPDFCMapParseResult;
EncodingMap: THPDFCMapParseResult; // /Encoding stream or named CMap
PredefinedEncoding: AnsiString; // 'WinAnsiEncoding' etc
CIDToGIDIdentity: boolean;
CIDToGIDs: array of Word; // binary CIDToGIDMap stream
CIDToUnicode: THPDFCIDToUnicodeTable; // cid2code.txt fallback
GlyphNameUnicode: array[0.. 255] of Cardinal;
GIDToUnicode: THPDFUnicodeByGID;
// v2.505.0 simple-font /Widths (PDF 1.7 9.6.3 Table 111). Index =
// (code - FirstChar); values are 1/1000-em glyph advances. Empty when
// the font has no /Widths array (the interpreter falls back to 0.5*fs)
Widths: array of Double;
FirstChar: Integer;
LastChar: Integer;
CIDWidths: THPDFCIDWidthRanges;
CIDDefaultWidth: Double;
// Vertical (WMode 1) counterparts from the descendant CIDFont /W2 and
// /DW2 (ISO 32000-1 9.7.4.3). Each /W2 metric is a [w1y v1x v1y]
// triple: w1y is the displacement along the writing axis, v1x/v1y the
// position vector from the glyph's horizontal origin to its vertical
// origin. A range entry (cFirst cLast w1y v1x v1y) stores one triple;
// a list entry (c [w1y v1x v1y ...]) stores one triple per CID from
// FirstCID to LastCID. VerticalWriting gates the resolver's vertical
// branch
CIDVertWidths: THPDFCIDWidthRanges;
CIDVertDefaultAdvance: Double; // /DW2 w1y (second entry); default -1000
CIDVertDefaultOriginY: Double; // /DW2 v1y (first entry); default 880
VerticalWriting: boolean;
Ascent: Double;
Descent: Double;
HasVerticalMetrics: boolean;
CodeUnitBytes: Integer; // bytes per char code
OK: boolean;
end;
单元
HPDFTextExtraction
字段
| 字段 | 用途 |
|---|---|
FontKey | 命名字体的资源键,例如 /F1,保留用于诊断 |
Subtype | 字体字典子类型:Type0、Type1、TrueType、CIDFontType2 等 |
Strategies | 成功填充的回退策略集合 |
ToUnicodeMap | 解析出的 /ToUnicode CMap,含 bfchar 和 bfrange 条目,优先级最高 |
EncodingMap | 解析出的 /Encoding 流或命名 CMap |
PredefinedEncoding | 预定义编码名称,例如 WinAnsiEncoding |
CIDToGIDIdentity | CIDToGIDMap 为 Identity 且不需要显式表时为 True |
CIDToGIDs | 二进制 CIDToGIDMap 流,已展开为每个 CID 一个 Word |
CIDToUnicode | 来自 cid2code.txt 回退的 CID 到 Unicode 表 |
GlyphNameUnicode | 供 /Differences 恢复使用的 256 项字形名到 Unicode 表 |
GIDToUnicode | 嵌入 cmap 反转得到的字形 ID 到 Unicode 映射 |
Widths | 简单字体的 /Widths 步进,单位为 1/1000 em,以码值减去 FirstChar 作为索引 |
FirstChar | Widths 数组支持的第一个字符码 |
LastChar | Widths 数组支持的最后一个字符码 |
CIDWidths | 来自 CIDFont /W 数组的 CID 宽度区间 |
CIDDefaultWidth | 来自 /DW 的默认 CID 前进量 |
CIDVertWidths | 垂直 /W2 度量,按 CID 或区间存储为 [w1y v1x v1y] 三元组 |
CIDVertDefaultAdvance | 来自 /DW2 w1y 的默认垂直位移,默认为 -1000 |
CIDVertDefaultOriginY | 来自 /DW2 v1y 的默认垂直原点,默认为 880 |
VerticalWriting | WMode 1 度量决定解析器走垂直分支时为 True |
Ascent | 从字体描述符度量读取的字体上伸值 |
Descent | 从字体描述符度量读取的字体下伸值 |
HasVerticalMetrics | 找到该字体的垂直度量时为 True |
CodeUnitBytes | 每个字符码的字节数,向内容解释器报告该字体的这一取值 |
OK | 至少有一个解码策略可用时为 True |
使用说明
- 用
HPDFBuildFontDecoder构建;纯记录让一整页的字体开销都很小,自身没有任何堆分配 HPDFDecodeCharCode按优先级顺序遍历各策略,未命中返回 0;缺失的流会静默降级到下一个策略- 当解码器必须比产生它的缓存存活更久时,调用
HPDFCloneFontDecoder,因为动态数组是按引用共享的