summaryrefslogtreecommitdiff
path: root/pdf
diff options
context:
space:
mode:
authorPaul Gardiner <paulg.artifex@glidos.net>2013-02-22 12:20:33 +0000
committerPaul Gardiner <paulg.artifex@glidos.net>2013-02-22 12:20:33 +0000
commit5d15995814d4d99e44a860ae435659d9e30fad3b (patch)
tree65617f8c4c5819774b510eca4f388a279b67b329 /pdf
parent9d20a4f3a69fdea855f8678c1ad50b5db7472d81 (diff)
downloadmupdf-5d15995814d4d99e44a860ae435659d9e30fad3b.tar.xz
Add fz_get_annot_type
Diffstat (limited to 'pdf')
-rw-r--r--pdf/mupdf-internal.h3
-rw-r--r--pdf/mupdf.h5
-rw-r--r--pdf/pdf_annot.c71
-rw-r--r--pdf/pdf_form.c8
4 files changed, 80 insertions, 7 deletions
diff --git a/pdf/mupdf-internal.h b/pdf/mupdf-internal.h
index 0c070206..0a468939 100644
--- a/pdf/mupdf-internal.h
+++ b/pdf/mupdf-internal.h
@@ -503,7 +503,8 @@ struct pdf_annot_s
fz_matrix matrix;
pdf_annot *next;
pdf_annot *next_changed;
- int type;
+ int annot_type;
+ int widget_type;
};
fz_link_dest pdf_parse_link_dest(pdf_document *doc, pdf_obj *dest);
diff --git a/pdf/mupdf.h b/pdf/mupdf.h
index 83710b84..9dbafc91 100644
--- a/pdf/mupdf.h
+++ b/pdf/mupdf.h
@@ -272,6 +272,11 @@ pdf_annot *pdf_next_annot(pdf_document *doc, pdf_annot *annot);
fz_rect *pdf_bound_annot(pdf_document *doc, pdf_annot *annot, fz_rect *rect);
/*
+ pdf_annot_type: Return the type of an annotation
+*/
+fz_annot_type pdf_annot_type(pdf_annot *annot);
+
+/*
pdf_run_page: Interpret a loaded page and render it on a device.
page: A page loaded by pdf_load_page.
diff --git a/pdf/pdf_annot.c b/pdf/pdf_annot.c
index 5b152592..7201045f 100644
--- a/pdf/pdf_annot.c
+++ b/pdf/pdf_annot.c
@@ -356,6 +356,63 @@ pdf_transform_annot(pdf_annot *annot)
fz_pre_scale(fz_translate(&annot->matrix, x, y), w, h);
}
+static int annot_type(pdf_obj *obj)
+{
+ char *subtype = pdf_to_name(pdf_dict_gets(obj, "Subtype"));
+ if (!strcmp(subtype, "Text"))
+ return FZ_ANNOT_TEXT;
+ else if (!strcmp(subtype, "Link"))
+ return FZ_ANNOT_LINK;
+ else if (!strcmp(subtype, "FreeText"))
+ return FZ_ANNOT_FREETEXT;
+ else if (!strcmp(subtype, "Line"))
+ return FZ_ANNOT_LINE;
+ else if (!strcmp(subtype, "Square"))
+ return FZ_ANNOT_SQUARE;
+ else if (!strcmp(subtype, "Circle"))
+ return FZ_ANNOT_CIRCLE;
+ else if (!strcmp(subtype, "Polygon"))
+ return FZ_ANNOT_POLYGON;
+ else if (!strcmp(subtype, "PolyLine"))
+ return FZ_ANNOT_POLYLINE;
+ else if (!strcmp(subtype, "Highlight"))
+ return FZ_ANNOT_HIGHLIGHT;
+ else if (!strcmp(subtype, "Underline"))
+ return FZ_ANNOT_UNDERLINE;
+ else if (!strcmp(subtype, "Squiggly"))
+ return FZ_ANNOT_SQUIGGLY;
+ else if (!strcmp(subtype, "StrikeOut"))
+ return FZ_ANNOT_STRIKEOUT;
+ else if (!strcmp(subtype, "Stamp"))
+ return FZ_ANNOT_STAMP;
+ else if (!strcmp(subtype, "Caret"))
+ return FZ_ANNOT_CARET;
+ else if (!strcmp(subtype, "Ink"))
+ return FZ_ANNOT_INK;
+ else if (!strcmp(subtype, "Popup"))
+ return FZ_ANNOT_POPUP;
+ else if (!strcmp(subtype, "FileAttachment"))
+ return FZ_ANNOT_FILEATTACHMENT;
+ else if (!strcmp(subtype, "Sound"))
+ return FZ_ANNOT_SOUND;
+ else if (!strcmp(subtype, "Movie"))
+ return FZ_ANNOT_MOVIE;
+ else if (!strcmp(subtype, "Widget"))
+ return FZ_ANNOT_WIDGET;
+ else if (!strcmp(subtype, "Screen"))
+ return FZ_ANNOT_SCREEN;
+ else if (!strcmp(subtype, "PrinterMark"))
+ return FZ_ANNOT_PRINTERMARK;
+ else if (!strcmp(subtype, "TrapNet"))
+ return FZ_ANNOT_TRAPNET;
+ else if (!strcmp(subtype, "Watermark"))
+ return FZ_ANNOT_WATERMARK;
+ else if (!strcmp(subtype, "3D"))
+ return FZ_ANNOT_3D;
+ else
+ return -1;
+}
+
pdf_annot *
pdf_load_annots(pdf_document *xref, pdf_obj *annots, pdf_page *page)
{
@@ -419,7 +476,8 @@ pdf_load_annots(pdf_document *xref, pdf_obj *annots, pdf_page *page)
annot->pagerect = annot->rect;
fz_transform_rect(&annot->pagerect, &page->ctm);
annot->ap = NULL;
- annot->type = pdf_field_type(xref, obj);
+ annot->annot_type = annot_type(obj);
+ annot->widget_type = annot->annot_type == FZ_ANNOT_WIDGET ? pdf_field_type(xref, obj) : FZ_WIDGET_TYPE_NOT_WIDGET;
if (pdf_is_stream(xref, pdf_to_num(n), pdf_to_gen(n)))
{
@@ -528,6 +586,12 @@ pdf_bound_annot(pdf_document *doc, pdf_annot *annot, fz_rect *rect)
return rect;
}
+fz_annot_type
+pdf_annot_type(pdf_annot *annot)
+{
+ return annot->annot_type;
+}
+
pdf_annot *
pdf_create_annot(pdf_document *doc, pdf_page *page, fz_annot_type type)
{
@@ -557,6 +621,8 @@ pdf_create_annot(pdf_document *doc, pdf_page *page, fz_annot_type type)
case FZ_ANNOT_STRIKEOUT:
type_str = "StrikeOut";
break;
+ default:
+ break;
}
pdf_dict_puts_drop(annot_obj, "Subtype", pdf_new_name(ctx, type_str));
@@ -568,7 +634,8 @@ pdf_create_annot(pdf_document *doc, pdf_page *page, fz_annot_type type)
annot->rect = rect;
annot->pagerect = rect;
annot->ap = NULL;
- annot->type = FZ_WIDGET_TYPE_NOT_WIDGET;
+ annot->widget_type = FZ_WIDGET_TYPE_NOT_WIDGET;
+ annot->annot_type = type;
/*
Both annotation object and annotation structure are now created.
diff --git a/pdf/pdf_form.c b/pdf/pdf_form.c
index c57608c0..eddf2326 100644
--- a/pdf/pdf_form.c
+++ b/pdf/pdf_form.c
@@ -2131,7 +2131,7 @@ int pdf_pass_event(pdf_document *doc, pdf_page *page, fz_ui_event *ui_event)
if (annot)
{
- switch(annot->type)
+ switch(annot->widget_type)
{
case FZ_WIDGET_TYPE_RADIOBUTTON:
case FZ_WIDGET_TYPE_CHECKBOX:
@@ -2206,7 +2206,7 @@ fz_widget *pdf_first_widget(pdf_document *doc, pdf_page *page)
{
pdf_annot *annot = page->annots;
- while (annot && annot->type == FZ_WIDGET_TYPE_NOT_WIDGET)
+ while (annot && annot->widget_type == FZ_WIDGET_TYPE_NOT_WIDGET)
annot = annot->next;
return (fz_widget *)annot;
@@ -2219,7 +2219,7 @@ fz_widget *pdf_next_widget(fz_widget *previous)
if (annot)
annot = annot->next;
- while (annot && annot->type == FZ_WIDGET_TYPE_NOT_WIDGET)
+ while (annot && annot->widget_type == FZ_WIDGET_TYPE_NOT_WIDGET)
annot = annot->next;
return (fz_widget *)annot;
@@ -2228,7 +2228,7 @@ fz_widget *pdf_next_widget(fz_widget *previous)
int fz_widget_get_type(fz_widget *widget)
{
pdf_annot *annot = (pdf_annot *)widget;
- return annot->type;
+ return annot->widget_type;
}
char *pdf_field_value(pdf_document *doc, pdf_obj *field)