|
1 /* |
|
2 * Copyright (c) 2002-2007 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: Defines the CXhtmlFileComposer class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CXHTMLFILECOMPOSER_H |
|
20 #define CXHTMLFILECOMPOSER_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <f32file.h> |
|
24 #include <e32math.h> |
|
25 |
|
26 #include "xfctemplates.h" |
|
27 #include "xhtmlfilecomposerconst.h" |
|
28 #include "cimageinfo.h" |
|
29 |
|
30 /** |
|
31 * @class CXhtmlFileComposer |
|
32 * @brief Implements the printing job compose to a XHTML file. |
|
33 */ |
|
34 |
|
35 /** |
|
36 * @example ExampleOfCreateXhtmlFile.cpp |
|
37 * This example |
|
38 * @li creates a list of images to be included in XHTML-file as CImageInfo classes |
|
39 * @li creates a new instance of this class |
|
40 * @li calls the CreateXhtmlFileL method to create the physical file |
|
41 */ |
|
42 |
|
43 class CXhtmlFileComposer : public CBase |
|
44 { |
|
45 public: |
|
46 |
|
47 /** |
|
48 * @enum TMeasureUnit |
|
49 * |
|
50 * The measure type is used in XHTML file for describing the unit for dimensions like |
|
51 * page, frame and image sizes, frame positions at the page etc. |
|
52 * Depending of the paper size type the two units of the measure is used: inches and millimeters. |
|
53 */ |
|
54 enum TMeasureUnit |
|
55 { |
|
56 EUAInches, ///<@brief Inch unit identifier. |
|
57 EUAMillis ///<@brief Millimeter unit identifier. |
|
58 }; |
|
59 |
|
60 public: |
|
61 |
|
62 /** NewL |
|
63 * @brief Creates a new instance of XHTML file composer. |
|
64 * @param aPath The path the XHTML file will be located.\n |
|
65 * If @a aPath is empty, the @ref KXFPDefaultResultPath is used to open the file |
|
66 * server session and to create path. Otherway the file name given in method |
|
67 * @ref CreateXhtmlFileL can be the name of the file without path. |
|
68 * @return Pointer to the instance. |
|
69 */ |
|
70 IMPORT_C static CXhtmlFileComposer* NewL(const TDesC& aPath); |
|
71 |
|
72 /** NewLC |
|
73 * @brief Creates a new instance of XHTML file composer and leaves it in the cleanup stack. |
|
74 * @param aPath The path the XHTML file will be located.\n |
|
75 * If @a aPath is empty, the @ref KXFPDefaultResultPath is used to open the file |
|
76 * server session and to create path. Otherway the file name given in method |
|
77 * @ref CreateXhtmlFileL can be the name of the file without path. |
|
78 * @return Pointer to the instance. |
|
79 */ |
|
80 IMPORT_C static CXhtmlFileComposer* NewLC(const TDesC& aPath); |
|
81 |
|
82 /** ~CXhtmlFileComposer |
|
83 * @brief Destructor. |
|
84 */ |
|
85 IMPORT_C ~CXhtmlFileComposer(); |
|
86 |
|
87 /** CreateXhtmlFileL |
|
88 * @brief Writes the XHTML-Print document of the job according to the given parameters. |
|
89 * @param aImages Array of the images to write in file |
|
90 * @param aLayout Jobs' <em>Number up</em> setting |
|
91 * @param aPaperSize Jobs' <em>Media size</em> setting |
|
92 * @param aQuality Jobs' <em>Quality</em> setting <b>not implemented</b> |
|
93 * @param aXhtmlPrintFile The name of the file to generate. The file name can be given |
|
94 * without the path, when the file is located in the @a aPath given when the |
|
95 * instance of this class is created. The @a aXhtmlPrintFile can be also given |
|
96 * with the path, but then the path must already exist. |
|
97 * @param aPageCount Returns the number of pages to print |
|
98 */ |
|
99 IMPORT_C void CreateXhtmlFileL(const RArray<CImageInfo>& aImages, const TInt aLayout, |
|
100 const TInt aPaperSize, const TInt aQuality, |
|
101 const TDesC& aXhtmlPrintFile, TInt& aPageCount, TBool aDataFile = EFalse); |
|
102 |
|
103 |
|
104 protected: |
|
105 |
|
106 /** ConstructL |
|
107 * @brief Symbian second phase constructor. |
|
108 * @param aPath The path the XHTML file will be located.\n |
|
109 * If @a aPath is empty, the @ref KXFPDefaultResultPath is used to open the file |
|
110 * server session and the path is created. This ensures the argument @a aXhtmlPrintFile |
|
111 * of the method @ref CreateXhtmlFileL can be given without path. |
|
112 */ |
|
113 void ConstructL(const TDesC& aPath); |
|
114 |
|
115 |
|
116 private: |
|
117 |
|
118 /** CXhtmlFileComposer |
|
119 * @brief C++ constructor |
|
120 */ |
|
121 CXhtmlFileComposer(); |
|
122 |
|
123 /** UnitToPixel |
|
124 * @brief Converts current unit to pixels. |
|
125 * @param aValue Inch/millimeter value |
|
126 * @return Pixel value |
|
127 */ |
|
128 IMPORT_C TReal UnitToPixel(TReal aValue); |
|
129 |
|
130 /** UnitToPixel |
|
131 * @brief Converts current unit to pixels. |
|
132 * @param aValue Inch/millimeter value |
|
133 * @return Pixel value |
|
134 */ |
|
135 IMPORT_C TSizeReal UnitToPixel(TSizeReal aValue); |
|
136 |
|
137 /** PixelToUnit |
|
138 * @brief Converts pixels to current unit. |
|
139 * @param aValue pixel value |
|
140 * @return Inch/millimeter value |
|
141 */ |
|
142 IMPORT_C TReal PixelToUnit(TReal aValue); |
|
143 |
|
144 /** PixelToUnit |
|
145 * @brief Converts pixels to current unit. |
|
146 * @param aValue pixel value |
|
147 * @return Inch/millimeter value |
|
148 */ |
|
149 IMPORT_C TSizeReal PixelToUnit(TSizeReal aValue); |
|
150 |
|
151 /** ReadTemplateL |
|
152 * @brief Reads the template file in iFileBuf |
|
153 */ |
|
154 void ReadTemplateFileL(); |
|
155 |
|
156 /** GetRatioL |
|
157 * @brief Counts the croping and scaling of the image |
|
158 * @param aNewSize Cropped and scaled size for the image |
|
159 * @param aImageSize Full string to define the margin in XHTML file |
|
160 */ |
|
161 void GetRatioL(TSizeReal &aNewSize, TSizeReal aImageSize); |
|
162 |
|
163 /** ComposeUnitL |
|
164 * @brief Converts the template to current unit (millimeters or inches) in member buffer. |
|
165 */ |
|
166 void ComposeUnitL(); |
|
167 |
|
168 /** ComposeTemplateL |
|
169 * @brief Replaces the template with string value in member buffer |
|
170 * @param aStr String to convert for |
|
171 * @param aTemplate Template to convert |
|
172 */ |
|
173 void ComposeTemplateL(const TDesC8 &aStr, const TDesC8 &aTemplate); |
|
174 |
|
175 /** ComposeTemplateL |
|
176 * @brief Replaces the template with number value in member buffer |
|
177 * @param aValue Number to convert for |
|
178 * @param aTemplate Template to convert |
|
179 */ |
|
180 void ComposeTemplateL(const TInt aValue, const TDesC8 &aTemplate); |
|
181 |
|
182 /** ComposeFileL |
|
183 * @brief Composes the data in the template in member buffer |
|
184 * @param aImageName Image name and path |
|
185 * @param aImgSize Image size |
|
186 */ |
|
187 void ComposeFileL(const TDes8 &aImageName, TSizeReal aImgSize, TBool aDataFile = EFalse); |
|
188 |
|
189 /** PageData |
|
190 * @brief Collects the paper size related data to page arguments |
|
191 * @param aPaperSize Media size |
|
192 */ |
|
193 void PageData(TInt aPaperSize); |
|
194 |
|
195 /** LayoutData |
|
196 * @brief Collects the layout related data to image frame arguments |
|
197 * @param aLayout Layout |
|
198 * @param aPositions Array of the image positions on the page |
|
199 */ |
|
200 void LayoutData(TInt aLayout, RArray<TSizeReal> &aPositions); |
|
201 |
|
202 /** FinalizeBufferL |
|
203 * @brief Trims the member buffer tail. Replacing the template strings from |
|
204 * the buffer makes the data length in the buffer vary and generates |
|
205 * rubbish in the end of buffer. |
|
206 * @return Pointer to the buffer data. |
|
207 */ |
|
208 TPtrC8 FinalizeBufferL(); |
|
209 |
|
210 /** SetPageTypeL |
|
211 * @brief Creates a new XHTML div for page. Last/only one must be always @c page_last. |
|
212 */ |
|
213 void SetPageTypeL(); |
|
214 |
|
215 /** GetTemplateStringL |
|
216 * @brief Reads the requested element's template for the XHTML file. |
|
217 * @param aStart Start marker tag for the element |
|
218 * @param aEnd End marker tag for the element |
|
219 * @param aTemplate Reference to the template element read |
|
220 * @return Pointer to the template element read |
|
221 */ |
|
222 TPtrC8 GetTemplateStringL(const TDesC8& aStart, const TDesC8& aEnd, TDes8& aTemplate); |
|
223 |
|
224 /** AddTemplateStringL |
|
225 * @brief Adds the template element in XHTML buffer |
|
226 * @param const TDesC8& The template element to add |
|
227 * @param const TDesC8& A marker tag to where to add the element |
|
228 */ |
|
229 void AddTemplateStringL(const TDesC8& aTemplate,const TDesC8& aTag); |
|
230 |
|
231 /** GetImageSize |
|
232 * @brief Returns the size in pixels of the image file |
|
233 * @param CImageInfo Image's info |
|
234 * @return Image size |
|
235 */ |
|
236 TSizeReal GetImageSizeL(CImageInfo aImage); |
|
237 |
|
238 /** AddPageL |
|
239 * @brief Adds the new page element in XHTML template if last one is full |
|
240 * @param aCurrentImage Index of the current image |
|
241 * @param aPositionIndex Reference to the index of the image position at page |
|
242 * @param aPageCount Reference to the page counter |
|
243 * @return True if page added, False if not. |
|
244 */ |
|
245 TBool AddPageL(TInt aCurrentImage, TInt& aPositionIndex, TInt& aPageCount); |
|
246 |
|
247 /** CreateMatrix |
|
248 * @brief Creates a list of positions at page for the grid of images. |
|
249 * @param aRows Number of rows at one page |
|
250 * @param aColumns Number of columns at one page |
|
251 * @param aPortrait Orientation of the paper vs. images |
|
252 * @param aPositions Reference to the array of the positions |
|
253 */ |
|
254 void CreateMatrix(TInt aRows, TInt aColumns, RArray<TSizeReal>& aPositions); |
|
255 |
|
256 /** GetImageNameL |
|
257 * @brief Returns the name of the image for IMG tag. |
|
258 * @param aImageInfo Image details |
|
259 * @param aImageName Reference to the image name |
|
260 */ |
|
261 void GetImageNameL(CImageInfo aImageInfo, TDes8 &aImageName, TBool aDataFile = EFalse); |
|
262 |
|
263 /** SizeAndOrientationL |
|
264 * @brief Returns the size and orientation of the image. |
|
265 * @param aImageInfo Image details |
|
266 * @param aImageSize Reference to the image size |
|
267 * @param aFramePortrait Returns True if image is portrait, otherway False |
|
268 */ |
|
269 void SizeAndOrientationL(const CImageInfo aImageInfo, TSizeReal& aImageSize, TBool& aFramePortrait); |
|
270 |
|
271 /** ComposePositionL |
|
272 * @brief Composes the position string identifier values in XHTML file. |
|
273 * @param aPositionIndex index of the position to compose |
|
274 * @param aPositions The array of the positions |
|
275 */ |
|
276 void ComposePositionL(TInt aPositionIndex, RArray<TSizeReal>& aPositions); |
|
277 |
|
278 /** FormatReal |
|
279 * @brief Composes the position string identifier values in XHTML file. |
|
280 * @param aNumber float number to convert |
|
281 * @param aString Converted string type of "%f<<units>>" |
|
282 */ |
|
283 void FormatReal(TRealX aNumber, TDes8& aString); |
|
284 |
|
285 private: |
|
286 |
|
287 /** @var TSizeReal iPaperSize |
|
288 * Paper size to print */ |
|
289 TSizeReal iPaperSize; |
|
290 |
|
291 /** @var TInt iPaperType |
|
292 * Measurement unit (millimeters or inches) in XHTML file */ |
|
293 TInt iPaperType; |
|
294 |
|
295 /** @var TReal iPageMargin |
|
296 * Marginals at the page */ |
|
297 TReal iPageMargin; |
|
298 |
|
299 /** @var TSizeReal iImageFrame |
|
300 * Frame to contain an image */ |
|
301 TSizeReal iImageFrame; |
|
302 |
|
303 /** @var HBufC8* iFileBuf |
|
304 * Buffer to read the template file */ |
|
305 HBufC8* iFileBuf; |
|
306 |
|
307 /** @var RFs iFsSession |
|
308 * File server session */ |
|
309 RFs iFsSession; |
|
310 |
|
311 /** @var TInt iImagesPerPage |
|
312 * Number of the images at one page */ |
|
313 TInt iImagesPerPage; |
|
314 |
|
315 /** @var TBool iImagePortrait |
|
316 * The orientation of the image. TRUE if portrait, FALSE if landscape */ |
|
317 TBool iImagePortrait; |
|
318 |
|
319 /** @var TBool iPagePortrait |
|
320 * The orientation of the page. TRUE if portrait, FALSE if landscape */ |
|
321 TBool iPagePortrait; |
|
322 |
|
323 /** @var TBlock iPageTemplate |
|
324 * Page element template of the XHTML file */ |
|
325 TBlock iPageTemplate; |
|
326 |
|
327 /** @var TBlock iFrameTemplate |
|
328 * Frame element template of the XHTML file */ |
|
329 TBlock iFrameTemplate; |
|
330 |
|
331 /** @var TBlock iPositionTemplate |
|
332 * Image position element template of the XHTML file */ |
|
333 TBlock iPositionTemplate; |
|
334 |
|
335 /** @var TBlock iImageTemplate |
|
336 * Image element template of the XHTML file */ |
|
337 TBlock iImageTemplate; |
|
338 }; |
|
339 |
|
340 #endif // CXHTMLFILECOMPOSER_H |
|
341 |
|
342 // End of File |