sw/qa/extras/tiledrendering/data/multiline.odt |binary sw/qa/extras/tiledrendering/tiledrendering.cxx | 40 +++++++++++++++++++++++++ sw/source/filter/html/htmlatr.cxx | 13 +++++--- sw/source/filter/html/wrthtml.cxx | 4 +- sw/source/filter/html/wrthtml.hxx | 3 + sw/source/uibase/dochdl/swdtflvr.cxx | 2 - 6 files changed, 55 insertions(+), 7 deletions(-)
New commits: commit 9ab3be6bc0848e44f88ae157c7e8323335246897 Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Fri Nov 19 12:38:18 2021 +0100 Commit: Henry Castro <hcas...@collabora.com> CommitDate: Tue Jul 19 20:58:41 2022 +0200 lok: don't pretty print html for online followup for "lok: don't limit line length in HTMLWriter" Pretty printing makes html more readable for human but introduces lots of new line marks which are later interpreted in the client as a valid new lines in the document content. This was causing multiplying the line breaks when inserting hyperlinks where we read current selection's content and then we pass it back to the core as link's content (with added new lines). This change needs cypress change to not contain "\n" at the beginning of some content read from the document. This also afects copying from the online document to clipboard. Change-Id: I2b17d62398d947fcf1d3fb1ed6005c3063d114f2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136893 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Henry Castro <hcas...@collabora.com> diff --git a/sw/qa/extras/tiledrendering/data/multiline.odt b/sw/qa/extras/tiledrendering/data/multiline.odt new file mode 100644 index 000000000000..4c60b58decb2 Binary files /dev/null and b/sw/qa/extras/tiledrendering/data/multiline.odt differ diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 6db7cd57dfdd..5b0443884ad8 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -425,6 +425,46 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testGetTextSelectionLineLimit) CPPUNIT_ASSERT(sHtmlText.match(sExpectedHtml, nStart)); } +CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testGetTextSelectionMultiLine) +{ + // Test will check if correct number of new line marks / paragraphs is generated + const char sOriginalText[] = u8"Heading\n\ +Let's have text; we need to be able to select the text inside the shape, but also the various individual ones too:\n\ +\n\ +\n\ +\n\ +\n\ +\n\ +And this is all for Writer shape objects\n\ +Heading on second page"; + + const char sExpectedHtml[] = u8"Heading</h2>\n\ +<p>Let's have text; we need to be able to select the text inside the shape, but also the various individual ones too:</p>\n\ +<p><br/><br/></p>\n\ +<p><br/><br/></p>\n\ +<p><br/><br/></p>\n\ +<p><br/><br/></p>\n\ +<p><br/><br/></p>\n\ +<h1 class=\"western\">And this is all for Writer shape objects</h1>\n\ +<h2 class=\"western\">Heading on second page</h2>"; + + SwXTextDocument* pXTextDocument = createDoc("multiline.odt"); + + SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell(); + // Create a selection. + pWrtShell->SelAll(); + + OString sPlainText = apitest::helper::transferable::getTextSelection(pXTextDocument->getSelection(), "text/plain;charset=utf-8"); + + CPPUNIT_ASSERT_EQUAL(OString(sOriginalText), sPlainText.trim()); + + OString sHtmlText = apitest::helper::transferable::getTextSelection(pXTextDocument->getSelection(), "text/html"); + + int nStart = sHtmlText.indexOf(u8"Heading"); + + CPPUNIT_ASSERT(sHtmlText.match(sExpectedHtml, nStart)); +} + CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testSetGraphicSelection) { SwXTextDocument* pXTextDocument = createDoc("shape.fodt"); diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx index 51f059d5a2cc..9b6c5b5d8155 100644 --- a/sw/source/filter/html/htmlatr.cxx +++ b/sw/source/filter/html/htmlatr.cxx @@ -770,6 +770,7 @@ static void OutHTML_SwFormat( Writer& rWrt, const SwFormat& rFormat, if( rInfo.bInNumberBulletList && bNumberedForListItem ) { HtmlWriter html(rWrt.Strm(), rHWrt.maNamespace); + html.prettyPrint(rHWrt.m_bPrettyPrint); html.start(OOO_STRING_SVTOOLS_HTML_li); if( USHRT_MAX != nNumStart ) html.attribute(OOO_STRING_SVTOOLS_HTML_O_value, OString::number(nNumStart)); @@ -1000,7 +1001,7 @@ static void OutHTML_SwFormatOff( Writer& rWrt, const SwHTMLTextCollOutputInfo& r if( rInfo.ShouldOutputToken() ) { - if( rHWrt.m_bLFPossible ) + if( rHWrt.m_bPrettyPrint && rHWrt.m_bLFPossible ) rHWrt.OutNewLine( true ); // if necessary, for BLOCKQUOTE, ADDRESS and DD another paragraph token @@ -2039,6 +2040,7 @@ Writer& OutHTML_SwTextNode( Writer& rWrt, const SwContentNode& rNode ) rHTMLWrt.m_bLFPossible = true; HtmlWriter aHtml(rWrt.Strm(), rHTMLWrt.maNamespace); + aHtml.prettyPrint(rHTMLWrt.m_bPrettyPrint); aHtml.start(OOO_STRING_SVTOOLS_HTML_horzrule); const SfxItemSet* pItemSet = pNd->GetpSwAttrSet(); @@ -2231,8 +2233,8 @@ Writer& OutHTML_SwTextNode( Writer& rWrt, const SwContentNode& rNode ) // now it's a good opportunity again for an LF - if it is still allowed // FIXME: for LOK case we set rHTMLWrt.m_nWishLineLen as -1, for now keep old flow // when LOK side will be fixed - don't insert new line at the beginning - if( rHTMLWrt.m_bLFPossible && - rHTMLWrt.GetLineLen() >= (rHTMLWrt.m_nWishLineLen >= 0 ? rHTMLWrt.m_nWishLineLen : 70 ) ) + if( rHTMLWrt.m_bLFPossible && rHTMLWrt.m_bPrettyPrint && rHTMLWrt.m_nWishLineLen >= 0 && + rHTMLWrt.GetLineLen() >= rHTMLWrt.m_nWishLineLen ) { rHTMLWrt.OutNewLine(); } @@ -2472,7 +2474,7 @@ Writer& OutHTML_SwTextNode( Writer& rWrt, const SwContentNode& rNode ) nWordLen = nEnd; nWordLen -= nStrPos; - if( rHTMLWrt.m_nWishLineLen >= 0 && + if( rHTMLWrt.m_bPrettyPrint && rHTMLWrt.m_nWishLineLen >= 0 && (nLineLen >= rHTMLWrt.m_nWishLineLen || (nLineLen+nWordLen) >= rHTMLWrt.m_nWishLineLen ) ) { @@ -2488,6 +2490,7 @@ Writer& OutHTML_SwTextNode( Writer& rWrt, const SwContentNode& rNode ) { HTMLOutFuncs::FlushToAscii( rWrt.Strm(), aContext ); HtmlWriter aHtml(rWrt.Strm(), rHTMLWrt.maNamespace); + aHtml.prettyPrint(rHTMLWrt.m_bPrettyPrint); aHtml.single(OOO_STRING_SVTOOLS_HTML_linebreak); } else if (c == CH_TXT_ATR_FORMELEMENT) @@ -2541,6 +2544,7 @@ Writer& OutHTML_SwTextNode( Writer& rWrt, const SwContentNode& rNode ) else { HtmlWriter aHtml(rHTMLWrt.Strm(), rHTMLWrt.maNamespace); + aHtml.prettyPrint(rHTMLWrt.m_bPrettyPrint); aHtml.single(OOO_STRING_SVTOOLS_HTML_linebreak); const SvxULSpaceItem& rULSpace = pNd->GetSwAttrSet().Get(RES_UL_SPACE); if (rULSpace.GetLower() > 0 && !bEndOfCell) @@ -2567,6 +2571,7 @@ Writer& OutHTML_SwTextNode( Writer& rWrt, const SwContentNode& rNode ) } HtmlWriter aHtml(rHTMLWrt.Strm(), rHTMLWrt.maNamespace); + aHtml.prettyPrint(rHTMLWrt.m_bPrettyPrint); aHtml.start(OOO_STRING_SVTOOLS_HTML_linebreak); aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_clear, pString); aHtml.end(); diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx index 0d6aa170c0ad..2dc669ba2266 100644 --- a/sw/source/filter/html/wrthtml.cxx +++ b/sw/source/filter/html/wrthtml.cxx @@ -152,6 +152,7 @@ SwHTMLWriter::SwHTMLWriter( const OUString& rBaseURL, const OUString& rFilterOpt , mbEmbedImages(false) , m_bCfgPrintLayout( false ) , m_bParaDotLeaders( false ) + , m_bPrettyPrint( true ) { SetBaseURL(rBaseURL); @@ -232,9 +233,10 @@ void SwHTMLWriter::SetupFilterOptions(const OUString& rFilterOptions) } // this option can be "on" together with any of above - if (rFilterOptions.indexOf("NoLineLimit") >= 0) + if (rFilterOptions.indexOf("NoPrettyPrint") >= 0) { m_nWishLineLen = -1; + m_bPrettyPrint = false; } const uno::Sequence<OUString> aOptionSeq = comphelper::string::convertCommaSeparated(rFilterOptions); diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx index 22a386bcee7c..53f3b6b5846b 100644 --- a/sw/source/filter/html/wrthtml.hxx +++ b/sw/source/filter/html/wrthtml.hxx @@ -416,7 +416,8 @@ public: #define sCSS2_P_CLASS_leaders "leaders" bool m_bCfgPrintLayout : 1; // PrintLayout option for TOC dot leaders bool m_bParaDotLeaders : 1; // for TOC dot leaders - // 25 + bool m_bPrettyPrint : 1; // Allows to add new lines to make it more readable + // 26 /// Tracks which text portion attributes are currently open: a which id -> open count map. std::map<sal_uInt16, int> maStartedAttributes; diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx index 1ad8d67d6433..b1869255697e 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -787,7 +787,7 @@ bool SwTransferable::WriteObject( tools::SvRef<SotTempStream>& xStream, case SWTRANSFER_OBJECTTYPE_HTML: { // LOK is interested in getting images embedded for copy/paste support. - GetHTMLWriter( comphelper::LibreOfficeKit::isActive() ? OUString("EmbedImages;NoLineLimit") : OUString(), OUString(), xWrt ); + GetHTMLWriter( comphelper::LibreOfficeKit::isActive() ? OUString("EmbedImages;NoPrettyPrint") : OUString(), OUString(), xWrt ); break; }