sl@0: /* sl@0: * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "TGraphicsContext.h" sl@0: #include sl@0: sl@0: #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS sl@0: #include sl@0: #include sl@0: #endif sl@0: sl@0: _LIT(KTestFontName, "Non Functional Test Font"); sl@0: sl@0: sl@0: // Utility functions to show contents of test data using test.Printf sl@0: sl@0: extern void PrintTestData (const TDesC& aTitle , const TDesC16& aDataBuffer); sl@0: sl@0: extern void PrintTestData(const TDesC& aTitle, const TText16* aDataBuffer, const TInt aSize); sl@0: sl@0: // sl@0: // sl@0: // CLineArray sl@0: // sl@0: // sl@0: CLineArray::CLineArray() : iArrayIsEnabled(ETrue), iArray(0) sl@0: { sl@0: iPrev = iNext = this; sl@0: } sl@0: sl@0: void CLineArray::Null() sl@0: { sl@0: if (iNext == this && iArray) sl@0: { sl@0: iArray->Close(); sl@0: delete iArray; sl@0: } sl@0: iArray = 0; sl@0: iPrev->iNext = iNext; sl@0: iNext->iPrev = iPrev; sl@0: iNext = iPrev = this; sl@0: } sl@0: sl@0: CLineArray::~CLineArray() sl@0: { sl@0: Null(); sl@0: } sl@0: sl@0: void CLineArray::ConstructL(TInt aGranularity) sl@0: { sl@0: CLineArray::Null(); sl@0: iArray = new (ELeave) RArray(aGranularity); sl@0: } sl@0: sl@0: void CLineArray::Copy(const CLineArray& aOther) sl@0: { sl@0: CLineArray::Null(); sl@0: iNext = &aOther; sl@0: iPrev = aOther.iPrev; sl@0: iPrev->iNext = this; sl@0: aOther.iPrev = this; sl@0: iArray = aOther.iArray; sl@0: iArrayIsEnabled = aOther.iArrayIsEnabled; sl@0: } sl@0: sl@0: void CLineArray::ResetLineArray() sl@0: { sl@0: iArray->Reset(); sl@0: } sl@0: sl@0: const TTestGCDisplayLine& CLineArray::Line(TInt aIndex) sl@0: { sl@0: return (*iArray)[aIndex]; sl@0: } sl@0: sl@0: const TTestGCDisplayLine* CLineArray::Find(const TDesC& aText) sl@0: { sl@0: TInt count = LinesPresent(); sl@0: for (TInt i = 0; i != count; ++i) sl@0: { sl@0: const TTestGCDisplayLine& line = Line(i); sl@0: if (line.iLineData.Find(aText) != KErrNotFound) sl@0: return &line; sl@0: } sl@0: return 0; sl@0: } sl@0: sl@0: void CLineArray::AddLineL(TTestGCDisplayLine& aLine) sl@0: { sl@0: if (iArrayIsEnabled) sl@0: User::LeaveIfError(iArray->Append(aLine)); sl@0: } sl@0: sl@0: TInt CLineArray::LinesPresent() sl@0: { sl@0: return iArray->Count(); sl@0: } sl@0: sl@0: // sl@0: // sl@0: // CTestGraphicsDevice sl@0: // sl@0: // sl@0: CTestGraphicsDevice* CTestGraphicsDevice::NewL(TSize aSizeInPixels, RWsSession* aWsSession) sl@0: { sl@0: CTestGraphicsDevice* r = aWsSession? sl@0: new (ELeave) CTestGraphicsDevice(aSizeInPixels, aWsSession) sl@0: : new (ELeave) CTestGraphicsDevice(aSizeInPixels); sl@0: r->iLineArray.ConstructL(4); sl@0: if (aWsSession && KErrNone != r->Construct()) sl@0: { sl@0: delete r; sl@0: return 0; sl@0: } sl@0: return r; sl@0: } sl@0: sl@0: CTestGraphicsDevice::CTestGraphicsDevice(TSize aSizeInPixels, RWsSession* aWsSession) sl@0: : CWsScreenDevice(*aWsSession) sl@0: { sl@0: Set(aSizeInPixels); sl@0: } sl@0: sl@0: CTestGraphicsDevice::CTestGraphicsDevice(TSize aSizeInPixels) sl@0: { sl@0: Set(aSizeInPixels); sl@0: } sl@0: sl@0: void CTestGraphicsDevice::Set(TSize aSizeInPixels) sl@0: { sl@0: iSize = aSizeInPixels; sl@0: iHorizontalTwipsToPixels = 40; sl@0: iVerticalTwipsToPixels = 40; sl@0: iPalette.SetEntry(0, KRgbBlack); sl@0: iPalette.SetEntry(1, KRgbWhite); sl@0: iPalette.SetEntry(2, KRgbMagenta); sl@0: iPalette.SetEntry(3, KRgbCyan); sl@0: } sl@0: sl@0: void CTestGraphicsDevice::SetHorizontalTwipsToPixels(TInt aTwipsToPixels) sl@0: { sl@0: iHorizontalTwipsToPixels = aTwipsToPixels; sl@0: } sl@0: sl@0: void CTestGraphicsDevice::SetVerticalTwipsToPixels(TInt aTwipsToPixels) sl@0: { sl@0: iVerticalTwipsToPixels = aTwipsToPixels; sl@0: } sl@0: sl@0: TDisplayMode CTestGraphicsDevice::DisplayMode() const sl@0: { sl@0: return EColor16M; sl@0: } sl@0: sl@0: TSize CTestGraphicsDevice::SizeInPixels() const sl@0: { sl@0: return iSize; sl@0: } sl@0: sl@0: TSize CTestGraphicsDevice::SizeInTwips() const sl@0: { sl@0: return TSize(iSize.iWidth * iHorizontalTwipsToPixels, sl@0: iSize.iHeight * iVerticalTwipsToPixels); sl@0: } sl@0: sl@0: TInt CTestGraphicsDevice::CreateContext(CWindowGc*& aGC) sl@0: { sl@0: CTestGraphicsContext* r = new CTestGraphicsContext(this); sl@0: if (!r) sl@0: return KErrNoMemory; sl@0: // only contruct if it is a fully-fledged Window Server thing sl@0: if (iBuffer) sl@0: r->Construct(); sl@0: aGC = r; sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CTestGraphicsDevice::CreateContext(CGraphicsContext*& aGC) sl@0: { sl@0: CWindowGc* p; sl@0: TInt r = CreateContext(p); sl@0: aGC = p; sl@0: return r; sl@0: } sl@0: sl@0: TInt CTestGraphicsDevice::NumTypefaces() const sl@0: { sl@0: return 1; sl@0: } sl@0: sl@0: void CTestGraphicsDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport, TInt aTypefaceIndex) const sl@0: { sl@0: // The only font we have at the moment is 10 pixels * 12 pixels for every character sl@0: __ASSERT_ALWAYS(aTypefaceIndex == 0, sl@0: CTestGraphicsContext::Panic(CTestGraphicsContext::ETypefaceIndexOutOfRange)); sl@0: aTypefaceSupport.iIsScalable = EFalse; sl@0: aTypefaceSupport.iMaxHeightInTwips = iVerticalTwipsToPixels * 12; sl@0: aTypefaceSupport.iMinHeightInTwips = iVerticalTwipsToPixels * 10; sl@0: aTypefaceSupport.iNumHeights = 1; sl@0: aTypefaceSupport.iTypeface.iName = KTestFontName; sl@0: aTypefaceSupport.iTypeface.SetIsProportional(ETrue); // a bit of a lie sl@0: aTypefaceSupport.iTypeface.SetIsSerif(EFalse); sl@0: aTypefaceSupport.iTypeface.SetIsSymbol(EFalse); sl@0: } sl@0: sl@0: TInt CTestGraphicsDevice::FontHeightInTwips(TInt aTypefaceIndex, TInt aHeightIndex) const sl@0: { sl@0: // The only font we have at the moment is 10 pixels * 12 pixels for every character sl@0: __ASSERT_ALWAYS(aTypefaceIndex == 0, sl@0: CTestGraphicsContext::Panic(CTestGraphicsContext::ETypefaceIndexOutOfRange)); sl@0: return iVerticalTwipsToPixels * FontHeightInPixels(aTypefaceIndex, aHeightIndex); sl@0: } sl@0: sl@0: void CTestGraphicsDevice::PaletteAttributes(TBool& aModifiable, TInt& aNumEntries) const sl@0: { sl@0: aModifiable = ETrue; sl@0: aNumEntries = 4; sl@0: } sl@0: sl@0: void CTestGraphicsDevice::SetPalette(CPalette* aPalette) sl@0: { sl@0: for (TInt i = 0; i != CTestPalette::KNumEntries; ++i) sl@0: { sl@0: TRgb col = aPalette->GetEntry(i); sl@0: iPalette.SetEntry(i, col); sl@0: } sl@0: } sl@0: sl@0: TInt CTestGraphicsDevice::GetPalette(CPalette*& aPalette) const sl@0: { sl@0: aPalette = const_cast(&iPalette); sl@0: return KErrNone; sl@0: } sl@0: sl@0: void CTestGraphicsDevice::GetPixel(TRgb& aColor, const TPoint&) const sl@0: { sl@0: aColor = KRgbWhite; sl@0: } sl@0: sl@0: void CTestGraphicsDevice::GetScanLine(TDes8&, const TPoint&, TInt, TDisplayMode) const sl@0: { sl@0: __ASSERT_DEBUG(0, CTestGraphicsContext::Panic(CTestGraphicsContext::EUnimplemented)); sl@0: } sl@0: sl@0: TInt CTestGraphicsDevice::AddFile(const TDesC&, TInt&) sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: void CTestGraphicsDevice::RemoveFile(TInt) sl@0: { sl@0: } sl@0: sl@0: TInt CTestGraphicsDevice::GetNearestFontInPixels(CFont*& aFont, const TFontSpec&) sl@0: { sl@0: CTestFont* font = new CTestFont(); sl@0: if (!font) sl@0: return KErrNoMemory; sl@0: aFont = font; sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CTestGraphicsDevice::FontHeightInPixels(TInt, TInt) const sl@0: { sl@0: return 12; sl@0: } sl@0: sl@0: TInt CTestGraphicsDevice::HorizontalTwipsToPixels(TInt aTwips) const sl@0: { sl@0: return aTwips / iHorizontalTwipsToPixels; sl@0: } sl@0: sl@0: TInt CTestGraphicsDevice::VerticalTwipsToPixels(TInt aTwips) const sl@0: { sl@0: return aTwips / iVerticalTwipsToPixels; sl@0: } sl@0: sl@0: TInt CTestGraphicsDevice::HorizontalPixelsToTwips(TInt aPixels) const sl@0: { sl@0: return aPixels * iHorizontalTwipsToPixels; sl@0: } sl@0: sl@0: TInt CTestGraphicsDevice::VerticalPixelsToTwips(TInt aPixels) const sl@0: { sl@0: return aPixels * iVerticalTwipsToPixels; sl@0: } sl@0: sl@0: TInt CTestGraphicsDevice::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec) sl@0: { sl@0: TFontSpec fontSpec = aFontSpec; sl@0: fontSpec.iHeight = VerticalTwipsToPixels(fontSpec.iHeight); sl@0: return GetNearestFontInPixels(aFont, fontSpec); sl@0: } sl@0: sl@0: void CTestGraphicsDevice::ReleaseFont(CFont* aFont) sl@0: { sl@0: __ASSERT_ALWAYS(aFont->TypeUid() == TUid::Uid(12345), sl@0: CTestGraphicsContext::Panic(CTestGraphicsContext::EUnknownFont)); sl@0: delete static_cast(aFont); sl@0: } sl@0: sl@0: void CTestGraphicsDevice::AddRectToDrawnArea(const TRect& aRect, TBool aCondition) sl@0: { sl@0: // check if the drawing is on testing area sl@0: if (!(iTestingArea.IsEmpty()) && // if testing area has been set sl@0: !iHasDrawnOnTestingArea) // and nothing hasn't been drawn on it so far sl@0: iHasDrawnOnTestingArea = iTestingArea.Intersects(aRect); sl@0: sl@0: if (iDrawnArea.IsEmpty()) sl@0: iDrawnArea = aRect; sl@0: else sl@0: iDrawnArea.BoundingRect(aRect); sl@0: // only one condition at the moment sl@0: if (aCondition) sl@0: { sl@0: if (iAreaDrawnWithCondition.IsEmpty()) sl@0: iAreaDrawnWithCondition = aRect; sl@0: else sl@0: iAreaDrawnWithCondition.BoundingRect(aRect); sl@0: } sl@0: } sl@0: sl@0: void CTestGraphicsDevice::SetTestingArea(TRect& aTestingArea) sl@0: { sl@0: iTestingArea = aTestingArea; sl@0: } sl@0: sl@0: void CTestGraphicsDevice::AddTestingArea(TRect& moreTestingArea) sl@0: { sl@0: if (iTestingArea.IsEmpty()) sl@0: iTestingArea = moreTestingArea; sl@0: else sl@0: iTestingArea.BoundingRect(moreTestingArea); sl@0: } sl@0: sl@0: // sl@0: // sl@0: // CTestGraphicsContext sl@0: // sl@0: // sl@0: void CTestGraphicsContext::Panic(TInt aReason) sl@0: { sl@0: User::Panic(_L("CTestGC"), aReason); sl@0: } sl@0: sl@0: CTestGraphicsContext::CTestGraphicsContext(CTestGraphicsDevice* aGd) sl@0: : CWindowGc(aGd), iGd(aGd), iDrawMode(EDrawModePEN), iPenSize(1,1) sl@0: { sl@0: iLineArray.Copy(aGd->LineArray()); sl@0: } sl@0: sl@0: TInt CTestGraphicsContext::Construct() sl@0: { sl@0: return CWindowGc::Construct(); sl@0: } sl@0: sl@0: void CTestGraphicsContext::AddRectToDrawnArea(const TRect& aRect) sl@0: { sl@0: TRect drawnRect = aRect; sl@0: drawnRect.Grow(iPenSize); sl@0: iGd->AddRectToDrawnArea(drawnRect, sl@0: iDrawMode == EDrawModeXOR || iDrawMode == EDrawModeNOTSCREEN); sl@0: } sl@0: sl@0: void CTestGraphicsContext::AddPointToDrawnArea(const TPoint& aPoint) sl@0: { sl@0: AddRectToDrawnArea(TRect(aPoint, iPenSize)); sl@0: } sl@0: sl@0: CGraphicsDevice* CTestGraphicsContext::Device() const sl@0: { sl@0: return iGd; sl@0: } sl@0: sl@0: void CTestGraphicsContext::SetOrigin(const TPoint& aPos) sl@0: { sl@0: iOrigin = aPos; sl@0: } sl@0: sl@0: void CTestGraphicsContext::SetDrawMode(TDrawMode aDrawingMode) sl@0: { sl@0: iDrawMode = aDrawingMode; sl@0: } sl@0: sl@0: void CTestGraphicsContext::SetClippingRect(const TRect& /*aRect*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::CancelClippingRect() sl@0: { sl@0: } sl@0: sl@0: TInt CTestGraphicsContext::SetClippingRegion(const TRegion& /*aRegion*/) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: sl@0: void CTestGraphicsContext::CancelClippingRegion() sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::Reset() sl@0: { sl@0: iDrawMode = EDrawModePEN; sl@0: iFont = 0; sl@0: iPenSize.iWidth = 1; sl@0: iPenSize.iHeight = 1; sl@0: } sl@0: sl@0: void CTestGraphicsContext::UseFont(const CFont* aFont) sl@0: { sl@0: iFont = aFont; sl@0: } sl@0: sl@0: void CTestGraphicsContext::DiscardFont() sl@0: { sl@0: iFont = 0; sl@0: } sl@0: sl@0: void CTestGraphicsContext::SetUnderlineStyle(TFontUnderline /*UnderlineStyle*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::SetStrikethroughStyle(TFontStrikethrough /*aStrikethroughStyle*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::SetWordJustification(TInt /*aExcessWidth*/,TInt /*aNumGaps*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::SetCharJustification(TInt /*aExcessWidth*/,TInt /*aNumChars*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::SetPenColor(const TRgb& aColor) sl@0: { sl@0: CPalette* palette; sl@0: iGd->GetPalette(palette); sl@0: iPenColorIndex = palette->NearestIndex(aColor); sl@0: } sl@0: sl@0: void CTestGraphicsContext::SetPenStyle(TPenStyle /*aPenStyle*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::SetPenSize(const TSize& aSize) sl@0: { sl@0: iPenSize = aSize; sl@0: } sl@0: sl@0: void CTestGraphicsContext::SetBrushColor(const TRgb& /*aColor*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::SetBrushStyle(TBrushStyle /*aBrushStyle*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::SetBrushOrigin(const TPoint& /*aOrigin*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::UseBrushPattern(const CFbsBitmap* /*aBitmap*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::DiscardBrushPattern() sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::MoveTo(const TPoint& aPoint) sl@0: { sl@0: iCurrentPos = iOrigin + aPoint; sl@0: } sl@0: sl@0: void CTestGraphicsContext::MoveBy(const TPoint& aVector) sl@0: { sl@0: iCurrentPos += aVector; sl@0: } sl@0: sl@0: void CTestGraphicsContext::Plot(const TPoint& aPoint) sl@0: { sl@0: iCurrentPos = iOrigin + aPoint; sl@0: AddPointToDrawnArea(iCurrentPos); sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawArc(const TRect& aRect,const TPoint& /*aStart*/,const TPoint& aEnd) sl@0: { sl@0: TRect r = aRect; sl@0: r.Move(iOrigin); sl@0: AddRectToDrawnArea(r); sl@0: iCurrentPos = iOrigin + aEnd; sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawLine(const TPoint& aPoint1,const TPoint& aPoint2) sl@0: { sl@0: AddPointToDrawnArea(iOrigin + aPoint1); sl@0: iCurrentPos = iOrigin + aPoint2; sl@0: AddPointToDrawnArea(iCurrentPos); sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawLineTo(const TPoint& aPoint) sl@0: { sl@0: AddPointToDrawnArea(iCurrentPos); sl@0: iCurrentPos = iOrigin + aPoint; sl@0: AddPointToDrawnArea(iCurrentPos); sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawLineBy(const TPoint& aVector) sl@0: { sl@0: AddPointToDrawnArea(iCurrentPos); sl@0: iCurrentPos += aVector; sl@0: AddPointToDrawnArea(iCurrentPos); sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawPolyLine(const CArrayFix* aPointList) sl@0: { sl@0: TInt num = aPointList->Count(); sl@0: while (num--) sl@0: { sl@0: iCurrentPos = iOrigin + (*aPointList)[num - 1]; sl@0: AddPointToDrawnArea(iCurrentPos); sl@0: } sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawPolyLine(const TPoint* aPointList,TInt aNumPoints) sl@0: { sl@0: while (aNumPoints--) sl@0: { sl@0: iCurrentPos = iOrigin + aPointList[aNumPoints - 1]; sl@0: AddPointToDrawnArea(iCurrentPos); sl@0: } sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawPie(const TRect& aRect, sl@0: const TPoint& /*aStart*/, const TPoint& aEnd) sl@0: { sl@0: TRect r = aRect; sl@0: r.Move(iOrigin); sl@0: AddRectToDrawnArea(r); sl@0: iCurrentPos = iOrigin + aEnd; sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawEllipse(const TRect& aRect) sl@0: { sl@0: TRect r = aRect; sl@0: r.Move(iOrigin); sl@0: AddRectToDrawnArea(r); sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawRect(const TRect& aRect) sl@0: { sl@0: TRect r = aRect; sl@0: r.Move(iOrigin); sl@0: AddRectToDrawnArea(r); sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawRoundRect(const TRect& aRect,const TSize& aCornerSize) sl@0: { sl@0: TRect r = aRect; sl@0: r.Move(iOrigin); sl@0: r.Grow(aCornerSize); sl@0: AddRectToDrawnArea(r); sl@0: } sl@0: sl@0: TInt CTestGraphicsContext::DrawPolygon(const CArrayFix* aPointList,TFillRule /*aFillRule*/) sl@0: { sl@0: TInt num = aPointList->Count(); sl@0: while (num--) sl@0: { sl@0: iCurrentPos = iOrigin + (*aPointList)[num - 1]; sl@0: AddPointToDrawnArea(iCurrentPos); sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CTestGraphicsContext::DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule /*aFillRule*/) sl@0: { sl@0: while (aNumPoints--) sl@0: { sl@0: iCurrentPos = iOrigin + aPointList[aNumPoints - 1]; sl@0: AddPointToDrawnArea(iCurrentPos); sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawBitmap(const TPoint& /*aTopLeft*/,const CFbsBitmap* /*aSource*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawBitmap(const TRect& /*aDestRect*/,const CFbsBitmap* /*aSource*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawBitmap(const TRect& /*aDestRect*/,const CFbsBitmap* /*aSource*/,const TRect& /*aSourceRect*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawText(const TDesC& aText, const TPoint& aPosition) sl@0: { sl@0: #ifdef PRINT_DRAWTEXT_LINES sl@0: sl@0: _LIT(KDrawTextTitle, "Text being drawn"); sl@0: PrintTestData(KDrawTextTitle, aText); sl@0: sl@0: #endif /* PRINT_DRAWTEXT_LINES */ sl@0: sl@0: TTestGCDisplayLine thisLine; sl@0: thisLine.Set(aPosition, aText); sl@0: iLineArray.AddLineL(thisLine); sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawText(const TDesC& aText,const TRect& aBox,TInt aBaselineOffset, sl@0: TTextAlign /*aAlignment*/, TInt aLeftMargin) sl@0: { sl@0: TPoint pos(aBox.iBr.iX + aLeftMargin, aBox.iTl.iY + aBaselineOffset); sl@0: pos += iOrigin; sl@0: DrawText(aText, pos); sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawText(const TDesC& aText,TTextParameters* aParam, const TPoint& aPosition) sl@0: { sl@0: #ifdef PRINT_DRAWTEXT_LINES sl@0: sl@0: _LIT(KDrawTextTitle, "Text being drawn"); sl@0: PrintTestData(KDrawTextTitle, aText); sl@0: sl@0: #endif /* PRINT_DRAWTEXT_LINES */ sl@0: sl@0: //Avoid crash by ASSERT in BitGdi DrawText function sl@0: __ASSERT_ALWAYS(aParam->iStart < aParam->iEnd, sl@0: CTestGraphicsContext::Panic(CTestGraphicsContext::EErrorParameter)); sl@0: sl@0: TTestGCDisplayLine thisLine; sl@0: TPtrC actualText = aText.Mid(aParam->iStart,aParam->iEnd - aParam->iStart + 1); sl@0: thisLine.Set(aPosition, actualText); sl@0: iLineArray.AddLineL(thisLine); sl@0: } sl@0: sl@0: void CTestGraphicsContext::DrawText(const TDesC& aText,TTextParameters* aParam,const TRect& aBox,TInt aBaselineOffset, sl@0: TTextAlign /*aAlignment*/, TInt aLeftMargin) sl@0: { sl@0: TPoint pos(aBox.iBr.iX + aLeftMargin, aBox.iTl.iY + aBaselineOffset); sl@0: pos += iOrigin; sl@0: DrawText(aText,aParam, pos); sl@0: } sl@0: sl@0: TInt CTestGraphicsContext::APIExtension(TUid aUid, TAny*& aOutput, TAny* aInput) sl@0: { sl@0: if (aUid == KDrawTextInContextUid) sl@0: { sl@0: TDrawTextInContextInternal* contextParam = (TDrawTextInContextInternal*)aInput; sl@0: DrawText(contextParam->iText, &contextParam->iParam, contextParam->iPosition); sl@0: return KErrNone; sl@0: } sl@0: else if (aUid == KDrawBoxTextInContextUid) sl@0: { sl@0: TDrawTextInContextInternal* contextParam = (TDrawTextInContextInternal*)aInput; sl@0: DrawText(contextParam->iText,&contextParam->iParam,contextParam->iBox,contextParam->iBaselineOffset,contextParam->iAlign,contextParam->iMargin); sl@0: return KErrNone; sl@0: } sl@0: // Future cases may be placed here later sl@0: else sl@0: return CWindowGc::APIExtension(aUid, aOutput, aInput); sl@0: } sl@0: sl@0: sl@0: void CTestGraphicsContext::Clear() sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::Clear(const TRect& /*aRect*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::CopyRect(const TPoint& /*aOffset*/, const TRect& /*aRect*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::BitBlt(const TPoint& /*aPoint*/, const CFbsBitmap* /*aBitmap*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::BitBlt(const TPoint& /*aPoint*/, const CFbsBitmap* /*aBitmap*/, sl@0: const TRect& /*aRect*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::BitBltMasked(const TPoint& /*aPoint*/, const CFbsBitmap* /*aBitmap*/, sl@0: const TRect& /*aSourceRect*/, const CFbsBitmap* /*aMaskBitmap*/, TBool /*aInvertMask*/) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::SetFaded(TBool) sl@0: { sl@0: } sl@0: sl@0: void CTestGraphicsContext::SetFadingParameters(TUint8,TUint8) sl@0: { sl@0: } sl@0: sl@0: // sl@0: // sl@0: // CTestFont sl@0: // sl@0: // sl@0: inline TBool IsSurrogate(TText a) { return 0xD800 == (a & 0xF800); } sl@0: inline TBool IsHighSurrogate(TText a) { return 0xD800 == (a & 0xFC00); } sl@0: inline TBool IsLowSurrogate(TText a) { return 0xDC00 == (a & 0xFC00); } sl@0: inline TChar PairSurrogates(TText aHigh, TText aLow) sl@0: { sl@0: return ((aHigh - 0xd7f7) << 10) + aLow; sl@0: } sl@0: sl@0: TUid CTestFont::DoTypeUid() const sl@0: { sl@0: return TUid::Uid(12345); sl@0: } sl@0: sl@0: TInt CTestFont::DoHeightInPixels() const sl@0: { sl@0: return 12; sl@0: } sl@0: sl@0: TInt CTestFont::DoAscentInPixels() const sl@0: { sl@0: return 10; sl@0: } sl@0: sl@0: struct TSpecialSizes sl@0: { sl@0: TInt iCharacter; sl@0: TInt iWidth; sl@0: }; sl@0: sl@0: static const TSpecialSizes KSpecialSizes[] = sl@0: { sl@0: { CTestFont::KThreePerEmSpace, 3 }, sl@0: { CTestFont::KThinSpace, 2 }, sl@0: { CTestFont::KHairSpace, 1 }, sl@0: { CTestFont::KZeroWidthSpace, 0 }, sl@0: { CTestFont::KZeroWidthNoBreakSpace, 0 }, sl@0: }; sl@0: sl@0: TInt CTestFont::DoCharWidthInPixels(TChar aChar) const sl@0: { sl@0: TInt cn = aChar; sl@0: // non-characters 0x??FFFE and 0x??FFFF sl@0: if ((cn & 0xFFFE) == 0xFFFE) sl@0: return 0; sl@0: sl@0: // Find character in the special sizes table sl@0: TInt first = 0; sl@0: TInt last = sizeof(KSpecialSizes)/sizeof(KSpecialSizes[0]); sl@0: while (first != last) sl@0: { sl@0: TInt c = static_cast(aChar); sl@0: TInt mid = (first + last) >> 1; sl@0: if (c < KSpecialSizes[mid].iCharacter) sl@0: last = mid; sl@0: else if (KSpecialSizes[mid].iCharacter < c) sl@0: first = mid + 1; sl@0: else sl@0: return KSpecialSizes[mid].iWidth; sl@0: } sl@0: sl@0: return 10; sl@0: } sl@0: sl@0: TInt CTestFont::DoTextCount(const TDesC& aText, TInt aWidthInPixels, sl@0: TInt& aExcessWidthInPixels) const sl@0: { sl@0: const TText* p = &aText[0]; sl@0: const TText* pEnd = p + aText.Length(); sl@0: TInt total = 0; sl@0: TInt prevSurrogate = 0; sl@0: TInt charactersThatFit = 0; sl@0: while (p != pEnd) sl@0: { sl@0: TChar c = *p; sl@0: if (IsSurrogate(*p)) sl@0: { sl@0: c = 0xFFFF; sl@0: if (IsHighSurrogate(*p)) sl@0: prevSurrogate = *p; sl@0: else if (prevSurrogate != 0) sl@0: { sl@0: c = PairSurrogates(static_cast(prevSurrogate), *p); sl@0: prevSurrogate = 0; sl@0: } sl@0: } sl@0: else sl@0: prevSurrogate = 0; sl@0: total += CharWidthInPixels(c); sl@0: if (total <= aWidthInPixels) sl@0: ++charactersThatFit; sl@0: ++p; sl@0: } sl@0: aExcessWidthInPixels = total - aWidthInPixels; sl@0: return charactersThatFit; sl@0: } sl@0: sl@0: TInt CTestFont::DoTextWidthInPixels(const TDesC& aText) const sl@0: { sl@0: TInt excess; sl@0: TextCount(aText, 0, excess); sl@0: return excess; sl@0: } sl@0: sl@0: TInt CTestFont::DoBaselineOffsetInPixels() const sl@0: { sl@0: return 10; sl@0: } sl@0: sl@0: TInt CTestFont::DoTextCount(const TDesC& aText,TInt aWidthInPixels) const sl@0: { sl@0: TInt excess; sl@0: return TextCount(aText, aWidthInPixels, excess); sl@0: } sl@0: sl@0: TInt CTestFont::DoMaxCharWidthInPixels() const sl@0: { sl@0: return 10; sl@0: } sl@0: sl@0: TInt CTestFont::DoMaxNormalCharWidthInPixels() const sl@0: { sl@0: return 10; sl@0: } sl@0: sl@0: TFontSpec CTestFont::DoFontSpecInTwips() const sl@0: { sl@0: return TFontSpec(KTestFontName, 12); sl@0: } sl@0: sl@0: CFont::TCharacterDataAvailability sl@0: CTestFont::DoGetCharacterData(TUint aCode, TOpenFontCharMetrics& aMetrics, sl@0: const TUint8*& aBitmap, TSize& aBitmapSize) const sl@0: { sl@0: TInt width; sl@0: switch (aCode) sl@0: { sl@0: case 0x001B: sl@0: // ESC character should cause this fault; no character data available. sl@0: return CFont::ENoCharacterData; sl@0: case 'W': sl@0: // We want 'W' to have side-bearings sl@0: CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize); sl@0: width = aMetrics.Width(); sl@0: aMetrics.SetHorizBearingX(-1); sl@0: aMetrics.SetWidth(width + 2); sl@0: return CFont::ECharacterWidthOnly ; sl@0: case '/': sl@0: // We want / to have a left side-bearing sl@0: CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize); sl@0: width = aMetrics.Width(); sl@0: aMetrics.SetHorizBearingX(-1); sl@0: aMetrics.SetWidth(width + 1); sl@0: return CFont::ECharacterWidthOnly ; sl@0: case 'D': sl@0: // We want 'D' to have a left side-bearing only sl@0: CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize); sl@0: aMetrics.SetHorizBearingX(-1); sl@0: return CFont::ECharacterWidthOnly ; sl@0: case KTav: sl@0: // We want Hebrew Tav to have a +ve left side-bearing sl@0: CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize); sl@0: aMetrics.SetHorizBearingX(1); sl@0: return CFont::ECharacterWidthOnly ; sl@0: case KFullWidthSolidus: sl@0: // We want fw/ to have a right side-bearing sl@0: CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize); sl@0: width = aMetrics.Width(); sl@0: aMetrics.SetWidth(width + 1); sl@0: return CFont::ECharacterWidthOnly ; sl@0: case KArabicWaw: sl@0: // Arabic Waw-- has massive left side-bearing sl@0: CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize); sl@0: width = aMetrics.Width(); sl@0: aMetrics.SetHorizBearingX(-5); sl@0: aMetrics.SetWidth(width + 5); sl@0: return CFont::ECharacterWidthOnly ; sl@0: default: sl@0: return CFont::DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize); sl@0: } sl@0: } sl@0: