summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mupdf/cmap.c3
-rw-r--r--mupdf/font.c3
-rw-r--r--mupdf/function.c5
-rw-r--r--mupdf/image.c5
-rw-r--r--mupdf/interpret.c75
-rw-r--r--mupdf/pattern.c3
-rw-r--r--mupdf/shade.c1
-rw-r--r--mupdf/xobject.c3
8 files changed, 76 insertions, 22 deletions
diff --git a/mupdf/cmap.c b/mupdf/cmap.c
index 0a53b28f..5029ae4a 100644
--- a/mupdf/cmap.c
+++ b/mupdf/cmap.c
@@ -383,7 +383,10 @@ pdf_loadembeddedcmap(fz_cmap **cmapp, pdf_xref *xref, fz_obj *stmref)
fz_obj *obj;
if ((*cmapp = pdf_finditem(xref->store, PDF_KCMAP, stmref)))
+ {
+ fz_keepcmap(*cmapp);
return nil;
+ }
pdf_logfont("load embedded cmap %d %d {\n", fz_tonum(stmref), fz_togen(stmref));
diff --git a/mupdf/font.c b/mupdf/font.c
index eeb48ac6..5c6aac57 100644
--- a/mupdf/font.c
+++ b/mupdf/font.c
@@ -997,7 +997,10 @@ pdf_loadfont(pdf_font **fontp, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
char *subtype;
if ((*fontp = pdf_finditem(xref->store, PDF_KFONT, ref)))
+ {
+ fz_keepfont((fz_font*)*fontp);
return nil;
+ }
subtype = fz_toname(fz_dictgets(dict, "Subtype"));
if (!strcmp(subtype, "Type0"))
diff --git a/mupdf/function.c b/mupdf/function.c
index 86e8f8bc..586c7af7 100644
--- a/mupdf/function.c
+++ b/mupdf/function.c
@@ -1385,9 +1385,8 @@ pdf_dropfunction(pdf_function *func)
case EXPONENTIAL:
break;
case STITCHING:
- if (func->u.st.funcs)
- for (i = 0; i < func->u.st.k; ++i)
- pdf_dropfunction(func->u.st.funcs[i]);
+ for (i = 0; i < func->u.st.k; ++i)
+ pdf_dropfunction(func->u.st.funcs[i]);
break;
case POSTSCRIPT:
fz_free(func->u.p.code);
diff --git a/mupdf/image.c b/mupdf/image.c
index d7014e0a..411d0b0e 100644
--- a/mupdf/image.c
+++ b/mupdf/image.c
@@ -64,6 +64,8 @@ pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict,
{
fz_obj *cso = fz_dictget(csd, cs);
img->super.cs = pdf_finditem(xref->store, PDF_KCOLORSPACE, cso);
+ if (img->super.cs)
+ fz_keepcolorspace(img->super.cs);
}
}
@@ -204,7 +206,10 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
int stride;
if ((*imgp = pdf_finditem(xref->store, PDF_KIMAGE, ref)))
+ {
+ fz_keepimage((fz_image*)*imgp);
return nil;
+ }
img = fz_malloc(sizeof(pdf_image));
if (!img)
diff --git a/mupdf/interpret.c b/mupdf/interpret.c
index 6f43bc7f..753a4aaf 100644
--- a/mupdf/interpret.c
+++ b/mupdf/interpret.c
@@ -62,16 +62,59 @@ clearstack(pdf_csi *csi)
csi->top = 0;
}
+static fz_error *
+gsave(pdf_csi *csi)
+{
+ if (csi->gtop == 31)
+ return fz_throw("gstate overflow in content stream");
+
+ memcpy(&csi->gstate[csi->gtop + 1], &csi->gstate[csi->gtop], sizeof(pdf_gstate));
+
+ csi->gtop ++;
+
+ if (csi->gstate[csi->gtop].fill.cs)
+ fz_keepcolorspace(csi->gstate[csi->gtop].fill.cs);
+ if (csi->gstate[csi->gtop].stroke.cs)
+ fz_keepcolorspace(csi->gstate[csi->gtop].stroke.cs);
+
+ return nil;
+}
+
+static fz_error *
+grestore(pdf_csi *csi)
+{
+ if (csi->gtop == 0)
+ return fz_throw("gstate underflow in content stream");
+
+ if (csi->gstate[csi->gtop].fill.cs)
+ fz_dropcolorspace(csi->gstate[csi->gtop].fill.cs);
+ if (csi->gstate[csi->gtop].stroke.cs)
+ fz_dropcolorspace(csi->gstate[csi->gtop].stroke.cs);
+
+ csi->gtop --;
+
+ return nil;
+}
+
void
pdf_dropcsi(pdf_csi *csi)
{
- /* TODO: drop gstates */
+ while (csi->gtop)
+ grestore(csi);
+
+ if (csi->gstate[csi->gtop].fill.cs)
+ fz_dropcolorspace(csi->gstate[csi->gtop].fill.cs);
+ if (csi->gstate[csi->gtop].stroke.cs)
+ fz_dropcolorspace(csi->gstate[csi->gtop].stroke.cs);
+
if (csi->path) fz_dropnode((fz_node*)csi->path);
if (csi->clip) fz_dropnode((fz_node*)csi->clip);
if (csi->textclip) fz_dropnode((fz_node*)csi->textclip);
if (csi->text) fz_dropnode((fz_node*)csi->text);
if (csi->array) fz_dropobj(csi->array);
+
clearstack(csi);
+
fz_free(csi);
}
@@ -88,12 +131,9 @@ runxobject(pdf_csi *csi, pdf_xref *xref, pdf_xobject *xobj)
fz_file *file;
/* gsave */
- if (csi->gtop == 31)
- return fz_throw("gstate overflow in content stream");
- memcpy(&csi->gstate[csi->gtop + 1],
- &csi->gstate[csi->gtop],
- sizeof (pdf_gstate));
- csi->gtop ++;
+ error = gsave(csi);
+ if (error)
+ return error;
/* push transform */
@@ -124,9 +164,9 @@ runxobject(pdf_csi *csi, pdf_xref *xref, pdf_xobject *xobj)
return error;
/* grestore */
- if (csi->gtop == 0)
- return fz_throw("gstate underflow in content stream");
- csi->gtop --;
+ error = grestore(csi);
+ if (error)
+ return error;
return nil;
}
@@ -798,20 +838,17 @@ fz_debugobj(rdb);
case 'q':
if (csi->top != 0)
goto syntaxerror;
- if (csi->gtop == 31)
- return fz_throw("gstate overflow in content stream");
- memcpy(&csi->gstate[csi->gtop + 1],
- &csi->gstate[csi->gtop],
- sizeof (pdf_gstate));
- csi->gtop ++;
+ error = gsave(csi);
+ if (error)
+ return error;
break;
case 'Q':
if (csi->top != 0)
goto syntaxerror;
- if (csi->gtop == 0)
- return fz_throw("gstate underflow in content stream");
- csi->gtop --;
+ error = grestore(csi);
+ if (error)
+ return error;
break;
case 'w':
diff --git a/mupdf/pattern.c b/mupdf/pattern.c
index ebd0d743..76b52034 100644
--- a/mupdf/pattern.c
+++ b/mupdf/pattern.c
@@ -29,7 +29,10 @@ pdf_loadpattern(pdf_pattern **patp, pdf_xref *xref, fz_obj *dict, fz_obj *stmref
pdf_csi *csi;
if ((*patp = pdf_finditem(xref->store, PDF_KPATTERN, stmref)))
+ {
+ pdf_keeppattern(*patp);
return nil;
+ }
pdf_logrsrc("load pattern %d %d {\n", fz_tonum(stmref), fz_togen(stmref));
diff --git a/mupdf/shade.c b/mupdf/shade.c
index cbe319f7..2f65f395 100644
--- a/mupdf/shade.c
+++ b/mupdf/shade.c
@@ -39,6 +39,7 @@ pdf_loadshadedict(fz_shade **shadep, pdf_xref *xref, fz_obj *shading, fz_obj *re
shade = fz_malloc(sizeof(fz_shade));
+ shade->refs = 1;
shade->usefunction = 0;
shade->matrix = mat;
diff --git a/mupdf/xobject.c b/mupdf/xobject.c
index c3c3b882..473a1485 100644
--- a/mupdf/xobject.c
+++ b/mupdf/xobject.c
@@ -9,7 +9,10 @@ pdf_loadxobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
fz_obj *obj;
if ((*formp = pdf_finditem(xref->store, PDF_KXOBJECT, ref)))
+ {
+ pdf_keepxobject(*formp);
return nil;
+ }
form = fz_malloc(sizeof(pdf_xobject));
if (!form)