summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Jamfile1
-rw-r--r--TODO1
-rw-r--r--include/mupdf.h7
-rw-r--r--mupdf/cmap.c14
-rw-r--r--mupdf/colorspace1.c28
-rw-r--r--mupdf/debug.c90
-rw-r--r--mupdf/doctor.c14
-rw-r--r--mupdf/font.c53
-rw-r--r--mupdf/fontfile.c12
-rw-r--r--mupdf/fontfilefc.c17
-rw-r--r--mupdf/image.c35
-rw-r--r--mupdf/open.c19
-rw-r--r--mupdf/page.c15
-rw-r--r--mupdf/pagetree.c34
-rw-r--r--mupdf/pattern.c26
-rw-r--r--mupdf/repair.c9
-rw-r--r--mupdf/resources.c37
-rw-r--r--mupdf/save.c8
-rw-r--r--mupdf/type3.c19
-rw-r--r--mupdf/unicode.c10
-rw-r--r--mupdf/xobject.c15
-rw-r--r--mupdf/xref.c23
22 files changed, 438 insertions, 49 deletions
diff --git a/Jamfile b/Jamfile
index 30074d0f..a8c24719 100644
--- a/Jamfile
+++ b/Jamfile
@@ -102,6 +102,7 @@ Library libfitz :
;
Library libmupdf :
+ mupdf/debug.c
mupdf/lex.c
mupdf/parse.c
mupdf/crypt.c
diff --git a/TODO b/TODO
index 4e77b437..6722d6f9 100644
--- a/TODO
+++ b/TODO
@@ -38,6 +38,7 @@ rendering
- font focus
parser
+ - stick objects automatically into xref resource cache, not in preloadres
- try to clean up colorspace/material handling in interpreter
- annotations and destinations (for links and outline)
diff --git a/include/mupdf.h b/include/mupdf.h
index a1633541..5ee5fe91 100644
--- a/include/mupdf.h
+++ b/include/mupdf.h
@@ -7,6 +7,13 @@
#error "fitz.h must be included before mupdf.h"
#endif
+void pdf_logxref(char *fmt, ...);
+void pdf_logrsrc(char *fmt, ...);
+void pdf_logfont(char *fmt, ...);
+void pdf_logimage(char *fmt, ...);
+void pdf_logshade(char *fmt, ...);
+void pdf_logpage(char *fmt, ...);
+
#include "mupdf/syntax.h"
#include "mupdf/xref.h"
#include "mupdf/rsrc.h"
diff --git a/mupdf/cmap.c b/mupdf/cmap.c
index 84dd386e..55ae0e2b 100644
--- a/mupdf/cmap.c
+++ b/mupdf/cmap.c
@@ -382,6 +382,8 @@ pdf_loadembeddedcmap(fz_cmap **cmapp, pdf_xref *xref, fz_obj *stmref)
fz_obj *wmode;
fz_obj *obj;
+ pdf_logfont("load embedded cmap %d %d {\n", fz_tonum(stmref), fz_togen(stmref));
+
error = pdf_resolve(&stmobj, xref);
if (error)
return error;
@@ -398,11 +400,15 @@ pdf_loadembeddedcmap(fz_cmap **cmapp, pdf_xref *xref, fz_obj *stmref)
wmode = fz_dictgets(stmobj, "WMode");
if (fz_isint(wmode))
+ {
+ pdf_logfont("wmode %d\n", wmode);
fz_setwmode(cmap, fz_toint(wmode));
+ }
obj = fz_dictgets(stmobj, "UseCMap");
if (fz_isname(obj))
{
+ pdf_logfont("usecmap /%s\n", fz_toname(obj));
error = pdf_loadsystemcmap(&usecmap, fz_toname(obj));
if (error)
goto cleanup;
@@ -411,6 +417,7 @@ pdf_loadembeddedcmap(fz_cmap **cmapp, pdf_xref *xref, fz_obj *stmref)
}
else if (fz_isindirect(obj))
{
+ pdf_logfont("usecmap %d %d R\n", fz_tonum(obj), fz_togen(obj));
error = pdf_loadembeddedcmap(&usecmap, xref, obj);
if (error)
goto cleanup;
@@ -420,6 +427,8 @@ pdf_loadembeddedcmap(fz_cmap **cmapp, pdf_xref *xref, fz_obj *stmref)
fz_dropobj(stmobj);
+ pdf_logfont("}\n");
+
*cmapp = cmap;
return nil;
@@ -444,6 +453,8 @@ pdf_loadsystemcmap(fz_cmap **cmapp, char *name)
fz_cmap *cmap;
char path[1024];
+ pdf_logfont("load system cmap %s {\n", name);
+
cmapdir = getenv("CMAPDIR");
if (!cmapdir)
return fz_throw("ioerror: CMAPDIR environment not set");
@@ -465,6 +476,7 @@ pdf_loadsystemcmap(fz_cmap **cmapp, char *name)
usecmapname = fz_getusecmapname(cmap);
if (usecmapname)
{
+ pdf_logfont("usecmap %s\n", usecmapname);
error = pdf_loadsystemcmap(&usecmap, usecmapname);
if (error)
goto cleanup;
@@ -472,6 +484,8 @@ pdf_loadsystemcmap(fz_cmap **cmapp, char *name)
fz_dropcmap(usecmap);
}
+ pdf_logfont("}\n");
+
*cmapp = cmap;
return nil;
diff --git a/mupdf/colorspace1.c b/mupdf/colorspace1.c
index 08569cc4..dcd6dc1f 100644
--- a/mupdf/colorspace1.c
+++ b/mupdf/colorspace1.c
@@ -234,6 +234,8 @@ loadcalgray(fz_colorspace **csp, pdf_xref *xref, fz_obj *dict)
if (!cs)
return fz_outofmem;
+ pdf_logrsrc("load CalGray\n");
+
initcs((fz_colorspace*)cs, "CalGray", 1, graytoxyz, xyztogray, nil);
cs->white[0] = 1.0;
@@ -281,6 +283,8 @@ loadcalrgb(fz_colorspace **csp, pdf_xref *xref, fz_obj *dict)
if (!cs)
return fz_outofmem;
+ pdf_logrsrc("load CalRGB\n");
+
initcs((fz_colorspace*)cs, "CalRGB", 3, rgbtoxyz, xyztorgb, nil);
cs->white[0] = 1.0;
@@ -346,6 +350,8 @@ loadlab(fz_colorspace **csp, pdf_xref *xref, fz_obj *dict)
if (!cs)
return fz_outofmem;
+ pdf_logrsrc("load Lab\n");
+
initcs((fz_colorspace*)cs, "Lab", 3, labtoxyz, xyztolab, nil);
cs->white[0] = 1.0;
@@ -403,6 +409,8 @@ loadiccbased(fz_colorspace **csp, pdf_xref *xref, fz_obj *ref)
fz_obj *dict;
int n;
+ pdf_logrsrc("load ICCBased\n");
+
error = pdf_loadindirect(&dict, xref, ref);
if (error)
return error;
@@ -472,11 +480,15 @@ loadseparation(fz_colorspace **csp, pdf_xref *xref, fz_obj *array)
pdf_function *tint;
int n;
+ pdf_logrsrc("load Separation {\n");
+
if (fz_isarray(nameobj))
n = fz_arraylen(nameobj);
else
n = 1;
+ pdf_logrsrc("n = %d\n", n);
+
error = pdf_resolve(&baseobj, xref);
if (error)
return error;
@@ -507,6 +519,8 @@ loadseparation(fz_colorspace **csp, pdf_xref *xref, fz_obj *array)
cs->base = base;
cs->tint = tint;
+ pdf_logrsrc("}\n");
+
*csp = (fz_colorspace*)cs;
return nil;
}
@@ -549,6 +563,8 @@ loadindexed(fz_colorspace **csp, pdf_xref *xref, fz_obj *array)
fz_colorspace *base;
int n;
+ pdf_logrsrc("load Indexed {\n");
+
error = pdf_resolve(&baseobj, xref);
if (error)
return error;
@@ -557,6 +573,8 @@ loadindexed(fz_colorspace **csp, pdf_xref *xref, fz_obj *array)
if (error)
return error;
+ pdf_logrsrc("base %s\n", base->name);
+
cs = fz_malloc(sizeof(pdf_indexed));
if (!cs)
{
@@ -580,8 +598,12 @@ loadindexed(fz_colorspace **csp, pdf_xref *xref, fz_obj *array)
if (fz_isstring(lookup) && fz_tostringlen(lookup) == n)
{
- unsigned char *buf = fz_tostringbuf(lookup);
+ unsigned char *buf;
int i;
+
+ pdf_logrsrc("string lookup\n");
+
+ buf = fz_tostringbuf(lookup);
for (i = 0; i < n; i++)
cs->lookup[i] = buf[i];
}
@@ -591,6 +613,8 @@ loadindexed(fz_colorspace **csp, pdf_xref *xref, fz_obj *array)
fz_buffer *buf;
int i;
+ pdf_logrsrc("stream lookup\n");
+
error = pdf_loadstream(&buf, xref, fz_tonum(lookup), fz_togen(lookup));
if (error)
{
@@ -604,6 +628,8 @@ loadindexed(fz_colorspace **csp, pdf_xref *xref, fz_obj *array)
fz_dropbuffer(buf);
}
+ pdf_logrsrc("}\n");
+
*csp = (fz_colorspace*)cs;
return nil;
}
diff --git a/mupdf/debug.c b/mupdf/debug.c
new file mode 100644
index 00000000..3a300e6a
--- /dev/null
+++ b/mupdf/debug.c
@@ -0,0 +1,90 @@
+#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 log(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(" ");
+ }
+
+ vprintf(fmt, ap);
+
+ if (strchr(fmt, '{'))
+ level ++;
+
+ push = strchr(fmt, '\n') != 0;
+}
+
+void pdf_logxref(char *fmt, ...)
+{va_list ap;va_start(ap,fmt);log(PDF_LXREF,"xref",fmt,ap);va_end(ap);}
+
+void pdf_logrsrc(char *fmt, ...)
+{va_list ap;va_start(ap,fmt);log(PDF_LRSRC,"rsrc",fmt,ap);va_end(ap);}
+
+void pdf_logfont(char *fmt, ...)
+{va_list ap;va_start(ap,fmt);log(PDF_LFONT,"font",fmt,ap);va_end(ap);}
+
+void pdf_logimage(char *fmt, ...)
+{va_list ap;va_start(ap,fmt);log(PDF_LIMAGE,"imag",fmt,ap);va_end(ap);}
+
+void pdf_logshade(char *fmt, ...)
+{va_list ap;va_start(ap,fmt);log(PDF_LSHADE,"shad",fmt,ap);va_end(ap);}
+
+void pdf_logpage(char *fmt, ...)
+{va_list ap;va_start(ap,fmt);log(PDF_LPAGE,"page",fmt,ap);va_end(ap);}
+
diff --git a/mupdf/doctor.c b/mupdf/doctor.c
index ed50b768..be683592 100644
--- a/mupdf/doctor.c
+++ b/mupdf/doctor.c
@@ -82,6 +82,8 @@ pdf_garbagecollect(pdf_xref *xref)
fz_error *error;
int i, g;
+ pdf_logxref("garbage collect {\n");
+
for (i = 0; i < xref->len; i++)
xref->table[i].mark = 0;
@@ -99,6 +101,8 @@ pdf_garbagecollect(pdf_xref *xref)
pdf_deleteobject(xref, i, g);
}
+ pdf_logxref("}\n");
+
return nil;
}
@@ -191,6 +195,8 @@ pdf_transplant(pdf_xref *dst, pdf_xref *src, fz_obj **newp, fz_obj *root)
fz_buffer *stm;
int i, n;
+ pdf_logxref("transplant {\n");
+
for (i = 0; i < src->len; i++)
src->table[i].mark = 0;
@@ -202,6 +208,8 @@ pdf_transplant(pdf_xref *dst, pdf_xref *src, fz_obj **newp, fz_obj *root)
if (src->table[i].mark)
n++;
+ pdf_logxref("marked %d\n", n);
+
map = fz_malloc(sizeof(struct pair) * n);
if (!map)
return fz_outofmem;
@@ -227,6 +235,10 @@ pdf_transplant(pdf_xref *dst, pdf_xref *src, fz_obj **newp, fz_obj *root)
for (i = 0; i < n; i++)
{
+ pdf_logxref("copyfrom %d %d to %d %d\n",
+ map[i].soid, map[i].sgen,
+ map[i].doid, map[i].dgen);
+
error = pdf_loadobject(&old, src, map[i].soid, map[i].sgen);
if (error)
goto cleanup;
@@ -249,6 +261,8 @@ pdf_transplant(pdf_xref *dst, pdf_xref *src, fz_obj **newp, fz_obj *root)
fz_dropobj(new);
}
+ pdf_logxref("}\n");
+
fz_free(map);
return nil;
diff --git a/mupdf/font.c b/mupdf/font.c
index 4cf29b89..e3a494b1 100644
--- a/mupdf/font.c
+++ b/mupdf/font.c
@@ -46,6 +46,7 @@ enum { UNKNOWN, TYPE1, CFF, TRUETYPE, CID };
static int ftkind(FT_Face face)
{
const char *kind = face->driver->clazz->root.module_name;
+ pdf_logfont("ft driver %s\n", kind);
if (!strcmp(kind, "type1"))
return TYPE1;
if (!strcmp(kind, "cff"))
@@ -308,10 +309,14 @@ loadsimplefont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict)
* Load font file
*/
- font = *fontp = pdf_newfont(fontname);
+ font = pdf_newfont(fontname);
if (!font)
return fz_outofmem;
+ pdf_logfont("load simple font %p {\n", font);
+ pdf_logfont("basefont0 %s\n", basefont);
+ pdf_logfont("basefont1 %s\n", fontname);
+
descriptor = fz_dictgets(dict, "FontDescriptor");
if (descriptor && basefont == fontname)
error = pdf_loadfontdescriptor(font, xref, descriptor, nil);
@@ -323,7 +328,11 @@ loadsimplefont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict)
face = font->ftface;
kind = ftkind(face);
- symbolic = font->flags & 4;
+ pdf_logfont("ft name '%s' '%s'\n", face->family_name, face->style_name);
+
+ pdf_logfont("ft bbox [%d %d %d %d]\n",
+ face->bbox.xMin, face->bbox.yMin,
+ face->bbox.xMax, face->bbox.yMax);
if (face->bbox.xMax == face->bbox.xMin)
fz_setfontbbox((fz_font*)font, -1000, -1000, 2000, 2000);
@@ -336,6 +345,8 @@ loadsimplefont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict)
* Encoding
*/
+ symbolic = font->flags & 4;
+
if (face->num_charmaps > 0)
cmap = face->charmaps[0];
else
@@ -420,6 +431,7 @@ loadsimplefont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict)
if (kind == TYPE1 || kind == CFF)
{
+ pdf_logfont("encode type1/cff by strings\n");
for (i = 0; i < 256; i++)
if (estrings[i])
etable[i] = FT_Get_Name_Index(face, estrings[i]);
@@ -432,6 +444,7 @@ loadsimplefont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict)
/* Unicode cmap */
if (face->charmap->platform_id == 3)
{
+ pdf_logfont("encode truetype via unicode\n");
for (i = 0; i < 256; i++)
if (estrings[i])
{
@@ -448,6 +461,7 @@ loadsimplefont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict)
/* MacRoman cmap */
else if (face->charmap->platform_id == 1)
{
+ pdf_logfont("encode truetype via macroman\n");
for (i = 0; i < 256; i++)
if (estrings[i])
{
@@ -464,6 +478,7 @@ loadsimplefont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict)
/* Symbolic cmap */
else
{
+ pdf_logfont("encode truetype symbolic\n");
for (i = 0; i < 256; i++)
etable[i] = FT_Get_Char_Index(face, i);
}
@@ -474,6 +489,7 @@ loadsimplefont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict)
else
{
+ pdf_logfont("encode builtin\n");
for (i = 0; i < 256; i++)
etable[i] = FT_Get_Char_Index(face, i);
}
@@ -536,6 +552,9 @@ loadsimplefont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict)
if (error)
goto cleanup;
+ pdf_logfont("}\n");
+
+ *fontp = font;
return nil;
cleanup:
@@ -543,7 +562,6 @@ cleanup:
if (widths)
fz_dropobj(widths);
fz_dropfont((fz_font*)font);
- *fontp = nil;
return error;
}
@@ -603,10 +621,14 @@ loadcidfont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict, fz_obj *encoding, fz
* Load font file
*/
- font = *fontp = pdf_newfont(basefont);
+ font = pdf_newfont(basefont);
if (!font)
return fz_outofmem;
+ pdf_logfont("load cid font %p {\n", font);
+ pdf_logfont("basefont %s\n", basefont);
+ pdf_logfont("collection %s\n", collection);
+
descriptor = fz_dictgets(dict, "FontDescriptor");
if (descriptor)
error = pdf_loadfontdescriptor(font, xref, descriptor, collection);
@@ -625,12 +647,17 @@ loadcidfont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict, fz_obj *encoding, fz
face->bbox.xMin, face->bbox.yMin,
face->bbox.xMax, face->bbox.yMax);
+ pdf_logfont("ft bbox [%d %d %d %d]\n",
+ face->bbox.xMin, face->bbox.yMin,
+ face->bbox.xMax, face->bbox.yMax);
+
/*
* Encoding
*/
if (fz_isname(encoding))
{
+ pdf_logfont("encoding /%s\n", fz_toname(encoding));
if (!strcmp(fz_toname(encoding), "Identity-H"))
error = pdf_makeidentitycmap(&font->encoding, 0, 2);
else if (!strcmp(fz_toname(encoding), "Identity-V"))
@@ -640,6 +667,7 @@ loadcidfont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict, fz_obj *encoding, fz
}
else if (fz_isindirect(encoding))
{
+ pdf_logfont("encoding %d %d R\n", fz_tonum(encoding), fz_togen(encoding));
error = pdf_loadembeddedcmap(&font->encoding, xref, encoding);
}
else
@@ -650,6 +678,7 @@ loadcidfont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict, fz_obj *encoding, fz
goto cleanup;
fz_setfontwmode((fz_font*)font, fz_getwmode(font->encoding));
+ pdf_logfont("wmode %d\n", fz_getwmode(font->encoding));
if (kind == TRUETYPE)
{
@@ -662,6 +691,8 @@ loadcidfont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict, fz_obj *encoding, fz
fz_buffer *buf;
int len;
+ pdf_logfont("cidtogidmap stream\n");
+
error = pdf_loadstream(&buf, xref, fz_tonum(cidtogidmap), fz_togen(cidtogidmap));
if (error)
goto cleanup;
@@ -691,6 +722,8 @@ loadcidfont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict, fz_obj *encoding, fz
{
int e;
+ pdf_logfont("emulate ttf cidfont\n");
+
e = FT_Select_Charmap(face, ft_encoding_unicode);
if (e)
return fz_throw("fonterror: no unicode cmap when emulating CID font");
@@ -832,13 +865,15 @@ loadcidfont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict, fz_obj *encoding, fz
goto cleanup;
}
+ pdf_logfont("}\n");
+
+ *fontp = font;
return nil;
cleanup:
if (widths)
fz_dropobj(widths);
fz_dropfont((fz_font*)font);
- *fontp = nil;
return error;
}
@@ -897,8 +932,12 @@ pdf_loadfontdescriptor(pdf_font *font, pdf_xref *xref, fz_obj *desc, char *colle
if (error)
return error;
+ pdf_logfont("load fontdescriptor {\n");
+
fontname = fz_toname(fz_dictgets(desc, "FontName"));
+ pdf_logfont("fontname %s\n", fontname);
+
font->flags = fz_toint(fz_dictgets(desc, "Flags"));
font->italicangle = fz_toreal(fz_dictgets(desc, "ItalicAngle"));
font->ascent = fz_toreal(fz_dictgets(desc, "Ascent"));
@@ -907,6 +946,8 @@ pdf_loadfontdescriptor(pdf_font *font, pdf_xref *xref, fz_obj *desc, char *colle
font->xheight = fz_toreal(fz_dictgets(desc, "XHeight"));
font->missingwidth = fz_toreal(fz_dictgets(desc, "MissingWidth"));
+ pdf_logfont("flags %d\n", font->flags);
+
obj1 = fz_dictgets(desc, "FontFile");
obj2 = fz_dictgets(desc, "FontFile2");
obj3 = fz_dictgets(desc, "FontFile3");
@@ -927,6 +968,8 @@ pdf_loadfontdescriptor(pdf_font *font, pdf_xref *xref, fz_obj *desc, char *colle
fz_dropobj(desc);
+ pdf_logfont("}\n");
+
return nil;
cleanup:
diff --git a/mupdf/fontfile.c b/mupdf/fontfile.c
index cdce1a86..72e0c1b5 100644
--- a/mupdf/fontfile.c
+++ b/mupdf/fontfile.c
@@ -110,6 +110,8 @@ pdf_loadbuiltinfont(pdf_font *font, char *fontname)
return fz_throw("font not found: %s", fontname);
found:
+ pdf_logfont("load builtin font %s\n", fontname);
+
loadfontdata(i, &data, &len);
e = FT_New_Memory_Face(ftlib, data, len, 0, (FT_Face*)&font->ftface);
@@ -126,7 +128,7 @@ loadcidfont(pdf_font *font, char *filename)
char *fontdir;
int e;
-printf(" load system cid font '%s'\n", filename);
+ pdf_logfont("load system font '%s'\n", filename);
fontdir = getenv("FONTDIR");
if (!fontdir)
@@ -186,11 +188,13 @@ pdf_loadsystemfont(pdf_font *font, char *fontname, char *collection)
if (font->flags & FD_FORCEBOLD)
isbold = 1;
+ pdf_logfont("fixed-%d serif-%d italic-%d script-%d bold-%d\n",
+ isfixed, isserif, isitalic, isscript, isbold);
+
if (collection)
{
char buf[256];
char *env;
-printf(" find cid font %s (%d)\n", collection, isserif);
snprintf(buf, sizeof buf, "%s_%s", strstr(collection, "-") + 1, isserif ? "S" : "G");
env = getenv(buf);
@@ -250,8 +254,6 @@ printf(" find cid font %s (%d)\n", collection, isserif);
}
}
-printf(" loading substitute font %s\n", name);
-
return pdf_loadbuiltinfont(font, name);
}
@@ -267,6 +269,8 @@ pdf_loadembeddedfont(pdf_font *font, pdf_xref *xref, fz_obj *stmref)
if (error)
return error;
+ pdf_logfont("load embedded font\n");
+
error = pdf_loadstream(&buf, xref, fz_tonum(stmref), fz_togen(stmref));
if (error)
return error;
diff --git a/mupdf/fontfilefc.c b/mupdf/fontfilefc.c
index 36368c28..e7dd0cd1 100644
--- a/mupdf/fontfilefc.c
+++ b/mupdf/fontfilefc.c
@@ -108,6 +108,8 @@ pdf_loadbuiltinfont(pdf_font *font, char *basefont)
if (!strcmp(basefont, basenames[i]))
pattern = basepatterns[i];
+ pdf_logfont("load builtin %s\n", pattern);
+
fcerr = FcResultMatch;
searchpat = FcNameParse(pattern);
FcDefaultSubstitute(searchpat);
@@ -124,7 +126,7 @@ pdf_loadbuiltinfont(pdf_font *font, char *basefont)
index = 0;
fcerr = FcPatternGetInteger(matchpat, FC_INDEX, 0, &index);
-printf(" builtin %s from %s idx %d\n", basefont, file, index);
+ pdf_logfont("load font file %s %d\n", file, index);
fterr = FT_New_Face(ftlib, file, index, &face);
if (fterr)
@@ -213,9 +215,9 @@ pdf_loadsystemfont(pdf_font *font, char *basefont, char *collection)
if (!FcPatternAddBool(searchpat, FC_OUTLINE, 1))
goto cleanup;
-file = FcNameUnparse(searchpat);
-printf(" fontconfig %s: %s\n", basefont, file);
-free(file);
+ file = FcNameUnparse(searchpat);
+ pdf_logfont("fontconfig %s\n", file);
+ free(file);
fcerr = FcResultMatch;
FcDefaultSubstitute(searchpat);
@@ -233,9 +235,6 @@ free(file);
if (file && style && strcmp(style, file))
font->substitute = 1;
-if (font->substitute)
-printf(" inexact match\n");
-
fcerr = FcPatternGetString(matchpat, FC_FILE, 0, (FcChar8**)&file);
if (fcerr != FcResultMatch)
return fz_throw("fontconfig could not find font %s", basefont);
@@ -243,7 +242,7 @@ printf(" inexact match\n");
index = 0;
fcerr = FcPatternGetInteger(matchpat, FC_INDEX, 0, &index);
-printf(" file %s idx %d\n", file, index);
+ pdf_logfont("load font file %s %d\n", file, index);
fterr = FT_New_Face(ftlib, file, index, &face);
if (fterr) {
@@ -276,6 +275,8 @@ pdf_loadembeddedfont(pdf_font *font, pdf_xref *xref, fz_obj *stmref)
if (error)
return error;
+ pdf_logfont("load embedded font\n");
+
error = pdf_loadstream(&buf, xref, fz_tonum(stmref), fz_togen(stmref));
if (error)
return error;
diff --git a/mupdf/image.c b/mupdf/image.c
index 2b4242e5..8e7ef844 100644
--- a/mupdf/image.c
+++ b/mupdf/image.c
@@ -21,10 +21,12 @@ pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict,
int ismask;
int i;
- img = *imgp = fz_malloc(sizeof(pdf_image));
+ img = fz_malloc(sizeof(pdf_image));
if (!img)
return fz_outofmem;
+ pdf_logimage("load inline image %p {\n", img);
+
img->super.loadtile = pdf_loadtile;
img->super.drop = pdf_dropimage;
img->super.n = 0;
@@ -39,8 +41,11 @@ pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict,
d = fz_dictgetsa(dict, "Decode", "D");
cs = fz_dictgetsa(dict, "ColorSpace", "CS");
+ pdf_logimage("size %dx%d %d\n", img->super.w, img->super.h, img->bpc);
+
if (ismask)
{
+ pdf_logimage("is mask\n");
img->super.cs = nil;
img->super.n = 0;
img->super.a = 1;
@@ -70,16 +75,20 @@ pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict,
if (!strcmp(img->super.cs->name, "Indexed"))
{
+ pdf_logimage("indexed\n");
img->indexed = (pdf_indexed*)img->super.cs;
img->super.cs = img->indexed->base;
}
+ pdf_logimage("colorspace %s\n", img->super.cs->name);
+
img->super.n = img->super.cs->n;
img->super.a = 0;
}
if (fz_isarray(d))
{
+ pdf_logimage("decode array\n");
if (img->indexed)
for (i = 0; i < 2; i++)
img->decode[i] = fz_toreal(fz_arrayget(d, i));
@@ -143,6 +152,9 @@ pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict,
*p = ~*p;
}
+ pdf_logimage("}\n");
+
+ *imgp = img;
return nil;
}
@@ -169,6 +181,8 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
if (!img)
return fz_outofmem;
+ pdf_logimage("load image %d %d (%p) {\n", fz_tonum(ref), fz_togen(ref), img);
+
/*
* Dimensions, BPC and ColorSpace
*/
@@ -177,6 +191,8 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
h = fz_toint(fz_dictgets(dict, "Height"));
bpc = fz_toint(fz_dictgets(dict, "BitsPerComponent"));
+ pdf_logimage("size %dx%d %d\n", w, h, bpc);
+
cs = nil;
obj = fz_dictgets(dict, "ColorSpace");
if (obj)
@@ -191,12 +207,15 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
if (!strcmp(cs->name, "Indexed"))
{
+ pdf_logimage("indexed\n");
indexed = (pdf_indexed*)cs;
cs = indexed->base;
}
n = cs->n;
a = 0;
+ pdf_logimage("colorspace %s\n", cs->name);
+
fz_dropobj(obj);
}
@@ -209,6 +228,7 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
ismask = fz_tobool(fz_dictgets(dict, "ImageMask"));
if (ismask)
{
+ pdf_logimage("is mask\n");
bpc = 1;
n = 0;
a = 1;
@@ -217,6 +237,8 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
obj = fz_dictgets(dict, "SMask");
if (fz_isindirect(obj))
{
+ pdf_logimage("has soft mask\n");
+
error = pdf_loadindirect(&sub, xref, obj);
if (error)
return error;
@@ -243,10 +265,12 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
return error;
if (fz_isarray(sub))
{
- puts(" mask / color key");
+ pdf_logimage("color keyed transparency\n");
+ // FIXME
}
else
{
+ pdf_logimage("has mask\n");
error = pdf_loadimage(&mask, xref, sub, obj);
if (error)
return error;
@@ -255,7 +279,8 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
}
else if (fz_isarray(obj))
{
- puts(" mask / color key");
+ pdf_logimage("color keyed transparency\n");
+ // FIXME
}
/*
@@ -265,6 +290,7 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
obj = fz_dictgets(dict, "Decode");
if (fz_isarray(obj))
{
+ pdf_logimage("decode array\n");
if (indexed)
for (i = 0; i < 2; i++)
img->decode[i] = fz_toreal(fz_arrayget(obj, i));
@@ -331,8 +357,9 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
img->bpc = bpc;
img->mask = (fz_image*)mask;
- *imgp = img;
+ pdf_logimage("}\n");
+ *imgp = img;
return nil;
}
diff --git a/mupdf/open.c b/mupdf/open.c
index 2705cd98..46e56802 100644
--- a/mupdf/open.c
+++ b/mupdf/open.c
@@ -27,6 +27,8 @@ loadversion(pdf_xref *xref)
xref->version = atof(buf + 5);
+ pdf_logxref("version %g\n", xref->version);
+
return nil;
}
@@ -77,6 +79,8 @@ readoldtrailer(pdf_xref *xref, char *buf, int cap)
int t;
int c;
+ pdf_logxref("load old xref format trailer\n");
+
fz_readline(xref->file, buf, cap);
if (strcmp(buf, "xref") != 0)
return fz_throw("syntaxerror: missing xref");
@@ -115,6 +119,7 @@ readoldtrailer(pdf_xref *xref, char *buf, int cap)
static fz_error *
readnewtrailer(pdf_xref *xref, char *buf, int cap)
{
+ pdf_logxref("load new xref format trailer\n");
return pdf_parseindobj(&xref->trailer, xref->file, buf, cap, nil, nil, nil);
}
@@ -151,6 +156,8 @@ readoldxref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap)
int i;
int c;
+ pdf_logxref("load old xref format\n");
+
fz_readline(xref->file, buf, cap);
if (strcmp(buf, "xref") != 0)
return fz_throw("syntaxerror: expected xref");
@@ -203,6 +210,8 @@ readnewxref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap)
int size, w0, w1, w2, i0, i1;
int i, n;
+ pdf_logxref("load new xref format\n");
+
error = pdf_parseindobj(&trailer, xref->file, buf, cap, &oid, &gen, &stmofs);
if (error)
return error;
@@ -329,6 +338,7 @@ readxrefsections(pdf_xref *xref, int ofs, char *buf, int cap)
xrefstm = fz_dictgets(trailer, "XrefStm");
if (xrefstm)
{
+ pdf_logxref("load xrefstm\n");
error = readxrefsections(xref, fz_toint(xrefstm), buf, cap);
if (error)
goto cleanup;
@@ -337,6 +347,7 @@ readxrefsections(pdf_xref *xref, int ofs, char *buf, int cap)
prev = fz_dictgets(trailer, "Prev");
if (prev)
{
+ pdf_logxref("load prev\n");
error = readxrefsections(xref, fz_toint(prev), buf, cap);
if (error)
goto cleanup;
@@ -367,6 +378,8 @@ pdf_loadobjstm(pdf_xref *xref, int oid, int gen, char *buf, int cap)
int count;
int i, n, t;
+ pdf_logxref("loadobjstm %d %d\n", oid, gen);
+
error = pdf_loadobject(&objstm, xref, oid, gen);
if (error)
return error;
@@ -374,6 +387,8 @@ pdf_loadobjstm(pdf_xref *xref, int oid, int gen, char *buf, int cap)
count = fz_toint(fz_dictgets(objstm, "N"));
first = fz_toint(fz_dictgets(objstm, "First"));
+ pdf_logxref(" count %d\n", count);
+
oidbuf = fz_malloc(count * sizeof(int));
if (!oidbuf) { error = fz_outofmem; goto cleanup1; }
@@ -475,6 +490,8 @@ pdf_openpdf(pdf_xref **xrefp, char *filename)
xref->cap = 0;
xref->table = nil;
+ pdf_logxref("openxref '%s' %p\n", filename, xref);
+
error = fz_openfile(&xref->file, filename, FZ_READ);
if (error)
goto cleanup;
@@ -495,6 +512,8 @@ pdf_openpdf(pdf_xref **xrefp, char *filename)
if (!size)
return fz_throw("syntaxerror: trailer missing Size entry");
+ pdf_logxref(" size %d\n", fz_toint(size));
+
xref->cap = fz_toint(size);
xref->len = fz_toint(size);
diff --git a/mupdf/page.c b/mupdf/page.c
index 88d44a42..3d09c269 100644
--- a/mupdf/page.c
+++ b/mupdf/page.c
@@ -6,6 +6,8 @@ runone(pdf_csi *csi, pdf_xref *xref, fz_obj *rdb, fz_obj *stmref)
{
fz_error *error;
+ pdf_logpage("simple content stream\n");
+
error = pdf_openstream(xref, fz_tonum(stmref), fz_togen(stmref));
if (error)
return error;
@@ -31,6 +33,8 @@ runmany(pdf_csi *csi, pdf_xref *xref, fz_obj *rdb, fz_obj *list)
int n;
int i;
+ pdf_logpage("multiple content streams: %d\n", fz_arraylen(list));
+
error = fz_newbuffer(&big, 32 * 1024);
if (error)
return error;
@@ -144,6 +148,8 @@ pdf_loadpage(pdf_page **pagep, pdf_xref *xref, fz_obj *dict)
fz_rect bbox;
int rotate;
+ pdf_logpage("load page {\n");
+
obj = fz_dictgets(dict, "CropBox");
if (!obj)
obj = fz_dictgets(dict, "MediaBox");
@@ -151,12 +157,17 @@ pdf_loadpage(pdf_page **pagep, pdf_xref *xref, fz_obj *dict)
return fz_throw("syntaxerror: Page missing MediaBox");
bbox = pdf_torect(obj);
+ pdf_logpage("bbox [%g %g %g %g]\n",
+ bbox.min.x, bbox.min.y, bbox.max.x, bbox.max.y);
+
obj = fz_dictgets(dict, "Rotate");
if (fz_isint(obj))
rotate = fz_toint(obj);
else
rotate = 0;
+ pdf_logpage("rotate %d\n", rotate);
+
/*
* Load resources
*/
@@ -182,6 +193,7 @@ pdf_loadpage(pdf_page **pagep, pdf_xref *xref, fz_obj *dict)
return error;
}
+ pdf_logpage("optimize tree\n");
error = fz_optimizetree(tree);
if (error) {
fz_dropobj(rdb);
@@ -207,12 +219,15 @@ pdf_loadpage(pdf_page **pagep, pdf_xref *xref, fz_obj *dict)
page->resources = rdb;
page->tree = tree;
+ pdf_logpage("} %p\n", page);
+
return nil;
}
void
pdf_droppage(pdf_page *page)
{
+ pdf_logpage("drop page %p\n", page);
fz_dropobj(page->resources);
fz_droptree(page->tree);
fz_free(page);
diff --git a/mupdf/pagetree.c b/mupdf/pagetree.c
index fbfca585..eafc0599 100644
--- a/mupdf/pagetree.c
+++ b/mupdf/pagetree.c
@@ -24,22 +24,30 @@ loadpagetree(pdf_xref *xref, pdf_pagetree *pages,
if (strcmp(fz_toname(type), "Page") == 0)
{
- if (inherit.resources && !fz_dictgets(obj, "Resources")) {
+ if (inherit.resources && !fz_dictgets(obj, "Resources"))
+ {
+ pdf_logpage("inherit resources (%d)\n", pages->cursor);
error = fz_dictputs(obj, "Resources", inherit.resources);
if (error) return error;
}
- if (inherit.mediabox && !fz_dictgets(obj, "MediaBox")) {
+ if (inherit.mediabox && !fz_dictgets(obj, "MediaBox"))
+ {
+ pdf_logpage("inherit mediabox (%d)\n", pages->cursor);
error = fz_dictputs(obj, "MediaBox", inherit.mediabox);
if (error) return error;
}
- if (inherit.cropbox && !fz_dictgets(obj, "CropBox")) {
+ if (inherit.cropbox && !fz_dictgets(obj, "CropBox"))
+ {
+ pdf_logpage("inherit cropbox (%d)\n", pages->cursor);
error = fz_dictputs(obj, "CropBox", inherit.cropbox);
if (error) return error;
}
- if (inherit.rotate && !fz_dictgets(obj, "Rotate")) {
+ if (inherit.rotate && !fz_dictgets(obj, "Rotate"))
+ {
+ pdf_logpage("inherit rotate (%d)\n", pages->cursor);
error = fz_dictputs(obj, "Rotate", inherit.rotate);
if (error) return error;
}
@@ -64,6 +72,9 @@ loadpagetree(pdf_xref *xref, pdf_pagetree *pages,
if (inh) inherit.rotate = inh;
kids = fz_dictgets(obj, "Kids");
+
+ pdf_logpage("subtree %d {\n", fz_arraylen(kids));
+
for (i = 0; i < fz_arraylen(kids); i++)
{
kref = fz_arrayget(kids, i);
@@ -75,6 +86,8 @@ loadpagetree(pdf_xref *xref, pdf_pagetree *pages,
fz_dropobj(kobj);
if (error) return error;
}
+
+ pdf_logpage("}\n");
}
return nil;
@@ -123,9 +136,12 @@ pdf_loadpagetree(pdf_pagetree **pp, pdf_xref *xref)
ref = fz_dictgets(pages, "Count");
count = fz_toint(ref);
- p = *pp = fz_malloc(sizeof(pdf_pagetree));
+ p = fz_malloc(sizeof(pdf_pagetree));
if (!p) { error = fz_outofmem; goto cleanup; }
+ pdf_logpage("load pagetree %p {\n", p);
+ pdf_logpage("count %d\n", count);
+
p->pref = nil;
p->pobj = nil;
p->count = count;
@@ -142,6 +158,10 @@ pdf_loadpagetree(pdf_pagetree **pp, pdf_xref *xref)
fz_dropobj(pages);
fz_dropobj(catalog);
+
+ pdf_logpage("}\n", count);
+
+ *pp = p;
return nil;
cleanup:
@@ -173,12 +193,16 @@ void
pdf_droppagetree(pdf_pagetree *pages)
{
int i;
+
+ pdf_logpage("drop pagetree %p\n", pages);
+
for (i = 0; i < pages->count; i++) {
if (pages->pref[i])
fz_dropobj(pages->pref[i]);
if (pages->pobj[i])
fz_dropobj(pages->pobj[i]);
}
+
fz_free(pages->pref);
fz_free(pages->pobj);
fz_free(pages);
diff --git a/mupdf/pattern.c b/mupdf/pattern.c
index ebe5f96c..7c29dc97 100644
--- a/mupdf/pattern.c
+++ b/mupdf/pattern.c
@@ -4,6 +4,8 @@
void
pdf_droppattern(pdf_pattern *pat)
{
+ pdf_logrsrc("drop pattern %p\n", pat);
+
if (pat->tree)
fz_droptree(pat->tree);
fz_free(pat);
@@ -18,7 +20,7 @@ pdf_loadpattern(pdf_pattern **patp, pdf_xref *xref, fz_obj *dict, fz_obj *stmref
fz_obj *obj;
pdf_csi *csi;
-printf("loading pattern %d %d\n", fz_tonum(stmref), fz_togen(stmref));
+ pdf_logrsrc("load pattern %d %d {\n", fz_tonum(stmref), fz_togen(stmref));
pat = fz_malloc(sizeof(pdf_pattern));
if (!pat)
@@ -29,18 +31,27 @@ printf("loading pattern %d %d\n", fz_tonum(stmref), fz_togen(stmref));
pat->xstep = fz_toreal(fz_dictgets(dict, "XStep"));
pat->ystep = fz_toreal(fz_dictgets(dict, "YStep"));
+ pdf_logrsrc("mask %d\n", pat->ismask);
+ pdf_logrsrc("xstep %g\n", pat->xstep);
+ pdf_logrsrc("ystep %g\n", pat->ystep);
+
obj = fz_dictgets(dict, "BBox");
pat->bbox = pdf_torect(obj);
+ pdf_logrsrc("bbox [%g %g %g %g]\n",
+ pat->bbox.min.x, pat->bbox.min.y,
+ pat->bbox.max.x, pat->bbox.max.y);
+
obj = fz_dictgets(dict, "Matrix");
if (obj)
pat->matrix = pdf_tomatrix(obj);
else
pat->matrix = fz_identity();
-printf(" mask %d\n", pat->ismask);
-printf(" xstep %g\n", pat->xstep);
-printf(" ystep %g\n", pat->ystep);
+ pdf_logrsrc("matrix [%g %g %g %g %g %g]\n",
+ pat->matrix.a, pat->matrix.b,
+ pat->matrix.c, pat->matrix.d,
+ pat->matrix.e, pat->matrix.f);
/*
* Resources
@@ -67,6 +78,8 @@ printf(" ystep %g\n", pat->ystep);
* Content stream
*/
+ pdf_logrsrc("content stream\n");
+
error = pdf_newcsi(&csi, pat->ismask);
if (error)
goto cleanup;
@@ -89,6 +102,11 @@ printf(" ystep %g\n", pat->ystep);
fz_dropobj(resources);
+ pdf_logrsrc("optimize tree\n");
+ fz_optimizetree(pat->tree);
+
+ pdf_logrsrc("}\n");
+
*patp = pat;
return nil;
diff --git a/mupdf/repair.c b/mupdf/repair.c
index a41f10ed..d5ce6584 100644
--- a/mupdf/repair.c
+++ b/mupdf/repair.c
@@ -135,12 +135,16 @@ pdf_repairpdf(pdf_xref **xrefp, char *filename)
xref->trailer = nil;
xref->crypt = nil;
+ pdf_logxref("repairxref '%s' %p\n", filename, xref);
+
error = fz_openfile(&file, filename, FZ_READ);
if (error)
goto cleanup;
xref->file = file;
+ /* TODO: extract version */
+
listlen = 0;
listcap = 1024;
list = fz_malloc(listcap * sizeof(struct entry));
@@ -167,11 +171,13 @@ pdf_repairpdf(pdf_xref **xrefp, char *filename)
goto cleanup;
if (isroot) {
+ pdf_logxref("found catalog: %d %d\n", oid, gen);
rootoid = oid;
rootgen = gen;
}
if (isinfo) {
+ pdf_logxref("found info: %d %d\n", oid, gen);
infooid = oid;
infogen = gen;
}
@@ -254,6 +260,9 @@ pdf_repairpdf(pdf_xref **xrefp, char *filename)
{
fz_obj *dict, *length;
+ pdf_logxref("correct stream length %d %d = %d\n",
+ list[i].oid, list[i].gen, list[i].stmlen);
+
error = pdf_loadobject(&dict, xref, list[i].oid, list[i].gen);
if (error)
goto cleanup;
diff --git a/mupdf/resources.c b/mupdf/resources.c
index 10d7de43..2b83e714 100644
--- a/mupdf/resources.c
+++ b/mupdf/resources.c
@@ -1,6 +1,8 @@
#include <fitz.h>
#include <mupdf.h>
+/* TODO: use binary search ... realizm.pdf */
+
void *
pdf_findresource(pdf_rsrc *rsrc, fz_obj *key)
{
@@ -62,12 +64,12 @@ preloadcolorspace(pdf_xref *xref, fz_obj *ref)
pdf_rsrc *rsrc;
fz_obj *obj = ref;
- if (!fz_isindirect(ref))
- fz_warn("inline colorspace resource");
-
if (pdf_findresource(xref->rcolorspace, ref))
return nil;
+ if (!fz_isindirect(ref))
+ pdf_logrsrc("inline colorspace resource\n");
+
rsrc = fz_malloc(sizeof(pdf_rsrc));
if (!rsrc)
return fz_outofmem;
@@ -97,14 +99,14 @@ preloadpattern(pdf_xref *xref, fz_obj *ref)
fz_obj *type;
fz_obj *obj = ref;
- if (!fz_isindirect(ref))
- fz_warn("inline pattern resource");
-
if (pdf_findresource(xref->rpattern, ref))
return nil;
if (pdf_findresource(xref->rshade, ref))
return nil;
+ if (!fz_isindirect(ref))
+ pdf_logrsrc("inline pattern resource\n");
+
rsrc = fz_malloc(sizeof(pdf_rsrc));
if (!rsrc)
return fz_outofmem;
@@ -158,12 +160,12 @@ preloadshading(pdf_xref *xref, fz_obj *ref)
pdf_rsrc *rsrc;
fz_obj *obj = ref;
- if (!fz_isindirect(ref))
- fz_warn("inline shading resource");
-
if (pdf_findresource(xref->rshade, ref))
return nil;
+ if (!fz_isindirect(ref))
+ pdf_logrsrc("inline shading resource\n");
+
rsrc = fz_malloc(sizeof(pdf_rsrc));
if (!rsrc)
return fz_outofmem;
@@ -193,14 +195,14 @@ preloadxobject(pdf_xref *xref, fz_obj *ref)
fz_obj *obj = ref;
fz_obj *subtype;
- if (!fz_isindirect(ref))
- fz_warn("inline xobject resource");
-
if (pdf_findresource(xref->rxobject, ref))
return nil;
if (pdf_findresource(xref->rimage, ref))
return nil;
+ if (!fz_isindirect(ref))
+ pdf_logrsrc("inline xobject resource\n");
+
rsrc = fz_malloc(sizeof(pdf_rsrc));
if (!rsrc)
return fz_outofmem;
@@ -255,12 +257,12 @@ preloadfont(pdf_xref *xref, fz_obj *ref)
pdf_rsrc *rsrc;
fz_obj *obj = ref;
- if (!fz_isindirect(ref))
- fz_warn("inline font resource");
-
if (pdf_findresource(xref->rfont, ref))
return nil;
+ if (!fz_isindirect(ref))
+ pdf_logrsrc("inline font resource\n");
+
rsrc = fz_malloc(sizeof(pdf_rsrc));
if (!rsrc)
return fz_outofmem;
@@ -299,6 +301,7 @@ scanfonts(pdf_xref *xref, fz_obj *rdb)
obj = fz_dictgets(obj, "Font");
if (obj)
{
+ pdf_logrsrc("extgstate font\n");
error = preloadfont(xref, fz_arrayget(obj, 0));
if (error)
return error;
@@ -375,6 +378,8 @@ pdf_loadresources(fz_obj **rdbp, pdf_xref *xref, fz_obj *orig)
fz_obj *obj;
int i;
+ pdf_logrsrc("load resources {\n");
+
/*
* Resolve indirect objects
*/
@@ -463,6 +468,8 @@ pdf_loadresources(fz_obj **rdbp, pdf_xref *xref, fz_obj *orig)
if (error)
goto cleanup;
+ pdf_logrsrc("}\n");
+
*rdbp = copy;
return nil;
diff --git a/mupdf/save.c b/mupdf/save.c
index 2639c993..e5d42a34 100644
--- a/mupdf/save.c
+++ b/mupdf/save.c
@@ -113,6 +113,8 @@ pdf_updatepdf(pdf_xref *xref, char *path)
int startxref;
fz_obj *obj;
+ pdf_logxref("updatexref '%s' %p\n", path, xref);
+
error = fz_openfile(&out, path, FZ_APPEND);
if (error)
return error;
@@ -141,6 +143,8 @@ pdf_updatepdf(pdf_xref *xref, char *path)
{
n = countmodified(xref, oid);
+ pdf_logxref(" section %d +%d\n", oid, n);
+
fz_print(out, "%d %d\n", oid, n);
for (i = 0; i < n; i++)
@@ -213,9 +217,13 @@ pdf_savepdf(pdf_xref *xref, char *path, pdf_crypt *encrypt)
fz_obj *obj;
int eoid, egen;
+ pdf_logxref("savexref '%s' %p\n", path, xref);
+
/* need to add encryption object for acrobat < 6 */
if (encrypt)
{
+ pdf_logxref("make encryption dict\n");
+
error = pdf_allocobject(xref, &eoid, &egen);
if (error)
return error;
diff --git a/mupdf/type3.c b/mupdf/type3.c
index bda9e06a..9999c07c 100644
--- a/mupdf/type3.c
+++ b/mupdf/type3.c
@@ -111,15 +111,27 @@ pdf_loadtype3font(pdf_font **fontp, pdf_xref *xref, fz_obj *dict)
if (!font)
return fz_outofmem;
+ pdf_logfont("load type3 font %p {\n", font);
+ pdf_logfont("name %s\n", buf);
+
font->super.render = t3render;
font->super.drop = (void(*)(fz_font*)) t3dropfont;
obj = fz_dictgets(dict, "FontMatrix");
font->matrix = pdf_tomatrix(obj);
+ pdf_logfont("matrix [%g %g %g %g %g %g]\n",
+ font->matrix.a, font->matrix.b,
+ font->matrix.c, font->matrix.d,
+ font->matrix.e, font->matrix.f);
+
obj = fz_dictgets(dict, "FontBBox");
bbox = pdf_torect(obj);
+ pdf_logfont("bbox [%g %g %g %g]\n",
+ bbox.min.x, bbox.min.y,
+ bbox.max.x, bbox.max.y);
+
bbox = fz_transformaabb(font->matrix, bbox);
bbox.min.x = fz_floor(bbox.min.x * 1000);
bbox.min.y = fz_floor(bbox.min.y * 1000);
@@ -240,6 +252,8 @@ pdf_loadtype3font(pdf_font **fontp, pdf_xref *xref, fz_obj *dict)
if (error)
goto cleanup;
}
+ else
+ pdf_logfont("no resource dict!\n");
/*
* CharProcs
@@ -263,6 +277,7 @@ pdf_loadtype3font(pdf_font **fontp, pdf_xref *xref, fz_obj *dict)
obj = fz_dictgets(charprocs, estrings[i]);
if (obj)
{
+ pdf_logfont("load charproc %s {\n", estrings[i]);
error = loadcharproc(&font->charprocs[i], xref, resources, obj);
if (error)
goto cleanup2;
@@ -270,6 +285,8 @@ pdf_loadtype3font(pdf_font **fontp, pdf_xref *xref, fz_obj *dict)
error = fz_optimizetree(font->charprocs[i]);
if (error)
goto cleanup2;
+
+ pdf_logfont("}\n");
}
}
}
@@ -278,6 +295,8 @@ pdf_loadtype3font(pdf_font **fontp, pdf_xref *xref, fz_obj *dict)
if (resources)
fz_dropobj(resources);
+ pdf_logfont("}\n");
+
*fontp = font;
return nil;
diff --git a/mupdf/unicode.c b/mupdf/unicode.c
index 9aa14001..ba6c621e 100644
--- a/mupdf/unicode.c
+++ b/mupdf/unicode.c
@@ -17,6 +17,8 @@ pdf_loadtounicode(pdf_font *font, pdf_xref *xref,
if (fz_isindirect(cmapstm))
{
+ pdf_logfont("tounicode embedded cmap\n");
+
error = pdf_loadembeddedcmap(&cmap, xref, cmapstm);
if (error)
return error;
@@ -46,8 +48,10 @@ pdf_loadtounicode(pdf_font *font, pdf_xref *xref,
return error;
}
- if (collection)
+ else if (collection)
{
+ pdf_logfont("tounicode cid collection\n");
+
if (!strcmp(collection, "Adobe-CNS1"))
return pdf_loadsystemcmap(&font->tounicode, "Adobe-CNS1-UCS2");
else if (!strcmp(collection, "Adobe-GB1"))
@@ -62,6 +66,8 @@ pdf_loadtounicode(pdf_font *font, pdf_xref *xref,
if (strings)
{
+ pdf_logfont("tounicode strings\n");
+
font->ncidtoucs = 256;
font->cidtoucs = fz_malloc(256 * sizeof(unsigned short));
if (!font->cidtoucs)
@@ -78,7 +84,7 @@ pdf_loadtounicode(pdf_font *font, pdf_xref *xref,
return nil;
}
- fz_warn("font: cannot create unicode conversion", collection);
+ pdf_logfont("tounicode impossible");
return nil;
}
diff --git a/mupdf/xobject.c b/mupdf/xobject.c
index b4014865..bd17235b 100644
--- a/mupdf/xobject.c
+++ b/mupdf/xobject.c
@@ -12,15 +12,26 @@ pdf_loadxobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
if (!form)
return fz_outofmem;
+ pdf_logrsrc("load xobject %d %d (%p) {\n", fz_tonum(ref), fz_togen(ref), form);
+
obj = fz_dictgets(dict, "BBox");
form->bbox = pdf_torect(obj);
+ pdf_logrsrc("bbox [%g %g %g %g]\n",
+ form->bbox.min.x, form->bbox.min.y,
+ form->bbox.max.x, form->bbox.max.y);
+
obj = fz_dictgets(dict, "Matrix");
if (obj)
form->matrix = pdf_tomatrix(obj);
else
form->matrix = fz_identity();
+ pdf_logrsrc("matrix [%g %g %g %g %g %g]\n",
+ form->matrix.a, form->matrix.b,
+ form->matrix.c, form->matrix.d,
+ form->matrix.e, form->matrix.f);
+
form->resources = nil;
obj = fz_dictgets(dict, "Resources");
if (obj)
@@ -51,6 +62,10 @@ pdf_loadxobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
return error;
}
+ pdf_logrsrc("stream %d bytes\n", form->contents->wp - form->contents->rp);
+
+ pdf_logrsrc("}\n");
+
*formp = form;
return nil;
}
diff --git a/mupdf/xref.c b/mupdf/xref.c
index 8a22b238..c1ed230e 100644
--- a/mupdf/xref.c
+++ b/mupdf/xref.c
@@ -15,6 +15,8 @@ pdf_newpdf(pdf_xref **xrefp)
return fz_outofmem;
memset(xref, 0, sizeof(pdf_xref));
+ pdf_logxref("newxref %p\n", xref);
+
xref->file = nil;
xref->version = 1.3;
xref->startxref = 0;
@@ -78,6 +80,8 @@ pdf_closepdf(pdf_xref *xref)
{
int i;
+ pdf_logxref("closexref %p\n", xref);
+
if (xref->table)
{
for (i = 0; i < xref->len; i++)
@@ -145,6 +149,8 @@ pdf_allocobject(pdf_xref *xref, int *oidp, int *genp)
int prev, next;
int oid = 0;
+ pdf_logxref("allocobj");
+
while (1)
{
x = xref->table + oid;
@@ -156,6 +162,8 @@ pdf_allocobject(pdf_xref *xref, int *oidp, int *genp)
*oidp = oid;
*genp = x->gen;
+ pdf_logxref(" reuse %d %d\n", *oidp, *genp);
+
x->type = 'a';
x->ofs = 0;
@@ -200,6 +208,8 @@ pdf_allocobject(pdf_xref *xref, int *oidp, int *genp)
*oidp = oid;
*genp = 0;
+ pdf_logxref(" %d %d\n", *oidp, *genp);
+
prev = findprev(xref, oid);
next = findnext(xref, oid);
xref->table[prev].type = 'd';
@@ -217,6 +227,8 @@ pdf_deleteobject(pdf_xref *xref, int oid, int gen)
if (oid < 0 || oid >= xref->len)
return fz_throw("rangecheck: object number out of range: %d", oid);
+ pdf_logxref("deleteobj %d %d\n", oid, gen);
+
x = xref->table + oid;
x->type = 'd';
@@ -246,6 +258,8 @@ pdf_updateobject(pdf_xref *xref, int oid, int gen, fz_obj *obj)
if (oid < 0 || oid >= xref->len)
return fz_throw("rangecheck: object number out of range: %d", oid);
+ pdf_logxref("updateobj %d %d (%p)\n", oid, gen, obj);
+
x = xref->table + oid;
if (x->obj)
@@ -273,6 +287,8 @@ pdf_updatestream(pdf_xref *xref, int oid, int gen, fz_buffer *stm)
if (oid < 0 || oid >= xref->len)
return fz_throw("rangecheck: object number out of range: %d", oid);
+ pdf_logxref("updatestm %d %d (%p)\n", oid, gen, stm);
+
x = xref->table + oid;
if (x->stmbuf)
@@ -305,7 +321,12 @@ pdf_cacheobject(pdf_xref *xref, int oid, int gen)
return nil;
if (x->type == 'f' || x->type == 'd')
- return fz_throw("rangecheck: tried to load free object");
+ {
+ error = fz_newnull(&x->obj);
+ if (error)
+ return error;
+ return nil;
+ }
if (x->type == 'n')
{