Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
// $Header: /cvsroot/html2ps/output.pcl.class.php,v 1.2 2006/06/25 13:55:39 Konstantin Exp $
3
 
4
define("ASCII_ESCAPE", chr(27));
5
 
6
class StreamString {
7
  var $_content;
8
 
9
  function StreamString() {
10
    $this->_content = "";
11
  }
12
 
13
  function write($string) {
14
    $this->_content .= $string;
15
  }
16
}
17
 
18
/**
19
 * There are  two forms of PCL escape  sequences: two-character escape
20
 * sequences and parameterized escape sequences.
21
 */
22
class PCLEscapeSequence {
23
  function output(&$stream) {
24
    $stream->write(ASCII_ESCAPE.$this->getSequenceString());
25
  }
26
}
27
 
28
/**
29
 * Two-character escape sequences have the following form:
30
 *
31
 * <Escape> X
32
 *
33
 * where  “X”  is  a  character  that  defines  the  operation  to  be
34
 * performed. “X” may be any character from the ASCII table within the
35
 * range 48-126 decimal (“0” through “~” - see Appendix A).
36
 */
37
class PCLEscapeGenericSimple {
38
  function getSequenceString() {
39
    return $this->_getEscapedCharacter();
40
  }
41
 
42
}
43
 
44
/**
45
 * Parameterized escape sequences have the following form:
46
 *
47
 * <Escape> X y z1 # z2 # z3 ... # Zn[data]
48
 *
49
 * where  y,  #,  zi (z1,  z2,  z3...)  and  [data] may  be  optional,
50
 * depending on the command.
51
 */
52
class PCLEscapeGenericParametric {
53
  function getSequenceString() {
54
    $result =
55
      $this->_getEscapedCharacter().
56
      $this->_getGroupCharacter();
57
    $groups = $this->_getGroups();
58
    $size = count($groups);
59
    for ($i=0; $i<$size-1; $i++) {
60
      $result .= $groups[$i]->getString();
61
    };
62
    $result .= $groups[$size-1]->getStringTerminate();
63
    return $result;
64
  }
65
}
66
 
67
class PCLEscapeGroup {
68
  var $_value;
69
  var $_character;
70
 
71
  function PCLEscapeGroup($char, $value) {
72
    $this->_character = $char;
73
    $this->_value     = $value;
74
  }
75
 
76
  function getString() {
77
    return $this->_value.$this->_character;
78
  }
79
 
80
  function getStringTerminate() {
81
    return $this->_value.strtoupper($this->_character);
82
  }
83
}
84
 
85
/**
86
 * Simple escape sequences
87
 */
88
 
89
/**
90
 * Printer Reset command
91
 *
92
 * Receipt  of the  Printer Reset  command restores  the  User Default
93
 * Environment, deletes  temporary fonts, macros,  user-defined symbol
94
 * sets and patterns.  It also prints any partial  pages of data which
95
 * may have been received.
96
 *
97
 * <Escape> E
98
 */
99
class PCLEscapeReset extends PCLEscapeGenericSimple {
100
  function _getEscapedCharacter() { return "E"; }
101
}
102
 
103
/**
104
 * The Universal  Exit Language (UEL)  command causes the  PCL printer
105
 * language to  shut down  and exit. Control  is then returned  to the
106
 * Printer Job Language  (PJL). Both PCL 5 and  HP-GL/2 recognize this
107
 * command.
108
 *
109
 * <Escape> % – 1 2 3 4 5 X
110
 *
111
 * Default = N/A
112
 * Range = –12345
113
 * This command performs the following actions:
114
 * .. Prints all data received before the Exit Language command.
115
 * .. Performs a printer reset (same effect as ? E).
116
 * .. Shuts down the PCL 5 printer language processor.
117
 * .. Turns control over to PJL.
118
 */
119
class PCLEscapeUEL extends PCLEscapeGenericParametric {
120
  function _getEscapedCharacter() { return "%"; }
121
  function _getGroupCharacter() { return ""; }
122
  function _getGroups() {
123
    return array(new PCLEscapeGroup('x',-12345));
124
  }
125
}
126
 
127
/**
128
 * The Number of Copies command designates the number of printed copies of each page.
129
 *
130
 * <Escape> & l # X
131
 *
132
 * # = Number of copies (1 to 32767 maximum)
133
 * Default = 1 (Configurable from control panel)
134
 * Range = 1-32767
135
 * (Values 32767 execute as 32767 values 1 are ignored.
136
 * Maximum number of copies=99 for LaserJet II, IIP, III, IIID, IIIP and earlier LaserJet printers.)
137
 *
138
 * This command can be received anywhere within a page and affects
139
 * the current page as well as subsequent pages.
140
 */
141
class PCLEscapeNumberOfCopies extends PCLEscapeGenericParametric {
142
  var $_number;
143
 
144
  function PCLEscapeNumberOfCopies($number) {
145
    $this->_number = $number;
146
  }
147
 
148
  function _getEscapedCharacter() { return "&"; }
149
  function _getGroupCharacter() { return "l"; }
150
  function _getGroups() {
151
    return array(new PCLEscapeGroup('x',$this->_number));
152
  }
153
}
154
 
155
/**
156
 * This command designates either  simplex or duplex printing mode for
157
 * duplex printers. Simplex mode prints an image on only one side of a
158
 * sheet (page). Duplex mode prints images on both sides of a sheet.
159
 *
160
 * ? & l # S
161
 *
162
 * # = 0 - Simplex
163
 * 1 - Duplex, Long-Edge Binding
164
 * 2 - Duplex, Short-Edge Binding
165
 * Default = 0
166
 * Range = 0-2 (Other values ignored)
167
 *
168
 * Long-Edge bound  duplexed pages are  bound along the length  of the
169
 * physical page (see Figure 4-2). Short-edge bound duplexed pages are
170
 * bound  along the  width  of  the physical  page  (see Figure  4-3).
171
 * Selecting long-edge binding usually  results in font rotation. This
172
 * may be a concern if available user memory is critical.
173
 */
174
define('PCL_DUPLEX');
175
 
176
class PCLEscapeSimplexDuplex extends PCLEscapeGenericParametric {
177
  var $_duplex;
178
 
179
  function PCLEscapeSimplexDuplex($duplex) {
180
    $this->_duplex = $duplex;
181
  }
182
 
183
  function _getEscapedCharacter() { return "&"; }
184
  function _getGroupCharacter() { return "l"; }
185
  function _getGroups() {
186
    return array(new PCLEscapeGroup('x',$this->_number));
187
  }
188
}
189
 
190
/**
191
 * Print Job
192
 *
193
 * Structure of a Typical Job
194
 * <Escape>%–12345X UEL Command (exit language)
195
 * <Escape>E Printer Reset Command.
196
 * Preamble Job Control Commands.
197
 * Page 1 Page Control Commands.
198
 * Data
199
 * Page 2 Page Control Commands.1
200
 * Data.
201
 * ...
202
 * Page n Page Control Commands.
203
 * Data.
204
 * <Escape>E Printer Reset Command.
205
 * <Escape>%–12345X UEL Command (exit language).
206
 */
207
class PCLPrintJob {
208
  function output(&$stream) {
209
    $uel = new PCLEscapeUEL();
210
    $reset  = new PCLEscapeReset();
211
 
212
    $uel->output($stream);
213
    $reset->output($stream);
214
    $this->_preamble->output($stream);
215
    foreach ($this->_pages as $page) {
216
      $page->output($stream);
217
    };
218
    $reset->output($stream);
219
    $uel->output($stream);
220
  }
221
}
222
 
223
class PCLPrintJobPreamble {
224
  function output(&$stream) {
225
    // TODO
226
  }
227
}
228
 
229
class PCLPrintJobPage {
230
  var $_control
231
  var $_data;
232
 
233
  function output(&$stream) {
234
    $this->_control->output($stream);
235
    $this->_data->output($stream);
236
  }
237
}
238
 
239
class OutputDriverPCL extends OutputDriverGeneric {
240
 
241
  /**
242
   * Standard output driver interface follows
243
   */
244
 
245
  function add_link($x, $y, $w, $h, $target) { /* N/A */ }
246
  function add_local_link($left, $top, $width, $height, $anchor) { /* N/A */ }
247
  function circle($x, $y, $r) { }
248
  function clip() {}
249
  function close() { die("Unoverridden 'close' method called in ".get_class($this)); }
250
  function closepath() {}
251
  function content_type() { die("Unoverridden 'content_type' method called in ".get_class($this));  }
252
  function dash($x, $y) { }
253
  function decoration($underline, $overline, $strikeout) { }
254
  function error_message() { die("Unoverridden 'error_message' method called in ".get_class($this)); }
255
 
256
  function field_multiline_text($x, $y, $w, $h, $value, $field_name) { /* N/A */ }
257
  function field_text($x, $y, $w, $h, $value, $field_name) { /* N/A */ }
258
  function field_password($x, $y, $w, $h, $value, $field_name) { /* N/A */ }
259
  function field_pushbutton($x, $y, $w, $h) { /* N/A */ }
260
  function field_pushbuttonimage($x, $y, $w, $h, $field_name, $value, $actionURL) { /* N/A */ }
261
  function field_pushbuttonreset($x, $y, $w, $h) { /* N/A */ }
262
  function field_pushbuttonsubmit($x, $y, $w, $h, $field_name, $value, $actionURL) { /* N/A */ }
263
  function field_checkbox($x, $y, $w, $h, $name, $value) { /* N/A */ }
264
  function field_radio($x, $y, $w, $h, $groupname, $value, $checked) { /* N/A */ }
265
  function field_select($x, $y, $w, $h, $name, $value, $options) { /* N/A */ }
266
 
267
  function fill() { }
268
  function font_ascender($name, $encoding) {}
269
  function font_descender($name, $encoding) {}
270
  function get_bottom() {}
271
  function image($image, $x, $y, $scale) {}
272
  function image_scaled($image, $x, $y, $scale_x, $scale_y) { }
273
  function image_ry($image, $x, $y, $height, $bottom, $ox, $oy, $scale) { }
274
  function image_rx($image, $x, $y, $width, $right, $ox, $oy, $scale) { }
275
  function image_rx_ry($image, $x, $y, $width, $height, $right, $bottom, $ox, $oy, $scale) { }
276
  function lineto($x, $y) { }
277
  function moveto($x, $y) { }
278
  function new_form($name) { /* N/A */ }
279
  function next_page() { /* N/A */ }
280
  function release() { }
281
  function restore() { }
282
  function save() { }
283
  function setfont($name, $encoding, $size) {}
284
  function setlinewidth($x) { }
285
  function setrgbcolor($r, $g, $b)  { }
286
  function set_watermark($text) { }
287
  function show_xy($text, $x, $y) {}
288
  function stringwidth($string, $name, $encoding, $size) { }
289
  function stroke() { }
290
}
291
?>