summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorPaul Gardiner <paulg.artifex@glidos.net>2012-08-08 14:03:34 +0100
committerPaul Gardiner <paulg.artifex@glidos.net>2012-08-08 14:03:34 +0100
commit274ab2d66943bb891976ef712a816e7d128eff22 (patch)
treebee912b4426f3dfe4acc176a57fd5b55db58d53c /apps
parent51661f29a5f229f30ae16e16bd0ef6396cd001af (diff)
parent511ea75a53db6e72334438bcda2ce774c7d72d1e (diff)
downloadmupdf-274ab2d66943bb891976ef712a816e7d128eff22.tar.xz
Merge branch 'master' into forms
Conflicts: Makefile apps/mudraw.c pdf/pdf_write.c win32/libmupdf-v8.vcproj
Diffstat (limited to 'apps')
-rw-r--r--apps/mudraw.c92
-rw-r--r--apps/mupdfclean.c32
-rw-r--r--apps/pdfapp.c18
3 files changed, 88 insertions, 54 deletions
diff --git a/apps/mudraw.c b/apps/mudraw.c
index a67ba8e8..a0aab51a 100644
--- a/apps/mudraw.c
+++ b/apps/mudraw.c
@@ -81,6 +81,7 @@ static int width = 0;
static int height = 0;
static int fit = 0;
static int errored = 0;
+static int ignore_errors = 0;
static fz_text_sheet *sheet = NULL;
static fz_colorspace *colorspace;
@@ -123,6 +124,7 @@ static void usage(void)
"\t-I\tinvert output\n"
"\t-l\tprint outline\n"
"\t-j -\tOutput mujstest file\n"
+ "\t-i\tignore errors and continue with the next file\n"
"\tpages\tcomma separated list of ranges\n");
exit(1);
}
@@ -311,15 +313,17 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum)
dev = fz_new_list_device(ctx, list);
fz_run_page(doc, page, dev, fz_identity, &cookie);
}
- fz_catch(ctx)
+ fz_always(ctx)
{
fz_free_device(dev);
+ dev = NULL;
+ }
+ fz_catch(ctx)
+ {
fz_free_display_list(ctx, list);
fz_free_page(doc, page);
fz_throw(ctx, "cannot draw page %d in file '%s'", pagenum, filename);
}
- fz_free_device(dev);
- dev = NULL;
}
if (showxml)
@@ -631,7 +635,7 @@ int main(int argc, char **argv)
fz_var(doc);
- while ((c = fz_getopt(argc, argv, "lo:p:r:R:ab:dgmtx5G:Iw:h:fj:")) != -1)
+ while ((c = fz_getopt(argc, argv, "lo:p:r:R:ab:dgmtx5G:Iw:h:fij:")) != -1)
{
switch (c)
{
@@ -654,6 +658,7 @@ int main(int argc, char **argv)
case 'f': fit = 1; break;
case 'I': invert++; break;
case 'j': mujstest_filename = fz_optarg; break;
+ case 'i': ignore_errors = 1; break;
default: usage(); break;
}
}
@@ -724,51 +729,62 @@ int main(int argc, char **argv)
{
while (fz_optind < argc)
{
- filename = argv[fz_optind++];
- files++;
-
fz_try(ctx)
{
- doc = fz_open_document(ctx, filename);
- }
- fz_catch(ctx)
- {
- fz_throw(ctx, "cannot open document: %s", filename);
- }
+ filename = argv[fz_optind++];
+ files++;
+
+ fz_try(ctx)
+ {
+ doc = fz_open_document(ctx, filename);
+ }
+ fz_catch(ctx)
+ {
+ fz_throw(ctx, "cannot open document: %s", filename);
+ }
+
+ if (fz_needs_password(doc))
+ {
+ if (!fz_authenticate_password(doc, password))
+ fz_throw(ctx, "cannot authenticate password: %s", filename);
+ if (mujstest_file)
+ fprintf(mujstest_file, "PASSWORD %s\n", password);
+ }
- if (fz_needs_password(doc))
- {
- if (!fz_authenticate_password(doc, password))
- fz_throw(ctx, "cannot authenticate password: %s", filename);
if (mujstest_file)
- fprintf(mujstest_file, "PASSWORD %s\n", password);
+ {
+ fprintf(mujstest_file, "OPEN %s\n", filename);
+ }
- }
+ if (showxml || showtext == TEXT_XML)
+ printf("<document name=\"%s\">\n", filename);
- if (mujstest_file)
- {
- fprintf(mujstest_file, "OPEN %s\n", filename);
- }
+ if (showoutline)
+ drawoutline(ctx, doc);
- if (showxml || showtext == TEXT_XML)
- printf("<document name=\"%s\">\n", filename);
+ if (showtext || showxml || showtime || showmd5 || output || mujstest_file)
+ {
+ if (fz_optind == argc || !isrange(argv[fz_optind]))
+ drawrange(ctx, doc, "1-");
+ if (fz_optind < argc && isrange(argv[fz_optind]))
+ drawrange(ctx, doc, argv[fz_optind++]);
+ }
- if (showoutline)
- drawoutline(ctx, doc);
+ if (showxml || showtext == TEXT_XML)
+ printf("</document>\n");
- if (showtext || showxml || showtime || showmd5 || output || mujstest_file)
- {
- if (fz_optind == argc || !isrange(argv[fz_optind]))
- drawrange(ctx, doc, "1-");
- if (fz_optind < argc && isrange(argv[fz_optind]))
- drawrange(ctx, doc, argv[fz_optind++]);
+ fz_close_document(doc);
+ doc = NULL;
}
+ fz_catch(ctx)
+ {
+ if (!ignore_errors)
+ fz_rethrow(ctx);
- if (showxml || showtext == TEXT_XML)
- printf("</document>\n");
-
- fz_close_document(doc);
- doc = NULL;
+ fz_close_document(doc);
+ doc = NULL;
+ fz_warn(ctx, "ignoring error in '%s'", filename);
+ }
}
}
fz_catch(ctx)
diff --git a/apps/mupdfclean.c b/apps/mupdfclean.c
index 6b185668..fdf9b412 100644
--- a/apps/mupdfclean.c
+++ b/apps/mupdfclean.c
@@ -161,6 +161,7 @@ int pdfclean_main(int argc, char **argv)
int c;
int subset;
fz_write_options opts;
+ int write_failed = 0;
opts.do_garbage = 0;
opts.do_expand = 0;
@@ -204,18 +205,29 @@ int pdfclean_main(int argc, char **argv)
exit(1);
}
- xref = pdf_open_document_no_run(ctx, infile);
- if (pdf_needs_password(xref))
- if (!pdf_authenticate_password(xref, password))
- fz_throw(ctx, "cannot authenticate password: %s", infile);
+ fz_try(ctx)
+ {
+ xref = pdf_open_document_no_run(ctx, infile);
+ if (pdf_needs_password(xref))
+ if (!pdf_authenticate_password(xref, password))
+ fz_throw(ctx, "cannot authenticate password: %s", infile);
- /* Only retain the specified subset of the pages */
- if (subset)
- retainpages(argc, argv);
+ /* Only retain the specified subset of the pages */
+ if (subset)
+ retainpages(argc, argv);
- pdf_write_document(xref, outfile, &opts);
+ pdf_write_document(xref, outfile, &opts);
+ }
+ fz_always(ctx)
+ {
+ pdf_close_document(xref);
+ }
+ fz_catch(ctx)
+ {
+ write_failed = 1;
+ }
- pdf_close_document(xref);
fz_free_context(ctx);
- return 0;
+
+ return write_failed ? 1 : 0;
}
diff --git a/apps/pdfapp.c b/apps/pdfapp.c
index a1dba6ce..57bc3e33 100644
--- a/apps/pdfapp.c
+++ b/apps/pdfapp.c
@@ -384,9 +384,12 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage, int repai
/* Extract text */
app->page_sheet = fz_new_text_sheet(app->ctx);
app->page_text = fz_new_text_page(app->ctx, app->page_bbox);
- tdev = fz_new_text_device(app->ctx, app->page_sheet, app->page_text);
- fz_run_display_list(app->page_list, tdev, fz_identity, fz_infinite_bbox, &cookie);
- fz_free_device(tdev);
+ if (app->page_list)
+ {
+ tdev = fz_new_text_device(app->ctx, app->page_sheet, app->page_text);
+ fz_run_display_list(app->page_list, tdev, fz_identity, fz_infinite_bbox, &cookie);
+ fz_free_device(tdev);
+ }
}
if (drawpage)
@@ -419,9 +422,12 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage, int repai
colorspace = app->colorspace;
app->image = fz_new_pixmap_with_bbox(app->ctx, colorspace, bbox);
fz_clear_pixmap_with_value(app->ctx, app->image, 255);
- idev = fz_new_draw_device(app->ctx, app->image);
- fz_run_display_list(app->page_list, idev, ctm, bbox, &cookie);
- fz_free_device(idev);
+ if (app->page_list)
+ {
+ idev = fz_new_draw_device(app->ctx, app->image);
+ fz_run_display_list(app->page_list, idev, ctm, bbox, &cookie);
+ fz_free_device(idev);
+ }
if (app->invert)
fz_invert_pixmap(app->ctx, app->image);
}