Skip to content

Commit 0fa545d

Browse files
da-liiiclaude
andauthored
[212_7] 修复导出PDF时中英文混合文件名导致的标题乱码 (#3293)
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 701d960 commit 0fa545d

3 files changed

Lines changed: 53 additions & 1 deletion

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<TMU|<tuple|1.1.0|2026.2.3>>
2+
3+
<style|<tuple|generic|chinese|table-captions-above|number-europe|preview-ref>>
4+
5+
<\body>
6+
用于测试导出PDF的标题
7+
</body>
8+
9+
<\initial>
10+
<\collection>
11+
<associate|page-medium|paper>
12+
<associate|page-screen-margin|false>
13+
</collection>
14+
</initial>

devel/212_7.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# [212_7] 修复导出 PDF 时中英文混合文件名导致的标题乱码
2+
3+
## 相关文档
4+
- [212_6](212_6.md) - 修复 PDF 导出时不可见字符导致的渲染问题
5+
- [222_66](222_66.md) - 修复超链接预览中异常显示的中文字符
6+
7+
## 任务相关的代码文件
8+
- `src/Edit/Editor/edit_main.cpp`
9+
- `TeXmacs/tests/tmu/212_7_中文_English.tmu`
10+
11+
## 如何测试
12+
1. 打开测试文件 `TeXmacs/tests/tmu/212_7_中文_English.tmu`
13+
2. 确保文档没有设置 `global-title``doc-title`
14+
3. 导出为 PDF
15+
4. 使用 PDF 阅读器查看文档属性中的标题,应正确显示为 `212_7_中文_English.tmu`
16+
17+
## 2026/05/08 修复 PDF 标题乱码
18+
19+
### What
20+
`edit_main.cpp``get_metadata` 函数中,当回退到文件名作为标题时,添加 `cork_to_utf8` 转换。
21+
22+
### Why
23+
`edit_main_rep::get_metadata` 在获取 `title` 元数据时,前两个来源(`global-title``doc-title`)都使用了 `cork_to_utf8` 转换,但第三个来源(文件名)没有:
24+
25+
```cpp
26+
if (kind == "title") return as_string (tail (get_name ()));
27+
```
28+
29+
TeXmacs 内部字符串使用 Cork 编码,文件名在某些情况下可能是 Cork 编码(如 `<#4E2D><#6587>English.tm`)。缺少 `cork_to_utf8` 转换会导致 PDF 元数据中的标题出现乱码。
30+
31+
这与 [222_66] 中修复超链接预览乱码的思路一致:在将内部字符串传递给需要 UTF-8 的外部系统(如 PDF 库或 UI)时,需要进行 `cork_to_utf8` 转换。
32+
33+
### How
34+
将上述代码改为:
35+
36+
```cpp
37+
if (kind == "title") return cork_to_utf8 (as_string (tail (get_name ())));
38+
```

src/Edit/Editor/edit_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ edit_main_rep::get_metadata (string kind) {
170170
if (val != "") return val;
171171
val= cork_to_utf8 (search_metadata (subtree (et, rp), kind));
172172
if (val != "") return val;
173-
if (kind == "title") return as_string (tail (get_name ()));
173+
if (kind == "title") return cork_to_utf8 (as_string (tail (get_name ())));
174174
return "";
175175
}
176176

0 commit comments

Comments
 (0)