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 | 15 +++++++++ sw/source/filter/html/wrthtml.hxx | 3 + sw/source/uibase/dochdl/swdtflvr.cxx | 2 - 6 files changed, 67 insertions(+), 6 deletions(-)
New commits: commit f30a8f6cb9a755d3ac73c2aafc2f71a0bb0d0369 Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Fri Nov 19 12:38:18 2021 +0100 Commit: Szymon Kłos <szymon.k...@collabora.com> CommitDate: Tue Feb 7 12:13:37 2023 +0000 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> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146580 Tested-by: Szymon Kłos <szymon.k...@collabora.com> Reviewed-by: Szymon Kłos <szymon.k...@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 d613b2738878..4799612d120d 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -426,6 +426,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 1bf0a45e82e3..6584e8a0e279 100644 --- a/sw/source/filter/html/htmlatr.cxx +++ b/sw/source/filter/html/htmlatr.cxx @@ -765,6 +765,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)); @@ -992,7 +993,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 @@ -2019,6 +2020,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(); @@ -2208,8 +2210,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(); } @@ -2447,7 +2449,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 ) ) { @@ -2463,6 +2465,7 @@ Writer& OutHTML_SwTextNode( Writer& rWrt, const SwContentNode& rNode ) { HTMLOutFuncs::FlushToAscii( rWrt.Strm() ); 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 a3b900b6a222..21d25d434eb6 100644 --- a/sw/source/filter/html/wrthtml.cxx +++ b/sw/source/filter/html/wrthtml.cxx @@ -154,6 +154,7 @@ SwHTMLWriter::SwHTMLWriter( const OUString& rBaseURL, std::u16string_view rFilte , mbEmbedImages(false) , m_bCfgPrintLayout( false ) , m_bParaDotLeaders( false ) + , m_bPrettyPrint( true ) { SetBaseURL(rBaseURL); @@ -228,6 +229,12 @@ void SwHTMLWriter::SetupFilterOptions(std::u16string_view rFilterOptions) aStoreMap["NoLineLimit"] <<= true; } + // this option can be "on" together with any of above + if (rFilterOptions.find(u"NoPrettyPrint") != std::u16string_view::npos) + { + aStoreMap["NoPrettyPrint"] <<= true; + } + const uno::Sequence<OUString> aOptionSeq = comphelper::string::convertCommaSeparated(rFilterOptions); static const OUStringLiteral aXhtmlNsKey(u"xhtmlns="); @@ -286,6 +293,14 @@ void SwHTMLWriter::SetupFilterFromPropertyValues( mbSkipHeaderFooter = bVal; } + // this option can be "on" together with any of above + it = aStoreMap.find("NoPrettyPrint"); + if (it != aStoreMap.end()) + { + m_nWishLineLen = -1; + m_bPrettyPrint = false; + } + it = aStoreMap.find("EmbedImages"); if (it != aStoreMap.end()) { diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx index b62aab60af6e..8f4073a5b6dd 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 d9a6db5c1bb5..c8787952d524 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -782,7 +782,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; }