diff options
author | Julien Nabet <serval2412@yahoo.fr> | 2017-11-08 23:17:56 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2017-11-24 19:39:46 +0100 |
commit | 479719b1f53cb5f44bbcc57e75dad1aae604cd20 (patch) | |
tree | 377f4ac309ea88c541fa16fb2dd06658e7c474fb | |
parent | 13511a077bb85a68a3d29d081d0f88090028185f (diff) |
tdf#113657: fix crash when trying to format empty paragraph
by creating a function to clean line feeds and returns if it's empty or not
Reviewed-on: https://gerrit.libreoffice.org/44513
Tested-by: Jenkins <ci@libreoffice.org>
Tested-by: Xisco FaulĂ <xiscofauli@libreoffice.org>
Reviewed-by: Michael Stahl <mstahl@redhat.com>
(cherry picked from commit 3f289fef2f2b00dcca4948dd9fb2ba2c493fac6f)
svx: loplugin:staticmethods
(cherry picked from commit 16687c57b5e378db93972fc1887b9b19747d068c)
Change-Id: I3a744c52bdb457c92f38595463099e1cbf17a37e
Reviewed-on: https://gerrit.libreoffice.org/45151
Reviewed-by: Michael Stahl <mstahl@redhat.com>
Tested-by: Jenkins <ci@libreoffice.org>
-rw-r--r-- | svx/source/dialog/fntctrl.cxx | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/svx/source/dialog/fntctrl.cxx b/svx/source/dialog/fntctrl.cxx index 213126c069c1..f139cb7f631f 100644 --- a/svx/source/dialog/fntctrl.cxx +++ b/svx/source/dialog/fntctrl.cxx @@ -611,6 +611,24 @@ void SvxFontPrevWindow::UseResourceText() pImpl->mbUseResText = true; } +/* + * removes line feeds and carriage returns from string + * returns if param is empty + */ +bool CleanAndCheckEmpty(OUString& rText) +{ + bool bEmpty = true; + for (sal_Int32 i = 0; i < rText.getLength(); ++i) + { + if (0xa == rText[i] || 0xd == rText[i]) + rText = rText.replaceAt(i, 1, " "); + else + bEmpty = false; + } + return bEmpty; +} + + void SvxFontPrevWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) { ApplySettings(rRenderContext); @@ -644,7 +662,7 @@ void SvxFontPrevWindow::Paint(vcl::RenderContext& rRenderContext, const tools::R { pImpl->maText = pSh->GetSelectionText(); pImpl->mbGetSelection = true; - pImpl->mbSelection = !pImpl->maText.isEmpty(); + pImpl->mbSelection = !CleanAndCheckEmpty(pImpl->maText); } if (!pImpl->mbSelection || pImpl->mbUseFontNameAsText) @@ -680,16 +698,8 @@ void SvxFontPrevWindow::Paint(vcl::RenderContext& rRenderContext, const tools::R pImpl->maText = makeRepresentativeTextForFont(LATIN, rFont); } - // remove line feeds and carriage returns from string - bool bNotEmpty = false; - for (sal_Int32 i = 0; i < pImpl->maText.getLength(); ++i) - { - if (0xa == pImpl->maText[i] || 0xd == pImpl->maText[i]) - pImpl->maText = pImpl->maText.replaceAt(i, 1, " "); - else - bNotEmpty = true; - } - if (!bNotEmpty) + bool bEmpty = CleanAndCheckEmpty(pImpl->maText); + if (bEmpty) pImpl->maText = GetText(); if (pImpl->maText.getLength() > (TEXT_WIDTH - 1)) |