diff options
-rw-r--r-- | apps/mudraw.c | 59 | ||||
-rw-r--r-- | fitz/doc_document.c | 7 | ||||
-rw-r--r-- | fitz/fitz-internal.h | 1 | ||||
-rw-r--r-- | fitz/fitz.h | 9 | ||||
-rw-r--r-- | pdf/mupdf.h | 9 | ||||
-rw-r--r-- | pdf/pdf_annot.c | 16 | ||||
-rw-r--r-- | pdf/pdf_xref.c | 6 |
7 files changed, 104 insertions, 3 deletions
diff --git a/apps/mudraw.c b/apps/mudraw.c index 359b102f..ae22d23d 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -22,6 +22,7 @@ static int showtext = 0; static int showtime = 0; static int showmd5 = 0; static int showoutline = 0; +static int showannotrects = 0; static int savealpha = 0; static int uselist = 1; static int alphabits = 8; @@ -37,6 +38,11 @@ static fz_colorspace *colorspace; static char *filename; static int files = 0; +static char *mujstest_filename = NULL; +static FILE *mujstest_file = NULL; +static int mujstest_page = 0; +static int mujstest_count = 0; + static struct { int count, total; int min, max; @@ -68,6 +74,7 @@ static void usage(void) "\t-G gamma\tgamma correct output\n" "\t-I\tinvert output\n" "\t-l\tprint outline\n" + "\t-j -\tOutput mujstest file\n" "\tpages\tcomma separated list of ranges\n"); exit(1); } @@ -97,6 +104,18 @@ static int isrange(char *s) return 1; } +static void mujsannot(void *arg, fz_rect *rect) +{ + if (mujstest_page >= 0) + { + fprintf(mujstest_file, "GOTO %d\n", mujstest_page); + mujstest_page = -1; + } + fprintf(mujstest_file, "%% %0.2f %0.2f %0.2f %0.2f\n", rect->x0, rect->y0, rect->x1, rect->y1); + fprintf(mujstest_file, "TEXT %dTestText\n", ++mujstest_count); + fprintf(mujstest_file, "CLICK %0.2f %0.2f\n", (rect->x0+rect->x1)/2, (rect->y0+rect->y1)/2); +} + static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) { fz_page *page; @@ -122,6 +141,12 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) fz_throw(ctx, "cannot load page %d in file '%s'", pagenum, filename); } + if (mujstest_file) + { + mujstest_page = pagenum; + fz_bound_annots(doc, page, mujsannot, NULL); + } + if (uselist) { fz_try(ctx) @@ -378,6 +403,12 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) fz_flush_warnings(ctx); + if (mujstest_file && mujstest_page < 0) + { + fprintf(mujstest_file, "SCREENSHOT\n"); + } + + if (cookie.errors) errored = 1; } @@ -444,7 +475,7 @@ int main(int argc, char **argv) fz_var(doc); - while ((c = fz_getopt(argc, argv, "lo:p:r:R:ab:dgmtx5G:Iw:h:f")) != -1) + while ((c = fz_getopt(argc, argv, "lo:p:r:R:ab:dgmtx5G:Iw:h:fj:")) != -1) { switch (c) { @@ -466,6 +497,7 @@ int main(int argc, char **argv) case 'h': height = atof(fz_optarg); break; case 'f': fit = 1; break; case 'I': invert++; break; + case 'j': mujstest_filename = fz_optarg; break; default: usage(); break; } } @@ -473,12 +505,20 @@ int main(int argc, char **argv) if (fz_optind == argc) usage(); - if (!showtext && !showxml && !showtime && !showmd5 && !showoutline && !output) + if (!showtext && !showxml && !showtime && !showmd5 && !showoutline && !output && !mujstest_filename) { printf("nothing to do\n"); exit(0); } + if (mujstest_filename) + { + if (strcmp(mujstest_filename, "-") == 0) + mujstest_file = stdout; + else + mujstest_file = fopen(mujstest_filename, "wb"); + } + ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT); if (!ctx) { @@ -541,8 +581,18 @@ int main(int argc, char **argv) } 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 (mujstest_file) + { + fprintf(mujstest_file, "OPEN %s\n", filename); + } if (showxml || showtext == TEXT_XML) printf("<document name=\"%s\">\n", filename); @@ -550,7 +600,7 @@ int main(int argc, char **argv) if (showoutline) drawoutline(ctx, doc); - if (showtext || showxml || showtime || showmd5 || output) + if (showtext || showxml || showtime || showmd5 || output || mujstest_file) { if (fz_optind == argc || !isrange(argv[fz_optind])) drawrange(ctx, doc, "1-"); @@ -601,6 +651,9 @@ int main(int argc, char **argv) } } + if (mujstest_file && mujstest_file != stdout) + fclose(mujstest_file); + fz_free_context(ctx); return (errored != 0); } diff --git a/fitz/doc_document.c b/fitz/doc_document.c index b1ca8eac..0699f00f 100644 --- a/fitz/doc_document.c +++ b/fitz/doc_document.c @@ -109,6 +109,13 @@ fz_bound_page(fz_document *doc, fz_page *page) } void +fz_bound_annots(fz_document *doc, fz_page *page, void (*callback)(void *arg, fz_rect *), void *arg) +{ + if (doc && doc->bound_annots && page && callback) + doc->bound_annots(doc, page, callback, arg); +} + +void fz_run_page(fz_document *doc, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie) { if (doc && doc->run_page && page) diff --git a/fitz/fitz-internal.h b/fitz/fitz-internal.h index 61ccd2a0..0f413893 100644 --- a/fitz/fitz-internal.h +++ b/fitz/fitz-internal.h @@ -1112,6 +1112,7 @@ struct fz_document_s int (*meta)(fz_document *doc, int key, void *ptr, int size); fz_interactive *(*interact)(fz_document *doc); void (*write)(fz_document *doc, char *filename, fz_write_options *opts); + void (*bound_annots)(fz_document *doc, fz_page *page, void (*callback)(void *arg, fz_rect *), void *arg); }; #endif diff --git a/fitz/fitz.h b/fitz/fitz.h index 60cddf9a..669ab6e4 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -2161,6 +2161,15 @@ fz_link *fz_load_links(fz_document *doc, fz_page *page); fz_rect fz_bound_page(fz_document *doc, fz_page *page); /* + fz_bound_annots: Bound the annotations on a page. + + (Temporary function - do not rely on this remaining in future) + + Does not throw exceptions (unless the callback does). +*/ +void fz_bound_annots(fz_document *doc, fz_page *page, void(*callback)(void *arg, fz_rect *), void *arg); + +/* fz_run_page: Run a page through a device. page: Page obtained from fz_load_page. diff --git a/pdf/mupdf.h b/pdf/mupdf.h index b3807852..d7cf85f7 100644 --- a/pdf/mupdf.h +++ b/pdf/mupdf.h @@ -233,6 +233,15 @@ fz_rect pdf_bound_page(pdf_document *doc, pdf_page *page); void pdf_free_page(pdf_document *doc, pdf_page *page); /* + pdf_bound_annots: Bound the annotations on a page. + + (Temporary function - do not rely on this remaining in future) + + Does not throw exceptions (unless the callback does). +*/ +void pdf_bound_annots(pdf_document *doc, pdf_page *page, void(*callback)(void *arg, fz_rect *), void *arg); + +/* pdf_run_page: Interpret a loaded page and render it on a device. page: A page loaded by pdf_load_page. diff --git a/pdf/pdf_annot.c b/pdf/pdf_annot.c index a3dde9a3..ea4fa2c4 100644 --- a/pdf/pdf_annot.c +++ b/pdf/pdf_annot.c @@ -431,3 +431,19 @@ pdf_load_annots(pdf_document *xref, pdf_obj *annots, fz_matrix page_ctm) return head; } + +void +pdf_bound_annots(pdf_document *doc, pdf_page *page, void (*callback)(void *arg, fz_rect *), void *arg) +{ + pdf_annot *a; + + if (!doc || !page || !callback) + return; + + a = page->annots; + while (a) + { + callback(arg, &a->pagerect); + a = a->next; + } +} diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c index c5c6507d..8e74850c 100644 --- a/pdf/pdf_xref.c +++ b/pdf/pdf_xref.c @@ -1292,6 +1292,11 @@ static fz_rect pdf_bound_page_shim(fz_document *doc, fz_page *page) return pdf_bound_page((pdf_document*)doc, (pdf_page*)page); } +static void pdf_bound_annots_shim(fz_document *doc, fz_page *page, void (*callback)(void *arg, fz_rect *), void *arg) +{ + pdf_bound_annots((pdf_document*)doc, (pdf_page*)page, callback, arg); +} + static void pdf_free_page_shim(fz_document *doc, fz_page *page) { pdf_free_page((pdf_document*)doc, (pdf_page*)page); @@ -1316,6 +1321,7 @@ pdf_new_document(fz_stream *file) doc->super.load_page = pdf_load_page_shim; doc->super.load_links = pdf_load_links_shim; doc->super.bound_page = pdf_bound_page_shim; + doc->super.bound_annots = pdf_bound_annots_shim; doc->super.run_page = NULL; /* see pdf_xref_aux.c */ doc->super.free_page = pdf_free_page_shim; doc->super.meta = pdf_meta_shim; |