diff options
Diffstat (limited to 'src/cmd/page')
-rw-r--r-- | src/cmd/page/cache.c | 13 | ||||
-rw-r--r-- | src/cmd/page/gfx.c | 8 | ||||
-rw-r--r-- | src/cmd/page/gs.c | 6 | ||||
-rw-r--r-- | src/cmd/page/nrotate.c | 11 | ||||
-rw-r--r-- | src/cmd/page/page.c | 12 | ||||
-rw-r--r-- | src/cmd/page/pdf.c | 8 | ||||
-rw-r--r-- | src/cmd/page/pdfprolog.c | 3 | ||||
-rw-r--r-- | src/cmd/page/pdfprolog.ps | 3 | ||||
-rw-r--r-- | src/cmd/page/ps.c | 7 | ||||
-rw-r--r-- | src/cmd/page/rotate.c | 14 | ||||
-rw-r--r-- | src/cmd/page/util.c | 6 | ||||
-rw-r--r-- | src/cmd/page/view.c | 80 |
12 files changed, 87 insertions, 84 deletions
diff --git a/src/cmd/page/cache.c b/src/cmd/page/cache.c index 0063a339..a1083fc7 100644 --- a/src/cmd/page/cache.c +++ b/src/cmd/page/cache.c @@ -29,7 +29,7 @@ questionmark(void) static Image *im; if(im) - return im; + return im; im = xallocimage(display, Rect(0,0,50,50), GREY1, 1, DBlack); if(im == nil) return nil; @@ -165,10 +165,15 @@ static void raproc(void *a) { Cached *c; - + c = a; lockdisplay(display); - _cachedpage(c->doc, c->angle, c->page, "-ra"); + /* + * If there is only one page in a fwdonly file, we may reach EOF + * while doing readahead and page will exit without showing anything. + */ + if(!c->doc->fwdonly) + _cachedpage(c->doc, c->angle, c->page, "-ra"); rabusy = 0; unlockdisplay(display); free(c); @@ -182,7 +187,7 @@ cachedpage(Document *doc, int angle, int page) Cached *c; Image *im; int ra; - + if(doc->npage < 1) return display->white; diff --git a/src/cmd/page/gfx.c b/src/cmd/page/gfx.c index 22e08665..793d75a4 100644 --- a/src/cmd/page/gfx.c +++ b/src/cmd/page/gfx.c @@ -77,7 +77,7 @@ initgfx(Biobuf *b, int argc, char **argv, uchar *buf, int nbuf) doc = emalloc(sizeof(*doc)); gfx = emalloc(sizeof(*gfx)); gfx->g = nil; - + doc->npage = 0; doc->drawpage = gfxdrawpage; doc->pagename = gfxpagename; @@ -141,7 +141,7 @@ genaddpage(Document *doc, char *name, uchar *buf, int nbuf) memset(g, 0, sizeof *g); if(memcmp(buf, "GIF", 3) == 0) g->type = Igif; - else if(memcmp(buf, "\111\111\052\000", 4) == 0) + else if(memcmp(buf, "\111\111\052\000", 4) == 0) g->type = Itiff; else if(memcmp(buf, "\115\115\000\052", 4) == 0) g->type = Itiff; @@ -186,7 +186,7 @@ genaddpage(Document *doc, char *name, uchar *buf, int nbuf) return doc->npage++; } -static int +static int addpage(Document *doc, char *name) { return genaddpage(doc, name, nil, 0); @@ -257,7 +257,7 @@ convert(Graphic *g) if(fd < 0) { fprint(2, "cannot spawn converter: %r\n"); wexits("convert"); - } + } } im = readimage(display, fd, 0); diff --git a/src/cmd/page/gs.c b/src/cmd/page/gs.c index 5c493b35..1d60212a 100644 --- a/src/cmd/page/gs.c +++ b/src/cmd/page/gs.c @@ -1,8 +1,8 @@ /* * gs interface for page. * ps.c and pdf.c both use these routines. - * a caveat: if you run more than one gs, only the last - * one gets killed by killgs + * a caveat: if you run more than one gs, only the last + * one gets killed by killgs */ #include <u.h> #include <libc.h> @@ -88,7 +88,7 @@ spawnmonitor(void *cp) threadexits(0); } -int +int spawngs(GSInfo *g, char *safer) { Channel *cp; diff --git a/src/cmd/page/nrotate.c b/src/cmd/page/nrotate.c index 96563c3d..00d065ad 100644 --- a/src/cmd/page/nrotate.c +++ b/src/cmd/page/nrotate.c @@ -6,7 +6,7 @@ * The basic concept is that you can invert an array by * inverting the top half, inverting the bottom half, and * then swapping them. - * + * * This is usually overkill, but it speeds up slow remote * connections quite a bit. */ @@ -132,7 +132,7 @@ shuffle(Image *img, Image *tmp, int axis, int imgdim, Image *mask, int maskdim) /* * Halve the grating period in the mask. - * The grating currently looks like + * The grating currently looks like * ####____####____####____####____ * where #### is opacity. * @@ -140,7 +140,7 @@ shuffle(Image *img, Image *tmp, int axis, int imgdim, Image *mask, int maskdim) * ##__##__##__##__##__##__##__##__ * which is achieved by shifting the mask * and drawing on itself through itself. - * Draw doesn't actually allow this, so + * Draw doesn't actually allow this, so * we have to copy it first. * * ####____####____####____####____ (dst) @@ -229,7 +229,7 @@ swapadjacent(Image *img, Image *tmp, int axis, int imgdim, Image *mask, int mask /* * r0 is the lower rectangle, while r1 is the upper one. */ - draw(tmp, tmp->r, img, nil, + draw(tmp, tmp->r, img, nil, } void @@ -271,8 +271,7 @@ writefile(char *name, Image *im, int gran) snprint(buf, sizeof buf, "%d%s%d", c++, name, gran); fd = create(buf, OWRITE, 0666); if(fd < 0) - return; + return; writeimage(fd, im, 0); close(fd); } - diff --git a/src/cmd/page/page.c b/src/cmd/page/page.c index 041df26b..01ad17ff 100644 --- a/src/cmd/page/page.c +++ b/src/cmd/page/page.c @@ -41,7 +41,7 @@ watcherproc(void *v) for(;;) sleep(1000); } - + int bell(void *u, char *x) { @@ -81,7 +81,7 @@ afmt(Fmt *fmt) void usage(void) { - fprint(2, "usage: page [-biRrwf] [-p ppi] file...\n"); + fprint(2, "usage: page [-biRrwf] [-p ppi] file...\n"); wexits("usage"); } @@ -145,7 +145,7 @@ threadmain(int argc, char **argv) break; case 'f': fitwin = 1; - break; + break; default: usage(); }ARGEND; @@ -184,13 +184,13 @@ threadmain(int argc, char **argv) fprint(2, "page: short read reading %s\n", argv[0]); wexits("read"); } - + atexit(cleanup); }else if(argc != 0){ if(!(b = Bopen(argv[0], OREAD))) { fprint(2, "page: cannot open \"%s\"\n", argv[0]); wexits("open"); - } + } if(Bread(b, buf, Ninput) != Ninput) { fprint(2, "page: short read reading %s\n", argv[0]); @@ -242,7 +242,7 @@ threadmain(int argc, char **argv) wexits("initdraw"); } display->locking = 1; - + truecolor = screen->depth > 8; viewer(doc); wexits(0); diff --git a/src/cmd/page/pdf.c b/src/cmd/page/pdf.c index 2de67bc7..89df6c5e 100644 --- a/src/cmd/page/pdf.c +++ b/src/cmd/page/pdf.c @@ -1,6 +1,6 @@ /* * pdf.c - * + * * pdf file support for page */ @@ -15,7 +15,7 @@ static Image* pdfdrawpage(Document *d, int page); static char* pdfpagename(Document*, int); -char *pdfprolog = +char *pdfprolog = #include "pdfprolog.c" ; @@ -25,7 +25,7 @@ pdfbbox(GSInfo *gs) char *p; char *f[4]; Rectangle r; - + r = Rect(0,0,0,0); waitgs(gs); gscmd(gs, "/CropBox knownoget {} {[0 0 0 0]} ifelse PAGE==\n"); @@ -152,7 +152,7 @@ static char* pdfpagename(Document *d, int page) { static char str[15]; - + USED(d); sprint(str, "p %d", page+1); return str; diff --git a/src/cmd/page/pdfprolog.c b/src/cmd/page/pdfprolog.c index de51c062..3b6cbcd7 100644 --- a/src/cmd/page/pdfprolog.c +++ b/src/cmd/page/pdfprolog.c @@ -16,5 +16,4 @@ " } if\n" "} bind def\n" "\n" -"GS_PDF_ProcSet begin\n" -"pdfdict begin\n" +"runpdfbegin\n" diff --git a/src/cmd/page/pdfprolog.ps b/src/cmd/page/pdfprolog.ps index 681e0587..a57e20b1 100644 --- a/src/cmd/page/pdfprolog.ps +++ b/src/cmd/page/pdfprolog.ps @@ -16,5 +16,4 @@ } if } bind def -GS_PDF_ProcSet begin -pdfdict begin +runpdfbegin diff --git a/src/cmd/page/ps.c b/src/cmd/page/ps.c index 7935f694..eb09cc8f 100644 --- a/src/cmd/page/ps.c +++ b/src/cmd/page/ps.c @@ -1,6 +1,6 @@ /* * ps.c - * + * * provide postscript file reading support for page */ @@ -245,10 +245,10 @@ Keepreading: if(!prefix(p, "%%Page:")) continue; - /* + /* * figure out of the %%Page: line contains a page number * or some other page description to use in the menu bar. - * + * * lines look like %%Page: x y or %%Page: x * we prefer just x, and will generate our * own if necessary. @@ -355,6 +355,7 @@ Keepreading: if(dumb) { fprint(ps->gs.gsfd, "(%s) run PAGEFLUSH\n", argv[0]); fprint(ps->gs.gsfd, "(/dev/fd/3) (w) file dup (THIS IS NOT A PLAN9 BITMAP 01234567890123456789012345678901234567890123456789\\n) writestring flushfile\n"); + close(ps->gs.gsfd); } ps->bbox = bbox; diff --git a/src/cmd/page/rotate.c b/src/cmd/page/rotate.c index 3ac83a1f..2c6ea520 100644 --- a/src/cmd/page/rotate.c +++ b/src/cmd/page/rotate.c @@ -1,12 +1,12 @@ /* * rotate an image 180° in O(log Dx + log Dy) /dev/draw writes, * using an extra buffer same size as the image. - * + * * the basic concept is that you can invert an array by inverting * the top half, inverting the bottom half, and then swapping them. * the code does this slightly backwards to ensure O(log n) runtime. * (If you do it wrong, you can get O(log² n) runtime.) - * + * * This is usually overkill, but it speeds up slow remote * connections quite a bit. */ @@ -37,7 +37,7 @@ writefile(char *name, Image *im, int gran) snprint(buf, sizeof buf, "%d%s%d", c++, name, gran); fd = create(buf, OWRITE, 0666); if(fd < 0) - return; + return; writeimage(fd, im, 0); close(fd); } @@ -109,7 +109,7 @@ interlace(Image *im, Image *tmp, int axis, int n, Image *mask, int gran) /* * Halve the grating period in the mask. - * The grating currently looks like + * The grating currently looks like * ####____####____####____####____ * where #### is opacity. * @@ -117,7 +117,7 @@ interlace(Image *im, Image *tmp, int axis, int n, Image *mask, int gran) * ##__##__##__##__##__##__##__##__ * which is achieved by shifting the mask * and drawing on itself through itself. - * Draw doesn't actually allow this, so + * Draw doesn't actually allow this, so * we have to copy it first. * * ####____####____####____####____ (dst) @@ -151,7 +151,7 @@ shuffle(Image *im, Image *tmp, int axis, int n, Image *mask, int gran, interlace(im, tmp, axis, nn, mask, gran); // writefile("interlace", im, gran); - + gran = nextmask(mask, axis, gran); shuffle(im, tmp, axis, n, mask, gran, nn); // writefile("shuffle", im, gran); @@ -288,7 +288,7 @@ fac(int L) return f; } -/* +/* * i0(x) is the modified Bessel function, Σ (x/2)^2L / (L!)² * There are faster ways to calculate this, but we precompute * into a table so let's keep it simple. diff --git a/src/cmd/page/util.c b/src/cmd/page/util.c index f10ef6db..3b4655d1 100644 --- a/src/cmd/page/util.c +++ b/src/cmd/page/util.c @@ -50,7 +50,7 @@ spooltodisk(uchar *ibuf, int in, char **name) { uchar buf[8192]; int fd, n; - + strcpy(tempfile, "/tmp/pagespoolXXXXXXXXX"); fd = opentemp(tempfile, ORDWR); if(name) @@ -94,7 +94,7 @@ _stdinpipe(void *a) arg = a; if(pipe(p) < 0){ - fprint(2, "pipe fails: %r\n"); + fprint(2, "pipe fails: %r\n"); wexits("pipe"); } @@ -103,7 +103,7 @@ _stdinpipe(void *a) write(p[1], arg->ibuf, arg->in); while((n = read(stdinfd, buf, sizeof buf)) > 0) write(p[1], buf, n); - + close(p[1]); threadexits(0); } diff --git a/src/cmd/page/view.c b/src/cmd/page/view.c index 315a22a8..2696f01f 100644 --- a/src/cmd/page/view.c +++ b/src/cmd/page/view.c @@ -33,25 +33,25 @@ void plumbproc(void*); Cursor reading={ {-1, -1}, - {0xff, 0x80, 0xff, 0x80, 0xff, 0x00, 0xfe, 0x00, - 0xff, 0x00, 0xff, 0x80, 0xff, 0xc0, 0xef, 0xe0, - 0xc7, 0xf0, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0xc0, + {0xff, 0x80, 0xff, 0x80, 0xff, 0x00, 0xfe, 0x00, + 0xff, 0x00, 0xff, 0x80, 0xff, 0xc0, 0xef, 0xe0, + 0xc7, 0xf0, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0xc0, 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, }, - {0x00, 0x00, 0x7f, 0x00, 0x7e, 0x00, 0x7c, 0x00, - 0x7e, 0x00, 0x7f, 0x00, 0x6f, 0x80, 0x47, 0xc0, - 0x03, 0xe0, 0x01, 0xf0, 0x00, 0xe0, 0x00, 0x40, + {0x00, 0x00, 0x7f, 0x00, 0x7e, 0x00, 0x7c, 0x00, + 0x7e, 0x00, 0x7f, 0x00, 0x6f, 0x80, 0x47, 0xc0, + 0x03, 0xe0, 0x01, 0xf0, 0x00, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x01, 0xb6, 0x01, 0xb6, 0x00, 0x00, } }; Cursor query = { {-7,-7}, - {0x0f, 0xf0, 0x1f, 0xf8, 0x3f, 0xfc, 0x7f, 0xfe, - 0x7c, 0x7e, 0x78, 0x7e, 0x00, 0xfc, 0x01, 0xf8, - 0x03, 0xf0, 0x07, 0xe0, 0x07, 0xc0, 0x07, 0xc0, + {0x0f, 0xf0, 0x1f, 0xf8, 0x3f, 0xfc, 0x7f, 0xfe, + 0x7c, 0x7e, 0x78, 0x7e, 0x00, 0xfc, 0x01, 0xf8, + 0x03, 0xf0, 0x07, 0xe0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, }, - {0x00, 0x00, 0x0f, 0xf0, 0x1f, 0xf8, 0x3c, 0x3c, - 0x38, 0x1c, 0x00, 0x3c, 0x00, 0x78, 0x00, 0xf0, - 0x01, 0xe0, 0x03, 0xc0, 0x03, 0x80, 0x03, 0x80, + {0x00, 0x00, 0x0f, 0xf0, 0x1f, 0xf8, 0x3c, 0x3c, + 0x38, 0x1c, 0x00, 0x3c, 0x00, 0x78, 0x00, 0xf0, + 0x01, 0xe0, 0x03, 0xc0, 0x03, 0x80, 0x03, 0x80, 0x00, 0x00, 0x03, 0x80, 0x03, 0x80, 0x00, 0x00, } }; @@ -79,13 +79,13 @@ unhide(void) USED(nil); } -int +int max(int a, int b) { return a > b ? a : b; } -int +int min(int a, int b) { return a < b ? a : b; @@ -130,7 +130,7 @@ showpage(int page, Menu *m) m->lasthit = 0; /* this page */ else m->lasthit = reverse ? doc->npage-1-page : page; - + setcursor(mc, &reading); delayfreeimage(nil); im = cachedpage(doc, angle, page); @@ -178,7 +178,7 @@ writebitmap(void) q = basename; if(p = strchr(q, '.')) *p = 0; - + memset(name, 0, sizeof name); snprint(name, sizeof(name)-1, "%s.%d.bit", q, page+1); if(access(name, 0) >= 0) { @@ -241,7 +241,7 @@ enum{ Empty3, Exit, }; - + void viewer(Document *dd) { @@ -269,13 +269,13 @@ viewer(Document *dd) "next", "prev", "zerox", - "", + "", "reverse", "discard", "write", - "", - "quit", - 0 + "", + "quit", + 0 }; char *s; enum { @@ -287,7 +287,7 @@ viewer(Document *dd) }; Alt alts[CN+1]; Plumbmsg *pm; - + cp = chancreate(sizeof pm, 0); assert(cp); @@ -483,7 +483,7 @@ viewer(Document *dd) setcursor(mc, &query); sleep(1000); setcursor(mc, nil); - break; + break; } break; @@ -494,7 +494,7 @@ viewer(Document *dd) xy0 = oxy; do { dxy = subpt(m.xy, oxy); - oxy = m.xy; + oxy = m.xy; translate(dxy); recv(mc->c, &m); } while(m.buttons == Left); @@ -503,7 +503,7 @@ viewer(Document *dd) translate(dxy); } break; - + case Middle: if(doc->npage == 0) break; @@ -524,7 +524,7 @@ viewer(Document *dd) if((page >= doc->npage) && !doc->fwdonly) return; - + showpage(page, &menu); nxt = 0; break; @@ -540,7 +540,7 @@ viewer(Document *dd) if((page >= doc->npage) && !doc->fwdonly && !reverse) return; - + showpage(page, &menu); nxt = 0; break; @@ -565,7 +565,7 @@ viewer(Document *dd) showpage(page, &menu); } break; - } + } else{ /* image */ double delta; Rectangle r; @@ -581,8 +581,8 @@ viewer(Document *dd) delta = (double)Dy(im->r)/(double)Dy(r); setcursor(mc, &reading); - tmp = xallocimage(display, - Rect(0, 0, (int)((double)Dx(im->r)*delta), (int)((double)Dy(im->r)*delta)), + tmp = xallocimage(display, + Rect(0, 0, (int)((double)Dx(im->r)*delta), (int)((double)Dy(im->r)*delta)), im->chan, 0, DBlack); if(tmp == nil) { fprint(2, "out of memory during zoom: %r\n"); @@ -639,7 +639,7 @@ viewer(Document *dd) break; reverse = !reverse; menu.lasthit = doc->npage-1-menu.lasthit; - + if(page == 0 || page == doc->npage-1) { page = doc->npage-1-page; showpage(page, &menu); @@ -672,10 +672,10 @@ viewer(Document *dd) case Empty3: break; - }; + }; + + - - case Right: if(doc->npage == 0) break; @@ -684,7 +684,7 @@ viewer(Document *dd) n = menuhit(RMenu, mc, &menu, nil); if(n == -1) break; - + if(doc->fwdonly) { switch(n){ case 0: /* this page */ @@ -697,12 +697,12 @@ viewer(Document *dd) } break; } - + if(n == doc->npage) return; else page = reverse ? doc->npage-1-n : n; - + if(oldpage != page) showpage(page, &menu); nxt = 0; @@ -753,7 +753,7 @@ Image *gray; * mp and sp get aligned with bot.min. */ static void -gendrawdiff(Image *dst, Rectangle bot, Rectangle top, +gendrawdiff(Image *dst, Rectangle bot, Rectangle top, Image *src, Point sp, Image *mask, Point mp, int op) { Rectangle r; @@ -890,7 +890,7 @@ redraw(Image *screen) } } border(screen, r, -4000, gray, ZP); -// flushimage(display, 0); +// flushimage(display, 0); } /* clip p to be in r */ @@ -911,7 +911,7 @@ pclip(Point p, Rectangle r) } /* - * resize is perhaps a misnomer. + * resize is perhaps a misnomer. * this really just grows the window to be at least dx across * and dy high. if the window hits the bottom or right edge, * it is backed up until it hits the top or left edge. |