summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mupdf/fitz/annotation.h7
-rw-r--r--include/mupdf/fitz/document.h2
-rw-r--r--include/mupdf/pdf/annot.h2
-rw-r--r--source/fitz/document.c21
-rw-r--r--source/pdf/pdf-annot-edit.c4
-rw-r--r--source/pdf/pdf-annot.c25
-rw-r--r--source/pdf/pdf-form.c2
-rw-r--r--source/pdf/pdf-page.c6
8 files changed, 49 insertions, 20 deletions
diff --git a/include/mupdf/fitz/annotation.h b/include/mupdf/fitz/annotation.h
index 82a902e6..a3120858 100644
--- a/include/mupdf/fitz/annotation.h
+++ b/include/mupdf/fitz/annotation.h
@@ -36,9 +36,12 @@ typedef enum
} fz_annot_type;
/*
- fz_get_annot_type: return the type of an annotation
+ fz_new_annot: Create and initialize an annotation struct.
*/
-fz_annot_type fz_get_annot_type(fz_context *ctx, fz_annot *annot);
+void *fz_new_annot(fz_context *ctx, int size);
+
+fz_annot *fz_keep_annot(fz_context *ctx, fz_annot *annot);
+void fz_drop_annot(fz_context *ctx, fz_annot *annot);
/*
fz_first_annot: Return a pointer to the first annotation on a page.
diff --git a/include/mupdf/fitz/document.h b/include/mupdf/fitz/document.h
index f8e67668..1964e41c 100644
--- a/include/mupdf/fitz/document.h
+++ b/include/mupdf/fitz/document.h
@@ -49,6 +49,7 @@ typedef int (fz_page_separation_disabled_fn)(fz_context *ctx, fz_page *page, int
typedef int (fz_page_count_separations_fn)(fz_context *ctx, fz_page *page);
typedef const char *(fz_page_get_separation_fn)(fz_context *ctx, fz_page *page, int separation, uint32_t *rgb, uint32_t *cmyk);
+typedef void (fz_annot_drop_imp_fn)(fz_context *ctx, fz_annot *annot);
typedef fz_annot *(fz_annot_next_fn)(fz_context *ctx, fz_annot *annot);
typedef fz_rect *(fz_annot_bound_fn)(fz_context *ctx, fz_annot *annot, fz_rect *rect);
typedef void (fz_annot_run_fn)(fz_context *ctx, fz_annot *annot, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie);
@@ -56,6 +57,7 @@ typedef void (fz_annot_run_fn)(fz_context *ctx, fz_annot *annot, fz_device *dev,
struct fz_annot_s
{
int refs;
+ fz_annot_drop_imp_fn *drop_annot_imp;
fz_annot_bound_fn *bound_annot;
fz_annot_run_fn *run_annot;
fz_annot_next_fn *next_annot;
diff --git a/include/mupdf/pdf/annot.h b/include/mupdf/pdf/annot.h
index 7328be4d..e25ec5db 100644
--- a/include/mupdf/pdf/annot.h
+++ b/include/mupdf/pdf/annot.h
@@ -83,7 +83,7 @@ fz_link *pdf_load_link_annots(fz_context *ctx, pdf_document *, pdf_obj *annots,
void pdf_transform_annot(fz_context *ctx, pdf_annot *annot);
void pdf_load_annots(fz_context *ctx, pdf_document *, pdf_page *page, pdf_obj *annots);
void pdf_update_annot(fz_context *ctx, pdf_document *, pdf_annot *annot);
-void pdf_drop_annot(fz_context *ctx, pdf_annot *link);
+void pdf_drop_annots(fz_context *ctx, pdf_annot *annot_list);
/*
pdf_create_annot: create a new annotation of the specified type on the
diff --git a/source/fitz/document.c b/source/fitz/document.c
index b902161c..319ac83b 100644
--- a/source/fitz/document.c
+++ b/source/fitz/document.c
@@ -369,6 +369,27 @@ fz_new_annot(fz_context *ctx, int size)
return page;
}
+fz_annot *
+fz_keep_annot(fz_context *ctx, fz_annot *annot)
+{
+ if (annot)
+ ++annot->refs;
+ return annot;
+}
+
+void
+fz_drop_annot(fz_context *ctx, fz_annot *annot)
+{
+ if (annot)
+ {
+ if (--annot->refs == 0 && annot->drop_annot_imp)
+ {
+ annot->drop_annot_imp(ctx, annot);
+ fz_free(ctx, annot);
+ }
+ }
+}
+
void *
fz_new_page(fz_context *ctx, int size)
{
diff --git a/source/pdf/pdf-annot-edit.c b/source/pdf/pdf-annot-edit.c
index aef14e6f..6b085055 100644
--- a/source/pdf/pdf-annot-edit.c
+++ b/source/pdf/pdf-annot-edit.c
@@ -138,7 +138,7 @@ pdf_create_annot(fz_context *ctx, pdf_document *doc, pdf_page *page, fz_annot_ty
/*
Linking must be done after any call that might throw because
- pdf_drop_annot below actually frees a list. Put the new annot
+ pdf_drop_annots below actually frees a list. Put the new annot
at the end of the list, so that it will be drawn last.
*/
*page->annot_tailp = annot;
@@ -153,7 +153,7 @@ pdf_create_annot(fz_context *ctx, pdf_document *doc, pdf_page *page, fz_annot_ty
}
fz_catch(ctx)
{
- pdf_drop_annot(ctx, annot);
+ pdf_drop_annots(ctx, annot);
fz_rethrow(ctx);
}
diff --git a/source/pdf/pdf-annot.c b/source/pdf/pdf-annot.c
index bfdfe306..84b0c3e1 100644
--- a/source/pdf/pdf-annot.c
+++ b/source/pdf/pdf-annot.c
@@ -384,17 +384,20 @@ pdf_load_link_annots(fz_context *ctx, pdf_document *doc, pdf_obj *annots, const
}
void
-pdf_drop_annot(fz_context *ctx, pdf_annot *annot)
+pdf_drop_annot_imp(fz_context *ctx, pdf_annot *annot)
{
- pdf_annot *next;
+ if (annot->ap)
+ pdf_drop_xobject(ctx, annot->ap);
+ pdf_drop_obj(ctx, annot->obj);
+}
+void
+pdf_drop_annots(fz_context *ctx, pdf_annot *annot)
+{
while (annot)
{
- next = annot->next;
- if (annot->ap)
- pdf_drop_xobject(ctx, annot->ap);
- pdf_drop_obj(ctx, annot->obj);
- fz_free(ctx, annot);
+ pdf_annot *next = annot->next;
+ fz_drop_annot(ctx, (fz_annot*)annot);
annot = next;
}
}
@@ -519,7 +522,7 @@ pdf_load_annots(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_obj *ann
}
fz_catch(ctx)
{
- pdf_drop_annot(ctx, page->annots);
+ pdf_drop_annots(ctx, page->annots);
page->annots = NULL;
fz_rethrow(ctx);
}
@@ -592,7 +595,7 @@ pdf_load_annots(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_obj *ann
{
if (fz_caught(ctx) == FZ_ERROR_TRYLATER)
{
- pdf_drop_annot(ctx, page->annots);
+ pdf_drop_annots(ctx, page->annots);
page->annots = NULL;
fz_rethrow(ctx);
}
@@ -603,8 +606,8 @@ pdf_load_annots(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_obj *ann
{
/* Move to next item in the linked list, dropping this one */
*itr = annot->next;
- annot->next = NULL; /* Required because pdf_drop_annot follows the "next" chain */
- pdf_drop_annot(ctx, annot);
+ annot->next = NULL; /* Required because pdf_drop_annots follows the "next" chain */
+ pdf_drop_annots(ctx, annot);
}
}
diff --git a/source/pdf/pdf-form.c b/source/pdf/pdf-form.c
index 9a2d35d9..1f101007 100644
--- a/source/pdf/pdf-form.c
+++ b/source/pdf/pdf-form.c
@@ -680,7 +680,7 @@ void pdf_update_page(fz_context *ctx, pdf_document *doc, pdf_page *page)
*/
if (page->tmp_annots)
{
- pdf_drop_annot(ctx, page->tmp_annots);
+ pdf_drop_annots(ctx, page->tmp_annots);
page->tmp_annots = NULL;
}
diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c
index d763b8c8..dcb0add4 100644
--- a/source/pdf/pdf-page.c
+++ b/source/pdf/pdf-page.c
@@ -405,11 +405,11 @@ pdf_drop_page_imp(fz_context *ctx, pdf_page *page)
if (page->links)
fz_drop_link(ctx, page->links);
if (page->annots)
- pdf_drop_annot(ctx, page->annots);
+ pdf_drop_annots(ctx, page->annots);
if (page->deleted_annots)
- pdf_drop_annot(ctx, page->deleted_annots);
+ pdf_drop_annots(ctx, page->deleted_annots);
if (page->tmp_annots)
- pdf_drop_annot(ctx, page->tmp_annots);
+ pdf_drop_annots(ctx, page->tmp_annots);
/* doc->focus, when not NULL, refers to one of
* the annotations and must be NULLed when the
* annotations are destroyed. doc->focus_obj