From d08f215e7d44fc521ae514316a429b755f864003 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 4 Sep 2011 04:01:58 +0200 Subject: Implement backwards search in viewer. --- apps/pdfapp.c | 34 ++++++++++++++++++++++++++++------ apps/pdfapp.h | 1 + 2 files changed, 29 insertions(+), 6 deletions(-) (limited to 'apps') diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 6292b039..6e0b465b 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -700,6 +700,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 @@ -736,10 +746,6 @@ void pdfapp_onkey(pdfapp_t *app, int c) switch (c) { - case '?': - winhelp(app); - break; - case 'q': winclose(app); break; @@ -925,8 +931,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; @@ -934,12 +950,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 732d637c..a3829b3e 100644 --- a/apps/pdfapp.h +++ b/apps/pdfapp.h @@ -81,6 +81,7 @@ struct pdfapp_s /* search state */ int isediting; + int searchdir; char search[512]; int hit; int hitlen; -- cgit v1.2.3 From 5e4ab352ecb523002221624ed71fb6bf4366c862 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Thu, 8 Sep 2011 00:23:02 +0200 Subject: Show page number in X11 viewer upon 'P' keypress. --- apps/x11_main.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 6 deletions(-) (limited to 'apps') diff --git a/apps/x11_main.c b/apps/x11_main.c index c2aef917..1b45c5ec 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 @@ -358,6 +361,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 +398,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) @@ -509,6 +517,13 @@ static void onkey(int c) winrepaint(&gapp); } + if (c == 'P') + { + showingpage = 1; + winrepaint(&gapp); + return; + } + pdfapp_onkey(&gapp, c); } @@ -554,6 +569,10 @@ int main(int argc, char **argv) fd_set fds; int width = -1; int height = -1; + struct timeval tmo_at; + struct timeval now; + struct timeval tmo; + struct timeval *timeout; while ((c = fz_getopt(argc, argv, "p:r:b:A")) != -1) { @@ -598,13 +617,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); @@ -693,7 +714,6 @@ int main(int argc, char **argv) break; } } - while (!closing && XPending(xdpy)); if (closing) continue; @@ -715,10 +735,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) { @@ -726,6 +774,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); -- cgit v1.2.3 From a848a4d942af4f6ccb8bec16d9bc947ab1802f84 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 19 Sep 2011 23:55:29 +0200 Subject: In X11 viewer, repaint entire page if no match found. --- apps/pdfapp.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'apps') diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 6e0b465b..11ea4220 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -603,13 +603,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); } @@ -657,13 +652,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); } -- cgit v1.2.3 From d0266d6f0863176ddc009d8ae33651e68e97fdde Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 19 Sep 2011 02:48:12 +0200 Subject: Plug some memory leaks in pdfapp. --- apps/pdfapp.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'apps') diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 11ea4220..e96b94e6 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -210,6 +210,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->page_list); + app->page_list = NULL; + + if (app->page_text) + fz_free_text_span(app->page_text); + app->page_text = NULL; + + if (app->page_links) + pdf_free_link(app->page_links); + app->page_links = NULL; + + if (app->doctitle) + fz_free(app->doctitle); + app->doctitle = NULL; + if (app->cache) fz_free_glyph_cache(app->cache); app->cache = NULL; -- cgit v1.2.3 From 0d82bc58cd51f92c3806f9cfdf0d601f9e1a42e7 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 2 Oct 2011 13:52:21 +0200 Subject: Ask for screen resolution in X11 viewer. Based on a patch by Zhihao Yuan . --- apps/x11_main.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'apps') diff --git a/apps/x11_main.c b/apps/x11_main.c index 1b45c5ec..b8f041cf 100644 --- a/apps/x11_main.c +++ b/apps/x11_main.c @@ -214,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) @@ -562,7 +568,7 @@ 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; @@ -586,11 +592,6 @@ int main(int argc, char **argv) } } - if (resolution < MINRES) - resolution = MINRES; - if (resolution > MAXRES) - resolution = MAXRES; - if (argc - fz_optind == 0) usage(); @@ -604,6 +605,13 @@ int main(int argc, char **argv) winopen(); + if (resolution == -1) + resolution = winresolution(); + if (resolution < MINRES) + resolution = MINRES; + if (resolution > MAXRES) + resolution = MAXRES; + pdfapp_init(&gapp); gapp.scrw = DisplayWidth(xdpy, xscr); gapp.scrh = DisplayHeight(xdpy, xscr); -- cgit v1.2.3 From 4ff408357b4584a84bc450a765fe11e7a52e8f00 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 2 Oct 2011 14:11:59 +0200 Subject: Default to opening URIs with xdg-open instead of open in X11 viewer. Based on a patch by Zhihao Yuan . --- apps/x11_main.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'apps') diff --git a/apps/x11_main.c b/apps/x11_main.c index b8f041cf..6d8e789e 100644 --- a/apps/x11_main.c +++ b/apps/x11_main.c @@ -510,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); } -- cgit v1.2.3 From 8be6412105a3c0b9a255b6a89ae164c91d3519de Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 3 Oct 2011 00:34:27 +0200 Subject: Make entering search terms not interfere with page number drawing. --- apps/x11_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps') diff --git a/apps/x11_main.c b/apps/x11_main.c index 6d8e789e..a2d36ac5 100644 --- a/apps/x11_main.c +++ b/apps/x11_main.c @@ -529,7 +529,7 @@ static void onkey(int c) winrepaint(&gapp); } - if (c == 'P') + if (!gapp.isediting && c == 'P') { showingpage = 1; winrepaint(&gapp); -- cgit v1.2.3 From 38abc1f9a91207569b64fc274ccb904094ac4f9a Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 3 Oct 2011 22:42:00 +0200 Subject: Add pdfdraw option to print the table of contents / outline. --- apps/pdfdraw.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 6 deletions(-) (limited to 'apps') diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c index a5f6aa1e..90db4c1b 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); } @@ -295,6 +297,56 @@ static void drawrange(pdf_xref *xref, char *range) } } +static int get_page_number(pdf_xref *xref, pdf_link *link) +{ + if (link->kind == PDF_LINK_GOTO) + return pdf_find_page_number(xref, fz_array_get(link->dest, 0)); + return 0; +} + +static void print_outline_xml(pdf_xref *xref, pdf_outline *outline, int level) +{ + int page; + printf("\n"); + while (outline) + { + page = get_page_number(xref, outline->link); + printf("\n", + outline->title ? outline->title : "", page); + if (outline->child) + print_outline_xml(xref, outline->child, level + 1); + outline = outline->next; + } + printf("\n"); +} + +static void print_outline_plain(pdf_xref *xref, pdf_outline *outline, int level) +{ + int i, page; + while (outline) + { + page = get_page_number(xref, outline->link); + for (i = 0; i < level; i++) + putchar('\t'); + printf("%s %d\n", outline->title ? outline->title : "", page); + if (outline->child) + print_outline_plain(xref, outline->child, level + 1); + outline = outline->next; + } +} + +static void drawoutline(pdf_xref *xref) +{ + pdf_outline *outline = pdf_load_outline(xref); + if (showoutline > 2) + pdf_debug_outline(outline, 0); + else if (showoutline > 1) + print_outline_xml(xref, outline, 0); + else + print_outline_plain(xref, outline, 0); + pdf_free_outline(outline); +} + int main(int argc, char **argv) { char *password = ""; @@ -304,7 +356,7 @@ int main(int argc, char **argv) fz_error error; int c; - 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) { @@ -315,6 +367,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; @@ -332,7 +385,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); @@ -378,10 +431,16 @@ int main(int argc, char **argv) if (showxml) printf("\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("\n"); -- cgit v1.2.3 From c5918f8ec97a9e914666da4a4b4da5bb81f9a77c Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Wed, 12 Oct 2011 18:31:33 +0200 Subject: Make sure PDF title is always an allocated string. Signed-off-by: Sebastian Rasmussen --- apps/pdfapp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apps') diff --git a/apps/pdfapp.c b/apps/pdfapp.c index e96b94e6..3050145f 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -139,7 +139,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(filename); if (strrchr(app->doctitle, '\\')) app->doctitle = strrchr(app->doctitle, '\\') + 1; if (strrchr(app->doctitle, '/')) @@ -174,7 +174,7 @@ static void pdfapp_open_xps(pdfapp_t *app, char *filename, int fd) pdfapp_error(app, fz_rethrow(error, "cannot open document '%s'", filename)); fz_close(file); - app->doctitle = filename; + app->doctitle = fz_strdup(filename); app->pagecount = xps_count_pages(app->xps); } -- cgit v1.2.3 From 97d00440c043b712a2d16134e3b52850c7b36d47 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 10 Nov 2011 01:52:40 +0100 Subject: Add XPS outline parsing and move outline data struct to fz_outline. --- apps/pdfapp.c | 2 +- apps/pdfapp.h | 2 +- apps/pdfdraw.c | 50 +++++--------------------------------------------- apps/xpsdraw.c | 31 +++++++++++++++++++++++++------ 4 files changed, 32 insertions(+), 53 deletions(-) (limited to 'apps') diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 3050145f..ab29fcb9 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -235,7 +235,7 @@ void pdfapp_close(pdfapp_t *app) app->image = NULL; if (app->outline) - pdf_free_outline(app->outline); + fz_free_outline(app->outline); app->outline = NULL; if (app->xref) diff --git a/apps/pdfapp.h b/apps/pdfapp.h index a3829b3e..270c450a 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_context *xps; int pagecount; diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c index 90db4c1b..d79cd75c 100644 --- a/apps/pdfdraw.c +++ b/apps/pdfdraw.c @@ -297,54 +297,14 @@ static void drawrange(pdf_xref *xref, char *range) } } -static int get_page_number(pdf_xref *xref, pdf_link *link) -{ - if (link->kind == PDF_LINK_GOTO) - return pdf_find_page_number(xref, fz_array_get(link->dest, 0)); - return 0; -} - -static void print_outline_xml(pdf_xref *xref, pdf_outline *outline, int level) -{ - int page; - printf("\n"); - while (outline) - { - page = get_page_number(xref, outline->link); - printf("\n", - outline->title ? outline->title : "", page); - if (outline->child) - print_outline_xml(xref, outline->child, level + 1); - outline = outline->next; - } - printf("\n"); -} - -static void print_outline_plain(pdf_xref *xref, pdf_outline *outline, int level) -{ - int i, page; - while (outline) - { - page = get_page_number(xref, outline->link); - for (i = 0; i < level; i++) - putchar('\t'); - printf("%s %d\n", outline->title ? outline->title : "", page); - if (outline->child) - print_outline_plain(xref, outline->child, level + 1); - outline = outline->next; - } -} - static void drawoutline(pdf_xref *xref) { - pdf_outline *outline = pdf_load_outline(xref); - if (showoutline > 2) - pdf_debug_outline(outline, 0); - else if (showoutline > 1) - print_outline_xml(xref, outline, 0); + fz_outline *outline = pdf_load_outline(xref); + if (showoutline > 1) + fz_debug_outline_xml(outline, 0); else - print_outline_plain(xref, outline, 0); - pdf_free_outline(outline); + fz_debug_outline(outline, 0); + fz_free_outline(outline); } int main(int argc, char **argv) diff --git a/apps/xpsdraw.c b/apps/xpsdraw.c index 29738e6b..1d2992bc 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; @@ -47,6 +48,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); } @@ -272,6 +274,16 @@ static void drawrange(xps_context *ctx, char *range) } } +static void drawoutline(xps_context *ctx) +{ + fz_outline *outline = xps_load_outline(ctx); + 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; @@ -280,7 +292,7 @@ int main(int argc, char **argv) int code; 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) { @@ -288,6 +300,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; @@ -301,7 +314,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); @@ -341,10 +354,16 @@ int main(int argc, char **argv) if (showxml) printf("\n", filename); - if (fz_optind == argc || !isrange(argv[fz_optind])) - drawrange(ctx, "1-"); - if (fz_optind < argc && isrange(argv[fz_optind])) - drawrange(ctx, argv[fz_optind++]); + if (showoutline) + drawoutline(ctx); + + if (showtext || showxml || showtime || showmd5 || output) + { + if (fz_optind == argc || !isrange(argv[fz_optind])) + drawrange(ctx, "1-"); + if (fz_optind < argc && isrange(argv[fz_optind])) + drawrange(ctx, argv[fz_optind++]); + } if (showxml) printf("\n"); -- cgit v1.2.3