Changeset 273 for pkpgcounter/trunk/pkpgpdls/postscript.py
- Timestamp:
- 10/07/05 23:36:57 (19 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/postscript.py
r272 r273 71 71 except OSError, msg : 72 72 raise pdlparser.PDLParserError, "Problem during analysis of Binary PostScript document : %s" % msg 73 self.logdebug("GhostScript said : %s pages" % pagecount) 73 74 return pagecount * self.copies 74 75 … … 77 78 self.infile.seek(0) 78 79 pagecount = 0 79 pages = {} 80 pages[0] = { "copies" : 1 } 80 self.pages = { 0 : { "copies" : 1 } } 81 81 oldpagenum = None 82 82 previousline = "" 83 notrust = 0 83 84 for line in self.infile.xreadlines() : 84 if line.startswith(r"%% Creator: PScript5.dll") :85 return 0 # Let this stuff be managed by GhostScript, since nup and copies disturb us.85 if line.startswith(r"%%BeginResource: procset pdf") : 86 notrust = 1 # Let this stuff be managed by GhostScript, but we still extract number of copies 86 87 elif line.startswith(r"%%Page: ") or line.startswith(r"(%%[Page: ") : 87 88 proceed = 1 … … 97 98 if proceed : 98 99 pagecount += 1 99 pages[pagecount] = { "copies" :pages[pagecount-1]["copies"] }100 self.pages[pagecount] = { "copies" : self.pages[pagecount-1]["copies"] } 100 101 elif line.startswith(r"%%Requirements: numcopies(") : 101 102 try : … … 104 105 pass 105 106 else : 106 if number > pages[pagecount]["copies"] :107 pages[pagecount]["copies"] = number107 if number > self.pages[pagecount]["copies"] : 108 self.pages[pagecount]["copies"] = number 108 109 elif line.startswith(r"%%BeginNonPPDFeature: NumCopies ") : 109 110 # handle # of copies set by some Windows printer driver … … 113 114 pass 114 115 else : 115 if number > pages[pagecount]["copies"] :116 pages[pagecount]["copies"] = number116 if number > self.pages[pagecount]["copies"] : 117 self.pages[pagecount]["copies"] = number 117 118 elif line.startswith("1 dict dup /NumCopies ") : 118 119 # handle # of copies set by mozilla/kprinter … … 122 123 pass 123 124 else : 124 if number > pages[pagecount]["copies"] :125 pages[pagecount]["copies"] = number125 if number > self.pages[pagecount]["copies"] : 126 self.pages[pagecount]["copies"] = number 126 127 elif line.startswith("/languagelevel where{pop languagelevel}{1}ifelse 2 ge{1 dict dup/NumCopies") : 127 128 try : … … 130 131 pass 131 132 else : 132 if number > pages[pagecount]["copies"] :133 pages[pagecount]["copies"] = number133 if number > self.pages[pagecount]["copies"] : 134 self.pages[pagecount]["copies"] = number 134 135 previousline = line 135 136 136 137 # extract max number of copies to please the ghostscript parser, just 137 138 # in case we will use it later 138 self.copies = max([ v["copies"] for (k, v) in pages.items() ])139 self.copies = max([ v["copies"] for (k, v) in self.pages.items() ]) 139 140 140 141 # now apply the number of copies to each page 141 142 for pnum in range(1, pagecount + 1) : 142 page = pages.get(pnum,pages.get(1, { "copies" : 1 }))143 page = self.pages.get(pnum, self.pages.get(1, { "copies" : 1 })) 143 144 copies = page["copies"] 144 145 pagecount += (copies - 1) 145 146 self.logdebug("%s * page #%s" % (copies, pnum)) 147 self.logdebug("Internal parser said : %s pages" % pagecount) 148 149 if notrust : 150 pagecount = 0 # Let gs do counting 146 151 return pagecount 147 152 … … 150 155 self.copies = 1 151 156 return self.natively() or self.throughGhostScript() 157 152 158 153 159 def test() :