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.
19 #include <bitdrawscaling.h>
20 #include <bitdrawinterfaceid.h>
23 #include <shapeinfo.h>
24 #include "bitgcextradata.h"
26 #define KDefaultShadowColor KRgbGray
28 //CFbsBitGc streams - version numbers.
29 //Add new version numbers here. A reason of adding new version numbers may be adding new
30 //CFbsBitGc data members, which may have to be externalized/internalized. When that happens:
31 //1.Put a new enum item (like EFbsBitGc_Ver01) with a version number, which is greater than
32 // the last version number, which was used.
33 //2.Comment the new enum item.
34 //3.Update KFbsBitGc_VerNo value to be the last enum item value.
35 //4.Update InternalizeL/ExternalizeL methods after adding the new version number.
36 // For example: If a new member is added to the class - TInt iSmth, when InternalizeL
37 // is called to operate on older archive, iSmth member won't be in the archive!
38 // So, in InternalizeL, there should be a check, something like:
39 // TUint16 archiveVerNo = 0;
40 // aReadStream >> archiveVerNo;
41 // .......................
42 // if(archiveVerNo < EFbsBitGc_Ver03) //EFbsBitGc_Ver03 has been added, when iSmth has been added
44 // //Do nothing - iSmth is not in the archive
45 // //Initialize it with some default value
50 // aReadStream >> iSmth;
54 EFbsBitGc_Ver01 = 1, //Base version number, when InternalizeL/ExternalizeL were added
55 EFbsBitGc_Ver02 = 2, //Supports InternalizeL/ExternalizeL for ShadowColor.
57 LOCAL_D const TUint16 KFbsBitGc_VerNo = EFbsBitGc_Ver02;
59 // Global panic functions
61 void Panic(TBitgdiPanic aPanicCode)
63 _LIT(KBitgdiPanicCategory,"BITGDI");
64 User::Panic(KBitgdiPanicCategory,aPanicCode);
67 _LIT(KBITGDIPanicDesc1,"BitGdi internal Panic %S, in file %S @ line %i");
68 _LIT(KBITGDIPanicDesc2,"Assert condition = \"%S\"");
69 _LIT(KBITGDIPanicDesc3, "BitGdi internal Invariant, in file %S @ line %i");
71 void PanicWithInfo(TBitgdiPanic aPanic, const TDesC& aFileName, const TDesC& aPanicName, TInt aLine)
74 buf.Format(KBITGDIPanicDesc1, &aPanicName, &aFileName, aLine);
79 void PanicWithCondAndInfo(TBitgdiPanic aPanic, const TDesC& aCondition, const TDesC& aFileName, const TDesC& aPanicName, TInt aLine)
82 buf.Format(KBITGDIPanicDesc1, &aPanicName, &aFileName, aLine);
85 buf.Format(KBITGDIPanicDesc2, &aCondition);
90 void InvariantWithCondAndInfo(const TDesC& aCondition, const TDesC& aFileName, TInt aLine)
93 buf.Format(KBITGDIPanicDesc3, &aFileName, aLine);
96 buf.Format(KBITGDIPanicDesc2, &aCondition);
107 /** Factory function for creating a CFbsBitGc object
108 The object is then ready for a call to Activate().
109 @return A pointer to the newly created object. */
110 EXPORT_C CFbsBitGc* CFbsBitGc::NewL()
112 CFbsBitGc* bitGc = new(ELeave) CFbsBitGc;
113 CleanupStack::PushL(bitGc);
114 bitGc->iFbsBitGcExtraData = new(ELeave) CFbsBitGcExtraData;
115 CleanupStack::Pop(bitGc);
119 CFbsBitGc::CFbsBitGc():
123 iBrushColor(KRgbWhite),
124 iBrushOrigin(TPoint(0,0)),
125 iBrushStyle(ENullBrush),
126 iClipRect(TRect(0,0,0,0)),
128 iDefaultRegionPtr(NULL),
129 iUserClipRect(TRect(0,0,0,0)),
131 iDitherOrigin(TPoint(0,0)),
136 iDrawMode(EDrawModePEN),
142 iLastPrintPosition(TPoint(0,0)),
143 iLinePosition(TPoint(0,0)),
144 iOrigin(TPoint(0,0)),
145 iPenColor(KRgbBlack),
146 iPenStyle(ESolidPen),
147 iPenSize(TSize(1,1)),
148 iShadowMode(CFbsDrawDevice::ENoShadow),
149 iAutoUpdateJustification(ETrue),
152 iStrikethrough(EStrikethroughOff),
153 iUnderline(EUnderlineOff),
154 iUserDisplayMode(ENone)
158 /** Frees all resources owned by the object. */
159 EXPORT_C CFbsBitGc::~CFbsBitGc()
162 iBrushBitmap.Reset();
163 iClippingRegion.Close();
164 delete iFbsBitGcExtraData;
167 /** Sets the object to draw to a particular device
168 @param aDevice The target device. */
169 EXPORT_C void CFbsBitGc::Activate(CFbsDevice* aDevice)
175 iDevice->iDrawDevice->GetDrawRect(deviceRect);
176 iDefaultRegion.Clear();
177 iDefaultRegion.AddRect(deviceRect);
178 iDefaultRegionPtr = &iDefaultRegion;
179 iUserClipRect = deviceRect;
180 iDrawnTo.SetWidth(0);
181 iDrawnTo.SetHeight(0);
182 iAutoUpdateJustification = ETrue;
185 /** Sets the object to draw to a particular device but doesn't 'use up'
186 justification settings when drawing text.
187 This is similar to Activate().
188 @param aDevice The target device. */
189 EXPORT_C void CFbsBitGc::ActivateNoJustAutoUpdate(CFbsDevice* aDevice)
192 iAutoUpdateJustification = EFalse;
195 void CFbsBitGc::SetupDevice() const
197 CFbsDrawDevice* drawDevice = iDevice->iDrawDevice;
198 drawDevice->SetDitherOrigin(iDitherOrigin);
199 drawDevice->SetShadowMode(CFbsDrawDevice::TShadowMode(iShadowMode));
200 drawDevice->SetFadingParameters(iFadeBlackMap,iFadeWhiteMap);
201 drawDevice->SetUserDisplayMode(iUserDisplayMode);
204 void CFbsBitGc::CheckDevice() const
206 BG_ASSERT_ALWAYS(iDevice,EBitgdiPanicNoDevicePresent);
209 TBool CFbsBitGc::CheckDevice(const TRect& aRect) const
211 BG_ASSERT_ALWAYS(iDevice,EBitgdiPanicNoDevicePresent);
213 return aRect.IsEmpty();
216 /** Externalizes an object of this class to a write stream.
217 It is important that the brush bitmap of the GC is maintained between calls
218 to externalize and internalize. The brush bitmap handle is externalized,
219 not the bitmap data. This is done for performance.
221 @param aWriteStream Stream to which the object should be externalized.
223 EXPORT_C void CFbsBitGc::ExternalizeL(RWriteStream& aWriteStream)
225 aWriteStream << KFbsBitGc_VerNo;
226 TInt bitmapHandle=iBrushBitmap.Handle();
227 aWriteStream.WriteInt32L(bitmapHandle);
228 iBrushColor.ExternalizeL(aWriteStream);
229 aWriteStream.WriteInt8L(iBrushUsed);
230 aWriteStream << iBrushOrigin;
231 aWriteStream.WriteUint8L(iBrushStyle);
232 aWriteStream << iDitherOrigin;
233 aWriteStream << iUserClipRect;
234 aWriteStream << iDrawnTo;
235 aWriteStream.WriteUint32L(iDotLength);
236 aWriteStream.WriteUint32L(iDotMask);
237 aWriteStream.WriteUint32L(iDotParam);
238 aWriteStream.WriteUint32L(iDotDirection);
239 aWriteStream.WriteUint8L(iDrawMode);
240 aWriteStream.WriteUint32L(iCharJustExcess);
241 aWriteStream.WriteUint32L(iCharJustNum);
242 aWriteStream.WriteUint32L(iWordJustExcess);
243 aWriteStream.WriteUint32L(iWordJustNum);
244 aWriteStream << iLastPrintPosition;
245 aWriteStream << iLinePosition;
246 aWriteStream << iOrigin;
247 iPenColor.ExternalizeL(aWriteStream);
248 aWriteStream.WriteUint8L(iPenStyle);
249 aWriteStream << iPenSize;
250 aWriteStream << iShadowMode;
251 aWriteStream << iAutoUpdateJustification;
252 aWriteStream << iFadeBlackMap;
253 aWriteStream << iFadeWhiteMap;
254 aWriteStream.WriteUint8L(iStrikethrough);
255 aWriteStream.WriteUint8L(iUnderline);
257 const TFontSpec fontSpec=iFont.FontSpecInTwips();
258 fontSpec.ExternalizeL(aWriteStream);
260 aWriteStream.WriteUint8L(iUserDisplayMode);
261 iFbsBitGcExtraData->ShadowColor().ExternalizeL(aWriteStream);
264 /** Internalizes an object of this class from a read stream.
265 It is important that the brush bitmap of the GC is maintained between calls
266 to externalize and internalize. The brush bitmap handle is internalized,
269 @param aReadStream Stream from which the object is to be internalized.
271 EXPORT_C void CFbsBitGc::InternalizeL(RReadStream& aReadStream)
273 TUint16 archiveVerNo = 0;
274 aReadStream >> archiveVerNo;
275 TInt bitmapHandle=aReadStream.ReadInt32L();
278 UseBrushPattern(bitmapHandle);
280 iBrushColor.InternalizeL(aReadStream);
281 iBrushUsed=aReadStream.ReadInt8L();
282 aReadStream >> iBrushOrigin;
283 iBrushStyle=(TBrushStyle)aReadStream.ReadUint8L();
284 aReadStream >> iDitherOrigin;
285 aReadStream >> iUserClipRect;
286 aReadStream >> iDrawnTo;
287 iDotLength=aReadStream.ReadUint32L();
288 iDotMask=aReadStream.ReadUint32L();
289 iDotParam=aReadStream.ReadUint32L();
290 iDotDirection=aReadStream.ReadUint32L();
291 iDrawMode=(TDrawMode)aReadStream.ReadUint8L();
292 iCharJustExcess=aReadStream.ReadUint32L();
293 iCharJustNum=aReadStream.ReadUint32L();
294 iWordJustExcess=aReadStream.ReadUint32L();
295 iWordJustNum=aReadStream.ReadUint32L();
296 aReadStream >> iLastPrintPosition;
297 aReadStream >> iLinePosition;
298 aReadStream >> iOrigin;
299 iPenColor.InternalizeL(aReadStream);
300 iPenStyle=(TPenStyle)aReadStream.ReadUint8L();
301 aReadStream >> iPenSize;
302 SetPenSize(iPenSize);
303 aReadStream >> iShadowMode;
304 aReadStream >> iAutoUpdateJustification;
305 aReadStream >> iFadeBlackMap;
306 aReadStream >> iFadeWhiteMap;
307 iStrikethrough=(TFontStrikethrough)aReadStream.ReadUint8L();
308 iUnderline=(TFontUnderline)aReadStream.ReadUint8L();
310 fontSpec.InternalizeL(aReadStream);
311 if (fontSpec.iHeight != 0)
313 CFbsFont* font = NULL;
314 User::LeaveIfError(iDevice->GetNearestFontToDesignHeightInTwips(font,fontSpec));
315 TInt err = iFont.Duplicate(font->Handle());
316 iDevice->ReleaseFont(font);
317 User::LeaveIfError(err);
318 UseFont(iFont.Handle());
320 iUserDisplayMode=(TDisplayMode)aReadStream.ReadUint8L();
321 if(archiveVerNo < EFbsBitGc_Ver02) //Without shadowcolor
323 //Initialize it with the default value
324 iFbsBitGcExtraData->SetShadowColor(KDefaultShadowColor);
326 else //With shadowcolor
329 shadowColor.InternalizeL(aReadStream);
330 iFbsBitGcExtraData->SetShadowColor(shadowColor);
334 /** Copies all settings from the specified bitmap graphics context.
335 @param aGc The bitmap graphics context whose settings are to be copied. */
336 EXPORT_C void CFbsBitGc::CopySettings(const CFbsBitGc& aGc)
338 iBrushColor = aGc.iBrushColor;
339 iBrushUsed = aGc.iBrushUsed;
340 iBrushOrigin = aGc.iBrushOrigin;
341 iBrushStyle = aGc.iBrushStyle;
342 iDefaultRegionPtr = aGc.iDefaultRegionPtr;
343 iDitherOrigin = aGc.iDitherOrigin;
344 iDotLength = aGc.iDotLength;
345 iDotMask = aGc.iDotMask;
346 iDotParam = aGc.iDotParam;
347 iDotDirection = aGc.iDotDirection;
348 iDrawMode = aGc.iDrawMode;
349 iCharJustExcess = aGc.iCharJustExcess;
350 iCharJustNum = aGc.iCharJustNum;
351 iWordJustExcess = aGc.iWordJustExcess;
352 iWordJustNum = aGc.iWordJustNum;
353 iLastPrintPosition = aGc.iLastPrintPosition;
354 iLinePosition = aGc.iLinePosition;
355 iOrigin = aGc.iOrigin;
356 iPenColor = aGc.iPenColor;
357 iPenStyle = aGc.iPenStyle;
358 SetPenSize(aGc.iPenSize);
359 iShadowMode = aGc.iShadowMode;
360 iStrikethrough = aGc.iStrikethrough;
361 iUnderline = aGc.iUnderline;
362 iUserDisplayMode = aGc.iUserDisplayMode;
363 if(aGc.iFont.Handle())
364 UseFont(aGc.iFont.Handle());
365 if(aGc.iBrushBitmap.Handle())
366 UseBrushPattern(aGc.iBrushBitmap.Handle());
367 iFbsBitGcExtraData->SetShadowColor(aGc.iFbsBitGcExtraData->ShadowColor());
370 /** Gets a pointer to the graphics device for the graphics context.
371 The graphics device is the device currently being drawn to.
372 The function provides a concrete implementation of the pure virtual function
373 CGraphicsContext::Device(). The function behaviour is the same as documented
375 @see CGraphicsContext::Device() */
376 EXPORT_C CGraphicsDevice* CFbsBitGc::Device() const
381 /** Discards a non-built-in brush pattern.
382 The function provides a concrete implementation of the pure virtual function
383 CGraphicsContext::DiscardBrushPattern(). The function behaviour is the same
384 as documented in that class.
385 @see CGraphicsContext::DiscardBrushPattern() */
386 EXPORT_C void CFbsBitGc::DiscardBrushPattern()
388 iBrushBitmap.Reset();
390 if (iBrushStyle == EPatternedBrush)
391 iBrushStyle = ENullBrush;
394 /** Discards a selected device font.
395 The function provides a concrete implementation of the pure virtual function
396 CGraphicsContext::DiscardFont(). The function behaviour is the same as documented
398 @see CGraphicsContext::DiscardFont() */
399 EXPORT_C void CFbsBitGc::DiscardFont()
404 /** Maps pixels in the specified rectangle.
405 The function tries to match the colour of a pixel with one of the RGB values
406 in an array of RGB pairs. If there is a match, the colour is changed to the
407 value specified in the other RGB in the RGB pair.
408 @param aRect The rectangle in which pixels are to be mapped.
409 @param aColors A pointer to a set of RGB pairs.
410 @param aNumPairs The number of pairs
411 @param aMapForwards ETrue, mapping is done from the first RGB to the second
412 RGB in the pair; EFalse, mapping is done from the second RGB to the first
414 EXPORT_C void CFbsBitGc::MapColors(const TRect& aRect,
419 if (CheckDevice(aRect) || !aColors)
425 if (UserClipRect(rcpy))
429 iDevice->DrawingBegin();
431 CFbsDrawDevice* drawDevice = iDevice->iDrawDevice;
435 drawDevice->GetDrawRect(deviceRect);
438 const TInt limit = iDefaultRegionPtr->Count();
439 for (TInt count = 0; count < limit; count++)
441 iClipRect = (*iDefaultRegionPtr)[count];
442 if (!iClipRect.Intersects(rcpy))
445 iClipRect.Intersection(rcpy);
447 BG_ASSERT_DEBUG(iClipRect.iTl.iX >= deviceRect.iTl.iX, EBitgdiPanicOutOfBounds);
448 BG_ASSERT_DEBUG(iClipRect.iTl.iY >= deviceRect.iTl.iY, EBitgdiPanicOutOfBounds);
449 BG_ASSERT_DEBUG(iClipRect.iBr.iX <= deviceRect.iBr.iX, EBitgdiPanicOutOfBounds);
450 BG_ASSERT_DEBUG(iClipRect.iBr.iY <= deviceRect.iBr.iY, EBitgdiPanicOutOfBounds);
452 drawDevice->MapColors(iClipRect,aColors,aNumPairs,aMapForwards);
453 drawDevice->UpdateRegion(iClipRect);
456 iDevice->DrawingEnd();
459 /** Sets the internal drawing position relative to the co-ordinate origin.
460 A subsequent call to DrawLineTo() or DrawLineBy() uses the new drawing point
461 as the start point for the line drawn.The function provides a concrete
462 implementation of the pure virtual function CGraphicsContext::MoveTo().
463 The function behaviour is the same as documented in that class. */
464 EXPORT_C void CFbsBitGc::MoveTo(const TPoint& aPoint)
466 iLinePosition = aPoint;
469 /** Sets the drawing point relative to the current co-ordinates.
470 The function provides a concrete implementation of the pure virtual
471 function CGraphicsContext::MoveBy(). The function behaviour
472 is the same as documented in that class. */
473 EXPORT_C void CFbsBitGc::MoveBy(const TPoint& aVector)
475 iLinePosition += aVector;
478 /** Resets the graphics context to its default settings.
479 The function provides a concrete implementation of the pure virtual function
480 CGraphicsContext::Reset(). The function behaviour is the same as documented
482 @see CGraphicsContext::Reset() */
483 EXPORT_C void CFbsBitGc::Reset()
485 iDefaultRegionPtr = &iDefaultRegion;
486 if (iDefaultRegion.Count() == 0)
487 iUserClipRect = TRect(0,0,0,0);
489 iUserClipRect = iDefaultRegion[0];
490 iLastPrintPosition.SetXY(0,0);
491 if(iFbsBitGcExtraData)
493 iFbsBitGcExtraData->Reset();
495 iPenColor = KRgbBlack;
496 iPenStyle = ESolidPen;
497 iPenSize.SetSize(1,1);
498 iDrawMode = EDrawModePEN;
500 iLinePosition.SetXY(0,0);
503 iBrushColor = KRgbWhite;
504 iBrushOrigin.SetXY(0,0);
505 iBrushStyle = ENullBrush;
510 iDitherOrigin.SetXY(0,0);
515 iShadowMode = CFbsDrawDevice::ENoShadow;
516 iStrikethrough = EStrikethroughOff;
517 iUnderline = EUnderlineOff;
518 iUserDisplayMode = ENone;
521 /** Needs to be called if the device is resized.
522 This only applies to devices of type CFbsBitmapDevice. */
523 EXPORT_C void CFbsBitGc::Resized()
528 iDevice->iDrawDevice->GetDrawRect(deviceRect);
529 iUserClipRect = deviceRect;
530 iDefaultRegion.Clear();
531 iDefaultRegion.AddRect(deviceRect);
532 iDefaultRegionPtr = &iDefaultRegion;
534 if (deviceRect.Contains(iLastPrintPosition))
535 iLastPrintPosition.SetXY(0,0);
536 if (deviceRect.Contains(iLinePosition))
537 iLinePosition.SetXY(0,0);
538 if (deviceRect.Contains(iOrigin))
540 if (deviceRect.Contains(iBrushOrigin))
541 iBrushOrigin.SetXY(0,0);
544 /**Returns current setting of brush color.
546 EXPORT_C TRgb CFbsBitGc::BrushColor()
551 /** Sets the brush pattern origin.
552 The function provides a concrete implementation of the pure virtual
553 function CGraphicsContext::SetBrushOrigin(). The function
554 behaviour is the same as documented in that class. */
555 EXPORT_C void CFbsBitGc::SetBrushOrigin(const TPoint& origin)
557 iBrushOrigin = origin;
560 /**Sets the brush colour.
561 The function provides a concrete implementation of the pure virtual
562 function CGraphicsContext::SetBrushColor(). The function
563 behaviour is the same as documented in that class. */
564 EXPORT_C void CFbsBitGc::SetBrushColor(const TRgb& aColor)
566 iBrushColor = aColor;
569 /** Sets the brush style.
570 The function provides a concrete implementation of the pure virtual
571 function CGraphicsContext::SetBrushStyle(). The function
572 behaviour is the same as documented in that class. */
573 EXPORT_C void CFbsBitGc::SetBrushStyle(TBrushStyle aStyle)
575 iBrushStyle = aStyle;
579 /** Sets the dither origin.
580 This is only useful for modes that do dithering. If the display is scrolled
581 an odd number of pixels then the (2x2) dither pattern will not match up for
582 new drawing unless this is called.
583 @param aPoint The dither origin. */
584 EXPORT_C void CFbsBitGc::SetDitherOrigin(const TPoint& aPoint)
586 iDitherOrigin = iOrigin + aPoint;
589 /** Sets the character justification.
590 The function provides a concrete implementation of the pure virtual
591 function CGraphicsContext::SetCharJustification(). The
592 function behaviour is the same as documented in that class. */
593 EXPORT_C void CFbsBitGc::SetCharJustification(TInt aExcessWidth,TInt aNumChars)
595 if (aExcessWidth == 0 || aNumChars <= 0)
602 iCharJustExcess = aExcessWidth;
603 iCharJustNum = aNumChars;
607 /** Sets the clipping rectangle.
608 This function provides a concrete implementation of the pure virtual function
609 CGraphicsContext::SetClippingRect(). The function behaviour is the same as
610 documented in that class.
611 @see CGraphicsContext::SetClippingRect() */
612 EXPORT_C void CFbsBitGc::SetClippingRect(const TRect& aRect)
617 iDevice->iDrawDevice->GetDrawRect(deviceRect);
618 iUserClipRect = deviceRect;
619 iUserClipRect.Intersection(TRect(aRect.iTl + iOrigin,aRect.iBr + iOrigin));
622 /** Cancels clipping rectangle and region. */
623 EXPORT_C void CFbsBitGc::CancelClipping()
625 CancelClippingRect();
626 CancelClippingRegion();
629 /** Cancels any clipping rectangle.
630 Clipping reverts to the full device area, the default.
631 The function provides a concrete implementation of the pure virtual function
632 CGraphicsContext::CancelClippingRect(). The function behaviour is the same
633 as documented in that class.
634 @see CGraphicsContext::CancelClippingRect() */
635 EXPORT_C void CFbsBitGc::CancelClippingRect()
637 if (iDefaultRegion.Count() == 0)
638 iUserClipRect = TRect(0,0,0,0);
640 iUserClipRect = iDefaultRegion[0];
643 /** Cancels the clipping region. */
644 EXPORT_C void CFbsBitGc::CancelClippingRegion()
646 iDefaultRegionPtr = &iDefaultRegion;
649 /** Sets the word justification.
650 The function provides a concrete implementation of the pure virtual
651 function CGraphicsContext::SetWordJustification(). The
652 function behaviour is the same as documented in that class. */
653 EXPORT_C void CFbsBitGc::SetWordJustification(TInt aExcessWidth,TInt aNumGaps)
655 if (aExcessWidth <= 0 || aNumGaps <= 0)
662 iWordJustExcess = aExcessWidth;
663 iWordJustNum = aNumGaps;
667 /** Sets a clipping region by storing a pointer to the TRegion parameter.
668 This function provides a concrete implementation of the pure virtual
669 function CGraphicsContext::SetClippingRegion(). The function behaviour is the
670 same as documented in that class.
671 @panic BITGDI 10 if aRegion is invalid or if aRegion is not contained by the
673 EXPORT_C void CFbsBitGc::SetClippingRegion(const TRegion* aRegion)
677 iDefaultRegionPtr = &iDefaultRegion;
681 BG_ASSERT_ALWAYS(!aRegion->CheckError(),EBitgdiPanicInvalidRegion);
682 BG_ASSERT_ALWAYS(aRegion->IsContainedBy(iDefaultRegion.BoundingRect()),EBitgdiPanicInvalidRegion);
684 iDefaultRegionPtr = aRegion;
687 /** Sets a clipping region by storing a copy of the TRegion parameter.
688 @param aRegion The clipping region to be stored and used. aRegion must be valid and bounded withing the iDefaultRegion.
689 @return KErrNone if successful; KErrArgument if aRegion is invalid, KErrMemory if the region could not be allocated.
690 @see CGraphicsContext::SetClippingRegion().
692 EXPORT_C TInt CFbsBitGc::SetClippingRegion(const TRegion& aRegion)
694 if (aRegion.CheckError() || !aRegion.IsContainedBy(iDefaultRegion.BoundingRect()))
697 iClippingRegion.Copy(aRegion);
698 if (iClippingRegion.CheckError())
701 iDefaultRegionPtr = &iClippingRegion;
706 /** Sets the drawing mode.
707 This affects the colour that is actually drawn, because it defines the way
708 that the current screen colour logically combines with the current pen colour
710 The function provides a concrete implementation of the pure virtual function
711 CGraphicsContext::SetDrawMode(). The function behaviour is the same as documented
713 @see CGraphicsContext::SetDrawMode() */
714 EXPORT_C void CFbsBitGc::SetDrawMode(CGraphicsContext::TDrawMode aDrawMode)
716 iDrawMode = aDrawMode;
719 /**Returns current setting of pen color.
721 EXPORT_C TRgb CFbsBitGc::PenColor()
726 /** Sets the position of the co-ordinate origin.
727 All subsequent drawing operations are then done relative to this
728 origin.The function provides a concrete implementation of the pure
729 virtual function CGraphicsContext::SetOrigin(). The
730 function behaviour is the same as documented in that class. */
731 EXPORT_C void CFbsBitGc::SetOrigin(const TPoint& aPoint)
733 iDitherOrigin -= iOrigin;
735 iDitherOrigin += iOrigin;
738 /** Sets the pen colour.
739 The function provides a concrete implementation of the pure virtual
740 function CGraphicsContext::SetPenColor(). The function
741 behaviour is the same as documented in that class. */
742 EXPORT_C void CFbsBitGc::SetPenColor(const TRgb& aColor)
748 /** Sets the line drawing style for the pen.
749 The function provides a concrete implementation of the pure virtual function
750 CGraphicsContext::SetPenStyle(). The function behaviour is the same as documented
752 @see CGraphicsContext::SetPenStyle() */
753 EXPORT_C void CFbsBitGc::SetPenStyle(TPenStyle aStyle)
788 /** Sets the line drawing size for the pen.
789 The function provides a concrete implementation of the pure virtual
790 function CGraphicsContext::SetPenSize(). The function
791 behaviour is the same as documented in that class. */
792 EXPORT_C void CFbsBitGc::SetPenSize(const TSize& aSize)
794 iPenSize.SetSize(Abs(aSize.iWidth),Abs(aSize.iHeight));
796 const TSize maxsize = iDevice->iDrawDevice->SizeInPixels();
798 iPenSize.iWidth = Min(iPenSize.iWidth,maxsize.iWidth << 1);
799 iPenSize.iHeight = Min(iPenSize.iHeight,maxsize.iHeight << 1);
801 if (iPenSize.iWidth || iPenSize.iHeight)
805 iFbsBitGcExtraData->ResetPenArray();
811 /** Simulates another graphics mode.
812 Some devices running in some modes can simulate other modes (EGray16 will
813 do EGray4 and EGray2, EGray4 will do EGray2).
814 @param aDisplayMode The display mode to be set. */
815 EXPORT_C void CFbsBitGc::SetUserDisplayMode(TDisplayMode aDisplayMode)
817 if(aDisplayMode==iDevice->DisplayMode())
818 aDisplayMode = ENone;
819 iUserDisplayMode = aDisplayMode;
822 /** Sets the underline style for all subsequently drawn text.
823 The function provides a concrete implementation of the pure virtual
824 function CGraphicsContext::SetUnderlineStyle(). The
825 function behaviour is the same as documented in that class. */
826 EXPORT_C void CFbsBitGc::SetUnderlineStyle(TFontUnderline aUnderlineStyle)
828 iUnderline = aUnderlineStyle;
831 /** Sets the strikethrough style for all subsequently drawn text.
832 The function provides a concrete implementation of the pure virtual
833 function CGraphicsContext::SetStrikethroughStyle(). The
834 function behaviour is the same as documented in that class. */
835 EXPORT_C void CFbsBitGc::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle)
837 iStrikethrough = aStrikethroughStyle;
840 /** Sets the shadow mode on or off.
841 @param aShadowMode ETrue, shadow mode is on; EFalse, shadow mode is off. EFalse
843 EXPORT_C void CFbsBitGc::SetShadowMode(TBool aShadowMode)
846 iShadowMode |= CFbsDrawDevice::EShadow;
848 iShadowMode &= ~CFbsDrawDevice::EShadow;
851 /** Sets whether the graphics context is faded.
852 The function provides a concrete implementation of the pure virtual
853 function CBitmapContext::SetFaded(). The function
854 behaviour is the same as documented in that class.
856 EXPORT_C void CFbsBitGc::SetFaded(TBool aFadeMode)
859 iShadowMode |= CFbsDrawDevice::EFade;
861 iShadowMode &= ~CFbsDrawDevice::EFade;
864 /** Set fading parameters.
865 The function provides a concrete implementation of the pure virtual
866 function CBitmapContext::SetFadingParameters(). The
867 function behaviour is the same as documented in that class.
869 EXPORT_C void CFbsBitGc::SetFadingParameters(TUint8 aBlackMap,TUint8 aWhiteMap)
871 iFadeBlackMap = aBlackMap;
872 iFadeWhiteMap = aWhiteMap;
875 /** Gets the orientations supported.
876 @param aOrientation[4] An array of four TBool values. Each entry in this
877 array corresponds to successive values of the TGraphicsOrientation enum.
878 If the first array entry has an EFrue value, then the normal orientation
879 is supported; if the second entry array has an ETrue value,
880 then a 90 degree orientation is supported etc. */
881 EXPORT_C void CFbsBitGc::OrientationsAvailable(TBool aOrientation[4])
885 iDevice->iDrawDevice->OrientationsAvailable(aOrientation);
889 aOrientation[EGraphicsOrientationNormal] = EFalse;
890 aOrientation[EGraphicsOrientationRotated90] = EFalse;
891 aOrientation[EGraphicsOrientationRotated180] = EFalse;
892 aOrientation[EGraphicsOrientationRotated270] = EFalse;
896 /** Sets the orientation.
897 @param aOrientation The required orientation
898 @return ETrue, if the requested orientation is supported; EFalse, otherwise. */
899 EXPORT_C TBool CFbsBitGc::SetOrientation(TGraphicsOrientation aOrientation)
904 TBool ret = iDevice->SetOrientation(aOrientation);
908 iDevice->iDrawDevice->GetDrawRect(deviceRect);
909 iDefaultRegion.Clear();
910 iDefaultRegion.AddRect(deviceRect);
911 iUserClipRect = deviceRect;
912 iDrawnTo.SetRect(0,0,0,0);
918 /** Sets the specified bitmap to be used as the brush pattern.
919 @param aBitmap The bitmap.*/
920 EXPORT_C void CFbsBitGc::UseBrushPattern(const CFbsBitmap* aBitmap)
922 BG_ASSERT_ALWAYS(aBitmap != NULL,EBitgdiPanicInvalidBitmap);
924 TInt brushResult = UseBrushPattern(((CFbsBitmap*)aBitmap)->Handle());
925 BG_ASSERT_ALWAYS(brushResult == KErrNone,EBitgdiPanicInvalidBitmap);
928 /** Sets the specified bitmap to be used as the brush pattern.
929 @param aFbsBitmapHandle The handle number of the bitmap.
930 @return KErrNone, if successful; otherwise another of the other system wide
932 EXPORT_C TInt CFbsBitGc::UseBrushPattern(TInt aFbsBitmapHandle)
934 BG_ASSERT_ALWAYS(aFbsBitmapHandle,EBitgdiPanicInvalidBitmap);
937 if (iBrushBitmap.Handle() == aFbsBitmapHandle)
940 TInt ret = iBrushBitmap.Duplicate(aFbsBitmapHandle);
947 /** Selects the device font, identified by handle number, to be used for text drawing.
949 When the font is no longer required, use DiscardFont() to free up the memory
950 used. If UseFont() is used again without using DiscardFont() then the previous
951 font is discarded automatically.
952 If no font has been selected, and an attempt is made to draw text with DrawText(),
954 @param aFontHandle A handle number for a device font.
955 @return The duplicate handle number for the device font.
957 EXPORT_C void CFbsBitGc::UseFont(const CFont* aFont)
959 BG_ASSERT_ALWAYS(aFont != NULL,EBitgdiPanicInvalidFont);
960 BG_ASSERT_ALWAYS(aFont->TypeUid() == KCFbsFontUid,EBitgdiPanicInvalidFont);
962 TInt fontResult = UseFont(((CFbsBitGcFont*)aFont)->Handle());
963 BG_ASSERT_ALWAYS(fontResult == KErrNone,EBitgdiPanicInvalidFont);
966 /** Selects the device font, identified by handle, to be used for
968 Notes:When the font is no longer required, use DiscardFont() to free up the memory used.
969 If UseFont() is used again without using DiscardFont() then the previous font is
970 discarded automatically.If no font has been selected, and an attempt is made to
971 draw text with DrawText(), then a panic occurs.
972 @param aFbsFontHandle A handle for a device font.
973 @return The result of CFbsFont::Duplicate(). */
974 EXPORT_C TInt CFbsBitGc::UseFont(TInt aFbsFontHandle)
976 BG_ASSERT_ALWAYS(aFbsFontHandle,EBitgdiPanicInvalidFont);
978 if (iFont.Handle() == aFbsFontHandle)
981 return iFont.Duplicate(aFbsFontHandle);
984 /** Selects a device font for text drawing but does not take a copy.
985 The original must not be destroyed until UseFont(), UseFontNoDuplicate(),
986 DiscardFont() or the destructor is called.
987 @param aFont A pointer to the font to be used. */
988 EXPORT_C void CFbsBitGc::UseFontNoDuplicate(const CFbsBitGcFont* aFont)
992 BG_ASSERT_ALWAYS(aFont->TypeUid() == KCFbsFontUid,EBitgdiPanicInvalidFont);
994 if (aFont->Handle() == NULL)
1000 /** Tests whether a brush pattern is being used.
1001 @return ETrue, if a brush pattern is being used; EFalse, otherwise. */
1002 EXPORT_C TBool CFbsBitGc::IsBrushPatternUsed() const
1007 /** Tests whether a font is used.
1008 @return ETrue, if a font is being used; EFalse, otherwise. */
1009 EXPORT_C TBool CFbsBitGc::IsFontUsed() const
1017 TBool CFbsBitGc::UserClipRect(TRect& aRect)
1019 if (!aRect.Intersects(iUserClipRect))
1022 aRect.Intersection(iUserClipRect);
1027 /** Fetches the bounding rectangle of all drawing done since this function was last
1029 @param aRect The bounding rectangle. */
1030 EXPORT_C void CFbsBitGc::RectDrawnTo(TRect& aRect)
1033 iDrawnTo.SetRect(0,0,0,0);
1036 /** Updates the justification settings.
1037 This function assumes that ActivateNoJustAutoUpdate() has been used.
1038 @param aText The text for which justification is to be adjusted. */
1039 EXPORT_C void CFbsBitGc::UpdateJustification(const TDesC& aText)
1041 TTextParameters* param = NULL;
1042 UpdateJustification(aText,param);
1045 /** Updates the justification for vertical text.
1046 @param aText The text for which justification is to be adjusted.
1047 @param aUp ETrue, if text is to be justified upwards;EFalse, if text is to
1048 be justified downwards. */
1049 EXPORT_C void CFbsBitGc::UpdateJustificationVertical(const TDesC& aText, TBool aUp)
1051 TTextParameters* param = NULL;
1052 UpdateJustificationVertical(aText,param,aUp);
1055 /** Updates the justification settings.
1056 This function assumes that ActivateNoJustAutoUpdate() has been used.
1057 @param aText The text for which justification is to be adjusted. */
1058 EXPORT_C void CFbsBitGc::UpdateJustification(const TDesC& aText,const TTextParameters* aParam)
1060 if ((iCharJustNum < 1 || iCharJustExcess == 0) && (iWordJustNum < 1 || iWordJustExcess < 1))
1063 TInt length = aText.Length();
1064 CFont::TPositionParam param;
1065 param.iText.Set(aText); // Set the start of the string
1068 length = aParam->iEnd;
1069 param.iPosInText = aParam->iStart;
1073 RShapeInfo shapeInfo;
1074 for (TInt count = 0; count < length; count++)
1076 if (iCharJustNum > 0 && iCharJustExcess != 0)
1077 excess += CGraphicsContext::JustificationInPixels(iCharJustExcess, iCharJustNum);
1078 if (iWordJustNum > 0 && iWordJustExcess > 0 && aText[count] == ' ')
1079 excess += CGraphicsContext::JustificationInPixels(iWordJustExcess, iWordJustNum);
1081 if (iCharJustNum < glyphs + length - count) // there's at least 1 combined glyph to come
1083 // otherwise we can skip this slow bit and just increment
1084 if (iFont.GetCharacterPosition2(param, shapeInfo))
1085 count = param.iPosInText - 1; // -1 'cos it gets incremented anyway
1089 if(shapeInfo.IsOpen())
1092 iLastPrintPosition.iX += excess;
1095 /** Updates the justification for vertical text.
1096 @param aText The text for which justification is to be adjusted.
1097 @param aUp ETrue, if text is to be justified upwards;EFalse, if text is to
1098 be justified downwards. */
1099 EXPORT_C void CFbsBitGc::UpdateJustificationVertical(const TDesC& aText,const TTextParameters* aParam,TBool aUp)
1101 if ((iCharJustNum < 1 || iCharJustExcess == 0) && (iWordJustNum < 1 || iWordJustExcess < 1))
1104 TInt length = aText.Length();
1105 CFont::TPositionParam param;
1106 param.iText.Set(aText); // Set the start of the string
1109 length = aParam->iEnd;
1110 param.iPosInText = aParam->iStart;
1114 RShapeInfo shapeInfo;
1115 for (TInt count = 0; count < length; count++)
1117 if (iCharJustNum > 0 && iCharJustExcess != 0)
1118 excess += CGraphicsContext::JustificationInPixels(iCharJustExcess, iCharJustNum);
1119 if (iWordJustNum > 0 && iWordJustExcess > 0 && aText[count] == ' ')
1120 excess += CGraphicsContext::JustificationInPixels(iWordJustExcess, iWordJustNum);
1121 if (iCharJustNum < glyphs + length - count) // there's at least 1 combined glyph to come
1123 // otherwise we can skip this slow bit and just increment
1124 if (iFont.GetCharacterPosition2(param, shapeInfo))
1125 count = param.iPosInText - 1; // -1 'cos it gets incremented anyway
1129 if (shapeInfo.IsOpen())
1133 iLastPrintPosition.iY -= excess;
1135 iLastPrintPosition.iY += excess;
1137 void CFbsBitGc::AddRect(const TRect& aRect)
1139 if (iDrawnTo.IsEmpty())
1141 else if (!aRect.IsEmpty())
1142 iDrawnTo.BoundingRect(aRect);
1145 CFbsBitGcExtraData::CFbsBitGcExtraData()
1147 iShadowColor = KDefaultShadowColor; //default shadow color
1150 CFbsBitGcExtraData::~CFbsBitGcExtraData()
1155 void CFbsBitGcExtraData::Reset()
1157 SetShadowColor(KDefaultShadowColor);
1161 #define ORIENTATION_TO_CAP(orientation) (1 << (TInt)orientation)
1163 CGraphicsAccelerator* CFbsBitGc::GraphicsAccelerator()
1165 CGraphicsAccelerator* ga = iDevice->GraphicsAccelerator();
1169 const TGraphicsAcceleratorCaps* caps = ga->Capabilities();
1170 //iReserved[0] specifies the supported rendering orientations.
1171 //Existing variable name is used to avoid SC break since it is an array.
1172 const TUint orientationCaps = caps->iReserved[0];
1173 const TGraphicsOrientation orientation = iDevice->Orientation();
1174 if(iDevice->iScreenDevice
1175 && ((orientationCaps == 0 && orientation !=EGraphicsOrientationNormal)
1176 || ((ORIENTATION_TO_CAP(orientation) & orientationCaps) ==0)))
1179 if(iUserDisplayMode!=ENone)
1185 /** Replace target device but keep the current state
1187 @param aDevice The target device
1190 EXPORT_C void CFbsBitGc::ChangeDevice(CFbsDevice* aDevice)