|
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 "CANONSTD.H" |
|
17 |
|
18 #include <banddev.h> |
|
19 #include <fbs.h> |
|
20 #include "CANON.H" |
|
21 #include "pdrtext.h" |
|
22 |
|
23 |
|
24 EXPORT_C CPrinterDevice* NewPrinterDeviceL() |
|
25 { |
|
26 CCanonDevice* device = new(ELeave) CCanonDevice; |
|
27 return device; |
|
28 } |
|
29 |
|
30 CCanonDevice::CCanonDevice(): |
|
31 CFbsDrvDevice() |
|
32 { |
|
33 __DECLARE_NAME(_S("CCanonDevice")); |
|
34 } |
|
35 |
|
36 CCanonDevice::~CCanonDevice() |
|
37 { |
|
38 } |
|
39 |
|
40 TInt CCanonDevice::CreateContext(CGraphicsContext*& aGC) |
|
41 { |
|
42 __ASSERT_DEBUG(iControl, Panic(ECanonControlDoesNotExist)); |
|
43 CPdrControl* control = (CPdrControl*)iControl; |
|
44 return control->CreateContext(aGC); |
|
45 } |
|
46 |
|
47 void CCanonDevice::CreateControlL(CPrinterPort* aPrinterPort) |
|
48 { |
|
49 __ASSERT_ALWAYS(aPrinterPort, Panic(ECanonRequiresPrinterPort)); |
|
50 __ASSERT_ALWAYS(!iControl, Panic(ECanonControlAlreadyExists)); |
|
51 __ASSERT_DEBUG(iCurrentPageSpecInTwips.iPortraitPageSize.iWidth && iCurrentPageSpecInTwips.iPortraitPageSize.iHeight, Panic(ECanonPageSpecNotSet)); |
|
52 iControl = CCanonControl::NewL(this, aPrinterPort, *iStore, iModelInfo->iResourcesStreamId); |
|
53 } |
|
54 |
|
55 CCanonControl* CCanonControl::NewL(CPdrDevice* aPdrDevice, CPrinterPort* aPrinterPort, CStreamStore& aStore, TStreamId aResourcesStreamId) |
|
56 { |
|
57 CCanonControl* control = new(ELeave) CCanonControl(aPdrDevice, aPrinterPort); |
|
58 CleanupStack::PushL(control); |
|
59 control->ConstructL(aStore, aResourcesStreamId); |
|
60 CleanupStack::Pop(); |
|
61 return control; |
|
62 } |
|
63 |
|
64 CCanonControl::~CCanonControl() |
|
65 { |
|
66 } |
|
67 |
|
68 void CCanonControl::ConstructL(CStreamStore& aStore, TStreamId aResourcesStreamId) |
|
69 { |
|
70 if((iPdrDevice->CurrentPageSpecInTwips().iOrientation == TPageSpec::ELandscape) |
|
71 && (iPdrDevice->Flags() & ECanonLandscapeNotAvailable)) |
|
72 User::Leave(KErrNotSupported); |
|
73 CFbsDrvControl::ConstructL(aStore, aResourcesStreamId); |
|
74 |
|
75 TRect rect = iPdrDevice->PrintablePageInPixels(); |
|
76 TSize size; |
|
77 size.iWidth = iPdrDevice->HorizontalPixelsToTwips(1000); |
|
78 size.iHeight = iPdrDevice->VerticalPixelsToTwips(1000); |
|
79 iBandedDevice = CBandedDevice::NewL(rect, size, iPdrDevice->DisplayMode(), EBandingTopToBottom, KCanonNumScanLinesPerBand); |
|
80 TInt len = CFbsBitmap::ScanLineLength(iBandedDevice->BandBitmap()->SizeInPixels().iWidth, iPdrDevice->DisplayMode()); |
|
81 CFbsDrvControl::iScanLine = HBufC8::NewL(len); |
|
82 CFbsDrvControl::iCompressedScanLine = HBufC8::NewL(len); |
|
83 iPageText = CPageText::NewL(); |
|
84 } |
|
85 |
|
86 void CCanonControl::OutputBandL() |
|
87 { |
|
88 if(IsGraphicsBand()) |
|
89 { |
|
90 TRect bandrect = iBandedDevice->BandRect(); |
|
91 TSize size = bandrect.Size(); |
|
92 TCommandString des; |
|
93 TBool datainband = EFalse; |
|
94 for(TInt i = 0; i < size.iWidth; i++) |
|
95 { |
|
96 iBandedDevice->BandBitmap()->GetVerticalScanLine(iScanLine, i, iPdrDevice->DisplayMode()); |
|
97 if(TransformBuffer() && !datainband) |
|
98 { |
|
99 MoveToL(bandrect.iTl + TPoint(i, 0)); |
|
100 des.Format(iResources->ResourceString(EPdrBitmapStart), KCanonBytesPerDotColumn * (size.iWidth - i)); |
|
101 iPageBuffer->AddBytesL(des); |
|
102 datainband = ETrue; |
|
103 } |
|
104 if(datainband) |
|
105 iPageBuffer->AddBytesL(iScanLine); |
|
106 } |
|
107 iPageBuffer->AddBytesL(iResources->ResourceString(EPdrBitmapEnd)); |
|
108 |
|
109 iPosition.iX = iPdrDevice->OffsetInPixels().iX; |
|
110 TInt numentries = iPageText->NumEntries(); |
|
111 if(numentries) |
|
112 { |
|
113 CPageTextEntry* entry; |
|
114 for(TInt y = bandrect.iTl.iY; y <= bandrect.iBr.iY; y++) |
|
115 { |
|
116 for(TInt index = 0; (index < numentries); index++) |
|
117 { |
|
118 entry = (*iPageText)[index]; |
|
119 TPoint drawPos = entry->iDrawPos - TPoint(0, 16); // bodge to align pdr fonts with true types |
|
120 if(drawPos.iY == y) |
|
121 OutputTextL(drawPos, entry->iTextWidthInPixels, *(entry->iTextFormat), *(entry->iText)); |
|
122 } |
|
123 } |
|
124 } |
|
125 } |
|
126 } |
|
127 |
|
128 void CCanonControl::MoveToL(const TPoint& aPoint) |
|
129 { |
|
130 TPoint vector = aPoint - iPosition; |
|
131 TInt maxNoOfYIncrements = 256 * 5 / 6; // Ensures no more than 256 |
|
132 for(; vector.iY >= maxNoOfYIncrements; ) |
|
133 { |
|
134 MoveByL(TPoint(0, maxNoOfYIncrements)); |
|
135 vector = aPoint - iPosition; |
|
136 } |
|
137 MoveByL(vector); |
|
138 iPosition = aPoint; |
|
139 } |
|
140 |
|
141 void CCanonControl::MoveByL(const TPoint& aPoint) |
|
142 { |
|
143 TPoint vector = aPoint; |
|
144 if(vector.iX < 0) |
|
145 { |
|
146 CommandL(EPdrCarriageReturn); |
|
147 vector.iX += iPosition.iX - iPdrDevice->OffsetInPixels().iX; |
|
148 } |
|
149 vector.iX = vector.iX * 2 / 3; // X increments are in 120ths of an inch |
|
150 vector.iY = vector.iY * 6 / 5; // Y increments are in 216ths of an inch |
|
151 TPoint oldPosition = iPosition; |
|
152 CFbsDrvControl::MoveByL(vector); |
|
153 iPosition = oldPosition + aPoint; // Correct the position |
|
154 } |
|
155 |
|
156 TBool CCanonControl::TransformBuffer() |
|
157 { |
|
158 TUint8* pStart = (TUint8*)iScanLine.Ptr(); |
|
159 TUint8* pEnd = pStart + (KCanonNumScanLinesPerBand >> 3); |
|
160 TUint8* p; |
|
161 for(p = pStart; (p < pEnd) && (*p == 0xFF); p++) |
|
162 { |
|
163 } |
|
164 TBool datainscanline = (p < pEnd); |
|
165 for(p = pStart; p < pEnd; p++) |
|
166 { |
|
167 TInt byte1 = *p; |
|
168 TInt byte2 = 0; |
|
169 for(TInt j = 0; j < 8; j++) |
|
170 { |
|
171 byte2 = byte2 << 1; |
|
172 byte2 = byte2 | (byte1 & 1); |
|
173 byte1 = byte1 >> 1; |
|
174 } |
|
175 *p = (TUint8)~byte2; |
|
176 } |
|
177 return datainscanline; // returns ETrue if there are non-blank bytes in scanline |
|
178 } |
|
179 |
|
180 CCanonControl::CCanonControl(CPdrDevice* aPdrDevice, CPrinterPort* aPrinterPort): |
|
181 CFbsDrvControl(aPdrDevice, aPrinterPort) |
|
182 { |
|
183 __DECLARE_NAME(_S("CCanonControl")); |
|
184 } |
|
185 |