|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef __GLYPHSEL_H__ |
|
17 #define __GLYPHSEL_H__ |
|
18 |
|
19 |
|
20 #include <e32std.h> |
|
21 #include <gdi.h> |
|
22 #include "ShapeInfo.h" |
|
23 |
|
24 /** |
|
25 Forward declarations. |
|
26 @internalComponent |
|
27 */ |
|
28 void Panic(TGdiPanic aError); |
|
29 |
|
30 class TGlyphSelectionState; |
|
31 |
|
32 |
|
33 /** |
|
34 The Unicode char to use for glyph cluster without a base char |
|
35 @internalComponent |
|
36 */ |
|
37 #define KUnicodeDottedCircle 0x25CC |
|
38 |
|
39 // |
|
40 // |
|
41 // TUtf32Iterator Class declaration |
|
42 // |
|
43 // |
|
44 |
|
45 class TUtf32Iterator |
|
46 /* |
|
47 Converts UTF16 encoded array of bytes into UTF32 characters, |
|
48 ignoring non-characters and unpaired surrogates and |
|
49 combining paired surrogates. |
|
50 @internalComponent |
|
51 */ |
|
52 { |
|
53 public: |
|
54 TUtf32Iterator(const TText16* aStart, const TText16* aEnd, TInt aOffset=0); |
|
55 |
|
56 inline TBool AtEnd() const; |
|
57 inline TBool BeforeStart() const; |
|
58 TChar Next(); |
|
59 TChar Prev(); |
|
60 void SetPos(TInt aOffset); |
|
61 inline TChar Get() const; |
|
62 TUint Get(TInt offset); |
|
63 TChar GetThenNext(); |
|
64 TChar GetThenPrev(); |
|
65 const TText16* CurrentPosition() const; |
|
66 void SetCurrentPosition(const TText16*); |
|
67 |
|
68 TInt LengthToStart() const; |
|
69 TInt LengthToEnd() const; |
|
70 |
|
71 private: |
|
72 TUint UTF16ToTChar(const TText16* a); |
|
73 |
|
74 private: |
|
75 /** Start address of the UTF16 array */ |
|
76 const TText16* iStart; |
|
77 /** Address of current position in array */ |
|
78 const TText16* iCurrent; |
|
79 /** Address of the first entry past the end of the array */ |
|
80 const TText16* iEnd; |
|
81 |
|
82 /** UTF32 value of the character at the current iterator position */ |
|
83 TChar iChar; |
|
84 }; |
|
85 |
|
86 |
|
87 // |
|
88 // |
|
89 // GlyphSelUtils Namespace declaration |
|
90 // |
|
91 // |
|
92 |
|
93 |
|
94 namespace GlyphSelUtils |
|
95 /** |
|
96 This namespace holds a collection of useful common utility |
|
97 functions used in glyph selection. These functions are intended to be |
|
98 used by the glyph selector classes. |
|
99 @internalComponent |
|
100 */ |
|
101 { |
|
102 inline TBool IsSurrogate(TText a) |
|
103 { |
|
104 return 0xD800 == (a & 0xF800); |
|
105 } |
|
106 |
|
107 inline TBool IsHighSurrogate(TText a) |
|
108 { |
|
109 return 0xD800 == (a & 0xFC00); |
|
110 } |
|
111 |
|
112 inline TBool IsLowSurrogate(TText a) |
|
113 { |
|
114 return 0xDC00 == (a & 0xFC00); |
|
115 } |
|
116 |
|
117 inline TChar PairSurrogates(TText aHigh, TText aLow) |
|
118 { |
|
119 return ((aHigh - 0xd7f7) << 10) + aLow; |
|
120 } |
|
121 |
|
122 inline TBool IsThaiCharacter(TUint code) |
|
123 { |
|
124 return ((code > 0x0E00 && code < 0x0E3B) || |
|
125 (code > 0x0E3E && code < 0x0E5C)); |
|
126 } |
|
127 |
|
128 } |
|
129 |
|
130 |
|
131 // |
|
132 // |
|
133 // TGlyphSelectionState Class declaration |
|
134 // |
|
135 // |
|
136 |
|
137 |
|
138 class TGlyphSelectionState |
|
139 /** |
|
140 This container class holds the data for glyph selection algorithm and is |
|
141 used to pass this data around the algorithm methods. |
|
142 @internalComponent |
|
143 */ |
|
144 { |
|
145 public: |
|
146 enum TPenAdvance |
|
147 /** |
|
148 Enum used in glyph selection code indicating if a pen advance is needed following |
|
149 the processing of the current glyph. |
|
150 */ |
|
151 { |
|
152 EPenAdvance_No, |
|
153 EPenAdvance_Yes, |
|
154 }; |
|
155 |
|
156 enum TGlyphClusterStateOverride |
|
157 /** |
|
158 These enumeration values are used by the glyph selector classes to indicated |
|
159 back to the glyph selection algorithm when they find a cluster complete. |
|
160 */ |
|
161 { |
|
162 EGClusterComplete, |
|
163 EGClusterNotComplete |
|
164 }; |
|
165 |
|
166 enum TGlyphPostCombine |
|
167 /** |
|
168 These enumeration values are used by the glyph selector classes to decide whether |
|
169 post combining is needed to combine the diacritic to the base character. |
|
170 */ |
|
171 { |
|
172 EGPostCombine_No, |
|
173 EGPostCombine_Yes |
|
174 }; |
|
175 |
|
176 |
|
177 TGlyphSelectionState(TUtf32Iterator& aIter, const CFont* aFont, CFont::TPositionParam& aParam) |
|
178 : iCodePt(0xFFFF), iCodeChar(0xFFFF), iCombCls(-1), iCats(0), |
|
179 iText(aIter), iFont(aFont), iParam(aParam), |
|
180 iClusterState(EGClusterNotComplete), iPen(EPenAdvance_No), |
|
181 iAdvance(), iLigaturePortionsRemaining(0), iGlyphPostCombine(EGPostCombine_No) { }; |
|
182 |
|
183 TBool IsCombiningClass() { return (iCats & 0xF0) == TChar::EMarkGroup; } |
|
184 void CombineLastGlyphToBase(const TRect& aBase, TInt aFirstDiacritic); |
|
185 |
|
186 TBool AppendGlyphToCluster(TUint code); |
|
187 |
|
188 public: |
|
189 /** The properties of the current character being processed */ |
|
190 TUint iCodePt; |
|
191 TChar iCodeChar; |
|
192 TInt iCombCls; |
|
193 TUint iCats; |
|
194 |
|
195 /** The Unicode iterator to the text processed */ |
|
196 TUtf32Iterator& iText; |
|
197 |
|
198 /** The font to select glyphs from */ |
|
199 const CFont* iFont; |
|
200 |
|
201 /** The in/out parameter data to the glyph selection code from outside */ |
|
202 CFont::TPositionParam& iParam; |
|
203 |
|
204 /** Result from the glyph selector class as to whether it thinks the |
|
205 cluster is complete or incomplete. |
|
206 */ |
|
207 TGlyphClusterStateOverride iClusterState; |
|
208 |
|
209 /** These hold the possible pen advance and if it should be applied */ |
|
210 TPenAdvance iPen; |
|
211 TSize iAdvance; |
|
212 |
|
213 /** Can be used in any way or not at all by the processing function. It is |
|
214 set to 0 on intitialisation. Suggested use is to pass information about |
|
215 which part of a ligature is currently having diacritics attatched to it. */ |
|
216 TInt iLigaturePortionsRemaining; |
|
217 /** Can be used in any way or not at all by the processing function. It is |
|
218 not initialised. Suggested use is to record the position in the output |
|
219 glyph array of the first diacritic on this portion of the ligature. */ |
|
220 TInt iLigaturePortionFirstMark; |
|
221 |
|
222 /** |
|
223 Result from the glyph selector class as to whether it needs to |
|
224 combine the diacritic with the base character. |
|
225 */ |
|
226 TGlyphPostCombine iGlyphPostCombine; |
|
227 }; |
|
228 |
|
229 |
|
230 // |
|
231 // |
|
232 // GlyphSelector_SoftHyphen Class declaration |
|
233 // |
|
234 // |
|
235 |
|
236 class GlyphSelector_SoftHyphen |
|
237 /** |
|
238 This glyph selector class processes the Unicode soft hyphen U+00AD |
|
239 character. |
|
240 This is a discretionary hyphen, i.e. it is only rendered when required |
|
241 and in Symbian OS that is when it is found at the end of a line. |
|
242 @internalComponent |
|
243 */ |
|
244 { |
|
245 public: |
|
246 |
|
247 static TBool Process(TGlyphSelectionState& aGss, RShapeInfo&); |
|
248 }; |
|
249 |
|
250 |
|
251 // |
|
252 // |
|
253 // GlyphSelector_Default Class declaration |
|
254 // |
|
255 // |
|
256 |
|
257 class GlyphSelector_Default |
|
258 /** |
|
259 This is the default glyph selector class which has the behaviour of outputting |
|
260 all glyphs it is invoked to process. |
|
261 @internalComponent |
|
262 */ |
|
263 { |
|
264 public: |
|
265 |
|
266 static TBool Process(TGlyphSelectionState& aGss, RShapeInfo&); |
|
267 }; |
|
268 |
|
269 |
|
270 // |
|
271 // TUtf32Iterator inline Function definitions. |
|
272 // |
|
273 |
|
274 |
|
275 inline TBool TUtf32Iterator::AtEnd() const |
|
276 { |
|
277 return iEnd == iCurrent; |
|
278 } |
|
279 |
|
280 inline TBool TUtf32Iterator::BeforeStart() const |
|
281 { |
|
282 return iStart > iCurrent; |
|
283 } |
|
284 |
|
285 inline TChar TUtf32Iterator::Get() const |
|
286 { |
|
287 __ASSERT_DEBUG(iCurrent >= iStart && iCurrent < iEnd, Panic(EGdiPanic_OutOfText)); |
|
288 |
|
289 return iChar; |
|
290 } |
|
291 |
|
292 #endif // __GLYPHSEL_H__ |