printingservices/printerdrivers/pcl5/PCL5.CPP
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "PCL5STD.H"
       
    17 
       
    18 #include <fbs.h>
       
    19 #include <banddev.h>
       
    20 #include "PCL5.H"
       
    21 #include "pdrtext.h"
       
    22 
       
    23 
       
    24 EXPORT_C CPrinterDevice* NewPrinterDeviceL()
       
    25 	{
       
    26 	CPcl5Device* device = new(ELeave) CPcl5Device;
       
    27 	return device;
       
    28 	}
       
    29 
       
    30 CPcl5Device::CPcl5Device()
       
    31 :	CFbsDrvDevice()
       
    32 	{
       
    33 	__DECLARE_NAME(_S("CPcl5Device"));
       
    34 	}
       
    35 
       
    36 CPcl5Device::~CPcl5Device()
       
    37 	{
       
    38 	}
       
    39 
       
    40 TInt CPcl5Device::CreateContext(CGraphicsContext*& aGC)
       
    41 	{
       
    42 	__ASSERT_DEBUG(iControl,Panic(EPcl5ControlDoesNotExist));
       
    43 	CPdrControl* control=(CPdrControl*) iControl;
       
    44 	return control->CreateContext(aGC);
       
    45 	}
       
    46 
       
    47 void CPcl5Device::CreateControlL(CPrinterPort* aPrinterPort)
       
    48 	{
       
    49 	__ASSERT_ALWAYS(aPrinterPort, Panic(EPcl5RequiresPrinterPort));
       
    50 	__ASSERT_ALWAYS(!iControl, Panic(EPcl5ControlAlreadyExists));
       
    51 	__ASSERT_DEBUG(iCurrentPageSpecInTwips.iPortraitPageSize.iWidth && iCurrentPageSpecInTwips.iPortraitPageSize.iHeight, Panic(EPcl5PageSpecNotSet));
       
    52 	iControl = CPcl5Control::NewL(this, aPrinterPort, *iStore, iModelInfo->iResourcesStreamId);
       
    53 	}
       
    54 
       
    55 CPcl5Control* CPcl5Control::NewL(CPdrDevice* aPdrDevice, CPrinterPort* aPrinterPort, CStreamStore& aStore, TStreamId aResourcesStreamId)
       
    56 	{
       
    57 	CPcl5Control* control = new(ELeave) CPcl5Control(aPdrDevice, aPrinterPort);
       
    58 	CleanupStack::PushL(control);
       
    59 	control->ConstructL(aStore, aResourcesStreamId);
       
    60 	CleanupStack::Pop();
       
    61 	return control;
       
    62 	}
       
    63 
       
    64 CPcl5Control::~CPcl5Control()
       
    65 	{
       
    66 	}
       
    67 
       
    68 CPcl5Control::CPcl5Control(CPdrDevice* aPdrDevice, CPrinterPort* aPrinterPort)
       
    69 :	CFbsDrvControl(aPdrDevice, aPrinterPort)
       
    70 	{
       
    71 	__DECLARE_NAME(_S("CPcl5Control"));
       
    72 	}
       
    73 
       
    74 CPrinterControl::TMoreOnPage CPcl5Control::QueueGetBand(TRequestStatus& aStatus, TBandAttributes& aBand)
       
    75 	{
       
    76 	TMoreOnPage moreonpage = ENoMoreOnPage;
       
    77 	TRAPD(ret, DoQueueGetBandL());
       
    78 	if (ret != KErrNone)
       
    79 		{
       
    80 		TRequestStatus* status = &aStatus;
       
    81 		User::RequestComplete(status, ret);
       
    82 		}
       
    83 	else
       
    84 		{
       
    85 		if (IsGraphicsBand())
       
    86 			{
       
    87 			aBand.iRect = iBandedDevice->BandRect();
       
    88 			aBand.iTextIsIgnored = ETrue;
       
    89 			aBand.iGraphicsIsIgnored = EFalse;
       
    90 			aBand.iFirstBandOnPage = EFalse;
       
    91 			}
       
    92 		else
       
    93 			{
       
    94 			aBand.iRect = iPdrDevice->PrintablePageInPixels();
       
    95 			aBand.iTextIsIgnored = EFalse;
       
    96 			aBand.iGraphicsIsIgnored = ETrue;
       
    97 			aBand.iFirstBandOnPage = ETrue;
       
    98 			}
       
    99 		if (iBandIndex == (BandsPerPage() - 1))
       
   100 			{
       
   101 			moreonpage = ENoMoreOnPage;
       
   102 			if (!(iPdrDevice->Flags() & EPcl5DeskjetPrinter))
       
   103 				{
       
   104 				CPageTextEntry* entry; //!!
       
   105 				TInt numentries = iPageText->NumEntries();
       
   106 				for (; (iEntryIndex < numentries); iEntryIndex++) //!!
       
   107 					{	
       
   108 					entry = (*iPageText)[iEntryIndex];
       
   109 					OutputTextL(entry->iDrawPos, entry->iTextWidthInPixels, *(entry->iTextFormat), *(entry->iText)); //!!
       
   110 					}
       
   111 				}
       
   112 			}
       
   113 		else
       
   114 			moreonpage = EMoreOnPage;
       
   115 		iPageBuffer->StartFlush(aStatus);
       
   116 		}
       
   117 	return moreonpage;
       
   118 	}
       
   119 
       
   120 void CPcl5Control::ConstructL(CStreamStore& aStore, TStreamId aResourcesStreamId)
       
   121 	{
       
   122 	if ((iPdrDevice->CurrentPageSpecInTwips().iOrientation == TPageSpec::ELandscape)
       
   123 		&& (iPdrDevice->Flags() & EPcl5LandscapeNotAvailable))
       
   124 		User::Leave(KErrNotSupported);
       
   125 	CFbsDrvControl::ConstructL(aStore, aResourcesStreamId);
       
   126 
       
   127 	TRect rect = iPdrDevice->PrintablePageInPixels();
       
   128 	iLandscapeMode = ((iPdrDevice->CurrentPageSpecInTwips().iOrientation == TPageSpec::ELandscape)
       
   129 		&& !(iPdrDevice->Flags() & EPcl5LandscapeNotAvailable));
       
   130 	TBandingDirection bandorientation =
       
   131 		{
       
   132 		(iLandscapeMode && (iPdrDevice->Flags() & EPcl5LandscapeBandingRightToLeft)) ?
       
   133 		EBandingRightToLeft :
       
   134 		EBandingTopToBottom
       
   135 		};	
       
   136 	TSize size;
       
   137 	size.iWidth = iPdrDevice->HorizontalPixelsToTwips(1000);
       
   138 	size.iHeight = iPdrDevice->VerticalPixelsToTwips(1000);
       
   139 	iBandedDevice = CBandedDevice::NewL(rect, size, iPdrDevice->DisplayMode(), bandorientation);
       
   140 	TInt len =
       
   141 		{
       
   142 		(bandorientation == EBandingTopToBottom) ?
       
   143 		CFbsBitmap::ScanLineLength(iBandedDevice->BandBitmap()->SizeInPixels().iWidth, iPdrDevice->DisplayMode()) :
       
   144 		CFbsBitmap::ScanLineLength(iBandedDevice->BandBitmap()->SizeInPixels().iHeight, iPdrDevice->DisplayMode())
       
   145 		};
       
   146 	iScanLine = HBufC8::NewL(len);
       
   147 	iCompressedScanLine = HBufC8::NewL(len);
       
   148 	if (!iLandscapeMode || !(iPdrDevice->Flags() & EPcl5DeskjetPrinter))
       
   149 		iPageText = CPageText::NewL();
       
   150 	}
       
   151 
       
   152 void CPcl5Control::OutputBandL()
       
   153 	{
       
   154 	if (IsGraphicsBand())
       
   155 		{
       
   156 		TRect bandrect = iBandedDevice->BandRect();
       
   157 		TSize size = bandrect.Size();
       
   158 		TCommandString des;
       
   159 		TBool datainband = EFalse;
       
   160 		TInt numscanlines = size.iHeight;
       
   161 		if (iBandedDevice->BandingDirection() == EBandingRightToLeft)
       
   162 			numscanlines = size.iWidth;
       
   163 		for (TInt i = 0; i < numscanlines; i++)
       
   164 			{
       
   165 			TInt x = bandrect.iTl.iX;
       
   166 			TInt y = bandrect.iTl.iY + i;
       
   167 			TPtr8 ptr = iScanLine->Des();
       
   168 			if (iBandedDevice->BandingDirection() == EBandingTopToBottom)
       
   169 				iBandedDevice->BandBitmap()->GetScanLine(ptr, TPoint(0, i), size.iWidth, iPdrDevice->DisplayMode());
       
   170 			else
       
   171 				{
       
   172 				iBandedDevice->BandBitmap()->GetVerticalScanLine(ptr, numscanlines - (i + 1), iPdrDevice->DisplayMode());
       
   173 				x = bandrect.iBr.iX - i;
       
   174 				y = bandrect.iTl.iY;
       
   175 				}
       
   176 			if ((iPdrDevice->Flags() & EPcl5DeskjetPrinter) && !iLandscapeMode)
       
   177 				{
       
   178 				CPageTextEntry* entry;
       
   179 				TBool textinscanline=EFalse;
       
   180 				TInt numentries=iPageText->NumEntries();
       
   181 				for (; (iEntryIndex < numentries) && ((entry = (*iPageText)[iEntryIndex])->iDrawPos.iY <= (y + iPageText->MaxFontHeightInPixels())); iEntryIndex++)
       
   182 					{
       
   183 					OutputTextL(entry->iDrawPos, entry->iTextWidthInPixels, *(entry->iTextFormat), *(entry->iText));
       
   184 					textinscanline = ETrue;
       
   185 					}
       
   186 				if (textinscanline && datainband)
       
   187 					MoveToL(TPoint(x, y));
       
   188 				}
       
   189 			if (TransformBuffer() && !datainband)
       
   190 				{
       
   191 				MoveToL(TPoint(x, y));
       
   192 				if (iBandedDevice->BandingDirection() == EBandingLeftToRight)
       
   193 					des.Format(iResources->ResourceString(EPdrBitmapStart), EPcl5PhysicalPageOrientation);
       
   194 				else
       
   195 					des.Format(iResources->ResourceString(EPdrBitmapStart), EPcl5LogicalPageOrientation);
       
   196 				iPageBuffer->AddBytesL(des);
       
   197 				datainband = ETrue;
       
   198 				}
       
   199 			if (datainband)
       
   200 				{
       
   201 				TCommandString buf = iResources->ResourceString(EPdrScanLine);
       
   202 				if (CompressBuffer())
       
   203 					{
       
   204 					des.Format(buf, EPcl5RunLength, iCompressedScanLine->Des().Length());
       
   205 					iPageBuffer->AddBytesL(des);
       
   206 					iPageBuffer->AddBytesL(iCompressedScanLine->Des());
       
   207 					}
       
   208 				else
       
   209 					{
       
   210 					des.Format(buf, EPcl5None, iScanLine->Des().Length());
       
   211 					iPageBuffer->AddBytesL(des);
       
   212 					iPageBuffer->AddBytesL(iScanLine->Des());
       
   213 					}
       
   214 				}
       
   215 			}
       
   216 		if (datainband)
       
   217 			iPageBuffer->AddBytesL(iResources->ResourceString(EPdrBitmapEnd));
       
   218 		}
       
   219 	}
       
   220 
       
   221 void CPcl5Control::SetPageSizeL()
       
   222 	{
       
   223 	TCommandString des;  //  Need more paper sizes
       
   224 	TSize size = iPdrDevice->CurrentPageSpecInTwips().iPortraitPageSize;
       
   225 	if (size == KA4PaperSizeInTwips)
       
   226 		des.Format(iResources->ResourceString(EPdrSetPageSize), EPcl5A4);
       
   227 	else if (size == KLegalPaperSizeInTwips)
       
   228 		des.Format(iResources->ResourceString(EPdrSetPageSize), EPcl5Legal);
       
   229 	else if (size == KExecutivePaperSizeInTwips)
       
   230 		des.Format(iResources->ResourceString(EPdrSetPageSize), EPcl5Executive);
       
   231 	else if (size == KLetterPaperSizeInTwips)
       
   232 		des.Format(iResources->ResourceString(EPdrSetPageSize), EPcl5Letter);
       
   233 	else if (size == KCom_10PaperSizeInTwips)
       
   234 		des.Format(iResources->ResourceString(EPdrSetPageSize), EPcl5Com_10);
       
   235 	else if (size == KMonarchPaperSizeInTwips)
       
   236 		des.Format(iResources->ResourceString(EPdrSetPageSize), EPcl5Monarch);
       
   237 	else if (size == KDLPaperSizeInTwips)
       
   238 		des.Format(iResources->ResourceString(EPdrSetPageSize), EPcl5DL);
       
   239 	else if (size == KC5PaperSizeInTwips)
       
   240 		des.Format(iResources->ResourceString(EPdrSetPageSize), EPcl5C5);
       
   241 	iPageBuffer->AddBytesL(des);
       
   242 	}
       
   243 
       
   244 void CPcl5Control::SetPageOrientationL()
       
   245 	{
       
   246 	if (iLandscapeMode)
       
   247 		CommandL(EPdrLandscape);
       
   248 	else
       
   249 		CommandL(EPdrPortrait);
       
   250 	}
       
   251 
       
   252 void CPcl5Control::SetTextColorL(const TRgb& aColor)
       
   253 	{
       
   254 	TCommandString des;
       
   255 	TInt color = aColor.Gray2();
       
   256 	if (iPdrDevice->Flags() & EPcl5DeskjetPrinter)
       
   257 		color = !color;
       
   258 	des.Format(iResources->ResourceString(EPdrSetTextColor), color);
       
   259 	iPageBuffer->AddBytesL(des);
       
   260 	}