From 8fc5e040ac9befb38d67fe89af89de37046caa37 Mon Sep 17 00:00:00 2001 From: malc Date: Sun, 4 Jul 2010 23:39:02 +0400 Subject: [PATCH] Support for rotation --- link.c | 29 ++++++++++++++++++++++++++--- main.ml | 33 ++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/link.c b/link.c index c1455d8..38b304d 100644 --- a/link.c +++ b/link.c @@ -151,6 +151,8 @@ struct { struct slice *slice; } *texowners; + int rotate; + #ifdef _WIN32 HANDLE thread; #else @@ -488,6 +490,7 @@ static void initpdims (void) else { rotate = 0; } + rotate += state.rotate; state.pagetbl[pageno] = fz_tonum (state.xref->pagerefs[pageno]); p = &state.pagedims[state.pagedimcount - 1]; @@ -905,6 +908,25 @@ mainloop (void *unused) unlock ("geometry"); printd (state.sock, "C %d", state.pagecount); } + else if (!strncmp ("rotate", p, 6)) { + float rotate; + + printd (state.sock, "c"); + ret = sscanf (p + 6, " %f", &rotate); + if (ret != 1) { + errx (1, "bad rotate line `%.*s' ret=%d", len, p, ret); + } + state.rotate = rotate; + lock ("rotate"); + state.pagedimcount = 0; + free (state.pagedims); + state.pagedims = NULL; + initpdims (); + layout (); + process_outline (); + unlock ("rotate"); + printd (state.sock, "C %d", state.pagecount); + } else if (!strncmp ("render", p, 6)) { int pageno, pindex, w, h, ret; struct page *page; @@ -915,10 +937,11 @@ mainloop (void *unused) } page = render (pageno, pindex); - printd (state.sock, "r %d %d %d %p\n", + printd (state.sock, "r %d %d %d %d %p\n", pageno, state.w, state.h, + state.rotate, page); } else { @@ -1102,8 +1125,8 @@ static pdf_link *getlink (struct page *page, int x, int y) fz_matrix ctm; pdf_link *link; - p.x = x; - p.y = y; + p.x = x + page->pixmap->x; + p.y = y + page->pixmap->y; ctm = fz_invertmatrix (page->pagedim->ctm); p = fz_transformpoint (ctm, p); diff --git a/main.ml b/main.ml index 16e5332..26be1d0 100644 --- a/main.ml +++ b/main.ml @@ -97,11 +97,12 @@ type state = ; mutable ssock : Unix.file_descr ; mutable w : int ; mutable h : int + ; mutable rotate : int ; mutable y : int ; mutable prevy : int ; mutable maxy : int ; mutable layout : layout list - ; pagemap : ((int * int), string) Hashtbl.t + ; pagemap : ((int * int * int), string) Hashtbl.t ; mutable pages : (int * int * int) list ; mutable pagecount : int ; pagecache : string circbuf @@ -142,6 +143,7 @@ let state = ; ssock = Unix.stdin ; w = 900 ; h = 900 + ; rotate = 0 ; y = 0 ; prevy = 0 ; layout = [] @@ -483,11 +485,11 @@ let act cmd = state.rects1 <- (pageno, c, (x0, y0), (x1, y1)) :: state.rects1 | 'r' -> - let n, w, h, p = - Scanf.sscanf cmd "r %d %d %d %s" - (fun n w h p -> (n, w, h, p)) + let n, w, h, r, p = + Scanf.sscanf cmd "r %d %d %d %d %s" + (fun n w h r p -> (n, w, h, r, p)) in - Hashtbl.replace state.pagemap (n, w) p; + Hashtbl.replace state.pagemap (n, w, r) p; let evicted = cbpeekw state.pagecache in if String.length evicted > 0 then begin @@ -525,12 +527,14 @@ let act cmd = ;; let getopaque pageno = - try Some (Hashtbl.find state.pagemap (pageno + 1, state.w - conf.scrollw)) + try Some (Hashtbl.find state.pagemap (pageno + 1, state.w - conf.scrollw, + state.rotate)) with Not_found -> None ;; let cache pageno opaque = - Hashtbl.replace state.pagemap (pageno + 1, state.w - conf.scrollw) opaque + Hashtbl.replace state.pagemap (pageno + 1, state.w - conf.scrollw, + state.rotate) opaque ;; let validopaque opaque = String.length opaque > 0;; @@ -649,6 +653,17 @@ let optentry text key = in TEswitch ('#', "", intentry, ondone) + | 'R' -> + let ondone s = + try + state.rotate <- int_of_string s; + wcmd "rotate" [`i state.rotate] + with exc -> + state.text <- Printf.sprintf "bad integer `%s': %s" + s (Printexc.to_string exc) + in + TEswitch ('^', "", intentry, ondone) + | 'i' -> conf.icase <- not conf.icase; TEdone ("case insensitive search " ^ (btos conf.icase)) @@ -937,6 +952,10 @@ let viewkeyboard ~key ~x ~y = | [] -> () end + | '<' | '>' -> + state.rotate <- state.rotate + (if c = '>' then 30 else -30); + wcmd "rotate" [`i state.rotate] + | _ -> vlog "huh? %d %c" key (Char.chr key); end -- 2.11.4.GIT