os/graphics/graphicsdeviceinterface/directgdi/test/tglyphimagecache.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// This test is designed to run in environment with monotype font support.
sl@0
    15
// To set up environment launch ityperast.cmd  from epoc32\winscw\, and 
sl@0
    16
// then follow instruction on the screen.
sl@0
    17
// 
sl@0
    18
//
sl@0
    19
sl@0
    20
#include "tglyphimagecache.h"
sl@0
    21
#include <graphics/directgdiengine.h>
sl@0
    22
#include <e32base.h>
sl@0
    23
#include <VG/openvg.h>
sl@0
    24
sl@0
    25
// The size of the target in pixels to use for these tests
sl@0
    26
const TSize KGlyphCacheWindowSize(400, 400);
sl@0
    27
sl@0
    28
enum TFontParam
sl@0
    29
	{
sl@0
    30
	ENormal, 
sl@0
    31
	EUnderline = 0x1, 
sl@0
    32
	EStrikeThrough = 0x2,
sl@0
    33
	EBold = 0x4,
sl@0
    34
	EUnderlineBold = 0x5, 
sl@0
    35
	EItalic = 0x8,
sl@0
    36
	EItalicStrikeThrough = 0xa,
sl@0
    37
	};
sl@0
    38
sl@0
    39
class TFontType
sl@0
    40
	{
sl@0
    41
public:
sl@0
    42
	TInt iFontSize;
sl@0
    43
	TFontParam iFontParam;
sl@0
    44
	}; 
sl@0
    45
sl@0
    46
LOCAL_C void CleanCache(TAny* aPtr)
sl@0
    47
	{
sl@0
    48
	MFontGlyphImageStorage* glyphImageStorage = reinterpret_cast<MFontGlyphImageStorage*> (aPtr);
sl@0
    49
	glyphImageStorage->CleanGlyphImageCache();
sl@0
    50
	}
sl@0
    51
sl@0
    52
CTGlyphImageCache::CTGlyphImageCache()
sl@0
    53
	{
sl@0
    54
	SetTestStepName(KTGlyphImageCacheStep);
sl@0
    55
	}
sl@0
    56
sl@0
    57
CTGlyphImageCache::~CTGlyphImageCache()
sl@0
    58
	{
sl@0
    59
	}
sl@0
    60
sl@0
    61
/**
sl@0
    62
@SYMTestCaseID
sl@0
    63
	GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0001
sl@0
    64
sl@0
    65
@SYMPREQ 
sl@0
    66
	PREQ39
sl@0
    67
sl@0
    68
@SYMREQ
sl@0
    69
	REQ9195
sl@0
    70
	REQ9201 
sl@0
    71
	REQ9202 
sl@0
    72
	REQ9222 
sl@0
    73
	REQ9223 
sl@0
    74
	REQ9236 
sl@0
    75
	REQ9237
sl@0
    76
sl@0
    77
@SYMTestCaseDesc
sl@0
    78
	Test requests Glyph Image elements from storage according their Glyph Key.
sl@0
    79
sl@0
    80
@SYMTestStatus
sl@0
    81
	Implemented
sl@0
    82
sl@0
    83
@SYMTestPriority
sl@0
    84
	High
sl@0
    85
sl@0
    86
@SYMTestActions
sl@0
    87
	Create Font Image Storage. In the cycle request aGlyph Image entry for a particular Glyph 
sl@0
    88
	code and a font ID. 
sl@0
    89
	Delete Glyph Storage.
sl@0
    90
	
sl@0
    91
@SYMTestExpectedResults
sl@0
    92
	GlyphImage function must succeed; foreground, shadow and outlined images (if applicable) must be created
sl@0
    93
*/
sl@0
    94
void CTGlyphImageCache::TestRetrieveEntryL(MFontGlyphImageStorage* aGlyphStorage, TGlyphBitmapType aGlyphType)
sl@0
    95
	{
sl@0
    96
	if(!aGlyphStorage)
sl@0
    97
		return;	
sl@0
    98
	_LIT(KTestName, "GlyphCache_RetrieveEntry"); 
sl@0
    99
	if(!iRunningOomTests)
sl@0
   100
		{
sl@0
   101
		INFO_PRINTF1(KTestName);
sl@0
   102
		}
sl@0
   103
sl@0
   104
	TSize size(20, 30);
sl@0
   105
	TInt bufferLength = size.iWidth * size.iHeight;
sl@0
   106
	TUint8* buffer = (TUint8*)User::AllocL(bufferLength);
sl@0
   107
	CleanupStack::PushL(buffer);
sl@0
   108
	if(aGlyphType == EMonochromeGlyphBitmap)
sl@0
   109
		{//to make decoding mechanizm work properly we need to fill the buffer
sl@0
   110
		Mem::Fill(buffer, bufferLength, 0x1);
sl@0
   111
		}
sl@0
   112
	
sl@0
   113
	TInt fontListId[] = 
sl@0
   114
		{
sl@0
   115
		1, 5, 3, 5
sl@0
   116
		};
sl@0
   117
	TInt numFont = sizeof(fontListId) / sizeof(fontListId[0]);
sl@0
   118
	TUint charCodeList[] =
sl@0
   119
		{
sl@0
   120
		1, 2, 3, 2, 3,
sl@0
   121
		};
sl@0
   122
	TInt numGlyphCode = sizeof(charCodeList) / sizeof(charCodeList[0]);
sl@0
   123
sl@0
   124
	for(TInt jj = 0; jj < numFont; jj++)
sl@0
   125
		{
sl@0
   126
		TInt fontId = fontListId[jj];
sl@0
   127
		for(TInt ii = 0; ii < numGlyphCode; ii++)
sl@0
   128
			{
sl@0
   129
			TChar glyphCode = TChar(charCodeList[ii]);
sl@0
   130
			VGImage foregroundImg = VG_INVALID_HANDLE;
sl@0
   131
			VGImage shadowImg = VG_INVALID_HANDLE;
sl@0
   132
			VGImage outlineImg = VG_INVALID_HANDLE;
sl@0
   133
			TBool res = aGlyphStorage->GlyphImage(fontId, glyphCode, aGlyphType, buffer, size, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   134
			TESTNOERROR(res);
sl@0
   135
			if(res != KErrNone)
sl@0
   136
				{
sl@0
   137
				User::Leave(res); 
sl@0
   138
				}
sl@0
   139
			else
sl@0
   140
				{
sl@0
   141
				TEST(foregroundImg);
sl@0
   142
				if(aGlyphType == EFourColourBlendGlyphBitmap)
sl@0
   143
					{
sl@0
   144
					TEST(shadowImg);
sl@0
   145
					TEST(outlineImg);
sl@0
   146
					}
sl@0
   147
				}	
sl@0
   148
			}
sl@0
   149
		}
sl@0
   150
	CleanupStack::PopAndDestroy(buffer);
sl@0
   151
	}
sl@0
   152
sl@0
   153
/**
sl@0
   154
@SYMTestCaseID
sl@0
   155
	GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0002
sl@0
   156
sl@0
   157
@SYMPREQ 
sl@0
   158
	PREQ39
sl@0
   159
sl@0
   160
@SYMREQ
sl@0
   161
	REQ9195
sl@0
   162
	REQ9201 
sl@0
   163
	REQ9202 
sl@0
   164
	REQ9222 
sl@0
   165
	REQ9223 
sl@0
   166
	REQ9236 
sl@0
   167
	REQ9237
sl@0
   168
sl@0
   169
@SYMTestCaseDesc
sl@0
   170
	Drawing monochrome, anti-aliased and four colour fonts with different styles  
sl@0
   171
sl@0
   172
@SYMTestStatus
sl@0
   173
	Implemented
sl@0
   174
sl@0
   175
@SYMTestPriority
sl@0
   176
	High
sl@0
   177
sl@0
   178
@SYMTestActions
sl@0
   179
	Text is output with different effects (strikethrough, underline) and orientation 
sl@0
   180
	(horizontal, vertical up, vertical down) and at different sizes and positions.
sl@0
   181
	Clip region is also specified.
sl@0
   182
sl@0
   183
@SYMTestExpectedResults
sl@0
   184
	Test and reference images must match
sl@0
   185
*/
sl@0
   186
void CTGlyphImageCache::TestDrawGlyphL(MFontGlyphImageStorage* aGlyphStorage, TGlyphBitmapType aGlyphBitmapType, DrawTextDirection aDirection, DrawTextAdjustment aDrawAdjustment, TBool aClipText)
sl@0
   187
	{	
sl@0
   188
	_LIT(KTestNameTemplate, "DrawGlyph%S_Dir%d_Clip%d_Adjust%d"); 
sl@0
   189
	TBuf<128> testName;
sl@0
   190
	_LIT(KTextOutput, "Hello world! Hello world! Hello world! Hello world! Hello world! Hello world!");
sl@0
   191
	
sl@0
   192
	switch(aGlyphBitmapType)
sl@0
   193
		{
sl@0
   194
	case EMonochromeGlyphBitmap:
sl@0
   195
		_LIT(KMonochromeName, "Monochrome");
sl@0
   196
		testName.Format(KTestNameTemplate, &KMonochromeName, aDirection, aClipText, aDrawAdjustment);
sl@0
   197
		break;
sl@0
   198
	case EAntiAliasedGlyphBitmap:
sl@0
   199
		_LIT(KAntiAliasedName, "AntiAliased");
sl@0
   200
		testName.Format(KTestNameTemplate, &KAntiAliasedName, aDirection, aClipText, aDrawAdjustment);
sl@0
   201
		break;
sl@0
   202
	case EFourColourBlendGlyphBitmap:
sl@0
   203
		_LIT(KFourColourName, "FourColour");
sl@0
   204
		testName.Format(KTestNameTemplate, &KFourColourName, aDirection, aClipText, aDrawAdjustment);
sl@0
   205
		break;
sl@0
   206
	default: 
sl@0
   207
		User::Leave(KErrNotSupported);
sl@0
   208
		break;	
sl@0
   209
		}
sl@0
   210
	
sl@0
   211
	if(!iRunningOomTests)
sl@0
   212
		{
sl@0
   213
		INFO_PRINTF1(testName);
sl@0
   214
		}
sl@0
   215
	
sl@0
   216
	ResetGc();
sl@0
   217
	_LIT(KTestFontTypefaceName,"DejaVu Sans Condensed");
sl@0
   218
	const TFontType fontType[] =
sl@0
   219
		{
sl@0
   220
		18, EStrikeThrough, 48, EUnderline, 16, EItalic, 78, EItalicStrikeThrough,
sl@0
   221
sl@0
   222
		18, EStrikeThrough, 48, EUnderlineBold, 16, ENormal, 78, EStrikeThrough, 78, EBold, 
sl@0
   223
		};
sl@0
   224
	
sl@0
   225
	TPoint pt(5, 5);
sl@0
   226
	TInt *coord = & (pt.iY);
sl@0
   227
sl@0
   228
	TSize size = iGdiTarget->SizeInPixels();
sl@0
   229
	TRect rect = size;
sl@0
   230
	rect.Shrink(20, 5);
sl@0
   231
	RRegion region(rect);
sl@0
   232
	TRect rect1;
sl@0
   233
	if(aDirection == EDrawTextHorizontal)
sl@0
   234
		{
sl@0
   235
		rect1 = TRect(size.iWidth / 2 - 40, 40, size.iWidth / 2 + 40, size.iHeight - 40);
sl@0
   236
		}
sl@0
   237
	else
sl@0
   238
		{
sl@0
   239
		rect1 = TRect(20, size.iHeight / 2 - 40, size.iWidth - 20, size.iHeight / 2 + 40);
sl@0
   240
		}	
sl@0
   241
	region.SubRect(rect1);
sl@0
   242
		
sl@0
   243
	if(aDirection == EDrawTextVerticalUp || aDirection == EDrawTextVerticalDown)
sl@0
   244
		{
sl@0
   245
		if(aDirection == EDrawTextVerticalUp)
sl@0
   246
			{
sl@0
   247
			pt.iY = size.iHeight - 5;
sl@0
   248
			}
sl@0
   249
		coord = &(pt.iX);
sl@0
   250
		}
sl@0
   251
	
sl@0
   252
	TInt arraySize = sizeof(fontType) / sizeof(fontType[0]);
sl@0
   253
	
sl@0
   254
	for(TInt ii = 0; ii < arraySize; ii++)
sl@0
   255
		{
sl@0
   256
		CFont *font = NULL;
sl@0
   257
		TFontSpec fspec(KTestFontTypefaceName, fontType[ii].iFontSize);
sl@0
   258
		fspec.iFontStyle.SetBitmapType(aGlyphBitmapType);
sl@0
   259
		
sl@0
   260
		iGc->Reset();
sl@0
   261
sl@0
   262
		if(aClipText)
sl@0
   263
			{
sl@0
   264
			iGc->SetClippingRegion(region);
sl@0
   265
			}
sl@0
   266
sl@0
   267
		if(aGlyphBitmapType == EFourColourBlendGlyphBitmap)
sl@0
   268
			{
sl@0
   269
			fspec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
sl@0
   270
			fspec.iFontStyle.SetEffects(FontEffect::EOutline, ETrue);
sl@0
   271
			fspec.iFontStyle.SetEffects(FontEffect::EDropShadow, ETrue);
sl@0
   272
			TRgb shadowColor = TRgb(0, 0, 255);
sl@0
   273
			iGc->SetTextShadowColor(shadowColor);
sl@0
   274
			TEST(shadowColor == iGc->TextShadowColor());
sl@0
   275
			iGc->SetBrushColor(TRgb(255, 0, 0));
sl@0
   276
			TEST(TRgb(255, 0, 0) == iGc->BrushColor());
sl@0
   277
			}
sl@0
   278
		else
sl@0
   279
			{
sl@0
   280
			iGc->SetBrushStyle(DirectGdi::ENullBrush);
sl@0
   281
			iGc->SetPenStyle(DirectGdi::ESolidPen);
sl@0
   282
			}	
sl@0
   283
		iGc->SetPenColor(TRgb(0, 255, 0));
sl@0
   284
		if(fontType[ii].iFontParam & EItalic)
sl@0
   285
			{
sl@0
   286
			fspec.iFontStyle.SetPosture(EPostureItalic);
sl@0
   287
			}
sl@0
   288
		if(fontType[ii].iFontParam & EBold)
sl@0
   289
			{
sl@0
   290
			fspec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
sl@0
   291
			}
sl@0
   292
			
sl@0
   293
		User::LeaveIfError(iFontStore->GetNearestFontToDesignHeightInPixels((CFont*&) font, fspec));
sl@0
   294
		if(iUseDirectGdi)
sl@0
   295
			{
sl@0
   296
			if(ii == 2)
sl@0
   297
				{
sl@0
   298
				iGc->SetFontNoDuplicate(font);
sl@0
   299
				(reinterpret_cast <CTestDirectGdiContext*> (iGc))->NoJustifyAutoUpdate();
sl@0
   300
				}
sl@0
   301
			else
sl@0
   302
				{
sl@0
   303
				iGc->SetFont(font);
sl@0
   304
				iGc->SetFontNoDuplicate(font);//shoudn't have any impact
sl@0
   305
				(reinterpret_cast <CTestDirectGdiContext*> (iGc))->SetJustifyAutoUpdate();
sl@0
   306
				}	
sl@0
   307
			}
sl@0
   308
		else
sl@0
   309
			{
sl@0
   310
			iGc->SetFont(font);
sl@0
   311
			iGc->SetFontNoDuplicate(font);//shoudn't have any impact
sl@0
   312
			}	
sl@0
   313
		TEST(iGc->HasFont());
sl@0
   314
		
sl@0
   315
		TFontSpec fontSpec = font->FontSpecInTwips();
sl@0
   316
		TGlyphBitmapType glyphBitmapType = fontSpec.iFontStyle.BitmapType();
sl@0
   317
sl@0
   318
		TEST(glyphBitmapType == aGlyphBitmapType);	
sl@0
   319
		if(fontType[ii].iFontParam & EUnderline)
sl@0
   320
			{
sl@0
   321
			iGc->SetUnderlineStyle(DirectGdi::EUnderlineOn);
sl@0
   322
			}
sl@0
   323
		else if(fontType[ii].iFontParam & EStrikeThrough)
sl@0
   324
			{
sl@0
   325
			iGc->SetStrikethroughStyle(DirectGdi::EStrikethroughOn);
sl@0
   326
			}
sl@0
   327
		
sl@0
   328
		if(EDrawTextVerticalDown != aDirection)
sl@0
   329
			{
sl@0
   330
			*coord += font->HeightInPixels() + 5;
sl@0
   331
			}
sl@0
   332
		
sl@0
   333
		if(aGlyphStorage && (ii == 0) && (arraySize > 1))
sl@0
   334
			{
sl@0
   335
			aGlyphStorage->CleanGlyphImageCache();
sl@0
   336
			aGlyphStorage->EnforceOOMFailure(ETrue);
sl@0
   337
			}
sl@0
   338
		DrawText(KTextOutput, pt, aDirection, aDrawAdjustment, ii == 1);
sl@0
   339
		if(aGlyphStorage)
sl@0
   340
			{
sl@0
   341
			aGlyphStorage->EnforceOOMFailure(EFalse);
sl@0
   342
			}
sl@0
   343
		
sl@0
   344
		if(EDrawTextVerticalDown == aDirection)
sl@0
   345
			{
sl@0
   346
			*coord += font->HeightInPixels() + 5;
sl@0
   347
			}
sl@0
   348
sl@0
   349
		if(fontType[ii].iFontParam == ENormal)
sl@0
   350
			{
sl@0
   351
			iGc->SetUnderlineStyle(DirectGdi::EUnderlineOff);
sl@0
   352
			iGc->SetStrikethroughStyle(DirectGdi::EStrikethroughOff);
sl@0
   353
			}
sl@0
   354
		iGc->ResetFont();
sl@0
   355
		iFontStore->ReleaseFont(font);
sl@0
   356
	
sl@0
   357
		TEST(!iGc->HasFont());
sl@0
   358
		}
sl@0
   359
	region.Close();
sl@0
   360
	if(aClipText)
sl@0
   361
		{
sl@0
   362
		iGc->ResetClippingRegion();
sl@0
   363
		}
sl@0
   364
sl@0
   365
	// Write the output to file.
sl@0
   366
	//
sl@0
   367
	TESTNOERROR(WriteTargetOutput(iTestParams, testName));
sl@0
   368
	}
sl@0
   369
sl@0
   370
/**
sl@0
   371
@SYMTestCaseID
sl@0
   372
	GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0003
sl@0
   373
sl@0
   374
@SYMPREQ 
sl@0
   375
	PREQ39
sl@0
   376
sl@0
   377
@SYMREQ
sl@0
   378
	REQ9195
sl@0
   379
	REQ9201 
sl@0
   380
	REQ9202 
sl@0
   381
	REQ9222 
sl@0
   382
	REQ9223 
sl@0
   383
	REQ9236 
sl@0
   384
	REQ9237
sl@0
   385
sl@0
   386
@SYMTestCaseDesc
sl@0
   387
	Filling up the glyph image cache
sl@0
   388
sl@0
   389
@SYMTestStatus
sl@0
   390
	Implemented
sl@0
   391
sl@0
   392
@SYMTestPriority
sl@0
   393
	High
sl@0
   394
sl@0
   395
@SYMTestActions
sl@0
   396
	1.	Fill glyph image storage with the same font but different glyphs until it exceeds its limit and resets the cache.
sl@0
   397
	Repeat this operation for other glyph types
sl@0
   398
sl@0
   399
	2.	Fill glyph image storage with different font and different glyph codes
sl@0
   400
sl@0
   401
@SYMTestExpectedResults
sl@0
   402
	Check that Glyph cache storage increments cache size correctly and deletes the least 
sl@0
   403
	usable tree.
sl@0
   404
*/
sl@0
   405
void CTGlyphImageCache::FillUpCacheL(MFontGlyphImageStorage* aGlyphStorage)
sl@0
   406
	{
sl@0
   407
	if(!aGlyphStorage)
sl@0
   408
		return;
sl@0
   409
	
sl@0
   410
	aGlyphStorage->CleanGlyphImageCache();
sl@0
   411
	TBuf<128> testName;
sl@0
   412
	_LIT(KTestName, "GlyphCache_FillUpCache"); 
sl@0
   413
	if(!iRunningOomTests)
sl@0
   414
		{
sl@0
   415
		INFO_PRINTF1(KTestName);
sl@0
   416
		}
sl@0
   417
	
sl@0
   418
	const TSize size(12, 16);
sl@0
   419
	TUint8* buffer = (TUint8*)User::AllocL(size.iWidth * size.iHeight);
sl@0
   420
	CleanupStack::PushL(buffer);
sl@0
   421
	TInt fontId = 10;
sl@0
   422
	TGlyphBitmapType glyphTypeList[] = 
sl@0
   423
		{
sl@0
   424
		EMonochromeGlyphBitmap,
sl@0
   425
		EAntiAliasedGlyphBitmap,
sl@0
   426
		EFourColourBlendGlyphBitmap,
sl@0
   427
		};
sl@0
   428
	const TInt numGlyphType = sizeof(glyphTypeList) / sizeof(glyphTypeList[0]);
sl@0
   429
	TESTL(aGlyphStorage->GlyphCacheSize() == 0);
sl@0
   430
	
sl@0
   431
	TInt glyphSizeInByte = 0;
sl@0
   432
	TInt expectedSize = 0;
sl@0
   433
	TUint32 glyphCode = 1;
sl@0
   434
	
sl@0
   435
	VGImage foregroundImg = VG_INVALID_HANDLE;
sl@0
   436
	VGImage shadowImg = VG_INVALID_HANDLE;
sl@0
   437
	VGImage outlineImg = VG_INVALID_HANDLE;
sl@0
   438
	for(TInt ii = 0; ii < numGlyphType; ii++)
sl@0
   439
		{
sl@0
   440
		TGlyphBitmapType glyphType = glyphTypeList[ii];
sl@0
   441
		//calculate the actual size of the glyph
sl@0
   442
		glyphSizeInByte = GlyphImageSizeInByte(glyphType, size);
sl@0
   443
sl@0
   444
		TUint maxGlyphSize = aGlyphStorage->MaxGlyphCacheSize() + glyphSizeInByte;
sl@0
   445
		do 
sl@0
   446
			{
sl@0
   447
			TEST(expectedSize == aGlyphStorage->GlyphCacheSize());
sl@0
   448
			TBool res = aGlyphStorage->GlyphImage(fontId, TChar(glyphCode), (TGlyphBitmapType)glyphType, buffer, size, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   449
			TESTNOERRORL(res);
sl@0
   450
			glyphCode++;
sl@0
   451
			expectedSize+= glyphSizeInByte; 
sl@0
   452
			foregroundImg = VG_INVALID_HANDLE;
sl@0
   453
			shadowImg = VG_INVALID_HANDLE;
sl@0
   454
			outlineImg = VG_INVALID_HANDLE;
sl@0
   455
			}while(expectedSize <= maxGlyphSize);
sl@0
   456
		glyphCode = 1;	
sl@0
   457
		expectedSize = 0;
sl@0
   458
		TEST(glyphSizeInByte == aGlyphStorage->GlyphCacheSize());
sl@0
   459
		aGlyphStorage->CleanGlyphImageCache();
sl@0
   460
		}
sl@0
   461
		
sl@0
   462
	//now try to filling cache with different fonts and check that last usable font wont be removed
sl@0
   463
	TUint maxGlyphSize = aGlyphStorage->MaxGlyphCacheSize();
sl@0
   464
	glyphSizeInByte = GlyphImageSizeInByte(EMonochromeGlyphBitmap, size);
sl@0
   465
	do 
sl@0
   466
		{
sl@0
   467
		TEST(expectedSize == aGlyphStorage->GlyphCacheSize());
sl@0
   468
		TBool res = aGlyphStorage->GlyphImage(fontId, TChar(glyphCode), EMonochromeGlyphBitmap, buffer, size, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   469
		TESTNOERRORL(res);
sl@0
   470
		glyphCode++;
sl@0
   471
		expectedSize+= glyphSizeInByte; 
sl@0
   472
		foregroundImg = VG_INVALID_HANDLE;
sl@0
   473
		shadowImg = VG_INVALID_HANDLE;
sl@0
   474
		outlineImg = VG_INVALID_HANDLE;
sl@0
   475
		}while(expectedSize <= maxGlyphSize);
sl@0
   476
sl@0
   477
	fontId += 10;
sl@0
   478
	glyphCode = 1;
sl@0
   479
sl@0
   480
	TBool res = aGlyphStorage->GlyphImage(fontId, TChar(glyphCode), EMonochromeGlyphBitmap, buffer, size, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   481
	TEST(glyphSizeInByte == aGlyphStorage->GlyphCacheSize());
sl@0
   482
	TESTNOERROR(res);
sl@0
   483
	
sl@0
   484
	RArray<TUint32> listFontId;
sl@0
   485
	aGlyphStorage->FontIdInOrder(listFontId);
sl@0
   486
	TESTL(listFontId.Count() == 1);
sl@0
   487
	TEST(listFontId[0] == fontId);
sl@0
   488
	listFontId.Reset();
sl@0
   489
	
sl@0
   490
	CleanupStack::PopAndDestroy(buffer);
sl@0
   491
	}
sl@0
   492
sl@0
   493
/**
sl@0
   494
@SYMTestCaseID
sl@0
   495
	GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0004
sl@0
   496
sl@0
   497
@SYMPREQ 
sl@0
   498
	PREQ39
sl@0
   499
sl@0
   500
@SYMREQ
sl@0
   501
	REQ9195
sl@0
   502
	REQ9201 
sl@0
   503
	REQ9202 
sl@0
   504
	REQ9222 
sl@0
   505
	REQ9223 
sl@0
   506
	REQ9236 
sl@0
   507
	REQ9237
sl@0
   508
sl@0
   509
@SYMTestCaseDesc
sl@0
   510
	Tests filling the glyph image cache with different glyph images
sl@0
   511
sl@0
   512
@SYMTestStatus
sl@0
   513
	Implemented
sl@0
   514
sl@0
   515
@SYMTestPriority
sl@0
   516
	High
sl@0
   517
sl@0
   518
@SYMTestActions
sl@0
   519
	Specify glyphs which correspond to different fonts, glyph codes.
sl@0
   520
	Request related VGImages.
sl@0
   521
	Test the cache size is correct after each operation.
sl@0
   522
	Get the driver's MDirectGdiDriverCacheSize interface.
sl@0
   523
	Attempt to set the maximum size of the glyph cache to a size smaller than
sl@0
   524
	the existing cache size.
sl@0
   525
	Attempt to set the maximum size of the glyph cache to a size the same as
sl@0
   526
	the existing cache size.
sl@0
   527
	
sl@0
   528
sl@0
   529
@SYMTestExpectedResults
sl@0
   530
	Obtained glyph code and cache size must be correct each time.
sl@0
   531
	Setting the maximum glyph cache size to a smaller size than the existing cache
sl@0
   532
	size should fail with error KErrArgument.
sl@0
   533
	Setting the maximum glyph cache size to a size the same as the existing cache
sl@0
   534
	size should pass.
sl@0
   535
*/
sl@0
   536
void CTGlyphImageCache::FillCacheL(MFontGlyphImageStorage* aGlyphStorage)
sl@0
   537
	{
sl@0
   538
	ASSERT(aGlyphStorage);		
sl@0
   539
	
sl@0
   540
	aGlyphStorage->CleanGlyphImageCache();
sl@0
   541
	TBuf<128> testName;
sl@0
   542
	_LIT(KTestName, "GlyphCache_FillCache"); 
sl@0
   543
	if(!iRunningOomTests)
sl@0
   544
		{
sl@0
   545
		INFO_PRINTF1(KTestName);
sl@0
   546
		}
sl@0
   547
	
sl@0
   548
	const TSize smallFontSize = TSize(12, 16);
sl@0
   549
	const TSize smallFont1Size = TSize(10, 14);
sl@0
   550
	const TSize bigFontSize = TSize(18, 24);
sl@0
   551
	const TSize bigFont1Size = TSize(20, 26);
sl@0
   552
	const TInt smallFontId = 10;
sl@0
   553
	const TInt bigFontId = 20;
sl@0
   554
	const TInt smallFont1Id = 30;
sl@0
   555
	const TInt bigFont1Id = 40;
sl@0
   556
	VGImage foregroundImg = VG_INVALID_HANDLE;
sl@0
   557
	VGImage shadowImg = VG_INVALID_HANDLE;
sl@0
   558
	VGImage outlineImg = VG_INVALID_HANDLE;
sl@0
   559
	
sl@0
   560
	TUint8* buffer = (TUint8*)User::AllocL(bigFontSize.iWidth * bigFontSize.iHeight);
sl@0
   561
	CleanupStack::PushL(buffer);
sl@0
   562
	TESTL(aGlyphStorage->GlyphCacheSize() == 0);
sl@0
   563
	
sl@0
   564
	TInt expectedCacheSize = 0;
sl@0
   565
	TChar glyphCode = TChar(1);
sl@0
   566
	TGlyphBitmapType glyphType = EMonochromeGlyphBitmap;
sl@0
   567
	TBool res = aGlyphStorage->GlyphImage(smallFontId, glyphCode, glyphType, buffer, smallFontSize, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   568
	TESTNOERRORL(res);
sl@0
   569
	expectedCacheSize = GlyphImageSizeInByte(glyphType, smallFontSize);
sl@0
   570
	TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize());
sl@0
   571
sl@0
   572
	//try to retrieve the same glyph
sl@0
   573
	res = aGlyphStorage->GlyphImage(smallFontId, glyphCode, glyphType, buffer, smallFontSize, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   574
	TESTNOERRORL(res);
sl@0
   575
	//the size should be the same
sl@0
   576
	TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize()); 
sl@0
   577
		
sl@0
   578
	//now retrieving the same glyphCode but for the different font
sl@0
   579
	res = aGlyphStorage->GlyphImage(bigFontId, glyphCode, glyphType, buffer, bigFontSize, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   580
	TESTNOERRORL(res);
sl@0
   581
	expectedCacheSize += GlyphImageSizeInByte(glyphType, bigFontSize);
sl@0
   582
	TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize()); 
sl@0
   583
sl@0
   584
	//last font but different glyphCode
sl@0
   585
	glyphCode = TChar(2);
sl@0
   586
	res = aGlyphStorage->GlyphImage(bigFontId, glyphCode, glyphType, buffer, bigFontSize, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   587
	TESTNOERRORL(res);
sl@0
   588
	expectedCacheSize += GlyphImageSizeInByte(glyphType, bigFontSize);
sl@0
   589
	TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize()); 
sl@0
   590
sl@0
   591
	//small font and last glyphCode
sl@0
   592
	res = aGlyphStorage->GlyphImage(smallFontId, glyphCode, glyphType, buffer, smallFontSize, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   593
	TESTNOERRORL(res);
sl@0
   594
	expectedCacheSize += GlyphImageSizeInByte(glyphType, smallFontSize);
sl@0
   595
	TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize()); 
sl@0
   596
sl@0
   597
	//now change the type
sl@0
   598
	glyphType = EAntiAliasedGlyphBitmap;
sl@0
   599
	res = aGlyphStorage->GlyphImage(smallFont1Id, glyphCode, glyphType, buffer, smallFont1Size, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   600
	TESTNOERRORL(res);
sl@0
   601
	expectedCacheSize += GlyphImageSizeInByte(glyphType, smallFont1Size);
sl@0
   602
	TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize()); 
sl@0
   603
	//try again
sl@0
   604
	res = aGlyphStorage->GlyphImage(smallFont1Id, glyphCode, glyphType, buffer, smallFont1Size, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   605
	TESTNOERRORL(res);
sl@0
   606
	TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize()); 
sl@0
   607
sl@0
   608
	//now change the type again
sl@0
   609
	glyphType = EFourColourBlendGlyphBitmap;
sl@0
   610
	res = aGlyphStorage->GlyphImage(bigFont1Id, glyphCode, glyphType, buffer, bigFont1Size, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   611
	TESTNOERRORL(res);
sl@0
   612
	expectedCacheSize += GlyphImageSizeInByte(glyphType, bigFont1Size);
sl@0
   613
	TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize()); 
sl@0
   614
sl@0
   615
	//using initial value.
sl@0
   616
	glyphType = EMonochromeGlyphBitmap;
sl@0
   617
	glyphCode = TChar(1);
sl@0
   618
	res = aGlyphStorage->GlyphImage(smallFontId, glyphCode, glyphType, buffer, smallFontSize, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   619
	TESTNOERRORL(res);
sl@0
   620
	TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize());
sl@0
   621
	
sl@0
   622
	//get the driver's MDirectGdiDriverCacheSize extension interface and attempt
sl@0
   623
	//to set the maximum cache size to be smaller than the existing cache size
sl@0
   624
	CDirectGdiDriver* driver = CDirectGdiDriver::Static();
sl@0
   625
	TESTL(driver != NULL);
sl@0
   626
	MDirectGdiDriverCacheSize* driverCacheSize = NULL;
sl@0
   627
	res = driver->GetInterface(TUid::Uid(KDirectGdiDriverCacheSizeUid), (TAny*&)driverCacheSize);
sl@0
   628
	TESTNOERRORL(res);
sl@0
   629
	//save the original cache size
sl@0
   630
	TInt originalCacheSize = driverCacheSize->MaxGlyphCacheSize();
sl@0
   631
	//setting the cache size to a size smaller than the existing cache should fail
sl@0
   632
	res = driverCacheSize->SetMaxGlyphCacheSize(aGlyphStorage->GlyphCacheSize()-1);
sl@0
   633
	TEST(res == KErrArgument);	
sl@0
   634
	//setting the cache size to the same size as the existing cache should pass
sl@0
   635
	res = driverCacheSize->SetMaxGlyphCacheSize(aGlyphStorage->GlyphCacheSize());
sl@0
   636
	TESTNOERROR(res);
sl@0
   637
	TEST(aGlyphStorage->GlyphCacheSize() == driverCacheSize->MaxGlyphCacheSize());
sl@0
   638
	//reset the original driver cache size
sl@0
   639
	res = driverCacheSize->SetMaxGlyphCacheSize(originalCacheSize);
sl@0
   640
	TESTNOERROR(res);
sl@0
   641
	
sl@0
   642
	CleanupStack::PopAndDestroy(buffer);
sl@0
   643
	}
sl@0
   644
sl@0
   645
/**
sl@0
   646
@SYMTestCaseID
sl@0
   647
	GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0005
sl@0
   648
sl@0
   649
@SYMPREQ 
sl@0
   650
	PREQ39
sl@0
   651
sl@0
   652
@SYMREQ
sl@0
   653
	REQ9195
sl@0
   654
	REQ9201 
sl@0
   655
	REQ9202 
sl@0
   656
	REQ9222 
sl@0
   657
	REQ9223 
sl@0
   658
	REQ9236 
sl@0
   659
	REQ9237
sl@0
   660
sl@0
   661
@SYMTestCaseDesc
sl@0
   662
	Tests the ordering font IDs in the glyph image cache.
sl@0
   663
sl@0
   664
@SYMTestStatus
sl@0
   665
	Implemented
sl@0
   666
sl@0
   667
@SYMTestPriority
sl@0
   668
	High
sl@0
   669
sl@0
   670
@SYMTestActions
sl@0
   671
	Request glyph images for different fonts.
sl@0
   672
sl@0
   673
@SYMTestExpectedResults
sl@0
   674
	List of glyph cache trees must be arranged in order from most used to least used.
sl@0
   675
*/
sl@0
   676
void CTGlyphImageCache::FontListIdOrderL(MFontGlyphImageStorage* aGlyphStorage)
sl@0
   677
	{
sl@0
   678
	if(!aGlyphStorage)
sl@0
   679
		return;
sl@0
   680
	
sl@0
   681
	aGlyphStorage->CleanGlyphImageCache();
sl@0
   682
	TBuf<128> testName;
sl@0
   683
	_LIT(KTestName, "GlyphCache_FontListIdOrder"); 
sl@0
   684
	if(!iRunningOomTests)
sl@0
   685
		{
sl@0
   686
		INFO_PRINTF1(KTestName);
sl@0
   687
		}
sl@0
   688
	
sl@0
   689
	const TSize fontSize = TSize(12, 16);
sl@0
   690
	TUint8* buffer = (TUint8*)User::AllocL(fontSize.iWidth * fontSize.iHeight);
sl@0
   691
	CleanupStack::PushL(buffer);
sl@0
   692
sl@0
   693
	TChar glyphCode = TChar(10);
sl@0
   694
	TInt fontId = 10;
sl@0
   695
	VGImage foregroundImg = VG_INVALID_HANDLE;
sl@0
   696
	VGImage shadowImg = VG_INVALID_HANDLE;
sl@0
   697
	VGImage outlineImg = VG_INVALID_HANDLE;
sl@0
   698
	
sl@0
   699
	TGlyphBitmapType glyphType = EMonochromeGlyphBitmap;
sl@0
   700
	TInt res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   701
	TESTNOERRORL(res);
sl@0
   702
sl@0
   703
	fontId = 20;
sl@0
   704
	res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   705
	TESTNOERRORL(res);
sl@0
   706
sl@0
   707
	fontId = 30;
sl@0
   708
	res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   709
	TESTNOERRORL(res);
sl@0
   710
sl@0
   711
	RArray<TUint32> fontListId;
sl@0
   712
	res = aGlyphStorage->FontIdInOrder(fontListId);
sl@0
   713
	if(res != KErrNone)
sl@0
   714
		{
sl@0
   715
		fontListId.Reset();
sl@0
   716
		User::Leave(res);
sl@0
   717
		}
sl@0
   718
	
sl@0
   719
	TESTL(fontListId.Count() == 3);
sl@0
   720
	TEST(fontListId[0] == 30);
sl@0
   721
	TEST(fontListId[1] == 20);
sl@0
   722
	TEST(fontListId[2] == 10);
sl@0
   723
	fontListId.Reset();
sl@0
   724
sl@0
   725
	//call entries again to reorder font id list
sl@0
   726
	fontId = 30;
sl@0
   727
	res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   728
	TESTNOERRORL(res);
sl@0
   729
	
sl@0
   730
	fontId = 20;
sl@0
   731
	res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   732
	TESTNOERRORL(res);
sl@0
   733
sl@0
   734
	fontId = 40;
sl@0
   735
	res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   736
	TESTNOERRORL(res);
sl@0
   737
sl@0
   738
	fontId = 10;
sl@0
   739
	res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   740
	TESTNOERRORL(res);
sl@0
   741
sl@0
   742
	fontId = 50;
sl@0
   743
	res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   744
	TESTNOERRORL(res);
sl@0
   745
sl@0
   746
	res = aGlyphStorage->FontIdInOrder(fontListId);
sl@0
   747
	if(res != KErrNone)
sl@0
   748
		{
sl@0
   749
		fontListId.Reset();
sl@0
   750
		User::Leave(res);
sl@0
   751
		}
sl@0
   752
sl@0
   753
	TESTL(fontListId.Count() == 5);
sl@0
   754
	TEST(fontListId[0] == 50);
sl@0
   755
	TEST(fontListId[1] == 10);
sl@0
   756
	TEST(fontListId[2] == 40);
sl@0
   757
	TEST(fontListId[3] == 20);
sl@0
   758
	TEST(fontListId[4] == 30);
sl@0
   759
	fontListId.Reset();
sl@0
   760
sl@0
   761
	CleanupStack::PopAndDestroy(buffer);
sl@0
   762
	}
sl@0
   763
sl@0
   764
/**
sl@0
   765
@SYMTestCaseID
sl@0
   766
	GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0006
sl@0
   767
sl@0
   768
@SYMPREQ 
sl@0
   769
	PREQ39
sl@0
   770
sl@0
   771
@SYMREQ
sl@0
   772
	REQ9195
sl@0
   773
	REQ9222 
sl@0
   774
	REQ9223 
sl@0
   775
	REQ9236 
sl@0
   776
	REQ9237
sl@0
   777
sl@0
   778
@SYMTestCaseDesc
sl@0
   779
	Test the operation of the glyph image cache when sent wrong parameters.
sl@0
   780
sl@0
   781
@SYMTestStatus
sl@0
   782
	Implemented
sl@0
   783
sl@0
   784
@SYMTestPriority
sl@0
   785
	High
sl@0
   786
sl@0
   787
@SYMTestActions
sl@0
   788
	Test requesting of glyph images with invalid paramaters - test an invalid glyph type
sl@0
   789
	and test requesting a glyph image with zero height and one with zero width.
sl@0
   790
sl@0
   791
@SYMTestExpectedResults
sl@0
   792
	The function must identify wrong arguments and return the expected error.
sl@0
   793
*/
sl@0
   794
void CTGlyphImageCache::WrongParameterL(MFontGlyphImageStorage* aGlyphStorage)
sl@0
   795
	{
sl@0
   796
	_LIT(KTestName, "GlyphCache_WrongParameters"); 
sl@0
   797
	if(!iRunningOomTests)
sl@0
   798
		{
sl@0
   799
		INFO_PRINTF1(KTestName);
sl@0
   800
		}
sl@0
   801
	
sl@0
   802
	aGlyphStorage->CleanGlyphImageCache();
sl@0
   803
sl@0
   804
	TChar glyphCode = TChar(10);
sl@0
   805
	TInt fontId = 10;
sl@0
   806
	VGImage foregroundImg = VG_INVALID_HANDLE;
sl@0
   807
	VGImage shadowImg = VG_INVALID_HANDLE;
sl@0
   808
	VGImage outlineImg = VG_INVALID_HANDLE;
sl@0
   809
	TSize fontSize = TSize(10, 12);
sl@0
   810
	TUint8* buffer = (TUint8*)User::AllocL(fontSize.iWidth * fontSize.iHeight);
sl@0
   811
	CleanupStack::PushL(buffer);
sl@0
   812
sl@0
   813
	TGlyphBitmapType glyphType = EDefaultGlyphBitmap; // unsupported
sl@0
   814
	
sl@0
   815
	TInt res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
sl@0
   816
	TEST(res == KErrNotSupported);
sl@0
   817
	TEST(foregroundImg == VG_INVALID_HANDLE);
sl@0
   818
	TEST(shadowImg == VG_INVALID_HANDLE);
sl@0
   819
	TEST(outlineImg == VG_INVALID_HANDLE);
sl@0
   820
	
sl@0
   821
	glyphType = EMonochromeGlyphBitmap; // supported
sl@0
   822
	res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, TSize(12, 0), &foregroundImg, &shadowImg, &outlineImg);
sl@0
   823
	TEST(res == KErrArgument);
sl@0
   824
	res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, TSize(0, 12), &foregroundImg, &shadowImg, &outlineImg);
sl@0
   825
	TEST(res == KErrArgument);
sl@0
   826
	TEST(foregroundImg == VG_INVALID_HANDLE);
sl@0
   827
	TEST(shadowImg == VG_INVALID_HANDLE);
sl@0
   828
	TEST(outlineImg == VG_INVALID_HANDLE);
sl@0
   829
sl@0
   830
	CleanupStack::PopAndDestroy(buffer);
sl@0
   831
	}
sl@0
   832
sl@0
   833
TInt CTGlyphImageCache::GlyphImageSizeInByte(TGlyphBitmapType aGlyphType, const TSize& aSize) const
sl@0
   834
	{
sl@0
   835
	TInt glyphSizeInByte = 0;	
sl@0
   836
		//calculate the actual size of the glyph
sl@0
   837
	switch(aGlyphType)
sl@0
   838
		{
sl@0
   839
	case EMonochromeGlyphBitmap:
sl@0
   840
		glyphSizeInByte = (((aSize.iWidth + 31) / 32) << 2) * aSize.iHeight;
sl@0
   841
		break;
sl@0
   842
	case EAntiAliasedGlyphBitmap:
sl@0
   843
		glyphSizeInByte = aSize.iWidth * aSize.iHeight;
sl@0
   844
		break;
sl@0
   845
	case EFourColourBlendGlyphBitmap:
sl@0
   846
		glyphSizeInByte = aSize.iWidth * aSize.iHeight;
sl@0
   847
		//we have to allocate memory for shadow and outline bitmap as well
sl@0
   848
		glyphSizeInByte *= 3;
sl@0
   849
		break;
sl@0
   850
	default :
sl@0
   851
		break;
sl@0
   852
		}
sl@0
   853
	return glyphSizeInByte;
sl@0
   854
	}
sl@0
   855
/**
sl@0
   856
Draws the text on the screen according its direction and alignment.
sl@0
   857
*/	
sl@0
   858
void CTGlyphImageCache::DrawText(const TDesC& aText, const TPoint& aPt, DrawTextDirection aDirection, DrawTextAdjustment aDrawAdjustment, TBool aUpdateJustification)
sl@0
   859
	{
sl@0
   860
	const TSize size = iGdiTarget->SizeInPixels();
sl@0
   861
	TRect rect = size;
sl@0
   862
	
sl@0
   863
	if(aDirection == EDrawTextHorizontal)
sl@0
   864
		{
sl@0
   865
		switch(aDrawAdjustment)
sl@0
   866
			{
sl@0
   867
		case EDrawFromPoint:
sl@0
   868
			iGc->DrawText(aText, NULL, aPt);
sl@0
   869
			break;
sl@0
   870
		case EDrawInBox:
sl@0
   871
			iGc->SetOrigin(aPt);
sl@0
   872
			rect = TRect(-aPt, size);
sl@0
   873
			iGc->DrawText(aText, NULL, rect);
sl@0
   874
			break;
sl@0
   875
		case EDrawRightAlignment:
sl@0
   876
			rect.iTl = aPt;
sl@0
   877
			rect.iBr.iX -= 30;
sl@0
   878
			iGc->DrawText(aText, NULL, rect, 0, DirectGdi::ERight);
sl@0
   879
			break;
sl@0
   880
			}
sl@0
   881
		}
sl@0
   882
	else if ((aDirection == EDrawTextVerticalDown) || (aDirection == EDrawTextVerticalUp))
sl@0
   883
		{
sl@0
   884
		TBool up = (aDirection==EDrawTextVerticalUp);
sl@0
   885
		switch(aDrawAdjustment)
sl@0
   886
			{
sl@0
   887
		case EDrawFromPoint:
sl@0
   888
			iGc->DrawTextVertical(aText, NULL, aPt, up);
sl@0
   889
			break;
sl@0
   890
		case EDrawInBox:
sl@0
   891
			iGc->SetOrigin(aPt);
sl@0
   892
			rect = TRect(-aPt, size);
sl@0
   893
			if(aUpdateJustification)
sl@0
   894
				{
sl@0
   895
				iGc->SetCharJustification(80, aText.Length());
sl@0
   896
				iGc->UpdateJustificationVertical(aText, NULL, up);
sl@0
   897
				}
sl@0
   898
sl@0
   899
			iGc->DrawTextVertical(aText, NULL, rect, up);
sl@0
   900
			iGc->SetOrigin(TPoint());
sl@0
   901
			break;
sl@0
   902
		case EDrawRightAlignment:
sl@0
   903
			rect.iTl = aPt;
sl@0
   904
			rect.iBr.iY -= 30;
sl@0
   905
			iGc->DrawTextVertical(aText, NULL, rect, 0, DirectGdi::ERight);
sl@0
   906
			break;
sl@0
   907
			}
sl@0
   908
		}
sl@0
   909
	}
sl@0
   910
sl@0
   911
/**
sl@0
   912
Overrides of base class virtual
sl@0
   913
@leave Gets system wide error code
sl@0
   914
@return - TVerdict code
sl@0
   915
*/
sl@0
   916
TVerdict CTGlyphImageCache::doTestStepPreambleL()
sl@0
   917
	{			
sl@0
   918
	CTDirectGdiStepBase::doTestStepPreambleL();
sl@0
   919
	return TestStepResult();
sl@0
   920
	}
sl@0
   921
	
sl@0
   922
/** 
sl@0
   923
Overrides of base class pure virtual
sl@0
   924
Our implementation only gets called if the base class doTestStepPreambleL() did
sl@0
   925
not leave. That being the case, the current test result value will be EPass.
sl@0
   926
@leave Gets system wide error code
sl@0
   927
@return TVerdict code
sl@0
   928
*/	
sl@0
   929
TVerdict CTGlyphImageCache::doTestStepL()
sl@0
   930
	{		
sl@0
   931
	// Test for each pixel format
sl@0
   932
	TInt maxPixelFormat =  iTargetPixelFormatArray.Count() - 1;
sl@0
   933
	for(TInt targetPixelFormatIndex = maxPixelFormat; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--)
sl@0
   934
		{
sl@0
   935
		iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex];
sl@0
   936
		SetTargetL(iTestParams.iTargetPixelFormat, EOneContextOneTarget, KGlyphCacheWindowSize);
sl@0
   937
sl@0
   938
		if(maxPixelFormat == targetPixelFormatIndex)
sl@0
   939
			{
sl@0
   940
			iMonotypeFont = DetectMonotypeFontL();
sl@0
   941
			
sl@0
   942
			if(!iMonotypeFont)
sl@0
   943
				{
sl@0
   944
				WARN_PRINTF1(_L("!! Due to running the test in environment without monotype fonts, some test cases will not \
sl@0
   945
be executed! To set up environment with monotype font support, launch ityperast.cmd \
sl@0
   946
from epoc32\\winscw\\c\\, and then follow the instruction on the screen!!"));
sl@0
   947
				}
sl@0
   948
			else
sl@0
   949
				{
sl@0
   950
				INFO_PRINTF1(_L("Monotype fonts have been detected"));
sl@0
   951
				}	
sl@0
   952
			}
sl@0
   953
		
sl@0
   954
		RunTestsL();
sl@0
   955
		if(targetPixelFormatIndex == 0)
sl@0
   956
			{
sl@0
   957
			RunOomTestsL();
sl@0
   958
			}
sl@0
   959
		}
sl@0
   960
	CloseTMSGraphicsStep();
sl@0
   961
	return TestStepResult();
sl@0
   962
	}
sl@0
   963
sl@0
   964
/**
sl@0
   965
Overrides of base class pure virtual function
sl@0
   966
Lists the tests to be run
sl@0
   967
*/
sl@0
   968
void CTGlyphImageCache::RunTestsL()
sl@0
   969
	{
sl@0
   970
	MFontGlyphImageStorage* glyphStorage = NULL;
sl@0
   971
	TBool testImageCache = (iUseDirectGdi && !iUseSwDirectGdi);
sl@0
   972
	if(testImageCache)
sl@0
   973
		{
sl@0
   974
		TInt err = iGc->GetInterface(TUid::Uid(KDirectGdiGetGlyphStorageUid), (TAny*&) glyphStorage);
sl@0
   975
		if(err != KErrNone)
sl@0
   976
			{
sl@0
   977
			ERR_PRINTF2(_L("Error while retrieving Glyph Storage Interface, err = %d"), err);
sl@0
   978
			TESTNOERRORL(err);
sl@0
   979
			}
sl@0
   980
		User::LeaveIfNull(glyphStorage);
sl@0
   981
		CleanupStack::PushL(TCleanupItem(CleanCache, glyphStorage));
sl@0
   982
		glyphStorage->CleanGlyphImageCache();
sl@0
   983
		}
sl@0
   984
sl@0
   985
	if(testImageCache)
sl@0
   986
		{
sl@0
   987
		SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0001"));
sl@0
   988
		TestRetrieveEntryL(glyphStorage, EAntiAliasedGlyphBitmap);
sl@0
   989
		RecordTestResultL();
sl@0
   990
		glyphStorage->CleanGlyphImageCache();
sl@0
   991
		SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0001"));
sl@0
   992
		TestRetrieveEntryL(glyphStorage, EFourColourBlendGlyphBitmap);
sl@0
   993
		RecordTestResultL();
sl@0
   994
		glyphStorage->CleanGlyphImageCache();
sl@0
   995
		SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0001"));
sl@0
   996
		TestRetrieveEntryL(glyphStorage, EMonochromeGlyphBitmap);
sl@0
   997
		RecordTestResultL();
sl@0
   998
		SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0006"));
sl@0
   999
		WrongParameterL(glyphStorage);
sl@0
  1000
		RecordTestResultL();
sl@0
  1001
		SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0005"));
sl@0
  1002
		FontListIdOrderL(glyphStorage);
sl@0
  1003
		RecordTestResultL();
sl@0
  1004
		glyphStorage->CleanGlyphImageCache();
sl@0
  1005
		}
sl@0
  1006
sl@0
  1007
	if(!iRunningOomTests)//fonts are cached in the array, where memory won't be freed even if the font is released
sl@0
  1008
		{
sl@0
  1009
		if(testImageCache)
sl@0
  1010
			{
sl@0
  1011
			SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0004"));
sl@0
  1012
			FillCacheL(glyphStorage);
sl@0
  1013
			RecordTestResultL();
sl@0
  1014
			SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0003"));
sl@0
  1015
			FillUpCacheL(glyphStorage);
sl@0
  1016
			RecordTestResultL();
sl@0
  1017
			glyphStorage->CleanGlyphImageCache();
sl@0
  1018
			}
sl@0
  1019
		for(TInt ii = EDrawTextHorizontal; ii < EDrawTextLast; ii++)
sl@0
  1020
			{
sl@0
  1021
			for(TInt kk = EDrawFromPoint; kk <= EDrawInBox; kk++)
sl@0
  1022
				{
sl@0
  1023
				DrawTextDirection direction = (DrawTextDirection) ii;
sl@0
  1024
				DrawTextAdjustment adjustment = (DrawTextAdjustment) kk;
sl@0
  1025
		
sl@0
  1026
				SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0002"));
sl@0
  1027
				TestDrawGlyphL(glyphStorage, EMonochromeGlyphBitmap, direction, adjustment, EFalse);
sl@0
  1028
				RecordTestResultL();
sl@0
  1029
				SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0002"));
sl@0
  1030
				TestDrawGlyphL(glyphStorage, EMonochromeGlyphBitmap, direction, adjustment, ETrue);
sl@0
  1031
				RecordTestResultL();
sl@0
  1032
				SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0002"));
sl@0
  1033
				TestDrawGlyphL(glyphStorage, EAntiAliasedGlyphBitmap, direction, adjustment, EFalse);
sl@0
  1034
				RecordTestResultL();
sl@0
  1035
				SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0002"));
sl@0
  1036
				TestDrawGlyphL(glyphStorage, EAntiAliasedGlyphBitmap, direction, adjustment, ETrue);
sl@0
  1037
				RecordTestResultL();
sl@0
  1038
				
sl@0
  1039
				if(iMonotypeFont)
sl@0
  1040
					{
sl@0
  1041
					SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0002"));
sl@0
  1042
					TestDrawGlyphL(glyphStorage, EFourColourBlendGlyphBitmap, direction, adjustment, EFalse);
sl@0
  1043
					RecordTestResultL();
sl@0
  1044
					SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0002"));
sl@0
  1045
					TestDrawGlyphL(glyphStorage, EFourColourBlendGlyphBitmap, direction, adjustment, ETrue);
sl@0
  1046
					RecordTestResultL();
sl@0
  1047
					}
sl@0
  1048
				}
sl@0
  1049
			}
sl@0
  1050
		}
sl@0
  1051
sl@0
  1052
	//next set of tests should start from clean cache to garantee consistent results
sl@0
  1053
	if(testImageCache)
sl@0
  1054
		{
sl@0
  1055
		glyphStorage->CleanGlyphImageCache();
sl@0
  1056
		CleanupStack::Pop(glyphStorage);
sl@0
  1057
		}
sl@0
  1058
	}
sl@0
  1059
sl@0
  1060
/**
sl@0
  1061
See if monotype font is installed on the platform we are running on. Monotype font is required
sl@0
  1062
to run the glyph tests that use the glyph bitmap type EFourColourBlendGlyphBitmap to draw
sl@0
  1063
outlined and shadowed fonts.
sl@0
  1064
@return ETrue if monotype is installed, EFalse if it is not installed.
sl@0
  1065
 */
sl@0
  1066
TBool CTGlyphImageCache::DetectMonotypeFontL()
sl@0
  1067
	{
sl@0
  1068
	CFont *font = NULL;
sl@0
  1069
	_LIT(KTestFontTypefaceName,"DejaVu Sans Condensed");
sl@0
  1070
	TFontSpec fspec(KTestFontTypefaceName, 12);
sl@0
  1071
	fspec.iFontStyle.SetBitmapType(EFourColourBlendGlyphBitmap);
sl@0
  1072
sl@0
  1073
	fspec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
sl@0
  1074
	fspec.iFontStyle.SetEffects(FontEffect::EOutline, ETrue);
sl@0
  1075
	fspec.iFontStyle.SetEffects(FontEffect::EDropShadow, ETrue);
sl@0
  1076
sl@0
  1077
	User::LeaveIfError(iFontStore->GetNearestFontToDesignHeightInPixels((CFont*&) font, fspec));
sl@0
  1078
sl@0
  1079
	TFontSpec fontSpec = font->FontSpecInTwips();
sl@0
  1080
	TGlyphBitmapType glyphBitmapType = fontSpec.iFontStyle.BitmapType();
sl@0
  1081
	iFontStore->ReleaseFont(font);
sl@0
  1082
sl@0
  1083
	return (EFourColourBlendGlyphBitmap==glyphBitmapType);
sl@0
  1084
	}