summaryrefslogtreecommitdiff
path: root/source/pdf
diff options
context:
space:
mode:
Diffstat (limited to 'source/pdf')
-rw-r--r--source/pdf/pdf-appearance.c4
-rw-r--r--source/pdf/pdf-cmap-load.c2
-rw-r--r--source/pdf/pdf-colorspace.c2
-rw-r--r--source/pdf/pdf-field.c2
-rw-r--r--source/pdf/pdf-font.c4
-rw-r--r--source/pdf/pdf-function.c12
-rw-r--r--source/pdf/pdf-graft.c2
-rw-r--r--source/pdf/pdf-image.c2
-rw-r--r--source/pdf/pdf-parse.c2
-rw-r--r--source/pdf/pdf-repair.c2
-rw-r--r--source/pdf/pdf-stream.c42
-rw-r--r--source/pdf/pdf-type3.c2
-rw-r--r--source/pdf/pdf-write.c6
-rw-r--r--source/pdf/pdf-xref.c4
14 files changed, 58 insertions, 30 deletions
diff --git a/source/pdf/pdf-appearance.c b/source/pdf/pdf-appearance.c
index ed8a6f4a..dadb04ce 100644
--- a/source/pdf/pdf-appearance.c
+++ b/source/pdf/pdf-appearance.c
@@ -778,7 +778,7 @@ static int get_matrix(fz_context *ctx, pdf_document *doc, pdf_xobject *form, int
pdf_lexbuf lbuf;
fz_stream *str;
- str = pdf_open_stream(ctx, doc, pdf_to_num(ctx, form->obj));
+ str = pdf_open_stream(ctx, form->obj);
pdf_lexbuf_init(ctx, &lbuf, PDF_LEXBUF_SMALL);
@@ -1041,7 +1041,7 @@ static void update_marked_content(fz_context *ctx, pdf_document *doc, pdf_xobjec
int first = 1;
newbuf = fz_new_buffer(ctx, 0);
- str_outer = pdf_open_stream(ctx, doc, pdf_to_num(ctx, form->obj));
+ str_outer = pdf_open_stream(ctx, form->obj);
len = fz_buffer_storage(ctx, fzbuf, &buf);
str_inner = fz_open_memory(ctx, buf, len);
diff --git a/source/pdf/pdf-cmap-load.c b/source/pdf/pdf-cmap-load.c
index 58b3dae6..1cfe9dec 100644
--- a/source/pdf/pdf-cmap-load.c
+++ b/source/pdf/pdf-cmap-load.c
@@ -37,7 +37,7 @@ pdf_load_embedded_cmap(fz_context *ctx, pdf_document *doc, pdf_obj *stmobj)
fz_try(ctx)
{
- file = pdf_open_stream(ctx, doc, pdf_to_num(ctx, stmobj));
+ file = pdf_open_stream(ctx, stmobj);
cmap = pdf_load_cmap(ctx, file);
obj = pdf_dict_get(ctx, stmobj, PDF_NAME_WMode);
diff --git a/source/pdf/pdf-colorspace.c b/source/pdf/pdf-colorspace.c
index 081ceaaf..56dfcf5d 100644
--- a/source/pdf/pdf-colorspace.c
+++ b/source/pdf/pdf-colorspace.c
@@ -168,7 +168,7 @@ load_indexed(fz_context *ctx, pdf_document *doc, pdf_obj *array)
fz_try(ctx)
{
- file = pdf_open_stream(ctx, doc, pdf_to_num(ctx, lookupobj));
+ file = pdf_open_stream(ctx, lookupobj);
i = (int)fz_read(ctx, file, lookup, n);
if (i < n)
memset(lookup+i, 0, n-i);
diff --git a/source/pdf/pdf-field.c b/source/pdf/pdf-field.c
index 53853ced..00f4205a 100644
--- a/source/pdf/pdf-field.c
+++ b/source/pdf/pdf-field.c
@@ -33,7 +33,7 @@ char *pdf_get_string_or_stream(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
}
else if (pdf_is_stream(ctx, obj))
{
- stmbuf = pdf_load_stream(ctx, doc, pdf_to_num(ctx, obj));
+ stmbuf = pdf_load_stream(ctx, obj);
len = fz_buffer_storage(ctx, stmbuf, (unsigned char **)&buf);
}
diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c
index a0bdc5f9..5af16f13 100644
--- a/source/pdf/pdf-font.c
+++ b/source/pdf/pdf-font.c
@@ -411,7 +411,7 @@ pdf_load_embedded_font(fz_context *ctx, pdf_document *doc, pdf_font_desc *fontde
{
fz_buffer *buf;
- buf = pdf_load_stream(ctx, doc, pdf_to_num(ctx, stmref));
+ buf = pdf_load_stream(ctx, stmref);
fz_try(ctx)
fontdesc->font = fz_new_font_from_buffer(ctx, fontname, buf, 0, 1);
fz_always(ctx)
@@ -1020,7 +1020,7 @@ load_cid_font(fz_context *ctx, pdf_document *doc, pdf_obj *dict, pdf_obj *encodi
fz_buffer *buf;
size_t z;
- buf = pdf_load_stream(ctx, doc, pdf_to_num(ctx, cidtogidmap));
+ buf = pdf_load_stream(ctx, cidtogidmap);
fontdesc->cid_to_gid_len = (buf->len) / 2;
fontdesc->cid_to_gid = fz_malloc_array(ctx, fontdesc->cid_to_gid_len, sizeof(unsigned short));
diff --git a/source/pdf/pdf-function.c b/source/pdf/pdf-function.c
index 6de7bfc0..1207b191 100644
--- a/source/pdf/pdf-function.c
+++ b/source/pdf/pdf-function.c
@@ -833,7 +833,7 @@ parse_code(fz_context *ctx, pdf_function *func, fz_stream *stream, int *codeptr,
}
static void
-load_postscript_func(fz_context *ctx, pdf_document *doc, pdf_function *func, pdf_obj *dict, int num)
+load_postscript_func(fz_context *ctx, pdf_document *doc, pdf_function *func, pdf_obj *dict)
{
fz_stream *stream = NULL;
int codeptr;
@@ -848,7 +848,7 @@ load_postscript_func(fz_context *ctx, pdf_document *doc, pdf_function *func, pdf
fz_try(ctx)
{
- stream = pdf_open_stream(ctx, doc, num);
+ stream = pdf_open_stream(ctx, dict);
tok = pdf_lex(ctx, stream, &buf);
if (tok != PDF_TOK_OPEN_BRACE)
@@ -906,7 +906,7 @@ eval_postscript_func(fz_context *ctx, pdf_function *func, const float *in, float
#define MAX_SAMPLE_FUNCTION_SIZE (100 << 20)
static void
-load_sample_func(fz_context *ctx, pdf_document *doc, pdf_function *func, pdf_obj *dict, int num)
+load_sample_func(fz_context *ctx, pdf_document *doc, pdf_function *func, pdf_obj *dict)
{
fz_stream *stream;
pdf_obj *obj;
@@ -984,7 +984,7 @@ load_sample_func(fz_context *ctx, pdf_document *doc, pdf_function *func, pdf_obj
func->u.sa.samples = fz_malloc_array(ctx, samplecount, sizeof(float));
func->base.size += samplecount * sizeof(float);
- stream = pdf_open_stream(ctx, doc, num);
+ stream = pdf_open_stream(ctx, dict);
fz_try(ctx)
{
@@ -1661,7 +1661,7 @@ pdf_load_function(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int in, int
switch (func->type)
{
case SAMPLE:
- load_sample_func(ctx, doc, func, dict, pdf_to_num(ctx, dict));
+ load_sample_func(ctx, doc, func, dict);
break;
case EXPONENTIAL:
@@ -1673,7 +1673,7 @@ pdf_load_function(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int in, int
break;
case POSTSCRIPT:
- load_postscript_func(ctx, doc, func, dict, pdf_to_num(ctx, dict));
+ load_postscript_func(ctx, doc, func, dict);
break;
default:
diff --git a/source/pdf/pdf-graft.c b/source/pdf/pdf-graft.c
index 64072eb0..f21e40b7 100644
--- a/source/pdf/pdf-graft.c
+++ b/source/pdf/pdf-graft.c
@@ -110,7 +110,7 @@ pdf_graft_object(fz_context *ctx, pdf_document *dst, pdf_document *src, pdf_obj
ref = pdf_new_indirect(ctx, dst, new_num, 0);
if (pdf_is_stream(ctx, obj_ref))
{
- buffer = pdf_load_raw_stream(ctx, src, src_num);
+ buffer = pdf_load_raw_stream_number(ctx, src, src_num);
pdf_update_stream(ctx, dst, ref, buffer, 1);
}
}
diff --git a/source/pdf/pdf-image.c b/source/pdf/pdf-image.c
index c9c1fdda..d54de34c 100644
--- a/source/pdf/pdf-image.c
+++ b/source/pdf/pdf-image.c
@@ -221,7 +221,7 @@ pdf_load_jpx(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int forcemask)
fz_var(colorspace);
fz_var(mask);
- buf = pdf_load_stream(ctx, doc, pdf_to_num(ctx, dict));
+ buf = pdf_load_stream(ctx, dict);
/* FIXME: We can't handle decode arrays for indexed images currently */
fz_try(ctx)
diff --git a/source/pdf/pdf-parse.c b/source/pdf/pdf-parse.c
index 0db2e2f0..5ac9ba4c 100644
--- a/source/pdf/pdf-parse.c
+++ b/source/pdf/pdf-parse.c
@@ -77,7 +77,7 @@ pdf_to_utf8(fz_context *ctx, pdf_document *doc, pdf_obj *src)
}
else if (pdf_is_stream(ctx, src))
{
- stmbuf = pdf_load_stream(ctx, doc, pdf_to_num(ctx, src));
+ stmbuf = pdf_load_stream(ctx, src);
srclen = fz_buffer_storage(ctx, stmbuf, (unsigned char **)&srcptr);
}
else
diff --git a/source/pdf/pdf-repair.c b/source/pdf/pdf-repair.c
index fdb48fe9..690bf15a 100644
--- a/source/pdf/pdf-repair.c
+++ b/source/pdf/pdf-repair.c
@@ -213,7 +213,7 @@ pdf_repair_obj_stm(fz_context *ctx, pdf_document *doc, int stm_num)
pdf_drop_obj(ctx, obj);
- stm = pdf_open_stream(ctx, doc, stm_num);
+ stm = pdf_open_stream_number(ctx, doc, stm_num);
for (i = 0; i < count; i++)
{
diff --git a/source/pdf/pdf-stream.c b/source/pdf/pdf-stream.c
index f54c2f91..9ff136b2 100644
--- a/source/pdf/pdf-stream.c
+++ b/source/pdf/pdf-stream.c
@@ -68,7 +68,7 @@ pdf_load_jbig2_globals(fz_context *ctx, pdf_document *doc, pdf_obj *dict)
fz_try(ctx)
{
- buf = pdf_load_stream(ctx, doc, pdf_to_num(ctx, dict));
+ buf = pdf_load_stream(ctx, dict);
globals = fz_load_jbig2_globals(ctx, buf);
pdf_store_item(ctx, dict, globals, buf->len);
}
@@ -382,7 +382,7 @@ pdf_load_compressed_inline_image(fz_context *ctx, pdf_document *doc, pdf_obj *di
* Open a stream for reading the raw (compressed but decrypted) data.
*/
fz_stream *
-pdf_open_raw_stream(fz_context *ctx, pdf_document *doc, int num)
+pdf_open_raw_stream_number(fz_context *ctx, pdf_document *doc, int num)
{
pdf_xref_entry *x;
int orig_num, orig_gen;
@@ -418,7 +418,7 @@ pdf_open_image_stream(fz_context *ctx, pdf_document *doc, int num, fz_compressio
* Using doc->file while a stream is open is a Bad idea.
*/
fz_stream *
-pdf_open_stream(fz_context *ctx, pdf_document *doc, int num)
+pdf_open_stream_number(fz_context *ctx, pdf_document *doc, int num)
{
return pdf_open_image_stream(ctx, doc, num, NULL);
}
@@ -435,7 +435,7 @@ pdf_open_stream_with_offset(fz_context *ctx, pdf_document *doc, int num, pdf_obj
* Load raw (compressed but decrypted) contents of a stream into buf.
*/
fz_buffer *
-pdf_load_raw_stream(fz_context *ctx, pdf_document *doc, int num)
+pdf_load_raw_stream_number(fz_context *ctx, pdf_document *doc, int num)
{
fz_stream *stm;
pdf_obj *dict;
@@ -456,7 +456,7 @@ pdf_load_raw_stream(fz_context *ctx, pdf_document *doc, int num)
pdf_drop_obj(ctx, dict);
- stm = pdf_open_raw_stream(ctx, doc, num);
+ stm = pdf_open_raw_stream_number(ctx, doc, num);
buf = fz_read_all(ctx, stm, len);
@@ -588,7 +588,7 @@ pdf_load_image_stream(fz_context *ctx, pdf_document *doc, int num, fz_compressio
* Load uncompressed contents of a stream into buf.
*/
fz_buffer *
-pdf_load_stream(fz_context *ctx, pdf_document *doc, int num)
+pdf_load_stream_number(fz_context *ctx, pdf_document *doc, int num)
{
return pdf_load_image_stream(ctx, doc, num, NULL, NULL);
}
@@ -631,7 +631,7 @@ pdf_open_object_array(fz_context *ctx, pdf_document *doc, pdf_obj *list)
pdf_obj *obj = pdf_array_get(ctx, list, i);
fz_try(ctx)
{
- fz_concat_push(ctx, stm, pdf_open_stream(ctx, doc, pdf_to_num(ctx, obj)));
+ fz_concat_push(ctx, stm, pdf_open_stream(ctx, obj));
}
fz_catch(ctx)
{
@@ -658,3 +658,31 @@ pdf_open_contents_stream(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
fz_throw(ctx, FZ_ERROR_GENERIC, "pdf object stream missing (%d 0 R)", num);
}
+
+fz_buffer *pdf_load_raw_stream(fz_context *ctx, pdf_obj *ref)
+{
+ if (pdf_is_stream(ctx, ref))
+ return pdf_load_raw_stream_number(ctx, pdf_get_indirect_document(ctx, ref), pdf_to_num(ctx, ref));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "object is not a stream");
+}
+
+fz_buffer *pdf_load_stream(fz_context *ctx, pdf_obj *ref)
+{
+ if (pdf_is_stream(ctx, ref))
+ return pdf_load_stream_number(ctx, pdf_get_indirect_document(ctx, ref), pdf_to_num(ctx, ref));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "object is not a stream");
+}
+
+fz_stream *pdf_open_raw_stream(fz_context *ctx, pdf_obj *ref)
+{
+ if (pdf_is_stream(ctx, ref))
+ return pdf_open_raw_stream_number(ctx, pdf_get_indirect_document(ctx, ref), pdf_to_num(ctx, ref));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "object is not a stream");
+}
+
+fz_stream *pdf_open_stream(fz_context *ctx, pdf_obj *ref)
+{
+ if (pdf_is_stream(ctx, ref))
+ return pdf_open_stream_number(ctx, pdf_get_indirect_document(ctx, ref), pdf_to_num(ctx, ref));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "object is not a stream");
+}
diff --git a/source/pdf/pdf-type3.c b/source/pdf/pdf-type3.c
index 8eeebd19..57cda6df 100644
--- a/source/pdf/pdf-type3.c
+++ b/source/pdf/pdf-type3.c
@@ -160,7 +160,7 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d
obj = pdf_dict_gets(ctx, charprocs, estrings[i]);
if (pdf_is_stream(ctx, obj))
{
- fontdesc->font->t3procs[i] = pdf_load_stream(ctx, doc, pdf_to_num(ctx, obj));
+ fontdesc->font->t3procs[i] = pdf_load_stream(ctx, obj);
fontdesc->size += fontdesc->font->t3procs[i]->cap;
fontdesc->size += 0; // TODO: display list size calculation
}
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c
index af5ce5b9..84e64450 100644
--- a/source/pdf/pdf-write.c
+++ b/source/pdf/pdf-write.c
@@ -692,8 +692,8 @@ static void removeduplicateobjs(fz_context *ctx, pdf_document *doc, pdf_write_st
{
unsigned char *dataa, *datab;
size_t lena, lenb;
- sa = pdf_load_raw_stream(ctx, doc, num);
- sb = pdf_load_raw_stream(ctx, doc, other);
+ sa = pdf_load_raw_stream_number(ctx, doc, num);
+ sb = pdf_load_raw_stream_number(ctx, doc, other);
lena = fz_buffer_storage(ctx, sa, &dataa);
lenb = fz_buffer_storage(ctx, sb, &datab);
if (lena == lenb && memcmp(dataa, datab, lena) == 0)
@@ -1631,7 +1631,7 @@ static void copystream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts
pdf_obj *newlen;
pdf_obj *obj;
- buf = pdf_load_raw_stream(ctx, doc, num);
+ buf = pdf_load_raw_stream_number(ctx, doc, num);
obj = pdf_copy_dict(ctx, obj_orig);
diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c
index c5b37127..30904d78 100644
--- a/source/pdf/pdf-xref.c
+++ b/source/pdf/pdf-xref.c
@@ -1682,7 +1682,7 @@ pdf_load_obj_stm(fz_context *ctx, pdf_document *doc, int num, pdf_lexbuf *buf, i
numbuf = fz_calloc(ctx, count, sizeof(*numbuf));
ofsbuf = fz_calloc(ctx, count, sizeof(*ofsbuf));
- stm = pdf_open_stream(ctx, doc, num);
+ stm = pdf_open_stream_number(ctx, doc, num);
for (i = 0; i < count; i++)
{
tok = pdf_lex(ctx, stm, buf);
@@ -2387,7 +2387,7 @@ pdf_load_hints(fz_context *ctx, pdf_document *doc, int objnum)
int least_shared_group_len, shared_group_len_num_bits;
int max_object_num = pdf_xref_len(ctx, doc);
- stream = pdf_open_stream(ctx, doc, objnum);
+ stream = pdf_open_stream_number(ctx, doc, objnum);
dict = pdf_get_xref_entry(ctx, doc, objnum)->obj;
if (dict == NULL || !pdf_is_dict(ctx, dict))
fz_throw(ctx, FZ_ERROR_GENERIC, "malformed hint object");