fontservices/fontstore/src/FNTBODY.CPP
branchRCL_3
changeset 1 e96e8a131979
parent 0 1fb32624e06b
child 16 748ec5531811
equal deleted inserted replaced
0:1fb32624e06b 1:e96e8a131979
   215 
   215 
   216 TCharacterMetricsTable::TCharacterMetricsTable(RHeap* aHeap)
   216 TCharacterMetricsTable::TCharacterMetricsTable(RHeap* aHeap)
   217  :	iHeap(aHeap),
   217  :	iHeap(aHeap),
   218 	iMetricsStartId(KNullStreamId),
   218 	iMetricsStartId(KNullStreamId),
   219 	iCharacterMetricsStartPtr(0),
   219 	iCharacterMetricsStartPtr(0),
   220 	iNumberOfMetrics(0)
   220 	iNumberOfMetrics(0),
       
   221 	iMetricsOnHeap(EFalse)
   221 	{}
   222 	{}
   222 
   223 
   223 void TCharacterMetricsTable::InternalizeL(RReadStream& aStream)
   224 void TCharacterMetricsTable::InternalizeL(RReadStream& aStream)
   224 	{
   225 	{
   225 	iMetricsStartId = aStream.ReadInt32L();
   226 	iMetricsStartId = aStream.ReadInt32L();
   228 
   229 
   229 void TCharacterMetricsTable::InternalizeMetricsL(RReadStream& aStream)
   230 void TCharacterMetricsTable::InternalizeMetricsL(RReadStream& aStream)
   230 	{
   231 	{
   231 	aStream.ReadInt32L(); // size
   232 	aStream.ReadInt32L(); // size
   232 	TBitmapFontCharacterMetrics* charactermetricslist = static_cast<TBitmapFontCharacterMetrics*>(iHeap->AllocL(sizeof(TBitmapFontCharacterMetrics) * iNumberOfMetrics));
   233 	TBitmapFontCharacterMetrics* charactermetricslist = static_cast<TBitmapFontCharacterMetrics*>(iHeap->AllocL(sizeof(TBitmapFontCharacterMetrics) * iNumberOfMetrics));
   233 	
   234 	iMetricsOnHeap = ETrue;
   234 	iCharacterMetricsStartPtr = TInt(charactermetricslist); // Ptr to location on the heap ('cos the file is not in ROM)
   235 	// Offset from this to location on the heap ('cos the file is not in ROM)
       
   236 	iCharacterMetricsStartPtr = reinterpret_cast<TInt>(charactermetricslist) - reinterpret_cast<TInt>(this);
   235 	TBitmapFontCharacterMetrics* pEnd = charactermetricslist + iNumberOfMetrics;
   237 	TBitmapFontCharacterMetrics* pEnd = charactermetricslist + iNumberOfMetrics;
   236 	for (TBitmapFontCharacterMetrics* p = charactermetricslist; p < pEnd; p++)
   238 	for (TBitmapFontCharacterMetrics* p = charactermetricslist; p < pEnd; p++)
   237 		{
   239 		{
   238 		p->InternalizeL(aStream);
   240 		p->InternalizeL(aStream);
   239 		}
   241 		}
   253 void TCharacterMetricsTable::FixUp(TInt aFileAddress)
   255 void TCharacterMetricsTable::FixUp(TInt aFileAddress)
   254 	{
   256 	{
   255 	TBitmapFontCharacterMetrics* charactermetricslist = reinterpret_cast<TBitmapFontCharacterMetrics*>(aFileAddress + sizeof(TInt) + iMetricsStartId.Value());
   257 	TBitmapFontCharacterMetrics* charactermetricslist = reinterpret_cast<TBitmapFontCharacterMetrics*>(aFileAddress + sizeof(TInt) + iMetricsStartId.Value());
   256 	iCharacterMetricsStartPtr = TInt(charactermetricslist);	// Ptr to location in a ROM file
   258 	iCharacterMetricsStartPtr = TInt(charactermetricslist);	// Ptr to location in a ROM file
   257 	iMetricsStartId = KNullStreamId;
   259 	iMetricsStartId = KNullStreamId;
       
   260 	iMetricsOnHeap = EFalse;
   258 	}
   261 	}
   259 
   262 
   260 void TCharacterMetricsTable::Delete()
   263 void TCharacterMetricsTable::Delete()
   261 	{	// This routine is only called if the font file is in RAM, not ROM, and therefore the metrics have been stashed on the heap
   264 	{	// This routine is only called if the font file is in RAM, not ROM, and therefore the metrics have been stashed on the heap
   262 	if (iCharacterMetricsStartPtr)
   265     if (iMetricsOnHeap && iCharacterMetricsStartPtr)
   263 		{
   266         {
   264 		iHeap->Free(reinterpret_cast<TAny*>(iCharacterMetricsStartPtr));
   267         iHeap->Free(reinterpret_cast<TAny*>(MetricsFromOffset(0)));
   265 		iCharacterMetricsStartPtr = 0;
   268         iCharacterMetricsStartPtr = 0;
   266 		}
   269         iMetricsOnHeap = EFalse;
       
   270         }
   267 	}
   271 	}
   268 
   272 
   269 const TBitmapFontCharacterMetrics* TCharacterMetricsTable::Metric(TInt aIndex) const
   273 const TBitmapFontCharacterMetrics* TCharacterMetricsTable::Metric(TInt aIndex) const
   270 	{
   274 	{
   271 	__ASSERT_DEBUG((aIndex >= 0) && (aIndex <= iNumberOfMetrics), Panic(EFntMetricsIndexOutOfBounds));
   275 	__ASSERT_DEBUG((aIndex >= 0) && (aIndex <= iNumberOfMetrics), Panic(EFntMetricsIndexOutOfBounds));
   272 	// Sometimes the start ptr is to a metrics heap item and sometimes it points into a ROM file
   276     // Sometimes the start ptr is to a metrics heap item and sometimes it points into a ROM file
   273 	return reinterpret_cast<const TBitmapFontCharacterMetrics*>(iCharacterMetricsStartPtr + (aIndex * sizeof(TBitmapFontCharacterMetrics)));
   277     if (iMetricsOnHeap)
       
   278         {
       
   279         // Start ptr is to metrics heap item
       
   280         return MetricsFromOffset(aIndex);
       
   281         }
       
   282     else
       
   283         {
       
   284         // Start ptr is to a file in ROM
       
   285         return reinterpret_cast<const TBitmapFontCharacterMetrics*> (iCharacterMetricsStartPtr + (aIndex * sizeof(TBitmapFontCharacterMetrics)));
       
   286         }
   274 	}
   287 	}
   275 
   288 
   276 TInt TCharacterMetricsTable::NumberOfMetrics() const
   289 TInt TCharacterMetricsTable::NumberOfMetrics() const
   277 	{
   290 	{
   278 	return iNumberOfMetrics;
   291 	return iNumberOfMetrics;
   279 	}
   292 	}
       
   293 
       
   294 TBitmapFontCharacterMetrics* TCharacterMetricsTable::MetricsFromOffset(TInt aIndex) const
       
   295     {
       
   296     __ASSERT_DEBUG(iMetricsOnHeap,Panic(EFntMetricsNotOnHeap));
       
   297     return reinterpret_cast<TBitmapFontCharacterMetrics*>(reinterpret_cast<TInt>(this) + iCharacterMetricsStartPtr+ (aIndex * sizeof(TBitmapFontCharacterMetrics)));
       
   298     }
   280 
   299 
   281 CFontBitmap::CFontBitmap(RHeap* aHeap, CFontStoreFile* aFontStoreFile)
   300 CFontBitmap::CFontBitmap(RHeap* aHeap, CFontStoreFile* aFontStoreFile)
   282  :	iHeap(aHeap),
   301  :	iHeap(aHeap),
   283 	iFontStoreFileOffset(0),
   302 	iFontStoreFileOffset(0),
   284 	iUid(KNullUid),
   303 	iUid(KNullUid),