os/graphics/graphicsdeviceinterface/gdi/tgdi/TGraphicsContext.cpp
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
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @test
sl@0
    19
 @internalComponent Internal Symbian test code
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include "TTYPES.H"
sl@0
    23
#include "TGraphicsContext.h"
sl@0
    24
sl@0
    25
sl@0
    26
sl@0
    27
// Utility functions to show contents of test data using test.Printf
sl@0
    28
sl@0
    29
extern void PrintTestData (const TDesC& aTitle , const TDesC16& aDataBuffer);
sl@0
    30
sl@0
    31
extern void PrintTestData(const TDesC& aTitle, const TText16* aDataBuffer, const TInt aSize);
sl@0
    32
sl@0
    33
sl@0
    34
sl@0
    35
sl@0
    36
_LIT(KTestFontName, "Non Functional Test Font");
sl@0
    37
sl@0
    38
sl@0
    39
CTestPalette2::~CTestPalette2()
sl@0
    40
	{
sl@0
    41
	iArray = 0; //avoid attempting to deallocate iArray in ~CPalette
sl@0
    42
	iNumEntries = 0;
sl@0
    43
	}
sl@0
    44
sl@0
    45
//
sl@0
    46
//
sl@0
    47
// CTestGraphicsDevice
sl@0
    48
//
sl@0
    49
//
sl@0
    50
CTestGraphicsDevice* CTestGraphicsDevice::NewL(TSize aSizeInPixels)
sl@0
    51
	{
sl@0
    52
	CTestGraphicsDevice* theDevice = new (ELeave) CTestGraphicsDevice(aSizeInPixels);
sl@0
    53
	CleanupStack::PushL(theDevice);
sl@0
    54
	theDevice->iPalette = new (ELeave) CTestPalette2;
sl@0
    55
	theDevice->iPalette->SetEntry(0, KRgbBlack);
sl@0
    56
	theDevice->iPalette->SetEntry(1, KRgbWhite);
sl@0
    57
	theDevice->iPalette->SetEntry(2, KRgbMagenta);
sl@0
    58
	theDevice->iPalette->SetEntry(3, KRgbCyan);
sl@0
    59
	
sl@0
    60
	CleanupStack::Pop(theDevice);
sl@0
    61
	return theDevice;
sl@0
    62
	}
sl@0
    63
sl@0
    64
CTestGraphicsDevice::CTestGraphicsDevice(TSize aSizeInPixels)
sl@0
    65
	: iSize(aSizeInPixels),
sl@0
    66
	iHorizontalTwipsToPixels(40),
sl@0
    67
	iVerticalTwipsToPixels(40)
sl@0
    68
	{
sl@0
    69
	}
sl@0
    70
CTestGraphicsDevice::~CTestGraphicsDevice()
sl@0
    71
	{
sl@0
    72
	delete iPalette;
sl@0
    73
	}
sl@0
    74
sl@0
    75
void CTestGraphicsDevice::SetHorizontalTwipsToPixels(TInt aTwipsToPixels)
sl@0
    76
	{
sl@0
    77
	iHorizontalTwipsToPixels = aTwipsToPixels;
sl@0
    78
	}
sl@0
    79
sl@0
    80
void CTestGraphicsDevice::SetVerticalTwipsToPixels(TInt aTwipsToPixels)
sl@0
    81
	{
sl@0
    82
	iVerticalTwipsToPixels = aTwipsToPixels;
sl@0
    83
	}
sl@0
    84
sl@0
    85
TDisplayMode CTestGraphicsDevice::DisplayMode() const
sl@0
    86
	{
sl@0
    87
	return EColor16M;
sl@0
    88
	}
sl@0
    89
sl@0
    90
TSize CTestGraphicsDevice::SizeInPixels() const
sl@0
    91
	{
sl@0
    92
	return iSize;
sl@0
    93
	}
sl@0
    94
sl@0
    95
TSize CTestGraphicsDevice::SizeInTwips() const
sl@0
    96
	{
sl@0
    97
	return TSize(iSize.iWidth * iHorizontalTwipsToPixels,
sl@0
    98
		iSize.iHeight * iVerticalTwipsToPixels);
sl@0
    99
	}
sl@0
   100
sl@0
   101
TInt CTestGraphicsDevice::CreateContext(CGraphicsContext*& aGC)
sl@0
   102
	{
sl@0
   103
	CGraphicsContext* r = new CTestGraphicsContext(this);
sl@0
   104
	if (!r)
sl@0
   105
		return KErrNoMemory;
sl@0
   106
	aGC = r;
sl@0
   107
	return KErrNone;
sl@0
   108
	}
sl@0
   109
sl@0
   110
TInt CTestGraphicsDevice::NumTypefaces() const
sl@0
   111
	{
sl@0
   112
	return 1;
sl@0
   113
	}
sl@0
   114
sl@0
   115
void CTestGraphicsDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport, TInt aTypefaceIndex) const
sl@0
   116
	{
sl@0
   117
	// The only font we have at the moment is 10 pixels * 12 pixels for every character
sl@0
   118
	__ASSERT_ALWAYS(aTypefaceIndex == 0,
sl@0
   119
		CTestGraphicsContext::Panic(CTestGraphicsContext::ETypefaceIndexOutOfRange));
sl@0
   120
	aTypefaceSupport.iIsScalable = EFalse;
sl@0
   121
	aTypefaceSupport.iMaxHeightInTwips = iVerticalTwipsToPixels * 12;
sl@0
   122
	aTypefaceSupport.iMinHeightInTwips = iVerticalTwipsToPixels * 10;
sl@0
   123
	aTypefaceSupport.iNumHeights = 1;
sl@0
   124
	aTypefaceSupport.iTypeface.iName = KTestFontName;
sl@0
   125
	aTypefaceSupport.iTypeface.SetIsProportional(ETrue); // a bit of a lie
sl@0
   126
	aTypefaceSupport.iTypeface.SetIsSerif(EFalse);
sl@0
   127
	aTypefaceSupport.iTypeface.SetIsSymbol(EFalse);
sl@0
   128
	}
sl@0
   129
sl@0
   130
TInt CTestGraphicsDevice::FontHeightInTwips(TInt aTypefaceIndex, TInt aHeightIndex) const
sl@0
   131
	{
sl@0
   132
	// The only font we have at the moment is 10 pixels * 12 pixels for every character
sl@0
   133
	__ASSERT_ALWAYS(aTypefaceIndex == 0,
sl@0
   134
		CTestGraphicsContext::Panic(CTestGraphicsContext::ETypefaceIndexOutOfRange));
sl@0
   135
	return iVerticalTwipsToPixels * FontHeightInPixels(aTypefaceIndex, aHeightIndex);
sl@0
   136
	}
sl@0
   137
sl@0
   138
void CTestGraphicsDevice::PaletteAttributes(TBool& aModifiable, TInt& aNumEntries) const
sl@0
   139
	{
sl@0
   140
	aModifiable = ETrue;
sl@0
   141
	aNumEntries = 4;
sl@0
   142
	}
sl@0
   143
sl@0
   144
void CTestGraphicsDevice::SetPalette(CPalette* aPalette)
sl@0
   145
	{
sl@0
   146
	for (TInt i = 0; i != CTestPalette2::KNumEntries; ++i)
sl@0
   147
		{
sl@0
   148
		TRgb col = aPalette->GetEntry(i);
sl@0
   149
		iPalette -> SetEntry(i, col);
sl@0
   150
		}
sl@0
   151
	}
sl@0
   152
sl@0
   153
TInt CTestGraphicsDevice::GetPalette(CPalette*& aPalette) const
sl@0
   154
	{
sl@0
   155
	aPalette =  const_cast<CTestPalette2*>(iPalette);
sl@0
   156
	return KErrNone;
sl@0
   157
	}
sl@0
   158
sl@0
   159
void CTestGraphicsDevice::GetPixel(TRgb& aColor, const TPoint&) const
sl@0
   160
	{
sl@0
   161
	aColor = KRgbWhite;
sl@0
   162
	}
sl@0
   163
sl@0
   164
void CTestGraphicsDevice::GetScanLine(TDes8&, const TPoint&, TInt, TDisplayMode) const
sl@0
   165
	{
sl@0
   166
	__ASSERT_DEBUG(0, CTestGraphicsContext::Panic(CTestGraphicsContext::EUnimplemented));
sl@0
   167
	}
sl@0
   168
sl@0
   169
TInt CTestGraphicsDevice::AddFile(const TDesC&, TInt&)
sl@0
   170
	{
sl@0
   171
	return KErrNotSupported;
sl@0
   172
	}
sl@0
   173
sl@0
   174
void CTestGraphicsDevice::RemoveFile(TInt)
sl@0
   175
	{
sl@0
   176
	}
sl@0
   177
sl@0
   178
TInt CTestGraphicsDevice::GetNearestFontInPixels(CFont*& aFont, const TFontSpec& aFontSpec)
sl@0
   179
	{
sl@0
   180
	return GetNearestFontToDesignHeightInPixels(aFont, aFontSpec);
sl@0
   181
	}
sl@0
   182
sl@0
   183
TInt CTestGraphicsDevice::GetNearestFontToDesignHeightInPixels(CFont*& aFont, const TFontSpec& /*aFontSpec*/)
sl@0
   184
	{
sl@0
   185
	CTestFont* font = new CTestFont();
sl@0
   186
	if (!font)
sl@0
   187
		return KErrNoMemory;
sl@0
   188
	aFont = font;
sl@0
   189
	return KErrNone;
sl@0
   190
	}
sl@0
   191
sl@0
   192
TInt CTestGraphicsDevice::GetNearestFontToMaxHeightInPixels(CFont*& aFont, const TFontSpec& /*aFontSpec*/, TInt /*aMaxHeight*/)
sl@0
   193
	{
sl@0
   194
	CTestFont* font = new CTestFont();
sl@0
   195
	if (!font)
sl@0
   196
		return KErrNoMemory;
sl@0
   197
	aFont = font;
sl@0
   198
	return KErrNone;
sl@0
   199
	}
sl@0
   200
sl@0
   201
TInt CTestGraphicsDevice::FontHeightInPixels(TInt, TInt) const
sl@0
   202
	{
sl@0
   203
	return 12;
sl@0
   204
	}
sl@0
   205
sl@0
   206
TInt CTestGraphicsDevice::HorizontalTwipsToPixels(TInt aTwips) const
sl@0
   207
	{
sl@0
   208
	return aTwips / iHorizontalTwipsToPixels;
sl@0
   209
	}
sl@0
   210
sl@0
   211
TInt CTestGraphicsDevice::VerticalTwipsToPixels(TInt aTwips) const
sl@0
   212
	{
sl@0
   213
	return aTwips / iVerticalTwipsToPixels;
sl@0
   214
	}
sl@0
   215
sl@0
   216
TInt CTestGraphicsDevice::HorizontalPixelsToTwips(TInt aPixels) const
sl@0
   217
	{
sl@0
   218
	return aPixels * iHorizontalTwipsToPixels;
sl@0
   219
	}
sl@0
   220
sl@0
   221
TInt CTestGraphicsDevice::VerticalPixelsToTwips(TInt aPixels) const
sl@0
   222
	{
sl@0
   223
	return aPixels * iVerticalTwipsToPixels;
sl@0
   224
	}
sl@0
   225
sl@0
   226
TInt CTestGraphicsDevice::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
sl@0
   227
	{
sl@0
   228
	return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
sl@0
   229
	}
sl@0
   230
sl@0
   231
TInt CTestGraphicsDevice::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
sl@0
   232
	{
sl@0
   233
	TFontSpec fontSpec = aFontSpec;
sl@0
   234
	fontSpec.iHeight = VerticalTwipsToPixels(fontSpec.iHeight);
sl@0
   235
	return GetNearestFontToDesignHeightInPixels(aFont, fontSpec);
sl@0
   236
	}
sl@0
   237
sl@0
   238
TInt CTestGraphicsDevice::GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight)
sl@0
   239
	{
sl@0
   240
	TFontSpec fontSpec = aFontSpec;
sl@0
   241
	fontSpec.iHeight = VerticalTwipsToPixels(fontSpec.iHeight);
sl@0
   242
	return GetNearestFontToMaxHeightInPixels(aFont, fontSpec, VerticalTwipsToPixels(aMaxHeight));
sl@0
   243
	}
sl@0
   244
sl@0
   245
void CTestGraphicsDevice::ReleaseFont(CFont* aFont)
sl@0
   246
	{
sl@0
   247
	__ASSERT_ALWAYS(aFont->TypeUid() == TUid::Uid(12345),
sl@0
   248
		CTestGraphicsContext::Panic(CTestGraphicsContext::EUnknownFont));
sl@0
   249
	delete static_cast<CTestFont*>(aFont);
sl@0
   250
	}
sl@0
   251
sl@0
   252
//
sl@0
   253
//
sl@0
   254
// CTestGraphicsContext
sl@0
   255
//
sl@0
   256
//
sl@0
   257
void CTestGraphicsContext::Panic(TInt aReason)
sl@0
   258
	{
sl@0
   259
	User::Panic(_L("CTestGC"), aReason);
sl@0
   260
	}
sl@0
   261
sl@0
   262
CTestGraphicsContext::CTestGraphicsContext(CTestGraphicsDevice* aGd)
sl@0
   263
	: iGd(aGd), iDrawMode(EDrawModePEN), iPenSize(1,1)
sl@0
   264
	{
sl@0
   265
	}
sl@0
   266
sl@0
   267
CTestGraphicsContext::~CTestGraphicsContext()
sl@0
   268
	{
sl@0
   269
	iLineArray.Reset();
sl@0
   270
	}
sl@0
   271
void CTestGraphicsContext::AddRectToDrawnArea(const TRect& aRect)
sl@0
   272
	{
sl@0
   273
	if (iDrawnArea.IsEmpty())
sl@0
   274
		iDrawnArea = aRect;
sl@0
   275
	else
sl@0
   276
		iDrawnArea.BoundingRect(aRect);
sl@0
   277
	// only one condition at the moment
sl@0
   278
	if (iDrawMode == EDrawModeXOR)
sl@0
   279
		{
sl@0
   280
		if (iAreaDrawnWithCondition.IsEmpty())
sl@0
   281
			iAreaDrawnWithCondition = aRect;
sl@0
   282
		else
sl@0
   283
			iAreaDrawnWithCondition.BoundingRect(aRect);
sl@0
   284
		}
sl@0
   285
	}
sl@0
   286
sl@0
   287
void CTestGraphicsContext::AddPointToDrawnArea(const TPoint& aPoint)
sl@0
   288
	{
sl@0
   289
	AddRectToDrawnArea(TRect(aPoint, iPenSize));
sl@0
   290
	}
sl@0
   291
sl@0
   292
CGraphicsDevice* CTestGraphicsContext::Device() const
sl@0
   293
	{
sl@0
   294
	return iGd;
sl@0
   295
	}
sl@0
   296
sl@0
   297
void CTestGraphicsContext::SetOrigin(const TPoint& aPos)
sl@0
   298
	{
sl@0
   299
	iOrigin = aPos;
sl@0
   300
	}
sl@0
   301
sl@0
   302
void CTestGraphicsContext::SetDrawMode(TDrawMode aDrawingMode)
sl@0
   303
	{
sl@0
   304
	iDrawMode = aDrawingMode;
sl@0
   305
	}
sl@0
   306
sl@0
   307
void CTestGraphicsContext::SetClippingRect(const TRect& /*aRect*/)
sl@0
   308
	{
sl@0
   309
	}
sl@0
   310
sl@0
   311
void CTestGraphicsContext::CancelClippingRect()
sl@0
   312
	{
sl@0
   313
	}
sl@0
   314
sl@0
   315
void CTestGraphicsContext::Reset()
sl@0
   316
	{
sl@0
   317
	iDrawMode = EDrawModePEN;
sl@0
   318
	iFont = 0;
sl@0
   319
	iPenSize.iWidth = 1;
sl@0
   320
	iPenSize.iHeight = 1;
sl@0
   321
	}
sl@0
   322
sl@0
   323
void CTestGraphicsContext::UseFont(const CFont* aFont)
sl@0
   324
	{
sl@0
   325
	iFont = aFont;
sl@0
   326
	}
sl@0
   327
sl@0
   328
void CTestGraphicsContext::DiscardFont()
sl@0
   329
	{
sl@0
   330
	iFont = 0;
sl@0
   331
	}
sl@0
   332
sl@0
   333
void CTestGraphicsContext::SetUnderlineStyle(TFontUnderline /*UnderlineStyle*/)
sl@0
   334
	{
sl@0
   335
	}
sl@0
   336
sl@0
   337
void CTestGraphicsContext::SetStrikethroughStyle(TFontStrikethrough /*aStrikethroughStyle*/)
sl@0
   338
	{
sl@0
   339
	}
sl@0
   340
sl@0
   341
void CTestGraphicsContext::SetWordJustification(TInt /*aExcessWidth*/,TInt /*aNumGaps*/)
sl@0
   342
	{
sl@0
   343
	}
sl@0
   344
sl@0
   345
void CTestGraphicsContext::SetCharJustification(TInt /*aExcessWidth*/,TInt /*aNumChars*/)
sl@0
   346
	{
sl@0
   347
	}
sl@0
   348
sl@0
   349
void CTestGraphicsContext::SetPenColor(const TRgb& aColor)
sl@0
   350
	{
sl@0
   351
	CPalette* palette;
sl@0
   352
	iGd->GetPalette(palette);
sl@0
   353
	iPenColorIndex = palette->NearestIndex(aColor);
sl@0
   354
	}
sl@0
   355
sl@0
   356
void CTestGraphicsContext::SetPenStyle(TPenStyle /*aPenStyle*/)
sl@0
   357
	{
sl@0
   358
	}
sl@0
   359
sl@0
   360
void CTestGraphicsContext::SetPenSize(const TSize& aSize)
sl@0
   361
	{
sl@0
   362
	iPenSize = aSize;
sl@0
   363
	}
sl@0
   364
sl@0
   365
void CTestGraphicsContext::SetBrushColor(const TRgb& /*aColor*/)
sl@0
   366
	{
sl@0
   367
	}
sl@0
   368
sl@0
   369
void CTestGraphicsContext::SetBrushStyle(TBrushStyle /*aBrushStyle*/)
sl@0
   370
	{
sl@0
   371
	}
sl@0
   372
sl@0
   373
void CTestGraphicsContext::SetBrushOrigin(const TPoint& /*aOrigin*/)
sl@0
   374
	{
sl@0
   375
	}
sl@0
   376
sl@0
   377
void CTestGraphicsContext::UseBrushPattern(const CFbsBitmap* /*aBitmap*/)
sl@0
   378
	{
sl@0
   379
	}
sl@0
   380
sl@0
   381
void CTestGraphicsContext::DiscardBrushPattern()
sl@0
   382
	{
sl@0
   383
	}
sl@0
   384
sl@0
   385
void CTestGraphicsContext::MoveTo(const TPoint& aPoint)
sl@0
   386
	{
sl@0
   387
	iCurrentPos = iOrigin + aPoint;
sl@0
   388
	}
sl@0
   389
sl@0
   390
void CTestGraphicsContext::MoveBy(const TPoint& aVector)
sl@0
   391
	{
sl@0
   392
	iCurrentPos += aVector;
sl@0
   393
	}
sl@0
   394
sl@0
   395
void CTestGraphicsContext::Plot(const TPoint& aPoint)
sl@0
   396
	{
sl@0
   397
	iCurrentPos = iOrigin + aPoint;
sl@0
   398
	AddPointToDrawnArea(iCurrentPos);
sl@0
   399
	}
sl@0
   400
sl@0
   401
void CTestGraphicsContext::DrawArc(const TRect& aRect,const TPoint& /*aStart*/,const TPoint& aEnd)
sl@0
   402
	{
sl@0
   403
	TRect r = aRect;
sl@0
   404
	r.Move(iOrigin);
sl@0
   405
	AddRectToDrawnArea(r);
sl@0
   406
	iCurrentPos = iOrigin + aEnd;
sl@0
   407
	}
sl@0
   408
sl@0
   409
void CTestGraphicsContext::DrawLine(const TPoint& aPoint1,const TPoint& aPoint2)
sl@0
   410
	{
sl@0
   411
	AddPointToDrawnArea(iOrigin + aPoint1);
sl@0
   412
	iCurrentPos = iOrigin + aPoint2;
sl@0
   413
	AddPointToDrawnArea(iCurrentPos);
sl@0
   414
	}
sl@0
   415
sl@0
   416
void CTestGraphicsContext::DrawLineTo(const TPoint& aPoint)
sl@0
   417
	{
sl@0
   418
	AddPointToDrawnArea(iCurrentPos);
sl@0
   419
	iCurrentPos = iOrigin + aPoint;
sl@0
   420
	AddPointToDrawnArea(iCurrentPos);
sl@0
   421
	}
sl@0
   422
sl@0
   423
void CTestGraphicsContext::DrawLineBy(const TPoint& aVector)
sl@0
   424
	{
sl@0
   425
	AddPointToDrawnArea(iCurrentPos);
sl@0
   426
	iCurrentPos += aVector;
sl@0
   427
	AddPointToDrawnArea(iCurrentPos);
sl@0
   428
	}
sl@0
   429
sl@0
   430
void CTestGraphicsContext::DrawPolyLine(const CArrayFix<TPoint>* aPointList)
sl@0
   431
	{
sl@0
   432
	TInt num = aPointList->Count();
sl@0
   433
	while (num--)
sl@0
   434
		{
sl@0
   435
		iCurrentPos = iOrigin + (*aPointList)[num - 1];
sl@0
   436
		AddPointToDrawnArea(iCurrentPos);
sl@0
   437
		}
sl@0
   438
	}
sl@0
   439
sl@0
   440
void CTestGraphicsContext::DrawPolyLine(const TPoint* aPointList,TInt aNumPoints)
sl@0
   441
	{
sl@0
   442
	while (aNumPoints--)
sl@0
   443
		{
sl@0
   444
		iCurrentPos = iOrigin + aPointList[aNumPoints - 1];
sl@0
   445
		AddPointToDrawnArea(iCurrentPos);
sl@0
   446
		}
sl@0
   447
	}
sl@0
   448
sl@0
   449
void CTestGraphicsContext::DrawPie(const TRect& aRect,
sl@0
   450
	const TPoint& /*aStart*/, const TPoint& aEnd)
sl@0
   451
	{
sl@0
   452
	TRect r = aRect;
sl@0
   453
	r.Move(iOrigin);
sl@0
   454
	AddRectToDrawnArea(r);
sl@0
   455
	iCurrentPos = iOrigin + aEnd;
sl@0
   456
	}
sl@0
   457
sl@0
   458
void CTestGraphicsContext::DrawEllipse(const TRect& aRect)
sl@0
   459
	{
sl@0
   460
	TRect r = aRect;
sl@0
   461
	r.Move(iOrigin);
sl@0
   462
	AddRectToDrawnArea(r);
sl@0
   463
	}
sl@0
   464
sl@0
   465
void CTestGraphicsContext::DrawRect(const TRect& aRect)
sl@0
   466
	{
sl@0
   467
	TRect r = aRect;
sl@0
   468
	r.Move(iOrigin);
sl@0
   469
	AddRectToDrawnArea(r);
sl@0
   470
	}
sl@0
   471
sl@0
   472
void CTestGraphicsContext::DrawRoundRect(const TRect& aRect,const TSize& aCornerSize)
sl@0
   473
	{
sl@0
   474
	TRect r = aRect;
sl@0
   475
	r.Move(iOrigin);
sl@0
   476
	r.Grow(aCornerSize);
sl@0
   477
	AddRectToDrawnArea(r);
sl@0
   478
	}
sl@0
   479
sl@0
   480
TInt CTestGraphicsContext::DrawPolygon(const CArrayFix<TPoint>* aPointList,TFillRule /*aFillRule*/)
sl@0
   481
	{
sl@0
   482
	TInt num = aPointList->Count();
sl@0
   483
	while (num--)
sl@0
   484
		{
sl@0
   485
		iCurrentPos = iOrigin + (*aPointList)[num - 1];
sl@0
   486
		AddPointToDrawnArea(iCurrentPos);
sl@0
   487
		}
sl@0
   488
	return KErrNone;
sl@0
   489
	}
sl@0
   490
sl@0
   491
TInt CTestGraphicsContext::DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule /*aFillRule*/)
sl@0
   492
	{
sl@0
   493
	while (aNumPoints--)
sl@0
   494
		{
sl@0
   495
		iCurrentPos = iOrigin + aPointList[aNumPoints - 1];
sl@0
   496
		AddPointToDrawnArea(iCurrentPos);
sl@0
   497
		}
sl@0
   498
	return KErrNone;
sl@0
   499
	}
sl@0
   500
sl@0
   501
void CTestGraphicsContext::DrawBitmap(const TPoint& /*aTopLeft*/,const CFbsBitmap* /*aSource*/)
sl@0
   502
	{
sl@0
   503
	}
sl@0
   504
sl@0
   505
void CTestGraphicsContext::DrawBitmap(const TRect& /*aDestRect*/,const CFbsBitmap* /*aSource*/)
sl@0
   506
	{
sl@0
   507
	}
sl@0
   508
sl@0
   509
void CTestGraphicsContext::DrawBitmap(const TRect& /*aDestRect*/,const CFbsBitmap* /*aSource*/,const TRect& /*aSourceRect*/)
sl@0
   510
	{
sl@0
   511
	}
sl@0
   512
sl@0
   513
void CTestGraphicsContext::DrawBitmapMasked(const TRect& /*aDestRect*/,const CFbsBitmap* /*aBitmap*/,const TRect& /*aSourceRect*/,const CFbsBitmap* /*aMaskBitmap*/,TBool /*aInvertMask*/)
sl@0
   514
	{}
sl@0
   515
	
sl@0
   516
void CTestGraphicsContext::DrawBitmapMasked(const TRect& /*aDestRect*/,const CWsBitmap* /*aBitmap*/,const TRect& /*aSourceRect*/,const CWsBitmap* /*aMaskBitmap*/,TBool /*aInvertMask*/)
sl@0
   517
	{
sl@0
   518
	}
sl@0
   519
sl@0
   520
void CTestGraphicsContext::MapColors(const TRect &/*aRect*/,const TRgb */*aColors*/,TInt /*aNumPairs*/,TBool /*aMapForwards*/)
sl@0
   521
	{}
sl@0
   522
	
sl@0
   523
TInt CTestGraphicsContext::SetClippingRegion(const TRegion &/*aRegion*/)
sl@0
   524
	{
sl@0
   525
		return KErrNone;
sl@0
   526
	}	
sl@0
   527
	
sl@0
   528
void CTestGraphicsContext::CancelClippingRegion()
sl@0
   529
	{}
sl@0
   530
	
sl@0
   531
void CTestGraphicsContext::DrawTextVertical(const TDesC& /*aText*/,const TPoint& /*aPos*/,TBool /*aUp*/)
sl@0
   532
	{}
sl@0
   533
	
sl@0
   534
void CTestGraphicsContext::DrawTextVertical(const TDesC& /*aText*/,const TRect& /*aBox*/,TInt /*aBaselineOffset*/,TBool /*aUp*/,TTextAlign /*aVert*/,TInt /*aMargin*/)
sl@0
   535
	{}
sl@0
   536
	
sl@0
   537
/**
sl@0
   538
 *
sl@0
   539
 * DrawText - merely add line "drawn" to collection
sl@0
   540
 *
sl@0
   541
 */
sl@0
   542
sl@0
   543
sl@0
   544
void CTestGraphicsContext::DrawText(const TDesC& aText,const TPoint& aPosition)
sl@0
   545
	{
sl@0
   546
sl@0
   547
#ifdef PRINT_DRAWTEXT_LINES
sl@0
   548
sl@0
   549
	_LIT(KDrawTextFormat, "DrawText called for position %d,%d:");
sl@0
   550
	_LIT(KDrawTextTitle, "Text being drawn");
sl@0
   551
		test.Printf(KDrawTextFormat, aPosition.iX, aPosition.iY);
sl@0
   552
		PrintTestData(KDrawTextTitle, aText);
sl@0
   553
sl@0
   554
#endif /* PRINT_DRAWTEXT_LINES */
sl@0
   555
	
sl@0
   556
	TTestGCDisplayLine thisLine;
sl@0
   557
	thisLine.Set(aPosition, aText);
sl@0
   558
	iLineArray.Append(thisLine);
sl@0
   559
sl@0
   560
	}
sl@0
   561
sl@0
   562
void CTestGraphicsContext::DrawText(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,
sl@0
   563
	TTextAlign /*aAlignment*/, TInt aLeftMargin)
sl@0
   564
	{
sl@0
   565
	TPoint pos(aBox.iBr.iX + aLeftMargin, aBox.iTl.iY + aBaselineOffset);
sl@0
   566
	pos += iOrigin;
sl@0
   567
	DrawText(aText, pos);
sl@0
   568
	}
sl@0
   569
sl@0
   570
void CTestGraphicsContext::DrawText(const TDesC& aText, const TPoint& aPosition,
sl@0
   571
	const TDrawTextParam&)
sl@0
   572
	{
sl@0
   573
	DrawText(aText, aPosition);
sl@0
   574
	}
sl@0
   575
sl@0
   576
//
sl@0
   577
//
sl@0
   578
// CTestFont
sl@0
   579
//
sl@0
   580
//
sl@0
   581
TUid CTestFont::DoTypeUid() const
sl@0
   582
	{
sl@0
   583
	return TUid::Uid(12345);
sl@0
   584
	}
sl@0
   585
sl@0
   586
TInt CTestFont::DoHeightInPixels() const
sl@0
   587
	{
sl@0
   588
	return 12;
sl@0
   589
	}
sl@0
   590
sl@0
   591
TInt CTestFont::DoAscentInPixels() const
sl@0
   592
	{
sl@0
   593
	return 10;
sl@0
   594
	}
sl@0
   595
sl@0
   596
TInt CTestFont::DoCharWidthInPixels(TChar aChar) const
sl@0
   597
	{
sl@0
   598
	switch (aChar)
sl@0
   599
		{
sl@0
   600
	case 0x200C:
sl@0
   601
	case 0x200D:
sl@0
   602
	case 0x200E:
sl@0
   603
	case 0x200F:
sl@0
   604
	case 0x202A:
sl@0
   605
	case 0x202B:
sl@0
   606
	case 0x202C:
sl@0
   607
	case 0x202D:
sl@0
   608
	case 0x202E:
sl@0
   609
	case 0xFFFF:
sl@0
   610
		return 0;
sl@0
   611
	default:
sl@0
   612
		return 10;
sl@0
   613
		}
sl@0
   614
	}
sl@0
   615
sl@0
   616
TInt CTestFont::DoTextWidthInPixels(const TDesC& aText) const
sl@0
   617
	{
sl@0
   618
	TInt total = 0;
sl@0
   619
	const TText* p = aText.Ptr();
sl@0
   620
	const TText* end = p + aText.Length();
sl@0
   621
	for (;p != end; ++p)
sl@0
   622
		total += CharWidthInPixels(*p);
sl@0
   623
	return total;
sl@0
   624
	}
sl@0
   625
sl@0
   626
TInt CTestFont::DoBaselineOffsetInPixels() const
sl@0
   627
	{
sl@0
   628
	return 10;
sl@0
   629
	}
sl@0
   630
sl@0
   631
TInt CTestFont::DoTextCount(const TDesC& aText,TInt aWidthInPixels) const
sl@0
   632
	{
sl@0
   633
	TInt excess;
sl@0
   634
	return DoTextCount(aText, aWidthInPixels, excess);
sl@0
   635
	}
sl@0
   636
sl@0
   637
TInt CTestFont::DoTextCount(const TDesC& aText,TInt aWidthInPixels,TInt& aExcessWidthInPixels) const
sl@0
   638
	{
sl@0
   639
	aExcessWidthInPixels = aWidthInPixels;
sl@0
   640
	const TText* start = aText.Ptr();
sl@0
   641
	const TText* end = start + aText.Length();
sl@0
   642
	const TText* p = start;
sl@0
   643
	TInt width;
sl@0
   644
	while (p != end
sl@0
   645
		&& (width = CharWidthInPixels(*p)) <= aExcessWidthInPixels)
sl@0
   646
		{
sl@0
   647
		aExcessWidthInPixels -= width;
sl@0
   648
		++p;
sl@0
   649
		}
sl@0
   650
	return p - start;
sl@0
   651
	}
sl@0
   652
sl@0
   653
TInt CTestFont::DoMaxCharWidthInPixels() const
sl@0
   654
	{
sl@0
   655
	return 10;
sl@0
   656
	}
sl@0
   657
sl@0
   658
TInt CTestFont::DoMaxNormalCharWidthInPixels() const
sl@0
   659
	{
sl@0
   660
	return 10;
sl@0
   661
	}
sl@0
   662
sl@0
   663
TFontSpec CTestFont::DoFontSpecInTwips() const
sl@0
   664
	{
sl@0
   665
	return TFontSpec(KTestFontName, 12);
sl@0
   666
	}
sl@0
   667
sl@0
   668
CFont::TCharacterDataAvailability 
sl@0
   669
 CTestFont::DoGetCharacterData(TUint aCode, TOpenFontCharMetrics& aMetrics,
sl@0
   670
 	const TUint8*& aBitmap, TSize& aBitmapSize) const
sl@0
   671
   	{
sl@0
   672
 	TInt width;
sl@0
   673
   	switch (aCode)
sl@0
   674
   		{
sl@0
   675
   	case 0x001B:
sl@0
   676
 		// ESC character should cause this fault; no character data available.
sl@0
   677
   		return CFont::ENoCharacterData;
sl@0
   678
 	case 'W':
sl@0
   679
 		// We want 'W' to have side-bearings
sl@0
   680
 		CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
sl@0
   681
 		width = aMetrics.Width();
sl@0
   682
 		aMetrics.SetHorizBearingX(-1);
sl@0
   683
 		aMetrics.SetWidth(width + 2);
sl@0
   684
 		return CFont::ECharacterWidthOnly ;
sl@0
   685
 	case 0x0648:
sl@0
   686
 		// Arabic Waw-- has massive left side-bearing
sl@0
   687
 		CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
sl@0
   688
 		width = aMetrics.Width();
sl@0
   689
 		aMetrics.SetHorizBearingX(-5);
sl@0
   690
 		aMetrics.SetWidth(width + 5);
sl@0
   691
 		return CFont::ECharacterWidthOnly ;
sl@0
   692
	case 'X':
sl@0
   693
		// We want 'X' to have a left side-bearing only
sl@0
   694
		CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
sl@0
   695
		aMetrics.SetHorizBearingX(-1);
sl@0
   696
		return CFont::ECharacterWidthOnly ;
sl@0
   697
	case 0x05EA:
sl@0
   698
		// We want Hebrew Tav to have a +ve left side-bearing
sl@0
   699
		CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
sl@0
   700
		aMetrics.SetHorizBearingX(1);
sl@0
   701
		return CFont::ECharacterWidthOnly ;
sl@0
   702
	case 0x304B:
sl@0
   703
		// We want Hiragana Ka to have a top end-bearing
sl@0
   704
		CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
sl@0
   705
		aMetrics.SetVertBearingY(-1);
sl@0
   706
		return CFont::EAllCharacterData ;
sl@0
   707
	case 0x0020:
sl@0
   708
		CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
sl@0
   709
		aMetrics.SetWidth(0);
sl@0
   710
		aMetrics.SetHeight(0);
sl@0
   711
		aMetrics.SetVertAdvance(0);
sl@0
   712
		return CFont::ECharacterWidthOnly ;	
sl@0
   713
	default:
sl@0
   714
		return CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
sl@0
   715
		}
sl@0
   716
	}