|
1 // Copyright (c) 1998-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 <gdi.h> |
|
17 #include <bidi.h> |
|
18 #include "GDIPANIC.h" |
|
19 #include "gdistructs.h" |
|
20 #include "gdiconsts.h" |
|
21 |
|
22 |
|
23 // Global panic function |
|
24 |
|
25 _LIT(KGdiPanicCategory,"GDI"); |
|
26 |
|
27 void Panic(TGdiPanic aError) |
|
28 { |
|
29 User::Panic(KGdiPanicCategory,aError); |
|
30 } |
|
31 |
|
32 _LIT(KGDIPanicDesc1, "Gdi internal Panic %S, in file %S @ line %i"); |
|
33 _LIT(KGDIPanicDesc2, "Assert condition = \"%S\""); |
|
34 _LIT(KGDIPanicDesc3, "Gdi internal %S, in file %S @ line %i"); |
|
35 |
|
36 void PanicWithCondAndInfo(TGdiPanic aError, const TDesC& aCondition, const TDesC& aFileName, const TDesC& aPanicName, TInt aLine) |
|
37 { |
|
38 TBuf<256> buf; |
|
39 buf.Format(KGDIPanicDesc1, &aPanicName, &aFileName, aLine); |
|
40 RDebug::Print(buf); |
|
41 |
|
42 buf.Format(KGDIPanicDesc2, &aCondition); |
|
43 RDebug::Print(buf); |
|
44 Panic(aError); |
|
45 } |
|
46 |
|
47 void PanicLogWithInfo(const TDesC& aCommand, const TDesC& aCondition, const TDesC& aFileName, TInt aLine) |
|
48 { |
|
49 TBuf<256> buf; |
|
50 buf.Format(KGDIPanicDesc3, &aCommand, &aFileName, aLine); |
|
51 RDebug::Print(buf); |
|
52 |
|
53 buf.Format(KGDIPanicDesc2, &aCondition); |
|
54 RDebug::Print(buf); |
|
55 } |
|
56 |
|
57 |
|
58 // |
|
59 // MGraphicsDeviceMap |
|
60 // |
|
61 |
|
62 |
|
63 EXPORT_C MGraphicsDeviceMap::MGraphicsDeviceMap() |
|
64 /** Default constructor. */ |
|
65 {} |
|
66 |
|
67 |
|
68 EXPORT_C MGraphicsDeviceMap::~MGraphicsDeviceMap() |
|
69 /** Destructor. */ |
|
70 {} |
|
71 |
|
72 |
|
73 EXPORT_C TPoint MGraphicsDeviceMap::TwipsToPixels(const TPoint& aTwipPoint) const |
|
74 /** Converts a point in twips to a point in pixels. |
|
75 |
|
76 @param aTwipPoint A point on the graphics device in twips. |
|
77 @return A point on the graphics device in pixels. */ |
|
78 { |
|
79 return TPoint(HorizontalTwipsToPixels(aTwipPoint.iX),VerticalTwipsToPixels(aTwipPoint.iY)); |
|
80 } |
|
81 |
|
82 |
|
83 EXPORT_C TRect MGraphicsDeviceMap::TwipsToPixels(const TRect& aTwipRect) const |
|
84 /** Converts a rectangle in twips to a rectangle in pixels. |
|
85 |
|
86 @param aTwipRect A rectangle on the graphics device in twips |
|
87 @return A rectangle on the graphics device in pixels. */ |
|
88 { |
|
89 return TRect(TwipsToPixels(aTwipRect.iTl),TwipsToPixels(aTwipRect.iBr)); |
|
90 } |
|
91 |
|
92 |
|
93 EXPORT_C TPoint MGraphicsDeviceMap::PixelsToTwips(const TPoint& aPixelPoint) const |
|
94 /** Converts a point in pixels to a point in twips. |
|
95 |
|
96 @param aPixelPoint A point on the graphics device in pixels. |
|
97 @return A point on the graphics device in twips. */ |
|
98 { |
|
99 return TPoint(HorizontalPixelsToTwips(aPixelPoint.iX),VerticalPixelsToTwips(aPixelPoint.iY)); |
|
100 } |
|
101 |
|
102 |
|
103 EXPORT_C TRect MGraphicsDeviceMap::PixelsToTwips(const TRect& aPixelRect) const |
|
104 /** Converts a rectangle in pixels to a rectangle in twips. |
|
105 |
|
106 @param aPixelRect A rectangle on the graphics device in pixels. |
|
107 @return A rectangle on the graphics device in twips. */ |
|
108 { |
|
109 return TRect(PixelsToTwips(aPixelRect.iTl),PixelsToTwips(aPixelRect.iBr)); |
|
110 } |
|
111 |
|
112 // |
|
113 // CGraphicsContext |
|
114 // |
|
115 |
|
116 EXPORT_C TInt CGraphicsContext::JustificationInPixels(TInt aExcessPixels,TInt aTotalUnits,TInt aFirstUnit,TInt aNumUnits) |
|
117 /** Gets the amount of space in pixels by which to adjust letter or word spacing, |
|
118 given the total number of words and spaces, a start space, and the number |
|
119 of units to be adjusted. |
|
120 |
|
121 The first two arguments are the number of pixels (character groups) and the |
|
122 number of units (word spaces) over which justification is to occur. The third |
|
123 argument specifies the current character group or word space, while the final |
|
124 argument specifies the number of units that are to be adjusted. |
|
125 |
|
126 A panic occurs if aExcessPixels is 0, aTotalUnits is not greater than 0, or |
|
127 aFirstUnit is not less than aTotalUnits. |
|
128 |
|
129 @param aExcessPixels The number of pixels by which the width of the text is |
|
130 to be changed. It may be positive, in which case the text is stretched, or |
|
131 negative, in which case it is shrunk. |
|
132 @param aTotalUnits The number of word spaces over which the change in width |
|
133 is to be distributed. |
|
134 @param aFirstUnit The current unit — the character group or word space we |
|
135 are 'on'. |
|
136 @param aNumUnits The number of units that are to be adjusted — starting |
|
137 at aFirstUnit. |
|
138 @return The number of pixels to be added to the width of the current unit. |
|
139 @see SetWordJustification() |
|
140 @see SetCharJustification() */ |
|
141 { |
|
142 if(aExcessPixels==0 || aTotalUnits<=0 || aFirstUnit>=aTotalUnits) |
|
143 return(0); |
|
144 TInt noExtra=Abs(aExcessPixels%aTotalUnits); |
|
145 TInt extraPixel=aExcessPixels/Abs(aExcessPixels); |
|
146 GDI_ASSERT_DEBUG_GENERAL( aFirstUnit>=0 , User::Panic(KGdiPanicCategory,KErrArgument) ) ; |
|
147 GDI_ASSERT_DEBUG_GENERAL( aNumUnits>=0 , User::Panic(KGdiPanicCategory,KErrArgument) ) ; |
|
148 if(aFirstUnit+aNumUnits>aTotalUnits) |
|
149 aNumUnits=aTotalUnits-aFirstUnit; |
|
150 TInt clip=aNumUnits*(aExcessPixels/aTotalUnits); |
|
151 if(aFirstUnit>=noExtra) |
|
152 return(clip); |
|
153 if(aFirstUnit+aNumUnits>noExtra) |
|
154 aNumUnits=noExtra-aFirstUnit; |
|
155 return(clip+aNumUnits*extraPixel); |
|
156 } |
|
157 |
|
158 |
|
159 EXPORT_C TInt CGraphicsContext::JustificationInPixels(TInt& aExcessPixels,TInt& aTotalUnits) |
|
160 /** Gets the amount of space in pixels by which to adjust the current letter or |
|
161 word spacing, and also retrieves the number of excess pixels and word spaces |
|
162 remaining after the adjustment is performed. |
|
163 |
|
164 The arguments are the number of remaining pixels (character groups) and units |
|
165 (word spaces) over which justification is to occur. The function can be called |
|
166 repetitively until the number of units is zero, and hence justification is |
|
167 complete. A panic occurs if the number of units is less than one or the amount |
|
168 of pixels is zero. |
|
169 |
|
170 @param aExcessPixels The number of pixels by which the width of the text is |
|
171 to be changed. It may be positive, in which case the text is stretched, or |
|
172 negative, in which case it is shrunk. On return, this is equal to its old |
|
173 value minus the return value. |
|
174 @param aTotalUnits The number of word spaces over which the change in width |
|
175 is to be distributed. On return, this is reduced by one. |
|
176 @return The number of pixels to be added to the width of the current unit. |
|
177 @see SetWordJustification() |
|
178 @see SetCharJustification() */ |
|
179 { |
|
180 GDI_ASSERT_DEBUG_GENERAL(aExcessPixels!=0,User::Panic(KGdiPanicCategory,KErrArgument)); |
|
181 GDI_ASSERT_DEBUG_GENERAL(aTotalUnits>0,User::Panic(KGdiPanicCategory,KErrArgument)); |
|
182 TInt justification=aExcessPixels/aTotalUnits; |
|
183 if(aExcessPixels%aTotalUnits) |
|
184 { |
|
185 if(aExcessPixels>0) |
|
186 justification++; |
|
187 else |
|
188 justification--; |
|
189 } |
|
190 aTotalUnits--; |
|
191 aExcessPixels-=justification; |
|
192 return(justification); |
|
193 } |
|
194 |
|
195 |
|
196 EXPORT_C TInt CGraphicsContext::DrawTextExtended(const TDesC& aText,const TPoint& aPosition, |
|
197 const TDrawTextExtendedParam& aParam) |
|
198 /** Draws text, optionally changing its direction (right-to-left / left-to-right). |
|
199 |
|
200 Apart from reordering the text, the function is the same as the two parameter |
|
201 variant of DrawText(), described above. |
|
202 |
|
203 @param aText The text string to be drawn, optionally changing its direction |
|
204 (right-to-left / left-to-right). |
|
205 @param aPosition A point specifying the position of the left end of the text. |
|
206 @param aParam Indicates whether the text should be drawn from right-to-left |
|
207 (for scripts like Arabic and Hebrew) or left-to-right. |
|
208 @return KErrNoMemory indicates there was an OOM error when reordering the text; |
|
209 KErrNone if the reordering was successful. */ |
|
210 { |
|
211 // Reorder the text bidirectionally. |
|
212 TText* reordered_text = NULL; |
|
213 int error = TBidirectionalState::ReorderText(aText.Ptr(),aText.Length(),aParam.iParRightToLeft,reordered_text); |
|
214 TPtrC p(reordered_text,aText.Length()); |
|
215 DrawText(p,aPosition,aParam); |
|
216 if (reordered_text != aText.Ptr()) |
|
217 delete [] reordered_text; |
|
218 return error; |
|
219 } |
|
220 |
|
221 |
|
222 EXPORT_C void CGraphicsContext::DrawText(const TDesC& aText,const TPoint& aPosition,const TDrawTextParam& /*aParam*/) |
|
223 /** Draws the specified text at the given position using the parameters supplied. |
|
224 |
|
225 @param aText The text to be drawn. |
|
226 @param aPosition The position to draw the text at. |
|
227 @param aParam Parameters to use for text drawing. */ |
|
228 { |
|
229 DrawText(aText,aPosition); |
|
230 } |
|
231 |
|
232 /* |
|
233 Can be used to find out the top and bottom of an underline for the active font. |
|
234 This allows correct calculation of the area required in which to draw text with underline. |
|
235 |
|
236 @param TInt& aTop The top of the underline position |
|
237 @param TInt& aBottom The bottom of the underline position |
|
238 @return TInt KErrNone if successful, else a standard system wide error value. |
|
239 */ |
|
240 EXPORT_C TInt CGraphicsContext::GetUnderlineMetrics(TInt& aTop,TInt& aBottom) |
|
241 { |
|
242 |
|
243 TTwoTInt outputPackage; |
|
244 TTwoTInt* outputPtr = &outputPackage; |
|
245 TInt err = APIExtension(KGetUnderlineMetrics, (TAny*&) outputPtr, NULL); |
|
246 aTop = outputPackage.iTop; |
|
247 aBottom = outputPackage.iBottom; |
|
248 return err; |
|
249 } |
|
250 |
|
251 EXPORT_C TInt CGraphicsContext::SetShadowColor(const TRgb& aShadowColor) |
|
252 { |
|
253 TRgb shadowColor = aShadowColor; |
|
254 TInt *dummy = NULL; |
|
255 return APIExtension(KSetShadowColor, (TAny*&)dummy, (TAny*)&shadowColor); |
|
256 } |
|
257 |
|
258 EXPORT_C TInt CGraphicsContext::GetShadowColor(TRgb& aShadowColor) |
|
259 { |
|
260 TRgb* shadowColor = &aShadowColor; |
|
261 return APIExtension(KGetShadowColor, (TAny*&)shadowColor, NULL); |
|
262 } |
|
263 |
|
264 EXPORT_C TBool CGraphicsContext::IsFbsBitGc() const |
|
265 { |
|
266 TBool isFbsBitGc=EFalse; |
|
267 TBool* isFbsBitGcPtr=&isFbsBitGc; |
|
268 |
|
269 //Have a non const this since want the published API to be const |
|
270 CGraphicsContext *nonConstThis = const_cast<CGraphicsContext*>(this); |
|
271 |
|
272 //The API extension function is non-const, and this is const function |
|
273 TInt err= nonConstThis->APIExtension(KUidIsFbsBitmapGc, (TAny*&)isFbsBitGcPtr, NULL); |
|
274 |
|
275 //on error, return EFalse |
|
276 return (!err ? isFbsBitGc : EFalse); |
|
277 } |
|
278 |
|
279 EXPORT_C void CGraphicsContext::DrawText(const TDesC& aText,const TTextParameters* iParam,const TPoint& aPosition) |
|
280 { |
|
281 TInt *dummy = NULL; |
|
282 |
|
283 TDrawTextInContextInternal context; |
|
284 TDrawTextInContextInternal* contextPtr = &context; |
|
285 contextPtr->iText.Set(aText); |
|
286 contextPtr->iPosition.SetXY(0,0); |
|
287 contextPtr->iPosition += aPosition; |
|
288 contextPtr->iParam.iStart = iParam->iStart; |
|
289 contextPtr->iParam.iEnd = iParam->iEnd; |
|
290 if (KErrNotSupported == APIExtension(KDrawTextInContextUid, (TAny*&)dummy, (TAny*)contextPtr)) |
|
291 { |
|
292 DrawText(aText,aPosition); |
|
293 } |
|
294 } |
|
295 |
|
296 EXPORT_C void CGraphicsContext::DrawText(const TDesC& aText,const TTextParameters* iParam,const TRect& aBox,TInt aBaselineOffset,TTextAlign aHrz,TInt aMargin) |
|
297 { |
|
298 TInt *dummy = NULL; |
|
299 |
|
300 TDrawTextInContextInternal context; |
|
301 TDrawTextInContextInternal* contextPtr = &context; |
|
302 contextPtr->iText.Set(aText); |
|
303 contextPtr->iBox.SetRect(aBox.iTl, aBox.iBr); |
|
304 contextPtr->iBaselineOffset = aBaselineOffset; |
|
305 contextPtr->iAlign = aHrz; |
|
306 contextPtr->iMargin = aMargin; |
|
307 contextPtr->iParam.iStart = iParam->iStart; |
|
308 contextPtr->iParam.iEnd = iParam->iEnd; |
|
309 if (KErrNotSupported == APIExtension(KDrawBoxTextInContextUid, (TAny*&)dummy, (TAny*)contextPtr)) |
|
310 { |
|
311 DrawText(aText,aBox,aBaselineOffset,aHrz,aMargin); |
|
312 } |
|
313 } |
|
314 |
|
315 EXPORT_C void CGraphicsContext::DrawText(const TDesC& aText,const TTextParameters* iParam,const TPoint& aPosition,const TDrawTextParam& /*aParam*/) |
|
316 { |
|
317 TInt *dummy = NULL; |
|
318 |
|
319 TDrawTextInContextInternal context; |
|
320 TDrawTextInContextInternal* contextPtr = &context; |
|
321 contextPtr->iText.Set(aText); |
|
322 contextPtr->iPosition.SetXY(0,0); |
|
323 contextPtr->iPosition += aPosition; |
|
324 contextPtr->iParam.iStart = iParam->iStart; |
|
325 contextPtr->iParam.iEnd = iParam->iEnd; |
|
326 if (KErrNotSupported == APIExtension(KDrawTextInContextUid, (TAny*&)dummy, (TAny*)contextPtr)) |
|
327 { |
|
328 DrawText(aText,aPosition); |
|
329 } |
|
330 } |
|
331 |
|
332 EXPORT_C void CGraphicsContext::DrawTextVertical(const TDesC& aText,const TTextParameters* iParam,const TPoint& aPos,TBool aUp) |
|
333 { |
|
334 TInt *dummy = NULL; |
|
335 |
|
336 TDrawTextInContextInternal context; |
|
337 TDrawTextInContextInternal* contextPtr = &context; |
|
338 contextPtr->iText.Set(aText); |
|
339 contextPtr->iPosition.SetXY(0,0); |
|
340 contextPtr->iPosition += aPos; |
|
341 contextPtr->iUp = aUp; |
|
342 contextPtr->iParam.iStart = iParam->iStart; |
|
343 contextPtr->iParam.iEnd = iParam->iEnd; |
|
344 if (KErrNotSupported == APIExtension(KDrawTextInContextVerticalUid, (TAny*&)dummy, (TAny*)contextPtr)) |
|
345 { |
|
346 DrawTextVertical(aText,aPos,aUp); |
|
347 } |
|
348 } |
|
349 |
|
350 EXPORT_C void CGraphicsContext::DrawTextVertical(const TDesC& aText,const TTextParameters* iParam,const TRect& aBox,TInt aBaselineOffset,TBool aUp,TTextAlign aVert,TInt aMargin) |
|
351 { |
|
352 TInt *dummy = NULL; |
|
353 |
|
354 TDrawTextInContextInternal context; |
|
355 TDrawTextInContextInternal* contextPtr = &context; |
|
356 contextPtr->iText.Set(aText); |
|
357 contextPtr->iBox.SetRect(aBox.iTl, aBox.iBr); |
|
358 contextPtr->iBaselineOffset = aBaselineOffset; |
|
359 contextPtr->iAlign = aVert; |
|
360 contextPtr->iMargin = aMargin; |
|
361 contextPtr->iUp = aUp; |
|
362 contextPtr->iParam.iStart = iParam->iStart; |
|
363 contextPtr->iParam.iEnd = iParam->iEnd; |
|
364 if (KErrNotSupported == APIExtension(KDrawBoxTextInContextVerticalUid, (TAny*&)dummy, (TAny*)contextPtr)) |
|
365 { |
|
366 DrawTextVertical(aText,aBox,aBaselineOffset,aUp,aVert,aMargin); |
|
367 } |
|
368 } |
|
369 |
|
370 EXPORT_C TInt CGraphicsContext::DrawTextExtended(const TDesC& aText,const TTextParameters* aTextParam,const TPoint& aPosition, |
|
371 const TDrawTextExtendedParam& aParam) |
|
372 /** Draws text, optionally changing its direction (right-to-left / left-to-right). |
|
373 |
|
374 Apart from reordering the text, the function is the same as the two parameter |
|
375 variant of DrawText(), described above. |
|
376 |
|
377 @param aText The text string to be drawn, optionally changing its direction |
|
378 (right-to-left / left-to-right). |
|
379 @param aPosition A point specifying the position of the left end of the text. |
|
380 @param aParam Indicates whether the text should be drawn from right-to-left |
|
381 (for scripts like Arabic and Hebrew) or left-to-right. |
|
382 @return KErrNoMemory indicates there was an OOM error when reordering the text; |
|
383 KErrNone if the reordering was successful. */ |
|
384 { |
|
385 // Reorder the text bidirectionally. |
|
386 TText* reordered_text = NULL; |
|
387 int error = TBidirectionalState::ReorderText(aText.Ptr(),aText.Length(),aParam.iParRightToLeft,reordered_text); |
|
388 TPtrC p(reordered_text,aText.Length()); |
|
389 DrawText(p,aTextParam,aPosition,aParam); |
|
390 if (reordered_text != aText.Ptr()) |
|
391 delete [] reordered_text; |
|
392 return error; |
|
393 } |
|
394 EXPORT_C void CGraphicsContext::Reserved() |
|
395 /**Reserved function for future use. */ |
|
396 { |
|
397 } |
|
398 |
|
399 /** |
|
400 An API extension for CGraphics context replacing a reserved virtual method. |
|
401 Effectively allows multiple methods to use just one ordinal number. |
|
402 |
|
403 @param TUid aUid A unique identifier for the internal method required |
|
404 @param TAny*& aOutput The output parameter |
|
405 @param TAny* aInput The input argument. Notably not const. |
|
406 @return KErrNone If a successful derived function is found, if the |
|
407 default is used then KErrNotSupported is returned. |
|
408 */ |
|
409 EXPORT_C TInt CGraphicsContext::APIExtension(TUid /*aUid*/, TAny*& /*aOutput*/, TAny* /*aInput*/) |
|
410 { |
|
411 return KErrNotSupported; |
|
412 } |
|
413 |
|
414 //Default implementation of reserved virtual |
|
415 EXPORT_C void CGraphicsContext::Reserved_CGraphicsContext_2() |
|
416 { |
|
417 } |
|
418 |
|
419 EXPORT_C TInt CBitmapContext::APIExtension(TUid aUid, TAny*& aOutput, TAny* aInput) |
|
420 { |
|
421 return CGraphicsContext::APIExtension(aUid, aOutput, aInput); |
|
422 } |
|
423 |
|
424 //Default implementation of reserved virtual |
|
425 EXPORT_C void CBitmapContext::Reserved_CGraphicsContext_2() |
|
426 { |
|
427 CGraphicsContext::Reserved_CGraphicsContext_2(); |
|
428 } |
|
429 |
|
430 //Default implementation of reserved virtual |
|
431 EXPORT_C void CBitmapContext::Reserved_CBitmapContext_1() |
|
432 { |
|
433 } |
|
434 |
|
435 //Default implementation of reserved virtual |
|
436 EXPORT_C void CBitmapContext::Reserved_CBitmapContext_2() |
|
437 { |
|
438 } |
|
439 |
|
440 //Default implementation of reserved virtual |
|
441 EXPORT_C void CBitmapContext::Reserved_CBitmapContext_3() |
|
442 { |
|
443 } |
|
444 |