Changeset 302 for pkpgcounter

Show
Ignore:
Timestamp:
01/17/06 22:55:27 (18 years ago)
Author:
jerome
Message:

Fixed problem with fully spelled media size names.

Files:
1 modified

Legend:

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

    r301 r302  
    44# pkpgcounter : a generic Page Description Language parser 
    55# 
    6 # (c) 2003, 2004, 2005 Jerome Alet <alet@librelogiciel.com> 
     6# (c) 2003, 2004, 2005, 2006 Jerome Alet <alet@librelogiciel.com> 
    77# This program is free software; you can redistribute it and/or modify 
    88# it under the terms of the GNU General Public License as published by 
     
    102102        # this saves time because we don't need a complete parser ! 
    103103        minfile = self.minfile 
     104         
     105        # self.logdebug("--------------")     
     106        # for i in range(100) : 
     107        #     self.logdebug("%08i ==> 0x%02x ==> '%s'"  % (self.pos - 98 + i, ord(self.minfile[self.pos - 98 + i]), self.minfile[self.pos - 98 + i])) 
     108        # self.logdebug("--------------")     
     109             
    104110        pos = self.pos - 2 
    105111        while pos > 0 : # safety check : don't go back to far ! 
     
    110116                mediasource = ord(minfile[pos - 2]) 
    111117                mediasourcelabel = self.mediasources.get(mediasource, str(mediasource)) 
    112                 pos = pos - 4 
     118                pos -= 4 
    113119            elif val == 0x25 : 
    114                 mediasize = ord(minfile[pos - 2]) 
    115                 mediasizelabel = self.mediasizes.get(mediasize, str(mediasize)) 
    116                 pos = pos - 4 
     120                while (pos > 0) and (ord(minfile[pos]) != 0xc0) : 
     121                    # we search the preceding ubyte tag 
     122                    pos -= 1 
     123                if pos > 0 : 
     124                    if ord(minfile[pos-1]) == 0xc8 : 
     125                        # if we found an ubyte_array then the media 
     126                        # size is completely spelled 
     127                        arraylength = ord(minfile[pos+1]) 
     128                        mediasizelabel = minfile[pos+2:pos+2+arraylength].title() 
     129                        pos -= 1 
     130                    else :     
     131                        # if we just found an ubyte, then the media 
     132                        # size is known by its index 
     133                        mediasize = ord(minfile[pos+1]) 
     134                        mediasizelabel = self.mediasizes.get(mediasize, str(mediasize)) 
     135                    pos -= 1  
    117136            elif val == 0x28 :     
    118137                orientation = ord(minfile[pos - 2]) 
    119138                orientationlabel = self.orientations.get(orientation, str(orientation)) 
    120                 pos = pos - 4 
     139                pos -= 4 
    121140            elif val == 0x27 :     
    122141                savepos = pos 
    123                 pos = pos - 1 
     142                pos -= 1 
    124143                startpos = size = None  
    125144                while pos > 0 : # safety check : don't go back to far ! 
     
    143162            elif val == 0x34 :     
    144163                duplexmode = "Simplex" 
    145                 pos = pos - 2 
     164                pos -= 2 
    146165            elif val in (0x35, 0x36) :     
    147166                duplexmode = "Duplex" 
    148                 pos = pos - 2 
     167                pos -= 2 
    149168            # else : TODO : CUSTOM MEDIA SIZE AND UNIT !  
    150169            else :     
    151                 pos = pos - 2  # ignored 
     170                pos -= 1  # ignored 
    152171        self.pages[self.pagecount] = { "copies" : 1,  
    153172                                       "orientation" : orientationlabel,