1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <breakiterator_cjk.hxx>
21 #include <localedata.hxx>
23 #include <com/sun/star/i18n/BreakType.hpp>
24 #include <com/sun/star/i18n/ScriptType.hpp>
26 using namespace ::com::sun::star::i18n
;
27 using namespace ::com::sun::star::lang
;
31 // ----------------------------------------------------
32 // class BreakIterator_CJK
33 // ----------------------------------------------------;
35 BreakIterator_CJK::BreakIterator_CJK()
37 cBreakIterator
= u
"com.sun.star.i18n.BreakIterator_CJK"_ustr
;
41 bool isHangul( sal_Unicode cCh
)
43 return (cCh
>= 0xAC00 && cCh
<= 0xD7AF) || (cCh
>= 0x1100 && cCh
<= 0x11FF) ||
44 (cCh
>= 0xA960 && cCh
<= 0xA97F) || (cCh
>= 0xD7B0 && cCh
<= 0xD7FF) ||
45 (cCh
>= 0x3130 && cCh
<= 0x318F);
49 LineBreakResults SAL_CALL
BreakIterator_CJK::getLineBreak(
50 const OUString
& Text
, sal_Int32 nStartPos
,
51 const css::lang::Locale
& /*rLocale*/, sal_Int32
/*nMinBreakPos*/,
52 const LineBreakHyphenationOptions
& /*hOptions*/,
53 const LineBreakUserOptions
& bOptions
)
57 const sal_Int32 nOldStartPos
= nStartPos
;
59 if (bOptions
.allowPunctuationOutsideMargin
&&
60 nStartPos
!= Text
.getLength() &&
61 hangingCharacters
.indexOf(Text
[nStartPos
]) != -1 &&
62 (Text
.iterateCodePoints( &nStartPos
), nStartPos
== Text
.getLength())) {
64 } else if (bOptions
.applyForbiddenRules
&& 0 < nStartPos
&& nStartPos
< Text
.getLength()) {
66 while (nStartPos
> 0 &&
67 (bOptions
.forbiddenBeginCharacters
.indexOf(Text
[nStartPos
]) != -1 ||
68 bOptions
.forbiddenEndCharacters
.indexOf(Text
[nStartPos
-1]) != -1))
69 Text
.iterateCodePoints( &nStartPos
, -1);
72 // Prevent cutting Korean words in the middle.
73 if (nOldStartPos
== nStartPos
&& nStartPos
< Text
.getLength()
74 && isHangul(Text
[nStartPos
]))
76 while ( nStartPos
>= 0 && isHangul( Text
[nStartPos
] ) )
79 // beginning of the last Korean word.
80 if ( nStartPos
< nOldStartPos
)
84 nStartPos
= nOldStartPos
;
87 lbr
.breakIndex
= nStartPos
;
88 lbr
.breakType
= BreakType::WORDBOUNDARY
;
92 #define LOCALE(language, country) css::lang::Locale(language, country, OUString())
93 // ----------------------------------------------------
94 // class BreakIterator_zh
95 // ----------------------------------------------------;
96 BreakIterator_zh::BreakIterator_zh()
98 assert(hangingCharacters
.pData
);
99 hangingCharacters
= LocaleDataImpl::get()->getHangingCharacters(LOCALE(u
"zh"_ustr
, u
"CN"_ustr
));
100 cBreakIterator
= u
"com.sun.star.i18n.BreakIterator_zh"_ustr
;
103 // ----------------------------------------------------
104 // class BreakIterator_zh_TW
105 // ----------------------------------------------------;
106 BreakIterator_zh_TW::BreakIterator_zh_TW()
108 assert(hangingCharacters
.pData
);
109 hangingCharacters
= LocaleDataImpl::get()->getHangingCharacters(LOCALE(u
"zh"_ustr
, u
"TW"_ustr
));
110 cBreakIterator
= u
"com.sun.star.i18n.BreakIterator_zh_TW"_ustr
;
113 // ----------------------------------------------------
114 // class BreakIterator_ja
115 // ----------------------------------------------------;
116 BreakIterator_ja::BreakIterator_ja()
118 assert(hangingCharacters
.pData
);
119 hangingCharacters
= LocaleDataImpl::get()->getHangingCharacters(LOCALE(u
"ja"_ustr
, u
"JP"_ustr
));
120 cBreakIterator
= u
"com.sun.star.i18n.BreakIterator_ja"_ustr
;
123 // ----------------------------------------------------
124 // class BreakIterator_ko
125 // ----------------------------------------------------;
126 BreakIterator_ko::BreakIterator_ko()
128 assert(hangingCharacters
.pData
);
129 hangingCharacters
= LocaleDataImpl::get()->getHangingCharacters(LOCALE(u
"ko"_ustr
, u
"KR"_ustr
));
130 cBreakIterator
= u
"com.sun.star.i18n.BreakIterator_ko"_ustr
;
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */