diff options
author | rsc <devnull@localhost> | 2006-03-20 02:25:59 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2006-03-20 02:25:59 +0000 |
commit | 17157e4aa85baea6c1503e2c95d98ed66a1596f1 (patch) | |
tree | 0d5170a9f88cb8f25e2d824d0b96f57b968d426a /src/cmd/page | |
parent | 7bd7fd2f4f6fb39400f6f64feb7ec9cba89cf3a3 (diff) | |
download | plan9port-17157e4aa85baea6c1503e2c95d98ed66a1596f1.tar.gz plan9port-17157e4aa85baea6c1503e2c95d98ed66a1596f1.tar.bz2 plan9port-17157e4aa85baea6c1503e2c95d98ed66a1596f1.zip |
update lucida
Diffstat (limited to 'src/cmd/page')
-rw-r--r-- | src/cmd/page/filter.c | 1 | ||||
-rw-r--r-- | src/cmd/page/gfx.c | 4 | ||||
-rw-r--r-- | src/cmd/page/gs.c | 16 | ||||
-rw-r--r-- | src/cmd/page/mkfile | 2 | ||||
-rw-r--r-- | src/cmd/page/nrotate.c | 1 | ||||
-rw-r--r-- | src/cmd/page/page.c | 59 | ||||
-rw-r--r-- | src/cmd/page/page.h | 5 | ||||
-rw-r--r-- | src/cmd/page/pdf.c | 9 | ||||
-rw-r--r-- | src/cmd/page/ps.c | 3 | ||||
-rw-r--r-- | src/cmd/page/rotate.c | 29 | ||||
-rw-r--r-- | src/cmd/page/util.c | 1 | ||||
-rw-r--r-- | src/cmd/page/view.c | 82 |
12 files changed, 133 insertions, 79 deletions
diff --git a/src/cmd/page/filter.c b/src/cmd/page/filter.c index 07c3df2b..319cfb68 100644 --- a/src/cmd/page/filter.c +++ b/src/cmd/page/filter.c @@ -1,6 +1,7 @@ #include <u.h> #include <libc.h> #include <draw.h> +#include <cursor.h> #include <event.h> #include <bio.h> #include "page.h" diff --git a/src/cmd/page/gfx.c b/src/cmd/page/gfx.c index 72254de8..6a947039 100644 --- a/src/cmd/page/gfx.c +++ b/src/cmd/page/gfx.c @@ -5,6 +5,7 @@ #include <u.h> #include <libc.h> #include <draw.h> +#include <cursor.h> #include <event.h> #include <bio.h> #include "page.h" @@ -71,6 +72,8 @@ static Image* convert(Graphic*); static Image* gfxdrawpage(Document *d, int page); static char* gfxpagename(Document*, int); static int spawnrc(char*, uchar*, int); +static void waitrc(void); +static int spawnpost(int); static int addpage(Document*, char*); static int rmpage(Document*, int); static int genaddpage(Document*, char*, uchar*, int); @@ -97,6 +100,7 @@ initgfx(Biobuf *b, int argc, char **argv, uchar *buf, int nbuf) int i; USED(b); + doc = emalloc(sizeof(*doc)); gfx = emalloc(sizeof(*gfx)); gfx->g = nil; diff --git a/src/cmd/page/gs.c b/src/cmd/page/gs.c index 524701e3..2093af56 100644 --- a/src/cmd/page/gs.c +++ b/src/cmd/page/gs.c @@ -7,6 +7,7 @@ #include <u.h> #include <libc.h> #include <draw.h> +#include <cursor.h> #include <event.h> #include <bio.h> #include "page.h" @@ -134,7 +135,7 @@ spawnmonitor(int fd) } int -spawngs(GSInfo *g) +spawngs(GSInfo *g, char *safer) { char *args[16]; char tb[32], gb[32]; @@ -158,7 +159,7 @@ spawngs(GSInfo *g) nargs = 0; args[nargs++] = "gs"; args[nargs++] = "-dNOPAUSE"; - args[nargs++] = "-dSAFER"; + args[nargs++] = safer; args[nargs++] = "-sDEVICE=plan9"; args[nargs++] = "-sOutputFile=/fd/3"; args[nargs++] = "-dQUIET"; @@ -268,14 +269,11 @@ setdim(GSInfo *gs, Rectangle bbox, int ppi, int landscape) if(!Dx(bbox)) bbox = Rect(0, 0, 612, 792); /* 8½×11 */ - switch(landscape){ - case 0: - pbox = bbox; - break; - case 1: + if(landscape) pbox = Rect(bbox.min.y, bbox.min.x, bbox.max.y, bbox.max.x); - break; - } + else + pbox = bbox; + gscmd(gs, "/PageSize [%d %d]\n", Dx(pbox), Dy(pbox)); gscmd(gs, "/Margins [%d %d]\n", -pbox.min.x, -pbox.min.y); gscmd(gs, "currentdevice putdeviceprops pop\n"); diff --git a/src/cmd/page/mkfile b/src/cmd/page/mkfile index e8dbf52a..0c4163ad 100644 --- a/src/cmd/page/mkfile +++ b/src/cmd/page/mkfile @@ -14,7 +14,7 @@ OFILES=\ util.$O\ view.$O\ -<$PLAN9/src//mkone +<$PLAN9/src/mkone pdfprolog.c: pdfprolog.ps cat pdfprolog.ps | sed 's/.*/"&\\n"/g' >pdfprolog.c diff --git a/src/cmd/page/nrotate.c b/src/cmd/page/nrotate.c index 2225ec3f..65fe33ab 100644 --- a/src/cmd/page/nrotate.c +++ b/src/cmd/page/nrotate.c @@ -15,6 +15,7 @@ #include <libc.h> #include <bio.h> #include <draw.h> +#include <cursor.h> #include <event.h> #include "page.h" diff --git a/src/cmd/page/page.c b/src/cmd/page/page.c index 3669ebfb..4c76e033 100644 --- a/src/cmd/page/page.c +++ b/src/cmd/page/page.c @@ -1,6 +1,7 @@ #include <u.h> #include <libc.h> #include <draw.h> +#include <cursor.h> #include <event.h> #include <bio.h> #include "page.h" @@ -19,43 +20,6 @@ int wctlfd = -1; int stdinfd; int truecolor; int imagemode; -int notewatcher; -int notegp; - -int -watcher(void *v, char *x) -{ - USED(v); - - if(strcmp(x, "die") != 0) - postnote(PNGROUP, notegp, x); - _exits(0); - return 0; -} - -int -bell(void *u, char *x) -{ - if(x && strcmp(x, "hangup") == 0) - _exits(0); - - if(x && strstr(x, "die") == nil) - fprint(2, "postnote %d: %s\n", getpid(), x); - - /* alarms come from the gs monitor */ - if(x && strstr(x, "alarm")){ - postnote(PNGROUP, getpid(), "die (gs error)"); - postnote(PNPROC, notewatcher, "die (gs error)"); - } - - /* function mentions u so that it's in the stack trace */ - if((u == nil || u != x) && doabort) - abort(); - -/* fprint(2, "exiting %d\n", getpid()); */ - wexits("note"); - return 0; -} static int afmt(Fmt *fmt) @@ -128,23 +92,7 @@ main(int argc, char **argv) usage(); }ARGEND; - notegp = getpid(); - - switch(notewatcher = fork()){ - case -1: - sysfatal("fork\n"); - exits(0); - default: - break; - case 0: - atnotify(watcher, 1); - for(;;) - sleep(1000); - _exits(0); - } - rfork(RFNOTEG); - atnotify(bell, 1); readstdin = 0; if(imagemode == 0 && argc == 0){ @@ -159,6 +107,8 @@ main(int argc, char **argv) fmtinstall('R', Rfmt); fmtinstall('P', Pfmt); + if(mknewwindow) + newwin(); if(readstdin){ b = nil; @@ -229,8 +179,5 @@ main(int argc, char **argv) void wexits(char *s) { - if(s && *s && strcmp(s, "note") != 0 && mknewwindow) - sleep(10*1000); - postnote(PNPROC, notewatcher, "die"); exits(s); } diff --git a/src/cmd/page/page.h b/src/cmd/page/page.h index aa19ff71..be54e386 100644 --- a/src/cmd/page/page.h +++ b/src/cmd/page/page.h @@ -1,5 +1,3 @@ -#include <cursor.h> - typedef struct Document Document; struct Document { @@ -44,6 +42,7 @@ extern int mknewwindow; void rot180(Image*); Image *rot90(Image*); +Image *rot270(Image*); Image *resample(Image*, Image*); /* ghostscript interface shared by ps, pdf */ @@ -57,7 +56,7 @@ struct GSInfo { }; void waitgs(GSInfo*); int gscmd(GSInfo*, char*, ...); -int spawngs(GSInfo*); +int spawngs(GSInfo*, char*); void setdim(GSInfo*, Rectangle, int, int); int spawnwriter(GSInfo*, Biobuf*); Rectangle screenrect(void); diff --git a/src/cmd/page/pdf.c b/src/cmd/page/pdf.c index 44615a21..d723ad8c 100644 --- a/src/cmd/page/pdf.c +++ b/src/cmd/page/pdf.c @@ -7,6 +7,7 @@ #include <u.h> #include <libc.h> #include <draw.h> +#include <cursor.h> #include <event.h> #include <bio.h> #include "page.h" @@ -97,14 +98,14 @@ initpdf(Biobuf *b, int argc, char **argv, uchar *buf, int nbuf) d->pagename = pdfpagename; d->fwdonly = 0; - if(spawngs(&pdf->gs) < 0) + if(spawngs(&pdf->gs, "-dDELAYSAFER") < 0) return nil; gscmd(&pdf->gs, "%s", pdfprolog); waitgs(&pdf->gs); setdim(&pdf->gs, Rect(0,0,0,0), ppi, 0); - gscmd(&pdf->gs, "(%s) (r) file pdfopen begin\n", fn); + gscmd(&pdf->gs, "(%s) (r) file { DELAYSAFER { .setsafe } if } stopped pop pdfopen begin\n", fn); gscmd(&pdf->gs, "pdfpagecount PAGE==\n"); p = Brdline(&pdf->gs.gsrd, '\n'); npage = atoi(p); @@ -121,11 +122,10 @@ initpdf(Biobuf *b, int argc, char **argv, uchar *buf, int nbuf) pdf->pagebbox = emalloc(sizeof(Rectangle)*npage); for(i=0; i<npage; i++) { gscmd(&pdf->gs, "%d pdfgetpage\n", i+1); - pdf->pagebbox[i] = pdfbbox(&pdf->gs); + pdf->pagebbox[i] = pdfbbox(pdf); if(Dx(pdf->pagebbox[i]) <= 0) pdf->pagebbox[i] = bbox; } - return d; } @@ -149,6 +149,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/ps.c b/src/cmd/page/ps.c index 46ad5cdb..cc6f3c51 100644 --- a/src/cmd/page/ps.c +++ b/src/cmd/page/ps.c @@ -7,6 +7,7 @@ #include <u.h> #include <libc.h> #include <draw.h> +#include <cursor.h> #include <event.h> #include <bio.h> #include <ctype.h> @@ -348,7 +349,7 @@ Keepreading: d->fwdonly = ps->clueless = dumb; d->docname = argv[0]; - if(spawngs(&ps->gs) < 0) + if(spawngs(&ps->gs, "-dSAFER") < 0) return nil; if(!cantranslate) diff --git a/src/cmd/page/rotate.c b/src/cmd/page/rotate.c index b2952637..9e1c20db 100644 --- a/src/cmd/page/rotate.c +++ b/src/cmd/page/rotate.c @@ -15,6 +15,7 @@ #include <libc.h> #include <bio.h> #include <draw.h> +#include <cursor.h> #include <event.h> #include "page.h" @@ -54,6 +55,7 @@ moveup(Image *im, Image *tmp, int a, int b, int c, int axis) drawop(tmp, tmp->r, im, nil, im->r.min, S); switch(axis){ + default: case Xaxis: range = Rect(a, im->r.min.y, c, im->r.max.y); dr0 = range; @@ -88,6 +90,7 @@ interlace(Image *im, Image *tmp, int axis, int n, Image *mask, int gran) r0 = im->r; r1 = im->r; switch(axis) { + default: case Xaxis: r0.max.x = n; r1.min.x = n; @@ -245,6 +248,31 @@ rot90(Image *im) return(tmp); } +/* rotates an image 270 degrees clockwise */ +Image * +rot270(Image *im) +{ + Image *tmp; + int i, j, dx, dy; + + dx = Dx(im->r); + dy = Dy(im->r); + tmp = xallocimage(display, Rect(0, 0, dy, dx), im->chan, 0, DCyan); + if(tmp == nil) { + fprint(2, "out of memory during rot270: %r\n"); + wexits("memory"); + } + + for(i = 0; i < dy; i++) { + for(j = 0; j < dx; j++) { + drawop(tmp, Rect(i, j, i+1, j+1), im, nil, Pt(dx-(j+1), i), S); + } + } + freeimage(im); + + return(tmp); +} + /* from resample.c -- resize from → to using interpolation */ @@ -288,6 +316,7 @@ kaiser(double x, double tau, double alpha) return i0(alpha*sqrt(1-(x*x/(tau*tau))))/i0(alpha); } + void resamplex(uchar *in, int off, int d, int inx, uchar *out, int outx) { diff --git a/src/cmd/page/util.c b/src/cmd/page/util.c index 22832baa..2669df84 100644 --- a/src/cmd/page/util.c +++ b/src/cmd/page/util.c @@ -1,6 +1,7 @@ #include <u.h> #include <libc.h> #include <draw.h> +#include <cursor.h> #include <event.h> #include <bio.h> #include "page.h" diff --git a/src/cmd/page/view.c b/src/cmd/page/view.c index 92aedeb9..4321f829 100644 --- a/src/cmd/page/view.c +++ b/src/cmd/page/view.c @@ -6,6 +6,7 @@ #include <libc.h> #include <draw.h> #include <cursor.h> +#include <cursor.h> #include <event.h> #include <bio.h> #include <plumb.h> @@ -16,7 +17,7 @@ Document *doc; Image *im; int page; -int upside = 0; +int angle = 0; int showbottom = 0; /* on the next showpage, move the image so the bottom is visible. */ Rectangle ulrange; /* the upper left corner of the image must be in this rectangle */ @@ -156,8 +157,17 @@ showpage(int page, Menu *m) im = tmp; } - if(upside) + switch(angle){ + case 90: + im = rot90(im); + break; + case 180: rot180(im); + break; + case 270: + im = rot270(im); + break; + } esetcursor(nil); if(showbottom){ @@ -390,7 +400,7 @@ viewer(Document *dd) esetcursor(&reading); rot180(im); esetcursor(nil); - upside = !upside; + angle = (angle+180) % 360; redraw(screen); flushimage(display, 1); break; @@ -589,6 +599,7 @@ viewer(Document *dd) esetcursor(&reading); im = rot90(im); esetcursor(nil); + angle = (angle+90) % 360; redraw(screen); flushimage(display, 1); break; @@ -598,7 +609,7 @@ viewer(Document *dd) esetcursor(&reading); rot180(im); esetcursor(nil); - upside = !upside; + angle = (angle+180) % 360; redraw(screen); flushimage(display, 1); break; @@ -978,6 +989,67 @@ rdenv(char *name) return v; } +void +newwin(void) +{ + char *srv, *mntsrv; + char spec[100]; + int srvfd, cons, pid; + + switch(rfork(RFFDG|RFPROC|RFNAMEG|RFENVG|RFNOTEG|RFNOWAIT)){ + case -1: + fprint(2, "page: can't fork: %r\n"); + wexits("no fork"); + case 0: + break; + default: + wexits(0); + } + + srv = rdenv("/env/wsys"); + if(srv == 0){ + mntsrv = rdenv("/mnt/term/env/wsys"); + if(mntsrv == 0){ + fprint(2, "page: can't find $wsys\n"); + wexits("srv"); + } + srv = malloc(strlen(mntsrv)+10); + sprint(srv, "/mnt/term%s", mntsrv); + free(mntsrv); + pid = 0; /* can't send notes to remote processes! */ + }else + pid = getpid(); + srvfd = open(srv, ORDWR); + free(srv); + if(srvfd == -1){ + fprint(2, "page: can't open %s: %r\n", srv); + wexits("no srv"); + } + sprint(spec, "new -pid %d", pid); + if(mount(srvfd, -1, "/mnt/wsys", 0, spec) == -1){ + fprint(2, "page: can't mount /mnt/wsys: %r (spec=%s)\n", spec); + wexits("no mount"); + } + close(srvfd); + unmount("/mnt/acme", "/dev"); + bind("/mnt/wsys", "/dev", MBEFORE); + cons = open("/dev/cons", OREAD); + if(cons==-1){ + NoCons: + fprint(2, "page: can't open /dev/cons: %r"); + wexits("no cons"); + } + dup(cons, 0); + close(cons); + cons = open("/dev/cons", OWRITE); + if(cons==-1) + goto NoCons; + dup(cons, 1); + dup(cons, 2); + close(cons); +// wctlfd = open("/dev/wctl", OWRITE); +} + Rectangle screenrect(void) { @@ -1011,7 +1083,7 @@ zerox(void) case 0: dup(pfd[1], 0); close(pfd[0]); - execl("/bin/page", "page", "-w", 0); + execl("/bin/page", "page", "-w", nil); wexits("cannot exec in zerox: %r\n"); default: close(pfd[1]); |