sl@0: // Copyright (c) 2002-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: // Simple stubs for testing purposes sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent Internal Symbian test code sl@0: */ sl@0: sl@0: #ifndef __TGRAPHICSCONTEXT_H__ sl@0: #define __TGRAPHICSCONTEXT_H__ sl@0: sl@0: #include sl@0: sl@0: /** sl@0: * sl@0: * Class to provide a dummy palette for test purposes sl@0: * sl@0: */ sl@0: sl@0: sl@0: class CTestPalette2 : public CPalette sl@0: { sl@0: public: sl@0: enum { KNumEntries = 4 }; sl@0: CTestPalette2() sl@0: { sl@0: iArray = iRgbArray; sl@0: iNumEntries = KNumEntries; sl@0: } sl@0: ~CTestPalette2(); sl@0: private: sl@0: TRgb iRgbArray[KNumEntries]; sl@0: }; sl@0: sl@0: /** sl@0: * sl@0: * Class to provide a dummy graphics device for test purposes sl@0: * sl@0: */ sl@0: sl@0: sl@0: class CTestGraphicsDevice : public CBitmapDevice sl@0: { sl@0: public: sl@0: static CTestGraphicsDevice* NewL(TSize aSizeInPixels); sl@0: ~CTestGraphicsDevice(); sl@0: void SetHorizontalTwipsToPixels(TInt aTwipsToPixels); sl@0: void SetVerticalTwipsToPixels(TInt aTwipsToPixels); sl@0: TDisplayMode DisplayMode() const; sl@0: TSize SizeInPixels() const; sl@0: TSize SizeInTwips() const; sl@0: TInt CreateContext(CGraphicsContext*& aGC); sl@0: TInt NumTypefaces() const; sl@0: void TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const; sl@0: TInt FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const; sl@0: void PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const; sl@0: void SetPalette(CPalette* aPalette); sl@0: TInt GetPalette(CPalette*& aPalette) const; sl@0: sl@0: // from CBitmapFont sl@0: void GetPixel(TRgb& aColor,const TPoint& aPixel) const; sl@0: void GetScanLine(TDes8& aBuf,const TPoint& aStartPixel,TInt aLength,TDisplayMode aDispMode) const; sl@0: TInt AddFile(const TDesC& aName,TInt& aId); sl@0: void RemoveFile(TInt aId); sl@0: TInt GetNearestFontInPixels(CFont*& aFont,const TFontSpec& aFontSpec); sl@0: TInt GetNearestFontToDesignHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec); sl@0: TInt GetNearestFontToMaxHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight); sl@0: TInt FontHeightInPixels(TInt aTypefaceIndex,TInt aHeightIndex) const; sl@0: sl@0: // from MGraphicsDeviceMap from CBitmapFont sl@0: TInt HorizontalTwipsToPixels(TInt aTwips) const; sl@0: TInt VerticalTwipsToPixels(TInt aTwips) const; sl@0: TInt HorizontalPixelsToTwips(TInt aPixels) const; sl@0: TInt VerticalPixelsToTwips(TInt aPixels) const; sl@0: TInt GetNearestFontInTwips(CFont*& aFont,const TFontSpec& aFontSpec); sl@0: TInt GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec); sl@0: TInt GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight); sl@0: void ReleaseFont(CFont* aFont); sl@0: private: sl@0: CTestGraphicsDevice(TSize aSizeInPixels); sl@0: private: sl@0: TSize iSize; sl@0: TInt iHorizontalTwipsToPixels; sl@0: TInt iVerticalTwipsToPixels; sl@0: CTestPalette2* iPalette; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * sl@0: * Class representing a line of displayed data sl@0: * sl@0: */ sl@0: sl@0: sl@0: class TTestGCDisplayLine sl@0: { sl@0: public: sl@0: TPoint iLinePos; sl@0: TBuf16<80> iLineData; sl@0: sl@0: void Set(const TPoint& aLinePos, const TDesC16& aLineData) sl@0: { sl@0: iLineData = aLineData; sl@0: iLinePos = aLinePos; sl@0: } sl@0: sl@0: TPtrC16 LineData() const sl@0: { sl@0: return TPtrC16(iLineData.Ptr(), iLineData.Length()); sl@0: } sl@0: sl@0: const TPoint& Position() const sl@0: { sl@0: return iLinePos; sl@0: } sl@0: sl@0: }; sl@0: sl@0: /** sl@0: * sl@0: * Class to provide a dummy graphics context for test purposes sl@0: * sl@0: */ sl@0: sl@0: class CTestGraphicsContext : public CGraphicsContext sl@0: { sl@0: public: sl@0: enum TPanic sl@0: { sl@0: EUnimplemented, sl@0: ETypefaceIndexOutOfRange, sl@0: EUnknownFont sl@0: }; sl@0: static void Panic(TInt aReason); sl@0: CTestGraphicsContext(CTestGraphicsDevice* aGd); sl@0: ~CTestGraphicsContext(); sl@0: CGraphicsDevice* Device() const; sl@0: void SetOrigin(const TPoint& aPos); sl@0: void SetDrawMode(TDrawMode aDrawingMode); sl@0: void SetClippingRect(const TRect& aRect); sl@0: void CancelClippingRect(); sl@0: void Reset(); sl@0: void UseFont(const CFont* aFont); sl@0: void DiscardFont(); sl@0: void SetUnderlineStyle(TFontUnderline aUnderlineStyle); sl@0: void SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle); sl@0: void SetWordJustification(TInt aExcessWidth,TInt aNumGaps); sl@0: void SetCharJustification(TInt aExcessWidth,TInt aNumChars); sl@0: void SetPenColor(const TRgb& aColor); sl@0: void SetPenStyle(TPenStyle aPenStyle); sl@0: void SetPenSize(const TSize& aSize); sl@0: void SetBrushColor(const TRgb& aColor); sl@0: void SetBrushStyle(TBrushStyle aBrushStyle); sl@0: void SetBrushOrigin(const TPoint& aOrigin); sl@0: void UseBrushPattern(const CFbsBitmap* aBitmap); sl@0: void DiscardBrushPattern(); sl@0: void MoveTo(const TPoint& aPoint); sl@0: void MoveBy(const TPoint& aVector); sl@0: void Plot(const TPoint& aPoint); sl@0: void DrawArc(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd); sl@0: void DrawLine(const TPoint& aPoint1,const TPoint& aPoint2); sl@0: void DrawLineTo(const TPoint& aPoint); sl@0: void DrawLineBy(const TPoint& aVector); sl@0: void DrawPolyLine(const CArrayFix* aPointList); sl@0: void DrawPolyLine(const TPoint* aPointList,TInt aNumPoints); sl@0: void DrawPie(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd); sl@0: void DrawEllipse(const TRect& aRect); sl@0: void DrawRect(const TRect& aRect); sl@0: void DrawRoundRect(const TRect& aRect,const TSize& aCornerSize); sl@0: TInt DrawPolygon(const CArrayFix* aPointList,TFillRule aFillRule); sl@0: TInt DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule); sl@0: void DrawBitmap(const TPoint& aTopLeft,const CFbsBitmap* aSource); sl@0: void DrawBitmap(const TRect& aDestRect,const CFbsBitmap* aSource); sl@0: void DrawBitmap(const TRect& aDestRect,const CFbsBitmap* aSource,const TRect& aSourceRect); sl@0: void DrawBitmapMasked(const TRect& aDestRect,const CFbsBitmap* aBitmap,const TRect& aSourceRect,const CFbsBitmap* aMaskBitmap,TBool aInvertMask); sl@0: void DrawBitmapMasked(const TRect& aDestRect,const CWsBitmap* aBitmap,const TRect& aSourceRect,const CWsBitmap* aMaskBitmap,TBool aInvertMask); sl@0: void DrawText(const TDesC& aText,const TPoint& aPosition); sl@0: void DrawText(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,TTextAlign aAlignment, sl@0: TInt aLeftMargin); sl@0: void DrawText(const TDesC& aText, const TPoint& aPosition, sl@0: const TDrawTextParam&); sl@0: sl@0: void MapColors(const TRect &aRect,const TRgb *aColors,TInt aNumPairs,TBool aMapForwards); sl@0: TInt SetClippingRegion(const TRegion &aRegion); sl@0: void CancelClippingRegion(); sl@0: void DrawTextVertical(const TDesC& aText,const TPoint& aPos,TBool aUp); sl@0: void DrawTextVertical(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,TBool aUp,TTextAlign aVert=ELeft,TInt aMargin=0); sl@0: sl@0: void ClearDrawnArea() sl@0: { sl@0: iDrawnArea.iTl.iX = iDrawnArea.iBr.iX = iDrawnArea.iTl.iY = iDrawnArea.iBr.iY = 0; sl@0: } sl@0: TRect DrawnArea() const sl@0: { sl@0: return iDrawnArea; sl@0: } sl@0: void ClearAreaDrawnWithCondition() sl@0: { sl@0: iAreaDrawnWithCondition.iTl.iX = iAreaDrawnWithCondition.iBr.iX sl@0: = iAreaDrawnWithCondition.iTl.iY = iAreaDrawnWithCondition.iBr.iY = 0; sl@0: } sl@0: const TRect& AreaDrawnWithCondition() const sl@0: { sl@0: return iAreaDrawnWithCondition; sl@0: } sl@0: void AddRectToDrawnArea(const TRect& aRect); sl@0: void AddPointToDrawnArea(const TPoint& aPoint); sl@0: sl@0: const TTestGCDisplayLine& DisplayLine(TInt index) sl@0: { sl@0: return iLineArray[index]; sl@0: } sl@0: private: sl@0: CTestGraphicsDevice* iGd; sl@0: TPoint iOrigin; sl@0: TDrawMode iDrawMode; sl@0: const CFont* iFont; sl@0: TSize iPenSize; sl@0: TPoint iCurrentPos; sl@0: TRect iDrawnArea; sl@0: TRect iAreaDrawnWithCondition; sl@0: TInt iPenColorIndex; sl@0: RArray iLineArray; sl@0: }; sl@0: sl@0: /** sl@0: * sl@0: * Class to provide a dummy font for test purposes sl@0: * sl@0: */ sl@0: class CTestFont : public CFont sl@0: { sl@0: public: sl@0: virtual TUid DoTypeUid() const; sl@0: TInt DoHeightInPixels() const; sl@0: TInt DoAscentInPixels() const; sl@0: TInt DoCharWidthInPixels(TChar aChar) const; sl@0: TInt DoTextWidthInPixels(const TDesC& aText) const; sl@0: TInt DoBaselineOffsetInPixels() const; sl@0: TInt DoTextCount(const TDesC& aText,TInt aWidthInPixels) const; sl@0: TInt DoTextCount(const TDesC& aText,TInt aWidthInPixels,TInt& aExcessWidthInPixels) const; sl@0: TInt DoMaxCharWidthInPixels() const; sl@0: TInt DoMaxNormalCharWidthInPixels() const; sl@0: TFontSpec DoFontSpecInTwips() const; sl@0: TCharacterDataAvailability DoGetCharacterData(TUint aCode, sl@0: TOpenFontCharMetrics& aMetrics,const TUint8*& aBitmap,TSize& aBitmapSize) const; sl@0: }; sl@0: sl@0: sl@0: #endif /* __TGRAPHICSCONTEXT_H__ */