svgtopt/SVG/SVGImpl/inc/SVGImageElementImpl.h
changeset 46 88edb906c587
equal deleted inserted replaced
-1:000000000000 46:88edb906c587
       
     1 /*
       
     2 * Copyright (c) 2003 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:  SVG Implementation header file
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef _INC_CSVGIMAGEELEMENTIMPL_
       
    20 #define _INC_CSVGIMAGEELEMENTIMPL_
       
    21 
       
    22 #include <imageconversion.h>
       
    23 
       
    24 #include "SVGElementImpl.h"
       
    25 #include "GfxRectangle2D.h"
       
    26 #include "SVGRequestObserver.h"
       
    27 
       
    28 #include "SVGImageLoadingObserver.h" // MSVGImageLoadingObserver
       
    29 
       
    30 class   CFbsBitmap;
       
    31 class   CSvgDocumentImpl;
       
    32 class   MXmlDocument;
       
    33 
       
    34 /**
       
    35  * This class is for internal use to receive notification from other
       
    36  * <image> elements.  This case is when an <image> element is Cloned
       
    37  * by a <use> element
       
    38  */
       
    39 class MSvgImageElementListener
       
    40 {
       
    41     public:
       
    42         /**
       
    43          * Inform the listener that the image is decoded and update its
       
    44          * bitmap pointers
       
    45          *
       
    46          * @since s60 3.0
       
    47          * @return : None.
       
    48          */
       
    49         virtual void BitmapDecoded( CFbsBitmap* aBitmap, CFbsBitmap* aMask ) = 0;
       
    50         
       
    51         /**
       
    52          * Inform the listener to reset its reference to the referred element
       
    53          * @since s60 3.1
       
    54          * @return : None.
       
    55          */
       
    56         virtual void ResetReference() = 0;
       
    57 };
       
    58 
       
    59 /**
       
    60  * Class description goes here.
       
    61  *
       
    62  *  @lib SVGEngine.lib
       
    63  *  @since 1.0
       
    64  */
       
    65 class CSvgImageElementImpl : public CSvgElementImpl,
       
    66                              public MSVGImageLoadingObserver,
       
    67                              public MSvgImageElementListener
       
    68 
       
    69     {
       
    70     public:
       
    71 
       
    72         /**
       
    73          * Helper class to load images asynchronously.  To load an image:
       
    74          * 1.  Instantiate CSvgImageLoaderUtil with NewL/NewLC, passing
       
    75          *     a MSVGImageLoadingObserver, which implements the 'ImageLoadingCompleted'
       
    76          *     method, and a file name.  This method is called by the CSvgImageLoaderUtil
       
    77          *     object when loading is complete.  The error code passed-in will indicate
       
    78          *     a successful load or not.
       
    79          * 2.  Set the output mode with 'SetDisplayMode' the default is EColor64K, see
       
    80          *     TDisplayMode for more options.
       
    81          * 3.  Call one of the 'RequestForImageL' method.
       
    82          *
       
    83          *  @lib SVGEngine.lib
       
    84          *  @since 1.0
       
    85          */
       
    86          class CSvgImageLoaderUtil : public CActive
       
    87             {
       
    88             public:
       
    89                 /**
       
    90                  * Constructor
       
    91                  *
       
    92                  * @since 1.0
       
    93                  * @param aObserver : callback object when image loading completes.
       
    94                  * @param aFileHandle : file handle of image to load.
       
    95                  * @param aSyncLoading : Perform Synchronous loading(ETrue) or not
       
    96                  * @return
       
    97                  */
       
    98                 static CSvgImageLoaderUtil* NewL( MSVGImageLoadingObserver* aObserver,
       
    99                                                   RFile& aFileHandle,
       
   100                                                   TBool aSyncLoading );
       
   101 
       
   102                 /**
       
   103                  * Constructor
       
   104                  *
       
   105                  * @since 1.0
       
   106                  * @param aObserver : callback object when image loading completes.
       
   107                  * @param aEncodedData : encode 8-bit data buffer
       
   108                  * @param aSyncLoading : Perform Synchronous loading(ETrue) or not
       
   109                  * @return
       
   110                  */
       
   111                 static CSvgImageLoaderUtil* NewL( MSVGImageLoadingObserver* aObserver,
       
   112                                                   const TDesC8& aEncodedData,
       
   113                                                   TBool aSyncLoading );
       
   114 
       
   115                 /**
       
   116                  * Destructor
       
   117                  *
       
   118                  * @since 1.0
       
   119                  * @return
       
   120                  */
       
   121                 ~CSvgImageLoaderUtil();
       
   122 
       
   123                 /**
       
   124                  * Set the output mode, the default value is EColor64K.
       
   125                  *
       
   126                  * @since 1.0
       
   127                  * @param aDisplayMode : output mode.
       
   128                  * @return
       
   129                  */
       
   130                 void SetDisplayMode( TDisplayMode aDisplayMode );
       
   131 
       
   132                 /**
       
   133                  * Request for the image and size the bitmap to the size of the image.
       
   134                  *
       
   135                  * @since 1.0
       
   136                  * @param aBitmap    : bitmap to store the pixels
       
   137                  * @param aMask      : bitmap to store the Mask pixels
       
   138                  * @param aHasAlpha  : Alpha value indicator, Used to create Mask
       
   139                  * @param aFrameInfo : TFrameInfo structure
       
   140                  * @return
       
   141                  */
       
   142                 void RequestForImageL( CFbsBitmap& aBitmap,
       
   143                                        CFbsBitmap& aMask,
       
   144                                        TBool       aHasAlpha,
       
   145                                        TFrameInfo  aFrameInfo );
       
   146 
       
   147                 /**
       
   148                  * From CActive Handles cancelling of asynchronous requests
       
   149                  *
       
   150                  * @param aBitmap : bitmap to store the pixels
       
   151                  * @since 2.0
       
   152                  */
       
   153                 void DoCancel();
       
   154 
       
   155                 /**
       
   156                  * From CActive Called when asynchronous request is completed
       
   157                  *
       
   158                  * @since 2.0
       
   159                  */
       
   160                 void RunL();
       
   161 
       
   162                 /**
       
   163                  * From CActive Called when asynchronous request is completed
       
   164                  *
       
   165                  * @since 2.0
       
   166                  * @param aError : error code
       
   167                  */
       
   168                 TInt RunError( TInt aError );
       
   169 
       
   170                 /**
       
   171          		 * Return wether image decoding is synchronous or asynchronous.
       
   172                  * @since 3.1
       
   173                  * @param None
       
   174                  * @return ETrue if image decoding is synchrounous else EFalse
       
   175                  */
       
   176                  TBool               IsSynchronousLoading();
       
   177                  
       
   178                 /**
       
   179                  * Returns the FrameInfo of Image. Function is called once the Decoder is
       
   180                  * created.
       
   181                  * @since 3.2
       
   182                  * @param None
       
   183                  * @return TFrameInfo structure.
       
   184                  */
       
   185                  
       
   186                  TFrameInfo          GetFrameInfo();
       
   187             private:
       
   188                 /**
       
   189                  * Constructor
       
   190                  *
       
   191                  * @since 1.0
       
   192                  */
       
   193                 CSvgImageLoaderUtil();
       
   194 
       
   195                 /**
       
   196                  * Construct this object with leavable calls.
       
   197                  *
       
   198                  * @since 1.0
       
   199                  * @param aObserver : callback object when image loading completes.
       
   200                  * @param aFileHandle : file handle of image to load.
       
   201                  * @param aSyncLoading : Perform Synchronous loading(ETrue) or not
       
   202                  */
       
   203                 void ConstructL( MSVGImageLoadingObserver* aObserver, 
       
   204                     RFile& aFileHandle,
       
   205                     TBool aSyncLoading );
       
   206 
       
   207                 /**
       
   208                  * Phase two of construction.
       
   209                  *
       
   210                  * @since 1.0
       
   211                  * @param aObserver : callback object when image loading completes.
       
   212                  * @param aEncodedData : encode 8-bit data buffer
       
   213                  * @param aSyncLoading : Perform Synchronous loading(ETrue) or not
       
   214                  */
       
   215                 void ConstructL( MSVGImageLoadingObserver* aObserver,
       
   216                                  const TDesC8& aEncodedData,
       
   217                                  TBool aSyncLoading );
       
   218 
       
   219 
       
   220             private:
       
   221                 MSVGImageLoadingObserver* iObserver;
       
   222                 CImageDecoder*  iImageDecoder;
       
   223                 TDisplayMode iDisplayMode;
       
   224                 CActiveSchedulerWait* iActiveSchedulerWait;
       
   225                 TBool iIsSyncLoading;
       
   226                 HBufC8* iImageByteData;
       
   227             };
       
   228 
       
   229     public:
       
   230         /**
       
   231          * Need method description
       
   232          *
       
   233          * @since 1.0
       
   234          * @param
       
   235          * @return
       
   236          */
       
   237         MXmlElement*        CloneL(MXmlElement* aParentElement);
       
   238 
       
   239         /**
       
   240          * Need method description
       
   241          *
       
   242          * @since 1.0
       
   243          * @param
       
   244          * @return
       
   245          */
       
   246         static CSvgImageElementImpl*NewL(  const TUint8 aElemID,
       
   247                                       CSvgDocumentImpl* aDoc );
       
   248 
       
   249         /**
       
   250          * Need method description
       
   251          *
       
   252          * @since 1.0
       
   253          * @param
       
   254          * @return
       
   255          */
       
   256         static CSvgImageElementImpl*NewLC(  const TUint8 aElemID,
       
   257                                        CSvgDocumentImpl* aDoc );
       
   258     private:
       
   259         /**
       
   260          * Need method description
       
   261          *
       
   262          * @since 1.0
       
   263          * @param
       
   264          * @return
       
   265          */
       
   266          void                            ConstructL(  const TUint8 aElemID,
       
   267                                                     CSvgDocumentImpl* aDoc );
       
   268 
       
   269 
       
   270 
       
   271     public:
       
   272 
       
   273         /**
       
   274          * Need method description
       
   275          *
       
   276          * @since 1.0
       
   277          * @param
       
   278          * @return
       
   279          */
       
   280         virtual                         ~CSvgImageElementImpl();
       
   281 
       
   282 
       
   283         /**
       
   284          * Need method description
       
   285          *
       
   286          * @since 1.0
       
   287          * @param
       
   288          * @return
       
   289          */
       
   290         const TDesC&                    Par();
       
   291 
       
   292 		TInt 	CheckRequiredAttributes();
       
   293 		
       
   294         /**
       
   295          * Need method description
       
   296          *
       
   297          * @since 1.0
       
   298          * @param
       
   299          * @return
       
   300          */
       
   301         void                            SetParL( const TDesC& aName );
       
   302 
       
   303         /**
       
   304          * Need method description
       
   305          *
       
   306          * @since 1.0
       
   307          * @param
       
   308          * @return
       
   309          */
       
   310         void                            ImageLoadingCompleted( TInt aErrorStatus );
       
   311 
       
   312         // From SVG DOM
       
   313 
       
   314         /**
       
   315          * Need method description
       
   316          *
       
   317          * @since 1.0
       
   318          * @param
       
   319          * @return
       
   320          */
       
   321         TFloatFixPt                          X();
       
   322 
       
   323         /**
       
   324          * Need method description
       
   325          *
       
   326          * @since 1.0
       
   327          * @param
       
   328          * @return
       
   329          */
       
   330         TFloatFixPt                          Y();
       
   331 
       
   332         /**
       
   333          * Need method description
       
   334          *
       
   335          * @since 1.0
       
   336          * @param
       
   337          * @return
       
   338          */
       
   339         TFloatFixPt                          Width();
       
   340 
       
   341         /**
       
   342          * Need method description
       
   343          *
       
   344          * @since 1.0
       
   345          * @param
       
   346          * @return
       
   347          */
       
   348         TFloatFixPt                          Height();
       
   349 
       
   350         // SVG Implementation
       
   351 
       
   352         /**
       
   353          * Need method description
       
   354          *
       
   355          * @since 1.0
       
   356          * @param
       
   357          * @return
       
   358          */
       
   359         void                            SetWidth( TFloatFixPt aWidth );
       
   360 
       
   361         /**
       
   362          * Need method description
       
   363          *
       
   364          * @since 1.0
       
   365          * @param
       
   366          * @return
       
   367          */
       
   368         void                            SetHeight( TFloatFixPt aHeight );
       
   369 
       
   370         /**
       
   371          * Need method description
       
   372          *
       
   373          * @since 1.0
       
   374          * @param
       
   375          * @return
       
   376          */
       
   377         void                            SetUriL( const TDesC& aUri );
       
   378 
       
   379         /**
       
   380          * Need method description
       
   381          *
       
   382          * @since 1.0
       
   383          * @param
       
   384          * @return
       
   385          */
       
   386         void                            LoadUriL();
       
   387 
       
   388         // From MXmlElement API
       
   389 
       
   390 
       
   391         /**
       
   392          * Need method description
       
   393          *
       
   394          * @since 1.0
       
   395          * @param
       
   396          * @return
       
   397          */
       
   398         TInt                            SetAttributeL( const TDesC& aName,
       
   399                                                        const TDesC& aValue );
       
   400 
       
   401 
       
   402         /**
       
   403          * Need method description
       
   404          *
       
   405          * @since 1.0
       
   406          * @param
       
   407          * @return
       
   408          */
       
   409         TBool                           DrawL( CGfx2dGc* aGc,
       
   410                                                CSvgElementImpl* aElement );
       
   411 
       
   412 
       
   413         /**
       
   414          * Need method description
       
   415          *
       
   416          * @since 1.0
       
   417          * @param
       
   418          * @return
       
   419          */
       
   420         void                            GetBBox( TGfxRectangle2D& aBbox );
       
   421 
       
   422         /**
       
   423          * Need method description
       
   424          *
       
   425          * @since 1.0
       
   426          * @param
       
   427          * @return
       
   428          */
       
   429         virtual void                    GetUnscaledBBox( TGfxRectangle2D& /*aBbox*/ );
       
   430 
       
   431         // From MXmlElementOpt API
       
   432 
       
   433 
       
   434         /**
       
   435          * Need method description
       
   436          *
       
   437          * @since 1.0
       
   438          * @param
       
   439          * @return
       
   440          */
       
   441         TInt                            GetAttributeFloat( const TInt aNameId,
       
   442                                                            TFloatFixPt& aValue );
       
   443 
       
   444         /**
       
   445          * Need method description
       
   446          *
       
   447          * @since 1.0
       
   448          * @param
       
   449          * @return
       
   450          */
       
   451         TInt                            SetAttributeFloatL( const TInt aNameId,
       
   452                                                             const TFloatFixPt aValue );
       
   453 
       
   454 
       
   455         /**
       
   456          * Need method description
       
   457          *
       
   458          * @since 1.0
       
   459          * @param
       
   460          * @return
       
   461          */
       
   462         TInt                            SetAttributeDesL( const TInt aNameId,
       
   463                                                           const TDesC& aValue );
       
   464         /**
       
   465          * Need method description
       
   466          *
       
   467          * @since 1.0
       
   468          * @param
       
   469          * @return
       
   470          */
       
   471                                         CSvgImageElementImpl( CSvgDocumentImpl* aDoc );
       
   472 
       
   473         TInt                GetAttributeDes( const TInt aNameId,
       
   474                                                      TPtrC16& aValue );
       
   475 
       
   476         /**
       
   477          * Return wether an svg element is displayable, such as <rect>, <circle>, or
       
   478          * an abstract element, such as <g>, <animate>.
       
   479          *
       
   480          * @since 1.0
       
   481          * @param None
       
   482          * @return ETrue if element is viewable.
       
   483          */
       
   484         TBool               IsViewable() { return ETrue; }
       
   485 
       
   486         // Adding/Removing listener interested in image decoding notification
       
   487         void AddImageElementListener( MSvgImageElementListener* aListener );
       
   488         void RemoveImageElementListener( MSvgImageElementListener* aListener );
       
   489 
       
   490         // MSvgImageElementListener method
       
   491         void BitmapDecoded( CFbsBitmap* aBitmap, CFbsBitmap* aMask );
       
   492         void ResetReference();
       
   493         
       
   494         void Print( TBool aIsEncodeOn );
       
   495 
       
   496         CFbsBitmap*                 GetBitmap();        
       
   497         
       
   498         void SetBitmap( CFbsBitmap* aBitmap );
       
   499 
       
   500         // Assigned image data for this object to manage delete
       
   501         // after image-decoding or destructing.
       
   502         void AssignImageData( HBufC8* aData );
       
   503 
       
   504         /**
       
   505          * Starts the image decoding. This is the version that accepts 
       
   506          * descriptor data of the image content. Image can be SVG/ any format
       
   507          * supported by CImageDecoder 
       
   508          * @since s60 3.2
       
   509          * @param aImageData Image Data Descriptor
       
   510          * @param aSyncLoading ETrue=Sync Loading
       
   511          * @return TInt errorcode
       
   512          */
       
   513         TInt StartImageDecoding( const TDesC8& aImageData,
       
   514                                  TBool aSyncLoading );
       
   515         
       
   516         /**
       
   517          * Starts the image decoding. This is the version that accepts 
       
   518          * file handle of the image content. Image can be SVG/ any format
       
   519          * supported by CImageDecoder 
       
   520          * @since s60 3.2
       
   521          * @param aImageFile Image File handle
       
   522          * @param aBitmap Bitmap Pointer
       
   523          * @param aSyncLoading ETrue=Sync Loading
       
   524          * @return TInt errorcode
       
   525          */
       
   526         TInt StartImageDecoding( RFile& aImageFile,
       
   527                                  CFbsBitmap* aBitmap,
       
   528                                  TBool aSyncLoading );
       
   529         /**
       
   530          * Informs the image element that it is referring to a 
       
   531          * particular element. This is used in case an image element
       
   532          * is cloned.
       
   533          * @since s60 3.2
       
   534          * @param aImageElement Image Element Pointer
       
   535          * @return None.
       
   536          */
       
   537         void SetReferenceElement( CSvgImageElementImpl* aImageElement );
       
   538 
       
   539         /**
       
   540          * Get function for reference element
       
   541          * @since s60 3.2
       
   542          * @param none 
       
   543          * @return Image Element Pointer.
       
   544          */
       
   545         
       
   546         CSvgImageElementImpl* ReferenceElement();
       
   547         
       
   548     private:
       
   549         /**
       
   550          * Notify the listeners (MSvgImageElementListener) when 
       
   551          * Image decoding is completed
       
   552          * @since s60 3.0
       
   553          * @param None.
       
   554          * @return None. 
       
   555          */
       
   556         void NotifyImageDecoded();
       
   557         /**
       
   558          * Notify the listeners (MSvgImageElementListener) to dereference 
       
   559          * the reference element. This function can be called for eg.
       
   560          * when the reference element is getting deleted.
       
   561          * @since s60 3.2
       
   562          * @param None.
       
   563          * @return None. 
       
   564          */
       
   565         void NotifyResetReference();
       
   566         void PrepareImageWithMask();
       
   567     protected:
       
   568 
       
   569         /**
       
   570          * Need method description
       
   571          *
       
   572          * @since 1.0
       
   573          * @param
       
   574          * @return
       
   575          */
       
   576         void                            CopyL( CSvgImageElementImpl* aDestElement );
       
   577 
       
   578     void                                PrepareImageFromSvgFile(const TDesC8& aImageData);
       
   579 
       
   580 
       
   581  private:
       
   582         /**
       
   583          * Process an encoded image in the xlink:href attribute value.
       
   584          *
       
   585          * @since 1.0
       
   586          * @param aXlinkHrefValue : the string of the xlink:href attribute value.
       
   587          * @return
       
   588          */
       
   589         void                            ProcessEncodedImageL( const TDesC& aXlinkHrefValue );
       
   590 
       
   591 
       
   592     private:
       
   593         TGfxRectangle2D                 iImgRect;
       
   594         HBufC*                          iPar;
       
   595         TBool                           iBitmapOrgReady;
       
   596         CSvgImageLoaderUtil*            iImageLoader;
       
   597         TBool                           iRenderImage;
       
   598 
       
   599         TBool                           iUsedImage;
       
   600 
       
   601         HBufC8*                         iImageData;
       
   602 
       
   603         RPointerArray<MSvgImageElementListener> iImageElementListeners;
       
   604         // Indicates whether the URI for xlink:href attribute is set.
       
   605         TBool                           iIsUriSet;
       
   606         TBool                           iImageDecodingDone;
       
   607     public:
       
   608         CFbsBitmap*                     iBitmap;
       
   609         CFbsBitmap*                     iMask;
       
   610         TBool                           iBitmapReady;
       
   611         TBool                           iBitmapLoadCalled;
       
   612         TInt                            iDownloadWait;
       
   613         TFileName                       iFullPathFileName;
       
   614         CPeriodic*                      iImageDownloadTimer;
       
   615 
       
   616         RFs                             iSession;
       
   617         TBool                           iSessionConnected;
       
   618         TBool                           iIsBase64;
       
   619 
       
   620         TBool                           iIsSvgFile;
       
   621         // Image Reference Element - used in clone scenario
       
   622         CSvgImageElementImpl*           iRefElement;
       
   623     };
       
   624 
       
   625 
       
   626 
       
   627 
       
   628 #endif /*_INC_CSVGIMAGEELEMENTIMPL_INCLUDED */