summaryrefslogtreecommitdiff
path: root/oox/source
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-07-23 15:49:11 -0400
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2014-07-30 21:46:30 +0000
commita7e5fc1485fc3a44a05168910430a57aee2b211e (patch)
tree22c1a69231b0bf0c227bd398249b62727b7f4de3 /oox/source
parent8e0c92c2ee46e90bdcceb641be267a9468968b0c (diff)
bnc#885825: OOXML import and export of data label borders.
(cherry picked from commit 48f31a924280a418046f0c816f8a7d20b672dac6) Conflicts: oox/source/export/chartexport.cxx Change-Id: I0fd808145aaeb0aa36d3ec30d7b977890642dcff Reviewed-on: https://gerrit.libreoffice.org/10562 Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'oox/source')
-rw-r--r--oox/source/drawingml/chart/seriesconverter.cxx28
-rw-r--r--oox/source/export/chartexport.cxx219
-rw-r--r--oox/source/token/properties.txt3
3 files changed, 113 insertions, 137 deletions
diff --git a/oox/source/drawingml/chart/seriesconverter.cxx b/oox/source/drawingml/chart/seriesconverter.cxx
index 0357114e0bfc..bcb8d609a40e 100644
--- a/oox/source/drawingml/chart/seriesconverter.cxx
+++ b/oox/source/drawingml/chart/seriesconverter.cxx
@@ -34,11 +34,13 @@
#include "oox/drawingml/chart/typegroupconverter.hxx"
#include "oox/drawingml/chart/typegroupmodel.hxx"
#include "oox/helper/containerhelper.hxx"
+#include <oox/drawingml/lineproperties.hxx>
namespace oox {
namespace drawingml {
namespace chart {
+using namespace com::sun::star;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::chart2;
using namespace ::com::sun::star::chart2::data;
@@ -162,6 +164,20 @@ void lclConvertLabelFormatting( PropertySet& rPropSet, ObjectFormatter& rFormatt
}
}
+void importBorderProperties( PropertySet& rPropSet, Shape& rShape, const GraphicHelper& rGraphicHelper )
+{
+ LineProperties& rLP = rShape.getLineProperties();
+ if (rLP.moLineWidth.has())
+ {
+ sal_Int32 nWidth = convertEmuToHmm(rLP.moLineWidth.get());
+ rPropSet.setProperty(PROP_LabelBorderWidth, uno::makeAny(nWidth));
+ rPropSet.setProperty(PROP_LabelBorderStyle, uno::makeAny(drawing::LineStyle_SOLID));
+ }
+ const Color& aColor = rLP.maLineFill.maFillColor;
+ sal_Int32 nColor = aColor.getColor(rGraphicHelper);
+ rPropSet.setProperty(PROP_LabelBorderColor, uno::makeAny(nColor));
+}
+
} // namespace
DataLabelConverter::DataLabelConverter( const ConverterRoot& rParent, DataLabelModel& rModel ) :
@@ -175,7 +191,10 @@ DataLabelConverter::~DataLabelConverter()
void DataLabelConverter::convertFromModel( const Reference< XDataSeries >& rxDataSeries, const TypeGroupConverter& rTypeGroup )
{
- if( rxDataSeries.is() ) try
+ if (!rxDataSeries.is())
+ return;
+
+ try
{
PropertySet aPropSet( rxDataSeries->getDataPointByIndex( mrModel.mnIndex ) );
lclConvertLabelFormatting( aPropSet, getFormatter(), mrModel, rTypeGroup, false );
@@ -201,6 +220,9 @@ void DataLabelConverter::convertFromModel( const Reference< XDataSeries >& rxDat
aPropSet.setProperty( PROP_LabelPlacement,
aPositionsLookupTable[ simplifiedX+1 + 3*(simplifiedY+1) ] );
}
+
+ if (mrModel.mxShapeProp)
+ importBorderProperties(aPropSet, *mrModel.mxShapeProp, getFilter().getGraphicHelper());
}
catch( Exception& )
{
@@ -222,6 +244,10 @@ void DataLabelsConverter::convertFromModel( const Reference< XDataSeries >& rxDa
{
PropertySet aPropSet( rxDataSeries );
lclConvertLabelFormatting( aPropSet, getFormatter(), mrModel, rTypeGroup, true );
+
+ if (mrModel.mxShapeProp)
+ // Import baseline border properties for these data labels.
+ importBorderProperties(aPropSet, *mrModel.mxShapeProp, getFilter().getGraphicHelper());
}
// data point label settings
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index 48c8fc5a5617..092909645ccb 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -1761,8 +1761,8 @@ void ChartExport::exportSeries( Reference< chart2::XChartType > xChartType, sal_
// export data labels
// Excel does not like our current data label export
// for scatter charts
- if( eChartType != chart::TYPEID_SCATTER && eChartType != chart::TYPEID_BAR )
- exportDataLabels( uno::Reference< beans::XPropertySet >( aSeriesSeq[nSeriesIdx], uno::UNO_QUERY ), nSeriesLength );
+ if( eChartType != chart::TYPEID_SCATTER )
+ exportDataLabels(aSeriesSeq[nSeriesIdx], nSeriesLength);
exportTrendlines( aSeriesSeq[nSeriesIdx] );
@@ -2536,156 +2536,103 @@ void ChartExport::_exportAxis(
pFS->endElement( FSNS( XML_c, nAxisType ) );
}
-void ChartExport::exportDataLabels(
- const uno::Reference< beans::XPropertySet > & xSeriesProperties,
- sal_Int32 nSeriesLength )
-{
- // TODO: export field separators, missing flag vs. showing series name or not
- uno::Reference< chart2::XDataSeries > xSeries( xSeriesProperties, uno::UNO_QUERY );
+namespace {
- if( xSeriesProperties.is())
+const char* toOOXMLPlacement( sal_Int32 nPlacement )
+{
+ switch (nPlacement)
{
- FSHelperPtr pFS = GetFS();
- pFS->startElement( FSNS( XML_c, XML_dLbls ),
- FSEND );
+ case css::chart::DataLabelPlacement::OUTSIDE: return "outEnd";
+ case css::chart::DataLabelPlacement::INSIDE: return "inEnd";
+ case css::chart::DataLabelPlacement::CENTER: return "ctr";
+ case css::chart::DataLabelPlacement::NEAR_ORIGIN: return "inBase";
+ case css::chart::DataLabelPlacement::TOP: return "t";
+ case css::chart::DataLabelPlacement::BOTTOM: return "b";
+ case css::chart::DataLabelPlacement::LEFT: return "l";
+ case css::chart::DataLabelPlacement::RIGHT: return "r";
+ case css::chart::DataLabelPlacement::AVOID_OVERLAP: return "bestFit";
+ default:
+ ;
+ }
- bool showLegendSymbol = false;
- bool showNumber = false;
- bool showCategoryName = false;
- bool showNumberInPercent = false;
+ return "outEnd";
+}
- sal_Int32 nElem = 0;
+void writeLabelProperties( FSHelperPtr pFS, const uno::Reference<beans::XPropertySet>& xPropSet )
+{
+ if (!xPropSet.is())
+ return;
+ chart2::DataPointLabel aLabel;
+ sal_Int32 nLabelPlacement = css::chart::DataLabelPlacement::OUTSIDE;
+ sal_Int32 nLabelBorderWidth = 0;
+ sal_Int32 nLabelBorderColor = 0x00FFFFFF;
- uno::Reference< beans::XPropertySet > xPropSet;
- if(nSeriesLength != 0)
- {
- try
- {
- xPropSet = SchXMLSeriesHelper::createOldAPIDataPointPropertySet(
- xSeries, nElem, getModel() );
- }
- catch( const uno::Exception & rEx )
- {
- SAL_WARN("oox", "Exception caught during Export of data label: " << rEx.Message );
- }
- }
+ xPropSet->getPropertyValue("Label") >>= aLabel;
+ xPropSet->getPropertyValue("LabelPlacement") >>= nLabelPlacement;
+ xPropSet->getPropertyValue("LabelBorderWidth") >>= nLabelBorderWidth;
+ xPropSet->getPropertyValue("LabelBorderColor") >>= nLabelBorderColor;
- namespace cssc2 = ::com::sun::star::chart2;
- cssc2::DataPointLabel aTempLabel;
- if( xPropSet.is() )
- {
- if (GetProperty( xPropSet, "Label"))
- mAny >>= aTempLabel;
- }
+ if (nLabelBorderWidth > 0)
+ {
+ pFS->startElement(FSNS(XML_c, XML_spPr), FSEND);
+ pFS->startElement(FSNS(XML_a, XML_ln), XML_w, IS(convertHmmToEmu(nLabelBorderWidth)), FSEND);
+ pFS->startElement(FSNS(XML_a, XML_solidFill), FSEND);
+ OString aStr = OString::number(nLabelBorderColor, 16).toAsciiUpperCase();
+ pFS->singleElement(FSNS(XML_a, XML_srgbClr), XML_val, aStr.getStr(), FSEND);
+ pFS->endElement(FSNS(XML_a, XML_solidFill));
+ pFS->endElement(FSNS(XML_a, XML_ln));
+ pFS->endElement(FSNS(XML_c, XML_spPr));
+ }
- for( nElem = 1; nElem < nSeriesLength; ++nElem)
- {
- try
- {
- xPropSet = SchXMLSeriesHelper::createOldAPIDataPointPropertySet(
- xSeries, nElem, getModel() );
- }
- catch( const uno::Exception & rEx )
- {
- SAL_WARN("oox", "Exception caught during Export of data label: " << rEx.Message );
- }
+ 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);
+ pFS->singleElement(FSNS(XML_c, XML_showSerName), XML_val, BS(false), FSEND);
+ pFS->singleElement(FSNS(XML_c, XML_showPercent), XML_val, BS(aLabel.ShowNumberInPercent), FSEND);
+}
- if( xPropSet.is() )
- {
- namespace cssc2 = ::com::sun::star::chart2;
- cssc2::DataPointLabel aLabel;
- if (GetProperty( xPropSet, "Label"))
- {
- mAny >>= aLabel;
-
- namespace csscd = ::com::sun::star::chart::DataLabelPlacement;
- sal_Int32 nPlacement(csscd::AVOID_OVERLAP);
- const char *aPlacement = NULL;
- OUString aSep;
-
- if (GetProperty( xPropSet, "LabelPlacement"))
- mAny >>= nPlacement;
-
- switch( nPlacement )
- {
- case csscd::OUTSIDE: aPlacement = "outEnd"; break;
- case csscd::INSIDE: aPlacement = "inEnd"; break;
- case csscd::CENTER: aPlacement = "ctr"; break;
- case csscd::NEAR_ORIGIN: aPlacement = "inBase"; break;
- case csscd::TOP: aPlacement = "t"; break;
- case csscd::BOTTOM: aPlacement = "b"; break;
- case csscd::LEFT: aPlacement = "l"; break;
- case csscd::RIGHT: aPlacement = "r"; break;
- case csscd::AVOID_OVERLAP: aPlacement = "bestFit"; break;
- }
-
- if (aLabel.ShowLegendSymbol)
- showLegendSymbol = true;
- if(aLabel.ShowNumber)
- showNumber = true;
- if(aLabel.ShowCategoryName)
- showCategoryName = true;
- if(aLabel.ShowNumberInPercent)
- showNumberInPercent = true;
-
- if(aTempLabel.ShowLegendSymbol != aLabel.ShowLegendSymbol || aTempLabel.ShowNumber!= aLabel.ShowNumber ||
- aTempLabel.ShowCategoryName != aLabel.ShowCategoryName || aTempLabel.ShowNumberInPercent != aLabel.ShowNumberInPercent)
- {
- pFS->startElement( FSNS( XML_c, XML_dLbl ), FSEND);
- pFS->singleElement( FSNS( XML_c, XML_idx), XML_val, I32S(nElem), FSEND);
- pFS->singleElement( FSNS( XML_c, XML_dLblPos), XML_val, aPlacement, FSEND);
-
- if(aTempLabel.ShowLegendSymbol != aLabel.ShowLegendSymbol)
- {
- pFS->singleElement( FSNS( XML_c, XML_showLegendKey), XML_val, aLabel.ShowLegendSymbol ? "1": "0", FSEND);
- }
-
- if (aTempLabel.ShowNumber!= aLabel.ShowNumber)
- {
- pFS->singleElement( FSNS( XML_c, XML_showVal), XML_val,aLabel.ShowNumber ? "1": "0", FSEND);
- }
-
-
- if(aTempLabel.ShowCategoryName != aLabel.ShowCategoryName)
- {
- pFS->singleElement( FSNS( XML_c, XML_showCatName), XML_val, aLabel.ShowCategoryName ? "1": "0", FSEND);
- }
- // MSO somehow assumes series name to be on (=displayed) by default.
- // Let's put false here and switch it off then, since we have no UI means
- // in LibO to toggle it on anyway
- pFS->singleElement( FSNS( XML_c, XML_showSerName), XML_val, "0", FSEND);
-
- if(aTempLabel.ShowNumberInPercent != aLabel.ShowNumberInPercent)
- {
- pFS->singleElement( FSNS( XML_c, XML_showPercent), XML_val,aLabel.ShowNumberInPercent ? "1": "0", FSEND);
- }
-
- if (GetProperty( xPropSet, "LabelSeparator"))
- {
- mAny >>= aSep;
- pFS->startElement( FSNS( XML_c, XML_separator), FSEND);
- pFS->writeEscaped(aSep);
- pFS->endElement( FSNS( XML_c, XML_separator) );
- }
- pFS->endElement( FSNS( XML_c, XML_dLbl ));
- }
- }
- }
- }
+}
- pFS->singleElement( FSNS( XML_c, XML_showLegendKey), XML_val, showLegendSymbol ? "1": "0", FSEND);
- pFS->singleElement( FSNS( XML_c, XML_showVal), XML_val, showNumber ? "1": "0", FSEND);
- pFS->singleElement( FSNS( XML_c, XML_showCatName), XML_val, showCategoryName ? "1": "0", FSEND);
+void ChartExport::exportDataLabels( const uno::Reference<chart2::XDataSeries> & xSeries,
+ sal_Int32 nSeriesLength )
+{
+ if (!xSeries.is() || nSeriesLength <= 0)
+ return;
- pFS->singleElement( FSNS( XML_c, XML_showSerName), XML_val, "0", FSEND);
+ uno::Reference<beans::XPropertySet> xPropSet(xSeries, uno::UNO_QUERY);
+ if (!xPropSet.is())
+ return;
+
+ FSHelperPtr pFS = GetFS();
+ pFS->startElement(FSNS(XML_c, XML_dLbls), FSEND);
- pFS->singleElement( FSNS( XML_c, XML_showPercent), XML_val, showNumberInPercent ? "1": "0", FSEND);
+ uno::Sequence<sal_Int32> aAttrLabelIndices;
+ xPropSet->getPropertyValue("AttributedDataPoints") >>= aAttrLabelIndices;
- pFS->endElement( FSNS( XML_c, XML_dLbls ) );
+ const sal_Int32* p = aAttrLabelIndices.getConstArray();
+ const sal_Int32* pEnd = p + aAttrLabelIndices.getLength();
+ for (; p != pEnd; ++p)
+ {
+ sal_Int32 nIdx = *p;
+ uno::Reference<beans::XPropertySet> xLabelPropSet = xSeries->getDataPointByIndex(nIdx);
+ if (!xLabelPropSet.is())
+ continue;
+
+ // Individual label property thhat 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);
+ pFS->endElement(FSNS(XML_c, XML_dLbl));
}
+
+ // Baseline label properties for all labels.
+ writeLabelProperties(pFS, xPropSet);
+
+ pFS->endElement(FSNS(XML_c, XML_dLbls));
}
void ChartExport::exportDataPoints(
diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt
index 44c759715975..988857b257c7 100644
--- a/oox/source/token/properties.txt
+++ b/oox/source/token/properties.txt
@@ -273,6 +273,9 @@ IterationCount
IterationEpsilon
Japanese
Label
+LabelBorderColor
+LabelBorderStyle
+LabelBorderWidth
LabelPlacement
LabelPosition
LabelSeparator