diff options
author | Ken Sharp <ken.sharp@artifex.com> | 2018-02-12 12:21:50 +0000 |
---|---|---|
committer | Ken Sharp <ken.sharp@artifex.com> | 2018-02-12 12:21:50 +0000 |
commit | 7a708d9fdcba9efbe21f236830e47eb4f4085672 (patch) | |
tree | 6c9f9513e37681e58fe73ed9cbf21ed6eb69b188 /base/gsstate.c | |
parent | 1af4fced38d9d842195e5635c9e0aa4b5e13f21b (diff) | |
download | ghostpdl-7a708d9fdcba9efbe21f236830e47eb4f4085672.tar.gz |
More work with initgraphics
Firstly, remove the kludgy gs_initgraphics_no_cspace() and have the
PostScript operator zinitgraphics() call gs_initgraphics().
This meant fixing the gs_initgraphics routine; the previous commit
d527031607a881237819835c2b1045c81e24c387 simply overwrote the existing
colour spaces in the graphics state with the new DeviceGray space. This
could lead to memory leaks if the previous colour space had been
reference counted up. So now we call gs_setcolorspace instead, which also
correctly sets the current colour.
This led to the interesting discovery that the null brush in PXL has
never been handled properly by the high level devices. This is
handled by the PXL interpreter setting a DeviceGray colour space, and
then directly editing the device colour 'type' field and setting it to
'typ_null'. This doesn't seem like the best way to proceed to me, I
would have expected us to push the nulldevice, but its what is done.
No in gx_hld_is_hl_color_available() the code simply tested whether
the device color 'ccolor_valid' flag was set. Since the PXL interpreter
simply stomped on the type field, and did not update any of the other
fields, the result of this was unknown. Sometimes we would decide it
was valid, and sometimes not. If we did decide it was valid then we
used the DeviceGray space and colour (0, black) which was also set up
by the null brush code to draw the object, which means that we could
end up drawing objects which should not be drawn.
'Fixed' this by having the code explicitly test for the device color
type being 'null' as well as being valid. In passing, it did appear
to me that we do not always update the ccolor_valid flag in the device
color structure, which may well lead to more problems of this kind.
This does result in a number of differences in the output. Mostly
these are due to the error page now always being rendered in DeviceGray
which results in a slightly (invisible) difference in printed gray text.
A very large number of the Quality Logic files exhibit progressions
due to the fact that we are now correctly processing the null brush.
Diffstat (limited to 'base/gsstate.c')
-rw-r--r-- | base/gsstate.c | 105 |
1 files changed, 56 insertions, 49 deletions
diff --git a/base/gsstate.c b/base/gsstate.c index a79849053..63ee3206c 100644 --- a/base/gsstate.c +++ b/base/gsstate.c @@ -828,57 +828,64 @@ gs_initgraphics(gs_gstate * pgs) 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; -} + if (pgs->icc_manager->default_gray == 0x00) { + gs_color_space *pcs1, *pcs2; + + pcs1 = gs_cspace_new_DeviceGray(pgs->memory); + if (pcs1 == NULL) + return_error(gs_error_unknownerror); + + if (pgs->color[0].color_space != NULL) + gs_setcolorspace(pgs, pcs1); + else { + pgs->color[0].color_space = pcs1; + gs_setcolorspace(pgs, pcs1); + } -/* - * 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. - * Clients should perform the appropriate color/colorspace - * initializaion themselves. - */ -int -gs_initgraphics_no_cspace(gs_gstate * pgs) -{ - int code; - const gs_gstate gstate_initial = { - gs_gstate_initial(1.0) - }; + gs_swapcolors_quick(pgs); /* To color 1 */ + + pcs2 = gs_cspace_new_DeviceGray(pgs->memory); + if (pcs2 == NULL) + return_error(gs_error_unknownerror); + + if (pgs->color[0].color_space != NULL) + gs_setcolorspace(pgs, pcs2); + else { + pgs->color[0].color_space = pcs2; + gs_setcolorspace(pgs, pcs2); + } + + gs_swapcolors_quick(pgs); /* To color 0 */ + } else { + gs_color_space *pcs1, *pcs2; + + pcs1 = gs_cspace_new_ICC(pgs->memory, pgs, 1);; + if (pcs1 == NULL) + return_error(gs_error_unknownerror); + + if (pgs->color[0].color_space != NULL) + gs_setcolorspace(pgs, pcs1); + else { + pgs->color[0].color_space = pcs1; + gs_setcolorspace(pgs, pcs1); + } + + gs_swapcolors_quick(pgs); /* To color 1 */ + pcs2 = gs_cspace_new_ICC(pgs->memory, pgs, 1);; + if (pcs2 == NULL) + return_error(gs_error_unknownerror); + + if (pgs->color[0].color_space != NULL) + gs_setcolorspace(pgs, pcs2); + else { + pgs->color[0].color_space = pcs2; + gs_setcolorspace(pgs, pcs2); + } + + gs_swapcolors_quick(pgs); /* To color 0 */ + } + pgs->in_cachedevice = 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); return 0; } |