void
fz_grow_buffer(fz_context *ctx, fz_buffer *buf)
{
	int newsize = (buf->cap * 3) / 2;
	if (newsize == 0)
		newsize = 256;
	fz_resize_buffer(ctx, buf, newsize);
}
static void
fz_ensure_buffer(fz_context *ctx, fz_buffer *buf, int min)
{
	int newsize = buf->cap;
	while (newsize < min)
	{
		newsize = (newsize * 3) / 2;
	}
	fz_resize_buffer(ctx, buf, newsize);
}
fz_buffer *
fz_keep_buffer(fz_context *ctx, fz_buffer *buf)
{
	if (buf)
	{
		if (buf->refs == 1 && buf->cap > buf->len+1)
			fz_resize_buffer(ctx, buf, buf->len);
		buf->refs ++;
	}

	return buf;
}
Beispiel #4
0
static int stream_deflate(pdf_document *xref,fz_context *ctx,int pageref,int pagegen,
                          int *length)

    {
    fz_buffer *strbuf;
    int n;
    unsigned char *p;
#ifdef HAVE_Z_LIB
    char tempfile[512];
    gzFile gz;
    FILE *f;
    int nw;
#endif

    strbuf=pdf_load_stream(xref,pageref,pagegen);
    n=fz_buffer_storage(ctx,strbuf,&p);
#ifdef HAVE_Z_LIB
    wfile_abstmpnam(tempfile);
    gz=gzopen(tempfile,"sab7");
    gzwrite(gz,p,n);
    gzclose(gz);
    nw=wfile_size(tempfile);
    fz_resize_buffer(ctx,strbuf,nw+1);
    fz_buffer_storage(ctx,strbuf,&p);
    f=fopen(tempfile,"rb");
    if (f==NULL || fread(p,1,nw,f)<nw)
        aprintf(ANSI_RED "** wmupdf: Error writing compressed stream to PDF file! **\n" ANSI_NORMAL);
    if (f!=NULL)
        fclose(f);
    remove(tempfile);
    p[nw]='\n';
    strbuf->len=nw+1;
    pdf_update_stream(xref,pageref,strbuf);
    fz_drop_buffer(ctx,strbuf);
/*
printf("    After drop, xref->table[%d].stm_buf=%p, refs=%d\n",pageref,xref->table[pageref].stm_buf,
                                                  xref->table[pageref].stm_buf->refs);
*/
    (*length)=nw;
    return(1);
#else
    fz_drop_buffer(ctx,strbuf);
    (*length)=n;
    return(0);
#endif
    }
Beispiel #5
0
static void
pdf_prepend_ap_background(fz_buffer *content, pdf_xref *xref, fz_obj *obj)
{
	fz_context *ctx = xref->ctx;
	pdf_xobject *form;
	int i;
	fz_obj *ap = pdf_get_ap_stream(xref, obj);
	if (!ap)
		return;
	if (pdf_load_xobject(&form, xref, ap) != fz_okay)
		return;

	for (i = 0; i < form->contents->len - 3 && memcmp(form->contents->data + i, "/Tx", 3) != 0; i++);
	if (i == form->contents->len - 3)
		i = form->contents->len;
	if (content->cap < content->len + i)
		fz_resize_buffer(ctx, content, content->len + i);
	memcpy(content->data + content->len, form->contents->data, i);
	content->len += i;

	pdf_drop_xobject(ctx, form);
}
void
fz_trim_buffer(fz_context *ctx, fz_buffer *buf)
{
	if (buf->cap > buf->len+1)
		fz_resize_buffer(ctx, buf, buf->len);
}
void
fz_grow_buffer(fz_buffer *buf)
{
	fz_resize_buffer(buf, (buf->cap * 3) / 2);
}
void
fz_grow_buffer(fz_context *ctx, fz_buffer *buf)
{
	fz_resize_buffer(ctx, buf, (buf->cap * 3) / 2);
}