diff options
author | Ken Sharp <ken.sharp@artifex.com> | 2018-02-07 09:55:41 +0000 |
---|---|---|
committer | Ken Sharp <ken.sharp@artifex.com> | 2018-02-07 10:03:20 +0000 |
commit | d527031607a881237819835c2b1045c81e24c387 (patch) | |
tree | f3c0a488ee19387c398634cdb32f703a6e2c38a5 | |
parent | 28c58b4114ec145b8597372b6e29cec9e1f5df15 (diff) | |
download | ghostpdl-d527031607a881237819835c2b1045c81e24c387.tar.gz |
Alter gs_initgraphcis to once again set the colour space and colour
At some time in the past gs_initgraphics was altered for 'colour substitution'
so that it did not reset the colour space and current colour. This is
surprising because the PostScript initgraphics operator is supposed to
do exactly that.
Restoring the code resulted in many seg faults with the PDF interpreter
so this is obviously a requirement, even though I can't see why.
However, leaving gs_initgraphics as it is would mean that (as per the
comment above the procedure) that all the interpreters (clients) would
have to reset the colour space and colour after calling it, which is
entirely unreasonable. Not only that, it hasn't been done leading to
the PXL interpreter printing error pages in the wrong colour.
This commit restores the setting of the colour space and colour to
gs_initgraphics, but introduces a new gs_initgraphics_no_cpsace()
procedure to be called from zinitgraphics, which behaves exactly as
the modified gs_initgraphics did, and does not set the colour space
or colour values.
The PDF interpreter now continues to work and the PXL interpreter now
prints a number of error pages in black where it previously was using a
pattern, grey or in one case green colour.
-rw-r--r-- | base/gsstate.c | 49 | ||||
-rw-r--r-- | base/gsstate.h | 1 | ||||
-rw-r--r-- | psi/zgstate.c | 2 |
3 files changed, 50 insertions, 2 deletions
diff --git a/base/gsstate.c b/base/gsstate.c index c6540c006..49b2c92cb 100644 --- a/base/gsstate.c +++ b/base/gsstate.c @@ -816,6 +816,53 @@ gs_currentblackptcomp(const gs_gstate * pgs) /* * Reset most of the graphics state. + */ +int +gs_initgraphics(gs_gstate * pgs) +{ + int code; + const gs_gstate gstate_initial = { + gs_gstate_initial(1.0) + }; + + gs_initmatrix(pgs); + if ((code = gs_newpath(pgs)) < 0 || + (code = gs_initclip(pgs)) < 0 || + (code = gs_setlinewidth(pgs, 1.0)) < 0 || + (code = gs_setlinestartcap(pgs, gstate_initial.line_params.start_cap)) < 0 || + (code = gs_setlineendcap(pgs, gstate_initial.line_params.end_cap)) < 0 || + (code = gs_setlinedashcap(pgs, gstate_initial.line_params.dash_cap)) < 0 || + (code = gs_setlinejoin(pgs, gstate_initial.line_params.join)) < 0 || + (code = gs_setcurvejoin(pgs, gstate_initial.line_params.curve_join)) < 0 || + (code = gs_setdash(pgs, (float *)0, 0, 0.0)) < 0 || + (gs_setdashadapt(pgs, false), + (code = gs_setdotlength(pgs, 0.0, false))) < 0 || + (code = gs_setdotorientation(pgs)) < 0 || + (code = gs_setmiterlimit(pgs, gstate_initial.line_params.miter_limit)) < 0 + ) + return code; + gs_init_rop(pgs); + /* Initialize things so that gx_remap_color won't crash. */ + pgs->color[0].color_space = gs_cspace_new_DeviceGray(pgs->memory); + if (pgs->color[0].color_space == NULL) + return_error(gs_error_unknownerror); + pgs->color[1].color_space = gs_cspace_new_DeviceGray(pgs->memory); + if (pgs->color[1].color_space == NULL) + return_error(gs_error_unknownerror); + pgs->in_cachedevice = 0; + gs_swapcolors_quick(pgs); /* To color 1 */ + code = gx_set_device_color_1(pgs); /* sets colorspace and client color */ + if (code < 0) + return code; + gs_swapcolors_quick(pgs); /* To color 0 */ + code = gx_set_device_color_1(pgs); /* sets colorspace and client color */ + if (code < 0) + return code; + return 0; +} + +/* + * Reset most of the graphics state. * * NB: This routine no longer resets the current color or current color * space. It cannot do this for PostScript, due to color substitution. @@ -823,7 +870,7 @@ gs_currentblackptcomp(const gs_gstate * pgs) * initializaion themselves. */ int -gs_initgraphics(gs_gstate * pgs) +gs_initgraphics_no_cspace(gs_gstate * pgs) { int code; const gs_gstate gstate_initial = { diff --git a/base/gsstate.h b/base/gsstate.h index 6c651adc4..a954132ce 100644 --- a/base/gsstate.h +++ b/base/gsstate.h @@ -66,6 +66,7 @@ int gs_currentblackptcomp(const gs_gstate *); int gs_setblackptcomp(gs_gstate *, int); int gs_initgraphics(gs_gstate *); +int gs_initgraphics_no_cspace(gs_gstate *); bool gs_currentcpsimode(const gs_memory_t *); void gs_setcpsimode(gs_memory_t *, bool); diff --git a/psi/zgstate.c b/psi/zgstate.c index 254335c0e..28f80cb6b 100644 --- a/psi/zgstate.c +++ b/psi/zgstate.c @@ -192,7 +192,7 @@ zinitgraphics(i_ctx_t *i_ctx_p) * this is now handled in the PostScript code. */ make_empty_array(&istate->dash_pattern_array, a_all); - return gs_initgraphics(igs); + return gs_initgraphics_no_cspace(igs); } /* ------ Operations on graphics state elements ------ */ |