Skip to content

fix: stop fake spaces from shredding letter-spaced PDF text - #222

Merged
Vantalens merged 2 commits into
mainfrom
fix/pdf-fake-spaces
Sep 24, 2026
Merged

Vantalens merged 2 commits into
mainfrom
fix/pdf-fake-spaces

Conversation

@Vantalens

Copy link
Copy Markdown
Owner

变更说明

PDF 提取的多余空格有两个来源,本 PR 一并修复:

  1. item 拼接层阈值过低:shouldSeparatePdfItems 原阈值 Math.max(1.5, height * 0.12)(0.12em),把加字距(letter-spacing)排版的字形间隙误判为词间空格,产生 "E x p a n d e d" 式碎词。
  2. pdf.js 内部 addFakeSpaces:对 0.102em–0.6em 的字间位移插入 ASCII 伪空格并混在 item.str 里,CJK 加字距文本被碎成「加 字 距 版」。

变更内容

  • public/formats/pdf.js
    • shouldSeparatePdfItems 词间空格阈值从 0.12em 提到 height * 0.22(近似真实空格宽度 0.25em),加字距字形间隙不再被当成词间空格。
    • 新增导出函数 collapseCjkFakeSpaces:连续 ≥3 个单字 CJK 以单空格相连的链收拢去空格("加 字 距 版" → "加字距版");两个多字 CJK 词之间的空格保留(表单对齐间距)。
    • extractTextWithPdfJs 的 item 映射(str:)与 textRuns 映射(text:)均经过 collapseCjkFakeSpaces。
  • scripts/layout-offset-regression-test.js
    • 新增回归断言:加字距字形链(0.18em 间隙)不拆词("Expanded")、collapseCjkFakeSpaces("加 字 距 版") === "加字距版"、("逐词 绘制") 保留、("Normal spacing line") 不变。
  • CHANGELOG.md、docs/development/DEVELOPMENT_TASKS.md:补充修复条目与验收记录。

测试验证

  • 本地完整 npm test(50 个脚本)在含 pdfjs-dist 环境下全量通过(退出码 0)。
  • 双向环境验证:隐藏 node_modules/pdfjs-dist 后 npm test 同样全量通过(退出码 0),缺 pdfjs 相关用例优雅降级 / 跳过而非失败,验证后目录已恢复。
  • 空格压测样例(validate-spacing-pdf.mjs)5 项全部通过 + 1 项已知限制标注。
  • 中英混排全链路样例(validate-mixed-pdf.mjs)20/20 无回归。

相关 Issue

Refs #216

注意事项

  • 已知上游限制:拉丁字母加字距碎词("E x p a n d e d")的词边界在 pdf.js 合并 item 时已丢失,无法可靠还原,保留原样;代码注释中已注明这是 pdf.js addFakeSpaces 的上游启发式限制。
  • 工作区另有用户未提交的 package-lock.json 改动,属于并行工作,未包含在本 PR 中。

…view gradient buttons

Landing:
- bump hero eyebrow v2.3 -> v2.4 to match package version
- tighten hero vertical rhythm; split subtitle into nowrap phrases to
  drop the single-character orphan line
- gate .reveal-on-scroll behind a .reveal-armed class so content stays
  visible when JS/observer/print contexts never trigger intersection
- hover feedback for feature cards, format rows, workflow steps; CTA
  section gets a brand gradient bar

Workbench (styles.css only):
- dashed centered empty states, tab active indicator, focus-visible rings
- gradient progress bar with tabular-nums percentage
- stronger pane elevation, press feedback on ghost/mini/menu buttons

Preview (preview.css):
- explicit brand-gradient primary button rules for dark topbar context
  (fixes unified-button-test baseline failure: token now used 3x)

Chore: add npm run dev script alongside existing start script

Tests: design-token, ui-accessibility, ui-button-consistency (12/12),
unified-button, smoke (60 groups), browser-smoke, ui-conversion-e2e,
server-hardening all pass.
- item 拼接层空格阈值从 0.12em 提到 0.22em(近似真实空格宽度 0.25em),加字距
  排版字形间隙不再被当成词间空格("E x p a n d e d" 式碎词)
- pdf.js addFakeSpaces 伪空格的收拢:连续 ≥3 个单字 CJK 链去空格("加 字 距 版"
  →"加字距版"),多字词间对齐空格保留;拉丁碎词词边界在 pdf.js 合并 item 时已
  丢失,保留原样并注明上游限制
- 回归断言:加字距字形链不拆词、CJK 伪空格收拢、多字词空格保留

Refs #216
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@Vantalens
Vantalens merged commit dd6f2d5 into main Sep 24, 2026
8 checks passed
@Vantalens
Vantalens deleted the fix/pdf-fake-spaces branch September 24, 2026 07:35
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.

1 participant