[gs-commits] ghostpdl branch, pdfi, updated. jbig2dec-0.14-2101-g7ca4837
[email protected] (Nancy Durgin)
| Newsgroups | gmane.comp.printing.ghostscript.cvs |
|---|---|
| Message-ID | <[email protected]> |
The ghostpdl branch, pdfi has been updated
via 7ca48379e8429cac855c4d5acfbc2c5956e15bc8 (commit)
from 6f7d75d99d10d050a5585b943cf47207c3f154b7 (commit)
----------------------------------------------------------------------
commit 7ca48379e8429cac855c4d5acfbc2c5956e15bc8
Author: Nancy Durgin <[email protected]>
Date: Tue Aug 6 11:49:25 2019 -0700
Fix segfault and some cleanups related to DefaultQState and patterns
Fixed segfault on pgmraw device with tests_private/comparefiles/Bug691763.pdf
The issue was that the saved ctx->base_pgs (now renamed DefaultQState
to match ps code) was saved before the transparency device was
installed, so it had the wrong device in it for the transparency case
(wreaking havoc).
Added better support for "DefaultQState", so it will have the correct
device in it. Added accessor functions.
Change to set the DefaultQState after transparency has been handled, so the
device will be correct.
Also changed a gsave/grestore to a q/Q to match gs implementation.
diff --git a/pdf/ghostpdf.c b/pdf/ghostpdf.c
index 55743e4..6650630 100644
--- a/pdf/ghostpdf.c
+++ b/pdf/ghostpdf.c
@@ -1587,13 +1587,6 @@ static int pdfi_render_page(pdf_context *ctx, uint64_t page_num)
code = gs_settexthscaling(ctx->pgs, (double)100.0);
ctx->TextBlockDepth = 0;
- /* Init a base_pgs graphics state for Patterns */
- if (ctx->base_pgs) {
- gs_gstate_free(ctx->base_pgs);
- ctx->base_pgs = NULL;
- }
- ctx->base_pgs = gs_gstate_copy(ctx->pgs, ctx->memory);
-
dbgmprintf1(ctx->memory, "Current page transparency setting is %d\n", ctx->PageTransparencyArray[page_index] & page_bit ? 1 : 0);
/* Force NOTRANSPARENCY here if required, until we can get it working... */
@@ -1626,6 +1619,11 @@ static int pdfi_render_page(pdf_context *ctx, uint64_t page_num)
}
}
+ /* Init a base_pgs graphics state for Patterns
+ * (this has to be after transparency device pushed, if applicable)
+ */
+ pdfi_set_DefaultQState(ctx, ctx->pgs);
+
/* Save the current stream state, for later cleanup, in a local variable */
local_save_stream_state(ctx, &local_entry_save);
initialise_stream_save(ctx);
@@ -2260,10 +2258,7 @@ int pdfi_free_context(gs_memory_t *pmem, pdf_context *ctx)
ctx->pgs = NULL;
}
- if(ctx->base_pgs != NULL) {
- gs_gstate_free(ctx->base_pgs);
- ctx->base_pgs = NULL;
- }
+ pdfi_free_DefaultQState(ctx);
if (ctx->pdfi_param_list.head != NULL)
gs_c_param_list_release(&ctx->pdfi_param_list);
diff --git a/pdf/ghostpdf.h b/pdf/ghostpdf.h
index 926dfd7..67608c0 100644
--- a/pdf/ghostpdf.h
+++ b/pdf/ghostpdf.h
@@ -238,7 +238,7 @@ typedef struct pdf_context_s
/* This is currently used for Patterns, but I suspect needs to be changed to use
* 'the enclosing context'
*/
- gs_gstate *base_pgs;
+ gs_gstate *DefaultQState;
int preserve_tr_mode; /* for avoiding charpath with pdfwrite */
diff --git a/pdf/pdf_gstate.c b/pdf/pdf_gstate.c
index bdf396f..101fd0c 100644
--- a/pdf/pdf_gstate.c
+++ b/pdf/pdf_gstate.c
@@ -912,3 +912,26 @@ int pdfi_setgstate(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict)
pdfi_countdown(o);
return code;
}
+
+
+int pdfi_free_DefaultQState(pdf_context *ctx)
+{
+ int code = 0;
+
+ if (ctx->DefaultQState)
+ code = gs_gstate_free(ctx->DefaultQState);
+ ctx->DefaultQState = NULL;
+ return code;
+}
+
+int pdfi_set_DefaultQState(pdf_context *ctx, gs_gstate *pgs)
+{
+ pdfi_free_DefaultQState(ctx);
+ ctx->DefaultQState = gs_gstate_copy(ctx->pgs, ctx->memory);
+ return 0;
+}
+
+gs_gstate *pdfi_get_DefaultQState(pdf_context *ctx)
+{
+ return ctx->DefaultQState;
+}
diff --git a/pdf/pdf_gstate.h b/pdf/pdf_gstate.h
index b1415e9..08e90ec 100644
--- a/pdf/pdf_gstate.h
+++ b/pdf/pdf_gstate.h
@@ -38,4 +38,8 @@ int pdfi_setdash(pdf_context *ctx);
int pdfi_setmiterlimit(pdf_context *ctx);
int pdfi_setgstate(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict);
+int pdfi_free_DefaultQState(pdf_context *ctx);
+int pdfi_set_DefaultQState(pdf_context *ctx, gs_gstate *pgs);
+gs_gstate *pdfi_get_DefaultQState(pdf_context *ctx);
+
#endif
diff --git a/pdf/pdf_pattern.c b/pdf/pdf_pattern.c
index ec3aaf5..f977609 100644
--- a/pdf/pdf_pattern.c
+++ b/pdf/pdf_pattern.c
@@ -161,7 +161,7 @@ pdfi_pattern_paint(const gs_client_color *pcc, gs_gstate *pgs)
pdf_context *ctx = context->ctx;
int code = 0;
- code = pdfi_gsave(ctx);
+ code = pdfi_op_q(ctx);
if (code < 0)
return code;
code = gs_setgstate(ctx->pgs, pgs);
@@ -175,7 +175,7 @@ pdfi_pattern_paint(const gs_client_color *pcc, gs_gstate *pgs)
}
exit:
- pdfi_grestore(ctx);
+ pdfi_op_Q(ctx);
return code;
}
@@ -280,14 +280,15 @@ pdfi_pattern_paintproc(const gs_client_color *pcc, gs_gstate *pgs)
static int
pdfi_pattern_gset(pdf_context *ctx)
{
- int code, level = ctx->pgs->level;
+ int code, level;
float strokealpha, fillalpha;
strokealpha = gs_getstrokeconstantalpha(ctx->pgs);
fillalpha = gs_getfillconstantalpha(ctx->pgs);
- code = gs_copygstate(ctx->pgs, ctx->base_pgs);
- if (code < 0)
- goto exit;
+
+ /* TODO: Apparently gs_copygstate() isn't really the right thing, especially considering
+ ken's comment below. Need to figure this out!
+ */
/* gs_copygstate also copies the save depth, this seems to me like a bad idea!
* It certainly causes problems for us because we pay attention to the save depth
* when processing pdfi_gsave/pdfi_grestore and also at the end of processing
@@ -295,7 +296,14 @@ pdfi_pattern_gset(pdf_context *ctx)
* graphics library gs_gsave/grestore, we must ensure that the save level
* doesn't get overwritten.
*/
+ /* TODO: Hack? Save the things we don't want to overwrite... */
+ level = ctx->pgs->level;
+ code = gs_copygstate(ctx->pgs, pdfi_get_DefaultQState(ctx));
+ /* TODO: Hack? Put back the things we don't want to overwrite... */
ctx->pgs->level = level;
+
+ if (code < 0)
+ goto exit;
code = gs_setstrokeconstantalpha(ctx->pgs, strokealpha);
code = gs_setfillconstantalpha(ctx->pgs, fillalpha);
Summary of changes:
pdf/ghostpdf.c | 17 ++++++-----------
pdf/ghostpdf.h | 2 +-
pdf/pdf_gstate.c | 23 +++++++++++++++++++++++
pdf/pdf_gstate.h | 4 ++++
pdf/pdf_pattern.c | 20 ++++++++++++++------
5 files changed, 48 insertions(+), 18 deletions(-)