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

Revision 3390, 24.8 kB (checked in by jerome, 16 years ago)

Added a small fix wrt problems reported by Roger Jochem.

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