summaryrefslogtreecommitdiff
path: root/fitz/base_link.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2011-12-23 12:59:24 +0000
committerRobin Watts <robin.watts@artifex.com>2011-12-23 13:18:42 +0000
commit73e548cdd564c6c2099ceafaa4019a7dbb188a30 (patch)
treee2d0b498abf0f0057d7d565d6b465226e6491d60 /fitz/base_link.c
parentcc4dd0f8358d3de1594cc530b8f2691bccf194f0 (diff)
downloadmupdf-73e548cdd564c6c2099ceafaa4019a7dbb188a30.tar.xz
Generalise pdf_links to be fz_links.
Move to a non-pdf specific type for links. PDF specific parsing is done in pdf_annots.c as before, but the essential type (and handling functions for that type) are in a new file fitz/base_link.c. The new type is more expressive than before; specifically all the possible PDF modes are expressable in it. Hopefully this should allow XPS links to be represented too.
Diffstat (limited to 'fitz/base_link.c')
-rw-r--r--fitz/base_link.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/fitz/base_link.c b/fitz/base_link.c
new file mode 100644
index 00000000..d8d7e3ab
--- /dev/null
+++ b/fitz/base_link.c
@@ -0,0 +1,57 @@
+#include "fitz.h"
+
+static void
+free_link_dest(fz_context *ctx, fz_link_kind kind, fz_link_dest *dest)
+{
+ switch(kind)
+ {
+ case FZ_LINK_GOTO:
+ break;
+ case FZ_LINK_URI:
+ fz_free(ctx, dest->uri.uri);
+ break;
+ case FZ_LINK_LAUNCH:
+ fz_free(ctx, dest->launch.file_spec);
+ break;
+ case FZ_LINK_NAMED:
+ fz_free(ctx, dest->named.named);
+ break;
+ case FZ_LINK_GOTOR:
+ fz_free(ctx, dest->gotor.file_spec);
+ break;
+ }
+}
+
+fz_link *
+fz_new_link(fz_context *ctx, fz_link_kind kind, fz_rect bbox, fz_link_dest dest)
+{
+ fz_link *link;
+
+ fz_try(ctx)
+ {
+ link = fz_malloc_struct(ctx, fz_link);
+ }
+ fz_catch(ctx)
+ {
+ free_link_dest(ctx, kind, &dest);
+ fz_rethrow(ctx);
+ }
+ link->kind = kind;
+ link->rect = bbox;
+ link->next = NULL;
+ return link;
+}
+
+void
+fz_free_link(fz_context *ctx, fz_link *link)
+{
+ fz_link *next;
+
+ while (link)
+ {
+ next = link->next;
+ free_link_dest(ctx, link->kind, &link->dest);
+ fz_free(ctx, link);
+ link = next;
+ }
+}