sw/qa/extras/rtfimport/data/tdf166191.rtf         |    7 +++
 sw/qa/extras/rtfimport/rtfimport.cxx              |   10 +++++
 sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx |   42 +++++++++++++++++++---
 sw/source/writerfilter/rtftok/rtfdocumentimpl.hxx |    6 ++-
 4 files changed, 58 insertions(+), 7 deletions(-)

New commits:
commit dd6e982f289ed5e31387465a1306f65e7e6c7e64
Author:     Oliver Specht <oliver.spe...@cib.de>
AuthorDate: Tue Apr 15 11:37:48 2025 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Mon May 5 11:54:33 2025 +0200

    tdf#166191 character style properties only applied if repeated
    
    Reset character properties that are not repated at run level also if
    - the text run is in a table
    - there is no style with the index 0 ('Normal')
    Change-Id: I840178d727a157b628cb359e5c2798c1455cd555
    
    Change-Id: Id04a501e156e33804e6b99b13688eef1cb899e6e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184277
    Reviewed-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de>
    Tested-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de>
    Tested-by: Jenkins
    (cherry picked from commit 5268e13d3924a62f164f5c2b018c8289fbcc1ac4)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184519
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/qa/extras/rtfimport/data/tdf166191.rtf 
b/sw/qa/extras/rtfimport/data/tdf166191.rtf
new file mode 100644
index 000000000000..6c026bf22443
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/tdf166191.rtf
@@ -0,0 +1,7 @@
+{ tf1
+{\stylesheet{\*+bf0fs32 \ltrchcs0 s32\lang1031\langfe0\kerning32\loch
31502\hichf31502\dbchf31501\langnp1031\langfenp0 \sbasedon10 \slink1 \slocked 
\spriority9 \'dcberschrift 1 Zchn;}}
+\pard Simple text \par
+\pard +}
+
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx 
b/sw/qa/extras/rtfimport/rtfimport.cxx
index 31af508baeca..defc0bf4a5cc 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -14,6 +14,7 @@
 
 #include <com/sun/star/awt/FontDescriptor.hpp>
 #include <com/sun/star/awt/FontUnderline.hpp>
+#include <com/sun/star/awt/FontWeight.hpp>
 #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
 #include <com/sun/star/drawing/EnhancedCustomShapeSegment.hpp>
 #include <com/sun/star/drawing/FillStyle.hpp>
@@ -2028,6 +2029,15 @@ CPPUNIT_TEST_FIXTURE(Test, tdf165923Tdf)
     CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xPara, 
u"ParaTopMargin"_ustr));
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf166191)
+{
+    createSwDoc("tdf166191.rtf");
+    //text of second paragraph should be in 12pt and not bold
+    uno::Reference<text::XTextRange> textRun = getRun(getParagraph(2), 1);
+    CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL, getProperty<float>(textRun, 
u"CharWeight"_ustr));
+    CPPUNIT_ASSERT_EQUAL(12.0f, getProperty<float>(textRun, 
u"CharHeight"_ustr));
+}
+
 // tests should only be added to rtfIMPORT *if* they fail round-tripping in 
rtfEXPORT
 } // end of anonymous namespace
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx 
b/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx
index 2eebb3a87eeb..a4dd2ac93cba 100644
--- a/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx
+++ b/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx
@@ -512,7 +512,8 @@ static void lcl_copyFlatten(RTFReferenceProperties& rProps, 
RTFSprms& rStyleAttr
 }
 
 writerfilter::Reference<Properties>::Pointer_t
-RTFDocumentImpl::getProperties(const RTFSprms& rAttributes, RTFSprms const& 
rSprms, Id nStyleType)
+RTFDocumentImpl::getProperties(const RTFSprms& rAttributes, RTFSprms const& 
rSprms, Id nStyleType,
+                               bool bReplay)
 {
     RTFSprms aSprms(rSprms);
     RTFValue::Pointer_t pAbstractList;
@@ -538,12 +539,22 @@ RTFDocumentImpl::getProperties(const RTFSprms& 
rAttributes, RTFSprms const& rSpr
         auto it = m_aInvalidListTableFirstIndents.find(nAbstractListId);
         if (it != m_aInvalidListTableFirstIndents.end())
             aSprms.deduplicateList(it->second);
+        aSprms.duplicateList(pAbstractList);
     }
 
     int nStyle = 0;
     if (!m_aStates.empty())
         nStyle = m_aStates.top().getCurrentStyleIndex();
     auto it = m_pStyleTableEntries->find(nStyle);
+    if (!nStyle && it == m_pStyleTableEntries->end())
+    {
+        RTFSprms aAttributes;
+        writerfilter::Reference<Properties>::Pointer_t pProps(
+            new RTFReferenceProperties(aAttributes));
+        writerfilter::Reference<Properties>::Pointer_t const pProp(pProps);
+        m_pStyleTableEntries->insert(std::make_pair(0, pProp));
+        it = m_pStyleTableEntries->find(nStyle);
+    }
 
     if (it != m_pStyleTableEntries->end())
     {
@@ -552,7 +563,29 @@ RTFDocumentImpl::getProperties(const RTFSprms& 
rAttributes, RTFSprms const& rSpr
         auto itChar = m_pStyleTableEntries->end();
         if (!m_aStates.empty())
         {
-            int nCharStyle = m_aStates.top().getCurrentCharacterStyleIndex();
+            int nCharStyle = -1;
+            if (bReplay)
+            {
+                auto pCharStyleName = 
aSprms.find(NS_ooxml::LN_EG_RPrBase_rStyle);
+                if (pCharStyleName)
+                {
+                    for (auto& rCharStyle : *m_pStyleTableEntries)
+                    {
+                        RTFReferenceProperties& rCharStyleProps
+                            = 
*static_cast<RTFReferenceProperties*>(rCharStyle.second.get());
+                        auto rEntryStyleName
+                            = 
rCharStyleProps.getSprms().find(NS_ooxml::LN_CT_Style_name);
+                        if (rEntryStyleName
+                            && pCharStyleName->getString() == 
rEntryStyleName->getString())
+                        {
+                            nCharStyle = rCharStyle.first;
+                            break;
+                        }
+                    }
+                }
+            }
+            else
+                nCharStyle = m_aStates.top().getCurrentCharacterStyleIndex();
             itChar = m_pStyleTableEntries->find(nCharStyle);
         }
 
@@ -580,8 +613,6 @@ RTFDocumentImpl::getProperties(const RTFSprms& rAttributes, 
RTFSprms const& rSpr
         return new RTFReferenceProperties(std::move(attributes), 
std::move(sprms));
     }
 
-    if (pAbstractList)
-        aSprms.duplicateList(pAbstractList);
     writerfilter::Reference<Properties>::Pointer_t pRet
         = new RTFReferenceProperties(rAttributes, std::move(aSprms));
     return pRet;
@@ -1772,7 +1803,8 @@ void RTFDocumentImpl::replayBuffer(RTFBuffer_t& rBuffer, 
RTFSprms* const pSprms,
             writerfilter::Reference<Properties>::Pointer_t const 
pProp(getProperties(
                 std::get<1>(aTuple)->getAttributes(), 
std::get<1>(aTuple)->getSprms(),
                 std::get<0>(aTuple) == BUFFER_PROPS_CHAR ? 
NS_ooxml::LN_Value_ST_StyleType_character
-                                                         : 0));
+                                                         : 0,
+                std::get<0>(aTuple) == BUFFER_PROPS_CHAR));
             Mapper().props(pProp);
         }
         else if (std::get<0>(aTuple) == BUFFER_NESTROW)
diff --git a/sw/source/writerfilter/rtftok/rtfdocumentimpl.hxx 
b/sw/source/writerfilter/rtftok/rtfdocumentimpl.hxx
index 835c91b15e80..f5357b4da208 100644
--- a/sw/source/writerfilter/rtftok/rtfdocumentimpl.hxx
+++ b/sw/source/writerfilter/rtftok/rtfdocumentimpl.hxx
@@ -784,8 +784,10 @@ private:
     void runBreak();
     void parBreak();
     void tableBreak();
-    writerfilter::Reference<Properties>::Pointer_t
-    getProperties(const RTFSprms& rAttributes, RTFSprms const& rSprms, Id 
nStyleType);
+    writerfilter::Reference<Properties>::Pointer_t getProperties(const 
RTFSprms& rAttributes,
+                                                                 RTFSprms 
const& rSprms,
+                                                                 Id nStyleType,
+                                                                 bool bReplay 
= false);
     void checkNeedPap();
     void handleFontTableEntry();
     void sectBreak(bool bFinal = false);

Reply via email to