sw/source/filter/ww8/docxattributeoutput.cxx | 15 +++++++++------ sw/source/filter/ww8/docxattributeoutput.hxx | 1 + 2 files changed, 10 insertions(+), 6 deletions(-)
New commits: commit 1cc468155c526639c3f5362932effc12c5fad969 Author: Noel Grandin <[email protected]> AuthorDate: Mon Nov 3 13:11:21 2025 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Mon Nov 3 14:29:45 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]> diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 93a5a378c4af..6ed38924da86 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -3348,6 +3348,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[] = @@ -3607,6 +3608,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 ); @@ -8096,10 +8100,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); } } @@ -8128,16 +8131,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 0f838a100988..7b937c650df3 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;
