|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 #ifndef nsILineBreaker_h__ |
|
6 #define nsILineBreaker_h__ |
|
7 |
|
8 #include "nsISupports.h" |
|
9 |
|
10 #include "nscore.h" |
|
11 |
|
12 #define NS_LINEBREAKER_NEED_MORE_TEXT -1 |
|
13 |
|
14 // {0x4b0b9e04-6ffb-4647-aa5f-2fa2ebd883e8} |
|
15 #define NS_ILINEBREAKER_IID \ |
|
16 {0x4b0b9e04, 0x6ffb, 0x4647, \ |
|
17 {0xaa, 0x5f, 0x2f, 0xa2, 0xeb, 0xd8, 0x83, 0xe8}} |
|
18 |
|
19 class nsILineBreaker : public nsISupports |
|
20 { |
|
21 public: |
|
22 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ILINEBREAKER_IID) |
|
23 |
|
24 enum { |
|
25 kWordBreak_Normal = 0, // default |
|
26 kWordBreak_BreakAll = 1, // break all |
|
27 kWordBreak_KeepAll = 2 // always keep |
|
28 }; |
|
29 |
|
30 virtual int32_t Next( const char16_t* aText, uint32_t aLen, |
|
31 uint32_t aPos) = 0; |
|
32 |
|
33 virtual int32_t Prev( const char16_t* aText, uint32_t aLen, |
|
34 uint32_t aPos) = 0; |
|
35 |
|
36 // Call this on a word with whitespace at either end. We will apply JISx4051 |
|
37 // rules to find breaks inside the word. aBreakBefore is set to the break- |
|
38 // before status of each character; aBreakBefore[0] will always be false |
|
39 // because we never return a break before the first character. |
|
40 // aLength is the length of the aText array and also the length of the aBreakBefore |
|
41 // output array. |
|
42 virtual void GetJISx4051Breaks(const char16_t* aText, uint32_t aLength, |
|
43 uint8_t aWordBreak, |
|
44 uint8_t* aBreakBefore) = 0; |
|
45 virtual void GetJISx4051Breaks(const uint8_t* aText, uint32_t aLength, |
|
46 uint8_t aWordBreak, |
|
47 uint8_t* aBreakBefore) = 0; |
|
48 }; |
|
49 |
|
50 NS_DEFINE_STATIC_IID_ACCESSOR(nsILineBreaker, NS_ILINEBREAKER_IID) |
|
51 |
|
52 static inline bool |
|
53 NS_IsSpace(char16_t u) |
|
54 { |
|
55 return u == 0x0020 || // SPACE |
|
56 u == 0x0009 || // CHARACTER TABULATION |
|
57 u == 0x000D || // CARRIAGE RETURN |
|
58 u == 0x1680 || // OGHAM SPACE MARK |
|
59 (0x2000 <= u && u <= 0x2006) || // EN QUAD, EM QUAD, EN SPACE, |
|
60 // EM SPACE, THREE-PER-EM SPACE, |
|
61 // FOUR-PER-SPACE, SIX-PER-EM SPACE, |
|
62 (0x2008 <= u && u <= 0x200B) || // PUNCTUATION SPACE, THIN SPACE, |
|
63 // HAIR SPACE, ZERO WIDTH SPACE |
|
64 u == 0x205F; // MEDIUM MATHEMATICAL SPACE |
|
65 } |
|
66 |
|
67 static inline bool |
|
68 NS_NeedsPlatformNativeHandling(char16_t aChar) |
|
69 { |
|
70 return (0x0e01 <= aChar && aChar <= 0x0fff) || // Thai, Lao, Tibetan |
|
71 (0x1780 <= aChar && aChar <= 0x17ff); // Khmer |
|
72 } |
|
73 |
|
74 #endif /* nsILineBreaker_h__ */ |