[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - 2 commits - include/oox oox/qa oox/source xmloff/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Wed Jul 15 11:35:02 UTC 2020
include/oox/core/filterbase.hxx | 3 +
oox/qa/unit/data/chart-data-label-char-color.docx |binary
oox/qa/unit/drawingml.cxx | 43 +++++++++++++++++++
oox/source/core/filterbase.cxx | 10 ++++
oox/source/drawingml/chart/seriesconverter.cxx | 48 +++++++++++++++++++++-
xmloff/source/chart/SchXMLSeries2Context.cxx | 20 +++++++++
6 files changed, 122 insertions(+), 2 deletions(-)
New commits:
commit fcad9e78c5e2d301d66d8d9708524baffd91bef7
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Jul 15 09:36:23 2020 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Jul 15 13:34:42 2020 +0200
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)
Change-Id: Iebac5ce0be31a59bafb0f9fe7636330585e33822
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98810
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
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
Binary files /dev/null and b/oox/qa/unit/data/chart-data-label-char-color.docx differ
diff --git a/oox/qa/unit/drawingml.cxx b/oox/qa/unit/drawingml.cxx
index bf82a5cbc1cd..39164120e94a 100644
--- a/oox/qa/unit/drawingml.cxx
+++ b/oox/qa/unit/drawingml.cxx
@@ -19,6 +19,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 <comphelper/embeddedobjectcontainer.hxx>
#include <comphelper/processfactory.hxx>
@@ -165,6 +170,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 b72c0b1941f3..9dc804949e57 100644
--- a/oox/source/drawingml/chart/seriesconverter.cxx
+++ b/oox/source/drawingml/chart/seriesconverter.cxx
@@ -407,6 +407,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 );
@@ -434,6 +470,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));
}
commit 712bafb3656e6a882ead54f1e8522e82d7b426da
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Jul 1 09:39:09 2020 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Jul 15 13:34:27 2020 +0200
Related: tdf#131175 OOXML chart: insert hatch definition into the right table
Both the chart and the containing document has one, but the intention is
to insert this into the chart one.
This is needed, but not enough to render the right hatch for data
labels.
(cherry picked from commit e18bc316efbd815b047f4e19ebd033e7a842d10d)
Conflicts:
oox/source/drawingml/chart/seriesconverter.cxx
Change-Id: I485d84e2ae33728963b648c05e730d418567fc0e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98809
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
diff --git a/include/oox/core/filterbase.hxx b/include/oox/core/filterbase.hxx
index ed4e35f3b52d..ddb51b97934a 100644
--- a/include/oox/core/filterbase.hxx
+++ b/include/oox/core/filterbase.hxx
@@ -180,6 +180,9 @@ public:
the imported document. */
ModelObjectHelper& getModelObjectHelper() const;
+ ModelObjectHelper& getModelObjectHelperForModel(
+ const css::uno::Reference<css::lang::XMultiServiceFactory>& xFactory) const;
+
/** Returns a helper for the handling of OLE objects. */
::oox::ole::OleObjectHelper& getOleObjectHelper() const;
diff --git a/oox/source/core/filterbase.cxx b/oox/source/core/filterbase.cxx
index c99c77ba870f..795cd074f678 100644
--- a/oox/source/core/filterbase.cxx
+++ b/oox/source/core/filterbase.cxx
@@ -137,6 +137,8 @@ struct FilterBaseImpl
GraphicHelperRef mxGraphicHelper; /// Graphic and graphic object handling.
ModelObjHelperRef mxModelObjHelper; /// Tables to create new named drawing objects.
+ std::map<css::uno::Reference<css::lang::XMultiServiceFactory>, ModelObjHelperRef>
+ mxModelObjHelpers;
OleObjHelperRef mxOleObjHelper; /// OLE object handling.
VbaProjectRef mxVbaProject; /// VBA project manager.
@@ -366,6 +368,14 @@ ModelObjectHelper& FilterBase::getModelObjectHelper() const
return *mxImpl->mxModelObjHelper;
}
+ModelObjectHelper& FilterBase::getModelObjectHelperForModel(
+ const css::uno::Reference<css::lang::XMultiServiceFactory>& xFactory) const
+{
+ if (!mxImpl->mxModelObjHelpers.count(xFactory))
+ mxImpl->mxModelObjHelpers[xFactory] = std::make_shared<ModelObjectHelper>(xFactory);
+ return *mxImpl->mxModelObjHelpers[xFactory];
+}
+
OleObjectHelper& FilterBase::getOleObjectHelper() const
{
if( !mxImpl->mxOleObjHelper )
diff --git a/oox/source/drawingml/chart/seriesconverter.cxx b/oox/source/drawingml/chart/seriesconverter.cxx
index 43a6f60f1779..b72c0b1941f3 100644
--- a/oox/source/drawingml/chart/seriesconverter.cxx
+++ b/oox/source/drawingml/chart/seriesconverter.cxx
@@ -34,6 +34,7 @@
#include <com/sun/star/chart2/data/LabeledDataSequence.hpp>
#include <com/sun/star/chart2/XFormattedString2.hpp>
#include <com/sun/star/chart2/FormattedString.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <osl/diagnose.h>
#include <basegfx/numeric/ftools.hxx>
@@ -331,7 +332,10 @@ void DataLabelConverter::convertFromModel( const Reference< XDataSeries >& rxDat
if (mrModel.mxShapeProp)
{
importBorderProperties(aPropSet, *mrModel.mxShapeProp, getFilter().getGraphicHelper());
- importFillProperties(aPropSet, *mrModel.mxShapeProp, getFilter().getGraphicHelper(), getFilter().getModelObjectHelper());
+ uno::Reference<lang::XMultiServiceFactory> xFactory(getChartDocument(), uno::UNO_QUERY);
+ ModelObjectHelper& rHelper = getFilter().getModelObjectHelperForModel(xFactory);
+ importFillProperties(aPropSet, *mrModel.mxShapeProp, getFilter().getGraphicHelper(),
+ rHelper);
}
if( mrModel.mxText && mrModel.mxText->mxTextBody && !mrModel.mxText->mxTextBody->getParagraphs().empty() )
{
@@ -418,7 +422,10 @@ void DataLabelsConverter::convertFromModel( const Reference< XDataSeries >& rxDa
{
// Import baseline border properties for these data labels.
importBorderProperties(aPropSet, *mrModel.mxShapeProp, getFilter().getGraphicHelper());
- importFillProperties(aPropSet, *mrModel.mxShapeProp, getFilter().getGraphicHelper(), getFilter().getModelObjectHelper());
+ uno::Reference<lang::XMultiServiceFactory> xFactory(getChartDocument(), uno::UNO_QUERY);
+ ModelObjectHelper& rHelper = getFilter().getModelObjectHelperForModel(xFactory);
+ importFillProperties(aPropSet, *mrModel.mxShapeProp, getFilter().getGraphicHelper(),
+ rHelper);
}
}
More information about the Libreoffice-commits
mailing list