graphicsdeviceinterface/bitgdi/tbit/TFontSelect.CPP
changeset 136 62bb7c97884c
parent 0 5d03bc08d59c
child 164 25ffed67c7ef
equal deleted inserted replaced
121:d72fc2aace31 136:62bb7c97884c
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
   119 	TTypefaceSupport info;
   119 	TTypefaceSupport info;
   120 	_LIT(KIgnoreFont1, "Test2");
   120 	_LIT(KIgnoreFont1, "Test2");
   121 	_LIT(KIgnoreFont2, "LinkedFont3TT"); //LinkedFont3/4TT both cause test failure on Freetype
   121 	_LIT(KIgnoreFont2, "LinkedFont3TT"); //LinkedFont3/4TT both cause test failure on Freetype
   122 	_LIT(KIgnoreFont3, "LinkedFont4TT"); //They are test files with incorrect metrics
   122 	_LIT(KIgnoreFont3, "LinkedFont4TT"); //They are test files with incorrect metrics
   123 
   123 
       
   124 	// Maximum height of font allowed by iType rasteriser
       
   125 	const TInt KMaxITypeHeightInPixels = 256;
       
   126 	_LIT(KErrorMessageWithFontName, "Font: %S, pixel height requested: %d, pixel height of font: %d");
       
   127 	_LIT(KErrorMessage, "Pixel height requested: %d, pixel height of font: %d");
       
   128 
   124 	for (TInt count = 0; count < typefaces; count++)
   129 	for (TInt count = 0; count < typefaces; count++)
   125 		{
   130 		{
   126 		iDevice->TypefaceSupport( info, count );
   131 		iDevice->TypefaceSupport( info, count );
   127 
   132 
   128 		for (TInt index = 0; index < info.iNumHeights; index++)
   133 		for (TInt index = 0; index < info.iNumHeights; index++)
   129 			{
   134 			{
   130 			TInt height = iDevice->FontHeightInPixels( count, index );
   135 			TInt height = iDevice->FontHeightInPixels( count, index );
       
   136 			if (height > KMaxITypeHeightInPixels)
       
   137 				{
       
   138 				continue;
       
   139 				}
   131 			fs.iTypeface = info.iTypeface;
   140 			fs.iTypeface = info.iTypeface;
   132 			fs.iHeight = height;
   141 			fs.iHeight = height;
   133 
   142 
   134 			INFO_PRINTF1(_L("Test GetNearestFontInPixels"));
   143 			INFO_PRINTF1(_L("Test GetNearestFontInPixels"));
   135 			User::LeaveIfError( iDevice->GetNearestFontInPixels( (CFont*&)iFont1 ,fs ) );
   144 			User::LeaveIfError( iDevice->GetNearestFontInPixels( (CFont*&)iFont1 ,fs ) );
   136 			TEST(iFont1->HeightInPixels() == height);
   145 			TInt heightInPixels = iFont1->HeightInPixels();
       
   146 			if ( heightInPixels == height )
       
   147 				{
       
   148 				TEST( ETrue );
       
   149 				}
       
   150 			else
       
   151 				{
       
   152 				TOpenFontFaceAttrib attrib;
       
   153 				if( iFont1->GetFaceAttrib( attrib ) )
       
   154 					{
       
   155 					INFO_PRINTF4(KErrorMessageWithFontName, &attrib.FullName(), height, heightInPixels);
       
   156 					}
       
   157 				else
       
   158 					{
       
   159 					INFO_PRINTF3(KErrorMessage, height, heightInPixels);
       
   160 					}
       
   161 				TEST( EFalse );
       
   162 				}
   137 
   163 
   138 			INFO_PRINTF1(_L("Test GetNearestFontToDesignHeightInPixels"));
   164 			INFO_PRINTF1(_L("Test GetNearestFontToDesignHeightInPixels"));
   139 			User::LeaveIfError( iDevice->GetNearestFontToDesignHeightInPixels( (CFont*&)iFont2, fs ) );
   165 			User::LeaveIfError( iDevice->GetNearestFontToDesignHeightInPixels( (CFont*&)iFont2, fs ) );
   140 			TEST(iFont2->HeightInPixels() == height);
   166 			heightInPixels = iFont2->HeightInPixels();
       
   167 			if ( heightInPixels == height )
       
   168 				{
       
   169 				TEST( ETrue );
       
   170 				}
       
   171 			else
       
   172 				{
       
   173 				TOpenFontFaceAttrib attrib;
       
   174 				if( iFont2->GetFaceAttrib( attrib ) )
       
   175 					{
       
   176 					INFO_PRINTF4(KErrorMessageWithFontName, &attrib.FullName(), height, heightInPixels);
       
   177 					}
       
   178 				else
       
   179 					{
       
   180 					INFO_PRINTF3(KErrorMessage, height, heightInPixels);
       
   181 					}
       
   182 				TEST( EFalse );
       
   183 				}
   141 			iDevice->ReleaseFont( iFont2 );
   184 			iDevice->ReleaseFont( iFont2 );
   142 			iDevice->ReleaseFont(iFont1);
   185 			iDevice->ReleaseFont( iFont1 );
   143 			}
   186 			}
   144 			
   187 			
   145 		INFO_PRINTF1(_L("Test GetNearestFontToMaxHeightInPixels"));
   188 		INFO_PRINTF1(_L("Test GetNearestFontToMaxHeightInPixels"));
   146 		for (TInt maxHeight = 20; maxHeight <= 50; maxHeight += 10)
   189 		for (TInt maxHeight = 20; maxHeight <= 50; maxHeight += 10)
   147 			{
   190 			{
   177 				{ // got a scalable (TrueType) font - can't guarantee will fit for bitmap font
   220 				{ // 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
   221 				// 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
   222 				// 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
   223 				// We can't make this test reliably with bitmap fonts
   181 				INFO_PRINTF1(_L("Font is scalable"));
   224 				INFO_PRINTF1(_L("Font is scalable"));
   182 				TEST(iFont3->FontMaxHeight() <= maxHeight);
   225 				TEST(iFont3->FontMaxHeight() <= maxHeight+1);
   183 				}
   226 				}
   184 
   227 
   185 			INFO_PRINTF1(_L("Test font level metrics"));
   228 			INFO_PRINTF1(_L("Test font level metrics"));
   186 			INFO_PRINTF3(_L("Requested max height %d, returned max height %d"), maxHeight, iFont3->FontMaxHeight());
   229 			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());
   230 			INFO_PRINTF4(_L("MaxAscent %d, MaxDescent %d, HeightInPixels %d"), iFont3->FontMaxAscent(), iFont3->FontMaxDescent(), iFont3->HeightInPixels());