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: * 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_IsolatedFontStore.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "T_FNT.H" sl@0: sl@0: #ifdef __WINS__ sl@0: _LIT(KEonFontFileName,"z:\\resource\\fonts\\eon14.gdr"); sl@0: #else sl@0: _LIT(KEonFontFileName,"z:\\resource\\fonts\\eon.gdr"); sl@0: #endif sl@0: sl@0: // Set KVerboseOutput to "ETrue" if extra INFO_PRINTFx for debug purposes are required sl@0: const TBool KVerboseOutput = EFalse; sl@0: sl@0: _LIT(K7650FontFileName,"z:\\resource\\fonts\\ceurope.gdr"); sl@0: sl@0: sl@0: sl@0: CTFnt::CTFnt(CTestStep* aStep): sl@0: CTGraphicsBase(aStep) sl@0: { sl@0: INFO_PRINTF1(_L("FontStore T_FNT test\n")); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-FNTSTORE-0023 sl@0: sl@0: @SYMTestCaseDesc sl@0: Tests adding a font file to the font store and checks sl@0: the properties of the font. sl@0: sl@0: @SYMTestActions sl@0: Creates a user heap. Creates a CFontStore object and sl@0: uses the user heap for memory allocation. Adds a sl@0: font file to the font store. Checks if added correctly. sl@0: Gets the typeface information for the font. Retrieves the sl@0: nearest available font. Sets the font style to superscript sl@0: and subscript and tests getting nearest font. Then for all sl@0: available typefaces it gets the nearest fonts and checks the sl@0: result. The user heap is closed and the heap is checked for memory leaks. sl@0: sl@0: @SYMTestExpectedResults sl@0: Test should pass sl@0: */ sl@0: void CTFnt::TestReadFileL(const TDesC& aFontFile) sl@0: { sl@0: sl@0: INFO_PRINTF2(_L("Starting TestReadFile with parameter %S"), &aFontFile); sl@0: sl@0: __UHEAP_MARK; sl@0: RHeap* heap=UserHeap::ChunkHeap(NULL,0x10000,0x10000); sl@0: sl@0: // Add file sl@0: sl@0: TUid id1 = TUid::Uid(0); sl@0: CFontStore *fs=CFontStore::NewL(heap); sl@0: sl@0: TRAPD(ret,id1=fs->AddFileL(aFontFile)); sl@0: TEST(ret==KErrNone); sl@0: INFO_PRINTF2(_L("NumTypefaces %d"),fs->NumTypefaces()); sl@0: sl@0: // Get typeface info sl@0: sl@0: INFO_PRINTF1(_L("Get typeface support")); sl@0: TTypefaceSupport support; sl@0: fs->TypefaceSupport(support,0); sl@0: TBuf name; sl@0: name.Copy(support.iTypeface.iName); sl@0: INFO_PRINTF2(_L("Typeface Name %S"),&name); sl@0: INFO_PRINTF2(_L("Typeface Isproportional %d"),support.iTypeface.IsProportional()); sl@0: INFO_PRINTF2(_L("Typeface IsSerif %d"),support.iTypeface.IsSerif()); sl@0: INFO_PRINTF2(_L("Typeface IsSymbol %d"),support.iTypeface.IsSymbol()); sl@0: INFO_PRINTF2(_L("NumHeights %d"),support.iNumHeights); sl@0: INFO_PRINTF2(_L("MinHeightInTwips %d"),support.iMinHeightInTwips); sl@0: INFO_PRINTF2(_L("MaxHeightInTwips %d"),support.iMaxHeightInTwips); sl@0: INFO_PRINTF2(_L("IsScalable %d"),support.iIsScalable); sl@0: sl@0: if (KVerboseOutput) sl@0: { sl@0: for (TInt i=0; iFontHeightInPixels(0/*fs->NumTypefaces()-2*/,i)); sl@0: } sl@0: } sl@0: sl@0: // Get nearest font sl@0: sl@0: INFO_PRINTF1(_L("Get nearest font")); sl@0: CBitmapFont *font; sl@0: TCharacterMetrics metrics; sl@0: const TUint8* bytes; sl@0: TFontSpec spec; sl@0: support.iTypeface=support.iTypeface; sl@0: spec.iTypeface.SetIsProportional(EFalse); sl@0: spec.iTypeface.SetIsSerif(ETrue); sl@0: spec.iTypeface.SetIsSymbol(EFalse); sl@0: spec.iHeight=10; sl@0: spec.iFontStyle.SetPosture(EPostureUpright); sl@0: for (spec.iHeight=support.iMinHeightInTwips; spec.iHeight<=support.iMaxHeightInTwips; spec.iHeight++) sl@0: { sl@0: ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec); sl@0: TEST(ret==KErrNone); sl@0: if (KVerboseOutput) sl@0: { sl@0: INFO_PRINTF2(_L("FontSpec Height %d"),spec.iHeight); sl@0: INFO_PRINTF2(_L("HeightInTwips %d"),font->FontSpecInTwips().iHeight); sl@0: INFO_PRINTF2(_L("HeightInPixels %d"),font->HeightInPixels()); sl@0: INFO_PRINTF2(_L("AscentInPixels %d"),font->AscentInPixels()); sl@0: INFO_PRINTF3(_L("Font Posture %d StrokeWeight %d"),font->FontSpecInTwips().iFontStyle.Posture(),font->FontSpecInTwips().iFontStyle.StrokeWeight()); sl@0: INFO_PRINTF3(_L("Font AlgPosture %d AlgStrokeWeight %d"),((CBitmapFont*)font)->iAlgStyle.IsItalic(),((CBitmapFont*)font)->iAlgStyle.IsBold()); sl@0: } sl@0: fs->ReleaseFont(font); sl@0: } sl@0: sl@0: ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec); sl@0: TEST(ret==KErrNone); sl@0: INFO_PRINTF1(_L("Got nearest font")); sl@0: metrics = font->CharacterMetrics(32,bytes); sl@0: INFO_PRINTF5(_L("First 4 bytes %d %d %d %d"),*(bytes),*(bytes+1),*(bytes+2),*(bytes+3)); sl@0: INFO_PRINTF5(_L("Second 4 bytes %d %d %d %d"),*(bytes+4),*(bytes+5),*(bytes+6),*(bytes+7)); sl@0: sl@0: INFO_PRINTF2(_L("LeftAdjustInPixels %d"),metrics.iLeftAdjustInPixels); sl@0: INFO_PRINTF2(_L("MoveInPixels %d"),metrics.iMoveInPixels); sl@0: INFO_PRINTF2(_L("RightAdjustInPixels %d"),metrics.iRightAdjustInPixels); sl@0: INFO_PRINTF2(_L("TextWidthInPixels(EPOC) %d"),font->TextWidthInPixels(_L("EPOC"))); sl@0: INFO_PRINTF2(_L("TextWidthInPixels(\x00BB) %d"),font->TextWidthInPixels(_L("\x00BB"))); //Double Greater Than » sl@0: CFont::TMeasureTextInput param; sl@0: param.iStartInputChar = 34; sl@0: INFO_PRINTF2(_L("TextWidthInPixels with supplied context(EPOC) %d"),font->TextWidthInPixels(_L("->This text will not be measured<-EPOC"),¶m)); sl@0: INFO_PRINTF2(_L("TextWidthInPixels with supplied context(\x00BB) %d"),font->TextWidthInPixels(_L("->This text will not be measured<-\x00BB"),¶m)); sl@0: INFO_PRINTF2(_L("TextCount(EPOC,50) %d"),font->TextCount(_L("EPOC"),50)); sl@0: sl@0: INFO_PRINTF2(_L("WidthZeroInPixels %d"),font->WidthZeroInPixels()); sl@0: INFO_PRINTF2(_L("MaxCharWidthInPixels %d"),font->MaxCharWidthInPixels()); sl@0: INFO_PRINTF2(_L("MaxNormalCharWidthInPixels %d"),font->MaxNormalCharWidthInPixels()); sl@0: INFO_PRINTF2(_L("HeightInTwips %d"),font->FontSpecInTwips().iHeight); sl@0: name.Copy(font->FontSpecInTwips().iTypeface.iName); sl@0: INFO_PRINTF2(_L("Typeface Name %S"),&name); sl@0: sl@0: fs->ReleaseFont(font); sl@0: sl@0: // Get nearest font sl@0: sl@0: INFO_PRINTF1(_L("Get nearest monoized font")); sl@0: support.iTypeface.iName=_L("");//Mono Swiss"); sl@0: support.iTypeface.SetIsProportional(ETrue);//=support.iTypeface; sl@0: support.iTypeface.SetIsSerif(ETrue);//=support.iTypeface; sl@0: spec.iTypeface=support.iTypeface; sl@0: spec.iHeight=18; sl@0: spec.iFontStyle.SetPosture(EPostureUpright); sl@0: spec.iFontStyle.SetPrintPosition(EPrintPosNormal); sl@0: ret=fs->GetNearestFontToDesignHeightInPixels((CFont *&) font,spec); sl@0: TEST(ret==KErrNone); sl@0: INFO_PRINTF2(_L("HeightInPixels %d"),font->HeightInPixels()); sl@0: INFO_PRINTF2(_L("AscentInPixels %d"),font->AscentInPixels()); sl@0: metrics = font->CharacterMetrics(32,bytes); sl@0: INFO_PRINTF5(_L("First 4 bytes %d %d %d %d"),*(bytes),*(bytes+1),*(bytes+2),*(bytes+3)); sl@0: INFO_PRINTF5(_L("Second 4 bytes %d %d %d %d"),*(bytes+4),*(bytes+5),*(bytes+6),*(bytes+7)); sl@0: INFO_PRINTF2(_L("LeftAdjustInPixels %d"),metrics.iLeftAdjustInPixels); sl@0: INFO_PRINTF2(_L("MoveInPixels %d"),metrics.iMoveInPixels); sl@0: INFO_PRINTF2(_L("RightAdjustInPixels %d"),metrics.iRightAdjustInPixels); sl@0: INFO_PRINTF2(_L("TextWidthInPixels(EPOC) %d"),font->TextWidthInPixels(_L("EPOC"))); sl@0: INFO_PRINTF2(_L("WidthZeroInPixels %d"),font->WidthZeroInPixels()); sl@0: INFO_PRINTF2(_L("TextCount(EPOC,50) %d"),font->TextCount(_L("EPOC"),50)); sl@0: INFO_PRINTF2(_L("MaxCharWidthInPixels %d"),font->MaxCharWidthInPixels()); sl@0: INFO_PRINTF2(_L("MaxNormalCharWidthInPixels %d"),font->MaxNormalCharWidthInPixels()); sl@0: INFO_PRINTF2(_L("HeightInTwips %d"),font->FontSpecInTwips().iHeight); sl@0: name.Copy(font->FontSpecInTwips().iTypeface.iName); sl@0: INFO_PRINTF2(_L("Typeface Name %S"),&name); sl@0: sl@0: fs->ReleaseFont(font); sl@0: sl@0: // Get superscript font sl@0: sl@0: INFO_PRINTF1(_L("Get superscript font")); sl@0: spec.iFontStyle.SetPrintPosition(EPrintPosSuperscript); sl@0: ret=fs->GetNearestFontToDesignHeightInPixels((CFont *&) font,spec); sl@0: TEST(ret==KErrNone); sl@0: INFO_PRINTF2(_L("HeightInPixels %d"),font->HeightInPixels()); sl@0: INFO_PRINTF2(_L("BaselineOffsetInPixels %d"),font->iAlgStyle.iBaselineOffsetInPixels); sl@0: INFO_PRINTF2(_L("HeightInTwips %d"),font->FontSpecInTwips().iHeight); sl@0: name.Copy(font->FontSpecInTwips().iTypeface.iName); sl@0: INFO_PRINTF2(_L("Typeface Name %S"),&name); sl@0: sl@0: fs->ReleaseFont(font); sl@0: sl@0: // Get subscript font sl@0: sl@0: INFO_PRINTF1(_L("Get subscript font")); sl@0: spec.iFontStyle.SetPrintPosition(EPrintPosSubscript); sl@0: ret=fs->GetNearestFontToDesignHeightInPixels((CFont *&) font,spec); sl@0: TEST(ret==KErrNone); sl@0: INFO_PRINTF2(_L("HeightInPixels %d"),font->HeightInPixels()); sl@0: INFO_PRINTF2(_L("BaselineOffsetInPixels %d"),font->iAlgStyle.iBaselineOffsetInPixels); sl@0: INFO_PRINTF2(_L("HeightInTwips %d"),font->FontSpecInTwips().iHeight); sl@0: name.Copy(font->FontSpecInTwips().iTypeface.iName); sl@0: INFO_PRINTF2(_L("Typeface Name %S"),&name); sl@0: sl@0: fs->ReleaseFont(font); sl@0: sl@0: // aTest all fonts sl@0: sl@0: INFO_PRINTF1(_L("Get typeface support")); sl@0: spec.iFontStyle.SetPrintPosition(EPrintPosNormal); sl@0: spec.iFontStyle.SetPosture(EPostureUpright); sl@0: spec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal); sl@0: for (TInt i=0; iNumTypefaces(); i++) sl@0: { sl@0: fs->TypefaceSupport(support,i); sl@0: name.Copy(support.iTypeface.iName); sl@0: INFO_PRINTF2(_L("Typeface Name %S"),&name); sl@0: for (TInt j=0; jFontHeightInPixels(i,j); sl@0: ret=fs->GetNearestFontToDesignHeightInPixels((CFont *&) font,spec); sl@0: TEST(ret==KErrNone); sl@0: INFO_PRINTF2(_L("Spec HeightInPixels %d"),spec.iHeight); sl@0: INFO_PRINTF2(_L("Font HeightInPixels %d"),font->HeightInPixels()); sl@0: INFO_PRINTF3(_L("Font Posture %d StrokeWeight %d"),font->FontSpecInTwips().iFontStyle.Posture(),font->FontSpecInTwips().iFontStyle.StrokeWeight()); sl@0: INFO_PRINTF3(_L("Font AlgPosture %d AlgStrokeWeight %d"),font->iAlgStyle.IsItalic(),font->iAlgStyle.IsBold()); sl@0: fs->ReleaseFont(font); sl@0: } sl@0: } sl@0: sl@0: // Close fontstore sl@0: INFO_PRINTF1(_L("Destroy filestore\n\n")); sl@0: delete fs; sl@0: sl@0: heap->Close(); sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-FNTSTORE-0052 sl@0: sl@0: @SYMPREQ sl@0: PREQ2147 sl@0: sl@0: @SYMREQ sl@0: REQ12172 sl@0: sl@0: @SYMTestCaseDesc sl@0: Creates an instance of fontstore to test that invalid font files generated by the test script sl@0: have not eclipsed the valid files already loaded. sl@0: sl@0: @SYMTestPriority sl@0: Critical sl@0: sl@0: @SYMTestStatus sl@0: Implemented sl@0: sl@0: @SYMTestActions sl@0: The start of this test script will create an invalid font file in c:\resource\fonts. This test sl@0: creates an instance of font store and performs the font loading to check the invalid file is not sl@0: loaded and font store has fallen back to the correct file. sl@0: sl@0: The test also ensures that the invalid file has been created sucessfully by T_WriteInvalidFontFile.exe sl@0: sl@0: After this set off test have been run the file is removed by T_RemoveInvalidFontFile.exe sl@0: sl@0: @SYMTestExpectedResults sl@0: The Invalid Font file will exist; font store will not load this file and instead will load the file that it sl@0: eclipses (from ROM) sl@0: sl@0: */ sl@0: void CTFnt::TestEclipseFallbackWithInvalidFontL() sl@0: { sl@0: //The path of the invalid file that should not be loaded sl@0: _LIT(KInvalidFontFilePath, "c:\\resource\\fonts\\DejaVuSansCondensed.ttf"); sl@0: sl@0: //The path of the valid file that should be loaded sl@0: _LIT(KValidFontPath, "z:\\resource\\fonts\\DejaVuSansCondensed.ttf"); sl@0: sl@0: //Check the invalid file exists sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: sl@0: RFile file; sl@0: TEST(file.Open(fs, KInvalidFontFilePath, EFileRead) == KErrNone); sl@0: sl@0: file.Close(); sl@0: fs.Close(); sl@0: sl@0: //Create an instance of CFontStore and load the current rasterizers and fonts sl@0: CTIsolatedFontStore* isolatedFontStore1 = CTIsolatedFontStore::NewL(); sl@0: CleanupStack::PushL(isolatedFontStore1); sl@0: sl@0: isolatedFontStore1->LoadRasterizersL(); sl@0: sl@0: CFontStore* fs1 = isolatedFontStore1->iFs; sl@0: fs1->LoadFontsAtStartupL(); sl@0: sl@0: TFileName fileName; sl@0: fs1->GetFontFilePath(_L("DejaVu Sans Condensed"), fileName); sl@0: sl@0: TEST(fileName.CompareF(KValidFontPath) == 0); sl@0: sl@0: CleanupStack::PopAndDestroy(isolatedFontStore1); sl@0: } sl@0: sl@0: void CTFnt::RunTestCaseL(TInt aCurTestCase) sl@0: { sl@0: ((CTFntStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); sl@0: switch(aCurTestCase) sl@0: { sl@0: case 1: sl@0: ((CTFntStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0023")); sl@0: INFO_PRINTF1(_L("#################### T_FNT test case 1 ########################\n")); sl@0: TRAPD(err,TestReadFileL(KEonFontFileName)); sl@0: TEST(err == KErrNone); sl@0: break; sl@0: case 2: sl@0: ((CTFntStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0023")); sl@0: INFO_PRINTF1(_L("#################### T_FNT test case 2 ########################\n")); sl@0: TRAP(err,TestReadFileL(K7650FontFileName)); sl@0: TEST(err == KErrNone); sl@0: break; sl@0: case 3: sl@0: ((CTFntStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0052")); sl@0: INFO_PRINTF1(_L("T_FNT test case 3 - Eclipsed font in \\resource\\fonts falls back to last good font")); sl@0: TRAP(err,TestEclipseFallbackWithInvalidFontL()); sl@0: TEST(err == KErrNone); sl@0: case 4: sl@0: ((CTFntStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); sl@0: ((CTFntStep*)iStep)->CloseTMSGraphicsStep(); sl@0: TestComplete(); sl@0: break; sl@0: } sl@0: ((CTFntStep*)iStep)->RecordTestResultL(); sl@0: } sl@0: sl@0: sl@0: //-------------- sl@0: __CONSTRUCT_STEP__(Fnt) sl@0: sl@0: sl@0: