Automatic Shaping Pipeline (Phase 8)

Opt-in producer-side GSUB pipeline (v2.119.59 - v2.120.10)

 

Arabic Shaping  Multi-Script Shaping  GSUB Engine

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 entriesShapingFeatures: THPDFShapingFeatures) and HotPDF takes care of running the right substitutions, marking substitute glyphs into the embedded font subset, and emitting the ToUnicode CMap reverse-mapping entries needed for accessibility.

property ShapingFeatures: THPDFShapingFeatures read ... write ...;

 

預設值為 [](empty set),會為依賴 v2.119.32-58 static post-pass shaper 的呼叫端保留 byte-identical output。設定一個或多個 flags 會將 engine 提升為對應 features 的 automatic mode

 

sfArabicGSUB - native Arabic GSUB shaping (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

 

Canonical users of rclt: Arabic init / medi / fina / isol when the font drives positional shaping through GSUB instead of through Unicode Presentation Forms codepoints; certain Latin sequence disambiguation rules; Indic shaping

 

sfArabicGSUB - native Arabic GSUB shaping (v2.185.0)

When sfArabicGSUB is set, HotPDF maps a logical Arabic run to base glyph IDs, applies the registered font's positional init, medi, fina, and isol lookups at the joining positions selected for each letter, then applies rlig, calt, and rclt over the shaped run. Substitute glyphs that have no Unicode codepoint are emitted through the synthetic-codepoint path with ToUnicode reverse mappings, so fonts whose contextual Arabic glyphs live outside the cmap can still be embedded and copied correctly

 

Setting sfArabicGSUB implicitly bypasses the v2.85.0 static 4-position shaper for Arabic - callers who need the static shaper to keep handling codepoints outside what the font's GSUB declares should leave sfArabicGSUB off.

 

sfStandardLigatures / sfContextualLigatures - Phase 8b (v2.119.65)

When sfStandardLigatures is set, Latin Standard Ligatures are folded automatically using the font's liga feature. ApplyLatinLigatureRefinement targets the Alphabetic Presentation Forms block (U+FB00-FB4F) - typically FB00 ff, FB01 fi, FB02 fl, FB03 ffi, FB04 ffl, FB05 long-s + t, FB06 st. sfContextualLigatures adds a second pass for the font's clig feature. Both passes use the same reverse-cmap mechanism as sfArabicGSUB and emit 7 new ToUnicode CMap reverse-mapping entries (FB00-FB06) so consumer-reader copy / paste resolves the ligature back to the source letters.

 

sfContextualAlternates - GSUB 'rclt' (v2.119.66)

When sfContextualAlternates is set, the font's rclt (Required Contextual Alternates) feature is applied. ApplyArabicGSUBContextualRefinement uses the v2.119.47 ApplyContextualSubst entry point and handles variable-length N-to-M output (substitution is only committed when every replacement GID is reachable through the reverse cmap). Reverse cmap range is extended to FB00-FDFF + FE70-FEFF to cover Latin + Arabic + Hebrew Presentation Forms.

 

Canonical users of rclt: Arabic init / medi / fina / isol when the font drives positional shaping through GSUB instead of through Unicode Presentation Forms codepoints; certain Latin sequence disambiguation rules; Indic shaping pres / blws / psts / half / pstf / cjct features when registered as rclt by the font designer.

 

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)仍留給字型的 GSUBsfIndicShaping is set, the v2.119.55 Devanagari capability ApplyDevanagariReorder is promoted from a manual method to an automatic pre-pass applied inside the three BuildUnicode*FieldContent helpers. Devanagari runs get Repha (Ra + Halant at cluster start) moved to the post-base position, and pre-base I-matra (U+093F) moved before the cluster base consonant, so the consumer reader's GSUB engine picks up the syllable in the correct rendering order. Other Indic reorders (above-base / below-base matra, conjunct formation) remain in the font's GSUB.

 

Advance-query support (v2.119.64 / Phase 8c.5)

A companion API exposes the cached /W em-fraction so callers can compute word-wrap correctly when emitting GSUB-substituted glyphs:

 

Advance-query support (v2.119.64 / Phase 8c.5)

配套 API 會公開快取的 /W em-fraction,讓呼叫端在輸出 GSUB-substituted glyphs 時能正確計算 word-wrap:

 CP. The same release also fixed CodeUnitAdvance to classify Arabic Presentation Forms (U+FB50-FDFF + U+FE70-FEFF) as NARROW instead of WIDE (the heuristic fallback was wrong before v2.65).

 

Typical workflow (full Arabic auto-shaping)

 

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;

 

Typical workflow (Latin standard ligatures + Devanagari reorder)

 

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 roadmap closure

Phase 8a (v2.119.59) opt-in framework + Arabic capability; Phase 8b (v2.119.65) Latin standard ligatures; Phase 8c.1 (v2.119.60) Allah; Phase 8c.2 (v2.119.63) GID-level GSUB rlig; Phase 8c.3 (v2.119.61) ToUnicode reverse mapping; Phase 8c.4 (v2.119.62) Bismillah; Phase 8c.5 (v2.119.64) advance query + heuristic fix; Phase 8c.6 (v2.119.68) PUA synthetic codepoint emit; Phase 8d was rolled into 8c sub-phases; Phase 8e (v2.119.67) Devanagari auto-reorder. With v2.119.68 the Phase 8 capability matrix is closed; further refinements (additional Indic scripts, OpenType GPOS positioning, BiDi resolution) are tracked under separate roadmap items.

 

Scope and limitations

此 opt-in pipeline 有意建立在 static post-pass shaper 之上;既有呼叫端除非 opt in,否則看不到行為變更。預設 [] set 是 byte-stable regression 的安全選擇。沒有要求 GSUB feature tables 的字型會產生安全 no-op output(呼叫端看到沒有 substitution 套用,也不會丟出例外)[] set is the safe choice for byte-stable regression. Fonts without the requested GSUB feature tables produce safe no-op output (callers see no substitution applied, no exceptions raised).

 

目前 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 alignment,sfTibetanShaping 套用 Tibetan GSUB shaping,sfMongolianShaping 套用 Mongolian positional forms,sfIndicGSUB 在 syllable reorder 後套用 Indic GSUB feature chain。請參閱 ShapingFeatures、GPOS methods 與 Indic shaping methodssfKerning applies GPOS pair kerning, sfMarkPositioning applies Mark-to-Base and Mark-to-Mark offsets, sfMarkToLigature applies Mark-to-Ligature placement, sfCursiveAttachment applies cursive entry/exit anchor alignment, sfTibetanShaping applies Tibetan GSUB shaping, sfMongolianShaping applies Mongolian positional forms, and sfIndicGSUB applies the Indic GSUB feature chain after syllable reorder. See ShapingFeatures, GPOS methods, and 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 methodssfLocalizedForms for locl, calt through ApplyGSUBContextualFeature, contextual and vertical GPOS kerning, native Arabic GSUB contextual glyph emission, and the N'Ko, Adlam, Thai/Lao, Hebrew, and Javanese paths. See script shaping preprocess methods

 

請參閱: OpenType GSUB Substitution Engine, Arabic / Persian / Urdu Shaping Support, Syriac / Mongolian / Devanagari Shaping, THotPDF.AssignSyntheticCodepointForGID, CFF / OpenType Font Subsetting