summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2021-06-09 15:33:16 +0100
committerRobin Watts <Robin.Watts@artifex.com>2021-08-10 11:06:14 +0100
commit09a246ab21cab8e926f0d625641c44c628b78b08 (patch)
tree36e946536750bad4e3622d0b4ae99a6ef4ffc618
parent1820019588377543f92d29d3f46e973ab4903d7c (diff)
downloadghostpdl-09a246ab21cab8e926f0d625641c44c628b78b08.tar.gz
Add -dRESETRESOURCES option for gpdl.
In this instance 'RESOURCES' means fonts, macros, symbol sets etc. This applies to PCL (and maybe others), but not Postscript resources. Default (and setting this to 0) gives the behaviour where resources are never reset based upon job language changes. Setting this to 1 causes resources to be reset between jobs (whenever we return to PJL). Setting this to 2 causes resources to be reset whenever we "change language". For this setting, we do not count returning to PJL and reentering the same language as being a language change. (Includes fixes and code from Henry Stiles).
-rw-r--r--gpdl/jbig2top.c3
-rw-r--r--gpdl/jp2ktop.c3
-rw-r--r--gpdl/jpgtop.c3
-rw-r--r--gpdl/pngtop.c3
-rw-r--r--gpdl/psitop.c3
-rw-r--r--gpdl/pwgtop.c3
-rw-r--r--gpdl/tifftop.c3
-rw-r--r--pcl/pcl/pctop.c14
-rw-r--r--pcl/pl/pjparsei.c3
-rw-r--r--pcl/pl/plmain.c56
-rw-r--r--pcl/pl/pltop.c7
-rw-r--r--pcl/pl/pltop.h8
-rw-r--r--pcl/pxl/pxtop.c3
13 files changed, 100 insertions, 12 deletions
diff --git a/gpdl/jbig2top.c b/gpdl/jbig2top.c
index a9ba74889..4a453c273 100644
--- a/gpdl/jbig2top.c
+++ b/gpdl/jbig2top.c
@@ -608,5 +608,6 @@ const pl_interp_implementation_t jbig2_implementation = {
jbig2_impl_report_errors,
jbig2_impl_dnit_job,
jbig2_impl_deallocate_interp_instance,
- NULL
+ NULL, /* jbig2_impl_reset */
+ NULL /* interp_client_data */
};
diff --git a/gpdl/jp2ktop.c b/gpdl/jp2ktop.c
index ef69fd2f5..3ceba9b07 100644
--- a/gpdl/jp2ktop.c
+++ b/gpdl/jp2ktop.c
@@ -721,5 +721,6 @@ const pl_interp_implementation_t jp2k_implementation = {
jp2k_impl_report_errors,
jp2k_impl_dnit_job,
jp2k_impl_deallocate_interp_instance,
- NULL
+ NULL, /* jp2k_impl_reset */
+ NULL /* interp_client_data */
};
diff --git a/gpdl/jpgtop.c b/gpdl/jpgtop.c
index 652ca4832..56651a262 100644
--- a/gpdl/jpgtop.c
+++ b/gpdl/jpgtop.c
@@ -870,5 +870,6 @@ const pl_interp_implementation_t jpg_implementation = {
jpg_impl_report_errors,
jpg_impl_dnit_job,
jpg_impl_deallocate_interp_instance,
- NULL
+ NULL, /* jpg_impl_reset */
+ NULL /* interp_client_data */
};
diff --git a/gpdl/pngtop.c b/gpdl/pngtop.c
index ea042b5d4..fad4e2fa2 100644
--- a/gpdl/pngtop.c
+++ b/gpdl/pngtop.c
@@ -795,5 +795,6 @@ const pl_interp_implementation_t png_implementation = {
png_impl_report_errors,
png_impl_dnit_job,
png_impl_deallocate_interp_instance,
- NULL
+ NULL, /* png_impl_reset */
+ NULL /* interp_client_data */
};
diff --git a/gpdl/psitop.c b/gpdl/psitop.c
index 3f49d8209..e509c4618 100644
--- a/gpdl/psitop.c
+++ b/gpdl/psitop.c
@@ -663,5 +663,6 @@ const pl_interp_implementation_t ps_implementation = {
ps_impl_report_errors,
ps_impl_dnit_job,
ps_impl_deallocate_interp_instance,
- NULL
+ NULL, /* ps_impl_reset */
+ NULL /* interp_client_data */
};
diff --git a/gpdl/pwgtop.c b/gpdl/pwgtop.c
index fbf860e2e..a8d628695 100644
--- a/gpdl/pwgtop.c
+++ b/gpdl/pwgtop.c
@@ -717,5 +717,6 @@ const pl_interp_implementation_t pwg_implementation = {
pwg_impl_report_errors,
pwg_impl_dnit_job,
pwg_impl_deallocate_interp_instance,
- NULL
+ NULL, /* pwg_impl_reset */
+ NULL /* interp_client_data */
};
diff --git a/gpdl/tifftop.c b/gpdl/tifftop.c
index dbd86bf29..10a9ebcc7 100644
--- a/gpdl/tifftop.c
+++ b/gpdl/tifftop.c
@@ -1123,5 +1123,6 @@ const pl_interp_implementation_t tiff_implementation = {
tiff_impl_report_errors,
tiff_impl_dnit_job,
tiff_impl_deallocate_interp_instance,
- NULL
+ NULL, /* tiff_impl_reset */
+ NULL /* interp_client_data */
};
diff --git a/pcl/pcl/pctop.c b/pcl/pcl/pctop.c
index ebc9ccffe..e4ba5fece 100644
--- a/pcl/pcl/pctop.c
+++ b/pcl/pcl/pctop.c
@@ -568,6 +568,17 @@ pcl_impl_deallocate_interp_instance(pl_interp_implementation_t * impl /* ins
return 0;
}
+static int
+pcl_impl_reset(pl_interp_implementation_t *impl, pl_interp_reset_reason reason)
+{
+ pcl_interp_instance_t *pcli = impl->interp_client_data;
+
+ if (reason != PL_RESET_RESOURCES)
+ return 0;
+
+ return pcl_do_resets(&pcli->pcs, pcl_reset_permanent);
+}
+
/*
* End-of-page called back by PCL - NB now exported.
*/
@@ -598,5 +609,6 @@ pl_interp_implementation_t pcl_implementation = {
pcl_impl_report_errors,
pcl_impl_dnit_job,
pcl_impl_deallocate_interp_instance,
- NULL
+ pcl_impl_reset,
+ NULL /* interp_client_data */
};
diff --git a/pcl/pl/pjparsei.c b/pcl/pl/pjparsei.c
index 343956253..05097f11b 100644
--- a/pcl/pl/pjparsei.c
+++ b/pcl/pl/pjparsei.c
@@ -185,5 +185,6 @@ pl_interp_implementation_t pjl_implementation = {
pjl_impl_report_errors,
pjl_impl_dnit_job,
pjl_impl_deallocate_interp_instance,
- NULL, /* instance */
+ NULL, /* pjl_impl_reset */
+ NULL, /* interp_client_data */
};
diff --git a/pcl/pl/plmain.c b/pcl/pl/plmain.c
index 0450648ab..a8850d83b 100644
--- a/pcl/pl/plmain.c
+++ b/pcl/pl/plmain.c
@@ -99,6 +99,18 @@ typedef struct
#define BUFFERED_FILE_CHUNK_SHIFT 20
#define BUFFERED_FILE_CHUNK_SIZE (1<<BUFFERED_FILE_CHUNK_SHIFT)
+typedef enum {
+ /* Default: Never reset resources automatically on job changes. */
+ PL_RESET_RESOURCES_NEVER = 0,
+
+ /* Reset resources whenver we drop back to PJL. */
+ PL_RESET_RESOURCES_ON_PJL = 1,
+
+ /* Reset resources whenever we change language (other than to drop
+ * back to PJL). */
+ PL_RESET_RESOURCES_ON_LANGUAGE_CHANGE = 2
+} pl_resource_reset;
+
/*
* Main instance for all interpreters.
*/
@@ -145,6 +157,12 @@ struct pl_main_instance_s
pl_interp_implementation_t **implementations;
pl_interp_implementation_t *curr_implementation;
+ /* We keep track of the last (non PJL) implementation we used.
+ * This is used to conditionally reset soft fonts etc. */
+ pl_interp_implementation_t *prev_non_pjl_implementation;
+
+ pl_resource_reset reset_resources;
+
/* When processing data via 'run_string', interpreters may not
* completely consume the data they are passed each time. We use
* this buffer to carry over data between calls. */
@@ -362,7 +380,18 @@ revert_to_pjli(pl_main_instance_t *minst)
return code;
}
}
+ minst->curr_implementation = NULL;
+ /* We may want to reset the fonts. */
+ if (minst->prev_non_pjl_implementation &&
+ minst->reset_resources == PL_RESET_RESOURCES_ON_PJL) {
+ if_debug1m('I', minst->memory, "Resetting resources (%s)\n",
+ pl_characteristics(minst->curr_implementation)->language);
+ code = pl_reset(minst->prev_non_pjl_implementation, PL_RESET_RESOURCES);
+ if (code < 0)
+ return code;
+ }
minst->curr_implementation = pjli;
+
code = pl_init_job(minst->curr_implementation, minst->device);
return code;
@@ -907,11 +936,26 @@ pl_main_run_file_utf8(pl_main_instance_t *minst, const char *prefix_commands, co
/* If the language implementation needs changing, change it. */
if (desired_implementation != pjli) {
+
+ /* If we are being asked to swap to a language implementation
+ * that is different to the last (non-PJL) implementation that
+ * we were using, we may want to clear soft-fonts. */
+ if (minst->prev_non_pjl_implementation &&
+ minst->reset_resources == PL_RESET_RESOURCES_ON_LANGUAGE_CHANGE &&
+ desired_implementation != minst->prev_non_pjl_implementation) {
+ if_debug1m('I', mem, "Resetting resources (%s)\n",
+ pl_characteristics(minst->curr_implementation)->language);
+ code = pl_reset(minst->prev_non_pjl_implementation, PL_RESET_RESOURCES);
+ if (code < 0)
+ goto error_fatal;
+ }
+
code = pl_dnit_job(pjli);
minst->curr_implementation = NULL;
if (code >= 0)
code = pl_init_job(desired_implementation, minst->device);
minst->curr_implementation = desired_implementation;
+ minst->prev_non_pjl_implementation = desired_implementation;
if (code < 0)
goto error_fatal;
}
@@ -1294,6 +1338,8 @@ pl_main_alloc_instance(gs_memory_t * mem)
minst->pause = true;
minst->device = 0;
minst->implementation = NULL;
+ minst->prev_non_pjl_implementation = NULL;
+ minst->reset_resources = PL_RESET_RESOURCES_NEVER;
minst->base_time[0] = 0;
minst->base_time[1] = 0;
minst->interpolate = false;
@@ -1475,6 +1521,10 @@ static int check_for_special_int(pl_main_instance_t * pmi, const char *arg, int6
pmi->scanconverter = b;
return 0;
}
+ if (argcmp(arg, "RESETRESOURCES", 10)) {
+ pmi->reset_resources = b;
+ return 0;
+ }
return 1;
}
@@ -1484,7 +1534,8 @@ static int check_for_special_float(pl_main_instance_t * pmi, const char *arg, fl
argcmp(arg, "NOPAUSE", 7) ||
argcmp(arg, "DOINTERPOLATE", 13) ||
argcmp(arg, "NOCACHE", 7) ||
- argcmp(arg, "SCANCONVERTERTYPE", 17)) {
+ argcmp(arg, "SCANCONVERTERTYPE", 17) ||
+ argcmp(arg, "RESETRESOURCES", 10)) {
return gs_note_error(gs_error_rangecheck);
}
return 1;
@@ -1496,7 +1547,8 @@ static int check_for_special_str(pl_main_instance_t * pmi, const char *arg, gs_p
argcmp(arg, "NOPAUSE", 7) ||
argcmp(arg, "DOINTERPOLATE", 13) ||
argcmp(arg, "NOCACHE", 7) ||
- argcmp(arg, "SCANCONVERTERTYPE", 17)) {
+ argcmp(arg, "SCANCONVERTERTYPE", 17) ||
+ argcmp(arg, "RESETRESOURCES", 10)) {
return gs_note_error(gs_error_rangecheck);
}
return 1;
diff --git a/pcl/pl/pltop.c b/pcl/pl/pltop.c
index 0c2936890..174b3362b 100644
--- a/pcl/pl/pltop.c
+++ b/pcl/pl/pltop.c
@@ -217,3 +217,10 @@ pl_deallocate_interp_instance(pl_interp_implementation_t * impl) /* instance t
return 0;
return impl->proc_deallocate_interp_instance(impl);
}
+
+int pl_reset(pl_interp_implementation_t *impl, pl_interp_reset_reason reason)
+{
+ if (impl->reset == NULL)
+ return 0;
+ return impl->reset(impl, reason);
+}
diff --git a/pcl/pl/pltop.h b/pcl/pl/pltop.h
index 099292136..4a5bd8b23 100644
--- a/pcl/pl/pltop.h
+++ b/pcl/pl/pltop.h
@@ -155,6 +155,13 @@ typedef int (*pl_interp_proc_dnit_job_t) (pl_interp_implementation_t *);
int pl_deallocate_interp_instance(pl_interp_implementation_t *);
typedef int (*pl_interp_proc_deallocate_interp_instance_t) (pl_interp_implementation_t *);
+typedef enum {
+ PL_RESET_RESOURCES = 1
+} pl_interp_reset_reason;
+
+int pl_reset(pl_interp_implementation_t *, pl_interp_reset_reason reason);
+typedef int (*pl_interp_proc_reset_t)(pl_interp_implementation_t *, pl_interp_reset_reason);
+
/*
* Define a generic interpreter implementation
*/
@@ -179,6 +186,7 @@ struct pl_interp_implementation_s
pl_interp_proc_dnit_job_t proc_dnit_job;
pl_interp_proc_deallocate_interp_instance_t
proc_deallocate_interp_instance;
+ pl_interp_proc_reset_t reset;
void *interp_client_data;
};
diff --git a/pcl/pxl/pxtop.c b/pcl/pxl/pxtop.c
index 1e3a2b958..dd7c79f85 100644
--- a/pcl/pxl/pxtop.c
+++ b/pcl/pxl/pxtop.c
@@ -566,7 +566,8 @@ pl_interp_implementation_t pxl_implementation = {
pxl_impl_report_errors,
pxl_impl_dnit_job,
pxl_impl_deallocate_interp_instance,
- NULL
+ NULL, /* pxl_impl_reset */
+ NULL /* interp_client_data */
};
/* ---------- Utility Procs ----------- */