svgtopt/SVG/SVGImpl/src/SVGLineElementImpl.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 #include "SVGLineElementImpl.h"
       
    23 #include "SVGElementImpl.h"
       
    24 #include "SVGDocumentImpl.h"
       
    25 #include "SVGSchemaData.h"
       
    26 
       
    27 #include "GfxAffineTransform.h"
       
    28 
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 // ---------------------------------------------------------------------------
       
    33 CSvgLineElementImpl* CSvgLineElementImpl::NewL(  const TUint8 aElemID,
       
    34 												CSvgDocumentImpl* aDoc )
       
    35 	{
       
    36 	CSvgLineElementImpl*self    = new ( ELeave ) CSvgLineElementImpl( aDoc );
       
    37 	CleanupStack::PushL( self );
       
    38 	self->ConstructL(  aElemID );
       
    39 	CleanupStack::Pop();
       
    40 
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 // ---------------------------------------------------------------------------
       
    47 CSvgLineElementImpl* CSvgLineElementImpl::NewLC(  const TUint8 aElemID,
       
    48 												 CSvgDocumentImpl* aDoc )
       
    49 	{
       
    50 	CSvgLineElementImpl*self    = new ( ELeave ) CSvgLineElementImpl( aDoc );
       
    51 	CleanupStack::PushL( self );
       
    52 	self->ConstructL(  aElemID );
       
    53 
       
    54 	return self;
       
    55 	}
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 // ---------------------------------------------------------------------------
       
    60 void CSvgLineElementImpl::ConstructL(  const TUint8 aElemID )
       
    61 	{
       
    62 	CSvgElementImpl::InitializeL(  aElemID );
       
    63 
       
    64 		iSvgStyleProperties = new(ELeave) RPointerArray<CCssValue>(KCSS_MAX_ATTR);
       
    65 	User::LeaveIfError( iSvgStyleProperties->Append( NULL ) );
       
    66 	iSvgStyleProperties->Remove( 0 );
       
    67     iSvgTransformable = CSvgTransformableImpl::NewL();
       
    68 	}
       
    69 
       
    70 
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 // ---------------------------------------------------------------------------
       
    75 CSvgLineElementImpl::CSvgLineElementImpl( CSvgDocumentImpl* aDoc ) : iLine( 0,
       
    76                                                                             0,
       
    77                                                                             0,
       
    78                                                                             0 )
       
    79     {
       
    80 	SetOwnerDocument(aDoc);
       
    81     }
       
    82 
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 // ---------------------------------------------------------------------------
       
    87 CSvgLineElementImpl::~CSvgLineElementImpl()
       
    88     {
       
    89 	if ( iSvgStyleProperties )
       
    90 		{
       
    91 		iSvgStyleProperties->Close();
       
    92 		delete iSvgStyleProperties;
       
    93 		iSvgStyleProperties = NULL;
       
    94 		}
       
    95     }
       
    96 
       
    97 
       
    98 
       
    99 // *******************************************************
       
   100 // From MXmlElement
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 // ---------------------------------------------------------------------------
       
   105 TInt CSvgLineElementImpl::SetAttributeL( const TDesC& aName,
       
   106                                          const TDesC& aValue )
       
   107     {
       
   108 
       
   109 	CSvgElementImpl::SetAttributeL(aName,aValue);
       
   110     return KErrNone;
       
   111     }
       
   112 
       
   113 
       
   114 // From MXmlElementOpt
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 // ---------------------------------------------------------------------------
       
   119 TInt CSvgLineElementImpl::GetAttributeFloat( const TInt aNameId,
       
   120                                              TFloatFixPt& aValue )
       
   121     {
       
   122     switch ( aNameId )
       
   123         {
       
   124         case KAtrX1:
       
   125         aValue = iLine.iX1;
       
   126         break;
       
   127         case KAtrY1:
       
   128         aValue = iLine.iY1;
       
   129         break;
       
   130         case KAtrX2:
       
   131         aValue = iLine.iX2;
       
   132         break;
       
   133         case KAtrY2:
       
   134         aValue = iLine.iY2;
       
   135         break;
       
   136         default:
       
   137         return CSvgElementImpl::GetAttributeFloat( aNameId, aValue );
       
   138         }
       
   139 
       
   140     return KErrNone;
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 // ---------------------------------------------------------------------------
       
   146 TInt CSvgLineElementImpl::SetAttributeFloatL( const TInt aNameId,
       
   147                                               const TFloatFixPt aValue )
       
   148     {
       
   149     switch ( aNameId )
       
   150         {
       
   151         case KAtrX1:
       
   152         iLine.iX1 = aValue;
       
   153         // SetX1(aValue);
       
   154         break;
       
   155         case KAtrY1:
       
   156         iLine.iY1 = aValue;
       
   157         // SetY1(aValue);
       
   158         break;
       
   159         case KAtrX2 :
       
   160         iLine.iX2 = aValue;
       
   161         //SetX1(aValue);
       
   162         break;
       
   163         case KAtrY2 :
       
   164         iLine.iY2 = aValue;
       
   165         //SetY2(aValue);
       
   166         break;
       
   167         default:
       
   168         return CSvgElementImpl::SetAttributeFloatL( aNameId, aValue );
       
   169         }
       
   170 
       
   171     return KErrNone;
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 // ---------------------------------------------------------------------------
       
   177 TBool CSvgLineElementImpl::DrawL( CGfx2dGc* aGc, CSvgElementImpl* aElement )
       
   178     {
       
   179     
       
   180     //line isnt a line at all two identical points
       
   181     if (iLine.iX1 == iLine.iX2 && iLine.iY1 == iLine.iY2)
       
   182     return ETrue;
       
   183     
       
   184     this->DrawShapeL( aGc, iLine, aElement );
       
   185     return ETrue;
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 // ---------------------------------------------------------------------------
       
   191 void CSvgLineElementImpl::GetBBox( TGfxRectangle2D& aBbox )
       
   192     {
       
   193     iLine.GetBounds( GetCTM(), aBbox );
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 // ---------------------------------------------------------------------------
       
   199 void CSvgLineElementImpl::GetUnscaledBBox( TGfxRectangle2D& aBbox )
       
   200     {
       
   201     TGfxAffineTransform identityTx;
       
   202     iLine.GetBounds( identityTx, aBbox );
       
   203     }
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // perform a deep clone of this object
       
   207 // ---------------------------------------------------------------------------
       
   208 
       
   209 MXmlElement* CSvgLineElementImpl::CloneL(MXmlElement* aParentElement)
       
   210     {
       
   211     // create new circle
       
   212     CSvgLineElementImpl* newElement = CSvgLineElementImpl::NewL(  this->ElemID(), ((CSvgDocumentImpl*)iOwnerDocument));
       
   213 
       
   214     CleanupStack::PushL(newElement);
       
   215 
       
   216 	newElement->iParentNode = aParentElement;
       
   217 
       
   218     // copy everything over
       
   219     this->CopyL(newElement);
       
   220 	CleanupStack::Pop();
       
   221     return newElement;
       
   222     }
       
   223 
       
   224 // perform a deep copy of this object
       
   225 void CSvgLineElementImpl::CopyL( CSvgLineElementImpl* aDestElement )
       
   226     {
       
   227     if(aDestElement)
       
   228 		{
       
   229 	    // copy stuff from superclass
       
   230 	    this->CSvgElementImpl::CopyL(aDestElement);
       
   231 
       
   232 	    // copy iLine items special to circle
       
   233 	    aDestElement->iLine.iX1 = this->iLine.iX1;
       
   234 	    aDestElement->iLine.iX2 = this->iLine.iX2;
       
   235 	    aDestElement->iLine.iY1 = this->iLine.iY1;
       
   236 	    aDestElement->iLine.iY2 = this->iLine.iY2;
       
   237 
       
   238 	    // copy the reference to idoc (CSvgDocumentImpl)
       
   239 	    aDestElement->iOwnerDocument = this->iOwnerDocument;
       
   240 		}
       
   241 
       
   242 
       
   243 
       
   244     }
       
   245 
       
   246 void CSvgLineElementImpl::Print( TBool aIsEncodeOn )
       
   247 {
       
   248 	if (!aIsEncodeOn)
       
   249 	{
       
   250 		#ifdef _DEBUG
       
   251 		RDebug::Printf("<line x1=\"%d\" x2=\"%d\" y1=\"%d\" y2=\"%d\">", (int)iLine.iX1, (int)iLine.iX2, (int)iLine.iY1, (int)iLine.iY2);
       
   252 		#endif
       
   253 	}
       
   254 }