os/textandloc/fontservices/fontstore/tfs/T_IsolatedFontStore.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/fontstore/tfs/T_IsolatedFontStore.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,157 @@
     1.4 +/*
     1.5 +* Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +#include "T_IsolatedFontStore.h"
    1.22 +#include <graphics/openfontrasterizer.h>
    1.23 +#include <graphics/openfontconstants.h>
    1.24 +
    1.25 +CTIsolatedFontStore::CTIsolatedFontStore():iIsHeapOwner(ETrue)
    1.26 +	{
    1.27 +	}
    1.28 +
    1.29 +CTIsolatedFontStore::CTIsolatedFontStore(RHeap* aHeap):iIsHeapOwner(EFalse),iHeap(aHeap)
    1.30 +    {
    1.31 +    }
    1.32 +
    1.33 +CTIsolatedFontStore::~CTIsolatedFontStore()
    1.34 +	{
    1.35 +	delete iFs;
    1.36 +	if (iIsHeapOwner && iHeap)
    1.37 +	    {
    1.38 +	    iHeap->Close();
    1.39 +	    }
    1.40 +	REComSession::FinalClose();
    1.41 +	}
    1.42 +
    1.43 +CTIsolatedFontStore* CTIsolatedFontStore::NewLC()
    1.44 +	{
    1.45 +	CTIsolatedFontStore* self = new (ELeave)CTIsolatedFontStore();
    1.46 +	CleanupStack::PushL(self);
    1.47 +	self->ConstructL();
    1.48 +	return self;
    1.49 +	}
    1.50 +
    1.51 +CTIsolatedFontStore* CTIsolatedFontStore::NewL()
    1.52 +	{
    1.53 +	CTIsolatedFontStore* self=CTIsolatedFontStore::NewLC();
    1.54 +	CleanupStack::Pop(); // self;
    1.55 +	return self;
    1.56 +	}
    1.57 +
    1.58 +CTIsolatedFontStore* CTIsolatedFontStore::NewLC(RHeap * aHeap)
    1.59 +    {
    1.60 +    CTIsolatedFontStore* self = new (ELeave)CTIsolatedFontStore(aHeap);
    1.61 +    CleanupStack::PushL(self);
    1.62 +    self->ConstructL();
    1.63 +    return self;
    1.64 +    }
    1.65 +
    1.66 +CTIsolatedFontStore* CTIsolatedFontStore::NewL(RHeap * aHeap)
    1.67 +    {
    1.68 +    CTIsolatedFontStore* self=CTIsolatedFontStore::NewLC(aHeap);
    1.69 +    CleanupStack::Pop(); // self;
    1.70 +    return self;
    1.71 +    }
    1.72 +
    1.73 +void CTIsolatedFontStore::ConstructL()
    1.74 +	{
    1.75 +    if(iIsHeapOwner)
    1.76 +        {
    1.77 +        iHeap = UserHeap::ChunkHeap(NULL,0x10000,0x10000);
    1.78 +        }	
    1.79 +	iFs = CFontStore::NewL(iHeap);
    1.80 +	}
    1.81 +
    1.82 +/**
    1.83 +Load all available font rasterizers and install to the instance of CFontStore
    1.84 +this class contains.
    1.85 +
    1.86 +@pre This function hasn't previously been called on this object
    1.87 +@post All rasterizers located and successfully loaded will be available for use
    1.88 + */
    1.89 +void CTIsolatedFontStore::LoadRasterizersL()
    1.90 +	{
    1.91 +	RImplInfoPtrArray implementationArray;
    1.92 +	TUid uid = {KUidOpenFontRasterizerPlunginInterface};
    1.93 +
    1.94 +	// get implementation list
    1.95 +	ListImplementationsWithRetry(uid, implementationArray, EFalse);
    1.96 +
    1.97 +	const TInt availCount = implementationArray.Count();
    1.98 +	for (TInt count=0; count < availCount; ++count)
    1.99 +		{
   1.100 +		const CImplementationInformation* info = implementationArray[count];
   1.101 +		// Create & install a rasterizer
   1.102 +		// ignore Leaves, as any necessary cleanup will have already been done through the cleanup stack
   1.103 +		TRAP_IGNORE(SafeInstallOfRasterizerL(info->ImplementationUid()));
   1.104 +		}
   1.105 +	
   1.106 +	// free memory
   1.107 +	implementationArray.ResetAndDestroy();
   1.108 +	}
   1.109 +
   1.110 +/**
   1.111 +Helper function from CFbTop to List all available rasterizers.
   1.112 +
   1.113 +@param aInterfaceUid The UID of the ECOM plugin
   1.114 +@param aImplementationArray An array to store the found plugins
   1.115 +@param aRomOnly If ETrue only ROM plugins are returned, otherwise all drives are searched
   1.116 +*/
   1.117 +void CTIsolatedFontStore::ListImplementationsWithRetry(TUid& aInterfaceUid, RImplInfoPtrArray &aImplementationArray, TBool aRomOnly)
   1.118 +	{
   1.119 +	// Making sure that no race situation arises between FBserv and Ecom
   1.120 +	// If ECom is not ready, give it another chance and try again. if it still doesn't work 
   1.121 +	// after the third try, then it just carries on quietly and fails... 
   1.122 +	for (TInt ecomnotready =0; ecomnotready <3; ecomnotready++)
   1.123 +		{
   1.124 +		TInt ecomError = KErrNone;
   1.125 +		if (aRomOnly)
   1.126 +			{
   1.127 +			TEComResolverParams resParams;
   1.128 +			TRAP(ecomError, REComSession::ListImplementationsL(aInterfaceUid, resParams, KRomOnlyResolverUid, aImplementationArray));
   1.129 +			}
   1.130 +		else
   1.131 +			{ // default resolver
   1.132 +			TRAP(ecomError, REComSession::ListImplementationsL(aInterfaceUid, aImplementationArray));
   1.133 +			}
   1.134 +
   1.135 +		if (!ecomError)
   1.136 +			{
   1.137 +			return;
   1.138 +			}
   1.139 +		else
   1.140 +			{
   1.141 +			User::After(0);
   1.142 +			}
   1.143 +		}
   1.144 +	}
   1.145 +
   1.146 +/**
   1.147 +Installs the rasterizer with the specified interface UID.
   1.148 +
   1.149 +@param aInterfaceImplUid The UID of the rasterizer to be installed.
   1.150 +
   1.151 +@see CFbTop::SafeInstallOfRasterizerL
   1.152 + */
   1.153 +void CTIsolatedFontStore::SafeInstallOfRasterizerL(TUid aInterfaceImplUid)
   1.154 +	{
   1.155 +	COpenFontRasterizer* rasterizer = COpenFontRasterizer::NewL(aInterfaceImplUid);
   1.156 +	CleanupStack::PushL(rasterizer);
   1.157 +	// Install it in the font store.
   1.158 +	iFs->InstallRasterizerL(rasterizer);
   1.159 +	CleanupStack::Pop(rasterizer);
   1.160 +	}