sw/source/core/txtnode/fntcache.cxx |   41 +++++++++---------------------------
 1 file changed, 11 insertions(+), 30 deletions(-)

New commits:
commit b37764993f7e524dbe2cf79ca921d0b01e6fba97
Author:     Khaled Hosny <kha...@aliftype.com>
AuthorDate: Sun Sep 25 11:37:05 2022 +0200
Commit:     Adolfo Jayme Barrientos <fit...@ubuntu.com>
CommitDate: Sun Oct 16 01:53:03 2022 +0200

    tdf#150726: Pass full string to DrawTextArray() when drawing bullet
    
    When drawing bullets for spaces, we were passing a substring to
    DrawTextArray() and even taking care of adding an extra character to
    both sides to help with Arabic layout. This, however, does not work when
    part of the text is in different color because the portion will cover
    only that substring and we wouldn’t be passing enough context.
    
    Copying the substring is unnecessary, though, and we can pass the full
    string like we do in the non-bullet case. The bullet array (where we
    replace spaces with bullets), can continue to be a substring as we are
    only drawing the bullets in this case.
    
    This probably also means we can re-use the glyph cache when switching
    between bullet and non-bullet mode.
    
    Change-Id: I256ae7b6d592b8c6670d66619e428f943714be57
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140568
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@aliftype.com>
    (cherry picked from commit 092e37a284ea8b8bc1e8dabbbeb001c98012a996)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141398
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>

diff --git a/sw/source/core/txtnode/fntcache.cxx 
b/sw/source/core/txtnode/fntcache.cxx
index 12613bfd3b7f..f787c55ec654 100644
--- a/sw/source/core/txtnode/fntcache.cxx
+++ b/sw/source/core/txtnode/fntcache.cxx
@@ -1182,9 +1182,6 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf )
         // set text render mode to suit use of resolution independent text 
layout
         rInf.GetOut().SetTextRenderModeForResolutionIndependentLayout(true);
 
-        const OUString* pStr = &rInf.GetText();
-
-        OUString aStr;
         OUString aBulletOverlay;
         bool bBullet = rInf.GetBullet();
         if( m_bSymbol )
@@ -1278,19 +1275,10 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf )
 
         if( bBullet )
         {
-            // !!! HACK !!!
-            // The Arabic layout engine requires some context of the string
-            // which should be painted.
+            // Copy the substring that will be painted, and replace spaces with
+            // bullets, and everything else with space.
             sal_Int32 nCopyStart = sal_Int32(rInf.GetIdx());
-            if ( nCopyStart )
-                --nCopyStart;
-
             sal_Int32 nCopyLen = sal_Int32(rInf.GetLen());
-            if ( nCopyStart + nCopyLen < rInf.GetText().getLength() )
-                ++nCopyLen;
-
-            aStr = rInf.GetText().copy( nCopyStart, nCopyLen );
-            pStr = &aStr;
 
             aBulletOverlay = rInf.GetText().copy( nCopyStart, nCopyLen );
 
@@ -1341,8 +1329,8 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf )
             rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(),
                          aKernArray, sal_Int32(rInf.GetIdx()), 1 );
             if( bBullet )
-                rInf.GetOut().DrawTextArray( aTextOriginPos, *pStr, aKernArray,
-                                             rInf.GetIdx() ? 1 : 0, 1 );
+                rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(), 
aKernArray,
+                                             sal_Int32(rInf.GetIdx()), 1 );
         }
         else
         {
@@ -1455,17 +1443,11 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf )
                 if ( bSwitchH2V )
                     rInf.GetFrame()->SwitchHorizontalToVertical( 
aTextOriginPos );
 
-                // If we paint bullets instead of spaces, we use a copy of
-                // the paragraph string. For the layout engine, the copy
-                // of the string has to be an environment of the range which
-                // is painted
-                sal_Int32 nTmpIdx = bBullet
-                            ? (rInf.GetIdx() ? 1 : 0)
-                            : sal_Int32(rInf.GetIdx());
+                sal_Int32 nIdx = sal_Int32(rInf.GetIdx());
                 const SalLayoutGlyphs* pGlyphs = 
SalLayoutGlyphsCache::self()->GetLayoutGlyphs(&rInf.GetOut(),
-                     *pStr, nTmpIdx, nLen);
-                rInf.GetOut().DrawTextArray( aTextOriginPos, *pStr, aKernArray,
-                                             nTmpIdx , nLen, 
SalLayoutFlags::NONE, pGlyphs );
+                     rInf.GetText(), nIdx, nLen);
+                rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(), 
aKernArray,
+                                             nIdx, nLen, SalLayoutFlags::NONE, 
pGlyphs );
                 if (bBullet)
                 {
                     rInf.GetOut().Push();
@@ -1485,8 +1467,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf )
                     {
                         tools::Long nAdd = 0;
 
-                        if (aBulletOverlay.getLength() > nTmpIdx &&
-                            aBulletOverlay[ nTmpIdx ] == CH_BULLET )
+                        if ( aBulletOverlay[ 0 ] == CH_BULLET )
                         {
                             if (bSwitchH2V)
                                 aTextOriginPos.AdjustY(nShift ) ;
@@ -1496,14 +1477,14 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf )
                         }
                         for( sal_Int32 i = 1 ; i < nLen ; ++i )
                         {
-                            if ( aBulletOverlay[ i + nTmpIdx ] == CH_BULLET )
+                            if ( aBulletOverlay[ i ] == CH_BULLET )
                                 aKernArray [ i - 1 ] += nShift ;
                             if ( nAdd )
                                 aKernArray [ i - 1 ] -= nAdd;
                         }
                     }
                     rInf.GetOut().DrawTextArray( aTextOriginPos, 
aBulletOverlay, aKernArray,
-                                                 nTmpIdx , nLen );
+                                                 0, nLen );
                     pTmpFont->SetColor( aPreviousColor );
 
                     pTmpFont->SetUnderline(aPreviousUnderline);

Reply via email to