150 | | while 1 : |
151 | | if hasirmarker and (minfile[pos:pos+2] == irmarker) : |
152 | | codop = minfile[pos+2:pos+4] |
153 | | # self.logdebug("Marker at 0x%08x (%s)" % (pos, wasirmarker)) |
154 | | length = unpack(">H", minfile[pos+8:pos+10])[0] |
155 | | pos += 20 |
156 | | if codop != irmarker2 : |
157 | | pos += length |
158 | | wasirmarker = 1 |
159 | | else : |
160 | | wasirmarker = 0 |
161 | | char = minfile[pos] ; pos += 1 |
162 | | if char == "\014" : |
163 | | pagecount += 1 |
164 | | elif char == "\033" : |
165 | | starb = ampl = 0 |
166 | | if minfile[pos : pos+8] == r"%-12345X" : |
167 | | endpos = pos + 9 |
168 | | quotes = 0 |
169 | | while (minfile[endpos] not in endmark) and \ |
170 | | ((minfile[endpos] < asciilimit) or (quotes % 2)) : |
171 | | if minfile[endpos] == '"' : |
172 | | quotes += 1 |
173 | | endpos += 1 |
174 | | self.setPageDict(pages, pagecount, "escaped", minfile[pos : endpos]) |
175 | | pos += (endpos - pos) |
176 | | else : |
177 | | # |
178 | | # <ESC>*b###y#m###v###w... -> PCL3 raster graphics |
179 | | # <ESC>*b###W -> Start of a raster data row/block |
180 | | # <ESC>*b###V -> Start of a raster data plane |
181 | | # <ESC>*c###W -> Start of a user defined pattern |
182 | | # <ESC>*i###W -> Start of a viewing illuminant block |
183 | | # <ESC>*l###W -> Start of a color lookup table |
184 | | # <ESC>*m###W -> Start of a download dither matrix block |
185 | | # <ESC>*v###W -> Start of a configure image data block |
186 | | # <ESC>*r1A -> Start Gfx |
187 | | # <ESC>(s###W -> Start of a characters description block |
188 | | # <ESC>)s###W -> Start of a fonts description block |
189 | | # <ESC>(f###W -> Start of a symbol set block |
190 | | # <ESC>&b###W -> Start of configuration data block |
191 | | # <ESC>&l###X -> Number of copies for current page |
192 | | # <ESC>&n###W -> Starts an alphanumeric string ID block |
193 | | # <ESC>&p###X -> Start of a non printable characters block |
194 | | # <ESC>&a2G -> Back side when duplex mode as generated by rastertohp |
195 | | # <ESC>*g###W -> Needed for planes in PCL3 output |
196 | | # <ESC>&l###H (or only 0 ?) -> Eject if NumPlanes > 1, as generated by rastertohp. Also defines mediasource |
197 | | # <ESC>&l###A -> mediasize |
198 | | # <ESC>&l###O -> orientation |
199 | | # <ESC>&l###M -> mediatype |
200 | | # <ESC>*t###R -> gfx resolution |
201 | | # |
202 | | tagstart = minfile[pos] ; pos += 1 |
203 | | if tagstart in "E9=YZ" : # one byte PCL tag |
204 | | if tagstart == "E" : |
205 | | resets += 1 |
206 | | continue # skip to next tag |
207 | | tag = tagstart + minfile[pos] ; pos += 1 |
208 | | if tag == "*b" : |
209 | | starb = 1 |
210 | | tagend = "VW" |
211 | | elif tag == "&l" : |
212 | | ampl = 1 |
213 | | tagend = "XHAOM" |
214 | | else : |
215 | | try : |
216 | | tagend = tagsends[tag] |
217 | | except KeyError : |
218 | | continue # Unsupported PCL tag |
219 | | # Now read the numeric argument |
220 | | size = 0 |
221 | | while 1 : |
222 | | char = minfile[pos] ; pos += 1 |
223 | | if not char.isdigit() : |
224 | | break |
225 | | size = (size * 10) + int(char) |
226 | | if char in tagend : |
227 | | if tag == "&l" : |
228 | | if char == "X" : |
229 | | self.setPageDict(pages, pagecount, "copies", size) |
230 | | elif char == "H" : |
| 150 | try : |
| 151 | while 1 : |
| 152 | if hasirmarker and (minfile[pos:pos+2] == irmarker) : |
| 153 | codop = minfile[pos+2:pos+4] |
| 154 | # self.logdebug("Marker at 0x%08x (%s)" % (pos, wasirmarker)) |
| 155 | length = unpack(">H", minfile[pos+8:pos+10])[0] |
| 156 | pos += 20 |
| 157 | if codop != irmarker2 : |
| 158 | pos += length |
| 159 | wasirmarker = 1 |
| 160 | else : |
| 161 | wasirmarker = 0 |
| 162 | char = minfile[pos] ; pos += 1 |
| 163 | if char == "\014" : |
| 164 | pagecount += 1 |
| 165 | elif char == "\033" : |
| 166 | starb = ampl = 0 |
| 167 | if minfile[pos : pos+8] == r"%-12345X" : |
| 168 | endpos = pos + 9 |
| 169 | quotes = 0 |
| 170 | while (minfile[endpos] not in endmark) and \ |
| 171 | ((minfile[endpos] < asciilimit) or (quotes % 2)) : |
| 172 | if minfile[endpos] == '"' : |
| 173 | quotes += 1 |
| 174 | endpos += 1 |
| 175 | self.setPageDict(pages, pagecount, "escaped", minfile[pos : endpos]) |
| 176 | pos += (endpos - pos) |
| 177 | else : |
| 178 | # |
| 179 | # <ESC>*b###y#m###v###w... -> PCL3 raster graphics |
| 180 | # <ESC>*b###W -> Start of a raster data row/block |
| 181 | # <ESC>*b###V -> Start of a raster data plane |
| 182 | # <ESC>*c###W -> Start of a user defined pattern |
| 183 | # <ESC>*i###W -> Start of a viewing illuminant block |
| 184 | # <ESC>*l###W -> Start of a color lookup table |
| 185 | # <ESC>*m###W -> Start of a download dither matrix block |
| 186 | # <ESC>*v###W -> Start of a configure image data block |
| 187 | # <ESC>*r1A -> Start Gfx |
| 188 | # <ESC>(s###W -> Start of a characters description block |
| 189 | # <ESC>)s###W -> Start of a fonts description block |
| 190 | # <ESC>(f###W -> Start of a symbol set block |
| 191 | # <ESC>&b###W -> Start of configuration data block |
| 192 | # <ESC>&l###X -> Number of copies for current page |
| 193 | # <ESC>&n###W -> Starts an alphanumeric string ID block |
| 194 | # <ESC>&p###X -> Start of a non printable characters block |
| 195 | # <ESC>&a2G -> Back side when duplex mode as generated by rastertohp |
| 196 | # <ESC>*g###W -> Needed for planes in PCL3 output |
| 197 | # <ESC>&l###H (or only 0 ?) -> Eject if NumPlanes > 1, as generated by rastertohp. Also defines mediasource |
| 198 | # <ESC>&l###A -> mediasize |
| 199 | # <ESC>&l###O -> orientation |
| 200 | # <ESC>&l###M -> mediatype |
| 201 | # <ESC>*t###R -> gfx resolution |
| 202 | # |
| 203 | tagstart = minfile[pos] ; pos += 1 |
| 204 | if tagstart in "E9=YZ" : # one byte PCL tag |
| 205 | if tagstart == "E" : |
| 206 | resets += 1 |
| 207 | continue # skip to next tag |
| 208 | tag = tagstart + minfile[pos] ; pos += 1 |
| 209 | if tag == "*b" : |
| 210 | starb = 1 |
| 211 | tagend = "VW" |
| 212 | elif tag == "&l" : |
| 213 | ampl = 1 |
| 214 | tagend = "XHAOM" |
| 215 | else : |
| 216 | try : |
| 217 | tagend = tagsends[tag] |
| 218 | except KeyError : |
| 219 | continue # Unsupported PCL tag |
| 220 | # Now read the numeric argument |
| 221 | size = 0 |
| 222 | while 1 : |
| 223 | char = minfile[pos] ; pos += 1 |
| 224 | if not char.isdigit() : |
| 225 | break |
| 226 | size = (size * 10) + int(char) |
| 227 | if char in tagend : |
| 228 | if tag == "&l" : |
| 229 | if char == "X" : |
| 230 | self.setPageDict(pages, pagecount, "copies", size) |
| 231 | elif char == "H" : |
| 232 | self.setPageDict(pages, pagecount, "mediasource", self.mediasources.get(size, str(size))) |
| 233 | mediasourcecount += 1 |
| 234 | ejects += 1 |
| 235 | elif char == "A" : |
| 236 | self.setPageDict(pages, pagecount, "mediasize", self.mediasizes.get(size, str(size))) |
| 237 | mediasizecount += 1 |
| 238 | elif char == "O" : |
| 239 | self.setPageDict(pages, pagecount, "orientation", self.orientations.get(size, str(size))) |
| 240 | orientationcount += 1 |
| 241 | elif char == "M" : |
| 242 | self.setPageDict(pages, pagecount, "mediatype", self.mediatypes.get(size, str(size))) |
| 243 | mediatypecount += 1 |
| 244 | elif tag == "*r" : |
| 245 | # Special tests for PCL3 |
| 246 | if (char == "s") and size : |
| 247 | while 1 : |
| 248 | char = minfile[pos] ; pos += 1 |
| 249 | if char == "A" : |
| 250 | break |
| 251 | elif (char == "b") and (minfile[pos] == "C") and not size : |
| 252 | ispcl3 = 1 # Certainely a PCL3 file |
| 253 | startgfx += (char == "A") and (minfile[pos - 2] in ("0", "1", "2", "3")) # Start Gfx |
| 254 | endgfx += (not size) and (char in ("C", "B")) # End Gfx |
| 255 | elif tag == "*t" : |
| 256 | escstart += 1 |
| 257 | elif (tag == "&a") and (size == 2) : |
| 258 | # We are on the backside, so mark current page as duplex |
| 259 | self.setPageDict(pages, pagecount, "duplex", 1) |
| 260 | backsides += 1 # Back side in duplex mode |
| 261 | else : |
| 262 | # we just ignore the block. |
| 263 | if tag == "&n" : |
| 264 | # we have to take care of the operation id byte |
| 265 | # which is before the string itself |
| 266 | size += 1 |
| 267 | pos += size |
| 268 | else : |
| 269 | if starb : |
| 270 | # special handling of PCL3 in which |
| 271 | # *b introduces combined ESCape sequences |
| 272 | size = 0 |
| 273 | while 1 : |
| 274 | char = minfile[pos] ; pos += 1 |
| 275 | if not char.isdigit() : |
| 276 | break |
| 277 | size = (size * 10) + int(char) |
| 278 | if char in ("w", "v") : |
| 279 | ispcl3 = 1 # certainely a PCL3 document |
| 280 | pos += size - 1 |
| 281 | elif char in ("y", "m") : |
| 282 | ispcl3 = 1 # certainely a PCL3 document |
| 283 | pos -= 1 # fix position : we were ahead |
| 284 | elif ampl : |
| 285 | # special handling of PCL3 in which |
| 286 | # &l introduces combined ESCape sequences |
| 287 | size = 0 |
| 288 | while 1 : |
| 289 | char = minfile[pos] ; pos += 1 |
| 290 | if not char.isdigit() : |
| 291 | break |
| 292 | size = (size * 10) + int(char) |
| 293 | if char in ("a", "o", "h", "m") : |
| 294 | ispcl3 = 1 # certainely a PCL3 document |
| 295 | pos -= 1 # fix position : we were ahead |
| 296 | if char == "h" : |
243 | | elif tag == "*r" : |
244 | | # Special tests for PCL3 |
245 | | if (char == "s") and size : |
246 | | while 1 : |
247 | | char = minfile[pos] ; pos += 1 |
248 | | if char == "A" : |
249 | | break |
250 | | elif (char == "b") and (minfile[pos] == "C") and not size : |
251 | | ispcl3 = 1 # Certainely a PCL3 file |
252 | | startgfx += (char == "A") and (minfile[pos - 2] in ("0", "1", "2", "3")) # Start Gfx |
253 | | endgfx += (not size) and (char in ("C", "B")) # End Gfx |
254 | | elif tag == "*t" : |
255 | | escstart += 1 |
256 | | elif (tag == "&a") and (size == 2) : |
257 | | # We are on the backside, so mark current page as duplex |
258 | | self.setPageDict(pages, pagecount, "duplex", 1) |
259 | | backsides += 1 # Back side in duplex mode |
260 | | else : |
261 | | # we just ignore the block. |
262 | | if tag == "&n" : |
263 | | # we have to take care of the operation id byte |
264 | | # which is before the string itself |
265 | | size += 1 |
266 | | pos += size |
267 | | else : |
268 | | if starb : |
269 | | # special handling of PCL3 in which |
270 | | # *b introduces combined ESCape sequences |
271 | | size = 0 |
272 | | while 1 : |
273 | | char = minfile[pos] ; pos += 1 |
274 | | if not char.isdigit() : |
275 | | break |
276 | | size = (size * 10) + int(char) |
277 | | if char in ("w", "v") : |
278 | | ispcl3 = 1 # certainely a PCL3 document |
279 | | pos += size - 1 |
280 | | elif char in ("y", "m") : |
281 | | ispcl3 = 1 # certainely a PCL3 document |
282 | | pos -= 1 # fix position : we were ahead |
283 | | elif ampl : |
284 | | # special handling of PCL3 in which |
285 | | # &l introduces combined ESCape sequences |
286 | | size = 0 |
287 | | while 1 : |
288 | | char = minfile[pos] ; pos += 1 |
289 | | if not char.isdigit() : |
290 | | break |
291 | | size = (size * 10) + int(char) |
292 | | if char in ("a", "o", "h", "m") : |
293 | | ispcl3 = 1 # certainely a PCL3 document |
294 | | pos -= 1 # fix position : we were ahead |
295 | | if char == "h" : |
296 | | self.setPageDict(pages, pagecount, "mediasource", self.mediasources.get(size, str(size))) |
297 | | mediasourcecount += 1 |
298 | | elif char == "a" : |
299 | | self.setPageDict(pages, pagecount, "mediasize", self.mediasizes.get(size, str(size))) |
300 | | mediasizecount += 1 |
301 | | elif char == "o" : |
302 | | self.setPageDict(pages, pagecount, "orientation", self.orientations.get(size, str(size))) |
303 | | orientationcount += 1 |
304 | | elif char == "m" : |
305 | | self.setPageDict(pages, pagecount, "mediatype", self.mediatypes.get(size, str(size))) |
306 | | mediatypecount += 1 |
307 | | except IndexError : # EOF ? |
308 | | minfile.close() # reached EOF |
| 308 | except IndexError : # EOF ? |
| 309 | pass |
| 310 | finally : |
| 311 | minfile.close() |