Пример #1
0
/*
 * Check if an object is a stream or not.
 */
int
pdf_is_stream(pdf_document *xref, int num, int gen)
{
    if (num < 0 || num >= xref->len)
        return 0;

    pdf_cache_object(xref, num, gen);
    /* RJW: "cannot load object, ignoring error" */

    return xref->table[num].stm_ofs > 0;
}
Пример #2
0
/*
 * Check if an object is a stream or not.
 */
int
pdf_is_stream(fz_context *ctx, pdf_document *doc, int num, int gen)
{
	pdf_xref_entry *entry;

	if (num <= 0 || num >= pdf_xref_len(ctx, doc))
		return 0;

	entry = pdf_cache_object(ctx, doc, num, gen);

	return entry->stm_ofs != 0 || entry->stm_buf;
}
Пример #3
0
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);
}
Пример #4
0
static fz_stream *
pdf_open_image_stream(fz_context *ctx, pdf_document *doc, int num, int gen, int orig_num, int orig_gen, fz_compression_params *params)
{
	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 && x->stm_buf == NULL)
		fz_throw(ctx, FZ_ERROR_GENERIC, "object is not a stream");

	return pdf_open_filter(ctx, doc, doc->file, x->obj, orig_num, orig_gen, x->stm_ofs, params);
}
Пример #5
0
fz_error
pdf_load_object(fz_obj **objp, pdf_xref *xref, int num, int gen)
{
	fz_error error;

	error = pdf_cache_object(xref, num, gen);
	if (error)
		return fz_rethrow(error, "cannot load object (%d %d R) into cache", num, gen);

	assert(xref->table[num].obj);

	*objp = fz_keep_obj(xref->table[num].obj);

	return fz_okay;
}
Пример #6
0
/*
 * Check if an object is a stream or not.
 */
int
pdf_is_stream(pdf_xref *xref, int num, int gen)
{
	fz_error error;

	if (num < 0 || num >= xref->len)
		return 0;

	error = pdf_cache_object(xref, num, gen);
	if (error)
	{
		fz_catch(error, "cannot load object, ignoring error");
		return 0;
	}

	return xref->table[num].stm_ofs > 0;
}
Пример #7
0
fz_stream *
pdf_open_image_stream(pdf_document *xref, int num, int gen, int orig_num, int orig_gen, pdf_image_params *params)
{
	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 && x->stm_buf == NULL)
		fz_throw(xref->ctx, "object is not a stream");

	return pdf_open_filter(xref->file, xref, x->obj, orig_num, orig_gen, x->stm_ofs, params);
}
Пример #8
0
fz_obj *
pdf_resolve_indirect(fz_obj *ref)
{
	if (fz_is_indirect(ref))
	{
		pdf_xref *xref = fz_get_indirect_xref(ref);
		int num = fz_to_num(ref);
		int gen = fz_to_gen(ref);
		if (xref)
		{
			fz_error error = pdf_cache_object(xref, num, gen);
			if (error)
			{
				fz_catch(error, "cannot load object (%d %d R) into cache", num, gen);
				return ref;
			}
			if (xref->table[num].obj)
				return xref->table[num].obj;
		}
	}
	return ref;
}
Пример #9
0
/*
 * 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;
}
Пример #10
0
/*
 * Open a stream for reading uncompressed data.
 * Put the opened file in xref->stream.
 * Using xref->file while a stream is open is a Bad idea.
 */
fz_error
pdf_open_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_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");
}