From 2216f9402a9ddf232e15fdd508b9123011af8bd3 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 14 Nov 2016 13:03:07 +0100 Subject: Add/fix page coordinates to link targets. Correctly transformed target coordinates for PDF. Target coordinates for EPUB and HTML. --- source/html/epub-doc.c | 10 +++++++--- source/html/html-doc.c | 9 ++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'source/html') diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c index a30fbcd3..f5f3ca67 100644 --- a/source/html/epub-doc.c +++ b/source/html/epub-doc.c @@ -35,7 +35,7 @@ struct epub_page_s }; static int -epub_resolve_link(fz_context *ctx, fz_document *doc_, const char *dest) +epub_resolve_link(fz_context *ctx, fz_document *doc_, const char *dest, float *xp, float *yp) { epub_document *doc = (epub_document*)doc_; epub_chapter *ch; @@ -54,7 +54,11 @@ epub_resolve_link(fz_context *ctx, fz_document *doc_, const char *dest) /* Search for a matching fragment */ float y = fz_find_html_target(ctx, ch->html, s+1); if (y >= 0) - return ch->start + y / ch->page_h; + { + int page = y / ch->page_h; + if (yp) *yp = y - page * ch->page_h; + return ch->start + page; + } } return ch->start; } @@ -68,7 +72,7 @@ epub_update_outline(fz_context *ctx, fz_document *doc, fz_outline *node) { while (node) { - node->page = epub_resolve_link(ctx, doc, node->uri); + node->page = epub_resolve_link(ctx, doc, node->uri, NULL, NULL); epub_update_outline(ctx, doc, node->down); node = node->next; } diff --git a/source/html/html-doc.c b/source/html/html-doc.c index 810b92c1..8d602030 100644 --- a/source/html/html-doc.c +++ b/source/html/html-doc.c @@ -32,16 +32,19 @@ htdoc_drop_document(fz_context *ctx, fz_document *doc_) } static int -htdoc_resolve_link(fz_context *ctx, fz_document *doc_, const char *dest) +htdoc_resolve_link(fz_context *ctx, fz_document *doc_, const char *dest, float *xp, float *yp) { html_document *doc = (html_document*)doc_; - const char *s = strchr(dest, '#'); if (s && s[1] != 0) { float y = fz_find_html_target(ctx, doc->html, s+1); if (y >= 0) - return y / doc->page_h; + { + int page = y / doc->page_h; + if (yp) *yp = y - page * doc->page_h; + return page; + } } return -1; -- cgit v1.2.3