summaryrefslogtreecommitdiff
path: root/source/fitz/link.c
blob: 152d48eaeca2c93b593ba091871437dbfdaac3a3 (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
59
60
61
62
63
64
65
#include "mupdf/fitz.h"

void
fz_drop_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, const fz_rect *bbox, fz_link_dest dest)
{
	fz_link *link;

	fz_try(ctx)
	{
		link = fz_malloc_struct(ctx, fz_link);
		link->refs = 1;
	}
	fz_catch(ctx)
	{
		fz_drop_link_dest(ctx, &dest);
		fz_rethrow(ctx);
	}
	link->dest = dest;
	link->rect = *bbox;
	link->next = NULL;
	return link;
}

fz_link *
fz_keep_link(fz_context *ctx, fz_link *link)
{
	if (link)
		link->refs++;
	return link;
}

void
fz_drop_link(fz_context *ctx, fz_link *link)
{
	while (link && --link->refs == 0)
	{
		fz_link *next = link->next;
		fz_drop_link_dest(ctx, &link->dest);
		fz_free(ctx, link);
		link = next;
	}
}