sw/qa/extras/rtfimport/data/tdf166191.rtf | 7 +++ sw/qa/extras/rtfimport/rtfimport.cxx | 9 ++++ sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx | 42 +++++++++++++++++++--- sw/source/writerfilter/rtftok/rtfdocumentimpl.hxx | 6 ++- 4 files changed, 57 insertions(+), 7 deletions(-)
New commits: commit 790a86c9840dee7852e5ed66daa7e378168c465b Author: Oliver Specht <oliver.spe...@cib.de> AuthorDate: Tue Apr 15 11:37:48 2025 +0200 Commit: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de> CommitDate: Wed Apr 23 17:16:57 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/+/184281 Tested-by: allotropia jenkins <jenk...@allotropia.de> Reviewed-by: Gabor Kelemen <gabor.kelemen.ext...@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 \ltrchcs0 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 70bab002de9e..41239394674a 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> @@ -2041,7 +2042,15 @@ CPPUNIT_TEST_FIXTURE(Test, tdf165923Tdf) uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); uno::Reference<text::XTextRange> xPara(xParaEnum->nextElement(), uno::UNO_QUERY); 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 diff --git a/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx b/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx index bdcd10705001..2b0d361cefe0 100644 --- a/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx +++ b/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx @@ -521,7 +521,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; @@ -547,12 +548,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()) { @@ -561,7 +572,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); } @@ -589,8 +622,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; @@ -1781,7 +1812,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 58e47e9e96e4..0cf25f1b5958 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);