示例#1
0
fz_stream *
fz_open_resized_dctd(fz_stream *chain, int color_transform, int factor)
{
	fz_context *ctx = chain->ctx;
	fz_dctd *state = NULL;

	fz_var(state);

	fz_try(ctx)
	{
		state = fz_malloc_struct(chain->ctx, fz_dctd);
		state->ctx = ctx;
		state->chain = chain;
		state->color_transform = color_transform;
		state->init = 0;
		state->factor = factor;
	}
	fz_catch(ctx)
	{
		fz_free(ctx, state);
		fz_close(chain);
		fz_rethrow(ctx);
	}

	return fz_new_stream(ctx, state, read_dctd, close_dctd);
}
示例#2
0
fz_stream *
fz_open_flated(fz_stream *chain, int window_bits)
{
	fz_flate *state = NULL;
	int code = Z_OK;
	fz_context *ctx = chain->ctx;

	fz_var(code);
	fz_var(state);

	fz_try(ctx)
	{
		state = fz_malloc_struct(ctx, fz_flate);
		state->chain = chain;

		state->z.zalloc = zalloc;
		state->z.zfree = zfree;
		state->z.opaque = ctx;
		state->z.next_in = NULL;
		state->z.avail_in = 0;

		code = inflateInit2(&state->z, window_bits);
		if (code != Z_OK)
			fz_throw(ctx, FZ_ERROR_GENERIC, "zlib error: inflateInit: %s", state->z.msg);
	}
	fz_catch(ctx)
	{
		if (state && code == Z_OK)
			inflateEnd(&state->z);
		fz_free(ctx, state);
		fz_close(chain);
		fz_rethrow(ctx);
	}
	return fz_new_stream(ctx, state, next_flated, close_flated, rebind_flated);
}
示例#3
0
/* Default: color_transform = -1 (unset), l2factor = 0, jpegtables = NULL */
fz_stream *
fz_open_dctd(fz_stream *chain, int color_transform, int l2factor, fz_stream *jpegtables)
{
	fz_context *ctx = chain->ctx;
	fz_dctd *state = NULL;

	fz_var(state);

	fz_try(ctx)
	{
		state = fz_malloc_struct(chain->ctx, fz_dctd);
		state->ctx = ctx;
		state->chain = chain;
		state->jpegtables = jpegtables;
		state->curr_stm = chain;
		state->color_transform = color_transform;
		state->init = 0;
		state->l2factor = l2factor;
	}
	fz_catch(ctx)
	{
		fz_free(ctx, state);
		fz_close(chain);
		fz_close(jpegtables);
		fz_rethrow(ctx);
	}

	return fz_new_stream(ctx, state, read_dctd, close_dctd);
}
示例#4
0
fz_stream *
fz_open_leecher(fz_context *ctx, fz_stream *chain, fz_buffer *buffer)
{
	fz_leech *state = fz_malloc_struct(ctx, fz_leech);
	state->chain = fz_keep_stream(ctx, chain);
	state->buffer = fz_keep_buffer(ctx, buffer);
	return fz_new_stream(ctx, state, next_leech, close_leech);
}
示例#5
0
/* Default: early_change = 1 */
fz_stream *
fz_open_lzwd(fz_context *ctx, fz_stream *chain, int early_change, int min_bits, int reverse_bits, int old_tiff)
{
	fz_lzwd *lzw = NULL;
	int i;

	fz_var(lzw);

	fz_try(ctx)
	{
		if (min_bits > MAX_BITS)
		{
			fz_warn(ctx, "out of range initial lzw code size");
			min_bits = MAX_BITS;
		}

		lzw = fz_malloc_struct(ctx, fz_lzwd);
		lzw->chain = chain;
		lzw->eod = 0;
		lzw->early_change = early_change;
		lzw->reverse_bits = reverse_bits;
		lzw->old_tiff = old_tiff;
		lzw->min_bits = min_bits;
		lzw->code_bits = lzw->min_bits;
		lzw->code = -1;
		lzw->next_code = LZW_FIRST(lzw);
		lzw->old_code = -1;
		lzw->rp = lzw->bp;
		lzw->wp = lzw->bp;

		for (i = 0; i < LZW_CLEAR(lzw); i++)
		{
			lzw->table[i].value = i;
			lzw->table[i].first_char = i;
			lzw->table[i].length = 1;
			lzw->table[i].prev = -1;
		}

		for (i = LZW_CLEAR(lzw); i < NUM_CODES; i++)
		{
			lzw->table[i].value = 0;
			lzw->table[i].first_char = 0;
			lzw->table[i].length = 0;
			lzw->table[i].prev = -1;
		}
	}
	fz_catch(ctx)
	{
		fz_free(ctx, lzw);
		fz_drop_stream(ctx, chain);
		fz_rethrow(ctx);
	}

	return fz_new_stream(ctx, lzw, next_lzwd, close_lzwd);
}
示例#6
0
static fz_stream *
fz_open_file_ptr(fz_context *ctx, FILE *file)
{
	fz_stream *stm;
	fz_file_stream *state = fz_malloc_struct(ctx, fz_file_stream);
	state->file = file;

	stm = fz_new_stream(ctx, state, next_file, drop_file);
	stm->seek = seek_file;

	return stm;
}
示例#7
0
fz_stream *
fz_open_concat(fz_context *ctx, int len, int pad)
{
	struct concat_filter *state;

	state = fz_calloc(ctx, 1, sizeof(struct concat_filter) + (len-1)*sizeof(fz_stream *));
	state->max = len;
	state->count = 0;
	state->current = 0;
	state->pad = pad;
	state->ws = 0; /* We never send padding byte at the start */

	return fz_new_stream(ctx, state, read_concat, close_concat);
}
示例#8
0
fz_stream *
fz_open_concat(fz_context *ctx, int len, int pad)
{
	struct concat_filter *state;

	state = fz_calloc(ctx, 1, sizeof(struct concat_filter) + (len-1)*sizeof(fz_stream *));
	state->max = len;
	state->count = 0;
	state->current = 0;
	state->pad = pad;
	state->ws_buf = 32;

	return fz_new_stream(ctx, state, next_concat, close_concat, rebind_concat);
}
示例#9
0
fz_stream *
fz_open_memory(fz_context *ctx, unsigned char *data, size_t len)
{
	fz_stream *stm;

	stm = fz_new_stream(ctx, NULL, next_buffer, close_buffer);
	stm->seek = seek_buffer;

	stm->rp = data;
	stm->wp = data + len;

	stm->pos = (fz_off_t)len;

	return stm;
}
示例#10
0
/*
	Open a block of memory as a stream.

	data: Pointer to start of data block. Ownership of the data block is
	NOT passed in.

	len: Number of bytes in data block.

	Returns pointer to newly created stream. May throw exceptions on
	failure to allocate.
*/
fz_stream *
fz_open_memory(fz_context *ctx, const unsigned char *data, size_t len)
{
	fz_stream *stm;

	stm = fz_new_stream(ctx, NULL, next_buffer, NULL);
	stm->seek = seek_buffer;

	stm->rp = (unsigned char *)data;
	stm->wp = (unsigned char *)data + len;

	stm->pos = (int64_t)len;

	return stm;
}
示例#11
0
/* Default: early_change = 1 */
fz_stream *
fz_open_lzwd(fz_stream *chain, int early_change)
{
	fz_context *ctx = chain->ctx;
	fz_lzwd *lzw = NULL;
	int i;

	fz_var(lzw);

	fz_try(ctx)
	{
		lzw = fz_malloc_struct(ctx, fz_lzwd);
		lzw->chain = chain;
		lzw->eod = 0;
		lzw->early_change = early_change;

		for (i = 0; i < 256; i++)
		{
			lzw->table[i].value = i;
			lzw->table[i].first_char = i;
			lzw->table[i].length = 1;
			lzw->table[i].prev = -1;
		}

		for (i = 256; i < NUM_CODES; i++)
		{
			lzw->table[i].value = 0;
			lzw->table[i].first_char = 0;
			lzw->table[i].length = 0;
			lzw->table[i].prev = -1;
		}

		lzw->code_bits = MIN_BITS;
		lzw->code = -1;
		lzw->next_code = LZW_FIRST;
		lzw->old_code = -1;
		lzw->rp = lzw->bp;
		lzw->wp = lzw->bp;
	}
	fz_catch(ctx)
	{
		fz_free(ctx, lzw);
		fz_close(chain);
		fz_rethrow(ctx);
	}

	return fz_new_stream(ctx, lzw, read_lzwd, close_lzwd);
}
示例#12
0
/*
	Open a buffer as a stream.

	buf: The buffer to open. Ownership of the buffer is NOT passed in
	(this function takes its own reference).

	Returns pointer to newly created stream. May throw exceptions on
	failure to allocate.
*/
fz_stream *
fz_open_buffer(fz_context *ctx, fz_buffer *buf)
{
	fz_stream *stm;

	fz_keep_buffer(ctx, buf);
	stm = fz_new_stream(ctx, buf, next_buffer, drop_buffer);
	stm->seek = seek_buffer;

	stm->rp = buf->data;
	stm->wp = buf->data + buf->len;

	stm->pos = (int64_t)buf->len;

	return stm;
}
示例#13
0
fz_stream *
fz_open_buffer(fz_context *ctx, fz_buffer *buf)
{
	fz_stream *stm;

	fz_keep_buffer(ctx, buf);
	stm = fz_new_stream(ctx, buf, next_buffer, close_buffer, NULL);
	stm->seek = seek_buffer;
	stm->reopen = reopen_buffer;

	stm->rp = buf->data;
	stm->wp = buf->data + buf->len;

	stm->pos = buf->len;

	return stm;
}
示例#14
0
fz_stream *
fz_open_memory(fz_context *ctx, unsigned char *data, int len)
{
	fz_stream *stm;

	stm = fz_new_stream(ctx, NULL, read_buffer, close_buffer);
	stm->seek = seek_buffer;

	stm->bp = data;
	stm->rp = data;
	stm->wp = data + len;
	stm->ep = data + len;

	stm->pos = len;

	return stm;
}
示例#15
0
fz_stream *
fz_open_dctd(fz_stream *chain, fz_obj *params)
{
	fz_dctd *state;
	fz_obj *obj;

	state = fz_malloc(chain->ctx, sizeof(fz_dctd));
	memset(state, 0, sizeof(fz_dctd));
	state->chain = chain;
	state->color_transform = -1; /* unset */
	state->init = 0;

	obj = fz_dict_gets(chain->ctx, params, "ColorTransform");
	if (obj)
		state->color_transform = fz_to_int(chain->ctx, obj);

	return fz_new_stream(chain->ctx, state, read_dctd, close_dctd);
}
示例#16
0
fz_stream *
fz_open_jbig2d(fz_stream *chain, fz_buffer *globals)
{
	fz_jbig2d *state = NULL;
	fz_context *ctx = chain->ctx;

	//fz_var(state);

	try
	{
		state = (fz_jbig2d*)fz_malloc_struct(chain->ctx, fz_jbig2d);
		state->ctx = NULL;
		state->gctx = NULL;
		state->chain = chain;
		state->ctx = jbig2_ctx_new(NULL, JBIG2_OPTIONS_EMBEDDED, NULL, NULL, NULL);
		state->page = NULL;
		state->idx = 0;

		if (globals)
		{
			jbig2_data_in(state->ctx, globals->data, globals->len);
			state->gctx = jbig2_make_global_ctx(state->ctx);
			state->ctx = jbig2_ctx_new(NULL, JBIG2_OPTIONS_EMBEDDED, state->gctx, NULL, NULL);
		}
	}
	catch(...)
	{
		if (state)
		{
			if (state->gctx)
				jbig2_global_ctx_free(state->gctx);
			if (state->ctx)
				jbig2_ctx_free(state->ctx);
		}
		fz_drop_buffer(ctx, globals);
		fz_free(ctx, state);
		fz_close(chain);
		throw("error");
	}
	fz_drop_buffer(ctx, globals);

	return fz_new_stream(ctx, state, read_jbig2d, close_jbig2d);
}
示例#17
0
fz_stream *
fz_open_ahxd(fz_stream *chain)
{
	fz_ahxd *state;
	fz_context *ctx = chain->ctx;

	fz_try(ctx)
	{
		state = fz_malloc_struct(ctx, fz_ahxd);
		state->chain = chain;
		state->eod = 0;
	}
	fz_catch(ctx)
	{
		fz_close(chain);
		fz_rethrow(ctx);
	}

	return fz_new_stream(ctx, state, read_ahxd, close_ahxd);
}
示例#18
0
fz_stream *
fz_open_null(fz_stream *chain, int len)
{
	struct null_filter *state;
	fz_context *ctx = chain->ctx;

	fz_try(ctx)
	{
		state = fz_malloc_struct(ctx, struct null_filter);
		state->chain = chain;
		state->remain = len;
	}
	fz_catch(ctx)
	{
		fz_close(chain);
		fz_rethrow(ctx);
	}

	return fz_new_stream(ctx, state, read_null, close_null);
}
示例#19
0
fz_stream *
fz_open_ahxd(fz_stream *chain)
{
	fz_ahxd *state;
	fz_context *ctx = chain->ctx;

	try
	{
		state = (fz_ahxd*)fz_malloc_struct(ctx, fz_ahxd);
		state->chain = chain;
		state->eod = 0;
	}
	catch(...)
	{
		fz_close(chain);
		throw(21);
	}

	return fz_new_stream(ctx, state, read_ahxd, close_ahxd);
}
示例#20
0
fz_stream *
fz_open_file_ptr(fz_context *ctx, FILE *file)
{
	fz_stream *stm;
	fz_file_stream *state = fz_malloc_struct(ctx, fz_file_stream);
	state->file = file;

	fz_try(ctx)
	{
		stm = fz_new_stream(ctx, state, next_file, close_file);
	}
	fz_catch(ctx)
	{
		fz_free(ctx, state);
		fz_rethrow(ctx);
	}
	stm->seek = seek_file;

	return stm;
}
示例#21
0
fz_stream *
fz_open_jbig2d(fz_stream *chain, fz_buffer *globals)
{
	fz_jbig2d *state;

	state = fz_malloc(sizeof(fz_jbig2d));
	state->chain = chain;
	state->ctx = jbig2_ctx_new(NULL, JBIG2_OPTIONS_EMBEDDED, NULL, NULL, NULL);
	state->gctx = NULL;
	state->page = NULL;
	state->idx = 0;

	if (globals)
	{
		jbig2_data_in(state->ctx, globals->data, globals->len);
		state->gctx = jbig2_make_global_ctx(state->ctx);
		state->ctx = jbig2_ctx_new(NULL, JBIG2_OPTIONS_EMBEDDED, state->gctx, NULL, NULL);
	}

	return fz_new_stream(state, read_jbig2d, close_jbig2d);
}
示例#22
0
fz_stream *
fz_open_fd(fz_context *ctx, int fd)
{
	fz_stream *stm;
	fz_file_stream *state = fz_malloc_struct(ctx, fz_file_stream);
	state->file = fd;

	fz_try(ctx)
	{
		stm = fz_new_stream(ctx, state, next_file, close_file, NULL);
	}
	fz_catch(ctx)
	{
		fz_free(ctx, state);
		fz_rethrow(ctx);
	}
	stm->seek = seek_file;
	/* SumatraPDF: TODO: can't reliably clone a file descriptor */

	return stm;
}
示例#23
0
fz_stream *
fz_open_leecher(fz_context *ctx, fz_stream *chain, fz_buffer *buffer)
{
	fz_leech *state = NULL;

	fz_var(state);

	fz_try(ctx)
	{
		state = fz_malloc_struct(ctx, fz_leech);
		state->chain = chain;
		state->buffer = buffer;
	}
	fz_catch(ctx)
	{
		fz_free(ctx, state);
		fz_drop_stream(ctx, chain);
		fz_rethrow(ctx);
	}
	return fz_new_stream(ctx, state, next_leech, close_leech);
}
示例#24
0
static fz_stream *
fz_open_file_ptr_progressive(fz_context *ctx, FILE *file, int bps)
{
	fz_stream *stm;
	prog_state *state;

	state = fz_malloc_struct(ctx, prog_state);
	state->file = file;
	state->bps = bps;
	state->start_time = clock();
	state->available = 0;

	fseek(state->file, 0, SEEK_END);
	state->length = ftell(state->file);
	fseek(state->file, 0, SEEK_SET);

	stm = fz_new_stream(ctx, state, next_prog, close_prog);
	stm->seek = seek_prog;
	stm->meta = meta_prog;

	return stm;
}
示例#25
0
fz_stream *
fz_open_fd(fz_context *ctx, int fd)
{
	fz_stream *stm;
	int *state;

	state = fz_malloc_struct(ctx, int);
	*state = fd;

	fz_try(ctx)
	{
		stm = fz_new_stream(ctx, state, read_file, close_file);
	}
	fz_catch(ctx)
	{
		fz_free(ctx, state);
		fz_rethrow(ctx);
	}
	stm->seek = seek_file;

	return stm;
}
示例#26
0
fz_stream *
fz_open_null(fz_stream *chain, int len, int offset)
{
	struct null_filter *state;
	fz_context *ctx = chain->ctx;

	if (len < 0)
		len = 0;
	fz_try(ctx)
	{
		state = fz_malloc_struct(ctx, struct null_filter);
		state->chain = chain;
		state->remain = len;
		state->offset = offset;
	}
	fz_catch(ctx)
	{
		fz_close(chain);
		fz_rethrow(ctx);
	}

	return fz_new_stream(ctx, state, next_null, close_null, rebind_null);
}
示例#27
0
fz_stream *
fz_open_sgilog16(fz_context *ctx, fz_stream *chain, int w)
{
	fz_sgilog16 *state = fz_malloc_struct(ctx, fz_sgilog16);

	fz_try(ctx)
	{
		state->run = 0;
		state->n = 0;
		state->c = 0;
		state->w = w;
		state->temp = fz_malloc(ctx, w * sizeof(uint16_t));
		state->chain = fz_keep_stream(ctx, chain);
	}
	fz_catch(ctx)
	{
		fz_free(ctx, state->temp);
		fz_free(ctx, state);
		fz_rethrow(ctx);
	}

	return fz_new_stream(ctx, state, next_sgilog16, close_sgilog16);
}
示例#28
0
	fz_close_document(mu_doc);
	page_cache->Empty(mu_ctx);
	fz_free_context(mu_ctx);

	mu_ctx = NULL;
	mu_doc = NULL;
	mu_outline = NULL;
	delete page_cache;
	page_cache = NULL;
}

/* Set up the stream access */
status_t muctx::InitializeStream(IRandomAccessStream^ readStream, char *ext)
{
	win_stream.stream = readStream;
	fz_stream *mu_stream = fz_new_stream(mu_ctx, 0, win_read_file, win_close_file);
	mu_stream->seek = win_seek_file;
	mu_stream->state =  reinterpret_cast <void*> (&win_stream);

	/* Now lets see if we can open the file */
	fz_try(mu_ctx)
	{
		mu_doc = fz_open_document_with_stream(mu_ctx, ext, mu_stream);
	}
	fz_always(mu_ctx)
	{
		fz_close(mu_stream);
	}
	fz_catch(mu_ctx)
	{
		return E_FAILURE;
示例#29
0
static int _pdf_doc_load(struct _pdf_doc *self, mume_stream_t *stm)
{
    fz_error error;
    fz_stream *fzstm;
    fz_rect *mbox;
    fz_obj *page_obj, *box_obj;
    int i, c;

    _pdf_doc_clear(self);

    fzstm = fz_new_stream(stm, _pdf_stream_read, _pdf_stream_close);
    mume_stream_reference(stm);
    fzstm->seek = _pdf_stream_seek;
    error = pdf_open_xref_with_stream(&self->xref, fzstm, NULL);
    fz_close(fzstm);
    if (error) {
        mume_error(("Read xref failed\n", error));
        return 0;
    }

    assert(!pdf_needs_password(self->xref));

    /* Load meta information. */
    error = pdf_load_page_tree(self->xref);
    if (error) {
        mume_error(("Cannot load page tree\n"));
        return 0;
    }

    c = pdf_count_pages(self->xref);
    self->glyph_cache = fz_new_glyph_cache();
    self->pages = calloc_abort(c, sizeof(pdf_page*));
    self->disps = calloc_abort(c, sizeof(fz_display_list*));
    self->media_boxes = malloc_abort(c * sizeof(fz_rect));
    self->page_rotates = malloc_abort(c * sizeof(int));

    /* Extract each pages' media box and rotation. */
    for (i = 0; i < c; ++i) {
        mbox = self->media_boxes + i;
        page_obj = self->xref->page_objs[i];
        if (!page_obj) {
            *mbox = fz_empty_rect;
            continue;
        }

        box_obj = fz_dict_gets(page_obj, "MediaBox");
        *mbox = pdf_to_rect(box_obj);
        if (fz_is_empty_rect(*mbox)) {
            fz_warn("Cannot find page bounds, guessing page bounds.");
            mbox->x1 = 612;
            mbox->y1 = 792;
        }

        box_obj = fz_dict_gets(page_obj, "CropBox");
        if (fz_is_array(box_obj))
            *mbox = fz_intersect_rect(*mbox, pdf_to_rect(box_obj));

        self->page_rotates[i] = fz_to_int(
            fz_dict_gets(page_obj, "Rotate"));

        if (self->page_rotates[i] % 90)
            self->page_rotates[i] = 0;
    }

    return 1;
}
示例#30
0
	curr_pos = Stream->Position;
	stm->pos = n;
	stm->wp = stm->rp;
}

static void win_close_file(fz_context *ctx, void *state)
{
	win_stream_struct *win_stream = reinterpret_cast <win_stream_struct*> (state);
	IRandomAccessStream^ stream = win_stream->stream;
	delete stream;
}

status_t muctx::InitializeStream(IRandomAccessStream^ readStream, char *ext)
{
	win_stream.stream = readStream;
	fz_stream *mu_stream = fz_new_stream(mu_ctx, 0, win_next_file, win_close_file, NULL);
	mu_stream->seek = win_seek_file;
	mu_stream->state = reinterpret_cast <void*> (&win_stream);

	/* Now lets see if we can open the file */
	fz_try(mu_ctx)
	{
		mu_doc = fz_open_document_with_stream(mu_ctx, ext, mu_stream);
	}
	fz_always(mu_ctx)
	{
		fz_close(mu_stream);
	}
	fz_catch(mu_ctx)
	{
		return E_FAILURE;