From 5b2252db42ec757f8d3fe37617661f3dc8fe9d72 Mon Sep 17 00:00:00 2001 From: Michael Vrhel Date: Wed, 19 Aug 2015 08:54:02 -0700 Subject: Add stdout and stderr procedures for use with gs api calls gsview on windows does not support the use of stdout and stderr. The calls to write out to these will return 0 leading to an i/o error from gs. To avoid this we define dummy functions that simply return the length that was to be written. To avoid issues with including "iapi.h" in Android builds that do not support gproof we wrap all of gprf-doc.c in an ifdef SUPPORT_GPROOF --- source/gprf/gprf-doc.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'source') diff --git a/source/gprf/gprf-doc.c b/source/gprf/gprf-doc.c index d69dac7f..8536bfc9 100644 --- a/source/gprf/gprf-doc.c +++ b/source/gprf/gprf-doc.c @@ -1,4 +1,17 @@ +#ifdef SUPPORT_GPROOF +/* Choose whether to call gs via an exe or via an API */ +#if defined(__ANDROID__) || defined(GSVIEW_WIN) +#define USE_GS_API +#endif +/* GSVIEW on Windows does not support stdout stderr */ +#ifdef GSVIEW_WIN +#define GS_API_NULL_STDIO +#endif + #include "mupdf/fitz.h" +#ifdef USE_GS_API +#include "iapi.h" +#endif typedef struct gprf_document_s gprf_document; typedef struct gprf_chapter_s gprf_chapter; @@ -9,11 +22,6 @@ typedef struct gprf_page_s gprf_page; #define SLOWCMYK #endif -/* Choose whether to call gs via an exe or via an API */ -#ifdef __ANDROID__ -#define USE_GS_API -#endif - enum { GPRF_TILESIZE = 256 @@ -479,6 +487,20 @@ fz_system(fz_context *ctx, const char *cmd) fz_throw(ctx, FZ_ERROR_GENERIC, "child process reported error %d", ret); } +#ifdef GS_API_NULL_STDIO +static int GSDLLCALL +gsdll_stdout(void *instance, const char *str, int len) +{ + return len; +} + +static int GSDLLCALL +gsdll_stderr(void *instance, const char *str, int len) +{ + return len; +} +#endif + static void generate_page(fz_context *ctx, gprf_page *page) { @@ -513,7 +535,9 @@ generate_page(fz_context *ctx, gprf_page *page) code = gsapi_new_instance(&instance, ctx); if (code < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "GS startup failed: %d", code); - +#ifdef GS_API_NULL_STDIO + gsapi_set_stdio(instance, NULL, gsdll_stdout, gsdll_stderr); +#endif code = gsapi_init_with_args(instance, sizeof(argv)/sizeof(*argv), argv); gsapi_delete_instance(instance); @@ -846,3 +870,4 @@ fz_document_handler gprf_document_handler = &gprf_open_document, &gprf_open_document_with_stream }; +#endif -- cgit v1.2.3