Show
Ignore:
Timestamp:
12/09/07 13:01:15 (16 years ago)
Author:
jerome
Message:

Added support for Canon BJ/BJC file format in page counting mode.

Location:
pkpgcounter/trunk/pkpgpdls
Files:
1 modified
1 copied

Legend:

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

    r539 r545  
    3030import version, pdlparser, postscript, pdf, pcl345, pclxl, hbp, \ 
    3131       pil, mscrap, cfax, lidil, escp2, dvi, tiff, ooo, zjstream, \ 
    32        qpdl, spl1, escpages03, plain 
     32       bj, qpdl, spl1, escpages03, plain 
    3333import inkcoverage 
    3434 
     
    164164                       escp2, \ 
    165165                       escpages03, \ 
     166                       bj, \ 
    166167                       pil, \ 
    167168                       mscrap, \ 
  • pkpgcounter/trunk/pkpgpdls/bj.py

    r527 r545  
    2121# 
    2222 
    23 """This modules implements a page counter for DVI documents.""" 
     23"""This modules implements a page counter for Canon BJ documents.""" 
    2424 
    2525import sys 
     
    3131 
    3232class Parser(pdlparser.PDLParser) : 
    33     """A parser for DVI documents.""" 
    34     totiffcommands = [ 'dvips -q -o - "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -' ] 
    35     required = [ "dvips", "gs" ] 
     33    """A parser for Canon BJ documents.""" 
    3634    def isValid(self) :         
    3735        """Returns True if data is DVI, else False.""" 
    38         try : 
    39             if (ord(self.firstblock[0]) == 0xf7) \ 
    40                 and (ord(self.lastblock[-1]) == 0xdf) : 
    41                 self.logdebug("DEBUG: Input file is in the DVI format.") 
    42                 return True 
    43             else :     
    44                 return False 
    45         except IndexError :           
     36        if self.firstblock.startswith("\033[K\002\000") : 
     37            self.logdebug("DEBUG: Input file is in the Canon BJ format.") 
     38            return True 
     39        else :     
    4640            return False 
    4741             
    4842    def getJobSize(self) : 
    49         """Counts pages in a DVI document. 
     43        """Counts pages in a Canon BJ document. 
    5044         
    5145           Algorithm by Jerome Alet. 
     
    5347           The documentation used for this was : 
    5448          
    55            http://www.math.umd.edu/~asnowden/comp-cont/dvi.html 
     49           ghostscript-8.60/src/gdevbj*.c 
    5650        """ 
    5751        infileno = self.infile.fileno() 
    5852        minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED) 
    5953        pagecount = 0 
    60         pos = -1 
    61         eofchar = chr(0xdf) 
    62         postchar = chr(0xf8) 
     54        pos = 0 
    6355        try : 
    6456            try : 
    65                 while minfile[pos] == eofchar : 
    66                     pos -= 1 
    67                 idbyte = minfile[pos]     
    68                 if idbyte != minfile[1] : 
    69                     raise IndexError, "Invalid DVI file." 
    70                 pos = unpack(">I", minfile[pos - 4:pos])[0] 
    71                 if minfile[pos] != postchar : 
    72                     raise IndexError, "Invalid DVI file." 
    73                 pagecount = unpack(">H", minfile[pos + 27: pos + 29])[0] 
     57                while True : 
     58                    if minfile[pos] == "\033" : 
     59                        # Look if we've found an initialization sequence 
     60                        # through the Set Initial Condition command 
     61                        pageheader = minfile[pos:pos+7] 
     62                        if pageheader in ("\033[K\002\000\000\017",  
     63                                          "\033[K\002\000\000\044", 
     64                                          "\033[K\002\000\004\044") : 
     65                            pagecount += 1 
     66                            pos += 6 
     67                    pos += 1 
    7468            except IndexError : # EOF ? 
    7569                pass