svgtopt/SVG/SVGEngine/src/SVGEngineInterfaceImpl.cpp
changeset 0 d46562c3d99d
child 19 df65ec4f2d28
child 38 db5c883ad1c5
equal deleted inserted replaced
-1:000000000000 0:d46562c3d99d
       
     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 #include "SVGEngineImpl.h"
       
    20 #include "SVGEngineInterfaceImpl.h"
       
    21 
       
    22 #include "GfxAffineTransform.h"
       
    23 
       
    24 #include "SVGTimer.h"
       
    25 #include "SVGSvgElementImpl.h"
       
    26 //#include "SVGTransformableImpl.h"
       
    27 //#include "SVGSchemaData.h"
       
    28 
       
    29 //#include "GfxPoint2D.h"
       
    30 //#include "GfxRectangle2D.h"
       
    31 
       
    32 #include "SVGErrorImpl.h"
       
    33 
       
    34 // added for JSR support
       
    35 #include  "SVGRectElementImpl.h"
       
    36 #include "SVGAnimationBase.h"
       
    37 #include "e32math.h"
       
    38 
       
    39 //#include "SVGFourPointRect.h"
       
    40 #include "SVGTextElementImpl.h"
       
    41 #include "SVGTextAreaElementImpl.h"
       
    42 #include "SVGListener.h"
       
    43 #include "SVGUseElementImpl.h"
       
    44 //#include "SvgEventHandler.h"
       
    45 #include "SVGMediaAnimationElementImpl.h"
       
    46 #include <AknUtils.h>
       
    47 #include <avkon.hrh>
       
    48 #include "SvgBitmapFontProvider.h"
       
    49 #include "SvgStopElementImpl.h"
       
    50 #include "SVGGradientElementImpl.h"
       
    51 #include <utf.h>
       
    52 
       
    53 #define  SvgUnitPixels  1
       
    54 #define  SvgUnitPercent 2
       
    55 #define  KBackgroundColor 0xffffffff
       
    56 _LIT(OFFSET, "offset");
       
    57 _LIT(ZEROVALUE, "0");
       
    58 
       
    59 // --------------------------------------------------------------------------
       
    60 // EXPORT_C CSvgEngineInterfaceImpl* CSvgEngineInterfaceImpl::NewL( CFbsBitmap* aFrameBuffer,
       
    61 // ---------------------------------------------------------------------------
       
    62 EXPORT_C CSvgEngineInterfaceImpl* CSvgEngineInterfaceImpl::NewL( CFbsBitmap* aFrameBuffer,
       
    63                                                        MSvgRequestObserver* aReqObserver, TFontSpec& aFontSpec )
       
    64     {
       
    65     CSvgEngineInterfaceImpl* self    = new ( ELeave ) CSvgEngineInterfaceImpl;
       
    66     CleanupStack::PushL( self );
       
    67     self->ConstructL( aFrameBuffer, aReqObserver,aFontSpec );
       
    68     CleanupStack::Pop();
       
    69 
       
    70     return self;
       
    71     }
       
    72 
       
    73 // --------------------------------------------------------------------------
       
    74 EXPORT_C CSvgEngineInterfaceImpl* CSvgEngineInterfaceImpl::NewL( CFbsBitmap* aFrameBuffer,
       
    75 
       
    76                                                        MSvgRequestObserver* aReqObserver, TFontSpec& aFontSpec ,SVGRendererId aRendererType)
       
    77 
       
    78     {
       
    79 
       
    80     CSvgEngineInterfaceImpl* self    = new ( ELeave ) CSvgEngineInterfaceImpl;
       
    81 
       
    82     CleanupStack::PushL( self );
       
    83 
       
    84     self->ConstructL( aFrameBuffer, aReqObserver,aFontSpec,aRendererType );
       
    85 
       
    86     CleanupStack::Pop();
       
    87 
       
    88 
       
    89 
       
    90     return self;
       
    91 
       
    92     }
       
    93 // EXPORT_C CSvgEngineInterfaceImpl* CSvgEngineInterfaceImpl::NewLC( CFbsBitmap* aFrameBuffer,
       
    94 // ---------------------------------------------------------------------------
       
    95 EXPORT_C CSvgEngineInterfaceImpl* CSvgEngineInterfaceImpl::NewLC( CFbsBitmap* aFrameBuffer,
       
    96                                                         MSvgRequestObserver* aReqObserver,TFontSpec& aFontSpec )
       
    97     {
       
    98     CSvgEngineInterfaceImpl* self    = new ( ELeave ) CSvgEngineInterfaceImpl;
       
    99     CleanupStack::PushL( self );
       
   100     self->ConstructL( aFrameBuffer, aReqObserver,aFontSpec );
       
   101 
       
   102     return self;
       
   103     }
       
   104 
       
   105 // --------------------------------------------------------------------------
       
   106 EXPORT_C CSvgEngineInterfaceImpl* CSvgEngineInterfaceImpl::NewLC( CFbsBitmap* aFrameBuffer,
       
   107 
       
   108                                                         MSvgRequestObserver* aReqObserver,TFontSpec& aFontSpec ,SVGRendererId aRendererType)
       
   109 
       
   110     {
       
   111 
       
   112     CSvgEngineInterfaceImpl* self    = new ( ELeave ) CSvgEngineInterfaceImpl;
       
   113 
       
   114     CleanupStack::PushL( self );
       
   115 
       
   116     self->ConstructL( aFrameBuffer, aReqObserver,aFontSpec,aRendererType );
       
   117 
       
   118 
       
   119 
       
   120     return self;
       
   121 
       
   122     }
       
   123 // EXPORT_C CSvgEngineInterfaceImpl::CSvgEngineInterfaceImpl()
       
   124 // ---------------------------------------------------------------------------
       
   125 EXPORT_C CSvgEngineInterfaceImpl::CSvgEngineInterfaceImpl()
       
   126     {
       
   127     iIsLoadingRequest = EFalse;
       
   128     iMouseDownFlag = EFalse;
       
   129     iDrmRightsConsumptionEnabled = ETrue;
       
   130     }
       
   131 
       
   132 // --------------------------------------------------------------------------
       
   133 // EXPORT_C void CSvgEngineInterfaceImpl::ConstructL( CFbsBitmap* aFrameBuffer,
       
   134 // ---------------------------------------------------------------------------
       
   135 EXPORT_C void CSvgEngineInterfaceImpl::ConstructL( CFbsBitmap* aFrameBuffer,
       
   136                                      MSvgRequestObserver* aReqObserver,TFontSpec& aFontSpec )
       
   137     {
       
   138     iSvgBitmapFontProvider = CSvgBitmapFontProvider::NewL( aFontSpec );
       
   139     iSvgEngine = CSvgEngineImpl::NewL( aFrameBuffer, aReqObserver,aFontSpec, iSvgBitmapFontProvider );
       
   140     iSvgEnginePointers.Append(iSvgEngine);
       
   141 
       
   142     SetDRMMode( ETrue );
       
   143     SetThumbNailMode( EFalse );
       
   144 
       
   145     iFileIsLoaded = EFalse;
       
   146 
       
   147     iTotalRotation= 0;
       
   148     iSvgError = CSvgErrorImpl::NewL();
       
   149     
       
   150 //	Not needed since no more VGR. Causes issues when multiple 
       
   151 //  contexts are created by multiple engines...	
       
   152 //  CustomOption(ETrue);	
       
   153     }
       
   154 
       
   155 //NGA :: Renderer selector included
       
   156 
       
   157 // --------------------------------------------------------------------------
       
   158 
       
   159 // EXPORT_C void CSvgEngineInterfaceImpl::ConstructL( CFbsBitmap* aFrameBuffer,
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 
       
   163 EXPORT_C void CSvgEngineInterfaceImpl::ConstructL( CFbsBitmap* aFrameBuffer,
       
   164 
       
   165                                      MSvgRequestObserver* aReqObserver,TFontSpec& aFontSpec,SVGRendererId aRendererType )
       
   166 
       
   167     {
       
   168 
       
   169     iSvgBitmapFontProvider = CSvgBitmapFontProvider::NewL( aFontSpec );
       
   170 
       
   171     iSvgEngine = CSvgEngineImpl::NewL( aFrameBuffer, aReqObserver,aFontSpec, iSvgBitmapFontProvider ,aRendererType);
       
   172 
       
   173     iSvgEnginePointers.Append(iSvgEngine);
       
   174 
       
   175 
       
   176 
       
   177     SetDRMMode( ETrue );
       
   178 
       
   179     SetThumbNailMode( EFalse );
       
   180 
       
   181 
       
   182 
       
   183     iFileIsLoaded = EFalse;
       
   184 
       
   185 
       
   186 
       
   187     iTotalRotation= 0;
       
   188 
       
   189     iSvgError = CSvgErrorImpl::NewL();
       
   190 
       
   191     
       
   192 
       
   193 //	Not needed since no more VGR. Causes issues when multiple 
       
   194 
       
   195 //  contexts are created by multiple engines...	
       
   196 
       
   197 //  CustomOption(ETrue);	
       
   198 
       
   199     }
       
   200 // EXPORT_C void CSvgEngineInterfaceImpl::ConstructL()
       
   201 // ---------------------------------------------------------------------------
       
   202 EXPORT_C void CSvgEngineInterfaceImpl::ConstructL()
       
   203     {
       
   204     iSvgEngine = NULL;
       
   205 
       
   206     iFileIsLoaded = EFalse;
       
   207     iTotalRotation= 0;
       
   208     iSvgError = CSvgErrorImpl::NewL();
       
   209 
       
   210     //Added to populated the font spec with variant default font
       
   211     const TInt KApacFontId = EApacPlain16;
       
   212     const TInt KLatintFontId = ELatinBold12;
       
   213     TInt fontId = KLatintFontId;
       
   214 
       
   215     switch ( AknLayoutUtils::Variant() )
       
   216         {
       
   217         case EApacVariant:
       
   218             {
       
   219             fontId = KApacFontId;
       
   220             }
       
   221             break;
       
   222         case EEuropeanVariant:
       
   223         default:
       
   224             break;
       
   225         }
       
   226 
       
   227     const CFont* font = AknLayoutUtils::FontFromId( fontId );
       
   228     TFontSpec spec = font->FontSpecInTwips();
       
   229 	iSvgBitmapFontProvider = CSvgBitmapFontProvider::NewL( spec );
       
   230 
       
   231 //	Not needed since no more VGR. Causes issues when multiple 
       
   232 //  contexts are created by multiple engines...		
       
   233 //  CustomOption(ETrue);
       
   234 
       
   235     }
       
   236 
       
   237 EXPORT_C void CSvgEngineInterfaceImpl::ConstructL(TFontSpec& aFontSpec)
       
   238     {
       
   239     iSvgEngine = NULL;
       
   240     iFileIsLoaded = EFalse;
       
   241     iTotalRotation= 0;
       
   242     iSvgError = CSvgErrorImpl::NewL();
       
   243 	iSvgBitmapFontProvider = CSvgBitmapFontProvider::NewL( aFontSpec );
       
   244     }
       
   245 // --------------------------------------------------------------------------
       
   246 // EXPORT_C CSvgEngineInterfaceImpl::~CSvgEngineInterfaceImpl()
       
   247 // ---------------------------------------------------------------------------
       
   248 EXPORT_C CSvgEngineInterfaceImpl::~CSvgEngineInterfaceImpl()
       
   249     {
       
   250     iSvgDocumentPointers.ResetAndDestroy();
       
   251     iSvgDocumentPointers.Close();
       
   252 
       
   253 	iSvgEnginePointers.ResetAndDestroy();
       
   254 	iSvgEnginePointers.Close();
       
   255 
       
   256     delete iSvgBitmapFontProvider ;
       
   257     //delete iTimer;
       
   258     if(iSvgError)
       
   259         {
       
   260     delete iSvgError;
       
   261         iSvgError = NULL;
       
   262         }
       
   263 
       
   264     iSvgLoadingListeners.Close();
       
   265     iSvgMouseEnteredElements.Close();
       
   266 
       
   267     }
       
   268 
       
   269 //DEPRECATED API
       
   270 // --------------------------------------------------------------------------
       
   271 // EXPORT_C void CSvgEngineInterfaceImpl::Destroy()
       
   272 // ---------------------------------------------------------------------------
       
   273 EXPORT_C void CSvgEngineInterfaceImpl::Destroy()
       
   274     {
       
   275     	DestroyDocument(iSvgLoadedDocument);
       
   276     	iSvgLoadedDocument = NULL;
       
   277     }
       
   278 
       
   279 // --------------------------------------------------------------------------
       
   280 // void CSvgEngineInterfaceImpl::PostLoadProcessing( TInt aDocumentHandle )
       
   281 // ---------------------------------------------------------------------------
       
   282 void CSvgEngineInterfaceImpl::PostLoadProcessing( TInt /* aDocumentHandle */ )
       
   283     {
       
   284     }
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 //Deprecated for platform security
       
   288 // ---------------------------------------------------------------------------
       
   289 EXPORT_C MSvgError* CSvgEngineInterfaceImpl::Load( const TDesC& aFileName )
       
   290     {
       
   291     TInt documentHandle = 0;
       
   292     iTotalRotation = 0;
       
   293     iSvgError->SetErrorCode( ESvgNoError );
       
   294 
       
   295     // Destroy current loaded document.
       
   296     DestroyDocument(iSvgLoadedDocument);
       
   297 
       
   298     iIsLoadingRequest = ETrue;
       
   299     TRAPD( error, iSvgEngine->iSvgNames->AppendL(aFileName));
       
   300         
       
   301     if( error != KErrNone )
       
   302         {
       
   303         _LIT( KErrorMsg, "Failed to Append filename" );
       
   304         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, error,KErrorMsg, aFileName );
       
   305          return iSvgError;
       
   306         }
       
   307     
       
   308     PrepareDom( aFileName, documentHandle );
       
   309     iIsLoadingRequest = EFalse;
       
   310 
       
   311     if ( iSvgError->HasError() && !iSvgError->IsWarning() )
       
   312     {
       
   313         return iSvgError;
       
   314     }
       
   315 
       
   316     PostLoadProcessing( documentHandle );
       
   317 
       
   318     iSvgLoadedDocument = (CSvgDocumentImpl*)documentHandle;
       
   319     return iSvgError;
       
   320 }
       
   321 
       
   322 // ---------------------------------------------------------------------------
       
   323 // Modified Load function to take RFile aHandle.
       
   324 // ---------------------------------------------------------------------------
       
   325 EXPORT_C MSvgError*  CSvgEngineInterfaceImpl::Load( RFile& aFileHandle)
       
   326     {
       
   327     TInt documentHandle = 0;
       
   328     iTotalRotation = 0;
       
   329     iSvgError->SetErrorCode( ESvgNoError );
       
   330 
       
   331     // Destroy current loaded document.
       
   332     DestroyDocument(iSvgLoadedDocument);
       
   333     
       
   334     TFileName fileName;
       
   335     aFileHandle.Name(fileName);
       
   336     iSvgEngine->iSvgNames->AppendL(fileName);
       
   337     iIsLoadingRequest = ETrue;
       
   338     PrepareDom( aFileHandle, documentHandle );
       
   339     iIsLoadingRequest = EFalse;
       
   340 
       
   341     if ( iSvgError->HasError() && !iSvgError->IsWarning() )
       
   342     {
       
   343         return iSvgError;
       
   344     }
       
   345 
       
   346     PostLoadProcessing( documentHandle );
       
   347 	iSvgLoadedDocument = (CSvgDocumentImpl*)documentHandle;
       
   348     return iSvgError;
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // Modified Load function which in turn calls the generic LoadL function
       
   353 // ---------------------------------------------------------------------------
       
   354 EXPORT_C MSvgError* CSvgEngineInterfaceImpl::Load( const TDesC8& aByteData )
       
   355     {
       
   356     TInt documentHandle = 0;
       
   357     iTotalRotation = 0;
       
   358     iSvgError->SetErrorCode( ESvgNoError );
       
   359 
       
   360     // Destroy current loaded document.
       
   361     DestroyDocument(iSvgLoadedDocument);
       
   362 
       
   363     iIsLoadingRequest = ETrue;
       
   364     PrepareDom( aByteData, documentHandle );
       
   365     iIsLoadingRequest = EFalse;
       
   366 
       
   367     if ( iSvgError->HasError() && !iSvgError->IsWarning() )
       
   368     {
       
   369         return iSvgError;
       
   370     }
       
   371 
       
   372     PostLoadProcessing( documentHandle );
       
   373 	iSvgLoadedDocument = (CSvgDocumentImpl*)documentHandle;
       
   374     return iSvgError;
       
   375     }
       
   376 
       
   377 // --------------------------------------------------------------------------
       
   378 // EXPORT_C void CSvgEngineInterfaceImpl::Start( CSvgEngineImpl* aEngine
       
   379 //                                                  , TBool /*aIsMainThread*/ )
       
   380 // ---------------------------------------------------------------------------
       
   381 EXPORT_C void CSvgEngineInterfaceImpl::Start( CSvgEngineImpl* aEngine,
       
   382                                               TBool /*aIsMainThread*/ )
       
   383     {
       
   384 
       
   385     if ( ChooseEngine((TInt)aEngine) )
       
   386         {
       
   387         iSvgEngine->SetMediaTime(0);
       
   388         iSvgEngine->ResetTimer();
       
   389         iSvgEngine->StartEngine();
       
   390         }
       
   391     }
       
   392 
       
   393 
       
   394 // -----------------------------------------------------------------------------------------------------
       
   395 // EXPORT_C void CSvgEngineInterfaceImpl::Start( CSvgEngineImpl* aEngine,TBool /*aIsMainThread*/ )
       
   396 // -----------------------------------------------------------------------------------------------------
       
   397 
       
   398 EXPORT_C void CSvgEngineInterfaceImpl::Start( MSvgError*& aError,
       
   399                                               CSvgEngineImpl* aEngine
       
   400                                             )
       
   401     {
       
   402     
       
   403     if ( ChooseEngine((TInt)aEngine) )
       
   404         {
       
   405             iSvgEngine->SetMediaTime(0);
       
   406             iSvgEngine->ResetTimer();
       
   407             iSvgEngine->StartEngine(iSvgError); 
       
   408         }
       
   409         
       
   410         aError = iSvgError;
       
   411     }
       
   412 // --------------------------------------------------------------------------
       
   413 // EXPORT_C void CSvgEngineInterfaceImpl::Pause( CSvgEngineImpl* aEngine )
       
   414 // ---------------------------------------------------------------------------
       
   415 EXPORT_C void CSvgEngineInterfaceImpl::Pause( CSvgEngineImpl* aEngine )
       
   416     {
       
   417     	if ( ChooseEngine((TInt)aEngine) )
       
   418     	{
       
   419     	    iSvgEngine->SetSVGEngineState(ESVGEnginePaused);
       
   420     	}
       
   421     }
       
   422 
       
   423 // --------------------------------------------------------------------------
       
   424 // EXPORT_C void CSvgEngineInterfaceImpl::Stop( CSvgEngineImpl* aEngine )
       
   425 // ---------------------------------------------------------------------------
       
   426 EXPORT_C void CSvgEngineInterfaceImpl::Stop( CSvgEngineImpl* aEngine )
       
   427     {
       
   428     	if ( ChooseEngine((TInt)aEngine) )
       
   429         {
       
   430             iSvgEngine->SetSVGEngineState(ESVGEngineStopped);
       
   431 
       
   432             if (iSvgEngine->Document() && iSvgEngine->Document()->IsAnimationFile())
       
   433             {
       
   434             // restore some properties that changed during animation
       
   435  //           RestoreAnimStyleProperties();
       
   436             }
       
   437         }
       
   438     }
       
   439 
       
   440 // Store properties that were changed during animation
       
   441 //
       
   442 // --------------------------------------------------------------------------
       
   443 // void CSvgEngineInterfaceImpl::RestoreAnimStyleProperties()
       
   444 // ---------------------------------------------------------------------------
       
   445 void CSvgEngineInterfaceImpl::RestoreAnimStyleProperties( TInt aEngine )
       
   446     {
       
   447     if ( ChooseEngine(aEngine) && iSvgEngine->Document())
       
   448         {
       
   449         RPointerArray<CSvgElementImpl> all_elements;
       
   450         iSvgEngine->Document()->FindAllElements(
       
   451             (CSvgElementImpl* )iSvgEngine->Document()->RootElement(), -1, all_elements );
       
   452 
       
   453 		TInt allEleCnt = all_elements.Count();
       
   454         for (TInt i=0; i < allEleCnt; i++ )
       
   455             {
       
   456             // make sure that this is an animation element.
       
   457             if( all_elements[i]->IsAnimatedElement() )
       
   458                 {
       
   459                 CSvgAnimationBase*
       
   460                     lAnimationBasePtr = (CSvgAnimationBase*)all_elements[i];
       
   461                 if ( !lAnimationBasePtr->IsFillFreeze() )
       
   462                     {
       
   463                     TRAPD(err, lAnimationBasePtr->ResetAttrValueL());    
       
   464                         if ( err != KErrNone )
       
   465                         {
       
   466                          #ifdef _DEBUG
       
   467                          RDebug::Printf("CSvgEngineInterfaceImpl::RestoreAnimStylePropertiesL() failed");
       
   468                          #endif
       
   469                         }
       
   470                     }
       
   471                 
       
   472                 
       
   473                 }
       
   474             }
       
   475         all_elements.Close();
       
   476         }
       
   477     }
       
   478 
       
   479 
       
   480 
       
   481 // --------------------------------------------------------------------------
       
   482 // EXPORT_C void CSvgEngineInterfaceImpl::Resume( CSvgEngineImpl* aEngine )
       
   483 // ---------------------------------------------------------------------------
       
   484 EXPORT_C void CSvgEngineInterfaceImpl::Resume( CSvgEngineImpl* aEngine )
       
   485     {
       
   486     	if ( ChooseEngine((TInt)aEngine) )
       
   487     	{
       
   488             iSvgEngine->SetSVGEngineState(ESVGEngineRunning);
       
   489         }
       
   490     }
       
   491 
       
   492 // --------------------------------------------------------------------------
       
   493 // EXPORT_C TUint32 CSvgEngineInterfaceImpl::Duration()
       
   494 // ---------------------------------------------------------------------------
       
   495 EXPORT_C TUint32 CSvgEngineInterfaceImpl::Duration( TInt aEngine )
       
   496     {
       
   497 
       
   498     	if ( ChooseEngine(aEngine) )
       
   499     	{
       
   500     		return ( iSvgEngine->Duration() );
       
   501     	}
       
   502     	else
       
   503     	{
       
   504     		return 0;
       
   505    		}
       
   506     }
       
   507 
       
   508 // --------------------------------------------------------------------------
       
   509 // EXPORT_C void CSvgEngineInterfaceImpl::OriginalView()
       
   510 // ---------------------------------------------------------------------------
       
   511 EXPORT_C void CSvgEngineInterfaceImpl::OriginalView( TInt aEngine )
       
   512     {
       
   513     MSvgTransformList*  trList;
       
   514     iTotalRotation= 0;
       
   515     if ( ChooseEngine(aEngine) && iSvgEngine->Document() )
       
   516         {
       
   517         CSvgSvgElementImpl* lRoot   = ( CSvgSvgElementImpl* )
       
   518                                       iSvgEngine->Document()->RootElement();
       
   519         if ( lRoot && lRoot->GetZoomAndPan() == ESvgZoomAndPanMagnify )
       
   520             {
       
   521             lRoot->GetTransform( trList );
       
   522             trList->ReplaceItem( TGfxAffineTransform(), 0 );
       
   523             }
       
   524         }
       
   525     }
       
   526 
       
   527 //
       
   528 // --------------------------------------------------------------------------
       
   529 // EXPORT_C void CSvgEngineInterfaceImpl::SetRenderQuality( TRenderingQuality aQualityLevel )
       
   530 // ---------------------------------------------------------------------------
       
   531 EXPORT_C void CSvgEngineInterfaceImpl::SetRenderQuality( TRenderingQuality aQualityLevel, TInt aEngine )
       
   532     {
       
   533     
       
   534     if( ChooseEngine(aEngine) )
       
   535     {
       
   536     	iSvgEngine->SetRenderingQuality(aQualityLevel);
       
   537     }
       
   538 
       
   539     }
       
   540 
       
   541 
       
   542 // --------------------------------------------------------------------------
       
   543 // EXPORT_C TRenderingQuality CSvgEngineInterfaceImpl::GetRenderQuality()
       
   544 // ---------------------------------------------------------------------------
       
   545 EXPORT_C TRenderingQuality CSvgEngineInterfaceImpl::GetRenderQuality()
       
   546     {
       
   547     return ( KLowAA );
       
   548     }
       
   549 
       
   550 // --------------------------------------------------------------------------
       
   551 // EXPORT_C void CSvgEngineInterfaceImpl::SetAnimFrameDuration( TUint aAFDur )
       
   552 // ---------------------------------------------------------------------------
       
   553 EXPORT_C void CSvgEngineInterfaceImpl::SetAnimFrameDuration( TUint aAFDur, TInt aEngine )
       
   554     {
       
   555     	if (ChooseEngine(aEngine))
       
   556     	{
       
   557     		iSvgEngine->ChangeDuration( aAFDur );
       
   558     	}
       
   559     }
       
   560 
       
   561 // --------------------------------------------------------------------------
       
   562 // EXPORT_C void CSvgEngineInterfaceImpl::Redraw( TBool aIsMainThread )
       
   563 // ---------------------------------------------------------------------------
       
   564 EXPORT_C void CSvgEngineInterfaceImpl::Redraw( TBool /*aIsMainThread*/, TInt aEngine )
       
   565     {
       
   566     if ( !ChooseEngine(aEngine) )
       
   567         {
       
   568         return;
       
   569         }
       
   570 
       
   571     CSvgDocumentImpl* document = iSvgEngine->Document();
       
   572     if ( !document )
       
   573         {
       
   574         return;
       
   575         }
       
   576 
       
   577     // This situation occurs when parsing is done in a separate thread then the draw thread
       
   578     // Wait for pruning to complete or invalid element pointer may occur during drawing
       
   579     if ( document->iIsPruningTree )
       
   580         {
       
   581         TInt waitCount = 0;
       
   582         while ( waitCount++ < 100 && document->iIsPruningTree )
       
   583             {
       
   584             User::After( 10000 ); // 10 millseconds
       
   585             }
       
   586 
       
   587         // Cannot wait any longer, prevent being stuck here
       
   588         if ( document->iIsPruningTree )
       
   589             {
       
   590             return;
       
   591             }
       
   592         }
       
   593 
       
   594     TRAPD(redrawError, iSvgEngine->RedrawL() );
       
   595     if( redrawError != KErrNone )
       
   596         {
       
   597         document->iIsRendering = EFalse;
       
   598         }
       
   599 
       
   600     }
       
   601 
       
   602 // --------------------------------------------------------------------------
       
   603 // EXPORT_C void CSvgEngineInterfaceImpl::SwitchDebugInfo( TInt aEngine )
       
   604 // ----------------------------------------------------------------------
       
   605 EXPORT_C void CSvgEngineInterfaceImpl::SwitchDebugInfo( TInt aEngine )
       
   606     {
       
   607     	if (ChooseEngine( aEngine ))
       
   608     	{
       
   609 
       
   610     	}
       
   611     }
       
   612 
       
   613 
       
   614 //*****************************
       
   615 // UI event
       
   616 // --------------------------------------------------------------------------
       
   617 // EXPORT_C void CSvgEngineInterfaceImpl::MouseDown( TInt aX, TInt aY )
       
   618 // ---------------------------------------------------------------------------
       
   619 EXPORT_C TInt CSvgEngineInterfaceImpl::MouseDown( TInt aX, TInt aY, TInt aEngine )
       
   620     {
       
   621 
       
   622     if ( iMouseDownFlag || !ChooseEngine(aEngine) )
       
   623     {
       
   624     	return NULL;
       
   625     }
       
   626 
       
   627     iMouseDownFlag = ETrue;
       
   628 
       
   629 
       
   630     TSvgUiMouseEvent    uiev    ( ESvgEngineEventMouseDown, aX, aY );
       
   631     TRAPD( error, iSvgEngine->ProcessEventL( iSvgEngine->Document(), &uiev ) );
       
   632     if (error != KErrNone)
       
   633         {
       
   634         #ifdef _DEBUG
       
   635         _LIT(KProcessEventFailed, "CSvgEngineInterfaceImpl::MouseDown: ProcessEventL error.");
       
   636         RDebug::Print(KProcessEventFailed);
       
   637         #endif //_DEBUG
       
   638         }
       
   639     // Process for MousePress
       
   640     TInt listenerCount = iSvgEngine->MouseListenerCount();
       
   641 
       
   642     if (iSvgEngine->Document())
       
   643     {
       
   644         listenerCount += iSvgEngine->Document()->MouseInternalListenerCount();
       
   645     }
       
   646     if ( listenerCount == 0 )
       
   647         {
       
   648         return 0;
       
   649         }
       
   650     RPointerArray<CSvgElementImpl> viewableElements;
       
   651     TInt topClickedElement = 0;
       
   652 
       
   653     iSvgEngine->GetViewableElementsAtPoint(iSvgEngine->Document(),viewableElements, aX, aY );
       
   654     if ( viewableElements.Count() > 0 )
       
   655         {
       
   656         iSvgEngine->NotifyMousePressed( viewableElements, aX, aY );
       
   657         if ( iSvgEngine->Document() )
       
   658             {
       
   659             iSvgEngine->Document()->NotifyInternalMousePressed( viewableElements, aX, aY );
       
   660             }
       
   661 
       
   662         topClickedElement = (TInt)viewableElements[viewableElements.Count()-1];
       
   663         }
       
   664     viewableElements.Close();
       
   665 
       
   666     return topClickedElement;
       
   667     }
       
   668 
       
   669 // --------------------------------------------------------------------------
       
   670 // EXPORT_C void CSvgEngineInterfaceImpl::MouseUp( TInt aX, TInt aY )
       
   671 // ---------------------------------------------------------------------------
       
   672 EXPORT_C void CSvgEngineInterfaceImpl::MouseUp( TInt aX, TInt aY, TInt aEngine )
       
   673     {
       
   674     iMouseDownFlag = EFalse;
       
   675 
       
   676     if (!ChooseEngine( aEngine ))
       
   677     {
       
   678     	return;
       
   679     }
       
   680 
       
   681     TSvgUiMouseEvent    uiev    ( ESvgEngineEventMouseUp, aX, aY );
       
   682     TRAPD( error, iSvgEngine->ProcessEventL( iSvgEngine->Document(), &uiev ) );
       
   683     if (error != KErrNone)
       
   684         {
       
   685         #ifdef _DEBUG
       
   686         _LIT(KProcessEventFailed, "CSvgEngineInterfaceImpl::MouseUp: ProcessEventL error.");
       
   687         RDebug::Print(KProcessEventFailed);
       
   688         #endif //_DEBUG
       
   689         }
       
   690 
       
   691     // Process for MouseRelease
       
   692     TInt listenerCount = iSvgEngine->MouseListenerCount();
       
   693 
       
   694     if (iSvgEngine->Document())
       
   695     {
       
   696         listenerCount += iSvgEngine->Document()->MouseInternalListenerCount();
       
   697     }
       
   698     if ( listenerCount == 0 )
       
   699         {
       
   700         return;
       
   701         }
       
   702     RPointerArray<CSvgElementImpl> viewableElements;
       
   703     iSvgEngine->GetViewableElementsAtPoint(iSvgEngine->Document(), viewableElements, aX, aY );
       
   704     if ( viewableElements.Count() > 0 )
       
   705         {
       
   706         iSvgEngine->NotifyMouseReleased( viewableElements, aX, aY );
       
   707         if ( iSvgEngine->Document() )
       
   708             {
       
   709             iSvgEngine->Document()->NotifyInternalMouseReleased( viewableElements, aX, aY );
       
   710             }
       
   711         }
       
   712     viewableElements.Close();
       
   713     }
       
   714 
       
   715 // --------------------------------------------------------------------------
       
   716 // EXPORT_C void CSvgEngineInterfaceImpl::MouseMove( TInt aX, TInt aY )
       
   717 // ---------------------------------------------------------------------------
       
   718 EXPORT_C void CSvgEngineInterfaceImpl::MouseMove( TInt aX, TInt aY, TInt aEngine )
       
   719     {
       
   720 
       
   721     if (!ChooseEngine( aEngine ))
       
   722     {
       
   723     	return;
       
   724     }
       
   725     RPointerArray<CSvgElementImpl> viewableElements;
       
   726     iSvgEngine->GetViewableElementsAtPoint(iSvgEngine->Document(), viewableElements, aX, aY );
       
   727     if( iSvgEngine->Document() && viewableElements.Count() )
       
   728 		{
       
   729 		iSvgEngine->Document()->SetCurFocusObject(viewableElements[viewableElements.Count()-1]);	
       
   730 		}
       
   731 
       
   732     TSvgUiMouseEvent    uiev    ( ESvgEngineEventMouseMove, aX, aY );
       
   733     TRAPD( error, iSvgEngine->ProcessEventL( iSvgEngine->Document(), &uiev ) );
       
   734     if (error != KErrNone)
       
   735         {
       
   736         #ifdef _DEBUG
       
   737         _LIT(KProcessEventFailed, "CSvgEngineInterfaceImpl::MouseMove: ProcessEventL error.");
       
   738         RDebug::Print(KProcessEventFailed);
       
   739         #endif //_DEBUG
       
   740         }
       
   741 
       
   742     // Process for Mouse enter/exit
       
   743     TInt listenerCount = iSvgEngine->MouseListenerCount();
       
   744 
       
   745     if (iSvgEngine->Document())
       
   746     {
       
   747         listenerCount += iSvgEngine->Document()->MouseInternalListenerCount();
       
   748     }
       
   749     if ( listenerCount == 0 )
       
   750         {
       
   751         viewableElements.Close();
       
   752         return;
       
   753         }
       
   754     // Get list of elements containing pointer (bounding-box)
       
   755     RPointerArray<CSvgElementImpl> enteringElements;
       
   756     RPointerArray<CSvgElementImpl> stillInsideElements;
       
   757     iSvgEngine->GetViewableElementsAtPoint(iSvgEngine->Document(), viewableElements, aX, aY );
       
   758 
       
   759     // check for mouse entering of elements
       
   760     TInt viewableEleCnt = viewableElements.Count();
       
   761     for ( TInt i = 0; i < viewableEleCnt; i++ )
       
   762         {
       
   763         // If an element is in the view-list but NOT in the entered-list
       
   764         // then, it's copied to the entered-list
       
   765         // otherwise, ignore (still inside)
       
   766         if ( iSvgMouseEnteredElements.Find( viewableElements[i] ) == KErrNotFound )
       
   767             {
       
   768             enteringElements.Append( viewableElements[i] );
       
   769             }
       
   770         else
       
   771             {
       
   772             stillInsideElements.Append( viewableElements[i] );
       
   773             }
       
   774         }
       
   775 
       
   776     // check for mouse exiting of elements
       
   777     RPointerArray<CSvgElementImpl> exitingElements;
       
   778     TInt svgMouseEnteredEleCnt = iSvgMouseEnteredElements.Count();
       
   779     for ( TInt i = 0; i < svgMouseEnteredEleCnt; i++ )
       
   780         {
       
   781         // If an element is in the entered-list but not the view-list
       
   782         // then, it's copied to the exiting list
       
   783         // otherwise, ignore (
       
   784         if ( viewableElements.Find( iSvgMouseEnteredElements[i] ) == KErrNotFound )
       
   785             {
       
   786             exitingElements.Append( iSvgMouseEnteredElements[i] );
       
   787             }
       
   788         }
       
   789 
       
   790     // Remove exiting elements from entered list
       
   791     TInt exitingEleCnt = exitingElements.Count();
       
   792     for ( TInt i = 0; i < exitingEleCnt; i++ )
       
   793         {
       
   794         TInt index = iSvgMouseEnteredElements.Find( exitingElements[i] );
       
   795         if ( index != KErrNotFound )
       
   796             {
       
   797             iSvgMouseEnteredElements.Remove( index );
       
   798             }
       
   799         }
       
   800 
       
   801     // Add entering elements to entered-list
       
   802     TInt enteringEleCnt = enteringElements.Count();
       
   803     for ( TInt i = 0; i < enteringEleCnt; i++ )
       
   804         {
       
   805         iSvgMouseEnteredElements.Append( enteringElements[i] );
       
   806         }
       
   807 
       
   808     // Notify exiting
       
   809     if ( exitingElements.Count() > 0 )
       
   810         {
       
   811         iSvgEngine->NotifyMouseExited( exitingElements, aX, aY );
       
   812         if ( iSvgEngine->Document() )
       
   813             {
       
   814             iSvgEngine->Document()->NotifyInternalMouseExited( exitingElements, aX, aY );
       
   815             }
       
   816         }
       
   817 
       
   818     // Notify entering
       
   819     if ( enteringElements.Count() > 0 )
       
   820         {
       
   821         iSvgEngine->NotifyMouseEntered( enteringElements, aX, aY );
       
   822         if ( iSvgEngine->Document() )
       
   823             {
       
   824             iSvgEngine->Document()->NotifyInternalMouseEntered( enteringElements, aX, aY );
       
   825             }
       
   826         }
       
   827 
       
   828     // Notify moved
       
   829     if ( stillInsideElements.Count() > 0 )
       
   830         {
       
   831         iSvgEngine->NotifyMouseMoved( stillInsideElements, aX, aY );
       
   832         if ( iSvgEngine->Document() )
       
   833             {
       
   834             iSvgEngine->Document()->NotifyInternalMouseMoved( stillInsideElements, aX, aY );
       
   835             }
       
   836         }
       
   837 
       
   838     exitingElements.Close();
       
   839     enteringElements.Close();
       
   840     stillInsideElements.Close();
       
   841     viewableElements.Close();
       
   842     }
       
   843 
       
   844 // --------------------------------------------------------------------------
       
   845 // EXPORT_C void CSvgEngineInterfaceImpl::KeyPress( const TKeyEvent &aKeyEvent )
       
   846 // ---------------------------------------------------------------------------
       
   847 EXPORT_C void CSvgEngineInterfaceImpl::KeyPress( const TKeyEvent &aKeyEvent, TInt aEngine )
       
   848     {
       
   849 
       
   850     if (!ChooseEngine( aEngine ))
       
   851     {
       
   852     	return;
       
   853     }
       
   854 
       
   855     TSvgUiKeyEvent  uiev    ( aKeyEvent.iCode );
       
   856     TRAPD( error, iSvgEngine->ProcessEventL( iSvgEngine->Document(), &uiev ) );
       
   857     if (error != KErrNone)
       
   858         {
       
   859         #ifdef _DEBUG
       
   860         _LIT(KProcessEventFailed, "CSvgEngineInterfaceImpl::KeyPress: ProcessEventL error.");
       
   861         RDebug::Print(KProcessEventFailed);
       
   862         #endif //_DEBUG
       
   863         }
       
   864     }
       
   865 
       
   866 // --------------------------------------------------------------------------
       
   867 // EXPORT_C CSvgDocumentImpl* CSvgEngineInterfaceImpl::SvgDocument()
       
   868 // ---------------------------------------------------------------------------
       
   869 EXPORT_C CSvgDocumentImpl* CSvgEngineInterfaceImpl::SvgDocument()
       
   870     {
       
   871     //this method is a bad idea and should be removed
       
   872     return iSvgLoadedDocument;
       
   873     }
       
   874 
       
   875 
       
   876 //*****************************
       
   877 //
       
   878 // --------------------------------------------------------------------------
       
   879 // EXPORT_C void CSvgEngineInterfaceImpl::Zoom( TReal32 aScaleFactor )
       
   880 // ---------------------------------------------------------------------------
       
   881 EXPORT_C void CSvgEngineInterfaceImpl::Zoom( TReal32 aScaleFactor, TInt aEngine ) __SOFTFP
       
   882     {
       
   883     TGfxAffineTransform zT;
       
   884     MSvgTransformList*  trList = NULL;
       
   885     TFloatFixPt cx,cy;
       
   886     if( ChooseEngine( aEngine ) && iSvgEngine->Document() && iSvgEngine->GraphicsContext())
       
   887         {
       
   888         CSvgSvgElementImpl* lRoot   = ( CSvgSvgElementImpl* )
       
   889                                       iSvgEngine->Document()->RootElement();
       
   890         if ( lRoot )
       
   891             {
       
   892             if ( lRoot->GetZoomAndPan() == ESvgZoomAndPanMagnify )
       
   893                 {
       
   894                 // Calculate screen center in svg element's coordinate system
       
   895                 TSize               devSize = iSvgEngine->GraphicsContext()->DeviceBounds();
       
   896 
       
   897 				TGfxRectangle2D devbound;
       
   898                 lRoot->GetBBox( devbound );
       
   899 
       
   900 				    cx = TFloatFixPt(devSize.iWidth/2);
       
   901 				    cy = TFloatFixPt(devSize.iHeight/2);
       
   902 
       
   903                 lRoot->GetTransform( trList );
       
   904                 if( trList )
       
   905                     {
       
   906                     zT = trList->GetItem( 0 );
       
   907                     zT.UserZoom(aScaleFactor,cx,cy);
       
   908                     trList->ReplaceItem( zT, 0 );
       
   909 
       
   910                     lRoot->SetTransform(trList);
       
   911                     }
       
   912 
       
   913 
       
   914                 }
       
   915             }
       
   916         }
       
   917     }
       
   918 
       
   919 
       
   920 // --------------------------------------------------------------------------
       
   921 // EXPORT_C void CSvgEngineInterfaceImpl::Pan( TInt aX, TInt aY )
       
   922 // ---------------------------------------------------------------------------
       
   923 EXPORT_C void CSvgEngineInterfaceImpl::Pan( TInt aX, TInt aY, TInt aEngine )
       
   924 
       
   925     {
       
   926     TInt32 PanX = aX;
       
   927     TInt32 PanY = aY;
       
   928     TGfxAffineTransform pT;
       
   929     MSvgTransformList*  trList = NULL;
       
   930 
       
   931     if( ChooseEngine( aEngine ) && iSvgEngine->Document() )
       
   932         {
       
   933 
       
   934         CSvgSvgElementImpl* lRoot   = ( CSvgSvgElementImpl* )
       
   935                                       iSvgEngine->Document()->RootElement();
       
   936         if ( lRoot )
       
   937             {
       
   938             if ( lRoot->GetZoomAndPan() == ESvgZoomAndPanMagnify )
       
   939                 {
       
   940 
       
   941                 // Do panning
       
   942                 lRoot->GetTransform( trList );
       
   943                 if( trList )
       
   944                     {
       
   945                     pT = trList->GetItem( 0 );
       
   946 
       
   947 
       
   948                     pT.UserPan( PanX , PanY  );
       
   949 
       
   950                     trList->ReplaceItem( pT, 0 );
       
   951 
       
   952                     lRoot->SetTransform(trList);
       
   953                     }
       
   954                 }
       
   955             }
       
   956         }
       
   957     }
       
   958 
       
   959 // ---------------------------------------------------------------------------
       
   960 // Panning indicator
       
   961 // ---------------------------------------------------------------------------
       
   962 
       
   963 EXPORT_C TBool CSvgEngineInterfaceImpl::IsPanPossible( TInt aX, TInt aY, TInt aEngine )
       
   964 
       
   965     {
       
   966     if( !ChooseEngine( aEngine ) || (iSvgEngine->Document() == NULL) )
       
   967     {
       
   968         return EFalse;
       
   969     }
       
   970 
       
   971     CSvgSvgElementImpl* lRoot   = ( CSvgSvgElementImpl* )
       
   972                                       iSvgEngine->Document()->RootElement();
       
   973     if ( lRoot == NULL)
       
   974         return EFalse;
       
   975     if ( lRoot->GetZoomAndPan() != ESvgZoomAndPanMagnify )
       
   976         return EFalse;
       
   977 
       
   978     // Get the clipping size
       
   979     TFloatFixPt  clipWidthFP, clipHeightFP;
       
   980     TInt    clipWidth, clipHeight;
       
   981     lRoot->GetAttributeFloat( KAtrWidth, clipWidthFP );
       
   982     lRoot->GetAttributeFloat( KAtrHeight, clipHeightFP );
       
   983     clipWidth = ( TInt ) clipWidthFP;
       
   984     clipHeight = ( TInt ) clipHeightFP;
       
   985     // Get bounding box of svg element
       
   986     TFloatFixPt          zero    ( 0 );
       
   987     TGfxRectangle2D bound;
       
   988     lRoot->GetBBox( bound );
       
   989     TInt32  xmax    = ( bound.iX + bound.iWidth );
       
   990     TInt32  ymax    = ( bound.iY + bound.iHeight );
       
   991 
       
   992     // check  them
       
   993     if ( xmax <= clipWidth && aX < 0 )
       
   994         aX = 0;
       
   995     if ( bound.iX >= zero && aX > 0 )
       
   996         aX = 0;
       
   997     if ( ymax <= clipHeight && aY < 0 )
       
   998         aY = 0;
       
   999     if ( bound.iY >= zero && aY > 0 )
       
  1000         aY = 0;
       
  1001     // Do panning
       
  1002     if ( ( aY == 0 ) && ( aX == 0 ) )
       
  1003         return EFalse;
       
  1004     else
       
  1005        return ETrue;
       
  1006 
       
  1007     }
       
  1008 
       
  1009 // ---------------------------------------------------------------------------
       
  1010 // Panning indicator
       
  1011 // ---------------------------------------------------------------------------
       
  1012 
       
  1013 EXPORT_C void CSvgEngineInterfaceImpl::IsPanPossibleFourWay
       
  1014     ( TBool& left, TBool& right, TBool& up, TBool& down, TInt aEngine )
       
  1015 
       
  1016     {
       
  1017 
       
  1018     left = right = up = down = EFalse;
       
  1019 
       
  1020     if( !ChooseEngine( aEngine ) || (iSvgEngine->Document() == NULL) )
       
  1021     {
       
  1022         return ;
       
  1023     }
       
  1024 
       
  1025     CSvgSvgElementImpl* lRoot   = ( CSvgSvgElementImpl* )
       
  1026                                       iSvgEngine->Document()->RootElement();
       
  1027     if ( lRoot == NULL)
       
  1028         return ;
       
  1029     if ( lRoot->GetZoomAndPan() != ESvgZoomAndPanMagnify )
       
  1030         return ;
       
  1031 
       
  1032     // Get the clipping size
       
  1033     TFloatFixPt  clipWidthFP, clipHeightFP;
       
  1034     TInt    clipWidth, clipHeight;
       
  1035     lRoot->GetAttributeFloat( KAtrWidth, clipWidthFP );
       
  1036     lRoot->GetAttributeFloat( KAtrHeight, clipHeightFP );
       
  1037     clipWidth = ( TInt ) clipWidthFP;
       
  1038     clipHeight = ( TInt ) clipHeightFP;
       
  1039     //the svg element has no width or height no reason to pan.
       
  1040     if (clipWidth <= 0 || clipHeight <= 0)
       
  1041     {
       
  1042     	return;
       
  1043     }
       
  1044     // Get bounding box of svg element
       
  1045     TFloatFixPt          zero    ( 0 );
       
  1046     TGfxRectangle2D bound;
       
  1047     lRoot->GetBBox( bound );
       
  1048     //fix if no width or heigth is there.
       
  1049     if((TInt32)bound.iWidth <=0 ||(TInt32) bound.iHeight <=0 )
       
  1050         return;
       
  1051     TInt32  xmax    = ( bound.iX + bound.iWidth );
       
  1052     TInt32  ymax    = ( bound.iY + bound.iHeight );
       
  1053 
       
  1054     // check the panning in four directions now.
       
  1055     TInt aX,aY;
       
  1056     // Check in Left direction
       
  1057     aX = 1; aY = 0;
       
  1058     if ( xmax <= clipWidth && aX < 0 )
       
  1059         aX = 0;
       
  1060     if ( bound.iX >= zero && aX > 0 )
       
  1061         aX = 0;
       
  1062     if ( ymax <= clipHeight && aY < 0 )
       
  1063         aY = 0;
       
  1064     if ( bound.iY >= zero && aY > 0 )
       
  1065         aY = 0;
       
  1066     // Do panning
       
  1067     if ( ( aY == 0 ) && ( aX == 0 ) )
       
  1068 	    left = EFalse;
       
  1069     else
       
  1070 	    left = ETrue;
       
  1071 
       
  1072     // Check in Right direction
       
  1073     aX = -1; aY = 0;
       
  1074     if ( xmax <= clipWidth && aX < 0 )
       
  1075         aX = 0;
       
  1076     if ( bound.iX >= zero && aX > 0 )
       
  1077         aX = 0;
       
  1078     if ( ymax <= clipHeight && aY < 0 )
       
  1079         aY = 0;
       
  1080     if ( bound.iY >= zero && aY > 0 )
       
  1081         aY = 0;
       
  1082     // Do panning
       
  1083     if ( ( aY == 0 ) && ( aX == 0 ) )
       
  1084 	    right = EFalse;
       
  1085     else
       
  1086 	    right = ETrue;
       
  1087 
       
  1088     // Check in Up direction
       
  1089     aX = 0; aY = 1;
       
  1090     if ( xmax <= clipWidth && aX < 0 )
       
  1091         aX = 0;
       
  1092     if ( bound.iX >= zero && aX > 0 )
       
  1093         aX = 0;
       
  1094     if ( ymax <= clipHeight && aY < 0 )
       
  1095         aY = 0;
       
  1096     if ( bound.iY >= zero && aY > 0 )
       
  1097         aY = 0;
       
  1098     // Do panning
       
  1099     if ( ( aY == 0 ) && ( aX == 0 ) )
       
  1100 	    up = EFalse;
       
  1101     else
       
  1102 	    up = ETrue;
       
  1103 
       
  1104     // Check in down direction
       
  1105     aX = 0; aY = -1;
       
  1106     if ( xmax <= clipWidth && aX < 0 )
       
  1107         aX = 0;
       
  1108     if ( bound.iX >= zero && aX > 0 )
       
  1109         aX = 0;
       
  1110     if ( ymax <= clipHeight && aY < 0 )
       
  1111         aY = 0;
       
  1112     if ( bound.iY >= zero && aY > 0 )
       
  1113         aY = 0;
       
  1114     // Do panning
       
  1115     if ( ( aY == 0 ) && ( aX == 0 ) )
       
  1116 	    down = EFalse;
       
  1117     else
       
  1118 	    down = ETrue;
       
  1119 
       
  1120     }
       
  1121 // --------------------------------------------------------------------------
       
  1122 // EXPORT_C void CSvgEngineInterfaceImpl::Rotate( TReal32 aAngle,
       
  1123 // ---------------------------------------------------------------------------
       
  1124 EXPORT_C void CSvgEngineInterfaceImpl::Rotate( TReal32 aAngle,
       
  1125                                                TInt aX,
       
  1126                                                TInt aY,
       
  1127                                                TInt aEngine ) __SOFTFP
       
  1128 
       
  1129     {
       
  1130     TGfxAffineTransform rT;
       
  1131     MSvgTransformList*  trList = NULL;
       
  1132 
       
  1133     if( ChooseEngine( aEngine ) && iSvgEngine->Document() )
       
  1134         {
       
  1135         CSvgSvgElementImpl* lRoot   = ( CSvgSvgElementImpl* )
       
  1136                                       iSvgEngine->Document()->RootElement();
       
  1137 
       
  1138         if ( lRoot )
       
  1139             {
       
  1140             if ( lRoot->GetZoomAndPan() == ESvgZoomAndPanMagnify )
       
  1141                 {
       
  1142                 lRoot->GetTransform( trList );
       
  1143                 if( trList )
       
  1144                     {
       
  1145                     rT = trList->GetItem( 0 );
       
  1146 
       
  1147                     rT.UserRotate( aAngle, aX, aY );
       
  1148                     trList->ReplaceItem( rT, 0 );
       
  1149                     iTotalRotation +=  aAngle;
       
  1150                     }
       
  1151                 lRoot->SetTransform(trList); //added
       
  1152                 }
       
  1153             }
       
  1154         }
       
  1155     }
       
  1156 
       
  1157 // ==========================================================================
       
  1158 // ContentDimensions integer value version
       
  1159 //1)  Return the size of the <svg> width/height if given in non-percentage.
       
  1160 //
       
  1161 //2)  If <svg> width/height are given as percentages:
       
  1162 //    A) If viewbox attribute is specified, return the viewbox width/height times the <svg> width/height percentages.
       
  1163 //    B) Return the content bounding-box size times times the <svg> width/height percentages.
       
  1164 // ==========================================================================
       
  1165 EXPORT_C TSize CSvgEngineInterfaceImpl::ContentDimensions( TInt aEngine )
       
  1166     {
       
  1167     if ( !ChooseEngine( aEngine ) || !iSvgEngine->Document() )
       
  1168         {
       
  1169         return TSize( 0, 0 );
       
  1170         }
       
  1171 
       
  1172     CSvgSvgElementImpl* svgElement = (CSvgSvgElementImpl* )iSvgEngine->Document()->RootElement();
       
  1173 
       
  1174     if ( !svgElement )
       
  1175         {
       
  1176         return TSize( 0, 0 );
       
  1177         }
       
  1178 
       
  1179     // width/height are given as user-units
       
  1180         if ( !( svgElement->iWidthInPercentage ) && !(svgElement->iHeightInPercentage))
       
  1181         {
       
  1182         return TSize( (TInt)svgElement->iWidthInUserCoordinate,
       
  1183                       (TInt)svgElement->iHeightInUserCoordinate );
       
  1184         }
       
  1185 
       
  1186     // width/height are given as percentages
       
  1187     TInt percentWidth = (TInt)svgElement->iWidthInUserCoordinate;
       
  1188     TInt percentHeight = (TInt)svgElement->iHeightInUserCoordinate;
       
  1189     // Multiply percentages with viewbox if available
       
  1190     TGfxRectangle2D viewBox;
       
  1191     if ( svgElement->GetViewBox( viewBox ) )
       
  1192         {
       
  1193             TInt tempWidth = 0, tempHeight = 0;
       
  1194             
       
  1195             if( svgElement->iWidthInPercentage )
       
  1196             {
       
  1197                 tempWidth  = ((TReal32)viewBox.iWidth)  * percentWidth / 100.0;    
       
  1198             }
       
  1199             else
       
  1200             {
       
  1201                 tempWidth = viewBox.iWidth;
       
  1202             }
       
  1203         
       
  1204             if( svgElement->iHeightInPercentage )
       
  1205             {
       
  1206                 tempHeight = ((TReal32)viewBox.iHeight) * percentHeight / 100.0;    
       
  1207             }
       
  1208             else
       
  1209             {
       
  1210                 tempHeight = viewBox.iHeight;
       
  1211             }
       
  1212             return TSize(tempWidth, tempHeight);
       
  1213         }
       
  1214     // return the <svg> bounding box
       
  1215     else
       
  1216         {
       
  1217         TSize bbSize = GetSvgBoundingBox().Size();
       
  1218             if( svgElement->iWidthInPercentage )
       
  1219             {
       
  1220                 bbSize.iWidth  = ((TReal32)bbSize.iWidth)  * percentWidth / 100.0;    
       
  1221             }
       
  1222             else
       
  1223             {
       
  1224                 bbSize.iWidth = bbSize.iWidth;
       
  1225             }
       
  1226         
       
  1227             if( svgElement->iHeightInPercentage )
       
  1228             {
       
  1229                 bbSize.iHeight = ((TReal32)bbSize.iHeight) * percentHeight / 100.0;    
       
  1230             }
       
  1231             else
       
  1232             {
       
  1233                 bbSize.iHeight = bbSize.iHeight;
       
  1234             }
       
  1235         return bbSize;
       
  1236         }
       
  1237     }
       
  1238 
       
  1239 // ==========================================================================
       
  1240 // ContentDimensions floating-point value version
       
  1241 //1)  Return the size of the <svg> width/height if given in non-percentage.
       
  1242 //
       
  1243 //2)  If <svg> width/height are given as percentages:
       
  1244 //    A) If viewbox attribute is specified, return the viewbox width/height times the <svg> width/height percentages.
       
  1245 //    B) Return the content bounding-box size times times the <svg> width/height percentages.
       
  1246 // ==========================================================================
       
  1247 EXPORT_C void CSvgEngineInterfaceImpl::ContentDimensions( TReal32& aWidth, TReal32& aHeight, TInt aEngine ) __SOFTFP
       
  1248     {
       
  1249     aWidth  = 0.0;
       
  1250     aHeight = 0.0;
       
  1251     if ( !ChooseEngine( aEngine ) || !iSvgEngine->Document() )
       
  1252         {
       
  1253         return;
       
  1254         }
       
  1255 
       
  1256     CSvgSvgElementImpl* svgElement = (CSvgSvgElementImpl* )iSvgEngine->Document()->RootElement();
       
  1257 
       
  1258     if ( !svgElement )
       
  1259         {
       
  1260         return;
       
  1261         }
       
  1262 
       
  1263     // width/height are given as user-units
       
  1264         if ( !( svgElement->iWidthInPercentage ) && !( svgElement->iHeightInPercentage) )
       
  1265         {
       
  1266         #ifdef _DEBUG
       
  1267         RDebug::Printf("content size: %.4fx%.4f",
       
  1268                       svgElement->iWidthInUserCoordinate,
       
  1269                       svgElement->iHeightInUserCoordinate );
       
  1270 
       
  1271         #endif
       
  1272         aWidth  = svgElement->iWidthInUserCoordinate;
       
  1273         aHeight = svgElement->iHeightInUserCoordinate;
       
  1274         return;
       
  1275         }
       
  1276 
       
  1277     // width/height are given as percentages
       
  1278     TReal32 percentWidth  = svgElement->iWidthInUserCoordinate;
       
  1279     TReal32 percentHeight = svgElement->iHeightInUserCoordinate;
       
  1280 
       
  1281     // Multiply percentages with viewbox if available
       
  1282     TGfxRectangle2D viewBox;
       
  1283     if ( svgElement->GetViewBox( viewBox ) )
       
  1284         {
       
  1285         #ifdef _DEBUG
       
  1286         RDebug::Printf("viewbox is defined: %.4fx%.4f",
       
  1287                       ((TReal32)viewBox.iWidth) * percentWidth / 100.0,
       
  1288                       ((TReal32)viewBox.iHeight) * percentHeight / 100.0 );
       
  1289 
       
  1290         #endif
       
  1291             if( svgElement->iWidthInPercentage )
       
  1292             {
       
  1293         aWidth  = ((TReal32)viewBox.iWidth)  * percentWidth / 100.0;
       
  1294             }
       
  1295             else
       
  1296             {
       
  1297                 aWidth = viewBox.iWidth;
       
  1298             }
       
  1299         
       
  1300             if( svgElement->iHeightInPercentage )
       
  1301             {
       
  1302         aHeight = ((TReal32)viewBox.iHeight) * percentHeight / 100.0;
       
  1303             }
       
  1304             else
       
  1305             {
       
  1306                 aHeight = viewBox.iHeight;
       
  1307             }
       
  1308         return;
       
  1309         }
       
  1310     // return the <svg> bounding box
       
  1311     else
       
  1312         {
       
  1313         CSvgSvgElementImpl* lRoot = ( CSvgSvgElementImpl* )iSvgEngine->Document()->RootElement();
       
  1314         if( lRoot )
       
  1315             {
       
  1316             TReal32 x, y;
       
  1317             GetElementBoundingbox( lRoot, x, y, aWidth, aHeight );
       
  1318                 if(svgElement->iWidthInPercentage )
       
  1319                 {
       
  1320             aWidth  = aWidth  * percentWidth / 100.0;
       
  1321                 }
       
  1322                 if(svgElement->iHeightInPercentage )
       
  1323                 {
       
  1324             aHeight = aHeight * percentHeight / 100.0;
       
  1325                 }
       
  1326             }
       
  1327         }
       
  1328     }
       
  1329 
       
  1330 // --------------------------------------------------------------------------
       
  1331 // EXPORT_C TSize CSvgEngineInterfaceImpl::ContentDimensions()
       
  1332 // ---------------------------------------------------------------------------
       
  1333 EXPORT_C TSize CSvgEngineInterfaceImpl::ContentDimensionsInPercentage( TInt aEngine )
       
  1334     {
       
  1335     TSize lSize;
       
  1336 
       
  1337     if( ChooseEngine( aEngine ) && (iSvgEngine->Document() != NULL) )
       
  1338         {
       
  1339         CSvgSvgElementImpl* rootElement = ( CSvgSvgElementImpl* )
       
  1340                                       iSvgEngine->Document()->RootElement();
       
  1341 
       
  1342         if ( rootElement != NULL )
       
  1343             {
       
  1344              if(rootElement->iWidthInPercentage)
       
  1345                 {
       
  1346                 lSize.iWidth = ( TFloatFixPt ) ( rootElement->iWidthInUserCoordinate );
       
  1347              }
       
  1348              else
       
  1349              {  
       
  1350                 lSize.iWidth = -1;
       
  1351              }
       
  1352              if(rootElement->iHeightInPercentage)
       
  1353              {
       
  1354                 lSize.iHeight = ( TFloatFixPt ) ( rootElement->iHeightInUserCoordinate );
       
  1355                 }
       
  1356              else
       
  1357              {
       
  1358                 lSize.iHeight = -1;
       
  1359              }
       
  1360             }
       
  1361 
       
  1362         }
       
  1363     return lSize;
       
  1364     }
       
  1365 // --------------------------------------------------------------------------
       
  1366 // EXPORT_C TRect CSvgEngineInterfaceImpl::FocusNext()
       
  1367 // ---------------------------------------------------------------------------
       
  1368 EXPORT_C TRect CSvgEngineInterfaceImpl::FocusNext()
       
  1369     {
       
  1370     if(iSvgEngine->Document())
       
  1371     iSvgEngine->Document()->IncCurFocusIndex();
       
  1372     return (GetFocusBbox(ETrue));
       
  1373     }
       
  1374 
       
  1375 // --------------------------------------------------------------------------
       
  1376 // EXPORT_C TRect CSvgEngineInterfaceImpl::FocusPrevious()
       
  1377 // ---------------------------------------------------------------------------
       
  1378 EXPORT_C TRect CSvgEngineInterfaceImpl::FocusPrevious()
       
  1379     {
       
  1380     if(iSvgEngine->Document())
       
  1381     iSvgEngine->Document()->DecCurFocusIndex();
       
  1382     return (GetFocusBbox(EFalse));
       
  1383     }
       
  1384 
       
  1385 // --------------------------------------------------------------------------
       
  1386 // EXPORT_C void CSvgEngineInterfaceImpl::ActivateObjectInFocus()
       
  1387 // ---------------------------------------------------------------------------
       
  1388 EXPORT_C void CSvgEngineInterfaceImpl::ActivateObjectInFocus()
       
  1389     {
       
  1390     TGfxRectangle2D lBbox;
       
  1391 
       
  1392     if( iSvgEngine->Document() && iSvgEngine->Document()->GetCurFocusObject() )
       
  1393         {
       
  1394         iSvgEngine->Document()->GetCurFocusObject()->GetBBox( lBbox );
       
  1395         // Send mouse down and mouse up events to the engine
       
  1396         // This will send message back to the application to handle the activation
       
  1397         MouseDown( lBbox.CenterX(), lBbox.CenterY() );
       
  1398         MouseUp( lBbox.CenterX(), lBbox.CenterY() );
       
  1399         }
       
  1400     }
       
  1401 
       
  1402 // --------------------------------------------------------------------------
       
  1403 // EXPORT_C TInt32 CSvgEngineInterfaceImpl::MediaTime()
       
  1404 // ---------------------------------------------------------------------------
       
  1405 EXPORT_C TInt32 CSvgEngineInterfaceImpl::MediaTime( TInt aEngine )
       
  1406     {
       
  1407     	if (ChooseEngine( aEngine ))
       
  1408     	{
       
  1409     		return iSvgEngine->CurrentTIme();
       
  1410     	}
       
  1411 
       
  1412     	return 0;
       
  1413     }
       
  1414 
       
  1415 // --------------------------------------------------------------------------
       
  1416 // EXPORT_C void CSvgEngineInterfaceImpl::SetMediaTime(TInt32 aTime)
       
  1417 // ---------------------------------------------------------------------------
       
  1418 EXPORT_C void CSvgEngineInterfaceImpl::SetMediaTime(TInt32 aTime, TInt aEngine )
       
  1419     {
       
  1420 
       
  1421     // Time given is in milliseconds whereas the time needed by timer is microseconds
       
  1422     // Resume(aTime * 1000);
       
  1423     	if ( ChooseEngine( aEngine ) )
       
  1424     	{
       
  1425     		iSvgEngine->SetMediaTime(aTime* 1000);
       
  1426     	}
       
  1427     }
       
  1428 
       
  1429 // --------------------------------------------------------------------------
       
  1430 // void CSvgEngineInterfaceImpl::ResetFocusIndex(TInt32 aIndex)
       
  1431 // ---------------------------------------------------------------------------
       
  1432 void CSvgEngineInterfaceImpl::ResetFocusIndex(TInt32 /*aIndex*/)
       
  1433     {
       
  1434     //iSvgEngine->Document()->SetCurIndex(TInt32 aVal); aIndex;
       
  1435     }
       
  1436 
       
  1437 
       
  1438 // --------------------------------------------------------------------------
       
  1439 // TRect CSvgEngineInterfaceImpl::GetFocusBbox( TBool aNextObj )
       
  1440 // ---------------------------------------------------------------------------
       
  1441 TRect CSvgEngineInterfaceImpl::GetFocusBbox( TBool aNextObj, TInt aEngine )
       
  1442     {
       
  1443     TGfxRectangle2D lBbox;
       
  1444     TInt32 lNewIndex;
       
  1445 
       
  1446     if( ChooseEngine( aEngine ) && iSvgEngine->Document() )
       
  1447         {
       
  1448         // Obtain the current focussable object starting with the current index
       
  1449         
       
  1450         // The GetEventReceiverElement function takes in parameters as the 
       
  1451         //current focus objects index and whether we are going next or previous
       
  1452         // and the mask of the kind of input that we are accepting..
       
  1453         // It returns the value of the new index through the lNewIndex.
       
  1454         iSvgEngine->Document()->SetCurFocusObject ( 
       
  1455          						iSvgEngine->Document()->GetEventReceiverElement(
       
  1456          						 iSvgEngine->Document()->GetCurFocusIndex(),
       
  1457          						  aNextObj, KSvgEventMaskExternalUI,
       
  1458          						   lNewIndex ));
       
  1459         // Update the index to where the focussable object was found
       
  1460         iSvgEngine->Document()->SetCurFocusIndex(lNewIndex);
       
  1461 
       
  1462         if( iSvgEngine->Document()->GetCurFocusObject() )
       
  1463             {
       
  1464             iSvgEngine->Document()->GetCurFocusObject()->GetBBox(lBbox);
       
  1465 
       
  1466             // Send a mouse move event to the engine
       
  1467             MouseMove( lBbox.CenterX(), lBbox.CenterY() );
       
  1468             }
       
  1469         }
       
  1470 
       
  1471     return TRect( lBbox.iX, lBbox.iY, lBbox.iX + lBbox.iWidth, lBbox.iY + lBbox.iHeight );
       
  1472     }
       
  1473 
       
  1474 
       
  1475 // --------------------------------------------------------------------------
       
  1476 // void CSvgEngineInterfaceImpl::Resume(TInt32 aTime)
       
  1477 // ---------------------------------------------------------------------------
       
  1478 void CSvgEngineInterfaceImpl::Resume(TInt32 aTime, TInt aEngine )
       
  1479     {
       
  1480     	if ( ChooseEngine( aEngine ) )
       
  1481     	{
       
  1482     		iSvgEngine->Resume(aTime);
       
  1483     	}
       
  1484     }
       
  1485 // --------------------------------------------------------------------------
       
  1486 // EXPORT_C TSize CSvgEngineInterfaceImpl::Size()
       
  1487 // ---------------------------------------------------------------------------
       
  1488 EXPORT_C TSize CSvgEngineInterfaceImpl::Size( TInt aEngine )
       
  1489     {
       
  1490     TSize lSize(0,0);
       
  1491 
       
  1492     if( ChooseEngine( aEngine ) )
       
  1493         {
       
  1494         CSvgDocumentImpl* lSvgDocument = iSvgEngine->Document();
       
  1495         if( lSvgDocument )
       
  1496             {
       
  1497             CSvgSvgElementImpl* lSvgRootElement = (CSvgSvgElementImpl *)lSvgDocument->RootElement();
       
  1498             if( lSvgRootElement )
       
  1499                 {
       
  1500                 lSize.iWidth = (TInt)lSvgRootElement->Width();
       
  1501                 lSize.iHeight = (TInt)lSvgRootElement->Height();
       
  1502                 }
       
  1503             }
       
  1504         }
       
  1505     return lSize;
       
  1506     }
       
  1507 // --------------------------------------------------------------------------
       
  1508 // EXPORT_C TPoint CSvgEngineInterfaceImpl::Position()
       
  1509 // ---------------------------------------------------------------------------
       
  1510 EXPORT_C TPoint CSvgEngineInterfaceImpl::Position( TInt aEngine )
       
  1511     {
       
  1512     TPoint lPoint(0,0);
       
  1513 
       
  1514     if(ChooseEngine( aEngine ))
       
  1515         {
       
  1516         CSvgDocumentImpl* lSvgDocument = iSvgEngine->Document();
       
  1517         if( lSvgDocument )
       
  1518             {
       
  1519             CSvgSvgElementImpl* lSvgRootElement = (CSvgSvgElementImpl *)lSvgDocument->RootElement();
       
  1520             if( lSvgRootElement )
       
  1521                 {
       
  1522                 lPoint.iX = (TInt)lSvgRootElement->X();
       
  1523                 lPoint.iY = (TInt)lSvgRootElement->Y();
       
  1524                 }
       
  1525             }
       
  1526         }
       
  1527     return lPoint;
       
  1528     }
       
  1529 
       
  1530 // --------------------------------------------------------------------------
       
  1531 // EXPORT_C void CSvgEngineInterfaceImpl::GenerateMask(CFbsBitmap* aMask)
       
  1532 // ---------------------------------------------------------------------------
       
  1533 EXPORT_C void CSvgEngineInterfaceImpl::GenerateMask(CFbsBitmap* aMask, TInt aEngine )
       
  1534     {
       
  1535         if ( ChooseEngine( aEngine ) )
       
  1536         {
       
  1537             iSvgEngine->GenerateMask(aMask);
       
  1538         }
       
  1539     }
       
  1540 
       
  1541 
       
  1542 // --------------------------------------------------------------------------
       
  1543 // EXPORT_C void CSvgEngineInterfaceImpl::SetBackgroundColor(TUint32 aRGBA8888Color, CSvgEngineImpl* aEngine)
       
  1544 // ---------------------------------------------------------------------------
       
  1545 EXPORT_C void CSvgEngineInterfaceImpl::SetBackgroundColor(TUint32 aRGBA8888Color, CSvgEngineImpl* aEngine)
       
  1546     {
       
  1547     	if (ChooseEngine( (TInt)aEngine ))
       
  1548     	{
       
  1549         	iSvgEngine->SetBackgroundColor(aRGBA8888Color);
       
  1550         }
       
  1551     }
       
  1552 
       
  1553 
       
  1554 // --------------------------------------------------------------------------
       
  1555 // EXPORT_C TInt CSvgEngineInterfaceImpl::CurrentState()
       
  1556 // ---------------------------------------------------------------------------
       
  1557 EXPORT_C TInt CSvgEngineInterfaceImpl::CurrentState( TInt aEngine )
       
  1558     {
       
  1559         if (ChooseEngine(aEngine))
       
  1560         {
       
  1561             return (TInt) iSvgEngine->SVGEngineState();
       
  1562         }
       
  1563 
       
  1564     return 0;
       
  1565     }
       
  1566 
       
  1567 
       
  1568 
       
  1569 // --------------------------------------------------------------------------
       
  1570 // EXPORT_C TPoint CSvgEngineInterfaceImpl::PanPosition()
       
  1571 // ---------------------------------------------------------------------------
       
  1572 EXPORT_C TPoint CSvgEngineInterfaceImpl::PanPosition( TInt aEngine )
       
  1573     {
       
  1574     TPoint lPoint;
       
  1575 
       
  1576     if( ChooseEngine(aEngine) && iSvgEngine->Document() )
       
  1577         {
       
  1578         CSvgSvgElementImpl* lRoot = ( CSvgSvgElementImpl* )
       
  1579                                         iSvgEngine->Document()->RootElement();
       
  1580         if ( lRoot )
       
  1581             {
       
  1582             MSvgTransformList*  trList = NULL;
       
  1583 
       
  1584             lRoot->GetTransform( trList );
       
  1585 
       
  1586             if( trList )
       
  1587                 {
       
  1588                 TGfxAffineTransform pT = trList->GetItem( 0 );
       
  1589 
       
  1590                 lPoint.iX = (TInt) pT.TranslateX();
       
  1591                 lPoint.iY = (TInt) pT.TranslateY();
       
  1592                 }
       
  1593             }
       
  1594         }
       
  1595 
       
  1596     return lPoint;
       
  1597     }
       
  1598 
       
  1599 
       
  1600 
       
  1601 // --------------------------------------------------------------------------
       
  1602 // EXPORT_C MSvgError*  CSvgEngineInterfaceImpl::Replay()
       
  1603 // ---------------------------------------------------------------------------
       
  1604 EXPORT_C MSvgError*  CSvgEngineInterfaceImpl::Replay( TInt aEngine )
       
  1605     {
       
  1606 
       
  1607     iTotalRotation = 0;
       
  1608 
       
  1609     if( ChooseEngine(aEngine) )
       
  1610     {
       
  1611         iSvgEngine->SetMediaTime( 0 );
       
  1612         return NULL;
       
  1613     }
       
  1614     return iSvgError;
       
  1615     }
       
  1616 
       
  1617 /*SVGT DOM API Caching APIs*/
       
  1618 // --------------------------------------------------------------------------
       
  1619 // EXPORT_C MSvgError* CSvgEngineInterfaceImpl::PrepareDom(const TDesC& aFileName, TInt& aHandle)
       
  1620 // ---------------------------------------------------------------------------
       
  1621 EXPORT_C MSvgError* CSvgEngineInterfaceImpl::PrepareDom(const TDesC& aFileName, TInt& aHandle, TInt aEngine)
       
  1622 {
       
  1623     // Create session to open file
       
  1624     RFs session;
       
  1625     CSvgDocumentImpl::OpenSession( session, *iSvgError );
       
  1626     if ( iSvgError->HasError() )
       
  1627     {
       
  1628         return iSvgError;
       
  1629     }
       
  1630 
       
  1631     // Open file handle
       
  1632     RFile fileHandle;
       
  1633     TInt openError = fileHandle.Open( session, aFileName, EFileRead );
       
  1634     if ( openError != KErrNone )
       
  1635     {
       
  1636         _LIT(msg, "Fail to open file for reading: ");
       
  1637         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, openError,
       
  1638                                         msg, aFileName );
       
  1639     }
       
  1640     else
       
  1641     {
       
  1642         PrepareDom( fileHandle, aHandle, aEngine );
       
  1643     }
       
  1644     session.Close();
       
  1645     return iSvgError;
       
  1646 }
       
  1647 
       
  1648 // --------------------------------------------------------------------------
       
  1649 // EXPORT_C MSvgError* CSvgEngineInterfaceImpl::PrepareDom( RFile& aFileHandle, TInt& aHandle )
       
  1650 // ---------------------------------------------------------------------------
       
  1651 EXPORT_C MSvgError* CSvgEngineInterfaceImpl::PrepareDom( RFile& aFileHandle, TInt& aHandle, TInt aEngine )
       
  1652 	{
       
  1653   	// reset to start of file
       
  1654     TInt zero = 0;
       
  1655     aFileHandle.Seek( ESeekStart, zero );
       
  1656 
       
  1657     TInt fileSize = 0;
       
  1658     TInt sizeError = aFileHandle.Size( fileSize );
       
  1659     if ( sizeError != KErrNone )
       
  1660     	{
       
  1661         _LIT( KErrorMsg, "Failed to Load Svg Content: Read File Size Error." );
       
  1662         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, sizeError,
       
  1663                                         KErrorMsg, KNullDesC );
       
  1664         return iSvgError;
       
  1665     	}
       
  1666 
       
  1667     //It is the fix for ESMA-7PN9WU
       
  1668     //file size should be more than 2 bytes
       
  1669     if ( fileSize < 2)
       
  1670         {
       
  1671         _LIT( KErrorMsg, "File is empty" );
       
  1672         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, sizeError,
       
  1673                                         KErrorMsg, KNullDesC );
       
  1674         return iSvgError;
       
  1675         }
       
  1676 
       
  1677 	HBufC8* binaryBuffer=NULL;
       
  1678   	
       
  1679 	binaryBuffer = HBufC8::New ( fileSize ); 
       
  1680 	 if (!binaryBuffer)
       
  1681     	{
       
  1682         _LIT( KErrorMsg, "Failed to Load Svg Content: Out of memory");
       
  1683         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgNoMemory, KErrNoMemory,
       
  1684                                         KErrorMsg, KNullDesC );
       
  1685         return iSvgError;
       
  1686     	}
       
  1687 	
       
  1688 	TPtr8 binaryBufferPtr = binaryBuffer->Des();
       
  1689 	TInt readError = aFileHandle.Read(binaryBufferPtr, fileSize);
       
  1690 	if ( readError != KErrNone )
       
  1691     	{
       
  1692         _LIT( KErrorMsg, "Failed to Load Svg Content: Read File Data Error");
       
  1693         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgNoMemory, readError,
       
  1694                                         KErrorMsg, KNullDesC );
       
  1695         delete binaryBuffer;
       
  1696         return iSvgError;
       
  1697     	}
       
  1698 		
       
  1699 	// For files which are in UTF-16 or unicode format the first 2 bytes
       
  1700 	// will be FF and FE. In UTF-16 and unicode format every single character
       
  1701 	// is represented by two bytes. 
       
  1702 	TInt hichar = (CEditableText::EReversedByteOrderMark & 0xFF00)>>8;
       
  1703 	TInt lochar = CEditableText::EReversedByteOrderMark & 0x00FF;
       
  1704 	TInt bytesPerChar = 1;
       
  1705 
       
  1706 		if(binaryBufferPtr[0] == hichar && binaryBufferPtr[1] == lochar)
       
  1707 		{
       
  1708 		bytesPerChar = 2;
       
  1709 
       
  1710 		HBufC* dataBuffer=NULL;
       
  1711 
       
  1712 		dataBuffer = HBufC::New(fileSize/bytesPerChar);
       
  1713 		if ( !dataBuffer)
       
  1714     		{
       
  1715         	_LIT( KErrorMsg, "Failed to Load Svg Content: Out of memory");
       
  1716         	CSvgDocumentImpl::PrepareError( *iSvgError, ESvgNoMemory, KErrNoMemory,
       
  1717                                         KErrorMsg, KNullDesC );
       
  1718         	delete binaryBuffer;
       
  1719         	return iSvgError;
       
  1720     		}
       
  1721 	
       
  1722 		TPtr dataBufferPtr = dataBuffer->Des();
       
  1723 		
       
  1724 		// Skip two bytes and set the pointer to the next location
       
  1725 		// from where the actual data starts.
       
  1726 		dataBufferPtr.Set((TUint16*)binaryBufferPtr.Ptr()+1,
       
  1727 							fileSize/bytesPerChar-1, 
       
  1728 							fileSize/bytesPerChar-1);
       
  1729 			
       
  1730 		HBufC8* outputBuffer= NULL;
       
  1731 		outputBuffer=HBufC8::New(fileSize);
       
  1732 		if(!outputBuffer)
       
  1733 			{
       
  1734 			_LIT( KErrorMsg, "Failed to Load Svg Content: Out of memory");
       
  1735         	CSvgDocumentImpl::PrepareError( *iSvgError, ESvgNoMemory, KErrNoMemory,
       
  1736                                         KErrorMsg, KNullDesC );
       
  1737         	delete dataBuffer;
       
  1738         	delete binaryBuffer;
       
  1739         	return iSvgError;
       
  1740 			}
       
  1741 		TPtr8 outputBufferptr=outputBuffer->Des();
       
  1742 		CnvUtfConverter::ConvertFromUnicodeToUtf8(
       
  1743             							outputBufferptr,   // Destination
       
  1744             							dataBufferPtr );
       
  1745 		PrepareDom( *outputBuffer, aHandle, aEngine );		
       
  1746 		delete outputBuffer;
       
  1747 		delete dataBuffer;
       
  1748 		}
       
  1749 	else
       
  1750 		{
       
  1751 		PrepareDom( *binaryBuffer, aHandle, aEngine );
       
  1752 		}
       
  1753     
       
  1754     delete binaryBuffer;
       
  1755   	return iSvgError;
       
  1756 	}
       
  1757 
       
  1758 // --------------------------------------------------------------------------
       
  1759 // EXPORT_C MSvgError* CSvgEngineInterfaceImpl::PrepareDom(const TDesC8& aByteData, TInt& aHandle)
       
  1760 // ---------------------------------------------------------------------------
       
  1761 EXPORT_C MSvgError* CSvgEngineInterfaceImpl::PrepareDom(const TDesC8& aByteData, TInt& aHandle, TInt aEngine )
       
  1762     {
       
  1763     aHandle = 0;
       
  1764 
       
  1765     // Clear Error
       
  1766     iSvgError->SetErrorCode( ESvgNoError );
       
  1767 
       
  1768     if( !ChooseEngine(aEngine) )
       
  1769         {
       
  1770         _LIT(KEngineFailed, "SvgEngine Internal Failure: SvgEngineImpl not present.");
       
  1771         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, KErrNone,
       
  1772                                         KEngineFailed, KNullDesC );
       
  1773         return iSvgError;
       
  1774         }
       
  1775 
       
  1776     CSvgDocumentImpl* newDocument = NULL;
       
  1777     // Pass EFalse to document creation to indicate it has no parent
       
  1778     TRAPD( error, newDocument = CSvgDocumentImpl::NewL( iSvgBitmapFontProvider, EFalse ) ); 
       
  1779 
       
  1780     // Check for error
       
  1781     if(error != KErrNone)
       
  1782         {
       
  1783         _LIT(KEngineFailed, "Failed to Create Svg Document: Out of Memory");
       
  1784         #ifdef _DEBUG
       
  1785         RDebug::Print(KEngineFailed);
       
  1786         #endif //_DEBUG
       
  1787         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgNoMemory, error,
       
  1788                                         KEngineFailed, KNullDesC );
       
  1789         return iSvgError;
       
  1790         }
       
  1791 
       
  1792 	iSvgDocumentPointers.Append(newDocument);
       
  1793 
       
  1794     // Set appropriate flags to documents
       
  1795     newDocument->SetWasPrepared( !iIsLoadingRequest );
       
  1796     newDocument->SetDRMMode( iDrmEnabled );
       
  1797     newDocument->SetThumbNailMode( iIsThumbNailMode );
       
  1798     newDocument->SetDRMRights( iDrmRightsConsumptionEnabled);
       
  1799 
       
  1800     CSvgDocumentImpl* currentDocument = iSvgEngine->Document();
       
  1801 
       
  1802     // Hook engine to document
       
  1803     iSvgEngine->SetDocument( newDocument );
       
  1804     newDocument->SetEngine( iSvgEngine );
       
  1805     newDocument->SetLoadingListeners( &iSvgLoadingListeners );
       
  1806 
       
  1807     // Parse document
       
  1808     newDocument->Load( aByteData, *iSvgError );
       
  1809 
       
  1810     // Put back the document that was attached to document,
       
  1811     // since this is preparing the dom tree only
       
  1812     if ( !iIsLoadingRequest )
       
  1813         {
       
  1814         iSvgEngine->SetDocument( currentDocument );
       
  1815         }
       
  1816 
       
  1817     #ifdef _DEBUG
       
  1818     if ( newDocument->GetError() && newDocument->GetError()->HasError() )
       
  1819         {
       
  1820         RDebug::Printf("Load warning: ");
       
  1821         RDebug::RawPrint( newDocument->GetError()->Description() );
       
  1822         }
       
  1823     #endif
       
  1824 
       
  1825     iFileIsLoaded = !iSvgError->HasError() || iSvgError->IsWarning();
       
  1826 
       
  1827     // Parsing error or out of memory
       
  1828     if ( !iFileIsLoaded )
       
  1829         {
       
  1830         DestroyDocument(newDocument);
       
  1831         return iSvgError;
       
  1832         }
       
  1833 
       
  1834     aHandle = (TInt)newDocument;
       
  1835 
       
  1836     return iSvgError;
       
  1837     }
       
  1838 
       
  1839 // --------------------------------------------------------------------------
       
  1840 // EXPORT_C MSvgError* CSvgEngineInterfaceImpl::RenderDom(TInt aHandle, CFbsBitmap* aRenderBuffer)
       
  1841 // ---------------------------------------------------------------------------
       
  1842 EXPORT_C MSvgError* CSvgEngineInterfaceImpl::RenderDom(TInt aHandle, CFbsBitmap* aRenderBuffer, CFbsBitmap* aMaskBuffer)
       
  1843     {
       
  1844     UseDom( aHandle, aRenderBuffer, aMaskBuffer );
       
  1845 
       
  1846     if ( !iSvgError->HasError() || iSvgError->IsWarning() )
       
  1847     {
       
  1848         iSvgEngine->StartEngine();
       
  1849         iFileIsLoaded = ETrue;
       
  1850     }
       
  1851 
       
  1852     return iSvgError;
       
  1853     }
       
  1854 
       
  1855 // --------------------------------------------------------------------------
       
  1856 // EXPORT_C MSvgError* CSvgEngineInterfaceImpl::DeleteDom(TInt aHandle)
       
  1857 // ---------------------------------------------------------------------------
       
  1858 EXPORT_C MSvgError* CSvgEngineInterfaceImpl::DeleteDom(TInt aHandle)
       
  1859     {
       
  1860     // Clear Error
       
  1861     iSvgError->SetErrorCode( ESvgNoError );
       
  1862 
       
  1863     DestroyDocument((CSvgDocumentImpl*)aHandle);
       
  1864 
       
  1865     return iSvgError;
       
  1866     }
       
  1867 
       
  1868 
       
  1869 // --------------------------------------------------------------------------
       
  1870 // EXPORT_C void CSvgEngineInterfaceImpl::SetDRMMode(TBool aEnable)
       
  1871 // ---------------------------------------------------------------------------
       
  1872 EXPORT_C void CSvgEngineInterfaceImpl::SetDRMMode(TBool aEnable, TInt aEngine)
       
  1873     {
       
  1874     iDrmEnabled = aEnable;
       
  1875     if( ChooseEngine( aEngine )  && iSvgEngine->Document())
       
  1876         iSvgEngine->Document()->SetDRMMode(aEnable);
       
  1877     }
       
  1878 
       
  1879 //---------------------------------------------------------------------------
       
  1880 // EXPORT_C void CSvgEngineInterfaceImpl::SetDRMRights(TBool aEnable)
       
  1881 //---------------------------------------------------------------------------
       
  1882 EXPORT_C void CSvgEngineInterfaceImpl::SetDRMRights(TBool aEnable)
       
  1883     {
       
  1884 	iDrmRightsConsumptionEnabled = aEnable;
       
  1885 	if ( iSvgEngine && iSvgEngine->Document())
       
  1886 	    {
       
  1887 	    iSvgEngine->Document()->SetDRMRights(aEnable);
       
  1888 	    }
       
  1889 	    
       
  1890 	}
       
  1891 
       
  1892 // --------------------------------------------------------------------------
       
  1893 // EXPORT_C MSvgError* CSvgEngineInterfaceImpl::UseDom(TInt aHandle, CFbsBitmap* aRenderBuffer)
       
  1894 // ---------------------------------------------------------------------------
       
  1895 EXPORT_C MSvgError* CSvgEngineInterfaceImpl::UseDom(TInt aHandle, CFbsBitmap* aRenderBuffer, CFbsBitmap* aMask, TInt aEngine)
       
  1896     {
       
  1897     // Clear Error
       
  1898     iSvgError->SetErrorCode( ESvgNoError );
       
  1899 
       
  1900     // Check for engine: Should not occur
       
  1901     if( !ChooseEngine( aEngine ) )
       
  1902         {
       
  1903         _LIT(KEngineFailed, "SvgEngine Internal Failure: SvgEngineImpl not present.");
       
  1904         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, KErrNone,
       
  1905                                         KEngineFailed, KNullDesC );
       
  1906         return iSvgError;
       
  1907         }
       
  1908 
       
  1909     // Check for valid DOM
       
  1910     if( !IsDomCached( aHandle ) )
       
  1911         {
       
  1912         _LIT(KEngineFailed, "Invalid DOM, Use Prepare() to create DOM");
       
  1913         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, KErrNone,
       
  1914                                         KEngineFailed, KNullDesC );
       
  1915         return iSvgError;
       
  1916         }
       
  1917 
       
  1918     iTotalRotation = 0;
       
  1919 
       
  1920     iFileIsLoaded = EFalse;
       
  1921 
       
  1922     // Switch GDI context
       
  1923     TRAPD( gdiError, iSvgEngine->SetGdiContextL( aRenderBuffer, aMask ) );
       
  1924     if ( gdiError != KErrNone )
       
  1925         {
       
  1926         if ( gdiError == KErrNoMemory )
       
  1927             {
       
  1928             _LIT(KEngineGDIFailed, "SVG Engine Set Gdi Context Failed");
       
  1929             CSvgDocumentImpl::PrepareError( *iSvgError, ESvgNoMemory, KErrNoMemory,
       
  1930                                              KEngineGDIFailed, KNullDesC );
       
  1931             return iSvgError;
       
  1932             }
       
  1933         _LIT(KEngineGDIFailed, "SVG Engine Set Gdi Context Failed");
       
  1934             CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, KErrNone,
       
  1935                                              KEngineGDIFailed, KNullDesC );
       
  1936         return iSvgError;
       
  1937         }
       
  1938 
       
  1939     CSvgDocumentImpl* document = (CSvgDocumentImpl*)aHandle;
       
  1940 
       
  1941     CSvgDocumentImpl* lExistDoc = iSvgEngine->Document();
       
  1942 
       
  1943     if (lExistDoc != document)
       
  1944         {
       
  1945         //this is a new document so swap it out...
       
  1946         iSvgEngine->SetDocument( document );
       
  1947         document->SetEngine( iSvgEngine );
       
  1948         document->ReInitialize();
       
  1949         }
       
  1950 
       
  1951 	if (lExistDoc == iSvgLoadedDocument)
       
  1952 	{
       
  1953 		DestroyDocument(iSvgLoadedDocument);
       
  1954 		iSvgLoadedDocument = NULL;
       
  1955 	}
       
  1956 
       
  1957     // Check for thumbnail restrictions
       
  1958     if ( !iSvgEngine->PassesThumbNailRestriction() )
       
  1959         {
       
  1960         _LIT( KThumbNailRestriction, "Frame buffer is larger than allowable size for thumbnail mode." );
       
  1961         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgThumbNailRestriction, KErrNone,
       
  1962                                          KThumbNailRestriction, KNullDesC );
       
  1963         return iSvgError;
       
  1964         }
       
  1965 
       
  1966     iFileIsLoaded = ETrue;
       
  1967 
       
  1968     return iSvgError;
       
  1969     }
       
  1970 
       
  1971 // ---------------------------------------------------------------------------
       
  1972 // Is DOM cached
       
  1973 // ---------------------------------------------------------------------------
       
  1974 TBool CSvgEngineInterfaceImpl::IsDomCached(TInt aHandle)
       
  1975     {
       
  1976     return iSvgDocumentPointers.Find( (CSvgDocumentImpl*)aHandle ) != KErrNotFound;
       
  1977     }
       
  1978 
       
  1979 //---------------------------------------------------------------------------=
       
  1980 //Resize the view to the rendering buffer
       
  1981 //---------------------------------------------------------------------------=
       
  1982 EXPORT_C void CSvgEngineInterfaceImpl::SetSvgDimensionToFrameBuffer(TUint aWidth, TUint aHeight, TInt aEngine)
       
  1983 {
       
  1984 
       
  1985      if ( ChooseEngine(aEngine) )
       
  1986         {
       
  1987         TRAPD(error,iSvgEngine->SetSvgDimensionToFrameBufferL(aWidth, aHeight) );
       
  1988         if (error != KErrNone)
       
  1989             {
       
  1990             #ifdef _DEBUG
       
  1991             _LIT(KSetFrameBufferFailed,
       
  1992                 "CSvgEngineInterfaceImpl::SetSvgDimensionToFrameBuffer: SetSvgDimensionToFrameBufferL error.");
       
  1993             RDebug::Print(KSetFrameBufferFailed);
       
  1994             #endif //_DEBUG
       
  1995             }
       
  1996         }
       
  1997 
       
  1998 
       
  1999 }
       
  2000 
       
  2001 //---------------------------------------------------------------------------=
       
  2002 //Check if content is interactive
       
  2003 //---------------------------------------------------------------------------=
       
  2004 
       
  2005 EXPORT_C TBool CSvgEngineInterfaceImpl::IsContentInteractive(CSvgDocumentImpl* aDocument, TInt aEngine )
       
  2006 {
       
  2007     if ( ( aDocument == NULL ) || ( !ChooseEngine(aEngine) ) || ( aDocument->RootElement() == NULL ) )
       
  2008         return EFalse;
       
  2009 
       
  2010     return aDocument->IsDocumentContentInteractive();
       
  2011    /* RPointerArray<CSvgElementImpl> elements;
       
  2012     aDocument->FindAllElements( (CSvgElementImpl* )aDocument->RootElement(),
       
  2013                                  KSvgAElement, elements );
       
  2014     if ( elements.Count() != 0 )
       
  2015     {
       
  2016         elements.Close();
       
  2017         return ETrue;
       
  2018     }
       
  2019     elements.Close();
       
  2020 
       
  2021     if ( aDocument->iIsInteractive )
       
  2022         return ETrue;
       
  2023     else
       
  2024         return EFalse;*/
       
  2025 }
       
  2026 
       
  2027 //---------------------------------------------------------------------------=
       
  2028 //Copies a new path vector into the the given element's path
       
  2029 //---------------------------------------------------------------------------=
       
  2030 
       
  2031 EXPORT_C void CSvgEngineInterfaceImpl::UpdatePath(TInt hPath, CSvgElementImpl* hElement)
       
  2032 {
       
  2033     if ((hElement != NULL) && (hElement->ElemID() == KSvgPathElement))
       
  2034     {
       
  2035         TRAPD(error,hElement->SetAttributePathL(KAtrData, (CGfxGeneralPath*)hPath ));
       
  2036         if ( error != KErrNone )
       
  2037            {
       
  2038             // Error Processing
       
  2039             return;
       
  2040            }
       
  2041     }
       
  2042 }
       
  2043 
       
  2044 //---------------------------------------------------------------------------=
       
  2045 //Returns the number of external resources in an svg document (A elements,IMG elements)
       
  2046 //---------------------------------------------------------------------------=
       
  2047 
       
  2048 EXPORT_C TInt CSvgEngineInterfaceImpl::GetExternalListSize(CSvgDocumentImpl* aDocument)
       
  2049 {
       
  2050     if ( ( aDocument == NULL ) || ( aDocument->RootElement() == NULL ) )
       
  2051         return 0;
       
  2052 
       
  2053     TInt sum = 0;
       
  2054 
       
  2055     RPointerArray<CSvgElementImpl> a_elements;
       
  2056     RPointerArray<CSvgElementImpl> image_elements;
       
  2057 
       
  2058     aDocument->FindAllElements( (CSvgElementImpl* )aDocument->RootElement(),
       
  2059                                  KSvgAElement, a_elements );
       
  2060     if ( a_elements.Count() != 0 )
       
  2061     {
       
  2062         sum = sum + a_elements.Count();
       
  2063     }
       
  2064         a_elements.Close();
       
  2065 
       
  2066     aDocument->FindAllElements( (CSvgElementImpl* )aDocument->RootElement(),
       
  2067                                  KSvgImageElement, image_elements );
       
  2068     if ( image_elements.Count() != 0 )
       
  2069     {
       
  2070         sum = sum + image_elements.Count();
       
  2071     }
       
  2072         image_elements.Close();
       
  2073 
       
  2074     return sum;
       
  2075 
       
  2076 }
       
  2077 
       
  2078 //---------------------------------------------------------------------------=
       
  2079 //Returns the uri of an external resource in an svg document (A elements,IMG elements)
       
  2080 //---------------------------------------------------------------------------=
       
  2081 
       
  2082 EXPORT_C void CSvgEngineInterfaceImpl::GetExternalListItemL(
       
  2083 										CSvgDocumentImpl* aDocument, TInt aIndex, TPtrC16& aUri)
       
  2084 	{
       
  2085 	TDesC* uri = NULL;
       
  2086 	if ( ( aDocument != NULL ) && ( aDocument->RootElement() != NULL ) )
       
  2087 		{
       
  2088 		RPointerArray<CSvgElementImpl> a_elements;
       
  2089 		RPointerArray<CSvgElementImpl> image_elements;
       
  2090 		RPointerArray<CSvgElementImpl> all_externals;
       
  2091 		// Find & add all <a> elements
       
  2092 		aDocument->FindAllElements( (CSvgElementImpl* )aDocument->RootElement(),
       
  2093 								 KSvgAElement, a_elements );
       
  2094 		for (TInt i=0; i < a_elements.Count(); i++ )
       
  2095 			{
       
  2096 			all_externals.Append(a_elements[i]);
       
  2097 			}
       
  2098 		// Find & add all <image> elements
       
  2099 		aDocument->FindAllElements( (CSvgElementImpl* )aDocument->RootElement(),
       
  2100 								 KSvgImageElement, image_elements );
       
  2101 		for ( TInt i=0; i < image_elements.Count(); i++ )
       
  2102 			{
       
  2103 			all_externals.Append( image_elements[ i ] );
       
  2104 			}
       
  2105 		// Get element according to the given index
       
  2106 		if ( aIndex < all_externals.Count() )
       
  2107 			{
       
  2108 
       
  2109 			CSvgElementImpl* myElement = (CSvgElementImpl*)all_externals[ aIndex ];
       
  2110 			if ( myElement )
       
  2111 				{
       
  2112         		if ( (myElement->ElemID() ==
       
  2113 					KSvgImageElement) && ( ( ( CSvgImageElementImpl* ) myElement )->iIsBase64 ) )
       
  2114 					{
       
  2115 				   //do nothing because this is base64.
       
  2116 				   //want to return null for aValue
       
  2117 					}
       
  2118 				// Get an external resource uri
       
  2119 				else
       
  2120 					{
       
  2121             		uri = myElement->HrefPointer();
       
  2122             		// Check if the uri is already downloaded
       
  2123             		if( ( uri != NULL ) && ( uri->Length() >= 0 ) )
       
  2124 						{
       
  2125 						TDesC* duplicateUri = NULL;
       
  2126 						for ( int index = aIndex - 1; index >= 0; index-- )
       
  2127 							{
       
  2128 							myElement = (CSvgElementImpl*)all_externals[ index ];
       
  2129 							if (myElement)
       
  2130 								{
       
  2131 								duplicateUri = myElement->HrefPointer();
       
  2132 								if ( ( duplicateUri != NULL ) && ( *uri == *duplicateUri ) )
       
  2133 									{
       
  2134 									// External resource is already downloaded. Don't have
       
  2135 									// to equest it again
       
  2136 									return;
       
  2137 									}
       
  2138 								}
       
  2139 							}
       
  2140 						}
       
  2141 					}
       
  2142 				}
       
  2143 			}
       
  2144 		image_elements.Close();
       
  2145 		a_elements.Close();
       
  2146 		all_externals.Close();
       
  2147 		}
       
  2148 	if( uri != NULL )
       
  2149 		{
       
  2150 		// Allocate heap memory
       
  2151 		/*TInt length = uri->Length() + 1;
       
  2152 		TUint16* result = new ( ELeave ) TUint16[ length ];
       
  2153 		TPtr16 resultPtr( result, length );
       
  2154 		resultPtr.Copy( *uri );
       
  2155 		resultPtr.ZeroTerminate();
       
  2156 		return CONST_CAST( TUint16*, resultPtr.Ptr() );*/
       
  2157 
       
  2158 		aUri.Set(*uri);
       
  2159 
       
  2160 		}
       
  2161 	return;
       
  2162 	}
       
  2163 
       
  2164 
       
  2165 //---------------------------------------------------------------------------=
       
  2166 // Finds the element with the corresponding uri and then adds the data that was
       
  2167 // passed in by an external resource handler
       
  2168 //---------------------------------------------------------------------------=
       
  2169 // This code was copied from the CSvgEngineImpl
       
  2170 EXPORT_C CSvgElementImpl* CSvgEngineInterfaceImpl::AddExternalData(
       
  2171                                         CSvgDocumentImpl* aDocument,
       
  2172                                         const TDesC& aUri,
       
  2173                                         const TDesC8& aData,
       
  2174                                         TBool aMakeCopy,
       
  2175                                         TInt aSize,
       
  2176                                         TInt aEngine )
       
  2177     {
       
  2178     // Use the internal engine's document if parameter is NULL
       
  2179     if ( aDocument == NULL )
       
  2180         {
       
  2181         if ( ChooseEngine( aEngine) )
       
  2182             {
       
  2183             aDocument = iSvgEngine->Document();
       
  2184             }
       
  2185         }
       
  2186 
       
  2187     // Check whether document, root element are valid and URI is of 
       
  2188     // non-zero length
       
  2189     if ( ( aDocument == NULL ) || ( aDocument->RootElement() == NULL ) ||
       
  2190          ( aUri.Length() == 0 ) )
       
  2191         {
       
  2192         return NULL;
       
  2193         }
       
  2194 
       
  2195     // Find all <image> elements in current document
       
  2196     RPointerArray<CSvgElementImpl> lAllImageElements;
       
  2197     RPointerArray<CSvgElementImpl> lMatchingImageElements;
       
  2198     aDocument->FindAllElements( (CSvgElementImpl*)aDocument->RootElement(),
       
  2199                                 KSvgImageElement,
       
  2200                                 lAllImageElements,
       
  2201                                 ESvgSearchExcludeUseSubtree ); // Ignore the 
       
  2202                                                                // cloned image elements
       
  2203                                                                // under use element
       
  2204    
       
  2205     // Set Owner Document to default Doc
       
  2206     for ( TInt lIndex = 0; lIndex < lAllImageElements.Count(); lIndex++ )
       
  2207         {
       
  2208         lAllImageElements[ lIndex ]->SetOwnerDocument( aDocument );
       
  2209         } // for ( TInt lIndex = 0; ...
       
  2210 
       
  2211     // Search for Image elements inside child document as well
       
  2212     // First create a list of animation elements. 
       
  2213     RPointerArray<CSvgElementImpl> lAllAnimationElements;                                
       
  2214     aDocument->FindAllElements( ( CSvgElementImpl* )aDocument->RootElement(),
       
  2215                                 KSvgMediaAnimationElement,
       
  2216                                 lAllAnimationElements );                                
       
  2217     // Each animation element has a child document, append the list of image elements
       
  2218     // found in the child document to lAllImageElements
       
  2219     TInt lAllAnimationEleCnt = lAllAnimationElements.Count();                            
       
  2220     for ( TInt i = 0; i < lAllAnimationEleCnt; i++ )
       
  2221         {
       
  2222         CSvgMediaAnimationElementImpl* element = 
       
  2223             ( CSvgMediaAnimationElementImpl* )lAllAnimationElements[i];
       
  2224         CSvgDocumentImpl* ldoc = element->GetChildDocument();
       
  2225         if ( ldoc )
       
  2226             {
       
  2227             RPointerArray<CSvgElementImpl> lChildImageElements;
       
  2228             ldoc->FindAllElements( (CSvgElementImpl*)ldoc->RootElement(),
       
  2229                                 KSvgImageElement,
       
  2230                                 lChildImageElements,
       
  2231                                 ESvgSearchExcludeUseSubtree ); // Ignore the 
       
  2232                                                                // cloned image elements
       
  2233                                                                // under use element
       
  2234             // Set Owner Document to child Doc
       
  2235             for ( TInt lIndex = 0; lIndex < lChildImageElements.Count(); lIndex++ )
       
  2236                 {
       
  2237                 lChildImageElements[ lIndex ]->SetOwnerDocument( ldoc );
       
  2238                 // Also append the image elements into the image list
       
  2239                 lAllImageElements.Append( lChildImageElements[ lIndex ] );
       
  2240                 } // for ( TInt lIndex = 0; ...
       
  2241               lChildImageElements.Close();  
       
  2242             }
       
  2243         } // for ( TInt i = 0; i < lAllAnimationEleCnt; i++ )
       
  2244 
       
  2245     lAllAnimationElements.Close();
       
  2246     // lAllImageElements now contains image elements in parent as well as child documents
       
  2247     // Generate a list with only those image elements with same URI
       
  2248     TInt lAllImageEleCnt = lAllImageElements.Count();
       
  2249     for ( TInt i = 0; i < lAllImageEleCnt; i++ )
       
  2250         {
       
  2251         CSvgImageElementImpl* element = ( CSvgImageElementImpl* )
       
  2252             lAllImageElements[ i ];
       
  2253         TPtrC href = element->Href();
       
  2254         if ( href == aUri )
       
  2255             {
       
  2256             lMatchingImageElements.Append( element );
       
  2257             }
       
  2258         }
       
  2259     lAllImageElements.Close();
       
  2260 
       
  2261     // Return if no <image> element matching URI
       
  2262     if ( lMatchingImageElements.Count() == 0 )
       
  2263         {
       
  2264         lMatchingImageElements.Close();
       
  2265         return NULL;
       
  2266         }
       
  2267 
       
  2268     // Only first <image> element owns the imageData and all other image 
       
  2269     // elements refer to this data for decoding.
       
  2270     CSvgImageElementImpl* firstElement = ( CSvgImageElementImpl* )
       
  2271         lMatchingImageElements[0];
       
  2272 
       
  2273     // This loop decodes the imageData for every image element which has 
       
  2274     // the same URI. 
       
  2275     // Two image elements could have the same URI, yet they may have different sizes
       
  2276     // hence every image element decodes the same imageData.
       
  2277     TInt lImageEleCnt = lMatchingImageElements.Count();
       
  2278     for (TInt j=0; j < lImageEleCnt; j++)
       
  2279         {
       
  2280         CSvgImageElementImpl* lImageElement = ( CSvgImageElementImpl* )
       
  2281             lMatchingImageElements[j];
       
  2282 
       
  2283         // Create bitmap if needed
       
  2284         CFbsBitmap* bitmap = lImageElement->GetBitmap();
       
  2285         if ( bitmap == NULL )
       
  2286             {
       
  2287             // Can't use ELeave because that this function can't leave
       
  2288             bitmap = new CFbsBitmap();
       
  2289             // Check if bitmap was allocated
       
  2290             if ( !bitmap )
       
  2291                 {
       
  2292                 #ifdef _DBEUG
       
  2293                 RDebug::Printf("ERROR IN BITAMP CREATION: new (ELeave) CFbsBitmap(): %d", bitmapError);
       
  2294                 #endif
       
  2295                 // Return firstElement so that the image data is not deleted.
       
  2296                 // The data needs to be valid as this is happening inside a 
       
  2297                 // loop and previous image elements which have started decoding
       
  2298                 // this image data should not get affected.
       
  2299                 return firstElement;
       
  2300                 }
       
  2301  
       
  2302             // Create minimum bitmap size
       
  2303             TInt createError = bitmap->Create( TSize( 1, 1 ), EColor64K );
       
  2304             if ( createError != KErrNone )
       
  2305                 {
       
  2306                 #ifdef _DEBUG
       
  2307                 RDebug::Printf( "ERROR IN BITAMP CREATION: bitmap->Create: %d", createError );
       
  2308                 #endif
       
  2309                 delete bitmap;
       
  2310                 // Return firstElement so that the image data is not deleted.
       
  2311                 // The data needs to be valid as this is happening inside a 
       
  2312                 // loop and previous image elements which have started decoding
       
  2313                 // this image data should not get affected.
       
  2314                 return firstElement;
       
  2315                 }
       
  2316             // Transfer ownership of bitmap to image element    
       
  2317             lImageElement->SetBitmap( bitmap );
       
  2318             } // if ( !bitmap )
       
  2319 
       
  2320         if ( aMakeCopy )
       
  2321             {
       
  2322             // Make a copy of the image data and transfer ownership for this
       
  2323             // data to the particular image element
       
  2324             HBufC8* lImageDataCopy = NULL;
       
  2325             TRAPD( error, lImageDataCopy = HBufC8::NewL( aData.Length() ) );
       
  2326  
       
  2327             if ( error != KErrNone )
       
  2328                 {
       
  2329                 #ifdef _DEBUG
       
  2330                     RDebug::Printf( "Failed to copy Image: Out of memory" );
       
  2331                 #endif
       
  2332  
       
  2333                 return NULL;
       
  2334                 }
       
  2335             // copy the data into the image element 
       
  2336             lImageDataCopy->Des().Copy(aData);
       
  2337  
       
  2338             if (aData.Length() == 0 || aSize == 0)
       
  2339                 {
       
  2340                 // No data available, cleanup allocated memory
       
  2341                 delete lImageDataCopy;
       
  2342                 delete lImageElement->iBitmap;
       
  2343                 lImageElement->iBitmap = NULL;
       
  2344                 }
       
  2345             else
       
  2346                 {
       
  2347                 // Begin image decoding (asynchronously).
       
  2348                 TInt lImgDecErr = lImageElement->StartImageDecoding( 
       
  2349                         *lImageDataCopy, 
       
  2350                         ETrue ); // ETrue means Sync decoding
       
  2351                 if ( lImgDecErr != KErrNone )
       
  2352                     {
       
  2353                     // No error processing
       
  2354                     }
       
  2355                 lImageElement->AssignImageData( lImageDataCopy );
       
  2356                 }
       
  2357  
       
  2358             }
       
  2359         else // if ( aMakeCopy )
       
  2360             {
       
  2361             // Do not make a copy of the imageData.
       
  2362             // Begin image decoding (asynchronously).
       
  2363             // An asynchronous approach was chosen as AddExternalData is called
       
  2364             // to asynchronously notify the engine of availability of image 
       
  2365             // data.
       
  2366             // The underlying ImageDecoder is an asynchronous API and an 
       
  2367             // ActiveSchedulerWait object is used to make it synchronous. In 
       
  2368             // this case the client Active objects get a chance to execute. 
       
  2369             // While decoding is in progress, if the client exits it used to
       
  2370             // delete the engine and the document but async service provider is
       
  2371             // not yet complete. When the async service provider completes 
       
  2372             // it would cause the access violation error as it would 
       
  2373             // try to use image element object which has been deleted.
       
  2374             TInt lImgDecErr = lImageElement->StartImageDecoding( aData, 
       
  2375                     EFalse ); // EFalse means async decoding
       
  2376 
       
  2377             if ( lImgDecErr != KErrNone )
       
  2378                 {
       
  2379                 // No error processing
       
  2380                 }
       
  2381             } // if ( aMakeCopy )
       
  2382         } // for (TInt j=0; j < lImageEleCnt; j++)
       
  2383 
       
  2384     lMatchingImageElements.Close();
       
  2385 
       
  2386     return firstElement;
       
  2387     }
       
  2388 
       
  2389 // --------------------------------------------------------------------------
       
  2390 // EXPORT_C void CSvgEngineInterfaceImpl::AssignImageData( const TDesC& aUri,
       
  2391 // ---------------------------------------------------------------------------
       
  2392 EXPORT_C void CSvgEngineInterfaceImpl::AssignImageData( const TDesC& aUri,
       
  2393                                                         HBufC8* aData )
       
  2394     {
       
  2395     CSvgImageElementImpl* element =
       
  2396         (CSvgImageElementImpl*)AddExternalData( NULL, aUri, *aData, EFalse );
       
  2397     if ( element == NULL )
       
  2398         {
       
  2399         // delete image data now -- due to failure
       
  2400         delete aData;
       
  2401         }
       
  2402     else
       
  2403         {
       
  2404         // <image> element will delete it after decoding
       
  2405         element->AssignImageData( aData );
       
  2406         }
       
  2407     }
       
  2408 
       
  2409 /********************** Wrapper functions for new avoid new exports *******************/
       
  2410 // --------------------------------------------------------------------------
       
  2411 // EXPORT_C CSvgEngineImpl* CSvgEngineInterfaceImpl::SvgEngineNewL()
       
  2412 // ---------------------------------------------------------------------------
       
  2413 EXPORT_C CSvgEngineImpl* CSvgEngineInterfaceImpl::SvgEngineNewL()
       
  2414 {
       
  2415     //this is the JSR side creating the engine
       
  2416     iSvgEngine = CSvgEngineImpl::NewL(iSvgBitmapFontProvider);
       
  2417     iSvgEnginePointers.Append(iSvgEngine);
       
  2418     return iSvgEngine;
       
  2419 }
       
  2420 // --------------------------------------------------------------------------
       
  2421 // EXPORT_C void CSvgEngineInterfaceImpl::StartEngine( CSvgEngineImpl* aEngine )
       
  2422 // ---------------------------------------------------------------------------
       
  2423 EXPORT_C void CSvgEngineInterfaceImpl::StartEngine( CSvgEngineImpl* aEngine )
       
  2424 {
       
  2425     if( ChooseEngine ( (TInt)aEngine ) )
       
  2426         {
       
  2427         iSvgEngine->StartEngine();
       
  2428         }
       
  2429 }
       
  2430 // --------------------------------------------------------------------------
       
  2431 // EXPORT_C void CSvgEngineInterfaceImpl::RenderFrame( CSvgEngineImpl* aEngine, TUint aCurrentTime )
       
  2432 // ---------------------------------------------------------------------------
       
  2433 EXPORT_C void CSvgEngineInterfaceImpl::RenderFrame( CSvgEngineImpl* aEngine, TUint aCurrentTime )
       
  2434 {
       
  2435     if( ChooseEngine ( (TInt)aEngine ) )
       
  2436         {
       
  2437         iSvgEngine->RenderFrame( aCurrentTime );
       
  2438         }
       
  2439 }
       
  2440 // --------------------------------------------------------------------------
       
  2441 // EXPORT_C void CSvgEngineInterfaceImpl::ViewportInit( CSvgDocumentImpl* aDocumentHandle )
       
  2442 // ---------------------------------------------------------------------------
       
  2443 EXPORT_C void CSvgEngineInterfaceImpl::ViewportInit( CSvgDocumentImpl* aDocumentHandle )
       
  2444 {
       
  2445     if( !aDocumentHandle )
       
  2446         return;
       
  2447 
       
  2448     aDocumentHandle->iInitialDrawFlag = ETrue;
       
  2449 
       
  2450 
       
  2451     TSize Size = TSize(100, 100); // default viewport size
       
  2452     aDocumentHandle->iReqExReqFtrSysLTested = EFalse;
       
  2453     if ( aDocumentHandle->RootElement() != NULL &&
       
  2454          ((CSvgElementImpl*)aDocumentHandle->RootElement())->ElemID() == KSvgSvgElement )
       
  2455 
       
  2456         {
       
  2457         // Scale width & height to fit to screen size
       
  2458         CSvgSvgElementImpl*     el      = ( CSvgSvgElementImpl* )
       
  2459                                           (aDocumentHandle->RootElement());
       
  2460         TFloatFixPt                  width, height;
       
  2461         TFloatFixPt scrnW( Size.iWidth ), scrnH( Size.iHeight );
       
  2462         TFloatFixPt                  zero    ( 0 );
       
  2463         if (((CSvgSvgElementImpl *)(aDocumentHandle->RootElement()))->iWidthInPercentage)
       
  2464             {
       
  2465             // since we are mapping the percentage to a viewport that is 100x100 the percentage value can be used directly
       
  2466             width = ( TFloatFixPt ) (((CSvgSvgElementImpl *)(aDocumentHandle->RootElement()))->iWidthInUserCoordinate);
       
  2467             }
       
  2468         else
       
  2469             {
       
  2470             width  = (TFloatFixPt)  (((CSvgSvgElementImpl *)(aDocumentHandle->RootElement()))->iWidthInUserCoordinate);
       
  2471             }
       
  2472 
       
  2473         if (((CSvgSvgElementImpl *)(aDocumentHandle->RootElement()))->iHeightInPercentage)
       
  2474         {
       
  2475             height = ( TFloatFixPt ) (((CSvgSvgElementImpl *)(aDocumentHandle->RootElement()))->iHeightInUserCoordinate);
       
  2476         }
       
  2477         else
       
  2478         {
       
  2479             height = (TFloatFixPt)  (((CSvgSvgElementImpl *)(aDocumentHandle->RootElement()))->iHeightInUserCoordinate);
       
  2480         }
       
  2481         if ( ( width <= zero ) && ( height <= zero ) )
       
  2482             {
       
  2483             width = 0;
       
  2484             height = 0;
       
  2485             return;
       
  2486             }
       
  2487 
       
  2488         // Set initial viewport
       
  2489         TInt err;
       
  2490         TRAP(err, el->SetAttributeFloatL( KAtrX, zero ));
       
  2491         TRAP(err, el->SetAttributeFloatL( KAtrY, zero ));
       
  2492         TRAP(err, el->SetAttributeFloatL( KAtrWidth, width ));
       
  2493         TRAP(err, el->SetAttributeFloatL( KAtrHeight, height ));
       
  2494         }
       
  2495 }
       
  2496 
       
  2497 // --------------------------------------------------------------------------
       
  2498 // EXPORT_C void CSvgEngineInterfaceImpl::SetGdiContextL( CSvgEngineImpl* aEngine, CFbsBitmap* aFrameBuffer )
       
  2499 // ---------------------------------------------------------------------------
       
  2500 EXPORT_C void CSvgEngineInterfaceImpl::SetGdiContextL( CSvgEngineImpl* aEngine, CFbsBitmap* aFrameBuffer )
       
  2501 {
       
  2502     if( aEngine )
       
  2503         {
       
  2504         aEngine->SetGdiContextL( aFrameBuffer );
       
  2505         }
       
  2506 }
       
  2507 // --------------------------------------------------------------------------
       
  2508 // EXPORT_C void CSvgEngineInterfaceImpl::SetDocument( CSvgEngineImpl* aEngine, CSvgDocumentImpl* aDocument )
       
  2509 // ---------------------------------------------------------------------------
       
  2510 EXPORT_C void CSvgEngineInterfaceImpl::SetDocument( CSvgEngineImpl* aEngine, CSvgDocumentImpl* aDocument )
       
  2511 {
       
  2512     iTotalRotation = 0;
       
  2513     if( aEngine && aDocument)
       
  2514         {
       
  2515         aEngine->SetDocument( aDocument );
       
  2516         aDocument->SetEngine( aEngine );
       
  2517 
       
  2518         // costly calls per frame
       
  2519         SvgElementAssignDocument((CSvgElementImpl*)aDocument->RootElement(), aDocument);
       
  2520 
       
  2521         ((CSvgElementImpl*)aDocument->RootElement())->InitAllSvgStyleProperties((CSvgElementImpl*)aDocument->RootElement());
       
  2522 
       
  2523         }
       
  2524 }
       
  2525 
       
  2526 // --------------------------------------------------------------------------
       
  2527 // void CSvgEngineInterfaceImpl::SvgElementAssignDocument( CSvgElementImpl* aElement, CSvgDocumentImpl* aDoc )
       
  2528 // ---------------------------------------------------------------------------
       
  2529 void CSvgEngineInterfaceImpl::SvgElementAssignDocument( CSvgElementImpl* aElement, CSvgDocumentImpl* aDoc )
       
  2530 {
       
  2531     if ( aElement == NULL )
       
  2532         return;
       
  2533 
       
  2534     aElement->SetOwnerDocument( aDoc );
       
  2535 
       
  2536     CSvgElementImpl* child = (CSvgElementImpl*)aElement->FirstChild();
       
  2537     if ( child )
       
  2538         {
       
  2539         SvgElementAssignDocument( child, aDoc );
       
  2540         }
       
  2541 
       
  2542     CSvgElementImpl* sibling = (CSvgElementImpl*)aElement->NextSibling();
       
  2543     if ( sibling )
       
  2544         {
       
  2545         SvgElementAssignDocument( sibling, aDoc );
       
  2546         }
       
  2547 }
       
  2548 
       
  2549 
       
  2550 // --------------------------------------------------------------------------
       
  2551 // EXPORT_C CSvgDocumentImpl* CSvgEngineInterfaceImpl::SvgDocumentNewL()
       
  2552 // ---------------------------------------------------------------------------
       
  2553 EXPORT_C CSvgDocumentImpl* CSvgEngineInterfaceImpl::SvgDocumentNewL()
       
  2554 {
       
  2555 	CSvgDocumentImpl* document = CSvgDocumentImpl::NewL(iSvgBitmapFontProvider);
       
  2556 	iSvgDocumentPointers.Append(document);
       
  2557 
       
  2558     return document;
       
  2559 }
       
  2560 // --------------------------------------------------------------------------
       
  2561 // EXPORT_C void CSvgEngineInterfaceImpl::FillDocumentL( CSvgDocumentImpl* aDocument, const TDesC16& aSvgString )
       
  2562 // ---------------------------------------------------------------------------
       
  2563 EXPORT_C void CSvgEngineInterfaceImpl::FillDocumentL( CSvgDocumentImpl* aDocument, const TDesC16& aSvgString )
       
  2564 {
       
  2565     if( aDocument )
       
  2566         {
       
  2567         aDocument->SetDRMMode( iDrmEnabled );
       
  2568         SetThumbNailMode( iIsThumbNailMode );
       
  2569         SetDRMRights( iDrmRightsConsumptionEnabled );
       
  2570         aDocument->Load16BitString(aSvgString, *iSvgError, EFalse );
       
  2571         if ( aDocument->HasError() )
       
  2572             {
       
  2573             iSvgError->SetErrorCode( aDocument->GetError()->ErrorCode() );
       
  2574             iSvgError->SetSystemErrorCode( aDocument->GetError()->SystemErrorCode() );
       
  2575             iSvgError->SetDescription( aDocument->GetError()->Description() );
       
  2576             User::Leave( iSvgError->SystemErrorCode() );
       
  2577             }
       
  2578         }
       
  2579 }
       
  2580 // --------------------------------------------------------------------------
       
  2581 // EXPORT_C void CSvgEngineInterfaceImpl::DestroyDocument( CSvgDocumentImpl* aDocument )
       
  2582 // ---------------------------------------------------------------------------
       
  2583 EXPORT_C void CSvgEngineInterfaceImpl::DestroyDocument( CSvgDocumentImpl* aDocument )
       
  2584 {
       
  2585     if (aDocument )
       
  2586     {
       
  2587         TInt index = iSvgDocumentPointers.Find( aDocument );
       
  2588         if ( index != KErrNotFound )
       
  2589         	{
       
  2590         		//make sure document isnt attached to an engine
       
  2591         		TInt svgEnginePointersCnt = iSvgEnginePointers.Count();
       
  2592         		for (TInt i=0; i < svgEnginePointersCnt; i++)
       
  2593        			{
       
  2594        				CSvgEngineImpl* engine = iSvgEnginePointers[i];
       
  2595        				CSvgDocumentImpl* docAttachedToEngine = engine->Document();
       
  2596 
       
  2597        				if (docAttachedToEngine == aDocument)
       
  2598        				{
       
  2599        					//remove document attachment to engine
       
  2600        					engine->SetDocument(NULL);
       
  2601        				}
       
  2602        			}
       
  2603 
       
  2604         		delete aDocument;
       
  2605         		iSvgDocumentPointers.Remove( index );
       
  2606         	}
       
  2607     }
       
  2608 }
       
  2609 // --------------------------------------------------------------------------
       
  2610 // EXPORT_C void CSvgEngineInterfaceImpl::DestroyEngine( CSvgEngineImpl* aEngine )
       
  2611 // ---------------------------------------------------------------------------
       
  2612 EXPORT_C void CSvgEngineInterfaceImpl::DestroyEngine( CSvgEngineImpl* aEngine )
       
  2613 {
       
  2614     if (aEngine)
       
  2615     {
       
  2616     	TInt index = iSvgEnginePointers.Find( aEngine );
       
  2617         if ( index != KErrNotFound )
       
  2618         	{
       
  2619         		//make sure no document has this engine attached
       
  2620         		TInt svgDocPointersCnt = iSvgDocumentPointers.Count();
       
  2621         		for (TInt i=0; i < svgDocPointersCnt; i++)
       
  2622        			{
       
  2623        				CSvgDocumentImpl* document = iSvgDocumentPointers[i];
       
  2624        				CSvgEngineImpl* engineAttachedToDocument = document->Engine();
       
  2625 
       
  2626        				if (engineAttachedToDocument == aEngine)
       
  2627        				{
       
  2628        					//remove engine from document it is attached to
       
  2629        					document->SetEngine(NULL);
       
  2630        				}
       
  2631        			}
       
  2632 
       
  2633        			//make sure there is no handle to this left around
       
  2634        			if (iSvgEngine == aEngine)
       
  2635        			{
       
  2636        				iSvgEngine = NULL;
       
  2637        			}
       
  2638 
       
  2639         		delete aEngine;
       
  2640         		iSvgEnginePointers.Remove( index );
       
  2641         	}
       
  2642    	}
       
  2643 }
       
  2644 // --------------------------------------------------------------------------
       
  2645 // EXPORT_C CXmlElementImpl* CSvgEngineInterfaceImpl::GetRootElement( CSvgDocumentImpl* aDocument )
       
  2646 // ---------------------------------------------------------------------------
       
  2647 EXPORT_C CXmlElementImpl* CSvgEngineInterfaceImpl::GetRootElement( CSvgDocumentImpl* aDocument )
       
  2648 {
       
  2649     if( aDocument )
       
  2650         {
       
  2651         return (CXmlElementImpl*)aDocument->RootElement();
       
  2652         }
       
  2653     else
       
  2654         return NULL;
       
  2655 }
       
  2656 
       
  2657 // --------------------------------------------------------------------------
       
  2658 // EXPORT_C void CSvgEngineInterfaceImpl::InitRootElement( CSvgDocumentImpl* aDocument )
       
  2659 // ---------------------------------------------------------------------------
       
  2660 EXPORT_C void CSvgEngineInterfaceImpl::InitRootElement( CSvgDocumentImpl* aDocument )
       
  2661 {
       
  2662     if( aDocument )
       
  2663         {
       
  2664         TRAPD(error,aDocument->AppendChildL(CreateElementL(aDocument,KSvgSvgElement)));
       
  2665         if (error != KErrNone)
       
  2666             {
       
  2667             #ifdef _DEBUG
       
  2668             _LIT(KAppendChildFailed,
       
  2669                 "CSvgEngineInterfaceImpl::InitRootElement: AppendChildL error.");
       
  2670             RDebug::Print(KAppendChildFailed);
       
  2671             #endif //_DEBUG
       
  2672             }
       
  2673         }
       
  2674 }
       
  2675 // --------------------------------------------------------------------------
       
  2676 // EXPORT_C CXmlElementImpl* CSvgEngineInterfaceImpl::GetElementById( CSvgDocumentImpl* aDocument, const TDesC& aId )
       
  2677 // ---------------------------------------------------------------------------
       
  2678 EXPORT_C CXmlElementImpl* CSvgEngineInterfaceImpl::GetElementById( CSvgDocumentImpl* aDocument, const TDesC& aId )
       
  2679 {
       
  2680     if( aDocument )
       
  2681         {
       
  2682         return (CXmlElementImpl*)aDocument->GetElementById( aId );
       
  2683         }
       
  2684     else
       
  2685         return NULL;
       
  2686 }
       
  2687 
       
  2688 // --------------------------------------------------------------------------
       
  2689 // EXPORT_C TInt CSvgEngineInterfaceImpl::GetNumberOfIds( CSvgDocumentImpl* aDocument )
       
  2690 // ---------------------------------------------------------------------------
       
  2691 EXPORT_C TInt CSvgEngineInterfaceImpl::GetNumberOfIds( CSvgDocumentImpl* aDocument )
       
  2692 {
       
  2693     if ( aDocument )
       
  2694         return (aDocument->GetNumberOfIds( aDocument->RootElement()));
       
  2695     else
       
  2696         return 0;
       
  2697 }
       
  2698 
       
  2699 // --------------------------------------------------------------------------
       
  2700 // EXPORT_C TDesC* CSvgEngineInterfaceImpl::GetId(CSvgDocumentImpl* aDocument, TInt index)
       
  2701 // ---------------------------------------------------------------------------
       
  2702 EXPORT_C TDesC* CSvgEngineInterfaceImpl::GetId(CSvgDocumentImpl* aDocument, TInt index)
       
  2703 {
       
  2704     if ( aDocument )
       
  2705         return (aDocument->GetId(index));
       
  2706     else
       
  2707         return NULL;
       
  2708 }
       
  2709 
       
  2710 // --------------------------------------------------------------------------
       
  2711 // EXPORT_C CXmlElementImpl* CSvgEngineInterfaceImpl::GetParentElement( CXmlElementImpl* aElement )
       
  2712 // ---------------------------------------------------------------------------
       
  2713 EXPORT_C CXmlElementImpl* CSvgEngineInterfaceImpl::GetParentElement( CXmlElementImpl* aElement )
       
  2714 {
       
  2715     if( aElement )
       
  2716         return (CXmlElementImpl*)aElement->ParentNode();
       
  2717     else
       
  2718         return NULL;
       
  2719 }
       
  2720 // --------------------------------------------------------------------------
       
  2721 // EXPORT_C void CSvgEngineInterfaceImpl::SetParentElement( CXmlElementImpl* aElement, CXmlElementImpl* aParentElement )
       
  2722 // ---------------------------------------------------------------------------
       
  2723 EXPORT_C void CSvgEngineInterfaceImpl::SetParentElement( CXmlElementImpl* aElement, CXmlElementImpl* aParentElement )
       
  2724 {
       
  2725     if( aElement )
       
  2726         aElement->SetParentNode( aParentElement );
       
  2727 }
       
  2728 
       
  2729 // --------------------------------------------------------------------------
       
  2730 // EXPORT_C void CSvgEngineInterfaceImpl::SetFirstChildElement( CXmlElementImpl* aElement, CXmlElementImpl* aParentElement )
       
  2731 // ---------------------------------------------------------------------------
       
  2732 EXPORT_C void CSvgEngineInterfaceImpl::SetFirstChildElement( CXmlElementImpl* aFirstChildElement, CXmlElementImpl* aParentElement )
       
  2733 {
       
  2734     if( aFirstChildElement && aParentElement )
       
  2735         aParentElement->SetFirstChild( aFirstChildElement );
       
  2736 }
       
  2737 
       
  2738 // --------------------------------------------------------------------------
       
  2739 // EXPORT_C CXmlElementImpl* CSvgEngineInterfaceImpl::CreateElementL( CSvgDocumentImpl* aDocument, TInt aElementType )
       
  2740 // ---------------------------------------------------------------------------
       
  2741 EXPORT_C CXmlElementImpl* CSvgEngineInterfaceImpl::CreateElementL( CSvgDocumentImpl* aDocument, TInt aElementType )
       
  2742 {
       
  2743     if( aDocument )
       
  2744         return (CXmlElementImpl*)aDocument->CreateElementL( (TUint8)aElementType );
       
  2745     else
       
  2746         return NULL;
       
  2747 }
       
  2748 // --------------------------------------------------------------------------
       
  2749 // EXPORT_C void CSvgEngineInterfaceImpl::DestroyElement( CXmlElementImpl* aElement )
       
  2750 // ---------------------------------------------------------------------------
       
  2751 EXPORT_C void CSvgEngineInterfaceImpl::DestroyElement( CXmlElementImpl* aElement )
       
  2752 {
       
  2753     delete aElement;
       
  2754 }
       
  2755 // --------------------------------------------------------------------------
       
  2756 // EXPORT_C void CSvgEngineInterfaceImpl::AppendChild( CXmlElementImpl* aParentElement, CXmlElementImpl* aChildElement, TBool aIsJSR226Element)
       
  2757 // ---------------------------------------------------------------------------
       
  2758 EXPORT_C void CSvgEngineInterfaceImpl::AppendChild( CXmlElementImpl* aParentElement, CXmlElementImpl* aChildElement, TBool aIsJSR226Element)
       
  2759 {
       
  2760     // Note: AppendChildL does not have any leaveble calls
       
  2761     if( aParentElement && aChildElement )
       
  2762         {
       
  2763 
       
  2764         MXmlElement* childExisted = NULL;
       
  2765         // Avoid appending child to parent twice
       
  2766         if ( aChildElement->ParentNode() == aParentElement )
       
  2767             {
       
  2768             //mark the first copy of the element that is already
       
  2769             //appended as a child that to be removed
       
  2770             MXmlElement* child = aParentElement->FirstChild();
       
  2771             if ( child == aChildElement )
       
  2772                 {
       
  2773                 childExisted = child;
       
  2774                 }
       
  2775             while ( child && !childExisted )
       
  2776                 {
       
  2777                 child = child->NextSibling();
       
  2778                 if ( child == aChildElement )
       
  2779                     {
       
  2780                     	//mark the first copy of the element that is already
       
  2781                     	//appended as a child that to be removed
       
  2782                     	childExisted = child;
       
  2783                     	break;
       
  2784                     }
       
  2785                 }
       
  2786             }
       
  2787 
       
  2788 				if ( childExisted )
       
  2789 				{
       
  2790 					aParentElement->RemoveChild( childExisted );
       
  2791 				}
       
  2792 
       
  2793         TRAPD( error, aParentElement->AppendChildL( aChildElement, aIsJSR226Element ) );
       
  2794         if (error != KErrNone)
       
  2795             {
       
  2796             #ifdef _DEBUG
       
  2797             _LIT(KAppendChildFailed,
       
  2798                 "CSvgEngineInterfaceImpl::AppendChild: AppendChildL error.");
       
  2799             RDebug::Print(KAppendChildFailed);
       
  2800             #endif //_DEBUG
       
  2801             }
       
  2802 
       
  2803         if ( aChildElement->ElemID() == KSvgUseElement)
       
  2804         {
       
  2805         	//we need to set the forward references up now
       
  2806         	((CSvgUseElementImpl*)aChildElement)->SetRefElemById( ((CSvgUseElementImpl*)aChildElement)->Href() );
       
  2807 
       
  2808         	TRAP_IGNORE( ((CSvgUseElementImpl *)aChildElement)->SetReferenceElementL() );
       
  2809         }
       
  2810         
       
  2811         
       
  2812         // If aChildElement is a Stop element then add it to Gradient's stop element array.
       
  2813         TInt lParentId =  ((CXmlElementImpl*)aParentElement)->ElemID();
       
  2814         TInt lChildId  =  ((CXmlElementImpl*)aChildElement)->ElemID();
       
  2815             
       
  2816         if(  ( ( ( lParentId == KSvgRadialGradientElement )||
       
  2817                  ( lParentId == KSvgLinearGradientElement ) ) &&
       
  2818                  ( lChildId == KSvgStopElement ) ) )
       
  2819 
       
  2820 	        {
       
  2821 		    // Initialize the offset value to 0 if its still -1.
       
  2822 	        TFloatFixPt lOffsetValue;
       
  2823 	        TFloatFixPt lDefaultOffsetValue(-1);
       
  2824 	        TBuf<6>     lAttributeName;
       
  2825 	        TBuf<1>     lValueBuffer;
       
  2826 	                      
       
  2827 	        lAttributeName.Append(OFFSET);
       
  2828 	        lValueBuffer.Append(ZEROVALUE);
       
  2829 	            
       
  2830 	        ((CSvgStopElementImpl*)aChildElement)->GetOffset( lOffsetValue );
       
  2831 	         
       
  2832 	        // Offset Value of -1 indicates that Offset Attribute is not declared in
       
  2833 	        // stop element.      
       
  2834 	        if( lOffsetValue == lDefaultOffsetValue )
       
  2835 	           {  
       
  2836 	           // Deliberately calling SetAttributeL in place of SetAttributeFloatL as the latter inturn
       
  2837 	           // calls UpdateOffsetValues which should be called on any Stop element once it is added to
       
  2838 	           // to the Stop element array Owned by parent Gradient element.
       
  2839 	           TRAP_IGNORE(((CSvgStopElementImpl*)aChildElement)->SetAttributeL( lAttributeName, lValueBuffer ));
       
  2840 	           }
       
  2841 	                
       
  2842 	         // The function not only adds the element in Stop element array but also
       
  2843 	         // Adjusts the offset values of all the previously added elements such that
       
  2844 	         // each gradient offset value is greater than the previous gradient stop's
       
  2845 	         // offset value.It calls UpdateOffsetValues to adjust the values.
       
  2846 	         ((CSvgGradientElementImpl*)aParentElement)->AddStopElementInArray((CSvgStopElementImpl*)aChildElement);
       
  2847 	                                  
       
  2848 	         }                          
       
  2849 
       
  2850         //CTM needs to be updated after appending child so it gets propogated to new children
       
  2851         ((CSvgElementImpl*)aParentElement)->UpdateCTM();
       
  2852 
       
  2853         }
       
  2854 }
       
  2855 // --------------------------------------------------------------------------
       
  2856 // EXPORT_C void CSvgEngineInterfaceImpl::RemoveChild( CXmlElementImpl* aParentElement, CXmlElementImpl* aChildElement)
       
  2857 // ---------------------------------------------------------------------------
       
  2858 EXPORT_C void CSvgEngineInterfaceImpl::RemoveChild( CXmlElementImpl* aParentElement, CXmlElementImpl* aChildElement)
       
  2859 {
       
  2860     if( aParentElement && aChildElement )
       
  2861         {
       
  2862         aParentElement->RemoveChild( aChildElement );
       
  2863         
       
  2864         if( ((CXmlElementImpl*)aChildElement)->ElemID() == KSvgTextElement )
       
  2865         	{
       
  2866         	((CSvgTextElementImpl*)aChildElement)->FreeFontData();
       
  2867         	}
       
  2868         
       
  2869         }
       
  2870 }
       
  2871 // --------------------------------------------------------------------------
       
  2872 // EXPORT_C CXmlElementImpl* CSvgEngineInterfaceImpl::GetFirstChild( CXmlElementImpl* aParentElement )
       
  2873 // ---------------------------------------------------------------------------
       
  2874 EXPORT_C CXmlElementImpl* CSvgEngineInterfaceImpl::GetFirstChild( CXmlElementImpl* aParentElement )
       
  2875 {
       
  2876     if( aParentElement )
       
  2877         return (CXmlElementImpl*)aParentElement->FirstChild();
       
  2878     else
       
  2879         return NULL;
       
  2880 }
       
  2881 // --------------------------------------------------------------------------
       
  2882 // EXPORT_C CXmlElementImpl* CSvgEngineInterfaceImpl::GetNextSibling( CXmlElementImpl* aElement )
       
  2883 // ---------------------------------------------------------------------------
       
  2884 EXPORT_C CXmlElementImpl* CSvgEngineInterfaceImpl::GetNextSibling( CXmlElementImpl* aElement )
       
  2885 {
       
  2886     if( aElement )
       
  2887         return (CXmlElementImpl*)aElement->NextSibling();
       
  2888     else
       
  2889         return NULL;
       
  2890 }
       
  2891 // --------------------------------------------------------------------------
       
  2892 // EXPORT_C void CSvgEngineInterfaceImpl::SetNextSibling( CXmlElementImpl* aElement, CXmlElementImpl* aSibling )
       
  2893 // ---------------------------------------------------------------------------
       
  2894 EXPORT_C void CSvgEngineInterfaceImpl::SetNextSibling( CXmlElementImpl* aElement, CXmlElementImpl* aSibling )
       
  2895 {
       
  2896     if( aElement && aSibling )
       
  2897         aElement->SetNextSibling( aSibling );
       
  2898 }
       
  2899 
       
  2900 // --------------------------------------------------------------------------
       
  2901 // EXPORT_C CSvgDocumentImpl* CSvgEngineInterfaceImpl::GetOwnerDocument( CXmlElementImpl* aElement )
       
  2902 // ---------------------------------------------------------------------------
       
  2903 EXPORT_C CSvgDocumentImpl* CSvgEngineInterfaceImpl::GetOwnerDocument( CXmlElementImpl* aElement )
       
  2904 {
       
  2905     if( aElement)
       
  2906         return (CSvgDocumentImpl*)aElement->OwnerDocument();
       
  2907     else
       
  2908         return NULL;
       
  2909 }
       
  2910 // --------------------------------------------------------------------------
       
  2911 // EXPORT_C TInt CSvgEngineInterfaceImpl::GetElementType( CXmlElementImpl* aElement )
       
  2912 // ---------------------------------------------------------------------------
       
  2913 EXPORT_C TInt CSvgEngineInterfaceImpl::GetElementType( CXmlElementImpl* aElement )
       
  2914 {
       
  2915     if( aElement )
       
  2916         return aElement->ElemID();
       
  2917     else
       
  2918         return -1;
       
  2919 }
       
  2920 
       
  2921 // --------------------------------------------------------------------------
       
  2922 // EXPORT_C void CSvgEngineInterfaceImpl::SetRequestObserver( CSvgEngineImpl* aEngine, MSvgRequestObserver* aObserver )
       
  2923 // ---------------------------------------------------------------------------
       
  2924 EXPORT_C void CSvgEngineInterfaceImpl::SetRequestObserver( CSvgEngineImpl* aEngine, MSvgRequestObserver* aObserver )
       
  2925 {
       
  2926     if( aEngine )
       
  2927         aEngine->iRequestObserver = aObserver;
       
  2928 }
       
  2929 // --------------------------------------------------------------------------
       
  2930 // EXPORT_C TInt  CSvgEngineInterfaceImpl::GetElementDesAttribute(CSvgElementImpl* aElementHandle,const TInt aAttributeId,TDes& aValue)
       
  2931 // ---------------------------------------------------------------------------
       
  2932 EXPORT_C TInt  CSvgEngineInterfaceImpl::GetElementDesAttribute(CSvgElementImpl* aElementHandle,const TInt aAttributeId, TPtrC16& aValue)
       
  2933 {
       
  2934     return aElementHandle->GetAttributeDes(aAttributeId, aValue);
       
  2935 }
       
  2936 // --------------------------------------------------------------------------
       
  2937 // EXPORT_C TReal32 CSvgEngineInterfaceImpl::GetElementFloatAttribute( CSvgElementImpl* aElementHandle, const TInt aAttributeId)
       
  2938 // ---------------------------------------------------------------------------
       
  2939 EXPORT_C TReal32 CSvgEngineInterfaceImpl::GetElementFloatAttribute( CSvgElementImpl* aElementHandle, const TInt aAttributeId) __SOFTFP
       
  2940 {
       
  2941 
       
  2942     TFloatFixPt lValue ;
       
  2943 
       
  2944     //hack for JSR 226 so it can return the original base value when the attribute is animated
       
  2945     //instead of returning the animated value in the element class
       
  2946     if ( aElementHandle->HasAnimation() )
       
  2947     {
       
  2948     	TInt lResult = ((CSvgAnimationBase*)aElementHandle->iHasAnimationBase)->GetAttributeFloat( aAttributeId, lValue);
       
  2949 
       
  2950     	if(lResult != KErrNoAttribute)
       
  2951         {
       
  2952  			return lValue;
       
  2953         }
       
  2954     }
       
  2955 
       
  2956     TInt lResult = aElementHandle->GetAttributeFloat( aAttributeId, lValue);
       
  2957     if(lResult == KErrNoAttribute)
       
  2958         {
       
  2959         return KInvalidFloatAttribute;
       
  2960         }
       
  2961     return lValue;
       
  2962 }
       
  2963 // --------------------------------------------------------------------------
       
  2964 // EXPORT_C void CSvgEngineInterfaceImpl::SetElementFloatAttribute( CSvgElementImpl* aElementHandle, const TInt aAttributeId, TReal32 aValue)
       
  2965 // ---------------------------------------------------------------------------
       
  2966 EXPORT_C void CSvgEngineInterfaceImpl::SetElementFloatAttribute( CSvgElementImpl* aElementHandle, const TInt aAttributeId, TReal32 aValue) __SOFTFP
       
  2967 {
       
  2968     TFloatFixPt lValue = TFloatFixPt(aValue);
       
  2969     TRAPD(error,aElementHandle->SetAttributeFloatL(aAttributeId,lValue));
       
  2970     if (error != KErrNone)
       
  2971         {
       
  2972         #ifdef _DEBUG
       
  2973         _LIT(KSetAttributeFloatFailed,
       
  2974             "CSvgEngineInterfaceImpl::SetElementFloatAttribute: SetElementFloatAttribute error.");
       
  2975         RDebug::Print(KSetAttributeFloatFailed);
       
  2976         #endif //_DEBUG
       
  2977         }
       
  2978 
       
  2979    //hack for JSR 226 so it can return the original base value when the attribute is animated
       
  2980     //instead of returning the animated value in the element class
       
  2981     if ( aElementHandle->HasAnimation() )
       
  2982     {
       
  2983     	TRAP_IGNORE( ((CSvgAnimationBase*)aElementHandle->iHasAnimationBase)->SetAttributeFloatL( aAttributeId, lValue) );
       
  2984     }
       
  2985 
       
  2986 }
       
  2987 // --------------------------------------------------------------------------
       
  2988 // EXPORT_C void CSvgEngineInterfaceImpl::SetElementDesAttribute(CSvgElementImpl* aElementHandle,const TInt aAttributeId, TDesC& lAttributeValue)
       
  2989 // ---------------------------------------------------------------------------
       
  2990 EXPORT_C void CSvgEngineInterfaceImpl::SetElementDesAttribute(CSvgElementImpl* aElementHandle,const TInt aAttributeId, const TDesC& lAttributeValue)
       
  2991 {
       
  2992     
       
  2993     const TDesC* ReferenceElementID = NULL;
       
  2994     
       
  2995     // Incase if the xlink-href attribute is set for USE element from JSR226 we need to 
       
  2996     // create a clone tree under the USE element explicitly same as done in Content handler.
       
  2997     if( aElementHandle->ElemID() == KSvgUseElement && aAttributeId == KAtrXlinkhref )
       
  2998     {
       
  2999         // Check if the USE element is already refereing to some element. If 'YES' we need to 
       
  3000         // remove the previously refered element.
       
  3001         CSvgElementImpl* lReferenceElement = ((CSvgUseElementImpl*)aElementHandle)->GetReferenceElementL();
       
  3002         
       
  3003         if( lReferenceElement != NULL)
       
  3004         {
       
  3005         	// Get the ID of this element.
       
  3006         	ReferenceElementID = lReferenceElement->Id();
       
  3007                     	
       
  3008         	// Get the first child of USE element and compare its ID with previously
       
  3009         	// refered element's ID. If they are same remove the referenced element branch
       
  3010         	// from the USE element. Else, continue finding some element under 'USE' element
       
  3011         	// that has same ID as the previously refered element has.
       
  3012         	CSvgElementImpl* ChildOfUseElement = (CSvgElementImpl*)aElementHandle->FirstChild();
       
  3013         	
       
  3014         	while( ChildOfUseElement && ReferenceElementID )
       
  3015         	{
       
  3016         	    const TDesC16* UseElementChildID = ChildOfUseElement->Id();
       
  3017         	    
       
  3018         	    // Compare the Child ID with reference element's ID
       
  3019 				if( UseElementChildID && ( ReferenceElementID->Compare(*UseElementChildID) == 0 ))
       
  3020 				{
       
  3021 					// delete the same child and get out of the loop.
       
  3022 					aElementHandle->RemoveChild(ChildOfUseElement);
       
  3023 					break;
       
  3024 				}
       
  3025 				
       
  3026 				ChildOfUseElement = (CSvgUseElementImpl*)ChildOfUseElement->NextSibling();
       
  3027         	}
       
  3028         }
       
  3029     }
       
  3030         
       
  3031     TRAPD(error,aElementHandle->SetAttributeDesL(aAttributeId,lAttributeValue));
       
  3032     
       
  3033     if (error != KErrNone)
       
  3034         {
       
  3035         #ifdef _DEBUG
       
  3036         _LIT(KSetAttributeDesFailed,
       
  3037             "CSvgEngineInterfaceImpl::SetElementDesAttribute: SetAttributeDesL error.");
       
  3038         RDebug::Print(KSetAttributeDesFailed);
       
  3039         #endif //_DEBUG
       
  3040         }
       
  3041     
       
  3042     if( ( aElementHandle->ElemID() == KSvgUseElement ) && aAttributeId == KAtrXlinkhref )
       
  3043     {
       
  3044     	// Create a new branch under the USE element
       
  3045     	TRAP(error,((CSvgUseElementImpl *)aElementHandle)->SetReferenceElementL());
       
  3046     	
       
  3047     	if (error != KErrNone)
       
  3048         {
       
  3049         #ifdef _DEBUG
       
  3050         _LIT(KSetReferenceElementLFailed,
       
  3051             "CSvgUseElementImpl::SetReferenceElementL: SetReferenceElementL error.");
       
  3052         RDebug::Print(KSetReferenceElementLFailed);
       
  3053         #endif //_DEBUG
       
  3054         }
       
  3055     }
       
  3056 }
       
  3057 // --------------------------------------------------------------------------
       
  3058 // EXPORT_C void CSvgEngineInterfaceImpl:: GetElementBoundingbox(CSvgElementImpl* aElementHandle,TReal32& aX ,TReal32& aY,TReal32& aWidth,TReal32& aHeight)
       
  3059 // this is used for ScreenBbox (actual bbox of an element on the screen)
       
  3060 // ---------------------------------------------------------------------------
       
  3061 EXPORT_C void CSvgEngineInterfaceImpl:: GetElementBoundingbox(CSvgElementImpl* aElementHandle,TReal32& aX ,TReal32& aY,TReal32& aWidth,TReal32& aHeight) __SOFTFP
       
  3062 {
       
  3063     if (aElementHandle)
       
  3064     {
       
  3065     	//updates CTM from root
       
  3066         aElementHandle->UpdateCTM();
       
  3067 
       
  3068         TGfxRectangle2D     bbox;
       
  3069         aElementHandle->GetBBox(bbox);
       
  3070         aX = (TReal32)bbox.iX;
       
  3071         aY = (TReal32)bbox.iY;
       
  3072         aWidth = (TReal32)bbox.iWidth;
       
  3073         aHeight = (TReal32)bbox.iHeight;
       
  3074     }
       
  3075 }
       
  3076 
       
  3077 // --------------------------------------------------------------------------
       
  3078 // EXPORT_C void CSvgEngineInterfaceImpl:: GetElementUnScaledBoundingBox(CSvgElementImpl* aElementHandle,TReal32& aX ,TReal32& aY,TReal32& aWidth,TReal32& aHeight)
       
  3079 // this is used for UserBBox (unscaled bbox)
       
  3080 // ---------------------------------------------------------------------------
       
  3081 EXPORT_C void CSvgEngineInterfaceImpl::GetElementUnScaledBoundingBox( CSvgElementImpl* aElementHandle,TReal32& aX ,TReal32& aY,TReal32& aWidth,TReal32& aHeight) __SOFTFP
       
  3082 {
       
  3083 		if (aElementHandle)
       
  3084     {
       
  3085 		//updates CTM from root
       
  3086         aElementHandle->UpdateCTM();
       
  3087 
       
  3088         TGfxRectangle2D     bbox;
       
  3089         aElementHandle->GetUnscaledBBox(bbox);
       
  3090         aX = (TReal32)bbox.iX;
       
  3091         aY = (TReal32)bbox.iY;
       
  3092         aWidth = (TReal32)bbox.iWidth;
       
  3093         aHeight = (TReal32)bbox.iHeight;
       
  3094     }
       
  3095 }
       
  3096 
       
  3097 // --------------------------------------------------------------------------
       
  3098 // EXPORT_C void CSvgEngineInterfaceImpl::GetFourPointElementBoundingBox(CSvgTextElementImpl* aTextElementHandle, TPoint& aPoint1, TPoint& aPoint2, TPoint& aPoint3, TPoint& aPoint4)
       
  3099 // ---------------------------------------------------------------------------
       
  3100 EXPORT_C void CSvgEngineInterfaceImpl::GetFourPointElementBoundingBox(CSvgTextElementImpl* aTextElementHandle, TPoint& aPoint1, TPoint& aPoint2, TPoint& aPoint3, TPoint& aPoint4)
       
  3101 {
       
  3102     TSvgFourPointRect fourPointRect;
       
  3103 
       
  3104 	//updates CTM from root
       
  3105 	aTextElementHandle->UpdateCTM();
       
  3106 
       
  3107     if (aTextElementHandle)
       
  3108     {
       
  3109         aTextElementHandle->GetFourPointBBox(fourPointRect);
       
  3110     }
       
  3111 
       
  3112     fourPointRect.GetPoints(aPoint1, aPoint2, aPoint3, aPoint4);
       
  3113 }
       
  3114 
       
  3115 // --------------------------------------------------------------------------
       
  3116 // EXPORT_C void CSvgEngineInterfaceImpl:: SetElementColorAttribute(CSvgElementImpl* aElementHandle,const TInt aAttributeId,TInt32 lColorValue)
       
  3117 // ---------------------------------------------------------------------------
       
  3118 EXPORT_C void CSvgEngineInterfaceImpl:: SetElementColorAttribute(CSvgElementImpl* aElementHandle,const TInt aAttributeId,TInt32 lColorValue)
       
  3119 {
       
  3120     TRAPD(error, aElementHandle->SetAttributeIntL(aAttributeId,lColorValue));
       
  3121     if (error != KErrNone)
       
  3122         {
       
  3123         #ifdef _DEBUG
       
  3124         _LIT(KSetAttributeIntFailed,
       
  3125             "CSvgEngineInterfaceImpl::SetElementColorAttribute: SetAttributeIntL( error.");
       
  3126         RDebug::Print(KSetAttributeIntFailed);
       
  3127         #endif //_DEBUG
       
  3128         }
       
  3129 
       
  3130 }
       
  3131 // --------------------------------------------------------------------------
       
  3132 // EXPORT_C TInt32 CSvgEngineInterfaceImpl::GetElementColorAttribute(CSvgElementImpl* aElementHandle,const TInt aAttributeId)
       
  3133 // ---------------------------------------------------------------------------
       
  3134 EXPORT_C TInt32 CSvgEngineInterfaceImpl::GetElementColorAttribute(CSvgElementImpl* aElementHandle,const TInt aAttributeId)
       
  3135 {
       
  3136     TInt lResult = KErrNone;
       
  3137     TInt32 lValue = KErrNone;
       
  3138     TRAPD(error,lResult = aElementHandle->GetAttributeIntL( aAttributeId, lValue));
       
  3139     if (error != KErrNone)
       
  3140         {
       
  3141         #ifdef _DEBUG
       
  3142         _LIT(KGetAttributeIntFailed,
       
  3143             "CSvgEngineInterfaceImpl::GetElementColorAttribute: GetElementColorAttribute( error.");
       
  3144         RDebug::Print(KGetAttributeIntFailed);
       
  3145         #endif //_DEBUG
       
  3146         }
       
  3147 
       
  3148     if (lResult == KErrInvalidAttribute && error == KErrNone)
       
  3149     {
       
  3150     	//attribute requested was invalid return an error
       
  3151     	return KInvalidEnumAttribute;
       
  3152     }
       
  3153     else if ( lResult == KErrNone && error == KErrNone)
       
  3154     {
       
  3155     	//got the attribute ok.
       
  3156     	return lValue;
       
  3157     }
       
  3158     else if(lResult == KErrNoAttribute && error == KErrNone)
       
  3159     {
       
  3160         //everything went ok that element just didnt have the attribute requested
       
  3161         return KErrNoAttribute;
       
  3162     }
       
  3163     else
       
  3164         {
       
  3165         return KInvalidEnumAttribute;
       
  3166         }
       
  3167 
       
  3168 }
       
  3169 
       
  3170 // --------------------------------------------------------------------------
       
  3171 // EXPORT_C void CSvgEngineInterfaceImpl::SetPreserveApsectRatio( TPreserveAspectRatio aType )
       
  3172 // ---------------------------------------------------------------------------
       
  3173 EXPORT_C void CSvgEngineInterfaceImpl::SetPreserveAspectRatio( CSvgDocumentImpl* aDocument, TSvgPreserveAspectAlignType aPreserveAspectRatioSetting, TSvgMeetOrSliceType aMeetSliceType, TBool aFrameBuffOverridesViewport)
       
  3174 {
       
  3175 	if ( !aDocument )
       
  3176 	{
       
  3177 		aDocument = iSvgLoadedDocument;
       
  3178 
       
  3179 		if ( !aDocument )
       
  3180 		{
       
  3181 			if (iSvgEngine)
       
  3182 			{
       
  3183 				aDocument = iSvgEngine->Document();
       
  3184 			}
       
  3185 		}
       
  3186 
       
  3187 		if ( !aDocument )
       
  3188 		return;
       
  3189 	}
       
  3190 
       
  3191 	if (iSvgEngine)
       
  3192 			{
       
  3193 				iSvgEngine->iFrameBufferOverridesViewport = aFrameBuffOverridesViewport;
       
  3194 			}
       
  3195 
       
  3196 	CSvgSvgElementImpl* el = ( CSvgSvgElementImpl* )(aDocument->RootElement());
       
  3197 
       
  3198 	if (el == NULL)
       
  3199 	{
       
  3200 		return;
       
  3201 	}
       
  3202 
       
  3203 	TRAPD(error, el->SetPreserveAspectRatioL( aPreserveAspectRatioSetting, aMeetSliceType));
       
  3204 
       
  3205 	if (error != KErrNone)
       
  3206   	{
       
  3207     	#ifdef _DEBUG
       
  3208       _LIT(KSetPreserveAspectRatioFailed,
       
  3209       "CSvgEngineInterfaceImpl::SetPreserveAspectRatio: error.");
       
  3210       RDebug::Print(KSetPreserveAspectRatioFailed);
       
  3211       #endif //_DEBUG
       
  3212     }
       
  3213 
       
  3214 }
       
  3215 
       
  3216 // --------------------------------------------------------------------------
       
  3217 // EXPORT_C void CSvgEngineInterfaceImpl::SetEnumAttribute(CSvgElementImpl* aElementHandle,const TInt aAttributeId,TInt32 lValue)
       
  3218 // ---------------------------------------------------------------------------
       
  3219 EXPORT_C void CSvgEngineInterfaceImpl::SetEnumAttribute(CSvgElementImpl* aElementHandle,const TInt aAttributeId,TInt32 lValue)
       
  3220     {
       
  3221 
       
  3222     if(aAttributeId == KAtrPreserveAspectRatio)
       
  3223         {
       
  3224         // convert in to desc and Call set attribute
       
  3225         _LIT( KNone, "none" );
       
  3226         _LIT( KXMidYMid, "xMidYMid" );
       
  3227         _LIT( KPreserveAspectRatio, "preserveAspectRatio" );
       
  3228         if(!lValue)
       
  3229             {
       
  3230             TRAPD(error,aElementHandle->SetAttributeL(KPreserveAspectRatio,KNone));
       
  3231             if (error != KErrNone)
       
  3232                 {
       
  3233                 #ifdef _DEBUG
       
  3234                 _LIT(KSetAttributeFailed,
       
  3235                     "CSvgEngineInterfaceImpl::SetEnumAttribute: SetAttributeL error.");
       
  3236                 RDebug::Print(KSetAttributeFailed);
       
  3237                 #endif //_DEBUG
       
  3238                 }
       
  3239             }
       
  3240         if(lValue == 1)
       
  3241             {
       
  3242             TRAPD(error,aElementHandle->SetAttributeL(KPreserveAspectRatio,KXMidYMid));
       
  3243             if (error != KErrNone)
       
  3244                 {
       
  3245                 #ifdef _DEBUG
       
  3246                 _LIT(KSetAttributeFailed,
       
  3247                     "CSvgEngineInterfaceImpl::SetEnumAttribute: SetAttributeL error.");
       
  3248                 RDebug::Print(KSetAttributeFailed);
       
  3249                 #endif //_DEBUG
       
  3250                 }
       
  3251             }
       
  3252         return ;
       
  3253         }
       
  3254     if( aAttributeId == KAtrZoomAndPan)
       
  3255         {
       
  3256         if( aElementHandle->ElemID() == KSvgSvgElement )
       
  3257             {
       
  3258             ((CSvgSvgElementImpl*)aElementHandle)->SetZoomAndPan((TSvgZoomAndPanType)lValue);
       
  3259             }
       
  3260         return;
       
  3261         }
       
  3262     // for fill and stroke if the value is specified as enum need to
       
  3263     // convert it in to "string"
       
  3264     // also check that it is not a animation elements.
       
  3265     // get enum for these values is not possible.
       
  3266     if((aAttributeId == KCSS_ATTR_FILL || aAttributeId == KCSS_ATTR_STROKE)
       
  3267          && ! (   aElementHandle->IsAnimatedElement() ))
       
  3268         {
       
  3269         if(lValue == 2)
       
  3270             {
       
  3271             _LIT( KNone, "none" );
       
  3272             TRAPD(error,aElementHandle->SetPropertyL(aAttributeId,KNone));
       
  3273             if (error != KErrNone)
       
  3274                 {
       
  3275                 #ifdef _DEBUG
       
  3276                 _LIT(KSetPropertyFailed,
       
  3277                     "CSvgEngineInterfaceImpl::SetEnumAttribute: SetPropertyL error.");
       
  3278                 RDebug::Print(KSetPropertyFailed);
       
  3279                 #endif //_DEBUG
       
  3280                 }
       
  3281             return;
       
  3282             }
       
  3283         if(lValue == 3)
       
  3284             {
       
  3285             _LIT( KCurrentColor, "currentColor" );
       
  3286             TRAPD(error,aElementHandle->SetPropertyL(aAttributeId,KCurrentColor));
       
  3287             if (error != KErrNone)
       
  3288                 {
       
  3289                 #ifdef _DEBUG
       
  3290                 _LIT(KSetPropertyFailed,
       
  3291                     "CSvgEngineInterfaceImpl::SetEnumAttribute: SetPropertyL error.");
       
  3292                 RDebug::Print(KSetPropertyFailed);
       
  3293                 #endif //_DEBUG
       
  3294                 }
       
  3295             return;
       
  3296             }
       
  3297         if(lValue == 4)
       
  3298             {
       
  3299             if (!(aElementHandle->StyleInParent(aElementHandle, aAttributeId)))
       
  3300             {
       
  3301             aElementHandle->RemoveAttribute(aAttributeId);
       
  3302             }
       
  3303             return;
       
  3304             }
       
  3305         }
       
  3306 
       
  3307     TRAPD(error, aElementHandle->SetAttributeIntL(aAttributeId,lValue));
       
  3308     if (error != KErrNone)
       
  3309         {
       
  3310         #ifdef _DEBUG
       
  3311         _LIT(KSetAttributeIntFailed,
       
  3312             "CSvgEngineInterfaceImpl::SetEnumAttribute: SetAttributeIntL error.");
       
  3313         RDebug::Print(KSetAttributeIntFailed);
       
  3314         #endif //_DEBUG
       
  3315         }
       
  3316     }
       
  3317 
       
  3318 
       
  3319 // --------------------------------------------------------------------------
       
  3320 // EXPORT_C TInt CSvgEngineInterfaceImpl::GetEnumAttribute(CSvgElementImpl* aElementHandle,const TInt aAttributeId,TInt32& aValue)
       
  3321 // ---------------------------------------------------------------------------
       
  3322 EXPORT_C TInt CSvgEngineInterfaceImpl::GetEnumAttribute(CSvgElementImpl* aElementHandle,const TInt aAttributeId,TInt32& aValue)
       
  3323 {
       
  3324 
       
  3325     if(aAttributeId == KAtrPreserveAspectRatio)
       
  3326         {
       
  3327         // convert in to desc and Call set attribute
       
  3328 
       
  3329         if(aElementHandle->ElemID() == KSvgSvgElement)
       
  3330             {
       
  3331             MSvgPreserveAspectRatio *lTestObject;
       
  3332             ((CSvgSvgElementImpl*)aElementHandle)->GetPreserveAspectRatio(lTestObject);
       
  3333             if(lTestObject != NULL)
       
  3334                 {
       
  3335                 aValue = (TInt32)lTestObject->GetAlign();
       
  3336                 return KErrNone;
       
  3337                 }
       
  3338             return KInvalidEnumAttribute;
       
  3339             }
       
  3340         if(aElementHandle->ElemID() == KSvgImageElement)
       
  3341             {
       
  3342             _LIT( KNone, "none" );
       
  3343             _LIT( KXMidYMid, "xMidYMid" );
       
  3344             TPtrC16 lParValue;
       
  3345             aElementHandle->GetAttributeDes( KAtrPreserveAspectRatio, lParValue );
       
  3346             if(lParValue == KNone)
       
  3347                 {
       
  3348                 aValue = 0;
       
  3349                 return KErrNone;
       
  3350                 }
       
  3351             if(lParValue == KXMidYMid)
       
  3352                 {
       
  3353                 aValue = 1;
       
  3354                 return KErrNone;
       
  3355                 }
       
  3356             return KInvalidEnumAttribute;
       
  3357             }
       
  3358 
       
  3359         }
       
  3360     if( aAttributeId == KAtrZoomAndPan)
       
  3361         {
       
  3362         if( aElementHandle->ElemID() == KSvgSvgElement )
       
  3363             {
       
  3364             aValue = (TInt32)((CSvgSvgElementImpl*)aElementHandle)->GetZoomAndPan();
       
  3365             return KErrNone;
       
  3366             }
       
  3367         return KInvalidEnumAttribute;
       
  3368         }
       
  3369     TInt lResult = KErrNone;
       
  3370     TRAPD(error, lResult = aElementHandle->GetAttributeIntL(aAttributeId,aValue));
       
  3371     if (error != KErrNone)
       
  3372         {
       
  3373         #ifdef _DEBUG
       
  3374         _LIT(KGetAttributeIntFailed,
       
  3375             "CSvgEngineInterfaceImpl::GetEnumAttribute: GetAttributeIntL error.");
       
  3376         RDebug::Print(KGetAttributeIntFailed);
       
  3377         #endif //_DEBUG
       
  3378         }
       
  3379     if(lResult == KErrNoAttribute)
       
  3380         {
       
  3381          return KInvalidEnumAttribute;
       
  3382         }
       
  3383     return KErrNone;
       
  3384 }
       
  3385 
       
  3386 // --------------------------------------------------------------------------
       
  3387 // EXPORT_C void CSvgEngineInterfaceImpl::SetRectAttribute( CXmlElementImpl* aElementHandle,
       
  3388 // ---------------------------------------------------------------------------
       
  3389 EXPORT_C void CSvgEngineInterfaceImpl::SetRectAttribute( CXmlElementImpl* aElementHandle,
       
  3390                                                         float aX, float aY, float aWidth, float aHeight )
       
  3391 {
       
  3392     if ( aElementHandle->ElemID() ==  KSvgRectElement )
       
  3393         {
       
  3394         CSvgRectElementImpl*  rect = (CSvgRectElementImpl*)aElementHandle;
       
  3395         rect->SetRectValues(TFloatFixPt(aX), TFloatFixPt(aY), TFloatFixPt(aWidth), TFloatFixPt(aHeight));
       
  3396         }
       
  3397     // added as a part of update of get and set API's.
       
  3398     if ( aElementHandle->ElemID() ==  KSvgSvgElement)
       
  3399         {
       
  3400         // for svg element it must be viewBox.
       
  3401         TGfxRectangle2D     viewBox(aX, aY,aWidth,aHeight);
       
  3402         CSvgSvgElementImpl *lSvgSvgElement = (CSvgSvgElementImpl*)(aElementHandle);
       
  3403         TRAPD(error,lSvgSvgElement->SetViewBoxL( viewBox));
       
  3404         if (error != KErrNone)
       
  3405             {
       
  3406             #ifdef _DEBUG
       
  3407             _LIT(KSetRectAttributeFailed,
       
  3408                 "CSvgEngineInterfaceImpl::SetRectAttribute: SetViewBoxL error.");
       
  3409             RDebug::Print(KSetRectAttributeFailed);
       
  3410             #endif //_DEBUG
       
  3411             }
       
  3412 
       
  3413          //CTM must be updated since viewbox changed
       
  3414          lSvgSvgElement->UpdateCTM();
       
  3415 
       
  3416         }
       
  3417 }
       
  3418 // --------------------------------------------------------------------------
       
  3419 // EXPORT_C TBool CSvgEngineInterfaceImpl::GetRectAttribute( CXmlElementImpl* aElementHandle,
       
  3420 // ---------------------------------------------------------------------------
       
  3421 EXPORT_C TBool CSvgEngineInterfaceImpl::GetRectAttribute( CXmlElementImpl* aElementHandle,
       
  3422                                                         float* aX, float* aY, float* aWidth, float* aHeight )
       
  3423 {
       
  3424     // added as a part of update of get and set API's.
       
  3425     TBool viewBoxExisted = EFalse;
       
  3426 
       
  3427     if ( aElementHandle->ElemID() ==  KSvgSvgElement)
       
  3428         {
       
  3429         // for svg element it must be viewBox.
       
  3430         TGfxRectangle2D     viewBox;
       
  3431         CSvgSvgElementImpl *lSvgSvgElemet = (CSvgSvgElementImpl*)(aElementHandle);
       
  3432 
       
  3433         viewBoxExisted = lSvgSvgElemet->GetViewBox(viewBox);
       
  3434         *aX = viewBox.iX;
       
  3435         *aY = viewBox.iY;
       
  3436         *aWidth  = viewBox.iWidth;
       
  3437         *aHeight = viewBox.iHeight;
       
  3438         }
       
  3439     else if ( aElementHandle->ElemID() ==  KSvgRectElement )
       
  3440         {
       
  3441         CSvgRectElementImpl*  rect = (CSvgRectElementImpl*)aElementHandle;
       
  3442         *aX = rect->X();
       
  3443         *aY = rect->Y();
       
  3444         *aWidth  = rect->Width();
       
  3445         *aHeight = rect->Height();
       
  3446         }
       
  3447      else
       
  3448         {
       
  3449          aX = NULL;
       
  3450         }
       
  3451 
       
  3452         return viewBoxExisted;
       
  3453 }
       
  3454 
       
  3455 // --------------------------------------------------------------------------
       
  3456 // EXPORT_C void CSvgEngineInterfaceImpl::GetMatrixAttribute( CXmlElementImpl* aElementHandle, float* aAVal,
       
  3457 // ---------------------------------------------------------------------------
       
  3458 EXPORT_C void CSvgEngineInterfaceImpl::GetMatrixAttribute( CXmlElementImpl* aElementHandle, float* aAVal,
       
  3459                                                            float* aBVal, float* aCVal, float* aDVal,
       
  3460                                                            float* aEVal, float* aFVal )
       
  3461 {
       
  3462 		//this should have been taken care of in the set only -
       
  3463 		//what about updating from the root all the way down here.
       
  3464 		//((CSvgElementImpl*)aElementHandle)->UpdateCTM();
       
  3465 
       
  3466     const TGfxAffineTransform& matrix = ((CSvgElementImpl*)aElementHandle)->GetCTM();
       
  3467 
       
  3468     *aAVal = matrix.iM00;
       
  3469     *aBVal = matrix.iM10;
       
  3470     *aCVal = matrix.iM01;
       
  3471     *aDVal = matrix.iM11;
       
  3472     *aEVal = matrix.iM02;
       
  3473     *aFVal = matrix.iM12;
       
  3474 }
       
  3475 
       
  3476 
       
  3477 // --------------------------------------------------------------------------
       
  3478 // EXPORT_C void CSvgEngineInterfaceImpl::GetMatrixAttribute( CXmlElementImpl* aElementHandle, float* aAVal,
       
  3479 // ---------------------------------------------------------------------------
       
  3480 EXPORT_C void CSvgEngineInterfaceImpl::GetMatrixAttribute( CXmlElementImpl* aElementHandle, TInt aAttributeType,
       
  3481 														   float* aAVal, float* aBVal, 
       
  3482 														   float* aCVal, float* aDVal,
       
  3483                                                            float* aEVal, float* aFVal )
       
  3484 {
       
  3485     if( aAttributeType == KAtrTransform)
       
  3486     {
       
  3487 	    MSvgTransformList*  trList;
       
  3488 	    ((CSvgElementImpl*)aElementHandle)->GetTransform( trList );
       
  3489 	    TGfxAffineTransform matrix = 
       
  3490 	      trList->Consolidate( ((CSvgElementImpl*)aElementHandle)->IsOverwriteTransforms() );
       
  3491 
       
  3492 	    *aAVal = matrix.iM00;
       
  3493 	    *aBVal = matrix.iM10;
       
  3494 	    *aCVal = matrix.iM01;
       
  3495 	    *aDVal = matrix.iM11;
       
  3496 	    *aEVal = matrix.iM02;
       
  3497 	    *aFVal = matrix.iM12;
       
  3498     }
       
  3499 }
       
  3500 // --------------------------------------------------------------------------
       
  3501 // EXPORT_C void CSvgEngineInterfaceImpl::SetMatrixAttribute( CXmlElementImpl* aElementHandle, float aAVal,
       
  3502 // ---------------------------------------------------------------------------
       
  3503 EXPORT_C void CSvgEngineInterfaceImpl::SetMatrixAttribute( CXmlElementImpl* aElementHandle, float aAVal,
       
  3504                                                            float aBVal, float aCVal, float aDVal,
       
  3505                                                            float aEVal, float aFVal )
       
  3506 {
       
  3507     if ((CSvgElementImpl*)aElementHandle)
       
  3508     {
       
  3509         TGfxAffineTransform matrix;
       
  3510         matrix.SetTransform( TReal32(aAVal), TReal32(aBVal), TReal32(aCVal),
       
  3511                          TReal32(aDVal), TReal32(aEVal), TReal32(aFVal) );
       
  3512         MSvgTransformList*  trList;
       
  3513         ((CSvgElementImpl*)aElementHandle)->GetTransform( trList );
       
  3514         trList->ReplaceItem( matrix, 0 );
       
  3515 
       
  3516         // we need to update the CTM on this element and below it....
       
  3517 
       
  3518         ((CSvgElementImpl*)aElementHandle)->UpdateCTM();
       
  3519     }
       
  3520 }
       
  3521 
       
  3522 // --------------------------------------------------------------------------
       
  3523 // EXPORT_C void CSvgEngineInterfaceImpl::ClearFrameBuffer(CFbsBitmap* aFrameBuffer, TUint32 aClearingColor)
       
  3524 // ---------------------------------------------------------------------------
       
  3525 EXPORT_C void CSvgEngineInterfaceImpl::ClearFrameBuffer(CFbsBitmap* /* aFrameBuffer */,
       
  3526                                                         TUint32 /* aClearingColor */,
       
  3527                                                         TInt /* aEngine */ )
       
  3528 {
       
  3529 }
       
  3530 
       
  3531 
       
  3532 // --------------------------------------------------------------------------
       
  3533 // EXPORT_C void CSvgEngineInterfaceImpl:: SetFrameBuffer(CFbsBitmap* aRenderBuffer)
       
  3534 // ---------------------------------------------------------------------------
       
  3535 EXPORT_C void CSvgEngineInterfaceImpl:: SetFrameBuffer(CFbsBitmap* aRenderBuffer, TInt aEngine)
       
  3536     {
       
  3537     if( ChooseEngine ( aEngine ) )
       
  3538         {
       
  3539         iSvgEngine->SetSVGEngineState(ESVGEnginePaused);
       
  3540         TRAPD( error1,iSvgEngine->SetGdiContextL(aRenderBuffer));
       
  3541 
       
  3542          if( error1 == KErrNone )
       
  3543             {
       
  3544 
       
  3545             TRAPD( error2, iSvgEngine->InitializeEngineL()); // set the viewport and viewbox
       
  3546             if (error2 != KErrNone)
       
  3547                 {
       
  3548                 #ifdef _DEBUG
       
  3549                 _LIT(KSetFrameBufferFailed,
       
  3550                     "CSvgEngineInterfaceImpl::SetFrameBuffer: InitializeEngineL error.");
       
  3551                 RDebug::Print(KSetFrameBufferFailed);
       
  3552                 #endif //_DEBUG
       
  3553                 }
       
  3554 
       
  3555             if( iSvgEngine->Document() )
       
  3556                 {
       
  3557                 if( iSvgEngine->Document()->IsAnimationFile() ) // If it is animation file
       
  3558                     {
       
  3559                     iSvgEngine->SetSVGEngineState(ESVGEngineRunning);
       
  3560                     }
       
  3561                 else
       
  3562                     {
       
  3563                     // If static file, just redraw it
       
  3564                     TSvgTimerEvent tmev( 0 );
       
  3565                     TRAPD( error2,iSvgEngine->ProcessEventL( 
       
  3566                         iSvgEngine->Document(), &tmev ));
       
  3567                     if (error2 != KErrNone)
       
  3568                         {
       
  3569                         #ifdef _DEBUG
       
  3570                         _LIT(KRedrawFailed, "CSvgEngineInterfaceImpl::SetFrameBuffer: Redraw error.");
       
  3571                         RDebug::Print(KRedrawFailed);
       
  3572                         #endif //_DEBUG
       
  3573                         }
       
  3574                     }
       
  3575                 }
       
  3576             }
       
  3577         }
       
  3578     }
       
  3579 
       
  3580 // --------------------------------------------------------------------------
       
  3581 // EXPORT_C TBool CSvgEngineInterfaceImpl::SearchForText( const TDesC& aSearchString,
       
  3582 // ---------------------------------------------------------------------------
       
  3583 EXPORT_C TBool CSvgEngineInterfaceImpl::SearchForText( const TDesC& aSearchString,
       
  3584                                                        RPointerArray<MRect>& aBoundingBoxes,
       
  3585                                                        RArray<TPtrC>& aTexts,
       
  3586                                                        RArray<TInt>& aElementIds,
       
  3587                                                        TBool aCaseSensitive,
       
  3588                                                        TInt aEngine )
       
  3589 {
       
  3590     if ( !ChooseEngine ( aEngine ) )
       
  3591     {
       
  3592         return EFalse;
       
  3593     }
       
  3594 
       
  3595     TInt initialCount = aBoundingBoxes.Count();
       
  3596 
       
  3597     iSvgEngine->FindBBoxesForRotatedText( aSearchString, aBoundingBoxes, aTexts, aElementIds, aCaseSensitive );
       
  3598 
       
  3599     return aBoundingBoxes.Count() > initialCount;
       
  3600 }
       
  3601 
       
  3602 // --------------------------------------------------------------------------
       
  3603 // EXPORT_C TBool CSvgEngineInterfaceImpl::AddTextListener( MSvgTextListener* aListener)
       
  3604 // ---------------------------------------------------------------------------
       
  3605 EXPORT_C TBool CSvgEngineInterfaceImpl::AddTextListener( MSvgTextListener* aListener, TInt aEngine )
       
  3606 {
       
  3607     if ( ChooseEngine ( aEngine ) )
       
  3608     {
       
  3609         iSvgEngine->AddTextListener( aListener );
       
  3610     }
       
  3611 
       
  3612     return ETrue;
       
  3613 }
       
  3614 
       
  3615 // --------------------------------------------------------------------------
       
  3616 // EXPORT_C TBool CSvgEngineInterfaceImpl::RemoveTextListener( MSvgTextListener* aListener)
       
  3617 // ---------------------------------------------------------------------------
       
  3618 EXPORT_C TBool CSvgEngineInterfaceImpl::RemoveTextListener( MSvgTextListener* aListener, TInt aEngine )
       
  3619 {
       
  3620      if ( ChooseEngine ( aEngine ) )
       
  3621      {
       
  3622         iSvgEngine->RemoveTextListener( aListener );
       
  3623      }
       
  3624 
       
  3625      return ETrue;
       
  3626 }
       
  3627 
       
  3628 // --------------------------------------------------------------------------
       
  3629 // EXPORT_C TBool CSvgEngineInterfaceImpl::SetTextForTextElement( TInt aTextElementId, TDesC& aXmlString )
       
  3630 // ---------------------------------------------------------------------------
       
  3631 EXPORT_C TBool CSvgEngineInterfaceImpl::SetTextForTextElement( TInt aTextElementId, TDesC& aXmlString )
       
  3632 {
       
  3633     TRAPD(err, ((CSvgTextElementImpl*)aTextElementId)->SetTextL(aXmlString));
       
  3634     if ( err != KErrNone )
       
  3635         {
       
  3636         #ifdef _DEBUG
       
  3637         RDebug::Printf("CSvgEngineInterfaceImpl::SetTextForTextElement failed");
       
  3638         #endif
       
  3639         return EFalse;
       
  3640         }
       
  3641 
       
  3642     return ETrue;
       
  3643 }
       
  3644 
       
  3645 // --------------------------------------------------------------------------
       
  3646 // EXPORT_C TBool CSvgEngineInterfaceImpl::GetTextForTextElement( TInt aTextElementId, TBool& aEditable, TDes& aXmlString )
       
  3647 // ---------------------------------------------------------------------------
       
  3648 EXPORT_C TBool CSvgEngineInterfaceImpl::GetTextForTextElement( TInt aTextElementId, TBool& aEditable, TDes& aXmlString )
       
  3649 {
       
  3650     if(aXmlString.MaxLength() < ((CSvgTextElementImpl*)aTextElementId)->GetText().Length() )
       
  3651         {
       
  3652         aXmlString = ((CSvgTextElementImpl*)aTextElementId)->GetText().Left( aXmlString.MaxLength() );
       
  3653         }
       
  3654     else
       
  3655         {
       
  3656         aXmlString = ((CSvgTextElementImpl*)aTextElementId)->GetText();
       
  3657         }
       
  3658 
       
  3659     aEditable = ((CSvgTextElementImpl*)aTextElementId)->IsEditable();
       
  3660 
       
  3661     return aEditable;
       
  3662 }
       
  3663 
       
  3664 
       
  3665 // --------------------------------------------------------------------------
       
  3666 // EXPORT_C TBool CSvgEngineInterfaceImpl::AddTextAreaListener( MSvgTextAreaListener* aListener)
       
  3667 // ---------------------------------------------------------------------------
       
  3668 EXPORT_C TBool CSvgEngineInterfaceImpl::AddTextAreaListener( MSvgTextAreaListener* aListener, TInt aEngine )
       
  3669 {
       
  3670     if ( ChooseEngine ( aEngine ) )
       
  3671     {
       
  3672         iSvgEngine->AddTextAreaListener( aListener );
       
  3673     }
       
  3674 
       
  3675     return ETrue;
       
  3676 }
       
  3677 
       
  3678 // --------------------------------------------------------------------------
       
  3679 // EXPORT_C TBool CSvgEngineInterfaceImpl::RemoveTextAreaListener( MSvgTextAreaListener* aListener)
       
  3680 // ---------------------------------------------------------------------------
       
  3681 EXPORT_C TBool CSvgEngineInterfaceImpl::RemoveTextAreaListener( MSvgTextAreaListener* aListener, TInt aEngine )
       
  3682 {
       
  3683      if ( ChooseEngine ( aEngine ) )
       
  3684      {
       
  3685         iSvgEngine->RemoveTextAreaListener( aListener );
       
  3686      }
       
  3687 
       
  3688      return ETrue;
       
  3689 }
       
  3690 
       
  3691 // --------------------------------------------------------------------------
       
  3692 // EXPORT_C TBool CSvgEngineInterfaceImpl::SetTextForTextAreaElement( TInt aTextAreaElementId, TDesC& aXmlString )
       
  3693 // ---------------------------------------------------------------------------
       
  3694 EXPORT_C TBool CSvgEngineInterfaceImpl::SetTextForTextAreaElement( TInt aTextAreaElementId, TDesC& aXmlString )
       
  3695 {
       
  3696     TRAPD(err, ((CSvgTextAreaElementImpl*)aTextAreaElementId)->SetTextL(aXmlString));
       
  3697 
       
  3698     if ( err != KErrNone )
       
  3699         {
       
  3700         #ifdef _DEBUG
       
  3701         RDebug::Printf("CSvgEngineInterfaceImpl::SetTextForTextElement failed");
       
  3702         #endif
       
  3703         return EFalse;
       
  3704         }
       
  3705 
       
  3706     return ETrue;
       
  3707 }
       
  3708 
       
  3709 // --------------------------------------------------------------------------
       
  3710 // EXPORT_C TBool CSvgEngineInterfaceImpl::GetTextForTextAreaElement( TInt aTextAreaElementId, TBool& aEditable, TDes& aXmlString )
       
  3711 // ---------------------------------------------------------------------------
       
  3712 EXPORT_C TBool CSvgEngineInterfaceImpl::GetTextForTextAreaElement( TInt aTextAreaElementId, TBool& aEditable, TDes& aXmlString )
       
  3713 {
       
  3714     ((CSvgTextAreaElementImpl*)aTextAreaElementId)->GetText( aXmlString );
       
  3715 
       
  3716     aEditable = ((CSvgTextAreaElementImpl*)aTextAreaElementId)->IsEditable();
       
  3717 
       
  3718     return aEditable;
       
  3719 }
       
  3720 
       
  3721 
       
  3722 // --------------------------------------------------------------------------
       
  3723 // EXPORT_C void CSvgEngineInterfaceImpl::AddHyperlinkListener( MSvgHyperlinkListener* aListener )
       
  3724 // ---------------------------------------------------------------------------
       
  3725 EXPORT_C void CSvgEngineInterfaceImpl::AddHyperlinkListener( MSvgHyperlinkListener* aListener, TInt aEngine )
       
  3726 {
       
  3727     if ( ChooseEngine ( aEngine ) )
       
  3728     {
       
  3729         iSvgEngine->AddHyperlinkListener( aListener );
       
  3730     }
       
  3731 }
       
  3732 
       
  3733 // --------------------------------------------------------------------------
       
  3734 // EXPORT_C void CSvgEngineInterfaceImpl::RemoveHyperlinkListener( MSvgHyperlinkListener* aListener )
       
  3735 // ---------------------------------------------------------------------------
       
  3736 EXPORT_C void CSvgEngineInterfaceImpl::RemoveHyperlinkListener( MSvgHyperlinkListener* aListener, TInt aEngine )
       
  3737 {
       
  3738     if ( ChooseEngine ( aEngine ) )
       
  3739     {
       
  3740         iSvgEngine->RemoveHyperlinkListener( aListener );
       
  3741     }
       
  3742 }
       
  3743 // --------------------------------------------------------------------------
       
  3744 // EXPORT_C void CSvgEngineInterfaceImpl::AddAnimationListener( MSvgAnimationListener* aListener )
       
  3745 // ---------------------------------------------------------------------------
       
  3746 EXPORT_C void CSvgEngineInterfaceImpl::AddAnimationListener( MSvgAnimationListener* aListener, TInt aEngine )
       
  3747 {
       
  3748     if ( ChooseEngine ( aEngine ) )
       
  3749     {
       
  3750         iSvgEngine->AddAnimationListener( aListener );
       
  3751     }
       
  3752 }
       
  3753 
       
  3754 // --------------------------------------------------------------------------
       
  3755 // EXPORT_C void CSvgEngineInterfaceImpl::RemoveAnimationListener( MSvgAnimationListener* aListener )
       
  3756 // ---------------------------------------------------------------------------
       
  3757 EXPORT_C void CSvgEngineInterfaceImpl::RemoveAnimationListener( MSvgAnimationListener* aListener, TInt aEngine )
       
  3758 {
       
  3759     if ( ChooseEngine ( aEngine ) )
       
  3760     {
       
  3761         iSvgEngine->RemoveAnimationListener( aListener );
       
  3762     }
       
  3763 }
       
  3764 
       
  3765 // --------------------------------------------------------------------------
       
  3766 // EXPORT_C TInt CSvgEngineInterfaceImpl::GetViewportWidth( CSvgDocumentImpl* aDocumentHandle )
       
  3767 // ---------------------------------------------------------------------------
       
  3768 EXPORT_C TInt CSvgEngineInterfaceImpl::GetViewportWidth( CSvgDocumentImpl* aDocumentHandle )
       
  3769 {
       
  3770     TFloatFixPt width = 0;
       
  3771     CSvgSvgElementImpl*  el = (CSvgSvgElementImpl*)(aDocumentHandle->RootElement());
       
  3772 
       
  3773     if ( el != NULL )
       
  3774     {
       
  3775     	width = el->Width( );
       
  3776     	    
       
  3777     	// this means the values were provided in % and the Engine is not initialized.
       
  3778       if((TInt)(width) == -1)
       
  3779         {
       
  3780         return (TInt)(el->iWidthInUserCoordinate);
       
  3781         }
       
  3782    	}
       
  3783 
       
  3784 
       
  3785     return (TInt)width;
       
  3786 }
       
  3787 
       
  3788 // --------------------------------------------------------------------------
       
  3789 // EXPORT_C TInt CSvgEngineInterfaceImpl::GetViewportHeight( CSvgDocumentImpl* aDocumentHandle )
       
  3790 // ---------------------------------------------------------------------------
       
  3791 EXPORT_C TInt CSvgEngineInterfaceImpl::GetViewportHeight( CSvgDocumentImpl* aDocumentHandle )
       
  3792 {
       
  3793     TFloatFixPt height = 0;
       
  3794     CSvgSvgElementImpl*  el = (CSvgSvgElementImpl*)(aDocumentHandle->RootElement());
       
  3795 
       
  3796     if ( el != NULL )
       
  3797     {
       
  3798     	height = el->Height( );
       
  3799     	
       
  3800     	// this means the values were provided in % and the Engine is not initialized.
       
  3801         if((TInt)(height) == -1)
       
  3802         {
       
  3803         return (TInt)(el->iHeightInUserCoordinate);
       
  3804         }
       
  3805    	}
       
  3806     
       
  3807     return (TInt)height;
       
  3808 }
       
  3809 
       
  3810 // --------------------------------------------------------------------------
       
  3811 // EXPORT_C void CSvgEngineInterfaceImpl::SetViewportWidth( CSvgDocumentImpl* aDocumentHandle, TInt aWidth )
       
  3812 // ---------------------------------------------------------------------------
       
  3813 EXPORT_C void CSvgEngineInterfaceImpl::SetViewportWidth( CSvgDocumentImpl* aDocumentHandle, TInt aWidth )
       
  3814 {
       
  3815     CSvgSvgElementImpl*  el = (CSvgSvgElementImpl*)( aDocumentHandle->RootElement());
       
  3816     if ( el != NULL )
       
  3817         {
       
  3818         TRAP_IGNORE( el->SetAttributeFloatL( KAtrWidth, (TFloatFixPt)aWidth ) );
       
  3819         el->iWidthInPercentage = EFalse;
       
  3820         }
       
  3821 }
       
  3822 
       
  3823 // --------------------------------------------------------------------------
       
  3824 // EXPORT_C void CSvgEngineInterfaceImpl::SetViewportHeight( CSvgDocumentImpl* aDocumentHandle, TInt aHeight )
       
  3825 // ---------------------------------------------------------------------------
       
  3826 EXPORT_C void CSvgEngineInterfaceImpl::SetViewportHeight( CSvgDocumentImpl* aDocumentHandle, TInt aHeight )
       
  3827 {
       
  3828     CSvgSvgElementImpl*  el = (CSvgSvgElementImpl*)( aDocumentHandle->RootElement());
       
  3829     if ( el != NULL )
       
  3830         {
       
  3831         TRAP_IGNORE( el->SetAttributeFloatL( KAtrHeight, (TFloatFixPt)aHeight ) );
       
  3832         el->iHeightInPercentage = EFalse;
       
  3833         }
       
  3834 }
       
  3835 
       
  3836 // --------------------------------------------------------------------------
       
  3837 // EXPORT_C TInt CSvgEngineInterfaceImpl::GetViewportUnits( CSvgDocumentImpl* aDocumentHandle )
       
  3838 // ---------------------------------------------------------------------------
       
  3839 EXPORT_C TInt CSvgEngineInterfaceImpl::GetViewportUnits( CSvgDocumentImpl* aDocumentHandle )
       
  3840 {
       
  3841     if ( 
       
  3842     ((CSvgSvgElementImpl*)aDocumentHandle->RootElement() )->iWidthInPercentage 
       
  3843     && ((CSvgSvgElementImpl*)aDocumentHandle->RootElement() )->iHeightInPercentage 
       
  3844     )
       
  3845     {
       
  3846         return SvgUnitPercent;
       
  3847     }
       
  3848     else
       
  3849     {
       
  3850         return SvgUnitPixels;
       
  3851     }
       
  3852 }
       
  3853 
       
  3854 // --------------------------------------------------------------------------
       
  3855 // EXPORT_C void CSvgEngineInterfaceImpl::SvgBeginElementAt(CXmlElementImpl* aElementHandle , TUint32 aTimeInMilliSeconds, CSvgDocumentImpl* aDocumentHandle)
       
  3856 // ---------------------------------------------------------------------------
       
  3857 EXPORT_C void CSvgEngineInterfaceImpl::SvgBeginElementAt( 
       
  3858         CXmlElementImpl* aElementHandle , 
       
  3859         TUint32 aTimeInMilliSeconds, 
       
  3860         CSvgDocumentImpl* /* aDocumentHandle */ )
       
  3861     {
       
  3862     if  ( ((CSvgElementImpl*)aElementHandle)->IsAnimatedElement() )
       
  3863         {
       
  3864         // do this only when this is  an animation element.
       
  3865 		CSvgAnimationBase*  lAnimationBasePtr = (CSvgAnimationBase*)aElementHandle;
       
  3866 		TRAPD( err, lAnimationBasePtr->SetBeginByEventL( lAnimationBasePtr,
       
  3867 			aTimeInMilliSeconds, ETrue ));
       
  3868 
       
  3869         lAnimationBasePtr->SaveBeginTimeToList(aTimeInMilliSeconds);
       
  3870         if ( err != KErrNone )
       
  3871             {
       
  3872             #ifdef _DEBUG
       
  3873             RDebug::Printf("CSvgEngineInterfaceImpl::SvgBeginElementAt SetBeginByEventL() failed");
       
  3874             #endif
       
  3875             }
       
  3876         }
       
  3877     }
       
  3878 
       
  3879 //---------------------------------------------------------------------------=
       
  3880 //Old begine element at...
       
  3881 //---------------------------------------------------------------------------=
       
  3882 /*EXPORT_C void CSvgEngineInterfaceImpl::SvgBeginElementAt(CXmlElementImpl* aElementHandle , TUint32 aTimeInMilliSeconds)
       
  3883 {
       
  3884   if  (   aElementHandle->ElemID() >= KSvgAnimElemsStartIndex &&
       
  3885                         aElementHandle->ElemID() <= KSvgAnimElemsEndIndex
       
  3886         )
       
  3887         {
       
  3888         // do this only when this is  an animation element.
       
  3889         CSvgAnimationBase*  lAnimationBasePtr = (CSvgAnimationBase*)aElementHandle;
       
  3890         lAnimationBasePtr->SetBeginTime(aTimeInMilliSeconds);
       
  3891         // what if the animation has already started. reflect the change in the end Time.
       
  3892         TUint32 lSimpleDuration = lAnimationBasePtr->SimpleDuration();
       
  3893         if( lSimpleDuration )
       
  3894             {
       
  3895             lAnimationBasePtr->SetEndTime(lSimpleDuration);
       
  3896             }
       
  3897         // should we change the animation status.
       
  3898         // if the animation has finished then it will not start here again
       
  3899         // Reset the status and reset the repeatCount.
       
  3900 
       
  3901         }
       
  3902 }*/
       
  3903 
       
  3904 // --------------------------------------------------------------------------
       
  3905 // EXPORT_C void CSvgEngineInterfaceImpl::SvgEndElementAt(CXmlElementImpl* aElementHandle , TUint32 aTimeInMilliSeconds, CSvgDocumentImpl* aDocumentHandle)
       
  3906 // ---------------------------------------------------------------------------
       
  3907 EXPORT_C void CSvgEngineInterfaceImpl::SvgEndElementAt( CXmlElementImpl* aElementHandle , TUint32 aTimeInMilliSeconds, CSvgDocumentImpl*  aDocumentHandle )
       
  3908 {
       
  3909   if  ( ((CSvgElementImpl*)aElementHandle)->IsAnimatedElement() )
       
  3910         {
       
  3911         // do this only when this is  an animation element.
       
  3912         CSvgAnimationBase*  lAnimationBasePtr = (CSvgAnimationBase*)aElementHandle;
       
  3913         lAnimationBasePtr->SetEndByEvent(lAnimationBasePtr, aTimeInMilliSeconds);
       
  3914 
       
  3915         //this may be more efficient then SetMediaTime below because it only does this element.
       
  3916         //lAnimationBasePtr->ReInitializeAnimation();
       
  3917 
       
  3918         SvgSetMediaTime(aDocumentHandle, SvgGetMediaTime(aDocumentHandle) );
       
  3919 
       
  3920         }
       
  3921 }
       
  3922 
       
  3923 // --------------------------------------------------------------------------
       
  3924 // EXPORT_C void CSvgEngineInterfaceImpl::SvgSetMediaTime(CSvgDocumentImpl* aDocumentHandle ,TUint32 aTimeInMilliSeconds)
       
  3925 // ---------------------------------------------------------------------------
       
  3926 EXPORT_C void CSvgEngineInterfaceImpl::SvgSetMediaTime(CSvgDocumentImpl* aDocumentHandle ,TUint32 aTimeInMilliSeconds)
       
  3927 {
       
  3928     if(aDocumentHandle && aDocumentHandle->Engine())
       
  3929     {
       
  3930         aDocumentHandle->Engine()->SetMediaTime(aTimeInMilliSeconds);
       
  3931         //Reset the document only if time is 0. This change is just to meet JSR request.
       
  3932         if(aTimeInMilliSeconds == 0 && !aDocumentHandle->Engine()->iTimer)
       
  3933         {
       
  3934         	TSvgTimerEvent timeEvent( aTimeInMilliSeconds );
       
  3935 	       	aDocumentHandle->Reset( &timeEvent );	
       
  3936         }
       
  3937     }
       
  3938     else if (aDocumentHandle && !aDocumentHandle->Engine())
       
  3939  	{
       
  3940 	//JSR226 Change in question
       
  3941     		#ifdef _DEBUG
       
  3942     		RDebug::Printf("CSvgEngineInterfaceImpl::SvgSetMediaTime--doc doesnt know its engine!");
       
  3943     		#endif
       
  3944 
       
  3945     		//creating a fake engine for the JSR 226 to be able to get valid numbers
       
  3946     		//before rendering.  Don't try this at home kids
       
  3947 
       
  3948 			CSvgEngineImpl* fakeEngine = NULL;
       
  3949 
       
  3950     		TRAP_IGNORE( fakeEngine  = CSvgEngineImpl::NewL(iSvgBitmapFontProvider) );
       
  3951 
       
  3952     		if (fakeEngine == NULL)
       
  3953     		{
       
  3954     			return;
       
  3955     		}
       
  3956 
       
  3957     		aDocumentHandle->SetEngine(fakeEngine );
       
  3958     		fakeEngine ->SetDocument(aDocumentHandle);
       
  3959 
       
  3960     		aDocumentHandle->Engine()->SetMediaTime(aTimeInMilliSeconds);
       
  3961 
       
  3962     		TSvgTimerEvent timeEvent( aTimeInMilliSeconds );
       
  3963 
       
  3964         	//AJD I think this needs to be down in the event handler where it sets the time...
       
  3965         	fakeEngine ->Document()->Reset( &timeEvent );
       
  3966 
       
  3967         	TRAPD( error3, fakeEngine ->ProcessEventL( 
       
  3968         	    aDocumentHandle, &timeEvent, EFalse ));
       
  3969 
       
  3970             if( error3 != KErrNone)
       
  3971             {
       
  3972                 // Error Processing
       
  3973             }
       
  3974 
       
  3975         	fakeEngine ->UpdateCTM(aDocumentHandle);
       
  3976 
       
  3977     		aDocumentHandle->SetEngine(NULL);
       
  3978     		fakeEngine ->SetDocument(NULL);
       
  3979 
       
  3980     		delete fakeEngine ;
       
  3981 
       
  3982     		//store off time on document because this was with a fake engine
       
  3983     		//because at this point it hasn't rendered
       
  3984     		aDocumentHandle->iTimeForJSR226 = aTimeInMilliSeconds;
       
  3985     }
       
  3986     else
       
  3987     {
       
  3988     		#ifdef _DEBUG
       
  3989     		RDebug::Printf("CSvgEngineInterfaceImpl::SvgSetMediaTime-- engine or doc null!");
       
  3990     		#endif
       
  3991     }
       
  3992 }
       
  3993 
       
  3994 // --------------------------------------------------------------------------
       
  3995 // EXPORT_C TReal32 CSvgEngineInterfaceImpl::SvgGetMediaTime(CSvgDocumentImpl* aDocumentHandle )
       
  3996 // ---------------------------------------------------------------------------
       
  3997 EXPORT_C TReal32 CSvgEngineInterfaceImpl::SvgGetMediaTime(CSvgDocumentImpl* aDocumentHandle ) __SOFTFP
       
  3998 {
       
  3999     // returns time in  milliseconds
       
  4000     if(aDocumentHandle && aDocumentHandle->Engine())
       
  4001     {
       
  4002         return (TReal32)(aDocumentHandle->Engine()->CurrentTIme());
       
  4003     }
       
  4004     else
       
  4005     {
       
  4006     	if (aDocumentHandle && !aDocumentHandle->Engine())
       
  4007     	{
       
  4008     		#ifdef _DEBUG
       
  4009     		RDebug::Printf("CSvgEngineInterfaceImpl::SvgGetMediaTime--doc doesnt know its engine!");
       
  4010     		#endif
       
  4011 
       
  4012     		return ( (TReal32)(aDocumentHandle->iTimeForJSR226) );
       
  4013     	}
       
  4014     	else
       
  4015     	{
       
  4016     		#ifdef _DEBUG
       
  4017     		RDebug::Printf("CSvgEngineInterfaceImpl::SvgGetMediaTime-- engine or doc null!");
       
  4018     		#endif
       
  4019     	}
       
  4020     }
       
  4021 
       
  4022     return 0;
       
  4023 }
       
  4024 
       
  4025 // --------------------------------------------------------------------------
       
  4026 // EXPORT_C TBool CSvgEngineInterfaceImpl::SvgHasAnimation(CSvgDocumentImpl* aDocumentHandle )
       
  4027 // ---------------------------------------------------------------------------
       
  4028 EXPORT_C TBool CSvgEngineInterfaceImpl::SvgHasAnimation(CSvgDocumentImpl* aDocumentHandle )
       
  4029 {
       
  4030     if (aDocumentHandle)
       
  4031     {
       
  4032         return aDocumentHandle->IsAnimationFile();
       
  4033     }
       
  4034 
       
  4035     return EFalse;
       
  4036 }
       
  4037 // --------------------------------------------------------------------------
       
  4038 // EXPORT_C CXmlElementImpl* CSvgEngineInterfaceImpl::GetFocusedElement(CSvgDocumentImpl* aDocument)
       
  4039 // ---------------------------------------------------------------------------
       
  4040 EXPORT_C CXmlElementImpl* CSvgEngineInterfaceImpl::GetFocusedElement(CSvgDocumentImpl* aDocument)
       
  4041 {
       
  4042     if(aDocument)
       
  4043     {
       
  4044         return aDocument->GetFocusElement();
       
  4045     }
       
  4046 
       
  4047         return 0;
       
  4048 }
       
  4049 // --------------------------------------------------------------------------
       
  4050 // EXPORT_C void CSvgEngineInterfaceImpl::SetFocusElement(CXmlElementImpl* aElement , CSvgDocumentImpl* aDocument)
       
  4051 // ---------------------------------------------------------------------------
       
  4052 EXPORT_C void CSvgEngineInterfaceImpl::SetFocusElement(CXmlElementImpl* aElement , CSvgDocumentImpl* aDocument)
       
  4053 {
       
  4054     if(aDocument)
       
  4055     {
       
  4056         aDocument->SetFocusElement(aElement);
       
  4057     }
       
  4058 }
       
  4059 // --------------------------------------------------------------------------
       
  4060 // EXPORT_C TBool CSvgEngineInterfaceImpl::SVGElementInDom(CSvgDocumentImpl* aDocument,  CXmlElementImpl* aElement)
       
  4061 // ---------------------------------------------------------------------------
       
  4062 EXPORT_C TBool CSvgEngineInterfaceImpl::SVGElementInDom(CSvgDocumentImpl* aDocument,  CXmlElementImpl* aElement)
       
  4063 {
       
  4064     if (aDocument)
       
  4065     {
       
  4066         return aDocument->SvgElementPresent((CSvgElementImpl*) aElement);
       
  4067     }
       
  4068 
       
  4069     return EFalse;
       
  4070 }
       
  4071 // --------------------------------------------------------------------------
       
  4072 // EXPORT_C void CSvgEngineInterfaceImpl::SvgActivateAnimation(CSvgDocumentImpl* aDocument)
       
  4073 // ---------------------------------------------------------------------------
       
  4074 EXPORT_C void CSvgEngineInterfaceImpl::SvgActivateAnimation(CSvgDocumentImpl* aDocument)
       
  4075 {
       
  4076     // this means that if the focus element is an animation element
       
  4077     // than the animation element should begin. // SVGACTIVATEANIMATION.
       
  4078     if(aDocument)
       
  4079         {
       
  4080         CXmlElementImpl* lCurrentFocusElement= aDocument->GetFocusElement();
       
  4081         if(lCurrentFocusElement)
       
  4082             {
       
  4083             // Get the element ID
       
  4084             TInt lId = lCurrentFocusElement->ElemID() ;
       
  4085 
       
  4086             // make sure that this is an animation element.
       
  4087             if( ((CSvgElementImpl*)lCurrentFocusElement)->IsAnimatedElement() )
       
  4088                 {
       
  4089                 // now we have to start the animations
       
  4090                 // get the current media time for the engine and set
       
  4091                 // the animations to begine at this time only.
       
  4092                 SvgBeginElementAt( (CXmlElementImpl*) lCurrentFocusElement , (TUint32)SvgGetMediaTime(aDocument), aDocument);
       
  4093 
       
  4094                 //dont need this anymore because it is done in begin element at now
       
  4095                 //CSvgAnimationBase*  lAnimationBasePtr = (CSvgAnimationBase*)lCurrentFocusElement;
       
  4096                 //lAnimationBasePtr->ReInitializeAnimation();
       
  4097                 }
       
  4098 
       
  4099             }
       
  4100         }
       
  4101 }
       
  4102 // --------------------------------------------------------------------------
       
  4103 // EXPORT_C CXmlElementImpl* CSvgEngineInterfaceImpl::SVGElementGetUsedElement(CXmlElementImpl* aElement)
       
  4104 // ---------------------------------------------------------------------------
       
  4105 EXPORT_C CXmlElementImpl* CSvgEngineInterfaceImpl::SVGElementGetUsedElement(CXmlElementImpl* aElement)
       
  4106 {
       
  4107     // this is for the reason that id's are not cloned.
       
  4108     // should there be a check for the element type for the parent element.
       
  4109     if(aElement && aElement->ParentNode())
       
  4110         {
       
  4111         if(aElement->OwnerDocument())
       
  4112             {
       
  4113             // get the xlink:href of the use element
       
  4114             TPtrC refElemId =  ( ((CSvgElementImpl*)(aElement->ParentNode()))->Href() );
       
  4115 
       
  4116             return (CXmlElementImpl*)((CSvgDocumentImpl*)(aElement->OwnerDocument()))->GetElementById(refElemId);
       
  4117             }
       
  4118         }
       
  4119     return 0;
       
  4120 
       
  4121 }
       
  4122 
       
  4123 // --------------------------------------------------------------------------
       
  4124 // EXPORT_C TBool CSvgEngineInterfaceImpl::IsRemoveable( CSvgElementImpl* hElement )
       
  4125 // ---------------------------------------------------------------------------
       
  4126 EXPORT_C TBool CSvgEngineInterfaceImpl::IsRemoveable( CSvgElementImpl* aElement, TBool aCheckSibling )
       
  4127 {
       
  4128     if ( !aElement )
       
  4129         {
       
  4130         return ETrue;
       
  4131         }
       
  4132 
       
  4133     if ( aElement->Id() )
       
  4134         {
       
  4135         return EFalse;
       
  4136         }
       
  4137 
       
  4138     CSvgElementImpl* child = (CSvgElementImpl*)aElement->FirstChild();
       
  4139     if ( !IsRemoveable( child, ETrue ) )
       
  4140         {
       
  4141         return EFalse;
       
  4142         }
       
  4143 
       
  4144     if (aCheckSibling)
       
  4145     {
       
  4146     	return IsRemoveable( (CSvgElementImpl*)aElement->NextSibling(), ETrue );
       
  4147 	}
       
  4148 
       
  4149 	return ETrue;
       
  4150 }
       
  4151 
       
  4152 // --------------------------------------------------------------------------
       
  4153 // EXPORT_C TBool CSvgEngineInterfaceImpl::IsElementActive( CSvgElementImpl* hElement )
       
  4154 // ---------------------------------------------------------------------------
       
  4155 EXPORT_C TBool CSvgEngineInterfaceImpl::IsElementActive( CSvgElementImpl* hElement )
       
  4156 {
       
  4157     if (hElement)
       
  4158     {
       
  4159         return  (hElement->IsAnimating());
       
  4160     }
       
  4161 
       
  4162     return EFalse;
       
  4163 }
       
  4164 
       
  4165 // --------------------------------------------------------------------------
       
  4166 // EXPORT_C void CSvgEngineInterfaceImpl::AddToEventReceiverList(CXmlElementImpl* aElement, const TUint8 aEventMask)
       
  4167 // ---------------------------------------------------------------------------
       
  4168 EXPORT_C void CSvgEngineInterfaceImpl::AddToEventReceiverList(CXmlElementImpl* aElement, const TUint8 aEventMask)
       
  4169 {
       
  4170     TRAPD(error,((CSvgDocumentImpl*)(aElement->OwnerDocument()))->AddToEventReceiverListL((CSvgElementImpl*)aElement, aEventMask));
       
  4171     if (error != KErrNone)
       
  4172         {
       
  4173         #ifdef _DEBUG
       
  4174         _LIT(KAddToEventReceiverListFailed,
       
  4175             "CSvgEngineInterfaceImpl::AddToEventReceiverList: AddToEventReceiverList error.");
       
  4176         RDebug::Print(KAddToEventReceiverListFailed);
       
  4177         #endif //_DEBUG
       
  4178         }
       
  4179 }
       
  4180 // --------------------------------------------------------------------------
       
  4181 // EXPORT_C void CSvgEngineInterfaceImpl::RemoveFromEventReceiverList(CXmlElementImpl* aElement)
       
  4182 // ---------------------------------------------------------------------------
       
  4183 EXPORT_C void CSvgEngineInterfaceImpl::RemoveFromEventReceiverList(CXmlElementImpl* aElement)
       
  4184 {
       
  4185     if ( aElement )
       
  4186     {
       
  4187         ((CSvgDocumentImpl*)(aElement->OwnerDocument()))->RemoveFromEventReceiverList((CSvgElementImpl*)aElement );
       
  4188     }
       
  4189 }
       
  4190 // --------------------------------------------------------------------------
       
  4191 // EXPORT_C int CSvgEngineInterfaceImpl::DispatchMouseEventsAt(CSvgDocumentImpl* aDocumentHandle, TInt aX, TInt aY)
       
  4192 // ---------------------------------------------------------------------------
       
  4193 EXPORT_C TInt CSvgEngineInterfaceImpl::DispatchMouseEventsAt(CSvgDocumentImpl* aDocumentHandle, TInt aX, TInt aY, MSvgMouseListener* aListener)
       
  4194 {
       
  4195     if(aDocumentHandle)
       
  4196     {
       
  4197         CSvgEngineImpl *lEngine= aDocumentHandle->Engine();
       
  4198 
       
  4199         TBool fakeEngine  = EFalse;
       
  4200 
       
  4201         if (!lEngine)
       
  4202         {
       
  4203         	fakeEngine  = ETrue;
       
  4204         	//no engine with the document pass in so use a fake one
       
  4205         	TRAPD(error, lEngine = SvgEngineNewL());
       
  4206         	if (error != KErrNone)
       
  4207         	{
       
  4208         		delete lEngine;
       
  4209         		return 0;
       
  4210         	}
       
  4211 
       
  4212         	if ( fakeEngine  && lEngine && aListener )
       
  4213             {
       
  4214             	lEngine->AddMouseListener( (MSvgMouseListener*)aListener );
       
  4215             }
       
  4216 
       
  4217    			aDocumentHandle->SetEngine(lEngine);
       
  4218    			lEngine->SetDocument(aDocumentHandle);
       
  4219         }
       
  4220 
       
  4221         TInt topSelectedElement  = 0;
       
  4222 
       
  4223         // Framework generates MouseDown,MouseMove and MouseUp
       
  4224         // The order needs to be maintained
       
  4225         topSelectedElement  = MouseDown( aX, aY, (TInt)lEngine);
       
  4226         MouseMove(aX, aY, (TInt)lEngine);
       
  4227         MouseUp(aX, aY, (TInt)lEngine);
       
  4228 
       
  4229 		//TSize lSize = ContentDimensions( (TInt)lEngine );
       
  4230 
       
  4231 		if (fakeEngine )
       
  4232 		{
       
  4233 			DestroyEngine(lEngine);
       
  4234 			aDocumentHandle->SetEngine(NULL) ;
       
  4235 		}
       
  4236 
       
  4237 		//this code was to make sure the click was on the screen, but this isn't the right way to do that
       
  4238 		//at all since the screen can be scaled but from negative coordinates...etc.
       
  4239 
       
  4240         //if ( (aX < lSize.iWidth) && (aX > 0 ) && (aY < lSize.iHeight) && (aY > 0))
       
  4241         //{
       
  4242              //really should return a handle to the element that was clicked here
       
  4243              return topSelectedElement ;
       
  4244         //}
       
  4245     }
       
  4246 
       
  4247     return 0;
       
  4248 }
       
  4249 
       
  4250 //Triggers the Focusin event for the SvgElement passed as a paramenter
       
  4251 EXPORT_C void CSvgEngineInterfaceImpl::DispatchFocusInEvent(CSvgDocumentImpl* aDocumentHandle,CSvgElementImpl *aElement)
       
  4252 {
       
  4253 	 if(aDocumentHandle)
       
  4254     	 {
       
  4255        	CSvgEngineImpl *lEngine = aDocumentHandle->Engine();
       
  4256 		TBool fakeEngine  = EFalse;
       
  4257 
       
  4258         	if (!lEngine)
       
  4259         	{
       
  4260 			lEngine = SvgEngineNewL() ;
       
  4261 		 	fakeEngine = ETrue ;
       
  4262 			//Set Engine for the document
       
  4263 			aDocumentHandle->SetEngine(lEngine );
       
  4264 	  		}
       
  4265        	//Set document Handle for the engine
       
  4266        	lEngine->SetDocument(aDocumentHandle);
       
  4267         //sets the focus as well as the mouse inside the element on which
       
  4268         //this function is called   	
       
  4269        	TGfxRectangle2D boundingBox;
       
  4270        	aElement->GetBBox( boundingBox );
       
  4271         MouseMove (boundingBox.CenterX() , boundingBox.CenterY());
       
  4272 
       
  4273 		if(fakeEngine)
       
  4274 		{
       
  4275 			DestroyEngine(lEngine) ;
       
  4276 			aDocumentHandle->SetEngine(NULL) ;
       
  4277 		}
       
  4278 	}
       
  4279 }
       
  4280 
       
  4281 //Triggers the Focusout event for the SvgElement passed as a paramenter
       
  4282 EXPORT_C void CSvgEngineInterfaceImpl::DispatchFocusOutEvent(CSvgDocumentImpl* aDocumentHandle,CSvgElementImpl* /*aElement */)
       
  4283 {
       
  4284 	 if(aDocumentHandle)
       
  4285     	 {
       
  4286        	CSvgEngineImpl *lEngine = aDocumentHandle->Engine();
       
  4287 		TBool fakeEngine  = EFalse;
       
  4288 
       
  4289         	if (!lEngine)
       
  4290         	{
       
  4291 			lEngine = SvgEngineNewL() ;
       
  4292 		 	fakeEngine = ETrue ;
       
  4293 			//Set Engine for the document
       
  4294 			aDocumentHandle->SetEngine(lEngine );
       
  4295 	  		}
       
  4296        	//Set document Handle for the engine
       
  4297        	lEngine->SetDocument(aDocumentHandle);
       
  4298 
       
  4299 		// Move the mouse outside the screen so that mouse is exitting
       
  4300 		// from all the elements in the DOM tree. 
       
  4301 		// After this, "focus out" internal event is generated by the 
       
  4302 		// element which is in focus. 
       
  4303 		MouseMove( KMINFLOATFIXVALUE, KMINFLOATFIXVALUE );
       
  4304 
       
  4305 		if(fakeEngine)
       
  4306 		{
       
  4307 			DestroyEngine(lEngine) ;
       
  4308 			aDocumentHandle->SetEngine(NULL) ;
       
  4309 		}
       
  4310 	}
       
  4311 }
       
  4312 
       
  4313 
       
  4314 // --------------------------------------------------------------------------
       
  4315 // EXPORT_C CGfxGeneralPath* CSvgEngineInterfaceImpl::SvgCreatePath()
       
  4316 // ---------------------------------------------------------------------------
       
  4317 EXPORT_C CGfxGeneralPath* CSvgEngineInterfaceImpl::SvgCreatePath()
       
  4318 {
       
  4319     CGfxGeneralPath* path = NULL;
       
  4320     TRAPD(error , path = CGfxGeneralPath::NewL());
       
  4321     if (error != KErrNone)
       
  4322         {
       
  4323         #ifdef _DEBUG
       
  4324         _LIT(KCreateCGfxGeneralPathFailed,
       
  4325             "CSvgEngineInterfaceImpl::SvgCreatePath: Can't create CGfxGeneralPath.");
       
  4326         RDebug::Print(KCreateCGfxGeneralPathFailed);
       
  4327         #endif //_DEBUG
       
  4328         }
       
  4329     return path;
       
  4330 }
       
  4331 // --------------------------------------------------------------------------
       
  4332 // EXPORT_C void CSvgEngineInterfaceImpl::SvgDestroyPath(CGfxGeneralPath* aPathHandle)
       
  4333 // ---------------------------------------------------------------------------
       
  4334 EXPORT_C void CSvgEngineInterfaceImpl::SvgDestroyPath(CGfxGeneralPath* aPathHandle)
       
  4335 {
       
  4336     if (aPathHandle)
       
  4337     {
       
  4338         delete aPathHandle;
       
  4339     }
       
  4340 }
       
  4341 // --------------------------------------------------------------------------
       
  4342 // EXPORT_C TInt CSvgEngineInterfaceImpl::GetSegmentCount(CGfxGeneralPath* aPathHandle)
       
  4343 // ---------------------------------------------------------------------------
       
  4344 EXPORT_C TInt CSvgEngineInterfaceImpl::GetSegmentCount(CGfxGeneralPath* aPathHandle)
       
  4345 {
       
  4346     if(aPathHandle)
       
  4347     {
       
  4348         return (aPathHandle)->GetSegmentCount();
       
  4349     }
       
  4350 
       
  4351     return 0;
       
  4352 }
       
  4353 // --------------------------------------------------------------------------
       
  4354 // EXPORT_C TInt CSvgEngineInterfaceImpl::GetSegmentType(CGfxGeneralPath* aPathHandle, TInt aSegmentIndex)
       
  4355 // ---------------------------------------------------------------------------
       
  4356 EXPORT_C TInt CSvgEngineInterfaceImpl::GetSegmentType(CGfxGeneralPath* aPathHandle, TInt aSegmentIndex)
       
  4357 {
       
  4358     if(aPathHandle)
       
  4359     {
       
  4360         return ( aPathHandle)->GetSegmentType(aSegmentIndex);
       
  4361     }
       
  4362 
       
  4363     return 0; // this should be verified that this is an error code.
       
  4364 }
       
  4365 // --------------------------------------------------------------------------
       
  4366 // EXPORT_C TReal32 CSvgEngineInterfaceImpl::GetSegmentParameter(CGfxGeneralPath* aPathHandle,TInt aSegmentIndex,TInt aSegmentParameterIndex)
       
  4367 // ---------------------------------------------------------------------------
       
  4368 EXPORT_C TReal32 CSvgEngineInterfaceImpl::GetSegmentParameter(CGfxGeneralPath* aPathHandle,TInt aSegmentIndex,TInt aSegmentParameterIndex) __SOFTFP
       
  4369 {
       
  4370 
       
  4371     if(aPathHandle)
       
  4372         {
       
  4373         return (aPathHandle)->GetSegmentParameter( aSegmentIndex,  aSegmentParameterIndex);
       
  4374         }
       
  4375     return 0; // this should be treated as error.
       
  4376 }
       
  4377 // --------------------------------------------------------------------------
       
  4378 // EXPORT_C void CSvgEngineInterfaceImpl::ADDMoveTo(CGfxGeneralPath* aPathHandle, TReal32 aX,TReal32 aY)
       
  4379 // ---------------------------------------------------------------------------
       
  4380 EXPORT_C void CSvgEngineInterfaceImpl::ADDMoveTo(CGfxGeneralPath* aPathHandle, TReal32 aX,TReal32 aY) __SOFTFP
       
  4381 {
       
  4382      if(aPathHandle)
       
  4383         {
       
  4384         TFloatFixPt lX = TFloatFixPt(aX);
       
  4385         TFloatFixPt lY = TFloatFixPt(aY);
       
  4386         TRAPD(error ,aPathHandle->MoveToL( lX, lY, ETrue));
       
  4387         if (error != KErrNone)
       
  4388             {
       
  4389             #ifdef _DEBUG
       
  4390             _LIT(KMoveToFailed,
       
  4391                 "CSvgEngineInterfaceImpl::ADDMoveTo: MoveToL error.");
       
  4392             RDebug::Print(KMoveToFailed);
       
  4393             #endif //_DEBUG
       
  4394             }
       
  4395         }
       
  4396 }
       
  4397 // --------------------------------------------------------------------------
       
  4398 // EXPORT_C void CSvgEngineInterfaceImpl::ADDLineTo(CGfxGeneralPath* aPathHandle,TReal32 aX,TReal32 aY)
       
  4399 // ---------------------------------------------------------------------------
       
  4400 EXPORT_C void CSvgEngineInterfaceImpl::ADDLineTo(CGfxGeneralPath* aPathHandle,TReal32 aX,TReal32 aY) __SOFTFP
       
  4401 {
       
  4402     if(aPathHandle)
       
  4403         {
       
  4404         TFloatFixPt lX = TFloatFixPt(aX);
       
  4405         TFloatFixPt lY = TFloatFixPt(aY);
       
  4406         TRAPD(error , aPathHandle->LineToL( lX, lY, ETrue));
       
  4407         if (error != KErrNone)
       
  4408             {
       
  4409             #ifdef _DEBUG
       
  4410             _LIT(KLineToLFailed,
       
  4411                 "CSvgEngineInterfaceImpl::ADDLineTo: LineToL error.");
       
  4412             RDebug::Print(KLineToLFailed);
       
  4413             #endif //_DEBUG
       
  4414             }
       
  4415         }
       
  4416 }
       
  4417 // --------------------------------------------------------------------------
       
  4418 // EXPORT_C void CSvgEngineInterfaceImpl::ADDQuadTo(CGfxGeneralPath* aPathHandle,TReal32 aX1,TReal32 aY1,TReal32 aX2,TReal32 aY2)
       
  4419 // ---------------------------------------------------------------------------
       
  4420 EXPORT_C void CSvgEngineInterfaceImpl::ADDQuadTo(CGfxGeneralPath* aPathHandle,TReal32 aX1,TReal32 aY1,TReal32 aX2,TReal32 aY2) __SOFTFP
       
  4421 {
       
  4422     if(aPathHandle)
       
  4423         {
       
  4424 
       
  4425         TFloatFixPt lX1 = TFloatFixPt(aX1);
       
  4426         TFloatFixPt lY1 = TFloatFixPt(aY1);
       
  4427         TFloatFixPt lX2 = TFloatFixPt(aX2);
       
  4428         TFloatFixPt lY2 = TFloatFixPt(aY2);
       
  4429         TRAPD(error ,aPathHandle->QuadToL( lX1, lY1, lX2, lY2, ETrue ));
       
  4430         if (error != KErrNone)
       
  4431             {
       
  4432             #ifdef _DEBUG
       
  4433             _LIT(KQuadToLLFailed,
       
  4434                 "CSvgEngineInterfaceImpl::ADDQuadTo: QuadToL error.");
       
  4435             RDebug::Print(KQuadToLLFailed);
       
  4436             #endif //_DEBUG
       
  4437             }
       
  4438         }
       
  4439 }
       
  4440 // --------------------------------------------------------------------------
       
  4441 // EXPORT_C void CSvgEngineInterfaceImpl::ADDCurveTo(CGfxGeneralPath* aPathHandle,TReal32 aX1,TReal32 aY1,TReal32 aX2,TReal32 aY2, TReal32 aX3, TReal32 aY3)
       
  4442 // ---------------------------------------------------------------------------
       
  4443 EXPORT_C void CSvgEngineInterfaceImpl::ADDCurveTo(CGfxGeneralPath* aPathHandle,TReal32 aX1,TReal32 aY1,TReal32 aX2,TReal32 aY2, TReal32 aX3, TReal32 aY3) __SOFTFP
       
  4444 {
       
  4445 
       
  4446     if(aPathHandle)
       
  4447         {
       
  4448 
       
  4449         TFloatFixPt lX1 = TFloatFixPt(aX1);
       
  4450         TFloatFixPt lY1 = TFloatFixPt(aY1);
       
  4451         TFloatFixPt lX2 = TFloatFixPt(aX2);
       
  4452         TFloatFixPt lY2 = TFloatFixPt(aY2);
       
  4453         TFloatFixPt lX3 = TFloatFixPt(aX3);
       
  4454         TFloatFixPt lY3 = TFloatFixPt(aY3);
       
  4455 
       
  4456         TRAPD(error ,aPathHandle->CubicToL( lX1,
       
  4457                                          lY1,
       
  4458                                          lX2,
       
  4459                                          lY2,
       
  4460                                          lX3,
       
  4461                                          lY3,
       
  4462                                          ETrue ));
       
  4463         if (error != KErrNone)
       
  4464             {
       
  4465             #ifdef _DEBUG
       
  4466             _LIT(KCubicToLFailed,
       
  4467                 "CSvgEngineInterfaceImpl::ADDCurveTo: CubicToL error.");
       
  4468             RDebug::Print(KCubicToLFailed);
       
  4469             #endif //_DEBUG
       
  4470             }
       
  4471         }
       
  4472 }
       
  4473 // --------------------------------------------------------------------------
       
  4474 // EXPORT_C void CSvgEngineInterfaceImpl::ADDCloseTo(CGfxGeneralPath* aPathHandle)
       
  4475 // ---------------------------------------------------------------------------
       
  4476 EXPORT_C void CSvgEngineInterfaceImpl::ADDCloseTo(CGfxGeneralPath* aPathHandle)
       
  4477 {
       
  4478     if(aPathHandle)
       
  4479         {
       
  4480         TRAPD(error ,aPathHandle->ClosePathL());
       
  4481         if (error != KErrNone)
       
  4482             {
       
  4483             #ifdef _DEBUG
       
  4484             _LIT(KClosePathLFailed,
       
  4485                 "CSvgEngineInterfaceImpl::ADDCloseTo: ClosePathL error.");
       
  4486             RDebug::Print(KClosePathLFailed);
       
  4487             #endif //_DEBUG
       
  4488             }
       
  4489         }
       
  4490 }
       
  4491 // --------------------------------------------------------------------------
       
  4492 // EXPORT_C CGfxGeneralPath* CSvgEngineInterfaceImpl::GetPathAttribute(CXmlElementImpl* aElementHandle, TInt aAttributeId)
       
  4493 // ---------------------------------------------------------------------------
       
  4494 EXPORT_C CGfxGeneralPath* CSvgEngineInterfaceImpl::GetPathAttribute(CXmlElementImpl* aElementHandle, TInt aAttributeId)
       
  4495 {
       
  4496     if(aElementHandle)
       
  4497         {
       
  4498 
       
  4499             CGfxGeneralPath* path =
       
  4500                 ((CSvgElementImpl*)aElementHandle)->GetPathAttribute(aAttributeId);
       
  4501 
       
  4502         if( path )
       
  4503             {
       
  4504             CGfxGeneralPath*  lClonePath = NULL;
       
  4505             TInt error = KErrNone;
       
  4506             TRAP(error,lClonePath = path->CloneL());
       
  4507             return lClonePath;
       
  4508             }
       
  4509 
       
  4510         }
       
  4511 
       
  4512         return NULL;
       
  4513 }
       
  4514 // --------------------------------------------------------------------------
       
  4515 // EXPORT_C void CSvgEngineInterfaceImpl::SetPathAttribute(CSvgElementImpl* aElementHandle, TInt lSvgAttrId, CGfxGeneralPath* aPathHandle)
       
  4516 // ---------------------------------------------------------------------------
       
  4517 EXPORT_C void CSvgEngineInterfaceImpl::SetPathAttribute(CSvgElementImpl* aElementHandle, TInt lSvgAttrId, CGfxGeneralPath* aPathHandle)
       
  4518 {
       
  4519     if(aElementHandle)
       
  4520         {
       
  4521         if(aPathHandle)
       
  4522             {
       
  4523             CGfxGeneralPath* clone = NULL;
       
  4524             TInt error = KErrNone;
       
  4525             TRAP(error,clone = aPathHandle->CloneL());
       
  4526             aElementHandle->SetPathAttribute(lSvgAttrId, clone);
       
  4527             }
       
  4528         }
       
  4529 }
       
  4530 
       
  4531 // --------------------------------------------------------------------------
       
  4532 // EXPORT_C TRect  CSvgEngineInterfaceImpl::GetSvgBoundingBox()
       
  4533 // ---------------------------------------------------------------------------
       
  4534 EXPORT_C TRect  CSvgEngineInterfaceImpl::GetSvgBoundingBox( TInt aEngine )
       
  4535 {
       
  4536     TRect lBBox(TSize(0,0));
       
  4537 
       
  4538     if( ChooseEngine(aEngine) )
       
  4539         {
       
  4540         if( iSvgEngine->Document() )
       
  4541             {
       
  4542             CSvgSvgElementImpl* lRoot = ( CSvgSvgElementImpl* )
       
  4543                                     iSvgEngine->Document()->RootElement();
       
  4544             if(lRoot)
       
  4545                 {
       
  4546                 TGfxRectangle2D     bbox;
       
  4547                 lRoot->GetBBox(bbox );
       
  4548 
       
  4549                 TInt lX = (TInt)bbox.iX;
       
  4550                 TInt lY = (TInt)bbox.iY;
       
  4551                 TInt lWidth = (TInt)bbox.iWidth;
       
  4552                 TInt lHeight = (TInt)bbox.iHeight;
       
  4553                 lBBox.SetRect(TPoint(lX,  lY),TSize(lWidth, lHeight));
       
  4554                 }
       
  4555 
       
  4556            }
       
  4557 
       
  4558     }
       
  4559     return lBBox;
       
  4560 }
       
  4561 
       
  4562 //---------------------------------------------------------------------------=
       
  4563 //Getting BoundingBox of Root Element
       
  4564 //---------------------------------------------------------------------------
       
  4565 EXPORT_C TSize CSvgEngineInterfaceImpl::GetUnscaledContentSize( TInt aDomHandle )
       
  4566     {
       
  4567     TSize size( 0, 0 );
       
  4568     if ( IsDomCached( aDomHandle ) )
       
  4569         {
       
  4570         CSvgDocumentImpl* document = (CSvgDocumentImpl*)aDomHandle;
       
  4571         CSvgSvgElementImpl* root = (CSvgSvgElementImpl*)document->RootElement();
       
  4572         if ( root )
       
  4573             {
       
  4574             TGfxRectangle2D bbox;
       
  4575             root->GetUnscaledBBox( bbox );
       
  4576             size.iWidth = (TInt)bbox.iWidth;
       
  4577             size.iHeight = (TInt)bbox.iHeight;
       
  4578             }
       
  4579         }
       
  4580     return size;
       
  4581     }
       
  4582 
       
  4583 // --------------------------------------------------------------------------
       
  4584 // EXPORT_C TBool CSvgEngineInterfaceImpl::IsElementVisible( TInt aElementHandle )
       
  4585 // ---------------------------------------------------------------------------
       
  4586 EXPORT_C TBool CSvgEngineInterfaceImpl::IsElementVisible( TInt aElementHandle, TInt aEngine )
       
  4587 {
       
  4588 	if (ChooseEngine( aEngine ))
       
  4589 	{
       
  4590 		return iSvgEngine->IsElementVisible( aElementHandle );
       
  4591 	}
       
  4592 	else
       
  4593 	{
       
  4594     	return EFalse;
       
  4595     }
       
  4596 }
       
  4597 
       
  4598 // --------------------------------------------------------------------------
       
  4599 // EXPORT_C void CSvgEngineInterfaceImpl::SetThumbNailMode( TBool aThumbNailMode )
       
  4600 // ---------------------------------------------------------------------------
       
  4601 EXPORT_C void CSvgEngineInterfaceImpl::SetThumbNailMode( TBool aThumbNailMode, TInt aEngine )
       
  4602 {
       
  4603     iIsThumbNailMode = aThumbNailMode;
       
  4604     if ( ChooseEngine(aEngine) && iSvgEngine->Document() )
       
  4605     {
       
  4606         iSvgEngine->Document()->SetThumbNailMode( aThumbNailMode );
       
  4607     }
       
  4608 }
       
  4609 
       
  4610 // --------------------------------------------------------------------------
       
  4611 // EXPORT_C void CSvgEngineInterfaceImpl::CustomOption( TBool aThumbNailMode )
       
  4612 // ---------------------------------------------------------------------------
       
  4613 EXPORT_C void CSvgEngineInterfaceImpl::CustomOption(TBool aCustomOption, TInt aEngine  )
       
  4614     {
       
  4615     if ( ChooseEngine(aEngine) )
       
  4616         {
       
  4617         iSvgEngine->CustomOption(aCustomOption);
       
  4618         }
       
  4619     }
       
  4620 
       
  4621 // --------------------------------------------------------------------------
       
  4622 // EXPORT_C TReal CSvgEngineInterfaceImpl::FramesPerSecond(TBool aShowOn)
       
  4623 // ---------------------------------------------------------------------------
       
  4624 EXPORT_C TReal CSvgEngineInterfaceImpl::FramesPerSecond(TBool aShowOn, TInt aEngine ) __SOFTFP
       
  4625     {
       
  4626 
       
  4627     //take the width in here..
       
  4628     CSvgDocumentImpl* doc = SvgDocument();
       
  4629 
       
  4630     if (aShowOn && ChooseEngine(aEngine) && iSvgEngine->Document() )
       
  4631     	{
       
  4632         TReal ret = 0.0;
       
  4633         TRAPD( error, ret = FramesPerSecondL() );
       
  4634         if ( error != KErrNone )
       
  4635         	{
       
  4636             RDebug::Printf("CSvgEngineInterfaceImpl::FramesPerSecond() Error in FramesPerSecondL");
       
  4637         	}
       
  4638 
       
  4639         return ret;
       
  4640     	}
       
  4641     else
       
  4642     	{
       
  4643     	_LIT(fps, "fps");
       
  4644         if (iSvgEngine && iSvgEngine->Document() && iSvgEngine->Document()->iPerfText && GetElementById(doc, fps))
       
  4645         	{
       
  4646             RemoveChild( (CXmlElementImpl*)iSvgEngine->Document()->RootElement(), (CXmlElementImpl*) iSvgEngine->Document()->iPerfText);
       
  4647             delete iSvgEngine->Document()->iPerfText;
       
  4648             iSvgEngine->Document()->iPerfText = NULL;
       
  4649         	}
       
  4650 
       
  4651         if ((iSvgEngine) && ( iSvgEngine->iTimer ))
       
  4652         	{
       
  4653             return (iSvgEngine->iTimer->Fps() / 10);
       
  4654         	}
       
  4655         else
       
  4656         	{
       
  4657             return 0;
       
  4658         	}
       
  4659     	}
       
  4660 	}
       
  4661 
       
  4662 // --------------------------------------------------------------------------
       
  4663 // TReal CSvgEngineInterfaceImpl::FramesPerSecondL()
       
  4664 // ---------------------------------------------------------------------------
       
  4665 TReal CSvgEngineInterfaceImpl::FramesPerSecondL( TInt aEngine )
       
  4666     {
       
  4667 
       
  4668     if (!ChooseEngine( aEngine ))
       
  4669 	{
       
  4670 	return 0;
       
  4671 	}
       
  4672 
       
  4673     CSvgDocumentImpl* doc = SvgDocument();
       
  4674 
       
  4675     TSize svgSize = ContentDimensions();
       
  4676     TBuf<10> fps;
       
  4677     _LIT(msg, "FPS: ");
       
  4678     _LIT(FPS, "fps");
       
  4679     fps.Append(msg);
       
  4680 
       
  4681     fps.AppendNum((iSvgEngine->iTimer->Fps() / 10));
       
  4682 
       
  4683     if (!iSvgEngine->Document()->iPerfText || !(GetElementById(doc, FPS)))
       
  4684     {
       
  4685         TRAPD(err, iSvgEngine->Document()->iPerfText = (CSvgElementImpl*)doc->CreateElementL(25));
       
  4686         if (err)
       
  4687             {
       
  4688             #ifdef _DEBUG
       
  4689             _LIT( KErrMsg, "CSvgEngineInterfaceImpl::FramesPerSecond() Error in CreateElementL" );
       
  4690             RDebug::Print(KErrMsg);
       
  4691             #endif //_DEBUG
       
  4692             }
       
  4693         AppendChild((CXmlElementImpl*)doc->RootElement(), (CXmlElementImpl*)iSvgEngine->Document()->iPerfText);
       
  4694     }
       
  4695 
       
  4696     const TGfxAffineTransform& tmtx  = ((CSvgSvgElementImpl* )iSvgEngine->Document()->RootElement())->GetCTM();
       
  4697     TGfxPoint2D whPt(svgSize.iWidth,svgSize.iHeight), whDstPt(1,1);
       
  4698     tmtx.Transform(&whPt,&whDstPt,1);
       
  4699 
       
  4700     //<text x="x" y ="y" font-family="verdana" font-size="6" fill= "grey">Testing 'text' element: </text>
       
  4701     iSvgEngine->Document()->iPerfText->SetAttributeDesL(KAtrCdata,fps);
       
  4702     iSvgEngine->Document()->iPerfText->SetAttributeDesL(KAtrId, FPS);
       
  4703     iSvgEngine->Document()->iPerfText->SetAttributeFloatL(KAtrX, (float)whDstPt.iX * (float).95);
       
  4704     iSvgEngine->Document()->iPerfText->SetAttributeFloatL(KAtrY, (float)whDstPt.iY * (float).05);
       
  4705     iSvgEngine->Document()->iPerfText->SetAttributeFloatL(KAtrWidth, ((float).05 * (float)whDstPt.iX));
       
  4706     iSvgEngine->Document()->iPerfText->SetAttributeFloatL(KAtrHeight,((float).05 * (float)whDstPt.iY));
       
  4707 
       
  4708     _LIT(RED, "red");
       
  4709     iSvgEngine->Document()->iPerfText->SetPropertyL( KCSS_ATTR_STROKE, RED);
       
  4710     iSvgEngine->Document()->iPerfText->SetPropertyL( KCSS_ATTR_FILL, RED);
       
  4711 
       
  4712     return (iSvgEngine->iTimer->Fps() / 10);
       
  4713     }
       
  4714 
       
  4715 //---------------------------------------------------------------------------=
       
  4716 ////debugging method to draw a rectangle on the screen
       
  4717 //---------------------------------------------------------------------------=
       
  4718 // --------------------------------------------------------------------------
       
  4719 // EXPORT_C CSvgElementImpl* CSvgEngineInterfaceImpl::DrawBox(TRect aRect)
       
  4720 // ---------------------------------------------------------------------------
       
  4721 EXPORT_C CSvgElementImpl* CSvgEngineInterfaceImpl::DrawBox(TRect aRect, TInt aEngine)
       
  4722 {
       
  4723 	if (!ChooseEngine( aEngine ))
       
  4724 	{
       
  4725 	return NULL;
       
  4726 	}
       
  4727 
       
  4728     CSvgElementImpl* lBox = NULL;
       
  4729     TRAPD(err, lBox = (CSvgElementImpl*)CreateElementL(SvgDocument(), KSvgRectElement));
       
  4730     if (err)
       
  4731         {
       
  4732         _LIT(msg1, "DrawBox error: ");
       
  4733         _LIT(msg2, "Can't create element");
       
  4734         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, err, msg1, msg2);
       
  4735         return lBox;
       
  4736         }
       
  4737 
       
  4738     AppendChild((CXmlElementImpl*)iSvgEngine->Document()->RootElement(), (CXmlElementImpl*)lBox);
       
  4739 
       
  4740     if (lBox)
       
  4741     {
       
  4742         //<rect fill="none" x="lBbox.iX" y="lBbox.iY" width="iBbox.iWidth" height="iBbox.iHeight" stroke="blue"/>
       
  4743         //fill
       
  4744         _LIT(NONE, "none");
       
  4745         TRAPD(err, lBox->SetPropertyL( KCSS_ATTR_FILL, NONE));
       
  4746         if (err)
       
  4747             {
       
  4748             #ifdef _DEBUG
       
  4749             _LIT( KErrMsg, "CSvgEngineInterfaceImpl::DrawBox) Error in SetPropertyL" );
       
  4750             RDebug::Print(KErrMsg);
       
  4751             #endif //_DEBUG
       
  4752             }
       
  4753 
       
  4754         //stroke
       
  4755         _LIT(BLUE, "blue");
       
  4756         TRAP(err, lBox->SetPropertyL( KCSS_ATTR_STROKE, BLUE));
       
  4757         if (err)
       
  4758             {
       
  4759             #ifdef _DEBUG
       
  4760             _LIT( KErrMsg, "CSvgEngineInterfaceImpl::DrawBox) Error in SetPropertyL" );
       
  4761             RDebug::Print(KErrMsg);
       
  4762             #endif //_DEBUG
       
  4763             }
       
  4764 
       
  4765         //x
       
  4766         TRAP(err, lBox->SetAttributeFloatL( KAtrX, ((TFloatFixPt)(float) aRect.iTl.iX)));
       
  4767         if (err)
       
  4768             {
       
  4769             #ifdef _DEBUG
       
  4770             _LIT( KErrMsg, "CSvgEngineInterfaceImpl::DrawBox) Error in SetPropertyL" );
       
  4771             RDebug::Print(KErrMsg);
       
  4772             #endif //_DEBUG
       
  4773             }
       
  4774 
       
  4775         //y
       
  4776         TRAP(err, lBox->SetAttributeFloatL( KAtrY, ((TFloatFixPt)(float) aRect.iTl.iY)));
       
  4777         if (err)
       
  4778             {
       
  4779             #ifdef _DEBUG
       
  4780             _LIT( KErrMsg, "CSvgEngineInterfaceImpl::DrawBox) Error in SetPropertyL" );
       
  4781             RDebug::Print(KErrMsg);
       
  4782             #endif //_DEBUG
       
  4783             }
       
  4784 
       
  4785         //width
       
  4786         TRAP(err, lBox->SetAttributeFloatL( KAtrWidth, ((TFloatFixPt)(float) aRect.Width())));
       
  4787         if (err)
       
  4788             {
       
  4789             #ifdef _DEBUG
       
  4790             _LIT( KErrMsg, "CSvgEngineInterfaceImpl::DrawBox) Error in SetPropertyL" );
       
  4791             RDebug::Print(KErrMsg);
       
  4792             #endif //_DEBUG
       
  4793             }
       
  4794         //height
       
  4795         TRAP(err, lBox->SetAttributeFloatL( KAtrHeight, ((TFloatFixPt)(float) aRect.Height())));
       
  4796         if (err)
       
  4797             {
       
  4798             #ifdef _DEBUG
       
  4799             _LIT( KErrMsg, "CSvgEngineInterfaceImpl::DrawBox) Error in SetPropertyL" );
       
  4800             RDebug::Print(KErrMsg);
       
  4801             #endif //_DEBUG
       
  4802             }
       
  4803     }
       
  4804 
       
  4805     return lBox;
       
  4806 }
       
  4807 
       
  4808 //---------------------------------------------------------------------------=
       
  4809 //Returns array of pointers to all elements of a certain type or all elements if aElementId = -1
       
  4810 //---------------------------------------------------------------------------=
       
  4811 // --------------------------------------------------------------------------
       
  4812 // EXPORT_C void CSvgEngineInterfaceImpl::FindAllElements( CSvgElementImpl* aStartElement, TInt aElementId,
       
  4813 // ---------------------------------------------------------------------------
       
  4814 EXPORT_C void CSvgEngineInterfaceImpl::FindAllElements( CSvgElementImpl* aStartElement, TInt aElementId,
       
  4815                                       RPointerArray<CSvgElementImpl>& aList, TInt aEngine )
       
  4816 {
       
  4817     if ( ChooseEngine(aEngine) && iSvgEngine->Document())
       
  4818     {
       
  4819         iSvgEngine->Document()->FindAllElements(aStartElement, aElementId, aList);
       
  4820     }
       
  4821 }
       
  4822 
       
  4823 //---------------------------------------------------------------------------=
       
  4824 ////DOM Element Traversal
       
  4825 //---------------------------------------------------------------------------=
       
  4826 
       
  4827 //---------------------------------------------------------------------------=
       
  4828 //Returns the first child element node of this element. null if this element has no child elements.
       
  4829 //---------------------------------------------------------------------------=
       
  4830 CSvgElementImpl* CSvgEngineInterfaceImpl::FirstElementChild(CSvgElementImpl* aParentElement)
       
  4831 {
       
  4832     if ( aParentElement )
       
  4833     {
       
  4834         return (CSvgElementImpl*)aParentElement->FirstChild();
       
  4835     }
       
  4836 
       
  4837     return NULL;
       
  4838 }
       
  4839 
       
  4840 //---------------------------------------------------------------------------=
       
  4841 //last child element node of this element. null if this element has no child elements.
       
  4842 //---------------------------------------------------------------------------=
       
  4843 CSvgElementImpl* CSvgEngineInterfaceImpl::LastElementChild(CSvgElementImpl* aParentElement)
       
  4844 {
       
  4845     if ( aParentElement )
       
  4846     {
       
  4847         return (CSvgElementImpl*)aParentElement->LastChild();
       
  4848     }
       
  4849 
       
  4850     return NULL;
       
  4851 
       
  4852 }
       
  4853 
       
  4854 //---------------------------------------------------------------------------=
       
  4855 //Returns the next sibling element node of this element. null if this element has no element sibling nodes that come after this one in the document tree.
       
  4856 //---------------------------------------------------------------------------=
       
  4857 CSvgElementImpl* CSvgEngineInterfaceImpl::PreviousElementSibling(CSvgElementImpl* aSiblingElement)
       
  4858 {
       
  4859     if ( aSiblingElement )
       
  4860     {
       
  4861         return (CSvgElementImpl*)aSiblingElement->PreviousSibling();
       
  4862     }
       
  4863 
       
  4864     return NULL;
       
  4865 }
       
  4866 
       
  4867 //---------------------------------------------------------------------------=
       
  4868 //previous sibling element node of this element. null if this element has no element sibling nodes that come before this one in the document tree.
       
  4869 //---------------------------------------------------------------------------=
       
  4870 CSvgElementImpl* CSvgEngineInterfaceImpl::NextElementSibling(CSvgElementImpl* aSiblingElement)
       
  4871 {
       
  4872     if ( aSiblingElement )
       
  4873     {
       
  4874         return (CSvgElementImpl*)aSiblingElement->NextSibling();
       
  4875     }
       
  4876 
       
  4877     return NULL;
       
  4878 }
       
  4879 
       
  4880 
       
  4881 //---------------------------------------------------------------------------=
       
  4882 // Precondition: bitmap A & B has same dimension and display mode.
       
  4883 // Return ETrue if both bitmaps are the same, bit for bit.
       
  4884 // Used by RenderFrames
       
  4885 //---------------------------------------------------------------------------=
       
  4886 TBool CSvgEngineInterfaceImpl::AreBitmapsTheSame( CFbsBitmap& aBitmapA, CFbsBitmap& aBitmapB )
       
  4887 {
       
  4888 
       
  4889     TInt bitsPerPixel = TDisplayModeUtils::NumDisplayModeBitsPerPixel( aBitmapA.DisplayMode() );
       
  4890     TSize size = aBitmapA.SizeInPixels();
       
  4891 
       
  4892     // Number of bytes of each scan line
       
  4893     // This is aligned to a 4 byte(DWORD) boundary for performance reasons.
       
  4894     TInt scanLineLength = CFbsBitmap::ScanLineLength( size.iWidth, aBitmapA.DisplayMode() );
       
  4895 
       
  4896     aBitmapA.LockHeap();
       
  4897     aBitmapB.LockHeap();
       
  4898     TUint32* dataA = aBitmapA.DataAddress();
       
  4899     TUint32* dataB = aBitmapB.DataAddress();
       
  4900     aBitmapA.UnlockHeap();
       
  4901     aBitmapB.UnlockHeap();
       
  4902     TInt dwords = scanLineLength / 4;
       
  4903     TInt bytesLeftOver = scanLineLength - ( 4 * dwords );
       
  4904 
       
  4905 	TInt sizeHeight = size.iHeight;
       
  4906 	for ( TInt y = 0; y < sizeHeight; y++ )
       
  4907     {
       
  4908         // compare 4 bytes are at time
       
  4909         TInt i = 0;
       
  4910         for ( ; i < dwords; i++ )
       
  4911             if ( dataA[i] != dataB[i] )
       
  4912                 return EFalse;
       
  4913 
       
  4914         // compare left over bytes
       
  4915         if ( bytesLeftOver > 0 )
       
  4916         {
       
  4917             TUint8* bytesA = (TUint8*)dataA[i];
       
  4918             TUint8* bytesB = (TUint8*)dataB[i];
       
  4919             for ( TInt k = 0; k < bytesLeftOver; k++ )
       
  4920                 if ( bytesA[k] != bytesB[k] )
       
  4921                     return EFalse;
       
  4922             // next scanline
       
  4923             dataA = &dataA[dwords+1];
       
  4924             dataB = &dataB[dwords+1];
       
  4925         }
       
  4926         else
       
  4927         {
       
  4928             // next scanline
       
  4929             dataA = &dataA[dwords];
       
  4930             dataB = &dataB[dwords];
       
  4931         }
       
  4932     }
       
  4933     return ETrue;
       
  4934 }
       
  4935 
       
  4936 //---------------------------------------------------------------------------=
       
  4937 // Create a bitmap with the specified size, colormode.
       
  4938 // Used by RenderFrames
       
  4939 //---------------------------------------------------------------------------=
       
  4940 CFbsBitmap* CSvgEngineInterfaceImpl::CreateBitmapL( TSize aSize, TDisplayMode aColorMode,
       
  4941                                                    CSvgErrorImpl& aError )
       
  4942 {
       
  4943     CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
       
  4944     CleanupStack::PushL(bitmap);
       
  4945 
       
  4946     User::LeaveIfError( bitmap->Create( aSize, aColorMode ));
       
  4947 
       
  4948     CleanupStack::Pop(); // bitmap
       
  4949 
       
  4950     aError.SetErrorCode( ESvgNoError );
       
  4951     return bitmap;
       
  4952 }
       
  4953 
       
  4954 //---------------------------------------------------------------------------=
       
  4955 // Generate animation frames
       
  4956 //---------------------------------------------------------------------------=
       
  4957 
       
  4958 EXPORT_C MSvgError* CSvgEngineInterfaceImpl::RenderFrames(
       
  4959                                   TInt aDomHandle,
       
  4960                                   const TSize& aDimensionOfBitmaps,
       
  4961                                   TUint aStartTime,
       
  4962                                   TUint aDuration,
       
  4963                                   TUint aMillisecondsPerFrame,
       
  4964                                   TDisplayMode aColorDepth,
       
  4965                                   TDisplayMode aMaskType,
       
  4966                                   RPointerArray<CFbsBitmap>& aBitmapFrames,
       
  4967                                   RPointerArray<CFbsBitmap>& aMaskFrames,
       
  4968                                   RArray<TUint>& aDelayIntervals,
       
  4969                                   TBool aRemoveRedundantFrames )
       
  4970 {
       
  4971     iSvgError->SetErrorCode( ESvgNoError );
       
  4972 
       
  4973     //-----------------------------------------------------
       
  4974     // Validate parameters
       
  4975     //-----------------------------------------------------
       
  4976     if ( aDimensionOfBitmaps.iWidth < 1 || aDimensionOfBitmaps.iHeight < 1 )
       
  4977         {
       
  4978         TBuf<100> buf;
       
  4979         buf.AppendNum( aDimensionOfBitmaps.iWidth );
       
  4980         _LIT(X, "x");
       
  4981         buf.Append( X );
       
  4982         buf.AppendNum( aDimensionOfBitmaps.iHeight );
       
  4983         _LIT(msg, "RenderFrames: Invalid bitmap dimensions: ");
       
  4984         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, KErrNone, msg, buf );
       
  4985         return iSvgError;
       
  4986         }
       
  4987     if ( aMillisecondsPerFrame == 0 )
       
  4988         {
       
  4989         _LIT(msg1, "RenderFrames: Invalid delay per frame: 0");
       
  4990         _LIT(msg2, "");
       
  4991         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, KErrNone, msg1, msg2);
       
  4992         return iSvgError;
       
  4993         }
       
  4994     if ( !( aMaskType == EGray2 || aMaskType == EGray256 ) )
       
  4995         {
       
  4996         _LIT(msg1, "RenderFrames: Unsupported Mask Type.");
       
  4997         _LIT(msg2, "Must be EGray2 or EGray256");
       
  4998         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, KErrNone, msg1, msg2);
       
  4999         return iSvgError;
       
  5000         }
       
  5001 
       
  5002     if ( !IsDomCached( aDomHandle ) )
       
  5003         {
       
  5004         _LIT(msg1, "RenderFrames: Invalid Dom Handle.");
       
  5005         _LIT(msg2, "");
       
  5006         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, KErrNone, msg1, msg2);
       
  5007         return iSvgError;
       
  5008         }
       
  5009 
       
  5010     // Create separate svg engine for operation, leaving intact
       
  5011     // default engine.
       
  5012     CSvgEngineImpl* svgEngine = NULL;
       
  5013     TRAPD( engineError, svgEngine = CSvgEngineImpl::NewL( iSvgEngine->iFrameBuffer,
       
  5014                                                           iSvgEngine->iRequestObserver,
       
  5015                                                           iSvgEngine->iBitmapFontSpec, iSvgBitmapFontProvider ) );
       
  5016     CleanupStack::PushL(svgEngine);                                                      
       
  5017     if ( engineError != KErrNone )
       
  5018         {
       
  5019         _LIT(msg1, "RenderFrames: Failed to instantiate SvgEngine.");
       
  5020         _LIT(msg2, "");
       
  5021         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, engineError, msg1, msg2);
       
  5022         return iSvgError;
       
  5023         }
       
  5024 	svgEngine->SetBackgroundColor(KBackgroundColor);
       
  5025     // Initialize engine with document
       
  5026     CSvgDocumentImpl* document = (CSvgDocumentImpl*)aDomHandle;
       
  5027     
       
  5028 	if(!document)
       
  5029 	   {
       
  5030         _LIT(msg1, "RenderFrames: Failed to get document.");
       
  5031         _LIT(msg2, "");
       
  5032         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgDocumentNotAvailable, KErrUnknown, msg1, msg2);
       
  5033         return iSvgError;
       
  5034         }
       
  5035 		
       
  5036     // Before changing the engine, if the current engine is valid
       
  5037     // and it is pointing to this document set the engine's document to NULL
       
  5038     if (document->Engine() )
       
  5039         {
       
  5040         CSvgEngineImpl* lCurEngine = document->Engine();
       
  5041         lCurEngine->SetDocument( NULL );
       
  5042         }
       
  5043 	
       
  5044         
       
  5045     svgEngine->SetDocument( document );
       
  5046     document->SetEngine( svgEngine );
       
  5047 
       
  5048     svgEngine->SetIgnoreUpdateScreen( ETrue );
       
  5049 
       
  5050     // Flag to indicate content is an animation
       
  5051     TBool isAnimationContent = SvgHasAnimation( document );
       
  5052 
       
  5053     CFbsBitmap* bitmap = NULL;
       
  5054     TBool usePreviousBitmap = EFalse;
       
  5055     TBool engineInitialized = EFalse;
       
  5056 
       
  5057     for ( TUint time = 0; time <= aDuration; time += aMillisecondsPerFrame )
       
  5058         {
       
  5059         //-----------------------------------------------------
       
  5060         // Create bitmap if needed
       
  5061         //-----------------------------------------------------
       
  5062         if ( !usePreviousBitmap )
       
  5063             {
       
  5064             TRAPD(err, bitmap = CreateBitmapL( aDimensionOfBitmaps,
       
  5065                 aColorDepth, *iSvgError ));
       
  5066             if ( err != KErrNone )
       
  5067                 {
       
  5068                 _LIT(msg1, "RenderFrames: Failed to create bitmap.");
       
  5069                 _LIT(msg2, "");
       
  5070                 CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, engineError, msg1, msg2);
       
  5071                 break;
       
  5072                 }
       
  5073             //-----------------------------------------------------
       
  5074             // Set the bitmap to render with the dom
       
  5075             //-----------------------------------------------------
       
  5076             TRAPD( setGdiError, svgEngine->SetGdiContextL( bitmap ) );
       
  5077             if ( setGdiError != KErrNone )
       
  5078                {
       
  5079                // Delete the bitmap
       
  5080                delete bitmap;
       
  5081                bitmap = NULL;
       
  5082                
       
  5083                CleanupStack::PopAndDestroy(svgEngine);
       
  5084                 
       
  5085                if ( setGdiError == KErrNoMemory )
       
  5086                   {
       
  5087                   _LIT(msg1, "RenderFrames: Set Bitmap to SVG Engine failed.");
       
  5088                   _LIT(msg2, "");
       
  5089                   CSvgDocumentImpl::PrepareError( *iSvgError, ESvgNoMemory, setGdiError, msg1, msg2);
       
  5090                   return iSvgError;
       
  5091                   }
       
  5092                   
       
  5093                 _LIT(msg1, "RenderFrames: Set Bitmap to SVG Engine failed.");
       
  5094                 _LIT(msg2, "");
       
  5095                 CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, setGdiError, msg1, msg2);
       
  5096                 return iSvgError;
       
  5097                 }
       
  5098             // Need to initialize after new bitmap is set
       
  5099             // for engine to set viewbox, etc.
       
  5100             if ( !engineInitialized )
       
  5101                 {
       
  5102                 TRAPD( initError, svgEngine->InitializeEngineL() );
       
  5103                 if ( initError != KErrNone )
       
  5104                     {
       
  5105                     _LIT(msg1, "RenderFrames: Initializing Svg Engine failed.");
       
  5106                     _LIT(msg2, "");
       
  5107                     CSvgDocumentImpl::PrepareError(
       
  5108                         *iSvgError, ESvgUnknown, initError, msg1, msg2);
       
  5109                     break;
       
  5110                     }
       
  5111                 engineInitialized = ETrue;
       
  5112                 }
       
  5113             }
       
  5114 
       
  5115         //-----------------------------------------------------
       
  5116         // draw to bitmap
       
  5117         //-----------------------------------------------------
       
  5118         TSvgTimerEvent timeEvent( aStartTime + time );
       
  5119         TRAPD( renderError, svgEngine->ProcessEventL( 
       
  5120             document, &timeEvent ) );
       
  5121         if ( renderError != KErrNone )
       
  5122             {
       
  5123             _LIT(msg1, "RenderFrames: Rendering image failed.");
       
  5124             _LIT(msg2, "");
       
  5125             CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, renderError,msg1, msg2);
       
  5126             break;
       
  5127             }
       
  5128         //-----------------------------------------------------
       
  5129         // compare new bitmap with previous bitmap to combine delay time
       
  5130         // if images are the same
       
  5131         //-----------------------------------------------------
       
  5132         usePreviousBitmap = aRemoveRedundantFrames &&
       
  5133                             ( aBitmapFrames.Count() > 0 ) &&
       
  5134                             AreBitmapsTheSame( *bitmap, *aBitmapFrames[aBitmapFrames.Count()-1] );
       
  5135 
       
  5136         //-----------------------------------------------------
       
  5137         // Use previous bitmap: add delay time
       
  5138         //-----------------------------------------------------
       
  5139         if ( usePreviousBitmap )
       
  5140             {
       
  5141             TInt index = aDelayIntervals.Count() - 1;
       
  5142             aDelayIntervals[index] += aMillisecondsPerFrame;
       
  5143             // In case this is the very last frame and it's the same with previous frame,
       
  5144             // then destroy it
       
  5145             if ( time + aMillisecondsPerFrame > aDuration )
       
  5146                 {
       
  5147                 delete bitmap;
       
  5148                 bitmap = NULL;
       
  5149                 }
       
  5150             continue;
       
  5151             }
       
  5152         //-----------------------------------------------------
       
  5153         // add new bitmap to array: bitmap is different than previous
       
  5154         //-----------------------------------------------------
       
  5155         TInt bitmapAppendError = aBitmapFrames.Append( bitmap );
       
  5156         if ( bitmapAppendError != KErrNone )
       
  5157             {
       
  5158             _LIT(msg1, "RenderFrames: Failed to append new bitmap to frames.");
       
  5159             _LIT(msg2, "");
       
  5160             CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, bitmapAppendError, msg1, msg2);
       
  5161             break;
       
  5162             }
       
  5163 
       
  5164         // Set the bitmap NULL as the ownership is transferred to
       
  5165         // aBitmapFrames
       
  5166         bitmap = NULL;
       
  5167 
       
  5168         //-----------------------------------------------------
       
  5169         // Render mask
       
  5170         //-----------------------------------------------------
       
  5171         // Create Mask
       
  5172         CFbsBitmap* maskBitmap = NULL;
       
  5173         TRAPD( err, maskBitmap = CreateBitmapL( aDimensionOfBitmaps, aMaskType, *iSvgError ));
       
  5174         if ( err != KErrNone || maskBitmap == NULL )
       
  5175             {
       
  5176             break;
       
  5177             }
       
  5178         GenerateMask( maskBitmap );
       
  5179         TInt appendMaskError = aMaskFrames.Append( maskBitmap );
       
  5180         if ( appendMaskError != KErrNone )
       
  5181             {
       
  5182             _LIT(msg1, "RenderFrames: Failed to append new mask to mask frames.");
       
  5183             _LIT(msg2, "");
       
  5184             CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, appendMaskError, msg1, msg2);
       
  5185             delete maskBitmap;
       
  5186             break;
       
  5187             }
       
  5188 
       
  5189         // Set the mask NULL as the ownership is transferred to
       
  5190         // aMaskFrames
       
  5191         maskBitmap = NULL;
       
  5192 
       
  5193         //-----------------------------------------------------
       
  5194         // Append delay interval
       
  5195         //-----------------------------------------------------
       
  5196         TUint delay = ( aDuration - time < aMillisecondsPerFrame ) ?
       
  5197                       aDuration - time : aMillisecondsPerFrame;
       
  5198         TInt appendIntervalError = aDelayIntervals.Append( delay );
       
  5199         if ( appendIntervalError != KErrNone )
       
  5200             {
       
  5201             _LIT(msg1, "RenderFrames: Failed to append delay interval to list.");
       
  5202             _LIT(msg2, "");
       
  5203             CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, appendIntervalError,msg1, msg2);
       
  5204             break;
       
  5205             }
       
  5206 
       
  5207         // Only process one frame for non-animation content
       
  5208         if ( !isAnimationContent )
       
  5209             {
       
  5210             // Set the duration for the whole frame for non-animation
       
  5211             if ( aDelayIntervals.Count() > 0 )
       
  5212                 {
       
  5213                 aDelayIntervals[0] = aDuration;
       
  5214                 }
       
  5215             break;
       
  5216             }
       
  5217         }
       
  5218     // Cleanup the bitmap
       
  5219     delete bitmap;
       
  5220     //remove engine from document it is attached to
       
  5221     document->SetEngine( NULL );
       
  5222     // Delete  the engine
       
  5223     iSvgDocumentPointers.ResetAndDestroy();
       
  5224     iSvgDocumentPointers.Close();
       
  5225     CleanupStack::PopAndDestroy(svgEngine);
       
  5226     return iSvgError;
       
  5227     }
       
  5228 
       
  5229 // --------------------------------------------------------------------------
       
  5230 // EXPORT_C void CSvgEngineInterfaceImpl::AddListener( 
       
  5231 //  const MSvgListener* aListener, 
       
  5232 //  TSvgListenerType aType )
       
  5233 // ---------------------------------------------------------------------------
       
  5234 EXPORT_C void CSvgEngineInterfaceImpl::AddListener( 
       
  5235         const MSvgListener* aListener, 
       
  5236         TSvgListenerType aType, 
       
  5237         TInt aEngine )
       
  5238     {
       
  5239     if ( aListener == NULL )
       
  5240         {
       
  5241         return;
       
  5242         }
       
  5243 
       
  5244 	ChooseEngine( aEngine );
       
  5245     
       
  5246     TInt index = 0;
       
  5247     // Loading listeners
       
  5248     switch( aType )
       
  5249         {
       
  5250         case ESvgLoadingListener:
       
  5251             index = iSvgLoadingListeners.Find( 
       
  5252                     (MSvgLoadingListener*)aListener );
       
  5253             if (  index == KErrNotFound )
       
  5254                 {
       
  5255                 iSvgLoadingListeners.Append( (MSvgLoadingListener*)aListener );
       
  5256                 }
       
  5257                 break;
       
  5258         // Mouse listeners
       
  5259         case ESvgMouseListener:
       
  5260             if ( iSvgEngine != NULL )
       
  5261                 {
       
  5262                 iSvgEngine->AddMouseListener( (MSvgMouseListener*)aListener );
       
  5263                 }
       
  5264             break;
       
  5265         case ESvgTextAreaListener:
       
  5266             if ( iSvgEngine != NULL )
       
  5267                 {
       
  5268                 iSvgEngine->AddTextAreaListener( 
       
  5269                         (MSvgTextAreaListener*)aListener );
       
  5270                 }
       
  5271             break;
       
  5272         case ESvgTextListener:
       
  5273             if ( iSvgEngine != NULL )
       
  5274                 {
       
  5275                 iSvgEngine->AddTextListener( (MSvgTextListener*)aListener );
       
  5276                 }
       
  5277             break;
       
  5278         case ESvgViewPortListener:
       
  5279             if ( iSvgEngine != NULL )
       
  5280                 {
       
  5281                 iSvgEngine->AddViewPortListener( 
       
  5282                         (MSvgViewPortListener*)aListener );
       
  5283                 }
       
  5284             break;
       
  5285         case ESvgInteractiveElementListener:
       
  5286             if ( iSvgEngine != NULL )
       
  5287                 {
       
  5288                 iSvgEngine->AddInteractiveElementListener( 
       
  5289                         (MSvgInteractiveElementListener*)aListener );
       
  5290                 }
       
  5291             break;
       
  5292         
       
  5293         
       
  5294         default:
       
  5295             break;
       
  5296         }
       
  5297     }
       
  5298 // --------------------------------------------------------------------------
       
  5299 // EXPORT_C void CSvgEngineInterfaceImpl::RemoveListener( const MSvgListener* aListener, TSvgListenerType aType )
       
  5300 // ---------------------------------------------------------------------------
       
  5301 EXPORT_C void CSvgEngineInterfaceImpl::RemoveListener( const MSvgListener* aListener, TSvgListenerType aType, TInt aEngine )
       
  5302     {
       
  5303 
       
  5304     ChooseEngine(aEngine);
       
  5305 
       
  5306     // Loading listeners
       
  5307     if ( aType == ESvgLoadingListener )
       
  5308         {
       
  5309         TInt index = iSvgLoadingListeners.Find( (MSvgLoadingListener*)aListener );
       
  5310         if ( index != KErrNotFound )
       
  5311             {
       
  5312             iSvgLoadingListeners.Remove( index );
       
  5313             }
       
  5314         }
       
  5315     // Mouse listeners
       
  5316     else if ( aType == ESvgMouseListener )
       
  5317         {
       
  5318             if ( iSvgEngine != NULL )
       
  5319             {
       
  5320                 iSvgEngine->RemoveMouseListener( (MSvgMouseListener*)aListener );
       
  5321             }
       
  5322         }
       
  5323     // Text area listeners
       
  5324     else if ( aType == ESvgTextAreaListener )
       
  5325         {
       
  5326             if ( iSvgEngine != NULL )
       
  5327             {
       
  5328                 iSvgEngine->RemoveTextAreaListener( (MSvgTextAreaListener*)aListener );
       
  5329             }
       
  5330         }
       
  5331     else if ( aType == ESvgTextListener )
       
  5332         {
       
  5333             if ( iSvgEngine != NULL )
       
  5334             {
       
  5335                 iSvgEngine->RemoveTextListener( (MSvgTextListener*)aListener );
       
  5336             }
       
  5337 
       
  5338         }
       
  5339     else if ( aType == ESvgInteractiveElementListener )
       
  5340         {
       
  5341         if ( iSvgEngine != NULL )
       
  5342             {
       
  5343             iSvgEngine->RemoveInteractiveElementListener( (MSvgInteractiveElementListener*)aListener );
       
  5344             }
       
  5345          }
       
  5346     }
       
  5347 // --------------------------------------------------------------------------
       
  5348 // EXPORT_C void CSvgEngineInterfaceImpl::InitSvgStylePropertiesWithNullL( CSvgElementImpl* aElement )
       
  5349 // ---------------------------------------------------------------------------
       
  5350 EXPORT_C void CSvgEngineInterfaceImpl::InitSvgStylePropertiesWithNullL( CSvgElementImpl* aElement )
       
  5351 {
       
  5352     if ( aElement )
       
  5353     {
       
  5354         aElement->InitSvgStylePropertiesWithNullL();
       
  5355     }
       
  5356 }
       
  5357 
       
  5358 //---------------------------------------------------------------------------=
       
  5359 // Initialize engine with <svg> information in attached document.
       
  5360 //---------------------------------------------------------------------------=
       
  5361 EXPORT_C void CSvgEngineInterfaceImpl::InitializeEngine(
       
  5362                                        CSvgEngineImpl* aEngine,
       
  5363                                        TBool /*aIsMainThread*/ )
       
  5364     {
       
  5365         if ( ChooseEngine( (TInt)aEngine ) )
       
  5366         {
       
  5367 
       
  5368         	TRAPD( error, iSvgEngine->InitializeEngineL() );
       
  5369         	if ( error != KErrNone )
       
  5370             {
       
  5371             	return;
       
  5372             }
       
  5373 
       
  5374         	iSvgEngine->SetMediaTime( 0 );
       
  5375         	// pause is so progressive parsing doesnt animate
       
  5376         	// before everything is there. This could be removed to
       
  5377         	// load and animate on the fly
       
  5378         	iSvgEngine->SetSVGEngineState( ESVGEnginePaused );
       
  5379 
       
  5380     	}
       
  5381     }
       
  5382 
       
  5383 // --------------------------------------------------------------------------
       
  5384 // EXPORT_C void CSvgEngineInterfaceImpl::SetDataRetrievalTimeOut( TUint aTimeoutSeconds )
       
  5385 // ---------------------------------------------------------------------------
       
  5386 EXPORT_C void CSvgEngineInterfaceImpl::SetDataRetrievalTimeOut( TUint /*aTimeoutSeconds*/, TInt /*aEngine*/ )
       
  5387 {
       
  5388 // Function is no more required
       
  5389 }
       
  5390 
       
  5391 // --------------------------------------------------------------------------
       
  5392 // EXPORT_C void CSvgEngineInterfaceImpl::CancelLoad()
       
  5393 // ---------------------------------------------------------------------------
       
  5394 EXPORT_C void CSvgEngineInterfaceImpl::CancelLoad( TInt aEngine )
       
  5395     {
       
  5396     	if ( ChooseEngine(aEngine) )
       
  5397     	{
       
  5398     		if ( iSvgEngine->Document() )
       
  5399         	{
       
  5400         	iSvgEngine->Document()->CancelParsing();
       
  5401        	 	}
       
  5402     	}
       
  5403     }
       
  5404 
       
  5405 // --------------------------------------------------------------------------
       
  5406 // EXPORT_C TBool CSvgEngineInterfaceImpl::IsLoading()
       
  5407 // ---------------------------------------------------------------------------
       
  5408 EXPORT_C TBool CSvgEngineInterfaceImpl::IsLoading( TInt aEngine )
       
  5409     {
       
  5410     	if ( ChooseEngine(aEngine) )
       
  5411     	{
       
  5412     		if ( iSvgEngine->Document() )
       
  5413         	{
       
  5414         	return iSvgEngine->Document()->IsParsing();
       
  5415         	}
       
  5416     	}
       
  5417 
       
  5418     return EFalse;
       
  5419 	}
       
  5420 
       
  5421 //---------------------------------------------------------------------------
       
  5422 //Print all of the elements in the DOM tree and most of their attributes (only works in _DEBUG mode)
       
  5423 //---------------------------------------------------------------------------
       
  5424 EXPORT_C void CSvgEngineInterfaceImpl::PrintAllElements( CSvgDocumentImpl* aDocument )
       
  5425 {
       
  5426 	if (aDocument)
       
  5427 	{
       
  5428 		aDocument->PrintAllElements((CSvgElementImpl*)aDocument->RootElement());
       
  5429 	}
       
  5430 	else if (iSvgEngine && iSvgEngine->Document())
       
  5431 	{
       
  5432 		iSvgEngine->Document()->PrintAllElements((CSvgElementImpl*)	iSvgEngine->Document()->RootElement());
       
  5433 	}
       
  5434 }
       
  5435 
       
  5436 //---------------------------------------------------------------------------
       
  5437 //Print all of the styles that the element has access to (only works in _DEBUG mode)
       
  5438 //---------------------------------------------------------------------------
       
  5439 EXPORT_C void CSvgEngineInterfaceImpl::PrintElementsStyles( CSvgElementImpl* aElement )
       
  5440 {
       
  5441 	if (aElement)
       
  5442 	{
       
  5443 		aElement->PrintStyleProperties();
       
  5444 	}
       
  5445 }
       
  5446 
       
  5447 // --------------------------------------------------------------------------
       
  5448 // EXPORT_C void CSvgEngineInterfaceImpl::WaitForImages( TBool aBool )
       
  5449 // ---------------------------------------------------------------------------
       
  5450 EXPORT_C void CSvgEngineInterfaceImpl::WaitForImages( TBool /* aBool */, TInt /* aEngine */ )
       
  5451     {
       
  5452     // Method is obsolete: image loading is synchronous now
       
  5453     }
       
  5454 
       
  5455 // --------------------------------------------------------------------------
       
  5456 // EXPORT_C void CSvgEngineInterfaceImpl::SetClientWindow( RWindow* /*aWindow*/ )
       
  5457 // ---------------------------------------------------------------------------
       
  5458 EXPORT_C void CSvgEngineInterfaceImpl::SetClientWindow( RWindow* /*aWindow*/ )
       
  5459     {
       
  5460 
       
  5461     }
       
  5462 
       
  5463 // --------------------------------------------------------------------------
       
  5464 // EXPORT_C MSvgError* CSvgEngineInterfaceImpl::SaveSvgDom(TInt aHandle, const TDesC& aFileName)
       
  5465 // ---------------------------------------------------------------------------
       
  5466 EXPORT_C MSvgError* CSvgEngineInterfaceImpl::SaveSvgDom(TInt /*aHandle*/, const TDesC& aFileName, TInt aEngine)
       
  5467     {
       
  5468 
       
  5469     	if (!ChooseEngine(aEngine))
       
  5470     	{
       
  5471     		return iSvgError;
       
  5472     	}
       
  5473 
       
  5474     	//UseDom( aHandle, NULL );
       
  5475 
       
  5476     	TRAPD(error, iSvgEngine->SaveSvgL(aFileName));
       
  5477 
       
  5478     	if (error != KErrNone)
       
  5479     	{
       
  5480     		#ifdef _DEBUG
       
  5481     		RDebug::Printf("CSvgEngineInterfaceImpl: SaveSvgL threw an exception while saving");
       
  5482     		#endif
       
  5483     	}
       
  5484 
       
  5485    	return iSvgError;
       
  5486     }
       
  5487 
       
  5488 // --------------------------------------------------------------------------
       
  5489 // EXPORT_C void CSvgEngineInterfaceImpl::SaveSvg( TBool aIsEncodeOn, const TDesC& aFileName, TInt aEngine )
       
  5490 // ---------------------------------------------------------------------------
       
  5491 EXPORT_C void CSvgEngineInterfaceImpl::SaveSvg( TBool /*aIsEncodeOn*/, const TDesC& /*aFileName*/, TInt aEngine )
       
  5492     {
       
  5493 
       
  5494     	if (!ChooseEngine(aEngine))
       
  5495     	{
       
  5496 
       
  5497     	}
       
  5498 
       
  5499     	//UseDom( aHandle, NULL );
       
  5500 
       
  5501     	//TRAPD(error, iSvgEngine->SaveSvgL(aFileName));
       
  5502     }
       
  5503 
       
  5504 // --------------------------------------------------------------------------
       
  5505 // EXPORT_C void SetAudioVolume( TInt aPercentage , TInt aEngine );
       
  5506 // --------------------------------------------------------------------------
       
  5507 EXPORT_C void CSvgEngineInterfaceImpl::SetAudioVolume( TInt aPercentage ,
       
  5508         TInt aEngine )
       
  5509     {
       
  5510     if ( ChooseEngine(aEngine) )
       
  5511         {
       
  5512        	iSvgEngine->SetAudioVolume( aPercentage );
       
  5513         }
       
  5514     }
       
  5515 
       
  5516 // --------------------------------------------------------------------------
       
  5517 // EXPORT_C void MuteAudioVolume();
       
  5518 // --------------------------------------------------------------------------
       
  5519 EXPORT_C void CSvgEngineInterfaceImpl::MuteAudioVolume( TInt aEngine )
       
  5520     {
       
  5521     if ( ChooseEngine(aEngine) )
       
  5522         {
       
  5523        	iSvgEngine->SetAudioVolume( 0 );
       
  5524         }
       
  5525     }
       
  5526 
       
  5527 // --------------------------------------------------------------------------
       
  5528 // TInt CSvgEngineInterfaceImpl::ChooseEngine( CSvgEngineImpl* aEngine )
       
  5529 // ---------------------------------------------------------------------------
       
  5530 CSvgEngineImpl* CSvgEngineInterfaceImpl::ChooseEngine( TInt aEngine )
       
  5531 	{
       
  5532 		if (aEngine)
       
  5533 		{
       
  5534 			iSvgEngine = (CSvgEngineImpl*)aEngine;
       
  5535 			return (CSvgEngineImpl*)aEngine;
       
  5536 		}
       
  5537 		else if (iSvgEngine)
       
  5538 		{
       
  5539 			return iSvgEngine;
       
  5540 		}
       
  5541 		else
       
  5542 		{
       
  5543 			return NULL;
       
  5544 		}
       
  5545 	}
       
  5546 
       
  5547 // --------------------------------------------------------------------------
       
  5548 // EXPORT_C MSvgError* CSvgEngineInterfaceImpl::ChooseViewBox(TInt aDomHandle)
       
  5549 // ---------------------------------------------------------------------------
       
  5550 EXPORT_C void CSvgEngineInterfaceImpl::ChooseViewBoxIfNotSet(TInt aDomHandle)
       
  5551     {
       
  5552         if ( IsDomCached( aDomHandle ) )
       
  5553         {
       
  5554         CSvgDocumentImpl* document = (CSvgDocumentImpl*)aDomHandle;
       
  5555         CSvgSvgElementImpl* root = (CSvgSvgElementImpl*)document->RootElement();
       
  5556         if ( root )
       
  5557             {
       
  5558             if(!root->ViewBoxDefined())
       
  5559                 {
       
  5560                  // If viewbox is missing in the content, the content
       
  5561                  // rendering in the frame buffer is many time as expected
       
  5562                  // Some part of the content can get clipped, since content
       
  5563                  // doesn't scale proportionately to the framebuffer.
       
  5564                  TGfxRectangle2D bbox;
       
  5565                  root->GetUnscaledBBox( bbox );
       
  5566                  TFloatFixPt lDefault= TFloatFixPt(0);
       
  5567                  if(bbox.iWidth > lDefault && bbox.iHeight > lDefault)
       
  5568                     {
       
  5569                     TRAP_IGNORE( root->SetViewBoxL( bbox ) );
       
  5570                     }
       
  5571                 }
       
  5572             }
       
  5573         }
       
  5574     }
       
  5575 
       
  5576 // --------------------------------------------------------------------------
       
  5577 // void CSvgEngineInterfaceImpl::ConvertBitmapToFileL(CFbsBitmap* aBitmap, const TDesC& aText)
       
  5578 //
       
  5579 // Utility function to dump out the svg engine framebuffer
       
  5580 // ---------------------------------------------------------------------------
       
  5581 void CSvgEngineInterfaceImpl::ConvertBitmapToFileL(CFbsBitmap* aBitmap, const TDesC& /*aText*/)
       
  5582 {
       
  5583 	//set size for bitmap
       
  5584 	//if it is new
       
  5585 	/*TInt aWidth = 200, aHeight = 200;
       
  5586 
       
  5587 	aBitmap = new(ELeave)CFbsBitmap();
       
  5588 	CleanupStack::PushL(aBitmap);
       
  5589 	User::LeaveIfError(aBitmap->Create(TSize(aWidth, aHeight), EColor64K));
       
  5590 	*/
       
  5591 
       
  5592 	//draw text on bitmap here!!
       
  5593 	/*CFbsBitmapDevice* bitDevice = CFbsBitmapDevice::NewL(aBitmap);
       
  5594 	CFbsBitGc* bitGc;
       
  5595 	User::LeaveIfError(bitDevice->CreateContext(bitGc));
       
  5596 
       
  5597 	CleanupStack::Pop(aBitmap);
       
  5598 
       
  5599 	bitGc->SetPenColor(KRgbBlack);
       
  5600 	bitGc->UseFont( LatinBold19() ); // a font has to be set otherwise it panics!
       
  5601 	bitGc->SetPenStyle(CGraphicsContext::ESolidPen);
       
  5602 	bitGc->DrawText(aText, TPoint(10, 10));
       
  5603 	*/
       
  5604 
       
  5605 	RFs fs;
       
  5606 	User::LeaveIfError( fs.Connect() );
       
  5607 
       
  5608 	// constructing encoder
       
  5609 	CImageEncoder* imgEncoder = CImageEncoder::FileNewL( fs, _L("svg_engine_bitmap.bmp"), _L8("image/bmp"),
       
  5610 	CImageEncoder::EOptionAlwaysThread );
       
  5611 
       
  5612 	// Following settings are for JPG file format
       
  5613 	// TJpegImageData* imageData = new (ELeave) TJpegImageData;
       
  5614 	// Set some format specific data
       
  5615 	// imageData->iSampleScheme = TJpegImageData::EColor444;
       
  5616 	// imageData->iQualityFactor = 95;
       
  5617 
       
  5618 	// Following settings are for BMP file format
       
  5619 	TBmpImageData* imgData = new(ELeave) TBmpImageData;
       
  5620 	imgData->iBitsPerPixel = 24;
       
  5621 
       
  5622 	CFrameImageData* lFrameImageData = CFrameImageData::NewL();
       
  5623 
       
  5624 	// frameData - ownership passed to lFrameImageData after AppendImageData
       
  5625 	User::LeaveIfError(lFrameImageData->AppendImageData(imgData)); // or append imageData for jpg file
       
  5626 
       
  5627 	// Do the convert
       
  5628 	TRequestStatus iRequesStatus;
       
  5629 	imgEncoder->Convert( &iRequesStatus, *aBitmap, lFrameImageData);
       
  5630 	User::WaitForRequest( iRequesStatus );
       
  5631 
       
  5632 	fs.Close();
       
  5633 	delete lFrameImageData;
       
  5634 	//delete aBitmap;
       
  5635 	delete imgEncoder;
       
  5636 	//delete bitGc;
       
  5637 	//delete bitDevice;
       
  5638 }
       
  5639 
       
  5640 // --------------------------------------------------------------------------
       
  5641 // EXPORT_C void CSvgEngineInterfaceImpl::ResetContext( TInt aEngine )
       
  5642 // --------------------------------------------------------------------------
       
  5643 EXPORT_C void CSvgEngineInterfaceImpl::ResetContext( TInt aEngine )
       
  5644 {
       
  5645 	if ( ChooseEngine((TInt)aEngine) )
       
  5646         {
       
  5647         iSvgEngine->ResetContext();
       
  5648         }	
       
  5649 }
       
  5650 
       
  5651 
       
  5652 EXPORT_C void CSvgEngineInterfaceImpl::Start(MSvgError*& aError, const TDesC8* aHeaderData ,
       
  5653         CSvgEngineImpl* aEngine )
       
  5654     {
       
  5655     if (aHeaderData)
       
  5656             {
       
  5657             iSvgEngine->SetBitmapHeader((const TDesC16 *)aHeaderData);
       
  5658             }
       
  5659     Start(aError, aEngine);
       
  5660     }
       
  5661 
       
  5662 EXPORT_C void CSvgEngineInterfaceImpl::Start( const TDesC8* aHeaderData, CSvgEngineImpl* aEngine,
       
  5663         TBool aIsMainThread)
       
  5664     {
       
  5665 
       
  5666     if (aHeaderData)
       
  5667         {
       
  5668         iSvgEngine->SetBitmapHeader((const TDesC16 *)aHeaderData);
       
  5669         }
       
  5670     Start(aEngine, aIsMainThread);
       
  5671     }
       
  5672 // Get the NVG-TLV data
       
  5673 // --------------------------------------------------------------------------
       
  5674 // EXPORT_C TPtr CSvgEngineInterfaceImpl::TLVEncodedData()
       
  5675 // ---------------------------------------------------------------------------
       
  5676 EXPORT_C const TPtrC8 CSvgEngineInterfaceImpl::TLVEncodedData() const
       
  5677     {
       
  5678     return (iSvgEngine->TLVEncodedData());
       
  5679     }
       
  5680 //NGA
       
  5681 // --------------------------------------------------------------------------
       
  5682 // EXPORT_C MSvgError* CSvgEngineInterfaceImpl::UseDom(TInt aHandle, TSize aRenderBufferSize,TDisplayMode aRenderDisplayMode,TDisplayMode aMaskDisplayMode,TInt aEngine = NULL)
       
  5683 // ---------------------------------------------------------------------------
       
  5684 EXPORT_C MSvgError* CSvgEngineInterfaceImpl::UseDom(TInt aHandle,CFbsBitmap* aRenderBuffer, CFbsBitmap* aMaskBuffer,TSize aRenderBufferSize,TDisplayMode aRenderDisplayMode,TDisplayMode aMaskDisplayMode,TInt aEngine)
       
  5685     {
       
  5686       // Clear Error
       
  5687       iSvgError->SetErrorCode( ESvgNoError );
       
  5688 
       
  5689       // Check for engine: Should not occur
       
  5690       if( !ChooseEngine( aEngine ) )
       
  5691           {
       
  5692           _LIT(KEngineFailed, "SvgEngine Internal Failure: SvgEngineImpl not present.");
       
  5693           CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, KErrNone,
       
  5694                                           KEngineFailed, KNullDesC );
       
  5695           return iSvgError;
       
  5696           }
       
  5697 
       
  5698       // Check for valid DOM
       
  5699       if( !IsDomCached( aHandle ) )
       
  5700           {
       
  5701           _LIT(KEngineFailed, "Invalid DOM, Use Prepare() to create DOM");
       
  5702           CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, KErrNone,
       
  5703                                           KEngineFailed, KNullDesC );
       
  5704           return iSvgError;
       
  5705           }
       
  5706 
       
  5707       iTotalRotation = 0;
       
  5708 
       
  5709       iFileIsLoaded = EFalse;
       
  5710 
       
  5711       // Switch GDI context
       
  5712       TRAPD( gdiError, iSvgEngine->SetGdiContextL( aRenderBuffer, aMaskBuffer,aRenderBufferSize,aRenderDisplayMode,aMaskDisplayMode ) );//Modify this setgdi context
       
  5713       if ( gdiError != KErrNone )
       
  5714           {
       
  5715           if ( gdiError == KErrNoMemory )
       
  5716               {
       
  5717               _LIT(KEngineGDIFailed, "SVG Engine Set Gdi Context Failed");
       
  5718               CSvgDocumentImpl::PrepareError( *iSvgError, ESvgNoMemory, KErrNoMemory,
       
  5719                                                KEngineGDIFailed, KNullDesC );
       
  5720               return iSvgError;
       
  5721               }
       
  5722           _LIT(KEngineGDIFailed, "SVG Engine Set Gdi Context Failed");
       
  5723               CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, KErrNone,
       
  5724                                                KEngineGDIFailed, KNullDesC );
       
  5725           return iSvgError;
       
  5726           }
       
  5727 
       
  5728       CSvgDocumentImpl* document = (CSvgDocumentImpl*)aHandle;
       
  5729 
       
  5730       CSvgDocumentImpl* lExistDoc = iSvgEngine->Document();
       
  5731 
       
  5732       if (lExistDoc != document)
       
  5733           {
       
  5734           //this is a new document so swap it out...
       
  5735           iSvgEngine->SetDocument( document );
       
  5736           document->SetEngine( iSvgEngine );
       
  5737           document->ReInitialize();
       
  5738           }
       
  5739 
       
  5740       if (lExistDoc == iSvgLoadedDocument)
       
  5741       {
       
  5742           DestroyDocument(iSvgLoadedDocument);
       
  5743           iSvgLoadedDocument = NULL;
       
  5744       }
       
  5745 
       
  5746       // Check for thumbnail restrictions
       
  5747       if ( !iSvgEngine->PassesThumbNailRestriction() )
       
  5748           {
       
  5749           _LIT( KThumbNailRestriction, "Frame buffer is larger than allowable size for thumbnail mode." );
       
  5750           CSvgDocumentImpl::PrepareError( *iSvgError, ESvgThumbNailRestriction, KErrNone,
       
  5751                                            KThumbNailRestriction, KNullDesC );
       
  5752           return iSvgError;
       
  5753           }
       
  5754 
       
  5755       iFileIsLoaded = ETrue;
       
  5756 
       
  5757       return iSvgError;
       
  5758       }