sw/qa/extras/ooxmlexport/data/tdf169413_asciiTheme.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport25.cxx              |    7 +++++++
 sw/source/filter/ww8/docxattributeoutput.cxx            |   11 +++++++----
 3 files changed, 14 insertions(+), 4 deletions(-)

New commits:
commit 019cfd97f73618258fd18470609a4f874d6c7cbf
Author:     Justin Luth <[email protected]>
AuthorDate: Sat Nov 15 14:08:13 2025 -0500
Commit:     Xisco Fauli <[email protected]>
CommitDate: Mon Nov 17 09:39:40 2025 +0100

    tdf#169413 docx export: don't write themes twice in w:rFonts
    
    A round-trip was reported as corrupt by both Writer and Word.
    
    This probably started in 6.0 with tdf#38778
    although a bibisect pointed to my 24.2 patch for tdf#108505.
    
    Although I'm not exactly sure what triggers this,
    grabBag was doubling up the bug report's conf12.docx
    w:cstheme in rFonts which looked like
        <w:rFonts w:cstheme="minorHAnsi"
                  w:cs="Calibri"
                  w:cstheme="minorHAnsi"/>
    and duplicate entries are invalid XML - even firefox complains.
    
    make CppunitTest_sw_ooxmlexport25 \
        CPPUNIT_TEST_NAME=testTdf169413_asciiTheme
    
    Change-Id: Id9561b940c2c536147422e10a8c1d37ea51c2e78
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194057
    Reviewed-by: Justin Luth <[email protected]>
    Tested-by: Jenkins
    (cherry picked from commit 9e8211b1c2a814880c0108b2122a6085be192b82)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194061

diff --git a/sw/qa/extras/ooxmlexport/data/tdf169413_asciiTheme.docx 
b/sw/qa/extras/ooxmlexport/data/tdf169413_asciiTheme.docx
new file mode 100644
index 000000000000..308e44019bbf
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf169413_asciiTheme.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
index 4d967ed58b24..3e73bd48092b 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
@@ -90,6 +90,13 @@ DECLARE_OOXMLEXPORT_TEST(testTdf165478_bottomAligned, 
"tdf165478_bottomAligned.d
     CPPUNIT_ASSERT_EQUAL(sal_Int32(1887), nFlyTop);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf169413_asciiTheme)
+{
+    // the document failed to reload without errors after a round-trip
+    createSwDoc("tdf169413_asciiTheme.docx");
+    saveAndReload(mpFilter);
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testTdf166620)
 {
     createSwDoc();
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 005ab1b18e5c..84162524104d 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3133,7 +3133,7 @@ void DocxAttributeOutput::CmdEndField_Impl(SwTextNode 
const*const pNode,
 ///         </w:rPr>
 ///         <w:fldChar w:fldCharType="begin" />
 ///     </w:r>
-///         <w:r>
+///     <w:r>
 ///         <w:rPr>
 ///             <!-- properties written with DoWriteFieldRunProperties()
 ///         </w:rPr>
@@ -10491,19 +10491,22 @@ void DocxAttributeOutput::CharGrabBag( const 
SfxGrabBagItem& rItem )
         {
             if ( rGrabBagElement.second >>= sOriginalValue )
                 bWriteCSTheme =
-                        ( m_pFontsAttrList->getOptionalValue( FSNS( XML_w, 
XML_cs ) ) == sOriginalValue );
+                    (m_pFontsAttrList->getOptionalValue(FSNS( XML_w, XML_cs)) 
== sOriginalValue)
+                    && !m_pFontsAttrList->hasAttribute(FSNS(XML_w, 
XML_cstheme));
         }
         else if ( m_pFontsAttrList.is() && rGrabBagElement.first == 
"CharThemeFontNameAscii" )
         {
             if ( rGrabBagElement.second >>= sOriginalValue )
                 bWriteAsciiTheme =
-                        ( m_pFontsAttrList->getOptionalValue( FSNS( XML_w, 
XML_ascii ) ) == sOriginalValue );
+                    (m_pFontsAttrList->getOptionalValue(FSNS( XML_w, 
XML_ascii)) == sOriginalValue)
+                    && !m_pFontsAttrList->hasAttribute(FSNS(XML_w, 
XML_asciiTheme));
         }
         else if ( m_pFontsAttrList.is() && rGrabBagElement.first == 
"CharThemeFontNameEastAsia" )
         {
             if ( rGrabBagElement.second >>= sOriginalValue )
                 bWriteEastAsiaTheme =
-                        ( m_pFontsAttrList->getOptionalValue( FSNS( XML_w, 
XML_eastAsia ) ) == sOriginalValue );
+                    (m_pFontsAttrList->getOptionalValue(FSNS(XML_w, 
XML_eastAsia)) == sOriginalValue)
+                    && !m_pFontsAttrList->hasAttribute(FSNS(XML_w, 
XML_eastAsiaTheme));
         }
     }
 

Reply via email to