svgtopt/SVG/SVGImpl/src/SVGPolylineElementImpl.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 "SVGPolylineElementImpl.h"
       
    23 #include "SVGElementImpl.h"
       
    24 #include "SVGDocumentImpl.h"
       
    25 #include "SVGSchemaData.h"
       
    26 #include "SVGPathDataParser.h"
       
    27 
       
    28 #include "GfxAffineTransform.h"
       
    29 
       
    30 _LIT(POINTS, "points");
       
    31 _LIT(INLINE, "inline");
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 // ---------------------------------------------------------------------------
       
    35 CSvgPolylineElementImpl* CSvgPolylineElementImpl::NewL(  const TUint8 aElemID,
       
    36 														CSvgDocumentImpl* aDoc )
       
    37 	{
       
    38 	CSvgPolylineElementImpl*self    = new ( ELeave )
       
    39 									  CSvgPolylineElementImpl( aDoc );
       
    40 	CleanupStack::PushL( self );
       
    41 	self->ConstructL(  aElemID );
       
    42 	CleanupStack::Pop();
       
    43 
       
    44 	return self;
       
    45 	}
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 // ---------------------------------------------------------------------------
       
    50 CSvgPolylineElementImpl* CSvgPolylineElementImpl::NewLC(  const TUint8 aElemID,
       
    51 														 CSvgDocumentImpl* aDoc )
       
    52 	{
       
    53 	CSvgPolylineElementImpl*self    = new ( ELeave )
       
    54 									  CSvgPolylineElementImpl( aDoc );
       
    55 	CleanupStack::PushL( self );
       
    56 	self->ConstructL(  aElemID );
       
    57 
       
    58 	return self;
       
    59 	}
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 // ---------------------------------------------------------------------------
       
    64 void CSvgPolylineElementImpl::ConstructL(  const TUint8 aElemID )
       
    65 	{
       
    66 	CSvgElementImpl::InitializeL(  aElemID );
       
    67 
       
    68 	 iSvgStyleProperties = new(ELeave) RPointerArray<CCssValue>(KCSS_MAX_ATTR);
       
    69 	 User::LeaveIfError( iSvgStyleProperties->Append( NULL ) );
       
    70 	 iSvgStyleProperties->Remove( 0 );
       
    71     iSvgTransformable = CSvgTransformableImpl::NewL();
       
    72 
       
    73 	iShape = CGfxGeneralPath::NewL();
       
    74 	iReqAttrFlag=KSVG_POLYLINE_ELEMFLAG;
       
    75 
       
    76 	}
       
    77 
       
    78 
       
    79 
       
    80 
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 // ---------------------------------------------------------------------------
       
    85 CSvgPolylineElementImpl::~CSvgPolylineElementImpl()
       
    86     {
       
    87 	if ( iShape )
       
    88 		{
       
    89 		delete iShape;
       
    90 		iShape = NULL;
       
    91         }
       
    92     if ( iSvgStyleProperties )
       
    93 		{
       
    94 		iSvgStyleProperties->Close();
       
    95 		delete iSvgStyleProperties;
       
    96 		iSvgStyleProperties = NULL;
       
    97 		}
       
    98     }
       
    99 
       
   100 // *******************************************************
       
   101 // From MXmlElement
       
   102 
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 // ---------------------------------------------------------------------------
       
   107 TInt CSvgPolylineElementImpl::SetAttributeL( const TDesC& aName,
       
   108                                              const TDesC& aValue )
       
   109     {
       
   110 
       
   111 
       
   112 	CSvgElementImpl::SetAttributeL(aName,aValue);
       
   113 
       
   114 	if( aName == POINTS )
       
   115 		{
       
   116 
       
   117 		iReqAttrFlag = 0;
       
   118 		TSvgPathDataParser::ParsePointDataL( aValue,
       
   119 															 iShape );
       
   120 				// Polyline does not close a path.
       
   121 		if(this->ElemID() == KSvgPolygonElement )
       
   122 			{
       
   123 			iShape->ClosePathL();
       
   124 			}
       
   125 		}
       
   126 
       
   127 	return KErrNone;
       
   128     }
       
   129 
       
   130 // From MXmlElementOpt
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 // ---------------------------------------------------------------------------
       
   135 TInt CSvgPolylineElementImpl::GetAttributeFloat( const TInt aNameId,
       
   136                                                  TFloatFixPt& aValue )
       
   137     {
       
   138     switch ( aNameId )
       
   139         {
       
   140         case KAtrRefX:
       
   141         aValue = iShape->PointCoordsArray()[0];
       
   142         break;
       
   143         case KAtrRefY:
       
   144         aValue = iShape->PointCoordsArray()[1];
       
   145         break;
       
   146         default:
       
   147         return CSvgElementImpl::GetAttributeFloat( aNameId, aValue );
       
   148         }
       
   149     return KErrNone;
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 // ---------------------------------------------------------------------------
       
   155 TInt CSvgPolylineElementImpl::GetAttributePath( const TInt aNameId,
       
   156                                                 CGfxGeneralPath*& aValue )
       
   157     {
       
   158     if ( aNameId == KAtrPoints )
       
   159         {
       
   160         aValue = iShape;
       
   161         }
       
   162     else
       
   163         {
       
   164         aValue = NULL;
       
   165         return KErrNoAttribute;
       
   166         }
       
   167 
       
   168     return KErrNone;
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 // ---------------------------------------------------------------------------
       
   174 TInt CSvgPolylineElementImpl::SetAttributePathL( const TInt aNameId,
       
   175                                                  CGfxGeneralPath* aValue )
       
   176     {
       
   177     if ( aNameId == KAtrPoints ) //.
       
   178         {
       
   179         // We need to copy aValue into iShape
       
   180         // We should not just reassign pointers - that will cause memory leak
       
   181         // We will do the copy when CGfxGeneralPath implements a copy method
       
   182         iShape->SetPointTypeArrayL( aValue->PointTypeArray() );
       
   183         iShape->SetPointCoordsArrayL( aValue->PointCoordsArrayAll() );
       
   184 		if( WasTurnedOff() )
       
   185 			{
       
   186 			// turn it on. this means all the required attributes Are present and
       
   187 			// hence we can render it.
       
   188 			CSvgElementImpl::SetPropertyL(KCSS_ATTR_DISPLAY, INLINE);
       
   189 			SetTurnOff( EFalse );
       
   190 			}
       
   191         }
       
   192     else
       
   193         {
       
   194         return KErrNoAttribute;
       
   195         }
       
   196 	if(this->ElemID() == KSvgPolygonElement )
       
   197 			{
       
   198 			iShape->ClosePathL();
       
   199 			}
       
   200     return KErrNone;
       
   201     }
       
   202 
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 // ---------------------------------------------------------------------------
       
   207 TInt CSvgPolylineElementImpl::SetAttributePathRef( const TInt aNameId,
       
   208                                               CGfxGeneralPath*&  aValue  )
       
   209     {
       
   210     if ( aNameId == KAtrPoints )
       
   211         {
       
   212 
       
   213 		if(iShape)
       
   214 			{
       
   215 			delete iShape;
       
   216 			iShape= NULL;
       
   217 			}
       
   218 		iShape= aValue;
       
   219 
       
   220         }
       
   221     else
       
   222         {
       
   223         return KErrNoAttribute;
       
   224         }
       
   225 
       
   226     return KErrNone;
       
   227     }
       
   228 
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 //
       
   232 // ---------------------------------------------------------------------------
       
   233 TBool CSvgPolylineElementImpl::DrawL( CGfx2dGc* aGc, CSvgElementImpl* aElement )
       
   234     {
       
   235     this->DrawShapeL( aGc, *iShape, aElement );
       
   236 
       
   237     return ETrue;
       
   238     }
       
   239 
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 // ---------------------------------------------------------------------------
       
   244 CSvgPolylineElementImpl::CSvgPolylineElementImpl( CSvgDocumentImpl* aDoc )
       
   245     {
       
   246 	SetOwnerDocument(aDoc);
       
   247     }
       
   248 
       
   249 
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 // ---------------------------------------------------------------------------
       
   253 void CSvgPolylineElementImpl::GetBBox( TGfxRectangle2D& aBbox )
       
   254     {
       
   255     iShape->GetBounds( GetCTM(), aBbox );
       
   256     }
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 //
       
   260 // ---------------------------------------------------------------------------
       
   261 void CSvgPolylineElementImpl::GetUnscaledBBox( TGfxRectangle2D& aBbox )
       
   262     {
       
   263     TGfxAffineTransform identityTx;
       
   264     iShape->GetBounds( identityTx, aBbox );
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // perform a deep clone of this object
       
   269 // ---------------------------------------------------------------------------
       
   270 MXmlElement* CSvgPolylineElementImpl::CloneL(MXmlElement* aParentElement)
       
   271     {
       
   272     // create new polyline
       
   273     CSvgPolylineElementImpl* newElement = CSvgPolylineElementImpl::NewL( this->ElemID(), ((CSvgDocumentImpl*)iOwnerDocument) );
       
   274 
       
   275 	CleanupStack::PushL(newElement);
       
   276 	newElement->iParentNode = aParentElement;
       
   277     // copy everything over
       
   278     CopyL(newElement);
       
   279 	CleanupStack::Pop();
       
   280     return newElement;
       
   281     }
       
   282 
       
   283 // ---------------------------------------------------------------------------
       
   284 // perform a deep copy of this object
       
   285 // ---------------------------------------------------------------------------
       
   286 void CSvgPolylineElementImpl::CopyL( CSvgPolylineElementImpl* aDestElement )
       
   287     {
       
   288     if(aDestElement)
       
   289 		{
       
   290 	    // copy stuff from superclass
       
   291 	    CSvgElementImpl::CopyL(aDestElement);
       
   292 
       
   293 	    // copy iShape
       
   294         RArray<TUint32>* lTypes = iShape->PointTypeArray();
       
   295         RArray<TFloatFixPt>* lCoords = iShape->PointCoordsArrayAll();
       
   296         aDestElement->iShape->SetPointTypeArrayL(lTypes);
       
   297         aDestElement->iShape->SetPointCoordsArrayL(lCoords);
       
   298 
       
   299         // copy the reference to idoc (CSvgDocumentImpl)
       
   300 	    aDestElement->iOwnerDocument = iOwnerDocument;
       
   301 		}
       
   302 
       
   303     }
       
   304 
       
   305 void CSvgPolylineElementImpl::Print( TBool aIsEncodeOn )
       
   306 {
       
   307 	if (!aIsEncodeOn)
       
   308 	{
       
   309 	#ifdef _DEBUG
       
   310 	RArray<TUint32>* lTypes = this->iShape->PointTypeArray();
       
   311 	RArray<TFloatFixPt>* lCoords = this->iShape->PointCoordsArrayAll();
       
   312 
       
   313 	if (lTypes->Count() != lCoords->Count())
       
   314 	{
       
   315 		RDebug::Printf("Invalid polyline points and types didnt match", this);
       
   316 		return;
       
   317 	}
       
   318 
       
   319 	RDebug::Printf("<polyline points=\"", this);
       
   320 
       
   321 	TInt lTypesCnt = lTypes->Count();
       
   322 	for (TInt i=0; i < lTypesCnt; i++)
       
   323 	{
       
   324 		RDebug::Printf("%c ", lTypes->operator[]( i ));
       
   325 		RDebug::Printf("%d ", (int)(lCoords->operator[]( i )));
       
   326 	}
       
   327 
       
   328 	RDebug::Printf(" z\">", this);
       
   329 
       
   330 	#endif
       
   331 	}
       
   332 }
       
   333