static fz_document * epub_init(fz_context *ctx, fz_archive *zip) { epub_document *doc; doc = fz_new_document(ctx, epub_document); doc->zip = zip; doc->set = fz_new_html_font_set(ctx); doc->super.drop_document = epub_drop_document; doc->super.layout = epub_layout; doc->super.load_outline = epub_load_outline; doc->super.resolve_link = epub_resolve_link; doc->super.count_pages = epub_count_pages; doc->super.load_page = epub_load_page; doc->super.lookup_metadata = epub_lookup_metadata; doc->super.is_reflowable = 1; fz_try(ctx) { epub_parse_header(ctx, doc); } fz_catch(ctx) { fz_drop_document(ctx, &doc->super); fz_rethrow(ctx); } return (fz_document*)doc; }
static tiff_document * tiff_open_document_with_stream(fz_context *ctx, fz_stream *file) { tiff_document *doc; doc = fz_new_document(ctx, sizeof *doc); doc->super.close = (fz_document_close_fn *)tiff_close_document; doc->super.count_pages = (fz_document_count_pages_fn *)tiff_count_pages; doc->super.load_page = (fz_document_load_page_fn *)tiff_load_page; doc->super.meta = (fz_document_meta_fn *)tiff_meta; fz_try(ctx) { doc->buffer = fz_read_all(ctx, file, 1024); doc->page_count = fz_load_tiff_subimage_count(ctx, doc->buffer->data, doc->buffer->len); } fz_catch(ctx) { tiff_close_document(ctx, doc); fz_rethrow(ctx); } return doc; }
static fz_document * htdoc_open_document(fz_context *ctx, const char *filename) { char dirname[2048]; fz_buffer *buf; html_document *doc; fz_dirname(dirname, filename, sizeof dirname); doc = fz_new_document(ctx, sizeof *doc); doc->super.close = htdoc_close_document; doc->super.layout = htdoc_layout; doc->super.count_pages = htdoc_count_pages; doc->super.load_page = htdoc_load_page; doc->super.lookup_metadata = htdoc_lookup_metadata; doc->zip = fz_open_directory(ctx, dirname); doc->set = fz_new_html_font_set(ctx); buf = fz_read_file(ctx, filename); fz_write_buffer_byte(ctx, buf, 0); doc->box = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, fz_user_css(ctx)); fz_drop_buffer(ctx, buf); return (fz_document*)doc; }
static tiff_document * tiff_open_document_with_stream(fz_context *ctx, fz_stream *file) { tiff_document *doc; doc = fz_new_document(ctx, tiff_document); doc->super.drop_document = (fz_document_drop_fn *)tiff_drop_document; doc->super.count_pages = (fz_document_count_pages_fn *)tiff_count_pages; doc->super.load_page = (fz_document_load_page_fn *)tiff_load_page; doc->super.lookup_metadata = (fz_document_lookup_metadata_fn *)tiff_lookup_metadata; fz_try(ctx) { size_t len; unsigned char *data; doc->buffer = fz_read_all(ctx, file, 1024); len = fz_buffer_storage(ctx, doc->buffer, &data); doc->page_count = fz_load_tiff_subimage_count(ctx, data, len); } fz_catch(ctx) { fz_drop_document(ctx, &doc->super); fz_rethrow(ctx); } return doc; }
static img_document * img_new_document(fz_context *ctx, fz_image *image) { img_document *doc = fz_new_document(ctx, sizeof *doc); doc->super.close = (fz_document_close_fn *)img_close_document; doc->super.count_pages = (fz_document_count_pages_fn *)img_count_pages; doc->super.load_page = (fz_document_load_page_fn *)img_load_page; doc->super.lookup_metadata = (fz_document_lookup_metadata_fn *)img_lookup_metadata; doc->image = fz_keep_image(ctx, image); return doc; }
static fz_document * svg_open_document_with_buffer(fz_context *ctx, fz_buffer *buf) { svg_document *doc; fz_xml *root; root = fz_parse_xml(ctx, buf->data, buf->len, 0); doc = fz_new_document(ctx, svg_document); doc->super.close = svg_close_document; doc->super.count_pages = svg_count_pages; doc->super.load_page = svg_load_page; doc->root = root; doc->idmap = NULL; svg_build_id_map(ctx, doc, root); return (fz_document*)doc; }
static cbz_document * cbz_open_document_with_stream(fz_context *ctx, fz_stream *file) { cbz_document *doc = fz_new_document(ctx, sizeof *doc); doc->super.close = (fz_document_close_fn *)cbz_close_document; doc->super.count_pages = (fz_document_count_pages_fn *)cbz_count_pages; doc->super.load_page = (fz_document_load_page_fn *)cbz_load_page; doc->super.lookup_metadata = (fz_document_lookup_metadata_fn *)cbz_lookup_metadata; fz_try(ctx) { doc->zip = fz_open_archive_with_stream(ctx, file); cbz_create_page_list(ctx, doc); } fz_catch(ctx) { cbz_close_document(ctx, doc); fz_rethrow(ctx); } return doc; }
static fz_document * svg_open_document_with_buffer(fz_context *ctx, fz_buffer *buf) { svg_document *doc; fz_xml *root; size_t len; unsigned char *data; len = fz_buffer_storage(ctx, buf, &data); root = fz_parse_xml(ctx, data, len, 0); doc = fz_new_document(ctx, svg_document); doc->super.drop_document = svg_drop_document; doc->super.count_pages = svg_count_pages; doc->super.load_page = svg_load_page; doc->root = root; doc->idmap = NULL; svg_build_id_map(ctx, doc, root); return (fz_document*)doc; }
static fz_document * htdoc_open_document_with_stream(fz_context *ctx, fz_stream *file) { html_document *doc; fz_buffer *buf; doc = fz_new_document(ctx, sizeof *doc); doc->super.close = htdoc_close_document; doc->super.layout = htdoc_layout; doc->super.count_pages = htdoc_count_pages; doc->super.load_page = htdoc_load_page; doc->zip = fz_open_directory(ctx, "."); doc->set = fz_new_html_font_set(ctx); buf = fz_read_all(ctx, file, 0); fz_write_buffer_byte(ctx, buf, 0); doc->box = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, fz_user_css(ctx)); fz_drop_buffer(ctx, buf); return (fz_document*)doc; }