sw/qa/extras/rtfimport/data/165333.rtf | 12 +++ sw/qa/extras/rtfimport/rtfimport.cxx | 11 +++ sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx | 58 ++++++++++--------- 3 files changed, 56 insertions(+), 25 deletions(-)
New commits: commit 330efa9db365fbc28d825de2fe14162a692ffb2f Author: Oliver Specht <oliver.spe...@cib.de> AuthorDate: Wed Feb 19 14:18:39 2025 +0100 Commit: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de> CommitDate: Fri Feb 21 19:42:00 2025 +0100 tdf#165333 RTF: import SYMBOL fields correctly Úsing XTextAppend to insert SYMBOL fields fixes wrongly extended character properties. Change-Id: I14f187e63e2c72d3c2cf27ab99cdced108797057 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181892 Tested-by: Jenkins Tested-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de> Reviewed-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de> diff --git a/sw/qa/extras/rtfimport/data/165333.rtf b/sw/qa/extras/rtfimport/data/165333.rtf new file mode 100644 index 000000000000..7834bfd178ef --- /dev/null +++ b/sw/qa/extras/rtfimport/data/165333.rtf @@ -0,0 +1,12 @@ +{ tf1 + +{\stylesheet +{\qls72 Normal;} +} + +\pard{ tlchcs1 bf40fs12 \ltrchcs0 +40s12+{ tlchcs1 f40fs10 \ltrchcs0 40s10\insrsid12669988+{ield{\* ldinst SYMBOL 253 \f "Wingdings" \s 5}{ldrslt10s10}}}\par + +} diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 7a83bffe7b35..6b854306dbe3 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -1984,6 +1984,17 @@ CPPUNIT_TEST_FIXTURE(Test, test118465Tdf) CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getProperty<sal_Int32>(xTable, u"HeaderRowCount"_ustr)); } +CPPUNIT_TEST_FIXTURE(Test, test165333Tdf) +{ + createSwDoc("165333.rtf"); + uno::Reference<text::XTextRange> const xRun1( + getRun(uno::Reference<text::XTextRange>(getParagraphOrTable(1), uno::UNO_QUERY), 1)); + CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xRun1, u"CharHidden"_ustr)); + uno::Reference<text::XTextRange> const xRun2( + getRun(uno::Reference<text::XTextRange>(getParagraphOrTable(1), uno::UNO_QUERY), 2)); + CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xRun2, u"CharHidden"_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/dmapper/DomainMapper_Impl.cxx b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx index aff98b7790f0..393c451c5f9a 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx @@ -8445,38 +8445,46 @@ void DomainMapper_Impl::CloseFieldCommand() if (xTextAppend.is()) { - uno::Reference< text::XText > xText = xTextAppend->getText(); - uno::Reference< text::XTextCursor > xCrsr = xText->createTextCursor(); - if (xCrsr.is()) + uno::Sequence<beans::PropertyValue> aValues(bHasFont ? 4 : 3); + beans::PropertyValue aCharSetVal; + aCharSetVal.Name = getPropertyName(PROP_CHAR_FONT_CHAR_SET); + aCharSetVal.Value <<= awt::CharSet::SYMBOL; + aValues.getArray()[0] = std::move(aCharSetVal); + if(bHasFont) { - xCrsr->gotoEnd(false); - xText->insertString(xCrsr, sSymbol, true); - uno::Reference< beans::XPropertySet > xProp( xCrsr, uno::UNO_QUERY ); - xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_CHAR_SET), uno::Any(awt::CharSet::SYMBOL)); - if(bHasFont) - { - uno::Any aVal( sFont ); - xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME), aVal); - xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME_ASIAN), aVal); - xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME_COMPLEX), aVal); + beans::PropertyValue aFontVal1; + beans::PropertyValue aFontVal2; + beans::PropertyValue aFontVal3; + + aFontVal1.Name = getPropertyName(PROP_CHAR_FONT_NAME); + aFontVal1.Value <<= sFont; + aFontVal2.Name = getPropertyName(PROP_CHAR_FONT_NAME_ASIAN); + aFontVal2.Value <<= sFont; + aFontVal3.Name = getPropertyName(PROP_CHAR_FONT_NAME_COMPLEX); + aFontVal3.Value <<= sFont; + + aValues.getArray()[1] = std::move(aFontVal1); + aValues.getArray()[2] = std::move(aFontVal2); + aValues.getArray()[3] = std::move(aFontVal3); + } - } - PropertyMapPtr pCharTopContext = GetTopContextOfType(CONTEXT_CHARACTER); - if (pCharTopContext.is()) + PropertyMapPtr pCharTopContext = GetTopContextOfType(CONTEXT_CHARACTER); + if (pCharTopContext.is()) + { + uno::Sequence<beans::PropertyValue> aContextValues + = pCharTopContext->GetPropertyValues( + /*bCharGrabBag=*/!IsInComments()); + OUString sFontName = getPropertyName(PROP_CHAR_FONT_NAME); + for (const beans::PropertyValue& rProperty : aContextValues) { - uno::Sequence<beans::PropertyValue> aValues - = pCharTopContext->GetPropertyValues( - /*bCharGrabBag=*/!IsInComments()); - OUString sFontName = getPropertyName(PROP_CHAR_FONT_NAME); - for (const beans::PropertyValue& rProperty : aValues) + if (!bHasFont || !rProperty.Name.startsWith(sFontName)) { - if (!bHasFont || !rProperty.Name.startsWith(sFontName)) - xProp->setPropertyValue(rProperty.Name, rProperty.Value); + aValues.realloc(aValues.getLength() + 1); + aValues.getArray()[aValues.getLength() - 1] = rProperty; } - } - } + xTextAppend->appendTextPortion(sSymbol, aValues); } } }