editeng/source/misc/svxacorr.cxx | 22 ++++++++++++++++++++++ include/editeng/svxacorr.hxx | 1 + sw/qa/extras/uiwriter/data/tdf128860.fodt | 14 ++++++++++++++ sw/qa/extras/uiwriter/uiwriter.cxx | 27 +++++++++++++++++++++++++++ 4 files changed, 64 insertions(+)
New commits: commit c3ef223ba5f893f8096d205ef09b5f5262ab6baa Author: László Németh <nem...@numbertext.org> AuthorDate: Fri May 29 16:46:44 2020 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue Jun 2 15:42:43 2020 +0200 tdf#128860 AutoCorrect: fix apostrophe in Czech, German, Icelandic, Slovak and Slovene at "Single quotes" replacement outside of second level quotations. For example: ‚quote' -> ‚quote‘ but now apostrophe' -> apostrophe’ instead of the bad apostrophe' -> apostrophe‘ Change-Id: Ie6d367639cb80ec9f11e4d824b87f537e5285182 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95213 Tested-by: Jenkins Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> (cherry picked from commit a0c90f1bccd9b5a349d3199746facab549f27dba) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95316 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx index 24a5235e9c1a..b381b1726f45 100644 --- a/editeng/source/misc/svxacorr.cxx +++ b/editeng/source/misc/svxacorr.cxx @@ -316,6 +316,7 @@ static constexpr sal_Unicode cRightDoubleAngleQuote = 0xBB; // (the first character is also the opening quote we are looking for) const sal_Unicode aStopDoubleAngleQuoteStart[] = { 0x201E, 0x201D, 0 }; // preceding ,, const sal_Unicode aStopDoubleAngleQuoteEnd[] = { cRightDoubleAngleQuote, cLeftDoubleAngleQuote, 0x201D, 0x201E, 0 }; // preceding >> +const sal_Unicode aStopSingleQuoteEnd[] = { 0x201A, 0x2018, 0x201C, 0x201E, 0 }; SvxAutoCorrect::SvxAutoCorrect( const OUString& rShareAutocorrFile, const OUString& rUserAutocorrFile ) @@ -1209,6 +1210,8 @@ void SvxAutoCorrect::InsertQuote( SvxAutoCorrDoc& rDoc, sal_Int32 nInsPos, ? cLeftDoubleAngleQuote : cRightDoubleAngleQuote; } + else if ( eType == ACQuotes::UseApostrophe ) + cRet = cApostrophe; else cRet = GetQuote( cInsChar, bSttQuote, eLang ); @@ -1341,6 +1344,25 @@ void SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& rDoc, const OUString& rTxt, { eType = ACQuotes::DoubleAngleQuote; } + // tdf#128860 use apostrophe outside of second level quotation in Czech, German, Icelandic, + // Slovak and Slovenian instead of the – in this case, bad – closing quotation mark U+2018. + else if ( bSingle && nInsPos && !bSttQuote && + ( primary(eLang) == primary(LANGUAGE_GERMAN) || eLang.anyOf ( + LANGUAGE_CZECH, + LANGUAGE_ICELANDIC, + LANGUAGE_SLOVAK, + LANGUAGE_SLOVENIAN ) ) && + !lcl_HasPrecedingChar( rTxt, nInsPos, aStopSingleQuoteEnd[0], aStopSingleQuoteEnd + 1 ) ) + { + LocaleDataWrapper& rLcl = GetLocaleDataWrapper( eLang ); + CharClass& rCC = GetCharClass( eLang ); + if ( rLcl.getQuotationMarkStart() == OUStringChar(aStopSingleQuoteEnd[0]) && + // use apostrophe only after letters, not after digits or punctuation + rCC.isLetter(rTxt, nInsPos-1) ) + { + eType = ACQuotes::UseApostrophe; + } + } } if ( eType == ACQuotes::NONE && !bSingle && diff --git a/include/editeng/svxacorr.hxx b/include/editeng/svxacorr.hxx index c9d9a866a949..697ac614f76d 100644 --- a/include/editeng/svxacorr.hxx +++ b/include/editeng/svxacorr.hxx @@ -86,6 +86,7 @@ enum class ACQuotes NonBreakingSpace, CapitalizeIAm, DoubleAngleQuote, + UseApostrophe, }; // TODO: handle code points > U+FFFF and check users of this class diff --git a/sw/qa/extras/uiwriter/data/tdf128860.fodt b/sw/qa/extras/uiwriter/data/tdf128860.fodt new file mode 100644 index 000000000000..5e93b60f667b --- /dev/null +++ b/sw/qa/extras/uiwriter/data/tdf128860.fodt @@ -0,0 +1,14 @@ +<?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="de" fo:country="DE"/> + </style:default-style> + </office:styles> + <office:body> + <office:text> + <text:p text:style-name="Standard"></text:p> + </office:text> + </office:body> +</office:document> diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 9ba5cb946328..1cdc40cc43a6 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -369,6 +369,7 @@ public: void testTdf38394(); void testTdf59666(); void testTdf133524(); + void testTdf128860(); void testInconsistentBookmark(); #if HAVE_FEATURE_PDFIUM void testInsertPdf(); @@ -584,6 +585,7 @@ public: CPPUNIT_TEST(testTdf38394); CPPUNIT_TEST(testTdf59666); CPPUNIT_TEST(testTdf133524); + CPPUNIT_TEST(testTdf128860); #if HAVE_FEATURE_PDFIUM CPPUNIT_TEST(testInsertPdf); #endif @@ -7240,6 +7242,31 @@ void SwUiWriterTest::testTdf133524() CPPUNIT_ASSERT_EQUAL(sReplaced, static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText()); } +void SwUiWriterTest::testTdf128860() +{ + SwDoc* pDoc = createDoc("tdf128860.fodt"); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + // Second level ending quote: ‚word' -> ,word‘ + SwAutoCorrect corr(*SvxAutoCorrCfg::Get().GetAutoCorrect()); + pWrtShell->Insert(u"‚word"); + pWrtShell->AutoCorrect(corr, '\''); + sal_uLong nIndex = pWrtShell->GetCursor()->GetNode().GetIndex(); + OUString sReplaced(u"‚word‘"); + CPPUNIT_ASSERT_EQUAL(sReplaced, static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText()); + // Us apostrophe without preceding starting quote: word' -> word’ + pWrtShell->Insert(u" word"); + pWrtShell->AutoCorrect(corr, '\''); + nIndex = pWrtShell->GetCursor()->GetNode().GetIndex(); + sReplaced += u" word’"; + CPPUNIT_ASSERT_EQUAL(sReplaced, static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText()); + // But only after letters: word.' -> word.‘ + pWrtShell->Insert(u" word."); + pWrtShell->AutoCorrect(corr, '\''); + nIndex = pWrtShell->GetCursor()->GetNode().GetIndex(); + sReplaced += u" word.‘"; + CPPUNIT_ASSERT_EQUAL(sReplaced, static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText()); +} + #if HAVE_FEATURE_PDFIUM void SwUiWriterTest::testInsertPdf() { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits