svgtopt/SVG/SVGImpl/src/SVGStyleElementImpl.cpp
changeset 46 88edb906c587
equal deleted inserted replaced
-1:000000000000 46:88edb906c587
       
     1 /*
       
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  SVG Implementation source file
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #if !defined(__E32BASE_H__)
       
    22 #include <e32base.h>
       
    23 #endif
       
    24 #include "SVGStyleElementImpl.h"
       
    25 #include "SVGDocumentImpl.h"
       
    26 #include "SVGSchemaData.h"
       
    27 
       
    28 #include "GfxAffineTransform.h"
       
    29 
       
    30 // *******************************************************
       
    31 // Constructor/deconstructor
       
    32 
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 // ---------------------------------------------------------------------------
       
    37 CSvgStyleElementImpl* CSvgStyleElementImpl::NewL(  const TUint8 aElemID,
       
    38                                                   CSvgDocumentImpl* aDoc )
       
    39     {
       
    40     CSvgStyleElementImpl*   self    = new ( ELeave )
       
    41                                       CSvgStyleElementImpl( aDoc );
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL(  aElemID );
       
    44     CleanupStack::Pop();
       
    45 
       
    46     return self;
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 // ---------------------------------------------------------------------------
       
    52 CSvgStyleElementImpl* CSvgStyleElementImpl::NewLC(  const TUint8 aElemID,
       
    53                                                    CSvgDocumentImpl* aDoc )
       
    54     {
       
    55     CSvgStyleElementImpl*   self    = new ( ELeave )
       
    56                                       CSvgStyleElementImpl( aDoc );
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL(  aElemID );
       
    59 
       
    60     return self;
       
    61     }
       
    62 
       
    63 
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 // ---------------------------------------------------------------------------
       
    69 CSvgStyleElementImpl::~CSvgStyleElementImpl()
       
    70     {
       
    71 	if ( iStyle )
       
    72 		{
       
    73 		delete iStyle;
       
    74 		iStyle =  NULL;
       
    75 		}
       
    76 
       
    77 	if ( iType )
       
    78 		{
       
    79 	    delete iType;
       
    80 		iType = NULL;
       
    81 		}
       
    82 
       
    83 	if ( iMedia )
       
    84 		{
       
    85 		delete iMedia;
       
    86 		iMedia = NULL;
       
    87 		}
       
    88 
       
    89 	if ( iTitle)
       
    90 		{
       
    91 		delete iTitle;
       
    92 		iTitle = NULL;
       
    93 		}
       
    94     }
       
    95 
       
    96 // *******************************************************
       
    97 // SVG Implementation
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 // ---------------------------------------------------------------------------
       
   101 void CSvgStyleElementImpl::SetTypeL( const TDesC& aValue )
       
   102     {
       
   103 	if ( iType )
       
   104 		{
       
   105 		delete iType;
       
   106 	    iType = NULL;
       
   107 		}
       
   108     iType = aValue.AllocL();
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 // ---------------------------------------------------------------------------
       
   114 void CSvgStyleElementImpl::SetMediaL( const TDesC& aValue )
       
   115     {
       
   116 	if ( iMedia )
       
   117 		{
       
   118 		delete iMedia;
       
   119 		iMedia = NULL;
       
   120 		}
       
   121     iMedia = aValue.AllocL();
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 // ---------------------------------------------------------------------------
       
   127 void CSvgStyleElementImpl::SetTitleL( const TDesC& aValue )
       
   128     {
       
   129 	if ( iTitle )
       
   130 		{
       
   131 		delete iTitle;
       
   132 		iTitle = NULL;
       
   133 		}
       
   134     iTitle = aValue.AllocL();
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 // ---------------------------------------------------------------------------
       
   140 void CSvgStyleElementImpl::SetStyleL( const TDesC& aValue )
       
   141     {
       
   142 	if ( iStyle )
       
   143 		{
       
   144 		delete iStyle;
       
   145 		iStyle = NULL;
       
   146 		}
       
   147     iStyle = aValue.AllocL();
       
   148     }
       
   149 
       
   150 
       
   151 // *******************************************************
       
   152 // From MXmlElement
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 // ---------------------------------------------------------------------------
       
   157 TInt CSvgStyleElementImpl::SetAttributeL( const TDesC& aName,
       
   158                                           const TDesC& aValue )
       
   159     {
       
   160     if ( SetIdandXmlbaseL( aName, aValue ) )
       
   161         {
       
   162         return KErrNone;
       
   163         }
       
   164 
       
   165     if ( this->SetLangSpaceAttributeL( aName, aValue ) )
       
   166         {
       
   167         return KErrNone;
       
   168         }
       
   169 
       
   170     // Set type
       
   171     _LIT( KType, "type" );
       
   172     _LIT( KMedia, "media" );
       
   173     _LIT( KTitle, "title" );
       
   174 
       
   175     if ( aName == KType )
       
   176         {
       
   177         SetTypeL( aValue );
       
   178         }
       
   179     // Set media
       
   180     else if ( aName == KMedia )
       
   181         {
       
   182         SetMediaL( aValue );
       
   183         }
       
   184     // Set title
       
   185     else if ( aName == KTitle )
       
   186         {
       
   187         SetTitleL( aValue );
       
   188         }
       
   189     else if ( aName == KTitle )
       
   190         {
       
   191         SetStyleL( aValue );
       
   192         }
       
   193 
       
   194     return KErrNone;
       
   195     }
       
   196 
       
   197 
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 // ---------------------------------------------------------------------------
       
   202 TInt  CSvgStyleElementImpl::SetAttributeDesL( const TInt aNameId,
       
   203 											   const TDesC& aValue )
       
   204 	{
       
   205 
       
   206 	switch (aNameId)
       
   207 		{
       
   208 		case KAtrType:
       
   209 				     delete iType;
       
   210                      iType = NULL;
       
   211 					 iType = aValue.AllocL();
       
   212 					 break;
       
   213 		case KAtrMedia:
       
   214 					 delete iMedia;
       
   215 					 iMedia = NULL;
       
   216 				     iMedia = aValue.AllocL();
       
   217 				     break;
       
   218 		case KAtrTitle:
       
   219 					 delete iTitle;
       
   220 					 iTitle = NULL;
       
   221 			         iTitle = aValue.AllocL();
       
   222 						break;
       
   223 
       
   224 		default:
       
   225 				return CSvgElementImpl::SetAttributeDesL( aNameId, aValue );
       
   226 
       
   227 		}
       
   228 	return KErrNone;
       
   229 	}
       
   230 
       
   231 // From MXmlElementOpt
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 // ---------------------------------------------------------------------------
       
   236 TInt CSvgStyleElementImpl::GetAttributeFloat( const TInt aNameId,
       
   237                                               TFloatFixPt& aValue )
       
   238     {
       
   239     switch ( aNameId )
       
   240         {
       
   241         case KAtrRefX:
       
   242             {
       
   243             TFloatFixPt          xmin( KMAXFLOATFIX ), x; // 0x7fff is the maximum integer in TFixPt
       
   244             CSvgElementImpl*lNewElement = ( CSvgElementImpl* ) FirstChild();
       
   245             while ( lNewElement != NULL )
       
   246                 {
       
   247                 lNewElement->GetAttributeFloat( KAtrRefX, x );
       
   248                 if ( x < xmin )
       
   249                     xmin = x;
       
   250                 lNewElement = ( CSvgElementImpl * )
       
   251                               lNewElement->NextSibling();
       
   252                 }
       
   253             aValue = xmin;
       
   254             }
       
   255         break;
       
   256         case KAtrRefY:
       
   257             {
       
   258             TFloatFixPt          ymin( KMAXFLOATFIX ), y; // 0x7fff is the maximum integer in TFixPt
       
   259             CSvgElementImpl*lNewElement = ( CSvgElementImpl* ) FirstChild();
       
   260             while ( lNewElement != NULL )
       
   261                 {
       
   262                 lNewElement->GetAttributeFloat( KAtrRefY, y );
       
   263                 if ( y < ymin )
       
   264                     ymin = y;
       
   265                 lNewElement = ( CSvgElementImpl * )
       
   266                               lNewElement->NextSibling();
       
   267                 }
       
   268             aValue = ymin;
       
   269             }
       
   270         break;
       
   271         default:
       
   272         return CSvgElementImpl::GetAttributeFloat( aNameId, aValue );
       
   273         }
       
   274     return KErrNone;
       
   275     }
       
   276 
       
   277 // *******************************************************
       
   278 // From CSvgElementImpl
       
   279 
       
   280 // perform a deep clone of this object
       
   281 // ---------------------------------------------------------------------------
       
   282 //
       
   283 // ---------------------------------------------------------------------------
       
   284 MXmlElement* CSvgStyleElementImpl::CloneL(MXmlElement*)
       
   285     {
       
   286     return NULL;
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 //
       
   291 // ---------------------------------------------------------------------------
       
   292 TBool CSvgStyleElementImpl::DrawL( CGfx2dGc* /* aGc */,
       
   293                                    CSvgElementImpl* /* aElement */ )
       
   294     {
       
   295     return EFalse;
       
   296     }
       
   297 
       
   298 
       
   299 // *******************************************************
       
   300 // Private
       
   301 
       
   302 // ---------------------------------------------------------------------------
       
   303 //
       
   304 // ---------------------------------------------------------------------------
       
   305 void CSvgStyleElementImpl::ConstructL(  const TUint8 aElemID )
       
   306 	{
       
   307 	CSvgElementImpl::InitializeL( aElemID );
       
   308 }
       
   309 
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 //
       
   313 // ---------------------------------------------------------------------------
       
   314 
       
   315 CSvgStyleElementImpl::CSvgStyleElementImpl( CSvgDocumentImpl* aDoc )
       
   316     {
       
   317 	SetOwnerDocument(aDoc);
       
   318     }
       
   319 
       
   320 // ---------------------------------------------------------------------------
       
   321 //
       
   322 // ---------------------------------------------------------------------------
       
   323 void CSvgStyleElementImpl::Print( TBool aIsEncodeOn )
       
   324 {
       
   325 	if (!aIsEncodeOn)
       
   326 	{
       
   327 		#ifdef _DEBUG
       
   328 		RDebug::Printf("<style type=\"hmm\" media=\"hmm\" title=\"hmm\">"/*, iType, iMedia, iTitle*/);
       
   329 		#endif
       
   330 	}
       
   331 }