From 37211633cf44cc8fead75933e9f594a030998a33 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 26 Jul 2010 13:32:36 +0000 Subject: Add function to update an object in the xref (for pdfclean). --- mupdf/mupdf.h | 1 + mupdf/pdf_xref.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/mupdf/mupdf.h b/mupdf/mupdf.h index 3c247bc0..abd9c9ec 100644 --- a/mupdf/mupdf.h +++ b/mupdf/mupdf.h @@ -150,6 +150,7 @@ struct pdf_xrefentry_s fz_error pdf_cacheobject(pdf_xref *, int num, int gen); fz_error pdf_loadobject(fz_obj **objp, pdf_xref *, int num, int gen); +void pdf_updateobject( pdf_xref *xref, int num, int gen, fz_obj *newobj); int pdf_isstream(pdf_xref *xref, int num, int gen); fz_filter * pdf_buildinlinefilter(pdf_xref *xref, fz_obj *stmobj, int length); diff --git a/mupdf/pdf_xref.c b/mupdf/pdf_xref.c index eba185e3..9dec068c 100644 --- a/mupdf/pdf_xref.c +++ b/mupdf/pdf_xref.c @@ -946,6 +946,28 @@ pdf_loadobject(fz_obj **objp, pdf_xref *xref, int num, int gen) return fz_okay; } +/* Replace numbered object -- for use by pdfclean and similar tools */ +void +pdf_updateobject(pdf_xref *xref, int num, int gen, fz_obj *newobj) +{ + pdf_xrefentry *x; + + if (num < 0 || num >= xref->len) + { + fz_warn("object out of range (%d %d R); xref size %d", num, gen, xref->len); + return; + } + + x = &xref->table[num]; + + if (x->obj) + fz_dropobj(x->obj); + + x->obj = fz_keepobj(newobj); + x->type = 'n'; + x->ofs = 0; +} + /* * Convenience function to open a file then call pdf_openxrefwithstream. */ -- cgit v1.2.3