tdf#150394 sw: fix crash of "Don't hyphenate last word"
Multiline last words, e.g. long URLs resulted crashing
using the new hyphenation option "Don't hyphenate last word".
Follow-up to commit 8c018910ae4d8701b1ce2a95727b9baed4016da3
"tdf#149248 sw offapi xmloff: add option to not hyphenate last word".
Note: .fodt format is not applicable for unit testing.
Change-Id: I8633af1517f09003b40a06825ad14f3ed7f882a5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138296
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
diff --git a/sw/qa/extras/odfexport/data/tdf150394.odt b/sw/qa/extras/odfexport/data/tdf150394.odt
new file mode 100644
index 0000000..e514f40
--- /dev/null
+++ b/sw/qa/extras/odfexport/data/tdf150394.odt
Binary files differ
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index ad65d88..1ff5f45 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -3057,6 +3057,12 @@ DECLARE_ODFEXPORT_TEST(tdf149248, "tdf149248.odt")
CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(getParagraph(4), "ParaHyphenationNoLastWord"));
}
DECLARE_ODFEXPORT_TEST(testTdf150394, "tdf150394.odt")
{
// crashes at import time
CPPUNIT_ASSERT_EQUAL(1, getPages());
}
DECLARE_ODFEXPORT_TEST(tdf149324, "tdf149324.odt")
{
CPPUNIT_ASSERT_EQUAL(1, getPages());
diff --git a/sw/source/core/text/guess.cxx b/sw/source/core/text/guess.cxx
index 34681c1..23b7319 100644
--- a/sw/source/core/text/guess.cxx
+++ b/sw/source/core/text/guess.cxx
@@ -257,7 +257,12 @@ bool SwTextGuess::Guess( const SwTextPortion& rPor, SwTextFormatInfo &rInf,
// don't hyphenate the last word of the paragraph
if ( bHyphenationNoLastWord && sal_Int32(m_nCutPos) > nLastWord &&
TextFrameIndex(COMPLETE_STRING) != m_nCutPos )
TextFrameIndex(COMPLETE_STRING) != m_nCutPos &&
// if the last word is multiple line long, e.g. an URL,
// apply this only if the space before the word is there
// in the actual line, i.e. start the long word in a new
// line, but still allows to break its last parts
sal_Int32(rInf.GetIdx()) < nLastWord )
{
m_nCutPos = TextFrameIndex(nLastWord);
}