summaryrefslogtreecommitdiff
path: root/include/mupdf
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2015-11-09 14:17:00 +0100
committerTor Andersson <tor.andersson@artifex.com>2015-12-11 12:11:31 +0100
commitc22e6a6dc2bf6acbac955bd5fbdd896329dfd725 (patch)
treed9d84d3a6a74ed74c9d470b532097769545e8dc6 /include/mupdf
parent95b928431f233052e4bbbd1b2bf9fc705657b5a7 (diff)
downloadmupdf-c22e6a6dc2bf6acbac955bd5fbdd896329dfd725.tar.xz
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.
Diffstat (limited to 'include/mupdf')
-rw-r--r--include/mupdf/fitz/buffer.h23
-rw-r--r--include/mupdf/fitz/device.h5
-rw-r--r--include/mupdf/fitz/font.h4
-rw-r--r--include/mupdf/fitz/function.h8
-rw-r--r--include/mupdf/fitz/hash.h7
-rw-r--r--include/mupdf/fitz/output-pnm.h16
-rw-r--r--include/mupdf/fitz/output.h73
-rw-r--r--include/mupdf/fitz/path.h4
-rw-r--r--include/mupdf/fitz/shade.h4
-rw-r--r--include/mupdf/fitz/store.h10
-rw-r--r--include/mupdf/fitz/stream.h5
-rw-r--r--include/mupdf/fitz/text.h1
-rw-r--r--include/mupdf/pdf/cmap.h4
-rw-r--r--include/mupdf/pdf/crypt.h4
-rw-r--r--include/mupdf/pdf/font.h4
-rw-r--r--include/mupdf/pdf/object.h8
16 files changed, 70 insertions, 110 deletions
diff --git a/include/mupdf/fitz/buffer.h b/include/mupdf/fitz/buffer.h
index a96f7603..0d0bb3b0 100644
--- a/include/mupdf/fitz/buffer.h
+++ b/include/mupdf/fitz/buffer.h
@@ -110,28 +110,19 @@ void fz_trim_buffer(fz_context *ctx, fz_buffer *buf);
*/
void fz_buffer_cat(fz_context *ctx, fz_buffer *buf, fz_buffer *extra);
+/*
+ fz_write_buffer*: write to a buffer.
+ fz_buffer_printf: print formatted to a buffer.
+ fz_buffer_cat_pdf_string: Print a string using PDF syntax and escapes.
+ The buffer will grow as required.
+*/
void fz_write_buffer(fz_context *ctx, fz_buffer *buf, const void *data, int len);
-
void fz_write_buffer_byte(fz_context *ctx, fz_buffer *buf, int val);
-
void fz_write_buffer_rune(fz_context *ctx, fz_buffer *buf, int val);
-
void fz_write_buffer_bits(fz_context *ctx, fz_buffer *buf, int val, int bits);
-
void fz_write_buffer_pad(fz_context *ctx, fz_buffer *buf);
-
-/*
- fz_buffer_printf: print formatted to a buffer. The buffer will grow
- as required.
-*/
int fz_buffer_printf(fz_context *ctx, fz_buffer *buffer, const char *fmt, ...);
int fz_buffer_vprintf(fz_context *ctx, fz_buffer *buffer, const char *fmt, va_list args);
-
-/*
- fz_buffer_printf: print a string formatted as a pdf string to a buffer.
- The buffer will grow.
-*/
-void
-fz_buffer_cat_pdf_string(fz_context *ctx, fz_buffer *buffer, const char *text);
+void fz_buffer_cat_pdf_string(fz_context *ctx, fz_buffer *buffer, const char *text);
#endif
diff --git a/include/mupdf/fitz/device.h b/include/mupdf/fitz/device.h
index e3b17fc6..3f2585ae 100644
--- a/include/mupdf/fitz/device.h
+++ b/include/mupdf/fitz/device.h
@@ -274,10 +274,9 @@ struct fz_cookie_s
};
/*
- fz_new_trace_device: Create a device to print a debug trace of
- all device calls.
+ fz_new_trace_device: Create a device to print a debug trace of all device calls.
*/
-fz_device *fz_new_trace_device(fz_context *ctx);
+fz_device *fz_new_trace_device(fz_context *ctx, fz_output *out);
/*
fz_new_bbox_device: Create a device to compute the bounding
diff --git a/include/mupdf/fitz/font.h b/include/mupdf/fitz/font.h
index e912eb75..1e053470 100644
--- a/include/mupdf/fitz/font.h
+++ b/include/mupdf/fitz/font.h
@@ -97,8 +97,6 @@ void fz_decouple_type3_font(fz_context *ctx, fz_font *font, void *t3doc);
float fz_advance_glyph(fz_context *ctx, fz_font *font, int glyph);
int fz_encode_character(fz_context *ctx, fz_font *font, int unicode);
-#ifndef NDEBUG
-void fz_print_font(fz_context *ctx, FILE *out, fz_font *font);
-#endif
+void fz_print_font(fz_context *ctx, fz_output *out, fz_font *font);
#endif
diff --git a/include/mupdf/fitz/function.h b/include/mupdf/fitz/function.h
index 005cef3f..0d17da6d 100644
--- a/include/mupdf/fitz/function.h
+++ b/include/mupdf/fitz/function.h
@@ -16,9 +16,7 @@ void fz_eval_function(fz_context *ctx, fz_function *func, const float *in, int i
fz_function *fz_keep_function(fz_context *ctx, fz_function *func);
void fz_drop_function(fz_context *ctx, fz_function *func);
unsigned int fz_function_size(fz_context *ctx, fz_function *func);
-#ifndef NDEBUG
-void pdf_debug_function(fz_context *ctx, fz_function *func);
-#endif
+void fz_print_function(fz_context *ctx, fz_output *out, fz_function *func);
enum
{
@@ -33,9 +31,7 @@ struct fz_function_s
int m; /* number of input values */
int n; /* number of output values */
void (*evaluate)(fz_context *ctx, fz_function *func, const float *in, float *out);
-#ifndef NDEBUG
- void (*debug)(fz_context *ctx, fz_function *func);
-#endif
+ void (*print)(fz_context *ctx, fz_output *out, fz_function *func);
};
#endif
diff --git a/include/mupdf/fitz/hash.h b/include/mupdf/fitz/hash.h
index c56c9d13..8d4874d7 100644
--- a/include/mupdf/fitz/hash.h
+++ b/include/mupdf/fitz/hash.h
@@ -3,6 +3,7 @@
#include "mupdf/fitz/system.h"
#include "mupdf/fitz/context.h"
+#include "mupdf/fitz/output.h"
/*
* Generic hash-table with fixed-length keys.
@@ -24,9 +25,7 @@ int fz_hash_len(fz_context *ctx, fz_hash_table *table);
void *fz_hash_get_key(fz_context *ctx, fz_hash_table *table, int idx);
void *fz_hash_get_val(fz_context *ctx, fz_hash_table *table, int idx);
-#ifndef NDEBUG
-void fz_print_hash(fz_context *ctx, FILE *out, fz_hash_table *table);
-void fz_print_hash_details(fz_context *ctx, FILE *out, fz_hash_table *table, void (*details)(FILE *, void *));
-#endif
+void fz_print_hash(fz_context *ctx, fz_output *out, fz_hash_table *table);
+void fz_print_hash_details(fz_context *ctx, fz_output *out, fz_hash_table *table, void (*details)(fz_context*, fz_output*, void*));
#endif
diff --git a/include/mupdf/fitz/output-pnm.h b/include/mupdf/fitz/output-pnm.h
index 54e8355c..0ea8a894 100644
--- a/include/mupdf/fitz/output-pnm.h
+++ b/include/mupdf/fitz/output-pnm.h
@@ -8,30 +8,28 @@
#include "mupdf/fitz/bitmap.h"
/*
- fz_write_pnm: Save a pixmap as a pnm
-
- filename: The filename to save as (including extension).
+ fz_write_pnm: Save a pixmap as a PNM image file.
*/
void fz_write_pnm(fz_context *ctx, fz_pixmap *pixmap, char *filename);
+void fz_output_pnm(fz_context *ctx, fz_output *out, fz_pixmap *pixmap);
void fz_output_pnm_header(fz_context *ctx, fz_output *out, int w, int h, int n);
void fz_output_pnm_band(fz_context *ctx, fz_output *out, int w, int h, int n, int band, int bandheight, unsigned char *p);
/*
- fz_write_pam: Save a pixmap as a pam
-
- filename: The filename to save as (including extension).
+ fz_write_pam: Save a pixmap as a PAM image file.
*/
void fz_write_pam(fz_context *ctx, fz_pixmap *pixmap, char *filename, int savealpha);
+void fz_output_pam(fz_context *ctx, fz_output *out, fz_pixmap *pixmap, int savealpha);
void fz_output_pam_header(fz_context *ctx, fz_output *out, int w, int h, int n, int savealpha);
void fz_output_pam_band(fz_context *ctx, fz_output *out, int w, int h, int n, int band, int bandheight, unsigned char *sp, int savealpha);
/*
- fz_write_pbm: Save a bitmap as a pbm
-
- filename: The filename to save as (including extension).
+ fz_write_pbm: Save a bitmap as a PBM image file.
*/
void fz_write_pbm(fz_context *ctx, fz_bitmap *bitmap, char *filename);
+void fz_output_pbm(fz_context *ctx, fz_output *out, fz_bitmap *bitmap);
+
#endif
diff --git a/include/mupdf/fitz/output.h b/include/mupdf/fitz/output.h
index 576755d3..449b76a6 100644
--- a/include/mupdf/fitz/output.h
+++ b/include/mupdf/fitz/output.h
@@ -4,6 +4,7 @@
#include "mupdf/fitz/system.h"
#include "mupdf/fitz/context.h"
#include "mupdf/fitz/buffer.h"
+#include "mupdf/fitz/string.h"
/*
Generic output streams - generalise between outputting to a file,
@@ -12,52 +13,47 @@
typedef struct fz_output_s fz_output;
/*
- fz_new_output_with_file: Open an output stream onto a FILE *.
-
- The stream does NOT take ownership of the FILE *.
-*/
-fz_output *fz_new_output_with_file(fz_context *, FILE *, int close);
-
-/*
- fz_new_output_to_filename: Open an output stream to a filename.
-*/
-fz_output *fz_new_output_to_filename(fz_context *, const char *filename);
-
-/*
- fz_new_output_with_buffer: Open an output stream onto a buffer.
-
- The stream does NOT take ownership of the buffer.
+ fz_new_output_with_file: Open an output stream that writes to a FILE *.
+ fz_new_output_with_path: Open an output stream that writes to a file.
+ fz_new_output_with_buffer: Open an output stream that writes into a buffer.
*/
+fz_output *fz_new_output_with_file_ptr(fz_context *, FILE *, int close);
+fz_output *fz_new_output_with_path(fz_context *, const char *filename, int append);
fz_output *fz_new_output_with_buffer(fz_context *, fz_buffer *);
/*
- fz_printf: fprintf equivalent for output streams.
-*/
-int fz_printf(fz_context *, fz_output *, const char *, ...);
-
-/*
+ fz_write: fwrite equivalent for output streams.
+ fz_printf: fprintf equivalent for output streams. See fz_snprintf.
+ fz_vprintf: vfprintf equivalent for output streams. See fz_vsnprintf.
fz_puts: fputs equivalent for output streams.
+ fz_putc: fputc equivalent for output streams.
+ fz_putrune: fputrune equivalent for output streams.
*/
-int fz_puts(fz_context *, fz_output *, const char *);
+void fz_printf(fz_context *ctx, fz_output *out, const char *fmt, ...);
+void fz_vprintf(fz_context *ctx, fz_output *out, const char *fmt, va_list ap);
+int fz_write(fz_context *, fz_output *out, const void *data, int len);
+#define fz_puts(C,O,S) fz_write(C, O, (S), strlen(S))
+#define fz_putc(C,O,B) fz_write_byte(C, O, B)
+#define fz_putrune(C,O,R) fz_write_rune(C, O, R)
/*
- fz_write: fwrite equivalent for output streams.
+ fz_seek_output: Seek to the specified file position. Throw an error on unseekable outputs.
+ fz_tell_output: Return the current file position. Throw an error on unseekable outputs.
*/
-int fz_write(fz_context *, fz_output *out, const void *data, int len);
+void fz_seek_output(fz_context *ctx, fz_output *out, fz_off_t off, int whence);
+fz_off_t fz_tell_output(fz_context *ctx, fz_output *out);
/*
- fz_putc: putc equivalent for output streams.
+ fz_drop_output: Close and free an output stream.
*/
-void fz_putc(fz_context *, fz_output *out, char c);
+void fz_drop_output(fz_context *, fz_output *);
/*
- fz_drop_output: Close a previously opened fz_output stream.
-
- Note: whether or not this closes the underlying output method is
- method dependent. FILE * streams created by fz_new_output_with_file
- are NOT closed.
+ fz_write_int32be: Write a big-endian 32-bit binary integer.
+ fz_write_int32le: Write a little-endian 32-bit binary integer.
+ fz_write_byte: Write a single byte.
+ fz_write_rune: Write a UTF-8 encoded unicode character.
*/
-void fz_drop_output(fz_context *, fz_output *);
static inline int fz_write_int32be(fz_context *ctx, fz_output *out, int x)
{
@@ -83,20 +79,19 @@ static inline int fz_write_int32le(fz_context *ctx, fz_output *out, int x)
return fz_write(ctx, out, data, 4);
}
-static inline void
-fz_write_byte(fz_context *ctx, fz_output *out, int x)
+static inline void fz_write_byte(fz_context *ctx, fz_output *out, int x)
{
char data = x;
fz_write(ctx, out, &data, 1);
}
-/*
- fz_vfprintf: Our customised vfprintf routine. Same supported
- format specifiers as for fz_vsnprintf.
-*/
-int fz_vfprintf(fz_context *ctx, FILE *file, const char *fmt, va_list ap);
-int fz_fprintf(fz_context *ctx, FILE *file, const char *fmt, ...);
+static inline void fz_write_rune(fz_context *ctx, fz_output *out, int rune)
+{
+ char data[10];
+
+ fz_write(ctx, out, data, fz_runetochar(data, rune));
+}
/*
fz_vsnprintf: Our customised vsnprintf routine. Takes %c, %d, %o, %s, %u, %x, as usual.
diff --git a/include/mupdf/fitz/path.h b/include/mupdf/fitz/path.h
index 81b6f7bb..0a602f18 100644
--- a/include/mupdf/fitz/path.h
+++ b/include/mupdf/fitz/path.h
@@ -92,8 +92,6 @@ fz_stroke_state *fz_unshare_stroke_state(fz_context *ctx, fz_stroke_state *share
fz_stroke_state *fz_unshare_stroke_state_with_dash_len(fz_context *ctx, fz_stroke_state *shared, int len);
fz_stroke_state *fz_clone_stroke_state(fz_context *ctx, fz_stroke_state *stroke);
-#ifndef NDEBUG
-void fz_print_path(fz_context *ctx, FILE *out, fz_path *, int indent);
-#endif
+void fz_print_path(fz_context *ctx, fz_output *out, fz_path *, int indent);
#endif
diff --git a/include/mupdf/fitz/shade.h b/include/mupdf/fitz/shade.h
index 55e8767b..56adea5b 100644
--- a/include/mupdf/fitz/shade.h
+++ b/include/mupdf/fitz/shade.h
@@ -96,8 +96,6 @@ typedef void (fz_mesh_process_fn)(fz_context *ctx, void *arg, fz_vertex *av, fz_
void fz_process_mesh(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm,
fz_mesh_prepare_fn *prepare, fz_mesh_process_fn *process, void *process_arg);
-#ifndef NDEBUG
-void fz_print_shade(fz_context *ctx, FILE *out, fz_shade *shade);
-#endif
+void fz_print_shade(fz_context *ctx, fz_output *out, fz_shade *shade);
#endif
diff --git a/include/mupdf/fitz/store.h b/include/mupdf/fitz/store.h
index 49e3cc17..3b7b69ab 100644
--- a/include/mupdf/fitz/store.h
+++ b/include/mupdf/fitz/store.h
@@ -92,9 +92,7 @@ struct fz_store_type_s
void *(*keep_key)(fz_context *,void *);
void (*drop_key)(fz_context *,void *);
int (*cmp_key)(fz_context *ctx, void *, void *);
-#ifndef NDEBUG
- void (*debug)(fz_context *ctx, FILE *, void *);
-#endif
+ void (*print)(fz_context *ctx, fz_output *out, void *);
};
/*
@@ -197,9 +195,7 @@ int fz_shrink_store(fz_context *ctx, unsigned int percent);
/*
fz_print_store: Dump the contents of the store for debugging.
*/
-#ifndef NDEBUG
-void fz_print_store(fz_context *ctx, FILE *out);
-void fz_print_store_locked(fz_context *ctx, FILE *out);
-#endif
+void fz_print_store(fz_context *ctx, fz_output *out);
+void fz_print_store_locked(fz_context *ctx, fz_output *out);
#endif
diff --git a/include/mupdf/fitz/stream.h b/include/mupdf/fitz/stream.h
index 8e9ee638..d9cb7509 100644
--- a/include/mupdf/fitz/stream.h
+++ b/include/mupdf/fitz/stream.h
@@ -6,6 +6,11 @@
#include "mupdf/fitz/buffer.h"
/*
+ fz_file_exists: Return true if the named file exists and is readable.
+*/
+int fz_file_exists(fz_context *ctx, const char *path);
+
+/*
fz_stream is a buffered reader capable of seeking in both
directions.
diff --git a/include/mupdf/fitz/text.h b/include/mupdf/fitz/text.h
index eb2ad12e..303731bc 100644
--- a/include/mupdf/fitz/text.h
+++ b/include/mupdf/fitz/text.h
@@ -44,6 +44,5 @@ void fz_drop_text(fz_context *ctx, fz_text *text);
void fz_add_text(fz_context *ctx, fz_text *text, int gid, int ucs, float x, float y);
fz_rect *fz_bound_text(fz_context *ctx, fz_text *text, const fz_stroke_state *stroke, const fz_matrix *ctm, fz_rect *r);
-void fz_print_text(fz_context *ctx, FILE *out, fz_text*);
#endif
diff --git a/include/mupdf/pdf/cmap.h b/include/mupdf/pdf/cmap.h
index e17ebbaa..7b437b1d 100644
--- a/include/mupdf/pdf/cmap.h
+++ b/include/mupdf/pdf/cmap.h
@@ -81,8 +81,6 @@ pdf_cmap *pdf_load_system_cmap(fz_context *ctx, char *name);
pdf_cmap *pdf_load_builtin_cmap(fz_context *ctx, char *name);
pdf_cmap *pdf_load_embedded_cmap(fz_context *ctx, pdf_document *doc, pdf_obj *ref);
-#ifndef NDEBUG
-void pdf_print_cmap(fz_context *ctx, pdf_cmap *cmap);
-#endif
+void pdf_print_cmap(fz_context *ctx, fz_output *out, pdf_cmap *cmap);
#endif
diff --git a/include/mupdf/pdf/crypt.h b/include/mupdf/pdf/crypt.h
index 00f36322..18260dbb 100644
--- a/include/mupdf/pdf/crypt.h
+++ b/include/mupdf/pdf/crypt.h
@@ -19,9 +19,7 @@ char *pdf_crypt_method(fz_context *ctx, pdf_document *doc);
int pdf_crypt_length(fz_context *ctx, pdf_document *doc);
unsigned char *pdf_crypt_key(fz_context *ctx, pdf_document *doc);
-#ifndef NDEBUG
-void pdf_print_crypt(fz_context *ctx, pdf_crypt *crypt);
-#endif
+void pdf_print_crypt(fz_context *ctx, fz_output *out, pdf_crypt *crypt);
typedef struct pdf_designated_name_s
{
diff --git a/include/mupdf/pdf/font.h b/include/mupdf/pdf/font.h
index 7697053f..9bd8d913 100644
--- a/include/mupdf/pdf/font.h
+++ b/include/mupdf/pdf/font.h
@@ -116,9 +116,7 @@ pdf_font_desc *pdf_new_font_desc(fz_context *ctx);
pdf_font_desc *pdf_keep_font(fz_context *ctx, pdf_font_desc *fontdesc);
void pdf_drop_font(fz_context *ctx, pdf_font_desc *font);
-#ifndef NDEBUG
-void pdf_print_font(fz_context *ctx, pdf_font_desc *fontdesc);
-#endif
+void pdf_print_font(fz_context *ctx, fz_output *out, pdf_font_desc *fontdesc);
fz_rect *pdf_measure_text(fz_context *ctx, pdf_font_desc *fontdesc, unsigned char *buf, int len, fz_rect *rect);
float pdf_text_stride(fz_context *ctx, pdf_font_desc *fontdesc, float fontsize, unsigned char *buf, int len, float room, int *count);
diff --git a/include/mupdf/pdf/object.h b/include/mupdf/pdf/object.h
index 84dbc4fe..c196bece 100644
--- a/include/mupdf/pdf/object.h
+++ b/include/mupdf/pdf/object.h
@@ -131,13 +131,7 @@ int pdf_obj_refs(fz_context *ctx, pdf_obj *ref);
int pdf_obj_parent_num(fz_context *ctx, pdf_obj *obj);
int pdf_sprint_obj(fz_context *ctx, char *s, int n, pdf_obj *obj, int tight);
-int pdf_fprint_obj(fz_context *ctx, FILE *fp, pdf_obj *obj, int tight);
-int pdf_output_obj(fz_context *ctx, fz_output *out, pdf_obj *obj, int tight);
-
-#ifndef NDEBUG
-void pdf_print_obj(fz_context *ctx, pdf_obj *obj);
-void pdf_print_ref(fz_context *ctx, pdf_obj *obj);
-#endif
+int pdf_print_obj(fz_context *ctx, fz_output *out, pdf_obj *obj, int tight);
char *pdf_to_utf8(fz_context *ctx, pdf_document *doc, pdf_obj *src);
unsigned short *pdf_to_ucs2(fz_context *ctx, pdf_document *doc, pdf_obj *src);