summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/jni/mupdf.c8
-rw-r--r--apps/pdfapp.c34
-rw-r--r--apps/pdfapp.h4
-rw-r--r--apps/pdfclean.c6
-rw-r--r--apps/pdfdraw.c56
-rw-r--r--apps/pdfextract.c22
-rw-r--r--apps/pdfinfo.c6
-rw-r--r--apps/pdfshow.c44
-rw-r--r--apps/win_main.c24
-rw-r--r--apps/xpsdraw.c6
-rw-r--r--fitz/base_object.c2
-rw-r--r--fitz/fitz.h8
-rw-r--r--fitz/res_font.c8
-rw-r--r--ios/document.c15
-rw-r--r--ios/document.h2
-rw-r--r--pdf/mupdf.h116
-rw-r--r--pdf/pdf_annot.c14
-rw-r--r--pdf/pdf_cmap_load.c2
-rw-r--r--pdf/pdf_colorspace.c10
-rw-r--r--pdf/pdf_crypt.c14
-rw-r--r--pdf/pdf_font.c14
-rw-r--r--pdf/pdf_function.c8
-rw-r--r--pdf/pdf_image.c10
-rw-r--r--pdf/pdf_interpret.c10
-rw-r--r--pdf/pdf_nametree.c8
-rw-r--r--pdf/pdf_outline.c4
-rw-r--r--pdf/pdf_page.c16
-rw-r--r--pdf/pdf_parse.c8
-rw-r--r--pdf/pdf_pattern.c2
-rw-r--r--pdf/pdf_repair.c6
-rw-r--r--pdf/pdf_shade.c20
-rw-r--r--pdf/pdf_stream.c22
-rw-r--r--pdf/pdf_type3.c8
-rw-r--r--pdf/pdf_unicode.c2
-rw-r--r--pdf/pdf_xobject.c2
-rw-r--r--pdf/pdf_xref.c64
-rw-r--r--xps/muxps.h6
-rw-r--r--xps/xps_zip.c16
38 files changed, 310 insertions, 317 deletions
diff --git a/android/jni/mupdf.c b/android/jni/mupdf.c
index 5d7eeb0de..757c02c08 100644
--- a/android/jni/mupdf.c
+++ b/android/jni/mupdf.c
@@ -22,7 +22,7 @@
22 22
23/* Globals */ 23/* Globals */
24fz_colorspace *colorspace; 24fz_colorspace *colorspace;
25pdf_xref *xref; 25pdf_document *xref;
26int pagenum = 1; 26int pagenum = 1;
27int resolution = 160; 27int resolution = 160;
28float pageWidth = 100; 28float pageWidth = 100;
@@ -64,7 +64,7 @@ Java_com_artifex_mupdf_MuPDFCore_openFile(JNIEnv * env, jobject thiz, jstring jf
64 LOGE("Opening document..."); 64 LOGE("Opening document...");
65 fz_try(ctx) 65 fz_try(ctx)
66 { 66 {
67 xref = pdf_open_xref(ctx, filename); 67 xref = pdf_open_document(ctx, filename);
68 } 68 }
69 fz_catch(ctx) 69 fz_catch(ctx)
70 { 70 {
@@ -76,7 +76,7 @@ Java_com_artifex_mupdf_MuPDFCore_openFile(JNIEnv * env, jobject thiz, jstring jf
76 fz_catch(ctx) 76 fz_catch(ctx)
77 { 77 {
78 LOGE("Failed: %s", ctx->error->message); 78 LOGE("Failed: %s", ctx->error->message);
79 pdf_free_xref(xref); 79 pdf_close_document(xref);
80 xref = NULL; 80 xref = NULL;
81 fz_free_context(ctx); 81 fz_free_context(ctx);
82 ctx = NULL; 82 ctx = NULL;
@@ -247,6 +247,6 @@ Java_com_artifex_mupdf_MuPDFCore_destroying(JNIEnv * env, jobject thiz)
247{ 247{
248 fz_free_display_list(ctx, currentPageList); 248 fz_free_display_list(ctx, currentPageList);
249 currentPageList = NULL; 249 currentPageList = NULL;
250 pdf_free_xref(xref); 250 pdf_close_document(xref);
251 xref = NULL; 251 xref = NULL;
252} 252}
diff --git a/apps/pdfapp.c b/apps/pdfapp.c
index 3ad71c9ab..9a3b9d0f4 100644
--- a/apps/pdfapp.c
+++ b/apps/pdfapp.c
@@ -107,13 +107,13 @@ static void pdfapp_open_pdf(pdfapp_t *app, char *filename, int fd)
107 fz_context *ctx = app->ctx; 107 fz_context *ctx = app->ctx;
108 108
109 /* 109 /*
110 * Open PDF and load xref table 110 * Open PDF document
111 */ 111 */
112 112
113 fz_try(ctx) 113 fz_try(ctx)
114 { 114 {
115 file = fz_open_fd(ctx, fd); 115 file = fz_open_fd(ctx, fd);
116 app->xref = pdf_open_xref_with_stream(file); 116 app->pdf = pdf_open_document_with_stream(file);
117 fz_close(file); 117 fz_close(file);
118 } 118 }
119 fz_catch(ctx) 119 fz_catch(ctx)
@@ -125,15 +125,15 @@ static void pdfapp_open_pdf(pdfapp_t *app, char *filename, int fd)
125 * Handle encrypted PDF files 125 * Handle encrypted PDF files
126 */ 126 */
127 127
128 if (pdf_needs_password(app->xref)) 128 if (pdf_needs_password(app->pdf))
129 { 129 {
130 int okay = pdf_authenticate_password(app->xref, password); 130 int okay = pdf_authenticate_password(app->pdf, password);
131 while (!okay) 131 while (!okay)
132 { 132 {
133 password = winpassword(app, filename); 133 password = winpassword(app, filename);
134 if (!password) 134 if (!password)
135 pdfapp_error(app, "Needs a password."); 135 pdfapp_error(app, "Needs a password.");
136 okay = pdf_authenticate_password(app->xref, password); 136 okay = pdf_authenticate_password(app->pdf, password);
137 if (!okay) 137 if (!okay)
138 pdfapp_warn(app, "Invalid password."); 138 pdfapp_warn(app, "Invalid password.");
139 } 139 }
@@ -143,7 +143,7 @@ static void pdfapp_open_pdf(pdfapp_t *app, char *filename, int fd)
143 * Load meta information 143 * Load meta information
144 */ 144 */
145 145
146 info = fz_dict_gets(app->xref->trailer, "Info"); 146 info = fz_dict_gets(app->pdf->trailer, "Info");
147 if (info) 147 if (info)
148 { 148 {
149 obj = fz_dict_gets(info, "Title"); 149 obj = fz_dict_gets(info, "Title");
@@ -164,9 +164,9 @@ static void pdfapp_open_pdf(pdfapp_t *app, char *filename, int fd)
164 * Start at first page 164 * Start at first page
165 */ 165 */
166 166
167 app->pagecount = pdf_count_pages(app->xref); 167 app->pagecount = pdf_count_pages(app->pdf);
168 168
169 app->outline = pdf_load_outline(app->xref); 169 app->outline = pdf_load_outline(app->pdf);
170} 170}
171 171
172static void pdfapp_open_xps(pdfapp_t *app, char *filename, int fd) 172static void pdfapp_open_xps(pdfapp_t *app, char *filename, int fd)
@@ -176,7 +176,7 @@ static void pdfapp_open_xps(pdfapp_t *app, char *filename, int fd)
176 file = fz_open_fd(app->ctx, fd); 176 file = fz_open_fd(app->ctx, fd);
177 fz_try(app->ctx) 177 fz_try(app->ctx)
178 { 178 {
179 app->xps = xps_open_stream(file); 179 app->xps = xps_open_document_with_stream(file);
180 } 180 }
181 fz_catch(app->ctx) 181 fz_catch(app->ctx)
182 { 182 {
@@ -242,15 +242,15 @@ void pdfapp_close(pdfapp_t *app)
242 fz_free_outline(app->outline); 242 fz_free_outline(app->outline);
243 app->outline = NULL; 243 app->outline = NULL;
244 244
245 if (app->xref) 245 if (app->pdf)
246 { 246 {
247 pdf_free_xref(app->xref); 247 pdf_close_document(app->pdf);
248 app->xref = NULL; 248 app->pdf = NULL;
249 } 249 }
250 250
251 if (app->xps) 251 if (app->xps)
252 { 252 {
253 xps_free_context(app->xps); 253 xps_close_document(app->xps);
254 app->xps = NULL; 254 app->xps = NULL;
255 } 255 }
256 256
@@ -296,14 +296,14 @@ static void pdfapp_loadpage_pdf(pdfapp_t *app)
296 296
297 fz_try(app->ctx) 297 fz_try(app->ctx)
298 { 298 {
299 page = pdf_load_page(app->xref, app->pageno - 1); 299 page = pdf_load_page(app->pdf, app->pageno - 1);
300 } 300 }
301 fz_catch(app->ctx) 301 fz_catch(app->ctx)
302 { 302 {
303 pdfapp_error(app, "cannot load page"); 303 pdfapp_error(app, "cannot load page");
304 } 304 }
305 305
306 app->page_bbox = pdf_bound_page(app->xref, page); 306 app->page_bbox = pdf_bound_page(app->pdf, page);
307 app->page_links = page->links; 307 app->page_links = page->links;
308 page->links = NULL; 308 page->links = NULL;
309 309
@@ -312,7 +312,7 @@ static void pdfapp_loadpage_pdf(pdfapp_t *app)
312 mdev = fz_new_list_device(app->ctx, app->page_list); 312 mdev = fz_new_list_device(app->ctx, app->page_list);
313 fz_try(app->ctx) 313 fz_try(app->ctx)
314 { 314 {
315 pdf_run_page(app->xref, page, mdev, fz_identity, NULL); 315 pdf_run_page(app->pdf, page, mdev, fz_identity, NULL);
316 } 316 }
317 fz_catch(app->ctx) 317 fz_catch(app->ctx)
318 { 318 {
@@ -369,7 +369,7 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage, int repai
369 if (app->page_links) 369 if (app->page_links)
370 fz_free_link(app->ctx, app->page_links); 370 fz_free_link(app->ctx, app->page_links);
371 371
372 if (app->xref) 372 if (app->pdf)
373 pdfapp_loadpage_pdf(app); 373 pdfapp_loadpage_pdf(app);
374 if (app->xps) 374 if (app->xps)
375 pdfapp_loadpage_xps(app); 375 pdfapp_loadpage_xps(app);
diff --git a/apps/pdfapp.h b/apps/pdfapp.h
index 7aad1238f..c1b03be24 100644
--- a/apps/pdfapp.h
+++ b/apps/pdfapp.h
@@ -30,10 +30,10 @@ extern void winfullscreen(pdfapp_t*, int state);
30struct pdfapp_s 30struct pdfapp_s
31{ 31{
32 /* current document params */ 32 /* current document params */
33 pdf_document *pdf;
34 xps_document *xps;
33 char *doctitle; 35 char *doctitle;
34 pdf_xref *xref;
35 fz_outline *outline; 36 fz_outline *outline;
36 xps_document *xps;
37 37
38 int pagecount; 38 int pagecount;
39 39
diff --git a/apps/pdfclean.c b/apps/pdfclean.c
index 82eb7c03e..8a163502a 100644
--- a/apps/pdfclean.c
+++ b/apps/pdfclean.c
@@ -30,7 +30,7 @@ static int dogarbage = 0;
30static int doexpand = 0; 30static int doexpand = 0;
31static int doascii = 0; 31static int doascii = 0;
32 32
33static pdf_xref *xref = NULL; 33static pdf_document *xref = NULL;
34static fz_context *ctx = NULL; 34static fz_context *ctx = NULL;
35 35
36static void usage(void) 36static void usage(void)
@@ -775,7 +775,7 @@ int main(int argc, char **argv)
775 exit(1); 775 exit(1);
776 } 776 }
777 777
778 xref = pdf_open_xref(ctx, infile); 778 xref = pdf_open_document(ctx, infile);
779 if (pdf_needs_password(xref)) 779 if (pdf_needs_password(xref))
780 if (!pdf_authenticate_password(xref, password)) 780 if (!pdf_authenticate_password(xref, password))
781 fz_throw(ctx, "cannot authenticate password: %s\n", infile); 781 fz_throw(ctx, "cannot authenticate password: %s\n", infile);
@@ -836,7 +836,7 @@ int main(int argc, char **argv)
836 fz_free(xref->ctx, genlist); 836 fz_free(xref->ctx, genlist);
837 fz_free(xref->ctx, renumbermap); 837 fz_free(xref->ctx, renumbermap);
838 838
839 pdf_free_xref(xref); 839 pdf_close_document(xref);
840 fz_free_context(ctx); 840 fz_free_context(ctx);
841 return 0; 841 return 0;
842} 842}
diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c
index 893b5b2b3..552fe31ac 100644
--- a/apps/pdfdraw.c
+++ b/apps/pdfdraw.c
@@ -85,13 +85,13 @@ static int isrange(char *s)
85 return 1; 85 return 1;
86} 86}
87 87
88static void drawpage(pdf_xref *xref, int pagenum) 88static void drawpage(pdf_document *doc, int pagenum)
89{ 89{
90 pdf_page *page; 90 pdf_page *page;
91 fz_display_list *list = NULL; 91 fz_display_list *list = NULL;
92 fz_device *dev = NULL; 92 fz_device *dev = NULL;
93 int start; 93 int start;
94 fz_context *ctx = xref->ctx; 94 fz_context *ctx = doc->ctx;
95 95
96 fz_var(list); 96 fz_var(list);
97 fz_var(dev); 97 fz_var(dev);
@@ -103,7 +103,7 @@ static void drawpage(pdf_xref *xref, int pagenum)
103 103
104 fz_try(ctx) 104 fz_try(ctx)
105 { 105 {
106 page = pdf_load_page(xref, pagenum - 1); 106 page = pdf_load_page(doc, pagenum - 1);
107 } 107 }
108 fz_catch(ctx) 108 fz_catch(ctx)
109 { 109 {
@@ -116,7 +116,7 @@ static void drawpage(pdf_xref *xref, int pagenum)
116 { 116 {
117 list = fz_new_display_list(ctx); 117 list = fz_new_display_list(ctx);
118 dev = fz_new_list_device(ctx, list); 118 dev = fz_new_list_device(ctx, list);
119 pdf_run_page(xref, page, dev, fz_identity, NULL); 119 pdf_run_page(doc, page, dev, fz_identity, NULL);
120 } 120 }
121 fz_catch(ctx) 121 fz_catch(ctx)
122 { 122 {
@@ -138,7 +138,7 @@ static void drawpage(pdf_xref *xref, int pagenum)
138 if (list) 138 if (list)
139 fz_execute_display_list(list, dev, fz_identity, fz_infinite_bbox, NULL); 139 fz_execute_display_list(list, dev, fz_identity, fz_infinite_bbox, NULL);
140 else 140 else
141 pdf_run_page(xref, page, dev, fz_identity, NULL); 141 pdf_run_page(doc, page, dev, fz_identity, NULL);
142 printf("</page>\n"); 142 printf("</page>\n");
143 } 143 }
144 fz_catch(ctx) 144 fz_catch(ctx)
@@ -165,7 +165,7 @@ static void drawpage(pdf_xref *xref, int pagenum)
165 if (list) 165 if (list)
166 fz_execute_display_list(list, dev, fz_identity, fz_infinite_bbox, NULL); 166 fz_execute_display_list(list, dev, fz_identity, fz_infinite_bbox, NULL);
167 else 167 else
168 pdf_run_page(xref, page, dev, fz_identity, NULL); 168 pdf_run_page(doc, page, dev, fz_identity, NULL);
169 fz_free_device(dev); 169 fz_free_device(dev);
170 dev = NULL; 170 dev = NULL;
171 printf("[Page %d]\n", pagenum); 171 printf("[Page %d]\n", pagenum);
@@ -199,7 +199,7 @@ static void drawpage(pdf_xref *xref, int pagenum)
199 199
200 fz_var(pix); 200 fz_var(pix);
201 201
202 bounds = pdf_bound_page(xref, page); 202 bounds = pdf_bound_page(doc, page);
203 zoom = resolution / 72; 203 zoom = resolution / 72;
204 ctm = fz_scale(zoom, zoom); 204 ctm = fz_scale(zoom, zoom);
205 ctm = fz_concat(ctm, fz_rotate(rotation)); 205 ctm = fz_concat(ctm, fz_rotate(rotation));
@@ -220,7 +220,7 @@ static void drawpage(pdf_xref *xref, int pagenum)
220 if (list) 220 if (list)
221 fz_execute_display_list(list, dev, ctm, bbox, NULL); 221 fz_execute_display_list(list, dev, ctm, bbox, NULL);
222 else 222 else
223 pdf_run_page(xref, page, dev, ctm, NULL); 223 pdf_run_page(doc, page, dev, ctm, NULL);
224 fz_free_device(dev); 224 fz_free_device(dev);
225 dev = NULL; 225 dev = NULL;
226 226
@@ -310,7 +310,7 @@ static void drawpage(pdf_xref *xref, int pagenum)
310 fz_flush_warnings(ctx); 310 fz_flush_warnings(ctx);
311} 311}
312 312
313static void drawrange(pdf_xref *xref, char *range) 313static void drawrange(pdf_document *doc, char *range)
314{ 314{
315 int page, spage, epage; 315 int page, spage, epage;
316 char *spec, *dash; 316 char *spec, *dash;
@@ -321,7 +321,7 @@ static void drawrange(pdf_xref *xref, char *range)
321 dash = strchr(spec, '-'); 321 dash = strchr(spec, '-');
322 322
323 if (dash == spec) 323 if (dash == spec)
324 spage = epage = pdf_count_pages(xref); 324 spage = epage = pdf_count_pages(doc);
325 else 325 else
326 spage = epage = atoi(spec); 326 spage = epage = atoi(spec);
327 327
@@ -330,26 +330,26 @@ static void drawrange(pdf_xref *xref, char *range)
330 if (strlen(dash) > 1) 330 if (strlen(dash) > 1)
331 epage = atoi(dash + 1); 331 epage = atoi(dash + 1);
332 else 332 else
333 epage = pdf_count_pages(xref); 333 epage = pdf_count_pages(doc);
334 } 334 }
335 335
336 spage = CLAMP(spage, 1, pdf_count_pages(xref)); 336 spage = CLAMP(spage, 1, pdf_count_pages(doc));
337 epage = CLAMP(epage, 1, pdf_count_pages(xref)); 337 epage = CLAMP(epage, 1, pdf_count_pages(doc));
338 338
339 if (spage < epage) 339 if (spage < epage)
340 for (page = spage; page <= epage; page++) 340 for (page = spage; page <= epage; page++)
341 drawpage(xref, page); 341 drawpage(doc, page);
342 else 342 else
343 for (page = spage; page >= epage; page--) 343 for (page = spage; page >= epage; page--)
344 drawpage(xref, page); 344 drawpage(doc, page);
345 345
346 spec = fz_strsep(&range, ","); 346 spec = fz_strsep(&range, ",");
347 } 347 }
348} 348}
349 349
350static void drawoutline(pdf_xref *xref) 350static void drawoutline(pdf_document *doc)
351{ 351{
352 fz_outline *outline = pdf_load_outline(xref); 352 fz_outline *outline = pdf_load_outline(doc);
353 if (showoutline > 1) 353 if (showoutline > 1)
354 fz_debug_outline_xml(outline, 0); 354 fz_debug_outline_xml(outline, 0);
355 else 355 else
@@ -366,11 +366,11 @@ int main(int argc, char **argv)
366 char *password = ""; 366 char *password = "";
367 int grayscale = 0; 367 int grayscale = 0;
368 int accelerate = 1; 368 int accelerate = 1;
369 pdf_xref *xref = NULL; 369 pdf_document *doc = NULL;
370 int c; 370 int c;
371 fz_context *ctx; 371 fz_context *ctx;
372 372
373 fz_var(xref); 373 fz_var(doc);
374 374
375 while ((c = fz_getopt(argc, argv, "lo:p:r:R:Aab:dgmtx5G:I")) != -1) 375 while ((c = fz_getopt(argc, argv, "lo:p:r:R:Aab:dgmtx5G:I")) != -1)
376 { 376 {
@@ -445,41 +445,41 @@ int main(int argc, char **argv)
445 445
446 fz_try(ctx) 446 fz_try(ctx)
447 { 447 {
448 xref = pdf_open_xref(ctx, filename); 448 doc = pdf_open_document(ctx, filename);
449 } 449 }
450 fz_catch(ctx) 450 fz_catch(ctx)
451 { 451 {
452 fz_throw(ctx, "cannot open document: %s", filename); 452 fz_throw(ctx, "cannot open document: %s", filename);
453 } 453 }
454 454
455 if (pdf_needs_password(xref)) 455 if (pdf_needs_password(doc))
456 if (!pdf_authenticate_password(xref, password)) 456 if (!pdf_authenticate_password(doc, password))
457 fz_throw(ctx, "cannot authenticate password: %s", filename); 457 fz_throw(ctx, "cannot authenticate password: %s", filename);
458 458
459 if (showxml) 459 if (showxml)
460 printf("<document name=\"%s\">\n", filename); 460 printf("<document name=\"%s\">\n", filename);
461 461
462 if (showoutline) 462 if (showoutline)
463 drawoutline(xref); 463 drawoutline(doc);
464 464
465 if (showtext || showxml || showtime || showmd5 || output) 465 if (showtext || showxml || showtime || showmd5 || output)
466 { 466 {
467 if (fz_optind == argc || !isrange(argv[fz_optind])) 467 if (fz_optind == argc || !isrange(argv[fz_optind]))
468 drawrange(xref, "1-"); 468 drawrange(doc, "1-");
469 if (fz_optind < argc && isrange(argv[fz_optind])) 469 if (fz_optind < argc && isrange(argv[fz_optind]))
470 drawrange(xref, argv[fz_optind++]); 470 drawrange(doc, argv[fz_optind++]);
471 } 471 }
472 472
473 if (showxml) 473 if (showxml)
474 printf("</document>\n"); 474 printf("</document>\n");
475 475
476 pdf_free_xref(xref); 476 pdf_close_document(doc);
477 xref = NULL; 477 doc = NULL;
478 } 478 }
479 } 479 }
480 fz_catch(ctx) 480 fz_catch(ctx)
481 { 481 {
482 pdf_free_xref(xref); 482 pdf_close_document(doc);
483 } 483 }
484 484
485 if (showtime) 485 if (showtime)
diff --git a/apps/pdfextract.c b/apps/pdfextract.c
index f69fd751a..1407f7f3e 100644
--- a/apps/pdfextract.c
+++ b/apps/pdfextract.c
@@ -5,7 +5,7 @@
5#include "fitz.h" 5#include "fitz.h"
6#include "mupdf.h" 6#include "mupdf.h"
7 7
8static pdf_xref *xref = NULL; 8static pdf_document *doc = NULL;
9static fz_context *ctx = NULL; 9static fz_context *ctx = NULL;
10static int dorgb = 0; 10static int dorgb = 0;
11 11
@@ -35,11 +35,11 @@ static void saveimage(int num)
35 fz_obj *ref; 35 fz_obj *ref;
36 char name[1024]; 36 char name[1024];
37 37
38 ref = fz_new_indirect(ctx, num, 0, xref); 38 ref = fz_new_indirect(ctx, num, 0, doc);
39 39
40 /* TODO: detect DCTD and save as jpeg */ 40 /* TODO: detect DCTD and save as jpeg */
41 41
42 img = pdf_load_image(xref, ref); 42 img = pdf_load_image(doc, ref);
43 43
44 if (dorgb && img->colorspace && img->colorspace != fz_device_rgb) 44 if (dorgb && img->colorspace && img->colorspace != fz_device_rgb)
45 { 45 {
@@ -121,7 +121,7 @@ static void savefont(fz_obj *dict, int num)
121 return; 121 return;
122 } 122 }
123 123
124 buf = pdf_load_stream(xref, fz_to_num(stream), fz_to_gen(stream)); 124 buf = pdf_load_stream(doc, fz_to_num(stream), fz_to_gen(stream));
125 125
126 sprintf(name, "%s-%04d.%s", fontname, num, ext); 126 sprintf(name, "%s-%04d.%s", fontname, num, ext);
127 printf("extracting font %s\n", name); 127 printf("extracting font %s\n", name);
@@ -144,10 +144,10 @@ static void showobject(int num)
144{ 144{
145 fz_obj *obj; 145 fz_obj *obj;
146 146
147 if (!xref) 147 if (!doc)
148 fz_throw(ctx, "no file specified"); 148 fz_throw(ctx, "no file specified");
149 149
150 obj = pdf_load_object(xref, num, 0); 150 obj = pdf_load_object(doc, num, 0);
151 151
152 if (isimage(obj)) 152 if (isimage(obj))
153 saveimage(num); 153 saveimage(num);
@@ -189,14 +189,14 @@ int main(int argc, char **argv)
189 exit(1); 189 exit(1);
190 } 190 }
191 191
192 xref = pdf_open_xref(ctx, infile); 192 doc = pdf_open_document(ctx, infile);
193 if (pdf_needs_password(xref)) 193 if (pdf_needs_password(doc))
194 if (!pdf_authenticate_password(xref, password)) 194 if (!pdf_authenticate_password(doc, password))
195 fz_throw(ctx, "cannot authenticate password: %s\n", infile); 195 fz_throw(ctx, "cannot authenticate password: %s\n", infile);
196 196
197 if (fz_optind == argc) 197 if (fz_optind == argc)
198 { 198 {
199 for (o = 0; o < xref->len; o++) 199 for (o = 0; o < doc->len; o++)
200 showobject(o); 200 showobject(o);
201 } 201 }
202 else 202 else
@@ -208,7 +208,7 @@ int main(int argc, char **argv)
208 } 208 }
209 } 209 }
210 210
211 pdf_free_xref(xref); 211 pdf_close_document(doc);
212 fz_flush_warnings(ctx); 212 fz_flush_warnings(ctx);
213 fz_free_context(ctx); 213 fz_free_context(ctx);
214 return 0; 214 return 0;
diff --git a/apps/pdfinfo.c b/apps/pdfinfo.c
index 47f26c188..c6c6b35c9 100644
--- a/apps/pdfinfo.c
+++ b/apps/pdfinfo.c
@@ -6,7 +6,7 @@
6#include "fitz.h" 6#include "fitz.h"
7#include "mupdf.h" 7#include "mupdf.h"
8 8
9pdf_xref *xref; 9pdf_document *xref;
10fz_context *ctx; 10fz_context *ctx;
11int pagecount; 11int pagecount;
12 12
@@ -94,7 +94,7 @@ void closexref(void)
94 int i; 94 int i;
95 if (xref) 95 if (xref)
96 { 96 {
97 pdf_free_xref(xref); 97 pdf_close_document(xref);
98 xref = NULL; 98 xref = NULL;
99 } 99 }
100 100
@@ -993,7 +993,7 @@ int main(int argc, char **argv)
993 993
994 filename = argv[fz_optind]; 994 filename = argv[fz_optind];
995 printf("%s:\n", filename); 995 printf("%s:\n", filename);
996 xref = pdf_open_xref(ctx, filename); 996 xref = pdf_open_document(ctx, filename);
997 if (pdf_needs_password(xref)) 997 if (pdf_needs_password(xref))
998 if (!pdf_authenticate_password(xref, password)) 998 if (!pdf_authenticate_password(xref, password))
999 fz_throw(ctx, "cannot authenticate password: %s\n", filename); 999 fz_throw(ctx, "cannot authenticate password: %s\n", filename);
diff --git a/apps/pdfshow.c b/apps/pdfshow.c
index 2fbfdc2f9..53578fd7c 100644
--- a/apps/pdfshow.c
+++ b/apps/pdfshow.c
@@ -5,7 +5,7 @@
5#include "fitz.h" 5#include "fitz.h"
6#include "mupdf.h" 6#include "mupdf.h"
7 7
8static pdf_xref *xref = NULL; 8static pdf_document *doc = NULL;
9static fz_context *ctx = NULL; 9static fz_context *ctx = NULL;
10static int showbinary = 0; 10static int showbinary = 0;
11static int showdecode = 1; 11static int showdecode = 1;
@@ -22,18 +22,18 @@ static void usage(void)
22 22
23static void showtrailer(void) 23static void showtrailer(void)
24{ 24{
25 if (!xref) 25 if (!doc)
26 fz_throw(ctx, "no file specified"); 26 fz_throw(ctx, "no file specified");
27 printf("trailer\n"); 27 printf("trailer\n");
28 fz_debug_obj(xref->trailer); 28 fz_debug_obj(doc->trailer);
29 printf("\n"); 29 printf("\n");
30} 30}
31 31
32static void showxref(void) 32static void showxref(void)
33{ 33{
34 if (!xref) 34 if (!doc)
35 fz_throw(ctx, "no file specified"); 35 fz_throw(ctx, "no file specified");
36 pdf_debug_xref(xref); 36 pdf_debug_xref(doc);
37 printf("\n"); 37 printf("\n");
38} 38}
39 39
@@ -43,13 +43,13 @@ static void showpagetree(void)
43 int count; 43 int count;
44 int i; 44 int i;
45 45
46 if (!xref) 46 if (!doc)
47 fz_throw(ctx, "no file specified"); 47 fz_throw(ctx, "no file specified");
48 48
49 count = pdf_count_pages(xref); 49 count = pdf_count_pages(doc);
50 for (i = 0; i < count; i++) 50 for (i = 0; i < count; i++)
51 { 51 {
52 ref = xref->page_refs[i]; 52 ref = doc->page_refs[i];
53 printf("page %d = %d %d R\n", i + 1, fz_to_num(ref), fz_to_gen(ref)); 53 printf("page %d = %d %d R\n", i + 1, fz_to_num(ref), fz_to_gen(ref));
54 } 54 }
55 printf("\n"); 55 printf("\n");
@@ -87,9 +87,9 @@ static void showstream(int num, int gen)
87 showcolumn = 0; 87 showcolumn = 0;
88 88
89 if (showdecode) 89 if (showdecode)
90 stm = pdf_open_stream(xref, num, gen); 90 stm = pdf_open_stream(doc, num, gen);
91 else 91 else
92 stm = pdf_open_raw_stream(xref, num, gen); 92 stm = pdf_open_raw_stream(doc, num, gen);
93 93
94 while (1) 94 while (1)
95 { 95 {
@@ -109,12 +109,12 @@ static void showobject(int num, int gen)
109{ 109{
110 fz_obj *obj; 110 fz_obj *obj;
111 111
112 if (!xref) 112 if (!doc)
113 fz_throw(ctx, "no file specified"); 113 fz_throw(ctx, "no file specified");
114 114
115 obj = pdf_load_object(xref, num, gen); 115 obj = pdf_load_object(doc, num, gen);
116 116
117 if (pdf_is_stream(xref, num, gen)) 117 if (pdf_is_stream(doc, num, gen))
118 { 118 {
119 if (showbinary) 119 if (showbinary)
120 { 120 {
@@ -145,13 +145,13 @@ static void showgrep(char *filename)
145 fz_obj *obj; 145 fz_obj *obj;
146 int i; 146 int i;
147 147
148 for (i = 0; i < xref->len; i++) 148 for (i = 0; i < doc->len; i++)
149 { 149 {
150 if (xref->table[i].type == 'n' || xref->table[i].type == 'o') 150 if (doc->table[i].type == 'n' || doc->table[i].type == 'o')
151 { 151 {
152 fz_try(ctx) 152 fz_try(ctx)
153 { 153 {
154 obj = pdf_load_object(xref, i, 0); 154 obj = pdf_load_object(doc, i, 0);
155 } 155 }
156 fz_catch(ctx) 156 fz_catch(ctx)
157 { 157 {
@@ -169,7 +169,7 @@ static void showgrep(char *filename)
169 } 169 }
170 170
171 printf("%s:trailer: ", filename); 171 printf("%s:trailer: ", filename);
172 fz_fprint_obj(stdout, xref->trailer, 1); 172 fz_fprint_obj(stdout, doc->trailer, 1);
173} 173}
174 174
175#ifdef MUPDF_COMBINED_EXE 175#ifdef MUPDF_COMBINED_EXE
@@ -205,12 +205,12 @@ int main(int argc, char **argv)
205 exit(1); 205 exit(1);
206 } 206 }
207 207
208 fz_var(xref); 208 fz_var(doc);
209 fz_try(ctx) 209 fz_try(ctx)
210 { 210 {
211 xref = pdf_open_xref(ctx, filename); 211 doc = pdf_open_document(ctx, filename);
212 if (pdf_needs_password(xref)) 212 if (pdf_needs_password(doc))
213 if (!pdf_authenticate_password(xref, password)) 213 if (!pdf_authenticate_password(doc, password))
214 fz_throw(ctx, "cannot authenticate password: %s", filename); 214 fz_throw(ctx, "cannot authenticate password: %s", filename);
215 215
216 if (fz_optind == argc) 216 if (fz_optind == argc)
@@ -233,7 +233,7 @@ int main(int argc, char **argv)
233 { 233 {
234 } 234 }
235 235
236 pdf_free_xref(xref); 236 pdf_close_document(doc);
237 fz_free_context(ctx); 237 fz_free_context(ctx);
238 return 0; 238 return 0;
239} 239}
diff --git a/apps/win_main.c b/apps/win_main.c
index 4818c58bd..db5b92db6 100644
--- a/apps/win_main.c
+++ b/apps/win_main.c
@@ -168,7 +168,7 @@ INT CALLBACK
168dloginfoproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 168dloginfoproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
169{ 169{
170 char buf[256]; 170 char buf[256];
171 pdf_xref *xref = gapp.xref; 171 pdf_document *doc = gapp.doc;
172 fz_obj *info, *obj; 172 fz_obj *info, *obj;
173 173
174 switch(message) 174 switch(message)
@@ -177,7 +177,7 @@ dloginfoproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
177 177
178 SetDlgItemTextW(hwnd, 0x10, wbuf); 178 SetDlgItemTextW(hwnd, 0x10, wbuf);
179 179
180 if (!xref) 180 if (!doc)
181 { 181 {
182 SetDlgItemTextA(hwnd, 0x11, "XPS"); 182 SetDlgItemTextA(hwnd, 0x11, "XPS");
183 SetDlgItemTextA(hwnd, 0x12, "None"); 183 SetDlgItemTextA(hwnd, 0x12, "None");
@@ -185,22 +185,22 @@ dloginfoproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
185 return TRUE; 185 return TRUE;
186 } 186 }
187 187
188 sprintf(buf, "PDF %d.%d", xref->version / 10, xref->version % 10); 188 sprintf(buf, "PDF %d.%d", doc->version / 10, doc->version % 10);
189 SetDlgItemTextA(hwnd, 0x11, buf); 189 SetDlgItemTextA(hwnd, 0x11, buf);
190 190
191 if (xref->crypt) 191 if (doc->crypt)
192 { 192 {
193 sprintf(buf, "Standard V%d %d-bit %s", pdf_get_crypt_revision(xref), 193 sprintf(buf, "Standard V%d %d-bit %s", pdf_get_crypt_revision(doc),
194 pdf_get_crypt_length(xref), pdf_get_crypt_method(xref)); 194 pdf_get_crypt_length(doc), pdf_get_crypt_method(doc));
195 SetDlgItemTextA(hwnd, 0x12, buf); 195 SetDlgItemTextA(hwnd, 0x12, buf);
196 strcpy(buf, ""); 196 strcpy(buf, "");
197 if (pdf_has_permission(xref, PDF_PERM_PRINT)) 197 if (pdf_has_permission(doc, PDF_PERM_PRINT))
198 strcat(buf, "print, "); 198 strcat(buf, "print, ");
199 if (pdf_has_permission(xref, PDF_PERM_CHANGE)) 199 if (pdf_has_permission(doc, PDF_PERM_CHANGE))
200 strcat(buf, "modify, "); 200 strcat(buf, "modify, ");
201 if (pdf_has_permission(xref, PDF_PERM_COPY)) 201 if (pdf_has_permission(doc, PDF_PERM_COPY))
202 strcat(buf, "copy, "); 202 strcat(buf, "copy, ");
203 if (pdf_has_permission(xref, PDF_PERM_NOTES)) 203 if (pdf_has_permission(doc, PDF_PERM_NOTES))
204 strcat(buf, "annotate, "); 204 strcat(buf, "annotate, ");
205 if (strlen(buf) > 2) 205 if (strlen(buf) > 2)
206 buf[strlen(buf)-2] = 0; 206 buf[strlen(buf)-2] = 0;
@@ -214,14 +214,14 @@ dloginfoproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
214 SetDlgItemTextA(hwnd, 0x13, "n/a"); 214 SetDlgItemTextA(hwnd, 0x13, "n/a");
215 } 215 }
216 216
217 info = fz_dict_gets(xref->trailer, "Info"); 217 info = fz_dict_gets(doc->trailer, "Info");
218 if (!info) 218 if (!info)
219 return TRUE; 219 return TRUE;
220 220
221#define SETUCS(ID) \ 221#define SETUCS(ID) \
222 { \ 222 { \
223 unsigned short *ucs; \ 223 unsigned short *ucs; \
224 ucs = pdf_to_ucs2(xref->ctx, obj); \ 224 ucs = pdf_to_ucs2(doc->ctx, obj); \
225 SetDlgItemTextW(hwnd, ID, ucs); \ 225 SetDlgItemTextW(hwnd, ID, ucs); \
226 fz_free(context, ucs); \ 226 fz_free(context, ucs); \
227 } 227 }
diff --git a/apps/xpsdraw.c b/apps/xpsdraw.c
index 50a2c3e39..8fec8efa2 100644
--- a/apps/xpsdraw.c
+++ b/apps/xpsdraw.c
@@ -338,7 +338,7 @@ int main(int argc, char **argv)
338 338
339 fz_try(ctx) 339 fz_try(ctx)
340 { 340 {
341 doc = xps_open_file(ctx, filename); 341 doc = xps_open_document(ctx, filename);
342 342
343 if (showxml) 343 if (showxml)
344 printf("<document name=\"%s\">\n", filename); 344 printf("<document name=\"%s\">\n", filename);
@@ -357,11 +357,11 @@ int main(int argc, char **argv)
357 if (showxml) 357 if (showxml)
358 printf("</document>\n"); 358 printf("</document>\n");
359 359
360 xps_free_context(doc); 360 xps_close_document(doc);
361 } 361 }
362 fz_catch(ctx) 362 fz_catch(ctx)
363 { 363 {
364 xps_free_context(doc); 364 xps_close_document(doc);
365 } 365 }
366 } 366 }
367 367
diff --git a/fitz/base_object.c b/fitz/base_object.c
index 4037c871f..a3b38c49f 100644
--- a/fitz/base_object.c
+++ b/fitz/base_object.c
@@ -294,7 +294,7 @@ int fz_to_gen(fz_obj *obj)
294 return obj->u.r.gen; 294 return obj->u.r.gen;
295} 295}
296 296
297void *fz_get_indirect_xref(fz_obj *obj) 297void *fz_get_indirect_document(fz_obj *obj)
298{ 298{
299 if (!obj || obj->kind != FZ_INDIRECT) 299 if (!obj || obj->kind != FZ_INDIRECT)
300 return NULL; 300 return NULL;
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 49db7dc2f..e156cb273 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -641,7 +641,7 @@ fz_obj *fz_new_int(fz_context *ctx, int i);
641fz_obj *fz_new_real(fz_context *ctx, float f); 641fz_obj *fz_new_real(fz_context *ctx, float f);
642fz_obj *fz_new_name(fz_context *ctx, char *str); 642fz_obj *fz_new_name(fz_context *ctx, char *str);
643fz_obj *fz_new_string(fz_context *ctx, char *str, int len); 643fz_obj *fz_new_string(fz_context *ctx, char *str, int len);
644fz_obj *fz_new_indirect(fz_context *ctx, int num, int gen, void *xref); 644fz_obj *fz_new_indirect(fz_context *ctx, int num, int gen, void *doc);
645 645
646fz_obj *fz_new_array(fz_context *ctx, int initialcap); 646fz_obj *fz_new_array(fz_context *ctx, int initialcap);
647fz_obj *fz_new_dict(fz_context *ctx, int initialcap); 647fz_obj *fz_new_dict(fz_context *ctx, int initialcap);
@@ -704,7 +704,7 @@ void fz_debug_obj(fz_obj *obj);
704void fz_debug_ref(fz_obj *obj); 704void fz_debug_ref(fz_obj *obj);
705 705
706void fz_set_str_len(fz_obj *obj, int newlen); /* private */ 706void fz_set_str_len(fz_obj *obj, int newlen); /* private */
707void *fz_get_indirect_xref(fz_obj *obj); /* private */ 707void *fz_get_indirect_document(fz_obj *obj); /* private */
708 708
709/* 709/*
710 * Data buffers. 710 * Data buffers.
@@ -1067,8 +1067,8 @@ struct fz_font_s
1067 fz_buffer **t3procs; /* has 256 entries if used */ 1067 fz_buffer **t3procs; /* has 256 entries if used */
1068 float *t3widths; /* has 256 entries if used */ 1068 float *t3widths; /* has 256 entries if used */
1069 char *t3flags; /* has 256 entries if used */ 1069 char *t3flags; /* has 256 entries if used */
1070 void *t3xref; /* a pdf_xref for the callback */ 1070 void *t3doc; /* a pdf_document for the callback */
1071 void (*t3run)(void *xref, fz_obj *resources, fz_buffer *contents, 1071 void (*t3run)(void *doc, fz_obj *resources, fz_buffer *contents,
1072 struct fz_device_s *dev, fz_matrix ctm, void *gstate); 1072 struct fz_device_s *dev, fz_matrix ctm, void *gstate);
1073 1073
1074 fz_rect bbox; /* font bbox is used only for t3 fonts */ 1074 fz_rect bbox; /* font bbox is used only for t3 fonts */
diff --git a/fitz/res_font.c b/fitz/res_font.c
index 7bc8f48bb..9f1bc73ba 100644
--- a/fitz/res_font.c
+++ b/fitz/res_font.c
@@ -37,7 +37,7 @@ fz_new_font(fz_context *ctx, char *name, int use_glyph_bbox, int glyph_count)
37 font->t3procs = NULL; 37 font->t3procs = NULL;
38 font->t3widths = NULL; 38 font->t3widths = NULL;
39 font->t3flags = NULL; 39 font->t3flags = NULL;
40 font->t3xref = NULL; 40 font->t3doc = NULL;
41 font->t3run = NULL; 41 font->t3run = NULL;
42 42
43 font->bbox.x0 = 0; 43 font->bbox.x0 = 0;
@@ -646,7 +646,7 @@ fz_bound_t3_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm)
646 FZ_DEVFLAG_LINEJOIN_UNDEFINED | 646 FZ_DEVFLAG_LINEJOIN_UNDEFINED |
647 FZ_DEVFLAG_MITERLIMIT_UNDEFINED | 647 FZ_DEVFLAG_MITERLIMIT_UNDEFINED |
648 FZ_DEVFLAG_LINEWIDTH_UNDEFINED; 648 FZ_DEVFLAG_LINEWIDTH_UNDEFINED;
649 font->t3run(font->t3xref, font->t3resources, contents, dev, ctm, NULL); 649 font->t3run(font->t3doc, font->t3resources, contents, dev, ctm, NULL);
650 font->t3flags[gid] = dev->flags; 650 font->t3flags[gid] = dev->flags;
651 fz_free_device(dev); 651 fz_free_device(dev);
652 652
@@ -702,7 +702,7 @@ fz_render_t3_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, fz_co
702 702
703 ctm = fz_concat(font->t3matrix, trm); 703 ctm = fz_concat(font->t3matrix, trm);
704 dev = fz_new_draw_device_type3(ctx, glyph); 704 dev = fz_new_draw_device_type3(ctx, glyph);
705 font->t3run(font->t3xref, font->t3resources, contents, dev, ctm, NULL); 705 font->t3run(font->t3doc, font->t3resources, contents, dev, ctm, NULL);
706 /* RJW: "cannot draw type3 glyph" */ 706 /* RJW: "cannot draw type3 glyph" */
707 fz_free_device(dev); 707 fz_free_device(dev);
708 708
@@ -744,7 +744,7 @@ fz_render_t3_glyph_direct(fz_context *ctx, fz_device *dev, fz_font *font, int gi
744 } 744 }
745 745
746 ctm = fz_concat(font->t3matrix, trm); 746 ctm = fz_concat(font->t3matrix, trm);
747 font->t3run(font->t3xref, font->t3resources, contents, dev, ctm, gstate); 747 font->t3run(font->t3doc, font->t3resources, contents, dev, ctm, gstate);
748 /* RJW: "cannot draw type3 glyph" */ 748 /* RJW: "cannot draw type3 glyph" */
749} 749}
750 750
diff --git a/ios/document.c b/ios/document.c
index 5531a9808..9c209046d 100644
--- a/ios/document.c
+++ b/ios/document.c
@@ -18,18 +18,11 @@ open_document(fz_context *ctx, char *filename)
18 fz_try(ctx) 18 fz_try(ctx)
19 { 19 {
20 if (strstr(filename, ".pdf") || strstr(filename, ".PDF")) 20 if (strstr(filename, ".pdf") || strstr(filename, ".PDF"))
21 { 21 doc->pdf = pdf_open_document(ctx, filename);
22 doc->pdf = pdf_open_xref(ctx, filename);
23 pdf_load_page_tree(doc->pdf);
24 }
25 else if (strstr(filename, ".xps") || strstr(filename, ".XPS")) 22 else if (strstr(filename, ".xps") || strstr(filename, ".XPS"))
26 { 23 doc->xps = xps_open_document(ctx, filename);
27 doc->xps = xps_open_file(ctx, filename);
28 }
29 else 24 else
30 {
31 fz_throw(ctx, "unknown document format"); 25 fz_throw(ctx, "unknown document format");
32 }
33 } 26 }
34 fz_catch(ctx) 27 fz_catch(ctx)
35 { 28 {
@@ -264,12 +257,12 @@ close_document(struct document *doc)
264 if (doc->pdf) { 257 if (doc->pdf) {
265 if (doc->pdf_page) 258 if (doc->pdf_page)
266 pdf_free_page(doc->ctx, doc->pdf_page); 259 pdf_free_page(doc->ctx, doc->pdf_page);
267 pdf_free_xref(doc->pdf); 260 pdf_close_document(doc->pdf);
268 } 261 }
269 if (doc->xps) { 262 if (doc->xps) {
270 if (doc->xps_page) 263 if (doc->xps_page)
271 xps_free_page(doc->xps, doc->xps_page); 264 xps_free_page(doc->xps, doc->xps_page);
272 xps_free_context(doc->xps); 265 xps_close_document(doc->xps);
273 } 266 }
274 fz_flush_warnings(doc->ctx); 267 fz_flush_warnings(doc->ctx);
275 fz_free(doc->ctx, doc); 268 fz_free(doc->ctx, doc);
diff --git a/ios/document.h b/ios/document.h
index ad0a8a626..5e3c740e5 100644
--- a/ios/document.h
+++ b/ios/document.h
@@ -16,7 +16,7 @@
16struct document 16struct document
17{ 17{
18 fz_context *ctx; 18 fz_context *ctx;
19 pdf_xref *pdf; 19 pdf_document *pdf;
20 xps_document *xps; 20 xps_document *xps;
21 int number; 21 int number;
22 pdf_page *pdf_page; 22 pdf_page *pdf_page;
diff --git a/pdf/mupdf.h b/pdf/mupdf.h
index f1b29e141..f09519761 100644
--- a/pdf/mupdf.h
+++ b/pdf/mupdf.h
@@ -5,7 +5,7 @@
5#error "fitz.h must be included before mupdf.h" 5#error "fitz.h must be included before mupdf.h"
6#endif 6#endif
7 7
8typedef struct pdf_xref_s pdf_xref; 8typedef struct pdf_document_s pdf_document;
9 9
10/* 10/*
11 * tokenizer and low-level object parser 11 * tokenizer and low-level object parser
@@ -27,10 +27,10 @@ enum
27 27
28int pdf_lex(fz_stream *f, char *buf, int n, int *len); 28int pdf_lex(fz_stream *f, char *buf, int n, int *len);
29 29
30fz_obj *pdf_parse_array(pdf_xref *xref, fz_stream *f, char *buf, int cap); 30fz_obj *pdf_parse_array(pdf_document *doc, fz_stream *f, char *buf, int cap);
31fz_obj *pdf_parse_dict(pdf_xref *xref, fz_stream *f, char *buf, int cap); 31fz_obj *pdf_parse_dict(pdf_document *doc, fz_stream *f, char *buf, int cap);
32fz_obj *pdf_parse_stm_obj(pdf_xref *xref, fz_stream *f, char *buf, int cap); 32fz_obj *pdf_parse_stm_obj(pdf_document *doc, fz_stream *f, char *buf, int cap);
33fz_obj * pdf_parse_ind_obj(pdf_xref *xref, fz_stream *f, char *buf, int cap, int *num, int *gen, int *stm_ofs); 33fz_obj * pdf_parse_ind_obj(pdf_document *doc, fz_stream *f, char *buf, int cap, int *num, int *gen, int *stm_ofs);
34 34
35fz_rect pdf_to_rect(fz_context *ctx, fz_obj *array); 35fz_rect pdf_to_rect(fz_context *ctx, fz_obj *array);
36fz_matrix pdf_to_matrix(fz_context *ctx, fz_obj *array); 36fz_matrix pdf_to_matrix(fz_context *ctx, fz_obj *array);
@@ -71,7 +71,7 @@ struct pdf_ocg_descriptor_s
71 fz_obj *intent; 71 fz_obj *intent;
72}; 72};
73 73
74struct pdf_xref_s 74struct pdf_document_s
75{ 75{
76 fz_context *ctx; 76 fz_context *ctx;
77 fz_stream *file; 77 fz_stream *file;
@@ -94,27 +94,27 @@ struct pdf_xref_s
94}; 94};
95 95
96fz_obj *pdf_resolve_indirect(fz_obj *ref); 96fz_obj *pdf_resolve_indirect(fz_obj *ref);
97void pdf_cache_object(pdf_xref *, int num, int gen); 97void pdf_cache_object(pdf_document *doc, int num, int gen);
98fz_obj *pdf_load_object(pdf_xref *, int num, int gen); 98fz_obj *pdf_load_object(pdf_document *doc, int num, int gen);
99void pdf_update_object( pdf_xref *xref, int num, int gen, fz_obj *newobj); 99void pdf_update_object( pdf_document *doc, int num, int gen, fz_obj *newobj);
100 100
101int pdf_is_stream(pdf_xref *xref, int num, int gen); 101int pdf_is_stream(pdf_document *doc, int num, int gen);
102fz_stream *pdf_open_inline_stream(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int length); 102fz_stream *pdf_open_inline_stream(fz_stream *chain, pdf_document *doc, fz_obj *stmobj, int length);
103fz_buffer *pdf_load_raw_stream(pdf_xref *xref, int num, int gen); 103fz_buffer *pdf_load_raw_stream(pdf_document *doc, int num, int gen);
104fz_buffer *pdf_load_stream(pdf_xref *xref, int num, int gen); 104fz_buffer *pdf_load_stream(pdf_document *doc, int num, int gen);
105fz_stream *pdf_open_raw_stream(pdf_xref *, int num, int gen); 105fz_stream *pdf_open_raw_stream(pdf_document *doc, int num, int gen);
106fz_stream *pdf_open_stream(pdf_xref *, int num, int gen); 106fz_stream *pdf_open_stream(pdf_document *doc, int num, int gen);
107fz_stream *pdf_open_stream_at(pdf_xref *xref, int num, int gen, fz_obj *dict, int stm_ofs); 107fz_stream *pdf_open_stream_at(pdf_document *doc, int num, int gen, fz_obj *dict, int stm_ofs);
108 108
109pdf_xref *pdf_open_xref_with_stream(fz_stream *file); 109pdf_document *pdf_open_document_with_stream(fz_stream *file);
110pdf_xref *pdf_open_xref(fz_context *ctx, const char *filename); 110pdf_document *pdf_open_document(fz_context *ctx, const char *filename);
111void pdf_free_xref(pdf_xref *); 111void pdf_close_document(pdf_document *doc);
112 112
113/* private */ 113/* private */
114void pdf_repair_xref(pdf_xref *xref, char *buf, int bufsize); 114void pdf_repair_xref(pdf_document *doc, char *buf, int bufsize);
115void pdf_repair_obj_stms(pdf_xref *xref); 115void pdf_repair_obj_stms(pdf_document *doc);
116void pdf_debug_xref(pdf_xref *); 116void pdf_debug_xref(pdf_document *);
117void pdf_resize_xref(pdf_xref *xref, int newcap); 117void pdf_resize_xref(pdf_document *doc, int newcap);
118 118
119/* 119/*
120 * Encryption 120 * Encryption
@@ -140,14 +140,14 @@ void pdf_crypt_obj(fz_context *ctx, pdf_crypt *crypt, fz_obj *obj, int num, int
140fz_stream *pdf_open_crypt(fz_stream *chain, pdf_crypt *crypt, int num, int gen); 140fz_stream *pdf_open_crypt(fz_stream *chain, pdf_crypt *crypt, int num, int gen);
141fz_stream *pdf_open_crypt_with_filter(fz_stream *chain, pdf_crypt *crypt, char *name, int num, int gen); 141fz_stream *pdf_open_crypt_with_filter(fz_stream *chain, pdf_crypt *crypt, char *name, int num, int gen);
142 142
143int pdf_needs_password(pdf_xref *xref); 143int pdf_needs_password(pdf_document *doc);
144int pdf_authenticate_password(pdf_xref *xref, char *pw); 144int pdf_authenticate_password(pdf_document *doc, char *pw);
145int pdf_has_permission(pdf_xref *xref, int p); 145int pdf_has_permission(pdf_document *doc, int p);
146 146
147int pdf_get_crypt_revision(pdf_xref *xref); 147int pdf_get_crypt_revision(pdf_document *doc);
148char *pdf_get_crypt_method(pdf_xref *xref); 148char *pdf_get_crypt_method(pdf_document *doc);
149int pdf_get_crypt_length(pdf_xref *xref); 149int pdf_get_crypt_length(pdf_document *doc);
150unsigned char *pdf_get_crypt_key(pdf_xref *xref); 150unsigned char *pdf_get_crypt_key(pdf_document *doc);
151 151
152void pdf_debug_crypt(pdf_crypt *crypt); 152void pdf_debug_crypt(pdf_crypt *crypt);
153 153
@@ -157,19 +157,19 @@ void pdf_debug_crypt(pdf_crypt *crypt);
157 157
158typedef struct pdf_function_s pdf_function; 158typedef struct pdf_function_s pdf_function;
159 159
160pdf_function *pdf_load_function(pdf_xref *xref, fz_obj *ref); 160pdf_function *pdf_load_function(pdf_document *doc, fz_obj *ref);
161void pdf_eval_function(fz_context *ctx, pdf_function *func, float *in, int inlen, float *out, int outlen); 161void pdf_eval_function(fz_context *ctx, pdf_function *func, float *in, int inlen, float *out, int outlen);
162pdf_function *pdf_keep_function(fz_context *ctx, pdf_function *func); 162pdf_function *pdf_keep_function(fz_context *ctx, pdf_function *func);
163void pdf_drop_function(fz_context *ctx, pdf_function *func); 163void pdf_drop_function(fz_context *ctx, pdf_function *func);
164unsigned int pdf_function_size(pdf_function *func); 164unsigned int pdf_function_size(pdf_function *func);
165 165
166fz_colorspace *pdf_load_colorspace(pdf_xref *xref, fz_obj *obj); 166fz_colorspace *pdf_load_colorspace(pdf_document *doc, fz_obj *obj);
167fz_pixmap *pdf_expand_indexed_pixmap(fz_context *ctx, fz_pixmap *src); 167fz_pixmap *pdf_expand_indexed_pixmap(fz_context *ctx, fz_pixmap *src);
168 168
169fz_shade *pdf_load_shading(pdf_xref *xref, fz_obj *obj); 169fz_shade *pdf_load_shading(pdf_document *doc, fz_obj *obj);
170 170
171fz_pixmap *pdf_load_inline_image(pdf_xref *xref, fz_obj *rdb, fz_obj *dict, fz_stream *file); 171fz_pixmap *pdf_load_inline_image(pdf_document *doc, fz_obj *rdb, fz_obj *dict, fz_stream *file);
172fz_pixmap *pdf_load_image(pdf_xref *xref, fz_obj *obj); 172fz_pixmap *pdf_load_image(pdf_document *doc, fz_obj *obj);
173int pdf_is_jpx_image(fz_context *ctx, fz_obj *dict); 173int pdf_is_jpx_image(fz_context *ctx, fz_obj *dict);
174 174
175/* 175/*
@@ -190,7 +190,7 @@ struct pdf_pattern_s
190 fz_buffer *contents; 190 fz_buffer *contents;
191}; 191};
192 192
193pdf_pattern *pdf_load_pattern(pdf_xref *xref, fz_obj *obj); 193pdf_pattern *pdf_load_pattern(pdf_document *doc, fz_obj *obj);
194pdf_pattern *pdf_keep_pattern(fz_context *ctx, pdf_pattern *pat); 194pdf_pattern *pdf_keep_pattern(fz_context *ctx, pdf_pattern *pat);
195void pdf_drop_pattern(fz_context *ctx, pdf_pattern *pat); 195void pdf_drop_pattern(fz_context *ctx, pdf_pattern *pat);
196 196
@@ -214,7 +214,7 @@ struct pdf_xobject_s
214 fz_obj *me; 214 fz_obj *me;
215}; 215};
216 216
217pdf_xobject *pdf_load_xobject(pdf_xref *xref, fz_obj *obj); 217pdf_xobject *pdf_load_xobject(pdf_document *doc, fz_obj *obj);
218pdf_xobject *pdf_keep_xobject(fz_context *ctx, pdf_xobject *xobj); 218pdf_xobject *pdf_keep_xobject(fz_context *ctx, pdf_xobject *xobj);
219void pdf_drop_xobject(fz_context *ctx, pdf_xobject *xobj); 219void pdf_drop_xobject(fz_context *ctx, pdf_xobject *xobj);
220 220
@@ -285,7 +285,7 @@ unsigned char *pdf_decode_cmap(pdf_cmap *cmap, unsigned char *s, int *cpt);
285 285
286pdf_cmap *pdf_new_identity_cmap(fz_context *ctx, int wmode, int bytes); 286pdf_cmap *pdf_new_identity_cmap(fz_context *ctx, int wmode, int bytes);
287pdf_cmap *pdf_parse_cmap(fz_stream *file); 287pdf_cmap *pdf_parse_cmap(fz_stream *file);
288pdf_cmap *pdf_load_embedded_cmap(pdf_xref *xref, fz_obj *ref); 288pdf_cmap *pdf_load_embedded_cmap(pdf_document *doc, fz_obj *ref);
289pdf_cmap *pdf_load_system_cmap(fz_context *ctx, char *name); 289pdf_cmap *pdf_load_system_cmap(fz_context *ctx, char *name);
290pdf_cmap *pdf_find_builtin_cmap(char *cmap_name); 290pdf_cmap *pdf_find_builtin_cmap(char *cmap_name);
291 291
@@ -389,7 +389,7 @@ void pdf_end_vmtx(pdf_font_desc *font);
389pdf_hmtx pdf_get_hmtx(pdf_font_desc *font, int cid); 389pdf_hmtx pdf_get_hmtx(pdf_font_desc *font, int cid);
390pdf_vmtx pdf_get_vmtx(pdf_font_desc *font, int cid); 390pdf_vmtx pdf_get_vmtx(pdf_font_desc *font, int cid);
391 391
392void pdf_load_to_unicode(pdf_font_desc *font, pdf_xref *xref, char **strings, char *collection, fz_obj *cmapstm); 392void pdf_load_to_unicode(pdf_font_desc *font, pdf_document *doc, char **strings, char *collection, fz_obj *cmapstm);
393 393
394int pdf_font_cid_to_gid(pdf_font_desc *fontdesc, int cid); 394int pdf_font_cid_to_gid(pdf_font_desc *fontdesc, int cid);
395 395
@@ -397,8 +397,8 @@ unsigned char *pdf_find_builtin_font(char *name, unsigned int *len);
397unsigned char *pdf_find_substitute_font(int mono, int serif, int bold, int italic, unsigned int *len); 397unsigned char *pdf_find_substitute_font(int mono, int serif, int bold, int italic, unsigned int *len);
398unsigned char *pdf_find_substitute_cjk_font(int ros, int serif, unsigned int *len); 398unsigned char *pdf_find_substitute_cjk_font(int ros, int serif, unsigned int *len);
399 399
400pdf_font_desc *pdf_load_type3_font(pdf_xref *xref, fz_obj *rdb, fz_obj *obj); 400pdf_font_desc *pdf_load_type3_font(pdf_document *doc, fz_obj *rdb, fz_obj *obj);
401pdf_font_desc *pdf_load_font(pdf_xref *xref, fz_obj *rdb, fz_obj *obj); 401pdf_font_desc *pdf_load_font(pdf_document *doc, fz_obj *rdb, fz_obj *obj);
402 402
403pdf_font_desc *pdf_new_font_desc(fz_context *ctx); 403pdf_font_desc *pdf_new_font_desc(fz_context *ctx);
404pdf_font_desc *pdf_keep_font(fz_context *ctx, pdf_font_desc *fontdesc); 404pdf_font_desc *pdf_keep_font(fz_context *ctx, pdf_font_desc *fontdesc);
@@ -421,17 +421,17 @@ struct pdf_annot_s
421 pdf_annot *next; 421 pdf_annot *next;
422}; 422};
423 423
424fz_link_dest pdf_parse_link_dest(pdf_xref *xref, fz_obj *dest); 424fz_link_dest pdf_parse_link_dest(pdf_document *doc, fz_obj *dest);
425fz_link_dest pdf_parse_action(pdf_xref *xref, fz_obj *action); 425fz_link_dest pdf_parse_action(pdf_document *doc, fz_obj *action);
426fz_obj *pdf_lookup_dest(pdf_xref *xref, fz_obj *needle); 426fz_obj *pdf_lookup_dest(pdf_document *doc, fz_obj *needle);
427fz_obj *pdf_lookup_name(pdf_xref *xref, char *which, fz_obj *needle); 427fz_obj *pdf_lookup_name(pdf_document *doc, char *which, fz_obj *needle);
428fz_obj *pdf_load_name_tree(pdf_xref *xref, char *which); 428fz_obj *pdf_load_name_tree(pdf_document *doc, char *which);
429 429
430fz_outline *pdf_load_outline(pdf_xref *xref); 430fz_outline *pdf_load_outline(pdf_document *doc);
431 431
432fz_link *pdf_load_links(pdf_xref *, fz_obj *annots, fz_matrix page_ctm); 432fz_link *pdf_load_links(pdf_document *, fz_obj *annots, fz_matrix page_ctm);
433 433
434pdf_annot *pdf_load_annots(pdf_xref *, fz_obj *annots); 434pdf_annot *pdf_load_annots(pdf_document *, fz_obj *annots);
435void pdf_free_annot(fz_context *ctx, pdf_annot *link); 435void pdf_free_annot(fz_context *ctx, pdf_annot *link);
436 436
437/* 437/*
@@ -452,19 +452,19 @@ struct pdf_page_s
452 pdf_annot *annots; 452 pdf_annot *annots;
453}; 453};
454 454
455int pdf_find_page_number(pdf_xref *xref, fz_obj *pageobj); 455int pdf_find_page_number(pdf_document *doc, fz_obj *pageobj);
456int pdf_count_pages(pdf_xref *xref); 456int pdf_count_pages(pdf_document *doc);
457 457
458pdf_page *pdf_load_page(pdf_xref *xref, int number); 458pdf_page *pdf_load_page(pdf_document *doc, int number);
459fz_rect pdf_bound_page(pdf_xref *xref, pdf_page *page); 459fz_rect pdf_bound_page(pdf_document *doc, pdf_page *page);
460void pdf_free_page(fz_context *ctx, pdf_page *page); 460void pdf_free_page(fz_context *ctx, pdf_page *page);
461 461
462/* 462/*
463 * Content stream parsing 463 * Content stream parsing
464 */ 464 */
465 465
466void pdf_run_page_with_usage(pdf_xref *xref, pdf_page *page, fz_device *dev, fz_matrix ctm, char *event, fz_cookie *cookie); 466void pdf_run_page_with_usage(pdf_document *doc, pdf_page *page, fz_device *dev, fz_matrix ctm, char *event, fz_cookie *cookie);
467void pdf_run_page(pdf_xref *xref, pdf_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie); 467void pdf_run_page(pdf_document *doc, pdf_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie);
468void pdf_run_glyph(pdf_xref *xref, fz_obj *resources, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate); 468void pdf_run_glyph(pdf_document *doc, fz_obj *resources, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate);
469 469
470#endif 470#endif
diff --git a/pdf/pdf_annot.c b/pdf/pdf_annot.c
index 1daf8dbf0..12c08bf4a 100644
--- a/pdf/pdf_annot.c
+++ b/pdf/pdf_annot.c
@@ -2,7 +2,7 @@
2#include "mupdf.h" 2#include "mupdf.h"
3 3
4static fz_obj * 4static fz_obj *
5resolve_dest_rec(pdf_xref *xref, fz_obj *dest, int depth) 5resolve_dest_rec(pdf_document *xref, fz_obj *dest, int depth)
6{ 6{
7 if (depth > 10) /* Arbitrary to avoid infinite recursion */ 7 if (depth > 10) /* Arbitrary to avoid infinite recursion */
8 return NULL; 8 return NULL;
@@ -31,13 +31,13 @@ resolve_dest_rec(pdf_xref *xref, fz_obj *dest, int depth)
31} 31}
32 32
33static fz_obj * 33static fz_obj *
34resolve_dest(pdf_xref *xref, fz_obj *dest) 34resolve_dest(pdf_document *xref, fz_obj *dest)
35{ 35{
36 return resolve_dest_rec(xref, dest, 0); 36 return resolve_dest_rec(xref, dest, 0);
37} 37}
38 38
39fz_link_dest 39fz_link_dest
40pdf_parse_link_dest(pdf_xref *xref, fz_obj *dest) 40pdf_parse_link_dest(pdf_document *xref, fz_obj *dest)
41{ 41{
42 fz_link_dest ld; 42 fz_link_dest ld;
43 fz_obj *obj; 43 fz_obj *obj;
@@ -192,7 +192,7 @@ pdf_parse_link_dest(pdf_xref *xref, fz_obj *dest)
192} 192}
193 193
194fz_link_dest 194fz_link_dest
195pdf_parse_action(pdf_xref *xref, fz_obj *action) 195pdf_parse_action(pdf_document *xref, fz_obj *action)
196{ 196{
197 fz_link_dest ld; 197 fz_link_dest ld;
198 fz_obj *obj, *dest; 198 fz_obj *obj, *dest;
@@ -238,7 +238,7 @@ pdf_parse_action(pdf_xref *xref, fz_obj *action)
238} 238}
239 239
240static fz_link * 240static fz_link *
241pdf_load_link(pdf_xref *xref, fz_obj *dict, fz_matrix page_ctm) 241pdf_load_link(pdf_document *xref, fz_obj *dict, fz_matrix page_ctm)
242{ 242{
243 fz_obj *dest = NULL; 243 fz_obj *dest = NULL;
244 fz_obj *action; 244 fz_obj *action;
@@ -278,7 +278,7 @@ pdf_load_link(pdf_xref *xref, fz_obj *dict, fz_matrix page_ctm)
278} 278}
279 279
280fz_link * 280fz_link *
281pdf_load_links(pdf_xref *xref, fz_obj *annots, fz_matrix page_ctm) 281pdf_load_links(pdf_document *xref, fz_obj *annots, fz_matrix page_ctm)
282{ 282{
283 fz_link *link, *head, *tail; 283 fz_link *link, *head, *tail;
284 fz_obj *obj; 284 fz_obj *obj;
@@ -349,7 +349,7 @@ pdf_transform_annot(pdf_annot *annot)
349} 349}
350 350
351pdf_annot * 351pdf_annot *
352pdf_load_annots(pdf_xref *xref, fz_obj *annots) 352pdf_load_annots(pdf_document *xref, fz_obj *annots)
353{ 353{
354 pdf_annot *annot, *head, *tail; 354 pdf_annot *annot, *head, *tail;
355 fz_obj *obj, *ap, *as, *n, *rect; 355 fz_obj *obj, *ap, *as, *n, *rect;
diff --git a/pdf/pdf_cmap_load.c b/pdf/pdf_cmap_load.c
index bcfc61aee..0d56bd039 100644
--- a/pdf/pdf_cmap_load.c
+++ b/pdf/pdf_cmap_load.c
@@ -16,7 +16,7 @@ pdf_cmap_size(pdf_cmap *cmap)
16 * Load CMap stream in PDF file 16 * Load CMap stream in PDF file
17 */ 17 */
18pdf_cmap * 18pdf_cmap *
19pdf_load_embedded_cmap(pdf_xref *xref, fz_obj *stmobj) 19pdf_load_embedded_cmap(pdf_document *xref, fz_obj *stmobj)
20{ 20{
21 fz_stream *file = NULL; 21 fz_stream *file = NULL;
22 pdf_cmap *cmap = NULL; 22 pdf_cmap *cmap = NULL;
diff --git a/pdf/pdf_colorspace.c b/pdf/pdf_colorspace.c
index b7f9f131d..7a410df85 100644
--- a/pdf/pdf_colorspace.c
+++ b/pdf/pdf_colorspace.c
@@ -4,7 +4,7 @@
4/* ICCBased */ 4/* ICCBased */
5 5
6static fz_colorspace * 6static fz_colorspace *
7load_icc_based(pdf_xref *xref, fz_obj *dict) 7load_icc_based(pdf_document *xref, fz_obj *dict)
8{ 8{
9 int n; 9 int n;
10 10
@@ -91,7 +91,7 @@ free_separation(fz_context *ctx, fz_colorspace *cs)
91} 91}
92 92
93static fz_colorspace * 93static fz_colorspace *
94load_separation(pdf_xref *xref, fz_obj *array) 94load_separation(pdf_document *xref, fz_obj *array)
95{ 95{
96 fz_colorspace *cs; 96 fz_colorspace *cs;
97 struct separation *sep = NULL; 97 struct separation *sep = NULL;
@@ -218,7 +218,7 @@ pdf_expand_indexed_pixmap(fz_context *ctx, fz_pixmap *src)
218} 218}
219 219
220static fz_colorspace * 220static fz_colorspace *
221load_indexed(pdf_xref *xref, fz_obj *array) 221load_indexed(pdf_document *xref, fz_obj *array)
222{ 222{
223 struct indexed *idx = NULL; 223 struct indexed *idx = NULL;
224 fz_context *ctx = xref->ctx; 224 fz_context *ctx = xref->ctx;
@@ -304,7 +304,7 @@ load_indexed(pdf_xref *xref, fz_obj *array)
304/* Parse and create colorspace from PDF object */ 304/* Parse and create colorspace from PDF object */
305 305
306static fz_colorspace * 306static fz_colorspace *
307pdf_load_colorspace_imp(pdf_xref *xref, fz_obj *obj) 307pdf_load_colorspace_imp(pdf_document *xref, fz_obj *obj)
308{ 308{
309 if (fz_is_name(obj)) 309 if (fz_is_name(obj))
310 { 310 {
@@ -390,7 +390,7 @@ pdf_load_colorspace_imp(pdf_xref *xref, fz_obj *obj)
390} 390}
391 391
392fz_colorspace * 392fz_colorspace *
393pdf_load_colorspace(pdf_xref *xref, fz_obj *obj) 393pdf_load_colorspace(pdf_document *xref, fz_obj *obj)
394{ 394{
395 fz_context *ctx = xref->ctx; 395 fz_context *ctx = xref->ctx;
396 fz_colorspace *cs; 396 fz_colorspace *cs;
diff --git a/pdf/pdf_crypt.c b/pdf/pdf_crypt.c
index 18b3d554d..c3cd5d8c7 100644
--- a/pdf/pdf_crypt.c
+++ b/pdf/pdf_crypt.c
@@ -575,7 +575,7 @@ pdf_authenticate_owner_password(pdf_crypt *crypt, unsigned char *ownerpass, int
575} 575}
576 576
577int 577int
578pdf_authenticate_password(pdf_xref *xref, char *password) 578pdf_authenticate_password(pdf_document *xref, char *password)
579{ 579{
580 if (xref->crypt) 580 if (xref->crypt)
581 { 581 {
@@ -591,7 +591,7 @@ pdf_authenticate_password(pdf_xref *xref, char *password)
591} 591}
592 592
593int 593int
594pdf_needs_password(pdf_xref *xref) 594pdf_needs_password(pdf_document *xref)
595{ 595{
596 if (!xref->crypt) 596 if (!xref->crypt)
597 return 0; 597 return 0;
@@ -601,7 +601,7 @@ pdf_needs_password(pdf_xref *xref)
601} 601}
602 602
603int 603int
604pdf_has_permission(pdf_xref *xref, int p) 604pdf_has_permission(pdf_document *xref, int p)
605{ 605{
606 if (!xref->crypt) 606 if (!xref->crypt)
607 return 1; 607 return 1;
@@ -609,7 +609,7 @@ pdf_has_permission(pdf_xref *xref, int p)
609} 609}
610 610
611unsigned char * 611unsigned char *
612pdf_get_crypt_key(pdf_xref *xref) 612pdf_get_crypt_key(pdf_document *xref)
613{ 613{
614 if (xref->crypt) 614 if (xref->crypt)
615 return xref->crypt->key; 615 return xref->crypt->key;
@@ -617,7 +617,7 @@ pdf_get_crypt_key(pdf_xref *xref)
617} 617}
618 618
619int 619int
620pdf_get_crypt_revision(pdf_xref *xref) 620pdf_get_crypt_revision(pdf_document *xref)
621{ 621{
622 if (xref->crypt) 622 if (xref->crypt)
623 return xref->crypt->v; 623 return xref->crypt->v;
@@ -625,7 +625,7 @@ pdf_get_crypt_revision(pdf_xref *xref)
625} 625}
626 626
627char * 627char *
628pdf_get_crypt_method(pdf_xref *xref) 628pdf_get_crypt_method(pdf_document *xref)
629{ 629{
630 if (xref->crypt) 630 if (xref->crypt)
631 { 631 {
@@ -642,7 +642,7 @@ pdf_get_crypt_method(pdf_xref *xref)
642} 642}
643 643
644int 644int
645pdf_get_crypt_length(pdf_xref *xref) 645pdf_get_crypt_length(pdf_document *xref)
646{ 646{
647 if (xref->crypt) 647 if (xref->crypt)
648 return xref->crypt->length; 648 return xref->crypt->length;
diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c
index b6c591533..65309a738 100644
--- a/pdf/pdf_font.c
+++ b/pdf/pdf_font.c
@@ -5,7 +5,7 @@
5#include FT_FREETYPE_H 5#include FT_FREETYPE_H
6#include FT_XFREE86_H 6#include FT_XFREE86_H
7 7
8static void pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_xref *xref, fz_obj *dict, char *collection, char *basefont); 8static void pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *xref, fz_obj *dict, char *collection, char *basefont);
9 9
10static char *base_font_names[14][7] = 10static char *base_font_names[14][7] =
11{ 11{
@@ -266,7 +266,7 @@ pdf_load_system_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontname, c
266} 266}
267 267
268static void 268static void
269pdf_load_embedded_font(pdf_font_desc *fontdesc, pdf_xref *xref, fz_obj *stmref) 269pdf_load_embedded_font(pdf_font_desc *fontdesc, pdf_document *xref, fz_obj *stmref)
270{ 270{
271 fz_buffer *buf; 271 fz_buffer *buf;
272 fz_context *ctx = xref->ctx; 272 fz_context *ctx = xref->ctx;
@@ -392,7 +392,7 @@ pdf_new_font_desc(fz_context *ctx)
392 */ 392 */
393 393
394static pdf_font_desc * 394static pdf_font_desc *
395pdf_load_simple_font(pdf_xref *xref, fz_obj *dict) 395pdf_load_simple_font(pdf_document *xref, fz_obj *dict)
396{ 396{
397 fz_obj *descriptor; 397 fz_obj *descriptor;
398 fz_obj *encoding; 398 fz_obj *encoding;
@@ -704,7 +704,7 @@ pdf_load_simple_font(pdf_xref *xref, fz_obj *dict)
704 */ 704 */
705 705
706static pdf_font_desc * 706static pdf_font_desc *
707load_cid_font(pdf_xref *xref, fz_obj *dict, fz_obj *encoding, fz_obj *to_unicode) 707load_cid_font(pdf_document *xref, fz_obj *dict, fz_obj *encoding, fz_obj *to_unicode)
708{ 708{
709 fz_obj *widths; 709 fz_obj *widths;
710 fz_obj *descriptor; 710 fz_obj *descriptor;
@@ -936,7 +936,7 @@ load_cid_font(pdf_xref *xref, fz_obj *dict, fz_obj *encoding, fz_obj *to_unicode
936} 936}
937 937
938static pdf_font_desc * 938static pdf_font_desc *
939pdf_load_type0_font(pdf_xref *xref, fz_obj *dict) 939pdf_load_type0_font(pdf_document *xref, fz_obj *dict)
940{ 940{
941 fz_obj *dfonts; 941 fz_obj *dfonts;
942 fz_obj *dfont; 942 fz_obj *dfont;
@@ -969,7 +969,7 @@ pdf_load_type0_font(pdf_xref *xref, fz_obj *dict)
969 */ 969 */
970 970
971static void 971static void
972pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_xref *xref, fz_obj *dict, char *collection, char *basefont) 972pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *xref, fz_obj *dict, char *collection, char *basefont)
973{ 973{
974 fz_obj *obj1, *obj2, *obj3, *obj; 974 fz_obj *obj1, *obj2, *obj3, *obj;
975 char *fontname; 975 char *fontname;
@@ -1067,7 +1067,7 @@ pdf_make_width_table(fz_context *ctx, pdf_font_desc *fontdesc)
1067} 1067}
1068 1068
1069pdf_font_desc * 1069pdf_font_desc *
1070pdf_load_font(pdf_xref *xref, fz_obj *rdb, fz_obj *dict) 1070pdf_load_font(pdf_document *xref, fz_obj *rdb, fz_obj *dict)
1071{ 1071{
1072 char *subtype; 1072 char *subtype;
1073 fz_obj *dfonts; 1073 fz_obj *dfonts;
diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c
index 7111cae76..34b419e58 100644
--- a/pdf/pdf_function.c
+++ b/pdf/pdf_function.c
@@ -816,7 +816,7 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr)
816} 816}
817 817
818static void 818static void
819load_postscript_func(pdf_function *func, pdf_xref *xref, fz_obj *dict, int num, int gen) 819load_postscript_func(pdf_function *func, pdf_document *xref, fz_obj *dict, int num, int gen)
820{ 820{
821 fz_stream *stream = NULL; 821 fz_stream *stream = NULL;
822 int codeptr; 822 int codeptr;
@@ -884,7 +884,7 @@ eval_postscript_func(fz_context *ctx, pdf_function *func, float *in, float *out)
884 */ 884 */
885 885
886static void 886static void
887load_sample_func(pdf_function *func, pdf_xref *xref, fz_obj *dict, int num, int gen) 887load_sample_func(pdf_function *func, pdf_document *xref, fz_obj *dict, int num, int gen)
888{ 888{
889 fz_context *ctx = xref->ctx; 889 fz_context *ctx = xref->ctx;
890 fz_stream *stream; 890 fz_stream *stream;
@@ -1169,7 +1169,7 @@ eval_exponential_func(fz_context *ctx, pdf_function *func, float in, float *out)
1169 */ 1169 */
1170 1170
1171static void 1171static void
1172load_stitching_func(pdf_function *func, pdf_xref *xref, fz_obj *dict) 1172load_stitching_func(pdf_function *func, pdf_document *xref, fz_obj *dict)
1173{ 1173{
1174 fz_context *ctx = xref->ctx; 1174 fz_context *ctx = xref->ctx;
1175 pdf_function **funcs; 1175 pdf_function **funcs;
@@ -1340,7 +1340,7 @@ pdf_function_size(pdf_function *func)
1340} 1340}
1341 1341
1342pdf_function * 1342pdf_function *
1343pdf_load_function(pdf_xref *xref, fz_obj *dict) 1343pdf_load_function(pdf_document *xref, fz_obj *dict)
1344{ 1344{
1345 fz_context *ctx = xref->ctx; 1345 fz_context *ctx = xref->ctx;
1346 pdf_function *func; 1346 pdf_function *func;
diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c
index 33e6077d5..80cbb0621 100644
--- a/pdf/pdf_image.c
+++ b/pdf/pdf_image.c
@@ -4,7 +4,7 @@
4/* TODO: store JPEG compressed samples */ 4/* TODO: store JPEG compressed samples */
5/* TODO: store flate compressed samples */ 5/* TODO: store flate compressed samples */
6 6
7static fz_pixmap *pdf_load_jpx_image(pdf_xref *xref, fz_obj *dict); 7static fz_pixmap *pdf_load_jpx_image(pdf_document *xref, fz_obj *dict);
8 8
9static void 9static void
10pdf_mask_color_key(fz_pixmap *pix, int n, int *colorkey) 10pdf_mask_color_key(fz_pixmap *pix, int n, int *colorkey)
@@ -26,7 +26,7 @@ pdf_mask_color_key(fz_pixmap *pix, int n, int *colorkey)
26} 26}
27 27
28static fz_pixmap * 28static fz_pixmap *
29pdf_load_image_imp(pdf_xref *xref, fz_obj *rdb, fz_obj *dict, fz_stream *cstm, int forcemask) 29pdf_load_image_imp(pdf_document *xref, fz_obj *rdb, fz_obj *dict, fz_stream *cstm, int forcemask)
30{ 30{
31 fz_stream *stm = NULL; 31 fz_stream *stm = NULL;
32 fz_pixmap *tile = NULL; 32 fz_pixmap *tile = NULL;
@@ -275,7 +275,7 @@ pdf_load_image_imp(pdf_xref *xref, fz_obj *rdb, fz_obj *dict, fz_stream *cstm, i
275} 275}
276 276
277fz_pixmap * 277fz_pixmap *
278pdf_load_inline_image(pdf_xref *xref, fz_obj *rdb, fz_obj *dict, fz_stream *file) 278pdf_load_inline_image(pdf_document *xref, fz_obj *rdb, fz_obj *dict, fz_stream *file)
279{ 279{
280 return pdf_load_image_imp(xref, rdb, dict, file, 0); 280 return pdf_load_image_imp(xref, rdb, dict, file, 0);
281 /* RJW: "cannot load inline image" */ 281 /* RJW: "cannot load inline image" */
@@ -298,7 +298,7 @@ pdf_is_jpx_image(fz_context *ctx, fz_obj *dict)
298} 298}
299 299
300static fz_pixmap * 300static fz_pixmap *
301pdf_load_jpx_image(pdf_xref *xref, fz_obj *dict) 301pdf_load_jpx_image(pdf_document *xref, fz_obj *dict)
302{ 302{
303 fz_buffer *buf = NULL; 303 fz_buffer *buf = NULL;
304 fz_colorspace *colorspace = NULL; 304 fz_colorspace *colorspace = NULL;
@@ -367,7 +367,7 @@ pdf_load_jpx_image(pdf_xref *xref, fz_obj *dict)
367} 367}
368 368
369fz_pixmap * 369fz_pixmap *
370pdf_load_image(pdf_xref *xref, fz_obj *dict) 370pdf_load_image(pdf_document *xref, fz_obj *dict)
371{ 371{
372 fz_context *ctx = xref->ctx; 372 fz_context *ctx = xref->ctx;
373 fz_pixmap *pix; 373 fz_pixmap *pix;
diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c
index ff9a8f2c3..3b774d716 100644
--- a/pdf/pdf_interpret.c
+++ b/pdf/pdf_interpret.c
@@ -64,7 +64,7 @@ struct pdf_gstate_s
64struct pdf_csi_s 64struct pdf_csi_s
65{ 65{
66 fz_device *dev; 66 fz_device *dev;
67 pdf_xref *xref; 67 pdf_document *xref;
68 68
69 /* usage mode for optional content groups */ 69 /* usage mode for optional content groups */
70 char *event; /* "View", "Print", "Export" */ 70 char *event; /* "View", "Print", "Export" */
@@ -942,7 +942,7 @@ copy_state(fz_context *ctx, pdf_gstate *gs, pdf_gstate *old)
942 942
943 943
944static pdf_csi * 944static pdf_csi *
945pdf_new_csi(pdf_xref *xref, fz_device *dev, fz_matrix ctm, char *event, fz_cookie *cookie, pdf_gstate *gstate) 945pdf_new_csi(pdf_document *xref, fz_device *dev, fz_matrix ctm, char *event, fz_cookie *cookie, pdf_gstate *gstate)
946{ 946{
947 pdf_csi *csi; 947 pdf_csi *csi;
948 fz_context *ctx = dev->ctx; 948 fz_context *ctx = dev->ctx;
@@ -2685,7 +2685,7 @@ pdf_run_buffer(pdf_csi *csi, fz_obj *rdb, fz_buffer *contents)
2685} 2685}
2686 2686
2687void 2687void
2688pdf_run_page_with_usage(pdf_xref *xref, pdf_page *page, fz_device *dev, fz_matrix ctm, char *event, fz_cookie *cookie) 2688pdf_run_page_with_usage(pdf_document *xref, pdf_page *page, fz_device *dev, fz_matrix ctm, char *event, fz_cookie *cookie)
2689{ 2689{
2690 fz_context *ctx = dev->ctx; 2690 fz_context *ctx = dev->ctx;
2691 pdf_csi *csi; 2691 pdf_csi *csi;
@@ -2760,13 +2760,13 @@ pdf_run_page_with_usage(pdf_xref *xref, pdf_page *page, fz_device *dev, fz_matri
2760} 2760}
2761 2761
2762void 2762void
2763pdf_run_page(pdf_xref *xref, pdf_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie) 2763pdf_run_page(pdf_document *xref, pdf_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie)
2764{ 2764{
2765 pdf_run_page_with_usage(xref, page, dev, ctm, "View", cookie); 2765 pdf_run_page_with_usage(xref, page, dev, ctm, "View", cookie);
2766} 2766}
2767 2767
2768void 2768void
2769pdf_run_glyph(pdf_xref *xref, fz_obj *resources, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate) 2769pdf_run_glyph(pdf_document *xref, fz_obj *resources, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate)
2770{ 2770{
2771 pdf_csi *csi = pdf_new_csi(xref, dev, ctm, "View", NULL, gstate); 2771 pdf_csi *csi = pdf_new_csi(xref, dev, ctm, "View", NULL, gstate);
2772 fz_context *ctx = xref->ctx; 2772 fz_context *ctx = xref->ctx;
diff --git a/pdf/pdf_nametree.c b/pdf/pdf_nametree.c
index bbb956f15..c78e238dd 100644
--- a/pdf/pdf_nametree.c
+++ b/pdf/pdf_nametree.c
@@ -71,7 +71,7 @@ pdf_lookup_name_imp(fz_context *ctx, fz_obj *node, fz_obj *needle)
71} 71}
72 72
73fz_obj * 73fz_obj *
74pdf_lookup_name(pdf_xref *xref, char *which, fz_obj *needle) 74pdf_lookup_name(pdf_document *xref, char *which, fz_obj *needle)
75{ 75{
76 fz_context *ctx = xref->ctx; 76 fz_context *ctx = xref->ctx;
77 77
@@ -82,7 +82,7 @@ pdf_lookup_name(pdf_xref *xref, char *which, fz_obj *needle)
82} 82}
83 83
84fz_obj * 84fz_obj *
85pdf_lookup_dest(pdf_xref *xref, fz_obj *needle) 85pdf_lookup_dest(pdf_document *xref, fz_obj *needle)
86{ 86{
87 fz_context *ctx = xref->ctx; 87 fz_context *ctx = xref->ctx;
88 88
@@ -111,7 +111,7 @@ pdf_lookup_dest(pdf_xref *xref, fz_obj *needle)
111} 111}
112 112
113static void 113static void
114pdf_load_name_tree_imp(fz_obj *dict, pdf_xref *xref, fz_obj *node) 114pdf_load_name_tree_imp(fz_obj *dict, pdf_document *xref, fz_obj *node)
115{ 115{
116 fz_context *ctx = xref->ctx; 116 fz_context *ctx = xref->ctx;
117 fz_obj *kids = fz_dict_gets(node, "Kids"); 117 fz_obj *kids = fz_dict_gets(node, "Kids");
@@ -146,7 +146,7 @@ pdf_load_name_tree_imp(fz_obj *dict, pdf_xref *xref, fz_obj *node)
146} 146}
147 147
148fz_obj * 148fz_obj *
149pdf_load_name_tree(pdf_xref *xref, char *which) 149pdf_load_name_tree(pdf_document *xref, char *which)
150{ 150{
151 fz_context *ctx = xref->ctx; 151 fz_context *ctx = xref->ctx;
152 152
diff --git a/pdf/pdf_outline.c b/pdf/pdf_outline.c
index 5762be05e..2815d918d 100644
--- a/pdf/pdf_outline.c
+++ b/pdf/pdf_outline.c
@@ -2,7 +2,7 @@
2#include "mupdf.h" 2#include "mupdf.h"
3 3
4static fz_outline * 4static fz_outline *
5pdf_load_outline_imp(pdf_xref *xref, fz_obj *dict) 5pdf_load_outline_imp(pdf_document *xref, fz_obj *dict)
6{ 6{
7 fz_context *ctx = xref->ctx; 7 fz_context *ctx = xref->ctx;
8 fz_outline *node, **prev, *first; 8 fz_outline *node, **prev, *first;
@@ -58,7 +58,7 @@ pdf_load_outline_imp(pdf_xref *xref, fz_obj *dict)
58} 58}
59 59
60fz_outline * 60fz_outline *
61pdf_load_outline(pdf_xref *xref) 61pdf_load_outline(pdf_document *xref)
62{ 62{
63 fz_obj *root, *obj, *first; 63 fz_obj *root, *obj, *first;
64 64
diff --git a/pdf/pdf_page.c b/pdf/pdf_page.c
index 8cfadfb75..ed80aa90d 100644
--- a/pdf/pdf_page.c
+++ b/pdf/pdf_page.c
@@ -28,7 +28,7 @@ put_marker_bool(fz_context *ctx, fz_obj *rdb, char *marker, int val)
28} 28}
29 29
30static void 30static void
31pdf_load_page_tree_node(pdf_xref *xref, fz_obj *node, struct info info) 31pdf_load_page_tree_node(pdf_document *xref, fz_obj *node, struct info info)
32{ 32{
33 fz_obj *dict, *kids, *count; 33 fz_obj *dict, *kids, *count;
34 fz_obj *obj; 34 fz_obj *obj;
@@ -99,7 +99,7 @@ pdf_load_page_tree_node(pdf_xref *xref, fz_obj *node, struct info info)
99} 99}
100 100
101static void 101static void
102pdf_load_page_tree(pdf_xref *xref) 102pdf_load_page_tree(pdf_document *xref)
103{ 103{
104 fz_context *ctx = xref->ctx; 104 fz_context *ctx = xref->ctx;
105 fz_obj *catalog; 105 fz_obj *catalog;
@@ -133,14 +133,14 @@ pdf_load_page_tree(pdf_xref *xref)
133} 133}
134 134
135int 135int
136pdf_count_pages(pdf_xref *xref) 136pdf_count_pages(pdf_document *xref)
137{ 137{
138 pdf_load_page_tree(xref); 138 pdf_load_page_tree(xref);
139 return xref->page_len; 139 return xref->page_len;
140} 140}
141 141
142int 142int
143pdf_find_page_number(pdf_xref *xref, fz_obj *page) 143pdf_find_page_number(pdf_document *xref, fz_obj *page)
144{ 144{
145 int i, num = fz_to_num(page); 145 int i, num = fz_to_num(page);
146 146
@@ -239,7 +239,7 @@ found:
239/* we need to combine all sub-streams into one for the content stream interpreter */ 239/* we need to combine all sub-streams into one for the content stream interpreter */
240 240
241static fz_buffer * 241static fz_buffer *
242pdf_load_page_contents_array(pdf_xref *xref, fz_obj *list) 242pdf_load_page_contents_array(pdf_document *xref, fz_obj *list)
243{ 243{
244 fz_buffer *big; 244 fz_buffer *big;
245 fz_buffer *one; 245 fz_buffer *one;
@@ -282,7 +282,7 @@ pdf_load_page_contents_array(pdf_xref *xref, fz_obj *list)
282} 282}
283 283
284static fz_buffer * 284static fz_buffer *
285pdf_load_page_contents(pdf_xref *xref, fz_obj *obj) 285pdf_load_page_contents(pdf_document *xref, fz_obj *obj)
286{ 286{
287 fz_context *ctx = xref->ctx; 287 fz_context *ctx = xref->ctx;
288 288
@@ -302,7 +302,7 @@ pdf_load_page_contents(pdf_xref *xref, fz_obj *obj)
302} 302}
303 303
304pdf_page * 304pdf_page *
305pdf_load_page(pdf_xref *xref, int number) 305pdf_load_page(pdf_document *xref, int number)
306{ 306{
307 fz_context *ctx = xref->ctx; 307 fz_context *ctx = xref->ctx;
308 pdf_page *page; 308 pdf_page *page;
@@ -389,7 +389,7 @@ pdf_load_page(pdf_xref *xref, int number)
389} 389}
390 390
391fz_rect 391fz_rect
392pdf_bound_page(pdf_xref *xref, pdf_page *page) 392pdf_bound_page(pdf_document *xref, pdf_page *page)
393{ 393{
394 fz_rect bounds, mediabox = fz_transform_rect(fz_rotate(page->rotate), page->mediabox); 394 fz_rect bounds, mediabox = fz_transform_rect(fz_rotate(page->rotate), page->mediabox);
395 bounds.x0 = bounds.y0 = 0; 395 bounds.x0 = bounds.y0 = 0;
diff --git a/pdf/pdf_parse.c b/pdf/pdf_parse.c
index b2f4fbf71..220eb30cc 100644
--- a/pdf/pdf_parse.c
+++ b/pdf/pdf_parse.c
@@ -171,7 +171,7 @@ pdf_to_utf8_name(fz_context *ctx, fz_obj *src)
171} 171}
172 172
173fz_obj * 173fz_obj *
174pdf_parse_array(pdf_xref *xref, fz_stream *file, char *buf, int cap) 174pdf_parse_array(pdf_document *xref, fz_stream *file, char *buf, int cap)
175{ 175{
176 fz_obj *ary = NULL; 176 fz_obj *ary = NULL;
177 fz_obj *obj = NULL; 177 fz_obj *obj = NULL;
@@ -312,7 +312,7 @@ end:
312} 312}
313 313
314fz_obj * 314fz_obj *
315pdf_parse_dict(pdf_xref *xref, fz_stream *file, char *buf, int cap) 315pdf_parse_dict(pdf_document *xref, fz_stream *file, char *buf, int cap)
316{ 316{
317 fz_obj *dict = NULL; 317 fz_obj *dict = NULL;
318 fz_obj *key = NULL; 318 fz_obj *key = NULL;
@@ -414,7 +414,7 @@ pdf_parse_dict(pdf_xref *xref, fz_stream *file, char *buf, int cap)
414} 414}
415 415
416fz_obj * 416fz_obj *
417pdf_parse_stm_obj(pdf_xref *xref, fz_stream *file, char *buf, int cap) 417pdf_parse_stm_obj(pdf_document *xref, fz_stream *file, char *buf, int cap)
418{ 418{
419 int tok; 419 int tok;
420 int len; 420 int len;
@@ -444,7 +444,7 @@ pdf_parse_stm_obj(pdf_xref *xref, fz_stream *file, char *buf, int cap)
444} 444}
445 445
446fz_obj * 446fz_obj *
447pdf_parse_ind_obj(pdf_xref *xref, 447pdf_parse_ind_obj(pdf_document *xref,
448 fz_stream *file, char *buf, int cap, 448 fz_stream *file, char *buf, int cap,
449 int *onum, int *ogen, int *ostmofs) 449 int *onum, int *ogen, int *ostmofs)
450{ 450{
diff --git a/pdf/pdf_pattern.c b/pdf/pdf_pattern.c
index 2b4d32a23..9ffbee02c 100644
--- a/pdf/pdf_pattern.c
+++ b/pdf/pdf_pattern.c
@@ -34,7 +34,7 @@ pdf_pattern_size(pdf_pattern *pat)
34} 34}
35 35
36pdf_pattern * 36pdf_pattern *
37pdf_load_pattern(pdf_xref *xref, fz_obj *dict) 37pdf_load_pattern(pdf_document *xref, fz_obj *dict)
38{ 38{
39 pdf_pattern *pat; 39 pdf_pattern *pat;
40 fz_obj *obj; 40 fz_obj *obj;
diff --git a/pdf/pdf_repair.c b/pdf/pdf_repair.c
index cdd8c5215..15886a8f0 100644
--- a/pdf/pdf_repair.c
+++ b/pdf/pdf_repair.c
@@ -141,7 +141,7 @@ atobjend:
141} 141}
142 142
143static void 143static void
144pdf_repair_obj_stm(pdf_xref *xref, int num, int gen) 144pdf_repair_obj_stm(pdf_document *xref, int num, int gen)
145{ 145{
146 fz_obj *obj; 146 fz_obj *obj;
147 fz_stream *stm = NULL; 147 fz_stream *stm = NULL;
@@ -193,7 +193,7 @@ pdf_repair_obj_stm(pdf_xref *xref, int num, int gen)
193} 193}
194 194
195void 195void
196pdf_repair_xref(pdf_xref *xref, char *buf, int bufsize) 196pdf_repair_xref(pdf_document *xref, char *buf, int bufsize)
197{ 197{
198 fz_obj *dict, *obj; 198 fz_obj *dict, *obj;
199 fz_obj *length; 199 fz_obj *length;
@@ -475,7 +475,7 @@ pdf_repair_xref(pdf_xref *xref, char *buf, int bufsize)
475} 475}
476 476
477void 477void
478pdf_repair_obj_stms(pdf_xref *xref) 478pdf_repair_obj_stms(pdf_document *xref)
479{ 479{
480 fz_obj *dict; 480 fz_obj *dict;
481 int i; 481 int i;
diff --git a/pdf/pdf_shade.c b/pdf/pdf_shade.c
index 4f43c225f..15f5de6b4 100644
--- a/pdf/pdf_shade.c
+++ b/pdf/pdf_shade.c
@@ -363,7 +363,7 @@ pdf_sample_shade_function(fz_context *ctx, fz_shade *shade, int funcs, pdf_funct
363/* Type 1-3 -- Function-based, axial and radial shadings */ 363/* Type 1-3 -- Function-based, axial and radial shadings */
364 364
365static void 365static void
366pdf_load_function_based_shading(fz_shade *shade, pdf_xref *xref, fz_obj *dict, pdf_function *func) 366pdf_load_function_based_shading(fz_shade *shade, pdf_document *xref, fz_obj *dict, pdf_function *func)
367{ 367{
368 fz_obj *obj; 368 fz_obj *obj;
369 float x0, y0, x1, y1; 369 float x0, y0, x1, y1;
@@ -428,7 +428,7 @@ pdf_load_function_based_shading(fz_shade *shade, pdf_xref *xref, fz_obj *dict, p
428} 428}
429 429
430static void 430static void
431pdf_load_axial_shading(fz_shade *shade, pdf_xref *xref, fz_obj *dict, int funcs, pdf_function **func) 431pdf_load_axial_shading(fz_shade *shade, pdf_document *xref, fz_obj *dict, int funcs, pdf_function **func)
432{ 432{
433 fz_obj *obj; 433 fz_obj *obj;
434 float d0, d1; 434 float d0, d1;
@@ -479,7 +479,7 @@ pdf_load_axial_shading(fz_shade *shade, pdf_xref *xref, fz_obj *dict, int funcs,
479} 479}
480 480
481static void 481static void
482pdf_load_radial_shading(fz_shade *shade, pdf_xref *xref, fz_obj *dict, int funcs, pdf_function **func) 482pdf_load_radial_shading(fz_shade *shade, pdf_document *xref, fz_obj *dict, int funcs, pdf_function **func)
483{ 483{
484 fz_obj *obj; 484 fz_obj *obj;
485 float d0, d1; 485 float d0, d1;
@@ -553,7 +553,7 @@ struct mesh_params
553}; 553};
554 554
555static void 555static void
556pdf_load_mesh_params(pdf_xref *xref, fz_obj *dict, struct mesh_params *p) 556pdf_load_mesh_params(pdf_document *xref, fz_obj *dict, struct mesh_params *p)
557{ 557{
558 fz_obj *obj; 558 fz_obj *obj;
559 int i, n; 559 int i, n;
@@ -603,7 +603,7 @@ pdf_load_mesh_params(pdf_xref *xref, fz_obj *dict, struct mesh_params *p)
603} 603}
604 604
605static void 605static void
606pdf_load_type4_shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict, 606pdf_load_type4_shade(fz_shade *shade, pdf_document *xref, fz_obj *dict,
607 int funcs, pdf_function **func, fz_stream *stream) 607 int funcs, pdf_function **func, fz_stream *stream)
608{ 608{
609 fz_context *ctx = xref->ctx; 609 fz_context *ctx = xref->ctx;
@@ -668,7 +668,7 @@ pdf_load_type4_shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict,
668} 668}
669 669
670static void 670static void
671pdf_load_type5_shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict, 671pdf_load_type5_shade(fz_shade *shade, pdf_document *xref, fz_obj *dict,
672 int funcs, pdf_function **func, fz_stream *stream) 672 int funcs, pdf_function **func, fz_stream *stream)
673{ 673{
674 fz_context *ctx = xref->ctx; 674 fz_context *ctx = xref->ctx;
@@ -718,7 +718,7 @@ pdf_load_type5_shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict,
718/* Type 6 & 7 -- Patch mesh shadings */ 718/* Type 6 & 7 -- Patch mesh shadings */
719 719
720static void 720static void
721pdf_load_type6_shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict, 721pdf_load_type6_shade(fz_shade *shade, pdf_document *xref, fz_obj *dict,
722 int funcs, pdf_function **func, fz_stream *stream) 722 int funcs, pdf_function **func, fz_stream *stream)
723{ 723{
724 fz_context *ctx = xref->ctx; 724 fz_context *ctx = xref->ctx;
@@ -837,7 +837,7 @@ pdf_load_type6_shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict,
837} 837}
838 838
839static void 839static void
840pdf_load_type7_shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict, 840pdf_load_type7_shade(fz_shade *shade, pdf_document *xref, fz_obj *dict,
841 int funcs, pdf_function **func, fz_stream *stream) 841 int funcs, pdf_function **func, fz_stream *stream)
842{ 842{
843 fz_context *ctx = xref->ctx; 843 fz_context *ctx = xref->ctx;
@@ -958,7 +958,7 @@ pdf_load_type7_shade(fz_shade *shade, pdf_xref *xref, fz_obj *dict,
958/* Load all of the shading dictionary parameters, then switch on the shading type. */ 958/* Load all of the shading dictionary parameters, then switch on the shading type. */
959 959
960static fz_shade * 960static fz_shade *
961pdf_load_shading_dict(pdf_xref *xref, fz_obj *dict, fz_matrix transform) 961pdf_load_shading_dict(pdf_document *xref, fz_obj *dict, fz_matrix transform)
962{ 962{
963 fz_shade *shade = NULL; 963 fz_shade *shade = NULL;
964 pdf_function *func[FZ_MAX_COLORS] = { NULL }; 964 pdf_function *func[FZ_MAX_COLORS] = { NULL };
@@ -1089,7 +1089,7 @@ fz_shade_size(fz_shade *s)
1089} 1089}
1090 1090
1091fz_shade * 1091fz_shade *
1092pdf_load_shading(pdf_xref *xref, fz_obj *dict) 1092pdf_load_shading(pdf_document *xref, fz_obj *dict)
1093{ 1093{
1094 fz_matrix mat; 1094 fz_matrix mat;
1095 fz_obj *obj; 1095 fz_obj *obj;
diff --git a/pdf/pdf_stream.c b/pdf/pdf_stream.c
index bf9ccc705..75c0f59cc 100644
--- a/pdf/pdf_stream.c
+++ b/pdf/pdf_stream.c
@@ -5,7 +5,7 @@
5 * Check if an object is a stream or not. 5 * Check if an object is a stream or not.
6 */ 6 */
7int 7int
8pdf_is_stream(pdf_xref *xref, int num, int gen) 8pdf_is_stream(pdf_document *xref, int num, int gen)
9{ 9{
10 if (num < 0 || num >= xref->len) 10 if (num < 0 || num >= xref->len)
11 return 0; 11 return 0;
@@ -49,7 +49,7 @@ pdf_stream_has_crypt(fz_context *ctx, fz_obj *stm)
49 * Create a filter given a name and param dictionary. 49 * Create a filter given a name and param dictionary.
50 */ 50 */
51static fz_stream * 51static fz_stream *
52build_filter(fz_stream *chain, pdf_xref * xref, fz_obj * f, fz_obj * p, int num, int gen) 52build_filter(fz_stream *chain, pdf_document * xref, fz_obj * f, fz_obj * p, int num, int gen)
53{ 53{
54 char *s; 54 char *s;
55 fz_context *ctx = chain->ctx; 55 fz_context *ctx = chain->ctx;
@@ -127,7 +127,7 @@ build_filter(fz_stream *chain, pdf_xref * xref, fz_obj * f, fz_obj * p, int num,
127 * Assume ownership of head. 127 * Assume ownership of head.
128 */ 128 */
129static fz_stream * 129static fz_stream *
130build_filter_chain(fz_stream *chain, pdf_xref *xref, fz_obj *fs, fz_obj *ps, int num, int gen) 130build_filter_chain(fz_stream *chain, pdf_document *xref, fz_obj *fs, fz_obj *ps, int num, int gen)
131{ 131{
132 fz_obj *f; 132 fz_obj *f;
133 fz_obj *p; 133 fz_obj *p;
@@ -150,7 +150,7 @@ build_filter_chain(fz_stream *chain, pdf_xref *xref, fz_obj *fs, fz_obj *ps, int
150 * stream length, followed by a decryption filter. 150 * stream length, followed by a decryption filter.
151 */ 151 */
152static fz_stream * 152static fz_stream *
153pdf_open_raw_filter(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int num, int gen) 153pdf_open_raw_filter(fz_stream *chain, pdf_document *xref, fz_obj *stmobj, int num, int gen)
154{ 154{
155 int hascrypt; 155 int hascrypt;
156 int len; 156 int len;
@@ -182,7 +182,7 @@ pdf_open_raw_filter(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int num, i
182 * to stream length and decrypting. 182 * to stream length and decrypting.
183 */ 183 */
184static fz_stream * 184static fz_stream *
185pdf_open_filter(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int num, int gen) 185pdf_open_filter(fz_stream *chain, pdf_document *xref, fz_obj *stmobj, int num, int gen)
186{ 186{
187 fz_obj *filters; 187 fz_obj *filters;
188 fz_obj *params; 188 fz_obj *params;
@@ -205,7 +205,7 @@ pdf_open_filter(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int num, int g
205 * constraining to stream length, and without decryption. 205 * constraining to stream length, and without decryption.
206 */ 206 */
207fz_stream * 207fz_stream *
208pdf_open_inline_stream(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int length) 208pdf_open_inline_stream(fz_stream *chain, pdf_document *xref, fz_obj *stmobj, int length)
209{ 209{
210 fz_obj *filters; 210 fz_obj *filters;
211 fz_obj *params; 211 fz_obj *params;
@@ -229,7 +229,7 @@ pdf_open_inline_stream(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int len
229 * Using xref->file while this is open is a bad idea. 229 * Using xref->file while this is open is a bad idea.
230 */ 230 */
231fz_stream * 231fz_stream *
232pdf_open_raw_stream(pdf_xref *xref, int num, int gen) 232pdf_open_raw_stream(pdf_document *xref, int num, int gen)
233{ 233{
234 pdf_xref_entry *x; 234 pdf_xref_entry *x;
235 fz_stream *stm; 235 fz_stream *stm;
@@ -258,7 +258,7 @@ pdf_open_raw_stream(pdf_xref *xref, int num, int gen)
258 * Using xref->file while a stream is open is a Bad idea. 258 * Using xref->file while a stream is open is a Bad idea.
259 */ 259 */
260fz_stream * 260fz_stream *
261pdf_open_stream(pdf_xref *xref, int num, int gen) 261pdf_open_stream(pdf_document *xref, int num, int gen)
262{ 262{
263 pdf_xref_entry *x; 263 pdf_xref_entry *x;
264 fz_stream *stm; 264 fz_stream *stm;
@@ -280,7 +280,7 @@ pdf_open_stream(pdf_xref *xref, int num, int gen)
280} 280}
281 281
282fz_stream * 282fz_stream *
283pdf_open_stream_at(pdf_xref *xref, int num, int gen, fz_obj *dict, int stm_ofs) 283pdf_open_stream_at(pdf_document *xref, int num, int gen, fz_obj *dict, int stm_ofs)
284{ 284{
285 fz_stream *stm; 285 fz_stream *stm;
286 286
@@ -296,7 +296,7 @@ pdf_open_stream_at(pdf_xref *xref, int num, int gen, fz_obj *dict, int stm_ofs)
296 * Load raw (compressed but decrypted) contents of a stream into buf. 296 * Load raw (compressed but decrypted) contents of a stream into buf.
297 */ 297 */
298fz_buffer * 298fz_buffer *
299pdf_load_raw_stream(pdf_xref *xref, int num, int gen) 299pdf_load_raw_stream(pdf_document *xref, int num, int gen)
300{ 300{
301 fz_stream *stm; 301 fz_stream *stm;
302 fz_obj *dict; 302 fz_obj *dict;
@@ -340,7 +340,7 @@ pdf_guess_filter_length(int len, char *filter)
340 * Load uncompressed contents of a stream into buf. 340 * Load uncompressed contents of a stream into buf.
341 */ 341 */
342fz_buffer * 342fz_buffer *
343pdf_load_stream(pdf_xref *xref, int num, int gen) 343pdf_load_stream(pdf_document *xref, int num, int gen)
344{ 344{
345 fz_context *ctx = xref->ctx; 345 fz_context *ctx = xref->ctx;
346 fz_stream *stm = NULL; 346 fz_stream *stm = NULL;
diff --git a/pdf/pdf_type3.c b/pdf/pdf_type3.c
index d9bf528ec..176bf32a0 100644
--- a/pdf/pdf_type3.c
+++ b/pdf/pdf_type3.c
@@ -2,13 +2,13 @@
2#include "mupdf.h" 2#include "mupdf.h"
3 3
4static void 4static void
5pdf_run_glyph_func(void *xref, fz_obj *rdb, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate) 5pdf_run_glyph_func(void *doc, fz_obj *rdb, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate)
6{ 6{
7 pdf_run_glyph(xref, rdb, contents, dev, ctm, gstate); 7 pdf_run_glyph(doc, rdb, contents, dev, ctm, gstate);
8} 8}
9 9
10pdf_font_desc * 10pdf_font_desc *
11pdf_load_type3_font(pdf_xref *xref, fz_obj *rdb, fz_obj *dict) 11pdf_load_type3_font(pdf_document *xref, fz_obj *rdb, fz_obj *dict)
12{ 12{
13 char buf[256]; 13 char buf[256];
14 char *estrings[256]; 14 char *estrings[256];
@@ -125,7 +125,7 @@ pdf_load_type3_font(pdf_xref *xref, fz_obj *rdb, fz_obj *dict)
125 if (!fontdesc->font->t3resources) 125 if (!fontdesc->font->t3resources)
126 fz_warn(ctx, "no resource dictionary for type 3 font!"); 126 fz_warn(ctx, "no resource dictionary for type 3 font!");
127 127
128 fontdesc->font->t3xref = xref; 128 fontdesc->font->t3doc = xref;
129 fontdesc->font->t3run = pdf_run_glyph_func; 129 fontdesc->font->t3run = pdf_run_glyph_func;
130 130
131 /* CharProcs */ 131 /* CharProcs */
diff --git a/pdf/pdf_unicode.c b/pdf/pdf_unicode.c
index 95e7fa00d..1fed0f633 100644
--- a/pdf/pdf_unicode.c
+++ b/pdf/pdf_unicode.c
@@ -4,7 +4,7 @@
4/* Load or synthesize ToUnicode map for fonts */ 4/* Load or synthesize ToUnicode map for fonts */
5 5
6void 6void
7pdf_load_to_unicode(pdf_font_desc *font, pdf_xref *xref, 7pdf_load_to_unicode(pdf_font_desc *font, pdf_document *xref,
8 char **strings, char *collection, fz_obj *cmapstm) 8 char **strings, char *collection, fz_obj *cmapstm)
9{ 9{
10 pdf_cmap *cmap; 10 pdf_cmap *cmap;
diff --git a/pdf/pdf_xobject.c b/pdf/pdf_xobject.c
index e33ac8588..91bf4db36 100644
--- a/pdf/pdf_xobject.c
+++ b/pdf/pdf_xobject.c
@@ -37,7 +37,7 @@ pdf_xobject_size(pdf_xobject *xobj)
37} 37}
38 38
39pdf_xobject * 39pdf_xobject *
40pdf_load_xobject(pdf_xref *xref, fz_obj *dict) 40pdf_load_xobject(pdf_document *xref, fz_obj *dict)
41{ 41{
42 pdf_xobject *form; 42 pdf_xobject *form;
43 fz_obj *obj; 43 fz_obj *obj;
diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c
index bfd04acbb..7fb247d99 100644
--- a/pdf/pdf_xref.c
+++ b/pdf/pdf_xref.c
@@ -13,7 +13,7 @@ static inline int iswhite(int ch)
13 */ 13 */
14 14
15static void 15static void
16pdf_load_version(pdf_xref *xref) 16pdf_load_version(pdf_document *xref)
17{ 17{
18 char buf[20]; 18 char buf[20];
19 19
@@ -26,7 +26,7 @@ pdf_load_version(pdf_xref *xref)
26} 26}
27 27
28static void 28static void
29pdf_read_start_xref(pdf_xref *xref) 29pdf_read_start_xref(pdf_document *xref)
30{ 30{
31 unsigned char buf[1024]; 31 unsigned char buf[1024];
32 int t, n; 32 int t, n;
@@ -63,7 +63,7 @@ pdf_read_start_xref(pdf_xref *xref)
63 */ 63 */
64 64
65static void 65static void
66pdf_read_old_trailer(pdf_xref *xref, char *buf, int cap) 66pdf_read_old_trailer(pdf_document *xref, char *buf, int cap)
67{ 67{
68 int len; 68 int len;
69 char *s; 69 char *s;
@@ -119,7 +119,7 @@ pdf_read_old_trailer(pdf_xref *xref, char *buf, int cap)
119} 119}
120 120
121static void 121static void
122pdf_read_new_trailer(pdf_xref *xref, char *buf, int cap) 122pdf_read_new_trailer(pdf_document *xref, char *buf, int cap)
123{ 123{
124 fz_try(xref->ctx) 124 fz_try(xref->ctx)
125 { 125 {
@@ -132,7 +132,7 @@ pdf_read_new_trailer(pdf_xref *xref, char *buf, int cap)
132} 132}
133 133
134static void 134static void
135pdf_read_trailer(pdf_xref *xref, char *buf, int cap) 135pdf_read_trailer(pdf_document *xref, char *buf, int cap)
136{ 136{
137 int c; 137 int c;
138 138
@@ -162,7 +162,7 @@ pdf_read_trailer(pdf_xref *xref, char *buf, int cap)
162 */ 162 */
163 163
164void 164void
165pdf_resize_xref(pdf_xref *xref, int newlen) 165pdf_resize_xref(pdf_document *xref, int newlen)
166{ 166{
167 int i; 167 int i;
168 168
@@ -179,7 +179,7 @@ pdf_resize_xref(pdf_xref *xref, int newlen)
179} 179}
180 180
181static fz_obj * 181static fz_obj *
182pdf_read_old_xref(pdf_xref *xref, char *buf, int cap) 182pdf_read_old_xref(pdf_document *xref, char *buf, int cap)
183{ 183{
184 int ofs, len; 184 int ofs, len;
185 char *s; 185 char *s;
@@ -260,7 +260,7 @@ pdf_read_old_xref(pdf_xref *xref, char *buf, int cap)
260} 260}
261 261
262static void 262static void
263pdf_read_new_xref_section(pdf_xref *xref, fz_stream *stm, int i0, int i1, int w0, int w1, int w2) 263pdf_read_new_xref_section(pdf_document *xref, fz_stream *stm, int i0, int i1, int w0, int w1, int w2)
264{ 264{
265 int i, n; 265 int i, n;
266 266
@@ -294,7 +294,7 @@ pdf_read_new_xref_section(pdf_xref *xref, fz_stream *stm, int i0, int i1, int w0
294} 294}
295 295
296static fz_obj * 296static fz_obj *
297pdf_read_new_xref(pdf_xref *xref, char *buf, int cap) 297pdf_read_new_xref(pdf_document *xref, char *buf, int cap)
298{ 298{
299 fz_stream *stm = NULL; 299 fz_stream *stm = NULL;
300 fz_obj *trailer = NULL; 300 fz_obj *trailer = NULL;
@@ -373,7 +373,7 @@ pdf_read_new_xref(pdf_xref *xref, char *buf, int cap)
373} 373}
374 374
375static fz_obj * 375static fz_obj *
376pdf_read_xref(pdf_xref *xref, int ofs, char *buf, int cap) 376pdf_read_xref(pdf_document *xref, int ofs, char *buf, int cap)
377{ 377{
378 int c; 378 int c;
379 fz_context *ctx = xref->ctx; 379 fz_context *ctx = xref->ctx;
@@ -402,7 +402,7 @@ pdf_read_xref(pdf_xref *xref, int ofs, char *buf, int cap)
402} 402}
403 403
404static void 404static void
405pdf_read_xref_sections(pdf_xref *xref, int ofs, char *buf, int cap) 405pdf_read_xref_sections(pdf_document *xref, int ofs, char *buf, int cap)
406{ 406{
407 fz_obj *trailer = NULL; 407 fz_obj *trailer = NULL;
408 fz_obj *xrefstm = NULL; 408 fz_obj *xrefstm = NULL;
@@ -436,7 +436,7 @@ pdf_read_xref_sections(pdf_xref *xref, int ofs, char *buf, int cap)
436 */ 436 */
437 437
438static void 438static void
439pdf_load_xref(pdf_xref *xref, char *buf, int bufsize) 439pdf_load_xref(pdf_document *xref, char *buf, int bufsize)
440{ 440{
441 fz_obj *size; 441 fz_obj *size;
442 int i; 442 int i;
@@ -473,7 +473,7 @@ pdf_load_xref(pdf_xref *xref, char *buf, int bufsize)
473} 473}
474 474
475void 475void
476pdf_ocg_set_config(pdf_xref *xref, int config) 476pdf_ocg_set_config(pdf_document *xref, int config)
477{ 477{
478 int i, j, len, len2; 478 int i, j, len, len2;
479 pdf_ocg_descriptor *desc = xref->ocg; 479 pdf_ocg_descriptor *desc = xref->ocg;
@@ -578,7 +578,7 @@ pdf_ocg_set_config(pdf_xref *xref, int config)
578} 578}
579 579
580static void 580static void
581pdf_read_ocg(pdf_xref *xref) 581pdf_read_ocg(pdf_document *xref)
582{ 582{
583 fz_obj *obj, *ocg; 583 fz_obj *obj, *ocg;
584 int len, i; 584 int len, i;
@@ -638,10 +638,10 @@ pdf_free_ocg(fz_context *ctx, pdf_ocg_descriptor *desc)
638 * If password is not null, try to decrypt. 638 * If password is not null, try to decrypt.
639 */ 639 */
640 640
641pdf_xref * 641pdf_document *
642pdf_open_xref_with_stream(fz_stream *file) 642pdf_open_document_with_stream(fz_stream *file)
643{ 643{
644 pdf_xref *xref; 644 pdf_document *xref;
645 fz_obj *encrypt, *id; 645 fz_obj *encrypt, *id;
646 fz_obj *dict = NULL; 646 fz_obj *dict = NULL;
647 fz_obj *obj; 647 fz_obj *obj;
@@ -655,7 +655,7 @@ pdf_open_xref_with_stream(fz_stream *file)
655 /* install pdf specific callback */ 655 /* install pdf specific callback */
656 fz_resolve_indirect = pdf_resolve_indirect; 656 fz_resolve_indirect = pdf_resolve_indirect;
657 657
658 xref = fz_calloc(ctx, 1, sizeof(pdf_xref)); 658 xref = fz_calloc(ctx, 1, sizeof(pdf_document));
659 xref->file = fz_keep_stream(file); 659 xref->file = fz_keep_stream(file);
660 xref->ctx = ctx; 660 xref->ctx = ctx;
661 661
@@ -749,7 +749,7 @@ pdf_open_xref_with_stream(fz_stream *file)
749 { 749 {
750 fz_drop_obj(dict); 750 fz_drop_obj(dict);
751 fz_drop_obj(nobj); 751 fz_drop_obj(nobj);
752 pdf_free_xref(xref); 752 pdf_close_document(xref);
753 fz_throw(ctx, "cannot open document"); 753 fz_throw(ctx, "cannot open document");
754 } 754 }
755 755
@@ -766,7 +766,7 @@ pdf_open_xref_with_stream(fz_stream *file)
766} 766}
767 767
768void 768void
769pdf_free_xref(pdf_xref *xref) 769pdf_close_document(pdf_document *xref)
770{ 770{
771 int i; 771 int i;
772 fz_context *ctx; 772 fz_context *ctx;
@@ -817,7 +817,7 @@ pdf_free_xref(pdf_xref *xref)
817} 817}
818 818
819void 819void
820pdf_debug_xref(pdf_xref *xref) 820pdf_debug_xref(pdf_document *xref)
821{ 821{
822 int i; 822 int i;
823 printf("xref\n0 %d\n", xref->len); 823 printf("xref\n0 %d\n", xref->len);
@@ -836,7 +836,7 @@ pdf_debug_xref(pdf_xref *xref)
836 */ 836 */
837 837
838static void 838static void
839pdf_load_obj_stm(pdf_xref *xref, int num, int gen, char *buf, int cap) 839pdf_load_obj_stm(pdf_document *xref, int num, int gen, char *buf, int cap)
840{ 840{
841 fz_stream *stm = NULL; 841 fz_stream *stm = NULL;
842 fz_obj *objstm = NULL; 842 fz_obj *objstm = NULL;
@@ -925,7 +925,7 @@ pdf_load_obj_stm(pdf_xref *xref, int num, int gen, char *buf, int cap)
925 */ 925 */
926 926
927void 927void
928pdf_cache_object(pdf_xref *xref, int num, int gen) 928pdf_cache_object(pdf_document *xref, int num, int gen)
929{ 929{
930 pdf_xref_entry *x; 930 pdf_xref_entry *x;
931 int rnum, rgen; 931 int rnum, rgen;
@@ -991,7 +991,7 @@ pdf_cache_object(pdf_xref *xref, int num, int gen)
991} 991}
992 992
993fz_obj * 993fz_obj *
994pdf_load_object(pdf_xref *xref, int num, int gen) 994pdf_load_object(pdf_document *xref, int num, int gen)
995{ 995{
996 fz_context *ctx = xref->ctx; 996 fz_context *ctx = xref->ctx;
997 997
@@ -1016,13 +1016,13 @@ pdf_resolve_indirect(fz_obj *ref)
1016 int num; 1016 int num;
1017 int gen; 1017 int gen;
1018 fz_context *ctx = NULL; /* Avoid warning for stupid compilers */ 1018 fz_context *ctx = NULL; /* Avoid warning for stupid compilers */
1019 pdf_xref *xref; 1019 pdf_document *xref;
1020 1020
1021 while (fz_is_indirect(ref)) 1021 while (fz_is_indirect(ref))
1022 { 1022 {
1023 if (--sanity == 0) 1023 if (--sanity == 0)
1024 fz_throw(ctx, "Too many indirections (possible indirection cycle involving %d %d R)", num, gen); 1024 fz_throw(ctx, "Too many indirections (possible indirection cycle involving %d %d R)", num, gen);
1025 xref = fz_get_indirect_xref(ref); 1025 xref = fz_get_indirect_document(ref);
1026 if (!xref) 1026 if (!xref)
1027 return NULL; 1027 return NULL;
1028 ctx = xref->ctx; 1028 ctx = xref->ctx;
@@ -1047,7 +1047,7 @@ pdf_resolve_indirect(fz_obj *ref)
1047 1047
1048/* Replace numbered object -- for use by pdfclean and similar tools */ 1048/* Replace numbered object -- for use by pdfclean and similar tools */
1049void 1049void
1050pdf_update_object(pdf_xref *xref, int num, int gen, fz_obj *newobj) 1050pdf_update_object(pdf_document *xref, int num, int gen, fz_obj *newobj)
1051{ 1051{
1052 pdf_xref_entry *x; 1052 pdf_xref_entry *x;
1053 1053
@@ -1068,20 +1068,20 @@ pdf_update_object(pdf_xref *xref, int num, int gen, fz_obj *newobj)
1068} 1068}
1069 1069
1070/* 1070/*
1071 * Convenience function to open a file then call pdf_open_xref_with_stream. 1071 * Convenience function to open a file then call pdf_open_document_with_stream.
1072 */ 1072 */
1073 1073
1074pdf_xref * 1074pdf_document *
1075pdf_open_xref(fz_context *ctx, const char *filename) 1075pdf_open_document(fz_context *ctx, const char *filename)
1076{ 1076{
1077 fz_stream *file = NULL; 1077 fz_stream *file = NULL;
1078 pdf_xref *xref; 1078 pdf_document *xref;
1079 1079
1080 fz_var(file); 1080 fz_var(file);
1081 fz_try(ctx) 1081 fz_try(ctx)
1082 { 1082 {
1083 file = fz_open_file(ctx, filename); 1083 file = fz_open_file(ctx, filename);
1084 xref = pdf_open_xref_with_stream(file); 1084 xref = pdf_open_document_with_stream(file);
1085 } 1085 }
1086 fz_catch(ctx) 1086 fz_catch(ctx)
1087 { 1087 {
diff --git a/xps/muxps.h b/xps/muxps.h
index c708ac60a..e7bdfa414 100644
--- a/xps/muxps.h
+++ b/xps/muxps.h
@@ -251,9 +251,9 @@ struct xps_document_s
251 fz_device *dev; 251 fz_device *dev;
252}; 252};
253 253
254xps_document *xps_open_file(fz_context *ctx, char *filename); 254xps_document *xps_open_document(fz_context *ctx, char *filename);
255xps_document *xps_open_stream(fz_stream *file); 255xps_document *xps_open_document_with_stream(fz_stream *file);
256void xps_free_context(xps_document *doc); 256void xps_close_document(xps_document *doc);
257 257
258/* 258/*
259 * Parsing helper functions 259 * Parsing helper functions
diff --git a/xps/xps_zip.c b/xps/xps_zip.c
index cc7fbb5ee..f38538c33 100644
--- a/xps/xps_zip.c
+++ b/xps/xps_zip.c
@@ -451,7 +451,7 @@ xps_has_part(xps_document *doc, char *partname)
451} 451}
452 452
453static xps_document * 453static xps_document *
454xps_open_directory(fz_context *ctx, char *directory) 454xps_open_document_with_directory(fz_context *ctx, char *directory)
455{ 455{
456 xps_document *doc; 456 xps_document *doc;
457 457
@@ -467,7 +467,7 @@ xps_open_directory(fz_context *ctx, char *directory)
467 } 467 }
468 fz_catch(ctx) 468 fz_catch(ctx)
469 { 469 {
470 xps_free_context(doc); 470 xps_close_document(doc);
471 fz_rethrow(ctx); 471 fz_rethrow(ctx);
472 } 472 }
473 473
@@ -475,7 +475,7 @@ xps_open_directory(fz_context *ctx, char *directory)
475} 475}
476 476
477xps_document * 477xps_document *
478xps_open_stream(fz_stream *file) 478xps_open_document_with_stream(fz_stream *file)
479{ 479{
480 fz_context *ctx = file->ctx; 480 fz_context *ctx = file->ctx;
481 xps_document *doc; 481 xps_document *doc;
@@ -493,7 +493,7 @@ xps_open_stream(fz_stream *file)
493 } 493 }
494 fz_catch(ctx) 494 fz_catch(ctx)
495 { 495 {
496 xps_free_context(doc); 496 xps_close_document(doc);
497 fz_rethrow(ctx); 497 fz_rethrow(ctx);
498 } 498 }
499 499
@@ -501,7 +501,7 @@ xps_open_stream(fz_stream *file)
501} 501}
502 502
503xps_document * 503xps_document *
504xps_open_file(fz_context *ctx, char *filename) 504xps_open_document(fz_context *ctx, char *filename)
505{ 505{
506 char buf[2048]; 506 char buf[2048];
507 fz_stream *file; 507 fz_stream *file;
@@ -515,7 +515,7 @@ xps_open_file(fz_context *ctx, char *filename)
515 if (!p) 515 if (!p)
516 p = strstr(buf, "\\_rels\\.rels"); 516 p = strstr(buf, "\\_rels\\.rels");
517 *p = 0; 517 *p = 0;
518 return xps_open_directory(ctx, buf); 518 return xps_open_document_with_directory(ctx, buf);
519 } 519 }
520 520
521 file = fz_open_file(ctx, filename); 521 file = fz_open_file(ctx, filename);
@@ -524,7 +524,7 @@ xps_open_file(fz_context *ctx, char *filename)
524 524
525 fz_try(ctx) 525 fz_try(ctx)
526 { 526 {
527 doc = xps_open_stream(file); 527 doc = xps_open_document_with_stream(file);
528 } 528 }
529 fz_catch(ctx) 529 fz_catch(ctx)
530 { 530 {
@@ -536,7 +536,7 @@ xps_open_file(fz_context *ctx, char *filename)
536} 536}
537 537
538void 538void
539xps_free_context(xps_document *doc) 539xps_close_document(xps_document *doc)
540{ 540{
541 xps_font_cache *font, *next; 541 xps_font_cache *font, *next;
542 int i; 542 int i;