summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vrhel <michael.vrhel@artifex.com>2015-09-01 16:16:24 -0700
committerMichael Vrhel <michael.vrhel@artifex.com>2015-09-02 08:43:59 -0700
commit6034e61c32dd57e1bf257290b39b6634f7893230 (patch)
tree0d3ec0b28e2126de21f4c601507511072a0ca73c
parentb30cc7aa30c5400893cb9c5f70d5ce8ca21c3831 (diff)
downloadmupdf-6034e61c32dd57e1bf257290b39b6634f7893230.tar.xz
Add in support for icc profiles in gprf/gproof format
The default profile case (sRGB and SWOP CMYK) are indicated by empty strings for those entries.
-rw-r--r--include/mupdf/fitz/document.h7
-rw-r--r--source/gprf/gprf-doc.c56
-rw-r--r--source/gprf/gprf-skeleton.c8
3 files changed, 62 insertions, 9 deletions
diff --git a/include/mupdf/fitz/document.h b/include/mupdf/fitz/document.h
index 5723bcc8..efd51332 100644
--- a/include/mupdf/fitz/document.h
+++ b/include/mupdf/fitz/document.h
@@ -392,7 +392,12 @@ const char *fz_get_separation_on_page(fz_context *ctx, fz_page *page, int sep, u
filename: The filename of the desired gproof file.
res: The resolution at which proofing should be done.
+
+ print_profile: The filename of the ICC profile for the printer we are proofing
+
+ display_profile: The filename of the ICC profile for our display device
*/
-void fz_write_gproof_file(fz_context *ctx, const char *doc_filename, fz_document *doc, const char *filename, int res);
+void fz_write_gproof_file(fz_context *ctx, const char *doc_filename, fz_document *doc, const char *filename, int res,
+ const char *print_profile, const char *display_profile);
#endif
diff --git a/source/gprf/gprf-doc.c b/source/gprf/gprf-doc.c
index 3a761add..b4777c6c 100644
--- a/source/gprf/gprf-doc.c
+++ b/source/gprf/gprf-doc.c
@@ -31,6 +31,8 @@ struct gprf_document_s
{
fz_document super;
char *pdf_filename;
+ char *print_profile;
+ char *display_profile;
int res;
int num_pages;
struct {
@@ -508,16 +510,46 @@ generate_page(fz_context *ctx, gprf_page *page)
char nameroot[32];
char *filename;
char gs_command[1024];
+ char *disp_profile = NULL;
+ char *print_profile = NULL;
+ int len;
sprintf(nameroot, "gprf_%d_", page->number);
filename = fz_tempfilename(ctx, nameroot, doc->pdf_filename);
+ /* Set up the icc profiles */
+ if (strlen(doc->display_profile) == 0)
+ {
+ len = sizeof("-sPostRenderProfile=srgb.icc");
+ disp_profile = (char*)fz_malloc(ctx, len + 1);
+ sprintf(disp_profile, "-sPostRenderProfile=srgb.icc");
+ }
+ else
+ {
+ len = sizeof("-sPostRenderProfile=\"\""); /* with quotes */
+ disp_profile = (char*)fz_malloc(ctx, len + strlen(doc->display_profile) + 1);
+ sprintf(disp_profile, "-sPostRenderProfile=\"%s\"", doc->display_profile);
+ }
+
+ if (strlen(doc->print_profile) == 0)
+ {
+ len = sizeof("-sOutputICCProfile=default_cmyk.icc");
+ print_profile = (char*)fz_malloc(ctx, len + 1);
+ sprintf(print_profile, "-sOutputICCProfile=default_cmyk.icc");
+ }
+ else
+ {
+ len = sizeof("-sOutputICCProfile=\"\""); /* with quotes */
+ print_profile = (char*)fz_malloc(ctx, len + strlen(doc->print_profile) + 1);
+ sprintf(print_profile, "-sOutputICCProfile=\"%s\"", doc->print_profile);
+ }
+
fz_try(ctx)
{
#ifdef USE_GS_API
void *instance;
int code;
- char *argv[] = { "gs", "-sDEVICE=gprf", NULL, "-o", NULL, NULL, NULL, NULL, NULL, NULL};
+ char *argv[] = { "gs", "-sDEVICE=gprf", NULL, "-o", NULL, NULL, NULL, NULL, NULL, NULL, NULL};
char arg_res[32];
char arg_fp[32];
char arg_lp[32];
@@ -529,9 +561,10 @@ generate_page(fz_context *ctx, gprf_page *page)
argv[5] = arg_fp;
sprintf(arg_lp, "-dLastPage=%d", page->number+1);
argv[6] = arg_lp;
- argv[7] = "-sPostRenderProfile=srgb.icc";
- argv[8] = "-I%rom%Resource/Init/";
- argv[9] = doc->pdf_filename;
+ argv[7] = disp_profile;
+ argv[8] = print_profile;
+ argv[9] = "-I%rom%Resource/Init/";
+ argv[10] = doc->pdf_filename;
code = gsapi_new_instance(&instance, ctx);
if (code < 0)
@@ -546,13 +579,18 @@ generate_page(fz_context *ctx, gprf_page *page)
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=gprf -r%d -o \"%s\" -sPostRenderProfile=srgb.icc -I\%rom\%Resource/Init/ -dFirstPage=%d -dLastPage=%d %s",
- doc->res, filename, page->number+1, page->number+1, doc->pdf_filename);
+ sprintf(gs_command, "gswin32c.exe -sDEVICE=gprf -r%d -o \"%s\" %s %s -I\%rom\%Resource/Init/ -dFirstPage=%d -dLastPage=%d %s",
+ doc->res, filename, disp_profile, print_profile, page->number+1, page->number+1, doc->pdf_filename);
fz_system(ctx, gs_command);
#endif
page->file = fz_new_gprf_file(ctx, filename);
}
+ fz_always(ctx)
+ {
+ fz_free(ctx, print_profile);
+ fz_free(ctx, disp_profile);
+ }
fz_catch(ctx)
{
unlink(filename);
@@ -780,6 +818,8 @@ gprf_close_document(fz_context *ctx, fz_document *doc_)
return;
fz_free(ctx, doc->page_dims);
fz_free(ctx, doc->pdf_filename);
+ fz_free(ctx, doc->print_profile);
+ fz_free(ctx, doc->display_profile);
fz_free(ctx, doc);
}
@@ -832,6 +872,10 @@ gprf_open_document_with_stream(fz_context *ctx, fz_stream *file)
}
fz_read_string(ctx, file, buf, sizeof(buf));
doc->pdf_filename = fz_strdup(ctx, buf);
+ fz_read_string(ctx, file, buf, sizeof(buf));
+ doc->print_profile = fz_strdup(ctx, buf);
+ fz_read_string(ctx, file, buf, sizeof(buf));
+ doc->display_profile = fz_strdup(ctx, buf);
}
fz_catch(ctx)
{
diff --git a/source/gprf/gprf-skeleton.c b/source/gprf/gprf-skeleton.c
index e17c3e21..7d46348c 100644
--- a/source/gprf/gprf-skeleton.c
+++ b/source/gprf/gprf-skeleton.c
@@ -1,7 +1,8 @@
#include "mupdf/fitz.h"
void
-fz_write_gproof_file(fz_context *ctx, const char *pdf_file, fz_document *doc, const char *filename, int res)
+fz_write_gproof_file(fz_context *ctx, const char *pdf_file, fz_document *doc, const char *filename, int res,
+ const char *print_profile, const char *display_profile)
{
int i;
int num_pages = fz_count_pages(ctx, doc);
@@ -46,8 +47,11 @@ fz_write_gproof_file(fz_context *ctx, const char *pdf_file, fz_document *doc, co
fz_write_int32le(ctx, out, h);
}
- /* Filename */
+ /* Filenames */
fz_write(ctx, out, pdf_file, strlen(pdf_file)+1);
+ fz_write(ctx, out, print_profile, strlen(print_profile) + 1);
+ fz_write(ctx, out, display_profile, strlen(display_profile) + 1);
+
}
fz_always(ctx)
{