svgtopt/SVG/SVGImpl/src/SVGGlyphElementImpl.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 "SVGGlyphElementImpl.h"
       
    23 #include "SVGElementImpl.h"
       
    24 #include "SVGDocumentImpl.h"
       
    25 #include "SVGSchemaData.h"
       
    26 #include "SVGPathDataParser.h"
       
    27 #include "SVGPathElementImpl.h"
       
    28 
       
    29 #include "GfxAffineTransform.h"
       
    30 
       
    31 #ifdef SVG_FONTS_INCLUDE
       
    32 
       
    33 _LIT( SPACE, " " );
       
    34 _LIT( D, "d" );
       
    35 
       
    36 // ==========================================================================
       
    37 // Need method description
       
    38 // ==========================================================================
       
    39 CSvgGlyphElementImpl* CSvgGlyphElementImpl::NewL(  const TUint8 aElemID,
       
    40 												  CSvgDocumentImpl* aDoc )
       
    41 	{
       
    42 	CSvgGlyphElementImpl*   self    = new ( ELeave )
       
    43 									  CSvgGlyphElementImpl( aDoc );
       
    44 	CleanupStack::PushL( self );
       
    45 	self->ConstructL(   aElemID);
       
    46 	CleanupStack::Pop();
       
    47 
       
    48 	return self;
       
    49 	}
       
    50 
       
    51 // ==========================================================================
       
    52 // Need method description
       
    53 // ==========================================================================
       
    54 CSvgGlyphElementImpl* CSvgGlyphElementImpl::NewLC(  const TUint8 aElemID,
       
    55 												   CSvgDocumentImpl* aDoc )
       
    56 	{
       
    57 	CSvgGlyphElementImpl*   self    = new ( ELeave )
       
    58 									  CSvgGlyphElementImpl( aDoc );
       
    59 	CleanupStack::PushL( self );
       
    60 	self->ConstructL(   aElemID);
       
    61 
       
    62 	return self;
       
    63 	}
       
    64 
       
    65 // ==========================================================================
       
    66 // Need method description
       
    67 // ==========================================================================
       
    68 void CSvgGlyphElementImpl::ConstructL(  const TUint8 aElemID )
       
    69 	{
       
    70 
       
    71 	CSvgElementImpl::InitializeL( aElemID);
       
    72 
       
    73 	iOwnedPath = EFalse;
       
    74 	iUnicode = HBufC::NewL( 2 );
       
    75 	*iUnicode = SPACE;
       
    76 	iGlyphName = HBufC::NewL( 0 );
       
    77 	iLangCode = HBufC::NewL( 0 );
       
    78 	iShape = CGfxGeneralPath::NewL();
       
    79 	#ifdef SVG_FLOAT_BUILD
       
    80   iHorzAdvX = TFloatFixPt( 0 );
       
    81 	#else
       
    82     iHorzAdvX = TFloatFixPt( 0 , ETrue);
       
    83 	#endif
       
    84 
       
    85     iSvgStyleProperties = new(ELeave) RPointerArray<CCssValue>(KCSS_MAX_ATTR);
       
    86     User::LeaveIfError( iSvgStyleProperties->Append( NULL ) );
       
    87 iSvgStyleProperties->Remove( 0 );
       
    88 
       
    89 
       
    90 	}
       
    91 
       
    92 
       
    93 
       
    94 
       
    95 
       
    96 
       
    97 // ==========================================================================
       
    98 // Need method description
       
    99 // ==========================================================================
       
   100 
       
   101 CSvgGlyphElementImpl::CSvgGlyphElementImpl( CSvgDocumentImpl* aDoc )
       
   102     {
       
   103 	SetOwnerDocument(aDoc);
       
   104     }
       
   105 
       
   106 
       
   107 // ==========================================================================
       
   108 // Need method description
       
   109 // ==========================================================================
       
   110 CSvgGlyphElementImpl::~CSvgGlyphElementImpl()
       
   111     {
       
   112 	if ( iUnicode )
       
   113 		{
       
   114 		delete iUnicode;
       
   115 		iUnicode = NULL;
       
   116 		}
       
   117 
       
   118 	if ( iGlyphName )
       
   119 		{
       
   120 		delete iGlyphName;
       
   121 		iGlyphName =  NULL;
       
   122 		}
       
   123 
       
   124 	if ( iLangCode )
       
   125 		{
       
   126 		delete iLangCode;
       
   127 		iLangCode = NULL;
       
   128 		}
       
   129 
       
   130 	if ( iShape )
       
   131 		{
       
   132 		CSvgElementImpl* aChild = (CSvgElementImpl*)FirstChild();
       
   133 		if (!(aChild && aChild->ElemID() == KSvgPathElement))
       
   134 			{
       
   135 			delete iShape;
       
   136 			iShape = NULL;
       
   137 			}
       
   138 		else if ( iOwnedPath )
       
   139 			{
       
   140 			delete iShape;
       
   141 			}
       
   142 		iShape = NULL;
       
   143 		}
       
   144 
       
   145 	if ( iSvgStyleProperties )
       
   146 		{
       
   147 		iSvgStyleProperties->Close();
       
   148 		delete iSvgStyleProperties;
       
   149 		iSvgStyleProperties = NULL;
       
   150 		}
       
   151 
       
   152     }
       
   153 
       
   154 // ==========================================================================
       
   155 // Need method description
       
   156 // ==========================================================================
       
   157 void CSvgGlyphElementImpl::GetBBox( TGfxRectangle2D& aBbox )
       
   158     {
       
   159     iShape->GetBounds( GetCTM(), aBbox );
       
   160     }
       
   161 
       
   162 // ==========================================================================
       
   163 // Need method description
       
   164 // ==========================================================================
       
   165 void CSvgGlyphElementImpl::GetUnscaledBBox( TGfxRectangle2D& aBbox )
       
   166     {
       
   167     TGfxAffineTransform identityTx;
       
   168     iShape->GetBounds( identityTx, aBbox );
       
   169     }
       
   170 
       
   171 // *******************************************************
       
   172 // From SVG DOM
       
   173 
       
   174 // ==========================================================================
       
   175 // Need method description
       
   176 // ==========================================================================
       
   177 void CSvgGlyphElementImpl::GetUnicode( TDes& aUnicode )
       
   178     {
       
   179     aUnicode = iUnicode->Des();
       
   180     }
       
   181 
       
   182 // ==========================================================================
       
   183 // Need method description
       
   184 // ==========================================================================
       
   185 TFloatFixPt CSvgGlyphElementImpl::GetHorzAdvX()
       
   186     {
       
   187     return iHorzAdvX;
       
   188     }
       
   189 
       
   190 
       
   191 // *******************************************************
       
   192 // SVG Implementation
       
   193 
       
   194 
       
   195 
       
   196 
       
   197 // ==========================================================================
       
   198 // Need method description
       
   199 // ==========================================================================
       
   200 void CSvgGlyphElementImpl::SetPath( const TDesC& aPath )
       
   201     {
       
   202 	TSvgPathDataParser::ParsePathData( aPath, iShape );
       
   203     }
       
   204 
       
   205 
       
   206 // *******************************************************
       
   207 // From MXmlElementOpt
       
   208 
       
   209 // ==========================================================================
       
   210 // Need method description
       
   211 // ==========================================================================
       
   212 TInt CSvgGlyphElementImpl::GetAttributeFloat( const TInt aNameId,
       
   213                                                TFloatFixPt& aValue )
       
   214     {
       
   215     switch ( aNameId )
       
   216         {
       
   217         case KAtrRefX:
       
   218         aValue = iShape->PointCoordsArray()[0];
       
   219         break;
       
   220         case KAtrRefY:
       
   221         aValue = iShape->PointCoordsArray()[1];
       
   222         break;
       
   223         case KAtrHorizAdvX:
       
   224         aValue = GetHorzAdvX();
       
   225         break;
       
   226         default:
       
   227         return CSvgElementImpl::GetAttributeFloat( aNameId, aValue );
       
   228         }
       
   229     return KErrNone;
       
   230     }
       
   231 
       
   232 // ==========================================================================
       
   233 // Need method description
       
   234 // ==========================================================================
       
   235 TInt CSvgGlyphElementImpl::GetAttributePath( const TInt aNameId,
       
   236                                              CGfxGeneralPath*& aValue )
       
   237     {
       
   238     if ( aNameId == KAtrData )
       
   239         {
       
   240         aValue = iShape;
       
   241         }
       
   242     else
       
   243         {
       
   244         aValue = NULL;
       
   245         return KErrNoAttribute;
       
   246         }
       
   247 
       
   248     return KErrNone;
       
   249     }
       
   250 
       
   251 // ==========================================================================
       
   252 // Need method description
       
   253 // ==========================================================================
       
   254 TInt CSvgGlyphElementImpl::SetAttributePathL( const TInt aNameId,
       
   255                                               CGfxGeneralPath* /* aValue */ )
       
   256     {
       
   257     if ( aNameId == KAtrData )
       
   258         {
       
   259         }
       
   260     else
       
   261         {
       
   262         return KErrNoAttribute;
       
   263         }
       
   264 
       
   265     return KErrNone;
       
   266     }
       
   267 
       
   268 // ==========================================================================
       
   269 // Need method description
       
   270 // ==========================================================================
       
   271 TInt CSvgGlyphElementImpl::SetAttributePathRef( const TInt aNameId,
       
   272                                               CGfxGeneralPath*&  aValue  )
       
   273     {
       
   274     if ( aNameId == KAtrData )
       
   275         {
       
   276 		if(iShape)
       
   277 			{
       
   278 			delete iShape;
       
   279 			iShape= NULL;
       
   280 			}
       
   281 		iShape= aValue;
       
   282 
       
   283         }
       
   284     else
       
   285         {
       
   286         return KErrNoAttribute;
       
   287         }
       
   288 
       
   289     return KErrNone;
       
   290     }
       
   291 // ==========================================================================
       
   292 // Need method description
       
   293 // ==========================================================================
       
   294 TInt CSvgGlyphElementImpl::GetAttributeDes( const TInt aNameId, TPtrC16& aValue )
       
   295     {
       
   296     switch ( aNameId )
       
   297         {
       
   298         case KAtrUnicode:
       
   299         if ( iUnicode->Length() > 0 )
       
   300             {
       
   301             aValue.Set( *iUnicode );
       
   302             break;
       
   303             }
       
   304         else
       
   305             return KErrNoAttribute;
       
   306 
       
   307         case KAtrGlyphName:
       
   308         if ( iGlyphName->Length() > 0 )
       
   309             {
       
   310             aValue.Set( *iGlyphName );
       
   311             break;
       
   312             }
       
   313         else
       
   314             return KErrNoAttribute;
       
   315 
       
   316         case KAtrLang:
       
   317         if ( iLangCode->Length() > 0 )
       
   318             {
       
   319             aValue.Set( *iLangCode );
       
   320             break;
       
   321             }
       
   322         else
       
   323             return KErrNoAttribute;
       
   324 
       
   325         default:
       
   326         return CSvgElementImpl::GetAttributeDes( aNameId, aValue );
       
   327         }
       
   328     return KErrNone;
       
   329     }
       
   330 
       
   331 // *******************************************************
       
   332 // From MXmlElement
       
   333 
       
   334 
       
   335 // ==========================================================================
       
   336 // Need method description
       
   337 // ==========================================================================
       
   338 TInt CSvgGlyphElementImpl::SetAttributeL( const TDesC& aName,
       
   339                                           const TDesC& aValue )
       
   340     {
       
   341 	CSvgElementImpl::SetAttributeL(aName,aValue);
       
   342 	if( aName == D )
       
   343 		{
       
   344 		SetPath (aValue);
       
   345 		iOwnedPath = ETrue;
       
   346 		}
       
   347     return KErrNone;
       
   348     }
       
   349 
       
   350 
       
   351 // ==========================================================================
       
   352 // Need method description
       
   353 // ==========================================================================
       
   354 TInt CSvgGlyphElementImpl::SetAttributeFloatL( const TInt aNameId,
       
   355                                                const TFloatFixPt aValue )
       
   356 	{
       
   357 		if( aNameId == KAtrHorizAdvX )
       
   358 			{
       
   359 			iHorzAdvX = aValue;
       
   360 			}
       
   361 		else return CSvgElementImpl::SetAttributeFloatL( aNameId, aValue );
       
   362     return KErrNone;
       
   363 	}
       
   364 
       
   365 // ==========================================================================
       
   366 // Need method description
       
   367 // ==========================================================================
       
   368 TInt  CSvgGlyphElementImpl::SetAttributeDesL( const TInt aNameId, const TDesC& aValue )
       
   369 {
       
   370 	switch (aNameId)
       
   371 		{
       
   372 		case KAtrUnicode:
       
   373 						delete iUnicode;
       
   374 						iUnicode = NULL;
       
   375 						iUnicode = aValue.AllocL();
       
   376 						//iUnicode->Des().ZeroTerminate();
       
   377 						break;
       
   378 		case KAtrGlyphName:
       
   379 						delete iGlyphName;
       
   380 						iGlyphName = NULL;
       
   381 						iGlyphName = aValue.AllocL();
       
   382 						break;
       
   383 		case KAtrLang:
       
   384 						delete iLangCode;
       
   385 						iLangCode = NULL;
       
   386 						iLangCode = aValue.AllocL();
       
   387 						break;
       
   388 
       
   389 		default:		return CSvgElementImpl::SetAttributeDesL( aNameId, aValue );
       
   390 
       
   391 		}
       
   392 	return KErrNone;
       
   393 }
       
   394 
       
   395 
       
   396 // *******************************************************
       
   397 // From CSvgElementImpl
       
   398 
       
   399 // perform a deep clone of this object
       
   400 // ==========================================================================
       
   401 // Need method description
       
   402 // ==========================================================================
       
   403 MXmlElement* CSvgGlyphElementImpl::CloneL(MXmlElement*)
       
   404     {
       
   405     return NULL;
       
   406     }
       
   407 
       
   408 // ==========================================================================
       
   409 // Need method description
       
   410 // ==========================================================================
       
   411 TBool CSvgGlyphElementImpl::DrawL( CGfx2dGc* /* aGc */,
       
   412                                    CSvgElementImpl* /* aElement */ )
       
   413     {
       
   414     return EFalse;
       
   415     }
       
   416 
       
   417 
       
   418 // *******************************************************
       
   419 // Private
       
   420 
       
   421 CGfxGeneralPath* CSvgGlyphElementImpl::GetPathAttribute(TInt aAttributeId)
       
   422 	{
       
   423 	if(aAttributeId == KAtrD)
       
   424 		{
       
   425 		return iShape;
       
   426 		}
       
   427 	else
       
   428 		{
       
   429 		return NULL;
       
   430 		}
       
   431 	}
       
   432 void CSvgGlyphElementImpl::SetPathAttribute(TInt aAttributeId, CGfxGeneralPath* aPathHandle)
       
   433 {
       
   434 	if(aAttributeId == KAtrD)
       
   435 		{
       
   436 		if(iShape == aPathHandle)
       
   437 			{
       
   438 			return;
       
   439 			}
       
   440 		delete iShape;
       
   441 		iShape = aPathHandle;
       
   442 		}
       
   443 }
       
   444 
       
   445 void CSvgGlyphElementImpl::Print( TBool aIsEncodeOn )
       
   446 {
       
   447 	if (!aIsEncodeOn)
       
   448 	{
       
   449 	#ifdef _DEBUG
       
   450 	if (iGlyphName)
       
   451 	{
       
   452 	RDebug::Printf("<glyph name=\"%s\" unicode=\"%d\" lang=\"%d\" horiz-adv-x=\"%d\" >",
       
   453 	iGlyphName, (int)iUnicode, (int)iLangCode, (int)iHorzAdvX);
       
   454 
       
   455 	if (iShape)
       
   456 	{
       
   457 		RArray<TUint32>* lTypes = iShape->PointTypeArray();
       
   458 		RArray<TFloatFixPt>* lCoords = iShape->PointCoordsArrayAll();
       
   459 
       
   460 		if (lTypes->Count() != lCoords->Count())
       
   461 		{
       
   462 			RDebug::Printf("Invalid path points and types didnt match", this);
       
   463 			return;
       
   464 		}
       
   465 
       
   466 		RDebug::Printf("<path d=\"", this);
       
   467 
       
   468 		TInt lTypesCnt = lTypes->Count();
       
   469 		for (TInt i=0; i < lTypesCnt; i++)
       
   470 		{
       
   471 			RDebug::Printf("%c ", lTypes->operator[]( i ));
       
   472 			RDebug::Printf("%d ", (int)(lCoords->operator[]( i )));
       
   473 		}
       
   474 
       
   475 		RDebug::Printf(" z\">", this);
       
   476 	}
       
   477 
       
   478 	RDebug::Printf("</glyph>", this);
       
   479 	}
       
   480 	#endif
       
   481 	}
       
   482 }
       
   483 #endif    //ifdef SVG_FONTS_INCLUDE