[Libreoffice-commits] core.git: 4 commits - chart2/qa oox/inc oox/source

Kohei Yoshida kohei.yoshida at collabora.com
Thu Aug 7 11:22:32 PDT 2014


 chart2/qa/extras/chart2export.cxx                                  |   42 ++++++++
 chart2/qa/extras/charttest.hxx                                     |    1 
 chart2/qa/extras/data/docx/doughnut-chart-labels.docx              |binary
 chart2/qa/extras/data/docx/line-chart-label-default-placement.docx |binary
 oox/inc/drawingml/chart/typegroupconverter.hxx                     |    2 
 oox/source/drawingml/chart/typegroupconverter.cxx                  |    5 +
 oox/source/export/chartexport.cxx                                  |   48 +++++++---
 7 files changed, 88 insertions(+), 10 deletions(-)

New commits:
commit fb1473692e9be2093924ab4df7c982dc282af18f
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Thu Aug 7 14:17:11 2014 -0400

    Default data label placement may vary depending on chart types.  Get it right.
    
    If we export a wrong placement value, MS Office will flag the file corrupt and
    the loading will fail.
    
    Change-Id: I7ca1239cd390494c1181ecdb3310c5f88bb18f9b

diff --git a/oox/inc/drawingml/chart/typegroupconverter.hxx b/oox/inc/drawingml/chart/typegroupconverter.hxx
index c4930e7..6c5e855 100644
--- a/oox/inc/drawingml/chart/typegroupconverter.hxx
+++ b/oox/inc/drawingml/chart/typegroupconverter.hxx
@@ -93,6 +93,8 @@ struct TypeGroupInfo
     bool                mbPictureOptions;       /// True = bitmaps support options from c:pictureOptions.
 };
 
+const TypeGroupInfo& GetTypeGroupInfo( TypeId eType );
+
 struct UpDownBarsModel;
 
 class UpDownBarsConverter : public ConverterBase< UpDownBarsModel >
diff --git a/oox/source/drawingml/chart/typegroupconverter.cxx b/oox/source/drawingml/chart/typegroupconverter.cxx
index 36fd0ec..3a23d44 100644
--- a/oox/source/drawingml/chart/typegroupconverter.cxx
+++ b/oox/source/drawingml/chart/typegroupconverter.cxx
@@ -96,6 +96,11 @@ const TypeGroupInfo& lclGetTypeInfoFromTypeId( TypeId eTypeId )
 
 } // namespace
 
+const TypeGroupInfo& GetTypeGroupInfo( TypeId eType )
+{
+    return lclGetTypeInfoFromTypeId(eType);
+}
+
 UpDownBarsConverter::UpDownBarsConverter( const ConverterRoot& rParent, UpDownBarsModel& rModel ) :
     ConverterBase< UpDownBarsModel >( rParent, rModel )
 {
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index 389485e..027a566 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -2535,6 +2535,16 @@ void ChartExport::_exportAxis(
 
 namespace {
 
+struct LabelPlacementParam
+{
+    bool mbExport;
+    sal_Int32 meDefault;
+
+    LabelPlacementParam() :
+        mbExport(true),
+        meDefault(css::chart::DataLabelPlacement::OUTSIDE) {}
+};
+
 const char* toOOXMLPlacement( sal_Int32 nPlacement )
 {
     switch (nPlacement)
@@ -2556,7 +2566,7 @@ const char* toOOXMLPlacement( sal_Int32 nPlacement )
 }
 
 void writeLabelProperties(
-    FSHelperPtr pFS, const uno::Reference<beans::XPropertySet>& xPropSet, bool bLabelPlacement )
+    FSHelperPtr pFS, const uno::Reference<beans::XPropertySet>& xPropSet, const LabelPlacementParam& rLabelParam )
 {
     if (!xPropSet.is())
         return;
@@ -2583,11 +2593,11 @@ void writeLabelProperties(
         pFS->endElement(FSNS(XML_c, XML_spPr));
     }
 
-    if (bLabelPlacement)
+    if (rLabelParam.mbExport)
     {
-        sal_Int32 nLabelPlacement = css::chart::DataLabelPlacement::OUTSIDE;
-        xPropSet->getPropertyValue("LabelPlacement") >>= nLabelPlacement;
-        pFS->singleElement(FSNS(XML_c, XML_dLblPos), XML_val, toOOXMLPlacement(nLabelPlacement), FSEND);
+        sal_Int32 nLabelPlacement = rLabelParam.meDefault;
+        if (xPropSet->getPropertyValue("LabelPlacement") >>= nLabelPlacement)
+            pFS->singleElement(FSNS(XML_c, XML_dLblPos), XML_val, toOOXMLPlacement(nLabelPlacement), FSEND);
     }
 
     pFS->singleElement(FSNS(XML_c, XML_showLegendKey), XML_val, BS(aLabel.ShowLegendSymbol), FSEND);
@@ -2618,17 +2628,20 @@ void ChartExport::exportDataLabels(
     // We must not export label placement property when the chart type doesn't
     // support this option in MS Office, else MS Office would think the file
     // is corrupt & refuse to open it.
-    bool bLabelPlacement = !mbIs3DChart;
-    eChartType = getChartType();
-    switch (eChartType)
+
+    const chart::TypeGroupInfo& rInfo = chart::GetTypeGroupInfo(static_cast<chart::TypeId>(eChartType));
+    LabelPlacementParam aParam;
+    aParam.mbExport = !mbIs3DChart;
+    aParam.meDefault = rInfo.mnDefLabelPos;
+    switch (getChartType()) // diagram chart type
     {
         case chart::TYPEID_PIE:
             // All pie charts support label placement.
-            bLabelPlacement = true;
+            aParam.mbExport = true;
         break;
         case chart::TYPEID_DOUGHNUT:
             // Doughnut charts don't support label placement.
-            bLabelPlacement = false;
+            aParam.mbExport = false;
         break;
         default:
             ;
@@ -2646,12 +2659,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, bLabelPlacement);
+        writeLabelProperties(pFS, xLabelPropSet, aParam);
         pFS->endElement(FSNS(XML_c, XML_dLbl));
     }
 
     // Baseline label properties for all labels.
-    writeLabelProperties(pFS, xPropSet, bLabelPlacement);
+    writeLabelProperties(pFS, xPropSet, aParam);
 
     pFS->endElement(FSNS(XML_c, XML_dLbls));
 }
commit 844d143905411ef9d3a1fce2fc448b29f643500d
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Thu Aug 7 14:16:22 2014 -0400

    Add test for default data label placement for line chart.
    
    Change-Id: I25cf48703a286470907ccc5415a0fab479aa4b8c

diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index 4d51dc4..2ebfd9d 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -72,6 +72,7 @@ public:
     void testDataLabelBordersDOCX();
     void testDataLabel3DChartDOCX();
     void testDataLabelDoughnutChartDOCX();
+    void testDataLabelDefaultLineChartDOCX();
 
     CPPUNIT_TEST_SUITE(Chart2ExportTest);
     CPPUNIT_TEST(test);
@@ -109,6 +110,7 @@ public:
     CPPUNIT_TEST(testDataLabelBordersDOCX);
     CPPUNIT_TEST(testDataLabel3DChartDOCX);
     CPPUNIT_TEST(testDataLabelDoughnutChartDOCX);
+    CPPUNIT_TEST(testDataLabelDefaultLineChartDOCX);
     CPPUNIT_TEST_SUITE_END();
 
 protected:
@@ -837,6 +839,29 @@ void Chart2ExportTest::testDataLabelDoughnutChartDOCX()
     assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:doughnutChart/c:ser/c:dLbls/c:dLbl/c:dLblPos", 0);
 }
 
+void Chart2ExportTest::testDataLabelDefaultLineChartDOCX()
+{
+    // This file was created by Word 2007, which doesn't provide default data
+    // label position (2010 does).  Make sure its default data label position
+    // is RIGHT when exporting.
+
+    load("/chart2/qa/extras/data/docx/", "line-chart-label-default-placement.docx");
+
+    Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xChartDoc.is());
+
+    reload("Office Open XML Text");
+
+    xChartDoc.set(getChartDocFromWriter(0), uno::UNO_QUERY);
+    Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
+    Reference<beans::XPropertySet> xPropSet(xDataSeries, uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xPropSet.is());
+    sal_Int32 nLabelPlacement = -1;
+    if (xPropSet->getPropertyValue("LabelPlacement") >>= nLabelPlacement)
+        // This option may not be set.  Check its value only when it's set.
+        CPPUNIT_ASSERT_MESSAGE("Line chart's default label placement should be 'right'.", nLabelPlacement == chart::DataLabelPlacement::RIGHT);
+}
+
 void Chart2ExportTest::testBarChartRotation()
 {
     load ("/chart2/qa/extras/data/docx/", "barChartRotation.docx");
diff --git a/chart2/qa/extras/charttest.hxx b/chart2/qa/extras/charttest.hxx
index d9c022d..a76a76c 100644
--- a/chart2/qa/extras/charttest.hxx
+++ b/chart2/qa/extras/charttest.hxx
@@ -44,6 +44,7 @@
 #include <com/sun/star/chart2/data/XDataSource.hpp>
 #include <com/sun/star/chart/XChartDataArray.hpp>
 #include <com/sun/star/chart/XComplexDescriptionAccess.hpp>
+#include <com/sun/star/chart/DataLabelPlacement.hpp>
 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
 #include <com/sun/star/drawing/FillStyle.hpp>
diff --git a/chart2/qa/extras/data/docx/line-chart-label-default-placement.docx b/chart2/qa/extras/data/docx/line-chart-label-default-placement.docx
new file mode 100755
index 0000000..ab9548d
Binary files /dev/null and b/chart2/qa/extras/data/docx/line-chart-label-default-placement.docx differ
commit ed39df130c6319409eb78eb5e9f03a070120c9d8
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Thu Aug 7 11:36:46 2014 -0400

    Doughnut charts don't support label placement option. Don't export it.
    
    Change-Id: I6d0e2c099869120bdf594813468a3c5ba4bb46fd

diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index 66df939..389485e 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -2615,9 +2615,24 @@ void ChartExport::exportDataLabels(
     uno::Sequence<sal_Int32> aAttrLabelIndices;
     xPropSet->getPropertyValue("AttributedDataPoints") >>= aAttrLabelIndices;
 
+    // We must not export label placement property when the chart type doesn't
+    // support this option in MS Office, else MS Office would think the file
+    // is corrupt & refuse to open it.
     bool bLabelPlacement = !mbIs3DChart;
-    if (eChartType == chart::TYPEID_PIE)
-        bLabelPlacement = true;
+    eChartType = getChartType();
+    switch (eChartType)
+    {
+        case chart::TYPEID_PIE:
+            // All pie charts support label placement.
+            bLabelPlacement = true;
+        break;
+        case chart::TYPEID_DOUGHNUT:
+            // Doughnut charts don't support label placement.
+            bLabelPlacement = false;
+        break;
+        default:
+            ;
+    }
 
     const sal_Int32* p = aAttrLabelIndices.getConstArray();
     const sal_Int32* pEnd = p + aAttrLabelIndices.getLength();
commit 96f890c63848db2975585a3fb5ae30e397c6add8
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Thu Aug 7 10:40:18 2014 -0400

    Write test for doughnut chart export of data labels to OOXML.
    
    We must not export label position properties for doughnut charts, else
    MS Office would think the file is corrupt.
    
    Change-Id: Icfab257ffb6da945b8add661e6455aa66cc475ab

diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index 67d25f9..4d51dc4 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -71,6 +71,7 @@ public:
     void testAxisNumberFormatODS();
     void testDataLabelBordersDOCX();
     void testDataLabel3DChartDOCX();
+    void testDataLabelDoughnutChartDOCX();
 
     CPPUNIT_TEST_SUITE(Chart2ExportTest);
     CPPUNIT_TEST(test);
@@ -107,6 +108,7 @@ public:
     CPPUNIT_TEST(testAxisNumberFormatODS);
     CPPUNIT_TEST(testDataLabelBordersDOCX);
     CPPUNIT_TEST(testDataLabel3DChartDOCX);
+    CPPUNIT_TEST(testDataLabelDoughnutChartDOCX);
     CPPUNIT_TEST_SUITE_END();
 
 protected:
@@ -820,6 +822,21 @@ void Chart2ExportTest::testDataLabel3DChartDOCX()
     assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:dLbl/c:dLblPos", 0);
 }
 
+void Chart2ExportTest::testDataLabelDoughnutChartDOCX()
+{
+    load("/chart2/qa/extras/data/docx/", "doughnut-chart-labels.docx");
+
+    Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xChartDoc.is());
+
+    xmlDocPtr pXmlDoc = parseExport("word/charts/chart","Office Open XML Text");
+    CPPUNIT_ASSERT(pXmlDoc);
+
+    // We must not export label position attributes for doughnut charts.
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:doughnutChart/c:ser/c:dLbls/c:dLblPos", 0);
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:doughnutChart/c:ser/c:dLbls/c:dLbl/c:dLblPos", 0);
+}
+
 void Chart2ExportTest::testBarChartRotation()
 {
     load ("/chart2/qa/extras/data/docx/", "barChartRotation.docx");
diff --git a/chart2/qa/extras/data/docx/doughnut-chart-labels.docx b/chart2/qa/extras/data/docx/doughnut-chart-labels.docx
new file mode 100755
index 0000000..5592085
Binary files /dev/null and b/chart2/qa/extras/data/docx/doughnut-chart-labels.docx differ


More information about the Libreoffice-commits mailing list