summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorRegina Henschel <rb.henschel@t-online.de>2020-08-22 23:03:02 +0200
committerRegina Henschel <rb.henschel@t-online.de>2020-09-05 17:49:15 +0200
commit87d1ebeb11a00301745ee3c3c03fffb7033ab59d (patch)
treefb346833aab57cf5ef9544afd03aaddb6de8c0ec /chart2
parent23cf849bd699427889a99301d50ad52edec9d06d (diff)
tdf#135366 ODF import of line and fill of data labels
LibreOffice has line and fill properties of data labels in a chart in properties of kind "LabelBorderWidth" or "LabelFillColor" at a data point or, as defaults for the points, at a series. But ODF has such information in a <style:style> element, which is refered by a <chart:data-label> element. That one can be child of a <chart:data-point> and child of a <chart:series> element. Microsoft Office correctly uses the <chart:data-point> element and its style for the line and fill properties of data labels. Up to now LO cannot import such information and does not write the ODF elements. Instead LibreOffice reads and writes attributes in 'loext' namespace. Using the "LabelFoo" properties was implemented by Kohei Yoshida, July 2014. Although there is no published service, these properties can be used in macros. Because they are now available since six years, the decision was to keep this internal model and convert on import and export. This patch implements the import of the ODF fill and line properties from the <chart:data-label> element and converts them to the internal used properties. LibreOffice has currently only implemented a few of the possible line and fill properties. When more are implemented, their <ODF,LabelFoo> pairs need to be added to the array aApiToLabelFooPairs, further adaptions are not needed. The <chart:data-label> contains in addition the absolute position of a data label. LibreOffice has internally only a position offset relative to the regular position of the label. The conversion of the position is not included in the patch. Change-Id: I5fd868945585971dac3dd945804a4a2951b8c12d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101194 Tested-by: Jenkins Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
Diffstat (limited to 'chart2')
-rw-r--r--chart2/qa/extras/chart2geometry.cxx100
-rw-r--r--chart2/qa/extras/data/ods/tdf135366_data_label_series.odsbin0 -> 7661 bytes
-rw-r--r--chart2/qa/extras/data/odt/tdf135366_data_label_point.odtbin0 -> 8344 bytes
3 files changed, 96 insertions, 4 deletions
diff --git a/chart2/qa/extras/chart2geometry.cxx b/chart2/qa/extras/chart2geometry.cxx
index 091dafe67265..b3f537c372e0 100644
--- a/chart2/qa/extras/chart2geometry.cxx
+++ b/chart2/qa/extras/chart2geometry.cxx
@@ -11,10 +11,14 @@
#include <test/xmltesttools.hxx>
+#include <com/sun/star/chart2/XChartDocument.hpp>
+#include <com/sun/star/chart2/XDataSeries.hpp>
#include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
+#include <com/sun/star/container/XNamed.hpp>
+#include <com/sun/star/drawing/FillStyle.hpp>
+#include <com/sun/star/drawing/LineStyle.hpp>
#include <com/sun/star/lang/XServiceName.hpp>
#include <com/sun/star/packages/zip/ZipFileAccess.hpp>
-#include <com/sun/star/drawing/LineStyle.hpp>
#include <unotools/ucbstreamhelper.hxx>
@@ -46,6 +50,8 @@ public:
void testTdf128345ChartWall_CS_TG_import();
void testTdf128345Legend_CS_TG_axial_export();
void testTdf128345Legend_CS_TG_axial_import();
+ void testTdf135366LabelOnSeries();
+ void testTdf135366LabelOnPoint();
CPPUNIT_TEST_SUITE(Chart2GeometryTest);
CPPUNIT_TEST(testTdf135184RoundLineCap);
@@ -58,6 +64,8 @@ public:
CPPUNIT_TEST(testTdf128345ChartWall_CS_TG_import);
CPPUNIT_TEST(testTdf128345Legend_CS_TG_axial_export);
CPPUNIT_TEST(testTdf128345Legend_CS_TG_axial_import);
+ CPPUNIT_TEST(testTdf135366LabelOnSeries);
+ CPPUNIT_TEST(testTdf135366LabelOnPoint);
CPPUNIT_TEST_SUITE_END();
@@ -71,12 +79,12 @@ protected:
xmlDocUniquePtr parseExport(const OUString& rDir, const OUString& rFilterFormat);
};
-// This is copied from Chart2ExportTest. It allows to access the chart form a MS Office document
+namespace
+{
+// This is copied from Chart2ExportTest. It allows to access the chart from a MS Office document
// without knowing whether the file is a chart1.xml or chart2.xml... As of August 2020, Calc
// and Impress use a static variable for the number and therefore the number depends on whether
// there had already been savings before.
-namespace
-{
struct CheckForChartName
{
private:
@@ -410,6 +418,90 @@ void Chart2GeometryTest::testTdf128345Legend_CS_TG_axial_import()
assertXPath(pXmlDoc2, sStart + " and @draw:end='100%']");
}
+void Chart2GeometryTest::testTdf135366LabelOnSeries()
+{
+ // Error was, that the fill and line properties of a <chart:data-label> were not
+ // imported at all. Here they should be at the series.
+ load("/chart2/qa/extras/data/ods/", "tdf135366_data_label_series.ods");
+ uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
+ CPPUNIT_ASSERT(xChartDoc.is());
+ Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
+ CPPUNIT_ASSERT(xDataSeries.is());
+ Reference<beans::XPropertySet> xPropSet(xDataSeries, UNO_QUERY_THROW);
+ uno::Any aAny;
+
+ aAny = xPropSet->getPropertyValue("LabelBorderStyle");
+ drawing::LineStyle eLineStyle;
+ CPPUNIT_ASSERT_MESSAGE("No LabelBorderStyle set.", aAny >>= eLineStyle);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("solid line expected", drawing::LineStyle_SOLID, eLineStyle);
+
+ sal_Int32 nBorderWidth;
+ sal_Int32 nExpectedWidth = 95;
+ xPropSet->getPropertyValue("LabelBorderWidth") >>= nBorderWidth;
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("LabelBorderWidth", nExpectedWidth, nBorderWidth);
+
+ sal_Int32 nLineColor;
+ sal_Int32 nExpectedLineColor = 255;
+ xPropSet->getPropertyValue("LabelBorderColor") >>= nLineColor;
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("line color blue, 255=#0000FF", nExpectedLineColor, nLineColor);
+
+ aAny = xPropSet->getPropertyValue("LabelFillStyle");
+ drawing::FillStyle eFillStyle;
+ CPPUNIT_ASSERT_MESSAGE("No LabelFillStyle set", aAny >>= eFillStyle);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("solid fill expected", drawing::FillStyle_SOLID, eFillStyle);
+
+ sal_Int32 nFillColor;
+ sal_Int32 nExpectedFillColor = 65280;
+ xPropSet->getPropertyValue("LabelFillColor") >>= nFillColor;
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("fill color green, 65280=#00FF00", nExpectedFillColor, nFillColor);
+}
+
+void Chart2GeometryTest::testTdf135366LabelOnPoint()
+{
+ // Error was, that the fill and line properties of a <chart:data-label> were not
+ // imported at all. Here they should be at point 2.
+ load("/chart2/qa/extras/data/odt/", "tdf135366_data_label_point.odt");
+ uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xChartDoc.is());
+ Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
+ CPPUNIT_ASSERT(xDataSeries.is());
+ Reference<beans::XPropertySet> xPropSet(xDataSeries->getDataPointByIndex(2),
+ uno::UNO_SET_THROW);
+ uno::Any aAny;
+
+ aAny = xPropSet->getPropertyValue("LabelBorderStyle");
+ drawing::LineStyle eLineStyle;
+ CPPUNIT_ASSERT_MESSAGE("No LabelBorderStyle set.", aAny >>= eLineStyle);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("solid line expected", drawing::LineStyle_SOLID, eLineStyle);
+
+ sal_Int32 nBorderWidth;
+ sal_Int32 nExpectedWidth = 381;
+ xPropSet->getPropertyValue("LabelBorderWidth") >>= nBorderWidth;
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("LabelBorderWidth", nExpectedWidth, nBorderWidth);
+
+ sal_Int32 nLineTransparency;
+ sal_Int32 nExpectedTransparency = 30;
+ xPropSet->getPropertyValue("LabelBorderTransparency") >>= nLineTransparency;
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("line transparency", nExpectedTransparency, nLineTransparency);
+
+ sal_Int32 nLineColor;
+ sal_Int32 nExpectedLineColor = 10206041;
+ xPropSet->getPropertyValue("LabelBorderColor") >>= nLineColor;
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("line color greenish, 10206041=#9BBB59", nExpectedLineColor,
+ nLineColor);
+
+ aAny = xPropSet->getPropertyValue("LabelFillStyle");
+ drawing::FillStyle eFillStyle;
+ CPPUNIT_ASSERT_MESSAGE("No LabelFillStyle set", aAny >>= eFillStyle);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("solid fill expected", drawing::FillStyle_SOLID, eFillStyle);
+
+ sal_Int32 nFillColor;
+ sal_Int32 nExpectedFillColor = 14277081;
+ xPropSet->getPropertyValue("LabelFillColor") >>= nFillColor;
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("fill color gray, 14277081=#d9d9d9", nExpectedFillColor,
+ nFillColor);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Chart2GeometryTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/chart2/qa/extras/data/ods/tdf135366_data_label_series.ods b/chart2/qa/extras/data/ods/tdf135366_data_label_series.ods
new file mode 100644
index 000000000000..e7c1f7d89de2
--- /dev/null
+++ b/chart2/qa/extras/data/ods/tdf135366_data_label_series.ods
Binary files differ
diff --git a/chart2/qa/extras/data/odt/tdf135366_data_label_point.odt b/chart2/qa/extras/data/odt/tdf135366_data_label_point.odt
new file mode 100644
index 000000000000..3c176a37adff
--- /dev/null
+++ b/chart2/qa/extras/data/odt/tdf135366_data_label_point.odt
Binary files differ