Skip to content

Java DOCX renderer: align Latin document layout with Word (14_Thesis_Chapter) #187

Description

@shps951023

Summary

This issue tracks the Java DOCX renderer session that brought 14_Thesis_Chapter to near-pixel parity with Microsoft 365 Word.

Metric Before After
14_Thesis_Chapter overall 0.9856 0.9932
14_Thesis_Chapter text similarity 0.9979 1.0
14_Thesis_Chapter visual - 0.983
Pages 2/2 2/2
Full issue/docx benchmark average 0.7225 0.7224 (28 cases)
Unit tests 20/20 78/79 (issues66 CJK smoke test now passes; 1 pre-existing Vietnamese issue91 extraction failure remains)

Session Flow

  1. Diagnose remaining image differences between minipdf, Word reference, and LibreOffice renders of 14_Thesis_Chapter p1: headings not bold, bullets missing, body lines wrapped wider than Word, table offset, and wrong page-break position.
  2. Heading bold — port Word's effective bold: paragraph-mark pPr/rPr and paragraph style rPr (CTParaRPr / CTRPr).
  3. Bullet markers — resolve numPr → abstractNum → lvl via XWPFNumbering; map Symbol PUA bullet (\uF0B7) to •.
  4. Heading color — apply paragraph-style rPr/w:color (Heading2 blue 4F81BD) when runs carry no explicit color.
  5. Width metrics — mirror DocxToPdfConverter.EstimateCalibrTextWidth/EstimateWrapTextWidth:
    • Calibri-default documents: Times table with -8.8 units/letter kerning for serif runs, Calibri ×0.977 otherwise.
    • Other defaults: wrap with actual TTF advances (PDType0Font#getStringWidth), since Word lays out with the same TTF metrics.
    • Center/right alignment positioned with actual font advances.
  6. Paragraph flow parity — contextualSpacing collapse between same-style paragraphs, keepNext widow control (reserve heading + up to 3 follow lines), top-of-page baseline = margin + font ascent, spacing-before suppressed at page top, spacing-after not collapsed across tables.
  7. Table parity — auto-width table indent -108 twips (Word default), cell vertical margin 0, table spacing tuned to Word/LibreOffice measurements.
  8. Bullet line height — Symbol-font labels advance 16.7pt (factor 1.21) matching Word and LibreOffice.

All changes are in minipdf-java/minipdf/src/main/java/io/github/minisoftware/minipdf/internal/docx/PoiDocxRenderer.java.

Validation

  • mvn -B -ntp -f minipdf-java/pom.xml test → 78/79 passing.
  • Run-Java-VisualBenchmark.ps1 -Suite issue -Format docx -SkipReference → 0.7224 average; 14_Thesis 0.9932, Issue79 0.9911/0.991, issues66 0.9879, Support_Letter 0.9761.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions