uiacceltk/hitchcock/Client/src/alftextvisual.cpp
changeset 0 15bf7259bb7c
child 3 d8a3531bc6b8
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     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     if(!iTextVisualData->iMeshUptoDate)
       
   420         {
       
   421         iTextVisualData->iMesh->PrepareForRasterize();
       
   422         }
       
   423     }
       
   424 
       
   425 void CAlfTextVisual::UpdateMesh(TBool aSynch)
       
   426     {
       
   427  #ifdef ALF_RASTER_TEXT
       
   428     // update textures
       
   429     CAlfTextStyle* style = iTextVisualData->iTextStyle;
       
   430     if (!style)
       
   431         { // default
       
   432         iTextVisualData->iTextStyle = Env().TextStyleManager().SwitchTextStyle(0,this);//register for updates 
       
   433         style = Env().TextStyleManager().TextStyle(0);
       
   434         }
       
   435     if (aSynch)
       
   436         {
       
   437         if(!iTextVisualData->iMeshUptoDate)
       
   438             {
       
   439             TRAPD(err, iTextVisualData->iMesh->DoBuildL(style))
       
   440             // Inform server
       
   441             if (!err)
       
   442                 {
       
   443                 TPtr8 ptr = iTextVisualData->iMesh->Buffer()->Des();
       
   444                 Comms()->DoCmdNoReply(EAlfTextVisualSetRasterizedMesh, ptr);    
       
   445                 }    
       
   446             iTextVisualData->iMesh->ReleaseTextures(ETrue);
       
   447             iTextVisualData->iMeshUptoDate = ETrue;
       
   448             }
       
   449         }
       
   450      else
       
   451         {
       
   452         iTextVisualData->iMeshUptoDate = EFalse;
       
   453         style->ReportChanged();
       
   454         }
       
   455  #endif
       
   456     }
       
   457 void CAlfTextVisual::ReleaseMesh()
       
   458     {
       
   459 #ifdef ALF_RASTER_TEXT
       
   460     iTextVisualData->iMesh->ResetLines(ETrue);
       
   461 #endif
       
   462     }
       
   463 	
       
   464 
       
   465 
       
   466 // ---------------------------------------------------------------------------
       
   467 // Destructor
       
   468 // ---------------------------------------------------------------------------
       
   469 //
       
   470 EXPORT_C CAlfTextVisual::~CAlfTextVisual()
       
   471     {
       
   472     if ( iTextVisualData )
       
   473         {
       
   474         delete iTextVisualData->iText;
       
   475 #ifdef ALF_RASTER_TEXT
       
   476         Env().TextStyleManager().Unregister(this);
       
   477         delete iTextVisualData->iMesh;
       
   478 #endif
       
   479         }
       
   480     delete iTextVisualData;
       
   481     
       
   482     Env().LayoutMetricsUtility()->UnmarkVisual(this);
       
   483     }
       
   484 
       
   485 
       
   486 // ---------------------------------------------------------------------------
       
   487 // Creates new CAlfTextVisual
       
   488 // ---------------------------------------------------------------------------
       
   489 //
       
   490 EXPORT_C CAlfTextVisual* CAlfTextVisual::AddNewL(
       
   491     CAlfControl& aOwnerControl,
       
   492     CAlfLayout* aParentLayout)
       
   493     {
       
   494     CAlfTextVisual* text = STATIC_CAST(CAlfTextVisual*,
       
   495         aOwnerControl.AppendVisualL(EAlfVisualTypeText, aParentLayout));
       
   496     return text;
       
   497     }
       
   498     
       
   499 // ---------------------------------------------------------------------------
       
   500 // Sets text.
       
   501 // ---------------------------------------------------------------------------
       
   502 //
       
   503 EXPORT_C void CAlfTextVisual::SetTextL(const TDesC& aText)
       
   504     {
       
   505 #ifdef ALF_RASTER_TEXT
       
   506     if (!iTextVisualData->iText || aText.Compare(*iTextVisualData->iText))
       
   507         {
       
   508 		// Store the text into a temp buffer.
       
   509         HBufC* newBuffer = aText.AllocL();
       
   510         delete iTextVisualData->iText;
       
   511         iTextVisualData->iText = newBuffer;
       
   512         UpdateMesh();
       
   513         }
       
   514 #else
       
   515     // Store the text into a temp buffer.
       
   516     HBufC* newBuffer = aText.AllocLC();
       
   517     
       
   518     TPtrC8 ptr(reinterpret_cast<const TUint8 *>(aText.Ptr()), aText.Length()*2);
       
   519     TBuf8<1> dum;
       
   520     
       
   521     TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualSetText, ptr, dum);
       
   522     if ( err )
       
   523         {
       
   524         __ALFLOGSTRING1( "CAlfTextVisual::SetTextL leave error %d", err )
       
   525         User::Leave( err );    
       
   526         }
       
   527     
       
   528     // Everything's OK. Switch the internal text buffer.
       
   529     CleanupStack::Pop( newBuffer );
       
   530     delete iTextVisualData->iText;
       
   531     iTextVisualData->iText = newBuffer;
       
   532 #endif
       
   533     }
       
   534   
       
   535 // ---------------------------------------------------------------------------
       
   536 // Gets text.
       
   537 // ---------------------------------------------------------------------------
       
   538 //  
       
   539 EXPORT_C const TDesC& CAlfTextVisual::Text() const
       
   540     {
       
   541     if ( iTextVisualData && iTextVisualData->iText )
       
   542         {
       
   543         return *iTextVisualData->iText;
       
   544         }
       
   545     return KNullDesC();
       
   546     }
       
   547   
       
   548 // ---------------------------------------------------------------------------
       
   549 // Sets style.
       
   550 // ---------------------------------------------------------------------------
       
   551 //  
       
   552 EXPORT_C void CAlfTextVisual::SetStyle(
       
   553         TAlfPreconfiguredTextStyle aStyle, 
       
   554         TAlfBackgroundType aBackgroundType )
       
   555     {
       
   556 #ifdef ALF_RASTER_TEXT
       
   557     iTextVisualData->iTextStyle = Env().TextStyleManager().SwitchTextStyle(aStyle, this);
       
   558     iTextVisualData->iTextStyleId = aBackgroundType; // zero warnings, right
       
   559     iTextVisualData->iTextStyleId = aStyle;
       
   560     UpdateMesh();
       
   561 #else
       
   562     TInt2 params(aStyle, aBackgroundType);
       
   563     TPckgC<TInt2> buf(params);
       
   564     
       
   565     TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetStyle, buf);
       
   566 
       
   567     if ( err != KErrNone )
       
   568         {
       
   569         __ALFLOGSTRING1( "CAlfTextVisual::SetStyle ignore error %d", err )
       
   570         } 
       
   571 #endif
       
   572     }
       
   573     
       
   574 // ---------------------------------------------------------------------------
       
   575 // Sets style.
       
   576 // ---------------------------------------------------------------------------
       
   577 //  
       
   578 EXPORT_C void CAlfTextVisual::SetTextStyle( TInt aTextStyleId )
       
   579     {   
       
   580 #ifdef ALF_RASTER_TEXT
       
   581     if(!iTextVisualData->iTextStyle || iTextVisualData->iTextStyleId != aTextStyleId)
       
   582         {
       
   583         iTextVisualData->iTextStyle = Env().TextStyleManager().SwitchTextStyle(aTextStyleId, this);
       
   584         iTextVisualData->iTextStyleId = aTextStyleId;
       
   585         UpdateMesh();
       
   586         }
       
   587 #else
       
   588     // Convert the text style id from client domain to session domain.
       
   589     CAlfTextStyle* textStyle = Env().TextStyleManager().TextStyle(aTextStyleId);
       
   590     TPckgC<TInt> buf(textStyle->Comms()->Identifier());
       
   591     TBuf8<1> dum;	
       
   592 	    
       
   593     TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualSetTextStyle, buf, dum);
       
   594 
       
   595     if ( err != KErrNone )
       
   596         {
       
   597         __ALFLOGSTRING1( "CAlfTextVisual::SetTextStyle ignore error %d", err )
       
   598         }     
       
   599     else
       
   600         {
       
   601         // once we know that it's been set successfully, we can cache the client-side id 
       
   602         // on the client-side, for later use
       
   603         iTextVisualData->iTextStyleId = aTextStyleId;
       
   604         }
       
   605 #endif // #ifdef ALF_RASTER_TEXT
       
   606     }
       
   607     
       
   608 // ---------------------------------------------------------------------------
       
   609 // Sets alignment.
       
   610 // ---------------------------------------------------------------------------
       
   611 //      
       
   612 EXPORT_C void CAlfTextVisual::SetAlign( TAlfAlignHorizontal aAlignHorizontal,
       
   613                                         TAlfAlignVertical aAlignVertical)
       
   614     {
       
   615     TInt2 params(aAlignHorizontal, aAlignVertical);
       
   616     TPckgC<TInt2> buf(params);
       
   617 
       
   618     TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetAlign, buf );
       
   619 
       
   620     if ( err != KErrNone )
       
   621         {
       
   622         __ALFLOGSTRING1( "CAlfTextVisual::SetAlign ignore error %d", err )
       
   623         }     
       
   624     }
       
   625     
       
   626 // ---------------------------------------------------------------------------
       
   627 // Sets the line spacing for multiline text visual when the text wraps around.
       
   628 // ---------------------------------------------------------------------------
       
   629 //      
       
   630 EXPORT_C void CAlfTextVisual::SetLineSpacing(TInt aLineSpacing, 
       
   631                                              TLineSpacingUnits aUnits)
       
   632     {
       
   633 #ifdef ALF_RASTER_TEXT
       
   634     iTextVisualData->iLineSpacing = aLineSpacing;
       
   635     iTextVisualData->iLineSpacingUnit = aUnits;   
       
   636     if (iTextVisualData->iMesh->Lines() > 1)
       
   637         {
       
   638         UpdateMesh();    
       
   639         }    
       
   640 #else
       
   641     TInt2 params(aLineSpacing, aUnits);
       
   642     TPckgC<TInt2> buf(params);
       
   643 
       
   644     TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetLineSpacing, buf );
       
   645 
       
   646     if ( err != KErrNone )
       
   647         {
       
   648         __ALFLOGSTRING1( "CAlfTextVisual::SetAlign ignore error %d", err )
       
   649         }     
       
   650 #endif
       
   651     }
       
   652 
       
   653 // ---------------------------------------------------------------------------
       
   654 // 
       
   655 // ---------------------------------------------------------------------------
       
   656 //      
       
   657 EXPORT_C TSize CAlfTextVisual::TextExtents() const
       
   658     {
       
   659 #ifdef ALF_RASTER_TEXT
       
   660     TSize size( 0, 0 );    
       
   661     if( Text().Length() != 0 )
       
   662         {
       
   663         TRAP_IGNORE(size = iTextVisualData->iTextStyle->LineExtentsL(Text()))
       
   664         }
       
   665         
       
   666     return size;
       
   667 #else
       
   668     if( Text().Length() == 0 )
       
   669         {
       
   670         return TSize( 0, 0 );
       
   671         }
       
   672 
       
   673     TBufC8<1> inDum;
       
   674     TSize size;
       
   675     TPckg<TSize> outBuf(size);
       
   676     
       
   677     TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualTextExtents, inDum, outBuf);
       
   678     
       
   679     if ( err != KErrNone )
       
   680         {
       
   681         __ALFLOGSTRING1( "CAlfTextVisual::TextExtents ignore error %d", err )
       
   682         } 
       
   683         
       
   684     return size;
       
   685 #endif
       
   686     }
       
   687 
       
   688 // ---------------------------------------------------------------------------
       
   689 // 
       
   690 // ---------------------------------------------------------------------------
       
   691 //      
       
   692 EXPORT_C TRect CAlfTextVisual::SubstringExtents(TUint aStart, TUint aEnd) const
       
   693     {
       
   694 #ifdef ALF_RASTER_TEXT
       
   695     TSize size( 0, 0 );    
       
   696     if( Text().Length() != 0 && aStart < aEnd )
       
   697         {
       
   698         TRAP_IGNORE(size = iTextVisualData->iTextStyle->LineExtentsL(Text().Mid(aStart, aEnd-aStart)))
       
   699         }
       
   700         
       
   701     return size;
       
   702 #else
       
   703     if( Text().Length() == 0 )
       
   704         {
       
   705         return TSize( 0, 0 );
       
   706         }
       
   707 
       
   708     TInt2 params(aStart, aEnd);
       
   709     TPckgC<TInt2> inBuf(params);
       
   710     TRect size;
       
   711     TPckg<TRect> outBuf(size);
       
   712     
       
   713     TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualSubstringExtents, inBuf, outBuf);
       
   714     
       
   715     if ( err != KErrNone )
       
   716         {
       
   717         __ALFLOGSTRING1( "CAlfTextVisual::SubstringExtents ignore error %d", err )
       
   718         } 
       
   719         
       
   720     return size;        
       
   721 #endif
       
   722     }
       
   723 
       
   724 // ---------------------------------------------------------------------------
       
   725 // 
       
   726 // ---------------------------------------------------------------------------
       
   727 //      
       
   728 EXPORT_C TAlfPreconfiguredTextStyle CAlfTextVisual::Style()
       
   729     {
       
   730 #ifdef ALF_RASTER_TEXT
       
   731     return (TAlfPreconfiguredTextStyle)TextStyle();        
       
   732 
       
   733 #else
       
   734     TAlfPreconfiguredTextStyle style = EAlfTextStyleNormal;
       
   735     TAlfBackgroundType backgroundType = EAlfBackgroundTypeLight; 
       
   736     TInt2 params(style, backgroundType);
       
   737     TPckg<TInt2> outBuf(params);
       
   738     
       
   739     TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualStyle, KNullDesC8(), outBuf);    
       
   740     
       
   741     if ( err != KErrNone )
       
   742         {
       
   743         __ALFLOGSTRING1( "CAlfTextVisual::Style ignore error %d", err )
       
   744         } 
       
   745         
       
   746     return style;        
       
   747  #endif
       
   748     }
       
   749 
       
   750 // ---------------------------------------------------------------------------
       
   751 // 
       
   752 // ---------------------------------------------------------------------------
       
   753 //      
       
   754 EXPORT_C TInt CAlfTextVisual::TextStyle() const
       
   755     {
       
   756     // use the client-side cache, as this id only makes sense on the client side
       
   757     return iTextVisualData->iTextStyleId;
       
   758     }
       
   759     
       
   760 // ---------------------------------------------------------------------------
       
   761 // 
       
   762 // ---------------------------------------------------------------------------
       
   763 //      
       
   764 EXPORT_C void CAlfTextVisual::SetMaxLineCount(TInt aMaxLineCount)
       
   765     {
       
   766 #ifdef ALF_RASTER_TEXT
       
   767     if (aMaxLineCount != iTextVisualData->iMaxLineCount )
       
   768         {
       
   769         iTextVisualData->iMaxLineCount = aMaxLineCount;
       
   770         if (iTextVisualData->iMesh->Lines() > aMaxLineCount)
       
   771             {
       
   772             UpdateMesh();
       
   773             }
       
   774         }
       
   775  
       
   776 #else
       
   777     TPckgC<TInt> inBuf(aMaxLineCount);    
       
   778     TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetMaxLineCount,  inBuf);     
       
   779         
       
   780     if ( err != KErrNone )
       
   781         {
       
   782         __ALFLOGSTRING1( "CAlfTextVisual::SetMaxLineCount ignore error %d", err )
       
   783         }        
       
   784 #endif
       
   785     }
       
   786     
       
   787 // ---------------------------------------------------------------------------
       
   788 // 
       
   789 // ---------------------------------------------------------------------------
       
   790 //      
       
   791 EXPORT_C TInt CAlfTextVisual::MaxLineCount() const
       
   792     {
       
   793 #ifdef ALF_RASTER_TEXT
       
   794     return iTextVisualData->iMaxLineCount;
       
   795 #else
       
   796     TBufC8<1> inDum;
       
   797     TInt value = 0;
       
   798     TPckg<TInt> outBuf(value);    
       
   799     TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualMaxLineCount, inDum, 
       
   800         outBuf);   
       
   801     
       
   802     if ( err != KErrNone )
       
   803         {
       
   804         __ALFLOGSTRING1( "CAlfTextVisual::MaxLineCount ignore error %d", err )
       
   805         }     
       
   806          
       
   807     return value;                
       
   808 #endif
       
   809     }
       
   810     
       
   811 // ---------------------------------------------------------------------------
       
   812 // 
       
   813 // ---------------------------------------------------------------------------
       
   814 //      
       
   815 
       
   816 EXPORT_C CAlfTextVisual::TLineWrap CAlfTextVisual::Wrapping() const
       
   817     {
       
   818 #ifdef ALF_RASTER_TEXT
       
   819 	return (CAlfTextVisual::TLineWrap)iTextVisualData->iWrappingMode;      
       
   820 #else
       
   821     TBufC8<1> inDum;
       
   822     TLineWrap value = ELineWrapTruncate;
       
   823     TPckg<TLineWrap> outBuf(value);    
       
   824     TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualWrapping, inDum, 
       
   825         outBuf);    
       
   826         
       
   827     if ( err != KErrNone )
       
   828         {
       
   829         __ALFLOGSTRING1( "CAlfTextVisual::Wrapping ignore error %d", err )
       
   830         }   
       
   831         
       
   832     return value;                        
       
   833 #endif
       
   834     }
       
   835     
       
   836 // ---------------------------------------------------------------------------
       
   837 // 
       
   838 // ---------------------------------------------------------------------------
       
   839 //      
       
   840 EXPORT_C void CAlfTextVisual::SetWrapping(CAlfTextVisual::TLineWrap aWrap)
       
   841     {
       
   842 #ifdef ALF_RASTER_TEXT
       
   843     if(iTextVisualData->iWrappingMode != (TInt)aWrap)
       
   844         {
       
   845         iTextVisualData->iWrappingMode = (TInt)aWrap;
       
   846         UpdateMesh();
       
   847         }
       
   848 #else
       
   849     TPckg<TLineWrap> inBuf(aWrap);    
       
   850     TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetWrapping, inBuf ); 
       
   851         
       
   852     if ( err != KErrNone )
       
   853         {
       
   854         __ALFLOGSTRING1( "CAlfTextVisual::SetWrapping ignore error %d", err )
       
   855         }     
       
   856 #endif
       
   857     }
       
   858     
       
   859 // ---------------------------------------------------------------------------
       
   860 // 
       
   861 // ---------------------------------------------------------------------------
       
   862 //      
       
   863 EXPORT_C TAlfBackgroundType CAlfTextVisual::BackgroundType()
       
   864     {
       
   865 #ifdef ALF_RASTER_TEXT
       
   866     TAlfBackgroundType backgroundType = EAlfBackgroundTypeLight;          
       
   867     return backgroundType;   
       
   868 #else
       
   869     TAlfPreconfiguredTextStyle style = EAlfTextStyleNormal;
       
   870     TAlfBackgroundType backgroundType = EAlfBackgroundTypeLight; 
       
   871     TInt2 params(style, backgroundType);
       
   872     TPckg<TInt2> outBuf(params);
       
   873     
       
   874     TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualStyle, KNullDesC8(), outBuf);    
       
   875         
       
   876     if ( err != KErrNone )
       
   877         {
       
   878         __ALFLOGSTRING1( "CAlfTextVisual::BackgroundType ignore error %d", err )
       
   879         }  
       
   880          
       
   881     return backgroundType;                                
       
   882 #endif
       
   883     }
       
   884     
       
   885 // ---------------------------------------------------------------------------
       
   886 // 
       
   887 // ---------------------------------------------------------------------------
       
   888 //      
       
   889 EXPORT_C TAlfTimedValue CAlfTextVisual::ShadowOpacity()
       
   890     {
       
   891     if ( DropShadowHandler() )
       
   892         {
       
   893         return 1.f; // not the real value...
       
   894         }   
       
   895         
       
   896     return TAlfTimedValue(0);                                        
       
   897     }
       
   898 
       
   899 // ---------------------------------------------------------------------------
       
   900 // 
       
   901 // ---------------------------------------------------------------------------
       
   902 //      
       
   903 EXPORT_C void CAlfTextVisual::SetShadowOpacity(const TAlfTimedValue& aShadowOpacity)
       
   904     {
       
   905     TRAPD( err, EnableDropShadowL() );
       
   906     
       
   907     if ( err != KErrNone )
       
   908         {
       
   909         __ALFLOGSTRING1( "CAlfTextVisual::SetShadowOpacity ignore error %d", err )
       
   910         return;
       
   911         }      
       
   912         
       
   913     DropShadowHandler()->SetOpacity( aShadowOpacity );    
       
   914     }
       
   915     
       
   916 // ---------------------------------------------------------------------------
       
   917 // 
       
   918 // ---------------------------------------------------------------------------
       
   919 //      
       
   920 EXPORT_C void CAlfTextVisual::SetColor(TRgb aColor)
       
   921     {
       
   922     TAlfTextVisualFontColorParams params;
       
   923     params.iColor = aColor;
       
   924     params.iId = KAknsIIDNone; // This will be ignored in the serverside
       
   925     params.iIndex = 0; // This will be ignored in the serverside
       
   926     
       
   927     TPckg<TAlfTextVisualFontColorParams> inBuf(params);    
       
   928     TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetColor, inBuf);  
       
   929         
       
   930     if ( err != KErrNone )
       
   931         {
       
   932         __ALFLOGSTRING1( "CAlfTextVisual::SetColor1 ignore error %d", err )
       
   933         }            
       
   934     }
       
   935     
       
   936 // ---------------------------------------------------------------------------
       
   937 // 
       
   938 // ---------------------------------------------------------------------------
       
   939 //      
       
   940 EXPORT_C void CAlfTextVisual::SetColor(const TAknsItemID& aId,const TInt aIndex)
       
   941     {
       
   942     TAlfTextVisualFontColorParams params;
       
   943     params.iColor = KRgbBlack; // This will be ignored in the serverside
       
   944     params.iId = aId;
       
   945     params.iIndex = aIndex;
       
   946     
       
   947     TPckg<TAlfTextVisualFontColorParams> inBuf(params);    
       
   948     TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetColor, inBuf);  
       
   949         
       
   950     if ( err != KErrNone )
       
   951         {
       
   952         __ALFLOGSTRING1( "CAlfTextVisual::SetColor1 ignore error %d", err )
       
   953         }            
       
   954     }
       
   955 
       
   956 // ---------------------------------------------------------------------------
       
   957 // 
       
   958 // ---------------------------------------------------------------------------
       
   959 //   
       
   960 EXPORT_C void CAlfTextVisual::EnableShadow(TBool aDoEnable)
       
   961     {
       
   962     TRAPD( err, EnableDropShadowL( aDoEnable ) );
       
   963         
       
   964     if ( err != KErrNone )
       
   965         {
       
   966         __ALFLOGSTRING1( "CAlfTextVisual::EnableShadow ignore error %d", err )
       
   967         }      
       
   968     }
       
   969 
       
   970 // ---------------------------------------------------------------------------
       
   971 // Place holder from CAlfVisual
       
   972 // ---------------------------------------------------------------------------
       
   973 //     
       
   974 EXPORT_C void CAlfTextVisual::RemoveAndDestroyAllD()
       
   975     {
       
   976     CAlfVisual::RemoveAndDestroyAllD();
       
   977     }
       
   978   
       
   979 // ---------------------------------------------------------------------------
       
   980 // Place holder from CAlfVisual
       
   981 // ---------------------------------------------------------------------------
       
   982 //  
       
   983 EXPORT_C void CAlfTextVisual::UpdateChildrenLayout(TInt aTransitionTime )
       
   984     {
       
   985     CAlfVisual::UpdateChildrenLayout( aTransitionTime );
       
   986     }
       
   987   
       
   988 // ---------------------------------------------------------------------------
       
   989 // Place holder from CAlfVisual
       
   990 // ---------------------------------------------------------------------------
       
   991 //  
       
   992 EXPORT_C CAlfVisual* CAlfTextVisual::FindTag(const TDesC8& aTag)
       
   993     {
       
   994     return CAlfVisual::FindTag( aTag );
       
   995     }
       
   996 
       
   997 // ---------------------------------------------------------------------------
       
   998 // Place holder from CAlfVisual
       
   999 // ---------------------------------------------------------------------------
       
  1000 //  
       
  1001 EXPORT_C void CAlfTextVisual::DoRemoveAndDestroyAllD()
       
  1002     {
       
  1003     CAlfVisual::DoRemoveAndDestroyAllD();
       
  1004     }
       
  1005     
       
  1006 // ---------------------------------------------------------------------------
       
  1007 //  future proofing  
       
  1008 // ---------------------------------------------------------------------------
       
  1009 //  
       
  1010 EXPORT_C void CAlfTextVisual::PropertyOwnerExtension(const TUid& aExtensionUid, TAny** aExtensionParams)
       
  1011     {
       
  1012     CAlfVisual::PropertyOwnerExtension(aExtensionUid,aExtensionParams);
       
  1013     }
       
  1014     
       
  1015 // ---------------------------------------------------------------------------
       
  1016 // DEPRECATED! Set Color for Visual using String table and Index
       
  1017 // ---------------------------------------------------------------------------
       
  1018 //
       
  1019 EXPORT_C void CAlfTextVisual::SetColor(const TDesC& /*aTextColorTable*/,const TDesC& /*aColorIndex*/)
       
  1020     {   	     		   
       
  1021     }
       
  1022 
       
  1023 // ---------------------------------------------------------------------------
       
  1024 // 
       
  1025 // ---------------------------------------------------------------------------
       
  1026 // 
       
  1027 EXPORT_C void CAlfTextVisual::SetOffset(const TAlfTimedPoint& aOffset)
       
  1028     {
       
  1029     TPckg<TAlfTimedPoint> inBuf(aOffset);    
       
  1030     TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetOffset, inBuf);  
       
  1031         
       
  1032     if ( err != KErrNone )
       
  1033         {
       
  1034         __ALFLOGSTRING1( "CAlfTextVisual::SetOffset ignore error %d", err )
       
  1035         }                    
       
  1036     }
       
  1037      
       
  1038 // ---------------------------------------------------------------------------
       
  1039 // 
       
  1040 // ---------------------------------------------------------------------------
       
  1041 // 
       
  1042 EXPORT_C TAlfTimedPoint CAlfTextVisual::Offset() const
       
  1043     {
       
  1044     TBufC8<1> inDum;
       
  1045     TAlfTimedPoint value;
       
  1046     TPckg<TAlfTimedPoint> outBuf(value);    
       
  1047     TInt err = Comms()->DoSynchronousCmd(EAlfTextVisualOffset, inDum, 
       
  1048         outBuf);    
       
  1049         
       
  1050     if ( err != KErrNone )
       
  1051         {
       
  1052         __ALFLOGSTRING1( "CAlfTextVisual::Offset ignore error %d", err )
       
  1053         }  
       
  1054         
       
  1055     return value;                                                
       
  1056     }
       
  1057 
       
  1058 #ifdef ALF_RASTER_TEXT
       
  1059 // for convenience
       
  1060 void DoLocalHighlightConversionL(TInt aStart, TInt aEnd, HBufC* aText, CAlfTextStyle* aStyle, TSize& aStartPos, TSize& aEndPos)
       
  1061     {
       
  1062     aStartPos = aStyle->LineExtentsL(aText->Left(aStart));
       
  1063     aEndPos = aStyle->LineExtentsL(aText->Left(aEnd));
       
  1064     }
       
  1065 #endif
       
  1066 // ---------------------------------------------------------------------------
       
  1067 // 
       
  1068 // ---------------------------------------------------------------------------
       
  1069 //      
       
  1070 EXPORT_C void CAlfTextVisual::SetHighlightRange(TInt aStart, TInt aEnd, TRgb& aHighlightColor, TRgb& aHighlightTextColor)
       
  1071     {
       
  1072 #ifdef ALF_RASTER_TEXT
       
  1073     // ToDO: convert to mesh coordinates    
       
  1074     CAlfTextStyle* style = iTextVisualData->iTextStyle;
       
  1075     if (!style || Text().Length() == 0 || // has not been rasterized ever or text lenght is zero
       
  1076         (aStart < 0) || (aStart > Text().Length()) || (aEnd < 0) || (aStart >= aEnd) || (aEnd > Text().Length()))
       
  1077                 
       
  1078         {
       
  1079         return;
       
  1080         }
       
  1081     
       
  1082     TSize startPos, endPos;
       
  1083     TRAPD(err, DoLocalHighlightConversionL(aStart, aEnd, iTextVisualData->iText, style, startPos, endPos))
       
  1084     if (!err)
       
  1085         {    
       
  1086         TAlfTextVisualSetHighlightRangeParams params;
       
  1087         params.iStart = startPos.iWidth;
       
  1088         params.iEnd = endPos.iWidth;
       
  1089         params.iHighlightColor = aHighlightColor;
       
  1090         params.iHighlightTextColor = aHighlightTextColor;
       
  1091             
       
  1092         TPckg<TAlfTextVisualSetHighlightRangeParams> inBuf(params);    
       
  1093         err = Comms()->DoCmdNoReply(EAlfTextVisualSetHighlightRange, inBuf);  
       
  1094             
       
  1095         if ( err != KErrNone )
       
  1096             {
       
  1097             __ALFLOGSTRING1( "CAlfTextVisual::SetHighlightRange ignore error %d", err )
       
  1098             }            
       
  1099         }
       
  1100     
       
  1101     
       
  1102 #else
       
  1103     TAlfTextVisualSetHighlightRangeParams params;
       
  1104     params.iStart = aStart;
       
  1105     params.iEnd = aEnd;
       
  1106     params.iHighlightColor = aHighlightColor;
       
  1107     params.iHighlightTextColor = aHighlightTextColor;
       
  1108         
       
  1109     TPckg<TAlfTextVisualSetHighlightRangeParams> inBuf(params);    
       
  1110     TInt err = Comms()->DoCmdNoReply(EAlfTextVisualSetHighlightRange, inBuf);  
       
  1111         
       
  1112     if ( err != KErrNone )
       
  1113         {
       
  1114         __ALFLOGSTRING1( "CAlfTextVisual::SetHighlightRange ignore error %d", err )
       
  1115         }            
       
  1116 #endif
       
  1117     }