sc/qa/filter/html/data/tdf79298_strikeout_variants.html | 3 + sc/qa/filter/html/html.cxx | 26 ++++++++++ sc/source/filter/html/htmlpars.cxx | 9 +++ sc/source/filter/rtf/eeimpars.cxx | 2 sw/qa/extras/htmlimport/data/tdf79298-strikeout-variants.html | 3 + sw/qa/extras/htmlimport/htmlimport.cxx | 19 +++++++ sw/source/filter/html/swhtml.cxx | 2 7 files changed, 63 insertions(+), 1 deletion(-)
New commits: commit 47176d51b994d7858c1f4ff2f674d2955bc0ca5a Author: Andreas Heinisch <andreas.heini...@yahoo.de> AuthorDate: Thu Dec 5 10:24:32 2024 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Mon Dec 16 10:28:09 2024 +0100 tdf#79298 - FORMATTING: Copy/paste: import strikethrough attribute Change-Id: I0539e87f2a87f869e234ed7c944b9da6bd0e82bf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177847 Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de> Tested-by: Jenkins (cherry picked from commit 813f34d6726584368641f2e93fdaf79ff387d6b8) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178189 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sc/qa/filter/html/data/tdf79298_strikeout_variants.html b/sc/qa/filter/html/data/tdf79298_strikeout_variants.html new file mode 100644 index 000000000000..391ddf095c2b --- /dev/null +++ b/sc/qa/filter/html/data/tdf79298_strikeout_variants.html @@ -0,0 +1,3 @@ +<p><s>s</s></p> +<p><strike>strike</strike></p> +<p><del>del</del></p> \ No newline at end of file diff --git a/sc/qa/filter/html/html.cxx b/sc/qa/filter/html/html.cxx index c243dea350b0..2f6b9cb249b8 100644 --- a/sc/qa/filter/html/html.cxx +++ b/sc/qa/filter/html/html.cxx @@ -13,6 +13,8 @@ #include <com/sun/star/sheet/XSpreadsheetDocument.hpp> #include <com/sun/star/table/XCellRange.hpp> +#include <editeng/crossedoutitem.hxx> + #include <comphelper/propertyvalue.hxx> #include <svl/numformat.hxx> #include <svl/zformat.hxx> @@ -205,6 +207,30 @@ CPPUNIT_TEST_FIXTURE(Test, testPasteSingleCell) CPPUNIT_ASSERT_EQUAL(static_cast<double>(3), pDoc->GetValue(/*col=*/2, /*row=*/0, /*tab=*/0)); } +CPPUNIT_TEST_FIXTURE(Test, testTdf79298_strikeout_variants) +{ + createScDoc(); + + // Paste different strikeout variants into the first cell + ScDocument* pDoc = getScDoc(); + ScAddress aCellPos(/*nColP=*/0, /*nRowP=*/0, /*nTabP=*/0); + ScImportExport aImporter(*pDoc, aCellPos); + SvFileStream aFile(createFileURL(u"tdf79298_strikeout_variants.html"), StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aFile); + aMemory.Seek(0); + CPPUNIT_ASSERT(aImporter.ImportStream(aMemory, OUString(), SotClipboardFormatId::HTML)); + + // Verify HTML strikeout tags (<del>, <s>, and <strike>) + for (size_t nCol = 0; nCol < 3; ++nCol) + { + const ScPatternAttr* pAttr = pDoc->GetPattern(ScAddress(0, nCol, 0)); + CPPUNIT_ASSERT_MESSAGE("Failed to get cell attribute.", pAttr); + const SvxCrossedOutItem& rCrossedOutItem = pAttr->GetItem(ATTR_FONT_CROSSEDOUT); + CPPUNIT_ASSERT_EQUAL(FontStrikeout::STRIKEOUT_SINGLE, rCrossedOutItem.GetStrikeout()); + } +} + CPPUNIT_TEST_FIXTURE(Test, testCopyText) { // Given a document with 01 in A1: diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx index 125d6e98ec80..6c225c3020c8 100644 --- a/sc/source/filter/html/htmlpars.cxx +++ b/sc/source/filter/html/htmlpars.cxx @@ -26,6 +26,7 @@ #include <scitems.hxx> #include <editeng/colritem.hxx> +#include <editeng/crossedoutitem.hxx> #include <editeng/brushitem.hxx> #include <editeng/editeng.hxx> #include <editeng/fhgtitem.hxx> @@ -1794,6 +1795,14 @@ void ScHTMLLayoutParser::ProcToken( HtmlImportInfo* pInfo ) } } break; + case HtmlTokenId::STRIKE_ON: + case HtmlTokenId::STRIKETHROUGH_ON: + case HtmlTokenId::DELETEDTEXT_ON: + { + if (IsAtBeginningOfText(pInfo)) + mxActEntry->aItemSet.Put(SvxCrossedOutItem(STRIKEOUT_SINGLE, ATTR_FONT_CROSSEDOUT)); + } + break; case HtmlTokenId::UNDERLINE_ON : { if ( IsAtBeginningOfText( pInfo ) ) diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx index 5b6ad74377f9..8b5b5b58dfb9 100644 --- a/sc/source/filter/rtf/eeimpars.cxx +++ b/sc/source/filter/rtf/eeimpars.cxx @@ -246,6 +246,8 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu pAttrItemSet->Put( *pItem ); if ( rESet.GetItemState( ATTR_FONT_UNDERLINE, false, &pItem) == SfxItemState::SET ) pAttrItemSet->Put( *pItem ); + if ( rESet.GetItemState( ATTR_FONT_CROSSEDOUT, false, &pItem) == SfxItemState::SET ) + pAttrItemSet->Put( *pItem ); // HTML LATIN/CJK/CTL script type dependent const SfxPoolItem* pFont; if ( rESet.GetItemState( ATTR_FONT, false, &pFont) != SfxItemState::SET ) diff --git a/sw/qa/extras/htmlimport/data/tdf79298-strikeout-variants.html b/sw/qa/extras/htmlimport/data/tdf79298-strikeout-variants.html new file mode 100644 index 000000000000..391ddf095c2b --- /dev/null +++ b/sw/qa/extras/htmlimport/data/tdf79298-strikeout-variants.html @@ -0,0 +1,3 @@ +<p><s>s</s></p> +<p><strike>strike</strike></p> +<p><del>del</del></p> \ No newline at end of file diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx index 43163ce5a39a..746379b6f7b1 100644 --- a/sw/qa/extras/htmlimport/htmlimport.cxx +++ b/sw/qa/extras/htmlimport/htmlimport.cxx @@ -11,6 +11,7 @@ #include <com/sun/star/awt/FontSlant.hpp> #include <com/sun/star/awt/FontUnderline.hpp> +#include <com/sun/star/awt/FontStrikeout.hpp> #include <com/sun/star/awt/FontWeight.hpp> #include <com/sun/star/graphic/XGraphic.hpp> #include <com/sun/star/graphic/GraphicType.hpp> @@ -376,6 +377,24 @@ CPPUNIT_TEST_FIXTURE(HtmlImportTest, testImageSize) CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(aExpected.getHeight()), aSize.Height); } +CPPUNIT_TEST_FIXTURE(HtmlImportTest, testTdf79298StrikeoutVariants) +{ + createSwWebDoc("tdf79298-strikeout-variants.html"); + + // Without the accompanying fix in place, this tests would have failed with: + // - Expected: 1 (FontStrikeout::SINGLE) + // - Actual : 0 (FontStrikeout::NONE) + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Strikeout for <del> missing", sal_Int16(awt::FontStrikeout::SINGLE), + getProperty<sal_Int16>(getRun(getParagraph(1), 1), u"CharStrikeout"_ustr)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Strikeout for <s> missing", sal_Int16(awt::FontStrikeout::SINGLE), + getProperty<sal_Int16>(getRun(getParagraph(2), 1), u"CharStrikeout"_ustr)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Strikeout for <strike> missing", sal_Int16(awt::FontStrikeout::SINGLE), + getProperty<sal_Int16>(getRun(getParagraph(3), 1), u"CharStrikeout"_ustr)); +} + CPPUNIT_TEST_FIXTURE(HtmlImportTest, testTdf142781) { // FIXME: the DPI check should be removed when either (1) the test is fixed to work with diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx index fb0ed452336f..9488fb0dafff 100644 --- a/sw/source/filter/html/swhtml.cxx +++ b/sw/source/filter/html/swhtml.cxx @@ -1889,6 +1889,7 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken ) case HtmlTokenId::STRIKE_ON: case HtmlTokenId::STRIKETHROUGH_ON: + case HtmlTokenId::DELETEDTEXT_ON: { NewStdAttr( HtmlTokenId::STRIKE_ON, &m_xAttrTab->pStrike, SvxCrossedOutItem(STRIKEOUT_SINGLE, RES_CHRATR_CROSSEDOUT) ); @@ -1974,7 +1975,6 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken ) case HtmlTokenId::ACRONYM_ON: case HtmlTokenId::ABBREVIATION_ON: case HtmlTokenId::INSERTEDTEXT_ON: - case HtmlTokenId::DELETEDTEXT_ON: case HtmlTokenId::TELETYPE_ON: NewCharFormat( nToken );