summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorfred ross-perry <fredross-perry@Fred-Ross-Perrys-Computer.local>2016-08-14 20:00:19 -0700
committerfredross-perry <fross-perry@conceptuamath.com>2016-08-16 11:21:02 -0700
commit07a60a0ef205eaf037135107085519616697f43e (patch)
tree955e8e3a7ee8957b3af88f8eca6eb96b5c9f42b7 /platform
parent786057a2c19f33d7e95fca13d3711ce60d388966 (diff)
downloadmupdf-07a60a0ef205eaf037135107085519616697f43e.tar.xz
Android java - ad textAsHtml() to the Page class.
The JNI implementation is taken from core.textAsHtml() in the old viewer.
Diffstat (limited to 'platform')
-rw-r--r--platform/java/mupdf_native.c85
-rw-r--r--platform/java/src/com/artifex/mupdf/fitz/Page.java2
2 files changed, 87 insertions, 0 deletions
diff --git a/platform/java/mupdf_native.c b/platform/java/mupdf_native.c
index fc90b6e8..62855ac0 100644
--- a/platform/java/mupdf_native.c
+++ b/platform/java/mupdf_native.c
@@ -4450,6 +4450,91 @@ FUN(Page_toStructuredText)(JNIEnv *env, jobject self)
return to_StructuredText_safe_own(ctx, env, text);
}
+JNIEXPORT jbyteArray JNICALL
+FUN(Page_textAsHtml)(JNIEnv *env, jobject self)
+{
+ fz_context *ctx = get_context(env);
+ fz_page *page = from_Page(env, self);
+
+ fz_stext_sheet *sheet = NULL;
+ fz_stext_page *text = NULL;
+ fz_device *dev = NULL;
+ fz_matrix ctm;
+ jbyteArray bArray = NULL;
+ fz_buffer *buf = NULL;
+ fz_output *out = NULL;
+
+ fz_var(sheet);
+ fz_var(text);
+ fz_var(dev);
+ fz_var(buf);
+ fz_var(out);
+
+ fz_try(ctx)
+ {
+ fz_rect mediabox;
+ int b, l, s, c;
+
+ ctm = fz_identity;
+ sheet = fz_new_stext_sheet(ctx);
+ text = fz_new_stext_page(ctx, fz_bound_page(ctx, page, &mediabox));
+ dev = fz_new_stext_device(ctx, sheet, text);
+ fz_run_page(ctx, page, dev, &ctm, NULL);
+ fz_close_device(ctx, dev);
+ 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(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_stext_page_html(ctx, out, text);
+ fz_printf(ctx, out, "</div></body>\n");
+ fz_printf(ctx, out, "<style>\n");
+ fz_print_stext_sheet(ctx, out, sheet);
+ fz_printf(ctx, out, "</style>\n</html>\n");
+ fz_drop_output(ctx, out);
+ out = NULL;
+
+ bArray = (*env)->NewByteArray(env, buf->len);
+ if (bArray == NULL)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to make byteArray");
+ (*env)->SetByteArrayRegion(env, bArray, 0, buf->len, buf->data);
+
+ }
+ fz_always(ctx)
+ {
+ fz_drop_stext_page(ctx, text);
+ fz_drop_stext_sheet(ctx, sheet);
+ fz_drop_device(ctx, dev);
+ fz_drop_output(ctx, out);
+ fz_drop_buffer(ctx, buf);
+ }
+ fz_catch(ctx)
+ {
+ jclass cls = (*env)->FindClass(env, "java/lang/OutOfMemoryError");
+ if (cls != NULL)
+ (*env)->ThrowNew(env, cls, "Out of memory in MuPDFCore_textAsHtml");
+ (*env)->DeleteLocalRef(env, cls);
+
+ return NULL;
+ }
+
+ return bArray;
+}
+
+
/* Cookie interface */
JNIEXPORT void JNICALL
diff --git a/platform/java/src/com/artifex/mupdf/fitz/Page.java b/platform/java/src/com/artifex/mupdf/fitz/Page.java
index 91bd5067..301b77df 100644
--- a/platform/java/src/com/artifex/mupdf/fitz/Page.java
+++ b/platform/java/src/com/artifex/mupdf/fitz/Page.java
@@ -40,4 +40,6 @@ public class Page
public native StructuredText toStructuredText();
public native Rect[] search(String needle);
+
+ public native byte[] textAsHtml();
}