xref: /haiku/headers/libs/print/libprint/GraphicsDriver.h (revision b46615c55ad2c8fe6de54412055a0713da3d610a)
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 
18 class BView;
19 class BBitmap;
20 class BMessage;
21 class PrinterData;
22 class PrinterCap;
23 
24 
25 class GraphicsDriver {
26 public:
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 
39 protected:
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 	static	void	ConvertToRGB24(const void* src, void* dst, int width,
58 						color_space cs);
59 	static	void	ConvertToGray(const void* src, void* dst, int width,
60 						color_space cs);
61 
62 			const JobData*			GetJobData() const;
63 			const PrinterData*		GetPrinterData() const;
64 			const PrinterCap*		GetPrinterCap() const;
65 			const SpoolMetaData*	GetSpoolMetaData() const;
66 			int						GetProtocolClass() const;
67 
68 			int		GetPageHeight() const;
69 
70 private:
71 			bool	_SetupData(BFile* file);
72 			void	_SetupBitmap();
73 			void	_CleanupData();
74 			void	_CleanupBitmap();
75 			bool	_PrintPage(PageDataList* pages);
76 			bool	_PrintBand(BBitmap* band, BPoint* offset);
77 			void	_RotateInto(BBitmap* target, const BBitmap* source);
78 			bool	_CollectPages(SpoolData* spoolData, PageDataList* pages);
79 			bool	_SkipPages(SpoolData* spoolData);
80 			bool	_PrintDocument(SpoolData* spoolData);
81 			bool	_PrintJob(BFile* file);
82 
83 			bool	_NeedRotateBitmapBand() const;
84 
85 	static	void	_ConvertRGB32ToRGB24(const void* src, void* dst, int width);
86 	static	void	_ConvertCMAP8ToRGB24(const void* src, void* dst, int width);
87 	static	uint8	_ConvertToGray(uint8 r, uint8 g, uint8 b);
88 	static	void	_ConvertRGB32ToGray(const void* src, void* dst, int width);
89 	static	void	_ConvertCMAP8ToGray(const void* src, void* dst, int width);
90 
91 	BMessage*			fMessage;
92 	BView*				fView;
93 	BBitmap*			fBitmap;
94 	BBitmap*			fRotatedBitmap;
95 	Transport*			fTransport;
96 	JobData*			fOrgJobData;
97 	JobData*			fRealJobData;
98 	PrinterData*		fPrinterData;
99 	const PrinterCap*	fPrinterCap;
100 	SpoolMetaData*		fSpoolMetaData;
101 
102 	int	fPageWidth;
103 	int	fPageHeight;
104 	int	fBandWidth;
105 	int	fBandHeight;
106 	int	fPixelDepth;
107 	int	fBandCount;
108 	int	fInternalCopies;
109 
110 	uint32	fPageCount;
111 
112 	StatusWindow*	fStatusWindow;
113 };
114 
115 
116 inline const JobData*
117 GraphicsDriver::GetJobData() const
118 {
119 	return fRealJobData;
120 }
121 
122 
123 inline const PrinterData*
124 GraphicsDriver::GetPrinterData() const
125 {
126 	return fPrinterData;
127 }
128 
129 
130 inline const PrinterCap*
131 GraphicsDriver::GetPrinterCap() const
132 {
133 	return fPrinterCap;
134 }
135 
136 
137 inline const SpoolMetaData*
138 GraphicsDriver::GetSpoolMetaData() const
139 {
140 	return fSpoolMetaData;
141 }
142 
143 
144 inline int
145 GraphicsDriver::GetProtocolClass() const
146 {
147 	return fPrinterData->GetProtocolClass();
148 }
149 
150 
151 inline int
152 GraphicsDriver::GetPageHeight() const
153 {
154 	if (!_NeedRotateBitmapBand())
155 		return fPageHeight;
156 	return fPageWidth;
157 }
158 
159 #endif	/* __GRAPHICSDRIVER_H */
160