1 /* 2 * PrintProcess.cpp 3 * Copyright 1999-2000 Y.Takagi. All Rights Reserved. 4 */ 5 6 #include <File.h> 7 #include <Picture.h> 8 #include <unistd.h> 9 10 #include "PrintProcess.h" 11 #include "DbgMsg.h" 12 13 PictureData::PictureData(BFile *file) 14 { 15 DBGMSG(("construct PictureData\n")); 16 DBGMSG(("1: current seek position = 0x%x\n", (int)file->Position())); 17 18 file->Read(&point, sizeof(BPoint)); 19 file->Read(&rect, sizeof(BRect)); 20 21 picture = new BPicture(); 22 23 DBGMSG(("picture_data::point = %f, %f\n", point.x, point.y)); 24 DBGMSG(("picture_data::rect = %f, %f, %f, %f\n", 25 rect.left, rect.top, rect.right, rect.bottom)); 26 DBGMSG(("2: current seek position = 0x%x\n", (int)file->Position())); 27 28 picture->Unflatten(file); 29 30 DBGMSG(("3: current seek position = 0x%x\n", (int)file->Position())); 31 } 32 33 PictureData::~PictureData() 34 { 35 delete picture; 36 } 37 38 /*--------------------------------------------------*/ 39 40 PageData::PageData() 41 { 42 fHollow = true; 43 } 44 45 PageData::PageData(BFile *file, bool reverse) 46 { 47 fFile = file; 48 fReverse = reverse; 49 fPictureCount = 0; 50 fRest = 0; 51 fOffset = 0; 52 fHollow = false; 53 54 if (reverse) { 55 file->Read(&fPictureCount, sizeof(long)); 56 DBGMSG(("picture_count = %d\n", (int)fPictureCount)); 57 fOffset = fFile->Position(); 58 off_t o = fOffset; 59 // seek to start of next page 60 fFile->Read(&o, sizeof(o)); 61 fFile->Seek(o, SEEK_SET); 62 } 63 } 64 65 bool PageData::startEnum() 66 { 67 off_t offset; 68 uchar dummy[40]; 69 70 if (fHollow) 71 return false; 72 73 if (fOffset == 0) { 74 fFile->Read(&fPictureCount, sizeof(long)); 75 DBGMSG(("picture_count = %d\n", (int)fPictureCount)); 76 fOffset = fFile->Position(); 77 } else { 78 fFile->Seek(fOffset, SEEK_SET); 79 } 80 // skip page header 81 fFile->Seek(sizeof(offset) + sizeof(dummy), SEEK_CUR); 82 83 fRest = fPictureCount; 84 return fPictureCount > 0; 85 } 86 87 bool PageData::enumObject(PictureData **picture_data) 88 { 89 if (fHollow || fPictureCount <= 0) { 90 *picture_data = NULL; 91 } else { 92 *picture_data = new PictureData(fFile); 93 if (--fRest > 0) { 94 return true; 95 } 96 } 97 return false; 98 } 99 100 /*--------------------------------------------------*/ 101 102 SpoolData::SpoolData( 103 BFile *file, 104 int page_count, 105 int nup, 106 bool reverse) 107 { 108 DBGMSG(("nup = %d\n", nup)); 109 DBGMSG(("page_count = %d\n", page_count)); 110 DBGMSG(("reverse = %s\n", reverse ? "true" : "false")); 111 112 if (reverse) { 113 if (nup > 1) { 114 for (int page_index = 0; page_index < page_count; page_index++) { 115 if (page_index % nup == 0) { 116 fPages.push_front(new PageData(file, reverse)); 117 fIt = fPages.begin(); 118 fIt++; 119 } else { 120 fPages.insert(fIt, new PageData(file, reverse)); 121 } 122 } 123 page_count = nup - page_count % nup; 124 if (page_count < nup) { 125 while (page_count--) { 126 fPages.insert(fIt, new PageData); 127 } 128 } 129 } else { 130 while (page_count--) { 131 fPages.push_front(new PageData(file, reverse)); 132 } 133 } 134 } else { 135 while (page_count--) { 136 fPages.push_back(new PageData(file, reverse)); 137 } 138 } 139 } 140 141 SpoolData::~SpoolData() 142 { 143 for (fIt = fPages.begin(); fIt != fPages.end(); fIt++) { 144 delete (*fIt); 145 } 146 } 147 148 bool SpoolData::startEnum() 149 { 150 fIt = fPages.begin(); 151 return true; 152 } 153 154 bool SpoolData::enumObject(PageData **page_data) 155 { 156 *page_data = *fIt++; 157 if (fIt == fPages.end()) { 158 return false; 159 } 160 return true; 161 } 162