From 1b4bf7effc4784cf9f0c135e70434993103e1475 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Tue, 3 Dec 2024 13:01:30 +0100 Subject: [PATCH] sw: HTML import: apply hard formatting at insert position ... ... even if there is a character format hint there - in this case, a RES_TXTATR_AUTOFMT attribute will not be converted to the SwTextNode's item set. Also add a test that uses the XDocumentInsertable interface to insert the HTML, which is closer to the real use case. (follow-up to commit f45d2fa85ba89eb7d71b51c3324f5938509b3201) Change-Id: Idbf7efceabca8d43d3e32d0b29fb37a9322c184c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177740 Reviewed-by: Michael Stahl Tested-by: Jenkins --- .../uiwriter/data/placeholder-bold-cs.fodt | 115 ++++++++++++++++++ sw/qa/extras/uiwriter/uiwriter3.cxx | 44 +++++++ sw/source/filter/html/swhtml.cxx | 8 +- 3 files changed, 163 insertions(+), 4 deletions(-) create mode 100644 sw/qa/extras/uiwriter/data/placeholder-bold-cs.fodt diff --git a/sw/qa/extras/uiwriter/data/placeholder-bold-cs.fodt b/sw/qa/extras/uiwriter/data/placeholder-bold-cs.fodt new file mode 100644 index 000000000000..25f610ad92e0 --- /dev/null +++ b/sw/qa/extras/uiwriter/data/placeholder-bold-cs.fodt @@ -0,0 +1,115 @@ + + + 2024-08-08T18:32:28.4200828172024-08-08T18:33:51.021911316PT1M27S1ZetaOffice/7.4.8.0.0$Linux_X86_64 LibreOffice_project/ab7057b1137e2241f51e62b58a0c605ec9a4b29c + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Test <replaceme>test + + + diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx index a030ad9c10f8..d169f76dbe09 100644 --- a/sw/qa/extras/uiwriter/uiwriter3.cxx +++ b/sw/qa/extras/uiwriter/uiwriter3.cxx @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -18,6 +19,7 @@ #include #include #include +#include #include #include @@ -86,6 +88,48 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testPlaceholderHTMLPaste) getProperty(getRun(getParagraph(4), 1, u" test"_ustr), u"CharWeight"_ustr)); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testPlaceholderHTMLInsert) +{ + createSwDoc("placeholder-bold-cs.fodt"); + + // select placeholder field + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xCursor{ xTextDocument->getText()->createTextCursor() }; + xCursor->gotoStart(false); + xCursor->goRight(5, false); + xCursor->goRight(1, true); + + sal_Int8 const html[] = "

AAA

BBB

CCC

"; + uno::Reference xStream{ new comphelper::MemoryInputStream{ html, + sizeof(html) } }; + + // insert HTML file + uno::Sequence aPropertyValues = comphelper::InitPropertySequence( + { { "InputStream", uno::Any(xStream) }, + { "Hidden", uno::Any(true) }, + { "FilterName", uno::Any(u"HTML (StarWriter)"_ustr) } }); + + uno::Reference xDocInsert{ xCursor, uno::UNO_QUERY }; + xDocInsert->insertDocumentFromURL("private:stream", aPropertyValues); + + CPPUNIT_ASSERT_EQUAL(int(4), getParagraphs()); + + CPPUNIT_ASSERT_EQUAL( + awt::FontWeight::NORMAL, + getProperty(getRun(getParagraph(1), 1, u"Test "_ustr), u"CharWeight"_ustr)); + CPPUNIT_ASSERT_EQUAL( + awt::FontWeight::BOLD, + getProperty(getRun(getParagraph(1), 2, u"AAA"_ustr), u"CharWeight"_ustr)); + CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, + getProperty(getParagraph(2), u"CharWeight"_ustr)); + CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, + getProperty(getParagraph(3), u"CharWeight"_ustr)); + CPPUNIT_ASSERT_EQUAL( + awt::FontWeight::NORMAL, + getProperty(getRun(getParagraph(4), 1, u" test"_ustr), u"CharWeight"_ustr)); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf151974) { createSwDoc("tdf151974.odt"); diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx index e838e2868fa8..fb0ed452336f 100644 --- a/sw/source/filter/html/swhtml.cxx +++ b/sw/source/filter/html/swhtml.cxx @@ -580,11 +580,11 @@ SvParserState SwHTMLParser::CallParser() aInsertionRangePam.Move( fnMoveBackward ); m_xDoc->getIDocumentRedlineAccess().SplitRedline( aInsertionRangePam ); - if (SwAttrSet const*const pAttrs = pPos->GetNode().GetTextNode()->GetpSwAttrSet()) + ::std::unique_ptr pSet{new SfxItemSet(m_xDoc->GetAttrPool(), + svl::Items)}; + if (pPos->GetNode().GetTextNode()->GetParaAttr(*pSet, 0, 0, false, false)) { - m_pTargetCharAttrs.reset(new SfxItemSet(*pAttrs->GetPool(), - svl::Items)); - m_pTargetCharAttrs->Put(*pAttrs); + m_pTargetCharAttrs = std::move(pSet); } m_xDoc->SetTextFormatColl( *m_pPam,