graphicsdeviceinterface/bitgdi/tbit/TFontSelect.CPP
changeset 0 5d03bc08d59c
child 136 62bb7c97884c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code 
       
    20 */
       
    21 
       
    22 #include <e32hal.h>
       
    23 #include <e32std.h>
       
    24 #include <e32test.h>
       
    25 #include <bitstd.h>
       
    26 #include <bitdev.h>
       
    27 #include <fntstore.h>
       
    28 #include <fbs.h>
       
    29 #include <hal.h>
       
    30 #include <graphics/fbsdefs.h>
       
    31 
       
    32 #include "tfontselect.h"
       
    33 
       
    34 
       
    35 //If you want to do font tests with scaled device - change KScalingFactorX, KScalingFactorY, KScalingOriginPt.
       
    36 const TInt KScalingFactorX = 1;
       
    37 const TInt KScalingFactorY = 1;
       
    38 const TPoint KScalingOriginPt(0, 0);
       
    39 
       
    40 //Non valid font --> This font comes from System Test test data. Not a proper font, so it's best to skip it.
       
    41 _LIT(KWrongFontFileName, "fnt");
       
    42 
       
    43 
       
    44 CTFontSelect::CTFontSelect(CTestStep* aStep) :
       
    45 	CTGraphicsBase(aStep),
       
    46 	iFont1(NULL),
       
    47 	iFont2(NULL),
       
    48 	iFont3(NULL),
       
    49 	iGc(NULL),
       
    50 	iDevice(NULL)	
       
    51 	{
       
    52 	}
       
    53 
       
    54 CTFontSelect::~CTFontSelect()
       
    55 	{
       
    56 	delete iGc;
       
    57 	delete iDevice;
       
    58 	}
       
    59 
       
    60 void CTFontSelect::ConstructL()
       
    61 	{
       
    62 	TRAPD(err,iDevice = CFbsScreenDevice::NewL(KNullDesC,EColor256));
       
    63 	if (err == KErrNotSupported)
       
    64 		TRAP(err,iDevice = CFbsScreenDevice::NewL(KNullDesC,EColor16MU));
       
    65 	if (err == KErrNotSupported)
       
    66 		TRAP(err,iDevice = CFbsScreenDevice::NewL(KNullDesC,EColor4K));
       
    67 	if (err == KErrNotSupported)
       
    68 		TRAP(err,iDevice = CFbsScreenDevice::NewL(KNullDesC,EColor16M));
       
    69 	if (err == KErrNotSupported)
       
    70 		TRAP(err,iDevice = CFbsScreenDevice::NewL(KNullDesC,EColor64K));
       
    71 	if (err == KErrNotSupported)
       
    72 		TRAP(err,iDevice = CFbsScreenDevice::NewL(KNullDesC,EGray256));
       
    73 	if (err == KErrNotSupported)
       
    74 		TRAP(err,iDevice = CFbsScreenDevice::NewL(KNullDesC,EGray16));
       
    75 	if (err == KErrNotSupported)
       
    76 		TRAP(err,iDevice = CFbsScreenDevice::NewL(KNullDesC,EGray4));
       
    77 	if (err == KErrNotSupported)
       
    78 		TRAP(err,iDevice = CFbsScreenDevice::NewL(KNullDesC,EGray2));
       
    79 	if (err == KErrNotSupported)
       
    80 		TRAP(err,iDevice = CFbsScreenDevice::NewL(KNullDesC,EColor16));
       
    81 	if (err == KErrNotSupported)
       
    82 		TRAP(err,iDevice = CFbsScreenDevice::NewL(KNullDesC,EColor16MA));
       
    83 	if (err == KErrNotSupported)
       
    84 		TRAP(err,iDevice = CFbsScreenDevice::NewL(KNullDesC,EColor16MAP));
       
    85 	if (err!=KErrNone)
       
    86 		{
       
    87 		_LIT(KLog,"Failed to create screen device, last returned error %d");
       
    88 		INFO_PRINTF2(KLog,err);
       
    89 		}
       
    90 
       
    91 	User::LeaveIfError(err);
       
    92 	iDevice->ChangeScreenDevice(NULL);
       
    93 	iDevice->SetAutoUpdate(ETrue);
       
    94 	iDevice->CreateContext(iGc);
       
    95 	iDevice->SetScalingFactor(KScalingOriginPt, KScalingFactorX, KScalingFactorY, 1, 1);
       
    96 	iGc->Activate(iDevice);
       
    97 
       
    98 	}
       
    99 
       
   100 /**
       
   101   @SYMTestCaseID GRAPHICS-BITGDI-0083
       
   102  
       
   103   @SYMDEF             
       
   104 
       
   105   @SYMTestCaseDesc Tests font selection
       
   106    
       
   107   @SYMTestPriority High
       
   108 
       
   109   @SYMTestStatus Implemented
       
   110 
       
   111   @SYMTestActions For different typeface and heights tests font selection to specific sizes
       
   112  
       
   113   @SYMTestExpectedResults Test should perform graphics operations succesfully. 
       
   114 */
       
   115 void CTFontSelect::DoFontSelectTestsL()
       
   116 	{
       
   117 	TFontSpec fs;
       
   118 	TInt typefaces = iDevice->NumTypefaces();
       
   119 	TTypefaceSupport info;
       
   120 	_LIT(KIgnoreFont1, "Test2");
       
   121 	_LIT(KIgnoreFont2, "LinkedFont3TT"); //LinkedFont3/4TT both cause test failure on Freetype
       
   122 	_LIT(KIgnoreFont3, "LinkedFont4TT"); //They are test files with incorrect metrics
       
   123 
       
   124 	for (TInt count = 0; count < typefaces; count++)
       
   125 		{
       
   126 		iDevice->TypefaceSupport( info, count );
       
   127 
       
   128 		for (TInt index = 0; index < info.iNumHeights; index++)
       
   129 			{
       
   130 			TInt height = iDevice->FontHeightInPixels( count, index );
       
   131 			fs.iTypeface = info.iTypeface;
       
   132 			fs.iHeight = height;
       
   133 
       
   134 			INFO_PRINTF1(_L("Test GetNearestFontInPixels"));
       
   135 			User::LeaveIfError( iDevice->GetNearestFontInPixels( (CFont*&)iFont1 ,fs ) );
       
   136 			TEST(iFont1->HeightInPixels() == height);
       
   137 
       
   138 			INFO_PRINTF1(_L("Test GetNearestFontToDesignHeightInPixels"));
       
   139 			User::LeaveIfError( iDevice->GetNearestFontToDesignHeightInPixels( (CFont*&)iFont2, fs ) );
       
   140 			TEST(iFont2->HeightInPixels() == height);
       
   141 			iDevice->ReleaseFont( iFont2 );
       
   142 			iDevice->ReleaseFont(iFont1);
       
   143 			}
       
   144 			
       
   145 		INFO_PRINTF1(_L("Test GetNearestFontToMaxHeightInPixels"));
       
   146 		for (TInt maxHeight = 20; maxHeight <= 50; maxHeight += 10)
       
   147 			{
       
   148 			fs.iTypeface = info.iTypeface;
       
   149 			fs.iHeight = maxHeight;
       
   150 			User::LeaveIfError( iDevice->GetNearestFontToMaxHeightInPixels( (CFont*&)iFont3, fs, maxHeight ) );
       
   151 
       
   152 			TBufC<64> fontName = ((CFont*&)iFont3)->FontSpecInTwips().iTypeface.iName;
       
   153 			INFO_PRINTF2(_L("Font name: '%S'."), &fontName);
       
   154 			if (fontName == KWrongFontFileName)
       
   155 				{
       
   156 				INFO_PRINTF2(_L(" ** '%S' is a wrong font file. Skip checks for this font **"), &fontName);
       
   157 				break;
       
   158 				}
       
   159 
       
   160 			if (!fontName.Compare(KIgnoreFont1))
       
   161 				{
       
   162 				INFO_PRINTF1(_L(" ** 'Test2' font ignored. This files metrics are incorrect."));
       
   163 				continue;
       
   164 				}
       
   165 			if (!fontName.Compare(KIgnoreFont2))
       
   166 				{
       
   167 				INFO_PRINTF1(_L(" ** 'LinkedFont3TT' font ignored. This files metrics are incorrect."));
       
   168 				continue;
       
   169 				}
       
   170 			if (!fontName.Compare(KIgnoreFont3))
       
   171 				{
       
   172 				INFO_PRINTF1(_L(" ** 'LinkedFont4TT' font ignored. This files metrics are incorrect."));
       
   173 				continue;
       
   174 				}
       
   175 			
       
   176 			if (info.iIsScalable)
       
   177 				{ // got a scalable (TrueType) font - can't guarantee will fit for bitmap font
       
   178 				// N.B. If this ever fails then try replacing maxHeight with maxHeight + 1 in the test
       
   179 				// as it could be down to the hinting rounding error that can very occasionally occur
       
   180 				// We can't make this test reliably with bitmap fonts
       
   181 				INFO_PRINTF1(_L("Font is scalable"));
       
   182 				TEST(iFont3->FontMaxHeight() <= maxHeight);
       
   183 				}
       
   184 
       
   185 			INFO_PRINTF1(_L("Test font level metrics"));
       
   186 			INFO_PRINTF3(_L("Requested max height %d, returned max height %d"), maxHeight, iFont3->FontMaxHeight());
       
   187 			INFO_PRINTF4(_L("MaxAscent %d, MaxDescent %d, HeightInPixels %d"), iFont3->FontMaxAscent(), iFont3->FontMaxDescent(), iFont3->HeightInPixels());
       
   188 			INFO_PRINTF3(_L("CapAscent %d, StdDescent %d"), iFont3->FontCapitalAscent(), iFont3->FontStandardDescent());
       
   189 			TEST(iFont3->FontMaxHeight() >= ( iFont3->FontMaxAscent() + iFont3->FontMaxDescent() ));
       
   190 			TEST(iFont3->FontMaxAscent() >= iFont3->FontCapitalAscent());
       
   191 			TInt expMaxDescent=iFont3->FontStandardDescent();
       
   192 			if (iDevice->SizeInPixels().iHeight>400)
       
   193 				--expMaxDescent;		//To get test to pass on X86 and NaviEngine
       
   194 			TEST(iFont3->FontMaxDescent() >= expMaxDescent);
       
   195 
       
   196 			iDevice->ReleaseFont(iFont3);
       
   197 			}
       
   198 		}
       
   199 	}
       
   200 
       
   201 void CTFontSelect::RunTestCaseL(TInt aCurTestCase)
       
   202 	{
       
   203 	((CTFontSelectStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
       
   204 	switch(aCurTestCase)
       
   205 		{
       
   206 		case 1:
       
   207 			{
       
   208 			((CTFontSelectStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0083"));
       
   209 			INFO_PRINTF1(_L("DoFontSelectTest"));
       
   210 			TRAPD(ret, DoFontSelectTestsL());
       
   211 			TEST(ret == KErrNone);
       
   212 			break;
       
   213 			}
       
   214 		case 2:
       
   215 			{
       
   216 			((CTFontSelectStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
       
   217 			((CTFontSelectStep*)iStep)->CloseTMSGraphicsStep();
       
   218 			TestComplete();		
       
   219 			break;
       
   220 			}
       
   221 		}
       
   222 	((CTFontSelectStep*)iStep)->RecordTestResultL();
       
   223 	}
       
   224 
       
   225 
       
   226 //--------------
       
   227 __CONSTRUCT_STEP__(FontSelect)
       
   228 
       
   229 void CTFontSelectStep::TestSetupL()
       
   230 	{
       
   231 	FbsStartup();
       
   232 	User::LeaveIfError(RFbsSession::Connect());
       
   233 	}
       
   234 	
       
   235 void CTFontSelectStep::TestClose()
       
   236 	{
       
   237 	RFbsSession::Disconnect();
       
   238 	}