diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2015-01-21 16:42:45 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2015-02-17 18:05:39 +0100 |
commit | f84a189d5f94250e46d2cbd1a75aba00130e2dd6 (patch) | |
tree | 8ee614ab90de1baa8941f91ae4946ed5c2e70721 /source/fitz/document.c | |
parent | 681039767f2ccc72e236246178893eb0989169c9 (diff) | |
download | mupdf-f84a189d5f94250e46d2cbd1a75aba00130e2dd6.tar.xz |
Add ctx parameter and remove embedded contexts for API regularity.
Purge several embedded contexts:
Remove embedded context in fz_output.
Remove embedded context in fz_stream.
Remove embedded context in fz_device.
Remove fz_rebind_stream (since it is no longer necessary).
Remove embedded context in svg_device.
Remove embedded context in XML parser.
Add ctx argument to fz_document functions.
Remove embedded context in fz_document.
Remove embedded context in pdf_document.
Remove embedded context in pdf_obj.
Make fz_page independent of fz_document in the interface.
We shouldn't need to pass the document to all functions handling a page.
If a page is tied to the source document, it's redundant; otherwise it's
just pointless.
Fix reference counting oddity in fz_new_image_from_pixmap.
Diffstat (limited to 'source/fitz/document.c')
-rw-r--r-- | source/fitz/document.c | 163 |
1 files changed, 89 insertions, 74 deletions
diff --git a/source/fitz/document.c b/source/fitz/document.c index 64de1bc0..63c9fd29 100644 --- a/source/fitz/document.c +++ b/source/fitz/document.c @@ -142,128 +142,142 @@ fz_open_document(fz_context *ctx, const char *filename) return NULL; } -fz_document * -fz_keep_document(fz_document *doc) +void * +fz_new_document(fz_context *ctx, int size) { - ++doc->refs; + fz_document *doc = fz_calloc(ctx, 1, size); + doc->refs = 1; return doc; } -void -fz_drop_document(fz_document *doc) +fz_document * +fz_keep_document(fz_context *ctx, fz_document *doc) { - if (doc && --doc->refs == 0 && doc->close) - doc->close(doc); + ++doc->refs; + return doc; } void -fz_rebind_document(fz_document *doc, fz_context *ctx) +fz_drop_document(fz_context *ctx, fz_document *doc) { - if (doc != NULL && doc->rebind != NULL) - doc->rebind(doc, ctx); + if (doc && --doc->refs == 0 && doc->close) + doc->close(ctx, doc); } int -fz_needs_password(fz_document *doc) +fz_needs_password(fz_context *ctx, fz_document *doc) { if (doc && doc->needs_password) - return doc->needs_password(doc); + return doc->needs_password(ctx, doc); return 0; } int -fz_authenticate_password(fz_document *doc, const char *password) +fz_authenticate_password(fz_context *ctx, fz_document *doc, const char *password) { if (doc && doc->authenticate_password) - return doc->authenticate_password(doc, password); + return doc->authenticate_password(ctx, doc, password); return 1; } fz_outline * -fz_load_outline(fz_document *doc) +fz_load_outline(fz_context *ctx, fz_document *doc) { if (doc && doc->load_outline) - return doc->load_outline(doc); + return doc->load_outline(ctx, doc); return NULL; } void -fz_layout_document(fz_document *doc, float w, float h, float em) +fz_layout_document(fz_context *ctx, fz_document *doc, float w, float h, float em) { if (doc && doc->layout) - doc->layout(doc, w, h, em); + doc->layout(ctx, doc, w, h, em); } int -fz_count_pages(fz_document *doc) +fz_count_pages(fz_context *ctx, fz_document *doc) { if (doc && doc->count_pages) - return doc->count_pages(doc); + return doc->count_pages(ctx, doc); return 0; } +int +fz_meta(fz_context *ctx, fz_document *doc, int key, void *ptr, int size) +{ + if (doc && doc->meta) + return doc->meta(ctx, doc, key, ptr, size); + return FZ_META_UNKNOWN_KEY; +} + +void +fz_write_document(fz_context *ctx, fz_document *doc, char *filename, fz_write_options *opts) +{ + if (doc && doc->write) + doc->write(ctx, doc, filename, opts); +} + fz_page * -fz_load_page(fz_document *doc, int number) +fz_load_page(fz_context *ctx, fz_document *doc, int number) { if (doc && doc->load_page) - return doc->load_page(doc, number); + return doc->load_page(ctx, doc, number); return NULL; } fz_link * -fz_load_links(fz_document *doc, fz_page *page) +fz_load_links(fz_context *ctx, fz_page *page) { - if (doc && doc->load_links && page) - return doc->load_links(doc, page); + if (page && page->load_links && page) + return page->load_links(ctx, page); return NULL; } fz_rect * -fz_bound_page(fz_document *doc, fz_page *page, fz_rect *r) +fz_bound_page(fz_context *ctx, fz_page *page, fz_rect *r) { - if (doc && doc->bound_page && page && r) - return doc->bound_page(doc, page, r); + if (page && page->bound_page && page && r) + return page->bound_page(ctx, page, r); if (r) *r = fz_empty_rect; return r; } fz_annot * -fz_first_annot(fz_document *doc, fz_page *page) +fz_first_annot(fz_context *ctx, fz_page *page) { - if (doc && doc->first_annot && page) - return doc->first_annot(doc, page); + if (page && page->first_annot && page) + return page->first_annot(ctx, page); return NULL; } fz_annot * -fz_next_annot(fz_document *doc, fz_annot *annot) +fz_next_annot(fz_context *ctx, fz_page *page, fz_annot *annot) { - if (doc && doc->next_annot && annot) - return doc->next_annot(doc, annot); + if (page && page->next_annot && annot) + return page->next_annot(ctx, page, annot); return NULL; } fz_rect * -fz_bound_annot(fz_document *doc, fz_annot *annot, fz_rect *rect) +fz_bound_annot(fz_context *ctx, fz_page *page, fz_annot *annot, fz_rect *rect) { - if (doc && doc->bound_annot && annot && rect) - return doc->bound_annot(doc, annot, rect); + if (page && page->bound_annot && annot && rect) + return page->bound_annot(ctx, page, annot, rect); if (rect) *rect = fz_empty_rect; return rect; } void -fz_run_page_contents(fz_document *doc, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie) +fz_run_page_contents(fz_context *ctx, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie) { - if (doc && doc->run_page_contents && page) + if (page && page->run_page_contents && page) { - fz_context *ctx = dev->ctx; - fz_try(ctx) { - doc->run_page_contents(doc, page, dev, transform, cookie); + page->run_page_contents(ctx, page, dev, transform, cookie); } fz_catch(ctx) { @@ -274,15 +288,13 @@ fz_run_page_contents(fz_document *doc, fz_page *page, fz_device *dev, const fz_m } void -fz_run_annot(fz_document *doc, fz_page *page, fz_annot *annot, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie) +fz_run_annot(fz_context *ctx, fz_page *page, fz_annot *annot, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie) { - if (doc && doc->run_annot && page && annot) + if (page && page->run_annot && page && annot) { - fz_context *ctx = dev->ctx; - fz_try(ctx) { - doc->run_annot(doc, page, annot, dev, transform, cookie); + page->run_annot(ctx, page, annot, dev, transform, cookie); } fz_catch(ctx) { @@ -293,25 +305,25 @@ fz_run_annot(fz_document *doc, fz_page *page, fz_annot *annot, fz_device *dev, c } void -fz_run_page(fz_document *doc, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie) +fz_run_page(fz_context *ctx, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie) { fz_annot *annot; fz_rect mediabox; - fz_bound_page(doc, page, &mediabox); - fz_begin_page(dev, &mediabox, transform); + fz_bound_page(ctx, page, &mediabox); + fz_begin_page(ctx, dev, &mediabox, transform); - fz_run_page_contents(doc, page, dev, transform, cookie); + fz_run_page_contents(ctx, page, dev, transform, cookie); if (cookie && cookie->progress_max != -1) { int count = 1; - for (annot = fz_first_annot(doc, page); annot; annot = fz_next_annot(doc, annot)) + for (annot = fz_first_annot(ctx, page); annot; annot = fz_next_annot(ctx, page, annot)) count++; cookie->progress_max += count; } - for (annot = fz_first_annot(doc, page); annot; annot = fz_next_annot(doc, annot)) + for (annot = fz_first_annot(ctx, page); annot; annot = fz_next_annot(ctx, page, annot)) { /* Check the cookie for aborting */ if (cookie) @@ -321,43 +333,46 @@ fz_run_page(fz_document *doc, fz_page *page, fz_device *dev, const fz_matrix *tr cookie->progress++; } - fz_run_annot(doc, page, annot, dev, transform, cookie); + fz_run_annot(ctx, page, annot, dev, transform, cookie); } - fz_end_page(dev); + fz_end_page(ctx, dev); } -void -fz_free_page(fz_document *doc, fz_page *page) +void * +fz_new_page(fz_context *ctx, int size) { - if (doc && doc->free_page && page) - doc->free_page(doc, page); + fz_page *page = fz_calloc(ctx, 1, size); + page->refs = 1; + return page; } -int -fz_meta(fz_document *doc, int key, void *ptr, int size) +fz_page * +fz_keep_page(fz_context *ctx, fz_page *page) { - if (doc && doc->meta) - return doc->meta(doc, key, ptr, size); - return FZ_META_UNKNOWN_KEY; + if (page) + ++page->refs; + return page; +} + +void +fz_drop_page(fz_context *ctx, fz_page *page) +{ + if (page) { + if (--page->refs == 0 && page->drop_page_imp) + page->drop_page_imp(ctx, page); + } } fz_transition * -fz_page_presentation(fz_document *doc, fz_page *page, float *duration) +fz_page_presentation(fz_context *ctx, fz_page *page, float *duration) { float dummy; if (duration) *duration = 0; else duration = &dummy; - if (doc && doc->page_presentation && page) - return doc->page_presentation(doc, page, duration); + if (page && page->page_presentation && page) + return page->page_presentation(ctx, page, duration); return NULL; } - -void -fz_write_document(fz_document *doc, char *filename, fz_write_options *opts) -{ - if (doc && doc->write) - doc->write(doc, filename, opts); -} |