1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/printingservices/printerdrivers/canon/CANON.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,185 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "CANONSTD.H"
1.20 +
1.21 +#include <banddev.h>
1.22 +#include <fbs.h>
1.23 +#include "CANON.H"
1.24 +#include "pdrtext.h"
1.25 +
1.26 +
1.27 +EXPORT_C CPrinterDevice* NewPrinterDeviceL()
1.28 + {
1.29 + CCanonDevice* device = new(ELeave) CCanonDevice;
1.30 + return device;
1.31 + }
1.32 +
1.33 +CCanonDevice::CCanonDevice():
1.34 + CFbsDrvDevice()
1.35 + {
1.36 + __DECLARE_NAME(_S("CCanonDevice"));
1.37 + }
1.38 +
1.39 +CCanonDevice::~CCanonDevice()
1.40 + {
1.41 + }
1.42 +
1.43 +TInt CCanonDevice::CreateContext(CGraphicsContext*& aGC)
1.44 + {
1.45 + __ASSERT_DEBUG(iControl, Panic(ECanonControlDoesNotExist));
1.46 + CPdrControl* control = (CPdrControl*)iControl;
1.47 + return control->CreateContext(aGC);
1.48 + }
1.49 +
1.50 +void CCanonDevice::CreateControlL(CPrinterPort* aPrinterPort)
1.51 + {
1.52 + __ASSERT_ALWAYS(aPrinterPort, Panic(ECanonRequiresPrinterPort));
1.53 + __ASSERT_ALWAYS(!iControl, Panic(ECanonControlAlreadyExists));
1.54 + __ASSERT_DEBUG(iCurrentPageSpecInTwips.iPortraitPageSize.iWidth && iCurrentPageSpecInTwips.iPortraitPageSize.iHeight, Panic(ECanonPageSpecNotSet));
1.55 + iControl = CCanonControl::NewL(this, aPrinterPort, *iStore, iModelInfo->iResourcesStreamId);
1.56 + }
1.57 +
1.58 +CCanonControl* CCanonControl::NewL(CPdrDevice* aPdrDevice, CPrinterPort* aPrinterPort, CStreamStore& aStore, TStreamId aResourcesStreamId)
1.59 + {
1.60 + CCanonControl* control = new(ELeave) CCanonControl(aPdrDevice, aPrinterPort);
1.61 + CleanupStack::PushL(control);
1.62 + control->ConstructL(aStore, aResourcesStreamId);
1.63 + CleanupStack::Pop();
1.64 + return control;
1.65 + }
1.66 +
1.67 +CCanonControl::~CCanonControl()
1.68 + {
1.69 + }
1.70 +
1.71 +void CCanonControl::ConstructL(CStreamStore& aStore, TStreamId aResourcesStreamId)
1.72 + {
1.73 + if((iPdrDevice->CurrentPageSpecInTwips().iOrientation == TPageSpec::ELandscape)
1.74 + && (iPdrDevice->Flags() & ECanonLandscapeNotAvailable))
1.75 + User::Leave(KErrNotSupported);
1.76 + CFbsDrvControl::ConstructL(aStore, aResourcesStreamId);
1.77 +
1.78 + TRect rect = iPdrDevice->PrintablePageInPixels();
1.79 + TSize size;
1.80 + size.iWidth = iPdrDevice->HorizontalPixelsToTwips(1000);
1.81 + size.iHeight = iPdrDevice->VerticalPixelsToTwips(1000);
1.82 + iBandedDevice = CBandedDevice::NewL(rect, size, iPdrDevice->DisplayMode(), EBandingTopToBottom, KCanonNumScanLinesPerBand);
1.83 + TInt len = CFbsBitmap::ScanLineLength(iBandedDevice->BandBitmap()->SizeInPixels().iWidth, iPdrDevice->DisplayMode());
1.84 + CFbsDrvControl::iScanLine = HBufC8::NewL(len);
1.85 + CFbsDrvControl::iCompressedScanLine = HBufC8::NewL(len);
1.86 + iPageText = CPageText::NewL();
1.87 + }
1.88 +
1.89 +void CCanonControl::OutputBandL()
1.90 + {
1.91 + if(IsGraphicsBand())
1.92 + {
1.93 + TRect bandrect = iBandedDevice->BandRect();
1.94 + TSize size = bandrect.Size();
1.95 + TCommandString des;
1.96 + TBool datainband = EFalse;
1.97 + for(TInt i = 0; i < size.iWidth; i++)
1.98 + {
1.99 + iBandedDevice->BandBitmap()->GetVerticalScanLine(iScanLine, i, iPdrDevice->DisplayMode());
1.100 + if(TransformBuffer() && !datainband)
1.101 + {
1.102 + MoveToL(bandrect.iTl + TPoint(i, 0));
1.103 + des.Format(iResources->ResourceString(EPdrBitmapStart), KCanonBytesPerDotColumn * (size.iWidth - i));
1.104 + iPageBuffer->AddBytesL(des);
1.105 + datainband = ETrue;
1.106 + }
1.107 + if(datainband)
1.108 + iPageBuffer->AddBytesL(iScanLine);
1.109 + }
1.110 + iPageBuffer->AddBytesL(iResources->ResourceString(EPdrBitmapEnd));
1.111 +
1.112 + iPosition.iX = iPdrDevice->OffsetInPixels().iX;
1.113 + TInt numentries = iPageText->NumEntries();
1.114 + if(numentries)
1.115 + {
1.116 + CPageTextEntry* entry;
1.117 + for(TInt y = bandrect.iTl.iY; y <= bandrect.iBr.iY; y++)
1.118 + {
1.119 + for(TInt index = 0; (index < numentries); index++)
1.120 + {
1.121 + entry = (*iPageText)[index];
1.122 + TPoint drawPos = entry->iDrawPos - TPoint(0, 16); // bodge to align pdr fonts with true types
1.123 + if(drawPos.iY == y)
1.124 + OutputTextL(drawPos, entry->iTextWidthInPixels, *(entry->iTextFormat), *(entry->iText));
1.125 + }
1.126 + }
1.127 + }
1.128 + }
1.129 + }
1.130 +
1.131 +void CCanonControl::MoveToL(const TPoint& aPoint)
1.132 + {
1.133 + TPoint vector = aPoint - iPosition;
1.134 + TInt maxNoOfYIncrements = 256 * 5 / 6; // Ensures no more than 256
1.135 + for(; vector.iY >= maxNoOfYIncrements; )
1.136 + {
1.137 + MoveByL(TPoint(0, maxNoOfYIncrements));
1.138 + vector = aPoint - iPosition;
1.139 + }
1.140 + MoveByL(vector);
1.141 + iPosition = aPoint;
1.142 + }
1.143 +
1.144 +void CCanonControl::MoveByL(const TPoint& aPoint)
1.145 + {
1.146 + TPoint vector = aPoint;
1.147 + if(vector.iX < 0)
1.148 + {
1.149 + CommandL(EPdrCarriageReturn);
1.150 + vector.iX += iPosition.iX - iPdrDevice->OffsetInPixels().iX;
1.151 + }
1.152 + vector.iX = vector.iX * 2 / 3; // X increments are in 120ths of an inch
1.153 + vector.iY = vector.iY * 6 / 5; // Y increments are in 216ths of an inch
1.154 + TPoint oldPosition = iPosition;
1.155 + CFbsDrvControl::MoveByL(vector);
1.156 + iPosition = oldPosition + aPoint; // Correct the position
1.157 + }
1.158 +
1.159 +TBool CCanonControl::TransformBuffer()
1.160 + {
1.161 + TUint8* pStart = (TUint8*)iScanLine.Ptr();
1.162 + TUint8* pEnd = pStart + (KCanonNumScanLinesPerBand >> 3);
1.163 + TUint8* p;
1.164 + for(p = pStart; (p < pEnd) && (*p == 0xFF); p++)
1.165 + {
1.166 + }
1.167 + TBool datainscanline = (p < pEnd);
1.168 + for(p = pStart; p < pEnd; p++)
1.169 + {
1.170 + TInt byte1 = *p;
1.171 + TInt byte2 = 0;
1.172 + for(TInt j = 0; j < 8; j++)
1.173 + {
1.174 + byte2 = byte2 << 1;
1.175 + byte2 = byte2 | (byte1 & 1);
1.176 + byte1 = byte1 >> 1;
1.177 + }
1.178 + *p = (TUint8)~byte2;
1.179 + }
1.180 + return datainscanline; // returns ETrue if there are non-blank bytes in scanline
1.181 + }
1.182 +
1.183 +CCanonControl::CCanonControl(CPdrDevice* aPdrDevice, CPrinterPort* aPrinterPort):
1.184 + CFbsDrvControl(aPdrDevice, aPrinterPort)
1.185 + {
1.186 + __DECLARE_NAME(_S("CCanonControl"));
1.187 + }
1.188 +