[Libreoffice-commits] core.git: sw/qa sw/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Mon Nov 12 19:03:07 UTC 2018
sw/qa/extras/odfimport/data/tdf120677.fodt | 13 +++++++++++++
sw/qa/extras/odfimport/odfimport.cxx | 5 +++++
sw/source/core/text/guess.cxx | 20 ++++++++++++--------
3 files changed, 30 insertions(+), 8 deletions(-)
New commits:
commit 4bb28ad217ea9d6511b6921dcd3d28328edcb4d6
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Mon Nov 12 15:07:58 2018 +0300
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Mon Nov 12 20:02:46 2018 +0100
tdf#120677: restore treatment of blanks in SwTextGuess::Guess
Before commit 0be3db28a4db4d2c81a5cb2edd48711eec55b51b, all non-breakable
spaces were converted to plain spaces in SwTextSlot::SwTextSlot (see
pInf->SetText call there). The mentioned commit has changed that to allow
differentiating non-breakable spaces from other types of spaces (related
to the fix of tdf#115067). This broke following processing of the NBSPs
when they don't fit to line, causing infinite layout loop leading to OOM.
This allows to restore old behavior to not call the break iterator for
NBSP by explicitly checking for it.
Change-Id: I36ab06abb66bbe65a5fc542c41e816a9f20a2dcf
Reviewed-on: https://gerrit.libreoffice.org/63290
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
diff --git a/sw/qa/extras/odfimport/data/tdf120677.fodt b/sw/qa/extras/odfimport/data/tdf120677.fodt
new file mode 100644
index 000000000000..b2006828fb10
--- /dev/null
+++ b/sw/qa/extras/odfimport/data/tdf120677.fodt
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:body>
+ <office:text>
+ <text:p><draw:frame draw:name="Frame1" text:anchor-type="char" svg:width="0cm" svg:height="2cm">
+ <draw:text-box>
+ <text:p>. </text:p><!-- The "space" here is non-breaking space -->
+ </draw:text-box>
+ </draw:frame></text:p>
+ </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/odfimport/odfimport.cxx b/sw/qa/extras/odfimport/odfimport.cxx
index bd31b56d3e76..160f72028f51 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -910,5 +910,10 @@ DECLARE_ODFIMPORT_TEST(testTdf116195, "tdf116195.odt")
);
}
+DECLARE_ODFIMPORT_TEST(testTdf120677, "tdf120677.fodt")
+{
+ // The document used to hang the layout, consuming memory until OOM
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/guess.cxx b/sw/source/core/text/guess.cxx
index 96f82ae8dd5e..f24fdef51094 100644
--- a/sw/source/core/text/guess.cxx
+++ b/sw/source/core/text/guess.cxx
@@ -40,7 +40,14 @@ using namespace ::com::sun::star::i18n;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::linguistic2;
-#define CH_FULL_BLANK 0x3000
+namespace{
+
+const sal_Unicode CH_FULL_BLANK = 0x3000;
+const sal_Unicode CH_NB_SPACE = 0xA0;
+
+bool IsBlank(sal_Unicode ch) { return ch == CH_BLANK || ch == CH_FULL_BLANK || ch == CH_NB_SPACE; }
+
+}
// provides information for line break calculation
// returns true if no line break has to be performed
@@ -243,7 +250,7 @@ bool SwTextGuess::Guess( const SwTextPortion& rPor, SwTextFormatInfo &rInf,
sal_Unicode cCutChar = nCutPos < TextFrameIndex(rInf.GetText().getLength())
? rInf.GetText()[sal_Int32(nCutPos)]
: 0;
- if( CH_BLANK == cCutChar || CH_FULL_BLANK == cCutChar )
+ if (IsBlank(cCutChar))
{
nBreakPos = nCutPos;
TextFrameIndex nX = nBreakPos;
@@ -253,23 +260,20 @@ bool SwTextGuess::Guess( const SwTextPortion& rPor, SwTextFormatInfo &rInf,
// we step back until a non blank character has been found
// or there is only one more character left
while (nX && TextFrameIndex(rInf.GetText().getLength()) < nBreakPos &&
- ( CH_BLANK == ( cCutChar = rInf.GetChar( --nX ) ) ||
- CH_FULL_BLANK == cCutChar ) )
+ IsBlank(rInf.GetChar(--nX)))
--nBreakPos;
}
else // #i20878#
{
while (nX && nBreakPos > rInf.GetLineStart() + TextFrameIndex(1) &&
- ( CH_BLANK == ( cCutChar = rInf.GetChar( --nX ) ) ||
- CH_FULL_BLANK == cCutChar ) )
+ IsBlank(rInf.GetChar(--nX)))
--nBreakPos;
}
if( nBreakPos > rInf.GetIdx() )
nPorLen = nBreakPos - rInf.GetIdx();
while (++nCutPos < TextFrameIndex(rInf.GetText().getLength()) &&
- ( CH_BLANK == ( cCutChar = rInf.GetChar( nCutPos ) ) ||
- CH_FULL_BLANK == cCutChar ) )
+ IsBlank(rInf.GetChar(nCutPos)))
; // nothing
nBreakStart = nCutPos;
More information about the Libreoffice-commits
mailing list