summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-01-07 14:21:23 +0100
committerTor Andersson <tor.andersson@artifex.com>2016-01-08 13:00:45 +0100
commit48afdad75f42b1eb165e87ffd69ae1195ada9350 (patch)
tree09683abf4d2ac046366842ed6d27cce127085e4a
parent948afc03e1385b1a26eaede946b67daace0376f4 (diff)
downloadmupdf-48afdad75f42b1eb165e87ffd69ae1195ada9350.tar.xz
pdf: Add function to look up the page for a named destination.
-rw-r--r--include/mupdf/pdf/page.h8
-rw-r--r--source/pdf/pdf-page.c18
2 files changed, 26 insertions, 0 deletions
diff --git a/include/mupdf/pdf/page.h b/include/mupdf/pdf/page.h
index 7cf6da44..1b8fa755 100644
--- a/include/mupdf/pdf/page.h
+++ b/include/mupdf/pdf/page.h
@@ -6,6 +6,14 @@ int pdf_count_pages(fz_context *ctx, pdf_document *doc);
pdf_obj *pdf_lookup_page_obj(fz_context *ctx, pdf_document *doc, int needle);
/*
+ pdf_lookup_anchor: Find the page number of a named destination.
+
+ For use with looking up the destination page of a fragment
+ identifier in hyperlinks: foo.pdf#bar.
+*/
+int pdf_lookup_anchor(fz_context *ctx, pdf_document *doc, const char *name);
+
+/*
pdf_load_page: Load a page and its resources.
Locates the page in the PDF document and loads the page and its
diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c
index dcb0add4..d893d204 100644
--- a/source/pdf/pdf-page.c
+++ b/source/pdf/pdf-page.c
@@ -200,6 +200,24 @@ pdf_lookup_page_number(fz_context *ctx, pdf_document *doc, pdf_obj *node)
return total;
}
+int
+pdf_lookup_anchor(fz_context *ctx, pdf_document *doc, const char *name)
+{
+ pdf_obj *needle, *dest;
+ fz_link_dest ld;
+
+ needle = pdf_new_string(ctx, doc, name, strlen(name));
+ fz_try(ctx)
+ dest = pdf_lookup_dest(ctx, doc, needle);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, needle);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+
+ ld = pdf_parse_link_dest(ctx, doc, FZ_LINK_GOTO, dest);
+ return ld.ld.gotor.page;
+}
+
static pdf_obj *
pdf_lookup_inherited_page_item(fz_context *ctx, pdf_document *doc, pdf_obj *node, pdf_obj *key)
{