svgtopt/SVG/SVGImpl/src/SVGImageHashMap.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 #include "SVGImageHashMap.h"
       
    20 
       
    21 // DECODED IMAGE STORAGE FOR IMAGE ELEMENTS TO SHARE
       
    22 // SO IMAGES WITH THE SAME XLINK-HREF don't have to decode twice
       
    23 // SVG FONT STORAGE FOR JSR 226 ONLY
       
    24 // BECAUSE WE DONT HAVE AN ENGINE AT PARSE TIME
       
    25 // FOR SVG FONTS
       
    26 
       
    27 // ==========================================================================
       
    28 // Need method description
       
    29 // ==========================================================================
       
    30 CSvgImageHashMap* CSvgImageHashMap::NewL()
       
    31     {
       
    32     CSvgImageHashMap*   self    = new ( ELeave ) CSvgImageHashMap;
       
    33     CleanupStack::PushL( self );
       
    34     self->ConstructL();
       
    35     CleanupStack::Pop();
       
    36 
       
    37     return self;
       
    38     }
       
    39 
       
    40 // ==========================================================================
       
    41 // Need method description
       
    42 // ==========================================================================
       
    43 CSvgImageHashMap* CSvgImageHashMap::NewLC()
       
    44     {
       
    45     CSvgImageHashMap*   self    = new ( ELeave ) CSvgImageHashMap;
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL();
       
    48 
       
    49     return self;
       
    50     }
       
    51 
       
    52 // ==========================================================================
       
    53 // Need method description
       
    54 // ==========================================================================
       
    55 void CSvgImageHashMap::ConstructL()
       
    56     {
       
    57     }
       
    58 
       
    59 // ==========================================================================
       
    60 // Need method description
       
    61 // ==========================================================================
       
    62 CSvgImageHashMap::CSvgImageHashMap()
       
    63 
       
    64     {
       
    65     }
       
    66 
       
    67 // ==========================================================================
       
    68 // Need method description
       
    69 // ==========================================================================
       
    70 CSvgImageHashMap::~CSvgImageHashMap()
       
    71     {
       
    72     	iSvgImageMapItems.ResetAndDestroy();
       
    73     	iSvgImageMapItems.Close();
       
    74     }
       
    75 
       
    76 // ==========================================================================
       
    77 // CSvgImageHashMap::AddImageL( CFbsBitmap* aImagePtr,
       
    78 //                                 const TDesC& aImageName )
       
    79 // return ETrue if image added
       
    80 // return EFalse if image was already in map
       
    81 // ==========================================================================
       
    82 TBool CSvgImageHashMap::AddImageL( CFbsBitmap* aImagePtr,
       
    83                                  const TDesC& aImageName )
       
    84 {
       
    85 	CSvgImageMapItem* lImageMapItem = GetImageMapItem( aImageName );
       
    86 
       
    87     	if (lImageMapItem)
       
    88     	{
       
    89     		//already a reference to this image in the image map
       
    90     		lImageMapItem->IncrementReferenceCount();
       
    91     		return EFalse;
       
    92     	}
       
    93     	else
       
    94     	{
       
    95     		//didnt find that image in the image map...add it
       
    96 			CSvgImageMapItem* lNewSvgImageMapItem = CSvgImageMapItem::NewL( );
       
    97 
       
    98 			lNewSvgImageMapItem->SetImagePtr( aImagePtr );
       
    99        		lNewSvgImageMapItem->CopyImageNameL( aImageName );
       
   100        		lNewSvgImageMapItem->IncrementReferenceCount();
       
   101 
       
   102 			iSvgImageMapItems.Append(lNewSvgImageMapItem);
       
   103 
       
   104 			return ETrue;
       
   105 		}
       
   106 }
       
   107 
       
   108 // --------------------------------------------------------------------------
       
   109 // TBool CSvgImageHashMap::HasImageName( const TDesC& aImageName
       
   110 // ---------------------------------------------------------------------------
       
   111 TBool CSvgImageHashMap::HasImageName( const TDesC& aImageName )
       
   112     {
       
   113         TBool lHaveImage = EFalse;
       
   114 
       
   115 		TInt svgImageMapItemsCnt = iSvgImageMapItems.Count();
       
   116         for (TInt i=0; i < svgImageMapItemsCnt; i++)
       
   117         {
       
   118             if ( aImageName == ((CSvgImageMapItem*)iSvgImageMapItems[i])->GetImageName() )
       
   119             {
       
   120                 lHaveImage = ETrue;
       
   121             }
       
   122         }
       
   123 
       
   124         return lHaveImage;
       
   125 
       
   126     }
       
   127 
       
   128 // --------------------------------------------------------------------------
       
   129 // CSvgImageMapItem* CSvgImageHashMap::GetImageMapItem( const TDesC& aImageName
       
   130 // ---------------------------------------------------------------------------
       
   131 CSvgImageMapItem* CSvgImageHashMap::GetImageMapItem( const TDesC& aImageName )
       
   132 {
       
   133 	TInt svgImageMapItemsCnt = iSvgImageMapItems.Count();
       
   134 	for ( TInt i = 0; i < svgImageMapItemsCnt; i++ )
       
   135             {
       
   136             CSvgImageMapItem* lImageMap = (CSvgImageMapItem*)iSvgImageMapItems[i];
       
   137 
       
   138 			TInt result = aImageName.Compare( lImageMap->GetImageName() );
       
   139 
       
   140             if ( result == 0 )
       
   141                 {
       
   142 					return lImageMap;
       
   143 				}
       
   144 			}
       
   145 
       
   146 	return NULL;
       
   147 }
       
   148 
       
   149 // --------------------------------------------------------------------------
       
   150 // TBool CSvgDocumentImpl::RemoveReferenceFromImageL( const TDesC& aImageName )
       
   151 // returns True if there aren't any left
       
   152 // returns False if there are references to that image left
       
   153 // ---------------------------------------------------------------------------
       
   154 TBool CSvgImageHashMap::RemoveReferenceFromImageL( const TDesC& aImageName )
       
   155     {
       
   156 
       
   157 		CSvgImageMapItem* lImageMapItem = GetImageMapItem( aImageName );
       
   158 
       
   159 		if (lImageMapItem != NULL)
       
   160 		{
       
   161 			//we have this lImageMapElement
       
   162 			TInt aReferenceCount = lImageMapItem->DecrementReferenceCount();
       
   163 
       
   164 			if (aReferenceCount <= 0)
       
   165 			{
       
   166 				//no more references to this image remove it from the map
       
   167 				iSvgImageMapItems.Remove(iSvgImageMapItems.Find(lImageMapItem));
       
   168 				delete lImageMapItem;
       
   169 				return ETrue;
       
   170 			}
       
   171 		}
       
   172 
       
   173 		return EFalse;
       
   174     }
       
   175 
       
   176 // --------------------------------------------------------------------------
       
   177 // CFbsBitmap* CSvgDocumentImpl::GetImagePtr( const TDesC& aImageName )
       
   178 // ---------------------------------------------------------------------------
       
   179 CFbsBitmap* CSvgImageHashMap::GetImagePtr( const TDesC& aImageName )
       
   180     {
       
   181 
       
   182     CSvgImageMapItem* lImageMapItem = GetImageMapItem( aImageName );
       
   183 
       
   184     if (lImageMapItem)
       
   185     	{
       
   186     	return (lImageMapItem->GetImagePtr());
       
   187     	}
       
   188 
       
   189     	return NULL;
       
   190 
       
   191     }
       
   192 
       
   193 // ==========================================================================
       
   194 // Need method description
       
   195 // ==========================================================================
       
   196 CSvgImageMapItem* CSvgImageMapItem::NewL()
       
   197     {
       
   198     CSvgImageMapItem*   self    = new ( ELeave ) CSvgImageMapItem;
       
   199     CleanupStack::PushL( self );
       
   200     self->ConstructL();
       
   201     CleanupStack::Pop();
       
   202 
       
   203     return self;
       
   204     }
       
   205 
       
   206 // ==========================================================================
       
   207 // Need method description
       
   208 // ==========================================================================
       
   209 CSvgImageMapItem* CSvgImageMapItem::NewLC()
       
   210     {
       
   211     CSvgImageMapItem*   self    = new ( ELeave ) CSvgImageMapItem;
       
   212     CleanupStack::PushL( self );
       
   213     self->ConstructL();
       
   214 
       
   215     return self;
       
   216     }
       
   217 
       
   218 // ==========================================================================
       
   219 // Need method description
       
   220 // ==========================================================================
       
   221 void CSvgImageMapItem::ConstructL()
       
   222     {
       
   223     }
       
   224 
       
   225 // ==========================================================================
       
   226 // Need method description
       
   227 // ==========================================================================
       
   228 CSvgImageMapItem::CSvgImageMapItem(): iImageDecodingStatus(EFalse)
       
   229 
       
   230     {
       
   231     }
       
   232 
       
   233 // ==========================================================================
       
   234 // Need method description
       
   235 // ==========================================================================
       
   236 CSvgImageMapItem::~CSvgImageMapItem()
       
   237     {
       
   238     	if (iImageName->Length())
       
   239     	{
       
   240     		//delete the xlink-href (base64 image data
       
   241     		delete iImageName;
       
   242     		iImageName = NULL;
       
   243     	}
       
   244     	/*if (iImagePtr)
       
   245     	{
       
   246     		//delete the bitmap
       
   247     		delete iImagePtr;
       
   248     	}*/
       
   249     }
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 // ---------------------------------------------------------------------------
       
   254 CFbsBitmap* CSvgImageMapItem::GetImagePtr()
       
   255     {
       
   256     return iImagePtr;
       
   257     }
       
   258 
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 // ---------------------------------------------------------------------------
       
   263 const TDesC& CSvgImageMapItem::GetImageName()
       
   264     {
       
   265     return ( const TDesC & ) *iImageName;
       
   266     }
       
   267 
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 // ---------------------------------------------------------------------------
       
   271 void CSvgImageMapItem::SetImagePtr( CFbsBitmap* aImagePtr )
       
   272     {
       
   273     iImagePtr = aImagePtr;
       
   274     }
       
   275 
       
   276 
       
   277 // ---------------------------------------------------------------------------
       
   278 //
       
   279 // ---------------------------------------------------------------------------
       
   280 void CSvgImageMapItem::CopyImageNameL( const TDesC& aImageName )
       
   281     {
       
   282     iImageName = aImageName.AllocL();
       
   283     }
       
   284 
       
   285 //----------------------------------------------------------------------
       
   286 //
       
   287 //-----------------------------------------------------------------------
       
   288 void CSvgImageMapItem::SetImageDecodingStatus( TBool aThisImageIsDecoding )
       
   289 	{
       
   290 	iImageDecodingStatus = aThisImageIsDecoding;
       
   291 	}
       
   292 
       
   293 //----------------------------------------------------------------------
       
   294 //
       
   295 //----------------------------------------------------------------------
       
   296 TBool CSvgImageMapItem::GetImageDecodingStatus( )
       
   297 	{
       
   298 	return iImageDecodingStatus;
       
   299 	}
       
   300 
       
   301 //-----------------------------------------------------------------------
       
   302 //
       
   303 //-----------------------------------------------------------------------
       
   304 TInt CSvgImageMapItem::IncrementReferenceCount( )
       
   305 	{
       
   306 	iImageReferenceCount++;
       
   307 	return iImageReferenceCount;
       
   308 	}
       
   309 
       
   310 //-----------------------------------------------------------------------
       
   311 //
       
   312 //-----------------------------------------------------------------------
       
   313 TInt CSvgImageMapItem::DecrementReferenceCount()
       
   314 	{
       
   315 	iImageReferenceCount--;
       
   316 	return iImageReferenceCount;
       
   317 	}
       
   318 
       
   319