|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <bitstd.h> |
|
17 #include <bitdev.h> |
|
18 #include <bitdraw.h> |
|
19 #include <bitdrawscaling.h> |
|
20 #include <bitdrawinterfaceid.h> |
|
21 #include "BITPANIC.H" |
|
22 #include <s32mem.h> |
|
23 #include <shapeinfo.h> |
|
24 #include "bitgcextradata.h" |
|
25 |
|
26 |
|
27 #define KDefaultShadowColor KRgbGray |
|
28 |
|
29 //CFbsBitGc streams - version numbers. |
|
30 //Add new version numbers here. A reason of adding new version numbers may be adding new |
|
31 //CFbsBitGc data members, which may have to be externalized/internalized. When that happens: |
|
32 //1.Put a new enum item (like EFbsBitGc_Ver01) with a version number, which is greater than |
|
33 // the last version number, which was used. |
|
34 //2.Comment the new enum item. |
|
35 //3.Update KFbsBitGc_VerNo value to be the last enum item value. |
|
36 //4.Update InternalizeL/ExternalizeL methods after adding the new version number. |
|
37 // For example: If a new member is added to the class - TInt iSmth, when InternalizeL |
|
38 // is called to operate on older archive, iSmth member won't be in the archive! |
|
39 // So, in InternalizeL, there should be a check, something like: |
|
40 // TUint16 archiveVerNo = 0; |
|
41 // aReadStream >> archiveVerNo; |
|
42 // ....................... |
|
43 // if(archiveVerNo < EFbsBitGc_Ver03) //EFbsBitGc_Ver03 has been added, when iSmth has been added |
|
44 // { |
|
45 // //Do nothing - iSmth is not in the archive |
|
46 // //Initialize it with some default value |
|
47 // iSmth = KDefVal; |
|
48 // } |
|
49 // else |
|
50 // { |
|
51 // aReadStream >> iSmth; |
|
52 // } |
|
53 enum |
|
54 { |
|
55 EFbsBitGc_Ver01 = 1, //Base version number, when InternalizeL/ExternalizeL were added |
|
56 EFbsBitGc_Ver02 = 2, //Supports InternalizeL/ExternalizeL for ShadowColor. |
|
57 }; |
|
58 LOCAL_D const TUint16 KFbsBitGc_VerNo = EFbsBitGc_Ver02; |
|
59 |
|
60 // Global panic functions |
|
61 |
|
62 void Panic(TBitgdiPanic aPanicCode) |
|
63 { |
|
64 _LIT(KBitgdiPanicCategory,"BITGDI"); |
|
65 User::Panic(KBitgdiPanicCategory,aPanicCode); |
|
66 } |
|
67 |
|
68 _LIT(KBITGDIPanicDesc1,"BitGdi internal Panic %S, in file %S @ line %i"); |
|
69 _LIT(KBITGDIPanicDesc2,"Assert condition = \"%S\""); |
|
70 _LIT(KBITGDIPanicDesc3, "BitGdi internal Invariant, in file %S @ line %i"); |
|
71 |
|
72 void PanicWithInfo(TBitgdiPanic aPanic, const TDesC& aFileName, const TDesC& aPanicName, TInt aLine) |
|
73 { |
|
74 TBuf<256> buf; |
|
75 buf.Format(KBITGDIPanicDesc1, &aPanicName, &aFileName, aLine); |
|
76 RDebug::Print(buf); |
|
77 Panic(aPanic); |
|
78 } |
|
79 |
|
80 void PanicWithCondAndInfo(TBitgdiPanic aPanic, const TDesC& aCondition, const TDesC& aFileName, const TDesC& aPanicName, TInt aLine) |
|
81 { |
|
82 TBuf<256> buf; |
|
83 buf.Format(KBITGDIPanicDesc1, &aPanicName, &aFileName, aLine); |
|
84 RDebug::Print(buf); |
|
85 |
|
86 buf.Format(KBITGDIPanicDesc2, &aCondition); |
|
87 RDebug::Print(buf); |
|
88 Panic(aPanic); |
|
89 } |
|
90 |
|
91 void InvariantWithCondAndInfo(const TDesC& aCondition, const TDesC& aFileName, TInt aLine) |
|
92 { |
|
93 TBuf<256> buf; |
|
94 buf.Format(KBITGDIPanicDesc3, &aFileName, aLine); |
|
95 RDebug::Print(buf); |
|
96 |
|
97 buf.Format(KBITGDIPanicDesc2, &aCondition); |
|
98 RDebug::Print(buf); |
|
99 User::Invariant(); |
|
100 } |
|
101 |
|
102 |
|
103 // |
|
104 // CFbsBitGc |
|
105 // |
|
106 |
|
107 |
|
108 /** Factory function for creating a CFbsBitGc object |
|
109 The object is then ready for a call to Activate(). |
|
110 @return A pointer to the newly created object. */ |
|
111 EXPORT_C CFbsBitGc* CFbsBitGc::NewL() |
|
112 { |
|
113 CFbsBitGc* bitGc = new(ELeave) CFbsBitGc; |
|
114 CleanupStack::PushL(bitGc); |
|
115 bitGc->iFbsBitGcExtraData = new(ELeave) CFbsBitGcExtraData; |
|
116 CleanupStack::Pop(bitGc); |
|
117 return bitGc; |
|
118 } |
|
119 |
|
120 CFbsBitGc::CFbsBitGc(): |
|
121 CBitmapContext(), |
|
122 iBrushBitmap(), |
|
123 iBrushUsed(EFalse), |
|
124 iBrushColor(KRgbWhite), |
|
125 iBrushOrigin(TPoint(0,0)), |
|
126 iBrushStyle(ENullBrush), |
|
127 iClipRect(TRect(0,0,0,0)), |
|
128 iDefaultRegion(), |
|
129 iDefaultRegionPtr(NULL), |
|
130 iUserClipRect(TRect(0,0,0,0)), |
|
131 iDevice(NULL), |
|
132 iDitherOrigin(TPoint(0,0)), |
|
133 iDotLength(0), |
|
134 iDotMask(0), |
|
135 iDotParam(0), |
|
136 iDotDirection(1), |
|
137 iDrawMode(EDrawModePEN), |
|
138 iFont(), |
|
139 iCharJustExcess(0), |
|
140 iCharJustNum(0), |
|
141 iWordJustExcess(0), |
|
142 iWordJustNum(0), |
|
143 iLastPrintPosition(TPoint(0,0)), |
|
144 iLinePosition(TPoint(0,0)), |
|
145 iOrigin(TPoint(0,0)), |
|
146 iPenColor(KRgbBlack), |
|
147 iPenStyle(ESolidPen), |
|
148 iPenSize(TSize(1,1)), |
|
149 iShadowMode(CFbsDrawDevice::ENoShadow), |
|
150 iAutoUpdateJustification(ETrue), |
|
151 iFadeBlackMap(128), |
|
152 iFadeWhiteMap(255), |
|
153 iStrikethrough(EStrikethroughOff), |
|
154 iUnderline(EUnderlineOff), |
|
155 iUserDisplayMode(ENone) |
|
156 {} |
|
157 |
|
158 |
|
159 /** Frees all resources owned by the object. */ |
|
160 EXPORT_C CFbsBitGc::~CFbsBitGc() |
|
161 { |
|
162 Reset(); |
|
163 iBrushBitmap.Reset(); |
|
164 iClippingRegion.Close(); |
|
165 delete iFbsBitGcExtraData; |
|
166 } |
|
167 |
|
168 /** Sets the object to draw to a particular device |
|
169 @param aDevice The target device. */ |
|
170 EXPORT_C void CFbsBitGc::Activate(CFbsDevice* aDevice) |
|
171 { |
|
172 if (!aDevice) |
|
173 return; |
|
174 iDevice = aDevice; |
|
175 TRect deviceRect; |
|
176 iDevice->iDrawDevice->GetDrawRect(deviceRect); |
|
177 iDefaultRegion.Clear(); |
|
178 iDefaultRegion.AddRect(deviceRect); |
|
179 iDefaultRegionPtr = &iDefaultRegion; |
|
180 iUserClipRect = deviceRect; |
|
181 iDrawnTo.SetWidth(0); |
|
182 iDrawnTo.SetHeight(0); |
|
183 iAutoUpdateJustification = ETrue; |
|
184 } |
|
185 |
|
186 /** Sets the object to draw to a particular device but doesn't 'use up' |
|
187 justification settings when drawing text. |
|
188 This is similar to Activate(). |
|
189 @param aDevice The target device. */ |
|
190 EXPORT_C void CFbsBitGc::ActivateNoJustAutoUpdate(CFbsDevice* aDevice) |
|
191 { |
|
192 Activate(aDevice); |
|
193 iAutoUpdateJustification = EFalse; |
|
194 } |
|
195 |
|
196 void CFbsBitGc::SetupDevice() const |
|
197 { |
|
198 CFbsDrawDevice* drawDevice = iDevice->iDrawDevice; |
|
199 drawDevice->SetDitherOrigin(iDitherOrigin); |
|
200 drawDevice->SetShadowMode(CFbsDrawDevice::TShadowMode(iShadowMode)); |
|
201 drawDevice->SetFadingParameters(iFadeBlackMap,iFadeWhiteMap); |
|
202 drawDevice->SetUserDisplayMode(iUserDisplayMode); |
|
203 } |
|
204 |
|
205 void CFbsBitGc::CheckDevice() const |
|
206 { |
|
207 BG_ASSERT_ALWAYS(iDevice,EBitgdiPanicNoDevicePresent); |
|
208 } |
|
209 |
|
210 TBool CFbsBitGc::CheckDevice(const TRect& aRect) const |
|
211 { |
|
212 BG_ASSERT_ALWAYS(iDevice,EBitgdiPanicNoDevicePresent); |
|
213 |
|
214 return aRect.IsEmpty(); |
|
215 } |
|
216 |
|
217 /** Externalizes an object of this class to a write stream. |
|
218 It is important that the brush bitmap of the GC is maintained between calls |
|
219 to externalize and internalize. The brush bitmap handle is externalized, |
|
220 not the bitmap data. This is done for performance. |
|
221 |
|
222 @param aWriteStream Stream to which the object should be externalized. |
|
223 @internalAll */ |
|
224 EXPORT_C void CFbsBitGc::ExternalizeL(RWriteStream& aWriteStream) |
|
225 { |
|
226 aWriteStream << KFbsBitGc_VerNo; |
|
227 TInt bitmapHandle=iBrushBitmap.Handle(); |
|
228 aWriteStream.WriteInt32L(bitmapHandle); |
|
229 iBrushColor.ExternalizeL(aWriteStream); |
|
230 aWriteStream.WriteInt8L(iBrushUsed); |
|
231 aWriteStream << iBrushOrigin; |
|
232 aWriteStream.WriteUint8L(iBrushStyle); |
|
233 aWriteStream << iDitherOrigin; |
|
234 aWriteStream << iUserClipRect; |
|
235 aWriteStream << iDrawnTo; |
|
236 aWriteStream.WriteUint32L(iDotLength); |
|
237 aWriteStream.WriteUint32L(iDotMask); |
|
238 aWriteStream.WriteUint32L(iDotParam); |
|
239 aWriteStream.WriteUint32L(iDotDirection); |
|
240 aWriteStream.WriteUint8L(iDrawMode); |
|
241 aWriteStream.WriteUint32L(iCharJustExcess); |
|
242 aWriteStream.WriteUint32L(iCharJustNum); |
|
243 aWriteStream.WriteUint32L(iWordJustExcess); |
|
244 aWriteStream.WriteUint32L(iWordJustNum); |
|
245 aWriteStream << iLastPrintPosition; |
|
246 aWriteStream << iLinePosition; |
|
247 aWriteStream << iOrigin; |
|
248 iPenColor.ExternalizeL(aWriteStream); |
|
249 aWriteStream.WriteUint8L(iPenStyle); |
|
250 aWriteStream << iPenSize; |
|
251 aWriteStream << iShadowMode; |
|
252 aWriteStream << iAutoUpdateJustification; |
|
253 aWriteStream << iFadeBlackMap; |
|
254 aWriteStream << iFadeWhiteMap; |
|
255 aWriteStream.WriteUint8L(iStrikethrough); |
|
256 aWriteStream.WriteUint8L(iUnderline); |
|
257 |
|
258 const TFontSpec fontSpec=iFont.FontSpecInTwips(); |
|
259 fontSpec.ExternalizeL(aWriteStream); |
|
260 |
|
261 aWriteStream.WriteUint8L(iUserDisplayMode); |
|
262 iFbsBitGcExtraData->ShadowColor().ExternalizeL(aWriteStream); |
|
263 } |
|
264 |
|
265 /** Internalizes an object of this class from a read stream. |
|
266 It is important that the brush bitmap of the GC is maintained between calls |
|
267 to externalize and internalize. The brush bitmap handle is internalized, |
|
268 not the bitmap data. |
|
269 |
|
270 @param aReadStream Stream from which the object is to be internalized. |
|
271 @internalAll */ |
|
272 EXPORT_C void CFbsBitGc::InternalizeL(RReadStream& aReadStream) |
|
273 { |
|
274 TUint16 archiveVerNo = 0; |
|
275 aReadStream >> archiveVerNo; |
|
276 TInt bitmapHandle=aReadStream.ReadInt32L(); |
|
277 if (bitmapHandle) |
|
278 { |
|
279 UseBrushPattern(bitmapHandle); |
|
280 } |
|
281 iBrushColor.InternalizeL(aReadStream); |
|
282 iBrushUsed=aReadStream.ReadInt8L(); |
|
283 aReadStream >> iBrushOrigin; |
|
284 iBrushStyle=(TBrushStyle)aReadStream.ReadUint8L(); |
|
285 aReadStream >> iDitherOrigin; |
|
286 aReadStream >> iUserClipRect; |
|
287 aReadStream >> iDrawnTo; |
|
288 iDotLength=aReadStream.ReadUint32L(); |
|
289 iDotMask=aReadStream.ReadUint32L(); |
|
290 iDotParam=aReadStream.ReadUint32L(); |
|
291 iDotDirection=aReadStream.ReadUint32L(); |
|
292 iDrawMode=(TDrawMode)aReadStream.ReadUint8L(); |
|
293 iCharJustExcess=aReadStream.ReadUint32L(); |
|
294 iCharJustNum=aReadStream.ReadUint32L(); |
|
295 iWordJustExcess=aReadStream.ReadUint32L(); |
|
296 iWordJustNum=aReadStream.ReadUint32L(); |
|
297 aReadStream >> iLastPrintPosition; |
|
298 aReadStream >> iLinePosition; |
|
299 aReadStream >> iOrigin; |
|
300 iPenColor.InternalizeL(aReadStream); |
|
301 iPenStyle=(TPenStyle)aReadStream.ReadUint8L(); |
|
302 aReadStream >> iPenSize; |
|
303 SetPenSize(iPenSize); |
|
304 aReadStream >> iShadowMode; |
|
305 aReadStream >> iAutoUpdateJustification; |
|
306 aReadStream >> iFadeBlackMap; |
|
307 aReadStream >> iFadeWhiteMap; |
|
308 iStrikethrough=(TFontStrikethrough)aReadStream.ReadUint8L(); |
|
309 iUnderline=(TFontUnderline)aReadStream.ReadUint8L(); |
|
310 TFontSpec fontSpec; |
|
311 fontSpec.InternalizeL(aReadStream); |
|
312 if (fontSpec.iHeight != 0) |
|
313 { |
|
314 CFbsFont* font = NULL; |
|
315 User::LeaveIfError(iDevice->GetNearestFontToDesignHeightInTwips(font,fontSpec)); |
|
316 TInt err = iFont.Duplicate(font->Handle()); |
|
317 iDevice->ReleaseFont(font); |
|
318 User::LeaveIfError(err); |
|
319 UseFont(iFont.Handle()); |
|
320 } |
|
321 iUserDisplayMode=(TDisplayMode)aReadStream.ReadUint8L(); |
|
322 if(archiveVerNo < EFbsBitGc_Ver02) //Without shadowcolor |
|
323 { |
|
324 //Initialize it with the default value |
|
325 iFbsBitGcExtraData->SetShadowColor(KDefaultShadowColor); |
|
326 } |
|
327 else //With shadowcolor |
|
328 { |
|
329 TRgb shadowColor; |
|
330 shadowColor.InternalizeL(aReadStream); |
|
331 iFbsBitGcExtraData->SetShadowColor(shadowColor); |
|
332 } |
|
333 } |
|
334 |
|
335 /** Copies all settings from the specified bitmap graphics context. |
|
336 @param aGc The bitmap graphics context whose settings are to be copied. */ |
|
337 EXPORT_C void CFbsBitGc::CopySettings(const CFbsBitGc& aGc) |
|
338 { |
|
339 iBrushColor = aGc.iBrushColor; |
|
340 iBrushUsed = aGc.iBrushUsed; |
|
341 iBrushOrigin = aGc.iBrushOrigin; |
|
342 iBrushStyle = aGc.iBrushStyle; |
|
343 iDefaultRegionPtr = aGc.iDefaultRegionPtr; |
|
344 iDitherOrigin = aGc.iDitherOrigin; |
|
345 iDotLength = aGc.iDotLength; |
|
346 iDotMask = aGc.iDotMask; |
|
347 iDotParam = aGc.iDotParam; |
|
348 iDotDirection = aGc.iDotDirection; |
|
349 iDrawMode = aGc.iDrawMode; |
|
350 iCharJustExcess = aGc.iCharJustExcess; |
|
351 iCharJustNum = aGc.iCharJustNum; |
|
352 iWordJustExcess = aGc.iWordJustExcess; |
|
353 iWordJustNum = aGc.iWordJustNum; |
|
354 iLastPrintPosition = aGc.iLastPrintPosition; |
|
355 iLinePosition = aGc.iLinePosition; |
|
356 iOrigin = aGc.iOrigin; |
|
357 iPenColor = aGc.iPenColor; |
|
358 iPenStyle = aGc.iPenStyle; |
|
359 SetPenSize(aGc.iPenSize); |
|
360 iShadowMode = aGc.iShadowMode; |
|
361 iStrikethrough = aGc.iStrikethrough; |
|
362 iUnderline = aGc.iUnderline; |
|
363 iUserDisplayMode = aGc.iUserDisplayMode; |
|
364 if(aGc.iFont.Handle()) |
|
365 UseFont(aGc.iFont.Handle()); |
|
366 if(aGc.iBrushBitmap.Handle()) |
|
367 UseBrushPattern(aGc.iBrushBitmap.Handle()); |
|
368 iFbsBitGcExtraData->SetShadowColor(aGc.iFbsBitGcExtraData->ShadowColor()); |
|
369 } |
|
370 |
|
371 /** Gets a pointer to the graphics device for the graphics context. |
|
372 The graphics device is the device currently being drawn to. |
|
373 The function provides a concrete implementation of the pure virtual function |
|
374 CGraphicsContext::Device(). The function behaviour is the same as documented |
|
375 in that class. |
|
376 @see CGraphicsContext::Device() */ |
|
377 EXPORT_C CGraphicsDevice* CFbsBitGc::Device() const |
|
378 { |
|
379 return iDevice; |
|
380 } |
|
381 |
|
382 /** Discards a non-built-in brush pattern. |
|
383 The function provides a concrete implementation of the pure virtual function |
|
384 CGraphicsContext::DiscardBrushPattern(). The function behaviour is the same |
|
385 as documented in that class. |
|
386 @see CGraphicsContext::DiscardBrushPattern() */ |
|
387 EXPORT_C void CFbsBitGc::DiscardBrushPattern() |
|
388 { |
|
389 iBrushBitmap.Reset(); |
|
390 iBrushUsed = EFalse; |
|
391 if (iBrushStyle == EPatternedBrush) |
|
392 iBrushStyle = ENullBrush; |
|
393 } |
|
394 |
|
395 /** Discards a selected device font. |
|
396 The function provides a concrete implementation of the pure virtual function |
|
397 CGraphicsContext::DiscardFont(). The function behaviour is the same as documented |
|
398 in that class. |
|
399 @see CGraphicsContext::DiscardFont() */ |
|
400 EXPORT_C void CFbsBitGc::DiscardFont() |
|
401 { |
|
402 iFont.Reset(); |
|
403 } |
|
404 |
|
405 /** Maps pixels in the specified rectangle. |
|
406 The function tries to match the colour of a pixel with one of the RGB values |
|
407 in an array of RGB pairs. If there is a match, the colour is changed to the |
|
408 value specified in the other RGB in the RGB pair. |
|
409 @param aRect The rectangle in which pixels are to be mapped. |
|
410 @param aColors A pointer to a set of RGB pairs. |
|
411 @param aNumPairs The number of pairs |
|
412 @param aMapForwards ETrue, mapping is done from the first RGB to the second |
|
413 RGB in the pair; EFalse, mapping is done from the second RGB to the first |
|
414 RGB in the pair. */ |
|
415 EXPORT_C void CFbsBitGc::MapColors(const TRect& aRect, |
|
416 const TRgb* aColors, |
|
417 TInt aNumPairs, |
|
418 TBool aMapForwards) |
|
419 { |
|
420 if (CheckDevice(aRect) || !aColors) |
|
421 return; |
|
422 |
|
423 TRect rcpy(aRect); |
|
424 rcpy.Move(iOrigin); |
|
425 AddRect(rcpy); |
|
426 if (UserClipRect(rcpy)) |
|
427 return; |
|
428 |
|
429 SetupDevice(); |
|
430 iDevice->DrawingBegin(); |
|
431 |
|
432 CFbsDrawDevice* drawDevice = iDevice->iDrawDevice; |
|
433 |
|
434 #if defined(_DEBUG) |
|
435 TRect deviceRect; |
|
436 drawDevice->GetDrawRect(deviceRect); |
|
437 #endif |
|
438 |
|
439 const TInt limit = iDefaultRegionPtr->Count(); |
|
440 for (TInt count = 0; count < limit; count++) |
|
441 { |
|
442 iClipRect = (*iDefaultRegionPtr)[count]; |
|
443 if (!iClipRect.Intersects(rcpy)) |
|
444 continue; |
|
445 |
|
446 iClipRect.Intersection(rcpy); |
|
447 |
|
448 BG_ASSERT_DEBUG(iClipRect.iTl.iX >= deviceRect.iTl.iX, EBitgdiPanicOutOfBounds); |
|
449 BG_ASSERT_DEBUG(iClipRect.iTl.iY >= deviceRect.iTl.iY, EBitgdiPanicOutOfBounds); |
|
450 BG_ASSERT_DEBUG(iClipRect.iBr.iX <= deviceRect.iBr.iX, EBitgdiPanicOutOfBounds); |
|
451 BG_ASSERT_DEBUG(iClipRect.iBr.iY <= deviceRect.iBr.iY, EBitgdiPanicOutOfBounds); |
|
452 |
|
453 drawDevice->MapColors(iClipRect,aColors,aNumPairs,aMapForwards); |
|
454 drawDevice->UpdateRegion(iClipRect); |
|
455 } |
|
456 |
|
457 iDevice->DrawingEnd(); |
|
458 } |
|
459 |
|
460 /** Sets the internal drawing position relative to the co-ordinate origin. |
|
461 A subsequent call to DrawLineTo() or DrawLineBy() uses the new drawing point |
|
462 as the start point for the line drawn.The function provides a concrete |
|
463 implementation of the pure virtual function CGraphicsContext::MoveTo(). |
|
464 The function behaviour is the same as documented in that class. */ |
|
465 EXPORT_C void CFbsBitGc::MoveTo(const TPoint& aPoint) |
|
466 { |
|
467 iLinePosition = aPoint; |
|
468 } |
|
469 |
|
470 /** Sets the drawing point relative to the current co-ordinates. |
|
471 The function provides a concrete implementation of the pure virtual |
|
472 function CGraphicsContext::MoveBy(). The function behaviour |
|
473 is the same as documented in that class. */ |
|
474 EXPORT_C void CFbsBitGc::MoveBy(const TPoint& aVector) |
|
475 { |
|
476 iLinePosition += aVector; |
|
477 } |
|
478 |
|
479 /** Resets the graphics context to its default settings. |
|
480 The function provides a concrete implementation of the pure virtual function |
|
481 CGraphicsContext::Reset(). The function behaviour is the same as documented |
|
482 in that class. |
|
483 @see CGraphicsContext::Reset() */ |
|
484 EXPORT_C void CFbsBitGc::Reset() |
|
485 { |
|
486 iDefaultRegionPtr = &iDefaultRegion; |
|
487 if (iDefaultRegion.Count() == 0) |
|
488 iUserClipRect = TRect(0,0,0,0); |
|
489 else |
|
490 iUserClipRect = iDefaultRegion[0]; |
|
491 iLastPrintPosition.SetXY(0,0); |
|
492 if(iFbsBitGcExtraData) |
|
493 { |
|
494 iFbsBitGcExtraData->Reset(); |
|
495 } |
|
496 iPenColor = KRgbBlack; |
|
497 iPenStyle = ESolidPen; |
|
498 iPenSize.SetSize(1,1); |
|
499 iDrawMode = EDrawModePEN; |
|
500 iFont.Reset(); |
|
501 iLinePosition.SetXY(0,0); |
|
502 iOrigin.SetXY(0,0); |
|
503 iBrushUsed = EFalse; |
|
504 iBrushColor = KRgbWhite; |
|
505 iBrushOrigin.SetXY(0,0); |
|
506 iBrushStyle = ENullBrush; |
|
507 iCharJustExcess = 0; |
|
508 iCharJustNum = 0; |
|
509 iWordJustExcess = 0; |
|
510 iWordJustNum = 0; |
|
511 iDitherOrigin.SetXY(0,0); |
|
512 iDotLength = 0; |
|
513 iDotMask = 0; |
|
514 iDotParam = 0; |
|
515 iDotDirection = 1; |
|
516 iShadowMode = CFbsDrawDevice::ENoShadow; |
|
517 iStrikethrough = EStrikethroughOff; |
|
518 iUnderline = EUnderlineOff; |
|
519 iUserDisplayMode = ENone; |
|
520 } |
|
521 |
|
522 /** Needs to be called if the device is resized. |
|
523 This only applies to devices of type CFbsBitmapDevice. */ |
|
524 EXPORT_C void CFbsBitGc::Resized() |
|
525 { |
|
526 CheckDevice(); |
|
527 |
|
528 TRect deviceRect; |
|
529 iDevice->iDrawDevice->GetDrawRect(deviceRect); |
|
530 iUserClipRect = deviceRect; |
|
531 iDefaultRegion.Clear(); |
|
532 iDefaultRegion.AddRect(deviceRect); |
|
533 iDefaultRegionPtr = &iDefaultRegion; |
|
534 |
|
535 if (deviceRect.Contains(iLastPrintPosition)) |
|
536 iLastPrintPosition.SetXY(0,0); |
|
537 if (deviceRect.Contains(iLinePosition)) |
|
538 iLinePosition.SetXY(0,0); |
|
539 if (deviceRect.Contains(iOrigin)) |
|
540 iOrigin.SetXY(0,0); |
|
541 if (deviceRect.Contains(iBrushOrigin)) |
|
542 iBrushOrigin.SetXY(0,0); |
|
543 } |
|
544 |
|
545 /**Returns current setting of brush color. |
|
546 @internalAll*/ |
|
547 EXPORT_C TRgb CFbsBitGc::BrushColor() |
|
548 { |
|
549 return iBrushColor; |
|
550 } |
|
551 |
|
552 /** Sets the brush pattern origin. |
|
553 The function provides a concrete implementation of the pure virtual |
|
554 function CGraphicsContext::SetBrushOrigin(). The function |
|
555 behaviour is the same as documented in that class. */ |
|
556 EXPORT_C void CFbsBitGc::SetBrushOrigin(const TPoint& origin) |
|
557 { |
|
558 iBrushOrigin = origin; |
|
559 } |
|
560 |
|
561 /**Sets the brush colour. |
|
562 The function provides a concrete implementation of the pure virtual |
|
563 function CGraphicsContext::SetBrushColor(). The function |
|
564 behaviour is the same as documented in that class. */ |
|
565 EXPORT_C void CFbsBitGc::SetBrushColor(const TRgb& aColor) |
|
566 { |
|
567 iBrushColor = aColor; |
|
568 } |
|
569 |
|
570 /** Sets the brush style. |
|
571 The function provides a concrete implementation of the pure virtual |
|
572 function CGraphicsContext::SetBrushStyle(). The function |
|
573 behaviour is the same as documented in that class. */ |
|
574 EXPORT_C void CFbsBitGc::SetBrushStyle(TBrushStyle aStyle) |
|
575 { |
|
576 iBrushStyle = aStyle; |
|
577 } |
|
578 |
|
579 |
|
580 /** Sets the dither origin. |
|
581 This is only useful for modes that do dithering. If the display is scrolled |
|
582 an odd number of pixels then the (2x2) dither pattern will not match up for |
|
583 new drawing unless this is called. |
|
584 @param aPoint The dither origin. */ |
|
585 EXPORT_C void CFbsBitGc::SetDitherOrigin(const TPoint& aPoint) |
|
586 { |
|
587 iDitherOrigin = iOrigin + aPoint; |
|
588 } |
|
589 |
|
590 /** Sets the character justification. |
|
591 The function provides a concrete implementation of the pure virtual |
|
592 function CGraphicsContext::SetCharJustification(). The |
|
593 function behaviour is the same as documented in that class. */ |
|
594 EXPORT_C void CFbsBitGc::SetCharJustification(TInt aExcessWidth,TInt aNumChars) |
|
595 { |
|
596 if (aExcessWidth == 0 || aNumChars <= 0) |
|
597 { |
|
598 iCharJustExcess = 0; |
|
599 iCharJustNum = 0; |
|
600 } |
|
601 else |
|
602 { |
|
603 iCharJustExcess = aExcessWidth; |
|
604 iCharJustNum = aNumChars; |
|
605 } |
|
606 } |
|
607 |
|
608 /** Sets the clipping rectangle. |
|
609 This function provides a concrete implementation of the pure virtual function |
|
610 CGraphicsContext::SetClippingRect(). The function behaviour is the same as |
|
611 documented in that class. |
|
612 @see CGraphicsContext::SetClippingRect() */ |
|
613 EXPORT_C void CFbsBitGc::SetClippingRect(const TRect& aRect) |
|
614 { |
|
615 CheckDevice(); |
|
616 |
|
617 TRect deviceRect; |
|
618 iDevice->iDrawDevice->GetDrawRect(deviceRect); |
|
619 iUserClipRect = deviceRect; |
|
620 iUserClipRect.Intersection(TRect(aRect.iTl + iOrigin,aRect.iBr + iOrigin)); |
|
621 } |
|
622 |
|
623 /** Cancels clipping rectangle and region. */ |
|
624 EXPORT_C void CFbsBitGc::CancelClipping() |
|
625 { |
|
626 CancelClippingRect(); |
|
627 CancelClippingRegion(); |
|
628 } |
|
629 |
|
630 /** Cancels any clipping rectangle. |
|
631 Clipping reverts to the full device area, the default. |
|
632 The function provides a concrete implementation of the pure virtual function |
|
633 CGraphicsContext::CancelClippingRect(). The function behaviour is the same |
|
634 as documented in that class. |
|
635 @see CGraphicsContext::CancelClippingRect() */ |
|
636 EXPORT_C void CFbsBitGc::CancelClippingRect() |
|
637 { |
|
638 if (iDefaultRegion.Count() == 0) |
|
639 iUserClipRect = TRect(0,0,0,0); |
|
640 else |
|
641 iUserClipRect = iDefaultRegion[0]; |
|
642 } |
|
643 |
|
644 /** Cancels the clipping region. */ |
|
645 EXPORT_C void CFbsBitGc::CancelClippingRegion() |
|
646 { |
|
647 iDefaultRegionPtr = &iDefaultRegion; |
|
648 } |
|
649 |
|
650 /** Sets the word justification. |
|
651 The function provides a concrete implementation of the pure virtual |
|
652 function CGraphicsContext::SetWordJustification(). The |
|
653 function behaviour is the same as documented in that class. */ |
|
654 EXPORT_C void CFbsBitGc::SetWordJustification(TInt aExcessWidth,TInt aNumGaps) |
|
655 { |
|
656 if (aExcessWidth <= 0 || aNumGaps <= 0) |
|
657 { |
|
658 iWordJustExcess = 0; |
|
659 iWordJustNum = 0; |
|
660 } |
|
661 else |
|
662 { |
|
663 iWordJustExcess = aExcessWidth; |
|
664 iWordJustNum = aNumGaps; |
|
665 } |
|
666 } |
|
667 |
|
668 /** Sets a clipping region by storing a pointer to the TRegion parameter. |
|
669 This function provides a concrete implementation of the pure virtual |
|
670 function CGraphicsContext::SetClippingRegion(). The function behaviour is the |
|
671 same as documented in that class. |
|
672 @panic BITGDI 10 if aRegion is invalid or if aRegion is not contained by the |
|
673 device area. */ |
|
674 EXPORT_C void CFbsBitGc::SetClippingRegion(const TRegion* aRegion) |
|
675 { |
|
676 if (!aRegion) |
|
677 { |
|
678 iDefaultRegionPtr = &iDefaultRegion; |
|
679 return; |
|
680 } |
|
681 |
|
682 BG_ASSERT_ALWAYS(!aRegion->CheckError(),EBitgdiPanicInvalidRegion); |
|
683 BG_ASSERT_ALWAYS(aRegion->IsContainedBy(iDefaultRegion.BoundingRect()),EBitgdiPanicInvalidRegion); |
|
684 |
|
685 iDefaultRegionPtr = aRegion; |
|
686 } |
|
687 |
|
688 /** Sets a clipping region by storing a copy of the TRegion parameter. |
|
689 @param aRegion The clipping region to be stored and used. aRegion must be valid and bounded withing the iDefaultRegion. |
|
690 @return KErrNone if successful; KErrArgument if aRegion is invalid, KErrMemory if the region could not be allocated. |
|
691 @see CGraphicsContext::SetClippingRegion(). |
|
692 */ |
|
693 EXPORT_C TInt CFbsBitGc::SetClippingRegion(const TRegion& aRegion) |
|
694 { |
|
695 if (aRegion.CheckError() || !aRegion.IsContainedBy(iDefaultRegion.BoundingRect())) |
|
696 return KErrArgument; |
|
697 |
|
698 iClippingRegion.Copy(aRegion); |
|
699 if (iClippingRegion.CheckError()) |
|
700 return KErrNoMemory; |
|
701 |
|
702 iDefaultRegionPtr = &iClippingRegion; |
|
703 |
|
704 return KErrNone; |
|
705 } |
|
706 |
|
707 /** Sets the drawing mode. |
|
708 This affects the colour that is actually drawn, because it defines the way |
|
709 that the current screen colour logically combines with the current pen colour |
|
710 and brush colour. |
|
711 The function provides a concrete implementation of the pure virtual function |
|
712 CGraphicsContext::SetDrawMode(). The function behaviour is the same as documented |
|
713 in that class. |
|
714 @see CGraphicsContext::SetDrawMode() */ |
|
715 EXPORT_C void CFbsBitGc::SetDrawMode(CGraphicsContext::TDrawMode aDrawMode) |
|
716 { |
|
717 iDrawMode = aDrawMode; |
|
718 } |
|
719 |
|
720 /**Returns current setting of pen color. |
|
721 @internalAll*/ |
|
722 EXPORT_C TRgb CFbsBitGc::PenColor() |
|
723 { |
|
724 return iPenColor; |
|
725 } |
|
726 |
|
727 /** Sets the position of the co-ordinate origin. |
|
728 All subsequent drawing operations are then done relative to this |
|
729 origin.The function provides a concrete implementation of the pure |
|
730 virtual function CGraphicsContext::SetOrigin(). The |
|
731 function behaviour is the same as documented in that class. */ |
|
732 EXPORT_C void CFbsBitGc::SetOrigin(const TPoint& aPoint) |
|
733 { |
|
734 iDitherOrigin -= iOrigin; |
|
735 iOrigin = aPoint; |
|
736 iDitherOrigin += iOrigin; |
|
737 } |
|
738 |
|
739 /** Sets the pen colour. |
|
740 The function provides a concrete implementation of the pure virtual |
|
741 function CGraphicsContext::SetPenColor(). The function |
|
742 behaviour is the same as documented in that class. */ |
|
743 EXPORT_C void CFbsBitGc::SetPenColor(const TRgb& aColor) |
|
744 { |
|
745 iPenColor = aColor; |
|
746 } |
|
747 |
|
748 |
|
749 /** Sets the line drawing style for the pen. |
|
750 The function provides a concrete implementation of the pure virtual function |
|
751 CGraphicsContext::SetPenStyle(). The function behaviour is the same as documented |
|
752 in that class. |
|
753 @see CGraphicsContext::SetPenStyle() */ |
|
754 EXPORT_C void CFbsBitGc::SetPenStyle(TPenStyle aStyle) |
|
755 { |
|
756 iPenStyle = aStyle; |
|
757 |
|
758 switch(iPenStyle) |
|
759 { |
|
760 case ENullPen: |
|
761 iDotMask=0; |
|
762 iDotLength=0; |
|
763 break; |
|
764 case EDottedPen: |
|
765 iDotMask=1; |
|
766 iDotLength=4; |
|
767 break; |
|
768 case EDashedPen: |
|
769 iDotMask=7; |
|
770 iDotLength=6; |
|
771 break; |
|
772 case EDotDashPen: |
|
773 iDotMask=113; |
|
774 iDotLength=10; |
|
775 break; |
|
776 case EDotDotDashPen: |
|
777 iDotMask=1809; |
|
778 iDotLength=14; |
|
779 break; |
|
780 default: |
|
781 iDotMask=1; |
|
782 iDotLength=1; |
|
783 break; |
|
784 }; |
|
785 |
|
786 iDotParam=0; |
|
787 } |
|
788 |
|
789 /** Sets the line drawing size for the pen. |
|
790 The function provides a concrete implementation of the pure virtual |
|
791 function CGraphicsContext::SetPenSize(). The function |
|
792 behaviour is the same as documented in that class. */ |
|
793 EXPORT_C void CFbsBitGc::SetPenSize(const TSize& aSize) |
|
794 { |
|
795 iPenSize.SetSize(Abs(aSize.iWidth),Abs(aSize.iHeight)); |
|
796 |
|
797 const TSize maxsize = iDevice->iDrawDevice->SizeInPixels(); |
|
798 |
|
799 iPenSize.iWidth = Min(iPenSize.iWidth,maxsize.iWidth << 1); |
|
800 iPenSize.iHeight = Min(iPenSize.iHeight,maxsize.iHeight << 1); |
|
801 |
|
802 if (iPenSize.iWidth || iPenSize.iHeight) |
|
803 PenAllocate(); |
|
804 else |
|
805 { |
|
806 iFbsBitGcExtraData->ResetPenArray(); |
|
807 } |
|
808 |
|
809 iDotParam = 0; |
|
810 } |
|
811 |
|
812 /** Simulates another graphics mode. |
|
813 Some devices running in some modes can simulate other modes (EGray16 will |
|
814 do EGray4 and EGray2, EGray4 will do EGray2). |
|
815 @param aDisplayMode The display mode to be set. */ |
|
816 EXPORT_C void CFbsBitGc::SetUserDisplayMode(TDisplayMode aDisplayMode) |
|
817 { |
|
818 if(aDisplayMode==iDevice->DisplayMode()) |
|
819 aDisplayMode = ENone; |
|
820 iUserDisplayMode = aDisplayMode; |
|
821 } |
|
822 |
|
823 /** Sets the underline style for all subsequently drawn text. |
|
824 The function provides a concrete implementation of the pure virtual |
|
825 function CGraphicsContext::SetUnderlineStyle(). The |
|
826 function behaviour is the same as documented in that class. */ |
|
827 EXPORT_C void CFbsBitGc::SetUnderlineStyle(TFontUnderline aUnderlineStyle) |
|
828 { |
|
829 iUnderline = aUnderlineStyle; |
|
830 } |
|
831 |
|
832 /** Sets the strikethrough style for all subsequently drawn text. |
|
833 The function provides a concrete implementation of the pure virtual |
|
834 function CGraphicsContext::SetStrikethroughStyle(). The |
|
835 function behaviour is the same as documented in that class. */ |
|
836 EXPORT_C void CFbsBitGc::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle) |
|
837 { |
|
838 iStrikethrough = aStrikethroughStyle; |
|
839 } |
|
840 |
|
841 /** Sets the shadow mode on or off. |
|
842 @param aShadowMode ETrue, shadow mode is on; EFalse, shadow mode is off. EFalse |
|
843 is the default. */ |
|
844 EXPORT_C void CFbsBitGc::SetShadowMode(TBool aShadowMode) |
|
845 { |
|
846 if (aShadowMode) |
|
847 iShadowMode |= CFbsDrawDevice::EShadow; |
|
848 else |
|
849 iShadowMode &= ~CFbsDrawDevice::EShadow; |
|
850 } |
|
851 |
|
852 /** Sets whether the graphics context is faded. |
|
853 The function provides a concrete implementation of the pure virtual |
|
854 function CBitmapContext::SetFaded(). The function |
|
855 behaviour is the same as documented in that class. |
|
856 */ |
|
857 EXPORT_C void CFbsBitGc::SetFaded(TBool aFadeMode) |
|
858 { |
|
859 if (aFadeMode) |
|
860 iShadowMode |= CFbsDrawDevice::EFade; |
|
861 else |
|
862 iShadowMode &= ~CFbsDrawDevice::EFade; |
|
863 } |
|
864 |
|
865 /** Set fading parameters. |
|
866 The function provides a concrete implementation of the pure virtual |
|
867 function CBitmapContext::SetFadingParameters(). The |
|
868 function behaviour is the same as documented in that class. |
|
869 */ |
|
870 EXPORT_C void CFbsBitGc::SetFadingParameters(TUint8 aBlackMap,TUint8 aWhiteMap) |
|
871 { |
|
872 iFadeBlackMap = aBlackMap; |
|
873 iFadeWhiteMap = aWhiteMap; |
|
874 } |
|
875 |
|
876 /** Gets the orientations supported. |
|
877 @param aOrientation[4] An array of four TBool values. Each entry in this |
|
878 array corresponds to successive values of the TGraphicsOrientation enum. |
|
879 If the first array entry has an EFrue value, then the normal orientation |
|
880 is supported; if the second entry array has an ETrue value, |
|
881 then a 90 degree orientation is supported etc. */ |
|
882 EXPORT_C void CFbsBitGc::OrientationsAvailable(TBool aOrientation[4]) |
|
883 { |
|
884 if (iDevice) |
|
885 { |
|
886 iDevice->iDrawDevice->OrientationsAvailable(aOrientation); |
|
887 } |
|
888 else |
|
889 { |
|
890 aOrientation[EGraphicsOrientationNormal] = EFalse; |
|
891 aOrientation[EGraphicsOrientationRotated90] = EFalse; |
|
892 aOrientation[EGraphicsOrientationRotated180] = EFalse; |
|
893 aOrientation[EGraphicsOrientationRotated270] = EFalse; |
|
894 } |
|
895 } |
|
896 |
|
897 /** Sets the orientation. |
|
898 @param aOrientation The required orientation |
|
899 @return ETrue, if the requested orientation is supported; EFalse, otherwise. */ |
|
900 EXPORT_C TBool CFbsBitGc::SetOrientation(TGraphicsOrientation aOrientation) |
|
901 { |
|
902 if (!iDevice) |
|
903 return EFalse; |
|
904 |
|
905 TBool ret = iDevice->SetOrientation(aOrientation); |
|
906 if(ret) |
|
907 { |
|
908 TRect deviceRect; |
|
909 iDevice->iDrawDevice->GetDrawRect(deviceRect); |
|
910 iDefaultRegion.Clear(); |
|
911 iDefaultRegion.AddRect(deviceRect); |
|
912 iUserClipRect = deviceRect; |
|
913 iDrawnTo.SetRect(0,0,0,0); |
|
914 } |
|
915 |
|
916 return ret; |
|
917 } |
|
918 |
|
919 /** Sets the specified bitmap to be used as the brush pattern. |
|
920 @param aBitmap The bitmap.*/ |
|
921 EXPORT_C void CFbsBitGc::UseBrushPattern(const CFbsBitmap* aBitmap) |
|
922 { |
|
923 BG_ASSERT_ALWAYS(aBitmap != NULL,EBitgdiPanicInvalidBitmap); |
|
924 |
|
925 TInt brushResult = UseBrushPattern(((CFbsBitmap*)aBitmap)->Handle()); |
|
926 BG_ASSERT_ALWAYS(brushResult == KErrNone,EBitgdiPanicInvalidBitmap); |
|
927 } |
|
928 |
|
929 /** Sets the specified bitmap to be used as the brush pattern. |
|
930 @param aFbsBitmapHandle The handle number of the bitmap. |
|
931 @return KErrNone, if successful; otherwise another of the other system wide |
|
932 error codes. */ |
|
933 EXPORT_C TInt CFbsBitGc::UseBrushPattern(TInt aFbsBitmapHandle) |
|
934 { |
|
935 BG_ASSERT_ALWAYS(aFbsBitmapHandle,EBitgdiPanicInvalidBitmap); |
|
936 |
|
937 iBrushUsed = ETrue; |
|
938 if (iBrushBitmap.Handle() == aFbsBitmapHandle) |
|
939 return KErrNone; |
|
940 |
|
941 TInt ret = iBrushBitmap.Duplicate(aFbsBitmapHandle); |
|
942 if (ret != KErrNone) |
|
943 iBrushUsed = EFalse; |
|
944 |
|
945 return ret; |
|
946 } |
|
947 |
|
948 /** Selects the device font, identified by handle number, to be used for text drawing. |
|
949 Notes: |
|
950 When the font is no longer required, use DiscardFont() to free up the memory |
|
951 used. If UseFont() is used again without using DiscardFont() then the previous |
|
952 font is discarded automatically. |
|
953 If no font has been selected, and an attempt is made to draw text with DrawText(), |
|
954 then a panic occurs. |
|
955 @param aFontHandle A handle number for a device font. |
|
956 @return The duplicate handle number for the device font. |
|
957 @see CFont */ |
|
958 EXPORT_C void CFbsBitGc::UseFont(const CFont* aFont) |
|
959 { |
|
960 BG_ASSERT_ALWAYS(aFont != NULL,EBitgdiPanicInvalidFont); |
|
961 BG_ASSERT_ALWAYS(aFont->TypeUid() == KCFbsFontUid,EBitgdiPanicInvalidFont); |
|
962 |
|
963 TInt fontResult = UseFont(((CFbsBitGcFont*)aFont)->Handle()); |
|
964 BG_ASSERT_ALWAYS(fontResult == KErrNone,EBitgdiPanicInvalidFont); |
|
965 } |
|
966 |
|
967 /** Selects the device font, identified by handle, to be used for |
|
968 text drawing. |
|
969 Notes:When the font is no longer required, use DiscardFont() to free up the memory used. |
|
970 If UseFont() is used again without using DiscardFont() then the previous font is |
|
971 discarded automatically.If no font has been selected, and an attempt is made to |
|
972 draw text with DrawText(), then a panic occurs. |
|
973 @param aFbsFontHandle A handle for a device font. |
|
974 @return The result of CFbsFont::Duplicate(). */ |
|
975 EXPORT_C TInt CFbsBitGc::UseFont(TInt aFbsFontHandle) |
|
976 { |
|
977 BG_ASSERT_ALWAYS(aFbsFontHandle,EBitgdiPanicInvalidFont); |
|
978 |
|
979 if (iFont.Handle() == aFbsFontHandle) |
|
980 return KErrNone; |
|
981 |
|
982 return iFont.Duplicate(aFbsFontHandle); |
|
983 } |
|
984 |
|
985 /** Selects a device font for text drawing but does not take a copy. |
|
986 The original must not be destroyed until UseFont(), UseFontNoDuplicate(), |
|
987 DiscardFont() or the destructor is called. |
|
988 @param aFont A pointer to the font to be used. */ |
|
989 EXPORT_C void CFbsBitGc::UseFontNoDuplicate(const CFbsBitGcFont* aFont) |
|
990 { |
|
991 DiscardFont(); |
|
992 |
|
993 BG_ASSERT_ALWAYS(aFont->TypeUid() == KCFbsFontUid,EBitgdiPanicInvalidFont); |
|
994 |
|
995 if (aFont->Handle() == NULL) |
|
996 return; |
|
997 |
|
998 iFont = *aFont; |
|
999 } |
|
1000 |
|
1001 /** Tests whether a brush pattern is being used. |
|
1002 @return ETrue, if a brush pattern is being used; EFalse, otherwise. */ |
|
1003 EXPORT_C TBool CFbsBitGc::IsBrushPatternUsed() const |
|
1004 { |
|
1005 return iBrushUsed; |
|
1006 } |
|
1007 |
|
1008 /** Tests whether a font is used. |
|
1009 @return ETrue, if a font is being used; EFalse, otherwise. */ |
|
1010 EXPORT_C TBool CFbsBitGc::IsFontUsed() const |
|
1011 { |
|
1012 if (iFont.Handle()) |
|
1013 return ETrue; |
|
1014 |
|
1015 return EFalse; |
|
1016 } |
|
1017 |
|
1018 TBool CFbsBitGc::UserClipRect(TRect& aRect) |
|
1019 { |
|
1020 if (!aRect.Intersects(iUserClipRect)) |
|
1021 return ETrue; |
|
1022 |
|
1023 aRect.Intersection(iUserClipRect); |
|
1024 |
|
1025 return EFalse; |
|
1026 } |
|
1027 |
|
1028 /** Fetches the bounding rectangle of all drawing done since this function was last |
|
1029 called. |
|
1030 @param aRect The bounding rectangle. */ |
|
1031 EXPORT_C void CFbsBitGc::RectDrawnTo(TRect& aRect) |
|
1032 { |
|
1033 aRect = iDrawnTo; |
|
1034 iDrawnTo.SetRect(0,0,0,0); |
|
1035 } |
|
1036 |
|
1037 /** Updates the justification settings. |
|
1038 This function assumes that ActivateNoJustAutoUpdate() has been used. |
|
1039 @param aText The text for which justification is to be adjusted. */ |
|
1040 EXPORT_C void CFbsBitGc::UpdateJustification(const TDesC& aText) |
|
1041 { |
|
1042 TTextParameters* param = NULL; |
|
1043 UpdateJustification(aText,param); |
|
1044 } |
|
1045 |
|
1046 /** Updates the justification for vertical text. |
|
1047 @param aText The text for which justification is to be adjusted. |
|
1048 @param aUp ETrue, if text is to be justified upwards;EFalse, if text is to |
|
1049 be justified downwards. */ |
|
1050 EXPORT_C void CFbsBitGc::UpdateJustificationVertical(const TDesC& aText, TBool aUp) |
|
1051 { |
|
1052 TTextParameters* param = NULL; |
|
1053 UpdateJustificationVertical(aText,param,aUp); |
|
1054 } |
|
1055 |
|
1056 /** Updates the justification settings. |
|
1057 This function assumes that ActivateNoJustAutoUpdate() has been used. |
|
1058 @param aText The text for which justification is to be adjusted. */ |
|
1059 EXPORT_C void CFbsBitGc::UpdateJustification(const TDesC& aText,const TTextParameters* aParam) |
|
1060 { |
|
1061 if ((iCharJustNum < 1 || iCharJustExcess == 0) && (iWordJustNum < 1 || iWordJustExcess < 1)) |
|
1062 return; |
|
1063 |
|
1064 TInt length = aText.Length(); |
|
1065 CFont::TPositionParam param; |
|
1066 param.iText.Set(aText); // Set the start of the string |
|
1067 if (aParam) |
|
1068 { |
|
1069 length = aParam->iEnd; |
|
1070 param.iPosInText = aParam->iStart; |
|
1071 } |
|
1072 TInt excess = 0; |
|
1073 TInt glyphs = 0; |
|
1074 RShapeInfo shapeInfo; |
|
1075 for (TInt count = 0; count < length; count++) |
|
1076 { |
|
1077 if (iCharJustNum > 0 && iCharJustExcess != 0) |
|
1078 excess += CGraphicsContext::JustificationInPixels(iCharJustExcess, iCharJustNum); |
|
1079 if (iWordJustNum > 0 && iWordJustExcess > 0 && aText[count] == ' ') |
|
1080 excess += CGraphicsContext::JustificationInPixels(iWordJustExcess, iWordJustNum); |
|
1081 |
|
1082 if (iCharJustNum < glyphs + length - count) // there's at least 1 combined glyph to come |
|
1083 { |
|
1084 // otherwise we can skip this slow bit and just increment |
|
1085 if (iFont.GetCharacterPosition2(param, shapeInfo)) |
|
1086 count = param.iPosInText - 1; // -1 'cos it gets incremented anyway |
|
1087 } |
|
1088 glyphs++; |
|
1089 } |
|
1090 if(shapeInfo.IsOpen()) |
|
1091 shapeInfo.Close(); |
|
1092 |
|
1093 iLastPrintPosition.iX += excess; |
|
1094 } |
|
1095 |
|
1096 /** Updates the justification for vertical text. |
|
1097 @param aText The text for which justification is to be adjusted. |
|
1098 @param aUp ETrue, if text is to be justified upwards;EFalse, if text is to |
|
1099 be justified downwards. */ |
|
1100 EXPORT_C void CFbsBitGc::UpdateJustificationVertical(const TDesC& aText,const TTextParameters* aParam,TBool aUp) |
|
1101 { |
|
1102 if ((iCharJustNum < 1 || iCharJustExcess == 0) && (iWordJustNum < 1 || iWordJustExcess < 1)) |
|
1103 return; |
|
1104 |
|
1105 TInt length = aText.Length(); |
|
1106 CFont::TPositionParam param; |
|
1107 param.iText.Set(aText); // Set the start of the string |
|
1108 if (aParam) |
|
1109 { |
|
1110 length = aParam->iEnd; |
|
1111 param.iPosInText = aParam->iStart; |
|
1112 } |
|
1113 TInt excess=0; |
|
1114 TInt glyphs = 0; |
|
1115 RShapeInfo shapeInfo; |
|
1116 for (TInt count = 0; count < length; count++) |
|
1117 { |
|
1118 if (iCharJustNum > 0 && iCharJustExcess != 0) |
|
1119 excess += CGraphicsContext::JustificationInPixels(iCharJustExcess, iCharJustNum); |
|
1120 if (iWordJustNum > 0 && iWordJustExcess > 0 && aText[count] == ' ') |
|
1121 excess += CGraphicsContext::JustificationInPixels(iWordJustExcess, iWordJustNum); |
|
1122 if (iCharJustNum < glyphs + length - count) // there's at least 1 combined glyph to come |
|
1123 { |
|
1124 // otherwise we can skip this slow bit and just increment |
|
1125 if (iFont.GetCharacterPosition2(param, shapeInfo)) |
|
1126 count = param.iPosInText - 1; // -1 'cos it gets incremented anyway |
|
1127 } |
|
1128 glyphs++; |
|
1129 } |
|
1130 if (shapeInfo.IsOpen()) |
|
1131 shapeInfo.Close(); |
|
1132 |
|
1133 if (aUp) |
|
1134 iLastPrintPosition.iY -= excess; |
|
1135 else |
|
1136 iLastPrintPosition.iY += excess; |
|
1137 } |
|
1138 void CFbsBitGc::AddRect(const TRect& aRect) |
|
1139 { |
|
1140 if (iDrawnTo.IsEmpty()) |
|
1141 iDrawnTo = aRect; |
|
1142 else if (!aRect.IsEmpty()) |
|
1143 iDrawnTo.BoundingRect(aRect); |
|
1144 } |
|
1145 |
|
1146 CFbsBitGcExtraData::CFbsBitGcExtraData() |
|
1147 { |
|
1148 iShadowColor = KDefaultShadowColor; //default shadow color |
|
1149 } |
|
1150 |
|
1151 CFbsBitGcExtraData::~CFbsBitGcExtraData() |
|
1152 { |
|
1153 delete[] iPenArray; |
|
1154 } |
|
1155 |
|
1156 void CFbsBitGcExtraData::Reset() |
|
1157 { |
|
1158 SetShadowColor(KDefaultShadowColor); |
|
1159 ResetPenArray(); |
|
1160 } |
|
1161 |
|
1162 #define ORIENTATION_TO_CAP(orientation) (1 << (TInt)orientation) |
|
1163 |
|
1164 CGraphicsAccelerator* CFbsBitGc::GraphicsAccelerator() |
|
1165 { |
|
1166 CGraphicsAccelerator* ga = iDevice->GraphicsAccelerator(); |
|
1167 if(!ga) |
|
1168 return NULL; |
|
1169 |
|
1170 const TGraphicsAcceleratorCaps* caps = ga->Capabilities(); |
|
1171 //iReserved[0] specifies the supported rendering orientations. |
|
1172 //Existing variable name is used to avoid SC break since it is an array. |
|
1173 const TUint orientationCaps = caps->iReserved[0]; |
|
1174 const TGraphicsOrientation orientation = iDevice->Orientation(); |
|
1175 if(iDevice->iScreenDevice |
|
1176 && ((orientationCaps == 0 && orientation !=EGraphicsOrientationNormal) |
|
1177 || ((ORIENTATION_TO_CAP(orientation) & orientationCaps) ==0))) |
|
1178 return NULL; |
|
1179 |
|
1180 if(iUserDisplayMode!=ENone) |
|
1181 return NULL; |
|
1182 |
|
1183 return ga; |
|
1184 } |
|
1185 |
|
1186 /** Replace target device but keep the current state |
|
1187 |
|
1188 @param aDevice The target device |
|
1189 @internalComponent |
|
1190 */ |
|
1191 EXPORT_C void CFbsBitGc::ChangeDevice(CFbsDevice* aDevice) |
|
1192 { |
|
1193 iDevice = aDevice; |
|
1194 } |