fontservices/fontstore/src/FNTSTORE.CPP
changeset 46 6124ff6478cc
parent 40 91ef7621b7fc
equal deleted inserted replaced
45:662fa7de7023 46:6124ff6478cc
     1 /*
     1 /*
     2 * Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    78 We can't return 2^32 - 1 sizes, or something that reflect the fact
    78 We can't return 2^32 - 1 sizes, or something that reflect the fact
    79 that any size is okay, because a UI will probably try to create a listbox containing all the sizes.
    79 that any size is okay, because a UI will probably try to create a listbox containing all the sizes.
    80 
    80 
    81 Array stored in Twips as that is the only form of the value currently used.
    81 Array stored in Twips as that is the only form of the value currently used.
    82 @internalComponent
    82 @internalComponent
    83 */ 
    83 */
    84 #define POINTSIZE_IN_TWIPS(p)	((p) * 20)
    84 #define POINTSIZE_IN_TWIPS(p)	((p) * 20)
    85 const TInt gOpenFontSizeInTwipsArray[] =
    85 const TInt gOpenFontSizeInTwipsArray[] =
    86 	{
    86 	{
    87 	// 4pt-18pt in steps of 1pt (15 sizes)
    87 	// 4pt-18pt in steps of 1pt (15 sizes)
    88 	POINTSIZE_IN_TWIPS(4), POINTSIZE_IN_TWIPS(5), POINTSIZE_IN_TWIPS(6),
    88 	POINTSIZE_IN_TWIPS(4), POINTSIZE_IN_TWIPS(5), POINTSIZE_IN_TWIPS(6),
   205  */
   205  */
   206 LOCAL_C TInt PointerToOffset(const TAny* aAny, TUint8* aHeapBase)
   206 LOCAL_C TInt PointerToOffset(const TAny* aAny, TUint8* aHeapBase)
   207     {
   207     {
   208     if (aAny && aHeapBase)
   208     if (aAny && aHeapBase)
   209         {
   209         {
   210         return (TInt)aAny - (TInt)aHeapBase;
   210         return reinterpret_cast<TInt>(aAny) - reinterpret_cast<TInt>(aHeapBase);
   211         }
   211         }
   212     return 0;
   212     return 0;
   213     }
   213     }
   214 
   214 
   215 /** Helper function for converting an offset (that was calculated using
   215 /** Helper function for converting an offset (that was calculated using
   217 @param aOffset The offset to be converted to a pointer.
   217 @param aOffset The offset to be converted to a pointer.
   218 @param aHeapBase The heap base of the current process.
   218 @param aHeapBase The heap base of the current process.
   219 @return A pointer relative to the passed heap base.
   219 @return A pointer relative to the passed heap base.
   220 @see PointerToOffset()
   220 @see PointerToOffset()
   221  */
   221  */
   222 LOCAL_C TAny* OffsetToPointer(const TInt aOffset, TUint8* aHeapBase)
   222 LOCAL_C TAny* OffsetToPointer(TInt aOffset, TUint8* aHeapBase)
   223     {
   223     {
   224     if (aOffset && aHeapBase)
   224     if (aOffset && aHeapBase)
   225         {
   225         {
   226         return (TAny*)(aOffset + (TInt)aHeapBase);
   226         return reinterpret_cast<TAny*>(aOffset + reinterpret_cast<TInt>(aHeapBase));
   227         }
   227         }
   228     return NULL;
   228     return NULL;
   229     }
   229     }
       
   230 
   230 
   231 
   231 // CTypefaceSupportInfo
   232 // CTypefaceSupportInfo
   232 CTypefaceSupportInfo::CTypefaceSupportInfo()
   233 CTypefaceSupportInfo::CTypefaceSupportInfo()
   233 	{
   234 	{
   234 	}
   235 	}
   546 	iAlgStyle(aAlgStyle),
   547 	iAlgStyle(aAlgStyle),
   547 	iHeap(aHeap)
   548 	iHeap(aHeap)
   548 	{
   549 	{
   549     // Set iOpenFont to be the offset of aOpenFont from the address of CBitmapFont.
   550     // Set iOpenFont to be the offset of aOpenFont from the address of CBitmapFont.
   550     // In order to be able to identify iOpenFont as an offset instead of a pointer,
   551     // In order to be able to identify iOpenFont as an offset instead of a pointer,
   551     // bitwise or the offset with 1.  Pointers will always be byte aligned (and therefore even).
   552     // bitwise or the offset with 1.  Pointers will always be word aligned (and therefore even).
   552     if (aOpenFont)
   553     if (aOpenFont)
   553         {
   554         {
       
   555         __ASSERT_DEBUG(!(reinterpret_cast<TInt>(aOpenFont) & 1), Panic(EFntPointerNotByteAligned));
   554         iOpenFont = reinterpret_cast<COpenFont*>((reinterpret_cast<TInt>(aOpenFont) - reinterpret_cast<TInt>(this)) | 1);
   556         iOpenFont = reinterpret_cast<COpenFont*>((reinterpret_cast<TInt>(aOpenFont) - reinterpret_cast<TInt>(this)) | 1);
   555         __ASSERT_DEBUG((reinterpret_cast<TInt>(iOpenFont) & 1),Panic(EFntPointerNotByteAligned));
       
   556         }
   557         }
   557     else
   558     else
   558         {
   559         {
   559         iOpenFont = NULL;
   560         iOpenFont = NULL;
   560         }
   561         }
  2245 	CTypefaceStore::ConstructL();
  2246 	CTypefaceStore::ConstructL();
  2246 	User::LeaveIfError(iFs.Connect());
  2247 	User::LeaveIfError(iFs.Connect());
  2247 
  2248 
  2248 	TMachineInfoV1Buf machineInfoBuffer;
  2249 	TMachineInfoV1Buf machineInfoBuffer;
  2249 	User::LeaveIfError(UserHal::MachineInfo(machineInfoBuffer));
  2250 	User::LeaveIfError(UserHal::MachineInfo(machineInfoBuffer));
  2250 	
  2251 
  2251 	//Create Handles which may be used by Fntstore
       
  2252 	iHandleArray = new(ELeave) RArray<RHandleBase>();
       
  2253 
       
  2254 	RSemaphore SessionCacheSem;
       
  2255 	TInt ret = SessionCacheSem.CreateGlobal(KSessionCacheSemaphoreName,KSessionCacheSemaphoreCount);
       
  2256 	if(ret == KErrAlreadyExists)
       
  2257 	    {
       
  2258 	    User::LeaveIfError(SessionCacheSem.OpenGlobal(KSessionCacheSemaphoreName));
       
  2259 	    }
       
  2260 	else
       
  2261 	    {
       
  2262 	    User::LeaveIfError(ret);	    
       
  2263 	    }
       
  2264 	ret = iHandleArray->Append(SessionCacheSem);
       
  2265 	if(ret != KErrNone)
       
  2266 	    {
       
  2267 	    SessionCacheSem.Close();
       
  2268 	    User::Leave(ret);
       
  2269 	    }
       
  2270 	
       
  2271 	const TSize twipSize = machineInfoBuffer().iPhysicalScreenSize;
  2252 	const TSize twipSize = machineInfoBuffer().iPhysicalScreenSize;
  2272 	const TSize pixelSize = machineInfoBuffer().iDisplaySizeInPixels;
  2253 	const TSize pixelSize = machineInfoBuffer().iDisplaySizeInPixels;
  2273 
  2254 
  2274 	if (twipSize.iWidth > 0 && pixelSize.iWidth > 0)
  2255 	if (twipSize.iWidth > 0 && pixelSize.iWidth > 0)
  2275 		iKPixelWidthInTwips = twipSize.iWidth * 1000 / pixelSize.iWidth;
  2256 		iKPixelWidthInTwips = twipSize.iWidth * 1000 / pixelSize.iWidth;
  2314 	if (iOpenFontSessionCacheList)
  2295 	if (iOpenFontSessionCacheList)
  2315 		{
  2296 		{
  2316 		iOpenFontSessionCacheList->Delete(iHeap);
  2297 		iOpenFontSessionCacheList->Delete(iHeap);
  2317 		iHeap->Free(iOpenFontSessionCacheList);
  2298 		iHeap->Free(iOpenFontSessionCacheList);
  2318 		}
  2299 		}
  2319     if (iHandleArray)
       
  2320         {
       
  2321         for (TInt i = 0; i < iHandleArray->Count(); i++)
       
  2322             {
       
  2323             (*iHandleArray)[i].Close();
       
  2324             }
       
  2325         iHandleArray->Close();
       
  2326         delete iHandleArray;
       
  2327         }
       
  2328 	iFs.Close();
  2300 	iFs.Close();
  2329 	
  2301 	
  2330     delete iFontTableCache;
  2302     delete iFontTableCache;
  2331     delete iUnhintedOutlineCache;
  2303     delete iUnhintedOutlineCache;
  2332     delete iHintedOutlineCache;
  2304     delete iHintedOutlineCache;