File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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>
Original file line number Diff line number Diff line change 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+ ```
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments