From 5b494880e86dfdb702f9cda807253fa575814d6f Mon Sep 17 00:00:00 2001 From: Jonathan Clark Date: Tue, 24 Sep 2024 20:24:10 -0600 Subject: [PATCH] tdf#163105 Require kashida after Seen, even before a final Yeh Small tweak to the kashida insertion rules to restore some previous behavior. Kashida should not be inserted after a final Yeh, but should be inserted after an initial or medial Seen, even if it is followed by a final Yeh. Change-Id: I1fef2d32961c6f55006b2df456827588f62af40b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173889 Reviewed-by: Jonathan Clark Tested-by: Jenkins --- i18nutil/qa/cppunit/test_kashida.cxx | 6 ++++-- i18nutil/source/utility/kashida.cxx | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/i18nutil/qa/cppunit/test_kashida.cxx b/i18nutil/qa/cppunit/test_kashida.cxx index 55f943a318a4..1ab2729cb06a 100644 --- a/i18nutil/qa/cppunit/test_kashida.cxx +++ b/i18nutil/qa/cppunit/test_kashida.cxx @@ -37,7 +37,7 @@ void KashidaTest::testCharacteristic() // Characteristic tests for kashida candidate selection. // Uses words from sample documents. CPPUNIT_ASSERT_EQUAL(sal_Int32(1), GetWordKashidaPosition(u"متن"_ustr).value().nIndex); - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), GetWordKashidaPosition(u"فارسی"_ustr).value().nIndex); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), GetWordKashidaPosition(u"فارسی"_ustr).value().nIndex); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), GetWordKashidaPosition(u"با"_ustr).value().nIndex); CPPUNIT_ASSERT_EQUAL(sal_Int32(3), GetWordKashidaPosition(u"نویسه"_ustr).value().nIndex); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), GetWordKashidaPosition(u"کشیده"_ustr).value().nIndex); @@ -58,7 +58,9 @@ void KashidaTest::testCharacteristic() void KashidaTest::testFinalYeh() { CPPUNIT_ASSERT(!GetWordKashidaPosition(u"نیمِي"_ustr).has_value()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), GetWordKashidaPosition(u"كرسي"_ustr).value().nIndex); + + // Should always insert kashida after Seen, even before a final Yeh + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), GetWordKashidaPosition(u"كرسي"_ustr).value().nIndex); } // #i98410#: Do not insert kashida under a ZWNJ diff --git a/i18nutil/source/utility/kashida.cxx b/i18nutil/source/utility/kashida.cxx index c4aea0069dd5..d016e96294fb 100644 --- a/i18nutil/source/utility/kashida.cxx +++ b/i18nutil/source/utility/kashida.cxx @@ -44,7 +44,8 @@ namespace /* The LibreOffice implementation modifies the above rules, as follows: - - tdf#65344: Kashida must not be inserted before the final form of Yeh. + - tdf#65344: Kashida must not be inserted before the final form of Yeh, unless + preceded by an initial or medial Seen. */ #define IS_JOINING_GROUP(c, g) (u_getIntPropertyValue((c), UCHAR_JOINING_GROUP) == U_JG_##g) @@ -152,7 +153,7 @@ std::optional i18nutil::GetWordKashidaPosition(const } auto fnTryInsertBefore = [&rWord, &nIdx, &nPrevIdx, &nKashidaPos, &nPriorityLevel, - &nWordLen](sal_Int32 nNewPriority) { + &nWordLen](sal_Int32 nNewPriority, bool bIgnoreFinalYeh = false) { // Exclusions: // #i98410#: prevent ZWNJ expansion @@ -162,7 +163,7 @@ std::optional i18nutil::GetWordKashidaPosition(const } // tdf#65344: Do not insert kashida before a final Yeh - if (nIdx == (nWordLen - 1) && isYehChar(rWord[nIdx])) + if (!bIgnoreFinalYeh && nIdx == (nWordLen - 1) && isYehChar(rWord[nIdx])) { return; } @@ -190,7 +191,7 @@ std::optional i18nutil::GetWordKashidaPosition(const { if (isSeenOrSadChar(cPrevCh)) { - fnTryInsertBefore(1); + fnTryInsertBefore(1, /*bIgnoreFinalYeh*/ true); } }