Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
24 EXPORT_C CPrinterDevice* NewPrinterDeviceL()
26 CPcl5Device* device = new(ELeave) CPcl5Device;
30 CPcl5Device::CPcl5Device()
33 __DECLARE_NAME(_S("CPcl5Device"));
36 CPcl5Device::~CPcl5Device()
40 TInt CPcl5Device::CreateContext(CGraphicsContext*& aGC)
42 __ASSERT_DEBUG(iControl,Panic(EPcl5ControlDoesNotExist));
43 CPdrControl* control=(CPdrControl*) iControl;
44 return control->CreateContext(aGC);
47 void CPcl5Device::CreateControlL(CPrinterPort* aPrinterPort)
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);
55 CPcl5Control* CPcl5Control::NewL(CPdrDevice* aPdrDevice, CPrinterPort* aPrinterPort, CStreamStore& aStore, TStreamId aResourcesStreamId)
57 CPcl5Control* control = new(ELeave) CPcl5Control(aPdrDevice, aPrinterPort);
58 CleanupStack::PushL(control);
59 control->ConstructL(aStore, aResourcesStreamId);
64 CPcl5Control::~CPcl5Control()
68 CPcl5Control::CPcl5Control(CPdrDevice* aPdrDevice, CPrinterPort* aPrinterPort)
69 : CFbsDrvControl(aPdrDevice, aPrinterPort)
71 __DECLARE_NAME(_S("CPcl5Control"));
74 CPrinterControl::TMoreOnPage CPcl5Control::QueueGetBand(TRequestStatus& aStatus, TBandAttributes& aBand)
76 TMoreOnPage moreonpage = ENoMoreOnPage;
77 TRAPD(ret, DoQueueGetBandL());
80 TRequestStatus* status = &aStatus;
81 User::RequestComplete(status, ret);
87 aBand.iRect = iBandedDevice->BandRect();
88 aBand.iTextIsIgnored = ETrue;
89 aBand.iGraphicsIsIgnored = EFalse;
90 aBand.iFirstBandOnPage = EFalse;
94 aBand.iRect = iPdrDevice->PrintablePageInPixels();
95 aBand.iTextIsIgnored = EFalse;
96 aBand.iGraphicsIsIgnored = ETrue;
97 aBand.iFirstBandOnPage = ETrue;
99 if (iBandIndex == (BandsPerPage() - 1))
101 moreonpage = ENoMoreOnPage;
102 if (!(iPdrDevice->Flags() & EPcl5DeskjetPrinter))
104 CPageTextEntry* entry; //!!
105 TInt numentries = iPageText->NumEntries();
106 for (; (iEntryIndex < numentries); iEntryIndex++) //!!
108 entry = (*iPageText)[iEntryIndex];
109 OutputTextL(entry->iDrawPos, entry->iTextWidthInPixels, *(entry->iTextFormat), *(entry->iText)); //!!
114 moreonpage = EMoreOnPage;
115 iPageBuffer->StartFlush(aStatus);
120 void CPcl5Control::ConstructL(CStreamStore& aStore, TStreamId aResourcesStreamId)
122 if ((iPdrDevice->CurrentPageSpecInTwips().iOrientation == TPageSpec::ELandscape)
123 && (iPdrDevice->Flags() & EPcl5LandscapeNotAvailable))
124 User::Leave(KErrNotSupported);
125 CFbsDrvControl::ConstructL(aStore, aResourcesStreamId);
127 TRect rect = iPdrDevice->PrintablePageInPixels();
128 iLandscapeMode = ((iPdrDevice->CurrentPageSpecInTwips().iOrientation == TPageSpec::ELandscape)
129 && !(iPdrDevice->Flags() & EPcl5LandscapeNotAvailable));
130 TBandingDirection bandorientation =
132 (iLandscapeMode && (iPdrDevice->Flags() & EPcl5LandscapeBandingRightToLeft)) ?
133 EBandingRightToLeft :
137 size.iWidth = iPdrDevice->HorizontalPixelsToTwips(1000);
138 size.iHeight = iPdrDevice->VerticalPixelsToTwips(1000);
139 iBandedDevice = CBandedDevice::NewL(rect, size, iPdrDevice->DisplayMode(), bandorientation);
142 (bandorientation == EBandingTopToBottom) ?
143 CFbsBitmap::ScanLineLength(iBandedDevice->BandBitmap()->SizeInPixels().iWidth, iPdrDevice->DisplayMode()) :
144 CFbsBitmap::ScanLineLength(iBandedDevice->BandBitmap()->SizeInPixels().iHeight, iPdrDevice->DisplayMode())
146 iScanLine = HBufC8::NewL(len);
147 iCompressedScanLine = HBufC8::NewL(len);
148 if (!iLandscapeMode || !(iPdrDevice->Flags() & EPcl5DeskjetPrinter))
149 iPageText = CPageText::NewL();
152 void CPcl5Control::OutputBandL()
154 if (IsGraphicsBand())
156 TRect bandrect = iBandedDevice->BandRect();
157 TSize size = bandrect.Size();
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++)
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());
172 iBandedDevice->BandBitmap()->GetVerticalScanLine(ptr, numscanlines - (i + 1), iPdrDevice->DisplayMode());
173 x = bandrect.iBr.iX - i;
176 if ((iPdrDevice->Flags() & EPcl5DeskjetPrinter) && !iLandscapeMode)
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++)
183 OutputTextL(entry->iDrawPos, entry->iTextWidthInPixels, *(entry->iTextFormat), *(entry->iText));
184 textinscanline = ETrue;
186 if (textinscanline && datainband)
187 MoveToL(TPoint(x, y));
189 if (TransformBuffer() && !datainband)
191 MoveToL(TPoint(x, y));
192 if (iBandedDevice->BandingDirection() == EBandingLeftToRight)
193 des.Format(iResources->ResourceString(EPdrBitmapStart), EPcl5PhysicalPageOrientation);
195 des.Format(iResources->ResourceString(EPdrBitmapStart), EPcl5LogicalPageOrientation);
196 iPageBuffer->AddBytesL(des);
201 TCommandString buf = iResources->ResourceString(EPdrScanLine);
202 if (CompressBuffer())
204 des.Format(buf, EPcl5RunLength, iCompressedScanLine->Des().Length());
205 iPageBuffer->AddBytesL(des);
206 iPageBuffer->AddBytesL(iCompressedScanLine->Des());
210 des.Format(buf, EPcl5None, iScanLine->Des().Length());
211 iPageBuffer->AddBytesL(des);
212 iPageBuffer->AddBytesL(iScanLine->Des());
217 iPageBuffer->AddBytesL(iResources->ResourceString(EPdrBitmapEnd));
221 void CPcl5Control::SetPageSizeL()
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);
244 void CPcl5Control::SetPageOrientationL()
247 CommandL(EPdrLandscape);
249 CommandL(EPdrPortrait);
252 void CPcl5Control::SetTextColorL(const TRgb& aColor)
255 TInt color = aColor.Gray2();
256 if (iPdrDevice->Flags() & EPcl5DeskjetPrinter)
258 des.Format(iResources->ResourceString(EPdrSetTextColor), color);
259 iPageBuffer->AddBytesL(des);