CFF and OpenType Font Subsetting Functions

PDF 篩選器支援

 

傳回頂部  EnableFontSubsetting  目錄

這些 unit-level functions 會暴露 HotPDF embedded font pipeline 使用的公開 CFF、OpenType-CFF 與 sfnt font-inspection surface。HotPDF 也隨附可重複使用的 Type 1 PFB 與 CFF parser units,供需要較低階 font inspection 的呼叫端使用

 

Delphi 語法

function HPDFSubsetCFF(const CFFBytes: TBytes; const KeepGlyph: array of Boolean): TBytes;

function HPDFIsCFF2Font(const FontBytes: TBytes): Boolean;

function HPDFInstantiateCFF2Font(const FontBytes: TBytes; const AxisValues: THPDFVariableFontAxisValueArray): TBytes;

function HPDFSubsetCFF2Font(const FontBytes: TBytes; const KeepGlyph: array of Boolean): TBytes;

function HPDFIsTrueTypeVariableFont(const FontBytes: TBytes): Boolean;

function HPDFInstantiateTrueTypeVariableFont(const FontBytes: TBytes; const AxisValues: THPDFVariableFontAxisValueArray): TBytes;

function HPDFSfntIsOTF(const Data: TBytes): Boolean;

function HPDFOTFFindCFFTable(const Data: TBytes; out TableOff: Cardinal; out TableLen: Cardinal): Boolean;

function HPDFSubsetOTFContainer(const OTFBytes: TBytes; const KeepGlyph: array of Boolean): TBytes;

function HPDFExtractTTFPostScriptName(const Data: TBytes): AnsiString;

 

說明

HPDFSubsetCFF 會就地改寫 CFF 字型內容,保留 glyph ID,並把未使用的 CharStrings 與 subroutines 換成最小 stub。這是給已經從字型容器取出 CFF table 的呼叫端使用的 helper

 

HPDFIsCFF2Font 會偵測含 CFF2 table 的 sfnt。HPDFInstantiateCFF2Font 會透過 avar 1.0 或 2.0 解析選定的 fvar 座標、在遞迴 subroutines 中評估由 VariationStore 支撐的 blend 運算、烘焙 HVAR、VVAR 與 MVAR metrics、移除 variable tables,最後傳回 checksum 正確的靜態 sfnt

 

HPDFSubsetCFF2Font 執行同樣的 default-coordinate instancing,並把未使用的 glyph 程式換成空 CharStrings。它會保留 glyph ID、multi-FD 字典、private hint 資料與字型矩陣

 

HPDFIsTrueTypeVariableFont 會偵測含 fvar、glyf 與 loca 的 sfnt。HPDFInstantiateTrueTypeVariableFont 會透過 avar 對應選定的軸、評估 gvar tuples 與 IUP 內插、更新簡單與複合外框及 phantom-point metrics,並在適用時套用 HVAR、VVAR 與 MVAR、移除 variation tables,最後傳回 checksum 正確的靜態 sfnt

 

HPDFSfntIsOTF 會偵測版本為 OTTO 的 sfnt 容器。HPDFOTFFindCFFTable 會找出內嵌的 'CFF ' table。HPDFSubsetOTFContainer 會子集化內嵌的 CFF 或 CFF2 資料,並傳回 sfnt checksum 正確的 OTF 容器。HPDFExtractTTFPostScriptName 會從 sfnt name table 讀取 name ID 6,並在存在時傳回 PostScript font name

 

subsetter 會同時識別 name-keyed CFF(單一 Private DICT、單一 Local Subr INDEX)與 CID-keyed CFF(Top DICT ROS operator、多個 sub-font Private DICT 的 FDArray、FDSelect glyph-to-FD map、per-FD Local Subr INDEXes)。CID 支援涵蓋 CJK / Indic / Arabic OpenType-CFF fonts;closure scan 會追蹤每個保留 CharString 的 FD context,因此 per-FD Local Subr INDEXes 可獨立子集化

 

較低階的 CFF integer decoders、FDArray / FDSelect parsers 與 subroutine scanners 都是此公開 helper surface 後方的實作細節

 

Type 1 and CFF parser units

HPDFType1Core、HPDFType1Glyphs、HPDFType1CFFHandler 與 HPDFType1PFBHandler 提供可重複使用的 byte-array readers、Type 1 glyph-outline command extraction、CFF Header / INDEX / dictionary / charset / encoding parsing,以及 Type 1 PFB metadata 與 glyph lookup helpers。HPDFType1CFFHandler 會在 FontSet 中解析 SyntheticBase 繼承,涵蓋 Top 與 Private DICT 值、CharStrings、charset、Encoding 與 Local Subrs,同時拒絕無效的索引、循環與過深層級。HPDFType1CB 提供 C++Builder 友善的 parser 進入點。這些 units 已包含在 Delphi 與 C++Builder package projects 中,因此應用程式可檢查 Type 1 PFB 與 CFF 資料,而不必重新實作 binary parsers

 

請參閱: EnableFontSubsetting, FontEmbedding, PDF 篩選器支援

Type 2 堆疊運算與子常式安全

原生字形轉譯器實作標準的 Type 2 布林、算術、條件、暫存陣列與堆疊運算,包括 put、get、ifelse、random、dup、exch、index 與 roll

暫存值會在每個字形重設,隨機值可重現,而運算元、暫存陣列、遞迴與執行上限會拒絕格式錯誤的程式,不會回傳不完整的外框

子集掃描器會解析本地與全域子常式呼叫用到的算術與暫存陣列運算式,包括 Type 2 16.16 定點數運算元

當隨機值、未知暫存狀態或跨程序的堆疊效應讓呼叫目標無法確定時,子集化會保留每一個候選子常式,而不是丟掉可能還連得到的外框相依

保留與已棄用的 Multiple Master 運算仍不支援,並會明確失敗