summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2021-06-14 09:22:35 +0200
committerLászló Németh <nemeth@numbertext.org>2021-07-03 18:50:40 +0200
commitac647b3da0e47ebe1c83093ca3cc1aae9efd55b2 (patch)
tree02583a94b129bb20342d9d7b3f40f0bd6654bfe4 /sw
parentcaad77052f9d0c9e59ce8231d67827f2106fbc60 (diff)
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 <nemeth@numbertext.org> (cherry picked from commit f5ff7a967b09a715c56630aff92cfb636e7c232b) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118305
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/uiwriter/data/tdf143176.fodt20
-rw-r--r--sw/qa/extras/uiwriter/uiwriter4.cxx20
-rw-r--r--sw/source/core/edit/acorrect.cxx4
-rw-r--r--sw/source/core/edit/autofmt.cxx21
-rw-r--r--sw/source/core/inc/acorrect.hxx3
5 files changed, 56 insertions, 12 deletions
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 dc3871dc1389..3d008a7e1801 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);
@@ -3581,6 +3583,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