diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2012-02-03 15:14:13 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2012-02-03 15:14:13 +0100 |
commit | 27cc2be0735b9ff115a9565b905f3b46f26e9ec8 (patch) | |
tree | c405c62bee5d3f7e618d567e95ee6a83ed53220e | |
parent | 70efb11990b0947e04d0051db8a813b9a0a0e4a4 (diff) | |
download | mupdf-27cc2be0735b9ff115a9565b905f3b46f26e9ec8.tar.xz |
Reference count fz_link objects.
-rw-r--r-- | android/jni/Core.mk | 3 | ||||
-rw-r--r-- | apps/pdfapp.c | 8 | ||||
-rw-r--r-- | fitz/doc_link.c (renamed from fitz/base_link.c) | 18 | ||||
-rw-r--r-- | fitz/fitz.h | 4 | ||||
-rw-r--r-- | pdf/pdf_page.c | 4 | ||||
-rw-r--r-- | xps/muxps.h | 1 | ||||
-rw-r--r-- | xps/xps_doc.c | 4 |
7 files changed, 26 insertions, 16 deletions
diff --git a/android/jni/Core.mk b/android/jni/Core.mk index 79de7230..b8a93c0d 100644 --- a/android/jni/Core.mk +++ b/android/jni/Core.mk @@ -25,7 +25,6 @@ LOCAL_SRC_FILES := \ $(MY_ROOT)/fitz/base_geometry.c \ $(MY_ROOT)/fitz/base_getopt.c \ $(MY_ROOT)/fitz/base_hash.c \ - $(MY_ROOT)/fitz/base_link.c \ $(MY_ROOT)/fitz/base_memory.c \ $(MY_ROOT)/fitz/base_object.c \ $(MY_ROOT)/fitz/base_string.c \ @@ -39,6 +38,8 @@ LOCAL_SRC_FILES := \ $(MY_ROOT)/fitz/dev_null.c \ $(MY_ROOT)/fitz/dev_text.c \ $(MY_ROOT)/fitz/dev_trace.c \ + $(MY_ROOT)/fitz/doc_document.c \ + $(MY_ROOT)/fitz/doc_link.c \ $(MY_ROOT)/fitz/doc_outline.c \ $(MY_ROOT)/fitz/filt_basic.c \ $(MY_ROOT)/fitz/filt_dctd.c \ diff --git a/apps/pdfapp.c b/apps/pdfapp.c index aba2056f..cd4b0747 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -178,7 +178,7 @@ void pdfapp_close(pdfapp_t *app) app->page_text = NULL; if (app->page_links) - fz_free_link(app->ctx, app->page_links); + fz_drop_link(app->ctx, app->page_links); app->page_links = NULL; if (app->doctitle) @@ -242,8 +242,8 @@ static void pdfapp_loadpage(pdfapp_t *app) fz_free_display_list(app->ctx, app->page_list); if (app->page_text) fz_free_text_span(app->ctx, app->page_text); -// if (app->page_links) // TODO: ownership -// fz_free_link(app->ctx, app->page_links); + if (app->page_links) + fz_drop_link(app->ctx, app->page_links); if (app->page) fz_free_page(app->doc, app->page); @@ -258,7 +258,7 @@ static void pdfapp_loadpage(pdfapp_t *app) fz_free_device(mdev); app->page_bbox = fz_bound_page(app->doc, app->page); - app->page_links = fz_load_links(app->doc, app->page); // FIXME: refcount or ownership of links + app->page_links = fz_load_links(app->doc, app->page); } fz_catch(app->ctx) { diff --git a/fitz/base_link.c b/fitz/doc_link.c index cf173b7a..c9065f24 100644 --- a/fitz/base_link.c +++ b/fitz/doc_link.c @@ -31,6 +31,7 @@ fz_new_link(fz_context *ctx, fz_rect bbox, fz_link_dest dest) fz_try(ctx) { link = fz_malloc_struct(ctx, fz_link); + link->refs = 1; } fz_catch(ctx) { @@ -43,16 +44,21 @@ fz_new_link(fz_context *ctx, fz_rect bbox, fz_link_dest dest) return link; } -void -fz_free_link(fz_context *ctx, fz_link *link) +fz_link * +fz_keep_link(fz_context *ctx, fz_link *link) { - fz_link *next; + if (link) + link->refs++; + return link; +} - while (link) +void +fz_drop_link(fz_context *ctx, fz_link *link) +{ + if (--link->refs == 0) { - next = link->next; + fz_drop_link(ctx, link->next); fz_free_link_dest(ctx, &link->dest); fz_free(ctx, link); - link = next; } } diff --git a/fitz/fitz.h b/fitz/fitz.h index d22c6661..a97817db 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -1569,13 +1569,15 @@ struct fz_link_dest_s struct fz_link_s { + int refs; fz_rect rect; fz_link_dest dest; fz_link *next; }; fz_link *fz_new_link(fz_context *ctx, fz_rect bbox, fz_link_dest dest); -void fz_free_link(fz_context *ctx, fz_link *link); +fz_link *fz_keep_link(fz_context *ctx, fz_link *link); +void fz_drop_link(fz_context *ctx, fz_link *link); void fz_free_link_dest(fz_context *ctx, fz_link_dest *dest); /* Outline */ diff --git a/pdf/pdf_page.c b/pdf/pdf_page.c index 6f7a97e3..f2bf713e 100644 --- a/pdf/pdf_page.c +++ b/pdf/pdf_page.c @@ -401,7 +401,7 @@ pdf_bound_page(pdf_document *xref, pdf_page *page) fz_link * pdf_load_links(pdf_document *xref, pdf_page *page) { - return page->links; + return fz_keep_link(xref->ctx, page->links); } void @@ -412,7 +412,7 @@ pdf_free_page(pdf_document *xref, pdf_page *page) if (page->contents) fz_drop_buffer(xref->ctx, page->contents); if (page->links) - fz_free_link(xref->ctx, page->links); + fz_drop_link(xref->ctx, page->links); if (page->annots) pdf_free_annot(xref->ctx, page->annots); fz_free(xref->ctx, page); diff --git a/xps/muxps.h b/xps/muxps.h index 6a6f345f..6037a64e 100644 --- a/xps/muxps.h +++ b/xps/muxps.h @@ -108,6 +108,7 @@ void xps_free_page_list(xps_document *doc); int xps_count_pages(xps_document *doc); xps_page *xps_load_page(xps_document *doc, int number); +fz_link *xps_load_links(xps_document *doc, xps_page *page); fz_rect xps_bound_page(xps_document *doc, xps_page *page); void xps_free_page(xps_document *doc, xps_page *page); diff --git a/xps/xps_doc.c b/xps/xps_doc.c index 3a4738dd..340cd700 100644 --- a/xps/xps_doc.c +++ b/xps/xps_doc.c @@ -146,7 +146,7 @@ xps_load_links(xps_document *doc, xps_page *page) { if (!page->links_resolved) fz_warn(doc->ctx, "xps_load_links before page has been executed!"); - return page->links; + return fz_keep_link(doc->ctx, page->links); } static void @@ -463,6 +463,6 @@ xps_free_page(xps_document *doc, xps_page *page) /* only free the XML contents */ if (page->root) xml_free_element(doc->ctx, page->root); - fz_free_link(doc->ctx, page->links); + fz_drop_link(doc->ctx, page->links); page->root = NULL; } |