editeng/source/editeng/impedit3.cxx |   18 ++++++++++--------
 sw/source/core/text/porlay.cxx      |   18 ++++++++++--------
 2 files changed, 20 insertions(+), 16 deletions(-)

New commits:
commit 72e56537d4bb9411229346da977d1d669ccfca9a
Author:     Khaled Hosny <kha...@aliftype.com>
AuthorDate: Thu Aug 11 18:52:17 2022 +0200
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Sun Aug 14 21:11:15 2022 +0200

    tdf#139627: Don’t set Kashida insertion position after combining marks
    
    We were skipping the marks when checking for previous char, but not when
    setting the index to previous char.
    
    Fixes also the second part of tdf#106653.
    
    Change-Id: I73436ba9df6ccf104ea6d4dfbd76a59c86040a44
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138154
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/editeng/source/editeng/impedit3.cxx 
b/editeng/source/editeng/impedit3.cxx
index d7129999dfa5..6195b0e8e606 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -2339,10 +2339,9 @@ void ImpEditEngine::ImpFindKashidas( ContentNode* pNode, 
sal_Int32 nStart, sal_I
         // restore selection for proper iteration at the end of the function
         aWordSel.Max().SetIndex( nSavPos );
 
-        sal_Int32 nIdx = 0;
+        sal_Int32 nIdx = 0, nPrevIdx = 0;
         sal_Int32 nKashidaPos = -1;
-        sal_Unicode cCh;
-        sal_Unicode cPrevCh = 0;
+        sal_Unicode cCh, cPrevCh = 0;
 
         int nPriorityLevel = 7;    // 0..6 = level found
                                    // 7 not found
@@ -2390,7 +2389,7 @@ void ImpEditEngine::ImpFindKashidas( ContentNode* pNode, 
sal_Int32 nStart, sal_I
                     // check if character is connectable to previous character,
                     if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
                     {
-                        nKashidaPos = aWordSel.Min().GetIndex() + nIdx - 1;
+                        nKashidaPos = aWordSel.Min().GetIndex() + nPrevIdx;
                         nPriorityLevel = 2;
                     }
                 }
@@ -2411,7 +2410,7 @@ void ImpEditEngine::ImpFindKashidas( ContentNode* pNode, 
sal_Int32 nStart, sal_I
                     // check if character is connectable to previous character,
                     if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
                     {
-                        nKashidaPos = aWordSel.Min().GetIndex() + nIdx - 1;
+                        nKashidaPos = aWordSel.Min().GetIndex() + nPrevIdx;
                         nPriorityLevel = 3;
                     }
                 }
@@ -2431,7 +2430,7 @@ void ImpEditEngine::ImpFindKashidas( ContentNode* pNode, 
sal_Int32 nStart, sal_I
                         // check if character is connectable to previous 
character,
                         if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
                         {
-                            nKashidaPos = aWordSel.Min().GetIndex() + nIdx - 1;
+                            nKashidaPos = aWordSel.Min().GetIndex() + nPrevIdx;
                             nPriorityLevel = 4;
                         }
                     }
@@ -2453,7 +2452,7 @@ void ImpEditEngine::ImpFindKashidas( ContentNode* pNode, 
sal_Int32 nStart, sal_I
                     // check if character is connectable to previous character,
                     if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
                     {
-                        nKashidaPos = aWordSel.Min().GetIndex() + nIdx - 1;
+                        nKashidaPos = aWordSel.Min().GetIndex() + nPrevIdx;
                         nPriorityLevel = 5;
                     }
                 }
@@ -2469,7 +2468,7 @@ void ImpEditEngine::ImpFindKashidas( ContentNode* pNode, 
sal_Int32 nStart, sal_I
                     // check if character is connectable to previous character,
                     if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
                     {
-                        nKashidaPos = aWordSel.Min().GetIndex() + nIdx - 1;
+                        nKashidaPos = aWordSel.Min().GetIndex() + nPrevIdx;
                         nPriorityLevel = 6;
                     }
                 }
@@ -2478,7 +2477,10 @@ void ImpEditEngine::ImpFindKashidas( ContentNode* pNode, 
sal_Int32 nStart, sal_I
             // Do not consider vowel marks when checking if a character
             // can be connected to previous character.
             if ( !isTransparentChar ( cCh) )
+            {
                 cPrevCh = cCh;
+                nPrevIdx = nIdx;
+            }
 
             ++nIdx;
         } // end of current word
diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index 3db6a07600e9..d1e4b967f235 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -1509,10 +1509,9 @@ void SwScriptInfo::InitScriptInfo(const SwTextNode& 
rNode,
             {
                 const OUString& rWord = aScanner.GetWord();
 
-                sal_Int32 nIdx = 0;
+                sal_Int32 nIdx = 0, nPrevIdx = 0;
                 sal_Int32 nKashidaPos = -1;
-                sal_Unicode cCh;
-                sal_Unicode cPrevCh = 0;
+                sal_Unicode cCh, cPrevCh = 0;
 
                 int nPriorityLevel = 7;    // 0..6 = level found
                                            // 7 not found
@@ -1560,7 +1559,7 @@ void SwScriptInfo::InitScriptInfo(const SwTextNode& rNode,
                             // check if character is connectable to previous 
character,
                             if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
                             {
-                                nKashidaPos = aScanner.GetBegin() + nIdx - 1;
+                                nKashidaPos = aScanner.GetBegin() + nPrevIdx;
                                 nPriorityLevel = 2;
                             }
                         }
@@ -1581,7 +1580,7 @@ void SwScriptInfo::InitScriptInfo(const SwTextNode& rNode,
                             // check if character is connectable to previous 
character,
                             if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
                             {
-                                nKashidaPos = aScanner.GetBegin() + nIdx - 1;
+                                nKashidaPos = aScanner.GetBegin() + nPrevIdx;
                                 nPriorityLevel = 3;
                             }
                         }
@@ -1601,7 +1600,7 @@ void SwScriptInfo::InitScriptInfo(const SwTextNode& rNode,
                                 // check if character is connectable to 
previous character,
                                 if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
                                 {
-                                    nKashidaPos = aScanner.GetBegin() + nIdx - 
1;
+                                    nKashidaPos = aScanner.GetBegin() + 
nPrevIdx;
                                     nPriorityLevel = 4;
                                 }
                             }
@@ -1623,7 +1622,7 @@ void SwScriptInfo::InitScriptInfo(const SwTextNode& rNode,
                             // check if character is connectable to previous 
character,
                             if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
                             {
-                                nKashidaPos = aScanner.GetBegin() + nIdx - 1;
+                                nKashidaPos = aScanner.GetBegin() + nPrevIdx;
                                 nPriorityLevel = 5;
                             }
                         }
@@ -1639,7 +1638,7 @@ void SwScriptInfo::InitScriptInfo(const SwTextNode& rNode,
                             // check if character is connectable to previous 
character,
                             if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
                             {
-                                nKashidaPos = aScanner.GetBegin() + nIdx - 1;
+                                nKashidaPos = aScanner.GetBegin() + nPrevIdx;
                                 nPriorityLevel = 6;
                             }
                         }
@@ -1648,7 +1647,10 @@ void SwScriptInfo::InitScriptInfo(const SwTextNode& 
rNode,
                     // Do not consider vowel marks when checking if a character
                     // can be connected to previous character.
                     if ( !isTransparentChar ( cCh) )
+                    {
                         cPrevCh = cCh;
+                        nPrevIdx = nIdx;
+                    }
 
                     ++nIdx;
                 } // end of current word

Reply via email to