vcl/source/text/ImplLayoutArgs.cxx |   21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)

New commits:
commit b3bdb10195cca95b632d0489a16a675b4717754d
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Mon May 23 11:26:43 2022 +0200
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Tue May 24 13:25:23 2022 +0200

    do not use ubidi_setLine() for text runs
    
    As far as I understand this, the setLine() is meant to be called for
    every line in the paragraph set by setPara(), but
    - our text layout API does not say this in any way, it may be kind of
    assumed that a substring is a line in a paragraph, but it's not a given,
    as we call layout functions also e.g. for underlined parts of the text
    - as I understand it after looking at the source of that function,
    it really just changes processing to work on a subset of the paragraph,
    so all it seems to do is to prepare the whole text once with setPara()
    and then reuse that with repeated calls to setLine(), so it's basically
    just an optimization, but here using setPara() on the entire string
    actually should make it slower by processing parts of the string that
    are not used
    - if the substring contains some control characters that may be
    interpreted as going to the next paragraph (#moz147714-1 does this with
    0x1e record-separator character), then setLine() will fail because
    it will not consider the substring to be in just one paragraph and there
    will be no run detected
    
    Change-Id: Ided1d777f086f7905732b408e845405db0163e49
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134763
    Tested-by: Luboš Luňák <l.lu...@collabora.com>
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/vcl/source/text/ImplLayoutArgs.cxx 
b/vcl/source/text/ImplLayoutArgs.cxx
index 0638473f4168..dbdc6e18f5a0 100644
--- a/vcl/source/text/ImplLayoutArgs.cxx
+++ b/vcl/source/text/ImplLayoutArgs.cxx
@@ -59,28 +59,19 @@ ImplLayoutArgs::ImplLayoutArgs(const OUString& rStr, int 
nMinCharPos, int nEndCh
         // prepare substring for BiDi analysis
         // TODO: reuse allocated pParaBidi
         UErrorCode rcI18n = U_ZERO_ERROR;
-        const int nLength = mrStr.getLength();
+        const int nLength = mnEndCharPos - mnMinCharPos;
         UBiDi* pParaBidi = ubidi_openSized(nLength, 0, &rcI18n);
         if (!pParaBidi)
             return;
-        ubidi_setPara(pParaBidi, reinterpret_cast<const 
UChar*>(mrStr.getStr()), nLength, nLevel,
-                      nullptr, &rcI18n);
-
-        UBiDi* pLineBidi = pParaBidi;
-        int nSubLength = mnEndCharPos - mnMinCharPos;
-        if (nSubLength != nLength)
-        {
-            pLineBidi = ubidi_openSized(nSubLength, 0, &rcI18n);
-            ubidi_setLine(pParaBidi, mnMinCharPos, mnEndCharPos, pLineBidi, 
&rcI18n);
-        }
+        ubidi_setPara(pParaBidi, reinterpret_cast<const 
UChar*>(mrStr.getStr()) + mnMinCharPos,
+                      nLength, nLevel, nullptr, &rcI18n);
 
         // run BiDi algorithm
-        const int nRunCount = ubidi_countRuns(pLineBidi, &rcI18n);
-        //maRuns.resize( 2 * nRunCount );
+        const int nRunCount = ubidi_countRuns(pParaBidi, &rcI18n);
         for (int i = 0; i < nRunCount; ++i)
         {
             int32_t nMinPos, nRunLength;
-            const UBiDiDirection nDir = ubidi_getVisualRun(pLineBidi, i, 
&nMinPos, &nRunLength);
+            const UBiDiDirection nDir = ubidi_getVisualRun(pParaBidi, i, 
&nMinPos, &nRunLength);
             const int nPos0 = nMinPos + mnMinCharPos;
             const int nPos1 = nPos0 + nRunLength;
 
@@ -89,8 +80,6 @@ ImplLayoutArgs::ImplLayoutArgs(const OUString& rStr, int 
nMinCharPos, int nEndCh
         }
 
         // cleanup BiDi engine
-        if (pLineBidi != pParaBidi)
-            ubidi_close(pLineBidi);
         ubidi_close(pParaBidi);
     }
 

Reply via email to