printingservices/printerdrivers/epson/EPSON.CPP
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     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 
       
    17 #include "EPSNSTD.H"
       
    18 
       
    19 #include <banddev.h>
       
    20 #include <fbs.h>
       
    21 #include "EPSON.H"
       
    22 #include "pdrtext.h"
       
    23 
       
    24 
       
    25 
       
    26 EXPORT_C CPrinterDevice* NewPrinterDeviceL()
       
    27 	{
       
    28 	CEpsonDevice* device = new(ELeave) CEpsonDevice;
       
    29 	return device;
       
    30 	}
       
    31 
       
    32 CEpsonDevice::CEpsonDevice():
       
    33 	CFbsDrvDevice()
       
    34 	{
       
    35 	__DECLARE_NAME(_S("CEpsonDevice"));
       
    36 	}
       
    37 
       
    38 CEpsonDevice::~CEpsonDevice()
       
    39 	{
       
    40 	}
       
    41 
       
    42 void CEpsonDevice::CreateControlL(CPrinterPort* aPrinterPort)
       
    43 	{
       
    44 	__ASSERT_ALWAYS(aPrinterPort, Panic(EEpsonRequiresPrinterPort));
       
    45 	__ASSERT_ALWAYS(!iControl, Panic(EEpsonControlAlreadyExists));
       
    46 	__ASSERT_DEBUG(iCurrentPageSpecInTwips.iPortraitPageSize.iWidth && iCurrentPageSpecInTwips.iPortraitPageSize.iHeight, Panic(EEpsonPageSpecNotSet));
       
    47 	iControl = CEpsonControl::NewL(this, aPrinterPort, *iStore, iModelInfo->iResourcesStreamId);
       
    48 	}
       
    49 
       
    50 CEpsonControl* CEpsonControl::NewL(CPdrDevice* aPdrDevice, CPrinterPort* aPrinterPort, CStreamStore& aStore, TStreamId aResourcesStreamId)
       
    51 	{
       
    52 	CEpsonControl* control=new(ELeave) CEpsonControl(aPdrDevice, aPrinterPort);
       
    53 	CleanupStack::PushL(control);
       
    54 	control->ConstructL(aStore, aResourcesStreamId);
       
    55 	CleanupStack::Pop();
       
    56 	return control;
       
    57 	}
       
    58 
       
    59 CEpsonControl::~CEpsonControl()
       
    60 	{
       
    61 	}
       
    62 
       
    63 void CEpsonControl::ConstructL(CStreamStore& aStore, TStreamId aResourcesStreamId)
       
    64 	{
       
    65 	if((iPdrDevice->CurrentPageSpecInTwips().iOrientation == TPageSpec::ELandscape)
       
    66 		&& (iPdrDevice->Flags() & EEpsonLandscapeNotAvailable))
       
    67 		User::Leave(KErrNotSupported);
       
    68 	CFbsDrvControl::ConstructL(aStore, aResourcesStreamId);
       
    69 	TRect rect = iPdrDevice->PrintablePageInPixels();
       
    70 	TSize size;
       
    71 	size.iWidth = iPdrDevice->HorizontalPixelsToTwips(1000);
       
    72 	size.iHeight = iPdrDevice->VerticalPixelsToTwips(1000);
       
    73 	iBandedDevice = CBandedDevice::NewL(rect, size, iPdrDevice->DisplayMode(), EBandingTopToBottom, KEpsonNumScanLinesPerBand);
       
    74 	iPageText = CPageText::NewL();
       
    75 	}
       
    76 
       
    77 void CEpsonControl::OutputBandL() 	
       
    78 	{
       
    79 	if(IsGraphicsBand())
       
    80 		{
       
    81 		TRect bandrect = iBandedDevice->BandRect();
       
    82 		TSize size = bandrect.Size();
       
    83 		TCommandString des;
       
    84 		TBool datainband = EFalse;
       
    85 		for(TInt i = 0; i < size.iWidth; i++)
       
    86 			{
       
    87 			iBandedDevice->BandBitmap()->GetVerticalScanLine(iScanLine, i, iPdrDevice->DisplayMode());
       
    88 			if(TransformBuffer() && !datainband)
       
    89 				{
       
    90 				MoveToL(bandrect.iTl + TPoint(i, 0));
       
    91 				des.Format(iResources->ResourceString(EPdrBitmapStart), size.iWidth - i);
       
    92 				iPageBuffer->AddBytesL(des);
       
    93 				datainband = ETrue;
       
    94 				}
       
    95 			if(datainband)
       
    96 				iPageBuffer->AddBytesL(iScanLine);
       
    97 			}
       
    98 		if(datainband)
       
    99 			{
       
   100 			iPageBuffer->AddBytesL(iResources->ResourceString(EPdrBitmapEnd));
       
   101 			iPosition.iX = iPdrDevice->OffsetInPixels().iX;
       
   102 			}
       
   103 		
       
   104 		TInt numentries = iPageText->NumEntries();
       
   105 		if(numentries)
       
   106 			{
       
   107 			CPageTextEntry* entry;
       
   108 			for(TInt y = bandrect.iTl.iY; y <= bandrect.iBr.iY; y++)
       
   109 				{
       
   110 				for(TInt index = 0; (index < numentries); index++)
       
   111 					{
       
   112 					entry = (*iPageText)[index];
       
   113 					TPoint drawPos = entry->iDrawPos - TPoint(0, 20);	// bodge to align pdr fonts with true types
       
   114 					if(drawPos.iY == y)
       
   115 						OutputTextL(drawPos, entry->iTextWidthInPixels, *(entry->iTextFormat), *(entry->iText));										 //!!
       
   116 					}
       
   117 				}
       
   118 			}
       
   119 		}
       
   120 	}
       
   121 
       
   122 void CEpsonControl::MoveToL(const TPoint& aPoint) 
       
   123 	{
       
   124 	TPoint vector = aPoint - iPosition;
       
   125 	for(; vector.iY > 255; )
       
   126 		{
       
   127 		MoveByL(TPoint(0, 255));
       
   128 		vector = aPoint - iPosition;
       
   129 		}
       
   130 	MoveByL(vector);		
       
   131 	}
       
   132 
       
   133 TBool CEpsonControl::TransformBuffer()
       
   134 	{
       
   135 	TUint8* pStart = (TUint8*)iScanLine.Ptr();
       
   136 	TUint8* pEnd = pStart + (KEpsonNumScanLinesPerBand >> 3);
       
   137 	TUint8* p;
       
   138 	for(p = pStart; (p < pEnd) && (*p == 0xFF); p++)
       
   139 		{
       
   140 		}
       
   141 	TBool datainscanline = (p < pEnd);
       
   142 	for(p = pStart; p<pEnd; p++)
       
   143 		{
       
   144 		TInt byte1 = *p;
       
   145 		TInt byte2 = 0;
       
   146 		for(TInt j = 0; j < 8; j++)
       
   147 			{
       
   148 			byte2 = byte2 << 1;
       
   149 			byte2 = byte2 | (byte1 & 1);
       
   150 			byte1 = byte1 >> 1;
       
   151 			}
       
   152 		*p = (TUint8)~byte2; 
       
   153 		}
       
   154 	return datainscanline;	// returns ETrue if there are non-blank bytes in scanline
       
   155 	}
       
   156 
       
   157 CEpsonControl::CEpsonControl(CPdrDevice* aPdrDevice, CPrinterPort* aPrinterPort):
       
   158 	CFbsDrvControl(aPdrDevice, aPrinterPort),
       
   159 	iScanLine()
       
   160 	{
       
   161 	__DECLARE_NAME(_S("CEpsonControl"));
       
   162 	}
       
   163