chart2/qa/extras/chart2export.cxx                       |   19 ++++++++++++++++
 chart2/qa/extras/data/xlsx/testCustomPosDataLabels.xlsx |binary
 oox/source/export/chartexport.cxx                       |   19 ++++++++++++++++
 3 files changed, 38 insertions(+)

New commits:
commit 5339d0800ccdcd325294e61f8ae9e67648beb035
Author:     Balazs Varga <balazs.varga...@gmail.com>
AuthorDate: Mon Feb 10 14:22:11 2020 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Mon Feb 17 17:58:40 2020 +0100

    tdf#130590 Chart OOXML export: fix custom label position
    
    in case of all chart types except pie chart.
    
    Follow-up of commit 4223ff2be69f03e571464b0b09ad0d278918631b
    (tdf#48436 Chart: add CustomLabelPosition UNO API property)
    
    Change-Id: I3ff1ca13928315f27988ae27c462a2f05354bc49
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88371
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/chart2/qa/extras/chart2export.cxx 
b/chart2/qa/extras/chart2export.cxx
index 1ff1064046e1..b9d5873052ba 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -134,6 +134,7 @@ public:
     void testAxisCrossBetweenXSLX();
     void testPieChartDataPointExplosionXLSX();
     void testCustomDataLabel();
+    void testCustomPositionofDataLabel();
     void testCustomDataLabelMultipleSeries();
     void testNumberFormatExportPPTX();
     void testLabelSeparatorExportDOCX();
@@ -251,6 +252,7 @@ public:
     CPPUNIT_TEST(testAxisCrossBetweenXSLX);
     CPPUNIT_TEST(testPieChartDataPointExplosionXLSX);
     CPPUNIT_TEST(testCustomDataLabel);
+    CPPUNIT_TEST(testCustomPositionofDataLabel);
     CPPUNIT_TEST(testCustomDataLabelMultipleSeries);
     CPPUNIT_TEST(testNumberFormatExportPPTX);
     CPPUNIT_TEST(testLabelSeparatorExportDOCX);
@@ -2170,6 +2172,23 @@ void Chart2ExportTest::testCustomDataLabel()
     CPPUNIT_ASSERT_EQUAL(OUString(" <CELLREF"), aFields[1]->getString());
 }
 
+void Chart2ExportTest::testCustomPositionofDataLabel()
+{
+    load("/chart2/qa/extras/data/xlsx/", "testCustomPosDataLabels.xlsx");
+    xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
+    CPPUNIT_ASSERT(pXmlDoc);
+
+    // test custom position of data label
+    assertXPath(pXmlDoc, 
"/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/c:dLbl[1]/c:idx", 
"val", "2");
+    OUString aXVal = getXPath(pXmlDoc, 
"/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/c:dLbl[1]/c:layout/c:manualLayout/c:x",
 "val");
+    double nX = aXVal.toDouble();
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.11027682973075476, nX, 1e-7);
+
+    OUString aYVal = getXPath(pXmlDoc, 
"/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/c:dLbl[1]/c:layout/c:manualLayout/c:y",
 "val");
+    double nY = aYVal.toDouble();
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.0742140311063737, nY, 1e-7);
+}
+
 void Chart2ExportTest::testCustomDataLabelMultipleSeries()
 {
     load("/chart2/qa/extras/data/pptx/", "tdf115107-2.pptx");
diff --git a/chart2/qa/extras/data/xlsx/testCustomPosDataLabels.xlsx 
b/chart2/qa/extras/data/xlsx/testCustomPosDataLabels.xlsx
new file mode 100644
index 000000000000..caa08956cd27
Binary files /dev/null and 
b/chart2/qa/extras/data/xlsx/testCustomPosDataLabels.xlsx differ
diff --git a/oox/source/export/chartexport.cxx 
b/oox/source/export/chartexport.cxx
index 8debc8d047c3..ae33fdcdd222 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -3416,6 +3416,25 @@ void ChartExport::exportDataLabels(
         pFS->startElement(FSNS(XML_c, XML_dLbl));
         pFS->singleElement(FSNS(XML_c, XML_idx), XML_val, 
OString::number(nIdx));
 
+        // export custom position of data label
+        if( eChartType != chart::TYPEID_PIE )
+        {
+            chart2::RelativePosition aCustomLabelPosition;
+            if( xLabelPropSet->getPropertyValue("CustomLabelPosition") >>= 
aCustomLabelPosition )
+            {
+                pFS->startElement(FSNS(XML_c, XML_layout));
+                pFS->startElement(FSNS(XML_c, XML_manualLayout));
+
+                pFS->singleElement(FSNS(XML_c, XML_x), XML_val, 
OString::number(aCustomLabelPosition.Primary));
+                pFS->singleElement(FSNS(XML_c, XML_y), XML_val, 
OString::number(aCustomLabelPosition.Secondary));
+
+                SAL_WARN_IF(aCustomLabelPosition.Anchor != 
css::drawing::Alignment_TOP_LEFT, "oox", "unsupported anchor position");
+
+                pFS->endElement(FSNS(XML_c, XML_manualLayout));
+                pFS->endElement(FSNS(XML_c, XML_layout));
+            }
+        }
+
         if( xLabelPropSet->getPropertyValue("Label") >>= aLabel )
             bLabelIsNumberFormat = aLabel.ShowNumber;
         else
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to