diff options
author | Robin Watts <robin.watts@artifex.com> | 2011-11-14 18:22:13 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2011-11-15 15:20:54 +0000 |
commit | 9c0a49060475b2dea1e4c2668bebd1d566113a7b (patch) | |
tree | 49e45a691cf105f4266d5c6b7242a4a3256c1200 /apps | |
parent | 60c0544742931da63db623ad7a79ba3758704cc1 (diff) | |
parent | fd6def85f22b598d4c278e76138ab7dccbb84c36 (diff) | |
download | mupdf-9c0a49060475b2dea1e4c2668bebd1d566113a7b.tar.xz |
Merge branch 'master' into context
Mostly redoing the xps_context to xps_document change and adding
contexts to newly written code.
Conflicts:
apps/pdfapp.c
apps/pdfapp.h
apps/x11_main.c
apps/xpsdraw.c
draw/draw_device.c
draw/draw_scale.c
fitz/base_object.c
fitz/fitz.h
pdf/mupdf.h
pdf/pdf_interpret.c
pdf/pdf_outline.c
pdf/pdf_page.c
xps/muxps.h
xps/xps_doc.c
xps/xps_xml.c
Diffstat (limited to 'apps')
-rw-r--r-- | apps/pdfapp.c | 69 | ||||
-rw-r--r-- | apps/pdfapp.h | 3 | ||||
-rw-r--r-- | apps/pdfdraw.c | 31 | ||||
-rw-r--r-- | apps/x11_main.c | 101 | ||||
-rw-r--r-- | apps/xpsdraw.c | 31 |
5 files changed, 190 insertions, 45 deletions
diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 5e235ddf..fed8a025 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -145,7 +145,7 @@ static void pdfapp_open_pdf(pdfapp_t *app, char *filename, int fd) app->outline = pdf_load_outline(app->xref); - app->doctitle = filename; + app->doctitle = fz_strdup(ctx, filename); if (strrchr(app->doctitle, '\\')) app->doctitle = strrchr(app->doctitle, '\\') + 1; if (strrchr(app->doctitle, '/')) @@ -189,7 +189,7 @@ static void pdfapp_open_xps(pdfapp_t *app, char *filename, int fd) } fz_close(file); - app->doctitle = filename; + app->doctitle = fz_strdup(app->ctx, filename); app->pagecount = xps_count_pages(app->xps); } @@ -225,6 +225,22 @@ void pdfapp_open(pdfapp_t *app, char *filename, int fd, int reload) void pdfapp_close(pdfapp_t *app) { + if (app->page_list) + fz_free_display_list(app->ctx, app->page_list); + app->page_list = NULL; + + if (app->page_text) + fz_free_text_span(app->ctx, app->page_text); + app->page_text = NULL; + + if (app->page_links) + pdf_free_link(app->ctx, app->page_links); + app->page_links = NULL; + + if (app->doctitle) + fz_free(app->ctx, app->doctitle); + app->doctitle = NULL; + if (app->cache) fz_free_glyph_cache(app->ctx, app->cache); app->cache = NULL; @@ -234,7 +250,7 @@ void pdfapp_close(pdfapp_t *app) app->image = NULL; if (app->outline) - pdf_free_outline(app->ctx, app->outline); + fz_free_outline(app->outline); app->outline = NULL; if (app->xref) @@ -629,13 +645,8 @@ static void pdfapp_searchforward(pdfapp_t *app, enum panning *panto) } while (app->pageno != startpage); if (app->pageno == startpage) - { pdfapp_warn(app, "String '%s' not found.", app->search); - winrepaintsearch(app); - } - else - winrepaint(app); - + winrepaint(app); wincursor(app, HAND); } @@ -683,13 +694,9 @@ static void pdfapp_searchbackward(pdfapp_t *app, enum panning *panto) } while (app->pageno != startpage); if (app->pageno == startpage) - { pdfapp_warn(app, "String '%s' not found.", app->search); - winrepaintsearch(app); - } - else - winrepaint(app); + winrepaint(app); wincursor(app, HAND); } @@ -726,6 +733,16 @@ void pdfapp_onkey(pdfapp_t *app, int c) if (n > 0) { winrepaintsearch(app); + + if (app->searchdir < 0) + { + if (app->pageno == 1) + app->pageno = app->pagecount; + else + app->pageno--; + pdfapp_showpage(app, 1, 1, 0); + } + pdfapp_onkey(app, 'n'); } else @@ -762,10 +779,6 @@ void pdfapp_onkey(pdfapp_t *app, int c) switch (c) { - case '?': - winhelp(app); - break; - case 'q': winclose(app); break; @@ -951,8 +964,18 @@ void pdfapp_onkey(pdfapp_t *app, int c) * Searching */ + case '?': + app->isediting = 1; + app->searchdir = -1; + app->search[0] = 0; + app->hit = -1; + app->hitlen = 0; + winrepaintsearch(app); + break; + case '/': app->isediting = 1; + app->searchdir = 1; app->search[0] = 0; app->hit = -1; app->hitlen = 0; @@ -960,12 +983,18 @@ void pdfapp_onkey(pdfapp_t *app, int c) break; case 'n': - pdfapp_searchforward(app, &panto); + if (app->searchdir > 0) + pdfapp_searchforward(app, &panto); + else + pdfapp_searchbackward(app, &panto); loadpage = 0; break; case 'N': - pdfapp_searchbackward(app, &panto); + if (app->searchdir > 0) + pdfapp_searchbackward(app, &panto); + else + pdfapp_searchforward(app, &panto); loadpage = 0; break; diff --git a/apps/pdfapp.h b/apps/pdfapp.h index 6bafbbf8..e617333d 100644 --- a/apps/pdfapp.h +++ b/apps/pdfapp.h @@ -31,7 +31,7 @@ struct pdfapp_s /* current document params */ char *doctitle; pdf_xref *xref; - pdf_outline *outline; + fz_outline *outline; xps_document *xps; int pagecount; @@ -81,6 +81,7 @@ struct pdfapp_s /* search state */ int isediting; + int searchdir; char search[512]; int hit; int hitlen; diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c index 790c7eaa..fd7cc57f 100644 --- a/apps/pdfdraw.c +++ b/apps/pdfdraw.c @@ -19,6 +19,7 @@ int showxml = 0; int showtext = 0; int showtime = 0; int showmd5 = 0; +int showoutline = 0; int savealpha = 0; int uselist = 1; int alphabits = 8; @@ -61,6 +62,7 @@ static void usage(void) "\t-R -\trotate clockwise by given number of degrees\n" "\t-G gamma\tgamma correct output\n" "\t-I\tinvert output\n" + "\t-l\tprint outline\n" "\tpages\tcomma separated list of ranges\n"); exit(1); } @@ -305,6 +307,16 @@ static void drawrange(pdf_xref *xref, char *range) } } +static void drawoutline(pdf_xref *xref) +{ + fz_outline *outline = pdf_load_outline(xref); + if (showoutline > 1) + fz_debug_outline_xml(outline, 0); + else + fz_debug_outline(outline, 0); + fz_free_outline(outline); +} + int main(int argc, char **argv) { char *password = ""; @@ -315,7 +327,7 @@ int main(int argc, char **argv) int c; fz_context *ctx; - while ((c = fz_getopt(argc, argv, "o:p:r:R:Aab:dgmtx5G:I")) != -1) + while ((c = fz_getopt(argc, argv, "lo:p:r:R:Aab:dgmtx5G:I")) != -1) { switch (c) { @@ -326,6 +338,7 @@ int main(int argc, char **argv) case 'A': accelerate = 0; break; case 'a': savealpha = 1; break; case 'b': alphabits = atoi(fz_optarg); break; + case 'l': showoutline++; break; case 'm': showtime++; break; case 't': showtext++; break; case 'x': showxml++; break; @@ -343,7 +356,7 @@ int main(int argc, char **argv) if (fz_optind == argc) usage(); - if (!showtext && !showxml && !showtime && !showmd5 && !output) + if (!showtext && !showxml && !showtime && !showmd5 && !showoutline && !output) { printf("nothing to do\n"); exit(0); @@ -406,10 +419,16 @@ int main(int argc, char **argv) if (showxml) printf("<document name=\"%s\">\n", filename); - if (fz_optind == argc || !isrange(argv[fz_optind])) - drawrange(xref, "1-"); - if (fz_optind < argc && isrange(argv[fz_optind])) - drawrange(xref, argv[fz_optind++]); + if (showoutline) + drawoutline(xref); + + if (showtext || showxml || showtime || showmd5 || output) + { + if (fz_optind == argc || !isrange(argv[fz_optind])) + drawrange(xref, "1-"); + if (fz_optind < argc && isrange(argv[fz_optind])) + drawrange(xref, argv[fz_optind++]); + } if (showxml) printf("</document>\n"); diff --git a/apps/x11_main.c b/apps/x11_main.c index d5b7dc55..5b19a176 100644 --- a/apps/x11_main.c +++ b/apps/x11_main.c @@ -61,6 +61,8 @@ extern void ximage_blit(Drawable d, GC gc, int dstx, int dsty, unsigned char *srcdata, int srcx, int srcy, int srcw, int srch, int srcstride); +void windrawstringxor(pdfapp_t *app, int x, int y, char *s); + static Display *xdpy; static Atom XA_TARGETS; static Atom XA_TIMESTAMP; @@ -90,6 +92,7 @@ static char *filename; static pdfapp_t gapp; static int closing = 0; static int reloading = 0; +static int showingpage = 0; /* * Dialog boxes @@ -211,6 +214,12 @@ void winclose(pdfapp_t *app) closing = 1; } +static int winresolution() +{ + return DisplayWidth(xdpy, xscr) * 25.4 / + DisplayWidthMM(xdpy, xscr) + 0.5; +} + void wincursor(pdfapp_t *app, int curs) { if (curs == ARROW) @@ -358,6 +367,13 @@ static void winblit(pdfapp_t *app) } winblitsearch(app); + + if (showingpage) + { + char buf[42]; + snprintf(buf, sizeof buf, "Page %d/%d", gapp.pageno, gapp.pagecount); + windrawstringxor(&gapp, 10, 20, buf); + } } void winrepaint(pdfapp_t *app) @@ -388,8 +404,6 @@ void windrawstringxor(pdfapp_t *app, int x, int y, char *s) XGetGCValues(xdpy, xgc, GCFunction, &xgcv); xgcv.function = prevfunction; XChangeGC(xdpy, xgc, GCFunction, &xgcv); - - printf("drawstring '%s'\n", s); } void windrawstring(pdfapp_t *app, int x, int y, char *s) @@ -496,7 +510,13 @@ void winopenuri(pdfapp_t *app, char *buf) { char *browser = getenv("BROWSER"); if (!browser) + { +#ifdef __APPLE__ browser = "open"; +#else + browser = "xdg-open"; +#endif + } if (fork() == 0) execlp(browser, browser, buf, (char*)0); } @@ -509,6 +529,13 @@ static void onkey(int c) winrepaint(&gapp); } + if (!gapp.isediting && c == 'P') + { + showingpage = 1; + winrepaint(&gapp); + return; + } + pdfapp_onkey(&gapp, c); } @@ -547,14 +574,21 @@ int main(int argc, char **argv) KeySym keysym; int oldx = 0; int oldy = 0; - int resolution = 72; + int resolution = -1; int pageno = 1; int accelerate = 1; int fd; fd_set fds; int width = -1; int height = -1; +<<<<<<< HEAD fz_context *ctx; +======= + struct timeval tmo_at; + struct timeval now; + struct timeval tmo; + struct timeval *timeout; +>>>>>>> master while ((c = fz_getopt(argc, argv, "p:r:b:A")) != -1) { @@ -568,11 +602,6 @@ int main(int argc, char **argv) } } - if (resolution < MINRES) - resolution = MINRES; - if (resolution > MAXRES) - resolution = MAXRES; - if (argc - fz_optind == 0) usage(); @@ -593,7 +622,18 @@ int main(int argc, char **argv) winopen(); +<<<<<<< HEAD pdfapp_init(ctx, &gapp); +======= + if (resolution == -1) + resolution = winresolution(); + if (resolution < MINRES) + resolution = MINRES; + if (resolution > MAXRES) + resolution = MAXRES; + + pdfapp_init(&gapp); +>>>>>>> master gapp.scrw = DisplayWidth(xdpy, xscr); gapp.scrh = DisplayHeight(xdpy, xscr); gapp.resolution = resolution; @@ -606,13 +646,15 @@ int main(int argc, char **argv) pdfapp_open(&gapp, filename, fd, 0); FD_ZERO(&fds); - FD_SET(x11fd, &fds); signal(SIGHUP, signal_handler); + tmo_at.tv_sec = 0; + tmo_at.tv_usec = 0; + while (!closing) { - do + while (!closing && XPending(xdpy)) { XNextEvent(xdpy, &xevt); @@ -701,7 +743,6 @@ int main(int argc, char **argv) break; } } - while (!closing && XPending(xdpy)); if (closing) continue; @@ -723,10 +764,38 @@ int main(int argc, char **argv) dirtysearch = 0; } + if (showingpage && !tmo_at.tv_sec && !tmo_at.tv_usec) + { + tmo.tv_sec = 2; + tmo.tv_usec = 0; + + gettimeofday(&now, NULL); + timeradd(&now, &tmo, &tmo_at); + } + if (XPending(xdpy)) continue; - if (select(x11fd + 1, &fds, NULL, NULL, NULL) < 0) + timeout = NULL; + + if (tmo_at.tv_sec || tmo_at.tv_usec) + { + gettimeofday(&now, NULL); + timersub(&tmo_at, &now, &tmo); + if (tmo.tv_sec <= 0) + { + tmo_at.tv_sec = 0; + tmo_at.tv_usec = 0; + timeout = NULL; + showingpage = 0; + winrepaint(&gapp); + } + else + timeout = &tmo; + } + + FD_SET(x11fd, &fds); + if (select(x11fd + 1, &fds, NULL, NULL, timeout) < 0) { if (reloading) { @@ -734,6 +803,14 @@ int main(int argc, char **argv) reloading = 0; } } + if (!FD_ISSET(x11fd, &fds)) + { + tmo_at.tv_sec = 0; + tmo_at.tv_usec = 0; + timeout = NULL; + showingpage = 0; + winrepaint(&gapp); + } } pdfapp_close(&gapp); diff --git a/apps/xpsdraw.c b/apps/xpsdraw.c index c91e8702..4ac40b72 100644 --- a/apps/xpsdraw.c +++ b/apps/xpsdraw.c @@ -14,6 +14,7 @@ int showxml = 0; int showtext = 0; int showtime = 0; int showmd5 = 0; +int showoutline = 0; int savealpha = 0; int uselist = 1; @@ -48,6 +49,7 @@ static void usage(void) "\t-x\tshow display list\n" "\t-d\tdisable use of display list\n" "\t-5\tshow md5 checksums\n" + "\t-l\tprint outline\n" "\tpages\tcomma separated list of ranges\n"); exit(1); } @@ -277,6 +279,16 @@ static void drawrange(xps_document *doc, char *range) } } +static void drawoutline(xps_document *doc) +{ + fz_outline *outline = xps_load_outline(doc); + if (showoutline > 1) + fz_debug_outline_xml(outline, 0); + else + fz_debug_outline(outline, 0); + fz_free_outline(outline); +} + int main(int argc, char **argv) { int grayscale = 0; @@ -284,7 +296,7 @@ int main(int argc, char **argv) xps_document *doc; int c; - while ((c = fz_getopt(argc, argv, "o:p:r:Aadgmtx5")) != -1) + while ((c = fz_getopt(argc, argv, "o:p:r:Aadglmtx5")) != -1) { switch (c) { @@ -292,6 +304,7 @@ int main(int argc, char **argv) case 'r': resolution = atof(fz_optarg); break; case 'A': accelerate = 0; break; case 'a': savealpha = 1; break; + case 'l': showoutline++; break; case 'm': showtime++; break; case 't': showtext++; break; case 'x': showxml++; break; @@ -305,7 +318,7 @@ int main(int argc, char **argv) if (fz_optind == argc) usage(); - if (!showtext && !showxml && !showtime && !showmd5 && !output) + if (!showtext && !showxml && !showtime && !showmd5 && !showoutline && !output) { printf("nothing to do\n"); exit(0); @@ -357,10 +370,16 @@ int main(int argc, char **argv) if (showxml) printf("<document name=\"%s\">\n", filename); - if (fz_optind == argc || !isrange(argv[fz_optind])) - drawrange(doc, "1-"); - if (fz_optind < argc && isrange(argv[fz_optind])) - drawrange(doc, argv[fz_optind++]); + if (showoutline) + drawoutline(doc); + + if (showtext || showxml || showtime || showmd5 || output) + { + if (fz_optind == argc || !isrange(argv[fz_optind])) + drawrange(doc, "1-"); + if (fz_optind < argc && isrange(argv[fz_optind])) + drawrange(doc, argv[fz_optind++]); + } if (showxml) printf("</document>\n"); |