svgtopt/SVG/SVGImpl/src/SVGSolidColorElementImpl.cpp
changeset 0 d46562c3d99d
equal deleted inserted replaced
-1:000000000000 0:d46562c3d99d
       
     1 /*
       
     2 * Copyright (c) 2005 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 // INCLUDE FILES
       
    20 #include "SVGSolidColorElementImpl.h"
       
    21 #include "SVGFloatCssValueImpl.h"
       
    22 #include "SVGDocumentImpl.h"
       
    23 #include "SVGSchemaData.h"
       
    24 
       
    25 _LIT(SOLIDOPACITY, "solid-opacity");
       
    26 _LIT(INHERIT, "inherit");
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // Two-phased constructor.
       
    30 // ---------------------------------------------------------------------------
       
    31 CSvgSolidColorElementImpl* CSvgSolidColorElementImpl::NewL(const TUint8 aElemID,
       
    32 																   CSvgDocumentImpl* aDoc )
       
    33 	{
       
    34     CSvgSolidColorElementImpl *self = new (ELeave) CSvgSolidColorElementImpl(aDoc);
       
    35     CleanupStack::PushL(self);
       
    36     self->ConstructL(aElemID);
       
    37     CleanupStack::Pop(self);
       
    38     return self;
       
    39 	}
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // Two-phased constructor.
       
    43 // ---------------------------------------------------------------------------
       
    44 CSvgSolidColorElementImpl* CSvgSolidColorElementImpl::NewLC(  const TUint8 aElemID,
       
    45                                                      CSvgDocumentImpl* aDoc )
       
    46     {
       
    47     CSvgSolidColorElementImpl*  self    = new ( ELeave )
       
    48                                       CSvgSolidColorElementImpl( aDoc );
       
    49     CleanupStack::PushL( self );
       
    50     self->ConstructL(  aElemID );
       
    51 
       
    52     return self;
       
    53     }
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // Symbian default constructor that can leave.
       
    58 // ---------------------------------------------------------------------------
       
    59 void CSvgSolidColorElementImpl::ConstructL(const TUint8 aElemID)
       
    60     {
       
    61     CSvgElementImpl::InitializeL( aElemID );
       
    62 
       
    63     iSvgStyleProperties = new(ELeave) RPointerArray<CCssValue>(KCSS_MAX_ATTR);
       
    64     User::LeaveIfError( iSvgStyleProperties->Append( NULL ) );
       
    65     iSvgStyleProperties->Remove( 0 );
       
    66 
       
    67     iSvgUriReferenceImpl = CSvgUriReferenceImpl::NewL();
       
    68     iSvgTransformable = CSvgTransformableImpl::NewL();
       
    69 
       
    70     }
       
    71 // ---------------------------------------------------------------------------
       
    72 //  C++ default constructor
       
    73 // ---------------------------------------------------------------------------
       
    74 
       
    75 CSvgSolidColorElementImpl::CSvgSolidColorElementImpl( CSvgDocumentImpl* aDoc )
       
    76     {
       
    77     SetOwnerDocument(aDoc);
       
    78 
       
    79     iSolidOpacity = TFloatFixPt(1);
       
    80 
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // Destructor
       
    85 // ---------------------------------------------------------------------------
       
    86 CSvgSolidColorElementImpl::~CSvgSolidColorElementImpl()
       
    87     {
       
    88 
       
    89     if ( iSvgStyleProperties )
       
    90         {
       
    91         iSvgStyleProperties->Close();
       
    92         delete iSvgStyleProperties;
       
    93         iSvgStyleProperties = NULL;
       
    94         }
       
    95 
       
    96     if ( iSvgUriReferenceImpl )
       
    97         {
       
    98         delete iSvgUriReferenceImpl;
       
    99         iSvgUriReferenceImpl = NULL;
       
   100         }
       
   101 
       
   102     }
       
   103 
       
   104 // ============================ MEMBER FUNCTIONS ========================================
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // SetAttributeL: The implemented function will be called from CSvgContentHandler.
       
   108 // SetAttributeFloatL: The implemented function will be called from CSvgContentHandler.
       
   109 //
       
   110 // From CSvgElementImpl
       
   111 //
       
   112 // There will be two attributes been set: solid-color and solid-opacity.
       
   113 // These attributes are redundant and are same as fill and fill-opacity
       
   114 //
       
   115 // Returns: ETrue always in this case.
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 TInt CSvgSolidColorElementImpl::SetAttributeL( const TDesC& aName,
       
   119                                            const TDesC& aValue )
       
   120     {
       
   121      TFloatFixPt KZero;
       
   122      TFloatFixPt KOne( KFloatFixOne );
       
   123 
       
   124     	if(aName == SOLIDOPACITY)
       
   125         {
       
   126         if(aValue == INHERIT)
       
   127             {
       
   128             // inherit does not make any sense since the stop-opacity is
       
   129             //specific to stop element only and a stop element can not have another stop element as
       
   130             //its child.
       
   131             iSolidOpacity = KOne;
       
   132             }
       
   133         else
       
   134             {
       
   135     #ifdef SVG_FLOAT_BUILD
       
   136             iSolidOpacity = TFloatFixPt::ConvertString( aValue );
       
   137             if (!(iSolidOpacity > TFloatFixPt(0) && iSolidOpacity < TFloatFixPt(1)) )
       
   138 
       
   139     #else
       
   140             if ( TFloatFixPt::ConvertString (aValue, iSolidOpacity ) != KErrNone )
       
   141     #endif
       
   142                 {
       
   143                 iSolidOpacity = KOne;
       
   144                 }
       
   145             else
       
   146                 {
       
   147                 if (aValue.Locate('%') != KErrNotFound)
       
   148 		 			{
       
   149 		 			//if stop opacity was listed as a percentage
       
   150 		 			iSolidOpacity = iSolidOpacity / TFloatFixPt(100);
       
   151                     }
       
   152 
       
   153                 if ( iSolidOpacity < KZero )
       
   154                     iSolidOpacity = KZero;
       
   155                 else if ( iSolidOpacity > KOne )
       
   156                     iSolidOpacity = KOne;
       
   157                 }
       
   158             }
       
   159 
       
   160             //CFloatCssValueImpl* lFloatObject = (CFloatCssValueImpl*)iSvgStyleProperties[KCSS_ATTR_FILL_OPACITY];
       
   161             CFloatCssValueImpl* lFloatObject;
       
   162             this->FindProperty( KCSS_ATTR_FILL_OPACITY, (CCssValue*&)lFloatObject, this );
       
   163             lFloatObject->SetValueL(iSolidOpacity);
       
   164 
       
   165 
       
   166 
       
   167 		}
       
   168 
       
   169 	CSvgElementImpl::SetAttributeL(aName,aValue);
       
   170     return KErrNone;
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 // ---------------------------------------------------------------------------
       
   176 TInt CSvgSolidColorElementImpl::GetAttributeFloat(const TInt aNameId, TFloatFixPt& aValue)
       
   177 {
       
   178 	switch(aNameId)
       
   179 	{
       
   180 	case KAtrSolidOpacity:
       
   181 		aValue = iSolidOpacity;
       
   182 		break;
       
   183 	default:
       
   184 		CSvgElementImpl::GetAttributeFloat(aNameId,aValue);
       
   185 		break;
       
   186 	}
       
   187 
       
   188     return 0;
       
   189 
       
   190 }
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 // ---------------------------------------------------------------------------
       
   195 TInt CSvgSolidColorElementImpl::SetAttributeFloatL(const TInt aNameId,const TFloatFixPt aValue)
       
   196 {
       
   197 	switch(aNameId)
       
   198 	{
       
   199     case KAtrSolidOpacity:
       
   200         {
       
   201         iSolidOpacity = aValue;
       
   202 
       
   203 		//set the solid opacity into the fill-opacity here
       
   204 //        CFloatCssValueImpl* lFloatObject = (CFloatCssValueImpl*)iSvgStyleProperties[KCSS_ATTR_FILL_OPACITY];
       
   205 //        lFloatObject->SetValueL(iSolidOpacity);
       
   206         CFloatCssValueImpl* lFloatObject;
       
   207         this->FindProperty( KCSS_ATTR_FILL_OPACITY, (CCssValue*&)lFloatObject, this );
       
   208         lFloatObject->SetValueL(iSolidOpacity);
       
   209 
       
   210         }
       
   211 		break;
       
   212 
       
   213     default:
       
   214         return CSvgElementImpl::SetAttributeFloatL(aNameId,aValue);
       
   215     }
       
   216 
       
   217     return 0;
       
   218 }
       
   219 
       
   220 
       
   221 // ---------------------------------------------------------------------------=======
       
   222 // ApplyOpacitytoElement: Applies solid-opacity to appropriate element
       
   223 // ---------------------------------------------------------------------------=======
       
   224 void CSvgSolidColorElementImpl::ApplyOpacitytoElement(CSvgElementImpl* aElement)
       
   225      {
       
   226        CCssValue*  lCssValue = NULL;
       
   227        // get soild-opacity attribute from SolidColor element
       
   228        // solid-opacity is same as fill-opacity attribute
       
   229        this->FindProperty( KCSS_ATTR_FILL_OPACITY, lCssValue, this );
       
   230        if (lCssValue != NULL)
       
   231           {
       
   232           TBool lResult = ETrue;
       
   233           // apply solid-opacity to the element
       
   234           TRAPD( err, lResult = aElement->SetPropertyFloatL( KCSS_ATTR_FILL_OPACITY,
       
   235       	                 ((CFloatCssValueImpl*)lCssValue)->Value()) );
       
   236           if ( err || !lResult )
       
   237              {
       
   238            	#ifdef _DEBUG
       
   239             _LIT( KErrMsg, "CPaintCssValueImpl::Value() Error in SetValueL" );
       
   240              RDebug::Print(KErrMsg);
       
   241             #endif //_DEBUG*/
       
   242              }
       
   243 
       
   244            }//
       
   245 
       
   246      }
       
   247 
       
   248 void CSvgSolidColorElementImpl::Print( TBool aIsEncodeOn )
       
   249 {
       
   250 	if (!aIsEncodeOn)
       
   251 	{
       
   252 		#ifdef _DEBUG
       
   253 		RDebug::Printf("<solidColor/>", this);
       
   254 		#endif
       
   255 	}
       
   256 }
       
   257 
       
   258 //  End of File