First public contribution.
2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Simple stubs for testing purposes
20 #ifndef __TGRAPHICSCONTEXT_H__
21 #define __TGRAPHICSCONTEXT_H__
25 /** Representing a line of displayed data.
27 class TTestGCDisplayLine
33 TTestGCDisplayLine() : iLinePos(0,0) {}
34 TTestGCDisplayLine(const TInt aX, const TInt aY, const TDesC16& aLineData) : iLinePos(aX, aY)
36 iLineData = aLineData;
38 TTestGCDisplayLine(const TPoint aLinePos, const TDesC16& aLineData) : iLinePos(aLinePos)
40 iLineData = aLineData;
43 void Set(const TPoint& aLinePos, const TDesC16& aLineData)
45 iLineData = aLineData;
49 TPtrC16 LineData() const
51 return TPtrC16(iLineData.Ptr(), iLineData.Length());
54 const TPoint& Position() const
60 /** Holds a reference-counted array of TTestGCDisplayLines. Copy makes another
61 reference to the same array, allowing arrays to be shared between graphics
65 class CLineArray : public CBase
70 void ConstructL(TInt aGranularity);
71 /** Make this refer to the same array as aOther currently does. */
72 void Copy(const CLineArray& aOther);
73 /** Removes this reference to the array. Deletes the array if all
74 references have been removed. */
76 void ResetLineArray();
77 const TTestGCDisplayLine& Line(TInt aIndex);
78 void AddLineL(TTestGCDisplayLine& aLine);
80 /** Finds a TTestGCDisplayLine with aText contained somewhere in its data.
81 Returns 0 if there is no such line. */
82 const TTestGCDisplayLine* Find(const TDesC& aText);
83 /** Disables any more adding to the line array, and disables it
84 in any CLineArrays copied from this one. */
85 void Disable() { iArrayIsEnabled = EFalse; }
86 /** Re-enables adding to the line array, and in any CLineArrays copied from
88 void Enable() { iArrayIsEnabled = ETrue; }
90 // CLineArrays copied from one another form a circular doubly-linked
91 // list. This is roughly equivalent to reference-counting; when iPrev and
92 // iNext point to 'this', this is the same as the reference count being 1.
93 mutable const CLineArray* iPrev;
94 mutable const CLineArray* iNext;
95 TBool iArrayIsEnabled;
96 RArray<TTestGCDisplayLine>* iArray;
99 class CTestPalette : public CPalette
102 enum { KNumEntries = 4 };
106 iNumEntries = KNumEntries;
110 // Stop iRgbArray from being deleted by ~CPalette.
111 // Ideally, iRgbArray should be removed in favour of
112 // allocating one on the heap.
116 TRgb iRgbArray[KNumEntries];
119 class CTestGraphicsDevice : public CWsScreenDevice
122 static CTestGraphicsDevice* NewL(TSize aSizeInPixels, RWsSession* aWsSession);
123 CTestGraphicsDevice(TSize aSizeInPixels, RWsSession* aWsSession);
124 CTestGraphicsDevice(TSize aSizeInPixels);
125 void SetHorizontalTwipsToPixels(TInt aTwipsToPixels);
126 void SetVerticalTwipsToPixels(TInt aTwipsToPixels);
127 TDisplayMode DisplayMode() const;
128 TSize SizeInPixels() const;
129 TSize SizeInTwips() const;
130 TInt CreateContext(CGraphicsContext*& aGC);
131 TInt CreateContext(CWindowGc*& aGC);
132 TInt NumTypefaces() const;
133 void TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const;
134 TInt FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const;
135 void PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const;
136 void SetPalette(CPalette* aPalette);
137 TInt GetPalette(CPalette*& aPalette) const;
139 // from CBitmapDevice
140 void GetPixel(TRgb& aColor,const TPoint& aPixel) const;
141 void GetScanLine(TDes8& aBuf,const TPoint& aStartPixel,TInt aLength,TDisplayMode aDispMode) const;
142 TInt AddFile(const TDesC& aName,TInt& aId);
143 void RemoveFile(TInt aId);
144 TInt GetNearestFontInPixels(CFont*& aFont,const TFontSpec& aFontSpec);
145 TInt FontHeightInPixels(TInt aTypefaceIndex,TInt aHeightIndex) const;
147 // from MGraphicsDeviceMap from CBitmapDevice
148 TInt HorizontalTwipsToPixels(TInt aTwips) const;
149 TInt VerticalTwipsToPixels(TInt aTwips) const;
150 TInt HorizontalPixelsToTwips(TInt aPixels) const;
151 TInt VerticalPixelsToTwips(TInt aPixels) const;
152 TInt GetNearestFontInTwips(CFont*& aFont,const TFontSpec& aFontSpec);
153 void ReleaseFont(CFont* aFont);
156 void ClearDrawnArea()
158 iDrawnArea.iTl.iX = iDrawnArea.iBr.iX = iDrawnArea.iTl.iY = iDrawnArea.iBr.iY = 0;
160 TRect DrawnArea() const
164 void ClearAreaDrawnWithCondition()
166 iAreaDrawnWithCondition.iTl.iX = iAreaDrawnWithCondition.iBr.iX
167 = iAreaDrawnWithCondition.iTl.iY = iAreaDrawnWithCondition.iBr.iY = 0;
169 const TRect& AreaDrawnWithCondition() const
171 return iAreaDrawnWithCondition;
173 void AddRectToDrawnArea(const TRect& aRect, TBool aCondition);
174 CLineArray& LineArray() { return iLineArray; }
175 void SetLineArray(const CLineArray& aLineArray)
177 iLineArray.Copy(aLineArray);
180 // new functions for testing area
181 void SetTestingArea(TRect& aTestingArea);
182 void AddTestingArea(TRect& moreTestingArea);
183 void ClearTestingArea()
185 iTestingArea.iTl.iX = iTestingArea.iBr.iX
186 = iTestingArea.iTl.iY = iTestingArea.iBr.iY = 0;
188 // check if anything has been drawn on testing area
189 inline TBool HasDrawnOnTestingArea()
191 return iHasDrawnOnTestingArea;
195 void Set(TSize aSizeInPixels);
197 // a rect of testing area
199 TBool iHasDrawnOnTestingArea;
202 TRect iAreaDrawnWithCondition;
204 TInt iHorizontalTwipsToPixels;
205 TInt iVerticalTwipsToPixels;
206 CTestPalette iPalette;
207 CLineArray iLineArray;
210 class CTestGraphicsContext : public CWindowGc
216 ETypefaceIndexOutOfRange,
220 static void Panic(TInt aReason);
221 CTestGraphicsContext(CTestGraphicsDevice* aGd);
224 // from CBitmapContext
225 CGraphicsDevice* Device() const;
226 void SetOrigin(const TPoint& aPos);
227 void SetDrawMode(TDrawMode aDrawingMode);
228 void SetClippingRect(const TRect& aRect);
229 void CancelClippingRect();
231 void UseFont(const CFont* aFont);
233 void SetUnderlineStyle(TFontUnderline aUnderlineStyle);
234 void SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle);
235 void SetWordJustification(TInt aExcessWidth,TInt aNumGaps);
236 void SetCharJustification(TInt aExcessWidth,TInt aNumChars);
237 void SetPenColor(const TRgb& aColor);
238 void SetPenStyle(TPenStyle aPenStyle);
239 void SetPenSize(const TSize& aSize);
240 void SetBrushColor(const TRgb& aColor);
241 void SetBrushStyle(TBrushStyle aBrushStyle);
242 void SetBrushOrigin(const TPoint& aOrigin);
243 void UseBrushPattern(const CFbsBitmap* aBitmap);
244 void DiscardBrushPattern();
245 void MoveTo(const TPoint& aPoint);
246 void MoveBy(const TPoint& aVector);
247 void Plot(const TPoint& aPoint);
248 void DrawArc(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd);
249 void DrawLine(const TPoint& aPoint1,const TPoint& aPoint2);
250 void DrawLineTo(const TPoint& aPoint);
251 void DrawLineBy(const TPoint& aVector);
252 void DrawPolyLine(const CArrayFix<TPoint>* aPointList);
253 void DrawPolyLine(const TPoint* aPointList,TInt aNumPoints);
254 void DrawPie(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd);
255 void DrawEllipse(const TRect& aRect);
256 void DrawRect(const TRect& aRect);
257 void DrawRoundRect(const TRect& aRect,const TSize& aCornerSize);
258 TInt DrawPolygon(const CArrayFix<TPoint>* aPointList,TFillRule aFillRule);
259 TInt DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule);
260 void DrawBitmap(const TPoint& aTopLeft,const CFbsBitmap* aSource);
261 void DrawBitmap(const TRect& aDestRect,const CFbsBitmap* aSource);
262 void DrawBitmap(const TRect& aDestRect,const CFbsBitmap* aSource,const TRect& aSourceRect);
263 void DrawText(const TDesC& aText,const TPoint& aPosition);
264 void DrawText(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,TTextAlign aAlignment,
266 TInt SetClippingRegion(const TRegion &aRegion);
267 void CancelClippingRegion();
269 // from CBitmapContext
271 void Clear(const TRect& aRect);
272 void CopyRect(const TPoint& aOffset,const TRect& aRect);
273 void BitBlt(const TPoint& aPoint,const CFbsBitmap* aBitmap);
274 void BitBlt(const TPoint& aPoint,const CFbsBitmap* aBitmap,const TRect& aRect);
275 void BitBltMasked(const TPoint& aPoint, const CFbsBitmap* aBitmap,
276 const TRect& aSourceRect, const CFbsBitmap* aMaskBitmap, TBool aInvertMask);
277 void SetFaded(TBool aFaded);
278 void SetFadingParameters(TUint8 aBlackMap,TUint8 aWhiteMap);
281 void AddRectToDrawnArea(const TRect& aRect);
282 void AddPointToDrawnArea(const TPoint& aPoint);
284 void DrawText(const TDesC& aText,TTextParameters* aParam,const TPoint& aPosition);
285 void DrawText(const TDesC& aText,TTextParameters* aParam,const TRect& aBox,TInt aBaselineOffset,TTextAlign aAlignment,
288 TInt APIExtension(TUid aUid, TAny*& aOutput, TAny* aInput);
291 CTestGraphicsDevice* iGd;
298 CLineArray iLineArray;
301 class CTestFont : public CFont
305 Sample Unicode characters.
310 /** ESC has no data at all */
312 /** Hebrew letter Tav, has right side-bearing */
314 /** Arabic Waw has a massive left side-bearing */
316 /** ZWNBS has zero width. */
317 KZeroWidthNoBreakSpace = 0xFEFF,
318 /** ZWS has zero width. */
319 KZeroWidthSpace = 0x200B,
320 /** Hair space has one pixel width. */
322 /** Thin space has two pixel width. */
324 /** 3-per-em space has three pixel width. */
325 KThreePerEmSpace = 0x2004,
326 /** Full-width solidus has a right side-bearing */
327 KFullWidthSolidus = 0xFF0F
329 TUid DoTypeUid() const;
330 TInt DoHeightInPixels() const;
331 TInt DoAscentInPixels() const;
332 TInt DoCharWidthInPixels(TChar aChar) const;
333 TInt DoTextWidthInPixels(const TDesC& aText) const;
334 TInt DoBaselineOffsetInPixels() const;
335 TInt DoTextCount(const TDesC& aText,TInt aWidthInPixels) const;
336 TInt DoTextCount(const TDesC& aText,TInt aWidthInPixels,TInt& aExcessWidthInPixels) const;
337 TInt DoMaxCharWidthInPixels() const;
338 TInt DoMaxNormalCharWidthInPixels() const;
339 TFontSpec DoFontSpecInTwips() const;
340 TCharacterDataAvailability DoGetCharacterData(TUint aCode,
341 TOpenFontCharMetrics& aMetrics,
342 const TUint8*& aBitmap, TSize& aBitmapSize) const;