Update contrib.
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 @internalComponent Internal Symbian test code
25 #include "T_IsolatedFontStore.h"
35 _LIT(KEonFontFileName,"z:\\resource\\fonts\\eon14.gdr");
37 _LIT(KEonFontFileName,"z:\\resource\\fonts\\eon.gdr");
40 // Set KVerboseOutput to "ETrue" if extra INFO_PRINTFx for debug purposes are required
41 const TBool KVerboseOutput = EFalse;
43 _LIT(K7650FontFileName,"z:\\resource\\fonts\\ceurope.gdr");
47 CTFnt::CTFnt(CTestStep* aStep):
50 INFO_PRINTF1(_L("FontStore T_FNT test\n"));
55 GRAPHICS-FNTSTORE-0023
58 Tests adding a font file to the font store and checks
59 the properties of the font.
62 Creates a user heap. Creates a CFontStore object and
63 uses the user heap for memory allocation. Adds a
64 font file to the font store. Checks if added correctly.
65 Gets the typeface information for the font. Retrieves the
66 nearest available font. Sets the font style to superscript
67 and subscript and tests getting nearest font. Then for all
68 available typefaces it gets the nearest fonts and checks the
69 result. The user heap is closed and the heap is checked for memory leaks.
71 @SYMTestExpectedResults
74 void CTFnt::TestReadFileL(const TDesC& aFontFile)
77 INFO_PRINTF2(_L("Starting TestReadFile with parameter %S"), &aFontFile);
80 RHeap* heap=UserHeap::ChunkHeap(NULL,0x10000,0x10000);
84 TUid id1 = TUid::Uid(0);
85 CFontStore *fs=CFontStore::NewL(heap);
87 TRAPD(ret,id1=fs->AddFileL(aFontFile));
89 INFO_PRINTF2(_L("NumTypefaces %d"),fs->NumTypefaces());
93 INFO_PRINTF1(_L("Get typeface support"));
94 TTypefaceSupport support;
95 fs->TypefaceSupport(support,0);
96 TBuf<KMaxTypefaceNameLength> name;
97 name.Copy(support.iTypeface.iName);
98 INFO_PRINTF2(_L("Typeface Name %S"),&name);
99 INFO_PRINTF2(_L("Typeface Isproportional %d"),support.iTypeface.IsProportional());
100 INFO_PRINTF2(_L("Typeface IsSerif %d"),support.iTypeface.IsSerif());
101 INFO_PRINTF2(_L("Typeface IsSymbol %d"),support.iTypeface.IsSymbol());
102 INFO_PRINTF2(_L("NumHeights %d"),support.iNumHeights);
103 INFO_PRINTF2(_L("MinHeightInTwips %d"),support.iMinHeightInTwips);
104 INFO_PRINTF2(_L("MaxHeightInTwips %d"),support.iMaxHeightInTwips);
105 INFO_PRINTF2(_L("IsScalable %d"),support.iIsScalable);
109 for (TInt i=0; i<support.iNumHeights; i++)
111 INFO_PRINTF3(_L("HeightInPixels %d is %d"),i,fs->FontHeightInPixels(0/*fs->NumTypefaces()-2*/,i));
117 INFO_PRINTF1(_L("Get nearest font"));
119 TCharacterMetrics metrics;
122 support.iTypeface=support.iTypeface;
123 spec.iTypeface.SetIsProportional(EFalse);
124 spec.iTypeface.SetIsSerif(ETrue);
125 spec.iTypeface.SetIsSymbol(EFalse);
127 spec.iFontStyle.SetPosture(EPostureUpright);
128 for (spec.iHeight=support.iMinHeightInTwips; spec.iHeight<=support.iMaxHeightInTwips; spec.iHeight++)
130 ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec);
134 INFO_PRINTF2(_L("FontSpec Height %d"),spec.iHeight);
135 INFO_PRINTF2(_L("HeightInTwips %d"),font->FontSpecInTwips().iHeight);
136 INFO_PRINTF2(_L("HeightInPixels %d"),font->HeightInPixels());
137 INFO_PRINTF2(_L("AscentInPixels %d"),font->AscentInPixels());
138 INFO_PRINTF3(_L("Font Posture %d StrokeWeight %d"),font->FontSpecInTwips().iFontStyle.Posture(),font->FontSpecInTwips().iFontStyle.StrokeWeight());
139 INFO_PRINTF3(_L("Font AlgPosture %d AlgStrokeWeight %d"),((CBitmapFont*)font)->iAlgStyle.IsItalic(),((CBitmapFont*)font)->iAlgStyle.IsBold());
141 fs->ReleaseFont(font);
144 ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec);
146 INFO_PRINTF1(_L("Got nearest font"));
147 metrics = font->CharacterMetrics(32,bytes);
148 INFO_PRINTF5(_L("First 4 bytes %d %d %d %d"),*(bytes),*(bytes+1),*(bytes+2),*(bytes+3));
149 INFO_PRINTF5(_L("Second 4 bytes %d %d %d %d"),*(bytes+4),*(bytes+5),*(bytes+6),*(bytes+7));
151 INFO_PRINTF2(_L("LeftAdjustInPixels %d"),metrics.iLeftAdjustInPixels);
152 INFO_PRINTF2(_L("MoveInPixels %d"),metrics.iMoveInPixels);
153 INFO_PRINTF2(_L("RightAdjustInPixels %d"),metrics.iRightAdjustInPixels);
154 INFO_PRINTF2(_L("TextWidthInPixels(EPOC) %d"),font->TextWidthInPixels(_L("EPOC")));
155 INFO_PRINTF2(_L("TextWidthInPixels(\x00BB) %d"),font->TextWidthInPixels(_L("\x00BB"))); //Double Greater Than »
156 CFont::TMeasureTextInput param;
157 param.iStartInputChar = 34;
158 INFO_PRINTF2(_L("TextWidthInPixels with supplied context(EPOC) %d"),font->TextWidthInPixels(_L("->This text will not be measured<-EPOC"),¶m));
159 INFO_PRINTF2(_L("TextWidthInPixels with supplied context(\x00BB) %d"),font->TextWidthInPixels(_L("->This text will not be measured<-\x00BB"),¶m));
160 INFO_PRINTF2(_L("TextCount(EPOC,50) %d"),font->TextCount(_L("EPOC"),50));
162 INFO_PRINTF2(_L("WidthZeroInPixels %d"),font->WidthZeroInPixels());
163 INFO_PRINTF2(_L("MaxCharWidthInPixels %d"),font->MaxCharWidthInPixels());
164 INFO_PRINTF2(_L("MaxNormalCharWidthInPixels %d"),font->MaxNormalCharWidthInPixels());
165 INFO_PRINTF2(_L("HeightInTwips %d"),font->FontSpecInTwips().iHeight);
166 name.Copy(font->FontSpecInTwips().iTypeface.iName);
167 INFO_PRINTF2(_L("Typeface Name %S"),&name);
169 fs->ReleaseFont(font);
173 INFO_PRINTF1(_L("Get nearest monoized font"));
174 support.iTypeface.iName=_L("");//Mono Swiss");
175 support.iTypeface.SetIsProportional(ETrue);//=support.iTypeface;
176 support.iTypeface.SetIsSerif(ETrue);//=support.iTypeface;
177 spec.iTypeface=support.iTypeface;
179 spec.iFontStyle.SetPosture(EPostureUpright);
180 spec.iFontStyle.SetPrintPosition(EPrintPosNormal);
181 ret=fs->GetNearestFontToDesignHeightInPixels((CFont *&) font,spec);
183 INFO_PRINTF2(_L("HeightInPixels %d"),font->HeightInPixels());
184 INFO_PRINTF2(_L("AscentInPixels %d"),font->AscentInPixels());
185 metrics = font->CharacterMetrics(32,bytes);
186 INFO_PRINTF5(_L("First 4 bytes %d %d %d %d"),*(bytes),*(bytes+1),*(bytes+2),*(bytes+3));
187 INFO_PRINTF5(_L("Second 4 bytes %d %d %d %d"),*(bytes+4),*(bytes+5),*(bytes+6),*(bytes+7));
188 INFO_PRINTF2(_L("LeftAdjustInPixels %d"),metrics.iLeftAdjustInPixels);
189 INFO_PRINTF2(_L("MoveInPixels %d"),metrics.iMoveInPixels);
190 INFO_PRINTF2(_L("RightAdjustInPixels %d"),metrics.iRightAdjustInPixels);
191 INFO_PRINTF2(_L("TextWidthInPixels(EPOC) %d"),font->TextWidthInPixels(_L("EPOC")));
192 INFO_PRINTF2(_L("WidthZeroInPixels %d"),font->WidthZeroInPixels());
193 INFO_PRINTF2(_L("TextCount(EPOC,50) %d"),font->TextCount(_L("EPOC"),50));
194 INFO_PRINTF2(_L("MaxCharWidthInPixels %d"),font->MaxCharWidthInPixels());
195 INFO_PRINTF2(_L("MaxNormalCharWidthInPixels %d"),font->MaxNormalCharWidthInPixels());
196 INFO_PRINTF2(_L("HeightInTwips %d"),font->FontSpecInTwips().iHeight);
197 name.Copy(font->FontSpecInTwips().iTypeface.iName);
198 INFO_PRINTF2(_L("Typeface Name %S"),&name);
200 fs->ReleaseFont(font);
202 // Get superscript font
204 INFO_PRINTF1(_L("Get superscript font"));
205 spec.iFontStyle.SetPrintPosition(EPrintPosSuperscript);
206 ret=fs->GetNearestFontToDesignHeightInPixels((CFont *&) font,spec);
208 INFO_PRINTF2(_L("HeightInPixels %d"),font->HeightInPixels());
209 INFO_PRINTF2(_L("BaselineOffsetInPixels %d"),font->iAlgStyle.iBaselineOffsetInPixels);
210 INFO_PRINTF2(_L("HeightInTwips %d"),font->FontSpecInTwips().iHeight);
211 name.Copy(font->FontSpecInTwips().iTypeface.iName);
212 INFO_PRINTF2(_L("Typeface Name %S"),&name);
214 fs->ReleaseFont(font);
216 // Get subscript font
218 INFO_PRINTF1(_L("Get subscript font"));
219 spec.iFontStyle.SetPrintPosition(EPrintPosSubscript);
220 ret=fs->GetNearestFontToDesignHeightInPixels((CFont *&) font,spec);
222 INFO_PRINTF2(_L("HeightInPixels %d"),font->HeightInPixels());
223 INFO_PRINTF2(_L("BaselineOffsetInPixels %d"),font->iAlgStyle.iBaselineOffsetInPixels);
224 INFO_PRINTF2(_L("HeightInTwips %d"),font->FontSpecInTwips().iHeight);
225 name.Copy(font->FontSpecInTwips().iTypeface.iName);
226 INFO_PRINTF2(_L("Typeface Name %S"),&name);
228 fs->ReleaseFont(font);
232 INFO_PRINTF1(_L("Get typeface support"));
233 spec.iFontStyle.SetPrintPosition(EPrintPosNormal);
234 spec.iFontStyle.SetPosture(EPostureUpright);
235 spec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
236 for (TInt i=0; i<fs->NumTypefaces(); i++)
238 fs->TypefaceSupport(support,i);
239 name.Copy(support.iTypeface.iName);
240 INFO_PRINTF2(_L("Typeface Name %S"),&name);
241 for (TInt j=0; j<support.iNumHeights; j++)
243 spec.iTypeface=support.iTypeface;
244 spec.iHeight=fs->FontHeightInPixels(i,j);
245 ret=fs->GetNearestFontToDesignHeightInPixels((CFont *&) font,spec);
247 INFO_PRINTF2(_L("Spec HeightInPixels %d"),spec.iHeight);
248 INFO_PRINTF2(_L("Font HeightInPixels %d"),font->HeightInPixels());
249 INFO_PRINTF3(_L("Font Posture %d StrokeWeight %d"),font->FontSpecInTwips().iFontStyle.Posture(),font->FontSpecInTwips().iFontStyle.StrokeWeight());
250 INFO_PRINTF3(_L("Font AlgPosture %d AlgStrokeWeight %d"),font->iAlgStyle.IsItalic(),font->iAlgStyle.IsBold());
251 fs->ReleaseFont(font);
256 INFO_PRINTF1(_L("Destroy filestore\n\n"));
265 GRAPHICS-FNTSTORE-0052
274 Creates an instance of fontstore to test that invalid font files generated by the test script
275 have not eclipsed the valid files already loaded.
284 The start of this test script will create an invalid font file in c:\resource\fonts. This test
285 creates an instance of font store and performs the font loading to check the invalid file is not
286 loaded and font store has fallen back to the correct file.
288 The test also ensures that the invalid file has been created sucessfully by T_WriteInvalidFontFile.exe
290 After this set off test have been run the file is removed by T_RemoveInvalidFontFile.exe
292 @SYMTestExpectedResults
293 The Invalid Font file will exist; font store will not load this file and instead will load the file that it
297 void CTFnt::TestEclipseFallbackWithInvalidFontL()
299 //The path of the invalid file that should not be loaded
300 _LIT(KInvalidFontFilePath, "c:\\resource\\fonts\\DejaVuSansCondensed.ttf");
302 //The path of the valid file that should be loaded
303 _LIT(KValidFontPath, "z:\\resource\\fonts\\DejaVuSansCondensed.ttf");
305 //Check the invalid file exists
307 User::LeaveIfError(fs.Connect());
310 TEST(file.Open(fs, KInvalidFontFilePath, EFileRead) == KErrNone);
315 //Create an instance of CFontStore and load the current rasterizers and fonts
316 CTIsolatedFontStore* isolatedFontStore1 = CTIsolatedFontStore::NewL();
317 CleanupStack::PushL(isolatedFontStore1);
319 isolatedFontStore1->LoadRasterizersL();
321 CFontStore* fs1 = isolatedFontStore1->iFs;
322 fs1->LoadFontsAtStartupL();
325 fs1->GetFontFilePath(_L("DejaVu Sans Condensed"), fileName);
327 TEST(fileName.CompareF(KValidFontPath) == 0);
329 CleanupStack::PopAndDestroy(isolatedFontStore1);
332 void CTFnt::RunTestCaseL(TInt aCurTestCase)
334 ((CTFntStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
338 ((CTFntStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0023"));
339 INFO_PRINTF1(_L("#################### T_FNT test case 1 ########################\n"));
340 TRAPD(err,TestReadFileL(KEonFontFileName));
341 TEST(err == KErrNone);
344 ((CTFntStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0023"));
345 INFO_PRINTF1(_L("#################### T_FNT test case 2 ########################\n"));
346 TRAP(err,TestReadFileL(K7650FontFileName));
347 TEST(err == KErrNone);
350 ((CTFntStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0052"));
351 INFO_PRINTF1(_L("T_FNT test case 3 - Eclipsed font in \\resource\\fonts falls back to last good font"));
352 TRAP(err,TestEclipseFallbackWithInvalidFontL());
353 TEST(err == KErrNone);
355 ((CTFntStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
356 ((CTFntStep*)iStep)->CloseTMSGraphicsStep();
360 ((CTFntStep*)iStep)->RecordTestResultL();
365 __CONSTRUCT_STEP__(Fnt)