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