oox/source/drawingml/shape.cxx         |   12 ++++++------
 sc/qa/unit/data/xlsx/tdf141644.xlsx    |binary
 sc/qa/unit/subsequent_export-test.cxx  |    4 ++--
 sc/qa/unit/subsequent_filters-test.cxx |   27 +++++++++++++++++++++++++++
 4 files changed, 35 insertions(+), 8 deletions(-)

New commits:
commit 16ec67b98179448a22c2cc3f82ca69a842ba8e3a
Author:     Szabolcs Toth <toth.szabo...@nisz.hu>
AuthorDate: Wed May 19 08:42:29 2021 +0200
Commit:     Gabor Kelemen <kelemen.gab...@nisz.hu>
CommitDate: Thu Aug 19 15:58:55 2021 +0200

    tdf#141644 OOXML shape import: fix upright text rotate angle
    
    Text rotate angle was not imported correctly with
    "upright" setting, e.g. resulting horizontal text
    in shapes of XLSX documents instead of vertical.
    
    Change-Id: I2ad9ba3465278220e64123c4400acff4125310d1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115777
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit b2190523e0b226bcae19cc8c3ce8a83855c7f009)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120714
    Tested-by: Gabor Kelemen <kelemen.gab...@nisz.hu>
    Reviewed-by: Gabor Kelemen <kelemen.gab...@nisz.hu>

diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx
index a9388e8a4a70..6fdc11a14a24 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -1498,6 +1498,9 @@ Reference< XShape > const & Shape::createAndInsert(
                 sal_Int32 nTextRotateAngle = static_cast< sal_Int32 >( 
getTextBody()->getTextProperties().moRotation.get( 0 ) );
 
                 nTextRotateAngle -= mnDiagramRotation;
+                /* OOX measures text rotation clockwise in 1/60000th degrees,
+                   relative to the containing shape. setTextRotateAngle wants 
degrees anticlockwise. */
+                nTextRotateAngle = -1 * nTextRotateAngle / 60000;
 
                 if (getTextBody()->getTextProperties().moUpright)
                 {
@@ -1506,18 +1509,15 @@ Reference< XShape > const & Shape::createAndInsert(
                     // shape containing it is rotated.
                     // Hence, we rotate the text into the opposite direction of
                     // the rotation of the shape, by as much as the shape was 
rotated.
-                    mpCustomShapePropertiesPtr->setTextRotateAngle(mnRotation 
/ 60000);
+                    mpCustomShapePropertiesPtr->setTextRotateAngle((mnRotation 
/ 60000) + nTextRotateAngle);
                     // Also put the initial angles away in a GrabBag.
                     putPropertyToGrabBag("Upright", Any(true));
                     putPropertyToGrabBag("nShapeRotationAtImport", 
Any(mnRotation / 60000));
-                    putPropertyToGrabBag("nTextRotationAtImport", 
Any(mnRotation / 60000));
+                    putPropertyToGrabBag("nTextRotationAtImport", 
Any(nTextRotateAngle));
                 }
                 else
                 {
-                    /* OOX measures text rotation clockwise in 1/60000th 
degrees,
-                       relative to the containing shape. setTextRotateAngle 
wants
-                       degrees anticlockwise. */
-                    mpCustomShapePropertiesPtr->setTextRotateAngle(-1 * 
nTextRotateAngle / 60000);
+                    
mpCustomShapePropertiesPtr->setTextRotateAngle(nTextRotateAngle);
                 }
 
                 auto sHorzOverflow = 
getTextBody()->getTextProperties().msHorzOverflow;
diff --git a/sc/qa/unit/data/xlsx/tdf141644.xlsx 
b/sc/qa/unit/data/xlsx/tdf141644.xlsx
new file mode 100644
index 000000000000..61599d53fd62
Binary files /dev/null and b/sc/qa/unit/data/xlsx/tdf141644.xlsx differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx 
b/sc/qa/unit/subsequent_export-test.cxx
index 4fe66b51f487..3b6a16d98b3c 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -5653,8 +5653,8 @@ void ScExportTest::testTdf137000_handle_upright()
         = XPathHelper::parseExport(pXPathFile, m_xSFactory, 
"xl/drawings/drawing1.xml");
     CPPUNIT_ASSERT(pDrawing);
 
-    assertXPathNoAttribute(pDrawing, 
"/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:txBody/a:bodyPr",
-                           "rot");
+    assertXPath(pDrawing, 
"/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:txBody/a:bodyPr",
+                           "rot", "-5400000");
 }
 
 void ScExportTest::testTdf126305_DataValidatyErrorAlert()
diff --git a/sc/qa/unit/subsequent_filters-test.cxx 
b/sc/qa/unit/subsequent_filters-test.cxx
index 38115f9ec2d6..8b9e000859cf 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -295,6 +295,7 @@ public:
     void testShapeRotationImport();
     void testShapeDisplacementOnRotationImport();
     void testTextBoxBodyUpright();
+    void testTextBoxBodyRotateAngle();
     void testTextLengthDataValidityXLSX();
     void testDeleteCircles();
     void testDrawCircleInMergeCells();
@@ -482,6 +483,7 @@ public:
     CPPUNIT_TEST(testShapeRotationImport);
     CPPUNIT_TEST(testShapeDisplacementOnRotationImport);
     CPPUNIT_TEST(testTextBoxBodyUpright);
+    CPPUNIT_TEST(testTextBoxBodyRotateAngle);
     CPPUNIT_TEST(testTextLengthDataValidityXLSX);
     CPPUNIT_TEST(testDeleteCircles);
     CPPUNIT_TEST(testDrawCircleInMergeCells);
@@ -5271,6 +5273,31 @@ void ScFiltersTest::testTextBoxBodyUpright()
     CPPUNIT_ASSERT_EQUAL(sal_Int32(90), nAngle);
 }
 
+void ScFiltersTest::testTextBoxBodyRotateAngle()
+{
+    ScDocShellRef xDocSh = loadDoc(u"tdf141644.", FORMAT_XLSX);
+    CPPUNIT_ASSERT_MESSAGE("Failed to load tdf141644.xlsx", xDocSh.is());
+
+    uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocSh->GetModel(), 
uno::UNO_QUERY_THROW);
+    uno::Reference<drawing::XDrawPage> 
xPage(xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW);
+    uno::Reference<drawing::XShape> xShape(xPage->getByIndex(0), 
uno::UNO_QUERY_THROW);
+    uno::Reference<beans::XPropertySet> xShapeProperties(xShape, 
uno::UNO_QUERY_THROW);
+
+    // Check the new textRotateAngle.
+    sal_Int32 nAngle;
+    uno::Any aGeom = xShapeProperties->getPropertyValue("CustomShapeGeometry");
+    auto aGeomSeq = aGeom.get<Sequence<beans::PropertyValue>>();
+    for (const auto& aProp : std::as_const(aGeomSeq))
+    {
+        if (aProp.Name == "TextPreRotateAngle")
+        {
+            aProp.Value >>= nAngle;
+            break;
+        }
+    }
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(-270), nAngle);
+}
+
 void ScFiltersTest::testTextLengthDataValidityXLSX()
 {
     ScDocShellRef xDocSh = loadDoc("textLengthDataValidity.", FORMAT_XLSX);

Reply via email to