editeng/source/editeng/impedit3.cxx |   22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

New commits:
commit 9063d99ff5ee43cc1239fc1dbb5d9897bdda1c9b
Author:     Khaled Hosny <kha...@aliftype.com>
AuthorDate: Sun Oct 2 22:45:24 2022 +0200
Commit:     خالد حسني <kha...@aliftype.com>
CommitDate: Mon Oct 3 01:39:56 2022 +0200

    tdf#137528: Fix skipping Kashida in fonts with bogus ones
    
    There was a typo in the check, and we also want to fallback to using
    blanks if no Kashidas were found, so check for Kashida positions first.
    
    Change-Id: I64cc3bf5c76ecc01764073bb5a2302520157fad8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140896
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@aliftype.com>

diff --git a/editeng/source/editeng/impedit3.cxx 
b/editeng/source/editeng/impedit3.cxx
index cf30aada8448..6efc74d95cfe 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -2190,14 +2190,19 @@ void ImpEditEngine::ImpAdjustBlocks( ParaPortion* 
pParaPortion, EditLine* pLine,
 
     // Search blanks or Kashidas...
     std::vector<sal_Int32> aPositions;
+
+    // Kashidas ?
+    ImpFindKashidas( pNode, nFirstChar, nLastChar, aPositions );
+    auto nKashidas = aPositions.size();
+
     sal_uInt16 nLastScript = i18n::ScriptType::LATIN;
     for ( sal_Int32 nChar = nFirstChar; nChar <= nLastChar; nChar++ )
     {
         EditPaM aPaM( pNode, nChar+1 );
         LanguageType eLang = GetLanguage(aPaM).nLang;
         sal_uInt16 nScript = GetI18NScriptType(aPaM);
-        if ( MsLangId::getPrimaryLanguage( eLang) == 
LANGUAGE_ARABIC_PRIMARY_ONLY )
-            // Arabic script is handled later.
+        // Arabic script is handled above, but if no Kashida positions are 
found, use blanks.
+        if (MsLangId::getPrimaryLanguage(eLang) == 
LANGUAGE_ARABIC_PRIMARY_ONLY && nKashidas)
             continue;
 
         if ( pNode->GetChar(nChar) == ' ' )
@@ -2223,13 +2228,6 @@ void ImpEditEngine::ImpAdjustBlocks( ParaPortion* 
pParaPortion, EditLine* pLine,
         nLastScript = nScript;
     }
 
-    // Save the number of blanks, we will use it below when marking Kashida
-    // positions.
-    auto nBlankSize = aPositions.size();
-
-    // Kashidas ?
-    ImpFindKashidas( pNode, nFirstChar, nLastChar, aPositions );
-
     if ( aPositions.empty() )
         return;
 
@@ -2268,10 +2266,10 @@ void ImpEditEngine::ImpAdjustBlocks( ParaPortion* 
pParaPortion, EditLine* pLine,
 
     // Mark Kashida positions, so that VCL knows where to insert Kashida and
     // where to only expand the width.
-    if (aPositions.size() > nBlankSize)
+    if (nKashidas)
     {
         pLine->GetKashidaArray().resize(pLine->GetCharPosArray().size(), 
false);
-        for (auto i = nBlankSize; i < aPositions.size(); i++)
+        for (size_t i = 0; i < nKashidas; i++)
         {
             auto nChar = aPositions[i];
             if ( nChar < nLastChar )
@@ -2316,7 +2314,7 @@ void ImpEditEngine::ImpAdjustBlocks( ParaPortion* 
pParaPortion, EditLine* pLine,
 void ImpEditEngine::ImpFindKashidas( ContentNode* pNode, sal_Int32 nStart, 
sal_Int32 nEnd, std::vector<sal_Int32>& rArray )
 {
     // Kashida glyph looks suspicious, skip Kashida justification
-    if (GetRefDevice()->GetMinKashida() < 0)
+    if (GetRefDevice()->GetMinKashida() <= 0)
         return;
 
     std::vector<sal_Int32> aKashidaArray;

Reply via email to