fontservices/fontstore/tfs/T_FontMetrics.cpp
changeset 57 01e38b33e72a
parent 0 1fb32624e06b
child 55 336bee5c2d35
equal deleted inserted replaced
51:a7c938434754 57:01e38b33e72a
   298 
   298 
   299    @SYMTestExpectedResults See returned values in Verify_GetNearestFontToDesignHeightInPixels.
   299    @SYMTestExpectedResults See returned values in Verify_GetNearestFontToDesignHeightInPixels.
   300 */
   300 */
   301 void CTFontMetrics::GetNearestFontToDesignHeightInPixels()
   301 void CTFontMetrics::GetNearestFontToDesignHeightInPixels()
   302 	{
   302 	{
       
   303     INFO_PRINTF3(_L("iKPixelWidthInTwips = %d; iKPixelHeightInTwips = %d"), 
       
   304                 iFontStore->iKPixelWidthInTwips, iFontStore->iKPixelHeightInTwips);
       
   305     
   303 	TOpenFontSpec openFontSpec = GetTOpenFontSpec();
   306 	TOpenFontSpec openFontSpec = GetTOpenFontSpec();
   304 
   307 
       
   308 	INFO_PRINTF1(_L("GetNearestFontToDesignHeightInPixels().ELangNone"));
   305 	CFont* font = NULL;
   309 	CFont* font = NULL;
   306 	openFontSpec.SetScriptTypeForMetrics(ELangNone);
   310 	openFontSpec.SetScriptTypeForMetrics(ELangNone);
   307 	iFontStore->GetNearestFontToDesignHeightInPixels(font, openFontSpec);
   311 	iFontStore->GetNearestFontToDesignHeightInPixels(font, openFontSpec);
   308 	Verify_GetNearestFontToDesignHeightInPixels(*font, openFontSpec.ScriptTypeForMetrics());
   312 	Verify_GetNearestFontToDesignHeightInPixels(*font, openFontSpec.ScriptTypeForMetrics());
   309 	iFontStore->ReleaseFont(font);
   313 	iFontStore->ReleaseFont(font);
   310 
   314 
       
   315 	INFO_PRINTF1(_L("GetNearestFontToDesignHeightInPixels().ELangFinnish"));
   311 	font = NULL;
   316 	font = NULL;
   312 	openFontSpec.SetScriptTypeForMetrics(ELangFinnish);
   317 	openFontSpec.SetScriptTypeForMetrics(ELangFinnish);
   313 	iFontStore->GetNearestFontToDesignHeightInPixels(font, openFontSpec);
   318 	iFontStore->GetNearestFontToDesignHeightInPixels(font, openFontSpec);
   314 	Verify_GetNearestFontToDesignHeightInPixels(*font, openFontSpec.ScriptTypeForMetrics());
   319 	Verify_GetNearestFontToDesignHeightInPixels(*font, openFontSpec.ScriptTypeForMetrics());
   315 	iFontStore->ReleaseFont(font);
   320 	iFontStore->ReleaseFont(font);
   316 
   321 
       
   322 	INFO_PRINTF1(_L("GetNearestFontToDesignHeightInPixels().ELangGreek"));
   317 	font = NULL;
   323 	font = NULL;
   318 	openFontSpec.SetScriptTypeForMetrics(ELangGreek);
   324 	openFontSpec.SetScriptTypeForMetrics(ELangGreek);
   319 	iFontStore->GetNearestFontToDesignHeightInPixels(font, openFontSpec);
   325 	iFontStore->GetNearestFontToDesignHeightInPixels(font, openFontSpec);
   320 	Verify_GetNearestFontToDesignHeightInPixels(*font, openFontSpec.ScriptTypeForMetrics());
   326 	Verify_GetNearestFontToDesignHeightInPixels(*font, openFontSpec.ScriptTypeForMetrics());
   321 	iFontStore->ReleaseFont(font);
   327 	iFontStore->ReleaseFont(font);
   322 
   328 
       
   329 	INFO_PRINTF1(_L("GetNearestFontToDesignHeightInPixels().ELangRussian"));
   323 	font = NULL;
   330 	font = NULL;
   324 	openFontSpec.SetScriptTypeForMetrics(ELangRussian);
   331 	openFontSpec.SetScriptTypeForMetrics(ELangRussian);
   325 	iFontStore->GetNearestFontToDesignHeightInPixels(font, openFontSpec);
   332 	iFontStore->GetNearestFontToDesignHeightInPixels(font, openFontSpec);
   326 	Verify_GetNearestFontToDesignHeightInPixels(*font, openFontSpec.ScriptTypeForMetrics());
   333 	Verify_GetNearestFontToDesignHeightInPixels(*font, openFontSpec.ScriptTypeForMetrics());
   327 	iFontStore->ReleaseFont(font);
   334 	iFontStore->ReleaseFont(font);
   328 	}
   335 	}
   329 
   336 
   330 void CTFontMetrics::Verify_GetNearestFontToDesignHeightInPixels(const CFont& aFont, TInt aScript)
   337 void CTFontMetrics::Verify_GetNearestFontToDesignHeightInPixels(const CFont& aFont, TInt aScript)
   331 	{
   338 	{
   332 	VerifyTypefaceNameAndID(aFont);
   339 	VerifyTypefaceNameAndID(aFont);
       
   340     INFO_PRINTF4(_L("HeightInPixels() = %d; AscentInPixels() = %d; DescentInPixels() = %d"), 
       
   341             aFont.HeightInPixels(), aFont.AscentInPixels(), aFont.DescentInPixels());
       
   342     INFO_PRINTF4(_L("FontCapitalAscent() = %d; FontStandardDescent() = %d; FontMaxAscent() = %d"), 
       
   343             aFont.FontCapitalAscent(), aFont.FontStandardDescent(), aFont.FontMaxAscent());
       
   344     INFO_PRINTF4(_L("FontMaxDescent() = %d; FontMaxHeight() = %d; FontLineGap() = %d"), 
       
   345             aFont.FontMaxDescent(), aFont.FontMaxHeight(), aFont.FontLineGap());
   333 	// Old metrics
   346 	// Old metrics
   334 	TEST(KRequiredHeight == aFont.HeightInPixels());
   347 	TEST(KRequiredHeight == aFont.HeightInPixels());
   335 	TEST(19 == aFont.AscentInPixels());
   348 	TEST(19 == aFont.AscentInPixels());
   336 	TEST(KRequiredHeight - aFont.AscentInPixels() == aFont.DescentInPixels());
   349 	TEST(KRequiredHeight - aFont.AscentInPixels() == aFont.DescentInPixels());
   337 	// New metrics
   350 	// New metrics
   338 	TEST(18 == aFont.FontCapitalAscent());
   351 	TEST(18 == aFont.FontCapitalAscent());
   339 	TEST(5  == aFont.FontStandardDescent());
   352 	TEST(5  == aFont.FontStandardDescent());
   340 	if (GlyphSample::EScriptNone == aScript)
   353 	if (GlyphSample::EScriptNone == aScript ||
       
   354 	        GlyphSample::EScriptLatin == aScript ||
       
   355 	        GlyphSample::EScriptGreek == aScript ||
       
   356 	        GlyphSample::EScriptCyrillic == aScript)	
   341 		{
   357 		{
   342 		TEST(28 == aFont.FontMaxAscent());
   358 		TEST(28 == aFont.FontMaxAscent());
   343 		TEST(8 	== aFont.FontMaxDescent());
   359 		TEST(8 	== aFont.FontMaxDescent());
   344 		TEST(42 == aFont.FontLineGap());
   360 		TEST(42 == aFont.FontLineGap());
   345 		}
       
   346 	else if (GlyphSample::EScriptLatin == aScript)
       
   347 		{
       
   348 		TEST(24 == aFont.FontMaxAscent());
       
   349 		TEST(5 	== aFont.FontMaxDescent());
       
   350 		TEST(35 == aFont.FontLineGap());
       
   351 		}
       
   352 	else if (GlyphSample::EScriptGreek == aScript)
       
   353 		{
       
   354 		TEST(22 == aFont.FontMaxAscent());
       
   355 		TEST(5 	== aFont.FontMaxDescent());
       
   356 		TEST(33 == aFont.FontLineGap());
       
   357 		}
       
   358 	else if (GlyphSample::EScriptCyrillic == aScript)
       
   359 		{
       
   360 		TEST(23 == aFont.FontMaxAscent());
       
   361 		TEST(5 	== aFont.FontMaxDescent());
       
   362 		TEST(34 == aFont.FontLineGap());
       
   363 		}
   361 		}
   364 	else TEST(1 == 0);
   362 	else TEST(1 == 0);
   365 	TEST(aFont.FontMaxAscent() + aFont.FontMaxDescent() == aFont.FontMaxHeight());
   363 	TEST(aFont.FontMaxAscent() + aFont.FontMaxDescent() == aFont.FontMaxHeight());
   366 	INFO_PRINTF2(_L("MaxCharWidthInPixels() returns %d"), aFont.MaxCharWidthInPixels());
   364 	INFO_PRINTF2(_L("MaxCharWidthInPixels() returns %d"), aFont.MaxCharWidthInPixels());
   367 	}
   365 	}
   391 */
   389 */
   392 void CTFontMetrics::GetNearestFontToMaxHeightInPixels()
   390 void CTFontMetrics::GetNearestFontToMaxHeightInPixels()
   393 	{
   391 	{
   394 	TOpenFontSpec openFontSpec = GetTOpenFontSpec();
   392 	TOpenFontSpec openFontSpec = GetTOpenFontSpec();
   395 
   393 
       
   394 	INFO_PRINTF1(_L("GetNearestFontToMaxHeightInPixels().ELangNone"));
   396 	CFont* font = NULL;
   395 	CFont* font = NULL;
   397 	openFontSpec.SetScriptTypeForMetrics(ELangNone);
   396 	openFontSpec.SetScriptTypeForMetrics(ELangNone);
   398 	iFontStore->GetNearestFontToMaxHeightInPixels(font, openFontSpec, KRequiredHeight);
   397 	iFontStore->GetNearestFontToMaxHeightInPixels(font, openFontSpec, KRequiredHeight);
   399 	Verify_GetNearestFontToMaxHeightInPixels(*font, openFontSpec.ScriptTypeForMetrics());
   398 	Verify_GetNearestFontToMaxHeightInPixels(*font, openFontSpec.ScriptTypeForMetrics());
   400 	iFontStore->ReleaseFont(font);
   399 	iFontStore->ReleaseFont(font);
   401 
   400 
       
   401 	INFO_PRINTF1(_L("GetNearestFontToMaxHeightInPixels().ELangFinnish"));
   402 	font = NULL;
   402 	font = NULL;
   403 	openFontSpec.SetScriptTypeForMetrics(ELangFinnish);
   403 	openFontSpec.SetScriptTypeForMetrics(ELangFinnish);
   404 	iFontStore->GetNearestFontToMaxHeightInPixels(font, openFontSpec, KRequiredHeight);
   404 	iFontStore->GetNearestFontToMaxHeightInPixels(font, openFontSpec, KRequiredHeight);
   405 	Verify_GetNearestFontToMaxHeightInPixels(*font, openFontSpec.ScriptTypeForMetrics());
   405 	Verify_GetNearestFontToMaxHeightInPixels(*font, openFontSpec.ScriptTypeForMetrics());
   406 	iFontStore->ReleaseFont(font);
   406 	iFontStore->ReleaseFont(font);
   407 
   407 
       
   408 	INFO_PRINTF1(_L("GetNearestFontToMaxHeightInPixels().ELangGreek"));
   408 	font = NULL;
   409 	font = NULL;
   409 	openFontSpec.SetScriptTypeForMetrics(ELangGreek);
   410 	openFontSpec.SetScriptTypeForMetrics(ELangGreek);
   410 	iFontStore->GetNearestFontToMaxHeightInPixels(font, openFontSpec, KRequiredHeight);
   411 	iFontStore->GetNearestFontToMaxHeightInPixels(font, openFontSpec, KRequiredHeight);
   411 	Verify_GetNearestFontToMaxHeightInPixels(*font, openFontSpec.ScriptTypeForMetrics());
   412 	Verify_GetNearestFontToMaxHeightInPixels(*font, openFontSpec.ScriptTypeForMetrics());
   412 	iFontStore->ReleaseFont(font);
   413 	iFontStore->ReleaseFont(font);
   413 
   414 
       
   415 	INFO_PRINTF1(_L("GetNearestFontToMaxHeightInPixels().ELangRussian"));
   414 	font = NULL;
   416 	font = NULL;
   415 	openFontSpec.SetScriptTypeForMetrics(ELangRussian);
   417 	openFontSpec.SetScriptTypeForMetrics(ELangRussian);
   416 	iFontStore->GetNearestFontToMaxHeightInPixels(font, openFontSpec, KRequiredHeight);
   418 	iFontStore->GetNearestFontToMaxHeightInPixels(font, openFontSpec, KRequiredHeight);
   417 	Verify_GetNearestFontToMaxHeightInPixels(*font, openFontSpec.ScriptTypeForMetrics());
   419 	Verify_GetNearestFontToMaxHeightInPixels(*font, openFontSpec.ScriptTypeForMetrics());
   418 	iFontStore->ReleaseFont(font);
   420 	iFontStore->ReleaseFont(font);
   419 	}
   421 	}
   420 
   422 
   421 void CTFontMetrics::Verify_GetNearestFontToMaxHeightInPixels(const CFont& aFont, TInt aScript)
   423 void CTFontMetrics::Verify_GetNearestFontToMaxHeightInPixels(const CFont& aFont, TInt aScript)
   422 	{
   424 	{
   423 	VerifyTypefaceNameAndID(aFont);
   425 	VerifyTypefaceNameAndID(aFont);
       
   426     INFO_PRINTF4(_L("HeightInPixels() = %d; AscentInPixels() = %d; DescentInPixels() = %d"), 
       
   427             aFont.HeightInPixels(), aFont.AscentInPixels(), aFont.DescentInPixels());
       
   428     INFO_PRINTF4(_L("FontCapitalAscent() = %d; FontStandardDescent() = %d; FontMaxAscent() = %d"), 
       
   429             aFont.FontCapitalAscent(), aFont.FontStandardDescent(), aFont.FontMaxAscent());
       
   430     INFO_PRINTF4(_L("FontMaxDescent() = %d; FontMaxHeight() = %d; FontLineGap() = %d"), 
       
   431             aFont.FontMaxDescent(), aFont.FontMaxHeight(), aFont.FontLineGap());
   424 	if (GlyphSample::EScriptNone == aScript)
   432 	if (GlyphSample::EScriptNone == aScript)
   425 		{
   433 		{
   426 		// Old metrics
   434 		// Old metrics
   427 		TEST(15 == aFont.HeightInPixels());
   435         TEST(16 == aFont.HeightInPixels());
   428 		TEST(12 == aFont.AscentInPixels());
   436         TEST(13 == aFont.AscentInPixels());
   429 		TEST(15 - 12 == aFont.DescentInPixels());
   437         TEST(16 - 13 == aFont.DescentInPixels());
   430 		// New metrics
   438         // New metrics
   431 		TEST(11 == aFont.FontCapitalAscent());
   439         TEST(12 == aFont.FontCapitalAscent());
   432 		TEST(3  == aFont.FontStandardDescent());
   440         TEST(3  == aFont.FontStandardDescent());
   433 		TEST(18 == aFont.FontMaxAscent());
   441         TEST(19 == aFont.FontMaxAscent());
   434 		TEST(5 	== aFont.FontMaxDescent());
   442         TEST(6  == aFont.FontMaxDescent());
   435 		TEST(KRequiredHeight - 1 == aFont.FontMaxHeight());
   443         TEST(KRequiredHeight + 1 == aFont.FontMaxHeight());
   436 		TEST(29 == aFont.FontLineGap());
   444         TEST(31 == aFont.FontLineGap());
   437 		}
   445 		}
   438 	else if (GlyphSample::EScriptLatin == aScript)
   446 	else if (GlyphSample::EScriptLatin == aScript ||
   439 		{
   447 	        GlyphSample::EScriptGreek == aScript ||
   440 		// Old metrics
   448 	        GlyphSample::EScriptCyrillic == aScript)
   441 		TEST(20 == aFont.HeightInPixels());
   449 	    {
   442 		TEST(16 == aFont.AscentInPixels());
   450         // Old metrics
   443 		TEST(20 - 16 == aFont.DescentInPixels());
   451         TEST(24 == aFont.HeightInPixels());
   444 		// New metrics
   452         TEST(19 == aFont.AscentInPixels());
   445 		TEST(15 == aFont.FontCapitalAscent());
   453         TEST(24 - 19 == aFont.DescentInPixels());
   446 		TEST(4  == aFont.FontStandardDescent());
   454         // New metrics
   447 		TEST(20 == aFont.FontMaxAscent());
   455         TEST(18 == aFont.FontCapitalAscent());
   448 		TEST(4 	== aFont.FontMaxDescent());
   456         TEST(5  == aFont.FontStandardDescent());
   449 		TEST(KRequiredHeight == aFont.FontMaxHeight());
   457         TEST(28 == aFont.FontMaxAscent());
   450 		TEST(30 == aFont.FontLineGap());
   458         TEST(8  == aFont.FontMaxDescent());
   451 		}
   459         TEST(KRequiredHeight + 12 == aFont.FontMaxHeight());
   452 	else if (GlyphSample::EScriptGreek == aScript)
   460         TEST(42 == aFont.FontLineGap());
   453 		{
   461 	    }
   454 		// Old metrics
       
   455 		TEST(20 == aFont.HeightInPixels());
       
   456 		TEST(16 == aFont.AscentInPixels());
       
   457 		TEST(20 - 16 == aFont.DescentInPixels());
       
   458 		// New metrics
       
   459 		TEST(15 == aFont.FontCapitalAscent());
       
   460 		TEST(4  == aFont.FontStandardDescent());
       
   461 		TEST(18 == aFont.FontMaxAscent());
       
   462 		TEST(5 	== aFont.FontMaxDescent());
       
   463 		TEST(KRequiredHeight - 1 == aFont.FontMaxHeight());
       
   464 		TEST(29 == aFont.FontLineGap());
       
   465 		}
       
   466 	else if (GlyphSample::EScriptCyrillic == aScript)
       
   467 		{
       
   468 		// Old metrics
       
   469 		TEST(21 == aFont.HeightInPixels());
       
   470 		TEST(16 == aFont.AscentInPixels());
       
   471 		TEST(21 - 16 == aFont.DescentInPixels());
       
   472 		// New metrics
       
   473 		TEST(16 == aFont.FontCapitalAscent());
       
   474 		TEST(4  == aFont.FontStandardDescent());
       
   475 		TEST(20 == aFont.FontMaxAscent());
       
   476 		TEST(4 	== aFont.FontMaxDescent());
       
   477 		TEST(KRequiredHeight == aFont.FontMaxHeight());
       
   478 		TEST(30 == aFont.FontLineGap());
       
   479 		}
       
   480 	else TEST(1 == 0);
   462 	else TEST(1 == 0);
   481 	INFO_PRINTF2(_L("MaxCharWidthInPixels() returns %d"), aFont.MaxCharWidthInPixels());
   463 	INFO_PRINTF2(_L("MaxCharWidthInPixels() returns %d"), aFont.MaxCharWidthInPixels());
   482 	}
   464 	}
   483 
   465 
   484 void CTFontMetrics::VerifyTypefaceNameAndID(const CFont& aFont)
   466 void CTFontMetrics::VerifyTypefaceNameAndID(const CFont& aFont)