summaryrefslogtreecommitdiff
path: root/source/html/epub-doc.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-10-20 14:07:21 +0200
committerTor Andersson <tor.andersson@artifex.com>2016-10-28 16:18:39 +0200
commitcc3bbe49ce3fa0c99dafd4d762b8da0ecd281ff2 (patch)
tree71637e49c05fd145e39636bb44605e8bbc062cde /source/html/epub-doc.c
parent8a07b7fb14f11204a0d840792ab9f4bd54b066e5 (diff)
downloadmupdf-cc3bbe49ce3fa0c99dafd4d762b8da0ecd281ff2.tar.xz
epub: Add 'id' attribute to all HTML elements, not just <a> tags.
Allows id anchoring to block elements as well as inline elements. Fix for bug 697123.
Diffstat (limited to 'source/html/epub-doc.c')
-rw-r--r--source/html/epub-doc.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c
index 0616bb70..f9d9e6aa 100644
--- a/source/html/epub-doc.c
+++ b/source/html/epub-doc.c
@@ -35,32 +35,40 @@ struct epub_page_s
};
static int
-find_anchor_flow(fz_html_flow *flow, const char *anchor, float page_h, int *page)
+find_anchor_flow(fz_html_flow *flow, const char *anchor, float page_h)
{
while (flow)
{
- if (flow->type == FLOW_ANCHOR && !strcmp(anchor, flow->content.text))
- {
- *page += (int)(flow->y / page_h);
- return 1;
- }
+ if (flow->box->id && !strcmp(anchor, flow->box->id))
+ return flow->y / page_h;
flow = flow->next;
}
- return 0;
+ return -1;
}
static int
-find_anchor_box(fz_html_box *box, const char *anchor, float page_h, int *page)
+find_anchor_box(fz_html_box *box, const char *anchor, float page_h)
{
+ int page;
while (box)
{
- if (box->flow_head && find_anchor_flow(box->flow_head, anchor, page_h, page))
- return 1;
- if (box->down && find_anchor_box(box->down, anchor, page_h, page))
- return 1;
+ if (box->id && !strcmp(anchor, box->id))
+ return box->y / page_h;
+ if (box->type == BOX_FLOW)
+ {
+ page = find_anchor_flow(box->flow_head, anchor, page_h);
+ if (page >= 0)
+ return page;
+ }
+ else
+ {
+ page = find_anchor_box(box->down, anchor, page_h);
+ if (page >= 0)
+ return page;
+ }
box = box->next;
}
- return 0;
+ return -1;
}
static int
@@ -79,16 +87,18 @@ epub_resolve_link(fz_context *ctx, fz_document *doc_, const char *dest)
{
if (!strncmp(ch->path, dest, n) && ch->path[n] == 0)
{
- page = ch->start;
if (s)
{
/* Search for a matching fragment */
- find_anchor_box(ch->html->root, s+1, ch->page_h, &page);
+ page = find_anchor_box(ch->html->root, s+1, ch->page_h);
+ if (page >= 0)
+ return ch->start + page;
}
+ return ch->start;
}
}
- return page;
+ return -1;
}
static void