From 6130ff73347b5e633babf9555ee1417462cc11ef Mon Sep 17 00:00:00 2001 From: Mark Hung Date: Sun, 16 Oct 2016 11:25:04 +0800 Subject: 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 Reviewed-by: Khaled Hosny --- 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(-) (limited to 'sw') 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; } -- cgit