diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2018-02-22 11:26:19 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2018-02-27 14:08:27 +0100 |
commit | 4dfced061fe7bc64335d3ccd31435091de0e0fe1 (patch) | |
tree | 6f33236c732363e4cc65e8389fb7397907317aa6 | |
parent | f4441c3c1a9a17275df5c75099633c4bf63a16d6 (diff) | |
download | mupdf-4dfced061fe7bc64335d3ccd31435091de0e0fe1.tar.xz |
Add annotation Vertices creation functions.
-rw-r--r-- | include/mupdf/pdf/annot.h | 10 | ||||
-rw-r--r-- | platform/java/mupdf_native.c | 12 | ||||
-rw-r--r-- | source/pdf/pdf-annot-edit.c | 78 | ||||
-rw-r--r-- | source/tools/murun.c | 8 |
4 files changed, 79 insertions, 29 deletions
diff --git a/include/mupdf/pdf/annot.h b/include/mupdf/pdf/annot.h index 2ae4d1c3..9f85d3ed 100644 --- a/include/mupdf/pdf/annot.h +++ b/include/mupdf/pdf/annot.h @@ -157,7 +157,7 @@ void pdf_annot_quad_point(fz_context *ctx, pdf_annot *annot, int i, float qp[8]) int pdf_annot_ink_list_count(fz_context *ctx, pdf_annot *annot); int pdf_annot_ink_list_stroke_count(fz_context *ctx, pdf_annot *annot, int i); -void pdf_annot_ink_list_stroke_vertex(fz_context *ctx, pdf_annot *annot, int i, int k, float v[2]); +fz_point pdf_annot_ink_list_stroke_vertex(fz_context *ctx, pdf_annot *annot, int i, int k); void pdf_set_annot_flags(fz_context *ctx, pdf_annot *annot, int flags); void pdf_set_annot_rect(fz_context *ctx, pdf_annot *annot, const fz_rect *rect); @@ -171,7 +171,6 @@ void pdf_clear_annot_ink_list(fz_context *ctx, pdf_annot *annot); void pdf_add_annot_ink_list(fz_context *ctx, pdf_annot *annot, int n, fz_point stroke[]); void pdf_set_annot_line_ending_styles(fz_context *ctx, pdf_annot *annot, int start_style, int end_style); -void pdf_set_annot_vertices(fz_context *ctx, pdf_annot *annot, int n, const float *v); void pdf_set_annot_icon_name(fz_context *ctx, pdf_annot *annot, const char *name); void pdf_set_annot_is_open(fz_context *ctx, pdf_annot *annot, int is_open); @@ -180,7 +179,12 @@ const char *pdf_annot_icon_name(fz_context *ctx, pdf_annot *annot); int pdf_annot_is_open(fz_context *ctx, pdf_annot *annot); int pdf_annot_vertex_count(fz_context *ctx, pdf_annot *annot); -void pdf_annot_vertex(fz_context *ctx, pdf_annot *annot, int i, float v[2]); +fz_point pdf_annot_vertex(fz_context *ctx, pdf_annot *annot, int i); + +void pdf_clear_annot_vertices(fz_context *ctx, pdf_annot *annot); +void pdf_add_annot_vertex(fz_context *ctx, pdf_annot *annot, fz_point p); +void pdf_set_annot_vertex(fz_context *ctx, pdf_annot *annot, int i, fz_point p); +void pdf_set_annot_vertices(fz_context *ctx, pdf_annot *annot, int n, const float *v); /* pdf_set_text_annot_position: set the position on page for a text (sticky note) annotation. diff --git a/platform/java/mupdf_native.c b/platform/java/mupdf_native.c index 42f1a1a8..69546564 100644 --- a/platform/java/mupdf_native.c +++ b/platform/java/mupdf_native.c @@ -9104,7 +9104,7 @@ FUN(PDFAnnotation_getInkList)(JNIEnv *env, jobject self) fz_context *ctx = get_context(env); pdf_annot *annot = from_PDFAnnotation(env, self); int i, k, n, m; - float v[2]; + fz_point v; jobject jinklist; jfloatArray jpath; @@ -9137,14 +9137,14 @@ FUN(PDFAnnotation_getInkList)(JNIEnv *env, jobject self) for (k = 0; k < m; k++) { fz_try(ctx) - pdf_annot_ink_list_stroke_vertex(ctx, annot, i, k, v); + v = pdf_annot_ink_list_stroke_vertex(ctx, annot, i, k); fz_catch(ctx) { jni_rethrow(env, ctx); return NULL; } - (*env)->SetFloatArrayRegion(env, jpath, k * 2, 2, &v[0]); + (*env)->SetFloatArrayRegion(env, jpath, k * 2, 2, (float*)&v); if ((*env)->ExceptionCheck(env)) return NULL; } @@ -9270,7 +9270,7 @@ FUN(PDFAnnotation_getVertices)(JNIEnv *env, jobject self) fz_context *ctx = get_context(env); pdf_annot *annot = from_PDFAnnotation(env, self); int i, n; - float vertex[2]; + fz_point v; jobject jvertices; if (!ctx || !annot) return NULL; @@ -9289,14 +9289,14 @@ FUN(PDFAnnotation_getVertices)(JNIEnv *env, jobject self) for (i = 0; i < n; i++) { fz_try(ctx) - pdf_annot_vertex(ctx, annot, i, vertex); + v = pdf_annot_vertex(ctx, annot, i); fz_catch(ctx) { jni_rethrow(env, ctx); return NULL; } - (*env)->SetFloatArrayRegion(env, jvertices, i * 2, 2, &vertex[0]); + (*env)->SetFloatArrayRegion(env, jvertices, i * 2, 2, (float*)&v); if ((*env)->ExceptionCheck(env)) return NULL; } diff --git a/source/pdf/pdf-annot-edit.c b/source/pdf/pdf-annot-edit.c index 97671eea..64a73142 100644 --- a/source/pdf/pdf-annot-edit.c +++ b/source/pdf/pdf-annot-edit.c @@ -608,8 +608,8 @@ pdf_annot_vertex_count(fz_context *ctx, pdf_annot *annot) return pdf_array_len(ctx, vertices) / 2; } -void -pdf_annot_vertex(fz_context *ctx, pdf_annot *annot, int i, float v[2]) +fz_point +pdf_annot_vertex(fz_context *ctx, pdf_annot *annot, int i) { pdf_obj *vertices; fz_matrix page_ctm; @@ -624,8 +624,8 @@ pdf_annot_vertex(fz_context *ctx, pdf_annot *annot, int i, float v[2]) point.x = pdf_to_real(ctx, pdf_array_get(ctx, vertices, i * 2)); point.y = pdf_to_real(ctx, pdf_array_get(ctx, vertices, i * 2 + 1)); fz_transform_point(&point, &page_ctm); - v[0] = point.x; - v[1] = point.y; + + return point; } void @@ -657,6 +657,56 @@ pdf_set_annot_vertices(fz_context *ctx, pdf_annot *annot, int n, const float *v) pdf_dirty_annot(ctx, annot); } +void pdf_clear_annot_vertices(fz_context *ctx, pdf_annot *annot) +{ + check_allowed_subtypes(ctx, annot, PDF_NAME_Vertices, vertices_subtypes); + pdf_dict_del(ctx, annot->obj, PDF_NAME_Vertices); + pdf_dirty_annot(ctx, annot); +} + +void pdf_add_annot_vertex(fz_context *ctx, pdf_annot *annot, fz_point p) +{ + pdf_document *doc = annot->page->doc; + fz_matrix page_ctm, inv_page_ctm; + pdf_obj *vertices; + + check_allowed_subtypes(ctx, annot, PDF_NAME_Vertices, vertices_subtypes); + + pdf_page_transform(ctx, annot->page, NULL, &page_ctm); + fz_invert_matrix(&inv_page_ctm, &page_ctm); + + vertices = pdf_dict_get(ctx, annot->obj, PDF_NAME_Vertices); + if (!pdf_is_array(ctx, vertices)) + { + vertices = pdf_new_array(ctx, doc, 32); + pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Vertices, vertices); + } + + fz_transform_point(&p, &inv_page_ctm); + pdf_array_push_real(ctx, vertices, p.x); + pdf_array_push_real(ctx, vertices, p.y); + + pdf_dirty_annot(ctx, annot); +} + +void pdf_set_annot_vertex(fz_context *ctx, pdf_annot *annot, int i, fz_point p) +{ + pdf_document *doc = annot->page->doc; + fz_matrix page_ctm, inv_page_ctm; + pdf_obj *vertices; + + check_allowed_subtypes(ctx, annot, PDF_NAME_Vertices, vertices_subtypes); + + pdf_page_transform(ctx, annot->page, NULL, &page_ctm); + fz_invert_matrix(&inv_page_ctm, &page_ctm); + + fz_transform_point(&p, &inv_page_ctm); + + vertices = pdf_dict_get(ctx, annot->obj, PDF_NAME_Vertices); + pdf_array_put_drop(ctx, vertices, i * 2 + 0, pdf_new_real(ctx, doc, p.x)); + pdf_array_put_drop(ctx, vertices, i * 2 + 1, pdf_new_real(ctx, doc, p.y)); +} + static pdf_obj *quad_point_subtypes[] = { PDF_NAME_Highlight, PDF_NAME_Link, @@ -766,30 +816,26 @@ pdf_annot_ink_list_stroke_count(fz_context *ctx, pdf_annot *annot, int i) return pdf_array_len(ctx, stroke) / 2; } -void -pdf_annot_ink_list_stroke_vertex(fz_context *ctx, pdf_annot *annot, int i, int k, float v[2]) +fz_point +pdf_annot_ink_list_stroke_vertex(fz_context *ctx, pdf_annot *annot, int i, int k) { pdf_obj *ink_list; pdf_obj *stroke; fz_matrix page_ctm; - fz_point point = { 0, 0 }; + fz_point point; check_allowed_subtypes(ctx, annot, PDF_NAME_InkList, ink_list_subtypes); ink_list = pdf_dict_get(ctx, annot->obj, PDF_NAME_InkList); stroke = pdf_array_get(ctx, ink_list, i); - if (v) - { - pdf_page_transform(ctx, annot->page, NULL, &page_ctm); + pdf_page_transform(ctx, annot->page, NULL, &page_ctm); - point.x = pdf_to_real(ctx, pdf_array_get(ctx, stroke, k * 2 + 0)); - point.y = pdf_to_real(ctx, pdf_array_get(ctx, stroke, k * 2 + 1)); - fz_transform_point(&point, &page_ctm); + point.x = pdf_to_real(ctx, pdf_array_get(ctx, stroke, k * 2 + 0)); + point.y = pdf_to_real(ctx, pdf_array_get(ctx, stroke, k * 2 + 1)); + fz_transform_point(&point, &page_ctm); - v[0] = point.x; - v[1] = point.y; - } + return point; } void diff --git a/source/tools/murun.c b/source/tools/murun.c index 4f535670..fd6c2c0d 100644 --- a/source/tools/murun.c +++ b/source/tools/murun.c @@ -4247,7 +4247,7 @@ static void ffi_PDFAnnotation_getInkList(js_State *J) fz_context *ctx = js_getcontext(J); pdf_annot *annot = js_touserdata(J, 0, "pdf_annot"); int i, k, m = 0, n = 0; - float v[2] = { 0 }; + fz_point pt; js_newarray(J); @@ -4265,12 +4265,12 @@ static void ffi_PDFAnnotation_getInkList(js_State *J) js_newarray(J); for (k = 0; k < m; ++k) { fz_try(ctx) - pdf_annot_ink_list_stroke_vertex(ctx, annot, i, k, v); + pt = pdf_annot_ink_list_stroke_vertex(ctx, annot, i, k); fz_catch(ctx) rethrow(J); - js_pushnumber(J, v[0]); + js_pushnumber(J, pt.x); js_setindex(J, -2, k * 2 + 0); - js_pushnumber(J, v[1]); + js_pushnumber(J, pt.y); js_setindex(J, -2, k * 2 + 1); } js_setindex(J, -2, i); |