os/textandloc/fontservices/fontstore/tfs/T_IsolatedFontStore.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1995-2010 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: 
    15 *
    16 */
    17 
    18 #include "T_IsolatedFontStore.h"
    19 #include <graphics/openfontrasterizer.h>
    20 #include <graphics/openfontconstants.h>
    21 
    22 CTIsolatedFontStore::CTIsolatedFontStore():iIsHeapOwner(ETrue)
    23 	{
    24 	}
    25 
    26 CTIsolatedFontStore::CTIsolatedFontStore(RHeap* aHeap):iIsHeapOwner(EFalse),iHeap(aHeap)
    27     {
    28     }
    29 
    30 CTIsolatedFontStore::~CTIsolatedFontStore()
    31 	{
    32 	delete iFs;
    33 	if (iIsHeapOwner && iHeap)
    34 	    {
    35 	    iHeap->Close();
    36 	    }
    37 	REComSession::FinalClose();
    38 	}
    39 
    40 CTIsolatedFontStore* CTIsolatedFontStore::NewLC()
    41 	{
    42 	CTIsolatedFontStore* self = new (ELeave)CTIsolatedFontStore();
    43 	CleanupStack::PushL(self);
    44 	self->ConstructL();
    45 	return self;
    46 	}
    47 
    48 CTIsolatedFontStore* CTIsolatedFontStore::NewL()
    49 	{
    50 	CTIsolatedFontStore* self=CTIsolatedFontStore::NewLC();
    51 	CleanupStack::Pop(); // self;
    52 	return self;
    53 	}
    54 
    55 CTIsolatedFontStore* CTIsolatedFontStore::NewLC(RHeap * aHeap)
    56     {
    57     CTIsolatedFontStore* self = new (ELeave)CTIsolatedFontStore(aHeap);
    58     CleanupStack::PushL(self);
    59     self->ConstructL();
    60     return self;
    61     }
    62 
    63 CTIsolatedFontStore* CTIsolatedFontStore::NewL(RHeap * aHeap)
    64     {
    65     CTIsolatedFontStore* self=CTIsolatedFontStore::NewLC(aHeap);
    66     CleanupStack::Pop(); // self;
    67     return self;
    68     }
    69 
    70 void CTIsolatedFontStore::ConstructL()
    71 	{
    72     if(iIsHeapOwner)
    73         {
    74         iHeap = UserHeap::ChunkHeap(NULL,0x10000,0x10000);
    75         }	
    76 	iFs = CFontStore::NewL(iHeap);
    77 	}
    78 
    79 /**
    80 Load all available font rasterizers and install to the instance of CFontStore
    81 this class contains.
    82 
    83 @pre This function hasn't previously been called on this object
    84 @post All rasterizers located and successfully loaded will be available for use
    85  */
    86 void CTIsolatedFontStore::LoadRasterizersL()
    87 	{
    88 	RImplInfoPtrArray implementationArray;
    89 	TUid uid = {KUidOpenFontRasterizerPlunginInterface};
    90 
    91 	// get implementation list
    92 	ListImplementationsWithRetry(uid, implementationArray, EFalse);
    93 
    94 	const TInt availCount = implementationArray.Count();
    95 	for (TInt count=0; count < availCount; ++count)
    96 		{
    97 		const CImplementationInformation* info = implementationArray[count];
    98 		// Create & install a rasterizer
    99 		// ignore Leaves, as any necessary cleanup will have already been done through the cleanup stack
   100 		TRAP_IGNORE(SafeInstallOfRasterizerL(info->ImplementationUid()));
   101 		}
   102 	
   103 	// free memory
   104 	implementationArray.ResetAndDestroy();
   105 	}
   106 
   107 /**
   108 Helper function from CFbTop to List all available rasterizers.
   109 
   110 @param aInterfaceUid The UID of the ECOM plugin
   111 @param aImplementationArray An array to store the found plugins
   112 @param aRomOnly If ETrue only ROM plugins are returned, otherwise all drives are searched
   113 */
   114 void CTIsolatedFontStore::ListImplementationsWithRetry(TUid& aInterfaceUid, RImplInfoPtrArray &aImplementationArray, TBool aRomOnly)
   115 	{
   116 	// Making sure that no race situation arises between FBserv and Ecom
   117 	// If ECom is not ready, give it another chance and try again. if it still doesn't work 
   118 	// after the third try, then it just carries on quietly and fails... 
   119 	for (TInt ecomnotready =0; ecomnotready <3; ecomnotready++)
   120 		{
   121 		TInt ecomError = KErrNone;
   122 		if (aRomOnly)
   123 			{
   124 			TEComResolverParams resParams;
   125 			TRAP(ecomError, REComSession::ListImplementationsL(aInterfaceUid, resParams, KRomOnlyResolverUid, aImplementationArray));
   126 			}
   127 		else
   128 			{ // default resolver
   129 			TRAP(ecomError, REComSession::ListImplementationsL(aInterfaceUid, aImplementationArray));
   130 			}
   131 
   132 		if (!ecomError)
   133 			{
   134 			return;
   135 			}
   136 		else
   137 			{
   138 			User::After(0);
   139 			}
   140 		}
   141 	}
   142 
   143 /**
   144 Installs the rasterizer with the specified interface UID.
   145 
   146 @param aInterfaceImplUid The UID of the rasterizer to be installed.
   147 
   148 @see CFbTop::SafeInstallOfRasterizerL
   149  */
   150 void CTIsolatedFontStore::SafeInstallOfRasterizerL(TUid aInterfaceImplUid)
   151 	{
   152 	COpenFontRasterizer* rasterizer = COpenFontRasterizer::NewL(aInterfaceImplUid);
   153 	CleanupStack::PushL(rasterizer);
   154 	// Install it in the font store.
   155 	iFs->InstallRasterizerL(rasterizer);
   156 	CleanupStack::Pop(rasterizer);
   157 	}