[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3-desktop' - editeng/qa editeng/source include/editeng
Tamás Zolnai
tamas.zolnai at collabora.com
Wed Feb 21 12:31:59 UTC 2018
editeng/qa/unit/core-test.cxx | 33 +++++++++++++++++++++++++++++++++
editeng/source/editeng/editeng.cxx | 4 ++--
editeng/source/editeng/impedit.hxx | 2 +-
editeng/source/editeng/impedit2.cxx | 4 ++--
editeng/source/editeng/impedit3.cxx | 4 ++--
include/editeng/editeng.hxx | 2 +-
6 files changed, 41 insertions(+), 8 deletions(-)
New commits:
commit 24c28ff3989d97e9023416408303dc1ff4580184
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
Date: Tue Feb 20 00:30:27 2018 +0100
tdf#115639: Handle alignment correctly for multiple paragraph case
I used the wrong calculator method to get the line width.
This commit also fixes the crashes found by crashtest.
Reviewed-on: https://gerrit.libreoffice.org/49994
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>
(cherry picked from commit f0485ba2d90aae0312f5775588f22789016165d2)
Change-Id: I25392f86af912ee54c07b14480d82282210ac346
Reviewed-on: https://gerrit.libreoffice.org/50100
Reviewed-by: Andras Timar <andras.timar at collabora.com>
Tested-by: Andras Timar <andras.timar at collabora.com>
diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx
index b6da4d4a1a8d..892293f43117 100644
--- a/editeng/qa/unit/core-test.cxx
+++ b/editeng/qa/unit/core-test.cxx
@@ -740,6 +740,39 @@ void Test::testHoriAlignIgnoreTrailingWhitespace()
EditLine* pLine = &pParaPortion->GetLines()[0];
CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<long>(8815), pLine->GetStartPosX(), 10);
}
+
+ // Test multiple paragraph case
+ {
+ // Set initial text
+ aText = "Some text \nMore Text ";
+ aTextLen = aText.getLength();
+ aEditEngine.SetText(aText);
+
+ // Assert changes - text insertion
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(aTextLen - 1), rDoc.GetTextLen());
+ CPPUNIT_ASSERT_EQUAL(OUString("Some text "), rDoc.GetParaAsString(static_cast<sal_Int32>(0)));
+ CPPUNIT_ASSERT_EQUAL(OUString("More Text "), rDoc.GetParaAsString(static_cast<sal_Int32>(1)));
+
+ aEditEngine.SetHoriAlignIgnoreTrailingWhitespace(true);
+ std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(aEditEngine.GetEmptyItemSet()));
+ pSet->Put(SvxAdjustItem( SVX_ADJUST_CENTER, EE_PARA_JUST ));
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), pSet->Count());
+
+ // Select all paragraphs and apply changes
+ ESelection aSelection(0, 0, 0, aTextLen);
+ aEditEngine.QuickSetAttribs(*pSet, aSelection);
+
+ // Get one line paragraphs
+ aEditEngine.SetPaperSize(Size(10000, 6000));
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aEditEngine.GetLineCount(0));
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aEditEngine.GetLineCount(1));
+
+ // Check horizontal position
+ ParaPortion* pParaPortion = aEditEngine.GetParaPortions()[0];
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<long>(4527), pParaPortion->GetLines()[0].GetStartPosX(), 50);
+ pParaPortion = aEditEngine.GetParaPortions()[1];
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<long>(8815), pParaPortion->GetLines()[0].GetStartPosX(), 50);
+ }
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx
index 0232b81e84aa..9086b18835cd 100644
--- a/editeng/source/editeng/editeng.cxx
+++ b/editeng/source/editeng/editeng.cxx
@@ -1433,13 +1433,13 @@ sal_uInt32 EditEngine::GetTextHeightNTP() const
return pImpEditEngine->GetTextHeightNTP();
}
-sal_uInt32 EditEngine::CalcTextWidth(bool bIgnoreTrailingWhiteSpaces)
+sal_uInt32 EditEngine::CalcTextWidth()
{
if ( !pImpEditEngine->IsFormatted() )
pImpEditEngine->FormatDoc();
- sal_uInt32 nWidth = !IsVertical() ? pImpEditEngine->CalcTextWidth( true, bIgnoreTrailingWhiteSpaces ) : pImpEditEngine->GetTextHeight();
+ sal_uInt32 nWidth = !IsVertical() ? pImpEditEngine->CalcTextWidth( true ) : pImpEditEngine->GetTextHeight();
return nWidth;
}
diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx
index f83cf46803dc..40f5d2514209 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -817,7 +817,7 @@ public:
sal_uInt32 CalcTextHeight( sal_uInt32* pHeightNTP );
sal_uInt32 GetTextHeight() const;
sal_uInt32 GetTextHeightNTP() const;
- sal_uInt32 CalcTextWidth( bool bIgnoreExtraSpace, bool bIgnoreTrailingWhiteSpaces = false );
+ sal_uInt32 CalcTextWidth( bool bIgnoreExtraSpace );
sal_uInt32 CalcLineWidth( ParaPortion* pPortion, EditLine* pLine, bool bIgnoreExtraSpace, bool bIgnoreTrailingWhiteSpaces = false );
sal_Int32 GetLineCount( sal_Int32 nParagraph ) const;
sal_Int32 GetLineLen( sal_Int32 nParagraph, sal_Int32 nLine ) const;
diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx
index 39da4832c5e8..e2230527a51e 100644
--- a/editeng/source/editeng/impedit2.cxx
+++ b/editeng/source/editeng/impedit2.cxx
@@ -3039,7 +3039,7 @@ sal_uInt32 ImpEditEngine::GetTextHeight() const
return nCurTextHeight;
}
-sal_uInt32 ImpEditEngine::CalcTextWidth( bool bIgnoreExtraSpace, bool bIgnoreTrailingWhiteSpaces )
+sal_uInt32 ImpEditEngine::CalcTextWidth( bool bIgnoreExtraSpace )
{
// If still not formatted and not in the process.
// Will be brought in the formatting for AutoPageSize.
@@ -3086,7 +3086,7 @@ sal_uInt32 ImpEditEngine::CalcTextWidth( bool bIgnoreExtraSpace, bool bIgnoreTra
}
}
nCurWidth += GetXValue( rLRItem.GetRight() );
- nCurWidth += CalcLineWidth( pPortion, &rLine, bIgnoreExtraSpace, bIgnoreTrailingWhiteSpaces );
+ nCurWidth += CalcLineWidth( pPortion, &rLine, bIgnoreExtraSpace );
if ( nCurWidth > nMaxWidth )
{
nMaxWidth = nCurWidth;
diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx
index 9366ffe6caeb..75e400ae98da 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -1471,7 +1471,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
{
long n;
if(IsHoriAlignIgnoreTrailingWhitespace())
- n = ( nMaxLineWidth - CalcTextWidth( true, true ) ) / 2;
+ n = ( nMaxLineWidth - CalcLineWidth( pParaPortion, pLine, false, true ) ) / 2;
else
n = ( nMaxLineWidth - aTextSize.Width() ) / 2;
n += nStartX; // Indentation is kept.
@@ -1484,7 +1484,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
// the blank must not be displayed!
long n;
if(IsHoriAlignIgnoreTrailingWhitespace())
- n = nMaxLineWidth - CalcTextWidth( true, true );
+ n = nMaxLineWidth - CalcLineWidth( pParaPortion, pLine, false, true );
else
n = nMaxLineWidth - aTextSize.Width();
n += nStartX; // Indentation is kept.
diff --git a/include/editeng/editeng.hxx b/include/editeng/editeng.hxx
index b30d689c25c0..f452d8590a1a 100644
--- a/include/editeng/editeng.hxx
+++ b/include/editeng/editeng.hxx
@@ -274,7 +274,7 @@ public:
sal_uInt32 GetTextLen() const;
sal_uInt32 GetTextHeight() const;
sal_uInt32 GetTextHeightNTP() const;
- sal_uInt32 CalcTextWidth( bool bIgnoreTrailingWhiteSpaces = false );
+ sal_uInt32 CalcTextWidth();
OUString GetText( sal_Int32 nParagraph ) const;
sal_Int32 GetTextLen( sal_Int32 nParagraph ) const;
More information about the Libreoffice-commits
mailing list