breakdeps/SVGEngineImpl.cpp
changeset 48 90e0261ad33c
child 50 c0380e36a50a
equal deleted inserted replaced
47:6d38c548573f 48:90e0261ad33c
       
     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 Engine source file
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #if !defined(__E32BASE_H__)
       
    22 #include <e32base.h>
       
    23 #endif
       
    24 
       
    25 #include <utf.h>
       
    26 #include <s32mem.h>
       
    27 
       
    28 #include "SVGDOMImplementationImpl.h"
       
    29 #include "SVGElementImpl.h"
       
    30 #include "SVGDocumentImpl.h"
       
    31 #include "SVGSvgElementImpl.h"
       
    32 #include "SVGUseElementImpl.h"
       
    33 #include "SVGAnimationElementImpl.h"
       
    34 #include "SVGTextElementImpl.h"
       
    35 
       
    36 #include "SVGAudioElementImpl.h"
       
    37 
       
    38 
       
    39 #include "Gfx2dGcOpenVG.h"
       
    40 
       
    41 #include "SVGSchemaData.h"
       
    42 #include "SVGPathElementImpl.h"
       
    43 #include "SVGAnimationBase.h"
       
    44 #include "SVGElementTimeControl.h"
       
    45 
       
    46 #include "SVGRequestObserver.h"
       
    47 #include "SVGHyperlinkListener.h"
       
    48 #include "SVGListener.h"
       
    49 #include "SVGAnimationListener.h"
       
    50 #include "SVGAElementImpl.h"
       
    51 #include "SVGTextAreaElementImpl.h"
       
    52 
       
    53 #include "SVGTimer.h"
       
    54 #include "SVGEventHandler.h"
       
    55 #include "SVGEngineImpl.h"
       
    56 #include "SVGErrorImpl.h"
       
    57 
       
    58 #include "SVGFloatCssValueImpl.h"
       
    59 #include "SVGTimeContainer.h"
       
    60 #include "SVGMediaAnimationElementImpl.h"
       
    61 
       
    62 // Constants
       
    63 // length of </text>
       
    64 const TInt KClosingTextTagLength = 7;
       
    65 // Length of </textArea>
       
    66 const TInt KClosingTextAreaTagLength = 11;
       
    67 // Length of <
       
    68 const TInt KClosingBracesLength = 1;
       
    69 // Number of chars to be converted at a time to Unicode
       
    70 const TInt KMaxConversionChars = 20;
       
    71 _LIT(KClosingTextTag,"</text>");
       
    72 _LIT(KClosingTextAreaTag,"</textArea>");
       
    73 _LIT(KClosingBraces,">");
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // Two phase constructor for this class
       
    77 // JSR 226 API
       
    78 // ---------------------------------------------------------------------------
       
    79 CSvgEngineImpl* CSvgEngineImpl::NewL(CSvgBitmapFontProvider *aSvgBitmapFontProvider)
       
    80     {
       
    81     CSvgEngineImpl* self    = new ( ELeave ) CSvgEngineImpl();
       
    82     CleanupStack::PushL( self );
       
    83     self->ConstructL(aSvgBitmapFontProvider);
       
    84     CleanupStack::Pop();
       
    85     return self;
       
    86     }
       
    87 
       
    88 
       
    89 // --------------------------------------------------------------------------
       
    90 // CSvgEngineImpl* CSvgEngineImpl::NewLC()
       
    91 // ---------------------------------------------------------------------------
       
    92 CSvgEngineImpl* CSvgEngineImpl::NewLC(CSvgBitmapFontProvider *aSvgBitmapFontProvider)
       
    93     {
       
    94     CSvgEngineImpl* self    = new ( ELeave ) CSvgEngineImpl();
       
    95     CleanupStack::PushL( self );
       
    96     self->ConstructL(aSvgBitmapFontProvider);
       
    97     return self;
       
    98     }
       
    99 
       
   100 // --------------------------------------------------------------------------
       
   101 // CSvgEngineImpl::CSvgEngineImpl() : iTextAreaHandle( NULL ),
       
   102 // ---------------------------------------------------------------------------
       
   103 CSvgEngineImpl::CSvgEngineImpl() : iTextAreaHandle( NULL ),
       
   104                                    iRequestObserver( NULL ),
       
   105                                    iFrameBuffer( NULL ),
       
   106                                    iFrameBufferSize(TSize(0,0)),
       
   107                                    iFontHashMap ( NULL ),
       
   108                                    iSvgDocument( NULL ),
       
   109                                    iBackgroundColor(0x00000000),
       
   110                                    iShowDebugInfo( EFalse ),
       
   111                                    iSvgEngineState(ESVGEngineNotStarted),
       
   112                                    iTimeoutSeconds( 0 ),
       
   113                                    iRenderQuality(2), // Set To Rendering quality "high"
       
   114                                    iCustomOption( ETrue ),
       
   115                                    iFrameBufferOverridesViewport( EFalse ),
       
   116                                    iClientDefinedViewPort(EFalse)
       
   117                                    
       
   118     {
       
   119     }
       
   120 
       
   121 
       
   122 // --------------------------------------------------------------------------
       
   123 // void CSvgEngineImpl::ConstructL()
       
   124 // ---------------------------------------------------------------------------
       
   125 void CSvgEngineImpl::ConstructL(CSvgBitmapFontProvider *aSvgBitmapFontProvider)
       
   126     {
       
   127     iGfxContext = NULL;
       
   128 
       
   129 	iSvgBitmapFontProvider = aSvgBitmapFontProvider ; 
       
   130     // create CSvgErrorImpl object
       
   131     iSvgError = CSvgErrorImpl::NewL();
       
   132 
       
   133     iFontHashMap = CSvgFontHashMap::NewL();
       
   134 
       
   135     SetIgnoreUpdateScreen( EFalse );
       
   136 
       
   137    // The iCustomOption need to be initialized for JSR
       
   138 
       
   139 	iCustomOption = ETrue;
       
   140 
       
   141     }
       
   142 
       
   143 
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // Two phase constructor for this class
       
   147 // Accepts a frame buffer and a MSvgRequestObserver object from the client
       
   148 // Buffer is used for rasterization of SVG content
       
   149 // Observer object, if provided, is used for notifying the client on updates
       
   150 // ---------------------------------------------------------------------------
       
   151 CSvgEngineImpl* CSvgEngineImpl::NewL( CFbsBitmap* aFrameBuffer,
       
   152                                       MSvgRequestObserver* aReqObserver, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider )
       
   153     {
       
   154     CSvgEngineImpl* self    = new ( ELeave ) CSvgEngineImpl( aFrameBuffer,
       
   155                                                              aReqObserver );
       
   156     CleanupStack::PushL( self );
       
   157     self->ConstructL(aFontSpec, aSvgBitmapFontProvider);
       
   158     CleanupStack::Pop();
       
   159 
       
   160     return self;
       
   161     }
       
   162 
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // Two phase constructor for this class
       
   166 // Accepts a frame buffer and a MSvgRequestObserver object from the client
       
   167 // Buffer is used for rasterization of SVG content
       
   168 // Observer object, if provided, is used for notifying the client on updates
       
   169 // ---------------------------------------------------------------------------
       
   170 CSvgEngineImpl* CSvgEngineImpl::NewLC( CFbsBitmap* aFrameBuffer,
       
   171                                        MSvgRequestObserver* aReqObserver, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider )
       
   172     {
       
   173     CSvgEngineImpl* self    = new ( ELeave ) CSvgEngineImpl( aFrameBuffer, aReqObserver );
       
   174     CleanupStack::PushL( self );
       
   175     self->ConstructL(aFontSpec, aSvgBitmapFontProvider);
       
   176 
       
   177     return self;
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // Symbian style private method that is used to construct heap objects
       
   182 // Builds the Graphics device objects with the client's frame buffer info
       
   183 // Builds the event handler object
       
   184 // ---------------------------------------------------------------------------
       
   185 void CSvgEngineImpl::ConstructL( TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider)
       
   186     {
       
   187     iBitmapFontSpec = aFontSpec;
       
   188 // iGfxContext is created through CSvgEngineInterfaceImpl::ConstructL
       
   189    // iGfxContext = CGfx2dGcVGR::NewL( iFrameBuffer->SizeInPixels(), iBitmapFontSpec );
       
   190     iSvgBitmapFontProvider = aSvgBitmapFontProvider ; 
       
   191 
       
   192     iGfxContext = CGfx2dGcOpenVG::NewL( iFrameBuffer->SizeInPixels(), iBitmapFontSpec, iSvgBitmapFontProvider );
       
   193     // create CSvgErrorImpl object
       
   194     iSvgError = CSvgErrorImpl::NewL();
       
   195     iFontHashMap = CSvgFontHashMap::NewL();
       
   196     iSvgNames = new (ELeave) CDesC16ArrayFlat(5);
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 CSvgEngineImpl* CSvgEngineImpl::NewL( CFbsBitmap* aFrameBuffer,
       
   201                                       MSvgRequestObserver* aReqObserver, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider ,SVGRendererId aRendererType)
       
   202     {
       
   203     CSvgEngineImpl* self    = new ( ELeave ) CSvgEngineImpl( aFrameBuffer,
       
   204                                                              aReqObserver );
       
   205     CleanupStack::PushL( self );
       
   206     self->ConstructL(aFontSpec, aSvgBitmapFontProvider,aRendererType);
       
   207     CleanupStack::Pop();
       
   208 	
       
   209     return self;
       
   210     }
       
   211 
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // Two phase constructor for this class
       
   215 // Accepts a frame buffer and a MSvgRequestObserver object from the client
       
   216 // Buffer is used for rasterization of SVG content
       
   217 // Observer object, if provided, is used for notifying the client on updates.
       
   218 //This contains the renderer selector parameter
       
   219 // ---------------------------------------------------------------------------
       
   220 CSvgEngineImpl* CSvgEngineImpl::NewLC( CFbsBitmap* aFrameBuffer,
       
   221                                        MSvgRequestObserver* aReqObserver, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider,SVGRendererId aRendererType )
       
   222     {
       
   223     CSvgEngineImpl* self    = new ( ELeave ) CSvgEngineImpl( aFrameBuffer, aReqObserver );
       
   224     CleanupStack::PushL( self );
       
   225     self->ConstructL(aFontSpec, aSvgBitmapFontProvider,aRendererType);
       
   226 
       
   227     return self;
       
   228     }
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // Symbian style private method that is used to construct heap objects
       
   232 // Builds the Graphics device objects with the client's frame buffer info
       
   233 // Builds the event handler object.
       
   234 //This contains the renderer selector parameter NGA
       
   235 // ---------------------------------------------------------------------------
       
   236 void CSvgEngineImpl::ConstructL( TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider,SVGRendererId aRendererType)
       
   237     {
       
   238     iBitmapFontSpec = aFontSpec;
       
   239 // iGfxContext is created through CSvgEngineInterfaceImpl::ConstructL
       
   240    // iGfxContext = CGfx2dGcVGR::NewL( iFrameBuffer->SizeInPixels(), iBitmapFontSpec );
       
   241     iSvgBitmapFontProvider = aSvgBitmapFontProvider ; 
       
   242 
       
   243     iGfxContext = CGfx2dGcOpenVG::NewL( iFrameBufferSize, iBitmapFontSpec, iSvgBitmapFontProvider ,aRendererType);
       
   244     // create CSvgErrorImpl object
       
   245     iSvgError = CSvgErrorImpl::NewL();
       
   246     iFontHashMap = CSvgFontHashMap::NewL();
       
   247     iSvgNames = new (ELeave) CDesC16ArrayFlat(5);
       
   248     }
       
   249 
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // Private constructor
       
   253 // Initializes private attributes
       
   254 // ---------------------------------------------------------------------------
       
   255 CSvgEngineImpl::CSvgEngineImpl( CFbsBitmap* aFrameBuffer,
       
   256                                 MSvgRequestObserver* aReqObserver ) : iTextAreaHandle( NULL ),
       
   257                                                                       iRequestObserver( aReqObserver ),
       
   258                                                                       iFrameBuffer( aFrameBuffer ),
       
   259                                                                       iFrameBufferSize(TSize(0,0)),
       
   260                                                                       iFontHashMap ( NULL),
       
   261                                                                       iSvgDocument( NULL ),
       
   262                                                                       iBackgroundColor(0x00000000),
       
   263                                                                       iShowDebugInfo( EFalse ),
       
   264                                                                       iSvgEngineState(ESVGEngineNotStarted),
       
   265                                                                       iCustomOption( ETrue ),
       
   266                                                                       iFrameBufferOverridesViewport( EFalse )
       
   267                                                                       
       
   268 
       
   269     {
       
   270         if(aFrameBuffer && aFrameBuffer->Handle()>0)
       
   271             {
       
   272                 iFrameBufferSize = aFrameBuffer->SizeInPixels();
       
   273             }
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 // Destructor
       
   278 // ---------------------------------------------------------------------------
       
   279 CSvgEngineImpl::~CSvgEngineImpl()
       
   280     {
       
   281     Destroy();
       
   282 
       
   283     if ( iFontHashMap )
       
   284     {
       
   285 		delete iFontHashMap;
       
   286 		iFontHashMap = NULL;
       
   287     }
       
   288 
       
   289 	iSvgTextBoundingBoxes.ResetAndDestroy();
       
   290 	iSvgTextBoundingBoxes.Close();
       
   291 
       
   292     if ( iGfxContext )
       
   293         {
       
   294         delete iGfxContext;
       
   295         iGfxContext = NULL;
       
   296         }
       
   297     if ( iSvgError )
       
   298         {
       
   299         delete iSvgError;
       
   300         iSvgError = NULL;
       
   301         }
       
   302     if (iTextAreaHandle)
       
   303     {
       
   304     delete iTextAreaHandle;
       
   305     iTextAreaHandle = NULL;
       
   306     }
       
   307 
       
   308     iTextAreaListeners.Close();
       
   309     iTextListeners.Close();
       
   310     iHyperlinkListeners.Close();
       
   311     iAnimationListeners.Close();
       
   312     iSvgMouseListeners.Close();
       
   313     iInteractiveElementListeners.Close();
       
   314     delete iSvgNames;
       
   315     }
       
   316 
       
   317 // ---------------------------------------------------------------------------
       
   318 // Draws aRootElement and calls itself for children.
       
   319 // Handles switch element differently, as it only draws one of its children.
       
   320 // ---------------------------------------------------------------------------
       
   321 
       
   322 void CSvgEngineImpl::DrawElementsL( CSvgElementImpl* aRootElement)
       
   323     {
       
   324     if ( aRootElement != NULL)
       
   325         {
       
   326         TInt32 displayValue = 0;
       
   327         //  while we have next elements
       
   328         CSvgElementImpl* newElement = aRootElement;
       
   329         while( newElement != NULL )
       
   330             {
       
   331 		    if(newElement->GetAttributeIntL( KCSS_ATTR_DISPLAY, displayValue ) == KErrNoAttribute)
       
   332 		        {
       
   333 		        newElement = ( CSvgElementImpl* ) newElement->FirstChild();
       
   334 		        while ( newElement != NULL )
       
   335 		            {
       
   336 		            DrawElementsL( newElement );
       
   337 		            newElement = ( CSvgElementImpl * ) newElement->NextSibling();
       
   338 		            }
       
   339 		            return;
       
   340 		         }
       
   341 
       
   342             if(displayValue != KDisplayEnumNone) // is it a hidden element
       
   343                 {
       
   344                 CCssValue*  CssValue = NULL;
       
   345                 TReal32 opacity = 1;
       
   346 
       
   347                 // check visisbility
       
   348                 TInt32  visbilityValue = 0;
       
   349                 TInt visibility = newElement->GetAttributeIntL( KCSS_ATTR_VISIBILITY, visbilityValue );
       
   350 
       
   351                 newElement->FindProperty( KCSS_ATTR_GROUP_OPACITY, CssValue, newElement );
       
   352                 if ( CssValue )
       
   353                     {
       
   354                     opacity = ((CFloatCssValueImpl*)CssValue)->Value();
       
   355                     }
       
   356 
       
   357                 if( opacity != 1 && !newElement->IsInherited( KCSS_ATTR_GROUP_OPACITY ) )
       
   358                     {
       
   359                     iGfxContext->BindToImageL();
       
   360                     // Group opacity
       
   361                     if ( newElement->ElemID() == KSvgGElement && newElement->FirstChild() )
       
   362                         {
       
   363                         // recurse with right context.
       
   364                         DrawElementsL( ( CSvgElementImpl* )newElement->FirstChild());
       
   365                         }
       
   366                     // Element opacity
       
   367                     else
       
   368                         {
       
   369                         TBool canDraw = ETrue;
       
   370                         if( (visibility == KErrNone) && (visbilityValue == 0) )
       
   371                             {
       
   372                             canDraw = newElement->DrawL( iGfxContext, NULL ) ;
       
   373                              }
       
   374                         if( canDraw && newElement->FirstChild() )
       
   375                             {
       
   376                             DrawElementsL( ( CSvgElementImpl* )newElement->FirstChild() );
       
   377                             }
       
   378                         }
       
   379 
       
   380                     // Blend opacity context buffer with parent's gfx context buffer
       
   381                     iGfxContext->UnbindFromImageL( opacity );
       
   382                     }
       
   383                 else // no opacity or is inherited from above....
       
   384                     {
       
   385                     TBool canDraw = ETrue;
       
   386                     if( (visibility == KErrNone) && (visbilityValue == 0) )
       
   387                         {
       
   388                         canDraw = newElement->DrawL(iGfxContext, NULL );
       
   389                         }
       
   390                     if( canDraw && newElement->FirstChild() )
       
   391                         {
       
   392                         DrawElementsL( ( CSvgElementImpl* )newElement->FirstChild());
       
   393                         }
       
   394                     }
       
   395 				}
       
   396             newElement = ( CSvgElementImpl * )newElement->NextSibling();
       
   397 
       
   398             }// end while....
       
   399         }
       
   400     }
       
   401 
       
   402 //--------------------------------------------------------------------
       
   403 //CFbsBitmap* CSvgEngineImpl::CreateOpacityFrameBufferL()
       
   404 //--------------------------------------------------------------------
       
   405 CFbsBitmap* CSvgEngineImpl::CreateOpacityFrameBufferL()
       
   406 {
       
   407     CFbsBitmap* bitmap = new ( ELeave ) CFbsBitmap();
       
   408 
       
   409     if ( iFrameBuffer != NULL )
       
   410         {
       
   411 /*NGA reverse*/if ( bitmap->Create( iFrameBufferSize, EColor16MU ) != KErrNone )
       
   412             {
       
   413             delete bitmap;
       
   414             bitmap = NULL;
       
   415             }
       
   416         }
       
   417     return bitmap;
       
   418     }
       
   419 
       
   420 // ---------------------------------------------------------------------------
       
   421 // Copy 32-bit buffer
       
   422 // ---------------------------------------------------------------------------
       
   423 
       
   424 void CSvgEngineImpl::CopyBuffer( TUint32* aSrc, TUint32* aDest, const TSize aSize )
       
   425     {
       
   426     if ( aSrc && aDest )
       
   427         {
       
   428         Mem::Copy( aDest, aSrc, aSize.iWidth * aSize.iHeight * sizeof( TUint32 ) );
       
   429         }
       
   430     }
       
   431 
       
   432 // ---------------------------------------------------------------------------
       
   433 // Positions the root element and calls itself (recursively) for all the
       
   434 // descendant elements
       
   435 // CTM stands for 'Current Transformation Matrix'.
       
   436 // ---------------------------------------------------------------------------
       
   437 void CSvgEngineImpl::UpdateCTM(CSvgDocumentImpl* aSvgDocument)
       
   438     {
       
   439 
       
   440     if (aSvgDocument)
       
   441     {
       
   442         ((CSvgElementImpl*)aSvgDocument->RootElement())->UpdateCTM();
       
   443     }
       
   444 
       
   445 
       
   446     }
       
   447 
       
   448 // ---------------------------------------------------------------------------
       
   449 // Initializes the SVG Engine primarily with width and height informtion
       
   450 // This is based on the attribute specifications for the root 'svg' element
       
   451 // ---------------------------------------------------------------------------
       
   452 void CSvgEngineImpl::InitializeEngineL()
       
   453     {
       
   454     // VIEWBOX
       
   455     // If x, y, w, h of outmost svg not defined, then put default values: 0 0 100% 100%
       
   456     // return;
       
   457     // Set locale, so that there is no thousands separator
       
   458 
       
   459     if( !iSvgDocument )
       
   460         return;
       
   461 
       
   462     iSvgDocument->iInitialDrawFlag = ETrue;
       
   463     if(!((CSvgSvgElementImpl *)(iSvgDocument->RootElement()))->iIsWidthSet)
       
   464     {
       
   465         ((CSvgSvgElementImpl *)(iSvgDocument->RootElement()))->iIsWidthSet = ETrue;
       
   466     }
       
   467     if(!((CSvgSvgElementImpl *)(iSvgDocument->RootElement()))->iIsHeightSet)
       
   468     {
       
   469         ((CSvgSvgElementImpl *)(iSvgDocument->RootElement()))->iIsHeightSet = ETrue;
       
   470     }
       
   471 
       
   472     TLocale locale; // locale object
       
   473     locale.SetCurrencyTriadsAllowed( EFalse ); // change setting
       
   474     TSize   lSize   = GetSize();
       
   475     iSvgDocument->iReqExReqFtrSysLTested = EFalse;
       
   476     if ( iSvgDocument->RootElement() != NULL &&
       
   477          ((CSvgElementImpl*)iSvgDocument->RootElement())->ElemID() == KSvgSvgElement )
       
   478 
       
   479         {
       
   480         // Scale width & height to fit to screen size
       
   481         CSvgSvgElementImpl*     el      = ( CSvgSvgElementImpl* )
       
   482                                           (iSvgDocument->RootElement());
       
   483         TFloatFixPt                  width, height;
       
   484         TInt                    widthInt, heightInt;
       
   485         TFloatFixPt scrnW( lSize.iWidth ), scrnH( lSize.iHeight );
       
   486         TFloatFixPt                  zero    ( 0 );
       
   487         
       
   488         if ( iFrameBufferOverridesViewport )
       
   489         {
       
   490         		//special case for Aknicon
       
   491     				//the don't care what the contents viewport is they just want it to scale to the framebuffer's size
       
   492         		width = scrnW;
       
   493         		height= scrnH;
       
   494         }
       
   495         else
       
   496         {
       
   497             //bitmap from the client overrides width height specified in svg
       
   498       
       
   499             if(iViewPortListener != NULL)
       
   500             {
       
   501                 TInt tempWidth=0,tempHeight=0;
       
   502                 iViewPortListener->GetViewPort(
       
   503                 ((CSvgSvgElementImpl *)(iSvgDocument->RootElement()))->iWidthInUserCoordinate, 
       
   504                 ((CSvgSvgElementImpl *)(iSvgDocument->RootElement()))->iHeightInUserCoordinate, 
       
   505                 ((CSvgSvgElementImpl *)(iSvgDocument->RootElement()))->iWidthInPercentage, 
       
   506                 ((CSvgSvgElementImpl *)(iSvgDocument->RootElement()))->iHeightInPercentage,
       
   507                 tempWidth,
       
   508                 tempHeight);
       
   509             
       
   510                 width = (TFloatFixPt) tempWidth;
       
   511                 height = (TFloatFixPt) tempHeight;
       
   512                 
       
   513                 //used in SetWindowViewportTrans of svgSvgElementImpl
       
   514                 iClientDefinedViewPort = ETrue;
       
   515                      
       
   516             }
       
   517         else
       
   518             {
       
   519         
       
   520                 TReal32 per = 100;
       
   521                 if(((CSvgSvgElementImpl *)(iSvgDocument->RootElement()))->iWidthInPercentage)
       
   522                 {   
       
   523                     width = ( TFloatFixPt ) (( lSize.iWidth/per ) * ((CSvgSvgElementImpl *)(iSvgDocument->RootElement()))->iWidthInUserCoordinate);
       
   524                 }
       
   525                 else
       
   526                 {   
       
   527                     width  = (TFloatFixPt)  (((CSvgSvgElementImpl *)(iSvgDocument->RootElement()))->iWidthInUserCoordinate);
       
   528                 }
       
   529         
       
   530                 if(((CSvgSvgElementImpl *)(iSvgDocument->RootElement()))->iHeightInPercentage)
       
   531                 {
       
   532                     height = ( TFloatFixPt ) (( lSize.iHeight/per ) * ((CSvgSvgElementImpl *)(iSvgDocument->RootElement()))->iHeightInUserCoordinate);
       
   533                 }
       
   534                 else
       
   535                 {
       
   536                     height  = (TFloatFixPt)  (((CSvgSvgElementImpl *)(iSvgDocument->RootElement()))->iHeightInUserCoordinate);
       
   537             }
       
   538         
       
   539         //default to XmidYmid_meet
       
   540         TSvgPreserveAspectAlignType lPreserverAspectAlignment = ESvgPreserveAspectRatio_XmidYmid;
       
   541   			TSvgMeetOrSliceType lMeetOrSlice = ESvgMeetOrSlice_Meet;
       
   542   		
       
   543   		MSvgPreserveAspectRatio* aPreserveAspectRatio;
       
   544         el->GetPreserveAspectRatio(aPreserveAspectRatio);
       
   545         
       
   546         if (aPreserveAspectRatio)
       
   547         {
       
   548         	lPreserverAspectAlignment = aPreserveAspectRatio->GetAlign();
       
   549         	lMeetOrSlice = aPreserveAspectRatio->GetMeetOrSlice();
       
   550         	
       
   551         	//el->SetPreserveAspectRatioL(  lPreserverAspectAlignment, lMeetOrSlice);
       
   552         	if( lPreserverAspectAlignment == ESvgPreserveAspectRatio_None && lMeetOrSlice == ESvgMeetOrSlice_Meet )
       
   553         	{
       
   554             width = scrnW;
       
   555             height = scrnH;
       
   556         	}
       
   557         }
       
   558             
       
   559         if( lMeetOrSlice == ESvgMeetOrSlice_Meet && !(lPreserverAspectAlignment == ESvgPreserveAspectRatio_None) )
       
   560             {
       
   561             widthInt = ( TInt ) width;
       
   562             heightInt = ( TInt ) height;
       
   563 
       
   564             // to avoid division by zero.
       
   565             TInt    rh  = lSize.iWidth ;
       
   566             if (widthInt != 0)
       
   567                 {
       
   568                 rh  = heightInt* lSize.iWidth / widthInt;
       
   569                 }
       
   570 
       
   571             if ( rh <= lSize.iHeight )
       
   572                 {
       
   573                 width = scrnW;
       
   574                 height = TFloatFixPt( rh );
       
   575                 }
       
   576             else
       
   577                 {
       
   578                 // to avoid division by zero.
       
   579                 if (heightInt != 0)
       
   580                     {
       
   581                     width = TFloatFixPt( ((TReal32)(widthInt * lSize.iHeight)) / heightInt );
       
   582                     }
       
   583                 height = scrnH;
       
   584                 }
       
   585             }
       
   586         else if( lMeetOrSlice == ESvgMeetOrSlice_Slice )
       
   587             {
       
   588             widthInt = ( TInt ) width;
       
   589             heightInt = ( TInt ) height;
       
   590 
       
   591             // to avoid division by zero.
       
   592             TInt    rh  = lSize.iWidth ;
       
   593             if (widthInt != 0)
       
   594                 {
       
   595                 rh  = heightInt* lSize.iWidth / widthInt;
       
   596                 }
       
   597 
       
   598             if ( rh <= lSize.iHeight )
       
   599                 {
       
   600                 // to avoid division by zero.
       
   601                 if (heightInt != 0)
       
   602                     {
       
   603                     width = TFloatFixPt( ((TReal32)(widthInt * lSize.iHeight)) / heightInt );
       
   604                     }
       
   605                 height = scrnH;
       
   606 
       
   607                 }
       
   608             else
       
   609                 {
       
   610                 width = scrnW;
       
   611                 height = TFloatFixPt( rh );
       
   612                 }
       
   613             }
       
   614         else
       
   615             {
       
   616             }
       
   617             }//Normal viewer| end of else
       
   618         }
       
   619 
       
   620         if ( ( width <= zero ) || ( height <= zero ) ) //.
       
   621         {
       
   622             width = 0;
       
   623             height = 0;
       
   624             return;
       
   625         }
       
   626         // Set initial viewport
       
   627         el->SetAttributeFloatL( KAtrX, zero );
       
   628         el->SetAttributeFloatL( KAtrY, zero );
       
   629         el->SetAttributeFloatL( KAtrWidth, width );
       
   630         el->SetAttributeFloatL( KAtrHeight, height );
       
   631         }
       
   632     }
       
   633 
       
   634 
       
   635 
       
   636 
       
   637 
       
   638 // ---------------------------------------------------------------------------
       
   639 // This method is called after the SVG file is read and all elements are
       
   640 // constructed
       
   641 // It also looks for rendering properties such as Anti Aliasing at this
       
   642 // point
       
   643 // It calibrates the system for rasterization quality based on contents
       
   644 // ---------------------------------------------------------------------------
       
   645 TBool CSvgEngineImpl::StartFrameLoopL()
       
   646     {
       
   647     if( iRequestObserver != NULL )
       
   648         {
       
   649         if(iSvgDocument != NULL && iSvgDocument->iEventHandler != NULL)
       
   650             {
       
   651             iRequestObserver->UpdatePresentation(
       
   652                          iSvgDocument->iEventHandler->AnimationElementsCount());
       
   653             }
       
   654         }
       
   655     if(iSvgDocument != NULL)
       
   656         {
       
   657         if ( iSvgDocument->RootElement() )
       
   658             {
       
   659             InitializeEngineL(); // set the viewport and viewbox
       
   660             return ETrue;
       
   661             }
       
   662         }
       
   663     return EFalse;
       
   664     }
       
   665 // ---------------------------------------------------------------------------
       
   666 // UpdatePresentation()
       
   667 // ---------------------------------------------------------------------------
       
   668 void  CSvgEngineImpl::UpdatePresentation(const TInt32& aParam)
       
   669     {
       
   670     if( iRequestObserver != NULL )
       
   671         {
       
   672         iRequestObserver->UpdatePresentation (aParam);
       
   673         }
       
   674     }
       
   675     
       
   676     
       
   677 //---------------------------------------------------------------------------
       
   678 // SetRenderingQuality
       
   679 //
       
   680 // @param : aRenderQuality
       
   681 // The function is called from JSR226 API. Specific to M2G/JSR226 only.
       
   682 //---------------------------------------------------------------------------
       
   683 void  CSvgEngineImpl::SetRenderingQuality( const TInt32 aRenderQuality)
       
   684 {
       
   685 	// Bydefault iRenderQuality is set to 2 i.e. Rendering Quality high.
       
   686 	
       
   687 	if( iRenderQuality != aRenderQuality )
       
   688 	{
       
   689 		iRenderQuality = aRenderQuality;
       
   690 		
       
   691 		if( iGfxContext )
       
   692 		{
       
   693 			iGfxContext->SetAntialiasingMode( iRenderQuality );
       
   694 		}
       
   695 	}
       
   696 }
       
   697 
       
   698 
       
   699 // ---------------------------------------------------------------------------
       
   700 // Invalidate the current raster (and frame buffer) and
       
   701 // update the buffer with new  raster.
       
   702 // ---------------------------------------------------------------------------
       
   703 void CSvgEngineImpl::RedrawL()
       
   704     {
       
   705     // Clear the frame buffer
       
   706     if( iGfxContext && iSvgDocument)
       
   707         {
       
   708         // Set Clipping rectangle
       
   709         CSvgSvgElementImpl* el  = ( CSvgSvgElementImpl* ) (iSvgDocument->RootElement());
       
   710         if ( !el )
       
   711             {
       
   712             return; // No DOM tree, nothing to draw.
       
   713             }
       
   714             
       
   715             
       
   716         
       
   717      	// If viewBox has been set and width or height is zero
       
   718      	// Do not render the content    
       
   719         TGfxRectangle2D viewBoxRect;    
       
   720         if(el->GetViewBox(viewBoxRect))
       
   721             {
       
   722                 if(viewBoxRect.iWidth == TFloatFixPt(0) || 
       
   723                     viewBoxRect.iHeight == TFloatFixPt(0))
       
   724                     {
       
   725                     return;
       
   726                     }
       
   727             }
       
   728            
       
   729         iGfxContext->SetupContextL();
       
   730         iGfxContext->Clear(iBackgroundColor);
       
   731         iGfxContext->SetFillOpacity( 1.0f );
       
   732         iGfxContext->SetStrokeOpacity( 1.0f );
       
   733 
       
   734         TFloatFixPt  width, height;
       
   735         el->GetAttributeFloat( KAtrWidth, width );
       
   736         el->GetAttributeFloat( KAtrHeight, height );
       
   737         TGfxRectangle2D clipRect    ( 0, 0, width, height );
       
   738         iGfxContext->SetClip( clipRect );
       
   739         iClipRect = clipRect;
       
   740 
       
   741         UpdateCTM(iSvgDocument);
       
   742 
       
   743         iSvgDocument->iIsRendering = ETrue;
       
   744         DrawElementsL( (CSvgElementImpl*)iSvgDocument->RootElement());
       
   745         iSvgDocument->iIsRendering = EFalse;
       
   746 
       
   747         iGfxContext->Flush();
       
   748 
       
   749         // Get the redering result onto CFbsBitmap.
       
   750         if(iFrameBufferSize.iWidth > 0)
       
   751             iGfxContext->UpdateFramebufferL( iFrameBuffer, iMask,iFrameBufferSize,iRenderDspMode,iMaskDspMode );    
       
   752         else
       
   753          iGfxContext->UpdateFramebufferL( iFrameBuffer, iMask );
       
   754 
       
   755         if ( !iIgnoreUpdateScreen && iRequestObserver != NULL )
       
   756             {
       
   757             iRequestObserver->UpdateScreen();
       
   758             }
       
   759         if ( iSvgDocument->iInitSortList )
       
   760             {
       
   761             iSvgDocument->SortEventList();
       
   762             }
       
   763         else
       
   764             {
       
   765             iSvgDocument->iInitSortList=EFalse;
       
   766             }
       
   767         }
       
   768     }
       
   769 
       
   770 // ---------------------------------------------------------------------------
       
   771 // Delete the objects associated with the last loaded SVG file
       
   772 // ---------------------------------------------------------------------------
       
   773 void CSvgEngineImpl::Destroy()
       
   774     {
       
   775     //if ( iSvgDocument )    
       
   776     //    {
       
   777         // Stop timer and reset time
       
   778     //    iSvgDocument->TimeContainer()->UserStop();
       
   779     //    iSvgDocument->TimeContainer()->UserResetTime();
       
   780     //    }
       
   781     }
       
   782 
       
   783 
       
   784 // ---------------------------------------------------------------------------
       
   785 // Set the URI information
       
   786 // ---------------------------------------------------------------------------
       
   787 void CSvgEngineImpl::LinkRequest( const TDesC& aUri )
       
   788     {
       
   789     iLinkUri.Set( aUri );
       
   790     }
       
   791 // ---------------------------------------------------------------------------
       
   792 // Set the Link:Show information
       
   793 // ---------------------------------------------------------------------------
       
   794 
       
   795 
       
   796 void CSvgEngineImpl::LinkRequestWithShow(const TDesC& aUri ,const TDesC& aLinkShow )
       
   797     {
       
   798     iLinkUri.Set( aUri );
       
   799     iLinkShow.Set( aLinkShow );
       
   800     }
       
   801 
       
   802 // ---------------------------------------------------------------------------
       
   803 // Initiate the process of getting an svg font from the client
       
   804 // ---------------------------------------------------------------------------
       
   805 TBool CSvgEngineImpl::FetchFont( const TDesC& aUri, RFs& aSession, RFile& aFileHandle )
       
   806     {
       
   807 		if ( iRequestObserver == NULL )
       
   808         {
       
   809         return EFalse;
       
   810         }
       
   811     else
       
   812         {
       
   813         if (iRequestObserver->FetchFont( aUri, aSession, aFileHandle ) == KErrNone)
       
   814         {
       
   815             return ETrue;
       
   816         }
       
   817             return EFalse;
       
   818         }
       
   819     }
       
   820 
       
   821 // ---------------------------------------------------------------------------
       
   822 // Initiate the process of getting an embedded image from the client
       
   823 // ---------------------------------------------------------------------------
       
   824 TBool CSvgEngineImpl::FetchImage( const TDesC& aUri, RFs& aSession, RFile& aFileHandle )
       
   825     {
       
   826     if ( iRequestObserver == NULL )
       
   827         {
       
   828         return EFalse;
       
   829         }
       
   830     else
       
   831         {
       
   832         if (iRequestObserver->FetchImage( aUri, aSession, aFileHandle ) == KErrNone)
       
   833         {
       
   834             return ETrue;
       
   835         }
       
   836             return EFalse;
       
   837         }
       
   838     }
       
   839 
       
   840 // ---------------------------------------------------------------------------
       
   841 // Accessor for Graphics Context object
       
   842 // ---------------------------------------------------------------------------
       
   843 CGfx2dGc* CSvgEngineImpl::GraphicsContext()
       
   844     {
       
   845     return iGfxContext;
       
   846     }
       
   847 
       
   848 // ---------------------------------------------------------------------------
       
   849 // Accessor for the Engine's current time
       
   850 // ---------------------------------------------------------------------------
       
   851 TInt32 CSvgEngineImpl::CurrentTIme()
       
   852     {
       
   853     if ( iSvgDocument )
       
   854         {
       
   855         return iSvgDocument->CurrentTime();        
       
   856         }
       
   857     return KErrGeneral;
       
   858     }
       
   859 
       
   860 
       
   861 // --------------------------------------------------------------------------
       
   862 // void CSvgEngineImpl::ImageLoadingCompleted( TInt /* aErrorStatus */ )
       
   863 // ---------------------------------------------------------------------------
       
   864 // ImageLoadingObserver interface
       
   865 void CSvgEngineImpl::ImageLoadingCompleted( TInt /* aErrorStatus */ )
       
   866 {
       
   867     TRAP_IGNORE(RedrawL());
       
   868     //aErrorStatus = 0;
       
   869 }
       
   870 
       
   871 // --------------------------------------------------------------------------
       
   872 // void CSvgEngineImpl::UpdatePath( CGfxGeneralPath* hPath, CSvgElementImpl* hElement )
       
   873 // ---------------------------------------------------------------------------
       
   874 void CSvgEngineImpl::UpdatePath( CGfxGeneralPath* hPath, CSvgElementImpl* hElement )
       
   875 {
       
   876     if ((hElement != NULL) && (hElement->ElemID() == KSvgPathElement))
       
   877     {
       
   878         TRAPD(error,hElement->SetAttributePathL(KAtrData, hPath));
       
   879         if ( error != KErrNone )
       
   880            {
       
   881             // Error Processing
       
   882             return;
       
   883            }
       
   884     }
       
   885 
       
   886 }
       
   887 
       
   888 // ---------------------------------------------------------------------------
       
   889 // Accessor for the document object for the currently loaded SVG source
       
   890 // ---------------------------------------------------------------------------
       
   891 CSvgDocumentImpl* CSvgEngineImpl::Document()
       
   892     {
       
   893     return iSvgDocument;
       
   894     }
       
   895 
       
   896 // ---------------------------------------------------------------------------
       
   897 // Restrict Thumbnail documents
       
   898 // Do not render to frame buffer when is in thumbnail mode and
       
   899 // frame buffer size width or height is larger than 80x80.
       
   900 // ---------------------------------------------------------------------------
       
   901 TBool CSvgEngineImpl::PassesThumbNailRestriction()
       
   902 {
       
   903     if ( iSvgDocument && iFrameBuffer && iSvgDocument->IsThumbNailOnly() )
       
   904     {
       
   905         TSize size = iFrameBuffer->SizeInPixels();
       
   906         if ( size.iWidth > 80 || size.iHeight > 80 )
       
   907         {
       
   908            return EFalse;
       
   909         }
       
   910     }
       
   911     return ETrue;
       
   912 }
       
   913 
       
   914 //***************************************************************
       
   915 // Event handling
       
   916 // ---------------------------------------------------------------------------
       
   917 // Initiate the process of handling an event from the client for the
       
   918 // SVG source
       
   919 // ---------------------------------------------------------------------------
       
   920 void CSvgEngineImpl::ProcessEventL( CSvgDocumentImpl* aSvgDocument, 
       
   921     MSvgEvent* aEvent, TBool aRedraw )
       
   922     {
       
   923     // Check for Thumbnail restrictions
       
   924     if ( !PassesThumbNailRestriction() )
       
   925     {
       
   926         return;
       
   927     }
       
   928 
       
   929     // Timer event
       
   930     //if(!aEvent || !iGfxContext)
       
   931     if(!aEvent)
       
   932     return;
       
   933     if ( aEvent->EventType() == ESvgEngineEventTimer )
       
   934         {
       
   935         // Update current time
       
   936         if ( aSvgDocument )
       
   937             {
       
   938             aSvgDocument->SetCurrentTime( 
       
   939                 ( ( MSvgTimerEvent * ) aEvent )->Time() );
       
   940             }
       
   941         }
       
   942 
       
   943     if( aSvgDocument &&  aSvgDocument->iEventHandler)
       
   944         {
       
   945         if (( aSvgDocument->iEventHandler->ProcessEventL( aEvent ) ||
       
   946               aSvgDocument->iInitialDrawFlag) && aEvent->EventType() == ESvgEngineEventTimer )
       
   947         {
       
   948 
       
   949       if(aSvgDocument->iInitSortList)
       
   950             {
       
   951             aSvgDocument->SortEventList();
       
   952             aSvgDocument->iInitSortList = EFalse;
       
   953             }
       
   954         aSvgDocument->iInitialDrawFlag = EFalse;
       
   955         aSvgDocument->iEventHandler->DoAnimProcL(aEvent);
       
   956 
       
   957         if (aRedraw)
       
   958             {
       
   959         	// Redraw is performed for iSvgDocument
       
   960             RedrawL();
       
   961             }
       
   962         }
       
   963         else
       
   964             {
       
   965         // this is to keep the dom in its final state.
       
   966             if(aEvent->EventType() == ESvgEngineEventTimer)
       
   967                 {
       
   968                 aSvgDocument->iEventHandler->DoAnimProcL(aEvent);
       
   969                 }
       
   970 
       
   971             }
       
   972 
       
   973     // Process Link
       
   974     if ( aEvent->EventMask() == KSvgEventMaskExternalUI )
       
   975             {
       
   976             if ( iLinkUri.Length() > 0 )
       
   977                 {
       
   978                 DoHyperLinkingL();
       
   979                 // reset link description
       
   980                 iLinkUri.Set( NullString );
       
   981                 }
       
   982             }
       
   983         }
       
   984 
       
   985 // Show FPS debug info. note. only write data to STI port
       
   986 #ifdef _DEBUG
       
   987 
       
   988     if ( aEvent->EventType() == ESvgEngineInternalEvent )
       
   989         {
       
   990         MSvgInternalEvent*  evt = ( MSvgInternalEvent* ) aEvent;
       
   991         if (evt->SvgEvent() == ESvgEventEndEvent)
       
   992             {
       
   993             iAnimationState = KAnimFinished;
       
   994             return;
       
   995             }
       
   996         else
       
   997         if (evt->SvgEvent() == ESvgEventBeginEvent)
       
   998             {
       
   999             iAnimationState = KAnimActive;
       
  1000             return;
       
  1001             }
       
  1002 
       
  1003         }
       
  1004 
       
  1005     // time display for debug
       
  1006     if ( iShowDebugInfo && iGfxContext && aEvent->EventType() == ESvgEngineEventTimer
       
  1007         && iAnimationState != KAnimFinished /*&& iTimer*/)
       
  1008         {
       
  1009         TInt fps = iSvgDocument->TimeContainer()->UserFps() / 10; //iTimer->Fps() / 10;
       
  1010         _LIT(msg, "\n%3d.%d\n");
       
  1011         RDebug::Print(msg, fps, iSvgDocument->TimeContainer()->UserFps()
       
  1012              - fps * 10 );
       
  1013 
       
  1014         }
       
  1015 #endif //_DEBUG
       
  1016 
       
  1017     }
       
  1018 
       
  1019 
       
  1020 // ---------------------------------------------------------------------------
       
  1021 // This method is for future extension, in which an external script engine
       
  1022 // could be used to evaluate a script description.
       
  1023 // ---------------------------------------------------------------------------
       
  1024 TBool CSvgEngineImpl::ScriptCall( const TDesC& aScript,
       
  1025                                   CSvgElementImpl* aCallerElement )
       
  1026     {
       
  1027     if ( iRequestObserver == NULL )
       
  1028         {
       
  1029         return EFalse;
       
  1030         }
       
  1031     else
       
  1032         {
       
  1033         return iRequestObserver->ScriptCall( aScript, aCallerElement );
       
  1034         }
       
  1035     }
       
  1036 
       
  1037 
       
  1038 //***************************************************************
       
  1039 //
       
  1040 // ---------------------------------------------------------------------------
       
  1041 // Obtain the longest duration for an animation given document
       
  1042 // NULL will assume the attached document.
       
  1043 // ---------------------------------------------------------------------------
       
  1044 TUint32 CSvgEngineImpl::Duration( CSvgDocumentImpl* aDocument )
       
  1045     {
       
  1046     if ( aDocument == NULL )
       
  1047         {
       
  1048         if ( iSvgDocument == NULL )
       
  1049             {
       
  1050             return 0;
       
  1051             }
       
  1052         return iSvgDocument->AnimationDuration();
       
  1053         }
       
  1054     return aDocument->AnimationDuration();
       
  1055     }
       
  1056 
       
  1057 //*******************************************************/
       
  1058 // --------------------------------------------------------------------------
       
  1059 // void CSvgEngineImpl::SwitchDebugInfo()
       
  1060 // ---------------------------------------------------------------------------
       
  1061 void CSvgEngineImpl::SwitchDebugInfo(TBool debug)
       
  1062     {
       
  1063     iShowDebugInfo = debug;
       
  1064     }
       
  1065 
       
  1066 void CSvgEngineImpl::CustomOption(TBool aCustomOption )
       
  1067     {
       
  1068         iCustomOption = aCustomOption;
       
  1069         delete iGfxContext;
       
  1070         iGfxContext = NULL;
       
  1071         
       
  1072 /*NGA reverse*/  TRAP_IGNORE( iGfxContext = CGfx2dGcOpenVG::NewL( iFrameBufferSize, iBitmapFontSpec, iSvgBitmapFontProvider ));            
       
  1073             
       
  1074            
       
  1075     }
       
  1076 
       
  1077 
       
  1078 
       
  1079 
       
  1080 // ---------------------------------------------------------------------------
       
  1081 // Initiate the process of opening and reading an embedded hyperlink
       
  1082 // ---------------------------------------------------------------------------
       
  1083 void CSvgEngineImpl::DoHyperLinkingL()
       
  1084     {
       
  1085 
       
  1086     if( iSvgDocument == NULL )
       
  1087         return;
       
  1088 
       
  1089     // Not full support of XPointer
       
  1090 
       
  1091     _LIT( KTmpHttp, "http:" );
       
  1092     _LIT( KTmpFile, "file:" );
       
  1093     _LIT( KTmpHash, "#" );
       
  1094     _LIT( KTmpSvgView, "SvgView" );
       
  1095     if ( iLinkUri.Left( 1 ) == KTmpHash )
       
  1096         {
       
  1097         // internal linking
       
  1098         // Extract id
       
  1099         TLex    lex ( iLinkUri );
       
  1100         lex.Inc();  // skip '#'
       
  1101         lex.Mark();
       
  1102         while ( !lex.Eos() && lex.Peek().IsAlpha() )
       
  1103             lex.Inc();
       
  1104         TPtrC   targetId    = lex.MarkedToken();
       
  1105         if ( targetId == KTmpSvgView )
       
  1106             {
       
  1107             // need to parse next token = {viewBoxSpec| preserveAspectRatioSpec
       
  1108             // |transformSpec|zoomAndPanSpec|viewTargetSpec}
       
  1109 
       
  1110             // Not yet supported
       
  1111             }
       
  1112         else
       
  1113             {
       
  1114 
       
  1115             CSvgElementImpl*targetElement   = ( CSvgElementImpl* )
       
  1116                                               iSvgDocument->GetElementById( targetId );
       
  1117             if ( targetElement == NULL )
       
  1118                 return;
       
  1119             
       
  1120             if  (   targetElement->IsAnimatedElement( ) )
       
  1121                 {
       
  1122                 // start animation
       
  1123                 ( ( CSvgAnimationBase * ) targetElement )->BeginElementL();
       
  1124                 }
       
  1125             else
       
  1126                 {
       
  1127                 }
       
  1128             }
       
  1129         }
       
  1130     else if ( iLinkUri.Length() >= 5 )
       
  1131         {
       
  1132         if ( iLinkUri.Left( 5 ) == KTmpHttp || iLinkUri.Left( 5 ) == KTmpFile )
       
  1133             {
       
  1134             // notify observer of desire to follow http link
       
  1135             NotifyHyperlinkActivated( iLinkUri );
       
  1136             }
       
  1137         else
       
  1138             {
       
  1139             // notify observer of desire to follow link
       
  1140             if ( iLinkShow.Length() > 0 )
       
  1141                 NotifyHyperlinkActivatedWithShow( iLinkUri, iLinkShow );
       
  1142             else
       
  1143                 NotifyHyperlinkActivated( iLinkUri );
       
  1144             }
       
  1145         }
       
  1146     else if ( iLinkUri.Length() > 0 )
       
  1147         {
       
  1148         // notify observer of desire to follow link
       
  1149         if ( iLinkShow.Length() > 0 )
       
  1150             NotifyHyperlinkActivatedWithShow( iLinkUri, iLinkShow );
       
  1151         else
       
  1152             NotifyHyperlinkActivated( iLinkUri );
       
  1153         }
       
  1154     }
       
  1155 
       
  1156 // ---------------------------------------------------------------------------
       
  1157 // Dump a completed raster to the off screen buffer provided by the
       
  1158 // client
       
  1159 // ---------------------------------------------------------------------------
       
  1160 TInt CSvgEngineImpl::RenderFileToBuffer( const TDesC8& aSvgData,
       
  1161                                            CFbsBitmap* aFrameBuffer,
       
  1162                                            CFbsBitmap* aMask,
       
  1163                                            TBool aPreserveAspectRatio )
       
  1164     {
       
  1165     if ( !iGfxContext )
       
  1166         {
       
  1167         return EFalse;
       
  1168         }
       
  1169 
       
  1170     CFbsBitmap* OrgFrameBuffer;
       
  1171     CFbsBitmap* OrgMask;
       
  1172 	OrgFrameBuffer = iFrameBuffer;
       
  1173 	OrgMask = iMask;
       
  1174 	CSvgDocumentImpl* lsvgorgdoc = iSvgDocument;
       
  1175 	// We have moved all the leaving functions into RenderFileL 
       
  1176 	TRAPD(err,RenderFileL(aSvgData,aFrameBuffer,aMask,aPreserveAspectRatio));
       
  1177 	// No matter what...whether the RenderFileL returns properly or leave we need to set the 
       
  1178 	//GDI context back to the original frame buffer and mask... and set back the engine to
       
  1179 	//how it was before all this happened..
       
  1180 	
       
  1181     SetDocument(lsvgorgdoc);
       
  1182     lsvgorgdoc->SetEngine(this);
       
  1183 	// the setGDIContextL error is a very serious error and if it occurs then 
       
  1184 	// there is no way of recovery. 
       
  1185 	TRAP_IGNORE(SetGdiContextL(OrgFrameBuffer,OrgMask));
       
  1186 	//So we are propagating the more probable error of the two which is the leaving of 
       
  1187 	// RenderFileL.
       
  1188     return err;
       
  1189     }
       
  1190     
       
  1191 // ---------------------------------------------------------------------------
       
  1192 // ---------------------------------------------------------------------------
       
  1193 // Helper leaving function for the function RenderFileToBuffer.
       
  1194 // The actual rendering happens in this function..while the calling function uses this to
       
  1195 // render the file.
       
  1196 // ---------------------------------------------------------------------------
       
  1197     
       
  1198 
       
  1199 void CSvgEngineImpl::RenderFileL( const TDesC8& aSvgData,
       
  1200                                            CFbsBitmap* aFrameBuffer,
       
  1201                                            CFbsBitmap* aMask,
       
  1202                                            TBool aPreserveAspectRatio)
       
  1203    
       
  1204 {
       
  1205     CFont *lFont = iGfxContext->Font();
       
  1206     TFontSpec lFontSpec = lFont->FontSpecInTwips();
       
  1207 		
       
  1208     TSize imageSize;
       
  1209     imageSize = aFrameBuffer->SizeInPixels();
       
  1210 	//iFrameBuffer = aFrameBuffer;
       
  1211 
       
  1212     SetGdiContextL(aFrameBuffer, aMask);
       
  1213     CSvgDocumentImpl* lSvgDocument = CSvgDocumentImpl::NewLC(iSvgBitmapFontProvider);
       
  1214     SetDocument(lSvgDocument);
       
  1215     lSvgDocument->SetEngine(this);
       
  1216 
       
  1217     // fileHandle is valid from client
       
  1218     lSvgDocument->Load( aSvgData, *iSvgError );
       
  1219     if ( iSvgError->HasError() && !iSvgError->IsWarning() )
       
  1220         {
       
  1221         CleanupStack::PopAndDestroy(1);
       
  1222         return;
       
  1223         }
       
  1224 
       
  1225     StartFrameLoopL();
       
  1226     CSvgSvgElementImpl* lRoot = (CSvgSvgElementImpl*)lSvgDocument->RootElement();
       
  1227     _LIT( KPreserveAspectRatio, "preserveAspectRatio" );
       
  1228 
       
  1229     if(lRoot)
       
  1230         {
       
  1231         if ( aPreserveAspectRatio )
       
  1232             {
       
  1233             _LIT( KXMidYMid, "xMidYMid" );
       
  1234             lRoot->SetAttributeL( KPreserveAspectRatio, KXMidYMid );
       
  1235             lRoot->SetWidth( imageSize.iWidth );
       
  1236             lRoot->SetHeight( imageSize.iHeight );
       
  1237             }
       
  1238         else {
       
  1239             _LIT( KNone, "none" );
       
  1240             lRoot->SetAttributeL( KPreserveAspectRatio, KNone );
       
  1241             lRoot->SetWidth( imageSize.iWidth );
       
  1242             lRoot->SetHeight( imageSize.iHeight );
       
  1243             }
       
  1244         RedrawL();
       
  1245         }
       
  1246     CleanupStack::PopAndDestroy( 1 );
       
  1247 }
       
  1248     
       
  1249 
       
  1250 // ---------------------------------------------------------------------------
       
  1251 // ---------------------------------------------------------------------------
       
  1252 // Generate a mask bitmap from alpha channel of the framebuffer.
       
  1253 // ---------------------------------------------------------------------------
       
  1254 void CSvgEngineImpl::GenerateMask(CFbsBitmap* aMask)
       
  1255     {
       
  1256     if ( iGfxContext )
       
  1257         {
       
  1258         iGfxContext->GenerateMask( aMask );
       
  1259         }
       
  1260     }
       
  1261 
       
  1262 //
       
  1263 // ---------------------------------------------------------------------------
       
  1264 // set background color
       
  1265 // ---------------------------------------------------------------------------
       
  1266 void CSvgEngineImpl::SetBackgroundColor(TUint32 aRGBA8888Color)
       
  1267     {
       
  1268     iBackgroundColor = aRGBA8888Color;
       
  1269     }
       
  1270 
       
  1271 //
       
  1272 // ---------------------------------------------------------------------------
       
  1273 // Get Size of render buffer
       
  1274 // ---------------------------------------------------------------------------
       
  1275 TSize CSvgEngineImpl::GetSize()
       
  1276     {
       
  1277     	  return iFrameBufferSize;
       
  1278     	  
       
  1279 
       
  1280         
       
  1281     }
       
  1282 
       
  1283 
       
  1284 //
       
  1285 // ---------------------------------------------------------------------------
       
  1286 // Return SVG Engine State
       
  1287 // ---------------------------------------------------------------------------
       
  1288 
       
  1289 TSvgEngineState CSvgEngineImpl::SVGEngineState()
       
  1290     {
       
  1291     return iSvgEngineState;
       
  1292     }
       
  1293 
       
  1294 //
       
  1295 // ---------------------------------------------------------------------------
       
  1296 // Set SVG Engine State
       
  1297 // ---------------------------------------------------------------------------
       
  1298 
       
  1299 void CSvgEngineImpl::SetSVGEngineState(TSvgEngineState aState)
       
  1300     {
       
  1301     iSvgEngineState = aState;
       
  1302     if( iSvgEngineState == ESVGEnginePaused )
       
  1303         {
       
  1304         if ( iSvgDocument )
       
  1305         	{
       
  1306             iSvgDocument->TimeContainer()->UserPause();
       
  1307             NotifyAnimationPaused();
       
  1308         	}
       
  1309         }
       
  1310     else if( iSvgEngineState == ESVGEngineRunning )
       
  1311         {
       
  1312         if (iSvgDocument && iSvgDocument->IsAnimationFile())
       
  1313             {
       
  1314            	iSvgDocument->TimeContainer()->UserResume();	
       
  1315             }
       
  1316         }
       
  1317     else if(iSvgEngineState == ESVGEngineStopped ) 
       
  1318         {
       
  1319             if ( iSvgDocument )
       
  1320             {
       
  1321                 iSvgDocument->TimeContainer()->UserStop();
       
  1322        	    }
       
  1323      
       
  1324         }   
       
  1325     }
       
  1326 
       
  1327 void CSvgEngineImpl::SeekEngine( TUint32 aTime)
       
  1328     {
       
  1329     iSvgEngineState = ESVGEngineRunning;
       
  1330     if ( iSvgDocument )
       
  1331     	{
       
  1332     	iSvgDocument->TimeContainer()->UserSeek( aTime );
       
  1333     	}
       
  1334     }
       
  1335 
       
  1336 void CSvgEngineImpl::ResetTimer()
       
  1337     {
       
  1338     if ( iSvgDocument )
       
  1339         {
       
  1340         iSvgDocument->TimeContainer()->UserResetTime();
       
  1341         }
       
  1342     }
       
  1343 
       
  1344 // ---------------------------------------------------------------------------
       
  1345 // SetGdiContext File
       
  1346 // ---------------------------------------------------------------------------
       
  1347 
       
  1348 void CSvgEngineImpl::SetGdiContextL(CFbsBitmap* aCurrentBitmap, CFbsBitmap* aMask)
       
  1349     {
       
  1350     // Handle for both Non-NULL and NULL parameter
       
  1351     iFrameBuffer = aCurrentBitmap;
       
  1352     iMask = aMask;
       
  1353 
       
  1354     if ( aCurrentBitmap )
       
  1355         {
       
  1356         if ( !iGfxContext )
       
  1357             {
       
  1358                 iGfxContext = CGfx2dGcOpenVG::NewL( iFrameBuffer->SizeInPixels(), iBitmapFontSpec, iSvgBitmapFontProvider );
       
  1359                 
       
  1360                 // The API is called Only in case of JSR226. Incase if the midlet developer
       
  1361                 // has changed the RedenderQuality of the midlet.ByDefualt the value of 
       
  1362                 // iRenderQuality is 2 i.e. VG_RENDERING_QUALITY_BETTER.
       
  1363                 iGfxContext->SetAntialiasingMode( iRenderQuality );
       
  1364             }
       
  1365         else
       
  1366             {
       
  1367             iGfxContext->ChangeBufferSizeL( iFrameBuffer->SizeInPixels() );
       
  1368             }
       
  1369         }
       
  1370     else if ( iGfxContext )
       
  1371         {
       
  1372         iGfxContext->ChangeBufferSizeL( TSize( 0,0 ) );
       
  1373         }
       
  1374     }
       
  1375 
       
  1376 // ---------------------------------------------------------------------------
       
  1377 // void CSvgEngineImpl::StartEngine(CSvgErrorImpl* aError)
       
  1378 // ---------------------------------------------------------------------------
       
  1379 
       
  1380 void CSvgEngineImpl::StartEngine(CSvgErrorImpl* aError)
       
  1381     {
       
  1382     if ( !iFrameBuffer || !iSvgDocument )
       
  1383         {
       
  1384         return;
       
  1385         }
       
  1386 
       
  1387     iMouseoverElement = NULL;
       
  1388     if ( ((iFrameBufferSize.iHeight <= 0 )||(iFrameBufferSize.iWidth <= 0 )) &&(( iFrameBuffer->SizeInPixels().iWidth == 0 ) ||
       
  1389          ( iFrameBuffer->SizeInPixels().iHeight == 0) ))
       
  1390         {
       
  1391         return;
       
  1392         }
       
  1393 
       
  1394     TBool initialized = EFalse;
       
  1395 
       
  1396     TRAPD( initError, initialized = StartFrameLoopL() );
       
  1397 
       
  1398     if ( initError != KErrNone || !initialized )
       
  1399         {
       
  1400         return;
       
  1401         }
       
  1402 
       
  1403     // Get the Engine State to Running
       
  1404     SetSVGEngineState(ESVGEngineRunning);
       
  1405 
       
  1406     // Document is an animation
       
  1407     if( iSvgDocument->IsAnimationFile() )
       
  1408         {
       
  1409             { // Atleast first frame should get drawn
       
  1410                 TRAPD(error, RedrawL() );
       
  1411                 {
       
  1412                     if ( error != KErrNone && aError != NULL )
       
  1413                     {
       
  1414                        if( error == KErrNoMemory )
       
  1415                        {
       
  1416                            CSvgDocumentImpl::PrepareError( *aError, ESvgNoMemory, error,
       
  1417                            _L( "Unable to Draw: " ),
       
  1418                            _L( "" ) );  
       
  1419                            return;  
       
  1420                        }
       
  1421                        
       
  1422                        CSvgDocumentImpl::PrepareError( *aError, ESvgUnknown, error,
       
  1423                        _L( "Unable to Draw: " ),
       
  1424                        _L( "" ) );  
       
  1425                        return;
       
  1426                     }
       
  1427                 }
       
  1428             
       
  1429             }
       
  1430             
       
  1431         iSvgDocument->TimeContainer()->UserPlay();
       
  1432         iSvgDocument->iAnimationResetNeeded = ETrue;
       
  1433         }
       
  1434     // Static svg file
       
  1435     else
       
  1436         {
       
  1437             TRAPD(error, RedrawL() );
       
  1438             {
       
  1439                 if ( error != KErrNone && aError != NULL )
       
  1440                 {
       
  1441                    if( error == KErrNoMemory )
       
  1442                    {
       
  1443                        CSvgDocumentImpl::PrepareError( *aError, ESvgNoMemory, error,
       
  1444                        _L( "Unable to Draw: " ),
       
  1445                        _L( "" ) );  
       
  1446                        return;  
       
  1447                    }
       
  1448                    
       
  1449                    CSvgDocumentImpl::PrepareError( *aError, ESvgUnknown, error,
       
  1450                    _L( "Unable to Draw: " ),
       
  1451                    _L( "" ) );  
       
  1452                    return;
       
  1453                 }
       
  1454             }
       
  1455         }
       
  1456     }
       
  1457 
       
  1458 // --------------------------------------------------------------------------
       
  1459 // void CSvgEngineImpl::RenderFrame( TUint aCurrentTime )
       
  1460 // ---------------------------------------------------------------------------
       
  1461 void CSvgEngineImpl::RenderFrame( TUint aCurrentTime )
       
  1462     {
       
  1463     if ( !iFrameBuffer || !iSvgDocument ||
       
  1464          iFrameBuffer->SizeInPixels().iWidth == 0 || iFrameBuffer->SizeInPixels().iHeight == 0 )
       
  1465         {
       
  1466         return;
       
  1467         }
       
  1468 
       
  1469     if ( aCurrentTime == 0 )
       
  1470         {
       
  1471         SeekEngine( 0 );
       
  1472         }
       
  1473 
       
  1474     iMouseoverElement = NULL;
       
  1475 
       
  1476      	CSvgSvgElementImpl* rootElement = (CSvgSvgElementImpl*)iSvgDocument->RootElement();
       
  1477 
       
  1478      	if (rootElement == NULL)
       
  1479      	{
       
  1480      		return;
       
  1481      	}
       
  1482 
       
  1483      	TGfxRectangle2D viewBoxRect;
       
  1484      	if (rootElement->GetViewBox(viewBoxRect))
       
  1485      	{
       
  1486      		//viewbox has been defined or set already
       
  1487    			if (viewBoxRect.iWidth == TFloatFixPt(0) || viewBoxRect.iHeight == TFloatFixPt(0))
       
  1488    			{
       
  1489    				//viewbox has no area so dont render
       
  1490    				return;
       
  1491    			}
       
  1492    		}
       
  1493 
       
  1494     if( iRequestObserver && iSvgDocument->iEventHandler )
       
  1495         {
       
  1496         iRequestObserver->UpdatePresentation( iSvgDocument->iEventHandler->AnimationElementsCount() );
       
  1497         }
       
  1498 
       
  1499     iSvgDocument->iInitialDrawFlag = ETrue;
       
  1500 
       
  1501     // Fix for animation element for testApp   
       
  1502     TSvgTick lTick;
       
  1503     lTick.iRealTimeTick = aCurrentTime;
       
  1504     lTick.iParentTcTick = 0;
       
  1505     iSvgDocument->TimeContainer()->ParentTimeContainerTick(lTick) ;
       
  1506     // Fix for animation element for testApp   
       
  1507     }
       
  1508 
       
  1509 
       
  1510 // ---------------------------------------------------------------------------
       
  1511 // Set SvgEngine Document
       
  1512 // ---------------------------------------------------------------------------
       
  1513 void CSvgEngineImpl::SetDocument(CSvgDocumentImpl* aDocument)
       
  1514     {
       
  1515     iSvgDocument = aDocument;
       
  1516     }
       
  1517 
       
  1518 
       
  1519 // ---------------------------------------------------------------------------
       
  1520 // Change the duration of the timer
       
  1521 // ---------------------------------------------------------------------------
       
  1522 void CSvgEngineImpl::ChangeDuration( TUint32 aTimerDuration )
       
  1523     {
       
  1524     if ( iSvgDocument )
       
  1525         {
       
  1526         iSvgDocument->TimeContainer()->UserChangeFrameDuration( 
       
  1527             aTimerDuration );
       
  1528         
       
  1529         // Check if there is animation element in the parent svg
       
  1530     RPointerArray<CSvgElementImpl> lAnimationEleList;
       
  1531     iSvgDocument->FindAllElements((CSvgElementImpl* )iSvgDocument->RootElement(),
       
  1532                KSvgMediaAnimationElement, lAnimationEleList );
       
  1533     TInt lAnimationEleCnt = lAnimationEleList.Count();    
       
  1534     for ( TInt lCurAnimationEle = 0; 
       
  1535              lCurAnimationEle < lAnimationEleCnt; lCurAnimationEle++ )
       
  1536         {
       
  1537         CSvgMediaAnimationElementImpl* lAnimationElement = 
       
  1538             (CSvgMediaAnimationElementImpl* )lAnimationEleList[ lCurAnimationEle ];
       
  1539         CSvgDocumentImpl* lChildDoc = lAnimationElement->GetChildDocument();
       
  1540         if ( lChildDoc )
       
  1541             {
       
  1542             lChildDoc->TimeContainer()->UserChangeFrameDuration( 
       
  1543             aTimerDuration ); // Change Frame duration for child svg
       
  1544             }
       
  1545         }
       
  1546         lAnimationEleList.Close();     
       
  1547     	}	   
       
  1548     }
       
  1549 
       
  1550 // --------------------------------------------------------------------------
       
  1551 // void CSvgEngineImpl::Resume(TInt32 aTime)
       
  1552 // ---------------------------------------------------------------------------
       
  1553 void CSvgEngineImpl::Resume(TInt32 aTime)
       
  1554     {
       
  1555     if ( iSvgDocument )
       
  1556         {
       
  1557         iSvgDocument->TimeContainer()->UserResume( aTime );
       
  1558         }
       
  1559     }
       
  1560 
       
  1561 // --------------------------------------------------------------------------
       
  1562 // void CSvgEngineImpl::FindBBoxesForRotatedText( const TDesC& aSearchString,
       
  1563 // ---------------------------------------------------------------------------
       
  1564 void CSvgEngineImpl::FindBBoxesForRotatedText( const TDesC& aSearchString,
       
  1565                            RPointerArray<MRect>& aBoundingBoxes,
       
  1566                                         RArray<TPtrC>& aTexts,
       
  1567                                         RArray<TInt>& aElementIds,
       
  1568                                         TBool aCaseSensitive )
       
  1569 {
       
  1570     if ( iSvgDocument == NULL )
       
  1571         return;
       
  1572 
       
  1573     if ( iSvgTextBoundingBoxes.Count() > 0 )
       
  1574     {
       
  1575     	iSvgTextBoundingBoxes.ResetAndDestroy();
       
  1576     }
       
  1577 
       
  1578     // Find all text elements
       
  1579 	HBufC* searchStr = aSearchString.AllocLC();    
       
  1580 	TPtr searchStrPtr = searchStr->Des();
       
  1581     RPointerArray<CSvgElementImpl> textElements;
       
  1582     iSvgDocument->FindAllElements( (CSvgElementImpl* )iSvgDocument->RootElement(),
       
  1583                      KSvgTextElement, textElements );
       
  1584     // Himanshu: Find all animation elements
       
  1585     RPointerArray<CSvgElementImpl> lAllAnimationElements;                                
       
  1586     iSvgDocument->FindAllElements( (CSvgElementImpl*)iSvgDocument->RootElement(),
       
  1587                                 KSvgMediaAnimationElement,
       
  1588                                 lAllAnimationElements );                                
       
  1589     TInt lAllAnimationEleCnt = lAllAnimationElements.Count();                            
       
  1590     for ( TInt i = 0; i < lAllAnimationEleCnt; i++ )
       
  1591         {
       
  1592           CSvgMediaAnimationElementImpl* element = (CSvgMediaAnimationElementImpl*)lAllAnimationElements[i];
       
  1593           CSvgDocumentImpl* ldoc = element->GetChildDocument();
       
  1594             if(ldoc)
       
  1595             {
       
  1596                 // Find all text elements in child document
       
  1597                 ldoc->FindAllElements( (CSvgElementImpl*)ldoc->RootElement(),
       
  1598                                 KSvgTextElement,
       
  1599                                 textElements );  
       
  1600             }
       
  1601           
       
  1602         }
       
  1603         lAllAnimationElements.Close();
       
  1604 
       
  1605     TSvgFourPointRect boundingBox;
       
  1606     TInt textEleCnt = textElements.Count();
       
  1607     for ( TInt i = 0; i < textEleCnt; i++ )
       
  1608     {
       
  1609         CSvgTextElementImpl* textElement = (CSvgTextElementImpl*)textElements[i];
       
  1610         TPtrC remainder( textElement->GetText() );
       
  1611 
       
  1612         TInt index = ( aCaseSensitive ) ? remainder.Find( aSearchString ) :
       
  1613                                           remainder.FindF( aSearchString );
       
  1614 
       
  1615         // continue to next element if nothing found
       
  1616         if ( index == KErrNotFound )
       
  1617             continue;
       
  1618 
       
  1619 		searchStrPtr.Copy( remainder.Mid(index,aSearchString.Length()) );
       
  1620         // Get the bounding box for the whole text element
       
  1621         textElement->GetFourPointBBox( boundingBox );
       
  1622 
       
  1623         // Get bounding box for every occurrence
       
  1624         TReal32 textAdvance = (TReal32)(textElement->TextAdvance( *searchStr, index ));
       
  1625         TReal32 leftAdvance = 0.0f;
       
  1626         //TReal32 aHeight = textElement->Ascent() + textElement->Descent();
       
  1627 
       
  1628         while ( index != KErrNotFound )
       
  1629         {
       
  1630             // Calculate boundingbox for searched-text
       
  1631             // indeterminate results with a string only one character long
       
  1632             leftAdvance = leftAdvance + (TReal32)(textElement->TextAdvance( remainder.Left( index )));
       
  1633 
       
  1634             // need to setup slope calculation here to determine where the new
       
  1635             // four point rect should be for partial pieces of text
       
  1636 
       
  1637             // need to do something for both vertical and horizontal text 0 and na slopes
       
  1638 
       
  1639             TReal32 dy = (TReal32)boundingBox.iPoint2.iY - (TReal32)boundingBox.iPoint1.iY;
       
  1640             TReal32 dx = (TReal32)boundingBox.iPoint2.iX - (TReal32)boundingBox.iPoint1.iX;
       
  1641 
       
  1642             double aSlopeRan;
       
  1643             Math::ATan(aSlopeRan, dy, dx);
       
  1644 
       
  1645             double aSinVal;
       
  1646             Math::Sin(aSinVal, aSlopeRan);
       
  1647 
       
  1648             double aCosVal;
       
  1649             Math::Cos(aCosVal, aSlopeRan);
       
  1650 
       
  1651 
       
  1652             TReal32 x1 = aCosVal * leftAdvance + (TReal32)boundingBox.iPoint1.iX;
       
  1653             TReal32 x3 = aCosVal * leftAdvance + (TReal32)boundingBox.iPoint3.iX;
       
  1654             TReal32 y1 = aSinVal * leftAdvance + (TReal32)boundingBox.iPoint1.iY;
       
  1655             TReal32 y3 = aSinVal * leftAdvance + (TReal32)boundingBox.iPoint3.iY;
       
  1656 
       
  1657             TReal32 x2 = aCosVal * textAdvance + x1;
       
  1658             TReal32 x4 = aCosVal * textAdvance + x3;
       
  1659 
       
  1660             TReal32 y2 = aSinVal * textAdvance + y1;
       
  1661             TReal32 y4 = aSinVal * textAdvance + y3;
       
  1662 
       
  1663 			TSvgFourPointRect* bbox = NULL;
       
  1664 
       
  1665             TRAP_IGNORE( bbox = new (ELeave) TSvgFourPointRect( TPoint(x1, y1),
       
  1666                         TPoint(x2, y2),
       
  1667                         TPoint(x3, y3),
       
  1668                         TPoint(x4, y4)) );
       
  1669 
       
  1670             if ( !bbox )
       
  1671             {
       
  1672             	#ifdef _DEBUG
       
  1673             		RDebug::Printf("Four Point Rect Failed: Out of Memory");
       
  1674             	#endif
       
  1675             	return;
       
  1676             }
       
  1677 
       
  1678             // store bound box pointers to go back to client
       
  1679             aBoundingBoxes.Append( (MRect*)bbox );
       
  1680 
       
  1681             iSvgTextBoundingBoxes.Append( bbox );
       
  1682 
       
  1683             // store point to text
       
  1684             aTexts.Append( TPtrC( textElement->GetText() ) );
       
  1685             aElementIds.Append( (TInt)textElement );
       
  1686 
       
  1687             remainder.Set( remainder.Right( remainder.Length() - index - aSearchString.Length() ) );
       
  1688             leftAdvance = leftAdvance + textAdvance;
       
  1689             index = ( aCaseSensitive ) ? remainder.Find( aSearchString ) :
       
  1690                                          remainder.FindF( aSearchString );
       
  1691         }
       
  1692     }
       
  1693     CleanupStack::PopAndDestroy(searchStr);
       
  1694     textElements.Close();
       
  1695 }
       
  1696 
       
  1697 //this is the old 2point rect way that only works for horizontal text
       
  1698 /*void CSvgEngineImpl::FindBBoxesForHorizontalText( const TDesC& aSearchString,
       
  1699                            RArray<TRect>& aBoundingBoxes,
       
  1700                                         RArray<TPtrC>& aTexts,
       
  1701                                         RArray<TInt>& aElementIds,
       
  1702                                         TBool aCaseSensitive                                        )
       
  1703 {
       
  1704     if ( iSvgDocument == NULL )
       
  1705         return;
       
  1706 
       
  1707     // Find all text elements
       
  1708     RPointerArray<CSvgElementImpl> textElements;
       
  1709     iSvgDocument->FindAllElements( (CSvgElementImpl* )iSvgDocument->RootElement(),
       
  1710                      KSvgTextElement, textElements );
       
  1711 
       
  1712     TGfxRectangle2D boundingBox;
       
  1713     for ( TInt i = 0; i < textElements.Count(); i++ )
       
  1714     {
       
  1715         CSvgTextElementImpl* textElement = (CSvgTextElementImpl*)textElements[i];
       
  1716         TPtrC remainder( textElement->GetText() );
       
  1717 
       
  1718         TInt index = ( aCaseSensitive ) ? remainder.Find( aSearchString ) :
       
  1719                                           remainder.FindF( aSearchString );
       
  1720 
       
  1721         // continue to next element if nothing found
       
  1722         if ( index == KErrNotFound )
       
  1723             continue;
       
  1724 
       
  1725         // Get the bounding box for the whole text element
       
  1726         textElement->GetBBox( boundingBox );
       
  1727 
       
  1728         // Get bounding box for every occurrence
       
  1729         TFloatFixPt textAdvance = textElement->TextAdvance( aSearchString, index );
       
  1730         TFloatFixPt leftAdvance = 0.0f;
       
  1731         while ( index != KErrNotFound )
       
  1732         {
       
  1733             // Calculate boundingbox for searched-text
       
  1734             leftAdvance = leftAdvance + textElement->TextAdvance( remainder.Left( index ), index );
       
  1735 
       
  1736             TRect bbox( (TInt)boundingBox.iX + (TInt)leftAdvance,
       
  1737                         (TInt)boundingBox.iY,
       
  1738                         (TInt)boundingBox.iX + (TInt)leftAdvance + (TInt)textAdvance,
       
  1739                         (TInt)boundingBox.iY + (TInt)boundingBox.iHeight );
       
  1740 
       
  1741             // store bound box
       
  1742             aBoundingBoxes.Append( bbox );
       
  1743 
       
  1744             // store point to text
       
  1745             aTexts.Append( TPtrC( textElement->GetText() ) );
       
  1746             aElementIds.Append( (TInt)textElement );
       
  1747 
       
  1748             remainder.Set( remainder.Right( remainder.Length() - index - aSearchString.Length() ) );
       
  1749             leftAdvance = leftAdvance + textAdvance;
       
  1750             index = ( aCaseSensitive ) ? remainder.Find( aSearchString ) :
       
  1751                                          remainder.FindF( aSearchString );
       
  1752         }
       
  1753     }
       
  1754     textElements.Close();
       
  1755 }
       
  1756 */
       
  1757 
       
  1758 /************************ HyperLinking Functions ***********************/
       
  1759 
       
  1760 // --------------------------------------------------------------------------
       
  1761 // void CSvgEngineImpl::CheckForHyperlinkMouseover( TInt aX, TInt aY )
       
  1762 // ---------------------------------------------------------------------------
       
  1763 void CSvgEngineImpl::CheckForHyperlinkMouseover( TInt aX, TInt aY )
       
  1764 {
       
  1765    if ( iHyperlinkListeners.Count() == 0 )
       
  1766         return;
       
  1767 
       
  1768     if ( iSvgDocument == NULL )
       
  1769         return;
       
  1770 
       
  1771     // Gather <a> elements if first time
       
  1772     RPointerArray<CSvgElementImpl> iAElementList;
       
  1773     if ( iAElementList.Count() == 0 )
       
  1774         {
       
  1775         iSvgDocument->FindAllElements( (CSvgElementImpl* )iSvgDocument->RootElement(),
       
  1776                          KSvgAElement, iAElementList );
       
  1777         }
       
  1778 
       
  1779     // find the bounding box containing point
       
  1780     TGfxPoint2D point( aX, aY );
       
  1781     TGfxRectangle2D boundingBox;
       
  1782     TInt aEleListCnt = iAElementList.Count();
       
  1783     for ( TInt i = 0; i < aEleListCnt; i++ )
       
  1784         {
       
  1785         CSvgElementImpl* element = iAElementList[i];
       
  1786         CSvgGElementImpl::GetGroupBounding( boundingBox, element );
       
  1787         if ( boundingBox.Contains( point ) )
       
  1788             {
       
  1789             // no existing mouse over element: notify HyperlinkEntered
       
  1790             if ( iMouseoverElement == NULL )
       
  1791                 {
       
  1792                 NotifyHyperlinkEntered( element->Href() );
       
  1793                 }
       
  1794             // otherwise: notify HyperlinkExited, HyperlinkEntered
       
  1795             else if ( iMouseoverElement != element )
       
  1796                 {
       
  1797                 NotifyHyperlinkExited( iMouseoverElement->Href() );
       
  1798                 NotifyHyperlinkEntered( element->Href() );
       
  1799                 }
       
  1800             iMouseoverElement = element;
       
  1801             return;
       
  1802             }
       
  1803         }
       
  1804 
       
  1805     // no bounding box containing point: notify HyperlinkExited
       
  1806     if ( iMouseoverElement != NULL )
       
  1807     {
       
  1808         NotifyHyperlinkExited( iMouseoverElement->Href() );
       
  1809         iMouseoverElement = NULL;
       
  1810     }
       
  1811 
       
  1812     iAElementList.Close();
       
  1813 }
       
  1814 
       
  1815 /*-------------------------Animation Listeners-----------------------------*/
       
  1816 // --------------------------------------------------------------------------
       
  1817 // void CSvgEngineImpl::AddAnimationListener( MSvgAnimationListener* aListener )
       
  1818 // ---------------------------------------------------------------------------
       
  1819 void CSvgEngineImpl::AddAnimationListener( MSvgAnimationListener* aListener )
       
  1820 {
       
  1821     if ( aListener != NULL && iAnimationListeners.Find( aListener ) == KErrNotFound )
       
  1822         iAnimationListeners.Append( aListener );
       
  1823 
       
  1824 }
       
  1825 
       
  1826 // --------------------------------------------------------------------------
       
  1827 // void CSvgEngineImpl::RemoveAnimationListener( MSvgAnimationListener* aListener )
       
  1828 // ---------------------------------------------------------------------------
       
  1829 void CSvgEngineImpl::RemoveAnimationListener( MSvgAnimationListener* aListener )
       
  1830 {
       
  1831     TInt index = iAnimationListeners.Find( aListener );
       
  1832     if ( index != KErrNotFound )
       
  1833         iAnimationListeners.Remove( index );
       
  1834 }
       
  1835 
       
  1836 /*-------------------------Animation listener notification to client-------*/
       
  1837 // --------------------------------------------------------------------------
       
  1838 // void CSvgEngineImpl::NotifyAnimationStarted()
       
  1839 // ---------------------------------------------------------------------------
       
  1840 void CSvgEngineImpl::NotifyAnimationStarted()
       
  1841 {
       
  1842 
       
  1843     TBool isAnimationIndefinite = EFalse;
       
  1844     if ( ( iSvgDocument == NULL ) || ( iSvgDocument->RootElement() == NULL ) ||
       
  1845          ( iAnimationListeners.Count() == 0 ) )
       
  1846     {
       
  1847         return;
       
  1848     }
       
  1849 
       
  1850     RPointerArray<CSvgElementImpl> AnimationElementList;
       
  1851 
       
  1852     iSvgDocument->FindAllElements( (CSvgElementImpl* )iSvgDocument->RootElement(),
       
  1853                                  KSvgSetElement, AnimationElementList );
       
  1854     iSvgDocument->FindAllElements( (CSvgElementImpl* )iSvgDocument->RootElement(),
       
  1855                                  KSvgAnimateElement, AnimationElementList );
       
  1856     iSvgDocument->FindAllElements( (CSvgElementImpl* )iSvgDocument->RootElement(),
       
  1857                                  KSvgAnimateMotionElement, AnimationElementList );
       
  1858     iSvgDocument->FindAllElements( (CSvgElementImpl* )iSvgDocument->RootElement(),
       
  1859                                  KSvgAnimateTransformElement, AnimationElementList );
       
  1860     iSvgDocument->FindAllElements( (CSvgElementImpl* )iSvgDocument->RootElement(),
       
  1861                                  KSvgAnimateColorElement, AnimationElementList );
       
  1862 
       
  1863     if ( AnimationElementList.Count() != 0 )
       
  1864     {
       
  1865     	TInt animationEleListCnt = AnimationElementList.Count();
       
  1866         for ( TInt i=0; i < animationEleListCnt; i++ )
       
  1867         {
       
  1868              CSvgElementImpl * element = AnimationElementList[i];
       
  1869               if ( ((CSvgAnimationBase *)element)->CompleteDuration() == KTimeIndefinite )  
       
  1870                 {
       
  1871                  isAnimationIndefinite = ETrue;
       
  1872                  break;
       
  1873                 }
       
  1874         }
       
  1875 
       
  1876     }
       
  1877    AnimationElementList.Close();
       
  1878 
       
  1879    TInt animationListenersCnt = iAnimationListeners.Count();
       
  1880    for ( TInt i = 0; i < animationListenersCnt; i++ )
       
  1881         iAnimationListeners[i]->AnimationStarted( isAnimationIndefinite );
       
  1882 
       
  1883 
       
  1884 }
       
  1885 
       
  1886 // --------------------------------------------------------------------------
       
  1887 // void CSvgEngineImpl::NotifyAnimationPaused()
       
  1888 // ---------------------------------------------------------------------------
       
  1889 void CSvgEngineImpl::NotifyAnimationPaused()
       
  1890 {
       
  1891 	TInt animationListenersCnt = iAnimationListeners.Count();
       
  1892     for ( TInt i = 0; i < animationListenersCnt; i++ )
       
  1893         iAnimationListeners[i]->AnimationPaused();
       
  1894 }
       
  1895 
       
  1896 // --------------------------------------------------------------------------
       
  1897 // void CSvgEngineImpl::NotifyAnimationEnded()
       
  1898 // ---------------------------------------------------------------------------
       
  1899 void CSvgEngineImpl::NotifyAnimationEnded()
       
  1900 {
       
  1901     if ( ( iSvgDocument == NULL ) || ( iSvgDocument->RootElement() == NULL ) ||
       
  1902          ( iAnimationListeners.Count() == 0 ) )
       
  1903     {
       
  1904         return;
       
  1905     }
       
  1906  #if 0
       
  1907     RPointerArray<CSvgElementImpl> AnimationElementList;
       
  1908 
       
  1909     FindAllElements( (CSvgElementImpl* )iSvgDocument->RootElement(),
       
  1910                                  KSvgSetElement, AnimationElementList );
       
  1911     FindAllElements( (CSvgElementImpl* )iSvgDocument->RootElement(),
       
  1912                                  KSvgAnimateElement, AnimationElementList );
       
  1913     FindAllElements( (CSvgElementImpl* )iSvgDocument->RootElement(),
       
  1914                                  KSvgAnimateMotionElement, AnimationElementList );
       
  1915     FindAllElements( (CSvgElementImpl* )iSvgDocument->RootElement(),
       
  1916                                  KSvgAnimateTransformElement, AnimationElementList );
       
  1917     FindAllElements( (CSvgElementImpl* )iSvgDocument->RootElement(),
       
  1918                                  KSvgAnimateColorElement, AnimationElementList );
       
  1919 
       
  1920     if ( AnimationElementList.Count() != 0 )
       
  1921     {
       
  1922     	TInt animationEleListCnt = AnimationElementList.Count();
       
  1923         for ( TInt i=0; i < animationEleListCnt; i++ )
       
  1924         {
       
  1925         CSvgElementImpl * element = AnimationElementList[i];
       
  1926         if ( ((CSvgAnimationBase *)element)->iAnimStatus == KAnimActive )
       
  1927             {
       
  1928              AnimationElementList.Close();
       
  1929              return;
       
  1930             }
       
  1931         }
       
  1932 
       
  1933     }
       
  1934      AnimationElementList.Close();
       
  1935 #endif
       
  1936 
       
  1937 	TInt animationListenersCnt = iAnimationListeners.Count();
       
  1938     for ( TInt i = 0; i < animationListenersCnt; i++ )
       
  1939         iAnimationListeners[i]->AnimationEnded();
       
  1940 
       
  1941 }
       
  1942 
       
  1943 /*------------------Register Client Text Area listeners----------------------------*/
       
  1944 // --------------------------------------------------------------------------
       
  1945 // void CSvgEngineImpl::AddTextAreaListener( MSvgTextAreaListener* aListener )
       
  1946 // ---------------------------------------------------------------------------
       
  1947 void CSvgEngineImpl::AddTextAreaListener( MSvgTextAreaListener* aListener )
       
  1948 {
       
  1949     if ( aListener != NULL && iTextAreaListeners.Find( aListener ) == KErrNotFound )
       
  1950     {
       
  1951         iTextAreaListeners.Append( aListener );
       
  1952     }
       
  1953 }
       
  1954 
       
  1955 // --------------------------------------------------------------------------
       
  1956 // void CSvgEngineImpl::RemoveTextAreaListener( MSvgTextAreaListener* aListener )
       
  1957 // ---------------------------------------------------------------------------
       
  1958 void CSvgEngineImpl::RemoveTextAreaListener( MSvgTextAreaListener* aListener )
       
  1959 {
       
  1960     TInt index = iTextAreaListeners.Find( aListener );
       
  1961     if ( index != KErrNotFound )
       
  1962     {
       
  1963         iTextAreaListeners.Remove( index );
       
  1964     }
       
  1965 }
       
  1966 
       
  1967 /*----------------Text Area listener notification to client--------------*/
       
  1968 // --------------------------------------------------------------------------
       
  1969 // void CSvgEngineImpl::NotifyTextAreaEntered( CSvgTextAreaElementImpl* aTextAreaHandle )
       
  1970 // ---------------------------------------------------------------------------
       
  1971 void CSvgEngineImpl::NotifyTextAreaEntered( CSvgTextAreaElementImpl* aTextAreaHandle )
       
  1972 {
       
  1973 	TInt textAreaListenersCnt = iTextAreaListeners.Count();
       
  1974     for (TInt i=0; i < textAreaListenersCnt; i++)
       
  1975     {
       
  1976         iTextAreaListeners[i]->TextAreaEntered( (TInt)aTextAreaHandle);
       
  1977     }
       
  1978 }
       
  1979 
       
  1980 // --------------------------------------------------------------------------
       
  1981 // void CSvgEngineImpl::NotifyTextAreaExited( CSvgTextAreaElementImpl* aTextAreaHandle )
       
  1982 // ---------------------------------------------------------------------------
       
  1983 void CSvgEngineImpl::NotifyTextAreaExited( CSvgTextAreaElementImpl* aTextAreaHandle )
       
  1984 {
       
  1985 	TInt textAreaListenersCnt = iTextAreaListeners.Count();
       
  1986     for (TInt i=0; i < textAreaListenersCnt; i++)
       
  1987     {
       
  1988         iTextAreaListeners[i]->TextAreaExited( (TInt)aTextAreaHandle);
       
  1989     }
       
  1990 }
       
  1991 
       
  1992 // --------------------------------------------------------------------------
       
  1993 // void CSvgEngineImpl::NotifyTextAreaActivated( CSvgTextAreaElementImpl* aTextAreaHandle )
       
  1994 // ---------------------------------------------------------------------------
       
  1995 void CSvgEngineImpl::NotifyTextAreaActivated( CSvgTextAreaElementImpl* aTextAreaHandle )
       
  1996 {
       
  1997 	TInt textAreaListenersCnt = iTextAreaListeners.Count();
       
  1998 	for (TInt i=0; i < textAreaListenersCnt; i++)
       
  1999     {
       
  2000         iTextAreaListeners[i]->TextAreaActivated( (TInt)aTextAreaHandle );
       
  2001     }
       
  2002 }
       
  2003 
       
  2004 /*------------------Register Client Text listeners----------------------------*/
       
  2005 // --------------------------------------------------------------------------
       
  2006 // void CSvgEngineImpl::AddTextListener( MSvgTextListener* aListener )
       
  2007 // ---------------------------------------------------------------------------
       
  2008 void CSvgEngineImpl::AddTextListener( MSvgTextListener* aListener )
       
  2009 {
       
  2010     if ( aListener != NULL && iTextListeners.Find( aListener ) == KErrNotFound )
       
  2011     {
       
  2012         iTextListeners.Append( aListener );
       
  2013     }
       
  2014 }
       
  2015 
       
  2016 // --------------------------------------------------------------------------
       
  2017 // void CSvgEngineImpl::RemoveTextListener( MSvgTextListener* aListener )
       
  2018 // ---------------------------------------------------------------------------
       
  2019 void CSvgEngineImpl::RemoveTextListener( MSvgTextListener* aListener )
       
  2020 {
       
  2021     TInt index = iTextListeners.Find( aListener );
       
  2022     if ( index != KErrNotFound )
       
  2023     {
       
  2024         iTextListeners.Remove( index );
       
  2025     }
       
  2026 }
       
  2027 
       
  2028 /*----------------Text listener notification to client--------------*/
       
  2029 // --------------------------------------------------------------------------
       
  2030 // void CSvgEngineImpl::NotifyTextEntered( CSvgTextElementImpl* aTextHandle )
       
  2031 // ---------------------------------------------------------------------------
       
  2032 void CSvgEngineImpl::NotifyTextEntered( CSvgTextElementImpl* aTextHandle )
       
  2033 {
       
  2034 	TInt textListenersCnt = iTextListeners.Count();
       
  2035     for (TInt i=0; i < textListenersCnt; i++)
       
  2036     {
       
  2037         iTextListeners[i]->TextEntered( (TInt)aTextHandle);
       
  2038     }
       
  2039 }
       
  2040 
       
  2041 // --------------------------------------------------------------------------
       
  2042 // void CSvgEngineImpl::NotifyTextExited( CSvgTextElementImpl* aTextHandle )
       
  2043 // ---------------------------------------------------------------------------
       
  2044 void CSvgEngineImpl::NotifyTextExited( CSvgTextElementImpl* aTextHandle )
       
  2045 {
       
  2046 	TInt textListenersCnt = iTextListeners.Count();
       
  2047     for (TInt i=0; i < textListenersCnt; i++)
       
  2048     {
       
  2049         iTextListeners[i]->TextExited( (TInt)aTextHandle);
       
  2050     }
       
  2051 }
       
  2052 
       
  2053 // --------------------------------------------------------------------------
       
  2054 // void CSvgEngineImpl::NotifyTextActivated( CSvgTextElementImpl* aTextHandle )
       
  2055 // ---------------------------------------------------------------------------
       
  2056 void CSvgEngineImpl::NotifyTextActivated( CSvgTextElementImpl* aTextHandle )
       
  2057 {
       
  2058 	TInt textListenersCnt = iTextListeners.Count();
       
  2059     for (TInt i=0; i < textListenersCnt; i++)
       
  2060     {
       
  2061         iTextListeners[i]->TextActivated( (TInt)aTextHandle );
       
  2062     }
       
  2063 }
       
  2064 
       
  2065 /*---------------------Register Client Hyperlink listeners----------------------------*/
       
  2066 // --------------------------------------------------------------------------
       
  2067 // void CSvgEngineImpl::AddHyperlinkListener( MSvgHyperlinkListener* aListener )
       
  2068 // ---------------------------------------------------------------------------
       
  2069 void CSvgEngineImpl::AddHyperlinkListener( MSvgHyperlinkListener* aListener )
       
  2070 {
       
  2071     if ( aListener != NULL && iHyperlinkListeners.Find( aListener ) == KErrNotFound )
       
  2072         iHyperlinkListeners.Append( aListener );
       
  2073 }
       
  2074 
       
  2075 // --------------------------------------------------------------------------
       
  2076 // void CSvgEngineImpl::RemoveHyperlinkListener( MSvgHyperlinkListener* aListener )
       
  2077 // ---------------------------------------------------------------------------
       
  2078 void CSvgEngineImpl::RemoveHyperlinkListener( MSvgHyperlinkListener* aListener )
       
  2079 {
       
  2080     TInt index = iHyperlinkListeners.Find( aListener );
       
  2081     if ( index != KErrNotFound )
       
  2082         iHyperlinkListeners.Remove( index );
       
  2083 }
       
  2084 
       
  2085 void CSvgEngineImpl::AddViewPortListener(MSvgViewPortListener* aListener)
       
  2086 {
       
  2087     if ( aListener != NULL )
       
  2088     {
       
  2089         iViewPortListener = aListener ;
       
  2090     }
       
  2091         
       
  2092 }
       
  2093   
       
  2094         
       
  2095 void CSvgEngineImpl::RemoveViewPortListener(MSvgViewPortListener* 
       
  2096         /* aListener */ )
       
  2097 {
       
  2098     if(iViewPortListener != NULL)
       
  2099     {
       
  2100         iViewPortListener = NULL;
       
  2101     }
       
  2102 }
       
  2103 /*----------------Hyperlink listener notification to client--------------*/
       
  2104 // --------------------------------------------------------------------------
       
  2105 // void CSvgEngineImpl::NotifyHyperlinkEntered( CSvgAElementImpl* aAElementHandle )
       
  2106 // ---------------------------------------------------------------------------
       
  2107 void CSvgEngineImpl::NotifyHyperlinkEntered( CSvgAElementImpl* aAElementHandle )
       
  2108 {
       
  2109 	TInt hyperLinkListenersCnt = iHyperlinkListeners.Count();
       
  2110     for ( TInt i = 0; i < hyperLinkListenersCnt; i++ )
       
  2111     {
       
  2112         if (aAElementHandle)
       
  2113         {
       
  2114             iHyperlinkListeners[i]->LinkEntered( aAElementHandle->Href() );
       
  2115         }
       
  2116     }
       
  2117 }
       
  2118 
       
  2119 // --------------------------------------------------------------------------
       
  2120 // void CSvgEngineImpl::NotifyHyperlinkEntered( const TDesC& aUri )
       
  2121 // ---------------------------------------------------------------------------
       
  2122 void CSvgEngineImpl::NotifyHyperlinkEntered( const TDesC& aUri )
       
  2123 {
       
  2124 	TInt hyperLinkListenersCnt = iHyperlinkListeners.Count();
       
  2125     for ( TInt i = 0; i < hyperLinkListenersCnt; i++ )
       
  2126     {
       
  2127         iHyperlinkListeners[i]->LinkEntered( aUri );
       
  2128     }
       
  2129 }
       
  2130 
       
  2131 // --------------------------------------------------------------------------
       
  2132 // void CSvgEngineImpl::NotifyHyperlinkExited( CSvgAElementImpl* aAElementHandle )
       
  2133 // ---------------------------------------------------------------------------
       
  2134 void CSvgEngineImpl::NotifyHyperlinkExited( CSvgAElementImpl* aAElementHandle )
       
  2135 {
       
  2136 	TInt hyperLinkListenersCnt = iHyperlinkListeners.Count();
       
  2137     for ( TInt i = 0; i < hyperLinkListenersCnt; i++ )
       
  2138     {
       
  2139         if (aAElementHandle)
       
  2140         {
       
  2141             iHyperlinkListeners[i]->LinkExited( aAElementHandle->Href() );
       
  2142         }
       
  2143     }
       
  2144 }
       
  2145 
       
  2146 // --------------------------------------------------------------------------
       
  2147 // void CSvgEngineImpl::NotifyHyperlinkExited( const TDesC& aUri )
       
  2148 // ---------------------------------------------------------------------------
       
  2149 void CSvgEngineImpl::NotifyHyperlinkExited( const TDesC& aUri )
       
  2150 {
       
  2151 	TInt hyperLinkListenersCnt = iHyperlinkListeners.Count();
       
  2152     for ( TInt i = 0; i < hyperLinkListenersCnt; i++ )
       
  2153     {
       
  2154         iHyperlinkListeners[i]->LinkExited( aUri );
       
  2155     }
       
  2156 }
       
  2157 
       
  2158 // --------------------------------------------------------------------------
       
  2159 // void CSvgEngineImpl::NotifyHyperlinkActivated( CSvgAElementImpl* aAElementHandle )
       
  2160 // ---------------------------------------------------------------------------
       
  2161 void CSvgEngineImpl::NotifyHyperlinkActivated( CSvgAElementImpl* aAElementHandle )
       
  2162 {
       
  2163     if ( !aAElementHandle ||
       
  2164           aAElementHandle->Href().Length() == 0 ||
       
  2165           aAElementHandle->Href()[0] == '#' )
       
  2166         {
       
  2167         return;
       
  2168         }
       
  2169 
       
  2170 	TInt hyperLinkListenersCnt = iHyperlinkListeners.Count();
       
  2171     for ( TInt i = 0; i < hyperLinkListenersCnt; i++ )
       
  2172     {
       
  2173         iHyperlinkListeners[i]->LinkActivated( aAElementHandle->Href() );
       
  2174     }
       
  2175 }
       
  2176 
       
  2177 // --------------------------------------------------------------------------
       
  2178 // void CSvgEngineImpl::NotifyHyperlinkActivated( const TDesC& aUri )
       
  2179 // ---------------------------------------------------------------------------
       
  2180 void CSvgEngineImpl::NotifyHyperlinkActivated( const TDesC& aUri )
       
  2181 {
       
  2182 	TInt hyperLinkListenersCnt = iHyperlinkListeners.Count();
       
  2183     for ( TInt i = 0; i < hyperLinkListenersCnt; i++ )
       
  2184     {
       
  2185         iHyperlinkListeners[i]->LinkActivated( aUri );
       
  2186     }
       
  2187 }
       
  2188 
       
  2189 // --------------------------------------------------------------------------
       
  2190 // void CSvgEngineImpl::NotifyHyperlinkActivatedWithShow( const TDesC& aUri, const TDesC& aShow )
       
  2191 // ---------------------------------------------------------------------------
       
  2192 void CSvgEngineImpl::NotifyHyperlinkActivatedWithShow( const TDesC& aUri, const TDesC& aShow )
       
  2193 {
       
  2194 	TInt hyperLinkListenersCnt = iHyperlinkListeners.Count();
       
  2195     for ( TInt i = 0; i < hyperLinkListenersCnt; i++ )
       
  2196         iHyperlinkListeners[i]->LinkActivatedWithShow( aUri, aShow );
       
  2197 }
       
  2198 
       
  2199 // --------------------------------------------------------------------------
       
  2200 // void CSvgEngineImpl::NotifyElementActivatedLinkEntered( CSvgElementImpl* aElement)
       
  2201 // ---------------------------------------------------------------------------
       
  2202 void CSvgEngineImpl::NotifyElementActivatedLinkEntered( CSvgElementImpl* aElement)
       
  2203     {
       
  2204       if(iMouseoverElement  == NULL)
       
  2205         {
       
  2206         const TDesC* myId = aElement->Id();
       
  2207 
       
  2208         if (myId)
       
  2209         NotifyHyperlinkEntered( *(myId));
       
  2210         iMouseoverElement = aElement;
       
  2211         }
       
  2212     }
       
  2213 // --------------------------------------------------------------------------
       
  2214 // void CSvgEngineImpl::NotifyElementActivatedLinkExited(  CSvgElementImpl* aElement)
       
  2215 // ---------------------------------------------------------------------------
       
  2216 void CSvgEngineImpl::NotifyElementActivatedLinkExited(  CSvgElementImpl* aElement)
       
  2217     {
       
  2218         if(iMouseoverElement == aElement )
       
  2219         {
       
  2220         const TDesC* myId = aElement->Id();
       
  2221 
       
  2222         if (myId)
       
  2223         NotifyHyperlinkExited( *(myId));
       
  2224         iMouseoverElement  = NULL;
       
  2225         }
       
  2226     }
       
  2227 void CSvgEngineImpl::GetViewPort(TInt getWidth, TInt getHeight, TBool isWidthInPer, TBool isHeightInPer, TInt &setWidth, TInt &setHeight)
       
  2228 {
       
  2229     if(iViewPortListener != NULL)
       
  2230     {
       
  2231         iViewPortListener->GetViewPort(getWidth, getHeight, isWidthInPer, isHeightInPer, setWidth, setHeight);
       
  2232     }
       
  2233 }
       
  2234 
       
  2235 /*------------------Register Client Interactive Element listeners------------*/
       
  2236 // --------------------------------------------------------------------------
       
  2237 // void CSvgEngineImpl::AddInteractiveElementListener( 
       
  2238 //                                  MSvgInteractiveElementListener* aListener )
       
  2239 // ---------------------------------------------------------------------------
       
  2240 void CSvgEngineImpl::AddInteractiveElementListener( 
       
  2241                                     MSvgInteractiveElementListener* aListener )
       
  2242     {
       
  2243     if ( 
       
  2244         aListener != NULL &&
       
  2245         iInteractiveElementListeners.Find( aListener ) == KErrNotFound )
       
  2246         {
       
  2247         iInteractiveElementListeners.Append( aListener );
       
  2248         }
       
  2249     }
       
  2250 
       
  2251 // --------------------------------------------------------------------------
       
  2252 // void CSvgEngineImpl::RemoveInteractiveElementListener( 
       
  2253 //                                  MSvgInteractiveElementListener* aListener )
       
  2254 // ---------------------------------------------------------------------------
       
  2255 void CSvgEngineImpl::RemoveInteractiveElementListener( 
       
  2256                                     MSvgInteractiveElementListener* aListener )
       
  2257     {
       
  2258     TInt index = iInteractiveElementListeners.Find( aListener );
       
  2259     if ( index != KErrNotFound )
       
  2260         {
       
  2261         iInteractiveElementListeners.Remove( index );
       
  2262         }
       
  2263     }
       
  2264 
       
  2265 /*-----------Interactive Element listener notification to client------------*/
       
  2266 // --------------------------------------------------------------------------
       
  2267 // void CSvgEngineImpl::NotifyInteractiveElementEntered(CSvgElementImpl* aElement)
       
  2268 // ---------------------------------------------------------------------------
       
  2269 void CSvgEngineImpl::NotifyInteractiveElementEntered(
       
  2270                         CSvgElementImpl* aElement)
       
  2271     {
       
  2272     TUint16 lsubeventmask=0; 
       
  2273     TBool linteractivity;
       
  2274     linteractivity=this->iSvgDocument->iEventHandler->
       
  2275     CheckInteractivityAndGetSubEventMask(aElement,lsubeventmask);
       
  2276     if(linteractivity)
       
  2277         {
       
  2278         TInt linteractiveElementListenersCnt = iInteractiveElementListeners.Count();
       
  2279         for ( TInt i = 0; i < linteractiveElementListenersCnt; i++ )
       
  2280             {
       
  2281             const TDesC* myId = aElement->Id();
       
  2282             TPtrC16 ptr;
       
  2283             if(myId)
       
  2284                 {
       
  2285                 ptr.Set(*myId);               
       
  2286                 }
       
  2287             else
       
  2288                 {
       
  2289                 _LIT(KEmptyString,"");
       
  2290                 ptr.Set( KEmptyString);                      
       
  2291                 }
       
  2292             iInteractiveElementListeners[i]->InteractiveElementEntered( 
       
  2293                                                ptr,lsubeventmask  ); 
       
  2294             }
       
  2295         }
       
  2296     }
       
  2297 // --------------------------------------------------------------------------
       
  2298 // void CSvgEngineImpl::NotifyInteractiveElementExited(CSvgElementImpl* aElement)
       
  2299 // ---------------------------------------------------------------------------
       
  2300 void CSvgEngineImpl::NotifyInteractiveElementExited(CSvgElementImpl* aElement)
       
  2301     {
       
  2302 	TInt linteractiveElementListenersCnt = iInteractiveElementListeners.Count();
       
  2303     for ( TInt i = 0; i < linteractiveElementListenersCnt; i++ )
       
  2304         {
       
  2305         const TDesC* myId = aElement->Id();
       
  2306         TPtrC16 ptr;
       
  2307         if(myId)
       
  2308             {            
       
  2309             ptr.Set(*myId);
       
  2310             }
       
  2311         else
       
  2312             {
       
  2313             _LIT(KEmptyString,"");
       
  2314             ptr.Set(KEmptyString);
       
  2315             }               
       
  2316         iInteractiveElementListeners[i]->InteractiveElementExited(ptr);
       
  2317         }
       
  2318 	}
       
  2319 
       
  2320 // ---------------------------------------------------------------------------
       
  2321 // Set SVG Dimension to frame buffer size
       
  2322 // ---------------------------------------------------------------------------
       
  2323 void CSvgEngineImpl::SetSvgDimensionToFrameBufferL(TUint aWidth, TUint aHeight)
       
  2324     {
       
  2325      if (iSvgDocument == NULL )   return;
       
  2326      if (iSvgDocument->RootElement() != NULL)
       
  2327          {
       
  2328          CSvgElementImpl* theElement = (CSvgElementImpl*)(iSvgDocument->RootElement());
       
  2329          ((CSvgSvgElementImpl*)theElement)->iWidthInUserCoordinate = 0;
       
  2330          ((CSvgSvgElementImpl*)theElement)->iHeightInUserCoordinate = 0;
       
  2331          TFloatFixPt wFix( (TInt)aWidth );
       
  2332          TFloatFixPt hFix( (TInt)aHeight );
       
  2333          theElement->SetAttributeFloatL(KAtrWidth, wFix );
       
  2334          theElement->SetAttributeFloatL(KAtrHeight, hFix );
       
  2335          }
       
  2336 
       
  2337     }
       
  2338 
       
  2339 // --------------------------------------------------------------------------
       
  2340 // void CSvgEngineImpl::SetMediaTime(TUint32 aTimeInMilliSeconds)
       
  2341 // ---------------------------------------------------------------------------
       
  2342 void CSvgEngineImpl::SetMediaTime(TUint32 aTimeInMilliSeconds)
       
  2343     {
       
  2344     // Set Current Time in the document
       
  2345     if(iSvgDocument != NULL)
       
  2346         {
       
  2347         //iSvgDocument->SetCurrentTime( aTimeInMilliSeconds );
       
  2348         
       
  2349         iSvgDocument->iAnimationResetNeeded = ETrue;
       
  2350         }
       
  2351     if(this->iSvgDocument && this->iSvgDocument->iEventHandler)
       
  2352         {
       
  2353         this->iSvgDocument->iEventHandler->SetCurrentTime(aTimeInMilliSeconds);
       
  2354         }
       
  2355    // Find all animation elements in the document    
       
  2356     RPointerArray<CSvgElementImpl> lAnimationEleList;
       
  2357     if(iSvgDocument)
       
  2358 	    {
       
  2359     iSvgDocument->FindAllElements((CSvgElementImpl* )iSvgDocument->RootElement(),
       
  2360                KSvgMediaAnimationElement, lAnimationEleList );
       
  2361     TInt lAnimationEleCnt = lAnimationEleList.Count();    
       
  2362     for ( TInt lCurAnimationEle = 0; 
       
  2363              lCurAnimationEle < lAnimationEleCnt; lCurAnimationEle++ )
       
  2364         {
       
  2365         CSvgMediaAnimationElementImpl* lAnimationElement = 
       
  2366             (CSvgMediaAnimationElementImpl* )lAnimationEleList[ lCurAnimationEle ];
       
  2367         CSvgDocumentImpl* lChildDoc = lAnimationElement->GetChildDocument();
       
  2368         if ( lChildDoc )
       
  2369             {
       
  2370             lChildDoc->iAnimationResetNeeded = ETrue;
       
  2371             if ( lChildDoc->iEventHandler )    
       
  2372                 {
       
  2373                 lChildDoc->iEventHandler->SetCurrentTime(aTimeInMilliSeconds); 
       
  2374                 }
       
  2375             
       
  2376             }
       
  2377         }
       
  2378     lAnimationEleList.Close();     
       
  2379 	    	
       
  2380 	    }
       
  2381     this->SetSVGEngineState(ESVGEnginePaused);
       
  2382     this->SeekEngine(aTimeInMilliSeconds);
       
  2383 
       
  2384     }
       
  2385 
       
  2386 // --------------------------------------------------------------------------
       
  2387 // TBool CSvgEngineImpl::IsElementVisible( TInt aElementId )
       
  2388 // ---------------------------------------------------------------------------
       
  2389 TBool CSvgEngineImpl::IsElementVisible( TInt aElementId )
       
  2390     {
       
  2391     if ( aElementId == 0 || iFrameBuffer == NULL )
       
  2392         {
       
  2393         return EFalse;
       
  2394         }
       
  2395 
       
  2396     CSvgElementImpl* element = (CSvgElementImpl*)aElementId;
       
  2397 
       
  2398     TInt32 visibleAttribute = -1;
       
  2399 
       
  2400     TRAPD(error,element->GetAttributeIntL( KCSS_ATTR_VISIBILITY, visibleAttribute ));
       
  2401     if (error != KErrNone)
       
  2402        {
       
  2403        // error processing
       
  2404        }
       
  2405 
       
  2406 
       
  2407     return visibleAttribute == 0;
       
  2408     }
       
  2409 
       
  2410 // Set whether to call request observer's UpdateScreen method
       
  2411 // --------------------------------------------------------------------------
       
  2412 // void CSvgEngineImpl::SetIgnoreUpdateScreen( TBool aBool )
       
  2413 // ---------------------------------------------------------------------------
       
  2414 void CSvgEngineImpl::SetIgnoreUpdateScreen( TBool aBool )
       
  2415 {
       
  2416     iIgnoreUpdateScreen = aBool;
       
  2417 }
       
  2418 
       
  2419 /*---------------------------MouseListener---------------------------*/
       
  2420 // --------------------------------------------------------------------------
       
  2421 // void CSvgEngineImpl::AddMouseListener( const MSvgMouseListener* aListener )
       
  2422 // ---------------------------------------------------------------------------
       
  2423 void CSvgEngineImpl::AddMouseListener( const MSvgMouseListener* aListener )
       
  2424     {
       
  2425     TInt index = iSvgMouseListeners.Find( aListener );
       
  2426     if ( aListener != NULL && index == KErrNotFound )
       
  2427         {
       
  2428         iSvgMouseListeners.Append( aListener );
       
  2429         }
       
  2430     }
       
  2431 
       
  2432 // --------------------------------------------------------------------------
       
  2433 // void CSvgEngineImpl::RemoveMouseListener( const MSvgMouseListener* aListener )
       
  2434 // ---------------------------------------------------------------------------
       
  2435 void CSvgEngineImpl::RemoveMouseListener( const MSvgMouseListener* aListener )
       
  2436     {
       
  2437     TInt index = iSvgMouseListeners.Find( aListener );
       
  2438     if ( index != KErrNotFound )
       
  2439         {
       
  2440         iSvgMouseListeners.Remove( index );
       
  2441         }
       
  2442     }
       
  2443 
       
  2444 // --------------------------------------------------------------------------
       
  2445 // TInt CSvgEngineImpl::MouseListenerCount()
       
  2446 // ---------------------------------------------------------------------------
       
  2447 TInt CSvgEngineImpl::MouseListenerCount()
       
  2448     {
       
  2449     return iSvgMouseListeners.Count();
       
  2450     }
       
  2451 
       
  2452 /*-------------MouseListener Notifications back to client---------------------------*/
       
  2453 // --------------------------------------------------------------------------
       
  2454 // void CSvgEngineImpl::NotifyMousePressed( RPointerArray<CSvgElementImpl>& aElements,
       
  2455 // ---------------------------------------------------------------------------
       
  2456 void CSvgEngineImpl::NotifyMousePressed( RPointerArray<CSvgElementImpl>& aElements,
       
  2457                                           TInt aX, TInt aY )
       
  2458     {
       
  2459     TInt svgMouseListenersCnt = iSvgMouseListeners.Count();
       
  2460     for ( TInt i = 0; i < svgMouseListenersCnt; i++ )
       
  2461         {
       
  2462         iSvgMouseListeners[i]->MousePressed( aElements, aX, aY );
       
  2463         }
       
  2464     }
       
  2465 
       
  2466 // --------------------------------------------------------------------------
       
  2467 // void CSvgEngineImpl::NotifyMouseReleased( RPointerArray<CSvgElementImpl>& aElements,
       
  2468 // ---------------------------------------------------------------------------
       
  2469 void CSvgEngineImpl::NotifyMouseReleased( RPointerArray<CSvgElementImpl>& aElements,
       
  2470                                           TInt aX, TInt aY )
       
  2471     {
       
  2472     TInt svgMouseListenersCnt = iSvgMouseListeners.Count();
       
  2473     for ( TInt i = 0; i < svgMouseListenersCnt; i++ )
       
  2474         {
       
  2475         iSvgMouseListeners[i]->MouseReleased( aElements, aX, aY );
       
  2476         }
       
  2477     }
       
  2478 
       
  2479 // --------------------------------------------------------------------------
       
  2480 // void CSvgEngineImpl::NotifyMouseEntered( RPointerArray<CSvgElementImpl>& aElements,
       
  2481 // ---------------------------------------------------------------------------
       
  2482 void CSvgEngineImpl::NotifyMouseEntered( RPointerArray<CSvgElementImpl>& aElements,
       
  2483                                           TInt aX, TInt aY )
       
  2484     {
       
  2485     TInt svgMouseListenersCnt = iSvgMouseListeners.Count();
       
  2486     for ( TInt i = 0; i < svgMouseListenersCnt; i++ )
       
  2487         {
       
  2488         iSvgMouseListeners[i]->MouseEntered( aElements, aX, aY );
       
  2489         }
       
  2490     }
       
  2491 
       
  2492 // --------------------------------------------------------------------------
       
  2493 // void CSvgEngineImpl::NotifyMouseExited( RPointerArray<CSvgElementImpl>& aElements,
       
  2494 // ---------------------------------------------------------------------------
       
  2495 void CSvgEngineImpl::NotifyMouseExited( RPointerArray<CSvgElementImpl>& aElements,
       
  2496                                           TInt aX, TInt aY )
       
  2497     {
       
  2498     TInt svgMouseListenersCnt = iSvgMouseListeners.Count();
       
  2499     for ( TInt i = 0; i < svgMouseListenersCnt; i++ )
       
  2500         {
       
  2501         iSvgMouseListeners[i]->MouseExited( aElements, aX, aY );
       
  2502         }
       
  2503     }
       
  2504 
       
  2505 // --------------------------------------------------------------------------
       
  2506 // void CSvgEngineImpl::NotifyMouseMoved( RPointerArray<CSvgElementImpl>& aElements,
       
  2507 // ---------------------------------------------------------------------------
       
  2508 void CSvgEngineImpl::NotifyMouseMoved( RPointerArray<CSvgElementImpl>& aElements,
       
  2509                                        TInt aX, TInt aY )
       
  2510     {
       
  2511     TInt svgMouseListenersCnt = iSvgMouseListeners.Count();
       
  2512     for ( TInt i = 0; i < svgMouseListenersCnt; i++ )
       
  2513         {
       
  2514         iSvgMouseListeners[i]->MouseMoved( aElements, aX, aY );
       
  2515         }
       
  2516     }
       
  2517 
       
  2518 /*---------------------------------------------------------------------*/
       
  2519 
       
  2520 // --------------------------------------------------------------------------
       
  2521 // void CSvgEngineImpl::GetViewableElementsAtPoint( RPointerArray<CSvgElementImpl>& aElements, TInt aX, TInt aY )
       
  2522 // ---------------------------------------------------------------------------
       
  2523 void CSvgEngineImpl::GetViewableElementsAtPoint( CSvgDocumentImpl* aSvgDocument, RPointerArray<CSvgElementImpl>& aElements, TInt aX, TInt aY )
       
  2524     {
       
  2525    if ( aSvgDocument == NULL )
       
  2526         return;
       
  2527 
       
  2528 	//JSR226 Change this could slow down event handling but it seems to be required to work
       
  2529    UpdateCTM(aSvgDocument);
       
  2530 
       
  2531     // Gather all "viewable" elements
       
  2532     RPointerArray<CSvgElementImpl> iViewableElementList;
       
  2533     if ( iViewableElementList.Count() == 0 )
       
  2534         {
       
  2535         FindAllViewableElements( (CSvgElementImpl* )aSvgDocument->RootElement(),
       
  2536                                  iViewableElementList );
       
  2537         }
       
  2538 
       
  2539     // find the bounding box containing point
       
  2540     TGfxPoint2D point( aX, aY );
       
  2541     TGfxRectangle2D boundingBox;
       
  2542     TInt viewableEleListCnt =  iViewableElementList.Count();
       
  2543     for ( TInt i = 0; i < viewableEleListCnt; i++ )
       
  2544         {
       
  2545         CSvgElementImpl* element = iViewableElementList[i];
       
  2546         element->GetBBox( boundingBox );
       
  2547         if ( boundingBox.Contains( point ) )
       
  2548             {
       
  2549             aElements.Append( element );
       
  2550             }
       
  2551         }
       
  2552     // Display of list
       
  2553     iViewableElementList.Close();
       
  2554     }
       
  2555 
       
  2556 // Return all viewable elements
       
  2557 // --------------------------------------------------------------------------
       
  2558 // void CSvgEngineImpl::FindAllViewableElements( CSvgElementImpl* aStartElement,
       
  2559 // ---------------------------------------------------------------------------
       
  2560 void CSvgEngineImpl::FindAllViewableElements( CSvgElementImpl* aStartElement,
       
  2561                                               RPointerArray<CSvgElementImpl>& iElementList )
       
  2562     {
       
  2563     if ( aStartElement == NULL )
       
  2564         return;
       
  2565     // The child elements of the defs element should not be viewable. skip the
       
  2566     // tree traversing if the element id is defs element
       
  2567     if(aStartElement->ElemID() == KSvgDefsElement)
       
  2568         return;
       
  2569 
       
  2570     CSvgElementImpl* child = (CSvgElementImpl*)aStartElement->FirstChild();
       
  2571     while ( child != NULL )
       
  2572         {
       
  2573         // add to list if child is found
       
  2574         TInt32 displayValue = 0;
       
  2575         TRAP_IGNORE(child->GetAttributeIntL( KCSS_ATTR_DISPLAY, displayValue ));
       
  2576         if ( child->IsViewable() && child->IsVisible() && displayValue != KDisplayEnumNone )
       
  2577             {
       
  2578 				//JSR226 CHANGE do we care if multiple signals are sent to some elements - would be faster without this check
       
  2579             	if ( iElementList.Find( child ) == KErrNotFound )
       
  2580             	{
       
  2581             		iElementList.Append( child );
       
  2582 				}
       
  2583 			}
       
  2584         // find in grandchildren
       
  2585         FindAllViewableElements( child, iElementList );
       
  2586         child = (CSvgElementImpl*)child->NextSibling();
       
  2587         }
       
  2588     }
       
  2589 
       
  2590 // Return all non-viewable elements
       
  2591 // --------------------------------------------------------------------------
       
  2592 // void CSvgEngineImpl::FindAllNonViewableElements( CSvgElementImpl* aStartElement,
       
  2593 // ---------------------------------------------------------------------------
       
  2594 void CSvgEngineImpl::FindAllNonViewableElements( CSvgElementImpl* aStartElement,
       
  2595                                                  RPointerArray<CSvgElementImpl>& iElementList )
       
  2596     {
       
  2597     if ( aStartElement == NULL )
       
  2598         return;
       
  2599 
       
  2600     CSvgElementImpl* child = (CSvgElementImpl*)aStartElement->FirstChild();
       
  2601     while ( child != NULL )
       
  2602         {
       
  2603         // add to list if child is found
       
  2604         if ( !child->IsViewable() && !child->IsVisible() )
       
  2605             iElementList.Append( child );
       
  2606 
       
  2607         // find in grandchildren
       
  2608         FindAllNonViewableElements( child, iElementList );
       
  2609         child = (CSvgElementImpl*)child->NextSibling();
       
  2610         }
       
  2611     }
       
  2612 
       
  2613 /**
       
  2614  * Return the data pointed to by the given URI string,
       
  2615  * from an external source.
       
  2616  */
       
  2617 // --------------------------------------------------------------------------
       
  2618 // HBufC8* CSvgEngineImpl::FetchExternalDataL( const TDesC& aUri )
       
  2619 // ---------------------------------------------------------------------------
       
  2620 HBufC8* CSvgEngineImpl::FetchExternalDataL( const TDesC& aUri )
       
  2621     {
       
  2622     if ( iRequestObserver == NULL )
       
  2623         {
       
  2624         #ifdef _DEBUG
       
  2625         RDebug::Printf("CSvgEngineImpl::FetchExternalData--requestobserver is NULL\n");
       
  2626         #endif //_DEBUG
       
  2627         return NULL;
       
  2628         }
       
  2629     // Connect session
       
  2630     RFs session;
       
  2631     TInt connectError = session.Connect();
       
  2632     if ( connectError != KErrNone )
       
  2633         {
       
  2634         #ifdef _DEBUG
       
  2635         RDebug::Printf("CSvgEngineImpl::FetchExternalData--session.Connect() failed: %d\n", connectError );
       
  2636         #endif //_DEBUG
       
  2637         return NULL;
       
  2638         }
       
  2639 
       
  2640     RFile fileHandle;
       
  2641     // Check for FetchImage error code
       
  2642     TInt fetchError = iRequestObserver->FetchImage( aUri, session, fileHandle );
       
  2643     if ( fetchError != KErrNone )
       
  2644         {
       
  2645         #ifdef _DEBUG
       
  2646         RDebug::Printf("CSvgEngineImpl::FetchExternalData--FetchImage error: %d\n", fetchError );
       
  2647         #endif //_DEBUG
       
  2648         session.Close();
       
  2649         return NULL;
       
  2650         }
       
  2651 
       
  2652     // Read file size
       
  2653     TInt fileSize = 0;
       
  2654     TInt sizeError = fileHandle.Size( fileSize );
       
  2655     if ( sizeError != KErrNone )
       
  2656         {
       
  2657         #ifdef _DEBUG
       
  2658         RDebug::Printf("CSvgEngineImpl::FetchExternalData--fileHandle.Size error: %d\n", sizeError );
       
  2659         #endif //_DEBUG
       
  2660         session.Close();
       
  2661         return NULL;
       
  2662         }
       
  2663 
       
  2664     // Allocate memory for file
       
  2665     HBufC8* data = HBufC8::NewL( fileSize );
       
  2666     TPtr8 des = data->Des();
       
  2667     TInt readError = fileHandle.Read( des );
       
  2668     if ( readError != KErrNone )
       
  2669         {
       
  2670         #ifdef _DEBUG
       
  2671         RDebug::Printf("CSvgEngineImpl::FetchExternalData--fileHandle.Read error: %d\n", readError );
       
  2672         #endif //_DEBUG
       
  2673         session.Close();
       
  2674         delete data;
       
  2675         return NULL;
       
  2676         }
       
  2677 
       
  2678     // Successful
       
  2679     session.Close();
       
  2680     return data;
       
  2681     }
       
  2682 // --------------------------------------------------------------------------
       
  2683 // void CSvgEngineImpl::SetAudioVolume( TInt aPercentage );
       
  2684 // --------------------------------------------------------------------------
       
  2685 void CSvgEngineImpl::SetAudioVolume( TInt aPercentage )
       
  2686     {
       
  2687     
       
  2688     if ( !iSvgDocument )
       
  2689         {
       
  2690         return;
       
  2691         }
       
  2692     // Locate all the active audio elements
       
  2693     RPointerArray<CSvgElementImpl> lAudioElementList;
       
  2694     
       
  2695     iSvgDocument->FindAllElements( 
       
  2696             (CSvgElementImpl* )iSvgDocument->RootElement(),
       
  2697             KSvgAudioElement, lAudioElementList );
       
  2698     // Set the volume on each audio element
       
  2699     TInt lAudEleCnt = lAudioElementList.Count();
       
  2700     for ( TInt lCurAudioEle = 0; lCurAudioEle < lAudEleCnt; lCurAudioEle++ )
       
  2701         {
       
  2702         CSvgAudioElementImpl* lAudioElement = (CSvgAudioElementImpl*)lAudioElementList[ lCurAudioEle ];
       
  2703         lAudioElement->SetVolume( aPercentage );
       
  2704         }
       
  2705     lAudioElementList.Close();
       
  2706     }
       
  2707 
       
  2708 // --------------------------------------------------------------------------
       
  2709 // TBool CSvgEngineImpl::ReadyToRender()
       
  2710 // ---------------------------------------------------------------------------
       
  2711 TBool CSvgEngineImpl::ReadyToRender()
       
  2712     {
       
  2713     return iSvgDocument != NULL;
       
  2714     }
       
  2715 
       
  2716 // --------------------------------------------------------------------------
       
  2717 // TBool CSvgEngineImpl::IsEndedWithCompleteTextTag( TDes &BufferPtr,
       
  2718 //                                                   TInt EndOffset)
       
  2719 // ---------------------------------------------------------------------------
       
  2720 TBool CSvgEngineImpl::IsEndedWithCompleteTextTag(TDes &aBufferPtr,TInt aEndOffset)
       
  2721     {
       
  2722     TChar KOpeningBrace = '<';
       
  2723     TChar KSlash = '/';
       
  2724 
       
  2725     // This function searches the buffer in reverse order from the end offset
       
  2726     // to check whether the last element had a complete text tag.
       
  2727     // eg. of complete text tags
       
  2728     //          <text>Hello</text>
       
  2729     //          <text></text>
       
  2730     // eg. of an incomplete text tag
       
  2731     //          <text />
       
  2732 
       
  2733     TPtrC currentSelectionPtr = aBufferPtr.Left( aEndOffset );
       
  2734     TInt OpeningBracePos = currentSelectionPtr.LocateReverse( KOpeningBrace );
       
  2735     TInt SlashPos = currentSelectionPtr.LocateReverse( KSlash );
       
  2736     TBool retVal = EFalse;
       
  2737 
       
  2738     // In case of a complete text tag the opening brace is one position behind
       
  2739     // slash.
       
  2740     if ( SlashPos == ( OpeningBracePos + 1 ) )
       
  2741         {
       
  2742         retVal = ETrue;
       
  2743         }
       
  2744 
       
  2745     return retVal;
       
  2746     }
       
  2747 
       
  2748 // --------------------------------------------------------------------------
       
  2749 // void CSvgEngineImpl::SaveSvgL( const TDesC& aFileName )
       
  2750 // ---------------------------------------------------------------------------
       
  2751 void CSvgEngineImpl::SaveSvgL( const TDesC& aFileName )
       
  2752     {
       
  2753     RFs  lFs;
       
  2754     RFileWriteStream  lStream;
       
  2755     TInt error ;
       
  2756     TChar KOpeningBrace = '<';
       
  2757     TChar KSlash = '/';
       
  2758     // Connect to File Server to write the changed content to a file
       
  2759     CleanupClosePushL(lFs);
       
  2760     User::LeaveIfError(lFs.Connect() );
       
  2761 
       
  2762     TBool isOpened = EFalse;
       
  2763     error = lFs.IsFileOpen( aFileName, isOpened ) ;
       
  2764     // dont leave if file doesnt exist or there is no error
       
  2765     if(error!= KErrNone && error!=KErrNotFound)
       
  2766         {
       
  2767         //usually will come here with KErrNotFound
       
  2768         //since file wont exist
       
  2769         User::Leave(error);
       
  2770         }
       
  2771 
       
  2772     if ( isOpened )
       
  2773         {
       
  2774         #ifdef _DEBUG
       
  2775         RDebug::Printf( "Cannot SaveSvgL: File is still opened: ");
       
  2776         RDebug::RawPrint( aFileName );
       
  2777         #endif
       
  2778         CleanupStack::PopAndDestroy(1);
       
  2779         return;
       
  2780         }
       
  2781 
       
  2782     // Try to create the write stream using the file name
       
  2783     if ( lStream.Create( lFs, aFileName, EFileWrite ) != KErrNone )
       
  2784         {
       
  2785         // If creation fails, file exists already, try to open the
       
  2786         // existing file
       
  2787         User::LeaveIfError( lStream.Open(lFs, aFileName, EFileWrite) );
       
  2788         }
       
  2789     CleanupClosePushL(lStream);
       
  2790 
       
  2791     // Array to store list of all editable elements
       
  2792     RPointerArray<CSvgElementImpl> lTextElementList;
       
  2793 
       
  2794     FindEditableElements( (CSvgElementImpl* )iSvgDocument->RootElement(),
       
  2795                           lTextElementList );
       
  2796     CleanupClosePushL(lTextElementList);
       
  2797     TInt index=0, startoffset = 0, endoffset = 0;
       
  2798 
       
  2799     // The content of the file is stored in the root <svg> node
       
  2800     HBufC*  lBufferContent = ((CSvgSvgElementImpl* )iSvgDocument->RootElement())->iContent;
       
  2801 
       
  2802 
       
  2803 
       
  2804     // While there are remaining editable elements do
       
  2805     while(index < lTextElementList.Count())
       
  2806         {
       
  2807         TBool EndedWithCompleteTextTag= true;
       
  2808         TInt OrgLength;
       
  2809 
       
  2810         if ( lTextElementList[index]->ElemID() == KSvgTextElement )
       
  2811             {
       
  2812             // If the element is a <text> element invoke element specific function
       
  2813             // to retrieve the offset and original length
       
  2814             endoffset = ((CSvgTextElementImpl *)lTextElementList[index])->iOffset;
       
  2815             OrgLength = ((CSvgTextElementImpl *)lTextElementList[index])->GetOrgLength();
       
  2816             }
       
  2817         else
       
  2818             {
       
  2819             // If the element is a <textArea> element invoke element specific function
       
  2820             // to retrieve the offset and original length
       
  2821             endoffset = ((CSvgTextAreaElementImpl *)lTextElementList[index])->iOffset;
       
  2822             OrgLength = ((CSvgTextAreaElementImpl *)lTextElementList[index])->GetOrgLength();
       
  2823             }
       
  2824 
       
  2825         // These are the cases which have to be processed
       
  2826         //     a. Text Element: No Closing Tag: <text  ... />
       
  2827         //     b. Text Element: No CData : <text ...></text>
       
  2828         //     c. Text Element: CData : <text ...>Sample Text</text>
       
  2829         //     d. TextArea Element: No Closing Tag: <textArea ... />
       
  2830         //     e. TextArea Element: No CData: <textArea ...></textArea>
       
  2831         //     f. TextArea Element: CData: <textArea ...>Sample TextArea</textArea>
       
  2832         //     -> for a,b,d,e the endoffset represents the offset after the closing braces.
       
  2833         //        for e.g.  <text ... />
       
  2834         //                              ^
       
  2835         //        <text></text>
       
  2836         //                     ^
       
  2837         //     -> for c,f the EndOffset represents the offset to the first character in
       
  2838         //        content.
       
  2839         //        <text>Hello</text>
       
  2840         //
       
  2841         //              ^
       
  2842         if(!OrgLength)
       
  2843             {
       
  2844             //case a,b,d,e
       
  2845             TPtr BufferPtr=lBufferContent->Des();
       
  2846             EndedWithCompleteTextTag = IsEndedWithCompleteTextTag(BufferPtr,endoffset);
       
  2847             if ( EndedWithCompleteTextTag )
       
  2848                 {
       
  2849                 // case b,e
       
  2850                 if(endoffset < startoffset)
       
  2851                     {
       
  2852                     User::Leave(KErrNotFound);
       
  2853                     }
       
  2854                 TPtrC lPtrtoPresentText = lBufferContent->Mid( startoffset, ( endoffset - startoffset ) );
       
  2855                 //end offset modified ot point to <text></text>
       
  2856                 //                                      ^
       
  2857                 endoffset = startoffset + lPtrtoPresentText.LocateReverse( KOpeningBrace );
       
  2858                 }
       
  2859             else
       
  2860                 {
       
  2861                 //case a,d
       
  2862                 if(endoffset < startoffset)
       
  2863                     {
       
  2864                     User::Leave(KErrNotFound);
       
  2865                     }
       
  2866                 TPtrC lPtrtoPresentText = lBufferContent->Mid( startoffset, ( endoffset - startoffset ) );
       
  2867                  endoffset = startoffset + lPtrtoPresentText.LocateReverse( KSlash );
       
  2868                 //end offset modified ot point to <text/>
       
  2869                 //                                     ^
       
  2870                 }
       
  2871             }
       
  2872         if(endoffset < startoffset)
       
  2873             {
       
  2874             User::Leave(KErrNotFound);
       
  2875             }
       
  2876         TPtrC lPtrtoWrBuffer = lBufferContent->Mid( startoffset, ( endoffset - startoffset ) );
       
  2877         TInt lWrBufLength = lPtrtoWrBuffer .Length();
       
  2878         User::LeaveIfError(WriteToStream(lStream,lPtrtoWrBuffer));
       
  2879         // If it was a text element ...
       
  2880         if ( lTextElementList[index]->ElemID() == KSvgTextElement )
       
  2881             {
       
  2882             HBufC *lBufTextContent= NULL;
       
  2883             //make startoffset point to opening tag '<' or '/' in case of a,d
       
  2884             TPtrC lPtrtoTextContent= ( (CSvgTextElementImpl* ) lTextElementList[ index ] )->GetText();
       
  2885             startoffset = endoffset + ( (CSvgTextElementImpl* ) lTextElementList[ index ] )->iOrgLength;
       
  2886             lBufTextContent = TextTagProcessingL(&lPtrtoTextContent,
       
  2887                                     startoffset,OrgLength,EndedWithCompleteTextTag);
       
  2888             CleanupStack::PushL(lBufTextContent);
       
  2889             TPtr lTempPtr(lBufTextContent->Des());
       
  2890             lPtrtoTextContent.Set(lTempPtr);
       
  2891             User::LeaveIfError(WriteToStream(lStream,lPtrtoTextContent));
       
  2892             CleanupStack::PopAndDestroy(lBufTextContent);
       
  2893             }
       
  2894        else
       
  2895             {
       
  2896             HBufC *lBufTextAreaContent= NULL;
       
  2897             HBufC* lBufPresentText = NULL;
       
  2898             TInt textlength = ((CSvgTextAreaElementImpl *)lTextElementList[index])->GetLength();
       
  2899             lBufTextAreaContent = HBufC::NewLC( textlength );
       
  2900 
       
  2901             TPtr lPtrtoGetTextAreaContent = lBufTextAreaContent->Des();
       
  2902             ((CSvgTextAreaElementImpl *)lTextElementList[index])->GetText( lPtrtoGetTextAreaContent );
       
  2903             TPtrC lPtrtoTextAreaContent=lPtrtoGetTextAreaContent;
       
  2904             startoffset = endoffset + ((CSvgTextAreaElementImpl *)lTextElementList[index])->iOrgLength;
       
  2905             lBufPresentText = TextAreaTagProcessingL(&lPtrtoTextAreaContent,startoffset,OrgLength,EndedWithCompleteTextTag);
       
  2906             CleanupStack::PushL(lBufPresentText);
       
  2907             TPtr lTempPtr(lBufPresentText->Des());
       
  2908             lPtrtoTextAreaContent.Set(lTempPtr);
       
  2909             User::LeaveIfError(WriteToStream(lStream,lPtrtoTextAreaContent));
       
  2910             CleanupStack::PopAndDestroy(lBufPresentText);
       
  2911             CleanupStack::PopAndDestroy(lBufTextAreaContent);
       
  2912             }
       
  2913             index++;
       
  2914         }
       
  2915 
       
  2916     // Done using the list, close the list to avoid a memory leak
       
  2917     CleanupStack::PopAndDestroy(&lTextElementList);
       
  2918 
       
  2919     // After processing all the editable text elements, are there any characters in the buffer
       
  2920     if( startoffset < lBufferContent->Length() )
       
  2921         {
       
  2922         TPtrC lPtrtoRemainText = lBufferContent->Mid(startoffset,(lBufferContent->Length()-startoffset));
       
  2923         User::LeaveIfError(WriteToStream(lStream,lPtrtoRemainText));
       
  2924         }
       
  2925 
       
  2926     // Close the stream
       
  2927     CleanupStack::PopAndDestroy(&lStream);
       
  2928 
       
  2929     // Close the file server session
       
  2930     CleanupStack::PopAndDestroy(&lFs);
       
  2931     }
       
  2932 
       
  2933 //-----------------------------------------------------------------------------
       
  2934 //Function to process the text and add tags at the end
       
  2935 //HBufC* CSvgEngineImpl::TextTagProcessing(TPtr* aCData, TInt aStartOffset, TInt aOrgLength,
       
  2936 //                              TBool aEndingWithTag)
       
  2937 //-----------------------------------------------------------------------------
       
  2938 
       
  2939 HBufC* CSvgEngineImpl::TextTagProcessingL(TPtrC* aCData,
       
  2940                     TInt &aStartOffset, TInt aOrgLength,TBool aEndingWithTag)
       
  2941     {
       
  2942         HBufC * lTextContentBuffer = NULL;
       
  2943         TPtrC lPtrToTextContent(*aCData) ;
       
  2944         //Ending with complete text tag and original length is 0
       
  2945         if( aEndingWithTag && aOrgLength == 0 )
       
  2946             {//case b
       
  2947             lTextContentBuffer = HBufC::NewLC(aCData->Length()
       
  2948                                     + KClosingTextTagLength );
       
  2949             TPtr lPtrToTempBuf(lTextContentBuffer->Des());//point to buffer
       
  2950             lPtrToTempBuf.Append(*aCData);//append cdata
       
  2951             lPtrToTempBuf.Append(KClosingTextTag);//append closing text tag
       
  2952             aStartOffset += KClosingTextTagLength;
       
  2953             }
       
  2954         else if( !aEndingWithTag && aOrgLength == 0 )
       
  2955             {//case a
       
  2956             lTextContentBuffer = HBufC::NewLC(aCData->Length()
       
  2957                                     + KClosingTextTagLength
       
  2958                                     + KClosingBracesLength );
       
  2959             TPtr lPtrToTempBuf(lTextContentBuffer->Des());//point to buffer
       
  2960             lPtrToTempBuf.Append(KClosingBraces);
       
  2961             lPtrToTempBuf.Append(*aCData);//append cdata
       
  2962             lPtrToTempBuf.Append(KClosingTextTag);//append closing text tag
       
  2963             aStartOffset += 2;// the length of /> which is 2 characters.
       
  2964             }
       
  2965         else if(aEndingWithTag && aOrgLength!= 0)
       
  2966             {
       
  2967             lTextContentBuffer = HBufC::NewLC(aCData->Length()
       
  2968                                     + KClosingTextTagLength );
       
  2969             TPtr lPtrToTempBuf(lTextContentBuffer->Des());//point to buffer
       
  2970             lPtrToTempBuf.Append(*aCData);//append cdata
       
  2971             lPtrToTempBuf.Append(KClosingTextTag);//append closing text tag
       
  2972             aStartOffset += KClosingTextTagLength ;
       
  2973             }
       
  2974         else
       
  2975             {
       
  2976             //i.e !aEndingWithTag && OrgLength!=0
       
  2977             //this case should never occur
       
  2978             //becoz there is no possibility of
       
  2979             //the quoted kind of text content definition in xml as shown below
       
  2980             //"<text /> this is a text content"
       
  2981             }
       
  2982         // Pop the buffer from the cleanup stack as ownership is transferred
       
  2983         // to caller
       
  2984         CleanupStack::Pop(lTextContentBuffer);
       
  2985         return lTextContentBuffer;
       
  2986 
       
  2987     }
       
  2988 
       
  2989 //-----------------------------------------------------------------------------
       
  2990 //Function to process the text and add tags at the end
       
  2991 //HBufC* CSvgEngineImpl::TextAreaTagProcessing(TPtr* aCData, TInt aStartOffset, TInt aOrgLength,
       
  2992 //                              TBool aEndingWithTag)
       
  2993 //-----------------------------------------------------------------------------
       
  2994 
       
  2995 HBufC* CSvgEngineImpl::TextAreaTagProcessingL(TPtrC* aCData, TInt &aStartOffset, TInt aOrgLength,
       
  2996                                 TBool aEndingWithTag)
       
  2997     {
       
  2998         HBufC * lTextAreaContentBuffer = NULL;
       
  2999         TPtrC lPtrToTextAreaContent(*aCData) ;
       
  3000 
       
  3001 
       
  3002         //Ending with complete text tag and original length is 0
       
  3003         if( aEndingWithTag && aOrgLength == 0 )
       
  3004             {//case e
       
  3005             lTextAreaContentBuffer = HBufC::NewLC(aCData->Length()
       
  3006                                         + KClosingTextAreaTagLength);
       
  3007             TPtr lPtrToTempBuf(lTextAreaContentBuffer->Des());//point to buffer
       
  3008             lPtrToTempBuf.Append(*aCData);//append cdata
       
  3009             lPtrToTempBuf.Append(KClosingTextAreaTag);//append closing text tag
       
  3010             aStartOffset += KClosingTextAreaTagLength;
       
  3011             }
       
  3012         else if( !aEndingWithTag && aOrgLength == 0 )
       
  3013             {//case d
       
  3014             lTextAreaContentBuffer = HBufC::NewLC(aCData->Length()
       
  3015                                         + KClosingBracesLength
       
  3016                                         + KClosingTextAreaTagLength );
       
  3017             TPtr lPtrToTempBuf(lTextAreaContentBuffer->Des());//point to buffer
       
  3018             lPtrToTempBuf.Append(KClosingBraces);
       
  3019             lPtrToTempBuf.Append(*aCData);//append cdata
       
  3020             lPtrToTempBuf.Append(KClosingTextAreaTag);//append closing text tag
       
  3021             aStartOffset += 2;// the length of /> which is 2 characters.
       
  3022             }
       
  3023         else if(aEndingWithTag && aOrgLength!= 0)
       
  3024             {//case f
       
  3025             lTextAreaContentBuffer = HBufC::NewLC(aCData->Length()
       
  3026                                         + KClosingTextAreaTagLength );
       
  3027             TPtr lPtrToTempBuf(lTextAreaContentBuffer->Des());//point to buffer
       
  3028             lPtrToTempBuf.Append(*aCData);//append cdata
       
  3029             lPtrToTempBuf.Append(KClosingTextAreaTag);//append closing text tag
       
  3030             aStartOffset += KClosingTextAreaTagLength;
       
  3031             }
       
  3032         else
       
  3033             {
       
  3034             //i.e !aEndingWithTag && OrgLength!=0
       
  3035             //this case should never occur
       
  3036             //becoz there is no possibility of
       
  3037             //the quoted kind of text content definition in xml as shown below
       
  3038             //"<textArea /> this is a text content"
       
  3039             }
       
  3040         // Pop the buffer from the cleanup stack as ownership is transferred
       
  3041         // to caller
       
  3042         CleanupStack::Pop(lTextAreaContentBuffer);
       
  3043         return lTextAreaContentBuffer;
       
  3044 
       
  3045     }
       
  3046 
       
  3047 
       
  3048 //-----------------------------------------------------------------------------
       
  3049 //Function to Write the buffer to the stream.
       
  3050 //In SaveSVGL while editing text - used to write partial buffers into the stream.
       
  3051 //TInt CSvgEngineImpl::WriteToStream(RFileWriteStream* aStream,TPtrC aWriteBuffer)
       
  3052 //-----------------------------------------------------------------------------
       
  3053 TInt CSvgEngineImpl::WriteToStream(RFileWriteStream &aStream,TPtrC aWriteBuffer)
       
  3054     {
       
  3055     // Create a small output buffer
       
  3056     TBuf8<KMaxConversionChars> outputBuffer;
       
  3057 
       
  3058     for(;;) // conversion loop
       
  3059         {
       
  3060         // Start conversion. When the output buffer is full, return the
       
  3061         // number of characters that were not converted
       
  3062         const TInt returnValue = CnvUtfConverter::ConvertFromUnicodeToUtf8(
       
  3063             outputBuffer,   // Destination
       
  3064             aWriteBuffer ); // Source
       
  3065 
       
  3066 
       
  3067         // check to see that the descriptor isn’t corrupt - return with
       
  3068         // err if it is
       
  3069         if ( returnValue == CnvUtfConverter::EErrorIllFormedInput )
       
  3070             {
       
  3071             return( KErrCorrupt );
       
  3072             }
       
  3073         else
       
  3074             {
       
  3075             if ( returnValue < 0 ) // future-proof against "TError" expanding
       
  3076                 {
       
  3077                 return( KErrGeneral );
       
  3078                 }
       
  3079             }
       
  3080 
       
  3081         // Store the converted contents of the output buffer into the stream
       
  3082         TRAPD( err1, aStream.WriteL( outputBuffer ) );
       
  3083         if ( err1 )
       
  3084             {
       
  3085             #ifdef _DEBUG
       
  3086             RDebug::Printf("CSvgEngineImpl::WriteToStream error trapped=%d", err1);
       
  3087             return err1;
       
  3088             #endif
       
  3089             }
       
  3090 
       
  3091         // Finish conversion if there are no unconverted characters in the
       
  3092         // remainder buffer
       
  3093         if ( returnValue == 0 )
       
  3094             {
       
  3095             break;
       
  3096             }
       
  3097 
       
  3098         // Remove the converted source text from the remainder buffer.
       
  3099         // The remainder buffer is then fed back into loop
       
  3100         aWriteBuffer.Set( aWriteBuffer.Right( returnValue ));
       
  3101         }
       
  3102     return KErrNone;
       
  3103     }
       
  3104 
       
  3105 
       
  3106 // --------------------------------------------------------------------------
       
  3107 // void CSvgEngineImpl::FindEditableElements( CSvgElementImpl* aStartElement,
       
  3108 // ---------------------------------------------------------------------------
       
  3109 void CSvgEngineImpl::FindEditableElements( CSvgElementImpl* aStartElement,
       
  3110                                            RPointerArray<CSvgElementImpl>& aList )
       
  3111     {
       
  3112     if ( aStartElement == NULL )
       
  3113         {
       
  3114         return;
       
  3115         }
       
  3116 
       
  3117     CSvgElementImpl* child = (CSvgElementImpl*)aStartElement->FirstChild();
       
  3118     while ( child != NULL )
       
  3119     {
       
  3120         // add to list if child is found
       
  3121         if ( child->ElemID() == KSvgTextElement || child->ElemID() == KSvgTextAreaElement  )
       
  3122             aList.Append( child );
       
  3123 
       
  3124         // find in grandchildren if element is not a textArea
       
  3125         if ( child->ElemID() != KSvgTextAreaElement )
       
  3126             {
       
  3127         FindEditableElements( child, aList );
       
  3128             }
       
  3129         child = (CSvgElementImpl*)child->NextSibling();
       
  3130     }
       
  3131 }
       
  3132 TBool CSvgEngineImpl::IsSVGEnginePaused()
       
  3133 {
       
  3134 	return (iSvgEngineState == ESVGEnginePaused );
       
  3135 
       
  3136 }
       
  3137 
       
  3138 // --------------------------------------------------------------------------
       
  3139 // void CSvgEngineImpl::ResetContext()
       
  3140 // ---------------------------------------------------------------------------
       
  3141 void CSvgEngineImpl::ResetContext()
       
  3142 {
       
  3143 	if( iGfxContext )
       
  3144 		{
       
  3145 		iGfxContext->DestroyContext();
       
  3146 		}
       
  3147 }
       
  3148 
       
  3149 void CSvgEngineImpl::SetBitmapHeader(const TDesC* aHeaderData)
       
  3150     {
       
  3151     if (iGfxContext)
       
  3152         {
       
  3153         ((CGfx2dGcOpenVG *)iGfxContext)->SetBitmapHeader(aHeaderData);
       
  3154         }
       
  3155     }
       
  3156 //NGA
       
  3157 // ---------------------------------------------------------------------------
       
  3158 // SetGdiContext File
       
  3159 // ---------------------------------------------------------------------------
       
  3160 
       
  3161 void CSvgEngineImpl::SetGdiContextL(CFbsBitmap* aCurrentBitmap, CFbsBitmap* aMask,TSize aCurrentBitmapSize,TDisplayMode aRenderDspMode,TDisplayMode aMaskDspMode)
       
  3162 
       
  3163     {
       
  3164     // Handle for both Non-NULL and NULL parameter
       
  3165        iFrameBufferSize = aCurrentBitmapSize;
       
  3166        iRenderDspMode   = aRenderDspMode;
       
  3167        iMaskDspMode     = aMaskDspMode; 
       
  3168        iFrameBuffer     = aCurrentBitmap;
       
  3169        iMask            = aMask;
       
  3170 
       
  3171     if ( aCurrentBitmapSize.iWidth > 0 && aCurrentBitmapSize.iHeight > 0 )
       
  3172         {
       
  3173         if ( !iGfxContext )
       
  3174             {
       
  3175                 iGfxContext = CGfx2dGcOpenVG::NewL( aCurrentBitmapSize, iBitmapFontSpec, iSvgBitmapFontProvider,1 );
       
  3176             }
       
  3177         else
       
  3178             {
       
  3179             iGfxContext->ChangeBufferSizeL( aCurrentBitmapSize );
       
  3180             }
       
  3181         }
       
  3182     else if ( iGfxContext )
       
  3183         {
       
  3184         iGfxContext->ChangeBufferSizeL( TSize( 1, 1 ) );
       
  3185         }
       
  3186     }
       
  3187 const TPtrC8 CSvgEngineImpl::TLVEncodedData() const
       
  3188     {
       
  3189     return (iGfxContext->TLVEncodedData());
       
  3190     }