diff options
Diffstat (limited to 'fitz')
55 files changed, 1462 insertions, 95 deletions
diff --git a/fitz/base_cpudep.c b/fitz/base_cpudep.c index 51273a59..ebd6a648 100644 --- a/fitz/base_cpudep.c +++ b/fitz/base_cpudep.c @@ -5,7 +5,7 @@ mm, alphabet soup... Glenn Kennard <d98gk@efd.lth.se> */ -#include "fitz-base.h" +#include "fitz_base.h" /* global run-time constant */ unsigned fz_cpuflags = 0; diff --git a/fitz/base_error.c b/fitz/base_error.c index 461ffc60..a2ebbdd5 100644 --- a/fitz/base_error.c +++ b/fitz/base_error.c @@ -1,4 +1,4 @@ -#include "fitz-base.h" +#include "fitz_base.h" void fz_droperror(fz_error *eo) diff --git a/fitz/base_hash.c b/fitz/base_hash.c index c7086ca9..bbf90807 100644 --- a/fitz/base_hash.c +++ b/fitz/base_hash.c @@ -9,7 +9,7 @@ * and removed frequently. */ -#include "fitz-base.h" +#include "fitz_base.h" enum { MAXKEYLEN = 16 }; diff --git a/fitz/base_matrix.c b/fitz/base_matrix.c index 364b287c..43de613d 100644 --- a/fitz/base_matrix.c +++ b/fitz/base_matrix.c @@ -1,4 +1,4 @@ -#include "fitz-base.h" +#include "fitz_base.h" void fz_invert3x3(float *dst, float *m) { diff --git a/fitz/base_memory.c b/fitz/base_memory.c index 8c2c0249..f124f8cc 100644 --- a/fitz/base_memory.c +++ b/fitz/base_memory.c @@ -1,4 +1,4 @@ -#include "fitz-base.h" +#include "fitz_base.h" /* Make this thread local storage if you wish. */ diff --git a/fitz/base_rect.c b/fitz/base_rect.c index 3c00cb94..f0606163 100644 --- a/fitz/base_rect.c +++ b/fitz/base_rect.c @@ -1,4 +1,4 @@ -#include "fitz-base.h" +#include "fitz_base.h" fz_rect fz_infiniterect = { 1, 1, -1, -1 }; fz_rect fz_emptyrect = { 0, 0, 0, 0 }; diff --git a/fitz/crypt_arc4.c b/fitz/crypt_arc4.c index fc4d487c..01a5b90d 100644 --- a/fitz/crypt_arc4.c +++ b/fitz/crypt_arc4.c @@ -21,8 +21,8 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" void fz_arc4init(fz_arc4 *arc4, const unsigned char *key, const unsigned keylen) diff --git a/fitz/crypt_crc32.c b/fitz/crypt_crc32.c index dded733e..c83759ac 100644 --- a/fitz/crypt_crc32.c +++ b/fitz/crypt_crc32.c @@ -2,8 +2,8 @@ * Compute the CRC-32 of a data buffer */ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" static const unsigned long crctab[256] = { diff --git a/fitz/crypt_md5.c b/fitz/crypt_md5.c index 8f665329..5851a156 100644 --- a/fitz/crypt_md5.c +++ b/fitz/crypt_md5.c @@ -23,8 +23,8 @@ These notices must be retained in any copies of any part of this documentation and/or software. */ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" /* Constants for MD5Transform routine */ enum diff --git a/fitz/filt_a85d.c b/fitz/filt_a85d.c index 19ba9e9a..92ae2f6f 100644 --- a/fitz/filt_a85d.c +++ b/fitz/filt_a85d.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" typedef struct fz_a85d_s fz_a85d; diff --git a/fitz/filt_a85e.c b/fitz/filt_a85e.c index 386d8bb3..4ae8a6b1 100644 --- a/fitz/filt_a85e.c +++ b/fitz/filt_a85e.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" typedef struct fz_a85e_s fz_a85e; diff --git a/fitz/filt_ahxd.c b/fitz/filt_ahxd.c index 0feb10c2..a7fb336d 100644 --- a/fitz/filt_ahxd.c +++ b/fitz/filt_ahxd.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" typedef struct fz_ahxd_s fz_ahxd; diff --git a/fitz/filt_ahxe.c b/fitz/filt_ahxe.c index 0fc727c3..4ccd1098 100644 --- a/fitz/filt_ahxe.c +++ b/fitz/filt_ahxe.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" typedef struct fz_ahxe_s fz_ahxe; diff --git a/fitz/filt_arc4.c b/fitz/filt_arc4.c index af038599..968db7b2 100644 --- a/fitz/filt_arc4.c +++ b/fitz/filt_arc4.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" typedef struct fz_arc4c_s fz_arc4c; diff --git a/fitz/filt_dctd.c b/fitz/filt_dctd.c index 3425b8e5..6054a9e6 100644 --- a/fitz/filt_dctd.c +++ b/fitz/filt_dctd.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" #include "filt_dctc.h" diff --git a/fitz/filt_dcte.c b/fitz/filt_dcte.c index 5380c6b1..bb95ad9b 100644 --- a/fitz/filt_dcte.c +++ b/fitz/filt_dcte.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" #include "filt_dctc.h" diff --git a/fitz/filt_faxd.c b/fitz/filt_faxd.c index 3eaf5f3b..7223f802 100644 --- a/fitz/filt_faxd.c +++ b/fitz/filt_faxd.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" #include "filt_faxd.h" #include "filt_faxc.h" diff --git a/fitz/filt_faxe.c b/fitz/filt_faxe.c index 7551fb80..d9358546 100644 --- a/fitz/filt_faxe.c +++ b/fitz/filt_faxe.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" #include "filt_faxe.h" #include "filt_faxc.h" diff --git a/fitz/filt_flate.c b/fitz/filt_flate.c index 6a86da3a..056e8670 100644 --- a/fitz/filt_flate.c +++ b/fitz/filt_flate.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" #include <zlib.h> diff --git a/fitz/filt_jbig2d.c b/fitz/filt_jbig2d.c index 3569d3eb..7ec5dec0 100644 --- a/fitz/filt_jbig2d.c +++ b/fitz/filt_jbig2d.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" /* TODO: complete rewrite with error checking and use fitz memctx */ diff --git a/fitz/filt_jpxd.c b/fitz/filt_jpxd.c index 28dc87de..35323e29 100644 --- a/fitz/filt_jpxd.c +++ b/fitz/filt_jpxd.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" /* TODO: bpc */ diff --git a/fitz/filt_lzwd.c b/fitz/filt_lzwd.c index c4aed45b..ef491f04 100644 --- a/fitz/filt_lzwd.c +++ b/fitz/filt_lzwd.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" /* TODO: error checking */ diff --git a/fitz/filt_lzwe.c b/fitz/filt_lzwe.c index 5a221f9f..c691456b 100644 --- a/fitz/filt_lzwe.c +++ b/fitz/filt_lzwe.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" #define noDEBUG 1 diff --git a/fitz/filt_null.c b/fitz/filt_null.c index 601ed815..08478c0b 100644 --- a/fitz/filt_null.c +++ b/fitz/filt_null.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" typedef struct fz_nullfilter_s fz_nullfilter; diff --git a/fitz/filt_pipeline.c b/fitz/filt_pipeline.c index ea0b9885..c6b28ebd 100644 --- a/fitz/filt_pipeline.c +++ b/fitz/filt_pipeline.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" #define noDEBUG 1 diff --git a/fitz/filt_predict.c b/fitz/filt_predict.c index 4654e792..fff5a8ce 100644 --- a/fitz/filt_predict.c +++ b/fitz/filt_predict.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" /* TODO: check if this works with 16bpp images */ diff --git a/fitz/filt_rld.c b/fitz/filt_rld.c index 9b0ed75f..53acd615 100644 --- a/fitz/filt_rld.c +++ b/fitz/filt_rld.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" fz_error * fz_newrld(fz_filter **fp, fz_obj *params) diff --git a/fitz/filt_rle.c b/fitz/filt_rle.c index 65c2a7a4..f0284d4c 100644 --- a/fitz/filt_rle.c +++ b/fitz/filt_rle.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" /* TODO: rewrite! * make it non-optimal or something, diff --git a/fitz/fitz.h b/fitz/fitz.h new file mode 100644 index 00000000..0e9bcd08 --- /dev/null +++ b/fitz/fitz.h @@ -0,0 +1,10 @@ +#ifndef _FITZ_H_ +#define _FITZ_H_ + +#include "fitz_base.h" +#include "fitz_stream.h" +#include "fitz_tree.h" +#include "fitz_draw.h" + +#endif + diff --git a/fitz/fitz_base.h b/fitz/fitz_base.h new file mode 100644 index 00000000..cd8d90ee --- /dev/null +++ b/fitz/fitz_base.h @@ -0,0 +1,364 @@ +/* + * Include the basic standard libc headers. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stddef.h> +#include <string.h> +#include <assert.h> +#include <stdarg.h> + +#include <limits.h> /* INT_MIN, MAX ... */ +#include <float.h> /* DBL_EPSILON */ +#include <math.h> + +#include <errno.h> +#include <fcntl.h> /* O_RDONLY & co */ + +/* Stupid macros that don't exist everywhere */ + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#ifndef M_SQRT2 +#define M_SQRT2 1.41421356237309504880 +#endif + +/* Some useful semi-standard functions */ + +#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 + +#ifdef MSVC /* stupid stone-age compiler */ + +#include <io.h> + +extern int gettimeofday(struct timeval *tv, struct timezone *tz); + +#define FZ_FLEX 1 +#define restrict + +#ifdef _MSC_VER +#define inline __inline +#else +#define inline __inline__ +#endif + +#define __func__ __FUNCTION__ + +#if _MSC_VER < 1500 +#define vsnprintf _vsnprintf +#endif + +#ifndef isnan +#define isnan _isnan +#endif + +#ifndef va_copy +#define va_copy(a,b) (a) = (b) +#endif + +#ifndef R_OK +#define R_OK 4 +#endif + +#else /* C99 or close enough */ + +#include <unistd.h> +#define FZ_FLEX + +#endif + +/* + * CPU detection and flags + */ + +#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; + +/* + * Base Fitz runtime. + */ + +#ifndef __printflike +#if __GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ >= 7 +#define __printflike(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf__, fmtarg, firstvararg))) +#else +#define __printflike(fmtarg, firstvararg) +#endif +#endif + +#ifndef nil +#define nil ((void*)0) +#endif + +#ifndef offsetof +#define offsetof(s, m) (unsigned long)(&(((s*)0)->m)) +#endif + +#ifndef nelem +#define nelem(x) (sizeof(x)/sizeof((x)[0])) +#endif + +#ifndef ABS +#define ABS(x) ( (x) < 0 ? -(x) : (x) ) +#endif + +#ifndef MAX +#define MAX(a,b) ( (a) > (b) ? (a) : (b) ) +#endif + +#ifndef MIN +#define MIN(a,b) ( (a) < (b) ? (a) : (b) ) +#endif + +#ifndef CLAMP +#define CLAMP(x,a,b) ( (x) > (b) ? (b) : ( (x) < (a) ? (a) : (x) ) ) +#endif + +#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 +{ + char msg[184]; + char file[32]; + char func[32]; + int line; + fz_error *cause; +}; + +#define fz_outofmem (&fz_koutofmem) +extern fz_error fz_koutofmem; + +void fz_printerror(fz_error *eo); +void fz_droperror(fz_error *eo); +void fz_warn(char *fmt, ...) __printflike(1,2); + +#define fz_throw(...) fz_throwimp(nil, __func__, __FILE__, __LINE__, __VA_ARGS__) +#define fz_rethrow(cause, ...) fz_throwimp(cause, __func__, __FILE__, __LINE__, __VA_ARGS__) +#define fz_okay ((fz_error*)0) + +fz_error *fz_throwimp(fz_error *cause, const char *func, const char *file, int line, char *fmt, ...) __printflike(5, 6); + +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); + +/* + * 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); + +/* 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; +} + +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); + +/* + *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, char *prefix); +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); + +/* needed for tiled rendering */ +fz_error *fz_newscaledpixmap(fz_pixmap **dstp, int w, int h, int n, int xdenom, int ydenom); +fz_error *fz_scalepixmaptile(fz_pixmap *dstp, int xoffs, int yoffs, + fz_pixmap *tile, int xdenom, int ydenom); + diff --git a/fitz/fitz_draw.h b/fitz/fitz_draw.h new file mode 100644 index 00000000..fc7d0a78 --- /dev/null +++ b/fitz/fitz_draw.h @@ -0,0 +1,129 @@ +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 + +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 +{ + fz_irect clip; + fz_irect bbox; + 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, fz_irect clip); +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 *argb, 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, float linewidth); +fz_error *fz_dashpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness, float linewidth); + + +/* + * 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*,unsigned char,int,FZ_BYTE*); +extern void (*fz_path_1o1)(FZ_BYTE*,unsigned char,int,FZ_BYTE*); +extern void (*fz_path_w4i1o4)(FZ_BYTE*,FZ_BYTE*,unsigned char,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_w4i1o4)(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_w4i1o4)(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 argb[7]; /* alpha, a*r, a*g, a*b, r, g, b */ + 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/fitz/fitz_stream.h b/fitz/fitz_stream.h new file mode 100644 index 00000000..94d1a360 --- /dev/null +++ b/fitz/fitz_stream.h @@ -0,0 +1,429 @@ +/* + * 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, ...); + +char *fz_objkindstr(fz_obj *obj); + +/* + * 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); + +/* + * 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 + * done -- remember if we've ever returned fz_iodone + * + * 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_throw("outofmem: %s filter struct", #NAME); \ + (*fp)->refs = 1; \ + (*fp)->process = fz_process ## NAME ; \ + (*fp)->drop = fz_drop ## NAME ; \ + (*fp)->consumed = 0; \ + (*fp)->produced = 0; \ + (*fp)->count = 0; \ + (*fp)->done = 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; + int done; +}; + +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); + +/* + * Basic crypto functions. + * Independent of the rest of fitz. + * For further encapsulation in filters, or not. + */ + +/* crc-32 checksum */ + +unsigned long fz_crc32(unsigned long crc, unsigned char *buf, int len); + +/* 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, const unsigned char *input, const 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, const unsigned char *key, const unsigned len); +unsigned char fz_arc4next(fz_arc4 *state); +void fz_arc4encrypt(fz_arc4 *state, unsigned char *dest, const unsigned char *src, const unsigned len); + +/* TODO: sha1 */ +/* TODO: aes */ + +/* + * 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; /* delayed error from readbyte and peekbyte */ + 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, unsigned char *mem, 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_stream *fz_keepstream(fz_stream *stm); +void fz_dropstream(fz_stream *stm); + +int fz_tell(fz_stream *stm); +fz_error * fz_seek(fz_stream *stm, int offset, int whence); + +/* + * Input stream functions. + */ + +int fz_rtell(fz_stream *stm); +fz_error * fz_rseek(fz_stream *stm, int offset, int whence); + +fz_error * fz_readimp(fz_stream *stm); +fz_error * fz_read(int *np, fz_stream *stm, unsigned char *buf, int len); +fz_error * fz_readall(fz_buffer **bufp, fz_stream *stm, int sizehint); +fz_error * fz_readline(fz_stream *stm, char *buf, int max); + +/* + * Error handling when reading with readbyte/peekbyte is non-standard. + * The cause of an error is stuck into the stream struct, + * and EOF is returned. Not good, but any other way is too painful. + * So we have to be careful to check the error status eventually. + */ + +fz_error *fz_readerror(fz_stream *stm); +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 + +static inline int fz_readbyte(fz_stream *stm) +{ + fz_buffer *buf = stm->buffer; + if (buf->rp < buf->wp) + return *buf->rp++; + return fz_readbytex(stm); +} + +static inline int fz_peekbyte(fz_stream *stm) +{ + fz_buffer *buf = stm->buffer; + if (buf->rp < buf->wp) + return *buf->rp; + return fz_peekbytex(stm); +} + +#endif + +/* + * Output stream functions. + */ + +int fz_wtell(fz_stream *stm); +fz_error * fz_wseek(fz_stream *stm, int offset, int whence); + +fz_error * fz_write(fz_stream *stm, unsigned char *buf, int n); +fz_error * fz_flush(fz_stream *stm); + +fz_error * fz_printstr(fz_stream *stm, char *s); +fz_error * fz_printobj(fz_stream *stm, fz_obj *obj, int tight); +fz_error * fz_print(fz_stream *stm, char *fmt, ...); + diff --git a/fitz/fitz_tree.h b/fitz/fitz_tree.h new file mode 100644 index 00000000..407656b0 --- /dev/null +++ b/fitz/fitz_tree.h @@ -0,0 +1,435 @@ +/* + * 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; + +typedef struct fz_colorspace_s fz_colorspace; +typedef struct fz_image_s fz_image; +typedef struct fz_shade_s fz_shade; +typedef struct fz_font_s fz_font; + +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 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_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 a; + float samples[FZ_FLEX]; +}; + +struct fz_linknode_s +{ + fz_node super; + fz_tree *tree; +}; + +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_newovernode(fz_node **nodep); +fz_error *fz_newmasknode(fz_node **nodep); +fz_error *fz_newblendnode(fz_node **nodep, 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); + +/* leaf nodes */ +fz_error *fz_newlinknode(fz_node **nodep, fz_tree *subtree); +fz_error *fz_newsolidnode(fz_node **nodep, float a, 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); + +/* + * 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, int indent); +void fz_printpathnode(fz_pathnode *node, int indent); + +fz_error *fz_newdash(fz_dash **dashp, float phase, int len, float *array); +void fz_dropdash(fz_dash *dash); + +/* + * 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 gid; + int ucs; +}; + +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 gid, int ucs, float x, float y); +fz_error *fz_endtext(fz_textnode *text); + +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); + +typedef struct fz_glyph_s fz_glyph; +typedef struct fz_glyphcache_s fz_glyphcache; + +char *ft_errorstring(int err); + +struct fz_font_s +{ + int refs; + char name[32]; + + void *ftface; /* has an FT_Face if used */ + int ftsubstitute; /* ... substitute metrics */ + int fthint; /* ... force hinting for DynaLab fonts */ + + struct fz_tree_s **t3procs; /* has 256 entries if used */ + fz_matrix t3matrix; + + fz_irect bbox; + +}; + +struct fz_glyph_s +{ + int x, y, w, h; + unsigned char *samples; +}; + +fz_error * fz_newfreetypefont(fz_font **fontp, char *name, int substitute); +fz_error * fz_loadfreetypefontfile(fz_font *font, char *path, int index); +fz_error * fz_loadfreetypefontbuffer(fz_font *font, unsigned char *data, int len, int index); +fz_error * fz_newtype3font(fz_font **fontp, char *name, fz_matrix matrix, void **procs); + +fz_error * fz_newfontfrombuffer(fz_font **fontp, unsigned char *data, int len, int index); +fz_error * fz_newfontfromfile(fz_font **fontp, char *path, int index); + +fz_font * fz_keepfont(fz_font *font); +void fz_dropfont(fz_font *font); + +void fz_debugfont(fz_font *font); +void fz_setfontbbox(fz_font *font, int xmin, int ymin, int xmax, int ymax); + +fz_error * fz_renderftglyph(fz_glyph *glyph, fz_font *font, int cid, fz_matrix trm); +fz_error * fz_rendert3glyph(fz_glyph *glyph, fz_font *font, int cid, fz_matrix trm); +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 *); + +/* 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); + +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/fitz/node_misc1.c b/fitz/node_misc1.c index fc8407d5..4e390265 100644 --- a/fitz/node_misc1.c +++ b/fitz/node_misc1.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-world.h" +#include "fitz_base.h" +#include "fitz_tree.h" void fz_droplinknode(fz_linknode* node); void fz_droppathnode(fz_pathnode* node); diff --git a/fitz/node_misc2.c b/fitz/node_misc2.c index b83678d1..be442dd0 100644 --- a/fitz/node_misc2.c +++ b/fitz/node_misc2.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-world.h" +#include "fitz_base.h" +#include "fitz_tree.h" /* * Over diff --git a/fitz/node_optimize.c b/fitz/node_optimize.c index cb3918e1..78a014f7 100644 --- a/fitz/node_optimize.c +++ b/fitz/node_optimize.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-world.h" +#include "fitz_base.h" +#include "fitz_tree.h" /* * Remove (mask ... white) until we get something not white diff --git a/fitz/node_path.c b/fitz/node_path.c index b5aea542..3b288347 100644 --- a/fitz/node_path.c +++ b/fitz/node_path.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-world.h" +#include "fitz_base.h" +#include "fitz_tree.h" fz_error * fz_newpathnode(fz_pathnode **pathp) diff --git a/fitz/node_text.c b/fitz/node_text.c index 86a523df..dc89c3eb 100644 --- a/fitz/node_text.c +++ b/fitz/node_text.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-world.h" +#include "fitz_base.h" +#include "fitz_tree.h" fz_error * fz_newtextnode(fz_textnode **textp, fz_font *font) diff --git a/fitz/node_toxml.c b/fitz/node_toxml.c index cc87c997..27845609 100644 --- a/fitz/node_toxml.c +++ b/fitz/node_toxml.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-world.h" +#include "fitz_base.h" +#include "fitz_tree.h" static void indent(int level) { diff --git a/fitz/node_tree.c b/fitz/node_tree.c index f5698bc1..1bdac451 100644 --- a/fitz/node_tree.c +++ b/fitz/node_tree.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-world.h" +#include "fitz_base.h" +#include "fitz_tree.h" fz_error * fz_newtree(fz_tree **treep) diff --git a/fitz/obj_array.c b/fitz/obj_array.c index 3953470a..72a533f3 100644 --- a/fitz/obj_array.c +++ b/fitz/obj_array.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" void fz_droparray(fz_obj *obj); diff --git a/fitz/obj_dict.c b/fitz/obj_dict.c index 236c8a1a..d8c6226e 100644 --- a/fitz/obj_dict.c +++ b/fitz/obj_dict.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" /* keep either names or strings in the dict. don't mix & match. */ diff --git a/fitz/obj_parse.c b/fitz/obj_parse.c index 48d59538..4282ca3d 100644 --- a/fitz/obj_parse.c +++ b/fitz/obj_parse.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" struct vap { va_list ap; }; diff --git a/fitz/obj_print.c b/fitz/obj_print.c index 4e321127..0c3eba42 100644 --- a/fitz/obj_print.c +++ b/fitz/obj_print.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" struct fmt { diff --git a/fitz/obj_simple.c b/fitz/obj_simple.c index d8eb77b7..d21bcda8 100644 --- a/fitz/obj_simple.c +++ b/fitz/obj_simple.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" extern void fz_droparray(fz_obj *array); extern void fz_dropdict(fz_obj *dict); diff --git a/fitz/res_colorspace.c b/fitz/res_colorspace.c index 04fc532e..63378538 100644 --- a/fitz/res_colorspace.c +++ b/fitz/res_colorspace.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-world.h" +#include "fitz_base.h" +#include "fitz_tree.h" void fz_convertpixmap(fz_colorspace *srcs, fz_pixmap *src, fz_colorspace *dsts, fz_pixmap *dst) diff --git a/fitz/res_font.c b/fitz/res_font.c index 7238cc3c..0fd4a908 100644 --- a/fitz/res_font.c +++ b/fitz/res_font.c @@ -1,6 +1,6 @@ -#include "fitz-base.h" -#include "fitz-world.h" -#include "fitz-draw.h" /* for type3 font rendering */ +#include "fitz_base.h" +#include "fitz_tree.h" +#include "fitz_draw.h" /* for type3 font rendering */ #include <ft2build.h> #include FT_FREETYPE_H diff --git a/fitz/res_image.c b/fitz/res_image.c index 4379cf17..f906f0ae 100644 --- a/fitz/res_image.c +++ b/fitz/res_image.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-world.h" +#include "fitz_base.h" +#include "fitz_tree.h" fz_image * fz_keepimage(fz_image *image) diff --git a/fitz/res_shade.c b/fitz/res_shade.c index d1bd991e..2d1b1cea 100644 --- a/fitz/res_shade.c +++ b/fitz/res_shade.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-world.h" +#include "fitz_base.h" +#include "fitz_tree.h" fz_shade * fz_keepshade(fz_shade *shade) diff --git a/fitz/stm_buffer.c b/fitz/stm_buffer.c index 8a1e0850..21764cde 100644 --- a/fitz/stm_buffer.c +++ b/fitz/stm_buffer.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" fz_error * fz_newbuffer(fz_buffer **bp, int size) diff --git a/fitz/stm_filter.c b/fitz/stm_filter.c index 450433d4..e633b3f2 100644 --- a/fitz/stm_filter.c +++ b/fitz/stm_filter.c @@ -1,5 +1,5 @@ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" fz_error fz_kioneedin = { "<ioneedin>", "<internal>", "<internal>", 0, nil }; fz_error fz_kioneedout = { "<ioneedout>", "<internal>", "<internal>", 0, nil }; diff --git a/fitz/stm_misc.c b/fitz/stm_misc.c index 70c1c315..af5e1445 100644 --- a/fitz/stm_misc.c +++ b/fitz/stm_misc.c @@ -2,8 +2,8 @@ * Miscellaneous I/O functions */ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" int fz_tell(fz_stream *stm) diff --git a/fitz/stm_open.c b/fitz/stm_open.c index 14e52642..3c4e916b 100644 --- a/fitz/stm_open.c +++ b/fitz/stm_open.c @@ -2,8 +2,8 @@ * Creation and destruction. */ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" static fz_stream * newstm(int kind, int mode) diff --git a/fitz/stm_read.c b/fitz/stm_read.c index e0a6e8a1..20a36a3e 100644 --- a/fitz/stm_read.c +++ b/fitz/stm_read.c @@ -2,8 +2,8 @@ * Input streams. */ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" fz_error * fz_readimp(fz_stream *stm) diff --git a/fitz/stm_write.c b/fitz/stm_write.c index ed928b50..dd8c0ebf 100644 --- a/fitz/stm_write.c +++ b/fitz/stm_write.c @@ -2,8 +2,8 @@ * Output streams. */ -#include "fitz-base.h" -#include "fitz-stream.h" +#include "fitz_base.h" +#include "fitz_stream.h" int fz_wtell(fz_stream *stm) |