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