This commit is contained in:
Agel committed 2026-11-01 12:19:45 +01:00
1 parent 1ad2f5446b
commit cdd33bc60e
1 file changed
+12 -7
+12 -7
View File
@@ -497,10 +497,10 @@ private slots:
void overstretchedJustifiedLineFallsBackToNaturalSpacing() void overstretchedJustifiedLineFallsBackToNaturalSpacing()
{ {
// When a line in a justified paragraph has an extreme ratio (> 2.0), // When a line in a justified paragraph has an extreme ratio (> 2.0),
// e.g. because the next word is slightly too wide to fit on the line, // e.g. because the next word is too wide to fit on the line,
// it must not stretch spaces across the line to fill the container. // it must not stretch spaces across the line to fill the container.
// E.g.: "WordA WordB" (fits in ~120px) followed by "MediumLengthWord" (fits on next line in 200px width). // We choose words that each individually fit in availWidth (250px) to avoid
// 120px in 200px line width: shortfall = 80px, glue stretch = ~2-3px -> ratio = 80/2 = 40.0 >> 2.0! // emergency letter-splitting, but whose sum exceeds 250px.
BlockItem p; BlockItem p;
p.kind = BlockItem::Kind::Paragraph; p.kind = BlockItem::Kind::Paragraph;
p.align = TextAlign::Justify; p.align = TextAlign::Justify;
@@ -508,7 +508,11 @@ private slots:
InlineItem t1; InlineItem t1;
t1.kind = InlineItem::Kind::Text; t1.kind = InlineItem::Kind::Text;
t1.text = QStringLiteral("WordA WordB MediumLengthWordThatCannotFitOnLineOne"); // "Alpha Beta Gamma" (~120px) followed by "Characterization" (~120px).
// Total width ~240px > 200px, so it must break onto 2 lines.
// Each word is well under 200px, so no emergency letter-split occurs.
// Line 0 has "Alpha Beta Gamma" with shortfall ~80px in 200px width (ratio ~20.0 >> 2.0).
t1.text = QStringLiteral("Alpha Beta Gamma Characterization");
p.inlines.append(t1); p.inlines.append(t1);
LayoutParams params; LayoutParams params;
@@ -519,11 +523,12 @@ private slots:
auto layout = ChunkLayoutEngine::layoutBlocks({p}, params); auto layout = ChunkLayoutEngine::layoutBlocks({p}, params);
QVERIFY(layout.lines.size() >= 2); QVERIFY(layout.lines.size() >= 2);
// First line has "WordA WordB". Since ratio > 2.0, it should NOT be stretched to fill 200px. // First line has "Alpha Beta Gamma" (natural width ~120-135px).
// If it were stretched to fill 200px, its right would be 200.0.
// Because line.ratio > 2.0, it falls back to natural spacing (right < 165.0).
const auto &line0 = layout.lines[0]; const auto &line0 = layout.lines[0];
QVERIFY(!line0.runs.isEmpty()); QVERIFY(!line0.runs.isEmpty());
// Natural width of "WordA WordB" is ~120px; stretched to 200px it would be 200px. QVERIFY(line0.runs.last().rect.right() < 165.0);
QVERIFY(line0.runs.last().rect.right() < 160.0);
} }
}; };