Show
Ignore:
Timestamp:
10/01/07 23:24:10 (17 years ago)
Author:
jerome
Message:

v3.20 is out with support for Brother HBP and improved PCLXL
parser wrt the inclusion of Canon ImageRunner? commands.

Files:
1 copied

Legend:

Unmodified
Added
Removed
  • pkpgcounter/trunk/pkpgpdls/hbp.py

    r463 r480  
    2121# 
    2222 
    23 """This modules implements a page counter for DVI documents.""" 
     23"""This modules implements a page counter for Brother HBP documents.""" 
    2424 
    2525import sys 
     
    3131 
    3232class Parser(pdlparser.PDLParser) : 
    33     """A parser for DVI documents.""" 
    34     totiffcommands = [ 'cat >%(fname)s && dvips -q -o - %(fname)s | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' ] 
     33    """A parser for HBP documents.""" 
    3534    def isValid(self) :         
    36         """Returns True if data is DVI, else False.""" 
    37         try : 
    38             if (ord(self.firstblock[0]) == 0xf7) and (ord(self.lastblock[-1]) == 0xdf) : 
    39                 self.logdebug("DEBUG: Input file is in the DVI format.") 
    40                 return True 
    41             else :     
    42                 return False 
    43         except IndexError :           
     35        """Returns True if data is HBP, else False.""" 
     36        if self.firstblock.find("@PJL ENTER LANGUAGE = HBP\n") != -1 : 
     37            self.logdebug("DEBUG: Input file is in the HBP format.") 
     38            return True 
     39        else :     
    4440            return False 
    4541             
    4642    def getJobSize(self) : 
    47         """Counts pages in a DVI document. 
     43        """Counts pages in a HBP document. 
    4844         
    4945           Algorithm by Jerome Alet. 
     
    5147           The documentation used for this was : 
    5248          
    53            http://www.math.umd.edu/~asnowden/comp-cont/dvi.html 
     49           http://sf.net/projects/hbp-for-brother/ 
     50            
     51           IMPORTANT : this may not work since @F should be sufficient, 
     52           but the documentation really is unclear and I don't know 
     53           how to skip raster data blocks for now. 
    5454        """ 
    5555        infileno = self.infile.fileno() 
    5656        minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED) 
    5757        pagecount = 0 
    58         pos = -1 
    59         eofchar = chr(0xdf) 
    60         postchar = chr(0xf8) 
     58         
     59        formfeed = "@G" + chr(0) + chr(0) + chr(1) + chr(0xff) + "@F" 
     60        fflen = len(formfeed) 
     61        pos = 0 
    6162        try : 
    62             while minfile[pos] == eofchar : 
    63                 pos -= 1 
    64             idbyte = minfile[pos]     
    65             if idbyte != minfile[1] : 
    66                 raise IndexError, "Invalid DVI file." 
    67             pos = unpack(">I", minfile[pos - 4:pos])[0] 
    68             if minfile[pos] != postchar : 
    69                 raise IndexError, "Invalid DVI file." 
    70             pagecount = unpack(">H", minfile[pos + 27: pos + 29])[0] 
     63            while True : 
     64                if (minfile[pos] == "@") \ 
     65                   and (minfile[pos:pos+fflen] == formfeed) : 
     66                    pagecount += 1 
     67                    pos += fflen 
     68                else :         
     69                    pos += 1 
    7170        except IndexError : # EOF ? 
    7271            pass