|
1 /* |
|
2 * Copyright (c) 2006 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: Text visual |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <s32mem.h> |
|
20 #include "alf/alftextvisual.h" |
|
21 #include "alf/alfcontrol.h" |
|
22 #include "alf/alfenv.h" |
|
23 #include "alfclient.h" |
|
24 #include "alf/alfconstants.h" |
|
25 #include "alf/alfgencomponent.h" |
|
26 #include "alflogger.h" |
|
27 #include "alf/alflayoutmetrics.h" |
|
28 #include "alf/alftextstyle.h" |
|
29 #include "alf/alfdropshadow.h" |
|
30 #include <uiacceltk/HuiFont.h> |
|
31 |
|
32 #include <AknsConstants.h> |
|
33 #include <AknBidiTextUtils.h> |
|
34 |
|
35 #include <utf.h> |
|
36 |
|
37 #include <aknnotewrappers.h> |
|
38 |
|
39 #ifdef ALF_RASTER_TEXT |
|
40 |
|
41 /** Granularity of line wrapping array. */ |
|
42 const TInt KLineArrayGranularity = 4; |
|
43 |
|
44 NONSHARABLE_CLASS(CAlfRasterizedTextMesh): public CBase |
|
45 { |
|
46 struct SRasterizedLine |
|
47 { |
|
48 SRasterizedLine() |
|
49 { |
|
50 iTexture = NULL; |
|
51 iGap = 0; |
|
52 } |
|
53 /** Texture that holds the rasterized version of a text line. The |
|
54 size of the texture determines the extents of the line. */ |
|
55 CAlfTexture* iTexture; |
|
56 |
|
57 /** Extra gap to the next line in pixels. Not applied to the last |
|
58 line. */ |
|
59 TInt iGap; |
|
60 }; |
|
61 |
|
62 public: |
|
63 static CAlfRasterizedTextMesh* NewL(CAlfTextVisual* aVisual) |
|
64 { |
|
65 CAlfRasterizedTextMesh* self = new (ELeave) CAlfRasterizedTextMesh(aVisual); |
|
66 return self; |
|
67 } |
|
68 |
|
69 CAlfRasterizedTextMesh(CAlfTextVisual* aVisual) |
|
70 :iVisual(aVisual){} |
|
71 |
|
72 ~CAlfRasterizedTextMesh() |
|
73 { |
|
74 ResetLines(ETrue); |
|
75 iLines.Close(); |
|
76 ReleaseTextures(ETrue); |
|
77 iObsoleteTextures.Close(); |
|
78 delete iBuf; |
|
79 } |
|
80 |
|
81 void PrepareForRasterize() |
|
82 { |
|
83 // resolve max width |
|
84 iMaxWidth = KMaxTInt; |
|
85 if(iVisual->Wrapping() != CAlfTextVisual::ELineWrapManual) |
|
86 { |
|
87 TAlfRealRect content = iVisual->DisplayRectTarget(); |
|
88 content.Shrink(iVisual->PaddingInPixels()); |
|
89 iMaxWidth = TInt(content.Width()+0.5f); |
|
90 } |
|
91 } |
|
92 |
|
93 TInt Lines() |
|
94 { |
|
95 return iLines.Count(); |
|
96 } |
|
97 |
|
98 void ResetLines(TBool aDeleteTexture = EFalse) |
|
99 { |
|
100 for(TInt i = 0; i < iLines.Count(); ++i) |
|
101 { |
|
102 if ( aDeleteTexture ) |
|
103 { |
|
104 delete iLines[i].iTexture; |
|
105 } |
|
106 else |
|
107 { |
|
108 MarkTextureForRemovalL(iLines[i].iTexture); |
|
109 } |
|
110 iLines[i].iTexture = NULL; |
|
111 } |
|
112 |
|
113 iLines.Reset(); |
|
114 } |
|
115 |
|
116 void RasterizeLineL(const TDesC& aTextLine, SRasterizedLine & aLineOut, CAlfTextStyle* aTextStyle) |
|
117 { |
|
118 // Calculate line extents and assign it to texture size. |
|
119 TSize textureSize = aTextStyle->LineExtentsL(aTextLine); |
|
120 |
|
121 if(textureSize.iWidth == 0) |
|
122 { |
|
123 // This is an empty string. We will not rasterize it. |
|
124 // Just add a gap to rows. |
|
125 aLineOut.iTexture = NULL; |
|
126 |
|
127 aLineOut.iGap = textureSize.iHeight; // @todo: refacture/rename iGap? iGap is used as a size of an empty line? |
|
128 return; |
|
129 } |
|
130 |
|
131 // Rasterize string using the defined text style. |
|
132 aTextStyle->RasterizeLineL(aTextLine, &aLineOut.iTexture); |
|
133 } |
|
134 |
|
135 void DoBuildL(CAlfTextStyle* aTextStyle) |
|
136 { |
|
137 ResetLines(); |
|
138 |
|
139 TSize extents(0, 0); |
|
140 const TDesC& text = iVisual->Text(); |
|
141 |
|
142 // Retrieve the CFont object used when rasterizing this text mesh. |
|
143 CFont* font = aTextStyle->Font()->NearestFontL(1.0); |
|
144 |
|
145 // In wrapping mode, let the mesh know how much space there is |
|
146 // for drawing into. |
|
147 TInt maxWidth = iMaxWidth; //KMaxTInt; |
|
148 TInt lineCount = 0; |
|
149 |
|
150 // awkward, just to avoid warning |
|
151 CArrayFixFlat<TPtrC>* linePtrs = 0; |
|
152 HBufC* buf = 0; |
|
153 |
|
154 switch(iVisual->Wrapping()) |
|
155 { |
|
156 case CAlfTextVisual::ELineWrapManual: |
|
157 { |
|
158 lineCount = 1; |
|
159 for (TInt i = text.Length()-2;i>=0;i--) // linebreak as last character is ignored |
|
160 { |
|
161 if (text[i]=='\n') // not elegant but keeps the compatibility |
|
162 lineCount++; |
|
163 } |
|
164 if (lineCount > 1) |
|
165 { |
|
166 TInt lineStart = 0; |
|
167 TInt breakpos = 0; |
|
168 TInt remaining = text.Length(); |
|
169 while(lineCount) |
|
170 { |
|
171 for (TInt i = lineStart; i<remaining ;i++) |
|
172 { |
|
173 if (text[i]=='\n') // not elegant but keeps the compatibility |
|
174 { |
|
175 breakpos = i; |
|
176 break; |
|
177 } |
|
178 } |
|
179 if (breakpos < lineStart) // not found |
|
180 { |
|
181 breakpos = remaining-1; |
|
182 } |
|
183 |
|
184 HBufC* buf = text.Mid(lineStart,breakpos-lineStart).AllocLC(); // todo.. is extra space required for bidi |
|
185 lineStart = breakpos+1; |
|
186 TPtr ptr = buf->Des(); |
|
187 // truncate line |
|
188 AknBidiTextUtils::ConvertToVisualAndClipL(ptr, *font, maxWidth, maxWidth); |
|
189 // create the line entry if not already existing |
|
190 |
|
191 SRasterizedLine line; |
|
192 line.iTexture = NULL; |
|
193 line.iGap = 0; |
|
194 iLines.AppendL(line); |
|
195 |
|
196 TInt index = iLines.Count()-1; |
|
197 // rasterize a single line (updates texture in iLines[0].iTexture) |
|
198 RasterizeLineL(ptr, iLines[index], aTextStyle); |
|
199 |
|
200 // Get extents from the texture we just created |
|
201 CAlfTexture* tex = iLines[index].iTexture; |
|
202 extents.iHeight += iLines[index].iGap; |
|
203 if(tex) |
|
204 { |
|
205 extents.iWidth = Max(extents.iWidth, tex->Size().iWidth); |
|
206 extents.iHeight += tex->Size().iHeight; |
|
207 } |
|
208 |
|
209 CleanupStack::PopAndDestroy(buf); |
|
210 lineCount--; |
|
211 } |
|
212 break; |
|
213 } |
|
214 } // fall through with single line |
|
215 case CAlfTextVisual::ELineWrapTruncate: |
|
216 { |
|
217 lineCount = 1; // there's always one line created per logical line |
|
218 HBufC* buf = text.AllocLC(); // todo.. is extra space required for bidi |
|
219 TPtr ptr = buf->Des(); |
|
220 // truncate line |
|
221 AknBidiTextUtils::ConvertToVisualAndClipL(ptr, *font, maxWidth, maxWidth); |
|
222 // create the line entry if not already existing |
|
223 |
|
224 SRasterizedLine line; |
|
225 line.iTexture = NULL; |
|
226 line.iGap = 0; |
|
227 iLines.AppendL(line); |
|
228 |
|
229 // rasterize a single line (updates texture in iLines[0].iTexture) |
|
230 RasterizeLineL(ptr, iLines[0], aTextStyle); |
|
231 |
|
232 // Get extents from the texture we just created |
|
233 CAlfTexture* tex = iLines[0].iTexture; |
|
234 extents.iHeight += iLines[0].iGap; |
|
235 if(tex) |
|
236 { |
|
237 extents.iWidth = Max(extents.iWidth, tex->Size().iWidth); |
|
238 extents.iHeight += tex->Size().iHeight; |
|
239 } |
|
240 |
|
241 CleanupStack::PopAndDestroy(buf); |
|
242 break; |
|
243 } |
|
244 |
|
245 case CAlfTextVisual::ELineWrapBreak: |
|
246 { |
|
247 // wrap lines to array |
|
248 linePtrs = new (ELeave) CArrayFixFlat<TPtrC>(KLineArrayGranularity); |
|
249 CleanupStack::PushL(linePtrs); |
|
250 |
|
251 buf = AknBidiTextUtils::ConvertToVisualAndWrapToArrayL( |
|
252 text, maxWidth, *font, *linePtrs); |
|
253 CleanupStack::PushL(buf); |
|
254 |
|
255 // Do rasterisation |
|
256 for(TInt i = 0; i < linePtrs->Count();i++) |
|
257 { |
|
258 SRasterizedLine line; |
|
259 line.iTexture = NULL; |
|
260 line.iGap = 0; |
|
261 iLines.AppendL(line); |
|
262 |
|
263 // rasterize a single line (updates texture in iLines[i].iTexture) |
|
264 RasterizeLineL(linePtrs->At(i), iLines[i], aTextStyle); |
|
265 CAlfTexture* tex = iLines[i].iTexture; |
|
266 extents.iHeight += iLines[i].iGap; |
|
267 |
|
268 if(tex) |
|
269 { |
|
270 extents.iWidth = Max(extents.iWidth, tex->Size().iWidth); |
|
271 extents.iHeight += tex->Size().iHeight; |
|
272 } |
|
273 |
|
274 if (i == iVisual->MaxLineCount()-1) |
|
275 { |
|
276 // Maximum number of lines reached. |
|
277 break; |
|
278 } |
|
279 } |
|
280 CleanupStack::PopAndDestroy(buf); |
|
281 CleanupStack::PopAndDestroy(linePtrs); |
|
282 break; |
|
283 } |
|
284 |
|
285 default: |
|
286 break; |
|
287 } |
|
288 |
|
289 // Extents needs to be updated in order to make alignment |
|
290 // work properly. |
|
291 iExtents = extents; |
|
292 |
|
293 UpdateDescriptorL(); |
|
294 } |
|
295 |
|
296 void UpdateDescriptorL() |
|
297 { |
|
298 delete iBuf; |
|
299 iBuf = 0; |
|
300 iBuf = HBufC8::NewL((iLines.Count()+1)*8 + 2*4); |
|
301 RDesWriteStream stream; |
|
302 TPtr8 ptr = iBuf->Des(); |
|
303 stream.Open(ptr); |
|
304 CleanupClosePushL(stream); |
|
305 stream.WriteInt32L(iLines.Count()); |
|
306 for (TInt i = iLines.Count()-1; i >= 0; i--) |
|
307 { |
|
308 if (iLines[i].iTexture) |
|
309 stream.WriteInt32L(iLines[i].iTexture->ServerHandle()); |
|
310 else |
|
311 stream.WriteInt32L(0); |
|
312 stream.WriteInt32L(iLines[i].iGap); |
|
313 } |
|
314 stream.WriteInt32L(iExtents.iWidth); |
|
315 stream.WriteInt32L(iExtents.iHeight); |
|
316 stream.CommitL(); |
|
317 CleanupStack::PopAndDestroy(); // close stream |
|
318 } |
|
319 |
|
320 HBufC8* Buffer() |
|
321 { |
|
322 return iBuf; |
|
323 } |
|
324 |
|
325 void MarkTextureForRemovalL(CAlfTexture* aTexture) |
|
326 { |
|
327 if (iObsoleteTextures.Find(aTexture)==KErrNotFound) |
|
328 { |
|
329 iObsoleteTextures.AppendL(aTexture); |
|
330 } |
|
331 } |
|
332 |
|
333 void ReleaseTextures(TBool aObsoleteOnly) |
|
334 { |
|
335 if (!aObsoleteOnly) |
|
336 { |
|
337 for (TInt i = iLines.Count()-1;i>=0;i--) |
|
338 { |
|
339 delete iLines[i].iTexture; |
|
340 iLines.Remove(0); |
|
341 } |
|
342 } |
|
343 iObsoleteTextures.ResetAndDestroy(); |
|
344 } |
|
345 |
|
346 |
|
347 CAlfTextVisual* iVisual; |
|
348 RArray<SRasterizedLine> iLines; |
|
349 RPointerArray<CAlfTexture> iObsoleteTextures; |
|
350 HBufC8* iBuf; |
|
351 TSize iExtents; |
|
352 |
|
353 TInt iMaxWidth; |
|
354 }; |
|
355 |
|
356 #endif // #ifdef ALF_RASTER_TEXT |
|
357 |
|
358 struct CAlfTextVisual::TTextVisualPrivateData |
|
359 { |
|
360 HBufC* iText; // own |
|
361 TInt iTextStyleId; |
|
362 CAlfTextStyle* iTextStyle; |
|
363 #ifdef ALF_RASTER_TEXT |
|
364 CAlfRasterizedTextMesh* iMesh; |
|
365 TInt iWrappingMode; |
|
366 TInt iMaxLineCount; |
|
367 TInt iLineSpacingUnit; |
|
368 TInt iLineSpacing; |
|
369 |
|
370 TBool iMeshUptoDate; |
|
371 #endif // #ifdef ALF_RASTER_TEXT |
|
372 }; |
|
373 |
|
374 |
|
375 // ======== MEMBER FUNCTIONS ======== |
|
376 |
|
377 // --------------------------------------------------------------------------- |
|
378 // Constructor |
|
379 // --------------------------------------------------------------------------- |
|
380 // |
|
381 EXPORT_C CAlfTextVisual::CAlfTextVisual() |
|
382 { |
|
383 } |
|
384 |
|
385 |
|
386 // --------------------------------------------------------------------------- |
|
387 // ConstructL |
|
388 // --------------------------------------------------------------------------- |
|
389 // |
|
390 EXPORT_C void CAlfTextVisual::ConstructL(CAlfControl& aOwner) |
|
391 { |
|
392 CAlfVisual::ConstructL(aOwner); |
|
393 |
|
394 iTextVisualData = new (ELeave) TTextVisualPrivateData; |
|
395 iTextVisualData->iText = NULL; |
|
396 iTextVisualData->iTextStyleId = 0; |
|
397 #ifdef ALF_RASTER_TEXT |
|
398 iTextVisualData->iTextStyle = 0; |
|
399 iTextVisualData->iMesh = 0; |
|
400 iTextVisualData->iWrappingMode=0; |
|
401 iTextVisualData->iMaxLineCount=256; |
|
402 iTextVisualData->iLineSpacing=0; |
|
403 iTextVisualData->iLineSpacingUnit=0; |
|
404 iTextVisualData->iMesh = CAlfRasterizedTextMesh::NewL(this); |
|
405 |
|
406 iTextVisualData->iMeshUptoDate = EFalse; |
|
407 |
|
408 #endif //#ifdef ALF_RASTER_TEXT |
|
409 |
|
410 // If alflayoutmetrcis is in automatic mode, mark this visual. |
|
411 if (aOwner.Env().LayoutMetricsUtility()->AutoMarking() ) |
|
412 { |
|
413 aOwner.Env().LayoutMetricsUtility()->MarkVisual(NULL, this); |
|
414 } |
|
415 } |
|
416 |
|
417 void CAlfTextVisual::PrepareForUpdateMesh() |
|
418 { |
|
419 #ifdef ALF_RASTER_TEXT |
|
420 if(!iTextVisualData->iMeshUptoDate) |
|
421 { |
|
422 iTextVisualData->iMesh->PrepareForRasterize(); |
|
423 } |
|
424 #endif // ALF_RASTER_TEXT |
|
425 } |
|
426 |
|
427 void CAlfTextVisual::UpdateMesh(TBool aSynch) |
|
428 { |
|
429 #ifdef ALF_RASTER_TEXT |
|
430 // update textures |
|
431 CAlfTextStyle* style = iTextVisualData->iTextStyle; |
|
432 if (!style) |
|
433 { // default |
|
434 iTextVisualData->iTextStyle = Env().TextStyleManager().SwitchTextStyle(0,this);//register for updates |
|
435 style = Env().TextStyleManager().TextStyle(0); |
|
436 } |
|
437 if (aSynch) |
|
438 { |
|
439 if(!iTextVisualData->iMeshUptoDate) |
|
440 { |
|
441 TRAPD(err, iTextVisualData->iMesh->DoBuildL(style)) |
|
442 // Inform server |
|
443 if (!err) |
|
444 { |
|
445 TPtr8 ptr = iTextVisualData->iMesh->Buffer()->Des(); |
|
446 Comms()->DoCmdNoReply(EAlfTextVisualSetRasterizedMesh, ptr); |
|
447 } |
|
448 iTextVisualData->iMesh->ReleaseTextures(ETrue); |
|
449 iTextVisualData->iMeshUptoDate = ETrue; |
|
450 } |
|
451 } |
|
452 else |
|
453 { |
|
454 iTextVisualData->iMeshUptoDate = EFalse; |
|
455 style->ReportChanged(); |
|
456 } |
|
457 #endif |
|
458 } |
|
459 void CAlfTextVisual::ReleaseMesh() |
|
460 { |
|
461 #ifdef ALF_RASTER_TEXT |
|
462 iTextVisualData->iMesh->ResetLines(ETrue); |
|
463 iTextVisualData->iMeshUptoDate = EFalse; |
|
464 #endif |
|
465 } |
|
466 |
|
467 |
|
468 |
|
469 // --------------------------------------------------------------------------- |
|
470 // Destructor |
|
471 // --------------------------------------------------------------------------- |
|
472 // |
|
473 EXPORT_C CAlfTextVisual::~CAlfTextVisual() |
|
474 { |
|
475 if ( iTextVisualData ) |
|
476 { |
|
477 delete iTextVisualData->iText; |
|
478 #ifdef ALF_RASTER_TEXT |
|
479 Env().TextStyleManager().Unregister(this); |
|
480 delete iTextVisualData->iMesh; |
|
481 #endif |
|
482 } |
|
483 delete iTextVisualData; |
|
484 |
|
485 Env().LayoutMetricsUtility()->UnmarkVisual(this); |
|
486 } |
|
487 |
|
488 |
|
489 // --------------------------------------------------------------------------- |
|
490 // Creates new CAlfTextVisual |
|
491 // --------------------------------------------------------------------------- |
|
492 // |
|
493 EXPORT_C CAlfTextVisual* CAlfTextVisual::AddNewL( |
|
494 CAlfControl& aOwnerControl, |
|
495 CAlfLayout* aParentLayout) |
|
496 { |
|
497 CAlfTextVisual* text = STATIC_CAST(CAlfTextVisual*, |
|
498 aOwnerControl.AppendVisualL(EAlfVisualTypeText, aParentLayout)); |
|
499 return text; |
|
500 } |
|
501 |
|
502 // --------------------------------------------------------------------------- |
|
503 // Sets text. |
|
504 // --------------------------------------------------------------------------- |
|
505 // |
|
506 EXPORT_C void CAlfTextVisual::SetTextL(const TDesC& aText) |
|
507 { |
|
508 #ifdef ALF_RASTER_TEXT |
|
509 if (!iTextVisualData->iText || aText.Compare(*iTextVisualData->iText)) |
|
510 { |
|
511 // Store the text into a temp buffer. |
|
512 HBufC* newBuffer = aText.AllocL(); |
|
513 delete iTextVisualData->iText; |
|
514 iTextVisualData->iText = newBuffer; |
|
515 UpdateMesh(); |
|
516 } |
|
517 #else |
|
518 // Store the text into a temp buffer. |
|
519 HBufC* newBuffer = aText.AllocLC(); |
|
520 |
|
521 TPtrC8 ptr(reinterpret_cast<const TUint8 *>(aText.Ptr()), aText.Length()*2); |
|
522 TBuf8<1> dum; |
|
523 |
|
524 TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualSetText, ptr, dum); |
|
525 if ( err ) |
|
526 { |
|
527 __ALFLOGSTRING1( "CAlfTextVisual::SetTextL leave error %d", err ) |
|
528 User::Leave( err ); |
|
529 } |
|
530 |
|
531 // Everything's OK. Switch the internal text buffer. |
|
532 CleanupStack::Pop( newBuffer ); |
|
533 delete iTextVisualData->iText; |
|
534 iTextVisualData->iText = newBuffer; |
|
535 #endif |
|
536 } |
|
537 |
|
538 // --------------------------------------------------------------------------- |
|
539 // Gets text. |
|
540 // --------------------------------------------------------------------------- |
|
541 // |
|
542 EXPORT_C const TDesC& CAlfTextVisual::Text() const |
|
543 { |
|
544 if ( iTextVisualData && iTextVisualData->iText ) |
|
545 { |
|
546 return *iTextVisualData->iText; |
|
547 } |
|
548 return KNullDesC(); |
|
549 } |
|
550 |
|
551 // --------------------------------------------------------------------------- |
|
552 // Sets style. |
|
553 // --------------------------------------------------------------------------- |
|
554 // |
|
555 EXPORT_C void CAlfTextVisual::SetStyle( |
|
556 TAlfPreconfiguredTextStyle aStyle, |
|
557 TAlfBackgroundType aBackgroundType ) |
|
558 { |
|
559 #ifdef ALF_RASTER_TEXT |
|
560 iTextVisualData->iTextStyle = Env().TextStyleManager().SwitchTextStyle(aStyle, this); |
|
561 iTextVisualData->iTextStyleId = aBackgroundType; // zero warnings, right |
|
562 iTextVisualData->iTextStyleId = aStyle; |
|
563 UpdateMesh(); |
|
564 #else |
|
565 TInt2 params(aStyle, aBackgroundType); |
|
566 TPckgC<TInt2> buf(params); |
|
567 |
|
568 TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetStyle, buf); |
|
569 |
|
570 if ( err != KErrNone ) |
|
571 { |
|
572 __ALFLOGSTRING1( "CAlfTextVisual::SetStyle ignore error %d", err ) |
|
573 } |
|
574 #endif |
|
575 } |
|
576 |
|
577 // --------------------------------------------------------------------------- |
|
578 // Sets style. |
|
579 // --------------------------------------------------------------------------- |
|
580 // |
|
581 EXPORT_C void CAlfTextVisual::SetTextStyle( TInt aTextStyleId ) |
|
582 { |
|
583 #ifdef ALF_RASTER_TEXT |
|
584 if(!iTextVisualData->iTextStyle || iTextVisualData->iTextStyleId != aTextStyleId) |
|
585 { |
|
586 iTextVisualData->iTextStyle = Env().TextStyleManager().SwitchTextStyle(aTextStyleId, this); |
|
587 iTextVisualData->iTextStyleId = aTextStyleId; |
|
588 UpdateMesh(); |
|
589 } |
|
590 #else |
|
591 // Convert the text style id from client domain to session domain. |
|
592 CAlfTextStyle* textStyle = Env().TextStyleManager().TextStyle(aTextStyleId); |
|
593 TPckgC<TInt> buf(textStyle->Comms()->Identifier()); |
|
594 TBuf8<1> dum; |
|
595 |
|
596 TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualSetTextStyle, buf, dum); |
|
597 |
|
598 if ( err != KErrNone ) |
|
599 { |
|
600 __ALFLOGSTRING1( "CAlfTextVisual::SetTextStyle ignore error %d", err ) |
|
601 } |
|
602 else |
|
603 { |
|
604 // once we know that it's been set successfully, we can cache the client-side id |
|
605 // on the client-side, for later use |
|
606 iTextVisualData->iTextStyleId = aTextStyleId; |
|
607 } |
|
608 #endif // #ifdef ALF_RASTER_TEXT |
|
609 } |
|
610 |
|
611 // --------------------------------------------------------------------------- |
|
612 // Sets alignment. |
|
613 // --------------------------------------------------------------------------- |
|
614 // |
|
615 EXPORT_C void CAlfTextVisual::SetAlign( TAlfAlignHorizontal aAlignHorizontal, |
|
616 TAlfAlignVertical aAlignVertical) |
|
617 { |
|
618 TInt2 params(aAlignHorizontal, aAlignVertical); |
|
619 TPckgC<TInt2> buf(params); |
|
620 |
|
621 TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetAlign, buf ); |
|
622 |
|
623 if ( err != KErrNone ) |
|
624 { |
|
625 __ALFLOGSTRING1( "CAlfTextVisual::SetAlign ignore error %d", err ) |
|
626 } |
|
627 } |
|
628 |
|
629 // --------------------------------------------------------------------------- |
|
630 // Sets the line spacing for multiline text visual when the text wraps around. |
|
631 // --------------------------------------------------------------------------- |
|
632 // |
|
633 EXPORT_C void CAlfTextVisual::SetLineSpacing(TInt aLineSpacing, |
|
634 TLineSpacingUnits aUnits) |
|
635 { |
|
636 #ifdef ALF_RASTER_TEXT |
|
637 iTextVisualData->iLineSpacing = aLineSpacing; |
|
638 iTextVisualData->iLineSpacingUnit = aUnits; |
|
639 if (iTextVisualData->iMesh->Lines() > 1) |
|
640 { |
|
641 UpdateMesh(); |
|
642 } |
|
643 #else |
|
644 TInt2 params(aLineSpacing, aUnits); |
|
645 TPckgC<TInt2> buf(params); |
|
646 |
|
647 TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetLineSpacing, buf ); |
|
648 |
|
649 if ( err != KErrNone ) |
|
650 { |
|
651 __ALFLOGSTRING1( "CAlfTextVisual::SetAlign ignore error %d", err ) |
|
652 } |
|
653 #endif |
|
654 } |
|
655 |
|
656 // --------------------------------------------------------------------------- |
|
657 // |
|
658 // --------------------------------------------------------------------------- |
|
659 // |
|
660 EXPORT_C TSize CAlfTextVisual::TextExtents() const |
|
661 { |
|
662 #ifdef ALF_RASTER_TEXT |
|
663 TSize size( 0, 0 ); |
|
664 if( Text().Length() != 0 ) |
|
665 { |
|
666 TRAP_IGNORE(size = iTextVisualData->iTextStyle->LineExtentsL(Text())) |
|
667 } |
|
668 |
|
669 return size; |
|
670 #else |
|
671 if( Text().Length() == 0 ) |
|
672 { |
|
673 return TSize( 0, 0 ); |
|
674 } |
|
675 |
|
676 TBufC8<1> inDum; |
|
677 TSize size; |
|
678 TPckg<TSize> outBuf(size); |
|
679 |
|
680 TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualTextExtents, inDum, outBuf); |
|
681 |
|
682 if ( err != KErrNone ) |
|
683 { |
|
684 __ALFLOGSTRING1( "CAlfTextVisual::TextExtents ignore error %d", err ) |
|
685 } |
|
686 |
|
687 return size; |
|
688 #endif |
|
689 } |
|
690 |
|
691 // --------------------------------------------------------------------------- |
|
692 // |
|
693 // --------------------------------------------------------------------------- |
|
694 // |
|
695 EXPORT_C TRect CAlfTextVisual::SubstringExtents(TUint aStart, TUint aEnd) const |
|
696 { |
|
697 #ifdef ALF_RASTER_TEXT |
|
698 TSize size( 0, 0 ); |
|
699 if( Text().Length() != 0 && aStart < aEnd ) |
|
700 { |
|
701 TRAP_IGNORE(size = iTextVisualData->iTextStyle->LineExtentsL(Text().Mid(aStart, aEnd-aStart))) |
|
702 } |
|
703 |
|
704 return size; |
|
705 #else |
|
706 if( Text().Length() == 0 ) |
|
707 { |
|
708 return TSize( 0, 0 ); |
|
709 } |
|
710 |
|
711 TInt2 params(aStart, aEnd); |
|
712 TPckgC<TInt2> inBuf(params); |
|
713 TRect size; |
|
714 TPckg<TRect> outBuf(size); |
|
715 |
|
716 TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualSubstringExtents, inBuf, outBuf); |
|
717 |
|
718 if ( err != KErrNone ) |
|
719 { |
|
720 __ALFLOGSTRING1( "CAlfTextVisual::SubstringExtents ignore error %d", err ) |
|
721 } |
|
722 |
|
723 return size; |
|
724 #endif |
|
725 } |
|
726 |
|
727 // --------------------------------------------------------------------------- |
|
728 // |
|
729 // --------------------------------------------------------------------------- |
|
730 // |
|
731 EXPORT_C TAlfPreconfiguredTextStyle CAlfTextVisual::Style() |
|
732 { |
|
733 #ifdef ALF_RASTER_TEXT |
|
734 return (TAlfPreconfiguredTextStyle)TextStyle(); |
|
735 |
|
736 #else |
|
737 TAlfPreconfiguredTextStyle style = EAlfTextStyleNormal; |
|
738 TAlfBackgroundType backgroundType = EAlfBackgroundTypeLight; |
|
739 TInt2 params(style, backgroundType); |
|
740 TPckg<TInt2> outBuf(params); |
|
741 |
|
742 TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualStyle, KNullDesC8(), outBuf); |
|
743 |
|
744 if ( err != KErrNone ) |
|
745 { |
|
746 __ALFLOGSTRING1( "CAlfTextVisual::Style ignore error %d", err ) |
|
747 } |
|
748 |
|
749 return style; |
|
750 #endif |
|
751 } |
|
752 |
|
753 // --------------------------------------------------------------------------- |
|
754 // |
|
755 // --------------------------------------------------------------------------- |
|
756 // |
|
757 EXPORT_C TInt CAlfTextVisual::TextStyle() const |
|
758 { |
|
759 // use the client-side cache, as this id only makes sense on the client side |
|
760 return iTextVisualData->iTextStyleId; |
|
761 } |
|
762 |
|
763 // --------------------------------------------------------------------------- |
|
764 // |
|
765 // --------------------------------------------------------------------------- |
|
766 // |
|
767 EXPORT_C void CAlfTextVisual::SetMaxLineCount(TInt aMaxLineCount) |
|
768 { |
|
769 #ifdef ALF_RASTER_TEXT |
|
770 if (aMaxLineCount != iTextVisualData->iMaxLineCount ) |
|
771 { |
|
772 iTextVisualData->iMaxLineCount = aMaxLineCount; |
|
773 if (iTextVisualData->iMesh->Lines() > aMaxLineCount) |
|
774 { |
|
775 UpdateMesh(); |
|
776 } |
|
777 } |
|
778 |
|
779 #else |
|
780 TPckgC<TInt> inBuf(aMaxLineCount); |
|
781 TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetMaxLineCount, inBuf); |
|
782 |
|
783 if ( err != KErrNone ) |
|
784 { |
|
785 __ALFLOGSTRING1( "CAlfTextVisual::SetMaxLineCount ignore error %d", err ) |
|
786 } |
|
787 #endif |
|
788 } |
|
789 |
|
790 // --------------------------------------------------------------------------- |
|
791 // |
|
792 // --------------------------------------------------------------------------- |
|
793 // |
|
794 EXPORT_C TInt CAlfTextVisual::MaxLineCount() const |
|
795 { |
|
796 #ifdef ALF_RASTER_TEXT |
|
797 return iTextVisualData->iMaxLineCount; |
|
798 #else |
|
799 TBufC8<1> inDum; |
|
800 TInt value = 0; |
|
801 TPckg<TInt> outBuf(value); |
|
802 TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualMaxLineCount, inDum, |
|
803 outBuf); |
|
804 |
|
805 if ( err != KErrNone ) |
|
806 { |
|
807 __ALFLOGSTRING1( "CAlfTextVisual::MaxLineCount ignore error %d", err ) |
|
808 } |
|
809 |
|
810 return value; |
|
811 #endif |
|
812 } |
|
813 |
|
814 // --------------------------------------------------------------------------- |
|
815 // |
|
816 // --------------------------------------------------------------------------- |
|
817 // |
|
818 |
|
819 EXPORT_C CAlfTextVisual::TLineWrap CAlfTextVisual::Wrapping() const |
|
820 { |
|
821 #ifdef ALF_RASTER_TEXT |
|
822 return (CAlfTextVisual::TLineWrap)iTextVisualData->iWrappingMode; |
|
823 #else |
|
824 TBufC8<1> inDum; |
|
825 TLineWrap value = ELineWrapTruncate; |
|
826 TPckg<TLineWrap> outBuf(value); |
|
827 TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualWrapping, inDum, |
|
828 outBuf); |
|
829 |
|
830 if ( err != KErrNone ) |
|
831 { |
|
832 __ALFLOGSTRING1( "CAlfTextVisual::Wrapping ignore error %d", err ) |
|
833 } |
|
834 |
|
835 return value; |
|
836 #endif |
|
837 } |
|
838 |
|
839 // --------------------------------------------------------------------------- |
|
840 // |
|
841 // --------------------------------------------------------------------------- |
|
842 // |
|
843 EXPORT_C void CAlfTextVisual::SetWrapping(CAlfTextVisual::TLineWrap aWrap) |
|
844 { |
|
845 #ifdef ALF_RASTER_TEXT |
|
846 if(iTextVisualData->iWrappingMode != (TInt)aWrap) |
|
847 { |
|
848 iTextVisualData->iWrappingMode = (TInt)aWrap; |
|
849 UpdateMesh(); |
|
850 } |
|
851 #else |
|
852 TPckg<TLineWrap> inBuf(aWrap); |
|
853 TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetWrapping, inBuf ); |
|
854 |
|
855 if ( err != KErrNone ) |
|
856 { |
|
857 __ALFLOGSTRING1( "CAlfTextVisual::SetWrapping ignore error %d", err ) |
|
858 } |
|
859 #endif |
|
860 } |
|
861 |
|
862 // --------------------------------------------------------------------------- |
|
863 // |
|
864 // --------------------------------------------------------------------------- |
|
865 // |
|
866 EXPORT_C TAlfBackgroundType CAlfTextVisual::BackgroundType() |
|
867 { |
|
868 #ifdef ALF_RASTER_TEXT |
|
869 TAlfBackgroundType backgroundType = EAlfBackgroundTypeLight; |
|
870 return backgroundType; |
|
871 #else |
|
872 TAlfPreconfiguredTextStyle style = EAlfTextStyleNormal; |
|
873 TAlfBackgroundType backgroundType = EAlfBackgroundTypeLight; |
|
874 TInt2 params(style, backgroundType); |
|
875 TPckg<TInt2> outBuf(params); |
|
876 |
|
877 TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualStyle, KNullDesC8(), outBuf); |
|
878 |
|
879 if ( err != KErrNone ) |
|
880 { |
|
881 __ALFLOGSTRING1( "CAlfTextVisual::BackgroundType ignore error %d", err ) |
|
882 } |
|
883 |
|
884 return backgroundType; |
|
885 #endif |
|
886 } |
|
887 |
|
888 // --------------------------------------------------------------------------- |
|
889 // |
|
890 // --------------------------------------------------------------------------- |
|
891 // |
|
892 EXPORT_C TAlfTimedValue CAlfTextVisual::ShadowOpacity() |
|
893 { |
|
894 if ( DropShadowHandler() ) |
|
895 { |
|
896 return 1.f; // not the real value... |
|
897 } |
|
898 |
|
899 return TAlfTimedValue(0); |
|
900 } |
|
901 |
|
902 // --------------------------------------------------------------------------- |
|
903 // |
|
904 // --------------------------------------------------------------------------- |
|
905 // |
|
906 EXPORT_C void CAlfTextVisual::SetShadowOpacity(const TAlfTimedValue& aShadowOpacity) |
|
907 { |
|
908 TRAPD( err, EnableDropShadowL() ); |
|
909 |
|
910 if ( err != KErrNone ) |
|
911 { |
|
912 __ALFLOGSTRING1( "CAlfTextVisual::SetShadowOpacity ignore error %d", err ) |
|
913 return; |
|
914 } |
|
915 |
|
916 DropShadowHandler()->SetOpacity( aShadowOpacity ); |
|
917 } |
|
918 |
|
919 // --------------------------------------------------------------------------- |
|
920 // |
|
921 // --------------------------------------------------------------------------- |
|
922 // |
|
923 EXPORT_C void CAlfTextVisual::SetColor(TRgb aColor) |
|
924 { |
|
925 TAlfTextVisualFontColorParams params; |
|
926 params.iColor = aColor; |
|
927 params.iId = KAknsIIDNone; // This will be ignored in the serverside |
|
928 params.iIndex = 0; // This will be ignored in the serverside |
|
929 |
|
930 TPckg<TAlfTextVisualFontColorParams> inBuf(params); |
|
931 TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetColor, inBuf); |
|
932 |
|
933 if ( err != KErrNone ) |
|
934 { |
|
935 __ALFLOGSTRING1( "CAlfTextVisual::SetColor1 ignore error %d", err ) |
|
936 } |
|
937 } |
|
938 |
|
939 // --------------------------------------------------------------------------- |
|
940 // |
|
941 // --------------------------------------------------------------------------- |
|
942 // |
|
943 EXPORT_C void CAlfTextVisual::SetColor(const TAknsItemID& aId,const TInt aIndex) |
|
944 { |
|
945 TAlfTextVisualFontColorParams params; |
|
946 params.iColor = KRgbBlack; // This will be ignored in the serverside |
|
947 params.iId = aId; |
|
948 params.iIndex = aIndex; |
|
949 |
|
950 TPckg<TAlfTextVisualFontColorParams> inBuf(params); |
|
951 TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetColor, inBuf); |
|
952 |
|
953 if ( err != KErrNone ) |
|
954 { |
|
955 __ALFLOGSTRING1( "CAlfTextVisual::SetColor1 ignore error %d", err ) |
|
956 } |
|
957 } |
|
958 |
|
959 // --------------------------------------------------------------------------- |
|
960 // |
|
961 // --------------------------------------------------------------------------- |
|
962 // |
|
963 EXPORT_C void CAlfTextVisual::EnableShadow(TBool aDoEnable) |
|
964 { |
|
965 TRAPD( err, EnableDropShadowL( aDoEnable ) ); |
|
966 |
|
967 if ( err != KErrNone ) |
|
968 { |
|
969 __ALFLOGSTRING1( "CAlfTextVisual::EnableShadow ignore error %d", err ) |
|
970 } |
|
971 } |
|
972 |
|
973 // --------------------------------------------------------------------------- |
|
974 // Place holder from CAlfVisual |
|
975 // --------------------------------------------------------------------------- |
|
976 // |
|
977 EXPORT_C void CAlfTextVisual::RemoveAndDestroyAllD() |
|
978 { |
|
979 CAlfVisual::RemoveAndDestroyAllD(); |
|
980 } |
|
981 |
|
982 // --------------------------------------------------------------------------- |
|
983 // Place holder from CAlfVisual |
|
984 // --------------------------------------------------------------------------- |
|
985 // |
|
986 EXPORT_C void CAlfTextVisual::UpdateChildrenLayout(TInt aTransitionTime ) |
|
987 { |
|
988 CAlfVisual::UpdateChildrenLayout( aTransitionTime ); |
|
989 } |
|
990 |
|
991 // --------------------------------------------------------------------------- |
|
992 // Place holder from CAlfVisual |
|
993 // --------------------------------------------------------------------------- |
|
994 // |
|
995 EXPORT_C CAlfVisual* CAlfTextVisual::FindTag(const TDesC8& aTag) |
|
996 { |
|
997 return CAlfVisual::FindTag( aTag ); |
|
998 } |
|
999 |
|
1000 // --------------------------------------------------------------------------- |
|
1001 // Place holder from CAlfVisual |
|
1002 // --------------------------------------------------------------------------- |
|
1003 // |
|
1004 EXPORT_C void CAlfTextVisual::DoRemoveAndDestroyAllD() |
|
1005 { |
|
1006 CAlfVisual::DoRemoveAndDestroyAllD(); |
|
1007 } |
|
1008 |
|
1009 // --------------------------------------------------------------------------- |
|
1010 // future proofing |
|
1011 // --------------------------------------------------------------------------- |
|
1012 // |
|
1013 EXPORT_C void CAlfTextVisual::PropertyOwnerExtension(const TUid& aExtensionUid, TAny** aExtensionParams) |
|
1014 { |
|
1015 CAlfVisual::PropertyOwnerExtension(aExtensionUid,aExtensionParams); |
|
1016 } |
|
1017 |
|
1018 // --------------------------------------------------------------------------- |
|
1019 // DEPRECATED! Set Color for Visual using String table and Index |
|
1020 // --------------------------------------------------------------------------- |
|
1021 // |
|
1022 EXPORT_C void CAlfTextVisual::SetColor(const TDesC& /*aTextColorTable*/,const TDesC& /*aColorIndex*/) |
|
1023 { |
|
1024 } |
|
1025 |
|
1026 // --------------------------------------------------------------------------- |
|
1027 // |
|
1028 // --------------------------------------------------------------------------- |
|
1029 // |
|
1030 EXPORT_C void CAlfTextVisual::SetOffset(const TAlfTimedPoint& aOffset) |
|
1031 { |
|
1032 TPckg<TAlfTimedPoint> inBuf(aOffset); |
|
1033 TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetOffset, inBuf); |
|
1034 |
|
1035 if ( err != KErrNone ) |
|
1036 { |
|
1037 __ALFLOGSTRING1( "CAlfTextVisual::SetOffset ignore error %d", err ) |
|
1038 } |
|
1039 } |
|
1040 |
|
1041 // --------------------------------------------------------------------------- |
|
1042 // |
|
1043 // --------------------------------------------------------------------------- |
|
1044 // |
|
1045 EXPORT_C TAlfTimedPoint CAlfTextVisual::Offset() const |
|
1046 { |
|
1047 TBufC8<1> inDum; |
|
1048 TAlfTimedPoint value; |
|
1049 TPckg<TAlfTimedPoint> outBuf(value); |
|
1050 TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualOffset, inDum, |
|
1051 outBuf); |
|
1052 |
|
1053 if ( err != KErrNone ) |
|
1054 { |
|
1055 __ALFLOGSTRING1( "CAlfTextVisual::Offset ignore error %d", err ) |
|
1056 } |
|
1057 |
|
1058 return value; |
|
1059 } |
|
1060 |
|
1061 #ifdef ALF_RASTER_TEXT |
|
1062 // for convenience |
|
1063 void DoLocalHighlightConversionL(TInt aStart, TInt aEnd, HBufC* aText, CAlfTextStyle* aStyle, TSize& aStartPos, TSize& aEndPos) |
|
1064 { |
|
1065 aStartPos = aStyle->LineExtentsL(aText->Left(aStart)); |
|
1066 aEndPos = aStyle->LineExtentsL(aText->Left(aEnd)); |
|
1067 } |
|
1068 #endif |
|
1069 // --------------------------------------------------------------------------- |
|
1070 // |
|
1071 // --------------------------------------------------------------------------- |
|
1072 // |
|
1073 EXPORT_C void CAlfTextVisual::SetHighlightRange(TInt aStart, TInt aEnd, TRgb& aHighlightColor, TRgb& aHighlightTextColor) |
|
1074 { |
|
1075 #ifdef ALF_RASTER_TEXT |
|
1076 // ToDO: convert to mesh coordinates |
|
1077 CAlfTextStyle* style = iTextVisualData->iTextStyle; |
|
1078 if (!style || Text().Length() == 0 || // has not been rasterized ever or text lenght is zero |
|
1079 (aStart < 0) || (aStart > Text().Length()) || (aEnd < 0) || (aStart >= aEnd) || (aEnd > Text().Length())) |
|
1080 |
|
1081 { |
|
1082 return; |
|
1083 } |
|
1084 |
|
1085 TSize startPos, endPos; |
|
1086 TRAPD(err, DoLocalHighlightConversionL(aStart, aEnd, iTextVisualData->iText, style, startPos, endPos)) |
|
1087 if (!err) |
|
1088 { |
|
1089 TAlfTextVisualSetHighlightRangeParams params; |
|
1090 params.iStart = startPos.iWidth; |
|
1091 params.iEnd = endPos.iWidth; |
|
1092 params.iHighlightColor = aHighlightColor; |
|
1093 params.iHighlightTextColor = aHighlightTextColor; |
|
1094 |
|
1095 TPckg<TAlfTextVisualSetHighlightRangeParams> inBuf(params); |
|
1096 err = Comms()->DoCmdNoReply(EAlfTextVisualSetHighlightRange, inBuf); |
|
1097 |
|
1098 if ( err != KErrNone ) |
|
1099 { |
|
1100 __ALFLOGSTRING1( "CAlfTextVisual::SetHighlightRange ignore error %d", err ) |
|
1101 } |
|
1102 } |
|
1103 |
|
1104 |
|
1105 #else |
|
1106 TAlfTextVisualSetHighlightRangeParams params; |
|
1107 params.iStart = aStart; |
|
1108 params.iEnd = aEnd; |
|
1109 params.iHighlightColor = aHighlightColor; |
|
1110 params.iHighlightTextColor = aHighlightTextColor; |
|
1111 |
|
1112 TPckg<TAlfTextVisualSetHighlightRangeParams> inBuf(params); |
|
1113 TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetHighlightRange, inBuf); |
|
1114 |
|
1115 if ( err != KErrNone ) |
|
1116 { |
|
1117 __ALFLOGSTRING1( "CAlfTextVisual::SetHighlightRange ignore error %d", err ) |
|
1118 } |
|
1119 #endif |
|
1120 } |