Skip to content

[0111] 修复 TFM 字体 get_xpositions 字距计算错误#3334

Merged
da-liii merged 2 commits into
mainfrom
da/0111/III
May 13, 2026
Merged

[0111] 修复 TFM 字体 get_xpositions 字距计算错误#3334
da-liii merged 2 commits into
mainfrom
da/0111/III

Conversation

@da-liii

@da-liii da-liii commented May 13, 2026

Copy link
Copy Markdown
Contributor

修复内容

修复中文文档中连续多个英文字母 "I" 导致光标位置偏左的问题。

根因

ec:ecrm10@600(European Computer Modern)字体对 "I"+"I" 存在字距调整(kerning)。tex_font_metric_rep::get_xpositions 有两处错误:

  1. 检查顺序错误:先检查 skip_byte >= 128 再检查 next_char 匹配,导致 valid kerning 指令被跳过
  2. 字距归属错误ADVANCE(kern) 将字距加到了当前字符的结束位置,导致 xpos[l]get_extents(prefix(0,l)) 不一致

修改

  • src/Plugins/Metafont/load_tfm.cpp:修正检查顺序,将字距从当前字符的 xpos 中分离
  • tests/Graphics/Fonts/smart_font_test.cpp:新增 test_cursor_position_iii 测试
  • 清理注释掉的调试输出

测试

xmake build smart_font_test
TEXMACS_PATH=... TEXMACS_HOME_PATH=... ./build/linux/x86_64/release/smart_font_test

结果:9 passed, 0 failed。

🤖 Generated with Claude Code

da-liii and others added 2 commits May 13, 2026 11:50
修复中文文档中连续多个 "I" 字符导致光标位置偏左的问题。

具体修复:
1. load_tfm.cpp: 修正 lig/kern 程序中 skip_byte 与 next_char 的检查顺序,
   确保与 execute 函数一致
2. load_tfm.cpp: 修正 kerning 分支中 xpos 的存储逻辑,将字距从当前字符
   的结束位置中分离,使 xpos[l] 与 get_extents(prefix(0,l)) 保持一致
3. smart_font_test.cpp: 新增 test_cursor_position_iii 单元测试
4. 清理注释掉的调试输出

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@da-liii da-liii merged commit 0b4be59 into main May 13, 2026
5 checks passed
@da-liii da-liii deleted the da/0111/III branch May 13, 2026 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants