summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--oox/qa/unit/data/chart-data-label-char-color.docxbin0 -> 26014 bytes
-rw-r--r--oox/qa/unit/drawingml.cxx43
-rw-r--r--oox/source/drawingml/chart/seriesconverter.cxx37
-rw-r--r--xmloff/source/chart/SchXMLSeries2Context.cxx20
4 files changed, 100 insertions, 0 deletions
diff --git a/oox/qa/unit/data/chart-data-label-char-color.docx b/oox/qa/unit/data/chart-data-label-char-color.docx
new file mode 100644
index 000000000000..0e389f9237c4
--- /dev/null
+++ b/oox/qa/unit/data/chart-data-label-char-color.docx
Binary files differ
diff --git a/oox/qa/unit/drawingml.cxx b/oox/qa/unit/drawingml.cxx
index e1400c7bfe0c..ee5ae764af70 100644
--- a/oox/qa/unit/drawingml.cxx
+++ b/oox/qa/unit/drawingml.cxx
@@ -17,6 +17,11 @@
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/drawing/EnhancedCustomShapeAdjustmentValue.hpp>
+#include <com/sun/star/chart2/XChartDocument.hpp>
+#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
+#include <com/sun/star/chart2/XChartTypeContainer.hpp>
+#include <com/sun/star/chart2/XDataSeriesContainer.hpp>
+#include <com/sun/star/chart2/XDataPointCustomLabelField.hpp>
#include <unotools/mediadescriptor.hxx>
#include <unotools/tempfile.hxx>
@@ -156,6 +161,44 @@ CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testPresetAdjustValue)
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(11587), aAdjustmentSeq[0].Value.get<sal_Int32>());
}
+CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testChartDataLabelCharColor)
+{
+ OUString aURL
+ = m_directories.getURLFromSrc(DATA_DIRECTORY) + "chart-data-label-char-color.docx";
+ load(aURL);
+
+ uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+ uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+ uno::Reference<chart2::XChartDocument> xModel(xShape->getPropertyValue("Model"),
+ uno::UNO_QUERY);
+ uno::Reference<chart2::XCoordinateSystemContainer> xDiagram(xModel->getFirstDiagram(),
+ uno::UNO_QUERY);
+
+ uno::Reference<chart2::XChartTypeContainer> xCoordinateSystem(
+ xDiagram->getCoordinateSystems()[0], uno::UNO_QUERY);
+
+ uno::Reference<chart2::XDataSeriesContainer> xChartType(xCoordinateSystem->getChartTypes()[0],
+ uno::UNO_QUERY);
+
+ uno::Reference<chart2::XDataSeries> xDataSeries = xChartType->getDataSeries()[0];
+
+ uno::Reference<beans::XPropertySet> xDataPoint = xDataSeries->getDataPointByIndex(0);
+
+ uno::Sequence<uno::Reference<chart2::XDataPointCustomLabelField>> aLabels;
+ xDataPoint->getPropertyValue("CustomLabelFields") >>= aLabels;
+ uno::Reference<beans::XPropertySet> xLabel = aLabels[0];
+
+ sal_Int32 nCharColor = 0;
+ xLabel->getPropertyValue("CharColor") >>= nCharColor;
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 16777215
+ // - Actual : -1
+ // i.e. the data label had no explicit (white) color.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0xffffff), nCharColor);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/drawingml/chart/seriesconverter.cxx b/oox/source/drawingml/chart/seriesconverter.cxx
index 4124d83d3d55..b34bc355ca4d 100644
--- a/oox/source/drawingml/chart/seriesconverter.cxx
+++ b/oox/source/drawingml/chart/seriesconverter.cxx
@@ -359,6 +359,42 @@ DataLabelsConverter::~DataLabelsConverter()
{
}
+namespace
+{
+/// Inherit <c:dLbl> text props (if not set) from <c:dLbls> text props (if set).
+void InheritFromDataLabelsTextProps(const DataLabelsModel& rLabels, const DataLabelModel& rLabel)
+{
+ // See if <c:dLbls> contains text properties to inherit.
+ if (!rLabels.mxTextProp.is() || rLabels.mxTextProp->getParagraphs().empty())
+ {
+ return;
+ }
+
+ const std::shared_ptr<TextParagraph>& rLabelsParagraph = rLabels.mxTextProp->getParagraphs()[0];
+
+ // See if <c:dLbl> lacks text properties.
+ if (rLabel.mxTextProp.is())
+ {
+ return;
+ }
+
+ if (!rLabel.mxText || !rLabel.mxText->mxTextBody
+ || rLabel.mxText->mxTextBody->getParagraphs().empty())
+ {
+ return;
+ }
+
+ const std::shared_ptr<TextParagraph>& rLabelParagraph
+ = rLabel.mxText->mxTextBody->getParagraphs()[0];
+
+ // Inherit rLabel.mxText's char props from rLabels.mxTextProp's char props.
+ TextCharacterProperties aCharProps;
+ aCharProps.assignUsed(rLabelsParagraph->getProperties().getTextCharacterProperties());
+ aCharProps.assignUsed(rLabelParagraph->getProperties().getTextCharacterProperties());
+ rLabelParagraph->getProperties().getTextCharacterProperties().assignUsed(aCharProps);
+}
+}
+
void DataLabelsConverter::convertFromModel( const Reference< XDataSeries >& rxDataSeries, const TypeGroupConverter& rTypeGroup )
{
PropertySet aPropSet( rxDataSeries );
@@ -389,6 +425,7 @@ void DataLabelsConverter::convertFromModel( const Reference< XDataSeries >& rxDa
{
if (pointLabel->maNumberFormat.maFormatCode.isEmpty())
pointLabel->maNumberFormat = mrModel.maNumberFormat;
+ InheritFromDataLabelsTextProps(mrModel, *pointLabel);
DataLabelConverter aLabelConv(*this, *pointLabel);
aLabelConv.convertFromModel( rxDataSeries, rTypeGroup );
diff --git a/xmloff/source/chart/SchXMLSeries2Context.cxx b/xmloff/source/chart/SchXMLSeries2Context.cxx
index 378c1195633a..eb743022fd3e 100644
--- a/xmloff/source/chart/SchXMLSeries2Context.cxx
+++ b/xmloff/source/chart/SchXMLSeries2Context.cxx
@@ -1121,6 +1121,26 @@ void SchXMLSeries2Context::setStylesToDataPoints( SeriesDefaultsAndStyles& rSeri
xLabels[j] = xCustomLabel;
xCustomLabel->setString(seriesStyle.mCustomLabels[j]);
xCustomLabel->setFieldType(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT);
+
+ // Restore character properties on the text span manually, till
+ // SchXMLExportHelper_Impl::exportCustomLabel() does not write the style.
+ uno::Reference<beans::XPropertySetInfo> xPointPropInfo
+ = xPointProp->getPropertySetInfo();
+ if (xPointPropInfo.is())
+ {
+ uno::Sequence<beans::Property> aProperties = xPointPropInfo->getProperties();
+ for (const auto& rProperty : std::as_const(aProperties))
+ {
+ if (!rProperty.Name.startsWith("Char")
+ || rProperty.Name.startsWith("Chart"))
+ {
+ continue;
+ }
+
+ xCustomLabel->setPropertyValue(
+ rProperty.Name, xPointProp->getPropertyValue(rProperty.Name));
+ }
+ }
}
xPointProp->setPropertyValue("CustomLabelFields", uno::Any(xLabels));
}