shithub: pdffs

ref: 1d93500ddcda77cd265d492c6c9094c0f5c7488f
dir: pdffs/eval.c

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

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

	if(o == nil)
		return &null;
	if(o->type != Oindir)
		return o;

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

	if(Bseek(o->pdf->bio, x->off, 0) != x->off){
		werrstr("xref seek failed");
		return &null;
	}
	if((d = pdfobj(o->pdf, o->pdf->bio)) == nil)
		return &null;

	pdfobjfree(o);

	return d;
}