|
1 /* |
|
2 * Copyright (c) 2001 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <eiklay.h> |
|
20 #include <eikpanic.h> |
|
21 #include <eikcoctlpanic.h> |
|
22 #include <AknLineBreaker.h> |
|
23 |
|
24 const TUint KOpFlag = 1 << MTmCustom::EOpLineBreakClass; |
|
25 const TUint KClFlag = 1 << MTmCustom::EClLineBreakClass; |
|
26 // const TUint KQuFlag = 1 << MTmCustom::EQuLineBreakClass; |
|
27 // const TUint KGlFlag = 1 << MTmCustom::EGlLineBreakClass; |
|
28 const TUint KNsFlag = 1 << MTmCustom::ENsLineBreakClass; |
|
29 const TUint KExFlag = 1 << MTmCustom::EExLineBreakClass; |
|
30 const TUint KSyFlag = 1 << MTmCustom::ESyLineBreakClass; |
|
31 const TUint KIsFlag = 1 << MTmCustom::EIsLineBreakClass; |
|
32 const TUint KPrFlag = 1 << MTmCustom::EPrLineBreakClass; |
|
33 const TUint KPoFlag = 1 << MTmCustom::EPoLineBreakClass; |
|
34 const TUint KNuFlag = 1 << MTmCustom::ENuLineBreakClass; |
|
35 const TUint KAlFlag = 1 << MTmCustom::EAlLineBreakClass; |
|
36 const TUint KIdFlag = 1 << MTmCustom::EIdLineBreakClass; |
|
37 const TUint KInFlag = 1 << MTmCustom::EInLineBreakClass; |
|
38 // const TUint KHyFlag = 1 << MTmCustom::EHyLineBreakClass; |
|
39 const TUint KBaFlag = 1 << MTmCustom::EBaLineBreakClass; |
|
40 const TUint KBbFlag = 1 << MTmCustom::EBbLineBreakClass; |
|
41 const TUint KB2Flag = 1 << MTmCustom::EB2LineBreakClass; |
|
42 const TUint KZwFlag = 1 << MTmCustom::EZwLineBreakClass; |
|
43 const TUint KCmFlag = 1 << MTmCustom::ECmLineBreakClass; |
|
44 // const TUint KBkFlag = 1 << MTmCustom::EBkLineBreakClass; |
|
45 // const TUint KCrFlag = 1 << MTmCustom::ECrLineBreakClass; |
|
46 // const TUint KLfFlag = 1 << MTmCustom::ELfLineBreakClass; |
|
47 // const TUint KSgFlag = 1 << MTmCustom::ESgLineBreakClass; |
|
48 // const TUint KCbFlag = 1 << MTmCustom::ECbLineBreakClass; |
|
49 // const TUint KSpFlag = 1 << MTmCustom::ESpLineBreakClass; |
|
50 // const TUint KSaFlag = 1 << MTmCustom::ESaLineBreakClass; |
|
51 const TUint KAiFlag = 1 << MTmCustom::EAiLineBreakClass; |
|
52 // const TUint KXxFlag = 1 << MTmCustom::EXxLineBreakClass; |
|
53 const TUint KCalSpaceFlag = 1 << TAvkonEditorCustomWrap::EAvkSpaceLineBreakClass; |
|
54 |
|
55 // const TInt KUsualBreaks = KOpFlag | KPrFlag | KPoFlag | KNuFlag | KAlFlag | KIdFlag | KInFlag | KBbFlag | KB2Flag | KAiFlag; |
|
56 |
|
57 struct TLineBreakRule |
|
58 { |
|
59 TUint iForbid; // set bits represent forbidden breaks |
|
60 TUint iAllow; // set bits represent allowed breaks |
|
61 // bits not in iForbid or iAllow represent breaks allowed only when spaces are present |
|
62 }; |
|
63 |
|
64 const TUint KAllBreaks = 0xFFFFFFFF; |
|
65 const TUint KUsualForbidden = KClFlag | KExFlag | KSyFlag | KIsFlag | KZwFlag; |
|
66 const TUint KUsualAllowed = KOpFlag | KPrFlag | KPoFlag | KNuFlag | KAlFlag | KIdFlag | KInFlag | KBbFlag | KB2Flag | KAiFlag | KBaFlag; |
|
67 |
|
68 // A table of break rules, indexed by the class of the character before the possible break. |
|
69 static const TLineBreakRule TheLineBreakRuleTable[TAvkonEditorCustomWrap::EAvkLineBreakClasses] = |
|
70 { |
|
71 { KAllBreaks - KCmFlag,0 }, // Op 0 |
|
72 { KUsualForbidden | KNsFlag,KUsualAllowed - KPoFlag }, // Cl 1 |
|
73 { KUsualForbidden | KOpFlag,0 }, // Qu 2 |
|
74 { KUsualForbidden, 0 }, // Gl 3 |
|
75 { KUsualForbidden, KUsualAllowed }, // Ns 4 |
|
76 { KUsualForbidden, KUsualAllowed }, // Ex 5 |
|
77 { KUsualForbidden, KUsualAllowed - KNuFlag }, // Sy 6 |
|
78 { KUsualForbidden, KUsualAllowed - KNuFlag }, // Is 7 |
|
79 { KUsualForbidden, KPrFlag | KPoFlag | KInFlag | KBbFlag | KB2Flag }, // Pr 8 |
|
80 { KUsualForbidden, KUsualAllowed }, // Po 9 |
|
81 { KUsualForbidden, KOpFlag | KPrFlag | KIdFlag | KBbFlag | KB2Flag }, // Nu 10 |
|
82 { KUsualForbidden, KOpFlag | KPrFlag | KPoFlag | KIdFlag | KBbFlag | KB2Flag }, // Al 11 |
|
83 { KUsualForbidden, KUsualAllowed - KPoFlag - KInFlag }, // Id 12 |
|
84 { KUsualForbidden, KUsualAllowed - KInFlag }, // In 13 |
|
85 { KUsualForbidden, KUsualAllowed }, // Hy 14 |
|
86 { KUsualForbidden, KUsualAllowed }, // Ba 15 |
|
87 { KUsualForbidden, 0 }, // Bb 16 |
|
88 { KUsualForbidden | KB2Flag, KUsualAllowed }, // B2 17 |
|
89 { KZwFlag, KAllBreaks }, // Zw 18 |
|
90 { KUsualForbidden, KOpFlag | KPrFlag | KPoFlag | KIdFlag | KBbFlag | KB2Flag }, // Cm 19 |
|
91 { 0, 0, }, // Bk 20 |
|
92 { 0, 0, }, // Cr 21 |
|
93 { 0, 0, }, // Lf 22 |
|
94 { 0, 0, }, // Sg 23 |
|
95 { 0, 0, }, // Cb 24 |
|
96 { 0, 0, }, // Sp 25 |
|
97 { 0, 0, }, // Sa 26 |
|
98 { KUsualForbidden, KOpFlag | KPrFlag | KPoFlag | KIdFlag | KBbFlag | KB2Flag }, // Ai 27 |
|
99 { 0, 0, }, // Xx 28 |
|
100 { KUsualForbidden, KUsualAllowed | KCalSpaceFlag }, // CalSpace 29 |
|
101 }; |
|
102 |
|
103 const TText KPrivateUseAreaStart = 0xE000; |
|
104 const TText KPrivateUseAreaEnd = 0xF900; |
|
105 |
|
106 /* |
|
107 |
|
108 Avkon break rules for editors: |
|
109 |
|
110 Break-before only: "+" |
|
111 Break-after only: ". , ? ! ; : - _" |
|
112 Before/After: "# * @ & / \ =" |
|
113 |
|
114 */ |
|
115 TUint TAvkonEditorCustomWrap::LineBreakClass(TUint aCode,TUint& aRangeStart,TUint& aRangeEnd) const |
|
116 { |
|
117 aRangeStart = aCode; |
|
118 aRangeEnd = aCode + 1; |
|
119 |
|
120 TUint lineclass; |
|
121 if (TAknLineBreaker::IsSpecialVariantChar(aCode, aRangeStart, aRangeEnd, lineclass)) |
|
122 { |
|
123 // if special line break classes are defined for each variant |
|
124 return lineclass; |
|
125 } |
|
126 |
|
127 switch (aCode) |
|
128 { |
|
129 case 0x0020: // unicode for space |
|
130 return EAvkSpaceLineBreakClass; |
|
131 case 0x0021: // unicode for exclamation mark (!) |
|
132 case 0xff01: // unicode for fullwidth exclamation mark |
|
133 return MTmCustom::EBaLineBreakClass; |
|
134 case 0x002c: // unicode for comma (,) deliberate fall through |
|
135 case 0x002d: // unicode for hyphen (-) deliberate fall through |
|
136 case 0x002e: // unicode for fullstop (.) |
|
137 case 0xff0c: // unicode for fullwidth comma |
|
138 aRangeStart=0x002c; |
|
139 aRangeEnd=0x002f; |
|
140 return MTmCustom::EBaLineBreakClass; |
|
141 case 0x3001: // unicode for ideographic comma |
|
142 case 0x3002: // unicode for idegraphic full stop |
|
143 case 0xff1f: // unicode for fullwidth question mark |
|
144 aRangeStart=0x002c; |
|
145 aRangeEnd=0x002f; |
|
146 return MTmCustom::EClLineBreakClass; |
|
147 case 0x003a: // unicode for colon (:) deliberate fall through |
|
148 case 0x003b: // unicode for semi-colon (;) |
|
149 case 0xff1a: // unicode for fullwidth colon |
|
150 aRangeStart=0x003a; |
|
151 aRangeEnd=0x003c; |
|
152 return MTmCustom::EBaLineBreakClass; |
|
153 case 0x003f: // unicode for question mark (?) deliberate fall through |
|
154 case 0x005f: // unicode for underscore (_) |
|
155 return MTmCustom::EBaLineBreakClass; |
|
156 case 0x002b: // unicode for plus (+) |
|
157 return MTmCustom::EBbLineBreakClass; |
|
158 case 0x0023: // unicode for hash (#) deliberate fall through |
|
159 case 0x0026: // unicode for ampersand (&) deliberate fall through |
|
160 case 0x002a: // unicode for asterisk (*) deliberate fall through |
|
161 case 0x002f: // unicode for fwd-slash (/) deliberate fall through |
|
162 case 0x003d: // unicode for equals (=) deliberate fall through |
|
163 case 0x0040: // unicode for 'at' (@) deliberate fall through |
|
164 case 0x005c: // unicode for bk-slash (\) |
|
165 return MTmCustom::EB2LineBreakClass; |
|
166 default: |
|
167 break; // carry on |
|
168 } |
|
169 |
|
170 // Allow break before and after PUA characters (required for pictographs). |
|
171 if ( aCode >= KPrivateUseAreaStart && aCode < KPrivateUseAreaEnd ) |
|
172 { |
|
173 aRangeStart = KPrivateUseAreaStart; |
|
174 aRangeEnd = KPrivateUseAreaEnd; |
|
175 // this allows break before and after |
|
176 return MTmCustom::EIdLineBreakClass; |
|
177 } |
|
178 |
|
179 return MFormCustomWrap::LineBreakClass(aCode,aRangeStart,aRangeEnd); |
|
180 } |
|
181 |
|
182 TBool TAvkonEditorCustomWrap::LineBreakPossible(TUint aPrevClass,TUint aNextClass,TBool aHaveSpaces) const |
|
183 { |
|
184 __ASSERT_DEBUG(!aHaveSpaces,Panic(EEikPanicUnexpectedSpaces)); // should be no codes->ESpLineBreakClass using this source |
|
185 if (aPrevClass >= EAvkLineBreakClasses || aNextClass >= EAvkLineBreakClasses) |
|
186 return FALSE; |
|
187 |
|
188 const TLineBreakRule& rule = TheLineBreakRuleTable[aPrevClass]; |
|
189 TUint flag = 1 << aNextClass; |
|
190 if (rule.iForbid & flag) |
|
191 return FALSE; |
|
192 return aHaveSpaces || (rule.iAllow & flag); |
|
193 } |