Changeset 3436 for pkpgcounter/trunk/pkpgpdls/escp2.py
- Timestamp:
- 10/06/08 00:22:07 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/escp2.py
r3410 r3436 8 8 # the Free Software Foundation, either version 3 of the License, or 9 9 # (at your option) any later version. 10 # 10 # 11 11 # This program is distributed in the hope that it will be useful, 12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 # GNU General Public License for more details. 15 # 15 # 16 16 # You should have received a copy of the GNU General Public License 17 17 # along with this program. If not, see <http://www.gnu.org/licenses/>. … … 29 29 """A parser for ESC/P2 documents.""" 30 30 format = "ESC/P2" 31 def isValid(self) : 31 def isValid(self) : 32 32 """Returns True if data is ESC/P2, else False.""" 33 33 if self.firstblock.startswith("\033@") or \ … … 36 36 self.firstblock.startswith("\0\0\0\033\1@EJL") : # ESC/P Raster ??? Seen on Stylus Photo 1284 37 37 return True 38 else : 38 else : 39 39 return False 40 41 def getJobSize(self) : 40 41 def getJobSize(self) : 42 42 """Counts pages in an ESC/P2 document.""" 43 43 # with Gimpprint, at least, for each page there 44 44 # are two Reset Printer sequences (ESC + @) 45 45 marker1 = "\033@" 46 46 47 47 # with other software or printer driver, we 48 48 # may prefer to search for "\r\n\fESCAPE" … … 50 50 marker2r = "\r\f\033" 51 51 marker2rn = "\r\n\f\033" 52 52 53 53 # and ghostscript's stcolor for example seems to 54 54 # output ESC + @ + \f for each page plus one 55 55 marker3 = "\033@\f" 56 56 57 57 # while ghostscript's escp driver outputs instead 58 58 # \f + ESC + @ 59 59 marker4 = "\f\033@" 60 60 61 61 data = self.infile.read() 62 62 pagecount1 = data.count(marker1) … … 64 64 pagecount3 = data.count(marker3) 65 65 pagecount4 = data.count(marker4) 66 67 if pagecount2 : 66 67 if pagecount2 : 68 68 return pagecount2 69 elif pagecount3 > 1 : 69 elif pagecount3 > 1 : 70 70 return pagecount3 - 1 71 elif pagecount4 : 71 elif pagecount4 : 72 72 return pagecount4 73 else : 74 return int(pagecount1 / 2) 73 else : 74 return int(pagecount1 / 2)