summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2018-03-09 14:48:49 +0100
committerJan Holesovsky <kendy@collabora.com>2018-05-22 12:03:48 +0200
commitf2d6178d3a0f6106e0798659df51a34b60ec9d70 (patch)
treee6937194070e78fad5583e2912422e845a426e41
parent0e38433b0c69a393ab7c9a41044c80d112765bab (diff)
tdf#116101 Correct bullet position for linespacing > 100%
Change-Id: Ia900636d4013ab2a9c893c8246391db867fe1543 Reviewed-on: https://gerrit.libreoffice.org/51017 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/51167 Reviewed-by: Andras Timar <andras.timar@collabora.com> Tested-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r--editeng/qa/unit/core-test.cxx94
-rw-r--r--editeng/source/editeng/impedit3.cxx13
2 files changed, 100 insertions, 7 deletions
diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx
index 892293f43117..01d51eb271d3 100644
--- a/editeng/qa/unit/core-test.cxx
+++ b/editeng/qa/unit/core-test.cxx
@@ -19,6 +19,9 @@
#include "editeng/eeitem.hxx"
#include "editeng/editids.hrc"
#include "editeng/editdoc.hxx"
+#include "editeng/fontitem.hxx"
+#include "editeng/fhgtitem.hxx"
+#include "editeng/lspcitem.hxx"
#include "editeng/svxacorr.hxx"
#include "editeng/unofield.hxx"
#include "editeng/wghtitem.hxx"
@@ -45,6 +48,9 @@ public:
virtual void setUp() override;
virtual void tearDown() override;
+ /// Test text portions position when percentage line spacing is set
+ void testLineSpacing();
+
void testConstruction();
/// Test UNO service class that implements text field items.
@@ -63,6 +69,7 @@ public:
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testConstruction);
+ CPPUNIT_TEST(testLineSpacing);
CPPUNIT_TEST(testUnoTextFields);
CPPUNIT_TEST(testAutocorrect);
CPPUNIT_TEST(testHyperlinkSearch);
@@ -110,6 +117,93 @@ bool includes(const uno::Sequence<OUString>& rSeq, const OUString& rVal)
}
+void Test::testLineSpacing()
+{
+ // Create EditEngine's instance
+ EditEngine aEditEngine(mpItemPool);
+
+ if(aEditEngine.GetRefDevice()->GetDPIY() != 96
+ || !basegfx::fTools::equal(aEditEngine.GetRefDevice()->GetDPIScaleFactor(), 1.0))
+ return;
+
+ // Get EditDoc for current EditEngine's instance
+ EditDoc &rDoc = aEditEngine.GetEditDoc();
+
+ // Initially no text should be there
+ CPPUNIT_ASSERT_EQUAL(sal_uLong(0), rDoc.GetTextLen());
+ CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0)));
+
+ // Set initial text
+ OUString aText = "This is multi-line paragraph";
+
+ sal_Int32 aTextLen = aText.getLength();
+ aEditEngine.SetText(aText);
+
+ // Assert changes - text insertion
+ CPPUNIT_ASSERT_EQUAL(sal_uLong(aTextLen), rDoc.GetTextLen());
+ CPPUNIT_ASSERT_EQUAL(aText, rDoc.GetParaAsString(sal_Int32(0)));
+
+ // Get ItemSet for line spacing - 60%
+ std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(aEditEngine.GetEmptyItemSet()));
+ SvxLineSpacingItem aLineSpacing(LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL);
+ aLineSpacing.SetPropLineSpace(60);
+ pSet->Put(aLineSpacing);
+
+ // Set font
+ SvxFontItem aFont(EE_CHAR_FONTINFO);
+ aFont.SetFamilyName("Liberation Sans");
+ pSet->Put(aFont);
+ SvxFontHeightItem aFontSize(240, 100, EE_CHAR_FONTHEIGHT);
+ pSet->Put(aFontSize);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(3), pSet->Count());
+
+ // Select all paragraphs and set spacing
+ ESelection aSelection(0, 0, 0, aTextLen);
+ aEditEngine.QuickSetAttribs(*pSet, aSelection);
+
+ // Force multiple lines
+ aEditEngine.SetPaperSize(Size(1000, 6000));
+ CPPUNIT_ASSERT_EQUAL((sal_Int32)4, aEditEngine.GetLineCount(0));
+
+ // Assert changes
+ ParaPortion* pParaPortion = aEditEngine.GetParaPortions()[0];
+ ContentNode* const pNode = pParaPortion->GetNode();
+ const SfxPoolItem& rLSItem = pNode->GetContentAttribs().GetItem(EE_PARA_SBL);
+ const SvxLineSpacingItem* pLSItem = static_cast<const SvxLineSpacingItem*>(&rLSItem);
+ CPPUNIT_ASSERT(SvxInterLineSpaceRule::Prop == pLSItem->GetInterLineSpaceRule());
+ CPPUNIT_ASSERT_EQUAL((sal_uInt16)60, pLSItem->GetPropLineSpace());
+
+ // Check the first line
+ ParagraphInfos aInfo = aEditEngine.GetParagraphInfos(0);
+ CPPUNIT_ASSERT_EQUAL((sal_uInt16)122, aInfo.nFirstLineMaxAscent);
+ CPPUNIT_ASSERT_EQUAL((sal_uInt16)153, (sal_uInt16)aEditEngine.GetLineHeight(0));
+
+ // Prepare second case - 150%
+ std::unique_ptr<SfxItemSet> pSet2(new SfxItemSet(aEditEngine.GetEmptyItemSet()));
+ SvxLineSpacingItem aLineSpacing2(LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL);
+ aLineSpacing2.SetPropLineSpace(150);
+ pSet2->Put(aLineSpacing2);
+ pSet2->Put(aFont);
+ pSet2->Put(aFontSize);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(3), pSet2->Count());
+
+ // Select all paragraphs and set spacing
+ aEditEngine.QuickSetAttribs(*pSet2, aSelection);
+
+ // Assert changes
+ const SfxPoolItem& rLSItem2 = pNode->GetContentAttribs().GetItem(EE_PARA_SBL);
+ const SvxLineSpacingItem* pLSItem2 = static_cast<const SvxLineSpacingItem*>(&rLSItem2);
+ CPPUNIT_ASSERT(SvxInterLineSpaceRule::Prop == pLSItem2->GetInterLineSpaceRule());
+ CPPUNIT_ASSERT_EQUAL((sal_uInt16)150, pLSItem2->GetPropLineSpace());
+
+ // Check the first line
+ ParagraphInfos aInfo2 = aEditEngine.GetParagraphInfos(0);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(311), aInfo2.nFirstLineMaxAscent);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(382), static_cast<sal_uInt16>(aEditEngine.GetLineHeight(0)));
+}
+
void Test::testUnoTextFields()
{
{
diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx
index e021aac81082..01050ab5d3c8 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -1416,15 +1416,14 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
else if ( rLSItem.GetPropLineSpace() && ( rLSItem.GetPropLineSpace() != 100 ) )
{
sal_uInt16 nTxtHeight = pLine->GetHeight();
- sal_Int32 nH = nTxtHeight;
- nH *= rLSItem.GetPropLineSpace();
- nH /= 100;
+ sal_Int32 nTxtHeightProp = nTxtHeight * rLSItem.GetPropLineSpace() / 100;
+ sal_Int32 nHeightProp = pLine->GetHeight() * rLSItem.GetPropLineSpace() / 100;
// The Ascent has to be adjusted for the difference:
- long nDiff = pLine->GetHeight() - nH;
+ long nDiff = ( pLine->GetHeight() - nTxtHeightProp ) * 4 / 5;
if ( nDiff > pLine->GetMaxAscent() )
- nDiff = pLine->GetMaxAscent();
- pLine->SetMaxAscent( (sal_uInt16)( pLine->GetMaxAscent() - nDiff ) * 4 / 5 ); // 80%
- pLine->SetHeight( (sal_uInt16)nH, nTxtHeight );
+ nDiff = pLine->GetMaxAscent() * 4 / 5;
+ pLine->SetMaxAscent( static_cast<sal_uInt16>( pLine->GetMaxAscent() - nDiff ) ); // 80%
+ pLine->SetHeight( static_cast<sal_uInt16>( nHeightProp ), nTxtHeightProp );
}
}
}