|
1 /* |
|
2 * Copyright (c) 2007 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: Implementation of class CFsTextParser |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 //<cmail> removed __FS_ALFRED_SUPPORT flag |
|
21 //#include <fsconfig.h> |
|
22 //</cmail> removed __FS_ALFRED_SUPPORT flag |
|
23 // <cmail> SF |
|
24 #include "emailtrace.h" |
|
25 #include <alf/alftextstylemanager.h> |
|
26 // </cmail> |
|
27 #include <eikenv.h> |
|
28 #include <imagedata.h> |
|
29 // <cmail> |
|
30 #include <AknUtils.h> |
|
31 // </cmail> |
|
32 #include <fldinfo.h> |
|
33 |
|
34 #include "fstextparser.h" |
|
35 #include "fsrichtexttext.h" |
|
36 #include "fsrichtextpicture.h" |
|
37 #include "fsrichtextsmiley.h" |
|
38 #include "fsrichtextnewline.h" |
|
39 #include "fsrichtext.h" |
|
40 #include "fsrichtextfields.h" |
|
41 #include "fssmileyparser.h" |
|
42 #include "fstextureloader.h" |
|
43 #include "fstexture.h" |
|
44 #include "fstextstylemanager.h" |
|
45 |
|
46 |
|
47 #include "fbs.h" |
|
48 |
|
49 |
|
50 CFsTextParser::CFsTextParser( |
|
51 CFsRichText& aText, |
|
52 CAlfEnv& aEnv, |
|
53 CFsTextureLoader* aTextureLoader): |
|
54 iText(aText), |
|
55 iTextureLoader(aTextureLoader), |
|
56 iEnv(aEnv), |
|
57 iTextStyleManager(NULL), |
|
58 iIsWordTooLong(EFalse), |
|
59 iIsSetSizeOfSmiley(EFalse), |
|
60 iGetCharsUsed(EFalse), |
|
61 iGetCharsUsedOfNextBlock(EFalse), |
|
62 iNewLineArrayIndex(0), |
|
63 iLastNewLinePositionIndex(0) |
|
64 { |
|
65 FUNC_LOG; |
|
66 |
|
67 } |
|
68 |
|
69 CFsTextParser* CFsTextParser::NewL( |
|
70 CFsRichText& aText, |
|
71 CAlfEnv& aEnv, |
|
72 CFsTextureLoader* aTextureLoader) |
|
73 { |
|
74 FUNC_LOG; |
|
75 CFsTextParser * self = new(ELeave) CFsTextParser( |
|
76 aText, |
|
77 aEnv, |
|
78 aTextureLoader ); |
|
79 CleanupStack::PushL(self); |
|
80 self->ConstructL(); |
|
81 CleanupStack::Pop(self); |
|
82 return self; |
|
83 } |
|
84 |
|
85 CFsTextParser::~CFsTextParser() |
|
86 { |
|
87 FUNC_LOG; |
|
88 iExpandArray.Close(); |
|
89 iHotSpotArray.Close(); |
|
90 iFieldLocation.Close(); |
|
91 iTextureIndex.Close(); |
|
92 iNewLineArray.Close(); |
|
93 iLineDirection.Close(); |
|
94 |
|
95 delete iSmileyParser; |
|
96 } |
|
97 |
|
98 void CFsTextParser::SetSizeOfSmile(TSize aSizeOfSmiley) |
|
99 { |
|
100 FUNC_LOG; |
|
101 iIsSetSizeOfSmiley = ETrue; |
|
102 iSizeOfSmiley = aSizeOfSmiley; |
|
103 } |
|
104 |
|
105 void CFsTextParser::ConstructL() |
|
106 { |
|
107 FUNC_LOG; |
|
108 iEikon = CEikonEnv::Static(); |
|
109 } |
|
110 |
|
111 TBool CFsTextParser::SetParsingPosition( TInt aPosition ) |
|
112 { |
|
113 FUNC_LOG; |
|
114 TBool retVal = ETrue; |
|
115 |
|
116 if( aPosition < 0 || aPosition >= iText.DocumentLength()) |
|
117 { |
|
118 retVal = EFalse; |
|
119 } |
|
120 else |
|
121 { |
|
122 iPosition = aPosition; |
|
123 } |
|
124 |
|
125 return retVal; |
|
126 } |
|
127 |
|
128 void CFsTextParser::MoveBack() |
|
129 { |
|
130 FUNC_LOG; |
|
131 iPosition = iLastPosition; |
|
132 } |
|
133 |
|
134 TInt CFsTextParser::IsWordPartOfExpandArea( |
|
135 TInt aStartPosition, |
|
136 TInt aEndPosition ) |
|
137 { |
|
138 FUNC_LOG; |
|
139 TInt retVal = -1; |
|
140 |
|
141 for(TInt i = 0 ; i < iExpandArray.Count() ; ++i) |
|
142 { |
|
143 if(iExpandArray[i].iStartIndex >= aStartPosition && |
|
144 iExpandArray[i].iStartIndex < aEndPosition) |
|
145 { |
|
146 if(-1 == retVal) |
|
147 { |
|
148 retVal = i; |
|
149 } |
|
150 else |
|
151 { |
|
152 if ( iExpandArray[i].iStartIndex |
|
153 < iExpandArray[retVal].iStartIndex ) |
|
154 { |
|
155 retVal = i; |
|
156 } |
|
157 } |
|
158 } |
|
159 else if ( aStartPosition >= iExpandArray[i].iStartIndex |
|
160 && aStartPosition |
|
161 < iExpandArray[i].iStartIndex + iExpandArray[i].iLength ) |
|
162 { |
|
163 if(-1 == retVal) |
|
164 { |
|
165 retVal = i; |
|
166 } |
|
167 else |
|
168 { |
|
169 if ( iExpandArray[i].iStartIndex |
|
170 < iExpandArray[retVal].iStartIndex ) |
|
171 { |
|
172 retVal = i; |
|
173 } |
|
174 } |
|
175 } |
|
176 } |
|
177 return retVal; |
|
178 } |
|
179 |
|
180 |
|
181 void CFsTextParser::CutWord(TInt aBeginOfWord, TInt aNewLengthOfWord) |
|
182 { |
|
183 FUNC_LOG; |
|
184 iIsWordTooLong = ETrue; |
|
185 iPosition = aBeginOfWord; |
|
186 iNewLengthOfWord = aNewLengthOfWord; |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // GetTextL |
|
191 // --------------------------------------------------------------------------- |
|
192 HBufC* CFsTextParser::GetTextL(TInt aStart, TInt aEnd) const |
|
193 { |
|
194 FUNC_LOG; |
|
195 HBufC* retVal = HBufC::NewL( aEnd - aStart + 1 ); |
|
196 // TBuf<200> someText01; |
|
197 if(aStart < 0 || aEnd > iText.DocumentLength() || aEnd < aStart) |
|
198 { |
|
199 User::Leave(KErrArgument); |
|
200 } |
|
201 |
|
202 // someText01.Zero(); |
|
203 TPtr ptr( retVal->Des() ); |
|
204 ptr.Append( iText.Read(aStart, aEnd - aStart + 1) ); |
|
205 while ( ptr.Length() < aEnd - aStart + 1 ) |
|
206 { |
|
207 ptr.Append( iText.Read( aStart + ptr.Length(), aEnd - aStart + 1 - ptr.Length() ) ); |
|
208 } |
|
209 // TPtrC retVal; |
|
210 // retVal.Set( someText01.Ptr(), someText01.Length() ); |
|
211 return retVal; |
|
212 } |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // GetTextureL |
|
216 // --------------------------------------------------------------------------- |
|
217 CFsTexture& CFsTextParser::GetTextureL(TInt aPos) |
|
218 { |
|
219 FUNC_LOG; |
|
220 if(aPos > iText.DocumentLength()) |
|
221 { |
|
222 User::Leave(KErrArgument); |
|
223 } |
|
224 |
|
225 const CTextField* field = iText.TextField(aPos); |
|
226 |
|
227 CFsTexture* retVal = NULL; |
|
228 |
|
229 TInt textureId; |
|
230 if(!IsTexturePosition(aPos, textureId)) |
|
231 { |
|
232 if(KFsRichTextPictureFieldUid == field->Type()) |
|
233 { |
|
234 TPictureHeader header = iText.PictureHeader(aPos); |
|
235 |
|
236 CMyPicture* picture = |
|
237 static_cast<CMyPicture*>(header.iPicture.AsPtr() ); |
|
238 |
|
239 CFbsBitmap* bitmap = picture->GetBitmap(); |
|
240 CFbsBitmap* bitmapMask = picture->GetBitmapMask(); |
|
241 |
|
242 CFsTexture& texture = (iTextureLoader->AppendBitmapL(bitmap, bitmapMask)); |
|
243 |
|
244 TTextureIndex newTextureIndex; |
|
245 newTextureIndex.iPositionInText = aPos; |
|
246 newTextureIndex.iTextureId = texture.Id(); |
|
247 |
|
248 iTextureIndex.Append(newTextureIndex); |
|
249 |
|
250 retVal = &texture; |
|
251 } |
|
252 else if(KFsRichTextSmileyFieldUid == field->Type()) |
|
253 { |
|
254 |
|
255 TInt smileyIndex = ((CSmileyField*)(field))->GetSmileyIndex(); |
|
256 |
|
257 |
|
258 TFileName fileName = iSmileyParser->GetSmileyFileName(smileyIndex); |
|
259 |
|
260 |
|
261 CFsTexture& texture = iTextureLoader->LoadTextureL( fileName ); |
|
262 |
|
263 TTextureIndex newTextureIndex; |
|
264 newTextureIndex.iPositionInText = aPos; |
|
265 newTextureIndex.iTextureId = texture.Id(); |
|
266 |
|
267 iTextureIndex.Append(newTextureIndex); |
|
268 |
|
269 retVal = &texture; |
|
270 } |
|
271 else |
|
272 { |
|
273 User::Leave(KErrArgument); |
|
274 } |
|
275 } |
|
276 else |
|
277 { |
|
278 CFsTexture* texture = iTextureLoader->SearchById(textureId); |
|
279 |
|
280 retVal = texture; |
|
281 } |
|
282 |
|
283 return *retVal; |
|
284 } |
|
285 |
|
286 TBool CFsTextParser::IsFieldInrange(TInt aStartPosition, TInt aRange) |
|
287 { |
|
288 FUNC_LOG; |
|
289 TInt siezOfArray = iFieldLocation.Count(); |
|
290 |
|
291 TBool retVal = EFalse; |
|
292 |
|
293 TInt endPosition = aStartPosition + aRange; |
|
294 TInt pos; |
|
295 |
|
296 for(TInt i = 0 ; i < siezOfArray ; i++) |
|
297 { |
|
298 pos = iFieldLocation[i]; |
|
299 |
|
300 if(aStartPosition <= pos && pos <= endPosition) |
|
301 { |
|
302 retVal = ETrue; |
|
303 i = siezOfArray; |
|
304 } |
|
305 } |
|
306 |
|
307 return retVal; |
|
308 } |
|
309 |
|
310 void CFsTextParser::FindBlokOfText() |
|
311 { |
|
312 if(!iGetCharsUsed) |
|
313 { |
|
314 iText.GetChars(iGNOSomeText, iGNOCharFormat, iPosition); |
|
315 iLastGetCharsPos = iPosition; |
|
316 iLastGetCharsLength = iGNOSomeText.Length(); |
|
317 iGetCharsUsed = ETrue; |
|
318 } |
|
319 else |
|
320 { |
|
321 if(iPosition >= iLastGetCharsPos && iPosition < (iLastGetCharsPos + iLastGetCharsLength)) |
|
322 { |
|
323 iGNOSomeText.Set(iText.Read( |
|
324 iPosition, |
|
325 iLastGetCharsLength - (iPosition - iLastGetCharsPos))); |
|
326 |
|
327 iLastGetCharsPos = iPosition; |
|
328 iLastGetCharsLength = iGNOSomeText.Length(); |
|
329 } |
|
330 else |
|
331 { |
|
332 if(iPosition == iLastGetCharsPosOfNextBlock) |
|
333 { |
|
334 iGNOSomeText.Set(iText.Read(iPosition, |
|
335 iLastGetCharsLengthOfNextBlock)); |
|
336 |
|
337 iLastGetCharsPos = iPosition; |
|
338 iLastGetCharsLength = iGNOSomeText.Length(); |
|
339 iGNOCharFormat = iGNOCharFormatOfNextBlock; |
|
340 } |
|
341 else |
|
342 { |
|
343 iText.GetChars(iGNOSomeText, iGNOCharFormat, iPosition); |
|
344 |
|
345 iLastGetCharsPos = iPosition; |
|
346 iLastGetCharsLength = iGNOSomeText.Length(); |
|
347 } |
|
348 } |
|
349 } |
|
350 } |
|
351 |
|
352 void CFsTextParser::FindNextBlokOfText() |
|
353 { |
|
354 if(!iGetCharsUsedOfNextBlock) |
|
355 { |
|
356 iText.GetChars(iGNOSomeTextOfNextBlock, iGNOCharFormatOfNextBlock, iGNONextPosition ); |
|
357 iLastGetCharsPosOfNextBlock = iGNONextPosition; |
|
358 iLastGetCharsLengthOfNextBlock = iGNOSomeTextOfNextBlock.Length(); |
|
359 iGetCharsUsedOfNextBlock = ETrue; |
|
360 } |
|
361 else |
|
362 { |
|
363 if(iLastGetCharsPosOfNextBlock == iGNONextPosition) |
|
364 { |
|
365 iGNOSomeTextOfNextBlock.Set(iText.Read(iGNONextPosition, |
|
366 iLastGetCharsLengthOfNextBlock)); |
|
367 } |
|
368 else |
|
369 { |
|
370 iText.GetChars(iGNOSomeTextOfNextBlock, iGNOCharFormatOfNextBlock, iGNONextPosition ); |
|
371 iLastGetCharsPosOfNextBlock = iGNONextPosition; |
|
372 iLastGetCharsLengthOfNextBlock = iGNOSomeTextOfNextBlock.Length(); |
|
373 } |
|
374 } |
|
375 } |
|
376 |
|
377 TInt CFsTextParser::IsNewLinePresent(TInt aPosition, TInt aLength) |
|
378 { |
|
379 TInt retVal = -1; |
|
380 |
|
381 TInt index = 0; |
|
382 TInt newLineArrayCount = iNewLineArray.Count(); |
|
383 |
|
384 if(iNewLineArray[iNewLineArrayIndex] < aPosition && |
|
385 iNewLineArray[iNewLineArrayIndex] < (aPosition + aLength)) |
|
386 { |
|
387 for(index = iNewLineArrayIndex ; index < newLineArrayCount - 1 ; ++index) |
|
388 { |
|
389 TInt alamakota= iNewLineArray[index]; |
|
390 |
|
391 if(iNewLineArray[index] >= aPosition && |
|
392 iNewLineArray[index] < (aPosition + aLength)) |
|
393 { |
|
394 retVal = iNewLineArray[index] - aPosition; |
|
395 iNewLineArrayIndex = index; |
|
396 index = newLineArrayCount + 1; |
|
397 } |
|
398 else if(iNewLineArray[index] > aPosition && |
|
399 iNewLineArray[index] > (aPosition + aLength)) |
|
400 { |
|
401 retVal = -1; |
|
402 index = newLineArrayCount + 1; |
|
403 } |
|
404 } |
|
405 } |
|
406 else |
|
407 { |
|
408 for(index = iNewLineArrayIndex ; index >= 0 ; --index) |
|
409 { |
|
410 TInt alamakota= iNewLineArray[index]; |
|
411 |
|
412 if(iNewLineArray[index] >= aPosition && |
|
413 iNewLineArray[index] < (aPosition + aLength)) |
|
414 { |
|
415 retVal = iNewLineArray[index] - aPosition; |
|
416 iNewLineArrayIndex = index; |
|
417 index = 0; |
|
418 } |
|
419 else if(iNewLineArray[index] > aPosition && |
|
420 iNewLineArray[index] > (aPosition + aLength)) |
|
421 { |
|
422 retVal = -1; |
|
423 index = 0; |
|
424 } |
|
425 } |
|
426 } |
|
427 |
|
428 return retVal; |
|
429 } |
|
430 |
|
431 |
|
432 MFsRichTextObject* CFsTextParser::GetNextObjectL() |
|
433 { |
|
434 MFsRichTextObject* textObject = NULL; |
|
435 |
|
436 TInt startPos = 0; |
|
437 TInt wordLength = 0; |
|
438 |
|
439 FindBlokOfText(); |
|
440 |
|
441 iGNONextPosition = iPosition + iGNOSomeText.Length(); |
|
442 |
|
443 if(iGNONextPosition < iText.DocumentLength()) |
|
444 { |
|
445 FindNextBlokOfText(); |
|
446 |
|
447 if(iGNOCharFormat.IsEqual(iGNOCharFormatOfNextBlock)) |
|
448 { |
|
449 TBool connect = ETrue; |
|
450 |
|
451 if(iGNOSomeTextOfNextBlock.Length() == 1) |
|
452 { |
|
453 TBuf<1> checkForSpecialChar; |
|
454 _LIT(specialChar, "\xFFFC"); |
|
455 |
|
456 iText.Extract(checkForSpecialChar, iGNONextPosition, 1); |
|
457 |
|
458 if(checkForSpecialChar.Right(1).Compare(specialChar) == 0) |
|
459 { |
|
460 connect = EFalse; |
|
461 } |
|
462 } |
|
463 if(iGNOSomeText.Length() == 1) |
|
464 { |
|
465 TBuf<1> checkForSpecialChar; |
|
466 _LIT(specialChar, "\xFFFC"); |
|
467 |
|
468 iText.Extract(checkForSpecialChar, iPosition, 1); |
|
469 |
|
470 if(checkForSpecialChar.Right(1).Compare(specialChar) == 0) |
|
471 { |
|
472 connect = EFalse; |
|
473 } |
|
474 } |
|
475 |
|
476 if(connect) |
|
477 { |
|
478 TInt l1 = iGNOSomeText.Length(); |
|
479 TInt l2 = iGNOSomeTextOfNextBlock.Length(); |
|
480 |
|
481 TBuf<121> someCharacter; |
|
482 |
|
483 TInt getTextLength = (l1 + l2) > 120 ? 120 : (l1 + l2); |
|
484 |
|
485 iText.Extract(someCharacter, iPosition, getTextLength); |
|
486 |
|
487 iGNOSomeText.Set(someCharacter.Left(someCharacter.Length())); |
|
488 } |
|
489 } |
|
490 } |
|
491 |
|
492 if(iPosition == 0 || iLastPosition != iLastWordPosition || iLastLength < 120) |
|
493 { |
|
494 iText.GetWordInfo( |
|
495 iPosition, |
|
496 startPos, |
|
497 wordLength, |
|
498 EFalse, |
|
499 EFalse); |
|
500 iLastLength = wordLength; |
|
501 } |
|
502 |
|
503 if(iGNOSomeText.Length() > 100) |
|
504 { |
|
505 //iGNOSomeText.Set(iText.Read(iPosition,100)); |
|
506 iGNOSomeText.Set(iGNOSomeText.Mid(0, 100)); |
|
507 |
|
508 iLastLength -= 100; |
|
509 |
|
510 //wordLength = 100; |
|
511 //startPos = iPosition; |
|
512 } |
|
513 |
|
514 |
|
515 iLastWordPosition = iPosition; |
|
516 |
|
517 if ( !wordLength ) |
|
518 { |
|
519 wordLength = iNewLengthOfWord != 0 ? iNewLengthOfWord : 0; |
|
520 startPos = iPosition; |
|
521 } |
|
522 |
|
523 TInt a1 = iGNOSomeText.Length(); |
|
524 TInt a2 = startPos + wordLength - iPosition + 1; |
|
525 |
|
526 if(a1 > a2) |
|
527 { |
|
528 //iGNOSomeText.Set(iText.Read(iPosition,startPos + wordLength - iPosition + 1)); |
|
529 iGNOSomeText.Set(iGNOSomeText.Mid(0, startPos + wordLength - iPosition + 1)); |
|
530 } |
|
531 |
|
532 /*_LIT(endOfFile, "\x2029"); |
|
533 if(iGNOSomeText.Length() > 0 && iGNOSomeText.Right(1).Compare(endOfFile) == 0) |
|
534 { |
|
535 iGNOSomeText.Set(iGNOSomeText.Mid(0, iGNOSomeText.Length() - 1)); |
|
536 }*/ |
|
537 |
|
538 |
|
539 if(iIsWordTooLong) |
|
540 { |
|
541 iIsWordTooLong = EFalse; |
|
542 |
|
543 if(iGNOSomeText.Length() > iNewLengthOfWord) |
|
544 { |
|
545 iGNOSomeText.Set(iText.Read( |
|
546 iPosition, |
|
547 iNewLengthOfWord)); |
|
548 } |
|
549 } |
|
550 |
|
551 //czy text jest elementem expanda |
|
552 TInt isWordPartOfExpandArea = IsWordPartOfExpandArea(iPosition, |
|
553 iPosition + iGNOSomeText.Length() - 1); |
|
554 |
|
555 if(-1 != isWordPartOfExpandArea) |
|
556 { |
|
557 // Profile |
|
558 if(iExpandArray.Count() > isWordPartOfExpandArea && |
|
559 iExpandArray[isWordPartOfExpandArea].iStartIndex > iPosition && |
|
560 iExpandArray[isWordPartOfExpandArea].iStartIndex < |
|
561 (iPosition + iGNOSomeText.Length() - 1)) |
|
562 { |
|
563 //w polowie slowa zaczyna sie expand - |
|
564 //nalezy slowo uciac i zajac sie |
|
565 //poczatkowa czescia, ktora nie jest expandem= |
|
566 iGNOSomeText.Set( iText.Read( |
|
567 iPosition, |
|
568 iExpandArray[isWordPartOfExpandArea].iStartIndex |
|
569 - iPosition ) ); |
|
570 |
|
571 isWordPartOfExpandArea = -1; |
|
572 } |
|
573 //wariant 3 |
|
574 else if(iExpandArray[isWordPartOfExpandArea].iStartIndex + |
|
575 iExpandArray[isWordPartOfExpandArea].iLength >= iPosition |
|
576 && |
|
577 iExpandArray[isWordPartOfExpandArea].iStartIndex + |
|
578 iExpandArray[isWordPartOfExpandArea].iLength < |
|
579 (iPosition + iGNOSomeText.Length() - 1)) |
|
580 { |
|
581 //poczatek slowa jest expandem |
|
582 //a jego konie nie jest - ten koniec nalezy uciac |
|
583 iGNOSomeText.Set(iText.Read( |
|
584 iPosition, |
|
585 iExpandArray[isWordPartOfExpandArea].iStartIndex + |
|
586 iExpandArray[isWordPartOfExpandArea].iLength - |
|
587 iPosition)); |
|
588 } |
|
589 } |
|
590 |
|
591 if(-1 != isWordPartOfExpandArea) |
|
592 { |
|
593 //Profile |
|
594 if(!iExpandArray[isWordPartOfExpandArea].iIsExpand) |
|
595 { |
|
596 if(iPosition >= |
|
597 iExpandArray[isWordPartOfExpandArea].iStartIndex + |
|
598 iExpandArray[isWordPartOfExpandArea].iCaptionLength) |
|
599 { |
|
600 iLastPosition = iPosition; |
|
601 iPosition = |
|
602 iExpandArray[isWordPartOfExpandArea].iStartIndex + |
|
603 iExpandArray[isWordPartOfExpandArea].iLength; |
|
604 |
|
605 //jak expand jest do konca textu; |
|
606 if(IsNextObject()) |
|
607 { |
|
608 return GetNextObjectL(); |
|
609 } |
|
610 else |
|
611 { |
|
612 textObject = CFsRichTextNewLine::NewL(); |
|
613 |
|
614 textObject->SetBeginOfObject(iPosition); |
|
615 textObject->SetEndOfObject(iPosition); |
|
616 |
|
617 iLastPosition = iPosition; |
|
618 iPosition += 1; |
|
619 |
|
620 return textObject; |
|
621 } |
|
622 } |
|
623 |
|
624 //expand nie jest rozwiniety dlatego |
|
625 //mozemy przekazac tylko caption |
|
626 if(iExpandArray[isWordPartOfExpandArea].iStartIndex + |
|
627 iExpandArray[isWordPartOfExpandArea].iCaptionLength > |
|
628 iPosition && |
|
629 iExpandArray[isWordPartOfExpandArea].iStartIndex + |
|
630 iExpandArray[isWordPartOfExpandArea].iCaptionLength < |
|
631 iPosition + iGNOSomeText.Length()) |
|
632 { |
|
633 iGNOSomeText.Set(iText.Read( |
|
634 iPosition, |
|
635 iExpandArray[isWordPartOfExpandArea].iStartIndex + |
|
636 iExpandArray[isWordPartOfExpandArea].iCaptionLength |
|
637 - iPosition)); |
|
638 } |
|
639 } |
|
640 // if ( Profiling2( &iGNOSomeText, &isWordPartOfExpandArea, textObject ) ) |
|
641 // { |
|
642 // return GetNextObjectL(); |
|
643 // } |
|
644 } |
|
645 |
|
646 TInt isWordPartOfHotSpotArea = |
|
647 IsWordPartOfHotSpotArea( |
|
648 iPosition, |
|
649 iPosition + iGNOSomeText.Length() - 1); |
|
650 |
|
651 if(-1 != isWordPartOfHotSpotArea |
|
652 && iHotSpotArray.Count() > isWordPartOfHotSpotArea) |
|
653 { |
|
654 if(iHotSpotArray[isWordPartOfHotSpotArea].iStartIndex > iPosition && |
|
655 iHotSpotArray[isWordPartOfHotSpotArea].iStartIndex < |
|
656 (iPosition + iGNOSomeText.Length() - 1)) |
|
657 { |
|
658 //w polowie slowa zaczyna sie expand - |
|
659 //nalezy slowo uciac i zajac sie |
|
660 //poczatkowa czescia, ktora nie jest expandem= |
|
661 iGNOSomeText.Set( iText.Read( |
|
662 iPosition, |
|
663 iHotSpotArray[isWordPartOfHotSpotArea].iStartIndex |
|
664 - iPosition ) ); |
|
665 |
|
666 isWordPartOfHotSpotArea = -1; |
|
667 } |
|
668 //wariant 3 |
|
669 else if(iHotSpotArray[isWordPartOfHotSpotArea].iStartIndex + |
|
670 iHotSpotArray[isWordPartOfHotSpotArea].iLength >= iPosition && |
|
671 iHotSpotArray[isWordPartOfHotSpotArea].iStartIndex + |
|
672 iHotSpotArray[isWordPartOfHotSpotArea].iLength < |
|
673 (iPosition + iGNOSomeText.Length() - 1)) |
|
674 { |
|
675 //poczatek slowa jest expandem |
|
676 //a jego konie nie jest - ten koniec nalezy uciac |
|
677 iGNOSomeText.Set(iText.Read( |
|
678 iPosition, |
|
679 iHotSpotArray[isWordPartOfHotSpotArea].iStartIndex + |
|
680 iHotSpotArray[isWordPartOfHotSpotArea].iLength - iPosition)); |
|
681 } |
|
682 } |
|
683 |
|
684 TFindFieldInfo info; |
|
685 |
|
686 TInt dx = iGNOSomeText.Length(); |
|
687 |
|
688 if(iPosition + dx > iText.DocumentLength()) |
|
689 { |
|
690 dx = iText.DocumentLength() - iPosition - 1; |
|
691 } |
|
692 |
|
693 //is new line in iGNOSomeText |
|
694 |
|
695 TInt positionOfNewLine = IsNewLinePresent(iPosition, iGNOSomeText.Length()); |
|
696 TBool isNewLinePresent = EFalse; |
|
697 |
|
698 if( positionOfNewLine > -1 ) |
|
699 { |
|
700 if(positionOfNewLine == 0) |
|
701 { |
|
702 isNewLinePresent = ETrue; |
|
703 iGNOSomeText.Set(iGNOSomeText.Mid(0, 1)); |
|
704 } |
|
705 else |
|
706 { |
|
707 iGNOSomeText.Set(iGNOSomeText.Mid(0, positionOfNewLine)); |
|
708 } |
|
709 } |
|
710 |
|
711 if(IsFieldInrange(iPosition, dx) && iText.FindFields(info, iPosition, dx)) |
|
712 { |
|
713 if(iPosition != info.iFirstFieldPos) |
|
714 { |
|
715 iGNOSomeText.Set(iText.Read( |
|
716 iPosition, |
|
717 info.iFirstFieldPos - iPosition)); |
|
718 textObject = static_cast<MFsRichTextObject*> |
|
719 (CFsRichTextText::NewL(iGNOSomeText, 0)); |
|
720 |
|
721 TInt styleId = iTextStyleManager->GetStyleIDL(iGNOCharFormat); |
|
722 ((CFsRichTextText*)textObject)->SetStyleId(styleId); |
|
723 |
|
724 textObject->SetBeginOfObject(iPosition); |
|
725 textObject->SetEndOfObject(iPosition + iGNOSomeText.Length() - 1); |
|
726 |
|
727 ((CFsRichTextText*)textObject)->SetTextColor( |
|
728 iGNOCharFormat.iFontPresentation.iTextColor ); |
|
729 |
|
730 iLastPosition = iPosition; |
|
731 iPosition += iGNOSomeText.Length(); |
|
732 } |
|
733 else |
|
734 { |
|
735 //pobrac fielda |
|
736 const CTextField* field = iText.TextField(iPosition); |
|
737 |
|
738 if(KFsRichTextPictureFieldUid == field->Type()) |
|
739 { |
|
740 TPictureHeader header = iText.PictureHeader(iPosition); |
|
741 |
|
742 CMyPicture* picture = |
|
743 static_cast<CMyPicture*>(header.iPicture.AsPtr() ); |
|
744 |
|
745 textObject = CFsRichTextPicture::NewL(); |
|
746 |
|
747 TSize sizeOfPicture = TSize( 0, 0 ); |
|
748 picture->GetOriginalSizeInTwips( sizeOfPicture ); |
|
749 |
|
750 static_cast< CFsRichTextPicture* > |
|
751 (textObject)->SetTextureSize(sizeOfPicture); |
|
752 |
|
753 textObject->SetBeginOfObject(iPosition); |
|
754 textObject->SetEndOfObject(iPosition); |
|
755 |
|
756 iLastPosition = iPosition; |
|
757 iPosition += 1; |
|
758 } |
|
759 else if(KFsRichTextSmileyFieldUid == field->Type()) |
|
760 { |
|
761 TInt smileyIndex = ((CSmileyField*)(field))->GetSmileyIndex(); |
|
762 |
|
763 iGNOSomeText.Set(iText.Read( |
|
764 iPosition, |
|
765 iSmileyParser->GetSmileyLength(smileyIndex))); |
|
766 |
|
767 CFsRichTextText* smileyTextObject = |
|
768 CFsRichTextText::NewL(iGNOSomeText, 0); |
|
769 smileyTextObject->SetTextColor( |
|
770 iGNOCharFormat.iFontPresentation.iTextColor ); |
|
771 |
|
772 TInt styleId = iTextStyleManager->GetStyleIDL(iGNOCharFormat); |
|
773 ((CFsRichTextText*)smileyTextObject)->SetStyleId(styleId); |
|
774 |
|
775 TFileName fileName = |
|
776 iSmileyParser->GetSmileyFileName(smileyIndex); |
|
777 |
|
778 TInt textureId = 0; |
|
779 TSize texturesize = TSize( 0, 0 ); |
|
780 if(IsTexturePosition(iPosition, textureId)) |
|
781 { |
|
782 CFsTexture* texture = iTextureLoader->SearchById(textureId); |
|
783 texturesize = texture->Texture().Size(); |
|
784 } |
|
785 else |
|
786 { |
|
787 CFsTexture& texture = iTextureLoader->LoadTextureL( fileName ); |
|
788 |
|
789 TTextureIndex newTextureIndex; |
|
790 newTextureIndex.iPositionInText = iPosition; |
|
791 newTextureIndex.iTextureId = texture.Id(); |
|
792 |
|
793 iTextureIndex.Append(newTextureIndex); |
|
794 |
|
795 texturesize = texture.Texture().Size(); |
|
796 } |
|
797 |
|
798 CFsRichTextPicture* smileyPictureObject = |
|
799 CFsRichTextPicture::NewL(); |
|
800 |
|
801 if(iIsSetSizeOfSmiley) |
|
802 { |
|
803 texturesize = iSizeOfSmiley; |
|
804 } |
|
805 else if ( texturesize == TSize( 0, 0 ) ) |
|
806 { |
|
807 TFrameInfo frameInfo; |
|
808 |
|
809 CFsTextureLoader::GetFrameInfoL( |
|
810 fileName, |
|
811 frameInfo ); |
|
812 texturesize = frameInfo.iOverallSizeInPixels; |
|
813 TSize texturesize = TSize( 10, 10 ); |
|
814 } |
|
815 |
|
816 static_cast< CFsRichTextPicture* > |
|
817 (smileyPictureObject)->SetTextureSize( texturesize ); |
|
818 |
|
819 textObject = CFsRichTextSmiley::NewL( |
|
820 smileyTextObject, |
|
821 smileyPictureObject); |
|
822 |
|
823 textObject->SetBeginOfObject(iPosition); |
|
824 textObject->SetEndOfObject(iPosition + iGNOSomeText.Length() - 1); |
|
825 |
|
826 iLastPosition = iPosition; |
|
827 iPosition += iGNOSomeText.Length(); |
|
828 } |
|
829 } |
|
830 } |
|
831 else |
|
832 { |
|
833 if(isNewLinePresent) |
|
834 { |
|
835 textObject = CFsRichTextNewLine::NewL(); |
|
836 |
|
837 textObject->SetBeginOfObject(iPosition); |
|
838 textObject->SetEndOfObject(iPosition); |
|
839 |
|
840 iLastPosition = iPosition; |
|
841 iPosition += 1; |
|
842 } |
|
843 else |
|
844 { |
|
845 textObject = static_cast<MFsRichTextObject*> |
|
846 (CFsRichTextText::NewL(iGNOSomeText, 0)); |
|
847 |
|
848 TInt styleId = iTextStyleManager->GetStyleIDL(iGNOCharFormat); |
|
849 ((CFsRichTextText*)textObject)->SetStyleId(styleId); |
|
850 |
|
851 textObject->SetBeginOfObject(iPosition); |
|
852 textObject->SetEndOfObject(iPosition + iGNOSomeText.Length() - 1); |
|
853 |
|
854 ((CFsRichTextText*)textObject)->SetTextColor( |
|
855 iGNOCharFormat.iFontPresentation.iTextColor ); |
|
856 |
|
857 TBidiText * bidiText = TBidiText::NewL(iGNOSomeText.Length() + 1, 1); |
|
858 |
|
859 TBool found = EFalse; |
|
860 |
|
861 TBidiText::TDirectionality direction = bidiText->TextDirectionality(iGNOSomeText, &found ); |
|
862 |
|
863 // <cmail> |
|
864 if ( !found ) |
|
865 { |
|
866 direction = AknLayoutUtils::LayoutMirrored() ? |
|
867 TBidiText::ERightToLeft : TBidiText::ELeftToRight; |
|
868 } |
|
869 // </cmail> |
|
870 |
|
871 static_cast<CFsRichTextText*>(textObject)->SetTextDirection(direction); |
|
872 |
|
873 delete bidiText; |
|
874 |
|
875 TInt sizeOfSomeText = iGNOSomeText.Length(); |
|
876 TBool isWhiteSpace = ETrue; |
|
877 for(TInt k = 0 ; k < sizeOfSomeText ; ++k) |
|
878 { |
|
879 if(iGNOSomeText[k] != ' ') |
|
880 { |
|
881 isWhiteSpace = EFalse; |
|
882 k = sizeOfSomeText + 1; |
|
883 } |
|
884 } |
|
885 |
|
886 textObject->SetIsWhiteSpace(isWhiteSpace); |
|
887 |
|
888 iLastPosition = iPosition; |
|
889 iPosition += iGNOSomeText.Length(); |
|
890 } |
|
891 } |
|
892 |
|
893 if(-1 != isWordPartOfHotSpotArea) |
|
894 { |
|
895 textObject->SetHotSpot( ETrue ); |
|
896 textObject->SetIdOfHotSpot(isWordPartOfHotSpotArea); |
|
897 textObject->SetTypeOfHotSpot( |
|
898 iHotSpotArray[isWordPartOfHotSpotArea].iId ); |
|
899 } |
|
900 |
|
901 if(-1 != isWordPartOfExpandArea) |
|
902 { |
|
903 textObject->SetEmbeded( ETrue ); |
|
904 textObject->SetIdOfEmbeded(isWordPartOfExpandArea); |
|
905 } |
|
906 |
|
907 return textObject; |
|
908 } |
|
909 |
|
910 void CFsTextParser::SetTextStylemanager( |
|
911 CFsTextStyleManager* aTextStyleManager ) |
|
912 { |
|
913 FUNC_LOG; |
|
914 iTextStyleManager = aTextStyleManager; |
|
915 } |
|
916 |
|
917 void CFsTextParser::ConvertBitmapL(CPicture* aPicture, CFbsBitmap*& aBitmap) |
|
918 { |
|
919 FUNC_LOG; |
|
920 TSize size; |
|
921 aPicture->GetOriginalSizeInTwips(size); |
|
922 aBitmap = new (ELeave)CFbsBitmap; |
|
923 |
|
924 size.iWidth = 45; |
|
925 size.iWidth = 45; |
|
926 |
|
927 User::LeaveIfError(aBitmap->Create(size,EColor256)); |
|
928 CleanupStack::PushL(aBitmap); |
|
929 |
|
930 //create an offscreen device and context |
|
931 CGraphicsContext* bitmapContext = NULL; |
|
932 CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(aBitmap); |
|
933 CleanupStack::PushL(bitmapDevice); |
|
934 User::LeaveIfError(bitmapDevice->CreateContext(bitmapContext)); |
|
935 CleanupStack::PushL(bitmapContext); |
|
936 |
|
937 aPicture->Draw( |
|
938 *bitmapContext, |
|
939 TPoint(0,0), |
|
940 TRect( TPoint(0,0),TPoint(45,45) ), |
|
941 bitmapDevice); |
|
942 |
|
943 CleanupStack::PopAndDestroy(bitmapContext); |
|
944 CleanupStack::PopAndDestroy(bitmapDevice); |
|
945 CleanupStack::Pop(aBitmap); |
|
946 } |
|
947 |
|
948 |
|
949 |
|
950 TInt CFsTextParser::IsWordPartOfHotSpotArea( |
|
951 TInt aStartPosition, |
|
952 TInt aEndPosition ) |
|
953 { |
|
954 FUNC_LOG; |
|
955 TInt retVal = -1; |
|
956 |
|
957 for(TInt i = 0 ; i < iHotSpotArray.Count() ; ++i) |
|
958 { |
|
959 /* |
|
960 TRichTextHotSpotArea test; |
|
961 test.iLength = iHotSpotArray[i].iLength; |
|
962 test.iStartIndex = iHotSpotArray[i].iStartIndex; |
|
963 */ |
|
964 |
|
965 if(iHotSpotArray[i].iStartIndex >= aStartPosition && |
|
966 iHotSpotArray[i].iStartIndex < aEndPosition) |
|
967 { |
|
968 if(-1 == retVal) |
|
969 { |
|
970 retVal = i; |
|
971 } |
|
972 else |
|
973 { |
|
974 if ( iHotSpotArray[i].iStartIndex |
|
975 < iHotSpotArray[retVal].iStartIndex ) |
|
976 { |
|
977 retVal = i; |
|
978 } |
|
979 } |
|
980 } |
|
981 else if ( aStartPosition >= iHotSpotArray[i].iStartIndex |
|
982 && aStartPosition |
|
983 < iHotSpotArray[i].iStartIndex |
|
984 + iHotSpotArray[i].iLength ) |
|
985 { |
|
986 if(-1 == retVal) |
|
987 { |
|
988 retVal = i; |
|
989 } |
|
990 else |
|
991 { |
|
992 if ( iHotSpotArray[i].iStartIndex |
|
993 < iHotSpotArray[retVal].iStartIndex ) |
|
994 { |
|
995 retVal = i; |
|
996 } |
|
997 } |
|
998 } |
|
999 } |
|
1000 return retVal; |
|
1001 } |
|
1002 |
|
1003 |
|
1004 |
|
1005 |
|
1006 TBool CFsTextParser::IsNextObject() const |
|
1007 { |
|
1008 FUNC_LOG; |
|
1009 |
|
1010 TInt documentLength = iText.DocumentLength() - 1; |
|
1011 TBool retVal = EFalse; |
|
1012 |
|
1013 if(documentLength < iPosition) |
|
1014 { |
|
1015 retVal = EFalse; |
|
1016 } |
|
1017 else |
|
1018 { |
|
1019 retVal = ETrue; |
|
1020 } |
|
1021 |
|
1022 return retVal; |
|
1023 } |
|
1024 |
|
1025 TBool CFsTextParser::MoveParsingPosition( TInt aMoveParsingPositionBy ) |
|
1026 { |
|
1027 FUNC_LOG; |
|
1028 TBool retVal = ETrue; |
|
1029 |
|
1030 if( (iPosition + aMoveParsingPositionBy) < 0 || |
|
1031 (iPosition + aMoveParsingPositionBy) >= iText.DocumentLength()) |
|
1032 { |
|
1033 retVal = EFalse; |
|
1034 } |
|
1035 else |
|
1036 { |
|
1037 iPosition += aMoveParsingPositionBy; |
|
1038 } |
|
1039 |
|
1040 return retVal; |
|
1041 } |
|
1042 |
|
1043 |
|
1044 |
|
1045 TBool CFsTextParser::ParseTextL() |
|
1046 { |
|
1047 FUNC_LOG; |
|
1048 TBool retVal = ETrue; |
|
1049 |
|
1050 TInt textLength = iText.DocumentLength(); |
|
1051 |
|
1052 TBuf<1> someCharacter; |
|
1053 |
|
1054 _LIT(fourSpaces, " "); |
|
1055 _LIT(validNewLine, "\n"); |
|
1056 |
|
1057 |
|
1058 _LIT(newLine1, "\x2028"); |
|
1059 _LIT(newLine2, "\x2029"); |
|
1060 _LIT(newLine3, "\x85"); |
|
1061 _LIT(newLine4, "\x0D"); |
|
1062 |
|
1063 _LIT(tabulator,"\x2007"); |
|
1064 |
|
1065 for(TInt i = 0 ; i < iText.GetNumberOfExpandAreas() ; ++i) |
|
1066 { |
|
1067 iExpandArray.AppendL(iText.GetExpandAreaL(i)); |
|
1068 } |
|
1069 |
|
1070 for(TInt i = 0 ; i < iText.GetNumberOfHotSpotAreas() ; ++i) |
|
1071 { |
|
1072 iHotSpotArray.AppendL(iText.GetHotSpotAreaL(i)); |
|
1073 } |
|
1074 |
|
1075 textLength = iText.DocumentLength(); |
|
1076 for(TInt i = 0 ; i < textLength ; ++i) |
|
1077 { |
|
1078 iText.Extract(someCharacter, i, 1); |
|
1079 |
|
1080 if(someCharacter[0] == '\t') |
|
1081 { |
|
1082 iText.DeleteL(i,1); |
|
1083 iText.InsertL(i,fourSpaces); |
|
1084 |
|
1085 textLength = iText.DocumentLength(); |
|
1086 |
|
1087 for(TInt j = 0 ; j < iText.GetNumberOfExpandAreas() ; ++j) |
|
1088 { |
|
1089 if(iExpandArray[j].iStartIndex > i) |
|
1090 { |
|
1091 iExpandArray[j].iStartIndex += 3; |
|
1092 } |
|
1093 } |
|
1094 |
|
1095 for(TInt j = 0 ; j < iText.GetNumberOfHotSpotAreas() ; ++j) |
|
1096 { |
|
1097 if(iHotSpotArray[j].iStartIndex <= i && |
|
1098 iHotSpotArray[j].iStartIndex + iHotSpotArray[j].iLength > i) |
|
1099 { |
|
1100 iHotSpotArray[j].iLength += 3; |
|
1101 } |
|
1102 if(iHotSpotArray[j].iStartIndex > i) |
|
1103 { |
|
1104 iHotSpotArray[j].iStartIndex += 3; |
|
1105 } |
|
1106 } |
|
1107 |
|
1108 ++i; |
|
1109 } |
|
1110 else if(someCharacter.Right(1).Compare(tabulator) == 0) |
|
1111 { |
|
1112 iText.DeleteL(i,1); |
|
1113 iText.InsertL(i,fourSpaces); |
|
1114 |
|
1115 textLength = iText.DocumentLength(); |
|
1116 ++i; |
|
1117 } |
|
1118 else if(someCharacter.Right(1).Compare(validNewLine) == 0) |
|
1119 { |
|
1120 TBuf<1> anotherCharacter; |
|
1121 if ( iText.DocumentLength() > ( i + 1 ) ) |
|
1122 { |
|
1123 iText.Extract(anotherCharacter, i + 1, 1); |
|
1124 |
|
1125 if( anotherCharacter.Right(1).Compare(newLine3) == 0 || |
|
1126 anotherCharacter.Right(1).Compare(newLine4) == 0 ) |
|
1127 { |
|
1128 iText.DeleteL( i, 2 ); |
|
1129 iText.InsertL( i, validNewLine ); |
|
1130 iText.InsertL( i, _L(" ") ); |
|
1131 |
|
1132 textLength = iText.DocumentLength(); |
|
1133 } |
|
1134 } |
|
1135 } |
|
1136 } |
|
1137 |
|
1138 textLength = iText.DocumentLength(); |
|
1139 TInt lastNewLine = 0; |
|
1140 TPtrC someText; |
|
1141 |
|
1142 for(TInt i = 0 ; i < textLength ; ++i) |
|
1143 { |
|
1144 iText.Extract(someCharacter, i, 1); |
|
1145 |
|
1146 if(someCharacter.Right(1).Compare(validNewLine) == 0 || |
|
1147 someCharacter.Right(1).Compare(newLine1) == 0 || |
|
1148 someCharacter.Right(1).Compare(newLine2) == 0 || |
|
1149 someCharacter.Right(1).Compare(newLine3) == 0 || |
|
1150 someCharacter.Right(1).Compare(newLine4) == 0 |
|
1151 || i == textLength - 1 |
|
1152 ) |
|
1153 { |
|
1154 iNewLineArray.AppendL(i); |
|
1155 |
|
1156 someText.Set(iText.Read( |
|
1157 lastNewLine, |
|
1158 i - lastNewLine)); |
|
1159 |
|
1160 // <cmail> |
|
1161 TInt partOfHotspotArea = IsWordPartOfHotSpotArea( |
|
1162 lastNewLine, |
|
1163 i); |
|
1164 // </cmail> |
|
1165 |
|
1166 lastNewLine = i; |
|
1167 |
|
1168 TBidiText * bidiText = TBidiText::NewL(someText.Length() + 1, 1); |
|
1169 |
|
1170 TBool found = EFalse; |
|
1171 |
|
1172 TBidiText::TDirectionality direction = bidiText->TextDirectionality(someText, &found ); |
|
1173 |
|
1174 delete bidiText; |
|
1175 |
|
1176 // <cmail> |
|
1177 if (!found || partOfHotspotArea != -1) |
|
1178 { |
|
1179 direction = AknLayoutUtils::LayoutMirrored() ? TBidiText::ERightToLeft : TBidiText::ELeftToRight; |
|
1180 } |
|
1181 // </cmail> |
|
1182 |
|
1183 iLineDirection.AppendL(direction); |
|
1184 } |
|
1185 } |
|
1186 |
|
1187 |
|
1188 for(int i = 0 ; i < textLength ; ++i) |
|
1189 { |
|
1190 iText.Extract(someCharacter, i, 1); |
|
1191 |
|
1192 if(!iSmileyParser->IsPartOfSmileyL(someCharacter)) |
|
1193 { |
|
1194 if(iSmileyParser->IsSmiley()) |
|
1195 { |
|
1196 TInt smileysIndex = iSmileyParser->GetSmileyIndex(); |
|
1197 CTextField* field = |
|
1198 (CTextField*)new(ELeave)CSmileyField(smileysIndex); |
|
1199 |
|
1200 TInt smileysLength = |
|
1201 iSmileyParser->GetSmileyLength(smileysIndex); |
|
1202 iText.InsertFieldL( |
|
1203 i-smileysLength, |
|
1204 field, |
|
1205 KFsRichTextSmileyFieldUid); |
|
1206 |
|
1207 iFieldLocation.Append(i-smileysLength); |
|
1208 } |
|
1209 } |
|
1210 |
|
1211 if(someCharacter[0] == CRichText::EPictureCharacter) |
|
1212 { |
|
1213 CTextField* field = (CTextField*) |
|
1214 new(ELeave)CPictureField(TSize(50,50)); |
|
1215 iText.InsertFieldL(i, field, KFsRichTextPictureFieldUid); |
|
1216 |
|
1217 iFieldLocation.Append(i); |
|
1218 } |
|
1219 } |
|
1220 |
|
1221 return retVal; |
|
1222 } |
|
1223 |
|
1224 TBool CFsTextParser::IsPartOfHotSpot(TInt aIndex) |
|
1225 { |
|
1226 FUNC_LOG; |
|
1227 TBool retVal = EFalse; |
|
1228 |
|
1229 for(TInt i = 0 ; i < iHotSpotArray.Count() ; ++i) |
|
1230 { |
|
1231 if ( aIndex > iHotSpotArray[i].iStartIndex |
|
1232 && aIndex < |
|
1233 iHotSpotArray[i].iStartIndex |
|
1234 + iHotSpotArray[i].iLength |
|
1235 - 1 ) |
|
1236 { |
|
1237 retVal = ETrue; |
|
1238 break; |
|
1239 } |
|
1240 } |
|
1241 |
|
1242 return retVal; |
|
1243 } |
|
1244 |
|
1245 void CFsTextParser::SetSmileyParser(CFsSmileyParser* aSmileyParser) |
|
1246 { |
|
1247 FUNC_LOG; |
|
1248 iSmileyParser = aSmileyParser; |
|
1249 } |
|
1250 |
|
1251 TBool CFsTextParser::SetExpandStatusL(TInt aIdOfExpand, TBool aStatus) |
|
1252 { |
|
1253 FUNC_LOG; |
|
1254 TBool retVal = ETrue; |
|
1255 |
|
1256 if(aIdOfExpand >= iExpandArray.Count()) |
|
1257 { |
|
1258 User::Leave(KErrArgument); |
|
1259 } |
|
1260 |
|
1261 iExpandArray[aIdOfExpand].iIsExpand = aStatus; |
|
1262 |
|
1263 return retVal; |
|
1264 } |
|
1265 |
|
1266 TInt CFsTextParser::GetEndIndexOfExpandAreaL(TInt aId) |
|
1267 { |
|
1268 FUNC_LOG; |
|
1269 if(aId >= iExpandArray.Count()) |
|
1270 { |
|
1271 User::Leave(KErrArgument); |
|
1272 } |
|
1273 |
|
1274 return iExpandArray[aId].iStartIndex + iExpandArray[aId].iLength - 1; |
|
1275 } |
|
1276 |
|
1277 TInt CFsTextParser::GetStartIndexOfExpandAreaL(TInt aId) |
|
1278 { |
|
1279 FUNC_LOG; |
|
1280 if(aId >= iExpandArray.Count()) |
|
1281 { |
|
1282 User::Leave(KErrArgument); |
|
1283 } |
|
1284 |
|
1285 return iExpandArray[aId].iStartIndex; |
|
1286 } |
|
1287 |
|
1288 TInt CFsTextParser::GetBodyIndexOfExpandAreaL(TInt aId) |
|
1289 { |
|
1290 FUNC_LOG; |
|
1291 if(aId >= iExpandArray.Count()) |
|
1292 { |
|
1293 User::Leave(KErrArgument); |
|
1294 } |
|
1295 |
|
1296 return |
|
1297 iExpandArray[aId].iStartIndex |
|
1298 + iExpandArray[aId].iCaptionLength - 1; |
|
1299 } |
|
1300 |
|
1301 TInt CFsTextParser::GetEndIndexOfHotSpotAreaL(TInt aId, TBool aOriginal) |
|
1302 { |
|
1303 FUNC_LOG; |
|
1304 if(aId >= iHotSpotArray.Count()) |
|
1305 { |
|
1306 User::Leave(KErrArgument); |
|
1307 } |
|
1308 |
|
1309 TInt retVal; |
|
1310 |
|
1311 retVal = aOriginal |
|
1312 ? iHotSpotArray[aId].iOriginalStartIndex + iHotSpotArray[aId].iOriginalLength - 1 |
|
1313 : iHotSpotArray[aId].iStartIndex + iHotSpotArray[aId].iLength - 1; |
|
1314 |
|
1315 return retVal; |
|
1316 } |
|
1317 |
|
1318 TInt CFsTextParser::GetStartIndexOfHotSpotAreaL(TInt aId, TBool aOriginal) |
|
1319 { |
|
1320 FUNC_LOG; |
|
1321 if(aId >= iHotSpotArray.Count()) |
|
1322 { |
|
1323 User::Leave(KErrArgument); |
|
1324 } |
|
1325 |
|
1326 TInt retVal = aOriginal |
|
1327 ? iHotSpotArray[aId].iOriginalStartIndex |
|
1328 : iHotSpotArray[aId].iStartIndex; |
|
1329 |
|
1330 return retVal; |
|
1331 } |
|
1332 |
|
1333 CFsRichText* CFsTextParser::GetRichTextL(TInt aBeginIndex, TInt aEndIndex) |
|
1334 { |
|
1335 FUNC_LOG; |
|
1336 CFsRichText* fsRichText = CFsRichText::NewL( |
|
1337 iEikon->SystemParaFormatLayerL(), |
|
1338 iEikon->SystemCharFormatLayerL()); |
|
1339 |
|
1340 TBuf<1> c; |
|
1341 |
|
1342 TCharFormat charFormat; |
|
1343 TCharFormatMask charMask; |
|
1344 |
|
1345 if(aBeginIndex < 0 || aBeginIndex > iText.DocumentLength() || |
|
1346 aEndIndex < 0 || aEndIndex > iText.DocumentLength()) |
|
1347 { |
|
1348 User::Leave(KErrArgument); |
|
1349 } |
|
1350 |
|
1351 for(TInt i = aBeginIndex ; i < aEndIndex ; ++i ) |
|
1352 { |
|
1353 iText.Extract( c, i, 1 ); |
|
1354 |
|
1355 TRAPD(err, fsRichText->InsertL(i,c)); |
|
1356 if(err == KErrNone) |
|
1357 { |
|
1358 iText.GetSpecificCharFormat(charFormat,charMask,i); |
|
1359 fsRichText->SetInsertCharFormatL(charFormat,charMask,i); |
|
1360 } |
|
1361 } |
|
1362 |
|
1363 return fsRichText; |
|
1364 } |
|
1365 |
|
1366 TBidiText::TDirectionality CFsTextParser::GetParagraphDirection(TInt aPosInText) |
|
1367 { |
|
1368 FUNC_LOG; |
|
1369 /*if(aPosInText > iText.DocumentLength()) |
|
1370 { |
|
1371 User::Leave(KErrArgument); |
|
1372 } |
|
1373 |
|
1374 if(iNewLineArray.Count() <= 0 || (iNewLineArray.Count() != iLineDirection.Count())) |
|
1375 { |
|
1376 User::Leave(KErrArgument); |
|
1377 }*/ |
|
1378 |
|
1379 // <cmail> |
|
1380 TBidiText::TDirectionality retVal = AknLayoutUtils::LayoutMirrored() ? TBidiText::ERightToLeft : TBidiText::ELeftToRight; |
|
1381 // </cmail> |
|
1382 |
|
1383 //TBool found = EFalse; |
|
1384 |
|
1385 TInt newLineArrayCount = iNewLineArray.Count(); |
|
1386 TInt lastNewLinePosition = 0; |
|
1387 if( aPosInText > iNewLineArray[iLastNewLinePositionIndex] ) |
|
1388 { |
|
1389 return iLineDirection[iLastNewLinePositionIndex + 1]; |
|
1390 } |
|
1391 for(TInt i = 0 ; i < newLineArrayCount ; ++i) |
|
1392 { |
|
1393 if(lastNewLinePosition <= aPosInText && iNewLineArray[i] >= aPosInText) |
|
1394 { |
|
1395 retVal = iLineDirection[i]; |
|
1396 iLastNewLinePositionIndex = i; |
|
1397 break; |
|
1398 } |
|
1399 |
|
1400 lastNewLinePosition = iNewLineArray[i]; |
|
1401 } |
|
1402 |
|
1403 /*if(!found) |
|
1404 { |
|
1405 User::Leave(KErrArgument); |
|
1406 }*/ |
|
1407 |
|
1408 return retVal; |
|
1409 } |
|
1410 |
|
1411 TBool CFsTextParser::SetTextDirection(TInt aStartPosInText, TInt aEndPosInText, |
|
1412 TBidiText::TDirectionality aDirection) |
|
1413 { |
|
1414 FUNC_LOG; |
|
1415 TInt indexOfStart = 0; |
|
1416 TInt indexOfEnd = 0; |
|
1417 |
|
1418 TInt tableCount = iNewLineArray.Count(); |
|
1419 |
|
1420 for(TInt i = 0 ; i < tableCount ; ++i) |
|
1421 { |
|
1422 TInt ala = iNewLineArray[i]; |
|
1423 |
|
1424 if(iNewLineArray[i] >= aStartPosInText) |
|
1425 { |
|
1426 indexOfStart = i; |
|
1427 i = tableCount + 1; |
|
1428 } |
|
1429 } |
|
1430 |
|
1431 for(TInt i = indexOfStart ; i < tableCount ; ++i) |
|
1432 { |
|
1433 TInt ala = iNewLineArray[i]; |
|
1434 |
|
1435 if(iNewLineArray[i] >= aEndPosInText) |
|
1436 { |
|
1437 indexOfEnd = i; |
|
1438 i = tableCount + 1; |
|
1439 } |
|
1440 } |
|
1441 |
|
1442 if(indexOfEnd == indexOfStart) |
|
1443 { |
|
1444 iNewLineArray.Insert(aStartPosInText, indexOfStart); |
|
1445 iNewLineArray.Insert(aEndPosInText, indexOfStart + 1); |
|
1446 |
|
1447 TBidiText::TDirectionality direction = iLineDirection[indexOfEnd]; |
|
1448 |
|
1449 iLineDirection.Insert(direction, indexOfStart); |
|
1450 iLineDirection.Insert(aDirection, indexOfStart + 1); |
|
1451 } |
|
1452 else |
|
1453 { |
|
1454 iNewLineArray.Insert(aEndPosInText, indexOfEnd); |
|
1455 iNewLineArray.Insert(aStartPosInText, indexOfStart); |
|
1456 |
|
1457 for(TInt i = indexOfEnd ; i > indexOfStart ; --i) |
|
1458 { |
|
1459 iNewLineArray.Remove(i); |
|
1460 } |
|
1461 |
|
1462 TBidiText::TDirectionality direction = iLineDirection[indexOfStart]; |
|
1463 |
|
1464 iLineDirection.Insert(aDirection, indexOfEnd); |
|
1465 iLineDirection.Insert(direction, indexOfStart); |
|
1466 |
|
1467 for(TInt i = indexOfEnd ; i > indexOfStart ; --i) |
|
1468 { |
|
1469 iLineDirection.Remove(i); |
|
1470 } |
|
1471 } |
|
1472 if(0 == aStartPosInText) |
|
1473 { |
|
1474 iLineDirection[indexOfStart] = aDirection; |
|
1475 } |
|
1476 return ETrue; |
|
1477 } |
|
1478 |
|
1479 TBool CFsTextParser::IsTexturePosition(TInt aPos, TInt &aId) |
|
1480 { |
|
1481 TBool retVal = EFalse; |
|
1482 |
|
1483 TInt tableCount = iTextureIndex.Count(); |
|
1484 |
|
1485 for(TInt i = 0 ; i < tableCount ; ++i) |
|
1486 { |
|
1487 TInt texturePosition = iTextureIndex[i].iPositionInText; |
|
1488 |
|
1489 if(aPos == texturePosition) |
|
1490 { |
|
1491 retVal = ETrue; |
|
1492 aId = iTextureIndex[i].iTextureId; |
|
1493 i = tableCount + 1; |
|
1494 } |
|
1495 } |
|
1496 |
|
1497 return retVal; |
|
1498 } |