sw/source/filter/ww8/docxattributeoutput.cxx |   22 +++++++++++++---------
 sw/source/filter/ww8/docxattributeoutput.hxx |    1 +
 2 files changed, 14 insertions(+), 9 deletions(-)

New commits:
commit 90161b9cb2efedfaa65a59fb2e53626cdb9e65c5
Author:     Noel Grandin <[email protected]>
AuthorDate: Fri Oct 31 16:09:17 2025 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Tue Nov 4 18:06:28 2025 +0100

    mso-test: clamp a:cx and a:cy to >= 0
    
    When loading and then saving the document from ooo83929-3.doc,
    we end up with negative values here, which is not valid.
    
    Use our existing mechanism to enforce correct ordering.
    
    Change-Id: Id584e0bd1d2a2bfcca84b19517f426b0b7c5f510
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193324
    Reviewed-by: Miklos Vajna <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    (cherry picked from commit ff30cc6a366f1cbaa4f038542d78842cbc90b039)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193362
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>
    (cherry picked from commit 7952978822858fedb580a4564f190223d767d6af)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193386
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 201bbbf590f4..8008b94bfd0d 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -5600,8 +5600,9 @@ void DocxAttributeOutput::FlyFrameGraphic( const 
SwGrfNode* pGrfNode, const Size
     m_pSerializer->startElementNS(XML_a, XML_xfrm, xFrameAttributes);
 
     m_pSerializer->singleElementNS(XML_a, XML_off, XML_x, "0", XML_y, "0");
-    OString aWidth( OString::number( TwipsToEMU( aSize.Width() ) ) );
-    OString aHeight( OString::number( TwipsToEMU( aSize.Height() ) ) );
+    // clamp to >=0, negative values are not valid here
+    OString aWidth( OString::number( std::max(sal_Int64(0), TwipsToEMU( 
aSize.Width() )) ) );
+    OString aHeight( OString::number( std::max(sal_Int64(0), TwipsToEMU( 
aSize.Height() )) ) );
     m_pSerializer->singleElementNS(XML_a, XML_ext, XML_cx, aWidth, XML_cy, 
aHeight);
     m_pSerializer->endElementNS( XML_a, XML_xfrm );
     m_pSerializer->startElementNS(XML_a, XML_prstGeom, XML_prst, "rect");
commit 570c63d555ecab9f9edc00ec343e25d8580283e1
Author:     Noel Grandin <[email protected]>
AuthorDate: Mon Nov 3 13:11:21 2025 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Tue Nov 4 18:06:22 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
    (cherry picked from commit 1d3ea5e7a4ea42390db29ed50bb426a663c86cc5)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193387
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 1d6cc512223c..201bbbf590f4 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3342,6 +3342,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[] =
@@ -3601,6 +3602,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 );
@@ -8078,10 +8082,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);
     }
 }
 
@@ -8110,16 +8113,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 5a00c9838b11..ca720311b8d6 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;
commit 7245a09d32410c3fb349724f1d78fa4a8171d05f
Author:     Noel Grandin <[email protected]>
AuthorDate: Wed Oct 29 13:40:30 2025 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Tue Nov 4 18:06:17 2025 +0100

    mso-test: fix duplicate w:rFonts elements under w:rPr
    
    When loading and then saving the document from forum-mso-de-56075.docx,
    we ended up with a duplicate rFonts element.
    
    The xml looked something like:
    
    <w:numbering ...
      <w:lvl w:ilvl="0">
          ...
          <w:rPr>
              <w:rFonts w:ascii="Calibri" w:hAnsi="Calibri" w:cs="Calibri" 
w:hint="default"/>
              <w:rFonts w:eastAsiaTheme="minorEastAsia"/>
          </w:rPr>
      </w:lvl>
    
    Change-Id: I958023fb0c9e40af5aec31b07628bb72b25e730e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193146
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>
    (cherry picked from commit f6140a360dced4fc45816bd0605089110dd6835c)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193252
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193336

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index a07d82df7c31..1d6cc512223c 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -7938,7 +7938,7 @@ void DocxAttributeOutput::NumberingLevel( sal_uInt8 
nLevel,
         {
             GetExport().GetId( *pFont ); // ensure font info is written to 
fontTable.xml
             OString aFamilyName( OUStringToOString( pFont->GetFamilyName(), 
RTL_TEXTENCODING_UTF8 ) );
-            m_pSerializer->singleElementNS( XML_w, XML_rFonts,
+            AddToAttrList( m_pFontsAttrList,
                     FSNS( XML_w, XML_ascii ), aFamilyName,
                     FSNS( XML_w, XML_hAnsi ), aFamilyName,
                     FSNS( XML_w, XML_cs ), aFamilyName,

Reply via email to