Show
Ignore:
Timestamp:
12/09/07 14:32:54 (17 years ago)
Author:
jerome
Message:

Improved parser for pksm ghostscript device.

Files:
1 modified

Legend:

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

    r548 r551  
    3636           If it's impossible to find one we consider it's not plain text. 
    3737        """    
    38         if (self.firstblock[:2] in ("P1", "P2", "P3")) : 
     38        if (self.firstblock.split()[0] in ("P1", "P2", "P3")) : 
    3939            self.logdebug("DEBUG: Input file seems to be in the PNM (ascii) format.") 
    4040            self.marker = self.firstblock[:2] 
     
    4646        """Counts pages in a PNM (ascii) document.""" 
    4747        pagecount = 0 
     48        linecount = 0 
     49        divby = 1 
    4850        marker = self.marker 
    4951        for line in self.infile : 
     52            linecount += 1 
     53            if (linecount == 2) and (line.find("device=pksm") != -1) : 
     54                # Special case of cmyk map 
     55                divby = 4 
    5056            pagecount += line.split().count(marker) 
    51         return pagecount 
     57             
     58        if not (pagecount % divby) :     
     59            return pagecount // divby 
     60        else :     
     61            return pagecount