summaryrefslogtreecommitdiff
path: root/i18npool/source/breakiterator/breakiterator_cjk.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'i18npool/source/breakiterator/breakiterator_cjk.cxx')
-rw-r--r--i18npool/source/breakiterator/breakiterator_cjk.cxx19
1 files changed, 19 insertions, 0 deletions
diff --git a/i18npool/source/breakiterator/breakiterator_cjk.cxx b/i18npool/source/breakiterator/breakiterator_cjk.cxx
index 98115e6c1d32..8a4244631759 100644
--- a/i18npool/source/breakiterator/breakiterator_cjk.cxx
+++ b/i18npool/source/breakiterator/breakiterator_cjk.cxx
@@ -86,6 +86,8 @@ BreakIterator_CJK::getWordBoundary( const OUString& text, sal_Int32 anyPos,
return BreakIterator_Unicode::getWordBoundary(text, anyPos, nLocale, wordType, bDirection);
}
+#define isHangul(cCh) ((cCh>=0xAC00&&cCh<=0xD7AF)||(cCh>=0x1100&&cCh<=0x11FF))
+
LineBreakResults SAL_CALL BreakIterator_CJK::getLineBreak(
const OUString& Text, sal_Int32 nStartPos,
const css::lang::Locale& /*rLocale*/, sal_Int32 /*nMinBreakPos*/,
@@ -94,17 +96,34 @@ LineBreakResults SAL_CALL BreakIterator_CJK::getLineBreak(
{
LineBreakResults lbr;
+ const sal_Int32 nOldStartPos = nStartPos;
+
if (bOptions.allowPunctuationOutsideMargin &&
hangingCharacters.indexOf(Text[nStartPos]) != -1 &&
(Text.iterateCodePoints( &nStartPos ), nStartPos == Text.getLength())) {
; // do nothing
} else if (bOptions.applyForbiddenRules && 0 < nStartPos && nStartPos < Text.getLength()) {
+
while (nStartPos > 0 &&
(bOptions.forbiddenBeginCharacters.indexOf(Text[nStartPos]) != -1 ||
bOptions.forbiddenEndCharacters.indexOf(Text[nStartPos-1]) != -1))
Text.iterateCodePoints( &nStartPos, -1);
}
+ // Prevent cutting Korean words in the middle.
+ if ( nOldStartPos == nStartPos && isHangul( Text[nStartPos] ) )
+ {
+ while ( nStartPos >= 0 && isHangul( Text[nStartPos] ) )
+ --nStartPos;
+
+ // beginning of the last Korean word.
+ if ( nStartPos < nOldStartPos )
+ ++nStartPos;
+
+ if ( nStartPos == 0 )
+ nStartPos = nOldStartPos;
+ }
+
lbr.breakIndex = nStartPos;
lbr.breakType = BreakType::WORDBOUNDARY;
return lbr;