Index: pkpgcounter/trunk/pkpgpdls/pclxl.py
===================================================================
--- pkpgcounter/trunk/pkpgpdls/pclxl.py (revision 478)
+++ pkpgcounter/trunk/pkpgpdls/pclxl.py (revision 479)
@@ -95,4 +95,5 @@
     def beginPage(self, nextpos) :
         """Indicates the beginning of a new page, and extracts media information."""
+        # self.logdebug("BeginPage at %x" % nextpos)
         self.pagecount += 1
         
@@ -181,4 +182,5 @@
     def endPage(self, nextpos) :    
         """Indicates the end of a page."""
+        # self.logdebug("EndPage at %x" % nextpos)
         pos3 = nextpos - 3
         minfile = self.minfile
@@ -199,5 +201,5 @@
         """Changes the color space."""
         if self.minfile[nextpos-4:nextpos-1] == self.RGBColorSpace : # TODO : doesn't seem to handle all cases !
-            self.iscolor = 1
+            self.iscolor = True
         return 0
             
@@ -224,6 +226,21 @@
         
     def array_32(self, nextpos) :
-        """Handles 32 bits arrays."""
-        return self.array_Generic(nextpos, 4)
+        """Handles 32 bits arrays and Canon ImageRunner tags."""
+        minfile = self.minfile
+        irtag = minfile[nextpos-1:nextpos+3]
+        if irtag in (self.imagerunnermarker1, self.imagerunnermarker2) :
+            # This is the beginning of a Canon ImageRunner tag
+            # self.logdebug("Canon ImageRunner tag at %x" % (nextpos-1))
+            codop = minfile[nextpos+1:nextpos+3]
+            length = unpack(">H", minfile[nextpos+7:nextpos+9])[0]
+            # self.logdebug("Canon ImageRunner block length=%04x" % length)
+            toskip = 19
+            if irtag != self.imagerunnermarker2 :
+                toskip += length
+            # self.logdebug("Canon ImageRunner skip until %x" % (nextpos+toskip))
+            return toskip    
+        else :
+            # This is a normal PCLXL array
+            return self.array_Generic(nextpos, 4)
         
     def embeddedDataSmall(self, nextpos) :
@@ -234,4 +251,17 @@
         """Handle normal amounts of data."""
         return 4 + unpack(self.unpackLong, self.minfile[nextpos:nextpos+4])[0]
+        
+    def skipHPPCLXL(self, nextpos) :    
+        """Skip the 'HP-PCL XL' statement if needed."""
+        minfile = self.minfile
+        if nextpos and (minfile[nextpos:nextpos+11] == " HP-PCL XL;") :
+            pos = nextpos
+            while minfile[pos] != '\n' :
+                pos += 1
+            length = (pos - nextpos + 1)    
+            # self.logdebug("Skip HP PCLXL statement until %x" % (nextpos + length))  
+            return length
+        else :    
+            return 0
         
     def littleEndian(self, nextpos) :
@@ -240,5 +270,6 @@
         self.unpackShort = self.unpackType[2]
         self.unpackLong = self.unpackType[4]
-        return 0
+        # self.logdebug("LittleEndian at %x" % (nextpos - 1))
+        return self.skipHPPCLXL(nextpos)
         
     def bigEndian(self, nextpos) :
@@ -247,5 +278,6 @@
         self.unpackShort = self.unpackType[2]
         self.unpackLong = self.unpackType[4]
-        return 0
+        # self.logdebug("BigEndian at %x" % (nextpos - 1))
+        return self.skipHPPCLXL(nextpos)
     
     def reservedForFutureUse(self, nextpos) :
@@ -335,5 +367,10 @@
            xl_refsup30r089.pdf
         """
-        self.iscolor = None
+        
+        infileno = self.infile.fileno()
+        self.minfile = minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED)
+        
+        self.iscolor = False
+        
         found = False
         while not found :
@@ -349,5 +386,5 @@
                 elif endian == 0x28 :    
                     self.bigEndian(0)
-                # elif endian == 0x27 : # TODO : This is the ESC code : parse it for PJL statements !
+                # elif endian == 0x27 : # TODO : This is the ASCII binding code : what does it do exactly ?
                 # 
                 else :    
@@ -446,5 +483,5 @@
         self.tags[0xcb] = self.array_16 # sint16_array
         self.tags[0xcc] = self.array_32 # sint32_array
-        self.tags[0xcd] = self.array_32 # real32_array
+        self.tags[0xcd] = self.array_32 # real32_array and unfortunately Canon ImageRunner
         
         self.tags[0xce] = self.reservedForFutureUse # reserved
@@ -525,5 +562,8 @@
                              }
                              
-        infileno = self.infile.fileno()
+        # Markers for Canon ImageRunner printers
+        self.imagerunnermarker1 = chr(0xcd) + chr(0xca) + chr(0x10) + chr(0x00)
+        self.imagerunnermarker2 = chr(0xcd) + chr(0xca) + chr(0x10) + chr(0x02)
+                             
         self.pages = { 0 : { "copies" : 1, 
                              "orientation" : "Default", 
@@ -534,5 +574,4 @@
                            } 
                      }      
-        self.minfile = minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED)
         tags = self.tags
         self.pagecount = 0
