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