1 /**
2 * Copyright (c) 2003 Roberto Ragusa, Hin-Tak Leung
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 **/
24
25 #include <stdio.h>
26 #include "epl_job.h"
27
epl_page_header(EPL_job_info * epl_job_info)28 int epl_page_header(EPL_job_info *epl_job_info)
29 {
30 char temp_string[256];
31 char *ts;
32 char paper_code;
33 char stripe_size;
34 int bytes_per_row;
35 int hor_pixels;
36 int ver_pixels;
37 int stripes_per_page;
38 int copies;
39 int cust_paper_hor;
40 int cust_paper_ver;
41 int e;
42
43
44 #ifdef EPL_DEBUG
45 fprintf(stderr, "EPL page header\n");
46 #endif
47
48 /* Prepare parameters */
49
50 paper_code = (char)0xff; /* 0xff is custom size */
51 stripe_size = 64;
52 bytes_per_row = ((epl_job_info->pixel_h + 32 - 1) / 32) * 4;
53 hor_pixels = epl_job_info->pixel_h;
54 ver_pixels = epl_job_info->pixel_v;
55 stripes_per_page = (epl_job_info->pixel_v + stripe_size - 1) / stripe_size;
56 copies=1;
57 cust_paper_hor = epl_job_info->paper_size_mm_h;
58 cust_paper_ver = epl_job_info->paper_size_mm_v;
59
60
61 /* Create the string */
62
63 ts = temp_string;
64 if(epl_job_info->model == MODEL_5700L)
65 {
66 ts += sprintf(ts, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
67 0x02, 0x00,
68 paper_code,
69 stripe_size,
70 bytes_per_row >> 8, bytes_per_row,
71 0x00,
72 0x00,
73 0x00,
74 0x00,
75 ver_pixels >> 8, ver_pixels,
76 hor_pixels >> 8, hor_pixels,
77 stripes_per_page >> 8, stripes_per_page,
78 0xff, /* tray */
79 0x00,
80 copies,
81 0xff,
82 0xfe,
83 cust_paper_hor >> 8, cust_paper_hor,
84 cust_paper_ver >> 8, cust_paper_ver
85 );
86 }
87 else if(epl_job_info->model == MODEL_5800L
88 || epl_job_info->model == MODEL_5900L)
89 {
90 ts += sprintf(ts, "\x01d");
91 ts += sprintf(ts, "26eps{I");
92 ts += sprintf(ts, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
93 0x04,0x00,
94 paper_code,
95 stripe_size,
96 bytes_per_row >> 8, bytes_per_row,
97 0x00,
98 0x00,
99 0x00,
100 0x00,
101 ver_pixels >> 8, ver_pixels,
102 hor_pixels >> 8, hor_pixels,
103 stripes_per_page >> 8, stripes_per_page,
104 0x00, /* tray */
105 0x00,
106 copies,
107 0xff,
108 0xfe,
109 cust_paper_hor >> 8, cust_paper_hor,
110 cust_paper_ver >> 8, cust_paper_ver,
111 0x01
112 );
113 }
114
115 #ifdef EPL_DEBUG
116 fprintf(stderr, "Writing %s page header (%i bytes)\n",
117 printername[epl_job_info->model], ts - temp_string);
118 #endif
119 e = fwrite(temp_string, 1, ts - temp_string, epl_job_info->outfile);
120 if(e != ts - temp_string) return -1;
121
122 return 0;
123 }
124