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