1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
/* Portions Copyright (C) 2001 artofcode LLC.
Portions Copyright (C) 1996, 2001 Artifex Software Inc.
Portions Copyright (C) 1988, 2000 Aladdin Enterprises.
This software is based in part on the work of the Independent JPEG Group.
All Rights Reserved.
This software is distributed under license and may not be copied, modified
or distributed except as expressly authorized under the terms of that
license. Refer to licensing information at http://www.artifex.com/ or
contact Artifex Software, Inc., 101 Lucas Valley Road #110,
San Rafael, CA 94903, (415)492-9861, for further information. */
/*$Id$ */
/* pgstate.h - definition of HP-GL/2 portion of PCL5 state */
/*
* This file should not be included by files other than pcstate.h; if you
* need the information in this file, include pcstate.h.
*/
#ifndef pgstate_INCLUDED
#define pgstate_INCLUDED
/*
* HPGL/2 coordinates are internally represented in plotter units
* 1/1024" when scaling is off and user units when scaling is in
* effect. The data structure g.pos maintains the coordinates in the
* hpgl/2 state. By default the coordinate system sets up the origin
* in the lower left of the page with X increasing along the short
* edge and Y increasing up the long edge. Note the Y direction is
* opposite PCL's.
*/
#include "gx.h"
#include "gxfixed.h"
#include "gslparam.h"
#ifndef gs_imager_state_DEFINED
# define gs_imager_state_DEFINED
typedef struct gs_imager_state_s gs_imager_state;
#endif
#include "gzpath.h"
/* Opaque type for a path */
#ifndef gx_path_DEFINED
# define gx_path_DEFINED
typedef struct gx_path_s gx_path;
#endif
/* Define a type for HP-GL/2 floating point values. */
typedef double hpgl_real_t;
/* scaling definition */
typedef struct hpgl_scaling_params_s {
gs_point pmin, pmax, factor;
float left, bottom;
} hpgl_scaling_params_t;
/* Define a line type (a.k.a. dash pattern). */
typedef struct hpgl_line_type_s {
int count;
hpgl_real_t gap[20];
} hpgl_line_type_t;
typedef struct hpgl_path_state_s {
gx_path path;
} hpgl_path_state_t;
/* Define rendering modes - character, polygon, or vector.
This affects the line attributes chosen (see
hpgl_set_graphics_line_attribute_state) and whether we use
stroke or fill on the path. */
typedef enum {
hpgl_rm_vector,
hpgl_rm_vector_no_close,
hpgl_rm_character,
hpgl_rm_polygon,
hpgl_rm_vector_fill,
hpgl_rm_clip_and_fill_polygon, /* for hpgl/2 line type filling */
hpgl_rm_nop /* don't do anything with the path. future use */
} hpgl_rendering_mode_t;
/* state of lost mode */
typedef enum {
hpgl_lost_mode_entered,
hpgl_lost_mode_cleared
} hpgl_lost_mode_t;
typedef enum {
hpgl_even_odd_rule,
hpgl_winding_number_rule
} hpgl_render_fill_type_t;
/* Define the structure for saving the pen state temporarily. */
/* HAS: note don't mix and match save a restores. perhaps there
should be a type check field in the structure. */
typedef struct hpgl_pen_state_s {
int relative_coords;
int move_or_draw;
gs_point pos;
} hpgl_pen_state_t;
/* Define the parameters for GL hatch/cross-hatch fill types. */
typedef struct hpgl_hatch_params_s {
float spacing;
float angle;
} hpgl_hatch_params_t;
/*
* Define the functions for adding points to paths. Note that the
* move/draw and absolute/relative alternatives can be tested, set, etc.
* individually.
*/
#define hpgl_plot_absolute 0
#define hpgl_plot_relative 1
#define hpgl_plot_is_absolute(func) (((func) & hpgl_plot_relative) == 0)
#define hpgl_plot_is_relative(func) (((func) & hpgl_plot_relative) != 0)
#define hpgl_plot_move 0
#define hpgl_plot_draw 2
#define hpgl_plot_is_move(func) (((func) & hpgl_plot_draw) == 0)
#define hpgl_plot_is_draw(func) (((func) & hpgl_plot_draw) != 0)
typedef enum {
hpgl_plot_move_absolute = hpgl_plot_move | hpgl_plot_absolute,
hpgl_plot_move_relative = hpgl_plot_move | hpgl_plot_relative,
hpgl_plot_draw_absolute = hpgl_plot_draw | hpgl_plot_absolute,
hpgl_plot_draw_relative = hpgl_plot_draw | hpgl_plot_relative
} hpgl_plot_function_t;
#define hpgl_plot_function_procedures\
gs_moveto, gs_rmoveto, gs_lineto, gs_rlineto
typedef struct pcl_hpgl_state_s {
/* Chapter 17 lost mode (pgmisc.c) */
/* According to PCLTRM IN, PG, RP and PA with args in range clears
lost mode. Note that all these commands have PA with valid args
as a side effect so only PA needs to clear lost mode. */
hpgl_lost_mode_t lost_mode;
/* Chapter 18 (pgframe.c) */
struct pf_ {
coord_point_t size;
coord_point_t anchor_point;
} picture_frame;
#define picture_frame_width picture_frame.size.x
#define picture_frame_height picture_frame.size.y
coord_point_t plot_size;
#define plot_width plot_size.x
#define plot_height plot_size.y
bool plot_size_vertical_specified;
bool plot_size_horizontal_specified;
/* Chapter 19 (pgconfig.c) */
enum {
hpgl_scaling_none = -1,
hpgl_scaling_anisotropic = 0,
hpgl_scaling_isotropic = 1,
hpgl_scaling_point_factor = 2
} scaling_type;
hpgl_scaling_params_t scaling_params;
struct soft_clip_window_ {
bool active; /* current unit window has be given,
if not use picture frame */
bool isbound; /* bound to plotter units */
gs_rect rect; /* clipping window (IW) */
} soft_clip_window;
int rotation;
gs_point P1, P2; /* in plotter units */
/* Chapter 20 (pgvector.c) */
int move_or_draw; /* hpgl_plot_move/draw */
int relative_coords; /* hpgl_plot_absolute/relative */
gs_point pos;
/* used to track the line drawing state in hpgl */
gs_point first_point;
/* Chapter 21 (pgpoly.c) */
struct polygon_ {
hpgl_path_state_t buffer; /* path for polygon buffer */
hpgl_pen_state_t pen_state; /* save pen state during polygon mode */
} polygon;
bool polygon_mode;
/* Chapter 22 (pglfill.c) */
struct lp_ {
struct ltl_ {
int type;
/* the offset value is not required by the gl/2
language, however we use it to implement offsetting
line patterns for hpgl/2 vector fills */
float pattern_offset;
float pattern_length;
bool pattern_length_relative;
bool is_solid;
gs_point pos;
} current, saved; /* enable saving for LT99 */
int cap;
int join;
} line;
float miter_limit;
struct pen_ {
bool width_relative;
int selected; /* currently selected pen # */
} pen;
byte symbol_mode; /* 0 if not in symbol mode */
struct ft_ {
hpgl_FT_pattern_source_t type;
/*
* Because each fill type remembers its previous parameter values,
* we must use a structure rather than a union here.
*/
struct fp_ {
hpgl_hatch_params_t hatch;
hpgl_hatch_params_t crosshatch;
int shading; /* 0..100 */
struct { int pattern_index; bool use_current_pen; } user_defined;
int pattern_type;
uint pattern_id;
} param;
} fill;
/* current bits of fraction for polyline encoded numbers */
int32 fraction_bits;
hpgl_render_fill_type_t fill_type;
hpgl_line_type_t fixed_line_type[8];
hpgl_line_type_t adaptive_line_type[8];
gs_point anchor_corner;
bool source_transparent;
struct scr_ {
hpgl_SV_pattern_source_t type;
struct sp_ {
int shading; /* 0..100 */
struct { int pattern_index; bool use_current_pen; } user_defined;
int pattern_type;
uint pattern_id;
} param;
} screen;
/* Temporary while downloading raster fill pattern */
struct rf_ {
int index, width, height;
uint raster;
byte *data;
bool is_mask;
} raster_fill;
/* Chapter 23 (pgchar.c, pglabel.c) */
pcl_font_selection_t font_selection[2];
int font_selected; /* 0 or 1 */
pl_font_t *font; /* 0 means recompute from params */
pl_symbol_map_t *map; /* map for current font */
pl_font_t stick_font[2][2]; /* stick/arc fonts */
struct ch_ {
gs_point direction;
bool direction_relative;
enum {
hpgl_text_right = 0,
hpgl_text_down = 1,
hpgl_text_left = 2,
hpgl_text_up = 3
} text_path;
#define hpgl_text_is_vertical(path) (((path) & 1) != 0)
int line_feed_direction; /* +1 = normal, -1 = reversed */
gs_point extra_space;
gs_point size;
enum {
hpgl_size_not_set,
hpgl_size_absolute,
hpgl_size_relative
} size_mode;
hpgl_real_t slant;
enum {
hpgl_char_solid_edge = 0,
hpgl_char_edge = 1,
hpgl_char_fill = 2,
hpgl_char_fill_edge = 3
} fill_mode;
int edge_pen; /* 0 = no edge */
} character;
struct lb_ {
int origin;
uint terminator;
bool print_terminator;
/* Double-byte support */
uint row_offset; /* implicit high byte */
bool double_byte;
bool write_vertical;
/*
* The following are only used during the execution of a
* single LB command, but since hpgl_LB may need to exit
* back to the parser for more data, we can't make them
* local variables of hpgl_LB.
*/
gs_point initial_pos;
#define hpgl_char_count 128 /* initial buffer size */
byte *buffer; /* start of line buffer pointer */
uint buffer_size; /* size of the current buffer */
uint char_count; /* count of chars in the buffer */
byte ch;
byte prev_ch;
bool have_16bits; /* two byte terminators need 16 bits */
} label;
bool transparent_data;
uint font_id[2];
bool bitmap_fonts_allowed;
gs_point carriage_return_pos;
/* extra pen state for routines that cannot use local variables
because of longjmp parser braindamage. */
hpgl_pen_state_t pen_state;
bool subpolygon_started; /* true if we are just starting a subpolygon */
bool have_drawn_in_path; /* true if the pen has been down during this path */
} pcl_hpgl_state_t;
#define hpgl_pen_relative (1)
#define hpgl_pen_down (1<<1)
#define hpgl_pen_pos (1<<2)
#define hpgl_pen_all (hpgl_pen_relative | hpgl_pen_down | hpgl_pen_pos)
#define hpgl_save_pen_state(pgls, save, save_flags)\
do {\
if ( (save_flags) & hpgl_pen_relative )\
((save)->relative_coords = (pgls)->g.relative_coords);\
if ( (save_flags) & hpgl_pen_down )\
((save)->move_or_draw = (pgls)->g.move_or_draw);\
if ( (save_flags) & hpgl_pen_pos )\
((save)->pos = (pgls)->g.pos);\
} while (0)
#define hpgl_restore_pen_state(pgls, save, restore_flags)\
do {\
if ( (restore_flags) & hpgl_pen_relative )\
((pgls)->g.relative_coords = (save)->relative_coords);\
if ( (restore_flags) & hpgl_pen_down )\
((pgls)->g.move_or_draw = (save)->move_or_draw);\
if ( (restore_flags) & hpgl_pen_pos )\
((pgls)->g.pos = (save)->pos);\
} while (0)
/* check if current units are within the so-called "functional range"
defined to be -2^30 to 2^30 - 1 */
bool current_units_out_of_range(hpgl_real_t x);
#endif /* pgstate_INCLUDED */
|