summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-01-19 11:11:43 +0100
committerCaolán McNamara <caolanm@redhat.com>2017-01-19 15:59:38 +0000
commitbb895db932ac8ed5b8c2d221ac7268b2d787194d (patch)
treee72e9cb86ad8b3df5ee91b0ba241ca1d445603df
parent573f8134af891beef3fdb1bd3181fbde1314bd9f (diff)
tdf#105417 sw hyphenation: avoid infinite loop on zero-length last line
This hang happened when the user executed Tools -> Language -> Hyphenation -> Hyphenate All. This problem is visible only if all of these conditions are met: - a line in a paragraph has a word that already contains a soft-hyphen, but not at the position where the automatic hyphenation would insert it - the last line ends with a word that can be hyphenated - there is a fly frame in the document In this case it happens during hyphenation that the layout has an additional empty line at the end (which is removed by the time the layout finishes), so we hit the case when SwTextFormatter::Hyphenate() skips the "if( m_pCurr->PrtWidth() && m_pCurr->GetLen() )" block. Normally hyphenation terminates when it iterates over the portions of the line and no overrun nor any existing hyphen portion are seen, but in this case that never happened. Fix the problem by terminating not only when we reach the end of the portion iteration, but also when the portion list is non-existing (has zero length). (cherry picked from commit 1b6fa616087e7415be9dc7113bbd8bf381aadd70) Conflicts: sw/qa/extras/uiwriter/uiwriter.cxx Change-Id: I71d4b040a2d4692ae6eb92807dbbbb42b077a0f8 Reviewed-on: https://gerrit.libreoffice.org/33307 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sw/qa/extras/uiwriter/data/tdf105417.odtbin0 -> 9238 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx27
-rw-r--r--sw/source/core/text/txthyph.cxx5
-rw-r--r--sw/source/uibase/inc/hyp.hxx3
-rw-r--r--sw/source/uibase/lingu/hyp.cxx2
5 files changed, 35 insertions, 2 deletions
diff --git a/sw/qa/extras/uiwriter/data/tdf105417.odt b/sw/qa/extras/uiwriter/data/tdf105417.odt
new file mode 100644
index 000000000000..d594d2a5aed5
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/tdf105417.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 50266fee803c..0ba241259e31 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -88,6 +88,7 @@
#include <paratr.hxx>
#include <drawfont.hxx>
#include <txtfrm.hxx>
+#include <hyp.hxx>
#include <editeng/svxenum.hxx>
#include <comphelper/propertysequence.hxx>
#include <sfx2/classificationhelper.hxx>
@@ -96,6 +97,7 @@
#include <sfx2/dispatch.hxx>
#include <comphelper/propertyvalue.hxx>
#include <comphelper/configurationhelper.hxx>
+#include <editeng/unolingu.hxx>
#include <config_features.h>
static const char* DATA_DIRECTORY = "/sw/qa/extras/uiwriter/data/";
@@ -217,6 +219,7 @@ public:
void testTdf95699();
void testTdf104425();
void testTdf104814();
+ void testTdf105417();
CPPUNIT_TEST_SUITE(SwUiWriterTest);
CPPUNIT_TEST(testReplaceForward);
@@ -330,6 +333,7 @@ public:
CPPUNIT_TEST(testTdf95699);
CPPUNIT_TEST(testTdf104425);
CPPUNIT_TEST(testTdf104814);
+ CPPUNIT_TEST(testTdf105417);
CPPUNIT_TEST_SUITE_END();
private:
@@ -4098,6 +4102,29 @@ void SwUiWriterTest::testTdf104814()
pEditShell->AcceptRedline(0);
}
+void SwUiWriterTest::testTdf105417()
+{
+ SwDoc* pDoc = createDoc("tdf105417.odt");
+ CPPUNIT_ASSERT(pDoc);
+ SwView* pView = pDoc->GetDocShell()->GetView();
+ CPPUNIT_ASSERT(pView);
+ uno::Reference<linguistic2::XHyphenator> xHyphenator = LinguMgr::GetHyphenator();
+ CPPUNIT_ASSERT(xHyphenator.is());
+ // If there are no English hyphenation rules installed, we can't test
+ // hyphenation.
+ if (!xHyphenator->hasLocale(lang::Locale("en", "US", OUString())))
+ return;
+
+ uno::Reference<linguistic2::XLinguProperties> xLinguProperties(LinguMgr::GetLinguPropertySet());
+ // Automatic hyphenation means not opening a dialog, but going ahead
+ // non-interactively.
+ xLinguProperties->setIsHyphAuto(true);
+ SwHyphWrapper aWrap(pView, xHyphenator, /*bStart=*/false, /*bOther=*/true, /*bSelection=*/false);
+ // This never returned, it kept trying to hyphenate the last word
+ // (greenbacks) again and again.
+ aWrap.SpellDocument();
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/text/txthyph.cxx b/sw/source/core/text/txthyph.cxx
index 369a22ae3b03..6b5bd8470648 100644
--- a/sw/source/core/text/txthyph.cxx
+++ b/sw/source/core/text/txthyph.cxx
@@ -197,6 +197,11 @@ bool SwTextFormatter::Hyphenate( SwInterHyphInfo &rHyphInf )
if( !pPos )
nWrdStart = 0;
}
+ else
+ // In case the whole line is zero-length, that's the same situation as
+ // above when the portion iteration ends without explicitly breaking
+ // from the loop.
+ nWrdStart = 0;
// Das alte LineLayout wird wieder eingestellt ...
delete m_pCurr;
diff --git a/sw/source/uibase/inc/hyp.hxx b/sw/source/uibase/inc/hyp.hxx
index 24942e31c680..e12638fa6575 100644
--- a/sw/source/uibase/inc/hyp.hxx
+++ b/sw/source/uibase/inc/hyp.hxx
@@ -23,10 +23,11 @@
#include <tools/link.hxx>
#include <editeng/splwrap.hxx>
#include <com/sun/star/linguistic2/XHyphenator.hpp>
+#include <swdllapi.h>
class SwView;
-class SwHyphWrapper : public SvxSpellWrapper {
+class SW_DLLPUBLIC SwHyphWrapper : public SvxSpellWrapper {
private:
SwView* pView;
sal_uInt16 nPageCount; // page count for progress view
diff --git a/sw/source/uibase/lingu/hyp.cxx b/sw/source/uibase/lingu/hyp.cxx
index 756c5c975613..e8396528ffc3 100644
--- a/sw/source/uibase/lingu/hyp.cxx
+++ b/sw/source/uibase/lingu/hyp.cxx
@@ -119,7 +119,7 @@ SwHyphWrapper::~SwHyphWrapper()
{
if( nPageCount )
::EndProgress( pView->GetDocShell() );
- if( bInfoBox )
+ if( bInfoBox && !Application::IsHeadlessModeEnabled() )
ScopedVclPtrInstance<InfoBox>(&pView->GetEditWin(), SW_RESSTR(STR_HYP_OK))->Execute();
}