diff options
55 files changed, 653 insertions, 688 deletions
diff --git a/pcl/pccid.c b/pcl/pccid.c index 1b0ea9c34..90b933f65 100644 --- a/pcl/pccid.c +++ b/pcl/pccid.c @@ -429,7 +429,8 @@ pcl_cid_IN( * code, as reset is handled at the palette level. */ private int -pcl_cid_do_init( +pcl_cid_do_registration( + pcl_parser_state_t *pcl_parser_state, gs_memory_t * pmem ) { @@ -450,4 +451,4 @@ pcl_cid_do_init( return 0; } -const pcl_init_t pcl_cid_init = { pcl_cid_do_init, 0, 0 }; +const pcl_init_t pcl_cid_init = { pcl_cid_do_registration, 0, 0 }; diff --git a/pcl/pccolor.c b/pcl/pccolor.c index 01498cc4e..6b161798d 100644 --- a/pcl/pccolor.c +++ b/pcl/pccolor.c @@ -21,7 +21,6 @@ * mode (i.e.: they do NOT end graphics mode, as one would expect from the * documentation). */ -private float color_comps[3]; /* * ESC * v <cc> A @@ -33,7 +32,7 @@ set_color_comp_1( ) { if (!pcs->raster_state.graphics_mode) - color_comps[0] = float_arg(pargs); + pcs->color_comps[0] = float_arg(pargs); return 0; } @@ -47,7 +46,7 @@ set_color_comp_2( ) { if (!pcs->raster_state.graphics_mode) - color_comps[1] = float_arg(pargs); + pcs->color_comps[1] = float_arg(pargs); return 0; } @@ -61,7 +60,7 @@ set_color_comp_3( ) { if (!pcs->raster_state.graphics_mode) - color_comps[2] = float_arg(pargs); + pcs->color_comps[2] = float_arg(pargs); return 0; } @@ -87,10 +86,10 @@ assign_color_index( if (!pcs->raster_state.graphics_mode) { if ((indx >= 0) && (indx < pcl_palette_get_num_entries(pcs->ppalet))) - pcl_palette_set_color(pcs, indx, color_comps); - color_comps[0] = 0.0; - color_comps[1] = 0.0; - color_comps[2] = 0.0; + pcl_palette_set_color(pcs, indx, pcs->color_comps); + pcs->color_comps[0] = 0.0; + pcs->color_comps[1] = 0.0; + pcs->color_comps[2] = 0.0; } return 0; } @@ -99,8 +98,9 @@ assign_color_index( * Initialization */ private int -color_do_init( - gs_memory_t * mem +color_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t * pmem ) { /* Register commands */ @@ -151,9 +151,9 @@ color_do_reset( | pcl_reset_printer ); if ((type & mask) != 0) { - color_comps[0] = 0.0; - color_comps[1] = 0.0; - color_comps[2] = 0.0; + pcs->color_comps[0] = 0.0; + pcs->color_comps[1] = 0.0; + pcs->color_comps[2] = 0.0; } } @@ -161,4 +161,4 @@ color_do_reset( * There is no copy operation for this module, as the color components are * just globals. */ -const pcl_init_t pcl_color_init = { color_do_init, color_do_reset, 0 }; +const pcl_init_t pcl_color_init = { color_do_registration, color_do_reset, 0 }; diff --git a/pcl/pccprint.c b/pcl/pccprint.c index c834d5f9d..e20b3f4ca 100644 --- a/pcl/pccprint.c +++ b/pcl/pccprint.c @@ -59,8 +59,9 @@ pcl_pixel_placement( * Initialization */ private int -pccprint_do_init( - gs_memory_t * mem +pccprint_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t * pmem ) { /* Register commands */ @@ -99,4 +100,4 @@ pccprint_do_reset( } } -const pcl_init_t pccprint_init = { pccprint_do_init, pccprint_do_reset, 0 }; +const pcl_init_t pccprint_init = { pccprint_do_registration, pccprint_do_reset, 0 }; diff --git a/pcl/pccrd.c b/pcl/pccrd.c index 63cd9453a..91d0d9267 100644 --- a/pcl/pccrd.c +++ b/pcl/pccrd.c @@ -24,19 +24,6 @@ private_st_crd_t(); /* - * Unlike other elements of the PCL "palette", color rendering dictionaries - * are for the most part not a feature that can be controlled from the language. - * Except for the white point, the parameters of a color rendering dictionary - * are determined by the output device rather than the language. - * - * To accommodate this situation, the device-specific or default color - * rendering dictionary is maintained as a global. When used as part of a - * palette, this global should be "copied" using the copy_from macro provided - * below. - */ -pcl_crd_t * pcl_default_crd; - -/* * The default color rendering information. This works for a monitor that * uses linear SMPTE-C phosphors. This is almost certainly not the case for * any actual printing device, but the approximation will do for now. @@ -67,13 +54,6 @@ private const gs_matrix3 dflt_MatrixLMN = { { 3.51, -1.07, 0.06 }, * which accepts the the component index as an operand. Rather than returning * the mapped value, the location pointed to by pnew_val is used to hold the * result and a success (0) or error (< 0) indication is returned. - * - * The final field of the TransformPQR data structure must be writable, so - * that the driver can insert its own name in this location. To support - * environements in which all initialized globals are in ROM, two copies - * of this structure are maintained: a prototype (qualified as const) and - * the actual value. The former is copied into the latter each time a CRD - * using this structure is created. */ private int dflt_TransformPQR_proc( @@ -98,9 +78,6 @@ private const gs_cie_transform_proc3 dflt_TransformPQR_proto = { NULL }; -private gs_cie_transform_proc3 dflt_TransformPQR; - - /* * Free a PCL color rendering dictionary structure. */ @@ -229,7 +206,7 @@ pcl_crd_build_default_crd( pcl_state_t * pcs ) { - pcl_crd_t * pcrd = pcl_default_crd; + pcl_crd_t * pcrd = pcs->pcl_default_crd; int code = 0; /* must not be a current CRD */ @@ -239,19 +216,19 @@ pcl_crd_build_default_crd( /* allocate the CRD structure */ if ((code = alloc_crd(&pcrd, pcs->memory)) < 0) return code; - pcl_default_crd = pcrd; + pcs->pcl_default_crd = pcrd; if (read_device_CRD(pcrd, pcs)) return 0; else { - dflt_TransformPQR = dflt_TransformPQR_proto; + pcs->dflt_TransformPQR = dflt_TransformPQR_proto; return gs_cie_render1_initialize( pcrd->pgscrd, NULL, &dflt_WhitePoint, NULL, NULL, NULL, - &dflt_TransformPQR, + &pcs->dflt_TransformPQR, &dflt_MatrixLMN, NULL, NULL, @@ -264,63 +241,6 @@ pcl_crd_build_default_crd( } /* - * Build a CRD with device-provided parameters, but with the default PCL - * white point. - * - * Note that this is one of the few routines which accepts a memory pointer - * operand but does not have it as the last operand. - * - * Any operands set to NULL will be given their graphic library defaults - * (which may not be the same as their values in the default PCL CRD). - * - * Returns 0 on success, < 0 in the event of an error. - */ - int -pcl_crd_build_dev_crd( - gs_memory_t * pmem, - const gs_vector3 * BlackPoint, - const gs_matrix3 * MatrixPQR, - const gs_range3 * RangePQR, - const gs_cie_transform_proc3 * TransformPQR, - const gs_matrix3 * MatrixLMN, - const gs_cie_render_proc3 * EncodeLMN, - const gs_range3 * RangeLMN, - const gs_matrix3 * MatrixABC, - const gs_cie_render_proc3 * EncodeABC, - const gs_range3 * RangeABC, - const gs_cie_render_table_t * RenderTable -) -{ - pcl_crd_t * pcrd = pcl_default_crd; - int code = 0; - - /* release any existing CRD */ - if (pcrd != 0) - rc_decrement(pcrd, "pcl build device specific CRD"); - - /* allocate the CRD structure */ - if ((code = alloc_crd(&pcrd, pmem)) < 0) - return code; - - pcl_default_crd = pcrd; - return gs_cie_render1_initialize( pcrd->pgscrd, - NULL, /* for now */ - &dflt_WhitePoint, - BlackPoint, - MatrixPQR, - RangePQR, - TransformPQR, - MatrixLMN, - EncodeLMN, - RangeLMN, - MatrixABC, - EncodeABC, - RangeABC, - RenderTable - ); -} - -/* * Set the viewing illuminant. * * Though this code goes through the motions of an "unshare" operation, it @@ -331,6 +251,7 @@ pcl_crd_build_dev_crd( */ int pcl_crd_set_view_illuminant( + pcl_state_t * pcs, pcl_crd_t ** ppcrd, const gs_vector3 * pwht_pt ) @@ -348,14 +269,14 @@ pcl_crd_set_view_illuminant( /* if no previous CRD, use the default settings */ if (pold == 0) { - dflt_TransformPQR = dflt_TransformPQR_proto; + pcs->dflt_TransformPQR = dflt_TransformPQR_proto; return gs_cie_render1_initialize( pcrd->pgscrd, NULL, pwht_pt, NULL, NULL, NULL, - &dflt_TransformPQR, + &pcs->dflt_TransformPQR, &dflt_MatrixLMN, NULL, NULL, @@ -403,10 +324,10 @@ pcl_crd_set_crd( int code = 0; if (pcrd == 0) { - if ( (pcl_default_crd == 0) && + if ( (pcs->pcl_default_crd == 0) && ((code = pcl_crd_build_default_crd(pcs)) < 0) ) return code; - pcrd = pcl_default_crd; + pcrd = pcs->pcl_default_crd; pcl_crd_init_from(*ppcrd, pcrd); } diff --git a/pcl/pccrd.h b/pcl/pccrd.h index 779f3bccc..6b1815893 100644 --- a/pcl/pccrd.h +++ b/pcl/pccrd.h @@ -107,33 +107,6 @@ extern pcl_crd_t * pcl_default_crd; int pcl_crd_build_default_crd(P1(pcl_state_t *pcs)); /* - * Build a CRD with device-provided parameters, but with the default PCL - * white point. - * - * Note that this is one of the few routines which accept a memory pointer - * operand but does not have it as the last operand. - * - * Any operands set to NULL will be given their graphic library defaults - * (which may not be the same as their values in the default PCL CRD). - * - * Returns 0 on success, < 0 in the event of an error. - */ -int pcl_crd_build_dev_crd(P12( - gs_memory_t * pmem, - const gs_vector3 * BlackPoint, - const gs_matrix3 * MatrixPQR, - const gs_range3 * RangePQR, - const gs_cie_transform_proc3 * TransformPQR, - const gs_matrix3 * MatrixLMN, - const gs_cie_render_proc3 * EncodeLMN, - const gs_range3 * RangeLMN, - const gs_matrix3 * MatrixABC, - const gs_cie_render_proc3 * EncodeABC, - const gs_range3 * RangeABC, - const gs_cie_render_table_t * RenderTable -)); - -/* * Set the viewing illuminant. * * Though this code goes through the motions of an "unshare" operation, it @@ -142,7 +115,8 @@ int pcl_crd_build_dev_crd(P12( * * Returns 0 on success, < 0 in the event of an error. */ -int pcl_crd_set_view_illuminant(P2( +int pcl_crd_set_view_illuminant(P3( + pcl_state_t * pcs, pcl_crd_t ** ppcrd, const gs_vector3 * pwht_pt )); diff --git a/pcl/pccsbase.c b/pcl/pccsbase.c index aa0e24e94..9d39a65a7 100644 --- a/pcl/pccsbase.c +++ b/pcl/pccsbase.c @@ -15,14 +15,11 @@ #include "gscie.h" #include "pcmtx3.h" #include "pccsbase.h" +#include "pcstate.h" /* GC routines */ private_st_cs_base_t(); -/* a special "white" color space */ -private pcl_cs_base_t * pwhite_cs; - - /* * Handle min/max values for device-independent color spaces. * @@ -1083,16 +1080,17 @@ pcl_cs_base_build_cspace( */ int pcl_cs_base_build_white_cspace( + pcl_state_t * pcs, pcl_cs_base_t ** ppbase, gs_memory_t * pmem ) { int code = 0; - if (pwhite_cs == 0) - code = alloc_base_cspace(&pwhite_cs, pcl_cspace_White, pmem); + if (pcs->pwhite_cs == 0) + code = alloc_base_cspace(&pcs->pwhite_cs, pcl_cspace_White, pmem); if (code >= 0) - pcl_cs_base_copy_from(*ppbase, pwhite_cs); + pcl_cs_base_copy_from(*ppbase, pcs->pwhite_cs); return code; } @@ -1185,7 +1183,7 @@ pcl_cs_base_install( * initialization of BSS. */ void -pcl_cs_base_init(void) +pcl_cs_base_init(pcl_state_t *pcs) { - pwhite_cs = 0; + pcs->pwhite_cs = 0; } diff --git a/pcl/pccsbase.h b/pcl/pccsbase.h index bf7938a79..ffd34eb72 100644 --- a/pcl/pccsbase.h +++ b/pcl/pccsbase.h @@ -12,7 +12,6 @@ #include "gsrefct.h" #include "gscspace.h" #include "pcident.h" -#include "pcstate.h" #include "pcommand.h" #include "pccid.h" #include "pclookup.h" @@ -119,7 +118,8 @@ int pcl_cs_base_build_cspace(P3( * * This routine is usually called once at initialization. */ -int pcl_cs_base_build_white_cspace(P2( +int pcl_cs_base_build_white_cspace(P3( + pcl_state_t * pcs, pcl_cs_base_t ** ppbase, gs_memory_t * pmem )); @@ -159,6 +159,6 @@ int pcl_cs_base_install(P2( * One-time initialization routine. This exists only to handle possible non- * initialization of BSS. */ -void pcl_cs_base_init( void ); +void pcl_cs_base_init(P1(pcl_state_t *pcs)); #endif /* pccsbase_INCLUDED */ diff --git a/pcl/pcdither.c b/pcl/pcdither.c index 7dd70317b..7efd15346 100644 --- a/pcl/pcdither.c +++ b/pcl/pcdither.c @@ -130,7 +130,8 @@ download_dither_matrix( * handled at the palette level. */ private int -udither_do_init( +udither_do_registration( + pcl_parser_state_t *pcl_parser_state, gs_memory_t * pmme ) { @@ -143,4 +144,4 @@ udither_do_init( return 0; } -const pcl_init_t pcl_udither_init = { udither_do_init, 0, 0 }; +const pcl_init_t pcl_udither_init = { udither_do_registration, 0, 0 }; diff --git a/pcl/pcfont.c b/pcl/pcfont.c index ccb8f3f6b..85cc615e9 100644 --- a/pcl/pcfont.c +++ b/pcl/pcfont.c @@ -345,7 +345,10 @@ pcl_set_pitch_mode(pcl_args_t *pargs, pcl_state_t *pcs) /* Initialization */ private int -pcfont_do_init(gs_memory_t *mem) +pcfont_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem +) { /* Register commands */ { int chr; /* @@ -572,5 +575,5 @@ pcfont_do_reset(pcl_state_t *pcs, pcl_reset_type_t type) } const pcl_init_t pcfont_init = { - pcfont_do_init, pcfont_do_reset, 0 + pcfont_do_registration, pcfont_do_reset, 0 }; diff --git a/pcl/pcfrgrnd.c b/pcl/pcfrgrnd.c index 88b27562e..a7c6f40fc 100644 --- a/pcl/pcfrgrnd.c +++ b/pcl/pcfrgrnd.c @@ -8,10 +8,6 @@ #include "pcfont.h" #include "pcfrgrnd.h" -/* the default foreground, built from the default palette */ -private pcl_frgrnd_t * pdflt_frgrnd; - - /* GC routines */ private_st_frgrnd_t(); @@ -44,6 +40,7 @@ free_foreground( */ private int alloc_foreground( + pcl_state_t *pcs, pcl_frgrnd_t ** ppfrgrnd, gs_memory_t * pmem ) @@ -58,7 +55,7 @@ alloc_foreground( "allocate pcl foreground object" ); pfrgrnd->rc.free = free_foreground; - pfrgrnd->id = pcl_next_id(); + pfrgrnd->id = pcl_next_id(pcs); pfrgrnd->pbase = 0; pfrgrnd->pht = 0; pfrgrnd->pcrd = 0; @@ -77,6 +74,7 @@ alloc_foreground( */ private int build_foreground( + pcl_state_t * pcs, pcl_frgrnd_t ** ppfrgrnd, const pcl_palette_t * ppalet, int pal_entry, @@ -100,8 +98,8 @@ build_foreground( (num_entries == 2) && (pal_entry == 1) ) { is_default = true; - if (pdflt_frgrnd != 0) { - pcl_frgrnd_copy_from(*ppfrgrnd, pdflt_frgrnd); + if (pcs->pdflt_frgrnd != 0) { + pcl_frgrnd_copy_from(*ppfrgrnd, pcs->pdflt_frgrnd); return 0; } } @@ -112,7 +110,7 @@ build_foreground( *ppfrgrnd = 0; } - if ((code = alloc_foreground(ppfrgrnd, pmem)) < 0) + if ((code = alloc_foreground(pcs, ppfrgrnd, pmem)) < 0) return code; pfrgrnd = *ppfrgrnd; @@ -131,7 +129,7 @@ build_foreground( pcl_crd_init_from(pfrgrnd->pcrd, ppalet->pcrd); if (is_default) - pcl_frgrnd_init_from(pdflt_frgrnd, pfrgrnd); + pcl_frgrnd_init_from(pcs->pdflt_frgrnd, pfrgrnd); return 0; } @@ -152,7 +150,8 @@ pcl_frgrnd_set_default_foreground( if ((code = pcl_palette_check_complete(pcs)) < 0) return code; - return build_foreground( &(pcs->pfrgrnd), + return build_foreground( pcs, + &(pcs->pfrgrnd), pcs->ppalet, 1, pcs->memory @@ -178,7 +177,8 @@ set_foreground( if ((code = pcl_palette_check_complete(pcs)) < 0) return code; - return build_foreground( &(pcs->pfrgrnd), + return build_foreground( pcs, + &(pcs->pfrgrnd), pcs->ppalet, int_arg(pargs), pcs->memory @@ -193,8 +193,9 @@ set_foreground( * by the palette module. */ private int -frgrnd_do_init( - gs_memory_t * pmem +frgrnd_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem ) { DEFINE_CLASS('*') @@ -204,12 +205,16 @@ frgrnd_do_init( }, END_CLASS - /* handle possible non-initialization of BSS */ - pdflt_frgrnd = 0; - return 0; } +private void +frgrnd_do_reset(pcl_state_t *pcs, pcl_reset_type_t type) +{ + if ( type & (pcl_reset_initial | pcl_reset_printer) ) + pcs->pdflt_frgrnd = 0; +} + private int frgrnd_do_copy( pcl_state_t * psaved, @@ -224,4 +229,4 @@ frgrnd_do_copy( return 0; } -const pcl_init_t pcl_frgrnd_init = { frgrnd_do_init, 0, frgrnd_do_copy }; +const pcl_init_t pcl_frgrnd_init = { frgrnd_do_registration, frgrnd_do_reset, frgrnd_do_copy }; diff --git a/pcl/pcfrgrnd.h b/pcl/pcfrgrnd.h index d682584f5..32097f2f6 100644 --- a/pcl/pcfrgrnd.h +++ b/pcl/pcfrgrnd.h @@ -109,9 +109,4 @@ typedef struct pcl_frgrnd_s pcl_frgrnd_t; */ int pcl_frgrnd_set_default_foreground(P1(pcl_state_t * pcs)); -/* - * Entry point for the set-foreground related routines - */ -extern const pcl_init_t pcl_frgrnd_init; - #endif /* pcfrgrnd_INCLUDED */ diff --git a/pcl/pcident.c b/pcl/pcident.c index 4f016bd5a..f6309053c 100644 --- a/pcl/pcident.c +++ b/pcl/pcident.c @@ -7,8 +7,7 @@ #include "gx.h" #include "gsuid.h" #include "pcident.h" - -private pcl_gsid_t next_id; +#include "pcstate.h" /* * Return the next unique identifier. @@ -23,20 +22,11 @@ private pcl_gsid_t next_id; * the graphic library. */ pcl_gsid_t -pcl_next_id(void) -{ - if (next_id == 0) - next_id = 16 * 1024 * 1024; - else if (next_id == no_UniqueID) - ++next_id; - return next_id++; -} - -/* - * Initialize the next_id value. - */ - void -pcl_init_id(void) +pcl_next_id(pcl_state_t *pcs) { - next_id = 8UL; + if (pcs->next_id == 0) + pcs->next_id = 16 * 1024 * 1024; + else if (pcs->next_id == no_UniqueID) + ++(pcs->next_id); + return (pcs->next_id)++; } diff --git a/pcl/pcident.h b/pcl/pcident.h index 161a7cd37..38d6f2723 100644 --- a/pcl/pcident.h +++ b/pcl/pcident.h @@ -35,8 +35,12 @@ typedef ulong pcl_gsid_t; -pcl_gsid_t pcl_next_id( void ); +/* Define an opaque type for the PCL state. */ +#ifndef pcl_state_DEFINED +# define pcl_state_DEFINED +typedef struct pcl_state_s pcl_state_t; +#endif -void pcl_init_id( void ); +pcl_gsid_t pcl_next_id(P1(pcl_state_t *pcs)); #endif /* pcident_INCLUDED */ diff --git a/pcl/pcjob.c b/pcl/pcjob.c index c24d87753..169064669 100644 --- a/pcl/pcjob.c +++ b/pcl/pcjob.c @@ -162,7 +162,10 @@ pcl_set_unit_of_measure(pcl_args_t *pargs, pcl_state_t *pcs) /* Initialization */ private int -pcjob_do_init(gs_memory_t *mem) +pcjob_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem +) { /* Register commands */ DEFINE_ESCAPE('E', "Printer Reset", pcl_printer_reset) DEFINE_CLASS('%') @@ -209,5 +212,5 @@ pcjob_do_reset(pcl_state_t *pcs, pcl_reset_type_t type) } } const pcl_init_t pcjob_init = { - pcjob_do_init, pcjob_do_reset, 0 + pcjob_do_registration, pcjob_do_reset, 0 }; diff --git a/pcl/pcl.mak b/pcl/pcl.mak index 02c272e05..f9f37340d 100644 --- a/pcl/pcl.mak +++ b/pcl/pcl.mak @@ -100,6 +100,7 @@ pcdict_h = $(PCLSRC)pcdict.h \ rtrstst_h = $(PCLSRC)rtrstst.h \ $(gx_h) \ + $(gsimage_h) \ $(pccoord_h) pcmtx3_h = $(PCLSRC)pcmtx3.h \ @@ -1071,6 +1072,7 @@ $(PCLOBJ)pgconfig.$(OBJ): $(PCLSRC)pgconfig.c \ $(PCLOBJ)pgvector.$(OBJ): $(PCLSRC)pgvector.c \ $(stdio__h) \ $(gdebug_h) \ + $(pcparse_h) \ $(pgmand_h) \ $(pggeom_h) \ $(pgdraw_h) \ @@ -1083,6 +1085,7 @@ $(PCLOBJ)pgvector.$(OBJ): $(PCLSRC)pgvector.c \ # Chapter 21 $(PCLOBJ)pgpoly.$(OBJ): $(PCLSRC)pgpoly.c \ $(std_h) \ + $(pcparse_h) \ $(pgmand_h) \ $(pgdraw_h) \ $(pggeom_h) \ @@ -1093,6 +1096,7 @@ $(PCLOBJ)pgpoly.$(OBJ): $(PCLSRC)pgpoly.c \ # Chapter 22 $(PCLOBJ)pglfill.$(OBJ): $(PCLSRC)pglfill.c \ $(memory__h) \ + $(pcparse_h) \ $(pgmand_h) \ $(pginit_h) \ $(pggeom_h) \ @@ -1129,6 +1133,7 @@ $(PCLOBJ)pglabel.$(OBJ): $(PCLSRC)pglabel.c \ $(stdio__h) \ $(gdebug_h) \ $(plvalue_h) \ + $(pcparse_h) \ $(pgmand_h) \ $(pginit_h) \ $(pgfont_h) \ diff --git a/pcl/pclookup.c b/pcl/pclookup.c index 5483afd7f..c9a7fd10e 100644 --- a/pcl/pclookup.c +++ b/pcl/pclookup.c @@ -120,7 +120,8 @@ set_gamma_correction( * are handled by the PCL palette module (using macros defined in pclookup.h). */ private int -lookup_do_init( +lookup_do_registration( + pcl_parser_state_t *pcl_parser_state, gs_memory_t * pmem ) { @@ -140,4 +141,4 @@ lookup_do_init( return 0; } -const pcl_init_t pcl_lookup_tbl_init = { lookup_do_init, 0, 0 }; +const pcl_init_t pcl_lookup_tbl_init = { lookup_do_registration, 0, 0 }; diff --git a/pcl/pcmacros.c b/pcl/pcmacros.c index c68cac562..3d741fe8b 100644 --- a/pcl/pcmacros.c +++ b/pcl/pcmacros.c @@ -6,6 +6,7 @@ /* PCL5 macro commands */ #include "stdio_.h" /* std.h + NULL */ #include "pcommand.h" +#include "pgmand.h" #include "pcstate.h" #include "pcparse.h" @@ -28,30 +29,38 @@ int pcl_execute_macro(const pcl_macro_t *pmac, pcl_state_t *pcs, pcl_copy_operation_t before, pcl_reset_type_t reset, pcl_copy_operation_t after) -{ pcl_parser_state_t state; - pcl_state_t saved; - stream_cursor_read r; - int code; +{ + pcl_parser_state_t state; + hpgl_parser_state_t gstate; + pcl_state_t saved; + stream_cursor_read r; + int code; - if ( before ) - { memcpy(&saved, pcs, sizeof(*pcs)); - do_copies(&saved, pcs, before); - pcs->saved = &saved; - } - if ( reset ) - pcl_do_resets(pcs, reset); - pcl_process_init(&state); - r.ptr = (const byte *)(pmac + 1) - 1; - r.limit = - (const byte *)pmac + (gs_object_size(pcs->memory, pmac) - 1); - pcs->macro_level++; - code = pcl_process(&state, pcs, &r); - pcs->macro_level--; - if ( after ) - { do_copies(&saved, pcs, after); - memcpy(pcs, &saved, sizeof(*pcs)); - } + if ( before ) { + memcpy(&saved, pcs, sizeof(*pcs)); + do_copies(&saved, pcs, before); + pcs->saved = &saved; + } + if ( reset ) + pcl_do_resets(pcs, reset); + state.hpgl_parser_state=&gstate; + pcl_process_init(&state); + code = pcl_do_registrations(pcs, &state); + if ( code < 0 ) + /* we don't try to clean up here. If command registration + fails, the system is not configured correctly. */ return code; + r.ptr = (const byte *)(pmac + 1) - 1; + r.limit = + (const byte *)pmac + (gs_object_size(pcs->memory, pmac) - 1); + pcs->macro_level++; + code = pcl_process(&state, pcs, &r); + pcs->macro_level--; + if ( after ) { + do_copies(&saved, pcs, after); + memcpy(pcs, &saved, sizeof(*pcs)); + } + return code; } /* ---------------- Commands ---------------- */ @@ -193,7 +202,9 @@ pcl_assign_macro_id(pcl_args_t *pargs, pcl_state_t *pcs) /* Initialization */ private int -pcmacros_do_init(gs_memory_t *mem) +pcmacros_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem) { /* Register commands */ DEFINE_CLASS('&') {'f', 'X', @@ -245,5 +256,5 @@ pcmacros_do_copy(pcl_state_t *psaved, const pcl_state_t *pcs, return 0; } const pcl_init_t pcmacros_init = { - pcmacros_do_init, pcmacros_do_reset, pcmacros_do_copy + pcmacros_do_registration, pcmacros_do_reset, pcmacros_do_copy }; diff --git a/pcl/pcmain.c b/pcl/pcmain.c index 153a38ec3..5208861b0 100644 --- a/pcl/pcmain.c +++ b/pcl/pcmain.c @@ -57,21 +57,6 @@ const pcl_init_t * pcl_init_table[] = { /* Built-in symbol set initialization procedure */ extern bool pcl_load_built_in_symbol_sets( pcl_state_t * ); -/* - * If inst.pause is set, pause at the end of each page. - */ - private int -pause_end_page( - pcl_state_t * pcs, - int num_copies, - int flush -) -{ - pl_main_instance_t * pmi = pcs->client_data; - - return pl_finish_page(pmi, pcs->pgs, num_copies, flush); -} - /* * Define the gstate client procedures. */ @@ -142,7 +127,8 @@ main( pl_main_instance_t inst; gs_state * pgs; pcl_state_t * pcs; - pcl_parser_state_t pstate; + pcl_parser_state_t pcl_parser_state; + hpgl_parser_state_t pgl_parser_state; arg_list args; const char * arg; @@ -203,27 +189,17 @@ main( /* initialize pjl */ pcs->pjls = pjl_process_init(mem); - - /* Run initialization code. */ + pcl_parser_state.hpgl_parser_state = &pgl_parser_state; { - const pcl_init_t ** init; - - hpgl_init_command_index(); - for (init = pcl_init_table; *init; ++init) { - if ( (*init)->do_init ) { - int code = (*(*init)->do_init)(mem); - - if (code < 0) { - lprintf1("Error %d during initialization!\n", code); - exit(code); - } - } - } - pcl_do_resets(pcs, pcl_reset_initial); + /* Run initialization code. */ + int code = pcl_do_registrations(pcs, &pcl_parser_state); + if ( code < 0 ) + exit(code); } - pcl_set_end_page(pause_end_page); - + /* glue the initialized gl/2 parser state into pcl's state */ + pcs->parse_data = &pgl_parser_state; + pcl_do_resets(pcs, pcl_reset_initial); pcl_load_built_in_symbol_sets(pcs); #ifdef DEBUG @@ -274,11 +250,11 @@ process: break; else if (code > 0) { in_pjl = false; - pcl_process_init(&pstate); + pcl_process_init(&pcl_parser_state); goto process; } } else { - code = pcl_process(&pstate, pcs, &r); + code = pcl_process(&pcl_parser_state, pcs, &r); if (code == e_ExitLanguage) in_pjl = true; else if (code < 0) diff --git a/pcl/pcmisc.c b/pcl/pcmisc.c index 08701945c..46587b0bd 100644 --- a/pcl/pcmisc.c +++ b/pcl/pcmisc.c @@ -33,7 +33,9 @@ pcl_disable_display_functions(pcl_args_t *pargs, pcl_state_t *pcs) /* Initialization */ private int -pcmisc_do_init(gs_memory_t *mem) +pcmisc_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem) { /* Register commands */ DEFINE_CLASS_COMMAND_ARGS('&', 's', 'C', "End of Line Wrap", pcl_end_of_line_wrap, @@ -52,5 +54,5 @@ pcmisc_do_reset(pcl_state_t *pcs, pcl_reset_type_t type) } } const pcl_init_t pcmisc_init = { - pcmisc_do_init, pcmisc_do_reset + pcmisc_do_registration, pcmisc_do_reset }; diff --git a/pcl/pcommand.c b/pcl/pcommand.c index b8c984a35..7863f1ed0 100644 --- a/pcl/pcommand.c +++ b/pcl/pcommand.c @@ -12,10 +12,11 @@ #include "gxstate.h" #include "gsdevice.h" #include "pcommand.h" +#include "pcparse.h" #include "pcstate.h" #include "pcparam.h" #include "pcident.h" - +#include "pgmand.h" /* temporary */ /* * Get the command argument as an int, uint, or float. */ @@ -140,6 +141,29 @@ put_param1_float_array( return end_param1(&list, pcs); } +/* initilialize the parser states */ + int +pcl_do_registrations( + pcl_state_t *pcs, + pcl_parser_state_t *pst +) +{ + const pcl_init_t ** init; + /* initialize gl/2 command counter */ + hpgl_init_command_index(pst->hpgl_parser_state); + /* initialize pcl's command counter */ + pcl_init_command_index(pst); + for (init = pcl_init_table; *init; ++init) { + if ( (*init)->do_registration ) { + int code = (*(*init)->do_registration)(pst, pcs->memory); + if (code < 0) { + lprintf1("Error %d during initialization!\n", code); + return code; + } + } + } + return 0; +} /* * Run the reset code of all the modules. */ @@ -192,8 +216,7 @@ pcl_init_state( pcs->monochrome_mode = false; pcs->render_mode = 3; + pcs->next_id = 8UL; pcl_init_gstate_stk(pcs); - /* the PCL identifier mechanism is not strictly part of the state */ - pcl_init_id(); } diff --git a/pcl/pcommand.h b/pcl/pcommand.h index 5a78f13f7..d83bb573f 100644 --- a/pcl/pcommand.h +++ b/pcl/pcommand.h @@ -8,6 +8,7 @@ #ifndef pcommand_INCLUDED # define pcommand_INCLUDED +#include "memory_.h" #include "gx.h" #include "gserrors.h" @@ -81,6 +82,16 @@ typedef struct pcl_args_s { typedef struct pcl_state_s pcl_state_t; #endif +#ifndef pcl_parser_state_DEFINED +# define pcl_parser_state_DEFINED +typedef struct pcl_parser_state_s pcl_parser_state_t; +#endif + +#ifndef hpgl_parser_state_DEFINED +# define hpgl_parser_state_DEFINED +typedef struct hpgl_args_s hpgl_parser_state_t; +#endif + /* Define a command processing procedure. */ #define pcl_command_proc(proc)\ int proc(P2(pcl_args_t *, pcl_state_t *)) @@ -145,37 +156,38 @@ typedef struct { } pcl_grouped_command_definition_t; /* Register (a) command definition(s). */ -void pcl_define_control_command(P2(int/*char*/, - const pcl_command_definition_t *)); +void pcl_define_control_command(P3(int/*char*/, + const pcl_command_definition_t *, pcl_parser_state_t *)); #define DEFINE_CONTROL(chr, cname, proc)\ { static const pcl_command_definition_t defn_ = PCL_COMMAND(cname, proc, 0);\ - pcl_define_control_command(chr, &defn_);\ + pcl_define_control_command(chr, &defn_, pcl_parser_state);\ } -void pcl_define_escape_command(P2(int/*char*/, - const pcl_command_definition_t *)); +void pcl_define_escape_command(P3(int/*char*/, + const pcl_command_definition_t *, pcl_parser_state_t *)); #define DEFINE_ESCAPE_ARGS(chr, cname, proc, acts)\ { static const pcl_command_definition_t defn_ = PCL_COMMAND(cname, proc, acts);\ - pcl_define_escape_command(chr, &defn_);\ + pcl_define_escape_command(chr, &defn_, pcl_parser_state);\ } #define DEFINE_ESCAPE(chr, cname, proc)\ DEFINE_ESCAPE_ARGS(chr, cname, proc, 0) -void pcl_define_class_command(P4(int/*char*/, int/*char*/, int/*char*/, - const pcl_command_definition_t *)); +void pcl_define_class_command(P5(int/*char*/, int/*char*/, int/*char*/, + const pcl_command_definition_t *, pcl_parser_state_t *)); #define DEFINE_CLASS_COMMAND_ARGS(cls, group, chr, cname, proc, acts)\ { static const pcl_command_definition_t defn_ = PCL_COMMAND(cname, proc, acts);\ - pcl_define_class_command(cls, group, chr, &defn_);\ + pcl_define_class_command(cls, group, chr, &defn_, pcl_parser_state);\ } #define DEFINE_CLASS_COMMAND(cls, group, chr, cname, proc)\ DEFINE_CLASS_COMMAND_ARGS(cls, group, chr, cname, proc, 0) -void pcl_define_class_commands(P2(int/*char*/, - const pcl_grouped_command_definition_t *)); +void pcl_define_class_commands(P3(int/*char*/, + const pcl_grouped_command_definition_t *, + pcl_parser_state_t *)); #define DEFINE_CLASS(cls)\ { const byte class_ = cls;\ static const pcl_grouped_command_definition_t defs_[] = { #define END_CLASS\ {0, 0}\ };\ - pcl_define_class_commands(class_, defs_);\ + pcl_define_class_commands(class_, defs_, pcl_parser_state);\ } /* @@ -209,16 +221,21 @@ typedef enum { } pcl_copy_operation_t; /* Define the structure for per-module implementation procedures. */ typedef struct pcl_init_s { - /* Register commands and do true one-time initialization. */ - int (*do_init)(P1(gs_memory_t *mem)); + /* Register commands */ + int (*do_registration)(P2(pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem)); /* Initialize state at startup, printer reset, and other times. */ - void (*do_reset)(P2(pcl_state_t *pcs, pcl_reset_type_t type)); + void (*do_reset)(P2(pcl_state_t *pcs, pcl_reset_type_t type)); /* Partially copy the state for macro call, overlay, and exit. */ - int (*do_copy)(P3(pcl_state_t *psaved, const pcl_state_t *pcs, - pcl_copy_operation_t operation)); + int (*do_copy)(P3(pcl_state_t *psaved, const pcl_state_t *pcs, + pcl_copy_operation_t operation)); } pcl_init_t; /* Define the table of pointers to init structures (in pcjob.c). */ extern const pcl_init_t *pcl_init_table[]; + +/* run the init code */ +int pcl_do_registrations(P2(pcl_state_t *pcs, pcl_parser_state_t *pst)); + /* Run the reset code of all the modules. */ int pcl_do_resets(P2(pcl_state_t *pcs, pcl_reset_type_t type)); @@ -239,14 +256,6 @@ typedef enum { ( ((1 << pcds_simm_max) - 1) << pcds_simm_shift ) } pcl_data_storage_t; -/* Define the common prefix for all stored entities (macros, patterns, */ -/* fonts, symbol sets). */ -#define pcl_entity_common\ - pcl_data_storage_t storage -typedef struct pcl_entity_s { - pcl_entity_common; -} pcl_entity_t; - /* Define the control characters. */ #define BS 0x8 #define HT 0x9 diff --git a/pcl/pcpage.c b/pcl/pcpage.c index bc58ee3e0..b13fa5345 100644 --- a/pcl/pcpage.c +++ b/pcl/pcpage.c @@ -17,6 +17,7 @@ #include "pcpage.h" #include "pgmand.h" #include "pginit.h" +#include "plmain.h" /* for finish page */ #include "gsmatrix.h" /* for gsdevice.h */ #include "gscoord.h" #include "gsdevice.h" @@ -359,34 +360,6 @@ new_logical_page( new_page_size(pcs, psize, reset_initial); } - -/* page end function to use */ -private int (*end_page)( pcl_state_t * pcs, int num_copies, int flush ); - -/* - * Set the page output procedure. - */ - void -pcl_set_end_page( - int (*procp)( pcl_state_t * pcs, int num_copies, int flush ) -) -{ - end_page = procp; -} - -/* - * Stub output page procedure. This will normally be overridden in pcmain.c. - */ - private int -default_end_page( - pcl_state_t * pcs, - int num_copies, - int flush -) -{ - return gs_output_page(pcs->pgs, num_copies, flush); -} - /* * End a page, either unconditionally or only if there are marks on it. * Return 1 if the page was actually printed and erased. @@ -443,7 +416,8 @@ pcl_end_page( } /* output the page */ - (*end_page)(pcs, pcs->num_copies, true); + pl_finish_page((pl_main_instance_t *)pcs->client_data, + pcs->pgs, pcs->num_copies, /* flush = */ true); pcl_set_drawing_color(pcs, pcl_pattern_solid_white, 0, false); code = gs_erasepage(pcs->pgs); /* @@ -791,7 +765,8 @@ pcl_print_quality( * Initialization */ private int -pcpage_do_init( +pcpage_do_registration( + pcl_parser_state_t *pcl_parser_state, gs_memory_t * pmem /* ignored */ ) { @@ -924,8 +899,6 @@ pcpage_do_reset( ) { if ((type & (pcl_reset_initial | pcl_reset_printer)) != 0) { - if ((type & pcl_reset_initial) != 0) - end_page = default_end_page; pcs->paper_source = 0; /* ??? */ pcs->xfm_state.left_offset_cp = 0.0; pcs->xfm_state.top_offset_cp = 0.0; @@ -946,4 +919,4 @@ pcpage_do_reset( } } -const pcl_init_t pcpage_init = { pcpage_do_init, pcpage_do_reset, 0 }; +const pcl_init_t pcpage_init = { pcpage_do_registration, pcpage_do_reset, 0 }; diff --git a/pcl/pcpalet.c b/pcl/pcpalet.c index 453e2419f..bc28007aa 100644 --- a/pcl/pcpalet.c +++ b/pcl/pcpalet.c @@ -11,17 +11,6 @@ #include "pcpalet.h" #include "pcfrgrnd.h" -/* - * The default palette. This is allocated once at boot time, and retained - * thereafter. It could be freed and re-allocated, but it is harder to use - * memory leak detection tools in that case. - */ -pcl_palette_t * pdflt_palette; - -/* dictionary to hold the palette store */ -private pl_dict_t palette_store; - - /* GC routines */ private_st_palette_t(); @@ -69,6 +58,7 @@ dict_free_palette( */ private int alloc_palette( + pcl_state_t * pcs, pcl_palette_t ** pppalet, gs_memory_t * pmem ) @@ -83,7 +73,7 @@ alloc_palette( "allocate pcl palette object" ); ppalet->rc.free = free_palette; - ppalet->id = pcl_next_id(); + ppalet->id = pcl_next_id(pcs); ppalet->pindexed = 0; ppalet->pcrd = 0; ppalet->pht = 0; @@ -132,12 +122,12 @@ unshare_palette( /* check if there is anything to do */ if ((ppalet != 0) && (ppalet->rc.ref_count == 1)) { - ppalet->id = pcl_next_id(); + ppalet->id = pcl_next_id(pcs); return 0; } /* allocate a new palette */ - if ((code = alloc_palette(&pnew, pcs->memory)) < 0) + if ((code = alloc_palette(pcs, &pnew, pcs->memory)) < 0) return code; if (ppalet != 0) { pcl_cs_indexed_init_from(pnew->pindexed, ppalet->pindexed); @@ -148,7 +138,7 @@ unshare_palette( /* redefine the current palette id. */ pcs->ppalet = pnew; id_set_value(key, pcs->sel_palette_id); - code = pl_dict_put(&palette_store, id_key(key), 2, pnew); + code = pl_dict_put(&pcs->palette_store, id_key(key), 2, pnew); return (code == -1 ? e_Memory : 0); } @@ -166,16 +156,16 @@ build_default_palette( pcl_palette_t * ppalet = 0; int code = 0; - if (pdflt_palette == 0) { - code = alloc_palette(&ppalet, pmem); + if (pcs->pdflt_palette == 0) { + code = alloc_palette(pcs, &ppalet, pmem); if (code == 0) code = pcl_cs_indexed_build_default_cspace( &(ppalet->pindexed), pmem ); - if ((code == 0) && (pcl_default_crd == 0)) + if ((code == 0) && (pcs->pcl_default_crd == 0)) code = pcl_crd_build_default_crd(pcs); if (code == 0) - pcl_crd_init_from(ppalet->pcrd, pcl_default_crd); + pcl_crd_init_from(ppalet->pcrd, pcs->pcl_default_crd); if (code == 0) code = pcl_ht_build_default_ht(pcs, &(ppalet->pht), pmem); if (code < 0) { @@ -183,14 +173,14 @@ build_default_palette( free_palette(pmem, ppalet, "build default palette"); return code; } - pcl_palette_init_from(pdflt_palette, ppalet); + pcl_palette_init_from(pcs->pdflt_palette, ppalet); } else - pcl_palette_init_from(ppalet, pdflt_palette); + pcl_palette_init_from(ppalet, pcs->pdflt_palette); /* NB: definitions do NOT record a referece */ id_set_value(key, pcs->sel_palette_id); - code = pl_dict_put(&palette_store, id_key(key), 2, ppalet); + code = pl_dict_put(&pcs->palette_store, id_key(key), 2, ppalet); if (code < 0) return e_Memory; @@ -200,33 +190,15 @@ build_default_palette( } /* - * Palette stack. This is implemented as a simple linked list, and is opaque - * outside of this module. - */ -typedef struct pstack_entry_s { - struct pstack_entry_s * pnext; - pcl_palette_t * ppalet; -} pstack_entry_t; - -gs_private_st_ptrs1( st_pstack_entry_t, - pstack_entry_t, - "palette stack entry", - pstack_enum_ptrs, - pstack_reloc_ptrs, - ppalet - ); - -private pstack_entry_t * palette_stack; - -/* * Clear the palette stack. */ private void clear_palette_stack( + pcl_state_t * pcs, gs_memory_t * pmem ) { - pstack_entry_t * pentry = palette_stack; + pstack_entry_t * pentry = pcs->palette_stack; while (pentry != 0) { pstack_entry_t * pnext = pentry->pnext; @@ -235,7 +207,7 @@ clear_palette_stack( gs_free_object(pmem, pentry, "clear palette stack"); pentry = pnext; } - palette_stack = 0; + pcs->palette_stack = 0; } /* @@ -270,26 +242,26 @@ push_pop_palette( return e_Memory; pcl_palette_init_from(pentry->ppalet, pcs->ppalet); - pentry->pnext = palette_stack; - palette_stack = pentry; + pentry->pnext = pcs->palette_stack; + pcs->palette_stack = pentry; return 0; } else if (action == 1) { - pstack_entry_t * pentry = palette_stack; + pstack_entry_t * pentry = pcs->palette_stack; int code = 0; if (pentry != 0) { pcl_id_t key; - palette_stack = pentry->pnext; + pcs->palette_stack = pentry->pnext; /* NB: just set - pcs->ppalet is not a reference */ pcs->ppalet = pentry->ppalet; /* the dictionary gets the stack reference on the palette */ id_set_value(key, pcs->sel_palette_id); - code = pl_dict_put(&palette_store, id_key(key), 2, pentry->ppalet); + code = pl_dict_put(&pcs->palette_store, id_key(key), 2, pentry->ppalet); gs_free_object(pcs->memory, pentry, "pop pcl palette"); } @@ -645,10 +617,10 @@ pcl_palette_set_view_illuminant( if ((code == 0) && (pcs->ppalet->pcrd == 0)) { if ((code = pcl_crd_build_default_crd(pcs)) == 0) - pcl_crd_init_from(pcs->ppalet->pcrd, pcl_default_crd); + pcl_crd_init_from(pcs->ppalet->pcrd, pcs->pcl_default_crd); } if (code == 0) - code = pcl_crd_set_view_illuminant(&(pcs->ppalet->pcrd), pwht_pt); + code = pcl_crd_set_view_illuminant(pcs, &(pcs->ppalet->pcrd), pwht_pt); return code; } @@ -684,7 +656,7 @@ pcl_palette_check_complete( ); if ((code == 0) && (ppalet->pcrd == 0)) { if ((code = pcl_crd_build_default_crd(pcs)) == 0) - pcl_crd_init_from(pcs->ppalet->pcrd, pcl_default_crd); + pcl_crd_init_from(pcs->ppalet->pcrd, pcs->pcl_default_crd); } if ((code == 0) && (ppalet->pht == 0)) code = pcl_ht_build_default_ht(pcs, &(ppalet->pht), pcs->memory); @@ -709,7 +681,7 @@ set_sel_palette_id( /* ignore attempts to select non-existent palettes */ id_set_value(key, id); - if ( pl_dict_lookup( &palette_store, + if ( pl_dict_lookup( &pcs->palette_store, id_key(key), 2, (void **)&(pcs->ppalet), @@ -753,15 +725,15 @@ clear_palette_store( gs_const_string plkey; int sel_id = pcs->sel_palette_id; - pl_dict_enum_begin(&palette_store, &denum); + pl_dict_enum_begin(&pcs->palette_store, &denum); while (pl_dict_enum_next(&denum, &plkey, &pvalue)) { int id = (((int)plkey.data[0]) << 8) + plkey.data[1]; if (id == sel_id) { - if (pvalue != pdflt_palette) + if (pvalue != pcs->pdflt_palette) build_default_palette(pcs); /* will redefine sel_id */ } else - pl_dict_undef(&palette_store, plkey.data, plkey.size); + pl_dict_undef(&pcs->palette_store, plkey.data, plkey.size); } } @@ -785,18 +757,18 @@ palette_control( break; case 1: - clear_palette_stack(pcs->memory); + clear_palette_stack(pcs, pcs->memory); break; case 2: if (pcs->ctrl_palette_id == pcs->sel_palette_id) { - if ((pcs->ppalet == 0) || (pcs->ppalet != pdflt_palette)) + if ((pcs->ppalet == 0) || (pcs->ppalet != pcs->pdflt_palette)) build_default_palette(pcs); } else { pcl_id_t key; id_set_value(key, pcs->ctrl_palette_id); - pl_dict_undef(&palette_store, id_key(key), 2); + pl_dict_undef(&pcs->palette_store, id_key(key), 2); } break; @@ -807,7 +779,7 @@ palette_control( /* NB: definitions don't incremente refernece counts */ id_set_value(key, pcs->ctrl_palette_id); - code = pl_dict_put(&palette_store, id_key(key), 2, pcs->ppalet); + code = pl_dict_put(&pcs->palette_store, id_key(key), 2, pcs->ppalet); if (code < 0) return code; rc_increment(pcs->ppalet); @@ -873,7 +845,8 @@ set_print_mode( * Initialization routine for palettes. */ private int -palette_do_init( +palette_do_registration( + pcl_parser_state_t *pcl_parser_state, gs_memory_t * pmem ) { @@ -946,7 +919,7 @@ palette_do_reset( /* for initial reset, set up the palette store */ if ((type & pcl_reset_initial) != 0) { - pl_dict_init(&palette_store, pcs->memory, dict_free_palette); + pl_dict_init(&pcs->palette_store, pcs->memory, dict_free_palette); pcs->ppalet = 0; pcs->pfrgrnd = 0; @@ -954,16 +927,16 @@ palette_do_reset( pcl_ht_init_render_methods(pcs, pcs->memory); /* handle possible non-initialization of BSS */ - pdflt_palette = 0; - palette_stack = 0; - pcl_default_crd = 0; - pcl_cs_base_init(); + pcs->pdflt_palette = 0; + pcs->palette_stack = 0; + pcs->pcl_default_crd = 0; + pcl_cs_base_init(pcs); pcl_cs_indexed_init(); } else if ((type & (pcl_reset_cold | pcl_reset_printer)) != 0) { /* clear the palette stack and store */ - clear_palette_stack(pcs->memory); + clear_palette_stack(pcs, pcs->memory); clear_palette_store(pcs); } @@ -1012,14 +985,13 @@ palette_do_copy( if ((operation & (pcl_copy_before_call | pcl_copy_before_overlay)) != 0) pcl_palette_init_from(psaved->ppalet, pcs->ppalet); else if ((operation & pcl_copy_after) != 0) { - pcl_id_t key; - + pcl_id_t key; id_set_value(key, psaved->sel_palette_id); - pl_dict_put(&palette_store, id_key(key), 2, psaved->ppalet); + pl_dict_put(&pcs->palette_store, id_key(key), 2, psaved->ppalet); } return 0; } const pcl_init_t pcl_palette_init = { - palette_do_init, palette_do_reset, palette_do_copy + palette_do_registration, palette_do_reset, palette_do_copy }; diff --git a/pcl/pcpalet.h b/pcl/pcpalet.h index 690e3f737..c8f1fab61 100644 --- a/pcl/pcpalet.h +++ b/pcl/pcpalet.h @@ -284,6 +284,15 @@ int pcl_palette_set_view_illuminant(P2( */ int pcl_palette_check_complete(P1(pcl_state_t * pcs)); + +gs_private_st_ptrs1( st_pstack_entry_t, + pstack_entry_t, + "palette stack entry", + pstack_enum_ptrs, + pstack_reloc_ptrs, + ppalet + ); + /* * Entry points to the palette-related commands. */ diff --git a/pcl/pcparse.c b/pcl/pcparse.c index 54576fd9f..c6bb28bc4 100644 --- a/pcl/pcparse.c +++ b/pcl/pcparse.c @@ -19,83 +19,36 @@ /* while scanning a macro definition. */ /*#define DISPLAY_FUNCTIONS_IN_MACRO*/ -/* GC structures and procedures */ -gs_private_st_simple(st_pcl_parser_state, pcl_parser_state_t, - "pcl_parser_state_t" /*, pcl_pstate_enum_ptrs, pcl_pstate_reloc_ptrs*/); - -/* ---------------- Command tables ---------------- */ - -/* - * We register all the PCL5* commands dynamically, for maximum configuration - * flexibility. pcl_command_list points to the individual command - * definitions; as each command is registered, we enter it in the list, and - * then store its index in the actual dispatch table - * (pcl_xxx_command_xxx_indices). - */ -private const pcl_command_definition_t *pcl_command_list[256]; -private int pcl_command_next_index; -/* - * First-level dispatch for control characters. - */ -private byte pcl_control_command_indices[33]; -/* - * Second-level dispatch for 2-character escape sequences. - */ -#define min_escape_2char '0' -#define max_escape_2char '~' -private byte - pcl_escape_command_indices[max_escape_2char - min_escape_2char + 1]; -/* - * Convert escape classes to second level dispatch indices. - */ -#define min_escape_class '!' -#define max_escape_class '/' -private const byte - pcl_escape_class_indices[max_escape_class - min_escape_class + 1] = { - 0, 0, 0, 0, 1/*%*/, 2/*&*/, 0, 3/*(*/, 4/*)*/, 5/***/, 0, 0, 0, 0, 0 - }; -/* - * Dispatch on class, group, and command. - */ -#define min_escape_group '`' -#define max_escape_group '~' -#define min_escape_command '@' /* or '`' */ -#define max_escape_command '^' /* or '~' */ -private byte - pcl_grouped_command_indices - [5 /* number of implemented classes, see escape_class_indices above */] - [1 + max_escape_group - min_escape_group + 1] - [max_escape_command - min_escape_command + 1]; - /* ---------------- Command definition ---------------- */ /* Register a command. Return true if this is a redefinition. */ private bool -pcl_register_command(byte *pindex, const pcl_command_definition_t *pcmd) -{ int index = pcl_command_next_index; +pcl_register_command(byte *pindex, pcl_command_definition_t *pcmd, + pcl_parser_state_t *pcl_parser_state) +{ int index = pcl_parser_state->pcl_command_next_index; byte prev = *pindex; - if ( prev != 0 && prev <= index && pcl_command_list[prev] == pcmd ) + if ( prev != 0 && prev <= index && pcl_parser_state->pcl_command_list[prev] == pcmd ) index = prev; - else if ( index != 0 && pcl_command_list[index] == pcmd ) + else if ( index != 0 && pcl_parser_state->pcl_command_list[index] == pcmd ) ; else - pcl_command_list[pcl_command_next_index = ++index] = pcmd; + pcl_parser_state->pcl_command_list[pcl_parser_state->pcl_command_next_index = ++index] = pcmd; *pindex = index; return (prev != 0 && prev != index); } /* Define a command or list of commands. */ void -pcl_define_control_command(int/*char*/ chr, - const pcl_command_definition_t *pcmd) +pcl_define_control_command(int/*char*/ chr, const pcl_command_definition_t *pcmd, + pcl_parser_state_t *pcl_parser_state) { #ifdef DEBUG - if ( chr < 0 || chr >= countof(pcl_control_command_indices) ) + if ( chr < 0 || chr >= countof(pcl_parser_state->pcl_control_command_indices) ) if_debug1('I', "Invalid control character %d\n", chr); else if ( #endif - pcl_register_command(&pcl_control_command_indices[chr], pcmd) + pcl_register_command(&pcl_parser_state->pcl_control_command_indices[chr], pcmd, pcl_parser_state) #ifdef DEBUG ) if_debug1('I', "Redefining control character %d\n", chr); @@ -104,23 +57,33 @@ pcl_define_control_command(int/*char*/ chr, } void pcl_define_escape_command(int/*char*/ chr, - const pcl_command_definition_t *pcmd) + const pcl_command_definition_t *pcmd, pcl_parser_state_t *pcl_parser_state) { #ifdef DEBUG - if ( chr < min_escape_2char || chr > max_escape_2char ) - if_debug1('I', "Invalid escape character %c\n", chr); - else if ( + if ( chr < min_escape_2char || chr > max_escape_2char ) + if_debug1('I', "Invalid escape character %c\n", chr); + else if ( #endif - pcl_register_command(&pcl_escape_command_indices[chr - min_escape_2char], pcmd) + pcl_register_command(&pcl_parser_state->pcl_escape_command_indices + [chr - min_escape_2char], pcmd, + pcl_parser_state) #ifdef DEBUG - ) - if_debug1('I', "Redefining ESC %c\n", chr) + ) + if_debug1('I', "Redefining ESC %c\n", chr) #endif - ; + ; } + +/* + * Convert escape classes to second level dispatch indices. + */ +private const byte pcl_escape_class_indices[max_escape_class - min_escape_class + 1] = { + 0, 0, 0, 0, 1/*%*/, 2/*&*/, 0, 3/*(*/, 4/*)*/, 5/***/, 0, 0, 0, 0, 0 +}; + void pcl_define_class_command(int/*char*/ class, int/*char*/ group, - int/*char*/ command, const pcl_command_definition_t *pcmd) + int/*char*/ command, const pcl_command_definition_t *pcmd, pcl_parser_state_t *pcl_parser_state) { #ifdef DEBUG if ( class < min_escape_class || class > max_escape_class || @@ -131,10 +94,11 @@ pcl_define_class_command(int/*char*/ class, int/*char*/ group, if_debug3('I', "Invalid command %c %c %c\n", class, group, command); else if ( #endif - pcl_register_command(&pcl_grouped_command_indices + pcl_register_command(&pcl_parser_state->pcl_grouped_command_indices [pcl_escape_class_indices[class - min_escape_class] - 1] [group == 0 ? 0 : group - min_escape_group + 1] - [command - min_escape_command], pcmd) + [command - min_escape_command], pcmd, + pcl_parser_state) #ifdef DEBUG ) if_debug3('I', "Redefining ESC %c %c %c\n", class, @@ -144,12 +108,12 @@ pcl_define_class_command(int/*char*/ class, int/*char*/ group, } void pcl_define_class_commands(int/*char*/ class, - const pcl_grouped_command_definition_t *pgroup) + const pcl_grouped_command_definition_t *pgroup, pcl_parser_state_t *pcl_parser_state) { const pcl_grouped_command_definition_t *pgc = pgroup; for ( ; pgc->command != 0; ++pgc ) pcl_define_class_command(class, pgc->group, pgc->command, - &pgc->defn); + &pgc->defn, pcl_parser_state); } /* @@ -160,19 +124,20 @@ pcl_define_class_commands(int/*char*/ class, * The caller is responsible for providing valid arguments. */ private const pcl_command_definition_t * -pcl_get_command_definition(int/*char*/ class, int/*char*/ group, +pcl_get_command_definition(pcl_parser_state_t *pcl_parser_state, int/*char*/ class, int/*char*/ group, int/*char*/ command) { const pcl_command_definition_t *cdefn = 0; if ( class == 0 ) {if ( command >= min_escape_2char && command <= max_escape_2char ) - cdefn = pcl_command_list[pcl_escape_command_indices[command - min_escape_2char]]; + cdefn = pcl_parser_state->pcl_command_list + [pcl_parser_state->pcl_escape_command_indices[command - min_escape_2char]]; } else { int class_index = pcl_escape_class_indices[class - min_escape_class]; if ( class_index ) - cdefn = pcl_command_list - [pcl_grouped_command_indices[class_index - 1] + cdefn = pcl_parser_state->pcl_command_list + [pcl_parser_state->pcl_grouped_command_indices[class_index - 1] [group ? group - min_escape_group + 1 : 0] [command - min_escape_command] ]; @@ -192,18 +157,6 @@ pcl_get_command_definition(int/*char*/ class, int/*char*/ group, /* ---------------- Parsing ---------------- */ -/* Allocate a parser state. */ -pcl_parser_state_t * -pcl_process_alloc(gs_memory_t *memory) -{ pcl_parser_state_t *pst = gs_alloc_struct(memory, pcl_parser_state_t, - &st_pcl_parser_state, - "pcl_process_alloc"); - if ( pst == 0 ) - return 0; - pcl_process_init(pst); - return pst; -} - /* Initialize the parser state. */ void pcl_process_init(pcl_parser_state_t *pst) @@ -308,7 +261,8 @@ pcl_process(pcl_parser_state_t *pst, pcl_state_t *pcs, stream_cursor_read *pr) continue; } /* Invoke the command. */ - cdefn = pcl_get_command_definition(pst->param_class, + cdefn = pcl_get_command_definition(pst, + pst->param_class, pst->param_group, pst->args.command); pst->scan_type = scanning_none; @@ -322,8 +276,8 @@ pcl_process(pcl_parser_state_t *pst, pcl_state_t *pcs, stream_cursor_read *pr) if ( p >= rlimit ) goto x; if ( p[1] >= min_escape_2char && p[1] <= max_escape_2char && - (index = pcl_escape_command_indices[p[1] - min_escape_2char]) != 0 && - pcl_command_list[index]->proc == + (index = pst->pcl_escape_command_indices[p[1] - min_escape_2char]) != 0 && + pst->pcl_command_list[index]->proc == pcl_disable_display_functions ) { if ( do_display_functions() ) @@ -415,7 +369,8 @@ pcl_process(pcl_parser_state_t *pst, pcl_state_t *pcs, stream_cursor_read *pr) continue; } /* Dispatch on param_class, param_group, and chr. */ - cdefn = pcl_get_command_definition(pst->param_class, + cdefn = pcl_get_command_definition(pst, + pst->param_class, pst->param_group, chr); if ( cdefn ) @@ -469,10 +424,10 @@ pcl_process(pcl_parser_state_t *pst, pcl_state_t *pcs, stream_cursor_read *pr) chr >= 33 && chr <= 126 ? "%c\n" : "\\%03o\n"), chr); - cdefn = pcl_command_list + cdefn = pst->pcl_command_list [chr < 33 ? - pcl_control_command_indices[chr] : - pcl_control_command_indices[1]]; + pst->pcl_control_command_indices[chr] : + pst->pcl_control_command_indices[1]]; if ( (cdefn == 0 || cdefn->proc == pcl_plain_char) && !in_macro && @@ -512,7 +467,7 @@ pcl_process(pcl_parser_state_t *pst, pcl_state_t *pcs, stream_cursor_read *pr) "ESC \\%03o\n"), chr); cdefn = - pcl_get_command_definition(0, 0, chr); + pcl_get_command_definition(pst, 0, 0, chr); if ( !cdefn ) { /* Skip only the ESC. */ --p; @@ -613,21 +568,31 @@ x: pr->ptr = p; return code; } +/* inialize the pcl command counter */ +void +pcl_init_command_index(pcl_parser_state_t *pcl_parser_state) +{ + pcl_parser_state->pcl_command_next_index = 0; + /* fix me. This is should be fixed along with + hpgl_init_command_index() in pgparse.c */ +#define init_to_zero(foop)\ + memset(pcl_parser_state->foop, 0, sizeof(pcl_parser_state->foop)) + init_to_zero(pcl_grouped_command_indices); + init_to_zero(pcl_escape_command_indices); + init_to_zero(pcl_control_command_indices); + init_to_zero(pcl_command_list); +#undef init_to_zero +} + /* ---------------- Initialization ---------------- */ private void pcparse_do_reset(pcl_state_t *pcs, pcl_reset_type_t type) -{ if ( type & (pcl_reset_initial | pcl_reset_printer) ) - { /* Return to PCL mode. */ - if ( type & pcl_reset_initial ) - pcl_command_next_index = 0; - if ( !(type & pcl_reset_initial) && pcs->parse_data ) - gs_free_object(pcs->memory, pcs->parse_data, - "secondary parser data(reset)"); - pcs->parse_data = 0; - pcs->parse_other = 0; - } +{ + if ( type & (pcl_reset_initial | pcl_reset_printer) ) + pcs->parse_other = 0; } + const pcl_init_t pcparse_init = { 0, pcparse_do_reset }; diff --git a/pcl/pcparse.h b/pcl/pcparse.h index 0f423904e..9c3bcdfc4 100644 --- a/pcl/pcparse.h +++ b/pcl/pcparse.h @@ -9,6 +9,7 @@ # define pcparse_INCLUDED #include "gsmemory.h" +#include "scommon.h" #include "pcommand.h" /* Define the lexical state of the scanner. */ @@ -18,21 +19,56 @@ typedef enum { scanning_display, /* display_functions mode */ scanning_data /* data following a command */ } pcl_scan_type_t; + +#define min_escape_2char '0' +#define max_escape_2char '~' +#define min_escape_class '!' +#define max_escape_class '/' +#define min_escape_group '`' +#define max_escape_group '~' +#define min_escape_command '@' /* or '`' */ +#define max_escape_command '^' /* or '~' */ + /* Define the state of the parser. */ -typedef struct pcl_parser_state_s { - /* Internal state */ - pcl_scan_type_t scan_type; - pcl_args_t args; - double scale; /* for accumulating floating numbers */ - byte param_class, param_group; /* for parameterized commands */ - uint data_pos; /* for data crossing buffer boundaries */ -} pcl_parser_state_t; +struct pcl_parser_state_s { + /* Internal state */ + pcl_scan_type_t scan_type; + pcl_args_t args; + double scale; /* for accumulating floating numbers */ + byte param_class, param_group; /* for parameterized commands */ + uint data_pos; /* for data crossing buffer boundaries */ + /* + * We register all the PCL5* commands dynamically, for maximum configuration + * flexibility. pcl_command_list points to the individual command + * definitions; as each command is registered, we enter it in the list, and + * then store its index in the actual dispatch table + * (pcl_xxx_command_xxx_indices). + */ + pcl_command_definition_t *pcl_command_list[256]; + int pcl_command_next_index; + /* + * First-level dispatch for control characters. + */ + byte pcl_control_command_indices[33]; + /* + * Second-level dispatch for 2-character escape sequences. + */ + byte pcl_escape_command_indices[max_escape_2char - min_escape_2char + 1]; + /* + * Dispatch on class, group, and command. + */ + byte pcl_grouped_command_indices + [5 /* number of implemented classes, see escape_class_indices above */] + [1 + max_escape_group - min_escape_group + 1] + [max_escape_command - min_escape_command + 1]; + hpgl_parser_state_t *hpgl_parser_state; +}; #define pcl_parser_init_inline(pst)\ ((pst)->scan_type = scanning_none, (pst)->args.data = 0) /* Define the prefix of a macro definition. */ typedef struct pcl_macro_s { - pcl_entity_common; + pcl_data_storage_t storage; } pcl_macro_t; /* ---------------- Procedural interface ---------------- */ @@ -52,4 +88,8 @@ int pcl_execute_macro(P5(const pcl_macro_t *pmac, pcl_state_t *pcs, pcl_copy_operation_t before, pcl_reset_type_t reset, pcl_copy_operation_t after)); +void pcparse_do_reset(P2(pcl_state_t *pcs, pcl_reset_type_t type)); + +void pcl_init_command_index(P1(pcl_parser_state_t *pcl_parser_state)); + #endif /* pcparse_INCLUDED */ diff --git a/pcl/pcpatrn.c b/pcl/pcpatrn.c index 9df1e6b92..cca1fe304 100644 --- a/pcl/pcpatrn.c +++ b/pcl/pcpatrn.c @@ -153,6 +153,7 @@ free_ccolor( */ private int unshare_ccolor( + pcl_state_t * pcs, pcl_ccolor_t ** ppccolor, gs_memory_t * pmem ) @@ -195,7 +196,7 @@ unshare_ccolor( /* set the color space to pure white */ pnew->pbase = 0; - (void)pcl_cs_base_build_white_cspace(&(pnew->pbase), pmem); + (void)pcl_cs_base_build_white_cspace(pcs, &(pnew->pbase), pmem); pnew->ccolor.paint = white_paint; pnew->ccolor.pattern = 0; } @@ -233,7 +234,7 @@ set_unpatterned_color( (pcur->ccolor.paint.values[2] == ppaint->values[2]) ) return 0; - if ( (code = unshare_ccolor(&(pcs->pids->pccolor), pcs->memory)) < 0 ) + if ( (code = unshare_ccolor(pcs, &(pcs->pids->pccolor), pcs->memory)) < 0 ) return code; pcur = pcs->pids->pccolor; @@ -364,7 +365,7 @@ check_pattern_rendering( (pccolor->pbase != pbase) ) { /* get a unique copy, and update the painting information */ - if (unshare_ccolor(&(pptrn->pmask_ccolor), pcs->memory) < 0) + if (unshare_ccolor(pcs, &(pptrn->pmask_ccolor), pcs->memory) < 0) return false; pccolor = pptrn->pmask_ccolor; @@ -427,11 +428,11 @@ render_pattern( /* un-share, or allocate, the appropriate client color */ if (type == pcl_ccolor_mask_pattern) { - code = unshare_ccolor(&(pptrn->pmask_ccolor), pcs->memory); + code = unshare_ccolor(pcs, &(pptrn->pmask_ccolor), pcs->memory); pccolor = pptrn->pmask_ccolor; pcspace = 0; } else { /* type == pcl_ccolor_colored_pattern */ - code = unshare_ccolor(&(pptrn->pcol_ccolor), pcs->memory); + code = unshare_ccolor(pcs, &(pptrn->pcol_ccolor), pcs->memory); pccolor = pptrn->pcol_ccolor; pcspace = pindexed->pcspace; pptrn->transp = pcs->pattern_transparent; @@ -847,7 +848,7 @@ pattern_set_white( return code; /* build the pure white color space and default halftone if necessary */ - if ((code = pcl_cs_base_build_white_cspace(&pwhite_cs, pcs->memory)) >= 0) + if ((code = pcl_cs_base_build_white_cspace(pcs, &pwhite_cs, pcs->memory)) >= 0) code = pcl_ht_build_default_ht(pcs, &pdflt_ht, pcs->memory); /* set the halftone and color space */ @@ -1311,7 +1312,8 @@ set_driver_configuration( * Initialization and reset routines. */ private int -pattern_do_init( +pattern_do_registration( + pcl_parser_state_t *pcl_parser_state, gs_memory_t * pmem ) { @@ -1379,4 +1381,4 @@ pattern_do_reset( } } -const pcl_init_t pcl_pattern_init = { pattern_do_init, pattern_do_reset, 0 }; +const pcl_init_t pcl_pattern_init = { pattern_do_registration, pattern_do_reset, 0 }; diff --git a/pcl/pcpatrn.h b/pcl/pcpatrn.h index 6df770b60..6d5098337 100644 --- a/pcl/pcpatrn.h +++ b/pcl/pcpatrn.h @@ -49,7 +49,7 @@ typedef enum { */ typedef struct pcl_pattern_data_s { gs_depth_bitmap pixinfo; /* pixmap information; must be first */ - pcl_entity_common; /* temporary/permanent/internal flag */ + pcl_data_storage_t storage; /* temporary/permanent/internal flag */ rc_header rc; pcl_pattern_type_t type; /* pattern type */ int xres; /* intended resolution for pattern */ diff --git a/pcl/pcpatxfm.c b/pcl/pcpatxfm.c index 274cde8e4..58c538c90 100644 --- a/pcl/pcpatxfm.c +++ b/pcl/pcpatxfm.c @@ -320,7 +320,8 @@ set_pat_ref_pt( * reference point as well. */ private int -xfm_do_init( +xfm_do_registration( + pcl_parser_state_t *pcl_parser_state, gs_memory_t * pmem ) { @@ -336,4 +337,4 @@ xfm_do_init( return 0; } -const pcl_init_t pcl_xfm_init = { xfm_do_init, 0, 0 }; +const pcl_init_t pcl_xfm_init = { xfm_do_registration, 0, 0 }; diff --git a/pcl/pcrect.c b/pcl/pcrect.c index ff77cd386..09ca3e9f0 100644 --- a/pcl/pcrect.c +++ b/pcl/pcrect.c @@ -212,7 +212,8 @@ pcl_fill_rect_area( * Initialization */ private int -pcrect_do_init( +pcrect_do_registration( + pcl_parser_state_t *pcl_parser_state, gs_memory_t * mem ) { @@ -272,4 +273,4 @@ pcrect_do_reset( } } -const pcl_init_t pcrect_init = { pcrect_do_init, pcrect_do_reset, 0 }; +const pcl_init_t pcrect_init = { pcrect_do_registration, pcrect_do_reset, 0 }; diff --git a/pcl/pcsfont.c b/pcl/pcsfont.c index a0c171760..798cfcd01 100644 --- a/pcl/pcsfont.c +++ b/pcl/pcsfont.c @@ -641,7 +641,10 @@ pcl_alphanumeric_id_data(pcl_args_t *pargs, pcl_state_t *pcs) /* Initialization */ private int -pcsfont_do_init(gs_memory_t *mem) +pcsfont_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem +) { /* Register commands */ DEFINE_CLASS('*') {'c', 'D', @@ -691,5 +694,5 @@ pcsfont_do_copy(pcl_state_t *psaved, const pcl_state_t *pcs, return 0; } const pcl_init_t pcsfont_init = { - pcsfont_do_init, pcsfont_do_reset, pcsfont_do_copy + pcsfont_do_registration, pcsfont_do_reset, pcsfont_do_copy }; diff --git a/pcl/pcstate.h b/pcl/pcstate.h index cf229f480..c9c68869e 100644 --- a/pcl/pcstate.h +++ b/pcl/pcstate.h @@ -11,6 +11,9 @@ #include "gxdevice.h" #include "gdevcmap.h" #include "scommon.h" +#include "gscspace.h" +#include "gscolor2.h" +#include "gscrd.h" #include "gsdcolor.h" /* for gx_ht_tile */ #include "gschar.h" #include "pldict.h" @@ -25,6 +28,9 @@ #include "pcdict.h" /* PL dictionary key structure */ #include "rtrstst.h" /* raster state information */ #include "pcht.h" +#include "pcident.h" +#include "pccsbase.h" + /*#include "pgstate.h"*/ /* HP-GL/2 state, included below */ #include "pjparse.h" @@ -40,6 +46,15 @@ typedef enum id_type_enum { numeric_id } id_type_t; +/* + * Palette stack. This is implemented as a simple linked list. NB + * needs to be moved. + */ +typedef struct pstack_entry_s { + struct pstack_entry_s * pnext; + pcl_palette_t * ppalet; +} pstack_entry_t; + #ifndef pcl_state_DEFINED # define pcl_state_DEFINED typedef struct pcl_state_s pcl_state_t; @@ -255,9 +270,20 @@ struct pcl_state_s { bool monochrome_mode;/* true ==> monochrome print mode */ int render_mode; /* raw (unmapped) render algorithm */ pcl_palette_t * ppalet; + pcl_gsid_t next_id; /* id's for palette's and foreground + colors see pcident.h */ pcl_frgrnd_t * pfrgrnd; + pcl_gsid_t frgnd_cache_id; + pcl_gstate_ids_t * pids; - + /* + * Unlike other elements of the PCL "palette", color rendering dictionaries + * are for the most part not a feature that can be controlled from the language. + * Except for the white point, the parameters of a color rendering dictionary + * are determined by the output device rather than the language. + */ + pcl_crd_t * pcl_default_crd; + /* internal dithers */ pcl_ht_builtin_dither_t ordered_dither; pcl_ht_builtin_dither_t clustered_dither; @@ -271,6 +297,7 @@ struct pcl_state_s { * Several devices are required because the rendering method used by the * foreground may not be the same as that used by the current palette. */ + gs_cie_transform_proc3 dflt_TransformPQR; /* default transform PQR */ gx_device_cmap cmap_device_identity; gx_device_cmap cmap_device_snap_to_primaries; gx_device_cmap cmap_device_color_to_black_over_white; @@ -279,7 +306,12 @@ struct pcl_state_s { byte dflt_rendering_remap[20]; /* NB not convinced this is necessary (review) */ byte rendering_remap[20]; /* remap the table of rendering methods */ pcl_ht_t * pdflt_ht; /* default halftone */ - + pcl_cs_base_t * pwhite_cs; + pcl_frgrnd_t * pdflt_frgrnd; + pstack_entry_t *palette_stack; + pcl_palette_t *pdflt_palette; /* default palette */ + pl_dict_t palette_store; /* dictionary to hold the palette store */ + float color_comps[3]; /* Chapter C5 (pccprint.c) */ byte logical_op; /* (also in graphics state) */ byte pp_mode; /* pixel placement mode */ diff --git a/pcl/pcstatus.c b/pcl/pcstatus.c index a766970f9..3b90e8d47 100644 --- a/pcl/pcstatus.c +++ b/pcl/pcstatus.c @@ -14,6 +14,7 @@ #include "pcstate.h" #include "pcfont.h" #include "pcsymbol.h" +#include "pcparse.h" #include "pcpatrn.h" #include "pcuptrn.h" #include "pcpage.h" @@ -355,7 +356,7 @@ status_macros(stream *s, pcl_state_t *pcs, return 0; /* no "currently selected" macro */ pl_dict_enum_begin(&pcs->macros, &denum); while ( pl_dict_enum_next(&denum, &key, &value) ) - if ( ((pcl_entity_t *)value)->storage & storage ) + if ( ((pcl_macro_t *)value)->storage & storage ) { char id_string[6]; sprintf(id_string, "%u", (key.data[0] << 8) + key.data[1]); status_put_id(s, "IDLIST", id_string); @@ -678,7 +679,10 @@ pcl_echo(pcl_args_t *pargs, pcl_state_t *pcs) /* Initialization */ private int -pcstatus_do_init(gs_memory_t *mem) +pcstatus_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem +) { /* Register commands */ DEFINE_CLASS('*') {'s', 'T', @@ -718,5 +722,5 @@ pcstatus_do_reset(pcl_state_t *pcs, pcl_reset_type_t type) } const pcl_init_t pcstatus_init = { - pcstatus_do_init, pcstatus_do_reset + pcstatus_do_registration, pcstatus_do_reset }; diff --git a/pcl/pcsymbol.c b/pcl/pcsymbol.c index 515493243..116caaac2 100644 --- a/pcl/pcsymbol.c +++ b/pcl/pcsymbol.c @@ -156,7 +156,10 @@ pcl_symbol_set_control(pcl_args_t *pargs, pcl_state_t *pcs) /* Initialization */ private int -pcsymbol_do_init(gs_memory_t *mem) +pcsymbol_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem +) { /* Register commands */ DEFINE_CLASS_COMMAND_ARGS('*', 'c', 'R', "Symbol Set ID Code", pcl_symbol_set_id_code, @@ -307,5 +310,5 @@ pcl_find_symbol_map(const pcl_state_t *pcs, const byte *id, } const pcl_init_t pcsymbol_init = { - pcsymbol_do_init, pcsymbol_do_reset, pcsymbol_do_copy + pcsymbol_do_registration, pcsymbol_do_reset, pcsymbol_do_copy }; diff --git a/pcl/pcsymbol.h b/pcl/pcsymbol.h index c4778f1b7..8363fdb35 100644 --- a/pcl/pcsymbol.h +++ b/pcl/pcsymbol.h @@ -18,8 +18,8 @@ * operations performed per symbol set (affecting all mappings). */ typedef struct pcl_symbol_set_s { - pcl_entity_common; - pl_symbol_map_t *maps[plgv_next]; /* (these may be NULL) */ + pcl_data_storage_t storage; + pl_symbol_map_t *maps[plgv_next]; /* (these may be NULL) */ } pcl_symbol_set_t; /* Check whether a symbol map's character requirements are supported by a diff --git a/pcl/pctext.c b/pcl/pctext.c index 4a931c179..67db58666 100644 --- a/pcl/pctext.c +++ b/pcl/pctext.c @@ -916,7 +916,8 @@ pcl_text_path_direction( /* ------ Initialization ------ */ private int -pctext_do_init( +pctext_do_registration( + pcl_parser_state_t *pcl_parser_state, gs_memory_t * mem ) { @@ -990,4 +991,4 @@ pctext_do_reset( } } -const pcl_init_t pctext_init = { pctext_do_init, pctext_do_reset, 0 }; +const pcl_init_t pctext_init = { pctext_do_registration, pctext_do_reset, 0 }; diff --git a/pcl/pcuptrn.c b/pcl/pcuptrn.c index d433ea5ec..6b0f0bdf2 100644 --- a/pcl/pcuptrn.c +++ b/pcl/pcuptrn.c @@ -514,7 +514,8 @@ delete_cached_patterns_stub( * Initialization and reset routines. */ private int -upattern_do_init( +upattern_do_registration( + pcl_parser_state_t *pcl_parser_state, gs_memory_t * pmem ) { @@ -562,4 +563,4 @@ upattern_do_reset( } } -const pcl_init_t pcl_upattern_init = { upattern_do_init, upattern_do_reset }; +const pcl_init_t pcl_upattern_init = { upattern_do_registration, upattern_do_reset }; diff --git a/pcl/pcursor.c b/pcl/pcursor.c index 5dfbb01ec..bf3fcb331 100644 --- a/pcl/pcursor.c +++ b/pcl/pcursor.c @@ -661,7 +661,8 @@ push_pop_cursor( * Initialization */ private int -pcursor_do_init( +pcursor_do_registration( + pcl_parser_state_t *pcl_parser_state, gs_memory_t * pmem ) { @@ -790,4 +791,4 @@ pcursor_do_reset( } } -const pcl_init_t pcursor_init = { pcursor_do_init, pcursor_do_reset, 0 }; +const pcl_init_t pcursor_init = { pcursor_do_registration, pcursor_do_reset, 0 }; diff --git a/pcl/pgchar.c b/pcl/pgchar.c index c11b59273..7b9be9065 100644 --- a/pcl/pgchar.c +++ b/pcl/pgchar.c @@ -7,6 +7,7 @@ #include "math_.h" #include "stdio_.h" /* for gdebug.h */ #include "gdebug.h" +#include "pcparse.h" #include "pgmand.h" #include "pgdraw.h" #include "pginit.h" @@ -479,7 +480,9 @@ hpgl_TD(hpgl_args_t *pargs, hpgl_state_t *pgls) /* Initialization */ private int -pgchar_do_init(gs_memory_t *mem) +pgchar_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem) { /* Register commands */ DEFINE_HPGL_COMMANDS HPGL_COMMAND('A', 'D', hpgl_AD, 0), /* kind/value pairs */ @@ -507,5 +510,5 @@ pgchar_do_init(gs_memory_t *mem) return 0; } const pcl_init_t pgchar_init = { - pgchar_do_init, 0 + pgchar_do_registration, 0 }; diff --git a/pcl/pgcolor.c b/pcl/pgcolor.c index e8096a1a7..88f87ed02 100644 --- a/pcl/pgcolor.c +++ b/pcl/pgcolor.c @@ -5,6 +5,7 @@ /* pgcolor.c - HP-GL/2 color vector graphics commands */ #include "std.h" +#include "pcparse.h" #include "pgmand.h" #include "pginit.h" #include "pgmisc.h" @@ -117,8 +118,9 @@ hpgl_CR( * carried out by the palette mechanism. */ private int -pgcolor_do_init( - gs_memory_t * mem +pgcolor_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem ) { /* Register commands */ @@ -130,5 +132,4 @@ pgcolor_do_init( return 0; } -const pcl_init_t pgcolor_init = { pgcolor_do_init, 0, 0 }; - +const pcl_init_t pgcolor_init = { pgcolor_do_registration, 0, 0 }; diff --git a/pcl/pgconfig.c b/pcl/pgconfig.c index 2e7db41a9..e0fee4377 100644 --- a/pcl/pgconfig.c +++ b/pcl/pgconfig.c @@ -10,6 +10,7 @@ #include "gsstate.h" /* for gscoord.h */ #include "gscoord.h" #include "pgmand.h" +#include "pcparse.h" #include "pgdraw.h" #include "pginit.h" #include "pggeom.h" @@ -515,7 +516,10 @@ hpgl_BP(hpgl_args_t *pargs, hpgl_state_t *pgls) /* Initialization */ private int -pgconfig_do_init(gs_memory_t *mem) +pgconfig_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem +) { /* Register commands */ DEFINE_HPGL_COMMANDS /* CO has special argument parsing, so it must handle skipping */ @@ -540,5 +544,5 @@ pgconfig_do_init(gs_memory_t *mem) return 0; } const pcl_init_t pgconfig_init = { - pgconfig_do_init, 0 + pgconfig_do_registration, 0 }; diff --git a/pcl/pgframe.c b/pcl/pgframe.c index 5de915fda..6270ac954 100644 --- a/pcl/pgframe.c +++ b/pcl/pgframe.c @@ -152,7 +152,10 @@ pcl_enter_pcl_mode(pcl_args_t *pargs, pcl_state_t *pcs) /* Initialization */ private int -pgframe_do_init(gs_memory_t *mem) +pgframe_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem +) { /* Register commands */ DEFINE_CLASS('*') {'c', 'X', @@ -185,5 +188,5 @@ pgframe_do_init(gs_memory_t *mem) return 0; } const pcl_init_t pgframe_init = { - pgframe_do_init, 0 + pgframe_do_registration, 0 }; diff --git a/pcl/pglabel.c b/pcl/pglabel.c index b6cb91cdb..1dd9b07b0 100644 --- a/pcl/pglabel.c +++ b/pcl/pglabel.c @@ -9,6 +9,7 @@ #include "ctype_.h" #include "stdio_.h" /* for gdebug.h */ #include "gdebug.h" +#include "pcparse.h" #include "plvalue.h" #include "pgmand.h" #include "pginit.h" @@ -1245,7 +1246,10 @@ hpgl_print_symbol_mode_char(hpgl_state_t *pgls) /* Initialization */ private int -pglabel_do_init(gs_memory_t *mem) +pglabel_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem +) { /* Register commands */ DEFINE_HPGL_COMMANDS HPGL_COMMAND('C', 'P', hpgl_CP, hpgl_cdf_lost_mode_cleared), @@ -1255,5 +1259,5 @@ pglabel_do_init(gs_memory_t *mem) return 0; } const pcl_init_t pglabel_init = { - pglabel_do_init, 0 + pglabel_do_registration, 0 }; diff --git a/pcl/pglfill.c b/pcl/pglfill.c index 294d7e572..795311524 100644 --- a/pcl/pglfill.c +++ b/pcl/pglfill.c @@ -4,6 +4,7 @@ /* pglfill.c - HP-GL/2 line and fill attributes commands */ #include "memory_.h" +#include "pcparse.h" #include "pgmand.h" #include "pginit.h" #include "pggeom.h" @@ -846,7 +847,8 @@ hpgl_WU( * Initialization */ private int -pglfill_do_init( +pglfill_do_registration( + pcl_parser_state_t *pcl_parser_state, gs_memory_t * mem ) { @@ -875,4 +877,4 @@ pglfill_do_init( return 0; } -const pcl_init_t pglfill_init = { pglfill_do_init, 0, 0 }; +const pcl_init_t pglfill_init = { pglfill_do_registration, 0, 0 }; diff --git a/pcl/pgmand.h b/pcl/pgmand.h index 9def93732..396d33c27 100644 --- a/pcl/pgmand.h +++ b/pcl/pgmand.h @@ -16,6 +16,11 @@ typedef struct pcl_state_s hpgl_state_t; /* Define the type for HP-GL/2 command arguments. */ +#ifndef hpgl_parser_state_DEFINED +# define hpgl_parser_state_DEFINED +typedef struct hpgl_args_s hpgl_parser_state_t; +#endif + typedef struct hpgl_args_s hpgl_args_t; /* Define a command processing procedure. */ @@ -72,40 +77,50 @@ typedef struct hpgl_value_s { /* Define the structure passed to HP-GL/2 commands. */ struct hpgl_args_s { - /* Parsing state */ - stream_cursor_read source; - int first_letter; /* -1 if we haven't seen the first letter of */ + /* Parsing state */ + stream_cursor_read source; + int first_letter; /* -1 if we haven't seen the first letter of */ /* a command, the letter (0-25) if we have */ - bool done; /* true if we've seen an argument */ + bool done; /* true if we've seen an argument */ /* terminator */ - const hpgl_command_definition_t *command; /* command being executed, */ + hpgl_command_definition_t *command; /* command being executed, */ /* 0 if none */ - jmp_buf exit_to_parser; /* longjmp here if we ran out of data */ + jmp_buf exit_to_parser; /* longjmp here if we ran out of data */ /* while scanning an argument, or we */ /* found a syntax error */ - struct arg_ { /* argument scanning state */ + struct arg_ { /* argument scanning state */ /* State within the current argument */ - int have_value; /* 0 = no value, 1 = int, 2 = real */ - double frac_scale; /* 10 ^ # of digits after dot */ - int sign; /* 0 = none, +/-1 = sign */ + int have_value; /* 0 = no value, 1 = int, 2 = real */ + double frac_scale; /* 10 ^ # of digits after dot */ + int sign; /* 0 = none, +/-1 = sign */ /* State of argument list collection */ - int count; /* # of fully scanned arguments */ - int next; /* # of next scanned arg to return */ - hpgl_value_t scanned[21]; /* args already scanned */ - } arg; - /* Command execution state */ - int phase; /* phase within command, see above */ + int count; /* # of fully scanned arguments */ + int next; /* # of next scanned arg to return */ + hpgl_value_t scanned[21]; /* args already scanned */ + } arg; + /* Command execution state */ + int phase; /* phase within command, see above */ + + /* + * We register all the HP-GL/2 commands dynamically, for maximum + * configuration flexibility. hpgl_command_list points to the individual + * command definitions; as each command is registered, we enter it in the + * list, and then store its index in the actual dispatch table + * (hpgl_command_indices). + */ + hpgl_command_definition_t *hpgl_command_list[100]; + int hpgl_command_next_index; + /* Dispatch tables */ + byte hpgl_command_indices[26][26]; }; -/* Note that this is synonymous with the HP-GL/2 parser state. */ -typedef hpgl_args_t hpgl_parser_state_t; /* Register HP-GL/2 commands. */ typedef struct { char char1, char2; hpgl_command_definition_t defn; } hpgl_named_command_t; -void hpgl_init_command_index(P1(void)); -void hpgl_define_commands(P1(const hpgl_named_command_t *)); +void hpgl_init_command_index(P1(hpgl_parser_state_t *pgl_parser_state)); +void hpgl_define_commands(P2(const hpgl_named_command_t *, hpgl_parser_state_t *pgl_parser_state)); #define DEFINE_HPGL_COMMANDS \ { static const hpgl_named_command_t defs_[] = { #define HPGL_COMMAND(c1, c2, proc, flag)\ @@ -113,7 +128,7 @@ void hpgl_define_commands(P1(const hpgl_named_command_t *)); #define END_HPGL_COMMANDS\ {0, 0}\ };\ - hpgl_define_commands(defs_);\ + hpgl_define_commands(defs_, pcl_parser_state->hpgl_parser_state);\ } /* Define a return code asking for more data. */ diff --git a/pcl/pgparse.c b/pcl/pgparse.c index 04dca5057..025f1dbf1 100644 --- a/pcl/pgparse.c +++ b/pcl/pgparse.c @@ -11,46 +11,41 @@ #include "scommon.h" #include "pgmand.h" -/* - * We register all the HP-GL/2 commands dynamically, for maximum - * configuration flexibility. hpgl_command_list points to the individual - * command definitions; as each command is registered, we enter it in the - * list, and then store its index in the actual dispatch table - * (hpgl_command_indices). - */ -private const hpgl_command_definition_t *hpgl_command_list[100]; -private int hpgl_command_next_index; -/* Dispatch tables */ -private byte hpgl_command_indices[26][26]; - /* ---------------- Command definition ---------------- */ /* Register a command. Return true if this is a redefinition. */ private bool -hpgl_register_command(byte *pindex, const hpgl_command_definition_t *pcmd) -{ int index = hpgl_command_next_index; - byte prev = *pindex; +hpgl_register_command(hpgl_parser_state_t *pgl_parser_state, + byte *pindex, + const hpgl_command_definition_t *pcmd) +{ + int index = pgl_parser_state->hpgl_command_next_index; + byte prev = *pindex; - if ( prev != 0 && prev <= index && hpgl_command_list[prev] == pcmd ) - index = prev; - else if ( index != 0 && hpgl_command_list[index] == pcmd ) - ; - else - hpgl_command_list[hpgl_command_next_index = ++index] = pcmd; - *pindex = index; - return (prev != 0 && prev != index); + if ( prev != 0 && prev <= index && + pgl_parser_state->hpgl_command_list[prev] == pcmd ) + index = prev; + else if ( index != 0 && pgl_parser_state->hpgl_command_list[index] == pcmd ) + ; + else + pgl_parser_state->hpgl_command_list[pgl_parser_state->hpgl_command_next_index = ++index] = pcmd; + *pindex = index; + return (prev != 0 && prev != index); } /* Define a list of commands. */ void -hpgl_define_commands(const hpgl_named_command_t *pcmds) +hpgl_define_commands(const hpgl_named_command_t *pcmds, + hpgl_parser_state_t *pgl_parser_state +) { const hpgl_named_command_t *pcmd = pcmds; for ( ; pcmd->char1; ++pcmd ) #ifdef DEBUG if ( #endif - hpgl_register_command(&hpgl_command_indices + hpgl_register_command(pgl_parser_state, + &pgl_parser_state->hpgl_command_indices [pcmd->char1 - 'A'][pcmd->char2 - 'A'], &pcmd->defn) #ifdef DEBUG @@ -127,7 +122,7 @@ call: if ( pst->command ) { pst->first_letter = next; continue; } - { int index = hpgl_command_indices[pst->first_letter][next]; + { int index = pst->hpgl_command_indices[pst->first_letter][next]; #ifdef DEBUG if ( gs_debug_c('i') ) @@ -141,7 +136,7 @@ call: if ( pst->command ) continue; } pst->first_letter = -1; - pst->command = hpgl_command_list[index]; + pst->command = pst->hpgl_command_list[index]; pst->phase = 0; pst->done = false; hpgl_args_init(pst); @@ -354,9 +349,14 @@ hpgl_arg_units(hpgl_args_t *pargs, hpgl_real_t *pu) return hpgl_arg_real(pargs, pu); } -/* initialize the HPGL command counter (for uninitialized BSS) */ +/* initialize the HPGL command counter */ void -hpgl_init_command_index(void) +hpgl_init_command_index(hpgl_parser_state_t *pgl_parser_state) { - hpgl_command_next_index = 0; + pgl_parser_state->hpgl_command_next_index = 0; + /* NB fix me the parser should not depend on this behavior the + previous design had these in bss which was automatically + cleared to zero. */ + memset(pgl_parser_state->hpgl_command_indices, 0, + sizeof(pgl_parser_state->hpgl_command_indices)); } diff --git a/pcl/pgpoly.c b/pcl/pgpoly.c index 63cd23093..a63c7300b 100644 --- a/pcl/pgpoly.c +++ b/pcl/pgpoly.c @@ -5,6 +5,7 @@ /* pgpoly.c - HP-GL/2 polygon commands */ #include "std.h" +#include "pcparse.h" #include "pgmand.h" #include "pgdraw.h" #include "pggeom.h" @@ -263,7 +264,9 @@ hpgl_WG(hpgl_args_t *pargs, hpgl_state_t *pgls) /* Initialization */ private int -pgpoly_do_init(gs_memory_t *mem) +pgpoly_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem) { /* Register commands */ DEFINE_HPGL_COMMANDS HPGL_COMMAND('E', 'A', hpgl_EA, hpgl_cdf_lost_mode_cleared), @@ -279,5 +282,5 @@ pgpoly_do_init(gs_memory_t *mem) return 0; } const pcl_init_t pgpoly_init = { - pgpoly_do_init, 0 + pgpoly_do_registration, 0 }; diff --git a/pcl/pgvector.c b/pcl/pgvector.c index f15faec29..7eee64e62 100644 --- a/pcl/pgvector.c +++ b/pcl/pgvector.c @@ -7,6 +7,7 @@ #include "stdio_.h" /* for gdebug.h */ #include "gdebug.h" +#include "pcparse.h" #include "pgmand.h" #include "pggeom.h" #include "pgdraw.h" @@ -496,7 +497,10 @@ hpgl_RT(hpgl_args_t *pargs, hpgl_state_t *pgls) /* Initialization */ private int -pgvector_do_init(gs_memory_t *mem) +pgvector_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem +) { /* Register commands */ DEFINE_HPGL_COMMANDS @@ -516,5 +520,5 @@ pgvector_do_init(gs_memory_t *mem) return 0; } const pcl_init_t pgvector_init = { - pgvector_do_init, 0 + pgvector_do_registration, 0 }; diff --git a/pcl/rtcursor.c b/pcl/rtcursor.c index 6b59aeda1..eea6d7ef6 100644 --- a/pcl/rtcursor.c +++ b/pcl/rtcursor.c @@ -38,7 +38,10 @@ rtl_vert_cursor_pos_units(pcl_args_t *pargs, pcl_state_t *pcs) /* Initialization */ private int -rtcursor_do_init(gs_memory_t *mem) +rtcursor_do_registration( + pcl_parser_state_t *pcl_parser_state, + gs_memory_t *mem +) { /* Register commands */ DEFINE_CLASS('&') {'a', 'H', @@ -77,5 +80,5 @@ rtcursor_do_copy(pcl_state_t *psaved, const pcl_state_t *pcs, return 0; } const pcl_init_t rtcursor_init = { - rtcursor_do_init, rtcursor_do_reset, rtcursor_do_copy + rtcursor_do_registration, rtcursor_do_reset, rtcursor_do_copy }; diff --git a/pcl/rtgmode.c b/pcl/rtgmode.c index 7ebfefda4..2aafedf54 100644 --- a/pcl/rtgmode.c +++ b/pcl/rtgmode.c @@ -307,7 +307,7 @@ pcl_end_graphics_mode( gs_matrix dev2pd; /* close the raster; exit graphics mode */ - pcl_complete_raster(); + pcl_complete_raster(pcs); pcs->raster_state.graphics_mode = false; /* get the new current point; then restore the graphic state */ @@ -578,7 +578,8 @@ end_graphics_mode_C( * Initialization */ private int -gmode_do_init( +gmode_do_registration( + pcl_parser_state_t *pcl_parser_state, gs_memory_t * pmem /* ignored */ ) { @@ -684,4 +685,4 @@ gmode_do_reset( } } -const pcl_init_t rtgmode_init = { gmode_do_init, gmode_do_reset, 0 }; +const pcl_init_t rtgmode_init = { gmode_do_registration, gmode_do_reset, 0 }; diff --git a/pcl/rtlrastr.c b/pcl/rtlrastr.c index 0e312ee72..a17be5f86 100644 --- a/pcl/rtlrastr.c +++ b/pcl/rtlrastr.c @@ -31,7 +31,8 @@ set_line_path( * Initialization */ private int -rtlrastr_do_init( +rtlrastr_do_registration( + pcl_parser_state_t *pcl_parser_state, gs_memory_t * mem ) { @@ -47,4 +48,4 @@ rtlrastr_do_init( return 0; } -const pcl_init_t rtlrastr_init = { rtlrastr_do_init, 0, 0 }; +const pcl_init_t rtlrastr_init = { rtlrastr_do_registration, 0, 0 }; diff --git a/pcl/rtmisc.c b/pcl/rtmisc.c index 75537a372..8c1d8d0a8 100644 --- a/pcl/rtmisc.c +++ b/pcl/rtmisc.c @@ -75,17 +75,6 @@ rtl_enter_hpgl_mode( else if (i > 3) return 0; - /**** PARTIAL IMPLEMENTATION ****/ - if (pcs->parse_data != 0) - return 0; /* already in HP-GL/2 mode */ - - pcs->parse_data = gs_alloc_bytes( pcs->memory, - sizeof(hpgl_parser_state_t), - "hpgl parser data(enter hpgl mode)" - ); - if (pcs->parse_data == 0) - return_error(e_Memory); - hpgl_process_init(pcs->parse_data); pcs->parse_other = ( int (*)( void *, pcl_state_t *, stream_cursor_read * @@ -117,7 +106,8 @@ rtl_enter_pcl_mode( { int b = int_arg(pargs) & 1; - if (pcs->parse_data != 0) { + if ( pcs->parse_other == + (int(*)(void *, pcl_state_t *, stream_cursor_read *))hpgl_process ) { /* * We were in HP-GL/2 mode. Destroy the gl/2 polygon path * and conditionally copy back the cursor position. @@ -138,12 +128,6 @@ rtl_enter_pcl_mode( pcs->cap.y = round(pt.y); #undef round } - gs_free_object( pcs->memory, - pcs->parse_data, - "hpgl parser data(enter pcl mode)" - ); - pcs->parse_data = 0; - } else b = 0; @@ -203,7 +187,8 @@ pcl_negative_motion( /* ---------------- Initialization ---------------- */ private int -rtmisc_do_init( +rtmisc_do_registration( + pcl_parser_state_t *pcl_parser_state, gs_memory_t * mem ) { @@ -301,4 +286,4 @@ rtmisc_do_reset( } } -const pcl_init_t rtmisc_init = { rtmisc_do_init, rtmisc_do_reset, 0 }; +const pcl_init_t rtmisc_init = { rtmisc_do_registration, rtmisc_do_reset, 0 }; diff --git a/pcl/rtraster.c b/pcl/rtraster.c index 5e70fdea3..83d990eda 100644 --- a/pcl/rtraster.c +++ b/pcl/rtraster.c @@ -37,44 +37,44 @@ * Structure to describe a PCL raster */ typedef struct pcl_raster_s { - - /* memory used to allocate this structure */ - gs_memory_t * pmem; - - byte nplanes; /* # of planes (seed rows) */ - byte bits_per_plane; /* bits per plane */ - byte nsrcs; /* # of data sources, 1 or 3 */ - - uint transparent:1; /* 1 ==> source transparency */ - uint src_height_set:1; /* source height was set */ - uint indexed:1; /* != 0 ==> indexed color space */ - uint zero_is_white:1; /* all planes 0 ==> white */ - uint zero_is_black:1; /* all planes 0 ==> solid color */ - - int wht_indx; /* white index, for indexed color - space only */ - const void * remap_ary; /* remap array, if needed */ - - pcl_state_t * pcs; /* to avoid n extra operand */ - pcl_cs_indexed_t * pindexed; /* color space */ - - gs_image_enum * pen; /* image enumerator */ - uint16 plane_index; /* next plane to be received */ - uint16 rows_rendered; /* # of source rows rendered */ - uint16 src_width; /* usable raster width */ - uint16 src_height; /* remaining usable raster height */ - - /* objects required for opaque source/transparent pattern case */ - gs_image_enum * mask_pen; /* enumerator for mask */ - pcl_cs_indexed_t * mask_pindexed; /* special color space for mask */ - ulong white_val; /* value interpreted as white */ - void (*gen_mask_row)( struct pcl_raster_s * prast ); - - /* buffers */ - pcl_seed_row_t * pseed_rows; /* seed rows, one per plane */ - byte * cons_buff; /* consolidation buffer */ - byte * mask_buff; /* buffer for mask row, if needed */ - + + /* memory used to allocate this structure */ + gs_memory_t * pmem; + + byte nplanes; /* # of planes (seed rows) */ + byte bits_per_plane; /* bits per plane */ + byte nsrcs; /* # of data sources, 1 or 3 */ + + uint transparent:1; /* 1 ==> source transparency */ + uint src_height_set:1; /* source height was set */ + uint indexed:1; /* != 0 ==> indexed color space */ + uint zero_is_white:1; /* all planes 0 ==> white */ + uint zero_is_black:1; /* all planes 0 ==> solid color */ + + int wht_indx; /* white index, for indexed color + space only */ + const void * remap_ary; /* remap array, if needed */ + + pcl_state_t * pcs; /* to avoid n extra operand */ + pcl_cs_indexed_t * pindexed; /* color space */ + + gs_image_enum * pen; /* image enumerator */ + uint16 plane_index; /* next plane to be received */ + uint16 rows_rendered; /* # of source rows rendered */ + uint16 src_width; /* usable raster width */ + uint16 src_height; /* remaining usable raster height */ + + /* objects required for opaque source/transparent pattern case */ + gs_image_enum * mask_pen; /* enumerator for mask */ + pcl_cs_indexed_t * mask_pindexed; /* special color space for mask */ + ulong white_val; /* value interpreted as white */ + void (*gen_mask_row)( struct pcl_raster_s * prast ); + + /* buffers */ + pcl_seed_row_t * pseed_rows; /* seed rows, one per plane */ + byte * cons_buff; /* consolidation buffer */ + byte * mask_buff; /* buffer for mask row, if needed */ + } pcl_raster_t; /* GC routines */ @@ -90,14 +90,6 @@ gs_private_st_ptrs2( st_raster_t, cons_buff ); -/* - * There is at most one image actively under construction in PCL at one time. - * This pointer points to that image, if it exists. The pointer will be non- - * null while in graphic mode. - */ -private pcl_raster_t * pcur_raster; - - /* forward declaration */ private int process_zero_rows( pcl_raster_t * prast, int nrows ); @@ -946,7 +938,7 @@ add_raster_plane( pcl_state_t * pcs ) { - pcl_raster_t * prast = pcur_raster; + pcl_raster_t * prast = (pcl_raster_t *)pcs->raster_state.pcur_raster; int comp_mode = pcs->raster_state.compression_mode; int nplanes = 0; int plane_index = 0; @@ -956,7 +948,7 @@ add_raster_plane( if (prast == 0) { if ((code = pcl_enter_graphics_mode(pcs, IMPLICIT)) < 0) return code; - prast = pcur_raster; + prast = (pcl_raster_t *)pcs->raster_state.pcur_raster; } /* @@ -1017,7 +1009,7 @@ pcl_start_raster( pcl_state_t * pcs ) { - pcl_raster_t * prast = pcur_raster; + pcl_raster_t * prast = (pcl_raster_t *)pcs->raster_state.pcur_raster; pcl_palette_t * ppalet = pcs->ppalet; pcl_cs_indexed_t * pindexed = ppalet->pindexed; pcl_encoding_type_t penc = pcl_cs_indexed_get_encoding(pindexed); @@ -1025,7 +1017,7 @@ pcl_start_raster( /* there can only be one raster object present at a time */ if (prast != 0) - pcl_complete_raster(); + pcl_complete_raster(pcs); prast = gs_alloc_struct( pcs->memory, pcl_raster_t, @@ -1138,7 +1130,7 @@ pcl_start_raster( } prast->pseed_rows = pseed_rows; - pcur_raster = prast; + pcs->raster_state.pcur_raster = (pcl_raster_type *)prast; /* see if a mask is required */ if ( !pcs->source_transparent && @@ -1186,9 +1178,9 @@ pcl_start_raster( * Complete a raster. This is called when exiting graphics mode. */ void -pcl_complete_raster(void) +pcl_complete_raster(pcl_state_t *pcs) { - pcl_raster_t * prast = pcur_raster; + pcl_raster_t * prast = (pcl_raster_t *)pcs->raster_state.pcur_raster; int i; /* if already in raster mode, ignore */ @@ -1236,7 +1228,7 @@ pcl_complete_raster(void) /* free the PCL raster robject itself */ gs_free_object(prast->pmem, prast, "Complete PCL raster"); - pcur_raster = 0; + pcs->raster_state.pcur_raster = 0; } /* @@ -1273,7 +1265,7 @@ transfer_raster_row( /* complete the row (execpt for adaptive compression) */ if (comp_mode != ADAPTIVE_COMPRESS && code >= 0) - code = process_row(pcur_raster, comp_mode); + code = process_row((pcl_raster_t *)pcs->raster_state.pcur_raster, comp_mode); return code; } @@ -1293,7 +1285,7 @@ raster_y_offset( pcl_state_t * pcs ) { - pcl_raster_t * prast = pcur_raster; + pcl_raster_t * prast = (pcl_raster_t *)pcs->raster_state.pcur_raster; /* ignored outside of graphics mode */ if ((prast != 0) && (uint_arg(pargs) > 0)) { @@ -1309,7 +1301,8 @@ raster_y_offset( * at a higher level. */ private int -raster_do_init( +raster_do_registration( + pcl_parser_state_t *pcl_parser_state, gs_memory_t * pmem /* ignored */ ) { @@ -1346,7 +1339,7 @@ raster_do_reset( ) { if ((type & pcl_reset_initial) != 0) - pcur_raster = 0; + pcs->raster_state.pcur_raster = 0; } -const pcl_init_t rtraster_init = { raster_do_init, raster_do_reset, 0 }; +const pcl_init_t rtraster_init = { raster_do_registration, raster_do_reset, 0 }; diff --git a/pcl/rtraster.h b/pcl/rtraster.h index 5abd4f4f6..51a682f13 100644 --- a/pcl/rtraster.h +++ b/pcl/rtraster.h @@ -22,7 +22,7 @@ int pcl_start_raster(P3( )); /* complete a raster (when exiting raster graphics mode) */ -void pcl_complete_raster(void); +void pcl_complete_raster(pcl_state_t *pcs); extern const pcl_init_t rtraster_init; diff --git a/pcl/rtrstst.h b/pcl/rtrstst.h index f3a8dbb3a..4eb591096 100644 --- a/pcl/rtrstst.h +++ b/pcl/rtrstst.h @@ -7,6 +7,7 @@ #ifndef rtrstst_INCLUDED #define rtrstst_INCLUDED +#include "gsimage.h" #include "gx.h" #include "pccoord.h" @@ -93,6 +94,11 @@ * situations do not arise in practice. */ +#ifndef pcl_raster_t_DEFINED +#define pcl_raster_t_DEFINED +typedef struct pcl_raster_t pcl_raster_type; +#endif pcl_raster_t_DEFINED + typedef struct pcl_raster_state_s { uint resolution; /* source resolution, dots per inch */ @@ -121,6 +127,12 @@ typedef struct pcl_raster_state_s { int clip_all; /* on last entry into raster mode, the raster * origin was at the logical page edge, hence * the raster needs to be clipped */ + pcl_raster_type *pcur_raster; /* There is at most one image + * actively under construction in PCL + * at one time. This pointer points + * to that image, if it exists. The + * pointer will be non-null while in + * graphic mode. */ } pcl_raster_state_t; #endif /* rtrstst_INCLUDED */ |