From c6b819933a3280cf66f4e282c7b7a28216e46889 Mon Sep 17 00:00:00 2001 From: malc Date: Thu, 11 Oct 2012 10:41:23 +0400 Subject: [PATCH] Fix another issue with page_of_y and use it to bootstrap layouting --- main.ml | 93 ++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/main.ml b/main.ml index 52800ad..521de43 100644 --- a/main.ml +++ b/main.ml @@ -1097,6 +1097,57 @@ let nogeomcmds cmds = | _ -> false ;; +let page_of_y y = + let (c, coverA, coverB), b = + match conf.columns with + | Csingle b -> (1, 0, 0), b + | Cmulti (c, b) -> c, b + | Csplit (_, b) -> (1, 0, 0), b + in + let rec bsearch nmin nmax = + if nmin > nmax + then -1 + else + let n = (nmax + nmin) / 2 in + let _, _, vy, (_, _, h, _) = b.(n) in + let y0, y1 = + if conf.presentation + then + let ips = calcips h in + let y0 = vy - ips in + let y1 = vy + h + ips in + y0, y1 + else ( + if n = 0 + then 0, vy + h + conf.interpagespace + else + let y0 = vy - conf.interpagespace in + y0, y0 + h + conf.interpagespace + ) + in + if y >= y0 && y < y1 + then ( + if c = 1 + then n + else ( + if n > coverA + then + if n < state.pagecount - coverB + then ((n-coverA)/c)*c + coverA + else n + else n + ) + ) + else ( + if y > y0 + then bsearch (n+1) nmax + else bsearch nmin (n-1) + ) + in + let r = bsearch 0 (state.pagecount-1) in + r; +;; + let layoutN ((columns, coverA, coverB), b) y sh = let sh = sh - state.hscrollh in let rec fold accu n = @@ -1155,7 +1206,7 @@ let layoutN ((columns, coverA, coverB), b) y sh = in fold accu (n+1) in - List.rev (fold [] 0); + List.rev (fold [] (page_of_y y)); ;; let layoutS (columns, b) y sh = @@ -1452,46 +1503,6 @@ let tilepage n p layout = then loop layout; ;; -let page_of_y y = - let b = - match conf.columns with - | Csingle b -> b - | Cmulti (_, b) -> b - | Csplit (_, b) -> b - in - let rec bsearch nmin nmax = - if nmin > nmax - then -1 - else - let n = (nmax + nmin) / 2 in - let _, _, vy, (_, _, h, _) = b.(n) in - let y0, y1 = - if conf.presentation - then - let ips = calcips h in - let y0 = vy - ips in - let y1 = vy + h + ips in - y0, y1 - else ( - if n = 0 - then 0, vy + h + conf.interpagespace - else - let y0 = vy - conf.interpagespace in - y0, y0 + h - ) - in - if y >= y0 && y < y1 - then n - else ( - if y > y0 - then bsearch (n+1) nmax - else bsearch nmin (n-1) - ) - in - let r = bsearch 0 (state.pagecount-1) in - r; -;; - let preloadlayout y = let y = if y < conf.winh then 0 else y - conf.winh in let h = conf.winh*3 in -- 2.11.4.GIT