Changeset 317
- Timestamp:
- 02/09/06 23:04:48 (19 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/pclxl.py
r316 r317 176 176 def endPage(self, prevpos) : 177 177 """Indicates the end of a page.""" 178 pos = prevpos 179 pos3 = pos - 3 178 pos3 = prevpos - 3 180 179 minfile = self.minfile 181 if minfile[pos3:p os-1] == self.setNumberOfCopies :180 if minfile[pos3:prevpos-1] == self.setNumberOfCopies : 182 181 # The EndPage operator may be preceded by a PageCopies attribute 183 182 # So set number of copies for current page. … … 185 184 # of copies is an unsigned 16 bits integer 186 185 try : 187 self.pages[self.pagecount]["copies"] = unpack(self.unpackShort, minfile[pos -5:pos3])[0]186 self.pages[self.pagecount]["copies"] = unpack(self.unpackShort, minfile[pos3-2:pos3])[0] 188 187 except KeyError : 189 188 self.logdebug("It looks like this PCLXL file is corrupted.") … … 192 191 def setColorSpace(self, prevpos) : 193 192 """Changes the color space.""" 194 if self.minfile[prevpos-4:prevpos-1] == self.RGBColorSpace : 193 if self.minfile[prevpos-4:prevpos-1] == self.RGBColorSpace : # TODO : doesn't seem to handle all cases ! 195 194 self.iscolor = 1 196 195 return 0 197 196 198 def array_ 8(self, prevpos) :199 """Handles bytearrays."""197 def array_Generic(self, prevpos, size) : 198 """Handles all arrays.""" 200 199 pos = prevpos 201 datatype = self.minfile[pos]200 datatype = ord(self.minfile[pos]) 202 201 pos += 1 203 length = self.tags[ ord(datatype)]202 length = self.tags[datatype] 204 203 if callable(length) : 205 204 length = length(pos) 206 205 posl = pos + length 207 206 if length == 1 : 208 return 1 + length + unpack("B", self.minfile[pos:posl])[0]207 return 1 + length + size * unpack("B", self.minfile[pos:posl])[0] 209 208 elif length == 2 : 210 return 1 + length + unpack(self.unpackShort, self.minfile[pos:posl])[0]209 return 1 + length + size * unpack(self.unpackShort, self.minfile[pos:posl])[0] 211 210 elif length == 4 : 212 return 1 + length + unpack(self.unpackLong, self.minfile[pos:posl])[0]211 return 1 + length + size * unpack(self.unpackLong, self.minfile[pos:posl])[0] 213 212 else : 214 213 raise pdlparser.PDLParserError, "Error on array size at %x" % prevpos 214 215 def array_8(self, prevpos) : 216 """Handles byte arrays.""" 217 return self.array_Generic(prevpos, 1) 215 218 216 219 def array_16(self, prevpos) : 217 220 """Handles byte arrays.""" 218 pos = prevpos 219 datatype = self.minfile[pos] 220 pos += 1 221 length = self.tags[ord(datatype)] 222 if callable(length) : 223 length = length(pos) 224 posl = pos + length 225 if length == 1 : 226 return 1 + length + 2 * unpack("B", self.minfile[pos:posl])[0] 227 elif length == 2 : 228 return 1 + length + 2 * unpack(self.unpackShort, self.minfile[pos:posl])[0] 229 elif length == 4 : 230 return 1 + length + 2 * unpack(self.unpackLong, self.minfile[pos:posl])[0] 231 else : 232 raise pdlparser.PDLParserError, "Error on array size at %x" % prevpos 221 return self.array_Generic(prevpos, 2) 233 222 234 223 def array_32(self, prevpos) : 235 224 """Handles byte arrays.""" 236 pos = prevpos 237 datatype = self.minfile[pos] 238 pos += 1 239 length = self.tags[ord(datatype)] 240 if callable(length) : 241 length = length(pos) 242 posl = pos + length 243 if length == 1 : 244 return 1 + length + 4 * unpack("B", self.minfile[pos:posl])[0] 245 elif length == 2 : 246 return 1 + length + 4 * unpack(self.unpackShort, self.minfile[pos:posl])[0] 247 elif length == 4 : 248 return 1 + length + 4 * unpack(self.unpackLong, self.minfile[pos:posl])[0] 249 else : 250 raise pdlparser.PDLParserError, "Error on array size at %x" % prevpos 225 return self.array_Generic(prevpos, 4) 251 226 252 227 def embeddedDataSmall(self, prevpos) : … … 260 235 def littleEndian(self, prevpos) : 261 236 """Toggles to little endianness.""" 262 self.endianness = "<" # little endian263 237 self.unpackShort = "<H" 264 238 self.unpackLong = "<I" … … 267 241 def bigEndian(self, prevpos) : 268 242 """Toggles to big endianness.""" 269 self.endianness = ">" # big endian270 243 self.unpackShort = ">H" 271 244 self.unpackLong = ">I" … … 285 258 if (val == 0xf8) and (ord(minfile[pos+1]) in (0x95, 0x96)) : 286 259 pos += 2 287 ordatatype = ord(self.minfile[pos])288 if ordatatype == 0x46 :260 datatype = ord(self.minfile[pos]) 261 if datatype == 0x46 : 289 262 break 290 263 pos += 1 291 length = self.tags[ ordatatype]264 length = self.tags[datatype] 292 265 posl = pos + length 293 266 if length == 1 : … … 359 332 """ 360 333 self.iscolor = None 361 self.endianness = None362 334 found = 0 363 335 while not found :