Changeset 1677

Show
Ignore:
Timestamp:
08/22/04 10:25:33 (20 years ago)
Author:
jalet
Message:

Improved ESC/P2 miniparser thanks to Paulo Silva

Location:
pykota/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/CREDITS

    r1672 r1677  
    124124  - Alban Crequy - Revolution Linux 
    125125  - Johannes Laemmermann - German translation 
     126  - Paulo Silva - Improved ESC/P2 miniparser 
    126127 
    127128============================================================== 
  • pykota/trunk/pykota/pdlanalyzer.py

    r1676 r1677  
    2222# 
    2323# $Log$ 
     24# Revision 1.31  2004/08/22 08:25:33  jalet 
     25# Improved ESC/P2 miniparser thanks to Paulo Silva 
     26# 
    2427# Revision 1.30  2004/08/21 23:16:57  jalet 
    2528# First draft of ESC/P2 (mini-)parser. 
     
    225228    def getJobSize(self) :     
    226229        """Counts pages in an ESC/P2 document.""" 
    227         # typical new page marker is Carriage Return (with optional Line Feed) 
    228         # followed by Form Feed, followed by Escape character 
    229         marker1 = chr(13) + chr(12) + chr(27) 
    230         marker2 = chr(13) + chr(10) + chr(12) + chr(27) 
     230        # with GhostScript, at least, for each page there 
     231        # are two Reset Printer sequences (ESC + @) 
     232        marker = "\033@" 
    231233        pagecount = 0 
    232234        for line in self.infile.xreadlines() :  
    233             c = line.count(marker1) 
    234             if not c : 
    235                 c = line.count(marker2) 
    236             pagecount += c     
    237         return pagecount     
     235            pagecount += line.count(marker) 
     236        return int(pagecount / 2)        
    238237         
    239238class PCLAnalyzer : 
     
    709708    def isESCP2(self, data) :         
    710709        """Returns 1 if data is ESC/P2, else 0.""" 
    711         if (data[:2] == "\033@") or (data[:2] == "\033*") : 
     710        if data.startswith("\033@") or \ 
     711           data.startswith("\n\033@") : 
     712            #data.startswith("\033*") or  
    712713            return 1 
    713714        else :