fz_stream * pdf_open_raw_renumbered_stream(fz_context *ctx, pdf_document *doc, int num, int gen, int orig_num, int orig_gen) { pdf_xref_entry *x; if (num <= 0 || num >= pdf_xref_len(ctx, doc)) fz_throw(ctx, FZ_ERROR_GENERIC, "object id out of range (%d %d R)", num, gen); x = pdf_cache_object(ctx, doc, num, gen); if (x->stm_ofs == 0) fz_throw(ctx, FZ_ERROR_GENERIC, "object is not a stream"); return pdf_open_raw_filter(ctx, doc->file, doc, x->obj, num, orig_num, orig_gen, x->stm_ofs); }
/* * Construct a filter to decode a stream, constraining * to stream length and decrypting. */ static fz_stream * pdf_open_filter(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int num, int gen) { fz_obj *filters; fz_obj *params; filters = fz_dict_getsa(stmobj, "Filter", "F"); params = fz_dict_getsa(stmobj, "DecodeParms", "DP"); chain = pdf_open_raw_filter(chain, xref, stmobj, num, gen); if (fz_is_name(filters)) return build_filter(chain, xref, filters, params, num, gen); if (fz_array_len(filters) > 0) return build_filter_chain(chain, xref, filters, params, num, gen); return chain; }
fz_stream * pdf_open_raw_renumbered_stream(pdf_document *xref, int num, int gen, int orig_num, int orig_gen) { pdf_xref_entry *x; if (num < 0 || num >= xref->len) fz_throw(xref->ctx, "object id out of range (%d %d R)", num, gen); x = xref->table + num; pdf_cache_object(xref, num, gen); /* RJW: "cannot load stream object (%d %d R)", num, gen */ if (x->stm_ofs == 0) fz_throw(xref->ctx, "object is not a stream"); return pdf_open_raw_filter(xref->file, xref, x->obj, orig_num, orig_gen, x->stm_ofs); }
/* * Construct a filter to decode a stream, constraining * to stream length and decrypting. */ static fz_stream * pdf_open_filter(fz_stream *chain, pdf_document *xref, pdf_obj *stmobj, int num, int gen, int offset, pdf_image_params *imparams) { pdf_obj *filters; pdf_obj *params; filters = pdf_dict_getsa(stmobj, "Filter", "F"); params = pdf_dict_getsa(stmobj, "DecodeParms", "DP"); chain = pdf_open_raw_filter(chain, xref, stmobj, num, gen, offset); if (pdf_is_name(filters)) chain = build_filter(chain, xref, filters, params, num, gen, imparams); else if (pdf_array_len(filters) > 0) chain = build_filter_chain(chain, xref, filters, params, num, gen, imparams); return chain; }
/* * Construct a filter to decode a stream, constraining * to stream length and decrypting. */ static fz_stream * pdf_open_filter(fz_context *ctx, pdf_document *doc, fz_stream *chain, pdf_obj *stmobj, int num, fz_off_t offset, fz_compression_params *imparams) { pdf_obj *filters; pdf_obj *params; int orig_num, orig_gen; filters = pdf_dict_geta(ctx, stmobj, PDF_NAME_Filter, PDF_NAME_F); params = pdf_dict_geta(ctx, stmobj, PDF_NAME_DecodeParms, PDF_NAME_DP); chain = pdf_open_raw_filter(ctx, chain, doc, stmobj, num, &orig_num, &orig_gen, offset); fz_var(chain); fz_try(ctx) { if (pdf_is_name(ctx, filters)) { fz_stream *chain2 = chain; chain = NULL; chain = build_filter(ctx, chain2, doc, filters, params, orig_num, orig_gen, imparams); } else if (pdf_array_len(ctx, filters) > 0) { fz_stream *chain2 = chain; chain = NULL; chain = build_filter_chain(ctx, chain2, doc, filters, params, orig_num, orig_gen, imparams); } } fz_catch(ctx) { fz_drop_stream(ctx, chain); fz_rethrow(ctx); } return chain; }
/* * Open a stream for reading the raw (compressed but decrypted) data. * Using xref->file while this is open is a bad idea. */ fz_stream * pdf_open_raw_stream(pdf_document *xref, int num, int gen) { pdf_xref_entry *x; fz_stream *stm; fz_var(x); if (num < 0 || num >= xref->len) fz_throw(xref->ctx, "object id out of range (%d %d R)", num, gen); x = xref->table + num; pdf_cache_object(xref, num, gen); /* RJW: "cannot load stream object (%d %d R)", num, gen */ if (x->stm_ofs == 0) fz_throw(xref->ctx, "object is not a stream"); stm = pdf_open_raw_filter(xref->file, xref, x->obj, num, gen); fz_lock_stream(stm); fz_seek(xref->file, x->stm_ofs, 0); return stm; }
/* * Open a stream for reading the raw (compressed but decrypted) data. * Using xref->file while this is open is a bad idea. */ fz_error pdf_open_raw_stream(fz_stream **stmp, pdf_xref *xref, int num, int gen) { pdf_xref_entry *x; fz_error error; if (num < 0 || num >= xref->len) return fz_throw("object id out of range (%d %d R)", num, gen); x = xref->table + num; error = pdf_cache_object(xref, num, gen); if (error) return fz_rethrow(error, "cannot load stream object (%d %d R)", num, gen); if (x->stm_ofs) { *stmp = pdf_open_raw_filter(xref->file, xref, x->obj, num, gen); fz_seek(xref->file, x->stm_ofs, 0); return fz_okay; } return fz_throw("object is not a stream"); }