sw/source/filter/ww8/docxattributeoutput.cxx | 15 +++++++++------ sw/source/filter/ww8/docxattributeoutput.hxx | 1 + 2 files changed, 10 insertions(+), 6 deletions(-)
New commits: commit 1d3ea5e7a4ea42390db29ed50bb426a663c86cc5 Author: Noel Grandin <[email protected]> AuthorDate: Mon Nov 3 13:11:21 2025 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Tue Nov 4 07:11:02 2025 +0100 mso-test: duplicate sz element in styles.xml This is using the test document from tdf94682-1.odt. We want to write w:sz in multiple places, which creates duplicate elements, which officeotron rules invalid. Use our existing strategy of collecting data and then writing it at the end. This is not ideal, because who is say which one of the font-sizes is the most correct? But our existing unit tests seem to believe that the "last" writer of the value is correct, so this approach works. Change-Id: I5f720f0d2c5d3efb7c2aec5ec955cc761fbb980d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193341 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> (cherry picked from commit 1cc468155c526639c3f5362932effc12c5fad969) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193374 Reviewed-by: Noel Grandin <[email protected]> Tested-by: Jenkins diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index a9c5fad5f806..be4634efdee1 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -3340,6 +3340,7 @@ void DocxAttributeOutput::InitCollectedRunProperties() m_pFontsAttrList = nullptr; m_pEastAsianLayoutAttrList = nullptr; m_pCharLangAttrList = nullptr; + m_oFontSize.reset(); // Write the elements in the spec order static const sal_Int32 aOrder[] = @@ -3598,6 +3599,9 @@ void DocxAttributeOutput::WriteCollectedRunProperties() m_pSerializer->singleElementNS( XML_w, XML_rFonts, detachFrom( m_pFontsAttrList ) ); } + if ( m_oFontSize ) + m_pSerializer->singleElementNS(XML_w, XML_sz, FSNS(XML_w, XML_val), OString::number(*m_oFontSize)); + if ( m_pColorAttrList.is() ) { m_pSerializer->singleElementNS( XML_w, XML_color, m_pColorAttrList ); @@ -8085,10 +8089,9 @@ void DocxAttributeOutput::CharEscapement( const SvxEscapementItem& rEscapement ) OString sPos = OString::number( round(( fHeight * nEsc ) / 1000) ); m_pSerializer->singleElementNS(XML_w, XML_position, FSNS(XML_w, XML_val), sPos); - if( ( 100 != nProp || sIss.match( "baseline" ) ) && !m_rExport.m_bFontSizeWritten ) + if( ( 100 != nProp || sIss.match( "baseline" ) ) && !m_oFontSize ) { - OString sSize = OString::number( round(( fHeight * nProp ) / 1000) ); - m_pSerializer->singleElementNS(XML_w, XML_sz, FSNS(XML_w, XML_val), sSize); + m_oFontSize = round(( fHeight * nProp ) / 1000); } } @@ -8117,16 +8120,16 @@ void DocxAttributeOutput::CharFont( const SvxFontItem& rFont) void DocxAttributeOutput::CharFontSize( const SvxFontHeightItem& rFontSize) { - OString fontSize = OString::number( ( rFontSize.GetHeight() + 5 ) / 10 ); + double fontSize = ( rFontSize.GetHeight() + 5 ) / 10; switch ( rFontSize.Which() ) { case RES_CHRATR_FONTSIZE: case RES_CHRATR_CJK_FONTSIZE: - m_pSerializer->singleElementNS(XML_w, XML_sz, FSNS(XML_w, XML_val), fontSize); + m_oFontSize = ( rFontSize.GetHeight() + 5 ) / 10; break; case RES_CHRATR_CTL_FONTSIZE: - m_pSerializer->singleElementNS(XML_w, XML_szCs, FSNS(XML_w, XML_val), fontSize); + m_pSerializer->singleElementNS(XML_w, XML_szCs, FSNS(XML_w, XML_val), OString::number(fontSize)); break; } } diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index 80be72b259de..c06ebc5eedf4 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -835,6 +835,7 @@ private: rtl::Reference<sax_fastparser::FastAttributeList> m_pLRSpaceAttrList; rtl::Reference<sax_fastparser::FastAttributeList> m_pParagraphSpacingAttrList; rtl::Reference<sax_fastparser::FastAttributeList> m_pHyperlinkAttrList; + std::optional<double> m_oFontSize; std::shared_ptr<SwContentControl> m_pContentControl; /// If the current SDT around runs should be ended before the current run. bool m_bEndCharSdt;
