Changeset 396 for pkpgcounter/trunk/pkpgpdls/newpcl345.py
- Timestamp:
- 09/08/06 13:44:32 (18 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/newpcl345.py
r395 r396 32 32 import pjl 33 33 34 FORMFEED = chr(12) 35 ESCAPE = chr(27) 34 NUL = chr(0x00) 35 FORMFEED = chr(0x0c) 36 ESCAPE = chr(0x1b) 37 ASCIILIMIT = chr(0x80) 36 38 37 39 class Parser(pdlparser.PDLParser) : … … 99 101 return False 100 102 101 def setPageDict(self, pages, number,attribute, value) :103 def setPageDict(self, attribute, value) : 102 104 """Initializes a page dictionnary.""" 103 dic = pages.setdefault(number, { "copies" : 1, "mediasource" : "Main", "mediasize" : "Default", "mediatype" : "Plain", "orientation" : "Portrait", "escaped" : "", "duplex": 0})105 dic = self.pages.setdefault(self.pagecount, { "copies" : 1, "mediasource" : "Main", "mediasize" : "Default", "mediatype" : "Plain", "orientation" : "Portrait", "escaped" : "", "duplex": 0}) 104 106 dic[attribute] = value 105 107 … … 107 109 """Reads a byte from the input stream.""" 108 110 tag = ord(self.minfile[self.pos]) 109 #self.logdebug("%08x ===> %02x" % (self.pos, tag)) 111 if tag == 0x0c : 112 self.logdebug("%08x ====> %02x %02x %02x %02x" % 113 (self.pos, 114 ord(self.minfile[self.pos-2]), 115 ord(self.minfile[self.pos-1]), 116 ord(self.minfile[self.pos-0]), 117 ord(self.minfile[self.pos+1]))) 110 118 self.pos += 1 111 119 return tag … … 113 121 def endPage(self) : 114 122 """Handle the FF marker.""" 115 self.logdebug("FORMFEED %i " % self.pagecount)123 self.logdebug("FORMFEED %i at %08x" % (self.pagecount, self.pos-1)) 116 124 self.pagecount += 1 117 125 … … 119 127 """Handles the ESC% sequence.""" 120 128 if self.minfile[self.pos : self.pos+7] == r"-12345X" : 121 self.logdebug("Generic ESCAPE sequence at %08x" % self.pos)129 #self.logdebug("Generic ESCAPE sequence at %08x" % self.pos) 122 130 self.pos += 7 131 buffer = [] 132 quotes = 0 133 char = chr(self.readByte()) 134 while ((char < ASCIILIMIT) or (quotes % 2)) and (char not in (FORMFEED, ESCAPE, NUL)) : 135 buffer.append(char) 136 if char == '"' : 137 quotes += 1 138 char = chr(self.readByte()) 139 self.setPageDict("escaped", "".join(buffer)) 140 #self.logdebug("ESCAPED : %s" % "".join(buffer)) 141 self.pos -= 1 # Adjust position 142 else : 143 while 1 : 144 (value, end) = self.getInteger() 145 if end == 'B' : 146 self.enterHPGL2() 147 while self.minfile[self.pos] != ESCAPE : 148 self.pos += 1 149 self.pos -= 1 150 return 151 elif end == 'A' : 152 self.exitHPGL2() 153 return 154 155 def enterHPGL2(self) : 156 """Enters HPGL2 mode.""" 157 self.logdebug("ENTERHPGL2 %08x" % self.pos) 158 self.hpgl2 = True 159 160 def exitHPGL2(self) : 161 """Exits HPGL2 mode.""" 162 self.logdebug("EXITHPGL2 %08x" % self.pos) 163 self.hpgl2 = False 123 164 124 165 def handleTag(self, tagtable) : … … 165 206 mediasource = self.mediasources.get(value, str(value)) 166 207 self.mediasourcesvalues.append(mediasource) 167 self.logdebug("MEDIASOURCE %s" % mediasource) 208 self.setPageDict("mediasource", mediasource) 209 #self.logdebug("MEDIASOURCE %s" % mediasource) 168 210 elif end in ('a', 'A') : 169 211 mediasize = self.mediasizes.get(value, str(value)) 170 212 self.mediasizesvalues.append(mediasize) 171 self.logdebug("MEDIASIZE %s" % mediasize) 213 self.setPageDict("mediasize", mediasize) 214 #self.logdebug("MEDIASIZE %s" % mediasize) 172 215 elif end in ('o', 'O') : 173 216 orientation = self.orientations.get(value, str(value)) 174 217 self.orientationsvalues.append(orientation) 175 self.logdebug("ORIENTATION %s" % orientation) 218 self.setPageDict("orientation", orientation) 219 #self.logdebug("ORIENTATION %s" % orientation) 176 220 elif end in ('m', 'M') : 177 221 mediatype = self.mediatypes.get(value, str(value)) 178 222 self.mediatypesvalues.append(mediatype) 179 self.logdebug("MEDIATYPE %s" % mediatype) 223 self.setPageDict("mediatype", mediatype) 224 #self.logdebug("MEDIATYPE %s" % mediatype) 180 225 elif end == 'X' : 181 226 self.copies.append(value) 182 self.logdebug("COPIES %i" % value) 227 self.setPageDict("copies", value) 228 #self.logdebug("COPIES %i" % value) 183 229 184 230 def escAmpa(self) : … … 189 235 return 190 236 if end == 'G' : 191 self.logdebug("BACKSIDES %i" % value)237 #self.logdebug("BACKSIDES %i" % value) 192 238 self.backsides.append(value) 239 self.setPageDict("duplex", value) 193 240 194 241 def escAmpb(self) : … … 272 319 elif end in ('B', 'C') : 273 320 #self.logdebug("EndGFX") 274 if notself.startgfx :275 self. logdebug("EndGFX found before StartGFX, ignored.")321 if self.startgfx : 322 self.endgfx.append(1) 276 323 else : 277 self.endgfx.append(1) 324 #self.logdebug("EndGFX found before StartGFX, ignored.") 325 pass 278 326 if end == 'A' and (0 <= value <= 3) : 279 327 #self.logdebug("StartGFX %i" % value) … … 303 351 while 1 : 304 352 char = chr(self.readByte()) 305 if char in ( ESCAPE, FORMFEED) :353 if char in (NUL, ESCAPE, FORMFEED, ASCIILIMIT) : 306 354 self.pos -= 1 # Adjust position 307 355 return (None, None) … … 315 363 else : 316 364 value = ((value or 0) * 10) + int(char) 365 366 def skipByte(self) : 367 """Skips a byte.""" 368 #self.logdebug("SKIPBYTE %08x ===> %02x" % (self.pos, ord(self.minfile[self.pos]))) 369 self.pos += 1 317 370 318 371 def getJobSize(self) : … … 336 389 infileno = self.infile.fileno() 337 390 self.minfile = minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED) 391 self.pages = {} 338 392 self.pagecount = 0 339 393 self.resets = 0 … … 346 400 self.startgfx = [] 347 401 self.endgfx = [] 402 self.hpgl2 = False 348 403 349 404 tags = [ lambda : None] * 256 350 405 tags[ord(FORMFEED)] = self.endPage 351 406 tags[ord(ESCAPE)] = self.escape 407 tags[ord(ASCIILIMIT)] = self.skipByte 352 408 353 409 self.esctags = [ lambda : None ] * 256