Changeset 539

Show
Ignore:
Timestamp:
12/09/07 09:58:08 (15 years ago)
Author:
jerome
Message:

Added support for Structured Fax documents.

Location:
pkpgcounter/trunk
Files:
6 modified
1 copied

Legend:

Unmodified
Added
Removed
  • pkpgcounter/trunk/bin/pkpgcounter

    r529 r539  
    5656    * Brother HBP 
    5757    * Hewlett-Packard LIDIL (hpijs) 
     58    * Structured Fax 
    5859 
    59 The seven latter ones, as well as some TIFF documents, are currently 
     60The eight latter ones, as well as some TIFF documents, are currently 
    6061only supported in page counting mode. 
    6162 
  • pkpgcounter/trunk/man/pkpgcounter.1

    r529 r539  
    11.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.36. 
    2 .TH PKPGCOUNTER "1" "November 2007" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
     2.TH PKPGCOUNTER "1" "December 2007" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
    33.SH NAME 
    44pkpgcounter \- count number of pages required to print various types of documents 
    55.SH DESCRIPTION 
    6 pkpgcounter v3.40 (c) 2003, 2004, 2005, 2006, 2007 Jerome Alet 
     6pkpgcounter v3.50alpha (c) 2003, 2004, 2005, 2006, 2007 Jerome Alet 
    77.PP 
    88pkpgcounter is a generic Page Description Language parser. 
     
    3333* Brother HBP 
    3434* Hewlett\-Packard LIDIL (hpijs) 
     35* Structured Fax 
    3536.PP 
    36 The seven latter ones, as well as some TIFF documents, are currently 
     37The eight latter ones, as well as some TIFF documents, are currently 
    3738only supported in page counting mode. 
    3839.PP 
  • pkpgcounter/trunk/NEWS

    r529 r539  
    2121pkpgcounter News : 
    2222 
     23  * 3.50 : 
     24   
     25    - Added support for Structured Fax documents in page counting mode. 
     26     
     27    - Fixed a problem with the parsing of SPL1 (GDI) documents. 
     28     
    2329  * 3.40 : 
    2430   
  • pkpgcounter/trunk/pkpgpdls/analyzer.py

    r529 r539  
    2828import tempfile 
    2929 
    30 import version, pdlparser, postscript, pdf, pcl345, pclxl, hbp, pil, mscrap, \ 
    31        lidil, escp2, dvi, tiff, ooo, zjstream, qpdl, spl1, escpages03, plain 
     30import version, pdlparser, postscript, pdf, pcl345, pclxl, hbp, \ 
     31       pil, mscrap, cfax, lidil, escp2, dvi, tiff, ooo, zjstream, \ 
     32       qpdl, spl1, escpages03, plain 
    3233import inkcoverage 
    3334 
     
    155156                       dvi, \ 
    156157                       tiff, \ 
     158                       cfax, \ 
    157159                       zjstream, \ 
    158160                       ooo, \ 
  • pkpgcounter/trunk/pkpgpdls/cfax.py

    r527 r539  
    2121# 
    2222 
    23 """This modules implements a page counter for DVI documents.""" 
     23"""This modules implements a page counter for Structured Fax documents.""" 
    2424 
    25 import sys 
    26 import os 
    27 import mmap 
    28 from struct import unpack 
     25import struct 
    2926 
    3027import pdlparser 
    3128 
    3229class 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" ] 
     30    """A parser for Structured Fax documents.""" 
    3631    def isValid(self) :         
    37         """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 :           
     32        """Returns True if data is Structured Fax, else False.""" 
     33        if self.firstblock.startswith("Sfff") : 
     34            self.logdebug("DEBUG: Input file is in the Structured Fax format.") 
     35            return True 
     36        else :     
    4637            return False 
    4738             
    4839    def getJobSize(self) : 
    49         """Counts pages in a DVI document. 
     40        """Counts pages in a Structured Fax document. 
    5041         
    5142           Algorithm by Jerome Alet. 
     
    5344           The documentation used for this was : 
    5445          
    55            http://www.math.umd.edu/~asnowden/comp-cont/dvi.html 
     46           http://delphi.pjh2.de/articles/graphic/sff_format.php 
    5647        """ 
    57         infileno = self.infile.fileno() 
    58         minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED) 
     48        unpack = struct.unpack 
    5949        pagecount = 0 
    60         pos = -1 
    61         eofchar = chr(0xdf) 
    62         postchar = chr(0xf8) 
     50        docheader = self.infile.read(20) 
    6351        try : 
    64             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] 
    74             except IndexError : # EOF ? 
    75                 pass 
    76         finally :         
    77             minfile.close() # reached EOF 
    78         return pagecount 
     52            (sffid, 
     53             version, 
     54             reserved, 
     55             userinfo, 
     56             docpagecount, 
     57             offsetfirstpage, 
     58             offsetlastpage, 
     59             offsetdocumentend) = unpack("<4sBBHHHII", docheader) 
     60            self.infile.seek(offsetfirstpage - len(docheader), 1)      
     61            while True : 
     62                headerid = self.infile.read(1) 
     63                if not headerid : 
     64                    break 
     65                headerid = ord(headerid)     
     66                if 1 <= headerid <= 216 : # Normal record header 
     67                    self.infile.seek(headerid, 1) 
     68                elif headerid == 255 :    # Illegal line / Additional user info 
     69                    additionalbyte = self.infile.read(1) 
     70                    if not additionalbyte : 
     71                        break 
     72                    additionalbyte = ord(additionalbyte)     
     73                    if 1 <= additionalbyte <= 255 : 
     74                        # Skip additional user information (reserved) 
     75                        self.infile.seek(additionalbyte, 1) 
     76                elif not headerid :         
     77                    # Record with more than 216 MH-coded bytes 
     78                    recordlen = self.infile.read(2) 
     79                    if not recordlen : 
     80                        break 
     81                    recordlen = unpack("<H", recordlen)[0]     
     82                    self.infile.seek(recordlen, 1) 
     83                elif headerid == 254 : # Page header 
     84                    pageheader = self.infile.read(17) 
     85                    if not pageheader :  
     86                        break 
     87                    headerlen = ord(pageheader[0]) 
     88                    if not headerlen : 
     89                        break # End Of Document 
     90                    (vres, 
     91                     hres, 
     92                     coding, 
     93                     reserved, 
     94                     linelen, 
     95                     pagelen, 
     96                     offsetpreviouspage, 
     97                     offsetnextpage) = unpack("<4BHHII", pageheader[1:]) 
     98                    pagecount += 1     
     99                    if (offsetnextpage == 1) or (vres == 255) : 
     100                        break # End Of Document 
     101                    self.infile.seek(offsetnextpage, 1)     
     102        except struct.error :      
     103             raise pdlparser.PDLParserError, "Invalid Structured Fax datas" 
     104        return max(docpagecount, pagecount)      
  • pkpgcounter/trunk/pkpgpdls/version.py

    r531 r539  
    2222 
    2323 
    24 __version__ = "3.41alpha" 
     24__version__ = "3.50alpha" 
    2525 
    2626__doc__ = """pkpgcounter : a generic Page Description Languages parser.""" 
  • pkpgcounter/trunk/README

    r529 r539  
    5959        - Hewlett-Packard Lightweight Imaging Device Interface Language 
    6060         
    61 The seven latter ones, as well as some TIFF documents, are currently  
     61        - Structured Fax 
     62         
     63The eight latter ones, as well as some TIFF documents, are currently  
    6264only supported in page counting mode.  
    6365