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