1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/gdi/tgdi/TGraphicsContext.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,716 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent Internal Symbian test code
1.23 +*/
1.24 +
1.25 +#include "TTYPES.H"
1.26 +#include "TGraphicsContext.h"
1.27 +
1.28 +
1.29 +
1.30 +// Utility functions to show contents of test data using test.Printf
1.31 +
1.32 +extern void PrintTestData (const TDesC& aTitle , const TDesC16& aDataBuffer);
1.33 +
1.34 +extern void PrintTestData(const TDesC& aTitle, const TText16* aDataBuffer, const TInt aSize);
1.35 +
1.36 +
1.37 +
1.38 +
1.39 +_LIT(KTestFontName, "Non Functional Test Font");
1.40 +
1.41 +
1.42 +CTestPalette2::~CTestPalette2()
1.43 + {
1.44 + iArray = 0; //avoid attempting to deallocate iArray in ~CPalette
1.45 + iNumEntries = 0;
1.46 + }
1.47 +
1.48 +//
1.49 +//
1.50 +// CTestGraphicsDevice
1.51 +//
1.52 +//
1.53 +CTestGraphicsDevice* CTestGraphicsDevice::NewL(TSize aSizeInPixels)
1.54 + {
1.55 + CTestGraphicsDevice* theDevice = new (ELeave) CTestGraphicsDevice(aSizeInPixels);
1.56 + CleanupStack::PushL(theDevice);
1.57 + theDevice->iPalette = new (ELeave) CTestPalette2;
1.58 + theDevice->iPalette->SetEntry(0, KRgbBlack);
1.59 + theDevice->iPalette->SetEntry(1, KRgbWhite);
1.60 + theDevice->iPalette->SetEntry(2, KRgbMagenta);
1.61 + theDevice->iPalette->SetEntry(3, KRgbCyan);
1.62 +
1.63 + CleanupStack::Pop(theDevice);
1.64 + return theDevice;
1.65 + }
1.66 +
1.67 +CTestGraphicsDevice::CTestGraphicsDevice(TSize aSizeInPixels)
1.68 + : iSize(aSizeInPixels),
1.69 + iHorizontalTwipsToPixels(40),
1.70 + iVerticalTwipsToPixels(40)
1.71 + {
1.72 + }
1.73 +CTestGraphicsDevice::~CTestGraphicsDevice()
1.74 + {
1.75 + delete iPalette;
1.76 + }
1.77 +
1.78 +void CTestGraphicsDevice::SetHorizontalTwipsToPixels(TInt aTwipsToPixels)
1.79 + {
1.80 + iHorizontalTwipsToPixels = aTwipsToPixels;
1.81 + }
1.82 +
1.83 +void CTestGraphicsDevice::SetVerticalTwipsToPixels(TInt aTwipsToPixels)
1.84 + {
1.85 + iVerticalTwipsToPixels = aTwipsToPixels;
1.86 + }
1.87 +
1.88 +TDisplayMode CTestGraphicsDevice::DisplayMode() const
1.89 + {
1.90 + return EColor16M;
1.91 + }
1.92 +
1.93 +TSize CTestGraphicsDevice::SizeInPixels() const
1.94 + {
1.95 + return iSize;
1.96 + }
1.97 +
1.98 +TSize CTestGraphicsDevice::SizeInTwips() const
1.99 + {
1.100 + return TSize(iSize.iWidth * iHorizontalTwipsToPixels,
1.101 + iSize.iHeight * iVerticalTwipsToPixels);
1.102 + }
1.103 +
1.104 +TInt CTestGraphicsDevice::CreateContext(CGraphicsContext*& aGC)
1.105 + {
1.106 + CGraphicsContext* r = new CTestGraphicsContext(this);
1.107 + if (!r)
1.108 + return KErrNoMemory;
1.109 + aGC = r;
1.110 + return KErrNone;
1.111 + }
1.112 +
1.113 +TInt CTestGraphicsDevice::NumTypefaces() const
1.114 + {
1.115 + return 1;
1.116 + }
1.117 +
1.118 +void CTestGraphicsDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport, TInt aTypefaceIndex) const
1.119 + {
1.120 + // The only font we have at the moment is 10 pixels * 12 pixels for every character
1.121 + __ASSERT_ALWAYS(aTypefaceIndex == 0,
1.122 + CTestGraphicsContext::Panic(CTestGraphicsContext::ETypefaceIndexOutOfRange));
1.123 + aTypefaceSupport.iIsScalable = EFalse;
1.124 + aTypefaceSupport.iMaxHeightInTwips = iVerticalTwipsToPixels * 12;
1.125 + aTypefaceSupport.iMinHeightInTwips = iVerticalTwipsToPixels * 10;
1.126 + aTypefaceSupport.iNumHeights = 1;
1.127 + aTypefaceSupport.iTypeface.iName = KTestFontName;
1.128 + aTypefaceSupport.iTypeface.SetIsProportional(ETrue); // a bit of a lie
1.129 + aTypefaceSupport.iTypeface.SetIsSerif(EFalse);
1.130 + aTypefaceSupport.iTypeface.SetIsSymbol(EFalse);
1.131 + }
1.132 +
1.133 +TInt CTestGraphicsDevice::FontHeightInTwips(TInt aTypefaceIndex, TInt aHeightIndex) const
1.134 + {
1.135 + // The only font we have at the moment is 10 pixels * 12 pixels for every character
1.136 + __ASSERT_ALWAYS(aTypefaceIndex == 0,
1.137 + CTestGraphicsContext::Panic(CTestGraphicsContext::ETypefaceIndexOutOfRange));
1.138 + return iVerticalTwipsToPixels * FontHeightInPixels(aTypefaceIndex, aHeightIndex);
1.139 + }
1.140 +
1.141 +void CTestGraphicsDevice::PaletteAttributes(TBool& aModifiable, TInt& aNumEntries) const
1.142 + {
1.143 + aModifiable = ETrue;
1.144 + aNumEntries = 4;
1.145 + }
1.146 +
1.147 +void CTestGraphicsDevice::SetPalette(CPalette* aPalette)
1.148 + {
1.149 + for (TInt i = 0; i != CTestPalette2::KNumEntries; ++i)
1.150 + {
1.151 + TRgb col = aPalette->GetEntry(i);
1.152 + iPalette -> SetEntry(i, col);
1.153 + }
1.154 + }
1.155 +
1.156 +TInt CTestGraphicsDevice::GetPalette(CPalette*& aPalette) const
1.157 + {
1.158 + aPalette = const_cast<CTestPalette2*>(iPalette);
1.159 + return KErrNone;
1.160 + }
1.161 +
1.162 +void CTestGraphicsDevice::GetPixel(TRgb& aColor, const TPoint&) const
1.163 + {
1.164 + aColor = KRgbWhite;
1.165 + }
1.166 +
1.167 +void CTestGraphicsDevice::GetScanLine(TDes8&, const TPoint&, TInt, TDisplayMode) const
1.168 + {
1.169 + __ASSERT_DEBUG(0, CTestGraphicsContext::Panic(CTestGraphicsContext::EUnimplemented));
1.170 + }
1.171 +
1.172 +TInt CTestGraphicsDevice::AddFile(const TDesC&, TInt&)
1.173 + {
1.174 + return KErrNotSupported;
1.175 + }
1.176 +
1.177 +void CTestGraphicsDevice::RemoveFile(TInt)
1.178 + {
1.179 + }
1.180 +
1.181 +TInt CTestGraphicsDevice::GetNearestFontInPixels(CFont*& aFont, const TFontSpec& aFontSpec)
1.182 + {
1.183 + return GetNearestFontToDesignHeightInPixels(aFont, aFontSpec);
1.184 + }
1.185 +
1.186 +TInt CTestGraphicsDevice::GetNearestFontToDesignHeightInPixels(CFont*& aFont, const TFontSpec& /*aFontSpec*/)
1.187 + {
1.188 + CTestFont* font = new CTestFont();
1.189 + if (!font)
1.190 + return KErrNoMemory;
1.191 + aFont = font;
1.192 + return KErrNone;
1.193 + }
1.194 +
1.195 +TInt CTestGraphicsDevice::GetNearestFontToMaxHeightInPixels(CFont*& aFont, const TFontSpec& /*aFontSpec*/, TInt /*aMaxHeight*/)
1.196 + {
1.197 + CTestFont* font = new CTestFont();
1.198 + if (!font)
1.199 + return KErrNoMemory;
1.200 + aFont = font;
1.201 + return KErrNone;
1.202 + }
1.203 +
1.204 +TInt CTestGraphicsDevice::FontHeightInPixels(TInt, TInt) const
1.205 + {
1.206 + return 12;
1.207 + }
1.208 +
1.209 +TInt CTestGraphicsDevice::HorizontalTwipsToPixels(TInt aTwips) const
1.210 + {
1.211 + return aTwips / iHorizontalTwipsToPixels;
1.212 + }
1.213 +
1.214 +TInt CTestGraphicsDevice::VerticalTwipsToPixels(TInt aTwips) const
1.215 + {
1.216 + return aTwips / iVerticalTwipsToPixels;
1.217 + }
1.218 +
1.219 +TInt CTestGraphicsDevice::HorizontalPixelsToTwips(TInt aPixels) const
1.220 + {
1.221 + return aPixels * iHorizontalTwipsToPixels;
1.222 + }
1.223 +
1.224 +TInt CTestGraphicsDevice::VerticalPixelsToTwips(TInt aPixels) const
1.225 + {
1.226 + return aPixels * iVerticalTwipsToPixels;
1.227 + }
1.228 +
1.229 +TInt CTestGraphicsDevice::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
1.230 + {
1.231 + return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
1.232 + }
1.233 +
1.234 +TInt CTestGraphicsDevice::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
1.235 + {
1.236 + TFontSpec fontSpec = aFontSpec;
1.237 + fontSpec.iHeight = VerticalTwipsToPixels(fontSpec.iHeight);
1.238 + return GetNearestFontToDesignHeightInPixels(aFont, fontSpec);
1.239 + }
1.240 +
1.241 +TInt CTestGraphicsDevice::GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight)
1.242 + {
1.243 + TFontSpec fontSpec = aFontSpec;
1.244 + fontSpec.iHeight = VerticalTwipsToPixels(fontSpec.iHeight);
1.245 + return GetNearestFontToMaxHeightInPixels(aFont, fontSpec, VerticalTwipsToPixels(aMaxHeight));
1.246 + }
1.247 +
1.248 +void CTestGraphicsDevice::ReleaseFont(CFont* aFont)
1.249 + {
1.250 + __ASSERT_ALWAYS(aFont->TypeUid() == TUid::Uid(12345),
1.251 + CTestGraphicsContext::Panic(CTestGraphicsContext::EUnknownFont));
1.252 + delete static_cast<CTestFont*>(aFont);
1.253 + }
1.254 +
1.255 +//
1.256 +//
1.257 +// CTestGraphicsContext
1.258 +//
1.259 +//
1.260 +void CTestGraphicsContext::Panic(TInt aReason)
1.261 + {
1.262 + User::Panic(_L("CTestGC"), aReason);
1.263 + }
1.264 +
1.265 +CTestGraphicsContext::CTestGraphicsContext(CTestGraphicsDevice* aGd)
1.266 + : iGd(aGd), iDrawMode(EDrawModePEN), iPenSize(1,1)
1.267 + {
1.268 + }
1.269 +
1.270 +CTestGraphicsContext::~CTestGraphicsContext()
1.271 + {
1.272 + iLineArray.Reset();
1.273 + }
1.274 +void CTestGraphicsContext::AddRectToDrawnArea(const TRect& aRect)
1.275 + {
1.276 + if (iDrawnArea.IsEmpty())
1.277 + iDrawnArea = aRect;
1.278 + else
1.279 + iDrawnArea.BoundingRect(aRect);
1.280 + // only one condition at the moment
1.281 + if (iDrawMode == EDrawModeXOR)
1.282 + {
1.283 + if (iAreaDrawnWithCondition.IsEmpty())
1.284 + iAreaDrawnWithCondition = aRect;
1.285 + else
1.286 + iAreaDrawnWithCondition.BoundingRect(aRect);
1.287 + }
1.288 + }
1.289 +
1.290 +void CTestGraphicsContext::AddPointToDrawnArea(const TPoint& aPoint)
1.291 + {
1.292 + AddRectToDrawnArea(TRect(aPoint, iPenSize));
1.293 + }
1.294 +
1.295 +CGraphicsDevice* CTestGraphicsContext::Device() const
1.296 + {
1.297 + return iGd;
1.298 + }
1.299 +
1.300 +void CTestGraphicsContext::SetOrigin(const TPoint& aPos)
1.301 + {
1.302 + iOrigin = aPos;
1.303 + }
1.304 +
1.305 +void CTestGraphicsContext::SetDrawMode(TDrawMode aDrawingMode)
1.306 + {
1.307 + iDrawMode = aDrawingMode;
1.308 + }
1.309 +
1.310 +void CTestGraphicsContext::SetClippingRect(const TRect& /*aRect*/)
1.311 + {
1.312 + }
1.313 +
1.314 +void CTestGraphicsContext::CancelClippingRect()
1.315 + {
1.316 + }
1.317 +
1.318 +void CTestGraphicsContext::Reset()
1.319 + {
1.320 + iDrawMode = EDrawModePEN;
1.321 + iFont = 0;
1.322 + iPenSize.iWidth = 1;
1.323 + iPenSize.iHeight = 1;
1.324 + }
1.325 +
1.326 +void CTestGraphicsContext::UseFont(const CFont* aFont)
1.327 + {
1.328 + iFont = aFont;
1.329 + }
1.330 +
1.331 +void CTestGraphicsContext::DiscardFont()
1.332 + {
1.333 + iFont = 0;
1.334 + }
1.335 +
1.336 +void CTestGraphicsContext::SetUnderlineStyle(TFontUnderline /*UnderlineStyle*/)
1.337 + {
1.338 + }
1.339 +
1.340 +void CTestGraphicsContext::SetStrikethroughStyle(TFontStrikethrough /*aStrikethroughStyle*/)
1.341 + {
1.342 + }
1.343 +
1.344 +void CTestGraphicsContext::SetWordJustification(TInt /*aExcessWidth*/,TInt /*aNumGaps*/)
1.345 + {
1.346 + }
1.347 +
1.348 +void CTestGraphicsContext::SetCharJustification(TInt /*aExcessWidth*/,TInt /*aNumChars*/)
1.349 + {
1.350 + }
1.351 +
1.352 +void CTestGraphicsContext::SetPenColor(const TRgb& aColor)
1.353 + {
1.354 + CPalette* palette;
1.355 + iGd->GetPalette(palette);
1.356 + iPenColorIndex = palette->NearestIndex(aColor);
1.357 + }
1.358 +
1.359 +void CTestGraphicsContext::SetPenStyle(TPenStyle /*aPenStyle*/)
1.360 + {
1.361 + }
1.362 +
1.363 +void CTestGraphicsContext::SetPenSize(const TSize& aSize)
1.364 + {
1.365 + iPenSize = aSize;
1.366 + }
1.367 +
1.368 +void CTestGraphicsContext::SetBrushColor(const TRgb& /*aColor*/)
1.369 + {
1.370 + }
1.371 +
1.372 +void CTestGraphicsContext::SetBrushStyle(TBrushStyle /*aBrushStyle*/)
1.373 + {
1.374 + }
1.375 +
1.376 +void CTestGraphicsContext::SetBrushOrigin(const TPoint& /*aOrigin*/)
1.377 + {
1.378 + }
1.379 +
1.380 +void CTestGraphicsContext::UseBrushPattern(const CFbsBitmap* /*aBitmap*/)
1.381 + {
1.382 + }
1.383 +
1.384 +void CTestGraphicsContext::DiscardBrushPattern()
1.385 + {
1.386 + }
1.387 +
1.388 +void CTestGraphicsContext::MoveTo(const TPoint& aPoint)
1.389 + {
1.390 + iCurrentPos = iOrigin + aPoint;
1.391 + }
1.392 +
1.393 +void CTestGraphicsContext::MoveBy(const TPoint& aVector)
1.394 + {
1.395 + iCurrentPos += aVector;
1.396 + }
1.397 +
1.398 +void CTestGraphicsContext::Plot(const TPoint& aPoint)
1.399 + {
1.400 + iCurrentPos = iOrigin + aPoint;
1.401 + AddPointToDrawnArea(iCurrentPos);
1.402 + }
1.403 +
1.404 +void CTestGraphicsContext::DrawArc(const TRect& aRect,const TPoint& /*aStart*/,const TPoint& aEnd)
1.405 + {
1.406 + TRect r = aRect;
1.407 + r.Move(iOrigin);
1.408 + AddRectToDrawnArea(r);
1.409 + iCurrentPos = iOrigin + aEnd;
1.410 + }
1.411 +
1.412 +void CTestGraphicsContext::DrawLine(const TPoint& aPoint1,const TPoint& aPoint2)
1.413 + {
1.414 + AddPointToDrawnArea(iOrigin + aPoint1);
1.415 + iCurrentPos = iOrigin + aPoint2;
1.416 + AddPointToDrawnArea(iCurrentPos);
1.417 + }
1.418 +
1.419 +void CTestGraphicsContext::DrawLineTo(const TPoint& aPoint)
1.420 + {
1.421 + AddPointToDrawnArea(iCurrentPos);
1.422 + iCurrentPos = iOrigin + aPoint;
1.423 + AddPointToDrawnArea(iCurrentPos);
1.424 + }
1.425 +
1.426 +void CTestGraphicsContext::DrawLineBy(const TPoint& aVector)
1.427 + {
1.428 + AddPointToDrawnArea(iCurrentPos);
1.429 + iCurrentPos += aVector;
1.430 + AddPointToDrawnArea(iCurrentPos);
1.431 + }
1.432 +
1.433 +void CTestGraphicsContext::DrawPolyLine(const CArrayFix<TPoint>* aPointList)
1.434 + {
1.435 + TInt num = aPointList->Count();
1.436 + while (num--)
1.437 + {
1.438 + iCurrentPos = iOrigin + (*aPointList)[num - 1];
1.439 + AddPointToDrawnArea(iCurrentPos);
1.440 + }
1.441 + }
1.442 +
1.443 +void CTestGraphicsContext::DrawPolyLine(const TPoint* aPointList,TInt aNumPoints)
1.444 + {
1.445 + while (aNumPoints--)
1.446 + {
1.447 + iCurrentPos = iOrigin + aPointList[aNumPoints - 1];
1.448 + AddPointToDrawnArea(iCurrentPos);
1.449 + }
1.450 + }
1.451 +
1.452 +void CTestGraphicsContext::DrawPie(const TRect& aRect,
1.453 + const TPoint& /*aStart*/, const TPoint& aEnd)
1.454 + {
1.455 + TRect r = aRect;
1.456 + r.Move(iOrigin);
1.457 + AddRectToDrawnArea(r);
1.458 + iCurrentPos = iOrigin + aEnd;
1.459 + }
1.460 +
1.461 +void CTestGraphicsContext::DrawEllipse(const TRect& aRect)
1.462 + {
1.463 + TRect r = aRect;
1.464 + r.Move(iOrigin);
1.465 + AddRectToDrawnArea(r);
1.466 + }
1.467 +
1.468 +void CTestGraphicsContext::DrawRect(const TRect& aRect)
1.469 + {
1.470 + TRect r = aRect;
1.471 + r.Move(iOrigin);
1.472 + AddRectToDrawnArea(r);
1.473 + }
1.474 +
1.475 +void CTestGraphicsContext::DrawRoundRect(const TRect& aRect,const TSize& aCornerSize)
1.476 + {
1.477 + TRect r = aRect;
1.478 + r.Move(iOrigin);
1.479 + r.Grow(aCornerSize);
1.480 + AddRectToDrawnArea(r);
1.481 + }
1.482 +
1.483 +TInt CTestGraphicsContext::DrawPolygon(const CArrayFix<TPoint>* aPointList,TFillRule /*aFillRule*/)
1.484 + {
1.485 + TInt num = aPointList->Count();
1.486 + while (num--)
1.487 + {
1.488 + iCurrentPos = iOrigin + (*aPointList)[num - 1];
1.489 + AddPointToDrawnArea(iCurrentPos);
1.490 + }
1.491 + return KErrNone;
1.492 + }
1.493 +
1.494 +TInt CTestGraphicsContext::DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule /*aFillRule*/)
1.495 + {
1.496 + while (aNumPoints--)
1.497 + {
1.498 + iCurrentPos = iOrigin + aPointList[aNumPoints - 1];
1.499 + AddPointToDrawnArea(iCurrentPos);
1.500 + }
1.501 + return KErrNone;
1.502 + }
1.503 +
1.504 +void CTestGraphicsContext::DrawBitmap(const TPoint& /*aTopLeft*/,const CFbsBitmap* /*aSource*/)
1.505 + {
1.506 + }
1.507 +
1.508 +void CTestGraphicsContext::DrawBitmap(const TRect& /*aDestRect*/,const CFbsBitmap* /*aSource*/)
1.509 + {
1.510 + }
1.511 +
1.512 +void CTestGraphicsContext::DrawBitmap(const TRect& /*aDestRect*/,const CFbsBitmap* /*aSource*/,const TRect& /*aSourceRect*/)
1.513 + {
1.514 + }
1.515 +
1.516 +void CTestGraphicsContext::DrawBitmapMasked(const TRect& /*aDestRect*/,const CFbsBitmap* /*aBitmap*/,const TRect& /*aSourceRect*/,const CFbsBitmap* /*aMaskBitmap*/,TBool /*aInvertMask*/)
1.517 + {}
1.518 +
1.519 +void CTestGraphicsContext::DrawBitmapMasked(const TRect& /*aDestRect*/,const CWsBitmap* /*aBitmap*/,const TRect& /*aSourceRect*/,const CWsBitmap* /*aMaskBitmap*/,TBool /*aInvertMask*/)
1.520 + {
1.521 + }
1.522 +
1.523 +void CTestGraphicsContext::MapColors(const TRect &/*aRect*/,const TRgb */*aColors*/,TInt /*aNumPairs*/,TBool /*aMapForwards*/)
1.524 + {}
1.525 +
1.526 +TInt CTestGraphicsContext::SetClippingRegion(const TRegion &/*aRegion*/)
1.527 + {
1.528 + return KErrNone;
1.529 + }
1.530 +
1.531 +void CTestGraphicsContext::CancelClippingRegion()
1.532 + {}
1.533 +
1.534 +void CTestGraphicsContext::DrawTextVertical(const TDesC& /*aText*/,const TPoint& /*aPos*/,TBool /*aUp*/)
1.535 + {}
1.536 +
1.537 +void CTestGraphicsContext::DrawTextVertical(const TDesC& /*aText*/,const TRect& /*aBox*/,TInt /*aBaselineOffset*/,TBool /*aUp*/,TTextAlign /*aVert*/,TInt /*aMargin*/)
1.538 + {}
1.539 +
1.540 +/**
1.541 + *
1.542 + * DrawText - merely add line "drawn" to collection
1.543 + *
1.544 + */
1.545 +
1.546 +
1.547 +void CTestGraphicsContext::DrawText(const TDesC& aText,const TPoint& aPosition)
1.548 + {
1.549 +
1.550 +#ifdef PRINT_DRAWTEXT_LINES
1.551 +
1.552 + _LIT(KDrawTextFormat, "DrawText called for position %d,%d:");
1.553 + _LIT(KDrawTextTitle, "Text being drawn");
1.554 + test.Printf(KDrawTextFormat, aPosition.iX, aPosition.iY);
1.555 + PrintTestData(KDrawTextTitle, aText);
1.556 +
1.557 +#endif /* PRINT_DRAWTEXT_LINES */
1.558 +
1.559 + TTestGCDisplayLine thisLine;
1.560 + thisLine.Set(aPosition, aText);
1.561 + iLineArray.Append(thisLine);
1.562 +
1.563 + }
1.564 +
1.565 +void CTestGraphicsContext::DrawText(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset,
1.566 + TTextAlign /*aAlignment*/, TInt aLeftMargin)
1.567 + {
1.568 + TPoint pos(aBox.iBr.iX + aLeftMargin, aBox.iTl.iY + aBaselineOffset);
1.569 + pos += iOrigin;
1.570 + DrawText(aText, pos);
1.571 + }
1.572 +
1.573 +void CTestGraphicsContext::DrawText(const TDesC& aText, const TPoint& aPosition,
1.574 + const TDrawTextParam&)
1.575 + {
1.576 + DrawText(aText, aPosition);
1.577 + }
1.578 +
1.579 +//
1.580 +//
1.581 +// CTestFont
1.582 +//
1.583 +//
1.584 +TUid CTestFont::DoTypeUid() const
1.585 + {
1.586 + return TUid::Uid(12345);
1.587 + }
1.588 +
1.589 +TInt CTestFont::DoHeightInPixels() const
1.590 + {
1.591 + return 12;
1.592 + }
1.593 +
1.594 +TInt CTestFont::DoAscentInPixels() const
1.595 + {
1.596 + return 10;
1.597 + }
1.598 +
1.599 +TInt CTestFont::DoCharWidthInPixels(TChar aChar) const
1.600 + {
1.601 + switch (aChar)
1.602 + {
1.603 + case 0x200C:
1.604 + case 0x200D:
1.605 + case 0x200E:
1.606 + case 0x200F:
1.607 + case 0x202A:
1.608 + case 0x202B:
1.609 + case 0x202C:
1.610 + case 0x202D:
1.611 + case 0x202E:
1.612 + case 0xFFFF:
1.613 + return 0;
1.614 + default:
1.615 + return 10;
1.616 + }
1.617 + }
1.618 +
1.619 +TInt CTestFont::DoTextWidthInPixels(const TDesC& aText) const
1.620 + {
1.621 + TInt total = 0;
1.622 + const TText* p = aText.Ptr();
1.623 + const TText* end = p + aText.Length();
1.624 + for (;p != end; ++p)
1.625 + total += CharWidthInPixels(*p);
1.626 + return total;
1.627 + }
1.628 +
1.629 +TInt CTestFont::DoBaselineOffsetInPixels() const
1.630 + {
1.631 + return 10;
1.632 + }
1.633 +
1.634 +TInt CTestFont::DoTextCount(const TDesC& aText,TInt aWidthInPixels) const
1.635 + {
1.636 + TInt excess;
1.637 + return DoTextCount(aText, aWidthInPixels, excess);
1.638 + }
1.639 +
1.640 +TInt CTestFont::DoTextCount(const TDesC& aText,TInt aWidthInPixels,TInt& aExcessWidthInPixels) const
1.641 + {
1.642 + aExcessWidthInPixels = aWidthInPixels;
1.643 + const TText* start = aText.Ptr();
1.644 + const TText* end = start + aText.Length();
1.645 + const TText* p = start;
1.646 + TInt width;
1.647 + while (p != end
1.648 + && (width = CharWidthInPixels(*p)) <= aExcessWidthInPixels)
1.649 + {
1.650 + aExcessWidthInPixels -= width;
1.651 + ++p;
1.652 + }
1.653 + return p - start;
1.654 + }
1.655 +
1.656 +TInt CTestFont::DoMaxCharWidthInPixels() const
1.657 + {
1.658 + return 10;
1.659 + }
1.660 +
1.661 +TInt CTestFont::DoMaxNormalCharWidthInPixels() const
1.662 + {
1.663 + return 10;
1.664 + }
1.665 +
1.666 +TFontSpec CTestFont::DoFontSpecInTwips() const
1.667 + {
1.668 + return TFontSpec(KTestFontName, 12);
1.669 + }
1.670 +
1.671 +CFont::TCharacterDataAvailability
1.672 + CTestFont::DoGetCharacterData(TUint aCode, TOpenFontCharMetrics& aMetrics,
1.673 + const TUint8*& aBitmap, TSize& aBitmapSize) const
1.674 + {
1.675 + TInt width;
1.676 + switch (aCode)
1.677 + {
1.678 + case 0x001B:
1.679 + // ESC character should cause this fault; no character data available.
1.680 + return CFont::ENoCharacterData;
1.681 + case 'W':
1.682 + // We want 'W' to have side-bearings
1.683 + CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
1.684 + width = aMetrics.Width();
1.685 + aMetrics.SetHorizBearingX(-1);
1.686 + aMetrics.SetWidth(width + 2);
1.687 + return CFont::ECharacterWidthOnly ;
1.688 + case 0x0648:
1.689 + // Arabic Waw-- has massive left side-bearing
1.690 + CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
1.691 + width = aMetrics.Width();
1.692 + aMetrics.SetHorizBearingX(-5);
1.693 + aMetrics.SetWidth(width + 5);
1.694 + return CFont::ECharacterWidthOnly ;
1.695 + case 'X':
1.696 + // We want 'X' to have a left side-bearing only
1.697 + CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
1.698 + aMetrics.SetHorizBearingX(-1);
1.699 + return CFont::ECharacterWidthOnly ;
1.700 + case 0x05EA:
1.701 + // We want Hebrew Tav to have a +ve left side-bearing
1.702 + CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
1.703 + aMetrics.SetHorizBearingX(1);
1.704 + return CFont::ECharacterWidthOnly ;
1.705 + case 0x304B:
1.706 + // We want Hiragana Ka to have a top end-bearing
1.707 + CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
1.708 + aMetrics.SetVertBearingY(-1);
1.709 + return CFont::EAllCharacterData ;
1.710 + case 0x0020:
1.711 + CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
1.712 + aMetrics.SetWidth(0);
1.713 + aMetrics.SetHeight(0);
1.714 + aMetrics.SetVertAdvance(0);
1.715 + return CFont::ECharacterWidthOnly ;
1.716 + default:
1.717 + return CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
1.718 + }
1.719 + }