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