summaryrefslogtreecommitdiff
path: root/fitz/base_link.c
blob: cf173b7a3ef0df549c9c5165966b36d00eae3fc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "fitz.h"

void
fz_free_link_dest(fz_context *ctx, fz_link_dest *dest)
{
	switch(dest->kind)
	{
	case FZ_LINK_NONE:
	case FZ_LINK_GOTO:
		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, fz_rect bbox, fz_link_dest dest)
{
	fz_link *link;

	fz_try(ctx)
	{
		link = fz_malloc_struct(ctx, fz_link);
	}
	fz_catch(ctx)
	{
		fz_free_link_dest(ctx, &dest);
		fz_rethrow(ctx);
	}
	link->dest = dest;
	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;
		fz_free_link_dest(ctx, &link->dest);
		fz_free(ctx, link);
		link = next;
	}
}