svgtopt/SVG/SVGImpl/src/SVGFontFaceElementImpl.cpp
changeset 0 d46562c3d99d
child 17 db5c883ad1c5
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 "SVGFontFaceElementImpl.h"
       
    23 #include "SVGDocumentImpl.h"
       
    24 #include "SVGSchemaData.h"
       
    25 #include "SVGEngineImpl.h"
       
    26 
       
    27 #include "GfxAffineTransform.h"
       
    28 #include "SVGFontHashMap.h"
       
    29 
       
    30 #ifdef SVG_FONTS_INCLUDE
       
    31 
       
    32 _LIT( SPACE, " " );
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 // ---------------------------------------------------------------------------
       
    37 CSvgFontFaceElementImpl* CSvgFontFaceElementImpl::NewL(  const TUint8 aElemID,
       
    38                                                         CSvgDocumentImpl* aDoc )
       
    39     {
       
    40     CSvgFontFaceElementImpl*self    = new ( ELeave )
       
    41                                       CSvgFontFaceElementImpl( aDoc );
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL(   aElemID);
       
    44     CleanupStack::Pop();
       
    45 
       
    46     return self;
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 // ---------------------------------------------------------------------------
       
    52 CSvgFontFaceElementImpl* CSvgFontFaceElementImpl::NewLC(  const TUint8 aElemID,
       
    53                                                      CSvgDocumentImpl* aDoc )
       
    54     {
       
    55     CSvgFontFaceElementImpl*self    = new ( ELeave )
       
    56                                       CSvgFontFaceElementImpl( aDoc );
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL(   aElemID);
       
    59 
       
    60     return self;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 // ---------------------------------------------------------------------------
       
    66 void CSvgFontFaceElementImpl::ConstructL(  const TUint8 aElemID)
       
    67     {
       
    68     CSvgElementImpl::InitializeL( aElemID);
       
    69     iFontFamily = HBufC::NewL( 2 );
       
    70     *iFontFamily = SPACE;
       
    71 
       
    72     iUnicodeRange = HBufC::NewL( 2 );
       
    73     *iUnicodeRange = SPACE;
       
    74 
       
    75 	#ifdef SVG_FLOAT_BUILD	
       
    76     iUnitsPerEm = TFloatFixPt( 0 );
       
    77     iAlphabetic = TFloatFixPt( 0 );
       
    78 
       
    79     iAscent = TFloatFixPt( 0 );
       
    80     iDescent = TFloatFixPt( 0 );
       
    81 
       
    82     iUnderlinePosition = TFloatFixPt( 0 );
       
    83     iUnderlineThickness = TFloatFixPt( 0 );
       
    84     iOverlinePosition = TFloatFixPt( 0 );
       
    85     iOverlineThickness = TFloatFixPt( 0 );
       
    86     iStrikethroughPosition = TFloatFixPt( 0 );
       
    87     iStrikethroughThickness = TFloatFixPt( 0 );
       
    88 	#else
       
    89     iUnitsPerEm = TFloatFixPt( 0 ,ETrue );
       
    90     iAlphabetic = TFloatFixPt( 0 ,ETrue);
       
    91 
       
    92     iAscent = TFloatFixPt( 0 ,ETrue );
       
    93     iDescent = TFloatFixPt( 0 ,ETrue );
       
    94 
       
    95     iUnderlinePosition = TFloatFixPt( 0 ,ETrue );
       
    96     iUnderlineThickness = TFloatFixPt( 0 ,ETrue );
       
    97     iOverlinePosition = TFloatFixPt( 0 ,ETrue );
       
    98     iOverlineThickness = TFloatFixPt( 0 ,ETrue );
       
    99     iStrikethroughPosition = TFloatFixPt( 0 ,ETrue );
       
   100     iStrikethroughThickness = TFloatFixPt( 0 ,ETrue );
       
   101 	#endif
       
   102 
       
   103     iSvgStyleProperties = new(ELeave) RPointerArray<CCssValue>(KCSS_MAX_ATTR);
       
   104 
       
   105 	// This is required to allocate buffer up to granularity so that the
       
   106     // following Insert calls cannot leave.
       
   107 
       
   108     User::LeaveIfError( iSvgStyleProperties->Append( NULL ) );
       
   109     iSvgStyleProperties->Remove( 0 );
       
   110     }
       
   111 
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 // ---------------------------------------------------------------------------
       
   116 CSvgFontFaceElementImpl::~CSvgFontFaceElementImpl()
       
   117     {
       
   118     //AJD this whole thing needs to be replaced with some sort of external resource registry area....
       
   119     //for images, fonts, other svg files
       
   120     if ( ((CSvgDocumentImpl*)iOwnerDocument)->Engine() && ((CSvgDocumentImpl*)iOwnerDocument)->Engine()->iFontHashMap)
       
   121 	{
       
   122     TRAPD(err, ((CSvgDocumentImpl*)iOwnerDocument)->Engine()->iFontHashMap->RemoveReferenceFromFontL(iFontFamily->Des()));
       
   123     if (err)
       
   124         {
       
   125         #ifdef _DEBUG
       
   126         RDebug::Printf("CSvgFontFaceElementImpl::~CSvgFontFaceElementImpl: Error trapped=%d", err);
       
   127         #endif
       
   128         }
       
   129 	}
       
   130 
       
   131 	if ( (CSvgDocumentImpl*)iOwnerDocument && ((CSvgDocumentImpl*)iOwnerDocument)->iFontHashMap)
       
   132 	{
       
   133 	TRAPD(err, ((CSvgDocumentImpl*)iOwnerDocument)->iFontHashMap->RemoveReferenceFromFontL(iFontFamily->Des()));
       
   134     if (err)
       
   135         {
       
   136         #ifdef _DEBUG
       
   137         RDebug::Printf("CSvgFontFaceElementImpl::~CSvgFontFaceElementImpl: Error trapped=%d", err);
       
   138         #endif
       
   139         }
       
   140 	}
       
   141 
       
   142     if ( iFontFamily )
       
   143         {
       
   144         delete iFontFamily;
       
   145         iFontFamily = NULL;
       
   146         }
       
   147 
       
   148     if ( iUnicodeRange )
       
   149         {
       
   150         delete iUnicodeRange;
       
   151         iUnicodeRange = NULL;
       
   152         }
       
   153 
       
   154     if ( iSvgStyleProperties )
       
   155         {
       
   156         iSvgStyleProperties->Close();
       
   157         delete iSvgStyleProperties;
       
   158         iSvgStyleProperties = NULL;
       
   159         }
       
   160     }
       
   161 
       
   162 // *******************************************************
       
   163 // From SVG DOM
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 // ---------------------------------------------------------------------------
       
   168 const TDesC* CSvgFontFaceElementImpl::GetFontFamily( )
       
   169     {
       
   170      return iFontFamily;
       
   171     }
       
   172 
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 // ---------------------------------------------------------------------------
       
   177 TFloatFixPt CSvgFontFaceElementImpl::GetAscent()
       
   178     {
       
   179     return iAscent;
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 // ---------------------------------------------------------------------------
       
   185 TFloatFixPt CSvgFontFaceElementImpl::GetDescent()
       
   186     {
       
   187     return iDescent;
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 // ---------------------------------------------------------------------------
       
   193 TFloatFixPt CSvgFontFaceElementImpl::GetUnitsPerEm()
       
   194     {
       
   195     return iUnitsPerEm;
       
   196     }
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 // ---------------------------------------------------------------------------
       
   201 TFloatFixPt CSvgFontFaceElementImpl::GetAlphabetic()
       
   202     {
       
   203     return iAlphabetic;
       
   204     }
       
   205 
       
   206 // *******************************************************
       
   207 // SVG Implementation
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 //
       
   211 // ---------------------------------------------------------------------------
       
   212 void CSvgFontFaceElementImpl::SetFontFamilyL( const TDesC& aFontFamily )
       
   213     {
       
   214     if ( iFontFamily )
       
   215         {
       
   216         delete iFontFamily;
       
   217         iFontFamily = NULL;
       
   218         }
       
   219     iFontFamily = aFontFamily.AllocL();
       
   220     
       
   221     if(iOwnerDocument)
       
   222    		{
       
   223    		//FOR JSR226 we have to store at document level
       
   224 		//since it doesnt have an engine at parsing time
       
   225    		((CSvgDocumentImpl*)iOwnerDocument)->iFontHashMap->AddFontL((CSvgFontElementImpl*) ParentNode(), *iFontFamily);	
       
   226    		
       
   227    		//Get the parent element(FontElement) and store it in the FontMap Table.
       
   228    		CSvgEngineImpl* lEngine = ((CSvgDocumentImpl*)iOwnerDocument)->Engine();
       
   229    		if (lEngine)
       
   230    			{
       
   231    			lEngine->iFontHashMap->AddFontL((CSvgFontElementImpl*)ParentNode(), *iFontFamily);
       
   232 			}
       
   233 		
       
   234    		}
       
   235     }
       
   236 // --------------------------------------------------------------------------
       
   237 // CSvgFontFaceElementImpl::RemoveFontFamily
       
   238 // Remove the font-family from the hash map 
       
   239 // --------------------------------------------------------------------------  
       
   240 void CSvgFontFaceElementImpl::RemoveFontFamily(const TDesC& aFontFamily)
       
   241    	{
       
   242    	
       
   243    	if(iOwnerDocument)
       
   244    		{
       
   245    		
       
   246    		((CSvgDocumentImpl*)iOwnerDocument)->iFontHashMap->RemoveReferenceFromFontL(aFontFamily);	
       
   247    		
       
   248    		CSvgEngineImpl* lEngine = ((CSvgDocumentImpl*)iOwnerDocument)->Engine();
       
   249    		if (lEngine)
       
   250    			{
       
   251    			lEngine->iFontHashMap->RemoveReferenceFromFontL(aFontFamily);
       
   252 			}
       
   253 		
       
   254    		}
       
   255     }
       
   256 
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 // ---------------------------------------------------------------------------
       
   260 void CSvgFontFaceElementImpl::SetUnicodeRangeL( const TDesC& aUnicodeRange )
       
   261     {
       
   262     if ( iUnicodeRange )
       
   263         {
       
   264         delete iUnicodeRange;
       
   265         iUnicodeRange = NULL;
       
   266         }
       
   267     iUnicodeRange = aUnicodeRange.AllocL();
       
   268     }
       
   269 
       
   270 
       
   271 
       
   272 // *******************************************************
       
   273 // From MXmlElement
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 // ---------------------------------------------------------------------------
       
   278 TInt CSvgFontFaceElementImpl::SetAttributeL( const TDesC& aName,
       
   279                                              const TDesC& aValue )
       
   280     {
       
   281     CSvgElementImpl::SetAttributeL(aName,aValue);
       
   282     _LIT( KUnicodeRange, "unicode-range" );
       
   283     if ( aName == KUnicodeRange )
       
   284         {
       
   285         SetUnicodeRangeL( aValue );
       
   286         }
       
   287     return KErrNone;
       
   288     }
       
   289 
       
   290 // ---------------------------------------------------------------------------
       
   291 //
       
   292 // ---------------------------------------------------------------------------
       
   293 TInt CSvgFontFaceElementImpl::SetAttributeFloatL( const TInt aNameId,
       
   294                                               const TFloatFixPt aValue )
       
   295     {
       
   296     switch ( aNameId )
       
   297         {
       
   298         case KAtrAscent:                iAscent = aValue;
       
   299                                         break;
       
   300         case KAtrDescent:               iDescent = aValue;
       
   301                                         break;
       
   302         case KAtrAlphabetic:            iAlphabetic = aValue;
       
   303                                         break;
       
   304         case KAtrUnderlinePosition:     iUnderlinePosition = aValue;
       
   305                                         break;
       
   306         case KAtrUnderlineThickness:    iUnderlineThickness = aValue;
       
   307                                         break;
       
   308         case KAtrOverlinePosition:      iOverlinePosition = aValue;
       
   309                                         break;
       
   310         case KAtrOverlineThickness:     iOverlineThickness = aValue;
       
   311                                         break;
       
   312         case KAtrStrikethroughPosition: iStrikethroughPosition = aValue;
       
   313                                         break;
       
   314         case KAtrStrikethroughThickness: iStrikethroughThickness = aValue;
       
   315                                         break;
       
   316         case KAtrUnitsPerEm:            iUnitsPerEm = aValue;
       
   317                                         break;
       
   318         default:
       
   319             return CSvgElementImpl::SetAttributeFloatL( aNameId, aValue );
       
   320         }
       
   321     return KErrNone;
       
   322     }
       
   323 
       
   324 
       
   325 // From MXmlElementOpt
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 //
       
   329 // ---------------------------------------------------------------------------
       
   330 TInt CSvgFontFaceElementImpl::GetAttributeFloat( const TInt aNameId,
       
   331                                                  TFloatFixPt& aValue )
       
   332     {
       
   333     switch ( aNameId )
       
   334         {
       
   335         case KAtrUnitsPerEm:
       
   336         aValue = GetUnitsPerEm();
       
   337         break;
       
   338         case KAtrAscent:
       
   339         aValue = GetAscent();
       
   340         break;
       
   341         case KAtrDescent:
       
   342         aValue = GetDescent();
       
   343         break;
       
   344         case KAtrAlphabetic:
       
   345         aValue = GetAlphabetic();
       
   346         break;
       
   347         case KAtrUnderlinePosition:
       
   348         aValue = iUnderlinePosition;
       
   349         break;
       
   350         case KAtrUnderlineThickness:
       
   351         aValue = iUnderlineThickness;
       
   352         break;
       
   353         case KAtrOverlinePosition:
       
   354         aValue = iOverlinePosition;
       
   355         break;
       
   356         case KAtrOverlineThickness:
       
   357         aValue = iOverlineThickness;
       
   358         break;
       
   359         case KAtrStrikethroughPosition:
       
   360         aValue = iStrikethroughPosition;
       
   361         break;
       
   362         case KAtrStrikethroughThickness:
       
   363         aValue = iStrikethroughThickness;
       
   364         break;
       
   365         default:
       
   366         return CSvgElementImpl::GetAttributeFloat( aNameId, aValue );
       
   367         }
       
   368 
       
   369     return KErrNone;
       
   370     }
       
   371 
       
   372 // ---------------------------------------------------------------------------
       
   373 //
       
   374 // ---------------------------------------------------------------------------
       
   375 TInt CSvgFontFaceElementImpl::GetAttributeDes( const TInt aNameId,
       
   376                                                TPtrC16& aValue )
       
   377     {
       
   378     switch ( aNameId )
       
   379         {
       
   380         case KAtrUnicodeRange:
       
   381             {
       
   382             if ( ( iUnicodeRange->Length() > 2 ) )
       
   383                 {
       
   384                 aValue.Set( *iUnicodeRange );
       
   385                 break;
       
   386                 }
       
   387             else
       
   388                 return KErrNoAttribute;
       
   389             }
       
   390         default:
       
   391         return CSvgElementImpl::GetAttributeDes( aNameId, aValue );
       
   392         }
       
   393     return KErrNone;
       
   394     }
       
   395 
       
   396 // *******************************************************
       
   397 // From CSvgElementImpl
       
   398 
       
   399 // perform a deep clone of this object
       
   400 // ---------------------------------------------------------------------------
       
   401 //
       
   402 // ---------------------------------------------------------------------------
       
   403 MXmlElement* CSvgFontFaceElementImpl::CloneL(MXmlElement*)
       
   404     {
       
   405     return NULL;
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------------------------
       
   409 //
       
   410 // ---------------------------------------------------------------------------
       
   411 TBool CSvgFontFaceElementImpl::DrawL( CGfx2dGc* /* aGc */,
       
   412                                       CSvgElementImpl* /* aElement */ )
       
   413     {
       
   414     return EFalse;
       
   415     }
       
   416 
       
   417 
       
   418 // *******************************************************
       
   419 // Private
       
   420 
       
   421 
       
   422 
       
   423 // ---------------------------------------------------------------------------
       
   424 //
       
   425 // ---------------------------------------------------------------------------
       
   426 
       
   427 CSvgFontFaceElementImpl::CSvgFontFaceElementImpl( CSvgDocumentImpl* aDoc )
       
   428     {
       
   429     SetOwnerDocument(aDoc);
       
   430     }
       
   431 
       
   432 void CSvgFontFaceElementImpl::Print( TBool aIsEncodeOn )
       
   433 {
       
   434 	if (!aIsEncodeOn)
       
   435 	{
       
   436 		#ifdef _DEBUG
       
   437 		RDebug::Printf("<font-face font-family=\"hmm\" alphabetic=\"%d\" underline-position=\"%d\" underline-thickness=\"%d\" overline-position=\"%d\" overline-thickness=\"%d\" strikethrough-position=\"%d\" strikethrough-thickness=\"%d\" unicode-range=\"hmm\" units-per-em=\"%d\" ascent=\"%d\" descent=\"%d\"\\>",
       
   438 		 /*iFontFamily,*/ (int)iAlphabetic, (int)iUnderlinePosition, (int)iUnderlineThickness, (int)iOverlinePosition, (int)iOverlineThickness, (int)iStrikethroughPosition, (int)iStrikethroughThickness, /*iUnicodeRange->Des(),*/ (int)iUnitsPerEm, (int)iAscent, (int)iDescent);
       
   439 		#endif
       
   440 	}
       
   441 }
       
   442 
       
   443 #endif      //ifdef SVG_FONTS_INCLUDE