root / pkpgcounter / trunk / pkpgpdls / pcl345.py @ 3497

Revision 3495, 24.9 kB (checked in by jerome, 15 years ago)

Now correctly handles the <ESC>$b???W sequences.
IMPORTANT : a post-parsing adjustment was done for ImageRunner?
documents, which incremented the page count. This adjustment **might**
have been needed because of this bug. A new adjustment is now done for
ImageRunner? files, which decrements the page count instead. Seems to
work on the set of test files. Fixes #40.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
Line 
1# -*- coding: utf-8 -*-
2#
3# pkpgcounter : a generic Page Description Language parser
4#
5# (c) 2003-2009 Jerome Alet <alet@librelogiciel.com>
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18#
19# $Id$
20#
21
22"""This modules implements a page counter for PCL3/4/5 documents."""
23
24import sys
25import os
26import mmap
27from struct import unpack
28
29import pdlparser
30import pjl
31
32NUL = chr(0x00)
33LINEFEED = chr(0x0a)
34FORMFEED = chr(0x0c)
35ESCAPE = chr(0x1b)
36ASCIILIMIT = chr(0x80)
37
38class Parser(pdlparser.PDLParser) :
39    """A parser for PCL3, PCL4, PCL5 documents."""
40    totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(outfname)s" -',
41                       'pcl6 -sDEVICE=pswrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(outfname)s" -',
42                     ]
43    required = [ "pcl6", "gs" ]
44    format = "PCL3/4/5"
45    mediasizes = {  # ESC&l####A
46                    0 : "Default",
47                    1 : "Executive",
48                    2 : "Letter",
49                    3 : "Legal",
50                    6 : "Ledger",
51                    25 : "A5",
52                    26 : "A4",
53                    27 : "A3",
54                    45 : "JB5",
55                    46 : "JB4",
56                    71 : "HagakiPostcard",
57                    72 : "OufukuHagakiPostcard",
58                    80 : "MonarchEnvelope",
59                    81 : "COM10Envelope",
60                    90 : "DLEnvelope",
61                    91 : "C5Envelope",
62                    100 : "B5Envelope",
63                    101 : "Custom",
64                 }
65
66    mediasources = { # ESC&l####H
67                     0 : "Default",
68                     1 : "Main",
69                     2 : "Manual",
70                     3 : "ManualEnvelope",
71                     4 : "Alternate",
72                     5 : "OptionalLarge",
73                     6 : "EnvelopeFeeder",
74                     7 : "Auto",
75                     8 : "Tray1",
76                   }
77
78    orientations = { # ESC&l####O
79                     0 : "Portrait",
80                     1 : "Landscape",
81                     2 : "ReversePortrait",
82                     3 : "ReverseLandscape",
83                   }
84
85    mediatypes = { # ESC&l####M
86                     0 : "Plain",
87                     1 : "Bond",
88                     2 : "Special",
89                     3 : "Glossy",
90                     4 : "Transparent",
91                   }
92
93    def isValid(self) :
94        """Returns True if data is PCL3/4/5, else False."""
95        try :
96            pos = 0
97            while self.firstblock[pos] == chr(0) :
98                pos += 1
99        except IndexError :
100            return False
101        else :
102            firstblock = self.firstblock[pos:]
103            if firstblock.startswith("\033E\033") or \
104               firstblock.startswith("\033%1BBPIN;") or \
105               ((pos == 11000) and firstblock.startswith("\033")) or \
106               (firstblock.startswith("\033*rbC") and (not self.lastblock[-3:] == "\f\033@")) or \
107               firstblock.startswith("\033*rB\033") or \
108               firstblock.startswith("\033%8\033") or \
109               (firstblock.find("\033%-12345X") != -1) or \
110               (firstblock.find("@PJL ENTER LANGUAGE=PCL\012\015\033") != -1) or \
111               (firstblock.startswith(chr(0xcd)+chr(0xca)) and (firstblock.find("\033E\033") != -1)) :
112                return True
113            else :
114                return False
115
116    def setPageDict(self, attribute, value) :
117        """Initializes a page dictionnary."""
118        dic = self.pages.setdefault(self.pagecount, { "linescount" : 1,
119                                                      "copies" : 1,
120                                                      "mediasource" : "Main",
121                                                      "mediasize" : "Default",
122                                                      "mediatype" : "Plain",
123                                                      "orientation" : "Portrait",
124                                                      "escaped" : "",
125                                                      "duplex": 0 })
126        dic[attribute] = value
127
128    def readByte(self) :
129        """Reads a byte from the input stream."""
130        tag = ord(self.minfile[self.pos])
131        self.pos += 1
132        return tag
133
134    def endPage(self) :
135        """Handle the FF marker."""
136        #self.logdebug("FORMFEED %i at %08x" % (self.pagecount, self.pos-1))
137        if not self.hpgl2 :
138            # Increments page count only if we are not inside an HPGL2 block
139            self.pagecount += 1
140
141    def escPercent(self) :
142        """Handles the ESC% sequence."""
143        if self.minfile[self.pos : self.pos+7] == r"-12345X" :
144            #self.logdebug("Generic ESCAPE sequence at %08x" % self.pos)
145            self.pos += 7
146            buffer = []
147            quotes = 0
148            char = chr(self.readByte())
149            while ((char < ASCIILIMIT) or (quotes % 2)) and (char not in (FORMFEED, ESCAPE, NUL)) :
150                buffer.append(char)
151                if char == '"' :
152                    quotes += 1
153                char = chr(self.readByte())
154            self.setPageDict("escaped", "".join(buffer))
155            #self.logdebug("ESCAPED : %s" % "".join(buffer))
156            self.pos -= 1   # Adjust position
157        else :
158            while 1 :
159                (value, end) = self.getInteger()
160                if end == 'B' :
161                    self.enterHPGL2()
162                    while self.minfile[self.pos] != ESCAPE :
163                        self.pos += 1
164                    self.pos -= 1
165                    return
166                elif end == 'A' :
167                    self.exitHPGL2()
168                    return
169                elif end is None :
170                    return
171
172    def enterHPGL2(self) :
173        """Enters HPGL2 mode."""
174        #self.logdebug("ENTERHPGL2 %08x" % self.pos)
175        self.hpgl2 = True
176
177    def exitHPGL2(self) :
178        """Exits HPGL2 mode."""
179        #self.logdebug("EXITHPGL2 %08x" % self.pos)
180        self.hpgl2 = False
181
182    def handleTag(self, tagtable) :
183        """Handles tags."""
184        tagtable[self.readByte()]()
185
186    def escape(self) :
187        """Handles the ESC character."""
188        #self.logdebug("ESCAPE")
189        self.handleTag(self.esctags)
190
191    def escAmp(self) :
192        """Handles the ESC& sequence."""
193        #self.logdebug("AMP")
194        self.handleTag(self.escamptags)
195
196    def escDollar(self) :
197        """Handles the ESC$ sequence."""
198        #self.logdebug("DOLLAR")
199        self.handleTag(self.escdollartags)
200
201    def escStar(self) :
202        """Handles the ESC* sequence."""
203        #self.logdebug("STAR")
204        self.handleTag(self.escstartags)
205
206    def escLeftPar(self) :
207        """Handles the ESC( sequence."""
208        #self.logdebug("LEFTPAR")
209        self.handleTag(self.escleftpartags)
210
211    def escRightPar(self) :
212        """Handles the ESC( sequence."""
213        #self.logdebug("RIGHTPAR")
214        self.handleTag(self.escrightpartags)
215
216    def escE(self) :
217        """Handles the ESCE sequence."""
218        #self.logdebug("RESET")
219        self.resets += 1
220
221    def escAmpl(self) :
222        """Handles the ESC&l sequence."""
223        while 1 :
224            (value, end) = self.getInteger()
225            if value is None :
226                return
227            if end in ('h', 'H') :
228                mediasource = self.mediasources.get(value, str(value))
229                self.mediasourcesvalues.append(mediasource)
230                self.setPageDict("mediasource", mediasource)
231                #self.logdebug("MEDIASOURCE %s" % mediasource)
232            elif end in ('a', 'A') :
233                mediasize = self.mediasizes.get(value, str(value))
234                self.mediasizesvalues.append(mediasize)
235                self.setPageDict("mediasize", mediasize)
236                #self.logdebug("MEDIASIZE %s" % mediasize)
237            elif end in ('o', 'O') :
238                orientation = self.orientations.get(value, str(value))
239                self.orientationsvalues.append(orientation)
240                self.setPageDict("orientation", orientation)
241                #self.logdebug("ORIENTATION %s" % orientation)
242            elif end in ('m', 'M') :
243                mediatype = self.mediatypes.get(value, str(value))
244                self.mediatypesvalues.append(mediatype)
245                self.setPageDict("mediatype", mediatype)
246                #self.logdebug("MEDIATYPE %s" % mediatype)
247            elif end == 'X' :
248                self.copies.append(value)
249                self.setPageDict("copies", value)
250                #self.logdebug("COPIES %i" % value)
251            elif end == 'F' :
252                self.linesperpagevalues.append(value)
253                self.linesperpage = value
254                #self.logdebug("LINES PER PAGE : %i" % self.linesperpage)
255            #else :
256            #    self.logdebug("Unexpected end <%s> and value <%s>" % (end, value))
257
258    def escAmpa(self) :
259        """Handles the ESC&a sequence."""
260        while 1 :
261            (value, end) = self.getInteger()
262            if value is None :
263                return
264            if end == 'G' :
265                #self.logdebug("BACKSIDES %i" % value)
266                self.backsides.append(value)
267                self.setPageDict("duplex", value)
268
269    def escAmpp(self) :
270        """Handles the ESC&p sequence."""
271        while 1 :
272            (value, end) = self.getInteger()
273            if value is None :
274                return
275            if end == 'X' :
276                self.pos += value
277                #self.logdebug("SKIPTO %08x" % self.pos)
278
279    def escStarb(self) :
280        """Handles the ESC*b sequence."""
281        while 1 :
282            (value, end) = self.getInteger()
283            if (end is None) and (value is None) :
284                return
285            if end in ('V', 'W', 'v', 'w') :
286                self.pos += (value or 0)
287                #self.logdebug("SKIPTO %08x" % self.pos)
288
289    def escStarr(self) :
290        """Handles the ESC*r sequence."""
291        while 1 :
292            (value, end) = self.getInteger()
293            if value is None :
294                if end is None :
295                    return
296                elif end in ('B', 'C') :
297                    #self.logdebug("EndGFX")
298                    if self.startgfx :
299                        self.endgfx.append(1)
300                    else :
301                        #self.logdebug("EndGFX found before StartGFX, ignored.")
302                        pass
303            if end == 'A' and (0 <= value <= 3) :
304                #self.logdebug("StartGFX %i" % value)
305                self.startgfx.append(value)
306
307    def escStaroptAmpu(self) :
308        """Handles the ESC*o ESC*p ESC*t and ESC&u sequences."""
309        while 1 :
310            (value, end) = self.getInteger()
311            if value is None :
312                return
313
314    def escSkipSomethingW(self) :
315        """Handles the ESC???###W sequences."""
316        while 1 :
317            (value, end) = self.getInteger()
318            if value is None :
319                return
320            if end == 'W' :
321                self.pos += value
322                #self.logdebug("SKIPTO %08x" % self.pos)
323
324    def newLine(self) :
325        """Handles new lines markers."""
326        if not self.hpgl2 :
327            dic = self.pages.get(self.pagecount, None)
328            if dic is None :
329                self.setPageDict("linescount", 1)
330                dic = self.pages.get(self.pagecount)
331            nblines = dic["linescount"]
332            self.setPageDict("linescount", nblines + 1)
333            if (self.linesperpage is not None) \
334               and (dic["linescount"] > self.linesperpage) :
335                self.pagecount += 1
336
337    def getInteger(self) :
338        """Returns an integer value and the end character."""
339        sign = 1
340        value = None
341        while 1 :
342            char = chr(self.readByte())
343            if char in (NUL, ESCAPE, FORMFEED, ASCIILIMIT) :
344                self.pos -= 1 # Adjust position
345                return (None, None)
346            if char == '-' :
347                sign = -1
348            elif not char.isdigit() :
349                if value is not None :
350                    return (sign*value, char)
351                else :
352                    return (value, char)
353            else :
354                value = ((value or 0) * 10) + int(char)
355
356    def skipByte(self) :
357        """Skips a byte."""
358        #self.logdebug("SKIPBYTE %08x ===> %02x" % (self.pos, ord(self.minfile[self.pos])))
359        self.pos += 1
360
361    def handleImageRunner(self) :
362        """Handles Canon ImageRunner tags."""
363        tag = self.readByte()
364        if tag == ord(self.imagerunnermarker1[-1]) :
365            oldpos = self.pos-2
366            codop = self.minfile[self.pos:self.pos+2]
367            length = unpack(">H", self.minfile[self.pos+6:self.pos+8])[0]
368            self.pos += 18
369            if codop != self.imagerunnermarker2 :
370                self.pos += length
371            self.logdebug("ImageRunner tag : Skip %i bytes from 0x%08x to 0x%08x" % (self.pos-oldpos,
372                                                                                     oldpos,
373                                                                                     self.pos))
374        else :
375            self.pos -= 1 # Adjust position
376
377    def getJobSize(self) :
378        """Count pages in a PCL5 document.
379
380           Should also work for PCL3 and PCL4 documents.
381
382           Algorithm from pclcount
383           (c) 2003, by Eduardo Gielamo Oliveira & Rodolfo Broco Manin
384           published under the terms of the GNU General Public Licence v2.
385
386           Backported from C to Python by Jerome Alet, then enhanced
387           with more PCL tags detected. I think all the necessary PCL tags
388           are recognized to correctly handle PCL5 files wrt their number
389           of pages. The documentation used for this was :
390
391           HP PCL/PJL Reference Set
392           PCL5 Printer Language Technical Quick Reference Guide
393           http://h20000.www2.hp.com/bc/docs/support/SupportManual/bpl13205/bpl13205.pdf
394        """
395        infileno = self.infile.fileno()
396        self.minfile = minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED)
397        self.pages = {}
398        self.pagecount = 0
399        self.resets = 0
400        self.backsides = []
401        self.copies = []
402        self.mediasourcesvalues = []
403        self.mediasizesvalues = []
404        self.orientationsvalues = []
405        self.mediatypesvalues = []
406        self.linesperpagevalues = []
407        self.linesperpage = None
408        self.startgfx = []
409        self.endgfx = []
410        self.hpgl2 = False
411        self.imagerunnermarker1 = chr(0xcd) + chr(0xca) # Markers for Canon ImageRunner printers
412        self.imagerunnermarker2 = chr(0x10) + chr(0x02)
413        self.isimagerunner = (minfile[:2] == self.imagerunnermarker1)
414
415        tags = [ lambda : None] * 256
416        tags[ord(LINEFEED)] = self.newLine
417        tags[ord(FORMFEED)] = self.endPage
418        tags[ord(ESCAPE)] = self.escape
419        tags[ord(ASCIILIMIT)] = self.skipByte
420        tags[ord(self.imagerunnermarker1[0])] = self.handleImageRunner
421
422        self.esctags = [ lambda : None ] * 256
423        self.esctags[ord('%')] = self.escPercent
424        self.esctags[ord('*')] = self.escStar
425        self.esctags[ord('$')] = self.escDollar
426        self.esctags[ord('&')] = self.escAmp
427        self.esctags[ord('(')] = self.escLeftPar
428        self.esctags[ord(')')] = self.escRightPar
429        self.esctags[ord('E')] = self.escE
430
431        self.escamptags = [lambda : None ] * 256
432        self.escamptags[ord('a')] = self.escAmpa
433        self.escamptags[ord('l')] = self.escAmpl
434        self.escamptags[ord('p')] = self.escAmpp
435        self.escamptags[ord('b')] = self.escSkipSomethingW
436        self.escamptags[ord('n')] = self.escSkipSomethingW
437        self.escamptags[ord('u')] = self.escStaroptAmpu
438
439        self.escstartags = [ lambda : None ] * 256
440        self.escstartags[ord('b')] = self.escStarb
441        self.escstartags[ord('r')] = self.escStarr
442        self.escstartags[ord('o')] = self.escStaroptAmpu
443        self.escstartags[ord('p')] = self.escStaroptAmpu
444        self.escstartags[ord('t')] = self.escStaroptAmpu
445        self.escstartags[ord('c')] = self.escSkipSomethingW
446        self.escstartags[ord('g')] = self.escSkipSomethingW
447        self.escstartags[ord('i')] = self.escSkipSomethingW
448        self.escstartags[ord('l')] = self.escSkipSomethingW
449        self.escstartags[ord('m')] = self.escSkipSomethingW
450        self.escstartags[ord('v')] = self.escSkipSomethingW
451
452        self.escdollartags = [ lambda : None ] * 256
453        self.escdollartags[ord('b')] = self.escSkipSomethingW
454
455        self.escleftpartags = [ lambda : None ] * 256
456        self.escleftpartags[ord('s')] = self.escSkipSomethingW
457        self.escleftpartags[ord('f')] = self.escSkipSomethingW
458
459        self.escrightpartags = [ lambda : None ] * 256
460        self.escrightpartags[ord('s')] = self.escSkipSomethingW
461
462        self.pos = 0
463        try :
464            try :
465                while 1 :
466                    tags[self.readByte()]()
467            except IndexError : # EOF ?
468                pass
469        finally :
470            self.minfile.close()
471
472        self.logdebug("Pagecount : \t\t\t%i" % self.pagecount)
473        self.logdebug("Resets : \t\t\t%i" % self.resets)
474        self.logdebug("Copies : \t\t\t%s" % self.copies)
475        self.logdebug("NbCopiesMarks : \t\t%i" % len(self.copies))
476        self.logdebug("MediaTypes : \t\t\t%s" % self.mediatypesvalues)
477        self.logdebug("NbMediaTypes : \t\t\t%i" % len(self.mediatypesvalues))
478        self.logdebug("MediaSizes : \t\t\t%s" % self.mediasizesvalues)
479        nbmediasizes = len(self.mediasizesvalues)
480        self.logdebug("NbMediaSizes : \t\t\t%i" % nbmediasizes)
481        self.logdebug("MediaSources : \t\t\t%s" % self.mediasourcesvalues)
482        nbmediasourcesdefault = len([m for m in self.mediasourcesvalues if m == 'Default'])
483        nbmediasourcesnotdefault = len(self.mediasourcesvalues) - nbmediasourcesdefault
484        self.logdebug("MediaSourcesDefault : \t\t%i" % nbmediasourcesdefault)
485        self.logdebug("MediaSourcesNOTDefault : \t%i" % nbmediasourcesnotdefault)
486        self.logdebug("Orientations : \t\t\t%s" % self.orientationsvalues)
487        nborientations = len(self.orientationsvalues)
488        self.logdebug("NbOrientations : \t\t\t%i" % nborientations)
489        self.logdebug("StartGfx : \t\t\t%s" % len(self.startgfx))
490        self.logdebug("EndGfx : \t\t\t%s" % len(self.endgfx))
491        nbbacksides = len(self.backsides)
492        self.logdebug("BackSides : \t\t\t%s" % self.backsides)
493        self.logdebug("NbBackSides : \t\t\t%i" % nbbacksides)
494        self.logdebug("IsImageRunner : \t\t\t%s" % self.isimagerunner)
495
496#        if self.isimagerunner :
497#            self.logdebug("Adjusting PageCount : +1")
498#            self.pagecount += 1      # ImageRunner adjustment
499        if self.isimagerunner :
500            self.logdebug("Adjusting PageCount : -1")
501            self.pagecount -= 1      # ImageRunner adjustment
502        elif self.linesperpage is not None :
503            self.logdebug("Adjusting PageCount : +1")
504            self.pagecount += 1      # Adjusts for incomplete last page
505        elif len(self.startgfx) == len(self.endgfx) == 0 :
506            if self.resets % 2 :
507                if (not self.pagecount) and (nborientations < nbbacksides) :
508                    self.logdebug("Adjusting PageCount because of backsides : %i" % nbbacksides)
509                    self.pagecount = nbbacksides
510                elif nborientations == self.pagecount + 1 :
511                    self.logdebug("Adjusting PageCount : +1")
512                    self.pagecount += 1
513                elif (self.pagecount > 1) \
514                     and (nborientations == self.pagecount - 1) :
515                    self.logdebug("Adjusting PageCount : -1")
516                    self.pagecount -= 1
517        elif (self.pagecount > 1) \
518             and (self.resets == 2) \
519             and (not nbmediasourcesdefault) \
520             and (nbmediasourcesnotdefault == 1) :
521            self.logdebug("Adjusting PageCount : -1")
522            self.pagecount -= 1
523
524        self.pagecount = self.pagecount or nbmediasourcesdefault or nbmediasizes or nborientations or self.resets
525
526        if not self.pagecount :
527            if self.resets == len(self.startgfx) :
528                self.pagecount = self.resets
529
530        defaultpjlcopies = 1
531        defaultduplexmode = "Simplex"
532        defaultpapersize = ""
533        oldpjlcopies = -1
534        oldduplexmode = ""
535        oldpapersize = ""
536        for pnum in range(self.pagecount) :
537            # if no number of copies defined, take the preceding one else the one set before any page else 1.
538            page = self.pages.get(pnum, self.pages.get(pnum - 1, self.pages.get(0, { "copies" : 1, "mediasource" : "Main", "mediasize" : "Default", "mediatype" : "Plain", "orientation" : "Portrait", "escaped" : "", "duplex": 0})))
539            pjlstuff = page["escaped"]
540            if pjlstuff :
541                pjlparser = pjl.PJLParser(pjlstuff)
542                nbdefaultcopies = int(pjlparser.default_variables.get("COPIES", -1))
543                nbcopies = int(pjlparser.environment_variables.get("COPIES", -1))
544                nbdefaultqty = int(pjlparser.default_variables.get("QTY", -1))
545                nbqty = int(pjlparser.environment_variables.get("QTY", -1))
546                if nbdefaultcopies > -1 :
547                    defaultpjlcopies = nbdefaultcopies
548                if nbdefaultqty > -1 :
549                    defaultpjlcopies = nbdefaultqty
550                if nbcopies > -1 :
551                    pjlcopies = nbcopies
552                elif nbqty > -1 :
553                    pjlcopies = nbqty
554                else :
555                    if oldpjlcopies == -1 :
556                        pjlcopies = defaultpjlcopies
557                    else :
558                        pjlcopies = oldpjlcopies
559                if page["duplex"] :
560                    duplexmode = "Duplex"
561                else :
562                    defaultdm = pjlparser.default_variables.get("DUPLEX", "")
563                    if defaultdm :
564                        if defaultdm.upper() == "ON" :
565                            defaultduplexmode = "Duplex"
566                        else :
567                            defaultduplexmode = "Simplex"
568                    envdm = pjlparser.environment_variables.get("DUPLEX", "")
569                    if envdm :
570                        if envdm.upper() == "ON" :
571                            duplexmode = "Duplex"
572                        else :
573                            duplexmode = "Simplex"
574                    else :
575                        duplexmode = oldduplexmode or defaultduplexmode
576                defaultps = pjlparser.default_variables.get("PAPER", "")
577                if defaultps :
578                    defaultpapersize = defaultps
579                envps = pjlparser.environment_variables.get("PAPER", "")
580                if envps :
581                    papersize = envps
582                else :
583                    if not oldpapersize :
584                        papersize = defaultpapersize
585                    else :
586                        papersize = oldpapersize
587            else :
588                if oldpjlcopies == -1 :
589                    pjlcopies = defaultpjlcopies
590                else :
591                    pjlcopies = oldpjlcopies
592
593                duplexmode = (page["duplex"] and "Duplex") or oldduplexmode or defaultduplexmode
594                if not oldpapersize :
595                    papersize = defaultpapersize
596                else :
597                    papersize = oldpapersize
598                papersize = oldpapersize or page["mediasize"]
599            if page["mediasize"] != "Default" :
600                papersize = page["mediasize"]
601            if not duplexmode :
602                duplexmode = oldduplexmode or defaultduplexmode
603            oldpjlcopies = pjlcopies
604            oldduplexmode = duplexmode
605            oldpapersize = papersize
606            copies = max(pjlcopies, page["copies"]) # Was : pjlcopies * page["copies"]
607            self.pagecount += (copies - 1)
608            self.logdebug("%s*%s*%s*%s*%s*%s*BW" % (copies, \
609                                              page["mediatype"], \
610                                              papersize, \
611                                              page["orientation"], \
612                                              page["mediasource"], \
613                                              duplexmode))
614
615        return self.pagecount
Note: See TracBrowser for help on using the browser.