1# -*- coding: utf-8 -*- 2# 3# (c) Copyright 2003-2015 HP Development Company, L.P. 4# 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 2 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program; if not, write to the Free Software 17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18# 19# Author: Don Welch 20# 21 22# Std Lib 23import struct 24 25# Local 26from base import pml 27from base.sixext import to_bytes_utf8 28 29ESC = to_bytes_utf8('\x1b') 30RESET = to_bytes_utf8('\x1bE') 31UEL = to_bytes_utf8('\x1b%-12345X') 32PJL_ENTER_LANG = to_bytes_utf8("@PJL ENTER LANGUAGE=PCL3GUI\n") 33PJL_BEGIN_JOB = to_bytes_utf8('@PJL JOB NAME="unnamed"\n') 34PJL_END_JOB = to_bytes_utf8('@PJL EOJ\n') 35 36def buildPCLCmd(punc, letter1, letter2, data=None, value=None): 37 if data is None: 38 return to_bytes_utf8('').join([ESC, to_bytes_utf8(punc), to_bytes_utf8(letter1), to_bytes_utf8(str(value)), to_bytes_utf8(letter2)]) 39 return to_bytes_utf8('').join([ESC, to_bytes_utf8(punc), to_bytes_utf8(letter1), to_bytes_utf8(str(len(data))), to_bytes_utf8(letter2), data]) 40 41 42def buildEmbeddedPML(pml): 43 return to_bytes_utf8('').join([UEL, PJL_ENTER_LANG, RESET, pml, RESET, UEL]) 44 45 46def buildEmbeddedPML2(pml): 47 return to_bytes_utf8('').join([RESET, UEL, PJL_BEGIN_JOB, PJL_ENTER_LANG, RESET, pml, RESET, PJL_END_JOB, RESET, UEL]) 48 49 50def buildDynamicCounter(counter): 51 #return ''.join([UEL, PJL_ENTER_LANG, ESC, '*o5W\xc0\x01', struct.pack(">I", counter)[1:], UEL]) 52 return to_bytes_utf8('').join([UEL, PJL_ENTER_LANG, ESC, b'*o5W\xc0\x01', struct.pack(">I", counter)[1:], PJL_END_JOB, UEL]) 53 54def buildRP(a, f, c, d, e): 55 return to_bytes_utf8('').join([b'\x00'*600, RESET, UEL, PJL_ENTER_LANG, buildPCLCmd('&', 'b', 'W', pml.buildEmbeddedPMLSetPacket('1.1.1.36', a + f + c + d + e, pml.TYPE_STRING)), RESET, UEL]) 56