shithub: pdffs

ref: 51cd3bfceeb001872d4ff298180875c4229a3d68
dir: /eval.c/

View raw version
#include <u.h>
#include <libc.h>
#include <bio.h>
#include "pdf.h"

int
pdfeval(Pdf *pdf, Object *o)
{
	Object *d;
	Xref *x;
	int i;

	if(o == nil || o->type != Oindir)
		return 0;

	for(i = 0; i < pdf->nxref && pdf->xref[i].id != o->indir.id; i++);
	if(i >= pdf->nxref){
		werrstr("no object id %d in xref", o->indir.id);
		return -1;
	}
	x = &pdf->xref[i];

	if(Bseek(pdf->bio, x->off, 0) != x->off){
		werrstr("xref seek failed");
		return -1;
	}
	if((d = pdfobject(pdf, pdf->bio)) == nil)
		return -1;
	*o = *d;
	memset(d, 0, sizeof(*d));
	freeobject(d);

	return 0;
}