summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-06-29 16:17:36 +0100
committerRobin Watts <robin.watts@artifex.com>2015-07-20 17:19:01 +0100
commit991a701b73b92c3954d75f186e44c8cbbabd9274 (patch)
tree8bf9dff6889b9dfa2092f61609369a6737aa5c02
parent3b5e21be58ae1fda85c3573adf5b7d25c71dfe0d (diff)
downloadmupdf-991a701b73b92c3954d75f186e44c8cbbabd9274.tar.xz
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.
-rw-r--r--include/mupdf/fitz/document.h14
-rw-r--r--include/mupdf/fitz/output.h12
-rw-r--r--platform/win32/libmupdf.vcproj4
-rw-r--r--source/gprf/gprf-doc.c4
-rw-r--r--source/gprf/gprf-skeleton.c61
5 files changed, 93 insertions, 2 deletions
diff --git a/include/mupdf/fitz/document.h b/include/mupdf/fitz/document.h
index 58cdc63a..1abdf807 100644
--- a/include/mupdf/fitz/document.h
+++ b/include/mupdf/fitz/document.h
@@ -360,4 +360,18 @@ int fz_lookup_metadata(fz_context *ctx, fz_document *doc, const char *key, char
#define FZ_META_INFO_AUTHOR "info:Author"
#define FZ_META_INFO_TITLE "info:Title"
+/*
+ fz_write_gproof_file: Given a currently open document, create a
+ gproof skeleton file from that document.
+
+ doc_filename: The name of the currently opened document file.
+
+ doc: The currently opened document.
+
+ filename: The filename of the desired gproof file.
+
+ res: The resolution at which proofing should be done.
+*/
+void fz_write_gproof_file(fz_context *ctx, const char *doc_filename, fz_document *doc, const char *filename, int res);
+
#endif
diff --git a/include/mupdf/fitz/output.h b/include/mupdf/fitz/output.h
index 94a3e45f..576755d3 100644
--- a/include/mupdf/fitz/output.h
+++ b/include/mupdf/fitz/output.h
@@ -71,6 +71,18 @@ static inline int fz_write_int32be(fz_context *ctx, fz_output *out, int x)
return fz_write(ctx, out, data, 4);
}
+static inline int fz_write_int32le(fz_context *ctx, fz_output *out, int x)
+{
+ char data[4];
+
+ data[0] = x;
+ data[1] = x>>8;
+ data[2] = x>>16;
+ data[3] = x>>24;
+
+ return fz_write(ctx, out, data, 4);
+}
+
static inline void
fz_write_byte(fz_context *ctx, fz_output *out, int x)
{
diff --git a/platform/win32/libmupdf.vcproj b/platform/win32/libmupdf.vcproj
index 0b83bb98..8d71f742 100644
--- a/platform/win32/libmupdf.vcproj
+++ b/platform/win32/libmupdf.vcproj
@@ -1589,6 +1589,10 @@
RelativePath="..\..\source\gprf\gprf-doc.c"
>
</File>
+ <File
+ RelativePath="..\..\source\gprf\gprf-skeleton.c"
+ >
+ </File>
</Filter>
</Files>
<Globals>
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);
+ }
+}