|
1 /* |
|
2 * Copyright (c) 2002 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: This class is a utitlity class for conversion of Vodafone |
|
15 * pictograph. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 // PICTOGRAPH_SHARED.CPP |
|
27 // |
|
28 // |
|
29 |
|
30 #include "CnvPictographShared.h" |
|
31 // #include "CnvPictograph1.h" |
|
32 #include "CnvShiftJisDirectmap.h" |
|
33 #include <convgeneratedcpp.h> |
|
34 |
|
35 |
|
36 // CONSTANTS |
|
37 // Escape sequence for Vodafone pictograph |
|
38 _LIT8(KLit8EscapeSequenceForPictograph, "\x1b\x24"); |
|
39 // _LIT8(KLit8EscapeSequenceForPictograph1, "\x1b\x24\x47"); |
|
40 |
|
41 const TInt KEscape = 0x1B; |
|
42 const TInt KShiftIn = 0x0F; |
|
43 |
|
44 // Intermidiate buffers for pictograph |
|
45 const TInt KIntermediateBuffer1 = 'G'; |
|
46 |
|
47 const TUint KSingleByteRangeFirstBlockStart = 0xF0; |
|
48 const TUint KSingleByteRangeFirstBlockEnd = 0xF9; |
|
49 const TUint KSingleByteRangeSecondBlockStart = 0x40; |
|
50 const TUint KSingleByteRangeSecondBlockEnd = 0xFC; |
|
51 |
|
52 const TUint KFirstByteRangeFirstBlockStart = 0xF5; |
|
53 const TUint KFirstByteRangeFirstBlockEnd = 0xFE; |
|
54 const TUint KSecondByteRangeSecondBlockStart = 0xA1; |
|
55 const TUint KSecondByteRangeSecondBlockEnd = 0xFE; |
|
56 |
|
57 const TUint KEUCJPSecondBlockStart = 0xF5; |
|
58 const TUint KEUCJPBlockSize = 0x5D; |
|
59 const TUint KSingleShift3=0x8f; |
|
60 // used for EucJp |
|
61 const TUint KPictographStartFirstByte = 0xF0; |
|
62 const TUint KPictographStartSecondByte = 0x40; |
|
63 const TUint KShiftJisTrailByteIllegal = 0x7F; |
|
64 |
|
65 // ============================ LOCAL FUNCTIONS =============================== |
|
66 |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // DummyConvertToIntermediateBufferInPlace ?description. |
|
70 // |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 LOCAL_C void DummyConvertToIntermediateBufferInPlace(TDes8&) |
|
74 { |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // DummyConvertFromIntermediateBufferInPlace |
|
79 // |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 LOCAL_C void DummyConvertFromIntermediateBufferInPlace(TInt, TDes8&, |
|
83 TInt& aNumberOfCharactersThatDroppedOut) |
|
84 { |
|
85 aNumberOfCharactersThatDroppedOut=0; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // ConvertFromPictogaphToEucJpDirectmapInPlace |
|
90 // Converts from EucJp packed Pictograph to Unicode |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 LOCAL_C void ConvertFromPictogaphToEucJpDirectmapInPlace( |
|
94 TInt aStartPositionInDescriptor, TDes8& aDescriptor, |
|
95 TInt& aNumberOfCharactersThatDroppedOut) |
|
96 { |
|
97 TInt descriptorLength=aDescriptor.Length(); |
|
98 TInt bytesPerCharacter = 2; |
|
99 if (aDescriptor[0] >= KEUCJPSecondBlockStart) |
|
100 { |
|
101 bytesPerCharacter = 3; |
|
102 } |
|
103 |
|
104 aNumberOfCharactersThatDroppedOut = |
|
105 Max(0, ((descriptorLength - aStartPositionInDescriptor) / 2) - |
|
106 ((aDescriptor.MaxLength() - aStartPositionInDescriptor) / |
|
107 bytesPerCharacter)); |
|
108 descriptorLength -= aNumberOfCharactersThatDroppedOut * 2; |
|
109 if (descriptorLength <= aStartPositionInDescriptor) |
|
110 { |
|
111 aDescriptor.SetLength(descriptorLength); |
|
112 } |
|
113 else |
|
114 { |
|
115 // pointerToTargetByte is initialized properly when descriptorLength |
|
116 // has been offset to the actual final length of aDescriptor |
|
117 TUint8* pointerToTargetByte = CONST_CAST(TUint8*, aDescriptor.Ptr()); |
|
118 const TUint8* const pointerToFirstByte = |
|
119 pointerToTargetByte + aStartPositionInDescriptor; |
|
120 const TUint8* pointerToSourceByte = |
|
121 pointerToTargetByte + (descriptorLength - 1); |
|
122 descriptorLength = (((descriptorLength - aStartPositionInDescriptor) |
|
123 * bytesPerCharacter) / 2) + aStartPositionInDescriptor; |
|
124 aDescriptor.SetLength(descriptorLength); |
|
125 // pointerToTargetByte is is initialized properly here |
|
126 pointerToTargetByte += descriptorLength - 1; |
|
127 for (;pointerToTargetByte > pointerToFirstByte; ) |
|
128 { |
|
129 TInt secondByte = *pointerToSourceByte; |
|
130 TInt firstByte = *(pointerToSourceByte - 1); |
|
131 |
|
132 if (bytesPerCharacter == 3) |
|
133 { |
|
134 firstByte = (firstByte - KEUCJPSecondBlockStart) * 2 + |
|
135 KFirstByteRangeFirstBlockStart; |
|
136 } |
|
137 else |
|
138 { |
|
139 firstByte = (firstByte - KPictographStartFirstByte) * 2 + |
|
140 KFirstByteRangeFirstBlockStart; |
|
141 } |
|
142 if (static_cast<TInt>(KEUCJPBlockSize + KPictographStartSecondByte + 1) |
|
143 < secondByte) |
|
144 { |
|
145 if (secondByte > KShiftJisTrailByteIllegal) |
|
146 secondByte -= 1; |
|
147 secondByte = secondByte -(KPictographStartSecondByte + |
|
148 KEUCJPBlockSize + 1) + KSecondByteRangeSecondBlockStart; |
|
149 firstByte++; |
|
150 } |
|
151 else |
|
152 { |
|
153 if (secondByte > KShiftJisTrailByteIllegal) |
|
154 secondByte -= 1; |
|
155 secondByte += KSecondByteRangeSecondBlockStart - KPictographStartSecondByte; |
|
156 } |
|
157 *pointerToTargetByte = static_cast<TUint8>(secondByte); |
|
158 --pointerToTargetByte; |
|
159 *pointerToTargetByte = static_cast<TUint8>(firstByte); |
|
160 if (bytesPerCharacter == 3) |
|
161 { |
|
162 --pointerToTargetByte; |
|
163 *pointerToTargetByte = KSingleShift3; |
|
164 } |
|
165 --pointerToTargetByte; |
|
166 pointerToSourceByte -= 2; |
|
167 } |
|
168 } |
|
169 } |
|
170 |
|
171 // ============================ MEMBER FUNCTIONS =============================== |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CnvPictographShared::SetCharacterSetsForPictograph |
|
175 // It sets parameters to SCharacterSet array. It called in ConvertFromUnicode(). |
|
176 // It makes possible that pictograph conversion is called from other conversion |
|
177 // plug-ins. |
|
178 // (other items were commented in a header). |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 void CnvPictographShared::SetCharacterSetsForPictograph( |
|
182 RArray<CnvUtilities::SCharacterSet>& /*aArrayOfCharacterSets*/) |
|
183 { |
|
184 // SAMPLE CODE |
|
185 // If this module needs to support escape sequence pictograph, |
|
186 // Remove the comment from the following code. |
|
187 |
|
188 // CnvUtilities::SCharacterSet characterSet; |
|
189 // characterSet.iConversionData = &CnvPictograph1::ConversionData(); |
|
190 // characterSet.iConvertFromIntermediateBufferInPlace = |
|
191 // CnvPictographShared::ConvertToPictograph1InPlace; |
|
192 // characterSet.iEscapeSequence = &KLit8EscapeSequenceForPictograph1; |
|
193 // aArrayOfCharacterSets.Append(characterSet); |
|
194 |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CnvPictographShared::SetMethodsForPictograph |
|
199 // It sets parameters to SMethod array. It called in ConvertToUnicode(). |
|
200 // It makes possible that pictograph conversion is called from other conversion |
|
201 // plug-ins. |
|
202 // (other items were commented in a header). |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 void CnvPictographShared::SetMethodsForPictograph( |
|
206 RArray<CnvUtilities::SMethod>& aArrayOfMethods, TOriginalCharset aOriginalCharset) |
|
207 { |
|
208 CnvUtilities::SMethod method; |
|
209 switch (aOriginalCharset) |
|
210 { |
|
211 case ECharsetShiftJis: |
|
212 method.iNumberOfBytesAbleToConvert = |
|
213 CnvPictographShared::NumberOfBytesAbleToConvertSJisDirectMap; |
|
214 method.iConvertToIntermediateBufferInPlace = |
|
215 DummyConvertToIntermediateBufferInPlace; |
|
216 method.iConversionData = |
|
217 &CnvShiftJisDirectmap::ConversionData(); |
|
218 method.iNumberOfBytesPerCharacter = 2; |
|
219 method.iNumberOfCoreBytesPerCharacter = 2; |
|
220 aArrayOfMethods.Append(method); |
|
221 break; |
|
222 case ECharsetEucJp: |
|
223 method.iNumberOfBytesAbleToConvert = |
|
224 CnvPictographShared::NumberOfBytesAbleToConvertToEucJpDirectMap1; |
|
225 method.iConvertToIntermediateBufferInPlace = |
|
226 CnvPictographShared::ConvertToPictographFromEucJpPackedInPlace; |
|
227 method.iConversionData = |
|
228 &CnvShiftJisDirectmap::ConversionData(); |
|
229 method.iNumberOfBytesPerCharacter = 2; |
|
230 method.iNumberOfCoreBytesPerCharacter = 2; |
|
231 aArrayOfMethods.Append(method); |
|
232 method.iNumberOfBytesAbleToConvert = |
|
233 CnvPictographShared::NumberOfBytesAbleToConvertToEucJpDirectMap2; |
|
234 method.iConvertToIntermediateBufferInPlace = |
|
235 CnvPictographShared::ConvertToPictographFromEucJpPackedInPlace; |
|
236 method.iConversionData = |
|
237 &CnvShiftJisDirectmap::ConversionData(); |
|
238 method.iNumberOfBytesPerCharacter = 3; |
|
239 method.iNumberOfCoreBytesPerCharacter = 2; |
|
240 aArrayOfMethods.Append(method); |
|
241 break; |
|
242 default: |
|
243 break; |
|
244 } |
|
245 |
|
246 // SAMPLE CODE |
|
247 // If this module needs to support escape sequence pictograph, |
|
248 // Remove the comment from the following code. |
|
249 |
|
250 // method.iNumberOfBytesAbleToConvert = |
|
251 // CnvPictographShared::NumberOfBytesAbleToConvertToPicto1; |
|
252 // method.iConvertToIntermediateBufferInPlace = |
|
253 // CnvPictographShared::ConvertToPictographFromUnicode; |
|
254 // method.iConversionData = &CnvPictograph1::ConversionData(); |
|
255 // method.iNumberOfBytesPerCharacter = 1; |
|
256 // method.iNumberOfCoreBytesPerCharacter = 1; |
|
257 // aArrayOfMethods.Append(method); |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CnvPictographShared::SetCharacterSetsForPictograph |
|
262 // It sets parameters to SState array. It called in ConvertToUnicode(). |
|
263 // It makes possible that pictograph conversion is called from other |
|
264 // conversion plug-ins. |
|
265 // (other items were commented in a header). |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 void CnvPictographShared::SetCharacterSetsForPictograph( |
|
269 RArray<CnvUtilities::SCharacterSet>& aArrayOfStates, |
|
270 TOriginalCharset aOriginalCharset) |
|
271 { |
|
272 CnvUtilities::SCharacterSet characterSet; |
|
273 switch (aOriginalCharset) |
|
274 { |
|
275 case ECharsetShiftJis: |
|
276 // Append the character set for pictograph |
|
277 characterSet.iConversionData = |
|
278 &CnvShiftJisDirectmap::ConversionData(); |
|
279 characterSet.iConvertFromIntermediateBufferInPlace = |
|
280 DummyConvertFromIntermediateBufferInPlace; |
|
281 characterSet.iEscapeSequence = &KNullDesC8; |
|
282 aArrayOfStates.Append(characterSet); |
|
283 break; |
|
284 case ECharsetEucJp: |
|
285 // Append the character set for pictograph1 |
|
286 characterSet.iConversionData = &CnvShiftJisDirectmap::ConversionData(); |
|
287 characterSet.iConvertFromIntermediateBufferInPlace = |
|
288 ConvertFromPictogaphToEucJpDirectmapInPlace; |
|
289 characterSet.iEscapeSequence = &KNullDesC8; |
|
290 aArrayOfStates.Append(characterSet); |
|
291 |
|
292 // Append the character set for pictograph2 |
|
293 characterSet.iConversionData = &CnvShiftJisDirectmap::ConversionData(); |
|
294 characterSet.iConvertFromIntermediateBufferInPlace = |
|
295 ConvertFromPictogaphToEucJpDirectmapInPlace; |
|
296 characterSet.iEscapeSequence = &KNullDesC8; |
|
297 aArrayOfStates.Append(characterSet); |
|
298 break; |
|
299 default: |
|
300 break; |
|
301 } |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CnvPictographShared::SetStatesForPictograph |
|
306 // It sets parameters to SState array. It called in ConvertToUnicode(). |
|
307 // It makes possible that pictograph conversion is called from other |
|
308 // conversion plug-ins. |
|
309 // (other items were commented in a header). |
|
310 // ----------------------------------------------------------------------------- |
|
311 // |
|
312 void CnvPictographShared::SetStatesForPictograph( |
|
313 RArray<CnvUtilities::SState>& /*aArrayOfStates*/) |
|
314 { |
|
315 // SAMPLE CODE |
|
316 // If this module needs to support escape sequence pictograph, |
|
317 // Remove the comment from the following code. |
|
318 |
|
319 // CnvUtilities::SState state; |
|
320 // state.iEscapeSequence = &KLit8EscapeSequenceForPictograph1; |
|
321 // state.iConversionData = &CnvPictograph1::ConversionData(); |
|
322 // aArrayOfStates.Append(state); |
|
323 } |
|
324 |
|
325 // ----------------------------------------------------------------------------- |
|
326 // CnvPictographShared::ConvertToPictograph1InPlace |
|
327 // It converts from an intermediate buffer to a pictograph code. |
|
328 // After that, it adds shift-in code(0x0F). |
|
329 // (other items were commented in a header). |
|
330 // ----------------------------------------------------------------------------- |
|
331 // |
|
332 // void CnvPictographShared::ConvertToPictograph1InPlace( |
|
333 // TInt aStartPositionInDescriptor, |
|
334 // TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut) |
|
335 // { |
|
336 // CnvUtilities::ConvertFromIntermediateBufferInPlace( |
|
337 // aStartPositionInDescriptor, aDescriptor, |
|
338 // aNumberOfCharactersThatDroppedOut, |
|
339 // KLit8EscapeSequenceForPictograph1, 1); |
|
340 // AppendShiftIn(aDescriptor, aNumberOfCharactersThatDroppedOut); |
|
341 // } |
|
342 |
|
343 |
|
344 // ----------------------------------------------------------------------------- |
|
345 // CnvPictographShared::NumberOfBytesAbleToConvertToPicto1 |
|
346 // It returns a number of bytes that the conversion to pictograph is |
|
347 // possible in the descriptor. |
|
348 // (other items were commented in a header). |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 TInt CnvPictographShared::NumberOfBytesAbleToConvertSJisDirectMap( |
|
352 const TDesC8& aDescriptor) |
|
353 { |
|
354 const TUint8* pointerToPreviousByte = aDescriptor.Ptr()-1; |
|
355 const TUint8* const pointerToLastByte = |
|
356 pointerToPreviousByte + aDescriptor.Length(); |
|
357 if (pointerToPreviousByte == pointerToLastByte) |
|
358 { |
|
359 return 0; |
|
360 } |
|
361 for (; pointerToPreviousByte < pointerToLastByte; ) |
|
362 { |
|
363 const TUint currentByte = *(pointerToPreviousByte + 1); |
|
364 const TUint nextByte = *(pointerToPreviousByte + 2); |
|
365 if (((currentByte < KSingleByteRangeFirstBlockStart) || |
|
366 (currentByte > KSingleByteRangeFirstBlockEnd)) || |
|
367 ((nextByte < KSingleByteRangeSecondBlockStart) || |
|
368 (nextByte > KSingleByteRangeSecondBlockEnd))) |
|
369 { |
|
370 break; |
|
371 } |
|
372 pointerToPreviousByte += 2; |
|
373 } |
|
374 return (pointerToPreviousByte + 1) - aDescriptor.Ptr(); |
|
375 } |
|
376 |
|
377 // ----------------------------------------------------------------------------- |
|
378 // NumberOfBytesAbleToConvertToEucJpDirectMap1 |
|
379 // |
|
380 // ----------------------------------------------------------------------------- |
|
381 // |
|
382 TInt CnvPictographShared::NumberOfBytesAbleToConvertToEucJpDirectMap1( |
|
383 const TDesC8& aDescriptor) |
|
384 { |
|
385 const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1; |
|
386 const TUint8* const pointerToLastByte = |
|
387 pointerToPreviousByte + aDescriptor.Length(); |
|
388 if (pointerToPreviousByte == pointerToLastByte) |
|
389 { |
|
390 return 0; |
|
391 } |
|
392 for (;pointerToPreviousByte < pointerToLastByte;) |
|
393 { |
|
394 TUint currentByte = *(pointerToPreviousByte + 1); |
|
395 const TUint nextByte = *(pointerToPreviousByte + 2); |
|
396 if (((currentByte < KFirstByteRangeFirstBlockStart) || |
|
397 (currentByte > KFirstByteRangeFirstBlockEnd)) || |
|
398 ((nextByte < KSecondByteRangeSecondBlockStart) || |
|
399 (nextByte > KSecondByteRangeSecondBlockEnd))) |
|
400 { |
|
401 break; |
|
402 } |
|
403 pointerToPreviousByte += 2; |
|
404 } |
|
405 return (pointerToPreviousByte + 1) - aDescriptor.Ptr(); |
|
406 } |
|
407 |
|
408 // ----------------------------------------------------------------------------- |
|
409 // NumberOfBytesAbleToConvertToPictograph |
|
410 // |
|
411 // ----------------------------------------------------------------------------- |
|
412 // |
|
413 TInt CnvPictographShared::NumberOfBytesAbleToConvertToEucJpDirectMap2( |
|
414 const TDesC8& aDescriptor) |
|
415 { |
|
416 const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1; |
|
417 const TUint8* const pointerToLastByte = |
|
418 pointerToPreviousByte + aDescriptor.Length(); |
|
419 if (pointerToPreviousByte == pointerToLastByte) |
|
420 { |
|
421 return 0; |
|
422 } |
|
423 for (;pointerToPreviousByte < pointerToLastByte;) |
|
424 { |
|
425 TUint currentByte = *(pointerToPreviousByte + 1); |
|
426 if (currentByte == KSingleShift3) |
|
427 { |
|
428 pointerToPreviousByte++; |
|
429 currentByte = *(pointerToPreviousByte + 1); |
|
430 } |
|
431 else |
|
432 { |
|
433 break; |
|
434 } |
|
435 if (currentByte < 0xa0) |
|
436 { |
|
437 return CCnvCharacterSetConverter::EErrorIllFormedInput; |
|
438 } |
|
439 const TUint nextByte = *(pointerToPreviousByte + 2); |
|
440 if (nextByte < 0xa0) |
|
441 { |
|
442 return CCnvCharacterSetConverter::EErrorIllFormedInput; |
|
443 } |
|
444 if (((currentByte < KFirstByteRangeFirstBlockStart) || |
|
445 (currentByte > KFirstByteRangeFirstBlockEnd)) || |
|
446 ((nextByte < KSecondByteRangeSecondBlockStart) || |
|
447 (nextByte > KSecondByteRangeSecondBlockEnd))) |
|
448 { |
|
449 // return the previous byte to the beginning of loop. |
|
450 pointerToPreviousByte--; |
|
451 break; |
|
452 } |
|
453 pointerToPreviousByte += 2; |
|
454 } |
|
455 return (pointerToPreviousByte + 1) - aDescriptor.Ptr(); |
|
456 } |
|
457 |
|
458 // ----------------------------------------------------------------------------- |
|
459 // CnvPictographShared::NumberOfBytesAbleToConvertToPicto1 |
|
460 // It returns a number of bytes that the conversion to pictograph is |
|
461 // possible in the descriptor. |
|
462 // (other items were commented in a header). |
|
463 // ----------------------------------------------------------------------------- |
|
464 // |
|
465 TInt CnvPictographShared::NumberOfBytesAbleToConvertToPicto1( |
|
466 const TDesC8& aDescriptor) |
|
467 { |
|
468 return NumberOfBytesAbleToConvertToPictograph(aDescriptor, |
|
469 KIntermediateBuffer1); |
|
470 } |
|
471 |
|
472 // ----------------------------------------------------------------------------- |
|
473 // CnvPictographShared::NumberOfBytesAbleToConvertToPictograph |
|
474 // It's a common function for checking the number of bytes that the conversion |
|
475 // to pictograph |
|
476 // (other items were commented in a header). |
|
477 // ----------------------------------------------------------------------------- |
|
478 // |
|
479 TInt CnvPictographShared::NumberOfBytesAbleToConvertToPictograph( |
|
480 const TDesC8& aDescriptor, TInt aIntermidiateCode) |
|
481 { |
|
482 TInt compLen(KLit8EscapeSequenceForPictograph().Length()); |
|
483 TInt ret(0); |
|
484 if (aDescriptor.Left(compLen) == KLit8EscapeSequenceForPictograph) |
|
485 { |
|
486 const TInt intermidiateBuff = aDescriptor[compLen]; |
|
487 if (intermidiateBuff == aIntermidiateCode) |
|
488 { |
|
489 ret = compLen + 2; |
|
490 |
|
491 const TInt descriptorLength = aDescriptor.Length(); |
|
492 const TUint8* pointerToCurrentByte = aDescriptor.Ptr(); |
|
493 const TUint8* pointerToLastByte = pointerToCurrentByte + |
|
494 (descriptorLength - 1); |
|
495 pointerToCurrentByte += compLen + 2; |
|
496 for (; pointerToCurrentByte <= pointerToLastByte; |
|
497 pointerToCurrentByte++) |
|
498 { |
|
499 if (*pointerToCurrentByte == KShiftIn) |
|
500 { |
|
501 ret++; |
|
502 break; |
|
503 } |
|
504 if (*pointerToCurrentByte == KEscape) |
|
505 break; |
|
506 ret++; |
|
507 } |
|
508 } |
|
509 } |
|
510 return ret; |
|
511 } |
|
512 |
|
513 // ----------------------------------------------------------------------------- |
|
514 // CnvPictographShared::ConvertToPictographFromUnicode |
|
515 // It converts the string which includes a pictograph's escape sequence |
|
516 // to unicode. |
|
517 // (other items were commented in a header). |
|
518 // ----------------------------------------------------------------------------- |
|
519 // |
|
520 void CnvPictographShared::ConvertToPictographFromUnicode(TDes8& aDescriptor) |
|
521 { |
|
522 const TInt descriptorLength = aDescriptor.Length(); |
|
523 TUint8* pointerToCurrentByte = CONST_CAST(TUint8*, aDescriptor.Ptr()); |
|
524 TUint8* pointerToDataByte = pointerToCurrentByte + |
|
525 KLit8EscapeSequenceForPictograph().Length(); |
|
526 const TUint8* const pointerToLastByte = pointerToCurrentByte + |
|
527 (descriptorLength - 1); |
|
528 const TUint8* const pointerToFirstByte = pointerToCurrentByte; |
|
529 pointerToDataByte++; |
|
530 |
|
531 for (; pointerToDataByte <= pointerToLastByte; pointerToDataByte++) |
|
532 { |
|
533 if (*pointerToDataByte != KShiftIn) |
|
534 { |
|
535 *pointerToCurrentByte = *pointerToDataByte; |
|
536 pointerToCurrentByte++; |
|
537 } |
|
538 } |
|
539 aDescriptor.SetLength(pointerToCurrentByte - pointerToFirstByte); |
|
540 } |
|
541 |
|
542 // ----------------------------------------------------------------------------- |
|
543 // CnvPictographShared::ConvertToPictographFromEucJpPackedInPlace |
|
544 // Converts from EucJp packed Pictograph to Unicode |
|
545 // ----------------------------------------------------------------------------- |
|
546 // |
|
547 void CnvPictographShared::ConvertToPictographFromEucJpPackedInPlace(TDes8& aDescriptor) |
|
548 { |
|
549 const TInt descriptorLength = aDescriptor.Length(); |
|
550 TUint8* pointerToTargetByte = CONST_CAST(TUint8*, aDescriptor.Ptr()); |
|
551 const TUint8* pointerToSourceByte = pointerToTargetByte; |
|
552 const TUint8* const pointerToLastByte = |
|
553 pointerToSourceByte + (descriptorLength - 1); |
|
554 TInt bytesPerCharacter = 2; |
|
555 TInt sjisStartbyte = KSingleByteRangeFirstBlockStart; |
|
556 if (*pointerToSourceByte == KSingleShift3) |
|
557 { |
|
558 ++pointerToSourceByte; |
|
559 bytesPerCharacter = 3; |
|
560 sjisStartbyte = KEUCJPSecondBlockStart; |
|
561 } |
|
562 for (;pointerToSourceByte < pointerToLastByte; ) |
|
563 { |
|
564 TUint firstByte = (*pointerToSourceByte |
|
565 - KFirstByteRangeFirstBlockStart) / 2 + sjisStartbyte; |
|
566 TUint secondByte = *(pointerToSourceByte + 1); |
|
567 if ((*pointerToSourceByte % 2) == 0) |
|
568 { |
|
569 secondByte += KSingleByteRangeSecondBlockStart - KSecondByteRangeSecondBlockStart |
|
570 + KEUCJPBlockSize + 1; |
|
571 if (secondByte >= KShiftJisTrailByteIllegal) |
|
572 secondByte++; |
|
573 } |
|
574 else |
|
575 { |
|
576 secondByte += KSingleByteRangeSecondBlockStart - KSecondByteRangeSecondBlockStart; |
|
577 if (secondByte >= KShiftJisTrailByteIllegal) |
|
578 secondByte++; |
|
579 } |
|
580 *pointerToTargetByte = static_cast<TUint8>(firstByte); |
|
581 |
|
582 ++pointerToTargetByte; |
|
583 *pointerToTargetByte = static_cast<TUint8>(secondByte); |
|
584 pointerToSourceByte += 2; |
|
585 ++pointerToTargetByte; |
|
586 } |
|
587 aDescriptor.SetLength((descriptorLength / bytesPerCharacter) * 2); |
|
588 } |
|
589 |
|
590 // ----------------------------------------------------------------------------- |
|
591 // CnvPictographShared::AppendShiftIn |
|
592 // It appends a shift-in code to the descriptor. |
|
593 // (other items were commented in a header). |
|
594 // ----------------------------------------------------------------------------- |
|
595 // |
|
596 void CnvPictographShared::AppendShiftIn(TDes8& aDescriptor, |
|
597 TInt& aNumberOfCharactersThatDroppedOut) |
|
598 { |
|
599 if (aDescriptor.MaxLength() > aDescriptor.Length()) |
|
600 { |
|
601 aDescriptor.Append(KShiftIn); |
|
602 } |
|
603 else |
|
604 { |
|
605 aNumberOfCharactersThatDroppedOut++; |
|
606 } |
|
607 } |
|
608 |
|
609 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
610 |
|
611 // ----------------------------------------------------------------------------- |
|
612 // SetCharacterSetsForPictograph() |
|
613 // It sets parameters to SCharacterSet array. |
|
614 // It called in ConvertFromUnicode(). |
|
615 // It makes possible that pictograph conversion is called from other |
|
616 // conversion plug-ins. |
|
617 // @since 2.6 |
|
618 // @param aArrayOfCharacterSets The conversion table array |
|
619 // ----------------------------------------------------------------------------- |
|
620 // |
|
621 EXPORT_C void SetCharacterSetsForPictograph( |
|
622 RArray<CnvUtilities::SCharacterSet>& aArrayOfCharacterSets) |
|
623 { |
|
624 CnvPictographShared::SetCharacterSetsForPictograph(aArrayOfCharacterSets); |
|
625 } |
|
626 |
|
627 // ----------------------------------------------------------------------------- |
|
628 // SetCharacterSetsForPictograph() |
|
629 // It sets parameters to SCharacterSet array. |
|
630 // It called in ConvertFromUnicode(). |
|
631 // It makes possible that pictograph conversion is called from other |
|
632 // conversion plug-ins. |
|
633 // @since 2.6 |
|
634 // @param aArrayOfCharacterSets The conversion table array |
|
635 // @param aOriginalCharset The character set |
|
636 // ----------------------------------------------------------------------------- |
|
637 // |
|
638 EXPORT_C void SetCharacterSetsForPictograph( |
|
639 RArray<CnvUtilities::SCharacterSet>& aArrayOfCharacterSets, |
|
640 TOriginalCharset aOriginalCharset) |
|
641 { |
|
642 CnvPictographShared::SetCharacterSetsForPictograph(aArrayOfCharacterSets, |
|
643 aOriginalCharset); |
|
644 } |
|
645 |
|
646 // ----------------------------------------------------------------------------- |
|
647 // SetMethodsForPictograph() |
|
648 // It sets parameters to SMethod array. |
|
649 // It called in ConvertToUnicode(). |
|
650 // It makes possible that pictograph conversion is called from other |
|
651 // conversion plug-ins. |
|
652 // @since 2.6 |
|
653 // @param aArrayOfMethods The conversion table array |
|
654 // @param aOriginalCharset The character set |
|
655 // ----------------------------------------------------------------------------- |
|
656 // |
|
657 EXPORT_C void SetMethodsForPictograph( |
|
658 RArray<CnvUtilities::SMethod>& aArrayOfMethods, |
|
659 TOriginalCharset aOriginalCharset) |
|
660 { |
|
661 CnvPictographShared::SetMethodsForPictograph(aArrayOfMethods, |
|
662 aOriginalCharset); |
|
663 } |
|
664 |
|
665 // ----------------------------------------------------------------------------- |
|
666 // SetStatesForPictograph() |
|
667 // It sets parameters to SState array. |
|
668 // It called in ConvertToUnicode(). |
|
669 // It makes possible that pictograph conversion is called from other |
|
670 // conversion plug-ins. |
|
671 // @since 2.6 |
|
672 // @param aArrayOfMethods The conversion table array |
|
673 // ----------------------------------------------------------------------------- |
|
674 // |
|
675 EXPORT_C void SetStatesForPictograph( |
|
676 RArray<CnvUtilities::SState>& aArrayOfStates) |
|
677 { |
|
678 CnvPictographShared::SetStatesForPictograph(aArrayOfStates); |
|
679 } |
|
680 |
|
681 // ----------------------------------------------------------------------------- |
|
682 // CountOfPictographPagesFromUnicode() |
|
683 // It returns count of pictograph pages. |
|
684 // This method is used for the conversion from Unicode to foreign character |
|
685 // set. |
|
686 // @since 2.6 |
|
687 // @return count of pictograph pages. |
|
688 // ----------------------------------------------------------------------------- |
|
689 // |
|
690 EXPORT_C TInt CountOfPictographPagesFromUnicode() |
|
691 { |
|
692 return KCountOfPictoPages; |
|
693 } |
|
694 |
|
695 // ----------------------------------------------------------------------------- |
|
696 // CountOfPictographPagesToUnicode() |
|
697 // It returns count of pictograph pages. |
|
698 // This method is used for the conversion from foreign character set to |
|
699 // Unicode. |
|
700 // @since 2.6 |
|
701 // @return count of pictograph pages. |
|
702 // ----------------------------------------------------------------------------- |
|
703 // |
|
704 EXPORT_C TInt CountOfPictographPagesToUnicode() |
|
705 { |
|
706 return KCountOfPictoPages + 1; |
|
707 } |
|
708 |
|
709 // End of File |