Changeset 1461 for pykota/trunk

Show
Ignore:
Timestamp:
05/08/04 01:08:21 (21 years ago)
Author:
jalet
Message:

Skeleton for PCLXL aka PCL6
Added the "potential" fix for rastertoprinter's output

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkpgcounter

    r1456 r1461  
    2424# 
    2525# $Log$ 
     26# Revision 1.7  2004/05/07 23:08:21  jalet 
     27# Skeleton for PCLXL aka PCL6 
     28# Added the "potential" fix for rastertoprinter's output 
     29# 
    2630# Revision 1.6  2004/05/06 21:19:27  jalet 
    2731# Doesn't exit anymore on the first nul byte 
     
    6367        return 0 
    6468     
     69def ispcl(data) :     
     70    """Returns 1 if data is PCL, else 0.""" 
     71    if data.startswith("\033E\033") or \ 
     72       ((data[:128].find("\033%-12345X") != -1) and \ 
     73         ((data.find("LANGUAGE=PCL") != -1) or \ 
     74          (data.find("LANGUAGE = PCL") != -1) or \ 
     75          (data.find("LANGUAGE = Pcl") != -1))) : 
     76        return 1 
     77    else :     
     78        return 0 
     79     
     80def ispclxl(data) :     
     81    """Returns 1 if data is PCLXL aka PCL6, else 0.""" 
     82    if ((data[:128].find("\033%-12345X") != -1) and \ 
     83         (data.find(" HP-PCL XL;") != -1) and \ 
     84         ((data.find("LANGUAGE=PCLXL") != -1) or \ 
     85          (data.find("LANGUAGE = PCLXL") != -1))) : 
     86        return 1 
     87    else :     
     88        return 0 
     89     
    6590def postscript(infile) : 
    66     """Count pages in a PostScript document.""" 
     91    """Count pages in a DSC compliant PostScript document.""" 
    6792    pagecount = 0 
    6893    pagenum = None 
     
    75100    return pagecount 
    76101     
    77 def ispcl(data) :     
    78     """Returns 1 if data is PCL, else 0.""" 
    79     if data.startswith("\033E\033") or \ 
    80        ((data[:128].find("\033%-12345X") != -1) and \ 
    81          ((data.find("LANGUAGE=PCL") != -1) or \ 
    82           (data.find("LANGUAGE = PCL") != -1) or \ 
    83           (data.find("LANGUAGE = Pcl") != -1))) : 
    84         return 1 
    85     else :     
    86         return 0 
    87      
    88102def pcl(infile) :     
    89     """Count pages in a PostScript document.""" 
     103    """Count pages in a PCL5 document.""" 
    90104    # 
    91105    # Algorithm from pclcount 
     
    118132                 "&l" : "X" }  
    119133    copies = 1 
    120     pagecount = 0 
     134    pagecount = resets = 0 
    121135    tag = None 
    122136    position = 0 
     
    149163            position += 1 
    150164            if tagstart in "E9=YZ" : # one byte PCL tag 
     165                if tagstart == "E" : 
     166                    resets += 1 
    151167                continue             # skip to next tag 
    152168            tag = tagstart + infile[position] 
     
    177193                            size += 1 
    178194                        position += size     
    179     return copies * pagecount         
    180  
     195                         
     196    # if pagecount is still 0, we will return the number 
     197    # of resets instead of the number of form feed characters. 
     198    # but the number of resets is always at least 2 with a valid 
     199    # pcl file : one at the very start and one at the very end 
     200    # of the job's data. So we substract 2 from the number of 
     201    # resets. And since on our test data we needed to substract 
     202    # 1 more, we finally substract 3, and will test several 
     203    # PCL files with this. If resets < 2, then the file is 
     204    # probably not a valid PCL file, so we return 0 
     205    if not pagecount : 
     206        return copies * (resets - 3) * (resets > 2) 
     207    else : 
     208        return copies * pagecount 
     209 
     210def pclxl(infile) :      
     211    """Count pages in a PCL6 aka PCLXL document.""" 
     212    raise TypeError, "Sorry but PCL6, aka PCLXL, is not supported yet.\n" 
     213     
    181214def smartpagecounter(filename) : 
    182215    """Autodetects file format and returns number of pages.""" 
     
    202235    if ispostscript(firstblock) : 
    203236        size = postscript(infile) 
     237    elif ispclxl(firstblock) :     
     238        size = pclxl(infile) 
    204239    elif ispcl(firstblock) :     
    205240        size = pcl(infile)