|
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_DataOpenFontRasterizerContext |
|
23 */ |
|
24 |
|
25 #include "T_DataOpenFontRasterizerContext.h" |
|
26 #include "T_GraphicsUtil.h" |
|
27 |
|
28 |
|
29 /*@{*/ |
|
30 /// Parameters |
|
31 _LIT(KFldGlyphData, "glyphdata"); |
|
32 _LIT(KFldBit, "bit"); |
|
33 _LIT(KFldByte, "byte"); |
|
34 |
|
35 /// Commands |
|
36 _LIT(KCmdNew, "new"); |
|
37 _LIT(KCmdEndGlyph, "EndGlyph"); |
|
38 _LIT(KCmdStartGlyph, "StartGlyph"); |
|
39 _LIT(KCmdWriteGlyphBit, "WriteGlyphBit"); |
|
40 _LIT(KCmdWriteGlyphByte, "WriteGlyphByte"); |
|
41 _LIT(KCmdDestructor, "~"); |
|
42 |
|
43 /// Logs |
|
44 _LIT(KLogMissingParameter, "Missing parameter '%S'"); |
|
45 |
|
46 /*@}*/ |
|
47 |
|
48 |
|
49 /** |
|
50 * Two phase constructor |
|
51 */ |
|
52 CT_DataOpenFontRasterizerContext* CT_DataOpenFontRasterizerContext::NewL() |
|
53 { |
|
54 CT_DataOpenFontRasterizerContext* ret = new (ELeave) CT_DataOpenFontRasterizerContext(); |
|
55 CleanupStack::PushL(ret); |
|
56 ret->ConstructL(); |
|
57 CleanupStack::Pop(ret); |
|
58 return ret; |
|
59 } |
|
60 |
|
61 |
|
62 /** |
|
63 * Protected constructor. First phase construction |
|
64 */ |
|
65 CT_DataOpenFontRasterizerContext::CT_DataOpenFontRasterizerContext() |
|
66 : CDataWrapperBase() |
|
67 , iRasterizerContext(NULL) |
|
68 { |
|
69 } |
|
70 |
|
71 |
|
72 /** |
|
73 * Protected second phase construction |
|
74 */ |
|
75 void CT_DataOpenFontRasterizerContext::ConstructL() |
|
76 { |
|
77 } |
|
78 |
|
79 |
|
80 /** |
|
81 * Destructor. |
|
82 */ |
|
83 CT_DataOpenFontRasterizerContext::~CT_DataOpenFontRasterizerContext() |
|
84 { |
|
85 DestroyData(); |
|
86 } |
|
87 |
|
88 |
|
89 /** |
|
90 * cleanup implementation. |
|
91 */ |
|
92 void CT_DataOpenFontRasterizerContext::DestroyData() |
|
93 { |
|
94 delete iRasterizerContext; |
|
95 iRasterizerContext = NULL; |
|
96 } |
|
97 |
|
98 TAny* CT_DataOpenFontRasterizerContext::GetObject() |
|
99 { |
|
100 return iRasterizerContext; |
|
101 } |
|
102 |
|
103 void CT_DataOpenFontRasterizerContext::SetObjectL(TAny* aObject) |
|
104 { |
|
105 DestroyData(); |
|
106 iRasterizerContext = static_cast<COpenFontRasterizerContext*> (aObject); |
|
107 } |
|
108 |
|
109 void CT_DataOpenFontRasterizerContext::DisownObjectL() |
|
110 { |
|
111 iRasterizerContext = NULL; |
|
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_DataOpenFontRasterizerContext::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 == KCmdEndGlyph) |
|
132 { |
|
133 DoCmdEndGlyph(); |
|
134 } |
|
135 else if (aCommand == KCmdStartGlyph) |
|
136 { |
|
137 DoCmdStartGlyphL(aSection); |
|
138 } |
|
139 else if (aCommand == KCmdWriteGlyphBit) |
|
140 { |
|
141 DoCmdWriteGlyphBit(aSection); |
|
142 } |
|
143 else if (aCommand == KCmdWriteGlyphByte) |
|
144 { |
|
145 DoCmdWriteGlyphByte(aSection); |
|
146 } |
|
147 else if (aCommand == KCmdDestructor) |
|
148 { |
|
149 DoCmdDestructor(); |
|
150 } |
|
151 else |
|
152 { |
|
153 retVal=EFalse; |
|
154 } |
|
155 |
|
156 return retVal; |
|
157 } |
|
158 |
|
159 |
|
160 ////////////////// COMMANDS IMPLEMENTATION //////////////////////// |
|
161 |
|
162 /** Creates an instance of COpenFontRasterizerContext structure */ |
|
163 void CT_DataOpenFontRasterizerContext::DoCmdNew() |
|
164 { |
|
165 INFO_PRINTF1(_L("Creates an instance of COpenFontRasterizerContext")); |
|
166 |
|
167 // cleanup if any |
|
168 DestroyData(); |
|
169 |
|
170 // call new operator |
|
171 TRAPD(err, iRasterizerContext = new (ELeave) COpenFontRasterizerContext()); |
|
172 |
|
173 // check error code |
|
174 if (err != KErrNone) |
|
175 { |
|
176 ERR_PRINTF2(_L("Error creating an instance: %d"), err); |
|
177 SetError(err); |
|
178 } |
|
179 } |
|
180 |
|
181 void CT_DataOpenFontRasterizerContext::DoCmdEndGlyph() |
|
182 { |
|
183 INFO_PRINTF1(_L("execute COpenFontRasterizerContext::EndGlyph()")); |
|
184 iRasterizerContext->EndGlyph(); |
|
185 } |
|
186 |
|
187 void CT_DataOpenFontRasterizerContext::DoCmdStartGlyphL(const TDesC& aSection) |
|
188 { |
|
189 TOpenFontGlyphData* glyphData= NULL; |
|
190 |
|
191 if (!CT_GraphicsUtil::GetOpenFontGlyphDataL(*this, aSection, KFldGlyphData, glyphData)) |
|
192 { |
|
193 ERR_PRINTF2(KLogMissingParameter, &KFldGlyphData()); |
|
194 SetBlockResult(EFail); |
|
195 } |
|
196 else |
|
197 { |
|
198 INFO_PRINTF1(_L("execute COpenFontRasterizerContext::StartGlyph(TOpenFontGlyphData*)")); |
|
199 iRasterizerContext->StartGlyph(glyphData); |
|
200 } |
|
201 } |
|
202 |
|
203 void CT_DataOpenFontRasterizerContext::DoCmdWriteGlyphBit(const TDesC& aSection) |
|
204 { |
|
205 TInt bit; |
|
206 |
|
207 if (!GetIntFromConfig(aSection, KFldBit, bit)) |
|
208 { |
|
209 ERR_PRINTF2(KLogMissingParameter, &KFldBit()); |
|
210 SetBlockResult(EFail); |
|
211 } |
|
212 else |
|
213 { |
|
214 INFO_PRINTF1(_L("execute COpenFontRasterizerContext::WriteGlyphBit(TInt)")); |
|
215 iRasterizerContext->WriteGlyphBit(bit); |
|
216 } |
|
217 } |
|
218 |
|
219 void CT_DataOpenFontRasterizerContext::DoCmdWriteGlyphByte(const TDesC& aSection) |
|
220 { |
|
221 TInt byte; |
|
222 |
|
223 if (!GetIntFromConfig(aSection, KFldByte, byte)) |
|
224 { |
|
225 ERR_PRINTF2(KLogMissingParameter, &KFldByte()); |
|
226 SetBlockResult(EFail); |
|
227 } |
|
228 else |
|
229 { |
|
230 INFO_PRINTF1(_L("execute COpenFontRasterizerContext::WriteGlyphByte(TInt)")); |
|
231 iRasterizerContext->WriteGlyphByte(byte); |
|
232 } |
|
233 } |
|
234 |
|
235 void CT_DataOpenFontRasterizerContext::DoCmdDestructor() |
|
236 { |
|
237 DestroyData(); |
|
238 } |