diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2017-09-20 13:03:47 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2017-09-20 14:07:51 +0200 |
commit | 4fc7d4abdada5efc25fe0976dfe6bc8324905140 (patch) | |
tree | 60203f163e488d36f5eb8672df8dc762281af24a | |
parent | bff6d163a94386eae21540183b130be6c04f08e9 (diff) | |
download | mupdf-4fc7d4abdada5efc25fe0976dfe6bc8324905140.tar.xz |
gl: Scroll to link coordinates when following links.
Also save link coordinates in outline nodes.
-rw-r--r-- | include/mupdf/fitz/outline.h | 1 | ||||
-rw-r--r-- | platform/gl/gl-main.c | 20 | ||||
-rw-r--r-- | source/html/epub-doc.c | 2 | ||||
-rw-r--r-- | source/pdf/pdf-outline.c | 2 |
4 files changed, 20 insertions, 5 deletions
diff --git a/include/mupdf/fitz/outline.h b/include/mupdf/fitz/outline.h index af68304b..85ce2f22 100644 --- a/include/mupdf/fitz/outline.h +++ b/include/mupdf/fitz/outline.h @@ -36,6 +36,7 @@ struct fz_outline_s char *title; char *uri; int page; + float x, y; fz_outline *next; fz_outline *down; int is_open; diff --git a/platform/gl/gl-main.c b/platform/gl/gl-main.c index de67b598..ac015a2d 100644 --- a/platform/gl/gl-main.c +++ b/platform/gl/gl-main.c @@ -346,6 +346,19 @@ static void jump_to_page(int newpage) push_history(); } +static void jump_to_page_xy(int newpage, float x, float y) +{ + fz_point p = { x, y }; + newpage = fz_clampi(newpage, 0, fz_count_pages(ctx, doc) - 1); + fz_transform_point(&p, &page_ctm); + clear_future(); + push_history(); + currentpage = newpage; + scroll_x = p.x; + scroll_y = p.y; + push_history(); +} + static void pop_history(void) { int here = currentpage; @@ -489,7 +502,7 @@ static int do_outline_imp(fz_outline *node, int end, int x0, int x1, int x, int if (!ui.active && ui.down) { ui.active = node; - jump_to_page(p); + jump_to_page_xy(p, node->x, node->y); ui_needs_update = 1; /* we changed the current page, so force a redraw */ } } @@ -565,6 +578,7 @@ static void do_links(fz_link *link, int xofs, int yofs) { fz_rect r; float x, y; + float link_x, link_y; x = ui.x; y = ui.y; @@ -606,9 +620,9 @@ static void do_links(fz_link *link, int xofs, int yofs) open_browser(link->uri); else { - int p = fz_resolve_link(ctx, doc, link->uri, NULL, NULL); + int p = fz_resolve_link(ctx, doc, link->uri, &link_x, &link_y); if (p >= 0) - jump_to_page(p); + jump_to_page_xy(p, link_x, link_y); else fz_warn(ctx, "cannot find link destination '%s'", link->uri); ui_needs_update = 1; diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c index 53976f78..41b21361 100644 --- a/source/html/epub-doc.c +++ b/source/html/epub-doc.c @@ -75,7 +75,7 @@ epub_update_outline(fz_context *ctx, fz_document *doc, fz_outline *node) { while (node) { - node->page = epub_resolve_link(ctx, doc, node->uri, NULL, NULL); + node->page = epub_resolve_link(ctx, doc, node->uri, &node->x, &node->y); epub_update_outline(ctx, doc, node->down); node = node->next; } diff --git a/source/pdf/pdf-outline.c b/source/pdf/pdf-outline.c index 2d184dd4..cfbd1961 100644 --- a/source/pdf/pdf-outline.c +++ b/source/pdf/pdf-outline.c @@ -34,7 +34,7 @@ pdf_load_outline_imp(fz_context *ctx, pdf_document *doc, pdf_obj *dict) node->uri = NULL; if (node->uri) - node->page = pdf_resolve_link(ctx, doc, node->uri, NULL, NULL); + node->page = pdf_resolve_link(ctx, doc, node->uri, &node->x, &node->y); else node->page = -1; |