Coverage Report

Created: 2025-04-22 06:20

/src/libspectre/ghostscript/contrib/eplaser/gdevescv.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) EPSON SOFTWARE DEVELOPMENT LABORATORY, INC. 1999,2000.
2
   Copyright (C) SEIKO EPSON CORPORATION 2000-2006,2009.
3
4
   Ghostscript printer driver for EPSON ESC/Page and ESC/Page-Color.
5
6
   This software is distributed in the hope that it will be useful, but
7
   WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
8
   to anyone for the consequences of using it or for whether it serves any
9
   particular purpose or works at all, unless he says so in writing.  Refer
10
   to the GNU General Public License for full details.
11
12
   Everyone is granted permission to copy, modify and redistribute
13
   this software, but only under the conditions described in the GNU
14
   General Public License.  A copy of this license is supposed to have been
15
   given to you along with this software so you can know your rights and
16
   responsibilities.  It should be in a file named COPYING.  Among other
17
   things, the copyright notice and this notice must be preserved on all
18
   copies.
19
20
 SPECIAL THANKS:
21
22
    本ドライバの作成にあたり、大森紀人さんの gdevlips, gdevl4v.c を参考に
23
    させて頂きました。
24
25
 NOTES:
26
27
  - About Ghostscript 5.10/5.50 BUGS
28
    Ghostscript 5.10/5.50 の Vector driver の setlinewidth 関数には
29
    バグがあります。本来スケールが変更されるにしたがって線の太さも変更され
30
    なければなりませんが、Ghostscript 5.10/5.50 ではスケールを考慮するのを
31
    忘れています。
32
    このドライバはそのバグを回避するためにスケールを自分で処理しています。
33
34
 */
35
36
#include <stdlib.h>   /* for abs() and free */
37
38
/* Get this definition in before we read memento.h */
39
static void
40
unvectored_free(void *x)
41
0
{
42
0
  free(x);
43
0
}
44
45
#if ( 6 > GS_VERSION_MAJOR )
46
47
#include <string.h>
48
#include <sys/utsname.h>  /* for uname(2) */
49
#include <ctype.h>    /* for toupper(3) */
50
51
#include "math_.h"
52
#include "gx.h"
53
#include "gserrors.h"
54
#include "gsmatrix.h"
55
#include "gsparam.h"
56
#include "gxdevice.h"
57
#include "gscspace.h"
58
#include "gsutil.h"
59
#include "gdevvec.h"
60
#include "gdevpstr.h"
61
#include "ghost.h"
62
#include "gzstate.h"
63
64
#include "gdevescv.h"
65
#include "gspath.h"
66
#include "gzpath.h"
67
68
#else /* 6 <= GS_VERSION_MAJOR */
69
70
#include "math_.h"
71
#include <sys/utsname.h>  /* for uname(2) */
72
#include <ctype.h>    /* for toupper(3) */
73
74
#include "time_.h"
75
#include "memory_.h"
76
#include "gx.h"
77
#include "gserrors.h"
78
#include "gzpath.h"
79
#include "gxdevice.h"
80
#include "gdevvec.h"
81
82
#if ( 7 >= GS_VERSION_MAJOR )
83
#include "gscspace.h"
84
#endif
85
86
#include "gdevescv.h"
87
88
#endif /* GS_VERSION_MAJOR */
89
90
0
#define ESCV_FORCEDRAWPATH 0  /* 0: correct LP-9200C path trouble. */
91
92
/* ---------------- Device definition ---------------- */
93
94
/* Device procedures */
95
static dev_proc_open_device(escv_open);
96
static dev_proc_output_page(escv_output_page);
97
static dev_proc_close_device(escv_close);
98
static dev_proc_copy_mono(escv_copy_mono);
99
static dev_proc_copy_color(escv_copy_color);
100
static dev_proc_put_params(escv_put_params);
101
static dev_proc_get_params(escv_get_params);
102
static dev_proc_fill_mask(escv_fill_mask);
103
static dev_proc_begin_image(escv_begin_image);
104
105
gs_public_st_suffix_add0_final(st_device_escv, gx_device_escv,
106
                               "gx_device_escv", device_escv_enum_ptrs, device_escv_reloc_ptrs,
107
                               gx_device_finalize, st_device_vector);
108
109
/* for ESC/Page-Color
110
** 原点の値を 0 とした場合,計算誤差?の問題から描画エリアが狂うため
111
** 原点を 0.001 としておく。
112
*/
113
#define escv_device_full_body(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, \
114
        ncomp, depth, mg, mc, dg, dc, lm, bm, rm, tm)\
115
        std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\
116
        dci_values(ncomp, depth, mg, mc, dg, dc),\
117
        std_device_part2_(w, h, xdpi, ydpi),\
118
        offset_margin_values(0.001, 0.001, lm, 0, 0, tm),\
119
        std_device_part3_()
120
121
/* for ESC/Page (Monochrome) */
122
#define esmv_device_full_body(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, \
123
        ncomp, depth, mg, mc, dg, dc, lm, bm, rm, tm)\
124
        std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\
125
        dci_values(ncomp, depth, mg, mc, dg, dc),\
126
        std_device_part2_(w, h, xdpi, ydpi),\
127
        offset_margin_values(-lm * xdpi / 72.0, -tm * ydpi / 72.0, 5.0 / (MMETER_PER_INCH / POINT),\
128
        0, 0, 5.0 / (MMETER_PER_INCH / POINT)), /* LPD.2.  041203 saito */\
129
        std_device_part3_()
130
131
/* for ESC/Page-Color */
132
#define escv_device_body(name)  \
133
  escv_device_full_body(gx_device_escv, 0, name, \
134
                                &st_device_escv,\
135
/* width & height */    ESCPAGE_DEFAULT_WIDTH, ESCPAGE_DEFAULT_HEIGHT,\
136
/* default resolution */  X_DPI, Y_DPI,\
137
/* color info */    3, 24, 255, 255, 256, 256,\
138
                                ESCPAGE_LEFT_MARGIN_DEFAULT,\
139
                                ESCPAGE_BOTTOM_MARGIN_DEFAULT,\
140
                                ESCPAGE_RIGHT_MARGIN_DEFAULT,\
141
                                ESCPAGE_TOP_MARGIN_DEFAULT)
142
143
/* for ESC/Page (Monochrome) */
144
#define esmv_device_body(name)  \
145
  esmv_device_full_body(gx_device_escv, 0, name, \
146
                                &st_device_escv,\
147
/* width & height */    ESCPAGE_DEFAULT_WIDTH, ESCPAGE_DEFAULT_HEIGHT,\
148
/* default resolution */  X_DPI, Y_DPI,\
149
/* color info */    1, 8, 255, 255, 256, 256,\
150
                                ESCPAGE_LEFT_MARGIN_DEFAULT,\
151
                                ESCPAGE_BOTTOM_MARGIN_DEFAULT,\
152
                                ESCPAGE_RIGHT_MARGIN_DEFAULT,\
153
                                ESCPAGE_TOP_MARGIN_DEFAULT)
154
155
#define escv_procs_part1 \
156
        escv_open,        /* open_device */\
157
        gx_default_get_initial_matrix,    /* get_initial_matrix */\
158
        NULL,         /* sync_output */\
159
        escv_output_page,     /* output_page */\
160
        escv_close        /* close_device */
161
162
#define escv_procs_part2 \
163
        gdev_vector_fill_rectangle,   /* fill_rectangle */\
164
        NULL,         /* tile_rectangle */\
165
        escv_copy_mono,       /* dev_t_proc_copy_mono */\
166
        escv_copy_color,      /* dev_t_proc_copy_color */\
167
        NULL,         /* draw_line */\
168
        NULL,         /* get_bits */\
169
        escv_get_params,      /* dev_t_proc_get_params */\
170
        escv_put_params,      /* dev_t_proc_put_params */\
171
        NULL,         /* map_cmyk_color */\
172
        NULL,         /* get_xfont_procs */\
173
        NULL,         /* get_xfont_device */\
174
        NULL,         /* map_rgb_alpha_color */\
175
        gx_page_device_get_page_device,   /* dev_t_proc_get_page_device */\
176
        NULL,         /* get_alpha_bits */\
177
        NULL,         /* copy_alpha */\
178
        NULL,         /* get_band */\
179
        NULL,         /* copy_rop */\
180
        gdev_vector_fill_path,      /* fill_path */\
181
        gdev_vector_stroke_path,    /* stroke_path */\
182
        escv_fill_mask,       /* fill_mask */\
183
        gdev_vector_fill_trapezoid,   /* fill_trapezoid */\
184
        gdev_vector_fill_parallelogram,   /* fill_parallelogram */\
185
        gdev_vector_fill_triangle,    /* fill_triangle */\
186
        NULL, /****** WRONG ******/   /* draw_thin_line */\
187
        escv_begin_image,     /* begin_image */\
188
        NULL,         /* image_data */\
189
        NULL,         /* end_image */\
190
        NULL,         /* strip_tile_rectangle */\
191
        NULL          /******strip_copy_rop******/
192
193
/* for ESC/Page-Color */
194
#define escv_procs  \
195
{\
196
        escv_procs_part1,\
197
        gx_default_rgb_map_rgb_color, /* map_rgb_color */\
198
        gx_default_rgb_map_color_rgb, /* map_color_rgb */\
199
        escv_procs_part2\
200
}
201
202
/* for ESC/Page (Monochrome) */
203
#define esmv_procs  \
204
{\
205
        escv_procs_part1,\
206
        gx_default_gray_map_rgb_color, /* map_rgb_color */\
207
        gx_default_gray_map_color_rgb, /* map_color_rgb */\
208
        escv_procs_part2\
209
}
210
211
#define escv_init_code_common \
212
        ESCPAGE_MANUALFEED_DEFAULT, /*   bool          manualFeed;     * Use manual feed *  */\
213
        ESCPAGE_CASSETFEED_DEFAULT, /*   int           cassetFeed;     * Input Casset *  */\
214
        ESCPAGE_RIT_DEFAULT,  /*   bool          RITOff;         * RIT Control * */\
215
        FALSE,      /*   bool          Collate; */\
216
        0,      /*   int           toner_density; */\
217
        FALSE,      /*   bool          toner_saving; */\
218
        0,      /*   int           prev_paper_size; */\
219
        0,      /*   int           prev_paper_width; */\
220
        0,      /*   int           prev_paper_height; */\
221
        0,      /*   int           prev_num_copies; */\
222
        -1,     /*   int           prev_feed_mode; */\
223
        0,      /*   int           orientation; */\
224
        ESCPAGE_FACEUP_DEFAULT, /*   bool          faceup; */\
225
        ESCPAGE_MEDIATYPE_DEFAULT, /*   int           MediaType; */\
226
        0,      /*   bool          first_page; */\
227
        0,      /*   bool          Duplex; */\
228
        ESCPAGE_TUMBLE_DEFAULT, /*   bool          Tumble; */\
229
        0,      /*   int           ncomp; */\
230
        0,      /*   int           MaskReverse; */\
231
        0,      /*   int           MaskState; */\
232
        TRUE,     /*   bool          c4map;          * 4bit ColorMap * */\
233
        TRUE,     /*   bool          c8map;          * 8bit ColorMap * */\
234
        0,      /*   int           prev_x; */\
235
        0,      /*   int           prev_y; */\
236
        0,      /*   gx_color_index        prev_color; */\
237
        0,      /*   gx_color_index        current_color; */\
238
        3,      /*   double        lwidth; */\
239
        0,      /*   long          cap; */\
240
        3,      /*   long          join; */\
241
        0,      /*   long          reverse_x; */\
242
        0,      /*   long          reverse_y; */\
243
       {0,},      /*   gs_matrix     xmat;    * matrix * */\
244
        0,      /*   int           bx; */\
245
        0,      /*   int           by; */\
246
        0,      /*   int           w;   * width * */\
247
        0,      /*   int           h;   * height * */\
248
        0,      /*   int           roll; */\
249
        0,      /*   float         sx;    * scale x * */\
250
        0,      /*   float         sy;    * scale y * */\
251
        0,      /*   long          dd; */\
252
        0,                      /*   int           ispath */\
253
       {0,},      /*   gx_bitmap_id  id_cache[VCACHE + 1];    * for Font Downloading * */\
254
       {0,},                    /*   char          JobID[ESCPAGE_JOBID_MAX + 1]; */\
255
       {0,},                    /*   char          UserName[ESCPAGE_USERNAME_MAX + 1]; */\
256
       {0,},                    /*   char          HostName[ESCPAGE_HOSTNAME_MAX + 1]; */\
257
       {0,},                    /*   char          Document[ESCPAGE_DOCUMENT_MAX + 1]; */\
258
       {0,},      /*   char          Comment[ESCPAGE_COMMENT_MAX + 1]; */\
259
       {0,0,0},                 /*  gs_param_string gpsJobID; */\
260
       {0,0,0},                 /*  gs_param_string gpsUserName; */\
261
       {0,0,0},                 /*  gs_param_string gpsHostName; */\
262
       {0,0,0},                 /*  gs_param_string gpsDocument; */\
263
       {0,0,0},                 /*  gs_param_string gpsComment; */\
264
       false,                   /*  bool            modelJP; */\
265
       false,                   /*  bool            capFaceUp; */\
266
       false,                   /*  bool            capDuplexUnit; */\
267
       RES600                   /*  int             capMaxResolution; */
268
269
/* for ESC/Page-Color */
270
#define escv_init_code \
271
        vector_initial_values,\
272
        1,                      /*   int           colormode;      1=ESC/Page-Color */\
273
        escv_init_code_common
274
275
/* for ESC/Page (Monochrome) */
276
#define esmv_init_code \
277
        vector_initial_values,\
278
        0,                      /*   int           colormode;      0=ESC/Page(Monochrome) */\
279
        escv_init_code_common
280
281
/* for ESC/Page (Monochrome) */
282
gx_device_escv far_data gs_epl2050_device ={esmv_device_body("epl2050"), esmv_procs, esmv_init_code};
283
gx_device_escv far_data gs_epl2050p_device={esmv_device_body("epl2050p"),esmv_procs, esmv_init_code};
284
gx_device_escv far_data gs_epl2120_device ={esmv_device_body("epl2120"), esmv_procs, esmv_init_code};
285
gx_device_escv far_data gs_epl2500_device ={esmv_device_body("epl2500"), esmv_procs, esmv_init_code};
286
gx_device_escv far_data gs_epl2750_device ={esmv_device_body("epl2750"), esmv_procs, esmv_init_code};
287
gx_device_escv far_data gs_epl5800_device ={esmv_device_body("epl5800"), esmv_procs, esmv_init_code};
288
gx_device_escv far_data gs_epl5900_device ={esmv_device_body("epl5900"), esmv_procs, esmv_init_code};
289
gx_device_escv far_data gs_epl6100_device ={esmv_device_body("epl6100"), esmv_procs, esmv_init_code};
290
gx_device_escv far_data gs_epl6200_device ={esmv_device_body("epl6200"), esmv_procs, esmv_init_code};
291
gx_device_escv far_data gs_lp1800_device  ={esmv_device_body("lp1800"),  esmv_procs, esmv_init_code};
292
gx_device_escv far_data gs_lp1900_device  ={esmv_device_body("lp1900"),  esmv_procs, esmv_init_code};
293
gx_device_escv far_data gs_lp2200_device  ={esmv_device_body("lp2200"),  esmv_procs, esmv_init_code};
294
gx_device_escv far_data gs_lp2400_device  ={esmv_device_body("lp2400"),  esmv_procs, esmv_init_code};
295
gx_device_escv far_data gs_lp2500_device  ={esmv_device_body("lp2500"),  esmv_procs, esmv_init_code};
296
gx_device_escv far_data gs_lp7500_device  ={esmv_device_body("lp7500"),  esmv_procs, esmv_init_code};
297
gx_device_escv far_data gs_lp7700_device  ={esmv_device_body("lp7700"),  esmv_procs, esmv_init_code};
298
gx_device_escv far_data gs_lp7900_device  ={esmv_device_body("lp7900"),  esmv_procs, esmv_init_code};
299
gx_device_escv far_data gs_lp8100_device  ={esmv_device_body("lp8100"),  esmv_procs, esmv_init_code};
300
gx_device_escv far_data gs_lp8300f_device ={esmv_device_body("lp8300f"), esmv_procs, esmv_init_code};
301
gx_device_escv far_data gs_lp8400f_device ={esmv_device_body("lp8400f"), esmv_procs, esmv_init_code};
302
gx_device_escv far_data gs_lp8600_device  ={esmv_device_body("lp8600"),  esmv_procs, esmv_init_code};
303
gx_device_escv far_data gs_lp8600f_device ={esmv_device_body("lp8600f"), esmv_procs, esmv_init_code};
304
gx_device_escv far_data gs_lp8700_device  ={esmv_device_body("lp8700"),  esmv_procs, esmv_init_code};
305
gx_device_escv far_data gs_lp8900_device  ={esmv_device_body("lp8900"),  esmv_procs, esmv_init_code};
306
gx_device_escv far_data gs_lp9000b_device ={esmv_device_body("lp9000b"), esmv_procs, esmv_init_code};
307
gx_device_escv far_data gs_lp9100_device  ={esmv_device_body("lp9100"),  esmv_procs, esmv_init_code};
308
gx_device_escv far_data gs_lp9200b_device ={esmv_device_body("lp9200b"), esmv_procs, esmv_init_code};
309
gx_device_escv far_data gs_lp9300_device  ={esmv_device_body("lp9300"),  esmv_procs, esmv_init_code};
310
gx_device_escv far_data gs_lp9400_device  ={esmv_device_body("lp9400"),  esmv_procs, esmv_init_code};
311
gx_device_escv far_data gs_lp9600_device  ={esmv_device_body("lp9600"),  esmv_procs, esmv_init_code};
312
gx_device_escv far_data gs_lp9600s_device ={esmv_device_body("lp9600s"), esmv_procs, esmv_init_code};
313
gx_device_escv far_data gs_lps4500_device ={esmv_device_body("lps4500"), esmv_procs, esmv_init_code};
314
gx_device_escv far_data gs_eplmono_device ={esmv_device_body(ESCPAGE_DEVICENAME_MONO), esmv_procs, esmv_init_code};
315
316
/* for ESC/Page-Color */
317
gx_device_escv far_data gs_alc1900_device ={escv_device_body("alc1900"), escv_procs, escv_init_code};
318
gx_device_escv far_data gs_alc2000_device ={escv_device_body("alc2000"), escv_procs, escv_init_code};
319
gx_device_escv far_data gs_alc4000_device ={escv_device_body("alc4000"), escv_procs, escv_init_code};
320
gx_device_escv far_data gs_alc4100_device ={escv_device_body("alc4100"), escv_procs, escv_init_code};
321
gx_device_escv far_data gs_alc8500_device ={escv_device_body("alc8500"), escv_procs, escv_init_code};
322
gx_device_escv far_data gs_alc8600_device ={escv_device_body("alc8600"), escv_procs, escv_init_code};
323
gx_device_escv far_data gs_alc9100_device ={escv_device_body("alc9100"), escv_procs, escv_init_code};
324
gx_device_escv far_data gs_lp3000c_device ={escv_device_body("lp3000c"), escv_procs, escv_init_code};
325
gx_device_escv far_data gs_lp8000c_device ={escv_device_body("lp8000c"), escv_procs, escv_init_code};
326
gx_device_escv far_data gs_lp8200c_device ={escv_device_body("lp8200c"), escv_procs, escv_init_code};
327
gx_device_escv far_data gs_lp8300c_device ={escv_device_body("lp8300c"), escv_procs, escv_init_code};
328
gx_device_escv far_data gs_lp8500c_device ={escv_device_body("lp8500c"), escv_procs, escv_init_code};
329
gx_device_escv far_data gs_lp8800c_device ={escv_device_body("lp8800c"), escv_procs, escv_init_code};
330
gx_device_escv far_data gs_lp9000c_device ={escv_device_body("lp9000c"), escv_procs, escv_init_code};
331
gx_device_escv far_data gs_lp9200c_device ={escv_device_body("lp9200c"), escv_procs, escv_init_code};
332
gx_device_escv far_data gs_lp9500c_device ={escv_device_body("lp9500c"), escv_procs, escv_init_code};
333
gx_device_escv far_data gs_lp9800c_device ={escv_device_body("lp9800c"), escv_procs, escv_init_code};
334
gx_device_escv far_data gs_lps6500_device ={escv_device_body("lps6500"), escv_procs, escv_init_code};
335
gx_device_escv far_data gs_eplcolor_device ={escv_device_body(ESCPAGE_DEVICENAME_COLOR), escv_procs, escv_init_code};
336
337
/* Vector device implementation */
338
#if ( 6 > GS_VERSION_MAJOR )
339
static int escv_beginpage(P1(gx_device_vector * vdev));
340
static int escv_setfillcolor(P2(gx_device_vector * vdev, const gx_drawing_color * pdc));
341
static int escv_setstrokecolor(P2(gx_device_vector * vdev, const gx_drawing_color * pdc));
342
static int escv_setdash(P4(gx_device_vector * vdev, const float *pattern,
343
                            uint count, double offset));
344
static int escv_setflat(P2(gx_device_vector * vdev, double flatness));
345
static int escv_setlogop(P3(gx_device_vector * vdev, gs_logical_operation_t lop,
346
                             gs_logical_operation_t diff));
347
static int escv_vector_dorect(gx_device_vector * vdev, fixed x0, fixed y0, fixed x1,
348
                               fixed y1, gx_path_type_t type);
349
static int escv_vector_dopath(gx_device_vector * vdev, const gx_path * ppath,
350
                               gx_path_type_t type);
351
static int escv_beginpath(P2(gx_device_vector * vdev, gx_path_type_t type));
352
static int escv_moveto(P6(gx_device_vector * vdev, double x0, double y0,
353
                           double x, double y, gx_path_type_t type));
354
static int escv_lineto(P6(gx_device_vector * vdev, double x0, double y0,
355
                           double x, double y, gx_path_type_t type));
356
static int escv_curveto(P10(gx_device_vector * vdev, double x0, double y0,
357
                             double x1, double y1, double x2, double y2,
358
                             double x3, double y3, gx_path_type_t type));
359
static int escv_closepath(P6(gx_device_vector * vdev, double x, double y,
360
                              double x_start, double y_start, gx_path_type_t type));
361
362
static int escv_endpath(P2(gx_device_vector * vdev, gx_path_type_t type));
363
static int escv_setlinewidth(gx_device_vector * vdev, double width);
364
static int escv_setlinecap(gx_device_vector * vdev, gs_line_cap cap);
365
static int escv_setlinejoin(gx_device_vector * vdev, gs_line_join join);
366
static int escv_setmiterlimit(gx_device_vector * vdev, double limit);
367
368
#else /* 6 <= GS_VERSION_MAJOR */
369
370
/* Page management */
371
static int escv_beginpage (gx_device_vector * vdev);
372
/* Imager state */
373
static int escv_setlinewidth (gx_device_vector * vdev, double width);
374
static int escv_setlinecap (gx_device_vector * vdev, gs_line_cap cap);
375
static int escv_setlinejoin (gx_device_vector * vdev, gs_line_join join);
376
static int escv_setmiterlimit (gx_device_vector * vdev, double limit);
377
static int escv_setdash (gx_device_vector * vdev, const float *pattern,
378
                          uint count, double offset);
379
static int escv_setflat (gx_device_vector * vdev, double flatness);
380
static int escv_setlogop (gx_device_vector * vdev, gs_logical_operation_t lop,
381
                           gs_logical_operation_t diff);
382
/* Other state */
383
#if ( 8 <= GS_VERSION_MAJOR )
384
static bool escv_can_handle_hl_color (gx_device_vector * vdev, const gs_gstate * pgs,
385
                                       const gx_drawing_color * pdc);
386
static int escv_setfillcolor (gx_device_vector * vdev, const gs_gstate * pgs,
387
                               const gx_drawing_color * pdc);
388
static int escv_setstrokecolor (gx_device_vector * vdev, const gs_gstate * pgs,
389
                                 const gx_drawing_color * pdc);
390
#else
391
static int escv_setfillcolor (gx_device_vector * vdev, const gx_drawing_color * pdc);
392
static int escv_setstrokecolor (gx_device_vector * vdev, const gx_drawing_color * pdc);
393
#endif
394
/* Paths */
395
/* dopath and dorect are normally defaulted */
396
static int escv_vector_dopath (gx_device_vector * vdev, const gx_path * ppath,
397
                                gx_path_type_t type, const gs_matrix *pmat);
398
static int escv_vector_dorect (gx_device_vector * vdev, fixed x0, fixed y0, fixed x1,
399
                                fixed y1, gx_path_type_t type);
400
static int escv_beginpath (gx_device_vector * vdev, gx_path_type_t type);
401
static int escv_moveto (gx_device_vector * vdev, double x0, double y0,
402
                         double x, double y, gx_path_type_t type);
403
static int escv_lineto (gx_device_vector * vdev, double x0, double y0,
404
                         double x, double y, gx_path_type_t type);
405
static int escv_curveto (gx_device_vector * vdev, double x0, double y0,
406
                          double x1, double y1, double x2, double y2,
407
                          double x3, double y3, gx_path_type_t type);
408
static int escv_closepath (gx_device_vector * vdev, double x0, double y0,
409
                            double x_start, double y_start, gx_path_type_t type);
410
static int escv_endpath (gx_device_vector * vdev, gx_path_type_t type);
411
412
#endif /* GS_VERSION_MAJOR */
413
414
static const gx_device_vector_procs escv_vector_procs =
415
  {
416
    /* Page management */
417
    escv_beginpage,
418
    /* Imager state */
419
    escv_setlinewidth,
420
    escv_setlinecap,
421
    escv_setlinejoin,
422
    escv_setmiterlimit,
423
    escv_setdash,
424
    escv_setflat,
425
    escv_setlogop,
426
    /* Other state */
427
#if ( 8 <= GS_VERSION_MAJOR )
428
    escv_can_handle_hl_color, /* add gs815 */
429
#endif
430
    escv_setfillcolor,  /* fill & stroke colors are the same */
431
    escv_setstrokecolor,
432
    /* Paths */
433
    escv_vector_dopath,
434
    escv_vector_dorect,
435
    escv_beginpath,
436
    escv_moveto,
437
    escv_lineto,
438
    escv_curveto,
439
    escv_closepath,
440
    escv_endpath
441
  };
442
443
static void escv_write_begin(gx_device *dev, int bits, int x, int y, int sw, int sh, int dw, int dh, int roll);
444
static void escv_write_data(gx_device *dev, int bits, byte *buf, int bsize, int w, int ras);
445
static void escv_write_end(gx_device *dev, int bits);
446
447
/* ---------------- Utilities ---------------- */
448
449
/* Put a string on a stream.
450
   This function is copy of `pputs' in gdevpstr.c */
451
static int
452
lputs(stream * s, const char *str)
453
0
{
454
0
  uint  len = strlen(str);
455
0
  uint  used;
456
0
  int   status;
457
458
0
  status = sputs(s, (const byte *)str, len, &used);
459
460
0
  return (status >= 0 && used == len ? 0 : EOF);
461
0
}
462
463
/* Write a string on a stream. */
464
static void
465
put_bytes(stream * s, const byte * data, uint count)
466
0
{
467
0
  uint used;
468
469
0
  sputs(s, data, count, &used);
470
0
}
471
472
static int
473
escv_range_check(gx_device * dev)
474
0
{
475
0
  int width = dev->MediaSize[0];
476
0
  int height = dev->MediaSize[1];
477
0
  int xdpi = dev->x_pixels_per_inch;
478
0
  int ydpi = dev->y_pixels_per_inch;
479
480
  /* Paper Size Check */
481
0
  if (width <= height) { /* portrait */
482
0
    if ((width < ESCPAGE_WIDTH_MIN ||
483
0
         width > ESCPAGE_WIDTH_MAX ||
484
0
         height < ESCPAGE_HEIGHT_MIN ||
485
0
         height > ESCPAGE_HEIGHT_MAX)) {
486
0
      return_error(gs_error_rangecheck);
487
0
    }
488
0
  } else {     /* landscape */
489
0
    if ((width < ESCPAGE_HEIGHT_MIN ||
490
0
         width > ESCPAGE_HEIGHT_MAX ||
491
0
         height < ESCPAGE_WIDTH_MIN ||
492
0
         height > ESCPAGE_WIDTH_MAX )) {
493
0
      return_error(gs_error_rangecheck);
494
0
    }
495
0
  }
496
497
  /* Resolution Check */
498
0
  if (xdpi != ydpi) {
499
0
    return_error(gs_error_rangecheck);
500
0
  }
501
502
0
  if ((xdpi < ESCPAGE_DPI_MIN ||
503
0
       xdpi > ESCPAGE_DPI_MAX)) {
504
0
    return_error(gs_error_rangecheck);
505
0
  }
506
507
0
  return 0;     /* pass */
508
0
}
509
510
/* ---------------- Vector device implementation ---------------- */
511
512
static int
513
escv_vector_dopath(gx_device_vector * vdev, const gx_path * ppath,
514
                   gx_path_type_t type
515
#if ( 6 <= GS_VERSION_MAJOR )
516
                   , const gs_matrix *pmat
517
#endif
518
                   )
519
0
{
520
0
  gx_device_escv *pdev = (gx_device_escv *) vdev;
521
0
  bool do_close = (type & gx_path_type_stroke) != 0;
522
0
  gs_fixed_rect rect;
523
0
  gs_point scale;
524
0
  double x_start = 0, y_start = 0;
525
0
  bool first = true;
526
0
  gs_path_enum cenum;
527
0
  int code;
528
529
0
  stream  *s = gdev_vector_stream(vdev);
530
0
  char  obuf[128];
531
532
0
  if (gx_path_is_rectangle(ppath, &rect))
533
0
    return (*vdev_proc(vdev, dorect)) (vdev, rect.p.x, rect.p.y, rect.q.x, rect.q.y, type);
534
0
  scale = vdev->scale;
535
0
  code = (*vdev_proc(vdev, beginpath)) (vdev, type);
536
0
  gx_path_enum_init(&cenum, ppath);
537
538
0
  for (;;) {
539
0
    double  x, y;
540
0
    fixed vs[6];
541
0
    int pe_op, cnt;
542
0
    const segment *pseg;
543
544
0
    pe_op = gx_path_enum_next(&cenum, (gs_fixed_point *) vs);
545
546
0
   sw:
547
0
    switch (pe_op) {
548
0
    case 0:   /* done */
549
0
      return (*vdev_proc(vdev, endpath)) (vdev, type);
550
551
0
    case gs_pe_moveto:
552
0
      x = fixed2float(vs[0]) / scale.x;
553
0
      y = fixed2float(vs[1]) / scale.y;
554
555
      /* サブパス開始命令 p1 */
556
0
      (void)gs_sprintf(obuf, ESC_GS "0;%d;%dmvpG", (int)x, (int)y);
557
0
      lputs(s, obuf);
558
559
0
      if (first)
560
0
        x_start = x, y_start = y, first = false;
561
0
      break;
562
563
0
    case gs_pe_lineto:
564
0
      cnt = 1;
565
0
      for (pseg = cenum.pseg; pseg != 0 && pseg->type == s_line; cnt++, pseg = pseg->next);
566
567
0
      (void)gs_sprintf(obuf, ESC_GS "0;%d", cnt);
568
0
      lputs(s, obuf);
569
570
0
      do {
571
0
        (void)gs_sprintf(obuf, ";%d;%d",
572
0
                         (int)(fixed2float(vs[0]) / scale.x),
573
0
                         (int)(fixed2float(vs[1]) / scale.y));
574
0
        lputs(s, obuf);
575
576
0
        pe_op = gx_path_enum_next(&cenum, (gs_fixed_point *) vs);
577
0
      } while (pe_op == gs_pe_lineto);
578
579
      /* パス・ポリライン命令 */
580
0
      lputs(s, "lnpG");
581
0
      pdev->ispath = 1;
582
583
0
      goto sw;
584
585
0
    case gs_pe_curveto:
586
0
      cnt = 1;
587
0
      for (pseg = cenum.pseg; pseg != 0 && pseg->type == s_curve; cnt++, pseg = pseg->next);
588
0
      (void)gs_sprintf(obuf, ESC_GS "0;%d", cnt * 3);
589
0
      lputs(s, obuf);
590
591
0
      do {
592
0
        (void)gs_sprintf(obuf, ";%d;%d;%d;%d;%d;%d",
593
0
                    (int)(fixed2float(vs[0]) / scale.x), (int)(fixed2float(vs[1]) / scale.y),
594
0
                    (int)(fixed2float(vs[2]) / scale.x), (int)(fixed2float(vs[3]) / scale.y),
595
0
                    (int)(fixed2float(vs[4]) / scale.x), (int)(fixed2float(vs[5]) / scale.y));
596
0
        lputs(s, obuf);
597
598
0
        pe_op = gx_path_enum_next(&cenum, (gs_fixed_point *) vs);
599
0
      } while (pe_op == gs_pe_curveto);
600
601
      /* ベジェ曲線 */
602
0
      lputs(s, "bzpG");
603
0
      pdev->ispath = 1;
604
605
0
      goto sw;
606
607
0
    case gs_pe_closepath:
608
0
      x = x_start, y = y_start;
609
0
      if (do_close) {
610
0
        lputs(s, ESC_GS "clpG");
611
0
        break;
612
0
      }
613
614
0
      pe_op = gx_path_enum_next(&cenum, (gs_fixed_point *) vs);
615
0
      if (pe_op != 0) {
616
0
        lputs(s, ESC_GS "clpG");
617
618
0
        if (code < 0)
619
0
          return code;
620
0
        goto sw;
621
0
      }
622
0
      return (*vdev_proc(vdev, endpath)) (vdev, type);
623
0
    default:    /* can't happen */
624
0
      return_error(gs_error_unknownerror);
625
0
    }
626
0
    if (code < 0)
627
0
      return code;
628
0
  }
629
0
}
630
631
static int
632
escv_vector_dorect(gx_device_vector * vdev, fixed x0, fixed y0, fixed x1,
633
                   fixed y1, gx_path_type_t type)
634
0
{
635
0
  gx_device_escv *pdev = (gx_device_escv *) vdev;
636
0
  int   code;
637
0
  char  obuf[128];
638
0
  gs_point  scale;
639
0
  stream  *s = gdev_vector_stream(vdev);
640
641
0
  code = (*vdev_proc(vdev, beginpath))(vdev, type);
642
0
  if (code < 0)
643
0
    return code;
644
645
0
  scale = vdev->scale;
646
647
0
  (void)gs_sprintf(obuf, ESC_GS "0;%d;%d;%d;%d;0;0rrpG",
648
0
                (int)(fixed2float(x0) / scale.x),
649
0
                (int)(fixed2float(y0) / scale.y),
650
0
                (int)(fixed2float(x1) / scale.x),
651
0
                (int)(fixed2float(y1) / scale.y));
652
0
  lputs(s, obuf);
653
0
  pdev->ispath = 1;
654
655
#if 0
656
  /* Ghostscript 側のバグで closepath を呼んでいないので処理を会わせる。 */
657
658
  /* 本来は (*vdev_proc(vdev, closepath))() を呼ぶべき */
659
  lputs(s, ESC_GS "clpG");
660
#endif
661
662
0
  return (*vdev_proc(vdev, endpath))(vdev, type);
663
0
}
664
665
/* ---------- */
666
667
static const EPaperTable ePaperTable[NUM_OF_PAPER_TABLES] =
668
  {
669
    {933, 1369, 72, "A3PLUS"},  /* A3 NOBI */
670
    {842, 1191, 13, "A3"},  /* A3 */
671
    {792, 1224, 36, "B"}, /* Ledger */
672
    {729, 1032, 24, "B4"},  /* B4 JIS */
673
    {709, 1001, 24, "B4"},  /* B4 */
674
    {612, 1008, 32, "LGL"}, /* Legal */
675
    {612,  936, 34, "GLG"}, /* Government Letter */ /* LPD.1. */
676
    {612,  792, 30, "LT"},  /* Letter */
677
    {595,  935, 37, "F4"},  /* F4 */
678
    {595,  842, 14, "A4"},  /* A4 */
679
    {576,  756, 35, "GLT"}, /* Government Legal */ /* LPD.1. */
680
    {522,  756, 33, "EXE"}, /* Executive */
681
    {516,  729, 25, "B5"},  /* B5 JIS */
682
    {499,  709, 99, "IB5"}, /* Envelope ISO B5 */
683
    {459,  649, 91, "C5"},  /* Envelope C5 */
684
    {420,  595, 15, "A5"},  /* A5 */
685
    {396,  612, 31, "HLT"}, /* Half Letter */
686
    {312,  624, 90, "DL"},  /* DL */
687
    {298,  666, 64, "YOU4"},  /* Japanese Envelope You4 */
688
    {297,  684, 81, "C10"}, /* Commercial 10 */
689
    {283,  420, 38, "POSTCARD"},/* PostCard */
690
    {279,  540, 80, "MON"}, /* Monarch */
691
    {  0,    0, -1, ""}   /* Undefined */
692
  };
693
694
static const EPaperTable *
695
escv_checkpapersize(gx_device_vector * vdev)
696
0
{
697
0
  gx_device_escv  *const pdev = (gx_device_escv *)vdev;
698
0
  int     devw, devh;
699
0
  paper_candidate candidate[NUM_OF_PAPER_TABLES];
700
0
  int     num_candidate;
701
702
0
  if (pdev->MediaSize[0] < pdev->MediaSize[1]) {
703
    /* portrait */
704
0
    devw = pdev->MediaSize[0];
705
0
    devh = pdev->MediaSize[1];
706
0
  } else {
707
    /* landscape */
708
0
    devw = pdev->MediaSize[1];
709
0
    devh = pdev->MediaSize[0];
710
0
  }
711
712
  /* pick up papersize candidate */
713
0
  {
714
0
    const EPaperTable *pt;
715
0
    int delta;
716
717
0
    num_candidate = 0;
718
719
0
    for (delta = 0; delta <= MAX_PAPER_SIZE_DELTA; delta++) {
720
0
      for (pt = ePaperTable; 0 <= pt->escpage; pt++) {
721
0
        if ( (pt->width  + delta) >= devw &&
722
0
             (pt->width  - delta) <= devw &&
723
0
             (pt->height + delta) >= devh &&
724
0
             (pt->height - delta) <= devh) {
725
726
0
          candidate[num_candidate].paper = pt;
727
0
          candidate[num_candidate].absw = abs(pt->width  - devw);
728
0
          candidate[num_candidate].absh = abs(pt->height - devh);
729
0
          candidate[num_candidate].score = 0;
730
0
          candidate[num_candidate].isfillw = false;
731
0
          candidate[num_candidate].isfillh = false;
732
0
          candidate[num_candidate].isminw  = false;
733
0
          candidate[num_candidate].isminh  = false;
734
735
0
          if( 0 <= (pt->width - devw) ){
736
0
            candidate[num_candidate].isfillw = true;
737
0
          }
738
0
          if( 0 <= (pt->height - devh) ){
739
0
            candidate[num_candidate].isfillh = true;
740
0
          }
741
0
          num_candidate++;
742
0
        }
743
0
      }
744
0
      if ( 0 < num_candidate ) {
745
0
        break;
746
0
      }
747
0
    }
748
0
  }
749
750
  /* no papersize match, so use default paper size */
751
0
  if ( 0 == num_candidate  ) {
752
0
    return (const EPaperTable *)0;    /* not found */
753
0
  }
754
755
0
  if ( 1 == num_candidate ) {
756
0
    return candidate[0].paper; /* find */
757
0
  }
758
759
  /* search abstruct minw & minh */
760
0
  {
761
0
    int absminw;
762
0
    int absminh;
763
0
    int i;
764
765
0
    absminw = candidate[0].absw;
766
0
    absminh = candidate[0].absh;
767
0
    for (i = 1; i < num_candidate; i++) {
768
0
      if (absminw > candidate[i].absw) {
769
0
        absminw = candidate[i].absw;
770
0
      }
771
0
      if (absminh > candidate[i].absh) {
772
0
        absminh = candidate[i].absh;
773
0
      }
774
0
    }
775
776
    /* check isminw & isminh flag */
777
0
    for (i = 0; i < num_candidate; i++) {
778
0
      if (absminw == candidate[i].absw) {
779
0
        candidate[i].isminw = true;
780
0
      }
781
0
      if (absminh == candidate[i].absh) {
782
0
        candidate[i].isminh = true;
783
0
      }
784
0
    }
785
786
    /* add score */
787
0
    for (i = 0; i < num_candidate; i++) {
788
0
      if (candidate[i].isminw == true) {
789
0
        candidate[i].score += 100;
790
0
      }
791
0
      if (candidate[i].isminh == true) {
792
0
        candidate[i].score += 100;
793
0
      }
794
0
      if (candidate[i].isfillw == true) {
795
0
        candidate[i].score += 10;
796
0
      }
797
0
      if (candidate[i].isfillh == true) {
798
0
        candidate[i].score += 10;
799
0
      }
800
0
      if (absminw < absminh) {
801
0
        if (candidate[i].isminw == true) {
802
0
          candidate[i].score += 1;
803
0
        }
804
0
      } else {
805
0
        if (candidate[i].isminh == true) {
806
0
          candidate[i].score += 1;
807
0
        }
808
0
      }
809
0
    }
810
0
  }
811
812
  /* select highest score papersize */
813
0
  {
814
0
    int best_candidate;
815
0
    int i;
816
817
0
    best_candidate = 0;
818
0
    for (i = 1; i < num_candidate; i++) {
819
0
      if ( candidate[best_candidate].score <= candidate[i].score ) {
820
0
        best_candidate = i;
821
0
      }
822
0
    }
823
0
    return candidate[best_candidate].paper;
824
0
  }
825
0
}
826
827
static char *
828
get_sysname ( void )
829
0
{
830
0
  char *result = NULL;
831
0
  struct utsname utsn;
832
833
0
  if (0 == uname (&utsn))
834
0
    {
835
0
      result = strdup (utsn.sysname);
836
0
    }
837
0
  return result;
838
0
}
839
840
/* EPSON printer model name translation.
841
  return: 0 unknown model, not translated.
842
          1 completed.
843
          -1 error.  ... This value not return now.
844
 */
845
static int
846
trans_modelname ( char *dest, const char * src, size_t dest_len )
847
0
{
848
0
  const char *cp = src;
849
850
0
  dest[0] = '\0';
851
852
0
  if ( 0 == strncmp( cp, "epl", 3 ) ) {
853
0
    strcat( dest, "EPSON EPL-" );
854
0
    cp = &cp[3];
855
0
  } else if ( 0 == strncmp( cp, "al", 2 ) ) {
856
0
    strcat( dest, "EPSON AL-" );
857
0
    cp = &cp[2];
858
0
  } else if ( 0 == strncmp( cp, "lp", 2 ) ) {
859
0
    strcat( dest, "EPSON LP-" );
860
0
    cp = &cp[2];
861
0
  } else {
862
0
    strncpy( dest, src, dest_len );
863
0
    dest[dest_len] = '\0';
864
0
    return 0;
865
0
  }
866
867
0
  {
868
0
    char * pdest = strchr( dest, '\0' );
869
0
    size_t len = strlen( dest );
870
871
0
    while ( ( len < (dest_len -1) ) && *cp && ( '_' != *cp) ) {
872
0
      *pdest = toupper( *cp );
873
0
      pdest++;
874
0
      cp++;
875
0
    }
876
0
    *pdest = '\0';
877
0
  }
878
879
0
  return 1;
880
0
}
881
882
static int
883
escv_beginpage(gx_device_vector * vdev)
884
0
{
885
0
  gx_device_escv  *const pdev = (gx_device_escv *)vdev;
886
887
0
  if (pdev -> first_page) {
888
889
    /* not use gdev_vector_stream */
890
0
    stream    *s = vdev->strm;
891
0
    char    ebuf[1024];
892
0
    int                 MaxRes;
893
0
    int                 Local;
894
0
    int                 Duplex;
895
0
    int                 FaceUp;
896
897
0
    const struct {
898
0
      const char *name;
899
0
      const int resolution;
900
0
      const int locale;
901
0
      const int duplex;
902
0
      const int faceup;
903
0
    } model_resource[] = {
904
      /* model, resolution, loca,deplex,faceup */
905
0
      { "alc1900", RES600,  ENG, TRUE,  FALSE },
906
0
      { "alc2000", RES600,  ENG, TRUE,  FALSE },
907
0
      { "alc4000", RES1200, ENG, TRUE,  FALSE },
908
0
      { "alc4100", RES600,  ENG, TRUE,  FALSE },
909
0
      { "alc8500", RES600,  ENG, TRUE,  TRUE },
910
0
      { "alc8600", RES600,  ENG, TRUE,  TRUE },
911
0
      { "alc9100", RES600,  ENG, TRUE,  TRUE },
912
0
      { "epl2050", RES1200, ENG, TRUE,  FALSE },
913
0
      { "epl2050p",RES1200, ENG, TRUE,  FALSE },
914
0
      { "epl2120", RES1200, ENG, TRUE,  FALSE },
915
0
      { "epl2500", RES600,  ENG, TRUE,  FALSE },
916
0
      { "epl2750", RES600,  ENG, TRUE,  FALSE },
917
0
      { "epl5800", RES1200, ENG, FALSE, FALSE },
918
0
      { "epl5900", RES1200, ENG, FALSE, FALSE },
919
0
      { "epl6100", RES1200, ENG, FALSE, FALSE },
920
0
      { "epl6200", RES1200, ENG, FALSE, FALSE },
921
0
      { "lp1800",  RES600,  JPN, FALSE, FALSE },
922
0
      { "lp1900",  RES1200, JPN, FALSE, FALSE },
923
0
      { "lp2200",  RES1200, JPN, FALSE, FALSE },
924
0
      { "lp2400",  RES1200, JPN, FALSE, FALSE },
925
0
      { "lp2500",  RES1200, JPN, FALSE, FALSE },
926
0
      { "lp3000c", RES600,  JPN, TRUE,  FALSE },
927
0
      { "lp7500",  RES600,  JPN, TRUE,  FALSE },
928
0
      { "lp7700",  RES600,  JPN, TRUE,  FALSE },
929
0
      { "lp7900",  RES600,  JPN, TRUE,  FALSE },
930
0
      { "lp8000c", RES600,  JPN, FALSE, TRUE },
931
0
      { "lp8100",  RES600,  JPN, TRUE,  FALSE },
932
0
      { "lp8200c", RES600,  JPN, FALSE, TRUE },
933
0
      { "lp8300c", RES600,  JPN, TRUE,  TRUE },
934
0
      { "lp8300f", RES600,  JPN, TRUE,  FALSE },
935
0
      { "lp8400f", RES600,  JPN, TRUE,  FALSE },
936
0
      { "lp8500c", RES600,  JPN, TRUE,  TRUE },
937
0
      { "lp8600",  RES600,  JPN, TRUE,  FALSE },
938
0
      { "lp8600f", RES600,  JPN, TRUE,  FALSE },
939
0
      { "lp8700",  RES1200, JPN, TRUE,  FALSE },
940
0
      { "lp8800c", RES600,  JPN, TRUE,  TRUE },
941
0
      { "lp8900",  RES600,  JPN, TRUE,  FALSE },
942
0
      { "lp9000b", RES600,  JPN, TRUE,  FALSE },
943
0
      { "lp9000c", RES600,  JPN, TRUE,  FALSE },
944
0
      { "lp9100",  RES600,  JPN, TRUE,  FALSE },
945
0
      { "lp9200b", RES600,  JPN, TRUE,  FALSE },
946
0
      { "lp9200c", RES600,  JPN, TRUE,  FALSE },
947
0
      { "lp9300",  RES600,  JPN, TRUE,  FALSE },
948
0
      { "lp9400",  RES600,  JPN, TRUE,  FALSE },
949
0
      { "lp9500c", RES600,  JPN, TRUE,  TRUE },
950
0
      { "lp9600",  RES600,  JPN, TRUE,  FALSE },
951
0
      { "lp9600s", RES600,  JPN, TRUE,  FALSE },
952
0
      { "lp9800c", RES600,  JPN, TRUE,  TRUE },
953
0
      { "lps4500", RES600,  JPN, TRUE,  FALSE },
954
0
      { "lps6500", RES600,  JPN, TRUE,  FALSE },
955
0
      { "",        -1,      -1,  FALSE, FALSE }
956
0
    };
957
958
    /* set default */
959
0
    MaxRes = RES600;
960
0
    Local  = JPN;
961
0
    Duplex = FALSE;
962
0
    FaceUp = FALSE;
963
964
0
    if ( !*pdev->JobID )
965
0
      strcpy(pdev->JobID, "0");
966
967
0
    lputs(s, "\033\001@EJL \012");
968
969
0
    lputs(s, "@EJL SJ ID=\"");
970
0
    lputs(s, pdev->JobID);
971
0
    lputs(s, "\"\012");
972
973
0
    lputs(s, "@EJL JI ID=\"");
974
0
    lputs(s, pdev->JobID);
975
0
    lputs(s, "\"");
976
977
0
    {
978
0
      time_t t;
979
980
#ifdef CLUSTER
981
      memset(&t, 0, sizeof(t));
982
#else
983
0
      time(&t);
984
0
#endif
985
986
0
      lputs(s, " DATE=\"");
987
0
      {
988
0
        struct tm *tm;
989
0
        char   str[32];
990
0
        size_t i;
991
992
#ifdef CLUSTER
993
        memset(&tm, 0, sizeof(tm));
994
        strcpy(str, "1970/01/01 00:00:00");
995
        i = strlen(str);
996
#else
997
0
        tm =  localtime( &t );
998
0
        i = strftime(str, 30, "%Y/%m/%d %H:%M:%S", tm);
999
0
#endif
1000
0
        if ( 30 >= i )
1001
0
          str[i] = '\0';
1002
1003
0
        lputs(s, str);
1004
0
      }
1005
0
      lputs(s, "\"");
1006
1007
0
      lputs(s, "\012");
1008
0
    }
1009
1010
0
    lputs(s, "@EJL JI");
1011
0
    {
1012
0
      lputs(s, " USER=\"");
1013
0
      if ( *pdev->UserName )
1014
0
        lputs(s, pdev->UserName);
1015
0
      lputs(s, "\"");
1016
1017
0
      lputs(s, " MACHINE=\"");
1018
0
      if ( *pdev->HostName )
1019
0
        lputs(s, pdev->HostName);
1020
0
      lputs(s, "\"");
1021
1022
0
      lputs(s, " DOCUMENT=\"");
1023
0
      if ( *pdev->Document )
1024
0
        lputs(s, pdev->Document);
1025
0
      lputs(s, "\"");
1026
0
    }
1027
0
    lputs(s, "\012");
1028
1029
0
    lputs(s, "@EJL JI OS=\"");
1030
0
    {
1031
0
      char *sysname = get_sysname ();
1032
0
      if (sysname)
1033
0
        {
1034
0
          lputs(s, sysname );
1035
          /* Carefully avoid memento interfering here. */
1036
0
          unvectored_free(sysname);
1037
0
          sysname = NULL;
1038
0
        }
1039
0
    }
1040
0
    lputs(s, "\"\012");
1041
1042
0
    if ( ( 0 == strcmp( pdev->dname, ESCPAGE_DEVICENAME_COLOR ) ) ||
1043
0
         ( 0 == strcmp( pdev->dname, ESCPAGE_DEVICENAME_MONO  ) ) )
1044
0
      {
1045
0
        Local = pdev->modelJP;
1046
0
        FaceUp = pdev->capFaceUp;
1047
0
        Duplex = pdev->capDuplexUnit;
1048
0
        MaxRes = pdev->capMaxResolution;
1049
1050
0
        lputs(s, "@EJL JI DRIVER=\"");
1051
0
        lputs(s, pdev->dname);
1052
0
        lputs(s, "\"\012");
1053
1054
0
        lputs(s, "@EJL JI PRINTER=\"");
1055
0
        lputs(s, pdev->dname);
1056
0
        lputs(s, "\"\012");
1057
1058
0
      } else {
1059
1060
0
      char _modelname[ ESCPAGE_MODELNAME_MAX + 1 ] = {0,};
1061
0
      const char *modelname;
1062
0
      int i;
1063
1064
0
      modelname = pdev->dname;
1065
1066
0
      for ( i = 0; (-1) != model_resource[i].resolution; i++ ) {
1067
0
        if ( 0 == strcmp( pdev->dname, model_resource[i].name ) )
1068
0
          break;
1069
0
      }
1070
1071
0
      lputs(s, "@EJL JI DRIVER=\"");
1072
0
      if ( (-1) != model_resource[i].resolution ) {
1073
0
        MaxRes = model_resource[i].resolution;
1074
0
        Local  = model_resource[i].locale;
1075
0
        Duplex = model_resource[i].duplex;
1076
0
        FaceUp = model_resource[i].faceup;
1077
1078
0
        if ( 0 <= trans_modelname( _modelname, model_resource[i].name, ESCPAGE_MODELNAME_MAX ) )
1079
0
            modelname = _modelname;
1080
1081
0
        lputs(s, modelname);
1082
0
      } else {
1083
0
        lputs(s, "Ghostscript");
1084
0
      }
1085
0
      lputs(s, "\"\012");
1086
1087
0
      lputs(s, "@EJL JI PRINTER=\"");
1088
0
      lputs(s, modelname);
1089
0
      lputs(s, "\"\012");
1090
0
    }
1091
1092
0
    if ( *pdev->Comment ) {
1093
0
      lputs(s, "@EJL CO ");
1094
0
      lputs(s, pdev->Comment );
1095
0
      lputs(s, "\012");
1096
0
    }
1097
1098
0
    lputs(s, "@EJL SE LA=ESC/PAGE\012");
1099
1100
0
    lputs(s, "@EJL SET");
1101
1102
    /* Resolusion */
1103
0
    if (vdev->x_pixels_per_inch == 1200){
1104
0
      if (MaxRes == 1200){
1105
0
        lputs(s, " RS=1200");
1106
0
      } else {
1107
0
        lputs(s, " RS=FN");
1108
0
      }
1109
0
    } else if (vdev->x_pixels_per_inch == 600) {
1110
0
      lputs(s, " RS=FN");
1111
0
    } else {
1112
0
      lputs(s, " RS=QK");
1113
0
    }
1114
1115
    /* Output Unit */
1116
0
    if ((pdev->faceup && FaceUp) || (pdev->MediaType && FaceUp)) {
1117
0
      lputs(s, " OU=FU");
1118
0
    } else {
1119
0
      lputs(s, " OU=FD");
1120
0
    }
1121
1122
    /* Paper unit */
1123
0
    if (pdev->MediaType){
1124
0
      if (Local == ENG){
1125
0
        lputs(s, " PU=1");
1126
0
      } else {
1127
0
        lputs(s, " PU=15");
1128
0
      }
1129
0
    }else{
1130
0
      if (pdev->manualFeed) {
1131
0
        if (Local == ENG){
1132
0
          lputs(s, " PU=1");
1133
0
        } else {
1134
0
          lputs(s, " PU=15");
1135
0
        }
1136
0
      } else if (pdev->cassetFeed) {
1137
0
        (void)gs_sprintf(ebuf, " PU=%d", pdev->cassetFeed);
1138
0
        lputs(s, ebuf);
1139
0
      } else {
1140
0
        lputs(s, " PU=AU");
1141
0
      }
1142
0
    }
1143
1144
0
    if (Duplex && pdev->Duplex) {
1145
      /* Duplex ON */
1146
0
      lputs(s, " DX=ON");
1147
1148
      /* binding type */
1149
0
      if (pdev->Tumble) {
1150
0
        lputs(s, " BD=SE");
1151
0
      } else {
1152
0
        lputs(s, " BD=LE");
1153
0
      }
1154
0
    } else {
1155
      /* Duplex off */
1156
0
      lputs(s, " DX=OFF");
1157
0
    }
1158
1159
    /* Number of copies */
1160
0
    if (pdev->NumCopies) {
1161
0
      if (pdev->NumCopies >= 1000) {
1162
0
        pdev->NumCopies = 999;
1163
0
      }
1164
1165
      /* lp8000c not have QT */
1166
0
      if (strcmp(pdev->dname, "lp8000c") == 0) {
1167
0
        (void)gs_sprintf(ebuf, " QT=1 CO=%d", pdev->NumCopies);
1168
0
      } else {
1169
0
        if (pdev->Collate) {
1170
          /* CO is 1, when set QT */
1171
0
          (void)gs_sprintf(ebuf, " QT=%d CO=1", pdev->NumCopies);
1172
0
        } else {
1173
          /* QT is 1, when not specified QT */
1174
0
          (void)gs_sprintf(ebuf, " QT=1 CO=%d", pdev->NumCopies);
1175
0
        }
1176
0
      }
1177
0
      lputs(s, ebuf);
1178
0
    } else {
1179
0
      lputs(s, " QT=1 CO=1");
1180
0
    }
1181
1182
0
    if (pdev->toner_density) {
1183
0
      (void)gs_sprintf(ebuf, " DL=%d", pdev->toner_density);
1184
0
      lputs(s, ebuf);
1185
0
    }
1186
1187
0
    if (pdev->orientation) {
1188
0
      lputs(s, " OR=LA");
1189
0
    }
1190
1191
0
    if (pdev->toner_saving) {
1192
0
      lputs(s, " SN=ON");
1193
0
    }
1194
1195
0
    if (pdev->RITOff) {
1196
0
      lputs(s, " RI=OFF");
1197
0
    } else {
1198
0
      lputs(s, " RI=ON");
1199
0
    }
1200
1201
0
    if        (pdev->MediaType == 0) { lputs(s, " PK=NM");
1202
0
    } else if (pdev->MediaType == 1) { lputs(s, " PK=TH");
1203
0
    } else if (pdev->MediaType == 2) { lputs(s, " PK=TR");
1204
0
    } else if (pdev->MediaType == 3) { lputs(s, " PK=TN");
1205
0
    } else if (pdev->MediaType == 4) { lputs(s, " PK=LH");
1206
0
    } else if (pdev->MediaType == 5) { lputs(s, " PK=CT");
1207
0
    } else if (pdev->MediaType == 6) { lputs(s, " PK=ET");
1208
0
    } else if (pdev->MediaType == 7) { lputs(s, " PK=HQ");
1209
0
    } else if (pdev->MediaType == 8) { lputs(s, " PK=UT");
1210
0
    } else if (pdev->MediaType == 9) { lputs(s, " PK=UM");
1211
0
    } else {
1212
0
      lputs(s, " PK=NM");
1213
0
    }
1214
1215
0
    lputs(s, " PS=");
1216
0
    {
1217
0
      const EPaperTable *pt;
1218
1219
0
      pt = escv_checkpapersize(vdev);
1220
0
      if ( 0 == pt ) {
1221
0
        lputs(s, "A4");
1222
0
      } else {
1223
0
        lputs(s, pt->name);
1224
0
      }
1225
0
    }
1226
1227
0
    if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
1228
1229
0
#define START_CODE1 ESC_GS "1tsE" ESC_GS "1owE" ESC_GS "0alfP" ESC_GS "0affP" ESC_GS "0;0;0clfP" ESC_GS "0pmP" ESC_GS "1024ibI" ESC_GS "2cmE" ESC_GS "0bcI" ESC_GS "1;10mlG"
1230
1231
0
#define STRAT_CODE  ESC_GS "1mmE" ESC_GS "1csE"
1232
1233
0
      lputs(s, " ZO=OFF EC=ON SZ=OFF SL=YES TO=0.0MM LO=0.0MM\012");
1234
0
      lputs(s, "@EJL EN LA=ESC/PAGE\012");
1235
1236
0
      lputs(s, ESC_GS "rhE");
1237
1238
0
      lputs(s, STRAT_CODE);
1239
1240
0
      if (vdev->x_pixels_per_inch == 1200) {
1241
        /* 1200 dpi */
1242
0
        lputs(s, ESC_GS "0;0.06muE");
1243
0
        lputs(s, ESC_GS "1;45;156htmE");
1244
0
        lputs(s, ESC_GS "9;1200;1200drE" ESC_GS "2;1200;1200drE" ESC_GS "1;1200;1200drE" ESC_GS "0;1200;1200drE");
1245
0
        lputs(s, ESC_GS "1;1;raE");
1246
0
      } else if (vdev->x_pixels_per_inch == 600) {
1247
        /* 600 dpi */
1248
0
        lputs(s, ESC_GS "0;0.12muE");
1249
0
        lputs(s, ESC_GS "1;45;106htmE");
1250
0
        lputs(s, ESC_GS "9;600;600drE" ESC_GS "2;600;600drE" ESC_GS "1;600;600drE" ESC_GS "0;600;600drE");
1251
0
      } else {
1252
        /* 300 dpi */
1253
0
        lputs(s, ESC_GS "0;0.24muE");
1254
0
        lputs(s, ESC_GS "1;45;71htmE");
1255
0
        lputs(s, ESC_GS "9;300;300drE" ESC_GS "2;300;300drE" ESC_GS "1;300;300drE" ESC_GS "0;300;300drE");
1256
0
      }
1257
1258
0
      lputs(s, START_CODE1);
1259
1260
0
      lputs(s, ESC_GS "0sarG");    /* 絶対座標指定 */
1261
      /*  lputs(s, ESC_GS "1owE");*/
1262
1263
0
    } else {     /* ESC/Page-Color */
1264
1265
0
#define COLOR_START_CODE1 ESC_GS "1tsE" ESC_GS "0alfP" ESC_GS "0affP" ESC_GS "0;0;0clfP" ESC_GS "0pmP" ESC_GS "1024ibI" ESC_GS "2cmE" ESC_GS "0bcI" ESC_GS "1;10mlG"
1266
1267
0
#define LP8000_CODE ESC_GS "0pddO" ESC_GS "0;0mmE" ESC_GS "2csE" ESC_GS "0;1;3cmmE" ESC_GS "0;1raE" ESC_GS "0;2;4ccmE"
1268
1269
0
#define LP8200_CODE ESC_GS "0pddO" ESC_GS "0;0cmmE" ESC_GS "1;2;3ccmE" ESC_GS "2;2;3ccmE" ESC_GS "3;2;4ccmE" ESC_GS "1;1raE" ESC_GS "2;1raE" ESC_GS "3;1raE"
1270
1271
0
      lputs(s, " ZO=OFF EC=ON SZ=OFF SL=YES TO=0 LO=0\012");
1272
0
      lputs(s, "@EJL EN LA=ESC/PAGE-COLOR\012");
1273
1274
0
      lputs(s, ESC_GS "rhE");
1275
1276
0
      if (strcmp(vdev -> dname, "lp8000c") == 0) {
1277
0
        lputs(s, LP8000_CODE);
1278
0
      } else {
1279
0
        lputs(s, LP8200_CODE);
1280
0
      }
1281
1282
0
      put_bytes(s, (const byte *)ESC_GS "7;0;2;0cam{E\012\000\000\000\000\000\000", 20);
1283
0
      lputs(s, ESC_GS "0;0cmmE");
1284
1285
0
      if (vdev->x_pixels_per_inch == 1200) {
1286
        /* 1200 dpi */
1287
0
        lputs(s, ESC_GS "0;0.06muE");
1288
0
        lputs(s, ESC_GS "3;1200;1200drE" ESC_GS "2;1200;1200drE" ESC_GS "1;1200;1200drE" ESC_GS "0;1200;1200drE");
1289
0
      } else if (vdev->x_pixels_per_inch == 600) {
1290
        /* 600 dpi */
1291
0
        lputs(s, ESC_GS "0;0.12muE");
1292
0
        lputs(s, ESC_GS "3;600;600drE" ESC_GS "2;600;600drE" ESC_GS "1;600;600drE" ESC_GS "0;600;600drE");
1293
0
      } else {
1294
        /* 300 dpi */
1295
0
        lputs(s, ESC_GS "0;0.24muE");
1296
0
        lputs(s, ESC_GS "3;300;300drE" ESC_GS "2;300;300drE" ESC_GS "1;300;300drE" ESC_GS "0;300;300drE");
1297
0
      }
1298
0
      lputs(s, ESC_GS "0;0loE");
1299
1300
/*    lputs(s, ESC_GS "0poE"); *//* for TEST */
1301
1302
0
      lputs(s, COLOR_START_CODE1);
1303
0
      lputs(s, ESC_GS "8;1;2;2;2plr{E");
1304
0
      put_bytes(s, (const byte *)"\377\377\377\377\000\000\000\000", 8);
1305
1306
0
      lputs(s, ESC_GS "0sarG");    /* 絶対座標指定 */
1307
0
      lputs(s, ESC_GS "2;204wfE");   /* rop 指定 */
1308
1309
0
    } /* ESC/Page-Color */
1310
1311
0
  }
1312
1313
0
  return 0;
1314
0
}
1315
1316
static int
1317
escv_setlinewidth(gx_device_vector * vdev, double width)
1318
0
{
1319
0
  stream      *s = gdev_vector_stream(vdev);
1320
0
  gx_device_escv *const pdev = (gx_device_escv *) vdev;
1321
0
  char      obuf[64];
1322
1323
#if GS_VERSION_MAJOR == 5
1324
  /* Scale を掛けているのは, Ghostscript 5.10/5.50 のバグのため */
1325
  double xscale, yscale;
1326
1327
  xscale = fabs(igs->ctm.xx);
1328
  yscale = fabs(igs->ctm.xy);
1329
1330
  if (xscale == 0 || yscale > xscale)   /* if portrait */
1331
    width = ceil(width * yscale);
1332
  else
1333
    width = ceil(width * xscale);
1334
#endif
1335
1336
0
  if (width < 1) width = 1;
1337
1338
  /* ESC/Page では線幅/終端/接合部の設定は1つのコマンドになっているため保持しておく。 */
1339
0
  pdev -> lwidth = width;
1340
1341
0
  (void)gs_sprintf(obuf, ESC_GS "%d;%d;%dlwG",
1342
0
                (int)(pdev -> lwidth),
1343
0
                (int)(pdev -> cap),
1344
0
                (int)(pdev -> join));
1345
0
  lputs(s, obuf);
1346
1347
0
  return 0;
1348
0
}
1349
1350
static int
1351
escv_setlinecap(gx_device_vector * vdev, gs_line_cap cap)
1352
0
{
1353
0
  stream      *s = gdev_vector_stream(vdev);
1354
0
  gx_device_escv *const pdev = (gx_device_escv *) vdev;
1355
0
  char      obuf[64];
1356
1357
  /* ESC/Page では線幅/終端/接合部の設定は1つのコマンドになっているため保持しておく。 */
1358
0
  pdev -> cap = cap;
1359
1360
0
  if (pdev -> cap >= 3) return -1;
1361
1362
0
  (void)gs_sprintf(obuf, ESC_GS "%d;%d;%dlwG",
1363
0
                (int)(pdev -> lwidth),
1364
0
                (int)(pdev -> cap),
1365
0
                (int)(pdev -> join));
1366
0
  lputs(s, obuf);
1367
1368
0
  return 0;
1369
0
}
1370
1371
static int
1372
escv_setlinejoin(gx_device_vector * vdev, gs_line_join join)
1373
0
{
1374
0
  stream      *s = gdev_vector_stream(vdev);
1375
0
  gx_device_escv *const pdev = (gx_device_escv *) vdev;
1376
0
  char      obuf[64];
1377
1378
  /* ESC/Page では線幅/終端/接合部の設定は1つのコマンドになっているため保持しておく。 */
1379
0
  switch (join) {
1380
0
  case 0:
1381
0
    pdev -> join = 3;   /* miter */
1382
0
    break;
1383
0
  case 1:
1384
0
    pdev -> join = 1;   /* round */
1385
0
    break;
1386
0
  case 2:
1387
0
    pdev -> join = 2;   /* bevel */
1388
0
    break;
1389
0
  default:
1390
0
    return -1;
1391
0
  }
1392
1393
0
  (void)gs_sprintf(obuf, ESC_GS "%d;%d;%dlwG",
1394
0
                (int)(pdev -> lwidth),
1395
0
                (int)(pdev -> cap),
1396
0
                (int)(pdev -> join));
1397
0
  lputs(s, obuf);
1398
1399
0
  return 0;
1400
0
}
1401
1402
static int
1403
escv_setmiterlimit(gx_device_vector * vdev, double limit)
1404
0
{
1405
0
  stream      *s = gdev_vector_stream(vdev);
1406
0
  gx_device_escv *const pdev = (gx_device_escv *) vdev;
1407
0
  char      obuf[128];
1408
1409
  /* マイターリミット値を設定するには lwG にて 接合部指定(n3) が 3 になっている
1410
  ** 必要がある。
1411
  */
1412
0
  if (pdev -> join != 3) {
1413
    /* 強制的に接合部指定を行う */
1414
0
    pdev -> join = 3;
1415
0
    (void)gs_sprintf(obuf, ESC_GS "%d;%d;%dlwG",
1416
0
                  (int)(pdev -> lwidth),
1417
0
                  (int)(pdev -> cap),
1418
0
                  (int)(pdev -> join));
1419
0
    lputs(s, obuf);
1420
0
  }
1421
1422
0
  (void)gs_sprintf(obuf, ESC_GS "1;%dmlG", (int)limit);
1423
0
  lputs(s, obuf);
1424
1425
0
  return 0;
1426
0
}
1427
1428
#if ( 8 <= GS_VERSION_MAJOR )
1429
static bool
1430
escv_can_handle_hl_color(gx_device_vector * vdev, const gs_gstate * pgs,
1431
                         const gx_drawing_color * pdc)
1432
0
{
1433
0
  return false;
1434
0
}
1435
#endif
1436
1437
static int
1438
escv_setfillcolor(gx_device_vector * vdev,
1439
#if ( 8 <= GS_VERSION_MAJOR )
1440
                  const gs_gstate * pgs,
1441
#endif
1442
                  const gx_drawing_color * pdc)
1443
0
{
1444
0
  stream      *s = gdev_vector_stream(vdev);
1445
0
  gx_device_escv *const pdev = (gx_device_escv *) vdev;
1446
0
  gx_color_index    color = gx_dc_pure_color(pdc);
1447
0
  char      obuf[64];
1448
1449
0
  if (!gx_dc_is_pure(pdc)) return_error(gs_error_rangecheck);
1450
0
  pdev->current_color = color;
1451
1452
0
  if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
1453
1454
0
    (void)gs_sprintf(obuf, /*ESC_GS "1owE"*/ ESC_GS "0;0;100spE" ESC_GS "1;0;%ldccE" ,color);
1455
0
    lputs(s, obuf);
1456
1457
0
    if (vdev->x_pixels_per_inch == 1200) {
1458
0
      lputs(s, ESC_GS "1;45;156htmE");
1459
0
    } else if (vdev->x_pixels_per_inch == 600) {
1460
0
      lputs(s, ESC_GS "1;45;106htmE");
1461
0
    } else {
1462
0
      lputs(s, ESC_GS "1;45;71htmE");
1463
0
    }
1464
1465
0
  } else {     /* ESC/Page-Color */
1466
1467
    /* パターンON指定/ソリッドパターン指定 */
1468
0
    (void)gs_sprintf(obuf, ESC_GS "1;2;3;%d;%d;%dfpE",
1469
0
                  (unsigned char)(color >> 16 & 0xff),
1470
0
                  (unsigned char)(color >> 8 & 0xff),
1471
0
                  (unsigned char)(color & 0xff));
1472
0
    lputs(s, obuf);
1473
0
    lputs(s, ESC_GS "3;2;1;0;0cpE" ESC_GS "1;2;1;0;0cpE" ESC_GS "5;2;1;0;0cpE");
1474
1475
0
  } /* ESC/Page-Color */
1476
1477
0
  return 0;
1478
0
}
1479
1480
static int
1481
escv_setstrokecolor(gx_device_vector * vdev,
1482
#if ( 8 <= GS_VERSION_MAJOR )
1483
                    const gs_gstate * pgs,
1484
#endif
1485
                    const gx_drawing_color * pdc)
1486
0
{
1487
0
  stream      *s = gdev_vector_stream(vdev);
1488
0
  gx_device_escv *const pdev = (gx_device_escv *) vdev;
1489
0
  gx_color_index    color = gx_dc_pure_color(pdc);
1490
0
  char      obuf[64];
1491
1492
0
  if (!gx_dc_is_pure(pdc)) return_error(gs_error_rangecheck);
1493
1494
0
  if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
1495
1496
0
    pdev->current_color = color;
1497
1498
0
    (void)gs_sprintf(obuf, /*ESC_GS "1owE"*/ ESC_GS "0;0;100spE" ESC_GS "1;1;%ldccE" , color);
1499
0
    lputs(s, obuf);
1500
1501
0
    if (vdev->x_pixels_per_inch == 1200) {
1502
0
      lputs(s, ESC_GS "1;45;156htmE");
1503
0
    } else if (vdev->x_pixels_per_inch == 600) {
1504
0
      lputs(s, ESC_GS "1;45;106htmE");
1505
0
    } else {
1506
0
      lputs(s, ESC_GS "1;45;71htmE");
1507
0
    }
1508
1509
0
  } else {     /* ESC/Page-Color */
1510
1511
0
    if (vdev->color_info.depth == 24) {
1512
1513
0
      pdev->current_color = color;
1514
      /* パターンON色指定/ソリッドパターン指定 */
1515
0
      (void)gs_sprintf(obuf, ESC_GS "1;2;3;%d;%d;%dfpE" ESC_GS "2;2;1;0;0cpE",
1516
0
                    (unsigned char)(color >> 16 & 0xff),
1517
0
                    (unsigned char)(color >> 8 & 0xff),
1518
0
                    (unsigned char)(color & 0xff));
1519
0
      lputs(s, obuf);
1520
1521
0
    }
1522
0
  } /* ESC/Page-Color */
1523
1524
0
  return 0;
1525
0
}
1526
1527
/* 線種指定命令 */
1528
static int
1529
escv_setdash(gx_device_vector * vdev, const float *pattern, uint count, double offset)
1530
0
{
1531
0
  stream      *s = gdev_vector_stream(vdev);
1532
0
  int       i;
1533
0
  char      obuf[64];
1534
1535
#if GS_VERSION_MAJOR == 5
1536
  float     scale, xscale, yscale;
1537
  /* Scale を掛けているのは, Ghostscript 5.10/5.50 のバグのため */
1538
  xscale = fabs(igs->ctm.xx);
1539
  yscale = fabs(igs->ctm.xy);
1540
1541
  if (xscale == 0)    /* if portrait */
1542
    scale = yscale;
1543
  else
1544
    scale = xscale;
1545
#endif
1546
1547
0
  if (count == 0){
1548
    /* 実線 */
1549
0
    lputs(s, ESC_GS "0;0lpG");
1550
0
    return 0;
1551
0
  }
1552
1553
  /* offset が0以外の場合は描画不可として返却 */
1554
0
  if (offset != 0) return -1;
1555
1556
0
  if (count) {
1557
0
    if (count == 1) {
1558
#if GS_VERSION_MAJOR == 5
1559
      (void)gs_sprintf(obuf, ESC_GS "1;%d;%ddlG",
1560
                    (int)(pattern[0] * scale / vdev->x_pixels_per_inch + 0.5),
1561
                    (int)(pattern[0] * scale / vdev->x_pixels_per_inch + 0.5));
1562
#else
1563
0
      (void)gs_sprintf(obuf, ESC_GS "1;%d;%ddlG", (int) pattern[0], (int) pattern[0]);
1564
0
#endif
1565
0
      lputs(s, obuf);
1566
0
    } else {
1567
      /* pattern に0があった場合は描画不可として返却 */
1568
0
      for (i = 0; i < count; ++i) {
1569
0
        if (pattern[i] == 0) return -1;
1570
0
      }
1571
1572
0
      lputs(s, ESC_GS "1");
1573
0
      for (i = 0; i < count; ++i) {
1574
#if GS_VERSION_MAJOR == 5
1575
        (void)gs_sprintf(obuf, ";%d", (int)(pattern[i] * scale / vdev->x_pixels_per_inch + 0.5));
1576
1577
#else
1578
0
        (void)gs_sprintf(obuf, ";%d", (int) pattern[i]);
1579
0
#endif
1580
0
        lputs(s, obuf);
1581
0
      }
1582
0
      lputs(s, "dlG");
1583
0
    }
1584
0
    lputs(s, ESC_GS "1;1lpG");
1585
0
  }
1586
0
  return 0;
1587
0
}
1588
1589
/* パス平滑度指定 */
1590
static int
1591
escv_setflat(gx_device_vector * vdev, double flatness)
1592
0
{
1593
0
  return 0;
1594
0
}
1595
1596
static int
1597
escv_setlogop(gx_device_vector * vdev, gs_logical_operation_t lop,
1598
              gs_logical_operation_t diff)
1599
0
{
1600
  /****** SHOULD AT LEAST DETECT SET-0 & SET-1 ******/
1601
0
  return 0;
1602
0
}
1603
1604
static int
1605
escv_beginpath(gx_device_vector * vdev, gx_path_type_t type)
1606
0
{
1607
0
  stream    *s = gdev_vector_stream(vdev);
1608
0
  gx_device_escv *pdev = (gx_device_escv *) vdev;
1609
1610
  /* パス構築開始命令 */
1611
0
  if (type & gx_path_type_clip) {
1612
0
    lputs(s, ESC_GS "1bgpG");    /* クリップ登録 */
1613
0
  } else {
1614
0
    lputs(s, ESC_GS "0bgpG");    /* 描画登録 */
1615
0
  }
1616
0
  pdev->ispath = 0;
1617
1618
0
  return 0;
1619
0
}
1620
1621
static int
1622
escv_moveto(gx_device_vector * vdev,
1623
            double x0, double y0, double x1, double y1, gx_path_type_t type)
1624
0
{
1625
0
  stream  *s = gdev_vector_stream(vdev);
1626
0
  char  obuf[64];
1627
1628
  /* サブパス開始命令 */
1629
0
  (void)gs_sprintf(obuf, ESC_GS "0;%d;%dmvpG", (int)x1, (int)y1);
1630
0
  lputs(s, obuf);
1631
1632
0
  return 0;
1633
0
}
1634
1635
static int
1636
escv_lineto(gx_device_vector * vdev,
1637
            double x0, double y0, double x1, double y1, gx_path_type_t type)
1638
0
{
1639
0
  stream  *s = gdev_vector_stream(vdev);
1640
0
  gx_device_escv *pdev = (gx_device_escv *) vdev;
1641
0
  char  obuf[64];
1642
1643
0
  (void)gs_sprintf(obuf, ESC_GS "0;1;%d;%dlnpG", (int)x1, (int)y1);
1644
0
  lputs(s, obuf);
1645
0
  pdev->ispath = 1;
1646
1647
0
  return 0;
1648
0
}
1649
1650
static int
1651
escv_curveto(gx_device_vector * vdev, double x0, double y0,
1652
             double x1, double y1, double x2, double y2, double x3, double y3,
1653
             gx_path_type_t type)
1654
0
{
1655
0
  stream  *s = gdev_vector_stream(vdev);
1656
0
  gx_device_escv *pdev = (gx_device_escv *) vdev;
1657
0
  char  obuf[128];
1658
1659
  /* ベジェ曲線 */
1660
0
  (void)gs_sprintf(obuf, ESC_GS "0;3;%d;%d;%d;%d;%d;%dbzpG",
1661
0
                (int)x1, (int)y1, (int)x2, (int)y2, (int)x3, (int)y3);
1662
0
  lputs(s, obuf);
1663
0
  pdev->ispath = 1;
1664
1665
0
  return 0;
1666
0
}
1667
1668
static int
1669
escv_closepath(gx_device_vector * vdev, double x, double y,
1670
               double x_start, double y_start, gx_path_type_t type)
1671
0
{
1672
0
  stream  *s = gdev_vector_stream(vdev);
1673
1674
0
  lputs(s, ESC_GS "clpG");
1675
0
  return 0;
1676
0
}
1677
1678
static int
1679
escv_endpath(gx_device_vector * vdev, gx_path_type_t type)
1680
0
{
1681
0
  stream  *s = gdev_vector_stream(vdev);
1682
0
  gx_device_escv *pdev = (gx_device_escv *) vdev;
1683
1684
0
  if (type & gx_path_type_fill || type & gx_path_type_clip) {
1685
    /* default で処理されるが出力しておく */
1686
0
    lputs(s, ESC_GS "clpG");
1687
0
  }
1688
1689
  /* パスクローズ */
1690
0
  lputs(s, ESC_GS "enpG");
1691
1692
  /* パス描画 */
1693
0
  if (type & gx_path_type_clip) {
1694
1695
0
    if ( ( 0 != ESCV_FORCEDRAWPATH ) || ( 0 != pdev->ispath ) ) {
1696
      /* クリップ指定
1697
      ** クリップにも gx_path_type_winding_number, gx_path_type_even_odd の判断が
1698
      ** 必要だと思うが gs 側が付加してこない。
1699
      ** とりあえず gx_path_type_even_odd をデフォルトにする。
1700
      */
1701
0
      lputs(s, ESC_GS "1;2capG");
1702
0
    }
1703
0
  } else if (type & gx_path_type_fill) {
1704
1705
    /* 塗りつぶし規則設定 */
1706
0
    if (type & gx_path_type_even_odd) {
1707
0
      lputs(s, ESC_GS "0;2drpG");    /* 塗りつぶし描画 */
1708
0
    } else {
1709
0
      lputs(s, ESC_GS "0;1drpG");    /* 塗りつぶし描画 */
1710
0
    }
1711
0
  } else {
1712
0
    lputs(s, ESC_GS "0;0drpG");    /* 輪郭線描画 */
1713
0
  }
1714
1715
0
  return 0;
1716
0
}
1717
1718
/* ---------------- Driver procedures ---------------- */
1719
1720
/* ------ Open/close/page ------ */
1721
1722
/* Open the device. */
1723
static int
1724
escv_open(gx_device * dev)
1725
0
{
1726
0
  gx_device_vector  *const vdev = (gx_device_vector *) dev;
1727
0
  gx_device_escv  *const pdev = (gx_device_escv *) dev;
1728
0
  int     code;
1729
  /*    char    *error, *path;*/
1730
0
  float               width, height;
1731
1732
0
  code = escv_range_check(dev);
1733
0
  if (code < 0) return code;
1734
1735
0
  vdev->v_memory = dev->memory;
1736
  /****** VERY WRONG ******/
1737
0
  vdev->vec_procs = &escv_vector_procs;
1738
1739
0
  code = gdev_vector_open_file_options(vdev, 512, VECTOR_OPEN_FILE_BBOX
1740
0
                                       | VECTOR_OPEN_FILE_SEQUENTIAL_OK);
1741
0
  if (code < 0) return code;
1742
1743
0
  gdev_vector_init(vdev);
1744
0
  pdev->first_page = true;
1745
1746
0
  if(pdev->orientation){
1747
1748
0
    if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
1749
1750
0
      pdev->Margins[1] = (pdev->width - pdev->height - \
1751
0
                          ESCPAGE_LEFT_MARGIN_DEFAULT * vdev->x_pixels_per_inch / 72.0) * \
1752
0
        X_DPI / vdev->x_pixels_per_inch;
1753
1754
0
    } else {     /* ESC/Page-Color */
1755
1756
      /*    pdev->Margins[1] = pdev->width - pdev->height + dev->HWMargins[0];
1757
       */
1758
0
      pdev->Margins[1] = (pdev->width - pdev->height) * \
1759
0
        X_DPI / vdev->x_pixels_per_inch;
1760
1761
0
    } /* ESC/Page-Color */
1762
1763
0
    width = dev->MediaSize[0];
1764
0
    height  = dev->MediaSize[1];
1765
0
    dev->MediaSize[0] = height;
1766
0
    dev->MediaSize[1] = width;
1767
0
  }
1768
1769
0
  return 0;
1770
0
}
1771
1772
/* Wrap up ("output") a page. */
1773
static int
1774
escv_output_page(gx_device * dev, int num_copies, int flush)
1775
0
{
1776
0
  gx_device_vector *const vdev = (gx_device_vector *) dev;
1777
0
  gx_device_escv *const pdev = (gx_device_escv *) dev;
1778
0
  stream *s = gdev_vector_stream(vdev);
1779
1780
  /* 線幅,終端処理,接合部処理を初期化しておく */
1781
0
  lputs(s, ESC_GS "3;0;0lwG" ESC_GS "1;10mlG" ESC_FF);
1782
1783
0
  sflush(s);
1784
0
  vdev->in_page = false;
1785
0
  pdev->first_page = false;
1786
1787
0
  gdev_vector_reset(vdev);
1788
1789
0
  return 0;
1790
0
}
1791
1792
static int
1793
escv_close(gx_device *dev)
1794
0
{
1795
0
  gx_device_vector *const vdev = (gx_device_vector *) dev;
1796
0
  gp_file          *f = vdev->file;
1797
1798
  /* 終了処理コードは決め打ち */
1799
0
  (void)gp_fprintf(f, ESC_GS "rhE" "\033\001@EJL \012@EJL EJ \012\033\001@EJL \012");
1800
1801
0
  gdev_vector_close_file(vdev);
1802
1803
0
  return 0;
1804
0
}
1805
1806
/* Close the device. */
1807
/* Note that if this is being called as a result of finalization, */
1808
/* the stream may no longer exist; but the file will still be open. */
1809
1810
/* ---------------- Get/put parameters ---------------- */
1811
1812
static int
1813
escv_get_str_param( gs_param_list * plist, gs_param_name key, gs_param_string *pgsstr, int code )
1814
0
{
1815
0
    int             ncode;
1816
1817
0
    ncode = param_write_string(plist, key, pgsstr);
1818
1819
0
    if ( ncode < 0)
1820
0
      code = ncode;
1821
1822
0
    return code;
1823
0
}
1824
1825
/* Get parameters. */
1826
static int
1827
escv_get_params(gx_device * dev, gs_param_list * plist)
1828
0
{
1829
0
  gx_device_escv  *const pdev = (gx_device_escv *) dev;
1830
0
  int     code;
1831
0
  int     ncode;
1832
1833
0
  code = gdev_vector_get_params(dev, plist);
1834
0
  if (code < 0) return code;
1835
1836
0
  if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_EPLModelJP, &pdev->modelJP)) < 0)
1837
0
    code = ncode;
1838
1839
0
  if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_EPLCapFaceUp, &pdev->capFaceUp)) < 0)
1840
0
    code = ncode;
1841
1842
0
  if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_EPLCapDuplexUnit, &pdev->capDuplexUnit)) < 0)
1843
0
    code = ncode;
1844
1845
0
  if ((ncode = param_write_int(plist, ESCPAGE_OPTION_EPLCapMaxResolution, &pdev->capMaxResolution)) < 0)
1846
0
    code = ncode;
1847
1848
0
  if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_MANUALFEED, &pdev->manualFeed)) < 0)
1849
0
    code = ncode;
1850
1851
0
  if ((ncode = param_write_int(plist, ESCPAGE_OPTION_CASSETFEED, &pdev->cassetFeed)) < 0)
1852
0
    code = ncode;
1853
1854
0
  if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_RIT, &pdev->RITOff)) < 0)
1855
0
    code = ncode;
1856
1857
0
  if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_COLLATE, &pdev->Collate)) < 0)
1858
0
    code = ncode;
1859
1860
0
  if ((ncode = param_write_int(plist, ESCPAGE_OPTION_TONERDENSITY, &pdev->toner_density)) < 0)
1861
0
    code = ncode;
1862
1863
0
  if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_LANDSCAPE, &pdev->orientation)) < 0)
1864
0
    code = ncode;
1865
1866
0
  if ( param_write_bool(plist, ESCPAGE_OPTION_TONERSAVING, &pdev->toner_saving)< 0)
1867
0
    code = ncode;
1868
1869
0
  if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_DUPLEX, &pdev->Duplex)) < 0)
1870
0
    code = ncode;
1871
1872
0
  if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_DUPLEX_TUMBLE, &pdev->Tumble)) < 0)
1873
0
    code = ncode;
1874
1875
0
  if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_FACEUP, &pdev->faceup)) < 0)
1876
0
    code = ncode;
1877
1878
0
  if ((ncode = param_write_int(plist, ESCPAGE_OPTION_MEDIATYPE, &pdev->MediaType)) < 0)
1879
0
    code = ncode;
1880
1881
0
  code = escv_get_str_param( plist, ESCPAGE_OPTION_JOBID,    &pdev->gpsJobID, code );
1882
0
  code = escv_get_str_param( plist, ESCPAGE_OPTION_USERNAME, &pdev->gpsUserName, code );
1883
0
  code = escv_get_str_param( plist, ESCPAGE_OPTION_HOSTNAME, &pdev->gpsHostName, code );
1884
0
  code = escv_get_str_param( plist, ESCPAGE_OPTION_DOCUMENT, &pdev->gpsDocument, code );
1885
0
  code = escv_get_str_param( plist, ESCPAGE_OPTION_COMMENT,  &pdev->gpsComment, code );
1886
1887
0
  return code;
1888
0
}
1889
1890
static int
1891
escv_set_str_param( gs_param_list * plist, const char * key, char *strvalue, int bufmax, int ecode )
1892
0
{
1893
0
    gs_param_name param_name;
1894
0
    gs_param_string gsstr;
1895
0
    int     code;
1896
0
    int                 writesize = bufmax;
1897
1898
0
    switch (code = param_read_string(plist, (param_name = key), &gsstr)) {
1899
0
    case 0:
1900
0
      writesize = ( bufmax < gsstr.size )? bufmax : gsstr.size ;
1901
0
      strncpy( strvalue, (const char *)gsstr.data, writesize );
1902
0
      strvalue[ writesize ] = '\0';
1903
0
      break;
1904
0
    default:
1905
0
      ecode = code;
1906
0
      param_signal_error(plist, param_name, ecode);
1907
0
    case 1:
1908
0
      break;
1909
0
    }
1910
0
    return ecode;
1911
0
}
1912
1913
/* Put parameters. */
1914
static int
1915
escv_put_params(gx_device * dev, gs_param_list * plist)
1916
0
{
1917
0
  gx_device_escv  *const pdev = (gx_device_escv *) dev;
1918
0
  int     ecode = 0;
1919
0
  int     code;
1920
0
  gs_param_name param_name;
1921
0
  gs_param_string pmedia;
1922
0
  bool    mf = pdev->manualFeed;
1923
0
  int     cass = pdev->cassetFeed;
1924
0
  bool    tum = pdev->Tumble;
1925
0
  bool    collate = pdev->Collate;
1926
0
  int     toner_density = pdev->toner_density;
1927
0
  bool    toner_saving = pdev->toner_saving;
1928
0
  bool    landscape = pdev->orientation;
1929
0
  bool    faceup = pdev->faceup;
1930
0
  bool    duplex = pdev->Duplex;
1931
0
  bool    RITOff = pdev->RITOff;
1932
0
  int     old_bpp = dev->color_info.depth;
1933
0
  int     bpp = 0;
1934
0
  bool          modelJP = false;
1935
0
  bool          capFaceUp = false;
1936
0
  bool          capDuplexUnit = false;
1937
0
  int           capMaxResolution = 0;
1938
1939
0
  ecode = escv_set_str_param( plist, ESCPAGE_OPTION_JOBID,    pdev->JobID,    ESCPAGE_JOBID_MAX,    ecode );
1940
0
  ecode = escv_set_str_param( plist, ESCPAGE_OPTION_USERNAME, pdev->UserName, ESCPAGE_USERNAME_MAX, ecode );
1941
0
  ecode = escv_set_str_param( plist, ESCPAGE_OPTION_HOSTNAME, pdev->HostName, ESCPAGE_HOSTNAME_MAX, ecode );
1942
0
  ecode = escv_set_str_param( plist, ESCPAGE_OPTION_DOCUMENT, pdev->Document, ESCPAGE_DOCUMENT_MAX, ecode );
1943
0
  ecode = escv_set_str_param( plist, ESCPAGE_OPTION_COMMENT,  pdev->Comment,  ESCPAGE_COMMENT_MAX,  ecode );
1944
1945
0
  modelJP = pdev->modelJP;
1946
0
  param_name = ESCPAGE_OPTION_EPLModelJP;
1947
0
  code = param_read_bool(plist, param_name, &modelJP);
1948
0
  if (code < 0) {
1949
0
    ecode = code;
1950
0
    param_signal_error(plist, param_name, ecode);
1951
0
  }
1952
1953
0
  capFaceUp = pdev->capFaceUp;
1954
0
  param_name = ESCPAGE_OPTION_EPLCapFaceUp;
1955
0
  code = param_read_bool(plist, param_name, &capFaceUp);
1956
0
  if (code < 0) {
1957
0
    ecode = code;
1958
0
    param_signal_error(plist, param_name, ecode);
1959
0
  }
1960
1961
0
  capDuplexUnit = pdev->capDuplexUnit;
1962
0
  param_name = ESCPAGE_OPTION_EPLCapDuplexUnit;
1963
0
  code = param_read_bool(plist, param_name, &capDuplexUnit);
1964
0
  if (code < 0) {
1965
0
    ecode = code;
1966
0
    param_signal_error(plist, param_name, ecode);
1967
0
  }
1968
1969
0
  capMaxResolution = pdev->capMaxResolution;
1970
0
  param_name = ESCPAGE_OPTION_EPLCapMaxResolution;
1971
0
  code = param_read_int(plist, param_name, &capMaxResolution);
1972
0
  switch ( code )
1973
0
    {
1974
0
    case 1:
1975
0
      break;
1976
1977
0
    case 0:
1978
0
      if ( ( 600 != capMaxResolution ) &&
1979
0
           ( 1200 != capMaxResolution ) ) {
1980
0
        ecode = gs_error_limitcheck;
1981
0
        goto maxrese;
1982
0
      }
1983
0
      break;
1984
1985
0
    default:
1986
0
      ecode = code;
1987
      /* through */
1988
0
    maxrese:
1989
0
      param_signal_error(plist, param_name, ecode);
1990
0
      break;
1991
0
    }
1992
1993
0
  if ((code = param_read_bool(plist, (param_name = ESCPAGE_OPTION_MANUALFEED), &mf)) < 0) {
1994
0
    param_signal_error(plist, param_name, ecode = code);
1995
0
  }
1996
0
  switch (code = param_read_int(plist, (param_name = ESCPAGE_OPTION_CASSETFEED), &cass)) {
1997
0
  case 0:
1998
0
    if (cass < -1 || cass > 15)
1999
0
      ecode = gs_error_limitcheck;
2000
0
    else
2001
0
      break;
2002
0
    goto casse;
2003
0
  default:
2004
0
    ecode = code;
2005
0
  casse:param_signal_error(plist, param_name, ecode);
2006
0
  case 1:
2007
0
    break;
2008
0
  }
2009
2010
0
  if((code = param_read_bool(plist, (param_name = ESCPAGE_OPTION_COLLATE), &collate)) < 0) {
2011
0
    param_signal_error(plist, param_name, ecode = code);
2012
0
  }
2013
2014
0
  if ((code = param_read_bool(plist, (param_name = ESCPAGE_OPTION_RIT), &RITOff)) < 0) {
2015
0
    param_signal_error(plist, param_name, ecode = code);
2016
0
  }
2017
2018
0
  switch (code = param_read_string(plist, (param_name = ESCPAGE_OPTION_MEDIATYPE), &pmedia)) {
2019
0
  case 0:
2020
0
    if (pmedia.size > ESCPAGE_MEDIACHAR_MAX) {
2021
0
        ecode = gs_error_limitcheck;
2022
0
        goto pmediae;
2023
0
    } else {   /* Check the validity of ``MediaType'' characters */
2024
2025
0
      if (strcmp((const char *)pmedia.data, "NM") == 0) {
2026
0
        pdev->MediaType = 0;
2027
0
      } else if ((strcmp((const char *)pmedia.data, "THICK") == 0) ||
2028
0
                 (strcmp((const char *)pmedia.data, "TH") == 0)) {
2029
0
        pdev->MediaType = 1;
2030
0
      } else if ((strcmp((const char *)pmedia.data, "TRANS") == 0) ||
2031
0
                 (strcmp((const char *)pmedia.data, "TR") == 0)) {
2032
0
        pdev->MediaType = 2;
2033
0
      } else if (strcmp((const char *)pmedia.data, "TN") == 0) {
2034
0
        pdev->MediaType = 3;
2035
0
      } else if (strcmp((const char *)pmedia.data, "LH") == 0) {
2036
0
        pdev->MediaType = 4;
2037
0
      } else if (strcmp((const char *)pmedia.data, "CT") == 0) {
2038
0
        pdev->MediaType = 5;
2039
0
      } else if (strcmp((const char *)pmedia.data, "ET") == 0) {
2040
0
        pdev->MediaType = 6;
2041
0
      } else if (strcmp((const char *)pmedia.data, "HQ") == 0) {
2042
0
        pdev->MediaType = 7;
2043
0
      } else if (strcmp((const char *)pmedia.data, "UT") == 0) {
2044
0
        pdev->MediaType = 8;
2045
0
      } else if (strcmp((const char *)pmedia.data, "UM") == 0) {
2046
0
        pdev->MediaType = 9;
2047
0
      } else {
2048
0
        ecode = gs_error_rangecheck;
2049
0
        goto pmediae;
2050
0
      }
2051
0
    }
2052
0
    break;
2053
0
  default:
2054
0
    ecode = code;
2055
0
  pmediae:
2056
0
    param_signal_error(plist, param_name, ecode);
2057
    /* Fall through. */
2058
0
  case 1:
2059
0
    if(!pdev->MediaType){
2060
0
      pdev->MediaType = 0;
2061
0
      pmedia.data = 0;
2062
0
    }
2063
0
    break;
2064
0
  }
2065
2066
0
  switch (code = param_read_int(plist,
2067
0
                                (param_name = ESCPAGE_OPTION_TONERDENSITY), &toner_density)) {
2068
0
  case 0:
2069
0
    if (toner_density < 0 || toner_density > 5)
2070
0
      ecode = gs_error_rangecheck;
2071
0
    else
2072
0
      break;
2073
0
    goto tden;
2074
0
  default:
2075
0
    ecode = code;
2076
0
  tden:
2077
0
    param_signal_error(plist, param_name, ecode);
2078
0
  case 1:
2079
0
    break;
2080
0
  }
2081
2082
0
  switch (code = param_read_bool(plist, (param_name = ESCPAGE_OPTION_TONERSAVING), &toner_saving)) {
2083
0
  case 0:
2084
0
    break;
2085
0
  default:
2086
0
    if ((code = param_read_null(plist, param_name)) == 0) {
2087
0
      break;
2088
0
    }
2089
0
    ecode = code;
2090
0
    param_signal_error(plist, param_name, ecode);
2091
0
  case 1:
2092
0
    break;
2093
0
  }
2094
2095
0
  if ((code = param_read_bool(plist, (param_name = ESCPAGE_OPTION_DUPLEX), &duplex)) < 0)
2096
0
    param_signal_error(plist, param_name, ecode = code);
2097
2098
0
  if ((code = param_read_bool(plist, (param_name = ESCPAGE_OPTION_DUPLEX_TUMBLE), &tum)) < 0)
2099
0
    param_signal_error(plist, param_name, ecode = code);
2100
2101
0
  if ((code = param_read_bool(plist, (param_name = ESCPAGE_OPTION_LANDSCAPE), &landscape)) < 0)
2102
0
    param_signal_error(plist, param_name, ecode = code);
2103
2104
0
  if ((code = param_read_bool(plist, (param_name = ESCPAGE_OPTION_FACEUP), &faceup)) < 0) {
2105
0
    param_signal_error(plist, param_name, ecode = code);
2106
0
  }
2107
2108
0
  switch (code = param_read_int(plist, (param_name = "BitsPerPixel"), &bpp)) {
2109
0
  case 0:
2110
0
    if (bpp != 8 && bpp != 24)
2111
0
      ecode = gs_error_rangecheck;
2112
0
    else
2113
0
      break;
2114
0
    goto bppe;
2115
0
  default:
2116
0
    ecode = code;
2117
0
  bppe:param_signal_error(plist, param_name, ecode);
2118
0
  case 1:
2119
0
    break;
2120
0
  }
2121
2122
0
  if (bpp != 0) {
2123
0
    dev->color_info.depth = bpp;
2124
0
    dev->color_info.num_components = ((bpp == 8) ? 1 : 3);
2125
0
    dev->color_info.max_gray = (bpp > 8 ? 255 : 1000);
2126
0
    dev->color_info.max_color = (bpp > 8 ? 255 : 1000);
2127
0
    dev->color_info.dither_grays = (bpp > 8 ? 256 : 5);
2128
0
    dev->color_info.dither_colors = (bpp > 8 ? 256 : 2);
2129
0
    dev_proc(pdev, map_rgb_color) = ((bpp == 8) ? gx_default_gray_map_rgb_color : gx_default_rgb_map_rgb_color);
2130
0
    dev_proc(pdev, map_color_rgb) = ((bpp == 8) ? gx_default_gray_map_color_rgb : gx_default_rgb_map_color_rgb);
2131
0
  }
2132
2133
0
  if (ecode < 0) return ecode;
2134
0
  code = gdev_vector_put_params(dev, plist);
2135
0
  if (code < 0) return code;
2136
2137
0
  pdev->modelJP = modelJP;
2138
0
  pdev->capFaceUp = capFaceUp;
2139
0
  pdev->capDuplexUnit = capDuplexUnit;
2140
0
  pdev->capMaxResolution = capMaxResolution;
2141
2142
0
  pdev->manualFeed = mf;
2143
0
  pdev->cassetFeed = cass;
2144
0
  pdev->faceup = faceup;
2145
0
  pdev->RITOff = RITOff;
2146
0
  pdev->orientation = landscape;
2147
0
  pdev->toner_density = toner_density;
2148
0
  pdev->toner_saving = toner_saving;
2149
0
  pdev->Collate = collate;
2150
0
  pdev->Duplex = duplex;
2151
0
  pdev->Tumble = tum;
2152
2153
0
  if (bpp != 0 && bpp != old_bpp && pdev->is_open)
2154
0
    return gs_closedevice(dev);
2155
2156
0
  return 0;
2157
0
}
2158
2159
/* ---------------- Images ---------------- */
2160
2161
static int
2162
escv_copy_mono(gx_device * dev, const byte * data,
2163
               int data_x, int raster, gx_bitmap_id id, int x, int y, int w, int h,
2164
               gx_color_index zero, gx_color_index one)
2165
0
{
2166
0
  gx_device_escv *const pdev = (gx_device_escv *) dev;
2167
0
  gx_device_vector *const vdev = (gx_device_vector *) dev;
2168
0
  stream      *s = gdev_vector_stream(vdev);
2169
0
  gx_drawing_color    color;
2170
0
  int       code = 0;
2171
0
  gx_color_index    c_color = 0;
2172
0
  char      obuf[128];
2173
0
  int       depth = 1;
2174
0
#if ( 8 <= GS_VERSION_MAJOR )
2175
  /* FIXME! add for gs815 */
2176
0
  const gs_gstate * pgs = (const gs_gstate *)0;
2177
0
#endif
2178
2179
0
  if (id != gs_no_id && zero == gx_no_color_index && one != gx_no_color_index && data_x == 0) {
2180
0
    gx_drawing_color dcolor;
2181
2182
0
    color_set_pure(&dcolor, one);
2183
0
    escv_setfillcolor(vdev,
2184
0
#if ( 8 <= GS_VERSION_MAJOR )
2185
0
                      pgs,
2186
0
#endif
2187
0
                      &dcolor); /* FIXME! gs815 */
2188
0
  }
2189
2190
0
  if (zero == gx_no_color_index) {
2191
2192
0
    if (one == gx_no_color_index) return 0;
2193
0
    if (pdev->MaskState != 1) {
2194
2195
0
      if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
2196
2197
        /*      lputs(s, ESC_GS "1owE");*/
2198
0
        (void)gs_sprintf(obuf, ESC_GS "1;1;%ldccE", c_color);
2199
0
        lputs(s, obuf);
2200
2201
0
        if (vdev->x_pixels_per_inch == 1200) {
2202
0
          lputs(s, ESC_GS "1;45;156htmE");
2203
0
        } else if (vdev->x_pixels_per_inch == 600) {
2204
0
          lputs(s, ESC_GS "1;45;106htmE");
2205
0
        } else {
2206
0
          lputs(s, ESC_GS "1;45;71htmE");
2207
0
        }
2208
2209
0
      } else {     /* ESC/Page-Color */
2210
2211
0
        lputs(s, ESC_GS "2;184wfE" ESC_GS "3;184wfE" ESC_GS "5;184wfE");
2212
2213
0
      } /* ESC/Page-Color */
2214
2215
0
      pdev->MaskState = 1;
2216
0
    }
2217
0
    c_color = one;
2218
2219
0
  } else if (one == gx_no_color_index)
2220
    /* 1bit は透明 ビット反転・zero 色に染める */
2221
0
    {
2222
0
      if (pdev->MaskState != 1) {
2223
2224
0
        if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
2225
2226
          /*      lputs(s, ESC_GS "1owE");*/
2227
2228
0
        } else {     /* ESC/Page-Color */
2229
2230
0
          lputs(s, ESC_GS "3;184wfE" ESC_GS "5;184wfE");
2231
2232
0
        } /* ESC/Page-Color */
2233
2234
0
        pdev->MaskState = 1;
2235
0
      }
2236
0
      c_color = zero;
2237
0
    } else if (one == vdev->white) {
2238
2239
0
      if (pdev->MaskState != 0) {
2240
2241
0
        if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
2242
2243
          /*      lputs(s, ESC_GS "1owE");*/
2244
2245
0
        } else {     /* ESC/Page-Color */
2246
2247
0
          lputs(s, ESC_GS "3;204wfE" ESC_GS "5;204wfE");
2248
2249
0
        } /* ESC/Page-Color */
2250
2251
0
        pdev->MaskState = 0;
2252
0
      }
2253
0
      c_color = zero;
2254
0
    } else {
2255
2256
0
      if (pdev->MaskState != 1) {
2257
2258
0
        if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
2259
2260
          /*      lputs(s, ESC_GS "1owE");*/
2261
2262
0
        } else {     /* ESC/Page-Color */
2263
2264
0
          lputs(s, ESC_GS "3;184wfE" ESC_GS "5;184wfE");
2265
2266
0
        } /* ESC/Page-Color */
2267
2268
0
        pdev->MaskState = 1;
2269
0
      }
2270
0
      color_set_pure(&color, one);
2271
0
      code = gdev_vector_update_fill_color((gx_device_vector *) pdev,
2272
0
#if ( 8 <= GS_VERSION_MAJOR )
2273
0
                                           pgs,
2274
0
#endif
2275
0
                                           &color);
2276
2277
      /* ここを通過したら以下の色設定は無意味? */
2278
0
    }
2279
0
  if (code < 0) return 0;
2280
2281
0
  if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
2282
0
  } else {     /* ESC/Page-Color */
2283
2284
    /* パターンON指定/ソリッドパターン指定 */
2285
0
    (void)gs_sprintf(obuf, ESC_GS "1;2;3;%d;%d;%dfpE",
2286
0
                  (unsigned char)(c_color >> 16 & 0xff),
2287
0
                  (unsigned char)(c_color >> 8 & 0xff),
2288
0
                  (unsigned char)(c_color & 0xff));
2289
0
    lputs(s, obuf);
2290
2291
0
    lputs(s, ESC_GS "5;2;1;0;0cpE");
2292
2293
0
  } /* ESC/Page-Color */
2294
2295
0
  escv_write_begin(dev, depth, (int)x, (int)y, w, h, w, h, 0);
2296
0
  {
2297
0
    int   i, j;
2298
0
    uint    width_bytes = (w + 7) >> 3;
2299
0
    uint    num_bytes = width_bytes * h;
2300
2301
0
    byte *buf = gs_alloc_bytes(vdev->memory, num_bytes, "escv_copy_mono(buf)");
2302
2303
0
    if (data_x % 8 == 0) {
2304
0
      for (i = 0; i < h; ++i) {
2305
0
        memcpy(buf + i * width_bytes, data + (data_x >> 3) + i * raster, width_bytes);
2306
0
      }
2307
0
    } else {
2308
0
      for (i = 0; i < h; ++i) {
2309
0
        for (j = 0; j < width_bytes; j++) {
2310
0
          *(buf + i * width_bytes + j) =
2311
0
            *(data + (data_x >> 3) + i * raster + j) << (data_x % 8) |
2312
0
            *(data + (data_x >> 3) + i * raster + j + 1) >> (8 - data_x % 8);
2313
0
        }
2314
0
      }
2315
0
    }
2316
2317
0
    escv_write_data(dev, depth, buf, num_bytes, w, h);
2318
0
    gs_free_object(vdev->memory, buf, "escv_copy_mono(buf)");
2319
0
  }
2320
0
  escv_write_end(dev, depth);
2321
0
  return 0;
2322
0
}
2323
2324
/* Copy a color bitmap. */
2325
static int
2326
escv_copy_color(gx_device * dev,
2327
                const byte * data, int data_x, int raster, gx_bitmap_id id,
2328
                int x, int y, int w, int h)
2329
0
{
2330
0
  gx_device_escv  *const pdev = (gx_device_escv *) dev;
2331
0
  gx_device_vector  *const vdev = (gx_device_vector *) dev;
2332
2333
0
  int     depth = dev->color_info.depth;
2334
0
  int     num_components = (depth < 24 ? 1 : 3);
2335
0
  uint    width_bytes = w * num_components;
2336
2337
0
  if (pdev->MaskState != 0) {
2338
2339
0
    if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
2340
2341
      /*  lputs(s, ESC_GS "1owE");*/
2342
2343
0
    } else {     /* ESC/Page-Color */
2344
0
      stream    *s = gdev_vector_stream(vdev);
2345
2346
0
      lputs(s, ESC_GS "3;204wfE" ESC_GS "5;204wfE");
2347
2348
0
    } /* ESC/Page-Color */
2349
0
    pdev->MaskState = 0;
2350
0
  }
2351
2352
0
  escv_write_begin(dev, depth, (int)x, (int)y, w, h, w, h, 0);
2353
2354
0
  {
2355
0
    int   i;
2356
0
    uint    num_bytes = width_bytes * h;
2357
0
    byte    *buf = gs_alloc_bytes(vdev->memory, num_bytes, "escv_copy_color(buf)");
2358
2359
0
    for (i = 0; i < h; ++i) {
2360
0
      memcpy(buf + i * width_bytes, data + ((data_x * depth) >> 3) + i * raster, width_bytes);
2361
0
    }
2362
2363
0
    escv_write_data(dev, depth, buf, num_bytes, w, h);
2364
0
    gs_free_object(vdev->memory, buf, "escv_copy_color(buf)");
2365
0
  }
2366
2367
0
  escv_write_end(dev, depth);
2368
0
  return 0;
2369
0
}
2370
2371
/* Fill a mask. */
2372
static int
2373
escv_fill_mask(gx_device * dev,
2374
               const byte * data, int data_x, int raster, gx_bitmap_id id,
2375
               int x, int y, int w, int h,
2376
               const gx_drawing_color * pdcolor, int depth,
2377
               gs_logical_operation_t lop, const gx_clip_path * pcpath)
2378
0
{
2379
0
  gx_device_vector *const vdev = (gx_device_vector *) dev;
2380
0
  gx_device_escv   *const pdev = (gx_device_escv *)   dev;
2381
0
  stream           *s    = gdev_vector_stream(vdev);
2382
2383
0
  gx_color_index    color = gx_dc_pure_color(pdcolor);
2384
0
  char      obuf[64];
2385
2386
0
#if ( 8 <= GS_VERSION_MAJOR )
2387
  /* FIXME! add for gs815 */
2388
0
  const gs_gstate * pgs = (const gs_gstate *)0;
2389
0
#endif
2390
2391
0
  if (w <= 0 || h <= 0) return 0;
2392
2393
0
  if (depth > 1 ||
2394
0
      gdev_vector_update_fill_color(vdev,
2395
0
#if ( 8 <= GS_VERSION_MAJOR )
2396
0
                                    pgs,
2397
0
#endif
2398
0
                                    pdcolor) < 0 ||
2399
0
      gdev_vector_update_clip_path(vdev, pcpath) < 0 ||
2400
0
      gdev_vector_update_log_op(vdev, lop) < 0
2401
0
      )
2402
0
    return gx_default_fill_mask(dev, data, data_x, raster, id,
2403
0
                                x, y, w, h, pdcolor, depth, lop, pcpath);
2404
2405
0
  if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
2406
2407
0
    if (!gx_dc_is_pure(pdcolor)) return_error(gs_error_rangecheck);
2408
0
    pdev->current_color = color;
2409
2410
0
    (void)gs_sprintf(obuf, ESC_GS "0;0;100spE" ESC_GS "1;1;%ldccE" ,color);
2411
0
    lputs(s, obuf);
2412
2413
0
    if (vdev->x_pixels_per_inch == 1200) {
2414
0
      lputs(s, ESC_GS "1;45;156htmE");
2415
0
    } else if (vdev->x_pixels_per_inch == 600) {
2416
0
      lputs(s, ESC_GS "1;45;106htmE");
2417
0
    } else {
2418
0
      lputs(s, ESC_GS "1;45;71htmE");
2419
0
    }
2420
2421
0
    if(pdev->MaskState != 1) {
2422
      /*      lputs(s, ESC_GS "1owE");*/
2423
0
      pdev->MaskState = 1;
2424
0
    }
2425
2426
0
  } else {     /* ESC/Page-Color */
2427
2428
0
    if (pdev->MaskState != 1) {
2429
2430
0
      lputs(s, ESC_GS "3;184wfE" ESC_GS "5;184wfE");
2431
0
      pdev->MaskState = 1;
2432
0
    }
2433
2434
0
    if (id != gs_no_id && data_x == 0 && depth == 1) {
2435
0
      char    obuf[128];
2436
0
      int   i;
2437
0
      uint    width_bytes = (w + 7) >> 3;
2438
0
      uint    num_bytes = width_bytes * h;
2439
0
      byte    *buf;
2440
2441
0
      if (pdev -> id_cache[id & VCACHE] != id) {
2442
2443
0
        buf = gs_alloc_bytes(vdev->memory, num_bytes, "escv_fill_mask(buf)");
2444
2445
        /* cache entry */
2446
0
        for (i = 0; i < h; ++i) {
2447
0
          memcpy(buf + i * width_bytes, data + (data_x >> 3) + i * raster, width_bytes);
2448
0
        }
2449
2450
0
        (void)gs_sprintf(obuf, ESC_GS "%d;%d;%d;%d;0db{F", num_bytes, (int)(id & VCACHE), w, h);
2451
0
        lputs(s, obuf);
2452
0
        put_bytes(s, buf, num_bytes);
2453
2454
0
        gs_free_object(vdev->memory, buf, "escv_fill_mask(buf)");
2455
0
        pdev -> id_cache[id & VCACHE] = id;
2456
0
      }
2457
2458
0
      (void)gs_sprintf(obuf, ESC_GS "%dX" ESC_GS "%dY", x, y);
2459
0
      lputs(s, obuf);
2460
0
      (void)gs_sprintf(obuf, ESC_GS "%lddbF", id & VCACHE);
2461
0
      lputs(s, obuf);
2462
2463
0
      return 0;
2464
0
    }
2465
0
  } /* ESC/Page-Color */
2466
2467
0
  escv_write_begin(dev, depth, (int)x, (int)y, w, h, w, h, 0);
2468
0
  {
2469
0
    int   i;
2470
0
    uint    width_bytes = (w + 7) >> 3;
2471
0
    uint    num_bytes = width_bytes * h;
2472
0
    byte    *buf = gs_alloc_bytes(vdev->memory, num_bytes, "escv_fill_mask(buf)");
2473
2474
0
    for (i = 0; i < h; ++i) {
2475
0
      memcpy(buf + i * width_bytes, data + (data_x >> 3) + i * raster, width_bytes);
2476
0
    }
2477
2478
0
    escv_write_data(dev, depth, buf, num_bytes, w, h);
2479
0
    escv_write_end(dev, depth);
2480
0
    gs_free_object(vdev->memory, buf, "escv_fill_mask(buf)");
2481
0
  }
2482
2483
0
  return 0;
2484
0
}
2485
2486
/* ---------------- High-level images ---------------- */
2487
2488
static image_enum_proc_plane_data(escv_image_plane_data);
2489
static image_enum_proc_end_image(escv_image_end_image);
2490
static const gx_image_enum_procs_t escv_image_enum_procs =
2491
  {
2492
    escv_image_plane_data, escv_image_end_image
2493
  };
2494
2495
/* Start processing an image. */
2496
static int
2497
escv_begin_image(gx_device * dev,
2498
                 const gs_gstate * pgs, const gs_image_t * pim,
2499
                 gs_image_format_t format, const gs_int_rect * prect,
2500
                 const gx_drawing_color * pdcolor, const gx_clip_path * pcpath,
2501
                 gs_memory_t * mem, gx_image_enum_common_t **pinfo)
2502
0
{
2503
0
  gx_device_vector *const vdev = (gx_device_vector *) dev;
2504
0
  gx_device_escv *const pdev = (gx_device_escv *) dev;
2505
0
  stream      *s = gdev_vector_stream((gx_device_vector *) pdev);
2506
0
  gdev_vector_image_enum_t  *pie =
2507
0
    gs_alloc_struct(mem, gdev_vector_image_enum_t, &st_vector_image_enum, "escv_begin_image");
2508
0
  const gs_color_space  *pcs = pim->ColorSpace;
2509
0
  gs_color_space_index  index;
2510
0
  int       num_components = 1;
2511
0
  bool can_do = prect == 0 &&
2512
0
    (pim->format == gs_image_format_chunky ||
2513
0
     pim->format == gs_image_format_component_planar);
2514
2515
0
  gs_matrix     imat;
2516
0
  int       code;
2517
0
  int       ty, bx, by, cy, sx, sy;
2518
2519
0
  char            obuf[128];
2520
2521
0
  if (pie == 0) return_error(gs_error_VMerror);
2522
0
  pie->memory = mem;
2523
0
  code = gdev_vector_begin_image(vdev, pgs, pim, format, prect,
2524
0
                                 pdcolor, pcpath, mem, &escv_image_enum_procs, pie);
2525
0
  if (code < 0) return code;
2526
2527
0
  *pinfo = (gx_image_enum_common_t *) pie;
2528
2529
0
  if (!pim->ImageMask) {
2530
0
    index = gs_color_space_get_index(pcs);
2531
0
    num_components = gs_color_space_num_components(pcs);
2532
2533
0
    if (pim->CombineWithColor) {
2534
0
      can_do = false;
2535
0
    } else {
2536
0
      switch (index) {
2537
0
      case gs_color_space_index_DeviceGray:
2538
0
        if ((pim->Decode[0] != 0 || pim->Decode[1] != 1)
2539
0
            && (pim->Decode[0] != 1 || pim->Decode[1] != 0))
2540
0
          can_do = false;
2541
0
        break;
2542
0
      case gs_color_space_index_DeviceRGB:
2543
0
        if (pim->Decode[0] != 0 || pim->Decode[1] != 1 ||
2544
0
            pim->Decode[2] != 0 || pim->Decode[3] != 1 ||
2545
0
            pim->Decode[4] != 0)
2546
0
          can_do = false;
2547
0
        break;
2548
0
      default:
2549
0
        can_do = false;
2550
0
      }
2551
0
    }
2552
0
  }
2553
0
  if (!can_do) {
2554
0
    return gx_default_begin_image(dev, pgs, pim, format, prect,
2555
0
                                  pdcolor, pcpath, mem, &pie->default_info);
2556
0
  }
2557
2558
0
  if (pim->ImageMask || (pim->BitsPerComponent == 1 && num_components == 1)) {
2559
0
    if (pim->Decode[0] > pim->Decode[1]) {
2560
0
      pdev->MaskReverse = 1;
2561
0
    } else {
2562
0
      if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
2563
0
      } else {     /* ESC/Page-Color */
2564
0
        lputs(s, ESC_GS "8;1;2;2;2plr{E");
2565
0
        put_bytes(s, (const byte *)"\000\000\000\000\377\377\377\377", 8);
2566
0
      } /* ESC/Page-Color */
2567
0
      pdev->MaskReverse = 0;
2568
0
    }
2569
0
  }
2570
2571
  /* Write the image/colorimage/imagemask preamble. */
2572
0
  code = gs_matrix_invert(&pim->ImageMatrix, &imat);
2573
0
  if (code < 0)
2574
0
      return code;
2575
2576
0
  gs_matrix_multiply(&imat, &ctm_only(pgs), &imat);
2577
2578
0
  ty = imat.ty;
2579
0
  bx = imat.xx * pim->Width + imat.yx * pim->Height + imat.tx;
2580
0
  by = imat.xy * pim->Width + imat.yy * pim->Height + imat.ty;
2581
0
  cy = imat.yy * pim->Height + imat.ty;
2582
2583
0
  sx = bx - (int)imat.tx;
2584
0
  sy = by - (int)imat.ty;
2585
2586
  /* とりあえず絵の位置に収まるように強制的に座標を変更する。 */
2587
0
  pdev -> roll = 0;
2588
0
  pdev -> reverse_x = pdev -> reverse_y = 0;
2589
0
  if (imat.tx > bx) {
2590
0
    pdev -> reverse_x = 1;
2591
0
    sx = -sx;
2592
0
    imat.tx = bx;
2593
0
  }
2594
2595
0
  if (imat.ty > by) {
2596
0
    pdev -> reverse_y = 1;
2597
0
    sy = -sy;
2598
0
    imat.ty = by;
2599
0
  }
2600
2601
0
  (void)memcpy(&pdev -> xmat, &imat, sizeof(gs_matrix));
2602
0
  pdev -> sx = sx;
2603
0
  pdev -> sy = sy;
2604
0
  pdev -> h = pim->Height;
2605
0
  pdev -> w = pim->Width;
2606
0
  pdev -> dd = 0;
2607
0
  pdev -> bx = 0;
2608
0
  pdev -> by = 0;
2609
2610
0
  if (ty == cy) {
2611
    /* 回転時の描画については現在未実装。GS 側の機能を使用する */
2612
0
    return -1;
2613
0
  }
2614
2615
0
  if (pim->ImageMask) {
2616
0
    pdev->ncomp = 1;
2617
2618
    /* 描画論理設定命令 - 透過 */
2619
0
    if (pdev->MaskState != 1) {
2620
2621
0
      if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
2622
0
        gx_color_index color = gx_dc_pure_color(pdcolor);
2623
2624
        /*      lputs(s, ESC_GS "1owE");*/
2625
0
        (void)gs_sprintf(obuf, ESC_GS "1;1;%ldccE", color);
2626
0
        lputs(s, obuf);
2627
2628
0
        if (vdev->x_pixels_per_inch == 1200) {
2629
0
          lputs(s, ESC_GS "1;45;156htmE");
2630
0
        } else if (vdev->x_pixels_per_inch == 600) {
2631
0
          lputs(s, ESC_GS "1;45;106htmE");
2632
0
        } else {
2633
0
          lputs(s, ESC_GS "1;45;71htmE");
2634
0
        }
2635
2636
0
      } else {     /* ESC/Page-Color */
2637
2638
0
        lputs(s, ESC_GS "3;184wfE" ESC_GS "5;184wfE");
2639
0
        pdev->MaskState = 1;
2640
2641
0
      } /* ESC/Page-Color */
2642
2643
0
    }
2644
2645
0
  } else {
2646
2647
    /* 描画論理設定命令 - 白塗り */
2648
0
    if (pdev->MaskState != 0) {
2649
2650
0
      if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
2651
        /*    lputs(s, ESC_GS "1owE");*/ /* 184->204 */
2652
0
      } else {     /* ESC/Page-Color */
2653
0
        lputs(s, ESC_GS "3;204wfE" ESC_GS "5;204wfE");
2654
0
      } /* ESC/Page-Color */
2655
2656
0
      pdev->MaskState = 0;
2657
0
    }
2658
0
    pdev->ncomp = num_components;
2659
0
  }
2660
2661
0
  if (pdev -> reverse_y) return 0;
2662
2663
0
  escv_write_begin(dev, pie->bits_per_pixel, (int)imat.tx, (int)imat.ty, pie->width, pie->height, sx, sy, pdev -> roll);
2664
2665
0
  return 0;
2666
0
}
2667
2668
/* Process the next piece of an image. */
2669
static int
2670
#if GS_VERSION_MAJOR >= 6
2671
escv_image_plane_data(gx_image_enum_common_t *info, const gx_image_plane_t *planes, int height, int *rows_used)
2672
#else
2673
     escv_image_plane_data(gx_device *dev, gx_image_enum_common_t *info, const gx_image_plane_t *planes, int height)
2674
#endif
2675
0
{
2676
0
#if GS_VERSION_MAJOR >= 6
2677
0
  gx_device *dev = info->dev;
2678
0
#endif
2679
0
  gx_device_vector *const vdev = (gx_device_vector *) dev;
2680
0
  gx_device_escv *const pdev = (gx_device_escv *) dev;
2681
0
  gdev_vector_image_enum_t  *pie = (gdev_vector_image_enum_t *) info;
2682
2683
0
  int       y;
2684
0
  int       plane;
2685
0
  int       width_bytes, tbyte;
2686
0
  byte      *buf;
2687
2688
0
  if (pie->default_info) return gx_image_plane_data(pie->default_info, planes, height);
2689
2690
0
  gx_image_plane_data(pie->bbox_info, planes, height);
2691
2692
0
  {
2693
2694
0
#if GS_VERSION_MAJOR >= 6
2695
0
    if (height == 260)
2696
0
      height = 1;
2697
0
#endif
2698
0
    width_bytes = (pie->width * pie->bits_per_pixel / pdev->ncomp + 7) / 8 * pdev->ncomp;
2699
0
    tbyte = width_bytes * height;
2700
0
    buf = gs_alloc_bytes(vdev->memory, tbyte, "escv_image_data(buf)");
2701
2702
0
    if (pdev -> reverse_y) {
2703
2704
0
      if (pdev -> h == height) {
2705
0
        if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
2706
2707
0
          if(tbyte == 1){
2708
0
            if(strcmp(pdev->dname, "lp1800") != 0 &&
2709
0
               strcmp(pdev->dname, "lp9600") != 0) {
2710
0
              pdev->w += pdev->sx / 2048;
2711
0
              height  += pdev->sy / 2048;
2712
0
            }
2713
0
          }
2714
2715
0
        } else {     /* ESC/Page-Color */
2716
2717
0
          if(tbyte == 1){
2718
0
            pdev->w += pdev->sx / 2048;
2719
0
            height  += pdev->sy / 2048;
2720
0
          }
2721
2722
0
        } /* ESC/Page-Color */
2723
2724
0
        escv_write_begin(dev, pie->bits_per_pixel, (int)pdev -> xmat.tx, (int)pdev -> xmat.ty, pdev -> w, height, (int)pdev -> sx, (int)pdev -> sy, pdev -> roll);
2725
2726
0
      } else {
2727
0
        float yy, sy;
2728
2729
0
        yy = (pdev -> h * pdev->xmat.yy) - (pdev -> dd * pdev -> xmat.yy) - (height * pdev -> xmat.yy);
2730
0
        if (yy == 0) {
2731
0
          yy = (pdev -> h * pdev->xmat.yx) - (pdev -> dd * pdev -> xmat.yx) - (height * pdev -> xmat.yx);
2732
0
        }
2733
2734
0
        if (pdev -> by) {
2735
0
          sy = (int)pdev -> xmat.ty - (int)yy;
2736
0
          sy = pdev -> by - (int)sy;
2737
0
        } else {
2738
0
          sy = height * pdev -> xmat.yy + 0.5;
2739
0
        }
2740
0
        if (sy < 0) {
2741
0
          sy = -sy;
2742
0
        }
2743
2744
0
        escv_write_begin(dev, pie->bits_per_pixel, (int)pdev -> xmat.tx, (int)pdev -> xmat.ty - (int)yy, pdev -> w, height, (int)pdev -> sx, (int)sy, pdev -> roll);
2745
2746
0
        pdev -> by = (int)pdev -> xmat.ty - (int)yy;
2747
0
      }
2748
0
    }
2749
0
    pdev -> dd += height;
2750
2751
0
    for (plane = 0; plane < pie->num_planes; ++plane) {
2752
2753
0
      for (y = 0; y < height; ++y) {
2754
2755
0
        int     bit, w;
2756
0
        const byte *p;
2757
0
        byte *d;
2758
0
        byte c;
2759
2760
0
        p = planes[plane].data + ((planes[plane].data_x * pie->bits_per_pixel) >> 3) + y * planes[plane].raster;
2761
0
        if (pdev -> reverse_y) {
2762
2763
0
          d = buf + (height - y) * width_bytes;
2764
2765
0
          if (!pdev -> reverse_x) {
2766
0
            (void)memcpy(buf + (height - y - 1) * width_bytes,
2767
0
                         planes[plane].data + ((planes[plane].data_x * pie->bits_per_pixel) >> 3)
2768
0
                         + y * planes[plane].raster, width_bytes);
2769
2770
0
          }
2771
2772
0
        } else {
2773
2774
0
          d = buf + (y + 1) * width_bytes;
2775
2776
0
          if (!pdev -> reverse_x) {
2777
2778
0
            (void)memcpy(buf + y * width_bytes,
2779
0
                         planes[plane].data + ((planes[plane].data_x * pie->bits_per_pixel) >> 3)
2780
0
                         + y * planes[plane].raster, width_bytes);
2781
2782
0
          }
2783
0
        }
2784
0
        if (pdev -> reverse_x) {
2785
0
          if (pie->bits_per_pixel == 1) {
2786
0
            for (w = 0; w < width_bytes; w++) {
2787
0
              c = 0;
2788
0
              for (bit = 0; bit < 8; bit++) {
2789
0
                if (*p & 1 << (7 - bit)) {
2790
0
                  c |= 1 << bit;
2791
0
                }
2792
0
              }
2793
0
              p++;
2794
0
              *--d = c;
2795
0
            }
2796
0
          } else if (pie->bits_per_pixel == 8){
2797
0
            for (w = 0; w < width_bytes; w++) {
2798
0
              *--d = *p++;
2799
0
            }
2800
0
          } else {
2801
0
            for (w = 0; w < width_bytes / 3; w++) {
2802
0
              *--d = *(p + 2);
2803
0
              *--d = *(p + 1);
2804
0
              *--d = *p;
2805
0
              p += 3;
2806
0
            }
2807
0
          }
2808
0
        }
2809
0
      }
2810
0
    }
2811
2812
0
    if(tbyte == 1){
2813
0
      int t;
2814
2815
0
      if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
2816
2817
0
        gs_free_object(vdev->memory, buf, "escv_image_data(buf)");
2818
0
        if(strcmp(pdev->dname, "lp1800") == 0 ||
2819
0
           strcmp(pdev->dname, "lp9600") == 0) {
2820
0
          if(pdev->sx > pdev->sy){
2821
0
            height  = pdev->sy;
2822
0
            pdev->w = pdev->sx;
2823
0
            tbyte = ((pdev->sx + 7) / 8) * pdev->sy;
2824
0
          } else {
2825
0
            if(pdev->sx < pdev->sy){
2826
0
              height  = pdev->sy;
2827
0
              pdev->w = pdev->sx;
2828
0
              tbyte = ((pdev->sx + 7) / 8) * pdev->sy;
2829
0
            } else {
2830
0
              tbyte = 1;
2831
0
            }
2832
0
          }
2833
2834
0
        } else {
2835
0
          if(pdev->sx > pdev->sy){
2836
0
            tbyte = 1;
2837
0
          } else {
2838
0
            if(pdev->sx < pdev->sy){
2839
0
              tbyte = tbyte * height;
2840
0
            } else {
2841
0
              tbyte = 1;
2842
0
            }
2843
0
          }
2844
0
        }
2845
0
        buf = gs_alloc_bytes(vdev->memory, tbyte, "escv_image_data(buf)");
2846
0
        for(t = 0; t < tbyte; t++){
2847
0
          buf[t] = 0xff;
2848
0
        }
2849
2850
0
      } else {     /* ESC/Page-Color */
2851
2852
0
        gs_free_object(vdev->memory, buf, "escv_image_data(buf)");
2853
0
        if(pdev->sx > pdev->sy){
2854
0
          tbyte = 1;
2855
0
        } else {
2856
0
          if(pdev->sx < pdev->sy){
2857
0
            tbyte = tbyte * height;
2858
0
          } else {
2859
0
            tbyte = 1;
2860
0
          }
2861
0
        }
2862
2863
0
        buf = gs_alloc_bytes(vdev->memory, tbyte, "escv_image_data(buf)");
2864
0
        for(t = 0; t < tbyte; t++){
2865
0
          buf[t] = 0x00;
2866
0
        }
2867
2868
0
      } /* ESC/Page-Color */
2869
2870
0
    }
2871
2872
0
    escv_write_data(dev, pie->bits_per_pixel, buf, tbyte, pdev -> w, height);
2873
2874
0
    if (pdev -> reverse_y) {
2875
0
      escv_write_end(dev, pie->bits_per_pixel);
2876
0
    }
2877
2878
0
    gs_free_object(vdev->memory, buf, "escv_image_data(buf)");
2879
0
  }
2880
0
  return (pie->y += height) >= pie->height;
2881
0
}
2882
2883
static int
2884
#if GS_VERSION_MAJOR >= 6
2885
escv_image_end_image(gx_image_enum_common_t * info, bool draw_last)
2886
#else
2887
     escv_image_end_image(gx_device *dev, gx_image_enum_common_t * info, bool draw_last)
2888
#endif
2889
0
{
2890
0
#if GS_VERSION_MAJOR >= 6
2891
0
  gx_device *dev = info->dev;
2892
0
#endif
2893
0
  gx_device_vector    *const vdev = (gx_device_vector *) dev;
2894
0
  gx_device_escv    *const pdev = (gx_device_escv *) dev;
2895
0
  gdev_vector_image_enum_t  *pie = (gdev_vector_image_enum_t *) info;
2896
0
  int       code;
2897
2898
0
  if (!(pdev -> reverse_y)) {
2899
0
    escv_write_end(dev, pie->bits_per_pixel);
2900
0
  }
2901
2902
0
  pdev->reverse_x = pdev->reverse_y = 0;
2903
0
  if (pdev->MaskReverse == 0) {
2904
0
    if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
2905
0
      ;
2906
0
    } else {     /* ESC/Page-Color */
2907
2908
0
      stream      *s = gdev_vector_stream((gx_device_vector *)pdev);
2909
2910
0
      lputs(s, ESC_GS "8;1;2;2;2plr{E");
2911
0
      put_bytes(s, (const byte *)"\377\377\377\377\000\000\000\000", 8);
2912
0
    } /* ESC/Page-Color */
2913
0
  }
2914
0
  pdev->MaskReverse = -1;
2915
2916
0
  code = gdev_vector_end_image(vdev, (gdev_vector_image_enum_t *) pie, draw_last, pdev->white);
2917
0
  return code;
2918
0
}
2919
2920
static void escv_write_begin(gx_device *dev, int bits, int x, int y, int sw, int sh, int dw, int dh, int roll)
2921
0
{
2922
0
  gx_device_vector *const     vdev = (gx_device_vector *) dev;
2923
0
  gx_device_escv   *const     pdev = (gx_device_escv *)dev;
2924
0
  stream      *s = gdev_vector_stream((gx_device_vector *)dev);
2925
0
  char                          obuf[128];
2926
0
  byte                         *tmp, *p;
2927
0
  int       i, comp;
2928
2929
0
  if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
2930
2931
0
    (void)gs_sprintf(obuf, ESC_GS "%dX" ESC_GS "%dY", x, y);
2932
0
    lputs(s, obuf);
2933
2934
0
    comp = 10;
2935
2936
0
    if (bits == 1) {
2937
0
      if (strcmp(pdev->dname, "lp1800") == 0 ||
2938
0
          strcmp(pdev->dname, "lp9600") == 0) {
2939
0
        (void)gs_sprintf(obuf, ESC_GS "0bcI");
2940
0
      }else{
2941
0
        (void)gs_sprintf(obuf, ESC_GS "5;%d;%d;%d;%d;%dsrI",  sw, sh, dw, dh, roll);
2942
0
      }
2943
0
    } else if (bits == 4) {
2944
0
      if (pdev -> c4map) {
2945
0
        pdev -> c4map = FALSE;
2946
0
      }
2947
0
      (void)gs_sprintf(obuf, ESC_GS "1;1;1;0;%d;%d;%d;%d;%d;%dscrI", comp, sw, sh, dw, dh, roll);
2948
0
    } else if (bits == 8) {
2949
0
      if (pdev -> c8map) {
2950
0
        pdev -> c8map = FALSE;
2951
0
      }
2952
0
      (void)gs_sprintf(obuf, ESC_GS "1;1;1;0;%d;%d;%d;%d;%d;%dscrI", comp, sw, sh, dw, dh, roll);
2953
0
    } else {
2954
      /* 24 bit */
2955
0
      (void)gs_sprintf(obuf, ESC_GS "1;1;1;0;%d;%d;%d;%d;%d;%dscrI", comp, sw, sh, dw, dh, roll);
2956
0
    }
2957
2958
0
  } else {     /* ESC/Page-Color */
2959
2960
0
    (void)gs_sprintf(obuf, ESC_GS "%dX" ESC_GS "%dY", x, y);
2961
0
    lputs(s, obuf);
2962
2963
0
    comp = 0;
2964
2965
0
    if (bits == 1) {
2966
0
      (void)gs_sprintf(obuf, ESC_GS "2;201;1;%d;%d;%d;%d;%d;%dscrI", comp, sw, sh, dw, dh, roll);
2967
0
    } else if (bits == 4) {
2968
0
      if (pdev -> c4map) {
2969
        /* カラーマップ登録 */
2970
0
        lputs(s, ESC_GS "64;2;2;16;16plr{E");
2971
0
        p = tmp = gs_alloc_bytes(vdev->memory, 64, "escv_write_begin(tmp4)");
2972
0
        for (i = 0; i < 16; i++) {
2973
0
          *p++ = i << 4;
2974
0
          *p++ = i << 4;
2975
0
          *p++ = i << 4;
2976
0
          *p++ = i << 4;
2977
0
        }
2978
0
        put_bytes(s, tmp, 64);
2979
0
        gs_free_object(vdev->memory, tmp, "escv_write_begin(tmp4)");
2980
0
        pdev -> c4map = FALSE;
2981
0
      }
2982
0
      (void)gs_sprintf(obuf, ESC_GS "2;203;2;%d;%d;%d;%d;%d;%dscrI", comp, sw, sh, dw, dh, roll);
2983
0
    } else if (bits == 8) {
2984
0
      if (pdev -> c8map) {
2985
        /* カラーマップ登録 */
2986
0
        lputs(s, ESC_GS "1024;4;2;256;256plr{E");
2987
0
        p = tmp = gs_alloc_bytes(vdev->memory, 1024, "escv_write_begin(tmp)");
2988
0
        for (i = 0; i < 256; i++) {
2989
0
          *p++ = i;
2990
0
          *p++ = i;
2991
0
          *p++ = i;
2992
0
          *p++ = i;
2993
0
        }
2994
0
        put_bytes(s, tmp, 1024);
2995
0
        gs_free_object(vdev->memory, tmp, "escv_write_begin(tmp)");
2996
0
        pdev -> c8map = FALSE;
2997
0
      }
2998
0
      (void)gs_sprintf(obuf, ESC_GS "2;204;4;%d;%d;%d;%d;%d;%dscrI", comp, sw, sh, dw, dh, roll);
2999
0
    } else {
3000
      /* 24 bit */
3001
0
      (void)gs_sprintf(obuf, ESC_GS "2;102;0;%d;%d;%d;%d;%d;%dscrI", comp, sw, sh, dw, dh, roll);
3002
0
    }
3003
3004
0
  } /* ESC/Page-Color */
3005
3006
0
  lputs(s, obuf);
3007
3008
0
  return;
3009
0
}
3010
3011
static void escv_write_data(gx_device *dev, int bits, byte *buf, int bsize, int w, int ras)
3012
0
{
3013
0
  gx_device_vector *const  vdev = (gx_device_vector *) dev;
3014
0
  gx_device_escv   *const  pdev = (gx_device_escv *) dev;
3015
0
  stream      *s = gdev_vector_stream((gx_device_vector *)pdev);
3016
0
  char                     obuf[128];
3017
0
  int                      size;
3018
0
  byte                    *tmps, *p;
3019
0
  unsigned char           *rgbbuf;
3020
0
  unsigned char           *ucp;
3021
0
  double                   gray8;
3022
3023
0
  if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
3024
3025
0
    tmps = 0;
3026
3027
0
    if (bits == 12) {
3028
0
      p = tmps = gs_alloc_bytes(vdev->memory, bsize * 2, "escv_write_data(tmp)");
3029
0
      for (size = 0; size < bsize; size++) {
3030
0
        *p++ = buf[size] & 0xF0;
3031
0
        *p++ = buf[size] << 4;
3032
0
      }
3033
0
      bsize = bsize * 2;
3034
0
      buf = tmps;
3035
0
    }
3036
3037
0
    if(bits == 4) {
3038
0
      p = tmps = gs_alloc_bytes(vdev->memory, bsize * 2, "escv_write_data(tmp)");
3039
0
      for (size = 0; size < bsize; size++) {
3040
0
        *p++ = ((buf[size] & 0xF0) * 0xFF / 0xF0);
3041
0
        *p++ = ((buf[size] << 4 & 0xF0) * 0xFF / 0xF0);
3042
0
      }
3043
0
      bsize = bsize * 2;
3044
0
      buf = tmps;
3045
0
    }
3046
3047
0
    if(bits == 24) {   /* 8bit RGB */
3048
0
      tmps = gs_alloc_bytes(vdev->memory, bsize / 3, "escv_write_data(tmp)");
3049
3050
      /* convert 24bit RGB to 8bit Grayscale */
3051
0
      rgbbuf = buf;
3052
0
      ucp = tmps;
3053
0
      for (size = 0; size < bsize; size = size + 3) {
3054
0
        gray8 = (0.299L * rgbbuf[size]) + (0.587L * rgbbuf[size + 1]) + (0.114L * rgbbuf[size + 2]);
3055
0
        if ( gray8 > 255L )
3056
0
          *ucp = 255;
3057
0
        else
3058
0
          *ucp = gray8;
3059
0
        ucp++;
3060
0
      }
3061
0
      bsize = bsize / 3;
3062
0
      buf = tmps;
3063
0
    }
3064
3065
0
    if(bits == 1){
3066
0
      if (strcmp(pdev->dname, "lp1800") == 0 || \
3067
0
          strcmp(pdev->dname, "lp9600") == 0) {
3068
0
        (void)gs_sprintf(obuf, ESC_GS "%d;1;%d;%d;0db{I", bsize, w, ras);
3069
0
      }else{
3070
0
        (void)gs_sprintf(obuf, ESC_GS "%d;%du{I", bsize, ras);
3071
0
      }
3072
0
    }else{
3073
0
      (void)gs_sprintf(obuf, ESC_GS "%d;%dcu{I", bsize, ras);
3074
0
    }
3075
0
    lputs(s, obuf);
3076
3077
0
    put_bytes(s, buf, bsize);
3078
3079
0
    if (bits == 12 || bits == 4 || bits == 24) {
3080
0
      gs_free_object(vdev->memory, tmps, "escv_write_data(tmp)");
3081
0
    }
3082
3083
0
  } else {     /* ESC/Page-Color */
3084
3085
0
    char                        tmp;
3086
3087
0
    tmps = 0;
3088
0
    if (bits == 12) {
3089
0
      p = tmps = gs_alloc_bytes(vdev->memory, bsize * 2, "escv_write_data(tmp)");
3090
0
      for (size = 0; size < bsize; size++) {
3091
0
        tmp = buf[size] & 0xF0;
3092
0
        *p++ = (tmp + (tmp >> 4 & 0x0F));
3093
0
        tmp = buf[size] << 4;
3094
0
        *p++ = (tmp + (tmp >> 4 & 0x0F));
3095
0
      }
3096
0
      bsize = bsize * 2;
3097
0
      buf = tmps;
3098
0
    }
3099
3100
0
    (void)gs_sprintf(obuf, ESC_GS "%d;%dcu{I", bsize, ras);
3101
0
    lputs(s, obuf);
3102
0
    put_bytes(s, buf, bsize);
3103
3104
0
    if (bits == 12) {
3105
0
      gs_free_object(vdev->memory, tmps, "escv_write_data(tmp)");
3106
0
    }
3107
0
  } /* ESC/Page-Color */
3108
3109
0
  return;
3110
0
}
3111
3112
static void escv_write_end(gx_device *dev, int bits)
3113
0
{
3114
0
  gx_device_escv *const       pdev = (gx_device_escv *) dev;
3115
0
  stream      *s = gdev_vector_stream((gx_device_vector *)pdev);
3116
3117
0
  if( 0 == pdev->colormode ) { /* ESC/Page (Monochrome) */
3118
3119
0
    if(bits == 1){
3120
0
      if (strcmp(pdev->dname, "lp1800") == 0 || \
3121
0
          strcmp(pdev->dname, "lp9600") == 0) {
3122
0
        lputs(s, ESC_GS "1dbI");
3123
0
      } else {
3124
0
        lputs(s, ESC_GS "erI");
3125
0
      }
3126
0
    }else{
3127
0
      lputs(s, ESC_GS "ecrI");
3128
0
    }
3129
3130
0
  } else {     /* ESC/Page-Color */
3131
3132
0
    lputs(s, ESC_GS "ecrI");
3133
3134
0
  } /* ESC/Page-Color */
3135
3136
0
  return;
3137
0
}
3138
3139
/* end of file */