From 88003e46fa0db666d4cbccdfa81857ca7853e55f Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Mon, 20 Jul 2015 19:25:28 +0100 Subject: Add JNI interface to MuPDFCore to read/write separations on a page. Get separation information out to the Java level. --- include/mupdf/fitz/document.h | 21 +++++++++++ platform/android/jni/mupdf.c | 44 ++++++++++++++++++++++ .../src/com/artifex/mupdfdemo/MuPDFCore.java | 15 ++++++++ .../src/com/artifex/mupdfdemo/Separation.java | 15 ++++++++ source/fitz/document.c | 28 ++++++++++++++ source/gprf/gprf-doc.c | 23 +++++++++++ 6 files changed, 146 insertions(+) create mode 100644 platform/android/src/com/artifex/mupdfdemo/Separation.java diff --git a/include/mupdf/fitz/document.h b/include/mupdf/fitz/document.h index 1abdf807..5723bcc8 100644 --- a/include/mupdf/fitz/document.h +++ b/include/mupdf/fitz/document.h @@ -360,6 +360,27 @@ 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" +/* + Get the number of separations on a page (including CMYK). This will + be 0, unless the format specifically supports separations (such as + gproof files). +*/ +int fz_count_separations_on_page(fz_context *ctx, fz_page *page); + +/* + Enable/Disable a given separation on a given page. This will only + affect future renderings of pages from a format that supports + separations (such as gproof files). +*/ +void fz_control_separation_on_page(fz_context *ctx, fz_page *page, int sep, int disable); + +/* + Get the name and equivalent RGBA, CMYK colors of a given separation + on a given page. This will only work for formats that support + gproof files. +*/ +const char *fz_get_separation_on_page(fz_context *ctx, fz_page *page, int sep, uint32_t *rgba, uint32_t *cmyk); + /* fz_write_gproof_file: Given a currently open document, create a gproof skeleton file from that document. diff --git a/platform/android/jni/mupdf.c b/platform/android/jni/mupdf.c index a9484866..6abb805f 100644 --- a/platform/android/jni/mupdf.c +++ b/platform/android/jni/mupdf.c @@ -2789,3 +2789,47 @@ JNI_FN(MuPDFCore_gprfSupportedInternal)(JNIEnv * env) return JNI_FALSE; #endif } + +JNIEXPORT int JNICALL +JNI_FN(MuPDFCore_getNumSepsOnPageInternal)(JNIEnv *env, jobject thiz) +{ + globals *glo = get_globals(env, thiz); + fz_context *ctx = glo->ctx; + + return fz_count_separations_on_page(ctx, glo->pages[glo->current].page); +} + +JNIEXPORT void JNICALL +JNI_FN(MuPDFCore_controlSepOnPageInternal)(JNIEnv *env, jobject thiz, int sep, jboolean disable) +{ + globals *glo = get_globals(env, thiz); + fz_context *ctx = glo->ctx; + + fz_control_separation_on_page(ctx, glo->pages[glo->current].page, sep, disable); +} + +JNIEXPORT jobject JNICALL +JNI_FN(MuPDFCore_getSepInternal)(JNIEnv *env, jobject thiz, int sep) +{ + globals *glo = get_globals(env, thiz); + fz_context *ctx = glo->ctx; + const char *name; + unsigned int rgb; + unsigned int cmyk; + jobject jname; + jclass sepClass; + jmethodID ctor; + + name = fz_get_separation_on_page(ctx, glo->pages[glo->current].page, sep, &rgb, &cmyk); + jname = name ? (*env)->NewStringUTF(env, name) : NULL; + + sepClass = (*env)->FindClass(env, PACKAGENAME "/Separation"); + if (sepClass == NULL) + return NULL; + + ctor = (*env)->GetMethodID(env, sepClass, "", "(Ljava/lang/String;II)V"); + if (ctor == NULL) + return NULL; + + return (*env)->NewObject(env, sepClass, ctor, jname, rgb, cmyk); +} diff --git a/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java b/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java index 5c8697fb..29e443c0 100644 --- a/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java +++ b/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java @@ -92,6 +92,9 @@ public class MuPDFCore private native void abortCookie(long cookie); private native String startProofInternal(); private native void endProofInternal(String filename); + private native int getNumSepsOnPageInternal(); + private native int controlSepOnPageInternal(int sep, boolean disable); + private native Separation getSepInternal(int sep); public native boolean javascriptSupported(); @@ -375,4 +378,16 @@ public class MuPDFCore return false; return gprfSupportedInternal(); } + + public synchronized int getNumSepsOnPage() { + return getNumSepsOnPageInternal(); + } + + public synchronized int controlSepOnPage(int sep, boolean disable) { + return controlSepOnPageInternal(sep, disable); + } + + public synchronized Separation getSep(int sep) { + return getSepInternal(sep); + } } diff --git a/platform/android/src/com/artifex/mupdfdemo/Separation.java b/platform/android/src/com/artifex/mupdfdemo/Separation.java new file mode 100644 index 00000000..eadda4ba --- /dev/null +++ b/platform/android/src/com/artifex/mupdfdemo/Separation.java @@ -0,0 +1,15 @@ +package com.artifex.mupdfdemo; + +public class Separation +{ + String name; + int rgba; + int cmyk; + + public Separation(String name, int rgba, int cmyk) + { + this.name = name; + this.rgba = rgba; + this.cmyk = cmyk; + } +} diff --git a/source/fitz/document.c b/source/fitz/document.c index 78bd707c..9c78187f 100644 --- a/source/fitz/document.c +++ b/source/fitz/document.c @@ -408,3 +408,31 @@ fz_page_presentation(fz_context *ctx, fz_page *page, float *duration) return page->page_presentation(ctx, page, duration); return NULL; } + +int fz_count_separations_on_page(fz_context *ctx, fz_page *page) +{ + if (ctx == NULL || page == NULL || page->count_separations == NULL) + return 0; + + return page->count_separations(ctx, page); +} + +void fz_control_separation_on_page(fz_context *ctx, fz_page *page, int sep, int disable) +{ + if (ctx == NULL || page == NULL || page->control_separation == NULL) + return; + + page->control_separation(ctx, page, sep, disable); +} + +const char *fz_get_separation_on_page(fz_context *ctx, fz_page *page, int sep, uint32_t *rgba, uint32_t *cmyk) +{ + if (ctx == NULL || page == NULL || page->get_separation == NULL) + { + *rgba = 0; + *cmyk = 0; + return NULL; + } + + return page->get_separation(ctx, page, sep, rgba, cmyk); +} diff --git a/source/gprf/gprf-doc.c b/source/gprf/gprf-doc.c index 07714b8a..02562ca7 100644 --- a/source/gprf/gprf-doc.c +++ b/source/gprf/gprf-doc.c @@ -654,6 +654,26 @@ gprf_run_page(fz_context *ctx, fz_page *page_, fz_device *dev, const fz_matrix * fz_render_flags(ctx, dev, 0, FZ_DEVFLAG_GRIDFIT_AS_TILED); } +static int gprf_count_separations(fz_context *ctx, fz_page *page_) +{ + gprf_page *page = (gprf_page *)page_; + + return fz_count_separations(ctx, page->separations); +} + +static void gprf_control_separation(fz_context *ctx, fz_page *page_, int sep, int disable) +{ + gprf_page *page = (gprf_page *)page_; + + fz_control_separation(ctx, page->separations, sep, disable); +} + +static const char *gprf_get_separation(fz_context *ctx, fz_page *page_, int sep, uint32_t *rgba, uint32_t*cmyk) +{ + gprf_page *page = (gprf_page *)page_; + + return fz_get_separation(ctx, page->separations, sep, rgba, cmyk); +} static fz_page * gprf_load_page(fz_context *ctx, fz_document *doc_, int number) @@ -666,6 +686,9 @@ gprf_load_page(fz_context *ctx, fz_document *doc_, int number) page->super.bound_page = gprf_bound_page; page->super.run_page_contents = gprf_run_page; page->super.drop_page_imp = gprf_drop_page_imp; + page->super.count_separations = gprf_count_separations; + page->super.control_separation = gprf_control_separation; + page->super.get_separation = gprf_get_separation; page->doc = (gprf_document *)fz_keep_document(ctx, &doc->super); page->number = number; page->separations = fz_new_separations(ctx); -- cgit v1.2.3