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 "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-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_DataMeasureTextOutput |
|
23 */ |
|
24 |
|
25 #include "T_DataMeasureTextOutput.h" |
|
26 |
|
27 |
|
28 /*@{*/ |
|
29 /// Parameters |
|
30 _LIT(KValue, "value"); |
|
31 _LIT(KRectAx, "rect_ax"); |
|
32 _LIT(KRectAy, "rect_ay"); |
|
33 _LIT(KRectBx, "rect_bx"); |
|
34 _LIT(KRectBy, "rect_by"); |
|
35 _LIT(KWidth, "width"); |
|
36 _LIT(KHeight, "height"); |
|
37 |
|
38 /// Commands |
|
39 _LIT(KCmdNew, "new"); |
|
40 _LIT(KCmdSetBounds, "iBounds"); |
|
41 _LIT(KCmdSetChars, "iChars"); |
|
42 _LIT(KCmdSetGlyphs, "iGlyphs"); |
|
43 _LIT(KCmdSetGroups, "iGroups"); |
|
44 _LIT(KCmdSetMaxGlyphSize, "iMaxGlyphSize"); |
|
45 _LIT(KCmdSetSpaces, "iSpaces"); |
|
46 _LIT(KCmdDestructor, "~"); |
|
47 |
|
48 |
|
49 |
|
50 /*@}*/ |
|
51 |
|
52 |
|
53 /** |
|
54 * Two phase constructor |
|
55 */ |
|
56 CT_DataMeasureTextOutput* CT_DataMeasureTextOutput::NewL() |
|
57 { |
|
58 CT_DataMeasureTextOutput* ret = new (ELeave) CT_DataMeasureTextOutput(); |
|
59 CleanupStack::PushL(ret); |
|
60 ret->ConstructL(); |
|
61 CleanupStack::Pop(ret); |
|
62 return ret; |
|
63 } |
|
64 |
|
65 |
|
66 /** |
|
67 * Protected constructor. First phase construction |
|
68 */ |
|
69 CT_DataMeasureTextOutput::CT_DataMeasureTextOutput() |
|
70 : CDataWrapperBase() |
|
71 , iMeasureTextOutput(NULL) |
|
72 { |
|
73 } |
|
74 |
|
75 |
|
76 /** |
|
77 * Protected second phase construction |
|
78 */ |
|
79 void CT_DataMeasureTextOutput::ConstructL() |
|
80 { |
|
81 } |
|
82 |
|
83 |
|
84 /** |
|
85 * Destructor. |
|
86 */ |
|
87 CT_DataMeasureTextOutput::~CT_DataMeasureTextOutput() |
|
88 { |
|
89 DestroyData(); |
|
90 } |
|
91 |
|
92 |
|
93 /** |
|
94 * cleanup implementation. |
|
95 */ |
|
96 void CT_DataMeasureTextOutput::DestroyData() |
|
97 { |
|
98 delete iMeasureTextOutput; |
|
99 iMeasureTextOutput = NULL; |
|
100 } |
|
101 |
|
102 |
|
103 /** |
|
104 * Return a pointer to the object that the data wraps |
|
105 * |
|
106 * @return pointer to the object that the data wraps |
|
107 */ |
|
108 TAny* CT_DataMeasureTextOutput::GetObject() |
|
109 { |
|
110 return iMeasureTextOutput; |
|
111 } |
|
112 |
|
113 |
|
114 /** |
|
115 * Process a command read from the ini file |
|
116 * |
|
117 * @param aDataWrapper test step requiring command to be processed |
|
118 * @param aCommand the command to process |
|
119 * @param aSection the entry in the ini file requiring the command to be processed |
|
120 * |
|
121 * @return ETrue if the command is processed |
|
122 */ |
|
123 TBool CT_DataMeasureTextOutput::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
124 { |
|
125 TBool retVal = ETrue; |
|
126 |
|
127 if (aCommand == KCmdNew) |
|
128 { |
|
129 DoCmdNew(); |
|
130 } |
|
131 else if (aCommand == KCmdSetBounds) |
|
132 { |
|
133 DoCmdSetBounds(aSection); |
|
134 } |
|
135 else if (aCommand == KCmdSetChars) |
|
136 { |
|
137 DoCmdSetChars(aSection); |
|
138 } |
|
139 else if (aCommand == KCmdSetGlyphs) |
|
140 { |
|
141 DoCmdSetGlyphs(aSection); |
|
142 } |
|
143 else if (aCommand == KCmdSetGroups) |
|
144 { |
|
145 DoCmdSetGroups(aSection); |
|
146 } |
|
147 else if (aCommand == KCmdSetMaxGlyphSize) |
|
148 { |
|
149 DoCmdSetMaxGlyphSize(aSection); |
|
150 } |
|
151 else if (aCommand == KCmdSetSpaces) |
|
152 { |
|
153 DoCmdSetSpaces(aSection); |
|
154 } |
|
155 else if (aCommand == KCmdDestructor) |
|
156 { |
|
157 DestroyData(); |
|
158 } |
|
159 else |
|
160 { |
|
161 retVal=EFalse; |
|
162 } |
|
163 |
|
164 return retVal; |
|
165 } |
|
166 |
|
167 |
|
168 ////////////////// COMMANDS IMPLEMENTATION //////////////////////// |
|
169 |
|
170 /** Creates an instance of TMeasureTextOutput structure */ |
|
171 void CT_DataMeasureTextOutput::DoCmdNew() |
|
172 { |
|
173 INFO_PRINTF1(_L("Creates an instance of TMeasureTextOutput structure")); |
|
174 |
|
175 // cleanup if any |
|
176 DestroyData(); |
|
177 |
|
178 // call new operator |
|
179 TRAPD(err, iMeasureTextOutput = new (ELeave) CFont::TMeasureTextOutput()); |
|
180 |
|
181 // check error code |
|
182 if (err != KErrNone) |
|
183 { |
|
184 ERR_PRINTF2(_L("Error creating an instance: %d"), err); |
|
185 SetError(err); |
|
186 } |
|
187 } |
|
188 |
|
189 |
|
190 /** Sets TMeasureTextOutputData::iChars */ |
|
191 void CT_DataMeasureTextOutput::DoCmdSetChars(const TDesC& aSection) |
|
192 { |
|
193 INFO_PRINTF1(_L("Sets TMeasureTextOutputData::iChars")); |
|
194 |
|
195 // get value from parameters |
|
196 TInt value; |
|
197 if (GetValueFromConfig(*this,aSection, value)) |
|
198 { |
|
199 iMeasureTextOutput->iChars = value; |
|
200 } |
|
201 } |
|
202 |
|
203 |
|
204 /** Sets TMeasureTextOutputData::iGlyphs */ |
|
205 void CT_DataMeasureTextOutput::DoCmdSetGlyphs(const TDesC& aSection) |
|
206 { |
|
207 INFO_PRINTF1(_L("Sets TMeasureTextOutputData::iGlyphs")); |
|
208 |
|
209 // get value from parameters |
|
210 TInt value; |
|
211 if (GetValueFromConfig(*this, aSection, value)) |
|
212 { |
|
213 iMeasureTextOutput->iGlyphs = value; |
|
214 } |
|
215 } |
|
216 |
|
217 |
|
218 /** Sets TMeasureTextOutputData::iGroups */ |
|
219 void CT_DataMeasureTextOutput::DoCmdSetGroups(const TDesC& aSection) |
|
220 { |
|
221 INFO_PRINTF1(_L("Sets TMeasureTextOutputData::iGroups")); |
|
222 |
|
223 // get value from parameters |
|
224 TInt value; |
|
225 if (GetValueFromConfig(*this, aSection, value)) |
|
226 { |
|
227 iMeasureTextOutput->iGroups = value; |
|
228 } |
|
229 } |
|
230 |
|
231 |
|
232 /** Sets TMeasureTextOutputData::iSpaces */ |
|
233 void CT_DataMeasureTextOutput::DoCmdSetSpaces(const TDesC& aSection) |
|
234 { |
|
235 INFO_PRINTF1(_L("Sets TMeasureTextOutputData::iSpaces")); |
|
236 |
|
237 // get value from parameters |
|
238 TInt value; |
|
239 if (GetValueFromConfig(*this, aSection, value)) |
|
240 { |
|
241 iMeasureTextOutput->iSpaces = value; |
|
242 } |
|
243 } |
|
244 |
|
245 |
|
246 /** Sets TMeasureTextOutputData::iBounds */ |
|
247 void CT_DataMeasureTextOutput::DoCmdSetBounds(const TDesC& aSection) |
|
248 { |
|
249 INFO_PRINTF1(_L("Sets TMeasureTextOutputData::iBounds")); |
|
250 |
|
251 TBool dataOk = ETrue; |
|
252 |
|
253 // get rect Ax from parameters |
|
254 TInt rectAx; |
|
255 if(!GetIntFromConfig(aSection, KRectAx(), rectAx)) |
|
256 { |
|
257 ERR_PRINTF2(_L("No %S"), &KRectAx()); |
|
258 SetBlockResult(EFail); |
|
259 dataOk = EFalse; |
|
260 } |
|
261 |
|
262 // get rect Ay from parameters |
|
263 TInt rectAy; |
|
264 if(!GetIntFromConfig(aSection, KRectAy(), rectAy)) |
|
265 { |
|
266 ERR_PRINTF2(_L("No %S"), &KRectAy()); |
|
267 SetBlockResult(EFail); |
|
268 dataOk = EFalse; |
|
269 } |
|
270 |
|
271 // get rect Bx from parameters |
|
272 TInt rectBx; |
|
273 if(!GetIntFromConfig(aSection, KRectBx(), rectBx)) |
|
274 { |
|
275 ERR_PRINTF2(_L("No %S"), &KRectBx()); |
|
276 SetBlockResult(EFail); |
|
277 dataOk = EFalse; |
|
278 } |
|
279 |
|
280 // get rect By from parameters |
|
281 TInt rectBy; |
|
282 if(!GetIntFromConfig(aSection, KRectBy(), rectBy)) |
|
283 { |
|
284 ERR_PRINTF2(_L("No %S"), &KRectBy()); |
|
285 SetBlockResult(EFail); |
|
286 dataOk = EFalse; |
|
287 } |
|
288 |
|
289 // set the field |
|
290 if (dataOk) |
|
291 { |
|
292 iMeasureTextOutput->iBounds.SetRect(rectAx, rectAy, rectBx, rectBy); |
|
293 } |
|
294 } |
|
295 |
|
296 |
|
297 /** Sets TMeasureTextOutputData::iMaxGlyphSize */ |
|
298 void CT_DataMeasureTextOutput::DoCmdSetMaxGlyphSize(const TDesC& aSection) |
|
299 { |
|
300 INFO_PRINTF1(_L("Sets TMeasureTextOutputData::iMaxGlyphSize")); |
|
301 |
|
302 TBool dataOk = ETrue; |
|
303 |
|
304 // get width from parameters |
|
305 TInt width; |
|
306 if(!GetIntFromConfig(aSection, KWidth(), width)) |
|
307 { |
|
308 ERR_PRINTF2(_L("No %S"), &KWidth()); |
|
309 SetBlockResult(EFail); |
|
310 dataOk = EFalse; |
|
311 } |
|
312 |
|
313 // get height from parameters |
|
314 TInt height; |
|
315 if(!GetIntFromConfig(aSection, KHeight(), height)) |
|
316 { |
|
317 ERR_PRINTF2(_L("No %S"), &KHeight()); |
|
318 SetBlockResult(EFail); |
|
319 dataOk = EFalse; |
|
320 } |
|
321 |
|
322 // set the field |
|
323 if (dataOk) |
|
324 { |
|
325 iMeasureTextOutput->iMaxGlyphSize.iWidth = width; |
|
326 iMeasureTextOutput->iMaxGlyphSize.iHeight = height; |
|
327 } |
|
328 } |
|
329 |
|
330 |
|
331 |
|
332 ///////////////////////////////// UTIL METHODS ////////////////////////////////////// |
|
333 |
|
334 |
|
335 /** |
|
336 * Utility method that fetches a int value from parameters |
|
337 */ |
|
338 TBool CT_DataMeasureTextOutput::GetValueFromConfig(CDataWrapper& iInputStep, const TDesC& aSection, TInt& aValue) |
|
339 { |
|
340 TBool ret=iInputStep.GetIntFromConfig(aSection, KValue(), aValue); |
|
341 if (!ret) |
|
342 { |
|
343 iInputStep.ERR_PRINTF2(_L("No %S"), &KValue()); |
|
344 iInputStep.SetBlockResult(EFail); |
|
345 } |
|
346 |
|
347 return ret; |
|
348 } |
|