Repository navigation
fix(pdfium): resolve installed CJK fonts referenced by PostScript name - #425
deepin-bot[bot] merged 1 commit into
Conversation
Register each enumerated font in m_FontList before notifying the mapper so that GetFont() succeeds during enumeration and PostScript names get read. 字体枚举时先注册进 m_FontList 再通知 mapper,保证枚举期间 GetFont() 成功, 使已安装字体的 PostScript 名可被读取索引。 Index the PostScript name of every installed font whose PS name differs from its family name, not only localized names, so /BaseFont entries like "FZXBSJW--GB1-0" can resolve to the installed font family. 为所有 PS 名与族名不同的已安装字体建立 PostScript 名索引(不再仅限本地化名), 使 /BaseFont 条目(如 "FZXBSJW--GB1-0")能解析到已安装字族。 Prefer an exact family-name match in MapFont for CJK charsets over the hardcoded fallback lists, which previously ignored the requested family. MapFont 对 CJK 字符集优先按请求族名精确匹配,而非直接落入硬编码回退列表。 Log: 修复PDF按PostScript字体名无法匹配已安装中文字体的问题 PMS: BUG-380413 Influence: PDF中引用已安装中文字体的PostScript名(如方正小标宋)时能正确 匹配对应字体,不再被无关替代字体替换,中文显示恢复正确。
Reviewer's GuideFixes installed CJK font resolution when PDFs reference fonts by PostScript name by making fonts available during enumeration, indexing differing PostScript names for all installed fonts, and honoring exact family-name matches before CJK fallback substitution. Sequence diagram for installed CJK PostScript font indexingsequenceDiagram
participant Enumerator as CFX_FolderFontInfo
participant Mapper as CFX_FontMapper
participant FontInfo as FontInfo
participant FontFile as InstalledFont
Enumerator->>FontInfo: m_FontList[facename] = FontFaceInfo
Enumerator->>Mapper: AddInstalledFont(facename, charset)
Mapper->>FontInfo: GetFont(name.c_str())
FontInfo-->>Mapper: Font handle
Mapper->>FontFile: GetPSNameFromTT(hFont)
FontFile-->>Mapper: ps_name
Mapper->>Mapper: m_LocalizedTTFonts.push_back(ps_name, name)
Mapper->>FontInfo: DeleteFont(hFont)
Flow diagram for CJK font matching by family or PostScript nameflowchart TD
A[PDF requests a CJK font] --> B{PostScript name indexed?}
B -->|Yes| C[Resolve to installed family]
B -->|No| D{Exact family in m_FontList?}
D -->|Yes| C
D -->|No| E[Use charset fallback list]
C --> F[Render with requested installed font]
E --> G[Render with fallback font]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp" line_range="122-123" />
<code_context>
+ // 该名字往往不在下方任何旧回退列表中;若不先做精确匹配,下方列表
+ // 会无条件替换为列表中第一个找到的字体,完全忽略请求的族名。
+ auto exact_it = m_FontList.find(family);
+ if (exact_it != m_FontList.end())
+ return exact_it->second.get();
for (const char* name : g_LinuxGbFontList) {
auto it = m_FontList.find(name);
</code_context>
<issue_to_address>
**CJK text loses glyphs**
When a requested CJK family is installed but its face lacks the requested charset, `MapFont()` returns `exact_it` without checking charset support, bypassing the CJK fallback list and rendering the text with a face that lacks the required glyphs.
Return the exact match only when it supports the requested charset; otherwise continue to the CJK fallback list.
Also at `3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp:133-135`, `3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp:145-147`.
</issue_to_address>
### Comment 2
<location path="3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp" line_range="121-122" />
<code_context>
+ // 某个已安装 CJK 字体的族名引用它(例如 "FZXiaoBiaoSong-B05S"),
+ // 该名字往往不在下方任何旧回退列表中;若不先做精确匹配,下方列表
+ // 会无条件替换为列表中第一个找到的字体,完全忽略请求的族名。
+ auto exact_it = m_FontList.find(family);
+ if (exact_it != m_FontList.end())
+ return exact_it->second.get();
for (const char* name : g_LinuxGbFontList) {
</code_context>
<issue_to_address>
**Installed Japanese font is ignored**
When a PDF requests ShiftJIS text in an installed Japanese family that is absent from the hardcoded Japanese fallback lists, `MapFont()` searches `g_LinuxJpFontList` without checking `m_FontList` for the requested family, so it selects a generic fallback instead of the installed font.
Check `m_FontList` for the requested family before searching the Japanese fallback lists.
</issue_to_address>
### Comment 3
<location path="3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp" line_range="121-123" />
<code_context>
+ // 某个已安装 CJK 字体的族名引用它(例如 "FZXiaoBiaoSong-B05S"),
+ // 该名字往往不在下方任何旧回退列表中;若不先做精确匹配,下方列表
+ // 会无条件替换为列表中第一个找到的字体,完全忽略请求的族名。
+ auto exact_it = m_FontList.find(family);
+ if (exact_it != m_FontList.end())
+ return exact_it->second.get();
for (const char* name : g_LinuxGbFontList) {
auto it = m_FontList.find(name);
</code_context>
<issue_to_address>
**Requested font style is ignored**
When the family has an exact regular face and the request calls for a different weight or italic style, the exact-family branch returns the regular face without considering `weight` or `bItalic`, even when the requested styled face is installed.
Apply the requested weight and italic style when selecting an exact-family match.
Also at `3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp:133-135`, `3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp:145-147`.
</issue_to_address>
### Comment 4
<location path="3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/cfx_fontmapper.cpp" line_range="334-335" />
<code_context>
+ // 原先仅对本地化(含非 ASCII 字符)的族名做该索引,导致 ASCII 族名字体
+ // 的 PostScript 名请求永远无法匹配已安装字体,总会被无关的替代字体替换。
+ void* hFont = m_pFontInfo->GetFont(name.c_str());
+ if (!hFont && bLocalized) {
hFont = m_pFontInfo->MapFont(0, 0, FX_CHARSET_Default, 0, name.c_str());
- if (!hFont)
- return;
</code_context>
<issue_to_address>
**PostScript font name is not indexed**
When an external provider cannot resolve an ASCII family through `GetFont()` but can open it through `MapFont()`, `AddInstalledFont()` calls `MapFont()` only when `bLocalized` is true, so it never reads the font’s differing PostScript name and requests using that name fail to resolve to the installed family.
Try `MapFont()` when `GetFont()` returns null for an ASCII family as well.
</issue_to_address>| if (exact_it != m_FontList.end()) | ||
| return exact_it->second.get(); |
There was a problem hiding this comment.
🟠 High · CJK text loses glyphs
When a requested CJK family is installed but its face lacks the requested charset, MapFont() returns exact_it without checking charset support, bypassing the CJK fallback list and rendering the text with a face that lacks the required glyphs.
Return the exact match only when it supports the requested charset; otherwise continue to the CJK fallback list.
Also at 3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp:133-135, 3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp:145-147.
Prompt for AI agents
In `3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp` at lines 122-123:
**CJK text loses glyphs**
When a requested CJK family is installed but its face lacks the requested charset, `MapFont()` returns `exact_it` without checking charset support, bypassing the CJK fallback list and rendering the text with a face that lacks the required glyphs.
Return the exact match only when it supports the requested charset; otherwise continue to the CJK fallback list.
Also at `3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp:133-135`, `3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp:145-147`.| auto exact_it = m_FontList.find(family); | ||
| if (exact_it != m_FontList.end()) |
There was a problem hiding this comment.
🟡 Medium · Installed Japanese font is ignored
When a PDF requests ShiftJIS text in an installed Japanese family that is absent from the hardcoded Japanese fallback lists, MapFont() searches g_LinuxJpFontList without checking m_FontList for the requested family, so it selects a generic fallback instead of the installed font.
Check m_FontList for the requested family before searching the Japanese fallback lists.
Prompt for AI agents
In `3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp` at lines 121-122:
**Installed Japanese font is ignored**
When a PDF requests ShiftJIS text in an installed Japanese family that is absent from the hardcoded Japanese fallback lists, `MapFont()` searches `g_LinuxJpFontList` without checking `m_FontList` for the requested family, so it selects a generic fallback instead of the installed font.
Check `m_FontList` for the requested family before searching the Japanese fallback lists.| auto exact_it = m_FontList.find(family); | ||
| if (exact_it != m_FontList.end()) | ||
| return exact_it->second.get(); |
There was a problem hiding this comment.
🟡 Medium · Requested font style is ignored
When the family has an exact regular face and the request calls for a different weight or italic style, the exact-family branch returns the regular face without considering weight or bItalic, even when the requested styled face is installed.
Apply the requested weight and italic style when selecting an exact-family match.
Also at 3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp:133-135, 3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp:145-147.
Prompt for AI agents
In `3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp` at lines 121-123:
**Requested font style is ignored**
When the family has an exact regular face and the request calls for a different weight or italic style, the exact-family branch returns the regular face without considering `weight` or `bItalic`, even when the requested styled face is installed.
Apply the requested weight and italic style when selecting an exact-family match.
Also at `3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp:133-135`, `3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/fx_ge_linux.cpp:145-147`.| if (!hFont && bLocalized) { | ||
| hFont = m_pFontInfo->MapFont(0, 0, FX_CHARSET_Default, 0, name.c_str()); |
There was a problem hiding this comment.
🟡 Medium · PostScript font name is not indexed
When an external provider cannot resolve an ASCII family through GetFont() but can open it through MapFont(), AddInstalledFont() calls MapFont() only when bLocalized is true, so it never reads the font’s differing PostScript name and requests using that name fail to resolve to the installed family.
Try MapFont() when GetFont() returns null for an ASCII family as well.
Prompt for AI agents
In `3rdparty/deepin-pdfium/src/3rdparty/pdfium/pdfium/core/fxge/cfx_fontmapper.cpp` at lines 334-335:
**PostScript font name is not indexed**
When an external provider cannot resolve an ASCII family through `GetFont()` but can open it through `MapFont()`, `AddInstalledFont()` calls `MapFont()` only when `bLocalized` is true, so it never reads the font’s differing PostScript name and requests using that name fail to resolve to the installed family.
Try `MapFont()` when `GetFont()` returns null for an ASCII family as well.
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: ['无'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['可考虑将 fx_ge_linux.cpp 中重复的精确匹配逻辑提取为辅助函数或宏,减少未来维护时的修改遗漏风险'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['无'] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: ['无'] 💡 改进建议代码示例// fx_ge_linux.cpp: 可将重复的精确匹配提取为辅助方法,减少重复
// 例如在 CFX_LinuxFontInfo 类中添加:
// void* FindExactFont(const ByteString& family) {
// auto it = m_FontList.find(family);
// return it != m_FontList.end() ? it->second.get() : nullptr;
// }
// 然后在各 case 中:
// case FX_CHARSET_ChineseSimplified: {
// if (void* p = FindExactFont(family))
// return p;
// for (const char* name : g_LinuxGbFontList) { ... }
// break;
// }本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: GongHeng2017, max-lvs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
Register each enumerated font in m_FontList before notifying the mapper so that GetFont() succeeds during enumeration and PostScript names get read.
字体枚举时先注册进 m_FontList 再通知 mapper,保证枚举期间 GetFont() 成功, 使已安装字体的 PostScript 名可被读取索引。
Index the PostScript name of every installed font whose PS name differs from its family name, not only localized names, so /BaseFont entries like "FZXBSJW--GB1-0" can resolve to the installed font family.
为所有 PS 名与族名不同的已安装字体建立 PostScript 名索引(不再仅限本地化名),
使 /BaseFont 条目(如 "FZXBSJW--GB1-0")能解析到已安装字族。
Prefer an exact family-name match in MapFont for CJK charsets over the hardcoded fallback lists, which previously ignored the requested family.
MapFont 对 CJK 字符集优先按请求族名精确匹配,而非直接落入硬编码回退列表。
Log: 修复PDF按PostScript字体名无法匹配已安装中文字体的问题
PMS: BUG-380413
Influence: PDF中引用已安装中文字体的PostScript名(如方正小标宋)时能正确
匹配对应字体,不再被无关替代字体替换,中文显示恢复正确。
Summary by Sourcery
Fix installed-font enumeration and matching so PDF PostScript and family font references resolve correctly for CJK text.
Bug Fixes:
Enhancements: