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.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* Simple stubs for testing purposes
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
#ifndef __TGRAPHICSCONTEXT_H__
sl@0
    21
#define __TGRAPHICSCONTEXT_H__
sl@0
    22
sl@0
    23
#include <w32std.h>
sl@0
    24
sl@0
    25
/** Representing a line of displayed data.
sl@0
    26
@internalComponent */
sl@0
    27
class TTestGCDisplayLine 
sl@0
    28
	{
sl@0
    29
public:
sl@0
    30
	TPoint iLinePos;
sl@0
    31
	TBuf16<80> iLineData;
sl@0
    32
sl@0
    33
	TTestGCDisplayLine() : iLinePos(0,0) {}
sl@0
    34
	TTestGCDisplayLine(const TInt aX, const TInt aY, const TDesC16& aLineData) : iLinePos(aX, aY) 
sl@0
    35
		{
sl@0
    36
		iLineData = aLineData;
sl@0
    37
		}
sl@0
    38
	TTestGCDisplayLine(const TPoint aLinePos, const TDesC16& aLineData) : iLinePos(aLinePos) 
sl@0
    39
		{
sl@0
    40
		iLineData = aLineData;
sl@0
    41
		}
sl@0
    42
sl@0
    43
	void Set(const TPoint& aLinePos, const TDesC16& aLineData)
sl@0
    44
		{
sl@0
    45
		iLineData = aLineData;
sl@0
    46
		iLinePos = aLinePos;
sl@0
    47
		}
sl@0
    48
sl@0
    49
	TPtrC16 LineData() const
sl@0
    50
		{
sl@0
    51
		return TPtrC16(iLineData.Ptr(), iLineData.Length());
sl@0
    52
		}
sl@0
    53
sl@0
    54
	const TPoint& Position() const
sl@0
    55
		{
sl@0
    56
		return iLinePos;
sl@0
    57
		}
sl@0
    58
	};
sl@0
    59
sl@0
    60
/** Holds a reference-counted array of TTestGCDisplayLines. Copy makes another
sl@0
    61
reference to the same array, allowing arrays to be shared between graphics
sl@0
    62
contexts and devices.
sl@0
    63
@internalComponent
sl@0
    64
*/
sl@0
    65
class CLineArray : public CBase
sl@0
    66
	{
sl@0
    67
public:
sl@0
    68
	CLineArray();
sl@0
    69
	~CLineArray();
sl@0
    70
	void ConstructL(TInt aGranularity);
sl@0
    71
	/** Make this refer to the same array as aOther currently does. */
sl@0
    72
	void Copy(const CLineArray& aOther);
sl@0
    73
	/** Removes this reference to the array. Deletes the array if all
sl@0
    74
	references have been removed. */
sl@0
    75
	void Null();
sl@0
    76
	void ResetLineArray();
sl@0
    77
	const TTestGCDisplayLine& Line(TInt aIndex);
sl@0
    78
	void AddLineL(TTestGCDisplayLine& aLine);
sl@0
    79
	TInt LinesPresent();
sl@0
    80
	/** Finds a TTestGCDisplayLine with aText contained somewhere in its data.
sl@0
    81
	Returns 0 if there is no such line. */
sl@0
    82
	const TTestGCDisplayLine* Find(const TDesC& aText);
sl@0
    83
	/** Disables any more adding to the line array, and disables it
sl@0
    84
	in any CLineArrays copied from this one. */
sl@0
    85
	void Disable() { iArrayIsEnabled = EFalse; }
sl@0
    86
	/** Re-enables adding to the line array, and in any CLineArrays copied from
sl@0
    87
	this one. */
sl@0
    88
	void Enable() { iArrayIsEnabled = ETrue; }
sl@0
    89
private:
sl@0
    90
	// CLineArrays copied from one another form a circular doubly-linked
sl@0
    91
	// list. This is roughly equivalent to reference-counting; when iPrev and
sl@0
    92
	// iNext point to 'this', this is the same as the reference count being 1.
sl@0
    93
	mutable const CLineArray* iPrev;
sl@0
    94
	mutable const CLineArray* iNext;
sl@0
    95
	TBool iArrayIsEnabled;
sl@0
    96
	RArray<TTestGCDisplayLine>* iArray;
sl@0
    97
	};
sl@0
    98
sl@0
    99
class CTestPalette : public CPalette
sl@0
   100
	{
sl@0
   101
public:
sl@0
   102
	enum { KNumEntries = 4 };
sl@0
   103
	CTestPalette()
sl@0
   104
		{
sl@0
   105
		iArray = iRgbArray;
sl@0
   106
		iNumEntries = KNumEntries;
sl@0
   107
		}
sl@0
   108
	~CTestPalette()
sl@0
   109
		{
sl@0
   110
		// Stop iRgbArray from being deleted by ~CPalette.
sl@0
   111
		// Ideally, iRgbArray should be removed in favour of
sl@0
   112
		// allocating one on the heap.
sl@0
   113
		iArray = 0;
sl@0
   114
		}
sl@0
   115
private:
sl@0
   116
	TRgb iRgbArray[KNumEntries];
sl@0
   117
	};
sl@0
   118
sl@0
   119
class CTestGraphicsDevice : public CWsScreenDevice
sl@0
   120
	{
sl@0
   121
public:
sl@0
   122
	static CTestGraphicsDevice* NewL(TSize aSizeInPixels, RWsSession* aWsSession);
sl@0
   123
	CTestGraphicsDevice(TSize aSizeInPixels, RWsSession* aWsSession);
sl@0
   124
	CTestGraphicsDevice(TSize aSizeInPixels);
sl@0
   125
	void SetHorizontalTwipsToPixels(TInt aTwipsToPixels);
sl@0
   126
	void SetVerticalTwipsToPixels(TInt aTwipsToPixels);
sl@0
   127
	TDisplayMode DisplayMode() const;
sl@0
   128
	TSize SizeInPixels() const;
sl@0
   129
	TSize SizeInTwips() const;
sl@0
   130
	TInt CreateContext(CGraphicsContext*& aGC);
sl@0
   131
	TInt CreateContext(CWindowGc*& aGC);
sl@0
   132
	TInt NumTypefaces() const;
sl@0
   133
	void TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const;
sl@0
   134
	TInt FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const;
sl@0
   135
	void PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const;
sl@0
   136
	void SetPalette(CPalette* aPalette);
sl@0
   137
	TInt GetPalette(CPalette*& aPalette) const;
sl@0
   138
sl@0
   139
	// from CBitmapDevice
sl@0
   140
	void GetPixel(TRgb& aColor,const TPoint& aPixel) const;
sl@0
   141
	void GetScanLine(TDes8& aBuf,const TPoint& aStartPixel,TInt aLength,TDisplayMode aDispMode) const;
sl@0
   142
	TInt AddFile(const TDesC& aName,TInt& aId);
sl@0
   143
	void RemoveFile(TInt aId);
sl@0
   144
	TInt GetNearestFontInPixels(CFont*& aFont,const TFontSpec& aFontSpec);
sl@0
   145
	TInt FontHeightInPixels(TInt aTypefaceIndex,TInt aHeightIndex) const;
sl@0
   146
sl@0
   147
	// from MGraphicsDeviceMap from CBitmapDevice
sl@0
   148
	TInt HorizontalTwipsToPixels(TInt aTwips) const;
sl@0
   149
	TInt VerticalTwipsToPixels(TInt aTwips) const;
sl@0
   150
	TInt HorizontalPixelsToTwips(TInt aPixels) const;
sl@0
   151
	TInt VerticalPixelsToTwips(TInt aPixels) const;
sl@0
   152
	TInt GetNearestFontInTwips(CFont*& aFont,const TFontSpec& aFontSpec);
sl@0
   153
	void ReleaseFont(CFont* aFont);
sl@0
   154
sl@0
   155
	// new functions
sl@0
   156
	void ClearDrawnArea()
sl@0
   157
		{
sl@0
   158
		iDrawnArea.iTl.iX = iDrawnArea.iBr.iX = iDrawnArea.iTl.iY = iDrawnArea.iBr.iY = 0;
sl@0
   159
		}
sl@0
   160
	TRect DrawnArea() const
sl@0
   161
		{
sl@0
   162
		return iDrawnArea;
sl@0
   163
		}
sl@0
   164
	void ClearAreaDrawnWithCondition()
sl@0
   165
		{
sl@0
   166
		iAreaDrawnWithCondition.iTl.iX = iAreaDrawnWithCondition.iBr.iX
sl@0
   167
			= iAreaDrawnWithCondition.iTl.iY = iAreaDrawnWithCondition.iBr.iY = 0;
sl@0
   168
		}
sl@0
   169
	const TRect& AreaDrawnWithCondition() const
sl@0
   170
		{
sl@0
   171
		return iAreaDrawnWithCondition;
sl@0
   172
		}
sl@0
   173
	void AddRectToDrawnArea(const TRect& aRect, TBool aCondition);
sl@0
   174
	CLineArray& LineArray() { return iLineArray; }
sl@0
   175
	void SetLineArray(const CLineArray& aLineArray)
sl@0
   176
		{
sl@0
   177
		iLineArray.Copy(aLineArray);
sl@0
   178
		}
sl@0
   179
	
sl@0
   180
	// new functions for testing area
sl@0
   181
	void SetTestingArea(TRect& aTestingArea);
sl@0
   182
	void AddTestingArea(TRect& moreTestingArea);
sl@0
   183
	void ClearTestingArea()
sl@0
   184
		{
sl@0
   185
		iTestingArea.iTl.iX = iTestingArea.iBr.iX
sl@0
   186
			= iTestingArea.iTl.iY = iTestingArea.iBr.iY = 0;
sl@0
   187
		}
sl@0
   188
	// check if anything has been drawn on testing area
sl@0
   189
	inline TBool HasDrawnOnTestingArea()
sl@0
   190
		{
sl@0
   191
		return iHasDrawnOnTestingArea;
sl@0
   192
		}
sl@0
   193
	
sl@0
   194
private:
sl@0
   195
	void Set(TSize aSizeInPixels);
sl@0
   196
sl@0
   197
	// a rect of testing area
sl@0
   198
	TRect iTestingArea;
sl@0
   199
	TBool iHasDrawnOnTestingArea;
sl@0
   200
	
sl@0
   201
	TRect iDrawnArea;
sl@0
   202
	TRect iAreaDrawnWithCondition;
sl@0
   203
	TSize iSize;
sl@0
   204
	TInt iHorizontalTwipsToPixels;
sl@0
   205
	TInt iVerticalTwipsToPixels;
sl@0
   206
	CTestPalette iPalette;
sl@0
   207
	CLineArray iLineArray;
sl@0
   208
	};
sl@0
   209
sl@0
   210
class CTestGraphicsContext : public CWindowGc
sl@0
   211
	{
sl@0
   212
public:
sl@0
   213
	enum TPanic
sl@0
   214
		{
sl@0
   215
		EUnimplemented,
sl@0
   216
		ETypefaceIndexOutOfRange,
sl@0
   217
		EUnknownFont,
sl@0
   218
		EErrorParameter
sl@0
   219
		};
sl@0
   220
	static void Panic(TInt aReason);
sl@0
   221
	CTestGraphicsContext(CTestGraphicsDevice* aGd);
sl@0
   222
	TInt Construct();
sl@0
   223
sl@0
   224
	// from CBitmapContext
sl@0
   225
	CGraphicsDevice* Device() const;
sl@0
   226
	void SetOrigin(const TPoint& aPos);
sl@0
   227
	void SetDrawMode(TDrawMode aDrawingMode);
sl@0
   228
	void SetClippingRect(const TRect& aRect);
sl@0
   229
	void CancelClippingRect();
sl@0
   230
	void Reset();
sl@0
   231
	void UseFont(const CFont* aFont);
sl@0
   232
	void DiscardFont();
sl@0
   233
	void SetUnderlineStyle(TFontUnderline aUnderlineStyle);
sl@0
   234
	void SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle);
sl@0
   235
	void SetWordJustification(TInt aExcessWidth,TInt aNumGaps);
sl@0
   236
	void SetCharJustification(TInt aExcessWidth,TInt aNumChars);
sl@0
   237
	void SetPenColor(const TRgb& aColor);
sl@0
   238
	void SetPenStyle(TPenStyle aPenStyle);
sl@0
   239
	void SetPenSize(const TSize& aSize);
sl@0
   240
	void SetBrushColor(const TRgb& aColor);
sl@0
   241
	void SetBrushStyle(TBrushStyle aBrushStyle);
sl@0
   242
	void SetBrushOrigin(const TPoint& aOrigin);
sl@0
   243
	void UseBrushPattern(const CFbsBitmap* aBitmap);
sl@0
   244
	void DiscardBrushPattern();
sl@0
   245
	void MoveTo(const TPoint& aPoint);
sl@0
   246
	void MoveBy(const TPoint& aVector);
sl@0
   247
	void Plot(const TPoint& aPoint);
sl@0
   248
	void DrawArc(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd);
sl@0
   249
	void DrawLine(const TPoint& aPoint1,const TPoint& aPoint2);
sl@0
   250
	void DrawLineTo(const TPoint& aPoint);
sl@0
   251
	void DrawLineBy(const TPoint& aVector);
sl@0
   252
	void DrawPolyLine(const CArrayFix<TPoint>* aPointList);
sl@0
   253
	void DrawPolyLine(const TPoint* aPointList,TInt aNumPoints);
sl@0
   254
	void DrawPie(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd);
sl@0
   255
	void DrawEllipse(const TRect& aRect);
sl@0
   256
	void DrawRect(const TRect& aRect);
sl@0
   257
	void DrawRoundRect(const TRect& aRect,const TSize& aCornerSize);
sl@0
   258
	TInt DrawPolygon(const CArrayFix<TPoint>* aPointList,TFillRule aFillRule);
sl@0
   259
	TInt DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule);
sl@0
   260
	void DrawBitmap(const TPoint& aTopLeft,const CFbsBitmap* aSource);
sl@0
   261
	void DrawBitmap(const TRect& aDestRect,const CFbsBitmap* aSource);
sl@0
   262
	void DrawBitmap(const TRect& aDestRect,const CFbsBitmap* aSource,const TRect& aSourceRect);
sl@0
   263
	void DrawText(const TDesC& aText,const TPoint& aPosition);
sl@0
   264
	void DrawText(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,TTextAlign aAlignment,
sl@0
   265
		TInt aLeftMargin);
sl@0
   266
	TInt SetClippingRegion(const TRegion &aRegion);
sl@0
   267
	void CancelClippingRegion();
sl@0
   268
sl@0
   269
	// from CBitmapContext
sl@0
   270
	void Clear();
sl@0
   271
	void Clear(const TRect& aRect);
sl@0
   272
	void CopyRect(const TPoint& aOffset,const TRect& aRect);
sl@0
   273
	void BitBlt(const TPoint& aPoint,const CFbsBitmap* aBitmap);
sl@0
   274
	void BitBlt(const TPoint& aPoint,const CFbsBitmap* aBitmap,const TRect& aRect);
sl@0
   275
	void BitBltMasked(const TPoint& aPoint, const CFbsBitmap* aBitmap,
sl@0
   276
		const TRect& aSourceRect, const CFbsBitmap* aMaskBitmap, TBool aInvertMask);
sl@0
   277
	void SetFaded(TBool aFaded);
sl@0
   278
	void SetFadingParameters(TUint8 aBlackMap,TUint8 aWhiteMap);
sl@0
   279
sl@0
   280
	// new functions
sl@0
   281
	void AddRectToDrawnArea(const TRect& aRect);
sl@0
   282
	void AddPointToDrawnArea(const TPoint& aPoint);
sl@0
   283
	
sl@0
   284
	void DrawText(const TDesC& aText,TTextParameters* aParam,const TPoint& aPosition);
sl@0
   285
	void DrawText(const TDesC& aText,TTextParameters* aParam,const TRect& aBox,TInt aBaselineOffset,TTextAlign aAlignment,
sl@0
   286
		TInt aLeftMargin);
sl@0
   287
protected:	
sl@0
   288
	TInt APIExtension(TUid aUid, TAny*& aOutput, TAny* aInput);
sl@0
   289
sl@0
   290
private:
sl@0
   291
	CTestGraphicsDevice* iGd;
sl@0
   292
	TPoint iOrigin;
sl@0
   293
	TDrawMode iDrawMode;
sl@0
   294
	const CFont* iFont;
sl@0
   295
	TSize iPenSize;
sl@0
   296
	TPoint iCurrentPos;
sl@0
   297
	TInt iPenColorIndex;
sl@0
   298
	CLineArray iLineArray;
sl@0
   299
	};
sl@0
   300
sl@0
   301
class CTestFont : public CFont
sl@0
   302
	{
sl@0
   303
public:
sl@0
   304
	/**
sl@0
   305
	Sample Unicode characters.
sl@0
   306
	@internalComponent
sl@0
   307
	*/
sl@0
   308
	enum
sl@0
   309
		{
sl@0
   310
 		/** ESC has no data at all */
sl@0
   311
 		KEsc = 0x001B,
sl@0
   312
 		/** Hebrew letter Tav, has right side-bearing */
sl@0
   313
 		KTav = 0x05EA,
sl@0
   314
 		/** Arabic Waw has a massive left side-bearing */
sl@0
   315
 		KArabicWaw = 0x0648,
sl@0
   316
   		/** ZWNBS has zero width. */
sl@0
   317
   		KZeroWidthNoBreakSpace = 0xFEFF,
sl@0
   318
   		/** ZWS has zero width. */
sl@0
   319
   		KZeroWidthSpace = 0x200B,
sl@0
   320
   		/** Hair space has one pixel width. */
sl@0
   321
   		KHairSpace = 0x200A,
sl@0
   322
   		/** Thin space has two pixel width. */
sl@0
   323
   		KThinSpace = 0x2009,
sl@0
   324
   		/** 3-per-em space has three pixel width. */
sl@0
   325
   		KThreePerEmSpace = 0x2004,
sl@0
   326
   		/** Full-width solidus has a right side-bearing */
sl@0
   327
   		KFullWidthSolidus = 0xFF0F
sl@0
   328
   		};
sl@0
   329
   	TUid DoTypeUid() const;
sl@0
   330
   	TInt DoHeightInPixels() const;
sl@0
   331
   	TInt DoAscentInPixels() const;
sl@0
   332
   	TInt DoCharWidthInPixels(TChar aChar) const;
sl@0
   333
   	TInt DoTextWidthInPixels(const TDesC& aText) const;
sl@0
   334
   	TInt DoBaselineOffsetInPixels() const;
sl@0
   335
   	TInt DoTextCount(const TDesC& aText,TInt aWidthInPixels) const;
sl@0
   336
   	TInt DoTextCount(const TDesC& aText,TInt aWidthInPixels,TInt& aExcessWidthInPixels) const;
sl@0
   337
   	TInt DoMaxCharWidthInPixels() const;
sl@0
   338
   	TInt DoMaxNormalCharWidthInPixels() const;
sl@0
   339
   	TFontSpec DoFontSpecInTwips() const;
sl@0
   340
 	TCharacterDataAvailability DoGetCharacterData(TUint aCode,
sl@0
   341
 		TOpenFontCharMetrics& aMetrics,
sl@0
   342
 		const TUint8*& aBitmap, TSize& aBitmapSize) const;
sl@0
   343
	};
sl@0
   344
sl@0
   345
#endif