svgtopt/SVG/SVGImpl/src/Svgsvgelementimpl.cpp
changeset 0 d46562c3d99d
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 Implementation source file
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #if !defined(__E32BASE_H__)
       
    20 #include <e32base.h>
       
    21 #endif
       
    22 
       
    23 #include "SVGSvgElementImpl.h"
       
    24 #include "SVGDocumentImpl.h"
       
    25 #include "SVGEngineImpl.h"
       
    26 #include "SVGSchemaData.h"
       
    27 
       
    28 #include "SVGClrCssValueImpl.h"
       
    29 #include "SVGPaintCssValueImpl.h"
       
    30 #include "SVGIntCssValueImpl.h"
       
    31 #include "SVGFloatCssValueImpl.h"
       
    32 #include "SVGStrCssValueImpl.h"
       
    33 #include "SVGVectorCssValueImpl.h"
       
    34 #include "SVGPathElementImpl.h"
       
    35 #include "SVGAnimTimingParser.h"
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 // ---------------------------------------------------------------------------
       
    40 CSvgSvgElementImpl* CSvgSvgElementImpl::NewL(  const TUint8 aElemID,
       
    41                                               CSvgDocumentImpl* aDoc )
       
    42     {
       
    43     CSvgSvgElementImpl* self    = new ( ELeave ) CSvgSvgElementImpl( aDoc );
       
    44     CleanupStack::PushL( self );
       
    45     self->ConstructL(  aElemID);
       
    46     CleanupStack::Pop();
       
    47     return self;
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 // ---------------------------------------------------------------------------
       
    53 CSvgSvgElementImpl* CSvgSvgElementImpl::NewLC(  const TUint8 aElemID,
       
    54                                                CSvgDocumentImpl* aDoc )
       
    55     {
       
    56     CSvgSvgElementImpl* self    = new ( ELeave ) CSvgSvgElementImpl( aDoc );
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL( aElemID);
       
    59     return self;
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 // ---------------------------------------------------------------------------
       
    65 void CSvgSvgElementImpl::ConstructL( const TUint8 aElemID )
       
    66     {
       
    67 
       
    68     CSvgElementImpl::InitializeL( aElemID );
       
    69 
       
    70     iSvgStyleProperties = new(ELeave) RPointerArray<CCssValue>(KCSS_MAX_ATTR);
       
    71 
       
    72 	CSvgDocumentImpl* lDocument = (CSvgDocumentImpl*)OwnerDocument();
       
    73 
       
    74 	if (!lDocument)
       
    75 	return;
       
    76 
       
    77     // This is required to allocate buffer up to granularity so that the
       
    78     // following Insert calls cannot leave.
       
    79 
       
    80     User::LeaveIfError( iSvgStyleProperties->Append( NULL ) );
       
    81     iSvgStyleProperties->Remove( 0 );
       
    82 
       
    83     iSvgTransformable = CSvgTransformableImpl::NewL();
       
    84 
       
    85     // Initilaise Svg Element with default values
       
    86 
       
    87     CPaintCssValueImpl* lPaintObject = lDocument->iMemoryManager->GetCssPaintObjectL( _L("black"),(CSvgElementImpl *)this );
       
    88     iSvgStyleProperties->InsertL(lPaintObject,KCSS_ATTR_FILL);
       
    89 
       
    90 	CClrCssValueImpl* lClrObject = lDocument->iMemoryManager->GetCssClrObjectL(_L("none"));
       
    91     iSvgStyleProperties->InsertL(lClrObject,KCSS_ATTR_STROKE);
       
    92 
       
    93 	CFloatCssValueImpl* lFloatObject = lDocument->iMemoryManager->GetCssFloatObjectL(_L("1"));
       
    94     iSvgStyleProperties->InsertL(lFloatObject,KCSS_ATTR_STROKEWIDTH);
       
    95 
       
    96     //set default to visible
       
    97     CIntCssValueImpl* lIntObject = lDocument->iMemoryManager->GetCssIntObjectL(_L("0"));
       
    98     iSvgStyleProperties->InsertL(lIntObject,KCSS_ATTR_VISIBILITY);
       
    99 
       
   100     iSvgStyleProperties->InsertL(NULL,KCSS_ATTR_FONTFAMILY);
       
   101 
       
   102 	CFloatCssValueImpl* lFloatObject2 = lDocument->iMemoryManager->GetCssFloatObjectL(_L("10"));
       
   103     iSvgStyleProperties->InsertL(lFloatObject2,KCSS_ATTR_FONTSIZE);
       
   104 
       
   105 	CIntCssValueImpl* lIntObject2 = lDocument->iMemoryManager->GetCssIntObjectL(_L("0"));
       
   106     iSvgStyleProperties->InsertL(lIntObject2,KCSS_ATTR_FONTSTYLE);
       
   107 
       
   108 	CIntCssValueImpl* lIntObject3 = lDocument->iMemoryManager->GetCssIntObjectL(_L("0"));
       
   109     iSvgStyleProperties->InsertL(lIntObject3,KCSS_ATTR_FONTWEIGHT);
       
   110 
       
   111     iSvgStyleProperties->InsertL(NULL,KCSS_ATTR_STROKE_DASHARRAY);
       
   112 
       
   113     //set default to inline
       
   114     CIntCssValueImpl* lIntObject4 = lDocument->iMemoryManager->GetCssIntObjectL(_L("0"));
       
   115     iSvgStyleProperties->InsertL(lIntObject4,KCSS_ATTR_DISPLAY);
       
   116 
       
   117 	CStrCssValueImpl* lStrObject1 = lDocument->iMemoryManager->GetCssStrObjectL(_L("nonzero"));
       
   118     iSvgStyleProperties->InsertL(lStrObject1,KCSS_ATTR_FILLRULE);
       
   119 
       
   120 	CStrCssValueImpl* lStrObject2 = lDocument->iMemoryManager->GetCssStrObjectL(_L("butt"));
       
   121     iSvgStyleProperties->InsertL(lStrObject2,KCSS_ATTR_STROKE_LINECAP);
       
   122 
       
   123 	CStrCssValueImpl* lStrObject3 = lDocument->iMemoryManager->GetCssStrObjectL(_L("miter"));
       
   124     iSvgStyleProperties->InsertL(lStrObject3,KCSS_ATTR_STROKE_LINEJOIN);
       
   125 
       
   126 	CFloatCssValueImpl* lFloatObject3 = lDocument->iMemoryManager->GetCssFloatObjectL(_L("0"));
       
   127     iSvgStyleProperties->InsertL(lFloatObject3,KCSS_ATTR_STROKE_DASHOFFSET);
       
   128 
       
   129 	CFloatCssValueImpl* lFloatObject4 = lDocument->iMemoryManager->GetCssFloatObjectL(_L("4"));
       
   130     iSvgStyleProperties->InsertL(lFloatObject4,KCSS_ATTR_STROKE_MITERLIMIT);
       
   131 
       
   132 	CClrCssValueImpl* lClrObject2 = lDocument->iMemoryManager->GetCssClrObjectL(_L("black"));
       
   133     iSvgStyleProperties->InsertL(lClrObject2,KCSS_ATTR_COLOR);
       
   134 
       
   135 	CIntCssValueImpl* lIntObject5 = lDocument->iMemoryManager->GetCssIntObjectL(_L("0"));
       
   136     iSvgStyleProperties->InsertL(lIntObject5,KCSS_ATTR_TEXTANCHOR);
       
   137 
       
   138 	CIntCssValueImpl* lIntObject6 = lDocument->iMemoryManager->GetCssIntObjectL(_L("-1"));
       
   139     iSvgStyleProperties->InsertL(lIntObject6,KCSS_ATTR_TEXTDECORATION);
       
   140 
       
   141     //default value is indeterminate at this point
       
   142     iSvgStyleProperties->InsertL(NULL,KCSS_ATTR_COLORINTERPOLATION);
       
   143 
       
   144     iSvgStyleProperties->InsertL(NULL,KCSS_ATTR_COLORRENDERING);
       
   145 
       
   146     iSvgStyleProperties->InsertL(NULL,KCSS_ATTR_LETTERSPACING);
       
   147 
       
   148     iSvgStyleProperties->InsertL(NULL,KCSS_ATTR_WORDSPACING);
       
   149 
       
   150 	CFloatCssValueImpl* lFloatObject5 = lDocument->iMemoryManager->GetCssFloatObjectL(_L("1"));
       
   151     iSvgStyleProperties->InsertL(lFloatObject5,KCSS_ATTR_FILL_OPACITY);
       
   152 
       
   153 	CFloatCssValueImpl* lFloatObject6 = lDocument->iMemoryManager->GetCssFloatObjectL(_L("1"));
       
   154     iSvgStyleProperties->InsertL(lFloatObject6,KCSS_ATTR_STROKE_OPACITY);
       
   155 
       
   156 	CFloatCssValueImpl* lFloatObject7 = lDocument->iMemoryManager->GetCssFloatObjectL(_L("1"));
       
   157     iSvgStyleProperties->InsertL(lFloatObject7,KCSS_ATTR_GROUP_OPACITY);
       
   158 
       
   159     iViewBoxImpl = CSvgFitToViewBoxImpl::NewL();
       
   160 
       
   161     iBaseProfile = HBufC::NewL( 0 );
       
   162     iVersion = HBufC::NewL( 0 );
       
   163     SetBaseProfileL(_L("tiny"));
       
   164     SetVersion(_L("1.1"));
       
   165 
       
   166 	iWidthInUserCoordinate = 100;
       
   167 	iHeightInUserCoordinate= 100;
       
   168 
       
   169     }
       
   170 
       
   171 
       
   172 
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 // ---------------------------------------------------------------------------
       
   177 CSvgSvgElementImpl::~CSvgSvgElementImpl()
       
   178     {
       
   179 
       
   180     if (iContent)
       
   181     {
       
   182 	delete iContent;
       
   183 	iContent = NULL;
       
   184     }
       
   185 
       
   186     if ( iViewBoxImpl )
       
   187         {
       
   188         delete iViewBoxImpl;
       
   189         iViewBoxImpl = NULL;
       
   190         }
       
   191 
       
   192     if ( iBaseProfile )
       
   193         {
       
   194         delete iBaseProfile;
       
   195         iBaseProfile = NULL;
       
   196         }
       
   197     if ( iVersion )
       
   198     	{
       
   199     	delete iVersion;
       
   200     	iVersion = NULL;
       
   201         }
       
   202 
       
   203     if ( iSvgStyleProperties )
       
   204         {
       
   205         iSvgStyleProperties->Close();
       
   206         delete iSvgStyleProperties;
       
   207         iSvgStyleProperties = NULL;
       
   208         }
       
   209 
       
   210     }
       
   211 
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 // ---------------------------------------------------------------------------
       
   216 
       
   217 CSvgSvgElementImpl::CSvgSvgElementImpl( CSvgDocumentImpl* aDoc ) : iZoomAndPan( ESvgZoomAndPanMagnify ),
       
   218                                                                    iWidth(100),
       
   219                                                                    iHeight(100),
       
   220                                                                    iWidthInPercentage(ETrue),
       
   221                                                                    iHeightInPercentage(ETrue),
       
   222                                                                    iIsWidthSet(EFalse),
       
   223                                                                    iIsHeightSet(EFalse)
       
   224     {
       
   225     SetOwnerDocument(aDoc);
       
   226 
       
   227     // Obtain the default sync behaviour/tolerance from the document
       
   228     if ( aDoc )
       
   229         {
       
   230         iSyncBehaviorDefault = aDoc->SyncBehaviorDefault();
       
   231         iSyncToleranceDefault = aDoc->SyncToleranceDefault();
       
   232         }    
       
   233     
       
   234     }
       
   235 
       
   236 
       
   237 
       
   238 // *******************************************************
       
   239 // From SVG DOM
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 // ---------------------------------------------------------------------------
       
   244 TFloatFixPt CSvgSvgElementImpl::X()
       
   245     {
       
   246     return iX;
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 // ---------------------------------------------------------------------------
       
   252 TFloatFixPt CSvgSvgElementImpl::Y()
       
   253     {
       
   254     return iY;
       
   255     }
       
   256 
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 // ---------------------------------------------------------------------------
       
   260 TFloatFixPt CSvgSvgElementImpl::Width()
       
   261     {
       
   262     return iWidth;
       
   263     }
       
   264 
       
   265 // ---------------------------------------------------------------------------
       
   266 //
       
   267 // ---------------------------------------------------------------------------
       
   268 TFloatFixPt CSvgSvgElementImpl::Height()
       
   269     {
       
   270     return iHeight;
       
   271     }
       
   272 
       
   273 // ---------------------------------------------------------------------------
       
   274 // Accessor funciton for SyncBehaviorDefault value
       
   275 // ---------------------------------------------------------------------------
       
   276 TSvgSyncBehaviour CSvgSvgElementImpl::SyncBehaviorDefault()
       
   277     {
       
   278     return iSyncBehaviorDefault;
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // Accessor funciton for SyncBehaviorDefault value
       
   283 // ---------------------------------------------------------------------------
       
   284 TUint32 CSvgSvgElementImpl::SyncToleranceDefault()
       
   285     {
       
   286     return iSyncToleranceDefault;
       
   287     }
       
   288 // ---------------------------------------------------------------------------
       
   289 //
       
   290 // ---------------------------------------------------------------------------
       
   291 MXmlElement* CSvgSvgElementImpl::GetElementById( const TDesC& /* aElementId */ )
       
   292     {
       
   293     return ( CSvgElementImpl * ) NULL;
       
   294     }
       
   295 
       
   296 // *******************************************************
       
   297 // SVG Implementation
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 //
       
   301 // ---------------------------------------------------------------------------
       
   302 void CSvgSvgElementImpl::SetWidth( TFloatFixPt aWidth )
       
   303     {
       
   304     iWidth = aWidth;
       
   305     }
       
   306 
       
   307 
       
   308 
       
   309 // ---------------------------------------------------------------------------
       
   310 //
       
   311 // ---------------------------------------------------------------------------
       
   312 void CSvgSvgElementImpl::SetHeight( TFloatFixPt aHeight )
       
   313     {
       
   314     iHeight = aHeight;
       
   315     }
       
   316 
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 // ---------------------------------------------------------------------------
       
   320 
       
   321 // *******************************************************
       
   322 // From MXmlElement
       
   323 
       
   324 // ---------------------------------------------------------------------------
       
   325 //
       
   326 // ---------------------------------------------------------------------------
       
   327 EXPORT_C TInt CSvgSvgElementImpl::GetAttribute( const TDesC& aName,
       
   328                                                 TDes& aValue )
       
   329     {
       
   330     _LIT( KTmpWidth, "width" );
       
   331     _LIT( KTmpHeight, "height" );
       
   332 
       
   333     if ( aName == KTmpWidth )
       
   334         {
       
   335         TFloatFixPt  width;
       
   336         GetAttributeFloat( KAtrWidth, width );
       
   337 	#ifdef SVG_FLOAT_BUILD
       
   338         TFloatFixPt::GetString( width, aValue );
       
   339 	#else
       
   340         width.GetString( aValue );
       
   341 	#endif
       
   342         }
       
   343     else if ( aName == KTmpHeight )
       
   344         {
       
   345         TFloatFixPt  height;
       
   346         GetAttributeFloat( KAtrHeight, height );
       
   347 	#ifdef SVG_FLOAT_BUILD
       
   348         TFloatFixPt::GetString( height, aValue );
       
   349 	#else
       
   350         height.GetString( aValue );
       
   351 	#endif
       
   352         }
       
   353 
       
   354     return KErrNone;
       
   355     }
       
   356 
       
   357 // ---------------------------------------------------------------------------
       
   358 //
       
   359 // ---------------------------------------------------------------------------
       
   360 TInt CSvgSvgElementImpl::SetAttributeL( const TDesC& aName,
       
   361                                         const TDesC& aValue )
       
   362     {
       
   363 
       
   364 
       
   365     CSvgElementImpl::SetAttributeL(aName,aValue);
       
   366 
       
   367     // Encapsulates both viewBox and preserveAspectRatio attributes.
       
   368     if ( iViewBoxImpl->SetViewBoxL( aName, aValue ) )
       
   369         {
       
   370         return KErrNone;
       
   371         }
       
   372 
       
   373 
       
   374     _LIT( KTmpBaseProfile, "baseProfile" );
       
   375     _LIT( KTmpVersion, "version" );
       
   376     _LIT( KTmpZoomAndPan, "zoomAndPan" );
       
   377     _LIT( KTmpDisable, "disable" );
       
   378     _LIT( KTmpMagnify, "magnify" );
       
   379     _LIT( KNameSpace, "xmlns" );
       
   380     _LIT( KSvgNameSpace, "http://www.w3.org/2000/svg" );
       
   381     _LIT( KTmpSyncBehaviorDefault, "syncBehaviorDefault" );
       
   382     _LIT( KTmpSyncToleranceDefault,"syncToleranceDefault" );
       
   383 
       
   384 
       
   385     TLex    input   ( aValue );
       
   386 
       
   387     if ( aName == KTmpBaseProfile )
       
   388         {
       
   389         SetBaseProfileL( aValue );
       
   390         }
       
   391     else if ( aName == KTmpVersion )
       
   392         {
       
   393         //if (input.Val( tmpFloat, '.' ) == KErrNone)
       
   394         SetVersion( aValue );
       
   395         }
       
   396     else if ( aName == KTmpZoomAndPan )
       
   397         {
       
   398         if ( aValue == KTmpDisable )
       
   399             iZoomAndPan = ESvgZoomAndPanDisable;
       
   400         else if ( aValue == KTmpMagnify )
       
   401             iZoomAndPan = ESvgZoomAndPanMagnify;
       
   402         }
       
   403     else if ( aName == KNameSpace && aValue != KSvgNameSpace )
       
   404         {
       
   405         if ( iOwnerDocument )
       
   406             {
       
   407             _LIT( KMsg, "Invalid <svg> namespace: " );
       
   408             ((CSvgDocumentImpl*)iOwnerDocument)->SetError( KErrNotFound, KMsg, aValue );
       
   409             }
       
   410         }
       
   411     else if ( aName == KTmpSyncBehaviorDefault )
       
   412         {
       
   413         SetSyncBehaviorDefault( aValue );
       
   414         }
       
   415     else if ( aName == KTmpSyncToleranceDefault )
       
   416         {
       
   417         SetSyncToleranceDefault( aValue );
       
   418         }
       
   419 
       
   420     return KErrNone;
       
   421     }
       
   422 
       
   423 // *******************************************************
       
   424 // From MXmlElementOpt
       
   425 
       
   426 // ---------------------------------------------------------------------------
       
   427 //
       
   428 // ---------------------------------------------------------------------------
       
   429 TInt CSvgSvgElementImpl::GetAttributeFloat( const TInt aNameId, TFloatFixPt& aValue )
       
   430     {
       
   431     switch ( aNameId )
       
   432         {
       
   433         case KAtrX:
       
   434         aValue = X();
       
   435         break;
       
   436         case KAtrY:
       
   437         aValue = Y();
       
   438         break;
       
   439         case KAtrWidth:
       
   440         aValue = Width();
       
   441         break;
       
   442         case KAtrHeight:
       
   443         aValue = Height();
       
   444         break;
       
   445         default:
       
   446 // ---------------------------------------------------------------------------
       
   447 //
       
   448 // ---------------------------------------------------------------------------
       
   449         return CSvgElementImpl::GetAttributeFloat( aNameId, aValue );
       
   450         }
       
   451     return KErrNone;
       
   452     }
       
   453 // ---------------------------------------------------------------------------
       
   454 //
       
   455 // ---------------------------------------------------------------------------
       
   456 TInt CSvgSvgElementImpl::SetAttributeFloatL( const TInt aNameId,
       
   457                                              const TFloatFixPt aValue )
       
   458     {
       
   459     TGfxRectangle2D lViewBox;
       
   460     switch ( aNameId )
       
   461         {
       
   462         case KAtrX:
       
   463         iX = aValue;
       
   464         break;
       
   465         case KAtrY:
       
   466         iY = aValue;
       
   467         break;
       
   468         case KAtrWidth:
       
   469 
       
   470         iWidth = aValue;
       
   471         if(!iIsWidthSet) // make sure that this is set only once
       
   472 	        {
       
   473 	        iWidthInUserCoordinate = (TReal32)aValue;
       
   474 	        iIsWidthSet = ETrue;
       
   475 	        }
       
   476         break;
       
   477         case KAtrHeight:
       
   478 
       
   479         iHeight = aValue;
       
   480         if(!iIsHeightSet ) // make sure that this is set only once
       
   481 	        {
       
   482 	        iHeightInUserCoordinate = (TReal32)aValue;
       
   483 	        iIsHeightSet= ETrue;
       
   484 	        }
       
   485         break;
       
   486 
       
   487         default:
       
   488 // ---------------------------------------------------------------------------
       
   489 //
       
   490 // ---------------------------------------------------------------------------
       
   491         return CSvgElementImpl::SetAttributeFloatL( aNameId, aValue );
       
   492         }
       
   493     return KErrNone;
       
   494     }
       
   495 
       
   496 // *******************************************************
       
   497 // From CSvgElementImpl
       
   498 
       
   499 // perform a deep clone of this object
       
   500 // ---------------------------------------------------------------------------
       
   501 //
       
   502 // ---------------------------------------------------------------------------
       
   503 MXmlElement* CSvgSvgElementImpl::CloneL(MXmlElement* aParentElement)
       
   504     {
       
   505 
       
   506     CSvgSvgElementImpl* retValue = CSvgSvgElementImpl::NewL(this->ElemID(),  ((CSvgDocumentImpl*)iOwnerDocument));
       
   507 
       
   508     CleanupStack::PushL(retValue);
       
   509     retValue->iParentNode = aParentElement;
       
   510 
       
   511     // *** have base class copy what it needs to
       
   512     this->CopyL(retValue);
       
   513 
       
   514     // *** copy iViewBoxImpl
       
   515     if (this->iViewBoxImpl != NULL)
       
   516         {
       
   517         if (retValue->iViewBoxImpl != NULL)
       
   518         {
       
   519 			delete retValue->iViewBoxImpl;
       
   520 			retValue->iViewBoxImpl= NULL;
       
   521 		}
       
   522         retValue->iViewBoxImpl = this->iViewBoxImpl->CloneL();
       
   523         }
       
   524 
       
   525     // *** copy iBaseProfile
       
   526     if (retValue->iBaseProfile != NULL)
       
   527         {
       
   528         delete retValue->iBaseProfile;
       
   529         retValue->iBaseProfile = NULL;
       
   530         }
       
   531     retValue->iBaseProfile = this->iBaseProfile->AllocL();
       
   532 
       
   533     // *** copy others
       
   534     retValue->iZoomAndPan = this->iZoomAndPan;
       
   535     retValue->iX = this->iX;
       
   536     retValue->iY = this->iY;
       
   537     retValue->iWidth = this->iWidth;
       
   538     retValue->iHeight = this->iHeight;
       
   539     retValue->iVersion = this->iVersion->AllocL();
       
   540     CleanupStack::Pop();
       
   541 
       
   542     return retValue;
       
   543     }
       
   544 
       
   545 // ---------------------------------------------------------------------------
       
   546 //
       
   547 // ---------------------------------------------------------------------------
       
   548 TBool CSvgSvgElementImpl::DrawL( CGfx2dGc* /* aGc */,
       
   549                                  CSvgElementImpl* /* aElement */ )
       
   550     {
       
   551     return ETrue;
       
   552     }
       
   553 
       
   554 // *******************************************************
       
   555 // From MSvgZoomAndPan
       
   556 
       
   557 // ---------------------------------------------------------------------------
       
   558 //
       
   559 // ---------------------------------------------------------------------------
       
   560 TSvgZoomAndPanType CSvgSvgElementImpl::GetZoomAndPan()
       
   561     {
       
   562     return iZoomAndPan;
       
   563     }
       
   564 
       
   565 // ---------------------------------------------------------------------------
       
   566 //
       
   567 // ---------------------------------------------------------------------------
       
   568 void CSvgSvgElementImpl::SetZoomAndPan( TSvgZoomAndPanType aZoomAndPan )
       
   569     {
       
   570     iZoomAndPan = aZoomAndPan;
       
   571     }
       
   572 
       
   573 // *******************************************************
       
   574 // From MSvgFitToWindow
       
   575 
       
   576 // ---------------------------------------------------------------------------
       
   577 //
       
   578 // ---------------------------------------------------------------------------
       
   579 void CSvgSvgElementImpl::GetPreserveAspectRatio( MSvgPreserveAspectRatio*& aAspectRatio )
       
   580     {
       
   581     iViewBoxImpl->GetPreserveAspectRatio( aAspectRatio );
       
   582     }
       
   583 
       
   584 // ---------------------------------------------------------------------------
       
   585 //
       
   586 // ---------------------------------------------------------------------------
       
   587 void CSvgSvgElementImpl::SetPreserveAspectRatioL( TSvgPreserveAspectAlignType aAlign, TSvgMeetOrSliceType aMeetslice )
       
   588     {
       
   589     iViewBoxImpl->SetPreserveAspectRatioL( aAlign, aMeetslice);
       
   590     }
       
   591 
       
   592 // ---------------------------------------------------------------------------
       
   593 //
       
   594 // ---------------------------------------------------------------------------
       
   595 TBool CSvgSvgElementImpl::GetViewBox( TGfxRectangle2D& aViewBox )
       
   596     {
       
   597     return iViewBoxImpl->GetViewBox( aViewBox );
       
   598     }
       
   599 
       
   600 // ---------------------------------------------------------------------------
       
   601 //
       
   602 // ---------------------------------------------------------------------------
       
   603 void CSvgSvgElementImpl::SetViewBoxL( TGfxRectangle2D aViewBox )
       
   604     {
       
   605     iViewBoxImpl->SetViewBoxL(aViewBox);
       
   606     }
       
   607 
       
   608 // ---------------------------------------------------------------------------
       
   609 //
       
   610 // ---------------------------------------------------------------------------
       
   611 TBool CSvgSvgElementImpl::ViewBoxDefined()
       
   612     {
       
   613     return iViewBoxImpl->ViewBoxDefined();
       
   614     }
       
   615 
       
   616 // *******************************************************
       
   617 // Baseprofile
       
   618 
       
   619 // ---------------------------------------------------------------------------
       
   620 //
       
   621 // ---------------------------------------------------------------------------
       
   622 const TDesC& CSvgSvgElementImpl::BaseProfile()
       
   623     {
       
   624     return *iBaseProfile;
       
   625     }
       
   626 
       
   627 // ---------------------------------------------------------------------------
       
   628 //
       
   629 // ---------------------------------------------------------------------------
       
   630 void CSvgSvgElementImpl::SetBaseProfileL( const TDesC& aValue )
       
   631     {
       
   632     if ( iBaseProfile )
       
   633         {
       
   634         delete iBaseProfile;
       
   635         iBaseProfile = NULL;
       
   636         }
       
   637     iBaseProfile = aValue.AllocL();
       
   638     }
       
   639 
       
   640 // Version
       
   641 
       
   642 // ---------------------------------------------------------------------------
       
   643 //
       
   644 // ---------------------------------------------------------------------------
       
   645 const TDesC& CSvgSvgElementImpl::Version()
       
   646     {
       
   647     return *iVersion;
       
   648     }
       
   649 
       
   650 // ---------------------------------------------------------------------------
       
   651 //
       
   652 // ---------------------------------------------------------------------------
       
   653 void CSvgSvgElementImpl::SetVersion( const TDesC& aValue )
       
   654     {
       
   655     if ( iVersion )
       
   656         {
       
   657         delete iVersion;
       
   658         iVersion = NULL;
       
   659         }
       
   660         TInt error = KErrNone;
       
   661         	TRAP(error,iVersion = aValue.AllocL());
       
   662     }
       
   663 
       
   664 // ---------------------------------------------------------------------------
       
   665 // set synchronised behaviour default
       
   666 // ---------------------------------------------------------------------------
       
   667 void CSvgSvgElementImpl::SetSyncBehaviorDefault( const TDesC& aValue )
       
   668     {
       
   669     _LIT( KTmpCanSlip, "canSlip" );
       
   670     _LIT( KTmpLocked, "locked" );
       
   671     _LIT( KTmpIndependent, "independent" );
       
   672     _LIT( KTmpInherit, "inherit" );
       
   673 	
       
   674 	if ( !aValue.CompareF( KTmpCanSlip ) )
       
   675 	    {
       
   676         iSyncBehaviorDefault = ESvgSyncCanSlip;        
       
   677 	    }
       
   678 	else if ( !aValue.CompareF( KTmpLocked ) )
       
   679 	    {
       
   680         iSyncBehaviorDefault = ESvgSyncLocked;
       
   681 	    }
       
   682 	else if ( !aValue.CompareF( KTmpIndependent ) )
       
   683 	    {
       
   684         iSyncBehaviorDefault = ESvgSyncIndependent;
       
   685 	    }
       
   686 	else if ( !aValue.CompareF( KTmpInherit ) )
       
   687 	    {
       
   688         // Obtain the sync behaviour from the document
       
   689         CSvgDocumentImpl* lSvgDoc = (( CSvgDocumentImpl* ) 
       
   690             iOwnerDocument);
       
   691         iSyncBehaviorDefault = lSvgDoc->SyncBehaviorDefault();
       
   692 	    }
       
   693     }
       
   694 
       
   695 // ---------------------------------------------------------------------------
       
   696 // set synchronised tolerance default
       
   697 // ---------------------------------------------------------------------------
       
   698 void CSvgSvgElementImpl::SetSyncToleranceDefault( const TDesC& aValue )
       
   699     {
       
   700     _LIT( KTmpInherit, "inherit" );
       
   701 	if ( !aValue.CompareF( KTmpInherit ) )
       
   702 	    {
       
   703 	    CSvgAnimTimingParser* lATParserPtr = NULL;
       
   704 	    // Treat as clock value
       
   705 	    TRAPD( lCreateATPErr, 
       
   706 	        {
       
   707 	        lATParserPtr = CSvgAnimTimingParser::NewL( aValue, this );
       
   708 	        } );
       
   709 	    
       
   710 	    if ( lCreateATPErr != KErrNone )
       
   711 	        {
       
   712 	        // Error Processing
       
   713 	        return;
       
   714 	        }
       
   715         TInt32 lClockValue;
       
   716         TLex lLex( aValue );
       
   717         lATParserPtr->ParseClockValue( lLex, lClockValue );
       
   718         delete lATParserPtr;
       
   719         iSyncToleranceDefault = lClockValue; // TODO: Convert Units
       
   720 	    }
       
   721 	else
       
   722 	    {
       
   723 	    // Get clock value from parent
       
   724         CSvgDocumentImpl* lSvgDoc = (( CSvgDocumentImpl* ) 
       
   725             iOwnerDocument);
       
   726         iSyncToleranceDefault = lSvgDoc->SyncToleranceDefault();
       
   727 	    }
       
   728     }
       
   729 
       
   730 // -----------------------------------------------------------------------------
       
   731 // CSvgSvgElementImpl::SetSyncBehaviorDefault
       
   732 // Set the Synchronised behaviour(default) 
       
   733 // -----------------------------------------------------------------------------
       
   734 //        
       
   735 void CSvgSvgElementImpl::SetSyncBehaviorDefault( 
       
   736     const TSvgSyncBehaviour aValue )
       
   737     {
       
   738     if ( aValue == ESvgSyncDefault )
       
   739         {
       
   740         // Obtain the sync behaviour from the document
       
   741         CSvgDocumentImpl* lSvgDoc = (( CSvgDocumentImpl* ) 
       
   742             iOwnerDocument);
       
   743         iSyncBehaviorDefault = lSvgDoc->SyncBehaviorDefault();
       
   744         }
       
   745      else
       
   746         {
       
   747         iSyncBehaviorDefault = aValue;
       
   748         }
       
   749     }   
       
   750 
       
   751 // -----------------------------------------------------------------------------
       
   752 // CSvgSvgElementImpl::SetSyncToleranceDefault
       
   753 // Set the Synchronised Tolerance (Default) 
       
   754 // -----------------------------------------------------------------------------
       
   755 //        
       
   756 void CSvgSvgElementImpl::SetSyncToleranceDefault( const TInt32 aValue , 
       
   757     const TBool aUseDefault )
       
   758     {
       
   759     if ( aUseDefault )
       
   760         {
       
   761 	    // Get clock value from parent
       
   762         CSvgDocumentImpl* lSvgDoc = (( CSvgDocumentImpl* ) 
       
   763             iOwnerDocument);
       
   764         iSyncToleranceDefault = lSvgDoc->SyncToleranceDefault();
       
   765         }
       
   766         else
       
   767             {
       
   768             iSyncToleranceDefault = aValue;            
       
   769             }
       
   770     }
       
   771      
       
   772 // ---------------------------------------------------------------------------
       
   773 //
       
   774 // ---------------------------------------------------------------------------
       
   775 void CSvgSvgElementImpl::GetBBox( TGfxRectangle2D& aBbox )
       
   776     {
       
   777     	if (!HasChildNodes())
       
   778     	{
       
   779     		return;
       
   780     	}
       
   781 
       
   782     CSvgGElementImpl::GetGroupBounding( aBbox, this );
       
   783     }
       
   784 
       
   785 // ---------------------------------------------------------------------------
       
   786 //
       
   787 // ---------------------------------------------------------------------------
       
   788 void CSvgSvgElementImpl::GetUnscaledBBox( TGfxRectangle2D& aBbox )
       
   789     {
       
   790     	if (!HasChildNodes())
       
   791     	{
       
   792     		return;
       
   793     	}
       
   794 
       
   795     CSvgGElementImpl::GetGroupBoundingUnscaled( aBbox, this );
       
   796     }
       
   797 
       
   798 // ---------------------------------------------------------------------------
       
   799 //
       
   800 // ---------------------------------------------------------------------------
       
   801 void CSvgSvgElementImpl::SetWindowViewportTrans( TGfxRectangle2D aXYWH,
       
   802                                                  TGfxAffineTransform& aTr )
       
   803     {
       
   804 		//this is a problem for the JSR.  There isn't an engine associated here yet.
       
   805     if ( (CSvgDocumentImpl*)iOwnerDocument)
       
   806     {
       
   807     	TSize lSize;
       
   808 
       
   809         TFloatFixPt width, height;
       
   810         TGfxRectangle2D viewBox;
       
   811         
       
   812         // Is engine defined
       
   813         TBool engine = EFalse;
       
   814         
       
   815         // Does the client define the viewPort
       
   816         TBool clientDefinedViewport = EFalse;
       
   817 
       
   818         TBool viewBoxDefined = iViewBoxImpl->GetViewBox(viewBox);
       
   819         if(((CSvgDocumentImpl*)iOwnerDocument)->Engine())
       
   820             engine = ETrue;
       
   821         
       
   822         // if Client like browser or viewer has set the viewport 
       
   823         // take the width/height got by using GetViewPort()
       
   824         if ( engine )
       
   825             {
       
   826             clientDefinedViewport = ((CSvgDocumentImpl*)iOwnerDocument )->Engine()->iClientDefinedViewPort;
       
   827             }
       
   828         
       
   829         if( clientDefinedViewport )
       
   830             {
       
   831             width = Width();
       
   832             height = Height();
       
   833             }
       
   834         else
       
   835             {
       
   836             if(iWidthInPercentage && engine)
       
   837                 {
       
   838                 lSize = ((CSvgDocumentImpl*)iOwnerDocument)->Engine()->GetSize();
       
   839                 TReal32 per = 100;
       
   840                 width = ( TFloatFixPt ) (( lSize.iWidth/per ) * iWidthInUserCoordinate);
       
   841                 }
       
   842             else if(iWidthInPercentage && !engine && viewBoxDefined)
       
   843                 {
       
   844                 aXYWH.iWidth = viewBox.iWidth;
       
   845                 aXYWH.iX = viewBox.iX;
       
   846                 width = viewBox.iWidth;
       
   847                 }
       
   848             else
       
   849                 {
       
   850                 width  = Width();
       
   851                 }
       
   852             
       
   853             if(iHeightInPercentage && engine)
       
   854                 {
       
   855                 lSize = ((CSvgDocumentImpl*)iOwnerDocument)->Engine()->GetSize();
       
   856                 TReal32 per = 100;
       
   857                 height = ( TFloatFixPt ) (( lSize.iHeight/per ) * iHeightInUserCoordinate);
       
   858                 }
       
   859             else if( iHeightInPercentage && !engine && viewBoxDefined)
       
   860                 {
       
   861             	aXYWH.iHeight = viewBox.iHeight;
       
   862             	aXYWH.iY = viewBox.iY;
       
   863             	height = viewBox.iHeight;
       
   864                 }
       
   865             else
       
   866                 {
       
   867                 height = Height();
       
   868                 }
       
   869         
       
   870             }
       
   871            
       
   872 
       
   873          TFloatFixPt KZero;
       
   874          if ( ( width < KZero ) && ( height < KZero ) )
       
   875             {
       
   876             width = lSize.iWidth;
       
   877             height = lSize.iHeight;
       
   878             }
       
   879         else if ( width <= KZero )
       
   880             {
       
   881             width = height;
       
   882             }
       
   883         else if ( height <= KZero )
       
   884             {
       
   885             height = width;
       
   886             }
       
   887 
       
   888             TSize lTmpViewBox(width,height);
       
   889 
       
   890 			//this should update the CTM based for the new viewbox...hopefully
       
   891     	iViewBoxImpl->SetWindowViewportTrans( aXYWH, aTr, lTmpViewBox );
       
   892     }
       
   893     else
       
   894     {
       
   895     	#ifdef _DEBUG
       
   896     	RDebug::Printf("SvgSvgElement:SetWindowViewportTrans Owner Document Not Found! Maybe JSR226?");
       
   897     	#endif
       
   898 		}
       
   899 }
       
   900 
       
   901 //Added as a part of update of Set/Get API's
       
   902 TInt CSvgSvgElementImpl::GetAttributeDes( const TInt aNameId,
       
   903                                                      TPtrC16& aValue )
       
   904 {
       
   905  if(aNameId == KAtrBaseProfile)
       
   906 	{
       
   907 	 aValue.Set( BaseProfile() );
       
   908 	 return KErrNone;
       
   909 	}
       
   910  else if (aNameId == KAtrVersion)
       
   911  	{
       
   912  	aValue.Set( Version() );
       
   913  	return KErrNone;
       
   914  	}
       
   915 
       
   916  return CSvgElementImpl::GetAttributeDes( aNameId, aValue );
       
   917 }
       
   918 TInt CSvgSvgElementImpl::SetAttributeDesL( const TInt aNameId,
       
   919                                                      TDesC& aValue )
       
   920 {
       
   921  if(aNameId == KAtrBaseProfile)
       
   922 	{
       
   923 	 SetBaseProfileL(aValue);
       
   924 	 return KErrNone;
       
   925 	}
       
   926  else if (aNameId == KAtrVersion)
       
   927  	{
       
   928  	SetVersion(aValue);
       
   929  	return KErrNone;
       
   930  	}
       
   931  return CSvgElementImpl::SetAttributeDesL( aNameId, aValue );
       
   932 
       
   933 }
       
   934 
       
   935 void CSvgSvgElementImpl::Print( TBool aIsEncodeOn )
       
   936 {
       
   937 	if (!aIsEncodeOn)
       
   938 	{
       
   939 		#ifdef _DEBUG
       
   940 		RDebug::Printf("<svg x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\">", (int)iX, (int)iY, (int)iWidth, (int)iHeight);
       
   941 		#endif
       
   942 	}
       
   943 }
       
   944