• R/O
  • SSH
  • HTTPS

opfc: Commit


Commit MetaInfo

Revision917 (tree)
Zeit2011-09-08 16:16:34
Autorsho-otani

Log Message

Release 1.0.7

Ändern Zusammenfassung

Diff

--- gdevopvp/tags/RELEASE_1_0_7/src/gdevopvp.c (nonexistent)
+++ gdevopvp/tags/RELEASE_1_0_7/src/gdevopvp.c (revision 917)
@@ -0,0 +1,5420 @@
1+/* Copyright (c) 2003-2004, AXE, Inc. All rights reserved.
2+
3+ This program is free software; you can redistribute it and/or modify it
4+ under the terms of the GNU General Public License as published by the
5+ Free Software Foundation; either version 2 of the License, or (at your
6+ option) any later version.
7+
8+ This program is distributed in the hope that it will be useful, but
9+ WITHOUT ANY WARRANTY; without even the implied warranty of
10+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ General Public License for more details.
12+
13+ You should have received a copy of the GNU General Public License along
14+ with this program; if not, write to the Free Software Foundation, Inc.,
15+ 59 Temple Place, Suite 330, Boston, MA, 02111-1307.
16+
17+*/
18+
19+/* $Id$ */
20+/* gdevopvp.c ver.1.00 rel.1.0 26 Nov 2004 */
21+/* OpenPrinting Vector Printer Driver Glue Code */
22+
23+#include <stdio.h>
24+#include <stdlib.h>
25+#include <unistd.h>
26+#include <string.h>
27+#include <locale.h>
28+#include <langinfo.h>
29+#include <dlfcn.h>
30+#include <sys/types.h>
31+#include <sys/stat.h>
32+#include <fcntl.h>
33+
34+/* Set compatibility flag just in case we have GNU iconv.h */
35+#ifndef USE_LIBICONV_GNU
36+# define LIBICONV_PLUG
37+#endif
38+#include <iconv.h>
39+
40+#include "string_.h"
41+#include "math_.h"
42+#include "gx.h"
43+#include "ghost.h"
44+#include "gscdefs.h"
45+#include "gsexit.h"
46+#include "gsstruct.h"
47+#include "gserrors.h"
48+#include "gsmatrix.h"
49+#include "gsparam.h"
50+#include "gxdevice.h"
51+#include "gxdcconv.h"
52+#include "gscspace.h"
53+#include "gsutil.h"
54+#include "gdevprn.h"
55+#include "gdevvec.h"
56+#include "spprint.h"
57+#include "ghost.h"
58+#include "gzstate.h"
59+#include "ialloc.h"
60+#include "iddict.h"
61+#include "dstack.h"
62+#include "ilevel.h"
63+#include "iinit.h"
64+#include "iname.h"
65+#include "imemory.h"
66+#include "igstate.h"
67+#include "interp.h"
68+#include "ipacked.h"
69+#include "iparray.h"
70+#include "iutil.h"
71+#include "ivmspace.h"
72+#include "opdef.h"
73+#include "store.h"
74+#include "gspath.h"
75+#include "gzpath.h"
76+#include "gzcpath.h"
77+#include "gsropt.h"
78+#include "gsiparam.h"
79+#include "gxxfont.h"
80+
81+/* added for image gamma correction */
82+#include "gximage.h"
83+#include "gxfmap.h"
84+#include "gxfrac.h"
85+#include "gxcvalue.h"
86+
87+#include "opvp_common.h"
88+
89+#define ENABLE_SIMPLE_MODE 1
90+#define ENABLE_SKIP_RASTER 1
91+#define ENABLE_AUTO_REVERSE 1
92+
93+/* ----- data types/macros ----- */
94+
95+/* for debug */
96+#ifdef printf
97+#undef printf
98+#endif
99+#ifdef fprintf
100+#undef fprintf
101+#endif
102+
103+/* buffer */
104+#define OPVP_BUFF_SIZE 1024
105+
106+/* ROP */
107+#define OPVP_0_2_ROP_S 0xCC
108+#define OPVP_0_2_ROP_P 0xF0
109+#define OPVP_0_2_ROP_OR 0xB8
110+
111+/* paper */
112+#define PS_DPI 72
113+#define MMPI 25.4
114+#define TOLERANCE 3.0
115+
116+typedef struct {
117+ const char *region;
118+ const char *name;
119+ float width;
120+ float height;
121+} OPVP_Paper;
122+
123+#define X_DPI 300
124+#define Y_DPI 300
125+
126+#define MAX_PATH_POINTS 1000
127+
128+/* driver */
129+typedef struct gx_device_opvp_s {
130+ gx_device_vector_common;
131+} gx_device_opvp;
132+
133+typedef struct gx_device_oprp_s {
134+ gx_device_common;
135+ gx_prn_device_common;
136+} gx_device_oprp;
137+
138+/* point (internal) */
139+typedef struct {
140+ floatp x;
141+ floatp y;
142+} _fPoint;
143+
144+/* ----- private function prototypes ----- */
145+
146+/* Utilities */
147+static int opvp_startpage(gx_device *);
148+static int opvp_endpage(void);
149+static char *opvp_alloc_string(char **, const char *);
150+static char *opvp_cat_string(char **, const char *);
151+static char *opvp_adjust_num_string(char *);
152+static char **opvp_gen_dynamic_lib_name(void);
153+static char *opvp_to_utf8(char *);
154+#define opvp_check_in_page(pdev) \
155+ ((beginPage) || (inkjet) ? 0 \
156+ : (*vdev_proc(pdev, beginpage))((gx_device_vector*)pdev))
157+static int opvp_get_papertable_index(gx_device *);
158+static char *opvp_get_sizestring(float, float);
159+/* not used static const char *opvp_get_papersize_region(gx_device *);*/
160+/* not used static const char *opvp_get_papersize_name(gx_device *);*/
161+/* not used static char *opvp_get_papersize_inch(gx_device *);*/
162+/* not used static const char *opvp_get_papersize(gx_device *);*/
163+static char *opvp_get_mediasize(gx_device *);
164+static char *opvp_gen_page_info(gx_device *);
165+static char *opvp_gen_doc_info(gx_device *);
166+static char *opvp_gen_job_info(gx_device *);
167+static int opvp_set_brush_color(gx_device_opvp *, gx_color_index,
168+ opvp_brush_t *);
169+static int opvp_draw_image(gx_device_opvp *, int,
170+ int, int, int, int, int, int, const byte *);
171+
172+/* load/unload vector driver */
173+static int opvp_load_vector_driver(void);
174+static int opvp_unload_vector_driver(void);
175+static int prepare_open(gx_device *);
176+
177+/* driver procs */
178+static int opvp_open(gx_device *);
179+static int oprp_open(gx_device *);
180+static void opvp_get_initial_matrix(gx_device *, gs_matrix *);
181+static int opvp_output_page(gx_device *, int, int);
182+static int opvp_close(gx_device *);
183+#if GS_VERSION_MAJOR >= 8
184+static gx_color_index opvp_map_rgb_color(gx_device *, const gx_color_value *); /* modified for gs 8.15 */
185+#else
186+static gx_color_index opvp_map_rgb_color(gx_device *, gx_color_value,
187+ gx_color_value, gx_color_value);
188+#endif
189+static int opvp_map_color_rgb(gx_device *, gx_color_index, gx_color_value *);
190+static int opvp_copy_mono(gx_device *, const byte *, int, int,
191+ gx_bitmap_id, int, int, int, int,
192+ gx_color_index, gx_color_index);
193+static int opvp_copy_color(gx_device *, const byte *, int, int,
194+ gx_bitmap_id, int, int, int, int);
195+static int _get_params(gs_param_list *);
196+static int opvp_get_params(gx_device *, gs_param_list *);
197+static int oprp_get_params(gx_device *, gs_param_list *);
198+static int _put_params(gs_param_list *);
199+static int opvp_put_params(gx_device *, gs_param_list *);
200+static int oprp_put_params(gx_device *, gs_param_list *);
201+static int opvp_fill_path(gx_device *, const gs_imager_state *, gx_path *,
202+ const gx_fill_params *, const gx_device_color *,
203+ const gx_clip_path *);
204+static int opvp_stroke_path(gx_device *, const gs_imager_state *, gx_path *,
205+ const gx_stroke_params *, const gx_drawing_color *,
206+ const gx_clip_path *);
207+static int opvp_fill_mask(gx_device *, const byte *, int, int, gx_bitmap_id,
208+ int, int, int, int, const gx_drawing_color *,
209+ int, gs_logical_operation_t, const gx_clip_path *);
210+
211+/* available color spaces */
212+
213+static char cspace_available[] = {
214+ 0, /* OPVP_CSPACE_BW */
215+ 0, /* OPVP_CSPACE_DEVICEGRAY */
216+ 0, /* OPVP_CSPACE_DEVICECMY */
217+ 0, /* OPVP_CSPACE_DEVICECMYK */
218+ 0, /* OPVP_CSPACE_DEVICERGB */
219+ 0, /* OPVP_CSPACE_DEVICEKRGB */
220+ 1, /* OPVP_CSPACE_STANDARDRGB */
221+ 0 /* OPVP_CSPACE_STANDARDRGB64 */
222+};
223+
224+/* vector driver procs */
225+static int opvp_beginpage(gx_device_vector *);
226+static int opvp_setlinewidth(gx_device_vector *, floatp);
227+static int opvp_setlinecap(gx_device_vector *, gs_line_cap);
228+static int opvp_setlinejoin(gx_device_vector *, gs_line_join);
229+static int opvp_setmiterlimit(gx_device_vector *, floatp);
230+static int opvp_setdash(gx_device_vector *, const float *, uint, floatp);
231+static int opvp_setflat(gx_device_vector *, floatp);
232+static int opvp_setlogop(gx_device_vector *, gs_logical_operation_t,
233+ gs_logical_operation_t);
234+#if GS_VERSION_MAJOR >= 8
235+static int opvp_can_handle_hl_color(gx_device_vector *, const gs_imager_state *, const gx_drawing_color *);
236+static int opvp_setfillcolor(gx_device_vector *, const gs_imager_state *, const gx_drawing_color *);
237+static int opvp_setstrokecolor(gx_device_vector *, const gs_imager_state *,const gx_drawing_color *);
238+#else
239+static int opvp_setfillcolor(gx_device_vector *, const gx_drawing_color *);
240+static int opvp_setstrokecolor(gx_device_vector *, const gx_drawing_color *);
241+#endif
242+static int opvp_vector_dopath(gx_device_vector *, const gx_path *,
243+ gx_path_type_t, const gs_matrix *);
244+static int opvp_vector_dorect(gx_device_vector *, fixed, fixed, fixed, fixed,
245+ gx_path_type_t);
246+static int opvp_beginpath(gx_device_vector *, gx_path_type_t);
247+static int opvp_moveto(gx_device_vector *, floatp, floatp, floatp, floatp,
248+ gx_path_type_t);
249+static int opvp_lineto(gx_device_vector *, floatp, floatp, floatp, floatp,
250+ gx_path_type_t);
251+static int opvp_curveto(gx_device_vector *, floatp, floatp, floatp, floatp,
252+ floatp, floatp, floatp, floatp, gx_path_type_t);
253+static int opvp_closepath(gx_device_vector *, floatp, floatp, floatp, floatp,
254+ gx_path_type_t);
255+static int opvp_endpath(gx_device_vector *, gx_path_type_t);
256+
257+/* ----- Paper definition ----- */
258+OPVP_Paper paperTable[] =
259+{
260+#if 0
261+ {"jpn","hagaki",100/MMPI*PS_DPI,148/MMPI*PS_DPI},
262+ {"iso","a6" ,105/MMPI*PS_DPI,148/MMPI*PS_DPI},
263+ {"jis","b6" ,128/MMPI*PS_DPI,182/MMPI*PS_DPI},
264+ {"jpn","oufuku",148/MMPI*PS_DPI,200/MMPI*PS_DPI},
265+ {"iso","a5" ,148/MMPI*PS_DPI,210/MMPI*PS_DPI},
266+ {"jis","b5" ,182/MMPI*PS_DPI,257/MMPI*PS_DPI},
267+ {"iso","a4" ,210/MMPI*PS_DPI,297/MMPI*PS_DPI},
268+ {"na" ,"letter", 8.5*PS_DPI, 11*PS_DPI},/* 215.9x279.4 */
269+ {"na" ,"legal" , 8.5*PS_DPI, 14*PS_DPI},/* 215.9x355.6 */
270+ {"jis","b4" ,257/MMPI*PS_DPI,364/MMPI*PS_DPI},
271+ {"iso","a3" ,297/MMPI*PS_DPI,420/MMPI*PS_DPI},
272+#else
273+#include "opvp_media.def"
274+#endif
275+ {NULL ,NULL , 0, 0}
276+};
277+
278+/* ----- Driver definition ----- */
279+
280+/* Driver procedures */
281+static dev_proc_open_device(opvp_open);
282+static dev_proc_open_device(oprp_open);
283+static dev_proc_output_page(opvp_output_page);
284+static dev_proc_print_page(oprp_print_page);
285+static dev_proc_close_device(opvp_close);
286+static dev_proc_get_params(opvp_get_params);
287+static dev_proc_get_params(oprp_get_params);
288+static dev_proc_put_params(opvp_put_params);
289+static dev_proc_put_params(oprp_put_params);
290+static dev_proc_fill_rectangle(opvp_fill_rectangle);
291+static dev_proc_begin_image(opvp_begin_image);
292+static image_enum_proc_plane_data(opvp_image_plane_data);
293+static image_enum_proc_end_image(opvp_image_end_image);
294+
295+gs_public_st_suffix_add0_final(
296+ st_device_opvp,
297+ gx_device_opvp,
298+ "gx_device_opvp",
299+ device_opvp_enum_ptrs,
300+ device_opvp_reloc_ptrs,
301+ gx_device_finalize,
302+ st_device_vector
303+);
304+
305+#define opvp_initial_values \
306+ NULL, /* *vectorDriver */\
307+ NULL, /* *printerModel */\
308+ NULL, /* *handle */\
309+ NULL, /* (*OpenPrinter)() */\
310+ NULL, /* *ErrorNo */\
311+ -1, /* outputFD */\
312+ 0, /* nApiEntry */\
313+ NULL, /* *apiEntry */\
314+ -1, /* printerContext */\
315+ NULL, /* *jobInfo */\
316+ NULL /* *docInfo */
317+
318+/* device procs */
319+#define opvp_procs \
320+{\
321+ opvp_open,\
322+ opvp_get_initial_matrix,\
323+ NULL, /* sync_output */\
324+ opvp_output_page,\
325+ opvp_close,\
326+ opvp_map_rgb_color,\
327+ opvp_map_color_rgb,\
328+ opvp_fill_rectangle, /*gdev_vector_fill_rectangle,*/\
329+ NULL, /* tile_rectangle OBSOLETE */\
330+ opvp_copy_mono,\
331+ opvp_copy_color,\
332+ NULL, /* draw_line OBSOLETE */\
333+ NULL, /* get_bits */\
334+ opvp_get_params,\
335+ opvp_put_params,\
336+ NULL, /* map_cmyk_color */\
337+ NULL, /* get_xfont_procs */\
338+ NULL, /* get_xfont_device */\
339+ NULL, /* map_rgb_alpha_color */\
340+ gx_page_device_get_page_device,\
341+ NULL, /* get_alpha_bits OBSOLETE */\
342+ NULL, /* copy_alpha */\
343+ NULL, /* get_band */\
344+ NULL, /* copy_rop */\
345+ opvp_fill_path,\
346+ opvp_stroke_path,\
347+ opvp_fill_mask,\
348+ gdev_vector_fill_trapezoid,\
349+ gdev_vector_fill_parallelogram,\
350+ gdev_vector_fill_triangle,\
351+ NULL, /* draw_thin_line */\
352+ opvp_begin_image,\
353+ NULL, /* image_data */\
354+ NULL, /* end_image */\
355+ NULL, /* strip_tile_rectangle */\
356+ NULL, /* strip_copy_rop */\
357+ NULL, /* get_clipping_box */\
358+ NULL, /* begin_typed_image */\
359+ NULL, /* get_bits_rectangle */\
360+ NULL, /* map_color_rgb_alpha */\
361+ NULL, /* create_compositor */\
362+ NULL, /* get_hardware_params */\
363+ NULL, /* text_begin */\
364+ NULL, /* finish_copydevice */\
365+ NULL, /* begin_transparency_group */\
366+ NULL, /* end_transparency_group */\
367+ NULL, /* begin_transparency_mask */\
368+ NULL, /* end_transparency_mask */\
369+ NULL /* discard_transparency_layer */\
370+}
371+
372+
373+/* vector procs */
374+static gx_device_vector_procs opvp_vector_procs =
375+{
376+ /* Page management */
377+ opvp_beginpage,
378+ /* Imager state */
379+ opvp_setlinewidth,
380+ opvp_setlinecap,
381+ opvp_setlinejoin,
382+ opvp_setmiterlimit,
383+ opvp_setdash,
384+ opvp_setflat,
385+ opvp_setlogop,
386+ /* Other state */
387+#if GS_VERSION_MAJOR >= 8
388+ opvp_can_handle_hl_color, /* added for gs 8.15 */
389+#endif
390+ opvp_setfillcolor,
391+ opvp_setstrokecolor,
392+ /* Paths */
393+ opvp_vector_dopath,
394+ opvp_vector_dorect,
395+ opvp_beginpath,
396+ opvp_moveto,
397+ opvp_lineto,
398+ opvp_curveto,
399+ opvp_closepath,
400+ opvp_endpath
401+};
402+
403+const gx_device_opvp gs_opvp_device =
404+{
405+ std_device_dci_type_body(
406+ gx_device_opvp,
407+ 0,
408+ "opvp",
409+ &st_device_opvp,
410+ DEFAULT_WIDTH_10THS_A4 * X_DPI / 10,
411+ DEFAULT_HEIGHT_10THS_A4 * Y_DPI / 10,
412+ X_DPI,
413+ Y_DPI,
414+ 3,
415+ 24,
416+ 255,
417+ 255,
418+ 256,
419+ 256
420+ ),
421+ opvp_procs
422+};
423+
424+/* for inkjet */
425+static gx_device_procs prn_oprp_procs =
426+ prn_color_params_procs(
427+ oprp_open,
428+ opvp_output_page,
429+ opvp_close,
430+ opvp_map_rgb_color,
431+ opvp_map_color_rgb,
432+ oprp_get_params,
433+ oprp_put_params
434+ );
435+
436+const gx_device_oprp gs_oprp_device =
437+{
438+ prn_device_std_margins_body(
439+ gx_device_oprp,
440+ prn_oprp_procs,
441+ "oprp",
442+ DEFAULT_WIDTH_10THS_A4,
443+ DEFAULT_HEIGHT_10THS_A4,
444+ X_DPI,
445+ Y_DPI,
446+ 0, 0, 0, 0, 0, 0,
447+ 24,
448+ oprp_print_page
449+ )
450+};
451+
452+/* driver mode */
453+static bool vector = true;
454+static bool inkjet = false;
455+static char *vectorDriver = NULL;
456+static char *printerModel = NULL;
457+static void *handle = NULL;
458+static opvp_dc_t (*OpenPrinter)(opvp_int_t,const opvp_char_t*,
459+ const opvp_int_t[2],
460+ opvp_api_procs_t**) = NULL;
461+static int (*OpenPrinter_0_2)(int,char*,int*,
462+ OPVP_api_procs**) = NULL;
463+static opvp_int_t *ErrorNo = NULL;
464+static opvp_int_t outputFD = -1;
465+static opvp_int_t nApiEntry = 0;
466+static opvp_api_procs_t *apiEntry = NULL;
467+static OPVP_api_procs *apiEntry_0_2 = NULL;
468+static opvp_dc_t printerContext = -1;
469+static char *jobInfo = NULL;
470+static char *docInfo = NULL;
471+static opvp_cspace_t colorSpace = OPVP_CSPACE_STANDARDRGB;
472+static opvp_cspace_t savedColorSpace;
473+static opvp_brush_t *vectorFillColor = NULL;
474+static float margins[4] = {0, 0, 0, 0};
475+static float zoom[2] = {1, 1};
476+static float shift[2] = {0, 0};
477+static bool zoomAuto = false;
478+static bool zooming = false;
479+static bool beginPage = false;
480+
481+static int
482+GetLastError_1_0(void)
483+{
484+ return *ErrorNo;
485+}
486+
487+static int (*GetLastError)(void) = GetLastError_1_0;
488+
489+/* Wrapper functions that keep compatible with 0.2 */
490+
491+/* color space mapping 0.2 to 1.0 */
492+static opvp_cspace_t cspace_0_2_to_1_0[] = {
493+ OPVP_CSPACE_BW,
494+ OPVP_CSPACE_DEVICEGRAY,
495+ OPVP_CSPACE_DEVICECMY,
496+ OPVP_CSPACE_DEVICECMYK,
497+ OPVP_CSPACE_DEVICERGB,
498+ OPVP_CSPACE_STANDARDRGB,
499+ OPVP_CSPACE_STANDARDRGB64
500+};
501+
502+/* color space mapping 1.0 to 0.2 */
503+static opvp_cspace_t cspace_1_0_to_0_2[] = {
504+ OPVP_cspaceBW,
505+ OPVP_cspaceDeviceGray,
506+ OPVP_cspaceDeviceCMY,
507+ OPVP_cspaceDeviceCMYK,
508+ OPVP_cspaceDeviceRGB,
509+ 0, /* 0.2 doesn't have OPVP_CSPACE_DEVICEKRGB */
510+ OPVP_cspaceStandardRGB,
511+ OPVP_cspaceStandardRGB64,
512+};
513+
514+/* image format mapping 1.0 to 0.2 */
515+static opvp_imageformat_t iformat_1_0_to_0_2[] = {
516+ OPVP_iformatRaw,
517+ OPVP_iformatRaw, /* OPVP_IFORMAT_MASK use iformat raw in 0.2 */
518+ OPVP_iformatRLE,
519+ OPVP_iformatJPEG,
520+ OPVP_iformatPNG,
521+};
522+/* image colorDepth needed in 0.2 */
523+static int colorDepth_0_2[] = {
524+ 1, /* OPVP_CSPACE_BW */
525+ 8, /* OPVP_CSPACE_DEVICEGRAY */
526+ 24, /* OPVP_CSPACE_DEVICECMY */
527+ 32, /* OPVP_CSPACE_DEVICECMYK */
528+ 24, /* OPVP_CSPACE_DEVICERGB */
529+ 32, /* OPVP_CSPACE_DEVICEKRGB */
530+ 24, /* OPVP_CSPACE_STANDARDRGB */
531+ 64, /* OPVP_CSPACE_STANDARDRGB64 */
532+};
533+
534+/* translate error code */
535+static int
536+GetLastError_0_2(void)
537+{
538+ switch(*ErrorNo) {
539+ case OPVP_FATALERROR_0_2:
540+ return OPVP_FATALERROR;
541+ break;
542+ case OPVP_BADREQUEST_0_2:
543+ return OPVP_BADREQUEST;
544+ break;
545+ case OPVP_BADCONTEXT_0_2:
546+ return OPVP_BADCONTEXT;
547+ break;
548+ case OPVP_NOTSUPPORTED_0_2:
549+ return OPVP_NOTSUPPORTED;
550+ break;
551+ case OPVP_JOBCANCELED_0_2:
552+ return OPVP_JOBCANCELED;
553+ break;
554+ case OPVP_PARAMERROR_0_2:
555+ return OPVP_PARAMERROR;
556+ break;
557+ default:
558+ break;
559+ }
560+ /* unknown error no */
561+ /* return FATALERROR instead */
562+ return OPVP_FATALERROR;
563+}
564+
565+static opvp_result_t
566+StartPageWrapper(opvp_dc_t printerContext, const opvp_char_t *pageInfo)
567+{
568+ int r;
569+
570+ if ((r = apiEntry_0_2->StartPage(printerContext,
571+ /* discard const */(char *)pageInfo)) != OPVP_OK) {
572+ /* error */
573+ return r;
574+ }
575+ /* initialize ROP */
576+ if (apiEntry_0_2->SetROP != NULL) {
577+ apiEntry_0_2->SetROP(printerContext,
578+ OPVP_0_2_ROP_P);
579+ }
580+ return OPVP_OK;
581+}
582+
583+static opvp_result_t
584+InitGSWrapper(opvp_dc_t printerContext)
585+{
586+ int r;
587+
588+ if ((r = apiEntry_0_2->InitGS(printerContext)) != OPVP_OK) {
589+ /* error */
590+ return r;
591+ }
592+ /* initialize ROP */
593+ if (apiEntry_0_2->SetROP != NULL) {
594+ apiEntry_0_2->SetROP(printerContext,
595+ OPVP_0_2_ROP_P);
596+ }
597+ return OPVP_OK;
598+}
599+
600+static opvp_result_t
601+QueryColorSpaceWrapper( opvp_dc_t printerContext, opvp_int_t *pnum,
602+ opvp_cspace_t *pcspace)
603+{
604+ int r;
605+ int i;
606+
607+ if ((r = apiEntry_0_2->QueryColorSpace(printerContext,
608+ (OPVP_ColorSpace *)pcspace,pnum)) != OPVP_OK) {
609+ /* error */
610+ return r;
611+ }
612+ /* translate cspaces */
613+ for (i = 0;i < *pnum;i++) {
614+ if (pcspace[i]
615+ >= sizeof(cspace_0_2_to_1_0)/sizeof(opvp_cspace_t)) {
616+ /* unknown color space */
617+ /* set DEVICERGB instead */
618+ pcspace[i] = OPVP_CSPACE_DEVICERGB;
619+ } else {
620+ pcspace[i] = cspace_0_2_to_1_0[pcspace[i]];
621+ }
622+ }
623+ return OPVP_OK;
624+}
625+
626+static opvp_result_t
627+SetColorSpaceWrapper(opvp_dc_t printerContext, opvp_cspace_t cspace)
628+{
629+ if (cspace == OPVP_CSPACE_DEVICEKRGB) {
630+ /* 0.2 doesn't have OPVP_CSPACE_DEVICEKRGB */
631+ *ErrorNo = OPVP_NOTSUPPORTED_0_2;
632+ return -1;
633+ }
634+ if (cspace
635+ >= sizeof(cspace_1_0_to_0_2)/sizeof(OPVP_ColorSpace)) {
636+ /* unknown color space */
637+ *ErrorNo = OPVP_PARAMERROR_0_2;
638+ return -1;
639+ }
640+ return apiEntry_0_2->SetColorSpace(printerContext,
641+ cspace_1_0_to_0_2[cspace]);
642+}
643+
644+static opvp_result_t
645+GetColorSpaceWrapper(opvp_dc_t printerContext, opvp_cspace_t *pcspace)
646+{
647+ int r;
648+
649+ if ((r = apiEntry_0_2->GetColorSpace(printerContext,
650+ (OPVP_ColorSpace *)pcspace)) != OPVP_OK) {
651+ /* error */
652+ return r;
653+ }
654+ if (*pcspace
655+ >= sizeof(cspace_0_2_to_1_0)/sizeof(opvp_cspace_t)) {
656+ /* unknown color space */
657+ /* set DEVICERGB instead */
658+ *pcspace = OPVP_CSPACE_DEVICERGB;
659+ } else {
660+ *pcspace = cspace_0_2_to_1_0[*pcspace];
661+ }
662+ return r;
663+}
664+
665+static opvp_result_t
666+SetStrokeColorWrapper(opvp_dc_t printerContext, const opvp_brush_t *brush)
667+{
668+ OPVP_Brush brush_0_2;
669+
670+ if (brush == NULL) {
671+ *ErrorNo = OPVP_PARAMERROR_0_2;
672+ return -1;
673+ }
674+ if (brush->colorSpace == OPVP_CSPACE_DEVICEKRGB) {
675+ /* 0.2 doesn't have OPVP_CSPACE_DEVICEKRGB */
676+ return OPVP_NOTSUPPORTED;
677+ }
678+ if (brush->colorSpace
679+ >= sizeof(cspace_1_0_to_0_2)/sizeof(OPVP_ColorSpace)) {
680+ /* unknown color space */
681+ *ErrorNo = OPVP_PARAMERROR_0_2;
682+ return -1;
683+ }
684+ brush_0_2.colorSpace = cspace_1_0_to_0_2[brush->colorSpace];
685+ brush_0_2.xorg = brush->xorg;
686+ brush_0_2.yorg = brush->yorg;
687+ brush_0_2.pbrush = (OPVP_BrushData *)brush->pbrush;
688+ memcpy(brush_0_2.color,brush->color,sizeof(brush_0_2.color));
689+ return apiEntry_0_2->SetStrokeColor(printerContext,&brush_0_2);
690+}
691+
692+static opvp_result_t
693+SetFillColorWrapper(opvp_dc_t printerContext, const opvp_brush_t *brush)
694+{
695+ OPVP_Brush brush_0_2;
696+
697+ if (brush == NULL) {
698+ *ErrorNo = OPVP_PARAMERROR_0_2;
699+ return -1;
700+ }
701+ if (brush->colorSpace == OPVP_CSPACE_DEVICEKRGB) {
702+ /* 0.2 doesn't have OPVP_CSPACE_DEVICEKRGB */
703+ return OPVP_NOTSUPPORTED;
704+ }
705+ if (brush->colorSpace
706+ >= sizeof(cspace_1_0_to_0_2)/sizeof(OPVP_ColorSpace)) {
707+ /* unknown color space */
708+ *ErrorNo = OPVP_PARAMERROR_0_2;
709+ return -1;
710+ }
711+ brush_0_2.colorSpace = cspace_1_0_to_0_2[brush->colorSpace];
712+ brush_0_2.xorg = brush->xorg;
713+ brush_0_2.yorg = brush->yorg;
714+ brush_0_2.pbrush = (OPVP_BrushData *)brush->pbrush;
715+ memcpy(brush_0_2.color,brush->color,sizeof(brush_0_2.color));
716+ return apiEntry_0_2->SetFillColor(printerContext,&brush_0_2);
717+}
718+
719+static opvp_result_t
720+SetBgColorWrapper(opvp_dc_t printerContext, const opvp_brush_t *brush)
721+{
722+ OPVP_Brush brush_0_2;
723+
724+ if (brush == NULL) {
725+ *ErrorNo = OPVP_PARAMERROR_0_2;
726+ return -1;
727+ }
728+ if (brush->colorSpace == OPVP_CSPACE_DEVICEKRGB) {
729+ /* 0.2 doesn't have OPVP_CSPACE_DEVICEKRGB */
730+ *ErrorNo = OPVP_NOTSUPPORTED_0_2;
731+ return -1;
732+ }
733+ if (brush->colorSpace
734+ >= sizeof(cspace_1_0_to_0_2)/sizeof(OPVP_ColorSpace)) {
735+ /* unknown color space */
736+ *ErrorNo = OPVP_PARAMERROR_0_2;
737+ return -1;
738+ }
739+ brush_0_2.colorSpace = cspace_1_0_to_0_2[brush->colorSpace];
740+ brush_0_2.xorg = brush->xorg;
741+ brush_0_2.yorg = brush->yorg;
742+ brush_0_2.pbrush = (OPVP_BrushData *)brush->pbrush;
743+ memcpy(brush_0_2.color,brush->color,sizeof(brush_0_2.color));
744+ return apiEntry_0_2->SetBgColor(printerContext,&brush_0_2);
745+}
746+
747+static opvp_result_t
748+DrawImageWrapper(
749+ opvp_dc_t printerContext,
750+ opvp_int_t sourceWidth,
751+ opvp_int_t sourceHeight,
752+ opvp_int_t sourcePitch,
753+ opvp_imageformat_t imageFormat,
754+ opvp_int_t destinationWidth,
755+ opvp_int_t destinationHeight,
756+ const void *imagedata)
757+{
758+ int r;
759+ OPVP_Rectangle rect;
760+ OPVP_ImageFormat iformat_0_2;
761+ OPVP_PaintMode paintmode_0_2 = OPVP_paintModeTransparent;
762+ int depth;
763+
764+ if (imageFormat == OPVP_IFORMAT_MASK) {
765+ if (apiEntry_0_2->GetPaintMode != NULL) {
766+ apiEntry_0_2->GetPaintMode(printerContext,
767+ &paintmode_0_2);
768+ }
769+ if (paintmode_0_2 != OPVP_paintModeTransparent) {
770+ if (apiEntry_0_2->SetROP != NULL) {
771+ apiEntry_0_2->SetROP(printerContext,
772+ OPVP_0_2_ROP_S);
773+ }
774+ }
775+ else {
776+ if (apiEntry_0_2->SetROP != NULL) {
777+ apiEntry_0_2->SetROP(printerContext,
778+ OPVP_0_2_ROP_OR);
779+ }
780+ }
781+ depth = 1;
782+ } else {
783+ if (apiEntry_0_2->SetROP != NULL) {
784+ apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_S);
785+ }
786+ depth = colorDepth_0_2[colorSpace];
787+ }
788+
789+ OPVP_I2FIX(0,rect.p0.x);
790+ OPVP_I2FIX(0,rect.p0.y);
791+ OPVP_I2FIX(destinationWidth,rect.p1.x);
792+ OPVP_I2FIX(destinationHeight,rect.p1.y);
793+ if (imageFormat >= sizeof(iformat_1_0_to_0_2)/sizeof(OPVP_ImageFormat)) {
794+ /* illegal image format */
795+ *ErrorNo = OPVP_PARAMERROR_0_2;
796+ return -1;
797+ }
798+ iformat_0_2 = iformat_1_0_to_0_2[imageFormat];
799+ r = apiEntry_0_2->DrawImage(printerContext,sourceWidth,sourceHeight,
800+ depth,iformat_0_2,rect,
801+ sourcePitch*sourceHeight,
802+ /* remove const */ (void *)imagedata);
803+
804+ if (apiEntry_0_2->SetROP != NULL) {
805+ apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_P);
806+ }
807+
808+ return r;
809+}
810+
811+static opvp_result_t
812+StartDrawImageWrapper(
813+ opvp_dc_t printerContext,
814+ opvp_int_t sourceWidth,
815+ opvp_int_t sourceHeight,
816+ opvp_int_t sourcePitch,
817+ opvp_imageformat_t imageFormat,
818+ opvp_int_t destinationWidth,
819+ opvp_int_t destinationHeight)
820+{
821+ int r;
822+ OPVP_Rectangle rect;
823+ OPVP_ImageFormat iformat_0_2;
824+ OPVP_PaintMode paintmode_0_2 = OPVP_paintModeTransparent;
825+ int depth;
826+
827+ if (imageFormat == OPVP_IFORMAT_MASK) {
828+ if (apiEntry_0_2->GetPaintMode != NULL) {
829+ apiEntry_0_2->GetPaintMode(printerContext,
830+ &paintmode_0_2);
831+ }
832+ if (paintmode_0_2 != OPVP_paintModeTransparent) {
833+ if (apiEntry_0_2->SetROP != NULL) {
834+ apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_S);
835+ }
836+ }
837+ else {
838+ if (apiEntry_0_2->SetROP != NULL) {
839+ apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_OR);
840+ }
841+ }
842+ depth = 1;
843+ } else {
844+ if (apiEntry_0_2->SetROP != NULL) {
845+ apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_S);
846+ }
847+ depth = colorDepth_0_2[colorSpace];
848+ }
849+
850+ OPVP_I2FIX(0,rect.p0.x);
851+ OPVP_I2FIX(0,rect.p0.y);
852+ OPVP_I2FIX(destinationWidth,rect.p1.x);
853+ OPVP_I2FIX(destinationHeight,rect.p1.y);
854+ if (imageFormat >= sizeof(iformat_1_0_to_0_2)/sizeof(OPVP_ImageFormat)) {
855+ /* illegal image format */
856+ *ErrorNo = OPVP_PARAMERROR_0_2;
857+ return -1;
858+ }
859+ iformat_0_2 = iformat_1_0_to_0_2[imageFormat];
860+ r = apiEntry_0_2->StartDrawImage(printerContext,
861+ sourceWidth,sourceHeight,
862+ depth,iformat_0_2,rect);
863+
864+ return r;
865+}
866+
867+static opvp_result_t
868+EndDrawImageWrapper(opvp_dc_t printerContext)
869+{
870+ int r;
871+
872+ r = apiEntry_0_2->EndDrawImage(printerContext);
873+
874+ /* make sure rop is pattern copy */
875+ if (apiEntry_0_2->SetROP != NULL) {
876+ apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_P);
877+ }
878+
879+ return r;
880+}
881+
882+static opvp_result_t
883+QueryDeviceCapabilityWrapper(
884+ opvp_dc_t printerContext,
885+ opvp_queryinfoflags_t queryflag,
886+ opvp_int_t *buflen,
887+ opvp_char_t *infoBuf)
888+{
889+ return apiEntry_0_2->QueryDeviceCapability(printerContext,queryflag,
890+ *buflen,(char *)infoBuf);
891+}
892+
893+static opvp_result_t
894+QueryDeviceInfoWrapper(
895+ opvp_dc_t printerContext,
896+ opvp_queryinfoflags_t queryflag,
897+ opvp_int_t *buflen,
898+ opvp_char_t *infoBuf)
899+{
900+ if (queryflag & OPVP_QF_MEDIACOPY) {
901+ *ErrorNo = OPVP_NOTSUPPORTED;
902+ return -1;
903+ }
904+ if (queryflag & OPVP_QF_PRINTREGION) {
905+ queryflag &= ~OPVP_QF_PRINTREGION;
906+ queryflag |= 0x0020000;
907+ }
908+ return apiEntry_0_2->QueryDeviceInfo(printerContext,queryflag,
909+ *buflen,(char *)infoBuf);
910+}
911+
912+static opvp_result_t
913+SetLineDashWrapper(opvp_dc_t printerContext, opvp_int_t num,
914+ const opvp_fix_t *pdash)
915+{
916+ return apiEntry_0_2->SetLineDash(printerContext,
917+ /* remove const */ (OPVP_Fix *)pdash,num);
918+}
919+
920+static opvp_result_t
921+GetLineDashWrapper(opvp_dc_t printerContext, opvp_int_t *pnum,
922+ opvp_fix_t *pdash)
923+{
924+ return apiEntry_0_2->GetLineDash(printerContext,
925+ pdash,pnum);
926+}
927+
928+static opvp_dc_t
929+OpenPrinterWrapper(
930+ opvp_int_t outputFD,
931+ const opvp_char_t *printerModel,
932+ const opvp_int_t apiVersion[2],
933+ opvp_api_procs_t **apiProcs)
934+{
935+ opvp_dc_t dc = -1;
936+
937+ if (OpenPrinter != NULL) {
938+ dc = (*OpenPrinter)(outputFD,printerModel,apiVersion,apiProcs);
939+ } else {
940+ /* try version 0.2 */
941+
942+ if (OpenPrinter_0_2 != NULL) {
943+ static opvp_api_procs_t tEntry;
944+ int nApiEntry;
945+
946+ dc = (*OpenPrinter_0_2)(outputFD,
947+ /* remove const */
948+ (char *)printerModel,
949+ &nApiEntry,&apiEntry_0_2);
950+ /* setting functions */
951+ tEntry.opvpClosePrinter
952+ = apiEntry_0_2->ClosePrinter;
953+ tEntry.opvpStartJob
954+ = (opvp_result_t (*)(opvp_int_t,
955+ const opvp_char_t*))
956+ apiEntry_0_2->StartJob;
957+ tEntry.opvpEndJob = apiEntry_0_2->EndJob;
958+ tEntry.opvpAbortJob = NULL;
959+ tEntry.opvpStartDoc
960+ = (opvp_result_t (*)(opvp_dc_t,
961+ const opvp_char_t*))
962+ apiEntry_0_2->StartDoc;
963+ tEntry.opvpEndDoc = apiEntry_0_2->EndDoc;
964+ if (apiEntry_0_2->StartPage != NULL) {
965+ tEntry.opvpStartPage = StartPageWrapper;
966+ } else {
967+ tEntry.opvpStartPage = NULL;
968+ }
969+ tEntry.opvpEndPage = apiEntry_0_2->EndPage;
970+
971+ if (apiEntry_0_2->QueryDeviceCapability != NULL) {
972+ tEntry.opvpQueryDeviceCapability
973+ = QueryDeviceCapabilityWrapper;
974+ } else {
975+ tEntry.opvpQueryDeviceCapability = NULL;
976+ }
977+
978+ if (apiEntry_0_2->QueryDeviceInfo != NULL) {
979+ tEntry.opvpQueryDeviceInfo = QueryDeviceInfoWrapper;
980+ } else {
981+ tEntry.opvpQueryDeviceInfo = NULL;
982+ }
983+
984+ tEntry.opvpResetCTM = apiEntry_0_2->ResetCTM;
985+ tEntry.opvpSetCTM = (opvp_result_t (*)(opvp_dc_t,
986+ const opvp_ctm_t*))
987+ apiEntry_0_2->SetCTM;
988+ tEntry.opvpGetCTM = (opvp_result_t (*)(opvp_dc_t,opvp_ctm_t*))
989+ apiEntry_0_2->GetCTM;
990+ if (apiEntry_0_2->InitGS != NULL) {
991+ tEntry.opvpInitGS = InitGSWrapper;
992+ } else {
993+ tEntry.opvpInitGS = NULL;
994+ }
995+ tEntry.opvpSaveGS = apiEntry_0_2->SaveGS;
996+ tEntry.opvpRestoreGS = apiEntry_0_2->RestoreGS;
997+ if (apiEntry_0_2->QueryColorSpace != NULL) {
998+ tEntry.opvpQueryColorSpace = QueryColorSpaceWrapper;
999+ } else {
1000+ tEntry.opvpQueryColorSpace = NULL;
1001+ }
1002+ if (apiEntry_0_2->SetColorSpace != NULL) {
1003+ tEntry.opvpSetColorSpace = SetColorSpaceWrapper;
1004+ } else {
1005+ tEntry.opvpSetColorSpace = NULL;
1006+ }
1007+ if (apiEntry_0_2->GetColorSpace != NULL) {
1008+ tEntry.opvpGetColorSpace = GetColorSpaceWrapper;
1009+ } else {
1010+ tEntry.opvpGetColorSpace = NULL;
1011+ }
1012+ tEntry.opvpSetFillMode
1013+ = (opvp_result_t (*)(opvp_dc_t,opvp_fillmode_t))
1014+ apiEntry_0_2->SetFillMode;
1015+ tEntry.opvpGetFillMode
1016+ = (opvp_result_t (*)(opvp_dc_t,opvp_fillmode_t*))
1017+ apiEntry_0_2->GetFillMode;
1018+ tEntry.opvpSetAlphaConstant = apiEntry_0_2->SetAlphaConstant;
1019+ tEntry.opvpGetAlphaConstant = apiEntry_0_2->GetAlphaConstant;
1020+ tEntry.opvpSetLineWidth = apiEntry_0_2->SetLineWidth;
1021+ tEntry.opvpGetLineWidth = apiEntry_0_2->GetLineWidth;
1022+ if (apiEntry_0_2->SetLineDash != NULL) {
1023+ tEntry.opvpSetLineDash = SetLineDashWrapper;
1024+ } else {
1025+ tEntry.opvpSetLineDash = NULL;
1026+ }
1027+ if (apiEntry_0_2->GetLineDash != NULL) {
1028+ tEntry.opvpGetLineDash = GetLineDashWrapper;
1029+ } else {
1030+ tEntry.opvpGetLineDash = NULL;
1031+ }
1032+ tEntry.opvpSetLineDashOffset
1033+ = apiEntry_0_2->SetLineDashOffset;
1034+ tEntry.opvpGetLineDashOffset
1035+ = apiEntry_0_2->GetLineDashOffset;
1036+ tEntry.opvpSetLineStyle
1037+ = (opvp_result_t (*)(opvp_dc_t,opvp_linestyle_t))
1038+ apiEntry_0_2->SetLineStyle;
1039+ tEntry.opvpGetLineStyle
1040+ = (opvp_result_t (*)(opvp_dc_t,opvp_linestyle_t*))
1041+ apiEntry_0_2->GetLineStyle;
1042+ tEntry.opvpSetLineCap
1043+ = (opvp_result_t (*)(opvp_dc_t,opvp_linecap_t))
1044+ apiEntry_0_2->SetLineCap;
1045+ tEntry.opvpGetLineCap
1046+ = (opvp_result_t (*)(opvp_dc_t,opvp_linecap_t*))
1047+ apiEntry_0_2->GetLineCap;
1048+ tEntry.opvpSetLineJoin
1049+ = (opvp_result_t (*)(opvp_dc_t,opvp_linejoin_t))
1050+ apiEntry_0_2->SetLineJoin;
1051+ tEntry.opvpGetLineJoin
1052+ = (opvp_result_t (*)(opvp_dc_t,opvp_linejoin_t*))
1053+ apiEntry_0_2->GetLineJoin;
1054+ tEntry.opvpSetMiterLimit = apiEntry_0_2->SetMiterLimit;
1055+ tEntry.opvpGetMiterLimit = apiEntry_0_2->GetMiterLimit;
1056+ tEntry.opvpSetPaintMode
1057+ = (opvp_result_t (*)(opvp_dc_t,opvp_paintmode_t))
1058+ apiEntry_0_2->SetPaintMode;
1059+ tEntry.opvpGetPaintMode
1060+ = (opvp_result_t (*)(opvp_dc_t,opvp_paintmode_t*))
1061+ apiEntry_0_2->GetPaintMode;
1062+ if (apiEntry_0_2->SetStrokeColor != NULL) {
1063+ tEntry.opvpSetStrokeColor = SetStrokeColorWrapper;
1064+ } else {
1065+ tEntry.opvpSetStrokeColor = NULL;
1066+ }
1067+ if (apiEntry_0_2->SetFillColor != NULL) {
1068+ tEntry.opvpSetFillColor = SetFillColorWrapper;
1069+ } else {
1070+ tEntry.opvpSetFillColor = NULL;
1071+ }
1072+ if (apiEntry_0_2->SetBgColor != NULL) {
1073+ tEntry.opvpSetBgColor = SetBgColorWrapper;
1074+ } else {
1075+ tEntry.opvpSetBgColor = NULL;
1076+ }
1077+ tEntry.opvpNewPath = apiEntry_0_2->NewPath;
1078+ tEntry.opvpEndPath = apiEntry_0_2->EndPath;
1079+ tEntry.opvpStrokePath = apiEntry_0_2->StrokePath;
1080+ tEntry.opvpFillPath = apiEntry_0_2->FillPath;
1081+ tEntry.opvpStrokeFillPath = apiEntry_0_2->StrokeFillPath;
1082+ tEntry.opvpSetClipPath
1083+ = (opvp_result_t (*)(opvp_dc_t,opvp_cliprule_t))
1084+ apiEntry_0_2->SetClipPath;
1085+ tEntry.opvpResetClipPath = apiEntry_0_2->ResetClipPath;
1086+ tEntry.opvpSetCurrentPoint = apiEntry_0_2->SetCurrentPoint;
1087+ tEntry.opvpLinePath
1088+ = (opvp_result_t (*)(opvp_dc_t,
1089+ opvp_pathmode_t,opvp_int_t,
1090+ const opvp_point_t*))
1091+ apiEntry_0_2->LinePath;
1092+ tEntry.opvpPolygonPath
1093+ = (opvp_result_t (*)(opvp_dc_t,opvp_int_t,
1094+ const opvp_int_t*,
1095+ const opvp_point_t*))
1096+ apiEntry_0_2->PolygonPath;
1097+ tEntry.opvpRectanglePath
1098+ = (opvp_result_t (*)(opvp_dc_t,opvp_int_t,
1099+ const opvp_rectangle_t*))
1100+ apiEntry_0_2->RectanglePath;
1101+ tEntry.opvpRoundRectanglePath
1102+ = (opvp_result_t (*)(opvp_dc_t,opvp_int_t,
1103+ const opvp_roundrectangle_t*))
1104+ apiEntry_0_2->RoundRectanglePath;
1105+ tEntry.opvpBezierPath
1106+ = (opvp_result_t (*)(opvp_dc_t,opvp_int_t,
1107+ const opvp_point_t*))
1108+ apiEntry_0_2->BezierPath;
1109+ tEntry.opvpArcPath
1110+ = (opvp_result_t (*)(opvp_dc_t,opvp_arcmode_t,
1111+ opvp_arcdir_t,opvp_fix_t,opvp_fix_t,opvp_fix_t,
1112+ opvp_fix_t,opvp_fix_t,opvp_fix_t,opvp_fix_t,
1113+ opvp_fix_t))apiEntry_0_2->ArcPath;
1114+ if (apiEntry_0_2->DrawImage != NULL) {
1115+ tEntry.opvpDrawImage = DrawImageWrapper;
1116+ } else {
1117+ tEntry.opvpDrawImage = NULL;
1118+ }
1119+ if (apiEntry_0_2->StartDrawImage != NULL) {
1120+ tEntry.opvpStartDrawImage = StartDrawImageWrapper;
1121+ } else {
1122+ tEntry.opvpStartDrawImage = NULL;
1123+ }
1124+ tEntry.opvpTransferDrawImage =
1125+ (opvp_result_t (*)(opvp_dc_t,opvp_int_t,const void*))
1126+ apiEntry_0_2->TransferDrawImage;
1127+ if (apiEntry_0_2->EndDrawImage != NULL) {
1128+ tEntry.opvpEndDrawImage = EndDrawImageWrapper;
1129+ } else {
1130+ tEntry.opvpEndDrawImage = NULL;
1131+ }
1132+ tEntry.opvpStartScanline = apiEntry_0_2->StartScanline;
1133+ tEntry.opvpScanline
1134+ = (opvp_result_t (*)(opvp_dc_t,opvp_int_t,
1135+ const opvp_int_t*))
1136+ apiEntry_0_2->Scanline;
1137+ tEntry.opvpEndScanline = apiEntry_0_2->EndScanline;
1138+ tEntry.opvpStartRaster = apiEntry_0_2->StartRaster;
1139+ tEntry.opvpTransferRasterData
1140+ = (opvp_result_t (*)(opvp_dc_t,opvp_int_t,
1141+ const opvp_byte_t*))
1142+ apiEntry_0_2->TransferRasterData;
1143+ tEntry.opvpSkipRaster = apiEntry_0_2->SkipRaster;
1144+ tEntry.opvpEndRaster = apiEntry_0_2->EndRaster;
1145+ tEntry.opvpStartStream = apiEntry_0_2->StartStream;
1146+ tEntry.opvpTransferStreamData
1147+ = (opvp_result_t (*)(opvp_dc_t,opvp_int_t,
1148+ const void *))
1149+ apiEntry_0_2->TransferStreamData;
1150+ tEntry.opvpEndStream = apiEntry_0_2->EndStream;
1151+
1152+ *apiProcs = &tEntry;
1153+
1154+ GetLastError = GetLastError_0_2;
1155+ }
1156+ }
1157+ return dc;
1158+}
1159+
1160+/* for image */
1161+static const
1162+gx_image_enum_procs_t opvp_image_enum_procs =
1163+{
1164+ opvp_image_plane_data,
1165+ opvp_image_end_image
1166+};
1167+typedef enum _FastImageSupportMode {
1168+ FastImageDisable,
1169+ FastImageNoCTM,
1170+ FastImageNoRotate,
1171+ FastImageRightAngle,
1172+ FastImageReverseAngle,
1173+ FastImageAll
1174+} FastImageSupportMode;
1175+static char *fastImage = NULL;
1176+static FastImageSupportMode FastImageMode = FastImageDisable;
1177+static bool begin_image = false;
1178+static bool change_paint_mode = false;
1179+static bool change_cspace = false;
1180+static gs_color_space_index color_index = 0;
1181+static gs_color_space_index base_color_index = 0;
1182+static byte palette[3*256];
1183+static float imageDecode[GS_IMAGE_MAX_COMPONENTS * 2];
1184+static bool reverse_image = false;
1185+
1186+/* added for image gamma correction */
1187+typedef struct bbox_image_enum_s {
1188+ gx_image_enum_common;
1189+/* gs_memory_t *memory; */
1190+ gs_matrix matrix; /* map from image space to device dpace */
1191+ const gx_clip_path *pcpath;
1192+ gx_image_enum_common_t *target_info;
1193+ bool params_are_const;
1194+ int x0, x1;
1195+ int y, height;
1196+} bbox_image_enum;
1197+
1198+/* The following is already defined in stdpre.h */
1199+/*#define min(a, b) (((a) < (b))? (a) : (b))*/
1200+
1201+
1202+/* ----- Utilities ----- */
1203+
1204+/* initialize Graphic State */
1205+/* No defaults in OPVP 1.0 */
1206+static int
1207+InitGS(void)
1208+{
1209+ if (apiEntry->opvpInitGS != NULL) {
1210+ if (apiEntry->opvpInitGS(printerContext) != OPVP_OK) {
1211+ return -1;
1212+ }
1213+ }
1214+ if (apiEntry->opvpSetColorSpace != NULL) {
1215+ if (apiEntry->opvpSetColorSpace(printerContext,colorSpace)
1216+ != OPVP_OK) {
1217+ return -1;
1218+ }
1219+ }
1220+ if (apiEntry->opvpSetPaintMode != NULL) {
1221+ if (apiEntry->opvpSetPaintMode(printerContext,
1222+ OPVP_PAINTMODE_TRANSPARENT) != OPVP_OK) {
1223+ return -1;
1224+ }
1225+ }
1226+ if (apiEntry->opvpSetAlphaConstant != NULL) {
1227+ if (apiEntry->opvpSetAlphaConstant(printerContext,1.0)
1228+ != OPVP_OK) {
1229+ return -1;
1230+ }
1231+ }
1232+
1233+ /* other properties are set by GhostScript */
1234+ return 0;
1235+}
1236+
1237+static int
1238+opvp_startpage(gx_device *dev)
1239+{
1240+ int ecode = 0;
1241+ opvp_result_t r = -1;
1242+ static char *page_info = NULL;
1243+
1244+ /* page info */
1245+ page_info = opvp_alloc_string(&page_info, OPVP_INFO_PREFIX);
1246+ page_info = opvp_cat_string(&page_info, opvp_gen_page_info(dev));
1247+
1248+ /* call StartPage */
1249+ if (printerContext != -1) {
1250+ if (apiEntry->opvpStartPage)
1251+ r = apiEntry->opvpStartPage(printerContext,
1252+ (opvp_char_t *)opvp_to_utf8(page_info));
1253+ if (r != OPVP_OK) {
1254+ ecode = -1;
1255+ } else {
1256+ ecode = InitGS();
1257+ }
1258+ }
1259+
1260+ return ecode;
1261+}
1262+
1263+static int
1264+opvp_endpage(void)
1265+{
1266+ int ecode = 0;
1267+ opvp_result_t r = -1;
1268+
1269+ /* call EndPage */
1270+ if (printerContext != -1) {
1271+ if (apiEntry->opvpEndPage)
1272+ r = apiEntry->opvpEndPage(printerContext);
1273+ if (r != OPVP_OK) {
1274+ ecode = -1;
1275+ }
1276+ }
1277+
1278+ return ecode;
1279+}
1280+
1281+static char *
1282+opvp_alloc_string(char **destin, const char *source)
1283+{
1284+ if (!destin) return NULL;
1285+
1286+ if (*destin) {
1287+ if (source) {
1288+ *destin = realloc(*destin, strlen(source)+1);
1289+ } else {
1290+ free(*destin);
1291+ *destin = NULL;
1292+ }
1293+ } else {
1294+ if (source) {
1295+ *destin = malloc(strlen(source)+1);
1296+ }
1297+ }
1298+ if (*destin && source) {
1299+ if (*destin != source) {
1300+ strcpy(*destin, source);
1301+ }
1302+ }
1303+
1304+ return *destin;
1305+}
1306+
1307+static char *
1308+opvp_cat_string(char **destin, const char *string)
1309+{
1310+ if (!destin) return NULL;
1311+ if (!(*destin)) return opvp_alloc_string(destin, string);
1312+
1313+ if (string) {
1314+ *destin = realloc(*destin, strlen(*destin) +strlen(string)+1);
1315+ strcat(*destin, string);
1316+ }
1317+
1318+ return *destin;
1319+}
1320+
1321+static char *
1322+opvp_adjust_num_string(char *num_string)
1323+{
1324+ char *pp;
1325+ char *lp;
1326+
1327+ if (!num_string) return NULL;
1328+
1329+ if ((pp = strrchr(num_string, '.'))) {
1330+ for (lp = &(num_string[strlen(num_string)-1]); lp > pp; lp--) {
1331+ if (*lp == '0') {
1332+ *lp = '\0';
1333+ } else {
1334+ break;
1335+ }
1336+ }
1337+ if (lp == pp) *lp = '\0';
1338+ }
1339+
1340+ return num_string;
1341+}
1342+
1343+static char **
1344+opvp_gen_dynamic_lib_name(void)
1345+{
1346+ static char *buff[5] = {NULL,NULL,NULL,NULL,NULL};
1347+ char tbuff[OPVP_BUFF_SIZE];
1348+
1349+ if (!vectorDriver) {
1350+ return NULL;
1351+ }
1352+
1353+ memset((void*)tbuff, 0, OPVP_BUFF_SIZE);
1354+ strncpy(tbuff, vectorDriver, OPVP_BUFF_SIZE - 1);
1355+ opvp_alloc_string(&(buff[0]), tbuff);
1356+
1357+ memset((void*)tbuff, 0, OPVP_BUFF_SIZE);
1358+ strncpy(tbuff, vectorDriver, OPVP_BUFF_SIZE - 4);
1359+ strcat(tbuff, ".so");
1360+ opvp_alloc_string(&(buff[1]), tbuff);
1361+
1362+ memset((void*)tbuff, 0, OPVP_BUFF_SIZE);
1363+ strncpy(tbuff, vectorDriver, OPVP_BUFF_SIZE - 5);
1364+ strcat(tbuff, ".dll");
1365+ opvp_alloc_string(&(buff[2]), tbuff);
1366+
1367+ memset((void*)tbuff, 0, OPVP_BUFF_SIZE);
1368+ strcpy(tbuff, "lib");
1369+ strncat(tbuff, vectorDriver, OPVP_BUFF_SIZE - 7);
1370+ strcat(tbuff, ".so");
1371+ opvp_alloc_string(&(buff[3]), tbuff);
1372+
1373+ buff[4] = NULL;
1374+
1375+ return buff;
1376+}
1377+
1378+static char *
1379+opvp_to_utf8(char *string)
1380+{
1381+ char *locale;
1382+ iconv_t cd;
1383+ char *buff = NULL;
1384+ size_t ib, ob;
1385+ int complete = false;
1386+ char *ibuff, *obuff;
1387+ char *ostring = NULL;
1388+
1389+ if (string) {
1390+ ib = strlen(string);
1391+ if (ib > 0) {
1392+ ob = ib * 4;
1393+ buff = malloc(ob+1);
1394+ setlocale(LC_CTYPE, "");
1395+#ifdef CODESET
1396+ locale = nl_langinfo(CODESET);
1397+#else
1398+ locale = "UTF-8";
1399+#endif /* CODESET */
1400+ if (locale) {
1401+ if (strcmp(locale, "C") && buff) {
1402+ if ((cd = iconv_open("UTF-8", locale)) != (iconv_t)-1) {
1403+ ibuff = string;
1404+ obuff = buff;
1405+ if (iconv(cd, &ibuff, &ib, &obuff, &ob) != -1) {
1406+ *obuff = 0;
1407+ complete = true;
1408+ }
1409+ iconv_close(cd);
1410+ }
1411+ }
1412+ }
1413+ }
1414+ }
1415+
1416+ if (complete) {
1417+ ostring = opvp_alloc_string(&ostring, buff);
1418+ } else {
1419+ ostring = string;
1420+ }
1421+
1422+ if (buff) free(buff);
1423+ return ostring;
1424+}
1425+
1426+static float
1427+opvp_fabsf(float f)
1428+{
1429+ return (float)fabs((double)f);
1430+}
1431+
1432+static int
1433+opvp_get_papertable_index(gx_device *pdev)
1434+{
1435+ int i;
1436+ float width, height;
1437+ bool landscape;
1438+ float paper_w, paper_h;
1439+ float prev = -1;
1440+ int paper = -1;
1441+ int candidate = -1;
1442+ int smaller = -1;
1443+ int larger = -1;
1444+ int s_candi = -1;
1445+ int l_candi = -1;
1446+ float h_delta = TOLERANCE;
1447+ float sw_delta = TOLERANCE;
1448+ float sh_delta = TOLERANCE;
1449+ float lw_delta = TOLERANCE;
1450+ float lh_delta = TOLERANCE;
1451+ bool match = false;
1452+ float f;
1453+
1454+ /* portrait or landscape */
1455+ landscape = (pdev->MediaSize[0] < pdev->MediaSize[1] ? false : true);
1456+
1457+ /* paper size */
1458+ width = (landscape ? pdev->MediaSize[1] : pdev->MediaSize[0]);
1459+ height = (landscape ? pdev->MediaSize[0] : pdev->MediaSize[1]);
1460+
1461+ for (i=0; paperTable[i].name != NULL; i++) {
1462+ paper_w = paperTable[i].width;
1463+ paper_h = paperTable[i].height;
1464+ if (width == paper_w) {
1465+ if (height == paper_h) {
1466+ paper = i;
1467+ match = true;
1468+ break;
1469+ } else if ((f = opvp_fabsf(height - paper_h)) < TOLERANCE) {
1470+ if (f < h_delta) {
1471+ h_delta = f;
1472+ candidate = i;
1473+ }
1474+ }
1475+ } else if (candidate != -1) {
1476+ paper = candidate;
1477+ match = true;
1478+ break;
1479+ } else if (prev != paper_w) {
1480+ prev = paper_w;
1481+ if (paper_w < width) {
1482+ if ((f = opvp_fabsf(width - paper_w)) < TOLERANCE) {
1483+ if (f < sw_delta) {
1484+ sw_delta = f;
1485+ smaller = i;
1486+ }
1487+ }
1488+ } else {
1489+ if ((f = opvp_fabsf(width - paper_w)) < TOLERANCE) {
1490+ if (f < lw_delta) {
1491+ lw_delta = f;
1492+ larger = i;
1493+ }
1494+ }
1495+ }
1496+ }
1497+ }
1498+ if (!match) {
1499+ paper = i;
1500+ if (smaller != -1) {
1501+ paper_w = paperTable[smaller].width;
1502+ for (i = smaller; paperTable[i].width == paper_w; i++) {
1503+ paper_h = paperTable[i].height;
1504+ if (height == paper_h) {
1505+ sh_delta = 0;
1506+ s_candi = i;
1507+ break;
1508+ } else if ((f = opvp_fabsf(height - paper_h)) < TOLERANCE) {
1509+ if (f < sh_delta) {
1510+ sh_delta = f;
1511+ s_candi = i;
1512+ }
1513+ }
1514+ }
1515+ }
1516+ if (larger != -1) {
1517+ paper_w = paperTable[larger].width;
1518+ for (i = larger; paperTable[i].width == paper_w; i++) {
1519+ paper_h = paperTable[i].height;
1520+ if (height == paper_h) {
1521+ lh_delta = 0;
1522+ l_candi = i;
1523+ break;
1524+ } else if ((f = opvp_fabsf(height - paper_h)) < TOLERANCE) {
1525+ if (f < lh_delta) {
1526+ lh_delta = f;
1527+ l_candi = i;
1528+ }
1529+ }
1530+ }
1531+ }
1532+ if (s_candi != -1) {
1533+ if (l_candi != -1) {
1534+ if ((sw_delta + sh_delta)
1535+ < (lw_delta + lh_delta)) {
1536+ paper = s_candi;
1537+ } else {
1538+ paper = l_candi;
1539+ }
1540+ } else {
1541+ paper = s_candi;
1542+ }
1543+ } else {
1544+ if (l_candi != -1) {
1545+ paper = l_candi;
1546+ }
1547+ }
1548+ }
1549+
1550+ return paper;
1551+}
1552+
1553+static char *
1554+opvp_get_sizestring(float width, float height)
1555+{
1556+ char nbuff[OPVP_BUFF_SIZE];
1557+ char nbuff1[OPVP_BUFF_SIZE / 2];
1558+ char nbuff2[OPVP_BUFF_SIZE / 2];
1559+ static char *buff = NULL;
1560+
1561+ memset((void*)nbuff, 0, OPVP_BUFF_SIZE);
1562+ memset((void*)nbuff1, 0, OPVP_BUFF_SIZE / 2);
1563+ memset((void*)nbuff2, 0, OPVP_BUFF_SIZE / 2);
1564+
1565+ snprintf(nbuff1, OPVP_BUFF_SIZE / 2 - 1, "%.3f", width);
1566+ snprintf(nbuff2, OPVP_BUFF_SIZE / 2 - 1, "%.3f", height);
1567+ snprintf(nbuff, OPVP_BUFF_SIZE - 1, "%sx%s",
1568+ opvp_adjust_num_string(nbuff1),
1569+ opvp_adjust_num_string(nbuff2));
1570+
1571+ return opvp_alloc_string(&buff, nbuff);
1572+}
1573+
1574+static char *
1575+opvp_get_mediasize(gx_device *pdev)
1576+{
1577+ int i;
1578+ char wbuff[OPVP_BUFF_SIZE];
1579+ static char *buff = NULL;
1580+ const char *region;
1581+ const char *name;
1582+ float width;
1583+ float height;
1584+ const char *unit;
1585+ bool landscape;
1586+
1587+ i = opvp_get_papertable_index(pdev);
1588+
1589+ if (paperTable[i].name) {
1590+ region = paperTable[i].region;
1591+ name = paperTable[i].name;
1592+ width = paperTable[i].width / PS_DPI;
1593+ height = paperTable[i].height / PS_DPI;
1594+ if((strcmp(region, "na" ) == 0) ||
1595+ (strcmp(region, "asme") == 0) ||
1596+ (strcmp(region, "roc" ) == 0) ||
1597+ (strcmp(region, "oe" ) == 0)) {
1598+ unit = "in";
1599+ } else {
1600+ width *= MMPI;
1601+ height *= MMPI;
1602+ unit = "mm";
1603+ }
1604+ } else {
1605+ landscape = (pdev->MediaSize[0] < pdev->MediaSize[1] ?
1606+ false : true);
1607+ region = "custom";
1608+ name = "opvp";
1609+ width = (landscape ? pdev->MediaSize[1] : pdev->MediaSize[0])
1610+ / PS_DPI;
1611+ height = (landscape ? pdev->MediaSize[0] : pdev->MediaSize[1])
1612+ / PS_DPI;
1613+ unit = "in";
1614+ }
1615+ memset((void*)wbuff, 0, OPVP_BUFF_SIZE);
1616+ snprintf(wbuff, OPVP_BUFF_SIZE - 1, "%s_%s_%s%s", region, name,
1617+ opvp_get_sizestring(width, height),
1618+ unit);
1619+ buff = opvp_alloc_string(&buff, wbuff);
1620+
1621+ return buff;
1622+}
1623+
1624+static char *
1625+opvp_gen_page_info(gx_device *dev)
1626+{
1627+ static char *buff = NULL;
1628+ int num_copies = 1;
1629+ bool landscape;
1630+ char tbuff[OPVP_BUFF_SIZE];
1631+
1632+ /* copies */
1633+ if (!inkjet) {
1634+ if (dev->IgnoreNumCopies) {
1635+ num_copies = 1;
1636+ } else if (dev->NumCopies_set > 0) {
1637+ num_copies = dev->NumCopies;
1638+ }
1639+ }
1640+
1641+ landscape = (dev->MediaSize[0] < dev->MediaSize[1] ? false
1642+ : true);
1643+ memset((void*)tbuff, 0, OPVP_BUFF_SIZE);
1644+ snprintf(tbuff, OPVP_BUFF_SIZE - 1,
1645+ "MediaCopy=%d;DeviceResolution=deviceResolution_%s;"
1646+ "MediaPageRotation=%s;MediaSize=%s",
1647+ num_copies,
1648+ opvp_get_sizestring(dev->x_pixels_per_inch, dev->y_pixels_per_inch),
1649+ (landscape ? "landscape" : "portrait"),
1650+ opvp_get_mediasize(dev));
1651+
1652+ opvp_alloc_string(&buff, tbuff);
1653+
1654+ return buff;
1655+}
1656+
1657+static char *
1658+opvp_gen_doc_info(gx_device *dev)
1659+{
1660+ return opvp_gen_page_info(dev);
1661+}
1662+
1663+static char *
1664+opvp_gen_job_info(gx_device *dev)
1665+{
1666+ return opvp_gen_doc_info(dev);
1667+}
1668+
1669+static int
1670+opvp_set_brush_color(gx_device_opvp *pdev, gx_color_index color,
1671+ opvp_brush_t *brush)
1672+{
1673+ int code;
1674+ int ecode = 0;
1675+ gx_color_value rgb[3];
1676+
1677+ code = opvp_map_color_rgb((gx_device *)pdev, color, rgb);
1678+ if (code) {
1679+ ecode = -1;
1680+ } else {
1681+#if ENABLE_SIMPLE_MODE
1682+ brush->colorSpace = colorSpace;
1683+#else
1684+ opvp_result_t r = -1;
1685+ /* call GetColorSpace */
1686+ if (apiEntry->opvpGetColorSpace) {
1687+ r = apiEntry->opvpGetColorSpace(printerContext,
1688+ &(brush->colorSpace));
1689+ }
1690+ if (r != OPVP_OK) {
1691+ brush->colorSpace = OPVP_CSPACE_DEVICEKRGB;
1692+ }
1693+#endif
1694+ brush->pbrush = NULL;
1695+ brush->xorg = brush->yorg = 0;
1696+ brush->color[3] = (color == gx_no_color_index ? -1 : 0);
1697+ brush->color[2] = rgb[0];
1698+ brush->color[1] = rgb[1];
1699+ brush->color[0] = rgb[2];
1700+ }
1701+
1702+ return ecode;
1703+}
1704+
1705+static int
1706+opvp_draw_image(
1707+ gx_device_opvp *pdev,
1708+ int depth,
1709+ int sw,
1710+ int sh,
1711+ int dw,
1712+ int dh,
1713+ int raster,
1714+ int mask,
1715+ const byte *data)
1716+{
1717+ opvp_result_t r = -1;
1718+ int ecode = 0;
1719+ int count;
1720+
1721+ /* check page-in */
1722+ if (opvp_check_in_page(pdev)) return -1;
1723+
1724+ /* image size */
1725+ count = raster * sh;
1726+
1727+ /* call DrawImage */
1728+ if (apiEntry->opvpDrawImage) {
1729+ r = apiEntry->opvpDrawImage(printerContext,
1730+ sw,sh,
1731+ raster,
1732+ mask ? OPVP_IFORMAT_MASK : OPVP_IFORMAT_RAW,
1733+ dw,dh,
1734+ /* discard 'const' qualifier */
1735+ (void *)data);
1736+ }
1737+ if (r != OPVP_OK) {
1738+ /* call StartDrawImage */
1739+ if (apiEntry->opvpStartDrawImage) {
1740+ r = apiEntry->opvpStartDrawImage(printerContext,
1741+ sw,sh,
1742+ raster,
1743+ mask ? OPVP_IFORMAT_MASK : OPVP_IFORMAT_RAW,
1744+ dw,dh);
1745+ }
1746+ if (r == OPVP_OK) {
1747+ /* call TansferDrawImage */
1748+ if (apiEntry->opvpTransferDrawImage) {
1749+ r = apiEntry->opvpTransferDrawImage(
1750+ printerContext,
1751+ count,
1752+ /* discard 'const' qualifier */
1753+ (void *)data);
1754+ }
1755+ if (r != OPVP_OK) ecode = -1;
1756+
1757+ /* call EndDrawImage */
1758+ if (apiEntry->opvpEndDrawImage) {
1759+ apiEntry->opvpEndDrawImage(printerContext);
1760+ }
1761+ } else {
1762+ ecode = 0; /* continue... */
1763+ }
1764+ }
1765+
1766+ return ecode;
1767+}
1768+
1769+/* ----- load/unload vector driver ----- */
1770+
1771+/*
1772+ * load vector-driver
1773+ */
1774+static int
1775+opvp_load_vector_driver(void)
1776+{
1777+ char **list = NULL;
1778+ int i;
1779+ void *h;
1780+
1781+ if (handle) {
1782+ opvp_unload_vector_driver();
1783+ }
1784+
1785+ if (vectorDriver) {
1786+ list = opvp_gen_dynamic_lib_name();
1787+ }
1788+
1789+ if (list) {
1790+ i = 0;
1791+ while (list[i]) {
1792+ if ((h = dlopen(list[i],RTLD_NOW))) {
1793+ OpenPrinter = dlsym(h,"opvpOpenPrinter");
1794+ ErrorNo = dlsym(h,"opvpErrorNo");
1795+ if (OpenPrinter && ErrorNo) {
1796+ handle = h;
1797+ break;
1798+ }
1799+ OpenPrinter = NULL;
1800+ ErrorNo = NULL;
1801+ /* try version 0.2 driver */
1802+ OpenPrinter_0_2 = dlsym(h,"OpenPrinter");
1803+ ErrorNo = dlsym(h,"errorno");
1804+ if (OpenPrinter_0_2 && ErrorNo) {
1805+ handle = h;
1806+ break;
1807+ }
1808+ OpenPrinter_0_2 = NULL;
1809+ ErrorNo = NULL;
1810+ }
1811+ i++;
1812+ }
1813+ }
1814+
1815+ if (handle) {
1816+ return 0;
1817+ } else {
1818+ return -1;
1819+ }
1820+}
1821+
1822+/*
1823+ * unload vector-driver
1824+ */
1825+static int
1826+opvp_unload_vector_driver(void)
1827+{
1828+ if (handle) {
1829+ dlclose(handle);
1830+ handle = NULL;
1831+ OpenPrinter = NULL;
1832+ ErrorNo = NULL;
1833+ }
1834+ return 0;
1835+}
1836+
1837+/*
1838+ * prepare open
1839+ */
1840+static int
1841+prepare_open(gx_device *dev)
1842+{
1843+ int ecode = 0;
1844+ int code;
1845+ opvp_result_t r = -1;
1846+ opvp_api_procs_t *api_entry;
1847+ int dumFD = -1;
1848+ opvp_dc_t dumContext = -1;
1849+ opvp_cspace_t cspace = OPVP_CSPACE_STANDARDRGB;
1850+
1851+ /* open dummy device */
1852+ code = open("/dev/null", O_RDWR);
1853+ if (code < 0) ecode = code;
1854+ else dumFD = code;
1855+
1856+ /* load vector driver */
1857+ if (!ecode) {
1858+ if ((code = opvp_load_vector_driver())) {
1859+ ecode = code;
1860+ }
1861+ }
1862+
1863+ /* prepare array of function pointer for PDAPI */
1864+ if (!ecode) {
1865+ if (!apiEntry) {
1866+ if (!(apiEntry = calloc(sizeof(opvp_api_procs_t), 1))) {
1867+ ecode = -1;
1868+ }
1869+ } else {
1870+ memset(apiEntry, 0, sizeof(opvp_api_procs_t));
1871+ }
1872+ }
1873+
1874+ /* call opvpOpenPrinter as dummy */
1875+ if (!ecode) {
1876+ opvp_dc_t dc;
1877+ opvp_int_t apiVersion[2];
1878+
1879+ /* require version 1.0 */
1880+ apiVersion[0] = 1;
1881+ apiVersion[1] = 0;
1882+ dc = OpenPrinterWrapper(dumFD, (opvp_char_t *)printerModel,
1883+ apiVersion,&api_entry);
1884+ if (dc == -1) {
1885+ ecode = -1;
1886+ } else {
1887+ dumContext = dc;
1888+ }
1889+ }
1890+
1891+ /* set apiEntry */
1892+ if (!ecode) {
1893+ nApiEntry = sizeof(opvp_api_procs_t)/sizeof(void *);
1894+ memcpy(apiEntry, api_entry, nApiEntry*sizeof(void *));
1895+ } else {
1896+ if (apiEntry) free(apiEntry);
1897+ apiEntry = NULL;
1898+ }
1899+
1900+ /* check vector fucntion */
1901+ if (apiEntry) {
1902+ if (!inkjet) {
1903+ if (!(apiEntry->opvpNewPath) ||
1904+ !(apiEntry->opvpEndPath) ||
1905+ !(apiEntry->opvpStrokePath) ||
1906+ !(apiEntry->opvpSetCurrentPoint) ||
1907+ !(apiEntry->opvpLinePath) ||
1908+ !(apiEntry->opvpBezierPath)) {
1909+ /* NOT avail vector drawing mode */
1910+ vector = false;
1911+ }
1912+ }
1913+ /* call GetColorSpace */
1914+ if (apiEntry->opvpGetColorSpace) {
1915+ r = apiEntry->opvpGetColorSpace(dumContext, &cspace);
1916+ }
1917+ if (cspace == OPVP_CSPACE_BW) {
1918+ /* mono-color */
1919+ colorSpace = cspace;
1920+ dev->color_info.num_components = 1;
1921+ dev->color_info.depth = 1;
1922+ dev->color_info.max_gray = 0;
1923+ dev->color_info.max_color = 0;
1924+ dev->color_info.dither_grays = 1;
1925+ dev->color_info.dither_colors = 1;
1926+ } else if (cspace == OPVP_CSPACE_DEVICEGRAY) {
1927+ /* gray-scale */
1928+ colorSpace = cspace;
1929+ dev->color_info.num_components = 1;
1930+ dev->color_info.depth = 8;
1931+ dev->color_info.max_gray = 255;
1932+ dev->color_info.max_color = 255;
1933+ dev->color_info.dither_grays = 256;
1934+ dev->color_info.dither_colors = 256;
1935+ } else {
1936+ /* rgb color */
1937+ colorSpace = OPVP_CSPACE_STANDARDRGB;
1938+ dev->color_info.num_components = 3;
1939+ dev->color_info.depth = 24;
1940+ dev->color_info.max_gray = 255;
1941+ dev->color_info.max_color = 255;
1942+ dev->color_info.dither_grays = 256;
1943+ dev->color_info.dither_colors = 256;
1944+ }
1945+#if GS_VERSION_MAJOR >= 8
1946+ dev->procs.get_color_mapping_procs = NULL;
1947+ dev->procs.get_color_comp_index = NULL;
1948+ gx_device_fill_in_procs(dev);
1949+#endif
1950+ }
1951+
1952+ /* call Closerinter as dummy */
1953+ if (dumContext != -1) {
1954+ /* call ClosePrinter */
1955+ if (apiEntry->opvpClosePrinter) {
1956+ apiEntry->opvpClosePrinter(dumContext);
1957+ }
1958+ dumContext = -1;
1959+ }
1960+
1961+ /* close device for dummy */
1962+ if (dumFD != -1) {
1963+ close(dumFD);
1964+ dumFD = -1;
1965+ }
1966+
1967+ /* un-load vector driver */
1968+ opvp_unload_vector_driver();
1969+
1970+ return ecode;
1971+}
1972+
1973+/* ----- driver procs ----- */
1974+/*
1975+ * open device
1976+ */
1977+static int
1978+opvp_open(gx_device *dev)
1979+{
1980+ gx_device_opvp *pdev = (gx_device_opvp *)dev;
1981+ gx_device_oprp *rdev = (gx_device_oprp *)dev;
1982+ int ecode = 0;
1983+ int code;
1984+ opvp_result_t r = -1;
1985+ opvp_dc_t dc;
1986+ opvp_api_procs_t *api_entry;
1987+ char *job_info = NULL;
1988+ char *doc_info = NULL;
1989+ char *tmp_info = NULL;
1990+ float margin_width = 0;
1991+ float margin_height = 0;
1992+ float adj_margins[4];
1993+ opvp_int_t apiVersion[2];
1994+
1995+ /* prepare open : load and open as dummy */
1996+ code = prepare_open(dev);
1997+ if (code) {
1998+ ecode = code;
1999+ return ecode;
2000+ }
2001+
2002+ /* set margins */
2003+ if (zoomAuto) {
2004+ margin_width = (margins[0] + margins[2])
2005+ * dev->HWResolution[0];
2006+ margin_height = (margins[1] + margins[3])
2007+ * dev->HWResolution[1];
2008+ zoom[0] = (dev->width - margin_width) / dev->width;
2009+ zoom[1] = (dev->height - margin_height) / dev->height;
2010+ if (zoom[0] < zoom[1]) {
2011+ zoom[1] = zoom[0];
2012+ } else {
2013+ zoom[0] = zoom[1];
2014+ }
2015+ }
2016+ if (inkjet) {
2017+ if ((margins[0] != 0) ||
2018+ (margins[1] != 0) || (margins[3] != 0)) {
2019+ shift[0] = margins[0] * dev->HWResolution[0];
2020+ shift[1] = (margins[1] + margins[3])
2021+ * dev->HWResolution[1];
2022+ zooming = true;
2023+ }
2024+ dev->width -= margins[2] * dev->HWResolution[0];
2025+ dev->height -= margins[1] * dev->HWResolution[1];
2026+ } else {
2027+ if ((margins[0] != 0) || (margins[1] != 0)) {
2028+ shift[0] = margins[0] * dev->HWResolution[0];
2029+ shift[1] = margins[3] * dev->HWResolution[1];
2030+ zooming = true;
2031+ }
2032+ adj_margins[0] = 0;
2033+ adj_margins[3] = 0;
2034+ adj_margins[1] = dev->height * zoom[1] / dev->HWResolution[1]
2035+ - (dev->MediaSize[1] / PS_DPI
2036+ - (margins[1] + margins[3]));
2037+ if (adj_margins[1] < 0) adj_margins[0] = 0;
2038+ adj_margins[2] = dev->width * zoom[0] / dev->HWResolution[0]
2039+ - (dev->MediaSize[0] / PS_DPI
2040+ - (margins[0] + margins[2]));
2041+ if (adj_margins[2] < 0) adj_margins[2] = 0;
2042+ gx_device_set_margins(dev, adj_margins, true);
2043+ }
2044+ if ((zoom[0] != 1) || (zoom[1] != 1)) zooming = true;
2045+
2046+ /* open file for output device */
2047+ if (!inkjet) {
2048+ pdev->v_memory = gs_memory_stable(pdev->memory);
2049+ /* open output stream */
2050+ code = gdev_vector_open_file_options((gx_device_vector*)dev,
2051+ 512,
2052+ (VECTOR_OPEN_FILE_SEQUENTIAL
2053+ |VECTOR_OPEN_FILE_BBOX
2054+ ));
2055+ if (code < 0) {
2056+ ecode = code;
2057+ return ecode;
2058+ }
2059+#if GS_VERSION_MAJOR >= 8
2060+ if (pdev->bbox_device != NULL) {
2061+ if (pdev->bbox_device->memory == NULL) {
2062+ pdev->bbox_device->memory = gs_memory_stable(dev->memory);
2063+ }
2064+#if GS_VERSION_MAJOR >= 9
2065+ if (pdev->bbox_device->device_icc_profile == NULL) {
2066+ pdev->bbox_device->device_icc_profile =
2067+ pdev->device_icc_profile;
2068+ }
2069+#endif
2070+ }
2071+#endif
2072+ outputFD = fileno(pdev->file);
2073+ } else {
2074+ /* open printer device */
2075+ code = gdev_prn_open(dev);
2076+ if (code < 0) {
2077+ ecode = ecode;
2078+ return ecode;
2079+ }
2080+ /* open output stream */
2081+ code = gdev_prn_open_printer_seekable(dev, true, false);
2082+ if (code < 0) {
2083+ ecode = code;
2084+ return ecode;
2085+ }
2086+ outputFD = fileno(rdev->file);
2087+ }
2088+
2089+ /* RE-load vector driver */
2090+ if ((code = opvp_load_vector_driver())) {
2091+ ecode = code;
2092+ return ecode;
2093+ }
2094+
2095+ /* call opvpOpenPrinter */
2096+ /* require version 1.0 */
2097+ apiVersion[0] = 1;
2098+ apiVersion[1] = 0;
2099+ dc = OpenPrinterWrapper(outputFD,(opvp_char_t *)printerModel,
2100+ apiVersion,&api_entry);
2101+ if (!apiEntry) {
2102+ if (!(apiEntry = calloc(sizeof(opvp_api_procs_t), 1))) {
2103+ ecode = -1;
2104+ }
2105+ } else {
2106+ memset(apiEntry, 0, sizeof(opvp_api_procs_t));
2107+ }
2108+ if (dc == -1) {
2109+ ecode = -1;
2110+ if (apiEntry) free(apiEntry);
2111+ apiEntry = NULL;
2112+ opvp_unload_vector_driver();
2113+ if (inkjet) gdev_prn_close(dev);
2114+ else gdev_vector_close_file((gx_device_vector *)pdev);
2115+ return ecode;
2116+ }
2117+ printerContext = dc;
2118+ nApiEntry = sizeof(opvp_api_procs_t)/sizeof(void *);
2119+ memcpy(apiEntry, api_entry, nApiEntry*sizeof(void *));
2120+
2121+ /* initialize */
2122+ if ((!ecode) && (!inkjet)) {
2123+ pdev->vec_procs = &opvp_vector_procs;
2124+ if (vector) gdev_vector_init((gx_device_vector *)pdev);
2125+ }
2126+
2127+ if (apiEntry->opvpQueryColorSpace) {
2128+ int n = sizeof(cspace_available);
2129+ int nn = n;
2130+ opvp_cspace_t *p = malloc(n*sizeof(opvp_cspace_t));
2131+
2132+ if ((r = apiEntry->opvpQueryColorSpace(printerContext,&nn,p))
2133+ == OPVP_PARAMERROR && nn > n) {
2134+ /* realloc buffer and retry */
2135+ p = realloc(p,nn*sizeof(opvp_cspace_t));
2136+ r = apiEntry->opvpQueryColorSpace(printerContext,&nn,p);
2137+ }
2138+ if (r == OPVP_OK) {
2139+ int i;
2140+
2141+ for (i = 0;i < nn;i++) {
2142+ if (p[i] < sizeof(cspace_available)) {
2143+ cspace_available[p[i]] = 1;
2144+ }
2145+ }
2146+ }
2147+ free(p);
2148+ }
2149+ /* start job */
2150+ if (!ecode) {
2151+ /* job info */
2152+ if (jobInfo) {
2153+ if (strlen(jobInfo) > 0) {
2154+ job_info = opvp_alloc_string(&job_info,jobInfo);
2155+ }
2156+ }
2157+ tmp_info = opvp_alloc_string(&tmp_info,opvp_gen_job_info(dev));
2158+ if (tmp_info) {
2159+ if (strlen(tmp_info) > 0) {
2160+ if (job_info) {
2161+ if (strlen(job_info) > 0) {
2162+ opvp_cat_string(&job_info, ";");
2163+ }
2164+ }
2165+ job_info = opvp_cat_string(&job_info,OPVP_INFO_PREFIX);
2166+ job_info = opvp_cat_string(&job_info,tmp_info);
2167+ }
2168+ }
2169+
2170+ /* call StartJob */
2171+ if (apiEntry->opvpStartJob) {
2172+ r = apiEntry->opvpStartJob(printerContext,
2173+ (opvp_char_t *)opvp_to_utf8(job_info));
2174+ }
2175+ if (r != OPVP_OK) {
2176+ ecode = -1;
2177+ }
2178+ }
2179+
2180+ /* start doc */
2181+ if (!ecode) {
2182+ /* doc info */
2183+ if (docInfo) {
2184+ if (strlen(docInfo) > 0) {
2185+ doc_info = opvp_alloc_string(&doc_info,docInfo);
2186+ }
2187+ }
2188+ tmp_info = opvp_alloc_string(&tmp_info, opvp_gen_doc_info(dev));
2189+ if (tmp_info) {
2190+ if (strlen(tmp_info) > 0) {
2191+ if (doc_info) {
2192+ if (strlen(doc_info) > 0) {
2193+ opvp_cat_string(&doc_info, ";");
2194+ }
2195+ }
2196+ doc_info = opvp_cat_string(&doc_info,OPVP_INFO_PREFIX);
2197+ doc_info = opvp_cat_string(&doc_info,tmp_info);
2198+ }
2199+ }
2200+
2201+ /* call StartDoc */
2202+ if (apiEntry->opvpStartDoc) {
2203+ r = apiEntry->opvpStartDoc(printerContext,
2204+ (opvp_char_t *)opvp_to_utf8(doc_info));
2205+ }
2206+ if (r != OPVP_OK) {
2207+ ecode = -1;
2208+ }
2209+ }
2210+
2211+ if (tmp_info) opvp_alloc_string(&tmp_info, NULL);
2212+ if (doc_info) opvp_alloc_string(&doc_info, NULL);
2213+ if (job_info) opvp_alloc_string(&job_info, NULL);
2214+
2215+ return ecode;
2216+}
2217+
2218+/*
2219+ * open device for inkjet
2220+ */
2221+static int
2222+oprp_open(gx_device *dev)
2223+{
2224+ /* set inkjet mode */
2225+ vector = false;
2226+ inkjet = true;
2227+
2228+ /* matrix */
2229+ dev->procs.get_initial_matrix = opvp_get_initial_matrix;
2230+ return opvp_open(dev);
2231+}
2232+
2233+/*
2234+ * get initial matrix
2235+ */
2236+static void
2237+opvp_get_initial_matrix(gx_device *dev, gs_matrix *pmat)
2238+{
2239+ gx_device_opvp *pdev = (gx_device_opvp *)dev;
2240+ opvp_ctm_t omat;
2241+
2242+ gx_default_get_initial_matrix(dev,pmat);
2243+ if (zooming) {
2244+ /* gs matrix */
2245+ pmat->xx *= zoom[0];
2246+ pmat->xy *= zoom[1];
2247+ pmat->yx *= zoom[0];
2248+ pmat->yy *= zoom[1];
2249+ pmat->tx = pmat->tx * zoom[0] + shift[0];
2250+ pmat->ty = pmat->ty * zoom[1] + shift[1];
2251+ }
2252+
2253+ if (pdev->is_open) {
2254+ /* call ResetCTM */
2255+ if (apiEntry->opvpResetCTM) {
2256+ apiEntry->opvpResetCTM(printerContext);
2257+ } else {
2258+ /* call SetCTM */
2259+ omat.a = 1;
2260+ omat.b = 0;
2261+ omat.c = 0;
2262+ omat.d = 1;
2263+ omat.e = 0;
2264+ omat.f = 0;
2265+ if (apiEntry->opvpSetCTM) {
2266+ apiEntry->opvpSetCTM(printerContext, &omat);
2267+ }
2268+ }
2269+ }
2270+
2271+ return;
2272+}
2273+
2274+/*
2275+ * output page
2276+ */
2277+static int
2278+opvp_output_page(gx_device *dev, int num_copies, int flush)
2279+{
2280+ gx_device_opvp *pdev = (gx_device_opvp *)dev;
2281+ int ecode = 0;
2282+ int code = -1;
2283+
2284+ if (inkjet) return gdev_prn_output_page(dev, num_copies, flush);
2285+
2286+#ifdef OPVP_IGNORE_BLANK_PAGE
2287+ if (pdev->in_page) {
2288+#else
2289+ /* check page-in */
2290+ if (opvp_check_in_page(pdev)) return -1;
2291+#endif
2292+ /* end page */
2293+ code = opvp_endpage();
2294+ if (code) ecode = code;
2295+
2296+ pdev->in_page = false;
2297+ beginPage = false;
2298+#ifdef OPVP_IGNORE_BLANK_PAGE
2299+ }
2300+#endif
2301+
2302+ if (vector) {
2303+ gdev_vector_reset((gx_device_vector *)pdev);
2304+ }
2305+
2306+ code = gx_finish_output_page(dev, num_copies, flush);
2307+ if (code) ecode = code;
2308+
2309+ return ecode;
2310+}
2311+
2312+/*
2313+ * print page
2314+ */
2315+static int
2316+oprp_print_page(gx_device_printer *pdev, FILE *prn_stream)
2317+{
2318+ int ecode = 0;
2319+ int code = -1;
2320+ opvp_result_t r = -1;
2321+ int raster_size;
2322+ int buff_size;
2323+ byte *buff = NULL;
2324+ int line;
2325+ int scan_lines;
2326+ byte *data;
2327+ int rasterWidth;
2328+ bool start_page = false;
2329+ bool start_raster = false;
2330+#if ENABLE_SKIP_RASTER
2331+ int i;
2332+ byte check;
2333+#endif
2334+
2335+ /* get raster/pixel size */
2336+ raster_size = gx_device_raster((gx_device *)pdev, 0);
2337+ buff_size = ((raster_size + 3) >> 2) << 2;
2338+ scan_lines = dev_print_scan_lines(pdev);
2339+ rasterWidth = pdev->width;
2340+
2341+ /* allocate buffer */
2342+ buff = (byte*)calloc(1, buff_size);
2343+ if (!buff) return ecode = -1;
2344+
2345+ /* start page */
2346+ if (!ecode) {
2347+ code = opvp_startpage((gx_device *)pdev);
2348+ if (code) ecode = code;
2349+ else start_page = true;
2350+ }
2351+
2352+ /* moveto origin */
2353+ if (!ecode)
2354+ opvp_moveto((gx_device_vector*)pdev, 0, 0, 0, 0, 0);
2355+
2356+ /* call StartRaster */
2357+ if (!ecode) {
2358+ if (apiEntry->opvpStartRaster) {
2359+ r = apiEntry->opvpStartRaster(printerContext,rasterWidth);
2360+ }
2361+ if (r != OPVP_OK) {
2362+ ecode = r;
2363+ } else {
2364+ start_raster = true;
2365+ }
2366+ }
2367+
2368+ /* line */
2369+ for (line = 0; (line < scan_lines) && (!ecode); line++) {
2370+ /* get raster data */
2371+ if (!ecode) {
2372+ code = gdev_prn_get_bits(pdev, line, buff, &data);
2373+ if (code) {
2374+ ecode = code;
2375+ break;
2376+ }
2377+ }
2378+#if ENABLE_SKIP_RASTER
2379+ /* check support SkipRaster */
2380+ if (apiEntry->opvpSkipRaster) {
2381+ /* check all white */
2382+ if (pdev->color_info.depth > 8) {
2383+ for (check = 0xff, i = 0; i < raster_size; i++)
2384+ {
2385+ check &= data[i];
2386+ if (check != 0xff) break;
2387+ }
2388+ /* if all white call SkipRaster */
2389+ if (check == 0xff) {
2390+ r = apiEntry->opvpSkipRaster(printerContext, 1);
2391+ if (r == OPVP_OK) continue;
2392+ }
2393+ } else {
2394+ for (check = 0, i = 0; i < raster_size; i++) {
2395+ check |= data[i];
2396+ if (check) break;
2397+ }
2398+ /* if all zero call SkipRaster */
2399+ if (check) {
2400+ r = apiEntry->opvpSkipRaster(printerContext, 1);
2401+ if (r == OPVP_OK) continue;
2402+ }
2403+ }
2404+ }
2405+#endif
2406+ /* call TransferRasterData */
2407+ if (!ecode) {
2408+ if (apiEntry->opvpTransferRasterData) {
2409+ r = apiEntry->opvpTransferRasterData(printerContext,
2410+ raster_size,
2411+ data);
2412+ }
2413+ if (r != OPVP_OK) ecode = r;
2414+ }
2415+ }
2416+
2417+ /* call EndRaster */
2418+ if (start_raster) {
2419+ if (apiEntry->opvpEndRaster) {
2420+ r = apiEntry->opvpEndRaster(printerContext);
2421+ }
2422+ if (r != OPVP_OK) ecode = r;
2423+ start_raster = false;
2424+ }
2425+
2426+ /* end page */
2427+ if (start_page) {
2428+ code = opvp_endpage();
2429+ if (code) ecode = code;
2430+ start_page = false;
2431+ }
2432+
2433+ /* free buffer */
2434+ if (buff) {
2435+ free(buff);
2436+ buff = NULL;
2437+ }
2438+
2439+ return ecode;
2440+}
2441+
2442+/*
2443+ * close device
2444+ */
2445+static int
2446+opvp_close(gx_device *dev)
2447+{
2448+ gx_device_opvp *pdev = (gx_device_opvp *)dev;
2449+ int ecode = 0;
2450+
2451+ /* finalize */
2452+ if (printerContext != -1) {
2453+ /* call EndDoc */
2454+ if (apiEntry->opvpEndDoc) {
2455+ apiEntry->opvpEndDoc(printerContext);
2456+ }
2457+
2458+ /* call EndJob */
2459+ if (apiEntry->opvpEndJob) {
2460+ apiEntry->opvpEndJob(printerContext);
2461+ }
2462+
2463+ /* call ClosePrinter */
2464+ if (apiEntry->opvpClosePrinter) {
2465+ apiEntry->opvpClosePrinter(printerContext);
2466+ }
2467+ printerContext = -1;
2468+ }
2469+
2470+ /* unload vector driver */
2471+ if (apiEntry) free(apiEntry);
2472+ apiEntry = NULL;
2473+ opvp_unload_vector_driver();
2474+
2475+ if (inkjet) {
2476+ /* close printer */
2477+ gdev_prn_close(dev);
2478+ } else {
2479+ /* close output stream */
2480+ gdev_vector_close_file((gx_device_vector *)pdev);
2481+ }
2482+ outputFD = -1;
2483+
2484+ return ecode;
2485+}
2486+
2487+/*
2488+ * map rgb color
2489+ */
2490+#if GS_VERSION_MAJOR >= 8
2491+static gx_color_index
2492+opvp_map_rgb_color(gx_device *dev,
2493+ const gx_color_value *prgb /* modified for gs 8.15 */)
2494+#else
2495+static gx_color_index
2496+opvp_map_rgb_color(gx_device *dev,
2497+ gx_color_value r,
2498+ gx_color_value g,
2499+ gx_color_value b)
2500+#endif
2501+{
2502+ opvp_cspace_t cs;
2503+ uint c, m, y, k;
2504+
2505+#if !(ENABLE_SIMPLE_MODE)
2506+ gx_device_opvp *pdev;
2507+ opvp_result_t r;
2508+#endif
2509+
2510+#if GS_VERSION_MAJOR >= 8
2511+ gx_color_value r, g, b; /* added for gs 8.15 */
2512+ r = prgb[0];
2513+ g = prgb[1];
2514+ b = prgb[2];
2515+#endif
2516+
2517+#if !(ENABLE_SIMPLE_MODE)
2518+ pdev = (gx_device_opvp *)dev;
2519+ r = -1;
2520+#endif
2521+ cs = OPVP_CSPACE_STANDARDRGB;
2522+
2523+#if ENABLE_SIMPLE_MODE
2524+ cs = colorSpace;
2525+#else
2526+ if (pdev->is_open) {
2527+ /* call GetColorSpace */
2528+ if (apiEntry->opvpGetColorSpace) {
2529+ r = apiEntry->opvpGetColorSpace(printerContext, &cs);
2530+ }
2531+ if (r != OPVP_OK) {
2532+ if (pdev->color_info.depth > 32) {
2533+ cs = OPVP_CSPACE_STANDARDRGB64;
2534+ } else if (pdev->color_info.depth > 8 ) {
2535+ cs = OPVP_CSPACE_STANDARDRGB;
2536+ } else if (pdev->color_info.depth > 1 ) {
2537+ cs = OPVP_CSPACE_DEVICEGRAY;
2538+ } else {
2539+ cs = OPVP_CSPACE_BW;
2540+ }
2541+ }
2542+ }
2543+#endif
2544+
2545+ switch (cs) {
2546+ case OPVP_CSPACE_STANDARDRGB64:
2547+ /* unsupported */
2548+ if (sizeof(gx_color_index) >= 6) {
2549+ return (long long)b
2550+ + ((long long)g << 16)
2551+ + ((long long)b << 32);
2552+ } else {
2553+ return gx_color_value_to_byte(b)
2554+ + ((uint)gx_color_value_to_byte(g) << 8)
2555+ + ((ulong)gx_color_value_to_byte(r) << 16);
2556+ }
2557+ break;
2558+ case OPVP_CSPACE_DEVICECMYK:
2559+ case OPVP_CSPACE_DEVICECMY:
2560+ /* unsupported */
2561+ c = gx_color_value_to_byte(~r);
2562+ m = gx_color_value_to_byte(~g);
2563+ y = gx_color_value_to_byte(~b);
2564+ if (cs == OPVP_CSPACE_DEVICECMYK) {
2565+ k = (c<m ? (c<y ? c : y) : (m<y ? m : y));
2566+ c -= k;
2567+ m -= k;
2568+ y -= k;
2569+ } else {
2570+ k = 0;
2571+ }
2572+ return (k + (y << 8) + (m << 16) + (c << 24));
2573+ break;
2574+ case OPVP_CSPACE_DEVICEGRAY:
2575+#if GS_VERSION_MAJOR >= 8
2576+ {
2577+ gx_color_value rgb[3];
2578+ rgb[0] = rgb[1] = rgb[2] = r;
2579+ return gx_default_gray_map_rgb_color(dev, rgb);
2580+ }
2581+#else
2582+ return gx_default_gray_map_rgb_color(dev, r, g, b);
2583+#endif
2584+ break;
2585+ case OPVP_CSPACE_BW :
2586+#if GS_VERSION_MAJOR >= 8
2587+ return gx_default_b_w_map_rgb_color(dev, prgb);
2588+#else
2589+ return gx_default_b_w_map_rgb_color(dev, r, g, b);
2590+#endif
2591+ break;
2592+ case OPVP_CSPACE_STANDARDRGB:
2593+ case OPVP_CSPACE_DEVICEKRGB:
2594+ default:
2595+#if GS_VERSION_MAJOR >= 8
2596+ return gx_default_rgb_map_rgb_color(dev, prgb);
2597+#else
2598+ return gx_default_rgb_map_rgb_color(dev, r, g, b);
2599+#endif
2600+ break;
2601+ }
2602+}
2603+
2604+/*
2605+ * map color rgb
2606+ */
2607+static int
2608+opvp_map_color_rgb(gx_device *dev, gx_color_index color,
2609+ gx_color_value prgb[3])
2610+{
2611+#if !(ENABLE_SIMPLE_MODE)
2612+ gx_device_opvp *pdev = (gx_device_opvp *)dev;
2613+ opvp_result_t r = -1;
2614+#endif
2615+ opvp_cspace_t cs = OPVP_CSPACE_STANDARDRGB;
2616+ uint c, m, y, k;
2617+
2618+#if ENABLE_SIMPLE_MODE
2619+ cs = colorSpace;
2620+#else
2621+ /* call GetColorSpace */
2622+ if (pdev->is_open) {
2623+ if (apiEntry->opvpGetColorSpace) {
2624+ r = apiEntry->opvpGetColorSpace(printerContext, &cs);
2625+ }
2626+ if (r != OPVP_OK) {
2627+ if (pdev->color_info.depth > 32) {
2628+ cs = OPVP_CSPACE_STANDARDRGB64;
2629+ } else if (pdev->color_info.depth > 8 ) {
2630+ cs = OPVP_CSPACE_STANDARDRGB;
2631+ } else if (pdev->color_info.depth > 1 ) {
2632+ cs = OPVP_CSPACE_DEVICEGRAY;
2633+ } else {
2634+ cs = OPVP_CSPACE_BW;
2635+ }
2636+ }
2637+ }
2638+#endif
2639+
2640+ switch (cs) {
2641+ case OPVP_CSPACE_STANDARDRGB64:
2642+ /* unsupported */
2643+ if (sizeof(gx_color_index) >= 6) {
2644+ prgb[0] = ((long long)color >> 32) & 0xffff;
2645+ prgb[1] = ((long long)color >> 16) & 0xffff;
2646+ prgb[2] = color & 0xffff;
2647+ } else {
2648+ prgb[0] = gx_color_value_from_byte((color >> 16) & 0xff);
2649+ prgb[1] = gx_color_value_from_byte((color >> 8) & 0xff);
2650+ prgb[2] = gx_color_value_from_byte(color & 0xff);
2651+ }
2652+ break;
2653+ case OPVP_CSPACE_DEVICECMYK:
2654+ case OPVP_CSPACE_DEVICECMY:
2655+ /* unsupported */
2656+ c = gx_color_value_from_byte((color >> 24) & 0xff);
2657+ m = gx_color_value_from_byte((color >> 16) & 0xff);
2658+ y = gx_color_value_from_byte((color >> 8) & 0xff);
2659+ if (cs == OPVP_CSPACE_DEVICECMYK) {
2660+ k = gx_color_value_from_byte(color & 0xff);
2661+ c += k; if (c > 255) c = 255;
2662+ m += k; if (m > 255) m = 255;
2663+ y += k; if (y > 255) y = 255;
2664+ }
2665+ prgb[0] = gx_color_value_from_byte(~c & 0xff);
2666+ prgb[1] = gx_color_value_from_byte(~m & 0xff);
2667+ prgb[2] = gx_color_value_from_byte(~y & 0xff);
2668+ break;
2669+ case OPVP_CSPACE_DEVICEGRAY:
2670+ return gx_default_gray_map_color_rgb(dev, color, prgb);
2671+ break;
2672+ case OPVP_CSPACE_BW:
2673+ return gx_default_b_w_map_color_rgb(dev, color, prgb);
2674+ break;
2675+ case OPVP_CSPACE_STANDARDRGB:
2676+ case OPVP_CSPACE_DEVICEKRGB:
2677+ default:
2678+ return gx_default_rgb_map_color_rgb(dev, color, prgb);
2679+ break;
2680+ }
2681+
2682+ return 0;
2683+}
2684+
2685+/*
2686+ * fill rectangle
2687+ */
2688+static int
2689+opvp_fill_rectangle(
2690+ gx_device *dev,
2691+ int x,
2692+ int y,
2693+ int w,
2694+ int h,
2695+ gx_color_index color)
2696+{
2697+ gx_device_opvp *pdev = (gx_device_opvp *)dev;
2698+ byte data[8] = {0xC0, 0, 0, 0, 0xC0, 0, 0, 0};
2699+ int code = -1;
2700+ int ecode = 0;
2701+ opvp_brush_t brush;
2702+ opvp_point_t point;
2703+
2704+ if (vector) {
2705+ return gdev_vector_fill_rectangle( dev, x, y, w, h, color);
2706+ }
2707+
2708+ /* check page-in */
2709+ if (opvp_check_in_page(pdev)) return -1;
2710+
2711+#if !(ENABLE_SIMPLE_MODE)
2712+ /* call SaveGS */
2713+ if (apiEntry->opvpSaveGS) {
2714+ apiEntry->opvpSaveGS(printerContext);
2715+ }
2716+#endif
2717+
2718+ /* one-color */
2719+ opvp_set_brush_color(pdev, color, &brush);
2720+
2721+ /* call SetFillColor */
2722+ if (apiEntry->opvpSetFillColor) {
2723+ apiEntry->opvpSetFillColor(printerContext, &brush);
2724+ }
2725+
2726+ /* call SetCurrentPoint */
2727+ OPVP_I2FIX(x, point.x);
2728+ OPVP_I2FIX(y, point.y);
2729+ if (apiEntry->opvpSetCurrentPoint) {
2730+ apiEntry->opvpSetCurrentPoint(printerContext,point.x, point.y);
2731+ }
2732+
2733+ /* draw image */
2734+ code = opvp_draw_image(pdev,
2735+ 1,
2736+ 2, 2,
2737+ w, h,
2738+ 4,
2739+ 0,
2740+ data);
2741+ if (code) {
2742+ ecode = code;
2743+ }
2744+
2745+ /* restore fill color */
2746+ if (vectorFillColor) {
2747+ /* call SetFillColor */
2748+ if (apiEntry->opvpSetFillColor) {
2749+ apiEntry->opvpSetFillColor(printerContext,vectorFillColor);
2750+ }
2751+ }
2752+
2753+#if !(ENABLE_SIMPLE_MODE)
2754+ /* call RestoreGS */
2755+ if (apiEntry->opvpRestoreGS) {
2756+ apiEntry->opvpRestoreGS(printerContext);
2757+ }
2758+#endif
2759+
2760+ return ecode;
2761+}
2762+
2763+/*
2764+ * copy mono
2765+ */
2766+static int
2767+opvp_copy_mono(
2768+ gx_device *dev,
2769+ const byte *data,
2770+ int data_x,
2771+ int raster,
2772+ gx_bitmap_id id,
2773+ int x,
2774+ int y,
2775+ int w,
2776+ int h,
2777+ gx_color_index zero,
2778+ gx_color_index one)
2779+{
2780+ gx_device_opvp *pdev = (gx_device_opvp *)dev;
2781+ int code = -1;
2782+ int ecode = 0;
2783+ opvp_brush_t brush;
2784+ opvp_point_t point;
2785+ const byte *buff = data;
2786+ byte *mybuf = NULL;
2787+ int i, j;
2788+ byte *d;
2789+ const byte *s;
2790+ int byte_offset = 0;
2791+ int byte_length = raster;
2792+ int bit_shift = 0;
2793+ int adj_raster = raster;
2794+ unsigned char bit_mask = 0xff;
2795+ bool reverse = false;
2796+
2797+ /* check page-in */
2798+ if (opvp_check_in_page(pdev)) return -1;
2799+
2800+ /* data offset */
2801+ if (data_x) {
2802+ byte_offset = data_x >> 3;
2803+ bit_shift = data_x & 0x07;
2804+ if (bit_shift) bit_mask <<= (8 - bit_shift);
2805+
2806+ byte_length = ((w + 7) >> 3);
2807+ adj_raster = ((byte_length + 3) >> 2) << 2;
2808+
2809+ buff = mybuf = calloc(adj_raster, h);
2810+ if (!mybuf) {
2811+ /* memory error */
2812+ return -1;
2813+ }
2814+ s = &(data[byte_offset]);
2815+ d = mybuf;
2816+ if (bit_shift) {
2817+ for (i = 0;i < h; i++, d += adj_raster, s+= raster) {
2818+ for (j = 0; j < byte_length; j++) {
2819+ d[j] = ((s[j] & ~bit_mask) << bit_shift)
2820+ | ((s[j + 1] & bit_mask) >> (8 - bit_shift));
2821+ }
2822+ }
2823+ } else {
2824+ for (i = 0;i < h; i++, d += adj_raster, s+= raster) {
2825+ for (j = 0; j < byte_length; j++) {
2826+ d[j] = s[j];
2827+ }
2828+ }
2829+ }
2830+ byte_offset = 0;
2831+ }
2832+
2833+#if !(ENABLE_SIMPLE_MODE)
2834+ /* call SaveGS */
2835+ if (apiEntry->opvpSaveGS) {
2836+ apiEntry->opvpSaveGS(printerContext);
2837+ }
2838+#endif
2839+ if (one == gx_no_color_index) {
2840+ gx_color_index tc;
2841+
2842+ reverse = (!reverse);
2843+ tc = zero;
2844+ zero = one;
2845+ one = tc;
2846+ }
2847+
2848+ if (zero != gx_no_color_index) {
2849+ /* not mask */
2850+ /* Set PaintMode */
2851+ if (apiEntry->opvpSetPaintMode) {
2852+ apiEntry->opvpSetPaintMode(printerContext,OPVP_PAINTMODE_OPAQUE);
2853+ }
2854+ /* zero-color */
2855+ opvp_set_brush_color(pdev, zero, &brush);
2856+
2857+ /* call SetBgColor */
2858+ if (apiEntry->opvpSetBgColor) {
2859+ apiEntry->opvpSetBgColor(printerContext, &brush);
2860+ }
2861+ }
2862+
2863+ /* one-color */
2864+ opvp_set_brush_color(pdev, one, &brush);
2865+
2866+ /* call SetFillColor */
2867+ if (apiEntry->opvpSetFillColor) {
2868+ apiEntry->opvpSetFillColor(printerContext, &brush);
2869+ }
2870+
2871+ if (reverse) {
2872+ /* 0/1 reverse image */
2873+ int n = adj_raster*h;
2874+
2875+ if (buff == data) {
2876+ /* buff was not allocated from this function yet */
2877+ /* allocate here */
2878+ if ((mybuf = malloc(n)) == 0) return -1;
2879+ }
2880+ for (i = 0;i < n;i++) {
2881+ mybuf[i] = ~buff[i];
2882+ }
2883+ buff = mybuf;
2884+ }
2885+ /* call SetCurrentPoint */
2886+ OPVP_I2FIX(x, point.x);
2887+ OPVP_I2FIX(y, point.y);
2888+ if (apiEntry->opvpSetCurrentPoint) {
2889+ apiEntry->opvpSetCurrentPoint(printerContext,point.x, point.y);
2890+ }
2891+
2892+ /* draw image */
2893+ code = opvp_draw_image(pdev,
2894+ 1,
2895+ w, h,
2896+ w, h,
2897+ adj_raster,
2898+ 1,
2899+ &(buff[byte_offset]));
2900+ if (code) {
2901+ ecode = code;
2902+ }
2903+
2904+ if (zero != gx_no_color_index) {
2905+ /* restore PaintMode */
2906+ if (apiEntry->opvpSetPaintMode) {
2907+ apiEntry->opvpSetPaintMode(printerContext,
2908+ OPVP_PAINTMODE_TRANSPARENT);
2909+ }
2910+ }
2911+ /* restore fill color */
2912+ if (vectorFillColor) {
2913+ /* call SetFillColor */
2914+ if (apiEntry->opvpSetFillColor) {
2915+ apiEntry->opvpSetFillColor(printerContext,vectorFillColor);
2916+ }
2917+ }
2918+
2919+#if !(ENABLE_SIMPLE_MODE)
2920+ /* call RestoreGS */
2921+ if (apiEntry->opvpRestoreGS) {
2922+ apiEntry->opvpRestoreGS(printerContext);
2923+ }
2924+#endif
2925+
2926+ if (buff != data) {
2927+ /* buff was allocated from this function */
2928+ if (mybuf) free(mybuf);
2929+ }
2930+
2931+ return ecode;
2932+}
2933+
2934+/*
2935+ * copy color
2936+ */
2937+static int
2938+opvp_copy_color(
2939+ gx_device *dev,
2940+ const byte *data,
2941+ int data_x,
2942+ int raster,
2943+ gx_bitmap_id id,
2944+ int x,
2945+ int y,
2946+ int w,
2947+ int h)
2948+{
2949+ gx_device_opvp *pdev = (gx_device_opvp *)dev;
2950+ int code = -1;
2951+ int ecode = 0;
2952+ opvp_point_t point;
2953+ const byte *buff = data;
2954+ byte *mybuf = NULL;
2955+ int i;
2956+ byte *d;
2957+ const byte *s;
2958+ int byte_length = raster;
2959+ int depth;
2960+ int pixel;
2961+ int adj_raster = raster;
2962+
2963+ /* check page-in */
2964+ if (opvp_check_in_page(pdev)) return -1;
2965+
2966+ /* data offset */
2967+ if (data_x) {
2968+ depth = pdev->color_info.depth;
2969+ pixel = (depth + 7) >> 3;
2970+ byte_length = pixel * w;
2971+ adj_raster = ((byte_length + 3) >> 2) << 2;
2972+
2973+ buff = mybuf = malloc(adj_raster * h);
2974+ if (!mybuf) {
2975+ /* memory error */
2976+ return -1;
2977+ }
2978+ s = &(data[data_x*pixel]);
2979+ d = mybuf;
2980+ for (i = 0;i < h; i++, d += adj_raster, s += raster) {
2981+ memcpy(d, s, byte_length);
2982+ }
2983+ data_x = 0;
2984+ }
2985+
2986+#if !(ENABLE_SIMPLE_MODE)
2987+ /* call SaveGS */
2988+ if (apiEntry->opvpSaveGS) {
2989+ apiEntry->opvpSaveGS(printerContext);
2990+ }
2991+#endif
2992+
2993+ /* call SetCurrentPoint */
2994+ OPVP_I2FIX(x, point.x);
2995+ OPVP_I2FIX(y, point.y);
2996+ if (apiEntry->opvpSetCurrentPoint) {
2997+ apiEntry->opvpSetCurrentPoint(printerContext, point.x, point.y);
2998+ }
2999+
3000+ /* draw image */
3001+ code = opvp_draw_image(pdev,
3002+ pdev->color_info.depth,
3003+ w, h,
3004+ w, h,
3005+ adj_raster,
3006+ 0,
3007+ &(buff[data_x]));
3008+ if (code) {
3009+ ecode = code;
3010+ }
3011+
3012+
3013+#if !(ENABLE_SIMPLE_MODE)
3014+ /* call RestoreGS */
3015+ if (apiEntry->opvpRestoreGS) {
3016+ apiEntry->opvpRestoreGS(printerContext);
3017+ }
3018+#endif
3019+
3020+ if (buff != data) {
3021+ /* buff was allocated from this function */
3022+ if (mybuf) free(mybuf);
3023+ }
3024+
3025+ return ecode;
3026+}
3027+
3028+/*
3029+ * get params
3030+ */
3031+static int
3032+_get_params(gs_param_list *plist)
3033+{
3034+ int code;
3035+ int ecode = 0;
3036+ gs_param_name pname;
3037+ gs_param_string vdps;
3038+ gs_param_string pmps;
3039+ gs_param_string jips;
3040+ gs_param_string dips;
3041+ gs_param_string fips;
3042+ gs_param_string mlps;
3043+ gs_param_string mtps;
3044+ gs_param_string mrps;
3045+ gs_param_string mbps;
3046+ gs_param_string zmps;
3047+ char buff[OPVP_BUFF_SIZE];
3048+
3049+ /* get params */
3050+
3051+ /* vector driver name */
3052+ pname = "Driver";
3053+ vdps.data = (byte *)vectorDriver;
3054+ vdps.size = (vectorDriver ? strlen(vectorDriver) + 1 : 0);
3055+ vdps.persistent = false;
3056+ code = param_write_string(plist, pname, &vdps);
3057+ if (code) ecode = code;
3058+
3059+ /* printer model name */
3060+ pname = "Model";
3061+ pmps.data = (byte *)printerModel;
3062+ pmps.size = (printerModel ? strlen(printerModel) + 1 : 0);
3063+ pmps.persistent = false;
3064+ code = param_write_string(plist, pname, &pmps);
3065+ if (code) ecode = code;
3066+
3067+ /* job info */
3068+ pname = "JobInfo";
3069+ jips.data = (byte *)jobInfo;
3070+ jips.size = (jobInfo ? strlen(jobInfo) + 1 : 0);
3071+ jips.persistent = false;
3072+ code = param_write_string(plist, pname, &jips);
3073+ if (code) ecode = code;
3074+
3075+ /* doc info */
3076+ pname = "DocInfo";
3077+ dips.data = (byte *)docInfo;
3078+ dips.size = (docInfo ? strlen(docInfo) + 1 : 0);
3079+ dips.persistent = false;
3080+ code = param_write_string(plist, pname, &dips);
3081+ if (code) ecode = code;
3082+
3083+ /* fast image support */
3084+ switch (FastImageMode) {
3085+ case FastImageNoCTM:
3086+ opvp_alloc_string(&fastImage, "NoCTM");
3087+ break;
3088+ case FastImageNoRotate:
3089+ opvp_alloc_string(&fastImage, "NoRotateCTM");
3090+ break;
3091+ case FastImageRightAngle:
3092+ opvp_alloc_string(&fastImage, "RightAngleCTM");
3093+ break;
3094+ case FastImageReverseAngle:
3095+ opvp_alloc_string(&fastImage, "ReverseAngleCTM");
3096+ break;
3097+ case FastImageAll:
3098+ opvp_alloc_string(&fastImage, "All");
3099+ break;
3100+ case FastImageDisable:
3101+ default:
3102+ opvp_alloc_string(&fastImage, NULL);
3103+ break;
3104+ }
3105+ pname = "FastImage";
3106+ fips.data = (byte *)fastImage;
3107+ fips.size = (fastImage ? strlen(fastImage) + 1 : 0);
3108+ fips.persistent = false;
3109+ code = param_write_string(plist, pname, &fips);
3110+ if (code) ecode = code;
3111+
3112+ /* margins */
3113+ memset((void*)buff, 0, OPVP_BUFF_SIZE);
3114+ pname = "MarginLeft";
3115+ snprintf(buff, OPVP_BUFF_SIZE - 1, "%f",margins[0]);
3116+ mlps.data = (byte *)buff;
3117+ mlps.size = strlen(buff) + 1;
3118+ mlps.persistent = false;
3119+ code = param_write_string(plist, pname, &mlps);
3120+ if (code) ecode = code;
3121+ pname = "MarginTop";
3122+ snprintf(buff, OPVP_BUFF_SIZE - 1, "%f",margins[3]);
3123+ mtps.data = (byte *)buff;
3124+ mtps.size = strlen(buff) + 1;
3125+ mtps.persistent = false;
3126+ code = param_write_string(plist, pname, &mtps);
3127+ if (code) ecode = code;
3128+ pname = "MarginRight";
3129+ snprintf(buff, OPVP_BUFF_SIZE - 1, "%f",margins[2]);
3130+ mrps.data = (byte *)buff;
3131+ mrps.size = strlen(buff) + 1;
3132+ mrps.persistent = false;
3133+ code = param_write_string(plist, pname, &mrps);
3134+ if (code) ecode = code;
3135+ pname = "MarginBottom";
3136+ snprintf(buff, OPVP_BUFF_SIZE - 1, "%f",margins[1]);
3137+ mbps.data = (byte *)buff;
3138+ mbps.size = strlen(buff) + 1;
3139+ mbps.persistent = false;
3140+ code = param_write_string(plist, pname, &mbps);
3141+ if (code) ecode = code;
3142+
3143+ /* zoom */
3144+ pname = "Zoom";
3145+ snprintf(buff, OPVP_BUFF_SIZE - 1, "%f",zoom[0]);
3146+ zmps.data = (byte *)buff;
3147+ zmps.size = strlen(buff) + 1;
3148+ zmps.persistent = false;
3149+ code = param_write_string(plist, pname, &zmps);
3150+ if (code) ecode = code;
3151+
3152+ return ecode;
3153+}
3154+
3155+/*
3156+ * get params for vector
3157+ */
3158+static int
3159+opvp_get_params(gx_device *dev, gs_param_list *plist)
3160+{
3161+ int code;
3162+
3163+ /* get default params */
3164+ code = gdev_vector_get_params(dev, plist);
3165+ if (code) return code;
3166+
3167+ /* get params */
3168+ return _get_params(plist);
3169+}
3170+
3171+/*
3172+ * get params for inkjet
3173+ */
3174+static int
3175+oprp_get_params(gx_device *dev, gs_param_list *plist)
3176+{
3177+ int code;
3178+
3179+ /* get default params */
3180+ code = gdev_prn_get_params(dev, plist);
3181+ if (code) return code;
3182+
3183+ /* get params */
3184+ return _get_params(plist);
3185+}
3186+
3187+/*
3188+ * put params
3189+ */
3190+static int
3191+_put_params(gs_param_list *plist)
3192+{
3193+ int code;
3194+ int ecode = 0;
3195+ gs_param_name pname;
3196+ char *buff = NULL;
3197+ gs_param_string vdps;
3198+ gs_param_string pmps;
3199+ gs_param_string jips;
3200+ gs_param_string dips;
3201+ gs_param_string fips;
3202+ gs_param_string mlps;
3203+ gs_param_string mtps;
3204+ gs_param_string mrps;
3205+ gs_param_string mbps;
3206+ gs_param_string zmps;
3207+
3208+ /* vector driver name */
3209+ pname = "Driver";
3210+ code = param_read_string(plist, pname, &vdps);
3211+ switch (code) {
3212+ case 0:
3213+ buff = realloc(buff, vdps.size + 1);
3214+ memcpy(buff, vdps.data, vdps.size);
3215+ buff[vdps.size] = 0;
3216+ opvp_alloc_string(&vectorDriver, buff);
3217+ break;
3218+ case 1:
3219+ /* opvp_alloc_string(&vectorDriver, NULL);*/
3220+ break;
3221+ default:
3222+ ecode = code;
3223+ param_signal_error(plist, pname, ecode);
3224+ }
3225+
3226+ /* printer model name */
3227+ pname = "Model";
3228+ code = param_read_string(plist, pname, &pmps);
3229+ switch (code) {
3230+ case 0:
3231+ buff = realloc(buff, pmps.size + 1);
3232+ memcpy(buff, pmps.data, pmps.size);
3233+ buff[pmps.size] = 0;
3234+ opvp_alloc_string(&printerModel, buff);
3235+ break;
3236+ case 1:
3237+ /*opvp_alloc_string(&printerModel, NULL);*/
3238+ break;
3239+ default:
3240+ ecode = code;
3241+ param_signal_error(plist, pname, ecode);
3242+ }
3243+
3244+ /* job info */
3245+ pname = "JobInfo";
3246+ code = param_read_string(plist, pname, &jips);
3247+ switch (code) {
3248+ case 0:
3249+ buff = realloc(buff, jips.size + 1);
3250+ memcpy(buff, jips.data, jips.size);
3251+ buff[jips.size] = 0;
3252+ opvp_alloc_string(&jobInfo, buff);
3253+ break;
3254+ case 1:
3255+ /*opvp_alloc_string(&jobInfo, NULL);*/
3256+ break;
3257+ default:
3258+ ecode = code;
3259+ param_signal_error(plist, pname, ecode);
3260+ }
3261+
3262+ /* doc info */
3263+ pname = "DocInfo";
3264+ code = param_read_string(plist, pname, &dips);
3265+ switch (code) {
3266+ case 0:
3267+ buff = realloc(buff, dips.size + 1);
3268+ memcpy(buff, dips.data, dips.size);
3269+ buff[dips.size] = 0;
3270+ opvp_alloc_string(&docInfo, buff);
3271+ break;
3272+ case 1:
3273+ /*opvp_alloc_string(&docInfo, NULL);*/
3274+ break;
3275+ default:
3276+ ecode = code;
3277+ param_signal_error(plist, pname, ecode);
3278+ }
3279+
3280+ /* fast image support */
3281+ pname = "FastImage";
3282+ code = param_read_string(plist, pname, &fips);
3283+ switch (code) {
3284+ case 0:
3285+ buff = realloc(buff, fips.size + 1);
3286+ memcpy(buff, fips.data, fips.size);
3287+ buff[fips.size] = 0;
3288+ opvp_alloc_string(&fastImage, buff);
3289+ if (strcasecmp(fastImage,"NoCTM")==0) {
3290+ FastImageMode = FastImageNoCTM;
3291+ } else if (strncasecmp(fastImage,"NoRotate",8)==0) {
3292+ FastImageMode = FastImageNoRotate;
3293+ } else if (strncasecmp(fastImage,"Right",5)==0) {
3294+ FastImageMode = FastImageRightAngle;
3295+ } else if (strncasecmp(fastImage,"Reverse",7)==0) {
3296+ FastImageMode = FastImageReverseAngle;
3297+ } else if (strncasecmp(fastImage,"All",3)==0) {
3298+ FastImageMode = FastImageAll;
3299+ } else {
3300+ FastImageMode = FastImageDisable;
3301+ }
3302+ break;
3303+ case 1:
3304+ /*opvp_alloc_string(&fastImage, NULL);*/
3305+ break;
3306+ default:
3307+ ecode = code;
3308+ param_signal_error(plist, pname, ecode);
3309+ }
3310+
3311+ /* margins */
3312+ pname = "MarginLeft";
3313+ code = param_read_string(plist, pname, &mlps);
3314+ switch (code) {
3315+ case 0:
3316+ buff = realloc(buff, mlps.size + 1);
3317+ memcpy(buff, mlps.data, mlps.size);
3318+ buff[mlps.size] = 0;
3319+ margins[0] = atof(buff);
3320+ break;
3321+ case 1:
3322+ break;
3323+ default:
3324+ ecode = code;
3325+ param_signal_error(plist, pname, ecode);
3326+ }
3327+ pname = "MarginTop";
3328+ code = param_read_string(plist, pname, &mtps);
3329+ switch (code) {
3330+ case 0:
3331+ buff = realloc(buff, mtps.size + 1);
3332+ memcpy(buff, mtps.data, mtps.size);
3333+ buff[mtps.size] = 0;
3334+ margins[3] = atof(buff);
3335+ break;
3336+ case 1:
3337+ break;
3338+ default:
3339+ ecode = code;
3340+ param_signal_error(plist, pname, ecode);
3341+ }
3342+ pname = "MarginRight";
3343+ code = param_read_string(plist, pname, &mrps);
3344+ switch (code) {
3345+ case 0:
3346+ buff = realloc(buff, mrps.size + 1);
3347+ memcpy(buff, mrps.data, mrps.size);
3348+ buff[mrps.size] = 0;
3349+ margins[2] = atof(buff);
3350+ break;
3351+ case 1:
3352+ break;
3353+ default:
3354+ ecode = code;
3355+ param_signal_error(plist, pname, ecode);
3356+ }
3357+ pname = "MarginBottom";
3358+ code = param_read_string(plist, pname, &mbps);
3359+ switch (code) {
3360+ case 0:
3361+ buff = realloc(buff, mbps.size + 1);
3362+ memcpy(buff, mbps.data, mbps.size);
3363+ buff[mbps.size] = 0;
3364+ margins[1] = atof(buff);
3365+ break;
3366+ case 1:
3367+ break;
3368+ default:
3369+ ecode = code;
3370+ param_signal_error(plist, pname, ecode);
3371+ }
3372+
3373+ /* zoom */
3374+ pname = "Zoom";
3375+ code = param_read_string(plist, pname, &zmps);
3376+ switch (code) {
3377+ case 0:
3378+ buff = realloc(buff, zmps.size + 1);
3379+ memcpy(buff, zmps.data, zmps.size);
3380+ buff[zmps.size] = 0;
3381+ if (strncasecmp(buff, "Auto", 4)) {
3382+ zoom[0] = atof(buff);
3383+ if (zoom[0] > 0) {
3384+ zoom[1] = zoom[0];
3385+ } else {
3386+ zoom[0] = zoom[1] = 1;
3387+ }
3388+ } else {
3389+ zoom[0] = zoom[1] = 1;
3390+ zoomAuto = true;
3391+ }
3392+ break;
3393+ case 1:
3394+ break;
3395+ default:
3396+ ecode = code;
3397+ param_signal_error(plist, pname, ecode);
3398+ }
3399+
3400+ if (buff) free(buff);
3401+
3402+ return ecode;
3403+}
3404+
3405+/*
3406+ * put params for vector
3407+ */
3408+static int
3409+opvp_put_params(gx_device *dev, gs_param_list *plist)
3410+{
3411+ int code;
3412+
3413+ /* put params */
3414+ code = _put_params(plist);
3415+ if (code) return code;
3416+
3417+ /* put default params */
3418+ return gdev_vector_put_params(dev, plist);
3419+}
3420+
3421+/*
3422+ * put params for inkjet
3423+ */
3424+static int
3425+oprp_put_params(gx_device *dev, gs_param_list *plist)
3426+{
3427+ int code;
3428+
3429+ /* put params */
3430+ code = _put_params(plist);
3431+ if (code) return code;
3432+
3433+ /* put default params */
3434+ return gdev_prn_put_params(dev, plist);
3435+}
3436+
3437+static int checkPath(const gx_path *ppath)
3438+{
3439+ unsigned int npoints = 0;
3440+ fixed vs[6];
3441+ int op;
3442+ gs_path_enum path;
3443+
3444+ gx_path_enum_init(&path, ppath);
3445+
3446+ while ((op = gx_path_enum_next(&path, (gs_fixed_point *)vs)) != 0) {
3447+ switch (op) {
3448+ case gs_pe_lineto:
3449+ case gs_pe_moveto:
3450+ npoints += 1;
3451+ break;
3452+ case gs_pe_curveto:
3453+ npoints += 3;
3454+ break;
3455+ case gs_pe_closepath:
3456+ break;
3457+ default:
3458+ break;
3459+ }
3460+ if (npoints > MAX_PATH_POINTS) {
3461+ return 0;
3462+ }
3463+
3464+ }
3465+ return 1;
3466+}
3467+
3468+static int checkCPath(const gx_clip_path *pcpath)
3469+{
3470+ const gx_clip_list *list;
3471+ const gx_clip_rect *prect;
3472+ int npoints;
3473+
3474+ if (pcpath == 0) return 1;
3475+ if (pcpath->path_valid) {
3476+ return checkPath(&pcpath->path);
3477+ }
3478+ list = gx_cpath_list(pcpath);
3479+ prect = list->head;
3480+ if (prect == 0) {
3481+ prect = &list->single;
3482+ }
3483+ npoints = 0;
3484+ for (;prect != 0;prect = prect->next) {
3485+ npoints += 4;
3486+ if (npoints > MAX_PATH_POINTS) {
3487+ return 0;
3488+ }
3489+ }
3490+ return 1;
3491+}
3492+
3493+/*
3494+ * fill path
3495+ */
3496+static int
3497+opvp_fill_path(
3498+ gx_device *dev,
3499+ const gs_imager_state *pis,
3500+ gx_path *ppath,
3501+ const gx_fill_params *params,
3502+ const gx_device_color *pdevc,
3503+ const gx_clip_path *pxpath)
3504+{
3505+ bool draw_image = false;
3506+ gs_fixed_rect inner, outer;
3507+
3508+ /* check if paths are too complex */
3509+ if (!checkPath(ppath) || !checkCPath(pxpath)) {
3510+ return gx_default_fill_path(dev, pis, ppath, params, pdevc, pxpath);
3511+ }
3512+ /* check clippath support */
3513+ if (!(apiEntry->opvpSetClipPath)) {
3514+ /* get clipping box area */
3515+ gx_cpath_inner_box(pxpath,&inner);
3516+ gx_cpath_outer_box(pxpath,&outer);
3517+ /* check difference between inner-box and outer-box */
3518+ if ((inner.p.x != outer.p.x) || (inner.p.y != outer.p.y) ||
3519+ (inner.q.x != outer.q.x) || (inner.q.y != outer.q.y)) {
3520+ /* set draw by image */
3521+ draw_image = true;
3522+ }
3523+ }
3524+
3525+ if (!vector || draw_image) {
3526+ return gx_default_fill_path(dev, pis, ppath, params, pdevc, pxpath);
3527+ }
3528+
3529+ return gdev_vector_fill_path(dev, pis, ppath, params, pdevc, pxpath);
3530+}
3531+
3532+/*
3533+ * stroke path
3534+ */
3535+static int
3536+opvp_stroke_path(
3537+ gx_device *dev,
3538+ const gs_imager_state *pis,
3539+ gx_path *ppath,
3540+ const gx_stroke_params *params,
3541+ const gx_drawing_color *pdcolor,
3542+ const gx_clip_path *pxpath)
3543+{
3544+ bool draw_image = false;
3545+ gs_fixed_rect inner, outer;
3546+
3547+ /* check if paths are too complex */
3548+ if (!checkPath(ppath) || !checkCPath(pxpath)) {
3549+ return gx_default_stroke_path(dev, pis, ppath,
3550+ params, pdcolor, pxpath);
3551+ }
3552+ /* check clippath support */
3553+ if (!(apiEntry->opvpSetClipPath)) {
3554+ /* get clipping box area */
3555+ gx_cpath_inner_box(pxpath,&inner);
3556+ gx_cpath_outer_box(pxpath,&outer);
3557+ /* check difference between inner-box and outer-box */
3558+ if ((inner.p.x != outer.p.x) || (inner.p.y != outer.p.y) ||
3559+ (inner.q.x != outer.q.x) || (inner.q.y != outer.q.y)) {
3560+ /* set draw by image */
3561+ draw_image = true;
3562+ }
3563+ }
3564+
3565+ if (!vector || draw_image) {
3566+ return gx_default_stroke_path(dev, pis, ppath,
3567+ params, pdcolor, pxpath);
3568+ }
3569+
3570+ return gdev_vector_stroke_path(dev, pis, ppath,
3571+ params, pdcolor, pxpath);
3572+}
3573+
3574+/*
3575+ * fill mask
3576+ */
3577+static int
3578+opvp_fill_mask(
3579+ gx_device *dev,
3580+ const byte *data,
3581+ int data_x,
3582+ int raster,
3583+ gx_bitmap_id id,
3584+ int x,
3585+ int y,
3586+ int w,
3587+ int h,
3588+ const gx_drawing_color *pdcolor,
3589+ int depth,
3590+ gs_logical_operation_t lop,
3591+ const gx_clip_path *pcpath)
3592+{
3593+ if (vector) {
3594+#if GS_VERSION_MAJOR >= 8 /* for gs 8.15 */
3595+ gdev_vector_update_fill_color((gx_device_vector *)dev, NULL, pdcolor);
3596+#else
3597+ gdev_vector_update_fill_color((gx_device_vector *)dev, pdcolor);
3598+#endif
3599+ gdev_vector_update_clip_path((gx_device_vector *)dev, pcpath);
3600+ gdev_vector_update_log_op((gx_device_vector *)dev, lop);
3601+ }
3602+
3603+ return gx_default_fill_mask(dev, data, data_x, raster, id,
3604+ x, y, w, h, pdcolor, depth, lop, pcpath);
3605+}
3606+
3607+/*
3608+ * begin image
3609+ */
3610+static int
3611+opvp_begin_image(
3612+ gx_device *dev,
3613+ const gs_imager_state *pis,
3614+ const gs_image_t *pim,
3615+ gs_image_format_t format,
3616+ const gs_int_rect *prect,
3617+ const gx_drawing_color *pdcolor,
3618+ const gx_clip_path *pcpath,
3619+ gs_memory_t *mem,
3620+ gx_image_enum_common_t **pinfo)
3621+{
3622+ gx_device_vector *vdev =(gx_device_vector *)dev;
3623+ gdev_vector_image_enum_t *vinfo;
3624+ gs_matrix mtx;
3625+ opvp_ctm_t ctm;
3626+ bool draw_image = false;
3627+ bool supported_angle = false;
3628+ int code = -1;
3629+ opvp_result_t r = -1;
3630+ int ecode = 0;
3631+ int bits_per_pixel = 24;
3632+ bool can_reverse = false;
3633+ int p;
3634+ float mag[2] = {1, 1};
3635+ const gs_color_space *pcs = pim->ColorSpace;
3636+
3637+ /* check if paths are too complex */
3638+ if (!checkCPath(pcpath)) {
3639+ return gx_default_begin_image(
3640+ dev, pis, pim, format,
3641+ prect, pdcolor, pcpath,
3642+ mem, pinfo);
3643+ }
3644+
3645+ color_index = 0;
3646+
3647+ vinfo = gs_alloc_struct(mem, gdev_vector_image_enum_t,
3648+ &st_vector_image_enum,
3649+ "opvp_begin_image");
3650+
3651+ if (vinfo) {
3652+ memcpy(imageDecode,pim->Decode,sizeof(pim->Decode));
3653+ vinfo->memory =mem;
3654+ code = gdev_vector_begin_image(vdev, pis, pim, format, prect,
3655+ pdcolor, pcpath, mem,
3656+ &opvp_image_enum_procs,
3657+ vinfo);
3658+ if (code) ecode = code;
3659+
3660+ if (!ecode) {
3661+ /* bits per pixel */
3662+ for (bits_per_pixel=0, p=0; p < vinfo->num_planes; p++) {
3663+ bits_per_pixel += vinfo->plane_depths[p];
3664+ }
3665+
3666+ /* for indexed color */
3667+ if (!(pim->ImageMask)) {
3668+ color_index = gs_color_space_get_index(pcs);
3669+ if (color_index == gs_color_space_index_Indexed) {
3670+ base_color_index
3671+ = gs_color_space_indexed_base_space(pcs)->type->index;
3672+ if (((pcs->params.indexed.hival + 1) > 256)
3673+ || (bits_per_pixel != 8 && bits_per_pixel != 1)) {
3674+ return gx_default_begin_image(
3675+ dev, pis, pim, format,
3676+ prect, pdcolor, pcpath,
3677+ mem, pinfo);
3678+ } else if (base_color_index
3679+ == gs_color_space_index_DeviceCMYK) {
3680+ /* for CMYK indexed color */
3681+ int count;
3682+ const unsigned char *p
3683+ = pcs->params.indexed.lookup.table.data;
3684+ frac rgb[3];
3685+
3686+ for(count = 0;count <
3687+ (pcs->params.indexed.hival + 1); count++) {
3688+ memset(rgb, 0, sizeof(rgb));
3689+ color_cmyk_to_rgb(
3690+ byte2frac((*(p + 0 + (count * 4)))),
3691+ byte2frac((*(p + 1 + (count * 4)))),
3692+ byte2frac((*(p + 2 + (count * 4)))),
3693+ byte2frac((*(p + 3 + (count * 4)))),
3694+#if GS_VERSION_MAJOR >= 9
3695+ pis, rgb, mem);
3696+#else
3697+ pis, rgb);
3698+#endif
3699+ *(palette + 0 + (count * 3)) = frac2byte(rgb[0]);
3700+ *(palette + 1 + (count * 3)) = frac2byte(rgb[1]);
3701+ *(palette + 2 + (count * 3)) = frac2byte(rgb[2]);
3702+ }
3703+
3704+ bits_per_pixel = 24;
3705+ } else if (base_color_index
3706+ == gs_color_space_index_DeviceRGB ||
3707+ base_color_index == gs_color_space_index_CIEABC) {
3708+ /* for RGB or CalRGB indexed color */
3709+ memcpy(palette, pcs->params.indexed.lookup.table.data,\
3710+ pcs->params.indexed.lookup.table.size);
3711+ bits_per_pixel = 24;
3712+ } else if (base_color_index
3713+ == gs_color_space_index_DeviceGray ||
3714+ base_color_index == gs_color_space_index_CIEA) {
3715+ /* for Gray or CalGray indexed color */
3716+ memcpy(palette, pcs->params.indexed.lookup.table.data,\
3717+ pcs->params.indexed.lookup.table.size);
3718+ bits_per_pixel = 8;
3719+ } else {
3720+ /* except CMYK and RGB */
3721+ return gx_default_begin_image(
3722+ dev, pis, pim, format,
3723+ prect, pdcolor, pcpath,
3724+ mem, pinfo);
3725+ }
3726+ }
3727+ }
3728+
3729+#if ENABLE_AUTO_REVERSE
3730+ if (bits_per_pixel % 8 == 0) {
3731+ can_reverse = true;
3732+ }
3733+#endif
3734+ /* adjust matrix */
3735+ reverse_image = false;
3736+ gs_matrix_invert(&pim->ImageMatrix, &mtx);
3737+ gs_matrix_multiply(&mtx, &ctm_only(pis), &mtx);
3738+ switch (FastImageMode) {
3739+ case FastImageNoCTM:
3740+ if ((mtx.xy==0)&&(mtx.yx==0)&& (mtx.yy>=0)) {
3741+ if (mtx.xx>=0) {
3742+ mag[0] = mtx.xx;
3743+ mag[1] = mtx.yy;
3744+ mtx.xx = 1;
3745+ mtx.yy = 1;
3746+ supported_angle = true;
3747+ } else if (can_reverse) {
3748+ mtx.xx *= -1;
3749+ mag[0] = mtx.xx;
3750+ mag[1] = mtx.yy;
3751+ mtx.xx = 1;
3752+ mtx.yy = 1;
3753+ mtx.tx -= vinfo->width
3754+ * mag[0];
3755+ supported_angle = true;
3756+ reverse_image = true;
3757+ }
3758+ }
3759+ break;
3760+ case FastImageNoRotate:
3761+ if ((mtx.xy==0)&&(mtx.yx==0)&& (mtx.yy>=0)) {
3762+ if (mtx.xx>=0) {
3763+ supported_angle = true;
3764+ } else if (can_reverse) {
3765+ mtx.xx *= -1;
3766+ mtx.tx -= vinfo->width
3767+ * mtx.xx;
3768+ supported_angle = true;
3769+ reverse_image = true;
3770+ }
3771+ }
3772+ break;
3773+ case FastImageRightAngle:
3774+ if ((mtx.xy==0)&&(mtx.yx==0)) {
3775+ if (((mtx.xx>=0)&&(mtx.yy>=0))||
3776+ ((mtx.xx<=0)&&(mtx.yy<=0))){
3777+ supported_angle = true;
3778+ } else if (can_reverse) {
3779+ mtx.xx *= -1;
3780+ mtx.tx -= vinfo->width
3781+ * mtx.xx;
3782+ supported_angle = true;
3783+ reverse_image = true;
3784+ }
3785+ } else if ((mtx.xx==0)&&(mtx.yy==0)) {
3786+ if (((mtx.xy>=0)&&(mtx.yx<=0))||
3787+ ((mtx.xy<=0)&&(mtx.yx>=0))){
3788+ supported_angle = true;
3789+ } else if (can_reverse) {
3790+ mtx.xy *= -1;
3791+ mtx.ty -= vinfo->height
3792+ * mtx.xy;
3793+ supported_angle = true;
3794+ reverse_image = true;
3795+ }
3796+ }
3797+ break;
3798+ case FastImageReverseAngle:
3799+ if (((mtx.xy==0)&&(mtx.yx==0))||
3800+ ((mtx.xx==0)&&(mtx.yy==0))) {
3801+ supported_angle = true;
3802+ }
3803+ break;
3804+ case FastImageAll:
3805+ supported_angle = true;
3806+ break;
3807+ case FastImageDisable:
3808+ default:
3809+ break;
3810+ }
3811+ }
3812+
3813+ if ((!ecode) && supported_angle) {
3814+ if ((!prect) &&
3815+ ((vinfo->num_planes == 1) ||
3816+ ((vinfo->num_planes == 3) &&
3817+ (vinfo->plane_depths[0] == 8) &&
3818+ (vinfo->plane_depths[1] == 8) &&
3819+ (vinfo->plane_depths[2] == 8))
3820+ )
3821+ ) {
3822+ /*
3823+ * avail only
3824+ * 1 plane image
3825+ * or
3826+ * 3 planes 24 bits color image
3827+ * (8 bits per plane)
3828+ */
3829+ if (apiEntry->opvpStartDrawImage) {
3830+ draw_image = true;
3831+ }
3832+ }
3833+ }
3834+ }
3835+
3836+ if (draw_image) {
3837+ *pinfo = (gx_image_enum_common_t *)vinfo;
3838+
3839+ if (!ecode) {
3840+ if (!pim->ImageMask) {
3841+ /* call SetPaintMode */
3842+ if (apiEntry->opvpSetPaintMode) {
3843+ apiEntry->opvpSetPaintMode(printerContext,
3844+ OPVP_PAINTMODE_OPAQUE);
3845+ change_paint_mode = true;
3846+ }
3847+ /* set color space */
3848+ if (apiEntry->opvpSetColorSpace != NULL) {
3849+ opvp_cspace_t ncspace;
3850+
3851+ savedColorSpace = colorSpace;
3852+ switch (bits_per_pixel) {
3853+ case 1:
3854+ ncspace = OPVP_CSPACE_DEVICEGRAY;
3855+ bits_per_pixel = 8;
3856+ if (!cspace_available[ncspace]) {
3857+ ncspace = OPVP_CSPACE_STANDARDRGB;
3858+ bits_per_pixel = 24;
3859+ }
3860+ break;
3861+ case 8:
3862+ ncspace = OPVP_CSPACE_DEVICEGRAY;
3863+ if (!cspace_available[ncspace]) {
3864+ ncspace = OPVP_CSPACE_STANDARDRGB;
3865+ bits_per_pixel = 24;
3866+ }
3867+ break;
3868+ case 24:
3869+ ncspace = OPVP_CSPACE_DEVICERGB;
3870+ if (!cspace_available[ncspace]) {
3871+ ncspace = OPVP_CSPACE_STANDARDRGB;
3872+ }
3873+ break;
3874+ default:
3875+ r = -1;
3876+ goto fallthrough;
3877+ break;
3878+ }
3879+ if (ncspace != colorSpace) {
3880+ if (apiEntry->opvpSetColorSpace(printerContext,ncspace)
3881+ != OPVP_OK) {
3882+ r = -1;
3883+ goto fallthrough;
3884+ }
3885+ colorSpace = ncspace;
3886+ change_cspace = true;
3887+ }
3888+ }
3889+ }
3890+ }
3891+ if (!ecode) {
3892+ if (supported_angle) {
3893+ /* moveto */
3894+ opvp_moveto(vdev, 0, 0, mtx.tx, mtx.ty, 0);
3895+ }
3896+ if ((supported_angle) && (FastImageMode != FastImageNoCTM)) {
3897+ /* call SetCTM */
3898+ ctm.a = mtx.xx;
3899+ ctm.b = mtx.xy;
3900+ ctm.c = mtx.yx;
3901+ ctm.d = mtx.yy;
3902+ ctm.e = mtx.tx;
3903+ ctm.f = mtx.ty;
3904+ if (apiEntry->opvpSetCTM) {
3905+ r = apiEntry->opvpSetCTM(printerContext, &ctm);
3906+ }
3907+ else r = -1;
3908+ if (r != OPVP_OK) ecode = r;
3909+ }
3910+ }
3911+ if (!ecode) {
3912+ int dw,dh;
3913+
3914+ /* image size */
3915+ if (mag[0] != 1) {
3916+ dw = floor(vinfo->width * mag[0]+0.5);
3917+ } else {
3918+ dw = vinfo->width;
3919+ }
3920+ if (mag[1] != 1) {
3921+ dh = floor(vinfo->height * mag[1]+0.5);
3922+ } else {
3923+ dh = vinfo->height;
3924+ }
3925+ /* call StartDrawImage */
3926+ if (apiEntry->opvpStartDrawImage) {
3927+ opvp_int_t adj_raster;
3928+
3929+ adj_raster = bits_per_pixel*vinfo->width;
3930+ adj_raster = ((adj_raster+31) >> 5) << 2;
3931+ r = apiEntry->opvpStartDrawImage(
3932+ printerContext,
3933+ vinfo->width,
3934+ vinfo->height,
3935+ adj_raster,
3936+ pim->ImageMask ?
3937+ OPVP_IFORMAT_MASK:
3938+ OPVP_IFORMAT_RAW,
3939+ dw,dh);
3940+ if(r != OPVP_OK) {
3941+ if (apiEntry->opvpEndDrawImage) {
3942+ apiEntry->opvpEndDrawImage(printerContext);
3943+ }
3944+ }
3945+ }
3946+
3947+ /* bugfix for 32bit CMYK image print error */
3948+fallthrough:
3949+ if(r != OPVP_OK) {
3950+ if (change_paint_mode) {
3951+ /* restore paint mode */
3952+ if (apiEntry->opvpSetPaintMode) {
3953+ apiEntry->opvpSetPaintMode(printerContext,
3954+ OPVP_PAINTMODE_TRANSPARENT);
3955+ }
3956+ change_paint_mode = false;
3957+ }
3958+ if (change_cspace) {
3959+ /* restore color space */
3960+ colorSpace = savedColorSpace;
3961+ if (apiEntry->opvpSetColorSpace) {
3962+ apiEntry->opvpSetColorSpace(printerContext,
3963+ colorSpace);
3964+ }
3965+ change_cspace = false;
3966+ }
3967+ if(apiEntry->opvpResetCTM) {
3968+ apiEntry->opvpResetCTM(printerContext); /* reset CTM */
3969+ }
3970+ return gx_default_begin_image(dev, pis, pim, format,
3971+ prect, pdcolor, pcpath, mem, pinfo);
3972+ }
3973+ }
3974+
3975+ if (!ecode) {
3976+ begin_image = true;
3977+ }
3978+
3979+ return ecode;
3980+ }
3981+
3982+ return gx_default_begin_image(dev, pis, pim, format, prect,
3983+ pdcolor, pcpath, mem, pinfo);
3984+}
3985+
3986+/*
3987+ * plane data
3988+ */
3989+static int
3990+opvp_image_plane_data(
3991+ gx_image_enum_common_t *info,
3992+ const gx_image_plane_t *planes,
3993+ int height,
3994+ int *rows_used)
3995+{
3996+ gdev_vector_image_enum_t *vinfo;
3997+ byte *tmp_buf = NULL;
3998+ byte *buf = NULL;
3999+ int bits_per_pixel;
4000+ int data_bytes, dst_bytes;
4001+ int raster_length, dst_length;
4002+ int p;
4003+ int x;
4004+ int d;
4005+ int h;
4006+ int ecode = 0;
4007+ int i, j;
4008+ byte *src_ptr, *dst_ptr, *ppalette;
4009+ byte *ptr;
4010+ bbox_image_enum *pbe;
4011+ gx_image_enum *tinfo;
4012+ const gs_imager_state *pis;
4013+
4014+ vinfo = (gdev_vector_image_enum_t *)info;
4015+
4016+ if (!begin_image) return 0;
4017+
4018+ for (bits_per_pixel=0, p=0; p < vinfo->num_planes; p++) {
4019+ bits_per_pixel += vinfo->plane_depths[p];
4020+ }
4021+
4022+ data_bytes = (bits_per_pixel * vinfo->width + 7) >> 3;
4023+ raster_length = ((data_bytes + 3) >> 2) << 2;
4024+ buf = calloc(raster_length, height);
4025+
4026+ if (vinfo->default_info) {
4027+ gx_image_plane_data(vinfo->default_info, planes, height);
4028+ }
4029+ if (vinfo->bbox_info) {
4030+ gx_image_plane_data(vinfo->bbox_info, planes, height);
4031+ }
4032+
4033+ if (buf) {
4034+ /* Adjust image data gamma */
4035+ pbe = (bbox_image_enum *)vinfo->bbox_info;
4036+ tinfo = (gx_image_enum *)pbe->target_info;
4037+ pis = tinfo->pis;
4038+
4039+ if (vinfo->num_planes == 1) {
4040+ for (h = 0; h < height; h++) {
4041+ d = raster_length * h;
4042+ if (reverse_image) {
4043+ int bytes_per_pixel = bits_per_pixel / 8;
4044+ for (x = data_bytes * (h + 1) - bytes_per_pixel;
4045+ x >= data_bytes * h;
4046+ x-=bytes_per_pixel,
4047+ d+=bytes_per_pixel) {
4048+ memcpy(buf+d, planes[0].data+x, bytes_per_pixel);
4049+ }
4050+ } else {
4051+ memcpy(buf + d,
4052+ planes[0].data
4053+ + (data_bytes * h),
4054+ data_bytes);
4055+ }
4056+ }
4057+ } else {
4058+ for (h = 0; h < height; h++) {
4059+ d = raster_length * h;
4060+ if (reverse_image) {
4061+ for (x = vinfo->width * (h + 1) - 1;
4062+ x >= vinfo->width * h;
4063+ x--) {
4064+ for (p = 0;
4065+ p < vinfo->num_planes;
4066+ p++, d++) {
4067+ buf[d] = (byte)(planes[p].data[x]);
4068+ }
4069+ }
4070+ } else {
4071+ for (x = vinfo->width * h;
4072+ x < vinfo->width * (h + 1);
4073+ x++) {
4074+ for (p = 0;
4075+ p < vinfo->num_planes;
4076+ p++, d++) {
4077+ buf[d] = (byte)
4078+ (planes[p].data[x]);
4079+ }
4080+ }
4081+ }
4082+ }
4083+ }
4084+
4085+ if (tinfo->masked) {
4086+ bool reverse = false;
4087+
4088+ /* image mask */
4089+ if (imageDecode[0] == 0) {
4090+ reverse = true;
4091+ }
4092+ if (reverse) {
4093+ for (i = 0; i < height; i++) {
4094+ src_ptr = buf + raster_length * i;
4095+ for (j = 0; j < data_bytes; j++) {
4096+ src_ptr[j] ^= 0xff;
4097+ }
4098+ }
4099+ }
4100+ } else {
4101+ if(color_index == gs_color_space_index_Indexed) {
4102+ if (base_color_index == gs_color_space_index_DeviceGray ||
4103+ base_color_index == gs_color_space_index_CIEA) {
4104+ if (colorSpace == OPVP_CSPACE_DEVICEGRAY) {
4105+ /* Convert indexed gray color -> Gray */
4106+ if (bits_per_pixel == 8) { /* 8bit image */
4107+ dst_bytes = data_bytes;
4108+ dst_length = ((dst_bytes + 3) >> 2) << 2;
4109+
4110+ tmp_buf = calloc(dst_length, height);
4111+ if (tmp_buf) {
4112+ for (i = 0; i < height; i++) {
4113+ src_ptr = buf + raster_length * i;
4114+ dst_ptr = tmp_buf + dst_length * i;
4115+ for (j = 0; j < data_bytes; j++) {
4116+ ppalette = palette + src_ptr[j] ;
4117+ dst_ptr[j] = ppalette[0];
4118+ }
4119+ }
4120+
4121+ free (buf);
4122+ buf = tmp_buf;
4123+ data_bytes = dst_bytes;
4124+ raster_length = dst_length;
4125+ vinfo->bits_per_pixel = 8;
4126+ }
4127+ } else { /* 1bit image */
4128+ dst_bytes = vinfo->width;
4129+ dst_length = ((dst_bytes + 3) >> 2) << 2;
4130+
4131+ tmp_buf = calloc(dst_length, height);
4132+ if (tmp_buf) {
4133+ for (i = 0; i < height; i++) {
4134+ src_ptr = buf + raster_length * i;
4135+ dst_ptr = tmp_buf + dst_length * i;
4136+ for (j = 0; j < vinfo->width; j++) {
4137+ int o = ((src_ptr[j/8] & (1 << (7 - (j & 7))))
4138+ != 0);
4139+ ppalette = palette + o;
4140+ dst_ptr[j] = ppalette[0];
4141+ }
4142+ }
4143+
4144+ free (buf);
4145+ buf = tmp_buf;
4146+ data_bytes = dst_bytes;
4147+ raster_length = dst_length;
4148+ vinfo->bits_per_pixel = 8;
4149+ }
4150+ }
4151+ } else {
4152+ /* Convert indexed Gray color -> RGB */
4153+ if (bits_per_pixel == 8) { /* 8bit image */
4154+ dst_bytes = data_bytes * 3;
4155+ dst_length = ((dst_bytes + 3) >> 2) << 2;
4156+
4157+ tmp_buf = calloc(dst_length, height);
4158+ if (tmp_buf) {
4159+ for (i = 0; i < height; i++) {
4160+ src_ptr = buf + raster_length * i;
4161+ dst_ptr = tmp_buf + dst_length * i;
4162+ for (j = 0; j < data_bytes; j++) {
4163+ ppalette = palette + src_ptr[j] * 3;
4164+ dst_ptr[j*3] = ppalette[0]; /* R */
4165+ dst_ptr[j*3 + 1] = ppalette[0]; /* G */
4166+ dst_ptr[j*3 + 2] = ppalette[0]; /* B */
4167+ }
4168+ }
4169+
4170+ free (buf);
4171+ buf = tmp_buf;
4172+ data_bytes = dst_bytes;
4173+ raster_length = dst_length;
4174+ vinfo->bits_per_pixel = 24;
4175+ }
4176+ } else { /* 1bit image */
4177+ dst_bytes = vinfo->width * 3;
4178+ dst_length = ((dst_bytes + 3) >> 2) << 2;
4179+
4180+ tmp_buf = calloc(dst_length, height);
4181+ if (tmp_buf) {
4182+ for (i = 0; i < height; i++) {
4183+ src_ptr = buf + raster_length * i;
4184+ dst_ptr = tmp_buf + dst_length * i;
4185+ for (j = 0; j < vinfo->width; j++) {
4186+ int o = ((src_ptr[j/8] & (1 << (7 - (j & 7))))
4187+ != 0);
4188+ ppalette = palette + o * 3;
4189+ dst_ptr[j*3] = ppalette[0]; /* R */
4190+ dst_ptr[j*3 + 1] = ppalette[0]; /* G */
4191+ dst_ptr[j*3 + 2] = ppalette[0]; /* B */
4192+ }
4193+ }
4194+
4195+ free (buf);
4196+ buf = tmp_buf;
4197+ data_bytes = dst_bytes;
4198+ raster_length = dst_length;
4199+ vinfo->bits_per_pixel = 24;
4200+ }
4201+ }
4202+ }
4203+ } else {
4204+ /* Convert indexed color -> RGB */
4205+ if (bits_per_pixel == 8) { /* 8bit image */
4206+ dst_bytes = data_bytes * 3;
4207+ dst_length = ((dst_bytes + 3) >> 2) << 2;
4208+
4209+ tmp_buf = calloc(dst_length, height);
4210+ if (tmp_buf) {
4211+ for (i = 0; i < height; i++) {
4212+ src_ptr = buf + raster_length * i;
4213+ dst_ptr = tmp_buf + dst_length * i;
4214+ for (j = 0; j < data_bytes; j++) {
4215+ ppalette = palette + src_ptr[j] * 3;
4216+ dst_ptr[j*3] = ppalette[0]; /* R */
4217+ dst_ptr[j*3 + 1] = ppalette[1]; /* G */
4218+ dst_ptr[j*3 + 2] = ppalette[2]; /* B */
4219+ }
4220+ }
4221+
4222+ free (buf);
4223+ buf = tmp_buf;
4224+ data_bytes = dst_bytes;
4225+ raster_length = dst_length;
4226+ vinfo->bits_per_pixel = 24;
4227+ }
4228+ } else { /* 1bit image */
4229+ dst_bytes = vinfo->width * 3;
4230+ dst_length = ((dst_bytes + 3) >> 2) << 2;
4231+
4232+ tmp_buf = calloc(dst_length, height);
4233+ if (tmp_buf) {
4234+ for (i = 0; i < height; i++) {
4235+ src_ptr = buf + raster_length * i;
4236+ dst_ptr = tmp_buf + dst_length * i;
4237+ for (j = 0; j < vinfo->width; j++) {
4238+ int o = ((src_ptr[j/8] & (1 << (7 - (j & 7))))
4239+ != 0);
4240+ ppalette = palette + o * 3;
4241+ dst_ptr[j*3] = ppalette[0]; /* R */
4242+ dst_ptr[j*3 + 1] = ppalette[1]; /* G */
4243+ dst_ptr[j*3 + 2] = ppalette[2]; /* B */
4244+ }
4245+ }
4246+
4247+ free (buf);
4248+ buf = tmp_buf;
4249+ data_bytes = dst_bytes;
4250+ raster_length = dst_length;
4251+ vinfo->bits_per_pixel = 24;
4252+ }
4253+ }
4254+ }
4255+ }
4256+
4257+ /* Convert Gray */
4258+ if(color_index == gs_color_space_index_DeviceGray ||
4259+ color_index == gs_color_space_index_CIEA) {
4260+ if (colorSpace == OPVP_CSPACE_STANDARDRGB
4261+ || colorSpace == OPVP_CSPACE_DEVICERGB) {
4262+ /* convert to RGB */
4263+ if (bits_per_pixel == 8) { /* 8bit image */
4264+ dst_bytes = data_bytes * 3;
4265+ dst_length = ((dst_bytes + 3) >> 2) << 2;
4266+
4267+ tmp_buf = calloc(dst_length, height);
4268+ if (tmp_buf) {
4269+ for (i = 0; i < height; i++) {
4270+ src_ptr = buf + raster_length * i;
4271+ dst_ptr = tmp_buf + dst_length * i;
4272+ for (j = 0; j < data_bytes; j++) {
4273+ unsigned char d = floor(
4274+ imageDecode[0]*255 + src_ptr[j]*
4275+ (imageDecode[1]-imageDecode[0])+0.5);
4276+
4277+ dst_ptr[j*3] = d; /* R */
4278+ dst_ptr[j*3 + 1] = d; /* G */
4279+ dst_ptr[j*3 + 2] = d; /* B */
4280+ }
4281+ }
4282+
4283+ free (buf);
4284+ buf = tmp_buf;
4285+ data_bytes = dst_bytes;
4286+ raster_length = dst_length;
4287+ vinfo->bits_per_pixel = 24;
4288+ }
4289+ } else { /* 1bit image */
4290+ dst_bytes = vinfo->width * 3;
4291+ dst_length = ((dst_bytes + 3) >> 2) << 2;
4292+
4293+ tmp_buf = calloc(dst_length, height);
4294+ if (tmp_buf) {
4295+ for (i = 0; i < height; i++) {
4296+ src_ptr = buf + raster_length * i;
4297+ dst_ptr = tmp_buf + dst_length * i;
4298+ for (j = 0; j < vinfo->width; j++) {
4299+ int o = ((src_ptr[j/8] & (1 << (7 - (j & 7))))
4300+ != 0);
4301+ unsigned char d = floor(
4302+ imageDecode[0]*255 + o*
4303+ (imageDecode[1]-imageDecode[0])*255+0.5);
4304+ dst_ptr[j*3] = d; /* R */
4305+ dst_ptr[j*3 + 1] = d; /* G */
4306+ dst_ptr[j*3 + 2] =d; /* B */
4307+ }
4308+ }
4309+
4310+ free (buf);
4311+ buf = tmp_buf;
4312+ data_bytes = dst_bytes;
4313+ raster_length = dst_length;
4314+ vinfo->bits_per_pixel = 24;
4315+ }
4316+ }
4317+ } else if (colorSpace == OPVP_CSPACE_DEVICEGRAY) {
4318+ if (bits_per_pixel == 1) { /* 1bit image */
4319+ dst_bytes = vinfo->width;
4320+ dst_length = ((dst_bytes + 3) >> 2) << 2;
4321+
4322+ tmp_buf = calloc(dst_length, height);
4323+ if (tmp_buf) {
4324+ for (i = 0; i < height; i++) {
4325+ src_ptr = buf + raster_length * i;
4326+ dst_ptr = tmp_buf + dst_length * i;
4327+ for (j = 0; j < vinfo->width; j++) {
4328+ int o = ((src_ptr[j/8] & (1 << (7 - (j & 7))))
4329+ != 0);
4330+ unsigned char d = floor(
4331+ imageDecode[0]*255 + o*
4332+ (imageDecode[1]-imageDecode[0])*255+0.5);
4333+ dst_ptr[j] = d; /* R */
4334+ }
4335+ }
4336+
4337+ free (buf);
4338+ buf = tmp_buf;
4339+ data_bytes = dst_bytes;
4340+ raster_length = dst_length;
4341+ vinfo->bits_per_pixel = 8;
4342+ }
4343+ }
4344+ }
4345+ }
4346+ }
4347+#if GS_VERSION_MAJOR >= 8
4348+ if (vinfo->bits_per_pixel == 24) { /* 24bit RGB color */
4349+ for (i = 0; i < height; i++) {
4350+ ptr = buf + raster_length * i;
4351+ for (j = 0; j < vinfo->width; j++) {
4352+ ptr[j*3] = min(255, frac2cv(gx_map_color_frac(pis,
4353+ cv2frac(ptr[j*3]), effective_transfer[0])));
4354+ ptr[j*3+1] = min(255, frac2cv(gx_map_color_frac(pis,
4355+ cv2frac(ptr[j*3+1]), effective_transfer[1])));
4356+ ptr[j*3+2] = min(255, frac2cv(gx_map_color_frac(pis,
4357+ cv2frac(ptr[j*3+2]), effective_transfer[2])));
4358+ }
4359+ }
4360+ } else if (vinfo->bits_per_pixel == 8) { /* 8bit Gray image */
4361+ for (i = 0; i < height; i++) {
4362+ ptr = buf + raster_length * i;
4363+ for (j=0; j < vinfo->width; j++) {
4364+ ptr[j] = min(255, frac2cv(gx_map_color_frac(pis,
4365+ cv2frac(ptr[j]), effective_transfer[3])));
4366+ }
4367+ }
4368+ }
4369+#else
4370+ if (vinfo->bits_per_pixel == 24) { /* 24bit RGB color */
4371+ for (i = 0; i < height; i++) {
4372+ ptr = buf + raster_length * i;
4373+ for (j = 0; j < vinfo->width; j++) {
4374+ ptr[j*3] = min(255, frac2cv(gx_map_color_frac(pis,
4375+ cv2frac(ptr[j*3]), effective_transfer.colored.red)));
4376+ ptr[j*3+1] = min(255, frac2cv(gx_map_color_frac(pis,
4377+ cv2frac(ptr[j*3+1]), effective_transfer.colored.green)));
4378+ ptr[j*3+2] = min(255, frac2cv(gx_map_color_frac(pis,
4379+ cv2frac(ptr[j*3+2]), effective_transfer.colored.blue)));
4380+ }
4381+ }
4382+ } else if (vinfo->bits_per_pixel == 8) { /* 8bit Gray image */
4383+ for (i = 0; i < height; i++) {
4384+ ptr = buf + raster_length * i;
4385+ for (j = 0; j < vinfo->width; j++) {
4386+ ptr[j] = min(255, frac2cv(gx_map_color_frac(pis,
4387+ cv2frac(ptr[j]), effective_transfer.colored.gray)));
4388+ }
4389+ }
4390+ }
4391+#endif
4392+
4393+ /* call TansferDrawImage */
4394+ if (apiEntry->opvpTransferDrawImage) {
4395+ apiEntry->opvpTransferDrawImage(printerContext,
4396+ raster_length * height, (void *)buf);
4397+ }
4398+ if (buf) {
4399+ free(buf); /* free buffer */
4400+ }
4401+ }
4402+
4403+ vinfo->y += height;
4404+ ecode = (vinfo->y >= vinfo->height);
4405+
4406+ return ecode;
4407+}
4408+
4409+/*
4410+ * end image
4411+ */
4412+static int
4413+opvp_image_end_image(gx_image_enum_common_t *info, bool draw_last)
4414+{
4415+ gx_device *dev = info->dev;
4416+ gx_device_vector *vdev = (gx_device_vector *)dev;
4417+ gdev_vector_image_enum_t *vinfo;
4418+ opvp_ctm_t ctm;
4419+
4420+ vinfo = (gdev_vector_image_enum_t *)info;
4421+
4422+ if (begin_image) {
4423+ /* call EndDrawImage */
4424+ if (apiEntry->opvpEndDrawImage) {
4425+ apiEntry->opvpEndDrawImage(printerContext);
4426+ }
4427+
4428+ begin_image = false;
4429+
4430+ if (FastImageMode != FastImageNoCTM) {
4431+ /* call ResetCTM */
4432+ if (apiEntry->opvpResetCTM) {
4433+ apiEntry->opvpResetCTM(printerContext);
4434+ } else {
4435+ /* call SetCTM */
4436+ ctm.a = 1;
4437+ ctm.b = 0;
4438+ ctm.c = 0;
4439+ ctm.d = 1;
4440+ ctm.e = 0;
4441+ ctm.f = 0;
4442+ if (apiEntry->opvpSetCTM) {
4443+ apiEntry->opvpSetCTM(printerContext, &ctm);
4444+ }
4445+ }
4446+ }
4447+ if (change_paint_mode) {
4448+ /* restore paint mode */
4449+ if (apiEntry->opvpSetPaintMode) {
4450+ apiEntry->opvpSetPaintMode(printerContext,
4451+ OPVP_PAINTMODE_TRANSPARENT);
4452+ }
4453+ change_paint_mode = false;
4454+ }
4455+ if (change_cspace) {
4456+ /* restore color space */
4457+ colorSpace = savedColorSpace;
4458+ if (apiEntry->opvpSetColorSpace) {
4459+ apiEntry->opvpSetColorSpace(printerContext,
4460+ colorSpace);
4461+ }
4462+ change_cspace = false;
4463+ }
4464+ }
4465+
4466+ return gdev_vector_end_image(vdev, vinfo, draw_last, vdev->white);
4467+}
4468+
4469+/* ----- vector driver procs ----- */
4470+/*
4471+ * begin page
4472+ */
4473+static int
4474+opvp_beginpage(gx_device_vector *vdev)
4475+{
4476+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
4477+ int code = -1;
4478+ int ecode = 0;
4479+
4480+#ifdef OPVP_IGNORE_BLANK_PAGE
4481+ if (pdev->in_page) return 0;
4482+#endif
4483+ /* start page */
4484+ code = opvp_startpage((gx_device *)pdev);
4485+ if (code) {
4486+ ecode = code;
4487+ } else {
4488+ pdev->in_page = true; /* added '05.12.07 */
4489+ beginPage = true;
4490+ }
4491+
4492+ return ecode;
4493+}
4494+
4495+/*
4496+ * set line width
4497+ */
4498+static int
4499+opvp_setlinewidth(gx_device_vector *vdev, floatp width)
4500+{
4501+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
4502+ opvp_result_t r = -1;
4503+ int ecode = 0;
4504+ opvp_fix_t w;
4505+
4506+ /* check page-in */
4507+ if (opvp_check_in_page(pdev)) return -1;
4508+
4509+ /* call SetLineWidth */
4510+ OPVP_F2FIX(width, w);
4511+ if (apiEntry->opvpSetLineWidth) {
4512+ r = apiEntry->opvpSetLineWidth(printerContext, w);
4513+ }
4514+ if (r != OPVP_OK) {
4515+ ecode = -1;
4516+ }
4517+
4518+ return ecode;
4519+}
4520+
4521+/*
4522+ * set line cap
4523+ */
4524+static int
4525+opvp_setlinecap(gx_device_vector *vdev, gs_line_cap cap)
4526+{
4527+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
4528+ opvp_result_t r = -1;
4529+ int ecode = 0;
4530+ opvp_linecap_t linecap;
4531+
4532+ /* check page-in */
4533+ if (opvp_check_in_page(pdev)) return -1;
4534+
4535+ switch (cap) {
4536+ case gs_cap_butt:
4537+ linecap = OPVP_LINECAP_BUTT;
4538+ break;
4539+ case gs_cap_round:
4540+ linecap = OPVP_LINECAP_ROUND;
4541+ break;
4542+ case gs_cap_square:
4543+ linecap = OPVP_LINECAP_SQUARE;
4544+ break;
4545+ case gs_cap_triangle:
4546+ default:
4547+ linecap = OPVP_LINECAP_BUTT;
4548+ break;
4549+ }
4550+
4551+ /* call SetLineCap */
4552+ if (apiEntry->opvpSetLineCap) {
4553+ r = apiEntry->opvpSetLineCap(printerContext, linecap);
4554+ }
4555+ if (r != OPVP_OK) {
4556+ ecode = -1;
4557+ }
4558+
4559+ return ecode;
4560+}
4561+
4562+/*
4563+ * set line join
4564+ */
4565+static int
4566+opvp_setlinejoin(gx_device_vector *vdev, gs_line_join join)
4567+{
4568+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
4569+ opvp_result_t r = -1;
4570+ int ecode = 0;
4571+ opvp_linejoin_t linejoin;
4572+
4573+ /* check page-in */
4574+ if (opvp_check_in_page(pdev)) return -1;
4575+
4576+ switch (join) {
4577+ case gs_join_miter:
4578+ linejoin = OPVP_LINEJOIN_MITER;
4579+ break;
4580+ case gs_join_round:
4581+ linejoin = OPVP_LINEJOIN_ROUND;
4582+ break;
4583+ case gs_join_bevel:
4584+ linejoin = OPVP_LINEJOIN_BEVEL;
4585+ break;
4586+ case gs_join_none:
4587+ case gs_join_triangle:
4588+ default:
4589+ linejoin = OPVP_LINEJOIN_MITER;
4590+ break;
4591+ }
4592+
4593+ /* call SetLineJoin */
4594+ if (apiEntry->opvpSetLineJoin) {
4595+ r = apiEntry->opvpSetLineJoin(printerContext, linejoin);
4596+ }
4597+ if (r != OPVP_OK) {
4598+ ecode = -1;
4599+ }
4600+
4601+ return ecode;
4602+}
4603+
4604+/*
4605+ * set miter limit
4606+ */
4607+static int
4608+opvp_setmiterlimit(gx_device_vector *vdev, floatp limit)
4609+{
4610+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
4611+ opvp_result_t r = -1;
4612+ int ecode = 0;
4613+ opvp_fix_t l;
4614+
4615+ /* check page-in */
4616+ if (opvp_check_in_page(pdev)) return -1;
4617+
4618+ /* call SetMiterLimit */
4619+ OPVP_F2FIX(limit, l);
4620+ if (apiEntry->opvpSetMiterLimit) {
4621+ r = apiEntry->opvpSetMiterLimit(printerContext, l);
4622+ }
4623+ if (r != OPVP_OK) {
4624+ ecode = -1;
4625+ }
4626+
4627+ return ecode;
4628+}
4629+
4630+/*
4631+ * set dash
4632+ */
4633+static int
4634+opvp_setdash(
4635+ gx_device_vector *vdev,
4636+ const float *pattern,
4637+ uint count,
4638+ floatp offset)
4639+{
4640+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
4641+ opvp_result_t r = -1;
4642+ int ecode = 0;
4643+ opvp_fix_t *p = NULL;
4644+ opvp_fix_t o;
4645+ int i;
4646+
4647+ /* check page-in */
4648+ if (opvp_check_in_page(pdev)) return -1;
4649+
4650+ /* pattern */
4651+ if (count) {
4652+ p = calloc(sizeof(opvp_fix_t), count);
4653+ if (p) {
4654+ for (i = 0; i < count; i++) {
4655+ OPVP_F2FIX(pattern[i], p[i]);
4656+ }
4657+ } else {
4658+ ecode = -1;
4659+ }
4660+ }
4661+
4662+ /* call SetLineDash */
4663+ if (!ecode) {
4664+ if (apiEntry->opvpSetLineDash) {
4665+ r = apiEntry->opvpSetLineDash(printerContext, count,p);
4666+ }
4667+ if (r != OPVP_OK) {
4668+ ecode = -1;
4669+ }
4670+ }
4671+
4672+ /* call SetLineDashOffset */
4673+ if (!ecode) {
4674+ OPVP_F2FIX(offset, o);
4675+ if (apiEntry->opvpSetLineDashOffset) {
4676+ r = apiEntry->opvpSetLineDashOffset(printerContext, o);
4677+ }
4678+ if (r != OPVP_OK) {
4679+ ecode = -1;
4680+ }
4681+ }
4682+
4683+ /* call SetLineStyle */
4684+ if (!ecode) {
4685+ if (apiEntry->opvpSetLineStyle) {
4686+ r = apiEntry->opvpSetLineStyle(printerContext,
4687+ (count ?
4688+ OPVP_LINESTYLE_DASH :
4689+ OPVP_LINESTYLE_SOLID));
4690+ }
4691+ if (r != OPVP_OK) {
4692+ ecode = -1;
4693+ }
4694+ }
4695+
4696+ if (p) free(p);
4697+
4698+ return ecode;
4699+}
4700+
4701+/*
4702+ * set flat
4703+ */
4704+static int
4705+opvp_setflat(gx_device_vector *vdev, floatp flatness)
4706+{
4707+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
4708+ int ecode = 0;
4709+
4710+ /* check page-in */
4711+ if (opvp_check_in_page(pdev)) return -1;
4712+
4713+ /* what to do ? */
4714+
4715+ return ecode;
4716+}
4717+
4718+/*
4719+ * set logical operation
4720+ */
4721+static int
4722+opvp_setlogop(
4723+ gx_device_vector *vdev,
4724+ gs_logical_operation_t lop,
4725+ gs_logical_operation_t diff)
4726+{
4727+ /* nothing done */
4728+ return 0;
4729+}
4730+
4731+#if GS_VERSION_MAJOR >= 8
4732+/*--- added for Ghostscritp 8.15 ---*/
4733+static int
4734+opvp_can_handle_hl_color(gx_device_vector * vdev,
4735+ const gs_imager_state * pis1, const gx_drawing_color * pdc)
4736+{
4737+ return false; /* High level color is not implemented yet. */
4738+}
4739+#endif
4740+
4741+/*
4742+ * set fill color
4743+ */
4744+#if GS_VERSION_MAJOR >= 8
4745+static int
4746+opvp_setfillcolor(
4747+ gx_device_vector *vdev,
4748+ const gs_imager_state *pis, /* added for gs 8.15 */
4749+ const gx_drawing_color *pdc)
4750+#else
4751+static int
4752+opvp_setfillcolor(gx_device_vector *vdev, const gx_drawing_color *pdc)
4753+#endif
4754+{
4755+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
4756+ opvp_result_t r = -1;
4757+ int ecode = 0;
4758+ gx_color_index color;
4759+ static opvp_brush_t brush;
4760+
4761+ /* check page-in */
4762+ if (opvp_check_in_page(pdev)) return -1;
4763+
4764+ if (!gx_dc_is_pure(pdc)) return_error(gs_error_rangecheck);
4765+
4766+ /* color */
4767+ if (!vectorFillColor) vectorFillColor = &brush;
4768+ color = gx_dc_pure_color(pdc);
4769+ opvp_set_brush_color(pdev, color, vectorFillColor);
4770+
4771+ /* call SetFillColor */
4772+ if (apiEntry->opvpSetFillColor) {
4773+ r = apiEntry->opvpSetFillColor(printerContext, vectorFillColor);
4774+ }
4775+ if (r != OPVP_OK) {
4776+ ecode = -1;
4777+ }
4778+
4779+ return ecode;
4780+}
4781+
4782+/*
4783+ * set stroke color
4784+ */
4785+#if GS_VERSION_MAJOR >= 8
4786+static int
4787+opvp_setstrokecolor(
4788+ gx_device_vector *vdev,
4789+ const gs_imager_state *pis, /* added for gs 8.15 */
4790+ const gx_drawing_color *pdc)
4791+#else
4792+static int
4793+opvp_setstrokecolor(gx_device_vector *vdev, const gx_drawing_color *pdc)
4794+#endif
4795+{
4796+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
4797+ opvp_result_t r = -1;
4798+ int ecode = 0;
4799+ gx_color_index color;
4800+ opvp_brush_t brush;
4801+
4802+ /* check page-in */
4803+ if (opvp_check_in_page(pdev)) return -1;
4804+
4805+ if (!gx_dc_is_pure(pdc)) return_error(gs_error_rangecheck);
4806+
4807+ /* color */
4808+ color = gx_dc_pure_color(pdc);
4809+ opvp_set_brush_color(pdev, color, &brush);
4810+
4811+ /* call SetStrokeColor */
4812+ if (apiEntry->opvpSetStrokeColor) {
4813+ r = apiEntry->opvpSetStrokeColor(printerContext, &brush);
4814+ }
4815+ if (r != OPVP_OK) {
4816+ ecode = -1;
4817+ }
4818+
4819+ return ecode;
4820+}
4821+
4822+#define OPVP_OPT_MULTI_PATH
4823+
4824+/*
4825+ * vector do path
4826+ */
4827+static int
4828+opvp_vector_dopath(
4829+ gx_device_vector *vdev,
4830+ const gx_path *ppath,
4831+ gx_path_type_t type,
4832+ const gs_matrix *pmat)
4833+{
4834+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
4835+ opvp_result_t r = -1;
4836+ int code = -1;
4837+ int ecode = 0;
4838+ gs_fixed_rect rect;
4839+ gs_path_enum path;
4840+ gs_point scale;
4841+ int op;
4842+#ifdef OPVP_OPT_MULTI_PATH
4843+ int i;
4844+ int pop = 0;
4845+ int npoints = 0;
4846+ int *cp_num = NULL;
4847+ _fPoint *points = NULL;
4848+ opvp_point_t *opvp_p = NULL;
4849+ _fPoint current;
4850+ _fPoint check_p;
4851+#else
4852+ _fPoint points[4];
4853+#endif
4854+ _fPoint start;
4855+ fixed vs[6];
4856+ bool begin = true;
4857+
4858+ start.x = start.y = 0;
4859+#ifdef OPVP_OPT_MULTI_PATH
4860+ current.x = current.y = 0;
4861+#endif
4862+ /* check page-in */
4863+ if (opvp_check_in_page(pdev)) return -1;
4864+
4865+ if (gx_path_is_rectangle(ppath, &rect))
4866+ return (*vdev_proc(vdev, dorect))(vdev,
4867+ rect.p.x, rect.p.y,
4868+ rect.q.x, rect.q.y,
4869+ type);
4870+
4871+ /* begin path */
4872+ code = (*vdev_proc(vdev, beginpath))(vdev, type);
4873+ if (code) ecode = code;
4874+ scale = vdev->scale;
4875+ gx_path_enum_init(&path, ppath);
4876+
4877+ while (!ecode) {
4878+ op = gx_path_enum_next(&path, (gs_fixed_point *)vs);
4879+ if (begin) {
4880+ /* start point */
4881+ start.x = fixed2float(vs[0]) / scale.x;
4882+ start.y = fixed2float(vs[1]) / scale.y;
4883+ begin = false;
4884+
4885+#ifdef OPVP_OPT_MULTI_PATH
4886+ npoints = 1;
4887+ points = realloc(points, sizeof(_fPoint));
4888+ current = start;
4889+#endif
4890+
4891+ points[0] = start;
4892+
4893+#ifdef OPVP_OPT_MULTI_PATH
4894+ } else if (op != pop) {
4895+ /* convert float to Fix */
4896+ opvp_p = realloc(opvp_p, sizeof(opvp_point_t) * npoints);
4897+ for (i = 0; i < npoints; i++) {
4898+ OPVP_F2FIX(points[i].x, opvp_p[i].x);
4899+ OPVP_F2FIX(points[i].y, opvp_p[i].y);
4900+ }
4901+
4902+ switch (pop) {
4903+ case gs_pe_moveto:
4904+ /* call SetCurrentPoint */
4905+ if (apiEntry->opvpSetCurrentPoint) {
4906+ r = apiEntry->opvpSetCurrentPoint(
4907+ printerContext,
4908+ opvp_p[npoints-1].x,
4909+ opvp_p[npoints-1].y);
4910+ }
4911+ if (r != OPVP_OK) ecode = -1;
4912+ break;
4913+ case gs_pe_lineto:
4914+ /* call LinePath */
4915+ if (apiEntry->opvpLinePath) {
4916+ r = apiEntry->opvpLinePath(
4917+ printerContext,
4918+ OPVP_PATHOPEN,
4919+ npoints - 1,
4920+ &(opvp_p[1]));
4921+ }
4922+ if (r != OPVP_OK) ecode = -1;
4923+ break;
4924+ case gs_pe_curveto:
4925+ /* npoints */
4926+ if (!cp_num)
4927+ cp_num = calloc(sizeof(int), 2);
4928+ cp_num[0] = npoints;
4929+ cp_num[1] = 0;
4930+
4931+ /* call BezierPath */
4932+ if (apiEntry->opvpBezierPath) {
4933+ r = apiEntry->opvpBezierPath(
4934+ printerContext,
4935+ npoints - 1,
4936+ &(opvp_p[1])
4937+ );
4938+ }
4939+ if (r != OPVP_OK) ecode = -1;
4940+ break;
4941+ case gs_pe_closepath:
4942+ /* close path */
4943+ break;
4944+ default:
4945+ /* error */
4946+ return_error(gs_error_unknownerror);
4947+ break;
4948+ }
4949+
4950+ /* reset */
4951+ npoints = 1;
4952+ if (cp_num) free(cp_num), cp_num = NULL;
4953+ points = realloc(points, sizeof(_fPoint));
4954+ points[0] = current;
4955+#endif
4956+ }
4957+
4958+ if (!op) break; /* END */
4959+
4960+ switch (op) {
4961+ case gs_pe_moveto:
4962+#ifdef OPVP_OPT_MULTI_PATH
4963+ /* move to */
4964+ i = npoints;
4965+ npoints += 1;
4966+ points = realloc(points, sizeof(_fPoint) * npoints);
4967+ points[i].x = fixed2float(vs[0]) / scale.x;
4968+ points[i].y = fixed2float(vs[1]) / scale.y;
4969+ current = points[i];
4970+ start = current;
4971+
4972+#else
4973+
4974+ /* move to */
4975+ points[1].x = fixed2float(vs[0]) / scale.x;
4976+ points[1].y = fixed2float(vs[1]) / scale.y;
4977+ code = (*vdev_proc(vdev, moveto))(vdev,
4978+ points[0].x,
4979+ points[0].y,
4980+ points[1].x,
4981+ points[1].y,
4982+ type);
4983+ if (code) ecode = code;
4984+ points[0] = points[1];
4985+ start = points[0];
4986+#endif
4987+ break;
4988+ case gs_pe_lineto:
4989+#ifdef OPVP_OPT_MULTI_PATH
4990+ /* line to */
4991+ i = npoints;
4992+ npoints += 1;
4993+ points = realloc(points, sizeof(_fPoint) * npoints);
4994+ points[i].x = fixed2float(vs[0]) / scale.x;
4995+ points[i].y = fixed2float(vs[1]) / scale.y;
4996+ current = points[i];
4997+#else
4998+ /* line to */
4999+ points[1].x = fixed2float(vs[0]) / scale.x;
5000+ points[1].y = fixed2float(vs[1]) / scale.y;
5001+ code = (*vdev_proc(vdev, lineto))(vdev,
5002+ points[0].x,
5003+ points[0].y,
5004+ points[1].x,
5005+ points[1].y,
5006+ type);
5007+ if (code) ecode = code;
5008+ points[0] = points[1];
5009+#endif
5010+ break;
5011+ case gs_pe_curveto:
5012+#ifdef OPVP_OPT_MULTI_PATH
5013+ /* curve to */
5014+ check_p.x = fixed2float(vs[0]) / scale.x;
5015+ check_p.y = fixed2float(vs[1]) / scale.y;
5016+
5017+ i = npoints;
5018+ npoints += 3;
5019+ points = realloc(points, sizeof(_fPoint) * npoints);
5020+ points[i ].x = fixed2float(vs[0]) / scale.x;
5021+ points[i ].y = fixed2float(vs[1]) / scale.y;
5022+ points[i+1].x = fixed2float(vs[2]) / scale.x;
5023+ points[i+1].y = fixed2float(vs[3]) / scale.y;
5024+ points[i+2].x = fixed2float(vs[4]) / scale.x;
5025+ points[i+2].y = fixed2float(vs[5]) / scale.y;
5026+ current = points[i+2];
5027+#else
5028+ /* curve to */
5029+ points[1].x = fixed2float(vs[0]) / scale.x;
5030+ points[1].y = fixed2float(vs[1]) / scale.y;
5031+ points[2].x = fixed2float(vs[2]) / scale.x;
5032+ points[2].y = fixed2float(vs[3]) / scale.y;
5033+ points[3].x = fixed2float(vs[4]) / scale.x;
5034+ points[3].y = fixed2float(vs[5]) / scale.y;
5035+ code = (*vdev_proc(vdev, curveto))(vdev,
5036+ points[0].x,
5037+ points[0].y,
5038+ points[1].x,
5039+ points[1].y,
5040+ points[2].x,
5041+ points[2].y,
5042+ points[3].x,
5043+ points[3].y,
5044+ type);
5045+ if (code) ecode = code;
5046+ points[0] = points[3];
5047+#endif
5048+ break;
5049+ case gs_pe_closepath:
5050+ /* close path */
5051+ code = (*vdev_proc(vdev, closepath))(
5052+ vdev,
5053+ points[0].x,
5054+ points[0].y,
5055+ start.x,
5056+ start.y,
5057+ type);
5058+ if (code) ecode = code;
5059+ points[0] = start;
5060+#ifdef OPVP_OPT_MULTI_PATH
5061+ current = start;
5062+#endif
5063+ break;
5064+ default:
5065+ /* error */
5066+ return_error(gs_error_unknownerror);
5067+ break;
5068+ }
5069+
5070+#ifdef OPVP_OPT_MULTI_PATH
5071+ pop = op;
5072+#endif
5073+ }
5074+
5075+ /* end path */
5076+ code = (*vdev_proc(vdev, endpath))(vdev, type);
5077+ if (code) ecode = code;
5078+
5079+#ifdef OPVP_OPT_MULTI_PATH
5080+ if (points) free(points);
5081+ if (opvp_p) free(opvp_p);
5082+ if (cp_num) free(cp_num);
5083+#endif
5084+ return ecode;
5085+}
5086+
5087+/*
5088+ * vector do rect
5089+ */
5090+static int
5091+opvp_vector_dorect(
5092+ gx_device_vector *vdev,
5093+ fixed x0,
5094+ fixed y0,
5095+ fixed x1,
5096+ fixed y1,
5097+ gx_path_type_t type)
5098+{
5099+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
5100+ opvp_result_t r = -1;
5101+ int code = -1;
5102+ int ecode = 0;
5103+ gs_point scale;
5104+ opvp_rectangle_t rectangles[1];
5105+ _fPoint p;
5106+
5107+ /* check page-in */
5108+ if (opvp_check_in_page(pdev)) return -1;
5109+
5110+ /* begin path */
5111+ code = (*vdev_proc(vdev, beginpath))(vdev, type);
5112+ if (code) ecode = code;
5113+ scale = vdev->scale;
5114+
5115+ if (!ecode) {
5116+ /* rectangle */
5117+ p.x = fixed2float(x0) / scale.x;
5118+ p.y = fixed2float(y0) / scale.y;
5119+ OPVP_F2FIX(p.x, rectangles[0].p0.x);
5120+ OPVP_F2FIX(p.y, rectangles[0].p0.y);
5121+ p.x = fixed2float(x1) / scale.x;
5122+ p.y = fixed2float(y1) / scale.y;
5123+ OPVP_F2FIX(p.x, rectangles[0].p1.x);
5124+ OPVP_F2FIX(p.y, rectangles[0].p1.y);
5125+
5126+ /* call RectanglePath */
5127+ if (apiEntry->opvpRectanglePath) {
5128+ r = apiEntry->opvpRectanglePath(printerContext,
5129+ 1,
5130+ rectangles);
5131+ }
5132+ if (r != OPVP_OK) {
5133+ ecode = -1;
5134+ }
5135+ }
5136+
5137+ /* end path */
5138+ if (!ecode) {
5139+ code = (*vdev_proc(vdev, endpath))(vdev, type);
5140+ if (code) ecode = code;
5141+ }
5142+
5143+ /* fallback */
5144+ if (ecode) return gdev_vector_dorect(vdev,x0,y0,x1,y1,type);
5145+
5146+ return ecode;
5147+}
5148+
5149+/*
5150+ * begin path
5151+ */
5152+static int
5153+opvp_beginpath(gx_device_vector *vdev, gx_path_type_t type)
5154+{
5155+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
5156+ opvp_result_t r = -1;
5157+ int ecode = 0;
5158+
5159+ /* check page-in */
5160+ if (opvp_check_in_page(pdev)) return -1;
5161+
5162+ /* check clip-path */
5163+ if (type & gx_path_type_clip) {
5164+ if (apiEntry->opvpResetClipPath)
5165+ apiEntry->opvpResetClipPath(printerContext);
5166+ }
5167+
5168+ /* call NewPath */
5169+ if (apiEntry->opvpNewPath) {
5170+ r = apiEntry->opvpNewPath(printerContext);
5171+ }
5172+ if (r != OPVP_OK) {
5173+ ecode = -1;
5174+ }
5175+
5176+ return ecode;
5177+}
5178+
5179+/*
5180+ * move to
5181+ */
5182+static int
5183+opvp_moveto(
5184+ gx_device_vector *vdev,
5185+ floatp x0,
5186+ floatp y0,
5187+ floatp x1,
5188+ floatp y1,
5189+ gx_path_type_t type)
5190+{
5191+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
5192+ opvp_result_t r = -1;
5193+ int ecode = 0;
5194+ opvp_point_t p;
5195+
5196+ /* check page-in */
5197+ if (opvp_check_in_page(pdev)) return -1;
5198+
5199+ /* call SetCurrentPoint */
5200+ OPVP_F2FIX(x1, p.x);
5201+ OPVP_F2FIX(y1, p.y);
5202+ if (apiEntry->opvpSetCurrentPoint) {
5203+ r = apiEntry->opvpSetCurrentPoint(printerContext, p.x, p.y);
5204+ }
5205+ if (r != OPVP_OK) {
5206+ ecode = -1;
5207+ }
5208+
5209+ return ecode;
5210+}
5211+
5212+/*
5213+ * line to
5214+ */
5215+static int
5216+opvp_lineto(
5217+ gx_device_vector *vdev,
5218+ floatp x0,
5219+ floatp y0,
5220+ floatp x1,
5221+ floatp y1,
5222+ gx_path_type_t type)
5223+{
5224+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
5225+ opvp_result_t r = -1;
5226+ int ecode = 0;
5227+ opvp_point_t points[1];
5228+
5229+ /* check page-in */
5230+ if (opvp_check_in_page(pdev)) return -1;
5231+
5232+ /* point */
5233+ OPVP_F2FIX(x1, points[0].x);
5234+ OPVP_F2FIX(y1, points[0].y);
5235+
5236+ /* call LinePath */
5237+ if (apiEntry->opvpLinePath) {
5238+ r = apiEntry->opvpLinePath(printerContext, OPVP_PATHOPEN, 1, points);
5239+ }
5240+ if (r != OPVP_OK) {
5241+ ecode = -1;
5242+ }
5243+
5244+ return ecode;
5245+}
5246+
5247+/*
5248+ * curve to
5249+ */
5250+static int
5251+opvp_curveto(
5252+ gx_device_vector *vdev,
5253+ floatp x0,
5254+ floatp y0,
5255+ floatp x1,
5256+ floatp y1,
5257+ floatp x2,
5258+ floatp y2,
5259+ floatp x3,
5260+ floatp y3,
5261+ gx_path_type_t type)
5262+{
5263+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
5264+ opvp_result_t r = -1;
5265+ int ecode = 0;
5266+ int npoints[2];
5267+ opvp_point_t points[4];
5268+
5269+ /* check page-in */
5270+ if (opvp_check_in_page(pdev)) return -1;
5271+
5272+ /* points */
5273+ npoints[0] = 4;
5274+ npoints[1] = 0;
5275+ OPVP_F2FIX(x0, points[0].x);
5276+ OPVP_F2FIX(y0, points[0].y);
5277+ OPVP_F2FIX(x1, points[1].x);
5278+ OPVP_F2FIX(y1, points[1].y);
5279+ OPVP_F2FIX(x2, points[2].x);
5280+ OPVP_F2FIX(y2, points[2].y);
5281+ OPVP_F2FIX(x3, points[3].x);
5282+ OPVP_F2FIX(y3, points[3].y);
5283+
5284+ /* call BezierPath */
5285+ if (apiEntry->opvpBezierPath) {
5286+ r = apiEntry->opvpBezierPath(printerContext,
5287+ 3,
5288+ &(points[1])
5289+ );
5290+ }
5291+ if (r != OPVP_OK) {
5292+ ecode = -1;
5293+ }
5294+
5295+ return ecode;
5296+}
5297+
5298+/*
5299+ * close path
5300+ */
5301+static int
5302+opvp_closepath(
5303+ gx_device_vector *vdev,
5304+ floatp x,
5305+ floatp y,
5306+ floatp x_start,
5307+ floatp y_start,
5308+ gx_path_type_t type)
5309+{
5310+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
5311+ opvp_result_t r = -1;
5312+ int ecode = 0;
5313+ opvp_point_t points[1];
5314+
5315+ /* check page-in */
5316+ if (opvp_check_in_page(pdev)) return -1;
5317+
5318+ /* point */
5319+ OPVP_F2FIX(x_start, points[0].x);
5320+ OPVP_F2FIX(y_start, points[0].y);
5321+
5322+ /* call LinePath */
5323+ if (apiEntry->opvpLinePath) {
5324+ r = apiEntry->opvpLinePath(printerContext, OPVP_PATHCLOSE, 1, points);
5325+ }
5326+ if (r != OPVP_OK) {
5327+ ecode = -1;
5328+ }
5329+
5330+ return ecode;
5331+}
5332+
5333+/*
5334+ * end path
5335+ */
5336+static int
5337+opvp_endpath(gx_device_vector *vdev, gx_path_type_t type)
5338+{
5339+ gx_device_opvp *pdev = (gx_device_opvp *)vdev;
5340+ opvp_result_t r = -1;
5341+ int ecode = 0;
5342+
5343+ /* check page-in */
5344+ if (opvp_check_in_page(pdev)) return -1;
5345+
5346+ /* call EndPath */
5347+ if (apiEntry->opvpEndPath) {
5348+ r = apiEntry->opvpEndPath(printerContext);
5349+ }
5350+ if (r != OPVP_OK) {
5351+ ecode = -1;
5352+ }
5353+
5354+ if (type & gx_path_type_fill) {
5355+ /* fill mode */
5356+ if (type & gx_path_type_even_odd) {
5357+ /* call SetFillMode */
5358+ if (apiEntry->opvpSetFillMode) {
5359+ r = apiEntry->opvpSetFillMode(
5360+ printerContext,
5361+ OPVP_FILLMODE_EVENODD
5362+ );
5363+ }
5364+ if (r != OPVP_OK) {
5365+ ecode = -1;
5366+ }
5367+ } else {
5368+ /* call SetFillMode */
5369+ if (apiEntry->opvpSetFillMode) {
5370+ r = apiEntry->opvpSetFillMode(
5371+ printerContext,
5372+ OPVP_FILLMODE_WINDING
5373+ );
5374+ }
5375+ if (r != OPVP_OK) {
5376+ ecode = -1;
5377+ }
5378+ }
5379+
5380+ if (type & gx_path_type_stroke) {
5381+ /* call StrokeFillPath */
5382+ if (apiEntry->opvpStrokeFillPath) {
5383+ r = apiEntry->opvpStrokeFillPath(printerContext);
5384+ }
5385+ if (r != OPVP_OK) {
5386+ ecode = -1;
5387+ }
5388+ } else {
5389+ /* call FillPath */
5390+ if (apiEntry->opvpFillPath) {
5391+ r = apiEntry->opvpFillPath(printerContext);
5392+ }
5393+ if (r != OPVP_OK) {
5394+ ecode = -1;
5395+ }
5396+ }
5397+ } else if (type & gx_path_type_clip) {
5398+ /* call SetClipPath */
5399+ if (apiEntry->opvpSetClipPath) {
5400+ r = apiEntry->opvpSetClipPath(
5401+ printerContext,
5402+ (type & gx_path_type_even_odd
5403+ ? OPVP_CLIPRULE_EVENODD
5404+ : OPVP_CLIPRULE_WINDING));
5405+ }
5406+ if (r != OPVP_OK) {
5407+ ecode = -1;
5408+ }
5409+ } else if (type & gx_path_type_stroke) {
5410+ /* call StrokePath */
5411+ if (apiEntry->opvpStrokePath) {
5412+ r = apiEntry->opvpStrokePath(printerContext);
5413+ }
5414+ if (r != OPVP_OK) {
5415+ ecode = -1;
5416+ }
5417+ }
5418+
5419+ return ecode;
5420+}
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
--- gdevopvp/tags/RELEASE_1_0_7/src/opvp.h (nonexistent)
+++ gdevopvp/tags/RELEASE_1_0_7/src/opvp.h (revision 917)
@@ -0,0 +1,298 @@
1+/*
2+ * OpenPrinting Vector Printer Driver API Definitions [opvp.h]
3+ *
4+ * Copyright (c) 2006 Free Standards Group
5+ * Copyright (c) 2006 Fuji Xerox Printing Systems Co., Ltd.
6+ * Copyright (c) 2006 Canon Inc.
7+ * Copyright (c) 2003-2006 AXE Inc.
8+ *
9+ * All Rights Reserverd.
10+ *
11+ * Permission to use, copy, modify, distribute, and sell this software
12+ * and its documentation for any purpose is hereby granted without
13+ * fee, provided that the above copyright notice appear in all copies
14+ * and that both that copyright notice and this permission notice
15+ * appear in supporting documentation.
16+ *
17+ * The above copyright notice and this permission notice shall be
18+ * included in all copies or substantial portions of the Software.
19+ *
20+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23+ * NONINFRINGEMENT. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR
24+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27+ */
28+ /*
29+ 2007 Modified for OPVP 1.0 by BBR Inc.
30+ */
31+
32+#ifndef _OPVP_H_
33+#define _OPVP_H_
34+
35+/* Return Values and Error Codes */
36+#define OPVP_OK 0 /* -1 for errors */
37+#define OPVP_FATALERROR -1 /* error: cannot be recovered */
38+#define OPVP_BADREQUEST -2 /* error: called where it should
39+ not be called */
40+#define OPVP_BADCONTEXT -3 /* error: invalid printer context */
41+#define OPVP_NOTSUPPORTED -4 /* error: combination of
42+ parameters are set
43+ which cannot be handled
44+ by driver or printer */
45+#define OPVP_JOBCANCELED -5 /* error: job has been canceled
46+ by some cause */
47+#define OPVP_PARAMERROR -6 /* error: invalid parameter */
48+#define OPVP_VERSIONERROR -7 /* error: invalid API version */
49+
50+/* Basic Types */
51+typedef int opvp_dc_t; /* driver/device context */
52+typedef int opvp_result_t; /* return value */
53+typedef unsigned char opvp_byte_t; /* BYTE */
54+typedef unsigned char opvp_char_t; /* character (string) */
55+typedef int opvp_int_t; /* integer */
56+typedef int opvp_fix_t; /* fixed integer */
57+typedef float opvp_float_t; /* float */
58+typedef unsigned int opvp_flag_t; /* flags */
59+typedef unsigned int opvp_rop_t; /* raster operation */
60+
61+/* for opvp_fix_t */
62+#define OPVP_FIX_FRACT_WIDTH 8
63+#define OPVP_FIX_FRACT_DENOM (1<<OPVP_FIX_FRACT_WIDTH)
64+#define OPVP_FIX_FLOOR_WIDTH (sizeof(int)*8-OPVP_FIX_FRACT_WIDTH)
65+
66+/* convert macro */
67+#define OPVP_I2FIX(i,fix) (fix=i<<OPVP_FIX_FRACT_WIDTH)
68+#define OPVP_F2FIX(f,fix) (fix=((int)floor(f)<<OPVP_FIX_FRACT_WIDTH)\
69+ |((int)((f-floor(f))*OPVP_FIX_FRACT_DENOM)\
70+ &(OPVP_FIX_FRACT_DENOM-1)))
71+
72+/* graphic elements */
73+typedef struct _opvp_point {
74+ opvp_fix_t x, y;
75+} opvp_point_t;
76+
77+typedef struct _opvp_rectangle {
78+ opvp_point_t p0; /* start point */
79+ opvp_point_t p1; /* diagonal point */
80+} opvp_rectangle_t;
81+
82+typedef struct _opvp_roundrectangle {
83+ opvp_point_t p0; /* start point */
84+ opvp_point_t p1; /* diagonal point */
85+ opvp_fix_t xellipse, yellipse;
86+} opvp_roundrectangle_t;
87+
88+/* Image Formats */
89+typedef enum _opvp_imageformat {
90+ OPVP_IFORMAT_RAW = 0,
91+ OPVP_IFORMAT_MASK = 1,
92+ OPVP_IFORMAT_RLE = 2,
93+ OPVP_IFORMAT_JPEG = 3,
94+ OPVP_IFORMAT_PNG = 4
95+} opvp_imageformat_t;
96+
97+/* Color Presentation */
98+typedef enum _opvp_colormapping {
99+ OPVP_CMAP_DIRECT = 0,
100+ OPVP_CMAP_INDEXED = 1
101+} opvp_colormapping_t;
102+
103+typedef enum _opvp_cspace {
104+ OPVP_CSPACE_BW = 0,
105+ OPVP_CSPACE_DEVICEGRAY = 1,
106+ OPVP_CSPACE_DEVICECMY = 2,
107+ OPVP_CSPACE_DEVICECMYK = 3,
108+ OPVP_CSPACE_DEVICERGB = 4,
109+ OPVP_CSPACE_DEVICEKRGB = 5,
110+ OPVP_CSPACE_STANDARDRGB = 6,
111+ OPVP_CSPACE_STANDARDRGB64 = 7
112+} opvp_cspace_t;
113+
114+/* Fill, Paint, Clip */
115+typedef enum _opvp_fillmode {
116+ OPVP_FILLMODE_EVENODD = 0,
117+ OPVP_FILLMODE_WINDING = 1
118+} opvp_fillmode_t;
119+
120+typedef enum _opvp_paintmode {
121+ OPVP_PAINTMODE_OPAQUE = 0,
122+ OPVP_PAINTMODE_TRANSPARENT = 1
123+} opvp_paintmode_t;
124+
125+typedef enum _opvp_cliprule {
126+ OPVP_CLIPRULE_EVENODD = 0,
127+ OPVP_CLIPRULE_WINDING = 1
128+} opvp_cliprule_t;
129+
130+/* Line */
131+typedef enum _opvp_linestyle {
132+ OPVP_LINESTYLE_SOLID = 0,
133+ OPVP_LINESTYLE_DASH = 1
134+} opvp_linestyle_t;
135+
136+typedef enum _opvp_linecap {
137+ OPVP_LINECAP_BUTT = 0,
138+ OPVP_LINECAP_ROUND = 1,
139+ OPVP_LINECAP_SQUARE = 2
140+} opvp_linecap_t;
141+
142+typedef enum _opvp_linejoin {
143+ OPVP_LINEJOIN_MITER = 0,
144+ OPVP_LINEJOIN_ROUND = 1,
145+ OPVP_LINEJOIN_BEVEL = 2
146+} opvp_linejoin_t;
147+
148+/* Brush */
149+typedef enum _opvp_bdtype {
150+ OPVP_BDTYPE_NORMAL = 0
151+} opvp_bdtype_t;
152+
153+typedef struct _opvp_brushdata {
154+ opvp_bdtype_t type;
155+ opvp_int_t width, height, pitch;
156+#if defined(__GNUC__) && __GNUC__ <= 2
157+ opvp_byte_t data[1];
158+#elif defined(__SUNPRO_C)
159+ opvp_byte_t data[1];
160+#else
161+ opvp_byte_t data[];
162+#endif
163+
164+} opvp_brushdata_t;
165+
166+typedef struct _opvp_brush {
167+ opvp_cspace_t colorSpace;
168+ opvp_int_t color[4]; /* aRGB quadruplet */
169+ opvp_int_t xorg, yorg; /* brush origin */
170+ /* ignored for opvpSetBgColor */
171+ opvp_brushdata_t *pbrush; /* pointer to brush data */
172+ /* solid brush used, if NULL */
173+} opvp_brush_t;
174+
175+/* Misc. Flags */
176+typedef enum _opvp_arcmode {
177+ OPVP_ARC = 0,
178+ OPVP_CHORD = 1,
179+ OPVP_PIE = 2
180+} opvp_arcmode_t;
181+
182+typedef enum _opvp_arcdir {
183+ OPVP_CLOCKWISE = 0,
184+ OPVP_COUNTERCLOCKWISE = 1
185+} opvp_arcdir_t;
186+
187+typedef enum _opvp_pathmode {
188+ OPVP_PATHCLOSE = 0,
189+ OPVP_PATHOPEN = 1
190+} opvp_pathmode_t;
191+
192+/* CTM */
193+typedef struct _opvp_ctm {
194+ opvp_float_t a, b, c, d, e, f;
195+} opvp_ctm_t;
196+
197+/* Device Information and Capabilites */
198+typedef enum _opvp_queryinfoflags {
199+ OPVP_QF_DEVICERESOLUTION = 0x00000001,
200+ OPVP_QF_MEDIASIZE = 0x00000002,
201+ OPVP_QF_PAGEROTATION = 0x00000004,
202+ OPVP_QF_MEDIANUP = 0x00000008,
203+ OPVP_QF_MEDIADUPLEX = 0x00000010,
204+ OPVP_QF_MEDIASOURCE = 0x00000020,
205+ OPVP_QF_MEDIADESTINATION = 0x00000040,
206+ OPVP_QF_MEDIATYPE = 0x00000080,
207+ OPVP_QF_MEDIACOPY = 0x00000100, /* Maximum copy number
208+ supported */
209+ OPVP_QF_PRINTREGION = 0x00010000 /* only for opvpQueryDeviceInfo */
210+} opvp_queryinfoflags_t;
211+
212+
213+/* API Procedure Entries */
214+typedef struct _opvp_api_procs {
215+ opvp_dc_t (*opvpOpenPrinter)(opvp_int_t,const opvp_char_t*,const opvp_int_t[2],struct _opvp_api_procs**);
216+ opvp_result_t (*opvpClosePrinter)(opvp_dc_t);
217+ opvp_result_t (*opvpStartJob)(opvp_dc_t,const opvp_char_t*);
218+ opvp_result_t (*opvpEndJob)(opvp_dc_t);
219+ opvp_result_t (*opvpAbortJob)(opvp_dc_t);
220+ opvp_result_t (*opvpStartDoc)(opvp_dc_t,const opvp_char_t*);
221+ opvp_result_t (*opvpEndDoc)(opvp_dc_t);
222+ opvp_result_t (*opvpStartPage)(opvp_dc_t,const opvp_char_t*);
223+ opvp_result_t (*opvpEndPage)(opvp_dc_t);
224+ opvp_result_t (*opvpQueryDeviceCapability)(opvp_dc_t,opvp_flag_t,opvp_int_t*,opvp_byte_t*);
225+ opvp_result_t (*opvpQueryDeviceInfo)(opvp_dc_t,opvp_flag_t,opvp_int_t*,opvp_char_t*);
226+ opvp_result_t (*opvpResetCTM)(opvp_dc_t);
227+ opvp_result_t (*opvpSetCTM)(opvp_dc_t,const opvp_ctm_t*);
228+ opvp_result_t (*opvpGetCTM)(opvp_dc_t,opvp_ctm_t*);
229+ opvp_result_t (*opvpInitGS)(opvp_dc_t);
230+ opvp_result_t (*opvpSaveGS)(opvp_dc_t);
231+ opvp_result_t (*opvpRestoreGS)(opvp_dc_t);
232+ opvp_result_t (*opvpQueryColorSpace)(opvp_dc_t,opvp_int_t*,opvp_cspace_t*);
233+ opvp_result_t (*opvpSetColorSpace)(opvp_dc_t,opvp_cspace_t);
234+ opvp_result_t (*opvpGetColorSpace)(opvp_dc_t,opvp_cspace_t*);
235+ opvp_result_t (*opvpSetFillMode)(opvp_dc_t,opvp_fillmode_t);
236+ opvp_result_t (*opvpGetFillMode)(opvp_dc_t,opvp_fillmode_t*);
237+ opvp_result_t (*opvpSetAlphaConstant)(opvp_dc_t,opvp_float_t);
238+ opvp_result_t (*opvpGetAlphaConstant)(opvp_dc_t,opvp_float_t*);
239+ opvp_result_t (*opvpSetLineWidth)(opvp_dc_t,opvp_fix_t);
240+ opvp_result_t (*opvpGetLineWidth)(opvp_dc_t,opvp_fix_t*);
241+ opvp_result_t (*opvpSetLineDash)(opvp_dc_t,opvp_int_t,const opvp_fix_t*);
242+ opvp_result_t (*opvpGetLineDash)(opvp_dc_t,opvp_int_t*,opvp_fix_t*);
243+ opvp_result_t (*opvpSetLineDashOffset)(opvp_dc_t,opvp_fix_t);
244+ opvp_result_t (*opvpGetLineDashOffset)(opvp_dc_t,opvp_fix_t*);
245+ opvp_result_t (*opvpSetLineStyle)(opvp_dc_t,opvp_linestyle_t);
246+ opvp_result_t (*opvpGetLineStyle)(opvp_dc_t,opvp_linestyle_t*);
247+ opvp_result_t (*opvpSetLineCap)(opvp_dc_t,opvp_linecap_t);
248+ opvp_result_t (*opvpGetLineCap)(opvp_dc_t,opvp_linecap_t*);
249+ opvp_result_t (*opvpSetLineJoin)(opvp_dc_t,opvp_linejoin_t);
250+ opvp_result_t (*opvpGetLineJoin)(opvp_dc_t,opvp_linejoin_t*);
251+ opvp_result_t (*opvpSetMiterLimit)(opvp_dc_t,opvp_fix_t);
252+ opvp_result_t (*opvpGetMiterLimit)(opvp_dc_t,opvp_fix_t*);
253+ opvp_result_t (*opvpSetPaintMode)(opvp_dc_t,opvp_paintmode_t);
254+ opvp_result_t (*opvpGetPaintMode)(opvp_dc_t,opvp_paintmode_t*);
255+ opvp_result_t (*opvpSetStrokeColor)(opvp_dc_t,const opvp_brush_t*);
256+ opvp_result_t (*opvpSetFillColor)(opvp_dc_t,const opvp_brush_t*);
257+ opvp_result_t (*opvpSetBgColor)(opvp_dc_t,const opvp_brush_t*);
258+ opvp_result_t (*opvpNewPath)(opvp_dc_t);
259+ opvp_result_t (*opvpEndPath)(opvp_dc_t);
260+ opvp_result_t (*opvpStrokePath)(opvp_dc_t);
261+ opvp_result_t (*opvpFillPath)(opvp_dc_t);
262+ opvp_result_t (*opvpStrokeFillPath)(opvp_dc_t);
263+ opvp_result_t (*opvpSetClipPath)(opvp_dc_t,opvp_cliprule_t);
264+ opvp_result_t (*opvpResetClipPath)(opvp_dc_t);
265+ opvp_result_t (*opvpSetCurrentPoint)(opvp_dc_t,opvp_fix_t,opvp_fix_t);
266+ opvp_result_t (*opvpLinePath)(opvp_dc_t,opvp_pathmode_t,opvp_int_t,const opvp_point_t*);
267+ opvp_result_t (*opvpPolygonPath)(opvp_dc_t,opvp_int_t,const opvp_int_t*,const opvp_point_t*);
268+ opvp_result_t (*opvpRectanglePath)(opvp_dc_t,opvp_int_t,const opvp_rectangle_t*);
269+ opvp_result_t (*opvpRoundRectanglePath)(opvp_dc_t,opvp_int_t,const opvp_roundrectangle_t*);
270+ opvp_result_t (*opvpBezierPath)(opvp_dc_t,opvp_int_t,const opvp_point_t*);
271+ opvp_result_t (*opvpArcPath)(opvp_dc_t,opvp_arcmode_t,opvp_arcdir_t,opvp_fix_t,opvp_fix_t,opvp_fix_t,opvp_fix_t,opvp_fix_t,opvp_fix_t,opvp_fix_t,opvp_fix_t);
272+ opvp_result_t (*opvpDrawImage)(opvp_dc_t,opvp_int_t,opvp_int_t,opvp_int_t,opvp_imageformat_t,opvp_int_t, opvp_int_t ,const void*);
273+ opvp_result_t (*opvpStartDrawImage)(opvp_dc_t,opvp_int_t,opvp_int_t,opvp_int_t,opvp_imageformat_t,opvp_int_t, opvp_int_t);
274+ opvp_result_t (*opvpTransferDrawImage)(opvp_dc_t,opvp_int_t,const void*);
275+ opvp_result_t (*opvpEndDrawImage)(opvp_dc_t);
276+ opvp_result_t (*opvpStartScanline)(opvp_dc_t,opvp_int_t);
277+ opvp_result_t (*opvpScanline)(opvp_dc_t,opvp_int_t,const opvp_int_t*);
278+ opvp_result_t (*opvpEndScanline)(opvp_dc_t);
279+ opvp_result_t (*opvpStartRaster)(opvp_dc_t,opvp_int_t);
280+ opvp_result_t (*opvpTransferRasterData)(opvp_dc_t,opvp_int_t,const opvp_byte_t*);
281+ opvp_result_t (*opvpSkipRaster)(opvp_dc_t,opvp_int_t);
282+ opvp_result_t (*opvpEndRaster)(opvp_dc_t);
283+ opvp_result_t (*opvpStartStream)(opvp_dc_t);
284+ opvp_result_t (*opvpTransferStreamData)(opvp_dc_t,opvp_int_t,const void*);
285+ opvp_result_t (*opvpEndStream)(opvp_dc_t);
286+} opvp_api_procs_t;
287+
288+/* Function prototype */
289+opvp_dc_t opvpOpenPrinter(
290+ opvp_int_t outputFD,
291+ const opvp_char_t *printerModel,
292+ const opvp_int_t apiVersion[2],
293+ opvp_api_procs_t **apiProcs);
294+
295+/* error no */
296+extern opvp_int_t opvpErrorNo;
297+
298+#endif /* _OPVP_H_ */
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
--- gdevopvp/tags/RELEASE_1_0_7/src/opvp_common.h (nonexistent)
+++ gdevopvp/tags/RELEASE_1_0_7/src/opvp_common.h (revision 917)
@@ -0,0 +1,54 @@
1+/*
2+
3+Copyright (c) 2003-2004, AXE, Inc. All rights reserved.
4+
5+Permission is hereby granted, free of charge, to any person obtaining
6+a copy of this software and associated documentation files (the
7+"Software"), to deal in the Software without restriction, including
8+without limitation the rights to use, copy, modify, merge, publish,
9+distribute, sublicense, and/or sell copies of the Software, and to
10+permit persons to whom the Software is furnished to do so, subject to
11+the following conditions:
12+
13+The above copyright notice and this permission notice shall be included
14+in all copies or substantial portions of the Software.
15+
16+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
24+*/
25+/* OpenPrinting Vector Printer Driver Glue Code */
26+
27+#ifndef _OPVP_COMMON_H_
28+#define _OPVP_COMMON_H_
29+
30+#include "opvp_0_2_0.h"
31+#undef _PDAPI_VERSION_MAJOR_
32+#undef _PDAPI_VERSION_MINOR_
33+/* undefine conflicted macros */
34+#undef OPVP_INFO_PREFIX
35+#undef OPVP_OK
36+#undef OPVP_FATALERROR
37+#undef OPVP_BADREQUEST
38+#undef OPVP_BADCONTEXT
39+#undef OPVP_NOTSUPPORTED
40+#undef OPVP_JOBCANCELED
41+#undef OPVP_PARAMERROR
42+/* define 0_2 error no as different macros */
43+#define OPVP_FATALERROR_0_2 -101
44+#define OPVP_BADREQUEST_0_2 -102
45+#define OPVP_BADCONTEXT_0_2 -103
46+#define OPVP_NOTSUPPORTED_0_2 -104
47+#define OPVP_JOBCANCELED_0_2 -105
48+#define OPVP_PARAMERROR_0_2 -106
49+
50+#include "opvp.h"
51+#define OPVP_INFO_PREFIX ""
52+
53+#endif /* _OPVP_COMMON_H_ */
54+
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
--- gdevopvp/tags/RELEASE_1_0_7/src/opvp_0_2_0.h (nonexistent)
+++ gdevopvp/tags/RELEASE_1_0_7/src/opvp_0_2_0.h (revision 917)
@@ -0,0 +1,299 @@
1+/*
2+
3+Copyright (c) 2003-2004, AXE, Inc. All rights reserved.
4+
5+Permission is hereby granted, free of charge, to any person obtaining
6+a copy of this software and associated documentation files (the
7+"Software"), to deal in the Software without restriction, including
8+without limitation the rights to use, copy, modify, merge, publish,
9+distribute, sublicense, and/or sell copies of the Software, and to
10+permit persons to whom the Software is furnished to do so, subject to
11+the following conditions:
12+
13+The above copyright notice and this permission notice shall be included
14+in all copies or substantial portions of the Software.
15+
16+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
24+*/
25+/* $Id$ */
26+/* opvp_common.h ver.1.00 rel.1.0 26 Nov 2004 */
27+/* OpenPrinting Vector Printer Driver Glue Code */
28+
29+#ifndef _FSGPD_0_2_0_H
30+#define _FSGPD_0_2_0_H
31+
32+#define _PDAPI_VERSION_MAJOR_ 0
33+#define _PDAPI_VERSION_MINOR_ 2
34+
35+/* Return Values */
36+#define OPVP_OK 0 /* error is -1 */
37+
38+/* Error Codes */
39+#define OPVP_FATALERROR -101 /* unrecoverable error occurred within the */
40+ /* library */
41+#define OPVP_BADREQUEST -102 /* invalid function parameters */
42+#define OPVP_BADCONTEXT -103 /* bad parameter precontext */
43+#define OPVP_NOTSUPPORTED -104 /* printer or driver request not supported */
44+#define OPVP_JOBCANCELED -105 /* job cancelled */
45+#define OPVP_PARAMERROR -106 /* illegal parameter combination */
46+
47+/* Info params */
48+#define OPVP_INFO_PREFIX "updf:"
49+
50+/* Fix */
51+#define OPVP_FIX_FRACT_WIDTH 8
52+#define OPVP_FIX_FRACT_DENOM (1<<OPVP_FIX_FRACT_WIDTH)
53+#define OPVP_FIX_FLOOR_WIDTH (sizeof(int)*8-OPVP_FIX_FRACT_WIDTH)
54+#if 0
55+typedef struct {
56+ unsigned int fract : OPVP_FIX_FRACT_WIDTH;
57+ signed int floor : OPVP_FIX_FLOOR_WIDTH;
58+} OPVP_Fix;
59+#define OPVP_i2Fix(i,fix) (fix.fract=0,fix.floor=i)
60+#define OPVP_Fix2f(fix,f) (f=(double)fix.floor\
61+ +(double)(fix.fract)/OPVP_FIX_FRACT_DENOM)
62+#define OPVP_f2Fix(f,fix) (fix.fract=(f-floor(f))*OPVP_FIX_FRACT_DENOM,\
63+ fix.floor=floor(f))
64+#else
65+typedef int OPVP_Fix;
66+#define OPVP_i2Fix(i,fix) (fix=i<<8)
67+#define OPVP_f2Fix(f,fix) (fix=((int)floor(f)<<8)\
68+ |((int)((f-floor(f))*OPVP_FIX_FRACT_DENOM)\
69+ &0x000000ff))
70+#endif
71+
72+/* Basic Types */
73+typedef struct _OPVP_Point {
74+ OPVP_Fix x;
75+ OPVP_Fix y;
76+} OPVP_Point;
77+
78+typedef struct _OPVP_Rectangle {
79+ OPVP_Point p0; /* start point */
80+ OPVP_Point p1; /* end point */
81+} OPVP_Rectangle;
82+
83+typedef struct _OPVP_RoundRectangle {
84+ OPVP_Point p0; /* start point */
85+ OPVP_Point p1; /* end point */
86+ OPVP_Fix xellipse;
87+ OPVP_Fix yellipse;
88+} OPVP_RoundRectangle;
89+
90+/* Image Formats */
91+typedef enum _OPVP_ImageFormat {
92+ OPVP_iformatRaw = 0,
93+ OPVP_iformatRLE = 1,
94+ OPVP_iformatJPEG = 2,
95+ OPVP_iformatPNG = 3
96+} OPVP_ImageFormat;
97+
98+/* Color Presentation */
99+typedef enum _OPVP_ColorMapping {
100+ OPVP_cmapDirect = 0,
101+ OPVP_cmapIndexed = 1
102+} OPVP_ColorMapping;
103+
104+typedef enum _OPVP_ColorSpace {
105+ OPVP_cspaceBW = 0,
106+ OPVP_cspaceDeviceGray = 1,
107+ OPVP_cspaceDeviceCMY = 2,
108+ OPVP_cspaceDeviceCMYK = 3,
109+ OPVP_cspaceDeviceRGB = 4,
110+ OPVP_cspaceStandardRGB = 5,
111+ OPVP_cspaceStandardRGB64 = 6
112+} OPVP_ColorSpace;
113+
114+/* Raster Operation modes */
115+typedef enum _OPVP_ROP {
116+ OPVP_ropPset = 0,
117+ OPVP_ropPreset = 1,
118+ OPVP_ropOr = 2,
119+ OPVP_ropAnd = 3,
120+ OPVP_ropXor = 4
121+} OPVP_ROP;
122+
123+/* Fill, Paint, Clip */
124+typedef enum _OPVP_FillMode {
125+ OPVP_fillModeEvenOdd = 0,
126+ OPVP_fillModeWinding = 1
127+} OPVP_FillMode;
128+
129+typedef enum _OPVP_PaintMode {
130+ OPVP_paintModeOpaque = 0,
131+ OPVP_paintModeTransparent = 1
132+} OPVP_PaintMode;
133+
134+typedef enum _OPVP_ClipRule {
135+ OPVP_clipRuleEvenOdd = 0,
136+ OPVP_clipRuleWinding = 1
137+} OPVP_ClipRule;
138+
139+/* Line */
140+typedef enum _OPVP_LineStyle {
141+ OPVP_lineStyleSolid = 0,
142+ OPVP_lineStyleDash = 1
143+} OPVP_LineStyle;
144+
145+typedef enum _OPVP_LineCap {
146+ OPVP_lineCapButt = 0,
147+ OPVP_lineCapRound = 1,
148+ OPVP_lineCapSquare = 2
149+} OPVP_LineCap;
150+
151+typedef enum _OPVP_LineJoin {
152+ OPVP_lineJoinMiter = 0,
153+ OPVP_lineJoinRound = 1,
154+ OPVP_lineJoinBevel = 2
155+} OPVP_LineJoin;
156+
157+/* Brush */
158+typedef enum _OPVP_BrushDataType {
159+ OPVP_bdtypeNormal = 0
160+} OPVP_BrushDataType;
161+
162+typedef struct _OPVP_BrushData {
163+ OPVP_BrushDataType type;
164+ int width;
165+ int height;
166+ int pitch;
167+#if (_PDAPI_VERSION_MAJOR_ == 0 && _PDAPI_VERSION_MINOR_ < 2)
168+ void *data; /* pointer to actual data */
169+#else
170+ char data[1];
171+#endif
172+} OPVP_BrushData;
173+
174+typedef struct _OPVP_Brush {
175+ OPVP_ColorSpace colorSpace;
176+ int color[4]; /* aRGB quadruplet */
177+#if (_PDAPI_VERSION_MAJOR_ == 0 && _PDAPI_VERSION_MINOR_ < 2)
178+ OPVP_BrushData *pbrush; /* pointer to brush data */
179+ /* solid brush used, if null */
180+ int xorg; /* brush origin */
181+ int yorg; /* ignored for SetBgColor */
182+#else
183+ int xorg; /* brush origin */
184+ int yorg; /* ignored for SetBgColor */
185+ OPVP_BrushData *pbrush; /* pointer to brush data */
186+ /* solid brush used, if null */
187+#endif
188+} OPVP_Brush;
189+
190+/* Misc. Flags */
191+#define OPVP_Arc 0 /* circular arc */
192+#define OPVP_Chord 1 /* arch */
193+#define OPVP_Pie 2 /* pie section */
194+#define OPVP_Clockwise 0 /* clockwise */
195+#define OPVP_Counterclockwise 1 /* counter-clockwise */
196+#define OPVP_PathClose 0 /* Close path when using LinePath */
197+#define OPVP_PathOpen 1 /* Do not close path when using LinePath */
198+
199+/* CTM */
200+typedef struct _OPVP_CTM {
201+ float a;
202+ float b;
203+ float c;
204+ float d;
205+ float e;
206+ float f;
207+} OPVP_CTM;
208+
209+/* Vector Driver API Proc. Entries */
210+typedef struct _OPVP_api_procs {
211+ int (*OpenPrinter)(int,char *,int *,struct _OPVP_api_procs **);
212+ int (*ClosePrinter)(int);
213+ int (*StartJob)(int,char *);
214+ int (*EndJob)(int);
215+ int (*StartDoc)(int,char *);
216+ int (*EndDoc)(int);
217+ int (*StartPage)(int,char *);
218+ int (*EndPage)(int);
219+#if (_PDAPI_VERSION_MAJOR_ > 0 || _PDAPI_VERSION_MINOR_ >= 2)
220+ int (*QueryDeviceCapability)(int,int,int,char *);
221+ int (*QueryDeviceInfo)(int,int,int,char *);
222+#endif
223+ int (*ResetCTM)(int);
224+ int (*SetCTM)(int,OPVP_CTM *);
225+ int (*GetCTM)(int,OPVP_CTM *);
226+ int (*InitGS)(int);
227+ int (*SaveGS)(int);
228+ int (*RestoreGS)(int);
229+ int (*QueryColorSpace)(int,OPVP_ColorSpace *,int *);
230+ int (*SetColorSpace)(int,OPVP_ColorSpace);
231+ int (*GetColorSpace)(int,OPVP_ColorSpace *);
232+ int (*QueryROP)(int,int *,int *);
233+ int (*SetROP)(int,int);
234+ int (*GetROP)(int,int *);
235+ int (*SetFillMode)(int,OPVP_FillMode);
236+ int (*GetFillMode)(int,OPVP_FillMode *);
237+ int (*SetAlphaConstant)(int,float);
238+ int (*GetAlphaConstant)(int,float *);
239+ int (*SetLineWidth)(int,OPVP_Fix);
240+ int (*GetLineWidth)(int,OPVP_Fix *);
241+ int (*SetLineDash)(int,OPVP_Fix *,int);
242+ int (*GetLineDash)(int,OPVP_Fix *,int *);
243+ int (*SetLineDashOffset)(int,OPVP_Fix);
244+ int (*GetLineDashOffset)(int,OPVP_Fix *);
245+ int (*SetLineStyle)(int,OPVP_LineStyle);
246+ int (*GetLineStyle)(int,OPVP_LineStyle *);
247+ int (*SetLineCap)(int,OPVP_LineCap);
248+ int (*GetLineCap)(int,OPVP_LineCap *);
249+ int (*SetLineJoin)(int,OPVP_LineJoin);
250+ int (*GetLineJoin)(int,OPVP_LineJoin *);
251+ int (*SetMiterLimit)(int,OPVP_Fix);
252+ int (*GetMiterLimit)(int,OPVP_Fix *);
253+ int (*SetPaintMode)(int,OPVP_PaintMode);
254+ int (*GetPaintMode)(int,OPVP_PaintMode *);
255+ int (*SetStrokeColor)(int,OPVP_Brush *);
256+ int (*SetFillColor)(int,OPVP_Brush *);
257+ int (*SetBgColor)(int,OPVP_Brush *);
258+ int (*NewPath)(int);
259+ int (*EndPath)(int);
260+ int (*StrokePath)(int);
261+ int (*FillPath)(int);
262+ int (*StrokeFillPath)(int);
263+ int (*SetClipPath)(int,OPVP_ClipRule);
264+#if (_PDAPI_VERSION_MAJOR_ > 0 || _PDAPI_VERSION_MINOR_ >= 2)
265+ int (*ResetClipPath)(int);
266+#endif
267+ int (*SetCurrentPoint)(int,OPVP_Fix,OPVP_Fix);
268+ int (*LinePath)(int,int,int,OPVP_Point *);
269+ int (*PolygonPath)(int,int,int *,OPVP_Point *);
270+ int (*RectanglePath)(int,int,OPVP_Rectangle *);
271+ int (*RoundRectanglePath)(int,int,OPVP_RoundRectangle *);
272+#if (_PDAPI_VERSION_MAJOR_ == 0 && _PDAPI_VERSION_MINOR_ < 2)
273+ int (*BezierPath)(int,int *,OPVP_Point *);
274+#else
275+ int (*BezierPath)(int,int,OPVP_Point *);
276+#endif
277+ int (*ArcPath)(int,int,int,OPVP_Fix,OPVP_Fix,OPVP_Fix,OPVP_Fix,
278+ OPVP_Fix,OPVP_Fix,OPVP_Fix,OPVP_Fix);
279+ int (*DrawBitmapText)(int,int,int,int,void *);
280+ int (*DrawImage)(int,int,int,int,
281+ OPVP_ImageFormat,OPVP_Rectangle,int,void *);
282+ int (*StartDrawImage)(int,int,int,int,
283+ OPVP_ImageFormat,OPVP_Rectangle);
284+ int (*TransferDrawImage)(int,int,void *);
285+ int (*EndDrawImage)(int);
286+ int (*StartScanline)(int,int);
287+ int (*Scanline)(int,int,int *);
288+ int (*EndScanline)(int);
289+ int (*StartRaster)(int,int);
290+ int (*TransferRasterData)(int,int,unsigned char *);
291+ int (*SkipRaster)(int,int);
292+ int (*EndRaster)(int);
293+ int (*StartStream)(int);
294+ int (*TransferStreamData)(int,int,void *);
295+ int (*EndStream)(int);
296+} OPVP_api_procs;
297+
298+#endif /* _OPVP_COMMON_H_ */
299+
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
--- gdevopvp/tags/RELEASE_1_0_7/ChangeLog (nonexistent)
+++ gdevopvp/tags/RELEASE_1_0_7/ChangeLog (revision 917)
@@ -0,0 +1,31 @@
1+* Sun Dec 11 2005 Toshihiro Yamagishi <toshihiro@turbolinux.co.jp> - ver.1.05.0
2+- The opvp driver incorrectly assumed that CODESET was
3+ supported on all platforms that supported iconv (espgs STR #1247)
4+- fixed the bug that 1bpp bitmap was printed in reverse color(SF #6485)
5+- use snprintf instead of sprintf to avoid a few potential security holes.
6+- do not ignore blank page
7+- we should use fabs instead of fabsf (espgs STR #1291)
8+
9+* Sat Jun 11 2005 Toshihiro Yamagishi <toshihiro@turbolinux.co.jp> - ver.1.04.0
10+- Correct the inappropriate pitch bytes handling for drawing bitmaps on 64bit arch.
11+
12+* Thu Mar 10 2005 Toshihiro Yamagishi <toshihiro@turbolinux.co.jp> - ver.1.03.02
13+- fixed the problem that fails to handle index colored BW images.
14+
15+* Thu Mar 3 2005 Toshihiro Yamagishi <toshihiro@turbolinux.co.jp> - ver.1.03.01
16+- avoid crash in gx_general_fill_path of ghostscript-8.x
17+
18+* Wed Mar 2 2005 Toshihiro Yamagishi <toshihiro@turbolinux.co.jp> - ver.1.03
19+- applied image gamma correction
20+- compiled with ghostscript-8.x
21+
22+2004-12-03 Masaki IWATA <iwata@axe-inc.co.jp>
23+* merged opfc.1.02 version updates
24+- fixed security hole (buffer overflows)
25+- modified 'Fix' data-type for big-endian
26+
27+* Mon Oct 25 2004 Toshihiro Yamagishi <toshihiro@turbolinux.co.jp> - ver.1.01
28+- merged 1.01
29+
30+* Fri Jul 23 2004 Toshihiro Yamagishi <toshihiro@turbolinux.co.jp> - ver.1.00 rel.0.8
31+- fixed 256-color image processing bug
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
--- gdevopvp/tags/RELEASE_1_0_7/gdevopvp-gs7.06.patch (nonexistent)
+++ gdevopvp/tags/RELEASE_1_0_7/gdevopvp-gs7.06.patch (revision 917)
@@ -0,0 +1,31 @@
1+--- ghostscript-7.06/src/Makefile.in.org 2003-11-06 15:29:59.000000000 +0900
2++++ ghostscript-7.06/src/Makefile.in 2004-02-01 01:04:57.000000000 +0900
3+@@ -369,7 +369,7 @@
4+ DEVICE_DEVS5=@OMNIDEVS@
5+ DEVICE_DEVS6=@STPDEVS@
6+ DEVICE_DEVS7=@HPIJSDEVS@
7+-DEVICE_DEVS8=
8++DEVICE_DEVS8=$(DD)opvp.dev $(DD)oprp.dev
9+ DEVICE_DEVS9=
10+ DEVICE_DEVS10=
11+ DEVICE_DEVS11=
12+--- ghostscript-7.06/src/contrib.mak.org 2003-11-06 15:05:22.000000000 +0900
13++++ ghostscript-7.06/src/contrib.mak 2004-03-16 17:32:27.249498080 +0900
14+@@ -1705,3 +1705,17 @@
15+ $(DD)djet820c.dev: $(djet820c_) $(DD)page.dev
16+ $(SETDEV) $(DD)djet820c $(djet820c_)
17+
18++### ---------------- OpenPrinting Vector Printer Driver ---------------- ###
19++
20++opvp_=$(GLOBJ)gdevopvp.$(OBJ)
21++OPVPH = $(GLSRC)opvp_common.h $(GLSRC)opvp_media.def $(PDEVH)
22++
23++$(GLOBJ)gdevopvp.$(OBJ) : $(GLSRC)gdevopvp.c $(OPVPH)
24++ $(GLCC) $(GLO_)gdevopvp.$(OBJ) $(C_) $(GLSRC)gdevopvp.c
25++
26++$(DD)opvp.dev : $(opvp_) $(DD)page.dev
27++ $(SETPDEV) $(DD)opvp $(opvp_)
28++
29++$(DD)oprp.dev : $(opvp_) $(DD)page.dev
30++ $(SETPDEV) $(DD)oprp $(opvp_)
31++
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Show on old repository browser