summaryrefslogtreecommitdiff
path: root/source/fitz
diff options
context:
space:
mode:
Diffstat (limited to 'source/fitz')
-rw-r--r--source/fitz/document.c26
1 files changed, 25 insertions, 1 deletions
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);
}
}