From 22cd7d8b679d238559820d3c4cd5ff0b9153ffce Mon Sep 17 00:00:00 2001 From: Tünde Tóth Date: Mon, 10 Aug 2020 10:26:06 +0200 Subject: tdf#123218 tdf#108067 config key ReverseXAxisOrientationDoughnutChart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit for OOXML compatibility of newly created doughnut charts. The X axis orientation of doughnut charts is the opposite of the primary writing direction in LibreOffice but not in Microsoft Office. Default value is "true" to keep current behavior. Using "false", the inner and outer data series of new doughnut charts are the same, as after DOCX export. Change-Id: If431d5717e70599f07231bd673cd90c196450ae6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100417 Tested-by: László Németh Reviewed-by: László Németh --- sw/qa/extras/uiwriter/uiwriter2.cxx | 121 ++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) (limited to 'sw') diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 2b31e2694038..f93aba8f4e2a 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -14,12 +14,18 @@ #include #include +#include +#include +#include +#include +#include #include #include #include #include #include #include +#include #include #include #include @@ -2890,4 +2896,119 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf129655) xmlDocUniquePtr pXmlDoc = parseLayoutDump(); assertXPath(pXmlDoc, "//fly/txt[@WritingMode='Vertical']", 1); } + +static uno::Reference getAssociatedTextRange(uno::Any object) +{ + // possible cases: + // 1. a container of other objects - e.g. selection of 0 to n text portions, or 1 to n drawing objects + try + { + uno::Reference xIndexAccess(object, uno::UNO_QUERY_THROW); + if (xIndexAccess.is() && xIndexAccess->getCount() > 0) + { + for (int i = 0; i < xIndexAccess->getCount(); ++i) + { + uno::Reference xRange + = getAssociatedTextRange(xIndexAccess->getByIndex(i)); + if (xRange.is()) + return xRange; + } + } + } + catch (const uno::Exception&) + { + } + + // 2. another TextContent, having an anchor we can use + try + { + uno::Reference xTextContent(object, uno::UNO_QUERY_THROW); + if (xTextContent.is()) + { + uno::Reference xRange = xTextContent->getAnchor(); + if (xRange.is()) + return xRange; + } + } + catch (const uno::Exception&) + { + } + + // an object which supports XTextRange directly + try + { + uno::Reference xRange(object, uno::UNO_QUERY_THROW); + if (xRange.is()) + return xRange; + } + catch (const uno::Exception&) + { + } + + return nullptr; +} + +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf123218) +{ + struct ReverseXAxisOrientationDoughnutChart + : public comphelper::ConfigurationProperty + { + static OUString path() + { + return "/org.openoffice.Office.Compatibility/View/ReverseXAxisOrientationDoughnutChart"; + } + ~ReverseXAxisOrientationDoughnutChart() = delete; + }; + auto batch = comphelper::ConfigurationChanges::create(); + + ReverseXAxisOrientationDoughnutChart::set(false, batch); + batch->commit(); + + createDoc(); + SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + + // create an OLE shape in the document + uno::Reference xMSF(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xMSF); + uno::Reference xShapeProps( + xMSF->createInstance("com.sun.star.text.TextEmbeddedObject"), uno::UNO_QUERY); + xShapeProps->setPropertyValue("CLSID", + uno::makeAny(OUString("12dcae26-281f-416f-a234-c3086127382e"))); + uno::Reference xShape(xShapeProps, uno::UNO_QUERY_THROW); + xShape->setSize(awt::Size(16000, 9000)); + uno::Reference chartTextContent(xShapeProps, uno::UNO_QUERY_THROW); + uno::Reference xSelSupplier(pTextDoc->getCurrentController(), + uno::UNO_QUERY_THROW); + uno::Any aSelection = xSelSupplier->getSelection(); + uno::Reference xTextRange = getAssociatedTextRange(aSelection); + CPPUNIT_ASSERT(xTextRange); + xTextRange->getText()->insertTextContent(xTextRange, chartTextContent, false); + + // insert a doughnut chart + uno::Reference xDocModel; + xShapeProps->getPropertyValue("Model") >>= xDocModel; + CPPUNIT_ASSERT(xDocModel); + uno::Reference xChartDoc(xDocModel, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xChartDoc); + uno::Reference xChartMSF(xChartDoc, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xChartMSF); + uno::Reference xDiagram( + xChartMSF->createInstance("com.sun.star.chart.DonutDiagram"), uno::UNO_QUERY); + xChartDoc->setDiagram(xDiagram); + + // test primary X axis Orientation value + uno::Reference xChartDoc2(xChartDoc, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xChartDoc2); + uno::Reference xCooSysContainer( + xChartDoc2->getFirstDiagram(), uno::UNO_QUERY_THROW); + uno::Sequence> xCooSysSequence + = xCooSysContainer->getCoordinateSystems(); + uno::Reference xCoord = xCooSysSequence[0]; + CPPUNIT_ASSERT(xCoord.is()); + uno::Reference xAxis = xCoord->getAxisByDimension(0, 0); + CPPUNIT_ASSERT(xAxis.is()); + chart2::ScaleData aScaleData = xAxis->getScaleData(); + CPPUNIT_ASSERT_EQUAL(chart2::AxisOrientation_MATHEMATICAL, aScaleData.Orientation); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit