xref: /haiku/headers/libs/print/libprint/PrintJobReader.h (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
1 /*
2 
3 PrintJobReader
4 
5 Copyright (c) 2002 OpenBeOS.
6 
7 Author:
8 	Michael Pfeiffer
9 
10 Permission is hereby granted, free of charge, to any person obtaining a copy of
11 this software and associated documentation files (the "Software"), to deal in
12 the Software without restriction, including without limitation the rights to
13 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14 of the Software, and to permit persons to whom the Software is furnished to do
15 so, subject to the following conditions:
16 
17 The above copyright notice and this permission notice shall be included in all
18 copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 THE SOFTWARE.
27 
28 */
29 
30 #ifndef _PRINT_JOB_READER_H
31 #define _PRINT_JOB_READER_H
32 
33 #include <File.h>
34 #include <Message.h>
35 #include <Picture.h>
36 
37 class PrintJobPage {
38 	BFile fJobFile; // the job file
39 	off_t fNextPicture; // offset to first picture
40 	int32 fNumberOfPictures; // of this page
41 	int32 fPicture; // the picture returned by NextPicture()
42 	status_t fStatus;
43 
44 public:
45 	PrintJobPage();
46 	PrintJobPage(const PrintJobPage& copy);
47 	PrintJobPage(BFile* jobFile, off_t start);
48 	status_t InitCheck() const;
49 
50 	int32 NumberOfPictures() const { return fNumberOfPictures; }
51 
52 	status_t NextPicture(BPicture& picture, BPoint& p, BRect& r);
53 
54 	PrintJobPage& operator=(const PrintJobPage& copy);
55 };
56 
57 class PrintJobReader {
58 	BFile fJobFile;  // the job file
59 	int32 fNumberOfPages; // the number of pages in the job file
60 	BMessage fJobSettings; // the settings extracted from the job file
61 	off_t* fPageIndex; // start positions of pages in the job file
62 
63 	void BuildPageIndex();
64 
65 public:
66 	PrintJobReader(BFile* jobFile);
67 	virtual ~PrintJobReader();
68 
69 		// test after construction if this is a valid job file
70 	status_t InitCheck() const;
71 
72 		// accessors to informations from job file
73 	int32 NumberOfPages() const { return fNumberOfPages; }
74 	int32 FirstPage() const;
75 	int32 LastPage() const;
76 	const BMessage* JobSettings() const { return &fJobSettings; }
77 	BRect PaperRect() const;
78 	BRect PrintableRect() const;
79 	void GetResolution(int32 *xdpi, int32 *ydpi) const;
80 	float GetScale() const;
81 
82 		// retrieve page
83 	status_t GetPage(int32 no, PrintJobPage& pjp);
84 };
85 
86 #endif
87 
88