static cbz_page * cbz_load_page(fz_context *ctx, cbz_document *doc, int number) { unsigned char *data = NULL; cbz_page *page = NULL; fz_buffer *buf; if (number < 0 || number >= doc->page_count) return NULL; fz_var(data); fz_var(page); buf = fz_read_archive_entry(ctx, doc->zip, doc->page[number]); fz_try(ctx) { page = fz_new_page(ctx, sizeof *page); page->super.bound_page = (fz_page_bound_page_fn *)cbz_bound_page; page->super.run_page_contents = (fz_page_run_page_contents_fn *)cbz_run_page; page->super.drop_page_imp = (fz_page_drop_page_imp_fn *)cbz_drop_page_imp; page->image = fz_new_image_from_buffer(ctx, buf); } fz_always(ctx) { fz_drop_buffer(ctx, buf); } fz_catch(ctx) { fz_free(ctx, data); cbz_drop_page_imp(ctx, page); fz_rethrow(ctx); } return page; }
static fz_page * htdoc_load_page(fz_context *ctx, fz_document *doc_, int number) { html_document *doc = (html_document*)doc_; html_page *page = fz_new_page(ctx, sizeof *page); page->super.bound_page = htdoc_bound_page; page->super.run_page_contents = htdoc_run_page; page->super.drop_page_imp = htdoc_drop_page_imp; page->doc = doc; page->number = number; return (fz_page*)page; }
static fz_page * epub_load_page(fz_context *ctx, fz_document *doc_, int number) { epub_document *doc = (epub_document*)doc_; epub_page *page = fz_new_page(ctx, sizeof *page); page->super.bound_page = epub_bound_page; page->super.run_page_contents = epub_run_page; page->super.drop_page_imp = epub_drop_page_imp; page->doc = doc; page->number = number; return (fz_page*)page; }
static fz_page * svg_load_page(fz_context *ctx, fz_document *doc_, int number) { svg_document *doc = (svg_document*)doc_; svg_page *page; if (number != 0) return NULL; page = fz_new_page(ctx, sizeof *page); page->super.bound_page = svg_bound_page; page->super.run_page_contents = svg_run_page; page->super.drop_page = svg_drop_page; page->doc = doc; return (fz_page*)page; }
static img_page * img_load_page(fz_context *ctx, img_document *doc, int number) { img_page *page; if (number != 0) return NULL; page = fz_new_page(ctx, sizeof *page); page->super.bound_page = (fz_page_bound_page_fn *)img_bound_page; page->super.run_page_contents = (fz_page_run_page_contents_fn *)img_run_page; page->super.drop_page_imp = (fz_page_drop_page_imp_fn *)img_drop_page_imp; page->image = fz_keep_image(ctx, doc->image); return page; }
static tiff_page * tiff_load_page(fz_context *ctx, tiff_document *doc, int number) { fz_pixmap *pixmap = NULL; fz_image *image = NULL; tiff_page *page = NULL; if (number < 0 || number >= doc->page_count) return NULL; fz_var(pixmap); fz_var(image); fz_var(page); fz_try(ctx) { size_t len; unsigned char *data; len = fz_buffer_storage(ctx, doc->buffer, &data); pixmap = fz_load_tiff_subimage(ctx, data, len, number); image = fz_new_image_from_pixmap(ctx, pixmap, NULL); page = fz_new_page(ctx, sizeof *page); page->super.bound_page = (fz_page_bound_page_fn *)tiff_bound_page; page->super.run_page_contents = (fz_page_run_page_contents_fn *)tiff_run_page; page->super.drop_page = (fz_page_drop_page_fn *)tiff_drop_page; page->image = fz_keep_image(ctx, image); } fz_always(ctx) { fz_drop_image(ctx, image); fz_drop_pixmap(ctx, pixmap); } fz_catch(ctx) { fz_free(ctx, page); fz_rethrow(ctx); } return page; }
xps_page * xps_load_page(fz_context *ctx, xps_document *doc, int number) { xps_page *page = NULL; xps_fixpage *fix; fz_xml *root; int n = 0; fz_var(page); for (fix = doc->first_page; fix; fix = fix->next) { if (n == number) { root = xps_load_fixed_page(ctx, doc, fix); fz_try(ctx) { page = fz_new_page(ctx, sizeof *page); page->super.load_links = (fz_page_load_links_fn *)xps_load_links; page->super.bound_page = (fz_page_bound_page_fn *)xps_bound_page; page->super.run_page_contents = (fz_page_run_page_contents_fn *)xps_run_page; page->super.drop_page_imp = (fz_page_drop_page_imp_fn *)xps_drop_page_imp; page->doc = (xps_document*) fz_keep_document(ctx, &doc->super); page->fix = fix; page->root = root; } fz_catch(ctx) { fz_drop_xml(ctx, root); fz_rethrow(ctx); } return page; } n ++; }