svgtopt/SVG/SVGImpl/src/SVGMissingGlyphElementImpl.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 #if !defined(__E32BASE_H__)
       
    20 #include <e32base.h>
       
    21 #endif
       
    22 #include "SVGMissingGlyphElementImpl.h"
       
    23 #include "SVGElementImpl.h"
       
    24 #include "SVGDocumentImpl.h"
       
    25 #include "SVGSchemaData.h"
       
    26 #include "SVGPathDataParser.h"
       
    27 
       
    28 #include "GfxAffineTransform.h"
       
    29 
       
    30 #ifdef SVG_FONTS_INCLUDE
       
    31 
       
    32 _LIT( D, "d" );
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 // ---------------------------------------------------------------------------
       
    37 CSvgMissingGlyphElementImpl* CSvgMissingGlyphElementImpl::NewL(  const TUint8 aElemID,
       
    38 																CSvgDocumentImpl* aDoc )
       
    39 	{
       
    40 	CSvgMissingGlyphElementImpl*self    = new ( ELeave )
       
    41 										  CSvgMissingGlyphElementImpl( aDoc );
       
    42 	CleanupStack::PushL( self );
       
    43 	self->ConstructL( aElemID);
       
    44 	CleanupStack::Pop();
       
    45 
       
    46 	return self;
       
    47 	}
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 // ---------------------------------------------------------------------------
       
    52 CSvgMissingGlyphElementImpl* CSvgMissingGlyphElementImpl::NewLC(  const TUint8 aElemID,
       
    53 																 CSvgDocumentImpl* aDoc )
       
    54 	{
       
    55 	CSvgMissingGlyphElementImpl*self    = new ( ELeave )
       
    56 										  CSvgMissingGlyphElementImpl( aDoc );
       
    57 	CleanupStack::PushL( self );
       
    58 	self->ConstructL(  aElemID);
       
    59 
       
    60 	return self;
       
    61 	}
       
    62 
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 // ---------------------------------------------------------------------------
       
    67 void CSvgMissingGlyphElementImpl::ConstructL(  const TUint8 aElemID )
       
    68 	{
       
    69 	CSvgElementImpl::InitializeL(  aElemID);
       
    70 
       
    71 	iShape = CGfxGeneralPath::NewL();
       
    72 	#ifdef SVG_FLOAT_BUILD	
       
    73 	iHorzAdvX = TFloatFixPt( 0 );
       
    74 	#else
       
    75 	iHorzAdvX = TFloatFixPt( 0, ETrue );
       
    76 	#endif
       
    77 
       
    78 	iSvgStyleProperties = new(ELeave) RPointerArray<CCssValue>(KCSS_MAX_ATTR);
       
    79 	// This is required to allocate buffer up to granularity so that the
       
    80     // following Insert calls cannot leave.
       
    81 
       
    82     User::LeaveIfError( iSvgStyleProperties->Append( NULL ) );
       
    83     iSvgStyleProperties->Remove( 0 );
       
    84 
       
    85 	}
       
    86 
       
    87 
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 // ---------------------------------------------------------------------------
       
    93 CSvgMissingGlyphElementImpl::~CSvgMissingGlyphElementImpl()
       
    94     {
       
    95     if(iShape)
       
    96 		{
       
    97 		delete iShape;
       
    98 		iShape = NULL;
       
    99 		}
       
   100 	if(iSvgStyleProperties)
       
   101 		{
       
   102 		iSvgStyleProperties->Close();
       
   103 		delete iSvgStyleProperties;
       
   104 		iSvgStyleProperties = NULL;
       
   105 		}
       
   106     }
       
   107 
       
   108 // *******************************************************
       
   109 // From SVG DOM
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 // ---------------------------------------------------------------------------
       
   114 TFloatFixPt CSvgMissingGlyphElementImpl::GetHorzAdvX()
       
   115     {
       
   116     return iHorzAdvX;
       
   117     }
       
   118 
       
   119 // *******************************************************
       
   120 // SVG Implementation
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 // ---------------------------------------------------------------------------
       
   125 void CSvgMissingGlyphElementImpl::SetPath( const TDesC& aPath )
       
   126     {
       
   127 	TSvgPathDataParser::ParsePathData( aPath, iShape );
       
   128     }
       
   129 
       
   130 
       
   131 // *******************************************************
       
   132 // From MXmlElement
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 // ---------------------------------------------------------------------------
       
   137 TInt CSvgMissingGlyphElementImpl::SetAttributeL( const TDesC& aName,
       
   138                                                  const TDesC& aValue )
       
   139     {
       
   140 	CSvgElementImpl::SetAttributeL(aName,aValue);
       
   141 
       
   142 	if (aName == D )
       
   143 		{
       
   144          SetPath( aValue );
       
   145         }
       
   146     return KErrNone;
       
   147     }
       
   148 
       
   149 
       
   150 
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 // ---------------------------------------------------------------------------
       
   155 TInt CSvgMissingGlyphElementImpl::GetAttributeFloat( const TInt aNameId,
       
   156                                                      TFloatFixPt& aValue )
       
   157     {
       
   158     switch ( aNameId )
       
   159         {
       
   160         case KAtrRefX:
       
   161         aValue = iShape->PointCoordsArray()[0];
       
   162         break;
       
   163         case KAtrRefY:
       
   164         aValue = iShape->PointCoordsArray()[1];
       
   165         break;
       
   166         case KAtrHorizAdvX:
       
   167         aValue = GetHorzAdvX();
       
   168         break;
       
   169         default:
       
   170         return CSvgElementImpl::GetAttributeFloat( aNameId, aValue );
       
   171         }
       
   172     return KErrNone;
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 // ---------------------------------------------------------------------------
       
   178 TInt CSvgMissingGlyphElementImpl::GetAttributePath( const TInt aNameId,
       
   179                                                     CGfxGeneralPath*& aValue )
       
   180     {
       
   181     if ( aNameId == KAtrData )
       
   182         {
       
   183         aValue = iShape;
       
   184         }
       
   185     else
       
   186         {
       
   187         aValue = NULL;
       
   188         return KErrNoAttribute;
       
   189         }
       
   190 
       
   191     return KErrNone;
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 // ---------------------------------------------------------------------------
       
   197 TInt CSvgMissingGlyphElementImpl::SetAttributePathL( const TInt aNameId,
       
   198                                                      CGfxGeneralPath* /* aValue */ )
       
   199     {
       
   200 	if ( aNameId != KAtrData )
       
   201 		return KErrNoAttribute;
       
   202 
       
   203 
       
   204     return KErrNone;
       
   205     }
       
   206 
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 // ---------------------------------------------------------------------------
       
   211 TInt CSvgMissingGlyphElementImpl::SetAttributePathRef( const TInt aNameId,
       
   212                                               CGfxGeneralPath*&  aValue  )
       
   213     {
       
   214     if ( aNameId == KAtrData )
       
   215         {
       
   216 
       
   217 		if(iShape)
       
   218 			{
       
   219 			delete iShape;
       
   220 			iShape= NULL;
       
   221 			}
       
   222 		iShape= aValue;
       
   223         }
       
   224     else
       
   225         {
       
   226         return KErrNoAttribute;
       
   227         }
       
   228 
       
   229     return KErrNone;
       
   230     }
       
   231 
       
   232 
       
   233 // *******************************************************
       
   234 // From CSvgElementImpl
       
   235 // perform a deep clone of this object
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 // ---------------------------------------------------------------------------
       
   239 
       
   240 MXmlElement* CSvgMissingGlyphElementImpl::CloneL(MXmlElement*)
       
   241     {
       
   242     return NULL;
       
   243     }
       
   244 
       
   245 // ---------------------------------------------------------------------------
       
   246 //
       
   247 // ---------------------------------------------------------------------------
       
   248 TBool CSvgMissingGlyphElementImpl::DrawL( CGfx2dGc* /* aGc */,
       
   249                                           CSvgElementImpl* /* aElement */ )
       
   250     {
       
   251     return EFalse;
       
   252     }
       
   253 
       
   254 
       
   255 // *******************************************************
       
   256 // Private
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 // ---------------------------------------------------------------------------
       
   260 
       
   261 CSvgMissingGlyphElementImpl::CSvgMissingGlyphElementImpl( CSvgDocumentImpl* aDoc )
       
   262     {
       
   263 	SetOwnerDocument(aDoc);
       
   264     }
       
   265 
       
   266 	TInt CSvgMissingGlyphElementImpl::SetAttributeFloatL( const TInt aNameId,
       
   267                                                       const TFloatFixPt aValue )
       
   268 	{
       
   269 		if( aNameId == KAtrHorizAdvX )
       
   270 			{
       
   271 			iHorzAdvX = aValue;
       
   272 			}
       
   273 		else
       
   274 			{
       
   275 			return CSvgElementImpl::SetAttributeFloatL( aNameId, aValue );
       
   276 			}
       
   277 		return KErrNone;
       
   278 	}
       
   279 
       
   280 CGfxGeneralPath* CSvgMissingGlyphElementImpl::GetPathAttribute(TInt aAttributeId)
       
   281 	{
       
   282 	if(aAttributeId == KAtrD)
       
   283 		{
       
   284 		return iShape;
       
   285 		}
       
   286 	else
       
   287 		{
       
   288 		return NULL;
       
   289 		}
       
   290 	}
       
   291 void CSvgMissingGlyphElementImpl::SetPathAttribute(TInt aAttributeId, CGfxGeneralPath* aPathHandle)
       
   292 {
       
   293 	// i think it will be better if it is  deleted here.
       
   294 	if(aAttributeId == KAtrD)
       
   295 		{
       
   296 		if(iShape == aPathHandle)
       
   297 			{
       
   298 			return;
       
   299 			}
       
   300 		delete iShape;
       
   301 		iShape = aPathHandle;
       
   302 		}
       
   303 }
       
   304 
       
   305 void CSvgMissingGlyphElementImpl::Print( TBool aIsEncodeOn )
       
   306 {
       
   307 	if (!aIsEncodeOn)
       
   308 	{
       
   309 	#ifdef _DEBUG
       
   310 	RDebug::Printf("<missing-glyph horiz-adv-x=\"%d\" >", (int)iHorzAdvX);
       
   311 
       
   312 	if (iShape)
       
   313 	{
       
   314 		RArray<TUint32>* lTypes = iShape->PointTypeArray();
       
   315 		RArray<TFloatFixPt>* lCoords = iShape->PointCoordsArrayAll();
       
   316 
       
   317 		if (lTypes->Count() != lCoords->Count())
       
   318 		{
       
   319 			RDebug::Printf("Invalid path points and types didnt match", this);
       
   320 			return;
       
   321 		}
       
   322 
       
   323 		RDebug::Printf("<path d=\"", this);
       
   324 		
       
   325 		TInt lTypesCnt = lTypes->Count();
       
   326 		for (TInt i=0; i < lTypesCnt; i++)
       
   327 		{
       
   328 			RDebug::Printf("%c ", lTypes->operator[]( i ));
       
   329 			RDebug::Printf("%d ", (int)(lCoords->operator[]( i )));
       
   330 		}
       
   331 
       
   332 		RDebug::Printf(" z\">", this);
       
   333 	}
       
   334 
       
   335 	RDebug::Printf("</missing-glyph>", this);
       
   336 	#endif
       
   337 	}
       
   338 }
       
   339 #endif     //ifdef SVG_FONTS_INCLUDE