Changeset 1591 for pykota/trunk
- Timestamp:
- 07/05/04 23:00:39 (20 years ago)
- Location:
- pykota/trunk
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/NEWS
r1588 r1591 24 24 - 1.19alpha29 : 25 25 26 - PCLXL parser should now correctly handle number of 27 copies set for each page. 28 26 29 - Added testsuite for generic PDL analyzer. 27 30 -
pykota/trunk/pykota/pdlanalyzer.py
r1588 r1591 22 22 # 23 23 # $Log$ 24 # Revision 1.24 2004/07/05 21:00:39 jalet 25 # Fix for number of copies for each page in PCLXL parser 26 # 24 27 # Revision 1.23 2004/07/03 08:21:59 jalet 25 28 # Testsuite for PDL Analyzer added … … 147 150 148 151 def getJobSize(self) : 149 """Count pages in a PCL5 document.""" 150 # 151 # Algorithm from pclcount 152 # (c) 2003, by Eduardo Gielamo Oliveira & Rodolfo Broco Manin 153 # published under the terms of the GNU General Public Licence v2. 154 # 155 # Backported from C to Python by Jerome Alet, then enhanced 156 # with more PCL tags detected. I think all the necessary PCL tags 157 # are recognized to correctly handle PCL5 files wrt their number 158 # of pages. The documentation used for this was : 159 # 160 # HP PCL/PJL Reference Set 161 # PCL5 Printer Language Technical Quick Reference Guide 162 # http://h20000.www2.hp.com/bc/docs/support/SupportManual/bpl13205/bpl13205.pdf 163 # 152 """Count pages in a PCL5 document. 153 154 Should also work for PCL3 and PCL4 documents. 155 156 Algorithm from pclcount 157 (c) 2003, by Eduardo Gielamo Oliveira & Rodolfo Broco Manin 158 published under the terms of the GNU General Public Licence v2. 159 160 Backported from C to Python by Jerome Alet, then enhanced 161 with more PCL tags detected. I think all the necessary PCL tags 162 are recognized to correctly handle PCL5 files wrt their number 163 of pages. The documentation used for this was : 164 165 HP PCL/PJL Reference Set 166 PCL5 Printer Language Technical Quick Reference Guide 167 http://h20000.www2.hp.com/bc/docs/support/SupportManual/bpl13205/bpl13205.pdf 168 """ 164 169 infileno = self.infile.fileno() 165 170 minfile = mmap.mmap(infileno, os.fstat(infileno).st_size, access=mmap.ACCESS_READ) … … 271 276 def __init__(self, infile) : 272 277 """Initialize PCLXL Analyzer.""" 273 # raise PDLAnalyzerError, "PCLXL (aka PCL6) is not supported yet."274 278 self.infile = infile 275 279 self.endianness = None … … 289 293 # 290 294 else : 291 raise PDLAnalyzerError, " Noendianness marker 0x%02x at start !" % endian295 raise PDLAnalyzerError, "Unknown endianness marker 0x%02x at start !" % endian 292 296 if not found : 293 297 raise PDLAnalyzerError, "This file doesn't seem to be PCLXL (aka PCL6)" … … 302 306 303 307 self.tags[0x43] = self.beginPage # BeginPage 308 self.tags[0x44] = self.endPage # EndPage 304 309 305 310 self.tags[0xc0] = 1 # ubyte … … 340 345 """Indicates the beginning of a new page.""" 341 346 self.pagecount += 1 347 return 0 348 349 def endPage(self) : 350 """Indicates the end of a page.""" 351 pos = self.pos 352 minfile = self.minfile 353 if (ord(minfile[pos-3]) == 0xf8) and (ord(minfile[pos-2]) == 0x31) : 354 # The EndPage operator is preceded by a PageCopies attribute 355 # So set number of copies for current page. 356 # From what I read in PCLXL documentation, the number 357 # of copies is an unsigned 16 bits integer 358 self.copies[self.pagecount] = unpack(self.endianness + "H", minfile[pos-5:pos-3])[0] 342 359 return 0 343 360 … … 430 447 431 448 def getJobSize(self) : 432 """Counts pages in a PCLXL (PCL6) document.""" 449 """Counts pages in a PCLXL (PCL6) document. 450 451 Algorithm by Jerome Alet. 452 453 The documentation used for this was : 454 455 HP PCL XL Feature Reference 456 Protocol Class 2.0 457 http://www.hpdevelopersolutions.com/downloads/64/358/xl_ref20r22.pdf 458 """ 433 459 infileno = self.infile.fileno() 460 self.copies = {} 434 461 self.minfile = minfile = mmap.mmap(infileno, os.fstat(infileno).st_size, access=mmap.ACCESS_READ) 435 462 tags = self.tags … … 450 477 except IndexError : # EOF ? 451 478 self.minfile.close() # reached EOF 479 480 # now handle number of copies for each page (may differ). 481 for pnum in range(self.pagecount) : 482 # if no number of copies defined, take 1, as explained 483 # in PCLXL documentation. 484 # NB : is number of copies is 0, the page won't be output 485 # but the formula below is still correct : we want 486 # to decrease the total number of pages in this case. 487 self.pagecount += (self.copies.get(pnum, 1) - 1) 488 452 489 return self.pagecount 453 490