|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Symbian Foundation License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** |
|
19 @test |
|
20 @internalComponent |
|
21 |
|
22 This contains CT_DataGraphicsDeviceMap |
|
23 */ |
|
24 |
|
25 #include "T_DataGraphicsDeviceMap.h" |
|
26 #include "T_DataFont.h" |
|
27 |
|
28 /*@{*/ |
|
29 /// Commands |
|
30 _LIT(KCmdGetNearestFontInTwips, "GetNearestFontInTwips"); |
|
31 _LIT(KCmdGetNearestFontToDesignHeightInTwips, "GetNearestFontToDesignHeightInTwips"); |
|
32 _LIT(KCmdGetNearestFontToMaxHeightInTwips, "GetNearestFontToMaxHeightInTwips"); |
|
33 _LIT(KCmdHorizontalPixelsToTwips, "HorizontalPixelsToTwips"); |
|
34 _LIT(KCmdHorizontalTwipsToPixels, "HorizontalTwipsToPixels"); |
|
35 _LIT(KCmdPixelsToTwips, "PixelsToTwips"); |
|
36 _LIT(KCmdReleaseFont, "ReleaseFont"); |
|
37 _LIT(KCmdTwipsToPixels, "TwipsToPixels"); |
|
38 _LIT(KCmdVerticalPixelsToTwips, "VerticalPixelsToTwips"); |
|
39 _LIT(KCmdVerticalTwipsToPixels, "VerticalTwipsToPixels"); |
|
40 |
|
41 /// Fields |
|
42 _LIT(KFldExpected, "expected"); |
|
43 _LIT(KFldFont, "font"); |
|
44 _LIT(KFldMaxHeight, "maxheight"); |
|
45 _LIT(KFldPixels, "pixels"); |
|
46 _LIT(KFldPoint, "point"); |
|
47 _LIT(KFldRect, "rect"); |
|
48 _LIT(KFldTwips, "twips"); |
|
49 _LIT(KFldDisown, "disown"); |
|
50 |
|
51 /// Logging |
|
52 _LIT(KLogError, "Error=%d"); |
|
53 _LIT(KLogMissingParameter, "Missing parameter '%S'"); |
|
54 _LIT(KLogMissingWrapper, "Missing wrapper for '%S'"); |
|
55 _LIT(KLogNotExpectedValue, "Not expected value"); |
|
56 /*@}*/ |
|
57 |
|
58 /** |
|
59 * Constructor. First phase construction |
|
60 */ |
|
61 CT_DataGraphicsDeviceMap::CT_DataGraphicsDeviceMap() |
|
62 : CDataWrapperBase() |
|
63 { |
|
64 } |
|
65 |
|
66 /** |
|
67 * Process a command read from the ini file |
|
68 * |
|
69 * @param aDataWrapper test step requiring command to be processed |
|
70 * @param aCommand the command to process |
|
71 * @param aSection the entry in the ini file requiring the command to be processed |
|
72 * |
|
73 * @return ETrue if the command is processed |
|
74 */ |
|
75 TBool CT_DataGraphicsDeviceMap::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
76 { |
|
77 TBool ret=ETrue; |
|
78 if ( aCommand==KCmdGetNearestFontInTwips ) |
|
79 { |
|
80 DoCmdGetNearestFontInTwipsL(aSection); |
|
81 } |
|
82 else if ( aCommand==KCmdGetNearestFontToDesignHeightInTwips ) |
|
83 { |
|
84 DoCmdGetNearestFontToDesignHeightInTwipsL(aSection); |
|
85 } |
|
86 else if ( aCommand==KCmdGetNearestFontToMaxHeightInTwips ) |
|
87 { |
|
88 DoCmdGetNearestFontToMaxHeightInTwipsL(aSection); |
|
89 } |
|
90 else if ( aCommand==KCmdHorizontalPixelsToTwips ) |
|
91 { |
|
92 DoCmdHorizontalPixelsToTwips(aSection); |
|
93 } |
|
94 else if ( aCommand==KCmdHorizontalTwipsToPixels ) |
|
95 { |
|
96 DoCmdHorizontalTwipsToPixels(aSection); |
|
97 } |
|
98 else if ( aCommand==KCmdPixelsToTwips ) |
|
99 { |
|
100 DoCmdPixelsToTwips(aSection); |
|
101 } |
|
102 else if ( aCommand==KCmdReleaseFont ) |
|
103 { |
|
104 DoCmdReleaseFontL(aSection); |
|
105 } |
|
106 else if ( aCommand==KCmdTwipsToPixels ) |
|
107 { |
|
108 DoCmdTwipsToPixels(aSection); |
|
109 } |
|
110 else if ( aCommand==KCmdVerticalPixelsToTwips ) |
|
111 { |
|
112 DoCmdVerticalPixelsToTwips(aSection); |
|
113 } |
|
114 else if ( aCommand==KCmdVerticalTwipsToPixels ) |
|
115 { |
|
116 DoCmdVerticalTwipsToPixels(aSection); |
|
117 } |
|
118 else |
|
119 { |
|
120 ret=EFalse; |
|
121 } |
|
122 return ret; |
|
123 } |
|
124 |
|
125 void CT_DataGraphicsDeviceMap::DoCmdGetNearestFontInTwipsL(const TDesC& aSection) |
|
126 { |
|
127 TBool dataOk=ETrue; |
|
128 |
|
129 TFontSpec fontSpec; |
|
130 if ( !GetFontSpecFromConfig(aSection, KFldFont, fontSpec) ) |
|
131 { |
|
132 dataOk=EFalse; |
|
133 ERR_PRINTF2(KLogMissingParameter, &KFldFont()); |
|
134 SetBlockResult(EFail); |
|
135 } |
|
136 |
|
137 TPtrC wrapperName; |
|
138 // get BitmapUtilData object from parameters |
|
139 if ( !GetStringFromConfig(aSection, KFldFont, wrapperName) ) |
|
140 { |
|
141 dataOk=EFalse; |
|
142 ERR_PRINTF2(KLogMissingParameter, &KFldFont()); |
|
143 SetBlockResult(EFail); |
|
144 } |
|
145 |
|
146 if ( dataOk ) |
|
147 { |
|
148 CDataWrapper* wrapper=GetDataWrapperL(wrapperName); |
|
149 if ( wrapper==NULL ) |
|
150 { |
|
151 ERR_PRINTF2(KLogMissingWrapper, &wrapperName); |
|
152 SetBlockResult(EFail); |
|
153 } |
|
154 else |
|
155 { |
|
156 CFont* font=NULL; |
|
157 INFO_PRINTF1(_L("execute GetNearestFontInTwips(CFont*&, TFontSpec)")); |
|
158 TInt err=GetGraphicsDeviceMap()->GetNearestFontInTwips(font, fontSpec); |
|
159 if ( err!=KErrNone ) |
|
160 { |
|
161 ERR_PRINTF2(KLogError, err); |
|
162 SetError(err); |
|
163 } |
|
164 else |
|
165 { |
|
166 wrapper->SetObjectL(font); |
|
167 } |
|
168 } |
|
169 } |
|
170 } |
|
171 |
|
172 void CT_DataGraphicsDeviceMap::DoCmdGetNearestFontToDesignHeightInTwipsL(const TDesC& aSection) |
|
173 { |
|
174 TBool dataOk=ETrue; |
|
175 |
|
176 TFontSpec fontSpec; |
|
177 if ( !GetFontSpecFromConfig(aSection, KFldFont, fontSpec) ) |
|
178 { |
|
179 dataOk=EFalse; |
|
180 ERR_PRINTF2(KLogMissingParameter, &KFldFont()); |
|
181 SetBlockResult(EFail); |
|
182 } |
|
183 |
|
184 TPtrC wrapperName; |
|
185 // get BitmapUtilData object from parameters |
|
186 if ( !GetStringFromConfig(aSection, KFldFont, wrapperName) ) |
|
187 { |
|
188 dataOk=EFalse; |
|
189 ERR_PRINTF2(KLogMissingParameter, &KFldFont()); |
|
190 SetBlockResult(EFail); |
|
191 } |
|
192 |
|
193 if ( dataOk ) |
|
194 { |
|
195 CDataWrapper* wrapper=GetDataWrapperL(wrapperName); |
|
196 if ( wrapper==NULL ) |
|
197 { |
|
198 ERR_PRINTF2(KLogMissingWrapper, &wrapperName); |
|
199 SetBlockResult(EFail); |
|
200 } |
|
201 else |
|
202 { |
|
203 CFont* font=NULL; |
|
204 INFO_PRINTF1(_L("execute GetNearestFontToDesignHeightInTwips(CFont*&, TFontSpec)")); |
|
205 TInt err=GetGraphicsDeviceMap()->GetNearestFontToDesignHeightInTwips(font, fontSpec); |
|
206 if ( err!=KErrNone ) |
|
207 { |
|
208 ERR_PRINTF2(KLogError, err); |
|
209 SetError(err); |
|
210 } |
|
211 else |
|
212 { |
|
213 wrapper->SetObjectL(font); |
|
214 } |
|
215 } |
|
216 } |
|
217 } |
|
218 |
|
219 void CT_DataGraphicsDeviceMap::DoCmdGetNearestFontToMaxHeightInTwipsL(const TDesC& aSection) |
|
220 { |
|
221 TBool dataOk=ETrue; |
|
222 |
|
223 TFontSpec fontSpec; |
|
224 if ( !GetFontSpecFromConfig(aSection, KFldFont, fontSpec) ) |
|
225 { |
|
226 dataOk=EFalse; |
|
227 ERR_PRINTF2(KLogMissingParameter, &KFldFont()); |
|
228 SetBlockResult(EFail); |
|
229 } |
|
230 |
|
231 TInt maxHeight; |
|
232 if ( !GetIntFromConfig(aSection, KFldMaxHeight, maxHeight) ) |
|
233 { |
|
234 dataOk=EFalse; |
|
235 ERR_PRINTF2(KLogMissingParameter, &KFldMaxHeight()); |
|
236 SetBlockResult(EFail); |
|
237 } |
|
238 |
|
239 TPtrC wrapperName; |
|
240 // get BitmapUtilData object from parameters |
|
241 if ( !GetStringFromConfig(aSection, KFldFont, wrapperName) ) |
|
242 { |
|
243 dataOk=EFalse; |
|
244 ERR_PRINTF2(KLogMissingParameter, &KFldFont()); |
|
245 SetBlockResult(EFail); |
|
246 } |
|
247 |
|
248 if ( dataOk ) |
|
249 { |
|
250 CDataWrapper* wrapper=GetDataWrapperL(wrapperName); |
|
251 if ( wrapper==NULL ) |
|
252 { |
|
253 ERR_PRINTF2(KLogMissingWrapper, &wrapperName); |
|
254 SetBlockResult(EFail); |
|
255 } |
|
256 else |
|
257 { |
|
258 CFont* font=NULL; |
|
259 INFO_PRINTF1(_L("execute GetNearestFontToMaxHeightInTwips(CFont*&, TFontSpec, TInt)")); |
|
260 TInt err=GetGraphicsDeviceMap()->GetNearestFontToMaxHeightInTwips(font, fontSpec, maxHeight); |
|
261 if ( err!=KErrNone ) |
|
262 { |
|
263 ERR_PRINTF2(KLogError, err); |
|
264 SetError(err); |
|
265 } |
|
266 else |
|
267 { |
|
268 wrapper->SetObjectL(font); |
|
269 } |
|
270 } |
|
271 } |
|
272 } |
|
273 |
|
274 void CT_DataGraphicsDeviceMap::DoCmdHorizontalPixelsToTwips(const TDesC& aSection) |
|
275 { |
|
276 TInt value; |
|
277 if ( !GetIntFromConfig(aSection, KFldPixels, value) ) |
|
278 { |
|
279 ERR_PRINTF2(KLogMissingParameter, &KFldPixels()); |
|
280 SetBlockResult(EFail); |
|
281 } |
|
282 else |
|
283 { |
|
284 INFO_PRINTF1(_L("execute HorizontalPixelsToTwips(TInt)")); |
|
285 TInt pixels=GetGraphicsDeviceMap()->HorizontalPixelsToTwips(value); |
|
286 INFO_PRINTF2(_L("HorizontalPixelsToTwips=%d"), pixels); |
|
287 |
|
288 if ( GetIntFromConfig(aSection, KFldExpected, value) ) |
|
289 { |
|
290 if ( value!=pixels ) |
|
291 { |
|
292 ERR_PRINTF1(KLogNotExpectedValue); |
|
293 SetBlockResult(EFail); |
|
294 } |
|
295 } |
|
296 } |
|
297 } |
|
298 |
|
299 void CT_DataGraphicsDeviceMap::DoCmdHorizontalTwipsToPixels(const TDesC& aSection) |
|
300 { |
|
301 TInt value; |
|
302 if ( !GetIntFromConfig(aSection, KFldTwips, value) ) |
|
303 { |
|
304 ERR_PRINTF2(KLogMissingParameter, &KFldTwips()); |
|
305 SetBlockResult(EFail); |
|
306 } |
|
307 else |
|
308 { |
|
309 INFO_PRINTF1(_L("execute HorizontalTwipsToPixels(TInt)")); |
|
310 TInt pixels=GetGraphicsDeviceMap()->HorizontalTwipsToPixels(value); |
|
311 INFO_PRINTF2(_L("HorizontalTwipsToPixels=%d"), pixels); |
|
312 |
|
313 if ( GetIntFromConfig(aSection, KFldExpected, value) ) |
|
314 { |
|
315 if ( value!=pixels ) |
|
316 { |
|
317 ERR_PRINTF1(KLogNotExpectedValue); |
|
318 SetBlockResult(EFail); |
|
319 } |
|
320 } |
|
321 } |
|
322 } |
|
323 |
|
324 void CT_DataGraphicsDeviceMap::DoCmdPixelsToTwips(const TDesC& aSection) |
|
325 { |
|
326 TPoint point; |
|
327 if ( GetPointFromConfig(aSection, KFldPoint, point) ) |
|
328 { |
|
329 INFO_PRINTF1(_L("execute PixelsToTwips(const TPoint&)")); |
|
330 iPixelsToTwipsPoint=GetGraphicsDeviceMap()->PixelsToTwips(point); |
|
331 INFO_PRINTF3(_L("PixelsToTwips x=%d y=%d"), iPixelsToTwipsPoint.iX, iPixelsToTwipsPoint.iY); |
|
332 |
|
333 if ( GetPointFromConfig(aSection, KFldExpected, point) ) |
|
334 { |
|
335 if ( point!=iPixelsToTwipsPoint ) |
|
336 { |
|
337 ERR_PRINTF1(KLogNotExpectedValue); |
|
338 SetBlockResult(EFail); |
|
339 } |
|
340 } |
|
341 } |
|
342 else |
|
343 { |
|
344 TRect rect; |
|
345 if ( GetRectFromConfig(aSection, KFldRect, rect) ) |
|
346 { |
|
347 INFO_PRINTF1(_L("execute PixelsToTwips(const TRect&)")); |
|
348 iPixelsToTwipsRect=GetGraphicsDeviceMap()->PixelsToTwips(rect); |
|
349 LogRect(_L("PixelsToTwips(TRect)"), iPixelsToTwipsRect); |
|
350 if ( GetRectFromConfig(aSection, KFldExpected, rect) ) |
|
351 { |
|
352 if ( rect!=iPixelsToTwipsRect ) |
|
353 { |
|
354 ERR_PRINTF1(KLogNotExpectedValue); |
|
355 SetBlockResult(EFail); |
|
356 } |
|
357 } |
|
358 } |
|
359 else |
|
360 { |
|
361 ERR_PRINTF2(KLogMissingParameter, &KFldPoint()); |
|
362 ERR_PRINTF2(KLogMissingParameter, &KFldRect()); |
|
363 SetBlockResult(EFail); |
|
364 } |
|
365 } |
|
366 } |
|
367 |
|
368 void CT_DataGraphicsDeviceMap::DoCmdReleaseFontL(const TDesC& aSection) |
|
369 { |
|
370 TPtrC wrapperName; |
|
371 // get BitmapUtilData object from parameters |
|
372 if ( !GetStringFromConfig(aSection, KFldFont, wrapperName) ) |
|
373 { |
|
374 ERR_PRINTF2(KLogMissingParameter, &KFldFont()); |
|
375 SetBlockResult(EFail); |
|
376 } |
|
377 else |
|
378 { |
|
379 CT_DataFont* wrapper=static_cast<CT_DataFont*>(GetDataWrapperL(wrapperName)); |
|
380 if ( wrapper==NULL ) |
|
381 { |
|
382 ERR_PRINTF2(KLogMissingWrapper, &wrapperName); |
|
383 SetBlockResult(EFail); |
|
384 } |
|
385 else |
|
386 { |
|
387 CFont* font=wrapper->GetFont(); |
|
388 INFO_PRINTF1(_L("execute ReleaseFont(CFont*)")); |
|
389 GetGraphicsDeviceMap()->ReleaseFont(font); |
|
390 |
|
391 // check if we need to disown object |
|
392 TBool disOwn=ETrue, Own; |
|
393 if ( GetBoolFromConfig(aSection, KFldDisown, Own)) |
|
394 disOwn=Own; |
|
395 if (disOwn) |
|
396 wrapper->DisownObjectL(); |
|
397 } |
|
398 } |
|
399 } |
|
400 |
|
401 void CT_DataGraphicsDeviceMap::DoCmdTwipsToPixels(const TDesC& aSection) |
|
402 { |
|
403 TPoint point; |
|
404 if ( GetPointFromConfig(aSection, KFldPoint, point) ) |
|
405 { |
|
406 INFO_PRINTF1(_L("execute TwipsToPixels(const TPoint&)")); |
|
407 iTwipsToPixelsPoint=GetGraphicsDeviceMap()->TwipsToPixels(point); |
|
408 INFO_PRINTF3(_L("TwipsToPixels x=%d y=%d"), iTwipsToPixelsPoint.iX, iTwipsToPixelsPoint.iY); |
|
409 |
|
410 if ( GetPointFromConfig(aSection, KFldExpected, point) ) |
|
411 { |
|
412 if ( point!=iTwipsToPixelsPoint ) |
|
413 { |
|
414 ERR_PRINTF1(KLogNotExpectedValue); |
|
415 SetBlockResult(EFail); |
|
416 } |
|
417 } |
|
418 } |
|
419 else |
|
420 { |
|
421 TRect rect; |
|
422 if ( GetRectFromConfig(aSection, KFldRect, rect) ) |
|
423 { |
|
424 INFO_PRINTF1(_L("execute TwipsToPixels(const TRect&)")); |
|
425 iTwipsToPixelsRect=GetGraphicsDeviceMap()->TwipsToPixels(rect); |
|
426 LogRect(_L("TwipsToPixels(const TRect&)"), iTwipsToPixelsRect); |
|
427 if ( GetRectFromConfig(aSection, KFldExpected, rect) ) |
|
428 { |
|
429 if ( rect!=iTwipsToPixelsRect ) |
|
430 { |
|
431 ERR_PRINTF1(KLogNotExpectedValue); |
|
432 SetBlockResult(EFail); |
|
433 } |
|
434 } |
|
435 } |
|
436 else |
|
437 { |
|
438 ERR_PRINTF2(KLogMissingParameter, &KFldPoint()); |
|
439 ERR_PRINTF2(KLogMissingParameter, &KFldRect()); |
|
440 SetBlockResult(EFail); |
|
441 } |
|
442 } |
|
443 } |
|
444 |
|
445 void CT_DataGraphicsDeviceMap::DoCmdVerticalPixelsToTwips(const TDesC& aSection) |
|
446 { |
|
447 TInt value; |
|
448 if ( !GetIntFromConfig(aSection, KFldPixels, value) ) |
|
449 { |
|
450 ERR_PRINTF2(KLogMissingParameter, &KFldPixels()); |
|
451 SetBlockResult(EFail); |
|
452 } |
|
453 else |
|
454 { |
|
455 INFO_PRINTF1(_L("execute VerticalPixelsToTwips(TInt)")); |
|
456 TInt pixels=GetGraphicsDeviceMap()->VerticalPixelsToTwips(value); |
|
457 INFO_PRINTF2(_L("VerticalPixelsToTwips=%d"), pixels); |
|
458 |
|
459 if ( GetIntFromConfig(aSection, KFldExpected, value) ) |
|
460 { |
|
461 if ( value!=pixels ) |
|
462 { |
|
463 ERR_PRINTF1(KLogNotExpectedValue); |
|
464 SetBlockResult(EFail); |
|
465 } |
|
466 } |
|
467 } |
|
468 } |
|
469 |
|
470 void CT_DataGraphicsDeviceMap::DoCmdVerticalTwipsToPixels(const TDesC& aSection) |
|
471 { |
|
472 TInt value; |
|
473 if ( !GetIntFromConfig(aSection, KFldTwips, value) ) |
|
474 { |
|
475 ERR_PRINTF2(KLogMissingParameter, &KFldTwips()); |
|
476 SetBlockResult(EFail); |
|
477 } |
|
478 else |
|
479 { |
|
480 INFO_PRINTF1(_L("execute VerticalTwipsToPixels(TInt)")); |
|
481 TInt pixels=GetGraphicsDeviceMap()->VerticalTwipsToPixels(value); |
|
482 INFO_PRINTF2(_L("VerticalTwipsToPixels=%d"), pixels); |
|
483 |
|
484 if ( GetIntFromConfig(aSection, KFldExpected, value) ) |
|
485 { |
|
486 if ( value!=pixels ) |
|
487 { |
|
488 ERR_PRINTF1(KLogNotExpectedValue); |
|
489 SetBlockResult(EFail); |
|
490 } |
|
491 } |
|
492 } |
|
493 } |