chart2/qa/extras/chart2export.cxx | 159 ++++++++++++++++++++++++++++++++++++++ oox/source/export/chartexport.cxx | 107 ++++++++++++++++++++++++- 2 files changed, 262 insertions(+), 4 deletions(-)
New commits: commit bad41c8fe40e88e416631d61437e6abe5d00131d Author: Szymon Kłos <szymon.k...@collabora.com> Date: Sat Jan 27 20:29:38 2018 +0100 tdf#114821 export complex data labels in charts Change-Id: I9b0893dfde4efc10bb05e6e17b7128b016efeb71 Reviewed-on: https://gerrit.libreoffice.org/48788 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index deedbc0bee7f..618a5b877af7 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -13,6 +13,8 @@ #include <com/sun/star/chart/ErrorBarStyle.hpp> #include <com/sun/star/chart2/XRegressionCurveContainer.hpp> +#include <com/sun/star/chart2/DataPointCustomLabelField.hpp> +#include <com/sun/star/chart2/DataPointCustomLabelFieldType.hpp> #include <com/sun/star/lang/XServiceName.hpp> #include <com/sun/star/packages/zip/ZipFileAccess.hpp> #include <com/sun/star/text/XTextDocument.hpp> @@ -102,6 +104,8 @@ public: void testAxisTitleRotationXLSX(); void testAxisCrossBetweenXSLX(); void testPieChartDataPointExplosionXLSX(); + void testCustomDataLabel(); + void testCustomDataLabelMultipleSeries(); CPPUNIT_TEST_SUITE(Chart2ExportTest); CPPUNIT_TEST(testErrorBarXLSX); @@ -168,6 +172,8 @@ public: CPPUNIT_TEST(testAxisTitleRotationXLSX); CPPUNIT_TEST(testAxisCrossBetweenXSLX); CPPUNIT_TEST(testPieChartDataPointExplosionXLSX); + CPPUNIT_TEST(testCustomDataLabel); + CPPUNIT_TEST(testCustomDataLabelMultipleSeries); CPPUNIT_TEST_SUITE_END(); protected: @@ -1572,6 +1578,159 @@ void Chart2ExportTest::testPieChartDataPointExplosionXLSX() assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dPt/c:explosion", "val", "28"); } +void Chart2ExportTest::testCustomDataLabel() +{ + load("/chart2/qa/extras/data/pptx/", "tdf115107.pptx"); + xmlDocPtr pXmlDoc = parseExport("ppt/charts/chart1", "Impress MS PowerPoint 2007 XML"); + CPPUNIT_ASSERT(pXmlDoc); + + Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xChartDoc.is()); + + uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0)); + CPPUNIT_ASSERT(xDataSeries.is()); + float nFontSize; + sal_Int64 nFontColor; + sal_Int32 nCharUnderline; + uno::Reference<beans::XPropertySet> xPropertySet; + uno::Sequence<uno::Reference<chart2::XDataPointCustomLabelField>> aFields; + + // 1 + xPropertySet.set(xDataSeries->getDataPointByIndex(0), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields; + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), aFields.getLength()); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT, aFields[0]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(OUString("90.0 = "), aFields[0]->getString()); + aFields[0]->getPropertyValue("CharHeight") >>= nFontSize; + aFields[0]->getPropertyValue("CharColor") >>= nFontColor; + CPPUNIT_ASSERT_EQUAL(static_cast<float>(18), nFontSize); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(0xed7d31), nFontColor); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_VALUE, aFields[1]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(OUString("90"), aFields[1]->getString()); + CPPUNIT_ASSERT_EQUAL(OUString("{0C576297-5A9F-4B4E-A675-B6BA406B7D87}"), aFields[1]->getGuid()); + + // 2 + xPropertySet.set(xDataSeries->getDataPointByIndex(1), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields; + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(8), aFields.getLength()); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT, aFields[0]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(OUString("Text"), aFields[0]->getString()); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT, aFields[1]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(OUString(" : "), aFields[1]->getString()); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CATEGORYNAME, aFields[2]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(OUString("B"), aFields[2]->getString()); + CPPUNIT_ASSERT_EQUAL(OUString("{0CCAAACD-B393-42CE-8DBD-82F9F9ADC852}"), aFields[2]->getGuid()); + aFields[2]->getPropertyValue("CharHeight") >>= nFontSize; + aFields[2]->getPropertyValue("CharColor") >>= nFontColor; + CPPUNIT_ASSERT_EQUAL(static_cast<float>(16), nFontSize); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(0xed7d31), nFontColor); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_NEWLINE, aFields[3]->getFieldType()); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT, aFields[4]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(OUString("Multi"), aFields[4]->getString()); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT, aFields[5]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(OUString("line"), aFields[5]->getString()); + aFields[5]->getPropertyValue("CharHeight") >>= nFontSize; + aFields[5]->getPropertyValue("CharColor") >>= nFontColor; + CPPUNIT_ASSERT_EQUAL(static_cast<float>(13), nFontSize); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(0xbf9000), nFontColor); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_NEWLINE, aFields[6]->getFieldType()); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT, aFields[7]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(OUString("Abc"), aFields[7]->getString()); + aFields[7]->getPropertyValue("CharHeight") >>= nFontSize; + aFields[7]->getPropertyValue("CharColor") >>= nFontColor; + aFields[7]->getPropertyValue("CharUnderline") >>= nCharUnderline; + CPPUNIT_ASSERT_EQUAL(static_cast<float>(12), nFontSize); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(0xa9d18e), nFontColor); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), nCharUnderline); + + // 3 + xPropertySet.set(xDataSeries->getDataPointByIndex(2), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields; + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aFields.getLength()); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_SERIESNAME, aFields[0]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(OUString("DATA"), aFields[0]->getString()); + CPPUNIT_ASSERT_EQUAL(OUString("{C8F3EB90-8960-4F9A-A3AD-B4FAC4FE4566}"), aFields[0]->getGuid()); + + // 4 + xPropertySet.set(xDataSeries->getDataPointByIndex(3), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields; + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), aFields.getLength()); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CELLREF, aFields[0]->getFieldType()); + //CPPUNIT_ASSERT_EQUAL(OUString("70"), aFields[0]->getString()); TODO: Not implemented yet + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT, aFields[1]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(OUString(" <CELLREF"), aFields[1]->getString()); +} + +void Chart2ExportTest::testCustomDataLabelMultipleSeries() +{ + load("/chart2/qa/extras/data/pptx/", "tdf115107-2.pptx"); + xmlDocPtr pXmlDoc = parseExport("ppt/charts/chart2", "Impress MS PowerPoint 2007 XML"); + CPPUNIT_ASSERT(pXmlDoc); + + Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xChartDoc.is()); + + uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0)); + CPPUNIT_ASSERT(xDataSeries.is()); + float nFontSize; + sal_Int64 nFontColor; + uno::Reference<beans::XPropertySet> xPropertySet; + uno::Sequence<uno::Reference<chart2::XDataPointCustomLabelField>> aFields; + + // First series + xPropertySet.set(xDataSeries->getDataPointByIndex(0), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields; + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), aFields.getLength()); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_VALUE, aFields[0]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(OUString("4.3"), aFields[0]->getString()); + aFields[0]->getPropertyValue("CharHeight") >>= nFontSize; + aFields[0]->getPropertyValue("CharColor") >>= nFontColor; + CPPUNIT_ASSERT_EQUAL(static_cast<float>(18), nFontSize); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(0xc00000), nFontColor); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT, aFields[1]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(OUString(" "), aFields[1]->getString()); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_SERIESNAME, aFields[2]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(OUString("Bars"), aFields[2]->getString()); + + // Second series + xDataSeries = uno::Reference<chart2::XDataSeries>(getDataSeriesFromDoc(xChartDoc, 0, 1)); + CPPUNIT_ASSERT(xDataSeries.is()); + + xPropertySet.set(xDataSeries->getDataPointByIndex(0), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields; + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), aFields.getLength()); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_VALUE, aFields[0]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(OUString("2"), aFields[0]->getString()); + aFields[0]->getPropertyValue("CharHeight") >>= nFontSize; + aFields[0]->getPropertyValue("CharColor") >>= nFontColor; + CPPUNIT_ASSERT_EQUAL(static_cast<float>(18), nFontSize); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(0xffd966), nFontColor); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT, aFields[1]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(OUString(" "), aFields[1]->getString()); + + CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_SERIESNAME, aFields[2]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(OUString("Line"), aFields[2]->getString()); + +} + CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index 0f33bf708a86..4c8bda4ea97b 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -60,6 +60,8 @@ #include <com/sun/star/chart2/XDataSeriesContainer.hpp> #include <com/sun/star/chart2/DataPointGeometry3D.hpp> #include <com/sun/star/chart2/DataPointLabel.hpp> +#include <com/sun/star/chart2/DataPointCustomLabelField.hpp> +#include <com/sun/star/chart2/DataPointCustomLabelFieldType.hpp> #include <com/sun/star/chart2/Symbol.hpp> #include <com/sun/star/chart2/data/XDataSource.hpp> #include <com/sun/star/chart2/data/XDataSink.hpp> @@ -2900,17 +2902,111 @@ const char* toOOXMLPlacement( sal_Int32 nPlacement ) return "outEnd"; } -void writeLabelProperties( - const FSHelperPtr& pFS, const uno::Reference<beans::XPropertySet>& xPropSet, const LabelPlacementParam& rLabelParam ) +OUString getFieldTypeString( const chart2::DataPointCustomLabelFieldType aType ) +{ + switch (aType) + { + case chart2::DataPointCustomLabelFieldType_CATEGORYNAME: + return OUString("CATEGORYNAME"); + + case chart2::DataPointCustomLabelFieldType_SERIESNAME: + return OUString("SERIESNAME"); + + case chart2::DataPointCustomLabelFieldType_VALUE: + return OUString("VALUE"); + + case chart2::DataPointCustomLabelFieldType_CELLREF: + return OUString("CELLREF"); + + default: + break; + } + return OUString(); +} + +void writeRunProperties( ChartExport* pChartExport, Reference<XPropertySet>& xPropertySet ) +{ + bool bDummy = false; + sal_Int32 nDummy; + pChartExport->WriteRunProperties(xPropertySet, false, XML_rPr, true, bDummy, nDummy); +} + +void writeCustomLabel( const FSHelperPtr& pFS, ChartExport* pChartExport, + const Sequence<Reference<chart2::XDataPointCustomLabelField>>& rCustomLabelFields ) +{ + pFS->startElement(FSNS(XML_c, XML_tx), FSEND); + pFS->startElement(FSNS(XML_c, XML_rich), FSEND); + + // TODO: body properties? + pFS->singleElement(FSNS(XML_a, XML_bodyPr), FSEND); + + OUString sFieldType; + bool bNewParagraph; + pFS->startElement(FSNS(XML_a, XML_p), FSEND); + + for (auto& rField : rCustomLabelFields) + { + Reference<XPropertySet> xPropertySet(rField, UNO_QUERY); + chart2::DataPointCustomLabelFieldType aType = rField->getFieldType(); + sFieldType.clear(); + bNewParagraph = false; + + if (aType == chart2::DataPointCustomLabelFieldType_NEWLINE) + bNewParagraph = true; + else if (aType != chart2::DataPointCustomLabelFieldType_TEXT) + sFieldType = getFieldTypeString(aType); + + if (bNewParagraph) + { + pFS->endElement(FSNS(XML_a, XML_p)); + pFS->startElement(FSNS(XML_a, XML_p), FSEND); + continue; + } + + if (sFieldType.isEmpty()) + { + // Normal text run + pFS->startElement(FSNS(XML_a, XML_r), FSEND); + writeRunProperties(pChartExport, xPropertySet); + + pFS->startElement(FSNS(XML_a, XML_t), FSEND); + pFS->writeEscaped(rField->getString()); + pFS->endElement(FSNS(XML_a, XML_t)); + + pFS->endElement(FSNS(XML_a, XML_r)); + } + else + { + // Field + pFS->startElement(FSNS(XML_a, XML_fld), XML_id, USS(rField->getGuid()), XML_type, USS(sFieldType), FSEND); + writeRunProperties(pChartExport, xPropertySet); + + pFS->startElement(FSNS(XML_a, XML_t), FSEND); + pFS->writeEscaped(rField->getString()); + pFS->endElement(FSNS(XML_a, XML_t)); + + pFS->endElement(FSNS(XML_a, XML_fld)); + } + } + + pFS->endElement(FSNS(XML_a, XML_p)); + pFS->endElement(FSNS(XML_c, XML_rich)); + pFS->endElement(FSNS(XML_c, XML_tx)); +} + +void writeLabelProperties( const FSHelperPtr& pFS, ChartExport* pChartExport, + const uno::Reference<beans::XPropertySet>& xPropSet, const LabelPlacementParam& rLabelParam ) { if (!xPropSet.is()) return; chart2::DataPointLabel aLabel; + Sequence<Reference<chart2::XDataPointCustomLabelField>> aCustomLabelFields; sal_Int32 nLabelBorderWidth = 0; sal_Int32 nLabelBorderColor = 0x00FFFFFF; xPropSet->getPropertyValue("Label") >>= aLabel; + xPropSet->getPropertyValue("CustomLabelFields") >>= aCustomLabelFields; xPropSet->getPropertyValue("LabelBorderWidth") >>= nLabelBorderWidth; xPropSet->getPropertyValue("LabelBorderColor") >>= nLabelBorderColor; @@ -2931,6 +3027,9 @@ void writeLabelProperties( pFS->endElement(FSNS(XML_c, XML_spPr)); } + if (aCustomLabelFields.getLength() > 0) + writeCustomLabel(pFS, pChartExport, aCustomLabelFields); + if (rLabelParam.mbExport) { sal_Int32 nLabelPlacement = rLabelParam.meDefault; @@ -3026,12 +3125,12 @@ void ChartExport::exportDataLabels( // Individual label property that overwrites the baseline. pFS->startElement(FSNS(XML_c, XML_dLbl), FSEND); pFS->singleElement(FSNS(XML_c, XML_idx), XML_val, I32S(nIdx), FSEND); - writeLabelProperties(pFS, xLabelPropSet, aParam); + writeLabelProperties(pFS, this, xLabelPropSet, aParam); pFS->endElement(FSNS(XML_c, XML_dLbl)); } // Baseline label properties for all labels. - writeLabelProperties(pFS, xPropSet, aParam); + writeLabelProperties(pFS, this, xPropSet, aParam); pFS->singleElement(FSNS(XML_c, XML_showLeaderLines), XML_val, "0", _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits