1 /* Copyright (C) EPSON KOWA Corp. 2000, 2001, 2002, 2003
2 
3    Ghostscript printer driver for EPSON ESC/Page
4 
5    This software is distributed in the hope that it will be useful, but
6    WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
7    to anyone for the consequences of using it or for whether it serves any
8    particular purpose or works at all, unless he says so in writing.  Refer
9    to the GNU General Public License for full details.
10 
11    Everyone is granted permission to copy, modify and redistribute
12    this software, but only under the conditions described in the GNU
13    General Public License.  A copy of this license is supposed to have been
14    given to you along with this software so you can know your rights and
15    responsibilities.  It should be in a file named COPYING.  Among other
16    things, the copyright notice and this notice must be preserved on all
17    copies.
18  */
19 
20 /*$Id: gdevesmv.c,v 1.1 2004/05/17 05:25:19 ishii Exp $ */
21 /* Vector Version of ESC/Page driver */
22 
23 /*
24    �ռ����翹���ͻ�� gdevl4v.c���ͤˤ����Ƥ�餤�ޤ�����
25 */
26 /*
27    ��Ghostscript 5.10/5.50 �ΥХ��ˤĤ���
28 
29    Ghostscript 5.10/5.50 �� Vector driver �� setlinewidth �ؿ��ˤ�
30    �Х�������ޤ������襹�����뤬�ѹ������ˤ������ä������������ѹ�����
31    �ʤ���Фʤ�ޤ�����Ghostscript 5.10/5.50 �Ǥϥ���������θ����Τ�
32    ˺��Ƥ��ޤ���
33    ���Υɥ饤�ФϤ��ΥХ�������뤿��˥��������ʬ�ǽ������Ƥ��ޤ���
34 
35  */
36 
37 #include "math_.h"
38 #include "gx.h"
39 #include "gserrors.h"
40 #include "gsmatrix.h"
41 #include "gsparam.h"
42 #include "gxdevice.h"
43 #include "gscspace.h"
44 #include "gsutil.h"
45 #include "gdevvec.h"
46 #include "spprint.h"
47 #if GS_VERSION_MAJOR == 5
48 #include "gdevpstr.h"
49 #endif
50 #include "ghost.h"
51 #include "gzstate.h"
52 #include "imemory.h"
53 #include "igstate.h"
54 #include "gdevescv.h"
55 #include "gspath.h"
56 #include "gzpath.h"
57 
58 #include <stdlib.h>
59 #include <unistd.h>
60 #include <string.h>
61 
62 /* ---------------- Device definition ---------------- */
63 
64 /* Device procedures */
65 private dev_proc_open_device(esmv_open);
66 private dev_proc_output_page(esmv_output_page);
67 private dev_proc_close_device(esmv_close);
68 private dev_proc_copy_mono(esmv_copy_mono);
69 private dev_proc_copy_color(esmv_copy_color);
70 private dev_proc_put_params(esmv_put_params);
71 private dev_proc_get_params(esmv_get_params);
72 private dev_proc_fill_mask(esmv_fill_mask);
73 private dev_proc_begin_image(esmv_begin_image);
74 
75 
76 #define	X_DPI		600
77 #define	Y_DPI		600
78 
79 typedef struct gx_device_esmv_s {
80     gx_device_vector_common;
81 
82     bool		manualFeed;			/* Use manual feed */
83     int			cassetFeed;			/* Input Casset */
84     bool		RITOff;				/* RIT Control */
85     bool		Collate;			/* �������� */
86     int			toner_density;			/* �ȥʡ�ǻ�� */
87     bool		toner_saving;			/* �ȥʡ������� */
88     int			prev_paper_size;
89     int			prev_paper_width;
90     int			prev_paper_height;
91     int			prev_num_copies;		/* */
92     int			prev_feed_mode;
93     int			orientation;			/* ���� */
94     bool		faceup;				/* �ե��������� */
95     int	                MediaType;			/* ��� */
96     bool		first_page;
97     bool		Duplex;				/* ξ�̰��� */
98     bool		Tumble;				/* �Ȥ����� */
99     int			ncomp;				/* */
100     int			MaskReverse;			/* ȿž���� */
101     int			MaskState;			/* */
102     bool		c4map;				/* 4bit ColorMap */
103     bool		c8map;				/* 8bit ColorMap */
104     int			prev_x;
105     int			prev_y;
106     gx_color_index	prev_color;
107     gx_color_index	current_color;			/* Current Color */
108     floatp		lwidth;
109     long		cap;
110     long		join;
111     long		reverse_x;
112     long		reverse_y;
113     gs_matrix		xmat;
114     int			bx, by;
115     int			w, h;
116     int			roll;
117     float		sx, sy;
118     long		dd;
119 } gx_device_esmv;
120 
121 
122 gs_public_st_suffix_add0_final(st_device_esmv, gx_device_esmv,
123       "gx_device_esmv", device_esmv_enum_ptrs, device_esmv_reloc_ptrs,
124 			       gx_device_finalize, st_device_vector);
125 
126 #define esmv_device_full_body(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, \
127 			      ncomp, depth, mg, mc, dg, dc, lm, bm, rm, tm)\
128         std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\
129         dci_values(ncomp, depth, mg, mc, dg, dc),\
130         std_device_part2_(w, h, xdpi, ydpi),\
131 	offset_margin_values(-lm * xdpi / 72.0, -tm * ydpi / 72.0, 0. / (MMETER_PER_INCH / POINT), 0, 0, 5. / (MMETER_PER_INCH / POINT)), \
132         std_device_part3_()
133 
134 
135 #define esmv_device_body(name)	\
136   esmv_device_full_body(gx_device_esmv, 0, name, \
137 				&st_device_esmv,\
138 /* width & height */		ESCPAGE_DEFAULT_WIDTH, ESCPAGE_DEFAULT_HEIGHT,\
139 /* default resolution */	X_DPI, Y_DPI,\
140 /* color info */	/*	3, 24, 255, 255, 256, 256,*/\
141 /* color info */		1, 8, 255, 255, 256, 256,\
142 				ESCPAGE_LEFT_MARGIN_DEFAULT,\
143 				ESCPAGE_BOTTOM_MARGIN_DEFAULT,\
144 				ESCPAGE_RIGHT_MARGIN_DEFAULT,\
145 				ESCPAGE_TOP_MARGIN_DEFAULT)
146 
147 #define esmv_procs	\
148 {\
149 	esmv_open,				/* open_device */\
150 	gx_default_get_initial_matrix,		/* get_initial_matrix */\
151 	NULL,					/* sync_output */\
152 	esmv_output_page,			/* output_page */\
153 	esmv_close,				/* close_device */\
154 /*	gx_default_rgb_map_rgb_color, */	/* map_rgb_color */\
155         gx_default_gray_map_rgb_color,\
156 /*      gx_default_rgb_map_color_rgb, */	/* map_color_rgb */\
157 	gx_default_gray_map_color_rgb,\
158 	gdev_vector_fill_rectangle,		/* fill_rectangle */\
159 	NULL,					/* tile_rectangle */\
160 	esmv_copy_mono,				/* dev_t_proc_copy_mono */\
161 	esmv_copy_color,			/* dev_t_proc_copy_color */\
162 	NULL,					/* draw_line */\
163 	NULL,					/* get_bits */\
164 	esmv_get_params,			/* dev_t_proc_get_params */\
165 	esmv_put_params,			/* dev_t_proc_put_params */\
166 	NULL,					/* map_cmyk_color */\
167 	NULL,					/* get_xfont_procs */\
168 	NULL,					/* get_xfont_device */\
169 	NULL,					/* map_rgb_alpha_color */\
170 	gx_page_device_get_page_device,		/* dev_t_proc_get_page_device */\
171 	NULL,					/* get_alpha_bits */\
172 	NULL,					/* copy_alpha */\
173 	NULL,					/* get_band */\
174 	NULL,					/* copy_rop */\
175 	gdev_vector_fill_path,			/* fill_path */\
176 	gdev_vector_stroke_path,		/* stroke_path */\
177 	esmv_fill_mask,				/* fill_mask */\
178 	gdev_vector_fill_trapezoid,		/* fill_trapezoid */\
179 	gdev_vector_fill_parallelogram,		/* fill_parallelogram */\
180 	gdev_vector_fill_triangle,		/* fill_triangle */\
181 	NULL,	/****** WRONG ******/		/* draw_thin_line */\
182 	esmv_begin_image,			/* begin_image */\
183 	NULL,					/* image_data */\
184 	NULL,					/* end_image */\
185 	NULL,					/* strip_tile_rectangle */\
186 	NULL					/******strip_copy_rop******/\
187 }
188 
189 
190 #define	esmv_init_code			\
191     vector_initial_values,\
192     ESCPAGE_MANUALFEED_DEFAULT,\
193     ESCPAGE_CASSETFEED_DEFAULT,\
194     ESCPAGE_RIT_DEFAULT,		/* RIT */\
195     FALSE,				/* Collate */\
196     0,					/* toner_density */\
197     FALSE,				/* toner_saving */\
198     0, 0, 0, 0, -1,\
199     0,					/* orientation */\
200     ESCPAGE_FACEUP_DEFAULT,\
201     ESCPAGE_MEDIATYPE_DEFAULT,\
202     0,					/* first_page */\
203     0,					/* Duplex */\
204     ESCPAGE_TUMBLE_DEFAULT,\
205     0,					/* ncomp */\
206     0,					/* MaskReverse */\
207     0,					/* MaskState */\
208     TRUE,				/* 4bits Color Map */\
209     TRUE,				/* 8bits Color Map */\
210     0,					/* prev_x */\
211     0,					/* prev_y */\
212     0,					/* prev_color */\
213     0,					/* current_color */\
214     3,					/* lwidth */\
215     0,					/* cap */\
216     3,					/* join */\
217     0,0,				/* reverse x, y */\
218     {}, 				/* matrix */\
219     0,0,				/* x, y */\
220     0,0,				/* width, hight */\
221     0,					/* roll */\
222     0,0,				/* scale x, y */\
223     0					/* */
224 
225 
226 gx_device_esmv far_data gs_lp9000b_device =
227 {
228     esmv_device_body("lp9000b"),
229     esmv_procs,
230     esmv_init_code
231 };
232 
233 gx_device_esmv far_data gs_lp2500_device =
234 {
235     esmv_device_body("lp2500"),
236     esmv_procs,
237     esmv_init_code
238 };
239 
240 gx_device_esmv far_data gs_lp9100_device =
241 {
242     esmv_device_body("lp9100"),
243     esmv_procs,
244     esmv_init_code
245 };
246 
247 gx_device_esmv far_data gs_lp7900_device =
248 {
249     esmv_device_body("lp7900"),
250     esmv_procs,
251     esmv_init_code
252 };
253 
254 gx_device_esmv far_data gs_lp7500_device =
255 {
256     esmv_device_body("lp7500"),
257     esmv_procs,
258     esmv_init_code
259 };
260 
261 gx_device_esmv far_data gs_lp2400_device =
262 {
263     esmv_device_body("lp2400"),
264     esmv_procs,
265     esmv_init_code
266 };
267 
268 gx_device_esmv far_data gs_lp8900_device =
269 {
270     esmv_device_body("lp8900"),
271     esmv_procs,
272     esmv_init_code
273 };
274 
275 gx_device_esmv far_data gs_lp7700_device =
276 {
277     esmv_device_body("lp7700"),
278     esmv_procs,
279     esmv_init_code
280 };
281 
282 gx_device_esmv far_data gs_lp2200_device =
283 {
284     esmv_device_body("lp2200"),
285     esmv_procs,
286     esmv_init_code
287 };
288 
289 gx_device_esmv far_data gs_lp9400_device =
290 {
291     esmv_device_body("lp9400"),
292     esmv_procs,
293     esmv_init_code
294 };
295 
296 gx_device_esmv far_data gs_lp8700_device =
297 {
298     esmv_device_body("lp8700"),
299     esmv_procs,
300     esmv_init_code
301 };
302 
303 gx_device_esmv far_data gs_lp8100_device =
304 {
305     esmv_device_body("lp8100"),
306     esmv_procs,
307     esmv_init_code
308 };
309 
310 gx_device_esmv far_data gs_lp1800_device =
311 {
312     esmv_device_body("lp1800"),
313     esmv_procs,
314     esmv_init_code
315 };
316 
317 gx_device_esmv far_data gs_lp9600_device =
318 {
319     esmv_device_body("lp9600"),
320     esmv_procs,
321     esmv_init_code
322 };
323 
324 gx_device_esmv far_data gs_lp9300_device =
325 {
326     esmv_device_body("lp9300"),
327     esmv_procs,
328     esmv_init_code
329 };
330 
331 gx_device_esmv far_data gs_lp8600_device =
332 {
333     esmv_device_body("lp8600"),
334     esmv_procs,
335     esmv_init_code
336 };
337 
338 gx_device_esmv far_data gs_lp8600f_device =
339 {
340     esmv_device_body("lp8600f"),
341     esmv_procs,
342     esmv_init_code
343 };
344 
345 gx_device_esmv far_data gs_lp8400f_device =
346 {
347     esmv_device_body("lp8400f"),
348     esmv_procs,
349     esmv_init_code
350 };
351 
352 gx_device_esmv far_data gs_lp8300f_device =
353 {
354     esmv_device_body("lp8300f"),
355     esmv_procs,
356     esmv_init_code
357 };
358 
359 gx_device_esmv far_data gs_lp1900_device =
360 {
361     esmv_device_body("lp1900"),
362     esmv_procs,
363     esmv_init_code
364 };
365 
366 gx_device_esmv far_data gs_lp9600s_device =
367 {
368     esmv_device_body("lp9600s"),
369     esmv_procs,
370     esmv_init_code
371 };
372 
373 gx_device_esmv far_data gs_epl6100_device =
374 {
375     esmv_device_body("epl6100"),
376     esmv_procs,
377     esmv_init_code
378 };
379 
380 gx_device_esmv far_data gs_epl5900_device =
381 {
382     esmv_device_body("epl5900"),
383     esmv_procs,
384     esmv_init_code
385 };
386 
387 gx_device_esmv far_data gs_epl5800_device =
388 {
389     esmv_device_body("epl5800"),
390     esmv_procs,
391     esmv_init_code
392 };
393 
394 gx_device_esmv far_data gs_epl2050_device =
395 {
396     esmv_device_body("epl2050"),
397     esmv_procs,
398     esmv_init_code
399 };
400 
401 gx_device_esmv far_data gs_epl2050p_device =
402 {
403     esmv_device_body("epl2050p"),
404     esmv_procs,
405     esmv_init_code
406 };
407 
408 gx_device_esmv far_data gs_epl2120_device =
409 {
410     esmv_device_body("epl2120"),
411     esmv_procs,
412     esmv_init_code
413 };
414 
415 gx_device_esmv far_data gs_epl2500_device =
416 {
417     esmv_device_body("epl2500"),
418     esmv_procs,
419     esmv_init_code
420 };
421 
422 gx_device_esmv far_data gs_epl2750_device =
423 {
424     esmv_device_body("epl2750"),
425     esmv_procs,
426     esmv_init_code
427 };
428 
429 
430 /* Vector device implementation */
431 #if GS_VERSION_MAJOR >= 8
432 private int esmv_beginpage(gx_device_vector * vdev);
433 private int esmv_setfillcolor(gx_device_vector * vdev, const gx_drawing_color * pdc);
434 private int esmv_setstrokecolor(gx_device_vector * vdev, const gx_drawing_color * pdc);
435 private int esmv_setdash(gx_device_vector * vdev, const float *pattern,
436 			      uint count, floatp offset);
437 private int esmv_setflat(gx_device_vector * vdev, floatp flatness);
438 private int esmv_setlogop(gx_device_vector * vdev, gs_logical_operation_t lop,
439 			       gs_logical_operation_t diff);
440 #else
441 private int esmv_beginpage(P1(gx_device_vector * vdev));
442 private int esmv_setfillcolor(P2(gx_device_vector * vdev, const gx_drawing_color * pdc));
443 private int esmv_setstrokecolor(P2(gx_device_vector * vdev, const gx_drawing_color * pdc));
444 private int esmv_setdash(P4(gx_device_vector * vdev, const float *pattern,
445 			      uint count, floatp offset));
446 private int esmv_setflat(P2(gx_device_vector * vdev, floatp flatness));
447 private int esmv_setlogop(P3(gx_device_vector * vdev, gs_logical_operation_t lop,
448 			       gs_logical_operation_t diff));
449 #endif
450 private int esmv_vector_dorect(gx_device_vector * vdev, fixed x0, fixed y0, fixed x1,
451 			       fixed y1, gx_path_type_t type);
452 private int esmv_vector_dopath(gx_device_vector * vdev, const gx_path * ppath,
453 			       gx_path_type_t type);
454 #if GS_VERSION_MAJOR >= 8
455 private int esmv_beginpath(gx_device_vector * vdev, gx_path_type_t type);
456 private int esmv_moveto(gx_device_vector * vdev, floatp x0, floatp y0,
457 			   floatp x, floatp y, gx_path_type_t type);
458 private int esmv_lineto(gx_device_vector * vdev, floatp x0, floatp y0,
459 			   floatp x, floatp y, gx_path_type_t type);
460 private int esmv_curveto(gx_device_vector * vdev, floatp x0, floatp y0,
461 			       floatp x1, floatp y1, floatp x2, floatp y2,
462 			       floatp x3, floatp y3, gx_path_type_t type);
463 private int esmv_closepath(gx_device_vector * vdev, floatp x, floatp y,
464 				floatp x_start, floatp y_start, gx_path_type_t type);
465 
466 private int esmv_endpath(gx_device_vector * vdev, gx_path_type_t type);
467 #else
468 private int esmv_beginpath(P2(gx_device_vector * vdev, gx_path_type_t type));
469 private int esmv_moveto(P6(gx_device_vector * vdev, floatp x0, floatp y0,
470 			   floatp x, floatp y, gx_path_type_t type));
471 private int esmv_lineto(P6(gx_device_vector * vdev, floatp x0, floatp y0,
472 			   floatp x, floatp y, gx_path_type_t type));
473 private int esmv_curveto(P10(gx_device_vector * vdev, floatp x0, floatp y0,
474 			       floatp x1, floatp y1, floatp x2, floatp y2,
475 			       floatp x3, floatp y3, gx_path_type_t type));
476 private int esmv_closepath(P6(gx_device_vector * vdev, floatp x, floatp y,
477 				floatp x_start, floatp y_start, gx_path_type_t type));
478 
479 private int esmv_endpath(P2(gx_device_vector * vdev, gx_path_type_t type));
480 #endif
481 private int esmv_setlinewidth(gx_device_vector * vdev, floatp width);
482 private int esmv_setlinecap(gx_device_vector * vdev, gs_line_cap cap);
483 private int esmv_setlinejoin(gx_device_vector * vdev, gs_line_join join);
484 private int esmv_setmiterlimit(gx_device_vector * vdev, floatp limit);
485 
486 private void esmv_write_begin(gx_device *, int, int, int, int, int, int, int, int);
487 private void esmv_write_data(gx_device *, int, char *, int, int, int);
488 private void esmv_write_end(gx_device *, int);
489 
490 
491 private const gx_device_vector_procs esmv_vector_procs =
492 {
493 	/* Page management */
494     esmv_beginpage,
495 	/* Imager state */
496     esmv_setlinewidth,
497     esmv_setlinecap,
498     esmv_setlinejoin,
499     esmv_setmiterlimit,
500     esmv_setdash,
501     esmv_setflat,
502     esmv_setlogop,
503 	/* Other state */
504     esmv_setfillcolor,	/* fill & stroke colors are the same */
505     esmv_setstrokecolor,
506 	/* Paths */
507     esmv_vector_dopath,
508     esmv_vector_dorect,
509     esmv_beginpath,
510     esmv_moveto,
511     esmv_lineto,
512     esmv_curveto,
513     esmv_closepath,
514     esmv_endpath
515 };
516 
517 /* ---------------- Utilities ---------------- */
518 
519 /* Put a string on a stream.
520    This function is copy of `pputs' in gdevpstr.c */
521 private int
lputs(stream * s,const char * str)522 lputs(stream * s, const char *str)
523 {
524     uint	len = strlen(str);
525     uint	used;
526     int		status;
527 
528     status = sputs(s, (const byte *)str, len, &used);
529 
530     return (status >= 0 && used == len ? 0 : EOF);
531 }
532 
533 /* Write a string on a stream. */
534 private void
put_bytes(stream * s,const byte * data,uint count)535 put_bytes(stream * s, const byte * data, uint count)
536 {
537     uint used;
538 
539     sputs(s, data, count, &used);
540 }
541 
542 
543 private int
esmv_range_check(gx_device * dev)544 esmv_range_check(gx_device * dev)
545 {
546     int width = dev->MediaSize[0];
547     int height = dev->MediaSize[1];
548     int xdpi = dev->x_pixels_per_inch;
549     int ydpi = dev->y_pixels_per_inch;
550 
551     /* Paper Size Check */
552     if (width <= height) {	/* portrait */
553 	if ((width < ESCPAGE_WIDTH_MIN || width > ESCPAGE_WIDTH_MAX ||
554 	     height < ESCPAGE_HEIGHT_MIN || height > ESCPAGE_HEIGHT_MAX) &&
555 	    !(width == ESCPAGE_LEDGER_WIDTH && height == ESCPAGE_LEDGER_HEIGHT))
556 	    return_error(gs_error_rangecheck);
557     } else {			/* landscape */
558 	if ((width < ESCPAGE_HEIGHT_MIN || width > ESCPAGE_HEIGHT_MAX ||
559 	     height < ESCPAGE_WIDTH_MIN || height > ESCPAGE_WIDTH_MAX) &&
560 	    !(width == ESCPAGE_LEDGER_HEIGHT && height == ESCPAGE_LEDGER_WIDTH))
561 	    return_error(gs_error_rangecheck);
562     }
563 
564     /* Resolution Check */
565     if (xdpi != ydpi)
566 	return_error(gs_error_rangecheck);
567     else {
568 	if ((xdpi < ESCPAGE_DPI_MIN || xdpi > ESCPAGE_DPI_MAX) && xdpi != ESCPAGE_DPI_SUPERFINE)
569 	    return_error(gs_error_rangecheck);
570     }
571 
572     return 0;
573 }
574 
575 
576 /* ---------------- Vector device implementation ---------------- */
577 
578 int
esmv_vector_dopath(gx_device_vector * vdev,const gx_path * ppath,gx_path_type_t type)579 esmv_vector_dopath(gx_device_vector * vdev, const gx_path * ppath,
580 		   gx_path_type_t type)
581 {
582     bool do_close = (type & gx_path_type_stroke) != 0;
583     gs_fixed_rect rect;
584     gs_point scale;
585     double x_start = 0, y_start = 0, x_prev = 0, y_prev = 0;
586     bool first = true;
587     gs_path_enum cenum;
588     int code;
589 
590     stream	*s = gdev_vector_stream(vdev);
591     char	obuf[128];
592 
593     if (gx_path_is_rectangle(ppath, &rect))
594 	return (*vdev_proc(vdev, dorect)) (vdev, rect.p.x, rect.p.y, rect.q.x, rect.q.y, type);
595     scale = vdev->scale;
596     code = (*vdev_proc(vdev, beginpath)) (vdev, type);
597     gx_path_enum_init(&cenum, ppath);
598 
599     for (;;) {
600 	double	x, y;
601 	fixed	vs[6];
602 	int	pe_op, cnt;
603 	segment *pseg;
604 
605 
606 	pe_op = gx_path_enum_next(&cenum, (gs_fixed_point *) vs);
607 
608       sw:switch (pe_op) {
609 	    case 0:		/* done */
610 		return (*vdev_proc(vdev, endpath)) (vdev, type);
611 
612 	    case gs_pe_moveto:
613 		x = fixed2float(vs[0]) / scale.x;
614 		y = fixed2float(vs[1]) / scale.y;
615 
616 		/* ���֥ѥ�����̿�� p1 */
617 		(void)sprintf(obuf, ESC_GS "0;%d;%dmvpG", (int)x, (int)y);
618 		lputs(s, obuf);
619 
620 		if (first)
621 		    x_start = x, y_start = y, first = false;
622 		break;
623 
624 	    case gs_pe_lineto:
625 		cnt = 1;
626 		for (pseg = cenum.pseg; pseg != 0 && pseg->type == s_line; cnt++, pseg = pseg->next);
627 
628 		(void)sprintf(obuf, ESC_GS "0;%d", cnt);
629 		lputs(s, obuf);
630 
631 		do {
632 		    (void)sprintf(obuf, ";%d;%d", (int)(fixed2float(vs[0]) / scale.x), (int)(fixed2float(vs[1]) / scale.y));
633 		    lputs(s, obuf);
634 
635 		    pe_op = gx_path_enum_next(&cenum, (gs_fixed_point *) vs);
636 		} while (pe_op == gs_pe_lineto);
637 
638 		/* �ѥ����ݥ�饤��̿�� */
639 		lputs(s, "lnpG");
640 
641 		goto sw;
642 
643 	    case gs_pe_curveto:
644 		cnt = 1;
645 		for (pseg = cenum.pseg; pseg != 0 && pseg->type == s_curve; cnt++, pseg = pseg->next);
646 		(void)sprintf(obuf, ESC_GS "0;%d", cnt * 3);
647 		lputs(s, obuf);
648 
649 		do {
650 		    (void)sprintf(obuf, ";%d;%d;%d;%d;%d;%d",
651 				  (int)(fixed2float(vs[0]) / scale.x), (int)(fixed2float(vs[1]) / scale.y),
652 				  (int)(fixed2float(vs[2]) / scale.x), (int)(fixed2float(vs[3]) / scale.y),
653 				  (int)(fixed2float(vs[4]) / scale.x), (int)(fixed2float(vs[5]) / scale.y));
654 		    lputs(s, obuf);
655 
656 		    pe_op = gx_path_enum_next(&cenum, (gs_fixed_point *) vs);
657 		} while (pe_op == gs_pe_curveto);
658 
659 		/* �٥������� */
660 		lputs(s, "bzpG");
661 
662 		goto sw;
663 
664 	    case gs_pe_closepath:
665 		x = x_start, y = y_start;
666 		if (do_close) {
667 		    lputs(s, ESC_GS "clpG");
668 		    break;
669 		}
670 
671 		pe_op = gx_path_enum_next(&cenum, (gs_fixed_point *) vs);
672 		if (pe_op != 0) {
673 		    lputs(s, ESC_GS "clpG");
674 
675 		    if (code < 0)
676 			return code;
677 		    goto sw;
678 		}
679 		return (*vdev_proc(vdev, endpath)) (vdev, type);
680 	    default:		/* can't happen */
681 		return_error(gs_error_unknownerror);
682 	}
683 	if (code < 0)
684 	    return code;
685 	x_prev = x, y_prev = y;
686     }
687 }
688 
689 
690 int
esmv_vector_dorect(gx_device_vector * vdev,fixed x0,fixed y0,fixed x1,fixed y1,gx_path_type_t type)691 esmv_vector_dorect(gx_device_vector * vdev, fixed x0, fixed y0, fixed x1,
692 		   fixed y1, gx_path_type_t type)
693 {
694     int		code;
695     char	obuf[128];
696     gs_point	scale;
697     stream	*s = gdev_vector_stream(vdev);
698 
699     code = (*vdev_proc(vdev, beginpath))(vdev, type);
700     if (code < 0)
701 	return code;
702 
703     scale = vdev->scale;
704 
705     (void)sprintf(obuf, ESC_GS "0;%d;%d;%d;%d;0;0rrpG", (int)(fixed2float(x0) / scale.x), (int)(fixed2float(y0) / scale.y), (int)(fixed2float(x1) / scale.x), (int)(fixed2float(y1) / scale.y));
706     lputs(s, obuf);
707 
708 #if 0
709     /* Ghostscript ¦�ΥХ��� closepath ��Ƥ�Ǥ��ʤ��Τǽ������碌�롣 */
710 
711     /* ����� (*vdev_proc(vdev, closepath))() ��Ƥ֤٤� */
712     lputs(s, ESC_GS "clpG");
713 #endif
714 
715     return (*vdev_proc(vdev, endpath))(vdev, type);
716 }
717 
718 
719 /* ---------- */
720 
721 
722 typedef struct {
723     int		width;			/* paper width (unit: point) */
724     int		height;			/* paper height (unit: point) */
725     int		escpage;		/* number of papersize in ESC/PAGE */
726     char	*name;			/* Paper Name */
727 } EPaperTable;
728 
729 private const EPaperTable ePaperTable[24] =
730 {
731     {933, 1369, 72, "A3PLUS"},		/* A3 NOBI */
732     {842, 1190, 13, "A3"},		/* A3 */
733     {595, 842, 14, "A4"},		/* A4 */
734     {421, 595, 15, "A5"},		/* A5 */
735     {709, 1002, 24, "B4"},		/* B4 */
736     {729, 1032, 24, "B4"},		/* B4 JIS */
737     {516, 729, 25, "B5"},		/* B5 JIS */
738     {612, 792, 30, "LT"},		/* Letter */
739     {396, 612, 31, "HLT"},		/* Half Letter */
740     {612, 1008, 32, "LGL"},		/* Legal */
741     {522, 756, 33, "EXE"},		/* Executive */
742     {612, 936, 34, "GLG"},              /* Government Letter */ /* LPD.1. */
743     {576, 756, 35, "GLT"},              /* Government Legal */ /* LPD.1. */
744     {792, 1224, 36, "B"},		/* Ledger */
745     {593, 935, 37, "F4"},		/* F4 */
746     {284, 419, 38, "POSTCARD"},		/* PostCard */
747     {298, 666, 64, "YOU4"},             /* Japanese Envelope You4 */
748     {279, 540, 80, "MON"},		/* Monarch */
749     {297, 684, 81, "C10"},		/* Commercial 10 */
750     {312, 624, 90, "DL"},		/* DL */
751     {459, 649, 91, "C5"},               /* Envelope C5 */
752     {501, 709, 99, "IB5"},              /* Envelope ISO B5 */
753     {0, 0, -1, NULL}			/* Undefined */
754 };
755 
756 private int
757 
esmv_beginpage(gx_device_vector * vdev)758 esmv_beginpage(gx_device_vector * vdev)
759 {
760     gx_device_esmv	*const pdev = (gx_device_esmv *)vdev;
761     /* gdev_vector_stream �ϻ��Ѷػ� */
762     stream		*s = vdev->strm;
763     char		ebuf[1024];
764     int			w, h;
765     EPaperTable		*pt;
766     int			MaxRes;
767     int			Local;
768     int			Duplex;
769     int			FaceUp;
770 
771     if (pdev -> first_page) {
772 
773 	if (strcmp(pdev->dname, "lp9600s") == 0 || \
774 	    strcmp(pdev->dname, "lp9600")  == 0 || \
775 	    strcmp(pdev->dname, "lp9400")  == 0 || \
776 	    strcmp(pdev->dname, "lp9300")  == 0 || \
777 	    strcmp(pdev->dname, "lp9100")  == 0 || \
778 	    strcmp(pdev->dname, "lp9000b")  == 0 || \
779 	    strcmp(pdev->dname, "lp8900")  == 0 || \
780 	    strcmp(pdev->dname, "lp8600f") == 0 || \
781 	    strcmp(pdev->dname, "lp8600")  == 0 || \
782 	    strcmp(pdev->dname, "lp8400f") == 0 || \
783 	    strcmp(pdev->dname, "lp8300f") == 0 || \
784 	    strcmp(pdev->dname, "lp8100")  == 0 || \
785 	    strcmp(pdev->dname, "lp7900")  == 0 || \
786 	    strcmp(pdev->dname, "lp7700")  == 0 || \
787 	    strcmp(pdev->dname, "lp7500")  == 0) {
788 	    MaxRes = RES600;
789 	    Local  = JPN;
790 	    Duplex = TRUE;
791 	    FaceUp = FALSE;
792 	} else if (strcmp(pdev->dname, "lp1800") == 0) {
793 	    MaxRes = RES600;
794 	    Local  = JPN;
795 	    Duplex = FALSE;
796 	    FaceUp = FALSE;
797 	} else if (strcmp(pdev->dname, "lp8700") == 0) {
798 	    MaxRes = RES1200;
799 	    Local  = JPN;
800 	    Duplex = TRUE;
801 	    FaceUp = FALSE;
802 	} else if (strcmp(pdev->dname, "lp2200") == 0 || \
803 	    strcmp(pdev->dname, "lp2500") == 0 || \
804 	    strcmp(pdev->dname, "lp2400") == 0 || \
805 	    strcmp(pdev->dname, "lp1900") == 0) {
806 	    MaxRes = RES1200;
807 	    Local  = JPN;
808 	    Duplex = FALSE;
809 	    FaceUp = FALSE;
810 	} else if (strcmp(pdev->dname, "epl5900") == 0 || \
811 	    strcmp(pdev->dname, "epl6100") == 0 || \
812 	    strcmp(pdev->dname, "epl5800") == 0) {
813 	    MaxRes = RES1200;
814 	    Local  = ENG;
815 	    Duplex = FALSE;
816 	    FaceUp = FALSE;
817 	} else if (strcmp(pdev->dname, "epl2050") == 0 || \
818 	    strcmp(pdev->dname, "epl2050p") == 0 || \
819 	    strcmp(pdev->dname, "epl2120") == 0) {
820 	    MaxRes = RES1200;
821 	    Local  = ENG;
822 	    Duplex = TRUE;
823 	    FaceUp = FALSE;
824 	} else if (strcmp(pdev->dname, "epl2750") == 0 || \
825 	    strcmp(pdev->dname, "epl2500") == 0) {
826 	    MaxRes = RES600;
827 	    Local  = ENG;
828 	    Duplex = TRUE;
829 	    FaceUp = FALSE;
830 	} else {
831 	    MaxRes = RES600;
832 	    Local  = JPN;
833 	    Duplex = FALSE;
834 	    FaceUp = FALSE;
835 	}
836 
837 	lputs(s, "\033\001@EJL \012@EJL SJ ID=\"Ghostscript\"\012");
838 
839 	lputs(s, "@EJL SE LA=ESC/PAGE\012");
840 
841 	lputs(s, "@EJL SET");
842 
843 	/* Resolusion */
844 	if (vdev->x_pixels_per_inch == 1200){
845 	    if (MaxRes == 1200){
846 	    	lputs(s, " RS=1200");
847 	    } else {
848 	        lputs(s, " RS=FN");
849 	    }
850 	} else if (vdev->x_pixels_per_inch == 600) {
851 	    lputs(s, " RS=FN");
852 	} else {
853 	    lputs(s, " RS=QK");
854 	}
855 
856 	/* Output Unit */
857         if ((pdev->faceup && FaceUp) || (pdev->MediaType && FaceUp)) {
858             lputs(s, " OU=FU");
859         } else {
860             lputs(s, " OU=FD");
861         }
862 
863 	/* Paper unit */
864         if (pdev->MediaType){
865 	    if (Local == ENG){
866 		lputs(s, " PU=1");
867 	    } else {
868 		lputs(s, " PU=15");
869 	    }
870 	}else{
871 	    if (pdev->manualFeed) {
872 		if (Local == ENG){
873 		    lputs(s, " PU=1");
874 		} else {
875 	            lputs(s, " PU=15");
876 		}
877 	    } else if (pdev->cassetFeed) {
878 	        (void)sprintf(ebuf, " PU=%d", pdev->cassetFeed);
879 	        lputs(s, ebuf);
880 	    } else {
881 	        lputs(s, " PU=AU");
882 	    }
883 	}
884 
885 	if (Duplex && pdev->Duplex) {
886 	    /* ξ�̰������� */
887 	    lputs(s, " DX=ON");
888 
889 	    /* �Ȥ����� */
890 	    if (pdev->Tumble) {
891 		lputs(s, " BD=SE");
892 	    } else {
893 		lputs(s, " BD=LE");
894 	    }
895 	} else {
896 	    /* ξ�̰���off */
897 	    lputs(s, " DX=OFF");
898 	}
899 
900 	/* �������� */
901 	if (pdev->NumCopies) {
902 	    if (pdev->NumCopies >= 1000) {
903 		pdev->NumCopies = 999;
904 	    }
905 
906 	    if (pdev->Collate) {
907 	      /* QT ����ꤷ����� CO �� 1 */
908 	      (void)sprintf(ebuf, " QT=%d CO=1", pdev->NumCopies);
909 	    } else {
910 	      /* QT ����ꤷ�ʤ��ä���� QT �� 1 */
911 	      (void)sprintf(ebuf, " QT=1 CO=%d", pdev->NumCopies);
912 	    }
913 
914 	    lputs(s, ebuf);
915 	} else {
916 	    lputs(s, " QT=1 CO=1");
917 	}
918 
919 	if (pdev->toner_density) {
920 	    (void)sprintf(ebuf, " DL=%d", pdev->toner_density);
921 	    lputs(s, ebuf);
922 	}
923 
924 	if (pdev->orientation) {
925 	    lputs(s, " OR=LA");
926 	}
927 
928 	if (pdev->toner_saving) {
929 	    lputs(s, " SN=ON");
930 	}
931 
932 	if (pdev->RITOff) {
933 	    lputs(s, " RI=OFF");
934 	} else {
935 	    lputs(s, " RI=ON");
936 	}
937 
938 	if (pdev->MediaType == 1) {
939 	    lputs(s, " PK=TH");
940 	} else if (pdev->MediaType == 2) {
941 	    lputs(s, " PK=TR");
942 	} else {
943 	    lputs(s, " PK=NM");
944 	}
945 
946 	if (pdev->MediaSize[0] < pdev->MediaSize[1]) {
947 	    w = pdev->MediaSize[0];
948 	    h = pdev->MediaSize[1];
949 	} else {
950 	    w = pdev->MediaSize[1];
951 	    h = pdev->MediaSize[0];
952 	}
953 
954 	for (pt = ePaperTable; pt->escpage > 0; pt++)
955 	    if (pt->width == w && pt->height == h)
956 		break;
957 	if (pt->name == NULL) {
958 	    lputs(s, " PS=A4");
959 	} else {
960 	    (void)sprintf(ebuf, " PS=%s", pt->name);
961 	    lputs(s, ebuf);
962 	}
963 
964 	lputs(s, " ZO=OFF EC=ON SZ=OFF SL=YES TO=0.0MM LO=0.0MM\012");
965 	lputs(s, "@EJL EN LA=ESC/PAGE\012");
966 
967 #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"
968 
969 #define	STRAT_CODE	ESC_GS "1mmE" ESC_GS "1csE"
970 
971 	lputs(s, ESC_GS "rhE");
972 
973 	lputs(s, STRAT_CODE);
974 
975 	if (vdev->x_pixels_per_inch == 1200) {
976 	    /* 1200 dpi */
977 	    lputs(s, ESC_GS "0;0.06muE");
978 	    lputs(s, ESC_GS "1;45;156htmE");
979 	    lputs(s, ESC_GS "9;1200;1200drE" ESC_GS "2;1200;1200drE" ESC_GS "1;1200;1200drE" ESC_GS "0;1200;1200drE");
980 	    lputs(s, ESC_GS "1;1;raE");
981 	} else if (vdev->x_pixels_per_inch == 600) {
982 	    /* 600 dpi */
983 	    lputs(s, ESC_GS "0;0.12muE");
984 	    lputs(s, ESC_GS "1;45;106htmE");
985 	    lputs(s, ESC_GS "9;600;600drE" ESC_GS "2;600;600drE" ESC_GS "1;600;600drE" ESC_GS "0;600;600drE");
986 	} else {
987 	    /* 300 dpi */
988 	    lputs(s, ESC_GS "0;0.24muE");
989 	    lputs(s, ESC_GS "1;45;71htmE");
990 	    lputs(s, ESC_GS "9;300;300drE" ESC_GS "2;300;300drE" ESC_GS "1;300;300drE" ESC_GS "0;300;300drE");
991 	}
992 
993 	lputs(s, START_CODE1);
994 
995 	lputs(s, ESC_GS "0sarG");		/* ���к�ɸ���� */
996 	/*	lputs(s, ESC_GS "1owE");*/
997     }
998 
999     return 0;
1000 }
1001 
1002 
1003 private int
esmv_setlinewidth(gx_device_vector * vdev,floatp width)1004 esmv_setlinewidth(gx_device_vector * vdev, floatp width)
1005 {
1006     stream			*s = gdev_vector_stream(vdev);
1007     gx_device_esmv *const	pdev = (gx_device_esmv *) vdev;
1008     char			obuf[64];
1009 
1010 #if GS_VERSION_MAJOR == 5
1011     /* Scale ��ݤ��Ƥ���Τ�, Ghostscript 5.10/5.50 �ΥХ��Τ��� */
1012     floatp xscale, yscale;
1013 
1014     xscale = fabs(igs->ctm.xx);
1015     yscale = fabs(igs->ctm.xy);
1016 
1017     if (xscale == 0 || yscale > xscale)		/* if portrait */
1018 	width = ceil(width * yscale);
1019     else
1020 	width = ceil(width * xscale);
1021 #endif
1022 
1023     if (width < 1) width = 1;
1024 
1025     /* ESC/Page �Ǥ���������ü���ܹ���������ϣ��ĤΥ��ޥ�ɤˤʤäƤ��뤿���ݻ����Ƥ����� */
1026     pdev -> lwidth = width;
1027 
1028     (void)sprintf(obuf, ESC_GS "%d;%d;%dlwG", (int)(pdev -> lwidth), (int)(pdev -> cap), (int)(pdev -> join));
1029     lputs(s, obuf);
1030 
1031     return 0;
1032 }
1033 
1034 
1035 private int
esmv_setlinecap(gx_device_vector * vdev,gs_line_cap cap)1036 esmv_setlinecap(gx_device_vector * vdev, gs_line_cap cap)
1037 {
1038     stream			*s = gdev_vector_stream(vdev);
1039     gx_device_esmv *const	pdev = (gx_device_esmv *) vdev;
1040     char			obuf[64];
1041 
1042     /* ESC/Page �Ǥ���������ü���ܹ���������ϣ��ĤΥ��ޥ�ɤˤʤäƤ��뤿���ݻ����Ƥ����� */
1043     pdev -> cap = cap;
1044 
1045     if (pdev -> cap >= 3) return -1;
1046 
1047     (void)sprintf(obuf, ESC_GS "%d;%d;%dlwG", (int)(pdev -> lwidth), (int)(pdev -> cap), (int)(pdev -> join));
1048     lputs(s, obuf);
1049 
1050     return 0;
1051 }
1052 
1053 
1054 private int
esmv_setlinejoin(gx_device_vector * vdev,gs_line_join join)1055 esmv_setlinejoin(gx_device_vector * vdev, gs_line_join join)
1056 {
1057     stream			*s = gdev_vector_stream(vdev);
1058     gx_device_esmv *const	pdev = (gx_device_esmv *) vdev;
1059     char			obuf[64];
1060 
1061     /* ESC/Page �Ǥ���������ü���ܹ���������ϣ��ĤΥ��ޥ�ɤˤʤäƤ��뤿���ݻ����Ƥ����� */
1062     switch (join) {
1063     case 0:
1064 	pdev -> join = 3;		/* miter */
1065 	break;
1066     case 1:
1067 	pdev -> join = 1;		/* round */
1068 	break;
1069     case 2:
1070 	pdev -> join = 2;		/* bevel */
1071 	break;
1072     default:
1073 	return -1;
1074     }
1075 
1076     (void)sprintf(obuf, ESC_GS "%d;%d;%dlwG", (int)(pdev -> lwidth), (int)(pdev -> cap), (int)(pdev -> join));
1077     lputs(s, obuf);
1078 
1079     return 0;
1080 }
1081 
1082 
1083 private int
esmv_setmiterlimit(gx_device_vector * vdev,floatp limit)1084 esmv_setmiterlimit(gx_device_vector * vdev, floatp limit)
1085 {
1086     stream			*s = gdev_vector_stream(vdev);
1087     gx_device_esmv *const	pdev = (gx_device_esmv *) vdev;
1088     char			obuf[128];
1089 
1090     /* �ޥ�������ߥå��ͤ����ꤹ��ˤ� lwG �ˤ� �ܹ�������(n3) �� 3 �ˤʤäƤ���
1091     ** ɬ�פ����롣
1092     */
1093     if (pdev -> join != 3) {
1094 	/* ����Ū���ܹ��������Ԥ� */
1095 	pdev -> join = 3;
1096 	(void)sprintf(obuf, ESC_GS "%d;%d;%dlwG", (int)(pdev -> lwidth), (int)(pdev -> cap), (int)(pdev -> join));
1097 	lputs(s, obuf);
1098     }
1099 
1100     (void)sprintf(obuf, ESC_GS "1;%dmlG", (int)limit);
1101     lputs(s, obuf);
1102 
1103     return 0;
1104 }
1105 
1106 
1107 private int
esmv_setfillcolor(gx_device_vector * vdev,const gx_drawing_color * pdc)1108 esmv_setfillcolor(gx_device_vector * vdev, const gx_drawing_color * pdc)
1109 {
1110     stream			*s = gdev_vector_stream(vdev);
1111     gx_device_esmv *const	pdev = (gx_device_esmv *) vdev;
1112     gx_color_index		color = gx_dc_pure_color(pdc);
1113     char			obuf[64];
1114 
1115     if (!gx_dc_is_pure(pdc)) return_error(gs_error_rangecheck);
1116     pdev->current_color = color;
1117 
1118     (void)sprintf(obuf, /*ESC_GS "1owE"*/ ESC_GS "0;0;100spE" ESC_GS "1;0;%dccE" ,color);
1119     lputs(s, obuf);
1120 
1121     if (vdev->x_pixels_per_inch == 1200) {
1122       lputs(s, ESC_GS "1;45;156htmE");
1123     } else if (vdev->x_pixels_per_inch == 600) {
1124       lputs(s, ESC_GS "1;45;106htmE");
1125     } else {
1126       lputs(s, ESC_GS "1;45;71htmE");
1127     }
1128 
1129     return 0;
1130 }
1131 
1132 
1133 private int
esmv_setstrokecolor(gx_device_vector * vdev,const gx_drawing_color * pdc)1134 esmv_setstrokecolor(gx_device_vector * vdev, const gx_drawing_color * pdc)
1135 {
1136     stream			*s = gdev_vector_stream(vdev);
1137     gx_device_esmv *const	pdev = (gx_device_esmv *) vdev;
1138     gx_color_index		color = gx_dc_pure_color(pdc);
1139     char			obuf[64];
1140 
1141     if (!gx_dc_is_pure(pdc)) return_error(gs_error_rangecheck);
1142 
1143   /*    if (vdev->color_info.depth == 24) {*/
1144 
1145 	pdev->current_color = color;
1146 
1147 	(void)sprintf(obuf, /*ESC_GS "1owE"*/ ESC_GS "0;0;100spE" ESC_GS "1;1;%dccE" , color);
1148 	lputs(s, obuf);
1149 
1150 	if (vdev->x_pixels_per_inch == 1200) {
1151 	  lputs(s, ESC_GS "1;45;156htmE");
1152 	} else if (vdev->x_pixels_per_inch == 600) {
1153 	  lputs(s, ESC_GS "1;45;106htmE");
1154 	} else {
1155 	  lputs(s, ESC_GS "1;45;71htmE");
1156 	}
1157 
1158     return 0;
1159 }
1160 
1161 
1162 /* �������̿�� */
1163 private int
esmv_setdash(gx_device_vector * vdev,const float * pattern,uint count,floatp offset)1164 esmv_setdash(gx_device_vector * vdev, const float *pattern, uint count, floatp offset)
1165 {
1166     stream			*s = gdev_vector_stream(vdev);
1167     int				i;
1168     char			obuf[64];
1169 
1170 #if GS_VERSION_MAJOR == 5
1171     float			scale, xscale, yscale;
1172     /* Scale ��ݤ��Ƥ���Τ�, Ghostscript 5.10/5.50 �ΥХ��Τ��� */
1173     xscale = fabs(igs->ctm.xx);
1174     yscale = fabs(igs->ctm.xy);
1175 
1176     if (xscale == 0)		/* if portrait */
1177 	scale = yscale;
1178     else
1179 	scale = xscale;
1180 #endif
1181 
1182     if (count == 0){
1183 	/* ���� */
1184 	lputs(s, ESC_GS "0;0lpG");
1185 	return 0;
1186     }
1187 
1188     /* offset �����ʳ��ξ��������ԲĤȤ����ֵ� */
1189     if (offset != 0) return -1;
1190 
1191     if (count) {
1192 	if (count == 1) {
1193 #if GS_VERSION_MAJOR == 5
1194 	    (void)sprintf(obuf, ESC_GS "1;%d;%ddlG",
1195 			  (int)(pattern[0] * scale / vdev->x_pixels_per_inch + 0.5),
1196 			  (int)(pattern[0] * scale / vdev->x_pixels_per_inch + 0.5));
1197 #else
1198 	    (void)sprintf(obuf, ESC_GS "1;%d;%ddlG", pattern[0], pattern[0]);
1199 #endif
1200 	    lputs(s, obuf);
1201 	} else {
1202 	    /* pattern �ˣ������ä����������ԲĤȤ����ֵ� */
1203 	    for (i = 0; i < count; ++i) {
1204 		if (pattern[i] == 0) return -1;
1205 	    }
1206 
1207 	    lputs(s, ESC_GS "1");
1208 	    for (i = 0; i < count; ++i) {
1209 #if GS_VERSION_MAJOR == 5
1210 		(void)sprintf(obuf, ";%d", (int)(pattern[i] * scale / vdev->x_pixels_per_inch + 0.5));
1211 
1212 #else
1213 		(void)sprintf(obuf, ";%d", pattern[i]);
1214 #endif
1215 		lputs(s, obuf);
1216 	    }
1217 	    lputs(s, "dlG");
1218 	}
1219 	lputs(s, ESC_GS "1;1lpG");
1220     }
1221     return 0;
1222 }
1223 
1224 
1225 /* �ѥ�ʿ���ٻ��� */
1226 private int
esmv_setflat(gx_device_vector * vdev,floatp flatness)1227 esmv_setflat(gx_device_vector * vdev, floatp flatness)
1228 {
1229     return 0;
1230 }
1231 
1232 
1233 private int
esmv_setlogop(gx_device_vector * vdev,gs_logical_operation_t lop,gs_logical_operation_t diff)1234 esmv_setlogop(gx_device_vector * vdev, gs_logical_operation_t lop,
1235 		gs_logical_operation_t diff)
1236 {
1237 /****** SHOULD AT LEAST DETECT SET-0 & SET-1 ******/
1238     return 0;
1239 }
1240 
1241 
1242 private int
esmv_beginpath(gx_device_vector * vdev,gx_path_type_t type)1243 esmv_beginpath(gx_device_vector * vdev, gx_path_type_t type)
1244 {
1245     stream		*s = gdev_vector_stream(vdev);
1246 
1247     /* �ѥ����۳���̿�� */
1248     if (type & gx_path_type_clip) {
1249 	lputs(s, ESC_GS "1bgpG");		/* ����å���Ͽ */
1250     } else {
1251 	lputs(s, ESC_GS "0bgpG");		/* ������Ͽ */
1252     }
1253     return 0;
1254 }
1255 
1256 
1257 private int
esmv_moveto(gx_device_vector * vdev,floatp x0,floatp y0,floatp x1,floatp y1,gx_path_type_t type)1258 esmv_moveto(gx_device_vector * vdev,
1259 	    floatp x0, floatp y0, floatp x1, floatp y1, gx_path_type_t type)
1260 {
1261     stream	*s = gdev_vector_stream(vdev);
1262     char	obuf[64];
1263 
1264     /* ���֥ѥ�����̿�� */
1265     (void)sprintf(obuf, ESC_GS "0;%d;%dmvpG", (int)x1, (int)y1);
1266     lputs(s, obuf);
1267 
1268     return 0;
1269 }
1270 
1271 
1272 private int
esmv_lineto(gx_device_vector * vdev,floatp x0,floatp y0,floatp x1,floatp y1,gx_path_type_t type)1273 esmv_lineto(gx_device_vector * vdev,
1274 	    floatp x0, floatp y0, floatp x1, floatp y1, gx_path_type_t type)
1275 {
1276     stream	*s = gdev_vector_stream(vdev);
1277     char	obuf[64];
1278 
1279     (void)sprintf(obuf, ESC_GS "0;1;%d;%dlnpG", (int)x1, (int)y1);
1280     lputs(s, obuf);
1281 
1282     return 0;
1283 }
1284 
1285 
1286 private int
esmv_curveto(gx_device_vector * vdev,floatp x0,floatp y0,floatp x1,floatp y1,floatp x2,floatp y2,floatp x3,floatp y3,gx_path_type_t type)1287 esmv_curveto(gx_device_vector * vdev, floatp x0, floatp y0,
1288 	   floatp x1, floatp y1, floatp x2, floatp y2, floatp x3, floatp y3,
1289 	       gx_path_type_t type)
1290 {
1291     stream	*s = gdev_vector_stream(vdev);
1292     char	obuf[128];
1293 
1294     /* �٥������� */
1295     (void)sprintf(obuf, ESC_GS "0;3;%d;%d;%d;%d;%d;%dbzpG",
1296 		  (int)x1, (int)y1, (int)x2, (int)y2, (int)x3, (int)y3);
1297     lputs(s, obuf);
1298 
1299     return 0;
1300 }
1301 
1302 
1303 private int
esmv_closepath(gx_device_vector * vdev,floatp x,floatp y,floatp x_start,floatp y_start,gx_path_type_t type)1304 esmv_closepath(gx_device_vector * vdev, floatp x, floatp y,
1305 		 floatp x_start, floatp y_start, gx_path_type_t type)
1306 {
1307     stream	*s = gdev_vector_stream(vdev);
1308 
1309     lputs(s, ESC_GS "clpG");
1310     return 0;
1311 }
1312 
1313 
1314 private int
esmv_endpath(gx_device_vector * vdev,gx_path_type_t type)1315 esmv_endpath(gx_device_vector * vdev, gx_path_type_t type)
1316 {
1317     stream	*s = gdev_vector_stream(vdev);
1318 
1319     if (type & gx_path_type_fill || type & gx_path_type_clip) {
1320 	/* default �ǽ�������뤬���Ϥ��Ƥ��� */
1321 	lputs(s, ESC_GS "clpG");
1322     }
1323 
1324     /* �ѥ������� */
1325     lputs(s, ESC_GS "enpG");
1326 
1327     /* �ѥ����� */
1328     if (type & gx_path_type_clip) {
1329 
1330 	/* ����å׻���
1331 	** ����åפˤ� gx_path_type_winding_number, gx_path_type_even_odd ��Ƚ�Ǥ�
1332 	** ɬ�פ��Ȼפ��� gs ¦���ղä��Ƥ��ʤ���
1333 	** �Ȥꤢ���� gx_path_type_even_odd ��ǥե���Ȥˤ��롣
1334 	*/
1335 	lputs(s, ESC_GS "1;2capG");
1336     } else if (type & gx_path_type_fill) {
1337 
1338 	/* �ɤ�Ĥ֤���§���� */
1339 	if (type & gx_path_type_even_odd) {
1340 /*	    lputs(s, ESC_GS "0;0;100spE");*/
1341 	    lputs(s, ESC_GS "0;2drpG");		/* �ɤ�Ĥ֤����� */
1342 	} else {
1343 /*	    lputs(s, ESC_GS "0;0;100spE");*/
1344 	    lputs(s, ESC_GS "0;1drpG");		/* �ɤ�Ĥ֤����� */
1345 	}
1346     } else {
1347 	lputs(s, ESC_GS "0;0drpG");		/* �س������� */
1348     }
1349 
1350     return 0;
1351 }
1352 
1353 /* ---------------- Driver procedures ---------------- */
1354 
1355 /* ------ Open/close/page ------ */
1356 
1357 /* Open the device. */
1358 private int
esmv_open(gx_device * dev)1359 esmv_open(gx_device * dev)
1360 {
1361     gx_device_vector	*const vdev = (gx_device_vector *) dev;
1362     gx_device_esmv	*const pdev = (gx_device_esmv *) dev;
1363     int			code;
1364     /*    char		*error, *path;*/
1365     float               width, height;
1366 
1367     code = esmv_range_check(dev);
1368     if (code < 0) return code;
1369 
1370     vdev->v_memory = dev->memory;
1371     /****** VERY WRONG ******/
1372     vdev->vec_procs = &esmv_vector_procs;
1373 
1374     code = gdev_vector_open_file_bbox(vdev, 512, true);
1375     if (code < 0) return code;
1376 
1377     gdev_vector_init(vdev);
1378     pdev->first_page = true;
1379 
1380     if(pdev->orientation){
1381       pdev->Margins[1] = (pdev->width - pdev->height - \
1382       ESCPAGE_LEFT_MARGIN_DEFAULT * vdev->x_pixels_per_inch / 72.0) * \
1383       X_DPI / vdev->x_pixels_per_inch;
1384 
1385       width = dev->MediaSize[0];
1386       height  = dev->MediaSize[1];
1387       dev->MediaSize[0] = height;
1388       dev->MediaSize[1] = width;
1389     }
1390 
1391     return 0;
1392 }
1393 
1394 
1395 /* Wrap up ("output") a page. */
1396 private int
esmv_output_page(gx_device * dev,int num_copies,int flush)1397 esmv_output_page(gx_device * dev, int num_copies, int flush)
1398 {
1399     gx_device_vector *const vdev = (gx_device_vector *) dev;
1400     gx_device_esmv *const pdev = (gx_device_esmv *) dev;
1401     stream *s = gdev_vector_stream(vdev);
1402 
1403     /* ����,��ü����,�ܹ����������������Ƥ��� */
1404     lputs(s, ESC_GS "3;0;0lwG" ESC_GS "1;10mlG" ESC_FF);
1405 
1406     sflush(s);
1407     vdev->in_page = false;
1408     pdev->first_page = false;
1409 
1410     gdev_vector_reset(vdev);
1411 
1412     return 0;
1413 }
1414 
1415 
1416 private int
esmv_close(gx_device * dev)1417 esmv_close(gx_device *dev)
1418 {
1419     gx_device_vector	*const vdev = (gx_device_vector *) dev;
1420     FILE		*f = vdev->file;
1421 
1422     /* ��λ���������ɤϷ���Ǥ� */
1423     (void)fprintf(f, ESC_GS "rhE" "\033\001@EJL \012@EJL EJ \012\033\001@EJL \012");
1424 
1425     gdev_vector_close_file(vdev);
1426 
1427     return 0;
1428 }
1429 
1430 /* Close the device. */
1431 /* Note that if this is being called as a result of finalization, */
1432 /* the stream may no longer exist; but the file will still be open. */
1433 
1434 /* ---------------- Get/put parameters ---------------- */
1435 
1436 /* Get parameters. */
1437 private int
esmv_get_params(gx_device * dev,gs_param_list * plist)1438 esmv_get_params(gx_device * dev, gs_param_list * plist)
1439 {
1440     gx_device_esmv	*const pdev = (gx_device_esmv *) dev;
1441     int			code;
1442     int			ncode;
1443     /*    gs_param_string     pmedia;*/
1444     gs_param_name	param_name;
1445 
1446     code = gdev_vector_get_params(dev, plist);
1447     if (code < 0) return code;
1448 
1449     if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_MANUALFEED, &pdev->manualFeed)) < 0)
1450 	code = ncode;
1451 
1452     if ((ncode = param_write_int(plist, ESCPAGE_OPTION_CASSETFEED, &pdev->cassetFeed)) < 0)
1453 	code = ncode;
1454 
1455     if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_RIT, &pdev->RITOff)) < 0)
1456 	code = ncode;
1457 
1458     if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_COLLATE, &pdev->Collate)) < 0)
1459         code = ncode;
1460 
1461     if ((ncode = param_write_int(plist, ESCPAGE_OPTION_TONERDENSITY, &pdev->toner_density)) < 0)
1462         code = ncode;
1463 
1464     if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_LANDSCAPE, &pdev->orientation)) < 0)
1465         code = ncode;
1466 
1467     if ( param_write_bool(plist, ESCPAGE_OPTION_TONERSAVING, &pdev->toner_saving)< 0)
1468         code = ncode;
1469 
1470     if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_DUPLEX, &pdev->Duplex)) < 0)
1471 	code = ncode;
1472 
1473     if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_DUPLEX_TUMBLE, &pdev->Tumble)) < 0)
1474 	code = ncode;
1475 
1476     if ((ncode = param_write_bool(plist, ESCPAGE_OPTION_FACEUP, &pdev->faceup)) < 0)
1477 	code = ncode;
1478 
1479     if ((ncode = param_write_int(plist, ESCPAGE_OPTION_MEDIATYPE, &pdev->MediaType)) < 0)
1480 	code = ncode;
1481 
1482     return code;
1483 }
1484 
1485 
1486 /* Put parameters. */
1487 private int
esmv_put_params(gx_device * dev,gs_param_list * plist)1488 esmv_put_params(gx_device * dev, gs_param_list * plist)
1489 {
1490     gx_device_esmv	*const pdev = (gx_device_esmv *) dev;
1491     int			ecode = 0;
1492     int			code;
1493     gs_param_name	param_name;
1494     gs_param_string	pmedia;
1495     bool		mf = pdev->manualFeed;
1496     int			cass = pdev->cassetFeed;
1497     bool		tum = pdev->Tumble;
1498     bool		collate = pdev->Collate;
1499     int			toner_density = pdev->toner_density;
1500     bool		toner_saving = pdev->toner_saving;
1501     bool		landscape = pdev->orientation;
1502     bool		faceup = pdev->faceup;
1503     bool		duplex = pdev->Duplex;
1504     bool		RITOff = pdev->RITOff;
1505     int			old_bpp = dev->color_info.depth;
1506     int			bpp = 0;
1507 
1508     if ((code = param_read_bool(plist, (param_name = ESCPAGE_OPTION_MANUALFEED), &mf)) < 0) {
1509 	param_signal_error(plist, param_name, ecode = code);
1510     }
1511     switch (code = param_read_int(plist, (param_name = ESCPAGE_OPTION_CASSETFEED), &cass)) {
1512 	case 0:
1513 	    if (cass < -1 || cass > 15)
1514 		ecode = gs_error_limitcheck;
1515 	    else
1516 		break;
1517 	    goto casse;
1518 	default:
1519 	    ecode = code;
1520 	  casse:param_signal_error(plist, param_name, ecode);
1521 	case 1:
1522 	    break;
1523     }
1524 
1525     if((code = param_read_bool(plist, (param_name = ESCPAGE_OPTION_COLLATE), &collate)) < 0) {
1526 	param_signal_error(plist, param_name, ecode = code);
1527     }
1528 
1529     if ((code = param_read_bool(plist, (param_name = ESCPAGE_OPTION_RIT), &RITOff)) < 0) {
1530 	param_signal_error(plist, param_name, ecode = code);
1531     }
1532 
1533 
1534     switch (code = param_read_string(plist, (param_name = ESCPAGE_OPTION_MEDIATYPE), &pmedia)) {
1535 
1536     case 0:
1537 	    if (pmedia.size > ESCPAGE_MEDIACHAR_MAX)
1538 		ecode = gs_error_limitcheck;
1539 	    else {		/* Check the validity of ``MediaType'' characters */
1540 
1541 		if (strcmp(pmedia.data, "TRANS") == 0) {
1542 		    pdev->MediaType = 2;
1543 		} else if (strcmp(pmedia.data, "THICK") == 0) {
1544 		    pdev->MediaType = 1;
1545 		} else {
1546 		    ecode = gs_error_rangecheck;
1547 		    goto pmediae;
1548 		}
1549 	    }
1550 	    break;
1551 	    goto pmediae;
1552 	default:
1553 	    ecode = code;
1554 	  pmediae:param_signal_error(plist, param_name, ecode);
1555 	case 1:
1556 	  if(!pdev->MediaType){
1557 	    pdev->MediaType = 0;
1558 	    pmedia.data = 0;
1559 	  }
1560 	  break;
1561     }
1562 
1563     switch (code = param_read_int(plist,
1564                                   (param_name = ESCPAGE_OPTION_TONERDENSITY), &toner_density)) {
1565     case 0:
1566             if (toner_density < 0 || toner_density > 5)
1567                 ecode = gs_error_rangecheck;
1568             else
1569                 break;
1570             goto tden;
1571     default:
1572 	ecode = code;
1573 tden:
1574 	param_signal_error(plist, param_name, ecode);
1575     case 1:
1576 	break;
1577     }
1578 
1579     switch (code = param_read_bool(plist, (param_name = ESCPAGE_OPTION_TONERSAVING), &toner_saving)) {
1580     case 0:
1581 	break;
1582     default:
1583 	if ((code = param_read_null(plist, param_name)) == 0) {
1584 	    break;
1585 	}
1586 	ecode = code;
1587 	param_signal_error(plist, param_name, ecode);
1588     case 1:
1589 	break;
1590     }
1591 
1592     if ((code = param_read_bool(plist, (param_name = ESCPAGE_OPTION_DUPLEX), &duplex)) < 0)
1593 	param_signal_error(plist, param_name, ecode = code);
1594 
1595     if ((code = param_read_bool(plist, (param_name = ESCPAGE_OPTION_DUPLEX_TUMBLE), &tum)) < 0)
1596 	param_signal_error(plist, param_name, ecode = code);
1597 
1598     if ((code = param_read_bool(plist, (param_name = ESCPAGE_OPTION_LANDSCAPE), &landscape)) < 0)
1599 	param_signal_error(plist, param_name, ecode = code);
1600 
1601     if ((code = param_read_bool(plist, (param_name = ESCPAGE_OPTION_FACEUP), &faceup)) < 0) {
1602 	param_signal_error(plist, param_name, ecode = code);
1603     }
1604 
1605 
1606     switch (code = param_read_int(plist, (param_name = "BitsPerPixel"), &bpp)) {
1607 	case 0:
1608 	    if (bpp != 8 && bpp != 24)
1609 		ecode = gs_error_rangecheck;
1610 	    else
1611 		break;
1612 	    goto bppe;
1613 	default:
1614 	    ecode = code;
1615 	  bppe:param_signal_error(plist, param_name, ecode);
1616 	case 1:
1617 	    break;
1618     }
1619 
1620     if (bpp != 0) {
1621 	dev->color_info.depth = bpp;
1622 	dev->color_info.num_components = ((bpp == 8) ? 1 : 3);
1623 	dev->color_info.max_gray = (bpp > 8 ? 255 : 1000);
1624 	dev->color_info.max_color = (bpp > 8 ? 255 : 1000);
1625 	dev->color_info.dither_grays = (bpp > 8 ? 256 : 5);
1626 	dev->color_info.dither_colors = (bpp > 8 ? 256 : 2);
1627 	dev_proc(pdev, map_rgb_color) = ((bpp == 8) ? gx_default_gray_map_rgb_color : gx_default_rgb_map_rgb_color);
1628 	dev_proc(pdev, map_color_rgb) = ((bpp == 8) ? gx_default_gray_map_color_rgb : gx_default_rgb_map_color_rgb);
1629     }
1630 
1631     if (ecode < 0) return ecode;
1632     code = gdev_vector_put_params(dev, plist);
1633     if (code < 0) return code;
1634 
1635     pdev->manualFeed = mf;
1636     pdev->cassetFeed = cass;
1637     pdev->faceup = faceup;
1638     pdev->RITOff = RITOff;
1639     pdev->orientation = landscape;
1640     pdev->toner_density = toner_density;
1641     pdev->toner_saving = toner_saving;
1642     pdev->Collate = collate;
1643     pdev->Duplex = duplex;
1644     pdev->Tumble = tum;
1645 
1646     if (bpp != 0 && bpp != old_bpp && pdev->is_open)
1647 	return gs_closedevice(dev);
1648 
1649     return 0;
1650 }
1651 
1652 /* ---------------- Images ---------------- */
1653 
1654 
1655 private int
esmv_copy_mono(gx_device * dev,const byte * data,int data_x,int raster,gx_bitmap_id id,int x,int y,int w,int h,gx_color_index zero,gx_color_index one)1656 esmv_copy_mono(gx_device * dev, const byte * data,
1657 	int data_x, int raster, gx_bitmap_id id, int x, int y, int w, int h,
1658 	   gx_color_index zero, gx_color_index one)
1659 {
1660     gx_device_esmv *const	pdev = (gx_device_esmv *) dev;
1661     gx_device_vector *const	vdev = (gx_device_vector *) dev;
1662     stream			*s = gdev_vector_stream(vdev);
1663     gx_drawing_color		color;
1664     int				code = 0;
1665     gx_color_index		c_color = 0;
1666     char			obuf[128];
1667     int				depth = 1;
1668 
1669     if (id != gs_no_id && zero == gx_no_color_index && one != gx_no_color_index && data_x == 0) {
1670 	gx_drawing_color dcolor;
1671 
1672 	color_set_pure(&dcolor, one);
1673 	esmv_setfillcolor(vdev, &dcolor);
1674     }
1675 
1676     if (zero == gx_no_color_index) {
1677 
1678         if (one == gx_no_color_index) return 0;
1679 	if (pdev->MaskState != 1) {
1680 	  /*	    lputs(s, ESC_GS "1owE");*/
1681 	    (void)sprintf(obuf, ESC_GS "1;1;%dccE", c_color);
1682 	    lputs(s, obuf);
1683 
1684 	    if (vdev->x_pixels_per_inch == 1200) {
1685 	      lputs(s, ESC_GS "1;45;156htmE");
1686 	    } else if (vdev->x_pixels_per_inch == 600) {
1687 	      lputs(s, ESC_GS "1;45;106htmE");
1688 	    } else {
1689 	      lputs(s, ESC_GS "1;45;71htmE");
1690 	    }
1691             pdev->MaskState = 1;
1692         }
1693 	c_color = one;
1694 
1695     } else if (one == gx_no_color_index)
1696 	/* 1bit ��Ʃ�� �ӥå�ȿž��zero ��������� */
1697     {
1698 	if (pdev->MaskState != 1) {
1699 	  /*	    lputs(s, ESC_GS "1owE");*/
1700 	    pdev->MaskState = 1;
1701 	}
1702 	c_color = zero;
1703     } else if (one == vdev->white) {
1704 
1705 	if (pdev->MaskState != 0) {
1706 	  /*	    lputs(s, ESC_GS "1owE");*/
1707 	    pdev->MaskState = 0;
1708 	}
1709 	c_color = zero;
1710     } else {
1711 
1712         if (pdev->MaskState != 1) {
1713 	  /*	    lputs(s, ESC_GS "1owE");*/
1714             pdev->MaskState = 1;
1715         }
1716 	color_set_pure(&color, one);
1717 	code = gdev_vector_update_fill_color((gx_device_vector *) pdev, &color);
1718 
1719 	/* �������̲ᤷ����ʲ��ο������̵��̣�� */
1720     }
1721     if (code < 0) return 0;
1722 
1723     esmv_write_begin(dev, depth, (int)x, (int)y, w, h, w, h, 0);
1724     {
1725 	int		i, j;
1726 	uint		width_bytes = (w + 7) >> 3;
1727 	uint		num_bytes = width_bytes * h;
1728 
1729 	byte *buf = gs_alloc_bytes(vdev->memory, num_bytes, "esmv_copy_mono(buf)");
1730 
1731 	if (data_x % 8 == 0) {
1732 	    for (i = 0; i < h; ++i) {
1733 		memcpy(buf + i * width_bytes, data + (data_x >> 3) + i * raster, width_bytes);
1734 	    }
1735 	} else {
1736 	    for (i = 0; i < h; ++i) {
1737 		for (j = 0; j < width_bytes; j++) {
1738 		    *(buf + i * width_bytes + j) =
1739 			*(data + (data_x >> 3) + i * raster + j) << (data_x % 8) |
1740 			*(data + (data_x >> 3) + i * raster + j + 1) >> (8 - data_x % 8);
1741 		}
1742 	    }
1743 	}
1744 
1745 	esmv_write_data(dev, depth, buf, num_bytes, w, h);
1746 	gs_free_object(vdev->memory, buf, "esmv_copy_mono(buf)");
1747     }
1748     esmv_write_end(dev, depth);
1749     return 0;
1750 }
1751 
1752 
1753 /* Copy a color bitmap. */
1754 private int
esmv_copy_color(gx_device * dev,const byte * data,int data_x,int raster,gx_bitmap_id id,int x,int y,int w,int h)1755 esmv_copy_color(gx_device * dev,
1756 		  const byte * data, int data_x, int raster, gx_bitmap_id id,
1757 		  int x, int y, int w, int h)
1758 {
1759     gx_device_esmv	*const pdev = (gx_device_esmv *) dev;
1760     gx_device_vector	*const vdev = (gx_device_vector *) dev;
1761 
1762     int			depth = dev->color_info.depth;
1763     int			num_components = (depth < 24 ? 1 : 3);
1764     uint		width_bytes = w * num_components;
1765 
1766     if (pdev->MaskState != 0) {
1767       /*	lputs(s, ESC_GS "1owE");*/
1768 	pdev->MaskState = 0;
1769     }
1770 
1771     esmv_write_begin(dev, depth, (int)x, (int)y, w, h, w, h, 0);
1772 
1773     {
1774 	int		i;
1775 	uint		num_bytes = width_bytes * h;
1776 	byte		*buf = gs_alloc_bytes(vdev->memory, num_bytes, "esmv_copy_color(buf)");
1777 
1778 	for (i = 0; i < h; ++i) {
1779 	    memcpy(buf + i * width_bytes, data + ((data_x * depth) >> 3) + i * raster, width_bytes);
1780 	}
1781 
1782 	esmv_write_data(dev, depth, buf, num_bytes, w, h);
1783 	gs_free_object(vdev->memory, buf, "esmv_copy_color(buf)");
1784     }
1785 
1786     esmv_write_end(dev, depth);
1787     return 0;
1788 }
1789 
1790 
1791 /* Fill a mask. */
1792 private int
esmv_fill_mask(gx_device * dev,const byte * data,int data_x,int raster,gx_bitmap_id id,int x,int y,int w,int h,const gx_drawing_color * pdcolor,int depth,gs_logical_operation_t lop,const gx_clip_path * pcpath)1793 esmv_fill_mask(gx_device * dev,
1794 		 const byte * data, int data_x, int raster, gx_bitmap_id id,
1795 		 int x, int y, int w, int h,
1796 		 const gx_drawing_color * pdcolor, int depth,
1797 		 gs_logical_operation_t lop, const gx_clip_path * pcpath)
1798 {
1799     gx_device_vector const	*vdev = (gx_device_vector *) dev;
1800     gx_device_esmv		*pdev = (gx_device_esmv *) dev;
1801     stream			*s = gdev_vector_stream(vdev);
1802     gx_color_index		color = gx_dc_pure_color(pdcolor);
1803     char			obuf[64];
1804 
1805     if (w <= 0 || h <= 0) return 0;
1806 
1807     if (depth > 1 ||
1808 	gdev_vector_update_fill_color(vdev, pdcolor) < 0 ||
1809 	gdev_vector_update_clip_path(vdev, pcpath) < 0 ||
1810 	gdev_vector_update_log_op(vdev, lop) < 0
1811 	)
1812 	return gx_default_fill_mask(dev, data, data_x, raster, id,
1813 				    x, y, w, h, pdcolor, depth, lop, pcpath);
1814 
1815 #if 0
1816     (*dev_proc(vdev->bbox_device, fill_mask))
1817 	((gx_device *) vdev->bbox_device, data, data_x, raster, id,
1818 	 x, y, w, h, pdcolor, depth, lop, pcpath);
1819 #endif
1820 
1821     if (!gx_dc_is_pure(pdcolor)) return_error(gs_error_rangecheck);
1822     pdev->current_color = color;
1823 
1824     (void)sprintf(obuf, ESC_GS "0;0;100spE" ESC_GS "1;1;%dccE" ,color);
1825     lputs(s, obuf);
1826 
1827 
1828     if (vdev->x_pixels_per_inch == 1200) {
1829       lputs(s, ESC_GS "1;45;156htmE");
1830     } else if (vdev->x_pixels_per_inch == 600) {
1831       lputs(s, ESC_GS "1;45;106htmE");
1832     } else {
1833       lputs(s, ESC_GS "1;45;71htmE");
1834     }
1835 
1836     if(pdev->MaskState != 1) {
1837       /*      lputs(s, ESC_GS "1owE");*/
1838 	pdev->MaskState = 1;
1839     }
1840 
1841     esmv_write_begin(dev, depth, (int)x, (int)y, w, h, w, h, 0);
1842     {
1843 	int		i;
1844 	uint		width_bytes = (w + 7) >> 3;
1845 	uint		num_bytes = width_bytes * h;
1846 	byte		*buf = gs_alloc_bytes(vdev->memory, num_bytes, "esmv_fill_mask(buf)");
1847 
1848 	for (i = 0; i < h; ++i) {
1849 	    memcpy(buf + i * width_bytes, data + (data_x >> 3) + i * raster, width_bytes);
1850 	}
1851 
1852 	esmv_write_data(dev, depth, buf, num_bytes, w, h);
1853 	esmv_write_end(dev, depth);
1854 	gs_free_object(vdev->memory, buf, "esmv_fill_mask(buf)");
1855     }
1856 
1857     return 0;
1858 }
1859 
1860 /* ---------------- High-level images ---------------- */
1861 
1862 private image_enum_proc_plane_data(esmv_image_plane_data);
1863 private image_enum_proc_end_image(esmv_image_end_image);
1864 private const gx_image_enum_procs_t esmv_image_enum_procs =
1865 {
1866     esmv_image_plane_data, esmv_image_end_image
1867 };
1868 
1869 
1870 /* Start processing an image. */
1871 private int
esmv_begin_image(gx_device * dev,const gs_imager_state * pis,const gs_image_t * pim,gs_image_format_t format,const gs_int_rect * prect,const gx_drawing_color * pdcolor,const gx_clip_path * pcpath,gs_memory_t * mem,gx_image_enum_common_t ** pinfo)1872 esmv_begin_image(gx_device * dev,
1873 		   const gs_imager_state * pis, const gs_image_t * pim,
1874 		   gs_image_format_t format, const gs_int_rect * prect,
1875 	      const gx_drawing_color * pdcolor, const gx_clip_path * pcpath,
1876 		   gs_memory_t * mem, gx_image_enum_common_t **pinfo)
1877 {
1878     gx_device_vector *const	vdev = (gx_device_vector *) dev;
1879     gx_device_esmv *const	pdev = (gx_device_esmv *) dev;
1880     stream			*s = gdev_vector_stream((gx_device_vector *) pdev);
1881     gdev_vector_image_enum_t	*pie =
1882 	gs_alloc_struct(mem, gdev_vector_image_enum_t, &st_vector_image_enum, "esmv_begin_image");
1883     const gs_color_space	*pcs = pim->ColorSpace;
1884     gx_color_index		color = gx_dc_pure_color(pdcolor);
1885     gs_color_space_index	index;
1886     int				num_components = 1;
1887     bool can_do = prect == 0 &&
1888       (pim->format == gs_image_format_chunky ||
1889        pim->format == gs_image_format_component_planar);
1890 
1891     gs_matrix			imat;
1892     int				code;
1893     int				ty, bx, by, cx, cy, dx, dy, sx, sy;
1894     char		        obuf[128];
1895 
1896     if (pie == 0) return_error(gs_error_VMerror);
1897     pie->memory = mem;
1898     code = gdev_vector_begin_image(vdev, pis, pim, format, prect,
1899 				   pdcolor, pcpath, mem, &esmv_image_enum_procs, pie);
1900     if (code < 0) return code;
1901 
1902     *pinfo = (gx_image_enum_common_t *) pie;
1903 
1904     if (!pim->ImageMask) {
1905 	index = gs_color_space_get_index(pcs);
1906 	num_components = gs_color_space_num_components(pcs);
1907 
1908 	if (pim->CombineWithColor) {
1909 	    can_do = false;
1910 	} else {
1911 	    switch (index) {
1912 		case gs_color_space_index_DeviceGray:
1913 		    if ((pim->Decode[0] != 0 || pim->Decode[1] != 1)
1914 			&& (pim->Decode[0] != 1 || pim->Decode[1] != 0))
1915 			can_do = false;
1916 		    break;
1917 		case gs_color_space_index_DeviceRGB:
1918 		    if (pim->Decode[0] != 0 || pim->Decode[1] != 1 ||
1919 			pim->Decode[2] != 0 || pim->Decode[3] != 1 ||
1920 			pim->Decode[4] != 0)
1921 			can_do = false;
1922 		    break;
1923 		default:
1924 		    can_do = false;
1925 	    }
1926 	}
1927     }
1928     if (!can_do) {
1929 	return gx_default_begin_image(dev, pis, pim, format, prect,
1930 				      pdcolor, pcpath, mem, &pie->default_info);
1931     }
1932 
1933     if (pim->ImageMask || (pim->BitsPerComponent == 1 && num_components == 1)) {
1934 	if (pim->Decode[0] > pim->Decode[1]) {
1935 	    pdev->MaskReverse = 1;
1936 	} else {
1937 	    pdev->MaskReverse = 0;
1938 	}
1939     }
1940 
1941     /* Write the image/colorimage/imagemask preamble. */
1942     gs_matrix_invert(&pim->ImageMatrix, &imat);
1943     gs_matrix_multiply(&imat, &ctm_only(pis), &imat);
1944 
1945     ty = imat.ty;
1946     bx = imat.xx * pim->Width + imat.yx * pim->Height + imat.tx;
1947     by = imat.xy * pim->Width + imat.yy * pim->Height + imat.ty;
1948     cx = imat.yx * pim->Height + imat.tx;
1949     cy = imat.yy * pim->Height + imat.ty;
1950     dx = imat.xx * pim->Width + imat.tx;
1951     dy = imat.xy * pim->Width + imat.ty;
1952 
1953     sx = bx - (int)imat.tx;
1954     sy = by - (int)imat.ty;
1955 
1956     /* �Ȥꤢ�������ΰ��֤˼��ޤ�褦�˶���Ū�˺�ɸ���ѹ����롣 */
1957     pdev -> roll = 0;
1958     pdev -> reverse_x = pdev -> reverse_y = 0;
1959     if (imat.tx > bx) {
1960 	pdev -> reverse_x = 1;
1961 	sx = -sx;
1962 	imat.tx = bx;
1963     }
1964 
1965     if (imat.ty > by) {
1966 	pdev -> reverse_y = 1;
1967 	sy = -sy;
1968 	imat.ty = by;
1969     }
1970 
1971     (void)memcpy(&pdev -> xmat, &imat, sizeof(gs_matrix));
1972     pdev -> sx = sx;
1973     pdev -> sy = sy;
1974     pdev -> h = pim->Height;
1975     pdev -> w = pim->Width;
1976     pdev -> dd = 0;
1977     pdev -> bx = 0;
1978     pdev -> by = 0;
1979 
1980     if (ty == cy) {
1981 	/* ��ž��������ˤĤ��Ƥϸ���̤������GS ¦�ε�ǽ����Ѥ��� */
1982 	return -1;
1983     }
1984 
1985     if (pim->ImageMask) {
1986 	pdev->ncomp = 1;
1987 
1988 	/* ������������̿�� - Ʃ�� */
1989 	if (pdev->MaskState != 1) {
1990 
1991 	  /*	    lputs(s, ESC_GS "1owE");*/
1992 	    (void)sprintf(obuf, ESC_GS "1;1;%dccE", color);
1993 	    lputs(s, obuf);
1994 
1995 	    if (vdev->x_pixels_per_inch == 1200) {
1996 	      lputs(s, ESC_GS "1;45;156htmE");
1997 	    } else if (vdev->x_pixels_per_inch == 600) {
1998 	      lputs(s, ESC_GS "1;45;106htmE");
1999 	    } else {
2000 	      lputs(s, ESC_GS "1;45;71htmE");
2001 	    }
2002 
2003 
2004 	}
2005 
2006     } else {
2007 
2008 	/* ������������̿�� - ���ɤ� */
2009 	if (pdev->MaskState != 0) {
2010 
2011 	  /*	  lputs(s, ESC_GS "1owE");*/ /* 184->204 */
2012 	    pdev->MaskState = 0;
2013 	}
2014 	pdev->ncomp = num_components;
2015     }
2016 
2017     if (pdev -> reverse_y) return 0;
2018 
2019     esmv_write_begin(dev, pie->bits_per_pixel, (int)imat.tx, (int)imat.ty, pie->width, pie->height, sx, sy, pdev -> roll);
2020 
2021     return 0;
2022 }
2023 
2024 
2025 /* Process the next piece of an image. */
2026 private int
2027 #if GS_VERSION_MAJOR >= 6
esmv_image_plane_data(gx_image_enum_common_t * info,const gx_image_plane_t * planes,int height,int * rows_used)2028 esmv_image_plane_data(gx_image_enum_common_t *info, const gx_image_plane_t *planes, int height, int *rows_used)
2029 #else
2030 esmv_image_plane_data(gx_device *dev, gx_image_enum_common_t *info, const gx_image_plane_t *planes, int height)
2031 #endif
2032 {
2033 #if GS_VERSION_MAJOR >= 6
2034     gx_device *dev = info->dev;
2035 #endif
2036     gx_device_vector *const	vdev = (gx_device_vector *) dev;
2037     gx_device_esmv *const	pdev = (gx_device_esmv *) dev;
2038     gdev_vector_image_enum_t	*pie = (gdev_vector_image_enum_t *) info;
2039 
2040     int				y;
2041     int				plane;
2042     int				width_bytes, tbyte;
2043     byte			*buf;
2044 
2045     if (pie->default_info) return gx_image_plane_data(pie->default_info, planes, height);
2046 
2047     gx_image_plane_data(pie->bbox_info, planes, height);
2048 
2049     {
2050 
2051 #if GS_VERSION_MAJOR >= 6
2052 	if (height == 260)
2053 	    height = 1;
2054 #endif
2055         width_bytes = (pie->width * pie->bits_per_pixel / pdev->ncomp + 7) / 8 * pdev->ncomp;
2056 	tbyte = width_bytes * height;
2057 	buf = gs_alloc_bytes(vdev->memory, tbyte, "esmv_image_data(buf)");
2058 
2059 	if (pdev -> reverse_y) {
2060 
2061 	    if (pdev -> h == height) {
2062 
2063 #if 1
2064 		if(tbyte == 1){
2065 		    if(strcmp(pdev->dname, "lp1800") != 0 &&
2066 		       strcmp(pdev->dname, "lp9600") != 0) {
2067 		      pdev->w += pdev->sx / 2048;
2068 		      height  += pdev->sy / 2048;
2069 		    }
2070 	        }
2071 #endif
2072 	      esmv_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);
2073 
2074 	    } else {
2075 		float	yy, sy;
2076 
2077 		yy = (pdev -> h * pdev->xmat.yy) - (pdev -> dd * pdev -> xmat.yy) - (height * pdev -> xmat.yy);
2078 		if (yy == 0) {
2079 		    yy = (pdev -> h * pdev->xmat.yx) - (pdev -> dd * pdev -> xmat.yx) - (height * pdev -> xmat.yx);
2080 		}
2081 
2082 		if (pdev -> by) {
2083 		    sy = (int)pdev -> xmat.ty - (int)yy;
2084 		    sy = pdev -> by - (int)sy;
2085 		} else {
2086 		    sy = height * pdev -> xmat.yy + 0.5;
2087 		}
2088 		if (sy < 0) {
2089 		    sy = -sy;
2090 		}
2091 
2092 		esmv_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);
2093 
2094 		pdev -> by = (int)pdev -> xmat.ty - (int)yy;
2095 	    }
2096 	}
2097 	pdev -> dd += height;
2098 
2099 	for (plane = 0; plane < pie->num_planes; ++plane) {
2100 
2101 	    for (y = 0; y < height; ++y) {
2102 
2103 		int     bit, w;
2104 		char    *p, *d, c;
2105 
2106                 p = planes[plane].data + ((planes[plane].data_x * pie->bits_per_pixel) >> 3) + y * planes[plane].raster;
2107 		if (pdev -> reverse_y) {
2108 
2109 		    d = buf + (height - y) * width_bytes;
2110 
2111 		    if (!pdev -> reverse_x) {
2112 			(void)memcpy(buf + (height - y - 1) * width_bytes,
2113 				     planes[plane].data + ((planes[plane].data_x * pie->bits_per_pixel) >> 3)
2114 				     + y * planes[plane].raster, width_bytes);
2115 
2116 		    }
2117 
2118 		} else {
2119 
2120 		    d = buf + (y + 1) * width_bytes;
2121 
2122 		    if (!pdev -> reverse_x) {
2123 
2124 			(void)memcpy(buf + y * width_bytes,
2125 				     planes[plane].data + ((planes[plane].data_x * pie->bits_per_pixel) >> 3)
2126 				     + y * planes[plane].raster, width_bytes);
2127 
2128 		    }
2129 		}
2130 		if (pdev -> reverse_x) {
2131 		    if (pie->bits_per_pixel == 1) {
2132 			for (w = 0; w < width_bytes; w++) {
2133 			    c = 0;
2134 			    for (bit = 0; bit < 8; bit++) {
2135 				if (*p & 1 << (7 - bit)) {
2136 				    c |= 1 << bit;
2137 				}
2138 			    }
2139 			    p++;
2140 			    *--d = c;
2141 			}
2142 		    } else if (pie->bits_per_pixel == 8){
2143 			for (w = 0; w < width_bytes; w++) {
2144 			    *--d = *p++;
2145 			}
2146 		    } else {
2147 			for (w = 0; w < width_bytes / 3; w++) {
2148 			    *--d = *(p + 2);
2149 			    *--d = *(p + 1);
2150 			    *--d = *p;
2151 			    p += 3;
2152 			}
2153 		    }
2154 		}
2155 	    }
2156 	}
2157 
2158 #if 1
2159 	if(tbyte == 1){
2160 	    int t;
2161 	    gs_free_object(vdev->memory, buf, "esmv_image_data(buf)");
2162 	    if(strcmp(pdev->dname, "lp1800") == 0 ||
2163 	       strcmp(pdev->dname, "lp9600") == 0) {
2164 		if(pdev->sx > pdev->sy){
2165 	            height  = pdev->sy;
2166 	            pdev->w = pdev->sx;
2167 	            tbyte = ((pdev->sx + 7) / 8) * pdev->sy;
2168 	        } else {
2169 		    if(pdev->sx < pdev->sy){
2170 	                height  = pdev->sy;
2171 	                pdev->w = pdev->sx;
2172 	                tbyte = ((pdev->sx + 7) / 8) * pdev->sy;
2173   	            } else {
2174 	                tbyte = 1;
2175 	            }
2176                 }
2177 
2178 	    } else {
2179 	        if(pdev->sx > pdev->sy){
2180 	            tbyte = 1;
2181 	        } else {
2182 		    if(pdev->sx < pdev->sy){
2183 	                tbyte = tbyte * height;
2184   	            } else {
2185 	                tbyte = 1;
2186 	            }
2187 	        }
2188 	    }
2189 	    buf = gs_alloc_bytes(vdev->memory, tbyte, "esmv_image_data(buf)");
2190 	    for(t = 0; t < tbyte; t++){
2191 	        buf[t] = 0xff;
2192 	    }
2193 	}
2194 #endif
2195 	esmv_write_data(dev, pie->bits_per_pixel, buf, tbyte, pdev -> w, height);
2196 
2197 	if (pdev -> reverse_y) {
2198 	    esmv_write_end(dev, pie->bits_per_pixel);
2199 	}
2200 
2201 	gs_free_object(vdev->memory, buf, "esmv_image_data(buf)");
2202     }
2203     return (pie->y += height) >= pie->height;
2204 }
2205 
2206 
2207 private int
2208 #if GS_VERSION_MAJOR >= 6
esmv_image_end_image(gx_image_enum_common_t * info,bool draw_last)2209 esmv_image_end_image(gx_image_enum_common_t * info, bool draw_last)
2210 #else
2211 esmv_image_end_image(gx_device * dev, gx_image_enum_common_t * info, bool draw_last)
2212 #endif
2213 {
2214 #if GS_VERSION_MAJOR >= 6
2215     gx_device *dev = info->dev;
2216 #endif
2217     gx_device_vector		*const vdev = (gx_device_vector *) dev;
2218     gx_device_esmv		*const pdev = (gx_device_esmv *) dev;
2219     gdev_vector_image_enum_t	*pie = (gdev_vector_image_enum_t *) info;
2220     int				code;
2221 
2222     if (!(pdev -> reverse_y)) {
2223 	esmv_write_end(dev, pie->bits_per_pixel);
2224     }
2225 
2226     pdev->reverse_x = pdev->reverse_y = 0;
2227     if (pdev->MaskReverse == 0) {
2228       ;
2229     }
2230     pdev->MaskReverse = -1;
2231 
2232     code = gdev_vector_end_image(vdev, (gdev_vector_image_enum_t *) pie, draw_last, pdev->white);
2233     return code;
2234 }
2235 
2236 
esmv_write_begin(gx_device * dev,int bits,int x,int y,int sw,int sh,int dw,int dh,int roll)2237 private void esmv_write_begin(gx_device *dev, int bits, int x, int y, int sw, int sh, int dw, int dh, int roll)
2238 {
2239     gx_device_esmv *const       pdev = (gx_device_esmv *)dev;
2240     stream			*s = gdev_vector_stream((gx_device_vector *)pdev);
2241     char                        obuf[128];
2242     int				comp;
2243 
2244     (void)sprintf(obuf, ESC_GS "%dX" ESC_GS "%dY", x, y);
2245     lputs(s, obuf);
2246 
2247     comp = 10;
2248 
2249     if (bits == 1) {
2250       if (strcmp(pdev->dname, "lp1800") == 0 ||
2251           strcmp(pdev->dname, "lp9600") == 0) {
2252 	(void)sprintf(obuf, ESC_GS "0bcI");
2253       }else{
2254 	(void)sprintf(obuf, ESC_GS "5;%d;%d;%d;%d;%dsrI",  sw, sh, dw, dh, roll);
2255       }
2256     } else if (bits == 4) {
2257 	if (pdev -> c4map) {
2258 	    pdev -> c4map = FALSE;
2259 	}
2260 	(void)sprintf(obuf, ESC_GS "1;1;1;0;%d;%d;%d;%d;%d;%dscrI", comp, sw, sh, dw, dh, roll);
2261     } else if (bits == 8) {
2262 	if (pdev -> c8map) {
2263 	    pdev -> c8map = FALSE;
2264 	}
2265 	(void)sprintf(obuf, ESC_GS "1;1;1;0;%d;%d;%d;%d;%d;%dscrI", comp, sw, sh, dw, dh, roll);
2266     } else {
2267 	/* 24 bit */
2268 	(void)sprintf(obuf, ESC_GS "1;1;1;0;%d;%d;%d;%d;%d;%dscrI", comp, sw, sh, dw, dh, roll);
2269     }
2270     lputs(s, obuf);
2271 
2272     return;
2273 }
2274 
2275 
esmv_write_data(gx_device * dev,int bits,char * buf,int bsize,int w,int ras)2276 private void esmv_write_data(gx_device *dev, int bits, char *buf, int bsize, int w, int ras)
2277 {
2278     gx_device_vector *const     vdev = (gx_device_vector *) dev;
2279     gx_device_esmv *const       pdev = (gx_device_esmv *) dev;
2280     stream			*s = gdev_vector_stream((gx_device_vector *)pdev);
2281     char                        obuf[128];
2282     int				size;
2283     char			*tmps, *p;
2284 
2285     if (bits == 12) {
2286       p = tmps = gs_alloc_bytes(vdev->memory, bsize * 2, "esmv_write_data(tmp)");
2287 	for (size = 0; size < bsize; size++) {
2288 	    *p++ = buf[size] & 0xF0;
2289 	    *p++ = buf[size] << 4;
2290 	}
2291 	bsize = bsize * 2;
2292 	buf = tmps;
2293     }
2294 
2295     if(bits == 4) {
2296       p = tmps = gs_alloc_bytes(vdev->memory, bsize * 2, "esmv_write_data(tmp)");
2297 	for (size = 0; size < bsize; size++) {
2298 	    *p++ = ((buf[size] & 0xF0) * 0xFF / 0xF0);
2299 	    *p++ = ((buf[size] << 4 & 0xF0) * 0xFF / 0xF0);
2300 	}
2301 	bsize = bsize * 2;
2302 	buf = tmps;
2303     }
2304 
2305 
2306     if(bits == 1){
2307       if (strcmp(pdev->dname, "lp1800") == 0 || \
2308 	  strcmp(pdev->dname, "lp9600") == 0) {
2309 	(void)sprintf(obuf, ESC_GS "%d;1;%d;%d;0db{I", bsize, w, ras);
2310       }else{
2311 	(void)sprintf(obuf, ESC_GS "%d;%du{I", bsize, ras);
2312       }
2313     }else{
2314       (void)sprintf(obuf, ESC_GS "%d;%dcu{I", bsize, ras);
2315     }
2316     lputs(s, obuf);
2317 
2318     put_bytes(s, buf, bsize);
2319 
2320     if (bits == 12 || bits == 4) {
2321       gs_free_object(vdev->memory, tmps, "esmv_write_data(tmp)");
2322     }
2323 
2324     return;
2325 }
2326 
2327 
esmv_write_end(gx_device * dev,int bits)2328 private void esmv_write_end(gx_device *dev, int bits)
2329 {
2330     gx_device_esmv *const       pdev = (gx_device_esmv *) dev;
2331     stream			*s = gdev_vector_stream((gx_device_vector *)pdev);
2332 
2333     if(bits == 1){
2334       if (strcmp(pdev->dname, "lp1800") == 0 || \
2335 	  strcmp(pdev->dname, "lp9600") == 0) {
2336 	lputs(s, ESC_GS "1dbI");
2337       } else {
2338 	lputs(s, ESC_GS "erI");
2339       }
2340     }else{
2341       lputs(s, ESC_GS "ecrI");
2342     }
2343     return;
2344 }
2345 
2346