64
|
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 <icl/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 |
CleanupStack::PushL(textObject);
|
|
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 |
CleanupStack::Pop(textObject);
|
|
733 |
}
|
|
734 |
else
|
|
735 |
{
|
|
736 |
//pobrac fielda
|
|
737 |
const CTextField* field = iText.TextField(iPosition);
|
|
738 |
|
|
739 |
if(KFsRichTextPictureFieldUid == field->Type())
|
|
740 |
{
|
|
741 |
TPictureHeader header = iText.PictureHeader(iPosition);
|
|
742 |
|
|
743 |
CMyPicture* picture =
|
|
744 |
static_cast<CMyPicture*>(header.iPicture.AsPtr() );
|
|
745 |
|
|
746 |
textObject = CFsRichTextPicture::NewL();
|
|
747 |
|
|
748 |
TSize sizeOfPicture = TSize( 0, 0 );
|
|
749 |
picture->GetOriginalSizeInTwips( sizeOfPicture );
|
|
750 |
|
|
751 |
static_cast< CFsRichTextPicture* >
|
|
752 |
(textObject)->SetTextureSize(sizeOfPicture);
|
|
753 |
|
|
754 |
textObject->SetBeginOfObject(iPosition);
|
|
755 |
textObject->SetEndOfObject(iPosition);
|
|
756 |
|
|
757 |
iLastPosition = iPosition;
|
|
758 |
iPosition += 1;
|
|
759 |
}
|
|
760 |
else if(KFsRichTextSmileyFieldUid == field->Type())
|
|
761 |
{
|
|
762 |
TInt smileyIndex = ((CSmileyField*)(field))->GetSmileyIndex();
|
|
763 |
|
|
764 |
iGNOSomeText.Set(iText.Read(
|
|
765 |
iPosition,
|
|
766 |
iSmileyParser->GetSmileyLength(smileyIndex)));
|
|
767 |
|
|
768 |
CFsRichTextText* smileyTextObject =
|
|
769 |
CFsRichTextText::NewL(iGNOSomeText, 0);
|
|
770 |
CleanupStack::PushL(smileyTextObject);
|
|
771 |
smileyTextObject->SetTextColor(
|
|
772 |
iGNOCharFormat.iFontPresentation.iTextColor );
|
|
773 |
|
|
774 |
TInt styleId = iTextStyleManager->GetStyleIDL(iGNOCharFormat);
|
|
775 |
((CFsRichTextText*)smileyTextObject)->SetStyleId(styleId);
|
|
776 |
|
|
777 |
TFileName fileName =
|
|
778 |
iSmileyParser->GetSmileyFileName(smileyIndex);
|
|
779 |
|
|
780 |
TInt textureId = 0;
|
|
781 |
TSize texturesize = TSize( 0, 0 );
|
|
782 |
if(IsTexturePosition(iPosition, textureId))
|
|
783 |
{
|
|
784 |
CFsTexture* texture = iTextureLoader->SearchById(textureId);
|
|
785 |
texturesize = texture->Texture().Size();
|
|
786 |
}
|
|
787 |
else
|
|
788 |
{
|
|
789 |
CFsTexture& texture = iTextureLoader->LoadTextureL( fileName );
|
|
790 |
|
|
791 |
TTextureIndex newTextureIndex;
|
|
792 |
newTextureIndex.iPositionInText = iPosition;
|
|
793 |
newTextureIndex.iTextureId = texture.Id();
|
|
794 |
|
|
795 |
iTextureIndex.Append(newTextureIndex);
|
|
796 |
|
|
797 |
texturesize = texture.Texture().Size();
|
|
798 |
}
|
|
799 |
|
|
800 |
CFsRichTextPicture* smileyPictureObject =
|
|
801 |
CFsRichTextPicture::NewL();
|
|
802 |
CleanupStack::PushL(smileyPictureObject);
|
|
803 |
if(iIsSetSizeOfSmiley)
|
|
804 |
{
|
|
805 |
texturesize = iSizeOfSmiley;
|
|
806 |
}
|
|
807 |
else if ( texturesize == TSize( 0, 0 ) )
|
|
808 |
{
|
|
809 |
TFrameInfo frameInfo;
|
|
810 |
|
|
811 |
CFsTextureLoader::GetFrameInfoL(
|
|
812 |
fileName,
|
|
813 |
frameInfo );
|
|
814 |
texturesize = frameInfo.iOverallSizeInPixels;
|
|
815 |
TSize texturesize = TSize( 10, 10 );
|
|
816 |
}
|
|
817 |
|
|
818 |
static_cast< CFsRichTextPicture* >
|
|
819 |
(smileyPictureObject)->SetTextureSize( texturesize );
|
|
820 |
|
|
821 |
textObject = CFsRichTextSmiley::NewL(
|
|
822 |
smileyTextObject,
|
|
823 |
smileyPictureObject);
|
|
824 |
|
|
825 |
CleanupStack::Pop(smileyPictureObject);
|
|
826 |
CleanupStack::Pop(smileyTextObject);
|
|
827 |
textObject->SetBeginOfObject(iPosition);
|
|
828 |
textObject->SetEndOfObject(iPosition + iGNOSomeText.Length() - 1);
|
|
829 |
|
|
830 |
iLastPosition = iPosition;
|
|
831 |
iPosition += iGNOSomeText.Length();
|
|
832 |
}
|
|
833 |
}
|
|
834 |
}
|
|
835 |
else
|
|
836 |
{
|
|
837 |
if(isNewLinePresent)
|
|
838 |
{
|
|
839 |
textObject = CFsRichTextNewLine::NewL();
|
|
840 |
|
|
841 |
textObject->SetBeginOfObject(iPosition);
|
|
842 |
textObject->SetEndOfObject(iPosition);
|
|
843 |
|
|
844 |
iLastPosition = iPosition;
|
|
845 |
iPosition += 1;
|
|
846 |
}
|
|
847 |
else
|
|
848 |
{
|
|
849 |
textObject = static_cast<MFsRichTextObject*>
|
|
850 |
(CFsRichTextText::NewL(iGNOSomeText, 0));
|
|
851 |
CleanupStack::PushL(textObject);
|
|
852 |
TInt styleId = iTextStyleManager->GetStyleIDL(iGNOCharFormat);
|
|
853 |
((CFsRichTextText*)textObject)->SetStyleId(styleId);
|
|
854 |
|
|
855 |
textObject->SetBeginOfObject(iPosition);
|
|
856 |
textObject->SetEndOfObject(iPosition + iGNOSomeText.Length() - 1);
|
|
857 |
|
|
858 |
((CFsRichTextText*)textObject)->SetTextColor(
|
|
859 |
iGNOCharFormat.iFontPresentation.iTextColor );
|
|
860 |
|
|
861 |
TBidiText * bidiText = TBidiText::NewL(iGNOSomeText.Length() + 1, 1);
|
|
862 |
|
|
863 |
TBool found = EFalse;
|
|
864 |
|
|
865 |
TBidiText::TDirectionality direction = bidiText->TextDirectionality(iGNOSomeText, &found );
|
|
866 |
|
|
867 |
// <cmail>
|
|
868 |
if ( !found )
|
|
869 |
{
|
|
870 |
direction = AknLayoutUtils::LayoutMirrored() ?
|
|
871 |
TBidiText::ERightToLeft : TBidiText::ELeftToRight;
|
|
872 |
}
|
|
873 |
// </cmail>
|
|
874 |
|
|
875 |
static_cast<CFsRichTextText*>(textObject)->SetTextDirection(direction);
|
|
876 |
|
|
877 |
delete bidiText;
|
|
878 |
|
|
879 |
TInt sizeOfSomeText = iGNOSomeText.Length();
|
|
880 |
TBool isWhiteSpace = ETrue;
|
|
881 |
for(TInt k = 0 ; k < sizeOfSomeText ; ++k)
|
|
882 |
{
|
|
883 |
if(iGNOSomeText[k] != ' ')
|
|
884 |
{
|
|
885 |
isWhiteSpace = EFalse;
|
|
886 |
k = sizeOfSomeText + 1;
|
|
887 |
}
|
|
888 |
}
|
|
889 |
|
|
890 |
textObject->SetIsWhiteSpace(isWhiteSpace);
|
|
891 |
|
|
892 |
iLastPosition = iPosition;
|
|
893 |
iPosition += iGNOSomeText.Length();
|
|
894 |
|
|
895 |
CleanupStack::Pop(textObject);
|
|
896 |
}
|
|
897 |
}
|
|
898 |
|
|
899 |
if(-1 != isWordPartOfHotSpotArea)
|
|
900 |
{
|
|
901 |
textObject->SetHotSpot( ETrue );
|
|
902 |
textObject->SetIdOfHotSpot(isWordPartOfHotSpotArea);
|
|
903 |
textObject->SetTypeOfHotSpot(
|
|
904 |
iHotSpotArray[isWordPartOfHotSpotArea].iId );
|
|
905 |
}
|
|
906 |
|
|
907 |
if(-1 != isWordPartOfExpandArea)
|
|
908 |
{
|
|
909 |
textObject->SetEmbeded( ETrue );
|
|
910 |
textObject->SetIdOfEmbeded(isWordPartOfExpandArea);
|
|
911 |
}
|
|
912 |
|
|
913 |
return textObject;
|
|
914 |
}
|
|
915 |
|
|
916 |
void CFsTextParser::SetTextStylemanager(
|
|
917 |
CFsTextStyleManager* aTextStyleManager )
|
|
918 |
{
|
|
919 |
FUNC_LOG;
|
|
920 |
iTextStyleManager = aTextStyleManager;
|
|
921 |
}
|
|
922 |
|
|
923 |
void CFsTextParser::ConvertBitmapL(CPicture* aPicture, CFbsBitmap*& aBitmap)
|
|
924 |
{
|
|
925 |
FUNC_LOG;
|
|
926 |
TSize size;
|
|
927 |
aPicture->GetOriginalSizeInTwips(size);
|
|
928 |
aBitmap = new (ELeave)CFbsBitmap;
|
|
929 |
|
|
930 |
size.iWidth = 45;
|
|
931 |
size.iWidth = 45;
|
|
932 |
|
|
933 |
User::LeaveIfError(aBitmap->Create(size,EColor256));
|
|
934 |
CleanupStack::PushL(aBitmap);
|
|
935 |
|
|
936 |
//create an offscreen device and context
|
|
937 |
CGraphicsContext* bitmapContext = NULL;
|
|
938 |
CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(aBitmap);
|
|
939 |
CleanupStack::PushL(bitmapDevice);
|
|
940 |
User::LeaveIfError(bitmapDevice->CreateContext(bitmapContext));
|
|
941 |
CleanupStack::PushL(bitmapContext);
|
|
942 |
|
|
943 |
aPicture->Draw(
|
|
944 |
*bitmapContext,
|
|
945 |
TPoint(0,0),
|
|
946 |
TRect( TPoint(0,0),TPoint(45,45) ),
|
|
947 |
bitmapDevice);
|
|
948 |
|
|
949 |
CleanupStack::PopAndDestroy(bitmapContext);
|
|
950 |
CleanupStack::PopAndDestroy(bitmapDevice);
|
|
951 |
CleanupStack::Pop(aBitmap);
|
|
952 |
}
|
|
953 |
|
|
954 |
|
|
955 |
|
|
956 |
TInt CFsTextParser::IsWordPartOfHotSpotArea(
|
|
957 |
TInt aStartPosition,
|
|
958 |
TInt aEndPosition )
|
|
959 |
{
|
|
960 |
FUNC_LOG;
|
|
961 |
TInt retVal = -1;
|
|
962 |
|
|
963 |
for(TInt i = 0 ; i < iHotSpotArray.Count() ; ++i)
|
|
964 |
{
|
|
965 |
/*
|
|
966 |
TRichTextHotSpotArea test;
|
|
967 |
test.iLength = iHotSpotArray[i].iLength;
|
|
968 |
test.iStartIndex = iHotSpotArray[i].iStartIndex;
|
|
969 |
*/
|
|
970 |
|
|
971 |
if(iHotSpotArray[i].iStartIndex >= aStartPosition &&
|
|
972 |
iHotSpotArray[i].iStartIndex < aEndPosition)
|
|
973 |
{
|
|
974 |
if(-1 == retVal)
|
|
975 |
{
|
|
976 |
retVal = i;
|
|
977 |
}
|
|
978 |
else
|
|
979 |
{
|
|
980 |
if ( iHotSpotArray[i].iStartIndex
|
|
981 |
< iHotSpotArray[retVal].iStartIndex )
|
|
982 |
{
|
|
983 |
retVal = i;
|
|
984 |
}
|
|
985 |
}
|
|
986 |
}
|
|
987 |
else if ( aStartPosition >= iHotSpotArray[i].iStartIndex
|
|
988 |
&& aStartPosition
|
|
989 |
< iHotSpotArray[i].iStartIndex
|
|
990 |
+ iHotSpotArray[i].iLength )
|
|
991 |
{
|
|
992 |
if(-1 == retVal)
|
|
993 |
{
|
|
994 |
retVal = i;
|
|
995 |
}
|
|
996 |
else
|
|
997 |
{
|
|
998 |
if ( iHotSpotArray[i].iStartIndex
|
|
999 |
< iHotSpotArray[retVal].iStartIndex )
|
|
1000 |
{
|
|
1001 |
retVal = i;
|
|
1002 |
}
|
|
1003 |
}
|
|
1004 |
}
|
|
1005 |
}
|
|
1006 |
return retVal;
|
|
1007 |
}
|
|
1008 |
|
|
1009 |
|
|
1010 |
|
|
1011 |
|
|
1012 |
TBool CFsTextParser::IsNextObject() const
|
|
1013 |
{
|
|
1014 |
FUNC_LOG;
|
|
1015 |
|
|
1016 |
TInt documentLength = iText.DocumentLength() - 1;
|
|
1017 |
TBool retVal = EFalse;
|
|
1018 |
|
|
1019 |
if(documentLength < iPosition)
|
|
1020 |
{
|
|
1021 |
retVal = EFalse;
|
|
1022 |
}
|
|
1023 |
else
|
|
1024 |
{
|
|
1025 |
retVal = ETrue;
|
|
1026 |
}
|
|
1027 |
|
|
1028 |
return retVal;
|
|
1029 |
}
|
|
1030 |
|
|
1031 |
TBool CFsTextParser::MoveParsingPosition( TInt aMoveParsingPositionBy )
|
|
1032 |
{
|
|
1033 |
FUNC_LOG;
|
|
1034 |
TBool retVal = ETrue;
|
|
1035 |
|
|
1036 |
if( (iPosition + aMoveParsingPositionBy) < 0 ||
|
|
1037 |
(iPosition + aMoveParsingPositionBy) >= iText.DocumentLength())
|
|
1038 |
{
|
|
1039 |
retVal = EFalse;
|
|
1040 |
}
|
|
1041 |
else
|
|
1042 |
{
|
|
1043 |
iPosition += aMoveParsingPositionBy;
|
|
1044 |
}
|
|
1045 |
|
|
1046 |
return retVal;
|
|
1047 |
}
|
|
1048 |
|
|
1049 |
|
|
1050 |
|
|
1051 |
TBool CFsTextParser::ParseTextL()
|
|
1052 |
{
|
|
1053 |
FUNC_LOG;
|
|
1054 |
TBool retVal = ETrue;
|
|
1055 |
|
|
1056 |
TInt textLength = iText.DocumentLength();
|
|
1057 |
|
|
1058 |
TBuf<1> someCharacter;
|
|
1059 |
|
|
1060 |
_LIT(fourSpaces, " ");
|
|
1061 |
_LIT(validNewLine, "\n");
|
|
1062 |
|
|
1063 |
|
|
1064 |
_LIT(newLine1, "\x2028");
|
|
1065 |
_LIT(newLine2, "\x2029");
|
|
1066 |
_LIT(newLine3, "\x85");
|
|
1067 |
_LIT(newLine4, "\x0D");
|
|
1068 |
|
|
1069 |
_LIT(tabulator,"\x2007");
|
|
1070 |
|
|
1071 |
for(TInt i = 0 ; i < iText.GetNumberOfExpandAreas() ; ++i)
|
|
1072 |
{
|
|
1073 |
iExpandArray.AppendL(iText.GetExpandAreaL(i));
|
|
1074 |
}
|
|
1075 |
|
|
1076 |
for(TInt i = 0 ; i < iText.GetNumberOfHotSpotAreas() ; ++i)
|
|
1077 |
{
|
|
1078 |
iHotSpotArray.AppendL(iText.GetHotSpotAreaL(i));
|
|
1079 |
}
|
|
1080 |
|
|
1081 |
textLength = iText.DocumentLength();
|
|
1082 |
for(TInt i = 0 ; i < textLength ; ++i)
|
|
1083 |
{
|
|
1084 |
iText.Extract(someCharacter, i, 1);
|
|
1085 |
|
|
1086 |
if(someCharacter[0] == '\t')
|
|
1087 |
{
|
|
1088 |
iText.DeleteL(i,1);
|
|
1089 |
iText.InsertL(i,fourSpaces);
|
|
1090 |
|
|
1091 |
textLength = iText.DocumentLength();
|
|
1092 |
|
|
1093 |
for(TInt j = 0 ; j < iText.GetNumberOfExpandAreas() ; ++j)
|
|
1094 |
{
|
|
1095 |
if(iExpandArray[j].iStartIndex > i)
|
|
1096 |
{
|
|
1097 |
iExpandArray[j].iStartIndex += 3;
|
|
1098 |
}
|
|
1099 |
}
|
|
1100 |
|
|
1101 |
for(TInt j = 0 ; j < iText.GetNumberOfHotSpotAreas() ; ++j)
|
|
1102 |
{
|
|
1103 |
if(iHotSpotArray[j].iStartIndex <= i &&
|
|
1104 |
iHotSpotArray[j].iStartIndex + iHotSpotArray[j].iLength > i)
|
|
1105 |
{
|
|
1106 |
iHotSpotArray[j].iLength += 3;
|
|
1107 |
}
|
|
1108 |
if(iHotSpotArray[j].iStartIndex > i)
|
|
1109 |
{
|
|
1110 |
iHotSpotArray[j].iStartIndex += 3;
|
|
1111 |
}
|
|
1112 |
}
|
|
1113 |
|
|
1114 |
++i;
|
|
1115 |
}
|
|
1116 |
else if(someCharacter.Right(1).Compare(tabulator) == 0)
|
|
1117 |
{
|
|
1118 |
iText.DeleteL(i,1);
|
|
1119 |
iText.InsertL(i,fourSpaces);
|
|
1120 |
|
|
1121 |
textLength = iText.DocumentLength();
|
|
1122 |
++i;
|
|
1123 |
}
|
|
1124 |
else if(someCharacter.Right(1).Compare(validNewLine) == 0)
|
|
1125 |
{
|
|
1126 |
TBuf<1> anotherCharacter;
|
|
1127 |
if ( iText.DocumentLength() > ( i + 1 ) )
|
|
1128 |
{
|
|
1129 |
iText.Extract(anotherCharacter, i + 1, 1);
|
|
1130 |
|
|
1131 |
if( anotherCharacter.Right(1).Compare(newLine3) == 0 ||
|
|
1132 |
anotherCharacter.Right(1).Compare(newLine4) == 0 )
|
|
1133 |
{
|
|
1134 |
iText.DeleteL( i, 2 );
|
|
1135 |
iText.InsertL( i, validNewLine );
|
|
1136 |
iText.InsertL( i, _L(" ") );
|
|
1137 |
|
|
1138 |
textLength = iText.DocumentLength();
|
|
1139 |
}
|
|
1140 |
}
|
|
1141 |
}
|
|
1142 |
}
|
|
1143 |
|
|
1144 |
textLength = iText.DocumentLength();
|
|
1145 |
TInt lastNewLine = 0;
|
|
1146 |
TPtrC someText;
|
|
1147 |
|
|
1148 |
for(TInt i = 0 ; i < textLength ; ++i)
|
|
1149 |
{
|
|
1150 |
iText.Extract(someCharacter, i, 1);
|
|
1151 |
|
|
1152 |
if(someCharacter.Right(1).Compare(validNewLine) == 0 ||
|
|
1153 |
someCharacter.Right(1).Compare(newLine1) == 0 ||
|
|
1154 |
someCharacter.Right(1).Compare(newLine2) == 0 ||
|
|
1155 |
someCharacter.Right(1).Compare(newLine3) == 0 ||
|
|
1156 |
someCharacter.Right(1).Compare(newLine4) == 0
|
|
1157 |
|| i == textLength - 1
|
|
1158 |
)
|
|
1159 |
{
|
|
1160 |
iNewLineArray.AppendL(i);
|
|
1161 |
|
|
1162 |
someText.Set(iText.Read(
|
|
1163 |
lastNewLine,
|
|
1164 |
i - lastNewLine));
|
|
1165 |
|
|
1166 |
// <cmail>
|
|
1167 |
TInt partOfHotspotArea = IsWordPartOfHotSpotArea(
|
|
1168 |
lastNewLine,
|
|
1169 |
i);
|
|
1170 |
// </cmail>
|
|
1171 |
|
|
1172 |
lastNewLine = i;
|
|
1173 |
|
|
1174 |
TBidiText * bidiText = TBidiText::NewL(someText.Length() + 1, 1);
|
|
1175 |
|
|
1176 |
TBool found = EFalse;
|
|
1177 |
|
|
1178 |
TBidiText::TDirectionality direction = bidiText->TextDirectionality(someText, &found );
|
|
1179 |
|
|
1180 |
delete bidiText;
|
|
1181 |
|
|
1182 |
// <cmail>
|
|
1183 |
if (!found || partOfHotspotArea != -1)
|
|
1184 |
{
|
|
1185 |
direction = AknLayoutUtils::LayoutMirrored() ? TBidiText::ERightToLeft : TBidiText::ELeftToRight;
|
|
1186 |
}
|
|
1187 |
// </cmail>
|
|
1188 |
|
|
1189 |
iLineDirection.AppendL(direction);
|
|
1190 |
}
|
|
1191 |
}
|
|
1192 |
|
|
1193 |
|
|
1194 |
for(int i = 0 ; i < textLength ; ++i)
|
|
1195 |
{
|
|
1196 |
iText.Extract(someCharacter, i, 1);
|
|
1197 |
|
|
1198 |
if(!iSmileyParser->IsPartOfSmileyL(someCharacter))
|
|
1199 |
{
|
|
1200 |
if(iSmileyParser->IsSmiley())
|
|
1201 |
{
|
|
1202 |
TInt smileysIndex = iSmileyParser->GetSmileyIndex();
|
|
1203 |
CTextField* field =
|
|
1204 |
(CTextField*)new(ELeave)CSmileyField(smileysIndex);
|
|
1205 |
|
|
1206 |
TInt smileysLength =
|
|
1207 |
iSmileyParser->GetSmileyLength(smileysIndex);
|
|
1208 |
iText.InsertFieldL(
|
|
1209 |
i-smileysLength,
|
|
1210 |
field,
|
|
1211 |
KFsRichTextSmileyFieldUid);
|
|
1212 |
|
|
1213 |
iFieldLocation.Append(i-smileysLength);
|
|
1214 |
}
|
|
1215 |
}
|
|
1216 |
|
|
1217 |
if(someCharacter[0] == CRichText::EPictureCharacter)
|
|
1218 |
{
|
|
1219 |
CTextField* field = (CTextField*)
|
|
1220 |
new(ELeave)CPictureField(TSize(50,50));
|
|
1221 |
iText.InsertFieldL(i, field, KFsRichTextPictureFieldUid);
|
|
1222 |
|
|
1223 |
iFieldLocation.Append(i);
|
|
1224 |
}
|
|
1225 |
}
|
|
1226 |
|
|
1227 |
return retVal;
|
|
1228 |
}
|
|
1229 |
|
|
1230 |
TBool CFsTextParser::IsPartOfHotSpot(TInt aIndex)
|
|
1231 |
{
|
|
1232 |
FUNC_LOG;
|
|
1233 |
TBool retVal = EFalse;
|
|
1234 |
|
|
1235 |
for(TInt i = 0 ; i < iHotSpotArray.Count() ; ++i)
|
|
1236 |
{
|
|
1237 |
if ( aIndex > iHotSpotArray[i].iStartIndex
|
|
1238 |
&& aIndex <
|
|
1239 |
iHotSpotArray[i].iStartIndex
|
|
1240 |
+ iHotSpotArray[i].iLength
|
|
1241 |
- 1 )
|
|
1242 |
{
|
|
1243 |
retVal = ETrue;
|
|
1244 |
break;
|
|
1245 |
}
|
|
1246 |
}
|
|
1247 |
|
|
1248 |
return retVal;
|
|
1249 |
}
|
|
1250 |
|
|
1251 |
void CFsTextParser::SetSmileyParser(CFsSmileyParser* aSmileyParser)
|
|
1252 |
{
|
|
1253 |
FUNC_LOG;
|
|
1254 |
iSmileyParser = aSmileyParser;
|
|
1255 |
}
|
|
1256 |
|
|
1257 |
TBool CFsTextParser::SetExpandStatusL(TInt aIdOfExpand, TBool aStatus)
|
|
1258 |
{
|
|
1259 |
FUNC_LOG;
|
|
1260 |
TBool retVal = ETrue;
|
|
1261 |
|
|
1262 |
if(aIdOfExpand >= iExpandArray.Count())
|
|
1263 |
{
|
|
1264 |
User::Leave(KErrArgument);
|
|
1265 |
}
|
|
1266 |
|
|
1267 |
iExpandArray[aIdOfExpand].iIsExpand = aStatus;
|
|
1268 |
|
|
1269 |
return retVal;
|
|
1270 |
}
|
|
1271 |
|
|
1272 |
TInt CFsTextParser::GetEndIndexOfExpandAreaL(TInt aId)
|
|
1273 |
{
|
|
1274 |
FUNC_LOG;
|
|
1275 |
if(aId >= iExpandArray.Count())
|
|
1276 |
{
|
|
1277 |
User::Leave(KErrArgument);
|
|
1278 |
}
|
|
1279 |
|
|
1280 |
return iExpandArray[aId].iStartIndex + iExpandArray[aId].iLength - 1;
|
|
1281 |
}
|
|
1282 |
|
|
1283 |
TInt CFsTextParser::GetStartIndexOfExpandAreaL(TInt aId)
|
|
1284 |
{
|
|
1285 |
FUNC_LOG;
|
|
1286 |
if(aId >= iExpandArray.Count())
|
|
1287 |
{
|
|
1288 |
User::Leave(KErrArgument);
|
|
1289 |
}
|
|
1290 |
|
|
1291 |
return iExpandArray[aId].iStartIndex;
|
|
1292 |
}
|
|
1293 |
|
|
1294 |
TInt CFsTextParser::GetBodyIndexOfExpandAreaL(TInt aId)
|
|
1295 |
{
|
|
1296 |
FUNC_LOG;
|
|
1297 |
if(aId >= iExpandArray.Count())
|
|
1298 |
{
|
|
1299 |
User::Leave(KErrArgument);
|
|
1300 |
}
|
|
1301 |
|
|
1302 |
return
|
|
1303 |
iExpandArray[aId].iStartIndex
|
|
1304 |
+ iExpandArray[aId].iCaptionLength - 1;
|
|
1305 |
}
|
|
1306 |
|
|
1307 |
TInt CFsTextParser::GetEndIndexOfHotSpotAreaL(TInt aId, TBool aOriginal)
|
|
1308 |
{
|
|
1309 |
FUNC_LOG;
|
|
1310 |
if(aId >= iHotSpotArray.Count())
|
|
1311 |
{
|
|
1312 |
User::Leave(KErrArgument);
|
|
1313 |
}
|
|
1314 |
|
|
1315 |
TInt retVal;
|
|
1316 |
|
|
1317 |
retVal = aOriginal
|
|
1318 |
? iHotSpotArray[aId].iOriginalStartIndex + iHotSpotArray[aId].iOriginalLength - 1
|
|
1319 |
: iHotSpotArray[aId].iStartIndex + iHotSpotArray[aId].iLength - 1;
|
|
1320 |
|
|
1321 |
return retVal;
|
|
1322 |
}
|
|
1323 |
|
|
1324 |
TInt CFsTextParser::GetStartIndexOfHotSpotAreaL(TInt aId, TBool aOriginal)
|
|
1325 |
{
|
|
1326 |
FUNC_LOG;
|
|
1327 |
if(aId >= iHotSpotArray.Count())
|
|
1328 |
{
|
|
1329 |
User::Leave(KErrArgument);
|
|
1330 |
}
|
|
1331 |
|
|
1332 |
TInt retVal = aOriginal
|
|
1333 |
? iHotSpotArray[aId].iOriginalStartIndex
|
|
1334 |
: iHotSpotArray[aId].iStartIndex;
|
|
1335 |
|
|
1336 |
return retVal;
|
|
1337 |
}
|
|
1338 |
|
|
1339 |
CFsRichText* CFsTextParser::GetRichTextL(TInt aBeginIndex, TInt aEndIndex)
|
|
1340 |
{
|
|
1341 |
FUNC_LOG;
|
|
1342 |
CFsRichText* fsRichText = CFsRichText::NewL(
|
|
1343 |
iEikon->SystemParaFormatLayerL(),
|
|
1344 |
iEikon->SystemCharFormatLayerL());
|
|
1345 |
|
|
1346 |
TBuf<1> c;
|
|
1347 |
|
|
1348 |
TCharFormat charFormat;
|
|
1349 |
TCharFormatMask charMask;
|
|
1350 |
|
|
1351 |
if(aBeginIndex < 0 || aBeginIndex > iText.DocumentLength() ||
|
|
1352 |
aEndIndex < 0 || aEndIndex > iText.DocumentLength())
|
|
1353 |
{
|
|
1354 |
User::Leave(KErrArgument);
|
|
1355 |
}
|
|
1356 |
|
|
1357 |
for(TInt i = aBeginIndex ; i < aEndIndex ; ++i )
|
|
1358 |
{
|
|
1359 |
iText.Extract( c, i, 1 );
|
|
1360 |
|
|
1361 |
TRAPD(err, fsRichText->InsertL(i,c));
|
|
1362 |
if(err == KErrNone)
|
|
1363 |
{
|
|
1364 |
iText.GetSpecificCharFormat(charFormat,charMask,i);
|
|
1365 |
fsRichText->SetInsertCharFormatL(charFormat,charMask,i);
|
|
1366 |
}
|
|
1367 |
}
|
|
1368 |
|
|
1369 |
return fsRichText;
|
|
1370 |
}
|
|
1371 |
|
|
1372 |
TBidiText::TDirectionality CFsTextParser::GetParagraphDirection(TInt aPosInText)
|
|
1373 |
{
|
|
1374 |
FUNC_LOG;
|
|
1375 |
/*if(aPosInText > iText.DocumentLength())
|
|
1376 |
{
|
|
1377 |
User::Leave(KErrArgument);
|
|
1378 |
}
|
|
1379 |
|
|
1380 |
if(iNewLineArray.Count() <= 0 || (iNewLineArray.Count() != iLineDirection.Count()))
|
|
1381 |
{
|
|
1382 |
User::Leave(KErrArgument);
|
|
1383 |
}*/
|
|
1384 |
|
|
1385 |
// <cmail>
|
|
1386 |
TBidiText::TDirectionality retVal = AknLayoutUtils::LayoutMirrored() ? TBidiText::ERightToLeft : TBidiText::ELeftToRight;
|
|
1387 |
// </cmail>
|
|
1388 |
|
|
1389 |
//TBool found = EFalse;
|
|
1390 |
|
|
1391 |
TInt newLineArrayCount = iNewLineArray.Count();
|
|
1392 |
TInt lastNewLinePosition = 0;
|
|
1393 |
if( aPosInText > iNewLineArray[iLastNewLinePositionIndex] )
|
|
1394 |
{
|
|
1395 |
return iLineDirection[iLastNewLinePositionIndex + 1];
|
|
1396 |
}
|
|
1397 |
for(TInt i = 0 ; i < newLineArrayCount ; ++i)
|
|
1398 |
{
|
|
1399 |
if(lastNewLinePosition <= aPosInText && iNewLineArray[i] >= aPosInText)
|
|
1400 |
{
|
|
1401 |
retVal = iLineDirection[i];
|
|
1402 |
iLastNewLinePositionIndex = i;
|
|
1403 |
break;
|
|
1404 |
}
|
|
1405 |
|
|
1406 |
lastNewLinePosition = iNewLineArray[i];
|
|
1407 |
}
|
|
1408 |
|
|
1409 |
/*if(!found)
|
|
1410 |
{
|
|
1411 |
User::Leave(KErrArgument);
|
|
1412 |
}*/
|
|
1413 |
|
|
1414 |
return retVal;
|
|
1415 |
}
|
|
1416 |
|
|
1417 |
TBool CFsTextParser::SetTextDirection(TInt aStartPosInText, TInt aEndPosInText,
|
|
1418 |
TBidiText::TDirectionality aDirection)
|
|
1419 |
{
|
|
1420 |
FUNC_LOG;
|
|
1421 |
TInt indexOfStart = 0;
|
|
1422 |
TInt indexOfEnd = 0;
|
|
1423 |
|
|
1424 |
TInt tableCount = iNewLineArray.Count();
|
|
1425 |
|
|
1426 |
for(TInt i = 0 ; i < tableCount ; ++i)
|
|
1427 |
{
|
|
1428 |
TInt ala = iNewLineArray[i];
|
|
1429 |
|
|
1430 |
if(iNewLineArray[i] >= aStartPosInText)
|
|
1431 |
{
|
|
1432 |
indexOfStart = i;
|
|
1433 |
i = tableCount + 1;
|
|
1434 |
}
|
|
1435 |
}
|
|
1436 |
|
|
1437 |
for(TInt i = indexOfStart ; i < tableCount ; ++i)
|
|
1438 |
{
|
|
1439 |
TInt ala = iNewLineArray[i];
|
|
1440 |
|
|
1441 |
if(iNewLineArray[i] >= aEndPosInText)
|
|
1442 |
{
|
|
1443 |
indexOfEnd = i;
|
|
1444 |
i = tableCount + 1;
|
|
1445 |
}
|
|
1446 |
}
|
|
1447 |
|
|
1448 |
if(indexOfEnd == indexOfStart)
|
|
1449 |
{
|
|
1450 |
iNewLineArray.Insert(aStartPosInText, indexOfStart);
|
|
1451 |
iNewLineArray.Insert(aEndPosInText, indexOfStart + 1);
|
|
1452 |
|
|
1453 |
TBidiText::TDirectionality direction = iLineDirection[indexOfEnd];
|
|
1454 |
|
|
1455 |
iLineDirection.Insert(direction, indexOfStart);
|
|
1456 |
iLineDirection.Insert(aDirection, indexOfStart + 1);
|
|
1457 |
}
|
|
1458 |
else
|
|
1459 |
{
|
|
1460 |
iNewLineArray.Insert(aEndPosInText, indexOfEnd);
|
|
1461 |
iNewLineArray.Insert(aStartPosInText, indexOfStart);
|
|
1462 |
|
|
1463 |
for(TInt i = indexOfEnd ; i > indexOfStart ; --i)
|
|
1464 |
{
|
|
1465 |
iNewLineArray.Remove(i);
|
|
1466 |
}
|
|
1467 |
|
|
1468 |
TBidiText::TDirectionality direction = iLineDirection[indexOfStart];
|
|
1469 |
|
|
1470 |
iLineDirection.Insert(aDirection, indexOfEnd);
|
|
1471 |
iLineDirection.Insert(direction, indexOfStart);
|
|
1472 |
|
|
1473 |
for(TInt i = indexOfEnd ; i > indexOfStart ; --i)
|
|
1474 |
{
|
|
1475 |
iLineDirection.Remove(i);
|
|
1476 |
}
|
|
1477 |
}
|
|
1478 |
if(0 == aStartPosInText)
|
|
1479 |
{
|
|
1480 |
iLineDirection[indexOfStart] = aDirection;
|
|
1481 |
}
|
|
1482 |
return ETrue;
|
|
1483 |
}
|
|
1484 |
|
|
1485 |
TBool CFsTextParser::IsTexturePosition(TInt aPos, TInt &aId)
|
|
1486 |
{
|
|
1487 |
TBool retVal = EFalse;
|
|
1488 |
|
|
1489 |
TInt tableCount = iTextureIndex.Count();
|
|
1490 |
|
|
1491 |
for(TInt i = 0 ; i < tableCount ; ++i)
|
|
1492 |
{
|
|
1493 |
TInt texturePosition = iTextureIndex[i].iPositionInText;
|
|
1494 |
|
|
1495 |
if(aPos == texturePosition)
|
|
1496 |
{
|
|
1497 |
retVal = ETrue;
|
|
1498 |
aId = iTextureIndex[i].iTextureId;
|
|
1499 |
i = tableCount + 1;
|
|
1500 |
}
|
|
1501 |
}
|
|
1502 |
|
|
1503 |
return retVal;
|
|
1504 |
}
|