1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/gdi/tgdi/TGraphicsContext.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,266 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Simple stubs for testing purposes
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file
1.23 + @test
1.24 + @internalComponent Internal Symbian test code
1.25 +*/
1.26 +
1.27 +#ifndef __TGRAPHICSCONTEXT_H__
1.28 +#define __TGRAPHICSCONTEXT_H__
1.29 +
1.30 +#include <gdi.h>
1.31 +
1.32 +/**
1.33 + *
1.34 + * Class to provide a dummy palette for test purposes
1.35 + *
1.36 + */
1.37 +
1.38 +
1.39 +class CTestPalette2 : public CPalette
1.40 + {
1.41 +public:
1.42 + enum { KNumEntries = 4 };
1.43 + CTestPalette2()
1.44 + {
1.45 + iArray = iRgbArray;
1.46 + iNumEntries = KNumEntries;
1.47 + }
1.48 + ~CTestPalette2();
1.49 +private:
1.50 + TRgb iRgbArray[KNumEntries];
1.51 + };
1.52 +
1.53 +/**
1.54 + *
1.55 + * Class to provide a dummy graphics device for test purposes
1.56 + *
1.57 + */
1.58 +
1.59 +
1.60 +class CTestGraphicsDevice : public CBitmapDevice
1.61 + {
1.62 +public:
1.63 + static CTestGraphicsDevice* NewL(TSize aSizeInPixels);
1.64 + ~CTestGraphicsDevice();
1.65 + void SetHorizontalTwipsToPixels(TInt aTwipsToPixels);
1.66 + void SetVerticalTwipsToPixels(TInt aTwipsToPixels);
1.67 + TDisplayMode DisplayMode() const;
1.68 + TSize SizeInPixels() const;
1.69 + TSize SizeInTwips() const;
1.70 + TInt CreateContext(CGraphicsContext*& aGC);
1.71 + TInt NumTypefaces() const;
1.72 + void TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const;
1.73 + TInt FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const;
1.74 + void PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const;
1.75 + void SetPalette(CPalette* aPalette);
1.76 + TInt GetPalette(CPalette*& aPalette) const;
1.77 +
1.78 + // from CBitmapFont
1.79 + void GetPixel(TRgb& aColor,const TPoint& aPixel) const;
1.80 + void GetScanLine(TDes8& aBuf,const TPoint& aStartPixel,TInt aLength,TDisplayMode aDispMode) const;
1.81 + TInt AddFile(const TDesC& aName,TInt& aId);
1.82 + void RemoveFile(TInt aId);
1.83 + TInt GetNearestFontInPixels(CFont*& aFont,const TFontSpec& aFontSpec);
1.84 + TInt GetNearestFontToDesignHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec);
1.85 + TInt GetNearestFontToMaxHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight);
1.86 + TInt FontHeightInPixels(TInt aTypefaceIndex,TInt aHeightIndex) const;
1.87 +
1.88 + // from MGraphicsDeviceMap from CBitmapFont
1.89 + TInt HorizontalTwipsToPixels(TInt aTwips) const;
1.90 + TInt VerticalTwipsToPixels(TInt aTwips) const;
1.91 + TInt HorizontalPixelsToTwips(TInt aPixels) const;
1.92 + TInt VerticalPixelsToTwips(TInt aPixels) const;
1.93 + TInt GetNearestFontInTwips(CFont*& aFont,const TFontSpec& aFontSpec);
1.94 + TInt GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec);
1.95 + TInt GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight);
1.96 + void ReleaseFont(CFont* aFont);
1.97 +private:
1.98 + CTestGraphicsDevice(TSize aSizeInPixels);
1.99 +private:
1.100 + TSize iSize;
1.101 + TInt iHorizontalTwipsToPixels;
1.102 + TInt iVerticalTwipsToPixels;
1.103 + CTestPalette2* iPalette;
1.104 + };
1.105 +
1.106 +
1.107 +/**
1.108 + *
1.109 + * Class representing a line of displayed data
1.110 + *
1.111 + */
1.112 +
1.113 +
1.114 +class TTestGCDisplayLine
1.115 + {
1.116 +public:
1.117 + TPoint iLinePos;
1.118 + TBuf16<80> iLineData;
1.119 +
1.120 + void Set(const TPoint& aLinePos, const TDesC16& aLineData)
1.121 + {
1.122 + iLineData = aLineData;
1.123 + iLinePos = aLinePos;
1.124 + }
1.125 +
1.126 + TPtrC16 LineData() const
1.127 + {
1.128 + return TPtrC16(iLineData.Ptr(), iLineData.Length());
1.129 + }
1.130 +
1.131 + const TPoint& Position() const
1.132 + {
1.133 + return iLinePos;
1.134 + }
1.135 +
1.136 + };
1.137 +
1.138 +/**
1.139 + *
1.140 + * Class to provide a dummy graphics context for test purposes
1.141 + *
1.142 + */
1.143 +
1.144 +class CTestGraphicsContext : public CGraphicsContext
1.145 + {
1.146 +public:
1.147 + enum TPanic
1.148 + {
1.149 + EUnimplemented,
1.150 + ETypefaceIndexOutOfRange,
1.151 + EUnknownFont
1.152 + };
1.153 + static void Panic(TInt aReason);
1.154 + CTestGraphicsContext(CTestGraphicsDevice* aGd);
1.155 + ~CTestGraphicsContext();
1.156 + CGraphicsDevice* Device() const;
1.157 + void SetOrigin(const TPoint& aPos);
1.158 + void SetDrawMode(TDrawMode aDrawingMode);
1.159 + void SetClippingRect(const TRect& aRect);
1.160 + void CancelClippingRect();
1.161 + void Reset();
1.162 + void UseFont(const CFont* aFont);
1.163 + void DiscardFont();
1.164 + void SetUnderlineStyle(TFontUnderline aUnderlineStyle);
1.165 + void SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle);
1.166 + void SetWordJustification(TInt aExcessWidth,TInt aNumGaps);
1.167 + void SetCharJustification(TInt aExcessWidth,TInt aNumChars);
1.168 + void SetPenColor(const TRgb& aColor);
1.169 + void SetPenStyle(TPenStyle aPenStyle);
1.170 + void SetPenSize(const TSize& aSize);
1.171 + void SetBrushColor(const TRgb& aColor);
1.172 + void SetBrushStyle(TBrushStyle aBrushStyle);
1.173 + void SetBrushOrigin(const TPoint& aOrigin);
1.174 + void UseBrushPattern(const CFbsBitmap* aBitmap);
1.175 + void DiscardBrushPattern();
1.176 + void MoveTo(const TPoint& aPoint);
1.177 + void MoveBy(const TPoint& aVector);
1.178 + void Plot(const TPoint& aPoint);
1.179 + void DrawArc(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd);
1.180 + void DrawLine(const TPoint& aPoint1,const TPoint& aPoint2);
1.181 + void DrawLineTo(const TPoint& aPoint);
1.182 + void DrawLineBy(const TPoint& aVector);
1.183 + void DrawPolyLine(const CArrayFix<TPoint>* aPointList);
1.184 + void DrawPolyLine(const TPoint* aPointList,TInt aNumPoints);
1.185 + void DrawPie(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd);
1.186 + void DrawEllipse(const TRect& aRect);
1.187 + void DrawRect(const TRect& aRect);
1.188 + void DrawRoundRect(const TRect& aRect,const TSize& aCornerSize);
1.189 + TInt DrawPolygon(const CArrayFix<TPoint>* aPointList,TFillRule aFillRule);
1.190 + TInt DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule);
1.191 + void DrawBitmap(const TPoint& aTopLeft,const CFbsBitmap* aSource);
1.192 + void DrawBitmap(const TRect& aDestRect,const CFbsBitmap* aSource);
1.193 + void DrawBitmap(const TRect& aDestRect,const CFbsBitmap* aSource,const TRect& aSourceRect);
1.194 + void DrawBitmapMasked(const TRect& aDestRect,const CFbsBitmap* aBitmap,const TRect& aSourceRect,const CFbsBitmap* aMaskBitmap,TBool aInvertMask);
1.195 + void DrawBitmapMasked(const TRect& aDestRect,const CWsBitmap* aBitmap,const TRect& aSourceRect,const CWsBitmap* aMaskBitmap,TBool aInvertMask);
1.196 + void DrawText(const TDesC& aText,const TPoint& aPosition);
1.197 + void DrawText(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,TTextAlign aAlignment,
1.198 + TInt aLeftMargin);
1.199 + void DrawText(const TDesC& aText, const TPoint& aPosition,
1.200 + const TDrawTextParam&);
1.201 +
1.202 + void MapColors(const TRect &aRect,const TRgb *aColors,TInt aNumPairs,TBool aMapForwards);
1.203 + TInt SetClippingRegion(const TRegion &aRegion);
1.204 + void CancelClippingRegion();
1.205 + void DrawTextVertical(const TDesC& aText,const TPoint& aPos,TBool aUp);
1.206 + void DrawTextVertical(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,TBool aUp,TTextAlign aVert=ELeft,TInt aMargin=0);
1.207 +
1.208 + void ClearDrawnArea()
1.209 + {
1.210 + iDrawnArea.iTl.iX = iDrawnArea.iBr.iX = iDrawnArea.iTl.iY = iDrawnArea.iBr.iY = 0;
1.211 + }
1.212 + TRect DrawnArea() const
1.213 + {
1.214 + return iDrawnArea;
1.215 + }
1.216 + void ClearAreaDrawnWithCondition()
1.217 + {
1.218 + iAreaDrawnWithCondition.iTl.iX = iAreaDrawnWithCondition.iBr.iX
1.219 + = iAreaDrawnWithCondition.iTl.iY = iAreaDrawnWithCondition.iBr.iY = 0;
1.220 + }
1.221 + const TRect& AreaDrawnWithCondition() const
1.222 + {
1.223 + return iAreaDrawnWithCondition;
1.224 + }
1.225 + void AddRectToDrawnArea(const TRect& aRect);
1.226 + void AddPointToDrawnArea(const TPoint& aPoint);
1.227 +
1.228 + const TTestGCDisplayLine& DisplayLine(TInt index)
1.229 + {
1.230 + return iLineArray[index];
1.231 + }
1.232 +private:
1.233 + CTestGraphicsDevice* iGd;
1.234 + TPoint iOrigin;
1.235 + TDrawMode iDrawMode;
1.236 + const CFont* iFont;
1.237 + TSize iPenSize;
1.238 + TPoint iCurrentPos;
1.239 + TRect iDrawnArea;
1.240 + TRect iAreaDrawnWithCondition;
1.241 + TInt iPenColorIndex;
1.242 + RArray<TTestGCDisplayLine> iLineArray;
1.243 + };
1.244 +
1.245 +/**
1.246 + *
1.247 + * Class to provide a dummy font for test purposes
1.248 + *
1.249 + */
1.250 +class CTestFont : public CFont
1.251 + {
1.252 +public:
1.253 + virtual TUid DoTypeUid() const;
1.254 + TInt DoHeightInPixels() const;
1.255 + TInt DoAscentInPixels() const;
1.256 + TInt DoCharWidthInPixels(TChar aChar) const;
1.257 + TInt DoTextWidthInPixels(const TDesC& aText) const;
1.258 + TInt DoBaselineOffsetInPixels() const;
1.259 + TInt DoTextCount(const TDesC& aText,TInt aWidthInPixels) const;
1.260 + TInt DoTextCount(const TDesC& aText,TInt aWidthInPixels,TInt& aExcessWidthInPixels) const;
1.261 + TInt DoMaxCharWidthInPixels() const;
1.262 + TInt DoMaxNormalCharWidthInPixels() const;
1.263 + TFontSpec DoFontSpecInTwips() const;
1.264 + TCharacterDataAvailability DoGetCharacterData(TUint aCode,
1.265 + TOpenFontCharMetrics& aMetrics,const TUint8*& aBitmap,TSize& aBitmapSize) const;
1.266 + };
1.267 +
1.268 +
1.269 +#endif /* __TGRAPHICSCONTEXT_H__ */