summaryrefslogtreecommitdiff
path: root/source/pdf
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-06-24 22:03:54 +0100
committerRobin Watts <robin.watts@artifex.com>2013-06-25 10:11:18 +0100
commit997902cd2a0d46404ff4fe09a7380410d1499c5a (patch)
treeded41aa535d7445807aea17a364f993fb8603729 /source/pdf
parent07dd8540ae72b0e7be64d04c38d8c19b83d184b6 (diff)
downloadmupdf-997902cd2a0d46404ff4fe09a7380410d1499c5a.tar.xz
Rid the world of "pdf_document *xref".
For historical reasons lots of the code uses "xref" when talking about a pdf document. Now pdf_xref is a separate type this has become confusing, so replace 'xref' with 'doc' for clarity.
Diffstat (limited to 'source/pdf')
-rw-r--r--source/pdf/pdf-annot.c98
-rw-r--r--source/pdf/pdf-cmap-load.c8
-rw-r--r--source/pdf/pdf-colorspace.c50
-rw-r--r--source/pdf/pdf-crypt.c52
-rw-r--r--source/pdf/pdf-font.c68
-rw-r--r--source/pdf/pdf-function.c28
-rw-r--r--source/pdf/pdf-image.c38
-rw-r--r--source/pdf/pdf-interpret.c74
-rw-r--r--source/pdf/pdf-nametree.c20
-rw-r--r--source/pdf/pdf-outline.c18
-rw-r--r--source/pdf/pdf-page.c130
-rw-r--r--source/pdf/pdf-parse.c16
-rw-r--r--source/pdf/pdf-pattern.c4
-rw-r--r--source/pdf/pdf-repair.c28
-rw-r--r--source/pdf/pdf-shade.c80
-rw-r--r--source/pdf/pdf-stream.c156
-rw-r--r--source/pdf/pdf-type3.c16
-rw-r--r--source/pdf/pdf-unicode.c8
-rw-r--r--source/pdf/pdf-write.c246
-rw-r--r--source/pdf/pdf-xobject.c6
-rw-r--r--source/pdf/pdf-xref.c310
21 files changed, 727 insertions, 727 deletions
diff --git a/source/pdf/pdf-annot.c b/source/pdf/pdf-annot.c
index 6d2d60fd..a46f67b7 100644
--- a/source/pdf/pdf-annot.c
+++ b/source/pdf/pdf-annot.c
@@ -3,15 +3,15 @@
#define SMALL_FLOAT (0.00001)
static pdf_obj *
-resolve_dest_rec(pdf_document *xref, pdf_obj *dest, int depth)
+resolve_dest_rec(pdf_document *doc, pdf_obj *dest, int depth)
{
if (depth > 10) /* Arbitrary to avoid infinite recursion */
return NULL;
if (pdf_is_name(dest) || pdf_is_string(dest))
{
- dest = pdf_lookup_dest(xref, dest);
- return resolve_dest_rec(xref, dest, depth+1);
+ dest = pdf_lookup_dest(doc, dest);
+ return resolve_dest_rec(doc, dest, depth+1);
}
else if (pdf_is_array(dest))
@@ -22,7 +22,7 @@ resolve_dest_rec(pdf_document *xref, pdf_obj *dest, int depth)
else if (pdf_is_dict(dest))
{
dest = pdf_dict_gets(dest, "D");
- return resolve_dest_rec(xref, dest, depth+1);
+ return resolve_dest_rec(doc, dest, depth+1);
}
else if (pdf_is_indirect(dest))
@@ -32,13 +32,13 @@ resolve_dest_rec(pdf_document *xref, pdf_obj *dest, int depth)
}
static pdf_obj *
-resolve_dest(pdf_document *xref, pdf_obj *dest)
+resolve_dest(pdf_document *doc, pdf_obj *dest)
{
- return resolve_dest_rec(xref, dest, 0);
+ return resolve_dest_rec(doc, dest, 0);
}
fz_link_dest
-pdf_parse_link_dest(pdf_document *xref, pdf_obj *dest)
+pdf_parse_link_dest(pdf_document *doc, pdf_obj *dest)
{
fz_link_dest ld;
pdf_obj *obj;
@@ -51,7 +51,7 @@ pdf_parse_link_dest(pdf_document *xref, pdf_obj *dest)
int t_from_2 = 0;
int z_from_4 = 0;
- dest = resolve_dest(xref, dest);
+ dest = resolve_dest(doc, dest);
if (dest == NULL || !pdf_is_array(dest))
{
ld.kind = FZ_LINK_NONE;
@@ -61,7 +61,7 @@ pdf_parse_link_dest(pdf_document *xref, pdf_obj *dest)
if (pdf_is_int(obj))
ld.ld.gotor.page = pdf_to_int(obj);
else
- ld.ld.gotor.page = pdf_lookup_page_number(xref, obj);
+ ld.ld.gotor.page = pdf_lookup_page_number(doc, obj);
ld.kind = FZ_LINK_GOTO;
ld.ld.gotor.flags = 0;
@@ -193,13 +193,13 @@ pdf_parse_link_dest(pdf_document *xref, pdf_obj *dest)
}
static char *
-pdf_parse_file_spec(pdf_document *xref, pdf_obj *file_spec)
+pdf_parse_file_spec(pdf_document *doc, pdf_obj *file_spec)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
pdf_obj *filename;
if (pdf_is_string(file_spec))
- return pdf_to_utf8(xref, file_spec);
+ return pdf_to_utf8(doc, file_spec);
if (pdf_is_dict(file_spec)) {
filename = pdf_dict_gets(file_spec, "UF");
@@ -212,7 +212,7 @@ pdf_parse_file_spec(pdf_document *xref, pdf_obj *file_spec)
if (!filename)
filename = pdf_dict_gets(file_spec, "DOS");
- return pdf_to_utf8(xref, filename);
+ return pdf_to_utf8(doc, filename);
}
fz_warn(ctx, "cannot parse file specification");
@@ -220,11 +220,11 @@ pdf_parse_file_spec(pdf_document *xref, pdf_obj *file_spec)
}
fz_link_dest
-pdf_parse_action(pdf_document *xref, pdf_obj *action)
+pdf_parse_action(pdf_document *doc, pdf_obj *action)
{
fz_link_dest ld;
pdf_obj *obj, *dest;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
UNUSED(ctx);
@@ -237,46 +237,46 @@ pdf_parse_action(pdf_document *xref, pdf_obj *action)
if (!strcmp(pdf_to_name(obj), "GoTo"))
{
dest = pdf_dict_gets(action, "D");
- ld = pdf_parse_link_dest(xref, dest);
+ ld = pdf_parse_link_dest(doc, dest);
}
else if (!strcmp(pdf_to_name(obj), "URI"))
{
ld.kind = FZ_LINK_URI;
ld.ld.uri.is_map = pdf_to_bool(pdf_dict_gets(action, "IsMap"));
- ld.ld.uri.uri = pdf_to_utf8(xref, pdf_dict_gets(action, "URI"));
+ ld.ld.uri.uri = pdf_to_utf8(doc, pdf_dict_gets(action, "URI"));
}
else if (!strcmp(pdf_to_name(obj), "Launch"))
{
ld.kind = FZ_LINK_LAUNCH;
dest = pdf_dict_gets(action, "F");
- ld.ld.launch.file_spec = pdf_parse_file_spec(xref, dest);
+ ld.ld.launch.file_spec = pdf_parse_file_spec(doc, dest);
ld.ld.launch.new_window = pdf_to_int(pdf_dict_gets(action, "NewWindow"));
}
else if (!strcmp(pdf_to_name(obj), "Named"))
{
ld.kind = FZ_LINK_NAMED;
- ld.ld.named.named = pdf_to_utf8(xref, pdf_dict_gets(action, "N"));
+ ld.ld.named.named = pdf_to_utf8(doc, pdf_dict_gets(action, "N"));
}
else if (!strcmp(pdf_to_name(obj), "GoToR"))
{
dest = pdf_dict_gets(action, "D");
- ld = pdf_parse_link_dest(xref, dest);
+ ld = pdf_parse_link_dest(doc, dest);
ld.kind = FZ_LINK_GOTOR;
dest = pdf_dict_gets(action, "F");
- ld.ld.gotor.file_spec = pdf_parse_file_spec(xref, dest);
+ ld.ld.gotor.file_spec = pdf_parse_file_spec(doc, dest);
ld.ld.gotor.new_window = pdf_to_int(pdf_dict_gets(action, "NewWindow"));
}
return ld;
}
static fz_link *
-pdf_load_link(pdf_document *xref, pdf_obj *dict, const fz_matrix *page_ctm)
+pdf_load_link(pdf_document *doc, pdf_obj *dict, const fz_matrix *page_ctm)
{
pdf_obj *dest = NULL;
pdf_obj *action;
pdf_obj *obj;
fz_rect bbox;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_link_dest ld;
obj = pdf_dict_gets(dict, "Rect");
@@ -290,8 +290,8 @@ pdf_load_link(pdf_document *xref, pdf_obj *dict, const fz_matrix *page_ctm)
obj = pdf_dict_gets(dict, "Dest");
if (obj)
{
- dest = resolve_dest(xref, obj);
- ld = pdf_parse_link_dest(xref, dest);
+ dest = resolve_dest(doc, obj);
+ ld = pdf_parse_link_dest(doc, dest);
}
else
{
@@ -300,7 +300,7 @@ pdf_load_link(pdf_document *xref, pdf_obj *dict, const fz_matrix *page_ctm)
if (!action)
action = pdf_dict_getsa(pdf_dict_gets(dict, "AA"), "U", "D");
- ld = pdf_parse_action(xref, action);
+ ld = pdf_parse_action(doc, action);
}
if (ld.kind == FZ_LINK_NONE)
return NULL;
@@ -308,7 +308,7 @@ pdf_load_link(pdf_document *xref, pdf_obj *dict, const fz_matrix *page_ctm)
}
fz_link *
-pdf_load_link_annots(pdf_document *xref, pdf_obj *annots, const fz_matrix *page_ctm)
+pdf_load_link_annots(pdf_document *doc, pdf_obj *annots, const fz_matrix *page_ctm)
{
fz_link *link, *head, *tail;
pdf_obj *obj;
@@ -320,12 +320,12 @@ pdf_load_link_annots(pdf_document *xref, pdf_obj *annots, const fz_matrix *page_
n = pdf_array_len(annots);
for (i = 0; i < n; i++)
{
- fz_try(xref->ctx)
+ fz_try(doc->ctx)
{
obj = pdf_array_get(annots, i);
- link = pdf_load_link(xref, obj, page_ctm);
+ link = pdf_load_link(doc, obj, page_ctm);
}
- fz_catch(xref->ctx)
+ fz_catch(doc->ctx)
{
/* FIXME: TryLater */
link = NULL;
@@ -475,12 +475,12 @@ static const char *annot_type_str(fz_annot_type type)
}
pdf_annot *
-pdf_load_annots(pdf_document *xref, pdf_obj *annots, pdf_page *page)
+pdf_load_annots(pdf_document *doc, pdf_obj *annots, pdf_page *page)
{
pdf_annot *annot, *head, *tail, **itr;
pdf_obj *obj, *ap, *as, *n, *rect;
int i, len, is_dict;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_var(annot);
fz_var(itr);
@@ -522,12 +522,12 @@ pdf_load_annots(pdf_document *xref, pdf_obj *annots, pdf_page *page)
fz_try(ctx)
{
- pdf_hotspot *hp = &xref->hotspot;
+ pdf_hotspot *hp = &doc->hotspot;
n = NULL;
- if (xref->update_appearance)
- xref->update_appearance(xref, annot);
+ if (doc->update_appearance)
+ doc->update_appearance(doc, annot);
obj = annot->obj;
rect = pdf_dict_gets(obj, "Rect");
@@ -549,7 +549,7 @@ pdf_load_annots(pdf_document *xref, pdf_obj *annots, pdf_page *page)
n = pdf_dict_gets(ap, "N"); /* normal state */
/* lookup current state in sub-dictionary */
- if (!pdf_is_stream(xref, pdf_to_num(n), pdf_to_gen(n)))
+ if (!pdf_is_stream(doc, pdf_to_num(n), pdf_to_gen(n)))
n = pdf_dict_get(n, as);
pdf_to_rect(ctx, rect, &annot->rect);
@@ -557,17 +557,17 @@ pdf_load_annots(pdf_document *xref, pdf_obj *annots, pdf_page *page)
fz_transform_rect(&annot->pagerect, &page->ctm);
annot->ap = NULL;
annot->annot_type = pdf_annot_obj_type(obj);
- annot->widget_type = annot->annot_type == FZ_ANNOT_WIDGET ? pdf_field_type(xref, obj) : PDF_WIDGET_TYPE_NOT_WIDGET;
+ annot->widget_type = annot->annot_type == FZ_ANNOT_WIDGET ? pdf_field_type(doc, obj) : PDF_WIDGET_TYPE_NOT_WIDGET;
- if (pdf_is_stream(xref, pdf_to_num(n), pdf_to_gen(n)))
+ if (pdf_is_stream(doc, pdf_to_num(n), pdf_to_gen(n)))
{
- annot->ap = pdf_load_xobject(xref, n);
+ annot->ap = pdf_load_xobject(doc, n);
pdf_transform_annot(annot);
annot->ap_iteration = annot->ap->iteration;
}
- if (obj == xref->focus_obj)
- xref->focus = annot;
+ if (obj == doc->focus_obj)
+ doc->focus = annot;
/* Move to next item in the linked list */
itr = &annot->next;
@@ -587,13 +587,13 @@ pdf_load_annots(pdf_document *xref, pdf_obj *annots, pdf_page *page)
}
void
-pdf_update_annot(pdf_document *xref, pdf_annot *annot)
+pdf_update_annot(pdf_document *doc, pdf_annot *annot)
{
pdf_obj *obj, *ap, *as, *n;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
- if (xref->update_appearance)
- xref->update_appearance(xref, annot);
+ if (doc->update_appearance)
+ doc->update_appearance(doc, annot);
obj = annot->obj;
@@ -602,7 +602,7 @@ pdf_update_annot(pdf_document *xref, pdf_annot *annot)
if (pdf_is_dict(ap))
{
- pdf_hotspot *hp = &xref->hotspot;
+ pdf_hotspot *hp = &doc->hotspot;
n = NULL;
@@ -617,17 +617,17 @@ pdf_update_annot(pdf_document *xref, pdf_annot *annot)
n = pdf_dict_gets(ap, "N"); /* normal state */
/* lookup current state in sub-dictionary */
- if (!pdf_is_stream(xref, pdf_to_num(n), pdf_to_gen(n)))
+ if (!pdf_is_stream(doc, pdf_to_num(n), pdf_to_gen(n)))
n = pdf_dict_get(n, as);
pdf_drop_xobject(ctx, annot->ap);
annot->ap = NULL;
- if (pdf_is_stream(xref, pdf_to_num(n), pdf_to_gen(n)))
+ if (pdf_is_stream(doc, pdf_to_num(n), pdf_to_gen(n)))
{
fz_try(ctx)
{
- annot->ap = pdf_load_xobject(xref, n);
+ annot->ap = pdf_load_xobject(doc, n);
pdf_transform_annot(annot);
annot->ap_iteration = annot->ap->iteration;
}
diff --git a/source/pdf/pdf-cmap-load.c b/source/pdf/pdf-cmap-load.c
index 5fcae15d..64dd0e12 100644
--- a/source/pdf/pdf-cmap-load.c
+++ b/source/pdf/pdf-cmap-load.c
@@ -15,14 +15,14 @@ pdf_cmap_size(fz_context *ctx, pdf_cmap *cmap)
* Load CMap stream in PDF file
*/
pdf_cmap *
-pdf_load_embedded_cmap(pdf_document *xref, pdf_obj *stmobj)
+pdf_load_embedded_cmap(pdf_document *doc, pdf_obj *stmobj)
{
fz_stream *file = NULL;
pdf_cmap *cmap = NULL;
pdf_cmap *usecmap;
pdf_obj *wmode;
pdf_obj *obj = NULL;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
int phase = 0;
fz_var(phase);
@@ -40,7 +40,7 @@ pdf_load_embedded_cmap(pdf_document *xref, pdf_obj *stmobj)
fz_try(ctx)
{
- file = pdf_open_stream(xref, pdf_to_num(stmobj), pdf_to_gen(stmobj));
+ file = pdf_open_stream(doc, pdf_to_num(stmobj), pdf_to_gen(stmobj));
phase = 1;
cmap = pdf_load_cmap(ctx, file);
phase = 2;
@@ -61,7 +61,7 @@ pdf_load_embedded_cmap(pdf_document *xref, pdf_obj *stmobj)
{
phase = 3;
pdf_obj_mark(obj);
- usecmap = pdf_load_embedded_cmap(xref, obj);
+ usecmap = pdf_load_embedded_cmap(doc, obj);
pdf_obj_unmark(obj);
phase = 4;
pdf_set_usecmap(ctx, cmap, usecmap);
diff --git a/source/pdf/pdf-colorspace.c b/source/pdf/pdf-colorspace.c
index 84b3e847..0d312ac9 100644
--- a/source/pdf/pdf-colorspace.c
+++ b/source/pdf/pdf-colorspace.c
@@ -3,7 +3,7 @@
/* ICCBased */
static fz_colorspace *
-load_icc_based(pdf_document *xref, pdf_obj *dict)
+load_icc_based(pdf_document *doc, pdf_obj *dict)
{
int n;
@@ -11,12 +11,12 @@ load_icc_based(pdf_document *xref, pdf_obj *dict)
switch (n)
{
- case 1: return fz_device_gray(xref->ctx);
- case 3: return fz_device_rgb(xref->ctx);
- case 4: return fz_device_cmyk(xref->ctx);
+ case 1: return fz_device_gray(doc->ctx);
+ case 3: return fz_device_rgb(doc->ctx);
+ case 4: return fz_device_cmyk(doc->ctx);
}
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "syntaxerror: ICCBased must have 1, 3 or 4 components");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "syntaxerror: ICCBased must have 1, 3 or 4 components");
return NULL; /* Stupid MSVC */
}
@@ -90,11 +90,11 @@ free_separation(fz_context *ctx, fz_colorspace *cs)
}
static fz_colorspace *
-load_separation(pdf_document *xref, pdf_obj *array)
+load_separation(pdf_document *doc, pdf_obj *array)
{
fz_colorspace *cs;
struct separation *sep = NULL;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
pdf_obj *nameobj = pdf_array_get(array, 1);
pdf_obj *baseobj = pdf_array_get(array, 2);
pdf_obj *tintobj = pdf_array_get(array, 3);
@@ -113,11 +113,11 @@ load_separation(pdf_document *xref, pdf_obj *array)
if (n > FZ_MAX_COLORS)
fz_throw(ctx, FZ_ERROR_GENERIC, "too many components in colorspace");
- base = pdf_load_colorspace(xref, baseobj);
+ base = pdf_load_colorspace(doc, baseobj);
fz_try(ctx)
{
- tint = pdf_load_function(xref, tintobj, n, base->n);
+ tint = pdf_load_function(doc, tintobj, n, base->n);
/* RJW: fz_drop_colorspace(ctx, base);
* "cannot load tint function (%d %d R)", pdf_to_num(tintobj), pdf_to_gen(tintobj) */
@@ -143,9 +143,9 @@ load_separation(pdf_document *xref, pdf_obj *array)
}
static fz_colorspace *
-load_indexed(pdf_document *xref, pdf_obj *array)
+load_indexed(pdf_document *doc, pdf_obj *array)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
pdf_obj *baseobj = pdf_array_get(array, 1);
pdf_obj *highobj = pdf_array_get(array, 2);
pdf_obj *lookupobj = pdf_array_get(array, 3);
@@ -158,7 +158,7 @@ load_indexed(pdf_document *xref, pdf_obj *array)
fz_try(ctx)
{
- base = pdf_load_colorspace(xref, baseobj);
+ base = pdf_load_colorspace(doc, baseobj);
high = pdf_to_int(highobj);
high = fz_clampi(high, 0, 255);
@@ -179,7 +179,7 @@ load_indexed(pdf_document *xref, pdf_obj *array)
fz_try(ctx)
{
- file = pdf_open_stream(xref, pdf_to_num(lookupobj), pdf_to_gen(lookupobj));
+ file = pdf_open_stream(doc, pdf_to_num(lookupobj), pdf_to_gen(lookupobj));
i = fz_read(file, lookup, n);
}
fz_always(ctx)
@@ -211,9 +211,9 @@ load_indexed(pdf_document *xref, pdf_obj *array)
/* Parse and create colorspace from PDF object */
static fz_colorspace *
-pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj)
+pdf_load_colorspace_imp(pdf_document *doc, pdf_obj *obj)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
if (pdf_obj_marked(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "Recursion in colorspace definition");
@@ -274,18 +274,18 @@ pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj)
{
pdf_obj_mark(obj);
if (!strcmp(str, "ICCBased"))
- cs = load_icc_based(xref, pdf_array_get(obj, 1));
+ cs = load_icc_based(doc, pdf_array_get(obj, 1));
else if (!strcmp(str, "Indexed"))
- cs = load_indexed(xref, obj);
+ cs = load_indexed(doc, obj);
else if (!strcmp(str, "I"))
- cs = load_indexed(xref, obj);
+ cs = load_indexed(doc, obj);
else if (!strcmp(str, "Separation"))
- cs = load_separation(xref, obj);
+ cs = load_separation(doc, obj);
else if (!strcmp(str, "DeviceN"))
- cs = load_separation(xref, obj);
+ cs = load_separation(doc, obj);
else if (!strcmp(str, "Pattern"))
{
pdf_obj *pobj;
@@ -297,7 +297,7 @@ pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj)
break;
}
- cs = pdf_load_colorspace(xref, pobj);
+ cs = pdf_load_colorspace(doc, pobj);
}
else
fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: unknown colorspace %s", str);
@@ -315,14 +315,14 @@ pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj)
}
}
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "syntaxerror: could not parse color space (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "syntaxerror: could not parse color space (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
return NULL; /* Stupid MSVC */
}
fz_colorspace *
-pdf_load_colorspace(pdf_document *xref, pdf_obj *obj)
+pdf_load_colorspace(pdf_document *doc, pdf_obj *obj)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_colorspace *cs;
if ((cs = pdf_find_item(ctx, fz_free_colorspace_imp, obj)))
@@ -330,7 +330,7 @@ pdf_load_colorspace(pdf_document *xref, pdf_obj *obj)
return cs;
}
- cs = pdf_load_colorspace_imp(xref, obj);
+ cs = pdf_load_colorspace_imp(doc, obj);
pdf_store_item(ctx, obj, cs, cs->size);
diff --git a/source/pdf/pdf-crypt.c b/source/pdf/pdf-crypt.c
index 5128473c..c1a4a52c 100644
--- a/source/pdf/pdf-crypt.c
+++ b/source/pdf/pdf-crypt.c
@@ -724,24 +724,24 @@ static void pdf_saslprep_from_utf8(char *password, const char *utf8, int n)
}
int
-pdf_authenticate_password(pdf_document *xref, const char *pwd_utf8)
+pdf_authenticate_password(pdf_document *doc, const char *pwd_utf8)
{
char password[2048];
- if (xref->crypt)
+ if (doc->crypt)
{
password[0] = 0;
if (pwd_utf8)
{
- if (xref->crypt->r <= 4)
+ if (doc->crypt->r <= 4)
pdf_docenc_from_utf8(password, pwd_utf8, sizeof password);
else
pdf_saslprep_from_utf8(password, pwd_utf8, sizeof password);
}
- if (pdf_authenticate_user_password(xref->ctx, xref->crypt, (unsigned char *)password, strlen(password)))
+ if (pdf_authenticate_user_password(doc->ctx, doc->crypt, (unsigned char *)password, strlen(password)))
return 1;
- if (pdf_authenticate_owner_password(xref->ctx, xref->crypt, (unsigned char *)password, strlen(password)))
+ if (pdf_authenticate_owner_password(doc->ctx, doc->crypt, (unsigned char *)password, strlen(password)))
return 1;
return 0;
}
@@ -749,52 +749,52 @@ pdf_authenticate_password(pdf_document *xref, const char *pwd_utf8)
}
int
-pdf_needs_password(pdf_document *xref)
+pdf_needs_password(pdf_document *doc)
{
- if (!xref->crypt)
+ if (!doc->crypt)
return 0;
- if (pdf_authenticate_password(xref, ""))
+ if (pdf_authenticate_password(doc, ""))
return 0;
return 1;
}
int
-pdf_has_permission(pdf_document *xref, int p)
+pdf_has_permission(pdf_document *doc, int p)
{
- if (!xref->crypt)
+ if (!doc->crypt)
return 1;
- return xref->crypt->p & p;
+ return doc->crypt->p & p;
}
unsigned char *
-pdf_crypt_key(pdf_document *xref)
+pdf_crypt_key(pdf_document *doc)
{
- if (xref->crypt)
- return xref->crypt->key;
+ if (doc->crypt)
+ return doc->crypt->key;
return NULL;
}
int
-pdf_crypt_version(pdf_document *xref)
+pdf_crypt_version(pdf_document *doc)
{
- if (xref->crypt)
- return xref->crypt->v;
+ if (doc->crypt)
+ return doc->crypt->v;
return 0;
}
-int pdf_crypt_revision(pdf_document *xref)
+int pdf_crypt_revision(pdf_document *doc)
{
- if (xref->crypt)
- return xref->crypt->r;
+ if (doc->crypt)
+ return doc->crypt->r;
return 0;
}
char *
-pdf_crypt_method(pdf_document *xref)
+pdf_crypt_method(pdf_document *doc)
{
- if (xref->crypt)
+ if (doc->crypt)
{
- switch (xref->crypt->strf.method)
+ switch (doc->crypt->strf.method)
{
case PDF_CRYPT_NONE: return "None";
case PDF_CRYPT_RC4: return "RC4";
@@ -807,10 +807,10 @@ pdf_crypt_method(pdf_document *xref)
}
int
-pdf_crypt_length(pdf_document *xref)
+pdf_crypt_length(pdf_document *doc)
{
- if (xref->crypt)
- return xref->crypt->length;
+ if (doc->crypt)
+ return doc->crypt->length;
return 0;
}
diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c
index 1c2beb7b..2c18d96a 100644
--- a/source/pdf/pdf-font.c
+++ b/source/pdf/pdf-font.c
@@ -4,7 +4,7 @@
#include FT_FREETYPE_H
#include FT_XFREE86_H
-static void pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *xref, pdf_obj *dict, char *collection, char *basefont, int iscidfont);
+static void pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *doc, pdf_obj *dict, char *collection, char *basefont, int iscidfont);
static char *base_font_names[][10] =
{
@@ -271,14 +271,14 @@ pdf_load_system_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontname, c
}
static void
-pdf_load_embedded_font(pdf_document *xref, pdf_font_desc *fontdesc, char *fontname, pdf_obj *stmref)
+pdf_load_embedded_font(pdf_document *doc, pdf_font_desc *fontdesc, char *fontname, pdf_obj *stmref)
{
fz_buffer *buf;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_try(ctx)
{
- buf = pdf_load_stream(xref, pdf_to_num(stmref), pdf_to_gen(stmref));
+ buf = pdf_load_stream(doc, pdf_to_num(stmref), pdf_to_gen(stmref));
}
fz_catch(ctx)
{
@@ -397,7 +397,7 @@ pdf_new_font_desc(fz_context *ctx)
*/
static pdf_font_desc *
-pdf_load_simple_font(pdf_document *xref, pdf_obj *dict)
+pdf_load_simple_font(pdf_document *doc, pdf_obj *dict)
{
pdf_obj *descriptor;
pdf_obj *encoding;
@@ -416,7 +416,7 @@ pdf_load_simple_font(pdf_document *xref, pdf_obj *dict)
int i, k, n;
int fterr;
int has_lock = 0;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_var(fontdesc);
fz_var(etable);
@@ -431,7 +431,7 @@ pdf_load_simple_font(pdf_document *xref, pdf_obj *dict)
descriptor = pdf_dict_gets(dict, "FontDescriptor");
if (descriptor)
- pdf_load_font_descriptor(fontdesc, xref, descriptor, NULL, basefont, 0);
+ pdf_load_font_descriptor(fontdesc, doc, descriptor, NULL, basefont, 0);
else
pdf_load_builtin_font(ctx, fontdesc, basefont);
@@ -458,7 +458,7 @@ pdf_load_simple_font(pdf_document *xref, pdf_obj *dict)
pdf_drop_font(ctx, fontdesc);
fontdesc = NULL;
fontdesc = pdf_new_font_desc(ctx);
- pdf_load_font_descriptor(fontdesc, xref, descriptor, "Adobe-GB1", cp936fonts[i+1], 0);
+ pdf_load_font_descriptor(fontdesc, doc, descriptor, "Adobe-GB1", cp936fonts[i+1], 0);
fontdesc->encoding = pdf_load_system_cmap(ctx, "GBK-EUC-H");
fontdesc->to_unicode = pdf_load_system_cmap(ctx, "Adobe-GB1-UCS2");
fontdesc->to_ttf_cmap = pdf_load_system_cmap(ctx, "Adobe-GB1-UCS2");
@@ -684,7 +684,7 @@ pdf_load_simple_font(pdf_document *xref, pdf_obj *dict)
fz_try(ctx)
{
- pdf_load_to_unicode(xref, fontdesc, estrings, NULL, pdf_dict_gets(dict, "ToUnicode"));
+ pdf_load_to_unicode(doc, fontdesc, estrings, NULL, pdf_dict_gets(dict, "ToUnicode"));
}
fz_catch(ctx)
{
@@ -749,7 +749,7 @@ pdf_load_simple_font(pdf_document *xref, pdf_obj *dict)
*/
static pdf_font_desc *
-load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_unicode)
+load_cid_font(pdf_document *doc, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_unicode)
{
pdf_obj *widths;
pdf_obj *descriptor;
@@ -761,7 +761,7 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_
int i, k, fterr;
pdf_obj *obj;
int dw;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_var(fontdesc);
@@ -802,7 +802,7 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_
descriptor = pdf_dict_gets(dict, "FontDescriptor");
if (!descriptor)
fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: missing font descriptor");
- pdf_load_font_descriptor(fontdesc, xref, descriptor, collection, basefont, 1);
+ pdf_load_font_descriptor(fontdesc, doc, descriptor, collection, basefont, 1);
face = fontdesc->font->ft_face;
kind = ft_kind(face);
@@ -820,7 +820,7 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_
}
else if (pdf_is_indirect(encoding))
{
- fontdesc->encoding = pdf_load_embedded_cmap(xref, encoding);
+ fontdesc->encoding = pdf_load_embedded_cmap(doc, encoding);
}
else
{
@@ -839,7 +839,7 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_
{
fz_buffer *buf;
- buf = pdf_load_stream(xref, pdf_to_num(cidtogidmap), pdf_to_gen(cidtogidmap));
+ buf = pdf_load_stream(doc, pdf_to_num(cidtogidmap), pdf_to_gen(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));
@@ -874,7 +874,7 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_
}
}
- pdf_load_to_unicode(xref, fontdesc, NULL, collection, to_unicode);
+ pdf_load_to_unicode(doc, fontdesc, NULL, collection, to_unicode);
/* If we have an identity encoding, we're supposed to use the glyph ids directly.
* If we only have a substitute font, that won't work.
@@ -990,7 +990,7 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_
}
static pdf_font_desc *
-pdf_load_type0_font(pdf_document *xref, pdf_obj *dict)
+pdf_load_type0_font(pdf_document *doc, pdf_obj *dict)
{
pdf_obj *dfonts;
pdf_obj *dfont;
@@ -1000,7 +1000,7 @@ pdf_load_type0_font(pdf_document *xref, pdf_obj *dict)
dfonts = pdf_dict_gets(dict, "DescendantFonts");
if (!dfonts)
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cid font is missing descendant fonts");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cid font is missing descendant fonts");
dfont = pdf_array_get(dfonts, 0);
@@ -1009,11 +1009,11 @@ pdf_load_type0_font(pdf_document *xref, pdf_obj *dict)
to_unicode = pdf_dict_gets(dict, "ToUnicode");
if (pdf_is_name(subtype) && !strcmp(pdf_to_name(subtype), "CIDFontType0"))
- return load_cid_font(xref, dfont, encoding, to_unicode);
+ return load_cid_font(doc, dfont, encoding, to_unicode);
else if (pdf_is_name(subtype) && !strcmp(pdf_to_name(subtype), "CIDFontType2"))
- return load_cid_font(xref, dfont, encoding, to_unicode);
+ return load_cid_font(doc, dfont, encoding, to_unicode);
else
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "syntaxerror: unknown cid font type");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "syntaxerror: unknown cid font type");
return NULL; /* Stupid MSVC */
}
@@ -1023,12 +1023,12 @@ pdf_load_type0_font(pdf_document *xref, pdf_obj *dict)
*/
static void
-pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *xref, pdf_obj *dict, char *collection, char *basefont, int iscidfont)
+pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *doc, pdf_obj *dict, char *collection, char *basefont, int iscidfont)
{
pdf_obj *obj1, *obj2, *obj3, *obj;
char *fontname, *origname;
FT_Face face;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
/* Prefer BaseFont; don't bother with FontName */
origname = basefont;
@@ -1053,7 +1053,7 @@ pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *xref, pdf_obj *d
{
fz_try(ctx)
{
- pdf_load_embedded_font(xref, fontdesc, fontname, obj);
+ pdf_load_embedded_font(doc, fontdesc, fontname, obj);
}
fz_catch(ctx)
{
@@ -1118,12 +1118,12 @@ pdf_make_width_table(fz_context *ctx, pdf_font_desc *fontdesc)
}
pdf_font_desc *
-pdf_load_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, int nested_depth)
+pdf_load_font(pdf_document *doc, pdf_obj *rdb, pdf_obj *dict, int nested_depth)
{
char *subtype;
pdf_obj *dfonts;
pdf_obj *charprocs;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
pdf_font_desc *fontdesc;
int type3 = 0;
@@ -1137,33 +1137,33 @@ pdf_load_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, int nested_depth)
charprocs = pdf_dict_gets(dict, "CharProcs");
if (subtype && !strcmp(subtype, "Type0"))
- fontdesc = pdf_load_type0_font(xref, dict);
+ fontdesc = pdf_load_type0_font(doc, dict);
else if (subtype && !strcmp(subtype, "Type1"))
- fontdesc = pdf_load_simple_font(xref, dict);
+ fontdesc = pdf_load_simple_font(doc, dict);
else if (subtype && !strcmp(subtype, "MMType1"))
- fontdesc = pdf_load_simple_font(xref, dict);
+ fontdesc = pdf_load_simple_font(doc, dict);
else if (subtype && !strcmp(subtype, "TrueType"))
- fontdesc = pdf_load_simple_font(xref, dict);
+ fontdesc = pdf_load_simple_font(doc, dict);
else if (subtype && !strcmp(subtype, "Type3"))
{
- fontdesc = pdf_load_type3_font(xref, rdb, dict);
+ fontdesc = pdf_load_type3_font(doc, rdb, dict);
type3 = 1;
}
else if (charprocs)
{
fz_warn(ctx, "unknown font format, guessing type3.");
- fontdesc = pdf_load_type3_font(xref, rdb, dict);
+ fontdesc = pdf_load_type3_font(doc, rdb, dict);
type3 = 1;
}
else if (dfonts)
{
fz_warn(ctx, "unknown font format, guessing type0.");
- fontdesc = pdf_load_type0_font(xref, dict);
+ fontdesc = pdf_load_type0_font(doc, dict);
}
else
{
fz_warn(ctx, "unknown font format, guessing type1 or truetype.");
- fontdesc = pdf_load_simple_font(xref, dict);
+ fontdesc = pdf_load_simple_font(doc, dict);
}
/* Save the widths to stretch non-CJK substitute fonts */
@@ -1173,7 +1173,7 @@ pdf_load_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, int nested_depth)
pdf_store_item(ctx, dict, fontdesc, fontdesc->size);
if (type3)
- pdf_load_type3_glyphs(xref, fontdesc, nested_depth);
+ pdf_load_type3_glyphs(doc, fontdesc, nested_depth);
return fontdesc;
}
diff --git a/source/pdf/pdf-function.c b/source/pdf/pdf-function.c
index 4771fbfd..4496a158 100644
--- a/source/pdf/pdf-function.c
+++ b/source/pdf/pdf-function.c
@@ -831,13 +831,13 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr, pdf_lexbuf *buf)
}
static void
-load_postscript_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num, int gen)
+load_postscript_func(pdf_function *func, pdf_document *doc, pdf_obj *dict, int num, int gen)
{
fz_stream *stream = NULL;
int codeptr;
pdf_lexbuf buf;
pdf_token tok;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
int locked = 0;
pdf_lexbuf_init(ctx, &buf, PDF_LEXBUF_SMALL);
@@ -847,7 +847,7 @@ load_postscript_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int
fz_try(ctx)
{
- stream = pdf_open_stream(xref, num, gen);
+ stream = pdf_open_stream(doc, num, gen);
tok = pdf_lex(stream, &buf);
if (tok != PDF_TOK_OPEN_BRACE)
@@ -905,9 +905,9 @@ eval_postscript_func(fz_context *ctx, pdf_function *func, float *in, float *out)
#define MAX_SAMPLE_FUNCTION_SIZE (100 << 20)
static void
-load_sample_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num, int gen)
+load_sample_func(pdf_function *func, pdf_document *doc, pdf_obj *dict, int num, int gen)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_stream *stream;
pdf_obj *obj;
int samplecount;
@@ -982,7 +982,7 @@ load_sample_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num,
func->u.sa.samples = fz_malloc_array(ctx, samplecount, sizeof(float));
func->base.size += samplecount * sizeof(float);
- stream = pdf_open_stream(xref, num, gen);
+ stream = pdf_open_stream(doc, num, gen);
/* read samples */
for (i = 0; i < samplecount; i++)
@@ -1209,9 +1209,9 @@ eval_exponential_func(fz_context *ctx, pdf_function *func, float in, float *out)
*/
static void
-load_stitching_func(pdf_function *func, pdf_document *xref, pdf_obj *dict)
+load_stitching_func(pdf_function *func, pdf_document *doc, pdf_obj *dict)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_function **funcs;
pdf_obj *obj;
pdf_obj *sub;
@@ -1242,7 +1242,7 @@ load_stitching_func(pdf_function *func, pdf_document *xref, pdf_obj *dict)
for (i = 0; i < k; i++)
{
sub = pdf_array_get(obj, i);
- funcs[i] = pdf_load_function(xref, sub, 1, func->base.n);
+ funcs[i] = pdf_load_function(doc, sub, 1, func->base.n);
func->base.size += fz_function_size(funcs[i]);
func->u.st.k ++;
@@ -1616,9 +1616,9 @@ pdf_debug_function(fz_function *func)
#endif
fz_function *
-pdf_load_function(pdf_document *xref, pdf_obj *dict, int in, int out)
+pdf_load_function(pdf_document *doc, pdf_obj *dict, int in, int out)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
pdf_function *func;
pdf_obj *obj;
int i;
@@ -1679,7 +1679,7 @@ pdf_load_function(pdf_document *xref, pdf_obj *dict, int in, int out)
switch (func->type)
{
case SAMPLE:
- load_sample_func(func, xref, dict, pdf_to_num(dict), pdf_to_gen(dict));
+ load_sample_func(func, doc, dict, pdf_to_num(dict), pdf_to_gen(dict));
break;
case EXPONENTIAL:
@@ -1687,11 +1687,11 @@ pdf_load_function(pdf_document *xref, pdf_obj *dict, int in, int out)
break;
case STITCHING:
- load_stitching_func(func, xref, dict);
+ load_stitching_func(func, doc, dict);
break;
case POSTSCRIPT:
- load_postscript_func(func, xref, dict, pdf_to_num(dict), pdf_to_gen(dict));
+ load_postscript_func(func, doc, dict, pdf_to_num(dict), pdf_to_gen(dict));
break;
default:
diff --git a/source/pdf/pdf-image.c b/source/pdf/pdf-image.c
index 719841d5..5d0d59d3 100644
--- a/source/pdf/pdf-image.c
+++ b/source/pdf/pdf-image.c
@@ -1,9 +1,9 @@
#include "mupdf/pdf.h"
-static fz_image *pdf_load_jpx(pdf_document *xref, pdf_obj *dict, int forcemask);
+static fz_image *pdf_load_jpx(pdf_document *doc, pdf_obj *dict, int forcemask);
static fz_image *
-pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *cstm, int forcemask)
+pdf_load_image_imp(pdf_document *doc, pdf_obj *rdb, pdf_obj *dict, fz_stream *cstm, int forcemask)
{
fz_stream *stm = NULL;
fz_image *image = NULL;
@@ -20,7 +20,7 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c
int colorkey[FZ_MAX_COLORS * 2];
int i;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_var(stm);
fz_var(mask);
@@ -31,7 +31,7 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c
/* special case for JPEG2000 images */
if (pdf_is_jpx_image(ctx, dict))
{
- image = pdf_load_jpx(xref, dict, forcemask);
+ image = pdf_load_jpx(doc, dict, forcemask);
if (forcemask)
{
@@ -84,7 +84,7 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c
obj = res;
}
- colorspace = pdf_load_colorspace(xref, obj);
+ colorspace = pdf_load_colorspace(doc, obj);
if (!strcmp(colorspace->name, "Indexed"))
indexed = 1;
@@ -118,7 +118,7 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c
else if (forcemask)
fz_warn(ctx, "Ignoring recursive image soft mask");
else
- mask = (fz_image *)pdf_load_image_imp(xref, rdb, obj, NULL, 1);
+ mask = (fz_image *)pdf_load_image_imp(doc, rdb, obj, NULL, 1);
}
else if (pdf_is_array(obj))
{
@@ -141,7 +141,7 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c
* decode it on demand. */
int num = pdf_to_num(dict);
int gen = pdf_to_gen(dict);
- fz_compressed_buffer *buffer = pdf_load_compressed_stream(xref, num, gen);
+ fz_compressed_buffer *buffer = pdf_load_compressed_stream(doc, num, gen);
image = fz_new_image(ctx, w, h, bpc, colorspace, 96, 96, interpolate, imagemask, decode, usecolorkey ? colorkey : NULL, buffer, mask);
break; /* Out of fz_try */
}
@@ -150,11 +150,11 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c
if (cstm)
{
int stride = (w * n * bpc + 7) / 8;
- stm = pdf_open_inline_stream(xref, dict, stride * h, cstm, NULL);
+ stm = pdf_open_inline_stream(doc, dict, stride * h, cstm, NULL);
}
else
{
- stm = pdf_open_stream(xref, pdf_to_num(dict), pdf_to_gen(dict));
+ stm = pdf_open_stream(doc, pdf_to_num(dict), pdf_to_gen(dict));
}
image = fz_new_image(ctx, w, h, bpc, colorspace, 96, 96, interpolate, imagemask, decode, usecolorkey ? colorkey : NULL, NULL, mask);
@@ -169,9 +169,9 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c
}
fz_image *
-pdf_load_inline_image(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *file)
+pdf_load_inline_image(pdf_document *doc, pdf_obj *rdb, pdf_obj *dict, fz_stream *file)
{
- return (fz_image *)pdf_load_image_imp(xref, rdb, dict, file, 0);
+ return (fz_image *)pdf_load_image_imp(doc, rdb, dict, file, 0);
}
int
@@ -191,13 +191,13 @@ pdf_is_jpx_image(fz_context *ctx, pdf_obj *dict)
}
static fz_image *
-pdf_load_jpx(pdf_document *xref, pdf_obj *dict, int forcemask)
+pdf_load_jpx(pdf_document *doc, pdf_obj *dict, int forcemask)
{
fz_buffer *buf = NULL;
fz_colorspace *colorspace = NULL;
fz_pixmap *img = NULL;
pdf_obj *obj;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
int indexed = 0;
fz_image *mask = NULL;
@@ -206,7 +206,7 @@ pdf_load_jpx(pdf_document *xref, pdf_obj *dict, int forcemask)
fz_var(colorspace);
fz_var(mask);
- buf = pdf_load_stream(xref, pdf_to_num(dict), pdf_to_gen(dict));
+ buf = pdf_load_stream(doc, pdf_to_num(dict), pdf_to_gen(dict));
/* FIXME: We can't handle decode arrays for indexed images currently */
fz_try(ctx)
@@ -214,7 +214,7 @@ pdf_load_jpx(pdf_document *xref, pdf_obj *dict, int forcemask)
obj = pdf_dict_gets(dict, "ColorSpace");
if (obj)
{
- colorspace = pdf_load_colorspace(xref, obj);
+ colorspace = pdf_load_colorspace(doc, obj);
indexed = !strcmp(colorspace->name, "Indexed");
}
@@ -232,7 +232,7 @@ pdf_load_jpx(pdf_document *xref, pdf_obj *dict, int forcemask)
if (forcemask)
fz_warn(ctx, "Ignoring recursive JPX soft mask");
else
- mask = (fz_image *)pdf_load_image_imp(xref, NULL, obj, NULL, 1);
+ mask = (fz_image *)pdf_load_image_imp(doc, NULL, obj, NULL, 1);
}
obj = pdf_dict_getsa(dict, "Decode", "D");
@@ -267,9 +267,9 @@ fz_image_size(fz_context *ctx, fz_image *im)
}
fz_image *
-pdf_load_image(pdf_document *xref, pdf_obj *dict)
+pdf_load_image(pdf_document *doc, pdf_obj *dict)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_image *image;
if ((image = pdf_find_item(ctx, fz_free_image, dict)))
@@ -277,7 +277,7 @@ pdf_load_image(pdf_document *xref, pdf_obj *dict)
return (fz_image *)image;
}
- image = pdf_load_image_imp(xref, NULL, dict, NULL, 0);
+ image = pdf_load_image_imp(doc, NULL, dict, NULL, 0);
pdf_store_item(ctx, dict, image, fz_image_size(ctx, image));
diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c
index 66a92370..aed02317 100644
--- a/source/pdf/pdf-interpret.c
+++ b/source/pdf/pdf-interpret.c
@@ -64,7 +64,7 @@ struct pdf_gstate_s
struct pdf_csi_s
{
fz_device *dev;
- pdf_document *xref;
+ pdf_document *doc;
int nested_depth;
@@ -151,7 +151,7 @@ pdf_is_hidden_ocg(pdf_obj *ocg, pdf_csi *csi, pdf_obj *rdb)
char event_state[16];
pdf_obj *obj, *obj2;
char *type;
- pdf_ocg_descriptor *desc = csi->xref->ocg;
+ pdf_ocg_descriptor *desc = csi->doc->ocg;
fz_context *ctx = csi->dev->ctx;
/* Avoid infinite recursions */
@@ -1072,7 +1072,7 @@ pdf_copy_pattern_gstate(fz_context *ctx, pdf_gstate *gs, const pdf_gstate *old)
}
static pdf_csi *
-pdf_new_csi(pdf_document *xref, fz_device *dev, const fz_matrix *ctm, char *event, fz_cookie *cookie, pdf_gstate *gstate, int nested)
+pdf_new_csi(pdf_document *doc, fz_device *dev, const fz_matrix *ctm, char *event, fz_cookie *cookie, pdf_gstate *gstate, int nested)
{
pdf_csi *csi;
fz_context *ctx = dev->ctx;
@@ -1080,7 +1080,7 @@ pdf_new_csi(pdf_document *xref, fz_device *dev, const fz_matrix *ctm, char *even
csi = fz_malloc_struct(ctx, pdf_csi);
fz_try(ctx)
{
- csi->xref = xref;
+ csi->doc = doc;
csi->dev = dev;
csi->event = event;
@@ -1619,7 +1619,7 @@ pdf_run_extgstate(pdf_csi *csi, pdf_obj *rdb, pdf_obj *extgstate)
gstate->font = NULL;
}
- gstate->font = pdf_load_font(csi->xref, rdb, font, csi->nested_depth);
+ gstate->font = pdf_load_font(csi->doc, rdb, font, csi->nested_depth);
if (!gstate->font)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find font in store");
gstate->size = pdf_to_real(pdf_array_get(val, 1));
@@ -1700,7 +1700,7 @@ pdf_run_extgstate(pdf_csi *csi, pdf_obj *rdb, pdf_obj *extgstate)
group = pdf_dict_gets(val, "G");
if (!group)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load softmask xobject (%d %d R)", pdf_to_num(val), pdf_to_gen(val));
- xobj = pdf_load_xobject(csi->xref, group);
+ xobj = pdf_load_xobject(csi->doc, group);
colorspace = xobj->colorspace;
if (!colorspace)
@@ -1796,7 +1796,7 @@ static void pdf_run_BI(pdf_csi *csi, pdf_obj *rdb, fz_stream *file)
fz_image *img;
pdf_obj *obj;
- obj = pdf_parse_dict(csi->xref, file, &csi->xref->lexbuf.base);
+ obj = pdf_parse_dict(csi->doc, file, &csi->doc->lexbuf.base);
/* read whitespace after ID keyword */
ch = fz_read_byte(file);
@@ -1806,7 +1806,7 @@ static void pdf_run_BI(pdf_csi *csi, pdf_obj *rdb, fz_stream *file)
fz_try(ctx)
{
- img = pdf_load_inline_image(csi->xref, rdb, obj, file);
+ img = pdf_load_inline_image(csi->doc, rdb, obj, file);
}
fz_always(ctx)
{
@@ -1889,7 +1889,7 @@ static void pdf_run_cs_imp(pdf_csi *csi, pdf_obj *rdb, int what)
obj = pdf_dict_gets(dict, csi->name);
if (!obj)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find colorspace resource '%s'", csi->name);
- colorspace = pdf_load_colorspace(csi->xref, obj);
+ colorspace = pdf_load_colorspace(csi->doc, obj);
}
pdf_set_colorspace(csi, what, colorspace);
@@ -1945,7 +1945,7 @@ static void pdf_run_Do(pdf_csi *csi, pdf_obj *rdb)
{
pdf_xobject *xobj;
- xobj = pdf_load_xobject(csi->xref, obj);
+ xobj = pdf_load_xobject(csi->doc, obj);
/* Inherit parent resources, in case this one was empty XXX check where it's loaded */
if (!xobj->resources)
@@ -1969,7 +1969,7 @@ static void pdf_run_Do(pdf_csi *csi, pdf_obj *rdb)
{
if ((csi->dev->hints & FZ_IGNORE_IMAGE) == 0)
{
- fz_image *img = pdf_load_image(csi->xref, obj);
+ fz_image *img = pdf_load_image(csi->doc, obj);
fz_try(ctx)
{
@@ -2108,14 +2108,14 @@ static void pdf_run_SC_imp(pdf_csi *csi, pdf_obj *rdb, int what, pdf_material *m
if (pdf_to_int(patterntype) == 1)
{
pdf_pattern *pat;
- pat = pdf_load_pattern(csi->xref, obj);
+ pat = pdf_load_pattern(csi->doc, obj);
pdf_set_pattern(csi, what, pat, csi->top > 0 ? csi->stack : NULL);
pdf_drop_pattern(ctx, pat);
}
else if (pdf_to_int(patterntype) == 2)
{
fz_shade *shd;
- shd = pdf_load_shading(csi->xref, obj);
+ shd = pdf_load_shading(csi->doc, obj);
pdf_set_shade(csi, what, shd);
fz_drop_shade(ctx, shd);
}
@@ -2191,7 +2191,7 @@ static void pdf_run_Tf(pdf_csi *csi, pdf_obj *rdb)
if (!obj)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find font resource: '%s'", csi->name);
- gstate->font = pdf_load_font(csi->xref, rdb, obj, csi->nested_depth);
+ gstate->font = pdf_load_font(csi->doc, rdb, obj, csi->nested_depth);
}
static void pdf_run_Tr(pdf_csi *csi)
@@ -2476,7 +2476,7 @@ static void pdf_run_sh(pdf_csi *csi, pdf_obj *rdb)
if ((csi->dev->hints & FZ_IGNORE_SHADE) == 0)
{
- shd = pdf_load_shading(csi->xref, obj);
+ shd = pdf_load_shading(csi->doc, obj);
fz_try(ctx)
{
@@ -2783,7 +2783,7 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf)
pdf_drop_obj(csi->obj);
csi->obj = NULL;
}
- csi->obj = pdf_parse_array(csi->xref, file, buf);
+ csi->obj = pdf_parse_array(csi->doc, file, buf);
}
else
{
@@ -2797,7 +2797,7 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf)
pdf_drop_obj(csi->obj);
csi->obj = NULL;
}
- csi->obj = pdf_parse_dict(csi->xref, file, buf);
+ csi->obj = pdf_parse_dict(csi->doc, file, buf);
break;
case PDF_TOK_NAME:
@@ -2835,7 +2835,7 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf)
pdf_drop_obj(csi->obj);
csi->obj = NULL;
}
- csi->obj = pdf_new_string(csi->xref, buf->scratch, buf->len);
+ csi->obj = pdf_new_string(csi->doc, buf->scratch, buf->len);
}
break;
@@ -2921,7 +2921,7 @@ pdf_run_contents_object(pdf_csi *csi, pdf_obj *rdb, pdf_obj *contents)
if (contents == NULL)
return;
- file = pdf_open_contents_stream(csi->xref, contents);
+ file = pdf_open_contents_stream(csi->doc, contents);
fz_try(ctx)
{
pdf_run_contents_stream(csi, rdb, file);
@@ -2960,7 +2960,7 @@ pdf_run_contents_buffer(pdf_csi *csi, pdf_obj *rdb, fz_buffer *contents)
}
}
-static void pdf_run_page_contents_with_usage(pdf_document *xref, pdf_page *page, fz_device *dev, const fz_matrix *ctm, char *event, fz_cookie *cookie)
+static void pdf_run_page_contents_with_usage(pdf_document *doc, pdf_page *page, fz_device *dev, const fz_matrix *ctm, char *event, fz_cookie *cookie)
{
fz_context *ctx = dev->ctx;
pdf_csi *csi;
@@ -2974,7 +2974,7 @@ static void pdf_run_page_contents_with_usage(pdf_document *xref, pdf_page *page,
fz_begin_group(dev, fz_transform_rect(&mediabox, &local_ctm), 1, 0, 0, 1);
}
- csi = pdf_new_csi(xref, dev, &local_ctm, event, cookie, NULL, 0);
+ csi = pdf_new_csi(doc, dev, &local_ctm, event, cookie, NULL, 0);
fz_try(ctx)
{
/* We need to save an extra level here to allow for level 0
@@ -2997,12 +2997,12 @@ static void pdf_run_page_contents_with_usage(pdf_document *xref, pdf_page *page,
fz_end_group(dev);
}
-void pdf_run_page_contents(pdf_document *xref, pdf_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie)
+void pdf_run_page_contents(pdf_document *doc, pdf_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie)
{
- pdf_run_page_contents_with_usage(xref, page, dev, ctm, "View", cookie);
+ pdf_run_page_contents_with_usage(doc, page, dev, ctm, "View", cookie);
}
-static void pdf_run_annot_with_usage(pdf_document *xref, pdf_page *page, pdf_annot *annot, fz_device *dev, const fz_matrix *ctm, char *event, fz_cookie *cookie)
+static void pdf_run_annot_with_usage(pdf_document *doc, pdf_page *page, pdf_annot *annot, fz_device *dev, const fz_matrix *ctm, char *event, fz_cookie *cookie)
{
fz_context *ctx = dev->ctx;
pdf_csi *csi;
@@ -3023,7 +3023,7 @@ static void pdf_run_annot_with_usage(pdf_document *xref, pdf_page *page, pdf_ann
if (!strcmp(event, "View") && (flags & (1 << 5))) /* NoView */
return;
- csi = pdf_new_csi(xref, dev, &local_ctm, event, cookie, NULL, 0);
+ csi = pdf_new_csi(doc, dev, &local_ctm, event, cookie, NULL, 0);
if (!pdf_is_hidden_ocg(pdf_dict_gets(annot->obj, "OC"), csi, page->resources))
{
fz_try(ctx)
@@ -3044,12 +3044,12 @@ static void pdf_run_annot_with_usage(pdf_document *xref, pdf_page *page, pdf_ann
pdf_free_csi(csi);
}
-void pdf_run_annot(pdf_document *xref, pdf_page *page, pdf_annot *annot, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie)
+void pdf_run_annot(pdf_document *doc, pdf_page *page, pdf_annot *annot, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie)
{
- pdf_run_annot_with_usage(xref, page, annot, dev, ctm, "View", cookie);
+ pdf_run_annot_with_usage(doc, page, annot, dev, ctm, "View", cookie);
}
-static void pdf_run_page_annots_with_usage(pdf_document *xref, pdf_page *page, fz_device *dev, const fz_matrix *ctm, char *event, fz_cookie *cookie)
+static void pdf_run_page_annots_with_usage(pdf_document *doc, pdf_page *page, fz_device *dev, const fz_matrix *ctm, char *event, fz_cookie *cookie)
{
pdf_annot *annot;
@@ -3071,28 +3071,28 @@ static void pdf_run_page_annots_with_usage(pdf_document *xref, pdf_page *page, f
cookie->progress++;
}
- pdf_run_annot_with_usage(xref, page, annot, dev, ctm, event, cookie);
+ pdf_run_annot_with_usage(doc, page, annot, dev, ctm, event, cookie);
}
}
void
-pdf_run_page_with_usage(pdf_document *xref, pdf_page *page, fz_device *dev, const fz_matrix *ctm, char *event, fz_cookie *cookie)
+pdf_run_page_with_usage(pdf_document *doc, pdf_page *page, fz_device *dev, const fz_matrix *ctm, char *event, fz_cookie *cookie)
{
- pdf_run_page_contents_with_usage(xref, page, dev, ctm, event, cookie);
- pdf_run_page_annots_with_usage(xref, page, dev, ctm, event, cookie);
+ pdf_run_page_contents_with_usage(doc, page, dev, ctm, event, cookie);
+ pdf_run_page_annots_with_usage(doc, page, dev, ctm, event, cookie);
}
void
-pdf_run_page(pdf_document *xref, pdf_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie)
+pdf_run_page(pdf_document *doc, pdf_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie)
{
- pdf_run_page_with_usage(xref, page, dev, ctm, "View", cookie);
+ pdf_run_page_with_usage(doc, page, dev, ctm, "View", cookie);
}
void
-pdf_run_glyph(pdf_document *xref, pdf_obj *resources, fz_buffer *contents, fz_device *dev, const fz_matrix *ctm, void *gstate, int nested_depth)
+pdf_run_glyph(pdf_document *doc, pdf_obj *resources, fz_buffer *contents, fz_device *dev, const fz_matrix *ctm, void *gstate, int nested_depth)
{
- pdf_csi *csi = pdf_new_csi(xref, dev, ctm, "View", NULL, gstate, nested_depth+1);
- fz_context *ctx = xref->ctx;
+ pdf_csi *csi = pdf_new_csi(doc, dev, ctm, "View", NULL, gstate, nested_depth+1);
+ fz_context *ctx = doc->ctx;
fz_try(ctx)
{
diff --git a/source/pdf/pdf-nametree.c b/source/pdf/pdf-nametree.c
index b67e1931..0be9fdf2 100644
--- a/source/pdf/pdf-nametree.c
+++ b/source/pdf/pdf-nametree.c
@@ -70,22 +70,22 @@ pdf_lookup_name_imp(fz_context *ctx, pdf_obj *node, pdf_obj *needle)
}
pdf_obj *
-pdf_lookup_name(pdf_document *xref, char *which, pdf_obj *needle)
+pdf_lookup_name(pdf_document *doc, char *which, pdf_obj *needle)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
- pdf_obj *root = pdf_dict_gets(pdf_trailer(xref), "Root");
+ pdf_obj *root = pdf_dict_gets(pdf_trailer(doc), "Root");
pdf_obj *names = pdf_dict_gets(root, "Names");
pdf_obj *tree = pdf_dict_gets(names, which);
return pdf_lookup_name_imp(ctx, tree, needle);
}
pdf_obj *
-pdf_lookup_dest(pdf_document *xref, pdf_obj *needle)
+pdf_lookup_dest(pdf_document *doc, pdf_obj *needle)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
- pdf_obj *root = pdf_dict_gets(pdf_trailer(xref), "Root");
+ pdf_obj *root = pdf_dict_gets(pdf_trailer(doc), "Root");
pdf_obj *dests = pdf_dict_gets(root, "Dests");
pdf_obj *names = pdf_dict_gets(root, "Names");
pdf_obj *dest = NULL;
@@ -110,9 +110,9 @@ pdf_lookup_dest(pdf_document *xref, pdf_obj *needle)
}
static void
-pdf_load_name_tree_imp(pdf_obj *dict, pdf_document *xref, pdf_obj *node)
+pdf_load_name_tree_imp(pdf_obj *dict, pdf_document *doc, pdf_obj *node)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
pdf_obj *kids = pdf_dict_gets(node, "Kids");
pdf_obj *names = pdf_dict_gets(node, "Names");
int i;
@@ -123,7 +123,7 @@ pdf_load_name_tree_imp(pdf_obj *dict, pdf_document *xref, pdf_obj *node)
{
int len = pdf_array_len(kids);
for (i = 0; i < len; i++)
- pdf_load_name_tree_imp(dict, xref, pdf_array_get(kids, i));
+ pdf_load_name_tree_imp(dict, doc, pdf_array_get(kids, i));
pdf_obj_unmark(node);
}
@@ -136,7 +136,7 @@ pdf_load_name_tree_imp(pdf_obj *dict, pdf_document *xref, pdf_obj *node)
pdf_obj *val = pdf_array_get(names, i + 1);
if (pdf_is_string(key))
{
- key = pdf_to_utf8_name(xref, key);
+ key = pdf_to_utf8_name(doc, key);
pdf_dict_put(dict, key, val);
pdf_drop_obj(key);
}
diff --git a/source/pdf/pdf-outline.c b/source/pdf/pdf-outline.c
index 584d60ea..e83997b8 100644
--- a/source/pdf/pdf-outline.c
+++ b/source/pdf/pdf-outline.c
@@ -1,9 +1,9 @@
#include "mupdf/pdf.h"
static fz_outline *
-pdf_load_outline_imp(pdf_document *xref, pdf_obj *dict)
+pdf_load_outline_imp(pdf_document *doc, pdf_obj *dict)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_outline *node, **prev, *first;
pdf_obj *obj;
pdf_obj *odict = dict;
@@ -29,16 +29,16 @@ pdf_load_outline_imp(pdf_document *xref, pdf_obj *dict)
obj = pdf_dict_gets(dict, "Title");
if (obj)
- node->title = pdf_to_utf8(xref, obj);
+ node->title = pdf_to_utf8(doc, obj);
if ((obj = pdf_dict_gets(dict, "Dest")))
- node->dest = pdf_parse_link_dest(xref, obj);
+ node->dest = pdf_parse_link_dest(doc, obj);
else if ((obj = pdf_dict_gets(dict, "A")))
- node->dest = pdf_parse_action(xref, obj);
+ node->dest = pdf_parse_action(doc, obj);
obj = pdf_dict_gets(dict, "First");
if (obj)
- node->down = pdf_load_outline_imp(xref, obj);
+ node->down = pdf_load_outline_imp(doc, obj);
dict = pdf_dict_gets(dict, "Next");
}
@@ -58,15 +58,15 @@ pdf_load_outline_imp(pdf_document *xref, pdf_obj *dict)
}
fz_outline *
-pdf_load_outline(pdf_document *xref)
+pdf_load_outline(pdf_document *doc)
{
pdf_obj *root, *obj, *first;
- root = pdf_dict_gets(pdf_trailer(xref), "Root");
+ root = pdf_dict_gets(pdf_trailer(doc), "Root");
obj = pdf_dict_gets(root, "Outlines");
first = pdf_dict_gets(obj, "First");
if (first)
- return pdf_load_outline_imp(xref, first);
+ return pdf_load_outline_imp(doc, first);
return NULL;
}
diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c
index 6150c3e1..12e38b5f 100644
--- a/source/pdf/pdf-page.c
+++ b/source/pdf/pdf-page.c
@@ -41,11 +41,11 @@ struct pdf_page_load_s
};
static void
-pdf_load_page_tree_node(pdf_document *xref, pdf_obj *node, struct info info)
+pdf_load_page_tree_node(pdf_document *doc, pdf_obj *node, struct info info)
{
pdf_obj *dict, *kids, *count;
pdf_obj *obj;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
pdf_page_load *stack = NULL;
int stacklen = -1;
int stackmax = 0;
@@ -101,17 +101,17 @@ pdf_load_page_tree_node(pdf_document *xref, pdf_obj *node, struct info info)
if (info.rotate && !pdf_dict_gets(dict, "Rotate"))
pdf_dict_puts(dict, "Rotate", info.rotate);
- if (xref->page_len == xref->page_cap)
+ if (doc->page_len == doc->page_cap)
{
fz_warn(ctx, "found more pages than expected");
- xref->page_refs = fz_resize_array(ctx, xref->page_refs, xref->page_cap+1, sizeof(pdf_obj*));
- xref->page_objs = fz_resize_array(ctx, xref->page_objs, xref->page_cap+1, sizeof(pdf_obj*));
- xref->page_cap ++;
+ doc->page_refs = fz_resize_array(ctx, doc->page_refs, doc->page_cap+1, sizeof(pdf_obj*));
+ doc->page_objs = fz_resize_array(ctx, doc->page_objs, doc->page_cap+1, sizeof(pdf_obj*));
+ doc->page_cap ++;
}
- xref->page_refs[xref->page_len] = pdf_keep_obj(node);
- xref->page_objs[xref->page_len] = pdf_keep_obj(dict);
- xref->page_len ++;
+ doc->page_refs[doc->page_len] = pdf_keep_obj(node);
+ doc->page_objs[doc->page_len] = pdf_keep_obj(dict);
+ doc->page_len ++;
pdf_obj_unmark(node);
}
}
@@ -146,18 +146,18 @@ pdf_load_page_tree_node(pdf_document *xref, pdf_obj *node, struct info info)
}
static void
-pdf_load_page_tree(pdf_document *xref)
+pdf_load_page_tree(pdf_document *doc)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
pdf_obj *catalog;
pdf_obj *pages;
pdf_obj *count;
struct info info;
- if (xref->page_refs)
+ if (doc->page_refs)
return;
- catalog = pdf_dict_gets(pdf_trailer(xref), "Root");
+ catalog = pdf_dict_gets(pdf_trailer(doc), "Root");
pages = pdf_dict_gets(catalog, "Pages");
count = pdf_dict_gets(pages, "Count");
@@ -166,34 +166,34 @@ pdf_load_page_tree(pdf_document *xref)
if (!pdf_is_int(count) || pdf_to_int(count) < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "missing page count");
- xref->page_cap = pdf_to_int(count);
- xref->page_len = 0;
- xref->page_refs = fz_malloc_array(ctx, xref->page_cap, sizeof(pdf_obj*));
- xref->page_objs = fz_malloc_array(ctx, xref->page_cap, sizeof(pdf_obj*));
+ doc->page_cap = pdf_to_int(count);
+ doc->page_len = 0;
+ doc->page_refs = fz_malloc_array(ctx, doc->page_cap, sizeof(pdf_obj*));
+ doc->page_objs = fz_malloc_array(ctx, doc->page_cap, sizeof(pdf_obj*));
info.resources = NULL;
info.mediabox = NULL;
info.cropbox = NULL;
info.rotate = NULL;
- pdf_load_page_tree_node(xref, pages, info);
+ pdf_load_page_tree_node(doc, pages, info);
}
int
-pdf_count_pages(pdf_document *xref)
+pdf_count_pages(pdf_document *doc)
{
- pdf_load_page_tree(xref);
- return xref->page_len;
+ pdf_load_page_tree(doc);
+ return doc->page_len;
}
int
-pdf_lookup_page_number(pdf_document *xref, pdf_obj *page)
+pdf_lookup_page_number(pdf_document *doc, pdf_obj *page)
{
int i, num = pdf_to_num(page);
- pdf_load_page_tree(xref);
- for (i = 0; i < xref->page_len; i++)
- if (num == pdf_to_num(xref->page_refs[i]))
+ pdf_load_page_tree(doc);
+ for (i = 0; i < doc->page_len; i++)
+ if (num == pdf_to_num(doc->page_refs[i]))
return i;
return -1;
}
@@ -287,7 +287,7 @@ found:
}
static void
-pdf_load_transition(pdf_document *xref, pdf_page *page, pdf_obj *transdict)
+pdf_load_transition(pdf_document *doc, pdf_page *page, pdf_obj *transdict)
{
char *name;
pdf_obj *obj;
@@ -449,7 +449,7 @@ pdf_load_page(pdf_document *doc, int number)
}
fz_rect *
-pdf_bound_page(pdf_document *xref, pdf_page *page, fz_rect *bounds)
+pdf_bound_page(pdf_document *doc, pdf_page *page, fz_rect *bounds)
{
fz_matrix mtx;
fz_rect mediabox = page->mediabox;
@@ -461,43 +461,43 @@ pdf_bound_page(pdf_document *xref, pdf_page *page, fz_rect *bounds)
}
fz_link *
-pdf_load_links(pdf_document *xref, pdf_page *page)
+pdf_load_links(pdf_document *doc, pdf_page *page)
{
- return fz_keep_link(xref->ctx, page->links);
+ return fz_keep_link(doc->ctx, page->links);
}
void
-pdf_free_page(pdf_document *xref, pdf_page *page)
+pdf_free_page(pdf_document *doc, pdf_page *page)
{
if (page == NULL)
return;
pdf_drop_obj(page->resources);
pdf_drop_obj(page->contents);
if (page->links)
- fz_drop_link(xref->ctx, page->links);
+ fz_drop_link(doc->ctx, page->links);
if (page->annots)
- pdf_free_annot(xref->ctx, page->annots);
+ pdf_free_annot(doc->ctx, page->annots);
if (page->deleted_annots)
- pdf_free_annot(xref->ctx, page->deleted_annots);
+ pdf_free_annot(doc->ctx, page->deleted_annots);
if (page->tmp_annots)
- pdf_free_annot(xref->ctx, page->tmp_annots);
- /* xref->focus, when not NULL, refers to one of
+ pdf_free_annot(doc->ctx, page->tmp_annots);
+ /* doc->focus, when not NULL, refers to one of
* the annotations and must be NULLed when the
- * annotations are destroyed. xref->focus_obj
+ * annotations are destroyed. doc->focus_obj
* keeps track of the actual annotation object. */
- xref->focus = NULL;
+ doc->focus = NULL;
pdf_drop_obj(page->me);
- fz_free(xref->ctx, page);
+ fz_free(doc->ctx, page);
}
void
-pdf_delete_page(pdf_document *xref, int page)
+pdf_delete_page(pdf_document *doc, int page)
{
- pdf_delete_page_range(xref, page, page+1);
+ pdf_delete_page_range(doc, page, page+1);
}
void
-pdf_delete_page_range(pdf_document *xref, int start, int end)
+pdf_delete_page_range(pdf_document *doc, int start, int end)
{
int i;
@@ -508,51 +508,51 @@ pdf_delete_page_range(pdf_document *xref, int start, int end)
end = tmp;
}
- if (!xref || start >= xref->page_len || end < 0)
+ if (!doc || start >= doc->page_len || end < 0)
return;
for (i=start; i < end; i++)
- pdf_drop_obj(xref->page_refs[i]);
- if (xref->page_len > end)
+ pdf_drop_obj(doc->page_refs[i]);
+ if (doc->page_len > end)
{
- memmove(&xref->page_refs[start], &xref->page_refs[end], sizeof(pdf_page *) * (xref->page_len - end + start));
- memmove(&xref->page_refs[start], &xref->page_refs[end], sizeof(pdf_page *) * (xref->page_len - end + start));
+ memmove(&doc->page_refs[start], &doc->page_refs[end], sizeof(pdf_page *) * (doc->page_len - end + start));
+ memmove(&doc->page_refs[start], &doc->page_refs[end], sizeof(pdf_page *) * (doc->page_len - end + start));
}
- xref->page_len -= end - start;
- xref->needs_page_tree_rebuild = 1;
+ doc->page_len -= end - start;
+ doc->needs_page_tree_rebuild = 1;
}
void
-pdf_insert_page(pdf_document *xref, pdf_page *page, int at)
+pdf_insert_page(pdf_document *doc, pdf_page *page, int at)
{
- if (!xref || !page)
+ if (!doc || !page)
return;
if (at < 0)
at = 0;
- if (at > xref->page_len)
- at = xref->page_len;
+ if (at > doc->page_len)
+ at = doc->page_len;
- if (xref->page_len + 1 >= xref->page_cap)
+ if (doc->page_len + 1 >= doc->page_cap)
{
- int newmax = xref->page_cap * 2;
+ int newmax = doc->page_cap * 2;
if (newmax == 0)
newmax = 4;
- xref->page_refs = fz_resize_array(xref->ctx, xref->page_refs, newmax, sizeof(pdf_page *));
- xref->page_objs = fz_resize_array(xref->ctx, xref->page_objs, newmax, sizeof(pdf_page *));
- xref->page_cap = newmax;
+ doc->page_refs = fz_resize_array(doc->ctx, doc->page_refs, newmax, sizeof(pdf_page *));
+ doc->page_objs = fz_resize_array(doc->ctx, doc->page_objs, newmax, sizeof(pdf_page *));
+ doc->page_cap = newmax;
}
- if (xref->page_len > at)
+ if (doc->page_len > at)
{
- memmove(&xref->page_objs[at+1], &xref->page_objs[at], xref->page_len - at);
- memmove(&xref->page_refs[at+1], &xref->page_refs[at], xref->page_len - at);
+ memmove(&doc->page_objs[at+1], &doc->page_objs[at], doc->page_len - at);
+ memmove(&doc->page_refs[at+1], &doc->page_refs[at], doc->page_len - at);
}
- xref->page_len++;
- xref->page_objs[at] = pdf_keep_obj(page->me);
- xref->page_refs[at] = NULL;
- xref->page_refs[at] = pdf_new_ref(xref, page->me);
- xref->needs_page_tree_rebuild = 1;
+ doc->page_len++;
+ doc->page_objs[at] = pdf_keep_obj(page->me);
+ doc->page_refs[at] = NULL;
+ doc->page_refs[at] = pdf_new_ref(doc, page->me);
+ doc->needs_page_tree_rebuild = 1;
}
pdf_page *
diff --git a/source/pdf/pdf-parse.c b/source/pdf/pdf-parse.c
index b499fbb7..cf2bdc20 100644
--- a/source/pdf/pdf-parse.c
+++ b/source/pdf/pdf-parse.c
@@ -28,9 +28,9 @@ pdf_to_matrix(fz_context *ctx, pdf_obj *array, fz_matrix *m)
/* Convert Unicode/PdfDocEncoding string into utf-8 */
char *
-pdf_to_utf8(pdf_document *xref, pdf_obj *src)
+pdf_to_utf8(pdf_document *doc, pdf_obj *src)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_buffer *strmbuf = NULL;
unsigned char *srcptr;
char *dstptr, *dst;
@@ -47,9 +47,9 @@ pdf_to_utf8(pdf_document *xref, pdf_obj *src)
srcptr = (unsigned char *) pdf_to_str_buf(src);
srclen = pdf_to_str_len(src);
}
- else if (pdf_is_stream(xref, pdf_to_num(src), pdf_to_gen(src)))
+ else if (pdf_is_stream(doc, pdf_to_num(src), pdf_to_gen(src)))
{
- strmbuf = pdf_load_stream(xref, pdf_to_num(src), pdf_to_gen(src));
+ strmbuf = pdf_load_stream(doc, pdf_to_num(src), pdf_to_gen(src));
srclen = fz_buffer_storage(ctx, strmbuf, (unsigned char **)&srcptr);
}
else
@@ -118,9 +118,9 @@ pdf_to_utf8(pdf_document *xref, pdf_obj *src)
/* Convert Unicode/PdfDocEncoding string into ucs-2 */
unsigned short *
-pdf_to_ucs2(pdf_document *xref, pdf_obj *src)
+pdf_to_ucs2(pdf_document *doc, pdf_obj *src)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
unsigned char *srcptr = (unsigned char *) pdf_to_str_buf(src);
unsigned short *dstptr, *dst;
int srclen = pdf_to_str_len(src);
@@ -180,9 +180,9 @@ pdf_to_ucs2_buf(unsigned short *buffer, pdf_obj *src)
/* Convert UCS-2 string into PdfDocEncoding for authentication */
char *
-pdf_from_ucs2(pdf_document *xref, unsigned short *src)
+pdf_from_ucs2(pdf_document *doc, unsigned short *src)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
int i, j, len;
char *docstr;
diff --git a/source/pdf/pdf-pattern.c b/source/pdf/pdf-pattern.c
index 622705b2..89e7f94f 100644
--- a/source/pdf/pdf-pattern.c
+++ b/source/pdf/pdf-pattern.c
@@ -33,11 +33,11 @@ pdf_pattern_size(pdf_pattern *pat)
}
pdf_pattern *
-pdf_load_pattern(pdf_document *xref, pdf_obj *dict)
+pdf_load_pattern(pdf_document *doc, pdf_obj *dict)
{
pdf_pattern *pat;
pdf_obj *obj;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
if ((pat = pdf_find_item(ctx, pdf_free_pattern_imp, dict)))
{
diff --git a/source/pdf/pdf-repair.c b/source/pdf/pdf-repair.c
index 8d50bb65..bf4bcf89 100644
--- a/source/pdf/pdf-repair.c
+++ b/source/pdf/pdf-repair.c
@@ -155,13 +155,13 @@ atobjend:
}
static void
-pdf_repair_obj_stm(pdf_document *xref, int num, int gen)
+pdf_repair_obj_stm(pdf_document *doc, int num, int gen)
{
pdf_obj *obj;
fz_stream *stm = NULL;
pdf_token tok;
int i, n, count;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
pdf_lexbuf buf;
fz_var(stm);
@@ -170,13 +170,13 @@ pdf_repair_obj_stm(pdf_document *xref, int num, int gen)
fz_try(ctx)
{
- obj = pdf_load_object(xref, num, gen);
+ obj = pdf_load_object(doc, num, gen);
count = pdf_to_int(pdf_dict_gets(obj, "N"));
pdf_drop_obj(obj);
- stm = pdf_open_stream(xref, num, gen);
+ stm = pdf_open_stream(doc, num, gen);
for (i = 0; i < count; i++)
{
@@ -198,7 +198,7 @@ pdf_repair_obj_stm(pdf_document *xref, int num, int gen)
continue;
}
- entry = pdf_get_populating_xref_entry(xref, n);
+ entry = pdf_get_populating_xref_entry(doc, n);
entry->ofs = num;
entry->gen = i;
entry->stm_ofs = 0;
@@ -542,24 +542,24 @@ pdf_repair_xref(pdf_document *doc, pdf_lexbuf *buf)
}
void
-pdf_repair_obj_stms(pdf_document *xref)
+pdf_repair_obj_stms(pdf_document *doc)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
pdf_obj *dict;
int i;
- int xref_len = pdf_xref_len(xref);
+ int xref_len = pdf_xref_len(doc);
for (i = 0; i < xref_len; i++)
{
- pdf_xref_entry *entry = pdf_get_populating_xref_entry(xref, i);
+ pdf_xref_entry *entry = pdf_get_populating_xref_entry(doc, i);
if (entry->stm_ofs)
{
- dict = pdf_load_object(xref, i, 0);
+ dict = pdf_load_object(doc, i, 0);
fz_try(ctx)
{
if (!strcmp(pdf_to_name(pdf_dict_gets(dict, "Type")), "ObjStm"))
- pdf_repair_obj_stm(xref, i, 0);
+ pdf_repair_obj_stm(doc, i, 0);
}
fz_always(ctx)
{
@@ -575,9 +575,9 @@ pdf_repair_obj_stms(pdf_document *xref)
/* Ensure that streamed objects reside inside a known non-streamed object */
for (i = 0; i < xref_len; i++)
{
- pdf_xref_entry *entry = pdf_get_populating_xref_entry(xref, i);
+ pdf_xref_entry *entry = pdf_get_populating_xref_entry(doc, i);
- if (entry->type == 'o' && pdf_get_populating_xref_entry(xref, entry->ofs)->type != 'n')
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "invalid reference to non-object-stream: %d (%d 0 R)", entry->ofs, i);
+ if (entry->type == 'o' && pdf_get_populating_xref_entry(doc, entry->ofs)->type != 'n')
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "invalid reference to non-object-stream: %d (%d 0 R)", entry->ofs, i);
}
}
diff --git a/source/pdf/pdf-shade.c b/source/pdf/pdf-shade.c
index 41ddcc1a..afeab247 100644
--- a/source/pdf/pdf-shade.c
+++ b/source/pdf/pdf-shade.c
@@ -47,14 +47,14 @@ pdf_sample_shade_function(fz_context *ctx, fz_shade *shade, int funcs, fz_functi
/* Type 1-3 -- Function-based, linear and radial shadings */
static void
-pdf_load_function_based_shading(fz_shade *shade, pdf_document *xref, pdf_obj *dict, fz_function *func)
+pdf_load_function_based_shading(fz_shade *shade, pdf_document *doc, pdf_obj *dict, fz_function *func)
{
pdf_obj *obj;
float x0, y0, x1, y1;
float fv[2];
fz_matrix matrix;
int xx, yy;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
float *p;
x0 = y0 = 0;
@@ -98,12 +98,12 @@ pdf_load_function_based_shading(fz_shade *shade, pdf_document *xref, pdf_obj *di
}
static void
-pdf_load_linear_shading(fz_shade *shade, pdf_document *xref, pdf_obj *dict, int funcs, fz_function **func)
+pdf_load_linear_shading(fz_shade *shade, pdf_document *doc, pdf_obj *dict, int funcs, fz_function **func)
{
pdf_obj *obj;
float d0, d1;
int e0, e1;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
obj = pdf_dict_gets(dict, "Coords");
shade->u.l_or_r.coords[0][0] = pdf_to_real(pdf_array_get(obj, 0));
@@ -135,12 +135,12 @@ pdf_load_linear_shading(fz_shade *shade, pdf_document *xref, pdf_obj *dict, int
}
static void
-pdf_load_radial_shading(fz_shade *shade, pdf_document *xref, pdf_obj *dict, int funcs, fz_function **func)
+pdf_load_radial_shading(fz_shade *shade, pdf_document *doc, pdf_obj *dict, int funcs, fz_function **func)
{
pdf_obj *obj;
float d0, d1;
int e0, e1;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
obj = pdf_dict_gets(dict, "Coords");
shade->u.l_or_r.coords[0][0] = pdf_to_real(pdf_array_get(obj, 0));
@@ -188,9 +188,9 @@ struct mesh_params
};
static void
-pdf_load_mesh_params(fz_shade *shade, pdf_document *xref, pdf_obj *dict)
+pdf_load_mesh_params(fz_shade *shade, pdf_document *doc, pdf_obj *dict)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
pdf_obj *obj;
int i, n;
@@ -252,67 +252,67 @@ pdf_load_mesh_params(fz_shade *shade, pdf_document *xref, pdf_obj *dict)
}
static void
-pdf_load_type4_shade(fz_shade *shade, pdf_document *xref, pdf_obj *dict,
+pdf_load_type4_shade(fz_shade *shade, pdf_document *doc, pdf_obj *dict,
int funcs, fz_function **func)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
- pdf_load_mesh_params(shade, xref, dict);
+ pdf_load_mesh_params(shade, doc, dict);
if (funcs > 0)
pdf_sample_shade_function(ctx, shade, funcs, func, shade->u.m.c0[0], shade->u.m.c1[0]);
- shade->buffer = pdf_load_compressed_stream(xref, pdf_to_num(dict), pdf_to_gen(dict));
+ shade->buffer = pdf_load_compressed_stream(doc, pdf_to_num(dict), pdf_to_gen(dict));
}
static void
-pdf_load_type5_shade(fz_shade *shade, pdf_document *xref, pdf_obj *dict,
+pdf_load_type5_shade(fz_shade *shade, pdf_document *doc, pdf_obj *dict,
int funcs, fz_function **func)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
- pdf_load_mesh_params(shade, xref, dict);
+ pdf_load_mesh_params(shade, doc, dict);
if (funcs > 0)
pdf_sample_shade_function(ctx, shade, funcs, func, shade->u.m.c0[0], shade->u.m.c1[0]);
- shade->buffer = pdf_load_compressed_stream(xref, pdf_to_num(dict), pdf_to_gen(dict));
+ shade->buffer = pdf_load_compressed_stream(doc, pdf_to_num(dict), pdf_to_gen(dict));
}
/* Type 6 & 7 -- Patch mesh shadings */
static void
-pdf_load_type6_shade(fz_shade *shade, pdf_document *xref, pdf_obj *dict,
+pdf_load_type6_shade(fz_shade *shade, pdf_document *doc, pdf_obj *dict,
int funcs, fz_function **func)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
- pdf_load_mesh_params(shade, xref, dict);
+ pdf_load_mesh_params(shade, doc, dict);
if (funcs > 0)
pdf_sample_shade_function(ctx, shade, funcs, func, shade->u.m.c0[0], shade->u.m.c1[0]);
- shade->buffer = pdf_load_compressed_stream(xref, pdf_to_num(dict), pdf_to_gen(dict));
+ shade->buffer = pdf_load_compressed_stream(doc, pdf_to_num(dict), pdf_to_gen(dict));
}
static void
-pdf_load_type7_shade(fz_shade *shade, pdf_document *xref, pdf_obj *dict,
+pdf_load_type7_shade(fz_shade *shade, pdf_document *doc, pdf_obj *dict,
int funcs, fz_function **func)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
- pdf_load_mesh_params(shade, xref, dict);
+ pdf_load_mesh_params(shade, doc, dict);
if (funcs > 0)
pdf_sample_shade_function(ctx, shade, funcs, func, shade->u.m.c0[0], shade->u.m.c1[0]);
- shade->buffer = pdf_load_compressed_stream(xref, pdf_to_num(dict), pdf_to_gen(dict));
+ shade->buffer = pdf_load_compressed_stream(doc, pdf_to_num(dict), pdf_to_gen(dict));
}
/* Load all of the shading dictionary parameters, then switch on the shading type. */
static fz_shade *
-pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transform)
+pdf_load_shading_dict(pdf_document *doc, pdf_obj *dict, const fz_matrix *transform)
{
fz_shade *shade = NULL;
fz_function *func[FZ_MAX_COLORS] = { NULL };
@@ -320,7 +320,7 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf
int funcs = 0;
int type = 0;
int i, in, out;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_var(shade);
fz_var(func);
@@ -347,7 +347,7 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf
obj = pdf_dict_gets(dict, "ColorSpace");
if (!obj)
fz_throw(ctx, FZ_ERROR_GENERIC, "shading colorspace is missing");
- shade->colorspace = pdf_load_colorspace(xref, obj);
+ shade->colorspace = pdf_load_colorspace(doc, obj);
obj = pdf_dict_gets(dict, "Background");
if (obj)
@@ -372,7 +372,7 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf
in = 1;
out = shade->colorspace->n;
- func[0] = pdf_load_function(xref, obj, in, out);
+ func[0] = pdf_load_function(doc, obj, in, out);
if (!func[0])
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load shading function (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
}
@@ -398,7 +398,7 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf
for (i = 0; i < funcs; i++)
{
- func[i] = pdf_load_function(xref, pdf_array_get(obj, i), in, out);
+ func[i] = pdf_load_function(doc, pdf_array_get(obj, i), in, out);
if (!func[i])
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load shading function (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
}
@@ -412,13 +412,13 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf
shade->type = type;
switch (type)
{
- case 1: pdf_load_function_based_shading(shade, xref, dict, func[0]); break;
- case 2: pdf_load_linear_shading(shade, xref, dict, funcs, func); break;
- case 3: pdf_load_radial_shading(shade, xref, dict, funcs, func); break;
- case 4: pdf_load_type4_shade(shade, xref, dict, funcs, func); break;
- case 5: pdf_load_type5_shade(shade, xref, dict, funcs, func); break;
- case 6: pdf_load_type6_shade(shade, xref, dict, funcs, func); break;
- case 7: pdf_load_type7_shade(shade, xref, dict, funcs, func); break;
+ case 1: pdf_load_function_based_shading(shade, doc, dict, func[0]); break;
+ case 2: pdf_load_linear_shading(shade, doc, dict, funcs, func); break;
+ case 3: pdf_load_radial_shading(shade, doc, dict, funcs, func); break;
+ case 4: pdf_load_type4_shade(shade, doc, dict, funcs, func); break;
+ case 5: pdf_load_type5_shade(shade, doc, dict, funcs, func); break;
+ case 6: pdf_load_type6_shade(shade, doc, dict, funcs, func); break;
+ case 7: pdf_load_type7_shade(shade, doc, dict, funcs, func); break;
default:
fz_throw(ctx, FZ_ERROR_GENERIC, "unknown shading type: %d", type);
}
@@ -449,11 +449,11 @@ fz_shade_size(fz_shade *s)
}
fz_shade *
-pdf_load_shading(pdf_document *xref, pdf_obj *dict)
+pdf_load_shading(pdf_document *doc, pdf_obj *dict)
{
fz_matrix mat;
pdf_obj *obj;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_shade *shade;
if ((shade = pdf_find_item(ctx, fz_free_shade_imp, dict)))
@@ -483,13 +483,13 @@ pdf_load_shading(pdf_document *xref, pdf_obj *dict)
if (!obj)
fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: missing shading dictionary");
- shade = pdf_load_shading_dict(xref, obj, &mat);
+ shade = pdf_load_shading_dict(doc, obj, &mat);
}
/* Naked shading dictionary */
else
{
- shade = pdf_load_shading_dict(xref, dict, &fz_identity);
+ shade = pdf_load_shading_dict(doc, dict, &fz_identity);
}
pdf_store_item(ctx, dict, shade, fz_shade_size(shade));
diff --git a/source/pdf/pdf-stream.c b/source/pdf/pdf-stream.c
index 7e74b666..9d25915b 100644
--- a/source/pdf/pdf-stream.c
+++ b/source/pdf/pdf-stream.c
@@ -4,16 +4,16 @@
* Check if an object is a stream or not.
*/
int
-pdf_is_stream(pdf_document *xref, int num, int gen)
+pdf_is_stream(pdf_document *doc, int num, int gen)
{
pdf_xref_entry *entry;
- if (num < 0 || num >= pdf_xref_len(xref))
+ if (num < 0 || num >= pdf_xref_len(doc))
return 0;
- pdf_cache_object(xref, num, gen);
+ pdf_cache_object(doc, num, gen);
- entry = pdf_get_xref_entry(xref, num);
+ entry = pdf_get_xref_entry(doc, num);
return entry->stm_ofs != 0 || entry->stm_buf;
}
@@ -50,7 +50,7 @@ pdf_stream_has_crypt(fz_context *ctx, pdf_obj *stm)
* Create a filter given a name and param dictionary.
*/
static fz_stream *
-build_filter(fz_stream *chain, pdf_document * xref, pdf_obj * f, pdf_obj * p, int num, int gen, fz_compression_params *params)
+build_filter(fz_stream *chain, pdf_document *doc, pdf_obj *f, pdf_obj *p, int num, int gen, fz_compression_params *params)
{
fz_context *ctx = chain->ctx;
char *s = pdf_to_name(f);
@@ -164,7 +164,7 @@ build_filter(fz_stream *chain, pdf_document * xref, pdf_obj * f, pdf_obj * p, in
fz_buffer *globals = NULL;
pdf_obj *obj = pdf_dict_gets(p, "JBIG2Globals");
if (obj)
- globals = pdf_load_stream(xref, pdf_to_num(obj), pdf_to_gen(obj));
+ globals = pdf_load_stream(doc, pdf_to_num(obj), pdf_to_gen(obj));
/* fz_open_jbig2d takes possession of globals */
return fz_open_jbig2d(chain, globals);
}
@@ -176,7 +176,7 @@ build_filter(fz_stream *chain, pdf_document * xref, pdf_obj * f, pdf_obj * p, in
{
pdf_obj *name;
- if (!xref->crypt)
+ if (!doc->crypt)
{
fz_warn(ctx, "crypt filter in unencrypted document");
return chain;
@@ -184,7 +184,7 @@ build_filter(fz_stream *chain, pdf_document * xref, pdf_obj * f, pdf_obj * p, in
name = pdf_dict_gets(p, "Name");
if (pdf_is_name(name))
- return pdf_open_crypt_with_filter(chain, xref->crypt, pdf_to_name(name), num, gen);
+ return pdf_open_crypt_with_filter(chain, doc->crypt, pdf_to_name(name), num, gen);
return chain;
}
@@ -199,7 +199,7 @@ build_filter(fz_stream *chain, pdf_document * xref, pdf_obj * f, pdf_obj * p, in
* Assume ownership of head.
*/
static fz_stream *
-build_filter_chain(fz_stream *chain, pdf_document *xref, pdf_obj *fs, pdf_obj *ps, int num, int gen, fz_compression_params *params)
+build_filter_chain(fz_stream *chain, pdf_document *doc, pdf_obj *fs, pdf_obj *ps, int num, int gen, fz_compression_params *params)
{
pdf_obj *f;
pdf_obj *p;
@@ -210,7 +210,7 @@ build_filter_chain(fz_stream *chain, pdf_document *xref, pdf_obj *fs, pdf_obj *p
{
f = pdf_array_get(fs, i);
p = pdf_array_get(ps, i);
- chain = build_filter(chain, xref, f, p, num, gen, (i == n-1 ? params : NULL));
+ chain = build_filter(chain, doc, f, p, num, gen, (i == n-1 ? params : NULL));
}
return chain;
@@ -225,15 +225,15 @@ build_filter_chain(fz_stream *chain, pdf_document *xref, pdf_obj *fs, pdf_obj *p
* orig_num and orig_gen are used purely to seed the encryption.
*/
static fz_stream *
-pdf_open_raw_filter(fz_stream *chain, pdf_document *xref, pdf_obj *stmobj, int num, int orig_num, int orig_gen, int offset)
+pdf_open_raw_filter(fz_stream *chain, pdf_document *doc, pdf_obj *stmobj, int num, int orig_num, int orig_gen, int offset)
{
fz_context *ctx = chain->ctx;
int hascrypt;
int len;
- if (num > 0 && num < pdf_xref_len(xref))
+ if (num > 0 && num < pdf_xref_len(doc))
{
- pdf_xref_entry *entry = pdf_get_xref_entry(xref, num);
+ pdf_xref_entry *entry = pdf_get_xref_entry(doc, num);
if (entry->stm_buf)
return fz_open_buffer(ctx, entry->stm_buf);
}
@@ -247,8 +247,8 @@ pdf_open_raw_filter(fz_stream *chain, pdf_document *xref, pdf_obj *stmobj, int n
fz_try(ctx)
{
hascrypt = pdf_stream_has_crypt(ctx, stmobj);
- if (xref->crypt && !hascrypt)
- chain = pdf_open_crypt(chain, xref->crypt, orig_num, orig_gen);
+ if (doc->crypt && !hascrypt)
+ chain = pdf_open_crypt(chain, doc->crypt, orig_num, orig_gen);
}
fz_catch(ctx)
{
@@ -264,7 +264,7 @@ pdf_open_raw_filter(fz_stream *chain, pdf_document *xref, pdf_obj *stmobj, int n
* to stream length and decrypting.
*/
static fz_stream *
-pdf_open_filter(fz_stream *chain, pdf_document *xref, pdf_obj *stmobj, int num, int gen, int offset, fz_compression_params *imparams)
+pdf_open_filter(fz_stream *chain, pdf_document *doc, pdf_obj *stmobj, int num, int gen, int offset, fz_compression_params *imparams)
{
pdf_obj *filters;
pdf_obj *params;
@@ -272,19 +272,19 @@ pdf_open_filter(fz_stream *chain, pdf_document *xref, pdf_obj *stmobj, int num,
filters = pdf_dict_getsa(stmobj, "Filter", "F");
params = pdf_dict_getsa(stmobj, "DecodeParms", "DP");
- chain = pdf_open_raw_filter(chain, xref, stmobj, num, num, gen, offset);
+ chain = pdf_open_raw_filter(chain, doc, stmobj, num, num, gen, offset);
- fz_try(xref->ctx)
+ fz_try(doc->ctx)
{
if (pdf_is_name(filters))
- chain = build_filter(chain, xref, filters, params, num, gen, imparams);
+ chain = build_filter(chain, doc, filters, params, num, gen, imparams);
else if (pdf_array_len(filters) > 0)
- chain = build_filter_chain(chain, xref, filters, params, num, gen, imparams);
+ chain = build_filter_chain(chain, doc, filters, params, num, gen, imparams);
}
- fz_catch(xref->ctx)
+ fz_catch(doc->ctx)
{
fz_close(chain);
- fz_rethrow(xref->ctx);
+ fz_rethrow(doc->ctx);
}
return chain;
@@ -295,7 +295,7 @@ pdf_open_filter(fz_stream *chain, pdf_document *xref, pdf_obj *stmobj, int num,
* constraining to stream length, and without decryption.
*/
fz_stream *
-pdf_open_inline_stream(pdf_document *xref, pdf_obj *stmobj, int length, fz_stream *chain, fz_compression_params *imparams)
+pdf_open_inline_stream(pdf_document *doc, pdf_obj *stmobj, int length, fz_stream *chain, fz_compression_params *imparams)
{
pdf_obj *filters;
pdf_obj *params;
@@ -307,9 +307,9 @@ pdf_open_inline_stream(pdf_document *xref, pdf_obj *stmobj, int length, fz_strea
fz_keep_stream(chain);
if (pdf_is_name(filters))
- return build_filter(chain, xref, filters, params, 0, 0, imparams);
+ return build_filter(chain, doc, filters, params, 0, 0, imparams);
if (pdf_array_len(filters) > 0)
- return build_filter_chain(chain, xref, filters, params, 0, 0, imparams);
+ return build_filter_chain(chain, doc, filters, params, 0, 0, imparams);
return fz_open_null(chain, length, fz_tell(chain));
}
@@ -318,98 +318,98 @@ pdf_open_inline_stream(pdf_document *xref, pdf_obj *stmobj, int length, fz_strea
* Open a stream for reading the raw (compressed but decrypted) data.
*/
fz_stream *
-pdf_open_raw_stream(pdf_document *xref, int num, int gen)
+pdf_open_raw_stream(pdf_document *doc, int num, int gen)
{
- return pdf_open_raw_renumbered_stream(xref, num, gen, num, gen);
+ return pdf_open_raw_renumbered_stream(doc, num, gen, num, gen);
}
fz_stream *
-pdf_open_raw_renumbered_stream(pdf_document *xref, int num, int gen, int orig_num, int orig_gen)
+pdf_open_raw_renumbered_stream(pdf_document *doc, int num, int gen, int orig_num, int orig_gen)
{
pdf_xref_entry *x;
- if (num < 0 || num >= pdf_xref_len(xref))
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "object id out of range (%d %d R)", num, gen);
+ if (num < 0 || num >= pdf_xref_len(doc))
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "object id out of range (%d %d R)", num, gen);
- x = pdf_get_xref_entry(xref, num);
+ x = pdf_get_xref_entry(doc, num);
- pdf_cache_object(xref, num, gen);
+ pdf_cache_object(doc, num, gen);
if (x->stm_ofs == 0)
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "object is not a stream");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "object is not a stream");
- return pdf_open_raw_filter(xref->file, xref, x->obj, num, orig_num, orig_gen, x->stm_ofs);
+ return pdf_open_raw_filter(doc->file, doc, x->obj, num, orig_num, orig_gen, x->stm_ofs);
}
static fz_stream *
-pdf_open_image_stream(pdf_document *xref, int num, int gen, int orig_num, int orig_gen, fz_compression_params *params)
+pdf_open_image_stream(pdf_document *doc, int num, int gen, int orig_num, int orig_gen, fz_compression_params *params)
{
pdf_xref_entry *x;
- if (num < 0 || num >= pdf_xref_len(xref))
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "object id out of range (%d %d R)", num, gen);
+ if (num < 0 || num >= pdf_xref_len(doc))
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "object id out of range (%d %d R)", num, gen);
- x = pdf_get_xref_entry(xref, num);
+ x = pdf_get_xref_entry(doc, num);
- pdf_cache_object(xref, num, gen);
+ pdf_cache_object(doc, num, gen);
if (x->stm_ofs == 0 && x->stm_buf == NULL)
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "object is not a stream");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "object is not a stream");
- return pdf_open_filter(xref->file, xref, x->obj, orig_num, orig_gen, x->stm_ofs, params);
+ return pdf_open_filter(doc->file, doc, x->obj, orig_num, orig_gen, x->stm_ofs, params);
}
/*
* Open a stream for reading uncompressed data.
- * Put the opened file in xref->stream.
- * Using xref->file while a stream is open is a Bad idea.
+ * Put the opened file in doc->stream.
+ * Using doc->file while a stream is open is a Bad idea.
*/
fz_stream *
-pdf_open_stream(pdf_document *xref, int num, int gen)
+pdf_open_stream(pdf_document *doc, int num, int gen)
{
- return pdf_open_image_stream(xref, num, gen, num, gen, NULL);
+ return pdf_open_image_stream(doc, num, gen, num, gen, NULL);
}
fz_stream *
-pdf_open_stream_with_offset(pdf_document *xref, int num, int gen, pdf_obj *dict, int stm_ofs)
+pdf_open_stream_with_offset(pdf_document *doc, int num, int gen, pdf_obj *dict, int stm_ofs)
{
if (stm_ofs == 0)
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "object is not a stream");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "object is not a stream");
- return pdf_open_filter(xref->file, xref, dict, num, gen, stm_ofs, NULL);
+ return pdf_open_filter(doc->file, doc, dict, num, gen, stm_ofs, NULL);
}
/*
* Load raw (compressed but decrypted) contents of a stream into buf.
*/
fz_buffer *
-pdf_load_raw_stream(pdf_document *xref, int num, int gen)
+pdf_load_raw_stream(pdf_document *doc, int num, int gen)
{
- return pdf_load_raw_renumbered_stream(xref, num, gen, num, gen);
+ return pdf_load_raw_renumbered_stream(doc, num, gen, num, gen);
}
fz_buffer *
-pdf_load_raw_renumbered_stream(pdf_document *xref, int num, int gen, int orig_num, int orig_gen)
+pdf_load_raw_renumbered_stream(pdf_document *doc, int num, int gen, int orig_num, int orig_gen)
{
fz_stream *stm;
pdf_obj *dict;
int len;
fz_buffer *buf;
- if (num > 0 && num < pdf_xref_len(xref))
+ if (num > 0 && num < pdf_xref_len(doc))
{
- pdf_xref_entry *entry = pdf_get_xref_entry(xref, num);
+ pdf_xref_entry *entry = pdf_get_xref_entry(doc, num);
if (entry->stm_buf)
- return fz_keep_buffer(xref->ctx, entry->stm_buf);
+ return fz_keep_buffer(doc->ctx, entry->stm_buf);
}
- dict = pdf_load_object(xref, num, gen);
+ dict = pdf_load_object(doc, num, gen);
len = pdf_to_int(pdf_dict_gets(dict, "Length"));
pdf_drop_obj(dict);
- stm = pdf_open_raw_renumbered_stream(xref, num, gen, orig_num, orig_gen);
+ stm = pdf_open_raw_renumbered_stream(doc, num, gen, orig_num, orig_gen);
buf = fz_read_all(stm, len);
@@ -434,9 +434,9 @@ pdf_guess_filter_length(int len, char *filter)
}
static fz_buffer *
-pdf_load_image_stream(pdf_document *xref, int num, int gen, int orig_num, int orig_gen, fz_compression_params *params, int *truncated)
+pdf_load_image_stream(pdf_document *doc, int num, int gen, int orig_num, int orig_gen, fz_compression_params *params, int *truncated)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_stream *stm = NULL;
pdf_obj *dict, *obj;
int i, len, n;
@@ -444,14 +444,14 @@ pdf_load_image_stream(pdf_document *xref, int num, int gen, int orig_num, int or
fz_var(buf);
- if (num > 0 && num < pdf_xref_len(xref))
+ if (num > 0 && num < pdf_xref_len(doc))
{
- pdf_xref_entry *entry = pdf_get_xref_entry(xref, num);
+ pdf_xref_entry *entry = pdf_get_xref_entry(doc, num);
if (entry->stm_buf)
- return fz_keep_buffer(xref->ctx, entry->stm_buf);
+ return fz_keep_buffer(doc->ctx, entry->stm_buf);
}
- dict = pdf_load_object(xref, num, gen);
+ dict = pdf_load_object(doc, num, gen);
len = pdf_to_int(pdf_dict_gets(dict, "Length"));
obj = pdf_dict_gets(dict, "Filter");
@@ -462,7 +462,7 @@ pdf_load_image_stream(pdf_document *xref, int num, int gen, int orig_num, int or
pdf_drop_obj(dict);
- stm = pdf_open_image_stream(xref, num, gen, orig_num, orig_gen, params);
+ stm = pdf_open_image_stream(doc, num, gen, orig_num, orig_gen, params);
fz_try(ctx)
{
@@ -487,26 +487,26 @@ pdf_load_image_stream(pdf_document *xref, int num, int gen, int orig_num, int or
* Load uncompressed contents of a stream into buf.
*/
fz_buffer *
-pdf_load_stream(pdf_document *xref, int num, int gen)
+pdf_load_stream(pdf_document *doc, int num, int gen)
{
- return pdf_load_image_stream(xref, num, gen, num, gen, NULL, NULL);
+ return pdf_load_image_stream(doc, num, gen, num, gen, NULL, NULL);
}
fz_buffer *
-pdf_load_renumbered_stream(pdf_document *xref, int num, int gen, int orig_num, int orig_gen, int *truncated)
+pdf_load_renumbered_stream(pdf_document *doc, int num, int gen, int orig_num, int orig_gen, int *truncated)
{
- return pdf_load_image_stream(xref, num, gen, orig_num, orig_gen, NULL, truncated);
+ return pdf_load_image_stream(doc, num, gen, orig_num, orig_gen, NULL, truncated);
}
fz_compressed_buffer *
-pdf_load_compressed_stream(pdf_document *xref, int num, int gen)
+pdf_load_compressed_stream(pdf_document *doc, int num, int gen)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_compressed_buffer *bc = fz_malloc_struct(ctx, fz_compressed_buffer);
fz_try(ctx)
{
- bc->buffer = pdf_load_image_stream(xref, num, gen, num, gen, &bc->params, NULL);
+ bc->buffer = pdf_load_image_stream(doc, num, gen, num, gen, &bc->params, NULL);
}
fz_catch(ctx)
{
@@ -517,10 +517,10 @@ pdf_load_compressed_stream(pdf_document *xref, int num, int gen)
}
static fz_stream *
-pdf_open_object_array(pdf_document *xref, pdf_obj *list)
+pdf_open_object_array(pdf_document *doc, pdf_obj *list)
{
int i, n;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_stream *stm;
n = pdf_array_len(list);
@@ -532,7 +532,7 @@ pdf_open_object_array(pdf_document *xref, pdf_obj *list)
pdf_obj *obj = pdf_array_get(list, i);
fz_try(ctx)
{
- fz_concat_push(stm, pdf_open_stream(xref, pdf_to_num(obj), pdf_to_gen(obj)));
+ fz_concat_push(stm, pdf_open_stream(doc, pdf_to_num(obj), pdf_to_gen(obj)));
}
fz_catch(ctx)
{
@@ -546,18 +546,18 @@ pdf_open_object_array(pdf_document *xref, pdf_obj *list)
}
fz_stream *
-pdf_open_contents_stream(pdf_document *xref, pdf_obj *obj)
+pdf_open_contents_stream(pdf_document *doc, pdf_obj *obj)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
int num, gen;
if (pdf_is_array(obj))
- return pdf_open_object_array(xref, obj);
+ return pdf_open_object_array(doc, obj);
num = pdf_to_num(obj);
gen = pdf_to_gen(obj);
- if (pdf_is_stream(xref, num, gen))
- return pdf_open_image_stream(xref, num, gen, num, gen, NULL);
+ if (pdf_is_stream(doc, num, gen))
+ return pdf_open_image_stream(doc, num, gen, num, gen, NULL);
fz_warn(ctx, "pdf object stream missing (%d %d R)", num, gen);
return NULL;
diff --git a/source/pdf/pdf-type3.c b/source/pdf/pdf-type3.c
index d85d9f11..d136b6f5 100644
--- a/source/pdf/pdf-type3.c
+++ b/source/pdf/pdf-type3.c
@@ -14,7 +14,7 @@ pdf_t3_free_resources(void *doc, void *rdb_)
}
pdf_font_desc *
-pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict)
+pdf_load_type3_font(pdf_document *doc, pdf_obj *rdb, pdf_obj *dict)
{
char buf[256];
char *estrings[256];
@@ -27,7 +27,7 @@ pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict)
int i, k, n;
fz_rect bbox;
fz_matrix matrix;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_var(fontdesc);
@@ -93,7 +93,7 @@ pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict)
fontdesc->encoding = pdf_new_identity_cmap(ctx, 0, 1);
fontdesc->size += pdf_cmap_size(ctx, fontdesc->encoding);
- pdf_load_to_unicode(xref, fontdesc, estrings, NULL, pdf_dict_gets(dict, "ToUnicode"));
+ pdf_load_to_unicode(doc, fontdesc, estrings, NULL, pdf_dict_gets(dict, "ToUnicode"));
/* Widths */
@@ -132,7 +132,7 @@ pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict)
if (!fontdesc->font->t3resources)
fz_warn(ctx, "no resource dictionary for type 3 font!");
- fontdesc->font->t3doc = xref;
+ fontdesc->font->t3doc = doc;
fontdesc->font->t3run = pdf_run_glyph_func;
/* CharProcs */
@@ -148,9 +148,9 @@ pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict)
if (estrings[i])
{
obj = pdf_dict_gets(charprocs, estrings[i]);
- if (pdf_is_stream(xref, pdf_to_num(obj), pdf_to_gen(obj)))
+ if (pdf_is_stream(doc, pdf_to_num(obj), pdf_to_gen(obj)))
{
- fontdesc->font->t3procs[i] = pdf_load_stream(xref, pdf_to_num(obj), pdf_to_gen(obj));
+ fontdesc->font->t3procs[i] = pdf_load_stream(doc, pdf_to_num(obj), pdf_to_gen(obj));
fontdesc->size += fontdesc->font->t3procs[i]->cap;
fontdesc->size += 0; // TODO: display list size calculation
}
@@ -166,10 +166,10 @@ pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict)
return fontdesc;
}
-void pdf_load_type3_glyphs(pdf_document *xref, pdf_font_desc *fontdesc, int nested_depth)
+void pdf_load_type3_glyphs(pdf_document *doc, pdf_font_desc *fontdesc, int nested_depth)
{
int i;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_try(ctx)
{
diff --git a/source/pdf/pdf-unicode.c b/source/pdf/pdf-unicode.c
index 694cbac6..c241dbc7 100644
--- a/source/pdf/pdf-unicode.c
+++ b/source/pdf/pdf-unicode.c
@@ -3,7 +3,7 @@
/* Load or synthesize ToUnicode map for fonts */
void
-pdf_load_to_unicode(pdf_document *xref, pdf_font_desc *font,
+pdf_load_to_unicode(pdf_document *doc, pdf_font_desc *font,
char **strings, char *collection, pdf_obj *cmapstm)
{
pdf_cmap *cmap;
@@ -11,11 +11,11 @@ pdf_load_to_unicode(pdf_document *xref, pdf_font_desc *font,
int ucsbuf[8];
int ucslen;
int i;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
- if (pdf_is_stream(xref, pdf_to_num(cmapstm), pdf_to_gen(cmapstm)))
+ if (pdf_is_stream(doc, pdf_to_num(cmapstm), pdf_to_gen(cmapstm)))
{
- cmap = pdf_load_embedded_cmap(xref, cmapstm);
+ cmap = pdf_load_embedded_cmap(doc, cmapstm);
font->to_unicode = pdf_new_cmap(ctx);
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c
index 792ef69c..8a41898b 100644
--- a/source/pdf/pdf-write.c
+++ b/source/pdf/pdf-write.c
@@ -487,11 +487,11 @@ page_objects_dump(pdf_write_options *opts)
}
static void
-objects_dump(pdf_document *xref, pdf_write_options *opts)
+objects_dump(pdf_document *doc, pdf_write_options *opts)
{
int i;
- for (i=0; i < pdf_xref_len(xref); i++)
+ for (i=0; i < pdf_xref_len(doc); i++)
{
fprintf(stderr, "Object %d use=%x offset=%d\n", i, opts->use_list[i], opts->ofs_list[i]);
}
@@ -502,13 +502,13 @@ objects_dump(pdf_document *xref, pdf_write_options *opts)
* Garbage collect objects not reachable from the trailer.
*/
-static pdf_obj *sweepref(pdf_document *xref, pdf_write_options *opts, pdf_obj *obj)
+static pdf_obj *sweepref(pdf_document *doc, pdf_write_options *opts, pdf_obj *obj)
{
int num = pdf_to_num(obj);
int gen = pdf_to_gen(obj);
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
- if (num < 0 || num >= pdf_xref_len(xref))
+ if (num < 0 || num >= pdf_xref_len(doc))
return NULL;
if (opts->use_list[num])
return NULL;
@@ -518,7 +518,7 @@ static pdf_obj *sweepref(pdf_document *xref, pdf_write_options *opts, pdf_obj *o
/* Bake in /Length in stream objects */
fz_try(ctx)
{
- if (pdf_is_stream(xref, num, gen))
+ if (pdf_is_stream(doc, num, gen))
{
pdf_obj *len = pdf_dict_gets(obj, "Length");
if (pdf_is_indirect(len))
@@ -538,25 +538,25 @@ static pdf_obj *sweepref(pdf_document *xref, pdf_write_options *opts, pdf_obj *o
return pdf_resolve_indirect(obj);
}
-static void sweepobj(pdf_document *xref, pdf_write_options *opts, pdf_obj *obj)
+static void sweepobj(pdf_document *doc, pdf_write_options *opts, pdf_obj *obj)
{
int i;
if (pdf_is_indirect(obj))
- obj = sweepref(xref, opts, obj);
+ obj = sweepref(doc, opts, obj);
if (pdf_is_dict(obj))
{
int n = pdf_dict_len(obj);
for (i = 0; i < n; i++)
- sweepobj(xref, opts, pdf_dict_get_val(obj, i));
+ sweepobj(doc, opts, pdf_dict_get_val(obj, i));
}
else if (pdf_is_array(obj))
{
int n = pdf_array_len(obj);
for (i = 0; i < n; i++)
- sweepobj(xref, opts, pdf_array_get(obj, i));
+ sweepobj(doc, opts, pdf_array_get(obj, i));
}
}
@@ -564,11 +564,11 @@ static void sweepobj(pdf_document *xref, pdf_write_options *opts, pdf_obj *obj)
* Scan for and remove duplicate objects (slow)
*/
-static void removeduplicateobjs(pdf_document *xref, pdf_write_options *opts)
+static void removeduplicateobjs(pdf_document *doc, pdf_write_options *opts)
{
int num, other;
- fz_context *ctx = xref->ctx;
- int xref_len = pdf_xref_len(xref);
+ fz_context *ctx = doc->ctx;
+ int xref_len = pdf_xref_len(doc);
for (num = 1; num < xref_len; num++)
{
@@ -589,8 +589,8 @@ static void removeduplicateobjs(pdf_document *xref, pdf_write_options *opts)
*/
fz_try(ctx)
{
- streama = pdf_is_stream(xref, num, 0);
- streamb = pdf_is_stream(xref, other, 0);
+ streama = pdf_is_stream(doc, num, 0);
+ streamb = pdf_is_stream(doc, other, 0);
differ = streama || streamb;
if (streama && streamb && opts->do_garbage >= 4)
differ = 0;
@@ -603,8 +603,8 @@ static void removeduplicateobjs(pdf_document *xref, pdf_write_options *opts)
if (differ)
continue;
- a = pdf_get_xref_entry(xref, num)->obj;
- b = pdf_get_xref_entry(xref, other)->obj;
+ a = pdf_get_xref_entry(doc, num)->obj;
+ b = pdf_get_xref_entry(doc, other)->obj;
a = pdf_resolve_indirect(a);
b = pdf_resolve_indirect(b);
@@ -626,8 +626,8 @@ static void removeduplicateobjs(pdf_document *xref, pdf_write_options *opts)
{
unsigned char *dataa, *datab;
int lena, lenb;
- sa = pdf_load_raw_renumbered_stream(xref, num, 0, num, 0);
- sb = pdf_load_raw_renumbered_stream(xref, other, 0, other, 0);
+ sa = pdf_load_raw_renumbered_stream(doc, num, 0, num, 0);
+ sb = pdf_load_raw_renumbered_stream(doc, other, 0, other, 0);
lena = fz_buffer_storage(ctx, sa, &dataa);
lenb = fz_buffer_storage(ctx, sb, &datab);
if (lena == lenb && memcmp(dataa, datab, lena) == 0)
@@ -665,10 +665,10 @@ static void removeduplicateobjs(pdf_document *xref, pdf_write_options *opts)
* This code assumes that any opts->renumber_map[n] <= n for all n.
*/
-static void compactxref(pdf_document *xref, pdf_write_options *opts)
+static void compactxref(pdf_document *doc, pdf_write_options *opts)
{
int num, newnum;
- int xref_len = pdf_xref_len(xref);
+ int xref_len = pdf_xref_len(doc);
/*
* Update renumber_map in-place, clustering all used
@@ -839,9 +839,9 @@ static void page_objects_list_renumber(pdf_write_options *opts)
}
static void
-mark_all(pdf_document *xref, pdf_write_options *opts, pdf_obj *val, int flag, int page)
+mark_all(pdf_document *doc, pdf_write_options *opts, pdf_obj *val, int flag, int page)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
if (pdf_obj_mark(val))
return;
@@ -866,7 +866,7 @@ mark_all(pdf_document *xref, pdf_write_options *opts, pdf_obj *val, int flag, in
for (i = 0; i < n; i++)
{
- mark_all(xref, opts, pdf_dict_get_val(val, i), flag, page);
+ mark_all(doc, opts, pdf_dict_get_val(val, i), flag, page);
}
}
else if (pdf_is_array(val))
@@ -875,7 +875,7 @@ mark_all(pdf_document *xref, pdf_write_options *opts, pdf_obj *val, int flag, in
for (i = 0; i < n; i++)
{
- mark_all(xref, opts, pdf_array_get(val, i), flag, page);
+ mark_all(doc, opts, pdf_array_get(val, i), flag, page);
}
}
}
@@ -890,9 +890,9 @@ mark_all(pdf_document *xref, pdf_write_options *opts, pdf_obj *val, int flag, in
}
static int
-mark_pages(pdf_document *xref, pdf_write_options *opts, pdf_obj *val, int pagenum)
+mark_pages(pdf_document *doc, pdf_write_options *opts, pdf_obj *val, int pagenum)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
if (pdf_obj_mark(val))
return pagenum;
@@ -905,7 +905,7 @@ mark_pages(pdf_document *xref, pdf_write_options *opts, pdf_obj *val, int pagenu
{
int num = pdf_to_num(val);
pdf_obj_unmark(val);
- mark_all(xref, opts, val, pagenum == 0 ? USE_PAGE1 : (pagenum<<USE_PAGE_SHIFT), pagenum);
+ mark_all(doc, opts, val, pagenum == 0 ? USE_PAGE1 : (pagenum<<USE_PAGE_SHIFT), pagenum);
page_objects_list_set_page_object(ctx, opts, pagenum, num);
pagenum++;
opts->use_list[num] |= USE_PAGE_OBJECT;
@@ -920,9 +920,9 @@ mark_pages(pdf_document *xref, pdf_write_options *opts, pdf_obj *val, int pagenu
pdf_obj *obj = pdf_dict_get_val(val, i);
if (!strcmp("Kids", pdf_to_name(key)))
- pagenum = mark_pages(xref, opts, obj, pagenum);
+ pagenum = mark_pages(doc, opts, obj, pagenum);
else
- mark_all(xref, opts, obj, USE_CATALOGUE, -1);
+ mark_all(doc, opts, obj, USE_CATALOGUE, -1);
}
if (pdf_is_indirect(val))
@@ -938,7 +938,7 @@ mark_pages(pdf_document *xref, pdf_write_options *opts, pdf_obj *val, int pagenu
for (i = 0; i < n; i++)
{
- pagenum = mark_pages(xref, opts, pdf_array_get(val, i), pagenum);
+ pagenum = mark_pages(doc, opts, pdf_array_get(val, i), pagenum);
}
if (pdf_is_indirect(val))
{
@@ -959,9 +959,9 @@ mark_pages(pdf_document *xref, pdf_write_options *opts, pdf_obj *val, int pagenu
}
static void
-mark_root(pdf_document *xref, pdf_write_options *opts, pdf_obj *dict)
+mark_root(pdf_document *doc, pdf_write_options *opts, pdf_obj *dict)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
int i, n = pdf_dict_len(dict);
if (pdf_obj_mark(dict))
@@ -981,11 +981,11 @@ mark_root(pdf_document *xref, pdf_write_options *opts, pdf_obj *dict)
pdf_obj *val = pdf_dict_get_val(dict, i);
if (!strcmp("Pages", key))
- opts->page_count = mark_pages(xref, opts, val, 0);
+ opts->page_count = mark_pages(doc, opts, val, 0);
else if (!strcmp("Names", key))
- mark_all(xref, opts, val, USE_OTHER_OBJECTS, -1);
+ mark_all(doc, opts, val, USE_OTHER_OBJECTS, -1);
else if (!strcmp("Dests", key))
- mark_all(xref, opts, val, USE_OTHER_OBJECTS, -1);
+ mark_all(doc, opts, val, USE_OTHER_OBJECTS, -1);
else if (!strcmp("Outlines", key))
{
int section;
@@ -995,10 +995,10 @@ mark_root(pdf_document *xref, pdf_write_options *opts, pdf_obj *dict)
section = USE_PAGE1;
else
section = USE_OTHER_OBJECTS;
- mark_all(xref, opts, val, section, -1);
+ mark_all(doc, opts, val, section, -1);
}
else
- mark_all(xref, opts, val, USE_CATALOGUE, -1);
+ mark_all(doc, opts, val, USE_CATALOGUE, -1);
}
}
fz_always(ctx)
@@ -1012,9 +1012,9 @@ mark_root(pdf_document *xref, pdf_write_options *opts, pdf_obj *dict)
}
static void
-mark_trailer(pdf_document *xref, pdf_write_options *opts, pdf_obj *dict)
+mark_trailer(pdf_document *doc, pdf_write_options *opts, pdf_obj *dict)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
int i, n = pdf_dict_len(dict);
if (pdf_obj_mark(dict))
@@ -1028,9 +1028,9 @@ mark_trailer(pdf_document *xref, pdf_write_options *opts, pdf_obj *dict)
pdf_obj *val = pdf_dict_get_val(dict, i);
if (!strcmp("Root", key))
- mark_root(xref, opts, val);
+ mark_root(doc, opts, val);
else
- mark_all(xref, opts, val, USE_CATALOGUE, -1);
+ mark_all(doc, opts, val, USE_CATALOGUE, -1);
}
}
fz_always(ctx)
@@ -1311,14 +1311,14 @@ pdf_localise_page_resources(pdf_document *doc)
}
static void
-linearize(pdf_document *xref, pdf_write_options *opts)
+linearize(pdf_document *doc, pdf_write_options *opts)
{
int i;
- int n = pdf_xref_len(xref) + 2;
+ int n = pdf_xref_len(doc) + 2;
int *reorder;
int *rev_renumber_map;
int *rev_gen_list;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
opts->page_object_lists = page_objects_list_create(ctx);
@@ -1326,18 +1326,18 @@ linearize(pdf_document *xref, pdf_write_options *opts)
/* FIXME: We could 'thin' the resources according to what is actually
* required for each page, but this would require us to run the page
* content streams. */
- pdf_localise_page_resources(xref);
+ pdf_localise_page_resources(doc);
/* Walk the objects for each page, marking which ones are used, where */
memset(opts->use_list, 0, n * sizeof(int));
- mark_trailer(xref, opts, pdf_trailer(xref));
+ mark_trailer(doc, opts, pdf_trailer(doc));
/* Add new objects required for linearization */
- add_linearization_objs(xref, opts);
+ add_linearization_objs(doc, opts);
#ifdef DEBUG_WRITING
fprintf(stderr, "Usage calculated:\n");
- for (i=0; i < pdf_xref_len(xref); i++)
+ for (i=0; i < pdf_xref_len(doc); i++)
{
fprintf(stderr, "%d: use=%d\n", i, opts->use_list[i]);
}
@@ -1357,7 +1357,7 @@ linearize(pdf_document *xref, pdf_write_options *opts)
#ifdef DEBUG_WRITING
fprintf(stderr, "Reordered:\n");
- for (i=1; i < pdf_xref_len(xref); i++)
+ for (i=1; i < pdf_xref_len(doc); i++)
{
fprintf(stderr, "%d: use=%d\n", i, opts->use_list[reorder[i]]);
}
@@ -1382,21 +1382,21 @@ linearize(pdf_document *xref, pdf_write_options *opts)
/* Apply the renumber_map */
page_objects_list_renumber(opts);
- renumberobjs(xref, opts);
+ renumberobjs(doc, opts);
page_objects_list_sort_and_dedupe(ctx, opts->page_object_lists);
}
static void
-update_linearization_params(pdf_document *xref, pdf_write_options *opts)
+update_linearization_params(pdf_document *doc, pdf_write_options *opts)
{
int offset;
pdf_set_int(opts->linear_l, opts->file_len);
/* Primary hint stream offset (of object, not stream!) */
- pdf_set_int(opts->linear_h0, opts->ofs_list[pdf_xref_len(xref)-1]);
+ pdf_set_int(opts->linear_h0, opts->ofs_list[pdf_xref_len(doc)-1]);
/* Primary hint stream length (of object, not stream!) */
offset = (opts->start == 1 ? opts->main_xref_offset : opts->ofs_list[1] + opts->hintstream_len);
- pdf_set_int(opts->linear_h1, offset - opts->ofs_list[pdf_xref_len(xref)-1]);
+ pdf_set_int(opts->linear_h1, offset - opts->ofs_list[pdf_xref_len(doc)-1]);
/* Object number of first pages page object (the first object of page 0) */
pdf_set_int(opts->linear_o, opts->page_object_lists->page[0]->object[0]);
/* Offset of end of first page (first page is followed by primary
@@ -1419,17 +1419,17 @@ update_linearization_params(pdf_document *xref, pdf_write_options *opts)
* Make sure we have loaded objects from object streams.
*/
-static void preloadobjstms(pdf_document *xref)
+static void preloadobjstms(pdf_document *doc)
{
pdf_obj *obj;
int num;
- int xref_len = pdf_xref_len(xref);
+ int xref_len = pdf_xref_len(doc);
for (num = 0; num < xref_len; num++)
{
- if (pdf_get_xref_entry(xref, num)->type == 'o')
+ if (pdf_get_xref_entry(doc, num)->type == 'o')
{
- obj = pdf_load_object(xref, num, 0);
+ obj = pdf_load_object(doc, num, 0);
pdf_drop_obj(obj);
}
}
@@ -1614,7 +1614,7 @@ static int is_image_filter(char *s)
return 0;
}
-static int filter_implies_image(pdf_document *xref, pdf_obj *o)
+static int filter_implies_image(pdf_document *doc, pdf_obj *o)
{
if (!o)
return 0;
@@ -1631,16 +1631,16 @@ static int filter_implies_image(pdf_document *xref, pdf_obj *o)
return 0;
}
-static void writeobject(pdf_document *xref, pdf_write_options *opts, int num, int gen)
+static void writeobject(pdf_document *doc, pdf_write_options *opts, int num, int gen)
{
pdf_xref_entry *entry;
pdf_obj *obj;
pdf_obj *type;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_try(ctx)
{
- obj = pdf_load_object(xref, num, gen);
+ obj = pdf_load_object(doc, num, gen);
}
fz_catch(ctx)
{
@@ -1675,8 +1675,8 @@ static void writeobject(pdf_document *xref, pdf_write_options *opts, int num, in
}
}
- entry = pdf_get_xref_entry(xref, num);
- if (!pdf_is_stream(xref, num, gen))
+ entry = pdf_get_xref_entry(doc, num);
+ if (!pdf_is_stream(doc, num, gen))
{
fprintf(opts->out, "%d %d obj\n", num, gen);
pdf_fprint_obj(opts->out, obj, opts->do_expand == 0);
@@ -1712,7 +1712,7 @@ static void writeobject(pdf_document *xref, pdf_write_options *opts, int num, in
dontexpand = !(opts->do_expand & fz_expand_fonts);
if (o = pdf_dict_gets(obj, "Subtype"), !strcmp(pdf_to_name(o), "CIDFontType0C"))
dontexpand = !(opts->do_expand & fz_expand_fonts);
- if (o = pdf_dict_gets(obj, "Filter"), filter_implies_image(xref, o))
+ if (o = pdf_dict_gets(obj, "Filter"), filter_implies_image(doc, o))
dontexpand = !(opts->do_expand & fz_expand_images);
if (pdf_dict_gets(obj, "Width") != NULL && pdf_dict_gets(obj, "Height") != NULL)
dontexpand = !(opts->do_expand & fz_expand_images);
@@ -1720,9 +1720,9 @@ static void writeobject(pdf_document *xref, pdf_write_options *opts, int num, in
fz_try(ctx)
{
if (opts->do_expand && !dontexpand && !pdf_is_jpx_image(ctx, obj))
- expandstream(xref, opts, obj, num, gen);
+ expandstream(doc, opts, obj, num, gen);
else
- copystream(xref, opts, obj, num, gen);
+ copystream(doc, opts, obj, num, gen);
}
fz_catch(ctx)
{
@@ -1830,9 +1830,9 @@ padto(FILE *file, int target)
}
static void
-dowriteobject(pdf_document *xref, pdf_write_options *opts, int num, int pass)
+dowriteobject(pdf_document *doc, pdf_write_options *opts, int num, int pass)
{
- pdf_xref_entry *entry = pdf_get_xref_entry(xref, num);
+ pdf_xref_entry *entry = pdf_get_xref_entry(doc, num);
if (entry->type == 'f')
opts->gen_list[num] = entry->gen;
if (entry->type == 'n')
@@ -1856,22 +1856,22 @@ dowriteobject(pdf_document *xref, pdf_write_options *opts, int num, int pass)
if (pass > 0)
padto(opts->out, opts->ofs_list[num]);
opts->ofs_list[num] = ftell(opts->out);
- writeobject(xref, opts, num, opts->gen_list[num]);
+ writeobject(doc, opts, num, opts->gen_list[num]);
}
else
opts->use_list[num] = 0;
}
static void
-writeobjects(pdf_document *xref, pdf_write_options *opts, int pass)
+writeobjects(pdf_document *doc, pdf_write_options *opts, int pass)
{
int num;
- int xref_len = pdf_xref_len(xref);
+ int xref_len = pdf_xref_len(doc);
- fprintf(opts->out, "%%PDF-%d.%d\n", xref->version / 10, xref->version % 10);
+ fprintf(opts->out, "%%PDF-%d.%d\n", doc->version / 10, doc->version % 10);
fprintf(opts->out, "%%\316\274\341\277\246\n\n");
- dowriteobject(xref, opts, opts->start, pass);
+ dowriteobject(doc, opts, opts->start, pass);
if (opts->do_linear)
{
@@ -1880,11 +1880,11 @@ writeobjects(pdf_document *xref, pdf_write_options *opts, int pass)
opts->first_xref_offset = ftell(opts->out);
else
padto(opts->out, opts->first_xref_offset);
- writexref(xref, opts, opts->start, pdf_xref_len(xref), 1, opts->main_xref_offset, 0);
+ writexref(doc, opts, opts->start, pdf_xref_len(doc), 1, opts->main_xref_offset, 0);
}
for (num = opts->start+1; num < xref_len; num++)
- dowriteobject(xref, opts, num, pass);
+ dowriteobject(doc, opts, num, pass);
if (opts->do_linear && pass == 1)
{
int offset = (opts->start == 1 ? opts->main_xref_offset : opts->ofs_list[1] + opts->hintstream_len);
@@ -1894,7 +1894,7 @@ writeobjects(pdf_document *xref, pdf_write_options *opts, int pass)
{
if (pass == 1)
opts->ofs_list[num] += opts->hintstream_len;
- dowriteobject(xref, opts, num, pass);
+ dowriteobject(doc, opts, num, pass);
}
}
@@ -1916,9 +1916,9 @@ my_log2(int x)
}
static void
-make_page_offset_hints(pdf_document *xref, pdf_write_options *opts, fz_buffer *buf)
+make_page_offset_hints(pdf_document *doc, pdf_write_options *opts, fz_buffer *buf)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
int i, j;
int min_objs_per_page, max_objs_per_page;
int min_page_length, max_page_length;
@@ -1929,9 +1929,9 @@ make_page_offset_hints(pdf_document *xref, pdf_write_options *opts, fz_buffer *b
page_objects **pop = &opts->page_object_lists->page[0];
int page_len_bits, shared_object_bits, shared_object_id_bits;
int shared_length_bits;
- int xref_len = pdf_xref_len(xref);
+ int xref_len = pdf_xref_len(doc);
- min_shared_object = pdf_xref_len(xref);
+ min_shared_object = pdf_xref_len(doc);
max_shared_object = 1;
min_shared_length = opts->file_len;
max_shared_length = 0;
@@ -2187,15 +2187,15 @@ make_page_offset_hints(pdf_document *xref, pdf_write_options *opts, fz_buffer *b
}
static void
-make_hint_stream(pdf_document *xref, pdf_write_options *opts)
+make_hint_stream(pdf_document *doc, pdf_write_options *opts)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_buffer *buf = fz_new_buffer(ctx, 100);
fz_try(ctx)
{
- make_page_offset_hints(xref, opts, buf);
- pdf_update_stream(xref, pdf_xref_len(xref)-1, buf);
+ make_page_offset_hints(doc, opts, buf);
+ pdf_update_stream(doc, pdf_xref_len(doc)-1, buf);
opts->hintstream_len = buf->len;
fz_drop_buffer(ctx, buf);
}
@@ -2207,18 +2207,18 @@ make_hint_stream(pdf_document *xref, pdf_write_options *opts)
}
#ifdef DEBUG_WRITING
-static void dump_object_details(pdf_document *xref, pdf_write_options *opts)
+static void dump_object_details(pdf_document *doc, pdf_write_options *opts)
{
int i;
- for (i = 0; i < pdf_xref_len(xref); i++)
+ for (i = 0; i < pdf_xref_len(doc); i++)
{
fprintf(stderr, "%d@%d: use=%d\n", i, opts->ofs_list[i], opts->use_list[i]);
}
}
#endif
-void pdf_write_document(pdf_document *xref, char *filename, fz_write_options *fz_opts)
+void pdf_write_document(pdf_document *doc, char *filename, fz_write_options *fz_opts)
{
int lastfree;
int num;
@@ -2226,14 +2226,14 @@ void pdf_write_document(pdf_document *xref, char *filename, fz_write_options *fz
fz_context *ctx;
int xref_len;
- if (!xref)
+ if (!doc)
return;
- ctx = xref->ctx;
+ ctx = doc->ctx;
- pdf_finish_edit(xref);
+ pdf_finish_edit(doc);
- xref_len = pdf_xref_len(xref);
+ xref_len = pdf_xref_len(doc);
opts.out = fopen(filename, "wb");
if (!opts.out)
@@ -2250,12 +2250,12 @@ void pdf_write_document(pdf_document *xref, char *filename, fz_write_options *fz
/* We deliberately make these arrays long enough to cope with
* 1 to n access rather than 0..n-1, and add space for 2 new
* extra entries that may be required for linearization. */
- opts.use_list = fz_malloc_array(ctx, pdf_xref_len(xref) + 3, sizeof(int));
- opts.ofs_list = fz_malloc_array(ctx, pdf_xref_len(xref) + 3, sizeof(int));
- opts.gen_list = fz_calloc(ctx, pdf_xref_len(xref) + 3, sizeof(int));
- opts.renumber_map = fz_malloc_array(ctx, pdf_xref_len(xref) + 3, sizeof(int));
- opts.rev_renumber_map = fz_malloc_array(ctx, pdf_xref_len(xref) + 3, sizeof(int));
- opts.rev_gen_list = fz_malloc_array(ctx, pdf_xref_len(xref) + 3, sizeof(int));
+ opts.use_list = fz_malloc_array(ctx, pdf_xref_len(doc) + 3, sizeof(int));
+ opts.ofs_list = fz_malloc_array(ctx, pdf_xref_len(doc) + 3, sizeof(int));
+ opts.gen_list = fz_calloc(ctx, pdf_xref_len(doc) + 3, sizeof(int));
+ opts.renumber_map = fz_malloc_array(ctx, pdf_xref_len(doc) + 3, sizeof(int));
+ opts.rev_renumber_map = fz_malloc_array(ctx, pdf_xref_len(doc) + 3, sizeof(int));
+ opts.rev_gen_list = fz_malloc_array(ctx, pdf_xref_len(doc) + 3, sizeof(int));
opts.continue_on_error = fz_opts->continue_on_error;
opts.errors = fz_opts->errors;
@@ -2265,40 +2265,40 @@ void pdf_write_document(pdf_document *xref, char *filename, fz_write_options *fz
opts.ofs_list[num] = 0;
opts.renumber_map[num] = num;
opts.rev_renumber_map[num] = num;
- opts.rev_gen_list[num] = pdf_get_xref_entry(xref, num)->gen;
+ opts.rev_gen_list[num] = pdf_get_xref_entry(doc, num)->gen;
}
/* Make sure any objects hidden in compressed streams have been loaded */
- preloadobjstms(xref);
+ preloadobjstms(doc);
/* Sweep & mark objects from the trailer */
if (opts.do_garbage >= 1)
- sweepobj(xref, &opts, pdf_trailer(xref));
+ sweepobj(doc, &opts, pdf_trailer(doc));
else
for (num = 0; num < xref_len; num++)
opts.use_list[num] = 1;
/* Coalesce and renumber duplicate objects */
if (opts.do_garbage >= 3)
- removeduplicateobjs(xref, &opts);
+ removeduplicateobjs(doc, &opts);
/* Compact xref by renumbering and removing unused objects */
if (opts.do_garbage >= 2 || opts.do_linear)
- compactxref(xref, &opts);
+ compactxref(doc, &opts);
/* Make renumbering affect all indirect references and update xref */
if (opts.do_garbage >= 2 || opts.do_linear)
- renumberobjs(xref, &opts);
+ renumberobjs(doc, &opts);
if (opts.do_linear)
{
- linearize(xref, &opts);
+ linearize(doc, &opts);
}
- writeobjects(xref, &opts, 0);
+ writeobjects(doc, &opts, 0);
#ifdef DEBUG_WRITING
- dump_object_details(xref, &opts);
+ dump_object_details(doc, &opts);
#endif
/* Construct linked list of free object slots */
@@ -2316,32 +2316,32 @@ void pdf_write_document(pdf_document *xref, char *filename, fz_write_options *fz
if (opts.do_linear)
{
opts.main_xref_offset = ftell(opts.out);
- writexref(xref, &opts, 0, opts.start, 0, 0, opts.first_xref_offset);
+ writexref(doc, &opts, 0, opts.start, 0, 0, opts.first_xref_offset);
opts.file_len = ftell(opts.out);
- make_hint_stream(xref, &opts);
+ make_hint_stream(doc, &opts);
opts.file_len += opts.hintstream_len;
opts.main_xref_offset += opts.hintstream_len;
- update_linearization_params(xref, &opts);
+ update_linearization_params(doc, &opts);
fseek(opts.out, 0, 0);
- writeobjects(xref, &opts, 1);
+ writeobjects(doc, &opts, 1);
padto(opts.out, opts.main_xref_offset);
- writexref(xref, &opts, 0, opts.start, 0, 0, opts.first_xref_offset);
+ writexref(doc, &opts, 0, opts.start, 0, 0, opts.first_xref_offset);
}
else
{
opts.first_xref_offset = ftell(opts.out);
- writexref(xref, &opts, 0, xref_len, 1, 0, opts.first_xref_offset);
+ writexref(doc, &opts, 0, xref_len, 1, 0, opts.first_xref_offset);
}
- xref->dirty = 0;
+ doc->dirty = 0;
}
fz_always(ctx)
{
#ifdef DEBUG_LINEARIZATION
page_objects_dump(&opts);
- objects_dump(xref, &opts);
+ objects_dump(doc, &opts);
#endif
fz_free(ctx, opts.use_list);
fz_free(ctx, opts.ofs_list);
@@ -2435,26 +2435,26 @@ make_page_tree_node(pdf_document *doc, int l, int r, pdf_obj *parent_ref, int ro
}
static void
-pdf_rebuild_page_tree(pdf_document *xref)
+pdf_rebuild_page_tree(pdf_document *doc)
{
pdf_obj *catalog;
pdf_obj *pages;
- if (!xref || !xref->needs_page_tree_rebuild)
+ if (!doc || !doc->needs_page_tree_rebuild)
return;
- catalog = pdf_dict_gets(pdf_trailer(xref), "Root");
- pages = make_page_tree_node(xref, 0, xref->page_len, catalog, 1);
+ catalog = pdf_dict_gets(pdf_trailer(doc), "Root");
+ pages = make_page_tree_node(doc, 0, doc->page_len, catalog, 1);
pdf_dict_puts_drop(catalog, "Pages", pages);
- xref->needs_page_tree_rebuild = 0;
+ doc->needs_page_tree_rebuild = 0;
}
-void pdf_finish_edit(pdf_document *xref)
+void pdf_finish_edit(pdf_document *doc)
{
- if (!xref)
+ if (!doc)
return;
- pdf_rebuild_page_tree(xref);
+ pdf_rebuild_page_tree(doc);
}
diff --git a/source/pdf/pdf-xobject.c b/source/pdf/pdf-xobject.c
index e85b2f75..0924e118 100644
--- a/source/pdf/pdf-xobject.c
+++ b/source/pdf/pdf-xobject.c
@@ -34,11 +34,11 @@ pdf_xobject_size(pdf_xobject *xobj)
}
pdf_xobject *
-pdf_load_xobject(pdf_document *xref, pdf_obj *dict)
+pdf_load_xobject(pdf_document *doc, pdf_obj *dict)
{
pdf_xobject *form;
pdf_obj *obj;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
if ((form = pdf_find_item(ctx, pdf_free_xobject_imp, dict)))
{
@@ -86,7 +86,7 @@ pdf_load_xobject(pdf_document *xref, pdf_obj *dict)
obj = pdf_dict_gets(attrs, "CS");
if (obj)
{
- form->colorspace = pdf_load_colorspace(xref, obj);
+ form->colorspace = pdf_load_colorspace(doc, obj);
if (!form->colorspace)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load xobject colorspace");
}
diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c
index 087931bf..9aa1eab6 100644
--- a/source/pdf/pdf-xref.c
+++ b/source/pdf/pdf-xref.c
@@ -198,35 +198,35 @@ void pdf_replace_xref(pdf_document *doc, pdf_xref_entry *entries, int n)
*/
static void
-pdf_load_version(pdf_document *xref)
+pdf_load_version(pdf_document *doc)
{
char buf[20];
- fz_seek(xref->file, 0, SEEK_SET);
- fz_read_line(xref->file, buf, sizeof buf);
+ fz_seek(doc->file, 0, SEEK_SET);
+ fz_read_line(doc->file, buf, sizeof buf);
if (memcmp(buf, "%PDF-", 5) != 0)
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot recognize version marker");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot recognize version marker");
- xref->version = atoi(buf + 5) * 10 + atoi(buf + 7);
+ doc->version = atoi(buf + 5) * 10 + atoi(buf + 7);
}
static void
-pdf_read_start_xref(pdf_document *xref)
+pdf_read_start_xref(pdf_document *doc)
{
unsigned char buf[1024];
int t, n;
int i;
- fz_seek(xref->file, 0, SEEK_END);
+ fz_seek(doc->file, 0, SEEK_END);
- xref->file_size = fz_tell(xref->file);
+ doc->file_size = fz_tell(doc->file);
- t = fz_maxi(0, xref->file_size - (int)sizeof buf);
- fz_seek(xref->file, t, SEEK_SET);
+ t = fz_maxi(0, doc->file_size - (int)sizeof buf);
+ fz_seek(doc->file, t, SEEK_SET);
- n = fz_read(xref->file, buf, sizeof buf);
+ n = fz_read(doc->file, buf, sizeof buf);
if (n < 0)
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot read from file");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot read from file");
for (i = n - 9; i >= 0; i--)
{
@@ -235,14 +235,14 @@ pdf_read_start_xref(pdf_document *xref)
i += 9;
while (iswhite(buf[i]) && i < n)
i ++;
- xref->startxref = atoi((char*)(buf + i));
- if (xref->startxref != 0)
+ doc->startxref = atoi((char*)(buf + i));
+ if (doc->startxref != 0)
return;
break;
}
}
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot find startxref");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot find startxref");
}
/*
@@ -250,7 +250,7 @@ pdf_read_start_xref(pdf_document *xref)
*/
static int
-pdf_xref_size_from_old_trailer(pdf_document *xref, pdf_lexbuf *buf)
+pdf_xref_size_from_old_trailer(pdf_document *doc, pdf_lexbuf *buf)
{
int len;
char *s;
@@ -261,61 +261,61 @@ pdf_xref_size_from_old_trailer(pdf_document *xref, pdf_lexbuf *buf)
int ofs;
/* Record the current file read offset so that we can reinstate it */
- ofs = fz_tell(xref->file);
+ ofs = fz_tell(doc->file);
- fz_read_line(xref->file, buf->scratch, buf->size);
+ fz_read_line(doc->file, buf->scratch, buf->size);
if (strncmp(buf->scratch, "xref", 4) != 0)
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot find xref marker");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot find xref marker");
while (1)
{
- c = fz_peek_byte(xref->file);
+ c = fz_peek_byte(doc->file);
if (!(c >= '0' && c <= '9'))
break;
- fz_read_line(xref->file, buf->scratch, buf->size);
+ fz_read_line(doc->file, buf->scratch, buf->size);
s = buf->scratch;
fz_strsep(&s, " "); /* ignore ofs */
if (!s)
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "invalid range marker in xref");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "invalid range marker in xref");
len = fz_atoi(fz_strsep(&s, " "));
/* broken pdfs where the section is not on a separate line */
if (s && *s != '\0')
- fz_seek(xref->file, -(2 + (int)strlen(s)), SEEK_CUR);
+ fz_seek(doc->file, -(2 + (int)strlen(s)), SEEK_CUR);
- t = fz_tell(xref->file);
+ t = fz_tell(doc->file);
if (t < 0)
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot tell in file");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot tell in file");
- fz_seek(xref->file, t + 20 * len, SEEK_SET);
+ fz_seek(doc->file, t + 20 * len, SEEK_SET);
}
- fz_try(xref->ctx)
+ fz_try(doc->ctx)
{
pdf_obj *trailer;
- tok = pdf_lex(xref->file, buf);
+ tok = pdf_lex(doc->file, buf);
if (tok != PDF_TOK_TRAILER)
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "expected trailer marker");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "expected trailer marker");
- tok = pdf_lex(xref->file, buf);
+ tok = pdf_lex(doc->file, buf);
if (tok != PDF_TOK_OPEN_DICT)
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "expected trailer dictionary");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "expected trailer dictionary");
- trailer = pdf_parse_dict(xref, xref->file, buf);
+ trailer = pdf_parse_dict(doc, doc->file, buf);
size = pdf_to_int(pdf_dict_gets(trailer, "Size"));
if (!size)
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "trailer missing Size entry");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "trailer missing Size entry");
pdf_drop_obj(trailer);
}
- fz_catch(xref->ctx)
+ fz_catch(doc->ctx)
{
- fz_rethrow_message(xref->ctx, "cannot parse trailer");
+ fz_rethrow_message(doc->ctx, "cannot parse trailer");
}
- fz_seek(xref->file, ofs, SEEK_SET);
+ fz_seek(doc->file, ofs, SEEK_SET);
return size;
}
@@ -419,24 +419,24 @@ pdf_read_old_xref(pdf_document *doc, pdf_lexbuf *buf)
}
static void
-pdf_read_new_xref_section(pdf_document *xref, fz_stream *stm, int i0, int i1, int w0, int w1, int w2)
+pdf_read_new_xref_section(pdf_document *doc, fz_stream *stm, int i0, int i1, int w0, int w1, int w2)
{
int i, n;
if (i0 < 0 || i1 < 0)
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "negative xref stream entry index");
- if (i0 + i1 > pdf_xref_len(xref))
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "xref stream has too many entries");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "negative xref stream entry index");
+ if (i0 + i1 > pdf_xref_len(doc))
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "xref stream has too many entries");
for (i = i0; i < i0 + i1; i++)
{
- pdf_xref_entry *entry = pdf_get_populating_xref_entry(xref, i);
+ pdf_xref_entry *entry = pdf_get_populating_xref_entry(doc, i);
int a = 0;
int b = 0;
int c = 0;
if (fz_is_eof(stm))
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "truncated xref stream");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "truncated xref stream");
for (n = 0; n < w0; n++)
a = (a << 8) + fz_read_byte(stm);
@@ -457,7 +457,7 @@ pdf_read_new_xref_section(pdf_document *xref, fz_stream *stm, int i0, int i1, in
/* Entered with file locked, remains locked throughout. */
static pdf_obj *
-pdf_read_new_xref(pdf_document *xref, pdf_lexbuf *buf)
+pdf_read_new_xref(pdf_document *doc, pdf_lexbuf *buf)
{
fz_stream *stm = NULL;
pdf_obj *trailer = NULL;
@@ -466,7 +466,7 @@ pdf_read_new_xref(pdf_document *xref, pdf_lexbuf *buf)
int num, gen, stm_ofs;
int size, w0, w1, w2;
int t;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_var(trailer);
fz_var(stm);
@@ -474,9 +474,9 @@ pdf_read_new_xref(pdf_document *xref, pdf_lexbuf *buf)
fz_try(ctx)
{
pdf_xref_entry *entry;
- int ofs = fz_tell(xref->file);
- trailer = pdf_parse_ind_obj(xref, xref->file, buf, &num, &gen, &stm_ofs);
- entry = pdf_get_populating_xref_entry(xref, num);
+ int ofs = fz_tell(doc->file);
+ trailer = pdf_parse_ind_obj(doc, doc->file, buf, &num, &gen, &stm_ofs);
+ entry = pdf_get_populating_xref_entry(doc, num);
entry->ofs = ofs;
entry->gen = gen;
entry->stm_ofs = stm_ofs;
@@ -497,10 +497,10 @@ pdf_read_new_xref(pdf_document *xref, pdf_lexbuf *buf)
size = pdf_to_int(obj);
/* Access xref entry to assure table size */
- (void)pdf_get_populating_xref_entry(xref, size-1);
+ (void)pdf_get_populating_xref_entry(doc, size-1);
- if (num < 0 || num >= pdf_xref_len(xref))
- fz_throw(ctx, FZ_ERROR_GENERIC, "object id (%d %d R) out of range (0..%d)", num, gen, pdf_xref_len(xref) - 1);
+ if (num < 0 || num >= pdf_xref_len(doc))
+ fz_throw(ctx, FZ_ERROR_GENERIC, "object id (%d %d R) out of range (0..%d)", num, gen, pdf_xref_len(doc) - 1);
obj = pdf_dict_gets(trailer, "W");
if (!obj)
@@ -522,11 +522,11 @@ pdf_read_new_xref(pdf_document *xref, pdf_lexbuf *buf)
index = pdf_dict_gets(trailer, "Index");
- stm = pdf_open_stream_with_offset(xref, num, gen, trailer, stm_ofs);
+ stm = pdf_open_stream_with_offset(doc, num, gen, trailer, stm_ofs);
if (!index)
{
- pdf_read_new_xref_section(xref, stm, 0, size, w0, w1, w2);
+ pdf_read_new_xref_section(doc, stm, 0, size, w0, w1, w2);
}
else
{
@@ -535,7 +535,7 @@ pdf_read_new_xref(pdf_document *xref, pdf_lexbuf *buf)
{
int i0 = pdf_to_int(pdf_array_get(index, t + 0));
int i1 = pdf_to_int(pdf_array_get(index, t + 1));
- pdf_read_new_xref_section(xref, stm, i0, i1, w0, w1, w2);
+ pdf_read_new_xref_section(doc, stm, i0, i1, w0, w1, w2);
}
}
}
@@ -554,24 +554,24 @@ pdf_read_new_xref(pdf_document *xref, pdf_lexbuf *buf)
/* File is locked on entry, and exit (but may be dropped in the middle) */
static pdf_obj *
-pdf_read_xref(pdf_document *xref, int ofs, pdf_lexbuf *buf)
+pdf_read_xref(pdf_document *doc, int ofs, pdf_lexbuf *buf)
{
int c;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
pdf_obj *trailer;
- fz_seek(xref->file, ofs, SEEK_SET);
+ fz_seek(doc->file, ofs, SEEK_SET);
- while (iswhite(fz_peek_byte(xref->file)))
- fz_read_byte(xref->file);
+ while (iswhite(fz_peek_byte(doc->file)))
+ fz_read_byte(doc->file);
fz_try(ctx)
{
- c = fz_peek_byte(xref->file);
+ c = fz_peek_byte(doc->file);
if (c == 'x')
- trailer = pdf_read_old_xref(xref, buf);
+ trailer = pdf_read_old_xref(doc, buf);
else if (c >= '0' && c <= '9')
- trailer = pdf_read_new_xref(xref, buf);
+ trailer = pdf_read_new_xref(doc, buf);
else
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot recognize xref format");
}
@@ -592,10 +592,10 @@ struct ofs_list_s
};
static int
-read_xref_section(pdf_document *xref, int ofs, pdf_lexbuf *buf, ofs_list *offsets)
+read_xref_section(pdf_document *doc, int ofs, pdf_lexbuf *buf, ofs_list *offsets)
{
pdf_obj *trailer = NULL;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
int xrefstmofs = 0;
int prevofs = 0;
@@ -622,9 +622,9 @@ read_xref_section(pdf_document *xref, int ofs, pdf_lexbuf *buf, ofs_list *offset
}
offsets->list[offsets->len++] = ofs;
- trailer = pdf_read_xref(xref, ofs, buf);
+ trailer = pdf_read_xref(doc, ofs, buf);
- pdf_set_populating_xref_trailer(xref, trailer);
+ pdf_set_populating_xref_trailer(doc, trailer);
/* FIXME: do we overwrite free entries properly? */
xrefstmofs = pdf_to_int(pdf_dict_gets(trailer, "XRefStm"));
@@ -638,7 +638,7 @@ read_xref_section(pdf_document *xref, int ofs, pdf_lexbuf *buf, ofs_list *offset
follow any Prev tag therein, as specified on Page 108 of the PDF reference
1.7
*/
- pdf_drop_obj(pdf_read_xref(xref, xrefstmofs, buf));
+ pdf_drop_obj(pdf_read_xref(doc, xrefstmofs, buf));
}
prevofs = pdf_to_int(pdf_dict_gets(trailer, "Prev"));
@@ -659,9 +659,9 @@ read_xref_section(pdf_document *xref, int ofs, pdf_lexbuf *buf, ofs_list *offset
}
static void
-pdf_read_xref_sections(pdf_document *xref, int ofs, pdf_lexbuf *buf)
+pdf_read_xref_sections(pdf_document *doc, int ofs, pdf_lexbuf *buf)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
ofs_list list;
list.len = 0;
@@ -671,8 +671,8 @@ pdf_read_xref_sections(pdf_document *xref, int ofs, pdf_lexbuf *buf)
{
while(ofs)
{
- pdf_populate_next_xref_level(xref);
- ofs = read_xref_section(xref, ofs, buf, &list);
+ pdf_populate_next_xref_level(doc);
+ ofs = read_xref_section(doc, ofs, buf, &list);
}
}
fz_always(ctx)
@@ -692,72 +692,72 @@ pdf_read_xref_sections(pdf_document *xref, int ofs, pdf_lexbuf *buf)
*/
static void
-pdf_load_xref(pdf_document *xref, pdf_lexbuf *buf)
+pdf_load_xref(pdf_document *doc, pdf_lexbuf *buf)
{
int i;
int xref_len;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
- pdf_load_version(xref);
+ pdf_load_version(doc);
- pdf_read_start_xref(xref);
+ pdf_read_start_xref(doc);
- pdf_read_xref_sections(xref, xref->startxref, buf);
+ pdf_read_xref_sections(doc, doc->startxref, buf);
- if (pdf_xref_len(xref) == 0)
+ if (pdf_xref_len(doc) == 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "found xref was empty");
/* broken pdfs where first object is not free */
- if (pdf_get_xref_entry(xref, 0)->type != 'f')
+ if (pdf_get_xref_entry(doc, 0)->type != 'f')
fz_throw(ctx, FZ_ERROR_GENERIC, "first object in xref is not free");
/* broken pdfs where object offsets are out of range */
- xref_len = pdf_xref_len(xref);
+ xref_len = pdf_xref_len(doc);
for (i = 0; i < xref_len; i++)
{
- pdf_xref_entry *entry = pdf_get_xref_entry(xref, i);
+ pdf_xref_entry *entry = pdf_get_xref_entry(doc, i);
if (entry->type == 'n')
{
/* Special case code: "0000000000 * n" means free,
* according to some producers (inc Quartz) */
if (entry->ofs == 0)
entry->type = 'f';
- else if (entry->ofs <= 0 || entry->ofs >= xref->file_size)
+ else if (entry->ofs <= 0 || entry->ofs >= doc->file_size)
fz_throw(ctx, FZ_ERROR_GENERIC, "object offset out of range: %d (%d 0 R)", entry->ofs, i);
}
if (entry->type == 'o')
- if (entry->ofs <= 0 || entry->ofs >= xref_len || pdf_get_xref_entry(xref, entry->ofs)->type != 'n')
+ if (entry->ofs <= 0 || entry->ofs >= xref_len || pdf_get_xref_entry(doc, entry->ofs)->type != 'n')
fz_throw(ctx, FZ_ERROR_GENERIC, "invalid reference to an objstm that does not exist: %d (%d 0 R)", entry->ofs, i);
}
}
void
-pdf_ocg_set_config(pdf_document *xref, int config)
+pdf_ocg_set_config(pdf_document *doc, int config)
{
int i, j, len, len2;
- pdf_ocg_descriptor *desc = xref->ocg;
+ pdf_ocg_descriptor *desc = doc->ocg;
pdf_obj *obj, *cobj;
char *name;
- obj = pdf_dict_gets(pdf_dict_gets(pdf_trailer(xref), "Root"), "OCProperties");
+ obj = pdf_dict_gets(pdf_dict_gets(pdf_trailer(doc), "Root"), "OCProperties");
if (!obj)
{
if (config == 0)
return;
else
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "Unknown OCG config (None known!)");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "Unknown OCG config (None known!)");
}
if (config == 0)
{
cobj = pdf_dict_gets(obj, "D");
if (!cobj)
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "No default OCG config");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "No default OCG config");
}
else
{
cobj = pdf_array_get(pdf_dict_gets(obj, "Configs"), config);
if (!cobj)
- fz_throw(xref->ctx, FZ_ERROR_GENERIC, "Illegal OCG config");
+ fz_throw(doc->ctx, FZ_ERROR_GENERIC, "Illegal OCG config");
}
pdf_drop_obj(desc->intent);
@@ -836,16 +836,16 @@ pdf_ocg_set_config(pdf_document *xref, int config)
}
static void
-pdf_read_ocg(pdf_document *xref)
+pdf_read_ocg(pdf_document *doc)
{
pdf_obj *obj, *ocg;
int len, i;
pdf_ocg_descriptor *desc;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_var(desc);
- obj = pdf_dict_gets(pdf_dict_gets(pdf_trailer(xref), "Root"), "OCProperties");
+ obj = pdf_dict_gets(pdf_dict_gets(pdf_trailer(doc), "Root"), "OCProperties");
if (!obj)
return;
ocg = pdf_dict_gets(obj, "OCGs");
@@ -866,7 +866,7 @@ pdf_read_ocg(pdf_document *xref)
desc->ocgs[i].gen = pdf_to_gen(o);
desc->ocgs[i].state = 0;
}
- xref->ocg = desc;
+ doc->ocg = desc;
}
fz_catch(ctx)
{
@@ -876,7 +876,7 @@ pdf_read_ocg(pdf_document *xref)
fz_rethrow(ctx);
}
- pdf_ocg_set_config(xref, 0);
+ pdf_ocg_set_config(doc, 0);
}
static void
@@ -1010,58 +1010,58 @@ pdf_init_document(pdf_document *doc)
}
void
-pdf_close_document(pdf_document *xref)
+pdf_close_document(pdf_document *doc)
{
int i;
fz_context *ctx;
- if (!xref)
+ if (!doc)
return;
- ctx = xref->ctx;
+ ctx = doc->ctx;
- pdf_drop_js(xref->js);
+ pdf_drop_js(doc->js);
- pdf_free_xref_sections(xref);
+ pdf_free_xref_sections(doc);
- if (xref->page_objs)
+ if (doc->page_objs)
{
- for (i = 0; i < xref->page_len; i++)
- pdf_drop_obj(xref->page_objs[i]);
- fz_free(ctx, xref->page_objs);
+ for (i = 0; i < doc->page_len; i++)
+ pdf_drop_obj(doc->page_objs[i]);
+ fz_free(ctx, doc->page_objs);
}
- if (xref->page_refs)
+ if (doc->page_refs)
{
- for (i = 0; i < xref->page_len; i++)
- pdf_drop_obj(xref->page_refs[i]);
- fz_free(ctx, xref->page_refs);
+ for (i = 0; i < doc->page_len; i++)
+ pdf_drop_obj(doc->page_refs[i]);
+ fz_free(ctx, doc->page_refs);
}
- if (xref->focus_obj)
- pdf_drop_obj(xref->focus_obj);
- if (xref->file)
- fz_close(xref->file);
- if (xref->crypt)
- pdf_free_crypt(ctx, xref->crypt);
+ if (doc->focus_obj)
+ pdf_drop_obj(doc->focus_obj);
+ if (doc->file)
+ fz_close(doc->file);
+ if (doc->crypt)
+ pdf_free_crypt(ctx, doc->crypt);
- pdf_free_ocg(ctx, xref->ocg);
+ pdf_free_ocg(ctx, doc->ocg);
fz_empty_store(ctx);
- pdf_lexbuf_fin(&xref->lexbuf.base);
+ pdf_lexbuf_fin(&doc->lexbuf.base);
- fz_free(ctx, xref);
+ fz_free(ctx, doc);
}
void
-pdf_print_xref(pdf_document *xref)
+pdf_print_xref(pdf_document *doc)
{
int i;
- int xref_len = pdf_xref_len(xref);
- printf("xref\n0 %d\n", pdf_xref_len(xref));
+ int xref_len = pdf_xref_len(doc);
+ printf("xref\n0 %d\n", xref_len);
for (i = 0; i < xref_len; i++)
{
- pdf_xref_entry *entry = pdf_get_xref_entry(xref, i);
+ pdf_xref_entry *entry = pdf_get_xref_entry(doc, i);
printf("%05d: %010d %05d %c (stm_ofs=%d; stm_buf=%p)\n", i,
entry->ofs,
entry->gen,
@@ -1076,7 +1076,7 @@ pdf_print_xref(pdf_document *xref)
*/
static void
-pdf_load_obj_stm(pdf_document *xref, int num, int gen, pdf_lexbuf *buf)
+pdf_load_obj_stm(pdf_document *doc, int num, int gen, pdf_lexbuf *buf)
{
fz_stream *stm = NULL;
pdf_obj *objstm = NULL;
@@ -1088,7 +1088,7 @@ pdf_load_obj_stm(pdf_document *xref, int num, int gen, pdf_lexbuf *buf)
int count;
int i;
pdf_token tok;
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
fz_var(numbuf);
fz_var(ofsbuf);
@@ -1097,7 +1097,7 @@ pdf_load_obj_stm(pdf_document *xref, int num, int gen, pdf_lexbuf *buf)
fz_try(ctx)
{
- objstm = pdf_load_object(xref, num, gen);
+ objstm = pdf_load_object(doc, num, gen);
count = pdf_to_int(pdf_dict_gets(objstm, "N"));
first = pdf_to_int(pdf_dict_gets(objstm, "First"));
@@ -1110,7 +1110,7 @@ pdf_load_obj_stm(pdf_document *xref, int num, int gen, pdf_lexbuf *buf)
numbuf = fz_calloc(ctx, count, sizeof(int));
ofsbuf = fz_calloc(ctx, count, sizeof(int));
- stm = pdf_open_stream(xref, num, gen);
+ stm = pdf_open_stream(doc, num, gen);
for (i = 0; i < count; i++)
{
tok = pdf_lex(stm, buf);
@@ -1128,11 +1128,11 @@ pdf_load_obj_stm(pdf_document *xref, int num, int gen, pdf_lexbuf *buf)
for (i = 0; i < count; i++)
{
- int xref_len = pdf_xref_len(xref);
+ int xref_len = pdf_xref_len(doc);
pdf_xref_entry *entry;
fz_seek(stm, first + ofsbuf[i], SEEK_SET);
- obj = pdf_parse_stm_obj(xref, stm, buf);
+ obj = pdf_parse_stm_obj(doc, stm, buf);
if (numbuf[i] < 1 || numbuf[i] >= xref_len)
{
@@ -1140,7 +1140,7 @@ pdf_load_obj_stm(pdf_document *xref, int num, int gen, pdf_lexbuf *buf)
fz_throw(ctx, FZ_ERROR_GENERIC, "object id (%d 0 R) out of range (0..%d)", numbuf[i], xref_len - 1);
}
- entry = pdf_get_xref_entry(xref, numbuf[i]);
+ entry = pdf_get_xref_entry(doc, numbuf[i]);
if (entry->type == 'o' && entry->ofs == num)
{
@@ -1166,8 +1166,8 @@ pdf_load_obj_stm(pdf_document *xref, int num, int gen, pdf_lexbuf *buf)
fz_always(ctx)
{
fz_close(stm);
- fz_free(xref->ctx, ofsbuf);
- fz_free(xref->ctx, numbuf);
+ fz_free(ctx, ofsbuf);
+ fz_free(ctx, numbuf);
pdf_drop_obj(objstm);
}
fz_catch(ctx)
@@ -1247,21 +1247,21 @@ pdf_cache_object(pdf_document *doc, int num, int gen)
}
pdf_obj *
-pdf_load_object(pdf_document *xref, int num, int gen)
+pdf_load_object(pdf_document *doc, int num, int gen)
{
- fz_context *ctx = xref->ctx;
+ fz_context *ctx = doc->ctx;
pdf_xref_entry *entry;
fz_try(ctx)
{
- pdf_cache_object(xref, num, gen);
+ pdf_cache_object(doc, num, gen);
}
fz_catch(ctx)
{
fz_rethrow_message(ctx, "cannot load object (%d %d R) into cache", num, gen);
}
- entry = pdf_get_xref_entry(xref, num);
+ entry = pdf_get_xref_entry(doc, num);
assert(entry->obj);
@@ -1275,7 +1275,7 @@ pdf_resolve_indirect(pdf_obj *ref)
int num;
int gen;
fz_context *ctx = NULL; /* Avoid warning for stupid compilers */
- pdf_document *xref;
+ pdf_document *doc;
pdf_xref_entry *entry;
while (pdf_is_indirect(ref))
@@ -1285,15 +1285,15 @@ pdf_resolve_indirect(pdf_obj *ref)
fz_warn(ctx, "Too many indirections (possible indirection cycle involving %d %d R)", num, gen);
return NULL;
}
- xref = pdf_get_indirect_document(ref);
- if (!xref)
+ doc = pdf_get_indirect_document(ref);
+ if (!doc)
return NULL;
- ctx = xref->ctx;
+ ctx = doc->ctx;
num = pdf_to_num(ref);
gen = pdf_to_gen(ref);
fz_try(ctx)
{
- pdf_cache_object(xref, num, gen);
+ pdf_cache_object(doc, num, gen);
}
fz_catch(ctx)
{
@@ -1301,7 +1301,7 @@ pdf_resolve_indirect(pdf_obj *ref)
fz_warn(ctx, "cannot load object (%d %d R) into cache", num, gen);
return NULL;
}
- entry = pdf_get_xref_entry(xref, num);
+ entry = pdf_get_xref_entry(doc, num);
if (!entry->obj)
return NULL;
ref = entry->obj;
@@ -1317,12 +1317,12 @@ pdf_count_objects(pdf_document *doc)
}
int
-pdf_create_object(pdf_document *xref)
+pdf_create_object(pdf_document *doc)
{
/* TODO: reuse free object slots by properly linking free object chains in the ofs field */
pdf_xref_entry *entry;
- int num = pdf_xref_len(xref);
- entry = pdf_get_new_xref_entry(xref, num);
+ int num = pdf_xref_len(doc);
+ entry = pdf_get_new_xref_entry(doc, num);
entry->type = 'f';
entry->ofs = -1;
entry->gen = 0;
@@ -1333,19 +1333,19 @@ pdf_create_object(pdf_document *xref)
}
void
-pdf_delete_object(pdf_document *xref, int num)
+pdf_delete_object(pdf_document *doc, int num)
{
pdf_xref_entry *x;
- if (num < 0 || num >= pdf_xref_len(xref))
+ if (num < 0 || num >= pdf_xref_len(doc))
{
- fz_warn(xref->ctx, "object out of range (%d 0 R); xref size %d", num, pdf_xref_len(xref));
+ fz_warn(doc->ctx, "object out of range (%d 0 R); xref size %d", num, pdf_xref_len(doc));
return;
}
- x = pdf_get_new_xref_entry(xref, num);
+ x = pdf_get_new_xref_entry(doc, num);
- fz_drop_buffer(xref->ctx, x->stm_buf);
+ fz_drop_buffer(doc->ctx, x->stm_buf);
pdf_drop_obj(x->obj);
x->type = 'f';
@@ -1357,17 +1357,17 @@ pdf_delete_object(pdf_document *xref, int num)
}
void
-pdf_update_object(pdf_document *xref, int num, pdf_obj *newobj)
+pdf_update_object(pdf_document *doc, int num, pdf_obj *newobj)
{
pdf_xref_entry *x;
- if (num < 0 || num >= pdf_xref_len(xref))
+ if (num < 0 || num >= pdf_xref_len(doc))
{
- fz_warn(xref->ctx, "object out of range (%d 0 R); xref size %d", num, pdf_xref_len(xref));
+ fz_warn(doc->ctx, "object out of range (%d 0 R); xref size %d", num, pdf_xref_len(doc));
return;
}
- x = pdf_get_new_xref_entry(xref, num);
+ x = pdf_get_new_xref_entry(doc, num);
pdf_drop_obj(x->obj);
@@ -1377,20 +1377,20 @@ pdf_update_object(pdf_document *xref, int num, pdf_obj *newobj)
}
void
-pdf_update_stream(pdf_document *xref, int num, fz_buffer *newbuf)
+pdf_update_stream(pdf_document *doc, int num, fz_buffer *newbuf)
{
pdf_xref_entry *x;
- if (num < 0 || num >= pdf_xref_len(xref))
+ if (num < 0 || num >= pdf_xref_len(doc))
{
- fz_warn(xref->ctx, "object out of range (%d 0 R); xref size %d", num, pdf_xref_len(xref));
+ fz_warn(doc->ctx, "object out of range (%d 0 R); xref size %d", num, pdf_xref_len(doc));
return;
}
- x = pdf_get_xref_entry(xref, num);
+ x = pdf_get_xref_entry(doc, num);
- fz_drop_buffer(xref->ctx, x->stm_buf);
- x->stm_buf = fz_keep_buffer(xref->ctx, newbuf);
+ fz_drop_buffer(doc->ctx, x->stm_buf);
+ x->stm_buf = fz_keep_buffer(doc->ctx, newbuf);
}
int