include/oox/export/chartexport.hxx | 7 ++ oox/source/export/chartexport.cxx | 115 +++++++++++++------------------------ 2 files changed, 49 insertions(+), 73 deletions(-)
New commits: commit 1b4d6fa2b39c203cf823074ed91d037b6bfc9b27 Author: Noel Grandin <[email protected]> AuthorDate: Wed Nov 5 08:33:03 2025 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Thu Nov 6 06:58:07 2025 +0100 mso-test: order of c:numFmt element in chart.xml This is using the test document from tdf121279-1.odt. When importing and exporting to XLSX, the order of elements is wrong according to officeotron. Move some code around in ChartExport to get that right. Change-Id: Id09328520c05ebb35074b4bb451d08572a9c831e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193439 Reviewed-by: Michael Stahl <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> (cherry picked from commit 0a8060e6d5cf7a7f1ce4b54c6019bb56995e57f6) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193481 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/include/oox/export/chartexport.hxx b/include/oox/export/chartexport.hxx index e52abebb9b46..d990d8221e75 100644 --- a/include/oox/export/chartexport.hxx +++ b/include/oox/export/chartexport.hxx @@ -77,6 +77,8 @@ namespace model { namespace oox::drawingml { +struct LabelPlacementParam; + enum AxesType { AXIS_PRIMARY_X = 1, @@ -297,6 +299,11 @@ private: void outputFontRef(::sax_fastparser::FSHelperPtr pFS, sal_Int32 nElTokenId, const model::FontRef& aColor); + void writeLabelProperties( + const css::uno::Reference<css::beans::XPropertySet>& xPropSet, const LabelPlacementParam& rLabelParam, + sal_Int32 nLabelIndex, DataLabelsRange& rDLblsRange, + bool bIsChartex); + public: OOX_DLLPUBLIC ChartExport( sal_Int32 nXmlNamespace, ::sax_fastparser::FSHelperPtr pFS, css::uno::Reference< css::frame::XModel > const & xModel, diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index c0795954aab0..60d79c954263 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -4768,8 +4768,6 @@ void ChartExport::exportOneAxis_chartex( pFS->endElement( FSNS( XML_cx, XML_axis ) ); } -namespace { - struct LabelPlacementParam { bool mbExport; @@ -4796,6 +4794,8 @@ struct LabelPlacementParam {} }; +namespace { + const char* toOOXMLPlacement( sal_Int32 nPlacement ) { switch (nPlacement) @@ -4931,7 +4931,9 @@ void writeCustomLabel( const FSHelperPtr& pFS, ChartExport* pChartExport, pFS->endElement(FSNS(XML_c, XML_tx)); } -void writeLabelProperties( const FSHelperPtr& pFS, ChartExport* pChartExport, +} + +void ChartExport::writeLabelProperties( const uno::Reference<beans::XPropertySet>& xPropSet, const LabelPlacementParam& rLabelParam, sal_Int32 nLabelIndex, DataLabelsRange& rDLblsRange, bool bIsChartex) @@ -4939,6 +4941,8 @@ void writeLabelProperties( const FSHelperPtr& pFS, ChartExport* pChartExport, if (!xPropSet.is()) return; + FSHelperPtr pFS = GetFS(); + const sal_Int32 nChartNS = bIsChartex ? XML_cx : XML_c; chart2::DataPointLabel aLabel; @@ -4947,12 +4951,38 @@ void writeLabelProperties( const FSHelperPtr& pFS, ChartExport* pChartExport, sal_Int32 nLabelBorderColor = 0x00FFFFFF; sal_Int32 nLabelFillColor = -1; - xPropSet->getPropertyValue(u"Label"_ustr) >>= aLabel; xPropSet->getPropertyValue(u"CustomLabelFields"_ustr) >>= aCustomLabelFields; xPropSet->getPropertyValue(u"LabelBorderWidth"_ustr) >>= nLabelBorderWidth; xPropSet->getPropertyValue(u"LabelBorderColor"_ustr) >>= nLabelBorderColor; xPropSet->getPropertyValue(u"LabelFillColor"_ustr) >>= nLabelFillColor; + if (aCustomLabelFields.hasElements()) + writeCustomLabel(pFS, this, aCustomLabelFields, nLabelIndex, rDLblsRange); // c:tx + + bool bLinkedNumFmt = false; + if( GetProperty(xPropSet, u"LinkNumberFormatToSource"_ustr) ) + mAny >>= bLinkedNumFmt; + + bool bLabelIsNumberFormat = true; + if( xPropSet->getPropertyValue(u"Label"_ustr) >>= aLabel ) + bLabelIsNumberFormat = aLabel.ShowNumber; + + if (GetProperty(xPropSet, bLabelIsNumberFormat ? u"NumberFormat"_ustr : u"PercentageNumberFormat"_ustr)) + { + sal_Int32 nKey = 0; + mAny >>= nKey; + + OUString aNumberFormatString = getNumberFormatCode(nKey); + + if (bIsChartex) { + pFS->singleElement(FSNS(XML_cx, XML_numFmt), XML_formatCode, aNumberFormatString, + XML_sourceLinked, ToPsz10(bLinkedNumFmt)); + } else { + pFS->singleElement(FSNS(XML_c, XML_numFmt), XML_formatCode, aNumberFormatString, + XML_sourceLinked, ToPsz10(bLinkedNumFmt)); + } + } + if (nLabelBorderWidth > 0 || nLabelFillColor != -1) { pFS->startElement(FSNS(nChartNS, XML_spPr)); @@ -4961,9 +4991,9 @@ void writeLabelProperties( const FSHelperPtr& pFS, ChartExport* pChartExport, { ::Color nColor(ColorTransparency, nLabelFillColor); if (nColor.IsTransparent()) - pChartExport->WriteSolidFill(nColor, nColor.GetAlpha()); + WriteSolidFill(nColor, nColor.GetAlpha()); else - pChartExport->WriteSolidFill(nColor); + WriteSolidFill(nColor); } if (nLabelBorderWidth > 0) @@ -4975,9 +5005,9 @@ void writeLabelProperties( const FSHelperPtr& pFS, ChartExport* pChartExport, { ::Color nColor(ColorTransparency, nLabelBorderColor); if (nColor.IsTransparent()) - pChartExport->WriteSolidFill(nColor, nColor.GetAlpha()); + WriteSolidFill(nColor, nColor.GetAlpha()); else - pChartExport->WriteSolidFill(nColor); + WriteSolidFill(nColor); } pFS->endElement(FSNS(XML_a, XML_ln)); @@ -4986,10 +5016,7 @@ void writeLabelProperties( const FSHelperPtr& pFS, ChartExport* pChartExport, pFS->endElement(FSNS(nChartNS, XML_spPr)); } - pChartExport->exportTextProps(xPropSet, bIsChartex); - - if (aCustomLabelFields.hasElements()) - writeCustomLabel(pFS, pChartExport, aCustomLabelFields, nLabelIndex, rDLblsRange); + exportTextProps(xPropSet, bIsChartex); // c:txPr if (!bIsChartex) { // In chartex label position is an attribute of cx:dataLabel @@ -5028,7 +5055,7 @@ void writeLabelProperties( const FSHelperPtr& pFS, ChartExport* pChartExport, // TODO: is the following correct for chartex? pFS->startElement(FSNS(nChartNS, XML_ext), XML_uri, "{CE6537A1-D6FC-4f65-9D91-7224C49458BB}", FSNS(XML_xmlns, XML_c15), - pChartExport->GetFB()->getNamespaceURL(OOX_NS(c15))); + GetFB()->getNamespaceURL(OOX_NS(c15))); pFS->singleElement(FSNS(XML_c15, XML_showDataLabelsRange), XML_val, "1"); @@ -5037,8 +5064,6 @@ void writeLabelProperties( const FSHelperPtr& pFS, ChartExport* pChartExport, } } -} - void ChartExport::exportDataLabels( const uno::Reference<chart2::XDataSeries> & xSeries, sal_Int32 nSeriesLength, sal_Int32 eChartType, DataLabelsRange& rDLblsRange, @@ -5165,69 +5190,13 @@ void ChartExport::exportDataLabels( } } - bool bLinkedNumFmt = false; - if( GetProperty(xLabelPropSet, u"LinkNumberFormatToSource"_ustr) ) - mAny >>= bLinkedNumFmt; - - chart2::DataPointLabel aLabel; - bool bLabelIsNumberFormat = true; - if( xLabelPropSet->getPropertyValue(u"Label"_ustr) >>= aLabel ) - bLabelIsNumberFormat = aLabel.ShowNumber; - else - bLabelIsNumberFormat = true; - - if (GetProperty(xLabelPropSet, bLabelIsNumberFormat ? u"NumberFormat"_ustr : u"PercentageNumberFormat"_ustr)) - { - sal_Int32 nKey = 0; - mAny >>= nKey; - - OUString aNumberFormatString = getNumberFormatCode(nKey); - - if (bIsChartex) { - pFS->singleElement(FSNS(XML_cx, XML_numFmt), XML_formatCode, aNumberFormatString, - XML_sourceLinked, ToPsz10(bLinkedNumFmt)); - } else { - pFS->singleElement(FSNS(XML_c, XML_numFmt), XML_formatCode, aNumberFormatString, - XML_sourceLinked, ToPsz10(bLinkedNumFmt)); - } - } - // Individual label property that overwrites the baseline. - writeLabelProperties(pFS, this, xLabelPropSet, aParam, nIdx, - rDLblsRange, bIsChartex); + writeLabelProperties(xLabelPropSet, aParam, nIdx, rDLblsRange, bIsChartex); pFS->endElement(FSNS(XML_c, XML_dLbl)); } - bool bLinkedNumFmt = true; - if (GetProperty(xPropSet, u"LinkNumberFormatToSource"_ustr)) - mAny >>= bLinkedNumFmt; - - chart2::DataPointLabel aLabel; - bool bLabelIsNumberFormat = true; - if( xPropSet->getPropertyValue(u"Label"_ustr) >>= aLabel ) - bLabelIsNumberFormat = aLabel.ShowNumber; - - if (GetProperty(xPropSet, bLabelIsNumberFormat ? u"NumberFormat"_ustr : u"PercentageNumberFormat"_ustr)) - { - sal_Int32 nKey = 0; - mAny >>= nKey; - - OUString aNumberFormatString = getNumberFormatCode(nKey); - - if (bIsChartex) { - pFS->singleElement(FSNS(XML_cx, XML_numFmt), - XML_formatCode, aNumberFormatString, - XML_sourceLinked, ToPsz10(bLinkedNumFmt)); - } else { - pFS->singleElement(FSNS(XML_c, XML_numFmt), - XML_formatCode, aNumberFormatString, - XML_sourceLinked, ToPsz10(bLinkedNumFmt)); - } - } - // Baseline label properties for all labels. - writeLabelProperties(pFS, this, xPropSet, aParam, -1, rDLblsRange, - bIsChartex); + writeLabelProperties(xPropSet, aParam, -1, rDLblsRange, bIsChartex); if (!bIsChartex) { bool bShowLeaderLines = false;
