summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Hung <marklh9@gmail.com>2016-10-16 11:25:04 +0800
committerKhaled Hosny <khaledhosny@eglug.org>2016-10-17 07:44:46 +0000
commit6130ff73347b5e633babf9555ee1417462cc11ef (patch)
tree53a6afad6c020f0e90a2e1d1d95f73784e89c47d
parent4ac1a406a78f58c8fba4040c960091e2af4a390b (diff)
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 <ci@libreoffice.org> Reviewed-by: Khaled Hosny <khaledhosny@eglug.org>
-rw-r--r--sw/source/core/inc/scriptinfo.hxx6
-rw-r--r--sw/source/core/text/porlay.cxx30
-rw-r--r--sw/source/core/txtnode/fntcache.cxx25
3 files changed, 42 insertions, 19 deletions
diff --git a/sw/source/core/inc/scriptinfo.hxx b/sw/source/core/inc/scriptinfo.hxx
index 962a87f68eb1..983c1c39b4fc 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 0df03c6a5c98..7850763b095c 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 92aa6ade51b8..a92fb879f2df 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;
}