tdf#170811: SwBlankPortion as part of field expansion must use SwTextSlot
Since commit e3c068cb19 (tdf#167946:
reimplement the fix for tdf#120677, 2026-02-07), SwBlankPortion stopped
using SwExpandPortion::Format, and therefore, SwTextSlot (that replaced
the text in SwTextFormatInfo). That was the intended change, because
replacing the text destroyed the context for formatting, and that was
the root of the problem.
However, SwBlankPortion may appear as part of a field expansion. Then
its length is zero (see SwTextFormatter::NewPortion, which sets length
to zero in that case). To avoid wrong formatting (where zero length
automatically means in SwTextGuess::Guess, that line break goes here),
which would change portion lingth to 1 (see SwTextPortion::BreakCut),
which would then try to access missing string indexes ... - to avoid
all that, restore use of SwTextSlot optionally for the "length is 0"
case.
A follow-up needs to improve the use of SwTextSlot here, to use the
actual, full expansion of the field text - which would allow to format
the NBSP in context of the surrounding text, and to fix tdf#56085.
Change-Id: I86497ed3099eec585f4454e1db19e070ce1b17d6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199458
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199498
This commit is contained in:
committed by
Xisco Fauli
parent
1624917392
commit
66879873c9
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" office:version="1.4" office:mimetype="application/vnd.oasis.opendocument.text">
|
||||
<office:meta><meta:user-defined meta:name="NBSP">word nobreakspace word space word nobreakspace word</meta:user-defined></office:meta>
|
||||
<office:font-face-decls>
|
||||
<style:font-face style:name="Liberation Serif" svg:font-family="'Liberation Serif'" style:font-family-generic="roman" style:font-pitch="variable"/>
|
||||
</office:font-face-decls>
|
||||
<office:styles>
|
||||
<style:default-style style:family="paragraph">
|
||||
<style:text-properties style:font-name="Liberation Serif" fo:font-size="12pt" fo:language="en" fo:country="US"/>
|
||||
</style:default-style>
|
||||
<style:style style:name="Standard" style:family="paragraph" style:class="text"/>
|
||||
</office:styles>
|
||||
<office:automatic-styles>
|
||||
<style:style style:name="P1" style:family="paragraph" style:parent-style-name="Standard">
|
||||
<style:paragraph-properties fo:margin-left="0" fo:margin-right="10cm"/>
|
||||
</style:style>
|
||||
<style:page-layout style:name="pm1">
|
||||
<style:page-layout-properties fo:page-width="210mm" fo:page-height="297mm" style:print-orientation="portrait" fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm" style:writing-mode="lr-tb"/>
|
||||
</style:page-layout>
|
||||
</office:automatic-styles>
|
||||
<office:master-styles>
|
||||
<style:master-page style:name="Standard" style:page-layout-name="pm1"/>
|
||||
</office:master-styles>
|
||||
<office:body>
|
||||
<office:text>
|
||||
<text:p text:style-name="P1"><text:user-defined text:name="NBSP"/></text:p>
|
||||
</office:text>
|
||||
</office:body>
|
||||
</office:document>
|
||||
@@ -2196,6 +2196,14 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter6, testTdf169607)
|
||||
assertXPath(pXmlDoc, "//page", 3);
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(SwLayoutWriter6, testTdf170811)
|
||||
{
|
||||
// This used to fail assertion
|
||||
createSwDoc("tdf170811.fodt");
|
||||
// This must succeed
|
||||
parseLayoutDump();
|
||||
}
|
||||
|
||||
} // end of anonymous namespace
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
||||
@@ -195,6 +195,15 @@ void SwBlankPortion::FormatEOL( SwTextFormatInfo &rInf )
|
||||
*/
|
||||
bool SwBlankPortion::Format( SwTextFormatInfo &rInf )
|
||||
{
|
||||
std::optional<SwTextSlot> oTextSlot;
|
||||
if (!GetLen())
|
||||
{
|
||||
// This is a hook char of a field portion. Use expansion.
|
||||
// FIXME: tdf#56085 the slot must use parent field portion text, to correctly format
|
||||
// in the context of surrounding text
|
||||
oTextSlot.emplace(&rInf, this, true, false);
|
||||
}
|
||||
|
||||
const bool bFull = rInf.IsUnderflow() || SwTextPortion::Format(rInf);
|
||||
if( bFull && MayUnderflow( rInf, rInf.GetIdx(), rInf.IsUnderflow() ) )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user