diff options
author | Szabolcs Toth <toth.szabolcs@nisz.hu> | 2021-05-19 08:42:29 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2021-05-25 13:41:29 +0200 |
commit | b2190523e0b226bcae19cc8c3ce8a83855c7f009 (patch) | |
tree | 784b0e90daf8882ce93f13d1d0395d743ba5eaa1 | |
parent | 4c1bab94d7c113f2fcb5458809fe8ec0683be951 (diff) |
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 <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | oox/source/drawingml/shape.cxx | 12 | ||||
-rw-r--r-- | sc/qa/unit/data/xlsx/tdf141644.xlsx | bin | 0 -> 9364 bytes | |||
-rw-r--r-- | sc/qa/unit/subsequent_export-test.cxx | 4 | ||||
-rw-r--r-- | sc/qa/unit/subsequent_filters-test.cxx | 27 |
4 files changed, 35 insertions, 8 deletions
diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index ed26e2313941..b0e2ddef30e7 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -1507,6 +1507,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) { @@ -1515,18 +1518,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 Binary files differnew file mode 100644 index 000000000000..61599d53fd62 --- /dev/null +++ b/sc/qa/unit/data/xlsx/tdf141644.xlsx diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index 6d1b927e931a..7a74e6ebf1f6 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -5856,8 +5856,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 078bd9d3686a..0aed0e30c4b2 100644 --- a/sc/qa/unit/subsequent_filters-test.cxx +++ b/sc/qa/unit/subsequent_filters-test.cxx @@ -311,6 +311,7 @@ public: void testShapeRotationImport(); void testShapeDisplacementOnRotationImport(); void testTextBoxBodyUpright(); + void testTextBoxBodyRotateAngle(); void testTextLengthDataValidityXLSX(); void testDeleteCircles(); void testDrawCircleInMergeCells(); @@ -512,6 +513,7 @@ public: CPPUNIT_TEST(testShapeRotationImport); CPPUNIT_TEST(testShapeDisplacementOnRotationImport); CPPUNIT_TEST(testTextBoxBodyUpright); + CPPUNIT_TEST(testTextBoxBodyRotateAngle); CPPUNIT_TEST(testTextLengthDataValidityXLSX); CPPUNIT_TEST(testDeleteCircles); CPPUNIT_TEST(testDrawCircleInMergeCells); @@ -5557,6 +5559,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(u"textLengthDataValidity.", FORMAT_XLSX); |