|
automatic shaping pipeline 會將 OpenType GSUB engine 從 capability-only query surface 提升為 producer-side feature,在文字輸出到 PDF content streams 時自動套用。呼叫端透過 typed set(ShapingFeatures: THPDFShapingFeatures)啟用特定 GSUB features,HotPDF 會負責執行正確 substitutions、將 substitute glyphs 標記進 embedded font subset,並輸出 accessibility 所需的 ToUnicode CMap reverse-mapping entries
Opt-in framework(v2.119.59 / Phase 8a)
新增的 enum 與 property 決定文字輸出期間要執行哪些自動 substitutions:
type
THPDFShapingFeature = (
sfArabicGSUB, // native Arabic init / medi / fina / isol + rlig / calt / rclt
sfStandardLigatures, // Latin 'liga' (ff / fi / fl / ffi / ffl / sft / st)
sfContextualLigatures,// Latin 'clig' (contextual ligatures)
sfContextualAlternates,// 'rclt' (Required Contextual Alternates)
sfIndicShaping); // Devanagari Repha + pre-base I-matra reorder
THPDFShapingFeatures = set of THPDFShapingFeature;
property ShapingFeatures: THPDFShapingFeatures read ... write ...;
預設值為 [](empty set),會為依賴 v2.119.32-58 static post-pass shaper 的呼叫端保留 byte-identical output。設定一個或多個 flags 會將 engine 提升為對應 features 的 automatic mode
sfArabicGSUB - 原生阿拉伯文 GSUB 塑形(v2.185.0)
設定 sfArabicGSUB 時,HotPDF 會將 logical Arabic run 對應到 base glyph IDs,依每個字母選定的 joining positions 套用已註冊字型的 positional init、medi、fina 與 isol lookups,接著在 shaped run 上套用 rlig、calt 與 rclt。沒有 Unicode codepoint 的 substitute glyphs 會透過 synthetic-codepoint path 與 ToUnicode reverse mappings 輸出,因此 contextual Arabic glyphs 位於 cmap 外的字型仍可正確嵌入與複製
設定 sfArabicGSUB 會隱含略過 v2.85.0 Arabic static 4-position shaper;若呼叫端需要 static shaper 繼續處理字型 GSUB 未宣告的 codepoints,應保持 sfArabicGSUB 關閉
sfStandardLigatures / sfContextualLigatures - Phase 8b(v2.119.65)
設定 sfStandardLigatures 時,Latin Standard Ligatures 會使用字型的 liga feature 自動摺疊。ApplyLatinLigatureRefinement 目標為 Alphabetic Presentation Forms block(U+FB00-FB4F),通常是 FB00 ff、FB01 fi、FB02 fl、FB03 ffi、FB04 ffl、FB05 long-s + t、FB06 st。sfContextualLigatures 會為字型的 clig feature 加入第二個 pass。兩個 passes 都使用與 sfArabicGSUB 相同的 reverse-cmap mechanism,並輸出 7 個新的 ToUnicode CMap reverse-mapping entries(FB00-FB06),讓閱讀端 copy / paste 可將 ligature 解析回來源字母
sfContextualAlternates - GSUB 'rclt'(v2.119.66)
設定 sfContextualAlternates 時,會套用字型的 rclt(Required Contextual Alternates)feature。ApplyArabicGSUBContextualRefinement 使用 v2.119.47 ApplyContextualSubst entry point,並處理 variable-length N-to-M output(只有每個 replacement GID 都可透過 reverse cmap 抵達時,substitution 才會提交)。Reverse cmap range 擴充到 FB00-FDFF + FE70-FEFF,以涵蓋 Latin + Arabic + Hebrew Presentation Forms
rclt 的典型使用者:字型以 GSUB 而非 Unicode Presentation Forms codepoint 驅動位置塑形時的阿拉伯文 init / medi / fina / isol;部分拉丁文字序列消歧規則;以及由字型設計者註冊為 rclt 的 Indic 塑形 pres / blws / psts / half / pstf / cjct features
sfIndicShaping - Phase 8e(v2.119.67)
設定 sfIndicShaping 時,v2.119.55 Devanagari capability ApplyDevanagariReorder 會從手動 method 提升為套用於三個 BuildUnicode*FieldContent helpers 內的 automatic pre-pass。Devanagari runs 會將 Repha(cluster 起始處的 Ra + Halant)移到 post-base position,並將 pre-base I-matra(U+093F)移到 cluster base consonant 前方,使閱讀端的 GSUB engine 能以正確 rendering order 取得 syllable。其他 Indic reorders(above-base / below-base matra、conjunct formation)仍留給字型的 GSUB
advance 查詢支援(v2.119.64 / Phase 8c.5)
配套 API 會公開快取的 /W em-fraction,讓呼叫端在輸出 GSUB-substituted glyphs 時能正確計算 word-wrap:
function GetCodepointAdvance(CP: Cardinal): Single;
會以 em 的分數傳回 CP 所對應 cmap glyph 的 hmtx 衍生 advance width。同一版本也修正了 CodeUnitAdvance,把 Arabic Presentation Forms(U+FB50-FDFF + U+FE70-FEFF)歸類為 NARROW 而非 WIDE(v2.65 之前採用的 heuristic fallback 是錯的)
典型工作流程(完整阿拉伯文自動塑形)
PDF.RegisterUnicodeTTF('NotoArab', 'NotoSansArabic-Regular.ttf');
PDF.ShapingFeatures :=
[sfArabicGSUB, // native Arabic GSUB contextual glyphs
sfCursiveAttachment]; // GPOS cursive entry / exit anchors
PDF.SetGSUBScript('arab');
PDF.BeginDoc;
PDF.CurrentPage.SetFont('NotoArab', [], 14);
PDF.CurrentPage.RtLTextOut(100, 700, 0,
UnicodeString(#$0628#$0633#$0645#$0020#$0627#$0644#$0644#$0647));
PDF.EndDoc;
典型工作流程(拉丁標準連字 + 天城文重排)
PDF.RegisterUnicodeTTF('NotoSans', 'NotoSans-Regular.ttf');
PDF.RegisterUnicodeTTF('NotoDeva', 'NotoSansDevanagari-Regular.ttf');
PDF.ShapingFeatures :=
[sfStandardLigatures, // FB00-FB06 Latin liga
sfContextualLigatures, // + clig
sfIndicShaping]; // Devanagari Repha + I-matra reorder
Phase 8 路線圖收束
Phase 8a(v2.119.59)opt-in framework 與 Arabic capability;Phase 8b(v2.119.65)拉丁標準連字;Phase 8c.1(v2.119.60)Allah;Phase 8c.2(v2.119.63)GID 層的 GSUB rlig;Phase 8c.3(v2.119.61)ToUnicode 反查對應;Phase 8c.4(v2.119.62)Bismillah;Phase 8c.5(v2.119.64)advance 查詢與 heuristic 修正;Phase 8c.6(v2.119.68)PUA synthetic codepoint 輸出;Phase 8d 已併入 8c 各子階段;Phase 8e(v2.119.67)Devanagari 自動重排。v2.119.68 之後 Phase 8 的能力矩陣已全部到位;後續加強項目(其他 Indic scripts、OpenType GPOS 定位、BiDi 解析)另立 roadmap 項目追蹤
範圍與限制
此 opt-in pipeline 有意建立在 static post-pass shaper 之上;既有呼叫端除非 opt in,否則看不到行為變更。預設 [] 集合是 byte-stable 回歸的安全選擇。沒有要求 GSUB feature tables 的字型會產生安全的 no-op 輸出(呼叫端看到沒有 substitution 套用,也不會丟出例外)
目前 shaping API 對照
目前 pipeline 已不再只是 substitution-only:sfKerning 套用 GPOS pair kerning,sfMarkPositioning 套用 Mark-to-Base 與 Mark-to-Mark offsets,sfMarkToLigature 套用 Mark-to-Ligature placement,sfCursiveAttachment 套用 cursive entry/exit anchor 對齊,sfTibetanShaping 套用 Tibetan GSUB shaping,sfMongolianShaping 套用 Mongolian positional forms,sfIndicGSUB 在 syllable reorder 後套用 Indic GSUB feature chain。請參閱 ShapingFeatures、GPOS methods 與 Indic shaping methods
近期新增項目包括用於 locl 的 sfLocalizedForms、透過 ApplyGSUBContextualFeature 支援 calt、contextual 與 vertical GPOS kerning、native Arabic GSUB contextual glyph emission,以及 N'Ko、Adlam、Thai/Lao、Hebrew 與 Javanese paths。請參閱 script shaping preprocess methods
請參閱: OpenType GSUB Substitution Engine, Arabic / Persian / Urdu Shaping Support, Syriac / Mongolian / Devanagari Shaping, THotPDF.AssignSyntheticCodepointForGID, CFF / OpenType Font Subsetting
|