Add support for filling / thindrawing raw polygons to the HID interface
[geda-pcb/gde.git] / src / hid / lpr / lpr.c
blobcbf19c60054c6c10ae9cd3c5903e3b8a652440d9
1 /* $Id$ */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include <stdio.h>
8 #include <stdarg.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <assert.h>
13 #include "global.h"
14 #include "data.h"
15 #include "misc.h"
17 #include "hid.h"
18 #include "../hidint.h"
19 #include "../ps/ps.h"
21 #ifdef HAVE_LIBDMALLOC
22 #include <dmalloc.h>
23 #endif
25 RCSID ("$Id$");
27 #define CRASH fprintf(stderr, "HID error: pcb called unimplemented PS function %s.\n", __FUNCTION__); abort()
29 static HID_Attribute base_lpr_options[] = {
30 {"lprcommand", "Command to print",
31 HID_String, 0, 0, {0, 0, 0}, 0, 0},
32 #define HA_lprcommand 0
35 #define NUM_OPTIONS (sizeof(lpr_options)/sizeof(lpr_options[0]))
37 static HID_Attribute *lpr_options = 0;
38 static int num_lpr_options = 0;
39 static HID_Attr_Val *lpr_values;
41 static HID_Attribute *
42 lpr_get_export_options (int *n)
45 * We initialize the default value in this manner because the GUI
46 * HID's may want to free() this string value and replace it with a
47 * new one based on how a user fills out a print dialog.
49 if (base_lpr_options[HA_lprcommand].default_val.str_value == NULL)
51 base_lpr_options[HA_lprcommand].default_val.str_value = strdup("lpr");
54 if (lpr_options == 0)
56 HID_Attribute *ps_opts = ps_hid.get_export_options (&num_lpr_options);
57 lpr_options =
58 (HID_Attribute *) calloc (num_lpr_options, sizeof (HID_Attribute));
59 memcpy (lpr_options, ps_opts, num_lpr_options * sizeof (HID_Attribute));
60 memcpy (lpr_options, base_lpr_options, sizeof (base_lpr_options));
61 lpr_values =
62 (HID_Attr_Val *) calloc (num_lpr_options, sizeof (HID_Attr_Val));
64 if (n)
65 *n = num_lpr_options;
66 return lpr_options;
69 static void
70 lpr_do_export (HID_Attr_Val * options)
72 FILE *f;
73 int i;
74 char *filename;
76 if (!options)
78 lpr_get_export_options (0);
79 for (i = 0; i < num_lpr_options; i++)
80 lpr_values[i] = lpr_options[i].default_val;
81 options = lpr_values;
84 filename = options[HA_lprcommand].str_value;
86 printf ("LPR: open %s\n", filename);
87 f = popen (filename, "w");
88 if (!f)
90 perror (filename);
91 return;
94 ps_start_file (f);
95 ps_hid_export_to_file (f, options);
97 fclose (f);
100 extern void hid_parse_command_line (int *argc, char ***argv);
102 static void
103 lpr_parse_arguments (int *argc, char ***argv)
105 lpr_get_export_options (0);
106 hid_register_attributes (lpr_options, num_lpr_options);
107 hid_parse_command_line (argc, argv);
110 static void
111 lpr_calibrate (double xval, double yval)
113 ps_calibrate_1 (xval, yval, 1);
116 HID lpr_hid = {
117 sizeof (HID),
118 "lpr",
119 "Postscript print.",
120 0, 1, 0, 1, 0, 0,
121 lpr_get_export_options,
122 lpr_do_export,
123 lpr_parse_arguments,
124 0 /* lpr_invalidate_wh */ ,
125 0 /* lpr_invalidate_lr */ ,
126 0 /* lpr_invalidate_all */ ,
127 0 /* lpr_set_layer */ ,
128 0 /* lpr_make_gc */ ,
129 0 /* lpr_destroy_gc */ ,
130 0 /* lpr_use_mask */ ,
131 0 /* lpr_set_color */ ,
132 0 /* lpr_set_line_cap */ ,
133 0 /* lpr_set_line_width */ ,
134 0 /* lpr_set_draw_xor */ ,
135 0 /* lpr_set_draw_faded */ ,
136 0 /* lpr_set_line_cap_angle */ ,
137 0 /* lpr_draw_line */ ,
138 0 /* lpr_draw_arc */ ,
139 0 /* lpr_draw_rect */ ,
140 0 /* lpr_fill_circle */ ,
141 0 /* lpr_fill_polygon */ ,
142 0 /* lpr_fill_pcb_polygon */ ,
143 0 /* lpr_thindraw_pcb_polygon */ ,
144 0 /* lpr_fill_rect */ ,
145 lpr_calibrate,
146 0 /* lpr_shift_is_pressed */ ,
147 0 /* lpr_control_is_pressed */ ,
148 0 /* lpr_get_coords */ ,
149 0 /* lpr_set_crosshair */ ,
150 0 /* lpr_add_timer */ ,
151 0 /* lpr_stop_timer */ ,
152 0 /* lpr_watch_file */ ,
153 0 /* lpr_unwatch_file */ ,
154 0 /* lpr_add_block_hook */ ,
155 0 /* lpr_stop_block_hook */ ,
156 0 /* lpr_log */ ,
157 0 /* lpr_logv */ ,
158 0 /* lpr_confirm_dialog */ ,
159 0 /* lpr_close_confirm_dialog */ ,
160 0 /* lpr_report_dialog */ ,
161 0 /* lpr_prompt_for */ ,
162 0 /* lpr_fileselect */ ,
163 0 /* lpr_attribute_dialog */ ,
164 0 /* lpr_show_item */ ,
165 0 /* lpr_beep */ ,
166 0 /* lpr_progress */
169 void
170 hid_lpr_init ()
172 apply_default_hid (&lpr_hid, &ps_hid);
173 apply_default_hid (&lpr_hid, 0);
174 hid_register_hid (&lpr_hid);