diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2018-08-10 15:12:16 +0200 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2018-09-19 17:13:45 +0100 |
commit | 6ff43c0f084b2ca5356ee6710b23fd751ce94749 (patch) | |
tree | 8a99682d6098d98a13b8f20af69b95ad8eff4fb6 | |
parent | 29af4a4709fea3ad06514083d3e96f08a202ebf4 (diff) | |
download | mupdf-6ff43c0f084b2ca5356ee6710b23fd751ce94749.tar.xz |
Make fz_page objects singleton.
Keep a list of currently open pages for each document. Attempting to
load a page that is already loaded will return the same instance again.
-rw-r--r-- | include/mupdf/fitz/document.h | 3 | ||||
-rw-r--r-- | source/fitz/document.c | 26 |
2 files changed, 28 insertions, 1 deletions
diff --git a/include/mupdf/fitz/document.h b/include/mupdf/fitz/document.h index 3e6ac1e9..9b506cba 100644 --- a/include/mupdf/fitz/document.h +++ b/include/mupdf/fitz/document.h @@ -209,6 +209,7 @@ struct fz_annot_s struct fz_page_s { int refs; + int number; /* page number */ fz_page_drop_page_fn *drop_page; fz_page_bound_page_fn *bound_page; fz_page_run_page_contents_fn *run_page_contents; @@ -219,6 +220,7 @@ struct fz_page_s fz_page_separation_disabled_fn *separation_disabled; fz_page_separations_fn *separations; fz_page_uses_overprint_fn *overprint; + fz_page **prev, *next; /* linked list of currently open pages */ }; /* @@ -245,6 +247,7 @@ struct fz_document_s fz_document_output_intent_fn *get_output_intent; int did_layout; int is_reflowable; + fz_page *open; /* linked list of currently open pages */ }; /* diff --git a/source/fitz/document.c b/source/fitz/document.c index 013badb0..26ae93ea 100644 --- a/source/fitz/document.c +++ b/source/fitz/document.c @@ -319,9 +319,27 @@ fz_document_output_intent(fz_context *ctx, fz_document *doc) fz_page * fz_load_page(fz_context *ctx, fz_document *doc, int number) { + fz_page *page; + fz_ensure_layout(ctx, doc); + + for (page = doc->open; page; page = page->next) + if (page->number == number) + return fz_keep_page(ctx, page); + if (doc && doc->load_page) - return doc->load_page(ctx, doc, number); + { + page = doc->load_page(ctx, doc, number); + page->number = number; + + /* Insert new page at the head of the list of open pages. */ + if ((page->next = doc->open) != NULL) + doc->open->prev = &page->next; + doc->open = page; + page->prev = &doc->open; + return page; + } + return NULL; } @@ -472,8 +490,14 @@ fz_drop_page(fz_context *ctx, fz_page *page) { if (fz_drop_imp(ctx, page, &page->refs)) { + /* Remove page from the list of open pages */ + if (page->next != NULL) + page->next->prev = page->prev; + *page->prev = page->next; + if (page->drop_page) page->drop_page(ctx, page); + fz_free(ctx, page); } } |