diff --git a/sw/source/core/inc/scriptinfo.hxx b/sw/source/core/inc/scriptinfo.hxx index e0ee73c491df..962a87f68eb1 100644 --- a/sw/source/core/inc/scriptinfo.hxx +++ b/sw/source/core/inc/scriptinfo.hxx @@ -352,6 +352,7 @@ public: sal_Int32 nLen, sal_Int32 nNumberOfBlanks = 0, long nSpaceAdd = 0 ); + static sal_Int32 CountCJKCharacters( const OUString &rText, sal_Int32 nPos, sal_Int32 nEnd, LanguageType aLang); 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 9dd9c952dd1c..0df03c6a5c98 100644 --- a/sw/source/core/text/porlay.cxx +++ b/sw/source/core/text/porlay.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -2142,4 +2143,24 @@ void SwScriptInfo::CalcHiddenRanges( const SwTextNode& rNode, MultiSelection& rH rNode.SetHiddenCharAttribute( bNewHiddenCharsHidePara, bNewContainsHiddenChars ); } +sal_Int32 SwScriptInfo::CountCJKCharacters( const OUString &rText, sal_Int32 nPos, sal_Int32 nEnd, LanguageType aLang) +{ + sal_Int32 nCount = 0; + if ( nEnd > nPos && g_pBreakIt->GetBreakIter().is() ) + { + sal_Int32 nDone = 0; + const lang::Locale &rLocale = g_pBreakIt->GetLocale( aLang ); + while ( nPos < nEnd ) + { + nPos = g_pBreakIt->GetBreakIter()->nextCharacters( rText, nPos, + rLocale, + i18n::CharacterIteratorMode::SKIPCELL, 1, nDone ); + nCount++; + } + } + else + nCount = nEnd - nPos ; + + return nCount; +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/text/portxt.cxx b/sw/source/core/text/portxt.cxx index e12955cc5f3e..2c200c09eec0 100644 --- a/sw/source/core/text/portxt.cxx +++ b/sw/source/core/text/portxt.cxx @@ -99,7 +99,7 @@ static sal_Int32 lcl_AddSpace( const SwTextSizeInfo &rInf, const OUString* pStr, pPor->IsPostItsPortion() ) ) pPor = pPor->GetPortion(); - nCnt += nEnd - nPos; + nCnt += SwScriptInfo::CountCJKCharacters( *pStr, nPos, nEnd, aLang ); if ( !pPor || pPor->IsHolePortion() || pPor->InFixMargGrp() || pPor->IsBreakPortion() )