From 991a701b73b92c3954d75f186e44c8cbbabd9274 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Mon, 29 Jun 2015 16:17:36 +0100 Subject: Code to generate a GProof file from a currently opened document. Given a document, generate a gproof file from it. This encapsulates the name of the file, the desired resolution for proofing, and the page dimensions of all the pages in the file. The idea is that an app will call this when it is asked to go into 'proofing' mode, and will reinvoke itself on this file. This gives the gprf document handler just enough information to fake up a document of n pages of the required sizes. Each page will then be autogenerated on demand. --- source/gprf/gprf-doc.c | 4 +-- source/gprf/gprf-skeleton.c | 61 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 source/gprf/gprf-skeleton.c (limited to 'source') diff --git a/source/gprf/gprf-doc.c b/source/gprf/gprf-doc.c index d9cd2938..bcd631ad 100644 --- a/source/gprf/gprf-doc.c +++ b/source/gprf/gprf-doc.c @@ -215,7 +215,7 @@ static inline unsigned char *cmyk_to_rgba(unsigned char *out, uint32_t c, uint32 g += (CONST16(0.2119) * x)>>16; b += (CONST16(0.2235) * x)>>16; #else - k = 63356 - k; + k = 65536 - k; r = k - c; g = k - m; b = k - y; @@ -275,7 +275,7 @@ gprf_get_pixmap(fz_context *ctx, fz_image *image_, int w, int h, int *l2factor) fz_try(ctx) { - /* First off, figure out of we are doing RGB or separations + /* First off, figure out if we are doing RGB or separations * decoding. */ num_seps = 3 + fz_count_separations(ctx, image->separations); if (fz_separations_all_enabled(ctx, image->separations)) diff --git a/source/gprf/gprf-skeleton.c b/source/gprf/gprf-skeleton.c new file mode 100644 index 00000000..e17c3e21 --- /dev/null +++ b/source/gprf/gprf-skeleton.c @@ -0,0 +1,61 @@ +#include "mupdf/fitz.h" + +void +fz_write_gproof_file(fz_context *ctx, const char *pdf_file, fz_document *doc, const char *filename, int res) +{ + int i; + int num_pages = fz_count_pages(ctx, doc); + fz_output *out; + fz_page *page = NULL; + + fz_var(page); + + if (num_pages <= 0) + fz_throw(ctx, FZ_ERROR_GENERIC, "Cannot write a 0 page GProof skeleton file"); + + out = fz_new_output_to_filename(ctx, filename); + + fz_try(ctx) + { + /* File Signature: GPRO */ + fz_write_int32le(ctx, out, 0x4f525047); + + /* Version = 1 */ + fz_write_byte(ctx, out, 1); + fz_write_byte(ctx, out, 0); + + /* Resolution */ + fz_write_int32le(ctx, out, res); + + /* Num Pages */ + fz_write_int32le(ctx, out, num_pages); + + for (i = 0; i < num_pages; i++) + { + fz_rect rect; + int w, h; + + page = fz_load_page(ctx, doc, i); + fz_bound_page(ctx, page, &rect); + fz_drop_page(ctx, page); + page = NULL; + + w = (int)((rect.x1 - rect.x0) * res / 72.0 + 0.5); + h = (int)((rect.y1 - rect.y0) * res / 72.0 + 0.5); + fz_write_int32le(ctx, out, w); + fz_write_int32le(ctx, out, h); + } + + /* Filename */ + fz_write(ctx, out, pdf_file, strlen(pdf_file)+1); + } + fz_always(ctx) + { + fz_drop_page(ctx, page); + fz_drop_output(ctx, out); + } + fz_catch(ctx) + { + fz_rethrow(ctx); + } +} -- cgit v1.2.3