GraphicsDriver.h revision 89f1fd65
1/*
2 * GraphicsDriver.h
3 * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
4 */
5
6#ifndef	__GRAPHICSDRIVER_H
7#define	__GRAPHICSDRIVER_H
8
9
10#include "JobData.h"
11#include "PrinterData.h"
12#include "PrintProcess.h"
13#include "SpoolMetaData.h"
14#include "Transport.h"
15#include "StatusWindow.h"
16
17
18class BView;
19class BBitmap;
20class BMessage;
21class PrinterData;
22class PrinterCap;
23
24
25class GraphicsDriver {
26public:
27				GraphicsDriver(BMessage* message, PrinterData* printerData,
28					const PrinterCap *printerCap);
29	virtual		~GraphicsDriver();
30
31	const JobData*	GetJobData(BFile* spoolFile);
32	BMessage*		TakeJob(BFile* spoolFile);
33	static BPoint	GetScale(int32 nup, BRect physicalRect, float scaling);
34	static BPoint	GetOffset(int32 nup, int index,
35						JobData::Orientation orientation, const BPoint* scale,
36						BRect scaledPhysicalRect, BRect scaledPrintableRect,
37						BRect physicalRect);
38
39protected:
40					GraphicsDriver(const GraphicsDriver &);
41
42			GraphicsDriver&	operator = (const GraphicsDriver &);
43
44	virtual	bool	StartDocument();
45	virtual	bool	StartPage(int page_number);
46	virtual	bool	NextBand(BBitmap* bitmap, BPoint* offset);
47	virtual	bool	EndPage(int page_number);
48	virtual	bool	EndDocument(bool success);
49
50			void	WriteSpoolData(const void* buffer, size_t size)
51						/* throw (TransportException) */;
52			void	WriteSpoolString(const char* buffer, ...)
53						/* throw (TransportException) */;
54			void	WriteSpoolChar(char c)
55						/* throw (TransportException) */;
56
57			void	ReadSpoolData(void* buffer, size_t size)
58						/* throw (TransportException) */;
59			int		ReadSpoolChar()
60						/* throw (TransportException) */;
61
62	static	void	ConvertToRGB24(const void* src, void* dst, int width,
63						color_space cs);
64	static	void	ConvertToGray(const void* src, void* dst, int width,
65						color_space cs);
66
67			const JobData*			GetJobData() const;
68			const PrinterData*		GetPrinterData() const;
69			const PrinterCap*		GetPrinterCap() const;
70			const SpoolMetaData*	GetSpoolMetaData() const;
71			int						GetProtocolClass() const;
72
73			int		GetPageHeight() const;
74
75private:
76			bool	_SetupData(BFile* file);
77			void	_SetupBitmap();
78			void	_CleanupData();
79			void	_CleanupBitmap();
80			bool	_PrintPage(PageDataList* pages);
81			bool	_PrintBand(BBitmap* band, BPoint* offset);
82			void	_RotateInto(BBitmap* target, const BBitmap* source);
83			bool	_CollectPages(SpoolData* spoolData, PageDataList* pages);
84			bool	_SkipPages(SpoolData* spoolData);
85			bool	_PrintDocument(SpoolData* spoolData);
86			bool	_PrintJob(BFile* file);
87
88			bool	_NeedRotateBitmapBand() const;
89
90	static	void	_ConvertRGB32ToRGB24(const void* src, void* dst, int width);
91	static	void	_ConvertCMAP8ToRGB24(const void* src, void* dst, int width);
92	static	uint8	_ConvertToGray(uint8 r, uint8 g, uint8 b);
93	static	void	_ConvertRGB32ToGray(const void* src, void* dst, int width);
94	static	void	_ConvertCMAP8ToGray(const void* src, void* dst, int width);
95
96	BMessage*			fMessage;
97	BView*				fView;
98	BBitmap*			fBitmap;
99	BBitmap*			fRotatedBitmap;
100	Transport*			fTransport;
101	JobData*			fOrgJobData;
102	JobData*			fRealJobData;
103	PrinterData*		fPrinterData;
104	const PrinterCap*	fPrinterCap;
105	SpoolMetaData*		fSpoolMetaData;
106
107	int	fPageWidth;
108	int	fPageHeight;
109	int	fBandWidth;
110	int	fBandHeight;
111	int	fPixelDepth;
112	int	fBandCount;
113	int	fInternalCopies;
114
115	uint32	fPageCount;
116
117	StatusWindow*	fStatusWindow;
118};
119
120
121inline const JobData*
122GraphicsDriver::GetJobData() const
123{
124	return fRealJobData;
125}
126
127
128inline const PrinterData*
129GraphicsDriver::GetPrinterData() const
130{
131	return fPrinterData;
132}
133
134
135inline const PrinterCap*
136GraphicsDriver::GetPrinterCap() const
137{
138	return fPrinterCap;
139}
140
141
142inline const SpoolMetaData*
143GraphicsDriver::GetSpoolMetaData() const
144{
145	return fSpoolMetaData;
146}
147
148
149inline int
150GraphicsDriver::GetProtocolClass() const
151{
152	return fPrinterData->GetProtocolClass();
153}
154
155
156inline int
157GraphicsDriver::GetPageHeight() const
158{
159	if (!_NeedRotateBitmapBand())
160		return fPageHeight;
161	return fPageWidth;
162}
163
164#endif	/* __GRAPHICSDRIVER_H */
165