editeng/inc/edtspell.hxx | 3 ++- editeng/qa/unit/core-test.cxx | 3 ++- editeng/source/editeng/edtspell.cxx | 2 +- include/editeng/svxacorr.hxx | 3 ++- sw/qa/extras/uiwriter/data/tdf143176.fodt | 20 ++++++++++++++++++++ sw/qa/extras/uiwriter/uiwriter4.cxx | 20 ++++++++++++++++++++ sw/source/core/edit/acorrect.cxx | 4 ++-- sw/source/core/edit/autofmt.cxx | 21 ++++++++++++--------- sw/source/core/inc/acorrect.hxx | 3 ++- 9 files changed, 63 insertions(+), 16 deletions(-)
New commits: commit f5ff7a967b09a715c56630aff92cfb636e7c232b Author: László Németh <nem...@numbertext.org> AuthorDate: Mon Jun 14 09:22:35 2021 +0200 Commit: László Németh <nem...@numbertext.org> CommitDate: Sat Jul 3 17:25:44 2021 +0200 tdf#143176 Old Hungarian transliteration: fix AutoCorrect->Apply and "Apply and Edit Changes". Transliteration worked only during typing, because AutoCorrect->Apply and "Apply and Edit Changes" remove right-to-left text direction silently, which resulted missing transliteration of text (with Default Paragraph Style and right-to-left direction) to Old Hungarian. Change-Id: I1481d958494828b6dce66f2eeecb44b327c70db4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118346 Tested-by: Jenkins Reviewed-by: László Németh <nem...@numbertext.org> diff --git a/editeng/inc/edtspell.hxx b/editeng/inc/edtspell.hxx index 91e2218dad06..3332fce4e1e6 100644 --- a/editeng/inc/edtspell.hxx +++ b/editeng/inc/edtspell.hxx @@ -131,7 +131,8 @@ public: virtual bool ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos, SvxAutoCorrect& rACorrect, OUString* pPara ) override; - virtual bool TransliterateRTLWord( sal_Int32& rSttPos, sal_Int32 nEndPos ) override; + virtual bool TransliterateRTLWord( sal_Int32& rSttPos, sal_Int32 nEndPos, + bool bApply = false ) override; virtual LanguageType GetLanguage( sal_Int32 nPos ) const override; diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx index dca5a0a8babf..0859a018ca0a 100644 --- a/editeng/qa/unit/core-test.cxx +++ b/editeng/qa/unit/core-test.cxx @@ -427,7 +427,8 @@ private: return false; } - virtual bool TransliterateRTLWord( sal_Int32& /*rSttPos*/, sal_Int32 /*nEndPos*/ ) override + virtual bool TransliterateRTLWord( sal_Int32& /*rSttPos*/, + sal_Int32 /*nEndPos*/, bool /*bApply*/ ) override { return false; } diff --git a/editeng/source/editeng/edtspell.cxx b/editeng/source/editeng/edtspell.cxx index f3aa07e25c1e..fdd0593418cc 100644 --- a/editeng/source/editeng/edtspell.cxx +++ b/editeng/source/editeng/edtspell.cxx @@ -681,7 +681,7 @@ bool EdtAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, } bool EdtAutoCorrDoc::TransliterateRTLWord( sal_Int32& /*rSttPos*/, - sal_Int32 /*nEndPos*/ ) + sal_Int32 /*nEndPos*/, bool /*bApply*/ ) { // Paragraph-start or a blank found, search for the word // shortcut in Auto diff --git a/include/editeng/svxacorr.hxx b/include/editeng/svxacorr.hxx index d386a6888f9a..4d21049a9d3c 100644 --- a/include/editeng/svxacorr.hxx +++ b/include/editeng/svxacorr.hxx @@ -122,7 +122,8 @@ public: virtual bool ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos, SvxAutoCorrect& rACorrect, OUString* pPara ) = 0; - virtual bool TransliterateRTLWord( sal_Int32& rSttPos, sal_Int32 nEndPos ) = 0; + virtual bool TransliterateRTLWord( sal_Int32& rSttPos, sal_Int32 nEndPos, + bool bApply = false ) = 0; // Is called after the change of the signs by the functions // - FnCapitalStartWord diff --git a/sw/qa/extras/uiwriter/data/tdf143176.fodt b/sw/qa/extras/uiwriter/data/tdf143176.fodt new file mode 100644 index 000000000000..fdd89c38da3c --- /dev/null +++ b/sw/qa/extras/uiwriter/data/tdf143176.fodt @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:styles> + <style:style style:name="Standard" style:family="paragraph" style:class="text"/> + <style:default-style style:family="paragraph"> + <style:text-properties fo:language="hu" fo:country="HU" style:writing-mode="rl-tb"/> + </style:default-style> + </office:styles> + <office:automatic-styles> + <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Standard"> + <style:paragraph-properties fo:text-align="end" style:justify-single-word="false" style:writing-mode="rl-tb"/> + </style:style> + </office:automatic-styles> + <office:body> + <office:text> + <text:p text:style-name="P1">Lorem ipsum dolor sit amet,</text:p> + <text:p text:style-name="P1">consectetur adipiscing elit.</text:p> + </office:text> + </office:body> +</office:document> diff --git a/sw/qa/extras/uiwriter/uiwriter4.cxx b/sw/qa/extras/uiwriter/uiwriter4.cxx index 1c8e3ad1fbaf..d93447d71dc2 100644 --- a/sw/qa/extras/uiwriter/uiwriter4.cxx +++ b/sw/qa/extras/uiwriter/uiwriter4.cxx @@ -271,6 +271,7 @@ public: void testTdf128860(); void testTdf123786(); void testTdf133589(); + void testTdf143176(); void testInconsistentBookmark(); void testInsertLongDateFormat(); void testSpellOnlineParameter(); @@ -386,6 +387,7 @@ public: CPPUNIT_TEST(testTdf128860); CPPUNIT_TEST(testTdf123786); CPPUNIT_TEST(testTdf133589); + CPPUNIT_TEST(testTdf143176); CPPUNIT_TEST(testInsertLongDateFormat); CPPUNIT_TEST(testSpellOnlineParameter); CPPUNIT_TEST(testRedlineAutoCorrect); @@ -3570,6 +3572,24 @@ void SwUiWriterTest4::testTdf133589() CPPUNIT_ASSERT_EQUAL(sReplaced, static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText()); } +void SwUiWriterTest4::testTdf143176() +{ + // Hungarian test document with right-to-left paragraph setting + createSwDoc(DATA_DIRECTORY, "tdf143176.fodt"); + + // transliterate the document to Old Hungarian (note: it only works + // with right-to-left text direction and Default Paragraph Style) + dispatchCommand(mxComponent, ".uno:AutoFormatApply", {}); + + // This was the original "Lorem ipsum..." + CPPUNIT_ASSERT_EQUAL(OUString(u"𐲖𐳛𐳢𐳉𐳘 𐳐𐳠𐳤𐳪𐳘 𐳇𐳛𐳖𐳛𐳢 " + u"𐳤𐳐𐳦 𐳀𐳘𐳉𐳦⹁"), + getParagraph(1)->getString()); + CPPUNIT_ASSERT_EQUAL(OUString(u"𐳄𐳛𐳙𐳤𐳉𐳄𐳦𐳉𐳦𐳪𐳢 " + u"𐳀𐳇𐳐𐳠𐳐𐳤𐳄𐳐𐳙𐳍 𐳉𐳖𐳐𐳦."), + getParagraph(2)->getString()); +} + void SwUiWriterTest4::testInsertLongDateFormat() { // only for Hungarian, yet diff --git a/sw/source/core/edit/acorrect.cxx b/sw/source/core/edit/acorrect.cxx index 1a5ffe5ca762..9a8e45cb137c 100644 --- a/sw/source/core/edit/acorrect.cxx +++ b/sw/source/core/edit/acorrect.cxx @@ -507,7 +507,7 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos, return bRet; } -bool SwAutoCorrDoc::TransliterateRTLWord( sal_Int32& rSttPos, sal_Int32 nEndPos ) +bool SwAutoCorrDoc::TransliterateRTLWord( sal_Int32& rSttPos, sal_Int32 nEndPos, bool bApply ) { if( m_bUndoIdInitialized ) m_bUndoIdInitialized = true; @@ -530,7 +530,7 @@ bool SwAutoCorrDoc::TransliterateRTLWord( sal_Int32& rSttPos, sal_Int32 nEndPos const OUString sFrameText = pFrame->GetText(); SwDoc* pDoc = m_rEditSh.GetDoc(); - if ( pFrame->IsRightToLeft() ) + if ( pFrame->IsRightToLeft() || bApply ) { // transliterate to Old Hungarian using Numbertext via NatNum12 number format modifier OUString sWord(sFrameText.copy(rSttPos, nEndPos - rSttPos)); diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx index 12df8e7383e9..0763cc06784c 100644 --- a/sw/source/core/edit/autofmt.cxx +++ b/sw/source/core/edit/autofmt.cxx @@ -94,6 +94,7 @@ class SwAutoFormat SwDoc* m_pDoc; SwTextNode* m_pCurTextNd; // the current TextNode SwTextFrame* m_pCurTextFrame; // frame of the current TextNode + bool m_bIsRightToLeft; // text direction of the current frame sal_uLong m_nEndNdIdx; // for the percentage-display mutable std::unique_ptr<CharClass> m_pCharClass; // Character classification mutable LanguageType m_eCharClassLang; @@ -336,6 +337,7 @@ void SwAutoFormat::GoNextPara() m_pCurTextNd = static_cast<SwTextNode*>(pNewNd); m_pCurTextFrame = GetFrame( *m_pCurTextNd ); + m_bIsRightToLeft = m_pCurTextFrame->IsRightToLeft(); } bool SwAutoFormat::HasObjects(const SwTextFrame & rFrame) @@ -2142,8 +2144,14 @@ void SwAutoFormat::AutoCorrect(TextFrameIndex nPos) { *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos); SetRedlineText( STR_AUTOFMTREDL_USE_REPLACE ); - if( m_aFlags.bAutoCorrect && - aACorrDoc.ChgAutoCorrWord(reinterpret_cast<sal_Int32&>(nSttPos), sal_Int32(nPos), *pATst, nullptr)) + + LanguageType eLang = bGetLanguage + ? m_pCurTextFrame->GetLangOfChar(nSttPos, 0, true) + : LANGUAGE_SYSTEM; + + if( m_bIsRightToLeft && m_aFlags.bTransliterateRTL && eLang == LANGUAGE_HUNGARIAN && + SetRedlineText( STR_AUTOFMTREDL_TRANSLITERATE_RTL ) && + aACorrDoc.TransliterateRTLWord(reinterpret_cast<sal_Int32&>(nSttPos), sal_Int32(nPos), /*bApply=*/true)) { nPos = m_pCurTextFrame->MapModelToViewPos(*m_aDelPam.GetPoint()); @@ -2160,13 +2168,8 @@ void SwAutoFormat::AutoCorrect(TextFrameIndex nPos) continue; // do not check further } - LanguageType eLang = bGetLanguage - ? m_pCurTextFrame->GetLangOfChar(nSttPos, 0, true) - : LANGUAGE_SYSTEM; - - if( m_aFlags.bTransliterateRTL && eLang == LANGUAGE_HUNGARIAN && - SetRedlineText( STR_AUTOFMTREDL_TRANSLITERATE_RTL ) && - aACorrDoc.TransliterateRTLWord(reinterpret_cast<sal_Int32&>(nSttPos), sal_Int32(nPos))) + if( m_aFlags.bAutoCorrect && + aACorrDoc.ChgAutoCorrWord(reinterpret_cast<sal_Int32&>(nSttPos), sal_Int32(nPos), *pATst, nullptr) ) { nPos = m_pCurTextFrame->MapModelToViewPos(*m_aDelPam.GetPoint()); if( m_aFlags.bWithRedlining ) diff --git a/sw/source/core/inc/acorrect.hxx b/sw/source/core/inc/acorrect.hxx index f8c9c765ec41..ef826f78da04 100644 --- a/sw/source/core/inc/acorrect.hxx +++ b/sw/source/core/inc/acorrect.hxx @@ -80,7 +80,8 @@ public: virtual bool ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos, SvxAutoCorrect& rACorrect, OUString* pPara ) override; - virtual bool TransliterateRTLWord( sal_Int32& rSttPos, sal_Int32 nEndPos ) override; + virtual bool TransliterateRTLWord( sal_Int32& rSttPos, sal_Int32 nEndPos, + bool bApply = false ) override; // Will be called after swapping characters by the functions // - FnCapitalStartWord and _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits