sw/source/core/inc/scriptinfo.hxx   |    6 ++++++
 sw/source/core/text/porlay.cxx      |   30 ++++++++++++++++++++++++++++++
 sw/source/core/txtnode/fntcache.cxx |   25 ++++++-------------------
 3 files changed, 42 insertions(+), 19 deletions(-)

New commits:
commit 6130ff73347b5e633babf9555ee1417462cc11ef
Author: Mark Hung <mark...@gmail.com>
Date:   Sun Oct 16 11:25:04 2016 +0800

    tdf#43740 Don't add space after ininvisible characters.
    
    Move CJK justify code in SwFntObj::DrawText to
    SwScriptInfo::CJKJustfiy() and use break iterator to
    prevent unecessary space.
    
    Change-Id: Ifd25373530fc97d3ce547ee3cd0484d4a852491c
    Reviewed-on: https://gerrit.libreoffice.org/29911
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Khaled Hosny <khaledho...@eglug.org>

diff --git a/sw/source/core/inc/scriptinfo.hxx 
b/sw/source/core/inc/scriptinfo.hxx
index 962a87f..983c1c3 100644
--- a/sw/source/core/inc/scriptinfo.hxx
+++ b/sw/source/core/inc/scriptinfo.hxx
@@ -353,6 +353,12 @@ public:
                                   long nSpaceAdd = 0 );
 
     static sal_Int32 CountCJKCharacters( const OUString &rText, sal_Int32 
nPos, sal_Int32 nEnd, LanguageType aLang);
+
+    static void CJKJustify( const OUString& rText, long* pKernArray,
+                                  long* pScrArray, sal_Int32 nStt,
+                                  sal_Int32 nLen, LanguageType aLang,
+                                  long nSpaceAdd );
+
     static SwScriptInfo* GetScriptInfo( const SwTextNode& rNode,
                                         bool bAllowInvalid = false );
 
diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index 0df03c6..7850763 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -2163,4 +2163,34 @@ sal_Int32 SwScriptInfo::CountCJKCharacters( const 
OUString &rText, sal_Int32 nPo
 
     return nCount;
 }
+
+void SwScriptInfo::CJKJustify( const OUString& rText, long* pKernArray,
+                                     long* pScrArray, sal_Int32 nStt,
+                                     sal_Int32 nLen, LanguageType aLang,
+                                     long nSpaceAdd )
+{
+    assert( pKernArray != nullptr && nStt >= 0 );
+    if ( nLen > 0 && g_pBreakIt->GetBreakIter().is() )
+    {
+        long nSpaceSum = nSpaceAdd;
+        const lang::Locale &rLocale = g_pBreakIt->GetLocale( aLang );
+        sal_Int32 nDone = 0;
+        sal_Int32 nNext = g_pBreakIt->GetBreakIter()->nextCharacters( rText, 
nStt,
+                        rLocale,
+                        i18n::CharacterIteratorMode::SKIPCELL, 1, nDone );
+        for ( sal_Int32 nI = 0; nI < nLen ; ++nI )
+        {
+            if ( nI + nStt == nNext )
+            {
+                nNext = g_pBreakIt->GetBreakIter()->nextCharacters( rText, 
nNext,
+                        rLocale,
+                        i18n::CharacterIteratorMode::SKIPCELL, 1, nDone );
+                nSpaceSum += nSpaceAdd;
+            }
+            pKernArray[ nI ] += nSpaceSum;
+            if ( pScrArray )
+                pScrArray[ nI ] += nSpaceSum;
+        }
+    }
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/txtnode/fntcache.cxx 
b/sw/source/core/txtnode/fntcache.cxx
index 92aa6ad..a92fb87 100644
--- a/sw/source/core/txtnode/fntcache.cxx
+++ b/sw/source/core/txtnode/fntcache.cxx
@@ -1242,12 +1242,8 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf )
 
                     if (!MsLangId::isKorean(aLang))
                     {
-                        long nSpaceSum = nSpaceAdd;
-                        for ( sal_Int32 nI = 0; nI < rInf.GetLen(); ++nI )
-                        {
-                            pKernArray[ nI ] += nSpaceSum;
-                            nSpaceSum += nSpaceAdd;
-                        }
+                        SwScriptInfo::CJKJustify( rInf.GetText(), pKernArray, 
nullptr,
+                                rInf.GetIdx(), rInf.GetLen(), aLang, nSpaceAdd 
);
 
                         bSpecialJust = true;
                         nSpaceAdd = 0;
@@ -1454,13 +1450,8 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf )
 
                 if (!MsLangId::isKorean(aLang))
                 {
-                    long nSpaceSum = nSpaceAdd;
-                    for ( sal_Int32 nI = 0; nI < rInf.GetLen(); ++nI )
-                    {
-                        pKernArray[ nI ] += nSpaceSum;
-                        pScrArray[ nI ] += nSpaceSum;
-                        nSpaceSum += nSpaceAdd;
-                    }
+                    SwScriptInfo::CJKJustify( rInf.GetText(), pKernArray, 
pScrArray,
+                            rInf.GetIdx(), rInf.GetLen(), aLang, nSpaceAdd );
 
                     nSpaceAdd = 0;
                 }
@@ -2067,12 +2058,8 @@ sal_Int32 SwFntObj::GetCursorOfst( SwDrawTextInfo &rInf )
 
             if (!MsLangId::isKorean(aLang))
             {
-                long nSpaceSum = nSpaceAdd;
-                for ( sal_Int32 nI = 0; nI < rInf.GetLen(); ++nI )
-                {
-                    pKernArray[ nI ] += nSpaceSum;
-                    nSpaceSum += nSpaceAdd;
-                }
+                SwScriptInfo::CJKJustify( rInf.GetText(), pKernArray, nullptr,
+                        rInf.GetIdx(), rInf.GetLen(), aLang, nSpaceAdd );
 
                 nSpaceAdd = 0;
             }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to