summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-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
5 files changed, 41 insertions, 17 deletions
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