[Libreoffice-commits] core.git: Branch 'libreoffice-6-2' - 2 commits - oox/source sd/qa

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Dec 17 14:40:26 UTC 2018


 oox/source/drawingml/diagram/diagramlayoutatoms.cxx         |   43 +++++++---
 sd/qa/unit/data/pptx/smartart-continuous-block-process.pptx |binary
 sd/qa/unit/import-tests-smartart.cxx                        |   48 ++++++++++++
 3 files changed, 78 insertions(+), 13 deletions(-)

New commits:
commit 9fb15b5bcde121f1aeedc1843a9a055479530753
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Dec 14 16:01:27 2018 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Dec 17 15:40:14 2018 +0100

    oox smartart, accent process: fix missing bullets and large para indent
    
    Bulleted paragraphs had a large left indent because we assumed the
    bullet levels are inherited from the normal master page styles.
    
    But that's not true, as
    <https://support.office.com/en-us/article/add-bullets-to-a-shape-in-a-smartart-graphic-47edc03d-a2f8-4b54-acfd-ca103c515ab4>
    points out:
    
    "It is not possible to change the bullet style for text in a SmartArt
    graphic."
    
    This explains why the margin and bullet char info is missing from the
    file format, and hints that just hardcoding these to the importer is
    correct.
    
    The result is less linebreaks in the shape text and the lost bullets are
    also fixed.
    
    Change-Id: I60bbee75f3e834551ebb1963a2f42101f3bd91d4
    Reviewed-on: https://gerrit.libreoffice.org/65168
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit 6277a767f33bb5327408dafff2fed199087e938d)
    Reviewed-on: https://gerrit.libreoffice.org/65254

diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index 15a064f2d66b..7a71ec106db9 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -853,13 +853,27 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
             }
 
             ParamMap::const_iterator aBulletLvl = maMap.find(XML_stBulletLvl);
+            int nStartBulletsAtLevel = 0;
             if (aBulletLvl != maMap.end())
+            {
                 nBaseLevel -= aBulletLvl->second;
+                nStartBulletsAtLevel = aBulletLvl->second;
+            }
 
             for (auto & aParagraph : pTextBody->getParagraphs())
             {
                 sal_Int32 nLevel = aParagraph->getProperties().getLevel();
                 aParagraph->getProperties().setLevel(nLevel - nBaseLevel);
+                if (nStartBulletsAtLevel > 0 && nLevel >= nStartBulletsAtLevel)
+                {
+                    // It is not possible to change the bullet style for text.
+                    sal_Int32 nLeftMargin = 285750 * (nLevel - nStartBulletsAtLevel) / EMU_PER_HMM;
+                    aParagraph->getProperties().getParaLeftMargin() = nLeftMargin;
+                    aParagraph->getProperties().getFirstLineIndentation() = -285750 / EMU_PER_HMM;
+                    OUString aBulletChar = OUString::fromUtf8(u8"•");
+                    aParagraph->getProperties().getBulletList().setBulletChar(aBulletChar);
+                    aParagraph->getProperties().getBulletList().setSuffixNone();
+                }
             }
 
             // explicit alignment
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index bb5b4b3c8e6a..944c40716795 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -485,6 +485,23 @@ void SdImportTestSmartArt::testAccentProcess()
     CPPUNIT_ASSERT_EQUAL(OUString("b"), xFirstChildText->getString());
     uno::Reference<drawing::XShape> xFirstChild(xFirstChildText, uno::UNO_QUERY);
     CPPUNIT_ASSERT(xFirstChildText.is());
+
+    {
+        uno::Reference<container::XEnumerationAccess> xParasAccess(xFirstChildText, uno::UNO_QUERY);
+        uno::Reference<container::XEnumeration> xParas = xParasAccess->createEnumeration();
+        uno::Reference<beans::XPropertySet> xPara(xParas->nextElement(), uno::UNO_QUERY);
+        // Without the accompanying fix in place, this test would have failed
+        // with 'Expected: 0; Actual  : 1270', i.e. there was a large
+        // unexpected left margin.
+        CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0),
+                             xPara->getPropertyValue("ParaLeftMargin").get<sal_Int32>());
+
+        uno::Reference<container::XIndexAccess> xRules(xPara->getPropertyValue("NumberingRules"),
+                                                       uno::UNO_QUERY);
+        comphelper::SequenceAsHashMap aRule(xRules->getByIndex(1));
+        CPPUNIT_ASSERT_EQUAL(OUString::fromUtf8(u8"•"), aRule["BulletChar"].get<OUString>());
+    }
+
     int nFirstChildTop = xFirstChild->getPosition().Y;
     int nFirstChildRight = xFirstChild->getPosition().X + xFirstChild->getSize().Width;
 
commit 6f2b06a279ecfeeeb7948a6373dd85bc7b4041e3
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Dec 12 18:09:12 2018 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Dec 17 15:40:05 2018 +0100

    oox smartart, continuous block process: read space width from constraint
    
    The information is needed by the linear layout, but it's provided by a
    child algorithm of type "space", with possibly multiple foreach atoms
    in-between.
    
    So start supporting a custom space factor by reading it from
    constraints, but still assume a fixed layout node name, as it's tricky
    to look that up.
    
    Change-Id: I2aa8db8823694618d8ca6707ddcd71715a65b831
    Reviewed-on: https://gerrit.libreoffice.org/65049
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit ee6787fc5597b7f730c4ee3a1f2a1b261d0a5644)
    Reviewed-on: https://gerrit.libreoffice.org/65253

diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index 74cd2ed7d06c..15a064f2d66b 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -536,22 +536,9 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
             const sal_Int32 nIncX = nDir==XML_fromL ? 1 : (nDir==XML_fromR ? -1 : 0);
             const sal_Int32 nIncY = nDir==XML_fromT ? 1 : (nDir==XML_fromB ? -1 : 0);
 
-            // TODO: get values from constraints
             sal_Int32 nCount = rShape->getChildren().size();
             double fSpace = 0.3;
 
-            awt::Size aChildSize = rShape->getSize();
-            if (nDir == XML_fromL || nDir == XML_fromR)
-                aChildSize.Width /= (nCount + (nCount-1)*fSpace);
-            else if (nDir == XML_fromT || nDir == XML_fromB)
-                aChildSize.Height /= (nCount + (nCount-1)*fSpace);
-
-            awt::Point aCurrPos(0, 0);
-            if (nIncX == -1)
-                aCurrPos.X = rShape->getSize().Width - aChildSize.Width;
-            if (nIncY == -1)
-                aCurrPos.Y = rShape->getSize().Height - aChildSize.Height;
-
             // Find out which constraint is relevant for which (internal) name.
             LayoutPropertyMap aProperties;
             for (const auto& rConstraint : rConstraints)
@@ -562,8 +549,24 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
                 LayoutProperty& rProperty = aProperties[rConstraint.msForName];
                 if (rConstraint.mnType == XML_w)
                     rProperty[XML_w] = rShape->getSize().Width * rConstraint.mfFactor;
+
+                // TODO: get values from differently named constraints as well
+                if (rConstraint.msForName == "sibTrans" && rConstraint.mnType == XML_w)
+                    fSpace = rConstraint.mfFactor;
             }
 
+            awt::Size aChildSize = rShape->getSize();
+            if (nDir == XML_fromL || nDir == XML_fromR)
+                aChildSize.Width /= (nCount + (nCount-1)*fSpace);
+            else if (nDir == XML_fromT || nDir == XML_fromB)
+                aChildSize.Height /= (nCount + (nCount-1)*fSpace);
+
+            awt::Point aCurrPos(0, 0);
+            if (nIncX == -1)
+                aCurrPos.X = rShape->getSize().Width - aChildSize.Width;
+            if (nIncY == -1)
+                aCurrPos.Y = rShape->getSize().Height - aChildSize.Height;
+
             // See if children requested more than 100% space in total: scale
             // down in that case.
             sal_Int32 nTotalWidth = 0;
diff --git a/sd/qa/unit/data/pptx/smartart-continuous-block-process.pptx b/sd/qa/unit/data/pptx/smartart-continuous-block-process.pptx
new file mode 100644
index 000000000000..b2ef58f0bbb3
Binary files /dev/null and b/sd/qa/unit/data/pptx/smartart-continuous-block-process.pptx differ
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index fe24ff486fa3..bb5b4b3c8e6a 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -46,6 +46,7 @@ public:
     void testVertialBracketList();
     void testTableList();
     void testAccentProcess();
+    void testContinuousBlockProcess();
 
     CPPUNIT_TEST_SUITE(SdImportTestSmartArt);
 
@@ -74,6 +75,7 @@ public:
     CPPUNIT_TEST(testVertialBracketList);
     CPPUNIT_TEST(testTableList);
     CPPUNIT_TEST(testAccentProcess);
+    CPPUNIT_TEST(testContinuousBlockProcess);
 
     CPPUNIT_TEST_SUITE_END();
 };
@@ -528,6 +530,35 @@ void SdImportTestSmartArt::testAccentProcess()
     xDocShRef->DoClose();
 }
 
+void SdImportTestSmartArt::testContinuousBlockProcess()
+{
+    sd::DrawDocShellRef xDocShRef = loadURL(
+        m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/smartart-continuous-block-process.pptx"),
+        PPTX);
+    uno::Reference<drawing::XShapes> xGroup(getShapeFromPage(0, 0, xDocShRef), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xGroup.is());
+    // 2 children: background, foreground.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xGroup->getCount());
+
+    uno::Reference<drawing::XShapes> xLinear(xGroup->getByIndex(1), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xLinear.is());
+    // 3 children: A, B and C.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), xLinear->getCount());
+
+    uno::Reference<text::XText> xA(xLinear->getByIndex(0), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xA.is());
+    CPPUNIT_ASSERT_EQUAL(OUString("A"), xA->getString());
+    uno::Reference<drawing::XShape> xAShape(xA, uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xAShape.is());
+    // Without the accompanying fix in place, this test would have failed: the
+    // theoretically correct value is 5462 mm100 (16933 is the total width, and
+    // need to divide that to 1, 0.5, 1, 0.5 and 1 units), while the old value
+    // was 4703 and the new one is 5461.
+    CPPUNIT_ASSERT_GREATER(static_cast<sal_Int32>(5000), xAShape->getSize().Width);
+
+    xDocShRef->DoClose();
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTestSmartArt);
 
 CPPUNIT_PLUGIN_IMPLEMENT();


More information about the Libreoffice-commits mailing list