diff options
Diffstat (limited to 'source/fitz/document.c')
-rw-r--r-- | source/fitz/document.c | 167 |
1 files changed, 96 insertions, 71 deletions
diff --git a/source/fitz/document.c b/source/fitz/document.c index ad2e84ba..40113469 100644 --- a/source/fitz/document.c +++ b/source/fitz/document.c @@ -142,121 +142,142 @@ fz_open_document(fz_context *ctx, const char *filename) return NULL; } -void -fz_close_document(fz_document *doc) +void * +fz_new_document(fz_context *ctx, int size) +{ + fz_document *doc = fz_calloc(ctx, 1, size); + doc->refs = 1; + return doc; +} + +fz_document * +fz_keep_document(fz_context *ctx, fz_document *doc) { - if (doc && 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) { @@ -267,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) { @@ -286,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) @@ -314,43 +333,49 @@ 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 = Memento_label(fz_calloc(ctx, 1, size), "fz_page"); + 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_free(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); -} |