os/textandloc/textrendering/textformatting/test/src/TGraphicsContext.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/textrendering/textformatting/test/src/TGraphicsContext.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,345 @@
     1.4 +/*
     1.5 +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* Simple stubs for testing purposes
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +#ifndef __TGRAPHICSCONTEXT_H__
    1.24 +#define __TGRAPHICSCONTEXT_H__
    1.25 +
    1.26 +#include <w32std.h>
    1.27 +
    1.28 +/** Representing a line of displayed data.
    1.29 +@internalComponent */
    1.30 +class TTestGCDisplayLine 
    1.31 +	{
    1.32 +public:
    1.33 +	TPoint iLinePos;
    1.34 +	TBuf16<80> iLineData;
    1.35 +
    1.36 +	TTestGCDisplayLine() : iLinePos(0,0) {}
    1.37 +	TTestGCDisplayLine(const TInt aX, const TInt aY, const TDesC16& aLineData) : iLinePos(aX, aY) 
    1.38 +		{
    1.39 +		iLineData = aLineData;
    1.40 +		}
    1.41 +	TTestGCDisplayLine(const TPoint aLinePos, const TDesC16& aLineData) : iLinePos(aLinePos) 
    1.42 +		{
    1.43 +		iLineData = aLineData;
    1.44 +		}
    1.45 +
    1.46 +	void Set(const TPoint& aLinePos, const TDesC16& aLineData)
    1.47 +		{
    1.48 +		iLineData = aLineData;
    1.49 +		iLinePos = aLinePos;
    1.50 +		}
    1.51 +
    1.52 +	TPtrC16 LineData() const
    1.53 +		{
    1.54 +		return TPtrC16(iLineData.Ptr(), iLineData.Length());
    1.55 +		}
    1.56 +
    1.57 +	const TPoint& Position() const
    1.58 +		{
    1.59 +		return iLinePos;
    1.60 +		}
    1.61 +	};
    1.62 +
    1.63 +/** Holds a reference-counted array of TTestGCDisplayLines. Copy makes another
    1.64 +reference to the same array, allowing arrays to be shared between graphics
    1.65 +contexts and devices.
    1.66 +@internalComponent
    1.67 +*/
    1.68 +class CLineArray : public CBase
    1.69 +	{
    1.70 +public:
    1.71 +	CLineArray();
    1.72 +	~CLineArray();
    1.73 +	void ConstructL(TInt aGranularity);
    1.74 +	/** Make this refer to the same array as aOther currently does. */
    1.75 +	void Copy(const CLineArray& aOther);
    1.76 +	/** Removes this reference to the array. Deletes the array if all
    1.77 +	references have been removed. */
    1.78 +	void Null();
    1.79 +	void ResetLineArray();
    1.80 +	const TTestGCDisplayLine& Line(TInt aIndex);
    1.81 +	void AddLineL(TTestGCDisplayLine& aLine);
    1.82 +	TInt LinesPresent();
    1.83 +	/** Finds a TTestGCDisplayLine with aText contained somewhere in its data.
    1.84 +	Returns 0 if there is no such line. */
    1.85 +	const TTestGCDisplayLine* Find(const TDesC& aText);
    1.86 +	/** Disables any more adding to the line array, and disables it
    1.87 +	in any CLineArrays copied from this one. */
    1.88 +	void Disable() { iArrayIsEnabled = EFalse; }
    1.89 +	/** Re-enables adding to the line array, and in any CLineArrays copied from
    1.90 +	this one. */
    1.91 +	void Enable() { iArrayIsEnabled = ETrue; }
    1.92 +private:
    1.93 +	// CLineArrays copied from one another form a circular doubly-linked
    1.94 +	// list. This is roughly equivalent to reference-counting; when iPrev and
    1.95 +	// iNext point to 'this', this is the same as the reference count being 1.
    1.96 +	mutable const CLineArray* iPrev;
    1.97 +	mutable const CLineArray* iNext;
    1.98 +	TBool iArrayIsEnabled;
    1.99 +	RArray<TTestGCDisplayLine>* iArray;
   1.100 +	};
   1.101 +
   1.102 +class CTestPalette : public CPalette
   1.103 +	{
   1.104 +public:
   1.105 +	enum { KNumEntries = 4 };
   1.106 +	CTestPalette()
   1.107 +		{
   1.108 +		iArray = iRgbArray;
   1.109 +		iNumEntries = KNumEntries;
   1.110 +		}
   1.111 +	~CTestPalette()
   1.112 +		{
   1.113 +		// Stop iRgbArray from being deleted by ~CPalette.
   1.114 +		// Ideally, iRgbArray should be removed in favour of
   1.115 +		// allocating one on the heap.
   1.116 +		iArray = 0;
   1.117 +		}
   1.118 +private:
   1.119 +	TRgb iRgbArray[KNumEntries];
   1.120 +	};
   1.121 +
   1.122 +class CTestGraphicsDevice : public CWsScreenDevice
   1.123 +	{
   1.124 +public:
   1.125 +	static CTestGraphicsDevice* NewL(TSize aSizeInPixels, RWsSession* aWsSession);
   1.126 +	CTestGraphicsDevice(TSize aSizeInPixels, RWsSession* aWsSession);
   1.127 +	CTestGraphicsDevice(TSize aSizeInPixels);
   1.128 +	void SetHorizontalTwipsToPixels(TInt aTwipsToPixels);
   1.129 +	void SetVerticalTwipsToPixels(TInt aTwipsToPixels);
   1.130 +	TDisplayMode DisplayMode() const;
   1.131 +	TSize SizeInPixels() const;
   1.132 +	TSize SizeInTwips() const;
   1.133 +	TInt CreateContext(CGraphicsContext*& aGC);
   1.134 +	TInt CreateContext(CWindowGc*& aGC);
   1.135 +	TInt NumTypefaces() const;
   1.136 +	void TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const;
   1.137 +	TInt FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const;
   1.138 +	void PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const;
   1.139 +	void SetPalette(CPalette* aPalette);
   1.140 +	TInt GetPalette(CPalette*& aPalette) const;
   1.141 +
   1.142 +	// from CBitmapDevice
   1.143 +	void GetPixel(TRgb& aColor,const TPoint& aPixel) const;
   1.144 +	void GetScanLine(TDes8& aBuf,const TPoint& aStartPixel,TInt aLength,TDisplayMode aDispMode) const;
   1.145 +	TInt AddFile(const TDesC& aName,TInt& aId);
   1.146 +	void RemoveFile(TInt aId);
   1.147 +	TInt GetNearestFontInPixels(CFont*& aFont,const TFontSpec& aFontSpec);
   1.148 +	TInt FontHeightInPixels(TInt aTypefaceIndex,TInt aHeightIndex) const;
   1.149 +
   1.150 +	// from MGraphicsDeviceMap from CBitmapDevice
   1.151 +	TInt HorizontalTwipsToPixels(TInt aTwips) const;
   1.152 +	TInt VerticalTwipsToPixels(TInt aTwips) const;
   1.153 +	TInt HorizontalPixelsToTwips(TInt aPixels) const;
   1.154 +	TInt VerticalPixelsToTwips(TInt aPixels) const;
   1.155 +	TInt GetNearestFontInTwips(CFont*& aFont,const TFontSpec& aFontSpec);
   1.156 +	void ReleaseFont(CFont* aFont);
   1.157 +
   1.158 +	// new functions
   1.159 +	void ClearDrawnArea()
   1.160 +		{
   1.161 +		iDrawnArea.iTl.iX = iDrawnArea.iBr.iX = iDrawnArea.iTl.iY = iDrawnArea.iBr.iY = 0;
   1.162 +		}
   1.163 +	TRect DrawnArea() const
   1.164 +		{
   1.165 +		return iDrawnArea;
   1.166 +		}
   1.167 +	void ClearAreaDrawnWithCondition()
   1.168 +		{
   1.169 +		iAreaDrawnWithCondition.iTl.iX = iAreaDrawnWithCondition.iBr.iX
   1.170 +			= iAreaDrawnWithCondition.iTl.iY = iAreaDrawnWithCondition.iBr.iY = 0;
   1.171 +		}
   1.172 +	const TRect& AreaDrawnWithCondition() const
   1.173 +		{
   1.174 +		return iAreaDrawnWithCondition;
   1.175 +		}
   1.176 +	void AddRectToDrawnArea(const TRect& aRect, TBool aCondition);
   1.177 +	CLineArray& LineArray() { return iLineArray; }
   1.178 +	void SetLineArray(const CLineArray& aLineArray)
   1.179 +		{
   1.180 +		iLineArray.Copy(aLineArray);
   1.181 +		}
   1.182 +	
   1.183 +	// new functions for testing area
   1.184 +	void SetTestingArea(TRect& aTestingArea);
   1.185 +	void AddTestingArea(TRect& moreTestingArea);
   1.186 +	void ClearTestingArea()
   1.187 +		{
   1.188 +		iTestingArea.iTl.iX = iTestingArea.iBr.iX
   1.189 +			= iTestingArea.iTl.iY = iTestingArea.iBr.iY = 0;
   1.190 +		}
   1.191 +	// check if anything has been drawn on testing area
   1.192 +	inline TBool HasDrawnOnTestingArea()
   1.193 +		{
   1.194 +		return iHasDrawnOnTestingArea;
   1.195 +		}
   1.196 +	
   1.197 +private:
   1.198 +	void Set(TSize aSizeInPixels);
   1.199 +
   1.200 +	// a rect of testing area
   1.201 +	TRect iTestingArea;
   1.202 +	TBool iHasDrawnOnTestingArea;
   1.203 +	
   1.204 +	TRect iDrawnArea;
   1.205 +	TRect iAreaDrawnWithCondition;
   1.206 +	TSize iSize;
   1.207 +	TInt iHorizontalTwipsToPixels;
   1.208 +	TInt iVerticalTwipsToPixels;
   1.209 +	CTestPalette iPalette;
   1.210 +	CLineArray iLineArray;
   1.211 +	};
   1.212 +
   1.213 +class CTestGraphicsContext : public CWindowGc
   1.214 +	{
   1.215 +public:
   1.216 +	enum TPanic
   1.217 +		{
   1.218 +		EUnimplemented,
   1.219 +		ETypefaceIndexOutOfRange,
   1.220 +		EUnknownFont,
   1.221 +		EErrorParameter
   1.222 +		};
   1.223 +	static void Panic(TInt aReason);
   1.224 +	CTestGraphicsContext(CTestGraphicsDevice* aGd);
   1.225 +	TInt Construct();
   1.226 +
   1.227 +	// from CBitmapContext
   1.228 +	CGraphicsDevice* Device() const;
   1.229 +	void SetOrigin(const TPoint& aPos);
   1.230 +	void SetDrawMode(TDrawMode aDrawingMode);
   1.231 +	void SetClippingRect(const TRect& aRect);
   1.232 +	void CancelClippingRect();
   1.233 +	void Reset();
   1.234 +	void UseFont(const CFont* aFont);
   1.235 +	void DiscardFont();
   1.236 +	void SetUnderlineStyle(TFontUnderline aUnderlineStyle);
   1.237 +	void SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle);
   1.238 +	void SetWordJustification(TInt aExcessWidth,TInt aNumGaps);
   1.239 +	void SetCharJustification(TInt aExcessWidth,TInt aNumChars);
   1.240 +	void SetPenColor(const TRgb& aColor);
   1.241 +	void SetPenStyle(TPenStyle aPenStyle);
   1.242 +	void SetPenSize(const TSize& aSize);
   1.243 +	void SetBrushColor(const TRgb& aColor);
   1.244 +	void SetBrushStyle(TBrushStyle aBrushStyle);
   1.245 +	void SetBrushOrigin(const TPoint& aOrigin);
   1.246 +	void UseBrushPattern(const CFbsBitmap* aBitmap);
   1.247 +	void DiscardBrushPattern();
   1.248 +	void MoveTo(const TPoint& aPoint);
   1.249 +	void MoveBy(const TPoint& aVector);
   1.250 +	void Plot(const TPoint& aPoint);
   1.251 +	void DrawArc(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd);
   1.252 +	void DrawLine(const TPoint& aPoint1,const TPoint& aPoint2);
   1.253 +	void DrawLineTo(const TPoint& aPoint);
   1.254 +	void DrawLineBy(const TPoint& aVector);
   1.255 +	void DrawPolyLine(const CArrayFix<TPoint>* aPointList);
   1.256 +	void DrawPolyLine(const TPoint* aPointList,TInt aNumPoints);
   1.257 +	void DrawPie(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd);
   1.258 +	void DrawEllipse(const TRect& aRect);
   1.259 +	void DrawRect(const TRect& aRect);
   1.260 +	void DrawRoundRect(const TRect& aRect,const TSize& aCornerSize);
   1.261 +	TInt DrawPolygon(const CArrayFix<TPoint>* aPointList,TFillRule aFillRule);
   1.262 +	TInt DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule);
   1.263 +	void DrawBitmap(const TPoint& aTopLeft,const CFbsBitmap* aSource);
   1.264 +	void DrawBitmap(const TRect& aDestRect,const CFbsBitmap* aSource);
   1.265 +	void DrawBitmap(const TRect& aDestRect,const CFbsBitmap* aSource,const TRect& aSourceRect);
   1.266 +	void DrawText(const TDesC& aText,const TPoint& aPosition);
   1.267 +	void DrawText(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,TTextAlign aAlignment,
   1.268 +		TInt aLeftMargin);
   1.269 +	TInt SetClippingRegion(const TRegion &aRegion);
   1.270 +	void CancelClippingRegion();
   1.271 +
   1.272 +	// from CBitmapContext
   1.273 +	void Clear();
   1.274 +	void Clear(const TRect& aRect);
   1.275 +	void CopyRect(const TPoint& aOffset,const TRect& aRect);
   1.276 +	void BitBlt(const TPoint& aPoint,const CFbsBitmap* aBitmap);
   1.277 +	void BitBlt(const TPoint& aPoint,const CFbsBitmap* aBitmap,const TRect& aRect);
   1.278 +	void BitBltMasked(const TPoint& aPoint, const CFbsBitmap* aBitmap,
   1.279 +		const TRect& aSourceRect, const CFbsBitmap* aMaskBitmap, TBool aInvertMask);
   1.280 +	void SetFaded(TBool aFaded);
   1.281 +	void SetFadingParameters(TUint8 aBlackMap,TUint8 aWhiteMap);
   1.282 +
   1.283 +	// new functions
   1.284 +	void AddRectToDrawnArea(const TRect& aRect);
   1.285 +	void AddPointToDrawnArea(const TPoint& aPoint);
   1.286 +	
   1.287 +	void DrawText(const TDesC& aText,TTextParameters* aParam,const TPoint& aPosition);
   1.288 +	void DrawText(const TDesC& aText,TTextParameters* aParam,const TRect& aBox,TInt aBaselineOffset,TTextAlign aAlignment,
   1.289 +		TInt aLeftMargin);
   1.290 +protected:	
   1.291 +	TInt APIExtension(TUid aUid, TAny*& aOutput, TAny* aInput);
   1.292 +
   1.293 +private:
   1.294 +	CTestGraphicsDevice* iGd;
   1.295 +	TPoint iOrigin;
   1.296 +	TDrawMode iDrawMode;
   1.297 +	const CFont* iFont;
   1.298 +	TSize iPenSize;
   1.299 +	TPoint iCurrentPos;
   1.300 +	TInt iPenColorIndex;
   1.301 +	CLineArray iLineArray;
   1.302 +	};
   1.303 +
   1.304 +class CTestFont : public CFont
   1.305 +	{
   1.306 +public:
   1.307 +	/**
   1.308 +	Sample Unicode characters.
   1.309 +	@internalComponent
   1.310 +	*/
   1.311 +	enum
   1.312 +		{
   1.313 + 		/** ESC has no data at all */
   1.314 + 		KEsc = 0x001B,
   1.315 + 		/** Hebrew letter Tav, has right side-bearing */
   1.316 + 		KTav = 0x05EA,
   1.317 + 		/** Arabic Waw has a massive left side-bearing */
   1.318 + 		KArabicWaw = 0x0648,
   1.319 +   		/** ZWNBS has zero width. */
   1.320 +   		KZeroWidthNoBreakSpace = 0xFEFF,
   1.321 +   		/** ZWS has zero width. */
   1.322 +   		KZeroWidthSpace = 0x200B,
   1.323 +   		/** Hair space has one pixel width. */
   1.324 +   		KHairSpace = 0x200A,
   1.325 +   		/** Thin space has two pixel width. */
   1.326 +   		KThinSpace = 0x2009,
   1.327 +   		/** 3-per-em space has three pixel width. */
   1.328 +   		KThreePerEmSpace = 0x2004,
   1.329 +   		/** Full-width solidus has a right side-bearing */
   1.330 +   		KFullWidthSolidus = 0xFF0F
   1.331 +   		};
   1.332 +   	TUid DoTypeUid() const;
   1.333 +   	TInt DoHeightInPixels() const;
   1.334 +   	TInt DoAscentInPixels() const;
   1.335 +   	TInt DoCharWidthInPixels(TChar aChar) const;
   1.336 +   	TInt DoTextWidthInPixels(const TDesC& aText) const;
   1.337 +   	TInt DoBaselineOffsetInPixels() const;
   1.338 +   	TInt DoTextCount(const TDesC& aText,TInt aWidthInPixels) const;
   1.339 +   	TInt DoTextCount(const TDesC& aText,TInt aWidthInPixels,TInt& aExcessWidthInPixels) const;
   1.340 +   	TInt DoMaxCharWidthInPixels() const;
   1.341 +   	TInt DoMaxNormalCharWidthInPixels() const;
   1.342 +   	TFontSpec DoFontSpecInTwips() const;
   1.343 + 	TCharacterDataAvailability DoGetCharacterData(TUint aCode,
   1.344 + 		TOpenFontCharMetrics& aMetrics,
   1.345 + 		const TUint8*& aBitmap, TSize& aBitmapSize) const;
   1.346 +	};
   1.347 +
   1.348 +#endif