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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#include "fitz.h"
#include "mupdf.h"
/*
* Enable logging by setting environment variable MULOG to:
* (a)ll or a combination of
* (x)ref (r)src (f)ont (i)mage (s)hade (p)age
*
* eg. MULOG=fis ./x11pdf mytestfile.pdf
*/
enum
{
PDF_LXREF = 1,
PDF_LRSRC = 2,
PDF_LFONT = 4,
PDF_LIMAGE = 8,
PDF_LSHADE = 16,
PDF_LPAGE = 32
};
static inline void pdflog(int tag, char *name, char *fmt, va_list ap)
{
static int flags = 128;
static int level = 0;
static int push = 1;
int i;
if (flags == 128)
{
char *s = getenv("MULOG");
flags = 0;
if (s)
{
if (strstr(s, "a"))
flags |= 0xffff;
if (strstr(s, "x"))
flags |= PDF_LXREF;
if (strstr(s, "r"))
flags |= PDF_LRSRC;
if (strstr(s, "f"))
flags |= PDF_LFONT;
if (strstr(s, "i"))
flags |= PDF_LIMAGE;
if (strstr(s, "s"))
flags |= PDF_LSHADE;
if (strstr(s, "p"))
flags |= PDF_LPAGE;
}
}
if (!(flags & tag))
return;
if (strchr(fmt, '}'))
level --;
if (push)
{
printf("%s: ", name);
for (i = 0; i < level; i++)
printf("\t");
}
vprintf(fmt, ap);
if (strchr(fmt, '{'))
level ++;
push = !!strchr(fmt, '\n');
fflush(stdout);
}
void pdf_log_xref(char *fmt, ...)
{va_list ap;va_start(ap,fmt);pdflog(PDF_LXREF,"xref",fmt,ap);va_end(ap);}
void pdf_log_rsrc(char *fmt, ...)
{va_list ap;va_start(ap,fmt);pdflog(PDF_LRSRC,"rsrc",fmt,ap);va_end(ap);}
void pdf_log_font(char *fmt, ...)
{va_list ap;va_start(ap,fmt);pdflog(PDF_LFONT,"font",fmt,ap);va_end(ap);}
void pdf_log_image(char *fmt, ...)
{va_list ap;va_start(ap,fmt);pdflog(PDF_LIMAGE,"imag",fmt,ap);va_end(ap);}
void pdf_log_shade(char *fmt, ...)
{va_list ap;va_start(ap,fmt);pdflog(PDF_LSHADE,"shad",fmt,ap);va_end(ap);}
void pdf_log_page(char *fmt, ...)
{va_list ap;va_start(ap,fmt);pdflog(PDF_LPAGE,"page",fmt,ap);va_end(ap);}
|