summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-07-16 13:13:39 +0100
committerRobin Watts <robin.watts@artifex.com>2015-07-20 17:19:04 +0100
commitbf460079428bf678a73cdcbcd13b58f88e29f3a8 (patch)
tree318d702a2652c5bfca2c315a15aebe92d4087474 /source
parent28432abe9a2fcdb47750c0e49cb484c615f5a883 (diff)
downloadmupdf-bf460079428bf678a73cdcbcd13b58f88e29f3a8.tar.xz
Gproof doc handler; add ability to call gs via gsapi rather than exe.
Diffstat (limited to 'source')
-rw-r--r--source/gprf/gprf-doc.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/source/gprf/gprf-doc.c b/source/gprf/gprf-doc.c
index e9638340..103b8e1e 100644
--- a/source/gprf/gprf-doc.c
+++ b/source/gprf/gprf-doc.c
@@ -4,6 +4,11 @@ typedef struct gprf_document_s gprf_document;
typedef struct gprf_chapter_s gprf_chapter;
typedef struct gprf_page_s gprf_page;
+/* Choose whether to call gs via an exe or via an API */
+#ifdef __ANDROID__
+#define USE_GS_API
+#endif
+
enum
{
GPRF_TILESIZE = 256
@@ -446,13 +451,40 @@ generate_page(fz_context *ctx, gprf_page *page)
sprintf(nameroot, "gprf_%d_", page->number);
filename = fz_tempfilename(ctx, nameroot, doc->pdf_filename);
- /* Invoke gs to convert to a temp file. */
- sprintf(gs_command, "gswin32c.exe -sDEVICE=gproof -r%d -o \"%s\" -dFirstPage=%d -dLastPage=%d %s",
- doc->res, filename, page->number+1, page->number+1, doc->pdf_filename);
-
fz_try(ctx)
{
+#ifdef USE_GS_API
+ void **instance;
+ int code;
+ char *argv[] = { "gs", "-sDEVICE=gproof", NULL, "-o", NULL, NULL, NULL, NULL };
+ char arg_res[32];
+ char arg_fp[32];
+ char arg_lp[32];
+
+ sprintf(arg_res, "-r%d", doc->res);
+ argv[2] = arg_res;
+ argv[4] = filename;
+ sprintf(arg_fp, "-dFirstPage=%d", page->number+1);
+ argv[5] = arg_fp;
+ sprintf(arg_lp, "-dLastPage=%d", page->number+1);
+ argv[6] = arg_lp;
+ argv[7] = doc->pdf_filename;
+
+ code = gsapi_new_instance(&instance, ctx);
+ if (code < 0)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "GS startup failed: %d", code);
+
+ code = gsapi_init_with_args(instance, sizeof(argv)/sizeof(*argv), argv);
+
+ gsapi_delete_instance(instance);
+ if (code < 0)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "GS run failed: %d", code);
+#else
+ /* Invoke gs to convert to a temp file. */
+ sprintf(gs_command, "gswin32c.exe -sDEVICE=gproof -r%d -o \"%s\" -dFirstPage=%d -dLastPage=%d %s",
+ doc->res, filename, page->number+1, page->number+1, doc->pdf_filename);
fz_system(ctx, gs_command);
+#endif
page->file = fz_new_gprf_file(ctx, filename);
}