sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "FRMPAGE.H"
|
sl@0
|
20 |
#include "FRMTLAY.H"
|
sl@0
|
21 |
#include "FRMCONST.H"
|
sl@0
|
22 |
#include <txtlaydc.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
#include "OstTraceDefinitions.h"
|
sl@0
|
25 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
sl@0
|
26 |
#include "FRMPAGETraces.h"
|
sl@0
|
27 |
#endif
|
sl@0
|
28 |
|
sl@0
|
29 |
#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
|
sl@0
|
30 |
#include "FRMCONST_INTERNAL.H"
|
sl@0
|
31 |
#include "FRMCONST_PARTNER.H"
|
sl@0
|
32 |
#endif
|
sl@0
|
33 |
|
sl@0
|
34 |
/** Allocates and constructs a CTextPaginator object with a page list, the
|
sl@0
|
35 |
printer device for which the document is to be paginated and an active object
|
sl@0
|
36 |
priority.
|
sl@0
|
37 |
|
sl@0
|
38 |
@param aPrinterDevice Pointer to the printer device for which the document is
|
sl@0
|
39 |
to be paginated. This must be provided.
|
sl@0
|
40 |
@param aCharsPerPage The page list. This is a client-provided array into which
|
sl@0
|
41 |
characters-per-page values are written. Ownership of the array remains with the
|
sl@0
|
42 |
client.
|
sl@0
|
43 |
@param aPriority Integer specifying the active object priority. A number of
|
sl@0
|
44 |
standard priorities are specified in CActive::TPriority.
|
sl@0
|
45 |
@return Pointer to the new paginator object. */
|
sl@0
|
46 |
EXPORT_C CTextPaginator* CTextPaginator::NewL(CPrinterDevice* aPrinterDevice,CArrayFix<TInt>* aPageList,TInt aPriority)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
CTextPaginator* self=new(ELeave) CTextPaginator(aPriority);
|
sl@0
|
49 |
CleanupStack::PushL(self);
|
sl@0
|
50 |
self->ConstructL(aPrinterDevice,aPageList);
|
sl@0
|
51 |
CleanupStack::Pop();
|
sl@0
|
52 |
return self;
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
/** Destructor. Cancels the active object, if any. */
|
sl@0
|
56 |
EXPORT_C CTextPaginator::~CTextPaginator()
|
sl@0
|
57 |
{
|
sl@0
|
58 |
Cancel();
|
sl@0
|
59 |
delete iLayout;
|
sl@0
|
60 |
delete iPageLineArray;
|
sl@0
|
61 |
delete iTempPageList;
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
/** Sets a pagination observer (an instance of a class inherited from
|
sl@0
|
65 |
MPaginateObserver). The use of an observer is optional.
|
sl@0
|
66 |
|
sl@0
|
67 |
An observer may be used when paginating a complete document in the background
|
sl@0
|
68 |
using the function PaginateCompleteDocumentL(). The observer notifies
|
sl@0
|
69 |
completion of pages, cancellation, errors, and on completion of multiple
|
sl@0
|
70 |
pagination.
|
sl@0
|
71 |
|
sl@0
|
72 |
@param aObserver Observer object inherited from MPaginateObserver. */
|
sl@0
|
73 |
EXPORT_C void CTextPaginator::SetObserver(MPaginateObserver* aObserver)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
|
sl@0
|
76 |
iObserver=aObserver;
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
/** Sets a pointer to the document which is to be paginated.
|
sl@0
|
80 |
@param aLayDoc The document to paginate. */
|
sl@0
|
81 |
EXPORT_C void CTextPaginator::SetDocumentL(MLayDoc* aLayDoc)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
|
sl@0
|
84 |
SetOrReplaceDocumentL(aLayDoc);
|
sl@0
|
85 |
iPaginator.Reset();
|
sl@0
|
86 |
iDocPos=0;
|
sl@0
|
87 |
SetLayoutDimensions();
|
sl@0
|
88 |
}
|
sl@0
|
89 |
|
sl@0
|
90 |
/** Sets a pointer to the printer device for which the document is to be
|
sl@0
|
91 |
paginated.
|
sl@0
|
92 |
|
sl@0
|
93 |
Note: This function must be called, and SetDocumentL() must have been called
|
sl@0
|
94 |
beforehand.
|
sl@0
|
95 |
|
sl@0
|
96 |
@param aPrinterDevice The printer device. */
|
sl@0
|
97 |
EXPORT_C void CTextPaginator::SetPrinterDevice(CPrinterDevice* aPrinterDevice)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
if (!iLayout)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
OstTrace0( TRACE_FATAL, CTEXTPAGINATOR_SETPRINTERDEVICE, "EFDocumentToPaginateNotSet" );
|
sl@0
|
102 |
}
|
sl@0
|
103 |
__ASSERT_ALWAYS(iLayout,FormPanic(EFDocumentToPaginateNotSet));
|
sl@0
|
104 |
iPrinterDevice=aPrinterDevice;
|
sl@0
|
105 |
iLayout->SetImageDeviceMap(aPrinterDevice);
|
sl@0
|
106 |
|
sl@0
|
107 |
iPageSizeInTwips=aPrinterDevice->CurrentPageSpecInTwips().OrientedPageSize();
|
sl@0
|
108 |
SetLayoutDimensions();
|
sl@0
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
/** Sets the page width and height in twips, overriding the current values
|
sl@0
|
112 |
specified in the printer device.
|
sl@0
|
113 |
@param aPageSpec Contains the new page dimensions. */
|
sl@0
|
114 |
EXPORT_C void CTextPaginator::SetPageSpecInTwips(const TPageSpec& aPageSpec)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
|
sl@0
|
117 |
iPageSizeInTwips=aPageSpec.OrientedPageSize();
|
sl@0
|
118 |
SetLayoutDimensions();
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
/** Sets the widths of the page margins in twips.
|
sl@0
|
122 |
|
sl@0
|
123 |
The page margin exists on all four sides of the page. It does not include the
|
sl@0
|
124 |
line cursor or labels margins. The labels and line cursor margins are set using
|
sl@0
|
125 |
SetTextMarginWidthsInTwips().
|
sl@0
|
126 |
|
sl@0
|
127 |
@param aPageMargins The page margin widths. */
|
sl@0
|
128 |
EXPORT_C void CTextPaginator::SetPageMarginsInTwips(const TMargins& aPageMargins)
|
sl@0
|
129 |
{
|
sl@0
|
130 |
iPageMarginsInTwips=aPageMargins;
|
sl@0
|
131 |
SetLayoutDimensions();
|
sl@0
|
132 |
}
|
sl@0
|
133 |
|
sl@0
|
134 |
/** Sets the widths in twips of:
|
sl@0
|
135 |
|
sl@0
|
136 |
the labels margin the area within which paragraph labels are displayed,
|
sl@0
|
137 |
|
sl@0
|
138 |
the gutter margin (also known as the line cursor margin) exists between the
|
sl@0
|
139 |
labels margin and the text area.
|
sl@0
|
140 |
|
sl@0
|
141 |
@param aLabelMarginWidth The labels margin width.
|
sl@0
|
142 |
@param aGutterMarginWidth The gutter margin width. */
|
sl@0
|
143 |
EXPORT_C void CTextPaginator::SetTextMarginWidthsInTwips(TInt aLabelMarginWidth
|
sl@0
|
144 |
,TInt aGutterMarginWidth)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
iLabelMarginWidthInTwips=aLabelMarginWidth;
|
sl@0
|
147 |
iGutterMarginWidthInTwips=aGutterMarginWidth;
|
sl@0
|
148 |
SetLayoutDimensions();
|
sl@0
|
149 |
}
|
sl@0
|
150 |
|
sl@0
|
151 |
CTextPaginator::CTextPaginator(TInt aPriority)
|
sl@0
|
152 |
:CActive(aPriority)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
void CTextPaginator::ConstructL(CPrinterDevice* aPrinterDevice,CArrayFix<TInt>* aPageList)
|
sl@0
|
157 |
{
|
sl@0
|
158 |
|
sl@0
|
159 |
iPageLineArray=new(ELeave) CArrayFixFlat<TPageLine>(EPageLineArrayGranularity);
|
sl@0
|
160 |
iTempPageList=new(ELeave) CArrayFixFlat<TInt>(EPageListArrayGranularity);
|
sl@0
|
161 |
iPrinterDevice=aPrinterDevice;
|
sl@0
|
162 |
iPageList=aPageList;
|
sl@0
|
163 |
|
sl@0
|
164 |
iPaginator.SetArray(iTempPageList);
|
sl@0
|
165 |
iPaginator.SetPageHeight(TextSizeInPixels().iHeight);
|
sl@0
|
166 |
|
sl@0
|
167 |
iPageSizeInTwips=iPrinterDevice->CurrentPageSpecInTwips().OrientedPageSize();
|
sl@0
|
168 |
SetLayoutDimensions();
|
sl@0
|
169 |
ResetPaginator();
|
sl@0
|
170 |
}
|
sl@0
|
171 |
|
sl@0
|
172 |
/** Initiates pagination of a complete document in the background using an
|
sl@0
|
173 |
active object. To start pagination, use either this function, or else
|
sl@0
|
174 |
incrementally paginate with AppendTextL() do not try to use both functions
|
sl@0
|
175 |
together.
|
sl@0
|
176 |
|
sl@0
|
177 |
Note: SetDocumentL() must have been called beforehand, or a panic occurs. */
|
sl@0
|
178 |
EXPORT_C void CTextPaginator::PaginateCompleteDocumentL()
|
sl@0
|
179 |
{
|
sl@0
|
180 |
if (!iLayout)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
OstTrace0( TRACE_FATAL, CTEXTPAGINATOR_PAGINATECOMPLETEDOCUMENTL, "EFDocumentToPaginateNotSet" );
|
sl@0
|
183 |
}
|
sl@0
|
184 |
__ASSERT_ALWAYS(iLayout,FormPanic(EFDocumentToPaginateNotSet));
|
sl@0
|
185 |
if (iPageList->Count()==0)
|
sl@0
|
186 |
iPageList->AppendL(iLayDoc->LdDocumentLength());
|
sl@0
|
187 |
if (!IsAdded())
|
sl@0
|
188 |
CActiveScheduler::Add(this); // Adds itself to the active scheduler
|
sl@0
|
189 |
iMode=EFPaginateCompleteDocument;
|
sl@0
|
190 |
ResetPaginator();
|
sl@0
|
191 |
Reque();
|
sl@0
|
192 |
}
|
sl@0
|
193 |
|
sl@0
|
194 |
/** Paginates incrementally as a document is being constructed (by appending
|
sl@0
|
195 |
paragraphs, for example). Call this function every time text is added to the
|
sl@0
|
196 |
document.
|
sl@0
|
197 |
|
sl@0
|
198 |
The function PaginationCompletedL() should be called at the end (in order to
|
sl@0
|
199 |
complete the last entry in the characters-per-page array).
|
sl@0
|
200 |
|
sl@0
|
201 |
Use either this function, or else paginate in the background with
|
sl@0
|
202 |
PaginateCompleteDocumentL() - do not try to use both functions together.
|
sl@0
|
203 |
|
sl@0
|
204 |
Note: SetDocumentL() must have been called beforehand, or a panic occurs.
|
sl@0
|
205 |
|
sl@0
|
206 |
@param aCumulativeDocPos The first time the function is called, this should be
|
sl@0
|
207 |
given a value of zero. Returns the last document position which has been
|
sl@0
|
208 |
paginated.
|
sl@0
|
209 |
@return A count of the current number of pages. */
|
sl@0
|
210 |
EXPORT_C TInt CTextPaginator::AppendTextL(TInt& aCumulativeDocPos)
|
sl@0
|
211 |
{
|
sl@0
|
212 |
if (!iLayout)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
OstTrace0( TRACE_FATAL, CTEXTPAGINATOR_APPENDTEXTL, "EFDocumentToPaginateNotSet" );
|
sl@0
|
215 |
}
|
sl@0
|
216 |
__ASSERT_ALWAYS(iLayout,FormPanic(EFDocumentToPaginateNotSet));
|
sl@0
|
217 |
if (aCumulativeDocPos>=iLayout->DocumentLength())
|
sl@0
|
218 |
{
|
sl@0
|
219 |
OstTrace0( TRACE_FATAL, DUP1_CTEXTPAGINATOR_APPENDTEXTL, "EFInvalidDocPos" );
|
sl@0
|
220 |
}
|
sl@0
|
221 |
__ASSERT_ALWAYS(aCumulativeDocPos<iLayout->DocumentLength(),FormPanic(EFInvalidDocPos));
|
sl@0
|
222 |
iMode=EFPaginateIncrementally;
|
sl@0
|
223 |
|
sl@0
|
224 |
if (iPageList->Count()==0)
|
sl@0
|
225 |
ResetPaginator();
|
sl@0
|
226 |
|
sl@0
|
227 |
TBool moreToDo=ETrue;
|
sl@0
|
228 |
while(moreToDo)
|
sl@0
|
229 |
{
|
sl@0
|
230 |
moreToDo = iDocPos<=iLayDoc->LdDocumentLength();
|
sl@0
|
231 |
if (moreToDo)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
TrapPaginateParagraphL();
|
sl@0
|
234 |
}
|
sl@0
|
235 |
else
|
sl@0
|
236 |
{
|
sl@0
|
237 |
if (iMode==EFPaginateCompleteDocument)
|
sl@0
|
238 |
{
|
sl@0
|
239 |
iPaginator.FlushL(iDocPos);
|
sl@0
|
240 |
PageCompleted();
|
sl@0
|
241 |
}
|
sl@0
|
242 |
iPageLineArray->Reset();
|
sl@0
|
243 |
iPageLineArray->Compress();
|
sl@0
|
244 |
}
|
sl@0
|
245 |
}
|
sl@0
|
246 |
|
sl@0
|
247 |
aCumulativeDocPos=iDocPos;
|
sl@0
|
248 |
|
sl@0
|
249 |
TRAPD(err,CopyTempPageListL());
|
sl@0
|
250 |
if (err)
|
sl@0
|
251 |
{
|
sl@0
|
252 |
LeaveL(err);
|
sl@0
|
253 |
}
|
sl@0
|
254 |
return iPageList->Count();
|
sl@0
|
255 |
}
|
sl@0
|
256 |
|
sl@0
|
257 |
/** This function should be called when incremental pagination has completed
|
sl@0
|
258 |
(see AppendTextL()), to complete the final entry in the page list. If an
|
sl@0
|
259 |
observer has been set, calls its NotifyCompletion() function.
|
sl@0
|
260 |
|
sl@0
|
261 |
@return Count of total number of pages. */
|
sl@0
|
262 |
EXPORT_C TInt CTextPaginator::PaginationCompletedL()
|
sl@0
|
263 |
{
|
sl@0
|
264 |
TRAPD(err,iPaginator.FlushL(iDocPos));
|
sl@0
|
265 |
if (err)
|
sl@0
|
266 |
LeaveL(err);
|
sl@0
|
267 |
iLayout->DiscardFormat();
|
sl@0
|
268 |
TRAP(err,CopyTempPageListL());
|
sl@0
|
269 |
if (err)
|
sl@0
|
270 |
LeaveL(err);
|
sl@0
|
271 |
if (iObserver)
|
sl@0
|
272 |
iObserver->NotifyCompletion();
|
sl@0
|
273 |
return iPageList->Count();
|
sl@0
|
274 |
}
|
sl@0
|
275 |
|
sl@0
|
276 |
void CTextPaginator::RunL()
|
sl@0
|
277 |
//
|
sl@0
|
278 |
// Called by active scheduler.
|
sl@0
|
279 |
// Paginates a document one paragraph at a time through succeeding
|
sl@0
|
280 |
// calls.
|
sl@0
|
281 |
//
|
sl@0
|
282 |
{
|
sl@0
|
283 |
TBool moreToDo = iDocPos<=iLayDoc->LdDocumentLength();
|
sl@0
|
284 |
if (moreToDo)
|
sl@0
|
285 |
{
|
sl@0
|
286 |
TrapPaginateParagraphL();
|
sl@0
|
287 |
}
|
sl@0
|
288 |
else
|
sl@0
|
289 |
{
|
sl@0
|
290 |
if (iMode==EFPaginateCompleteDocument)
|
sl@0
|
291 |
{
|
sl@0
|
292 |
iPaginator.FlushL(iDocPos);
|
sl@0
|
293 |
PageCompleted();
|
sl@0
|
294 |
}
|
sl@0
|
295 |
iPageLineArray->Reset();
|
sl@0
|
296 |
iPageLineArray->Compress();
|
sl@0
|
297 |
}
|
sl@0
|
298 |
|
sl@0
|
299 |
if (moreToDo)
|
sl@0
|
300 |
Reque();
|
sl@0
|
301 |
else
|
sl@0
|
302 |
{
|
sl@0
|
303 |
iLayout->DiscardFormat();
|
sl@0
|
304 |
TRAPD(err,CopyTempPageListL());
|
sl@0
|
305 |
if (err)
|
sl@0
|
306 |
LeaveL(err);
|
sl@0
|
307 |
if (iObserver)
|
sl@0
|
308 |
iObserver->NotifyCompletion();
|
sl@0
|
309 |
}
|
sl@0
|
310 |
}
|
sl@0
|
311 |
|
sl@0
|
312 |
void CTextPaginator::DoCancel()
|
sl@0
|
313 |
{
|
sl@0
|
314 |
iPaginator.Reset();
|
sl@0
|
315 |
iLayout->DiscardFormat();
|
sl@0
|
316 |
iDocPos=0;
|
sl@0
|
317 |
iPageBreakChar=EFalse;
|
sl@0
|
318 |
|
sl@0
|
319 |
if (iObserver)
|
sl@0
|
320 |
iObserver->NotifyError(KErrCancel);
|
sl@0
|
321 |
}
|
sl@0
|
322 |
|
sl@0
|
323 |
void CTextPaginator::SetLayoutDimensions()
|
sl@0
|
324 |
{
|
sl@0
|
325 |
iPaginator.SetPageHeight(TextSizeInPixels().iHeight);
|
sl@0
|
326 |
if (iLayout)
|
sl@0
|
327 |
iLayout->SetFormatMode(CLayoutData::EFPrintMode,TextRectInTwips().Width(),iPrinterDevice);
|
sl@0
|
328 |
}
|
sl@0
|
329 |
|
sl@0
|
330 |
void CTextPaginator::SetOrReplaceDocumentL(MLayDoc* aLayDoc)
|
sl@0
|
331 |
{
|
sl@0
|
332 |
|
sl@0
|
333 |
iLayDoc=aLayDoc;
|
sl@0
|
334 |
if (iLayout)
|
sl@0
|
335 |
iLayout->SetLayDoc(aLayDoc);
|
sl@0
|
336 |
else
|
sl@0
|
337 |
iLayout=CTextLayout::NewL(aLayDoc,TextSizeInPixels().iWidth);
|
sl@0
|
338 |
iLayout->SetImageDeviceMap(iPrinterDevice);
|
sl@0
|
339 |
}
|
sl@0
|
340 |
|
sl@0
|
341 |
TRect CTextPaginator::TextRectInTwips() const
|
sl@0
|
342 |
{
|
sl@0
|
343 |
TRect textRect;
|
sl@0
|
344 |
|
sl@0
|
345 |
textRect.iTl.iX=iPageMarginsInTwips.iLeft+iGutterMarginWidthInTwips+iLabelMarginWidthInTwips;
|
sl@0
|
346 |
textRect.iTl.iY=iPageMarginsInTwips.iTop;
|
sl@0
|
347 |
textRect.iBr.iX=iPageSizeInTwips.iWidth-iPageMarginsInTwips.iRight;
|
sl@0
|
348 |
textRect.iBr.iY=iPageSizeInTwips.iHeight-iPageMarginsInTwips.iBottom;
|
sl@0
|
349 |
|
sl@0
|
350 |
return textRect;
|
sl@0
|
351 |
}
|
sl@0
|
352 |
|
sl@0
|
353 |
TSize CTextPaginator::TextSizeInPixels() const
|
sl@0
|
354 |
{
|
sl@0
|
355 |
TRect textRect=iPrinterDevice->TwipsToPixels(TextRectInTwips());
|
sl@0
|
356 |
|
sl@0
|
357 |
return textRect.Size();
|
sl@0
|
358 |
}
|
sl@0
|
359 |
|
sl@0
|
360 |
void CTextPaginator::TrapPaginateParagraphL()
|
sl@0
|
361 |
{
|
sl@0
|
362 |
TRAPD(err,PaginateParagraphL());
|
sl@0
|
363 |
if (err)
|
sl@0
|
364 |
LeaveL(err);
|
sl@0
|
365 |
}
|
sl@0
|
366 |
|
sl@0
|
367 |
void CTextPaginator::PaginateParagraphL()
|
sl@0
|
368 |
{
|
sl@0
|
369 |
TInt lineHeight;
|
sl@0
|
370 |
TBool keepTogether; // Prevents page break in a paragraph when ETrue.
|
sl@0
|
371 |
TBool keepWithNext; // Prevents page break between this & next para when ETrue.
|
sl@0
|
372 |
TBool startNewPage; // Inserts page break before this paragraph when ETrue.
|
sl@0
|
373 |
TBool widowOrphan; // Prevents widowing/orphaning of para. lines when ETrue.
|
sl@0
|
374 |
TPageLine pageLine;
|
sl@0
|
375 |
TInt numLines;
|
sl@0
|
376 |
CParaFormat* paraFormat=NULL;
|
sl@0
|
377 |
|
sl@0
|
378 |
paraFormat=CParaFormat::NewLC();
|
sl@0
|
379 |
iLayDoc->GetParagraphFormatL(paraFormat,iDocPos);
|
sl@0
|
380 |
TInt docPos=iDocPos;
|
sl@0
|
381 |
TBool startOfPara=(iLayDoc->LdToParagraphStart(docPos)==0);
|
sl@0
|
382 |
|
sl@0
|
383 |
keepTogether=paraFormat->iKeepTogether;
|
sl@0
|
384 |
keepWithNext=paraFormat->iKeepWithNext;
|
sl@0
|
385 |
startNewPage=paraFormat->iStartNewPage;
|
sl@0
|
386 |
widowOrphan=paraFormat->iWidowOrphan;
|
sl@0
|
387 |
|
sl@0
|
388 |
iPageLineArray->Reset(); // Better safe than sorry at the moment ###
|
sl@0
|
389 |
iPageLineArray->Compress();
|
sl@0
|
390 |
|
sl@0
|
391 |
TInt lines=0;
|
sl@0
|
392 |
TBool moreToDo = ETrue;
|
sl@0
|
393 |
do
|
sl@0
|
394 |
{
|
sl@0
|
395 |
pageLine.iDocPos=iDocPos;
|
sl@0
|
396 |
pageLine.iStartNewPage=EFalse;
|
sl@0
|
397 |
if (iPageBreakChar)
|
sl@0
|
398 |
pageLine.iStartNewPage=ETrue;
|
sl@0
|
399 |
moreToDo=iLayout->FormatLineL(paraFormat,iDocPos,lineHeight,iPageBreakChar);
|
sl@0
|
400 |
lines++;
|
sl@0
|
401 |
pageLine.iLineHeight=lineHeight;
|
sl@0
|
402 |
if (keepTogether)
|
sl@0
|
403 |
pageLine.iKeepWithNext=ETrue;
|
sl@0
|
404 |
else
|
sl@0
|
405 |
pageLine.iKeepWithNext=EFalse;
|
sl@0
|
406 |
iPageLineArray->AppendL(pageLine);
|
sl@0
|
407 |
} while (moreToDo && lines<EFMaximumNumberLinesInBlock);
|
sl@0
|
408 |
|
sl@0
|
409 |
|
sl@0
|
410 |
TBool endOfPara=(!moreToDo);
|
sl@0
|
411 |
TBool penultimateLine=EFalse;
|
sl@0
|
412 |
numLines=iPageLineArray->Count();
|
sl@0
|
413 |
if (!endOfPara)
|
sl@0
|
414 |
{
|
sl@0
|
415 |
docPos=iDocPos;
|
sl@0
|
416 |
TBool pageBreakChar;
|
sl@0
|
417 |
penultimateLine=(!iLayout->FormatLineL(paraFormat,docPos,lineHeight,pageBreakChar));
|
sl@0
|
418 |
}
|
sl@0
|
419 |
|
sl@0
|
420 |
if (startNewPage && startOfPara)
|
sl@0
|
421 |
(*iPageLineArray)[0].iStartNewPage=ETrue;
|
sl@0
|
422 |
|
sl@0
|
423 |
if (keepTogether && endOfPara)
|
sl@0
|
424 |
(*iPageLineArray)[numLines-1].iKeepWithNext=EFalse;
|
sl@0
|
425 |
|
sl@0
|
426 |
if (keepWithNext && endOfPara)
|
sl@0
|
427 |
(*iPageLineArray)[numLines-1].iKeepWithNext=ETrue;
|
sl@0
|
428 |
|
sl@0
|
429 |
if (widowOrphan)
|
sl@0
|
430 |
{
|
sl@0
|
431 |
if (startOfPara)
|
sl@0
|
432 |
(*iPageLineArray)[0].iKeepWithNext=ETrue;
|
sl@0
|
433 |
if (endOfPara && numLines>=2)
|
sl@0
|
434 |
(*iPageLineArray)[numLines-2].iKeepWithNext=ETrue;
|
sl@0
|
435 |
else if (penultimateLine)
|
sl@0
|
436 |
(*iPageLineArray)[numLines-1].iKeepWithNext=ETrue;
|
sl@0
|
437 |
}
|
sl@0
|
438 |
|
sl@0
|
439 |
TBool pageBreak = EFalse;
|
sl@0
|
440 |
for (TInt i=0; i<numLines; i++)
|
sl@0
|
441 |
{
|
sl@0
|
442 |
pageBreak=iPaginator.AppendLineL((*iPageLineArray)[i]);
|
sl@0
|
443 |
if (pageBreak)
|
sl@0
|
444 |
PageCompleted();
|
sl@0
|
445 |
}
|
sl@0
|
446 |
|
sl@0
|
447 |
iPageLineArray->Reset();
|
sl@0
|
448 |
iPageLineArray->Compress();
|
sl@0
|
449 |
|
sl@0
|
450 |
CleanupStack::PopAndDestroy(); // delete format;
|
sl@0
|
451 |
}
|
sl@0
|
452 |
|
sl@0
|
453 |
void CTextPaginator::PageCompleted()
|
sl@0
|
454 |
{
|
sl@0
|
455 |
if (iObserver)
|
sl@0
|
456 |
iObserver->NotifyPageCompletion(iTempPageList->Count());
|
sl@0
|
457 |
}
|
sl@0
|
458 |
|
sl@0
|
459 |
void CTextPaginator::Reque()
|
sl@0
|
460 |
//
|
sl@0
|
461 |
// Called just before Paginate Process goes to sleep to set it active
|
sl@0
|
462 |
//
|
sl@0
|
463 |
{
|
sl@0
|
464 |
TRequestStatus *pS=(&iStatus);
|
sl@0
|
465 |
User::RequestComplete(pS,0);
|
sl@0
|
466 |
SetActive();
|
sl@0
|
467 |
}
|
sl@0
|
468 |
|
sl@0
|
469 |
void CTextPaginator::ResetPaginator()
|
sl@0
|
470 |
//
|
sl@0
|
471 |
{
|
sl@0
|
472 |
|
sl@0
|
473 |
iDocPos=0;
|
sl@0
|
474 |
iPageBreakChar=EFalse;
|
sl@0
|
475 |
iPaginator.Reset();
|
sl@0
|
476 |
}
|
sl@0
|
477 |
|
sl@0
|
478 |
void CTextPaginator::CopyTempPageListL()
|
sl@0
|
479 |
//
|
sl@0
|
480 |
// Copies temp page list to one that external user sees
|
sl@0
|
481 |
//
|
sl@0
|
482 |
{
|
sl@0
|
483 |
if (iTempPageList->Count()<1 && iMode!=EFPaginateIncrementally)
|
sl@0
|
484 |
{
|
sl@0
|
485 |
OstTrace0( TRACE_DUMP, CTEXTPAGINATOR_COPYTEMPPAGELISTL, "EFPageListEmpty" );
|
sl@0
|
486 |
}
|
sl@0
|
487 |
__ASSERT_DEBUG(iTempPageList->Count()>=1||iMode==EFPaginateIncrementally,FormPanic(EFPageListEmpty));
|
sl@0
|
488 |
TRAPD(err,iPageList->ResizeL(iTempPageList->Count()));
|
sl@0
|
489 |
if (err)
|
sl@0
|
490 |
LeaveL(err);
|
sl@0
|
491 |
|
sl@0
|
492 |
{for(TInt ii=0;ii<iTempPageList->Count();ii++)
|
sl@0
|
493 |
(*iPageList)[ii]=(*iTempPageList)[ii];
|
sl@0
|
494 |
}
|
sl@0
|
495 |
}
|
sl@0
|
496 |
|
sl@0
|
497 |
|
sl@0
|
498 |
void CTextPaginator::LeaveL(TInt aErr)
|
sl@0
|
499 |
//
|
sl@0
|
500 |
// Something has left
|
sl@0
|
501 |
// Reset everything.
|
sl@0
|
502 |
//
|
sl@0
|
503 |
{
|
sl@0
|
504 |
iPaginator.Reset();
|
sl@0
|
505 |
iLayout->DiscardFormat();
|
sl@0
|
506 |
iDocPos=0;
|
sl@0
|
507 |
|
sl@0
|
508 |
iPageLineArray->Reset();
|
sl@0
|
509 |
iPageLineArray->Compress();
|
sl@0
|
510 |
iTempPageList->Reset();
|
sl@0
|
511 |
iTempPageList->Compress();
|
sl@0
|
512 |
|
sl@0
|
513 |
if (iObserver)
|
sl@0
|
514 |
iObserver->NotifyError(aErr);
|
sl@0
|
515 |
|
sl@0
|
516 |
OstTrace1( TRACE_FATAL, CTEXTPAGINATOR_LEAVEL, "CTextPaginator::LeaveL;aErr=%d", aErr );
|
sl@0
|
517 |
|
sl@0
|
518 |
User::Leave(aErr);
|
sl@0
|
519 |
}
|
sl@0
|
520 |
|