sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "PCL5STD.H" sl@0: sl@0: #include sl@0: #include sl@0: #include "PCL5.H" sl@0: #include "pdrtext.h" sl@0: sl@0: sl@0: EXPORT_C CPrinterDevice* NewPrinterDeviceL() sl@0: { sl@0: CPcl5Device* device = new(ELeave) CPcl5Device; sl@0: return device; sl@0: } sl@0: sl@0: CPcl5Device::CPcl5Device() sl@0: : CFbsDrvDevice() sl@0: { sl@0: __DECLARE_NAME(_S("CPcl5Device")); sl@0: } sl@0: sl@0: CPcl5Device::~CPcl5Device() sl@0: { sl@0: } sl@0: sl@0: TInt CPcl5Device::CreateContext(CGraphicsContext*& aGC) sl@0: { sl@0: __ASSERT_DEBUG(iControl,Panic(EPcl5ControlDoesNotExist)); sl@0: CPdrControl* control=(CPdrControl*) iControl; sl@0: return control->CreateContext(aGC); sl@0: } sl@0: sl@0: void CPcl5Device::CreateControlL(CPrinterPort* aPrinterPort) sl@0: { sl@0: __ASSERT_ALWAYS(aPrinterPort, Panic(EPcl5RequiresPrinterPort)); sl@0: __ASSERT_ALWAYS(!iControl, Panic(EPcl5ControlAlreadyExists)); sl@0: __ASSERT_DEBUG(iCurrentPageSpecInTwips.iPortraitPageSize.iWidth && iCurrentPageSpecInTwips.iPortraitPageSize.iHeight, Panic(EPcl5PageSpecNotSet)); sl@0: iControl = CPcl5Control::NewL(this, aPrinterPort, *iStore, iModelInfo->iResourcesStreamId); sl@0: } sl@0: sl@0: CPcl5Control* CPcl5Control::NewL(CPdrDevice* aPdrDevice, CPrinterPort* aPrinterPort, CStreamStore& aStore, TStreamId aResourcesStreamId) sl@0: { sl@0: CPcl5Control* control = new(ELeave) CPcl5Control(aPdrDevice, aPrinterPort); sl@0: CleanupStack::PushL(control); sl@0: control->ConstructL(aStore, aResourcesStreamId); sl@0: CleanupStack::Pop(); sl@0: return control; sl@0: } sl@0: sl@0: CPcl5Control::~CPcl5Control() sl@0: { sl@0: } sl@0: sl@0: CPcl5Control::CPcl5Control(CPdrDevice* aPdrDevice, CPrinterPort* aPrinterPort) sl@0: : CFbsDrvControl(aPdrDevice, aPrinterPort) sl@0: { sl@0: __DECLARE_NAME(_S("CPcl5Control")); sl@0: } sl@0: sl@0: CPrinterControl::TMoreOnPage CPcl5Control::QueueGetBand(TRequestStatus& aStatus, TBandAttributes& aBand) sl@0: { sl@0: TMoreOnPage moreonpage = ENoMoreOnPage; sl@0: TRAPD(ret, DoQueueGetBandL()); sl@0: if (ret != KErrNone) sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, ret); sl@0: } sl@0: else sl@0: { sl@0: if (IsGraphicsBand()) sl@0: { sl@0: aBand.iRect = iBandedDevice->BandRect(); sl@0: aBand.iTextIsIgnored = ETrue; sl@0: aBand.iGraphicsIsIgnored = EFalse; sl@0: aBand.iFirstBandOnPage = EFalse; sl@0: } sl@0: else sl@0: { sl@0: aBand.iRect = iPdrDevice->PrintablePageInPixels(); sl@0: aBand.iTextIsIgnored = EFalse; sl@0: aBand.iGraphicsIsIgnored = ETrue; sl@0: aBand.iFirstBandOnPage = ETrue; sl@0: } sl@0: if (iBandIndex == (BandsPerPage() - 1)) sl@0: { sl@0: moreonpage = ENoMoreOnPage; sl@0: if (!(iPdrDevice->Flags() & EPcl5DeskjetPrinter)) sl@0: { sl@0: CPageTextEntry* entry; //!! sl@0: TInt numentries = iPageText->NumEntries(); sl@0: for (; (iEntryIndex < numentries); iEntryIndex++) //!! sl@0: { sl@0: entry = (*iPageText)[iEntryIndex]; sl@0: OutputTextL(entry->iDrawPos, entry->iTextWidthInPixels, *(entry->iTextFormat), *(entry->iText)); //!! sl@0: } sl@0: } sl@0: } sl@0: else sl@0: moreonpage = EMoreOnPage; sl@0: iPageBuffer->StartFlush(aStatus); sl@0: } sl@0: return moreonpage; sl@0: } sl@0: sl@0: void CPcl5Control::ConstructL(CStreamStore& aStore, TStreamId aResourcesStreamId) sl@0: { sl@0: if ((iPdrDevice->CurrentPageSpecInTwips().iOrientation == TPageSpec::ELandscape) sl@0: && (iPdrDevice->Flags() & EPcl5LandscapeNotAvailable)) sl@0: User::Leave(KErrNotSupported); sl@0: CFbsDrvControl::ConstructL(aStore, aResourcesStreamId); sl@0: sl@0: TRect rect = iPdrDevice->PrintablePageInPixels(); sl@0: iLandscapeMode = ((iPdrDevice->CurrentPageSpecInTwips().iOrientation == TPageSpec::ELandscape) sl@0: && !(iPdrDevice->Flags() & EPcl5LandscapeNotAvailable)); sl@0: TBandingDirection bandorientation = sl@0: { sl@0: (iLandscapeMode && (iPdrDevice->Flags() & EPcl5LandscapeBandingRightToLeft)) ? sl@0: EBandingRightToLeft : sl@0: EBandingTopToBottom sl@0: }; sl@0: TSize size; sl@0: size.iWidth = iPdrDevice->HorizontalPixelsToTwips(1000); sl@0: size.iHeight = iPdrDevice->VerticalPixelsToTwips(1000); sl@0: iBandedDevice = CBandedDevice::NewL(rect, size, iPdrDevice->DisplayMode(), bandorientation); sl@0: TInt len = sl@0: { sl@0: (bandorientation == EBandingTopToBottom) ? sl@0: CFbsBitmap::ScanLineLength(iBandedDevice->BandBitmap()->SizeInPixels().iWidth, iPdrDevice->DisplayMode()) : sl@0: CFbsBitmap::ScanLineLength(iBandedDevice->BandBitmap()->SizeInPixels().iHeight, iPdrDevice->DisplayMode()) sl@0: }; sl@0: iScanLine = HBufC8::NewL(len); sl@0: iCompressedScanLine = HBufC8::NewL(len); sl@0: if (!iLandscapeMode || !(iPdrDevice->Flags() & EPcl5DeskjetPrinter)) sl@0: iPageText = CPageText::NewL(); sl@0: } sl@0: sl@0: void CPcl5Control::OutputBandL() sl@0: { sl@0: if (IsGraphicsBand()) sl@0: { sl@0: TRect bandrect = iBandedDevice->BandRect(); sl@0: TSize size = bandrect.Size(); sl@0: TCommandString des; sl@0: TBool datainband = EFalse; sl@0: TInt numscanlines = size.iHeight; sl@0: if (iBandedDevice->BandingDirection() == EBandingRightToLeft) sl@0: numscanlines = size.iWidth; sl@0: for (TInt i = 0; i < numscanlines; i++) sl@0: { sl@0: TInt x = bandrect.iTl.iX; sl@0: TInt y = bandrect.iTl.iY + i; sl@0: TPtr8 ptr = iScanLine->Des(); sl@0: if (iBandedDevice->BandingDirection() == EBandingTopToBottom) sl@0: iBandedDevice->BandBitmap()->GetScanLine(ptr, TPoint(0, i), size.iWidth, iPdrDevice->DisplayMode()); sl@0: else sl@0: { sl@0: iBandedDevice->BandBitmap()->GetVerticalScanLine(ptr, numscanlines - (i + 1), iPdrDevice->DisplayMode()); sl@0: x = bandrect.iBr.iX - i; sl@0: y = bandrect.iTl.iY; sl@0: } sl@0: if ((iPdrDevice->Flags() & EPcl5DeskjetPrinter) && !iLandscapeMode) sl@0: { sl@0: CPageTextEntry* entry; sl@0: TBool textinscanline=EFalse; sl@0: TInt numentries=iPageText->NumEntries(); sl@0: for (; (iEntryIndex < numentries) && ((entry = (*iPageText)[iEntryIndex])->iDrawPos.iY <= (y + iPageText->MaxFontHeightInPixels())); iEntryIndex++) sl@0: { sl@0: OutputTextL(entry->iDrawPos, entry->iTextWidthInPixels, *(entry->iTextFormat), *(entry->iText)); sl@0: textinscanline = ETrue; sl@0: } sl@0: if (textinscanline && datainband) sl@0: MoveToL(TPoint(x, y)); sl@0: } sl@0: if (TransformBuffer() && !datainband) sl@0: { sl@0: MoveToL(TPoint(x, y)); sl@0: if (iBandedDevice->BandingDirection() == EBandingLeftToRight) sl@0: des.Format(iResources->ResourceString(EPdrBitmapStart), EPcl5PhysicalPageOrientation); sl@0: else sl@0: des.Format(iResources->ResourceString(EPdrBitmapStart), EPcl5LogicalPageOrientation); sl@0: iPageBuffer->AddBytesL(des); sl@0: datainband = ETrue; sl@0: } sl@0: if (datainband) sl@0: { sl@0: TCommandString buf = iResources->ResourceString(EPdrScanLine); sl@0: if (CompressBuffer()) sl@0: { sl@0: des.Format(buf, EPcl5RunLength, iCompressedScanLine->Des().Length()); sl@0: iPageBuffer->AddBytesL(des); sl@0: iPageBuffer->AddBytesL(iCompressedScanLine->Des()); sl@0: } sl@0: else sl@0: { sl@0: des.Format(buf, EPcl5None, iScanLine->Des().Length()); sl@0: iPageBuffer->AddBytesL(des); sl@0: iPageBuffer->AddBytesL(iScanLine->Des()); sl@0: } sl@0: } sl@0: } sl@0: if (datainband) sl@0: iPageBuffer->AddBytesL(iResources->ResourceString(EPdrBitmapEnd)); sl@0: } sl@0: } sl@0: sl@0: void CPcl5Control::SetPageSizeL() sl@0: { sl@0: TCommandString des; // Need more paper sizes sl@0: TSize size = iPdrDevice->CurrentPageSpecInTwips().iPortraitPageSize; sl@0: if (size == KA4PaperSizeInTwips) sl@0: des.Format(iResources->ResourceString(EPdrSetPageSize), EPcl5A4); sl@0: else if (size == KLegalPaperSizeInTwips) sl@0: des.Format(iResources->ResourceString(EPdrSetPageSize), EPcl5Legal); sl@0: else if (size == KExecutivePaperSizeInTwips) sl@0: des.Format(iResources->ResourceString(EPdrSetPageSize), EPcl5Executive); sl@0: else if (size == KLetterPaperSizeInTwips) sl@0: des.Format(iResources->ResourceString(EPdrSetPageSize), EPcl5Letter); sl@0: else if (size == KCom_10PaperSizeInTwips) sl@0: des.Format(iResources->ResourceString(EPdrSetPageSize), EPcl5Com_10); sl@0: else if (size == KMonarchPaperSizeInTwips) sl@0: des.Format(iResources->ResourceString(EPdrSetPageSize), EPcl5Monarch); sl@0: else if (size == KDLPaperSizeInTwips) sl@0: des.Format(iResources->ResourceString(EPdrSetPageSize), EPcl5DL); sl@0: else if (size == KC5PaperSizeInTwips) sl@0: des.Format(iResources->ResourceString(EPdrSetPageSize), EPcl5C5); sl@0: iPageBuffer->AddBytesL(des); sl@0: } sl@0: sl@0: void CPcl5Control::SetPageOrientationL() sl@0: { sl@0: if (iLandscapeMode) sl@0: CommandL(EPdrLandscape); sl@0: else sl@0: CommandL(EPdrPortrait); sl@0: } sl@0: sl@0: void CPcl5Control::SetTextColorL(const TRgb& aColor) sl@0: { sl@0: TCommandString des; sl@0: TInt color = aColor.Gray2(); sl@0: if (iPdrDevice->Flags() & EPcl5DeskjetPrinter) sl@0: color = !color; sl@0: des.Format(iResources->ResourceString(EPdrSetTextColor), color); sl@0: iPageBuffer->AddBytesL(des); sl@0: }