Changeset 1591

Show
Ignore:
Timestamp:
07/05/04 23:00:39 (20 years ago)
Author:
jalet
Message:

Fix for number of copies for each page in PCLXL parser

Location:
pykota/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/NEWS

    r1588 r1591  
    2424    - 1.19alpha29 :  
    2525     
     26        - PCLXL parser should now correctly handle number of 
     27          copies set for each page. 
     28           
    2629        - Added testsuite for generic PDL analyzer. 
    2730         
  • pykota/trunk/pykota/pdlanalyzer.py

    r1588 r1591  
    2222# 
    2323# $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# 
    2427# Revision 1.23  2004/07/03 08:21:59  jalet 
    2528# Testsuite for PDL Analyzer added 
     
    147150         
    148151    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        """ 
    164169        infileno = self.infile.fileno() 
    165170        minfile = mmap.mmap(infileno, os.fstat(infileno).st_size, access=mmap.ACCESS_READ) 
     
    271276    def __init__(self, infile) : 
    272277        """Initialize PCLXL Analyzer.""" 
    273         # raise PDLAnalyzerError, "PCLXL (aka PCL6) is not supported yet." 
    274278        self.infile = infile 
    275279        self.endianness = None 
     
    289293                #  
    290294                else :     
    291                     raise PDLAnalyzerError, "No endianness marker 0x%02x at start !" % endian 
     295                    raise PDLAnalyzerError, "Unknown endianness marker 0x%02x at start !" % endian 
    292296        if not found : 
    293297            raise PDLAnalyzerError, "This file doesn't seem to be PCLXL (aka PCL6)" 
     
    302306             
    303307            self.tags[0x43] = self.beginPage    # BeginPage 
     308            self.tags[0x44] = self.endPage      # EndPage 
    304309             
    305310            self.tags[0xc0] = 1 # ubyte 
     
    340345        """Indicates the beginning of a new page.""" 
    341346        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] 
    342359        return 0 
    343360         
     
    430447     
    431448    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        """ 
    433459        infileno = self.infile.fileno() 
     460        self.copies = {} 
    434461        self.minfile = minfile = mmap.mmap(infileno, os.fstat(infileno).st_size, access=mmap.ACCESS_READ) 
    435462        tags = self.tags 
     
    450477        except IndexError : # EOF ? 
    451478            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             
    452489        return self.pagecount 
    453490