Skip to content

DOCX: consecutive Courier New paragraphs advance 28% tighter than Word #452

Description

@developer0hye

Summary

Consecutive single-line DOCX paragraphs set in Courier New render 2.86 pt tighter per line than Word, about a 28% shortfall. The gap accumulates down the page: by the last body line of the technical manual, office2pdf is 15.5 pt above Word.

Both PDFs embed the same CourierNewPSMT, so this is line-box modeling, not font substitution.

Reproduction

target/release/office2pdf \
  tests/golden_mocks/business/sources/docx/05_technical_manual_en.docx -o /tmp/05.pdf
pdftotext -f 1 -l 1 -bbox tests/golden_mocks/business/expected/docx/05_technical_manual_en.pdf -
pdftotext -f 1 -l 1 -bbox /tmp/05.pdf -

Each shaded code line is its own paragraph:

<w:p>
  <w:pPr>
    <w:shd w:fill="F4F4F4" w:val="clear"/>
    <w:spacing w:after="0"/>
    <w:ind w:left="240"/>
  </w:pPr>
  <w:r>
    <w:rPr><w:rFonts w:ascii="Courier New" .../><w:sz w:val="18"/></w:rPr>
    <w:t xml:space="preserve">$ cargo install office2pdf-cli</w:t>
  </w:r>
</w:p>

Measurements

Consecutive code paragraphs, 9 pt Courier New, w:spacing w:after="0", page 1:

Step Word GT pitch office2pdf pitch
line 1 to 2 10.08 pt 7.22 pt
line 2 to 3 10.32 pt 7.21 pt

Word's pitch matches Courier New's 1.133 em line height at 9 pt (10.2 pt). office2pdf uses 0.80 em.

Accumulated yMin drift down page 1, measured after the first-paragraph fix in #420 landed:

Line Word GT office2pdf Delta
1. Installation 77.07 pt 76.35 pt -0.72 pt
2. Basic Usage 161.55 pt 147.04 pt -14.51 pt
3. Troubleshooting 276.27 pt 271.03 pt -5.24 pt
for more width. 384.28 pt 368.82 pt -15.46 pt

Expected

A paragraph with no explicit w:spacing w:line advances by the run font's line height, as Word does.

Actual

The advance is roughly 0.80 em regardless of the font's ascent and descent, so monospace-heavy documents compress.

Scope

  • crates/office2pdf/src/render/typst_gen_text.rsword_line_leading_pt and the paragraph leading it feeds.

Visual checklist

Related: #420, #404

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions