Coverage Report

Created: 2026-04-09 07:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ghostpdl/pcl/pcl/pcstate.h
Line
Count
Source
1
/* Copyright (C) 2001-2024 Artifex Software, Inc.
2
   All Rights Reserved.
3
4
   This software is provided AS-IS with no warranty, either express or
5
   implied.
6
7
   This software is distributed under license and may not be copied,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
13
   CA 94129, USA, for further information.
14
*/
15
16
17
/* pcstate.h - Definition of PCL5 state */
18
19
#ifndef pcstate_INCLUDED
20
#  define pcstate_INCLUDED
21
22
#include "gx.h"
23
#include "gxdevice.h"
24
#include "scommon.h"
25
#include "gscspace.h"
26
#include "gscolor2.h"
27
#include "gscrd.h"
28
#include "gsdcolor.h"           /* for gx_ht_tile */
29
#include "gschar.h"
30
#include "pldict.h"
31
#include "plfont.h"
32
33
/* various components of the state structure */
34
#include "pccoord.h"            /* centi-point coordinate system */
35
#include "pcxfmst.h"            /* geometric transformation information */
36
#include "pcfontst.h"           /* font selection information */
37
#include "pctpm.h"              /* text parsing method information */
38
#include "pcpattyp.h"           /* pattern related structures */
39
#include "pcdict.h"             /* PL dictionary key structure */
40
#include "rtrstst.h"            /* raster state information */
41
#include "pcht.h"
42
#include "pcident.h"
43
#include "pccsbase.h"
44
45
                                /*#include "pgstate.h"*//* HP-GL/2 state, included below */
46
#include "pjtop.h"
47
#include "gsgstate.h"
48
49
/* type for string id's */
50
typedef struct pcl_string_id_s
51
{
52
    byte *id;
53
    int size;
54
} alphanumeric_string_id_t;
55
56
/* type for current state of id's, string or regular id's macros */
57
typedef enum id_type_enum
58
{
59
    string_id,
60
    numeric_id
61
} id_type_t;
62
63
/* define different language personalities for dynamic configuration */
64
typedef enum personality_enum
65
{                               /* NB  document */
66
    pcl5c,
67
    pcl5e,
68
    rtl,
69
    hpgl
70
} pcl_personality_t;
71
72
/*
73
 * Palette stack. This is implemented as a simple linked list.  NB
74
 * needs to be moved.
75
 */
76
typedef struct pstack_entry_s
77
{
78
    struct pstack_entry_s *pnext;
79
    pcl_palette_t *ppalet;
80
} pstack_entry_t;
81
82
#ifndef pcl_state_DEFINED
83
#  define pcl_state_DEFINED
84
typedef struct pcl_state_s pcl_state_t;
85
#endif
86
87
/*
88
 * The routines pcl_gsave and pcl_grestore should be used instead of
89
 * gs_gsave and gs_grestore. See the comment in pcdraw.c for details.
90
 *
91
 * The routine pcl_init_gstate_stk must be called once a boot time to
92
 * intialize PCL graphics state stack tracking mechanism.
93
 */
94
int pcl_gsave(pcl_state_t * pcs);
95
96
int pcl_grestore(pcl_state_t * pcs);
97
98
void pcl_init_gstate_stk(pcl_state_t * pcs);
99
100
void pcl_free_gstate_stk(pcl_state_t * pcs);
101
102
/*
103
 * "Cold start" initialization for the graphic state.
104
 */
105
void pcl_init_state(pcl_state_t * pcs, gs_memory_t * pmem);
106
107
#include "pgstate.h"            /* HP-GL/2 state */
108
109
#ifndef pcl_pattern_data_DEFINED
110
#define pcl_ht_builtin_dither_DEFINED
111
typedef struct pcl_pattern_t pcl_pattern;
112
#endif
113
114
#ifndef pcl_cs_indexed_DEFINED
115
#define pcl_cs_indexed_DEFINED
116
typedef struct pcl_cs_indexed_s pcl_cs_indexed_t;
117
#endif
118
119
/*
120
 * Define the entire PCL/HPGL state.  The documentation for this is spread
121
 * out over the PCL reference manuals, and is incomplete, inconsistent, and
122
 * poorly organized.  In order to have a ghost (:-)) of a chance of being
123
 * able to think about it as a whole, we've organized it here by
124
 * documentation chapter, just as we did the .c files.
125
 *
126
 * NB: If you modify this structure, be sure to also modify the routine
127
 *     pcl_init_state in pcommand.c.
128
 */
129
struct pcl_state_s
130
{
131
132
    gs_memory_t *memory;
133
134
    /* hook back to client data, for callback procedures */
135
    void *client_data;
136
137
    /* graphics state */
138
    gs_gstate *pgs;
139
140
    /* Define an optional procedure for parsing non-ESC data. */
141
    int (*parse_other) (void *parse_data,
142
                        pcl_state_t * pcs, stream_cursor_read * pr);
143
    void *parse_data;           /* closure data for parse_other */
144
145
    /* Chapter 4 (pcjob.c) */
146
    int num_copies;             /* (also a device parameter) */
147
    bool duplex;                /* (also a device parameter) */
148
    bool bind_short_edge;       /* (also a device parameter) */
149
    bool back_side;             /* (also a device parameter) */
150
    int output_bin;             /* (also a device parameter) */
151
    coord uom_cp;               /* centipoints per PCL unit */
152
153
    /* Chapter 5 (pcpage.c) */
154
    int paper_source;
155
    int perforation_skip;
156
    pcl_margins_t margins;      /* relative to print_direction */
157
    pcl_xfm_state_t xfm_state;
158
159
    /* Chapter 6 (pcursor.c) */
160
    coord hmi_cp;
161
    coord vmi_cp;
162
    int line_termination;
163
    coord_point_t cap;
164
    gs_point cursor_stk[20];
165
    int cursor_stk_size;
166
167
    /* Chapter 8 (pcfont.c) */
168
    pcl_font_selection_t font_selection[2];
169
    enum
170
    {
171
        primary = 0,
172
        secondary = 1
173
    } font_selected;
174
    pl_font_t *font;            /* 0 means recompute from params */
175
    pl_dict_t built_in_fonts;   /* "built-in", known at start-up */
176
177
    /* Internal variables */
178
    gs_font_dir *font_dir;      /* gs-level dictionary of fonts */
179
    pl_symbol_map_t *map;       /* map for current font (above) */
180
181
    /* more Chapter 8 (pctext.c) */
182
    bool underline_enabled;
183
    bool underline_floating;
184
    float underline_position;   /* distance from baseline */
185
186
    pcl_text_parsing_method_t text_parsing_method;
187
188
    int text_path;              /* 0, 1, -1 */
189
190
    /* Internal variables */
191
    float last_width;           /* escapement of last char (for BS) */
192
    coord_point_t underline_start;      /* start point of underline */
193
    bool last_was_BS;           /* no printable chars since last BS */
194
195
    /* Chapter 10 (pcsymbol.c) */
196
    pcl_id_t symbol_set_id;
197
    pl_dict_t soft_symbol_sets;
198
    pl_dict_t built_in_symbol_sets;
199
    pl_dict_t simm_fonts;
200
    pl_dict_t cartridge_fonts;
201
    int default_symbol_set_value;
202
203
    /* Chapter 9 & 11 (pcsfont.c) */
204
    pcl_id_t font_id;
205
    uint character_code;
206
    pl_dict_t soft_fonts;
207
    uint soft_font_count;
208
    byte *soft_font_char_data;
209
    /* PCL comparison guide - alphanumeric string id */
210
    alphanumeric_string_id_t alpha_font_id;
211
    id_type_t font_id_type;
212
213
214
0
#define CURRENT_FONT_STRING_ID (pcs->alpha_font_id.id)
215
#define CURRENT_FONT_ID                                                 \
216
245
    ( ((pcs->font_id_type == string_id) ? CURRENT_FONT_STRING_ID        \
217
245
                                         : (id_key(pcs->font_id))) )
218
219
0
#define CURRENT_FONT_STRING_ID_SIZE (pcs->alpha_font_id.size)
220
#define CURRENT_FONT_ID_SIZE                                                  \
221
245
    ( ((pcs->font_id_type == string_id) ? CURRENT_FONT_STRING_ID_SIZE : (2)) )
222
223
    /* Chapter 12 (pcmacros.c) */
224
    pcl_id_t macro_id;
225
    pcl_id_t overlay_macro_id;
226
    bool overlay_enabled;
227
    int macro_level;
228
    pl_dict_t macros;
229
230
    bool defining_macro;
231
    pcl_state_t *saved;         /* saved state during execute/call/overlay */
232
233
    /* Internal variables */
234
    byte *macro_definition;     /* for macro being defined, if any */
235
    alphanumeric_string_id_t alpha_macro_id;
236
    id_type_t macro_id_type;
237
238
0
#define CURRENT_MACRO_STRING_ID (pcs->alpha_macro_id.id)
239
#define CURRENT_MACRO_ID                                                \
240
0
    ( ((pcs->macro_id_type == string_id) ? CURRENT_MACRO_STRING_ID   \
241
0
                                          : (id_key(pcs->macro_id))) )
242
243
0
#define CURRENT_MACRO_STRING_ID_SIZE (pcs->alpha_macro_id.size)
244
#define CURRENT_MACRO_ID_SIZE                                                   \
245
0
    ( ((pcs->macro_id_type == string_id) ? CURRENT_MACRO_STRING_ID_SIZE : (2)) )
246
247
    /* Chapter 13 (pcprint.c) */
248
    gs_point pat_ref_pt;        /* active pattern reference point,
249
                                 * in device space */
250
251
    int pat_orient;             /* current pattern orientation */
252
    int pattern_id;
253
    int current_pattern_id;
254
    pcl_pattern_source_t pattern_type;  /* current source for PCL patterns */
255
    gs_point pcl_pat_ref_pt;    /* PCL's pattern reference point */
256
    pl_dict_t pcl_patterns;     /* dictionaries to hold pcl and gl/2 patterns */
257
    pl_dict_t gl_patterns;
258
#define PCL_NUM_SHADE_PATTERNS (7)      /* pcl support 7 shades of gray */
259
#define PCL_NUM_CROSSHATCH_PATTERNS (6) /* and 6 cross hatch patterns */
260
    pcl_pattern *bi_pattern_array[PCL_NUM_SHADE_PATTERNS +
261
                                  PCL_NUM_CROSSHATCH_PATTERNS];
262
    int last_pcl_uptrn_id;      /* optimizations for recording last patter */
263
    pcl_pattern *plast_pcl_uptrn;       /* and pattern id */
264
    int last_gl2_RF_indx;
265
    pcl_pattern *plast_gl2_uptrn;
266
    pcl_pattern *psolid_pattern;        /* see documentation in pcbiptrn.c for these two */
267
    pcl_pattern *punsolid_pattern;
268
    bool rotate_patterns;       /* rotate patterns with print direction in PCL */
269
    bool source_transparent;    /* (also in graphics state) */
270
    bool pattern_transparent;   /* (also in graphics state);
271
                                 * PCL and GL/2 set this
272
                                 * independenty; for GL/2 it is
273
                                 * known as source transparent */
274
    bool pcl_pattern_transparent;
275
276
    /* Chapter 14 (pcrect.c) */
277
    coord_point_t rectangle;
278
279
    /* Chapter 15 &  Chapter C6 (pcgmode.c) */
280
    pcl_raster_state_t raster_state;
281
282
    /* Chapter 16 (pcstatus.c) */
283
    int location_type;
284
    int location_unit;
285
    struct _sb
286
    {
287
        byte internal_buffer[80];       /* enough for an error message */
288
        byte *buffer;
289
        uint write_pos;
290
        uint read_pos;
291
    } status;
292
293
    /* Chapter 24 (pcmisc.c) */
294
    bool end_of_line_wrap;
295
    bool display_functions;
296
    int (*configure_appletalk) (const byte * key,
297
                                uint key_length,
298
                                const byte * value, uint value_length);
299
300
    /* Chapter C2/C3/C4 (pcpalet.c/pcindexed.c/pccsbase.c/etc.) */
301
    int sel_palette_id;
302
    int ctrl_palette_id;
303
    int monochrome_mode;        /* 0=off */
304
    int render_mode;            /* raw (unmapped) render algorithm */
305
    pcl_palette_t *ppalet;
306
    pcl_gsid_t next_id;         /* id's for palette's and foreground
307
                                   colors see pcident.h */
308
    pcl_frgrnd_t *pfrgrnd;
309
    pcl_gsid_t frgnd_cache_id;
310
311
    pcl_gstate_ids_t *pids;
312
313
    /* internal dithers */
314
    pcl_ht_builtin_dither_t ordered_dither;
315
    pcl_ht_builtin_dither_t clustered_dither;
316
    pcl_ht_builtin_dither_t noise_dither;
317
    /*
318
     * The forwarding devices to preform any necessary color mapping. There are
319
     * four of these: identity mapping, snap to primaries, map black to white and
320
     * all other colors to black, and monochrome mapping. The devices are all
321
     * identical except for the mapping method used.
322
     *
323
     * Several devices are required because the rendering method used by the
324
     * foreground may not be the same as that used by the current palette.
325
     */
326
    gs_cie_transform_proc3 dflt_TransformPQR;   /* default transform PQR */
327
    pcl_rend_info_t rendering_info[20]; /* rendering methods */
328
    byte dflt_rendering_remap[20];      /* NB not convinced this is necessary (review) */
329
    byte rendering_remap[20];   /* remap the table of rendering methods */
330
    pcl_ht_t *pdflt_ht;         /* default halftone */
331
    pcl_cs_indexed_t *pdflt_cs_indexed;
332
    pcl_cid_data_t dflt_cid_data;
333
    pcl_cs_base_t *pwhite_cs;
334
    pcl_frgrnd_t *pdflt_frgrnd;
335
    pstack_entry_t *palette_stack;
336
    pcl_palette_t *pdflt_palette;       /* default palette */
337
    pl_dict_t palette_store;    /* dictionary to hold the palette store */
338
    float color_comps[3];
339
    /* Chapter C5 (pccprint.c) */
340
    byte logical_op;            /* (also in graphics state) */
341
    byte pp_mode;               /* pixel placement mode */
342
    /* ---------------- HP-GL/2 state ---------------- */
343
    pcl_hpgl_state_t g;         /* see pgstate.h */
344
    /* ---------------- PJL state -------------------- */
345
    pl_interp_implementation_t *pjls;
346
    /* we need a separate PJL number for downloaded fonts. PJL
347
       numbers for internal fonts are defined statically in the font
348
       table. */
349
    int pjl_dlfont_number;
350
    /* ---------------- page size table -------------- */
351
    pcl_paper_type_t *ppaper_type_table;
352
    /* yet another poorly documented pjl variable - this should widen
353
       the margins on A4 paper to support 80 10 pitch characters but
354
       it appears to affect letter paper as well */
355
    bool wide_a4;
356
357
    /* the current language personality */
358
    pcl_personality_t personality;
359
360
    /* enable image interpolation */
361
    bool interpolate;
362
363
    /* disable the font cache */
364
    bool nocache;
365
366
    /* store a pointer to the command definitions for use by macros */
367
    void *pcl_commands;
368
369
    /* indicates page has been written to with a drawing command */
370
    bool page_marked;
371
    /* indicates that the cursor has been moved */
372
    bool cursor_moved;
373
374
    /* end page procedure to use */
375
    int (*end_page) (pcl_state_t * pcs, int num_copies, int flush);
376
377
    bool halftone_set;
378
    bool page_set_on_command_line;
379
    bool res_set_on_command_line;
380
    bool high_level_device;
381
    bool supports_rasterops;
382
    /* last entry mode to hpgl/2 */
383
    int hpgl_mode;
384
    int scanconverter;
385
};
386
387
static inline int check_rasterops(pcl_state_t * pcs, byte op)
388
13.4M
{
389
    /* 252 here is a magic number. It is the default state of RasterOPs which appears to be
390
     * fully opaque. Since it's the default, and that seems to work, permit it to be set.
391
     */
392
13.4M
    if (pcs->high_level_device && !pcs->supports_rasterops && op != 252) {
393
0
        errprintf(pcs->memory, "Unsupported use of RasterOP %d detected. Output may not be correct.\n", op);
394
0
        return_error(gs_error_undefined);
395
0
    }
396
13.4M
    return 0;
397
13.4M
}
Unexecuted instantiation: pctop.c:check_rasterops
Unexecuted instantiation: pxtop.c:check_rasterops
Unexecuted instantiation: pxerrors.c:check_rasterops
Unexecuted instantiation: pxparse.c:check_rasterops
Unexecuted instantiation: pxstate.c:check_rasterops
Unexecuted instantiation: pxptable.c:check_rasterops
Unexecuted instantiation: pxpthr.c:check_rasterops
Unexecuted instantiation: pxfont.c:check_rasterops
Unexecuted instantiation: pxgstate.c:check_rasterops
Unexecuted instantiation: pximage.c:check_rasterops
Unexecuted instantiation: pxink.c:check_rasterops
Unexecuted instantiation: pxpaint.c:check_rasterops
Unexecuted instantiation: pxsessio.c:check_rasterops
Unexecuted instantiation: pxstream.c:check_rasterops
Unexecuted instantiation: pccprint.c:check_rasterops
Unexecuted instantiation: pcjob.c:check_rasterops
Unexecuted instantiation: pcpage.c:check_rasterops
Unexecuted instantiation: pcursor.c:check_rasterops
Unexecuted instantiation: pcfont.c:check_rasterops
pctext.c:check_rasterops
Line
Count
Source
388
14.9k
{
389
    /* 252 here is a magic number. It is the default state of RasterOPs which appears to be
390
     * fully opaque. Since it's the default, and that seems to work, permit it to be set.
391
     */
392
14.9k
    if (pcs->high_level_device && !pcs->supports_rasterops && op != 252) {
393
0
        errprintf(pcs->memory, "Unsupported use of RasterOP %d detected. Output may not be correct.\n", op);
394
0
        return_error(gs_error_undefined);
395
0
    }
396
14.9k
    return 0;
397
14.9k
}
Unexecuted instantiation: pcsymbol.c:check_rasterops
Unexecuted instantiation: pcsfont.c:check_rasterops
Unexecuted instantiation: pcmacros.c:check_rasterops
Unexecuted instantiation: pcrect.c:check_rasterops
Unexecuted instantiation: pcstatus.c:check_rasterops
Unexecuted instantiation: pcmisc.c:check_rasterops
Unexecuted instantiation: pcfontpg.c:check_rasterops
Unexecuted instantiation: rtmisc.c:check_rasterops
Unexecuted instantiation: rtraster.c:check_rasterops
Unexecuted instantiation: pcommand.c:check_rasterops
Unexecuted instantiation: pcparse.c:check_rasterops
pcdraw.c:check_rasterops
Line
Count
Source
388
11.6M
{
389
    /* 252 here is a magic number. It is the default state of RasterOPs which appears to be
390
     * fully opaque. Since it's the default, and that seems to work, permit it to be set.
391
     */
392
11.6M
    if (pcs->high_level_device && !pcs->supports_rasterops && op != 252) {
393
0
        errprintf(pcs->memory, "Unsupported use of RasterOP %d detected. Output may not be correct.\n", op);
394
0
        return_error(gs_error_undefined);
395
0
    }
396
11.6M
    return 0;
397
11.6M
}
Unexecuted instantiation: pcbiptrn.c:check_rasterops
Unexecuted instantiation: pccid.c:check_rasterops
Unexecuted instantiation: pccolor.c:check_rasterops
Unexecuted instantiation: pccsbase.c:check_rasterops
Unexecuted instantiation: pcdither.c:check_rasterops
Unexecuted instantiation: pcfrgrnd.c:check_rasterops
Unexecuted instantiation: pcht.c:check_rasterops
Unexecuted instantiation: pcident.c:check_rasterops
Unexecuted instantiation: pcindxed.c:check_rasterops
Unexecuted instantiation: pclookup.c:check_rasterops
Unexecuted instantiation: pcpalet.c:check_rasterops
Unexecuted instantiation: pcpatrn.c:check_rasterops
Unexecuted instantiation: pcpatxfm.c:check_rasterops
Unexecuted instantiation: pcuptrn.c:check_rasterops
Unexecuted instantiation: pcwhtidx.c:check_rasterops
Unexecuted instantiation: rtgmode.c:check_rasterops
Unexecuted instantiation: rtrstcmp.c:check_rasterops
Unexecuted instantiation: pgcolor.c:check_rasterops
pgdraw.c:check_rasterops
Line
Count
Source
388
1.79M
{
389
    /* 252 here is a magic number. It is the default state of RasterOPs which appears to be
390
     * fully opaque. Since it's the default, and that seems to work, permit it to be set.
391
     */
392
1.79M
    if (pcs->high_level_device && !pcs->supports_rasterops && op != 252) {
393
0
        errprintf(pcs->memory, "Unsupported use of RasterOP %d detected. Output may not be correct.\n", op);
394
0
        return_error(gs_error_undefined);
395
0
    }
396
1.79M
    return 0;
397
1.79M
}
Unexecuted instantiation: pginit.c:check_rasterops
Unexecuted instantiation: pgparse.c:check_rasterops
Unexecuted instantiation: pgmisc.c:check_rasterops
Unexecuted instantiation: pgframe.c:check_rasterops
Unexecuted instantiation: pgconfig.c:check_rasterops
Unexecuted instantiation: pgvector.c:check_rasterops
Unexecuted instantiation: pgpoly.c:check_rasterops
Unexecuted instantiation: pglfill.c:check_rasterops
Unexecuted instantiation: pgchar.c:check_rasterops
Unexecuted instantiation: pglabel.c:check_rasterops
Unexecuted instantiation: pgfont.c:check_rasterops
Unexecuted instantiation: pxffont.c:check_rasterops
Unexecuted instantiation: pcfsel.c:check_rasterops
Unexecuted instantiation: pgfdata.c:check_rasterops
398
399
/* accessor functions for the pcl target device.  These live in
400
   pctop.c for now */
401
int pcl_load_cartridge_fonts(pcl_state_t * pcs, const char *pathname);
402
403
int pcl_load_simm_fonts(pcl_state_t * pcs, const char *pathname);
404
405
int pcl_load_built_in_fonts(pcl_state_t * pcs, const char *pathname);
406
407
/* implicitly exit gl/2 whenever ESC E is found */
408
int pcl_implicit_gl2_finish(pcl_state_t * pcs);
409
410
int pcl_do_printer_reset(pcl_state_t * pcs);
411
412
int pcl_end_page_top(pcl_state_t * pcs, int num_copies, int flush);
413
414
/* exported from pcl to support PCL XL pass through mode */
415
bool pcl_downloaded_and_bound(const pl_font_t * plfont);
416
417
void pcl_font_scale(pcl_state_t *, gs_point * psz);
418
419
/* exported from pcl to support HPGL label */
420
bool char_is_printable(const pl_font_t *font, const pl_symbol_map_t *map, gs_char chr, bool is_stick, bool literal);
421
422
#endif /* pcstate_INCLUDED */