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