tdf#43740 Count CJK characters to distribute spaces.
lcl_AddSpace determine the amount of space to distribute to a portion based on its text length. Counting the number of CJK characters prevent including codepoints that are not visible, such as surrogate pairs or Unicode variance selectors, by mistake. Change-Id: Ia20a7f76ea1ea3c1f4638db865721eaa26a8c82c Reviewed-on: https://gerrit.libreoffice.org/29616 Reviewed-by: Khaled Hosny <khaledhosny@eglug.org> Tested-by: Khaled Hosny <khaledhosny@eglug.org>
This commit is contained in:
@@ -352,6 +352,7 @@ public:
|
|||||||
sal_Int32 nLen, sal_Int32 nNumberOfBlanks = 0,
|
sal_Int32 nLen, sal_Int32 nNumberOfBlanks = 0,
|
||||||
long nSpaceAdd = 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,
|
static SwScriptInfo* GetScriptInfo( const SwTextNode& rNode,
|
||||||
bool bAllowInvalid = false );
|
bool bAllowInvalid = false );
|
||||||
|
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include <breakit.hxx>
|
#include <breakit.hxx>
|
||||||
#include <unicode/uchar.h>
|
#include <unicode/uchar.h>
|
||||||
#include <com/sun/star/i18n/ScriptType.hpp>
|
#include <com/sun/star/i18n/ScriptType.hpp>
|
||||||
|
#include <com/sun/star/i18n/CharacterIteratorMode.hpp>
|
||||||
#include <com/sun/star/i18n/CTLScriptType.hpp>
|
#include <com/sun/star/i18n/CTLScriptType.hpp>
|
||||||
#include <com/sun/star/i18n/WordType.hpp>
|
#include <com/sun/star/i18n/WordType.hpp>
|
||||||
#include <paratr.hxx>
|
#include <paratr.hxx>
|
||||||
@@ -2142,4 +2143,24 @@ void SwScriptInfo::CalcHiddenRanges( const SwTextNode& rNode, MultiSelection& rH
|
|||||||
rNode.SetHiddenCharAttribute( bNewHiddenCharsHidePara, bNewContainsHiddenChars );
|
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: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
@@ -99,7 +99,7 @@ static sal_Int32 lcl_AddSpace( const SwTextSizeInfo &rInf, const OUString* pStr,
|
|||||||
pPor->IsPostItsPortion() ) )
|
pPor->IsPostItsPortion() ) )
|
||||||
pPor = pPor->GetPortion();
|
pPor = pPor->GetPortion();
|
||||||
|
|
||||||
nCnt += nEnd - nPos;
|
nCnt += SwScriptInfo::CountCJKCharacters( *pStr, nPos, nEnd, aLang );
|
||||||
|
|
||||||
if ( !pPor || pPor->IsHolePortion() || pPor->InFixMargGrp() ||
|
if ( !pPor || pPor->IsHolePortion() || pPor->InFixMargGrp() ||
|
||||||
pPor->IsBreakPortion() )
|
pPor->IsBreakPortion() )
|
||||||
|
Reference in New Issue
Block a user