]> git.ipfire.org Git - thirdparty/cups.git/blob - filter/hpgl-main.c
Fixed HP-GL/2 scaling bugs.
[thirdparty/cups.git] / filter / hpgl-main.c
1 /*
2 * "$Id: hpgl-main.c,v 1.16 1999/10/27 20:20:14 mike Exp $"
3 *
4 * HP-GL/2 filter main entry for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1993-1999 by Easy Software Products.
7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
19 *
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * Contents:
25 *
26 * main() - Main entry for HP-GL/2 filter.
27 * compare_names() - Compare two command names.
28 */
29
30 /*
31 * Include necessary headers...
32 */
33
34 /*#define DEBUG*/
35 #define _HPGL_MAIN_C_
36 #include "hpgltops.h"
37
38
39 /*
40 * HP-GL/2 command table...
41 */
42
43 typedef struct
44 {
45 char name[4]; /* Name of command */
46 void (*func)(int, param_t *); /* Function to call */
47 } name_t;
48
49 static name_t commands[] =
50 {
51 { "BP", BP_begin_plot },
52 { "DF", DF_default_values },
53 { "IN", IN_initialize },
54 { "IP", IP_input_absolute },
55 { "IR", IR_input_relative },
56 { "IW", IW_input_window },
57 { "PG", PG_advance_page },
58 { "RO", RO_rotate },
59 { "RP", RP_replot },
60 { "SC", SC_scale },
61 { "AA", AA_arc_absolute },
62 { "AR", AR_arc_relative },
63 { "AT", AT_arc_absolute3 },
64 { "CI", CI_circle },
65 { "PA", PA_plot_absolute },
66 { "PD", PD_pen_down },
67 { "PE", PE_polyline_encoded },
68 { "PR", PR_plot_relative },
69 { "PS", PS_plot_size },
70 { "PU", PU_pen_up },
71 { "RT", RT_arc_relative3 },
72 { "EA", EA_edge_rect_absolute },
73 { "EP", EP_edge_polygon },
74 { "ER", ER_edge_rect_relative },
75 { "EW", EW_edge_wedge },
76 { "FP", FP_fill_polygon },
77 { "PM", PM_polygon_mode },
78 { "RA", RA_fill_rect_absolute },
79 { "RR", RR_fill_rect_relative },
80 { "WG", WG_fill_wedge },
81 { "AD", AD_define_alternate },
82 { "CF", CF_character_fill },
83 { "CP", CP_character_plot },
84 { "DI", DI_absolute_direction },
85 { "DR", DR_relative_direction },
86 { "DT", DT_define_label_term },
87 { "DV", DV_define_variable_path },
88 { "ES", ES_extra_space },
89 { "LB", LB_label },
90 { "LO", LO_label_origin },
91 { "SA", SA_select_alternate },
92 { "SD", SD_define_standard },
93 { "SI", SI_absolute_size },
94 { "SL", SL_character_slant },
95 { "SR", SR_relative_size },
96 { "SS", SS_select_standard },
97 { "TD", TD_transparent_data },
98 { "AC", AC_anchor_corner },
99 { "FT", FT_fill_type },
100 { "LA", LA_line_attributes },
101 { "LT", LT_line_type },
102 { "NP", NP_number_pens },
103 { "PC", PC_pen_color },
104 { "CR", CR_color_range },
105 { "PW", PW_pen_width },
106 { "RF", RF_raster_fill },
107 { "SM", SM_symbol_mode },
108 { "SP", SP_select_pen },
109 { "UL", UL_user_line_type },
110 { "WU", WU_width_units }
111 };
112 #define NUM_COMMANDS (sizeof(commands) / sizeof(name_t))
113
114
115 /*
116 * Local functions...
117 */
118
119 static int compare_names(const void *p1, const void *p2);
120
121
122 /*
123 * 'main()' - Main entry for HP-GL/2 filter.
124 */
125
126 int /* O - Exit status */
127 main(int argc, /* I - Number of command-line arguments */
128 char *argv[]) /* I - Command-line arguments */
129 {
130 FILE *fp; /* Input file */
131 int num_params; /* Number of parameters */
132 param_t *params; /* Command parameters */
133 name_t *command, /* Command */
134 name; /* Name of command */
135 int num_options; /* Number of print options */
136 cups_option_t *options; /* Print options */
137 const char *val; /* Option value */
138 int shading; /* -1 = black, 0 = grey, 1 = color */
139 float penwidth; /* Default pen width */
140
141
142 if (argc < 6 || argc > 7)
143 {
144 fputs("ERROR: hpgltops job-id user title copies options [file]\n", stderr);
145 return (1);
146 }
147
148 /*
149 * If we have 7 arguments, print the file named on the command-line.
150 * Otherwise, send stdin instead...
151 */
152
153 if (argc == 6)
154 fp = stdin;
155 else
156 {
157 /*
158 * Try to open the print file...
159 */
160
161 if ((fp = fopen(argv[6], "rb")) == NULL)
162 {
163 perror("ERROR: unable to open print file - ");
164 return (1);
165 }
166 }
167
168 /*
169 * Process command-line options and write the prolog...
170 */
171
172 options = NULL;
173 num_options = cupsParseOptions(argv[5], 0, &options);
174
175 PPD = SetCommonOptions(num_options, options, 1);
176
177 shading = 1;
178 penwidth = 1.0;
179
180 if ((val = cupsGetOption("blackplot", num_options, options)) != NULL)
181 shading = 0;
182
183 if ((val = cupsGetOption("fitplot", num_options, options)) != NULL)
184 FitPlot = 1;
185
186 if ((val = cupsGetOption("penwidth", num_options, options)) != NULL)
187 penwidth = (float)atof(val);
188
189 /*
190 * Write the PostScript prolog and initialize the plotting "engine"...
191 */
192
193 OutputProlog(argv[3], argv[2], shading, penwidth);
194
195 IP_input_absolute(0, NULL);
196
197 /*
198 * Sort the command array...
199 */
200
201 qsort(commands, NUM_COMMANDS, sizeof(name_t),
202 (int (*)(const void *, const void *))compare_names);
203
204 /*
205 * Read commands until we reach the end of file.
206 */
207
208 while ((num_params = ParseCommand(fp, name.name, &params)) >= 0)
209 {
210 #ifdef DEBUG
211 {
212 int i;
213 fprintf(stderr, "DEBUG: %s(%d)", name.name, num_params);
214 for (i = 0; i < num_params; i ++)
215 if (params[i].type == PARAM_STRING)
216 fprintf(stderr, " \'%s\'", params[i].value.string);
217 else
218 fprintf(stderr, " %f", params[i].value.number);
219 fputs("\n", stderr);
220 }
221 #endif /* DEBUG */
222
223 if ((command = bsearch(&name, commands, NUM_COMMANDS, sizeof(name_t),
224 (int (*)(const void *, const void *))compare_names)) != NULL)
225 (*command->func)(num_params, params);
226
227 FreeParameters(num_params, params);
228 }
229
230 OutputTrailer();
231
232 if (fp != stdin)
233 fclose(fp);
234
235 return (0);
236 }
237
238
239 /*
240 * 'compare_names()' - Compare two command names.
241 */
242
243 static int /* O - Result of strcasecmp() on names */
244 compare_names(const void *p1, /* I - First name */
245 const void *p2) /* I - Second name */
246 {
247 return (strcasecmp(((name_t *)p1)->name, ((name_t *)p2)->name));
248 }
249
250
251 /*
252 * End of "$Id: hpgl-main.c,v 1.16 1999/10/27 20:20:14 mike Exp $".
253 */