os/graphics/graphicsdeviceinterface/gdi/tgdi/TGraphicsContext.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2002-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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Simple stubs for testing purposes
    15 // 
    16 //
    17 
    18 /**
    19  @file
    20  @test
    21  @internalComponent Internal Symbian test code
    22 */
    23 
    24 #ifndef __TGRAPHICSCONTEXT_H__
    25 #define __TGRAPHICSCONTEXT_H__
    26 
    27 #include <gdi.h>
    28 
    29 /**
    30  *
    31  * Class to provide a dummy palette for test purposes
    32  *
    33  */
    34 
    35 
    36 class CTestPalette2 : public CPalette
    37 	{
    38 public:
    39 	enum { KNumEntries = 4 };
    40 	CTestPalette2()
    41 		{
    42 		iArray = iRgbArray;
    43 		iNumEntries = KNumEntries;
    44 		}
    45 	~CTestPalette2();
    46 private:
    47 	TRgb iRgbArray[KNumEntries];
    48 	};
    49 
    50 /**
    51  *
    52  * Class to provide a dummy graphics device for test purposes
    53  *
    54  */
    55 
    56 
    57 class CTestGraphicsDevice : public CBitmapDevice
    58 	{
    59 public:
    60 	static CTestGraphicsDevice* NewL(TSize aSizeInPixels);
    61 	~CTestGraphicsDevice();
    62 	void SetHorizontalTwipsToPixels(TInt aTwipsToPixels);
    63 	void SetVerticalTwipsToPixels(TInt aTwipsToPixels);
    64 	TDisplayMode DisplayMode() const;
    65 	TSize SizeInPixels() const;
    66 	TSize SizeInTwips() const;
    67 	TInt CreateContext(CGraphicsContext*& aGC);
    68 	TInt NumTypefaces() const;
    69 	void TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const;
    70 	TInt FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const;
    71 	void PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const;
    72 	void SetPalette(CPalette* aPalette);
    73 	TInt GetPalette(CPalette*& aPalette) const;
    74 
    75 	// from CBitmapFont
    76 	void GetPixel(TRgb& aColor,const TPoint& aPixel) const;
    77 	void GetScanLine(TDes8& aBuf,const TPoint& aStartPixel,TInt aLength,TDisplayMode aDispMode) const;
    78 	TInt AddFile(const TDesC& aName,TInt& aId);
    79 	void RemoveFile(TInt aId);
    80 	TInt GetNearestFontInPixels(CFont*& aFont,const TFontSpec& aFontSpec);
    81 	TInt GetNearestFontToDesignHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec);
    82 	TInt GetNearestFontToMaxHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight);
    83 	TInt FontHeightInPixels(TInt aTypefaceIndex,TInt aHeightIndex) const;
    84 
    85 	// from MGraphicsDeviceMap from CBitmapFont
    86 	TInt HorizontalTwipsToPixels(TInt aTwips) const;
    87 	TInt VerticalTwipsToPixels(TInt aTwips) const;
    88 	TInt HorizontalPixelsToTwips(TInt aPixels) const;
    89 	TInt VerticalPixelsToTwips(TInt aPixels) const;
    90 	TInt GetNearestFontInTwips(CFont*& aFont,const TFontSpec& aFontSpec);
    91 	TInt GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec);
    92 	TInt GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight);
    93 	void ReleaseFont(CFont* aFont);
    94 private:
    95 	CTestGraphicsDevice(TSize aSizeInPixels);
    96 private:
    97 	TSize iSize;
    98 	TInt iHorizontalTwipsToPixels;
    99 	TInt iVerticalTwipsToPixels;
   100 	CTestPalette2* iPalette;
   101 	};
   102 
   103 
   104 /**
   105  *
   106  * Class representing a line of displayed data
   107  *
   108  */
   109 
   110 
   111 class TTestGCDisplayLine 
   112 	{
   113 public:
   114 	TPoint iLinePos;
   115 	TBuf16<80> iLineData;
   116 
   117 	void Set(const TPoint& aLinePos, const TDesC16& aLineData)
   118 		{
   119 			iLineData = aLineData;
   120 			iLinePos = aLinePos;
   121 		}
   122 
   123 	TPtrC16 LineData() const
   124 		{
   125 			return TPtrC16(iLineData.Ptr(), iLineData.Length());
   126 		}
   127 
   128 	const TPoint& Position() const
   129 		{
   130 			return iLinePos;
   131 		}
   132 	
   133 	};
   134 
   135 /**
   136  *
   137  * Class to provide a dummy graphics context for test purposes
   138  *
   139  */
   140 
   141 class CTestGraphicsContext : public CGraphicsContext
   142 	{
   143 public:
   144 	enum TPanic
   145 		{
   146 		EUnimplemented,
   147 		ETypefaceIndexOutOfRange,
   148 		EUnknownFont
   149 		};
   150 	static void Panic(TInt aReason);
   151 	CTestGraphicsContext(CTestGraphicsDevice* aGd);
   152 	~CTestGraphicsContext();
   153 	CGraphicsDevice* Device() const;
   154 	void SetOrigin(const TPoint& aPos);
   155 	void SetDrawMode(TDrawMode aDrawingMode);
   156 	void SetClippingRect(const TRect& aRect);
   157 	void CancelClippingRect();
   158 	void Reset();
   159 	void UseFont(const CFont* aFont);
   160 	void DiscardFont();
   161 	void SetUnderlineStyle(TFontUnderline aUnderlineStyle);
   162 	void SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle);
   163 	void SetWordJustification(TInt aExcessWidth,TInt aNumGaps);
   164 	void SetCharJustification(TInt aExcessWidth,TInt aNumChars);
   165 	void SetPenColor(const TRgb& aColor);
   166 	void SetPenStyle(TPenStyle aPenStyle);
   167 	void SetPenSize(const TSize& aSize);
   168 	void SetBrushColor(const TRgb& aColor);
   169 	void SetBrushStyle(TBrushStyle aBrushStyle);
   170 	void SetBrushOrigin(const TPoint& aOrigin);
   171 	void UseBrushPattern(const CFbsBitmap* aBitmap);
   172 	void DiscardBrushPattern();
   173 	void MoveTo(const TPoint& aPoint);
   174 	void MoveBy(const TPoint& aVector);
   175 	void Plot(const TPoint& aPoint);
   176 	void DrawArc(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd);
   177 	void DrawLine(const TPoint& aPoint1,const TPoint& aPoint2);
   178 	void DrawLineTo(const TPoint& aPoint);
   179 	void DrawLineBy(const TPoint& aVector);
   180 	void DrawPolyLine(const CArrayFix<TPoint>* aPointList);
   181 	void DrawPolyLine(const TPoint* aPointList,TInt aNumPoints);
   182 	void DrawPie(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd);
   183 	void DrawEllipse(const TRect& aRect);
   184 	void DrawRect(const TRect& aRect);
   185 	void DrawRoundRect(const TRect& aRect,const TSize& aCornerSize);
   186 	TInt DrawPolygon(const CArrayFix<TPoint>* aPointList,TFillRule aFillRule);
   187 	TInt DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule);
   188 	void DrawBitmap(const TPoint& aTopLeft,const CFbsBitmap* aSource);
   189 	void DrawBitmap(const TRect& aDestRect,const CFbsBitmap* aSource);
   190 	void DrawBitmap(const TRect& aDestRect,const CFbsBitmap* aSource,const TRect& aSourceRect);
   191 	void DrawBitmapMasked(const TRect& aDestRect,const CFbsBitmap* aBitmap,const TRect& aSourceRect,const CFbsBitmap* aMaskBitmap,TBool aInvertMask);
   192 	void DrawBitmapMasked(const TRect& aDestRect,const CWsBitmap* aBitmap,const TRect& aSourceRect,const CWsBitmap* aMaskBitmap,TBool aInvertMask);
   193 	void DrawText(const TDesC& aText,const TPoint& aPosition);
   194 	void DrawText(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,TTextAlign aAlignment,
   195 		TInt aLeftMargin);
   196 	void DrawText(const TDesC& aText, const TPoint& aPosition,
   197 		const TDrawTextParam&);
   198 		
   199 	void MapColors(const TRect &aRect,const TRgb *aColors,TInt aNumPairs,TBool aMapForwards);
   200 	TInt SetClippingRegion(const TRegion &aRegion);
   201 	void CancelClippingRegion();
   202 	void DrawTextVertical(const TDesC& aText,const TPoint& aPos,TBool aUp);
   203 	void DrawTextVertical(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,TBool aUp,TTextAlign aVert=ELeft,TInt aMargin=0);
   204 
   205 	void ClearDrawnArea()
   206 		{
   207 		iDrawnArea.iTl.iX = iDrawnArea.iBr.iX = iDrawnArea.iTl.iY = iDrawnArea.iBr.iY = 0;
   208 		}
   209 	TRect DrawnArea() const
   210 		{
   211 		return iDrawnArea;
   212 		}
   213 	void ClearAreaDrawnWithCondition()
   214 		{
   215 		iAreaDrawnWithCondition.iTl.iX = iAreaDrawnWithCondition.iBr.iX
   216 			= iAreaDrawnWithCondition.iTl.iY = iAreaDrawnWithCondition.iBr.iY = 0;
   217 		}
   218 	const TRect& AreaDrawnWithCondition() const
   219 		{
   220 		return iAreaDrawnWithCondition;
   221 		}
   222 	void AddRectToDrawnArea(const TRect& aRect);
   223 	void AddPointToDrawnArea(const TPoint& aPoint);
   224 
   225 	const TTestGCDisplayLine& DisplayLine(TInt index)
   226 		{
   227 			return iLineArray[index];
   228 		}
   229 private:
   230 	CTestGraphicsDevice* iGd;
   231 	TPoint iOrigin;
   232 	TDrawMode iDrawMode;
   233 	const CFont* iFont;
   234 	TSize iPenSize;
   235 	TPoint iCurrentPos;
   236 	TRect iDrawnArea;
   237 	TRect iAreaDrawnWithCondition;
   238 	TInt iPenColorIndex;
   239 	RArray<TTestGCDisplayLine> iLineArray;
   240 	};
   241 
   242 /**
   243  *
   244  * Class to provide a dummy font for test purposes
   245  *
   246  */
   247 class CTestFont : public CFont
   248 	{
   249 public:
   250 	virtual TUid DoTypeUid() const;
   251 	TInt DoHeightInPixels() const;
   252 	TInt DoAscentInPixels() const;
   253 	TInt DoCharWidthInPixels(TChar aChar) const;
   254 	TInt DoTextWidthInPixels(const TDesC& aText) const;
   255 	TInt DoBaselineOffsetInPixels() const;
   256 	TInt DoTextCount(const TDesC& aText,TInt aWidthInPixels) const;
   257 	TInt DoTextCount(const TDesC& aText,TInt aWidthInPixels,TInt& aExcessWidthInPixels) const;
   258 	TInt DoMaxCharWidthInPixels() const;
   259 	TInt DoMaxNormalCharWidthInPixels() const;
   260 	TFontSpec DoFontSpecInTwips() const;
   261 	TCharacterDataAvailability DoGetCharacterData(TUint aCode,
   262 		TOpenFontCharMetrics& aMetrics,const TUint8*& aBitmap,TSize& aBitmapSize) const;
   263 	};
   264 
   265 
   266 #endif /* __TGRAPHICSCONTEXT_H__ */