summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2017-07-25 22:36:20 +0800
committerSebastian Rasmussen <sebras@gmail.com>2017-07-25 22:36:20 +0800
commit818e78d3cadf3a6236526fa54ae188d63891a0bd (patch)
tree507eba2a4ffa9766c198c843370cec94c3689f08
parent2bd66c263ec4514b31966495924ed386413d8327 (diff)
downloadmupdf-818e78d3cadf3a6236526fa54ae188d63891a0bd.tar.xz
Make it possible to check for properties of PDF annotations.
-rw-r--r--include/mupdf/pdf/annot.h8
-rw-r--r--source/pdf/pdf-annot-edit.c58
2 files changed, 62 insertions, 4 deletions
diff --git a/include/mupdf/pdf/annot.h b/include/mupdf/pdf/annot.h
index bc4b1d2e..4d98d9ce 100644
--- a/include/mupdf/pdf/annot.h
+++ b/include/mupdf/pdf/annot.h
@@ -143,6 +143,14 @@ pdf_annot *pdf_create_annot(fz_context *ctx, pdf_page *page, fz_annot_type type)
*/
void pdf_delete_annot(fz_context *ctx, pdf_page *page, pdf_annot *annot);
+int pdf_annot_has_ink_list(fz_context *ctx, pdf_annot *annot);
+int pdf_annot_has_quad_points(fz_context *ctx, pdf_annot *annot);
+int pdf_annot_has_vertices(fz_context *ctx, pdf_annot *annot);
+int pdf_annot_has_interior_color(fz_context *ctx, pdf_annot *annot);
+int pdf_annot_has_line_ending_styles(fz_context *ctx, pdf_annot *annot);
+int pdf_annot_has_icon_name(fz_context *ctx, pdf_annot *annot);
+int pdf_annot_has_open(fz_context *ctx, pdf_annot *annot);
+
int pdf_annot_flags(fz_context *ctx, pdf_annot *annot);
void pdf_annot_rect(fz_context *ctx, pdf_annot *annot, fz_rect *rect);
float pdf_annot_border(fz_context *ctx, pdf_annot *annot);
diff --git a/source/pdf/pdf-annot-edit.c b/source/pdf/pdf-annot-edit.c
index e557edd4..ee3b1964 100644
--- a/source/pdf/pdf-annot-edit.c
+++ b/source/pdf/pdf-annot-edit.c
@@ -70,16 +70,23 @@ pdf_annot_type_from_string(fz_context *ctx, const char *subtype)
return PDF_ANNOT_UNKNOWN;
}
-static void check_allowed_subtypes(fz_context *ctx, pdf_annot *annot, pdf_obj *property, pdf_obj **allowed)
+static int is_allowed_subtype(fz_context *ctx, pdf_annot *annot, pdf_obj *property, pdf_obj **allowed)
{
pdf_obj *subtype = pdf_dict_get(ctx, annot->obj, PDF_NAME_Subtype);
- while (allowed) {
+ while (*allowed) {
if (pdf_name_eq(ctx, subtype, *allowed))
- return;
+ return 1;
allowed++;
}
- fz_throw(ctx, FZ_ERROR_GENERIC, "%s annotations have no %s property", pdf_to_name(ctx, subtype), pdf_to_name(ctx, property));
+ return 0;
+}
+
+static void check_allowed_subtypes(fz_context *ctx, pdf_annot *annot, pdf_obj *property, pdf_obj **allowed)
+{
+ pdf_obj *subtype = pdf_dict_get(ctx, annot->obj, PDF_NAME_Subtype);
+ if (!is_allowed_subtype(ctx, annot, property, allowed))
+ fz_throw(ctx, FZ_ERROR_GENERIC, "%s annotations have no %s property", pdf_to_name(ctx, subtype), pdf_to_name(ctx, property));
}
pdf_annot *
@@ -272,6 +279,13 @@ static pdf_obj *open_subtypes[] = {
NULL,
};
+
+int
+pdf_annot_has_open(fz_context *ctx, pdf_annot *annot)
+{
+ return is_allowed_subtype(ctx, annot, PDF_NAME_Open, open_subtypes);
+}
+
int
pdf_annot_is_open(fz_context *ctx, pdf_annot *annot)
{
@@ -296,6 +310,12 @@ static pdf_obj *icon_name_subtypes[] = {
NULL,
};
+int
+pdf_annot_has_icon_name(fz_context *ctx, pdf_annot *annot)
+{
+ return is_allowed_subtype(ctx, annot, PDF_NAME_Name, icon_name_subtypes);
+}
+
const char *
pdf_annot_icon_name(fz_context *ctx, pdf_annot *annot)
{
@@ -352,6 +372,12 @@ static pdf_obj *line_ending_subtypes[] = {
NULL,
};
+int
+pdf_annot_has_line_ending_styles(fz_context *ctx, pdf_annot *annot)
+{
+ return is_allowed_subtype(ctx, annot, PDF_NAME_LE, line_ending_subtypes);
+}
+
void
pdf_annot_line_ending_styles(fz_context *ctx, pdf_annot *annot, int *start_style, int *end_style)
{
@@ -519,6 +545,12 @@ static pdf_obj *interior_color_subtypes[] = {
NULL,
};
+int
+pdf_annot_has_interior_color(fz_context *ctx, pdf_annot *annot)
+{
+ return is_allowed_subtype(ctx, annot, PDF_NAME_IC, interior_color_subtypes);
+}
+
void
pdf_annot_interior_color(fz_context *ctx, pdf_annot *annot, int *n, float color[4])
{
@@ -538,6 +570,12 @@ static pdf_obj *vertices_subtypes[] = {
};
int
+pdf_annot_has_vertices(fz_context *ctx, pdf_annot *annot)
+{
+ return is_allowed_subtype(ctx, annot, PDF_NAME_Vertices, vertices_subtypes);
+}
+
+int
pdf_annot_vertex_count(fz_context *ctx, pdf_annot *annot)
{
pdf_obj *vertices;
@@ -605,6 +643,12 @@ static pdf_obj *quad_point_subtypes[] = {
};
int
+pdf_annot_has_quad_points(fz_context *ctx, pdf_annot *annot)
+{
+ return is_allowed_subtype(ctx, annot, PDF_NAME_QuadPoints, quad_point_subtypes);
+}
+
+int
pdf_annot_quad_point_count(fz_context *ctx, pdf_annot *annot)
{
pdf_obj *quad_points;
@@ -677,6 +721,12 @@ static pdf_obj *ink_list_subtypes[] = {
};
int
+pdf_annot_has_ink_list(fz_context *ctx, pdf_annot *annot)
+{
+ return is_allowed_subtype(ctx, annot, PDF_NAME_InkList, ink_list_subtypes);
+}
+
+int
pdf_annot_ink_list_count(fz_context *ctx, pdf_annot *annot)
{
pdf_obj *ink_list;