summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-07-15 09:36:23 +0200
committerGabor Kelemen <kelemen.gabor2@nisz.hu>2020-09-23 20:13:28 +0200
commit437b6fe9a499987d9d31bd1515e2b8a9ff574041 (patch)
tree1346eea4333c56588c6e3c6645953e03ea875fe2
parent8f8c71f4633bab43b2a2b3251b0c6ab69ab8b21a (diff)
tdf#131175 oox chart import: fix char color of <dLbl>, inherited from <dLbls>
There were two problems here: 1) Our chart model expects the char formatting of a data label as direct formatting, so in case <c:dLbl> has no such formatting, but <c:dLbls> has, oox has to explicitly inherit. 2) The data label char formatting is represented using chart::FormattedString, but the char format of it is not (yet) exported to ODF. Given that the char format of the series and the individual data labels is the same, restore the same formatting on import to please rendering. With these, finally the chart labels in the bugdoc are white, not black (and have a dark background, so they are readable). (cherry picked from commit 8a43bfeffab9009c9f373e883fef87af1a7b3843) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99026 Tested-by: Jenkins Reviewed-by: Andras Timar <andras.timar@collabora.com> (cherry picked from commit b894890cfdddc7dd38f483c9a9b2592a24dd1697) Change-Id: Iebac5ce0be31a59bafb0f9fe7636330585e33822 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103201 Tested-by: Gabor Kelemen <kelemen.gabor2@nisz.hu> Reviewed-by: Gabor Kelemen <kelemen.gabor2@nisz.hu>
-rw-r--r--oox/source/drawingml/chart/seriesconverter.cxx37
-rw-r--r--xmloff/source/chart/SchXMLSeries2Context.cxx20
2 files changed, 57 insertions, 0 deletions
diff --git a/oox/source/drawingml/chart/seriesconverter.cxx b/oox/source/drawingml/chart/seriesconverter.cxx
index 2acf265847dc..ea13f93982bf 100644
--- a/oox/source/drawingml/chart/seriesconverter.cxx
+++ b/oox/source/drawingml/chart/seriesconverter.cxx
@@ -366,6 +366,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 );
@@ -387,6 +423,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 ef6cd0249a7e..85711d9ffa9c 100644
--- a/xmloff/source/chart/SchXMLSeries2Context.cxx
+++ b/xmloff/source/chart/SchXMLSeries2Context.cxx
@@ -1119,6 +1119,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));
}