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

Revision 3578, 24.9 kB (checked in by jerome, 5 years ago)

Clarified dependency wrt PIL/Pillow.
Updated copyright years.
Regenerated manual page.

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