From 48afdad75f42b1eb165e87ffd69ae1195ada9350 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 7 Jan 2016 14:21:23 +0100 Subject: pdf: Add function to look up the page for a named destination. --- include/mupdf/pdf/page.h | 8 ++++++++ source/pdf/pdf-page.c | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) 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 @@ -5,6 +5,14 @@ int pdf_lookup_page_number(fz_context *ctx, pdf_document *doc, pdf_obj *pageobj) 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. 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) { -- cgit v1.2.3