os/textandloc/fontservices/fontstore/tfs/T_FNT.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) 2006-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
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file
sl@0
    21
 @test
sl@0
    22
 @internalComponent Internal Symbian test code
sl@0
    23
*/
sl@0
    24
sl@0
    25
#include "T_IsolatedFontStore.h"
sl@0
    26
#include <f32file.h>
sl@0
    27
#include <e32test.h>
sl@0
    28
#include <fntstore.h>
sl@0
    29
#include <f32file.h>
sl@0
    30
#include <s32file.h>
sl@0
    31
#include <fbs.h>
sl@0
    32
#include "T_FNT.H"
sl@0
    33
sl@0
    34
#ifdef __WINS__
sl@0
    35
_LIT(KEonFontFileName,"z:\\resource\\fonts\\eon14.gdr");
sl@0
    36
#else
sl@0
    37
_LIT(KEonFontFileName,"z:\\resource\\fonts\\eon.gdr");
sl@0
    38
#endif
sl@0
    39
sl@0
    40
// Set KVerboseOutput to "ETrue" if extra INFO_PRINTFx for debug purposes are required
sl@0
    41
const TBool KVerboseOutput = EFalse;
sl@0
    42
sl@0
    43
_LIT(K7650FontFileName,"z:\\resource\\fonts\\ceurope.gdr");
sl@0
    44
sl@0
    45
sl@0
    46
sl@0
    47
CTFnt::CTFnt(CTestStep* aStep):
sl@0
    48
	CTGraphicsBase(aStep)
sl@0
    49
	{
sl@0
    50
	INFO_PRINTF1(_L("FontStore T_FNT test\n"));
sl@0
    51
	}
sl@0
    52
sl@0
    53
/**
sl@0
    54
	@SYMTestCaseID
sl@0
    55
	GRAPHICS-FNTSTORE-0023
sl@0
    56
sl@0
    57
	@SYMTestCaseDesc
sl@0
    58
	Tests adding a font file to the font store and checks
sl@0
    59
	the properties of the font.
sl@0
    60
sl@0
    61
	@SYMTestActions
sl@0
    62
	Creates a user heap. Creates a CFontStore object and
sl@0
    63
	uses the user heap for memory allocation. Adds a
sl@0
    64
	font file to the font store. Checks if added correctly.
sl@0
    65
	Gets the typeface information for the font. Retrieves the
sl@0
    66
	nearest available font. Sets the font style to superscript
sl@0
    67
	and subscript and tests getting nearest font. Then for all
sl@0
    68
	available typefaces it gets the nearest fonts and checks the
sl@0
    69
	result. The user heap is closed and the heap is checked for memory leaks.
sl@0
    70
	
sl@0
    71
	@SYMTestExpectedResults
sl@0
    72
	Test should pass
sl@0
    73
*/
sl@0
    74
void CTFnt::TestReadFileL(const TDesC& aFontFile)
sl@0
    75
	{
sl@0
    76
	
sl@0
    77
	INFO_PRINTF2(_L("Starting TestReadFile with parameter %S"), &aFontFile);
sl@0
    78
	
sl@0
    79
	__UHEAP_MARK;
sl@0
    80
	RHeap* heap=UserHeap::ChunkHeap(NULL,0x10000,0x10000);
sl@0
    81
sl@0
    82
// Add file
sl@0
    83
sl@0
    84
	TUid id1 = TUid::Uid(0);
sl@0
    85
	CFontStore *fs=CFontStore::NewL(heap);
sl@0
    86
sl@0
    87
	TRAPD(ret,id1=fs->AddFileL(aFontFile));
sl@0
    88
	TEST(ret==KErrNone);
sl@0
    89
	INFO_PRINTF2(_L("NumTypefaces %d"),fs->NumTypefaces());
sl@0
    90
sl@0
    91
// Get typeface info
sl@0
    92
sl@0
    93
	INFO_PRINTF1(_L("Get typeface support"));
sl@0
    94
	TTypefaceSupport support;
sl@0
    95
	fs->TypefaceSupport(support,0);
sl@0
    96
	TBuf<KMaxTypefaceNameLength> name;
sl@0
    97
	name.Copy(support.iTypeface.iName);
sl@0
    98
	INFO_PRINTF2(_L("Typeface Name %S"),&name);
sl@0
    99
	INFO_PRINTF2(_L("Typeface Isproportional %d"),support.iTypeface.IsProportional());
sl@0
   100
	INFO_PRINTF2(_L("Typeface IsSerif %d"),support.iTypeface.IsSerif());
sl@0
   101
	INFO_PRINTF2(_L("Typeface IsSymbol %d"),support.iTypeface.IsSymbol());
sl@0
   102
	INFO_PRINTF2(_L("NumHeights %d"),support.iNumHeights);
sl@0
   103
	INFO_PRINTF2(_L("MinHeightInTwips %d"),support.iMinHeightInTwips);
sl@0
   104
	INFO_PRINTF2(_L("MaxHeightInTwips %d"),support.iMaxHeightInTwips);
sl@0
   105
	INFO_PRINTF2(_L("IsScalable %d"),support.iIsScalable);
sl@0
   106
sl@0
   107
	if (KVerboseOutput)
sl@0
   108
		{
sl@0
   109
		for (TInt i=0; i<support.iNumHeights; i++)
sl@0
   110
			{
sl@0
   111
			INFO_PRINTF3(_L("HeightInPixels %d is %d"),i,fs->FontHeightInPixels(0/*fs->NumTypefaces()-2*/,i));
sl@0
   112
			}
sl@0
   113
		}
sl@0
   114
sl@0
   115
// Get nearest font
sl@0
   116
 
sl@0
   117
	INFO_PRINTF1(_L("Get nearest font"));
sl@0
   118
	CBitmapFont *font;
sl@0
   119
	TCharacterMetrics metrics;
sl@0
   120
	const TUint8* bytes;
sl@0
   121
	TFontSpec spec;
sl@0
   122
	support.iTypeface=support.iTypeface;
sl@0
   123
	spec.iTypeface.SetIsProportional(EFalse);
sl@0
   124
	spec.iTypeface.SetIsSerif(ETrue);
sl@0
   125
	spec.iTypeface.SetIsSymbol(EFalse);
sl@0
   126
	spec.iHeight=10;
sl@0
   127
	spec.iFontStyle.SetPosture(EPostureUpright);
sl@0
   128
	for (spec.iHeight=support.iMinHeightInTwips; spec.iHeight<=support.iMaxHeightInTwips; spec.iHeight++)
sl@0
   129
		{
sl@0
   130
		ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec);
sl@0
   131
		TEST(ret==KErrNone);
sl@0
   132
		if (KVerboseOutput)
sl@0
   133
			{
sl@0
   134
			INFO_PRINTF2(_L("FontSpec Height %d"),spec.iHeight);
sl@0
   135
			INFO_PRINTF2(_L("HeightInTwips %d"),font->FontSpecInTwips().iHeight);
sl@0
   136
			INFO_PRINTF2(_L("HeightInPixels %d"),font->HeightInPixels());
sl@0
   137
			INFO_PRINTF2(_L("AscentInPixels %d"),font->AscentInPixels());
sl@0
   138
			INFO_PRINTF3(_L("Font Posture %d StrokeWeight %d"),font->FontSpecInTwips().iFontStyle.Posture(),font->FontSpecInTwips().iFontStyle.StrokeWeight());
sl@0
   139
			INFO_PRINTF3(_L("Font AlgPosture %d AlgStrokeWeight %d"),((CBitmapFont*)font)->iAlgStyle.IsItalic(),((CBitmapFont*)font)->iAlgStyle.IsBold());
sl@0
   140
			}
sl@0
   141
		fs->ReleaseFont(font);
sl@0
   142
		}
sl@0
   143
sl@0
   144
	ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec);
sl@0
   145
	TEST(ret==KErrNone);
sl@0
   146
	INFO_PRINTF1(_L("Got nearest font"));
sl@0
   147
	metrics = font->CharacterMetrics(32,bytes);
sl@0
   148
	INFO_PRINTF5(_L("First 4 bytes %d %d %d %d"),*(bytes),*(bytes+1),*(bytes+2),*(bytes+3));
sl@0
   149
	INFO_PRINTF5(_L("Second 4 bytes %d %d %d %d"),*(bytes+4),*(bytes+5),*(bytes+6),*(bytes+7));
sl@0
   150
sl@0
   151
	INFO_PRINTF2(_L("LeftAdjustInPixels %d"),metrics.iLeftAdjustInPixels);
sl@0
   152
	INFO_PRINTF2(_L("MoveInPixels %d"),metrics.iMoveInPixels);
sl@0
   153
	INFO_PRINTF2(_L("RightAdjustInPixels %d"),metrics.iRightAdjustInPixels);
sl@0
   154
	INFO_PRINTF2(_L("TextWidthInPixels(EPOC) %d"),font->TextWidthInPixels(_L("EPOC")));
sl@0
   155
	INFO_PRINTF2(_L("TextWidthInPixels(\x00BB) %d"),font->TextWidthInPixels(_L("\x00BB")));		//Double Greater Than »
sl@0
   156
	CFont::TMeasureTextInput param;
sl@0
   157
	param.iStartInputChar = 34;
sl@0
   158
	INFO_PRINTF2(_L("TextWidthInPixels with supplied context(EPOC) %d"),font->TextWidthInPixels(_L("->This text will not be measured<-EPOC"),&param));
sl@0
   159
	INFO_PRINTF2(_L("TextWidthInPixels with supplied context(\x00BB) %d"),font->TextWidthInPixels(_L("->This text will not be measured<-\x00BB"),&param));
sl@0
   160
	INFO_PRINTF2(_L("TextCount(EPOC,50) %d"),font->TextCount(_L("EPOC"),50));
sl@0
   161
sl@0
   162
	INFO_PRINTF2(_L("WidthZeroInPixels %d"),font->WidthZeroInPixels());
sl@0
   163
	INFO_PRINTF2(_L("MaxCharWidthInPixels %d"),font->MaxCharWidthInPixels());
sl@0
   164
	INFO_PRINTF2(_L("MaxNormalCharWidthInPixels %d"),font->MaxNormalCharWidthInPixels());
sl@0
   165
	INFO_PRINTF2(_L("HeightInTwips %d"),font->FontSpecInTwips().iHeight);
sl@0
   166
	name.Copy(font->FontSpecInTwips().iTypeface.iName);
sl@0
   167
	INFO_PRINTF2(_L("Typeface Name %S"),&name);
sl@0
   168
sl@0
   169
	fs->ReleaseFont(font);
sl@0
   170
sl@0
   171
// Get nearest font
sl@0
   172
 
sl@0
   173
	INFO_PRINTF1(_L("Get nearest monoized font"));
sl@0
   174
	support.iTypeface.iName=_L("");//Mono Swiss");
sl@0
   175
	support.iTypeface.SetIsProportional(ETrue);//=support.iTypeface;
sl@0
   176
	support.iTypeface.SetIsSerif(ETrue);//=support.iTypeface;
sl@0
   177
	spec.iTypeface=support.iTypeface;
sl@0
   178
	spec.iHeight=18;
sl@0
   179
	spec.iFontStyle.SetPosture(EPostureUpright);
sl@0
   180
	spec.iFontStyle.SetPrintPosition(EPrintPosNormal);
sl@0
   181
	ret=fs->GetNearestFontToDesignHeightInPixels((CFont *&) font,spec);
sl@0
   182
	TEST(ret==KErrNone);
sl@0
   183
	INFO_PRINTF2(_L("HeightInPixels %d"),font->HeightInPixels());
sl@0
   184
	INFO_PRINTF2(_L("AscentInPixels %d"),font->AscentInPixels());
sl@0
   185
	metrics = font->CharacterMetrics(32,bytes);
sl@0
   186
	INFO_PRINTF5(_L("First 4 bytes %d %d %d %d"),*(bytes),*(bytes+1),*(bytes+2),*(bytes+3));
sl@0
   187
	INFO_PRINTF5(_L("Second 4 bytes %d %d %d %d"),*(bytes+4),*(bytes+5),*(bytes+6),*(bytes+7));
sl@0
   188
	INFO_PRINTF2(_L("LeftAdjustInPixels %d"),metrics.iLeftAdjustInPixels);
sl@0
   189
	INFO_PRINTF2(_L("MoveInPixels %d"),metrics.iMoveInPixels);
sl@0
   190
	INFO_PRINTF2(_L("RightAdjustInPixels %d"),metrics.iRightAdjustInPixels);
sl@0
   191
	INFO_PRINTF2(_L("TextWidthInPixels(EPOC) %d"),font->TextWidthInPixels(_L("EPOC")));
sl@0
   192
	INFO_PRINTF2(_L("WidthZeroInPixels %d"),font->WidthZeroInPixels());
sl@0
   193
	INFO_PRINTF2(_L("TextCount(EPOC,50) %d"),font->TextCount(_L("EPOC"),50));
sl@0
   194
	INFO_PRINTF2(_L("MaxCharWidthInPixels %d"),font->MaxCharWidthInPixels());
sl@0
   195
	INFO_PRINTF2(_L("MaxNormalCharWidthInPixels %d"),font->MaxNormalCharWidthInPixels());
sl@0
   196
	INFO_PRINTF2(_L("HeightInTwips %d"),font->FontSpecInTwips().iHeight);
sl@0
   197
	name.Copy(font->FontSpecInTwips().iTypeface.iName);
sl@0
   198
	INFO_PRINTF2(_L("Typeface Name %S"),&name);
sl@0
   199
sl@0
   200
	fs->ReleaseFont(font);
sl@0
   201
sl@0
   202
// Get superscript font
sl@0
   203
 
sl@0
   204
	INFO_PRINTF1(_L("Get superscript font"));
sl@0
   205
	spec.iFontStyle.SetPrintPosition(EPrintPosSuperscript);
sl@0
   206
	ret=fs->GetNearestFontToDesignHeightInPixels((CFont *&) font,spec);
sl@0
   207
	TEST(ret==KErrNone);
sl@0
   208
	INFO_PRINTF2(_L("HeightInPixels %d"),font->HeightInPixels());
sl@0
   209
	INFO_PRINTF2(_L("BaselineOffsetInPixels %d"),font->iAlgStyle.iBaselineOffsetInPixels);
sl@0
   210
	INFO_PRINTF2(_L("HeightInTwips %d"),font->FontSpecInTwips().iHeight);
sl@0
   211
	name.Copy(font->FontSpecInTwips().iTypeface.iName);
sl@0
   212
	INFO_PRINTF2(_L("Typeface Name %S"),&name);
sl@0
   213
sl@0
   214
	fs->ReleaseFont(font);
sl@0
   215
sl@0
   216
// Get subscript font
sl@0
   217
 
sl@0
   218
	INFO_PRINTF1(_L("Get subscript font"));
sl@0
   219
	spec.iFontStyle.SetPrintPosition(EPrintPosSubscript);
sl@0
   220
	ret=fs->GetNearestFontToDesignHeightInPixels((CFont *&) font,spec);
sl@0
   221
	TEST(ret==KErrNone);
sl@0
   222
	INFO_PRINTF2(_L("HeightInPixels %d"),font->HeightInPixels());
sl@0
   223
	INFO_PRINTF2(_L("BaselineOffsetInPixels %d"),font->iAlgStyle.iBaselineOffsetInPixels);
sl@0
   224
	INFO_PRINTF2(_L("HeightInTwips %d"),font->FontSpecInTwips().iHeight);
sl@0
   225
	name.Copy(font->FontSpecInTwips().iTypeface.iName);
sl@0
   226
	INFO_PRINTF2(_L("Typeface Name %S"),&name);
sl@0
   227
sl@0
   228
	fs->ReleaseFont(font);
sl@0
   229
sl@0
   230
//  aTest all fonts
sl@0
   231
sl@0
   232
	INFO_PRINTF1(_L("Get typeface support"));
sl@0
   233
	spec.iFontStyle.SetPrintPosition(EPrintPosNormal);
sl@0
   234
	spec.iFontStyle.SetPosture(EPostureUpright);
sl@0
   235
	spec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
sl@0
   236
	for (TInt i=0; i<fs->NumTypefaces(); i++)
sl@0
   237
		{
sl@0
   238
		fs->TypefaceSupport(support,i);
sl@0
   239
		name.Copy(support.iTypeface.iName);
sl@0
   240
		INFO_PRINTF2(_L("Typeface Name %S"),&name);
sl@0
   241
		for (TInt j=0; j<support.iNumHeights; j++)
sl@0
   242
			{
sl@0
   243
			spec.iTypeface=support.iTypeface;
sl@0
   244
			spec.iHeight=fs->FontHeightInPixels(i,j);
sl@0
   245
			ret=fs->GetNearestFontToDesignHeightInPixels((CFont *&) font,spec);
sl@0
   246
			TEST(ret==KErrNone);
sl@0
   247
			INFO_PRINTF2(_L("Spec HeightInPixels %d"),spec.iHeight);
sl@0
   248
			INFO_PRINTF2(_L("Font HeightInPixels %d"),font->HeightInPixels());
sl@0
   249
			INFO_PRINTF3(_L("Font Posture %d StrokeWeight %d"),font->FontSpecInTwips().iFontStyle.Posture(),font->FontSpecInTwips().iFontStyle.StrokeWeight());
sl@0
   250
			INFO_PRINTF3(_L("Font AlgPosture %d AlgStrokeWeight %d"),font->iAlgStyle.IsItalic(),font->iAlgStyle.IsBold());
sl@0
   251
			fs->ReleaseFont(font);
sl@0
   252
			}
sl@0
   253
		}
sl@0
   254
sl@0
   255
// Close fontstore
sl@0
   256
	INFO_PRINTF1(_L("Destroy filestore\n\n"));	
sl@0
   257
	delete fs;
sl@0
   258
sl@0
   259
	heap->Close();
sl@0
   260
	__UHEAP_MARKEND;
sl@0
   261
	}
sl@0
   262
sl@0
   263
/**
sl@0
   264
@SYMTestCaseID
sl@0
   265
GRAPHICS-FNTSTORE-0052
sl@0
   266
sl@0
   267
@SYMPREQ
sl@0
   268
PREQ2147
sl@0
   269
sl@0
   270
@SYMREQ
sl@0
   271
REQ12172
sl@0
   272
sl@0
   273
@SYMTestCaseDesc
sl@0
   274
Creates an instance of fontstore to test that invalid font files generated by the test script
sl@0
   275
have not eclipsed the valid files already loaded.
sl@0
   276
sl@0
   277
@SYMTestPriority
sl@0
   278
Critical
sl@0
   279
sl@0
   280
@SYMTestStatus
sl@0
   281
Implemented
sl@0
   282
sl@0
   283
@SYMTestActions
sl@0
   284
The start of this test script will create an invalid font file in c:\resource\fonts. This test
sl@0
   285
creates an instance of font store and performs the font loading to check the invalid file is not
sl@0
   286
loaded and font store has fallen back to the correct file.
sl@0
   287
sl@0
   288
The test also ensures that the invalid file has been created sucessfully by T_WriteInvalidFontFile.exe
sl@0
   289
sl@0
   290
After this set off test have been run the file is removed by T_RemoveInvalidFontFile.exe
sl@0
   291
sl@0
   292
@SYMTestExpectedResults
sl@0
   293
The Invalid Font file will exist; font store will not load this file and instead will load the file that it
sl@0
   294
eclipses (from ROM)
sl@0
   295
sl@0
   296
*/
sl@0
   297
void CTFnt::TestEclipseFallbackWithInvalidFontL()
sl@0
   298
	{
sl@0
   299
	//The path of the invalid file that should not be loaded
sl@0
   300
	_LIT(KInvalidFontFilePath, "c:\\resource\\fonts\\DejaVuSansCondensed.ttf");
sl@0
   301
	
sl@0
   302
	//The path of the valid file that should be loaded
sl@0
   303
	_LIT(KValidFontPath, "z:\\resource\\fonts\\DejaVuSansCondensed.ttf");
sl@0
   304
	
sl@0
   305
	//Check the invalid file exists
sl@0
   306
	RFs fs;
sl@0
   307
	User::LeaveIfError(fs.Connect());
sl@0
   308
	
sl@0
   309
	RFile file;
sl@0
   310
	TEST(file.Open(fs, KInvalidFontFilePath, EFileRead) == KErrNone);
sl@0
   311
	
sl@0
   312
	file.Close();
sl@0
   313
	fs.Close();
sl@0
   314
	
sl@0
   315
	//Create an instance of CFontStore and load the current rasterizers and fonts
sl@0
   316
	CTIsolatedFontStore* isolatedFontStore1 = CTIsolatedFontStore::NewL();
sl@0
   317
	CleanupStack::PushL(isolatedFontStore1);
sl@0
   318
	
sl@0
   319
	isolatedFontStore1->LoadRasterizersL();
sl@0
   320
	
sl@0
   321
	CFontStore* fs1 = isolatedFontStore1->iFs;
sl@0
   322
	fs1->LoadFontsAtStartupL();
sl@0
   323
	
sl@0
   324
	TFileName fileName;
sl@0
   325
	fs1->GetFontFilePath(_L("DejaVu Sans Condensed"), fileName);
sl@0
   326
sl@0
   327
	TEST(fileName.CompareF(KValidFontPath) == 0);
sl@0
   328
		
sl@0
   329
	CleanupStack::PopAndDestroy(isolatedFontStore1);
sl@0
   330
	}
sl@0
   331
sl@0
   332
void CTFnt::RunTestCaseL(TInt aCurTestCase)
sl@0
   333
	{
sl@0
   334
	((CTFntStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
   335
	switch(aCurTestCase)
sl@0
   336
		{
sl@0
   337
	case 1:
sl@0
   338
		((CTFntStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0023"));
sl@0
   339
		INFO_PRINTF1(_L("#################### T_FNT test case 1 ########################\n"));
sl@0
   340
		TRAPD(err,TestReadFileL(KEonFontFileName));
sl@0
   341
		TEST(err == KErrNone);
sl@0
   342
		break;
sl@0
   343
	case 2:
sl@0
   344
		((CTFntStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0023"));
sl@0
   345
		INFO_PRINTF1(_L("#################### T_FNT test case 2 ########################\n"));
sl@0
   346
		TRAP(err,TestReadFileL(K7650FontFileName));
sl@0
   347
		TEST(err == KErrNone);
sl@0
   348
		break;
sl@0
   349
	case 3:
sl@0
   350
		((CTFntStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0052"));
sl@0
   351
		INFO_PRINTF1(_L("T_FNT test case 3 - Eclipsed font in \\resource\\fonts falls back to last good font"));
sl@0
   352
		TRAP(err,TestEclipseFallbackWithInvalidFontL());
sl@0
   353
		TEST(err == KErrNone);
sl@0
   354
	case 4:
sl@0
   355
		((CTFntStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   356
		((CTFntStep*)iStep)->CloseTMSGraphicsStep();
sl@0
   357
		TestComplete();				
sl@0
   358
		break;
sl@0
   359
		}
sl@0
   360
	((CTFntStep*)iStep)->RecordTestResultL();
sl@0
   361
	}
sl@0
   362
sl@0
   363
sl@0
   364
//--------------
sl@0
   365
__CONSTRUCT_STEP__(Fnt)
sl@0
   366
sl@0
   367
sl@0
   368