sl@0: /* sl@0: * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * T_NearestFont.cpp sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent Internal Symbian test code sl@0: */ sl@0: sl@0: #include "T_GetNearestFont.h" sl@0: #include sl@0: sl@0: _LIT( KFontNotAvailable, "NotAvailableOnSystem" ); sl@0: _LIT( KTypefaceName, "DejaVu Sans Condensed" ); sl@0: _LIT( KFontAlias, "Alias"); sl@0: sl@0: class CTGetNearestFont : public CTGraphicsBase sl@0: { sl@0: public: sl@0: CTGetNearestFont(CTestStep* aStep); sl@0: virtual ~CTGetNearestFont(); sl@0: sl@0: protected: sl@0: //from CTGraphicsStep sl@0: virtual void RunTestCaseL(TInt aCurTestCase); sl@0: virtual void ConstructL(); sl@0: private: sl@0: void TestINC064346(); sl@0: void AliasedFontCreationL(); sl@0: void TestFontStoreL(); sl@0: void TestSystemDefaultFont(); sl@0: sl@0: CFbsTypefaceStore* iTfs; sl@0: }; sl@0: sl@0: CTGetNearestFont::CTGetNearestFont(CTestStep* aStep) : sl@0: CTGraphicsBase(aStep) sl@0: { sl@0: sl@0: } sl@0: sl@0: void CTGetNearestFont::ConstructL() sl@0: { sl@0: iTfs = CFbsTypefaceStore::NewL(NULL); sl@0: } sl@0: sl@0: CTGetNearestFont::~CTGetNearestFont() sl@0: { sl@0: delete iTfs; sl@0: } sl@0: sl@0: void CTGetNearestFont::RunTestCaseL( TInt aCurTestCase ) sl@0: { sl@0: ((CTGetNearestFontStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); sl@0: switch ( aCurTestCase ) sl@0: { sl@0: case 1: sl@0: ((CTGetNearestFontStep*)iStep)->SetTestStepID(_L("GRAPHICS-INC064346-0001")); sl@0: INFO_PRINTF1(_L("TestINC064346 Started")); sl@0: TestINC064346(); sl@0: INFO_PRINTF1(_L("TestINC064346 Finished")); sl@0: break; sl@0: sl@0: case 2: sl@0: ((CTGetNearestFontStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0005")); sl@0: INFO_PRINTF1(_L("TestFontStore Started")); sl@0: TestFontStoreL(); sl@0: INFO_PRINTF1(_L("TestFontStore Finished")); sl@0: break; sl@0: sl@0: case 3: sl@0: ((CTGetNearestFontStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0006")); sl@0: INFO_PRINTF1(_L("Test System default font Started")); sl@0: TestSystemDefaultFont(); sl@0: INFO_PRINTF1(_L("Test System default font Finished")); sl@0: break; sl@0: sl@0: case 4: sl@0: ((CTGetNearestFontStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0051")); sl@0: INFO_PRINTF1(_L("AliasedFontCreationL Started")); sl@0: AliasedFontCreationL(); sl@0: INFO_PRINTF1(_L("AliasedFontCreationL Finished")); sl@0: break; sl@0: sl@0: case 5: sl@0: ((CTGetNearestFontStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); sl@0: ((CTGetNearestFontStep*)iStep)->CloseTMSGraphicsStep(); sl@0: TestComplete(); sl@0: break; sl@0: } sl@0: ((CTGetNearestFontStep*)iStep)->RecordTestResultL(); sl@0: } sl@0: sl@0: void CTGetNearestFont::TestINC064346() sl@0: { sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-INC064346-0001 sl@0: @SYMTestType UT sl@0: @SYMTestPriority Medium sl@0: @SYMDEF INC064346 sl@0: @SYMTestCaseDesc Tests that the correct font height is returned when matching with a superscript font. sl@0: @SYMTestActions Get nearest font to design height for a font with the following parameters: sl@0: Font name must be specified that is a font that does not exist on the system. sl@0: Font must be superscript, proportional and serif. sl@0: @SYMTestExpectedResults The correct height must be returned for the nearest font found which is checked with the expected value. sl@0: */ sl@0: TInt ret = KErrGeneral; sl@0: CFont* font = NULL; sl@0: TFontSpec spec(KFontNotAvailable, 15); sl@0: sl@0: spec.iFontStyle = TFontStyle(EPostureUpright, EStrokeWeightNormal, EPrintPosSuperscript); sl@0: spec.iTypeface.SetIsProportional(ETrue); sl@0: spec.iTypeface.SetIsSerif(ETrue); sl@0: ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec); sl@0: TEST(ret == KErrNone); sl@0: INFO_PRINTF2(_L("Font height = %d"), font->HeightInPixels()); sl@0: TEST(10 == font->HeightInPixels()); sl@0: } sl@0: sl@0: void CTGetNearestFont::TestFontStoreL() sl@0: { sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-FNTSTORE-0005 sl@0: @SYMPREQ PREQ1228 sl@0: @SYMREQ REQ5921 sl@0: @SYMTestCaseDesc Tests the font store optimisation changes for reduce the font load time sl@0: @SYMTestPriority High sl@0: @SYMTestStatus Implemented sl@0: @SYMTestActions Get the nearest font to the design height for a font which exists and one which does not exists sl@0: @SYMTestExpectedResults Time taken for fetching an existing font should be less then time take for fetching a non existent font. sl@0: In addition fetching a non existent font should take almost the same time in principle, as taken by fetching sl@0: n existing with old method (as old search method checks all existing fonts even if it finds one in between sl@0: during search procedure). sl@0: */ sl@0: CFont* font = NULL; sl@0: TFontSpec spec(KFontNotAvailable, 15); sl@0: sl@0: spec.iHeight = 15; sl@0: spec.iTypeface.iName = KFontNotAvailable; sl@0: spec.iFontStyle = TFontStyle(EPostureUpright, EStrokeWeightNormal, EPrintPosSuperscript); sl@0: spec.iTypeface.SetIsProportional(ETrue); sl@0: sl@0: //Set the Bold and Italic attribute for the font sl@0: TOpenFontSpec openFontSpec(spec); sl@0: openFontSpec.SetBold(ETrue); sl@0: openFontSpec.SetItalic(ETrue); sl@0: openFontSpec.GetTFontSpec(spec); sl@0: sl@0: TInt64 diffTime[2]; sl@0: sl@0: //Run it twice with same font specifications except different typeface name sl@0: //First iteration for Non Existent font and second iteration for Existent font sl@0: for (TInt cntr = 0; cntr < 2; cntr++) sl@0: { sl@0: TInt freq = 0; sl@0: sl@0: TUint32 starttime = User::FastCounter(); sl@0: TInt ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec); sl@0: TUint32 endtime = User::FastCounter(); sl@0: TEST(ret == KErrNone); sl@0: sl@0: User::LeaveIfError(HAL::Get(HALData::EFastCounterFrequency, freq)); sl@0: TUint32 diff = endtime - starttime; sl@0: diffTime[cntr] = (1000000 * TInt64(diff)) / (TInt64)freq; sl@0: sl@0: TFontSpec returnedSpecs = font->FontSpecInTwips(); sl@0: INFO_PRINTF3(_L("Font Desired : Name = %S Height = %d "), &spec.iTypeface.iName, spec.iHeight); sl@0: INFO_PRINTF4(_L("Font Returned : Name = %S Height = %d Time = %d Microseconds"), &returnedSpecs.iTypeface.iName, font->HeightInPixels(),TUint32(diffTime[cntr])); sl@0: sl@0: //Change the font spec to specify available typeface sl@0: spec.iTypeface.iName = KTypefaceName; sl@0: sl@0: iTfs->ReleaseFont(font); sl@0: } sl@0: sl@0: TEST(diffTime[1] < diffTime[0]); sl@0: INFO_PRINTF2(_L("OPTIMISATION Factor %f"), (TReal(1)-(TReal(diffTime[1])/TReal(diffTime[0])))); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-FNTSTORE-0006 sl@0: @SYMTestPriority Critical sl@0: @SYMREQ REQ6158 sl@0: sl@0: @SYMTestCaseDesc sl@0: Default system font sl@0: sl@0: @SYMTestActions sl@0: 1 - Test without setting system default font sl@0: 2 - Set the system default font to typeface 1 sl@0: 3 - Set the system default font to typeface 2 sl@0: 4 - Set the system default font to an empty descriptor sl@0: 5 - Set the system default font to large descriptor sl@0: 6 - Set the system default font to a font that does not exist sl@0: 7 - Set system font to an alias font sl@0: sl@0: @SYMTestExpectedResults sl@0: The following applies when the typeface name is empty when requesting a font: sl@0: If a default system typeface is not set then the nearest font to the specified font will be returned. sl@0: If a default system typeface name is set then this will be the returned font. sl@0: If the character length of the system typeface is greater than KMaxTypefaceNameLength then a KErrTooBig leave will occur. sl@0: */ sl@0: void CTGetNearestFont::TestSystemDefaultFont() sl@0: { sl@0: const TInt numTypefaces = iTfs->NumTypefaces(); sl@0: TEST(numTypefaces >= 2); // Must have at least 2 typefaces sl@0: sl@0: // Get the first typeface sl@0: TTypefaceSupport tfSupport1; sl@0: iTfs->TypefaceSupport(tfSupport1, 0); sl@0: TPtrC typeface1 = tfSupport1.iTypeface.iName; sl@0: sl@0: // Get the second typeface sl@0: TTypefaceSupport tfSupport2; sl@0: iTfs->TypefaceSupport(tfSupport2, 1); sl@0: TPtrC typeface2 = tfSupport2.iTypeface.iName; sl@0: sl@0: // Test without setting system default font and the returned font should not be typeface1 or typeface2 sl@0: CFont* font = NULL; sl@0: TFontSpec spec(KNullDesC, 15); sl@0: spec.iTypeface.SetIsProportional(ETrue); sl@0: spec.iTypeface.SetIsSerif(ETrue); sl@0: TInt ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec); sl@0: TEST(ret == KErrNone); sl@0: TFontSpec returnedSpecs = font->FontSpecInTwips(); sl@0: TEST(returnedSpecs.iTypeface.iName != typeface1 && returnedSpecs.iTypeface.iName != typeface2); sl@0: iTfs->ReleaseFont(font); sl@0: sl@0: // Now set the system default font and the returned font should be typeface1 sl@0: iTfs->SetSystemDefaultTypefaceNameL(typeface1); sl@0: ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec); sl@0: TEST(ret == KErrNone); sl@0: returnedSpecs = font->FontSpecInTwips(); sl@0: TEST(returnedSpecs.iTypeface.iName == typeface1); sl@0: iTfs->ReleaseFont(font); sl@0: sl@0: // Now set the system default font and the returned font should be typeface2 sl@0: iTfs->SetSystemDefaultTypefaceNameL(typeface2); sl@0: ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec); sl@0: TEST(ret == KErrNone); sl@0: returnedSpecs = font->FontSpecInTwips(); sl@0: TEST(returnedSpecs.iTypeface.iName == typeface2); sl@0: iTfs->ReleaseFont(font); sl@0: sl@0: // Now set the system default font to an empty descriptor and the font returned should not be typeface1 or typeface2 sl@0: iTfs->SetSystemDefaultTypefaceNameL(KNullDesC); sl@0: ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec); sl@0: TEST(ret == KErrNone); sl@0: returnedSpecs = font->FontSpecInTwips(); sl@0: TEST(returnedSpecs.iTypeface.iName != typeface1 && returnedSpecs.iTypeface.iName != typeface2); sl@0: iTfs->ReleaseFont(font); sl@0: sl@0: // Set the system default font to large descriptor and we should get an error sl@0: TRAP(ret, iTfs->SetSystemDefaultTypefaceNameL(_L("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"))); sl@0: TEST(ret == KErrTooBig); sl@0: sl@0: // Now set the system default font to a font that does not exist and the font returned should not be typeface 1 or typeface2 sl@0: _LIT( KFontNotExisting, "FontDoesNotExist" ); sl@0: iTfs->SetSystemDefaultTypefaceNameL(KFontNotExisting); sl@0: ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec); sl@0: TEST(ret == KErrNone); sl@0: returnedSpecs = font->FontSpecInTwips(); sl@0: TEST(returnedSpecs.iTypeface.iName != typeface1 && returnedSpecs.iTypeface.iName != typeface2); sl@0: iTfs->ReleaseFont(font); sl@0: sl@0: // Now set the system default font and set an alias on typeface1 - the returned font should still be typeface1 sl@0: iTfs->SetSystemDefaultTypefaceNameL(typeface1); sl@0: iTfs->SetFontNameAliasL(typeface1, typeface2); sl@0: ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec); sl@0: TEST(ret == KErrNone); sl@0: returnedSpecs = font->FontSpecInTwips(); sl@0: TEST(returnedSpecs.iTypeface.iName == typeface1); sl@0: iTfs->ReleaseFont(font); sl@0: sl@0: // Now set the system default font to an aliased font - the returned font should still be typeface1 sl@0: iTfs->SetSystemDefaultTypefaceNameL(KFontAlias); sl@0: iTfs->SetFontNameAliasL(KFontAlias, typeface1); sl@0: ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec); sl@0: TEST(ret == KErrNone); sl@0: returnedSpecs = font->FontSpecInTwips(); sl@0: TEST(returnedSpecs.iTypeface.iName == typeface1); sl@0: iTfs->ReleaseFont(font); sl@0: sl@0: // tear down the default font sl@0: iTfs->SetSystemDefaultTypefaceNameL(KNullDesC); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-FNTSTORE-0051 sl@0: @SYMTestType UT sl@0: @SYMTestPriority Medium sl@0: @SYMDEF INC127988 sl@0: @SYMTestCaseDesc Tests that an alias does not prevent a real font from being loaded. sl@0: @SYMTestActions Create an alias using the name of a real font. Get the real font. sl@0: @SYMTestExpectedResults Ensure the real font, not the aliased font is returned. sl@0: */ sl@0: void CTGetNearestFont::AliasedFontCreationL() sl@0: { sl@0: TInt numTypefaces = iTfs->NumTypefaces(); sl@0: if(numTypefaces <2) sl@0: return; sl@0: sl@0: TTypefaceSupport tfSupport1; sl@0: sl@0: iTfs->TypefaceSupport(tfSupport1, 0); sl@0: INFO_PRINTF1(tfSupport1.iTypeface.iName); sl@0: // Get the first different typeface sl@0: TTypefaceSupport tfSupport2; sl@0: while (--numTypefaces) sl@0: { sl@0: iTfs->TypefaceSupport(tfSupport2, numTypefaces); sl@0: INFO_PRINTF1(tfSupport2.iTypeface.iName); sl@0: if (tfSupport2.iTypeface.iName != tfSupport1.iTypeface.iName) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: sl@0: // Make sure we aren't at the end of the list sl@0: TEST(numTypefaces); sl@0: // Alias the other font with the same name as the original sl@0: iTfs->SetFontNameAliasL(tfSupport1.iTypeface.iName, tfSupport2.iTypeface.iName); sl@0: sl@0: // Request the original font (making sure we don't get the aliased font back) sl@0: CFont* font = NULL; sl@0: TFontSpec spec(tfSupport1.iTypeface.iName, 0); sl@0: TInt ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec); sl@0: TEST(ret == KErrNone); sl@0: TFontSpec returnedSpecs = font->FontSpecInTwips(); sl@0: INFO_PRINTF1(returnedSpecs.iTypeface.iName); sl@0: TEST(returnedSpecs.iTypeface.iName == tfSupport1.iTypeface.iName); sl@0: iTfs->ReleaseFont(font); sl@0: } sl@0: sl@0: //-------------- sl@0: __CONSTRUCT_STEP__(GetNearestFont)