Changeset 318 for pkpgcounter/trunk/pkpgpdls/pclxl.py
- Timestamp:
- 02/10/06 00:30:17 (19 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/pclxl.py
r317 r318 88 88 return 0 89 89 90 def beginPage(self, prevpos) :90 def beginPage(self, nextpos) : 91 91 """Indicates the beginning of a new page, and extracts media information.""" 92 92 self.pagecount += 1 … … 102 102 # this saves time because we don't need a complete parser ! 103 103 minfile = self.minfile 104 pos = prevpos - 2104 pos = nextpos - 2 105 105 while pos > 0 : # safety check : don't go back to far ! 106 106 val = ord(minfile[pos]) … … 174 174 return 0 175 175 176 def endPage(self, prevpos) :176 def endPage(self, nextpos) : 177 177 """Indicates the end of a page.""" 178 pos3 = prevpos - 3178 pos3 = nextpos - 3 179 179 minfile = self.minfile 180 if minfile[pos3: prevpos-1] == self.setNumberOfCopies :180 if minfile[pos3:nextpos-1] == self.setNumberOfCopies : 181 181 # The EndPage operator may be preceded by a PageCopies attribute 182 182 # So set number of copies for current page. … … 189 189 return 0 190 190 191 def setColorSpace(self, prevpos) :191 def setColorSpace(self, nextpos) : 192 192 """Changes the color space.""" 193 if self.minfile[ prevpos-4:prevpos-1] == self.RGBColorSpace : # TODO : doesn't seem to handle all cases !193 if self.minfile[nextpos-4:nextpos-1] == self.RGBColorSpace : # TODO : doesn't seem to handle all cases ! 194 194 self.iscolor = 1 195 195 return 0 196 196 197 def array_Generic(self, prevpos, size) :197 def array_Generic(self, nextpos, size) : 198 198 """Handles all arrays.""" 199 pos = prevpos199 pos = nextpos 200 200 datatype = ord(self.minfile[pos]) 201 201 pos += 1 … … 203 203 if callable(length) : 204 204 length = length(pos) 205 posl = pos + length 206 if length == 1 : 207 return 1 + length + size * unpack("B", self.minfile[pos:posl])[0] 208 elif length == 2 : 209 return 1 + length + size * unpack(self.unpackShort, self.minfile[pos:posl])[0] 210 elif length == 4 : 211 return 1 + length + size * unpack(self.unpackLong, self.minfile[pos:posl])[0] 212 else : 213 raise pdlparser.PDLParserError, "Error on array size at %x" % prevpos 214 215 def array_8(self, prevpos) : 205 try : 206 return 1 + length + size * unpack(self.unpackType[length], self.minfile[pos:pos+length])[0] 207 except KeyError : 208 raise pdlparser.PDLParserError, "Error on array size at %x" % nextpos 209 210 def array_8(self, nextpos) : 216 211 """Handles byte arrays.""" 217 return self.array_Generic( prevpos, 1)218 219 def array_16(self, prevpos) :212 return self.array_Generic(nextpos, 1) 213 214 def array_16(self, nextpos) : 220 215 """Handles byte arrays.""" 221 return self.array_Generic( prevpos, 2)222 223 def array_32(self, prevpos) :216 return self.array_Generic(nextpos, 2) 217 218 def array_32(self, nextpos) : 224 219 """Handles byte arrays.""" 225 return self.array_Generic( prevpos, 4)226 227 def embeddedDataSmall(self, prevpos) :220 return self.array_Generic(nextpos, 4) 221 222 def embeddedDataSmall(self, nextpos) : 228 223 """Handle small amounts of data.""" 229 return 1 + ord(self.minfile[ prevpos])230 231 def embeddedData(self, prevpos) :224 return 1 + ord(self.minfile[nextpos]) 225 226 def embeddedData(self, nextpos) : 232 227 """Handle normal amounts of data.""" 233 return 4 + unpack(self.unpackLong, self.minfile[ prevpos:prevpos+4])[0]234 235 def littleEndian(self, prevpos) :228 return 4 + unpack(self.unpackLong, self.minfile[nextpos:nextpos+4])[0] 229 230 def littleEndian(self, nextpos) : 236 231 """Toggles to little endianness.""" 237 self.unpackShort = "<H" 238 self.unpackLong = "<I" 232 self.unpackType = { 1 : "B", 2 : "<H", 4 : "<I" } 233 self.unpackShort = self.unpackType[2] 234 self.unpackLong = self.unpackType[4] 239 235 return 0 240 236 241 def bigEndian(self, prevpos) :237 def bigEndian(self, nextpos) : 242 238 """Toggles to big endianness.""" 243 self.unpackShort = ">H" 244 self.unpackLong = ">I" 239 self.unpackType = { 1 : "B", 2 : ">H", 4 : ">I" } 240 self.unpackShort = self.unpackType[2] 241 self.unpackLong = self.unpackType[4] 245 242 return 0 246 243 247 def reservedForFutureUse(self, prevpos) :244 def reservedForFutureUse(self, nextpos) : 248 245 """Outputs something when a reserved byte is encountered.""" 249 self.logdebug("Byte at %x is out of the PCLXL Protocol Class 2.0 Specification" % prevpos)246 self.logdebug("Byte at %x is out of the PCLXL Protocol Class 2.0 Specification" % nextpos) 250 247 return 0 251 248 252 def x46_class3(self, prevpos) :249 def x46_class3(self, nextpos) : 253 250 """Undocumented tag 0x46 in class 3.0 streams.""" 254 pos = prevpos251 pos = nextpos - 3 255 252 minfile = self.minfile 256 while pos > 0 : # safety check : don't go back to far ! 253 val = ord(minfile[pos]) 254 while val == 0xf8 : 255 funcid = ord(minfile[pos+1]) 256 try : 257 offset = self.x46_functions[funcid] 258 except KeyError : 259 self.logdebug("Unexpected subfunction 0x%02x for undocumented tag 0x46 at %x" % (funcid, nextpos)) 260 break 261 else : 262 length = self.tags[ord(self.minfile[pos-offset])] 263 if callable(length) : 264 length = length(pos-offset+1) 265 pos -= offset 266 if funcid == 0x92 : 267 try : 268 return unpack(self.unpackType[length], self.minfile[pos+1:pos+length+1])[0] 269 except KeyError : 270 raise pdlparser.PDLParserError, "Error on size '%s' at %x" % (length, pos+1) 257 271 val = ord(minfile[pos]) 258 if (val == 0xf8) and (ord(minfile[pos+1]) in (0x95, 0x96)) :259 pos += 2260 datatype = ord(self.minfile[pos])261 if datatype == 0x46 :262 break263 pos += 1264 length = self.tags[datatype]265 posl = pos + length266 if length == 1 :267 return unpack("B", self.minfile[pos:posl])[0]268 elif length == 2 :269 return unpack(self.unpackShort, self.minfile[pos:posl])[0]270 elif length == 4 :271 return unpack(self.unpackLong, self.minfile[pos:posl])[0]272 else :273 raise pdlparser.PDLParserError, "Error on size at %x" % prevpos274 else :275 pos -= 1276 272 return 0 277 273 278 def escape(self, prevpos) :274 def escape(self, nextpos) : 279 275 """Handles the ESC code.""" 280 pos = endpos = prevpos276 pos = endpos = nextpos 281 277 minfile = self.minfile 282 278 if minfile[pos : pos+8] == r"%-12345X" : … … 298 294 return endpos - pos 299 295 300 def skipKyoceraPrescribe(self, prevpos) :296 def skipKyoceraPrescribe(self, nextpos) : 301 297 """Skips Kyocera Prescribe commands.""" 302 pos = prevpos - 1298 pos = nextpos - 1 303 299 minfile = self.minfile 304 300 if minfile[pos:pos+3] == "!R!" : 305 while (pos - prevpos) < 1024 : # This is a realistic upper bound, to avoid infinite loops301 while (pos - nextpos) < 1024 : # This is a realistic upper bound, to avoid infinite loops 306 302 if (minfile[pos] == ";") and (minfile[pos-4:pos] == "EXIT") : 307 303 pos += 1 308 304 prescribe = self.prescribeStuff.setdefault(self.pagecount, []) 309 prescribe.append(minfile[ prevpos-1:pos])310 self.logdebug("Prescribe commands : [%s]" % repr(minfile[ prevpos-1:pos]))311 return (pos - prevpos)305 prescribe.append(minfile[nextpos-1:pos]) 306 self.logdebug("Prescribe commands : [%s]" % repr(minfile[nextpos-1:pos])) 307 return (pos - nextpos) 312 308 pos += 1 313 309 else : … … 509 505 self.setNumberOfCopies = "".join([chr(0xf8), chr(0x31)]) 510 506 507 # subcodes for undocumented tag 0x46 and the negative 508 # offset to grab the value from. 509 self.x46_functions = { 0x91 : 5, 510 0x92 : 5, 511 0x93 : 3, 512 0x94 : 3, 513 0x95 : 5, 514 0x96 : 2, 515 0x97 : 2, 516 0x98 : 2, 517 } 518 511 519 infileno = self.infile.fileno() 512 520 self.pages = { 0 : { "copies" : 1,