Update contrib.
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 NONSHARABLE_CLASS(CFontStack) : public CBase
23 CFontStack(CGraphicsDevice* aDevice);
25 static CFontStack* NewL(CGraphicsDevice* aDevice);
27 void AddFontL(CFont* aFont);
29 CGraphicsDevice* iDevice;
30 CArrayPtrFlat<CFont>* iFontList;
33 CFontStack::CFontStack(CGraphicsDevice* aDevice):
37 __DECLARE_NAME(_S("CFontStack"));
40 CFontStack* CFontStack::NewL(CGraphicsDevice* aDevice)
42 CFontStack* fontstack=new(ELeave) CFontStack(aDevice);
43 CleanupStack::PushL(fontstack);
44 fontstack->iFontList=new(ELeave) CArrayPtrFlat<CFont>(8);
49 CFontStack::~CFontStack()
53 TInt count=iFontList->Count();
54 for (TInt i=0; i<count; i++)
55 iDevice->ReleaseFont((*iFontList)[i]);
60 void CFontStack::AddFontL(CFont* aFont)
62 TRAPD(ret,iFontList->AppendL(aFont));
65 iDevice->ReleaseFont(aFont);
70 enum TGraphicsContextCommandCode
72 EUseGc, // Not gc command
83 ESetStrikethroughStyle,
84 ESetWordJustification,
85 ESetCharJustification,
116 inline RWriteStream& operator<<(RWriteStream& aStream,TGraphicsContextCommandCode aCommandCode)
118 aStream.WriteUint8L(TUint8(aCommandCode));
122 EXPORT_C CMetafileDevice::CMetafileDevice(CGraphicsDevice* aDevice):
126 iRealDevice(aDevice),
129 __DECLARE_NAME(_S("CMetafileDevice"));
132 EXPORT_C CMetafileDevice* CMetafileDevice::NewL(CGraphicsDevice* aDevice)
134 CMetafileDevice* device=new(ELeave) CMetafileDevice(aDevice);
138 EXPORT_C CMetafileDevice::~CMetafileDevice()
142 EXPORT_C TInt CMetafileDevice::HorizontalTwipsToPixels(TInt aTwips) const
144 return iRealDevice->HorizontalTwipsToPixels(aTwips);
147 EXPORT_C TInt CMetafileDevice::VerticalTwipsToPixels(TInt aTwips) const
149 return iRealDevice->VerticalTwipsToPixels(aTwips);
152 EXPORT_C TInt CMetafileDevice::HorizontalPixelsToTwips(TInt aPixels) const
154 return iRealDevice->HorizontalPixelsToTwips(aPixels);
157 EXPORT_C TInt CMetafileDevice::VerticalPixelsToTwips(TInt aPixels) const
159 return iRealDevice->VerticalPixelsToTwips(aPixels);
162 EXPORT_C TInt CMetafileDevice::GetNearestFontInTwips(CFont*& aFont,const TFontSpec& aFontSpec)
164 return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
167 EXPORT_C TInt CMetafileDevice::GetNearestFontToDesignHeightInTwips(CFont*& aFont,const TFontSpec& aFontSpec)
169 return iRealDevice->GetNearestFontToDesignHeightInTwips(aFont,aFontSpec);
172 EXPORT_C TInt CMetafileDevice::GetNearestFontToMaxHeightInTwips(CFont*& aFont,const TFontSpec& aFontSpec, TInt aMaxHeight)
174 return iRealDevice->GetNearestFontToMaxHeightInTwips(aFont, aFontSpec, aMaxHeight);
177 EXPORT_C void CMetafileDevice::ReleaseFont(CFont* aFont)
179 iRealDevice->ReleaseFont(aFont);
182 EXPORT_C TDisplayMode CMetafileDevice::DisplayMode() const
184 return iRealDevice->DisplayMode();
187 EXPORT_C TSize CMetafileDevice::SizeInPixels() const
189 return iRealDevice->SizeInPixels();
192 EXPORT_C TSize CMetafileDevice::SizeInTwips() const
194 return iRealDevice->SizeInTwips();
197 EXPORT_C TInt CMetafileDevice::CreateContext(CGraphicsContext*& aGC)
199 CMetafileGc* gc=new CMetafileGc(this,iGcCount);
207 EXPORT_C TInt CMetafileDevice::NumTypefaces() const
209 return iRealDevice->NumTypefaces();
212 EXPORT_C void CMetafileDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const
214 iRealDevice->TypefaceSupport(aTypefaceSupport,aTypefaceIndex);
217 EXPORT_C TInt CMetafileDevice::FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const
219 return iRealDevice->FontHeightInTwips(aTypefaceIndex,aHeightIndex);
222 EXPORT_C void CMetafileDevice::PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const
224 iRealDevice->PaletteAttributes(aModifiable,aNumEntries);
227 EXPORT_C void CMetafileDevice::SetPalette(CPalette* aPalette)
229 iRealDevice->SetPalette(aPalette);
232 EXPORT_C TInt CMetafileDevice::GetPalette(CPalette*& aPalette) const
234 return iRealDevice->GetPalette(aPalette);
237 EXPORT_C void CMetafileDevice::UseGcL(TInt aGcIndex)
239 if (iGcIndex!=aGcIndex)
242 *iWriteStream << EUseGc;
243 iWriteStream->WriteInt32L(iGcIndex);
247 EXPORT_C void CMetafileDevice::StartOutputStreamL(RWriteStream& aStream) // Returns error code
249 iWriteStream=&aStream;
250 TSize size(HorizontalPixelsToTwips(1000),VerticalPixelsToTwips(1000));
251 *iWriteStream << size;
254 EXPORT_C void CMetafileDevice::EndOfStreamL() // Returns error code
256 *iWriteStream << EEndOfStream;
259 EXPORT_C RWriteStream& CMetafileDevice::WriteStream()
261 return *iWriteStream;
264 EXPORT_C CMetafileGc::CMetafileGc(CMetafileDevice* aDevice,TInt anIndex):
271 EXPORT_C CMetafileGc::~CMetafileGc()
275 EXPORT_C CGraphicsDevice* CMetafileGc::Device() const
280 EXPORT_C void CMetafileGc::SetOrigin(const TPoint& aPos)
282 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
283 TRAP_IGNORE(iDevice->UseGcL(iIndex));
284 iDevice->WriteStream() << ESetOrigin;
285 iDevice->WriteStream() << aPos;
288 EXPORT_C void CMetafileGc::SetDrawMode(TDrawMode aDrawingMode)
291 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
292 TRAP_IGNORE(iDevice->UseGcL(iIndex));
293 iDevice->WriteStream() << ESetDrawMode;
294 TRAP(errCode, iDevice->WriteStream().WriteUint8L((TUint8) aDrawingMode));
297 EXPORT_C void CMetafileGc::SetClippingRect(const TRect& aRect)
299 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
300 TRAP_IGNORE(iDevice->UseGcL(iIndex));
301 iDevice->WriteStream() << ESetClippingRect;
302 iDevice->WriteStream() << aRect;
305 EXPORT_C void CMetafileGc::CancelClippingRect()
307 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
308 TRAP_IGNORE(iDevice->UseGcL(iIndex));
309 iDevice->WriteStream() << ECancelClippingRect;
312 EXPORT_C void CMetafileGc::Reset()
314 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
315 TRAP_IGNORE(iDevice->UseGcL(iIndex));
316 iDevice->WriteStream() << EReset;
319 EXPORT_C void CMetafileGc::UseFont(const CFont* aFont)
321 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
323 TRAP(errCode, iDevice->UseGcL(iIndex));
324 iDevice->WriteStream() << EUseFont;
325 iDevice->WriteStream() << aFont->FontSpecInTwips();
326 TRAP(errCode, iDevice->WriteStream().WriteInt32L(aFont->HeightInPixels()));
327 TRAP(errCode, iDevice->WriteStream().WriteInt32L(aFont->BaselineOffsetInPixels()));
330 EXPORT_C void CMetafileGc::DiscardFont()
332 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
333 TRAP_IGNORE(iDevice->UseGcL(iIndex));
334 iDevice->WriteStream() << EDiscardFont;
337 EXPORT_C void CMetafileGc::SetUnderlineStyle(TFontUnderline aUnderlineStyle)
339 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
341 TRAP(errCode, iDevice->UseGcL(iIndex));
342 iDevice->WriteStream() << ESetUnderlineStyle;
343 TRAP(errCode, iDevice->WriteStream().WriteUint8L((TUint8) aUnderlineStyle));
346 EXPORT_C void CMetafileGc::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle)
348 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
350 TRAP(errCode, iDevice->UseGcL(iIndex));
351 iDevice->WriteStream() << ESetStrikethroughStyle;
352 TRAP(errCode, iDevice->WriteStream().WriteUint8L((TUint8) aStrikethroughStyle));
355 EXPORT_C void CMetafileGc::SetWordJustification(TInt aExcessWidth,TInt aNumGaps)
357 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
359 TRAP(errCode, iDevice->UseGcL(iIndex));
360 iDevice->WriteStream() << ESetWordJustification;
361 TRAP(errCode, iDevice->WriteStream().WriteInt32L(aExcessWidth));
362 TRAP(errCode, iDevice->WriteStream().WriteInt32L(aNumGaps));
365 EXPORT_C void CMetafileGc::SetCharJustification(TInt aExcessWidth,TInt aNumChars)
367 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
369 TRAP(errCode, iDevice->UseGcL(iIndex));
370 iDevice->WriteStream() << ESetCharJustification;
371 TRAP(errCode, iDevice->WriteStream().WriteInt32L(aExcessWidth));
372 TRAP(errCode, iDevice->WriteStream().WriteInt32L(aNumChars));
375 EXPORT_C void CMetafileGc::SetPenColor(const TRgb& aColor)
377 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
378 TRAP_IGNORE(iDevice->UseGcL(iIndex));
379 iDevice->WriteStream() << ESetPenColor;
380 iDevice->WriteStream() << aColor;
383 EXPORT_C void CMetafileGc::SetPenStyle(TPenStyle aPenStyle)
385 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
387 TRAP(errCode, iDevice->UseGcL(iIndex));
388 iDevice->WriteStream() << ESetPenStyle;
389 TRAP(errCode, iDevice->WriteStream().WriteUint8L((TUint8) aPenStyle));
392 EXPORT_C void CMetafileGc::SetPenSize(const TSize& aSize)
394 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
395 TRAP_IGNORE(iDevice->UseGcL(iIndex));
396 iDevice->WriteStream() << ESetPenSize;
397 iDevice->WriteStream() << aSize;
400 EXPORT_C void CMetafileGc::SetBrushColor(const TRgb& aColor)
402 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
403 TRAP_IGNORE( iDevice->UseGcL(iIndex));
404 iDevice->WriteStream() << ESetBrushColor;
405 iDevice->WriteStream() << aColor;
408 EXPORT_C void CMetafileGc::SetBrushStyle(TBrushStyle aBrushStyle)
410 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
412 TRAP(errCode, iDevice->UseGcL(iIndex));
413 iDevice->WriteStream() << ESetBrushStyle;
414 TRAP(errCode, iDevice->WriteStream().WriteUint8L((TUint8) aBrushStyle));
417 EXPORT_C void CMetafileGc::SetBrushOrigin(const TPoint& aOrigin)
419 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
420 TRAP_IGNORE(iDevice->UseGcL(iIndex));
421 iDevice->WriteStream() << ESetBrushOrigin;
422 iDevice->WriteStream() << aOrigin;
425 EXPORT_C void CMetafileGc::UseBrushPattern(const CFbsBitmap* aBitmap)
427 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
429 TRAP(errCode, iDevice->UseGcL(iIndex));
430 iDevice->WriteStream() << EUseBrushPattern;
431 TRAP(errCode, aBitmap->ExternalizeL(iDevice->WriteStream()));
434 EXPORT_C void CMetafileGc::DiscardBrushPattern()
436 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
437 TRAP_IGNORE(iDevice->UseGcL(iIndex));
438 iDevice->WriteStream() << EDiscardBrushPattern;
441 EXPORT_C void CMetafileGc::MoveTo(const TPoint& aPoint)
443 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
444 TRAP_IGNORE(iDevice->UseGcL(iIndex));
445 iDevice->WriteStream() << EMoveTo;
446 iDevice->WriteStream() << aPoint;
449 EXPORT_C void CMetafileGc::MoveBy(const TPoint& aVector)
451 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
452 TRAP_IGNORE(iDevice->UseGcL(iIndex));
453 iDevice->WriteStream() << EMoveBy;
454 iDevice->WriteStream() << aVector;
457 EXPORT_C void CMetafileGc::Plot(const TPoint& aPoint)
459 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
460 TRAP_IGNORE(iDevice->UseGcL(iIndex));
461 iDevice->WriteStream() << EPlot;
462 iDevice->WriteStream() << aPoint;
465 EXPORT_C void CMetafileGc::DrawArc(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd)
467 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
468 TRAP_IGNORE(iDevice->UseGcL(iIndex));
469 iDevice->WriteStream() << EDrawArc;
470 iDevice->WriteStream() << aRect;
471 iDevice->WriteStream() << aStart;
472 iDevice->WriteStream() << aEnd;
475 EXPORT_C void CMetafileGc::DrawLine(const TPoint& aPoint1,const TPoint& aPoint2)
477 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
478 TRAP_IGNORE(iDevice->UseGcL(iIndex));
479 iDevice->WriteStream() << EDrawLine;
480 iDevice->WriteStream() << aPoint1;
481 iDevice->WriteStream() << aPoint2;
484 EXPORT_C void CMetafileGc::DrawLineTo(const TPoint& aPoint)
486 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
487 TRAP_IGNORE(iDevice->UseGcL(iIndex));
488 iDevice->WriteStream() << EDrawLineTo;
489 iDevice->WriteStream() << aPoint;
492 EXPORT_C void CMetafileGc::DrawLineBy(const TPoint& aVector)
494 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
495 TRAP_IGNORE(iDevice->UseGcL(iIndex));
496 iDevice->WriteStream() << EDrawLineBy;
497 iDevice->WriteStream() << aVector;
500 EXPORT_C void CMetafileGc::DrawPolyLine(const CArrayFix<TPoint>* aPointList)
502 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
504 TRAP(errCode, iDevice->UseGcL(iIndex));
505 iDevice->WriteStream() << EDrawPolyLine1;
507 TInt numpoints=aPointList->Count();
508 TRAP(errCode, iDevice->WriteStream().WriteInt32L(numpoints));
509 for (TInt i=0; i<numpoints; i++)
510 iDevice->WriteStream() << (*aPointList)[i];
513 EXPORT_C void CMetafileGc::DrawPolyLine(const TPoint* aPointList,TInt aNumPoints)
515 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
517 TRAP(errCode, iDevice->UseGcL(iIndex));
518 iDevice->WriteStream() << EDrawPolyLine2;
519 TRAP(errCode, iDevice->WriteStream().WriteInt32L(aNumPoints));
520 TPoint *p=(TPoint*) aPointList,*pEnd=p+aNumPoints;
522 iDevice->WriteStream() << *p;
525 EXPORT_C void CMetafileGc::DrawPie(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd)
527 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
528 TRAP_IGNORE(iDevice->UseGcL(iIndex));
529 iDevice->WriteStream() << EDrawPie;
530 iDevice->WriteStream() << aRect;
531 iDevice->WriteStream() << aStart;
532 iDevice->WriteStream() << aEnd;
535 EXPORT_C void CMetafileGc::DrawEllipse(const TRect& aRect)
537 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
538 TRAP_IGNORE(iDevice->UseGcL(iIndex));
539 iDevice->WriteStream() << EDrawEllipse;
540 iDevice->WriteStream() << aRect;
543 EXPORT_C void CMetafileGc::DrawRect(const TRect& aRect)
545 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
546 TRAP_IGNORE(iDevice->UseGcL(iIndex));
547 iDevice->WriteStream() << EDrawRect;
548 iDevice->WriteStream() << aRect;
551 EXPORT_C void CMetafileGc::DrawRoundRect(const TRect& aRect,const TSize& aCornerSize)
553 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
554 TRAP_IGNORE(iDevice->UseGcL(iIndex));
555 iDevice->WriteStream() << EDrawRoundRect;
556 iDevice->WriteStream() << aRect;
557 iDevice->WriteStream() << aCornerSize;
560 EXPORT_C TInt CMetafileGc::DrawPolygon(const CArrayFix<TPoint>* aPointList,TFillRule aFillRule)
562 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
564 TRAP(errCode, iDevice->UseGcL(iIndex));
565 iDevice->WriteStream() << EDrawPolygon1;
566 TInt numpoints=aPointList->Count();
567 TRAP(errCode, iDevice->WriteStream().WriteInt32L(numpoints));
568 for (TInt i=0; i<numpoints; i++)
569 iDevice->WriteStream() << (*aPointList)[i];
570 TRAP(errCode, iDevice->WriteStream().WriteUint8L((TUint8) aFillRule));
574 EXPORT_C TInt CMetafileGc::DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule)
576 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
578 TRAP(errCode, iDevice->UseGcL(iIndex));
579 iDevice->WriteStream() << EDrawPolygon2;
580 TRAP(errCode, iDevice->WriteStream().WriteInt32L(aNumPoints));
581 TPoint *p=(TPoint*) aPointList,*pEnd=p+aNumPoints;
583 iDevice->WriteStream() << *p;
584 TRAP(errCode, iDevice->WriteStream().WriteUint8L((TUint8) aFillRule));
588 EXPORT_C void CMetafileGc::DrawBitmap(const TPoint& aTopLeft,const CFbsBitmap* aSource)
590 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
592 TRAP(errCode, iDevice->UseGcL(iIndex));
593 iDevice->WriteStream() << EDrawBitmap1;
594 iDevice->WriteStream() << aTopLeft;
595 TRAP(errCode, ExternalizeBitmapL(aSource));
598 EXPORT_C void CMetafileGc::DrawBitmap(const TRect& aDestRect,const CFbsBitmap* aSource)
600 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
602 TRAP(errCode, iDevice->UseGcL(iIndex));
603 iDevice->WriteStream() << EDrawBitmap2;
604 iDevice->WriteStream() << aDestRect;
605 TRAP(errCode, ExternalizeBitmapL(aSource));
608 EXPORT_C void CMetafileGc::DrawBitmap(const TRect& aDestRect,const CFbsBitmap* aSource,const TRect& aSourceRect)
610 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
612 TRAP(errCode, iDevice->UseGcL(iIndex));
613 iDevice->WriteStream() << EDrawBitmap3;
614 iDevice->WriteStream() << aDestRect;
615 TRAP(errCode, ExternalizeBitmapL(aSource));
616 iDevice->WriteStream() << aSourceRect;
619 EXPORT_C void CMetafileGc::DrawBitmapMasked(const TRect& /*aDestRect*/,const CFbsBitmap* /*aBitmap*/,const TRect& /*aSourceRect*/,const CFbsBitmap* /*aMaskBitmap*/,TBool /*aInvertMask*/)
622 EXPORT_C void CMetafileGc::DrawBitmapMasked(const TRect& /*aDestRect*/,const CWsBitmap* /*aBitmap*/,const TRect& /*aSourceRect*/,const CWsBitmap* /*aMaskBitmap*/,TBool /*aInvertMask*/)
625 EXPORT_C void CMetafileGc::MapColors(const TRect& /*aRect*/,const TRgb* /*aColors*/,TInt /*aNumPairs*/,TBool /*aMapForwards*/)
628 EXPORT_C TInt CMetafileGc::SetClippingRegion(const TRegion &/*aRegion*/)
633 EXPORT_C void CMetafileGc::CancelClippingRegion()
636 EXPORT_C void CMetafileGc::DrawTextVertical(const TDesC& /*aText*/,const TPoint& /*aPos*/,TBool /*aUp*/)
639 EXPORT_C void CMetafileGc::DrawTextVertical(const TDesC& /*aText*/,const TRect& /*aBox*/,TInt /*aBaselineOffset*/,TBool /*aUp*/,TTextAlign /*aVert*/,TInt /*aMargin*/)
642 EXPORT_C TInt CMetafileGc::AlphaBlendBitmaps(const TPoint& /*aDestPt*/, const CFbsBitmap* /*aSrcBmp*/, const TRect& /*aSrcRect*/, const CFbsBitmap* /*aAlphaBmp*/, const TPoint& /*aAlphaPt*/)
647 EXPORT_C TInt CMetafileGc::AlphaBlendBitmaps(const TPoint& /*aDestPt*/, const CWsBitmap* /*aSrcBmp*/, const TRect& /*aSrcRect*/, const CWsBitmap* /*aAlphaBmp*/, const TPoint& /*aAlphaPt*/)
653 EXPORT_C void CMetafileGc::DrawText(const TDesC& aString,const TPoint& aPosition)
655 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
656 TRAP_IGNORE(iDevice->UseGcL(iIndex));
657 iDevice->WriteStream() << EDrawText1;
658 iDevice->WriteStream() << aString;
659 iDevice->WriteStream() << aPosition;
662 EXPORT_C void CMetafileGc::DrawText(const TDesC& aString,const TRect& aBox,TInt aBaselineOffset,TTextAlign aHoriz,TInt aLeftMrg)
664 // TRAP and ignore the ERROR code due to this beeing a non-leaving method
666 TRAP(errCode, iDevice->UseGcL(iIndex));
667 iDevice->WriteStream() << EDrawText2;
668 iDevice->WriteStream() << aString;
669 iDevice->WriteStream() << aBox;
670 TRAP(errCode, iDevice->WriteStream().WriteInt32L(aBaselineOffset));
671 TRAP(errCode, iDevice->WriteStream().WriteUint8L((TUint8) aHoriz));
672 TRAP(errCode, iDevice->WriteStream().WriteInt32L(aLeftMrg));
675 void CMetafileGc::ExternalizeBitmapL(const CFbsBitmap* aSource)
677 CFbsBitmap* bitmap=new(ELeave) CFbsBitmap;
678 CleanupStack::PushL(bitmap);
679 User::LeaveIfError(bitmap->Create(aSource->SizeInPixels(),iDevice->DisplayMode()));
680 CFbsBitmapDevice* bitmapdevice=CFbsBitmapDevice::NewL(bitmap);
681 CleanupStack::PushL(bitmapdevice);
683 User::LeaveIfError(bitmapdevice->CreateContext((CGraphicsContext*&) gc));
684 CleanupStack::PushL(gc);
685 gc->BitBlt(TPoint(0,0),aSource);
686 bitmap->ExternalizeL(iDevice->WriteStream());
687 CleanupStack::PopAndDestroy(3);
690 EXPORT_C CMetafilePlayback::CMetafilePlayback(CGraphicsDevice* aDevice):
693 __DECLARE_NAME(_S("CMetafilePlayback"));
696 EXPORT_C CMetafilePlayback* CMetafilePlayback::NewL(CGraphicsDevice* aDevice)
698 CMetafilePlayback* playback=new(ELeave) CMetafilePlayback(aDevice);
702 EXPORT_C CMetafilePlayback::~CMetafilePlayback()
707 EXPORT_C void CMetafilePlayback::DrawL(RReadStream& aReadStream)
709 CArrayPtrFlat<CGraphicsContext>* gclist=new(ELeave) CArrayPtrFlat<CGraphicsContext>(8);
710 CleanupStack::PushL(gclist);
711 CFontStack* fontstack = CFontStack::NewL(iDevice);
712 CleanupStack::PushL(fontstack);
713 CArrayFixFlat<TPoint>* pointlist=new(ELeave) CArrayFixFlat<TPoint>(8);
714 CleanupStack::PushL(pointlist);
715 CFbsBitmap* bitmap=new(ELeave) CFbsBitmap;
716 CleanupStack::PushL(bitmap);
717 TSize kpixelsizeintwips;
718 aReadStream >> kpixelsizeintwips;
719 TGraphicsContextCommandCode code;
723 code = (TGraphicsContextCommandCode) aReadStream.ReadUint8L();
728 TInt gcindex=aReadStream.ReadInt32L();
729 if (gcindex>=gclist->Count())
731 for (TInt i=gclist->Count(); i<=gcindex; i++)
733 CGraphicsContext* gc;
734 User::LeaveIfError(iDevice->CreateContext(gc));
735 CleanupStack::PushL(gc);
750 (*gclist)[gcindex]->SetOrigin(pos);
755 CGraphicsContext::TDrawMode drawingmode;
756 drawingmode = (CGraphicsContext::TDrawMode) aReadStream.ReadUint8L();
757 (*gclist)[gcindex]->SetDrawMode(drawingmode);
760 case ESetClippingRect:
764 (*gclist)[gcindex]->SetClippingRect(rect);
767 case ECancelClippingRect:
769 (*gclist)[gcindex]->CancelClippingRect();
774 (*gclist)[gcindex]->CancelClippingRect();
781 aReadStream.ReadInt32L(); // height in pixels
782 aReadStream.ReadInt32L(); // baseline offset in pixels
783 spec.iHeight=((spec.iHeight*iDevice->VerticalPixelsToTwips(1000))+(kpixelsizeintwips.iHeight/2))/kpixelsizeintwips.iHeight;
785 User::LeaveIfError(iDevice->GetNearestFontToDesignHeightInTwips(font,spec));
786 fontstack->AddFontL(font);
787 (*gclist)[gcindex]->UseFont(font);
792 (*gclist)[gcindex]->DiscardFont();
795 case ESetUnderlineStyle:
797 TFontUnderline underlinestyle;
798 underlinestyle = (TFontUnderline) aReadStream.ReadUint8L();
799 (*gclist)[gcindex]->SetUnderlineStyle(underlinestyle);
802 case ESetStrikethroughStyle:
804 TFontStrikethrough strikethroughstyle;
805 strikethroughstyle = (TFontStrikethrough) aReadStream.ReadUint8L();
806 (*gclist)[gcindex]->SetStrikethroughStyle(strikethroughstyle);
809 case ESetWordJustification:
811 TInt excesswidth,numgaps;
812 excesswidth=aReadStream.ReadInt32L();
813 numgaps=aReadStream.ReadInt32L();
814 (*gclist)[gcindex]->SetWordJustification(excesswidth,numgaps);
817 case ESetCharJustification:
819 TInt excesswidth,numgaps;
820 excesswidth=aReadStream.ReadInt32L();
821 numgaps=aReadStream.ReadInt32L();
822 (*gclist)[gcindex]->SetCharJustification(excesswidth,numgaps);
828 aReadStream >> color;
829 (*gclist)[gcindex]->SetPenColor(color);
834 CGraphicsContext::TPenStyle penstyle;
835 penstyle=(CGraphicsContext::TPenStyle) aReadStream.ReadUint8L();
836 (*gclist)[gcindex]->SetPenStyle(penstyle);
843 (*gclist)[gcindex]->SetPenSize(size);
849 aReadStream >> color;
850 (*gclist)[gcindex]->SetBrushColor(color);
855 CGraphicsContext::TBrushStyle brushstyle;
856 brushstyle = (CGraphicsContext::TBrushStyle) aReadStream.ReadUint8L();
857 (*gclist)[gcindex]->SetBrushStyle(brushstyle);
860 case ESetBrushOrigin:
863 aReadStream >> origin;
864 (*gclist)[gcindex]->SetBrushOrigin(origin);
867 case EUseBrushPattern:
869 bitmap->InternalizeL(aReadStream);
870 (*gclist)[gcindex]->UseBrushPattern(bitmap);
874 case EDiscardBrushPattern:
876 (*gclist)[gcindex]->DiscardBrushPattern();
882 aReadStream >> point;
883 (*gclist)[gcindex]->MoveTo(point);
889 aReadStream >> vector;
890 (*gclist)[gcindex]->MoveBy(vector);
896 aReadStream >> point;
897 (*gclist)[gcindex]->Plot(point);
905 aReadStream >> start;
907 (*gclist)[gcindex]->DrawArc(rect,start,end);
912 TPoint point1,point2;
913 aReadStream >> point1;
914 aReadStream >> point2;
915 (*gclist)[gcindex]->DrawLine(point1,point2);
921 aReadStream >> point;
922 (*gclist)[gcindex]->DrawLineTo(point);
928 aReadStream >> vector;
929 (*gclist)[gcindex]->DrawLineBy(vector);
938 numpoints=aReadStream.ReadInt32L();
939 for (TInt i=0; i<numpoints; i++)
942 aReadStream >> point;
943 pointlist->AppendL(point);
945 (*gclist)[gcindex]->DrawPolyLine(pointlist);
954 aReadStream >> start;
956 (*gclist)[gcindex]->DrawPie(rect,start,end);
963 (*gclist)[gcindex]->DrawEllipse(rect);
970 (*gclist)[gcindex]->DrawRect(rect);
978 aReadStream >> cornersize;
979 (*gclist)[gcindex]->DrawRoundRect(rect,cornersize);
988 numpoints=aReadStream.ReadInt32L();
989 for (TInt i=0; i<numpoints; i++)
992 aReadStream >> point;
993 pointlist->AppendL(point);
995 CGraphicsContext::TFillRule fillrule=(CGraphicsContext::TFillRule) aReadStream.ReadUint8L();
996 (*gclist)[gcindex]->DrawPolygon(pointlist,fillrule);
1003 aReadStream >> topleft;
1004 bitmap->InternalizeL(aReadStream);
1005 (*gclist)[gcindex]->DrawBitmap(topleft,bitmap);
1012 aReadStream >> destrect;
1013 bitmap->InternalizeL(aReadStream);
1014 (*gclist)[gcindex]->DrawBitmap(destrect,bitmap);
1021 aReadStream >> destrect;
1022 bitmap->InternalizeL(aReadStream);
1024 aReadStream >> sourcerect;
1025 (*gclist)[gcindex]->DrawBitmap(destrect,bitmap,sourcerect);
1031 HBufC* string=HBufC::NewLC(aReadStream,KMaxTInt);
1033 aReadStream >> position;
1034 (*gclist)[gcindex]->DrawText(*string,position);
1035 CleanupStack::PopAndDestroy();
1040 HBufC* string=HBufC::NewLC(aReadStream,KMaxTInt);
1043 TInt baselineoffset=aReadStream.ReadInt32L();
1044 CGraphicsContext::TTextAlign horiz=(CGraphicsContext::TTextAlign) aReadStream.ReadUint8L();
1045 TInt leftmrg=aReadStream.ReadInt32L();
1046 (*gclist)[gcindex]->DrawText(*string,box,baselineoffset,horiz,leftmrg);
1047 CleanupStack::PopAndDestroy();
1052 while (code!=EEndOfStream);
1053 CleanupStack::PopAndDestroy(gclist->Count()+4);