os/textandloc/fontservices/fontstore/tfs/T_FSOPEN.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) 2007-2009 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
* Tests FNTSTORE with respect to the Open Font system.
sl@0
    16
* Creates a dummy rasterizer and tests font file loading and unloading and
sl@0
    17
* font creation. This just exercises the way the Open Font system connects to the
sl@0
    18
* 'classic' bitmap-font-only font system.
sl@0
    19
*
sl@0
    20
*/
sl@0
    21
sl@0
    22
sl@0
    23
/**
sl@0
    24
 @file
sl@0
    25
 @test
sl@0
    26
 @internalComponent Internal Symbian test code
sl@0
    27
*/
sl@0
    28
sl@0
    29
#include "T_FSOPEN.H"
sl@0
    30
#include <e32std.h>
sl@0
    31
#include <graphics/shaperparams.h>
sl@0
    32
#include <graphics/fbsdefs.h>
sl@0
    33
sl@0
    34
#ifdef _DEBUG
sl@0
    35
_LIT(KFBSERVFontDir,"\\resource\\fonts\\");
sl@0
    36
#endif// _DEBUG
sl@0
    37
sl@0
    38
sl@0
    39
_LIT(KFontDummy,"z:\\PlatTest\\Graphics\\TestData\\dummy_fonts\\dummy");
sl@0
    40
_LIT(KFontDummy_b,"z:\\PlatTest\\Graphics\\TestData\\dummy_fonts\\dummy_b");
sl@0
    41
_LIT(KFontDummy_i,"z:\\PlatTest\\Graphics\\TestData\\dummy_fonts\\dummy_i");
sl@0
    42
_LIT(KFontDummy_bi,"z:\\PlatTest\\Graphics\\TestData\\dummy_fonts\\dummy_bi");
sl@0
    43
sl@0
    44
const TUint32 KDevanagariScriptCode = 0x64657661;
sl@0
    45
_LIT16(KTextToShape, "\x0915\x094D\x0937\x0924\x094D\x0930\x093F\x092F");
sl@0
    46
sl@0
    47
sl@0
    48
sl@0
    49
sl@0
    50
CDummyShaperFactory* CDummyShaperFactory::NewL()
sl@0
    51
	{
sl@0
    52
	CDummyShaperFactory* r = new(ELeave) CDummyShaperFactory;
sl@0
    53
	return r;
sl@0
    54
	}
sl@0
    55
sl@0
    56
CDummyShaperFactory::CDummyShaperFactory()
sl@0
    57
	{
sl@0
    58
	}
sl@0
    59
sl@0
    60
CDummyShaperFactory::~CDummyShaperFactory()
sl@0
    61
	{
sl@0
    62
	
sl@0
    63
	}
sl@0
    64
sl@0
    65
sl@0
    66
CShaper* CDummyShaperFactory::NewShaperL(CBitmapFont* aBitmapfont, TInt aScript, TInt aLanguage, RHeap* aHeap)
sl@0
    67
	{
sl@0
    68
	return CDummyShaper::NewL(aBitmapfont, aScript, aLanguage, aHeap);
sl@0
    69
	} 
sl@0
    70
sl@0
    71
void* CShaperFactory::ExtendedInterface(TUid /*aInterfaceId*/)
sl@0
    72
	{
sl@0
    73
	return 0;
sl@0
    74
	}
sl@0
    75
sl@0
    76
sl@0
    77
CShaper * CDummyShaper::NewL(CBitmapFont* aBitmapfont, TInt aScript, TInt aLanguage, RHeap* aHeap)
sl@0
    78
	{
sl@0
    79
	CDummyShaper* newShaper = new(ELeave)CDummyShaper();
sl@0
    80
	CleanupStack::PushL(newShaper);
sl@0
    81
	TInt error = newShaper->ConstructL(aBitmapfont, aScript, aLanguage, aHeap);
sl@0
    82
	
sl@0
    83
	// if the layout engine fails to construct with this font return NULL
sl@0
    84
	if (error == KErrNone )
sl@0
    85
		{
sl@0
    86
		CleanupStack::Pop(); // newShaper
sl@0
    87
		return newShaper;
sl@0
    88
		}
sl@0
    89
	else
sl@0
    90
		{
sl@0
    91
		CleanupStack::PopAndDestroy(); 
sl@0
    92
		return NULL;		
sl@0
    93
		}		
sl@0
    94
	} 
sl@0
    95
sl@0
    96
sl@0
    97
/**
sl@0
    98
Construct an instance of CDummyShaper 	
sl@0
    99
@param aOpenFont The required font
sl@0
   100
@param aHeap The heap to be used for storage by the engine
sl@0
   101
@return KErrNone if successful or a system wide error code. 
sl@0
   102
Note that KErrGeneral may be returned in certain out of memory situations.
sl@0
   103
@see CShaper
sl@0
   104
 */
sl@0
   105
 TInt CDummyShaper::ConstructL(CBitmapFont* /*aBitmapfont*/, TInt /*aScript*/, TInt /*aLanguage*/, RHeap* /*aHeap*/ )
sl@0
   106
	{
sl@0
   107
	return KErrNone;
sl@0
   108
	}
sl@0
   109
sl@0
   110
CDummyShaper::CDummyShaper()
sl@0
   111
	{
sl@0
   112
	}	
sl@0
   113
		
sl@0
   114
/** 
sl@0
   115
 Frees all resources owned by ...
sl@0
   116
 */
sl@0
   117
 CDummyShaper::~CDummyShaper()
sl@0
   118
	{
sl@0
   119
	}	
sl@0
   120
	
sl@0
   121
/** This is implementation of CShaper::ShapeText for the Icu layout Engine
sl@0
   122
 The data is taken from TInput and pass to the shaper.
sl@0
   123
 A memory buffer is allocated on aHeapForOutput starting with TShapeHeader is allocated.
sl@0
   124
 The results of the shaping are copied into this buffer and passed back via aOutput. 
sl@0
   125
 @param aOutput On success a new structure containing the results allocated on aHeapForOutput.  
sl@0
   126
 @param aInput The input text and other parameters.
sl@0
   127
 @param aHeapForOutput On success, aOutput should be allocated from this and nothing else. 
sl@0
   128
 		On failure, nothing should be allocated from it.
sl@0
   129
 @return Error value from one of the system-wide error codes on	failure, KErrNone on success.
sl@0
   130
 @see CShaper::ShapeText
sl@0
   131
 */		
sl@0
   132
TInt CDummyShaper::ShapeText(TShapeHeader*& /*aOutput*/, const TInput& /*aInput*/, RHeap* /*aHeapForOutput*/)
sl@0
   133
	{
sl@0
   134
	// This shaper doesnt return any results
sl@0
   135
 	return KErrNotSupported;
sl@0
   136
	}
sl@0
   137
sl@0
   138
class CDummyFontFile: public COpenFontFile
sl@0
   139
	{
sl@0
   140
public:
sl@0
   141
	static CDummyFontFile* NewL(TInt aUid,const TDesC& aFileName);
sl@0
   142
	TBool GetNearestFontHelperOld(const TOpenFontSpec& aDesiredFontSpec,TInt aPixelWidth,TInt aPixelHeight,
sl@0
   143
										TInt& aFaceIndex,TOpenFontSpec& aActualFontSpec) const;
sl@0
   144
private:
sl@0
   145
	CDummyFontFile(TInt aUid,const TDesC& aFileName);
sl@0
   146
	void ConstructL();
sl@0
   147
	// From COpenFontFile
sl@0
   148
	void GetNearestFontInPixelsL(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList,
sl@0
   149
								 const TOpenFontSpec& aDesiredFontSpec,TInt aPixelWidth,TInt aPixelHeight,
sl@0
   150
								 COpenFont*& aFont,TOpenFontSpec& aActualFontSpec);
sl@0
   151
	void GetNearestFontToDesignHeightInPixelsL(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList,
sl@0
   152
								 const TOpenFontSpec& aDesiredFontSpec,TInt aPixelWidth,TInt aPixelHeight,
sl@0
   153
								 COpenFont*& aFont,TOpenFontSpec& aActualFontSpec);
sl@0
   154
	void GetNearestFontToMaxHeightInPixelsL(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList,
sl@0
   155
								 const TOpenFontSpec& aDesiredFontSpec,TInt aPixelWidth,TInt aPixelHeight,
sl@0
   156
								 COpenFont*& aFont,TOpenFontSpec& aActualFontSpec, TInt aMaxHeight);
sl@0
   157
	virtual TBool HasUnicodeCharacterL(TInt aFaceIndex,TInt aCode) const;
sl@0
   158
	};
sl@0
   159
sl@0
   160
class CDummyFont: public COpenFont
sl@0
   161
	{
sl@0
   162
public:
sl@0
   163
	static CDummyFont* NewL(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList,CDummyFontFile* aFontFile,TInt aSizeInPixels);
sl@0
   164
private:
sl@0
   165
	CDummyFont(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList,CDummyFontFile* aFontFile,TInt aSizeInPixels);
sl@0
   166
	// From COpenFont
sl@0
   167
	virtual void RasterizeL(TInt aCode,TOpenFontGlyphData* aGlyphData);
sl@0
   168
	};
sl@0
   169
sl@0
   170
CTFsOpen::CTFsOpen(CTestStep* aStep) :
sl@0
   171
	CTGraphicsBase(aStep)
sl@0
   172
	{
sl@0
   173
	INFO_PRINTF1(_L("FontStore and the Open Font System"));
sl@0
   174
	}
sl@0
   175
sl@0
   176
CTFsOpen::~CTFsOpen()
sl@0
   177
	{
sl@0
   178
	iFilesys.Close();
sl@0
   179
	delete iFontStore;
sl@0
   180
	iHeap->__DbgMarkEnd(0);
sl@0
   181
	iHeap->Close();
sl@0
   182
	__UHEAP_MARKEND;
sl@0
   183
	User::Heap().Check();
sl@0
   184
	}
sl@0
   185
sl@0
   186
void CTFsOpen::ConstructL()
sl@0
   187
	{
sl@0
   188
	__UHEAP_MARK;
sl@0
   189
	iHeap = UserHeap::ChunkHeap(NULL,0x10000,0x10000);
sl@0
   190
	if (iHeap == NULL)
sl@0
   191
		User::Leave(KErrGeneral);
sl@0
   192
	iHeap->__DbgMarkStart();
sl@0
   193
	iFontStore = CFontStore::NewL(iHeap);
sl@0
   194
	
sl@0
   195
	// Install the dummy rasterizer.
sl@0
   196
	COpenFontRasterizer* r = CDummyRasterizer::NewL();
sl@0
   197
	CleanupStack::PushL(r);
sl@0
   198
	iFontStore->InstallRasterizerL(r);
sl@0
   199
	CleanupStack::Pop();
sl@0
   200
sl@0
   201
	// Install the dummy shaper
sl@0
   202
	CShaperFactory* shaperFactory = CDummyShaperFactory::NewL();
sl@0
   203
	CleanupStack::PushL(shaperFactory);
sl@0
   204
	iFontStore->InstallShaperFactoryL(shaperFactory);
sl@0
   205
	CleanupStack::Pop();
sl@0
   206
	}
sl@0
   207
sl@0
   208
void CTFsOpen::RunTestCaseL(TInt aCurTestCase)
sl@0
   209
	{
sl@0
   210
	((CTFsOpenStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
   211
	switch(aCurTestCase)
sl@0
   212
		{
sl@0
   213
	case 1:
sl@0
   214
		((CTFsOpenStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0031"));
sl@0
   215
		AddAndRemoveFilesL();
sl@0
   216
		break;
sl@0
   217
	case 2:
sl@0
   218
		((CTFsOpenStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0032"));
sl@0
   219
		CreateAndReleaseFontsL();
sl@0
   220
		break;
sl@0
   221
	case 3:
sl@0
   222
		((CTFsOpenStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0033"));
sl@0
   223
#ifdef _DEBUG
sl@0
   224
		TestGetNearestFontHelperL();
sl@0
   225
#endif //_DEBUG
sl@0
   226
		break;
sl@0
   227
	case 4:
sl@0
   228
		((CTFsOpenStep*)iStep)->SetTestStepID(_L("GRAPHICS-SYSLIB-FNTSTORE-UT-1498"));
sl@0
   229
		CreateShaperL();
sl@0
   230
		break;
sl@0
   231
	case 5:
sl@0
   232
        	((CTFsOpenStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   233
		((CTFsOpenStep*)iStep)->CloseTMSGraphicsStep();
sl@0
   234
		TestComplete();
sl@0
   235
		break;
sl@0
   236
		}
sl@0
   237
	((CTFsOpenStep*)iStep)->RecordTestResultL();
sl@0
   238
	}
sl@0
   239
sl@0
   240
/**
sl@0
   241
	@SYMTestCaseID
sl@0
   242
	GRAPHICS-FNTSTORE-0031
sl@0
   243
sl@0
   244
	@SYMTestCaseDesc
sl@0
   245
	Tests adding and removing files from the font store.
sl@0
   246
sl@0
   247
	@SYMTestActions
sl@0
   248
	1. Finds or creates a font file object to support a font file. 
sl@0
   249
	   If an appropriate font file object exists then no new open font file is created. 
sl@0
   250
	   In this case the reference count of the font file object is incremented.
sl@0
   251
	2. Gets the number of typefaces held in the font store.
sl@0
   252
	3. Checks all fonts are in the same typeface family.
sl@0
   253
	4. Checks all fonts have different FontStore ids.
sl@0
   254
	5. Tries to add a font (which has been added once already) and checks it gets 
sl@0
   255
	   the same id as when it was added.
sl@0
   256
	6. Releases four load fonts.
sl@0
   257
	7. Checks font that was loaded twice should still be loaded.
sl@0
   258
	8. Removes last reference a font and checks all fonts are unloaded correctly.
sl@0
   259
sl@0
   260
	@SYMTestExpectedResults
sl@0
   261
	Test should pass
sl@0
   262
*/
sl@0
   263
void CTFsOpen::AddAndRemoveFilesL()
sl@0
   264
	{
sl@0
   265
	TEST(iFontStore->NumTypefaces() == 0);
sl@0
   266
sl@0
   267
	INFO_PRINTF1(_L("loading dummy Open Fonts\n"));
sl@0
   268
	
sl@0
   269
	TUid id1 = iFontStore->AddFileL(KFontDummy);
sl@0
   270
	TUid id2 = iFontStore->AddFileL(KFontDummy_b);
sl@0
   271
	TUid id3 = iFontStore->AddFileL(KFontDummy_i);
sl@0
   272
	TUid id4 = iFontStore->AddFileL(KFontDummy_bi);
sl@0
   273
sl@0
   274
	// all fonts are in the same typeface family
sl@0
   275
	INFO_PRINTF1(_L("increasing reference count for for an Open Font file\n"));
sl@0
   276
	TEST(iFontStore->NumTypefaces() == 1);
sl@0
   277
sl@0
   278
	// ids should each be different
sl@0
   279
	TEST(id1 != id2);
sl@0
   280
	TEST(id1 != id3);
sl@0
   281
	TEST(id1 != id4);
sl@0
   282
	TEST(id2 != id3);
sl@0
   283
	TEST(id2 != id4);
sl@0
   284
	TEST(id3 != id4);
sl@0
   285
sl@0
   286
	// ask for one of the font files again
sl@0
   287
	TUid id5 = iFontStore->AddFileL(KFontDummy_bi);
sl@0
   288
sl@0
   289
	// should get the same UID as the first time
sl@0
   290
	TEST(id4 == id5);
sl@0
   291
sl@0
   292
	INFO_PRINTF1(_L("unloading dummy Open Fonts\n"));
sl@0
   293
	iFontStore->RemoveFile(id1);
sl@0
   294
	iFontStore->RemoveFile(id2);
sl@0
   295
	iFontStore->RemoveFile(id3);
sl@0
   296
	iFontStore->RemoveFile(id4);
sl@0
   297
sl@0
   298
	// font that was loaded twice should still be loaded
sl@0
   299
	TEST(iFontStore->NumTypefaces() == 1);
sl@0
   300
sl@0
   301
	// remove last reference
sl@0
   302
	iFontStore->RemoveFile(id5);
sl@0
   303
sl@0
   304
	// all fonts unloaded
sl@0
   305
	TEST(iFontStore->NumTypefaces() == 0);
sl@0
   306
	}
sl@0
   307
sl@0
   308
void CTFsOpen::TestFont(const TFontSpec& aSpec)
sl@0
   309
	{
sl@0
   310
	iHeap->__DbgMarkStart();
sl@0
   311
sl@0
   312
	CFont* font = NULL;
sl@0
   313
	TInt error = iFontStore->GetNearestFontToDesignHeightInTwips(font,aSpec);
sl@0
   314
	TEST(error == KErrNone);
sl@0
   315
	TEST(font != NULL);
sl@0
   316
	INFO_PRINTF2(_L("desired font spec: %S: "),&aSpec.iTypeface.iName);
sl@0
   317
	if (aSpec.iFontStyle.StrokeWeight() == EStrokeWeightBold)
sl@0
   318
		INFO_PRINTF1(_L("bold "));
sl@0
   319
	if (aSpec.iFontStyle.Posture() == EPostureItalic)
sl@0
   320
		INFO_PRINTF1(_L("italic "));
sl@0
   321
	INFO_PRINTF2(_L("%dpt"),(aSpec.iHeight + 10) / 20);
sl@0
   322
	INFO_PRINTF1(_L("\n"));
sl@0
   323
	TFontSpec actual_spec = font->FontSpecInTwips();
sl@0
   324
	INFO_PRINTF2(_L("actual font spec: %S: "),&actual_spec.iTypeface.iName);
sl@0
   325
	if (actual_spec.iFontStyle.StrokeWeight() == EStrokeWeightBold)
sl@0
   326
		INFO_PRINTF1(_L("bold "));
sl@0
   327
	if (actual_spec.iFontStyle.Posture() == EPostureItalic)
sl@0
   328
		INFO_PRINTF1(_L("italic "));
sl@0
   329
	INFO_PRINTF2(_L("%dpt"),(actual_spec.iHeight + 10) / 20);
sl@0
   330
	INFO_PRINTF1(_L("\n"));
sl@0
   331
	iFontStore->ReleaseFont(font);
sl@0
   332
sl@0
   333
	TEST (iHeap->__DbgMarkEnd(0) == 0);
sl@0
   334
	}
sl@0
   335
sl@0
   336
/**
sl@0
   337
	@SYMTestCaseID
sl@0
   338
	GRAPHICS-FNTSTORE-0032
sl@0
   339
sl@0
   340
	@SYMTestCaseDesc
sl@0
   341
	Creates fonts and tests their properties
sl@0
   342
	and then releases them.
sl@0
   343
sl@0
   344
	@SYMTestActions
sl@0
   345
	1. Adds four files to the font store.
sl@0
   346
	2. Retrieves number of typefaces.
sl@0
   347
	3. For all of the typefaces available it gets
sl@0
   348
	   the typeface support and retrieves its font height
sl@0
   349
	   in twips.
sl@0
   350
	4. Tests the fonts properties.
sl@0
   351
	5. Releases a hold on all font file objects allocated.
sl@0
   352
	
sl@0
   353
	@SYMTestExpectedResults
sl@0
   354
	Test should pass
sl@0
   355
*/
sl@0
   356
void CTFsOpen::CreateAndReleaseFontsL()
sl@0
   357
	{
sl@0
   358
	TUid id1 = iFontStore->AddFileL(KFontDummy);
sl@0
   359
	TUid id2 = iFontStore->AddFileL(KFontDummy_b);
sl@0
   360
	TUid id3 = iFontStore->AddFileL(KFontDummy_i);
sl@0
   361
	TUid id4 = iFontStore->AddFileL(KFontDummy_bi);
sl@0
   362
sl@0
   363
	int typefaces = iFontStore->NumTypefaces();
sl@0
   364
	for (int typeface = 0; typeface < typefaces; typeface++)
sl@0
   365
		{
sl@0
   366
		TTypefaceSupport support;
sl@0
   367
		iFontStore->TypefaceSupport(support,typeface);
sl@0
   368
		TFontSpec fs;
sl@0
   369
		fs.iTypeface = support.iTypeface;
sl@0
   370
		for (int height = 0; height < support.iNumHeights; height++)
sl@0
   371
			{
sl@0
   372
			fs.iHeight = iFontStore->FontHeightInTwips(typeface,height);
sl@0
   373
			TestFont(fs);
sl@0
   374
			}
sl@0
   375
		}
sl@0
   376
sl@0
   377
	iFontStore->RemoveFile(id1);
sl@0
   378
	iFontStore->RemoveFile(id2);
sl@0
   379
	iFontStore->RemoveFile(id3);
sl@0
   380
	iFontStore->RemoveFile(id4);
sl@0
   381
	}
sl@0
   382
	
sl@0
   383
/**
sl@0
   384
@file
sl@0
   385
@SYMTestCaseID				GRAPHICS-SYSLIB-FNTSTORE-UT-1498
sl@0
   386
@SYMTestCaseDesc 			Test the Shaper API  
sl@0
   387
@SYMTestPriority 			High
sl@0
   388
@SYMTestActions  			This test checks the CBitmapFont::ShapeTextL() using a dummy font and a dummy shaper
sl@0
   389
@SYMTestExpectedResults		The test must not fail.
sl@0
   390
@SYMPREQ					PREQ18
sl@0
   391
*/
sl@0
   392
void CTFsOpen::CreateShaperL()
sl@0
   393
	{
sl@0
   394
	__UHEAP_MARK;
sl@0
   395
	INFO_PRINTF1(_L("Creating Shaper and Shaping Text\n"));
sl@0
   396
	
sl@0
   397
	// Add fonts
sl@0
   398
	TUid id1 = iFontStore->AddFileL(KFontDummy);
sl@0
   399
	TUid id2 = iFontStore->AddFileL(KFontDummy_b);
sl@0
   400
	TUid id3 = iFontStore->AddFileL(KFontDummy_i);
sl@0
   401
	TUid id4 = iFontStore->AddFileL(KFontDummy_bi);
sl@0
   402
	
sl@0
   403
	TInt error = 0;
sl@0
   404
	TInt err = 0;
sl@0
   405
	int typefaces = iFontStore->NumTypefaces();
sl@0
   406
	for (TInt typeface = 0; typeface < typefaces; typeface++)
sl@0
   407
		{
sl@0
   408
		TTypefaceSupport support;
sl@0
   409
		iFontStore->TypefaceSupport(support,typeface);
sl@0
   410
		TFontSpec fs;
sl@0
   411
		fs.iTypeface = support.iTypeface;
sl@0
   412
		for (TInt height = 0; height < support.iNumHeights; height++)
sl@0
   413
			{
sl@0
   414
			//Create a font
sl@0
   415
			CFont* font = NULL;
sl@0
   416
			fs.iHeight = iFontStore->FontHeightInTwips(typeface,height);
sl@0
   417
			// get a COpenFont object
sl@0
   418
			iFontStore->GetNearestFontToDesignHeightInPixels(font, fs);	
sl@0
   419
			CleanupStack::PushL(font);
sl@0
   420
			
sl@0
   421
			 //do some dummy shaping
sl@0
   422
			TShapeHeader* shape = 0;
sl@0
   423
						
sl@0
   424
			TShapeMessageParameters params;
sl@0
   425
			params.iStart = 0;
sl@0
   426
			params.iEnd = 8;
sl@0
   427
			params.iScript = KDevanagariScriptCode;
sl@0
   428
			params.iLanguage = 0;
sl@0
   429
			
sl@0
   430
					
sl@0
   431
			TRAP(err, shape = ((CBitmapFont*)font)->ShapeTextL(KTextToShape, 0, params));
sl@0
   432
			TEST(err == KErrNotSupported);
sl@0
   433
					
sl@0
   434
			// Now do some dummy deletion of the TShapeHeader
sl@0
   435
			TInt dummyHandle=0;
sl@0
   436
			TRAP(error, ((CBitmapFont*)font)->DeleteShape(dummyHandle,shape));
sl@0
   437
			TEST(error == KErrNone);
sl@0
   438
			CleanupStack::Pop(font);
sl@0
   439
			iFontStore->ReleaseFont(font);
sl@0
   440
			}
sl@0
   441
		}
sl@0
   442
sl@0
   443
	// Remove the fonts
sl@0
   444
	iFontStore->RemoveFile(id1);
sl@0
   445
	iFontStore->RemoveFile(id2);
sl@0
   446
	iFontStore->RemoveFile(id3);
sl@0
   447
	iFontStore->RemoveFile(id4);	
sl@0
   448
sl@0
   449
	__UHEAP_MARKEND;	
sl@0
   450
	}
sl@0
   451
	
sl@0
   452
/** End of Shaper Tests*/
sl@0
   453
sl@0
   454
/**
sl@0
   455
	@SYMTestCaseID
sl@0
   456
	GRAPHICS-FNTSTORE-0033
sl@0
   457
sl@0
   458
	@SYMTestCaseDesc
sl@0
   459
	Tests the GetNearestFontHelper function. This function may be used by 
sl@0
   460
	derived classes in their GetNearestFontInPixelsL() 
sl@0
   461
	implementations. It finds the nearest font in the typeface attribute array, 
sl@0
   462
	if any, to the provided font specification. If there is a possible match it 
sl@0
   463
	places the face index in aFaceIndex and the actual specification (including 
sl@0
   464
	algorithmic effects) in aActualFontSpec.
sl@0
   465
sl@0
   466
	@SYMTestActions
sl@0
   467
	1. Connects to the file system.
sl@0
   468
	2. Finds a specified file.
sl@0
   469
	3. Retrieves a font file.
sl@0
   470
	4. Sets different font attributes.
sl@0
   471
	5. Calls the GetNearestFontHelper and GetNearestFontHelperOld functions.
sl@0
   472
	6. Checks if the two functions give the same result.
sl@0
   473
		
sl@0
   474
	@SYMTestExpectedResults
sl@0
   475
	Test should pass
sl@0
   476
*/
sl@0
   477
#ifdef _DEBUG
sl@0
   478
void CTFsOpen::TestGetNearestFontHelperL()
sl@0
   479
	{
sl@0
   480
	INFO_PRINTF1(_L("GetNearestFontHelper\n"));
sl@0
   481
	User::LeaveIfError(iFilesys.Connect());
sl@0
   482
	TFindFile file_finder(iFilesys);
sl@0
   483
	CDir* file_list = NULL;
sl@0
   484
	_LIT(KFBSERVFontFilePattern, "*.ttf");
sl@0
   485
	TInt error = file_finder.FindWildByDir(KFBSERVFontFilePattern,KFBSERVFontDir,file_list);
sl@0
   486
	while (!error)
sl@0
   487
		{
sl@0
   488
		CleanupStack::PushL(file_list);
sl@0
   489
		for (int i = 0; i < file_list->Count(); i++)
sl@0
   490
			{
sl@0
   491
			TParse parse;
sl@0
   492
			if (parse.Set((*file_list)[i].iName,&file_finder.File(),NULL) == KErrNone)
sl@0
   493
				{
sl@0
   494
				TPtrC name = parse.Name();
sl@0
   495
				INFO_PRINTF2(_L("Font file: %S\r\n"), &name);
sl@0
   496
				CDummyFontFile* font_file = CDummyFontFile::NewL(0,parse.FullName());
sl@0
   497
sl@0
   498
				TOpenFontSpec font_spec1;
sl@0
   499
				TOpenFontSpec font_spec2_new;
sl@0
   500
				TOpenFontSpec font_spec2_old;
sl@0
   501
				
sl@0
   502
				TInt face_index = 0;
sl@0
   503
sl@0
   504
				font_spec1.SetName(KNullDesC);
sl@0
   505
				font_spec1.SetHeight(10);
sl@0
   506
sl@0
   507
				font_spec1.SetCoverage(0,0,0,0);
sl@0
   508
				font_spec1.SetBold(EFalse);
sl@0
   509
				font_spec1.SetItalic(EFalse);
sl@0
   510
				font_spec1.SetSerif(EFalse);
sl@0
   511
				font_spec1.SetMonoWidth(EFalse);
sl@0
   512
				TBool res1 = font_file->GetNearestFontHelper(font_spec1,0,0,face_index,font_spec2_new);
sl@0
   513
				TBool res2 = font_file->GetNearestFontHelperOld(font_spec1,0,0,face_index,font_spec2_old);
sl@0
   514
				TEST(res2 ? res1 && (font_spec2_new == font_spec2_old) : ETrue);
sl@0
   515
sl@0
   516
				font_spec1.SetBold(ETrue);
sl@0
   517
				res1 = font_file->GetNearestFontHelper(font_spec1,0,0,face_index,font_spec2_new);
sl@0
   518
				res2 = font_file->GetNearestFontHelperOld(font_spec1,0,0,face_index,font_spec2_old);
sl@0
   519
				TEST(res2 ? res1 && (font_spec2_new == font_spec2_old) : ETrue);
sl@0
   520
sl@0
   521
				font_spec1.SetItalic(ETrue);
sl@0
   522
				res1 = font_file->GetNearestFontHelper(font_spec1,0,0,face_index,font_spec2_new);
sl@0
   523
				res2 = font_file->GetNearestFontHelperOld(font_spec1,0,0,face_index,font_spec2_old);
sl@0
   524
				TEST(res2 ? res1 && (font_spec2_new == font_spec2_old) : ETrue);
sl@0
   525
sl@0
   526
				font_spec1.SetSerif(ETrue);
sl@0
   527
				res1 = font_file->GetNearestFontHelper(font_spec1,0,0,face_index,font_spec2_new);
sl@0
   528
				res2 = font_file->GetNearestFontHelperOld(font_spec1,0,0,face_index,font_spec2_old);
sl@0
   529
				TEST(res2 ? res1 && (font_spec2_new == font_spec2_old) : ETrue);
sl@0
   530
sl@0
   531
				font_spec1.SetMonoWidth(ETrue);
sl@0
   532
				res1 = font_file->GetNearestFontHelper(font_spec1,0,0,face_index,font_spec2_new);
sl@0
   533
				res2 = font_file->GetNearestFontHelperOld(font_spec1,0,0,face_index,font_spec2_old);
sl@0
   534
				TEST(res2 ? res1 && (font_spec2_new == font_spec2_old) : ETrue);
sl@0
   535
sl@0
   536
				font_spec1.SetCoverage(8);
sl@0
   537
				font_spec1.SetBold(EFalse);
sl@0
   538
				font_spec1.SetItalic(EFalse);
sl@0
   539
				font_spec1.SetSerif(EFalse);
sl@0
   540
				font_spec1.SetMonoWidth(EFalse);
sl@0
   541
				res1 = font_file->GetNearestFontHelper(font_spec1,0,0,face_index,font_spec2_new);
sl@0
   542
				res2 = font_file->GetNearestFontHelperOld(font_spec1,0,0,face_index,font_spec2_old);
sl@0
   543
				TEST(res2 ? res1 && (font_spec2_new == font_spec2_old) : ETrue);
sl@0
   544
sl@0
   545
				delete font_file;
sl@0
   546
				}
sl@0
   547
			}
sl@0
   548
		CleanupStack::PopAndDestroy(); // file_list
sl@0
   549
		if (!error)
sl@0
   550
			error = file_finder.FindWild(file_list);
sl@0
   551
		}
sl@0
   552
	}
sl@0
   553
#endif //_DEBUG
sl@0
   554
sl@0
   555
CDummyRasterizer* CDummyRasterizer::NewL()
sl@0
   556
	{
sl@0
   557
	return new(ELeave) CDummyRasterizer;
sl@0
   558
	}
sl@0
   559
sl@0
   560
COpenFontFile* CDummyRasterizer::NewFontFileL(TInt aUid,const TDesC& aFileName,RFs& /*aFileSession*/)
sl@0
   561
	{
sl@0
   562
	// Allow 'dummy', 'dummy_b', etc. Don't actually open a file; just create a dummy font.
sl@0
   563
	if (aFileName.CompareF(KFontDummy) == 0 ||
sl@0
   564
		aFileName.CompareF(KFontDummy_b) == 0 ||
sl@0
   565
		aFileName.CompareF(KFontDummy_i) == 0 ||
sl@0
   566
		aFileName.CompareF(KFontDummy_bi) == 0)
sl@0
   567
		return CDummyFontFile::NewL(aUid,aFileName);
sl@0
   568
	return NULL;
sl@0
   569
	}
sl@0
   570
sl@0
   571
CDummyFontFile::CDummyFontFile(TInt aUid,const TDesC& aFileName):
sl@0
   572
	COpenFontFile(aUid,aFileName)
sl@0
   573
	{
sl@0
   574
	}
sl@0
   575
sl@0
   576
CDummyFontFile* CDummyFontFile::NewL(TInt aUid,const TDesC& aFileName)
sl@0
   577
	{
sl@0
   578
	CDummyFontFile* f = new(ELeave)CDummyFontFile(aUid,aFileName);
sl@0
   579
	CleanupStack::PushL(f);
sl@0
   580
	f->ConstructL();
sl@0
   581
	CleanupStack::Pop();
sl@0
   582
	return f;
sl@0
   583
	}
sl@0
   584
sl@0
   585
TBool CDummyFontFile::GetNearestFontHelperOld(const TOpenFontSpec& aDesiredFontSpec,TInt aPixelWidth,TInt aPixelHeight,
sl@0
   586
											  TInt& aFaceIndex,TOpenFontSpec& aActualFontSpec) const
sl@0
   587
	{
sl@0
   588
	return COpenFontFile::GetNearestFontHelperOld(aDesiredFontSpec,aPixelWidth,aPixelHeight,aFaceIndex,aActualFontSpec);
sl@0
   589
	}
sl@0
   590
sl@0
   591
void CDummyFontFile::ConstructL()
sl@0
   592
	{
sl@0
   593
	const TDesC& filename = FileName();
sl@0
   594
	TOpenFontFaceAttrib attrib;
sl@0
   595
sl@0
   596
	if (filename.CompareF(KFontDummy) == 0)
sl@0
   597
		attrib.SetFullName(_L("Dummy"));
sl@0
   598
	else if (filename.CompareF(KFontDummy_b) == 0)
sl@0
   599
		{
sl@0
   600
		attrib.SetFullName(_L("Dummy Bold"));
sl@0
   601
		attrib.SetBold(TRUE);
sl@0
   602
		}
sl@0
   603
	else if (filename.CompareF(KFontDummy_i) == 0)
sl@0
   604
		{
sl@0
   605
		attrib.SetFullName(_L("Dummy Italic"));
sl@0
   606
		attrib.SetItalic(TRUE);
sl@0
   607
		}
sl@0
   608
	else if (filename.CompareF(KFontDummy_bi) == 0)
sl@0
   609
		{
sl@0
   610
		attrib.SetFullName(_L("Dummy Bold Italic"));
sl@0
   611
		attrib.SetBold(TRUE);
sl@0
   612
		attrib.SetItalic(TRUE);
sl@0
   613
		}
sl@0
   614
	attrib.SetFamilyName(_L("Dummy"));
sl@0
   615
	attrib.SetLocalFullName(attrib.FullName());
sl@0
   616
	attrib.SetCoverage(TOpenFontFaceAttrib::ELatinSet);
sl@0
   617
	attrib.SetMinSizeInPixels(8);
sl@0
   618
	AddFaceL(attrib);
sl@0
   619
	}
sl@0
   620
sl@0
   621
void CDummyFontFile::GetNearestFontInPixelsL(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList,
sl@0
   622
											 const TOpenFontSpec& aDesiredFontSpec,TInt aPixelWidth,TInt aPixelHeight,
sl@0
   623
											 COpenFont*& aFont,TOpenFontSpec& aActualFontSpec)
sl@0
   624
sl@0
   625
	{
sl@0
   626
	aFont = NULL;
sl@0
   627
	TInt face_index = 0;
sl@0
   628
	if (GetNearestFontHelper(aDesiredFontSpec,aPixelWidth,aPixelHeight,face_index,aActualFontSpec))
sl@0
   629
		aFont = CDummyFont::NewL(aHeap,aSessionCacheList,this,aActualFontSpec.Height());
sl@0
   630
	}
sl@0
   631
sl@0
   632
void CDummyFontFile::GetNearestFontToDesignHeightInPixelsL(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList,
sl@0
   633
											 const TOpenFontSpec& aDesiredFontSpec,TInt aPixelWidth,TInt aPixelHeight,
sl@0
   634
											 COpenFont*& aFont,TOpenFontSpec& aActualFontSpec)
sl@0
   635
sl@0
   636
	{
sl@0
   637
	aFont = NULL;
sl@0
   638
	TInt face_index = 0;
sl@0
   639
	if (GetNearestFontHelper(aDesiredFontSpec,aPixelWidth,aPixelHeight,face_index,aActualFontSpec))
sl@0
   640
		aFont = CDummyFont::NewL(aHeap,aSessionCacheList,this,aActualFontSpec.Height());
sl@0
   641
	}
sl@0
   642
sl@0
   643
void CDummyFontFile::GetNearestFontToMaxHeightInPixelsL(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList,
sl@0
   644
											 const TOpenFontSpec& aDesiredFontSpec,TInt aPixelWidth,TInt aPixelHeight,
sl@0
   645
											 COpenFont*& aFont,TOpenFontSpec& aActualFontSpec,TInt /*aMaxHeight*/)
sl@0
   646
sl@0
   647
	{
sl@0
   648
	aFont = NULL;
sl@0
   649
	TInt face_index = 0;
sl@0
   650
	if (GetNearestFontHelper(aDesiredFontSpec,aPixelWidth,aPixelHeight,face_index,aActualFontSpec))
sl@0
   651
		aFont = CDummyFont::NewL(aHeap,aSessionCacheList,this,aActualFontSpec.Height());
sl@0
   652
	}
sl@0
   653
sl@0
   654
TBool CDummyFontFile::HasUnicodeCharacterL(TInt /*aFaceIndex*/,TInt /*aCode*/) const
sl@0
   655
	{
sl@0
   656
	return EFalse; // this dummy font has no characters
sl@0
   657
	}
sl@0
   658
sl@0
   659
CDummyFont* CDummyFont::NewL(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList,
sl@0
   660
							 CDummyFontFile* aFontFile,TInt aSizeInPixels)
sl@0
   661
	{
sl@0
   662
	CDummyFont* f = (CDummyFont*)aHeap->AllocL(sizeof(CDummyFont));
sl@0
   663
	new(f) CDummyFont(aHeap,aSessionCacheList,aFontFile,aSizeInPixels);
sl@0
   664
	return f;
sl@0
   665
	}
sl@0
   666
sl@0
   667
CDummyFont::CDummyFont(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList,CDummyFontFile* aFontFile,
sl@0
   668
					   TInt aSizeInPixels):
sl@0
   669
	COpenFont(aHeap,aSessionCacheList,aFontFile)
sl@0
   670
	{
sl@0
   671
	iMetrics.SetSize(aSizeInPixels);
sl@0
   672
	iMetrics.SetAscent(aSizeInPixels * 3 / 4);
sl@0
   673
	iMetrics.SetDescent(aSizeInPixels - iMetrics.Ascent());
sl@0
   674
	iMetrics.SetMaxHeight(iMetrics.Ascent());
sl@0
   675
	iMetrics.SetMaxDepth(iMetrics.Descent());
sl@0
   676
	iMetrics.SetMaxWidth(aSizeInPixels * 2);
sl@0
   677
	}
sl@0
   678
sl@0
   679
void CDummyFont::RasterizeL(TInt /*aCode*/,TOpenFontGlyphData* /*aGlyphData*/)
sl@0
   680
	{
sl@0
   681
	User::Leave(KErrNotSupported); // this dummy font has no glyphs
sl@0
   682
	}
sl@0
   683
sl@0
   684
static void ExpandCleanupStackL()
sl@0
   685
	{
sl@0
   686
	TInt count = 0;
sl@0
   687
	for (; count < 10; count++)
sl@0
   688
		CleanupStack::PushL((TUint32*)0x1);
sl@0
   689
	CleanupStack::Pop(count);
sl@0
   690
	}
sl@0
   691
sl@0
   692
//--------------
sl@0
   693
__CONSTRUCT_STEP__(FsOpen)
sl@0
   694
sl@0
   695
sl@0
   696
void CTFsOpenStep::TestSetupL()
sl@0
   697
	{
sl@0
   698
	ExpandCleanupStackL();
sl@0
   699
	}