From c22e6a6dc2bf6acbac955bd5fbdd896329dfd725 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 9 Nov 2015 14:17:00 +0100 Subject: Use fz_output instead of FILE* for most of our output needs. Use fz_output in debug printing functions. Use fz_output in pdfshow. Use fz_output in fz_trace_device instead of stdout. Use fz_output in pdf-write.c. Rename fz_new_output_to_filename to fz_new_output_with_path. Add seek and tell to fz_output. Remove unused functions like fz_fprintf. Fix typo in pdf_print_obj. --- source/fitz/bitmap.c | 31 ++-- source/fitz/draw-device.c | 10 +- source/fitz/font.c | 16 +- source/fitz/hash.c | 18 +-- source/fitz/image.c | 11 +- source/fitz/output-pcl.c | 38 +---- source/fitz/output-pwg.c | 34 +---- source/fitz/output.c | 183 ++++++++++++++--------- source/fitz/path.c | 30 ++-- source/fitz/pixmap.c | 22 ++- source/fitz/printf.c | 41 ------ source/fitz/shade.c | 30 ++-- source/fitz/store.c | 26 ++-- source/fitz/stream-open.c | 9 ++ source/fitz/text.c | 28 ---- source/fitz/trace-device.c | 355 +++++++++++++++++++++++++-------------------- source/fitz/unzip.c | 6 +- 17 files changed, 415 insertions(+), 473 deletions(-) (limited to 'source/fitz') diff --git a/source/fitz/bitmap.c b/source/fitz/bitmap.c index 4ae74932..5d2af061 100644 --- a/source/fitz/bitmap.c +++ b/source/fitz/bitmap.c @@ -45,36 +45,37 @@ fz_clear_bitmap(fz_context *ctx, fz_bitmap *bit) memset(bit->samples, 0, bit->stride * bit->h); } -/* - * Write bitmap to PBM file - */ - void -fz_write_pbm(fz_context *ctx, fz_bitmap *bitmap, char *filename) +fz_output_pbm(fz_context *ctx, fz_output *out, fz_bitmap *bitmap) { - FILE *fp; unsigned char *p; int h, bytestride; - fp = fz_fopen(filename, "wb"); - if (!fp) - fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); + if (bitmap->n != 1) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many color components in bitmap"); - assert(bitmap->n == 1); - - fprintf(fp, "P4\n%d %d\n", bitmap->w, bitmap->h); + fz_printf(ctx, out, "P4\n%d %d\n", bitmap->w, bitmap->h); p = bitmap->samples; - h = bitmap->h; bytestride = (bitmap->w + 7) >> 3; while (h--) { - fwrite(p, 1, bytestride, fp); + fz_write(ctx, out, p, bytestride); p += bitmap->stride; } +} - fclose(fp); +void +fz_write_pbm(fz_context *ctx, fz_bitmap *bitmap, char *filename) +{ + fz_output *out = fz_new_output_with_path(ctx, filename, 0); + fz_try(ctx) + fz_output_pbm(ctx, out, bitmap); + fz_always(ctx) + fz_drop_output(ctx, out); + fz_catch(ctx) + fz_rethrow(ctx); } fz_colorspace *fz_pixmap_colorspace(fz_context *ctx, fz_pixmap *pix) diff --git a/source/fitz/draw-device.c b/source/fitz/draw-device.c index fdb631f4..b109e6b7 100644 --- a/source/fitz/draw-device.c +++ b/source/fitz/draw-device.c @@ -1711,14 +1711,12 @@ fz_cmp_tile_key(fz_context *ctx, void *k0_, void *k1_) return k0->id == k1->id && k0->ctm[0] == k1->ctm[0] && k0->ctm[1] == k1->ctm[1] && k0->ctm[2] == k1->ctm[2] && k0->ctm[3] == k1->ctm[3]; } -#ifndef NDEBUG static void -fz_debug_tile(fz_context *ctx, FILE *out, void *key_) +fz_print_tile(fz_context *ctx, fz_output *out, void *key_) { tile_key *key = (tile_key *)key_; - fprintf(out, "(tile id=%x, ctm=%g %g %g %g) ", key->id, key->ctm[0], key->ctm[1], key->ctm[2], key->ctm[3]); + fz_printf(ctx, out, "(tile id=%x, ctm=%g %g %g %g) ", key->id, key->ctm[0], key->ctm[1], key->ctm[2], key->ctm[3]); } -#endif static fz_store_type fz_tile_store_type = { @@ -1726,9 +1724,7 @@ static fz_store_type fz_tile_store_type = fz_keep_tile_key, fz_drop_tile_key, fz_cmp_tile_key, -#ifndef NDEBUG - fz_debug_tile -#endif + fz_print_tile }; static void diff --git a/source/fitz/font.c b/source/fitz/font.c index d5296eb9..75aa62c9 100644 --- a/source/fitz/font.c +++ b/source/fitz/font.c @@ -1218,33 +1218,31 @@ fz_render_t3_glyph_direct(fz_context *ctx, fz_device *dev, fz_font *font, int gi font->t3run(ctx, font->t3doc, font->t3resources, contents, dev, &ctm, gstate, nested_depth); } -#ifndef NDEBUG void -fz_print_font(fz_context *ctx, FILE *out, fz_font *font) +fz_print_font(fz_context *ctx, fz_output *out, fz_font *font) { - fprintf(out, "font '%s' {\n", font->name); + fz_printf(ctx, out, "font '%s' {\n", font->name); if (font->ft_face) { - fprintf(out, "\tfreetype face %p\n", font->ft_face); + fz_printf(ctx, out, "\tfreetype face %p\n", font->ft_face); if (font->ft_substitute) - fprintf(out, "\tsubstitute font\n"); + fz_printf(ctx, out, "\tsubstitute font\n"); } if (font->t3procs) { - fprintf(out, "\ttype3 matrix [%g %g %g %g]\n", + fz_printf(ctx, out, "\ttype3 matrix [%g %g %g %g]\n", font->t3matrix.a, font->t3matrix.b, font->t3matrix.c, font->t3matrix.d); - fprintf(out, "\ttype3 bbox [%g %g %g %g]\n", + fz_printf(ctx, out, "\ttype3 bbox [%g %g %g %g]\n", font->bbox.x0, font->bbox.y0, font->bbox.x1, font->bbox.y1); } - fprintf(out, "}\n"); + fz_printf(ctx, out, "}\n"); } -#endif fz_rect * fz_bound_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm, fz_rect *rect) diff --git a/source/fitz/hash.c b/source/fitz/hash.c index f80e79b3..6c4d9a5e 100644 --- a/source/fitz/hash.c +++ b/source/fitz/hash.c @@ -324,34 +324,32 @@ fz_hash_remove_fast(fz_context *ctx, fz_hash_table *table, const void *key, unsi do_removal(ctx, table, key, pos); } -#ifndef NDEBUG void -fz_print_hash(fz_context *ctx, FILE *out, fz_hash_table *table) +fz_print_hash(fz_context *ctx, fz_output *out, fz_hash_table *table) { fz_print_hash_details(ctx, out, table, NULL); } void -fz_print_hash_details(fz_context *ctx, FILE *out, fz_hash_table *table, void (*details)(FILE *,void*)) +fz_print_hash_details(fz_context *ctx, fz_output *out, fz_hash_table *table, void (*details)(fz_context*,fz_output*,void*)) { int i, k; - fprintf(out, "cache load %d / %d\n", table->load, table->size); + fz_printf(ctx, out, "cache load %d / %d\n", table->load, table->size); for (i = 0; i < table->size; i++) { if (!table->ents[i].val) - fprintf(out, "table % 4d: empty\n", i); + fz_printf(ctx, out, "table % 4d: empty\n", i); else { - fprintf(out, "table % 4d: key=", i); + fz_printf(ctx, out, "table % 4d: key=", i); for (k = 0; k < MAX_KEY_LEN; k++) - fprintf(out, "%02x", ((char*)table->ents[i].key)[k]); + fz_printf(ctx, out, "%02x", ((char*)table->ents[i].key)[k]); if (details) - details(out, table->ents[i].val); + details(ctx, out, table->ents[i].val); else - fprintf(out, " val=$%p\n", table->ents[i].val); + fz_printf(ctx, out, " val=$%p\n", table->ents[i].val); } } } -#endif diff --git a/source/fitz/image.c b/source/fitz/image.c index 4728c5f3..60c3578d 100644 --- a/source/fitz/image.c +++ b/source/fitz/image.c @@ -65,15 +65,12 @@ fz_cmp_image_key(fz_context *ctx, void *k0_, void *k1_) return k0->image == k1->image && k0->l2factor == k1->l2factor; } -#ifndef NDEBUG static void -fz_debug_image(fz_context *ctx, FILE *out, void *key_) +fz_print_image(fz_context *ctx, fz_output *out, void *key_) { fz_image_key *key = (fz_image_key *)key_; - - fprintf(out, "(image %d x %d sf=%d) ", key->image->w, key->image->h, key->l2factor); + fz_printf(ctx, out, "(image %d x %d sf=%d) ", key->image->w, key->image->h, key->l2factor); } -#endif static fz_store_type fz_image_store_type = { @@ -81,9 +78,7 @@ static fz_store_type fz_image_store_type = fz_keep_image_key, fz_drop_image_key, fz_cmp_image_key, -#ifndef NDEBUG - fz_debug_image -#endif + fz_print_image }; static void diff --git a/source/fitz/output-pcl.c b/source/fitz/output-pcl.c index 1299e73d..9d21a6d3 100644 --- a/source/fitz/output-pcl.c +++ b/source/fitz/output-pcl.c @@ -792,57 +792,23 @@ fz_output_pcl_bitmap(fz_context *ctx, fz_output *out, const fz_bitmap *bitmap, f void fz_write_pcl(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append, fz_pcl_options *pcl) { - FILE *fp; - fz_output *out = NULL; - - fp = fz_fopen(filename, append ? "ab" : "wb"); - if (!fp) - { - fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); - } - - fz_var(out); - + fz_output *out = fz_new_output_with_path(ctx, filename, append); fz_try(ctx) - { - out = fz_new_output_with_file(ctx, fp, 1); fz_output_pcl(ctx, out, pixmap, pcl); - } fz_always(ctx) - { fz_drop_output(ctx, out); - } fz_catch(ctx) - { fz_rethrow(ctx); - } } void fz_write_pcl_bitmap(fz_context *ctx, fz_bitmap *bitmap, char *filename, int append, fz_pcl_options *pcl) { - FILE *fp; - fz_output *out = NULL; - - fp = fz_fopen(filename, append ? "ab" : "wb"); - if (!fp) - { - fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); - } - - fz_var(out); - + fz_output *out = fz_new_output_with_path(ctx, filename, append); fz_try(ctx) - { - out = fz_new_output_with_file(ctx, fp, 1); fz_output_pcl_bitmap(ctx, out, bitmap, pcl); - } fz_always(ctx) - { fz_drop_output(ctx, out); - } fz_catch(ctx) - { fz_rethrow(ctx); - } } diff --git a/source/fitz/output-pwg.c b/source/fitz/output-pwg.c index 205966d3..d46dd04f 100644 --- a/source/fitz/output-pwg.c +++ b/source/fitz/output-pwg.c @@ -260,61 +260,31 @@ fz_output_pwg(fz_context *ctx, fz_output *out, const fz_pixmap *pixmap, const fz void fz_write_pwg(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append, const fz_pwg_options *pwg) { - FILE *fp; - fz_output *out = NULL; - - fp = fz_fopen(filename, append ? "ab" : "wb"); - if (!fp) - { - fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); - } - - fz_var(out); - + fz_output *out = fz_new_output_with_path(ctx, filename, append); fz_try(ctx) { - out = fz_new_output_with_file(ctx, fp, 1); if (!append) fz_output_pwg_file_header(ctx, out); fz_output_pwg_page(ctx, out, pixmap, pwg); } fz_always(ctx) - { fz_drop_output(ctx, out); - } fz_catch(ctx) - { fz_rethrow(ctx); - } } void fz_write_pwg_bitmap(fz_context *ctx, fz_bitmap *bitmap, char *filename, int append, const fz_pwg_options *pwg) { - FILE *fp; - fz_output *out = NULL; - - fp = fz_fopen(filename, append ? "ab" : "wb"); - if (!fp) - { - fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); - } - - fz_var(out); - + fz_output *out = fz_new_output_with_path(ctx, filename, append); fz_try(ctx) { - out = fz_new_output_with_file(ctx, fp, 1); if (!append) fz_output_pwg_file_header(ctx, out); fz_output_pwg_bitmap_page(ctx, out, bitmap, pwg); } fz_always(ctx) - { fz_drop_output(ctx, out); - } fz_catch(ctx) - { fz_rethrow(ctx); - } } diff --git a/source/fitz/output.c b/source/fitz/output.c index 027f66c3..e39dd352 100644 --- a/source/fitz/output.c +++ b/source/fitz/output.c @@ -3,61 +3,74 @@ struct fz_output_s { void *opaque; - int (*printf)(fz_context *, void *opaque, const char *, va_list ap); int (*write)(fz_context *, void *opaque, const void *, int n); + void (*seek)(fz_context *, void *opaque, fz_off_t off, int whence); + fz_off_t (*tell)(fz_context *, void *opaque); void (*close)(fz_context *, void *opaque); }; static int -file_printf(fz_context *ctx, void *opaque, const char *fmt, va_list ap) +file_write(fz_context *ctx, void *opaque, const void *buffer, int count) { FILE *file = opaque; - return fz_vfprintf(ctx, file, fmt, ap); + size_t n = fwrite(buffer, 1, count, file); + if (n < count && ferror(file)) + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot fwrite: %s", strerror(errno)); + return n; } -static int -file_write(fz_context *ctx, void *opaque, const void *buffer, int count) +static void +file_seek(fz_context *ctx, void *opaque, fz_off_t off, int whence) { FILE *file = opaque; - return fwrite(buffer, 1, count, file); + int n = fz_fseek(file, off, whence); + if (n < 0) + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot fseek: %s", strerror(errno)); +} + +static fz_off_t +file_tell(fz_context *ctx, void *opaque) +{ + FILE *file = opaque; + fz_off_t off = fz_ftell(file); + if (off == -1) + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot ftell: %s", strerror(errno)); + return off; } static void file_close(fz_context *ctx, void *opaque) { FILE *file = opaque; - fclose(file); + int n = fclose(file); + if (n < 0) + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot fclose: %s", strerror(errno)); } fz_output * -fz_new_output_with_file(fz_context *ctx, FILE *file, int close) +fz_new_output_with_file_ptr(fz_context *ctx, FILE *file, int close) { fz_output *out = fz_malloc_struct(ctx, fz_output); out->opaque = file; - out->printf = file_printf; out->write = file_write; + out->seek = file_seek; + out->tell = file_tell; out->close = close ? file_close : NULL; return out; } fz_output * -fz_new_output_to_filename(fz_context *ctx, const char *filename) +fz_new_output_with_path(fz_context *ctx, const char *filename, int append) { fz_output *out = NULL; - FILE *file = fz_fopen(filename, "wb"); + FILE *file = fz_fopen(filename, append ? "ab" : "wb"); if (!file) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); - fz_var(ctx); - fz_try(ctx) { - out = fz_malloc_struct(ctx, fz_output); - out->opaque = file; - out->printf = file_printf; - out->write = file_write; - out->close = file_close; + out = fz_new_output_with_file_ptr(ctx, file, 1); } fz_catch(ctx) { @@ -67,84 +80,114 @@ fz_new_output_to_filename(fz_context *ctx, const char *filename) return out; } -void -fz_drop_output(fz_context *ctx, fz_output *out) +static int +buffer_write(fz_context *ctx, void *opaque, const void *data, int len) { - if (!out) - return; - if (out->close) - out->close(ctx, out->opaque); - fz_free(ctx, out); + fz_buffer *buffer = opaque; + fz_write_buffer(ctx, buffer, (unsigned char *)data, len); + return len; } -int -fz_printf(fz_context *ctx, fz_output *out, const char *fmt, ...) +static void +buffer_seek(fz_context *ctx, void *opaque, fz_off_t off, int whence) { - int ret; - va_list ap; - - if (!out) - return 0; + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot seek in buffer: %s", strerror(errno)); +} - va_start(ap, fmt); - ret = out->printf(ctx, out->opaque, fmt, ap); - va_end(ap); +static fz_off_t +buffer_tell(fz_context *ctx, void *opaque) +{ + fz_buffer *buffer = opaque; + return buffer->len; +} - return ret; +static void +buffer_close(fz_context *ctx, void *opaque) +{ + fz_buffer *buffer = opaque; + fz_drop_buffer(ctx, buffer); } -int -fz_write(fz_context *ctx, fz_output *out, const void *data, int len) +fz_output * +fz_new_output_with_buffer(fz_context *ctx, fz_buffer *buf) { - if (!out) - return 0; - return out->write(ctx, out->opaque, data, len); + fz_output *out = fz_malloc_struct(ctx, fz_output); + out->opaque = fz_keep_buffer(ctx, buf); + out->write = buffer_write; + out->seek = buffer_seek; + out->tell = buffer_tell; + out->close = buffer_close; + return out; } void -fz_putc(fz_context *ctx, fz_output *out, char c) +fz_drop_output(fz_context *ctx, fz_output *out) { - if (out) - (void)out->write(ctx, out->opaque, &c, 1); + if (!out) return; + if (out->close) + out->close(ctx, out->opaque); + fz_free(ctx, out); } -int -fz_puts(fz_context *ctx, fz_output *out, const char *str) +void +fz_seek_output(fz_context *ctx, fz_output *out, fz_off_t off, int whence) { - if (!out) - return 0; - return out->write(ctx, out->opaque, str, strlen(str)); + if (!out) return; + out->seek(ctx, out->opaque, off, whence); } -static int -buffer_printf(fz_context *ctx, void *opaque, const char *fmt, va_list list) +fz_off_t +fz_tell_output(fz_context *ctx, fz_output *out) { - fz_buffer *buffer = opaque; - return fz_buffer_vprintf(ctx, buffer, fmt, list); + if (!out) return 0; + return out->tell(ctx, out->opaque); } -static int -buffer_write(fz_context *ctx, void *opaque, const void *data, int len) +void +fz_vprintf(fz_context *ctx, fz_output *out, const char *fmt, va_list old_args) { - fz_buffer *buffer = opaque; - fz_write_buffer(ctx, buffer, (unsigned char *)data, len); - return len; + char buffer[256], *p = buffer; + int len; + va_list args; + + if (!out) return; + + /* First try using our fixed size buffer */ + va_copy(args, old_args); + len = fz_vsnprintf(buffer, sizeof buffer, fmt, args); + va_copy_end(args); + + /* If that failed, allocate a big enough buffer */ + if (len >= sizeof buffer) + { + p = fz_malloc(ctx, len + 1); + va_copy(args, old_args); + fz_vsnprintf(p, len + 1, fmt, args); + va_copy_end(args); + } + + fz_try(ctx) + out->write(ctx, out->opaque, p, len); + fz_always(ctx) + if (p != buffer) + fz_free(ctx, p); + fz_catch(ctx) + fz_rethrow(ctx); } -static void -buffer_close(fz_context *ctx, void *opaque) +void +fz_printf(fz_context *ctx, fz_output *out, const char *fmt, ...) { - fz_buffer *buffer = opaque; - fz_drop_buffer(ctx, buffer); + va_list args; + if (!out) return; + va_start(args, fmt); + fz_vprintf(ctx, out, fmt, args); + va_end(args); } -fz_output * -fz_new_output_with_buffer(fz_context *ctx, fz_buffer *buf) +int +fz_write(fz_context *ctx, fz_output *out, const void *data, int len) { - fz_output *out = fz_malloc_struct(ctx, fz_output); - out->opaque = fz_keep_buffer(ctx, buf); - out->printf = buffer_printf; - out->write = buffer_write; - out->close = buffer_close; - return out; + if (!out) return 0; + return out->write(ctx, out->opaque, data, len); } diff --git a/source/fitz/path.c b/source/fitz/path.c index a1ee1c15..5481a90d 100644 --- a/source/fitz/path.c +++ b/source/fitz/path.c @@ -1338,9 +1338,8 @@ void fz_trim_path(fz_context *ctx, fz_path *path) } } -#ifndef NDEBUG void -fz_print_path(fz_context *ctx, FILE *out, fz_path *path, int indent) +fz_print_path(fz_context *ctx, fz_output *out, fz_path *path, int indent) { float x, y; int i = 0, k = 0; @@ -1350,46 +1349,46 @@ fz_print_path(fz_context *ctx, FILE *out, fz_path *path, int indent) uint8_t cmd = path->cmds[i++]; for (n = 0; n < indent; n++) - fputc(' ', out); + fz_putc(ctx, out, ' '); switch (cmd) { case FZ_MOVETO: case FZ_MOVETOCLOSE: x = path->coords[k++]; y = path->coords[k++]; - fprintf(out, "%g %g m%s\n", x, y, cmd == FZ_MOVETOCLOSE ? " z" : ""); + fz_printf(ctx, out, "%g %g m%s\n", x, y, cmd == FZ_MOVETOCLOSE ? " z" : ""); break; case FZ_LINETO: case FZ_LINETOCLOSE: x = path->coords[k++]; y = path->coords[k++]; - fprintf(out, "%g %g l%s\n", x, y, cmd == FZ_LINETOCLOSE ? " z" : ""); + fz_printf(ctx, out, "%g %g l%s\n", x, y, cmd == FZ_LINETOCLOSE ? " z" : ""); break; case FZ_DEGENLINETO: case FZ_DEGENLINETOCLOSE: - fprintf(out, "d%s\n", cmd == FZ_DEGENLINETOCLOSE ? " z" : ""); + fz_printf(ctx, out, "d%s\n", cmd == FZ_DEGENLINETOCLOSE ? " z" : ""); break; case FZ_HORIZTO: case FZ_HORIZTOCLOSE: x = path->coords[k++]; - fprintf(out, "%g h%s\n", x, cmd == FZ_HORIZTOCLOSE ? " z" : ""); + fz_printf(ctx, out, "%g h%s\n", x, cmd == FZ_HORIZTOCLOSE ? " z" : ""); break; case FZ_VERTTOCLOSE: case FZ_VERTTO: y = path->coords[k++]; - fprintf(out, "%g i%s\n", y, cmd == FZ_VERTTOCLOSE ? " z" : ""); + fz_printf(ctx, out, "%g i%s\n", y, cmd == FZ_VERTTOCLOSE ? " z" : ""); break; case FZ_CURVETOCLOSE: case FZ_CURVETO: x = path->coords[k++]; y = path->coords[k++]; - fprintf(out, "%g %g ", x, y); + fz_printf(ctx, out, "%g %g ", x, y); x = path->coords[k++]; y = path->coords[k++]; - fprintf(out, "%g %g ", x, y); + fz_printf(ctx, out, "%g %g ", x, y); x = path->coords[k++]; y = path->coords[k++]; - fprintf(out, "%g %g c%s\n", x, y, cmd == FZ_CURVETOCLOSE ? " z" : ""); + fz_printf(ctx, out, "%g %g c%s\n", x, y, cmd == FZ_CURVETOCLOSE ? " z" : ""); break; case FZ_CURVETOVCLOSE: case FZ_CURVETOV: @@ -1397,23 +1396,22 @@ fz_print_path(fz_context *ctx, FILE *out, fz_path *path, int indent) case FZ_CURVETOY: x = path->coords[k++]; y = path->coords[k++]; - fprintf(out, "%g %g ", x, y); + fz_printf(ctx, out, "%g %g ", x, y); x = path->coords[k++]; y = path->coords[k++]; - fprintf(out, "%g %g %c%s\n", x, y, (cmd == FZ_CURVETOVCLOSE || cmd == FZ_CURVETOV ? 'v' : 'y'), (cmd == FZ_CURVETOVCLOSE || cmd == FZ_CURVETOYCLOSE) ? " z" : ""); + fz_printf(ctx, out, "%g %g %c%s\n", x, y, (cmd == FZ_CURVETOVCLOSE || cmd == FZ_CURVETOV ? 'v' : 'y'), (cmd == FZ_CURVETOVCLOSE || cmd == FZ_CURVETOYCLOSE) ? " z" : ""); break; case FZ_RECTTO: x = path->coords[k++]; y = path->coords[k++]; - fprintf(out, "%g %g ", x, y); + fz_printf(ctx, out, "%g %g ", x, y); x = path->coords[k++]; y = path->coords[k++]; - fprintf(out, "%g %g r\n", x, y); + fz_printf(ctx, out, "%g %g r\n", x, y); break; } } } -#endif const fz_stroke_state fz_default_stroke_state = { -2, /* -2 is the magic number we use when we have stroke states stored on the stack */ diff --git a/source/fitz/pixmap.c b/source/fitz/pixmap.c index fa4843bc..9f1ec20e 100644 --- a/source/fitz/pixmap.c +++ b/source/fitz/pixmap.c @@ -575,10 +575,17 @@ fz_output_pnm_band(fz_context *ctx, fz_output *out, int w, int h, int n, int ban } } +void +fz_output_pnm(fz_context *ctx, fz_output *out, fz_pixmap *pixmap) +{ + fz_output_pnm_header(ctx, out, pixmap->w, pixmap->h, pixmap->n); + fz_output_pnm_band(ctx, out, pixmap->w, pixmap->h, pixmap->n, 0, pixmap->h, pixmap->samples); +} + void fz_write_pnm(fz_context *ctx, fz_pixmap *pixmap, char *filename) { - fz_output *out = fz_new_output_to_filename(ctx, filename); + fz_output *out = fz_new_output_with_path(ctx, filename, 0); fz_output_pnm_header(ctx, out, pixmap->w, pixmap->h, pixmap->n); fz_output_pnm_band(ctx, out, pixmap->w, pixmap->h, pixmap->n, 0, pixmap->h, pixmap->samples); fz_drop_output(ctx, out); @@ -637,10 +644,17 @@ fz_output_pam_band(fz_context *ctx, fz_output *out, int w, int h, int n, int ban } } +void +fz_output_pam(fz_context *ctx, fz_output *out, fz_pixmap *pixmap, int savealpha) +{ + fz_output_pam_header(ctx, out, pixmap->w, pixmap->h, pixmap->n, savealpha); + fz_output_pam_band(ctx, out, pixmap->w, pixmap->h, pixmap->n, 0, pixmap->h, pixmap->samples, savealpha); +} + void fz_write_pam(fz_context *ctx, fz_pixmap *pixmap, char *filename, int savealpha) { - fz_output *out = fz_new_output_to_filename(ctx, filename); + fz_output *out = fz_new_output_with_path(ctx, filename, 0); fz_output_pam_header(ctx, out, pixmap->w, pixmap->h, pixmap->n, savealpha); fz_output_pam_band(ctx, out, pixmap->w, pixmap->h, pixmap->n, 0, pixmap->h, pixmap->samples, savealpha); fz_drop_output(ctx, out); @@ -675,7 +689,7 @@ static void putchunk(fz_context *ctx, fz_output *out, char *tag, unsigned char * void fz_write_png(fz_context *ctx, fz_pixmap *pixmap, char *filename, int savealpha) { - fz_output *out = fz_new_output_to_filename(ctx, filename); + fz_output *out = fz_new_output_with_path(ctx, filename, 0); fz_png_output_context *poc = NULL; fz_var(poc); @@ -979,7 +993,7 @@ fz_write_tga(fz_context *ctx, fz_pixmap *pixmap, const char *filename, int savea fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap must be grayscale or rgb to write as tga"); } - out = fz_new_output_to_filename(ctx, filename); + out = fz_new_output_with_path(ctx, filename, 0); memset(head, 0, sizeof(head)); head[2] = n == 4 ? 10 : 11; diff --git a/source/fitz/printf.c b/source/fitz/printf.c index c554540b..dcc89952 100644 --- a/source/fitz/printf.c +++ b/source/fitz/printf.c @@ -321,47 +321,6 @@ fz_vsnprintf(char *buffer, int space, const char *fmt, va_list args) return out.n - 1; } -int -fz_vfprintf(fz_context *ctx, FILE *file, const char *fmt, va_list old_args) -{ - char buffer[256]; - int l; - va_list args; - char *b = buffer; - - /* First try using our fixed size buffer */ - va_copy(args, old_args); - l = fz_vsnprintf(buffer, sizeof buffer, fmt, args); - va_copy_end(args); - - /* If that failed, allocate the right size buffer dynamically */ - if (l >= sizeof buffer) - { - b = fz_malloc(ctx, l + 1); - va_copy(args, old_args); - fz_vsnprintf(b, l + 1, fmt, args); - va_copy_end(args); - } - - l = fwrite(b, 1, l, file); - - if (b != buffer) - fz_free(ctx, b); - - return l; -} - -int -fz_fprintf(fz_context *ctx, FILE *file, const char *fmt, ...) -{ - int n; - va_list ap; - va_start(ap, fmt); - n = fz_vfprintf(ctx, file, fmt, ap); - va_end(ap); - return n; -} - int fz_snprintf(char *buffer, int space, const char *fmt, ...) { diff --git a/source/fitz/shade.c b/source/fitz/shade.c index f5e25639..d543b020 100644 --- a/source/fitz/shade.c +++ b/source/fitz/shade.c @@ -1086,45 +1086,43 @@ fz_bound_shade(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz_rect * return fz_transform_rect(s, &local_ctm); } -#ifndef NDEBUG void -fz_print_shade(fz_context *ctx, FILE *out, fz_shade *shade) +fz_print_shade(fz_context *ctx, fz_output *out, fz_shade *shade) { int i; - fprintf(out, "shading {\n"); + fz_printf(ctx, out, "shading {\n"); switch (shade->type) { - case FZ_FUNCTION_BASED: fprintf(out, "\ttype function_based\n"); break; - case FZ_LINEAR: fprintf(out, "\ttype linear\n"); break; - case FZ_RADIAL: fprintf(out, "\ttype radial\n"); break; - default: /* MESH */ fprintf(out, "\ttype mesh\n"); break; + case FZ_FUNCTION_BASED: fz_printf(ctx, out, "\ttype function_based\n"); break; + case FZ_LINEAR: fz_printf(ctx, out, "\ttype linear\n"); break; + case FZ_RADIAL: fz_printf(ctx, out, "\ttype radial\n"); break; + default: /* MESH */ fz_printf(ctx, out, "\ttype mesh\n"); break; } - fprintf(out, "\tbbox [%g %g %g %g]\n", + fz_printf(ctx, out, "\tbbox [%g %g %g %g]\n", shade->bbox.x0, shade->bbox.y0, shade->bbox.x1, shade->bbox.y1); - fprintf(out, "\tcolorspace %s\n", shade->colorspace->name); + fz_printf(ctx, out, "\tcolorspace %s\n", shade->colorspace->name); - fprintf(out, "\tmatrix [%g %g %g %g %g %g]\n", + fz_printf(ctx, out, "\tmatrix [%g %g %g %g %g %g]\n", shade->matrix.a, shade->matrix.b, shade->matrix.c, shade->matrix.d, shade->matrix.e, shade->matrix.f); if (shade->use_background) { - fprintf(out, "\tbackground ["); + fz_printf(ctx, out, "\tbackground ["); for (i = 0; i < shade->colorspace->n; i++) - fprintf(out, "%s%g", i == 0 ? "" : " ", shade->background[i]); - fprintf(out, "]\n"); + fz_printf(ctx, out, "%s%g", i == 0 ? "" : " ", shade->background[i]); + fz_printf(ctx, out, "]\n"); } if (shade->use_function) { - fprintf(out, "\tfunction\n"); + fz_printf(ctx, out, "\tfunction\n"); } - fprintf(out, "}\n"); + fz_printf(ctx, out, "}\n"); } -#endif diff --git a/source/fitz/store.c b/source/fitz/store.c index ce83e87f..4bb54c19 100644 --- a/source/fitz/store.c +++ b/source/fitz/store.c @@ -484,52 +484,46 @@ fz_drop_store_context(fz_context *ctx) ctx->store = NULL; } -#ifndef NDEBUG static void -print_item(FILE *out, void *item_) +print_item(fz_context *ctx, fz_output *out, void *item_) { fz_item *item = (fz_item *)item_; - fprintf(out, " val=%p item=%p\n", item->val, item); - fflush(out); + fz_printf(ctx, out, " val=%p item=%p\n", item->val, item); } void -fz_print_store_locked(fz_context *ctx, FILE *out) +fz_print_store_locked(fz_context *ctx, fz_output *out) { fz_item *item, *next; fz_store *store = ctx->store; - fprintf(out, "-- resource store contents --\n"); - fflush(out); + fz_printf(ctx, out, "-- resource store contents --\n"); for (item = store->head; item; item = next) { next = item->next; if (next) next->val->refs++; - fprintf(out, "store[*][refs=%d][size=%d] ", item->val->refs, item->size); + fz_printf(ctx, out, "store[*][refs=%d][size=%d] ", item->val->refs, item->size); fz_unlock(ctx, FZ_LOCK_ALLOC); - item->type->debug(ctx, out, item->key); - fprintf(out, " = %p\n", item->val); - fflush(out); + item->type->print(ctx, out, item->key); + fz_printf(ctx, out, " = %p\n", item->val); fz_lock(ctx, FZ_LOCK_ALLOC); if (next) next->val->refs--; } - fprintf(out, "-- resource store hash contents --\n"); + fz_printf(ctx, out, "-- resource store hash contents --\n"); fz_print_hash_details(ctx, out, store->hash, print_item); - fprintf(out, "-- end --\n"); - fflush(out); + fz_printf(ctx, out, "-- end --\n"); } void -fz_print_store(fz_context *ctx, FILE *out) +fz_print_store(fz_context *ctx, fz_output *out) { fz_lock(ctx, FZ_LOCK_ALLOC); fz_print_store_locked(ctx, out); fz_unlock(ctx, FZ_LOCK_ALLOC); } -#endif /* This is now an n^2 algorithm - not ideal, but it'll only be bad if we are * actually managing to scavenge lots of blocks back. */ diff --git a/source/fitz/stream-open.c b/source/fitz/stream-open.c index b4df2a61..e9836dd1 100644 --- a/source/fitz/stream-open.c +++ b/source/fitz/stream-open.c @@ -1,5 +1,14 @@ #include "mupdf/fitz.h" +int +fz_file_exists(fz_context *ctx, const char *path) +{ + FILE *file = fz_fopen(path, "rb"); + if (file) + fclose(file); + return !!file; +} + fz_stream * fz_new_stream(fz_context *ctx, void *state, fz_stream_next_fn *next, fz_stream_close_fn *close) { diff --git a/source/fitz/text.c b/source/fitz/text.c index 466c869a..0616d6a9 100644 --- a/source/fitz/text.c +++ b/source/fitz/text.c @@ -109,31 +109,3 @@ fz_add_text(fz_context *ctx, fz_text *text, int gid, int ucs, float x, float y) text->items[text->len].y = y; text->len++; } - -static int -isxmlmeta(int c) -{ - return c < 32 || c >= 128 || c == '&' || c == '<' || c == '>' || c == '\'' || c == '"'; -} - -static void -do_print_text(FILE *out, fz_text *text, int indent) -{ - int i, n; - for (i = 0; i < text->len; i++) - { - for (n = 0; n < indent; n++) - fputc(' ', out); - if (!isxmlmeta(text->items[i].ucs)) - fprintf(out, "\n", - text->items[i].ucs, text->items[i].gid, text->items[i].x, text->items[i].y); - else - fprintf(out, "\n", - text->items[i].ucs, text->items[i].gid, text->items[i].x, text->items[i].y); - } -} - -void fz_print_text(fz_context *ctx, FILE *out, fz_text *text) -{ - do_print_text(out, text, 0); -} diff --git a/source/fitz/trace-device.c b/source/fitz/trace-device.c index 5ea716b4..59ea8ad8 100644 --- a/source/fitz/trace-device.c +++ b/source/fitz/trace-device.c @@ -1,73 +1,63 @@ #include "mupdf/fitz.h" +typedef struct fz_trace_device_s +{ + fz_device super; + fz_output *out; +} fz_trace_device; + static void -fz_trace_matrix(const fz_matrix *ctm) +fz_trace_matrix(fz_context *ctx, fz_output *out, const fz_matrix *ctm) { - printf(" matrix=\"%g %g %g %g %g %g\"", + fz_printf(ctx, out, " matrix=\"%g %g %g %g %g %g\"", ctm->a, ctm->b, ctm->c, ctm->d, ctm->e, ctm->f); } static void -fz_trace_trm(const fz_matrix *trm) +fz_trace_trm(fz_context *ctx, fz_output *out, const fz_matrix *trm) { - printf(" trm=\"%g %g %g %g\"", + fz_printf(ctx, out, " trm=\"%g %g %g %g\"", trm->a, trm->b, trm->c, trm->d); } static void -fz_trace_color(fz_colorspace *colorspace, float *color, float alpha) +fz_trace_color(fz_context *ctx, fz_output *out, fz_colorspace *colorspace, float *color, float alpha) { int i; - printf(" colorspace=\"%s\" color=\"", colorspace->name); + fz_printf(ctx, out, " colorspace=\"%s\" color=\"", colorspace->name); for (i = 0; i < colorspace->n; i++) - printf("%s%g", i == 0 ? "" : " ", color[i]); - printf("\""); + fz_printf(ctx, out, "%s%g", i == 0 ? "" : " ", color[i]); + fz_printf(ctx, out, "\""); if (alpha < 1) - printf(" alpha=\"%g\"", alpha); + fz_printf(ctx, out, " alpha=\"%g\"", alpha); } static void trace_moveto(fz_context *ctx, void *arg, float x, float y) { - int indent = (int)(intptr_t)arg; - int n; - - for (n = 0; n < indent; n++) - putchar(' '); - printf("\n", x, y); + fz_output *out = arg; + fz_printf(ctx, out, "\n", x, y); } static void trace_lineto(fz_context *ctx, void *arg, float x, float y) { - int indent = (int)(intptr_t)arg; - int n; - - for (n = 0; n < indent; n++) - putchar(' '); - printf("\n", x, y); + fz_output *out = arg; + fz_printf(ctx, out, "\n", x, y); } static void trace_curveto(fz_context *ctx, void *arg, float x1, float y1, float x2, float y2, float x3, float y3) { - int indent = (int)(intptr_t)arg; - int n; - - for (n = 0; n < indent; n++) - putchar(' '); - printf("\n", x1, y1, x2, y2, x3, y3); + fz_output *out = arg; + fz_printf(ctx, out, "\n", x1, y1, x2, y2, x3, y3); } static void trace_close(fz_context *ctx, void *arg) { - int indent = (int)(intptr_t)arg; - int n; - - for (n = 0; n < indent; n++) - putchar(' '); - printf("\n"); + fz_output *out = arg; + fz_printf(ctx, out, "\n"); } static const fz_path_processor trace_path_proc = @@ -79,219 +69,259 @@ static const fz_path_processor trace_path_proc = }; static void -fz_trace_path(fz_context *ctx, fz_path *path, int indent) +fz_trace_path(fz_context *ctx, fz_output *out, fz_path *path) { - fz_process_path(ctx, &trace_path_proc, (void *)(intptr_t)indent, path); + fz_process_path(ctx, &trace_path_proc, out, path); } static void fz_trace_begin_page(fz_context *ctx, fz_device *dev, const fz_rect *rect, const fz_matrix *ctm) { - printf("x0, rect->y0, rect->x1, rect->y1); - fz_trace_matrix(ctm); - printf(">\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "x0, rect->y0, rect->x1, rect->y1); + fz_trace_matrix(ctx, out, ctm); + fz_printf(ctx, out, ">\n"); } static void fz_trace_end_page(fz_context *ctx, fz_device *dev) { - printf("\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "\n"); } static void fz_trace_fill_path(fz_context *ctx, fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { - printf("out; + fz_printf(ctx, out, "\n"); - fz_trace_path(ctx, path, 0); - printf("\n"); + fz_printf(ctx, out, " winding=\"nonzero\""); + fz_trace_color(ctx, out, colorspace, color, alpha); + fz_trace_matrix(ctx, out, ctm); + fz_printf(ctx, out, ">\n"); + fz_trace_path(ctx, out, path); + fz_printf(ctx, out, "\n"); } static void fz_trace_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { + fz_output *out = ((fz_trace_device*)dev)->out; int i; - printf("linewidth); - printf(" miterlimit=\"%g\"", stroke->miterlimit); - printf(" linecap=\"%d,%d,%d\"", stroke->start_cap, stroke->dash_cap, stroke->end_cap); - printf(" linejoin=\"%d\"", stroke->linejoin); + fz_printf(ctx, out, "linewidth); + fz_printf(ctx, out, " miterlimit=\"%g\"", stroke->miterlimit); + fz_printf(ctx, out, " linecap=\"%d,%d,%d\"", stroke->start_cap, stroke->dash_cap, stroke->end_cap); + fz_printf(ctx, out, " linejoin=\"%d\"", stroke->linejoin); if (stroke->dash_len) { - printf(" dash_phase=\"%g\" dash=\"", stroke->dash_phase); + fz_printf(ctx, out, " dash_phase=\"%g\" dash=\"", stroke->dash_phase); for (i = 0; i < stroke->dash_len; i++) - printf("%s%g", i > 0 ? " " : "", stroke->dash_list[i]); - printf("\""); + fz_printf(ctx, out, "%s%g", i > 0 ? " " : "", stroke->dash_list[i]); + fz_printf(ctx, out, "\""); } - fz_trace_color(colorspace, color, alpha); - fz_trace_matrix(ctm); - printf(">\n"); + fz_trace_color(ctx, out, colorspace, color, alpha); + fz_trace_matrix(ctx, out, ctm); + fz_printf(ctx, out, ">\n"); - fz_trace_path(ctx, path, 0); + fz_trace_path(ctx, out, path); - printf("\n"); + fz_printf(ctx, out, "\n"); } static void fz_trace_clip_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm) { - printf("out; + fz_printf(ctx, out, "\n", rect->x0, rect->y0, rect->x1, rect->y1); + fz_printf(ctx, out, " contentbbox=\"%g %g %g %g\">\n", rect->x0, rect->y0, rect->x1, rect->y1); else - printf(">\n"); - fz_trace_path(ctx, path, 0); - printf("\n"); + fz_printf(ctx, out, ">\n"); + fz_trace_path(ctx, out, path); + fz_printf(ctx, out, "\n"); } static void fz_trace_clip_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm) { - printf("\n"); - fz_trace_path(ctx, path, 0); - printf("\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "\n"); + fz_trace_path(ctx, out, path); + fz_printf(ctx, out, "\n"); +} + +static int +isxmlmeta(int c) +{ + return c < 32 || c >= 128 || c == '&' || c == '<' || c == '>' || c == '\'' || c == '"'; +} + +static void +fz_trace_text(fz_context *ctx, fz_output *out, fz_text *text) +{ + int i; + for (i = 0; i < text->len; i++) + { + if (!isxmlmeta(text->items[i].ucs)) + fz_printf(ctx, out, "\n", + text->items[i].ucs, text->items[i].gid, text->items[i].x, text->items[i].y); + else + fz_printf(ctx, out, "\n", + text->items[i].ucs, text->items[i].gid, text->items[i].x, text->items[i].y); + } } static void fz_trace_fill_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { - printf("font->name, text->wmode); - fz_trace_color(colorspace, color, alpha); - fz_trace_matrix(ctm); - fz_trace_trm(&text->trm); - printf(">\n"); - fz_print_text(ctx, stdout, text); - printf("\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "font->name, text->wmode); + fz_trace_color(ctx, out, colorspace, color, alpha); + fz_trace_matrix(ctx, out, ctm); + fz_trace_trm(ctx, out, &text->trm); + fz_printf(ctx, out, ">\n"); + fz_trace_text(ctx, out, text); + fz_printf(ctx, out, "\n"); } static void fz_trace_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { - printf("font->name, text->wmode); - fz_trace_color(colorspace, color, alpha); - fz_trace_matrix(ctm); - fz_trace_trm(&text->trm); - printf(">\n"); - fz_print_text(ctx, stdout, text); - printf("\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "font->name, text->wmode); + fz_trace_color(ctx, out, colorspace, color, alpha); + fz_trace_matrix(ctx, out, ctm); + fz_trace_trm(ctx, out, &text->trm); + fz_printf(ctx, out, ">\n"); + fz_trace_text(ctx, out, text); + fz_printf(ctx, out, "\n"); } static void fz_trace_clip_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate) { - printf("font->name, text->wmode); - printf(" accumulate=\"%d\"", accumulate); - fz_trace_matrix(ctm); - fz_trace_trm(&text->trm); - printf(">\n"); - fz_print_text(ctx, stdout, text); - printf("\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "font->name, text->wmode); + fz_printf(ctx, out, " accumulate=\"%d\"", accumulate); + fz_trace_matrix(ctx, out, ctm); + fz_trace_trm(ctx, out, &text->trm); + fz_printf(ctx, out, ">\n"); + fz_trace_text(ctx, out, text); + fz_printf(ctx, out, "\n"); } static void fz_trace_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm) { - printf("font->name, text->wmode); - fz_trace_matrix(ctm); - fz_trace_trm(&text->trm); - printf(">\n"); - fz_print_text(ctx, stdout, text); - printf("\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "font->name, text->wmode); + fz_trace_matrix(ctx, out, ctm); + fz_trace_trm(ctx, out, &text->trm); + fz_printf(ctx, out, ">\n"); + fz_trace_text(ctx, out, text); + fz_printf(ctx, out, "\n"); } static void fz_trace_ignore_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm) { - printf("font->name, text->wmode); - fz_trace_matrix(ctm); - fz_trace_trm(&text->trm); - printf(">\n"); - fz_print_text(ctx, stdout, text); - printf("\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "font->name, text->wmode); + fz_trace_matrix(ctx, out, ctm); + fz_trace_trm(ctx, out, &text->trm); + fz_printf(ctx, out, ">\n"); + fz_trace_text(ctx, out, text); + fz_printf(ctx, out, "\n"); } static void fz_trace_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha) { - printf("w, image->h); - printf("/>\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "w, image->h); + fz_printf(ctx, out, "/>\n"); } static void fz_trace_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha) { - printf("\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "\n"); } static void fz_trace_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { - printf("w, image->h); - printf("/>\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "w, image->h); + fz_printf(ctx, out, "/>\n"); } static void fz_trace_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm) { - printf("w, image->h); - printf("/>\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "w, image->h); + fz_printf(ctx, out, "/>\n"); } static void fz_trace_pop_clip(fz_context *ctx, fz_device *dev) { - printf("\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "\n"); } static void fz_trace_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int luminosity, fz_colorspace *colorspace, float *color) { - printf("out; + fz_printf(ctx, out, "x0, bbox->y0, bbox->x1, bbox->y1, luminosity ? "luminosity" : "alpha"); - printf(">\n"); + fz_printf(ctx, out, ">\n"); } static void fz_trace_end_mask(fz_context *ctx, fz_device *dev) { - printf("\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "\n"); } static void fz_trace_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int isolated, int knockout, int blendmode, float alpha) { - printf("\n", + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "\n", bbox->x0, bbox->y0, bbox->x1, bbox->y1, isolated, knockout, fz_blendmode_name(blendmode), alpha); } @@ -299,59 +329,64 @@ fz_trace_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int i static void fz_trace_end_group(fz_context *ctx, fz_device *dev) { - printf("\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "\n"); } static int fz_trace_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id) { - printf("x0, area->y0, area->x1, area->y1); - printf(" view=\"%g %g %g %g\"", view->x0, view->y0, view->x1, view->y1); - printf(" xstep=\"%g\" ystep=\"%g\"", xstep, ystep); - fz_trace_matrix(ctm); - printf(">\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "x0, area->y0, area->x1, area->y1); + fz_printf(ctx, out, " view=\"%g %g %g %g\"", view->x0, view->y0, view->x1, view->y1); + fz_printf(ctx, out, " xstep=\"%g\" ystep=\"%g\"", xstep, ystep); + fz_trace_matrix(ctx, out, ctm); + fz_printf(ctx, out, ">\n"); return 0; } static void fz_trace_end_tile(fz_context *ctx, fz_device *dev) { - printf("\n"); + fz_output *out = ((fz_trace_device*)dev)->out; + fz_printf(ctx, out, "\n"); } -fz_device *fz_new_trace_device(fz_context *ctx) +fz_device *fz_new_trace_device(fz_context *ctx, fz_output *out) { - fz_device *dev = fz_new_device(ctx, sizeof *dev); + fz_trace_device *dev = fz_new_device(ctx, sizeof *dev); + + dev->super.begin_page = fz_trace_begin_page; + dev->super.end_page = fz_trace_end_page; - dev->begin_page = fz_trace_begin_page; - dev->end_page = fz_trace_end_page; + dev->super.fill_path = fz_trace_fill_path; + dev->super.stroke_path = fz_trace_stroke_path; + dev->super.clip_path = fz_trace_clip_path; + dev->super.clip_stroke_path = fz_trace_clip_stroke_path; - dev->fill_path = fz_trace_fill_path; - dev->stroke_path = fz_trace_stroke_path; - dev->clip_path = fz_trace_clip_path; - dev->clip_stroke_path = fz_trace_clip_stroke_path; + dev->super.fill_text = fz_trace_fill_text; + dev->super.stroke_text = fz_trace_stroke_text; + dev->super.clip_text = fz_trace_clip_text; + dev->super.clip_stroke_text = fz_trace_clip_stroke_text; + dev->super.ignore_text = fz_trace_ignore_text; - dev->fill_text = fz_trace_fill_text; - dev->stroke_text = fz_trace_stroke_text; - dev->clip_text = fz_trace_clip_text; - dev->clip_stroke_text = fz_trace_clip_stroke_text; - dev->ignore_text = fz_trace_ignore_text; + dev->super.fill_shade = fz_trace_fill_shade; + dev->super.fill_image = fz_trace_fill_image; + dev->super.fill_image_mask = fz_trace_fill_image_mask; + dev->super.clip_image_mask = fz_trace_clip_image_mask; - dev->fill_shade = fz_trace_fill_shade; - dev->fill_image = fz_trace_fill_image; - dev->fill_image_mask = fz_trace_fill_image_mask; - dev->clip_image_mask = fz_trace_clip_image_mask; + dev->super.pop_clip = fz_trace_pop_clip; - dev->pop_clip = fz_trace_pop_clip; + dev->super.begin_mask = fz_trace_begin_mask; + dev->super.end_mask = fz_trace_end_mask; + dev->super.begin_group = fz_trace_begin_group; + dev->super.end_group = fz_trace_end_group; - dev->begin_mask = fz_trace_begin_mask; - dev->end_mask = fz_trace_end_mask; - dev->begin_group = fz_trace_begin_group; - dev->end_group = fz_trace_end_group; + dev->super.begin_tile = fz_trace_begin_tile; + dev->super.end_tile = fz_trace_end_tile; - dev->begin_tile = fz_trace_begin_tile; - dev->end_tile = fz_trace_end_tile; + dev->out = out; - return dev; + return (fz_device*)dev; } diff --git a/source/fitz/unzip.c b/source/fitz/unzip.c index b14705ba..21cfa7a5 100644 --- a/source/fitz/unzip.c +++ b/source/fitz/unzip.c @@ -364,14 +364,10 @@ fz_has_archive_entry(fz_context *ctx, fz_archive *zip, const char *name) if (zip->directory) { char path[2048]; - FILE *file; fz_strlcpy(path, zip->directory, sizeof path); fz_strlcat(path, "/", sizeof path); fz_strlcat(path, name, sizeof path); - file = fz_fopen(path, "rb"); - if (file) - fclose(file); - return file != NULL; + return fz_file_exists(ctx, path); } else { -- cgit v1.2.3