os/textandloc/textrendering/textformatting/test/src/TGraphicsContext.cpp
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.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,903 @@
     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 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "TGraphicsContext.h"
    1.23 +#include <e32std.h>
    1.24 +
    1.25 +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    1.26 +#include <graphics/gdi/gdiconsts.h>
    1.27 +#include <graphics/gdi/gdistructs.h>
    1.28 +#endif
    1.29 +
    1.30 +_LIT(KTestFontName, "Non Functional Test Font");
    1.31 +
    1.32 +
    1.33 +// Utility functions to show contents of test data using test.Printf
    1.34 +
    1.35 +extern void PrintTestData (const TDesC& aTitle , const TDesC16& aDataBuffer);
    1.36 +
    1.37 +extern void PrintTestData(const TDesC& aTitle, const TText16* aDataBuffer, const TInt aSize);
    1.38 +
    1.39 +//
    1.40 +//
    1.41 +// CLineArray
    1.42 +//
    1.43 +//
    1.44 +CLineArray::CLineArray() : iArrayIsEnabled(ETrue), iArray(0)
    1.45 +	{
    1.46 +	iPrev = iNext = this;
    1.47 +	}
    1.48 +
    1.49 +void CLineArray::Null()
    1.50 +	{
    1.51 +	if (iNext == this && iArray)
    1.52 +		{
    1.53 +		iArray->Close();
    1.54 +		delete iArray;
    1.55 +		}
    1.56 +	iArray = 0;
    1.57 +	iPrev->iNext = iNext;
    1.58 +	iNext->iPrev = iPrev;
    1.59 +	iNext = iPrev = this;
    1.60 +	}
    1.61 +
    1.62 +CLineArray::~CLineArray()
    1.63 +	{
    1.64 +	Null();
    1.65 +	}
    1.66 +
    1.67 +void CLineArray::ConstructL(TInt aGranularity)
    1.68 +	{
    1.69 +	CLineArray::Null();
    1.70 +	iArray = new (ELeave) RArray<TTestGCDisplayLine>(aGranularity);
    1.71 +	}
    1.72 +
    1.73 +void CLineArray::Copy(const CLineArray& aOther)
    1.74 +	{
    1.75 +	CLineArray::Null();
    1.76 +	iNext = &aOther;
    1.77 +	iPrev = aOther.iPrev;
    1.78 +	iPrev->iNext = this;
    1.79 +	aOther.iPrev = this;
    1.80 +	iArray = aOther.iArray;
    1.81 +	iArrayIsEnabled = aOther.iArrayIsEnabled;
    1.82 +	}
    1.83 +
    1.84 +void CLineArray::ResetLineArray()
    1.85 +	{
    1.86 +	iArray->Reset();
    1.87 +	}
    1.88 +
    1.89 +const TTestGCDisplayLine& CLineArray::Line(TInt aIndex)
    1.90 +	{
    1.91 +	return (*iArray)[aIndex];
    1.92 +	}
    1.93 +
    1.94 +const TTestGCDisplayLine* CLineArray::Find(const TDesC& aText)
    1.95 +	{
    1.96 +	TInt count = LinesPresent();
    1.97 +	for (TInt i = 0; i != count; ++i)
    1.98 +		{		
    1.99 +		const TTestGCDisplayLine& line = Line(i);
   1.100 +		if (line.iLineData.Find(aText) != KErrNotFound)
   1.101 +			return &line;
   1.102 +		}
   1.103 +	return 0;
   1.104 +	}
   1.105 +
   1.106 +void CLineArray::AddLineL(TTestGCDisplayLine& aLine)
   1.107 +	{
   1.108 +	if (iArrayIsEnabled)
   1.109 +		User::LeaveIfError(iArray->Append(aLine));
   1.110 +	}
   1.111 +
   1.112 +TInt CLineArray::LinesPresent()
   1.113 +	{
   1.114 +	return iArray->Count();
   1.115 +	}
   1.116 +
   1.117 +//
   1.118 +//
   1.119 +// CTestGraphicsDevice
   1.120 +//
   1.121 +//
   1.122 +CTestGraphicsDevice* CTestGraphicsDevice::NewL(TSize aSizeInPixels, RWsSession* aWsSession)
   1.123 +	{
   1.124 +	CTestGraphicsDevice* r = aWsSession?
   1.125 +		new (ELeave) CTestGraphicsDevice(aSizeInPixels, aWsSession)
   1.126 +		: new (ELeave) CTestGraphicsDevice(aSizeInPixels);
   1.127 +	r->iLineArray.ConstructL(4);
   1.128 +	if (aWsSession && KErrNone != r->Construct())
   1.129 +		{
   1.130 +		delete r;
   1.131 +		return 0;
   1.132 +		}
   1.133 +	return r;
   1.134 +	}
   1.135 +
   1.136 +CTestGraphicsDevice::CTestGraphicsDevice(TSize aSizeInPixels, RWsSession* aWsSession)
   1.137 +	: CWsScreenDevice(*aWsSession)
   1.138 +	{
   1.139 +	Set(aSizeInPixels);
   1.140 +	}
   1.141 +
   1.142 +CTestGraphicsDevice::CTestGraphicsDevice(TSize aSizeInPixels)
   1.143 +	{
   1.144 +	Set(aSizeInPixels);
   1.145 +	}
   1.146 +
   1.147 +void CTestGraphicsDevice::Set(TSize aSizeInPixels)
   1.148 +	{
   1.149 +	iSize = aSizeInPixels;
   1.150 +	iHorizontalTwipsToPixels = 40;
   1.151 +	iVerticalTwipsToPixels = 40;
   1.152 +	iPalette.SetEntry(0, KRgbBlack);
   1.153 +	iPalette.SetEntry(1, KRgbWhite);
   1.154 +	iPalette.SetEntry(2, KRgbMagenta);
   1.155 +	iPalette.SetEntry(3, KRgbCyan);
   1.156 +	}
   1.157 +
   1.158 +void CTestGraphicsDevice::SetHorizontalTwipsToPixels(TInt aTwipsToPixels)
   1.159 +	{
   1.160 +	iHorizontalTwipsToPixels = aTwipsToPixels;
   1.161 +	}
   1.162 +
   1.163 +void CTestGraphicsDevice::SetVerticalTwipsToPixels(TInt aTwipsToPixels)
   1.164 +	{
   1.165 +	iVerticalTwipsToPixels = aTwipsToPixels;
   1.166 +	}
   1.167 +
   1.168 +TDisplayMode CTestGraphicsDevice::DisplayMode() const
   1.169 +	{
   1.170 +	return EColor16M;
   1.171 +	}
   1.172 +
   1.173 +TSize CTestGraphicsDevice::SizeInPixels() const
   1.174 +	{
   1.175 +	return iSize;
   1.176 +	}
   1.177 +
   1.178 +TSize CTestGraphicsDevice::SizeInTwips() const
   1.179 +	{
   1.180 +	return TSize(iSize.iWidth * iHorizontalTwipsToPixels,
   1.181 +		iSize.iHeight * iVerticalTwipsToPixels);
   1.182 +	}
   1.183 +
   1.184 +TInt CTestGraphicsDevice::CreateContext(CWindowGc*& aGC)
   1.185 +	{
   1.186 +	CTestGraphicsContext* r = new CTestGraphicsContext(this);
   1.187 +	if (!r)
   1.188 +		return KErrNoMemory;
   1.189 +	// only contruct if it is a fully-fledged Window Server thing
   1.190 +	if (iBuffer)
   1.191 +		r->Construct();
   1.192 +	aGC = r;
   1.193 +	return KErrNone;
   1.194 +	}
   1.195 +
   1.196 +TInt CTestGraphicsDevice::CreateContext(CGraphicsContext*& aGC)
   1.197 +	{
   1.198 +	CWindowGc* p;
   1.199 +	TInt r = CreateContext(p);
   1.200 +	aGC = p;
   1.201 +	return r;
   1.202 +	}
   1.203 +
   1.204 +TInt CTestGraphicsDevice::NumTypefaces() const
   1.205 +	{
   1.206 +	return 1;
   1.207 +	}
   1.208 +
   1.209 +void CTestGraphicsDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport, TInt aTypefaceIndex) const
   1.210 +	{
   1.211 +	// The only font we have at the moment is 10 pixels * 12 pixels for every character
   1.212 +	__ASSERT_ALWAYS(aTypefaceIndex == 0,
   1.213 +		CTestGraphicsContext::Panic(CTestGraphicsContext::ETypefaceIndexOutOfRange));
   1.214 +	aTypefaceSupport.iIsScalable = EFalse;
   1.215 +	aTypefaceSupport.iMaxHeightInTwips = iVerticalTwipsToPixels * 12;
   1.216 +	aTypefaceSupport.iMinHeightInTwips = iVerticalTwipsToPixels * 10;
   1.217 +	aTypefaceSupport.iNumHeights = 1;
   1.218 +	aTypefaceSupport.iTypeface.iName = KTestFontName;
   1.219 +	aTypefaceSupport.iTypeface.SetIsProportional(ETrue); // a bit of a lie
   1.220 +	aTypefaceSupport.iTypeface.SetIsSerif(EFalse);
   1.221 +	aTypefaceSupport.iTypeface.SetIsSymbol(EFalse);
   1.222 +	}
   1.223 +
   1.224 +TInt CTestGraphicsDevice::FontHeightInTwips(TInt aTypefaceIndex, TInt aHeightIndex) const
   1.225 +	{
   1.226 +	// The only font we have at the moment is 10 pixels * 12 pixels for every character
   1.227 +	__ASSERT_ALWAYS(aTypefaceIndex == 0,
   1.228 +		CTestGraphicsContext::Panic(CTestGraphicsContext::ETypefaceIndexOutOfRange));
   1.229 +	return iVerticalTwipsToPixels * FontHeightInPixels(aTypefaceIndex, aHeightIndex);
   1.230 +	}
   1.231 +
   1.232 +void CTestGraphicsDevice::PaletteAttributes(TBool& aModifiable, TInt& aNumEntries) const
   1.233 +	{
   1.234 +	aModifiable = ETrue;
   1.235 +	aNumEntries = 4;
   1.236 +	}
   1.237 +
   1.238 +void CTestGraphicsDevice::SetPalette(CPalette* aPalette)
   1.239 +	{
   1.240 +	for (TInt i = 0; i != CTestPalette::KNumEntries; ++i)
   1.241 +		{
   1.242 +		TRgb col = aPalette->GetEntry(i);
   1.243 +		iPalette.SetEntry(i, col);
   1.244 +		}
   1.245 +	}
   1.246 +
   1.247 +TInt CTestGraphicsDevice::GetPalette(CPalette*& aPalette) const
   1.248 +	{
   1.249 +	aPalette = const_cast<CTestPalette*>(&iPalette);
   1.250 +	return KErrNone;
   1.251 +	}
   1.252 +
   1.253 +void CTestGraphicsDevice::GetPixel(TRgb& aColor, const TPoint&) const
   1.254 +	{
   1.255 +	aColor = KRgbWhite;
   1.256 +	}
   1.257 +
   1.258 +void CTestGraphicsDevice::GetScanLine(TDes8&, const TPoint&, TInt, TDisplayMode) const
   1.259 +	{
   1.260 +	__ASSERT_DEBUG(0, CTestGraphicsContext::Panic(CTestGraphicsContext::EUnimplemented));
   1.261 +	}
   1.262 +
   1.263 +TInt CTestGraphicsDevice::AddFile(const TDesC&, TInt&)
   1.264 +	{
   1.265 +	return KErrNotSupported;
   1.266 +	}
   1.267 +
   1.268 +void CTestGraphicsDevice::RemoveFile(TInt)
   1.269 +	{
   1.270 +	}
   1.271 +
   1.272 +TInt CTestGraphicsDevice::GetNearestFontInPixels(CFont*& aFont, const TFontSpec&)
   1.273 +	{
   1.274 +	CTestFont* font = new CTestFont();
   1.275 +	if (!font)
   1.276 +		return KErrNoMemory;
   1.277 +	aFont = font;
   1.278 +	return KErrNone;
   1.279 +	}
   1.280 +
   1.281 +TInt CTestGraphicsDevice::FontHeightInPixels(TInt, TInt) const
   1.282 +	{
   1.283 +	return 12;
   1.284 +	}
   1.285 +
   1.286 +TInt CTestGraphicsDevice::HorizontalTwipsToPixels(TInt aTwips) const
   1.287 +	{
   1.288 +	return aTwips / iHorizontalTwipsToPixels;
   1.289 +	}
   1.290 +
   1.291 +TInt CTestGraphicsDevice::VerticalTwipsToPixels(TInt aTwips) const
   1.292 +	{
   1.293 +	return aTwips / iVerticalTwipsToPixels;
   1.294 +	}
   1.295 +
   1.296 +TInt CTestGraphicsDevice::HorizontalPixelsToTwips(TInt aPixels) const
   1.297 +	{
   1.298 +	return aPixels * iHorizontalTwipsToPixels;
   1.299 +	}
   1.300 +
   1.301 +TInt CTestGraphicsDevice::VerticalPixelsToTwips(TInt aPixels) const
   1.302 +	{
   1.303 +	return aPixels * iVerticalTwipsToPixels;
   1.304 +	}
   1.305 +
   1.306 +TInt CTestGraphicsDevice::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
   1.307 +	{
   1.308 +	TFontSpec fontSpec = aFontSpec;
   1.309 +	fontSpec.iHeight = VerticalTwipsToPixels(fontSpec.iHeight);
   1.310 +	return GetNearestFontInPixels(aFont, fontSpec);
   1.311 +	}
   1.312 +
   1.313 +void CTestGraphicsDevice::ReleaseFont(CFont* aFont)
   1.314 +	{
   1.315 +	__ASSERT_ALWAYS(aFont->TypeUid() == TUid::Uid(12345),
   1.316 +		CTestGraphicsContext::Panic(CTestGraphicsContext::EUnknownFont));
   1.317 +	delete static_cast<CTestFont*>(aFont);
   1.318 +	}
   1.319 +
   1.320 +void CTestGraphicsDevice::AddRectToDrawnArea(const TRect& aRect, TBool aCondition)
   1.321 +	{
   1.322 +	// check if the drawing is on testing area
   1.323 +	if (!(iTestingArea.IsEmpty()) &&  	// if testing area has been set
   1.324 +		!iHasDrawnOnTestingArea)		// and nothing hasn't been drawn on it so far
   1.325 +		iHasDrawnOnTestingArea = iTestingArea.Intersects(aRect);
   1.326 +	
   1.327 +	if (iDrawnArea.IsEmpty())
   1.328 +		iDrawnArea = aRect;
   1.329 +	else
   1.330 +		iDrawnArea.BoundingRect(aRect);
   1.331 +	// only one condition at the moment
   1.332 +	if (aCondition)
   1.333 +		{
   1.334 +		if (iAreaDrawnWithCondition.IsEmpty())
   1.335 +			iAreaDrawnWithCondition = aRect;
   1.336 +		else
   1.337 +			iAreaDrawnWithCondition.BoundingRect(aRect);
   1.338 +		}
   1.339 +	}
   1.340 +
   1.341 +void CTestGraphicsDevice::SetTestingArea(TRect& aTestingArea)
   1.342 +	{
   1.343 +	iTestingArea = aTestingArea;
   1.344 +	}
   1.345 +
   1.346 +void CTestGraphicsDevice::AddTestingArea(TRect& moreTestingArea)
   1.347 +	{
   1.348 +	if (iTestingArea.IsEmpty())
   1.349 +		iTestingArea = moreTestingArea;
   1.350 +	else
   1.351 +		iTestingArea.BoundingRect(moreTestingArea);
   1.352 +	}
   1.353 +
   1.354 +//
   1.355 +//
   1.356 +// CTestGraphicsContext
   1.357 +//
   1.358 +//
   1.359 +void CTestGraphicsContext::Panic(TInt aReason)
   1.360 +	{
   1.361 +	User::Panic(_L("CTestGC"), aReason);
   1.362 +	}
   1.363 +
   1.364 +CTestGraphicsContext::CTestGraphicsContext(CTestGraphicsDevice* aGd)
   1.365 +	: CWindowGc(aGd), iGd(aGd), iDrawMode(EDrawModePEN), iPenSize(1,1)
   1.366 +	{
   1.367 +	iLineArray.Copy(aGd->LineArray());
   1.368 +	}
   1.369 +
   1.370 +TInt CTestGraphicsContext::Construct()
   1.371 +	{
   1.372 +	return CWindowGc::Construct();
   1.373 +	}
   1.374 +
   1.375 +void CTestGraphicsContext::AddRectToDrawnArea(const TRect& aRect)
   1.376 +	{
   1.377 +	TRect drawnRect = aRect;
   1.378 +	drawnRect.Grow(iPenSize);
   1.379 +	iGd->AddRectToDrawnArea(drawnRect,
   1.380 +		iDrawMode == EDrawModeXOR || iDrawMode == EDrawModeNOTSCREEN);
   1.381 +	}
   1.382 +
   1.383 +void CTestGraphicsContext::AddPointToDrawnArea(const TPoint& aPoint)
   1.384 +	{
   1.385 +	AddRectToDrawnArea(TRect(aPoint, iPenSize));
   1.386 +	}
   1.387 +
   1.388 +CGraphicsDevice* CTestGraphicsContext::Device() const
   1.389 +	{
   1.390 +	return iGd;
   1.391 +	}
   1.392 +
   1.393 +void CTestGraphicsContext::SetOrigin(const TPoint& aPos)
   1.394 +	{
   1.395 +	iOrigin = aPos;
   1.396 +	}
   1.397 +
   1.398 +void CTestGraphicsContext::SetDrawMode(TDrawMode aDrawingMode)
   1.399 +	{
   1.400 +	iDrawMode = aDrawingMode;
   1.401 +	}
   1.402 +
   1.403 +void CTestGraphicsContext::SetClippingRect(const TRect& /*aRect*/)
   1.404 +	{
   1.405 +	}
   1.406 +
   1.407 +void CTestGraphicsContext::CancelClippingRect()
   1.408 +	{
   1.409 +	}
   1.410 +
   1.411 +TInt CTestGraphicsContext::SetClippingRegion(const TRegion& /*aRegion*/)
   1.412 +	{
   1.413 +	return KErrNone;
   1.414 +	}
   1.415 +
   1.416 +void CTestGraphicsContext::CancelClippingRegion()
   1.417 +	{
   1.418 +	}
   1.419 +
   1.420 +void CTestGraphicsContext::Reset()
   1.421 +	{
   1.422 +	iDrawMode = EDrawModePEN;
   1.423 +	iFont = 0;
   1.424 +	iPenSize.iWidth = 1;
   1.425 +	iPenSize.iHeight = 1;
   1.426 +	}
   1.427 +
   1.428 +void CTestGraphicsContext::UseFont(const CFont* aFont)
   1.429 +	{
   1.430 +	iFont = aFont;
   1.431 +	}
   1.432 +
   1.433 +void CTestGraphicsContext::DiscardFont()
   1.434 +	{
   1.435 +	iFont = 0;
   1.436 +	}
   1.437 +
   1.438 +void CTestGraphicsContext::SetUnderlineStyle(TFontUnderline /*UnderlineStyle*/)
   1.439 +	{
   1.440 +	}
   1.441 +
   1.442 +void CTestGraphicsContext::SetStrikethroughStyle(TFontStrikethrough /*aStrikethroughStyle*/)
   1.443 +	{
   1.444 +	}
   1.445 +
   1.446 +void CTestGraphicsContext::SetWordJustification(TInt /*aExcessWidth*/,TInt /*aNumGaps*/)
   1.447 +	{
   1.448 +	}
   1.449 +
   1.450 +void CTestGraphicsContext::SetCharJustification(TInt /*aExcessWidth*/,TInt /*aNumChars*/)
   1.451 +	{
   1.452 +	}
   1.453 +
   1.454 +void CTestGraphicsContext::SetPenColor(const TRgb& aColor)
   1.455 +	{
   1.456 +	CPalette* palette;
   1.457 +	iGd->GetPalette(palette);
   1.458 +	iPenColorIndex = palette->NearestIndex(aColor);
   1.459 +	}
   1.460 +
   1.461 +void CTestGraphicsContext::SetPenStyle(TPenStyle /*aPenStyle*/)
   1.462 +	{
   1.463 +	}
   1.464 +
   1.465 +void CTestGraphicsContext::SetPenSize(const TSize& aSize)
   1.466 +	{
   1.467 +	iPenSize = aSize;
   1.468 +	}
   1.469 +
   1.470 +void CTestGraphicsContext::SetBrushColor(const TRgb& /*aColor*/)
   1.471 +	{
   1.472 +	}
   1.473 +
   1.474 +void CTestGraphicsContext::SetBrushStyle(TBrushStyle /*aBrushStyle*/)
   1.475 +	{
   1.476 +	}
   1.477 +
   1.478 +void CTestGraphicsContext::SetBrushOrigin(const TPoint& /*aOrigin*/)
   1.479 +	{
   1.480 +	}
   1.481 +
   1.482 +void CTestGraphicsContext::UseBrushPattern(const CFbsBitmap* /*aBitmap*/)
   1.483 +	{
   1.484 +	}
   1.485 +
   1.486 +void CTestGraphicsContext::DiscardBrushPattern()
   1.487 +	{
   1.488 +	}
   1.489 +
   1.490 +void CTestGraphicsContext::MoveTo(const TPoint& aPoint)
   1.491 +	{
   1.492 +	iCurrentPos = iOrigin + aPoint;
   1.493 +	}
   1.494 +
   1.495 +void CTestGraphicsContext::MoveBy(const TPoint& aVector)
   1.496 +	{
   1.497 +	iCurrentPos += aVector;
   1.498 +	}
   1.499 +
   1.500 +void CTestGraphicsContext::Plot(const TPoint& aPoint)
   1.501 +	{
   1.502 +	iCurrentPos = iOrigin + aPoint;
   1.503 +	AddPointToDrawnArea(iCurrentPos);
   1.504 +	}
   1.505 +
   1.506 +void CTestGraphicsContext::DrawArc(const TRect& aRect,const TPoint& /*aStart*/,const TPoint& aEnd)
   1.507 +	{
   1.508 +	TRect r = aRect;
   1.509 +	r.Move(iOrigin);
   1.510 +	AddRectToDrawnArea(r);
   1.511 +	iCurrentPos = iOrigin + aEnd;
   1.512 +	}
   1.513 +
   1.514 +void CTestGraphicsContext::DrawLine(const TPoint& aPoint1,const TPoint& aPoint2)
   1.515 +	{
   1.516 +	AddPointToDrawnArea(iOrigin + aPoint1);
   1.517 +	iCurrentPos = iOrigin + aPoint2;
   1.518 +	AddPointToDrawnArea(iCurrentPos);
   1.519 +	}
   1.520 +
   1.521 +void CTestGraphicsContext::DrawLineTo(const TPoint& aPoint)
   1.522 +	{
   1.523 +	AddPointToDrawnArea(iCurrentPos);
   1.524 +	iCurrentPos = iOrigin + aPoint;
   1.525 +	AddPointToDrawnArea(iCurrentPos);
   1.526 +	}
   1.527 +
   1.528 +void CTestGraphicsContext::DrawLineBy(const TPoint& aVector)
   1.529 +	{
   1.530 +	AddPointToDrawnArea(iCurrentPos);
   1.531 +	iCurrentPos += aVector;
   1.532 +	AddPointToDrawnArea(iCurrentPos);
   1.533 +	}
   1.534 +
   1.535 +void CTestGraphicsContext::DrawPolyLine(const CArrayFix<TPoint>* aPointList)
   1.536 +	{
   1.537 +	TInt num = aPointList->Count();
   1.538 +	while (num--)
   1.539 +		{
   1.540 +		iCurrentPos = iOrigin + (*aPointList)[num - 1];
   1.541 +		AddPointToDrawnArea(iCurrentPos);
   1.542 +		}
   1.543 +	}
   1.544 +
   1.545 +void CTestGraphicsContext::DrawPolyLine(const TPoint* aPointList,TInt aNumPoints)
   1.546 +	{
   1.547 +	while (aNumPoints--)
   1.548 +		{
   1.549 +		iCurrentPos = iOrigin + aPointList[aNumPoints - 1];
   1.550 +		AddPointToDrawnArea(iCurrentPos);
   1.551 +		}
   1.552 +	}
   1.553 +
   1.554 +void CTestGraphicsContext::DrawPie(const TRect& aRect,
   1.555 +	const TPoint& /*aStart*/, const TPoint& aEnd)
   1.556 +	{
   1.557 +	TRect r = aRect;
   1.558 +	r.Move(iOrigin);
   1.559 +	AddRectToDrawnArea(r);
   1.560 +	iCurrentPos = iOrigin + aEnd;
   1.561 +	}
   1.562 +
   1.563 +void CTestGraphicsContext::DrawEllipse(const TRect& aRect)
   1.564 +	{
   1.565 +	TRect r = aRect;
   1.566 +	r.Move(iOrigin);
   1.567 +	AddRectToDrawnArea(r);
   1.568 +	}
   1.569 +
   1.570 +void CTestGraphicsContext::DrawRect(const TRect& aRect)
   1.571 +	{
   1.572 +	TRect r = aRect;
   1.573 +	r.Move(iOrigin);
   1.574 +	AddRectToDrawnArea(r);
   1.575 +	}
   1.576 +
   1.577 +void CTestGraphicsContext::DrawRoundRect(const TRect& aRect,const TSize& aCornerSize)
   1.578 +	{
   1.579 +	TRect r = aRect;
   1.580 +	r.Move(iOrigin);
   1.581 +	r.Grow(aCornerSize);
   1.582 +	AddRectToDrawnArea(r);
   1.583 +	}
   1.584 +
   1.585 +TInt CTestGraphicsContext::DrawPolygon(const CArrayFix<TPoint>* aPointList,TFillRule /*aFillRule*/)
   1.586 +	{
   1.587 +	TInt num = aPointList->Count();
   1.588 +	while (num--)
   1.589 +		{
   1.590 +		iCurrentPos = iOrigin + (*aPointList)[num - 1];
   1.591 +		AddPointToDrawnArea(iCurrentPos);
   1.592 +		}
   1.593 +	return KErrNone;
   1.594 +	}
   1.595 +
   1.596 +TInt CTestGraphicsContext::DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule /*aFillRule*/)
   1.597 +	{
   1.598 +	while (aNumPoints--)
   1.599 +		{
   1.600 +		iCurrentPos = iOrigin + aPointList[aNumPoints - 1];
   1.601 +		AddPointToDrawnArea(iCurrentPos);
   1.602 +		}
   1.603 +	return KErrNone;
   1.604 +	}
   1.605 +
   1.606 +void CTestGraphicsContext::DrawBitmap(const TPoint& /*aTopLeft*/,const CFbsBitmap* /*aSource*/)
   1.607 +	{
   1.608 +	}
   1.609 +
   1.610 +void CTestGraphicsContext::DrawBitmap(const TRect& /*aDestRect*/,const CFbsBitmap* /*aSource*/)
   1.611 +	{
   1.612 +	}
   1.613 +
   1.614 +void CTestGraphicsContext::DrawBitmap(const TRect& /*aDestRect*/,const CFbsBitmap* /*aSource*/,const TRect& /*aSourceRect*/)
   1.615 +	{
   1.616 +	}
   1.617 +
   1.618 +void CTestGraphicsContext::DrawText(const TDesC& aText, const TPoint& aPosition)
   1.619 +	{
   1.620 +#ifdef PRINT_DRAWTEXT_LINES
   1.621 +
   1.622 +	_LIT(KDrawTextTitle, "Text being drawn");
   1.623 +		PrintTestData(KDrawTextTitle, aText);
   1.624 +
   1.625 +#endif /* PRINT_DRAWTEXT_LINES */
   1.626 +	
   1.627 +	TTestGCDisplayLine thisLine;
   1.628 +	thisLine.Set(aPosition, aText);
   1.629 +	iLineArray.AddLineL(thisLine);
   1.630 +	}
   1.631 +
   1.632 +void CTestGraphicsContext::DrawText(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,
   1.633 +	TTextAlign /*aAlignment*/, TInt aLeftMargin)
   1.634 +	{
   1.635 +	TPoint pos(aBox.iBr.iX + aLeftMargin, aBox.iTl.iY + aBaselineOffset);
   1.636 +	pos += iOrigin;
   1.637 +	DrawText(aText, pos);
   1.638 +	}
   1.639 +	
   1.640 +void CTestGraphicsContext::DrawText(const TDesC& aText,TTextParameters* aParam, const TPoint& aPosition)
   1.641 +	{
   1.642 +#ifdef PRINT_DRAWTEXT_LINES
   1.643 +
   1.644 +	_LIT(KDrawTextTitle, "Text being drawn");
   1.645 +		PrintTestData(KDrawTextTitle, aText);
   1.646 +
   1.647 +#endif /* PRINT_DRAWTEXT_LINES */
   1.648 +
   1.649 +	//Avoid crash by ASSERT in BitGdi DrawText function
   1.650 +	__ASSERT_ALWAYS(aParam->iStart < aParam->iEnd,
   1.651 +		CTestGraphicsContext::Panic(CTestGraphicsContext::EErrorParameter));
   1.652 +	
   1.653 +	TTestGCDisplayLine thisLine;
   1.654 +	TPtrC actualText = aText.Mid(aParam->iStart,aParam->iEnd - aParam->iStart + 1);
   1.655 +	thisLine.Set(aPosition, actualText);
   1.656 +	iLineArray.AddLineL(thisLine);
   1.657 +	}
   1.658 +
   1.659 +void CTestGraphicsContext::DrawText(const TDesC& aText,TTextParameters* aParam,const TRect& aBox,TInt aBaselineOffset,
   1.660 +	TTextAlign /*aAlignment*/, TInt aLeftMargin)
   1.661 +	{
   1.662 +	TPoint pos(aBox.iBr.iX + aLeftMargin, aBox.iTl.iY + aBaselineOffset);
   1.663 +	pos += iOrigin;
   1.664 +	DrawText(aText,aParam, pos);
   1.665 +	}
   1.666 +
   1.667 +TInt CTestGraphicsContext::APIExtension(TUid aUid, TAny*& aOutput, TAny* aInput)
   1.668 +	{
   1.669 +	if (aUid == KDrawTextInContextUid)
   1.670 +		{
   1.671 +		TDrawTextInContextInternal* contextParam = (TDrawTextInContextInternal*)aInput;
   1.672 +		DrawText(contextParam->iText, &contextParam->iParam, contextParam->iPosition);
   1.673 +		return KErrNone;
   1.674 +		}
   1.675 +	else if (aUid == KDrawBoxTextInContextUid)
   1.676 +		{
   1.677 +		TDrawTextInContextInternal* contextParam = (TDrawTextInContextInternal*)aInput;
   1.678 +		DrawText(contextParam->iText,&contextParam->iParam,contextParam->iBox,contextParam->iBaselineOffset,contextParam->iAlign,contextParam->iMargin);
   1.679 +		return KErrNone;
   1.680 +		}
   1.681 +	// Future cases may be placed here later
   1.682 +	else
   1.683 +		return CWindowGc::APIExtension(aUid, aOutput, aInput);
   1.684 +	}
   1.685 +
   1.686 +
   1.687 +void CTestGraphicsContext::Clear()
   1.688 +	{
   1.689 +	}
   1.690 +
   1.691 +void CTestGraphicsContext::Clear(const TRect& /*aRect*/)
   1.692 +	{
   1.693 +	}
   1.694 +
   1.695 +void CTestGraphicsContext::CopyRect(const TPoint& /*aOffset*/, const TRect& /*aRect*/)
   1.696 +	{
   1.697 +	}
   1.698 +
   1.699 +void CTestGraphicsContext::BitBlt(const TPoint& /*aPoint*/, const CFbsBitmap* /*aBitmap*/)
   1.700 +	{
   1.701 +	}
   1.702 +
   1.703 +void CTestGraphicsContext::BitBlt(const TPoint& /*aPoint*/, const CFbsBitmap* /*aBitmap*/,
   1.704 +	const TRect& /*aRect*/)
   1.705 +	{
   1.706 +	}
   1.707 +
   1.708 +void CTestGraphicsContext::BitBltMasked(const TPoint& /*aPoint*/, const CFbsBitmap* /*aBitmap*/,
   1.709 +	const TRect& /*aSourceRect*/, const CFbsBitmap* /*aMaskBitmap*/, TBool /*aInvertMask*/)
   1.710 +	{
   1.711 +	}
   1.712 +
   1.713 +void CTestGraphicsContext::SetFaded(TBool)
   1.714 +	{
   1.715 +	}
   1.716 +
   1.717 +void CTestGraphicsContext::SetFadingParameters(TUint8,TUint8)
   1.718 +	{
   1.719 +	}
   1.720 +
   1.721 +//
   1.722 +//
   1.723 +// CTestFont
   1.724 +//
   1.725 +//
   1.726 +inline TBool IsSurrogate(TText a) { return 0xD800 == (a & 0xF800); }
   1.727 +inline TBool IsHighSurrogate(TText a) { return 0xD800 == (a & 0xFC00); }
   1.728 +inline TBool IsLowSurrogate(TText a) { return 0xDC00 == (a & 0xFC00); }
   1.729 +inline TChar PairSurrogates(TText aHigh, TText aLow)
   1.730 +	{
   1.731 +	return ((aHigh - 0xd7f7) << 10) + aLow;
   1.732 +	}
   1.733 +
   1.734 +TUid CTestFont::DoTypeUid() const
   1.735 +	{
   1.736 +	return TUid::Uid(12345);
   1.737 +	}
   1.738 +
   1.739 +TInt CTestFont::DoHeightInPixels() const
   1.740 +	{
   1.741 +	return 12;
   1.742 +	}
   1.743 +
   1.744 +TInt CTestFont::DoAscentInPixels() const
   1.745 +	{
   1.746 +	return 10;
   1.747 +	}
   1.748 +
   1.749 +struct TSpecialSizes
   1.750 +	{
   1.751 +	TInt iCharacter;
   1.752 +	TInt iWidth;
   1.753 +	};
   1.754 +
   1.755 +static const TSpecialSizes KSpecialSizes[] =
   1.756 +	{
   1.757 +	{ CTestFont::KThreePerEmSpace, 3 },
   1.758 +	{ CTestFont::KThinSpace, 2 },
   1.759 +	{ CTestFont::KHairSpace, 1 },
   1.760 +	{ CTestFont::KZeroWidthSpace, 0 },
   1.761 +	{ CTestFont::KZeroWidthNoBreakSpace, 0 },
   1.762 +	};
   1.763 +
   1.764 +TInt CTestFont::DoCharWidthInPixels(TChar aChar) const
   1.765 +	{
   1.766 +	TInt cn = aChar;
   1.767 +	// non-characters 0x??FFFE and 0x??FFFF
   1.768 +	if ((cn & 0xFFFE) == 0xFFFE)
   1.769 +		return 0;
   1.770 +
   1.771 +	// Find character in the special sizes table
   1.772 +	TInt first = 0;
   1.773 +	TInt last = sizeof(KSpecialSizes)/sizeof(KSpecialSizes[0]);
   1.774 +	while (first != last)
   1.775 +		{
   1.776 +		TInt c = static_cast<TInt>(aChar);
   1.777 +		TInt mid = (first + last) >> 1;
   1.778 +		if (c < KSpecialSizes[mid].iCharacter)
   1.779 +			last = mid;
   1.780 +		else if (KSpecialSizes[mid].iCharacter < c)
   1.781 +			first = mid + 1;
   1.782 +		else
   1.783 +			return KSpecialSizes[mid].iWidth;
   1.784 +		}
   1.785 +
   1.786 +	return 10;
   1.787 +	}
   1.788 +
   1.789 +TInt CTestFont::DoTextCount(const TDesC& aText, TInt aWidthInPixels,
   1.790 +	TInt& aExcessWidthInPixels) const
   1.791 +	{
   1.792 +	const TText* p = &aText[0];
   1.793 +	const TText* pEnd = p + aText.Length();
   1.794 +	TInt total = 0;
   1.795 +	TInt prevSurrogate = 0;
   1.796 +	TInt charactersThatFit = 0;
   1.797 +	while (p != pEnd)
   1.798 +		{
   1.799 +		TChar c = *p;
   1.800 +		if (IsSurrogate(*p))
   1.801 +			{
   1.802 +			c = 0xFFFF;
   1.803 +			if (IsHighSurrogate(*p))
   1.804 +				prevSurrogate = *p;
   1.805 +			else if (prevSurrogate != 0)
   1.806 +				{
   1.807 +				c = PairSurrogates(static_cast<TText>(prevSurrogate), *p);
   1.808 +				prevSurrogate = 0;
   1.809 +				}
   1.810 +			}
   1.811 +		else
   1.812 +			prevSurrogate = 0;
   1.813 +		total += CharWidthInPixels(c);
   1.814 +		if (total <= aWidthInPixels)
   1.815 +			++charactersThatFit;
   1.816 +		++p;
   1.817 +		}
   1.818 +	aExcessWidthInPixels = total - aWidthInPixels;
   1.819 +	return charactersThatFit;
   1.820 +	}
   1.821 +
   1.822 +TInt CTestFont::DoTextWidthInPixels(const TDesC& aText) const
   1.823 +	{
   1.824 +	TInt excess;
   1.825 +	TextCount(aText, 0, excess);
   1.826 +	return excess;
   1.827 +	}
   1.828 +
   1.829 +TInt CTestFont::DoBaselineOffsetInPixels() const
   1.830 +	{
   1.831 +	return 10;
   1.832 +	}
   1.833 +
   1.834 +TInt CTestFont::DoTextCount(const TDesC& aText,TInt aWidthInPixels) const
   1.835 +	{
   1.836 +	TInt excess;
   1.837 +	return TextCount(aText, aWidthInPixels, excess);
   1.838 +	}
   1.839 +
   1.840 +TInt CTestFont::DoMaxCharWidthInPixels() const
   1.841 +	{
   1.842 +	return 10;
   1.843 +	}
   1.844 +
   1.845 +TInt CTestFont::DoMaxNormalCharWidthInPixels() const
   1.846 +	{
   1.847 +	return 10;
   1.848 +	}
   1.849 +
   1.850 +TFontSpec CTestFont::DoFontSpecInTwips() const
   1.851 +	{
   1.852 +	return TFontSpec(KTestFontName, 12);
   1.853 +	}
   1.854 + 
   1.855 +CFont::TCharacterDataAvailability 
   1.856 +CTestFont::DoGetCharacterData(TUint aCode, TOpenFontCharMetrics& aMetrics,
   1.857 +	const TUint8*& aBitmap, TSize& aBitmapSize) const
   1.858 +	{
   1.859 +	TInt width;
   1.860 +	switch (aCode)
   1.861 +		{
   1.862 +	case 0x001B:
   1.863 +		// ESC character should cause this fault; no character data available.
   1.864 +		return CFont::ENoCharacterData;
   1.865 +	case 'W':
   1.866 +		// We want 'W' to have side-bearings
   1.867 +		CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
   1.868 +		width = aMetrics.Width();
   1.869 +		aMetrics.SetHorizBearingX(-1);
   1.870 +		aMetrics.SetWidth(width + 2);
   1.871 +		return CFont::ECharacterWidthOnly ;
   1.872 +	case '/':
   1.873 +		// We want / to have a left side-bearing
   1.874 +		CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
   1.875 +		width = aMetrics.Width();
   1.876 +		aMetrics.SetHorizBearingX(-1);
   1.877 +		aMetrics.SetWidth(width + 1);
   1.878 +		return CFont::ECharacterWidthOnly ;
   1.879 +	case 'D':
   1.880 +		// We want 'D' to have a left side-bearing only
   1.881 +		CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
   1.882 +		aMetrics.SetHorizBearingX(-1);
   1.883 +		return CFont::ECharacterWidthOnly ;
   1.884 +	case KTav:
   1.885 +		// We want Hebrew Tav to have a +ve left side-bearing
   1.886 +		CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
   1.887 +		aMetrics.SetHorizBearingX(1);
   1.888 +		return CFont::ECharacterWidthOnly ;
   1.889 +	case KFullWidthSolidus:
   1.890 +		// We want fw/ to have a right side-bearing
   1.891 +		CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
   1.892 +		width = aMetrics.Width();
   1.893 +		aMetrics.SetWidth(width + 1);
   1.894 +		return CFont::ECharacterWidthOnly ;
   1.895 +	case KArabicWaw:
   1.896 +		// Arabic Waw-- has massive left side-bearing
   1.897 +		CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
   1.898 +		width = aMetrics.Width();
   1.899 +		aMetrics.SetHorizBearingX(-5);
   1.900 +		aMetrics.SetWidth(width + 5);
   1.901 +		return CFont::ECharacterWidthOnly ;
   1.902 +	default:
   1.903 +		return CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
   1.904 +		}
   1.905 +	}
   1.906 +