fix: keep composite glyph CIDs aligned with subset GIDs / 修复复合字形子集中的 CID/GID 错位 - #74
Open
activeliang wants to merge 1 commit into
Open
fix: keep composite glyph CIDs aligned with subset GIDs / 修复复合字形子集中的 CID/GID 错位#74activeliang wants to merge 1 commit into
activeliang wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary / 概要
/CIDToGIDMap /Identitycontent CIDs aligned with the final embedded font GIDs.Problem / 问题
When a rendered glyph is composite, the TTF subsetter also inserts its component
glyphs into the embedded font. However,
prepare_subset_maps()previously builtthe old-to-new GID map from directly shaped glyphs only.
当渲染的字形是复合字形时,TTF 子集器还会将其组件字形插入嵌入字体。
但此前
prepare_subset_maps()只根据直接参与排版的字形构建新旧 GID 映射。Because the generated PDF uses
/CIDToGIDMap /Identity, the inserted componentglyphs shifted the final subset GIDs while the content stream continued using
the old mapping. The PDF therefore displayed incorrect glyph outlines even
though its ToUnicode mapping and copied text were correct.
由于生成的 PDF 使用
/CIDToGIDMap /Identity,组件字形的插入会改变后续字形在最终子集中的 GID,但内容流仍使用旧映射。因此 PDF 显示了错误的字形轮廓,
而 ToUnicode 映射和复制出来的文本仍然正确。
One downstream reproduction extracted
ˈsɪtɪŋcorrectly but visually renderedit as
ʌsɛtɛð.一个实际案例中,复制或提取出的文本是正确的
ˈsɪtɪŋ,但 PDF 中显示成了错误的
ʌsɛtɛð。Solution / 解决方案
Expose the subsetter's transitive composite-glyph closure and use that exact
ordered glyph list when preparing the PDF CID map. The CID map and final subset
font now assign identical GIDs, including all component-glyph slots.
复用子集器计算出的复合字形传递闭包,并使用完全相同的有序字形列表生成 PDF
CID 映射。现在 CID 映射与最终字体子集会为所有字形分配相同的 GID,其中也
包括复合字形所依赖的组件字形。
Testing / 测试
cargo test- 5 tests passed / 5 个测试全部通过node scripts/verify.mjs- all verification groups passed / 全部验证通过npm pack --dry-runNotes / 说明