summaryrefslogtreecommitdiff
path: root/source/fitz/outline.c
blob: 888212bcd094e4cbdc03ac8ec8893ca4bb8af75a (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
66
67
68
69
70
71
72
73
74
75
76
#include "mupdf/fitz.h"

fz_outline *
fz_new_outline(fz_context *ctx)
{
	fz_outline *outline = fz_malloc_struct(ctx, fz_outline);
	outline->refs = 1;
	return outline;
}

fz_outline *
fz_keep_outline(fz_context *ctx, fz_outline *outline)
{
	return fz_keep_imp(ctx, outline, &outline->refs);
}

void
fz_drop_outline(fz_context *ctx, fz_outline *outline)
{
	while (fz_drop_imp(ctx, outline, &outline->refs))
	{
		fz_outline *next = outline->next;
		fz_drop_outline(ctx, outline->down);
		fz_free(ctx, outline->title);
		fz_free(ctx, outline->uri);
		fz_free(ctx, outline);
		outline = next;
	}
}

static void
fz_debug_outline_xml_imp(fz_context *ctx, fz_output *out, fz_outline *outline, int level)
{
	while (outline)
	{
		fz_printf(ctx, out, "<outline title=%q uri=\"%s\"", outline->title, outline->uri);
		if (outline->down)
		{
			fz_printf(ctx, out, ">\n");
			fz_debug_outline_xml_imp(ctx, out, outline->down, level + 1);
			fz_printf(ctx, out, "</outline>\n");
		}
		else
		{
			fz_printf(ctx, out, " />\n");
		}
		outline = outline->next;
	}
}

void
fz_print_outline_xml(fz_context *ctx, fz_output *out, fz_outline *outline)
{
	fz_debug_outline_xml_imp(ctx, out, outline, 0);
}

static void
fz_print_outline_imp(fz_context *ctx, fz_output *out, fz_outline *outline, int level)
{
	int i;
	while (outline)
	{
		for (i = 0; i < level; i++)
			fz_printf(ctx, out, "\t");
		fz_printf(ctx, out, "%s\t%s\n", outline->title, outline->uri);
		if (outline->down)
			fz_print_outline_imp(ctx, out, outline->down, level + 1);
		outline = outline->next;
	}
}

void
fz_print_outline(fz_context *ctx, fz_output *out, fz_outline *outline)
{
	fz_print_outline_imp(ctx, out, outline, 0);
}