summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-04-05 01:18:03 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-04-05 01:18:03 +0200
commit69875363f1766f95c35c1fe429dd85ac9a19add5 (patch)
tree1204d27eadd066a37075c093befdb1973b2e71ce /apps
parentd2de9cee6036b997e536a0c0384b88b38e523e56 (diff)
downloadmupdf-69875363f1766f95c35c1fe429dd85ac9a19add5.tar.xz
Clean up xps and pdf page access functions.
Diffstat (limited to 'apps')
-rw-r--r--apps/pdfapp.c24
-rw-r--r--apps/pdfclean.c12
-rw-r--r--apps/pdfdraw.c12
-rw-r--r--apps/pdfinfo.c10
-rw-r--r--apps/pdfshow.c4
-rw-r--r--apps/xpsdraw.c10
6 files changed, 35 insertions, 37 deletions
diff --git a/apps/pdfapp.c b/apps/pdfapp.c
index 277bdbf0..46459497 100644
--- a/apps/pdfapp.c
+++ b/apps/pdfapp.c
@@ -159,7 +159,7 @@ static void pdfapp_open_pdf(pdfapp_t *app, char *filename, int fd)
if (error)
pdfapp_error(app, fz_rethrow(error, "cannot load page tree"));
- app->pagecount = pdf_get_page_count(app->xref);
+ app->pagecount = pdf_count_pages(app->xref);
}
static void pdfapp_open_xps(pdfapp_t *app, char *filename, int fd)
@@ -168,8 +168,7 @@ static void pdfapp_open_xps(pdfapp_t *app, char *filename, int fd)
close(fd); // TODO: fix this for windows
- app->xps = xps_new_context();
- error = xps_open_file(app->xps, filename);
+ error = xps_open_file(&app->xps, filename);
if (error)
pdfapp_error(app, fz_rethrow(error, "cannot open document: '%s'", filename));
@@ -278,10 +277,8 @@ static void pdfapp_loadpage_pdf(pdfapp_t *app)
pdf_page *page;
fz_error error;
fz_device *mdev;
- fz_obj *obj;
- obj = pdf_get_page_object(app->xref, app->pageno);
- error = pdf_load_page(&page, app->xref, obj);
+ error = pdf_load_page(&page, app->xref, app->pageno - 1);
if (error)
pdfapp_error(app, error);
@@ -310,10 +307,11 @@ static void pdfapp_loadpage_xps(pdfapp_t *app)
{
xps_page *page;
fz_device *mdev;
+ fz_error error;
- page = xps_load_page(app->xps, app->pageno - 1);
- if (!page)
- pdfapp_error(app, fz_rethrow(-1, "cannot load page %d in file '%s'", app->pageno, app->doctitle));
+ error = xps_load_page(&page, app->xps, app->pageno - 1);
+ if (error)
+ pdfapp_error(app, fz_rethrow(error, "cannot load page %d in file '%s'", app->pageno, app->doctitle));
app->page_bbox.x0 = 0;
app->page_bbox.y0 = 0;
@@ -436,9 +434,11 @@ static void pdfapp_gotouri(pdfapp_t *app, fz_obj *uri)
static void pdfapp_gotopage(pdfapp_t *app, fz_obj *obj)
{
- int page;
+ int number;
- page = pdf_find_page_object(app->xref, obj);
+ number = pdf_find_page_number(app->xref, obj);
+ if (number < 0)
+ return;
if (app->histlen + 1 == 256)
{
@@ -446,7 +446,7 @@ static void pdfapp_gotopage(pdfapp_t *app, fz_obj *obj)
app->histlen --;
}
app->hist[app->histlen++] = app->pageno;
- app->pageno = page;
+ app->pageno = number + 1;
pdfapp_showpage(app, 1, 1, 1);
}
diff --git a/apps/pdfclean.c b/apps/pdfclean.c
index 67c7809c..dd85b1a4 100644
--- a/apps/pdfclean.c
+++ b/apps/pdfclean.c
@@ -314,7 +314,7 @@ static void retainpages(int argc, char **argv)
dash = strchr(spec, '-');
if (dash == spec)
- spage = epage = pdf_get_page_count(xref);
+ spage = epage = pdf_count_pages(xref);
else
spage = epage = atoi(spec);
@@ -323,7 +323,7 @@ static void retainpages(int argc, char **argv)
if (strlen(dash) > 1)
epage = atoi(dash + 1);
else
- epage = pdf_get_page_count(xref);
+ epage = pdf_count_pages(xref);
}
if (spage > epage)
@@ -331,13 +331,13 @@ static void retainpages(int argc, char **argv)
if (spage < 1)
spage = 1;
- if (epage > pdf_get_page_count(xref))
- epage = pdf_get_page_count(xref);
+ if (epage > pdf_count_pages(xref))
+ epage = pdf_count_pages(xref);
for (page = spage; page <= epage; page++)
{
- fz_obj *pageobj = pdf_get_page_object(xref, page);
- fz_obj *pageref = pdf_get_page_ref(xref, page);
+ fz_obj *pageobj = xref->page_objs[page-1];
+ fz_obj *pageref = xref->page_refs[page-1];
fz_dict_puts(pageobj, "Parent", parent);
diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c
index f15fdfb4..baaac92c 100644
--- a/apps/pdfdraw.c
+++ b/apps/pdfdraw.c
@@ -87,7 +87,6 @@ static int isrange(char *s)
static void drawpage(pdf_xref *xref, int pagenum)
{
fz_error error;
- fz_obj *pageobj;
pdf_page *page;
fz_display_list *list;
fz_device *dev;
@@ -98,8 +97,7 @@ static void drawpage(pdf_xref *xref, int pagenum)
start = gettime();
}
- pageobj = pdf_get_page_object(xref, pagenum);
- error = pdf_load_page(&page, xref, pageobj);
+ error = pdf_load_page(&page, xref, pagenum - 1);
if (error)
die(fz_rethrow(error, "cannot load page %d in file '%s'", pagenum, filename));
@@ -253,7 +251,7 @@ static void drawrange(pdf_xref *xref, char *range)
dash = strchr(spec, '-');
if (dash == spec)
- spage = epage = pdf_get_page_count(xref);
+ spage = epage = pdf_count_pages(xref);
else
spage = epage = atoi(spec);
@@ -262,11 +260,11 @@ static void drawrange(pdf_xref *xref, char *range)
if (strlen(dash) > 1)
epage = atoi(dash + 1);
else
- epage = pdf_get_page_count(xref);
+ epage = pdf_count_pages(xref);
}
- spage = CLAMP(spage, 1, pdf_get_page_count(xref));
- epage = CLAMP(epage, 1, pdf_get_page_count(xref));
+ spage = CLAMP(spage, 1, pdf_count_pages(xref));
+ epage = CLAMP(epage, 1, pdf_count_pages(xref));
if (spage < epage)
for (page = spage; page <= epage; page++)
diff --git a/apps/pdfinfo.c b/apps/pdfinfo.c
index fcc2cb38..d8948264 100644
--- a/apps/pdfinfo.c
+++ b/apps/pdfinfo.c
@@ -569,8 +569,8 @@ gatherresourceinfo(int page, fz_obj *rsrc)
fz_obj *subrsrc;
int i;
- pageobj = pdf_get_page_object(xref, page);
- pageref = pdf_get_page_ref(xref, page);
+ pageobj = xref->page_objs[page-1];
+ pageref = xref->page_refs[page-1];
if (!pageobj)
die(fz_throw("cannot retrieve info from page %d", page));
@@ -632,8 +632,8 @@ gatherpageinfo(int page)
fz_obj *pageref;
fz_obj *rsrc;
- pageobj = pdf_get_page_object(xref, page);
- pageref = pdf_get_page_ref(xref, page);
+ pageobj = xref->page_objs[page-1];
+ pageref = xref->page_refs[page-1];
if (!pageobj)
die(fz_throw("cannot retrieve info from page %d", page));
@@ -988,7 +988,7 @@ int main(int argc, char **argv)
error = pdf_load_page_tree(xref);
if (error)
die(fz_rethrow(error, "cannot load page tree: %s", filename));
- pagecount = pdf_get_page_count(xref);
+ pagecount = pdf_count_pages(xref);
showglobalinfo();
state = NO_INFO_GATHERED;
diff --git a/apps/pdfshow.c b/apps/pdfshow.c
index 4c834035..5e74042b 100644
--- a/apps/pdfshow.c
+++ b/apps/pdfshow.c
@@ -61,10 +61,10 @@ static void showpagetree(void)
die(fz_rethrow(error, "cannot load page tree"));
}
- count = pdf_get_page_count(xref);
+ count = pdf_count_pages(xref);
for (i = 0; i < count; i++)
{
- ref = pdf_get_page_ref(xref, i + 1);
+ ref = xref->page_refs[i];
printf("page %d = %d %d R\n", i + 1, fz_to_num(ref), fz_to_gen(ref));
}
printf("\n");
diff --git a/apps/xpsdraw.c b/apps/xpsdraw.c
index 41d01c14..29738e6b 100644
--- a/apps/xpsdraw.c
+++ b/apps/xpsdraw.c
@@ -90,15 +90,16 @@ static void drawpage(xps_context *ctx, int pagenum)
fz_display_list *list;
fz_device *dev;
int start;
+ int code;
if (showtime)
{
start = gettime();
}
- page = xps_load_page(ctx, pagenum - 1);
- if (!page)
- die(fz_throw("cannot load page %d in file '%s'", pagenum, filename));
+ code = xps_load_page(&page, ctx, pagenum - 1);
+ if (code)
+ die(fz_rethrow(code, "cannot load page %d in file '%s'", pagenum, filename));
list = NULL;
@@ -333,8 +334,7 @@ int main(int argc, char **argv)
{
filename = argv[fz_optind++];
- ctx = xps_new_context();
- code = xps_open_file(ctx, filename);
+ code = xps_open_file(&ctx, filename);
if (code)
die(fz_rethrow(code, "cannot open document: %s", filename));