summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-08-07 14:17:11 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-08-07 14:22:11 -0400
commitfb1473692e9be2093924ab4df7c982dc282af18f (patch)
treec95015701551eecd86df35e7527c5a497b89c811 /oox
parent844d143905411ef9d3a1fce2fc448b29f643500d (diff)
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
Diffstat (limited to 'oox')
-rw-r--r--oox/inc/drawingml/chart/typegroupconverter.hxx2
-rw-r--r--oox/source/drawingml/chart/typegroupconverter.cxx5
-rw-r--r--oox/source/export/chartexport.cxx37
3 files changed, 32 insertions, 12 deletions
diff --git a/oox/inc/drawingml/chart/typegroupconverter.hxx b/oox/inc/drawingml/chart/typegroupconverter.hxx
index c4930e7c9216..6c5e85522037 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 36fd0eca083b..3a23d4431196 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 389485e234f3..027a566bf2a3 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));
}