tdf#126154 sw word spacing: fix greedy shrinking regression

Fix failing unit test file:///home/sberg/lo/core//sw/qa/extras/layout/data//tdf126154_minimum_shrinking.fodt:
/home/sberg/lo/core/test/source/xmltesttools.cxx:169:(anonymous namespace)::testTdf126154_minimum_shrinking::TestBody
equality assertion failed
- Expected: ,, , , , , , , , Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vesti bulum
- Actual  : ,, , , , , , , , Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vesti bulum c
- In <>, attribute 'portion' of '/root/page[1]/body/txt[18]/SwParaPortion/SwLineLayout[1]' incorrect value.

Regression since commit 01d1037262
"tdf#126154 tdf#149420 tdf#165984 sw: fix hyphenation
zones with portions".

Notes: Instead of the desired word spacing, an extra shrinking
was applied, when minimum and maximum word spacing is specified,
despite that there was no hyphenation with the desired
word spacing.

The first Guess() call is for the original line breaking
with 100% word spacing (specified in the font, no shrinking
or expanding yet), detecting also the possible space count
in the line. The second Guess() call is for both the custom
desired and maximum word spacing. The third Guess() call is
for the minimum word spacing. No need for the third call, if

1) The desired word spacing is 100% (as in the first Guess() call, and

2) There was no hyphenation in the first Guess() call (minimum
word spacing is used only for avoid hyphenation, yet).

Change-Id: Ia2e689800f4bdf94512e8b47bc42d6e77c3723ec
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185299
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
This commit is contained in:
László Németh
2025-05-14 13:46:04 +02:00
parent 97066d4f5a
commit 41d3574263
+9 -1
View File
@@ -420,6 +420,8 @@ bool SwTextPortion::Format_( SwTextFormatInfo &rInf )
}
else
{
bool bOrigHyphenated = pGuess->HyphWord().is() &&
pGuess->BreakPos() > rInf.GetLineStart();
if ( bWordSpacing || bWordSpacingMaximum )
{
pGuess.emplace();
@@ -428,7 +430,13 @@ bool SwTextPortion::Format_( SwTextFormatInfo &rInf )
// if both maximum word spacing or minimum word spacing can disable
// hyphenation, prefer the last one
if ( bWordSpacingMinimum && ( bWordSpacingMaximum ||
( pGuess->HyphWord().is() && pGuess->BreakPos() > rInf.GetLineStart() ) ) )
( pGuess->HyphWord().is() && pGuess->BreakPos() > rInf.GetLineStart() ) ) &&
// if the desired word spacing is 100% (!bWordSpacing), and it was possible
// to break the line without hyphenation in the first run (where maximum
// word spacing was not used), no need to check minimum word spacing
// FIXME: avoid too much shrinking, if desired word spacing is not 100%
( bWordSpacing || bOrigHyphenated )
)
{
std::optional<SwTextGuess> pGuess2(std::in_place);
SwTwips nOldExtraSpace = rInf.GetExtraSpace();