summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2018-11-12 15:07:58 +0300
committerCaolán McNamara <caolanm@redhat.com>2018-11-19 16:02:28 +0100
commit7c7f46faa213d9c20bf5cebcc72b0f5dc86b0248 (patch)
tree4db4419052b8caeee9e3584ddf4913cdea8dc72f /sw
parent21467c1c0fea676a33c7b7e75648947efea18fcb (diff)
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@collabora.com> (cherry picked from commit 4bb28ad217ea9d6511b6921dcd3d28328edcb4d6) Reviewed-on: https://gerrit.libreoffice.org/63304 Tested-by: Xisco Faulí <xiscofauli@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/odfimport/data/tdf120677.fodt13
-rw-r--r--sw/qa/extras/odfimport/odfimport.cxx5
-rw-r--r--sw/source/core/text/guess.cxx20
3 files changed, 30 insertions, 8 deletions
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 3b879d9f82ff..88f3564e3be3 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 6b37ce710dc4..117656b5c69d 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;