sw/CppunitTest_sw_ooxmlexport26.mk                 |   16 ++++++++
 sw/Module_sw.mk                                    |    1 
 sw/qa/extras/ooxmlexport/data/tdf166850.docx       |binary
 sw/qa/extras/ooxmlexport/ooxmlexport26.cxx         |   41 +++++++++++++++++++++
 sw/source/writerfilter/dmapper/StyleSheetTable.cxx |   16 +++++---
 sw/source/writerfilter/dmapper/StyleSheetTable.hxx |    2 -
 6 files changed, 70 insertions(+), 6 deletions(-)

New commits:
commit 80877c7dc467bf5ad6b28ec1b2662db36fcf7542
Author:     Oliver Specht <oliver.spe...@cib.de>
AuthorDate: Tue Jun 3 16:21:43 2025 +0200
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Thu Jun 5 10:26:14 2025 +0200

    tdf#166850 Apply converted style name to StyleRef field
    
    As a result of e45f187870362ed4448f4a9fb96883b8431887fb the StyleRef
    field needs to use the modified style name with (suffix " (user)")
    The related JUnit test requires a German locale to detect the
    related issue. Otherwise there is no suffix that needs to be
    applied to the field.
    
    Change-Id: Iad4257568ad05900df63a6098ba81e926df701e1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186150
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>
    Tested-by: Jenkins

diff --git a/sw/CppunitTest_sw_ooxmlexport26.mk 
b/sw/CppunitTest_sw_ooxmlexport26.mk
new file mode 100755
index 000000000000..8b57467c2f61
--- /dev/null
+++ b/sw/CppunitTest_sw_ooxmlexport26.mk
@@ -0,0 +1,16 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call sw_ooxmlexport_test,26))
+
+$(call gb_CppunitTest_get_target,sw_ooxmlexport26) : export LO_TEST_LOCALE=de
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index b00830e0fe2f..f3421aecb542 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -103,6 +103,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_ooxmlexport23 \
     CppunitTest_sw_ooxmlexport24 \
     CppunitTest_sw_ooxmlexport25 \
+    CppunitTest_sw_ooxmlexport26 \
     CppunitTest_sw_ooxmlexport_template \
     CppunitTest_sw_ooxmlfieldexport \
     CppunitTest_sw_ooxmllinks \
diff --git a/sw/qa/extras/ooxmlexport/data/tdf166850.docx 
b/sw/qa/extras/ooxmlexport/data/tdf166850.docx
new file mode 100644
index 000000000000..5fb96bdb2276
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf166850.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport26.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport26.cxx
new file mode 100755
index 000000000000..2346da8dc504
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport26.cxx
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+
+#include <IDocumentLayoutAccess.hxx>
+#include <wrtsh.hxx>
+
+namespace
+{
+class Test : public SwModelTestBase
+{
+public:
+    Test()
+        : SwModelTestBase(u"/sw/qa/extras/ooxmlexport/data/"_ustr, u"Office 
Open XML Text"_ustr)
+    {
+    }
+};
+
+//test requires German user interface otherwise it will not detect the issue
+CPPUNIT_TEST_FIXTURE(Test, testTdf166850)
+{
+    createSwDoc("tdf166850.docx");
+    SwDoc* pDoc = getSwDoc();
+    SwViewShell* pViewShell = 
pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
+    pViewShell->UpdateFields();
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, 
"/root/page[2]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion",
+                "expand", u"Heading 1");
+}
+
+} // end of anonymous namespace
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/writerfilter/dmapper/StyleSheetTable.cxx 
b/sw/source/writerfilter/dmapper/StyleSheetTable.cxx
index 099ae839e7ef..6e3259aacc8f 100644
--- a/sw/source/writerfilter/dmapper/StyleSheetTable.cxx
+++ b/sw/source/writerfilter/dmapper/StyleSheetTable.cxx
@@ -1103,19 +1103,22 @@ OUString StyleSheetTable::CloneTOCStyle(FontTablePtr 
const& rFontTable, StyleShe
     // the old converted name is what is applied to paragraphs
     m_pImpl->m_ClonedTOCStylesMap.emplace(pStyle->m_sConvertedStyleName, 
pClone->m_sConvertedStyleName);
     std::vector<StyleSheetEntryPtr> const styles{ pClone };
-    ApplyStyleSheetsImpl(rFontTable, styles);
+    std::vector<OUString> aRetStyleNames = ApplyStyleSheetsImpl(rFontTable, 
styles);
+    pClone->m_sConvertedStyleName = aRetStyleNames[0];
     return pClone->m_sConvertedStyleName;
 }
 
 void StyleSheetTable::ApplyStyleSheets( const FontTablePtr& rFontTable )
 {
-    return ApplyStyleSheetsImpl(rFontTable, m_pImpl->m_aStyleSheetEntries);
+    ApplyStyleSheetsImpl(rFontTable, m_pImpl->m_aStyleSheetEntries);
 }
 
-void StyleSheetTable::ApplyStyleSheetsImpl(const FontTablePtr& rFontTable, 
std::vector<StyleSheetEntryPtr> const& rEntries)
+std::vector<OUString> StyleSheetTable::ApplyStyleSheetsImpl(const 
FontTablePtr& rFontTable, std::vector<StyleSheetEntryPtr> const& rEntries)
 {
+    std::vector<OUString> aStyleUINames(rEntries.size());
+    std::vector<OUString>::iterator aStyleUINamesIt = aStyleUINames.begin();
     if (!m_pImpl->m_xTextDocument)
-        return;
+        return aStyleUINames;
     try
     {
         rtl::Reference< SwXStyleFamilies > xStyleFamilies = 
m_pImpl->m_xTextDocument->getSwStyleFamilies();
@@ -1131,6 +1134,7 @@ void StyleSheetTable::ApplyStyleSheetsImpl(const 
FontTablePtr& rFontTable, std::
             std::vector<beans::PropertyValue> aTableStylesVec;
             for (auto& pEntry : rEntries)
             {
+                *aStyleUINamesIt = pEntry->m_sStyleName;
                 if( pEntry->m_nStyleTypeCode == STYLE_TYPE_UNKNOWN && 
!pEntry->m_sStyleName.isEmpty() )
                     pEntry->m_nStyleTypeCode = STYLE_TYPE_PARA; // unspecified 
style types are considered paragraph styles
 
@@ -1414,7 +1418,7 @@ void StyleSheetTable::ApplyStyleSheetsImpl(const 
FontTablePtr& rFontTable, std::
                             aMissingParent.emplace_back( sParentStyle, xStyle 
);
 
                         xStyles->insertStyleByName( sConvertedStyleName, 
static_cast<SwXStyle*>(xStyle.get()) );
-
+                        *aStyleUINamesIt = 
static_cast<SwXStyle*>(xStyle.get())->GetStyleUIName().toString();
                         if (!m_pImpl->m_bIsNewDoc && bParaStyle)
                         {
                             // Remember the inserted style, which may or may 
not be referred during
@@ -1443,6 +1447,7 @@ void StyleSheetTable::ApplyStyleSheetsImpl(const 
FontTablePtr& rFontTable, std::
                     pEntry->m_pProperties->InsertProps( 
m_pImpl->m_pDefaultCharProps, /*bOverwrite=*/false );
                     pEntry->m_pProperties->InsertProps( 
m_pImpl->m_pDefaultParaProps, /*bOverwrite=*/false );
                 }
+                ++aStyleUINamesIt;
             }
 
             // Update the styles that were created before their parents or 
next-styles
@@ -1492,6 +1497,7 @@ void StyleSheetTable::ApplyStyleSheetsImpl(const 
FontTablePtr& rFontTable, std::
     {
         DBG_UNHANDLED_EXCEPTION("writerfilter", "Styles could not be imported 
completely");
     }
+    return aStyleUINames;
 }
 
 
diff --git a/sw/source/writerfilter/dmapper/StyleSheetTable.hxx 
b/sw/source/writerfilter/dmapper/StyleSheetTable.hxx
index eaf84387b512..3715e1ef6ef7 100644
--- a/sw/source/writerfilter/dmapper/StyleSheetTable.hxx
+++ b/sw/source/writerfilter/dmapper/StyleSheetTable.hxx
@@ -128,7 +128,7 @@ private:
 
     void applyDefaults(bool bParaProperties);
 
-    void ApplyStyleSheetsImpl(const FontTablePtr& rFontTable, 
std::vector<StyleSheetEntryPtr> const& rEntries);
+    std::vector<OUString> ApplyStyleSheetsImpl(const FontTablePtr& rFontTable, 
std::vector<StyleSheetEntryPtr> const& rEntries);
 };
 
 

Reply via email to