Update contrib.
2 * Copyright (c) 2008-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.
20 #include "t_linkedfontscomparison.h"
22 #include <test/thashreferenceimages.h>
23 #include <linkedfonts.h>
28 @SYMPurpose structures used to define linked typefaces used in this test, create and
29 use linked typefaces, and check against a hash value
32 /** this is for the group entries
36 CLinkedTypefaceGroup::TBaselineShift iBaselineShift;
37 CLinkedTypefaceGroup::TScalingOption iScalingOption;
38 TInt iAntiAliasThreshold; //KMinTInt for do not set;
39 TInt iBoldnessPercentage; //KMinTInt for do not set;
40 TInt iItalicAngle; //KMinTInt for do not set;
43 /** this is for linked font elements
45 struct TTLinkedFontElement
47 const TPtrC iTypefaceName;
52 /** this is for the linked typeface table
54 struct TTLinkedTypeface
56 const TPtrC iTypefaceName;
57 const TTLinkedFontElement* iElements;
60 /** this is a plain group
62 const TTGroup KPlainGroup =
64 CLinkedTypefaceGroup::ENoBaselineShift,
65 CLinkedTypefaceGroup::EScalingNone,
66 KMinTInt, //this value means do not set
67 KMinTInt, //this value means do not set
68 KMinTInt, //this value means do not set
71 const TTGroup KGroup1 =
73 CLinkedTypefaceGroup::ENoBaselineShift,
74 CLinkedTypefaceGroup::EScalingNone,
75 KMinTInt, //this value means do not set - antialiased
76 KMinTInt, //this value means do not set - boldness percentage
77 KMinTInt, //this value means do not set - italic angle
80 const TTGroup KGroup2 =
82 CLinkedTypefaceGroup::EBaselineShift,
83 CLinkedTypefaceGroup::EScalingUp,
84 KMinTInt, //this value means do not set
85 KMinTInt, //this value means do not set
86 KMinTInt, //this value means do not set
88 const TTGroup KGroup3 =
90 CLinkedTypefaceGroup::EBaselineShift,
91 CLinkedTypefaceGroup::EScalingUpOrDown,
92 KMinTInt, //this value means do not set
93 KMinTInt, //this value means do not set
94 KMinTInt, //this value means do not set
96 const TTGroup KGroup4 =
98 CLinkedTypefaceGroup::ENoBaselineShift,
99 CLinkedTypefaceGroup::EScalingNone,
101 KMinTInt, //this value means do not set
102 KMinTInt, //this value means do not set
104 const TTGroup KGroup5 =
106 CLinkedTypefaceGroup::ENoBaselineShift,
107 CLinkedTypefaceGroup::EScalingNone,
109 KMinTInt, //this value means do not set
110 KMinTInt, //this value means do not set
112 const TTGroup KGroup6 =
114 CLinkedTypefaceGroup::ENoBaselineShift,
115 CLinkedTypefaceGroup::EScalingNone,
116 KMinTInt, //this value means do not set
117 100, //boldness percentage
118 KMinTInt, //this value means do not set
120 const TTGroup KGroup7 =
122 CLinkedTypefaceGroup::ENoBaselineShift,
123 CLinkedTypefaceGroup::EScalingNone,
124 KMinTInt, //this value means do not set
125 10, //boldness percentage
126 KMinTInt, //this value means do not set
128 const TTGroup KGroup8 =
130 CLinkedTypefaceGroup::ENoBaselineShift,
131 CLinkedTypefaceGroup::EScalingNone,
132 KMinTInt, //this value means do not set
133 KMinTInt, //this value means do not set
136 const TTGroup KGroup9 =
138 CLinkedTypefaceGroup::EBaselineShift,
139 CLinkedTypefaceGroup::EScalingNone,
140 KMinTInt, //this value means do not set
141 KMinTInt, //this value means do not set
142 KMinTInt, //this value means do not set
144 const TTGroup KGroup10 =
146 CLinkedTypefaceGroup::ENoBaselineShift,
147 CLinkedTypefaceGroup::EScalingNone,
148 KMinTInt, //this value means do not set
149 KMinTInt, //this value means do not set
150 40, //large italic angle
153 /** all the groups are added to every linked typeface
154 if there are too many groups then there may be a need for a group list
155 per linked typeface. Can have a maximum of 12 groups
157 const TTGroup* KGroupList[]=
159 &KPlainGroup, /* index 0 */
172 /** typeface element definitions
177 const TTLinkedFontElement KLatinFontCanonical =
179 _L("DejaVu Sans Condensed"),0, ETrue //name, group zero, is canonical
184 const TTLinkedFontElement KJapaneseNotCanonical =
186 _L("TBKomachiG-R"), 0, EFalse //name, group zero, not canonical
189 /** Japanese - to be updated
191 const TTLinkedFontElement KJapaneseNotCanonicalGroup1 =
193 _L("TBKomachiG-R"), 1, EFalse //name, group , not canonical
195 const TTLinkedFontElement KJapaneseNotCanonicalGroup3 =
197 _L("TBKomachiG-R"), 3, EFalse //name, group, not canonical
199 const TTLinkedFontElement KJapaneseNotCanonicalGroup4 =
201 _L("TBKomachiG-R"), 4, EFalse //name, group, not canonical
203 const TTLinkedFontElement KJapaneseNotCanonicalGroup6 =
205 _L("TBKomachiG-R"), 6, EFalse //name, group, not canonical
207 const TTLinkedFontElement KJapaneseNotCanonicalGroup8 =
209 _L("TBKomachiG-R"), 8, EFalse //name, group, not canonical
211 const TTLinkedFontElement KJapaneseNotCanonicalGroup9 =
213 _L("TBKomachiG-R"), 9, EFalse //name, group, not canonical
215 const TTLinkedFontElement KJapaneseNotCanonicalGroup10 =
217 _L("TBKomachiG-R"), 10, EFalse //name, group, not canonical
220 const TTLinkedFontElement KLatinFontTTNotCanonicalGroup0 =
222 _L("LinkedFontTestFont"), 0, EFalse
225 const TTLinkedFontElement KLatinFontTTCanonicalGroup0 =
227 _L("LinkedFontTestFont"), 0, ETrue
230 /* for use case testing */
231 const TTLinkedFontElement KLatinFontTTCanonicalGroup2 =
233 _L("LinkedFontTestFont"), 2, ETrue
235 const TTLinkedFontElement KLatinFontTTCanonicalGroup3 =
237 _L("LinkedFontTestFont"), 3, ETrue
239 const TTLinkedFontElement KLatinFontTTCanonicalGroup5 =
241 _L("LinkedFontTestFont"), 5, ETrue
243 const TTLinkedFontElement KLatinFontTTCanonicalGroup7 =
245 _L("LinkedFontTestFont"), 7, ETrue
247 const TTLinkedFontElement KLatinFontTTCanonicalGroup8 =
249 _L("LinkedFontTestFont"), 8, ETrue
251 const TTLinkedFontElement KLatinFontTTCanonicalGroup9 =
253 _L("LinkedFontTestFont"), 9, ETrue
255 const TTLinkedFontElement KLatinFontTTCanonicalGroup10 =
257 _L("LinkedFontTestFont"), 10, ETrue
262 const TTLinkedFontElement KHindiCanonical =
264 _L("Chandas"), 0, ETrue
269 const TTLinkedFontElement KHindiNotCanonical =
271 _L("Chandas"), 0, EFalse
274 /** Information about linked fonts
276 Typeface name: LinkedFont1
277 This will be the dominant font. It contains 178 characters.
278 Some of the characters (13) are deleted from this file and separated in to other three files.
279 Characters missing are F, D, J, M, P, S, V, X, Z, a, n, l, y.
282 Typeface name: LinkedFont2
283 Characters available (7): F, J, M, S, Z, a, y.
286 Typeface name: LinkedFont3
287 Characters available (4): D, P, x, l
290 Typeface name: LinkedFont4
291 Characters available (2): V, n
293 TWithoutLinkedFont.ttf
294 Typeface name: WithoutLinkedFont
295 Characters available: It contains 191 characters U+0020-U+007E and U+00A0-U+00FF
300 const TTLinkedFontElement KLinkedFont1TT =
302 _L("LinkedFont1TT"), 0, EFalse
307 const TTLinkedFontElement KLinkedFont2TTCanonical =
309 _L("LinkedFont2TT"), 0, ETrue
314 const TTLinkedFontElement KLinkedFont3TT =
316 _L("LinkedFont3TT"), 0, EFalse
321 const TTLinkedFontElement KLinkedFont4TT =
323 _L("LinkedFont4TT"), 0, EFalse
328 const TTLinkedFontElement KNullElement =
333 /** linked typeface, this list is terminated by KNullElement
335 const TTLinkedFontElement KLatinFontHindi[]=
337 KLatinFontTTNotCanonicalGroup0,
341 /** linked typeface, this list is terminated by KNullElement
343 const TTLinkedFontElement KLatinFontJapanese[]=
346 KJapaneseNotCanonical,
349 /** linked typeface, this list is terminated by KNullElement
351 const TTLinkedFontElement KLinkedFontTestFonts[]=
354 KLinkedFont2TTCanonical,
360 const TTLinkedFontElement KJapaneseLatinFontTypeface1[]=
362 KLatinFontTTCanonicalGroup2,
363 KJapaneseNotCanonicalGroup1,
366 const TTLinkedFontElement KJapaneseLatinFontTypeface2[]=
368 KLatinFontTTCanonicalGroup3,
369 KJapaneseNotCanonicalGroup3,
372 const TTLinkedFontElement KJapaneseLatinFontTypeface3[]=
374 KLatinFontTTCanonicalGroup5,
375 KJapaneseNotCanonicalGroup4,
378 const TTLinkedFontElement KJapaneseLatinFontTypeface4[]=
380 KLatinFontTTCanonicalGroup7,
381 KJapaneseNotCanonicalGroup6,
384 const TTLinkedFontElement KJapaneseLatinFontTypeface5[]=
386 KLatinFontTTCanonicalGroup8,
387 KJapaneseNotCanonicalGroup8,
390 const TTLinkedFontElement KJapaneseLatinFontTypeface6[]=
392 KLatinFontTTCanonicalGroup9,
393 KJapaneseNotCanonicalGroup9,
397 const TTLinkedFontElement KJapaneseLatinFontTypeface7[]=
399 KLatinFontTTCanonicalGroup10,
400 KJapaneseNotCanonicalGroup10,
404 const TTLinkedFontElement KEnglishJapanseHindiFont[]=
406 KLatinFontTTCanonicalGroup0,
407 KJapaneseNotCanonical,
412 /** the linked typeface set, no need to null terminate, sizeof is used for this array
414 const TTLinkedTypeface KLinkedTypefaces[] =
416 //name, list of linked font elements
417 {_L("LinkedFontTestFont"), KLinkedFontTestFonts},
418 {_L("LatinFontHindi"), KLatinFontHindi},
419 {_L("LatinFontJapanese"), KLatinFontJapanese},
420 {_L("EnglishJapaneseHindi"), KEnglishJapanseHindiFont},
421 {_L("UseCaseFont1"), KJapaneseLatinFontTypeface1},
422 {_L("UseCaseFont2"), KJapaneseLatinFontTypeface2},
423 {_L("UseCaseFont3"), KJapaneseLatinFontTypeface3},
424 {_L("UseCaseFont4"), KJapaneseLatinFontTypeface4},
425 {_L("UseCaseFont5"), KJapaneseLatinFontTypeface5},
426 {_L("UseCaseFont6"), KJapaneseLatinFontTypeface6},
427 {_L("UseCaseFont7"), KJapaneseLatinFontTypeface7},
430 /** Enum which constains bitwise flags for attrbutes which can be set for each font
432 enum TFontEffectsFlags
437 ESetMonochromeGlyphBitmap = 0x4,
438 ESetAntiAliasedGlyphBitmap = 0x8,
439 ESetFourColourBlendGlyphBitmap = 0x10,
440 EVerticalDraw = 0x20,
441 ERotate90Degrees = 0x40,
442 EIsStrikethroughOn = 0x80,
443 EIsUnderlineOn = 0x100,
445 EAlgorithmicBoldOn = 0x400,
448 ERegularBoldOn = 0x2000,
449 EEndOfList = 0x80000000 //a meta flag
452 const TInt KLengthOfHashValue = 1000;
454 /** table used to produce hash string from attributes
456 const TPtrC KFontEffectsFlagsString[32]=
461 _L("ESetMonochromeGlyphBitmap"),
462 _L("ESetAntiAliasedGlyphBitmap"),
463 _L("ESetFourColourBlendGlyphBitmap"),
465 _L("ERotate90Degrees"),
466 _L("EIsStrikethroughOn"),
467 _L("EIsUnderlineOn"),
469 _L("EAlgorithmicBoldOn"),
472 _L("ERegularBoldOn"),
493 /**this structure is used to define a test case
497 const TPtrC iTypeFaceName; //typeface name
498 const TDesC* iOutputString; //the output string
499 const TDesC* iTestDecription; //test description
500 const TPoint iPosition; //the position
501 const TInt* iSizes; // a list of sizes
502 const TUint32* iFontAttributes; //a list of font attrbutes (bitwise flags, see above
505 /** an array of sizes used during testing, terminated by zero
507 const TInt KFontSizeNormalTesting[]=
515 const TInt KFontSizeUseCaseTesting[]=
524 /** an array of attributes used during font testing, terminated by EEndOfList
526 const TUint32 KFontAttributesNormalTest[] =// probably need to expand this with position
531 ESetFourColourBlendGlyphBitmap,
532 EIsUnderlineOn| EIsStrikethroughOn,
535 EVerticalDraw | EIsUnderlineOn,
536 EVerticalDraw | EIsUnderlineOn | ERotate90Degrees,
540 const TUint32 KFontAttributesUseCaseTest[] =// probably need to expand this with position
544 ESetAntiAliasedGlyphBitmap,
549 // here are the output strings which are used for testing
550 _LIT(KHindiText,"\x0915\x094D\x0937\x0924\x094D\x0930\x093F\x092F\x0020");
551 _LIT(KEnglishText,"The quick brown fox 123");
552 _LIT(KEnglishHindiText,"TEST 123 \x0915\x094D\x0937\x0924\x094D\x0930\x093F\x092F\x0020");
553 _LIT(KEnglishJapaneseText,"T\x308a\x3093\x3054 ESghy LINKED FONTS 123");
554 _LIT(KEnglishJapaneseHindiText, "T\x308a\x3093\x3054\x306e EST FOnTS LINKED \x0915\x094D\x0937\x0924\x094D\x0930\x093F\x092F\x0020 123");
555 _LIT(KLinkedFontTestString,"lInKED FOnTS");
559 _LIT(KEnglishTest,"EnglishTest");
560 _LIT(KHindiTest,"HindiTest");
561 _LIT(KEnglishHindiTest,"EnglishHindiTest");
562 _LIT(KEnglishJapaneseTest,"EnglishJapaneseTest");
563 _LIT(KLinkedFontTest1,"LinkedFontTest-withLinking");
564 _LIT(KLinkedFontTest2,"LinkedFontTest-unlinkedFont");
565 _LIT(KEnglishJapaneseHindiTest,"EnglishJapaneseHindiTest");
566 _LIT(KUseCaseTest,"UseCaseTest");
570 _LIT(KTestName0001,"TestCase001");
571 /** this table defines the test cases:
572 font name, string, position, sizes(array), attributes(array)
574 const TTestCase KTestCases[]=
576 {_L("LatinFontHindi"), &KHindiText,&KHindiTest, TPoint(50,50),KFontSizeNormalTesting, KFontAttributesNormalTest},
577 {_L("LatinFontHindi"), &KEnglishText, &KEnglishTest, TPoint(50,50),KFontSizeNormalTesting, KFontAttributesNormalTest},
578 {_L("LatinFontHindi"), &KEnglishHindiText, &KEnglishHindiTest, TPoint(50,50),KFontSizeNormalTesting, KFontAttributesNormalTest},
579 {_L("LatinFontJapanese"),&KEnglishText, &KEnglishTest, TPoint(50,50),KFontSizeNormalTesting, KFontAttributesNormalTest},
580 {_L("LatinFontJapanese"),&KEnglishJapaneseText, &KEnglishJapaneseTest, TPoint(50,50),KFontSizeNormalTesting, KFontAttributesNormalTest},
581 {_L("LinkedFontTestFont"),&KLinkedFontTestString, &KLinkedFontTest1, TPoint(50,50),KFontSizeNormalTesting, KFontAttributesNormalTest},
582 {_L("WithoutLinkedFontTT"),&KLinkedFontTestString, &KLinkedFontTest2, TPoint(50,50),KFontSizeNormalTesting, KFontAttributesNormalTest},
583 {_L("EnglishJapaneseHindi"),&KEnglishJapaneseHindiText, &KEnglishJapaneseHindiTest, TPoint(50,50),KFontSizeNormalTesting, KFontAttributesNormalTest},
586 {_L("UseCaseFont1"),&KEnglishJapaneseText, &KUseCaseTest, TPoint(50,50),KFontSizeUseCaseTesting, KFontAttributesUseCaseTest},
587 {_L("UseCaseFont2"),&KEnglishJapaneseText, &KUseCaseTest, TPoint(50,50),KFontSizeUseCaseTesting, KFontAttributesUseCaseTest},
588 {_L("UseCaseFont3"),&KEnglishJapaneseText, &KUseCaseTest, TPoint(50,50),KFontSizeUseCaseTesting, KFontAttributesUseCaseTest},
589 {_L("UseCaseFont4"),&KEnglishJapaneseText, &KUseCaseTest, TPoint(50,50),KFontSizeUseCaseTesting, KFontAttributesUseCaseTest},
590 {_L("UseCaseFont5"),&KEnglishJapaneseText, &KUseCaseTest, TPoint(50,50),KFontSizeUseCaseTesting, KFontAttributesUseCaseTest},
591 {_L("UseCaseFont6"),&KEnglishJapaneseText, &KUseCaseTest, TPoint(50,50),KFontSizeUseCaseTesting, KFontAttributesUseCaseTest},
592 {_L("UseCaseFont7"),&KEnglishJapaneseText, &KUseCaseTest, TPoint(50,50),KFontSizeUseCaseTesting, KFontAttributesUseCaseTest},
595 /** Class used to register the linked typefaces
597 class CTLinkedTypefaceCreator : public CBase
600 static CTLinkedTypefaceCreator* NewL(CTestStep* aStep);
601 void CreateL(); //creates the linked typefaces - will not leave with a registration error, but try the next
602 ~CTLinkedTypefaceCreator();
604 CTLinkedTypefaceCreator(CTestStep* aStep);
605 void CreateGroupsL(const TTGroup* aElement[],TInt aNumberOfElements);
606 void CreateElementsL(const TTLinkedFontElement* aElements);
610 CTestStep* iStep; //for recording failures, not owned
611 RPointerArray<CLinkedTypefaceGroup> iGroups; //owned
612 RPointerArray<CLinkedTypefaceElementSpec> iElements; //owned
613 CFbsScreenDevice* iDev; //owned
617 @return CTLinkedTypefaceCreator*
619 CTLinkedTypefaceCreator* CTLinkedTypefaceCreator::NewL(CTestStep* aStep)
621 CTLinkedTypefaceCreator* ptr = new (ELeave) CTLinkedTypefaceCreator(aStep);
622 CleanupStack::PushL(ptr);
628 CTLinkedTypefaceCreator::CTLinkedTypefaceCreator(CTestStep* aStep):iStep(aStep)
633 void CTLinkedTypefaceCreator::ConstructL()
635 TDisplayMode mode[4]= {EColor16MAP, EColor16MA, EColor16MU, EColor64K};
638 for (TInt count=0;count<(sizeof(mode)/sizeof(mode[0]));count++)
640 TRAP(err, iDev = CFbsScreenDevice::NewL(KNullDesC, mode[count]));
641 if (err!=KErrNotSupported)
647 User::LeaveIfError(err);
650 CTLinkedTypefaceCreator::~CTLinkedTypefaceCreator()
653 iGroups.ResetAndDestroy();
654 iElements.ResetAndDestroy();
657 /** function used to create the linked typefaces
659 void CTLinkedTypefaceCreator::CreateL()
661 CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(iDev);
662 CleanupStack::PushL(store);
664 for (TInt counter=0; counter< sizeof(KLinkedTypefaces)/sizeof(TTLinkedTypeface);counter++)
666 //creating the groups needs to be done for every typeface since ownwership is taken
667 //after adding the group to one linked typeface specification
668 //leave on any failure e.g. out of memory, which is not expected
669 CreateGroupsL(KGroupList, sizeof(KGroupList)/sizeof(TTGroup*));
671 //create the linked typeface elements for this linked typeface
672 CreateElementsL(KLinkedTypefaces[counter].iElements);
674 //add the groups and elements, but first create the spec
675 CLinkedTypefaceSpecification* spec = CLinkedTypefaceSpecification::NewLC(KLinkedTypefaces[counter].iTypefaceName);
678 for (TInt groupCounter=0; groupCounter<iGroups.Count();groupCounter++)
680 spec->AddLinkedTypefaceGroupL(*iGroups[groupCounter]);//ownership is taken
681 iGroups[groupCounter]=NULL;
685 for (TInt elementCounter=0; elementCounter<iElements.Count();elementCounter++)
687 spec->AddTypefaceAtBackL(*iElements[elementCounter]);//ownership is taken
688 iElements[elementCounter]=NULL;
690 iElements.ResetAndDestroy();
691 iGroups.ResetAndDestroy();
695 TRAP(err,spec->RegisterLinkedTypefaceL(*store)); //may fail if something is wrong with the tables, want to try to continue
697 //do not report test failure if already registered
698 iStep->testBooleanTrue(err==KErrNone || err==KErrAlreadyExists, (TText8*)__FILE__, __LINE__);
701 CleanupStack::PopAndDestroy();
703 CleanupStack::PopAndDestroy();//store
706 /** function used to create the groups, note all groups are created at once, and
707 added to all linked typefaces
709 @param aElement array of pointers to groups
710 @param aNumberOfElements the number of elements in the group
712 void CTLinkedTypefaceCreator::CreateGroupsL(const TTGroup* aElement[],TInt aNumberOfElements)
714 for (TInt counter =0; counter<aNumberOfElements;counter++)
716 CLinkedTypefaceGroup* groupPtr= CLinkedTypefaceGroup::NewLC(counter);
717 groupPtr->SetScalingOption(aElement[counter]->iScalingOption);
718 groupPtr->SetBaselineShift(aElement[counter]->iBaselineShift);
720 if (aElement[counter]->iBoldnessPercentage!=KMinTInt)
722 groupPtr->SetBoldnessPercentage(aElement[counter]->iBoldnessPercentage);
724 if (aElement[counter]->iItalicAngle!=KMinTInt)
726 groupPtr->SetItalicAngle(aElement[counter]->iItalicAngle);
728 iGroups.AppendL(groupPtr);
729 CleanupStack::Pop();//ptr is now on the RArray
733 /** creates all the elements for one typeface
736 @param aElements pointer to a list of elements, terminated by a typeface with null name
739 void CTLinkedTypefaceCreator::CreateElementsL(const TTLinkedFontElement* aElements)
741 const TTLinkedFontElement* ptrElementSpec = aElements;
743 //need a loop to go through all the typefaces
744 for (;ptrElementSpec->iTypefaceName!=KNullDesC;ptrElementSpec++)
746 CLinkedTypefaceElementSpec* elementSpec = CLinkedTypefaceElementSpec::NewLC(ptrElementSpec->iTypefaceName,ptrElementSpec->iGroup);
747 elementSpec->SetCanonical(ptrElementSpec->iIsCanonical);
748 iElements.AppendL(elementSpec);
753 // Code for creating fonts, drawing text, and comparing hash value
755 //Considering the intersection of the screen size for both hw and emulator so that same
756 //baselined hash can be used to test for both
757 #define KScreenWidth 320
758 #define KScreenHeight 240
760 const TInt KNumOfDisplayModes = 12;
762 /** table of strings of display modes
764 const TPtrC KDisplayModeNames[KNumOfDisplayModes] =
780 /** a mapping table index from DisplayMode into the table of strings
781 for supported colour modes.
782 The tables of strings do not include ERgb, or ENone. The value in the table is also
783 needed for compatibility with CTHashReferenceImages
785 const TInt KSupportDisplayStringIndex[14] =
787 0, //ENone - use EGray2 output string
803 /** a helper cleanup class
807 CBitmapDevice* device;
811 /** path where the output file are to be stored (if this is configured in chashreferenceimages.cpp
813 _LIT(KPath,"c:\\fntstoretest\\%S.mbm");
816 @param aStep the test step
818 CTLinkedFontsComparison::CTLinkedFontsComparison(CTestStep *aStep):CTGraphicsBase(aStep),iStep(aStep)
824 void CTLinkedFontsComparison::ConstructL()
826 iFbs = RFbsSession::GetSession();
827 User::LeaveIfNull(iFbs);
828 iHashUtil = CTHashReferenceImages::NewL(iStep,iFbs,&KPath);
833 CTLinkedFontsComparison::~CTLinkedFontsComparison()
842 Auxilary function will be called in case of a leave to release the font
843 @param aCleanFont font to be released
845 void CleanUpFont(TAny* aCleanFont)
847 SCleanFont* cleanFont= static_cast<SCleanFont*>(aCleanFont);
848 (cleanFont->device)->ReleaseFont(cleanFont->font);
852 class CFbsFontEx : public CFbsFont
855 static CBitmapFont* FontAddress(CFbsFont* aFont);
858 CBitmapFont* CFbsFontEx::FontAddress(CFbsFont* aFont)
860 return(((CFbsFontEx*)aFont)->Address());
864 @SYMTestCaseID GRAPHICS-FNTSTORE-LINKEDFONTS-0107
868 @SYMREQ REQ10924, REQ10925, REQ10926, REQ10927, REQ10942, REQ10943, REQ10947, REQ10949
870 @SYMTestCaseDesc This test registers linked typefaces with defintions coming from tables.
872 @SYMTestActions Register a number of linked typefaces which are defined in a set of tables.
874 Groups can have the following attributes:
875 CLinkedTypefaceGroup::TBaselineShift
876 CLinkedTypefaceGroup::TScalingOption
877 AntiAliasingThreshold (integer value)
878 BoldnessPercentage (integer value)
879 ItalicAngle (integer value)
881 Typeface elements can have the following attributes:
886 Linked typefaces can have the following attributes:
888 Linked typeface elements
891 For each linked typeface to be created
892 create linked typeface specification
894 add groups to linked typeface specification
895 create linked typeface elements
896 add linked typeface elements to linked typeface specification
897 register the specification
899 To produce new linked typefaces it should be possible to do this by updating
902 The linked typefaces should be valid. This test requires that the internal test
905 @SYMTestPriority Critical
907 @SYMTestStatus Implemented
909 @SYMTestActions (1)For each linked typeface, create the groups, create the linked typeface elements,
910 create a linked typeface, add the groups and elements, and
911 register the linked typeface with the font and bitmap server.
913 @SYMTestExpectedResults (1) - linked font registration succeeds with no panics or leaves. If the test is run a
914 second time then KErrAlreadyExists is returned, which is not a failure.
916 void CTLinkedFontsComparison::RegisterLinkedTypefacesL()
918 CTLinkedTypefaceCreator* creator = CTLinkedTypefaceCreator::NewL(iStep);
919 CleanupStack::PushL(creator);
921 CleanupStack::PopAndDestroy();
924 /** Create the screen device.
925 @param aMode display mode for which device has to be created
927 void CTLinkedFontsComparison::CreateBitmapDeviceL(TDisplayMode aMode)
929 iBitmap = new(ELeave) CFbsBitmap;
930 //Considering the intersection of the screen size for both hw and emulator so that same
931 //baselined hash can be used to test for both
932 iBitmap->Create(TSize(KScreenWidth, KScreenHeight), aMode);
933 iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
934 User::LeaveIfError(iBitmapDevice->CreateContext((CGraphicsContext*&)iGc));
935 iHashUtil->SetScreenDeviceAndBitmap(iBitmapDevice,iBitmap,iGc);
939 Delete the devices created and gc.
941 void CTLinkedFontsComparison::FreeScreenDevice()
943 delete iBitmapDevice;
946 iBitmapDevice = NULL;
951 /** Function to generate a meaningful hash string from the test attributes
953 @param aSize the size of the font
954 @param aAttributes the attributes of the font
955 @see TFontEffectsFlags
956 @param aTypefaceName the typeface name
958 @return the buffer with a text description, used for inclusion in the hash string
960 HBufC* CTLinkedFontsComparison::GenerateTestDescriptionLC(TInt aSize,TUint32 aAttributes, const TPtrC &aTypefaceName, const TDesC &aTestDescription)
962 TBuf<KLengthOfHashValue> tempBuffer;
965 tempBuffer.Append(_L("_"));
966 tempBuffer.Append(aTypefaceName);
967 tempBuffer.Append(_L("_"));
968 tempBuffer.Append(aTestDescription);
969 tempBuffer.Append(_L("_"));
972 tempBuffer.AppendFormat(_L("_size-%d"),aSize);
973 if (aAttributes == 0)
975 //output no attributes
976 tempBuffer.Append(_L("_"));
977 tempBuffer.Append(KFontEffectsFlagsString[0]); //no attributes string
981 for (TInt counter=0;counter<31;counter++)
983 TInt bit = 1<<counter; //1,2,4,8 etc
986 tempBuffer.Append(_L("_"));
987 tempBuffer.Append(KFontEffectsFlagsString[counter+1]);
991 return tempBuffer.AllocLC();
995 @SYMTestCaseID GRAPHICS-FNTSTORE-LINKEDFONTS-0108
999 @SYMREQ REQ10924, REQ10925, REQ10926, REQ10927, REQ10942, REQ10943, REQ10947, REQ10949
1001 @SYMTestCaseDesc This test draws fonts and compares a hash value from the output against
1002 a value stored in a file.
1004 @SYMTestActions The fonts used for this test come from a table, and each font can
1005 be tested with a different output string, size, and creation flag.
1006 The sizes are typically, 10, 20, 35 pixels.
1008 Steps for each font in the test table entry:
1011 (3) For each attribute
1012 (4)Draw the text and compare against the stored hash value
1015 The font creation parameters are typically:
1016 ENoEffect : plain font
1017 EIsUnderlineOn : have underline
1018 EIsStrikethroughOn : have strikethrough
1019 ESetFourColourBlendGlyphBitmap : for shadow and outline
1020 EIsUnderlineOn, EIsStrikethroughOn : both underline and strikethrough
1021 EAlgorithmicBoldOn : algorithmic bold on
1022 EVerticalDraw : vertical text
1023 EVerticalDraw, EIsUnderlineOn : vertical text and underline
1025 If more fonts or attribute combinations are required to be tested, then this should be
1026 achievable by adding table entries.
1028 To produce the hash values the test needs to be run with a special version
1029 of test harness where APPEND_NEW_OR_MISSING_HASH_DATA and SAVEBITMAP macros are defined
1030 in thashreferenceimages.cpp. The saved mbm files should be converted to bitmap
1031 for manual checking.
1033 The fonts used for this tests should have been registered beforehand with
1034 test GRAPHICS-FNTSTORE-LINKEDFONTS-0107.
1036 @SYMTestPriority Critical
1038 @SYMTestStatus Implemented
1040 @SYMTestActions (1) Create the font. Draw text, and compare the hash value against
1041 the value in the file tlinkedfontcomparison.ini. Note that having the same hash
1042 value as the ini file does not necessarily mean that the output is correct.
1044 @SYMTestExpectedResults (1) - font creation succeeds
1045 (4) - the hash values are the same for each text string output
1047 void CTLinkedFontsComparison::TestDrawTextUsingLinkedFontsL()
1049 INFO_PRINTF1(_L("TestDrawTextUsingLinkedFontsL()"));
1051 const TDisplayMode displayMode = EColor16MAP;
1053 CreateBitmapDeviceL(displayMode);
1055 INFO_PRINTF2(_L("Display mode: %S"), &KDisplayModeNames[KSupportDisplayStringIndex[displayMode]]);
1058 TInt numberOfTestsRun=0;
1059 for (TInt testCounter = 0; testCounter< sizeof(KTestCases)/sizeof(TTestCase); testCounter++)
1063 const TInt* ptrSizes = KTestCases[testCounter].iSizes;
1064 for (; *ptrSizes!=0 ;ptrSizes++)
1066 TInt size = *ptrSizes;
1068 // for all the attributes
1069 const TUint32 *ptrAttributes = KTestCases[testCounter].iFontAttributes;
1070 for (;*ptrAttributes!=EEndOfList;ptrAttributes++)
1073 TUint32 attributes = *ptrAttributes;
1075 HBufC* testDescription = GenerateTestDescriptionLC(size,attributes,KTestCases[testCounter].iTypeFaceName,*( KTestCases[testCounter].iTestDecription));
1076 //this function is used for a fuller description
1078 //conversion from HBufC to TPtrC
1079 //need this an an argument to the generate hash id function
1080 TPtrC ptr = TPtrC(testDescription->Des());
1082 //construct a desriptor string, function in hashutility KTestName0001
1083 HBufC* hashIdString = iHashUtil->GenerateHashIdStringLC(
1084 KTestName0001,//general name for test
1085 numberOfTestsRun, //number of sub test
1087 0, //fontFaceIndex, index into the name array above, must be zero
1088 KSupportDisplayStringIndex[static_cast<TInt>(displayMode)],//display mode, converted to text
1089 //in the hash code this is an index to a string table, which is missing ENone and ERgb
1090 attributes //was orientation, but just integer at end, no use attributes
1093 DoTestDrawingOutputL(*hashIdString, KTestCases[testCounter].iTypeFaceName, *(KTestCases[testCounter].iOutputString),
1094 KTestCases[testCounter].iPosition,size,attributes);
1097 CleanupStack::PopAndDestroy(2,testDescription);
1104 Function to create a font, draw the text, and compare the hash value
1106 @param aHashId a string with the hash ID.
1107 @param aFont the font name
1108 @param aOutputString the output string
1109 @param aPosition the position where to draw the text
1110 @param aSize the height of the font in pixels
1111 @param aAttributes the attributes for the font
1112 @see TFontEffectsFlags
1114 void CTLinkedFontsComparison::DoTestDrawingOutputL(const TDesC& aHashId, const TPtrC& aFont, const TDesC& aOutputString,
1115 TPoint aPosition, TInt aSize, TUint32 aAttributes)
1118 PrepareTestEnvironment(fontSpec, aFont, aSize, aAttributes, ETrue, ETrue);
1120 TEST(iBitmapDevice->GetNearestFontToDesignHeightInPixels((CFont*&)font, fontSpec) == KErrNone);
1121 SCleanFont cleanupFont = {iBitmapDevice, font};
1122 CleanupStack::PushL(TCleanupItem(CleanUpFont, &cleanupFont));
1124 //may need to add attributes for the font
1125 CBitmapFont* bitmapFont=CFbsFontEx::FontAddress(static_cast<CFbsFont*>(font));
1126 if (aAttributes& EItalicOn)
1128 bitmapFont->iAlgStyle.SetIsItalic(ETrue);
1130 if (aAttributes& ERegularBoldOn)
1132 bitmapFont->iAlgStyle.SetIsBold(ETrue);
1135 iGc->SetBrushColor(KRgbWhite);
1137 iGc->SetBrushColor(KRgbYellow);
1139 if(EVerticalDraw & aAttributes)
1141 iGc->DrawTextVertical(aOutputString, aPosition, ERotate90Degrees & aAttributes);
1145 iGc->DrawText(aOutputString, aPosition);
1147 iHashUtil->CompareHashValuesL(aHashId);
1148 CleanupStack::Pop();//font
1149 iBitmapDevice->ReleaseFont(font);
1154 Sets the fontspec and gc attributes according to the flags set in STestFontParameters for the test.
1155 Before setting gc attributes it is cleared and reset.
1156 @param aFontSpec holds all effective font settings
1157 @param aSettings holds the flags for setting the fontspec and gc
1158 @param aFontIndex the fonts index of KFontFace to be set as typeface
1159 @param aSetEffects ETrue will set the effects on in fontspec if their flags are enabled. By default it is ETrue.
1160 @param aSetColors ETrue will set the colours in gc from STestFontParameters. By default it is EFalse.
1162 void CTLinkedFontsComparison::PrepareTestEnvironment(TFontSpec &aFontSpec, const TPtrC& aFont, TInt aSize, TUint32 aAttributes,
1163 TBool aSetEffects, TBool aSetColors)
1165 //Set the typeface from the font face array
1166 aFontSpec.iTypeface.iName = aFont;
1167 aFontSpec.iHeight = aSize;
1169 //Set the effects on if any of flags for the effects are set in aSettings and aSetEffects is ETrue
1172 aFontSpec.iFontStyle.SetEffects(FontEffect::EDropShadow, EDropShadowOn & aAttributes);
1173 aFontSpec.iFontStyle.SetEffects(FontEffect::EOutline, EOutlineOn & aAttributes);
1174 aFontSpec.iFontStyle.SetEffects(FontEffect::ESoftEdge, ESoftEdgeOn & aAttributes);
1175 aFontSpec.iFontStyle.SetEffects(FontEffect::EAlgorithmicBold, EAlgorithmicBoldOn & aAttributes);
1180 iGc->SetPenColor(KRgbBlack);
1181 iGc->SetStrikethroughStyle((EIsStrikethroughOn & aAttributes) ? EStrikethroughOn : EStrikethroughOff);
1182 iGc->SetUnderlineStyle((EIsUnderlineOn & aAttributes) ? EUnderlineOn : EUnderlineOff);
1184 //Set the glyph bitmap type
1185 if(ESetMonochromeGlyphBitmap & aAttributes)
1187 aFontSpec.iFontStyle.SetBitmapType(EMonochromeGlyphBitmap);
1189 else if(ESetAntiAliasedGlyphBitmap & aAttributes)
1191 aFontSpec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
1194 //Set the colours in gc if asked for
1197 iGc->SetBrushColor(KRgbYellow);
1198 iGc->SetPenColor(KRgbBlack);
1199 iGc->SetShadowColor(KRgbGray);
1203 /** Function to determine if the rasterizer has the linked typeface extended interface.
1205 @return ETrue if the linked fonts rasterizer is present. EFalse otherwise
1207 TBool CTLinkedFontsComparison::CheckMonoTypeInstalledL()
1209 CreateBitmapDeviceL(EColor16MU); //this is just for the bitmap device to get the font
1211 CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(iBitmapDevice);
1212 CleanupStack::PushL(store);
1214 // Create typeface to be linked
1215 _LIT(KLinkedTypefaceTT, "LinkedFont1TT");
1217 CLinkedTypefaceSpecification *typefaceSpec;
1218 _LIT(KLinkedFont1TTLinkingTest, "LinkedFont1TTLinkingTest");
1220 typefaceSpec = CLinkedTypefaceSpecification::NewLC(KLinkedFont1TTLinkingTest);
1222 CLinkedTypefaceGroup* group1 = CLinkedTypefaceGroup::NewLC(1);
1223 typefaceSpec->AddLinkedTypefaceGroupL(*group1);
1224 CleanupStack::Pop();
1226 // Add first typeface
1227 CLinkedTypefaceElementSpec *elementSpec1;
1228 elementSpec1 = CLinkedTypefaceElementSpec::NewLC(KLinkedTypefaceTT, 1);
1229 elementSpec1->SetCanonical(ETrue);
1231 typefaceSpec->AddTypefaceAtBackL(*elementSpec1);
1232 CleanupStack::Pop(1, elementSpec1);
1234 // Now try regstering the linked typeface
1235 TRAPD(ret, typefaceSpec->RegisterLinkedTypefaceL(*store));
1236 CleanupStack::PopAndDestroy(2, store);
1238 if (ret == KErrNone|| ret== KErrAlreadyExists)
1244 INFO_PRINTF1(_L("Linked fonts comparison: no linked fonts rasterizer found"));
1249 /** regular RunTestCaseL, a virtual function called by the test framework
1251 void CTLinkedFontsComparison::RunTestCaseL(TInt aCurTestCase)
1253 ((CTLinkedFontsComparisonStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1254 switch (aCurTestCase)
1258 ((CTLinkedFontsComparisonStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1259 if (!CheckMonoTypeInstalledL())
1267 ((CTLinkedFontsComparisonStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0107"));
1268 RegisterLinkedTypefacesL();
1273 ((CTLinkedFontsComparisonStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0108"));
1274 TestDrawTextUsingLinkedFontsL();
1279 ((CTLinkedFontsComparisonStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1280 ((CTLinkedFontsComparisonStep*)iStep)->CloseTMSGraphicsStep();
1285 ((CTLinkedFontsComparisonStep*)iStep)->RecordTestResultL();
1288 __CONSTRUCT_STEP__(LinkedFontsComparison)