lafagnosticuifoundation/uigraphicsutils/tef/T_DigitWidth.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file 
       
    18  @internalComponent - Internal Symbian test code  
       
    19 */
       
    20 
       
    21 #include <gdi.h>
       
    22 #include <gulutil.h>
       
    23 #include <bitdev.h>
       
    24 #include <fbs.h>
       
    25 #include "T_DigitWidth.h"
       
    26 
       
    27 CTestFont::CTestFont(CT_DigitWidth* aDigitWidth):iDigitWidth(aDigitWidth)
       
    28 	{
       
    29 	}
       
    30 
       
    31 CTestFont::~CTestFont()
       
    32 	{
       
    33 	}
       
    34 
       
    35 TUid CTestFont::DoTypeUid() const
       
    36 	{
       
    37 	return TUid::Uid(1010);
       
    38 	}
       
    39 
       
    40 TInt CTestFont::DoHeightInPixels() const
       
    41 	{
       
    42 	return 12;
       
    43 	}
       
    44 
       
    45 TInt CTestFont::DoAscentInPixels() const
       
    46 	{
       
    47 	return 10;
       
    48 	}
       
    49 
       
    50 TInt CTestFont::DoCharWidthInPixels(TChar aChar) const
       
    51 	{
       
    52 	switch (aChar)
       
    53 		{
       
    54 	//EDigitTypeWestern = 0x0030
       
    55 	case 0x0030:
       
    56 		return 6;
       
    57 	case 0x0031:
       
    58 		return 6;
       
    59 	case 0x0032:
       
    60 		return 6;
       
    61 	case 0x0033:
       
    62 		return 6;
       
    63 	case 0x0034:
       
    64 		return 6;
       
    65 	case 0x0035:
       
    66 		return 7;  //widest
       
    67 	case 0x0036:
       
    68 		return 6;
       
    69 	case 0x0037:
       
    70 		return 6;
       
    71 	case 0x0038:
       
    72 		return 6;
       
    73 	case 0x0039:
       
    74 		return 6;
       
    75 	//EDigitTypeArabicIndic = 0x0660
       
    76 	case 0x0660:
       
    77 		return 8;
       
    78 	case 0x0661:
       
    79 		return 8;
       
    80 	case 0x0662:
       
    81 		return 9; //widest
       
    82 	case 0x0663:
       
    83 		return 8;
       
    84 	case 0x0664:
       
    85 		return 8;
       
    86 	case 0x0665:
       
    87 		return 8;
       
    88 	case 0x0666:
       
    89 		return 8;
       
    90 	case 0x0667:
       
    91 		return 8;
       
    92 	case 0x0668:
       
    93 		return 8;
       
    94 	case 0x0669:
       
    95 		return 8;
       
    96 	//EDigitTypeEasternArabicIndic = 0x6F0
       
    97 	case 0x06F0:
       
    98 		return 4;
       
    99 	case 0x06F1:
       
   100 		return 4;
       
   101 	case 0x06F2:
       
   102 		return 4;
       
   103 	case 0x06F3:
       
   104 		return 4;
       
   105 	case 0x06F4:
       
   106 		return 4;
       
   107 	case 0x06F5:
       
   108 		return 4;
       
   109 	case 0x06F6:
       
   110 		return 4;
       
   111 	case 0x06F7:
       
   112 		return 4;
       
   113 	case 0x06F8:
       
   114 		return 4;
       
   115 	case 0x06F9:
       
   116 		return 5; //widest
       
   117 	//EDigitTypeDevanagari = 0x0966
       
   118 	case 0x0966:
       
   119 		return 11;//widest
       
   120 	case 0x0967:
       
   121 		return 10;
       
   122 	case 0x0968:
       
   123 		return 10;
       
   124 	case 0x0969:
       
   125 		return 10;
       
   126 	case 0x096A:
       
   127 		return 10;
       
   128 	case 0x096B:
       
   129 		return 10;
       
   130 	case 0x096C:
       
   131 		return 10;
       
   132 	case 0x096D:
       
   133 		return 10;
       
   134 	case 0x096E:
       
   135 		return 10;
       
   136 	case 0x096F:
       
   137 		return 10;
       
   138 	//EDigitTypeThai = 0x0E50
       
   139 	case 0x0E50:
       
   140 		return 15;
       
   141 	case 0x0E51:
       
   142 		return 15;
       
   143 	case 0x0E52:
       
   144 		return 15;
       
   145 	case 0x0E53:
       
   146 		return 15;
       
   147 	case 0x0E54:
       
   148 		return 15;
       
   149 	case 0x0E55:
       
   150 		return 15;
       
   151 	case 0x0E56:
       
   152 		return 15;
       
   153 	case 0x0E57:
       
   154 		return 15;
       
   155 	case 0x0E58:
       
   156 		return 16;//widest
       
   157 	case 0x0E59:
       
   158 		return 15;
       
   159 		}
       
   160 	iDigitWidth->TEST(EFalse);
       
   161 	return 0;
       
   162 	}
       
   163 
       
   164 TInt CTestFont::DoTextWidthInPixels(const TDesC& aText) const
       
   165 	{
       
   166 	TInt total = 0;
       
   167 	const TText* p = aText.Ptr();
       
   168 	const TText* end = p + aText.Length();
       
   169 	for (;p != end; ++p)
       
   170 		total += CharWidthInPixels(*p);
       
   171 	return total;
       
   172 	}
       
   173 
       
   174 TInt CTestFont::DoBaselineOffsetInPixels() const
       
   175 	{
       
   176 	return 10;
       
   177 	}
       
   178 
       
   179 TInt CTestFont::DoTextCount(const TDesC& aText,TInt aWidthInPixels) const
       
   180 	{
       
   181 	TInt excess;
       
   182 	return TextCount(aText, aWidthInPixels, excess);
       
   183 	}
       
   184 
       
   185 TInt CTestFont::DoTextCount(const TDesC& aText,TInt aWidthInPixels,TInt& aExcessWidthInPixels) const
       
   186 	{
       
   187 	aExcessWidthInPixels = aWidthInPixels;
       
   188 	const TText* start = aText.Ptr();
       
   189 	const TText* end = start + aText.Length();
       
   190 	const TText* p = start;
       
   191 	TInt width;
       
   192 	while (p != end
       
   193 		&& (width = CharWidthInPixels(*p)) <= aExcessWidthInPixels)
       
   194 		{
       
   195 		aExcessWidthInPixels -= width;
       
   196 		++p;
       
   197 		}
       
   198 	return p - start;
       
   199 	}
       
   200 
       
   201 TInt CTestFont::DoMaxCharWidthInPixels() const
       
   202 	{
       
   203 	return 10;
       
   204 	}
       
   205 
       
   206 TInt CTestFont::DoMaxNormalCharWidthInPixels() const
       
   207 	{
       
   208 	return 10;
       
   209 	}
       
   210 
       
   211 TFontSpec CTestFont::DoFontSpecInTwips() const
       
   212 	{
       
   213 	return TFontSpec(KTestFontName, 12);
       
   214 	}
       
   215 
       
   216 
       
   217 /*void CTestFont::testResult(TInt aResult)
       
   218 	{
       
   219 	if (aResult==1)
       
   220 		INFO_PRINTF1(_L("test passed\n"));
       
   221 //	else
       
   222 //		INFO_PRINTF1(_L("test failed\n"));
       
   223 	}*/
       
   224 
       
   225 TInt CT_DigitWidth::TestFindWidthOfWidestDigitType(CFont* aFont, TDigitType aDigitType)
       
   226 	{
       
   227 	TFindWidthOfWidestDigitType finder(aDigitType);
       
   228     return finder.MaximumWidthInPixels(*aFont);
       
   229 	}
       
   230 
       
   231 void CT_DigitWidth::TestFontsL()
       
   232 	{
       
   233 	CTestFont font(this);
       
   234 	TFontSpec font_spec = font.FontSpecInTwips();
       
   235 
       
   236 	INFO_PRINTF1(_L("-------------\r\n"));
       
   237 	INFO_PRINTF2(_L("Font: %S\r\n"), &(font_spec.iTypeface.iName));
       
   238 
       
   239 	TInt maxWidth = 0;
       
   240 
       
   241 	maxWidth = TestFindWidthOfWidestDigitType(&font, EDigitTypeWestern);
       
   242 	INFO_PRINTF2(_L("EDigitTypeWestern, MaxWidth=%d\r\n"), maxWidth);
       
   243 	TEST(maxWidth == 7);
       
   244 
       
   245 	maxWidth = TestFindWidthOfWidestDigitType(&font, EDigitTypeArabicIndic);
       
   246 	INFO_PRINTF2(_L("EDigitTypeArabicIndic, MaxWidth=%d\r\n"), maxWidth);
       
   247 	TEST(maxWidth == 9);
       
   248 
       
   249 	maxWidth = TestFindWidthOfWidestDigitType(&font, EDigitTypeEasternArabicIndic);
       
   250 	INFO_PRINTF2(_L("EDigitTypeEasternArabicIndic, MaxWidth=%d\r\n"), maxWidth);
       
   251 	TEST(maxWidth == 5);
       
   252 
       
   253 	maxWidth = TestFindWidthOfWidestDigitType(&font, EDigitTypeDevanagari);
       
   254 	INFO_PRINTF2(_L("EDigitTypeDevanagari, MaxWidth=%d\r\n"), maxWidth);
       
   255 	TEST(maxWidth == 11);
       
   256 
       
   257 	maxWidth = TestFindWidthOfWidestDigitType(&font, EDigitTypeThai);
       
   258 	INFO_PRINTF2(_L("EDigitTypeThai, MaxWidth=%d\r\n"), maxWidth);
       
   259 	TEST(maxWidth == 16);
       
   260 	}
       
   261 
       
   262 void CT_DigitWidth::DoTestsL()
       
   263     {
       
   264 
       
   265 	INFO_PRINTF1(_L("Test WidestDigitType"));
       
   266 	TestFontsL();
       
   267     
       
   268 	}
       
   269 
       
   270 
       
   271 
       
   272 CT_DigitWidth::~CT_DigitWidth()
       
   273 /**
       
   274    Destructor
       
   275  */
       
   276 	{
       
   277 	}
       
   278 
       
   279 
       
   280 CT_DigitWidth::CT_DigitWidth()
       
   281 /**
       
   282    Constructor
       
   283  */
       
   284 	{
       
   285 	// Call base class method to set up the human readable name for logging
       
   286 	SetTestStepName(KT_DigitWidth);
       
   287 	}
       
   288 
       
   289 
       
   290 TVerdict CT_DigitWidth::doTestStepL()
       
   291 {
       
   292 	INFO_PRINTF1(_L("Test Started"));
       
   293 
       
   294 	__UHEAP_MARK;
       
   295 
       
   296 	INFO_PRINTF1(_L("Digit Width"));
       
   297 
       
   298     TRAPD(err, DoTestsL());
       
   299     TEST(err==KErrNone);
       
   300 
       
   301 
       
   302 	INFO_PRINTF1(_L("Test Finished"));
       
   303 
       
   304     __UHEAP_MARKEND;
       
   305 
       
   306 	return TestStepResult();
       
   307 }