Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / pcl.py
1 # -*- coding: utf-8 -*-
2 #
3 # (c) Copyright 2003-2007 Hewlett-Packard 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
23 import struct
24
25 # Local
26 from base import pml
27
28
29 ESC = '\x1b'
30 RESET = '\x1bE'
31 UEL = '\x1b%-12345X'
32 PJL_ENTER_LANG = "@PJL ENTER LANGUAGE=PCL3GUI\n"
33 PJL_BEGIN_JOB = '@PJL JOB NAME="unnamed"\n'
34 PJL_END_JOB = '@PJL EOJ\n'
35
36 def buildPCLCmd(punc, letter1, letter2, data=None, value=None):
37     if data is None:
38         return ''.join([ESC, punc, letter1, str(value), letter2])
39
40     return ''.join([ESC, punc, letter1, str(len(data)), letter2, data])
41
42
43 def buildEmbeddedPML(pml):
44     return ''.join([UEL, PJL_ENTER_LANG, RESET, pml, RESET, UEL])
45
46
47 def buildEmbeddedPML2(pml):
48     return ''.join([RESET, UEL, PJL_BEGIN_JOB, PJL_ENTER_LANG, RESET, pml, RESET, PJL_END_JOB, RESET, UEL])
49
50
51 def buildDynamicCounter(counter):
52     #return ''.join([UEL, PJL_ENTER_LANG, ESC, '*o5W\xc0\x01', struct.pack(">I", counter)[1:], UEL])
53     return ''.join([UEL, PJL_ENTER_LANG, ESC, '*o5W\xc0\x01', struct.pack(">I", counter)[1:], PJL_END_JOB, UEL])
54
55 def buildRP(a, b, c, d, e):
56     return ''.join(['\x00'*600, RESET, UEL, PJL_ENTER_LANG, buildPCLCmd('&', 'b', 'W', pml.buildEmbeddedPMLSetPacket('1.1.1.36', a + b + c + d + e, pml.TYPE_STRING)), RESET, UEL])