sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "textendedbitmapgc.h" sl@0: #include sl@0: sl@0: const TInt KNumBitmapDrawingTests = 10; sl@0: const TInt KNumBrushPatternTests = 8; sl@0: const TUid KUidExampleExtendedBitmap = {0x10285A78}; sl@0: sl@0: /** Constructor. sl@0: @param aCallBack Pointer to a valid implementation of MTestHarnessCallBack, to allow logging and sl@0: test status requests to be passed back to the creator of a CTExtendedBitmapGc object. sl@0: @param aGc A graphics context to use for all drawing operations. sl@0: @param aDrawMode The mode to draw extended bitmaps in, either EDrawFlag or EDrawWhite. sl@0: @param aDisplayMode The display mode to use when creating extended bitmaps, this sl@0: must be one of EGray256, EColor64K, EColor16MU or EColor16MAP. sl@0: @return a pointer to a newly constructed CTExtendedBitmapGc object. sl@0: @leave KErrNotSupported if an unsupported display mode is passed in aDisplayMode. sl@0: */ sl@0: EXPORT_C CTExtendedBitmapGc* CTExtendedBitmapGc::NewL(MTestHarnessCallBack* aCallBack, sl@0: CBitmapContext& aGc, sl@0: TDrawMode aDrawMode, sl@0: TDisplayMode aDisplayMode) sl@0: { sl@0: CTExtendedBitmapGc* ebgc = new(ELeave) CTExtendedBitmapGc(aCallBack, aGc, aDrawMode); sl@0: CleanupStack::PushL(ebgc); sl@0: ebgc->ConstructL(aDisplayMode); sl@0: CleanupStack::Pop(ebgc); sl@0: return ebgc; sl@0: } sl@0: sl@0: CTExtendedBitmapGc::CTExtendedBitmapGc(MTestHarnessCallBack* aCallBack, sl@0: CBitmapContext& aGc, sl@0: TDrawMode aDrawMode) : sl@0: iCallBack(aCallBack), iDrawMode(aDrawMode), iGc(aGc), iIsFbs(aGc.IsFbsBitGc()) sl@0: { sl@0: } sl@0: sl@0: void CTExtendedBitmapGc::ConstructL(TDisplayMode aDisplayMode) sl@0: sl@0: { sl@0: // Check that the display mode chosen is supported by the example rasterizer sl@0: if ((aDisplayMode != EGray256) && (aDisplayMode != EColor64K) && (aDisplayMode != EColor16MU) && (aDisplayMode != EColor16MAP)) sl@0: { sl@0: INFO_PRINTF2(_L("Failed to construct CTExtendedBitmapGc with unsupported display mode %d"), aDisplayMode); sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: iDisplayMode = aDisplayMode; sl@0: sl@0: // Get a font for use with the DrawText() and DrawTextVertical() tests sl@0: _LIT(KFontName, "DejaVu Sans Condensed"); sl@0: TFontSpec fontSpec(KFontName, 75); sl@0: fontSpec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap); sl@0: iCallBack->TestTrue(KErrNone == static_cast(iGc.Device())->GetNearestFontToDesignHeightInPixels(iFont, fontSpec)); sl@0: iGc.UseFont(iFont); sl@0: } sl@0: sl@0: EXPORT_C CTExtendedBitmapGc::~CTExtendedBitmapGc() sl@0: { sl@0: if(iFont) sl@0: { sl@0: iGc.DiscardFont(); sl@0: static_cast(iGc.Device())->ReleaseFont(iFont); sl@0: } sl@0: } sl@0: sl@0: /** Test case calling function used to test drawing of Extended Bitmaps on graphics contexts. sl@0: Utilised by GRAPHICS-BITGDI-0103 to test with CFbsBitGc, and by GRAPHICS-WSERV-0493 with CWindowGc. sl@0: @param aCaseNumber Case number to run sl@0: */ sl@0: EXPORT_C void CTExtendedBitmapGc::RunTestCaseL(TInt aCurTestCase) sl@0: { sl@0: --aCurTestCase; sl@0: switch(aCurTestCase / KNumBitmapDrawingTests) sl@0: { sl@0: case 0: sl@0: TestBitmapDrawingL(EFalse, EVerticalStripe, aCurTestCase % KNumBitmapDrawingTests); sl@0: break; sl@0: case 1: sl@0: TestBitmapDrawingL(EFalse, EHorizontalStripe, aCurTestCase % KNumBitmapDrawingTests); sl@0: break; sl@0: case 2: sl@0: TestBitmapDrawingL(ETrue, EVerticalStripe, aCurTestCase % KNumBitmapDrawingTests); sl@0: break; sl@0: case 3: sl@0: TestBitmapDrawingL(ETrue, EHorizontalStripe, aCurTestCase % KNumBitmapDrawingTests); sl@0: break; sl@0: default: sl@0: { sl@0: TInt brushCase = aCurTestCase - (4 * KNumBitmapDrawingTests); sl@0: if(brushCase < KNumBrushPatternTests) sl@0: { sl@0: TestBrushPatternL(brushCase); sl@0: } sl@0: else sl@0: { sl@0: // Finished tests sl@0: iCallBack->TestComplete(); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: /** Test case function used to test drawing of Extended Bitmaps on graphics contexts. sl@0: Utilised by GRAPHICS-BITGDI-0103 to test with CFbsBitGc, and by GRAPHICS-WSERV-0493 with CWindowGc. sl@0: @param aTestRegionOfInterest ETrue if to set a region of interest before drawing, EFalse not to sl@0: @param aStripeStyle Direction to draw the flag stripes, when rasterizer is present sl@0: @param aCaseNumber Case number to run - between 0 and (KNumBitmapDrawingTests - 1) sl@0: */ sl@0: void CTExtendedBitmapGc::TestBitmapDrawingL(TBool aTestRegionOfInterest, TStripeStyle aStripeStyle, TInt aCaseNumber) sl@0: { sl@0: _LIT(KVertical, "vertical"); sl@0: _LIT(KHorizontal, "horizontal"); sl@0: _LIT(KRegionNotSet, "not set"); sl@0: _LIT(KRegionSet, "set"); sl@0: const TPtrC KStripeStyle[2] = {KVertical(), KHorizontal()}; sl@0: const TPtrC KRegionStyle[2] = {KRegionNotSet(), KRegionSet()}; sl@0: const TInt KNumColors = 3; sl@0: const TRgb KColors[KNumColors] = {TRgb(0,255,255), TRgb(255,0,255), TRgb(255,255,0)}; sl@0: sl@0: const TRgb KMaskColors[KNumColors] = {KRgbBlack, KRgbWhite, KRgbBlack}; sl@0: const TRgb KAlphaColors[KNumColors] = {KRgbDarkGray, KRgbGray, KRgbDarkGray}; sl@0: const TStripeStyle KMaskBitmapStripeStyle = EVerticalStripe; sl@0: const TStripeStyle KAlphaBitmapStripeStyle = EHorizontalStripe; sl@0: sl@0: TInt dataSize = sizeof(KColors)+sizeof(TUint8); // estimate the data size sl@0: TUint8* data = new(ELeave) TUint8[dataSize]; sl@0: CleanupStack::PushL(data); sl@0: sl@0: const TSize scrSize = iGc.Device()->SizeInPixels(); sl@0: sl@0: // Decide what size the bitmaps should be sl@0: TRect extendedRect; sl@0: extendedRect.SetRect(10,10,(scrSize.iWidth>>1)-10,scrSize.iHeight-10); sl@0: TRect standardRect(extendedRect); sl@0: standardRect.Move(scrSize.iWidth>>1,0); sl@0: const TSize sizeInPixels(extendedRect.Width(),extendedRect.Height()); sl@0: sl@0: // Rects used for scaling tests sl@0: TRect scaledExtendedRect = extendedRect; sl@0: scaledExtendedRect.SetWidth(sizeInPixels.iWidth*3/4); sl@0: scaledExtendedRect.SetHeight(sizeInPixels.iHeight*3/5); sl@0: TRect scaledStandardRect = standardRect; sl@0: scaledStandardRect.SetWidth(sizeInPixels.iWidth*3/4); sl@0: scaledStandardRect.SetHeight(sizeInPixels.iHeight*3/5); sl@0: sl@0: // Positions for drawing extended and normal bitmaps sl@0: TPoint bmpExPos(10,10); sl@0: TPoint bmpNmlPos(10+(scrSize.iWidth>>1),10); sl@0: sl@0: // Use black and white vertical stripes as the data for the mask sl@0: WriteExtendedBitmapInfoL(data, dataSize, KMaskColors, KMaskBitmapStripeStyle); sl@0: sl@0: // Create an extended bitmap to use as a mask sl@0: CFbsBitmap* bmpMaskEx = new(ELeave) CFbsBitmap; sl@0: CleanupStack::PushL(bmpMaskEx); sl@0: TInt err = bmpMaskEx->CreateExtendedBitmap(sizeInPixels, iDisplayMode, KUidExampleExtendedBitmap, data, dataSize); sl@0: iCallBack->TestTrue(err == KErrNone); sl@0: sl@0: // Create a normal mask bitmap to use when testing the extended mask bitmap above sl@0: CFbsBitmap* bmpMaskNml; sl@0: CreateTestBitmapLC(bmpMaskNml, sizeInPixels, iDisplayMode, KRgbBlack, KRgbWhite, KRgbBlack, KMaskBitmapStripeStyle); sl@0: sl@0: // Use dark grey and grey horizontal stripes as the data for the alpha bitmap sl@0: WriteExtendedBitmapInfoL(data, dataSize, KAlphaColors, KAlphaBitmapStripeStyle); sl@0: sl@0: // Create an EGray256 extended bitmap to use when alpha blending sl@0: CFbsBitmap* bmpAlphaEx = new(ELeave) CFbsBitmap; sl@0: CleanupStack::PushL(bmpAlphaEx); sl@0: err = bmpAlphaEx->CreateExtendedBitmap(sizeInPixels, EGray256, KUidExampleExtendedBitmap, data, dataSize); sl@0: iCallBack->TestTrue(err == KErrNone); sl@0: sl@0: // Create a normal EGray256 alpha bitmap to use when testing the extended alpha bitmap above sl@0: CFbsBitmap* bmpAlphaNml; sl@0: CreateTestBitmapLC(bmpAlphaNml, sizeInPixels, EGray256, KRgbDarkGray, KRgbGray, KRgbDarkGray, KAlphaBitmapStripeStyle); sl@0: sl@0: // Create a clipping region and a clipping rect, making sure the shape of the region sl@0: // that is set is the same on both sides of the screen sl@0: const TInt KStripeSize = ((scrSize.iWidth>=300)&&(scrSize.iHeight>=100))?50:30; sl@0: TRegionFix<8> clippingRegion; sl@0: clippingRegion.AddRect(TRect(TPoint(0,0), TSize(scrSize.iWidth,KStripeSize))); sl@0: clippingRegion.AddRect(TRect(TPoint(0,scrSize.iHeight>>1), TSize(scrSize.iWidth,KStripeSize))); sl@0: clippingRegion.AddRect(TRect(TPoint(KStripeSize,0), TSize(KStripeSize<<1,scrSize.iHeight))); sl@0: clippingRegion.AddRect(TRect(TPoint((scrSize.iWidth>>1)+KStripeSize,0), TSize(KStripeSize<<1,scrSize.iHeight))); sl@0: iCallBack->TestTrue(clippingRegion.CheckError() == EFalse); sl@0: TRect clippingRect(TPoint(0,KStripeSize>>1), TSize(scrSize.iWidth,scrSize.iHeight-KStripeSize)); sl@0: sl@0: // Write the colours to be used in the extended bitmap to the extended bitmap data, sl@0: // we run the tests one with horizontal stripes and once with vertical stripes sl@0: WriteExtendedBitmapInfoL(data, dataSize, KColors, aStripeStyle); sl@0: sl@0: // Create an extended bitmap sl@0: CFbsBitmap* bmpEx = new(ELeave) CFbsBitmap; sl@0: CleanupStack::PushL(bmpEx); sl@0: err = bmpEx->CreateExtendedBitmap(sizeInPixels, iDisplayMode, KUidExampleExtendedBitmap, data, dataSize); sl@0: iCallBack->TestTrue(err == KErrNone); sl@0: sl@0: // Create a normal bitmap to use when testing the extended bitmap above sl@0: CFbsBitmap* bmpNml; sl@0: CreateTestBitmapLC(bmpNml, sizeInPixels, iDisplayMode, KColors[0], KColors[1], KColors[2], aStripeStyle); sl@0: sl@0: // Clear to red sl@0: iGc.SetBrushColor(KRgbRed); sl@0: iGc.Clear(); sl@0: sl@0: if (aTestRegionOfInterest) sl@0: { sl@0: iGc.SetClippingRegion(clippingRegion); sl@0: iGc.SetClippingRect(clippingRect); sl@0: } sl@0: sl@0: // Draw the extended bitmap(s) on the left side of the screen and the normal bitmap(s) on the sl@0: // right side of the screen in each case sl@0: switch (aCaseNumber) sl@0: { sl@0: case 0: sl@0: { sl@0: INFO_PRINTF3(_L("Stripe style %S. Region of interest %S"), &KStripeStyle[aStripeStyle], &KRegionStyle[aTestRegionOfInterest]); sl@0: INFO_PRINTF1(_L("... BitBlt()")); sl@0: iGc.BitBlt(bmpExPos, bmpEx); sl@0: iGc.BitBlt(bmpNmlPos, bmpNml); sl@0: break; sl@0: } sl@0: case 1: sl@0: { sl@0: INFO_PRINTF1(_L("... BitBltMasked()")); sl@0: iGc.BitBltMasked(bmpExPos, bmpEx, sizeInPixels, bmpMaskEx, EFalse); sl@0: iGc.BitBltMasked(bmpNmlPos, bmpNml, sizeInPixels, bmpMaskNml, EFalse); sl@0: break; sl@0: } sl@0: case 2: sl@0: { sl@0: INFO_PRINTF1(_L("... DrawBitmap()")); sl@0: iGc.DrawBitmap(extendedRect, bmpEx); sl@0: iGc.DrawBitmap(standardRect, bmpNml); sl@0: break; sl@0: } sl@0: case 3: sl@0: { sl@0: INFO_PRINTF1(_L("... DrawBitmap() with scaling")); sl@0: iGc.DrawBitmap(scaledExtendedRect, bmpEx); sl@0: iGc.DrawBitmap(scaledStandardRect, bmpNml); sl@0: break; sl@0: } sl@0: case 4: sl@0: { sl@0: INFO_PRINTF1(_L("... DrawBitmapMasked()")); sl@0: iGc.DrawBitmapMasked(extendedRect, bmpEx, sizeInPixels, bmpMaskEx, EFalse); sl@0: iGc.DrawBitmapMasked(standardRect, bmpNml, sizeInPixels, bmpMaskNml, EFalse); sl@0: break; sl@0: } sl@0: case 5: sl@0: { sl@0: INFO_PRINTF1(_L("... DrawBitmapMasked() with scaling")); sl@0: iGc.DrawBitmapMasked(scaledExtendedRect, bmpEx, sizeInPixels, bmpMaskEx, EFalse); sl@0: iGc.DrawBitmapMasked(scaledStandardRect, bmpNml, sizeInPixels, bmpMaskNml, EFalse); sl@0: break; sl@0: } sl@0: case 6: sl@0: { sl@0: if(iIsFbs) sl@0: { sl@0: CFbsBitGc& fbsGc = static_cast(iGc); sl@0: INFO_PRINTF1(_L("... AlphaBlendBitmaps() - 1")); sl@0: iCallBack->TestTrue(fbsGc.AlphaBlendBitmaps(bmpExPos, bmpEx, bmpMaskEx, sizeInPixels, TPoint(0,0), bmpAlphaEx, TPoint(0,0)) == KErrNone); sl@0: iCallBack->TestTrue(fbsGc.AlphaBlendBitmaps(bmpNmlPos, bmpNml, bmpMaskNml, sizeInPixels, TPoint(0,0), bmpAlphaNml, TPoint(0,0)) == KErrNone); sl@0: } sl@0: break; sl@0: } sl@0: case 7: sl@0: { sl@0: if(iIsFbs) sl@0: { sl@0: CFbsBitGc& fbsGc = static_cast(iGc); sl@0: INFO_PRINTF1(_L("... AlphaBlendBitmaps() - 1 with offset")); sl@0: iCallBack->TestTrue(fbsGc.AlphaBlendBitmaps(bmpExPos, bmpEx, bmpMaskEx, TSize(sizeInPixels.iWidth-5, sizeInPixels.iHeight-10), TPoint(5,10), bmpAlphaEx, TPoint(3,2)) == KErrNone); sl@0: iCallBack->TestTrue(fbsGc.AlphaBlendBitmaps(bmpNmlPos, bmpNml, bmpMaskNml, TSize(sizeInPixels.iWidth-5, sizeInPixels.iHeight-10), TPoint(5,10), bmpAlphaNml, TPoint(3,2)) == KErrNone); sl@0: } sl@0: break; sl@0: } sl@0: case 8: sl@0: { sl@0: INFO_PRINTF1(_L("... AlphaBlendBitmaps() - 2")); sl@0: iCallBack->TestTrue(iGc.AlphaBlendBitmaps(bmpExPos, bmpEx, sizeInPixels, bmpAlphaEx, TPoint(0,0)) == KErrNone); sl@0: iCallBack->TestTrue(iGc.AlphaBlendBitmaps(bmpNmlPos, bmpNml, sizeInPixels, bmpAlphaNml, TPoint(0,0)) == KErrNone); sl@0: break; sl@0: } sl@0: case 9: sl@0: { sl@0: INFO_PRINTF1(_L("... AlphaBlendBitmaps() - 2 with offset")); sl@0: iCallBack->TestTrue(iGc.AlphaBlendBitmaps(bmpExPos, bmpEx, TSize(sizeInPixels.iWidth-16, sizeInPixels.iHeight-7), bmpAlphaEx, TPoint(16,7)) == KErrNone); sl@0: iCallBack->TestTrue(iGc.AlphaBlendBitmaps(bmpNmlPos, bmpNml, TSize(sizeInPixels.iWidth-16, sizeInPixels.iHeight-7), bmpAlphaNml, TPoint(16,7)) == KErrNone); sl@0: break; sl@0: } sl@0: default: sl@0: { sl@0: // Should not be reached sl@0: iCallBack->TestTrue(EFalse); sl@0: } sl@0: break; sl@0: } sl@0: sl@0: if (aTestRegionOfInterest) sl@0: { sl@0: // Cancel clipping rectangle and region if necessary sl@0: iGc.CancelClippingRegion(); sl@0: iGc.CancelClippingRect(); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(7, data); sl@0: } sl@0: sl@0: /** Test case function used to test the use of Extended Bitmaps as brush patterns within graphics contexts. sl@0: Utilised by GRAPHICS-BITGDI-0103 to test with CFbsBitGc, and by GRAPHICS-WSERV-0493 with CWindowGc. sl@0: @param aCaseNumber Case number to run - between 0 and (KNumBrushPatternTests - 1) sl@0: */ sl@0: void CTExtendedBitmapGc::TestBrushPatternL(TInt aCaseNumber) sl@0: { sl@0: const TInt KNumColors = 3; sl@0: const TRgb KColors[KNumColors] = {TRgb(0,255,255), TRgb(255,0,255), TRgb(255,255,0)}; sl@0: const TSize KBrushSize(63,63); sl@0: TInt dataSize = sizeof(KColors)+sizeof(TUint8); // estimate the data size sl@0: TUint8* data = new(ELeave) TUint8[dataSize]; sl@0: CleanupStack::PushL(data); sl@0: sl@0: // Write the colours to be used in the extended bitmap to the data sl@0: WriteExtendedBitmapInfoL(data, dataSize, KColors, EHorizontalStripe); sl@0: sl@0: // Create the extended bitmap to be used a a brush sl@0: CFbsBitmap* extendedBmp = new(ELeave) CFbsBitmap; sl@0: CleanupStack::PushL(extendedBmp); sl@0: TInt err = extendedBmp->CreateExtendedBitmap(KBrushSize, iDisplayMode, KUidExampleExtendedBitmap, data, dataSize); sl@0: iCallBack->TestTrue(err == KErrNone); sl@0: sl@0: // Create the standard bitmap to also be used as a brush sl@0: CFbsBitmap* standardBmp = new(ELeave) CFbsBitmap; sl@0: CleanupStack::PushL(standardBmp); sl@0: err = standardBmp->Create(KBrushSize, iDisplayMode); sl@0: iCallBack->TestTrue(err == KErrNone); sl@0: sl@0: // Create a bitmap device and a context so that the flag pattern can be drawn on sl@0: // the standard bitmap sl@0: CFbsBitmapDevice* bitDev = CFbsBitmapDevice::NewL(standardBmp); sl@0: CleanupStack::PushL(bitDev); sl@0: CFbsBitGc* bitGc; sl@0: err = bitDev->CreateContext(bitGc); sl@0: iCallBack->TestTrue(err == KErrNone); sl@0: CleanupStack::PushL(bitGc); sl@0: sl@0: // Draw the flag pattern to the standard bitmap if the draw mode is EDrawFlag, sl@0: // leave as white otehrwise sl@0: if (iDrawMode == EDrawFlag) sl@0: { sl@0: bitGc->SetPenStyle(CGraphicsContext::ENullPen); sl@0: bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: for (TInt i = 0; i < KNumColors; i++) sl@0: { sl@0: bitGc->SetBrushColor(KColors[i]); sl@0: bitGc->DrawRect(TRect(0,(KBrushSize.iHeight/3)*i,KBrushSize.iWidth,(KBrushSize.iHeight/3)*(i+1))); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(2, bitDev); sl@0: sl@0: // Create a screen device and a context to draw to sl@0: TSize scrSize = iGc.Device()->SizeInPixels(); sl@0: sl@0: TRect extendedShapeSize; sl@0: extendedShapeSize.SetRect(10,10,(scrSize.iWidth>>1)-10,scrSize.iHeight-10); sl@0: TRect standardShapeSize(extendedShapeSize); sl@0: standardShapeSize.Move(scrSize.iWidth>>1,0); sl@0: sl@0: TInt baseline = extendedShapeSize.Height() / 2 + iFont->AscentInPixels() / 2; sl@0: sl@0: iGc.SetBrushColor(KRgbBlue); sl@0: iGc.Clear(); sl@0: iGc.SetBrushColor(KRgbWhite); sl@0: iGc.UseBrushPattern(extendedBmp); sl@0: iGc.SetBrushStyle(CGraphicsContext::EPatternedBrush); sl@0: sl@0: switch (aCaseNumber) sl@0: { sl@0: case 0: //DrawPie() sl@0: { sl@0: INFO_PRINTF1(_L("Testing brush patterns with an extended bitmap")); sl@0: INFO_PRINTF1(_L("... DrawPie()")); sl@0: iGc.DrawPie(extendedShapeSize, TPoint(extendedShapeSize.iTl.iX,0), TPoint(extendedShapeSize.iBr.iX,0)); sl@0: iGc.UseBrushPattern(standardBmp); sl@0: iGc.DrawPie(standardShapeSize, TPoint(standardShapeSize.iTl.iX,0), TPoint(standardShapeSize.iBr.iX,0)); sl@0: break; sl@0: } sl@0: case 1: // DrawRoundRect() sl@0: { sl@0: INFO_PRINTF1(_L("... DrawRoundRect()")); sl@0: iGc.DrawRoundRect(extendedShapeSize, TSize(10,10)); sl@0: iGc.UseBrushPattern(standardBmp); sl@0: iGc.DrawRoundRect(standardShapeSize, TSize(10,10)); sl@0: break; sl@0: } sl@0: case 2: // DrawPolygon() sl@0: { sl@0: INFO_PRINTF1(_L("... DrawPolygon() 1")); sl@0: const TInt KNumPoints = 3; sl@0: CArrayFix* points = new(ELeave) CArrayFixFlat(KNumPoints); sl@0: CleanupStack::PushL(points); sl@0: points->AppendL(TPoint(extendedShapeSize.iTl.iX,extendedShapeSize.iTl.iY)); sl@0: points->AppendL(TPoint(extendedShapeSize.iBr.iX,extendedShapeSize.iBr.iY)); sl@0: points->AppendL(TPoint(extendedShapeSize.iTl.iX,extendedShapeSize.iBr.iY)); sl@0: iGc.DrawPolygon(points, CGraphicsContext::EWinding); sl@0: iGc.UseBrushPattern(standardBmp); sl@0: iGc.SetOrigin(TPoint(standardShapeSize.iTl.iX-10,0)); sl@0: iGc.DrawPolygon(points, CGraphicsContext::EWinding); sl@0: iGc.SetOrigin(TPoint(0,0)); sl@0: CleanupStack::PopAndDestroy(points); sl@0: break; sl@0: } sl@0: case 3: // DrawPolygon() sl@0: { sl@0: INFO_PRINTF1(_L("... DrawPolygon() 2")); sl@0: const TInt KNumPoints = 3; sl@0: TPoint* points = static_cast(User::AllocL(sizeof(TPoint)*KNumPoints)); sl@0: CleanupStack::PushL(points); sl@0: points[0] = TPoint(extendedShapeSize.iBr.iX,extendedShapeSize.iTl.iY); sl@0: points[1] = TPoint(extendedShapeSize.iBr.iX,extendedShapeSize.iBr.iY); sl@0: points[2] = TPoint(extendedShapeSize.iTl.iX,extendedShapeSize.iBr.iY/2); sl@0: iGc.DrawPolygon(points, KNumPoints, CGraphicsContext::EWinding); sl@0: iGc.UseBrushPattern(standardBmp); sl@0: iGc.SetOrigin(TPoint(standardShapeSize.iTl.iX-10,0)); sl@0: iGc.DrawPolygon(points, KNumPoints, CGraphicsContext::EWinding); sl@0: iGc.SetOrigin(TPoint(0,0)); sl@0: CleanupStack::PopAndDestroy(points); sl@0: break; sl@0: } sl@0: case 4: // DrawEllipse() sl@0: { sl@0: INFO_PRINTF1(_L("... DrawEllipse()")); sl@0: iGc.DrawEllipse(extendedShapeSize); sl@0: iGc.UseBrushPattern(standardBmp); sl@0: iGc.DrawEllipse(standardShapeSize); sl@0: break; sl@0: } sl@0: case 5: // DrawRect() sl@0: { sl@0: INFO_PRINTF1(_L("... DrawRect()")); sl@0: iGc.DrawRect(extendedShapeSize); sl@0: iGc.UseBrushPattern(standardBmp); sl@0: iGc.DrawRect(standardShapeSize); sl@0: break; sl@0: } sl@0: case 6: // DrawText() sl@0: { sl@0: INFO_PRINTF1(_L("... DrawText()")); sl@0: iGc.DrawText(_L("HELLO"), extendedShapeSize, baseline); sl@0: iGc.UseBrushPattern(standardBmp); sl@0: iGc.DrawText(_L("HELLO"), standardShapeSize, baseline); sl@0: break; sl@0: } sl@0: case 7: // DrawTextVertical() sl@0: { sl@0: INFO_PRINTF1(_L("... DrawTextVertical()")); sl@0: iGc.DrawTextVertical(_L("HELLO"), extendedShapeSize, baseline, EFalse); sl@0: iGc.UseBrushPattern(standardBmp); sl@0: iGc.DrawTextVertical(_L("HELLO"), standardShapeSize, baseline, EFalse); sl@0: break; sl@0: } sl@0: default: sl@0: { sl@0: // Should not be reached sl@0: iCallBack->TestTrue(EFalse); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(3, data); sl@0: } sl@0: sl@0: /** Helper method for creating and filling striped bitmaps equivalent to the extended bitmaps used in the test sl@0: CTExtendedBitmap::TestBitmapDrawingL(). sl@0: @param aBmpRet The newly created bitmap. sl@0: @param aSize The size of the bitmap to create. sl@0: @param aDisplayMode The display mode of the bitmap to create. sl@0: @param aColor1 The colour of the first stripe. sl@0: @param aColor2 The colour of the second stripe. sl@0: @param aColor3 The colour of the third stripe. sl@0: @param aStripeStyle Horizontal or vertical stripes, 0 for vertical stripe, 1 for horizontal stripes. sl@0: @return KErrNone if the bitmap was created successfully and returned in aBmpRet, one of the system sl@0: wide error codes otherwise. sl@0: @post Leaves aBmpRet on the clean up stack if it is created successfully sl@0: */ sl@0: void CTExtendedBitmapGc::CreateTestBitmapLC(CFbsBitmap*& aBmpRet, sl@0: const TSize& aSize, sl@0: TDisplayMode aDisplayMode, sl@0: const TRgb& aColor1, sl@0: const TRgb& aColor2, sl@0: const TRgb& aColor3, sl@0: TStripeStyle aStripeStyle) sl@0: { sl@0: const TInt KNumColors = 3; sl@0: TRgb colors[3] = {aColor1, aColor2, aColor3}; sl@0: sl@0: CFbsBitmap* bmp = new(ELeave) CFbsBitmap; sl@0: CleanupStack::PushL(bmp); // This gets left on the cleanup stack when the function returns sl@0: TInt err = bmp->Create(aSize, aDisplayMode); sl@0: User::LeaveIfError(err); sl@0: sl@0: CFbsBitmapDevice* bmpDev = CFbsBitmapDevice::NewL(bmp); sl@0: CleanupStack::PushL(bmpDev); sl@0: CFbsBitGc* gc; sl@0: err = bmpDev->CreateContext(gc); sl@0: User::LeaveIfError(err); sl@0: CleanupStack::PushL(gc); sl@0: sl@0: // Only draw stripes onto the test bitmap if the draw mode is EDrawFlag, otherwise sl@0: // it should be left as cleared to white sl@0: if (iDrawMode == EDrawFlag) sl@0: { sl@0: TInt outerStripeSize; sl@0: TInt middleStripeSize; sl@0: TRect stripeRect[3]; sl@0: sl@0: if (aStripeStyle == EHorizontalStripe) sl@0: { sl@0: outerStripeSize = aSize.iHeight/3; sl@0: middleStripeSize = aSize.iHeight-(outerStripeSize<<1); sl@0: stripeRect[0] = TRect(TPoint(0,0), TSize(aSize.iWidth,outerStripeSize)); sl@0: stripeRect[1] = TRect(TPoint(0,outerStripeSize), TSize(aSize.iWidth,middleStripeSize)); sl@0: stripeRect[2] = TRect(TPoint(0,outerStripeSize+middleStripeSize), TSize(aSize.iWidth,outerStripeSize)); sl@0: } sl@0: else if (aStripeStyle == EVerticalStripe) sl@0: { sl@0: outerStripeSize = aSize.iWidth/3; sl@0: middleStripeSize = aSize.iWidth-(outerStripeSize<<1); sl@0: stripeRect[0] = TRect(TPoint(0,0), TSize(outerStripeSize,aSize.iHeight)); sl@0: stripeRect[1] = TRect(TPoint(outerStripeSize,0), TSize(middleStripeSize,aSize.iHeight)); sl@0: stripeRect[2] = TRect(TPoint(outerStripeSize+middleStripeSize,0), TSize(outerStripeSize,aSize.iHeight)); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("Unsupported stripe style passed to CTExtendedBitmap::CreateTestBitmapLC: %d"), aStripeStyle); sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: for (TInt i = 0; i < KNumColors; i++) sl@0: { sl@0: gc->SetBrushColor(colors[i]); sl@0: gc->SetPenStyle(CGraphicsContext::ENullPen); sl@0: gc->SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: gc->DrawRect(stripeRect[i]); sl@0: } sl@0: } sl@0: sl@0: // Only pop the bitmap device and the gc, the created bitmap is left on the cleanup stack sl@0: CleanupStack::PopAndDestroy(2, bmpDev); sl@0: sl@0: aBmpRet = bmp; sl@0: } sl@0: sl@0: /** Helper function for writing colour and stripe information used when creating an extended bitmap to sl@0: a write stream. sl@0: @param aData A pointer to a buffer that is large enough to write three TRgb colours and one TUint8 to. sl@0: @param aDataSize The size of buffer pointed to by aData, the actual size written is returned here sl@0: @param aColourArray A pointer to an array of the three colours to be written to the buffer sl@0: @param aHorizontalStripe ETrue to use horizontal stripes, EFalse for vertcial stripes sl@0: */ sl@0: EXPORT_C void CTExtendedBitmapGc::WriteExtendedBitmapInfoL(TUint8* aData, sl@0: TInt& aDataSize, sl@0: const TRgb* aColorArray, sl@0: TStripeStyle aStripeStyle) sl@0: { sl@0: const TInt KNumColors = 3; sl@0: sl@0: // We expect an array of three colours sl@0: if (sizeof(aColorArray) == (sizeof(TRgb)*KNumColors)) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: RMemWriteStream ws; sl@0: ws.Open(aData, aDataSize); sl@0: CleanupClosePushL(ws); sl@0: ws << aColorArray[0] << aColorArray[1] << aColorArray[2] << static_cast(aStripeStyle); // horizontal stripe sl@0: aDataSize = ws.Sink()->TellL(MStreamBuf::EWrite).Offset(); // get the actual size written sl@0: CleanupStack::PopAndDestroy(1, &ws); sl@0: }