|
1 /* |
|
2 * Copyright (c) 1996-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 #include "FRMPRINT.H" |
|
20 #include "FRMCONST.H" |
|
21 |
|
22 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
23 #include "FRMCONST_INTERNAL.H" |
|
24 #include "FRMCONST_PARTNER.H" |
|
25 #endif |
|
26 |
|
27 /** Page region printer interface. |
|
28 @publishedAll |
|
29 @return CTextPageRegionPrinter returned |
|
30 @param aLayDoc Information needed by the text layout engine to lay out a text object. |
|
31 @param aPrinterDevice Physical graphics device. |
|
32 @post CTextPageRegionPrinter object is now fully initialised |
|
33 */ |
|
34 EXPORT_C CTextPageRegionPrinter* CTextPageRegionPrinter::NewL(MLayDoc* aLayDoc,CPrinterDevice* aPrinterDevice) |
|
35 { |
|
36 CTextPageRegionPrinter* self=new(ELeave) CTextPageRegionPrinter(); |
|
37 CleanupStack::PushL(self); |
|
38 self->ConstructL(aLayDoc,aPrinterDevice); |
|
39 CleanupStack::Pop(); |
|
40 return self; |
|
41 } |
|
42 |
|
43 EXPORT_C CTextPageRegionPrinter::~CTextPageRegionPrinter() |
|
44 { |
|
45 delete iLayout; |
|
46 delete iGc; |
|
47 delete iPictureGc; |
|
48 } |
|
49 |
|
50 /** |
|
51 Sets the page list. |
|
52 @publishedAll |
|
53 @param aPageList Page list. |
|
54 */ |
|
55 EXPORT_C void CTextPageRegionPrinter::SetPageList(const CArrayFix<TInt>* aPageList) |
|
56 { |
|
57 iPageList=aPageList; |
|
58 } |
|
59 |
|
60 |
|
61 /** |
|
62 Sets the printer device. |
|
63 @publishedAll |
|
64 @param aPrinterDevice Physical graphics device. |
|
65 */ |
|
66 EXPORT_C void CTextPageRegionPrinter::SetPrinterDevice(CPrinterDevice* aPrinterDevice) |
|
67 { |
|
68 iPrinterDevice=aPrinterDevice; |
|
69 iImageDevice=aPrinterDevice; |
|
70 |
|
71 iCurrentPage=KMinTInt32; // To force a call to SetPageL when PrintBandL first called. |
|
72 |
|
73 iPageSizeInTwips=aPrinterDevice->CurrentPageSpecInTwips().OrientedPageSize(); |
|
74 } |
|
75 |
|
76 /** |
|
77 Sets the layout document. |
|
78 @publishedAll |
|
79 @param aDoc Layout document. |
|
80 */ |
|
81 EXPORT_C void CTextPageRegionPrinter::SetDocument(MLayDoc *aDoc) |
|
82 { |
|
83 iCurrentPage=KMinTInt32; // To force a call to SetPageL when PrintBandL first called. |
|
84 iLayout->SetLayDoc(aDoc); |
|
85 } |
|
86 |
|
87 /** |
|
88 Sets the print preview. |
|
89 @publishedAll |
|
90 @param aPrintPreview. |
|
91 */ |
|
92 EXPORT_C void CTextPageRegionPrinter::SetPrintPreview(TBool aPrintPreview) |
|
93 { |
|
94 iPrintPreview=aPrintPreview; |
|
95 iCurrentPage=KMinTInt32; // To force a call to SetPageL when PrintBandL first called. |
|
96 } |
|
97 |
|
98 /** |
|
99 Sets the Page Spec In Twips. |
|
100 @publishedAll |
|
101 @param aPageSpec. |
|
102 */ |
|
103 EXPORT_C void CTextPageRegionPrinter::SetPageSpecInTwips(const TPageSpec& aPageSpec) |
|
104 { |
|
105 iPageSizeInTwips=aPageSpec.OrientedPageSize(); |
|
106 } |
|
107 |
|
108 /** |
|
109 Sets the page margin in twips. |
|
110 @publishedAll |
|
111 @param aPageMargins. |
|
112 */ |
|
113 EXPORT_C void CTextPageRegionPrinter::SetPageMarginsInTwips(const TMargins& aPageMargins) |
|
114 { |
|
115 iPageMarginsInTwips=aPageMargins; |
|
116 } |
|
117 |
|
118 /** |
|
119 Sets the text margin widths in twips. |
|
120 @publishedAll |
|
121 @param aLabelMarginWidth |
|
122 @param aGutterMarginWidth |
|
123 */ |
|
124 EXPORT_C void CTextPageRegionPrinter::SetTextMarginWidthsInTwips(TInt aLabelMarginWidth,TInt aGutterMarginWidth) |
|
125 { |
|
126 iLabelMarginWidthInTwips=aLabelMarginWidth; |
|
127 iGutterMarginWidthInTwips=aGutterMarginWidth; |
|
128 } |
|
129 |
|
130 /** |
|
131 Set the number given to the first page of the document that has been paginated. |
|
132 Typically 1, but might be different (eg for document containing second chapter of book). |
|
133 @publishedAll |
|
134 @param aFirstPage |
|
135 */ |
|
136 EXPORT_C void CTextPageRegionPrinter::SetFirstPageOfDoc(TInt aFirstPage) |
|
137 { |
|
138 iFirstPage=aFirstPage; |
|
139 } |
|
140 |
|
141 |
|
142 /** |
|
143 Set the number given to the first page of the document that has been paginated. |
|
144 Typically 1, but might be different (eg for document containing second chapter of book). |
|
145 @publishedAll |
|
146 @param aImageDevice |
|
147 @param aPageNo |
|
148 @param aBandInPixels |
|
149 */ |
|
150 EXPORT_C void CTextPageRegionPrinter::PrintBandL(CGraphicsDevice* aImageDevice,TInt aPageNo,const TBandAttributes& aBandInPixels) |
|
151 // |
|
152 // Traps leaves |
|
153 // |
|
154 { |
|
155 __ASSERT_ALWAYS(iPageList!=NULL,FormPanic(EFInvalidPageList)); |
|
156 __ASSERT_DEBUG(aPageNo-iFirstPage<iPageList->Count(),FormPanic(EFInvalidPageNumber)); |
|
157 __ASSERT_DEBUG(aPageNo>=iFirstPage,FormPanic(EFInvalidPageNumber)); |
|
158 |
|
159 TRAPD(err,PrintBand2L(aImageDevice,aPageNo,aBandInPixels)); |
|
160 if (err) |
|
161 LeaveL(err); |
|
162 } |
|
163 |
|
164 /** |
|
165 Sets the fill to either the text box or whole view rect occupied by paragraph. |
|
166 @publishedAll |
|
167 @deprecated 7.0 |
|
168 @param aFillTextOnly |
|
169 */ |
|
170 EXPORT_C void CTextPageRegionPrinter::SetParagraphFillTextOnly(TBool aFillTextOnly) |
|
171 { |
|
172 iDrawTextLayoutContext.SetParagraphFillTextOnly(aFillTextOnly); |
|
173 } |
|
174 |
|
175 /** |
|
176 Takes the specified band and draws to specified Gc those lines that intersect the band on the page. |
|
177 @param aImageDevice The specified Graphics device. |
|
178 @param aPageNo The page number. |
|
179 @param aBandInPixels The specified band in pixels. |
|
180 */ |
|
181 void CTextPageRegionPrinter::PrintBand2L(CGraphicsDevice* aImageDevice,TInt aPageNo |
|
182 ,const TBandAttributes& aBandInPixels) |
|
183 { |
|
184 |
|
185 iImageDevice=aImageDevice; |
|
186 |
|
187 if (aBandInPixels.iFirstBandOnPage || aPageNo!=iCurrentPage) |
|
188 SetPageL(aPageNo); |
|
189 |
|
190 if (!iGc) |
|
191 { |
|
192 User::LeaveIfError(iImageDevice->CreateContext((CGraphicsContext *&) iGc)); |
|
193 if (!aBandInPixels.iGraphicsIsIgnored) |
|
194 User::LeaveIfError(iImageDevice->CreateContext((CGraphicsContext *&) iPictureGc)); |
|
195 iDrawTextLayoutContext.SetGc(iGc,iPictureGc); |
|
196 } |
|
197 |
|
198 iDrawTextLayoutContext.SetDrawTextAndGraphics(); |
|
199 if (aBandInPixels.iTextIsIgnored && aBandInPixels.iGraphicsIsIgnored) |
|
200 return; |
|
201 else if (aBandInPixels.iTextIsIgnored) |
|
202 iDrawTextLayoutContext.SetDrawGraphicsOnly(); |
|
203 else if (aBandInPixels.iGraphicsIsIgnored) |
|
204 iDrawTextLayoutContext.SetDrawTextOnly(); |
|
205 |
|
206 |
|
207 iLayout->DrawL(aBandInPixels.iRect,&iDrawTextLayoutContext); |
|
208 iDrawTextLayoutContext.SetDrawTextAndGraphics(); |
|
209 |
|
210 delete iGc; |
|
211 iGc=NULL; |
|
212 delete iPictureGc; |
|
213 iPictureGc=NULL; |
|
214 } |
|
215 |
|
216 CTextPageRegionPrinter::CTextPageRegionPrinter() |
|
217 { |
|
218 iDrawTextLayoutContext.SetDrawToEveryPixel(EFalse); |
|
219 iDrawTextLayoutContext.SetClipping(EFalse); |
|
220 } |
|
221 |
|
222 /** |
|
223 Constructs a CTextPageRegionPrinter. |
|
224 |
|
225 Defaults are that no label margin nor gutter margin and that text is formatted and displayed |
|
226 to the printable page. |
|
227 |
|
228 @param aLayDoc |
|
229 @param aPrinterDevice The printer device. |
|
230 */ |
|
231 void CTextPageRegionPrinter::ConstructL(MLayDoc* aLayDoc,CPrinterDevice* aPrinterDevice) |
|
232 { |
|
233 |
|
234 iPrintPreview=EFalse; |
|
235 iPageSizeInTwips=aPrinterDevice->CurrentPageSpecInTwips().OrientedPageSize(); |
|
236 iPrinterDevice=aPrinterDevice; |
|
237 iImageDevice=aPrinterDevice; |
|
238 |
|
239 iCurrentPage=KMinTInt32; // To force a call to SetPageL when PrintBandL first called. |
|
240 |
|
241 TInt textWidth=aPrinterDevice->HorizontalTwipsToPixels(LayoutWidthInTwips()); |
|
242 iLayout=CTextLayout::NewL(aLayDoc,textWidth); |
|
243 iLayout->SetAmountToFormat(CTextLayout::EFFormatBand); |
|
244 |
|
245 SetFirstPageOfDoc(1); |
|
246 } |
|
247 |
|
248 |
|
249 /** |
|
250 Set the format and Image devices. |
|
251 All these calls must pass values in twips to textlayout and image pixels to textdraw |
|
252 */ |
|
253 void CTextPageRegionPrinter::SetFormatAndImageDevices() |
|
254 { |
|
255 |
|
256 iDrawTextLayoutContext.iViewRect=iImageDevice->TwipsToPixels(ViewRectInTwips()); |
|
257 iDrawTextLayoutContext.iGutterMarginWidth=iImageDevice->HorizontalTwipsToPixels(iGutterMarginWidthInTwips); |
|
258 iDrawTextLayoutContext.iLabelMarginWidth=LabelMarginWidthInPixels(); |
|
259 iDrawTextLayoutContext.iTextStartX=TextStartXInPixels(); |
|
260 |
|
261 // iLayout - everything in twips |
|
262 iLayout->SetBandHeight(ViewRectInTwips().Height()); |
|
263 iLayout->SetImageDeviceMap(iImageDevice); |
|
264 iLayout->SetLabelsMarginWidth(LabelMarginWidthInPixels()); |
|
265 if (iPrintPreview) |
|
266 iLayout->SetFormatMode(CLayoutData::EFPrintPreviewMode,LayoutWidthInTwips(),iPrinterDevice); |
|
267 else |
|
268 iLayout->SetFormatMode(CLayoutData::EFPrintMode,LayoutWidthInTwips(),iPrinterDevice); |
|
269 |
|
270 } |
|
271 |
|
272 /** |
|
273 Gets the view rect in twips. |
|
274 @return Returns the view rect in pixels |
|
275 */ |
|
276 TRect CTextPageRegionPrinter::ViewRectInTwips() const |
|
277 { |
|
278 TRect viewRect; |
|
279 |
|
280 if (iLabelMarginWidthInTwips==0) |
|
281 viewRect.iTl.iX=0; |
|
282 else |
|
283 viewRect.iTl.iX=iPageMarginsInTwips.iLeft; |
|
284 viewRect.iTl.iY=iPageMarginsInTwips.iTop; |
|
285 viewRect.iBr.iX=iPageSizeInTwips.iWidth; |
|
286 viewRect.iBr.iY=iPageSizeInTwips.iHeight-iPageMarginsInTwips.iBottom; |
|
287 |
|
288 return viewRect; |
|
289 } |
|
290 |
|
291 /** |
|
292 Returns the width of page, excluding margins. |
|
293 @return Returns the width of page, excluding margins |
|
294 */ |
|
295 TInt CTextPageRegionPrinter::LayoutWidthInTwips() const |
|
296 { |
|
297 TInt width=iPageSizeInTwips.iWidth-(iPageMarginsInTwips.iLeft+iPageMarginsInTwips.iRight); |
|
298 return width-(iGutterMarginWidthInTwips+iLabelMarginWidthInTwips); |
|
299 } |
|
300 |
|
301 /** |
|
302 Gets the label margin width in pixels. |
|
303 @return Label margin width in pixels. |
|
304 */ |
|
305 TInt CTextPageRegionPrinter::LabelMarginWidthInPixels() const |
|
306 { |
|
307 |
|
308 return iImageDevice->HorizontalTwipsToPixels(iLabelMarginWidthInTwips); |
|
309 } |
|
310 |
|
311 /** |
|
312 Get the text start X in pixels. |
|
313 @return text start X in pixels. |
|
314 */ |
|
315 TInt CTextPageRegionPrinter::TextStartXInPixels() const |
|
316 { |
|
317 |
|
318 if (iLabelMarginWidthInTwips==0) |
|
319 return iImageDevice->HorizontalTwipsToPixels(iPageMarginsInTwips.iLeft); |
|
320 else |
|
321 return 0; |
|
322 } |
|
323 |
|
324 /** |
|
325 Calculates the docPos at the top of this page, by summing throught the CharsPerPage. |
|
326 Can be called for aPage==0, when loop not entered. |
|
327 |
|
328 @return Explanation of the object returned |
|
329 @param aPage Page Number. |
|
330 */ |
|
331 void CTextPageRegionPrinter::SetPageL(TInt aPage) |
|
332 { |
|
333 TInt pagesToScroll=0; |
|
334 TInt pageTextHeightInPixels=0; //To stop warning |
|
335 iCurrentPage=aPage; |
|
336 iTopPageDocPos=0; |
|
337 TInt page=iFirstPage; |
|
338 |
|
339 SetFormatAndImageDevices(); |
|
340 |
|
341 while (page<aPage) |
|
342 { |
|
343 __ASSERT_DEBUG((*iPageList)[page-iFirstPage]>=0,FormPanic(EFInvalidPageList)); |
|
344 if ((*iPageList)[page-iFirstPage]>0) |
|
345 { |
|
346 iTopPageDocPos+=(*iPageList)[page-iFirstPage]; |
|
347 pagesToScroll=0; |
|
348 } |
|
349 else |
|
350 ++pagesToScroll; |
|
351 page++; |
|
352 //Count zeros --> n |
|
353 } |
|
354 |
|
355 __ASSERT_DEBUG((*iPageList)[iCurrentPage-iFirstPage]>=0,FormPanic(EFInvalidPageList)); |
|
356 TInt bottomPageDocPos=iTopPageDocPos+(*iPageList)[iCurrentPage-iFirstPage]-1; |
|
357 if (bottomPageDocPos<iTopPageDocPos) |
|
358 ++bottomPageDocPos; |
|
359 __ASSERT_DEBUG(iTopPageDocPos<=iLayout->DocumentLength(),FormPanic(EFInvalidPageList)); |
|
360 __ASSERT_DEBUG(bottomPageDocPos>=0 && bottomPageDocPos<=iLayout->DocumentLength(),FormPanic(EFInvalidPageList)); |
|
361 __ASSERT_DEBUG(bottomPageDocPos>=iTopPageDocPos,FormPanic(EFInvalidPageList)); |
|
362 |
|
363 if (pagesToScroll>0) |
|
364 pageTextHeightInPixels=iImageDevice->VerticalTwipsToPixels(iPageSizeInTwips.iHeight-iPageMarginsInTwips.iTop-iPageMarginsInTwips.iBottom); |
|
365 iLayout->DiscardFormat(); |
|
366 TRAPD(err,iLayout->FormatCharRangeL(iTopPageDocPos,bottomPageDocPos,pagesToScroll*pageTextHeightInPixels)); |
|
367 //Scroll by n*Page Height |
|
368 if (err) |
|
369 LeaveL(err); |
|
370 } |
|
371 |
|
372 void CTextPageRegionPrinter::LeaveL(TInt aErr) |
|
373 // |
|
374 // There is not enough memory to do the formatting, or other leave |
|
375 // Reset everything. |
|
376 // |
|
377 { |
|
378 |
|
379 iCurrentPage=KMinTInt32; |
|
380 iLayout->DiscardFormat(); |
|
381 |
|
382 delete iGc; |
|
383 iGc=NULL; |
|
384 |
|
385 delete iPictureGc; |
|
386 iPictureGc=NULL; |
|
387 |
|
388 User::Leave(aErr); |
|
389 } |
|
390 |