summaryrefslogtreecommitdiff
path: root/platform/android
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2015-01-21 16:42:45 +0100
committerTor Andersson <tor.andersson@artifex.com>2015-02-17 18:05:39 +0100
commitf84a189d5f94250e46d2cbd1a75aba00130e2dd6 (patch)
tree8ee614ab90de1baa8941f91ae4946ed5c2e70721 /platform/android
parent681039767f2ccc72e236246178893eb0989169c9 (diff)
downloadmupdf-f84a189d5f94250e46d2cbd1a75aba00130e2dd6.tar.xz
Add ctx parameter and remove embedded contexts for API regularity.
Purge several embedded contexts: Remove embedded context in fz_output. Remove embedded context in fz_stream. Remove embedded context in fz_device. Remove fz_rebind_stream (since it is no longer necessary). Remove embedded context in svg_device. Remove embedded context in XML parser. Add ctx argument to fz_document functions. Remove embedded context in fz_document. Remove embedded context in pdf_document. Remove embedded context in pdf_obj. Make fz_page independent of fz_document in the interface. We shouldn't need to pass the document to all functions handling a page. If a page is tied to the source document, it's redundant; otherwise it's just pointless. Fix reference counting oddity in fz_new_image_from_pixmap.
Diffstat (limited to 'platform/android')
-rw-r--r--platform/android/jni/mupdf.c298
1 files changed, 157 insertions, 141 deletions
diff --git a/platform/android/jni/mupdf.c b/platform/android/jni/mupdf.c
index 1486e75a..5e6506be 100644
--- a/platform/android/jni/mupdf.c
+++ b/platform/android/jni/mupdf.c
@@ -137,7 +137,7 @@ static void drop_page_cache(globals *glo, page_cache *pc)
pc->page_list = NULL;
fz_drop_display_list(ctx, pc->annot_list);
pc->annot_list = NULL;
- fz_free_page(doc, pc->page);
+ fz_free_page(ctx, pc->page);
pc->page = NULL;
drop_changed_rects(ctx, &pc->changed_rects);
drop_changed_rects(ctx, &pc->hq_changed_rects);
@@ -180,27 +180,28 @@ static void show_alert(globals *glo, pdf_alert_event *alert)
pthread_mutex_unlock(&glo->fin_lock2);
}
-static void event_cb(pdf_doc_event *event, void *data)
+static void event_cb(fz_context *ctx, pdf_document *doc, pdf_doc_event *event, void *data)
{
globals *glo = (globals *)data;
switch (event->type)
{
case PDF_DOCUMENT_EVENT_ALERT:
- show_alert(glo, pdf_access_alert_event(event));
+ show_alert(glo, pdf_access_alert_event(ctx, event));
break;
}
}
static void alerts_init(globals *glo)
{
- pdf_document *idoc = pdf_specifics(glo->doc);
+ fz_context *ctx = glo->ctx;
+ pdf_document *idoc = pdf_specifics(ctx, glo->doc);
if (!idoc || glo->alerts_initialised)
return;
if (idoc)
- pdf_enable_js(idoc);
+ pdf_enable_js(ctx, idoc);
glo->alerts_active = 0;
glo->alert_request = 0;
@@ -211,20 +212,21 @@ static void alerts_init(globals *glo)
pthread_cond_init(&glo->alert_request_cond, NULL);
pthread_cond_init(&glo->alert_reply_cond, NULL);
- pdf_set_doc_event_callback(idoc, event_cb, glo);
+ pdf_set_doc_event_callback(ctx, idoc, event_cb, glo);
LOGT("alert_init");
glo->alerts_initialised = 1;
}
static void alerts_fin(globals *glo)
{
- pdf_document *idoc = pdf_specifics(glo->doc);
+ fz_context *ctx = glo->ctx;
+ pdf_document *idoc = pdf_specifics(ctx, glo->doc);
if (!glo->alerts_initialised)
return;
LOGT("Enter alerts_fin");
if (idoc)
- pdf_set_doc_event_callback(idoc, NULL, NULL);
+ pdf_set_doc_event_callback(ctx, idoc, NULL, NULL);
// Set alerts_active false and wake up show_alert and waitForAlertInternal,
pthread_mutex_lock(&glo->alert_lock);
@@ -330,7 +332,7 @@ JNI_FN(MuPDFCore_openFile)(JNIEnv * env, jobject thiz, jstring jfilename)
fz_catch(ctx)
{
LOGE("Failed: %s", ctx->error->message);
- fz_drop_document(glo->doc);
+ fz_drop_document(ctx, glo->doc);
glo->doc = NULL;
fz_drop_context(ctx);
glo->ctx = NULL;
@@ -350,7 +352,7 @@ typedef struct buffer_state_s
}
buffer_state;
-static int bufferStreamNext(fz_stream *stream, int max)
+static int bufferStreamNext(fz_context *ctx, fz_stream *stream, int max)
{
buffer_state *bs = (buffer_state *)stream->state;
globals *glo = bs->globals;
@@ -382,7 +384,7 @@ static void bufferStreamClose(fz_context *ctx, void *state)
fz_free(ctx, state);
}
-static void bufferStreamSeek(fz_stream *stream, int offset, int whence)
+static void bufferStreamSeek(fz_context *ctx, fz_stream *stream, int offset, int whence)
{
buffer_state *bs = (buffer_state *)stream->state;
globals *glo = bs->globals;
@@ -459,7 +461,7 @@ JNI_FN(MuPDFCore_openBuffer)(JNIEnv * env, jobject thiz, jstring jmagic)
{
bs = fz_malloc_struct(ctx, buffer_state);
bs->globals = glo;
- stream = fz_new_stream(ctx, bs, bufferStreamNext, bufferStreamClose, NULL);
+ stream = fz_new_stream(ctx, bs, bufferStreamNext, bufferStreamClose);
stream->seek = bufferStreamSeek;
glo->colorspace = fz_device_rgb(ctx);
@@ -479,12 +481,12 @@ JNI_FN(MuPDFCore_openBuffer)(JNIEnv * env, jobject thiz, jstring jmagic)
}
fz_always(ctx)
{
- fz_drop_stream(stream);
+ fz_drop_stream(ctx, stream);
}
fz_catch(ctx)
{
LOGE("Failed: %s", ctx->error->message);
- fz_drop_document(glo->doc);
+ fz_drop_document(ctx, glo->doc);
glo->doc = NULL;
fz_drop_context(ctx);
glo->ctx = NULL;
@@ -506,7 +508,7 @@ JNI_FN(MuPDFCore_countPagesInternal)(JNIEnv *env, jobject thiz)
fz_try(ctx)
{
- count = fz_count_pages(glo->doc);
+ count = fz_count_pages(ctx, glo->doc);
}
fz_catch(ctx)
{
@@ -520,8 +522,9 @@ JNI_FN(MuPDFCore_fileFormatInternal)(JNIEnv * env, jobject thiz)
{
char info[64];
globals *glo = get_globals(env, thiz);
+ fz_context *ctx = glo->ctx;
- fz_meta(glo->doc, FZ_META_FORMAT_INFO, info, sizeof(info));
+ fz_meta(ctx, glo->doc, FZ_META_FORMAT_INFO, info, sizeof(info));
return (*env)->NewStringUTF(env, info);
}
@@ -533,11 +536,12 @@ JNI_FN(MuPDFCore_isUnencryptedPDFInternal)(JNIEnv * env, jobject thiz)
if (glo == NULL)
return JNI_FALSE;
- pdf_document *idoc = pdf_specifics(glo->doc);
+ fz_context *ctx = glo->ctx;
+ pdf_document *idoc = pdf_specifics(ctx, glo->doc);
if (idoc == NULL)
return JNI_FALSE; // Not a PDF
- int cryptVer = pdf_crypt_version(idoc);
+ int cryptVer = pdf_crypt_version(ctx, idoc);
return (cryptVer == 0) ? JNI_TRUE : JNI_FALSE;
}
@@ -600,9 +604,9 @@ JNI_FN(MuPDFCore_gotoPageInternal)(JNIEnv *env, jobject thiz, int page)
{
fz_rect rect;
LOGI("Load page %d", pc->number);
- pc->page = fz_load_page(glo->doc, pc->number);
+ pc->page = fz_load_page(ctx, glo->doc, pc->number);
zoom = glo->resolution / 72;
- fz_bound_page(glo->doc, pc->page, &pc->media_box);
+ fz_bound_page(ctx, pc->page, &pc->media_box);
fz_scale(&ctm, zoom, zoom);
rect = pc->media_box;
fz_round_rect(&bbox, fz_transform_rect(&rect, &ctm));
@@ -635,25 +639,27 @@ JNIEXPORT jboolean JNICALL
JNI_FN(MuPDFCore_javascriptSupported)(JNIEnv *env, jobject thiz)
{
globals *glo = get_globals(env, thiz);
- pdf_document *idoc = pdf_specifics(glo->doc);
- return pdf_js_supported(idoc);
+ fz_context *ctx = glo->ctx;
+ pdf_document *idoc = pdf_specifics(ctx, glo->doc);
+ return pdf_js_supported(ctx, idoc);
}
static void update_changed_rects(globals *glo, page_cache *pc, pdf_document *idoc)
{
+ fz_context *ctx = glo->ctx;
fz_annot *annot;
- pdf_update_page(idoc, (pdf_page *)pc->page);
- while ((annot = (fz_annot *)pdf_poll_changed_annot(idoc, (pdf_page *)pc->page)) != NULL)
+ pdf_update_page(ctx, idoc, (pdf_page *)pc->page);
+ while ((annot = (fz_annot *)pdf_poll_changed_annot(ctx, idoc, (pdf_page *)pc->page)) != NULL)
{
/* FIXME: We bound the annot twice here */
rect_node *node = fz_malloc_struct(glo->ctx, rect_node);
- fz_bound_annot(glo->doc, annot, &node->rect);
+ fz_bound_annot(ctx, pc->page, annot, &node->rect);
node->next = pc->changed_rects;
pc->changed_rects = node;
node = fz_malloc_struct(glo->ctx, rect_node);
- fz_bound_annot(glo->doc, annot, &node->rect);
+ fz_bound_annot(ctx, pc->page, annot, &node->rect);
node->next = pc->hq_changed_rects;
pc->hq_changed_rects = node;
}
@@ -712,7 +718,7 @@ JNI_FN(MuPDFCore_drawPage)(JNIEnv *env, jobject thiz, jobject bitmap,
fz_try(ctx)
{
fz_irect pixbbox;
- pdf_document *idoc = pdf_specifics(doc);
+ pdf_document *idoc = pdf_specifics(ctx, doc);
if (idoc)
{
@@ -729,8 +735,8 @@ JNI_FN(MuPDFCore_drawPage)(JNIEnv *env, jobject thiz, jobject bitmap,
/* Render to list */
pc->page_list = fz_new_display_list(ctx);
dev = fz_new_list_device(ctx, pc->page_list);
- fz_run_page_contents(doc, pc->page, dev, &fz_identity, cookie);
- fz_drop_device(dev);
+ fz_run_page_contents(ctx, pc->page, dev, &fz_identity, cookie);
+ fz_drop_device(ctx, dev);
dev = NULL;
if (cookie != NULL && cookie->abort)
{
@@ -744,9 +750,9 @@ JNI_FN(MuPDFCore_drawPage)(JNIEnv *env, jobject thiz, jobject bitmap,
fz_annot *annot;
pc->annot_list = fz_new_display_list(ctx);
dev = fz_new_list_device(ctx, pc->annot_list);
- for (annot = fz_first_annot(doc, pc->page); annot; annot = fz_next_annot(doc, annot))
- fz_run_annot(doc, pc->page, annot, dev, &fz_identity, cookie);
- fz_drop_device(dev);
+ for (annot = fz_first_annot(ctx, pc->page); annot; annot = fz_next_annot(ctx, pc->page, annot))
+ fz_run_annot(ctx, pc->page, annot, dev, &fz_identity, cookie);
+ fz_drop_device(ctx, dev);
dev = NULL;
if (cookie != NULL && cookie->abort)
{
@@ -793,12 +799,12 @@ JNI_FN(MuPDFCore_drawPage)(JNIEnv *env, jobject thiz, jobject bitmap,
for (i=0; i<100;i++) {
#endif
if (pc->page_list)
- fz_run_display_list(pc->page_list, dev, &ctm, &rect, cookie);
+ fz_run_display_list(ctx, pc->page_list, dev, &ctm, &rect, cookie);
if (cookie != NULL && cookie->abort)
fz_throw(ctx, FZ_ERROR_GENERIC, "Render aborted");
if (pc->annot_list)
- fz_run_display_list(pc->annot_list, dev, &ctm, &rect, cookie);
+ fz_run_display_list(ctx, pc->annot_list, dev, &ctm, &rect, cookie);
if (cookie != NULL && cookie->abort)
fz_throw(ctx, FZ_ERROR_GENERIC, "Render aborted");
@@ -808,14 +814,14 @@ JNI_FN(MuPDFCore_drawPage)(JNIEnv *env, jobject thiz, jobject bitmap,
LOGI("100 renders in %d (%d per sec)", time, CLOCKS_PER_SEC);
}
#endif
- fz_drop_device(dev);
+ fz_drop_device(ctx, dev);
dev = NULL;
fz_drop_pixmap(ctx, pix);
LOGI("Rendered");
}
fz_always(ctx)
{
- fz_drop_device(dev);
+ fz_drop_device(ctx, dev);
dev = NULL;
}
fz_catch(ctx)
@@ -884,7 +890,7 @@ JNI_FN(MuPDFCore_updatePageInternal)(JNIEnv *env, jobject thiz, jobject bitmap,
return JNI_FN(MuPDFCore_drawPage)(env, thiz, bitmap, pageW, pageH, patchX, patchY, patchW, patchH, (jlong)(intptr_t)cookie);
}
- idoc = pdf_specifics(doc);
+ idoc = pdf_specifics(ctx, doc);
fz_var(pix);
fz_var(dev);
@@ -927,8 +933,8 @@ JNI_FN(MuPDFCore_updatePageInternal)(JNIEnv *env, jobject thiz, jobject bitmap,
/* Render to list */
pc->page_list = fz_new_display_list(ctx);
dev = fz_new_list_device(ctx, pc->page_list);
- fz_run_page_contents(doc, pc->page, dev, &fz_identity, cookie);
- fz_drop_device(dev);
+ fz_run_page_contents(ctx, pc->page, dev, &fz_identity, cookie);
+ fz_drop_device(ctx, dev);
dev = NULL;
if (cookie != NULL && cookie->abort)
{
@@ -941,9 +947,9 @@ JNI_FN(MuPDFCore_updatePageInternal)(JNIEnv *env, jobject thiz, jobject bitmap,
if (pc->annot_list == NULL) {
pc->annot_list = fz_new_display_list(ctx);
dev = fz_new_list_device(ctx, pc->annot_list);
- for (annot = fz_first_annot(doc, pc->page); annot; annot = fz_next_annot(doc, annot))
- fz_run_annot(doc, pc->page, annot, dev, &fz_identity, cookie);
- fz_drop_device(dev);
+ for (annot = fz_first_annot(ctx, pc->page); annot; annot = fz_next_annot(ctx, pc->page, annot))
+ fz_run_annot(ctx, pc->page, annot, dev, &fz_identity, cookie);
+ fz_drop_device(ctx, dev);
dev = NULL;
if (cookie != NULL && cookie->abort)
{
@@ -990,16 +996,16 @@ JNI_FN(MuPDFCore_updatePageInternal)(JNIEnv *env, jobject thiz, jobject bitmap,
fz_clear_pixmap_rect_with_value(ctx, pix, 0xff, &abox);
dev = fz_new_draw_device_with_bbox(ctx, pix, &abox);
if (pc->page_list)
- fz_run_display_list(pc->page_list, dev, &ctm, &arect, cookie);
+ fz_run_display_list(ctx, pc->page_list, dev, &ctm, &arect, cookie);
if (cookie != NULL && cookie->abort)
fz_throw(ctx, FZ_ERROR_GENERIC, "Render aborted");
if (pc->annot_list)
- fz_run_display_list(pc->annot_list, dev, &ctm, &arect, cookie);
+ fz_run_display_list(ctx, pc->annot_list, dev, &ctm, &arect, cookie);
if (cookie != NULL && cookie->abort)
fz_throw(ctx, FZ_ERROR_GENERIC, "Render aborted");
- fz_drop_device(dev);
+ fz_drop_device(ctx, dev);
dev = NULL;
}
}
@@ -1012,7 +1018,7 @@ JNI_FN(MuPDFCore_updatePageInternal)(JNIEnv *env, jobject thiz, jobject bitmap,
}
fz_always(ctx)
{
- fz_drop_device(dev);
+ fz_drop_device(ctx, dev);
dev = NULL;
}
fz_catch(ctx)
@@ -1027,17 +1033,17 @@ JNI_FN(MuPDFCore_updatePageInternal)(JNIEnv *env, jobject thiz, jobject bitmap,
}
static int
-charat(fz_text_page *page, int idx)
+charat(fz_context *ctx, fz_text_page *page, int idx)
{
fz_char_and_box cab;
- return fz_text_char_at(&cab, page, idx)->c;
+ return fz_text_char_at(ctx, &cab, page, idx)->c;
}
static fz_rect
-bboxcharat(fz_text_page *page, int idx)
+bboxcharat(fz_context *ctx, fz_text_page *page, int idx)
{
fz_char_and_box cab;
- return fz_text_char_at(&cab, page, idx)->bbox;
+ return fz_text_char_at(ctx, &cab, page, idx)->bbox;
}
static int
@@ -1120,8 +1126,9 @@ JNIEXPORT jboolean JNICALL
JNI_FN(MuPDFCore_needsPasswordInternal)(JNIEnv * env, jobject thiz)
{
globals *glo = get_globals(env, thiz);
+ fz_context *ctx = glo->ctx;
- return fz_needs_password(glo->doc) ? JNI_TRUE : JNI_FALSE;
+ return fz_needs_password(ctx, glo->doc) ? JNI_TRUE : JNI_FALSE;
}
JNIEXPORT jboolean JNICALL
@@ -1130,12 +1137,13 @@ JNI_FN(MuPDFCore_authenticatePasswordInternal)(JNIEnv *env, jobject thiz, jstrin
const char *pw;
int result;
globals *glo = get_globals(env, thiz);
+ fz_context *ctx = glo->ctx;
pw = (*env)->GetStringUTFChars(env, password, NULL);
if (pw == NULL)
return JNI_FALSE;
- result = fz_authenticate_password(glo->doc, (char *)pw);
+ result = fz_authenticate_password(ctx, glo->doc, (char *)pw);
(*env)->ReleaseStringUTFChars(env, password, pw);
return result;
}
@@ -1144,7 +1152,8 @@ JNIEXPORT jboolean JNICALL
JNI_FN(MuPDFCore_hasOutlineInternal)(JNIEnv * env, jobject thiz)
{
globals *glo = get_globals(env, thiz);
- fz_outline *outline = fz_load_outline(glo->doc);
+ fz_context *ctx = glo->ctx;
+ fz_outline *outline = fz_load_outline(ctx, glo->doc);
fz_drop_outline(glo->ctx, outline);
return (outline == NULL) ? JNI_FALSE : JNI_TRUE;
@@ -1160,6 +1169,7 @@ JNI_FN(MuPDFCore_getOutlineInternal)(JNIEnv * env, jobject thiz)
fz_outline *outline;
int nItems;
globals *glo = get_globals(env, thiz);
+ fz_context *ctx = glo->ctx;
jobjectArray ret;
olClass = (*env)->FindClass(env, PACKAGENAME "/OutlineItem");
@@ -1167,7 +1177,7 @@ JNI_FN(MuPDFCore_getOutlineInternal)(JNIEnv * env, jobject thiz)
ctor = (*env)->GetMethodID(env, olClass, "<init>", "(ILjava/lang/String;I)V");
if (ctor == NULL) return NULL;
- outline = fz_load_outline(glo->doc);
+ outline = fz_load_outline(ctx, glo->doc);
nItems = countOutlineItems(outline);
arr = (*env)->NewObjectArray(env,
@@ -1226,8 +1236,8 @@ JNI_FN(MuPDFCore_searchPage)(JNIEnv * env, jobject thiz, jstring jtext)
sheet = fz_new_text_sheet(ctx);
text = fz_new_text_page(ctx);
dev = fz_new_text_device(ctx, sheet, text);
- fz_run_page(doc, pc->page, dev, &ctm, NULL);
- fz_drop_device(dev);
+ fz_run_page(ctx, pc->page, dev, &ctm, NULL);
+ fz_drop_device(ctx, dev);
dev = NULL;
hit_count = fz_search_text_page(ctx, text, str, glo->hit_bbox, MAX_SEARCH_HITS);
@@ -1236,7 +1246,7 @@ JNI_FN(MuPDFCore_searchPage)(JNIEnv * env, jobject thiz, jstring jtext)
{
fz_drop_text_page(ctx, text);
fz_drop_text_sheet(ctx, sheet);
- fz_drop_device(dev);
+ fz_drop_device(ctx, dev);
}
fz_catch(ctx)
{
@@ -1316,8 +1326,8 @@ JNI_FN(MuPDFCore_text)(JNIEnv * env, jobject thiz)
sheet = fz_new_text_sheet(ctx);
text = fz_new_text_page(ctx);
dev = fz_new_text_device(ctx, sheet, text);
- fz_run_page(doc, pc->page, dev, &ctm, NULL);
- fz_drop_device(dev);
+ fz_run_page(ctx, pc->page, dev, &ctm, NULL);
+ fz_drop_device(ctx, dev);
dev = NULL;
barr = (*env)->NewObjectArray(env, text->len, textBlockClass, NULL);
@@ -1356,7 +1366,7 @@ JNI_FN(MuPDFCore_text)(JNIEnv * env, jobject thiz)
{
fz_text_char *ch = &span->text[c];
fz_rect bbox;
- fz_text_char_bbox(&bbox, span, c);
+ fz_text_char_bbox(ctx, &bbox, span, c);
jobject cobj = (*env)->NewObject(env, textCharClass, ctor, bbox.x0, bbox.y0, bbox.x1, bbox.y1, ch->c);
if (cobj == NULL) fz_throw(ctx, FZ_ERROR_GENERIC, "NewObjectfailed");
@@ -1380,7 +1390,7 @@ JNI_FN(MuPDFCore_text)(JNIEnv * env, jobject thiz)
{
fz_drop_text_page(ctx, text);
fz_drop_text_sheet(ctx, sheet);
- fz_drop_device(dev);
+ fz_drop_device(ctx, dev);
}
fz_catch(ctx)
{
@@ -1424,31 +1434,31 @@ JNI_FN(MuPDFCore_textAsHtml)(JNIEnv * env, jobject thiz)
sheet = fz_new_text_sheet(ctx);
text = fz_new_text_page(ctx);
dev = fz_new_text_device(ctx, sheet, text);
- fz_run_page(doc, pc->page, dev, &ctm, NULL);
- fz_drop_device(dev);
+ fz_run_page(ctx, pc->page, dev, &ctm, NULL);
+ fz_drop_device(ctx, dev);
dev = NULL;
fz_analyze_text(ctx, sheet, text);
buf = fz_new_buffer(ctx, 256);
out = fz_new_output_with_buffer(ctx, buf);
- fz_printf(out, "<html>\n");
- fz_printf(out, "<style>\n");
- fz_printf(out, "body{margin:0;}\n");
- fz_printf(out, "div.page{background-color:white;}\n");
- fz_printf(out, "div.block{margin:0pt;padding:0pt;}\n");
- fz_printf(out, "div.metaline{display:table;width:100%%}\n");
- fz_printf(out, "div.line{display:table-row;}\n");
- fz_printf(out, "div.cell{display:table-cell;padding-left:0.25em;padding-right:0.25em}\n");
- //fz_printf(out, "p{margin:0;padding:0;}\n");
- fz_printf(out, "</style>\n");
- fz_printf(out, "<body style=\"margin:0\"><div style=\"padding:10px\" id=\"content\">");
+ fz_printf(ctx, out, "<html>\n");
+ fz_printf(ctx, out, "<style>\n");
+ fz_printf(ctx, out, "body{margin:0;}\n");
+ fz_printf(ctx, out, "div.page{background-color:white;}\n");
+ fz_printf(ctx, out, "div.block{margin:0pt;padding:0pt;}\n");
+ fz_printf(ctx, out, "div.metaline{display:table;width:100%%}\n");
+ fz_printf(ctx, out, "div.line{display:table-row;}\n");
+ fz_printf(ctx, out, "div.cell{display:table-cell;padding-left:0.25em;padding-right:0.25em}\n");
+ //fz_printf(ctx, out, "p{margin:0;padding:0;}\n");
+ fz_printf(ctx, out, "</style>\n");
+ fz_printf(ctx, out, "<body style=\"margin:0\"><div style=\"padding:10px\" id=\"content\">");
fz_print_text_page_html(ctx, out, text);
- fz_printf(out, "</div></body>\n");
- fz_printf(out, "<style>\n");
+ fz_printf(ctx, out, "</div></body>\n");
+ fz_printf(ctx, out, "<style>\n");
fz_print_text_sheet(ctx, out, sheet);
- fz_printf(out, "</style>\n</html>\n");
- fz_drop_output(out);
+ fz_printf(ctx, out, "</style>\n</html>\n");
+ fz_drop_output(ctx, out);
out = NULL;
bArray = (*env)->NewByteArray(env, buf->len);
@@ -1461,8 +1471,8 @@ JNI_FN(MuPDFCore_textAsHtml)(JNIEnv * env, jobject thiz)
{
fz_drop_text_page(ctx, text);
fz_drop_text_sheet(ctx, sheet);
- fz_drop_device(dev);
- fz_drop_output(out);
+ fz_drop_device(ctx, dev);
+ fz_drop_output(ctx, out);
fz_drop_buffer(ctx, buf);
}
fz_catch(ctx)
@@ -1484,7 +1494,7 @@ JNI_FN(MuPDFCore_addMarkupAnnotationInternal)(JNIEnv * env, jobject thiz, jobjec
globals *glo = get_globals(env, thiz);
fz_context *ctx = glo->ctx;
fz_document *doc = glo->doc;
- pdf_document *idoc = pdf_specifics(doc);
+ pdf_document *idoc = pdf_specifics(ctx, doc);
page_cache *pc = &glo->pages[glo->current];
jclass pt_cls;
jfieldID x_fid, y_fid;
@@ -1556,10 +1566,10 @@ JNI_FN(MuPDFCore_addMarkupAnnotationInternal)(JNIEnv * env, jobject thiz, jobjec
fz_transform_point(&pts[i], &ctm);
}
- annot = (fz_annot *)pdf_create_annot(idoc, (pdf_page *)pc->page, type);
+ annot = (fz_annot *)pdf_create_annot(ctx, idoc, (pdf_page *)pc->page, type);
- pdf_set_markup_annot_quadpoints(idoc, (pdf_annot *)annot, pts, n);
- pdf_set_markup_appearance(idoc, (pdf_annot *)annot, color, alpha, line_thickness, line_height);
+ pdf_set_markup_annot_quadpoints(ctx, idoc, (pdf_annot *)annot, pts, n);
+ pdf_set_markup_appearance(ctx, idoc, (pdf_annot *)annot, color, alpha, line_thickness, line_height);
dump_annotation_display_lists(glo);
}
@@ -1583,7 +1593,7 @@ JNI_FN(MuPDFCore_addInkAnnotationInternal)(JNIEnv * env, jobject thiz, jobjectAr
globals *glo = get_globals(env, thiz);
fz_context *ctx = glo->ctx;
fz_document *doc = glo->doc;
- pdf_document *idoc = pdf_specifics(doc);
+ pdf_document *idoc = pdf_specifics(ctx, doc);
page_cache *pc = &glo->pages[glo->current];
jclass pt_cls;
jfieldID x_fid, y_fid;
@@ -1651,9 +1661,9 @@ JNI_FN(MuPDFCore_addInkAnnotationInternal)(JNIEnv * env, jobject thiz, jobjectAr
(*env)->DeleteLocalRef(env, arc);
}
- annot = (fz_annot *)pdf_create_annot(idoc, (pdf_page *)pc->page, FZ_ANNOT_INK);
+ annot = (fz_annot *)pdf_create_annot(ctx, idoc, (pdf_page *)pc->page, FZ_ANNOT_INK);
- pdf_set_ink_annot_list(idoc, (pdf_annot *)annot, pts, counts, n, color, INK_THICKNESS);
+ pdf_set_ink_annot_list(ctx, idoc, (pdf_annot *)annot, pts, counts, n, color, INK_THICKNESS);
dump_annotation_display_lists(glo);
}
@@ -1678,7 +1688,7 @@ JNI_FN(MuPDFCore_deleteAnnotationInternal)(JNIEnv * env, jobject thiz, int annot
globals *glo = get_globals(env, thiz);
fz_context *ctx = glo->ctx;
fz_document *doc = glo->doc;
- pdf_document *idoc = pdf_specifics(doc);
+ pdf_document *idoc = pdf_specifics(ctx, doc);
page_cache *pc = &glo->pages[glo->current];
fz_annot *annot;
int i;
@@ -1688,13 +1698,13 @@ JNI_FN(MuPDFCore_deleteAnnotationInternal)(JNIEnv * env, jobject thiz, int annot
fz_try(ctx)
{
- annot = fz_first_annot(glo->doc, pc->page);
+ annot = fz_first_annot(ctx, pc->page);
for (i = 0; i < annot_index && annot; i++)
- annot = fz_next_annot(glo->doc, annot);
+ annot = fz_next_annot(ctx, pc->page, annot);
if (annot)
{
- pdf_delete_annot(idoc, (pdf_page *)pc->page, (pdf_annot *)annot);
+ pdf_delete_annot(ctx, idoc, (pdf_page *)pc->page, (pdf_annot *)annot);
dump_annotation_display_lists(glo);
}
}
@@ -1718,7 +1728,7 @@ static void close_doc(globals *glo)
alerts_fin(glo);
- fz_drop_document(glo->doc);
+ fz_drop_document(glo->ctx, glo->doc);
glo->doc = NULL;
}
@@ -1795,7 +1805,7 @@ JNI_FN(MuPDFCore_getPageLinksInternal)(JNIEnv * env, jobject thiz, int pageNumbe
zoom = glo->resolution / 72;
fz_scale(&ctm, zoom, zoom);
- list = fz_load_links(glo->doc, pc->page);
+ list = fz_load_links(glo->ctx, pc->page);
count = 0;
for (link = list; link; link = link->next)
{
@@ -1883,6 +1893,7 @@ JNI_FN(MuPDFCore_getWidgetAreasInternal)(JNIEnv * env, jobject thiz, int pageNum
globals *glo = get_globals(env, thiz);
if (glo == NULL)
return NULL;
+ fz_context *ctx = glo->ctx;
rectFClass = (*env)->FindClass(env, "android/graphics/RectF");
if (rectFClass == NULL) return NULL;
@@ -1894,7 +1905,7 @@ JNI_FN(MuPDFCore_getWidgetAreasInternal)(JNIEnv * env, jobject thiz, int pageNum
if (pc->number != pageNumber || pc->page == NULL)
return NULL;
- idoc = pdf_specifics(glo->doc);
+ idoc = pdf_specifics(ctx, glo->doc);
if (idoc == NULL)
return NULL;
@@ -1902,17 +1913,17 @@ JNI_FN(MuPDFCore_getWidgetAreasInternal)(JNIEnv * env, jobject thiz, int pageNum
fz_scale(&ctm, zoom, zoom);
count = 0;
- for (widget = pdf_first_widget(idoc, (pdf_page *)pc->page); widget; widget = pdf_next_widget(widget))
+ for (widget = pdf_first_widget(ctx, idoc, (pdf_page *)pc->page); widget; widget = pdf_next_widget(ctx, widget))
count ++;
arr = (*env)->NewObjectArray(env, count, rectFClass, NULL);
if (arr == NULL) return NULL;
count = 0;
- for (widget = pdf_first_widget(idoc, (pdf_page *)pc->page); widget; widget = pdf_next_widget(widget))
+ for (widget = pdf_first_widget(ctx, idoc, (pdf_page *)pc->page); widget; widget = pdf_next_widget(ctx, widget))
{
fz_rect rect;
- pdf_bound_widget(widget, &rect);
+ pdf_bound_widget(ctx, widget, &rect);
fz_transform_rect(&rect, &ctm);
rectF = (*env)->NewObject(env, rectFClass, ctor,
@@ -1942,6 +1953,7 @@ JNI_FN(MuPDFCore_getAnnotationsInternal)(JNIEnv * env, jobject thiz, int pageNum
globals *glo = get_globals(env, thiz);
if (glo == NULL)
return NULL;
+ fz_context *ctx = glo->ctx;
annotClass = (*env)->FindClass(env, PACKAGENAME "/Annotation");
if (annotClass == NULL) return NULL;
@@ -1957,18 +1969,18 @@ JNI_FN(MuPDFCore_getAnnotationsInternal)(JNIEnv * env, jobject thiz, int pageNum
fz_scale(&ctm, zoom, zoom);
count = 0;
- for (annot = fz_first_annot(glo->doc, pc->page); annot; annot = fz_next_annot(glo->doc, annot))
+ for (annot = fz_first_annot(ctx, pc->page); annot; annot = fz_next_annot(ctx, pc->page, annot))
count ++;
arr = (*env)->NewObjectArray(env, count, annotClass, NULL);
if (arr == NULL) return NULL;
count = 0;
- for (annot = fz_first_annot(glo->doc, pc->page); annot; annot = fz_next_annot(glo->doc, annot))
+ for (annot = fz_first_annot(ctx, pc->page); annot; annot = fz_next_annot(ctx, pc->page, annot))
{
fz_rect rect;
- fz_annot_type type = pdf_annot_type((pdf_annot *)annot);
- fz_bound_annot(glo->doc, annot, &rect);
+ fz_annot_type type = pdf_annot_type(ctx, (pdf_annot *)annot);
+ fz_bound_annot(ctx, pc->page, annot, &rect);
fz_transform_rect(&rect, &ctm);
jannot = (*env)->NewObject(env, annotClass, ctor,
@@ -1989,7 +2001,7 @@ JNI_FN(MuPDFCore_passClickEventInternal)(JNIEnv * env, jobject thiz, int pageNum
globals *glo = get_globals(env, thiz);
fz_context *ctx = glo->ctx;
fz_matrix ctm;
- pdf_document *idoc = pdf_specifics(glo->doc);
+ pdf_document *idoc = pdf_specifics(ctx, glo->doc);
float zoom;
fz_point p;
pdf_ui_event event;
@@ -2021,9 +2033,9 @@ JNI_FN(MuPDFCore_passClickEventInternal)(JNIEnv * env, jobject thiz, int pageNum
event.etype = PDF_EVENT_TYPE_POINTER;
event.event.pointer.pt = p;
event.event.pointer.ptype = PDF_POINTER_DOWN;
- changed = pdf_pass_event(idoc, (pdf_page *)pc->page, &event);
+ changed = pdf_pass_event(ctx, idoc, (pdf_page *)pc->page, &event);
event.event.pointer.ptype = PDF_POINTER_UP;
- changed |= pdf_pass_event(idoc, (pdf_page *)pc->page, &event);
+ changed |= pdf_pass_event(ctx, idoc, (pdf_page *)pc->page, &event);
if (changed) {
dump_annotation_display_lists(glo);
}
@@ -2045,14 +2057,14 @@ JNI_FN(MuPDFCore_getFocusedWidgetTextInternal)(JNIEnv * env, jobject thiz)
fz_try(ctx)
{
- pdf_document *idoc = pdf_specifics(glo->doc);
+ pdf_document *idoc = pdf_specifics(ctx, glo->doc);
if (idoc)
{
- pdf_widget *focus = pdf_focused_widget(idoc);
+ pdf_widget *focus = pdf_focused_widget(ctx, idoc);
if (focus)
- text = pdf_text_widget_text(idoc, focus);
+ text = pdf_text_widget_text(ctx, idoc, focus);
}
}
fz_catch(ctx)
@@ -2080,15 +2092,15 @@ JNI_FN(MuPDFCore_setFocusedWidgetTextInternal)(JNIEnv * env, jobject thiz, jstri
fz_try(ctx)
{
- pdf_document *idoc = pdf_specifics(glo->doc);
+ pdf_document *idoc = pdf_specifics(ctx, glo->doc);
if (idoc)
{
- pdf_widget *focus = pdf_focused_widget(idoc);
+ pdf_widget *focus = pdf_focused_widget(ctx, idoc);
if (focus)
{
- result = pdf_text_widget_set_text(idoc, focus, (char *)text);
+ result = pdf_text_widget_set_text(ctx, idoc, focus, (char *)text);
dump_annotation_display_lists(glo);
}
}
@@ -2108,7 +2120,7 @@ JNI_FN(MuPDFCore_getFocusedWidgetChoiceOptions)(JNIEnv * env, jobject thiz)
{
globals *glo = get_globals(env, thiz);
fz_context *ctx = glo->ctx;
- pdf_document *idoc = pdf_specifics(glo->doc);
+ pdf_document *idoc = pdf_specifics(ctx, glo->doc);
pdf_widget *focus;
int type;
int nopts, i;
@@ -2119,20 +2131,20 @@ JNI_FN(MuPDFCore_getFocusedWidgetChoiceOptions)(JNIEnv * env, jobject thiz)
if (idoc == NULL)
return NULL;
- focus = pdf_focused_widget(idoc);
+ focus = pdf_focused_widget(ctx, idoc);
if (focus == NULL)
return NULL;
- type = pdf_widget_get_type(focus);
+ type = pdf_widget_get_type(ctx, focus);
if (type != PDF_WIDGET_TYPE_LISTBOX && type != PDF_WIDGET_TYPE_COMBOBOX)
return NULL;
fz_var(opts);
fz_try(ctx)
{
- nopts = pdf_choice_widget_options(idoc, focus, NULL);
+ nopts = pdf_choice_widget_options(ctx, idoc, focus, NULL);
opts = fz_malloc(ctx, nopts * sizeof(*opts));
- (void)pdf_choice_widget_options(idoc, focus, opts);
+ (void)pdf_choice_widget_options(ctx, idoc, focus, opts);
}
fz_catch(ctx)
{
@@ -2164,7 +2176,7 @@ JNI_FN(MuPDFCore_getFocusedWidgetChoiceSelected)(JNIEnv * env, jobject thiz)
{
globals *glo = get_globals(env, thiz);
fz_context *ctx = glo->ctx;
- pdf_document *idoc = pdf_specifics(glo->doc);
+ pdf_document *idoc = pdf_specifics(ctx, glo->doc);
pdf_widget *focus;
int type;
int nsel, i;
@@ -2175,20 +2187,20 @@ JNI_FN(MuPDFCore_getFocusedWidgetChoiceSelected)(JNIEnv * env, jobject thiz)
if (idoc == NULL)
return NULL;
- focus = pdf_focused_widget(idoc);
+ focus = pdf_focused_widget(ctx, idoc);
if (focus == NULL)
return NULL;
- type = pdf_widget_get_type(focus);
+ type = pdf_widget_get_type(ctx, focus);
if (type != PDF_WIDGET_TYPE_LISTBOX && type != PDF_WIDGET_TYPE_COMBOBOX)
return NULL;
fz_var(sel);
fz_try(ctx)
{
- nsel = pdf_choice_widget_value(idoc, focus, NULL);
+ nsel = pdf_choice_widget_value(ctx, idoc, focus, NULL);
sel = fz_malloc(ctx, nsel * sizeof(*sel));
- (void)pdf_choice_widget_value(idoc, focus, sel);
+ (void)pdf_choice_widget_value(ctx, idoc, focus, sel);
}
fz_catch(ctx)
{
@@ -2220,7 +2232,7 @@ JNI_FN(MuPDFCore_setFocusedWidgetChoiceSelectedInternal)(JNIEnv * env, jobject t
{
globals *glo = get_globals(env, thiz);
fz_context *ctx = glo->ctx;
- pdf_document *idoc = pdf_specifics(glo->doc);
+ pdf_document *idoc = pdf_specifics(ctx, glo->doc);
pdf_widget *focus;
int type;
int nsel, i;
@@ -2230,11 +2242,11 @@ JNI_FN(MuPDFCore_setFocusedWidgetChoiceSelectedInternal)(JNIEnv * env, jobject t
if (idoc == NULL)
return;
- focus = pdf_focused_widget(idoc);
+ focus = pdf_focused_widget(ctx, idoc);
if (focus == NULL)
return;
- type = pdf_widget_get_type(focus);
+ type = pdf_widget_get_type(ctx, focus);
if (type != PDF_WIDGET_TYPE_LISTBOX && type != PDF_WIDGET_TYPE_COMBOBOX)
return;
@@ -2258,7 +2270,7 @@ JNI_FN(MuPDFCore_setFocusedWidgetChoiceSelectedInternal)(JNIEnv * env, jobject t
fz_try(ctx)
{
- pdf_choice_widget_set_value(idoc, focus, nsel, sel);
+ pdf_choice_widget_set_value(ctx, idoc, focus, nsel, sel);
dump_annotation_display_lists(glo);
}
fz_catch(ctx)
@@ -2277,18 +2289,19 @@ JNIEXPORT int JNICALL
JNI_FN(MuPDFCore_getFocusedWidgetTypeInternal)(JNIEnv * env, jobject thiz)
{
globals *glo = get_globals(env, thiz);
- pdf_document *idoc = pdf_specifics(glo->doc);
+ fz_context *ctx = glo->ctx;
+ pdf_document *idoc = pdf_specifics(ctx, glo->doc);
pdf_widget *focus;
- if (idoc == NULL)
+ if (ctx, idoc == NULL)
return NONE;
- focus = pdf_focused_widget(idoc);
+ focus = pdf_focused_widget(ctx, idoc);
if (focus == NULL)
return NONE;
- switch (pdf_widget_get_type(focus))
+ switch (pdf_widget_get_type(ctx, focus))
{
case PDF_WIDGET_TYPE_TEXT: return TEXT;
case PDF_WIDGET_TYPE_LISTBOX: return LISTBOX;
@@ -2311,13 +2324,14 @@ JNIEXPORT int JNICALL
JNI_FN(MuPDFCore_getFocusedWidgetSignatureState)(JNIEnv * env, jobject thiz)
{
globals *glo = get_globals(env, thiz);
- pdf_document *idoc = pdf_specifics(glo->doc);
+ fz_context *ctx = glo->ctx;
+ pdf_document *idoc = pdf_specifics(ctx, glo->doc);
pdf_widget *focus;
- if (idoc == NULL)
+ if (ctx, idoc == NULL)
return Signature_NoSupport;
- focus = pdf_focused_widget(idoc);
+ focus = pdf_focused_widget(ctx, idoc);
if (focus == NULL)
return Signature_NoSupport;
@@ -2325,26 +2339,27 @@ JNI_FN(MuPDFCore_getFocusedWidgetSignatureState)(JNIEnv * env, jobject thiz)
if (!pdf_signatures_supported())
return Signature_NoSupport;
- return pdf_dict_gets(((pdf_annot *)focus)->obj, "V") ? Signature_Signed : Signature_Unsigned;
+ return pdf_dict_gets(ctx, ((pdf_annot *)focus)->obj, "V") ? Signature_Signed : Signature_Unsigned;
}
JNIEXPORT jstring JNICALL
JNI_FN(MuPDFCore_checkFocusedSignatureInternal)(JNIEnv * env, jobject thiz)
{
globals *glo = get_globals(env, thiz);
- pdf_document *idoc = pdf_specifics(glo->doc);
+ fz_context *ctx = glo->ctx;
+ pdf_document *idoc = pdf_specifics(ctx, glo->doc);
pdf_widget *focus;
char ebuf[256] = "Failed";
if (idoc == NULL)
goto exit;
- focus = pdf_focused_widget(idoc);
+ focus = pdf_focused_widget(ctx, idoc);
if (focus == NULL)
goto exit;
- if (pdf_check_signature(idoc, focus, glo->current_path, ebuf, sizeof(ebuf)))
+ if (pdf_check_signature(ctx, idoc, focus, glo->current_path, ebuf, sizeof(ebuf)))
{
strcpy(ebuf, "Signature is valid");
}
@@ -2358,7 +2373,7 @@ JNI_FN(MuPDFCore_signFocusedSignatureInternal)(JNIEnv * env, jobject thiz, jstri
{
globals *glo = get_globals(env, thiz);
fz_context *ctx = glo->ctx;
- pdf_document *idoc = pdf_specifics(glo->doc);
+ pdf_document *idoc = pdf_specifics(ctx, glo->doc);
pdf_widget *focus;
const char *keyfile;
const char *password;
@@ -2367,7 +2382,7 @@ JNI_FN(MuPDFCore_signFocusedSignatureInternal)(JNIEnv * env, jobject thiz, jstri
if (idoc == NULL)
return JNI_FALSE;
- focus = pdf_focused_widget(idoc);
+ focus = pdf_focused_widget(ctx, idoc);
if (focus == NULL)
return JNI_FALSE;
@@ -2380,7 +2395,7 @@ JNI_FN(MuPDFCore_signFocusedSignatureInternal)(JNIEnv * env, jobject thiz, jstri
fz_var(res);
fz_try(ctx)
{
- pdf_sign_signature(idoc, focus, keyfile, password);
+ pdf_sign_signature(ctx, idoc, focus, keyfile, password);
dump_annotation_display_lists(glo);
res = JNI_TRUE;
}
@@ -2521,9 +2536,10 @@ JNIEXPORT jboolean JNICALL
JNI_FN(MuPDFCore_hasChangesInternal)(JNIEnv * env, jobject thiz)
{
globals *glo = get_globals(env, thiz);
- pdf_document *idoc = pdf_specifics(glo->doc);
+ fz_context *ctx = glo->ctx;
+ pdf_document *idoc = pdf_specifics(ctx, glo->doc);
- return (idoc && pdf_has_unsaved_changes(idoc)) ? JNI_TRUE : JNI_FALSE;
+ return (idoc && pdf_has_unsaved_changes(ctx, idoc)) ? JNI_TRUE : JNI_FALSE;
}
static char *tmp_path(char *path)
@@ -2593,7 +2609,7 @@ JNI_FN(MuPDFCore_saveInternal)(JNIEnv * env, jobject thiz)
if (!err)
{
- fz_write_document(glo->doc, tmp, &opts);
+ fz_write_document(ctx, glo->doc, tmp, &opts);
written = 1;
}
}