sl@0: // Copyright (c) 1997-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: #include sl@0: #include sl@0: #include sl@0: sl@0: NONSHARABLE_CLASS(CFontStack) : public CBase sl@0: { sl@0: protected: sl@0: CFontStack(CGraphicsDevice* aDevice); sl@0: public: sl@0: static CFontStack* NewL(CGraphicsDevice* aDevice); sl@0: ~CFontStack(); sl@0: void AddFontL(CFont* aFont); sl@0: private: sl@0: CGraphicsDevice* iDevice; sl@0: CArrayPtrFlat* iFontList; sl@0: }; sl@0: sl@0: CFontStack::CFontStack(CGraphicsDevice* aDevice): sl@0: iDevice(aDevice), sl@0: iFontList(NULL) sl@0: { sl@0: __DECLARE_NAME(_S("CFontStack")); sl@0: } sl@0: sl@0: CFontStack* CFontStack::NewL(CGraphicsDevice* aDevice) sl@0: { sl@0: CFontStack* fontstack=new(ELeave) CFontStack(aDevice); sl@0: CleanupStack::PushL(fontstack); sl@0: fontstack->iFontList=new(ELeave) CArrayPtrFlat(8); sl@0: CleanupStack::Pop(); sl@0: return fontstack; sl@0: } sl@0: sl@0: CFontStack::~CFontStack() sl@0: { sl@0: if (iFontList) sl@0: { sl@0: TInt count=iFontList->Count(); sl@0: for (TInt i=0; iReleaseFont((*iFontList)[i]); sl@0: delete iFontList; sl@0: } sl@0: } sl@0: sl@0: void CFontStack::AddFontL(CFont* aFont) sl@0: { sl@0: TRAPD(ret,iFontList->AppendL(aFont)); sl@0: if (ret!=KErrNone) sl@0: { sl@0: iDevice->ReleaseFont(aFont); sl@0: User::Leave(ret); sl@0: } sl@0: } sl@0: sl@0: enum TGraphicsContextCommandCode sl@0: { sl@0: EUseGc, // Not gc command sl@0: EEndOfStream, sl@0: sl@0: ESetOrigin, sl@0: ESetDrawMode, sl@0: ESetClippingRect, sl@0: ECancelClippingRect, sl@0: EReset, sl@0: EUseFont, sl@0: EDiscardFont, sl@0: ESetUnderlineStyle, sl@0: ESetStrikethroughStyle, sl@0: ESetWordJustification, sl@0: ESetCharJustification, sl@0: ESetPenColor, sl@0: ESetPenStyle, sl@0: ESetPenSize, sl@0: ESetBrushColor, sl@0: ESetBrushStyle, sl@0: ESetBrushOrigin, sl@0: EUseBrushPattern, sl@0: EDiscardBrushPattern, sl@0: EMoveTo, sl@0: EMoveBy, sl@0: EPlot, sl@0: EDrawArc, sl@0: EDrawLine, sl@0: EDrawLineTo, sl@0: EDrawLineBy, sl@0: EDrawPolyLine1, sl@0: EDrawPolyLine2, sl@0: EDrawPie, sl@0: EDrawEllipse, sl@0: EDrawRect, sl@0: EDrawRoundRect, sl@0: EDrawPolygon1, sl@0: EDrawPolygon2, sl@0: EDrawBitmap1, sl@0: EDrawBitmap2, sl@0: EDrawBitmap3, sl@0: EDrawText1, sl@0: EDrawText2 sl@0: }; sl@0: sl@0: inline RWriteStream& operator<<(RWriteStream& aStream,TGraphicsContextCommandCode aCommandCode) sl@0: { sl@0: aStream.WriteUint8L(TUint8(aCommandCode)); sl@0: return aStream; sl@0: } sl@0: sl@0: EXPORT_C CMetafileDevice::CMetafileDevice(CGraphicsDevice* aDevice): sl@0: CGraphicsDevice(), sl@0: iGcCount(0), sl@0: iGcIndex(-1), sl@0: iRealDevice(aDevice), sl@0: iWriteStream(NULL) sl@0: { sl@0: __DECLARE_NAME(_S("CMetafileDevice")); sl@0: } sl@0: sl@0: EXPORT_C CMetafileDevice* CMetafileDevice::NewL(CGraphicsDevice* aDevice) sl@0: { sl@0: CMetafileDevice* device=new(ELeave) CMetafileDevice(aDevice); sl@0: return device; sl@0: } sl@0: sl@0: EXPORT_C CMetafileDevice::~CMetafileDevice() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C TInt CMetafileDevice::HorizontalTwipsToPixels(TInt aTwips) const sl@0: { sl@0: return iRealDevice->HorizontalTwipsToPixels(aTwips); sl@0: } sl@0: sl@0: EXPORT_C TInt CMetafileDevice::VerticalTwipsToPixels(TInt aTwips) const sl@0: { sl@0: return iRealDevice->VerticalTwipsToPixels(aTwips); sl@0: } sl@0: sl@0: EXPORT_C TInt CMetafileDevice::HorizontalPixelsToTwips(TInt aPixels) const sl@0: { sl@0: return iRealDevice->HorizontalPixelsToTwips(aPixels); sl@0: } sl@0: sl@0: EXPORT_C TInt CMetafileDevice::VerticalPixelsToTwips(TInt aPixels) const sl@0: { sl@0: return iRealDevice->VerticalPixelsToTwips(aPixels); sl@0: } sl@0: sl@0: EXPORT_C TInt CMetafileDevice::GetNearestFontInTwips(CFont*& aFont,const TFontSpec& aFontSpec) sl@0: { sl@0: return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec); sl@0: } sl@0: sl@0: EXPORT_C TInt CMetafileDevice::GetNearestFontToDesignHeightInTwips(CFont*& aFont,const TFontSpec& aFontSpec) sl@0: { sl@0: return iRealDevice->GetNearestFontToDesignHeightInTwips(aFont,aFontSpec); sl@0: } sl@0: sl@0: EXPORT_C TInt CMetafileDevice::GetNearestFontToMaxHeightInTwips(CFont*& aFont,const TFontSpec& aFontSpec, TInt aMaxHeight) sl@0: { sl@0: return iRealDevice->GetNearestFontToMaxHeightInTwips(aFont, aFontSpec, aMaxHeight); sl@0: } sl@0: sl@0: EXPORT_C void CMetafileDevice::ReleaseFont(CFont* aFont) sl@0: { sl@0: iRealDevice->ReleaseFont(aFont); sl@0: } sl@0: sl@0: EXPORT_C TDisplayMode CMetafileDevice::DisplayMode() const sl@0: { sl@0: return iRealDevice->DisplayMode(); sl@0: } sl@0: sl@0: EXPORT_C TSize CMetafileDevice::SizeInPixels() const sl@0: { sl@0: return iRealDevice->SizeInPixels(); sl@0: } sl@0: sl@0: EXPORT_C TSize CMetafileDevice::SizeInTwips() const sl@0: { sl@0: return iRealDevice->SizeInTwips(); sl@0: } sl@0: sl@0: EXPORT_C TInt CMetafileDevice::CreateContext(CGraphicsContext*& aGC) sl@0: { sl@0: CMetafileGc* gc=new CMetafileGc(this,iGcCount); sl@0: if (!gc) sl@0: return KErrNoMemory; sl@0: iGcCount++; sl@0: aGC=gc; sl@0: return KErrNone; sl@0: } sl@0: sl@0: EXPORT_C TInt CMetafileDevice::NumTypefaces() const sl@0: { sl@0: return iRealDevice->NumTypefaces(); sl@0: } sl@0: sl@0: EXPORT_C void CMetafileDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const sl@0: { sl@0: iRealDevice->TypefaceSupport(aTypefaceSupport,aTypefaceIndex); sl@0: } sl@0: sl@0: EXPORT_C TInt CMetafileDevice::FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const sl@0: { sl@0: return iRealDevice->FontHeightInTwips(aTypefaceIndex,aHeightIndex); sl@0: } sl@0: sl@0: EXPORT_C void CMetafileDevice::PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const sl@0: { sl@0: iRealDevice->PaletteAttributes(aModifiable,aNumEntries); sl@0: } sl@0: sl@0: EXPORT_C void CMetafileDevice::SetPalette(CPalette* aPalette) sl@0: { sl@0: iRealDevice->SetPalette(aPalette); sl@0: } sl@0: sl@0: EXPORT_C TInt CMetafileDevice::GetPalette(CPalette*& aPalette) const sl@0: { sl@0: return iRealDevice->GetPalette(aPalette); sl@0: } sl@0: sl@0: EXPORT_C void CMetafileDevice::UseGcL(TInt aGcIndex) sl@0: { sl@0: if (iGcIndex!=aGcIndex) sl@0: { sl@0: iGcIndex=aGcIndex; sl@0: *iWriteStream << EUseGc; sl@0: iWriteStream->WriteInt32L(iGcIndex); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CMetafileDevice::StartOutputStreamL(RWriteStream& aStream) // Returns error code sl@0: { sl@0: iWriteStream=&aStream; sl@0: TSize size(HorizontalPixelsToTwips(1000),VerticalPixelsToTwips(1000)); sl@0: *iWriteStream << size; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileDevice::EndOfStreamL() // Returns error code sl@0: { sl@0: *iWriteStream << EEndOfStream; sl@0: } sl@0: sl@0: EXPORT_C RWriteStream& CMetafileDevice::WriteStream() sl@0: { sl@0: return *iWriteStream; sl@0: } sl@0: sl@0: EXPORT_C CMetafileGc::CMetafileGc(CMetafileDevice* aDevice,TInt anIndex): sl@0: CGraphicsContext(), sl@0: iDevice(aDevice), sl@0: iIndex(anIndex) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CMetafileGc::~CMetafileGc() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CGraphicsDevice* CMetafileGc::Device() const sl@0: { sl@0: return iDevice; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::SetOrigin(const TPoint& aPos) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << ESetOrigin; sl@0: iDevice->WriteStream() << aPos; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::SetDrawMode(TDrawMode aDrawingMode) sl@0: { sl@0: TInt errCode = 0; sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << ESetDrawMode; sl@0: TRAP(errCode, iDevice->WriteStream().WriteUint8L((TUint8) aDrawingMode)); sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::SetClippingRect(const TRect& aRect) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << ESetClippingRect; sl@0: iDevice->WriteStream() << aRect; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::CancelClippingRect() sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << ECancelClippingRect; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::Reset() sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EReset; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::UseFont(const CFont* aFont) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TInt errCode = 0; sl@0: TRAP(errCode, iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EUseFont; sl@0: iDevice->WriteStream() << aFont->FontSpecInTwips(); sl@0: TRAP(errCode, iDevice->WriteStream().WriteInt32L(aFont->HeightInPixels())); sl@0: TRAP(errCode, iDevice->WriteStream().WriteInt32L(aFont->BaselineOffsetInPixels())); sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DiscardFont() sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDiscardFont; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::SetUnderlineStyle(TFontUnderline aUnderlineStyle) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TInt errCode = 0; sl@0: TRAP(errCode, iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << ESetUnderlineStyle; sl@0: TRAP(errCode, iDevice->WriteStream().WriteUint8L((TUint8) aUnderlineStyle)); sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TInt errCode = 0; sl@0: TRAP(errCode, iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << ESetStrikethroughStyle; sl@0: TRAP(errCode, iDevice->WriteStream().WriteUint8L((TUint8) aStrikethroughStyle)); sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::SetWordJustification(TInt aExcessWidth,TInt aNumGaps) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TInt errCode = 0; sl@0: TRAP(errCode, iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << ESetWordJustification; sl@0: TRAP(errCode, iDevice->WriteStream().WriteInt32L(aExcessWidth)); sl@0: TRAP(errCode, iDevice->WriteStream().WriteInt32L(aNumGaps)); sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::SetCharJustification(TInt aExcessWidth,TInt aNumChars) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TInt errCode = 0; sl@0: TRAP(errCode, iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << ESetCharJustification; sl@0: TRAP(errCode, iDevice->WriteStream().WriteInt32L(aExcessWidth)); sl@0: TRAP(errCode, iDevice->WriteStream().WriteInt32L(aNumChars)); sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::SetPenColor(const TRgb& aColor) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << ESetPenColor; sl@0: iDevice->WriteStream() << aColor; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::SetPenStyle(TPenStyle aPenStyle) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TInt errCode = 0; sl@0: TRAP(errCode, iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << ESetPenStyle; sl@0: TRAP(errCode, iDevice->WriteStream().WriteUint8L((TUint8) aPenStyle)); sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::SetPenSize(const TSize& aSize) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << ESetPenSize; sl@0: iDevice->WriteStream() << aSize; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::SetBrushColor(const TRgb& aColor) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE( iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << ESetBrushColor; sl@0: iDevice->WriteStream() << aColor; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::SetBrushStyle(TBrushStyle aBrushStyle) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TInt errCode = 0; sl@0: TRAP(errCode, iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << ESetBrushStyle; sl@0: TRAP(errCode, iDevice->WriteStream().WriteUint8L((TUint8) aBrushStyle)); sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::SetBrushOrigin(const TPoint& aOrigin) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << ESetBrushOrigin; sl@0: iDevice->WriteStream() << aOrigin; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::UseBrushPattern(const CFbsBitmap* aBitmap) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TInt errCode = 0; sl@0: TRAP(errCode, iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EUseBrushPattern; sl@0: TRAP(errCode, aBitmap->ExternalizeL(iDevice->WriteStream())); sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DiscardBrushPattern() sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDiscardBrushPattern; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::MoveTo(const TPoint& aPoint) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EMoveTo; sl@0: iDevice->WriteStream() << aPoint; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::MoveBy(const TPoint& aVector) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EMoveBy; sl@0: iDevice->WriteStream() << aVector; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::Plot(const TPoint& aPoint) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EPlot; sl@0: iDevice->WriteStream() << aPoint; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DrawArc(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawArc; sl@0: iDevice->WriteStream() << aRect; sl@0: iDevice->WriteStream() << aStart; sl@0: iDevice->WriteStream() << aEnd; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DrawLine(const TPoint& aPoint1,const TPoint& aPoint2) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawLine; sl@0: iDevice->WriteStream() << aPoint1; sl@0: iDevice->WriteStream() << aPoint2; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DrawLineTo(const TPoint& aPoint) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawLineTo; sl@0: iDevice->WriteStream() << aPoint; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DrawLineBy(const TPoint& aVector) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawLineBy; sl@0: iDevice->WriteStream() << aVector; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DrawPolyLine(const CArrayFix* aPointList) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TInt errCode = 0; sl@0: TRAP(errCode, iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawPolyLine1; sl@0: sl@0: TInt numpoints=aPointList->Count(); sl@0: TRAP(errCode, iDevice->WriteStream().WriteInt32L(numpoints)); sl@0: for (TInt i=0; iWriteStream() << (*aPointList)[i]; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DrawPolyLine(const TPoint* aPointList,TInt aNumPoints) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TInt errCode = 0; sl@0: TRAP(errCode, iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawPolyLine2; sl@0: TRAP(errCode, iDevice->WriteStream().WriteInt32L(aNumPoints)); sl@0: TPoint *p=(TPoint*) aPointList,*pEnd=p+aNumPoints; sl@0: for (; pWriteStream() << *p; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DrawPie(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawPie; sl@0: iDevice->WriteStream() << aRect; sl@0: iDevice->WriteStream() << aStart; sl@0: iDevice->WriteStream() << aEnd; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DrawEllipse(const TRect& aRect) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawEllipse; sl@0: iDevice->WriteStream() << aRect; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DrawRect(const TRect& aRect) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawRect; sl@0: iDevice->WriteStream() << aRect; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DrawRoundRect(const TRect& aRect,const TSize& aCornerSize) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawRoundRect; sl@0: iDevice->WriteStream() << aRect; sl@0: iDevice->WriteStream() << aCornerSize; sl@0: } sl@0: sl@0: EXPORT_C TInt CMetafileGc::DrawPolygon(const CArrayFix* aPointList,TFillRule aFillRule) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TInt errCode = 0; sl@0: TRAP(errCode, iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawPolygon1; sl@0: TInt numpoints=aPointList->Count(); sl@0: TRAP(errCode, iDevice->WriteStream().WriteInt32L(numpoints)); sl@0: for (TInt i=0; iWriteStream() << (*aPointList)[i]; sl@0: TRAP(errCode, iDevice->WriteStream().WriteUint8L((TUint8) aFillRule)); sl@0: return KErrNone; sl@0: } sl@0: sl@0: EXPORT_C TInt CMetafileGc::DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TInt errCode = 0; sl@0: TRAP(errCode, iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawPolygon2; sl@0: TRAP(errCode, iDevice->WriteStream().WriteInt32L(aNumPoints)); sl@0: TPoint *p=(TPoint*) aPointList,*pEnd=p+aNumPoints; sl@0: for (; pWriteStream() << *p; sl@0: TRAP(errCode, iDevice->WriteStream().WriteUint8L((TUint8) aFillRule)); sl@0: return KErrNone; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DrawBitmap(const TPoint& aTopLeft,const CFbsBitmap* aSource) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TInt errCode = 0; sl@0: TRAP(errCode, iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawBitmap1; sl@0: iDevice->WriteStream() << aTopLeft; sl@0: TRAP(errCode, ExternalizeBitmapL(aSource)); sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DrawBitmap(const TRect& aDestRect,const CFbsBitmap* aSource) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TInt errCode = 0; sl@0: TRAP(errCode, iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawBitmap2; sl@0: iDevice->WriteStream() << aDestRect; sl@0: TRAP(errCode, ExternalizeBitmapL(aSource)); sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DrawBitmap(const TRect& aDestRect,const CFbsBitmap* aSource,const TRect& aSourceRect) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TInt errCode = 0; sl@0: TRAP(errCode, iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawBitmap3; sl@0: iDevice->WriteStream() << aDestRect; sl@0: TRAP(errCode, ExternalizeBitmapL(aSource)); sl@0: iDevice->WriteStream() << aSourceRect; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DrawBitmapMasked(const TRect& /*aDestRect*/,const CFbsBitmap* /*aBitmap*/,const TRect& /*aSourceRect*/,const CFbsBitmap* /*aMaskBitmap*/,TBool /*aInvertMask*/) sl@0: {} sl@0: sl@0: EXPORT_C void CMetafileGc::DrawBitmapMasked(const TRect& /*aDestRect*/,const CWsBitmap* /*aBitmap*/,const TRect& /*aSourceRect*/,const CWsBitmap* /*aMaskBitmap*/,TBool /*aInvertMask*/) sl@0: {} sl@0: sl@0: EXPORT_C void CMetafileGc::MapColors(const TRect& /*aRect*/,const TRgb* /*aColors*/,TInt /*aNumPairs*/,TBool /*aMapForwards*/) sl@0: {} sl@0: sl@0: EXPORT_C TInt CMetafileGc::SetClippingRegion(const TRegion &/*aRegion*/) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::CancelClippingRegion() sl@0: {} sl@0: sl@0: EXPORT_C void CMetafileGc::DrawTextVertical(const TDesC& /*aText*/,const TPoint& /*aPos*/,TBool /*aUp*/) sl@0: {} sl@0: sl@0: EXPORT_C void CMetafileGc::DrawTextVertical(const TDesC& /*aText*/,const TRect& /*aBox*/,TInt /*aBaselineOffset*/,TBool /*aUp*/,TTextAlign /*aVert*/,TInt /*aMargin*/) sl@0: {} sl@0: sl@0: EXPORT_C TInt CMetafileGc::AlphaBlendBitmaps(const TPoint& /*aDestPt*/, const CFbsBitmap* /*aSrcBmp*/, const TRect& /*aSrcRect*/, const CFbsBitmap* /*aAlphaBmp*/, const TPoint& /*aAlphaPt*/) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: sl@0: EXPORT_C TInt CMetafileGc::AlphaBlendBitmaps(const TPoint& /*aDestPt*/, const CWsBitmap* /*aSrcBmp*/, const TRect& /*aSrcRect*/, const CWsBitmap* /*aAlphaBmp*/, const TPoint& /*aAlphaPt*/) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CMetafileGc::DrawText(const TDesC& aString,const TPoint& aPosition) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TRAP_IGNORE(iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawText1; sl@0: iDevice->WriteStream() << aString; sl@0: iDevice->WriteStream() << aPosition; sl@0: } sl@0: sl@0: EXPORT_C void CMetafileGc::DrawText(const TDesC& aString,const TRect& aBox,TInt aBaselineOffset,TTextAlign aHoriz,TInt aLeftMrg) sl@0: { sl@0: // TRAP and ignore the ERROR code due to this beeing a non-leaving method sl@0: TInt errCode = 0; sl@0: TRAP(errCode, iDevice->UseGcL(iIndex)); sl@0: iDevice->WriteStream() << EDrawText2; sl@0: iDevice->WriteStream() << aString; sl@0: iDevice->WriteStream() << aBox; sl@0: TRAP(errCode, iDevice->WriteStream().WriteInt32L(aBaselineOffset)); sl@0: TRAP(errCode, iDevice->WriteStream().WriteUint8L((TUint8) aHoriz)); sl@0: TRAP(errCode, iDevice->WriteStream().WriteInt32L(aLeftMrg)); sl@0: } sl@0: sl@0: void CMetafileGc::ExternalizeBitmapL(const CFbsBitmap* aSource) sl@0: { sl@0: CFbsBitmap* bitmap=new(ELeave) CFbsBitmap; sl@0: CleanupStack::PushL(bitmap); sl@0: User::LeaveIfError(bitmap->Create(aSource->SizeInPixels(),iDevice->DisplayMode())); sl@0: CFbsBitmapDevice* bitmapdevice=CFbsBitmapDevice::NewL(bitmap); sl@0: CleanupStack::PushL(bitmapdevice); sl@0: CFbsBitGc* gc; sl@0: User::LeaveIfError(bitmapdevice->CreateContext((CGraphicsContext*&) gc)); sl@0: CleanupStack::PushL(gc); sl@0: gc->BitBlt(TPoint(0,0),aSource); sl@0: bitmap->ExternalizeL(iDevice->WriteStream()); sl@0: CleanupStack::PopAndDestroy(3); sl@0: } sl@0: sl@0: EXPORT_C CMetafilePlayback::CMetafilePlayback(CGraphicsDevice* aDevice): sl@0: iDevice(aDevice) sl@0: { sl@0: __DECLARE_NAME(_S("CMetafilePlayback")); sl@0: } sl@0: sl@0: EXPORT_C CMetafilePlayback* CMetafilePlayback::NewL(CGraphicsDevice* aDevice) sl@0: { sl@0: CMetafilePlayback* playback=new(ELeave) CMetafilePlayback(aDevice); sl@0: return playback; sl@0: } sl@0: sl@0: EXPORT_C CMetafilePlayback::~CMetafilePlayback() sl@0: { sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CMetafilePlayback::DrawL(RReadStream& aReadStream) sl@0: { sl@0: CArrayPtrFlat* gclist=new(ELeave) CArrayPtrFlat(8); sl@0: CleanupStack::PushL(gclist); sl@0: CFontStack* fontstack = CFontStack::NewL(iDevice); sl@0: CleanupStack::PushL(fontstack); sl@0: CArrayFixFlat* pointlist=new(ELeave) CArrayFixFlat(8); sl@0: CleanupStack::PushL(pointlist); sl@0: CFbsBitmap* bitmap=new(ELeave) CFbsBitmap; sl@0: CleanupStack::PushL(bitmap); sl@0: TSize kpixelsizeintwips; sl@0: aReadStream >> kpixelsizeintwips; sl@0: TGraphicsContextCommandCode code; sl@0: TInt gcindex=0; sl@0: do sl@0: { sl@0: code = (TGraphicsContextCommandCode) aReadStream.ReadUint8L(); sl@0: switch (code) sl@0: { sl@0: case EUseGc: sl@0: { sl@0: TInt gcindex=aReadStream.ReadInt32L(); sl@0: if (gcindex>=gclist->Count()) sl@0: { sl@0: for (TInt i=gclist->Count(); i<=gcindex; i++) sl@0: { sl@0: CGraphicsContext* gc; sl@0: User::LeaveIfError(iDevice->CreateContext(gc)); sl@0: CleanupStack::PushL(gc); sl@0: gclist->AppendL(gc); sl@0: } sl@0: } sl@0: sl@0: break; sl@0: } sl@0: case EEndOfStream: sl@0: { sl@0: break; sl@0: } sl@0: case ESetOrigin: sl@0: { sl@0: TPoint pos; sl@0: aReadStream >> pos; sl@0: (*gclist)[gcindex]->SetOrigin(pos); sl@0: break; sl@0: } sl@0: case ESetDrawMode: sl@0: { sl@0: CGraphicsContext::TDrawMode drawingmode; sl@0: drawingmode = (CGraphicsContext::TDrawMode) aReadStream.ReadUint8L(); sl@0: (*gclist)[gcindex]->SetDrawMode(drawingmode); sl@0: break; sl@0: } sl@0: case ESetClippingRect: sl@0: { sl@0: TRect rect; sl@0: aReadStream >> rect; sl@0: (*gclist)[gcindex]->SetClippingRect(rect); sl@0: break; sl@0: } sl@0: case ECancelClippingRect: sl@0: { sl@0: (*gclist)[gcindex]->CancelClippingRect(); sl@0: break; sl@0: } sl@0: case EReset: sl@0: { sl@0: (*gclist)[gcindex]->CancelClippingRect(); sl@0: break; sl@0: } sl@0: case EUseFont: sl@0: { sl@0: TFontSpec spec; sl@0: aReadStream >> spec; sl@0: aReadStream.ReadInt32L(); // height in pixels sl@0: aReadStream.ReadInt32L(); // baseline offset in pixels sl@0: spec.iHeight=((spec.iHeight*iDevice->VerticalPixelsToTwips(1000))+(kpixelsizeintwips.iHeight/2))/kpixelsizeintwips.iHeight; sl@0: CFont* font; sl@0: User::LeaveIfError(iDevice->GetNearestFontToDesignHeightInTwips(font,spec)); sl@0: fontstack->AddFontL(font); sl@0: (*gclist)[gcindex]->UseFont(font); sl@0: break; sl@0: } sl@0: case EDiscardFont: sl@0: { sl@0: (*gclist)[gcindex]->DiscardFont(); sl@0: break; sl@0: } sl@0: case ESetUnderlineStyle: sl@0: { sl@0: TFontUnderline underlinestyle; sl@0: underlinestyle = (TFontUnderline) aReadStream.ReadUint8L(); sl@0: (*gclist)[gcindex]->SetUnderlineStyle(underlinestyle); sl@0: break; sl@0: } sl@0: case ESetStrikethroughStyle: sl@0: { sl@0: TFontStrikethrough strikethroughstyle; sl@0: strikethroughstyle = (TFontStrikethrough) aReadStream.ReadUint8L(); sl@0: (*gclist)[gcindex]->SetStrikethroughStyle(strikethroughstyle); sl@0: break; sl@0: } sl@0: case ESetWordJustification: sl@0: { sl@0: TInt excesswidth,numgaps; sl@0: excesswidth=aReadStream.ReadInt32L(); sl@0: numgaps=aReadStream.ReadInt32L(); sl@0: (*gclist)[gcindex]->SetWordJustification(excesswidth,numgaps); sl@0: break; sl@0: } sl@0: case ESetCharJustification: sl@0: { sl@0: TInt excesswidth,numgaps; sl@0: excesswidth=aReadStream.ReadInt32L(); sl@0: numgaps=aReadStream.ReadInt32L(); sl@0: (*gclist)[gcindex]->SetCharJustification(excesswidth,numgaps); sl@0: break; sl@0: } sl@0: case ESetPenColor: sl@0: { sl@0: TRgb color; sl@0: aReadStream >> color; sl@0: (*gclist)[gcindex]->SetPenColor(color); sl@0: break; sl@0: } sl@0: case ESetPenStyle: sl@0: { sl@0: CGraphicsContext::TPenStyle penstyle; sl@0: penstyle=(CGraphicsContext::TPenStyle) aReadStream.ReadUint8L(); sl@0: (*gclist)[gcindex]->SetPenStyle(penstyle); sl@0: break; sl@0: } sl@0: case ESetPenSize: sl@0: { sl@0: TSize size; sl@0: aReadStream >> size; sl@0: (*gclist)[gcindex]->SetPenSize(size); sl@0: break; sl@0: } sl@0: case ESetBrushColor: sl@0: { sl@0: TRgb color; sl@0: aReadStream >> color; sl@0: (*gclist)[gcindex]->SetBrushColor(color); sl@0: break; sl@0: } sl@0: case ESetBrushStyle: sl@0: { sl@0: CGraphicsContext::TBrushStyle brushstyle; sl@0: brushstyle = (CGraphicsContext::TBrushStyle) aReadStream.ReadUint8L(); sl@0: (*gclist)[gcindex]->SetBrushStyle(brushstyle); sl@0: break; sl@0: } sl@0: case ESetBrushOrigin: sl@0: { sl@0: TPoint origin; sl@0: aReadStream >> origin; sl@0: (*gclist)[gcindex]->SetBrushOrigin(origin); sl@0: break; sl@0: } sl@0: case EUseBrushPattern: sl@0: { sl@0: bitmap->InternalizeL(aReadStream); sl@0: (*gclist)[gcindex]->UseBrushPattern(bitmap); sl@0: bitmap->Reset(); sl@0: break; sl@0: } sl@0: case EDiscardBrushPattern: sl@0: { sl@0: (*gclist)[gcindex]->DiscardBrushPattern(); sl@0: break; sl@0: } sl@0: case EMoveTo: sl@0: { sl@0: TPoint point; sl@0: aReadStream >> point; sl@0: (*gclist)[gcindex]->MoveTo(point); sl@0: break; sl@0: } sl@0: case EMoveBy: sl@0: { sl@0: TPoint vector; sl@0: aReadStream >> vector; sl@0: (*gclist)[gcindex]->MoveBy(vector); sl@0: break; sl@0: } sl@0: case EPlot: sl@0: { sl@0: TPoint point; sl@0: aReadStream >> point; sl@0: (*gclist)[gcindex]->Plot(point); sl@0: break; sl@0: } sl@0: case EDrawArc: sl@0: { sl@0: TRect rect; sl@0: aReadStream >> rect; sl@0: TPoint start,end; sl@0: aReadStream >> start; sl@0: aReadStream >> end; sl@0: (*gclist)[gcindex]->DrawArc(rect,start,end); sl@0: break; sl@0: } sl@0: case EDrawLine: sl@0: { sl@0: TPoint point1,point2; sl@0: aReadStream >> point1; sl@0: aReadStream >> point2; sl@0: (*gclist)[gcindex]->DrawLine(point1,point2); sl@0: break; sl@0: } sl@0: case EDrawLineTo: sl@0: { sl@0: TPoint point; sl@0: aReadStream >> point; sl@0: (*gclist)[gcindex]->DrawLineTo(point); sl@0: break; sl@0: } sl@0: case EDrawLineBy: sl@0: { sl@0: TPoint vector; sl@0: aReadStream >> vector; sl@0: (*gclist)[gcindex]->DrawLineBy(vector); sl@0: break; sl@0: } sl@0: case EDrawPolyLine1: sl@0: { sl@0: } sl@0: case EDrawPolyLine2: sl@0: { sl@0: TInt numpoints; sl@0: numpoints=aReadStream.ReadInt32L(); sl@0: for (TInt i=0; i> point; sl@0: pointlist->AppendL(point); sl@0: } sl@0: (*gclist)[gcindex]->DrawPolyLine(pointlist); sl@0: pointlist->Reset(); sl@0: break; sl@0: } sl@0: case EDrawPie: sl@0: { sl@0: TRect rect; sl@0: aReadStream >> rect; sl@0: TPoint start,end; sl@0: aReadStream >> start; sl@0: aReadStream >> end; sl@0: (*gclist)[gcindex]->DrawPie(rect,start,end); sl@0: break; sl@0: } sl@0: case EDrawEllipse: sl@0: { sl@0: TRect rect; sl@0: aReadStream >> rect; sl@0: (*gclist)[gcindex]->DrawEllipse(rect); sl@0: break; sl@0: } sl@0: case EDrawRect: sl@0: { sl@0: TRect rect; sl@0: aReadStream >> rect; sl@0: (*gclist)[gcindex]->DrawRect(rect); sl@0: break; sl@0: } sl@0: case EDrawRoundRect: sl@0: { sl@0: TRect rect; sl@0: aReadStream >> rect; sl@0: TSize cornersize; sl@0: aReadStream >> cornersize; sl@0: (*gclist)[gcindex]->DrawRoundRect(rect,cornersize); sl@0: break; sl@0: } sl@0: case EDrawPolygon1: sl@0: { sl@0: } sl@0: case EDrawPolygon2: sl@0: { sl@0: TInt numpoints; sl@0: numpoints=aReadStream.ReadInt32L(); sl@0: for (TInt i=0; i> point; sl@0: pointlist->AppendL(point); sl@0: } sl@0: CGraphicsContext::TFillRule fillrule=(CGraphicsContext::TFillRule) aReadStream.ReadUint8L(); sl@0: (*gclist)[gcindex]->DrawPolygon(pointlist,fillrule); sl@0: pointlist->Reset(); sl@0: break; sl@0: } sl@0: case EDrawBitmap1: sl@0: { sl@0: TPoint topleft; sl@0: aReadStream >> topleft; sl@0: bitmap->InternalizeL(aReadStream); sl@0: (*gclist)[gcindex]->DrawBitmap(topleft,bitmap); sl@0: bitmap->Reset(); sl@0: break; sl@0: } sl@0: case EDrawBitmap2: sl@0: { sl@0: TRect destrect; sl@0: aReadStream >> destrect; sl@0: bitmap->InternalizeL(aReadStream); sl@0: (*gclist)[gcindex]->DrawBitmap(destrect,bitmap); sl@0: bitmap->Reset(); sl@0: break; sl@0: } sl@0: case EDrawBitmap3: sl@0: { sl@0: TRect destrect; sl@0: aReadStream >> destrect; sl@0: bitmap->InternalizeL(aReadStream); sl@0: TRect sourcerect; sl@0: aReadStream >> sourcerect; sl@0: (*gclist)[gcindex]->DrawBitmap(destrect,bitmap,sourcerect); sl@0: bitmap->Reset(); sl@0: break; sl@0: } sl@0: case EDrawText1: sl@0: { sl@0: HBufC* string=HBufC::NewLC(aReadStream,KMaxTInt); sl@0: TPoint position; sl@0: aReadStream >> position; sl@0: (*gclist)[gcindex]->DrawText(*string,position); sl@0: CleanupStack::PopAndDestroy(); sl@0: break; sl@0: } sl@0: case EDrawText2: sl@0: { sl@0: HBufC* string=HBufC::NewLC(aReadStream,KMaxTInt); sl@0: TRect box; sl@0: aReadStream >> box; sl@0: TInt baselineoffset=aReadStream.ReadInt32L(); sl@0: CGraphicsContext::TTextAlign horiz=(CGraphicsContext::TTextAlign) aReadStream.ReadUint8L(); sl@0: TInt leftmrg=aReadStream.ReadInt32L(); sl@0: (*gclist)[gcindex]->DrawText(*string,box,baselineoffset,horiz,leftmrg); sl@0: CleanupStack::PopAndDestroy(); sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: while (code!=EEndOfStream); sl@0: CleanupStack::PopAndDestroy(gclist->Count()+4); sl@0: }