diff options
author | Tor Andersson <tor@ghostscript.com> | 2004-10-11 10:42:05 +0200 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2004-10-11 10:42:05 +0200 |
commit | 358811630686460d6b0a96021a1bcb4c3124fb03 (patch) | |
tree | 08a0049753ead2cd063723fddd0dd241740769df /test/pdfdebug.c | |
parent | bd77c6880a7cf32e20865fb0cdb6816df0e6f775 (diff) | |
download | mupdf-358811630686460d6b0a96021a1bcb4c3124fb03.tar.xz |
cleaned up xref object and stream api
Diffstat (limited to 'test/pdfdebug.c')
-rw-r--r-- | test/pdfdebug.c | 61 |
1 files changed, 22 insertions, 39 deletions
diff --git a/test/pdfdebug.c b/test/pdfdebug.c index 7536e7e0..eefa0a74 100644 --- a/test/pdfdebug.c +++ b/test/pdfdebug.c @@ -41,86 +41,73 @@ void printsafe(unsigned char *buf, int n) } } -void decodestream(pdf_xref *xref, fz_obj *stream, int oid, int gid, int ofs) +void decodestream(pdf_xref *xref, int oid, int gid) { fz_error *error; unsigned char buf[512]; safecol = 0; - error = pdf_openstream0(xref, stream, oid, gid, ofs); + error = pdf_openstream(xref, oid, gid); if (error) fz_abort(error); while (1) { - int n = fz_read(xref->file, buf, sizeof buf); + int n = fz_read(xref->stream, buf, sizeof buf); if (n == 0) break; if (n < 0) - fz_abort(fz_ferror(xref->file)); + fz_abort(fz_ferror(xref->stream)); printsafe(buf, n); } pdf_closestream(xref); } -void copystream(pdf_xref *xref, fz_obj *stream, int ofs) +void copystream(pdf_xref *xref, int oid, int gid) { fz_error *error; unsigned char buf[512]; - fz_filter *filter; - fz_obj *obj; - int len; safecol = 0; - obj = fz_dictgets(stream, "Length"); - error = pdf_resolve(&obj, xref); - if (error) fz_abort(error); - len = fz_toint(obj); - fz_dropobj(obj); - - error = fz_newnullfilter(&filter, len); - if (error) fz_abort(error); - - fz_seek(xref->file, ofs, 0); - - error = fz_pushfilter(xref->file, filter); + error = pdf_openrawstream(xref, oid, gid); if (error) fz_abort(error); while (1) { - int n = fz_read(xref->file, buf, sizeof buf); + int n = fz_read(xref->stream, buf, sizeof buf); if (n == 0) break; if (n < 0) - fz_abort(fz_ferror(xref->file)); + fz_abort(fz_ferror(xref->stream)); printsafe(buf, n); } - fz_popfilter(xref->file); + pdf_closestream(xref); } void printobject(pdf_xref *xref, int oid, int gid) { fz_error *error; - int stmofs; fz_obj *obj; - error = pdf_loadobject0(&obj, xref, oid, gid, &stmofs); + error = pdf_loadobject(&obj, xref, oid, gid); if (error) fz_abort(error); printf("%d %d obj\n", oid, gid); fz_debugobj(obj); printf("\n"); - if (stmofs != -1) { + + if (xref->table[oid].stmofs) { printf("stream\n"); if (dodecode) - decodestream(xref, obj, oid, gid, stmofs); + decodestream(xref, oid, gid); else - copystream(xref, obj, stmofs); + copystream(xref, oid, gid); printf("endstream\n"); } + printf("endobj\n"); fz_dropobj(obj); @@ -159,18 +146,14 @@ int main(int argc, char **argv) filename = argv[optind++]; - error = pdf_newxref(&xref); - if (error) - fz_abort(error); - if (dorepair) - error = pdf_repairxref(xref, filename); + error = pdf_repairpdf(&xref, filename); else - error = pdf_openxref(xref, filename); + error = pdf_openpdf(&xref, filename); if (error) fz_abort(error); - error = pdf_decryptxref(xref); + error = pdf_decryptpdf(xref); if (error) fz_abort(error); @@ -180,9 +163,6 @@ int main(int argc, char **argv) if (error) fz_abort(error); } - if (doprintxref) - pdf_debugxref(xref); - if (optind == argc) { printf("trailer\n"); @@ -196,7 +176,10 @@ int main(int argc, char **argv) printf("\n"); } - pdf_closexref(xref); + if (doprintxref) + pdf_debugpdf(xref); + + pdf_closepdf(xref); return 0; } |