os/textandloc/textrendering/textformatting/test/src/TGraphicsContext.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * Simple stubs for testing purposes
    16 *
    17 */
    18 
    19 
    20 #ifndef __TGRAPHICSCONTEXT_H__
    21 #define __TGRAPHICSCONTEXT_H__
    22 
    23 #include <w32std.h>
    24 
    25 /** Representing a line of displayed data.
    26 @internalComponent */
    27 class TTestGCDisplayLine 
    28 	{
    29 public:
    30 	TPoint iLinePos;
    31 	TBuf16<80> iLineData;
    32 
    33 	TTestGCDisplayLine() : iLinePos(0,0) {}
    34 	TTestGCDisplayLine(const TInt aX, const TInt aY, const TDesC16& aLineData) : iLinePos(aX, aY) 
    35 		{
    36 		iLineData = aLineData;
    37 		}
    38 	TTestGCDisplayLine(const TPoint aLinePos, const TDesC16& aLineData) : iLinePos(aLinePos) 
    39 		{
    40 		iLineData = aLineData;
    41 		}
    42 
    43 	void Set(const TPoint& aLinePos, const TDesC16& aLineData)
    44 		{
    45 		iLineData = aLineData;
    46 		iLinePos = aLinePos;
    47 		}
    48 
    49 	TPtrC16 LineData() const
    50 		{
    51 		return TPtrC16(iLineData.Ptr(), iLineData.Length());
    52 		}
    53 
    54 	const TPoint& Position() const
    55 		{
    56 		return iLinePos;
    57 		}
    58 	};
    59 
    60 /** Holds a reference-counted array of TTestGCDisplayLines. Copy makes another
    61 reference to the same array, allowing arrays to be shared between graphics
    62 contexts and devices.
    63 @internalComponent
    64 */
    65 class CLineArray : public CBase
    66 	{
    67 public:
    68 	CLineArray();
    69 	~CLineArray();
    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. */
    75 	void Null();
    76 	void ResetLineArray();
    77 	const TTestGCDisplayLine& Line(TInt aIndex);
    78 	void AddLineL(TTestGCDisplayLine& aLine);
    79 	TInt LinesPresent();
    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
    87 	this one. */
    88 	void Enable() { iArrayIsEnabled = ETrue; }
    89 private:
    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;
    97 	};
    98 
    99 class CTestPalette : public CPalette
   100 	{
   101 public:
   102 	enum { KNumEntries = 4 };
   103 	CTestPalette()
   104 		{
   105 		iArray = iRgbArray;
   106 		iNumEntries = KNumEntries;
   107 		}
   108 	~CTestPalette()
   109 		{
   110 		// Stop iRgbArray from being deleted by ~CPalette.
   111 		// Ideally, iRgbArray should be removed in favour of
   112 		// allocating one on the heap.
   113 		iArray = 0;
   114 		}
   115 private:
   116 	TRgb iRgbArray[KNumEntries];
   117 	};
   118 
   119 class CTestGraphicsDevice : public CWsScreenDevice
   120 	{
   121 public:
   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;
   138 
   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;
   146 
   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);
   154 
   155 	// new functions
   156 	void ClearDrawnArea()
   157 		{
   158 		iDrawnArea.iTl.iX = iDrawnArea.iBr.iX = iDrawnArea.iTl.iY = iDrawnArea.iBr.iY = 0;
   159 		}
   160 	TRect DrawnArea() const
   161 		{
   162 		return iDrawnArea;
   163 		}
   164 	void ClearAreaDrawnWithCondition()
   165 		{
   166 		iAreaDrawnWithCondition.iTl.iX = iAreaDrawnWithCondition.iBr.iX
   167 			= iAreaDrawnWithCondition.iTl.iY = iAreaDrawnWithCondition.iBr.iY = 0;
   168 		}
   169 	const TRect& AreaDrawnWithCondition() const
   170 		{
   171 		return iAreaDrawnWithCondition;
   172 		}
   173 	void AddRectToDrawnArea(const TRect& aRect, TBool aCondition);
   174 	CLineArray& LineArray() { return iLineArray; }
   175 	void SetLineArray(const CLineArray& aLineArray)
   176 		{
   177 		iLineArray.Copy(aLineArray);
   178 		}
   179 	
   180 	// new functions for testing area
   181 	void SetTestingArea(TRect& aTestingArea);
   182 	void AddTestingArea(TRect& moreTestingArea);
   183 	void ClearTestingArea()
   184 		{
   185 		iTestingArea.iTl.iX = iTestingArea.iBr.iX
   186 			= iTestingArea.iTl.iY = iTestingArea.iBr.iY = 0;
   187 		}
   188 	// check if anything has been drawn on testing area
   189 	inline TBool HasDrawnOnTestingArea()
   190 		{
   191 		return iHasDrawnOnTestingArea;
   192 		}
   193 	
   194 private:
   195 	void Set(TSize aSizeInPixels);
   196 
   197 	// a rect of testing area
   198 	TRect iTestingArea;
   199 	TBool iHasDrawnOnTestingArea;
   200 	
   201 	TRect iDrawnArea;
   202 	TRect iAreaDrawnWithCondition;
   203 	TSize iSize;
   204 	TInt iHorizontalTwipsToPixels;
   205 	TInt iVerticalTwipsToPixels;
   206 	CTestPalette iPalette;
   207 	CLineArray iLineArray;
   208 	};
   209 
   210 class CTestGraphicsContext : public CWindowGc
   211 	{
   212 public:
   213 	enum TPanic
   214 		{
   215 		EUnimplemented,
   216 		ETypefaceIndexOutOfRange,
   217 		EUnknownFont,
   218 		EErrorParameter
   219 		};
   220 	static void Panic(TInt aReason);
   221 	CTestGraphicsContext(CTestGraphicsDevice* aGd);
   222 	TInt Construct();
   223 
   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();
   230 	void Reset();
   231 	void UseFont(const CFont* aFont);
   232 	void DiscardFont();
   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,
   265 		TInt aLeftMargin);
   266 	TInt SetClippingRegion(const TRegion &aRegion);
   267 	void CancelClippingRegion();
   268 
   269 	// from CBitmapContext
   270 	void Clear();
   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);
   279 
   280 	// new functions
   281 	void AddRectToDrawnArea(const TRect& aRect);
   282 	void AddPointToDrawnArea(const TPoint& aPoint);
   283 	
   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,
   286 		TInt aLeftMargin);
   287 protected:	
   288 	TInt APIExtension(TUid aUid, TAny*& aOutput, TAny* aInput);
   289 
   290 private:
   291 	CTestGraphicsDevice* iGd;
   292 	TPoint iOrigin;
   293 	TDrawMode iDrawMode;
   294 	const CFont* iFont;
   295 	TSize iPenSize;
   296 	TPoint iCurrentPos;
   297 	TInt iPenColorIndex;
   298 	CLineArray iLineArray;
   299 	};
   300 
   301 class CTestFont : public CFont
   302 	{
   303 public:
   304 	/**
   305 	Sample Unicode characters.
   306 	@internalComponent
   307 	*/
   308 	enum
   309 		{
   310  		/** ESC has no data at all */
   311  		KEsc = 0x001B,
   312  		/** Hebrew letter Tav, has right side-bearing */
   313  		KTav = 0x05EA,
   314  		/** Arabic Waw has a massive left side-bearing */
   315  		KArabicWaw = 0x0648,
   316    		/** ZWNBS has zero width. */
   317    		KZeroWidthNoBreakSpace = 0xFEFF,
   318    		/** ZWS has zero width. */
   319    		KZeroWidthSpace = 0x200B,
   320    		/** Hair space has one pixel width. */
   321    		KHairSpace = 0x200A,
   322    		/** Thin space has two pixel width. */
   323    		KThinSpace = 0x2009,
   324    		/** 3-per-em space has three pixel width. */
   325    		KThreePerEmSpace = 0x2004,
   326    		/** Full-width solidus has a right side-bearing */
   327    		KFullWidthSolidus = 0xFF0F
   328    		};
   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;
   343 	};
   344 
   345 #endif