From 7888b56b928707329a84a61eca8f8e75ef6a745a Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Tue, 13 Mar 2012 15:11:32 +0000 Subject: Make fz_print functions all take a FILE *. Also tidy up the taking of fz_context *'s, and hide an unwanted indent param. --- fitz/base_hash.c | 12 ++++++------ fitz/dev_text.c | 8 ++++---- fitz/dev_trace.c | 10 +++++----- fitz/doc_outline.c | 28 ++++++++++++++-------------- fitz/fitz-internal.h | 12 ++++++------ fitz/fitz.h | 35 +++++++++++++++++++++++------------ fitz/res_font.c | 14 +++++++------- fitz/res_path.c | 16 ++++++++-------- fitz/res_shade.c | 34 +++++++++++++++++----------------- fitz/res_store.c | 14 +++++++------- fitz/res_text.c | 17 ++++++++++++----- 11 files changed, 109 insertions(+), 91 deletions(-) (limited to 'fitz') diff --git a/fitz/base_hash.c b/fitz/base_hash.c index bf56b9bc..4ba02f4d 100644 --- a/fitz/base_hash.c +++ b/fitz/base_hash.c @@ -268,22 +268,22 @@ fz_hash_remove(fz_context *ctx, fz_hash_table *table, void *key) } void -fz_print_hash(fz_context *ctx, fz_hash_table *table) +fz_print_hash(fz_context *ctx, FILE *out, fz_hash_table *table) { int i, k; - printf("cache load %d / %d\n", table->load, table->size); + fprintf(out, "cache load %d / %d\n", table->load, table->size); for (i = 0; i < table->size; i++) { if (!table->ents[i].val) - printf("table % 4d: empty\n", i); + fprintf(out, "table % 4d: empty\n", i); else { - printf("table % 4d: key=", i); + fprintf(out, "table % 4d: key=", i); for (k = 0; k < MAX_KEY_LEN; k++) - printf("%02x", ((char*)table->ents[i].key)[k]); - printf(" val=$%p\n", table->ents[i].val); + fprintf(out, "%02x", ((char*)table->ents[i].key)[k]); + fprintf(out, " val=$%p\n", table->ents[i].val); } } } diff --git a/fitz/dev_text.c b/fitz/dev_text.c index bb6aaac9..7a059e5a 100644 --- a/fitz/dev_text.c +++ b/fitz/dev_text.c @@ -597,7 +597,7 @@ fz_print_style(FILE *out, fz_text_style *style) } void -fz_print_text_sheet(FILE *out, fz_text_sheet *sheet) +fz_print_text_sheet(fz_context *ctx, FILE *out, fz_text_sheet *sheet) { fz_text_style *style; for (style = sheet->style; style; style = style->next) @@ -605,7 +605,7 @@ fz_print_text_sheet(FILE *out, fz_text_sheet *sheet) } void -fz_print_text_page_html(FILE *out, fz_text_page *page) +fz_print_text_page_html(fz_context *ctx, FILE *out, fz_text_page *page) { int block_n, line_n, span_n, ch_n; fz_text_style *style = NULL; @@ -661,7 +661,7 @@ fz_print_text_page_html(FILE *out, fz_text_page *page) } void -fz_print_text_page_xml(FILE *out, fz_text_page *page) +fz_print_text_page_xml(fz_context *ctx, FILE *out, fz_text_page *page) { fz_text_block *block; fz_text_line *line; @@ -716,7 +716,7 @@ fz_print_text_page_xml(FILE *out, fz_text_page *page) } void -fz_print_text_page(FILE *out, fz_text_page *page) +fz_print_text_page(fz_context *ctx, FILE *out, fz_text_page *page) { fz_text_block *block; fz_text_line *line; diff --git a/fitz/dev_trace.c b/fitz/dev_trace.c index 33406130..b3c73ff2 100644 --- a/fitz/dev_trace.c +++ b/fitz/dev_trace.c @@ -145,7 +145,7 @@ fz_trace_fill_text(fz_device *dev, fz_text *text, fz_matrix ctm, fz_trace_matrix(ctm); fz_trace_trm(text->trm); printf(">\n"); - fz_print_text(dev->ctx, text, 0); + fz_print_text(dev->ctx, stdout, text); printf("\n"); } @@ -158,7 +158,7 @@ fz_trace_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, fz_ fz_trace_matrix(ctm); fz_trace_trm(text->trm); printf(">\n"); - fz_print_text(dev->ctx, text, 0); + fz_print_text(dev->ctx, stdout, text); printf("\n"); } @@ -170,7 +170,7 @@ fz_trace_clip_text(fz_device *dev, fz_text *text, fz_matrix ctm, int accumulate) fz_trace_matrix(ctm); fz_trace_trm(text->trm); printf(">\n"); - fz_print_text(dev->ctx, text, 0); + fz_print_text(dev->ctx, stdout, text); printf("\n"); } @@ -181,7 +181,7 @@ fz_trace_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke fz_trace_matrix(ctm); fz_trace_trm(text->trm); printf(">\n"); - fz_print_text(dev->ctx, text, 0); + fz_print_text(dev->ctx, stdout, text); printf("\n"); } @@ -192,7 +192,7 @@ fz_trace_ignore_text(fz_device *dev, fz_text *text, fz_matrix ctm) fz_trace_matrix(ctm); fz_trace_trm(text->trm); printf(">\n"); - fz_print_text(dev->ctx, text, 0); + fz_print_text(dev->ctx, stdout, text); printf("\n"); } diff --git a/fitz/doc_outline.c b/fitz/doc_outline.c index 023abd23..71694851 100644 --- a/fitz/doc_outline.c +++ b/fitz/doc_outline.c @@ -15,48 +15,48 @@ fz_free_outline(fz_context *ctx, fz_outline *outline) } static void -do_debug_outline_xml(fz_outline *outline, int level) +do_debug_outline_xml(FILE *out, fz_outline *outline, int level) { while (outline) { - printf("title, outline->dest.kind == FZ_LINK_GOTO ? outline->dest.ld.gotor.page + 1 : 0); + fprintf(out, "title, outline->dest.kind == FZ_LINK_GOTO ? outline->dest.ld.gotor.page + 1 : 0); if (outline->down) { - printf(">\n"); - do_debug_outline_xml(outline->down, level + 1); - printf("\n"); + fprintf(out, ">\n"); + do_debug_outline_xml(out, outline->down, level + 1); + fprintf(out, "\n"); } else { - printf(" />\n"); + fprintf(out, " />\n"); } outline = outline->next; } } void -fz_print_outline_xml(fz_context *ctx, fz_outline *outline) +fz_print_outline_xml(fz_context *ctx, FILE *out, fz_outline *outline) { - do_debug_outline_xml(outline, 0); + do_debug_outline_xml(out, outline, 0); } static void -do_debug_outline(fz_outline *outline, int level) +do_debug_outline(FILE *out, fz_outline *outline, int level) { int i; while (outline) { for (i = 0; i < level; i++) - putchar('\t'); - printf("%s\t%d\n", outline->title, outline->dest.kind == FZ_LINK_GOTO ? outline->dest.ld.gotor.page + 1 : 0); + fputc('\t', out); + fprintf(out, "%s\t%d\n", outline->title, outline->dest.kind == FZ_LINK_GOTO ? outline->dest.ld.gotor.page + 1 : 0); if (outline->down) - do_debug_outline(outline->down, level + 1); + do_debug_outline(out, outline->down, level + 1); outline = outline->next; } } void -fz_print_outline(fz_context *ctx, fz_outline *outline) +fz_print_outline(fz_context *ctx, FILE *out, fz_outline *outline) { - do_debug_outline(outline, 0); + do_debug_outline(out, outline, 0); } diff --git a/fitz/fitz-internal.h b/fitz/fitz-internal.h index 2e9508a6..300f4900 100644 --- a/fitz/fitz-internal.h +++ b/fitz/fitz-internal.h @@ -87,7 +87,7 @@ float fz_atof(const char *s); typedef struct fz_hash_table_s fz_hash_table; fz_hash_table *fz_new_hash_table(fz_context *ctx, int initialsize, int keylen, int lock); -void fz_print_hash(fz_context *ctx, fz_hash_table *table); +void fz_print_hash(fz_context *ctx, FILE *out, fz_hash_table *table); void fz_empty_hash(fz_context *ctx, fz_hash_table *table); void fz_free_hash(fz_context *ctx, fz_hash_table *table); @@ -310,7 +310,7 @@ fz_store *fz_keep_store_context(fz_context *ctx); /* fz_print_store: Dump the contents of the store for debugging. */ -void fz_print_store(fz_context *ctx); +void fz_print_store(fz_context *ctx, FILE *out); /* fz_store_item: Add an item to the store. @@ -736,7 +736,7 @@ fz_font *fz_new_font_from_file(fz_context *ctx, char *path, int index, int use_g fz_font *fz_keep_font(fz_context *ctx, fz_font *font); void fz_drop_font(fz_context *ctx, fz_font *font); -void fz_print_font(fz_context *ctx, fz_font *font); +void fz_print_font(fz_context *ctx, FILE *out, fz_font *font); void fz_set_font_bbox(fz_context *ctx, fz_font *font, float xmin, float ymin, float xmax, float ymax); fz_rect fz_bound_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm); @@ -818,7 +818,7 @@ void fz_transform_path(fz_context *ctx, fz_path *path, fz_matrix transform); fz_path *fz_clone_path(fz_context *ctx, fz_path *old); fz_rect fz_bound_path(fz_context *ctx, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm); -void fz_print_path(fz_context *ctx, fz_path *, int indent); +void fz_print_path(fz_context *ctx, FILE *out, fz_path *, int indent); /* * Glyph cache @@ -872,7 +872,7 @@ void fz_add_text(fz_context *ctx, fz_text *text, int gid, int ucs, float x, floa void fz_free_text(fz_context *ctx, fz_text *text); fz_rect fz_bound_text(fz_context *ctx, fz_text *text, fz_matrix ctm); fz_text *fz_clone_text(fz_context *ctx, fz_text *old); -void fz_print_text(fz_context *ctx, fz_text*, int indent); +void fz_print_text(fz_context *ctx, FILE *out, fz_text*); /* * The shading code uses gouraud shaded triangle meshes. @@ -912,7 +912,7 @@ struct fz_shade_s fz_shade *fz_keep_shade(fz_context *ctx, fz_shade *shade); void fz_drop_shade(fz_context *ctx, fz_shade *shade); void fz_free_shade_imp(fz_context *ctx, fz_storable *shade); -void fz_print_shade(fz_context *ctx, fz_shade *shade); +void fz_print_shade(fz_context *ctx, FILE *out, fz_shade *shade); fz_rect fz_bound_shade(fz_context *ctx, fz_shade *shade, fz_matrix ctm); void fz_paint_shade(fz_context *ctx, fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox); diff --git a/fitz/fitz.h b/fitz/fitz.h index 964bd7f7..a7fcbac4 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -118,7 +118,9 @@ int gettimeofday(struct timeval *tv, struct timezone *tz); #endif #endif -/* Contexts */ +/* + Contexts +*/ typedef struct fz_alloc_context_s fz_alloc_context; typedef struct fz_error_context_s fz_error_context; @@ -467,7 +469,9 @@ void *fz_resize_array_no_throw(fz_context *ctx, void *p, unsigned int count, uns */ char *fz_strdup_no_throw(fz_context *ctx, char *s); -/* safe string functions */ +/* + Safe string functions +*/ /* fz_strsep: Given a pointer to a C string (or a pointer to NULL) break it at the first occurence of a delimiter char (from a given set). @@ -1434,7 +1438,7 @@ fz_device *fz_new_bbox_device(fz_context *ctx, fz_bbox *bboxp); fz_device *fz_new_draw_device(fz_context *ctx, fz_pixmap *dest); /* - * Text extraction device + Text extraction device: Used for searching, format conversion etc. */ typedef struct fz_text_style_s fz_text_style; @@ -1526,10 +1530,10 @@ void fz_free_text_sheet(fz_context *ctx, fz_text_sheet *sheet); fz_text_page *fz_new_text_page(fz_context *ctx, fz_rect mediabox); void fz_free_text_page(fz_context *ctx, fz_text_page *page); -void fz_print_text_sheet(FILE *out, fz_text_sheet *sheet); -void fz_print_text_page_html(FILE *out, fz_text_page *page); -void fz_print_text_page_xml(FILE *out, fz_text_page *page); -void fz_print_text_page(FILE *out, fz_text_page *page); +void fz_print_text_sheet(fz_context *ctx, FILE *out, fz_text_sheet *sheet); +void fz_print_text_page_html(fz_context *ctx, FILE *out, fz_text_page *page); +void fz_print_text_page_xml(fz_context *ctx, FILE *out, fz_text_page *page); +void fz_print_text_page(fz_context *ctx, FILE *out, fz_text_page *page); /* * Cookie support - simple communication channel between app/library. @@ -1815,15 +1819,22 @@ struct fz_outline_s }; /* - fz_print_outline_xml: Dump the given outlines to stdout as (pseudo) - XML. + fz_print_outline_xml: Dump the given outlines as (pseudo) XML. + + out: The file handle to output to. + + outline: The outlines to output. */ -void fz_print_outline_xml(fz_context *ctx, fz_outline *outline); +void fz_print_outline_xml(fz_context *ctx, FILE *out, fz_outline *outline); /* - fz_print_outline: Dump the given outlines to stdout as text. + fz_print_outline: Dump the given outlines to as text. + + out: The file handle to output to. + + outline: The outlines to output. */ -void fz_print_outline(fz_context *ctx, fz_outline *outline); +void fz_print_outline(fz_context *ctx, FILE *out, fz_outline *outline); /* fz_free_outline: Free hierarchical outline. diff --git a/fitz/res_font.c b/fitz/res_font.c index 438d5ba7..c1db35d8 100644 --- a/fitz/res_font.c +++ b/fitz/res_font.c @@ -808,29 +808,29 @@ fz_render_t3_glyph_direct(fz_context *ctx, fz_device *dev, fz_font *font, int gi } void -fz_print_font(fz_context *ctx, fz_font *font) +fz_print_font(fz_context *ctx, FILE *out, fz_font *font) { - printf("font '%s' {\n", font->name); + fprintf(out, "font '%s' {\n", font->name); if (font->ft_face) { - printf("\tfreetype face %p\n", font->ft_face); + fprintf(out, "\tfreetype face %p\n", font->ft_face); if (font->ft_substitute) - printf("\tsubstitute font\n"); + fprintf(out, "\tsubstitute font\n"); } if (font->t3procs) { - printf("\ttype3 matrix [%g %g %g %g]\n", + fprintf(out, "\ttype3 matrix [%g %g %g %g]\n", font->t3matrix.a, font->t3matrix.b, font->t3matrix.c, font->t3matrix.d); - printf("\ttype3 bbox [%g %g %g %g]\n", + fprintf(out, "\ttype3 bbox [%g %g %g %g]\n", font->bbox.x0, font->bbox.y0, font->bbox.x1, font->bbox.y1); } - printf("}\n"); + fprintf(out, "}\n"); } fz_rect diff --git a/fitz/res_path.c b/fitz/res_path.c index 9c2072c1..45ead677 100644 --- a/fitz/res_path.c +++ b/fitz/res_path.c @@ -316,7 +316,7 @@ fz_transform_path(fz_context *ctx, fz_path *path, fz_matrix ctm) } void -fz_print_path(fz_context *ctx, fz_path *path, int indent) +fz_print_path(fz_context *ctx, FILE *out, fz_path *path, int indent) { float x, y; int i = 0; @@ -324,32 +324,32 @@ fz_print_path(fz_context *ctx, fz_path *path, int indent) while (i < path->len) { for (n = 0; n < indent; n++) - putchar(' '); + fputc(' ', out); switch (path->items[i++].k) { case FZ_MOVETO: x = path->items[i++].v; y = path->items[i++].v; - printf("%g %g m\n", x, y); + fprintf(out, "%g %g m\n", x, y); break; case FZ_LINETO: x = path->items[i++].v; y = path->items[i++].v; - printf("%g %g l\n", x, y); + fprintf(out, "%g %g l\n", x, y); break; case FZ_CURVETO: x = path->items[i++].v; y = path->items[i++].v; - printf("%g %g ", x, y); + fprintf(out, "%g %g ", x, y); x = path->items[i++].v; y = path->items[i++].v; - printf("%g %g ", x, y); + fprintf(out, "%g %g ", x, y); x = path->items[i++].v; y = path->items[i++].v; - printf("%g %g c\n", x, y); + fprintf(out, "%g %g c\n", x, y); break; case FZ_CLOSE_PATH: - printf("h\n"); + fprintf(out, "h\n"); break; } } diff --git a/fitz/res_shade.c b/fitz/res_shade.c index 59e3887e..d2b2f44b 100644 --- a/fitz/res_shade.c +++ b/fitz/res_shade.c @@ -68,59 +68,59 @@ fz_bound_shade(fz_context *ctx, fz_shade *shade, fz_matrix ctm) } void -fz_print_shade(fz_context *ctx, fz_shade *shade) +fz_print_shade(fz_context *ctx, FILE *out, fz_shade *shade) { int i, j, n; float *vertex; int triangle; - printf("shading {\n"); + fprintf(out, "shading {\n"); switch (shade->type) { - case FZ_LINEAR: printf("\ttype linear\n"); break; - case FZ_RADIAL: printf("\ttype radial\n"); break; - case FZ_MESH: printf("\ttype mesh\n"); break; + case FZ_LINEAR: fprintf(out, "\ttype linear\n"); break; + case FZ_RADIAL: fprintf(out, "\ttype radial\n"); break; + case FZ_MESH: fprintf(out, "\ttype mesh\n"); break; } - printf("\tbbox [%g %g %g %g]\n", + fprintf(out, "\tbbox [%g %g %g %g]\n", shade->bbox.x0, shade->bbox.y0, shade->bbox.x1, shade->bbox.y1); - printf("\tcolorspace %s\n", shade->colorspace->name); + fprintf(out, "\tcolorspace %s\n", shade->colorspace->name); - printf("\tmatrix [%g %g %g %g %g %g]\n", + fprintf(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) { - printf("\tbackground ["); + fprintf(out, "\tbackground ["); for (i = 0; i < shade->colorspace->n; i++) - printf("%s%g", i == 0 ? "" : " ", shade->background[i]); - printf("]\n"); + fprintf(out, "%s%g", i == 0 ? "" : " ", shade->background[i]); + fprintf(out, "]\n"); } if (shade->use_function) { - printf("\tfunction\n"); + fprintf(out, "\tfunction\n"); n = 3; } else n = 2 + shade->colorspace->n; - printf("\tvertices: %d\n", shade->mesh_len); + fprintf(out, "\tvertices: %d\n", shade->mesh_len); vertex = shade->mesh; triangle = 0; i = 0; while (i < shade->mesh_len) { - printf("\t%d:(%g, %g): ", triangle, vertex[0], vertex[1]); + fprintf(out, "\t%d:(%g, %g): ", triangle, vertex[0], vertex[1]); for (j = 2; j < n; j++) - printf("%s%g", j == 2 ? "" : " ", vertex[j]); - printf("\n"); + fprintf(out, "%s%g", j == 2 ? "" : " ", vertex[j]); + fprintf(out, "\n"); vertex += n; i++; @@ -128,5 +128,5 @@ fz_print_shade(fz_context *ctx, fz_shade *shade) triangle++; } - printf("}\n"); + fprintf(out, "}\n"); } diff --git a/fitz/res_store.c b/fitz/res_store.c index 1de4f240..8e5375d6 100644 --- a/fitz/res_store.c +++ b/fitz/res_store.c @@ -453,12 +453,12 @@ fz_drop_store_context(fz_context *ctx) } void -fz_print_store(fz_context *ctx) +fz_print_store(fz_context *ctx, FILE *out) { fz_item *item, *next; fz_store *store = ctx->store; - printf("-- resource store contents --\n"); + fprintf(out, "-- resource store contents --\n"); fz_lock(ctx, FZ_LOCK_ALLOC); for (item = store->head; item; item = next) @@ -466,10 +466,10 @@ fz_print_store(fz_context *ctx) next = item->next; if (next) next->val->refs++; - printf("store[*][refs=%d][size=%d] ", item->val->refs, item->size); + fprintf(out, "store[*][refs=%d][size=%d] ", item->val->refs, item->size); fz_unlock(ctx, FZ_LOCK_ALLOC); item->type->debug(item->key); - printf(" = %p\n", item->val); + fprintf(out, " = %p\n", item->val); fz_lock(ctx, FZ_LOCK_ALLOC); if (next) next->val->refs--; @@ -521,7 +521,7 @@ int fz_store_scavenge(fz_context *ctx, unsigned int size, int *phase) #ifdef DEBUG_SCAVENGING printf("Scavenging: store=%d size=%d phase=%d\n", store->size, size, *phase); - fz_print_store(ctx); + fz_print_store(ctx, stderr); Memento_stats(); #endif do @@ -549,7 +549,7 @@ int fz_store_scavenge(fz_context *ctx, unsigned int size, int *phase) { #ifdef DEBUG_SCAVENGING printf("scavenged: store=%d\n", store->size); - fz_print_store(ctx); + fz_print_store(ctx, stderr); Memento_stats(); #endif return 1; @@ -559,7 +559,7 @@ int fz_store_scavenge(fz_context *ctx, unsigned int size, int *phase) #ifdef DEBUG_SCAVENGING printf("scavenging failed\n"); - fz_print_store(ctx); + fz_print_store(ctx, stderr); Memento_listBlocks(); #endif return 0; diff --git a/fitz/res_text.c b/fitz/res_text.c index 43b4471a..643b4c9f 100644 --- a/fitz/res_text.c +++ b/fitz/res_text.c @@ -118,23 +118,30 @@ fz_add_text(fz_context *ctx, fz_text *text, int gid, int ucs, float x, float y) text->len++; } -static int isxmlmeta(int c) +static int +isxmlmeta(int c) { return c < 32 || c >= 128 || c == '&' || c == '<' || c == '>' || c == '\'' || c == '"'; } -void fz_print_text(fz_context *ctx, fz_text *text, int indent) +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++) - putchar(' '); + fputc(' ', out); if (!isxmlmeta(text->items[i].ucs)) - printf("\n", + fprintf(out, "\n", text->items[i].ucs, text->items[i].gid, text->items[i].x, text->items[i].y); else - printf("\n", + 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); +} -- cgit v1.2.3