Update contrib.
1 // Copyright (c) 2007-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // This test is designed to run in environment with monotype font support.
15 // To set up environment launch ityperast.cmd from epoc32\winscw\, and
16 // then follow instruction on the screen.
20 #include "tglyphimagecache.h"
21 #include <graphics/directgdiengine.h>
23 #include <VG/openvg.h>
25 // The size of the target in pixels to use for these tests
26 const TSize KGlyphCacheWindowSize(400, 400);
36 EItalicStrikeThrough = 0xa,
43 TFontParam iFontParam;
46 LOCAL_C void CleanCache(TAny* aPtr)
48 MFontGlyphImageStorage* glyphImageStorage = reinterpret_cast<MFontGlyphImageStorage*> (aPtr);
49 glyphImageStorage->CleanGlyphImageCache();
52 CTGlyphImageCache::CTGlyphImageCache()
54 SetTestStepName(KTGlyphImageCacheStep);
57 CTGlyphImageCache::~CTGlyphImageCache()
63 GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0001
78 Test requests Glyph Image elements from storage according their Glyph Key.
87 Create Font Image Storage. In the cycle request aGlyph Image entry for a particular Glyph
91 @SYMTestExpectedResults
92 GlyphImage function must succeed; foreground, shadow and outlined images (if applicable) must be created
94 void CTGlyphImageCache::TestRetrieveEntryL(MFontGlyphImageStorage* aGlyphStorage, TGlyphBitmapType aGlyphType)
98 _LIT(KTestName, "GlyphCache_RetrieveEntry");
101 INFO_PRINTF1(KTestName);
105 TInt bufferLength = size.iWidth * size.iHeight;
106 TUint8* buffer = (TUint8*)User::AllocL(bufferLength);
107 CleanupStack::PushL(buffer);
108 if(aGlyphType == EMonochromeGlyphBitmap)
109 {//to make decoding mechanizm work properly we need to fill the buffer
110 Mem::Fill(buffer, bufferLength, 0x1);
117 TInt numFont = sizeof(fontListId) / sizeof(fontListId[0]);
118 TUint charCodeList[] =
122 TInt numGlyphCode = sizeof(charCodeList) / sizeof(charCodeList[0]);
124 for(TInt jj = 0; jj < numFont; jj++)
126 TInt fontId = fontListId[jj];
127 for(TInt ii = 0; ii < numGlyphCode; ii++)
129 TChar glyphCode = TChar(charCodeList[ii]);
130 VGImage foregroundImg = VG_INVALID_HANDLE;
131 VGImage shadowImg = VG_INVALID_HANDLE;
132 VGImage outlineImg = VG_INVALID_HANDLE;
133 TBool res = aGlyphStorage->GlyphImage(fontId, glyphCode, aGlyphType, buffer, size, &foregroundImg, &shadowImg, &outlineImg);
142 if(aGlyphType == EFourColourBlendGlyphBitmap)
150 CleanupStack::PopAndDestroy(buffer);
155 GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0002
170 Drawing monochrome, anti-aliased and four colour fonts with different styles
179 Text is output with different effects (strikethrough, underline) and orientation
180 (horizontal, vertical up, vertical down) and at different sizes and positions.
181 Clip region is also specified.
183 @SYMTestExpectedResults
184 Test and reference images must match
186 void CTGlyphImageCache::TestDrawGlyphL(MFontGlyphImageStorage* aGlyphStorage, TGlyphBitmapType aGlyphBitmapType, DrawTextDirection aDirection, DrawTextAdjustment aDrawAdjustment, TBool aClipText)
188 _LIT(KTestNameTemplate, "DrawGlyph%S_Dir%d_Clip%d_Adjust%d");
190 _LIT(KTextOutput, "Hello world! Hello world! Hello world! Hello world! Hello world! Hello world!");
192 switch(aGlyphBitmapType)
194 case EMonochromeGlyphBitmap:
195 _LIT(KMonochromeName, "Monochrome");
196 testName.Format(KTestNameTemplate, &KMonochromeName, aDirection, aClipText, aDrawAdjustment);
198 case EAntiAliasedGlyphBitmap:
199 _LIT(KAntiAliasedName, "AntiAliased");
200 testName.Format(KTestNameTemplate, &KAntiAliasedName, aDirection, aClipText, aDrawAdjustment);
202 case EFourColourBlendGlyphBitmap:
203 _LIT(KFourColourName, "FourColour");
204 testName.Format(KTestNameTemplate, &KFourColourName, aDirection, aClipText, aDrawAdjustment);
207 User::Leave(KErrNotSupported);
211 if(!iRunningOomTests)
213 INFO_PRINTF1(testName);
217 _LIT(KTestFontTypefaceName,"DejaVu Sans Condensed");
218 const TFontType fontType[] =
220 18, EStrikeThrough, 48, EUnderline, 16, EItalic, 78, EItalicStrikeThrough,
222 18, EStrikeThrough, 48, EUnderlineBold, 16, ENormal, 78, EStrikeThrough, 78, EBold,
226 TInt *coord = & (pt.iY);
228 TSize size = iGdiTarget->SizeInPixels();
231 RRegion region(rect);
233 if(aDirection == EDrawTextHorizontal)
235 rect1 = TRect(size.iWidth / 2 - 40, 40, size.iWidth / 2 + 40, size.iHeight - 40);
239 rect1 = TRect(20, size.iHeight / 2 - 40, size.iWidth - 20, size.iHeight / 2 + 40);
241 region.SubRect(rect1);
243 if(aDirection == EDrawTextVerticalUp || aDirection == EDrawTextVerticalDown)
245 if(aDirection == EDrawTextVerticalUp)
247 pt.iY = size.iHeight - 5;
252 TInt arraySize = sizeof(fontType) / sizeof(fontType[0]);
254 for(TInt ii = 0; ii < arraySize; ii++)
257 TFontSpec fspec(KTestFontTypefaceName, fontType[ii].iFontSize);
258 fspec.iFontStyle.SetBitmapType(aGlyphBitmapType);
264 iGc->SetClippingRegion(region);
267 if(aGlyphBitmapType == EFourColourBlendGlyphBitmap)
269 fspec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
270 fspec.iFontStyle.SetEffects(FontEffect::EOutline, ETrue);
271 fspec.iFontStyle.SetEffects(FontEffect::EDropShadow, ETrue);
272 TRgb shadowColor = TRgb(0, 0, 255);
273 iGc->SetTextShadowColor(shadowColor);
274 TEST(shadowColor == iGc->TextShadowColor());
275 iGc->SetBrushColor(TRgb(255, 0, 0));
276 TEST(TRgb(255, 0, 0) == iGc->BrushColor());
280 iGc->SetBrushStyle(DirectGdi::ENullBrush);
281 iGc->SetPenStyle(DirectGdi::ESolidPen);
283 iGc->SetPenColor(TRgb(0, 255, 0));
284 if(fontType[ii].iFontParam & EItalic)
286 fspec.iFontStyle.SetPosture(EPostureItalic);
288 if(fontType[ii].iFontParam & EBold)
290 fspec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
293 User::LeaveIfError(iFontStore->GetNearestFontToDesignHeightInPixels((CFont*&) font, fspec));
298 iGc->SetFontNoDuplicate(font);
299 (reinterpret_cast <CTestDirectGdiContext*> (iGc))->NoJustifyAutoUpdate();
304 iGc->SetFontNoDuplicate(font);//shoudn't have any impact
305 (reinterpret_cast <CTestDirectGdiContext*> (iGc))->SetJustifyAutoUpdate();
311 iGc->SetFontNoDuplicate(font);//shoudn't have any impact
313 TEST(iGc->HasFont());
315 TFontSpec fontSpec = font->FontSpecInTwips();
316 TGlyphBitmapType glyphBitmapType = fontSpec.iFontStyle.BitmapType();
318 TEST(glyphBitmapType == aGlyphBitmapType);
319 if(fontType[ii].iFontParam & EUnderline)
321 iGc->SetUnderlineStyle(DirectGdi::EUnderlineOn);
323 else if(fontType[ii].iFontParam & EStrikeThrough)
325 iGc->SetStrikethroughStyle(DirectGdi::EStrikethroughOn);
328 if(EDrawTextVerticalDown != aDirection)
330 *coord += font->HeightInPixels() + 5;
333 if(aGlyphStorage && (ii == 0) && (arraySize > 1))
335 aGlyphStorage->CleanGlyphImageCache();
336 aGlyphStorage->EnforceOOMFailure(ETrue);
338 DrawText(KTextOutput, pt, aDirection, aDrawAdjustment, ii == 1);
341 aGlyphStorage->EnforceOOMFailure(EFalse);
344 if(EDrawTextVerticalDown == aDirection)
346 *coord += font->HeightInPixels() + 5;
349 if(fontType[ii].iFontParam == ENormal)
351 iGc->SetUnderlineStyle(DirectGdi::EUnderlineOff);
352 iGc->SetStrikethroughStyle(DirectGdi::EStrikethroughOff);
355 iFontStore->ReleaseFont(font);
357 TEST(!iGc->HasFont());
362 iGc->ResetClippingRegion();
365 // Write the output to file.
367 TESTNOERROR(WriteTargetOutput(iTestParams, testName));
372 GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0003
387 Filling up the glyph image cache
396 1. Fill glyph image storage with the same font but different glyphs until it exceeds its limit and resets the cache.
397 Repeat this operation for other glyph types
399 2. Fill glyph image storage with different font and different glyph codes
401 @SYMTestExpectedResults
402 Check that Glyph cache storage increments cache size correctly and deletes the least
405 void CTGlyphImageCache::FillUpCacheL(MFontGlyphImageStorage* aGlyphStorage)
410 aGlyphStorage->CleanGlyphImageCache();
412 _LIT(KTestName, "GlyphCache_FillUpCache");
413 if(!iRunningOomTests)
415 INFO_PRINTF1(KTestName);
418 const TSize size(12, 16);
419 TUint8* buffer = (TUint8*)User::AllocL(size.iWidth * size.iHeight);
420 CleanupStack::PushL(buffer);
422 TGlyphBitmapType glyphTypeList[] =
424 EMonochromeGlyphBitmap,
425 EAntiAliasedGlyphBitmap,
426 EFourColourBlendGlyphBitmap,
428 const TInt numGlyphType = sizeof(glyphTypeList) / sizeof(glyphTypeList[0]);
429 TESTL(aGlyphStorage->GlyphCacheSize() == 0);
431 TInt glyphSizeInByte = 0;
432 TInt expectedSize = 0;
433 TUint32 glyphCode = 1;
435 VGImage foregroundImg = VG_INVALID_HANDLE;
436 VGImage shadowImg = VG_INVALID_HANDLE;
437 VGImage outlineImg = VG_INVALID_HANDLE;
438 for(TInt ii = 0; ii < numGlyphType; ii++)
440 TGlyphBitmapType glyphType = glyphTypeList[ii];
441 //calculate the actual size of the glyph
442 glyphSizeInByte = GlyphImageSizeInByte(glyphType, size);
444 TUint maxGlyphSize = aGlyphStorage->MaxGlyphCacheSize() + glyphSizeInByte;
447 TEST(expectedSize == aGlyphStorage->GlyphCacheSize());
448 TBool res = aGlyphStorage->GlyphImage(fontId, TChar(glyphCode), (TGlyphBitmapType)glyphType, buffer, size, &foregroundImg, &shadowImg, &outlineImg);
451 expectedSize+= glyphSizeInByte;
452 foregroundImg = VG_INVALID_HANDLE;
453 shadowImg = VG_INVALID_HANDLE;
454 outlineImg = VG_INVALID_HANDLE;
455 }while(expectedSize <= maxGlyphSize);
458 TEST(glyphSizeInByte == aGlyphStorage->GlyphCacheSize());
459 aGlyphStorage->CleanGlyphImageCache();
462 //now try to filling cache with different fonts and check that last usable font wont be removed
463 TUint maxGlyphSize = aGlyphStorage->MaxGlyphCacheSize();
464 glyphSizeInByte = GlyphImageSizeInByte(EMonochromeGlyphBitmap, size);
467 TEST(expectedSize == aGlyphStorage->GlyphCacheSize());
468 TBool res = aGlyphStorage->GlyphImage(fontId, TChar(glyphCode), EMonochromeGlyphBitmap, buffer, size, &foregroundImg, &shadowImg, &outlineImg);
471 expectedSize+= glyphSizeInByte;
472 foregroundImg = VG_INVALID_HANDLE;
473 shadowImg = VG_INVALID_HANDLE;
474 outlineImg = VG_INVALID_HANDLE;
475 }while(expectedSize <= maxGlyphSize);
480 TBool res = aGlyphStorage->GlyphImage(fontId, TChar(glyphCode), EMonochromeGlyphBitmap, buffer, size, &foregroundImg, &shadowImg, &outlineImg);
481 TEST(glyphSizeInByte == aGlyphStorage->GlyphCacheSize());
484 RArray<TUint32> listFontId;
485 aGlyphStorage->FontIdInOrder(listFontId);
486 TESTL(listFontId.Count() == 1);
487 TEST(listFontId[0] == fontId);
490 CleanupStack::PopAndDestroy(buffer);
495 GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0004
510 Tests filling the glyph image cache with different glyph images
519 Specify glyphs which correspond to different fonts, glyph codes.
520 Request related VGImages.
521 Test the cache size is correct after each operation.
522 Get the driver's MDirectGdiDriverCacheSize interface.
523 Attempt to set the maximum size of the glyph cache to a size smaller than
524 the existing cache size.
525 Attempt to set the maximum size of the glyph cache to a size the same as
526 the existing cache size.
529 @SYMTestExpectedResults
530 Obtained glyph code and cache size must be correct each time.
531 Setting the maximum glyph cache size to a smaller size than the existing cache
532 size should fail with error KErrArgument.
533 Setting the maximum glyph cache size to a size the same as the existing cache
536 void CTGlyphImageCache::FillCacheL(MFontGlyphImageStorage* aGlyphStorage)
538 ASSERT(aGlyphStorage);
540 aGlyphStorage->CleanGlyphImageCache();
542 _LIT(KTestName, "GlyphCache_FillCache");
543 if(!iRunningOomTests)
545 INFO_PRINTF1(KTestName);
548 const TSize smallFontSize = TSize(12, 16);
549 const TSize smallFont1Size = TSize(10, 14);
550 const TSize bigFontSize = TSize(18, 24);
551 const TSize bigFont1Size = TSize(20, 26);
552 const TInt smallFontId = 10;
553 const TInt bigFontId = 20;
554 const TInt smallFont1Id = 30;
555 const TInt bigFont1Id = 40;
556 VGImage foregroundImg = VG_INVALID_HANDLE;
557 VGImage shadowImg = VG_INVALID_HANDLE;
558 VGImage outlineImg = VG_INVALID_HANDLE;
560 TUint8* buffer = (TUint8*)User::AllocL(bigFontSize.iWidth * bigFontSize.iHeight);
561 CleanupStack::PushL(buffer);
562 TESTL(aGlyphStorage->GlyphCacheSize() == 0);
564 TInt expectedCacheSize = 0;
565 TChar glyphCode = TChar(1);
566 TGlyphBitmapType glyphType = EMonochromeGlyphBitmap;
567 TBool res = aGlyphStorage->GlyphImage(smallFontId, glyphCode, glyphType, buffer, smallFontSize, &foregroundImg, &shadowImg, &outlineImg);
569 expectedCacheSize = GlyphImageSizeInByte(glyphType, smallFontSize);
570 TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize());
572 //try to retrieve the same glyph
573 res = aGlyphStorage->GlyphImage(smallFontId, glyphCode, glyphType, buffer, smallFontSize, &foregroundImg, &shadowImg, &outlineImg);
575 //the size should be the same
576 TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize());
578 //now retrieving the same glyphCode but for the different font
579 res = aGlyphStorage->GlyphImage(bigFontId, glyphCode, glyphType, buffer, bigFontSize, &foregroundImg, &shadowImg, &outlineImg);
581 expectedCacheSize += GlyphImageSizeInByte(glyphType, bigFontSize);
582 TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize());
584 //last font but different glyphCode
585 glyphCode = TChar(2);
586 res = aGlyphStorage->GlyphImage(bigFontId, glyphCode, glyphType, buffer, bigFontSize, &foregroundImg, &shadowImg, &outlineImg);
588 expectedCacheSize += GlyphImageSizeInByte(glyphType, bigFontSize);
589 TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize());
591 //small font and last glyphCode
592 res = aGlyphStorage->GlyphImage(smallFontId, glyphCode, glyphType, buffer, smallFontSize, &foregroundImg, &shadowImg, &outlineImg);
594 expectedCacheSize += GlyphImageSizeInByte(glyphType, smallFontSize);
595 TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize());
597 //now change the type
598 glyphType = EAntiAliasedGlyphBitmap;
599 res = aGlyphStorage->GlyphImage(smallFont1Id, glyphCode, glyphType, buffer, smallFont1Size, &foregroundImg, &shadowImg, &outlineImg);
601 expectedCacheSize += GlyphImageSizeInByte(glyphType, smallFont1Size);
602 TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize());
604 res = aGlyphStorage->GlyphImage(smallFont1Id, glyphCode, glyphType, buffer, smallFont1Size, &foregroundImg, &shadowImg, &outlineImg);
606 TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize());
608 //now change the type again
609 glyphType = EFourColourBlendGlyphBitmap;
610 res = aGlyphStorage->GlyphImage(bigFont1Id, glyphCode, glyphType, buffer, bigFont1Size, &foregroundImg, &shadowImg, &outlineImg);
612 expectedCacheSize += GlyphImageSizeInByte(glyphType, bigFont1Size);
613 TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize());
615 //using initial value.
616 glyphType = EMonochromeGlyphBitmap;
617 glyphCode = TChar(1);
618 res = aGlyphStorage->GlyphImage(smallFontId, glyphCode, glyphType, buffer, smallFontSize, &foregroundImg, &shadowImg, &outlineImg);
620 TEST(expectedCacheSize == aGlyphStorage->GlyphCacheSize());
622 //get the driver's MDirectGdiDriverCacheSize extension interface and attempt
623 //to set the maximum cache size to be smaller than the existing cache size
624 CDirectGdiDriver* driver = CDirectGdiDriver::Static();
625 TESTL(driver != NULL);
626 MDirectGdiDriverCacheSize* driverCacheSize = NULL;
627 res = driver->GetInterface(TUid::Uid(KDirectGdiDriverCacheSizeUid), (TAny*&)driverCacheSize);
629 //save the original cache size
630 TInt originalCacheSize = driverCacheSize->MaxGlyphCacheSize();
631 //setting the cache size to a size smaller than the existing cache should fail
632 res = driverCacheSize->SetMaxGlyphCacheSize(aGlyphStorage->GlyphCacheSize()-1);
633 TEST(res == KErrArgument);
634 //setting the cache size to the same size as the existing cache should pass
635 res = driverCacheSize->SetMaxGlyphCacheSize(aGlyphStorage->GlyphCacheSize());
637 TEST(aGlyphStorage->GlyphCacheSize() == driverCacheSize->MaxGlyphCacheSize());
638 //reset the original driver cache size
639 res = driverCacheSize->SetMaxGlyphCacheSize(originalCacheSize);
642 CleanupStack::PopAndDestroy(buffer);
647 GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0005
662 Tests the ordering font IDs in the glyph image cache.
671 Request glyph images for different fonts.
673 @SYMTestExpectedResults
674 List of glyph cache trees must be arranged in order from most used to least used.
676 void CTGlyphImageCache::FontListIdOrderL(MFontGlyphImageStorage* aGlyphStorage)
681 aGlyphStorage->CleanGlyphImageCache();
683 _LIT(KTestName, "GlyphCache_FontListIdOrder");
684 if(!iRunningOomTests)
686 INFO_PRINTF1(KTestName);
689 const TSize fontSize = TSize(12, 16);
690 TUint8* buffer = (TUint8*)User::AllocL(fontSize.iWidth * fontSize.iHeight);
691 CleanupStack::PushL(buffer);
693 TChar glyphCode = TChar(10);
695 VGImage foregroundImg = VG_INVALID_HANDLE;
696 VGImage shadowImg = VG_INVALID_HANDLE;
697 VGImage outlineImg = VG_INVALID_HANDLE;
699 TGlyphBitmapType glyphType = EMonochromeGlyphBitmap;
700 TInt res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
704 res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
708 res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
711 RArray<TUint32> fontListId;
712 res = aGlyphStorage->FontIdInOrder(fontListId);
719 TESTL(fontListId.Count() == 3);
720 TEST(fontListId[0] == 30);
721 TEST(fontListId[1] == 20);
722 TEST(fontListId[2] == 10);
725 //call entries again to reorder font id list
727 res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
731 res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
735 res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
739 res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
743 res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
746 res = aGlyphStorage->FontIdInOrder(fontListId);
753 TESTL(fontListId.Count() == 5);
754 TEST(fontListId[0] == 50);
755 TEST(fontListId[1] == 10);
756 TEST(fontListId[2] == 40);
757 TEST(fontListId[3] == 20);
758 TEST(fontListId[4] == 30);
761 CleanupStack::PopAndDestroy(buffer);
766 GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0006
779 Test the operation of the glyph image cache when sent wrong parameters.
788 Test requesting of glyph images with invalid paramaters - test an invalid glyph type
789 and test requesting a glyph image with zero height and one with zero width.
791 @SYMTestExpectedResults
792 The function must identify wrong arguments and return the expected error.
794 void CTGlyphImageCache::WrongParameterL(MFontGlyphImageStorage* aGlyphStorage)
796 _LIT(KTestName, "GlyphCache_WrongParameters");
797 if(!iRunningOomTests)
799 INFO_PRINTF1(KTestName);
802 aGlyphStorage->CleanGlyphImageCache();
804 TChar glyphCode = TChar(10);
806 VGImage foregroundImg = VG_INVALID_HANDLE;
807 VGImage shadowImg = VG_INVALID_HANDLE;
808 VGImage outlineImg = VG_INVALID_HANDLE;
809 TSize fontSize = TSize(10, 12);
810 TUint8* buffer = (TUint8*)User::AllocL(fontSize.iWidth * fontSize.iHeight);
811 CleanupStack::PushL(buffer);
813 TGlyphBitmapType glyphType = EDefaultGlyphBitmap; // unsupported
815 TInt res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, fontSize, &foregroundImg, &shadowImg, &outlineImg);
816 TEST(res == KErrNotSupported);
817 TEST(foregroundImg == VG_INVALID_HANDLE);
818 TEST(shadowImg == VG_INVALID_HANDLE);
819 TEST(outlineImg == VG_INVALID_HANDLE);
821 glyphType = EMonochromeGlyphBitmap; // supported
822 res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, TSize(12, 0), &foregroundImg, &shadowImg, &outlineImg);
823 TEST(res == KErrArgument);
824 res = aGlyphStorage->GlyphImage(fontId, glyphCode, glyphType, buffer, TSize(0, 12), &foregroundImg, &shadowImg, &outlineImg);
825 TEST(res == KErrArgument);
826 TEST(foregroundImg == VG_INVALID_HANDLE);
827 TEST(shadowImg == VG_INVALID_HANDLE);
828 TEST(outlineImg == VG_INVALID_HANDLE);
830 CleanupStack::PopAndDestroy(buffer);
833 TInt CTGlyphImageCache::GlyphImageSizeInByte(TGlyphBitmapType aGlyphType, const TSize& aSize) const
835 TInt glyphSizeInByte = 0;
836 //calculate the actual size of the glyph
839 case EMonochromeGlyphBitmap:
840 glyphSizeInByte = (((aSize.iWidth + 31) / 32) << 2) * aSize.iHeight;
842 case EAntiAliasedGlyphBitmap:
843 glyphSizeInByte = aSize.iWidth * aSize.iHeight;
845 case EFourColourBlendGlyphBitmap:
846 glyphSizeInByte = aSize.iWidth * aSize.iHeight;
847 //we have to allocate memory for shadow and outline bitmap as well
848 glyphSizeInByte *= 3;
853 return glyphSizeInByte;
856 Draws the text on the screen according its direction and alignment.
858 void CTGlyphImageCache::DrawText(const TDesC& aText, const TPoint& aPt, DrawTextDirection aDirection, DrawTextAdjustment aDrawAdjustment, TBool aUpdateJustification)
860 const TSize size = iGdiTarget->SizeInPixels();
863 if(aDirection == EDrawTextHorizontal)
865 switch(aDrawAdjustment)
868 iGc->DrawText(aText, NULL, aPt);
872 rect = TRect(-aPt, size);
873 iGc->DrawText(aText, NULL, rect);
875 case EDrawRightAlignment:
878 iGc->DrawText(aText, NULL, rect, 0, DirectGdi::ERight);
882 else if ((aDirection == EDrawTextVerticalDown) || (aDirection == EDrawTextVerticalUp))
884 TBool up = (aDirection==EDrawTextVerticalUp);
885 switch(aDrawAdjustment)
888 iGc->DrawTextVertical(aText, NULL, aPt, up);
892 rect = TRect(-aPt, size);
893 if(aUpdateJustification)
895 iGc->SetCharJustification(80, aText.Length());
896 iGc->UpdateJustificationVertical(aText, NULL, up);
899 iGc->DrawTextVertical(aText, NULL, rect, up);
900 iGc->SetOrigin(TPoint());
902 case EDrawRightAlignment:
905 iGc->DrawTextVertical(aText, NULL, rect, 0, DirectGdi::ERight);
912 Overrides of base class virtual
913 @leave Gets system wide error code
914 @return - TVerdict code
916 TVerdict CTGlyphImageCache::doTestStepPreambleL()
918 CTDirectGdiStepBase::doTestStepPreambleL();
919 return TestStepResult();
923 Overrides of base class pure virtual
924 Our implementation only gets called if the base class doTestStepPreambleL() did
925 not leave. That being the case, the current test result value will be EPass.
926 @leave Gets system wide error code
927 @return TVerdict code
929 TVerdict CTGlyphImageCache::doTestStepL()
931 // Test for each pixel format
932 TInt maxPixelFormat = iTargetPixelFormatArray.Count() - 1;
933 for(TInt targetPixelFormatIndex = maxPixelFormat; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--)
935 iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex];
936 SetTargetL(iTestParams.iTargetPixelFormat, EOneContextOneTarget, KGlyphCacheWindowSize);
938 if(maxPixelFormat == targetPixelFormatIndex)
940 iMonotypeFont = DetectMonotypeFontL();
944 WARN_PRINTF1(_L("!! Due to running the test in environment without monotype fonts, some test cases will not \
945 be executed! To set up environment with monotype font support, launch ityperast.cmd \
946 from epoc32\\winscw\\c\\, and then follow the instruction on the screen!!"));
950 INFO_PRINTF1(_L("Monotype fonts have been detected"));
955 if(targetPixelFormatIndex == 0)
960 CloseTMSGraphicsStep();
961 return TestStepResult();
965 Overrides of base class pure virtual function
966 Lists the tests to be run
968 void CTGlyphImageCache::RunTestsL()
970 MFontGlyphImageStorage* glyphStorage = NULL;
971 TBool testImageCache = (iUseDirectGdi && !iUseSwDirectGdi);
974 TInt err = iGc->GetInterface(TUid::Uid(KDirectGdiGetGlyphStorageUid), (TAny*&) glyphStorage);
977 ERR_PRINTF2(_L("Error while retrieving Glyph Storage Interface, err = %d"), err);
980 User::LeaveIfNull(glyphStorage);
981 CleanupStack::PushL(TCleanupItem(CleanCache, glyphStorage));
982 glyphStorage->CleanGlyphImageCache();
987 SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0001"));
988 TestRetrieveEntryL(glyphStorage, EAntiAliasedGlyphBitmap);
990 glyphStorage->CleanGlyphImageCache();
991 SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0001"));
992 TestRetrieveEntryL(glyphStorage, EFourColourBlendGlyphBitmap);
994 glyphStorage->CleanGlyphImageCache();
995 SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0001"));
996 TestRetrieveEntryL(glyphStorage, EMonochromeGlyphBitmap);
998 SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0006"));
999 WrongParameterL(glyphStorage);
1000 RecordTestResultL();
1001 SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0005"));
1002 FontListIdOrderL(glyphStorage);
1003 RecordTestResultL();
1004 glyphStorage->CleanGlyphImageCache();
1007 if(!iRunningOomTests)//fonts are cached in the array, where memory won't be freed even if the font is released
1011 SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0004"));
1012 FillCacheL(glyphStorage);
1013 RecordTestResultL();
1014 SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0003"));
1015 FillUpCacheL(glyphStorage);
1016 RecordTestResultL();
1017 glyphStorage->CleanGlyphImageCache();
1019 for(TInt ii = EDrawTextHorizontal; ii < EDrawTextLast; ii++)
1021 for(TInt kk = EDrawFromPoint; kk <= EDrawInBox; kk++)
1023 DrawTextDirection direction = (DrawTextDirection) ii;
1024 DrawTextAdjustment adjustment = (DrawTextAdjustment) kk;
1026 SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0002"));
1027 TestDrawGlyphL(glyphStorage, EMonochromeGlyphBitmap, direction, adjustment, EFalse);
1028 RecordTestResultL();
1029 SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0002"));
1030 TestDrawGlyphL(glyphStorage, EMonochromeGlyphBitmap, direction, adjustment, ETrue);
1031 RecordTestResultL();
1032 SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0002"));
1033 TestDrawGlyphL(glyphStorage, EAntiAliasedGlyphBitmap, direction, adjustment, EFalse);
1034 RecordTestResultL();
1035 SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0002"));
1036 TestDrawGlyphL(glyphStorage, EAntiAliasedGlyphBitmap, direction, adjustment, ETrue);
1037 RecordTestResultL();
1041 SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0002"));
1042 TestDrawGlyphL(glyphStorage, EFourColourBlendGlyphBitmap, direction, adjustment, EFalse);
1043 RecordTestResultL();
1044 SetTestStepID(_L("GRAPHICS-DIRECTGDI-GLYPHIMAGECACHE-0002"));
1045 TestDrawGlyphL(glyphStorage, EFourColourBlendGlyphBitmap, direction, adjustment, ETrue);
1046 RecordTestResultL();
1052 //next set of tests should start from clean cache to garantee consistent results
1055 glyphStorage->CleanGlyphImageCache();
1056 CleanupStack::Pop(glyphStorage);
1061 See if monotype font is installed on the platform we are running on. Monotype font is required
1062 to run the glyph tests that use the glyph bitmap type EFourColourBlendGlyphBitmap to draw
1063 outlined and shadowed fonts.
1064 @return ETrue if monotype is installed, EFalse if it is not installed.
1066 TBool CTGlyphImageCache::DetectMonotypeFontL()
1069 _LIT(KTestFontTypefaceName,"DejaVu Sans Condensed");
1070 TFontSpec fspec(KTestFontTypefaceName, 12);
1071 fspec.iFontStyle.SetBitmapType(EFourColourBlendGlyphBitmap);
1073 fspec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
1074 fspec.iFontStyle.SetEffects(FontEffect::EOutline, ETrue);
1075 fspec.iFontStyle.SetEffects(FontEffect::EDropShadow, ETrue);
1077 User::LeaveIfError(iFontStore->GetNearestFontToDesignHeightInPixels((CFont*&) font, fspec));
1079 TFontSpec fontSpec = font->FontSpecInTwips();
1080 TGlyphBitmapType glyphBitmapType = fontSpec.iFontStyle.BitmapType();
1081 iFontStore->ReleaseFont(font);
1083 return (EFourColourBlendGlyphBitmap==glyphBitmapType);