Skip to content

Justified paragraphs with CJK-only lines are not stretched — trailing gap at line end (spaceCount=0) #3901

Description

@superfm831010

Description

In justified paragraphs (w:jc="both"), lines that contain no space characters —
which is the normal case for Chinese/Japanese text, since CJK prose has no
inter-word spaces — are never stretched. Lines that don't naturally fill the
available width show a visible gap (up to ~1 char width) at the right edge,
so the paragraph doesn't look justified in the editor.

The saved DOCX is correct (w:jc="both" is preserved); Word and other DOCX
editors render the same file flush on both edges by distributing the extra
width between characters. This is a preview/rendering limitation only.

Steps to reproduce

  1. Open a DOCX containing a paragraph of pure Chinese text with alignment set to justify (w:jc="both").
  2. Observe non-last lines in the editor.

Expected: all non-last lines are flush with the right margin (as in Word).
Actual: lines whose natural width is less than the available width keep a trailing gap.

(Happy to attach a minimal repro DOCX and editor-vs-Word screenshots on request.)

Root cause (from reading the layout-engine contracts)

layout-engine/contracts/src/justify-utils distributes justify space only
across SPACE_CHARS (space / nbsp), implemented via CSS word-spacing:
calculateJustifySpacing returns 0 when spaceCount === 0. CJK-only lines
therefore never stretch. Word's behavior is to fall back to inter-character
distribution when a line has no (or too few) spaces.

I understand measure and paint must stay in sync (the module warns about
caret drift), so this likely needs inter-character spacing support in both
paths (e.g. CSS letter-spacing applied uniformly per line, excluding the
last character), not a paint-only hack.

Environment

  • superdoc 2.4.0 (also reproduced on earlier 2.x)
  • Chromium-based browsers (multiple versions)

Related

Possibly related to #3884 (CJK line breaking / compression), but this report
is specifically about justify stretch distribution, not break opportunities.
We'd also be happy to test a patch or contribute if maintainers can point at
the preferred extension point.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions