summaryrefslogtreecommitdiff
path: root/source/fitz/link.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-10-17 17:13:32 +0200
committerTor Andersson <tor.andersson@artifex.com>2016-10-28 16:18:38 +0200
commit8a07b7fb14f11204a0d840792ab9f4bd54b066e5 (patch)
treee617a898c17aeb353f35d7b362ca2de290cf2b82 /source/fitz/link.c
parent4029b45e494634361a4205f8896ec429d11e990a (diff)
downloadmupdf-8a07b7fb14f11204a0d840792ab9f4bd54b066e5.tar.xz
Clean up link destination handling.
All link destinations should be URIs, and a document specific function can be called to resolve them to actual page numbers. Outlines have cached page numbers as well as string URIs.
Diffstat (limited to 'source/fitz/link.c')
-rw-r--r--source/fitz/link.c58
1 files changed, 20 insertions, 38 deletions
diff --git a/source/fitz/link.c b/source/fitz/link.c
index eaed1402..430c9bfe 100644
--- a/source/fitz/link.c
+++ b/source/fitz/link.c
@@ -1,51 +1,25 @@
#include "mupdf/fitz.h"
-void
-fz_drop_link_dest(fz_context *ctx, fz_link_dest *dest)
-{
- if (!dest)
- return;
-
- switch (dest->kind)
- {
- case FZ_LINK_NONE:
- break;
- case FZ_LINK_GOTO:
- fz_free(ctx, dest->ld.gotor.dest);
- break;
- case FZ_LINK_URI:
- fz_free(ctx, dest->ld.uri.uri);
- break;
- case FZ_LINK_LAUNCH:
- fz_free(ctx, dest->ld.launch.file_spec);
- break;
- case FZ_LINK_NAMED:
- fz_free(ctx, dest->ld.named.named);
- break;
- case FZ_LINK_GOTOR:
- fz_free(ctx, dest->ld.gotor.file_spec);
- break;
- }
-}
-
fz_link *
-fz_new_link(fz_context *ctx, const fz_rect *bbox, fz_link_dest dest)
+fz_new_link(fz_context *ctx, const fz_rect *bbox, void *doc, const char *uri)
{
fz_link *link;
+ link = fz_malloc_struct(ctx, fz_link);
+ link->refs = 1;
+ link->rect = *bbox;
+ link->next = NULL;
+ link->doc = doc; /* don't take reference */
+ link->uri = NULL;
+
fz_try(ctx)
- {
- link = fz_malloc_struct(ctx, fz_link);
- link->refs = 1;
- }
+ link->uri = fz_strdup(ctx, uri);
fz_catch(ctx)
{
- fz_drop_link_dest(ctx, &dest);
+ fz_drop_link(ctx, link);
fz_rethrow(ctx);
}
- link->dest = dest;
- link->rect = *bbox;
- link->next = NULL;
+
return link;
}
@@ -61,8 +35,16 @@ fz_drop_link(fz_context *ctx, fz_link *link)
while (fz_drop_imp(ctx, link, &link->refs))
{
fz_link *next = link->next;
- fz_drop_link_dest(ctx, &link->dest);
+ fz_free(ctx, link->uri);
fz_free(ctx, link);
link = next;
}
}
+
+int
+fz_is_external_link(fz_context *ctx, const char *uri)
+{
+ while (*uri >= 'a' && *uri <= 'z')
+ ++uri;
+ return uri[0] == ':' && uri[1] == '/' && uri[2] == '/';
+}