From b8eb55a488aa9dc6884e01b06e948faf1f83012d Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 7 Apr 2015 14:27:48 +0200 Subject: Trigger default layout in fz_document layer. Trigger the default layout when needed, but only if no manual layout has been done. This avoids doing a pointless double layout (once with default when loading the document, then with the manual layout call with the desired layout options). --- include/mupdf/fitz/document.h | 1 + source/fitz/document.c | 19 +++++++++++++++++++ source/html/epub-doc.c | 5 ----- source/html/html-doc.c | 8 -------- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/include/mupdf/fitz/document.h b/include/mupdf/fitz/document.h index d19b3661..f633fdbe 100644 --- a/include/mupdf/fitz/document.h +++ b/include/mupdf/fitz/document.h @@ -67,6 +67,7 @@ struct fz_document_s fz_document_load_page_fn *load_page; fz_document_meta_fn *meta; fz_document_write_fn *write; + int did_layout; }; typedef fz_document *(fz_document_open_fn)(fz_context *ctx, const char *filename); diff --git a/source/fitz/document.c b/source/fitz/document.c index 40113469..232aa931 100644 --- a/source/fitz/document.c +++ b/source/fitz/document.c @@ -5,6 +5,10 @@ enum FZ_DOCUMENT_HANDLER_MAX = 10 }; +#define DEFW (450) +#define DEFH (600) +#define DEFEM (12) + struct fz_document_handler_context_s { int refs; @@ -164,6 +168,16 @@ fz_drop_document(fz_context *ctx, fz_document *doc) doc->close(ctx, doc); } +static void +fz_ensure_layout(fz_context *ctx, fz_document *doc) +{ + if (doc && doc->layout && !doc->did_layout) + { + doc->layout(ctx, doc, DEFW, DEFH, DEFEM); + doc->did_layout = 1; + } +} + int fz_needs_password(fz_context *ctx, fz_document *doc) { @@ -192,12 +206,16 @@ void fz_layout_document(fz_context *ctx, fz_document *doc, float w, float h, float em) { if (doc && doc->layout) + { doc->layout(ctx, doc, w, h, em); + doc->did_layout = 1; + } } int fz_count_pages(fz_context *ctx, fz_document *doc) { + fz_ensure_layout(ctx, doc); if (doc && doc->count_pages) return doc->count_pages(ctx, doc); return 0; @@ -221,6 +239,7 @@ fz_write_document(fz_context *ctx, fz_document *doc, char *filename, fz_write_op fz_page * fz_load_page(fz_context *ctx, fz_document *doc, int number) { + fz_ensure_layout(ctx, doc); if (doc && doc->load_page) return doc->load_page(ctx, doc, number); return NULL; diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c index 51eca0b9..9b518bd0 100644 --- a/source/html/epub-doc.c +++ b/source/html/epub-doc.c @@ -1,9 +1,5 @@ #include "mupdf/html.h" -#define DEFW (450) -#define DEFH (600) -#define DEFEM (12) - typedef struct epub_document_s epub_document; typedef struct epub_chapter_s epub_chapter; typedef struct epub_page_s epub_page; @@ -270,7 +266,6 @@ epub_init(fz_context *ctx, fz_archive *zip) fz_try(ctx) { epub_parse_header(ctx, doc); - epub_layout(ctx, (fz_document*)doc, DEFW, DEFH, DEFEM); } fz_catch(ctx) { diff --git a/source/html/html-doc.c b/source/html/html-doc.c index 80bc98b3..55a743ed 100644 --- a/source/html/html-doc.c +++ b/source/html/html-doc.c @@ -1,9 +1,5 @@ #include "mupdf/html.h" -#define DEFW (450) -#define DEFH (600) -#define DEFEM (12) - typedef struct html_document_s html_document; typedef struct html_page_s html_page; @@ -109,8 +105,6 @@ htdoc_open_document_with_stream(fz_context *ctx, fz_stream *file) doc->box = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, NULL); fz_drop_buffer(ctx, buf); - htdoc_layout(ctx, (fz_document*)doc, DEFW, DEFH, DEFEM); - return (fz_document*)doc; } @@ -137,8 +131,6 @@ htdoc_open_document(fz_context *ctx, const char *filename) doc->box = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, NULL); fz_drop_buffer(ctx, buf); - htdoc_layout(ctx, (fz_document*)doc, DEFW, DEFH, DEFEM); - return (fz_document*)doc; } -- cgit v1.2.3