diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2021-11-19 09:51:36 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2021-12-09 13:20:31 +0100 |
commit | eb664f6d747798c768bb399994e19cab307ee63a (patch) | |
tree | 9704e61149890f58755bf4e72686cab0fac2c340 | |
parent | 5840ad541c8c7363448c155742f28f93408ed45c (diff) |
lok: don't limit line length in HTMLWriter
Problem:
https://github.com/CollaboraOnline/online/issues/3645
Test case:
1. Open Collabora Online and paste "Alphabet" section from
wikipedia article: https://en.wikipedia.org/wiki/Estonian_language#Alphabet
2. Select last two sentences (starting from "The letter")
3. Open Insert -> Hyperlink dialog
Result: notice that some spaces was removed/converted into new line
Expected: Text field should contain original text
Hyperlink dialog uses current selection which is get as HTML from the
core.
In the SwHTMLWriter there is a parameter defining how long
line should be and it replaces ' ' space into '\n' new line
when limit is reached.
This patch turns off that feature but only for getting html
for current selection in LOK case.
For now don't remove new line at the beginning as cypress has to
be fixed first. Added FIXME in the code.
Change-Id: I03b540b0b2d639a08774ecc4fc75abb7b3f0b7a3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125482
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r-- | sw/qa/extras/tiledrendering/data/estonian.odt | bin | 0 -> 11615 bytes | |||
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 26 | ||||
-rw-r--r-- | sw/source/filter/html/htmlatr.cxx | 9 | ||||
-rw-r--r-- | sw/source/filter/html/wrthtml.cxx | 15 | ||||
-rw-r--r-- | sw/source/uibase/dochdl/swdtflvr.cxx | 2 |
5 files changed, 43 insertions, 9 deletions
diff --git a/sw/qa/extras/tiledrendering/data/estonian.odt b/sw/qa/extras/tiledrendering/data/estonian.odt Binary files differnew file mode 100644 index 000000000000..0d1fedd6babb --- /dev/null +++ b/sw/qa/extras/tiledrendering/data/estonian.odt diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index ffc81dbc3d63..ab63c0003908 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -86,6 +86,7 @@ public: void testPostMouseEvent(); void testSetTextSelection(); void testGetTextSelection(); + void testGetTextSelectionLineLimit(); void testSetGraphicSelection(); void testResetSelection(); void testInsertShape(); @@ -169,6 +170,7 @@ public: CPPUNIT_TEST(testPostMouseEvent); CPPUNIT_TEST(testSetTextSelection); CPPUNIT_TEST(testGetTextSelection); + CPPUNIT_TEST(testGetTextSelectionLineLimit); CPPUNIT_TEST(testSetGraphicSelection); CPPUNIT_TEST(testResetSelection); CPPUNIT_TEST(testInsertShape); @@ -552,6 +554,30 @@ void SwTiledRenderingTest::testGetTextSelection() CPPUNIT_ASSERT_EQUAL(OString("Shape"), apitest::helper::transferable::getTextSelection(pXTextDocument->getSelection(), "text/plain;charset=utf-8")); } +void SwTiledRenderingTest::testGetTextSelectionLineLimit() +{ + const char sOriginalText[] = u8"Estonian employs the Latin script as the basis for its alphabet, which adds the letters ä, ö, ü, and õ, plus the later additions š and ž. The letters c, q, w, x and y are limited to proper names of foreign origin, and f, z, š, and ž appear in loanwords and foreign names only. Ö and Ü are pronounced similarly to their equivalents in Swedish and German. Unlike in standard German but like Swedish (when followed by 'r') and Finnish, Ä is pronounced [æ], as in English mat. The vowels Ä, Ö and Ü are clearly separate phonemes and inherent in Estonian, although the letter shapes come from German. The letter õ denotes /ɤ/, unrounded /o/, or a close-mid back unrounded vowel. It is almost identical to the Bulgarian ъ /ɤ̞/ and the Vietnamese ơ, and is also used to transcribe the Russian ы."; + const char sExpectedHtml[] = u8"Estonian employs the <a href=\"https://en.wikipedia.org/wiki/Latin_script\">Latin script</a> as the basis for <a href=\"https://en.wikipedia.org/wiki/Estonian_alphabet\">its alphabet</a>, which adds the letters <a href=\"https://en.wikipedia.org/wiki/%C3%84\"><i>ä</i></a>, <a href=\"https://en.wikipedia.org/wiki/%C3%96\"><i>ö</i></a>, <a href=\"https://en.wikipedia.org/wiki/%C3%9C\"><i>ü</i></a>, and <a href=\"https://en.wikipedia.org/wiki/%C3%95\"><i>õ</i></a>, plus the later additions <a href=\"https://en.wikipedia.org/wiki/%C5%A0\"><i>š</i></a> and <a href=\"https://en.wikipedia.org/wiki/%C5%BD\"><i>ž</i></a>. The letters <i>c</i>, <i>q</i>, <i>w</i>, <i>x</i> and <i>y</i> are limited to <a href=\"https://en.wikipedia.org/wiki/Proper_names\">proper names</a> of foreign origin, and <i>f</i>, <i>z</i>, <i>š</i>, and <i>ž</i> appear in loanwords and foreign names only. <i>Ö</i> and <i>Ü</i> are pronounced similarly to their equivalents in Swedish and German. Unlike in standard German but like Swedish (when followed by 'r') and Finnish, <i>Ä</i> is pronounced [æ], as in English <i>mat</i>. The vowels Ä, Ö and Ü are clearly separate <a href=\"https://en.wikipedia.org/wiki/Phonemes\">phonemes</a> and inherent in Estonian, although the letter shapes come from German. The letter <a href=\"https://en.wikipedia.org/wiki/%C3%95\"><i>õ</i></a> denotes /ɤ/, unrounded /o/, or a <a href=\"https://en.wikipedia.org/wiki/Close-mid_back_unrounded_vowel\">close-mid back unrounded vowel</a>. It is almost identical to the <a href=\"https://en.wikipedia.org/wiki/Bulgarian_language\">Bulgarian</a> <a href=\"https://en.wikipedia.org/wiki/%D0%AA\">ъ</a> /ɤ̞/ and the <a href=\"https://en.wikipedia.org/wiki/Vietnamese_language\">Vietnamese</a> <a href=\"https://en.wikipedia.org/wiki/%C6%A0\">ơ</a>, and is also used to transcribe the Russian <a href=\"https://en.wikipedia.org/wiki/%D0%AB\">ы</a>."; + + SwXTextDocument* pXTextDocument = createDoc("estonian.odt"); + + SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell(); + // Move the cursor into the first word. + pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 2, /*bBasicCall=*/false); + // 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"Estonian"); + + CPPUNIT_ASSERT(sHtmlText.match(sExpectedHtml, nStart)); +} + void SwTiledRenderingTest::testSetGraphicSelection() { SwXTextDocument* pXTextDocument = createDoc("shape.fodt"); diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx index 4c5f335597a0..0ea735ace5db 100644 --- a/sw/source/filter/html/htmlatr.cxx +++ b/sw/source/filter/html/htmlatr.cxx @@ -2225,8 +2225,10 @@ Writer& OutHTML_SwTextNode( Writer& rWrt, const SwContentNode& rNode ) rHTMLWrt.OutBookmarks(); // 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 ) + rHTMLWrt.GetLineLen() >= (rHTMLWrt.m_nWishLineLen >= 0 ? rHTMLWrt.m_nWishLineLen : 70 ) ) { rHTMLWrt.OutNewLine(); } @@ -2463,8 +2465,9 @@ Writer& OutHTML_SwTextNode( Writer& rWrt, const SwContentNode& rNode ) nWordLen = nEnd; nWordLen -= nStrPos; - if( nLineLen >= rHTMLWrt.m_nWishLineLen || - (nLineLen+nWordLen) >= rHTMLWrt.m_nWishLineLen ) + if( rHTMLWrt.m_nWishLineLen >= 0 && + (nLineLen >= rHTMLWrt.m_nWishLineLen || + (nLineLen+nWordLen) >= rHTMLWrt.m_nWishLineLen ) ) { HTMLOutFuncs::FlushToAscii( rWrt.Strm(), aContext ); rHTMLWrt.OutNewLine(); diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx index 4e4dfe722670..281296798006 100644 --- a/sw/source/filter/html/wrthtml.cxx +++ b/sw/source/filter/html/wrthtml.cxx @@ -114,7 +114,7 @@ SwHTMLWriter::SwHTMLWriter( const OUString& rBaseURL, const OUString& rFilterOpt , m_nDfltTopMargin(0) , m_nDfltBottomMargin(0) , m_nIndentLvl(0) - , m_nWishLineLen(0) + , m_nWishLineLen(70) , m_nDefListLvl(0) , m_nDefListMargin(0) , m_nHeaderFooterSpace(0) @@ -206,19 +206,25 @@ void SwHTMLWriter::SetupFilterOptions(SfxMedium& rMedium) void SwHTMLWriter::SetupFilterOptions(const OUString& rFilterOptions) { - if (rFilterOptions == "SkipImages") + if (rFilterOptions.indexOf("SkipImages") >= 0) { mbSkipImages = true; } - else if (rFilterOptions == "SkipHeaderFooter") + else if (rFilterOptions.indexOf("SkipHeaderFooter") >= 0) { mbSkipHeaderFooter = true; } - else if (rFilterOptions == "EmbedImages") + else if (rFilterOptions.indexOf("EmbedImages") >= 0) { mbEmbedImages = true; } + // this option can be "on" together with any of above + if (rFilterOptions.indexOf("NoLineLimit") >= 0) + { + m_nWishLineLen = -1; + } + const uno::Sequence<OUString> aOptionSeq = comphelper::string::convertCommaSeparated(rFilterOptions); const OUString aXhtmlNsKey("xhtmlns="); for (const auto& rOption : aOptionSeq) @@ -357,7 +363,6 @@ ErrCode SwHTMLWriter::WriteStream() m_bFirstCSS1Property = m_bFirstCSS1Rule = false; m_bCSS1IgnoreFirstPageDesc = false; m_nIndentLvl = 0; - m_nWishLineLen = 70; m_nLastLFPos = 0; m_nDefListLvl = 0; m_nDefListMargin = ((m_xTemplate.is() && !m_bCfgOutStyles) ? m_xTemplate.get() : m_pDoc) diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx index 60043a036c76..ff0b54eb0b4e 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -784,7 +784,7 @@ bool SwTransferable::WriteObject( tools::SvRef<SotStorageStream>& xStream, case SWTRANSFER_OBJECTTYPE_HTML: { // LOK is interested in getting images embedded for copy/paste support. - GetHTMLWriter( comphelper::LibreOfficeKit::isActive() ? OUString("EmbedImages") : OUString(), OUString(), xWrt ); + GetHTMLWriter( comphelper::LibreOfficeKit::isActive() ? OUString("EmbedImages;NoLineLimit") : OUString(), OUString(), xWrt ); break; } |