[Libreoffice-commits] core.git: oox/source sd/qa

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sat Dec 1 15:53:14 UTC 2018


 oox/source/drawingml/diagram/diagramlayoutatoms.cxx |   22 +++-
 sd/qa/unit/data/pptx/smartart-autoTxRot.pptx        |binary
 sd/qa/unit/import-tests-smartart.cxx                |   91 ++++++++++++++++++++
 3 files changed, 109 insertions(+), 4 deletions(-)

New commits:
commit af843af4c816ef25246c815e187729ec25b2f000
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sat Dec 1 17:51:11 2018 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sat Dec 1 16:52:52 2018 +0100

    tdf#121844: properly implement autoTxRot support
    
    ... after commit cf7b97d1328ec2f2c8254abb9ce67d63d9c54c80
    
    Change-Id: If46265f49a85d92254fedb719d76ff7319c092cc
    Reviewed-on: https://gerrit.libreoffice.org/64396
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index 74cd2ed7d06c..f99126be9bed 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -802,20 +802,34 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
                 break;
             }
 
+            // ECMA-376-1:2016 21.4.7.5 ST_AutoTextRotation (Auto Text Rotation)
             const sal_Int32 nautoTxRot = maMap.count(XML_autoTxRot) ? maMap.find(XML_autoTxRot)->second : XML_upr;
+            sal_Int32 nShapeRot = rShape->getRotation();
+            while (nShapeRot < 0)
+                nShapeRot += 360 * PER_DEGREE;
+            while (nShapeRot > 360 * PER_DEGREE)
+                nShapeRot -= 360 * PER_DEGREE;
 
             switch(nautoTxRot)
             {
                 case XML_upr:
                 {
-                    if (rShape->getRotation())
-                        pTextBody->getTextProperties().moRotation = -F_PI180*90*rShape->getRotation();
+                    int n90x = 0;
+                    if (nShapeRot >= 315 * PER_DEGREE)
+                        /* keep 0 */;
+                    else if (nShapeRot > 225 * PER_DEGREE)
+                        n90x = -3;
+                    else if (nShapeRot >= 135 * PER_DEGREE)
+                        n90x = -2;
+                    else if (nShapeRot > 45 * PER_DEGREE)
+                        n90x = -1;
+                    pTextBody->getTextProperties().moRotation = n90x * 90 * PER_DEGREE;
                 }
                 break;
                 case XML_grav:
                 {
-                    if (rShape->getRotation()==90*F_PI180 || rShape->getRotation()==180*F_PI180)
-                        pTextBody->getTextProperties().moRotation = 180*F_PI180;
+                    if (nShapeRot > (90 * PER_DEGREE) && nShapeRot < (270 * PER_DEGREE))
+                        pTextBody->getTextProperties().moRotation = -180 * PER_DEGREE;
                 }
                 break;
                 case XML_none:
diff --git a/sd/qa/unit/data/pptx/smartart-autoTxRot.pptx b/sd/qa/unit/data/pptx/smartart-autoTxRot.pptx
new file mode 100644
index 000000000000..30e69a6de6c1
Binary files /dev/null and b/sd/qa/unit/data/pptx/smartart-autoTxRot.pptx differ
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index fe24ff486fa3..1f30ba36e394 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -28,6 +28,7 @@ public:
     void testDir();
     void testMaxDepth();
     void testRotation();
+    void testTextAutoRotation();
     void testPyramid();
     void testChevron();
     void testCycle();
@@ -56,6 +57,7 @@ public:
     CPPUNIT_TEST(testDir);
     CPPUNIT_TEST(testMaxDepth);
     CPPUNIT_TEST(testRotation);
+    CPPUNIT_TEST(testTextAutoRotation);
     CPPUNIT_TEST(testPyramid);
     CPPUNIT_TEST(testChevron);
     CPPUNIT_TEST(testCycle);
@@ -240,6 +242,95 @@ void SdImportTestSmartArt::testRotation()
     xDocShRef->DoClose();
 }
 
+void SdImportTestSmartArt::testTextAutoRotation()
+{
+    sd::DrawDocShellRef xDocShRef = loadURL(
+        m_directories.getURLFromSrc("sd/qa/unit/data/pptx/smartart-autoTxRot.pptx"), PPTX);
+
+    auto testText = [&](int pageNo, sal_Int32 txtNo, const OUString& expTx, sal_Int32 expShRot,
+                        sal_Int32 expTxRot) {
+        OString msgText = "Page: " + OString::number(pageNo) + " text: " + OString::number(txtNo);
+        uno::Reference<drawing::XShapes> xShapeGroup(getShapeFromPage(0, pageNo, xDocShRef),
+                                                     uno::UNO_QUERY_THROW);
+
+        uno::Reference<text::XText> xTxt(xShapeGroup->getByIndex(txtNo), uno::UNO_QUERY_THROW);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(msgText.getStr(), expTx, xTxt->getString());
+        uno::Reference<beans::XPropertySet> xTxtProps(xTxt, uno::UNO_QUERY_THROW);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(msgText.getStr(), expShRot,
+                                     xTxtProps->getPropertyValue("RotateAngle").get<sal_Int32>());
+
+        auto aGeomPropSeq = xTxtProps->getPropertyValue("CustomShapeGeometry")
+                                .get<uno::Sequence<beans::PropertyValue>>();
+        comphelper::SequenceAsHashMap aCustomShapeGeometry(aGeomPropSeq);
+
+        auto it = aCustomShapeGeometry.find("TextPreRotateAngle");
+        if (it == aCustomShapeGeometry.end())
+        {
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(msgText.getStr(), sal_Int32(0), expTxRot);
+        }
+        else
+        {
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(msgText.getStr(), expTxRot, it->second.get<sal_Int32>());
+        }
+    };
+
+    // Slide 1: absent autoTxRot => defaults to "upr"
+    testText(0, 0,  "a", 0,     0);
+    testText(0, 1,  "b", 33750, 0);
+    testText(0, 2,  "c", 31500, 0);
+    testText(0, 3,  "d", 29250, 90);
+    testText(0, 4,  "e", 27000, 90);
+    testText(0, 5,  "f", 24750, 90);
+    testText(0, 6,  "g", 22500, 180);
+    testText(0, 7,  "h", 20250, 180);
+    testText(0, 8,  "i", 18000, 180);
+    testText(0, 9,  "j", 15750, 180);
+    testText(0, 10, "k", 13500, 180);
+    testText(0, 11, "l", 11250, 270);
+    testText(0, 12, "m", 9000,  270);
+    testText(0, 13, "n", 6750,  270);
+    testText(0, 14, "o", 4500,  0);
+    testText(0, 15, "p", 2250,  0);
+
+    // Slide 2: autoTxRot == "none"
+    testText(1, 0,  "a", 0,     0);
+    testText(1, 1,  "b", 33750, 0);
+    testText(1, 2,  "c", 31500, 0);
+    testText(1, 3,  "d", 29250, 0);
+    testText(1, 4,  "e", 27000, 0);
+    testText(1, 5,  "f", 24750, 0);
+    testText(1, 6,  "g", 22500, 0);
+    testText(1, 7,  "h", 20250, 0);
+    testText(1, 8,  "i", 18000, 0);
+    testText(1, 9,  "j", 15750, 0);
+    testText(1, 10, "k", 13500, 0);
+    testText(1, 11, "l", 11250, 0);
+    testText(1, 12, "m", 9000,  0);
+    testText(1, 13, "n", 6750,  0);
+    testText(1, 14, "o", 4500,  0);
+    testText(1, 15, "p", 2250,  0);
+
+    // Slide 3: autoTxRot == "grav"
+    testText(2, 0,  "a", 0,     0);
+    testText(2, 1,  "b", 33750, 0);
+    testText(2, 2,  "c", 31500, 0);
+    testText(2, 3,  "d", 29250, 0);
+    testText(2, 4,  "e", 27000, 0);
+    testText(2, 5,  "f", 24750, 180);
+    testText(2, 6,  "g", 22500, 180);
+    testText(2, 7,  "h", 20250, 180);
+    testText(2, 8,  "i", 18000, 180);
+    testText(2, 9,  "j", 15750, 180);
+    testText(2, 10, "k", 13500, 180);
+    testText(2, 11, "l", 11250, 180);
+    testText(2, 12, "m", 9000,  0);
+    testText(2, 13, "n", 6750,  0);
+    testText(2, 14, "o", 4500,  0);
+    testText(2, 15, "p", 2250,  0);
+
+    xDocShRef->DoClose();
+}
+
 void SdImportTestSmartArt::testBasicProcess()
 {
     //FIXME : so far this only introduce the test document, but the actual importer was not fixed yet.


More information about the Libreoffice-commits mailing list