Changeset 1461 for pykota/trunk
- Timestamp:
- 05/08/04 01:08:21 (21 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pkpgcounter
r1456 r1461 24 24 # 25 25 # $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 # 26 30 # Revision 1.6 2004/05/06 21:19:27 jalet 27 31 # Doesn't exit anymore on the first nul byte … … 63 67 return 0 64 68 69 def 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 80 def 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 65 90 def postscript(infile) : 66 """Count pages in a PostScript document."""91 """Count pages in a DSC compliant PostScript document.""" 67 92 pagecount = 0 68 93 pagenum = None … … 75 100 return pagecount 76 101 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 185 else :86 return 087 88 102 def pcl(infile) : 89 """Count pages in a P ostScriptdocument."""103 """Count pages in a PCL5 document.""" 90 104 # 91 105 # Algorithm from pclcount … … 118 132 "&l" : "X" } 119 133 copies = 1 120 pagecount = 0134 pagecount = resets = 0 121 135 tag = None 122 136 position = 0 … … 149 163 position += 1 150 164 if tagstart in "E9=YZ" : # one byte PCL tag 165 if tagstart == "E" : 166 resets += 1 151 167 continue # skip to next tag 152 168 tag = tagstart + infile[position] … … 177 193 size += 1 178 194 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 210 def 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 181 214 def smartpagecounter(filename) : 182 215 """Autodetects file format and returns number of pages.""" … … 202 235 if ispostscript(firstblock) : 203 236 size = postscript(infile) 237 elif ispclxl(firstblock) : 238 size = pclxl(infile) 204 239 elif ispcl(firstblock) : 205 240 size = pcl(infile)