shithub: pdffs

ref: ef6cdd0d40612067504d1587aa4e64206fe1ea8a
dir: pdffs/pdf.h

View raw version
enum {
	Obool,   /* 7.3.2 */
	Onum,    /* 7.3.3 */
	Ostr,    /* 7.3.4 */
	Oname,   /* 7.3.5 */
	Oarray,  /* 7.3.6 */
	Odict,   /* 7.3.7 */
	Ostream, /* 7.3.8 */
	Onull,   /* 7.3.9 */
	Oindir,  /* 7.3.10 */
};

typedef struct KeyValue KeyValue;
typedef struct Object Object;
typedef struct Pdf Pdf;
typedef struct Xref Xref;
typedef struct Stream Stream;

struct Object {
	int type;
	union {
		int bool;
		double num;
		struct {
			int len;
			char str[1];
		};
		char name[1];

		struct {
			u32int id;
			u16int gen;
		}indir;

		struct {
			KeyValue *kv;
			int nkv;
		}dict;

		struct {
			Object **e;
			int ne;
		}array;

		struct {
			KeyValue *kv;
			int nkv;
			u32int length; /* packed */
			u32int offset;
		}stream;
	};
};

struct KeyValue {
	char *key;
	Object *value;
};

struct Pdf {
	void *bio;
	Xref *xref;
	int nxref; /* 7.5.4 xref subsection number of objects */

	Object *root; /* 7.7.2 root object */
	Object *info; /* 14.3.3 info dictionary */
};

struct Xref {
	u32int id;
	u32int off;
	u16int gen;
};

struct Stream {
	Biobuf;
	Object *o;
	u32int offset;
};

Pdf *pdfopen(int fd);
void pdfclose(Pdf *pdf);

Object *pdfobj(Pdf *pdf, void *b);
void pdfobjfree(Object *o);

/*
 * If the object is indirect, resolve it. Operation is not recursive, ie
 * values of a dictionary won't be resolved automatically.
 */
int pdfeval(Pdf *pdf, Object *o);

int isws(int c);
int isdelim(int c);

Object *pdfdictget(Object *o, char *name);

Stream *streamopen(Pdf *pdf, Object *o);
void streamclose(Stream *s);