diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-05-06 14:14:56 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-06-08 14:51:29 +0200 |
commit | d0a1616ccad0dd5f5a02c1b0204f537b57d0b4b5 (patch) | |
tree | f52e71cd8c4f6e2df6dad122d70e28a00d75e2a1 /sd | |
parent | 95ebd24a629b4c8cd62cc20c0701683512cc8fa0 (diff) |
editengine-columns: Implement layout
This changes the way how different parts access positions of lines and
paragraphs. Now there is ImpEditEngine::IterateLineAreas, which performs
uniform iteration over all ParaPortions and lines in order, calling a
user-provided callback function for each portion and line; it passes
all information about current portion, line, area, and column to the
callback, and checks the return from the callback, to decide if it needs
to continue iteration (in case when callback indicated that if doesn't
need further data), and if it needs calling the callback for the rest of
current portion's lines.
This allows to have the code that calculates and iterates dimensions of
lines in one central place, without the need to have duplicating logic
in several places.
One important exception is ImpEditEngine::Paint, which iterates without
ImpEditEngine::IterateLineAreas, because it does many atomic paint
operations in different points of iteration process, and implementing
ImpEditEngine::IterateLineAreas to call callback in the required places
would require increased complexity, which is left for a future change.
To make that possible, ImpEditEngine::IterFlag should be extended to
indicate additional requirements.
Note that in fact, ImpEditEngine::Paint was taken as the model for
implementation of ImpEditEngine::IterateLineAreas, with its detailed
handling of all the vertical offsets like additional line spacing and
interparagraph spacings that depend on context.
The notable result of the centralization of the iteration code is slight
change of heights reported by ImpEditEngine::CalcTextHeight. Previously
it simply added all pre-calculated heights of portions, and not taking
into account all the spacing handling that ImpEditEngine::Paint did,
which was inconsistent (calculated height was different from painted
height). Now ImpEditEngine::CalcTextHeight should provide more accurate
results, which required small changes in the unit tests.
Change-Id: I33cbb978deb974b314d36fda8674186a03991107
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116034
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/qa/uitest/impress_tests/tdf91762.py | 8 | ||||
-rw-r--r-- | sd/qa/unit/data/xml/n593612_0.xml | 4 | ||||
-rw-r--r-- | sd/qa/unit/data/xml/n758621_1.xml | 4 | ||||
-rw-r--r-- | sd/qa/unit/layout-tests.cxx | 107 | ||||
-rw-r--r-- | sd/qa/unit/tiledrendering/LOKitSearchTest.cxx | 4 |
5 files changed, 115 insertions, 12 deletions
diff --git a/sd/qa/uitest/impress_tests/tdf91762.py b/sd/qa/uitest/impress_tests/tdf91762.py index 92a23de6b101..8492e3425373 100644 --- a/sd/qa/uitest/impress_tests/tdf91762.py +++ b/sd/qa/uitest/impress_tests/tdf91762.py @@ -26,9 +26,9 @@ class tdf91762(UITestCase): self.ui_test.close_dialog_through_button(xOkBtn) document = self.ui_test.get_component() - self.assertEqual(1929, document.DrawPages[0].getByIndex(1).BoundRect.Height) + self.assertEqual(1931, document.DrawPages[0].getByIndex(1).BoundRect.Height) self.assertEqual(25198, document.DrawPages[0].getByIndex(1).Size.Width) - self.assertEqual(1923, document.DrawPages[0].getByIndex(1).Size.Height) + self.assertEqual(1925, document.DrawPages[0].getByIndex(1).Size.Height) self.assertEqual(1400, document.DrawPages[0].getByIndex(1).Position.X) self.assertEqual(3685, document.DrawPages[0].getByIndex(1).Position.Y) @@ -40,8 +40,8 @@ class tdf91762(UITestCase): xEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"})) # tdf#138011: Without the fix in place, this test would have failed with - # AssertionError: 5494 != 3559 - self.assertEqual(5494, document.DrawPages[0].getByIndex(1).BoundRect.Height) + # AssertionError: 5496 != 3559 + self.assertEqual(5496, document.DrawPages[0].getByIndex(1).BoundRect.Height) self.ui_test.close_doc() diff --git a/sd/qa/unit/data/xml/n593612_0.xml b/sd/qa/unit/data/xml/n593612_0.xml index 7c93f494e3ca..51fb75eba050 100644 --- a/sd/qa/unit/data/xml/n593612_0.xml +++ b/sd/qa/unit/data/xml/n593612_0.xml @@ -1,6 +1,6 @@ <?xml version="1.0"?> <XShapes> - <XShape positionX="11429" positionY="1324" sizeX="2259" sizeY="15209" type="com.sun.star.drawing.CustomShape" name="Rectangle 52" text=" " fontHeight="24.000000" fontColor="ffffffff" textAutoGrowHeight="true" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="CENTER" textVerticalAdjust="TOP" textLeftDistance="254" textRightDistance="254" textUpperDistance="127" textLowerDistance="127" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="SOLID" fillColor="3c8c93" fillTransparence="0" fillTransparenceGradientName=""> + <XShape positionX="11429" positionY="1324" sizeX="2259" sizeY="15210" type="com.sun.star.drawing.CustomShape" name="Rectangle 52" text=" " fontHeight="24.000000" fontColor="ffffffff" textAutoGrowHeight="true" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="CENTER" textVerticalAdjust="TOP" textLeftDistance="254" textRightDistance="254" textUpperDistance="127" textLowerDistance="127" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="SOLID" fillColor="3c8c93" fillTransparence="0" fillTransparenceGradientName=""> <FillTransparenceGradient style="LINEAR" startColor="000000" endColor="000000" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/> <FillGradient style="LINEAR" startColor="3465a4" endColor="ffffff" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/> <FillHatch style="SINGLE" color="3465a4" distance="20" angle="0"/> @@ -10,7 +10,7 @@ <LineEnd/> <Transformation> <Line1 column1="2260.000000" column2="0.000000" column3="11429.000000"/> - <Line2 column1="0.000000" column2="15210.000000" column3="1324.000000"/> + <Line2 column1="0.000000" column2="15211.000000" column3="1324.000000"/> <Line3 column1="0.000000" column2="0.000000" column3="1.000000"/> </Transformation> <CustomShapeGeometry> diff --git a/sd/qa/unit/data/xml/n758621_1.xml b/sd/qa/unit/data/xml/n758621_1.xml index 556c18673065..92de100a09f1 100644 --- a/sd/qa/unit/data/xml/n758621_1.xml +++ b/sd/qa/unit/data/xml/n758621_1.xml @@ -1,6 +1,6 @@ <?xml version="1.0"?> <XShapes> - <XShape positionX="1485" positionY="610" sizeX="18411" sizeY="1954" type="com.sun.star.presentation.TitleTextShape" fontHeight="40.000000" fontColor="ff0000" textAutoGrowHeight="true" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="LEFT" textVerticalAdjust="CENTER" textLeftDistance="250" textRightDistance="250" textUpperDistance="130" textLowerDistance="130" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="1645" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="NONE" fillColor="ffffff" fillTransparence="0" fillTransparenceGradientName=""> + <XShape positionX="1485" positionY="609" sizeX="18411" sizeY="1955" type="com.sun.star.presentation.TitleTextShape" fontHeight="40.000000" fontColor="ff0000" textAutoGrowHeight="true" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="LEFT" textVerticalAdjust="CENTER" textLeftDistance="250" textRightDistance="250" textUpperDistance="130" textLowerDistance="130" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="1645" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="NONE" fillColor="ffffff" fillTransparence="0" fillTransparenceGradientName=""> <FillTransparenceGradient style="LINEAR" startColor="000000" endColor="000000" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/> <FillGradient style="LINEAR" startColor="000000" endColor="ffffff" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/> <FillHatch style="SINGLE" color="3465a4" distance="20" angle="0"/> @@ -10,7 +10,7 @@ <LineEnd/> <Transformation> <Line1 column1="18412.000000" column2="0.000000" column3="1485.000000"/> - <Line2 column1="0.000000" column2="1955.000000" column3="610.000000"/> + <Line2 column1="0.000000" column2="1956.000000" column3="609.000000"/> <Line3 column1="0.000000" column2="0.000000" column3="1.000000"/> </Transformation> </XShape> diff --git a/sd/qa/unit/layout-tests.cxx b/sd/qa/unit/layout-tests.cxx index 1d10ab0a2a1e..8a2853693505 100644 --- a/sd/qa/unit/layout-tests.cxx +++ b/sd/qa/unit/layout-tests.cxx @@ -14,12 +14,14 @@ public: void testTdf104722(); void testTdf136949(); void testTdf128212(); + void testColumnsLayout(); CPPUNIT_TEST_SUITE(SdLayoutTest); CPPUNIT_TEST(testTdf104722); CPPUNIT_TEST(testTdf136949); CPPUNIT_TEST(testTdf128212); + CPPUNIT_TEST(testColumnsLayout); CPPUNIT_TEST_SUITE_END(); }; @@ -77,10 +79,111 @@ void SdLayoutTest::testTdf128212() CPPUNIT_ASSERT(pXmlDoc); // Without the fix in place, this test would have failed with - // - Expected: 7797 + // - Expected: 7798 // - Actual : 12068 assertXPath(pXmlDoc, "/metafile/push[1]/push[1]/textarray", "x", "4525"); - assertXPath(pXmlDoc, "/metafile/push[1]/push[1]/textarray", "y", "7797"); + assertXPath(pXmlDoc, "/metafile/push[1]/push[1]/textarray", "y", "7798"); + + xDocShRef->DoClose(); +} + +void SdLayoutTest::testColumnsLayout() +{ + // This tests a 2-column text box's layout + + const OUString sText[] = { + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum consequat mi quis " + "pretium semper. Proin luctus orci ac neque venenatis, quis commodo dolor posuere. " + "Curabitur dignissim sapien quis cursus egestas. Donec blandit auctor arcu, nec " + "pellentesque eros molestie eget. In consectetur aliquam hendrerit. Sed cursus mauris " + "vitae ligula pellentesque, non pellentesque urna aliquet. Fusce placerat mauris enim, " + "nec rutrum purus semper vel. Praesent tincidunt neque eu pellentesque pharetra. Fusce " + "pellentesque est orci.", + "Integer sodales tincidunt tristique. Sed a metus posuere, adipiscing nunc et, viverra " + "odio. Donec auctor molestie sem, sit amet tristique lectus hendrerit sed. Cras sodales " + "nisl sed orci mattis iaculis. Nunc eget dolor accumsan, pharetra risus a, vestibulum " + "mauris. Nunc vulputate lobortis mollis. Vivamus nec tellus faucibus, tempor magna nec, " + "facilisis felis. Donec commodo enim a vehicula pellentesque. Nullam vehicula vestibulum " + "est vel ultricies.", + "Aliquam velit massa, laoreet vel leo nec, volutpat facilisis eros. Donec consequat arcu " + "ut diam tempor luctus. Cum sociis natoque penatibus et magnis dis parturient montes, " + "nascetur ridiculus mus. Praesent vitae lacus vel leo sodales pharetra a a nibh. " + "Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; " + "Nam luctus tempus nibh, fringilla dictum augue consectetur eget. Curabitur at ante sit " + "amet tortor pharetra molestie eu nec ante. Mauris tincidunt, nibh eu sollicitudin " + "molestie, dolor sapien congue tortor, a pulvinar sapien turpis sed ante. Donec nec est " + "elementum, euismod nulla in, mollis nunc." + }; + + // sentence#, index, length, x, y + const std::tuple<int, int, int, int, int> strings[] = { + // Column 1 + { 0, 0, 40, 3750, 3193 }, + { 0, 40, 41, 3750, 3587 }, + { 0, 81, 39, 3750, 3981 }, + { 0, 120, 33, 3750, 4375 }, + { 0, 153, 35, 3750, 4769 }, + { 0, 188, 34, 3750, 5163 }, + { 0, 222, 38, 3750, 5557 }, + { 0, 260, 35, 3750, 5951 }, + { 0, 295, 37, 3750, 6345 }, + { 0, 332, 31, 3750, 6739 }, + { 0, 363, 33, 3750, 7133 }, + { 0, 396, 39, 3750, 7527 }, + { 0, 435, 37, 3750, 7921 }, + { 0, 472, 32, 3750, 8315 }, + { 0, 504, 22, 3750, 8709 }, + { 1, 0, 43, 3750, 9103 }, + { 1, 43, 35, 3750, 9497 }, + { 1, 78, 36, 3750, 9891 }, + { 1, 114, 41, 3750, 10285 }, + { 1, 155, 39, 3750, 10679 }, + { 1, 194, 35, 3750, 11073 }, + { 1, 229, 37, 3750, 11467 }, + { 1, 266, 40, 3750, 11861 }, + { 1, 306, 39, 3750, 12255 }, + { 1, 345, 38, 3750, 12649 }, + { 1, 383, 39, 3750, 13043 }, + { 1, 422, 29, 3750, 13437 }, + { 2, 0, 42, 3750, 13831 }, + { 2, 42, 41, 3750, 14225 }, + { 2, 83, 39, 3750, 14619 }, + { 2, 122, 32, 3750, 15013 }, + { 2, 154, 38, 3750, 15407 }, + { 2, 192, 34, 3750, 15801 }, + { 2, 226, 38, 3750, 16195 }, + // Column 2 + { 2, 264, 42, 10725, 3193 }, + { 2, 306, 39, 10725, 3587 }, + { 2, 345, 37, 10725, 3981 }, + { 2, 382, 37, 10725, 4375 }, + { 2, 419, 42, 10725, 4769 }, + { 2, 461, 36, 10725, 5163 }, + { 2, 497, 36, 10725, 5557 }, + { 2, 533, 40, 10725, 5951 }, + { 2, 573, 35, 10725, 6345 }, + { 2, 608, 30, 10725, 6739 }, + }; + + sd::DrawDocShellRef xDocShRef + = loadURL(m_directories.getURLFromSrc(u"/sd/qa/unit/data/odg/two_columns.odg"), ODG); + + std::shared_ptr<GDIMetaFile> xMetaFile = xDocShRef->GetPreviewMetaFile(); + MetafileXmlDump dumper; + + xmlDocUniquePtr pXmlDoc = XmlTestTools::dumpAndParse(dumper, *xMetaFile); + CPPUNIT_ASSERT(pXmlDoc); + + for (size_t i = 0; i < SAL_N_ELEMENTS(strings); ++i) + { + const auto & [ sentence, index, length, x, y ] = strings[i]; + OString sXPath = "/metafile/push[1]/push[1]/textarray[" + OString::number(i + 1) + "]"; + assertXPathContent(pXmlDoc, sXPath + "/text", sText[sentence]); + assertXPath(pXmlDoc, sXPath, "index", OUString::number(index)); + assertXPath(pXmlDoc, sXPath, "length", OUString::number(length)); + assertXPath(pXmlDoc, sXPath, "x", OUString::number(x)); + assertXPath(pXmlDoc, sXPath, "y", OUString::number(y)); + } xDocShRef->DoClose(); } diff --git a/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx b/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx index 762faaac1b56..7232d59cc29d 100644 --- a/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx +++ b/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx @@ -664,7 +664,7 @@ void LOKitSearchTest::testSearchIn2MixedObjects() CPPUNIT_ASSERT_EQUAL(size_t(1), mpCallbackRecorder->m_aSearchResultSelection.size()); CPPUNIT_ASSERT_EQUAL(size_t(1), mpCallbackRecorder->m_aSearchResultPart.size()); - CPPUNIT_ASSERT_EQUAL(OString("3546, 3174, 738, 402"), + CPPUNIT_ASSERT_EQUAL(OString("3546, 3173, 738, 401"), mpCallbackRecorder->m_aSearchResultSelection[0]); // Search next @@ -690,7 +690,7 @@ void LOKitSearchTest::testSearchIn2MixedObjects() CPPUNIT_ASSERT_EQUAL(size_t(1), mpCallbackRecorder->m_aSearchResultSelection.size()); CPPUNIT_ASSERT_EQUAL(size_t(1), mpCallbackRecorder->m_aSearchResultPart.size()); - CPPUNIT_ASSERT_EQUAL(OString("3546, 3174, 738, 402"), + CPPUNIT_ASSERT_EQUAL(OString("3546, 3173, 738, 401"), mpCallbackRecorder->m_aSearchResultSelection[0]); } |