[Libreoffice-commits] core.git: 2 commits - chart2/qa include/oox oox/source
Kohei Yoshida
kohei.yoshida at collabora.com
Tue Aug 5 10:26:46 PDT 2014
chart2/qa/extras/chart2export.cxx | 18 ++++++++++++++++
chart2/qa/extras/data/docx/3d-bar-label.docx |binary
include/oox/export/chartexport.hxx | 2 -
oox/source/export/chartexport.cxx | 29 +++++++++++++++++----------
4 files changed, 38 insertions(+), 11 deletions(-)
New commits:
commit 2f247407662922fe84bcc0e2aac3372d9ca1cb7b
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Tue Aug 5 11:44:21 2014 -0400
Add test to ensure that we don't export label position attributes.
At least for 3D bar chart, exporting this would choke MS Office.
Change-Id: Ic6747f3c5502495d8cae734290183ff89b14fc70
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index 1beb411..67d25f9 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -70,6 +70,7 @@ public:
void testFdo78290CombinationChartMarkerX();
void testAxisNumberFormatODS();
void testDataLabelBordersDOCX();
+ void testDataLabel3DChartDOCX();
CPPUNIT_TEST_SUITE(Chart2ExportTest);
CPPUNIT_TEST(test);
@@ -105,6 +106,7 @@ public:
CPPUNIT_TEST(testFdo78290CombinationChartMarkerX);
CPPUNIT_TEST(testAxisNumberFormatODS);
CPPUNIT_TEST(testDataLabelBordersDOCX);
+ CPPUNIT_TEST(testDataLabel3DChartDOCX);
CPPUNIT_TEST_SUITE_END();
protected:
@@ -802,6 +804,22 @@ void Chart2ExportTest::testDataLabelBordersDOCX()
aTest.checkObject2(xChartDoc);
}
+void Chart2ExportTest::testDataLabel3DChartDOCX()
+{
+ load("/chart2/qa/extras/data/docx/", "3d-bar-label.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 3D bar charts. The
+ // same rule also applies to several other 3D charts, apparently.
+ assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:dLblPos", 0);
+ assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/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/3d-bar-label.docx b/chart2/qa/extras/data/docx/3d-bar-label.docx
new file mode 100755
index 0000000..69cab8e
Binary files /dev/null and b/chart2/qa/extras/data/docx/3d-bar-label.docx differ
commit bb13f1a063c8934325929ff5b1944814bc2cb023
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Tue Aug 5 10:15:28 2014 -0400
Avoid exporting label placement property when the chart is 3D.
MS Office has trouble loading the file if you do. There is an exception,
however. A pie chart allows label placement option even when 3D. There
may be other chart types that allow variable label placement when 3D.
Change-Id: I6a9247041ca6ee3ae1b9c245f5919fcb35951f24
diff --git a/include/oox/export/chartexport.hxx b/include/oox/export/chartexport.hxx
index 8d570ec..7eb7e81 100644
--- a/include/oox/export/chartexport.hxx
+++ b/include/oox/export/chartexport.hxx
@@ -157,7 +157,7 @@ private:
void exportDataPoints(
const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesProperties,
sal_Int32 nSeriesLength );
- void exportDataLabels( const css::uno::Reference<css::chart2::XDataSeries>& xSeries, sal_Int32 nSeriesLength );
+ void exportDataLabels( const css::uno::Reference<css::chart2::XDataSeries>& xSeries, sal_Int32 nSeriesLength, sal_Int32 eChartType );
void exportGrouping( bool isBar = false );
void exportTrendlines( ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > xSeries );
void exportMarker( ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > xSeries );
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index 2d4555f..66df939 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -1761,7 +1761,7 @@ void ChartExport::exportSeries( Reference< chart2::XChartType > xChartType, sal_
// Excel does not like our current data label export
// for scatter charts
if( eChartType != chart::TYPEID_SCATTER )
- exportDataLabels(aSeriesSeq[nSeriesIdx], nSeriesLength);
+ exportDataLabels(aSeriesSeq[nSeriesIdx], nSeriesLength, eChartType);
exportTrendlines( aSeriesSeq[nSeriesIdx] );
@@ -2555,18 +2555,17 @@ const char* toOOXMLPlacement( sal_Int32 nPlacement )
return "outEnd";
}
-void writeLabelProperties( FSHelperPtr pFS, const uno::Reference<beans::XPropertySet>& xPropSet )
+void writeLabelProperties(
+ FSHelperPtr pFS, const uno::Reference<beans::XPropertySet>& xPropSet, bool bLabelPlacement )
{
if (!xPropSet.is())
return;
chart2::DataPointLabel aLabel;
- sal_Int32 nLabelPlacement = css::chart::DataLabelPlacement::OUTSIDE;
sal_Int32 nLabelBorderWidth = 0;
sal_Int32 nLabelBorderColor = 0x00FFFFFF;
xPropSet->getPropertyValue("Label") >>= aLabel;
- xPropSet->getPropertyValue("LabelPlacement") >>= nLabelPlacement;
xPropSet->getPropertyValue("LabelBorderWidth") >>= nLabelBorderWidth;
xPropSet->getPropertyValue("LabelBorderColor") >>= nLabelBorderColor;
@@ -2584,7 +2583,13 @@ void writeLabelProperties( FSHelperPtr pFS, const uno::Reference<beans::XPropert
pFS->endElement(FSNS(XML_c, XML_spPr));
}
- pFS->singleElement(FSNS(XML_c, XML_dLblPos), XML_val, toOOXMLPlacement(nLabelPlacement), FSEND);
+ if (bLabelPlacement)
+ {
+ sal_Int32 nLabelPlacement = css::chart::DataLabelPlacement::OUTSIDE;
+ 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);
pFS->singleElement(FSNS(XML_c, XML_showVal), XML_val, BS(aLabel.ShowNumber), FSEND);
pFS->singleElement(FSNS(XML_c, XML_showCatName), XML_val, BS(aLabel.ShowCategoryName), FSEND);
@@ -2594,8 +2599,8 @@ void writeLabelProperties( FSHelperPtr pFS, const uno::Reference<beans::XPropert
}
-void ChartExport::exportDataLabels( const uno::Reference<chart2::XDataSeries> & xSeries,
- sal_Int32 nSeriesLength )
+void ChartExport::exportDataLabels(
+ const uno::Reference<chart2::XDataSeries> & xSeries, sal_Int32 nSeriesLength, sal_Int32 eChartType )
{
if (!xSeries.is() || nSeriesLength <= 0)
return;
@@ -2610,6 +2615,10 @@ void ChartExport::exportDataLabels( const uno::Reference<chart2::XDataSeries> &
uno::Sequence<sal_Int32> aAttrLabelIndices;
xPropSet->getPropertyValue("AttributedDataPoints") >>= aAttrLabelIndices;
+ bool bLabelPlacement = !mbIs3DChart;
+ if (eChartType == chart::TYPEID_PIE)
+ bLabelPlacement = true;
+
const sal_Int32* p = aAttrLabelIndices.getConstArray();
const sal_Int32* pEnd = p + aAttrLabelIndices.getLength();
for (; p != pEnd; ++p)
@@ -2619,15 +2628,15 @@ void ChartExport::exportDataLabels( const uno::Reference<chart2::XDataSeries> &
if (!xLabelPropSet.is())
continue;
- // Individual label property thhat overwrites the baseline.
+ // 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);
+ writeLabelProperties(pFS, xLabelPropSet, bLabelPlacement);
pFS->endElement(FSNS(XML_c, XML_dLbl));
}
// Baseline label properties for all labels.
- writeLabelProperties(pFS, xPropSet);
+ writeLabelProperties(pFS, xPropSet, bLabelPlacement);
pFS->endElement(FSNS(XML_c, XML_dLbls));
}
More information about the Libreoffice-commits
mailing list