uiacceltk/hitchcock/coretoolkit/inc/HuiRasterizedTextMesh.h
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006-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:   Definition of HuiRasterizedTextMesh. CHuiRasterizedTextMesh 
       
    15 *                stores a rasterized bitmap version of a text string.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef __HUIRASTERIZEDTEXTMESH_H__
       
    22 #define __HUIRASTERIZEDTEXTMESH_H__
       
    23 
       
    24 #include <e32cmn.h>
       
    25 #include <AknPictographDrawerInterface.h>
       
    26 
       
    27 #include "uiacceltk/HuiTextMesh.h"
       
    28 #include "uiacceltk/HuiRealPoint.h"
       
    29 #include "uiacceltk/HuiImage.h"
       
    30 #include "uiacceltk/HuiGc.h"
       
    31 #include "uiacceltk/HuiTexture.h"
       
    32 
       
    33 class CFont;
       
    34 class CFbsBitmap;
       
    35 class CAknPictographInterface;
       
    36 
       
    37 /**
       
    38  * CHuiRasterizedTextMesh is a concrete implementation of a CHuiTextMesh.
       
    39  * CHuiRasterizedTextMesh uses Symbian's BITGDI text drawing routines and Avkon
       
    40  * BiDi text utilities to draw text onto a bitmap. The bitmap is then copied
       
    41  * onto a CHuiTexture and drawn with CHuiGc. This makes CHuiRasterizedTextMesh
       
    42  * independent of the underlying rendering plugin. Multiple lines of text are
       
    43  * supported.
       
    44  */
       
    45 NONSHARABLE_CLASS(CHuiRasterizedTextMesh) : public CHuiTextMesh, public MHuiTextureContentObserver
       
    46     {
       
    47 public:
       
    48 
       
    49     /* Constructors and destructors. */
       
    50 
       
    51     /**
       
    52      * Constructs a new rasterized text mesh.
       
    53      */
       
    54     IMPORT_C static CHuiRasterizedTextMesh* NewL();
       
    55 
       
    56     /**
       
    57      * Constructs a new rasterized text mesh and leaves it on the cleanup stack.
       
    58      */
       
    59     static CHuiRasterizedTextMesh* NewLC();
       
    60 
       
    61     /**
       
    62      * Destructor.
       
    63      */
       
    64     virtual ~CHuiRasterizedTextMesh();
       
    65 
       
    66 
       
    67     /* Methods. */
       
    68 
       
    69     /**
       
    70      * Resets the contents of the text mesh.
       
    71      */
       
    72     virtual void Reset();
       
    73 
       
    74     /**
       
    75      * Draws the text mesh.
       
    76      *
       
    77      * @param aGc             Graphics context.
       
    78      * @param aShadowOpacity  Opacity of shadows.
       
    79      */
       
    80     virtual void Draw(CHuiGc& aGc, TReal32 aShadowOpacity = 1.0) const __SOFTFP;
       
    81 
       
    82     void BuildPictographsL();
       
    83 
       
    84     virtual void ExpandRectWithShadow(TRect& aRect) const;
       
    85 
       
    86 protected:
       
    87 
       
    88     /* Constructors. */
       
    89 
       
    90     /**
       
    91      * Default constructor.
       
    92      */
       
    93     CHuiRasterizedTextMesh();
       
    94 
       
    95     /* Methods. */
       
    96 
       
    97     void ResetLines();
       
    98     void ResetPictographLines();
       
    99 
       
   100     TBool IsMaxLineCountReached() const;
       
   101 
       
   102     /**
       
   103      * Updates the mesh and the extents. Both text and font must be set
       
   104      * when this is called.
       
   105      * 
       
   106      * @param aRasterize Set this to ETrue if text is to be rendered. Set to
       
   107      *                   EFalse if you only need to calculate text extents.
       
   108      */
       
   109     virtual void BuildL(TBool aRasterize);
       
   110 
       
   111     /**
       
   112      * Draws the lines of the text mesh.
       
   113      */
       
   114     void DrawLines(CHuiGc& aGc, const THuiRealPoint& aOffset,
       
   115                    THuiAlignHorizontal aLineAlignment, TReal32 aShadowOpacity) const;
       
   116 
       
   117 
       
   118     /**
       
   119      * Draws the pictographlines of the text mesh.
       
   120      */
       
   121     void DrawPictographLines(CHuiGc& aGc, const THuiRealPoint& aOffset,
       
   122                    THuiAlignHorizontal aLineAlignment) const;
       
   123 
       
   124 
       
   125     /* Implementation of MHuiTextureContentObserver. */
       
   126 
       
   127     void TextureContentUploaded(CHuiTexture& aTexture);
       
   128 
       
   129     void TextureContentReleased(CHuiTexture& aTexture);
       
   130 
       
   131     void RestoreTextureContentL(CHuiTexture& aTexture);
       
   132 
       
   133 
       
   134 private:
       
   135 
       
   136     /** Each line of rasterized text is stored in an SLine. */
       
   137     struct SRasterizedLine
       
   138         {
       
   139         SRasterizedLine()
       
   140             {
       
   141             iTexture = NULL;
       
   142             iGap = 0;
       
   143             }
       
   144         /** Texture that holds the rasterized version of a text line. The
       
   145             size of the texture determines the extents of the line. */
       
   146         CHuiTexture* iTexture;
       
   147         
       
   148         /** Extra gap to the next line in pixels. Not applied to the last
       
   149             line. */
       
   150         TInt iGap;
       
   151         };
       
   152 
       
   153 protected:
       
   154 
       
   155     /**
       
   156      * Rasterizes a single line of text using the defined text style.
       
   157      * The result is a new line texture.
       
   158      *
       
   159      * @param aTextLine  The line of text to rasterize.
       
   160      * @param aLine		 SRasterizedLine entry that will
       
   161      *                   store the rasterized line content.
       
   162      *
       
   163      * @return  <code>ETrue</code>, if the maximum number of lines has
       
   164      *          not been reached (rasterization was successful);
       
   165      *          otherwise <code>EFalse</code>. BuildL() is stopped
       
   166      *          when this method returns EFalse.
       
   167      */
       
   168     TBool RasterizeLineL(const TDesC& aTextLine, SRasterizedLine & aLine);
       
   169 
       
   170     /**
       
   171      * Rasterizes a single line of pictographs using the specified font.
       
   172      * The result is a new line texture.
       
   173      *
       
   174      * @param aTextLine  The line of text to rasterize.
       
   175      * @param aFont      Font to be used in rasterization.
       
   176      * @param aLine		 SRasterizedLine entry that will
       
   177      *                   store the rasterized line content.
       
   178      *
       
   179      * @return  <code>ETrue</code>, if the maximum number of lines has
       
   180      *          not been reached (rasterization was successful);
       
   181      *          otherwise <code>EFalse</code>. BuildL() is stopped
       
   182      *          when this method returns EFalse.
       
   183      */
       
   184     TBool RasterizePictographLineL(const TDesC& aTextLine, CFont* aFont, SRasterizedLine & aLine);
       
   185 
       
   186     /** 
       
   187      * Sets the pictograph interface, ownership is NOT transferred.
       
   188      *
       
   189      * @param aExtents  Width and height of the text mesh.
       
   190      */
       
   191     virtual void InitPictographsL(CAknPictographInterface* aInterface);
       
   192 
       
   193     /**
       
   194      * Internal utility for using pre-rasterized mesh
       
   195      */
       
   196     virtual void UpdateMeshL(const TDesC8& aBuffer);
       
   197     
       
   198 private:
       
   199     
       
   200     void DoBuildL(TInt aRasterizeFlags);    
       
   201 
       
   202 private:
       
   203 
       
   204     /** Rasterized lines. 
       
   205      * @see SRasterizedLine.
       
   206      */
       
   207     RArray<SRasterizedLine> iLines;
       
   208     
       
   209     /** Rasterized line pictographs.
       
   210      * @see SRasterizedLine.
       
   211      */
       
   212     RArray<SRasterizedLine> iPictographLines;
       
   213 
       
   214     /** Bitmap onto which Symbian BITGDI draws pictographs. */
       
   215     CFbsBitmap* iPictographBitmap;
       
   216 
       
   217     TBool iUsingPreRasterizedMesh;
       
   218     };
       
   219 
       
   220 
       
   221 #endif // __HUIRASTERIZEDTEXTMESH_H__
       
   222