shithub: pdffs

ref: f8f7ffe655e3a6439adf0614d0232e7520757566
dir: /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;

struct Object {
	int type;
	union {
		int bool;
		double num;
		char *str;
		char *name;

		struct {
			int id;
			int gen;
		}indir;

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

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

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

	u32int root; /* 7.5.5 root object */
	u32int info; /* 7.5.5 info dictionary */
};

struct Xref {
	u32int id;
	u32int off;
};

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

Object *pdfobject(char *p, char **e, int len);
void freeobject(Object *o);

/*
 * 7.3.4 String Objects
 *
 * Rewrites the string in place with null termination and returns the
 * length in bytes, without the null terminator.
 * Returns < 0 if parsing failed.
 * (*e) is advanced to the position after the string pointed by (p).
 */
int pdfstring(char *p, char **e, int len);

/*
 * 7.3.5 Name Objects
 *
 * Works the same way as pdfstring, but for name objects.
 */
int pdfname(char *p, char **e, int len);

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