From cfb66cd25bbf31857b471735e5ff0f7c2aea4d3c Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 12 Mar 2017 11:19:09 -0500 Subject: Rename fz_putc/puts/printf to fz_write_*. Rename fz_write to fz_write_data. Rename fz_write_buffer_* and fz_buffer_printf to fz_append_*. Be consistent in naming: fz_write_* calls write to fz_output. fz_append_* calls append to fz_buffer. Update documentation. --- source/fitz/bitmap.c | 10 +- source/fitz/buffer.c | 67 +++++++----- source/fitz/draw-device.c | 2 +- source/fitz/font.c | 12 +-- source/fitz/hash.c | 10 +- source/fitz/image.c | 2 +- source/fitz/load-gif.c | 2 +- source/fitz/outline.c | 12 +-- source/fitz/output-pcl.c | 114 ++++++++++---------- source/fitz/output-png.c | 6 +- source/fitz/output-pnm.c | 44 ++++---- source/fitz/output-ps.c | 28 ++--- source/fitz/output-pwg.c | 30 +++--- source/fitz/output-tga.c | 44 ++++---- source/fitz/output.c | 10 +- source/fitz/path.c | 26 ++--- source/fitz/shade.c | 26 ++--- source/fitz/stext-output.c | 148 ++++++++++++------------- source/fitz/stext-search.c | 4 +- source/fitz/store.c | 12 +-- source/fitz/svg-device.c | 264 ++++++++++++++++++++++----------------------- source/fitz/trace-device.c | 158 +++++++++++++-------------- source/fitz/util.c | 6 +- source/fitz/zip.c | 44 ++++---- 24 files changed, 550 insertions(+), 531 deletions(-) (limited to 'source/fitz') diff --git a/source/fitz/bitmap.c b/source/fitz/bitmap.c index 2a7a9142..9db6a1df 100644 --- a/source/fitz/bitmap.c +++ b/source/fitz/bitmap.c @@ -310,7 +310,7 @@ pbm_write_header(fz_context *ctx, fz_band_writer *writer) int w = writer->w; int h = writer->h; - fz_printf(ctx, out, "P4\n%d %d\n", w, h); + fz_write_printf(ctx, out, "P4\n%d %d\n", w, h); } static void @@ -320,7 +320,7 @@ pkm_write_header(fz_context *ctx, fz_band_writer *writer) int w = writer->w; int h = writer->h; - fz_printf(ctx, out, "P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\nTUPLTYPE CMYK\nENDHDR\n", w, h); + fz_write_printf(ctx, out, "P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\nTUPLTYPE CMYK\nENDHDR\n", w, h); } void @@ -363,7 +363,7 @@ pbm_write_band(fz_context *ctx, fz_band_writer *writer, int stride, int band_sta bytestride = (w + 7) >> 3; while (end--) { - fz_write(ctx, out, p, bytestride); + fz_write_data(ctx, out, p, bytestride); p += stride; } } @@ -391,11 +391,11 @@ pkm_write_band(fz_context *ctx, fz_band_writer *writer, int stride, int band_sta int ww = w-1; while (ww > 0) { - fz_write(ctx, out, &pkm[8 * *p++], 8); + fz_write_data(ctx, out, &pkm[8 * *p++], 8); ww -= 2; } if (ww == 0) - fz_write(ctx, out, &pkm[8 * *p], 4); + fz_write_data(ctx, out, &pkm[8 * *p], 4); p += bytestride; } } diff --git a/source/fitz/buffer.c b/source/fitz/buffer.c index a2880659..ab814728 100644 --- a/source/fitz/buffer.c +++ b/source/fitz/buffer.c @@ -76,15 +76,15 @@ fz_new_buffer_from_base64(fz_context *ctx, const char *data, size_t size) { int c = *s++; if (c >= 'A' && c <= 'Z') - fz_write_buffer_bits(ctx, buf, c - 'A', 6); + fz_append_bits(ctx, buf, c - 'A', 6); else if (c >= 'a' && c <= 'z') - fz_write_buffer_bits(ctx, buf, c - 'a' + 26, 6); + fz_append_bits(ctx, buf, c - 'a' + 26, 6); else if (c >= '0' && c <= '9') - fz_write_buffer_bits(ctx, buf, c - '0' + 52, 6); + fz_append_bits(ctx, buf, c - '0' + 52, 6); else if (c == '+') - fz_write_buffer_bits(ctx, buf, 62, 6); + fz_append_bits(ctx, buf, 62, 6); else if (c == '/') - fz_write_buffer_bits(ctx, buf, 63, 6); + fz_append_bits(ctx, buf, 63, 6); } } fz_catch(ctx) @@ -205,7 +205,8 @@ fz_append_buffer(fz_context *ctx, fz_buffer *buf, fz_buffer *extra) buf->len += extra->len; } -void fz_write_buffer(fz_context *ctx, fz_buffer *buf, const void *data, size_t len) +void +fz_append_data(fz_context *ctx, fz_buffer *buf, const void *data, size_t len) { if (buf->len + len > buf->cap) fz_ensure_buffer(ctx, buf, buf->len + len); @@ -214,7 +215,19 @@ void fz_write_buffer(fz_context *ctx, fz_buffer *buf, const void *data, size_t l buf->unused_bits = 0; } -void fz_write_buffer_byte(fz_context *ctx, fz_buffer *buf, int val) +void +fz_append_string(fz_context *ctx, fz_buffer *buf, const char *data) +{ + size_t len = strlen(data); + if (buf->len + len > buf->cap) + fz_ensure_buffer(ctx, buf, buf->len + len); + memcpy(buf->data + buf->len, data, len); + buf->len += len; + buf->unused_bits = 0; +} + +void +fz_append_byte(fz_context *ctx, fz_buffer *buf, int val) { if (buf->len + 1 > buf->cap) fz_grow_buffer(ctx, buf); @@ -222,7 +235,8 @@ void fz_write_buffer_byte(fz_context *ctx, fz_buffer *buf, int val) buf->unused_bits = 0; } -void fz_write_buffer_rune(fz_context *ctx, fz_buffer *buf, int c) +void +fz_append_rune(fz_context *ctx, fz_buffer *buf, int c) { char data[10]; int len = fz_runetochar(data, c); @@ -233,21 +247,24 @@ void fz_write_buffer_rune(fz_context *ctx, fz_buffer *buf, int c) buf->unused_bits = 0; } -void fz_write_buffer_int32_le(fz_context *ctx, fz_buffer *buf, int x) +void +fz_append_int32_le(fz_context *ctx, fz_buffer *buf, int x) { - fz_write_buffer_byte(ctx, buf, (x)&0xFF); - fz_write_buffer_byte(ctx, buf, (x>>8)&0xFF); - fz_write_buffer_byte(ctx, buf, (x>>16)&0xFF); - fz_write_buffer_byte(ctx, buf, (x>>24)&0xFF); + fz_append_byte(ctx, buf, (x)&0xFF); + fz_append_byte(ctx, buf, (x>>8)&0xFF); + fz_append_byte(ctx, buf, (x>>16)&0xFF); + fz_append_byte(ctx, buf, (x>>24)&0xFF); } -void fz_write_buffer_int16_le(fz_context *ctx, fz_buffer *buf, int x) +void +fz_append_int16_le(fz_context *ctx, fz_buffer *buf, int x) { - fz_write_buffer_byte(ctx, buf, (x)&0xFF); - fz_write_buffer_byte(ctx, buf, (x>>8)&0xFF); + fz_append_byte(ctx, buf, (x)&0xFF); + fz_append_byte(ctx, buf, (x>>8)&0xFF); } -void fz_write_buffer_bits(fz_context *ctx, fz_buffer *buf, int val, int bits) +void +fz_append_bits(fz_context *ctx, fz_buffer *buf, int val, int bits) { int shift; @@ -308,24 +325,25 @@ void fz_write_buffer_bits(fz_context *ctx, fz_buffer *buf, int val, int bits) buf->unused_bits = bits; } -void fz_write_buffer_pad(fz_context *ctx, fz_buffer *buf) +void +fz_append_bits_pad(fz_context *ctx, fz_buffer *buf) { buf->unused_bits = 0; } size_t -fz_buffer_printf(fz_context *ctx, fz_buffer *buffer, const char *fmt, ...) +fz_append_printf(fz_context *ctx, fz_buffer *buffer, const char *fmt, ...) { size_t ret; va_list args; va_start(args, fmt); - ret = fz_buffer_vprintf(ctx, buffer, fmt, args); + ret = fz_append_vprintf(ctx, buffer, fmt, args); va_end(args); return ret; } size_t -fz_buffer_vprintf(fz_context *ctx, fz_buffer *buffer, const char *fmt, va_list old_args) +fz_append_vprintf(fz_context *ctx, fz_buffer *buffer, const char *fmt, va_list old_args) { size_t slack; size_t len; @@ -355,7 +373,7 @@ fz_buffer_vprintf(fz_context *ctx, fz_buffer *buffer, const char *fmt, va_list o } void -fz_buffer_print_pdf_string(fz_context *ctx, fz_buffer *buffer, const char *text) +fz_append_pdf_string(fz_context *ctx, fz_buffer *buffer, const char *text) { size_t len = 2; const char *s = text; @@ -430,7 +448,8 @@ fz_buffer_print_pdf_string(fz_context *ctx, fz_buffer *buffer, const char *text) buffer->len += len; } -void fz_md5_buffer(fz_context *ctx, fz_buffer *buffer, unsigned char digest[16]) +void +fz_md5_buffer(fz_context *ctx, fz_buffer *buffer, unsigned char digest[16]) { fz_md5 state; fz_md5_init(&state); @@ -469,7 +488,7 @@ fz_test_buffer_write(fz_context *ctx) k = (rand() & 31)+1; if (k > j) k = j; - fz_write_buffer_bits(ctx, copy, fz_read_bits(ctx, stm, k), k); + fz_append_bits(ctx, copy, fz_read_bits(ctx, stm, k), k); j -= k; } while (j); diff --git a/source/fitz/draw-device.c b/source/fitz/draw-device.c index 230e3a8e..9d7a19af 100644 --- a/source/fitz/draw-device.c +++ b/source/fitz/draw-device.c @@ -1950,7 +1950,7 @@ static void fz_print_tile(fz_context *ctx, fz_output *out, void *key_) { tile_key *key = (tile_key *)key_; - 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]); + fz_write_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]); } static fz_store_type fz_tile_store_type = diff --git a/source/fitz/font.c b/source/fitz/font.c index 31877d67..3927eb17 100644 --- a/source/fitz/font.c +++ b/source/fitz/font.c @@ -1356,27 +1356,27 @@ fz_render_t3_glyph_direct(fz_context *ctx, fz_device *dev, fz_font *font, int gi void fz_print_font(fz_context *ctx, fz_output *out, fz_font *font) { - fz_printf(ctx, out, "font '%s' {\n", font->name); + fz_write_printf(ctx, out, "font '%s' {\n", font->name); if (font->ft_face) { - fz_printf(ctx, out, "\tfreetype face %p\n", font->ft_face); + fz_write_printf(ctx, out, "\tfreetype face %p\n", font->ft_face); if (font->flags.ft_substitute) - fz_printf(ctx, out, "\tsubstitute font\n"); + fz_write_printf(ctx, out, "\tsubstitute font\n"); } if (font->t3procs) { - fz_printf(ctx, out, "\ttype3 matrix [%g %g %g %g]\n", + fz_write_printf(ctx, out, "\ttype3 matrix [%g %g %g %g]\n", font->t3matrix.a, font->t3matrix.b, font->t3matrix.c, font->t3matrix.d); - fz_printf(ctx, out, "\ttype3 bbox [%g %g %g %g]\n", + fz_write_printf(ctx, out, "\ttype3 bbox [%g %g %g %g]\n", font->bbox.x0, font->bbox.y0, font->bbox.x1, font->bbox.y1); } - fz_printf(ctx, out, "}\n"); + fz_write_printf(ctx, out, "}\n"); } fz_rect * diff --git a/source/fitz/hash.c b/source/fitz/hash.c index fe6ae6f8..9ebb0b31 100644 --- a/source/fitz/hash.c +++ b/source/fitz/hash.c @@ -290,21 +290,21 @@ fz_print_hash_details(fz_context *ctx, fz_output *out, fz_hash_table *table, voi { int i, k; - fz_printf(ctx, out, "cache load %d / %d\n", table->load, table->size); + fz_write_printf(ctx, out, "cache load %d / %d\n", table->load, table->size); for (i = 0; i < table->size; i++) { if (!table->ents[i].val && !compact) - fz_printf(ctx, out, "table %04d: empty\n", i); + fz_write_printf(ctx, out, "table %04d: empty\n", i); else if (table->ents[i].val) { - fz_printf(ctx, out, "table %04d: key=", i); + fz_write_printf(ctx, out, "table %04d: key=", i); for (k = 0; k < MAX_KEY_LEN; k++) - fz_printf(ctx, out, "%02x", ((unsigned char*)table->ents[i].key)[k]); + fz_write_printf(ctx, out, "%02x", ((unsigned char*)table->ents[i].key)[k]); if (details) details(ctx, out, table->ents[i].val); else - fz_printf(ctx, out, " val=$%p\n", table->ents[i].val); + fz_write_printf(ctx, out, " val=$%p\n", table->ents[i].val); } } } diff --git a/source/fitz/image.c b/source/fitz/image.c index 261c9f09..a1d392d9 100644 --- a/source/fitz/image.c +++ b/source/fitz/image.c @@ -85,7 +85,7 @@ static void fz_print_image_key(fz_context *ctx, fz_output *out, void *key_) { fz_image_key *key = (fz_image_key *)key_; - fz_printf(ctx, out, "(image %d x %d sf=%d) ", key->image->w, key->image->h, key->l2factor); + fz_write_printf(ctx, out, "(image %d x %d sf=%d) ", key->image->w, key->image->h, key->l2factor); } static int diff --git a/source/fitz/load-gif.c b/source/fitz/load-gif.c index 49e7cc06..c8835774 100644 --- a/source/fitz/load-gif.c +++ b/source/fitz/load-gif.c @@ -110,7 +110,7 @@ gif_read_subblocks(fz_context *ctx, struct info *info, unsigned char *p, unsigne if (end - p < len) fz_throw(ctx, FZ_ERROR_GENERIC, "premature end in data subblock in gif image"); if (buf) - fz_write_buffer(ctx, buf, p, len); + fz_append_data(ctx, buf, p, len); p += len; } } while (len > 0); diff --git a/source/fitz/outline.c b/source/fitz/outline.c index 888212bc..4948110c 100644 --- a/source/fitz/outline.c +++ b/source/fitz/outline.c @@ -33,16 +33,16 @@ fz_debug_outline_xml_imp(fz_context *ctx, fz_output *out, fz_outline *outline, i { while (outline) { - fz_printf(ctx, out, "title, outline->uri); + fz_write_printf(ctx, out, "title, outline->uri); if (outline->down) { - fz_printf(ctx, out, ">\n"); + fz_write_printf(ctx, out, ">\n"); fz_debug_outline_xml_imp(ctx, out, outline->down, level + 1); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } else { - fz_printf(ctx, out, " />\n"); + fz_write_printf(ctx, out, " />\n"); } outline = outline->next; } @@ -61,8 +61,8 @@ fz_print_outline_imp(fz_context *ctx, fz_output *out, fz_outline *outline, int l while (outline) { for (i = 0; i < level; i++) - fz_printf(ctx, out, "\t"); - fz_printf(ctx, out, "%s\t%s\n", outline->title, outline->uri); + fz_write_printf(ctx, out, "\t"); + fz_write_printf(ctx, out, "%s\t%s\n", outline->title, outline->uri); if (outline->down) fz_print_outline_imp(ctx, out, outline->down, level + 1); outline = outline->next; diff --git a/source/fitz/output-pcl.c b/source/fitz/output-pcl.c index 4bc36fd8..ab95f6aa 100644 --- a/source/fitz/output-pcl.c +++ b/source/fitz/output-pcl.c @@ -371,12 +371,12 @@ pcl_header(fz_context *ctx, fz_output *out, fz_pcl_options *pcl, int num_copies, if (pcl->page_count == 0) { if (pcl->features & HACK__IS_A_LJET4PJL) - fz_puts(ctx, out, "\033%-12345X@PJL\r\n@PJL ENTER LANGUAGE = PCL\r\n"); - fz_puts(ctx, out, "\033E"); /* reset printer */ + fz_write_string(ctx, out, "\033%-12345X@PJL\r\n@PJL ENTER LANGUAGE = PCL\r\n"); + fz_write_string(ctx, out, "\033E"); /* reset printer */ /* If the printer supports it, set orientation */ if (pcl->features & PCL_HAS_ORIENTATION) { - fz_printf(ctx, out, "\033&l%dO", pcl->orientation); + fz_write_printf(ctx, out, "\033&l%dO", pcl->orientation); } /* If the printer supports it, set the paper size */ /* based on the actual requested size. */ @@ -387,10 +387,10 @@ pcl_header(fz_context *ctx, fz_output *out, fz_pcl_options *pcl, int num_copies, int decipointw = (w * 720 + (xres>>1)) / xres; int decipointh = (h * 720 + (yres>>1)) / yres; - fz_printf(ctx, out, "\033&f%dI", decipointw); - fz_printf(ctx, out, "\033&f%dJ", decipointh); + fz_write_printf(ctx, out, "\033&f%dI", decipointw); + fz_write_printf(ctx, out, "\033&f%dJ", decipointh); } - fz_printf(ctx, out, "\033&l%dA", pcl->paper_size); + fz_write_printf(ctx, out, "\033&l%dA", pcl->paper_size); } /* If printer can duplex, set duplex mode appropriately. */ if (pcl->features & PCL_HAS_DUPLEX) @@ -400,17 +400,17 @@ pcl_header(fz_context *ctx, fz_output *out, fz_pcl_options *pcl, int num_copies, if (pcl->duplex) { if (!pcl->tumble) - fz_puts(ctx, out, "\033&l1S"); + fz_write_string(ctx, out, "\033&l1S"); else - fz_puts(ctx, out, "\033&l2S"); + fz_write_string(ctx, out, "\033&l2S"); } else - fz_puts(ctx, out, "\033&l0S"); + fz_write_string(ctx, out, "\033&l0S"); } else { /* default to duplex for this printer */ - fz_puts(ctx, out, "\033&l1S"); + fz_write_string(ctx, out, "\033&l1S"); } } } @@ -433,39 +433,39 @@ pcl_header(fz_context *ctx, fz_output *out, fz_pcl_options *pcl, int num_copies, { if (pcl->page_count != 0 && (pcl->features & PCL_CAN_SET_PAPER_SIZE)) { - fz_printf(ctx, out, "\033&l%dA", pcl->paper_size); + fz_write_printf(ctx, out, "\033&l%dA", pcl->paper_size); } - fz_puts(ctx, out, "\033&l0o0l0E"); - fz_puts(ctx, out, pcl->odd_page_init); + fz_write_string(ctx, out, "\033&l0o0l0E"); + fz_write_string(ctx, out, pcl->odd_page_init); } else - fz_puts(ctx, out, pcl->even_page_init); + fz_write_string(ctx, out, pcl->even_page_init); } else { if (pcl->features & PCL_CAN_SET_PAPER_SIZE) { - fz_printf(ctx, out, "\033&l%dA", pcl->paper_size); + fz_write_printf(ctx, out, "\033&l%dA", pcl->paper_size); } - fz_puts(ctx, out, "\033&l0o0l0E"); - fz_puts(ctx, out, pcl->odd_page_init); + fz_write_string(ctx, out, "\033&l0o0l0E"); + fz_write_string(ctx, out, pcl->odd_page_init); } - fz_printf(ctx, out, "\033&l%dX", num_copies); /* # of copies */ + fz_write_printf(ctx, out, "\033&l%dX", num_copies); /* # of copies */ /* End raster graphics, position cursor at top. */ - fz_puts(ctx, out, "\033*rB\033*p0x0Y"); + fz_write_string(ctx, out, "\033*rB\033*p0x0Y"); /* The DeskJet and DeskJet Plus reset everything upon */ /* receiving \033*rB, so we must reinitialize graphics mode. */ if (pcl->features & PCL_END_GRAPHICS_DOES_RESET) { - fz_puts(ctx, out, pcl->odd_page_init); /* Assume this does the right thing */ - fz_printf(ctx, out, "\033&l%dX", num_copies); /* # of copies */ + fz_write_string(ctx, out, pcl->odd_page_init); /* Assume this does the right thing */ + fz_write_printf(ctx, out, "\033&l%dX", num_copies); /* # of copies */ } /* Set resolution. */ - fz_printf(ctx, out, "\033*t%dR", xres); + fz_write_printf(ctx, out, "\033*t%dR", xres); pcl->page_count++; } @@ -736,10 +736,10 @@ color_pcl_write_header(fz_context *ctx, fz_band_writer *writer_) /* Raster presentation */ /* Print in orientation of the logical page */ - fz_printf(ctx, out, "\033&r0F"); + fz_write_printf(ctx, out, "\033&r0F"); /* Set color mode */ - fz_write(ctx, out, "\033*v6W" + fz_write_data(ctx, out, "\033*v6W" "\000" /* Colorspace 0 = Device RGB */ "\003" /* Pixel encoding mode: 3 = Direct by Pixel*/ "\000" /* Bits per index: 0 = no palette */ @@ -752,21 +752,21 @@ color_pcl_write_header(fz_context *ctx, fz_band_writer *writer_) /* Raster resolution */ /* Supposed to be strictly 75, 100, 150, 200, 300, 600 */ /* FIXME: xres vs yres */ - fz_printf(ctx, out, "\033*t%dR", xres); + fz_write_printf(ctx, out, "\033*t%dR", xres); /* Raster height */ - fz_printf(ctx, out, "\033*r%dT", h); + fz_write_printf(ctx, out, "\033*r%dT", h); /* Raster width */ - fz_printf(ctx, out, "\033*r%dS", w); + fz_write_printf(ctx, out, "\033*r%dS", w); /* start raster graphics */ /* 0 = start at default left graphics margin */ - fz_printf(ctx, out, "\033*r0A"); + fz_write_printf(ctx, out, "\033*r0A"); /* Now output the actual bitmap */ /* Adaptive Compression */ - fz_printf(ctx, out, "\033*b5M"); + fz_write_printf(ctx, out, "\033*b5M"); } static void @@ -816,8 +816,8 @@ color_pcl_write_band(fz_context *ctx, fz_band_writer *writer_, int stride, int b if (fill + 3 >= 32767) { /* Can't fit into the block, so flush */ - fz_printf(ctx, out, "\033*b%dW", fill); - fz_write(ctx, out, comp, fill); + fz_write_printf(ctx, out, "\033*b%dW", fill); + fz_write_data(ctx, out, comp, fill); fill = 0; } comp[fill++] = 4; /* Empty row */ @@ -860,8 +860,8 @@ color_pcl_write_band(fz_context *ctx, fz_band_writer *writer_, int stride, int b if (fill + len + 3 > 32767) { /* Can't fit this into the block, so flush and send uncompressed */ - fz_printf(ctx, out, "\033*b%dW", fill); - fz_write(ctx, out, comp, fill); + fz_write_printf(ctx, out, "\033*b%dW", fill); + fz_write_data(ctx, out, comp, fill); fill = 0; len = 0; } @@ -879,8 +879,8 @@ color_pcl_write_band(fz_context *ctx, fz_band_writer *writer_, int stride, int b if (fill + ds + 3 > 32767) { /* Can't fit a line uncompressed, so flush */ - fz_printf(ctx, out, "\033*b%dW", fill); - fz_write(ctx, out, comp, fill); + fz_write_printf(ctx, out, "\033*b%dW", fill); + fz_write_data(ctx, out, comp, fill); fill = 0; } @@ -916,12 +916,12 @@ color_pcl_write_trailer(fz_context *ctx, fz_band_writer *writer_) if (writer->fill) { - fz_printf(ctx, out, "\033*b%dW", writer->fill); - fz_write(ctx, out, writer->compbuf, writer->fill); + fz_write_printf(ctx, out, "\033*b%dW", writer->fill); + fz_write_data(ctx, out, writer->compbuf, writer->fill); } /* End Raster Graphics */ - fz_printf(ctx, out, "\033*rC"); + fz_write_printf(ctx, out, "\033*rC"); } static void @@ -1126,7 +1126,7 @@ mono_pcl_write_header(fz_context *ctx, fz_band_writer *writer_) if (writer->options.features & HACK__IS_A_OCE9050) { /* Enter HPGL/2 mode, begin plot, Initialise (start plot), Enter PCL mode */ - fz_puts(ctx, out, "\033%1BBPIN;\033%1A"); + fz_write_string(ctx, out, "\033%1BBPIN;\033%1A"); } pcl_header(ctx, out, &writer->options, 1, xres, yres, w, h); @@ -1188,23 +1188,23 @@ mono_pcl_write_band(fz_context *ctx, fz_band_writer *writer_, int ss, int band_s if (pcl->features & PCL_ANY_SPACING) { if (num_blank_lines > 0) - fz_printf(ctx, out, "\033*p+%dY", num_blank_lines); + fz_write_printf(ctx, out, "\033*p+%dY", num_blank_lines); /* Start raster graphics. */ - fz_puts(ctx, out, "\033*r1A"); + fz_write_string(ctx, out, "\033*r1A"); } else if (pcl->features & PCL_MODE_3_COMPRESSION) { /* Start raster graphics. */ - fz_puts(ctx, out, "\033*r1A"); + fz_write_string(ctx, out, "\033*r1A"); for (; num_blank_lines; num_blank_lines--) - fz_puts(ctx, out, "\033*b0W"); + fz_write_string(ctx, out, "\033*b0W"); } else { /* Start raster graphics. */ - fz_puts(ctx, out, "\033*r1A"); + fz_write_string(ctx, out, "\033*r1A"); for (; num_blank_lines; num_blank_lines--) - fz_puts(ctx, out, "\033*bW"); + fz_write_string(ctx, out, "\033*bW"); } } @@ -1226,30 +1226,30 @@ mono_pcl_write_band(fz_context *ctx, fz_band_writer *writer_, int ss, int band_s if (mode_3ns && compression != 2) { /* Switch to mode 2 */ - fz_puts(ctx, out, from3to2); + fz_write_string(ctx, out, from3to2); compression = 2; } if (pcl->features & PCL_MODE_3_COMPRESSION) { /* Must clear the seed row. */ - fz_puts(ctx, out, "\033*b1Y"); + fz_write_string(ctx, out, "\033*b1Y"); num_blank_lines--; } if (mode_3ns) { for (; num_blank_lines; num_blank_lines--) - fz_puts(ctx, out, "\033*b0W"); + fz_write_string(ctx, out, "\033*b0W"); } else { for (; num_blank_lines; num_blank_lines--) - fz_puts(ctx, out, "\033*bW"); + fz_write_string(ctx, out, "\033*bW"); } } else if (pcl->features & PCL3_SPACING) - fz_printf(ctx, out, "\033*p+%dY", num_blank_lines * yres); + fz_write_printf(ctx, out, "\033*p+%dY", num_blank_lines * yres); else - fz_printf(ctx, out, "\033*b%dY", num_blank_lines); + fz_write_printf(ctx, out, "\033*b%dY", num_blank_lines); /* Clear the seed row (only matters for mode 3 compression). */ memset(prev, 0, line_size); } @@ -1269,7 +1269,7 @@ mono_pcl_write_band(fz_context *ctx, fz_band_writer *writer_, int ss, int band_s if (count3 + penalty3 < count2 + penalty2) { if (compression != 3) - fz_puts(ctx, out, from2to3); + fz_write_string(ctx, out, from2to3); compression = 3; out_data = (unsigned char *)mode3buf; out_count = count3; @@ -1277,7 +1277,7 @@ mono_pcl_write_band(fz_context *ctx, fz_band_writer *writer_, int ss, int band_s else { if (compression != 2) - fz_puts(ctx, out, from3to2); + fz_write_string(ctx, out, from3to2); compression = 2; out_data = (unsigned char *)mode2buf; out_count = count2; @@ -1295,8 +1295,8 @@ mono_pcl_write_band(fz_context *ctx, fz_band_writer *writer_, int ss, int band_s } /* Transfer the data */ - fz_printf(ctx, out, "\033*b%dW", out_count); - fz_write(ctx, out, out_data, out_count); + fz_write_printf(ctx, out, "\033*b%dW", out_count); + fz_write_data(ctx, out, out_data, out_count); } writer->num_blank_lines = num_blank_lines; @@ -1309,12 +1309,12 @@ mono_pcl_write_trailer(fz_context *ctx, fz_band_writer *writer_) fz_output *out = writer->super.out; /* end raster graphics and eject page */ - fz_puts(ctx, out, "\033*rB\f"); + fz_write_string(ctx, out, "\033*rB\f"); if (writer->options.features & HACK__IS_A_OCE9050) { /* Pen up, pen select, advance full page, reset */ - fz_puts(ctx, out, "\033%1BPUSP0PG;\033E"); + fz_write_string(ctx, out, "\033%1BPUSP0PG;\033E"); } } diff --git a/source/fitz/output-png.c b/source/fitz/output-png.c index 62be417b..de5500c9 100644 --- a/source/fitz/output-png.c +++ b/source/fitz/output-png.c @@ -14,8 +14,8 @@ static void putchunk(fz_context *ctx, fz_output *out, char *tag, unsigned char * { unsigned int sum; fz_write_int32_be(ctx, out, size); - fz_write(ctx, out, tag, 4); - fz_write(ctx, out, data, size); + fz_write_data(ctx, out, tag, 4); + fz_write_data(ctx, out, data, size); sum = crc32(0, NULL, 0); sum = crc32(sum, (unsigned char*)tag, 4); sum = crc32(sum, data, size); @@ -114,7 +114,7 @@ png_write_header(fz_context *ctx, fz_band_writer *writer_) head[11] = 0; /* filter */ head[12] = 0; /* interlace */ - fz_write(ctx, out, pngsig, 8); + fz_write_data(ctx, out, pngsig, 8); putchunk(ctx, out, "IHDR", head, 13); } diff --git a/source/fitz/output-pnm.c b/source/fitz/output-pnm.c index 299c9e47..dbc521b7 100644 --- a/source/fitz/output-pnm.c +++ b/source/fitz/output-pnm.c @@ -17,11 +17,11 @@ pnm_write_header(fz_context *ctx, fz_band_writer *writer) fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap must be grayscale or rgb to write as pnm"); if (n == 1) - fz_printf(ctx, out, "P5\n"); + fz_write_printf(ctx, out, "P5\n"); if (n == 3) - fz_printf(ctx, out, "P6\n"); - fz_printf(ctx, out, "%d %d\n", w, h); - fz_printf(ctx, out, "255\n"); + fz_write_printf(ctx, out, "P6\n"); + fz_write_printf(ctx, out, "%d %d\n", w, h); + fz_write_printf(ctx, out, "255\n"); } static void @@ -61,7 +61,7 @@ pnm_write_band(fz_context *ctx, fz_band_writer *writer, int stride, int band_sta { case 1: /* No collation required */ - fz_write(ctx, out, p, num_written); + fz_write_data(ctx, out, p, num_written); p += num_written; break; case 2: @@ -77,11 +77,11 @@ pnm_write_band(fz_context *ctx, fz_band_writer *writer, int stride, int band_sta *o++ = *p; p += 2; } - fz_write(ctx, out, buffer, num_written); + fz_write_data(ctx, out, buffer, num_written); break; } case 3: - fz_write(ctx, out, p, num_written*3); + fz_write_data(ctx, out, p, num_written*3); p += num_written*3; break; case 4: @@ -99,7 +99,7 @@ pnm_write_band(fz_context *ctx, fz_band_writer *writer, int stride, int band_sta *o++ = p[2]; p += n; } - fz_write(ctx, out, buffer, num_written * 3); + fz_write_data(ctx, out, buffer, num_written * 3); break; } } @@ -164,22 +164,22 @@ pam_write_header(fz_context *ctx, fz_band_writer *writer) int n = writer->n; int alpha = writer->alpha; - fz_printf(ctx, out, "P7\n"); - fz_printf(ctx, out, "WIDTH %d\n", w); - fz_printf(ctx, out, "HEIGHT %d\n", h); - fz_printf(ctx, out, "DEPTH %d\n", n); - fz_printf(ctx, out, "MAXVAL 255\n"); + fz_write_printf(ctx, out, "P7\n"); + fz_write_printf(ctx, out, "WIDTH %d\n", w); + fz_write_printf(ctx, out, "HEIGHT %d\n", h); + fz_write_printf(ctx, out, "DEPTH %d\n", n); + fz_write_printf(ctx, out, "MAXVAL 255\n"); n -= alpha; - if (n == 0 && alpha) fz_printf(ctx, out, "TUPLTYPE GRAYSCALE\n"); - else if (n == 1 && !alpha) fz_printf(ctx, out, "TUPLTYPE GRAYSCALE\n"); - else if (n == 1 && alpha) fz_printf(ctx, out, "TUPLTYPE GRAYSCALE_ALPHA\n"); - else if (n == 3 && !alpha) fz_printf(ctx, out, "TUPLTYPE RGB\n"); - else if (n == 3 && alpha) fz_printf(ctx, out, "TUPLTYPE RGB_ALPHA\n"); - else if (n == 4 && !alpha) fz_printf(ctx, out, "TUPLTYPE CMYK\n"); - else if (n == 5) fz_printf(ctx, out, "TUPLTYPE CMYK_ALPHA\n"); - fz_printf(ctx, out, "ENDHDR\n"); + if (n == 0 && alpha) fz_write_printf(ctx, out, "TUPLTYPE GRAYSCALE\n"); + else if (n == 1 && !alpha) fz_write_printf(ctx, out, "TUPLTYPE GRAYSCALE\n"); + else if (n == 1 && alpha) fz_write_printf(ctx, out, "TUPLTYPE GRAYSCALE_ALPHA\n"); + else if (n == 3 && !alpha) fz_write_printf(ctx, out, "TUPLTYPE RGB\n"); + else if (n == 3 && alpha) fz_write_printf(ctx, out, "TUPLTYPE RGB_ALPHA\n"); + else if (n == 4 && !alpha) fz_write_printf(ctx, out, "TUPLTYPE CMYK\n"); + else if (n == 5) fz_write_printf(ctx, out, "TUPLTYPE CMYK_ALPHA\n"); + fz_write_printf(ctx, out, "ENDHDR\n"); } static void @@ -201,7 +201,7 @@ pam_write_band(fz_context *ctx, fz_band_writer *writer, int stride, int band_sta for (y = 0; y < end; y++) { - fz_write(ctx, out, sp, w * n); + fz_write_data(ctx, out, sp, w * n); sp += stride; } } diff --git a/source/fitz/output-ps.c b/source/fitz/output-ps.c index 915dc222..9b6aeb06 100644 --- a/source/fitz/output-ps.c +++ b/source/fitz/output-ps.c @@ -15,7 +15,7 @@ typedef struct ps_band_writer_s void fz_write_ps_file_header(fz_context *ctx, fz_output *out) { - fz_printf(ctx, out, + fz_write_printf(ctx, out, "%%!PS-Adobe-3.0\n" //"%%%%BoundingBox: 0 0 612 792\n" //"%%%%HiResBoundingBox: 0 0 612 792\n" @@ -37,7 +37,7 @@ fz_write_ps_file_header(fz_context *ctx, fz_output *out) void fz_write_ps_file_trailer(fz_context *ctx, fz_output *out, int pages) { - fz_printf(ctx, out, "%%%%Trailer\n%%%%Pages: %d\n%%%%EOF\n", pages); + fz_write_printf(ctx, out, "%%%%Trailer\n%%%%Pages: %d\n%%%%EOF\n", pages); } static void @@ -72,27 +72,27 @@ ps_write_header(fz_context *ctx, fz_band_writer *writer_) fz_throw(ctx, FZ_ERROR_GENERIC, "compression error %d", err); } - fz_printf(ctx, out, "%%%%Page: %d %d\n", pagenum, pagenum); - fz_printf(ctx, out, "%%%%PageBoundingBox: 0 0 %d %d\n", w_points, h_points); - fz_printf(ctx, out, "%%%%BeginPageSetup\n"); - fz_printf(ctx, out, "<> setpagedevice\n", w_points, h_points); - fz_printf(ctx, out, "%%%%EndPageSetup\n\n"); - fz_printf(ctx, out, "/DataFile currentfile /FlateDecode filter def\n\n"); + fz_write_printf(ctx, out, "%%%%Page: %d %d\n", pagenum, pagenum); + fz_write_printf(ctx, out, "%%%%PageBoundingBox: 0 0 %d %d\n", w_points, h_points); + fz_write_printf(ctx, out, "%%%%BeginPageSetup\n"); + fz_write_printf(ctx, out, "<> setpagedevice\n", w_points, h_points); + fz_write_printf(ctx, out, "%%%%EndPageSetup\n\n"); + fz_write_printf(ctx, out, "/DataFile currentfile /FlateDecode filter def\n\n"); switch(n) { case 1: - fz_printf(ctx, out, "/DeviceGray setcolorspace\n"); + fz_write_printf(ctx, out, "/DeviceGray setcolorspace\n"); break; case 3: - fz_printf(ctx, out, "/DeviceRGB setcolorspace\n"); + fz_write_printf(ctx, out, "/DeviceRGB setcolorspace\n"); break; case 4: - fz_printf(ctx, out, "/DeviceCMYK setcolorspace\n"); + fz_write_printf(ctx, out, "/DeviceCMYK setcolorspace\n"); break; default: fz_throw(ctx, FZ_ERROR_GENERIC, "Unexpected colorspace for ps output"); } - fz_printf(ctx, out, + fz_write_printf(ctx, out, "<<\n" "/ImageType 1\n" "/Width %d\n" @@ -125,7 +125,7 @@ ps_write_trailer(fz_context *ctx, fz_band_writer *writer_) fz_throw(ctx, FZ_ERROR_GENERIC, "compression error %d", err); fz_write(ctx, out, writer->output, writer->output_size - writer->stream.avail_out); - fz_printf(ctx, out, "\nshowpage\n%%%%PageTrailer\n%%%%EndPageTrailer\n\n"); + fz_write_printf(ctx, out, "\nshowpage\n%%%%PageTrailer\n%%%%EndPageTrailer\n\n"); } static void @@ -231,7 +231,7 @@ ps_write_band(fz_context *ctx, fz_band_writer *writer_, int stride, int band_sta if (err != Z_OK) fz_throw(ctx, FZ_ERROR_GENERIC, "compression error %d", err); - fz_write(ctx, out, writer->output, writer->output_size - writer->stream.avail_out); + fz_write_data(ctx, out, writer->output, writer->output_size - writer->stream.avail_out); } fz_band_writer *fz_new_ps_band_writer(fz_context *ctx, fz_output *out) diff --git a/source/fitz/output-pwg.c b/source/fitz/output-pwg.c index ea6e7add..9d31f2a5 100644 --- a/source/fitz/output-pwg.c +++ b/source/fitz/output-pwg.c @@ -11,7 +11,7 @@ fz_write_pwg_file_header(fz_context *ctx, fz_output *out) static const unsigned char pwgsig[4] = { 'R', 'a', 'S', '2' }; /* Sync word */ - fz_write(ctx, out, pwgsig, 4); + fz_write_data(ctx, out, pwgsig, 4); } static void @@ -22,10 +22,10 @@ pwg_page_header(fz_context *ctx, fz_output *out, const fz_pwg_options *pwg, int i; /* Page Header: */ - fz_write(ctx, out, pwg ? pwg->media_class : zero, 64); - fz_write(ctx, out, pwg ? pwg->media_color : zero, 64); - fz_write(ctx, out, pwg ? pwg->media_type : zero, 64); - fz_write(ctx, out, pwg ? pwg->output_type : zero, 64); + fz_write_data(ctx, out, pwg ? pwg->media_class : zero, 64); + fz_write_data(ctx, out, pwg ? pwg->media_color : zero, 64); + fz_write_data(ctx, out, pwg ? pwg->media_type : zero, 64); + fz_write_data(ctx, out, pwg ? pwg->output_type : zero, 64); fz_write_int32_be(ctx, out, pwg ? pwg->advance_distance : 0); fz_write_int32_be(ctx, out, pwg ? pwg->advance_media : 0); fz_write_int32_be(ctx, out, pwg ? pwg->collate : 0); @@ -36,14 +36,14 @@ pwg_page_header(fz_context *ctx, fz_output *out, const fz_pwg_options *pwg, /* CUPS format says that 284->300 are supposed to be the bbox of the * page in points. PWG says 'Reserved'. */ for (i=284; i < 300; i += 4) - fz_write(ctx, out, zero, 4); + fz_write_data(ctx, out, zero, 4); fz_write_int32_be(ctx, out, pwg ? pwg->insert_sheet : 0); fz_write_int32_be(ctx, out, pwg ? pwg->jog : 0); fz_write_int32_be(ctx, out, pwg ? pwg->leading_edge : 0); /* CUPS format says that 312->320 are supposed to be the margins of * the lower left hand edge of page in points. PWG says 'Reserved'. */ for (i=312; i < 320; i += 4) - fz_write(ctx, out, zero, 4); + fz_write_data(ctx, out, zero, 4); fz_write_int32_be(ctx, out, pwg ? pwg->manual_feed : 0); fz_write_int32_be(ctx, out, pwg ? pwg->media_position : 0); fz_write_int32_be(ctx, out, pwg ? pwg->media_weight : 0); @@ -78,7 +78,7 @@ pwg_page_header(fz_context *ctx, fz_output *out, const fz_pwg_options *pwg, fz_write_int32_be(ctx, out, pwg ? pwg->row_step : 0); fz_write_int32_be(ctx, out, bpp <= 8 ? 1 : (bpp>>8)); /* Num Colors */ for (i=424; i < 452; i += 4) - fz_write(ctx, out, zero, 4); + fz_write_data(ctx, out, zero, 4); fz_write_int32_be(ctx, out, 1); /* TotalPageCount */ fz_write_int32_be(ctx, out, 1); /* CrossFeedTransform */ fz_write_int32_be(ctx, out, 1); /* FeedTransform */ @@ -87,9 +87,9 @@ pwg_page_header(fz_context *ctx, fz_output *out, const fz_pwg_options *pwg, fz_write_int32_be(ctx, out, w); /* ImageBoxRight */ fz_write_int32_be(ctx, out, h); /* ImageBoxBottom */ for (i=480; i < 1668; i += 4) - fz_write(ctx, out, zero, 4); - fz_write(ctx, out, pwg ? pwg->rendering_intent : zero, 64); - fz_write(ctx, out, pwg ? pwg->page_size_name : zero, 64); + fz_write_data(ctx, out, zero, 4); + fz_write_data(ctx, out, pwg ? pwg->rendering_intent : zero, 64); + fz_write_data(ctx, out, pwg ? pwg->page_size_name : zero, 64); } void @@ -235,14 +235,14 @@ pwg_write_mono_band(fz_context *ctx, fz_band_writer *writer_, int stride, int ba break; } fz_write_byte(ctx, out, xrep-1); - fz_write(ctx, out, sp, 1); + fz_write_data(ctx, out, sp, 1); sp += xrep; x += xrep; } else { fz_write_byte(ctx, out, 257-d); - fz_write(ctx, out, sp, d); + fz_write_data(ctx, out, sp, d); sp += d; x += d; } @@ -338,7 +338,7 @@ pwg_write_band(fz_context *ctx, fz_band_writer *writer_, int stride, int band_st break; } fz_write_byte(ctx, out, xrep-1); - fz_write(ctx, out, sp, n); + fz_write_data(ctx, out, sp, n); sp += n*xrep; x += xrep; } @@ -348,7 +348,7 @@ pwg_write_band(fz_context *ctx, fz_band_writer *writer_, int stride, int band_st x += d; while (d > 0) { - fz_write(ctx, out, sp, n); + fz_write_data(ctx, out, sp, n); sp += n; d--; } diff --git a/source/fitz/output-tga.c b/source/fitz/output-tga.c index 0e3cf3c5..e6e9a4a5 100644 --- a/source/fitz/output-tga.c +++ b/source/fitz/output-tga.c @@ -15,35 +15,35 @@ static inline void tga_put_pixel(fz_context *ctx, fz_output *out, const unsigned { case 4: /* RGBA or BGRA */ if (!is_bgr) { - fz_putc(ctx, out, data[2]); - fz_putc(ctx, out, data[1]); - fz_putc(ctx, out, data[0]); + fz_write_byte(ctx, out, data[2]); + fz_write_byte(ctx, out, data[1]); + fz_write_byte(ctx, out, data[0]); } else { - fz_putc(ctx, out, data[0]); - fz_putc(ctx, out, data[1]); - fz_putc(ctx, out, data[2]); + fz_write_byte(ctx, out, data[0]); + fz_write_byte(ctx, out, data[1]); + fz_write_byte(ctx, out, data[2]); } - fz_putc(ctx, out, data[3]); + fz_write_byte(ctx, out, data[3]); break; case 3: /* RGB or BGR */ if (!is_bgr) { - fz_putc(ctx, out, data[2]); - fz_putc(ctx, out, data[1]); - fz_putc(ctx, out, data[0]); + fz_write_byte(ctx, out, data[2]); + fz_write_byte(ctx, out, data[1]); + fz_write_byte(ctx, out, data[0]); } else { - fz_putc(ctx, out, data[0]); - fz_putc(ctx, out, data[1]); - fz_putc(ctx, out, data[2]); + fz_write_byte(ctx, out, data[0]); + fz_write_byte(ctx, out, data[1]); + fz_write_byte(ctx, out, data[2]); } break; case 2: /* GA */ - fz_putc(ctx, out, data[0]); - fz_putc(ctx, out, data[0]); - fz_putc(ctx, out, data[0]); - fz_putc(ctx, out, data[1]); + fz_write_byte(ctx, out, data[0]); + fz_write_byte(ctx, out, data[0]); + fz_write_byte(ctx, out, data[0]); + fz_write_byte(ctx, out, data[1]); break; case 1: /* G */ - fz_putc(ctx, out, data[0]); + fz_write_byte(ctx, out, data[0]); break; } } @@ -97,7 +97,7 @@ tga_write_header(fz_context *ctx, fz_band_writer *writer_) head[16] = d * 8; /* BPP */ head[17] = alpha && n > 1 ? 8 : 0; /* Alpha bpp */ - fz_write(ctx, out, head, sizeof(head)); + fz_write_data(ctx, out, head, sizeof(head)); } static void @@ -121,7 +121,7 @@ tga_write_band(fz_context *ctx, fz_band_writer *writer_, int stride, int band_st for (; i + j < w && j < 128 && !memcmp(line + i * n, line + (i + j) * n, d); j++); if (j > 1) { - fz_putc(ctx, out, j - 1 + 128); + fz_write_byte(ctx, out, j - 1 + 128); tga_put_pixel(ctx, out, line + i * n, n, is_bgr); } else @@ -129,7 +129,7 @@ tga_write_band(fz_context *ctx, fz_band_writer *writer_, int stride, int band_st for (; i + j < w && j <= 128 && memcmp(line + (i + j - 1) * n, line + (i + j) * n, d) != 0; j++); if (i + j < w || j > 128) j--; - fz_putc(ctx, out, j - 1); + fz_write_byte(ctx, out, j - 1); for (; j > 0; j--, i++) tga_put_pixel(ctx, out, line + i * n, n, is_bgr); } @@ -142,7 +142,7 @@ tga_write_trailer(fz_context *ctx, fz_band_writer *writer) { fz_output *out = writer->out; - fz_write(ctx, out, "\0\0\0\0\0\0\0\0TRUEVISION-XFILE.\0", 26); + fz_write_data(ctx, out, "\0\0\0\0\0\0\0\0TRUEVISION-XFILE.\0", 26); } fz_band_writer *fz_new_tga_band_writer(fz_context *ctx, fz_output *out, int is_bgr) diff --git a/source/fitz/output.c b/source/fitz/output.c index 7ca6fa4e..bd4dba66 100644 --- a/source/fitz/output.c +++ b/source/fitz/output.c @@ -206,7 +206,7 @@ static void buffer_write(fz_context *ctx, void *opaque, const void *data, size_t len) { fz_buffer *buffer = opaque; - fz_write_buffer(ctx, buffer, data, len); + fz_append_data(ctx, buffer, data, len); } static void @@ -267,7 +267,7 @@ fz_tell_output(fz_context *ctx, fz_output *out) } void -fz_vprintf(fz_context *ctx, fz_output *out, const char *fmt, va_list old_args) +fz_write_vprintf(fz_context *ctx, fz_output *out, const char *fmt, va_list old_args) { char buffer[256], *p = buffer; size_t len; @@ -299,12 +299,12 @@ fz_vprintf(fz_context *ctx, fz_output *out, const char *fmt, va_list old_args) } void -fz_printf(fz_context *ctx, fz_output *out, const char *fmt, ...) +fz_write_printf(fz_context *ctx, fz_output *out, const char *fmt, ...) { va_list args; if (!out) return; va_start(args, fmt); - fz_vprintf(ctx, out, fmt, args); + fz_write_vprintf(ctx, out, fmt, args); va_end(args); } @@ -313,7 +313,7 @@ fz_save_buffer(fz_context *ctx, fz_buffer *buf, const char *filename) { fz_output *out = fz_new_output_with_path(ctx, filename, 0); fz_try(ctx) - fz_write(ctx, out, buf->data, buf->len); + fz_write_data(ctx, out, buf->data, buf->len); fz_always(ctx) fz_drop_output(ctx, out); fz_catch(ctx) diff --git a/source/fitz/path.c b/source/fitz/path.c index 8fef2a32..120d2e9e 100644 --- a/source/fitz/path.c +++ b/source/fitz/path.c @@ -1354,46 +1354,46 @@ fz_print_path(fz_context *ctx, fz_output *out, fz_path *path, int indent) uint8_t cmd = path->cmds[i++]; for (n = 0; n < indent; n++) - fz_putc(ctx, out, ' '); + fz_write_byte(ctx, out, ' '); switch (cmd) { case FZ_MOVETO: case FZ_MOVETOCLOSE: x = path->coords[k++]; y = path->coords[k++]; - fz_printf(ctx, out, "%g %g m%s\n", x, y, cmd == FZ_MOVETOCLOSE ? " z" : ""); + fz_write_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++]; - fz_printf(ctx, out, "%g %g l%s\n", x, y, cmd == FZ_LINETOCLOSE ? " z" : ""); + fz_write_printf(ctx, out, "%g %g l%s\n", x, y, cmd == FZ_LINETOCLOSE ? " z" : ""); break; case FZ_DEGENLINETO: case FZ_DEGENLINETOCLOSE: - fz_printf(ctx, out, "d%s\n", cmd == FZ_DEGENLINETOCLOSE ? " z" : ""); + fz_write_printf(ctx, out, "d%s\n", cmd == FZ_DEGENLINETOCLOSE ? " z" : ""); break; case FZ_HORIZTO: case FZ_HORIZTOCLOSE: x = path->coords[k++]; - fz_printf(ctx, out, "%g h%s\n", x, cmd == FZ_HORIZTOCLOSE ? " z" : ""); + fz_write_printf(ctx, out, "%g h%s\n", x, cmd == FZ_HORIZTOCLOSE ? " z" : ""); break; case FZ_VERTTOCLOSE: case FZ_VERTTO: y = path->coords[k++]; - fz_printf(ctx, out, "%g i%s\n", y, cmd == FZ_VERTTOCLOSE ? " z" : ""); + fz_write_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++]; - fz_printf(ctx, out, "%g %g ", x, y); + fz_write_printf(ctx, out, "%g %g ", x, y); x = path->coords[k++]; y = path->coords[k++]; - fz_printf(ctx, out, "%g %g ", x, y); + fz_write_printf(ctx, out, "%g %g ", x, y); x = path->coords[k++]; y = path->coords[k++]; - fz_printf(ctx, out, "%g %g c%s\n", x, y, cmd == FZ_CURVETOCLOSE ? " z" : ""); + fz_write_printf(ctx, out, "%g %g c%s\n", x, y, cmd == FZ_CURVETOCLOSE ? " z" : ""); break; case FZ_CURVETOVCLOSE: case FZ_CURVETOV: @@ -1401,18 +1401,18 @@ fz_print_path(fz_context *ctx, fz_output *out, fz_path *path, int indent) case FZ_CURVETOY: x = path->coords[k++]; y = path->coords[k++]; - fz_printf(ctx, out, "%g %g ", x, y); + fz_write_printf(ctx, out, "%g %g ", x, y); x = path->coords[k++]; y = path->coords[k++]; - 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" : ""); + fz_write_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++]; - fz_printf(ctx, out, "%g %g ", x, y); + fz_write_printf(ctx, out, "%g %g ", x, y); x = path->coords[k++]; y = path->coords[k++]; - fz_printf(ctx, out, "%g %g r\n", x, y); + fz_write_printf(ctx, out, "%g %g r\n", x, y); break; } } diff --git a/source/fitz/shade.c b/source/fitz/shade.c index 274d40f3..4e5b9a19 100644 --- a/source/fitz/shade.c +++ b/source/fitz/shade.c @@ -1090,39 +1090,39 @@ fz_print_shade(fz_context *ctx, fz_output *out, fz_shade *shade) { int i; - fz_printf(ctx, out, "shading {\n"); + fz_write_printf(ctx, out, "shading {\n"); switch (shade->type) { - 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; + case FZ_FUNCTION_BASED: fz_write_printf(ctx, out, "\ttype function_based\n"); break; + case FZ_LINEAR: fz_write_printf(ctx, out, "\ttype linear\n"); break; + case FZ_RADIAL: fz_write_printf(ctx, out, "\ttype radial\n"); break; + default: /* MESH */ fz_write_printf(ctx, out, "\ttype mesh\n"); break; } - fz_printf(ctx, out, "\tbbox [%g %g %g %g]\n", + fz_write_printf(ctx, out, "\tbbox [%g %g %g %g]\n", shade->bbox.x0, shade->bbox.y0, shade->bbox.x1, shade->bbox.y1); - fz_printf(ctx, out, "\tcolorspace %s\n", fz_colorspace_name(ctx, shade->colorspace)); + fz_write_printf(ctx, out, "\tcolorspace %s\n", fz_colorspace_name(ctx, shade->colorspace)); - fz_printf(ctx, out, "\tmatrix [%g %g %g %g %g %g]\n", + fz_write_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) { int n = fz_colorspace_n(ctx, shade->colorspace); - fz_printf(ctx, out, "\tbackground ["); + fz_write_printf(ctx, out, "\tbackground ["); for (i = 0; i < n; i++) - fz_printf(ctx, out, "%s%g", i == 0 ? "" : " ", shade->background[i]); - fz_printf(ctx, out, "]\n"); + fz_write_printf(ctx, out, "%s%g", i == 0 ? "" : " ", shade->background[i]); + fz_write_printf(ctx, out, "]\n"); } if (shade->use_function) { - fz_printf(ctx, out, "\tfunction\n"); + fz_write_printf(ctx, out, "\tfunction\n"); } - fz_printf(ctx, out, "}\n"); + fz_write_printf(ctx, out, "}\n"); } diff --git a/source/fitz/stext-output.c b/source/fitz/stext-output.c index 09b18db8..49ef2ea5 100644 --- a/source/fitz/stext-output.c +++ b/source/fitz/stext-output.c @@ -12,11 +12,11 @@ static void fz_print_style_begin(fz_context *ctx, fz_output *out, fz_stext_style *style) { int script = style->script; - fz_printf(ctx, out, "", style->id); + fz_write_printf(ctx, out, "", style->id); while (script-- > 0) - fz_printf(ctx, out, ""); + fz_write_printf(ctx, out, ""); while (++script < 0) - fz_printf(ctx, out, ""); + fz_write_printf(ctx, out, ""); } static void @@ -24,10 +24,10 @@ fz_print_style_end(fz_context *ctx, fz_output *out, fz_stext_style *style) { int script = style->script; while (script-- > 0) - fz_printf(ctx, out, ""); + fz_write_printf(ctx, out, ""); while (++script < 0) - fz_printf(ctx, out, ""); - fz_printf(ctx, out, ""); + fz_write_printf(ctx, out, ""); + fz_write_printf(ctx, out, ""); } static void @@ -36,13 +36,13 @@ fz_print_style(fz_context *ctx, fz_output *out, fz_stext_style *style) const char *name = fz_font_name(ctx, style->font); const char *s = strchr(name, '+'); s = s ? s + 1 : name; - fz_printf(ctx, out, "span.s%d{font-family:\"%s\";font-size:%gpt;", + fz_write_printf(ctx, out, "span.s%d{font-family:\"%s\";font-size:%gpt;", style->id, s, style->size); if (fz_font_is_italic(ctx, style->font)) - fz_printf(ctx, out, "font-style:italic;"); + fz_write_printf(ctx, out, "font-style:italic;"); if (fz_font_is_bold(ctx, style->font)) - fz_printf(ctx, out, "font-weight:bold;"); - fz_printf(ctx, out, "}\n"); + fz_write_printf(ctx, out, "font-weight:bold;"); + fz_write_printf(ctx, out, "}\n"); } void @@ -66,8 +66,8 @@ send_data_base64_stext(fz_context *ctx, fz_output *out, fz_buffer *buffer) int d = buffer->data[3*i+1]; int e = buffer->data[3*i+2]; if ((i & 15) == 0) - fz_printf(ctx, out, "\n"); - fz_printf(ctx, out, "%c%c%c%c", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)|(e>>6)], set[e & 63]); + fz_write_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "%c%c%c%c", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)|(e>>6)], set[e & 63]); } i *= 3; switch (buffer->len-i) @@ -76,13 +76,13 @@ send_data_base64_stext(fz_context *ctx, fz_output *out, fz_buffer *buffer) { int c = buffer->data[i]; int d = buffer->data[i+1]; - fz_printf(ctx, out, "%c%c%c=", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)]); + fz_write_printf(ctx, out, "%c%c%c=", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)]); break; } case 1: { int c = buffer->data[i]; - fz_printf(ctx, out, "%c%c==", set[c>>2], set[(c&3)<<4]); + fz_write_printf(ctx, out, "%c%c==", set[c>>2], set[(c&3)<<4]); break; } default: @@ -100,7 +100,7 @@ fz_print_stext_page_html(fz_context *ctx, fz_output *out, fz_stext_page *page) fz_stext_span *span; void *last_region = NULL; - fz_printf(ctx, out, "
\n"); + fz_write_printf(ctx, out, "
\n"); for (block_n = 0; block_n < page->len; block_n++) { @@ -109,7 +109,7 @@ fz_print_stext_page_html(fz_context *ctx, fz_output *out, fz_stext_page *page) case FZ_PAGE_BLOCK_TEXT: { fz_stext_block * block = page->blocks[block_n].u.text; - fz_printf(ctx, out, "

\n"); + fz_write_printf(ctx, out, "

\n"); for (line_n = 0; line_n < block->len; line_n++) { int lastcol=-1; @@ -119,16 +119,16 @@ fz_print_stext_page_html(fz_context *ctx, fz_output *out, fz_stext_page *page) if (line->region != last_region) { if (last_region) - fz_printf(ctx, out, "

"); - fz_printf(ctx, out, "
"); + fz_write_printf(ctx, out, "
"); + fz_write_printf(ctx, out, "
"); last_region = line->region; } - fz_printf(ctx, out, "
region) - fz_printf(ctx, out, " region=\"%x\"", line->region); + fz_write_printf(ctx, out, " region=\"%x\"", line->region); #endif - fz_printf(ctx, out, ">"); + fz_write_printf(ctx, out, ">"); for (span = line->first_span; span; span = span->next) { float size = fz_matrix_expansion(&span->transform); @@ -138,17 +138,17 @@ fz_print_stext_page_html(fz_context *ctx, fz_output *out, fz_stext_page *page) { if (lastcol >= 0) { - fz_printf(ctx, out, "
"); + fz_write_printf(ctx, out, "
"); } /* If we skipped any columns then output some spacer spans */ while (lastcol < span->column-1) { - fz_printf(ctx, out, "
"); + fz_write_printf(ctx, out, "
"); lastcol++; } lastcol++; /* Now output the span to contain this entire column */ - fz_printf(ctx, out, "
next; sn; sn = sn->next) @@ -156,26 +156,26 @@ fz_print_stext_page_html(fz_context *ctx, fz_output *out, fz_stext_page *page) if (sn->column != lastcol) break; } - fz_printf(ctx, out, "width:%g%%;align:%s", span->column_width, (span->align == 0 ? "left" : (span->align == 1 ? "center" : "right"))); + fz_write_printf(ctx, out, "width:%g%%;align:%s", span->column_width, (span->align == 0 ? "left" : (span->align == 1 ? "center" : "right"))); } if (span->indent > 1) - fz_printf(ctx, out, ";padding-left:1em;text-indent:-1em"); + fz_write_printf(ctx, out, ";padding-left:1em;text-indent:-1em"); if (span->indent < -1) - fz_printf(ctx, out, ";text-indent:1em"); - fz_printf(ctx, out, "\">"); + fz_write_printf(ctx, out, ";text-indent:1em"); + fz_write_printf(ctx, out, "\">"); } #ifdef DEBUG_INTERNALS - fz_printf(ctx, out, "column) - fz_printf(ctx, out, " col=\"%x\"", span->column); - fz_printf(ctx, out, ">"); + fz_write_printf(ctx, out, " col=\"%x\"", span->column); + fz_write_printf(ctx, out, ">"); #endif if (span->spacing >= 1) - fz_printf(ctx, out, " "); + fz_write_printf(ctx, out, " "); if (base_offset > SUBSCRIPT_OFFSET) - fz_printf(ctx, out, ""); + fz_write_printf(ctx, out, ""); else if (base_offset < SUPERSCRIPT_OFFSET) - fz_printf(ctx, out, ""); + fz_write_printf(ctx, out, ""); for (ch_n = 0; ch_n < span->len; ch_n++) { fz_stext_char *ch = &span->text[ch_n]; @@ -188,15 +188,15 @@ fz_print_stext_page_html(fz_context *ctx, fz_output *out, fz_stext_page *page) } if (ch->c == '<') - fz_printf(ctx, out, "<"); + fz_write_printf(ctx, out, "<"); else if (ch->c == '>') - fz_printf(ctx, out, ">"); + fz_write_printf(ctx, out, ">"); else if (ch->c == '&') - fz_printf(ctx, out, "&"); + fz_write_printf(ctx, out, "&"); else if (ch->c >= 32 && ch->c <= 127) - fz_printf(ctx, out, "%c", ch->c); + fz_write_printf(ctx, out, "%c", ch->c); else - fz_printf(ctx, out, "&#x%x;", ch->c); + fz_write_printf(ctx, out, "&#x%x;", ch->c); } if (style) { @@ -204,56 +204,56 @@ fz_print_stext_page_html(fz_context *ctx, fz_output *out, fz_stext_page *page) style = NULL; } if (base_offset > SUBSCRIPT_OFFSET) - fz_printf(ctx, out, ""); + fz_write_printf(ctx, out, ""); else if (base_offset < SUPERSCRIPT_OFFSET) - fz_printf(ctx, out, ""); + fz_write_printf(ctx, out, ""); #ifdef DEBUG_INTERNALS - fz_printf(ctx, out, ""); + fz_write_printf(ctx, out, ""); #endif } /* Close our floating span */ - fz_printf(ctx, out, "
"); + fz_write_printf(ctx, out, "
"); /* Close the line */ - fz_printf(ctx, out, "
"); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "
"); + fz_write_printf(ctx, out, "\n"); } /* Close the metaline */ - fz_printf(ctx, out, ""); + fz_write_printf(ctx, out, ""); last_region = NULL; - fz_printf(ctx, out, "

\n"); + fz_write_printf(ctx, out, "

\n"); break; } case FZ_PAGE_BLOCK_IMAGE: { fz_image_block *image = page->blocks[block_n].u.image; fz_compressed_buffer *buffer = fz_compressed_image_buffer(ctx, image->image); - fz_printf(ctx, out, "image->w, image->image->h); + fz_write_printf(ctx, out, "image->w, image->image->h); switch (buffer == NULL ? FZ_IMAGE_JPX : buffer->params.type) { case FZ_IMAGE_JPEG: - fz_printf(ctx, out, "image/jpeg;base64,"); + fz_write_printf(ctx, out, "image/jpeg;base64,"); send_data_base64_stext(ctx, out, buffer->buffer); break; case FZ_IMAGE_PNG: - fz_printf(ctx, out, "image/png;base64,"); + fz_write_printf(ctx, out, "image/png;base64,"); send_data_base64_stext(ctx, out, buffer->buffer); break; default: { fz_buffer *buf = fz_new_buffer_from_image_as_png(ctx, image->image); - fz_printf(ctx, out, "image/png;base64,"); + fz_write_printf(ctx, out, "image/png;base64,"); send_data_base64_stext(ctx, out, buf); fz_drop_buffer(ctx, buf); break; } } - fz_printf(ctx, out, "\">\n"); + fz_write_printf(ctx, out, "\">\n"); break; } } } - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } void @@ -261,7 +261,7 @@ fz_print_stext_page_xml(fz_context *ctx, fz_output *out, fz_stext_page *page) { int block_n; - fz_printf(ctx, out, "\n", + fz_write_printf(ctx, out, "\n", page->mediabox.x1 - page->mediabox.x0, page->mediabox.y1 - page->mediabox.y0); @@ -275,12 +275,12 @@ fz_print_stext_page_xml(fz_context *ctx, fz_output *out, fz_stext_page *page) fz_stext_line *line; const char *s; - fz_printf(ctx, out, "\n", + fz_write_printf(ctx, out, "\n", block->bbox.x0, block->bbox.y0, block->bbox.x1, block->bbox.y1); for (line = block->lines; line < block->lines + block->len; line++) { fz_stext_span *span; - fz_printf(ctx, out, "\n", + fz_write_printf(ctx, out, "\n", line->bbox.x0, line->bbox.y0, line->bbox.x1, line->bbox.y1); for (span = line->first_span; span; span = span->next) { @@ -294,44 +294,44 @@ fz_print_stext_page_xml(fz_context *ctx, fz_output *out, fz_stext_page *page) { if (style) { - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } style = ch->style; name = fz_font_name(ctx, style->font); s = strchr(name, '+'); s = s ? s + 1 : name; - fz_printf(ctx, out, "\n", + fz_write_printf(ctx, out, "\n", span->bbox.x0, span->bbox.y0, span->bbox.x1, span->bbox.y1, s, style->size); } { fz_rect rect; fz_stext_char_bbox(ctx, &rect, span, char_num); - fz_printf(ctx, out, "p.x, ch->p.y); } switch (ch->c) { - case '<': fz_printf(ctx, out, "<"); break; - case '>': fz_printf(ctx, out, ">"); break; - case '&': fz_printf(ctx, out, "&"); break; - case '"': fz_printf(ctx, out, """); break; - case '\'': fz_printf(ctx, out, "'"); break; + case '<': fz_write_printf(ctx, out, "<"); break; + case '>': fz_write_printf(ctx, out, ">"); break; + case '&': fz_write_printf(ctx, out, "&"); break; + case '"': fz_write_printf(ctx, out, """); break; + case '\'': fz_write_printf(ctx, out, "'"); break; default: if (ch->c >= 32 && ch->c <= 127) - fz_printf(ctx, out, "%c", ch->c); + fz_write_printf(ctx, out, "%c", ch->c); else - fz_printf(ctx, out, "&#x%x;", ch->c); + fz_write_printf(ctx, out, "&#x%x;", ch->c); break; } - fz_printf(ctx, out, "\"/>\n"); + fz_write_printf(ctx, out, "\"/>\n"); } if (style) - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); break; } case FZ_PAGE_BLOCK_IMAGE: @@ -340,7 +340,7 @@ fz_print_stext_page_xml(fz_context *ctx, fz_output *out, fz_stext_page *page) } } } - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } void @@ -369,12 +369,12 @@ fz_print_stext_page(fz_context *ctx, fz_output *out, fz_stext_page *page) { n = fz_runetochar(utf, ch->c); for (i = 0; i < n; i++) - fz_printf(ctx, out, "%c", utf[i]); + fz_write_printf(ctx, out, "%c", utf[i]); } } - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); break; } case FZ_PAGE_BLOCK_IMAGE: diff --git a/source/fitz/stext-search.c b/source/fitz/stext-search.c index 99584581..6a3ea526 100644 --- a/source/fitz/stext-search.c +++ b/source/fitz/stext-search.c @@ -255,7 +255,7 @@ fz_copy_selection(fz_context *ctx, fz_stext_page *page, fz_rect rect) { if (seen) { - fz_write_buffer_byte(ctx, buffer, '\n'); + fz_append_byte(ctx, buffer, '\n'); } seen = 0; @@ -268,7 +268,7 @@ fz_copy_selection(fz_context *ctx, fz_stext_page *page, fz_rect rect) c = 0xFFFD; if (hitbox.x1 >= x0 && hitbox.x0 <= x1 && hitbox.y1 >= y0 && hitbox.y0 <= y1) { - fz_write_buffer_rune(ctx, buffer, c); + fz_append_rune(ctx, buffer, c); seen = 1; } } diff --git a/source/fitz/store.c b/source/fitz/store.c index 620bf0ea..70f25029 100644 --- a/source/fitz/store.c +++ b/source/fitz/store.c @@ -677,7 +677,7 @@ static void print_item(fz_context *ctx, fz_output *out, void *item_) { fz_item *item = (fz_item *)item_; - fz_printf(ctx, out, " val=%p item=%p\n", item->val, item); + fz_write_printf(ctx, out, " val=%p item=%p\n", item->val, item); } void @@ -686,24 +686,24 @@ fz_print_store_locked(fz_context *ctx, fz_output *out) fz_item *item, *next; fz_store *store = ctx->store; - fz_printf(ctx, out, "-- resource store contents --\n"); + fz_write_printf(ctx, out, "-- resource store contents --\n"); for (item = store->head; item; item = next) { next = item->next; if (next) next->val->refs++; - fz_printf(ctx, out, "store[*][refs=%d][size=%d] ", item->val->refs, item->size); + fz_write_printf(ctx, out, "store[*][refs=%d][size=%d] ", item->val->refs, item->size); fz_unlock(ctx, FZ_LOCK_ALLOC); item->type->print(ctx, out, item->key); - fz_printf(ctx, out, " = %p\n", item->val); + fz_write_printf(ctx, out, " = %p\n", item->val); fz_lock(ctx, FZ_LOCK_ALLOC); if (next) next->val->refs--; } - fz_printf(ctx, out, "-- resource store hash contents --\n"); + fz_write_printf(ctx, out, "-- resource store hash contents --\n"); fz_print_hash_details(ctx, out, store->hash, print_item, 1); - fz_printf(ctx, out, "-- end --\n"); + fz_write_printf(ctx, out, "-- end --\n"); } void diff --git a/source/fitz/svg-device.c b/source/fitz/svg-device.c index eb056c13..e80682fd 100644 --- a/source/fitz/svg-device.c +++ b/source/fitz/svg-device.c @@ -94,7 +94,7 @@ end_def(fz_context *ctx, svg_device *sdev) sdev->out = sdev->out_store; if (sdev->def_count == 0 && sdev->defs_buffer != NULL) { - fz_write(ctx, sdev->out, sdev->defs_buffer->data, sdev->defs_buffer->len); + fz_write_data(ctx, sdev->out, sdev->defs_buffer->data, sdev->defs_buffer->len); sdev->defs_buffer->len = 0; } return sdev->out; @@ -107,7 +107,7 @@ svg_path_moveto(fz_context *ctx, void *arg, float x, float y) { fz_output *out = (fz_output *)arg; - fz_printf(ctx, out, "M %g %g ", x, y); + fz_write_printf(ctx, out, "M %g %g ", x, y); } static void @@ -115,7 +115,7 @@ svg_path_lineto(fz_context *ctx, void *arg, float x, float y) { fz_output *out = (fz_output *)arg; - fz_printf(ctx, out, "L %g %g ", x, y); + fz_write_printf(ctx, out, "L %g %g ", x, y); } static void @@ -123,7 +123,7 @@ svg_path_curveto(fz_context *ctx, void *arg, float x1, float y1, float x2, float { fz_output *out = (fz_output *)arg; - fz_printf(ctx, out, "C %g %g %g %g %g %g ", x1, y1, x2, y2, x3, y3); + fz_write_printf(ctx, out, "C %g %g %g %g %g %g ", x1, y1, x2, y2, x3, y3); } static void @@ -131,7 +131,7 @@ svg_path_close(fz_context *ctx, void *arg) { fz_output *out = (fz_output *)arg; - fz_printf(ctx, out, "Z "); + fz_write_printf(ctx, out, "Z "); } static const fz_path_walker svg_path_walker = @@ -145,9 +145,9 @@ static const fz_path_walker svg_path_walker = static void svg_dev_path(fz_context *ctx, svg_device *sdev, const fz_path *path) { - fz_printf(ctx, sdev->out, " d=\""); + fz_write_printf(ctx, sdev->out, " d=\""); fz_walk_path(ctx, path, &svg_path_walker, sdev->out); - fz_printf(ctx, sdev->out, "\""); + fz_write_printf(ctx, sdev->out, "\""); } static void @@ -157,7 +157,7 @@ svg_dev_ctm(fz_context *ctx, svg_device *sdev, const fz_matrix *ctm) if (ctm->a != 1.0 || ctm->b != 0 || ctm->c != 0 || ctm->d != 1.0 || ctm->e != 0 || ctm->f != 0) { - fz_printf(ctx, out, " transform=\"matrix(%g,%g,%g,%g,%g,%g)\"", + fz_write_printf(ctx, out, " transform=\"matrix(%g,%g,%g,%g,%g,%g)\"", ctm->a, ctm->b, ctm->c, ctm->d, ctm->e, ctm->f); } } @@ -175,23 +175,23 @@ svg_dev_stroke_state(fz_context *ctx, svg_device *sdev, const fz_stroke_state *s if (exp < 1) exp = 1; - fz_printf(ctx, out, " stroke-width=\"%g\"", exp); - fz_printf(ctx, out, " stroke-linecap=\"%s\"", + fz_write_printf(ctx, out, " stroke-width=\"%g\"", exp); + fz_write_printf(ctx, out, " stroke-linecap=\"%s\"", (stroke_state->start_cap == FZ_LINECAP_SQUARE ? "square" : (stroke_state->start_cap == FZ_LINECAP_ROUND ? "round" : "butt"))); if (stroke_state->dash_len != 0) { int i; - fz_printf(ctx, out, " stroke-dasharray="); + fz_write_printf(ctx, out, " stroke-dasharray="); for (i = 0; i < stroke_state->dash_len; i++) - fz_printf(ctx, out, "%c%g", (i == 0 ? '\"' : ','), stroke_state->dash_list[i]); - fz_printf(ctx, out, "\""); + fz_write_printf(ctx, out, "%c%g", (i == 0 ? '\"' : ','), stroke_state->dash_list[i]); + fz_write_printf(ctx, out, "\""); if (stroke_state->dash_phase != 0) - fz_printf(ctx, out, " stroke-dashoffset=\"%g\"", stroke_state->dash_phase); + fz_write_printf(ctx, out, " stroke-dashoffset=\"%g\"", stroke_state->dash_phase); } if (stroke_state->linejoin == FZ_LINEJOIN_MITER || stroke_state->linejoin == FZ_LINEJOIN_MITER_XPS) - fz_printf(ctx, out, " stroke-miterlimit=\"%g\"", stroke_state->miterlimit); - fz_printf(ctx, out, " stroke-linejoin=\"%s\"", + fz_write_printf(ctx, out, " stroke-miterlimit=\"%g\"", stroke_state->miterlimit); + fz_write_printf(ctx, out, " stroke-linejoin=\"%s\"", (stroke_state->linejoin == FZ_LINEJOIN_BEVEL ? "bevel" : (stroke_state->linejoin == FZ_LINEJOIN_ROUND ? "round" : "miter"))); } @@ -223,12 +223,12 @@ svg_dev_fill_color(fz_context *ctx, svg_device *sdev, fz_colorspace *colorspace, { int rgb = svg_hex_color(ctx, colorspace, color); if (rgb != 0) /* black is the default value */ - fz_printf(ctx, out, " fill=\"#%06x\"", rgb); + fz_write_printf(ctx, out, " fill=\"#%06x\"", rgb); } else - fz_printf(ctx, out, " fill=\"none\""); + fz_write_printf(ctx, out, " fill=\"none\""); if (alpha != 1) - fz_printf(ctx, out, " fill-opacity=\"%g\"", alpha); + fz_write_printf(ctx, out, " fill-opacity=\"%g\"", alpha); } static void @@ -236,11 +236,11 @@ svg_dev_stroke_color(fz_context *ctx, svg_device *sdev, fz_colorspace *colorspac { fz_output *out = sdev->out; if (colorspace) - fz_printf(ctx, out, " fill=\"none\" stroke=\"#%06x\"", svg_hex_color(ctx, colorspace, color)); + fz_write_printf(ctx, out, " fill=\"none\" stroke=\"#%06x\"", svg_hex_color(ctx, colorspace, color)); else - fz_printf(ctx, out, " fill=\"none\" stroke=\"none\""); + fz_write_printf(ctx, out, " fill=\"none\" stroke=\"none\""); if (alpha != 1) - fz_printf(ctx, out, " stroke-opacity=\"%g\"", alpha); + fz_write_printf(ctx, out, " stroke-opacity=\"%g\"", alpha); } static void @@ -322,7 +322,7 @@ svg_dev_text_span(fz_context *ctx, svg_device *sdev, const fz_matrix *ctm, const if (span->len == 0) { - fz_printf(ctx, out, "/>\n"); + fz_write_printf(ctx, out, "/>\n"); return; } @@ -344,15 +344,15 @@ svg_dev_text_span(fz_context *ctx, svg_device *sdev, const fz_matrix *ctm, const is_bold = fz_font_is_bold(ctx, span->font); is_italic = fz_font_is_italic(ctx, span->font); - fz_printf(ctx, out, " xml:space=\"preserve\""); - fz_printf(ctx, out, " transform=\"matrix(%M)\"", &final_tm); - fz_printf(ctx, out, " font-size=\"%g\"", font_size); - fz_printf(ctx, out, " font-family=\"%s\"", font_family); - if (is_bold) fz_printf(ctx, out, " font-weight=\"bold\""); - if (is_italic) fz_printf(ctx, out, " font-style=\"italic\""); - if (span->wmode != 0) fz_printf(ctx, out, " writing-mode=\"tb\""); + fz_write_printf(ctx, out, " xml:space=\"preserve\""); + fz_write_printf(ctx, out, " transform=\"matrix(%M)\"", &final_tm); + fz_write_printf(ctx, out, " font-size=\"%g\"", font_size); + fz_write_printf(ctx, out, " font-family=\"%s\"", font_family); + if (is_bold) fz_write_printf(ctx, out, " font-weight=\"bold\""); + if (is_italic) fz_write_printf(ctx, out, " font-style=\"italic\""); + if (span->wmode != 0) fz_write_printf(ctx, out, " writing-mode=\"tb\""); - fz_putc(ctx, out, '>'); + fz_write_byte(ctx, out, '>'); start = find_first_char(ctx, span, 0); while (start < span->len) @@ -365,9 +365,9 @@ svg_dev_text_span(fz_context *ctx, svg_device *sdev, const fz_matrix *ctm, const if (span->items[start].gid >= 0) cluster_advance = svg_cluster_advance(ctx, span, start, end); if (span->wmode == 0) - fz_printf(ctx, out, "items[i]; @@ -389,10 +389,10 @@ svg_dev_text_span(fz_context *ctx, svg_device *sdev, const fz_matrix *ctm, const else p.y += font_size * cluster_advance; } - fz_printf(ctx, out, " %g", span->wmode == 0 ? p.x : p.y); + fz_write_printf(ctx, out, " %g", span->wmode == 0 ? p.x : p.y); } } - fz_printf(ctx, out, "\">"); + fz_write_printf(ctx, out, "\">"); for (i = start; i < end; ++i) { it = &span->items[i]; @@ -400,17 +400,17 @@ svg_dev_text_span(fz_context *ctx, svg_device *sdev, const fz_matrix *ctm, const { int c = it->ucs; if (c >= 32 && c <= 127 && c != '<' && c != '&' && c != '>') - fz_putc(ctx, out, c); + fz_write_byte(ctx, out, c); else - fz_printf(ctx, out, "&#x%04x;", c); + fz_write_printf(ctx, out, "&#x%04x;", c); } } - fz_printf(ctx, out, ""); + fz_write_printf(ctx, out, ""); start = find_first_char(ctx, span, end); } - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } static font * @@ -476,10 +476,10 @@ svg_dev_text_span_as_paths_defs(fz_context *ctx, fz_device *dev, fz_text_span *s shift.f = -rect.y0; fz_transform_path(ctx, path, &shift); out = start_def(ctx, sdev); - fz_printf(ctx, out, "\n", fnt->id, gid); - fz_printf(ctx, out, "\n", fnt->id, gid); + fz_write_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "/>\n"); fz_drop_path(ctx, path); } else @@ -488,10 +488,10 @@ svg_dev_text_span_as_paths_defs(fz_context *ctx, fz_device *dev, fz_text_span *s shift.e = -rect.x0; shift.f = -rect.y0; out = start_def(ctx, sdev); - fz_printf(ctx, out, "\n", fnt->id, gid); + fz_write_printf(ctx, out, "\n", fnt->id, gid); fz_run_t3_glyph(ctx, span->font, gid, &shift, dev); } - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); out = end_def(ctx, sdev); fnt->sentlist[gid].x_off = rect.x0; fnt->sentlist[gid].y_off = rect.y0; @@ -533,10 +533,10 @@ svg_dev_text_span_as_paths_fill(fz_context *ctx, fz_device *dev, const fz_text_s local_trm.f = it->y; fz_concat(&local_trm2, &local_trm, ctm); fz_concat(&local_trm2, &shift, &local_trm2); - fz_printf(ctx, out, "id, gid); + fz_write_printf(ctx, out, "id, gid); svg_dev_ctm(ctx, sdev, &local_trm2); svg_dev_fill_color(ctx, sdev, colorspace, color, alpha); - fz_printf(ctx, out, "/>\n"); + fz_write_printf(ctx, out, "/>\n"); } } @@ -573,11 +573,11 @@ svg_dev_text_span_as_paths_stroke(fz_context *ctx, fz_device *dev, const fz_text local_trm.f = it->y; fz_concat(&local_trm2, &local_trm, ctm); fz_concat(&local_trm2, &shift, &local_trm2); - fz_printf(ctx, out, "id, gid); + fz_write_printf(ctx, out, "id, gid); svg_dev_stroke_state(ctx, sdev, stroke, &local_trm2); svg_dev_ctm(ctx, sdev, &local_trm2); svg_dev_stroke_color(ctx, sdev, colorspace, color, alpha); - fz_printf(ctx, out, "/>\n"); + fz_write_printf(ctx, out, "/>\n"); } } @@ -590,13 +590,13 @@ svg_dev_fill_path(fz_context *ctx, fz_device *dev, const fz_path *path, int even svg_device *sdev = (svg_device*)dev; fz_output *out = sdev->out; - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, " fill-rule=\"evenodd\""); + fz_write_printf(ctx, out, "/>\n"); } static void @@ -606,12 +606,12 @@ svg_dev_stroke_path(fz_context *ctx, fz_device *dev, const fz_path *path, const svg_device *sdev = (svg_device*)dev; fz_output *out = sdev->out; - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "/>\n"); } static void @@ -623,15 +623,15 @@ svg_dev_clip_path(fz_context *ctx, fz_device *dev, const fz_path *path, int even int num = sdev->id++; out = start_def(ctx, sdev); - fz_printf(ctx, out, "\n", num); - fz_printf(ctx, out, "\n", num); + fz_write_printf(ctx, out, "\n\n"); + fz_write_printf(ctx, out, " fill-rule=\"evenodd\""); + fz_write_printf(ctx, out, "/>\n\n"); out = end_def(ctx, sdev); - fz_printf(ctx, out, "\n", num); + fz_write_printf(ctx, out, "\n", num); } static void @@ -647,16 +647,16 @@ svg_dev_clip_stroke_path(fz_context *ctx, fz_device *dev, const fz_path *path, c fz_bound_path(ctx, path, stroke, ctm, &bounds); out = start_def(ctx, sdev); - fz_printf(ctx, out, "\n", + fz_write_printf(ctx, out, "\n", num, bounds.x0, bounds.y0, bounds.x1 - bounds.x0, bounds.y1 - bounds.y0); - fz_printf(ctx, out, "\n\n"); + fz_write_printf(ctx, out, "/>\n\n"); out = end_def(ctx, sdev); - fz_printf(ctx, out, "\n", num); + fz_write_printf(ctx, out, "\n", num); } static void @@ -672,7 +672,7 @@ svg_dev_fill_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz { for (span = text->head; span; span = span->next) { - fz_printf(ctx, out, "head; span; span = span->next) { - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, " maskUnits=\"userSpaceOnUse\" maskContentUnits=\"userSpaceOnUse\">\n"); if (sdev->text_as_text) { for (span = text->head; span; span = span->next) { - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); out = end_def(ctx, sdev); - fz_printf(ctx, out, "\n", num); + fz_write_printf(ctx, out, "\n", num); } static void @@ -770,14 +770,14 @@ svg_dev_clip_stroke_text(fz_context *ctx, fz_device *dev, const fz_text *text, c fz_bound_text(ctx, text, NULL, ctm, &bounds); out = start_def(ctx, sdev); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, " maskUnits=\"userSpaceOnUse\" maskContentUnits=\"userSpaceOnUse\">\n"); if (sdev->text_as_text) { for (span = text->head; span; span = span->next) { - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); out = end_def(ctx, sdev); - fz_printf(ctx, out, "\n", num); + fz_write_printf(ctx, out, "\n", num); } static void @@ -809,7 +809,7 @@ svg_dev_ignore_text(fz_context *ctx, fz_device *dev, const fz_text *text, const { for (span = text->head; span; span = span->next) { - fz_printf(ctx, out, "data[3*i+1]; int e = buffer->data[3*i+2]; if ((i & 15) == 0) - fz_printf(ctx, out, "\n"); - fz_printf(ctx, out, "%c%c%c%c", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)|(e>>6)], set[e & 63]); + fz_write_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "%c%c%c%c", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)|(e>>6)], set[e & 63]); } i *= 3; switch (buffer->len-i) @@ -839,13 +839,13 @@ send_data_base64(fz_context *ctx, fz_output *out, fz_buffer *buffer) { int c = buffer->data[i]; int d = buffer->data[i+1]; - fz_printf(ctx, out, "%c%c%c=", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)]); + fz_write_printf(ctx, out, "%c%c%c=", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)]); break; } case 1: { int c = buffer->data[i]; - fz_printf(ctx, out, "%c%c==", set[c>>2], set[(c&3)<<4]); + fz_write_printf(ctx, out, "%c%c==", set[c>>2], set[(c&3)<<4]); break; } default: @@ -874,7 +874,7 @@ svg_send_image(fz_context *ctx, svg_device *sdev, fz_image *img) break; if (i >= 0) { - fz_printf(ctx, out, "\n", + fz_write_printf(ctx, out, "\n", sdev->images[i].id, img->w, img->h); return; } @@ -891,23 +891,23 @@ svg_send_image(fz_context *ctx, svg_device *sdev, fz_image *img) id = sdev->id++; out = start_def(ctx, sdev); - fz_printf(ctx, out, "\n", id, img->w, img->h); + fz_write_printf(ctx, out, "\n", id, img->w, img->h); } - fz_printf(ctx, out, "w, img->h); + fz_write_printf(ctx, out, " width=\"%d\" height=\"%d\" xlink:href=\"data:", img->w, img->h); switch (buffer == NULL ? FZ_IMAGE_JPX : buffer->params.type) { case FZ_IMAGE_PNG: - fz_printf(ctx, out, "image/png;base64,"); + fz_write_printf(ctx, out, "image/png;base64,"); send_data_base64(ctx, out, buffer->buffer); break; case FZ_IMAGE_JPEG: /* SVG cannot cope with CMYK images */ if (img->colorspace != fz_device_cmyk(ctx)) { - fz_printf(ctx, out, "image/jpeg;base64,"); + fz_write_printf(ctx, out, "image/jpeg;base64,"); send_data_base64(ctx, out, buffer->buffer); break; } @@ -915,24 +915,24 @@ svg_send_image(fz_context *ctx, svg_device *sdev, fz_image *img) default: { fz_buffer *buf = fz_new_buffer_from_image_as_png(ctx, img); - fz_printf(ctx, out, "image/png;base64,"); + fz_write_printf(ctx, out, "image/png;base64,"); send_data_base64(ctx, out, buf); fz_drop_buffer(ctx, buf); break; } } - fz_printf(ctx, out, "\"/>\n"); + fz_write_printf(ctx, out, "\"/>\n"); if (sdev->reuse_images) { - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); out = end_def(ctx, sdev); sdev->images[sdev->num_images].id = id; sdev->images[sdev->num_images].image = fz_keep_image(ctx, img); sdev->num_images++; - fz_printf(ctx, out, "\n", + fz_write_printf(ctx, out, "\n", id, img->w, img->h); } } @@ -950,13 +950,13 @@ svg_dev_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_ma scale.d = 1.0f / image->h; fz_concat(&local_ctm, &scale, ctm); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, ">\n"); svg_send_image(ctx, sdev, image); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } static void @@ -985,12 +985,12 @@ svg_dev_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_ma fz_paint_shade(ctx, shade, ctm, pix, &bbox); buf = fz_new_buffer_from_pixmap_as_png(ctx, pix); if (alpha != 1.0f) - fz_printf(ctx, out, "\n", alpha); - fz_printf(ctx, out, "x, pix->y, pix->w, pix->h); + fz_write_printf(ctx, out, "\n", alpha); + fz_write_printf(ctx, out, "x, pix->y, pix->w, pix->h); send_data_base64(ctx, out, buf); - fz_printf(ctx, out, "\"/>\n"); + fz_write_printf(ctx, out, "\"/>\n"); if (alpha != 1.0f) - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } fz_always(ctx) { @@ -1018,14 +1018,14 @@ svg_dev_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_concat(&local_ctm, &scale, ctm); out = start_def(ctx, sdev); - fz_printf(ctx, out, "\n", mask); + fz_write_printf(ctx, out, "\n", mask); svg_send_image(ctx, sdev, image); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); out = end_def(ctx, sdev); - fz_printf(ctx, out, "w, image->h); + fz_write_printf(ctx, out, "w, image->h); svg_dev_fill_color(ctx, sdev, colorspace, color, alpha); svg_dev_ctm(ctx, sdev, &local_ctm); - fz_printf(ctx, out, " mask=\"url(#ma%d)\"/>\n", mask); + fz_write_printf(ctx, out, " mask=\"url(#ma%d)\"/>\n", mask); } static void @@ -1042,13 +1042,13 @@ svg_dev_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_concat(&local_ctm, &scale, ctm); out = start_def(ctx, sdev); - fz_printf(ctx, out, "\n\n\n"); + fz_write_printf(ctx, out, ">\n"); svg_send_image(ctx, sdev, image); - fz_printf(ctx, out, "\n\n"); + fz_write_printf(ctx, out, "\n\n"); out = end_def(ctx, sdev); - fz_printf(ctx, out, "\n", mask); + fz_write_printf(ctx, out, "\n", mask); } static void @@ -1058,7 +1058,7 @@ svg_dev_pop_clip(fz_context *ctx, fz_device *dev) fz_output *out = sdev->out; /* FIXME */ - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } static void @@ -1069,7 +1069,7 @@ svg_dev_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int lum int mask = sdev->id++; out = start_def(ctx, sdev); - fz_printf(ctx, out, "\n", mask); + fz_write_printf(ctx, out, "\n", mask); if (dev->container_len > 0) dev->container[dev->container_len-1].user = mask; @@ -1085,9 +1085,9 @@ svg_dev_end_mask(fz_context *ctx, fz_device *dev) if (dev->container_len > 0) mask = (int)dev->container[dev->container_len-1].user; - fz_printf(ctx, out, "\"/>\n\n"); + fz_write_printf(ctx, out, "\"/>\n\n"); out = end_def(ctx, sdev); - fz_printf(ctx, out, "\n", mask); + fz_write_printf(ctx, out, "\n", mask); } static void @@ -1098,9 +1098,9 @@ svg_dev_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int is /* SVG 1.1 doesn't support adequate blendmodes/knockout etc, so just ignore it for now */ if (alpha == 1) - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); else - fz_printf(ctx, out, "\n", alpha); + fz_write_printf(ctx, out, "\n", alpha); } static void @@ -1109,7 +1109,7 @@ svg_dev_end_group(fz_context *ctx, fz_device *dev) svg_device *sdev = (svg_device*)dev; fz_output *out = sdev->out; - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } static int @@ -1148,7 +1148,7 @@ svg_dev_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const f /* The first thing we do is to capture the contents of the pattern * as a symbol we can reuse. */ out = start_def(ctx, sdev); - fz_printf(ctx, out, "\n", t->pattern); + fz_write_printf(ctx, out, "\n", t->pattern); return 0; } @@ -1168,7 +1168,7 @@ svg_dev_end_tile(fz_context *ctx, fz_device *dev) num = --sdev->num_tiles; t = &sdev->tiles[num]; - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); /* In svg, the reference tile is taken from (x,y) to (x+width,y+height) * and is repeated at (x+n*width,y+m*height) for all integer n and m. @@ -1178,48 +1178,48 @@ svg_dev_end_tile(fz_context *ctx, fz_device *dev) * pattern tile, we need to render the pattern contents several times * to ensure that the pattern tile contains everything. */ - fz_printf(ctx, out, "pattern); - fz_printf(ctx, out, " x=\"0\" y=\"0\" width=\"%g\" height=\"%g\">\n", + fz_write_printf(ctx, out, " x=\"0\" y=\"0\" width=\"%g\" height=\"%g\">\n", t->step.x, t->step.y); if (t->view.x0 > 0 || t->step.x < t->view.x1 || t->view.y0 > 0 || t->step.y < t->view.y1) { cp = sdev->id++; - fz_printf(ctx, out, "\n", cp); - fz_printf(ctx, out, "\n", + fz_write_printf(ctx, out, "\n", cp); + fz_write_printf(ctx, out, "\n", t->view.x0, t->view.y0, t->view.x1, t->view.y0, t->view.x1, t->view.y1, t->view.x0, t->view.y1); - fz_printf(ctx, out, "\n"); - fz_printf(ctx, out, "\n", cp); + fz_write_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n", cp); } /* All the pattern contents will have their own ctm applied. Let's * undo the current one to allow for this */ fz_invert_matrix(&inverse, &t->ctm); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, ">\n"); w = t->view.x1 - t->view.x0; h = t->view.y1 - t->view.y0; for (x = 0; x > -w; x -= t->step.x) for (y = 0; y > -h; y -= t->step.y) - fz_printf(ctx, out, "\n", x, y, t->pattern); + fz_write_printf(ctx, out, "\n", x, y, t->pattern); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); if (cp != -1) - fz_printf(ctx, out, "\n"); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); out = end_def(ctx, sdev); /* Finally, fill a rectangle with the pattern. */ - fz_printf(ctx, out, "ctm); - fz_printf(ctx, out, " fill=\"url(#pa%d)\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"/>\n", + fz_write_printf(ctx, out, " fill=\"url(#pa%d)\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"/>\n", t->pattern, t->area.x0, t->area.y0, t->area.x1 - t->area.x0, t->area.y1 - t->area.y0); } @@ -1228,7 +1228,7 @@ svg_dev_close_device(fz_context *ctx, fz_device *dev) { svg_device *sdev = (svg_device*)dev; fz_output *out = sdev->out; - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } static void @@ -1294,9 +1294,9 @@ fz_device *fz_new_svg_device(fz_context *ctx, fz_output *out, float page_width, dev->text_as_text = (text_format == FZ_SVG_TEXT_AS_TEXT); dev->reuse_images = reuse_images; - fz_printf(ctx, out, "\n"); - fz_printf(ctx, out, "\n"); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n", page_width, page_height, page_width, page_height); diff --git a/source/fitz/trace-device.c b/source/fitz/trace-device.c index 881d7567..d306297f 100644 --- a/source/fitz/trace-device.c +++ b/source/fitz/trace-device.c @@ -9,7 +9,7 @@ typedef struct fz_trace_device_s static void fz_trace_matrix(fz_context *ctx, fz_output *out, const fz_matrix *ctm) { - fz_printf(ctx, out, " matrix=\"%g %g %g %g %g %g\"", + fz_write_printf(ctx, out, " matrix=\"%g %g %g %g %g %g\"", ctm->a, ctm->b, ctm->c, ctm->d, ctm->e, ctm->f); } @@ -20,13 +20,13 @@ fz_trace_color(fz_context *ctx, fz_output *out, fz_colorspace *colorspace, const if (colorspace) { n = fz_colorspace_n(ctx, colorspace); - fz_printf(ctx, out, " colorspace=\"%s\" color=\"", fz_colorspace_name(ctx, colorspace)); + fz_write_printf(ctx, out, " colorspace=\"%s\" color=\"", fz_colorspace_name(ctx, colorspace)); for (i = 0; i < n; i++) - fz_printf(ctx, out, "%s%g", i == 0 ? "" : " ", color[i]); - fz_printf(ctx, out, "\""); + fz_write_printf(ctx, out, "%s%g", i == 0 ? "" : " ", color[i]); + fz_write_printf(ctx, out, "\""); } if (alpha < 1) - fz_printf(ctx, out, " alpha=\"%g\"", alpha); + fz_write_printf(ctx, out, " alpha=\"%g\"", alpha); } static int @@ -39,30 +39,30 @@ static void fz_trace_text_span(fz_context *ctx, fz_output *out, fz_text_span *span) { int i; - fz_printf(ctx, out, "font), span->wmode); - fz_printf(ctx, out, " trm=\"%g %g %g %g\">\n", span->trm.a, span->trm.b, span->trm.c, span->trm.d); + fz_write_printf(ctx, out, "font), span->wmode); + fz_write_printf(ctx, out, " trm=\"%g %g %g %g\">\n", span->trm.a, span->trm.b, span->trm.c, span->trm.d); for (i = 0; i < span->len; i++) { char name[32]; if (span->items[i].ucs == -1) - fz_printf(ctx, out, "items[i].ucs)) - fz_printf(ctx, out, "items[i].ucs); + fz_write_printf(ctx, out, "items[i].ucs); else - fz_printf(ctx, out, "items[i].ucs); + fz_write_printf(ctx, out, "items[i].ucs); if (span->items[i].gid >= 0) { fz_get_glyph_name(ctx, span->font, span->items[i].gid, name, sizeof name); - fz_printf(ctx, out, " glyph=\"%s\"", name); + fz_write_printf(ctx, out, " glyph=\"%s\"", name); } else - fz_printf(ctx, out, " glyph=\"-1\""); + fz_write_printf(ctx, out, " glyph=\"-1\""); - fz_printf(ctx, out, " x=\"%g\" y=\"%g\" />\n", span->items[i].x, span->items[i].y); + fz_write_printf(ctx, out, " x=\"%g\" y=\"%g\" />\n", span->items[i].x, span->items[i].y); } - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } static void @@ -77,28 +77,28 @@ static void trace_moveto(fz_context *ctx, void *arg, float x, float y) { fz_output *out = arg; - fz_printf(ctx, out, "\n", x, y); + fz_write_printf(ctx, out, "\n", x, y); } static void trace_lineto(fz_context *ctx, void *arg, float x, float y) { fz_output *out = arg; - fz_printf(ctx, out, "\n", x, y); + fz_write_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) { fz_output *out = arg; - fz_printf(ctx, out, "\n", x1, y1, x2, y2, x3, y3); + fz_write_printf(ctx, out, "\n", x1, y1, x2, y2, x3, y3); } static void trace_close(fz_context *ctx, void *arg) { fz_output *out = arg; - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } static const fz_path_walker trace_path_walker = @@ -120,16 +120,16 @@ fz_trace_fill_path(fz_context *ctx, fz_device *dev, const fz_path *path, int eve fz_colorspace *colorspace, const float *color, float alpha) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, ">\n"); fz_trace_path(ctx, out, path); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } static void @@ -139,53 +139,53 @@ fz_trace_stroke_path(fz_context *ctx, fz_device *dev, const fz_path *path, const fz_output *out = ((fz_trace_device*)dev)->out; int i; - 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); + fz_write_printf(ctx, out, "linewidth); + fz_write_printf(ctx, out, " miterlimit=\"%g\"", stroke->miterlimit); + fz_write_printf(ctx, out, " linecap=\"%d,%d,%d\"", stroke->start_cap, stroke->dash_cap, stroke->end_cap); + fz_write_printf(ctx, out, " linejoin=\"%d\"", stroke->linejoin); if (stroke->dash_len) { - fz_printf(ctx, out, " dash_phase=\"%g\" dash=\"", stroke->dash_phase); + fz_write_printf(ctx, out, " dash_phase=\"%g\" dash=\"", stroke->dash_phase); for (i = 0; i < stroke->dash_len; i++) - fz_printf(ctx, out, "%s%g", i > 0 ? " " : "", stroke->dash_list[i]); - fz_printf(ctx, out, "\""); + fz_write_printf(ctx, out, "%s%g", i > 0 ? " " : "", stroke->dash_list[i]); + fz_write_printf(ctx, out, "\""); } fz_trace_color(ctx, out, colorspace, color, alpha); fz_trace_matrix(ctx, out, ctm); - fz_printf(ctx, out, ">\n"); + fz_write_printf(ctx, out, ">\n"); fz_trace_path(ctx, out, path); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } static void fz_trace_clip_path(fz_context *ctx, fz_device *dev, const fz_path *path, int even_odd, const fz_matrix *ctm, const fz_rect *scissor) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, ">\n"); fz_trace_path(ctx, out, path); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } static void fz_trace_clip_stroke_path(fz_context *ctx, fz_device *dev, const fz_path *path, const fz_stroke_state *stroke, const fz_matrix *ctm, const fz_rect *scissor) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, ">\n"); fz_trace_path(ctx, out, path); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } static void @@ -193,12 +193,12 @@ fz_trace_fill_text(fz_context *ctx, fz_device *dev, const fz_text *text, const f fz_colorspace *colorspace, const float *color, float alpha) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, ">\n"); fz_trace_text(ctx, out, text); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } static void @@ -206,64 +206,64 @@ fz_trace_stroke_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz_colorspace *colorspace, const float *color, float alpha) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, ">\n"); fz_trace_text(ctx, out, text); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } static void fz_trace_clip_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz_matrix *ctm, const fz_rect *scissor) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, ">\n"); fz_trace_text(ctx, out, text); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } static void fz_trace_clip_stroke_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz_stroke_state *stroke, const fz_matrix *ctm, const fz_rect *scissor) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, ">\n"); fz_trace_text(ctx, out, text); - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } static void fz_trace_ignore_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz_matrix *ctm) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, ">\n"); fz_trace_text(ctx, out, text); - fz_printf(ctx, out, "\n"); + fz_write_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) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "w, image->h); - fz_printf(ctx, out, "/>\n"); + fz_write_printf(ctx, out, " width=\"%d\" height=\"%d\"", image->w, image->h); + fz_write_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) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "/>\n"); } static void @@ -271,52 +271,52 @@ fz_trace_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_colorspace *colorspace, const float *color, float alpha) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "w, image->h); - fz_printf(ctx, out, "/>\n"); + fz_write_printf(ctx, out, " width=\"%d\" height=\"%d\"", image->w, image->h); + fz_write_printf(ctx, out, "/>\n"); } static void fz_trace_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, const fz_rect *scissor) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "w, image->h); - fz_printf(ctx, out, "/>\n"); + fz_write_printf(ctx, out, " width=\"%d\" height=\"%d\"", image->w, image->h); + fz_write_printf(ctx, out, "/>\n"); } static void fz_trace_pop_clip(fz_context *ctx, fz_device *dev) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "\n"); + fz_write_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, const float *color) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "x0, bbox->y0, bbox->x1, bbox->y1, luminosity ? "luminosity" : "alpha"); - fz_printf(ctx, out, ">\n"); + fz_write_printf(ctx, out, ">\n"); } static void fz_trace_end_mask(fz_context *ctx, fz_device *dev) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "\n"); + fz_write_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) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "\n", + fz_write_printf(ctx, out, "\n", bbox->x0, bbox->y0, bbox->x1, bbox->y1, isolated, knockout, fz_blendmode_name(blendmode), alpha); } @@ -325,19 +325,19 @@ static void fz_trace_end_group(fz_context *ctx, fz_device *dev) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "\n"); + fz_write_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) { 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_write_printf(ctx, out, "x0, area->y0, area->x1, area->y1); + fz_write_printf(ctx, out, " view=\"%g %g %g %g\"", view->x0, view->y0, view->x1, view->y1); + fz_write_printf(ctx, out, " xstep=\"%g\" ystep=\"%g\"", xstep, ystep); fz_trace_matrix(ctx, out, ctm); - fz_printf(ctx, out, ">\n"); + fz_write_printf(ctx, out, ">\n"); return 0; } @@ -345,7 +345,7 @@ static void fz_trace_end_tile(fz_context *ctx, fz_device *dev) { fz_output *out = ((fz_trace_device*)dev)->out; - fz_printf(ctx, out, "\n"); + fz_write_printf(ctx, out, "\n"); } fz_device *fz_new_trace_device(fz_context *ctx, fz_output *out) diff --git a/source/fitz/util.c b/source/fitz/util.c index 8d32346e..346ebaeb 100644 --- a/source/fitz/util.c +++ b/source/fitz/util.c @@ -464,11 +464,11 @@ fz_new_buffer_from_stext_page(fz_context *ctx, fz_stext_page *text, const fz_rec if (need_newline) { if (crlf) - fz_write_buffer_rune(ctx, buf, '\r'); - fz_write_buffer_rune(ctx, buf, '\n'); + fz_append_byte(ctx, buf, '\r'); + fz_append_byte(ctx, buf, '\n'); need_newline = 0; } - fz_write_buffer_rune(ctx, buf, c); + fz_append_rune(ctx, buf, c); } } } diff --git a/source/fitz/zip.c b/source/fitz/zip.c index cb51fd6d..6b7dca34 100644 --- a/source/fitz/zip.c +++ b/source/fitz/zip.c @@ -27,24 +27,24 @@ fz_write_zip_entry(fz_context *ctx, fz_zip_writer *zip, const char *name, fz_buf sum = crc32(0, NULL, 0); sum = crc32(sum, buf->data, (uInt)buf->len); - fz_write_buffer_int32_le(ctx, zip->central, ZIP_CENTRAL_DIRECTORY_SIG); - fz_write_buffer_int16_le(ctx, zip->central, 0); /* version made by: MS-DOS */ - fz_write_buffer_int16_le(ctx, zip->central, 20); /* version to extract: 2.0 */ - fz_write_buffer_int16_le(ctx, zip->central, 0); /* general purpose bit flag */ - fz_write_buffer_int16_le(ctx, zip->central, 0); /* compression method: store */ - fz_write_buffer_int16_le(ctx, zip->central, 0); /* TODO: last mod file time */ - fz_write_buffer_int16_le(ctx, zip->central, 0); /* TODO: last mod file date */ - fz_write_buffer_int32_le(ctx, zip->central, sum); /* crc-32 */ - fz_write_buffer_int32_le(ctx, zip->central, (int)buf->len); /* csize */ - fz_write_buffer_int32_le(ctx, zip->central, (int)buf->len); /* usize */ - fz_write_buffer_int16_le(ctx, zip->central, (int)strlen(name)); /* file name length */ - fz_write_buffer_int16_le(ctx, zip->central, 0); /* extra field length */ - fz_write_buffer_int16_le(ctx, zip->central, 0); /* file comment length */ - fz_write_buffer_int16_le(ctx, zip->central, 0); /* disk number start */ - fz_write_buffer_int16_le(ctx, zip->central, 0); /* internal file attributes */ - fz_write_buffer_int32_le(ctx, zip->central, 0); /* external file attributes */ - fz_write_buffer_int32_le(ctx, zip->central, offset); /* relative offset of local header */ - fz_write_buffer(ctx, zip->central, name, strlen(name)); + fz_append_int32_le(ctx, zip->central, ZIP_CENTRAL_DIRECTORY_SIG); + fz_append_int16_le(ctx, zip->central, 0); /* version made by: MS-DOS */ + fz_append_int16_le(ctx, zip->central, 20); /* version to extract: 2.0 */ + fz_append_int16_le(ctx, zip->central, 0); /* general purpose bit flag */ + fz_append_int16_le(ctx, zip->central, 0); /* compression method: store */ + fz_append_int16_le(ctx, zip->central, 0); /* TODO: last mod file time */ + fz_append_int16_le(ctx, zip->central, 0); /* TODO: last mod file date */ + fz_append_int32_le(ctx, zip->central, sum); /* crc-32 */ + fz_append_int32_le(ctx, zip->central, (int)buf->len); /* csize */ + fz_append_int32_le(ctx, zip->central, (int)buf->len); /* usize */ + fz_append_int16_le(ctx, zip->central, (int)strlen(name)); /* file name length */ + fz_append_int16_le(ctx, zip->central, 0); /* extra field length */ + fz_append_int16_le(ctx, zip->central, 0); /* file comment length */ + fz_append_int16_le(ctx, zip->central, 0); /* disk number start */ + fz_append_int16_le(ctx, zip->central, 0); /* internal file attributes */ + fz_append_int32_le(ctx, zip->central, 0); /* external file attributes */ + fz_append_int32_le(ctx, zip->central, offset); /* relative offset of local header */ + fz_append_string(ctx, zip->central, name); fz_write_int32_le(ctx, zip->output, ZIP_LOCAL_FILE_SIG); fz_write_int16_le(ctx, zip->output, 20); /* version to extract: 2.0 */ @@ -57,8 +57,8 @@ fz_write_zip_entry(fz_context *ctx, fz_zip_writer *zip, const char *name, fz_buf fz_write_int32_le(ctx, zip->output, (int)buf->len); /* usize */ fz_write_int16_le(ctx, zip->output, (int)strlen(name)); /* file name length */ fz_write_int16_le(ctx, zip->output, 0); /* extra field length */ - fz_write(ctx, zip->output, name, strlen(name)); - fz_write(ctx, zip->output, buf->data, buf->len); + fz_write_data(ctx, zip->output, name, strlen(name)); + fz_write_data(ctx, zip->output, buf->data, buf->len); ++zip->count; } @@ -68,7 +68,7 @@ fz_close_zip_writer(fz_context *ctx, fz_zip_writer *zip) { fz_off_t offset = fz_tell_output(ctx, zip->output); - fz_write(ctx, zip->output, zip->central->data, zip->central->len); + fz_write_data(ctx, zip->output, zip->central->data, zip->central->len); fz_write_int32_le(ctx, zip->output, ZIP_END_OF_CENTRAL_DIRECTORY_SIG); fz_write_int16_le(ctx, zip->output, 0); /* number of this disk */ @@ -79,7 +79,7 @@ fz_close_zip_writer(fz_context *ctx, fz_zip_writer *zip) fz_write_int32_le(ctx, zip->output, (int)offset); /* offset of the central directory */ fz_write_int16_le(ctx, zip->output, 5); /* zip file comment length */ - fz_write(ctx, zip->output, "MuPDF", 5); + fz_write_data(ctx, zip->output, "MuPDF", 5); zip->closed = 1; } -- cgit v1.2.3