summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-04-12 13:51:44 +0200
committerTor Andersson <tor.andersson@artifex.com>2018-04-25 12:26:32 +0200
commite41e86bd0172036cb29d6fe1a26f88ad075d060f (patch)
treefdb4478c773621eb166a3dab0ae51e33654a3667 /source
parent6ee3e43ca37620febd255390b2c29a2ceda35f93 (diff)
downloadmupdf-e41e86bd0172036cb29d6fe1a26f88ad075d060f.tar.xz
Remove document argument from pdf_new_primitive functions.
Also remove useless pdf_new_null and pdf_new_bool functions. Use the PDF_NULL, PDF_TRUE, and PDF_FALSE macros instead.
Diffstat (limited to 'source')
-rw-r--r--source/pdf/pdf-annot-edit.c9
-rw-r--r--source/pdf/pdf-clean-file.c4
-rw-r--r--source/pdf/pdf-form.c31
-rw-r--r--source/pdf/pdf-interpret.c4
-rw-r--r--source/pdf/pdf-nametree.c2
-rw-r--r--source/pdf/pdf-object.c50
-rw-r--r--source/pdf/pdf-op-filter.c2
-rw-r--r--source/pdf/pdf-page.c2
-rw-r--r--source/pdf/pdf-parse.c64
-rw-r--r--source/pdf/pdf-portfolio.c6
-rw-r--r--source/pdf/pdf-repair.c4
-rw-r--r--source/pdf/pdf-write.c32
-rw-r--r--source/pdf/pdf-xref.c2
-rw-r--r--source/tools/murun.c54
14 files changed, 105 insertions, 161 deletions
diff --git a/source/pdf/pdf-annot-edit.c b/source/pdf/pdf-annot-edit.c
index f559828b..c76b2446 100644
--- a/source/pdf/pdf-annot-edit.c
+++ b/source/pdf/pdf-annot-edit.c
@@ -295,10 +295,8 @@ pdf_annot_is_open(fz_context *ctx, pdf_annot *annot)
void
pdf_set_annot_is_open(fz_context *ctx, pdf_annot *annot, int is_open)
{
- pdf_document *doc = annot->page->doc;
check_allowed_subtypes(ctx, annot, PDF_NAME(Open), open_subtypes);
- pdf_dict_put_drop(ctx, annot->obj, PDF_NAME(Open),
- pdf_new_bool(ctx, doc, is_open));
+ pdf_dict_put_bool(ctx, annot->obj, PDF_NAME(Open), is_open);
pdf_dirty_annot(ctx, annot);
}
@@ -821,7 +819,6 @@ void pdf_add_annot_vertex(fz_context *ctx, pdf_annot *annot, fz_point p)
void pdf_set_annot_vertex(fz_context *ctx, pdf_annot *annot, int i, fz_point p)
{
- pdf_document *doc = annot->page->doc;
fz_matrix page_ctm, inv_page_ctm;
pdf_obj *vertices;
@@ -833,8 +830,8 @@ void pdf_set_annot_vertex(fz_context *ctx, pdf_annot *annot, int i, fz_point p)
fz_transform_point(&p, &inv_page_ctm);
vertices = pdf_dict_get(ctx, annot->obj, PDF_NAME(Vertices));
- pdf_array_put_drop(ctx, vertices, i * 2 + 0, pdf_new_real(ctx, doc, p.x));
- pdf_array_put_drop(ctx, vertices, i * 2 + 1, pdf_new_real(ctx, doc, p.y));
+ pdf_array_put_drop(ctx, vertices, i * 2 + 0, pdf_new_real(ctx, p.x));
+ pdf_array_put_drop(ctx, vertices, i * 2 + 1, pdf_new_real(ctx, p.y));
}
static pdf_obj *quad_point_subtypes[] = {
diff --git a/source/pdf/pdf-clean-file.c b/source/pdf/pdf-clean-file.c
index eb5505dc..86199f22 100644
--- a/source/pdf/pdf-clean-file.c
+++ b/source/pdf/pdf-clean-file.c
@@ -228,7 +228,7 @@ static void retainpages(fz_context *ctx, globals *glo, int argc, char **argv)
}
/* Update page count and kids array */
- countobj = pdf_new_int(ctx, doc, pdf_array_len(ctx, kids));
+ countobj = pdf_new_int(ctx, pdf_array_len(ctx, kids));
pdf_dict_put_drop(ctx, pages, PDF_NAME(Count), countobj);
pdf_dict_put_drop(ctx, pages, PDF_NAME(Kids), kids);
@@ -261,7 +261,7 @@ static void retainpages(fz_context *ctx, globals *glo, int argc, char **argv)
dest = pdf_array_get(ctx, dest ? dest : val, 0);
if (dest_is_valid_page(ctx, dest, page_object_nums, pagecount))
{
- pdf_obj *key_str = pdf_new_string(ctx, doc, pdf_to_name(ctx, key), strlen(pdf_to_name(ctx, key)));
+ pdf_obj *key_str = pdf_new_string(ctx, pdf_to_name(ctx, key), strlen(pdf_to_name(ctx, key)));
pdf_array_push_drop(ctx, names_list, key_str);
pdf_array_push(ctx, names_list, val);
}
diff --git a/source/pdf/pdf-form.c b/source/pdf/pdf-form.c
index fa20949d..85c0cda7 100644
--- a/source/pdf/pdf-form.c
+++ b/source/pdf/pdf-form.c
@@ -212,9 +212,7 @@ static pdf_obj *specified_fields(fz_context *ctx, pdf_document *doc, pdf_obj *fi
pdf_obj *form = pdf_dict_getl(ctx, pdf_trailer(ctx, doc), PDF_NAME(Root), PDF_NAME(AcroForm), PDF_NAME(Fields), NULL);
int i, n;
pdf_obj *result = pdf_new_array(ctx, doc, 0);
- pdf_obj *nil = NULL;
- fz_var(nil);
fz_try(ctx)
{
/* The 'fields' array not being present signals that all fields
@@ -222,10 +220,7 @@ static pdf_obj *specified_fields(fz_context *ctx, pdf_document *doc, pdf_obj *fi
if (exclude || !fields)
{
/* mark the fields we don't want to act upon */
- nil = pdf_new_null(ctx, doc);
-
n = pdf_array_len(ctx, fields);
-
for (i = 0; i < n; i++)
{
pdf_obj *field = pdf_array_get(ctx, fields, i);
@@ -234,7 +229,7 @@ static pdf_obj *specified_fields(fz_context *ctx, pdf_document *doc, pdf_obj *fi
field = pdf_lookup_field(ctx, form, pdf_to_str_buf(ctx, field));
if (field)
- pdf_dict_put(ctx, field, PDF_NAME(Exclude), nil);
+ pdf_dict_put(ctx, field, PDF_NAME(Exclude), PDF_NULL);
}
/* Act upon all unmarked fields */
@@ -273,10 +268,6 @@ static pdf_obj *specified_fields(fz_context *ctx, pdf_document *doc, pdf_obj *fi
}
}
}
- fz_always(ctx)
- {
- pdf_drop_obj(ctx, nil);
- }
fz_catch(ctx)
{
pdf_drop_obj(ctx, result);
@@ -529,7 +520,7 @@ static void toggle_check_box(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
if (val && grp)
{
- pdf_obj *v = pdf_new_text_string(ctx, doc, val);
+ pdf_obj *v = pdf_new_text_string(ctx, val);
pdf_dict_put_drop(ctx, grp, PDF_NAME(V), v);
recalculate(ctx, doc);
}
@@ -689,7 +680,7 @@ pdf_widget *pdf_create_widget(fz_context *ctx, pdf_document *doc, pdf_page *page
if (type == PDF_WIDGET_TYPE_SIGNATURE)
{
int sigflags = (old_sigflags | (SigFlag_SignaturesExist|SigFlag_AppendOnly));
- pdf_dict_putl_drop(ctx, pdf_trailer(ctx, doc), pdf_new_int(ctx, doc, sigflags), PDF_NAME(Root), PDF_NAME(AcroForm), PDF_NAME(SigFlags), NULL);
+ pdf_dict_putl_drop(ctx, pdf_trailer(ctx, doc), pdf_new_int(ctx, sigflags), PDF_NAME(Root), PDF_NAME(AcroForm), PDF_NAME(SigFlags), NULL);
}
/*
@@ -712,7 +703,7 @@ pdf_widget *pdf_create_widget(fz_context *ctx, pdf_document *doc, pdf_page *page
/* An empty Fields array may have been created, but that is harmless */
if (type == PDF_WIDGET_TYPE_SIGNATURE)
- pdf_dict_putl_drop(ctx, pdf_trailer(ctx, doc), pdf_new_int(ctx, doc, old_sigflags), PDF_NAME(Root), PDF_NAME(AcroForm), PDF_NAME(SigFlags), NULL);
+ pdf_dict_putl_drop(ctx, pdf_trailer(ctx, doc), pdf_new_int(ctx, old_sigflags), PDF_NAME(Root), PDF_NAME(AcroForm), PDF_NAME(SigFlags), NULL);
fz_rethrow(ctx);
}
@@ -771,7 +762,7 @@ static void update_checkbox_selector(fz_context *ctx, pdf_document *doc, pdf_obj
pdf_obj *oval;
if (pdf_dict_gets(ctx, n, val))
- oval = pdf_new_name(ctx, doc, val);
+ oval = pdf_new_name(ctx, val);
else
oval = PDF_NAME(Off);
pdf_dict_put_drop(ctx, field, PDF_NAME(AS), oval);
@@ -851,7 +842,7 @@ void pdf_field_set_button_caption(fz_context *ctx, pdf_document *doc, pdf_obj *f
{
if (pdf_field_type(ctx, doc, field) == PDF_WIDGET_TYPE_PUSHBUTTON)
{
- pdf_obj *val = pdf_new_text_string(ctx, doc, text);
+ pdf_obj *val = pdf_new_text_string(ctx, text);
pdf_dict_putl_drop(ctx, field, val, PDF_NAME(MK), PDF_NAME(CA), NULL);
pdf_field_mark_dirty(ctx, doc, field);
}
@@ -959,7 +950,7 @@ void pdf_field_set_display(fz_context *ctx, pdf_document *doc, pdf_obj *field, i
break;
}
- fo = pdf_new_int(ctx, doc, f);
+ fo = pdf_new_int(ctx, f);
pdf_dict_put_drop(ctx, field, PDF_NAME(F), fo);
}
else
@@ -1008,7 +999,7 @@ void pdf_field_set_text_color(fz_context *ctx, pdf_document *doc, pdf_obj *field
fzbuf = fz_new_buffer(ctx, 0);
pdf_fzbuf_print_da(ctx, fzbuf, &di);
len = fz_buffer_storage(ctx, fzbuf, &buf);
- daobj = pdf_new_string(ctx, doc, (char *)buf, len);
+ daobj = pdf_new_string(ctx, (char *)buf, len);
pdf_dict_put_drop(ctx, field, PDF_NAME(DA), daobj);
pdf_field_mark_dirty(ctx, doc, field);
}
@@ -1232,7 +1223,7 @@ void pdf_choice_widget_set_value(fz_context *ctx, pdf_document *doc, pdf_widget
for (i = 0; i < n; i++)
{
- opt = pdf_new_text_string(ctx, doc, opts[i]);
+ opt = pdf_new_text_string(ctx, opts[i]);
pdf_array_push_drop(ctx, optarr, opt);
}
@@ -1240,7 +1231,7 @@ void pdf_choice_widget_set_value(fz_context *ctx, pdf_document *doc, pdf_widget
}
else
{
- opt = pdf_new_text_string(ctx, doc, opts[0]);
+ opt = pdf_new_text_string(ctx, opts[0]);
pdf_dict_put_drop(ctx, annot->obj, PDF_NAME(V), opt);
}
@@ -1348,7 +1339,7 @@ void pdf_signature_set_value(fz_context *ctx, pdf_document *doc, pdf_obj *field,
byte_range = pdf_new_array(ctx, doc, 4);
pdf_dict_put_drop(ctx, v, PDF_NAME(ByteRange), byte_range);
- contents = pdf_new_string(ctx, doc, buf, sizeof(buf));
+ contents = pdf_new_string(ctx, buf, sizeof(buf));
pdf_dict_put_drop(ctx, v, PDF_NAME(Contents), contents);
pdf_dict_put(ctx, v, PDF_NAME(Filter), PDF_NAME(Adobe_PPKLite));
diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c
index 8f8d051f..88b98bb5 100644
--- a/source/pdf/pdf-interpret.c
+++ b/source/pdf/pdf-interpret.c
@@ -892,7 +892,7 @@ pdf_process_stream(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, fz_stream
{
pdf_drop_obj(ctx, csi->obj);
csi->obj = NULL;
- csi->obj = pdf_new_name(ctx, doc, buf->scratch);
+ csi->obj = pdf_new_name(ctx, buf->scratch);
}
else
fz_strlcpy(csi->name, buf->scratch, sizeof(csi->name));
@@ -929,7 +929,7 @@ pdf_process_stream(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, fz_stream
pdf_drop_obj(ctx, csi->obj);
csi->obj = NULL;
}
- csi->obj = pdf_new_string(ctx, doc, buf->scratch, buf->len);
+ csi->obj = pdf_new_string(ctx, buf->scratch, buf->len);
}
break;
diff --git a/source/pdf/pdf-nametree.c b/source/pdf/pdf-nametree.c
index 375b9fd5..30dd5974 100644
--- a/source/pdf/pdf-nametree.c
+++ b/source/pdf/pdf-nametree.c
@@ -140,7 +140,7 @@ pdf_load_name_tree_imp(fz_context *ctx, pdf_obj *dict, pdf_document *doc, pdf_ob
pdf_obj *val = pdf_array_get(ctx, names, i + 1);
if (pdf_is_string(ctx, key))
{
- key = pdf_to_utf8_name(ctx, doc, key);
+ key = pdf_to_utf8_name(ctx, key);
pdf_dict_put(ctx, dict, key, val);
pdf_drop_obj(ctx, key);
}
diff --git a/source/pdf/pdf-object.c b/source/pdf/pdf-object.c
index 286097f7..b774f878 100644
--- a/source/pdf/pdf-object.c
+++ b/source/pdf/pdf-object.c
@@ -105,19 +105,7 @@ typedef struct pdf_obj_ref_s
#define REF(obj) ((pdf_obj_ref *)(obj))
pdf_obj *
-pdf_new_null(fz_context *ctx, pdf_document *doc)
-{
- return PDF_NULL;
-}
-
-pdf_obj *
-pdf_new_bool(fz_context *ctx, pdf_document *doc, int b)
-{
- return b ? PDF_TRUE : PDF_FALSE;
-}
-
-pdf_obj *
-pdf_new_int(fz_context *ctx, pdf_document *doc, int64_t i)
+pdf_new_int(fz_context *ctx, int64_t i)
{
pdf_obj_num *obj;
obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj_num)), "pdf_obj(int)");
@@ -129,7 +117,7 @@ pdf_new_int(fz_context *ctx, pdf_document *doc, int64_t i)
}
pdf_obj *
-pdf_new_real(fz_context *ctx, pdf_document *doc, float f)
+pdf_new_real(fz_context *ctx, float f)
{
pdf_obj_num *obj;
obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj_num)), "pdf_obj(real)");
@@ -141,7 +129,7 @@ pdf_new_real(fz_context *ctx, pdf_document *doc, float f)
}
pdf_obj *
-pdf_new_string(fz_context *ctx, pdf_document *doc, const char *str, size_t len)
+pdf_new_string(fz_context *ctx, const char *str, size_t len)
{
pdf_obj_string *obj;
unsigned int l = (unsigned int)len;
@@ -160,7 +148,7 @@ pdf_new_string(fz_context *ctx, pdf_document *doc, const char *str, size_t len)
}
pdf_obj *
-pdf_new_name(fz_context *ctx, pdf_document *doc, const char *str)
+pdf_new_name(fz_context *ctx, const char *str)
{
pdf_obj_name *obj;
int l = 3; /* skip dummy slots */
@@ -1271,7 +1259,7 @@ pdf_dict_puts(fz_context *ctx, pdf_obj *obj, const char *key, pdf_obj *val)
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
doc = DICT(obj)->doc;
- keyobj = pdf_new_name(ctx, doc, key);
+ keyobj = pdf_new_name(ctx, key);
fz_try(ctx)
pdf_dict_put(ctx, obj, keyobj, val);
@@ -1284,15 +1272,13 @@ pdf_dict_puts(fz_context *ctx, pdf_obj *obj, const char *key, pdf_obj *val)
void
pdf_dict_puts_drop(fz_context *ctx, pdf_obj *obj, const char *key, pdf_obj *val)
{
- pdf_document *doc;
pdf_obj *keyobj;
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
- doc = DICT(obj)->doc;
- keyobj = pdf_new_name(ctx, doc, key);
+ keyobj = pdf_new_name(ctx, key);
fz_var(keyobj);
@@ -2136,32 +2122,32 @@ int pdf_obj_refs(fz_context *ctx, pdf_obj *obj)
void pdf_dict_put_bool(fz_context *ctx, pdf_obj *dict, pdf_obj *key, int x)
{
- pdf_dict_put_drop(ctx, dict, key, pdf_new_bool(ctx, NULL, x));
+ pdf_dict_put(ctx, dict, key, x ? PDF_TRUE : PDF_FALSE);
}
void pdf_dict_put_int(fz_context *ctx, pdf_obj *dict, pdf_obj *key, int64_t x)
{
- pdf_dict_put_drop(ctx, dict, key, pdf_new_int(ctx, NULL, x));
+ pdf_dict_put_drop(ctx, dict, key, pdf_new_int(ctx, x));
}
void pdf_dict_put_real(fz_context *ctx, pdf_obj *dict, pdf_obj *key, double x)
{
- pdf_dict_put_drop(ctx, dict, key, pdf_new_real(ctx, NULL, x));
+ pdf_dict_put_drop(ctx, dict, key, pdf_new_real(ctx, x));
}
void pdf_dict_put_name(fz_context *ctx, pdf_obj *dict, pdf_obj *key, const char *x)
{
- pdf_dict_put_drop(ctx, dict, key, pdf_new_name(ctx, NULL, x));
+ pdf_dict_put_drop(ctx, dict, key, pdf_new_name(ctx, x));
}
void pdf_dict_put_string(fz_context *ctx, pdf_obj *dict, pdf_obj *key, const char *x, size_t n)
{
- pdf_dict_put_drop(ctx, dict, key, pdf_new_string(ctx, NULL, x, n));
+ pdf_dict_put_drop(ctx, dict, key, pdf_new_string(ctx, x, n));
}
void pdf_dict_put_text_string(fz_context *ctx, pdf_obj *dict, pdf_obj *key, const char *x)
{
- pdf_dict_put_drop(ctx, dict, key, pdf_new_text_string(ctx, NULL, x));
+ pdf_dict_put_drop(ctx, dict, key, pdf_new_text_string(ctx, x));
}
void pdf_dict_put_rect(fz_context *ctx, pdf_obj *dict, pdf_obj *key, const fz_rect *x)
@@ -2190,32 +2176,32 @@ pdf_obj *pdf_dict_put_dict(fz_context *ctx, pdf_obj *dict, pdf_obj *key, int ini
void pdf_array_push_bool(fz_context *ctx, pdf_obj *array, int x)
{
- pdf_array_push_drop(ctx, array, pdf_new_bool(ctx, NULL, x));
+ pdf_array_push(ctx, array, x ? PDF_TRUE : PDF_FALSE);
}
void pdf_array_push_int(fz_context *ctx, pdf_obj *array, int64_t x)
{
- pdf_array_push_drop(ctx, array, pdf_new_int(ctx, NULL, x));
+ pdf_array_push_drop(ctx, array, pdf_new_int(ctx, x));
}
void pdf_array_push_real(fz_context *ctx, pdf_obj *array, double x)
{
- pdf_array_push_drop(ctx, array, pdf_new_real(ctx, NULL, x));
+ pdf_array_push_drop(ctx, array, pdf_new_real(ctx, x));
}
void pdf_array_push_name(fz_context *ctx, pdf_obj *array, const char *x)
{
- pdf_array_push_drop(ctx, array, pdf_new_name(ctx, NULL, x));
+ pdf_array_push_drop(ctx, array, pdf_new_name(ctx, x));
}
void pdf_array_push_string(fz_context *ctx, pdf_obj *array, const char *x, size_t n)
{
- pdf_array_push_drop(ctx, array, pdf_new_string(ctx, NULL, x, n));
+ pdf_array_push_drop(ctx, array, pdf_new_string(ctx, x, n));
}
void pdf_array_push_text_string(fz_context *ctx, pdf_obj *array, const char *x)
{
- pdf_array_push_drop(ctx, array, pdf_new_text_string(ctx, NULL, x));
+ pdf_array_push_drop(ctx, array, pdf_new_text_string(ctx, x));
}
pdf_obj *pdf_array_push_array(fz_context *ctx, pdf_obj *array, int initial)
diff --git a/source/pdf/pdf-op-filter.c b/source/pdf/pdf-op-filter.c
index b848816d..ec905ff7 100644
--- a/source/pdf/pdf-op-filter.c
+++ b/source/pdf/pdf-op-filter.c
@@ -504,7 +504,7 @@ send_adjustment(fz_context *ctx, pdf_filter_processor *p, fz_point skip)
{
float skip_dist = p->tos.fontdesc->wmode == 1 ? -skip.y : -skip.x;
skip_dist = skip_dist / p->gstate->pending.text.size;
- skip_obj = pdf_new_real(ctx, p->doc, skip_dist * 1000);
+ skip_obj = pdf_new_real(ctx, skip_dist * 1000);
pdf_array_insert(ctx, arr, skip_obj, 0);
diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c
index 68e2b55e..b1e286ee 100644
--- a/source/pdf/pdf-page.c
+++ b/source/pdf/pdf-page.c
@@ -323,7 +323,7 @@ pdf_lookup_anchor(fz_context *ctx, pdf_document *doc, const char *name, float *x
if (xp) *xp = 0;
if (yp) *yp = 0;
- needle = pdf_new_string(ctx, doc, name, strlen(name));
+ needle = pdf_new_string(ctx, name, strlen(name));
fz_try(ctx)
dest = pdf_lookup_dest(ctx, doc, needle);
fz_always(ctx)
diff --git a/source/pdf/pdf-parse.c b/source/pdf/pdf-parse.c
index b1d012ef..87b326ae 100644
--- a/source/pdf/pdf-parse.c
+++ b/source/pdf/pdf-parse.c
@@ -309,16 +309,16 @@ pdf_from_ucs2(fz_context *ctx, unsigned short *src)
}
pdf_obj *
-pdf_to_utf8_name(fz_context *ctx, pdf_document *doc, pdf_obj *src)
+pdf_to_utf8_name(fz_context *ctx, pdf_obj *src)
{
char *buf = pdf_to_utf8(ctx, src);
- pdf_obj *dst = pdf_new_name(ctx, doc, buf);
+ pdf_obj *dst = pdf_new_name(ctx, buf);
fz_free(ctx, buf);
return dst;
}
static pdf_obj *
-pdf_new_text_string_utf16be(fz_context *ctx, pdf_document *doc, const char *s)
+pdf_new_text_string_utf16be(fz_context *ctx, const char *s)
{
int c, i = 0, n = fz_utflen(s);
unsigned char *p = fz_malloc(ctx, n * 2 + 2);
@@ -332,7 +332,7 @@ pdf_new_text_string_utf16be(fz_context *ctx, pdf_document *doc, const char *s)
p[i++] = (c) & 0xff;
}
fz_try(ctx)
- obj = pdf_new_string(ctx, doc, (char*)p, i);
+ obj = pdf_new_string(ctx, (char*)p, i);
fz_always(ctx)
fz_free(ctx, p);
fz_catch(ctx)
@@ -345,16 +345,16 @@ pdf_new_text_string_utf16be(fz_context *ctx, pdf_document *doc, const char *s)
* In theory, we could also use PDFDocEncoding.
*/
pdf_obj *
-pdf_new_text_string(fz_context *ctx, pdf_document *doc, const char *s)
+pdf_new_text_string(fz_context *ctx, const char *s)
{
int i = 0;
while (s[i] != 0)
{
if (((unsigned char)s[i]) >= 128)
- return pdf_new_text_string_utf16be(ctx, doc, s);
+ return pdf_new_text_string_utf16be(ctx, s);
++i;
}
- return pdf_new_string(ctx, doc, s, i);
+ return pdf_new_string(ctx, s, i);
}
pdf_obj *
@@ -491,7 +491,7 @@ pdf_parse_dict(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbuf *
if (tok != PDF_TOK_NAME)
fz_throw(ctx, FZ_ERROR_SYNTAX, "invalid key in dict");
- key = pdf_new_name(ctx, doc, buf->scratch);
+ key = pdf_new_name(ctx, buf->scratch);
tok = pdf_lex(ctx, file, buf);
@@ -505,12 +505,12 @@ pdf_parse_dict(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbuf *
val = pdf_parse_dict(ctx, doc, file, buf);
break;
- case PDF_TOK_NAME: val = pdf_new_name(ctx, doc, buf->scratch); break;
- case PDF_TOK_REAL: val = pdf_new_real(ctx, doc, buf->f); break;
- case PDF_TOK_STRING: val = pdf_new_string(ctx, doc, buf->scratch, buf->len); break;
- case PDF_TOK_TRUE: val = pdf_new_bool(ctx, doc, 1); break;
- case PDF_TOK_FALSE: val = pdf_new_bool(ctx, doc, 0); break;
- case PDF_TOK_NULL: val = pdf_new_null(ctx, doc); break;
+ case PDF_TOK_NAME: val = pdf_new_name(ctx, buf->scratch); break;
+ case PDF_TOK_REAL: val = pdf_new_real(ctx, buf->f); break;
+ case PDF_TOK_STRING: val = pdf_new_string(ctx, buf->scratch, buf->len); break;
+ case PDF_TOK_TRUE: val = PDF_TRUE; break;
+ case PDF_TOK_FALSE: val = PDF_FALSE; break;
+ case PDF_TOK_NULL: val = PDF_NULL; break;
case PDF_TOK_INT:
/* 64-bit to allow for numbers > INT_MAX and overflow */
@@ -519,7 +519,7 @@ pdf_parse_dict(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbuf *
if (tok == PDF_TOK_CLOSE_DICT || tok == PDF_TOK_NAME ||
(tok == PDF_TOK_KEYWORD && !strcmp(buf->scratch, "ID")))
{
- val = pdf_new_int(ctx, doc, a);
+ val = pdf_new_int(ctx, a);
pdf_dict_put(ctx, dict, key, val);
pdf_drop_obj(ctx, val);
val = NULL;
@@ -538,11 +538,11 @@ pdf_parse_dict(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbuf *
}
}
fz_warn(ctx, "invalid indirect reference in dict");
- val = pdf_new_null(ctx, doc);
+ val = PDF_NULL;
break;
default:
- val = pdf_new_null(ctx, doc);
+ val = PDF_NULL;
break;
}
@@ -576,13 +576,13 @@ pdf_parse_stm_obj(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbu
return pdf_parse_array(ctx, doc, file, buf);
case PDF_TOK_OPEN_DICT:
return pdf_parse_dict(ctx, doc, file, buf);
- case PDF_TOK_NAME: return pdf_new_name(ctx, doc, buf->scratch); break;
- case PDF_TOK_REAL: return pdf_new_real(ctx, doc, buf->f); break;
- case PDF_TOK_STRING: return pdf_new_string(ctx, doc, buf->scratch, buf->len); break;
- case PDF_TOK_TRUE: return pdf_new_bool(ctx, doc, 1); break;
- case PDF_TOK_FALSE: return pdf_new_bool(ctx, doc, 0); break;
- case PDF_TOK_NULL: return pdf_new_null(ctx, doc); break;
- case PDF_TOK_INT: return pdf_new_int(ctx, doc, buf->i); break;
+ case PDF_TOK_NAME: return pdf_new_name(ctx, buf->scratch);
+ case PDF_TOK_REAL: return pdf_new_real(ctx, buf->f);
+ case PDF_TOK_STRING: return pdf_new_string(ctx, buf->scratch, buf->len);
+ case PDF_TOK_TRUE: return PDF_TRUE;
+ case PDF_TOK_FALSE: return PDF_FALSE;
+ case PDF_TOK_NULL: return PDF_NULL;
+ case PDF_TOK_INT: return pdf_new_int(ctx, buf->i);
default: fz_throw(ctx, FZ_ERROR_SYNTAX, "unknown token in object stream");
}
}
@@ -641,12 +641,12 @@ pdf_parse_ind_obj(fz_context *ctx, pdf_document *doc,
obj = pdf_parse_dict(ctx, doc, file, buf);
break;
- case PDF_TOK_NAME: obj = pdf_new_name(ctx, doc, buf->scratch); break;
- case PDF_TOK_REAL: obj = pdf_new_real(ctx, doc, buf->f); break;
- case PDF_TOK_STRING: obj = pdf_new_string(ctx, doc, buf->scratch, buf->len); break;
- case PDF_TOK_TRUE: obj = pdf_new_bool(ctx, doc, 1); break;
- case PDF_TOK_FALSE: obj = pdf_new_bool(ctx, doc, 0); break;
- case PDF_TOK_NULL: obj = pdf_new_null(ctx, doc); break;
+ case PDF_TOK_NAME: obj = pdf_new_name(ctx, buf->scratch); break;
+ case PDF_TOK_REAL: obj = pdf_new_real(ctx, buf->f); break;
+ case PDF_TOK_STRING: obj = pdf_new_string(ctx, buf->scratch, buf->len); break;
+ case PDF_TOK_TRUE: obj = PDF_TRUE; break;
+ case PDF_TOK_FALSE: obj = PDF_FALSE; break;
+ case PDF_TOK_NULL: obj = PDF_NULL; break;
case PDF_TOK_INT:
a = buf->i;
@@ -654,7 +654,7 @@ pdf_parse_ind_obj(fz_context *ctx, pdf_document *doc,
if (tok == PDF_TOK_STREAM || tok == PDF_TOK_ENDOBJ)
{
- obj = pdf_new_int(ctx, doc, a);
+ obj = pdf_new_int(ctx, a);
read_next_token = 0;
break;
}
@@ -671,7 +671,7 @@ pdf_parse_ind_obj(fz_context *ctx, pdf_document *doc,
fz_throw(ctx, FZ_ERROR_SYNTAX, "expected 'R' keyword (%d %d R)", num, gen);
case PDF_TOK_ENDOBJ:
- obj = pdf_new_null(ctx, doc);
+ obj = PDF_NULL;
read_next_token = 0;
break;
diff --git a/source/pdf/pdf-portfolio.c b/source/pdf/pdf-portfolio.c
index 65610013..10dbc412 100644
--- a/source/pdf/pdf-portfolio.c
+++ b/source/pdf/pdf-portfolio.c
@@ -173,7 +173,7 @@ void pdf_rename_portfolio_schema(fz_context *ctx, pdf_document *doc, int entry,
if (p == NULL || entry)
fz_throw(ctx, FZ_ERROR_GENERIC, "entry out of range in pdf_rename_portfolio_schema");
- s = pdf_new_string(ctx, doc, name, name_len);
+ s = pdf_new_string(ctx, name, name_len);
pdf_drop_obj(ctx, p->entry.name);
p->entry.name = s;
pdf_dict_put(ctx, p->val, PDF_NAME(N), s);
@@ -316,7 +316,7 @@ void pdf_add_portfolio_schema(fz_context *ctx, pdf_document *doc, int entry, con
num_name = NULL;
num++;
fz_snprintf(str_name, sizeof str_name, "%d", num);
- num_name = pdf_new_name(ctx, doc, str_name);
+ num_name = pdf_new_name(ctx, str_name);
p = doc->portfolio;
for (p = doc->portfolio; p; p = p->next)
if (pdf_name_eq(ctx, num_name, p->key))
@@ -627,7 +627,7 @@ int pdf_add_portfolio_entry(fz_context *ctx, pdf_document *doc,
if (doc->portfolio == NULL)
load_portfolio(ctx, doc);
- key = pdf_new_string(ctx, doc, name, name_len);
+ key = pdf_new_string(ctx, name, name_len);
fz_try(ctx)
{
val = pdf_new_dict(ctx, doc, 6);
diff --git a/source/pdf/pdf-repair.c b/source/pdf/pdf-repair.c
index 1965a37e..3b4eceea 100644
--- a/source/pdf/pdf-repair.c
+++ b/source/pdf/pdf-repair.c
@@ -570,7 +570,7 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc)
fz_try(ctx)
{
- length = pdf_new_int(ctx, doc, list[i].stm_len);
+ length = pdf_new_int(ctx, list[i].stm_len);
pdf_dict_get_put_drop(ctx, dict, PDF_NAME(Length), length, &old_obj);
if (old_obj)
orphan_object(ctx, doc, old_obj);
@@ -610,7 +610,7 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc)
pdf_drop_obj(ctx, obj);
obj = NULL;
- obj = pdf_new_int(ctx, doc, maxnum + 1);
+ obj = pdf_new_int(ctx, maxnum + 1);
pdf_dict_put(ctx, pdf_trailer(ctx, doc), PDF_NAME(Size), obj);
pdf_drop_obj(ctx, obj);
obj = NULL;
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c
index 24e6d9e4..12d0f605 100644
--- a/source/pdf/pdf-write.c
+++ b/source/pdf/pdf-write.c
@@ -820,7 +820,7 @@ static void renumberobj(fz_context *ctx, pdf_document *doc, pdf_write_state *opt
{
int o = pdf_to_num(ctx, val);
if (o >= xref_len || o <= 0 || opts->renumber_map[o] == 0)
- val = pdf_new_null(ctx, doc);
+ val = PDF_NULL;
else
val = pdf_new_indirect(ctx, doc, opts->renumber_map[o], 0);
pdf_dict_put_drop(ctx, obj, key, val);
@@ -842,7 +842,7 @@ static void renumberobj(fz_context *ctx, pdf_document *doc, pdf_write_state *opt
{
int o = pdf_to_num(ctx, val);
if (o >= xref_len || o <= 0 || opts->renumber_map[o] == 0)
- val = pdf_new_null(ctx, doc);
+ val = PDF_NULL;
else
val = pdf_new_indirect(ctx, doc, opts->renumber_map[o], 0);
pdf_array_put_drop(ctx, obj, i, val);
@@ -1188,21 +1188,21 @@ add_linearization_objs(fz_context *ctx, pdf_document *doc, pdf_write_state *opts
opts->rev_renumber_map[params_num] = params_num;
opts->gen_list[params_num] = 0;
pdf_dict_put_real(ctx, params_obj, PDF_NAME(Linearized), 1.0f);
- opts->linear_l = pdf_new_int(ctx, doc, INT_MIN);
+ opts->linear_l = pdf_new_int(ctx, INT_MIN);
pdf_dict_put(ctx, params_obj, PDF_NAME(L), opts->linear_l);
- opts->linear_h0 = pdf_new_int(ctx, doc, INT_MIN);
+ opts->linear_h0 = pdf_new_int(ctx, INT_MIN);
o = pdf_new_array(ctx, doc, 2);
pdf_dict_put_drop(ctx, params_obj, PDF_NAME(H), o);
pdf_array_push(ctx, o, opts->linear_h0);
- opts->linear_h1 = pdf_new_int(ctx, doc, INT_MIN);
+ opts->linear_h1 = pdf_new_int(ctx, INT_MIN);
pdf_array_push(ctx, o, opts->linear_h1);
- opts->linear_o = pdf_new_int(ctx, doc, INT_MIN);
+ opts->linear_o = pdf_new_int(ctx, INT_MIN);
pdf_dict_put(ctx, params_obj, PDF_NAME(O), opts->linear_o);
- opts->linear_e = pdf_new_int(ctx, doc, INT_MIN);
+ opts->linear_e = pdf_new_int(ctx, INT_MIN);
pdf_dict_put(ctx, params_obj, PDF_NAME(E), opts->linear_e);
- opts->linear_n = pdf_new_int(ctx, doc, INT_MIN);
+ opts->linear_n = pdf_new_int(ctx, INT_MIN);
pdf_dict_put(ctx, params_obj, PDF_NAME(N), opts->linear_n);
- opts->linear_t = pdf_new_int(ctx, doc, INT_MIN);
+ opts->linear_t = pdf_new_int(ctx, INT_MIN);
pdf_dict_put(ctx, params_obj, PDF_NAME(T), opts->linear_t);
/* Primary hint stream */
@@ -1215,7 +1215,7 @@ add_linearization_objs(fz_context *ctx, pdf_document *doc, pdf_write_state *opts
opts->rev_renumber_map[hint_num] = hint_num;
opts->gen_list[hint_num] = 0;
pdf_dict_put_int(ctx, hint_obj, PDF_NAME(P), 0);
- opts->hints_s = pdf_new_int(ctx, doc, INT_MIN);
+ opts->hints_s = pdf_new_int(ctx, INT_MIN);
pdf_dict_put(ctx, hint_obj, PDF_NAME(S), opts->hints_s);
/* FIXME: Do we have thumbnails? Do a T entry */
/* FIXME: Do we have outlines? Do an O entry */
@@ -1226,7 +1226,7 @@ add_linearization_objs(fz_context *ctx, pdf_document *doc, pdf_write_state *opts
/* FIXME: Do we have logical structure hierarchy? Do a C entry */
/* FIXME: Do L, Page Label hint table */
pdf_dict_put(ctx, hint_obj, PDF_NAME(Filter), PDF_NAME(FlateDecode));
- opts->hints_length = pdf_new_int(ctx, doc, INT_MIN);
+ opts->hints_length = pdf_new_int(ctx, INT_MIN);
pdf_dict_put(ctx, hint_obj, PDF_NAME(Length), opts->hints_length);
pdf_get_xref_entry(ctx, doc, hint_num)->stm_ofs = -1;
}
@@ -1668,7 +1668,6 @@ static void write_data(fz_context *ctx, void *arg, const unsigned char *data, in
static void copystream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, pdf_obj *obj_orig, int num, int gen, int do_deflate)
{
fz_buffer *buf, *tmp;
- pdf_obj *newlen;
pdf_obj *obj;
size_t len;
unsigned char *data;
@@ -1709,8 +1708,7 @@ static void copystream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts
addhexfilter(ctx, doc, obj);
}
- newlen = pdf_new_int(ctx, doc, pdf_encrypted_len(ctx, doc->crypt, num, gen, (int)len));
- pdf_dict_put_drop(ctx, obj, PDF_NAME(Length), newlen);
+ pdf_dict_put_int(ctx, obj, PDF_NAME(Length), pdf_encrypted_len(ctx, doc->crypt, num, gen, (int)len));
fz_write_printf(ctx, opts->out, "%d %d obj\n", num, gen);
pdf_print_encrypted_obj(ctx, opts->out, obj, opts->do_tight, doc->crypt, num, gen);
@@ -2008,7 +2006,7 @@ static void writexref(fz_context *ctx, pdf_document *doc, pdf_write_state *opts,
{
trailer = pdf_new_dict(ctx, doc, 5);
- nobj = pdf_new_int(ctx, doc, to);
+ nobj = pdf_new_int(ctx, to);
pdf_dict_put_drop(ctx, trailer, PDF_NAME(Size), nobj);
if (first)
@@ -2031,7 +2029,7 @@ static void writexref(fz_context *ctx, pdf_document *doc, pdf_write_state *opts,
}
if (main_xref_offset != 0)
{
- nobj = pdf_new_int(ctx, doc, main_xref_offset);
+ nobj = pdf_new_int(ctx, main_xref_offset);
pdf_dict_put_drop(ctx, trailer, PDF_NAME(Prev), nobj);
}
}
@@ -2893,7 +2891,7 @@ change_identity(fz_context *ctx, pdf_document *doc)
/* Maybe recalculate this in future. For now, just change the second one. */
fz_memrnd(ctx, rnd, 16);
- str = pdf_new_string(ctx, doc, (char *)rnd, 16);
+ str = pdf_new_string(ctx, (char *)rnd, 16);
pdf_array_put_drop(ctx, identity, 1, str);
}
diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c
index a9dada66..7aaec51e 100644
--- a/source/pdf/pdf-xref.c
+++ b/source/pdf/pdf-xref.c
@@ -1955,7 +1955,7 @@ object_updated:
if (x->type == 'f')
{
- x->obj = pdf_new_null(ctx, doc);
+ x->obj = PDF_NULL;
}
else if (x->type == 'n')
{
diff --git a/source/tools/murun.c b/source/tools/murun.c
index 03e55606..e051be44 100644
--- a/source/tools/murun.c
+++ b/source/tools/murun.c
@@ -2932,9 +2932,9 @@ static pdf_obj *ffi_toobj(js_State *J, pdf_document *pdf, int idx)
float f = js_tonumber(J, idx);
fz_try(ctx)
if (f == (int)f)
- obj = pdf_new_int(ctx, pdf, f);
+ obj = pdf_new_int(ctx, f);
else
- obj = pdf_new_real(ctx, pdf, f);
+ obj = pdf_new_real(ctx, f);
fz_catch(ctx)
rethrow(J);
return obj;
@@ -2944,29 +2944,20 @@ static pdf_obj *ffi_toobj(js_State *J, pdf_document *pdf, int idx)
const char *s = js_tostring(J, idx);
fz_try(ctx)
if (s[0] == '(' && s[1] != 0)
- obj = pdf_new_string(ctx, pdf, s+1, strlen(s)-2);
+ obj = pdf_new_string(ctx, s+1, strlen(s)-2);
else
- obj = pdf_new_name(ctx, pdf, s);
+ obj = pdf_new_name(ctx, s);
fz_catch(ctx)
rethrow(J);
return obj;
}
if (js_isboolean(J, idx)) {
- int b = js_toboolean(J, idx);
- fz_try(ctx)
- obj = pdf_new_bool(ctx, pdf, b);
- fz_catch(ctx)
- rethrow(J);
- return obj;
+ return js_toboolean(J, idx) ? PDF_TRUE : PDF_FALSE;
}
if (js_isnull(J, idx)) {
- fz_try(ctx)
- obj = pdf_new_null(ctx, pdf);
- fz_catch(ctx)
- rethrow(J);
- return obj;
+ return PDF_NULL;
}
if (js_isarray(J, idx)) {
@@ -3398,37 +3389,22 @@ static void ffi_PDFDocument_save(js_State *J)
static void ffi_PDFDocument_newNull(js_State *J)
{
- fz_context *ctx = js_getcontext(J);
- pdf_document *pdf = js_touserdata(J, 0, "pdf_document");
- pdf_obj *obj = NULL;
- fz_try(ctx)
- obj = pdf_new_null(ctx, pdf);
- fz_catch(ctx)
- rethrow(J);
- ffi_pushobj(J, obj);
+ ffi_pushobj(J, PDF_NULL);
}
static void ffi_PDFDocument_newBoolean(js_State *J)
{
- fz_context *ctx = js_getcontext(J);
- pdf_document *pdf = js_touserdata(J, 0, "pdf_document");
int val = js_toboolean(J, 1);
- pdf_obj *obj = NULL;
- fz_try(ctx)
- obj = pdf_new_bool(ctx, pdf, val);
- fz_catch(ctx)
- rethrow(J);
- ffi_pushobj(J, obj);
+ ffi_pushobj(J, val ? PDF_TRUE : PDF_FALSE);
}
static void ffi_PDFDocument_newInteger(js_State *J)
{
fz_context *ctx = js_getcontext(J);
- pdf_document *pdf = js_touserdata(J, 0, "pdf_document");
int val = js_tointeger(J, 1);
pdf_obj *obj = NULL;
fz_try(ctx)
- obj = pdf_new_int(ctx, pdf, val);
+ obj = pdf_new_int(ctx, val);
fz_catch(ctx)
rethrow(J);
ffi_pushobj(J, obj);
@@ -3437,11 +3413,10 @@ static void ffi_PDFDocument_newInteger(js_State *J)
static void ffi_PDFDocument_newReal(js_State *J)
{
fz_context *ctx = js_getcontext(J);
- pdf_document *pdf = js_touserdata(J, 0, "pdf_document");
float val = js_tonumber(J, 1);
pdf_obj *obj = NULL;
fz_try(ctx)
- obj = pdf_new_real(ctx, pdf, val);
+ obj = pdf_new_real(ctx, val);
fz_catch(ctx)
rethrow(J);
ffi_pushobj(J, obj);
@@ -3450,12 +3425,11 @@ static void ffi_PDFDocument_newReal(js_State *J)
static void ffi_PDFDocument_newString(js_State *J)
{
fz_context *ctx = js_getcontext(J);
- pdf_document *pdf = js_touserdata(J, 0, "pdf_document");
const char *val = js_tostring(J, 1);
pdf_obj *obj = NULL;
fz_try(ctx)
- obj = pdf_new_text_string(ctx, pdf, val);
+ obj = pdf_new_text_string(ctx, val);
fz_catch(ctx)
rethrow(J);
ffi_pushobj(J, obj);
@@ -3464,7 +3438,6 @@ static void ffi_PDFDocument_newString(js_State *J)
static void ffi_PDFDocument_newByteString(js_State *J)
{
fz_context *ctx = js_getcontext(J);
- pdf_document *pdf = js_touserdata(J, 0, "pdf_document");
int n, i;
char *buf;
pdf_obj *obj = NULL;
@@ -3490,7 +3463,7 @@ static void ffi_PDFDocument_newByteString(js_State *J)
js_endtry(J);
fz_try(ctx)
- obj = pdf_new_string(ctx, pdf, buf, n);
+ obj = pdf_new_string(ctx, buf, n);
fz_always(ctx)
fz_free(ctx, buf);
fz_catch(ctx)
@@ -3501,11 +3474,10 @@ static void ffi_PDFDocument_newByteString(js_State *J)
static void ffi_PDFDocument_newName(js_State *J)
{
fz_context *ctx = js_getcontext(J);
- pdf_document *pdf = js_touserdata(J, 0, "pdf_document");
const char *val = js_tostring(J, 1);
pdf_obj *obj = NULL;
fz_try(ctx)
- obj = pdf_new_name(ctx, pdf, val);
+ obj = pdf_new_name(ctx, val);
fz_catch(ctx)
rethrow(J);
ffi_pushobj(J, obj);