diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2014-09-02 20:39:21 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2014-12-03 12:25:51 +0100 |
commit | 4b8638cfa35ecacf7418ec8933f971577652bb79 (patch) | |
tree | 41fcad38598a0d0ec6e54ace3e7411aea455b86d | |
parent | 026e27be430c5d1dca82f087ed1dc1a594232b70 (diff) | |
download | mupdf-4b8638cfa35ecacf7418ec8933f971577652bb79.tar.xz |
html: Add scaffolding.
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | include/mupdf/fitz/document.h | 1 | ||||
-rw-r--r-- | include/mupdf/html.h | 12 | ||||
-rw-r--r-- | source/fitz/document-all.c | 1 | ||||
-rw-r--r-- | source/html/handler.c | 127 |
6 files changed, 150 insertions, 1 deletions
@@ -6,8 +6,11 @@ build DerivedData generated cscope.* +*.epub *.pdf *.pnm +*.html +*.xhtml tags TAGS *.xcworkspace @@ -66,6 +66,7 @@ ALL_DIR += $(OUT)/xps ALL_DIR += $(OUT)/cbz ALL_DIR += $(OUT)/img ALL_DIR += $(OUT)/tiff +ALL_DIR += $(OUT)/html ALL_DIR += $(OUT)/tools ALL_DIR += $(OUT)/platform/x11 ALL_DIR += $(OUT)/platform/x11/curl @@ -82,6 +83,7 @@ XPS_SRC := $(wildcard source/xps/*.c) CBZ_SRC := $(wildcard source/cbz/*.c) IMG_SRC := $(wildcard source/img/*.c) TIFF_SRC := $(wildcard source/tiff/*.c) +HTML_SRC := $(wildcard source/html/*.c) FITZ_SRC_HDR := $(wildcard source/fitz/*.h) PDF_SRC_HDR := $(wildcard source/pdf/*.h) @@ -89,6 +91,7 @@ XPS_SRC_HDR := $(wildcard source/xps/*.h) CBZ_SRC_HDR := $(wildcard source/cbz/*.h) IMG_SRC_HDR := $(wildcard source/img/*.h) TIFF_SRC_HDR := $(wildcard source/tiff/*.h) +HTML_SRC_HDR := $(wildcard source/html/*.h) FITZ_OBJ := $(subst source/, $(OUT)/, $(addsuffix .o, $(basename $(FITZ_SRC)))) PDF_OBJ := $(subst source/, $(OUT)/, $(addsuffix .o, $(basename $(PDF_SRC)))) @@ -96,6 +99,7 @@ XPS_OBJ := $(subst source/, $(OUT)/, $(addsuffix .o, $(basename $(XPS_SRC)))) CBZ_OBJ := $(subst source/, $(OUT)/, $(addsuffix .o, $(basename $(CBZ_SRC)))) IMG_OBJ := $(subst source/, $(OUT)/, $(addsuffix .o, $(basename $(IMG_SRC)))) TIFF_OBJ := $(subst source/, $(OUT)/, $(addsuffix .o, $(basename $(TIFF_SRC)))) +HTML_OBJ := $(subst source/, $(OUT)/, $(addsuffix .o, $(basename $(HTML_SRC)))) # --- Choice of Javascript library --- @@ -125,12 +129,13 @@ $(XPS_OBJ) : $(FITZ_HDR) $(XPS_HDR) $(XPS_SRC_HDR) $(CBZ_OBJ) : $(FITZ_HDR) $(CBZ_HDR) $(CBZ_SRC_HDR) $(IMG_OBJ) : $(FITZ_HDR) $(IMG_HDR) $(IMG_SRC_HDR) $(TIFF_OBJ) : $(FITZ_HDR) $(IMG_HDR) $(TIFF_SRC_HDR) +$(HTML_OBJ) : $(FITZ_HDR) $(IMG_HDR) $(HTML_SRC_HDR) # --- Library --- MUPDF_LIB := $(OUT)/libmupdf.a -$(MUPDF_LIB) : $(FITZ_OBJ) $(PDF_OBJ) $(XPS_OBJ) $(CBZ_OBJ) $(IMG_OBJ) $(TIFF_OBJ) +$(MUPDF_LIB) : $(FITZ_OBJ) $(PDF_OBJ) $(XPS_OBJ) $(CBZ_OBJ) $(IMG_OBJ) $(TIFF_OBJ) $(HTML_OBJ) INSTALL_LIBS := $(MUPDF_LIB) diff --git a/include/mupdf/fitz/document.h b/include/mupdf/fitz/document.h index e140bc3f..e4143819 100644 --- a/include/mupdf/fitz/document.h +++ b/include/mupdf/fitz/document.h @@ -80,6 +80,7 @@ extern fz_document_handler xps_document_handler; extern fz_document_handler cbz_document_handler; extern fz_document_handler img_document_handler; extern fz_document_handler tiff_document_handler; +extern fz_document_handler html_document_handler; void fz_register_document_handler(fz_context *ctx, const fz_document_handler *handler); diff --git a/include/mupdf/html.h b/include/mupdf/html.h new file mode 100644 index 00000000..ab67d1be --- /dev/null +++ b/include/mupdf/html.h @@ -0,0 +1,12 @@ +#ifndef MUPDF_HTML_H +#define MUPDF_HTML_H + +#include "mupdf/fitz.h" + +typedef struct html_document_s html_document; +typedef struct html_page_s html_page; + +html_document *html_open_document(fz_context *ctx, const char *filename); +html_document *html_open_document_with_stream(fz_context *ctx, fz_stream *file); + +#endif diff --git a/source/fitz/document-all.c b/source/fitz/document-all.c index e1eb4a58..1b8c52c1 100644 --- a/source/fitz/document-all.c +++ b/source/fitz/document-all.c @@ -7,4 +7,5 @@ void fz_register_document_handlers(fz_context *ctx) fz_register_document_handler(ctx, &cbz_document_handler); fz_register_document_handler(ctx, &img_document_handler); fz_register_document_handler(ctx, &tiff_document_handler); + fz_register_document_handler(ctx, &html_document_handler); } diff --git a/source/html/handler.c b/source/html/handler.c new file mode 100644 index 00000000..39d5e9c9 --- /dev/null +++ b/source/html/handler.c @@ -0,0 +1,127 @@ +#include "mupdf/html.h" + +struct html_document_s +{ + fz_document super; + fz_context *ctx; + fz_xml *root; +}; + +struct html_page_s +{ +}; + +void +html_close_document(html_document *doc) +{ + fz_context *ctx = doc->ctx; + fz_free(ctx, doc); +} + +int +html_count_pages(html_document *doc) +{ + return 1; +} + +html_page * +html_load_page(html_document *doc, int number) +{ + printf("html: load page %d\n", number); + return NULL; +} + +void +html_free_page(html_document *doc, html_page *page) +{ +} + +fz_rect * +html_bound_page(html_document *doc, html_page *page, fz_rect *bbox) +{ + printf("html: bound page\n"); + bbox->x0 = bbox->y0 = 0; + bbox->x1 = 400; + bbox->y1 = 600; + return bbox; +} + +void +html_run_page(html_document *doc, html_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie) +{ + printf("html: run page\n"); +} + +html_document * +html_open_document_with_stream(fz_context *ctx, fz_stream *file) +{ + html_document *doc; + fz_buffer *buf; + fz_xml *root; + + buf = fz_read_all(file, 0); + root = fz_parse_xml(ctx, buf->data, buf->len, 1); + fz_drop_buffer(ctx, buf); + + doc = fz_malloc_struct(ctx, html_document); + doc->ctx = ctx; + doc->root = root; + + doc->super.close = (void*)html_close_document; + doc->super.count_pages = (void*)html_count_pages; + doc->super.load_page = (void*)html_load_page; + doc->super.bound_page = (void*)html_bound_page; + doc->super.run_page_contents = (void*)html_run_page; + doc->super.free_page = (void*)html_free_page; + + return doc; +} + +html_document * +html_open_document(fz_context *ctx, const char *filename) +{ + fz_stream *file; + html_document *doc; + + file = fz_open_file(ctx, filename); + if (!file) + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); + + fz_try(ctx) + { + doc = html_open_document_with_stream(ctx, file); + } + fz_always(ctx) + { + fz_close(file); + } + fz_catch(ctx) + { + fz_rethrow(ctx); + } + + return doc; +} + +static int +html_recognize(fz_context *doc, const char *magic) +{ + char *ext = strrchr(magic, '.'); + + if (ext) + { + if (!fz_strcasecmp(ext, ".xhtml") || !fz_strcasecmp(ext, ".html")) + return 100; + } + if (!strcmp(magic, "application/html+xml") || !strcmp(magic, "application/xml") || !strcmp(magic, "text/xml")) + return 100; + + return 0; +} + +fz_document_handler html_document_handler = +{ + (fz_document_recognize_fn *)&html_recognize, + (fz_document_open_fn *)&html_open_document, + (fz_document_open_with_stream_fn *)&html_open_document_with_stream +}; |