diff options
Diffstat (limited to 'source/pdf')
-rw-r--r-- | source/pdf/pdf-appearance.c | 16 | ||||
-rw-r--r-- | source/pdf/pdf-font.c | 19 | ||||
-rw-r--r-- | source/pdf/pdf-image.c | 11 | ||||
-rw-r--r-- | source/pdf/pdf-op-buffer.c | 9 | ||||
-rw-r--r-- | source/pdf/pdf-pkcs7.c | 2 | ||||
-rw-r--r-- | source/pdf/pdf-stream.c | 2 | ||||
-rw-r--r-- | source/pdf/pdf-type3.c | 3 | ||||
-rw-r--r-- | source/pdf/pdf-write.c | 84 | ||||
-rw-r--r-- | source/pdf/pdf-xref.c | 2 |
9 files changed, 90 insertions, 58 deletions
diff --git a/source/pdf/pdf-appearance.c b/source/pdf/pdf-appearance.c index f94103a9..5627aaa4 100644 --- a/source/pdf/pdf-appearance.c +++ b/source/pdf/pdf-appearance.c @@ -397,7 +397,7 @@ typedef struct text_splitter_s float unscaled_width; float fontsize; float lineheight; - char *text; + const char *text; int done; float x_orig; float y_orig; @@ -409,7 +409,7 @@ typedef struct text_splitter_s int retry; } text_splitter; -static void text_splitter_init(text_splitter *splitter, font_info *info, char *text, float width, float height, int variable) +static void text_splitter_init(text_splitter *splitter, font_info *info, const char *text, float width, float height, int variable) { float fontsize = info->da_rec.font_size; @@ -442,7 +442,7 @@ static void text_splitter_start_line(text_splitter *splitter) static int text_splitter_layout(fz_context *ctx, text_splitter *splitter) { - char *text; + const char *text; float room; float stride; size_t count; @@ -1899,7 +1899,7 @@ void pdf_update_ink_appearance(fz_context *ctx, pdf_document *doc, pdf_annot *an } } -static void add_text(fz_context *ctx, font_info *font_rec, fz_text *text, char *str, size_t str_len, const fz_matrix *tm_) +static void add_text(fz_context *ctx, font_info *font_rec, fz_text *text, const char *str, size_t str_len, const fz_matrix *tm_) { fz_font *font = font_rec->font->font; fz_matrix tm = *tm_; @@ -1940,7 +1940,7 @@ static fz_text *layout_text(fz_context *ctx, font_info *font_rec, char *str, flo return text; } -static fz_text *fit_text(fz_context *ctx, font_info *font_rec, char *str, fz_rect *bounds) +static fz_text *fit_text(fz_context *ctx, font_info *font_rec, const char *str, fz_rect *bounds) { float width = bounds->x1 - bounds->x0; float height = bounds->y1 - bounds->y0; @@ -1989,7 +1989,7 @@ static fz_text *fit_text(fz_context *ctx, font_info *font_rec, char *str, fz_rec if (splitter.text[splitter.text_start] != ' ') { float dx, dy; - char *word = str+splitter.text_start; + const char *word = str+splitter.text_start; size_t wordlen = splitter.text_end-splitter.text_start; text_splitter_move(&splitter, -line, &dx, &dy); @@ -2374,7 +2374,6 @@ void pdf_set_signature_appearance(fz_context *ctx, pdf_document *doc, pdf_annot fz_rect annot_rect; fz_rect logo_bounds; fz_matrix logo_tm; - unsigned char *bufstr; fz_rect rect; pdf_to_rect(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_Rect), &annot_rect); @@ -2415,10 +2414,9 @@ void pdf_set_signature_appearance(fz_context *ctx, pdf_document *doc, pdf_annot fz_buffer_printf(ctx, fzbuf, "\nDN: %s", dn); if (date) fz_buffer_printf(ctx, fzbuf, "\nDate: %s", date); - (void)fz_buffer_storage(ctx, fzbuf, &bufstr); rect = annot_rect; rect.x0 = (rect.x0 + rect.x1)/2.0f; - text = fit_text(ctx, &font_rec, (char *)bufstr, &rect); + text = fit_text(ctx, &font_rec, fz_string_from_buffer(ctx, fzbuf), &rect); fz_fill_text(ctx, dev, text, &page_ctm, cs, font_rec.da_rec.col, 1.0f); fz_close_device(ctx, dev); diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c index 5b5c7735..a974c8d5 100644 --- a/source/pdf/pdf-font.c +++ b/source/pdf/pdf-font.c @@ -124,9 +124,11 @@ static const char *clean_font_name(const char *fontname) static int is_builtin_font(fz_context *ctx, fz_font *font) { int size; + unsigned char *data; if (!font->buffer) return 0; - return fz_lookup_base14_font(ctx, clean_font_name(font->name), &size) == (char*)font->buffer->data; + fz_buffer_storage(ctx, font->buffer, &data); + return fz_lookup_base14_font(ctx, clean_font_name(font->name), &size) == (char*)data; } /* @@ -448,7 +450,7 @@ pdf_load_embedded_font(fz_context *ctx, pdf_document *doc, pdf_font_desc *fontde fz_catch(ctx) fz_rethrow(ctx); - fontdesc->size += buf->len; + fontdesc->size += fz_buffer_storage(ctx, buf, NULL); fontdesc->is_embedded = 1; } @@ -1032,15 +1034,17 @@ load_cid_font(fz_context *ctx, pdf_document *doc, pdf_obj *dict, pdf_obj *encodi if (pdf_is_indirect(ctx, cidtogidmap)) { fz_buffer *buf; - size_t z; + size_t z, len; + unsigned char *data; buf = pdf_load_stream(ctx, cidtogidmap); - fontdesc->cid_to_gid_len = (buf->len) / 2; + len = fz_buffer_storage(ctx, buf, &data); + fontdesc->cid_to_gid_len = len / 2; fontdesc->cid_to_gid = fz_malloc_array(ctx, fontdesc->cid_to_gid_len, sizeof(unsigned short)); fontdesc->size += fontdesc->cid_to_gid_len * sizeof(unsigned short); for (z = 0; z < fontdesc->cid_to_gid_len; z++) - fontdesc->cid_to_gid[z] = (buf->data[z * 2] << 8) + buf->data[z * 2 + 1]; + fontdesc->cid_to_gid[z] = (data[z * 2] << 8) + data[z * 2 + 1]; fz_drop_buffer(ctx, buf); } @@ -1466,13 +1470,14 @@ pdf_add_font_file(fz_context *ctx, pdf_document *doc, fz_font *font) fz_try(ctx) { + size_t len = fz_buffer_storage(ctx, buf, NULL); obj = pdf_new_dict(ctx, doc, 3); - pdf_dict_put_drop(ctx, obj, PDF_NAME_Length1, pdf_new_int(ctx, doc, (int)buf->len)); + pdf_dict_put_drop(ctx, obj, PDF_NAME_Length1, pdf_new_int(ctx, doc, (int)len)); switch (ft_font_file_kind(font->ft_face)) { case 1: /* TODO: these may not be the correct values, but I doubt it matters */ - pdf_dict_put_drop(ctx, obj, PDF_NAME_Length2, pdf_new_int(ctx, doc, (int)buf->len)); + pdf_dict_put_drop(ctx, obj, PDF_NAME_Length2, pdf_new_int(ctx, doc, (int)len)); pdf_dict_put_drop(ctx, obj, PDF_NAME_Length3, pdf_new_int(ctx, doc, 0)); break; case 2: diff --git a/source/pdf/pdf-image.c b/source/pdf/pdf-image.c index 37e2ca50..b669948b 100644 --- a/source/pdf/pdf-image.c +++ b/source/pdf/pdf-image.c @@ -226,6 +226,9 @@ pdf_load_jpx(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int forcemask) /* FIXME: We can't handle decode arrays for indexed images currently */ fz_try(ctx) { + unsigned char *data; + size_t len; + obj = pdf_dict_get(ctx, dict, PDF_NAME_ColorSpace); if (obj) { @@ -233,7 +236,8 @@ pdf_load_jpx(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int forcemask) indexed = fz_colorspace_is_indexed(ctx, colorspace); } - pix = fz_load_jpx(ctx, buf->data, buf->len, colorspace, indexed); + len = fz_buffer_storage(ctx, buf, &data); + pix = fz_load_jpx(ctx, data, len, colorspace, indexed); obj = pdf_dict_geta(ctx, dict, PDF_NAME_SMask, PDF_NAME_Mask); if (pdf_is_dict(ctx, obj)) @@ -392,9 +396,8 @@ raw_or_unknown_compression: s = pixmap->samples; h = image->h; size = image->w * n; - buffer = fz_new_buffer(ctx, size * h); - buffer->len = size * h; - d = buffer->data; + d = fz_malloc(ctx, size * h); + buffer = fz_new_buffer_from_data(ctx, d, size * h); if (pixmap->alpha == 0 || n == 1) { while (h--) diff --git a/source/pdf/pdf-op-buffer.c b/source/pdf/pdf-op-buffer.c index 2eb4323a..1bfe982a 100644 --- a/source/pdf/pdf-op-buffer.c +++ b/source/pdf/pdf-op-buffer.c @@ -548,6 +548,8 @@ pdf_out_BI(fz_context *ctx, pdf_processor *proc, fz_image *img) fz_compressed_buffer *cbuf; fz_buffer *buf; int i; + unsigned char *data; + size_t len; if (img == NULL) return; @@ -662,12 +664,13 @@ pdf_out_BI(fz_context *ctx, pdf_processor *proc, fz_image *img) } fz_printf(ctx, out, "ID\n"); + len = fz_buffer_storage(ctx, buf, &data); if (ahx) { size_t z; - for (z = 0; z < buf->len; ++z) + for (z = 0; z < len; ++z) { - int c = buf->data[z]; + int c = data[z]; fz_putc(ctx, out, "0123456789abcdef"[(c >> 4) & 0xf]); fz_putc(ctx, out, "0123456789abcdef"[c & 0xf]); if ((z & 31) == 31) @@ -677,7 +680,7 @@ pdf_out_BI(fz_context *ctx, pdf_processor *proc, fz_image *img) } else { - fz_write(ctx, out, buf->data, buf->len); + fz_write(ctx, out, data, len); } fz_printf(ctx, out, "\nEI\n"); } diff --git a/source/pdf/pdf-pkcs7.c b/source/pdf/pdf-pkcs7.c index 934202e1..9fa15970 100644 --- a/source/pdf/pdf-pkcs7.c +++ b/source/pdf/pdf-pkcs7.c @@ -749,7 +749,7 @@ void pdf_sign_signature(fz_context *ctx, pdf_document *doc, pdf_widget *widget, if (dn->c) fz_buffer_printf(ctx, fzbuf, ", c=%s", dn->c); - (void)fz_buffer_storage(ctx, fzbuf, (unsigned char **) &dn_str); + dn_str = fz_string_from_buffer(ctx, fzbuf); pdf_set_signature_appearance(ctx, doc, (pdf_annot *)widget, dn->cn, dn_str, NULL); } } diff --git a/source/pdf/pdf-stream.c b/source/pdf/pdf-stream.c index b6645eca..289f27da 100644 --- a/source/pdf/pdf-stream.c +++ b/source/pdf/pdf-stream.c @@ -70,7 +70,7 @@ pdf_load_jbig2_globals(fz_context *ctx, pdf_document *doc, pdf_obj *dict) { buf = pdf_load_stream(ctx, dict); globals = fz_load_jbig2_globals(ctx, buf); - pdf_store_item(ctx, dict, globals, buf->len); + pdf_store_item(ctx, dict, globals, fz_buffer_storage(ctx, buf, NULL)); } fz_always(ctx) { diff --git a/source/pdf/pdf-type3.c b/source/pdf/pdf-type3.c index ede5a5ee..677a26e5 100644 --- a/source/pdf/pdf-type3.c +++ b/source/pdf/pdf-type3.c @@ -165,7 +165,8 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d if (pdf_is_stream(ctx, obj)) { font->t3procs[i] = pdf_load_stream(ctx, obj); - fontdesc->size += font->t3procs[i]->cap; + fz_trim_buffer(ctx, font->t3procs[i]); + fontdesc->size += fz_buffer_storage(ctx, font->t3procs[i], NULL); fontdesc->size += 0; // TODO: display list size calculation } } diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c index eb1a2f29..3401f59d 100644 --- a/source/pdf/pdf-write.c +++ b/source/pdf/pdf-write.c @@ -1517,11 +1517,13 @@ static inline int isbinary(int c) return c < 32 || c > 127; } -static int isbinarystream(fz_buffer *buf) +static int isbinarystream(fz_context *ctx, fz_buffer *buf) { + unsigned char *data; + size_t len = fz_buffer_storage(ctx, buf, &data); size_t i; - for (i = 0; i < buf->len; i++) - if (isbinary(buf->data[i])) + for (i = 0; i < len; i++) + if (isbinary(data[i])) return 1; return 0; } @@ -1529,25 +1531,25 @@ static int isbinarystream(fz_buffer *buf) static fz_buffer *hexbuf(fz_context *ctx, unsigned char *p, size_t n) { static const char hex[17] = "0123456789abcdef"; - fz_buffer *buf; int x = 0; - - buf = fz_new_buffer(ctx, n * 2 + (n / 32) + 2); + size_t len = n * 2 + (n / 32) + 2; + unsigned char *data = fz_malloc(ctx, len); + fz_buffer *buf = fz_new_buffer_from_data(ctx, data, len); while (n--) { - buf->data[buf->len++] = hex[*p >> 4]; - buf->data[buf->len++] = hex[*p & 15]; + *data++ = hex[*p >> 4]; + *data++ = hex[*p & 15]; if (++x == 32) { - buf->data[buf->len++] = '\n'; + *data++ = '\n'; x = 0; } p++; } - buf->data[buf->len++] = '>'; - buf->data[buf->len++] = '\n'; + *data++ = '>'; + *data++ = '\n'; return buf; } @@ -1609,19 +1611,23 @@ static fz_buffer *deflatebuf(fz_context *ctx, unsigned char *p, size_t n) uLongf csize; int t; uLong longN = (uLong)n; + unsigned char *data; + size_t cap; if (n != (size_t)longN) fz_throw(ctx, FZ_ERROR_GENERIC, "Buffer to large to deflate"); - buf = fz_new_buffer(ctx, compressBound(longN)); - csize = (uLongf)buf->cap; - t = compress(buf->data, &csize, p, longN); + cap = compressBound(longN); + data = fz_malloc(ctx, cap); + buf = fz_new_buffer_from_data(ctx, data, cap); + csize = (uLongf)cap; + t = compress(data, &csize, p, longN); if (t != Z_OK) { fz_drop_buffer(ctx, buf); fz_throw(ctx, FZ_ERROR_GENERIC, "cannot deflate buffer"); } - buf->len = csize; + fz_resize_buffer(ctx, buf, csize); return buf; } @@ -1630,45 +1636,53 @@ static void copystream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts fz_buffer *buf, *tmp; pdf_obj *newlen; pdf_obj *obj; + size_t len; + unsigned char *data; buf = pdf_load_raw_stream_number(ctx, doc, num); obj = pdf_copy_dict(ctx, obj_orig); + len = fz_buffer_storage(ctx, buf, &data); if (do_deflate && !pdf_dict_get(ctx, obj, PDF_NAME_Filter)) { - tmp = deflatebuf(ctx, buf->data, buf->len); - if (tmp->len >= buf->len) + size_t clen; + unsigned char *cdata; + tmp = deflatebuf(ctx, data, len); + clen = fz_buffer_storage(ctx, tmp, &cdata); + if (clen >= len) { /* Don't bother compressing, as we gain nothing. */ fz_drop_buffer(ctx, tmp); } else { + len = clen; + data = cdata; pdf_dict_put(ctx, obj, PDF_NAME_Filter, PDF_NAME_FlateDecode); fz_drop_buffer(ctx, buf); buf = tmp; } } - if (opts->do_ascii && isbinarystream(buf)) + if (opts->do_ascii && isbinarystream(ctx, buf)) { - tmp = hexbuf(ctx, buf->data, buf->len); + tmp = hexbuf(ctx, data, len); fz_drop_buffer(ctx, buf); buf = tmp; addhexfilter(ctx, doc, obj); } - newlen = pdf_new_int(ctx, doc, (int)buf->len); + newlen = pdf_new_int(ctx, doc, (int)len); pdf_dict_put(ctx, obj, PDF_NAME_Length, newlen); pdf_drop_obj(ctx, newlen); fz_printf(ctx, opts->out, "%d %d obj\n", num, gen); pdf_print_obj(ctx, opts->out, obj, opts->do_tight); fz_puts(ctx, opts->out, "\nstream\n"); - fz_write(ctx, opts->out, buf->data, buf->len); - if (buf->len > 0 && buf->data[buf->len-1] != '\n') + fz_write(ctx, opts->out, data, len); + if (len > 0 && data[len-1] != '\n') fz_putc(ctx, opts->out, '\n'); fz_puts(ctx, opts->out, "endstream\nendobj\n\n"); @@ -1682,6 +1696,8 @@ static void expandstream(fz_context *ctx, pdf_document *doc, pdf_write_state *op pdf_obj *newlen; pdf_obj *obj; int truncated = 0; + size_t len; + unsigned char *data; buf = pdf_load_stream_truncated(ctx, doc, num, (opts->continue_on_error ? &truncated : NULL)); if (truncated && opts->errors) @@ -1691,40 +1707,46 @@ static void expandstream(fz_context *ctx, pdf_document *doc, pdf_write_state *op pdf_dict_del(ctx, obj, PDF_NAME_Filter); pdf_dict_del(ctx, obj, PDF_NAME_DecodeParms); + len = fz_buffer_storage(ctx, buf, &data); if (do_deflate) { - tmp = deflatebuf(ctx, buf->data, buf->len); - if (tmp->len >= buf->len) + unsigned char *cdata; + size_t clen; + tmp = deflatebuf(ctx, data, len); + clen = fz_buffer_storage(ctx, tmp, &cdata); + if (clen >= len) { /* Don't bother compressing, as we gain nothing. */ fz_drop_buffer(ctx, tmp); } else { + len = clen; + data = cdata; pdf_dict_put(ctx, obj, PDF_NAME_Filter, PDF_NAME_FlateDecode); fz_drop_buffer(ctx, buf); buf = tmp; } } - if (opts->do_ascii && isbinarystream(buf)) + if (opts->do_ascii && isbinarystream(ctx, buf)) { - tmp = hexbuf(ctx, buf->data, buf->len); + tmp = hexbuf(ctx, data, len); fz_drop_buffer(ctx, buf); buf = tmp; addhexfilter(ctx, doc, obj); } - newlen = pdf_new_int(ctx, doc, (int)buf->len); + newlen = pdf_new_int(ctx, doc, (int)len); pdf_dict_put(ctx, obj, PDF_NAME_Length, newlen); pdf_drop_obj(ctx, newlen); fz_printf(ctx, opts->out, "%d %d obj\n", num, gen); pdf_print_obj(ctx, opts->out, obj, opts->do_tight); fz_puts(ctx, opts->out, "\nstream\n"); - fz_write(ctx, opts->out, buf->data, buf->len); - if (buf->len > 0 && buf->data[buf->len-1] != '\n') + fz_write(ctx, opts->out, data, len); + if (len > 0 && data[len-1] != '\n') fz_putc(ctx, opts->out, '\n'); fz_puts(ctx, opts->out, "endstream\nendobj\n\n"); @@ -2439,7 +2461,7 @@ make_page_offset_hints(fz_context *ctx, pdf_document *doc, pdf_write_state *opts /* Pad, and then do shared object hint table */ fz_write_buffer_pad(ctx, buf); - opts->hints_shared_offset = (int)buf->len; + opts->hints_shared_offset = (int)fz_buffer_storage(ctx, buf, NULL); /* Table F.5: */ /* Header Item 1: Object number of the first object in the shared @@ -2516,7 +2538,7 @@ make_hint_stream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts) { make_page_offset_hints(ctx, doc, opts, buf); pdf_update_stream(ctx, doc, pdf_load_object(ctx, doc, pdf_xref_len(ctx, doc)-1), buf, 0); - opts->hintstream_len = (int)buf->len; + opts->hintstream_len = (int)fz_buffer_storage(ctx, buf, NULL); fz_drop_buffer(ctx, buf); } fz_catch(ctx) diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c index 6280c2ff..df3c3254 100644 --- a/source/pdf/pdf-xref.c +++ b/source/pdf/pdf-xref.c @@ -2119,7 +2119,7 @@ pdf_update_stream(fz_context *ctx, pdf_document *doc, pdf_obj *obj, fz_buffer *n fz_drop_buffer(ctx, x->stm_buf); x->stm_buf = fz_keep_buffer(ctx, newbuf); - pdf_dict_puts_drop(ctx, obj, "Length", pdf_new_int(ctx, doc, (int)newbuf->len)); + pdf_dict_puts_drop(ctx, obj, "Length", pdf_new_int(ctx, doc, (int)fz_buffer_storage(ctx, newbuf, NULL))); if (!compressed) { pdf_dict_dels(ctx, obj, "Filter"); |