From cefd16bc7a557ccaf0bb66d504d7a8cbc9ec43d3 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 7 Jun 2005 15:09:48 +0200 Subject: more shuffling --- include/fitz-base.h | 13 ++-- include/fitz-draw.h | 4 +- include/fitz-stream.h | 10 +-- include/fitz-world.h | 16 ++-- include/fitz/base_cpudep.h | 26 +++++++ include/fitz/base_geom.h | 65 ++++++++++++++++ include/fitz/base_hash.h | 20 +++++ include/fitz/base_math.h | 29 +++++++ include/fitz/base_pixmap.h | 26 +++++++ include/fitz/base_runtime.h | 80 +++++++++++++++++++ include/fitz/base_sysdep.h | 78 +++++++++++++++++++ include/fitz/buffer.h | 41 ---------- include/fitz/colorspace.h | 40 ---------- include/fitz/cpudep.h | 26 ------- include/fitz/crypt.h | 39 ---------- include/fitz/draw_misc.h | 83 ++++++++++++++++++++ include/fitz/draw_path.h | 46 +++++++++++ include/fitz/filter.h | 95 ----------------------- include/fitz/font.h | 68 ---------------- include/fitz/geometry.h | 65 ---------------- include/fitz/hash.h | 20 ----- include/fitz/image.h | 16 ---- include/fitz/math.h | 29 ------- include/fitz/object.h | 132 -------------------------------- include/fitz/path.h | 83 -------------------- include/fitz/pathscan.h | 46 ----------- include/fitz/pixmap.h | 25 ------ include/fitz/render.h | 83 -------------------- include/fitz/runtime.h | 80 ------------------- include/fitz/shade.h | 29 ------- include/fitz/stm_buffer.h | 41 ++++++++++ include/fitz/stm_crypt.h | 39 ++++++++++ include/fitz/stm_filter.h | 95 +++++++++++++++++++++++ include/fitz/stm_object.h | 132 ++++++++++++++++++++++++++++++++ include/fitz/stm_stream.h | 103 +++++++++++++++++++++++++ include/fitz/stream.h | 103 ------------------------- include/fitz/sysdep.h | 78 ------------------- include/fitz/text.h | 44 ----------- include/fitz/tree.h | 183 -------------------------------------------- include/fitz/wld_color.h | 40 ++++++++++ include/fitz/wld_font.h | 68 ++++++++++++++++ include/fitz/wld_image.h | 16 ++++ include/fitz/wld_path.h | 83 ++++++++++++++++++++ include/fitz/wld_shade.h | 29 +++++++ include/fitz/wld_text.h | 44 +++++++++++ include/fitz/wld_tree.h | 183 ++++++++++++++++++++++++++++++++++++++++++++ 46 files changed, 1347 insertions(+), 1347 deletions(-) create mode 100644 include/fitz/base_cpudep.h create mode 100644 include/fitz/base_geom.h create mode 100644 include/fitz/base_hash.h create mode 100644 include/fitz/base_math.h create mode 100644 include/fitz/base_pixmap.h create mode 100644 include/fitz/base_runtime.h create mode 100644 include/fitz/base_sysdep.h delete mode 100644 include/fitz/buffer.h delete mode 100644 include/fitz/colorspace.h delete mode 100644 include/fitz/cpudep.h delete mode 100644 include/fitz/crypt.h create mode 100644 include/fitz/draw_misc.h create mode 100644 include/fitz/draw_path.h delete mode 100644 include/fitz/filter.h delete mode 100644 include/fitz/font.h delete mode 100644 include/fitz/geometry.h delete mode 100644 include/fitz/hash.h delete mode 100644 include/fitz/image.h delete mode 100644 include/fitz/math.h delete mode 100644 include/fitz/object.h delete mode 100644 include/fitz/path.h delete mode 100644 include/fitz/pathscan.h delete mode 100644 include/fitz/pixmap.h delete mode 100644 include/fitz/render.h delete mode 100644 include/fitz/runtime.h delete mode 100644 include/fitz/shade.h create mode 100644 include/fitz/stm_buffer.h create mode 100644 include/fitz/stm_crypt.h create mode 100644 include/fitz/stm_filter.h create mode 100644 include/fitz/stm_object.h create mode 100644 include/fitz/stm_stream.h delete mode 100644 include/fitz/stream.h delete mode 100644 include/fitz/sysdep.h delete mode 100644 include/fitz/text.h delete mode 100644 include/fitz/tree.h create mode 100644 include/fitz/wld_color.h create mode 100644 include/fitz/wld_font.h create mode 100644 include/fitz/wld_image.h create mode 100644 include/fitz/wld_path.h create mode 100644 include/fitz/wld_shade.h create mode 100644 include/fitz/wld_text.h create mode 100644 include/fitz/wld_tree.h diff --git a/include/fitz-base.h b/include/fitz-base.h index 0f6e8ba6..8c13cd5e 100644 --- a/include/fitz-base.h +++ b/include/fitz-base.h @@ -3,10 +3,11 @@ #endif #define _FITZ_BASE_H_ -#include "fitz/sysdep.h" -#include "fitz/cpudep.h" -#include "fitz/runtime.h" -#include "fitz/math.h" -#include "fitz/geometry.h" -#include "fitz/hash.h" +#include "fitz/base_sysdep.h" +#include "fitz/base_cpudep.h" +#include "fitz/base_runtime.h" +#include "fitz/base_math.h" +#include "fitz/base_geom.h" +#include "fitz/base_hash.h" +#include "fitz/base_pixmap.h" diff --git a/include/fitz-draw.h b/include/fitz-draw.h index 9f25fe44..ceef524a 100644 --- a/include/fitz-draw.h +++ b/include/fitz-draw.h @@ -15,6 +15,6 @@ #error "fitz-world.h must be included before fitz-draw.h" #endif -#include "fitz/pathscan.h" -#include "fitz/render.h" +#include "fitz/draw_path.h" +#include "fitz/draw_misc.h" diff --git a/include/fitz-stream.h b/include/fitz-stream.h index 47454ce5..bd210f24 100644 --- a/include/fitz-stream.h +++ b/include/fitz-stream.h @@ -11,9 +11,9 @@ #error "fitz-base.h must be included before fitz-stream.h" #endif -#include "fitz/crypt.h" -#include "fitz/object.h" -#include "fitz/buffer.h" -#include "fitz/filter.h" -#include "fitz/stream.h" +#include "fitz/stm_crypt.h" +#include "fitz/stm_object.h" +#include "fitz/stm_buffer.h" +#include "fitz/stm_filter.h" +#include "fitz/stm_stream.h" diff --git a/include/fitz-world.h b/include/fitz-world.h index 0f1855f5..f810e07b 100644 --- a/include/fitz-world.h +++ b/include/fitz-world.h @@ -11,13 +11,11 @@ #error "fitz-base.h must be included before fitz-world.h" #endif -#include "fitz/font.h" -#include "fitz/pixmap.h" -#include "fitz/colorspace.h" -#include "fitz/image.h" -#include "fitz/shade.h" - -#include "fitz/tree.h" -#include "fitz/path.h" -#include "fitz/text.h" +#include "fitz/wld_font.h" +#include "fitz/wld_color.h" +#include "fitz/wld_image.h" +#include "fitz/wld_shade.h" +#include "fitz/wld_tree.h" +#include "fitz/wld_path.h" +#include "fitz/wld_text.h" diff --git a/include/fitz/base_cpudep.h b/include/fitz/base_cpudep.h new file mode 100644 index 00000000..261c3c79 --- /dev/null +++ b/include/fitz/base_cpudep.h @@ -0,0 +1,26 @@ +#if defined(ARCH_X86) || defined(ARCH_X86_64) +# define HAVE_CPUDEP +# define HAVE_MMX (1<<0) +# define HAVE_MMXEXT (1<<1) +# define HAVE_SSE (1<<2) +# define HAVE_SSE2 (1<<3) +# define HAVE_SSE3 (1<<4) +# define HAVE_3DNOW (1<<5) +# define HAVE_AMD64 (1<<6) + +#elif defined (ARCH_PPC) +# define HAVE_CPUDEP +# define HAVE_ALTIVEC (1<<7) + +#elif defined (ARCH_SPARC) +# define HAVE_CPUDEP +# define HAVE_VIS (1<<8) + +#endif + +/* call this before using fitz */ +extern void fz_cpudetect(); + +/* treat as constant! */ +extern unsigned fz_cpuflags; + diff --git a/include/fitz/base_geom.h b/include/fitz/base_geom.h new file mode 100644 index 00000000..13290007 --- /dev/null +++ b/include/fitz/base_geom.h @@ -0,0 +1,65 @@ +typedef struct fz_matrix_s fz_matrix; +typedef struct fz_point_s fz_point; +typedef struct fz_rect_s fz_rect; +typedef struct fz_ipoint_s fz_ipoint; +typedef struct fz_irect_s fz_irect; + +extern fz_rect fz_emptyrect; +extern fz_rect fz_infiniterect; + +#define fz_isemptyrect(r) ((r).x0 == (r).x1) +#define fz_isinfiniterect(r) ((r).x0 > (r).x1) + +/* + / a b 0 \ + | c d 0 | + \ e f 1 / +*/ +struct fz_matrix_s +{ + float a, b, c, d, e, f; +}; + +struct fz_point_s +{ + float x, y; +}; + +struct fz_rect_s +{ + float x0, y0; + float x1, y1; +}; + +struct fz_ipoint_s +{ + int x, y; +}; + +struct fz_irect_s +{ + int x0, y0; + int x1, y1; +}; + +void fz_invert3x3(float *dst, float *m); + +fz_matrix fz_concat(fz_matrix one, fz_matrix two); +fz_matrix fz_identity(void); +fz_matrix fz_scale(float sx, float sy); +fz_matrix fz_rotate(float theta); +fz_matrix fz_translate(float tx, float ty); +fz_matrix fz_invertmatrix(fz_matrix m); +int fz_isrectilinear(fz_matrix m); +float fz_matrixexpansion(fz_matrix m); + +fz_rect fz_intersectrects(fz_rect a, fz_rect b); +fz_rect fz_mergerects(fz_rect a, fz_rect b); + +fz_irect fz_roundrect(fz_rect r); +fz_irect fz_intersectirects(fz_irect a, fz_irect b); +fz_irect fz_mergeirects(fz_irect a, fz_irect b); + +fz_point fz_transformpoint(fz_matrix m, fz_point p); +fz_rect fz_transformaabb(fz_matrix m, fz_rect r); + diff --git a/include/fitz/base_hash.h b/include/fitz/base_hash.h new file mode 100644 index 00000000..5d2ec1b5 --- /dev/null +++ b/include/fitz/base_hash.h @@ -0,0 +1,20 @@ +/* + * Generic hash-table with fixed-length keys. + */ + +typedef struct fz_hashtable_s fz_hashtable; + +fz_error *fz_newhash(fz_hashtable **tablep, int initialsize, int keylen); +fz_error *fz_resizehash(fz_hashtable *table, int newsize); +void fz_debughash(fz_hashtable *table); +void fz_emptyhash(fz_hashtable *table); +void fz_drophash(fz_hashtable *table); + +void *fz_hashfind(fz_hashtable *table, void *key); +fz_error *fz_hashinsert(fz_hashtable *table, void *key, void *val); +fz_error *fz_hashremove(fz_hashtable *table, void *key); + +int fz_hashlen(fz_hashtable *table); +void *fz_hashgetkey(fz_hashtable *table, int idx); +void *fz_hashgetval(fz_hashtable *table, int idx); + diff --git a/include/fitz/base_math.h b/include/fitz/base_math.h new file mode 100644 index 00000000..4dee81fc --- /dev/null +++ b/include/fitz/base_math.h @@ -0,0 +1,29 @@ +/* multiply 8-bit fixpoint (0..1) so that 0*0==0 and 255*255==255 */ +#define fz_mul255(a,b) (((a) * ((b) + 1)) >> 8) +#define fz_floor(x) floor(x) +#define fz_ceil(x) ceil(x) + +/* divide and floor towards -inf */ +static inline int fz_idiv(int a, int b) +{ + return a < 0 ? (a - b + 1) / b : a / b; +} + +/* from python */ +static inline void fz_idivmod(int x, int y, int *d, int *m) +{ + int xdivy = x / y; + int xmody = x - xdivy * y; + /* If the signs of x and y differ, and the remainder is non-0, + * C89 doesn't define whether xdivy is now the floor or the + * ceiling of the infinitely precise quotient. We want the floor, + * and we have it iff the remainder's sign matches y's. + */ + if (xmody && ((y ^ xmody) < 0)) { + xmody += y; + xdivy --; + } + *d = xdivy; + *m = xmody; +} + diff --git a/include/fitz/base_pixmap.h b/include/fitz/base_pixmap.h new file mode 100644 index 00000000..9a0f2b43 --- /dev/null +++ b/include/fitz/base_pixmap.h @@ -0,0 +1,26 @@ +/* TODO: move this into draw module */ +/* +pixmaps have n components per pixel. the first is always alpha. +premultiplied alpha when rendering, but non-premultiplied for colorspace +conversions and rescaling. +*/ + +typedef struct fz_pixmap_s fz_pixmap; +typedef unsigned char fz_sample; + +struct fz_pixmap_s +{ + int x, y, w, h, n; + fz_sample *samples; +}; + +fz_error *fz_newpixmapwithrect(fz_pixmap **mapp, fz_irect bbox, int n); +fz_error *fz_newpixmap(fz_pixmap **mapp, int x, int y, int w, int h, int n); +fz_error *fz_newpixmapcopy(fz_pixmap **pixp, fz_pixmap *old); + +void fz_debugpixmap(fz_pixmap *map); +void fz_clearpixmap(fz_pixmap *map); +void fz_droppixmap(fz_pixmap *map); + +fz_error *fz_scalepixmap(fz_pixmap **dstp, fz_pixmap *src, int xdenom, int ydenom); + diff --git a/include/fitz/base_runtime.h b/include/fitz/base_runtime.h new file mode 100644 index 00000000..feeb7ffc --- /dev/null +++ b/include/fitz/base_runtime.h @@ -0,0 +1,80 @@ +#undef nil +#define nil ((void*)0) + +#undef offsetof +#define offsetof(s, m) (unsigned long)(&(((s*)0)->m)) + +#undef nelem +#define nelem(x) (sizeof(x)/sizeof((x)[0])) + +#undef ABS +#define ABS(x) ( (x) < 0 ? -(x) : (x) ) + +#undef MAX +#define MAX(a,b) ( (a) > (b) ? (a) : (b) ) + +#undef MIN +#define MIN(a,b) ( (a) < (b) ? (a) : (b) ) + +#undef CLAMP +#define CLAMP(x,a,b) ( (x) > (b) ? (b) : ( (x) < (a) ? (a) : (x) ) ) + +#define MAX4(a,b,c,d) MAX(MAX(a,b), MAX(c,d)) +#define MIN4(a,b,c,d) MIN(MIN(a,b), MIN(c,d)) + +#define STRIDE(n, bcp) (((bpc) * (n) + 7) / 8) + +/* plan9 stuff for utf-8 and path munging */ +int chartorune(int *rune, char *str); +int runetochar(char *str, int *rune); +int runelen(long c); +int runenlen(int *r, int nrune); +int fullrune(char *str, int n); +char *cleanname(char *name); + +typedef struct fz_error_s fz_error; + +struct fz_error_s +{ + int refs; + char msg[184]; + char file[32]; + char func[32]; + int line; +}; + +#define fz_outofmem (&fz_koutofmem) +extern fz_error fz_koutofmem; + +#ifdef WIN32 +#define fz_throw(...) fz_throw0(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__) +#elif HAVE_C99 +#define fz_throw(...) fz_throw0(__func__, __FILE__, __LINE__, __VA_ARGS__) +#else +#define fz_throw fz_throw1 +#endif +fz_error *fz_throw0(const char *func, const char *file, int line, char *fmt, ...); +fz_error *fz_throw1(char *fmt, ...); + +void fz_warn(char *fmt, ...); +void fz_abort(fz_error *eo); +void fz_droperror(fz_error *eo); + +typedef struct fz_memorycontext_s fz_memorycontext; + +struct fz_memorycontext_s +{ + void * (*malloc)(fz_memorycontext *, int); + void * (*realloc)(fz_memorycontext *, void *, int); + void (*free)(fz_memorycontext *, void *); +}; + +fz_memorycontext *fz_currentmemorycontext(void); +void fz_setmemorycontext(fz_memorycontext *memorycontext); + +void *fz_malloc(int n); +void *fz_realloc(void *p, int n); +void fz_free(void *p); + +char *fz_strdup(char *s); + diff --git a/include/fitz/base_sysdep.h b/include/fitz/base_sysdep.h new file mode 100644 index 00000000..4e8b1115 --- /dev/null +++ b/include/fitz/base_sysdep.h @@ -0,0 +1,78 @@ +/* + * Include the basic standard libc headers. + */ + +#include +#include +#include +#include + +#include /* INT_MIN, MAX ... */ +#include /* DBL_EPSILON */ +#include + +#include +#include /* O_RDONLY & co */ + +#ifdef HAVE_C99 +# define FZ_FLEX +#else +# define FZ_FLEX 1 +# define restrict +# define inline __inline__ +#endif + +#ifdef WIN32 +# define vsnprintf _vsnprintf +# include +#else +# include +#endif + +#ifndef va_copy +#define va_copy(a,b) (a) = (b) +#endif + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +/* + * Extras! Extras! Get them while they're hot! + */ + +/* not supposed to be here, but printf debugging sorta needs it */ +#include + +#ifdef NEED_MATH +#define M_E 2.71828182845904523536 +#define M_LOG2E 1.44269504088896340736 +#define M_LOG10E 0.434294481903251827651 +#define M_LN2 0.693147180559945309417 +#define M_LN10 2.30258509299404568402 +#define M_PI 3.14159265358979323846 +#define M_PI_2 1.57079632679489661923 +#define M_PI_4 0.785398163397448309616 +#define M_1_PI 0.318309886183790671538 +#define M_2_PI 0.636619772367581343076 +#define M_1_SQRTPI 0.564189583547756286948 +#define M_2_SQRTPI 1.12837916709551257390 +#define M_SQRT2 1.41421356237309504880 +#define M_SQRT_2 0.707106781186547524401 +#endif + +#ifdef NEED_STRLCPY +extern int strlcpy(char *dst, const char *src, int n); +extern int strlcat(char *dst, const char *src, int n); +#endif + +#ifdef NEED_STRSEP +extern char *strsep(char **stringp, const char *delim); +#endif + +#ifdef NEED_GETOPT +extern int getopt(int nargc, char * const * nargv, const char *ostr); +extern int opterr, optind, optopt; +extern char *optarg; +#endif + diff --git a/include/fitz/buffer.h b/include/fitz/buffer.h deleted file mode 100644 index 1a6f34ad..00000000 --- a/include/fitz/buffer.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Data buffers for streams and filters. - * - * bp is the pointer to the allocated memory - * rp is read-position (*in->rp++ to read data) - * wp is write-position (*out->wp++ to write data) - * ep is the sentinel - * - * Only the data between rp and wp is valid data. - * - * Writers set eof to true at the end. - * Readers look at eof. - * - * A buffer owns the memory it has allocated, unless ownsdata is false, - * in which case the creator of the buffer owns it. - */ - -typedef struct fz_buffer_s fz_buffer; - -#define FZ_BUFSIZE (8 * 1024) - -struct fz_buffer_s -{ - int refs; - int ownsdata; - unsigned char *bp; - unsigned char *rp; - unsigned char *wp; - unsigned char *ep; - int eof; -}; - -fz_error *fz_newbuffer(fz_buffer **bufp, int size); -fz_error *fz_newbufferwithmemory(fz_buffer **bufp, unsigned char *data, int size); - -fz_error *fz_rewindbuffer(fz_buffer *buf); -fz_error *fz_growbuffer(fz_buffer *buf); - -fz_buffer *fz_keepbuffer(fz_buffer *buf); -void fz_dropbuffer(fz_buffer *buf); - diff --git a/include/fitz/colorspace.h b/include/fitz/colorspace.h deleted file mode 100644 index f6fae48c..00000000 --- a/include/fitz/colorspace.h +++ /dev/null @@ -1,40 +0,0 @@ -typedef struct fz_colorspace_s fz_colorspace; -typedef struct fz_colorcube_s fz_colorcube; -typedef struct fz_colorcube1_s fz_colorcube1; -typedef struct fz_colorcube3_s fz_colorcube3; -typedef struct fz_colorcube4_s fz_colorcube4; - -enum { FZ_MAXCOLORS = 32 }; - -struct fz_colorspace_s -{ - int refs; - char name[16]; - int n; - void (*convpixmap)(fz_colorspace *ss, fz_pixmap *sp, fz_colorspace *ds, fz_pixmap *dp); - void (*convcolor)(fz_colorspace *ss, float *sv, fz_colorspace *ds, float *dv); - void (*toxyz)(fz_colorspace *, float *src, float *xyz); - void (*fromxyz)(fz_colorspace *, float *xyz, float *dst); - void (*drop)(fz_colorspace *); -}; - -struct fz_colorcube1_s { unsigned char v[17]; }; -struct fz_colorcube3_s { unsigned char v[17][17][17]; }; -struct fz_colorcube4_s { unsigned char v[17][17][17][17]; }; - -struct fz_colorcube_s -{ - fz_colorspace *src; - fz_colorspace *dst; - void **subcube; /* dst->n * colorcube(src->n) */ -}; - -fz_colorspace *fz_keepcolorspace(fz_colorspace *cs); -void fz_dropcolorspace(fz_colorspace *cs); - -void fz_convertcolor(fz_colorspace *srcs, float *srcv, fz_colorspace *dsts, float *dstv); -void fz_convertpixmap(fz_colorspace *srcs, fz_pixmap *srcv, fz_colorspace *dsts, fz_pixmap *dstv); - -void fz_stdconvcolor(fz_colorspace *srcs, float *srcv, fz_colorspace *dsts, float *dstv); -void fz_stdconvpixmap(fz_colorspace *srcs, fz_pixmap *srcv, fz_colorspace *dsts, fz_pixmap *dstv); - diff --git a/include/fitz/cpudep.h b/include/fitz/cpudep.h deleted file mode 100644 index 261c3c79..00000000 --- a/include/fitz/cpudep.h +++ /dev/null @@ -1,26 +0,0 @@ -#if defined(ARCH_X86) || defined(ARCH_X86_64) -# define HAVE_CPUDEP -# define HAVE_MMX (1<<0) -# define HAVE_MMXEXT (1<<1) -# define HAVE_SSE (1<<2) -# define HAVE_SSE2 (1<<3) -# define HAVE_SSE3 (1<<4) -# define HAVE_3DNOW (1<<5) -# define HAVE_AMD64 (1<<6) - -#elif defined (ARCH_PPC) -# define HAVE_CPUDEP -# define HAVE_ALTIVEC (1<<7) - -#elif defined (ARCH_SPARC) -# define HAVE_CPUDEP -# define HAVE_VIS (1<<8) - -#endif - -/* call this before using fitz */ -extern void fz_cpudetect(); - -/* treat as constant! */ -extern unsigned fz_cpuflags; - diff --git a/include/fitz/crypt.h b/include/fitz/crypt.h deleted file mode 100644 index 15191caa..00000000 --- a/include/fitz/crypt.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Basic crypto functions. - * Independent of the rest of fitz. - * For further encapsulation in filters, or not. - */ - -/* md5 digests */ - -typedef struct fz_md5_s fz_md5; - -struct fz_md5_s -{ - unsigned long state[4]; - unsigned long count[2]; - unsigned char buffer[64]; -}; - -void fz_md5init(fz_md5 *state); -void fz_md5update(fz_md5 *state, unsigned char *input, unsigned inlen); -void fz_md5final(fz_md5 *state, unsigned char digest[16]); - -/* arc4 crypto */ - -typedef struct fz_arc4_s fz_arc4; - -struct fz_arc4_s -{ - unsigned x; - unsigned y; - unsigned char state[256]; -}; - -void fz_arc4init(fz_arc4 *state, unsigned char *key, unsigned len); -unsigned char fz_arc4next(fz_arc4 *state); -void fz_arc4encrypt(fz_arc4 *state, unsigned char *dest, unsigned char *src, unsigned len); - -/* TODO: sha1 */ -/* TODO: aes */ - diff --git a/include/fitz/draw_misc.h b/include/fitz/draw_misc.h new file mode 100644 index 00000000..cb78b57c --- /dev/null +++ b/include/fitz/draw_misc.h @@ -0,0 +1,83 @@ +typedef struct fz_renderer_s fz_renderer; + +#define FZ_BYTE unsigned char + +#define FZ_PSRC \ + unsigned char *src, int srcw, int srch +#define FZ_PDST \ + unsigned char *dst0, int dstw +#define FZ_PCTM \ + int u0, int v0, int fa, int fb, int fc, int fd, int w0, int h + +/* + * Function pointers -- they can be replaced by cpu-optimized versions + */ + +extern void (*fz_duff_non)(FZ_BYTE*,int,int,FZ_BYTE*,int,int,int); +extern void (*fz_duff_nimcn)(FZ_BYTE*,int,int,FZ_BYTE*,int,int,FZ_BYTE*,int,int,int); +extern void (*fz_duff_nimon)(FZ_BYTE*,int,int,FZ_BYTE*,int,int,FZ_BYTE*,int,int,int); +extern void (*fz_duff_1o1)(FZ_BYTE*,int,FZ_BYTE*,int,int,int); +extern void (*fz_duff_4o4)(FZ_BYTE*,int,FZ_BYTE*,int,int,int); +extern void (*fz_duff_1i1c1)(FZ_BYTE*,int,FZ_BYTE*,int,FZ_BYTE*,int,int,int); +extern void (*fz_duff_4i1c4)(FZ_BYTE*,int,FZ_BYTE*,int,FZ_BYTE*,int,int,int); +extern void (*fz_duff_1i1o1)(FZ_BYTE*,int,FZ_BYTE*,int,FZ_BYTE*,int,int,int); +extern void (*fz_duff_4i1o4)(FZ_BYTE*,int,FZ_BYTE*,int,FZ_BYTE*,int,int,int); + +extern void (*fz_path_1c1)(FZ_BYTE*,int,int,FZ_BYTE*); +extern void (*fz_path_1o1)(FZ_BYTE*,int,int,FZ_BYTE*); +extern void (*fz_path_w3i1o4)(FZ_BYTE*,FZ_BYTE*,int,int,FZ_BYTE*); + +extern void (*fz_text_1c1)(FZ_BYTE*,int,FZ_BYTE*,int,int,int); +extern void (*fz_text_1o1)(FZ_BYTE*,int,FZ_BYTE*,int,int,int); +extern void (*fz_text_w3i1o4)(FZ_BYTE*,FZ_BYTE*,int,FZ_BYTE*,int,int,int); + +extern void (*fz_img_ncn)(FZ_PSRC, int sn, FZ_PDST, FZ_PCTM); +extern void (*fz_img_1c1)(FZ_PSRC, FZ_PDST, FZ_PCTM); +extern void (*fz_img_4c4)(FZ_PSRC, FZ_PDST, FZ_PCTM); +extern void (*fz_img_1o1)(FZ_PSRC, FZ_PDST, FZ_PCTM); +extern void (*fz_img_4o4)(FZ_PSRC, FZ_PDST, FZ_PCTM); +extern void (*fz_img_w3i1o4)(FZ_BYTE*,FZ_PSRC,FZ_PDST,FZ_PCTM); + +extern void (*fz_decodetile)(fz_pixmap *pix, int skip, float *decode); +extern void (*fz_loadtile1)(FZ_BYTE*, int sw, FZ_BYTE*, int dw, int w, int h, int pad); +extern void (*fz_loadtile2)(FZ_BYTE*, int sw, FZ_BYTE*, int dw, int w, int h, int pad); +extern void (*fz_loadtile4)(FZ_BYTE*, int sw, FZ_BYTE*, int dw, int w, int h, int pad); +extern void (*fz_loadtile8)(FZ_BYTE*, int sw, FZ_BYTE*, int dw, int w, int h, int pad); + +extern void (*fz_srown)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom, int n); +extern void (*fz_srow1)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom); +extern void (*fz_srow2)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom); +extern void (*fz_srow4)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom); +extern void (*fz_srow5)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom); + +extern void (*fz_scoln)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom, int n); +extern void (*fz_scol1)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom); +extern void (*fz_scol2)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom); +extern void (*fz_scol4)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom); +extern void (*fz_scol5)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom); + +#undef FZ_BYTE + +struct fz_renderer_s +{ + int maskonly; + fz_colorspace *model; + fz_glyphcache *cache; + fz_gel *gel; + fz_ael *ael; + + fz_irect clip; + fz_pixmap *dest; + fz_pixmap *over; + unsigned char rgb[3]; + int flag; +}; + +extern void fz_accelerate(); + +fz_error *fz_newrenderer(fz_renderer **gcp, fz_colorspace *pcm, int maskonly, int gcmem); +void fz_droprenderer(fz_renderer *gc); +fz_error *fz_rendertree(fz_pixmap **out, fz_renderer *gc, fz_tree *tree, fz_matrix ctm, fz_irect bbox, int white); +fz_error *fz_rendertreeover(fz_renderer *gc, fz_pixmap *dest, fz_tree *tree, fz_matrix ctm); + + diff --git a/include/fitz/draw_path.h b/include/fitz/draw_path.h new file mode 100644 index 00000000..0be71e9e --- /dev/null +++ b/include/fitz/draw_path.h @@ -0,0 +1,46 @@ +typedef struct fz_edge_s fz_edge; +typedef struct fz_gel_s fz_gel; +typedef struct fz_ael_s fz_ael; + +struct fz_edge_s +{ + int x, e, h, y; + int adjup, adjdown; + int xmove; + int xdir, ydir; /* -1 or +1 */ +}; + +struct fz_gel_s +{ + int hs, vs; + int xmin, xmax; + int ymin, ymax; + int cap; + int len; + fz_edge *edges; +}; + +struct fz_ael_s +{ + int cap; + int len; + fz_edge **edges; +}; + +fz_error *fz_newgel(fz_gel **gelp); +fz_error *fz_insertgel(fz_gel *gel, float x0, float y0, float x1, float y1); +fz_irect fz_boundgel(fz_gel *gel); +void fz_resetgel(fz_gel *gel, int hs, int vs); +void fz_sortgel(fz_gel *gel); +void fz_dropgel(fz_gel *gel); + +fz_error *fz_newael(fz_ael **aelp); +void fz_dropael(fz_ael *ael); + +fz_error *fz_scanconvert(fz_gel *gel, fz_ael *ael, int eofill, + fz_irect clip, fz_pixmap *pix, unsigned char *rgb, int over); + +fz_error *fz_fillpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness); +fz_error *fz_strokepath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness); +fz_error *fz_dashpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness); + diff --git a/include/fitz/filter.h b/include/fitz/filter.h deleted file mode 100644 index f8902f98..00000000 --- a/include/fitz/filter.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Data filters for encryption, compression and decompression. - * - * A filter has one method, process, that takes an input and an output buffer. - * - * It returns one of three statuses: - * ioneedin -- input buffer exhausted, please give me more data (wp-rp) - * ioneedout -- output buffer exhausted, please provide more space (ep-wp) - * iodone -- finished, please never call me again. ever! - * or... - * any other error object -- oops, something blew up. - * - * To make using the filter easier, three variables are updated: - * produced -- if we actually produced any new data - * consumed -- like above - * count -- number of bytes produced in total since the beginning - * - * Most filters take fz_obj as a way to specify parameters. - * In most cases, this is a dictionary that contains the same keys - * that the corresponding PDF filter would expect. - * - * The pipeline filter is special, and needs some care when chaining - * and unchaining new filters. - */ - -typedef struct fz_filter_s fz_filter; - -#define fz_ioneedin (&fz_kioneedin) -#define fz_ioneedout (&fz_kioneedout) -#define fz_iodone (&fz_kiodone) - -extern fz_error fz_kioneedin; -extern fz_error fz_kioneedout; -extern fz_error fz_kiodone; - -/* - * Evil looking macro to create an initialize a filter struct. - */ - -#define FZ_NEWFILTER(TYPE,VAR,NAME) \ - fz_error * fz_process ## NAME (fz_filter*,fz_buffer*,fz_buffer*); \ - void fz_drop ## NAME (fz_filter*); \ - TYPE *VAR; \ - *fp = fz_malloc(sizeof(TYPE)); \ - if (!*fp) return fz_outofmem; \ - (*fp)->refs = 1; \ - (*fp)->process = fz_process ## NAME ; \ - (*fp)->drop = fz_drop ## NAME ; \ - (*fp)->consumed = 0; \ - (*fp)->produced = 0; \ - (*fp)->count = 0; \ - VAR = (TYPE*) *fp - -struct fz_filter_s -{ - int refs; - fz_error* (*process)(fz_filter *filter, fz_buffer *in, fz_buffer *out); - void (*drop)(fz_filter *filter); - int consumed; - int produced; - int count; -}; - -fz_error *fz_process(fz_filter *f, fz_buffer *in, fz_buffer *out); -fz_filter *fz_keepfilter(fz_filter *f); -void fz_dropfilter(fz_filter *f); - -fz_error *fz_newpipeline(fz_filter **fp, fz_filter *head, fz_filter *tail); -fz_error *fz_chainpipeline(fz_filter **fp, fz_filter *head, fz_filter *tail, fz_buffer *buf); -void fz_unchainpipeline(fz_filter *pipe, fz_filter **oldfp, fz_buffer **oldbp); - -/* stop and reverse! special case needed for postscript only */ -void fz_pushbackahxd(fz_filter *filter, fz_buffer *in, fz_buffer *out, int n); - -fz_error *fz_newnullfilter(fz_filter **fp, int len); -fz_error *fz_newarc4filter(fz_filter **fp, unsigned char *key, unsigned keylen); -fz_error *fz_newa85d(fz_filter **filterp, fz_obj *param); -fz_error *fz_newa85e(fz_filter **filterp, fz_obj *param); -fz_error *fz_newahxd(fz_filter **filterp, fz_obj *param); -fz_error *fz_newahxe(fz_filter **filterp, fz_obj *param); -fz_error *fz_newrld(fz_filter **filterp, fz_obj *param); -fz_error *fz_newrle(fz_filter **filterp, fz_obj *param); -fz_error *fz_newdctd(fz_filter **filterp, fz_obj *param); -fz_error *fz_newdcte(fz_filter **filterp, fz_obj *param); -fz_error *fz_newfaxd(fz_filter **filterp, fz_obj *param); -fz_error *fz_newfaxe(fz_filter **filterp, fz_obj *param); -fz_error *fz_newflated(fz_filter **filterp, fz_obj *param); -fz_error *fz_newflatee(fz_filter **filterp, fz_obj *param); -fz_error *fz_newlzwd(fz_filter **filterp, fz_obj *param); -fz_error *fz_newlzwe(fz_filter **filterp, fz_obj *param); -fz_error *fz_newpredictd(fz_filter **filterp, fz_obj *param); -fz_error *fz_newpredicte(fz_filter **filterp, fz_obj *param); -fz_error *fz_newjbig2d(fz_filter **filterp, fz_obj *param); -fz_error *fz_newjpxd(fz_filter **filterp, fz_obj *param); - diff --git a/include/fitz/font.h b/include/fitz/font.h deleted file mode 100644 index 27217c6c..00000000 --- a/include/fitz/font.h +++ /dev/null @@ -1,68 +0,0 @@ -typedef struct fz_font_s fz_font; -typedef struct fz_hmtx_s fz_hmtx; -typedef struct fz_vmtx_s fz_vmtx; -typedef struct fz_glyph_s fz_glyph; -typedef struct fz_glyphcache_s fz_glyphcache; - -struct fz_hmtx_s -{ - unsigned short lo; - unsigned short hi; - int w; /* type3 fonts can be big! */ -}; - -struct fz_vmtx_s -{ - unsigned short lo; - unsigned short hi; - short x; - short y; - short w; -}; - -struct fz_font_s -{ - int refs; - char name[32]; - - fz_error* (*render)(fz_glyph*, fz_font*, int, fz_matrix); - void (*drop)(fz_font *); - - int wmode; - fz_irect bbox; - - int nhmtx, hmtxcap; - fz_hmtx dhmtx; - fz_hmtx *hmtx; - - int nvmtx, vmtxcap; - fz_vmtx dvmtx; - fz_vmtx *vmtx; -}; - -struct fz_glyph_s -{ - int x, y, w, h; - unsigned char *samples; -}; - -void fz_initfont(fz_font *font, char *name); -fz_font *fz_keepfont(fz_font *font); -void fz_dropfont(fz_font *font); -void fz_debugfont(fz_font *font); -void fz_setfontwmode(fz_font *font, int wmode); -void fz_setfontbbox(fz_font *font, int xmin, int ymin, int xmax, int ymax); -void fz_setdefaulthmtx(fz_font *font, int w); -void fz_setdefaultvmtx(fz_font *font, int y, int w); -fz_error *fz_addhmtx(fz_font *font, int lo, int hi, int w); -fz_error *fz_addvmtx(fz_font *font, int lo, int hi, int x, int y, int w); -fz_error *fz_endhmtx(fz_font *font); -fz_error *fz_endvmtx(fz_font *font); -fz_hmtx fz_gethmtx(fz_font *font, int cid); -fz_vmtx fz_getvmtx(fz_font *font, int cid); - -fz_error *fz_newglyphcache(fz_glyphcache **arenap, int slots, int size); -fz_error *fz_renderglyph(fz_glyphcache*, fz_glyph*, fz_font*, int, fz_matrix); -void fz_debugglyphcache(fz_glyphcache *); -void fz_dropglyphcache(fz_glyphcache *); - diff --git a/include/fitz/geometry.h b/include/fitz/geometry.h deleted file mode 100644 index 13290007..00000000 --- a/include/fitz/geometry.h +++ /dev/null @@ -1,65 +0,0 @@ -typedef struct fz_matrix_s fz_matrix; -typedef struct fz_point_s fz_point; -typedef struct fz_rect_s fz_rect; -typedef struct fz_ipoint_s fz_ipoint; -typedef struct fz_irect_s fz_irect; - -extern fz_rect fz_emptyrect; -extern fz_rect fz_infiniterect; - -#define fz_isemptyrect(r) ((r).x0 == (r).x1) -#define fz_isinfiniterect(r) ((r).x0 > (r).x1) - -/* - / a b 0 \ - | c d 0 | - \ e f 1 / -*/ -struct fz_matrix_s -{ - float a, b, c, d, e, f; -}; - -struct fz_point_s -{ - float x, y; -}; - -struct fz_rect_s -{ - float x0, y0; - float x1, y1; -}; - -struct fz_ipoint_s -{ - int x, y; -}; - -struct fz_irect_s -{ - int x0, y0; - int x1, y1; -}; - -void fz_invert3x3(float *dst, float *m); - -fz_matrix fz_concat(fz_matrix one, fz_matrix two); -fz_matrix fz_identity(void); -fz_matrix fz_scale(float sx, float sy); -fz_matrix fz_rotate(float theta); -fz_matrix fz_translate(float tx, float ty); -fz_matrix fz_invertmatrix(fz_matrix m); -int fz_isrectilinear(fz_matrix m); -float fz_matrixexpansion(fz_matrix m); - -fz_rect fz_intersectrects(fz_rect a, fz_rect b); -fz_rect fz_mergerects(fz_rect a, fz_rect b); - -fz_irect fz_roundrect(fz_rect r); -fz_irect fz_intersectirects(fz_irect a, fz_irect b); -fz_irect fz_mergeirects(fz_irect a, fz_irect b); - -fz_point fz_transformpoint(fz_matrix m, fz_point p); -fz_rect fz_transformaabb(fz_matrix m, fz_rect r); - diff --git a/include/fitz/hash.h b/include/fitz/hash.h deleted file mode 100644 index 5d2ec1b5..00000000 --- a/include/fitz/hash.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Generic hash-table with fixed-length keys. - */ - -typedef struct fz_hashtable_s fz_hashtable; - -fz_error *fz_newhash(fz_hashtable **tablep, int initialsize, int keylen); -fz_error *fz_resizehash(fz_hashtable *table, int newsize); -void fz_debughash(fz_hashtable *table); -void fz_emptyhash(fz_hashtable *table); -void fz_drophash(fz_hashtable *table); - -void *fz_hashfind(fz_hashtable *table, void *key); -fz_error *fz_hashinsert(fz_hashtable *table, void *key, void *val); -fz_error *fz_hashremove(fz_hashtable *table, void *key); - -int fz_hashlen(fz_hashtable *table); -void *fz_hashgetkey(fz_hashtable *table, int idx); -void *fz_hashgetval(fz_hashtable *table, int idx); - diff --git a/include/fitz/image.h b/include/fitz/image.h deleted file mode 100644 index 89d180ba..00000000 --- a/include/fitz/image.h +++ /dev/null @@ -1,16 +0,0 @@ -typedef struct fz_image_s fz_image; - -/* loadtile will fill a pixmap with the pixel samples. non-premultiplied alpha. */ - -struct fz_image_s -{ - int refs; - fz_error* (*loadtile)(fz_image*,fz_pixmap*); - void (*drop)(fz_image*); - fz_colorspace *cs; - int w, h, n, a; -}; - -fz_image *fz_keepimage(fz_image *img); -void fz_dropimage(fz_image *img); - diff --git a/include/fitz/math.h b/include/fitz/math.h deleted file mode 100644 index 4dee81fc..00000000 --- a/include/fitz/math.h +++ /dev/null @@ -1,29 +0,0 @@ -/* multiply 8-bit fixpoint (0..1) so that 0*0==0 and 255*255==255 */ -#define fz_mul255(a,b) (((a) * ((b) + 1)) >> 8) -#define fz_floor(x) floor(x) -#define fz_ceil(x) ceil(x) - -/* divide and floor towards -inf */ -static inline int fz_idiv(int a, int b) -{ - return a < 0 ? (a - b + 1) / b : a / b; -} - -/* from python */ -static inline void fz_idivmod(int x, int y, int *d, int *m) -{ - int xdivy = x / y; - int xmody = x - xdivy * y; - /* If the signs of x and y differ, and the remainder is non-0, - * C89 doesn't define whether xdivy is now the floor or the - * ceiling of the infinitely precise quotient. We want the floor, - * and we have it iff the remainder's sign matches y's. - */ - if (xmody && ((y ^ xmody) < 0)) { - xmody += y; - xdivy --; - } - *d = xdivy; - *m = xmody; -} - diff --git a/include/fitz/object.h b/include/fitz/object.h deleted file mode 100644 index fe9c12e5..00000000 --- a/include/fitz/object.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Dynamic objects. - * The same type of objects as found in PDF and PostScript. - * Used by the filter library and the mupdf parser. - */ - -typedef struct fz_obj_s fz_obj; -typedef struct fz_keyval_s fz_keyval; - -typedef enum fz_objkind_e -{ - FZ_NULL, - FZ_BOOL, - FZ_INT, - FZ_REAL, - FZ_STRING, - FZ_NAME, - FZ_ARRAY, - FZ_DICT, - FZ_INDIRECT, - FZ_POINTER -} fz_objkind; - -struct fz_keyval_s -{ - fz_obj *k; - fz_obj *v; -}; - -struct fz_obj_s -{ - unsigned short refs; - char kind; /* fz_objkind takes 4 bytes :( */ - union - { - int b; - int i; - float f; - struct { - unsigned short len; - char buf[1]; - } s; - char n[1]; - struct { - int len; - int cap; - fz_obj **items; - } a; - struct { - char sorted; - int len; - int cap; - fz_keyval *items; - } d; - struct { - int oid; - int gid; - } r; - void *p; - } u; -}; - -fz_error *fz_newnull(fz_obj **op); -fz_error *fz_newbool(fz_obj **op, int b); -fz_error *fz_newint(fz_obj **op, int i); -fz_error *fz_newreal(fz_obj **op, float f); -fz_error *fz_newname(fz_obj **op, char *str); -fz_error *fz_newstring(fz_obj **op, char *str, int len); -fz_error *fz_newindirect(fz_obj **op, int oid, int gid); -fz_error *fz_newpointer(fz_obj **op, void *p); - -fz_error *fz_newarray(fz_obj **op, int initialcap); -fz_error *fz_newdict(fz_obj **op, int initialcap); -fz_error *fz_copyarray(fz_obj **op, fz_obj *array); -fz_error *fz_copydict(fz_obj **op, fz_obj *dict); -fz_error *fz_deepcopyarray(fz_obj **op, fz_obj *array); -fz_error *fz_deepcopydict(fz_obj **op, fz_obj *dict); - -fz_obj *fz_keepobj(fz_obj *obj); -void fz_dropobj(fz_obj *obj); - -/* type queries */ -int fz_isnull(fz_obj *obj); -int fz_isbool(fz_obj *obj); -int fz_isint(fz_obj *obj); -int fz_isreal(fz_obj *obj); -int fz_isname(fz_obj *obj); -int fz_isstring(fz_obj *obj); -int fz_isarray(fz_obj *obj); -int fz_isdict(fz_obj *obj); -int fz_isindirect(fz_obj *obj); -int fz_ispointer(fz_obj *obj); - -int fz_objcmp(fz_obj *a, fz_obj *b); - -/* silent failure, no error reporting */ -int fz_tobool(fz_obj *obj); -int fz_toint(fz_obj *obj); -float fz_toreal(fz_obj *obj); -char *fz_toname(fz_obj *obj); -char *fz_tostrbuf(fz_obj *obj); -int fz_tostrlen(fz_obj *obj); -int fz_tonum(fz_obj *obj); -int fz_togen(fz_obj *obj); -void *fz_topointer(fz_obj *obj); - -fz_error *fz_newnamefromstring(fz_obj **op, fz_obj *str); - -int fz_arraylen(fz_obj *array); -fz_obj *fz_arrayget(fz_obj *array, int i); -fz_error *fz_arrayput(fz_obj *array, int i, fz_obj *obj); -fz_error *fz_arraypush(fz_obj *array, fz_obj *obj); - -int fz_dictlen(fz_obj *dict); -fz_obj *fz_dictgetkey(fz_obj *dict, int idx); -fz_obj *fz_dictgetval(fz_obj *dict, int idx); -fz_obj *fz_dictget(fz_obj *dict, fz_obj *key); -fz_obj *fz_dictgets(fz_obj *dict, char *key); -fz_obj *fz_dictgetsa(fz_obj *dict, char *key, char *abbrev); -fz_error *fz_dictput(fz_obj *dict, fz_obj *key, fz_obj *val); -fz_error *fz_dictputs(fz_obj *dict, char *key, fz_obj *val); -fz_error *fz_dictdel(fz_obj *dict, fz_obj *key); -fz_error *fz_dictdels(fz_obj *dict, char *key); -void fz_sortdict(fz_obj *dict); - -int fz_sprintobj(char *s, int n, fz_obj *obj, int tight); -void fz_debugobj(fz_obj *obj); - -fz_error *fz_parseobj(fz_obj **objp, char *s); -fz_error *fz_packobj(fz_obj **objp, char *fmt, ...); -fz_error *fz_unpackobj(fz_obj *obj, char *fmt, ...); - diff --git a/include/fitz/path.h b/include/fitz/path.h deleted file mode 100644 index 6a7c55b7..00000000 --- a/include/fitz/path.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Vector path nodes in the display tree. - * They can be stroked and dashed, or be filled. - * They have a fill rule (nonzero or evenodd). - * - * When rendering, they are flattened, stroked and dashed straight - * into the Global Edge List. - * - * TODO flatten, stroke and dash into another path - * TODO set operations on flat paths (union, intersect, difference) - * TODO decide whether dashing should be part of the tree and renderer, - * or if it is something the client has to do (with a util function). - */ - -typedef struct fz_stroke_s fz_stroke; -typedef struct fz_dash_s fz_dash; -typedef union fz_pathel_s fz_pathel; - -typedef enum fz_pathkind_e -{ - FZ_STROKE, - FZ_FILL, - FZ_EOFILL -} fz_pathkind; - -typedef enum fz_pathelkind_e -{ - FZ_MOVETO, - FZ_LINETO, - FZ_CURVETO, - FZ_CLOSEPATH -} fz_pathelkind; - -struct fz_stroke_s -{ - int linecap; - int linejoin; - float linewidth; - float miterlimit; -}; - -struct fz_dash_s -{ - int len; - float phase; - float array[FZ_FLEX]; -}; - -union fz_pathel_s -{ - fz_pathelkind k; - float v; -}; - -struct fz_pathnode_s -{ - fz_node super; - fz_pathkind paint; - fz_dash *dash; - int linecap; - int linejoin; - float linewidth; - float miterlimit; - int len, cap; - fz_pathel *els; -}; - -fz_error *fz_newpathnode(fz_pathnode **pathp); -fz_error *fz_clonepathnode(fz_pathnode **pathp, fz_pathnode *oldpath); -fz_error *fz_moveto(fz_pathnode*, float x, float y); -fz_error *fz_lineto(fz_pathnode*, float x, float y); -fz_error *fz_curveto(fz_pathnode*, float, float, float, float, float, float); -fz_error *fz_curvetov(fz_pathnode*, float, float, float, float); -fz_error *fz_curvetoy(fz_pathnode*, float, float, float, float); -fz_error *fz_closepath(fz_pathnode*); -fz_error *fz_endpath(fz_pathnode*, fz_pathkind paint, fz_stroke *stroke, fz_dash *dash); - -fz_rect fz_boundpathnode(fz_pathnode *node, fz_matrix ctm); -void fz_debugpathnode(fz_pathnode *node); - -fz_error *fz_newdash(fz_dash **dashp, float phase, int len, float *array); -void fz_dropdash(fz_dash *dash); - diff --git a/include/fitz/pathscan.h b/include/fitz/pathscan.h deleted file mode 100644 index 0be71e9e..00000000 --- a/include/fitz/pathscan.h +++ /dev/null @@ -1,46 +0,0 @@ -typedef struct fz_edge_s fz_edge; -typedef struct fz_gel_s fz_gel; -typedef struct fz_ael_s fz_ael; - -struct fz_edge_s -{ - int x, e, h, y; - int adjup, adjdown; - int xmove; - int xdir, ydir; /* -1 or +1 */ -}; - -struct fz_gel_s -{ - int hs, vs; - int xmin, xmax; - int ymin, ymax; - int cap; - int len; - fz_edge *edges; -}; - -struct fz_ael_s -{ - int cap; - int len; - fz_edge **edges; -}; - -fz_error *fz_newgel(fz_gel **gelp); -fz_error *fz_insertgel(fz_gel *gel, float x0, float y0, float x1, float y1); -fz_irect fz_boundgel(fz_gel *gel); -void fz_resetgel(fz_gel *gel, int hs, int vs); -void fz_sortgel(fz_gel *gel); -void fz_dropgel(fz_gel *gel); - -fz_error *fz_newael(fz_ael **aelp); -void fz_dropael(fz_ael *ael); - -fz_error *fz_scanconvert(fz_gel *gel, fz_ael *ael, int eofill, - fz_irect clip, fz_pixmap *pix, unsigned char *rgb, int over); - -fz_error *fz_fillpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness); -fz_error *fz_strokepath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness); -fz_error *fz_dashpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness); - diff --git a/include/fitz/pixmap.h b/include/fitz/pixmap.h deleted file mode 100644 index c369df84..00000000 --- a/include/fitz/pixmap.h +++ /dev/null @@ -1,25 +0,0 @@ -/* -pixmaps have n components per pixel. the first is always alpha. -premultiplied alpha when rendering, but non-premultiplied for colorspace -conversions and rescaling. -*/ - -typedef struct fz_pixmap_s fz_pixmap; -typedef unsigned char fz_sample; - -struct fz_pixmap_s -{ - int x, y, w, h, n; - fz_sample *samples; -}; - -fz_error *fz_newpixmapwithrect(fz_pixmap **mapp, fz_irect bbox, int n); -fz_error *fz_newpixmap(fz_pixmap **mapp, int x, int y, int w, int h, int n); -fz_error *fz_newpixmapcopy(fz_pixmap **pixp, fz_pixmap *old); - -void fz_debugpixmap(fz_pixmap *map); -void fz_clearpixmap(fz_pixmap *map); -void fz_droppixmap(fz_pixmap *map); - -fz_error *fz_scalepixmap(fz_pixmap **dstp, fz_pixmap *src, int xdenom, int ydenom); - diff --git a/include/fitz/render.h b/include/fitz/render.h deleted file mode 100644 index cb78b57c..00000000 --- a/include/fitz/render.h +++ /dev/null @@ -1,83 +0,0 @@ -typedef struct fz_renderer_s fz_renderer; - -#define FZ_BYTE unsigned char - -#define FZ_PSRC \ - unsigned char *src, int srcw, int srch -#define FZ_PDST \ - unsigned char *dst0, int dstw -#define FZ_PCTM \ - int u0, int v0, int fa, int fb, int fc, int fd, int w0, int h - -/* - * Function pointers -- they can be replaced by cpu-optimized versions - */ - -extern void (*fz_duff_non)(FZ_BYTE*,int,int,FZ_BYTE*,int,int,int); -extern void (*fz_duff_nimcn)(FZ_BYTE*,int,int,FZ_BYTE*,int,int,FZ_BYTE*,int,int,int); -extern void (*fz_duff_nimon)(FZ_BYTE*,int,int,FZ_BYTE*,int,int,FZ_BYTE*,int,int,int); -extern void (*fz_duff_1o1)(FZ_BYTE*,int,FZ_BYTE*,int,int,int); -extern void (*fz_duff_4o4)(FZ_BYTE*,int,FZ_BYTE*,int,int,int); -extern void (*fz_duff_1i1c1)(FZ_BYTE*,int,FZ_BYTE*,int,FZ_BYTE*,int,int,int); -extern void (*fz_duff_4i1c4)(FZ_BYTE*,int,FZ_BYTE*,int,FZ_BYTE*,int,int,int); -extern void (*fz_duff_1i1o1)(FZ_BYTE*,int,FZ_BYTE*,int,FZ_BYTE*,int,int,int); -extern void (*fz_duff_4i1o4)(FZ_BYTE*,int,FZ_BYTE*,int,FZ_BYTE*,int,int,int); - -extern void (*fz_path_1c1)(FZ_BYTE*,int,int,FZ_BYTE*); -extern void (*fz_path_1o1)(FZ_BYTE*,int,int,FZ_BYTE*); -extern void (*fz_path_w3i1o4)(FZ_BYTE*,FZ_BYTE*,int,int,FZ_BYTE*); - -extern void (*fz_text_1c1)(FZ_BYTE*,int,FZ_BYTE*,int,int,int); -extern void (*fz_text_1o1)(FZ_BYTE*,int,FZ_BYTE*,int,int,int); -extern void (*fz_text_w3i1o4)(FZ_BYTE*,FZ_BYTE*,int,FZ_BYTE*,int,int,int); - -extern void (*fz_img_ncn)(FZ_PSRC, int sn, FZ_PDST, FZ_PCTM); -extern void (*fz_img_1c1)(FZ_PSRC, FZ_PDST, FZ_PCTM); -extern void (*fz_img_4c4)(FZ_PSRC, FZ_PDST, FZ_PCTM); -extern void (*fz_img_1o1)(FZ_PSRC, FZ_PDST, FZ_PCTM); -extern void (*fz_img_4o4)(FZ_PSRC, FZ_PDST, FZ_PCTM); -extern void (*fz_img_w3i1o4)(FZ_BYTE*,FZ_PSRC,FZ_PDST,FZ_PCTM); - -extern void (*fz_decodetile)(fz_pixmap *pix, int skip, float *decode); -extern void (*fz_loadtile1)(FZ_BYTE*, int sw, FZ_BYTE*, int dw, int w, int h, int pad); -extern void (*fz_loadtile2)(FZ_BYTE*, int sw, FZ_BYTE*, int dw, int w, int h, int pad); -extern void (*fz_loadtile4)(FZ_BYTE*, int sw, FZ_BYTE*, int dw, int w, int h, int pad); -extern void (*fz_loadtile8)(FZ_BYTE*, int sw, FZ_BYTE*, int dw, int w, int h, int pad); - -extern void (*fz_srown)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom, int n); -extern void (*fz_srow1)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom); -extern void (*fz_srow2)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom); -extern void (*fz_srow4)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom); -extern void (*fz_srow5)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom); - -extern void (*fz_scoln)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom, int n); -extern void (*fz_scol1)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom); -extern void (*fz_scol2)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom); -extern void (*fz_scol4)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom); -extern void (*fz_scol5)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom); - -#undef FZ_BYTE - -struct fz_renderer_s -{ - int maskonly; - fz_colorspace *model; - fz_glyphcache *cache; - fz_gel *gel; - fz_ael *ael; - - fz_irect clip; - fz_pixmap *dest; - fz_pixmap *over; - unsigned char rgb[3]; - int flag; -}; - -extern void fz_accelerate(); - -fz_error *fz_newrenderer(fz_renderer **gcp, fz_colorspace *pcm, int maskonly, int gcmem); -void fz_droprenderer(fz_renderer *gc); -fz_error *fz_rendertree(fz_pixmap **out, fz_renderer *gc, fz_tree *tree, fz_matrix ctm, fz_irect bbox, int white); -fz_error *fz_rendertreeover(fz_renderer *gc, fz_pixmap *dest, fz_tree *tree, fz_matrix ctm); - - diff --git a/include/fitz/runtime.h b/include/fitz/runtime.h deleted file mode 100644 index feeb7ffc..00000000 --- a/include/fitz/runtime.h +++ /dev/null @@ -1,80 +0,0 @@ -#undef nil -#define nil ((void*)0) - -#undef offsetof -#define offsetof(s, m) (unsigned long)(&(((s*)0)->m)) - -#undef nelem -#define nelem(x) (sizeof(x)/sizeof((x)[0])) - -#undef ABS -#define ABS(x) ( (x) < 0 ? -(x) : (x) ) - -#undef MAX -#define MAX(a,b) ( (a) > (b) ? (a) : (b) ) - -#undef MIN -#define MIN(a,b) ( (a) < (b) ? (a) : (b) ) - -#undef CLAMP -#define CLAMP(x,a,b) ( (x) > (b) ? (b) : ( (x) < (a) ? (a) : (x) ) ) - -#define MAX4(a,b,c,d) MAX(MAX(a,b), MAX(c,d)) -#define MIN4(a,b,c,d) MIN(MIN(a,b), MIN(c,d)) - -#define STRIDE(n, bcp) (((bpc) * (n) + 7) / 8) - -/* plan9 stuff for utf-8 and path munging */ -int chartorune(int *rune, char *str); -int runetochar(char *str, int *rune); -int runelen(long c); -int runenlen(int *r, int nrune); -int fullrune(char *str, int n); -char *cleanname(char *name); - -typedef struct fz_error_s fz_error; - -struct fz_error_s -{ - int refs; - char msg[184]; - char file[32]; - char func[32]; - int line; -}; - -#define fz_outofmem (&fz_koutofmem) -extern fz_error fz_koutofmem; - -#ifdef WIN32 -#define fz_throw(...) fz_throw0(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__) -#elif HAVE_C99 -#define fz_throw(...) fz_throw0(__func__, __FILE__, __LINE__, __VA_ARGS__) -#else -#define fz_throw fz_throw1 -#endif -fz_error *fz_throw0(const char *func, const char *file, int line, char *fmt, ...); -fz_error *fz_throw1(char *fmt, ...); - -void fz_warn(char *fmt, ...); -void fz_abort(fz_error *eo); -void fz_droperror(fz_error *eo); - -typedef struct fz_memorycontext_s fz_memorycontext; - -struct fz_memorycontext_s -{ - void * (*malloc)(fz_memorycontext *, int); - void * (*realloc)(fz_memorycontext *, void *, int); - void (*free)(fz_memorycontext *, void *); -}; - -fz_memorycontext *fz_currentmemorycontext(void); -void fz_setmemorycontext(fz_memorycontext *memorycontext); - -void *fz_malloc(int n); -void *fz_realloc(void *p, int n); -void fz_free(void *p); - -char *fz_strdup(char *s); - diff --git a/include/fitz/shade.h b/include/fitz/shade.h deleted file mode 100644 index 1b7c81c5..00000000 --- a/include/fitz/shade.h +++ /dev/null @@ -1,29 +0,0 @@ -typedef struct fz_shade_s fz_shade; - -struct fz_shade_s -{ - int refs; - - fz_rect bbox; /* can be fz_infiniterect */ - fz_colorspace *cs; - - /* used by build.c -- not used in drawshade.c */ - fz_matrix matrix; /* matrix from pattern dict */ - int usebackground; /* background color for fills but not 'sh' */ - float background[FZ_MAXCOLORS]; - - int usefunction; - float function[256][FZ_MAXCOLORS]; - - int meshlen; - int meshcap; - float *mesh; /* [x y t] or [x y c1 ... cn] * 3 * meshlen */ -}; - - -fz_shade *fz_keepshade(fz_shade *shade); -void fz_dropshade(fz_shade *shade); - -fz_rect fz_boundshade(fz_shade *shade, fz_matrix ctm); -fz_error *fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_colorspace *dsts, fz_pixmap *dstp); - diff --git a/include/fitz/stm_buffer.h b/include/fitz/stm_buffer.h new file mode 100644 index 00000000..1a6f34ad --- /dev/null +++ b/include/fitz/stm_buffer.h @@ -0,0 +1,41 @@ +/* + * Data buffers for streams and filters. + * + * bp is the pointer to the allocated memory + * rp is read-position (*in->rp++ to read data) + * wp is write-position (*out->wp++ to write data) + * ep is the sentinel + * + * Only the data between rp and wp is valid data. + * + * Writers set eof to true at the end. + * Readers look at eof. + * + * A buffer owns the memory it has allocated, unless ownsdata is false, + * in which case the creator of the buffer owns it. + */ + +typedef struct fz_buffer_s fz_buffer; + +#define FZ_BUFSIZE (8 * 1024) + +struct fz_buffer_s +{ + int refs; + int ownsdata; + unsigned char *bp; + unsigned char *rp; + unsigned char *wp; + unsigned char *ep; + int eof; +}; + +fz_error *fz_newbuffer(fz_buffer **bufp, int size); +fz_error *fz_newbufferwithmemory(fz_buffer **bufp, unsigned char *data, int size); + +fz_error *fz_rewindbuffer(fz_buffer *buf); +fz_error *fz_growbuffer(fz_buffer *buf); + +fz_buffer *fz_keepbuffer(fz_buffer *buf); +void fz_dropbuffer(fz_buffer *buf); + diff --git a/include/fitz/stm_crypt.h b/include/fitz/stm_crypt.h new file mode 100644 index 00000000..15191caa --- /dev/null +++ b/include/fitz/stm_crypt.h @@ -0,0 +1,39 @@ +/* + * Basic crypto functions. + * Independent of the rest of fitz. + * For further encapsulation in filters, or not. + */ + +/* md5 digests */ + +typedef struct fz_md5_s fz_md5; + +struct fz_md5_s +{ + unsigned long state[4]; + unsigned long count[2]; + unsigned char buffer[64]; +}; + +void fz_md5init(fz_md5 *state); +void fz_md5update(fz_md5 *state, unsigned char *input, unsigned inlen); +void fz_md5final(fz_md5 *state, unsigned char digest[16]); + +/* arc4 crypto */ + +typedef struct fz_arc4_s fz_arc4; + +struct fz_arc4_s +{ + unsigned x; + unsigned y; + unsigned char state[256]; +}; + +void fz_arc4init(fz_arc4 *state, unsigned char *key, unsigned len); +unsigned char fz_arc4next(fz_arc4 *state); +void fz_arc4encrypt(fz_arc4 *state, unsigned char *dest, unsigned char *src, unsigned len); + +/* TODO: sha1 */ +/* TODO: aes */ + diff --git a/include/fitz/stm_filter.h b/include/fitz/stm_filter.h new file mode 100644 index 00000000..f8902f98 --- /dev/null +++ b/include/fitz/stm_filter.h @@ -0,0 +1,95 @@ +/* + * Data filters for encryption, compression and decompression. + * + * A filter has one method, process, that takes an input and an output buffer. + * + * It returns one of three statuses: + * ioneedin -- input buffer exhausted, please give me more data (wp-rp) + * ioneedout -- output buffer exhausted, please provide more space (ep-wp) + * iodone -- finished, please never call me again. ever! + * or... + * any other error object -- oops, something blew up. + * + * To make using the filter easier, three variables are updated: + * produced -- if we actually produced any new data + * consumed -- like above + * count -- number of bytes produced in total since the beginning + * + * Most filters take fz_obj as a way to specify parameters. + * In most cases, this is a dictionary that contains the same keys + * that the corresponding PDF filter would expect. + * + * The pipeline filter is special, and needs some care when chaining + * and unchaining new filters. + */ + +typedef struct fz_filter_s fz_filter; + +#define fz_ioneedin (&fz_kioneedin) +#define fz_ioneedout (&fz_kioneedout) +#define fz_iodone (&fz_kiodone) + +extern fz_error fz_kioneedin; +extern fz_error fz_kioneedout; +extern fz_error fz_kiodone; + +/* + * Evil looking macro to create an initialize a filter struct. + */ + +#define FZ_NEWFILTER(TYPE,VAR,NAME) \ + fz_error * fz_process ## NAME (fz_filter*,fz_buffer*,fz_buffer*); \ + void fz_drop ## NAME (fz_filter*); \ + TYPE *VAR; \ + *fp = fz_malloc(sizeof(TYPE)); \ + if (!*fp) return fz_outofmem; \ + (*fp)->refs = 1; \ + (*fp)->process = fz_process ## NAME ; \ + (*fp)->drop = fz_drop ## NAME ; \ + (*fp)->consumed = 0; \ + (*fp)->produced = 0; \ + (*fp)->count = 0; \ + VAR = (TYPE*) *fp + +struct fz_filter_s +{ + int refs; + fz_error* (*process)(fz_filter *filter, fz_buffer *in, fz_buffer *out); + void (*drop)(fz_filter *filter); + int consumed; + int produced; + int count; +}; + +fz_error *fz_process(fz_filter *f, fz_buffer *in, fz_buffer *out); +fz_filter *fz_keepfilter(fz_filter *f); +void fz_dropfilter(fz_filter *f); + +fz_error *fz_newpipeline(fz_filter **fp, fz_filter *head, fz_filter *tail); +fz_error *fz_chainpipeline(fz_filter **fp, fz_filter *head, fz_filter *tail, fz_buffer *buf); +void fz_unchainpipeline(fz_filter *pipe, fz_filter **oldfp, fz_buffer **oldbp); + +/* stop and reverse! special case needed for postscript only */ +void fz_pushbackahxd(fz_filter *filter, fz_buffer *in, fz_buffer *out, int n); + +fz_error *fz_newnullfilter(fz_filter **fp, int len); +fz_error *fz_newarc4filter(fz_filter **fp, unsigned char *key, unsigned keylen); +fz_error *fz_newa85d(fz_filter **filterp, fz_obj *param); +fz_error *fz_newa85e(fz_filter **filterp, fz_obj *param); +fz_error *fz_newahxd(fz_filter **filterp, fz_obj *param); +fz_error *fz_newahxe(fz_filter **filterp, fz_obj *param); +fz_error *fz_newrld(fz_filter **filterp, fz_obj *param); +fz_error *fz_newrle(fz_filter **filterp, fz_obj *param); +fz_error *fz_newdctd(fz_filter **filterp, fz_obj *param); +fz_error *fz_newdcte(fz_filter **filterp, fz_obj *param); +fz_error *fz_newfaxd(fz_filter **filterp, fz_obj *param); +fz_error *fz_newfaxe(fz_filter **filterp, fz_obj *param); +fz_error *fz_newflated(fz_filter **filterp, fz_obj *param); +fz_error *fz_newflatee(fz_filter **filterp, fz_obj *param); +fz_error *fz_newlzwd(fz_filter **filterp, fz_obj *param); +fz_error *fz_newlzwe(fz_filter **filterp, fz_obj *param); +fz_error *fz_newpredictd(fz_filter **filterp, fz_obj *param); +fz_error *fz_newpredicte(fz_filter **filterp, fz_obj *param); +fz_error *fz_newjbig2d(fz_filter **filterp, fz_obj *param); +fz_error *fz_newjpxd(fz_filter **filterp, fz_obj *param); + diff --git a/include/fitz/stm_object.h b/include/fitz/stm_object.h new file mode 100644 index 00000000..fe9c12e5 --- /dev/null +++ b/include/fitz/stm_object.h @@ -0,0 +1,132 @@ +/* + * Dynamic objects. + * The same type of objects as found in PDF and PostScript. + * Used by the filter library and the mupdf parser. + */ + +typedef struct fz_obj_s fz_obj; +typedef struct fz_keyval_s fz_keyval; + +typedef enum fz_objkind_e +{ + FZ_NULL, + FZ_BOOL, + FZ_INT, + FZ_REAL, + FZ_STRING, + FZ_NAME, + FZ_ARRAY, + FZ_DICT, + FZ_INDIRECT, + FZ_POINTER +} fz_objkind; + +struct fz_keyval_s +{ + fz_obj *k; + fz_obj *v; +}; + +struct fz_obj_s +{ + unsigned short refs; + char kind; /* fz_objkind takes 4 bytes :( */ + union + { + int b; + int i; + float f; + struct { + unsigned short len; + char buf[1]; + } s; + char n[1]; + struct { + int len; + int cap; + fz_obj **items; + } a; + struct { + char sorted; + int len; + int cap; + fz_keyval *items; + } d; + struct { + int oid; + int gid; + } r; + void *p; + } u; +}; + +fz_error *fz_newnull(fz_obj **op); +fz_error *fz_newbool(fz_obj **op, int b); +fz_error *fz_newint(fz_obj **op, int i); +fz_error *fz_newreal(fz_obj **op, float f); +fz_error *fz_newname(fz_obj **op, char *str); +fz_error *fz_newstring(fz_obj **op, char *str, int len); +fz_error *fz_newindirect(fz_obj **op, int oid, int gid); +fz_error *fz_newpointer(fz_obj **op, void *p); + +fz_error *fz_newarray(fz_obj **op, int initialcap); +fz_error *fz_newdict(fz_obj **op, int initialcap); +fz_error *fz_copyarray(fz_obj **op, fz_obj *array); +fz_error *fz_copydict(fz_obj **op, fz_obj *dict); +fz_error *fz_deepcopyarray(fz_obj **op, fz_obj *array); +fz_error *fz_deepcopydict(fz_obj **op, fz_obj *dict); + +fz_obj *fz_keepobj(fz_obj *obj); +void fz_dropobj(fz_obj *obj); + +/* type queries */ +int fz_isnull(fz_obj *obj); +int fz_isbool(fz_obj *obj); +int fz_isint(fz_obj *obj); +int fz_isreal(fz_obj *obj); +int fz_isname(fz_obj *obj); +int fz_isstring(fz_obj *obj); +int fz_isarray(fz_obj *obj); +int fz_isdict(fz_obj *obj); +int fz_isindirect(fz_obj *obj); +int fz_ispointer(fz_obj *obj); + +int fz_objcmp(fz_obj *a, fz_obj *b); + +/* silent failure, no error reporting */ +int fz_tobool(fz_obj *obj); +int fz_toint(fz_obj *obj); +float fz_toreal(fz_obj *obj); +char *fz_toname(fz_obj *obj); +char *fz_tostrbuf(fz_obj *obj); +int fz_tostrlen(fz_obj *obj); +int fz_tonum(fz_obj *obj); +int fz_togen(fz_obj *obj); +void *fz_topointer(fz_obj *obj); + +fz_error *fz_newnamefromstring(fz_obj **op, fz_obj *str); + +int fz_arraylen(fz_obj *array); +fz_obj *fz_arrayget(fz_obj *array, int i); +fz_error *fz_arrayput(fz_obj *array, int i, fz_obj *obj); +fz_error *fz_arraypush(fz_obj *array, fz_obj *obj); + +int fz_dictlen(fz_obj *dict); +fz_obj *fz_dictgetkey(fz_obj *dict, int idx); +fz_obj *fz_dictgetval(fz_obj *dict, int idx); +fz_obj *fz_dictget(fz_obj *dict, fz_obj *key); +fz_obj *fz_dictgets(fz_obj *dict, char *key); +fz_obj *fz_dictgetsa(fz_obj *dict, char *key, char *abbrev); +fz_error *fz_dictput(fz_obj *dict, fz_obj *key, fz_obj *val); +fz_error *fz_dictputs(fz_obj *dict, char *key, fz_obj *val); +fz_error *fz_dictdel(fz_obj *dict, fz_obj *key); +fz_error *fz_dictdels(fz_obj *dict, char *key); +void fz_sortdict(fz_obj *dict); + +int fz_sprintobj(char *s, int n, fz_obj *obj, int tight); +void fz_debugobj(fz_obj *obj); + +fz_error *fz_parseobj(fz_obj **objp, char *s); +fz_error *fz_packobj(fz_obj **objp, char *fmt, ...); +fz_error *fz_unpackobj(fz_obj *obj, char *fmt, ...); + diff --git a/include/fitz/stm_stream.h b/include/fitz/stm_stream.h new file mode 100644 index 00000000..b0778373 --- /dev/null +++ b/include/fitz/stm_stream.h @@ -0,0 +1,103 @@ +/* + * Stream API for Fitz. + * Read and write data to and from files, memory buffers and filters. + */ + +typedef struct fz_stream_s fz_stream; + +enum { FZ_SFILE, FZ_SBUFFER, FZ_SFILTER }; +enum { FZ_SREAD, FZ_SWRITE }; + +struct fz_stream_s +{ + int refs; + int kind; + int mode; + int dead; + fz_buffer *buffer; + fz_filter *filter; + fz_stream *chain; + fz_error *error; + int file; +}; + +/* + * Various stream creation functions. + */ + +/* open() and creat() & co */ +fz_error *fz_openrfile(fz_stream **stmp, char *filename); +fz_error *fz_openwfile(fz_stream **stmp, char *filename); +fz_error *fz_openafile(fz_stream **stmp, char *filename); + +/* write to memory buffers! */ +fz_error *fz_openrmemory(fz_stream **stmp, char *buf, int len); +fz_error *fz_openrbuffer(fz_stream **stmp, fz_buffer *buf); +fz_error *fz_openwbuffer(fz_stream **stmp, fz_buffer *buf); + +/* almost like fork() exec() pipe() */ +fz_error *fz_openrfilter(fz_stream **stmp, fz_filter *flt, fz_stream *chain); +fz_error *fz_openwfilter(fz_stream **stmp, fz_filter *flt, fz_stream *chain); + +/* + * Functions that are common to both input and output streams. + */ + +fz_error *fz_ioerror(fz_stream *stm); + +fz_stream *fz_keepstream(fz_stream *stm); +void fz_dropstream(fz_stream *stm); + +int fz_tell(fz_stream *stm); +int fz_seek(fz_stream *stm, int offset, int whence); + +/* + * Input stream functions. + * Return EOF (-1) on errors. + */ + +int fz_rtell(fz_stream *stm); +int fz_rseek(fz_stream *stm, int offset, int whence); + +int fz_makedata(fz_stream *stm); +int fz_read(fz_stream *stm, unsigned char *buf, int len); + +int fz_readall(fz_buffer **bufp, fz_stream *stm); +int fz_readline(fz_stream *stm, char *buf, int max); + +int fz_readbytex(fz_stream *stm); +int fz_peekbytex(fz_stream *stm); + +#ifdef DEBUG +#define fz_readbyte fz_readbytex +#define fz_peekbyte fz_peekbytex +#else + +#define FZ_READBYTE(XXX) { \ + fz_buffer *buf = stm->buffer; \ + if (buf->rp == buf->wp) \ + if (fz_makedata(stm) < 0) \ + return EOF; \ + return buf->rp < buf->wp ? XXX : EOF ; \ +} + +static inline int fz_readbyte(fz_stream *stm) FZ_READBYTE(*buf->rp++) +static inline int fz_peekbyte(fz_stream *stm) FZ_READBYTE(*buf->rp) + +#endif + +/* + * Output stream functions. + * Return N or 0 on success, -1 on failure. + */ + +int fz_wtell(fz_stream *stm); +int fz_wseek(fz_stream *stm, int offset, int whence); + +int fz_write(fz_stream *stm, unsigned char *buf, int n); +int fz_flush(fz_stream *stm); + +int fz_printstr(fz_stream *stm, char *s); +int fz_printobj(fz_stream *stm, fz_obj *obj, int tight); +int fz_print(fz_stream *stm, char *fmt, ...); + diff --git a/include/fitz/stream.h b/include/fitz/stream.h deleted file mode 100644 index b0778373..00000000 --- a/include/fitz/stream.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Stream API for Fitz. - * Read and write data to and from files, memory buffers and filters. - */ - -typedef struct fz_stream_s fz_stream; - -enum { FZ_SFILE, FZ_SBUFFER, FZ_SFILTER }; -enum { FZ_SREAD, FZ_SWRITE }; - -struct fz_stream_s -{ - int refs; - int kind; - int mode; - int dead; - fz_buffer *buffer; - fz_filter *filter; - fz_stream *chain; - fz_error *error; - int file; -}; - -/* - * Various stream creation functions. - */ - -/* open() and creat() & co */ -fz_error *fz_openrfile(fz_stream **stmp, char *filename); -fz_error *fz_openwfile(fz_stream **stmp, char *filename); -fz_error *fz_openafile(fz_stream **stmp, char *filename); - -/* write to memory buffers! */ -fz_error *fz_openrmemory(fz_stream **stmp, char *buf, int len); -fz_error *fz_openrbuffer(fz_stream **stmp, fz_buffer *buf); -fz_error *fz_openwbuffer(fz_stream **stmp, fz_buffer *buf); - -/* almost like fork() exec() pipe() */ -fz_error *fz_openrfilter(fz_stream **stmp, fz_filter *flt, fz_stream *chain); -fz_error *fz_openwfilter(fz_stream **stmp, fz_filter *flt, fz_stream *chain); - -/* - * Functions that are common to both input and output streams. - */ - -fz_error *fz_ioerror(fz_stream *stm); - -fz_stream *fz_keepstream(fz_stream *stm); -void fz_dropstream(fz_stream *stm); - -int fz_tell(fz_stream *stm); -int fz_seek(fz_stream *stm, int offset, int whence); - -/* - * Input stream functions. - * Return EOF (-1) on errors. - */ - -int fz_rtell(fz_stream *stm); -int fz_rseek(fz_stream *stm, int offset, int whence); - -int fz_makedata(fz_stream *stm); -int fz_read(fz_stream *stm, unsigned char *buf, int len); - -int fz_readall(fz_buffer **bufp, fz_stream *stm); -int fz_readline(fz_stream *stm, char *buf, int max); - -int fz_readbytex(fz_stream *stm); -int fz_peekbytex(fz_stream *stm); - -#ifdef DEBUG -#define fz_readbyte fz_readbytex -#define fz_peekbyte fz_peekbytex -#else - -#define FZ_READBYTE(XXX) { \ - fz_buffer *buf = stm->buffer; \ - if (buf->rp == buf->wp) \ - if (fz_makedata(stm) < 0) \ - return EOF; \ - return buf->rp < buf->wp ? XXX : EOF ; \ -} - -static inline int fz_readbyte(fz_stream *stm) FZ_READBYTE(*buf->rp++) -static inline int fz_peekbyte(fz_stream *stm) FZ_READBYTE(*buf->rp) - -#endif - -/* - * Output stream functions. - * Return N or 0 on success, -1 on failure. - */ - -int fz_wtell(fz_stream *stm); -int fz_wseek(fz_stream *stm, int offset, int whence); - -int fz_write(fz_stream *stm, unsigned char *buf, int n); -int fz_flush(fz_stream *stm); - -int fz_printstr(fz_stream *stm, char *s); -int fz_printobj(fz_stream *stm, fz_obj *obj, int tight); -int fz_print(fz_stream *stm, char *fmt, ...); - diff --git a/include/fitz/sysdep.h b/include/fitz/sysdep.h deleted file mode 100644 index 4e8b1115..00000000 --- a/include/fitz/sysdep.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Include the basic standard libc headers. - */ - -#include -#include -#include -#include - -#include /* INT_MIN, MAX ... */ -#include /* DBL_EPSILON */ -#include - -#include -#include /* O_RDONLY & co */ - -#ifdef HAVE_C99 -# define FZ_FLEX -#else -# define FZ_FLEX 1 -# define restrict -# define inline __inline__ -#endif - -#ifdef WIN32 -# define vsnprintf _vsnprintf -# include -#else -# include -#endif - -#ifndef va_copy -#define va_copy(a,b) (a) = (b) -#endif - -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -/* - * Extras! Extras! Get them while they're hot! - */ - -/* not supposed to be here, but printf debugging sorta needs it */ -#include - -#ifdef NEED_MATH -#define M_E 2.71828182845904523536 -#define M_LOG2E 1.44269504088896340736 -#define M_LOG10E 0.434294481903251827651 -#define M_LN2 0.693147180559945309417 -#define M_LN10 2.30258509299404568402 -#define M_PI 3.14159265358979323846 -#define M_PI_2 1.57079632679489661923 -#define M_PI_4 0.785398163397448309616 -#define M_1_PI 0.318309886183790671538 -#define M_2_PI 0.636619772367581343076 -#define M_1_SQRTPI 0.564189583547756286948 -#define M_2_SQRTPI 1.12837916709551257390 -#define M_SQRT2 1.41421356237309504880 -#define M_SQRT_2 0.707106781186547524401 -#endif - -#ifdef NEED_STRLCPY -extern int strlcpy(char *dst, const char *src, int n); -extern int strlcat(char *dst, const char *src, int n); -#endif - -#ifdef NEED_STRSEP -extern char *strsep(char **stringp, const char *delim); -#endif - -#ifdef NEED_GETOPT -extern int getopt(int nargc, char * const * nargv, const char *ostr); -extern int opterr, optind, optopt; -extern char *optarg; -#endif - diff --git a/include/fitz/text.h b/include/fitz/text.h deleted file mode 100644 index 619aae83..00000000 --- a/include/fitz/text.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Fitz display tree text node. - * - * The text node is an optimization to reference glyphs in a font resource - * and specifying an individual transform matrix for each one. - * - * The trm field contains the a, b, c and d coefficients. - * The e and f coefficients come from the individual elements, - * together they form the transform matrix for the glyph. - * - * Glyphs are referenced by glyph ID. - * The Unicode text equivalent is kept in a separate array - * with indexes into the glyph array. - * - -TODO the unicode textels - -struct fz_textgid_s { float e, f; int gid; }; -struct fz_textucs_s { int idx; int ucs; }; - - */ - -typedef struct fz_textel_s fz_textel; - -struct fz_textel_s -{ - float x, y; - int cid; -}; - -struct fz_textnode_s -{ - fz_node super; - fz_font *font; - fz_matrix trm; - int len, cap; - fz_textel *els; -}; - -fz_error *fz_newtextnode(fz_textnode **textp, fz_font *face); -fz_error *fz_clonetextnode(fz_textnode **textp, fz_textnode *oldtext); -fz_error *fz_addtext(fz_textnode *text, int g, float x, float y); -fz_error *fz_endtext(fz_textnode *text); - diff --git a/include/fitz/tree.h b/include/fitz/tree.h deleted file mode 100644 index 324b8098..00000000 --- a/include/fitz/tree.h +++ /dev/null @@ -1,183 +0,0 @@ -/* - * The display tree is at the center of attention in Fitz. - * The tree and most of its minor nodes. - * Paths and text nodes are found elsewhere. - */ - -typedef struct fz_tree_s fz_tree; -typedef struct fz_node_s fz_node; - -struct fz_tree_s -{ - int refs; - fz_node *root; - fz_node *head; -}; - -/* tree operations */ -fz_error *fz_newtree(fz_tree **treep); -fz_tree *fz_keeptree(fz_tree *tree); -void fz_droptree(fz_tree *tree); - -fz_rect fz_boundtree(fz_tree *tree, fz_matrix ctm); -void fz_debugtree(fz_tree *tree); -void fz_insertnodefirst(fz_node *parent, fz_node *child); -void fz_insertnodelast(fz_node *parent, fz_node *child); -void fz_insertnodeafter(fz_node *prev, fz_node *child); -void fz_removenode(fz_node *child); - -fz_error *fz_optimizetree(fz_tree *tree); - -/* node types */ - -typedef struct fz_transformnode_s fz_transformnode; -typedef struct fz_overnode_s fz_overnode; -typedef struct fz_masknode_s fz_masknode; -typedef struct fz_blendnode_s fz_blendnode; -typedef struct fz_pathnode_s fz_pathnode; -typedef struct fz_textnode_s fz_textnode; -typedef struct fz_solidnode_s fz_solidnode; -typedef struct fz_imagenode_s fz_imagenode; -typedef struct fz_shadenode_s fz_shadenode; -typedef struct fz_linknode_s fz_linknode; -typedef struct fz_metanode_s fz_metanode; - -typedef enum fz_nodekind_e -{ - FZ_NTRANSFORM, - FZ_NOVER, - FZ_NMASK, - FZ_NBLEND, - FZ_NPATH, - FZ_NTEXT, - FZ_NCOLOR, - FZ_NIMAGE, - FZ_NSHADE, - FZ_NLINK, - FZ_NMETA -} fz_nodekind; - -typedef enum fz_blendkind_e -{ - /* PDF 1.4 -- standard separable */ - FZ_BNORMAL, - FZ_BMULTIPLY, - FZ_BSCREEN, - FZ_BOVERLAY, - FZ_BDARKEN, - FZ_BLIGHTEN, - FZ_BCOLORDODGE, - FZ_BCOLORBURN, - FZ_BHARDLIGHT, - FZ_BSOFTLIGHT, - FZ_BDIFFERENCE, - FZ_BEXCLUSION, - - /* PDF 1.4 -- standard non-separable */ - FZ_BHUE, - FZ_BSATURATION, - FZ_BCOLOR, - FZ_BLUMINOSITY, - - FZ_BOVERPRINT, - FZ_BRASTEROP -} fz_blendkind; - -struct fz_node_s -{ - fz_nodekind kind; - fz_node *parent; - fz_node *first; - fz_node *last; - fz_node *next; -}; - -struct fz_transformnode_s -{ - fz_node super; - fz_matrix m; -}; - -struct fz_overnode_s -{ - fz_node super; -}; - -struct fz_masknode_s -{ - fz_node super; -}; - -struct fz_blendnode_s -{ - fz_node super; - fz_colorspace *cs; - fz_blendkind mode; - int isolated; - int knockout; -}; - -struct fz_solidnode_s -{ - fz_node super; - fz_colorspace *cs; - int n; - float samples[FZ_FLEX]; -}; - -struct fz_linknode_s -{ - fz_node super; - fz_tree *tree; -}; - -struct fz_metanode_s -{ - fz_node super; - char *name; - void *dict; -}; - -struct fz_imagenode_s -{ - fz_node super; - fz_image *image; -}; - -struct fz_shadenode_s -{ - fz_node super; - fz_shade *shade; -}; - -/* common to all nodes */ -void fz_initnode(fz_node *node, fz_nodekind kind); -fz_rect fz_boundnode(fz_node *node, fz_matrix ctm); -void fz_dropnode(fz_node *node); - -/* branch nodes */ -fz_error *fz_newmetanode(fz_node **nodep, char *name, void *dict); -fz_error *fz_newovernode(fz_node **nodep); -fz_error *fz_newmasknode(fz_node **nodep); -fz_error *fz_newblendnode(fz_node **nodep, fz_colorspace *cs, fz_blendkind b, int k, int i); -fz_error *fz_newtransformnode(fz_node **nodep, fz_matrix m); - -int fz_istransformnode(fz_node *node); -int fz_isovernode(fz_node *node); -int fz_ismasknode(fz_node *node); -int fz_isblendnode(fz_node *node); -int fz_ismetanode(fz_node *node); - -/* leaf nodes */ -fz_error *fz_newlinknode(fz_node **nodep, fz_tree *subtree); -fz_error *fz_newsolidnode(fz_node **nodep, fz_colorspace *cs, int n, float *v); -fz_error *fz_newimagenode(fz_node **nodep, fz_image *image); -fz_error *fz_newshadenode(fz_node **nodep, fz_shade *shade); - -int fz_islinknode(fz_node *node); -int fz_issolidnode(fz_node *node); -int fz_ispathnode(fz_node *node); -int fz_istextnode(fz_node *node); -int fz_isimagenode(fz_node *node); -int fz_isshadenode(fz_node *node); - diff --git a/include/fitz/wld_color.h b/include/fitz/wld_color.h new file mode 100644 index 00000000..f6fae48c --- /dev/null +++ b/include/fitz/wld_color.h @@ -0,0 +1,40 @@ +typedef struct fz_colorspace_s fz_colorspace; +typedef struct fz_colorcube_s fz_colorcube; +typedef struct fz_colorcube1_s fz_colorcube1; +typedef struct fz_colorcube3_s fz_colorcube3; +typedef struct fz_colorcube4_s fz_colorcube4; + +enum { FZ_MAXCOLORS = 32 }; + +struct fz_colorspace_s +{ + int refs; + char name[16]; + int n; + void (*convpixmap)(fz_colorspace *ss, fz_pixmap *sp, fz_colorspace *ds, fz_pixmap *dp); + void (*convcolor)(fz_colorspace *ss, float *sv, fz_colorspace *ds, float *dv); + void (*toxyz)(fz_colorspace *, float *src, float *xyz); + void (*fromxyz)(fz_colorspace *, float *xyz, float *dst); + void (*drop)(fz_colorspace *); +}; + +struct fz_colorcube1_s { unsigned char v[17]; }; +struct fz_colorcube3_s { unsigned char v[17][17][17]; }; +struct fz_colorcube4_s { unsigned char v[17][17][17][17]; }; + +struct fz_colorcube_s +{ + fz_colorspace *src; + fz_colorspace *dst; + void **subcube; /* dst->n * colorcube(src->n) */ +}; + +fz_colorspace *fz_keepcolorspace(fz_colorspace *cs); +void fz_dropcolorspace(fz_colorspace *cs); + +void fz_convertcolor(fz_colorspace *srcs, float *srcv, fz_colorspace *dsts, float *dstv); +void fz_convertpixmap(fz_colorspace *srcs, fz_pixmap *srcv, fz_colorspace *dsts, fz_pixmap *dstv); + +void fz_stdconvcolor(fz_colorspace *srcs, float *srcv, fz_colorspace *dsts, float *dstv); +void fz_stdconvpixmap(fz_colorspace *srcs, fz_pixmap *srcv, fz_colorspace *dsts, fz_pixmap *dstv); + diff --git a/include/fitz/wld_font.h b/include/fitz/wld_font.h new file mode 100644 index 00000000..27217c6c --- /dev/null +++ b/include/fitz/wld_font.h @@ -0,0 +1,68 @@ +typedef struct fz_font_s fz_font; +typedef struct fz_hmtx_s fz_hmtx; +typedef struct fz_vmtx_s fz_vmtx; +typedef struct fz_glyph_s fz_glyph; +typedef struct fz_glyphcache_s fz_glyphcache; + +struct fz_hmtx_s +{ + unsigned short lo; + unsigned short hi; + int w; /* type3 fonts can be big! */ +}; + +struct fz_vmtx_s +{ + unsigned short lo; + unsigned short hi; + short x; + short y; + short w; +}; + +struct fz_font_s +{ + int refs; + char name[32]; + + fz_error* (*render)(fz_glyph*, fz_font*, int, fz_matrix); + void (*drop)(fz_font *); + + int wmode; + fz_irect bbox; + + int nhmtx, hmtxcap; + fz_hmtx dhmtx; + fz_hmtx *hmtx; + + int nvmtx, vmtxcap; + fz_vmtx dvmtx; + fz_vmtx *vmtx; +}; + +struct fz_glyph_s +{ + int x, y, w, h; + unsigned char *samples; +}; + +void fz_initfont(fz_font *font, char *name); +fz_font *fz_keepfont(fz_font *font); +void fz_dropfont(fz_font *font); +void fz_debugfont(fz_font *font); +void fz_setfontwmode(fz_font *font, int wmode); +void fz_setfontbbox(fz_font *font, int xmin, int ymin, int xmax, int ymax); +void fz_setdefaulthmtx(fz_font *font, int w); +void fz_setdefaultvmtx(fz_font *font, int y, int w); +fz_error *fz_addhmtx(fz_font *font, int lo, int hi, int w); +fz_error *fz_addvmtx(fz_font *font, int lo, int hi, int x, int y, int w); +fz_error *fz_endhmtx(fz_font *font); +fz_error *fz_endvmtx(fz_font *font); +fz_hmtx fz_gethmtx(fz_font *font, int cid); +fz_vmtx fz_getvmtx(fz_font *font, int cid); + +fz_error *fz_newglyphcache(fz_glyphcache **arenap, int slots, int size); +fz_error *fz_renderglyph(fz_glyphcache*, fz_glyph*, fz_font*, int, fz_matrix); +void fz_debugglyphcache(fz_glyphcache *); +void fz_dropglyphcache(fz_glyphcache *); + diff --git a/include/fitz/wld_image.h b/include/fitz/wld_image.h new file mode 100644 index 00000000..89d180ba --- /dev/null +++ b/include/fitz/wld_image.h @@ -0,0 +1,16 @@ +typedef struct fz_image_s fz_image; + +/* loadtile will fill a pixmap with the pixel samples. non-premultiplied alpha. */ + +struct fz_image_s +{ + int refs; + fz_error* (*loadtile)(fz_image*,fz_pixmap*); + void (*drop)(fz_image*); + fz_colorspace *cs; + int w, h, n, a; +}; + +fz_image *fz_keepimage(fz_image *img); +void fz_dropimage(fz_image *img); + diff --git a/include/fitz/wld_path.h b/include/fitz/wld_path.h new file mode 100644 index 00000000..6a7c55b7 --- /dev/null +++ b/include/fitz/wld_path.h @@ -0,0 +1,83 @@ +/* + * Vector path nodes in the display tree. + * They can be stroked and dashed, or be filled. + * They have a fill rule (nonzero or evenodd). + * + * When rendering, they are flattened, stroked and dashed straight + * into the Global Edge List. + * + * TODO flatten, stroke and dash into another path + * TODO set operations on flat paths (union, intersect, difference) + * TODO decide whether dashing should be part of the tree and renderer, + * or if it is something the client has to do (with a util function). + */ + +typedef struct fz_stroke_s fz_stroke; +typedef struct fz_dash_s fz_dash; +typedef union fz_pathel_s fz_pathel; + +typedef enum fz_pathkind_e +{ + FZ_STROKE, + FZ_FILL, + FZ_EOFILL +} fz_pathkind; + +typedef enum fz_pathelkind_e +{ + FZ_MOVETO, + FZ_LINETO, + FZ_CURVETO, + FZ_CLOSEPATH +} fz_pathelkind; + +struct fz_stroke_s +{ + int linecap; + int linejoin; + float linewidth; + float miterlimit; +}; + +struct fz_dash_s +{ + int len; + float phase; + float array[FZ_FLEX]; +}; + +union fz_pathel_s +{ + fz_pathelkind k; + float v; +}; + +struct fz_pathnode_s +{ + fz_node super; + fz_pathkind paint; + fz_dash *dash; + int linecap; + int linejoin; + float linewidth; + float miterlimit; + int len, cap; + fz_pathel *els; +}; + +fz_error *fz_newpathnode(fz_pathnode **pathp); +fz_error *fz_clonepathnode(fz_pathnode **pathp, fz_pathnode *oldpath); +fz_error *fz_moveto(fz_pathnode*, float x, float y); +fz_error *fz_lineto(fz_pathnode*, float x, float y); +fz_error *fz_curveto(fz_pathnode*, float, float, float, float, float, float); +fz_error *fz_curvetov(fz_pathnode*, float, float, float, float); +fz_error *fz_curvetoy(fz_pathnode*, float, float, float, float); +fz_error *fz_closepath(fz_pathnode*); +fz_error *fz_endpath(fz_pathnode*, fz_pathkind paint, fz_stroke *stroke, fz_dash *dash); + +fz_rect fz_boundpathnode(fz_pathnode *node, fz_matrix ctm); +void fz_debugpathnode(fz_pathnode *node); + +fz_error *fz_newdash(fz_dash **dashp, float phase, int len, float *array); +void fz_dropdash(fz_dash *dash); + diff --git a/include/fitz/wld_shade.h b/include/fitz/wld_shade.h new file mode 100644 index 00000000..1b7c81c5 --- /dev/null +++ b/include/fitz/wld_shade.h @@ -0,0 +1,29 @@ +typedef struct fz_shade_s fz_shade; + +struct fz_shade_s +{ + int refs; + + fz_rect bbox; /* can be fz_infiniterect */ + fz_colorspace *cs; + + /* used by build.c -- not used in drawshade.c */ + fz_matrix matrix; /* matrix from pattern dict */ + int usebackground; /* background color for fills but not 'sh' */ + float background[FZ_MAXCOLORS]; + + int usefunction; + float function[256][FZ_MAXCOLORS]; + + int meshlen; + int meshcap; + float *mesh; /* [x y t] or [x y c1 ... cn] * 3 * meshlen */ +}; + + +fz_shade *fz_keepshade(fz_shade *shade); +void fz_dropshade(fz_shade *shade); + +fz_rect fz_boundshade(fz_shade *shade, fz_matrix ctm); +fz_error *fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_colorspace *dsts, fz_pixmap *dstp); + diff --git a/include/fitz/wld_text.h b/include/fitz/wld_text.h new file mode 100644 index 00000000..619aae83 --- /dev/null +++ b/include/fitz/wld_text.h @@ -0,0 +1,44 @@ +/* + * Fitz display tree text node. + * + * The text node is an optimization to reference glyphs in a font resource + * and specifying an individual transform matrix for each one. + * + * The trm field contains the a, b, c and d coefficients. + * The e and f coefficients come from the individual elements, + * together they form the transform matrix for the glyph. + * + * Glyphs are referenced by glyph ID. + * The Unicode text equivalent is kept in a separate array + * with indexes into the glyph array. + * + +TODO the unicode textels + +struct fz_textgid_s { float e, f; int gid; }; +struct fz_textucs_s { int idx; int ucs; }; + + */ + +typedef struct fz_textel_s fz_textel; + +struct fz_textel_s +{ + float x, y; + int cid; +}; + +struct fz_textnode_s +{ + fz_node super; + fz_font *font; + fz_matrix trm; + int len, cap; + fz_textel *els; +}; + +fz_error *fz_newtextnode(fz_textnode **textp, fz_font *face); +fz_error *fz_clonetextnode(fz_textnode **textp, fz_textnode *oldtext); +fz_error *fz_addtext(fz_textnode *text, int g, float x, float y); +fz_error *fz_endtext(fz_textnode *text); + diff --git a/include/fitz/wld_tree.h b/include/fitz/wld_tree.h new file mode 100644 index 00000000..324b8098 --- /dev/null +++ b/include/fitz/wld_tree.h @@ -0,0 +1,183 @@ +/* + * The display tree is at the center of attention in Fitz. + * The tree and most of its minor nodes. + * Paths and text nodes are found elsewhere. + */ + +typedef struct fz_tree_s fz_tree; +typedef struct fz_node_s fz_node; + +struct fz_tree_s +{ + int refs; + fz_node *root; + fz_node *head; +}; + +/* tree operations */ +fz_error *fz_newtree(fz_tree **treep); +fz_tree *fz_keeptree(fz_tree *tree); +void fz_droptree(fz_tree *tree); + +fz_rect fz_boundtree(fz_tree *tree, fz_matrix ctm); +void fz_debugtree(fz_tree *tree); +void fz_insertnodefirst(fz_node *parent, fz_node *child); +void fz_insertnodelast(fz_node *parent, fz_node *child); +void fz_insertnodeafter(fz_node *prev, fz_node *child); +void fz_removenode(fz_node *child); + +fz_error *fz_optimizetree(fz_tree *tree); + +/* node types */ + +typedef struct fz_transformnode_s fz_transformnode; +typedef struct fz_overnode_s fz_overnode; +typedef struct fz_masknode_s fz_masknode; +typedef struct fz_blendnode_s fz_blendnode; +typedef struct fz_pathnode_s fz_pathnode; +typedef struct fz_textnode_s fz_textnode; +typedef struct fz_solidnode_s fz_solidnode; +typedef struct fz_imagenode_s fz_imagenode; +typedef struct fz_shadenode_s fz_shadenode; +typedef struct fz_linknode_s fz_linknode; +typedef struct fz_metanode_s fz_metanode; + +typedef enum fz_nodekind_e +{ + FZ_NTRANSFORM, + FZ_NOVER, + FZ_NMASK, + FZ_NBLEND, + FZ_NPATH, + FZ_NTEXT, + FZ_NCOLOR, + FZ_NIMAGE, + FZ_NSHADE, + FZ_NLINK, + FZ_NMETA +} fz_nodekind; + +typedef enum fz_blendkind_e +{ + /* PDF 1.4 -- standard separable */ + FZ_BNORMAL, + FZ_BMULTIPLY, + FZ_BSCREEN, + FZ_BOVERLAY, + FZ_BDARKEN, + FZ_BLIGHTEN, + FZ_BCOLORDODGE, + FZ_BCOLORBURN, + FZ_BHARDLIGHT, + FZ_BSOFTLIGHT, + FZ_BDIFFERENCE, + FZ_BEXCLUSION, + + /* PDF 1.4 -- standard non-separable */ + FZ_BHUE, + FZ_BSATURATION, + FZ_BCOLOR, + FZ_BLUMINOSITY, + + FZ_BOVERPRINT, + FZ_BRASTEROP +} fz_blendkind; + +struct fz_node_s +{ + fz_nodekind kind; + fz_node *parent; + fz_node *first; + fz_node *last; + fz_node *next; +}; + +struct fz_transformnode_s +{ + fz_node super; + fz_matrix m; +}; + +struct fz_overnode_s +{ + fz_node super; +}; + +struct fz_masknode_s +{ + fz_node super; +}; + +struct fz_blendnode_s +{ + fz_node super; + fz_colorspace *cs; + fz_blendkind mode; + int isolated; + int knockout; +}; + +struct fz_solidnode_s +{ + fz_node super; + fz_colorspace *cs; + int n; + float samples[FZ_FLEX]; +}; + +struct fz_linknode_s +{ + fz_node super; + fz_tree *tree; +}; + +struct fz_metanode_s +{ + fz_node super; + char *name; + void *dict; +}; + +struct fz_imagenode_s +{ + fz_node super; + fz_image *image; +}; + +struct fz_shadenode_s +{ + fz_node super; + fz_shade *shade; +}; + +/* common to all nodes */ +void fz_initnode(fz_node *node, fz_nodekind kind); +fz_rect fz_boundnode(fz_node *node, fz_matrix ctm); +void fz_dropnode(fz_node *node); + +/* branch nodes */ +fz_error *fz_newmetanode(fz_node **nodep, char *name, void *dict); +fz_error *fz_newovernode(fz_node **nodep); +fz_error *fz_newmasknode(fz_node **nodep); +fz_error *fz_newblendnode(fz_node **nodep, fz_colorspace *cs, fz_blendkind b, int k, int i); +fz_error *fz_newtransformnode(fz_node **nodep, fz_matrix m); + +int fz_istransformnode(fz_node *node); +int fz_isovernode(fz_node *node); +int fz_ismasknode(fz_node *node); +int fz_isblendnode(fz_node *node); +int fz_ismetanode(fz_node *node); + +/* leaf nodes */ +fz_error *fz_newlinknode(fz_node **nodep, fz_tree *subtree); +fz_error *fz_newsolidnode(fz_node **nodep, fz_colorspace *cs, int n, float *v); +fz_error *fz_newimagenode(fz_node **nodep, fz_image *image); +fz_error *fz_newshadenode(fz_node **nodep, fz_shade *shade); + +int fz_islinknode(fz_node *node); +int fz_issolidnode(fz_node *node); +int fz_ispathnode(fz_node *node); +int fz_istextnode(fz_node *node); +int fz_isimagenode(fz_node *node); +int fz_isshadenode(fz_node *node); + -- cgit v1.2.3