4 | Ulinkgoto
of (int * int)
6 | Uunexpected
of string
9 | Uremote
of (string * int)
10 and facename
= string;;
12 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
13 let now = Unix.gettimeofday
;;
15 type params
= (angle
* proportional
* trimparams
16 * texcount
* sliceheight
* memsize
17 * colorspace
* fontpath
)
26 and proportional
= bool
27 and trimmargins
= bool
28 and interpagespace
= int
36 and irect
= (int * int * int * int)
37 and trimparams
= (trimmargins
* irect
)
38 and colorspace
= | Rgb
| Bgr
| Gray
41 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
42 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
44 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
46 external init
: pipe
-> params
-> unit = "ml_init";;
47 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
48 external copysel
: string -> opaque
-> unit = "ml_copysel";;
49 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
50 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
51 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
52 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
53 external measurestr
: int -> string -> float = "ml_measure_string";;
54 external getmaxw
: unit -> float = "ml_getmaxw";;
55 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
56 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
57 external platform
: unit -> platform
= "ml_platform";;
58 external setaalevel
: int -> unit = "ml_setaalevel";;
59 external realloctexts
: int -> bool = "ml_realloctexts";;
60 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
62 let platform_to_string = function
63 | Punknown
-> "unknown"
67 | Pfreebsd
-> "FreeBSD"
68 | Pdragonflybsd
-> "DragonflyBSD"
69 | Popenbsd
-> "OpenBSD"
74 let platform = platform ();;
80 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
83 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
87 | Msel
of (mpos
* mpos
)
90 | Mzoom
of (int * int)
91 | Mzoomrect
of (mpos
* mpos
)
95 type textentry
= string * string * onhist
option * onkey
* ondone
96 and onkey
= string -> int -> te
97 and ondone
= string -> unit
98 and histcancel
= unit -> unit
99 and onhist
= ((histcmd
-> string) * histcancel
)
100 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
105 | TEswitch
of textentry
116 let bound v minv maxv
=
117 max minv
(min maxv v
);
121 { store
= Array.create n v
128 let drawstring size x y s
=
130 Gl.enable `texture_2d
;
131 ignore
(drawstr size x y s
);
133 Gl.disable `texture_2d
;
136 let drawstring1 size x y s
=
140 let drawstring2 size x y fmt
=
141 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
144 let cbcap b
= Array.length b
.store
;;
149 b
.wc
<- (b
.wc
+ 1) mod cap;
151 b
.len
<- min
(b
.len
+ 1) cap;
154 let cbempty b
= b
.len
= 0;;
156 let cbgetg b circular dir
=
160 let rc = b
.rc + dir
in
172 else max
0 (min
rc (b
.len
-1))
178 let cbget b
= cbgetg b
false;;
179 let cbgetc b
= cbgetg b
true;;
196 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
197 dolog " WxH %dx%d" l
.pagew l
.pageh
;
198 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
199 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
200 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
204 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
206 dolog " x0,y0=(% f, % f)" x0 y0
;
207 dolog " x1,y1=(% f, % f)" x1 y1
;
208 dolog " x2,y2=(% f, % f)" x2 y2
;
209 dolog " x3,y3=(% f, % f)" x3 y3
;
214 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
215 and multicol
= columncount
* covercount
* covercount
217 and columncount
= int
218 and covercount
= int;;
221 { mutable scrollbw
: int
222 ; mutable scrollh
: int
223 ; mutable icase
: bool
224 ; mutable preload
: bool
225 ; mutable pagebias
: int
226 ; mutable verbose
: bool
227 ; mutable debug
: bool
228 ; mutable scrollstep
: int
229 ; mutable maxhfit
: bool
230 ; mutable crophack
: bool
231 ; mutable autoscrollstep
: int
232 ; mutable maxwait
: float option
233 ; mutable hlinks
: bool
234 ; mutable underinfo
: bool
235 ; mutable interpagespace
: interpagespace
236 ; mutable zoom
: float
237 ; mutable presentation
: bool
238 ; mutable angle
: angle
241 ; mutable savebmarks
: bool
242 ; mutable proportional
: proportional
243 ; mutable trimmargins
: trimmargins
244 ; mutable trimfuzz
: irect
245 ; mutable memlimit
: memsize
246 ; mutable texcount
: texcount
247 ; mutable sliceheight
: sliceheight
248 ; mutable thumbw
: width
249 ; mutable jumpback
: bool
250 ; mutable bgcolor
: float * float * float
251 ; mutable bedefault
: bool
252 ; mutable scrollbarinpm
: bool
253 ; mutable tilew
: int
254 ; mutable tileh
: int
255 ; mutable mustoresize
: memsize
256 ; mutable checkers
: bool
257 ; mutable aalevel
: int
258 ; mutable urilauncher
: string
259 ; mutable colorspace
: colorspace
260 ; mutable invert
: bool
261 ; mutable colorscale
: float
262 ; mutable redirectstderr
: bool
263 ; mutable ghyllscroll
: (int * int * int) option
264 ; mutable columns
: columns
option
265 ; mutable beyecolumns
: columncount
option
266 ; mutable selcmd
: string
270 type anchor
= pageno
* top
;;
272 type outline
= string * int * anchor
;;
274 type rect
= float * float * float * float * float * float * float * float;;
276 type tile
= opaque
* pixmapsize
* elapsed
277 and elapsed
= float;;
278 type pagemapkey
= pageno
* gen
;;
279 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
283 let emptyanchor = (0, 0.0);;
285 type infochange
= | Memused
| Docinfo
| Pdim
;;
287 class type uioh
= object
288 method display
: unit
289 method key
: int -> int -> uioh
290 method button
: int -> bool -> int -> int -> int -> uioh
291 method motion
: int -> int -> uioh
292 method pmotion
: int -> int -> uioh
293 method infochanged
: infochange
-> unit
294 method scrollpw
: (int * float * float)
295 method scrollph
: (int * float * float)
299 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
300 | Textentry
of (textentry
* onleave
)
302 and onleave
= leavetextentrystatus
-> unit
303 and leavetextentrystatus
= | Cancel
| Confirm
304 and helpitem
= string * int * action
307 | Action
of (uioh
-> uioh
)
310 let isbirdseye = function Birdseye _
-> true | _
-> false;;
311 let istextentry = function Textentry _
-> true | _
-> false;;
315 | Loading
of (page
* gen
)
317 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
319 | Outlining
of outline list
322 let nouioh : uioh
= object (self
)
324 method key _ _
= self
325 method button _ _ _ _ _
= self
326 method motion _ _
= self
327 method pmotion _ _
= self
328 method infochanged _
= ()
329 method scrollpw
= (0, nan
, nan
)
330 method scrollph
= (0, nan
, nan
)
334 { mutable sr
: Unix.file_descr
335 ; mutable sw
: Unix.file_descr
336 ; mutable wsfd
: Unix.file_descr
337 ; mutable errfd
: Unix.file_descr
option
338 ; mutable stderr
: Unix.file_descr
339 ; mutable errmsgs
: Buffer.t
340 ; mutable newerrmsgs
: bool
344 ; mutable scrollw
: int
345 ; mutable hscrollh
: int
346 ; mutable anchor
: anchor
347 ; mutable ranchors
: (string * string * anchor
) list
349 ; mutable layout
: page list
350 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
351 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
352 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
353 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
354 ; mutable pagecount
: int
355 ; mutable currently
: currently
356 ; mutable mstate
: mstate
357 ; mutable searchpattern
: string
358 ; mutable rects
: (pageno
* recttype
* rect
) list
359 ; mutable rects1
: (pageno
* recttype
* rect
) list
360 ; mutable text
: string
361 ; mutable fullscreen
: (width
* height
) option
362 ; mutable mode
: mode
363 ; mutable uioh
: uioh
364 ; mutable outlines
: outline array
365 ; mutable bookmarks
: outline list
366 ; mutable path
: string
367 ; mutable password
: string
368 ; mutable invalidated
: int
369 ; mutable memused
: memsize
371 ; mutable throttle
: (page list
* int * float) option
372 ; mutable autoscroll
: int option
373 ; mutable ghyll
: (int option -> unit)
374 ; mutable help
: helpitem array
375 ; mutable docinfo
: (int * string) list
376 ; mutable texid
: GlTex.texture_id
option
378 ; mutable prevzoom
: float
379 ; mutable progress
: float
380 ; mutable redisplay
: bool
383 { pat
: string circbuf
384 ; pag
: string circbuf
385 ; nav
: anchor circbuf
386 ; sel
: string circbuf
407 ; presentation
= false
412 ; proportional
= true
413 ; trimmargins
= false
414 ; trimfuzz
= (0,0,0,0)
415 ; memlimit
= 32 lsl 20
420 ; bgcolor
= (0.5, 0.5, 0.5)
422 ; scrollbarinpm
= true
425 ; mustoresize
= 128 lsl 20
430 | Plinux
| Pfreebsd
| Pdragonflybsd
431 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
432 | Posx
-> "open \"%s\""
433 | Pcygwin
-> "cygstart %s"
434 | Punknown
-> "echo %s")
437 | Plinux
| Pfreebsd
| Pdragonflybsd
438 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
445 ; redirectstderr
= false
452 let conf = { defconf with angle
= defconf.angle
};;
455 { mutable fontsize
: int
456 ; mutable wwidth
: float
457 ; mutable maxrows
: int
469 fstate.fontsize
<- n
;
470 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
471 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
475 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
476 let len = String.length s
in
477 if colonpos >= 0 && colonpos + 3 < len
479 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
482 try String.rindex_from s
colonpos ' '
486 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
489 | "http" | "ftp" | "mailto" ->
491 try String.index_from s
colonpos ' '
492 with Not_found
-> len
494 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
502 let shell, farg
= "/bin/sh", "-c" in
504 let args = [|shell; farg
; s
|] in
505 ignore
(Unix.create_process
shell args Unix.stdin
Unix.stdout
Unix.stderr
)
509 if String.length
conf.urilauncher
= 0
510 then print_endline uri
512 let url = geturl uri
in
513 if String.length
url = 0
514 then print_endline uri
516 let re = Str.regexp
"%s" in
517 let command = Str.global_replace
re url conf.urilauncher
in
521 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
527 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
528 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
532 let strings = version () :: "" :: Help.keys
in
535 let url = geturl s
in
536 if String.length
url > 0
537 then (s
, 0, Action
(fun u
-> gotouri url; u
))
538 else (s
, 0, Noaction
)
549 ; stderr
= Unix.stderr
550 ; errmsgs
= Buffer.create
0
557 ; anchor
= emptyanchor
561 ; tilelru
= Queue.create
()
562 ; pagemap
= Hashtbl.create
10
563 ; tilemap
= Hashtbl.create
10
580 { nav
= cbnew 10 (0, 0.0)
603 Printf.kprintf prerr_endline fmt
605 Printf.kprintf ignore fmt
608 let redirectstderr () =
609 if conf.redirectstderr
611 let rfd, wfd
= Unix.pipe
() in
612 state.stderr
<- Unix.dup
Unix.stderr
;
613 state.errfd
<- Some
rfd;
614 Unix.dup2 wfd
Unix.stderr
;
616 state.newerrmsgs
<- false;
617 begin match state.errfd
with
620 Unix.dup2
state.stderr
Unix.stderr
;
624 prerr_string
(Buffer.contents
state.errmsgs
);
626 Buffer.clear
state.errmsgs
;
632 let postRedisplay who
=
634 then prerr_endline
("redisplay for " ^ who
);
635 state.redisplay
<- true;
640 let b = Buffer.create
(String.length s
+ 1) in
641 Buffer.add_string
b s
;
646 let colorspace_of_string s
=
647 match String.lowercase s
with
651 | _
-> failwith
"invalid colorspace"
654 let int_of_colorspace = function
660 let colorspace_of_int = function
664 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
667 let colorspace_to_string = function
673 let intentry_with_suffix text key
=
675 if key
>= 32 && key
< 127
679 match Char.lowercase
c with
681 let text = addchar text c in
685 let text = addchar text c in
689 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
693 let columns_to_string (n
, a
, b) =
695 then Printf.sprintf
"%d" n
696 else Printf.sprintf
"%d,%d,%d" n a
b;
699 let columns_of_string s
=
701 (int_of_string s
, 0, 0)
703 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
707 let len = String.length s
in
709 let b = Buffer.create
n in
710 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
711 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
712 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
713 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
714 Buffer.add_string
b s
;
715 let s'
= Buffer.contents
b in
716 let n'
= Unix.write fd
s'
0 n in
717 if n'
!= n then failwith
"write failed";
722 let n = Unix.read fd
s 0 4 in
723 if n != 4 then failwith
"incomplete read(len)";
725 lor (Char.code
s.[0] lsl 24)
726 lor (Char.code
s.[1] lsl 16)
727 lor (Char.code
s.[2] lsl 8)
728 lor (Char.code
s.[3] lsl 0)
730 let s = String.create
len in
731 let n = Unix.read fd
s 0 len in
732 if n != len then failwith
"incomplete read(data)";
737 let b = Buffer.create
10 in
738 Buffer.add_string
b s;
739 let rec combine = function
742 Buffer.add_char
b ' '
;
745 | `
b b -> if b then "1" else "0"
747 | `i i
-> string_of_int i
748 | `f f
-> string_of_float f
749 | `I f
-> string_of_int
(truncate f
)
751 Buffer.add_string
b s;
758 let cmd = Buffer.contents
(makecmd s l
) in
759 writecmd state.sw
cmd;
765 let d = conf.winh
- h
in
772 let rec f pn ph pi fh l
=
774 | (n, _
, h
, _
) :: rest
->
775 let ips = calcips h
in
780 if isbirdseye state.mode
&& pn
= 0
785 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
790 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
794 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
797 let fh = f 0 0 0 0 state.pdims
in
802 match conf.columns
with
803 | None
-> calcheight ()
805 if Array.length
b > 0
807 let (_
, _
, y
, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
812 let getpageyh pageno
=
813 let rec f pn ph pi y l
=
815 | (n, _
, h
, _
) :: rest
->
816 let ips = calcips h
in
819 let h = if n = pageno
then h else ph
in
820 if conf.presentation
&& n = pageno
822 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
824 y
+ (pageno
- pn
) * (ph
+ pi
), h
826 let y = y + (if conf.presentation
then pi
else 0) in
827 let y = y + (n - pn
) * (ph
+ pi
) in
831 y + (pageno
- pn
) * (ph
+ pi
), ph
833 f 0 0 0 0 state.pdims
836 let getpageyh pageno
=
837 match conf.columns
with
838 | None
-> getpageyh pageno
840 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
844 let getpagedim pageno
=
847 | (n, _
, _
, _
) as pdim
:: rest
->
849 then (if n = pageno
then pdim
else ppdim
)
854 f (-1, -1, -1, -1) state.pdims
857 let getpagey pageno
= fst
(getpageyh pageno
);;
860 let sh = sh - state.hscrollh
in
861 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
862 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
864 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
865 let ips = calcips h in
867 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
871 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
873 prev
, pdims
, pdimno
, 0
875 let dy = dy + yinc in
876 let py = py + yinc in
877 if pageno
= state.pagecount
|| dy >= sh
882 if py + h <= vy - yinc
884 let py = py + h + ips in
885 let dy = max
0 (py - y) in
894 let pagey = vy - py in
895 let pagevh = h - pagey in
896 let pagevh = min
(sh - dy) pagevh in
897 let off = if yinc > 0 then py - vy else 0 in
898 let py = py + h + ips in
901 if state.w
< conf.winw
- state.scrollw
902 then (conf.winw
- state.scrollw
- state.w
) / 2
905 let dispx = xoff + state.x
in
911 let lw = w
- pagex in
912 min
lw (conf.winw
- state.scrollw
)
920 ; pagey = pagey + off
922 ; pagevh = pagevh - off
924 ; pagedispy
= dy + off
927 let accu = e :: accu in
936 if state.invalidated
= 0
954 let layoutN ((columns
, coverA
, coverB
), b) y sh =
955 let sh = sh - state.hscrollh
in
956 let rec fold accu n =
957 if n = Array.length
b
960 let pdimno, dx
, vy, (_
, w
, h, xoff) = b.(n) in
963 || n = state.pagecount
- coverB
964 || (n - coverA
) mod columns
= columns
- 1)
970 let pagey = max
0 (y - vy) in
971 let pagedispy = if pagey > 0 then 0 else vy - y in
972 let pagedispx, pagex, pagevw =
974 if n = coverA
- 1 || n = state.pagecount
- coverB
975 then state.x
+ (conf.winw
- state.scrollw
- w
) / 2
976 else dx
+ xoff + state.x
979 then 0, -pdx, w
+ pdx
980 else pdx, 0, min
(conf.winw
- state.scrollw
) w
982 let pagevh = min
(h - pagey) (sh - pagedispy) in
983 if pagedispx < conf.winw
- state.scrollw
&& pagevw > 0 && pagevh > 0
994 ; pagedispx = pagedispx
995 ; pagedispy = pagedispy
1006 if state.invalidated
= 0
1007 then List.rev
(fold [] 0)
1012 match conf.columns
with
1013 | None
-> layout1 y sh
1014 | Some
c -> layoutN c y sh
1018 let y = state.y + incr
in
1020 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1024 let getopaque pageno
=
1025 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
1026 with Not_found
-> None
1029 let putopaque pageno opaque
=
1030 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
1034 let tilex = l
.pagex mod conf.tilew
in
1035 let tiley = l
.pagey mod conf.tileh
in
1037 let col = l
.pagex / conf.tilew
in
1038 let row = l
.pagey / conf.tileh
in
1041 let a = l
.pagew
- l
.pagex in
1042 let b = conf.winw
- state.scrollw
in
1044 and vh
= l
.pagevh in
1046 let rec rowloop row y0 dispy
h =
1050 let dh = conf.tileh
- y0
in
1051 let dh = min
h dh in
1052 let rec colloop col x0
dispx w
=
1056 let dw = conf.tilew
- x0
in
1057 let dw = min w
dw in
1059 f col row dispx dispy x0 y0
dw dh;
1060 colloop (col+1) 0 (dispx+dw) (w
-dw)
1063 colloop col tilex l
.pagedispx vw;
1064 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1068 then rowloop row tiley l
.pagedispy vh
;
1071 let gettileopaque l
col row =
1073 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1075 try Some
(Hashtbl.find
state.tilemap
key)
1076 with Not_found
-> None
1079 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1080 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1081 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1084 let drawtiles l color
=
1086 let f col row x
y tilex tiley w
h =
1087 match gettileopaque l
col row with
1088 | Some
(opaque
, _
, t
) ->
1089 let params = x
, y, w
, h, tilex, tiley in
1093 GlFunc.blend_func `zero `one_minus_src_color
;
1095 drawtile
params opaque
;
1097 then Gl.disable `blend
;
1100 let s = Printf.sprintf
1104 let w = measurestr
fstate.fontsize
s in
1105 GlMisc.push_attrib
[`current
];
1106 GlDraw.color
(0.0, 0.0, 0.0);
1108 (float (x
-2), float (y-2))
1109 (float (x
+2) +. w, float (y + fstate.fontsize
+ 2));
1110 GlDraw.color
(1.0, 1.0, 1.0);
1111 drawstring fstate.fontsize x
(y + fstate.fontsize
- 1) s;
1112 GlMisc.pop_attrib
();
1117 let lw = conf.winw
- state.scrollw
- x
in
1120 let lh = conf.winh
- y in
1123 Gl.enable `texture_2d
;
1124 begin match state.texid
with
1126 GlTex.bind_texture `texture_2d id
;
1129 and x1
= float (x
+w)
1130 and y1
= float (y+h) in
1132 let tw = float w /. 64.0
1133 and th
= float h /. 64.0 in
1134 let tx0 = float tilex /. 64.0
1135 and ty0
= float tiley /. 64.0 in
1137 and ty1
= ty0
+. th
in
1138 GlDraw.begins `quads
;
1139 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
1140 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
1141 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
1142 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
1145 Gl.disable `texture_2d
;
1147 GlDraw.color
(1.0, 1.0, 1.0);
1150 (float (x
+w), float (y+h));
1152 if w > 128 && h > fstate.fontsize
+ 10
1154 GlDraw.color
(0.0, 0.0, 0.0);
1157 then (col*conf.tilew
, row*conf.tileh
)
1160 drawstring2 fstate.fontsize x
y "Loading %d [%d,%d]" l
.pageno
c r
;
1167 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1169 let tilevisible1 l x
y =
1171 and ax1
= l
.pagex + l
.pagevw
1173 and ay1
= l
.pagey + l
.pagevh in
1177 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1178 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1180 let rx0 = max
ax0 bx0
1181 and ry0
= max ay0 by0
1182 and rx1
= min ax1
bx1
1183 and ry1
= min ay1 by1
in
1185 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1186 nonemptyintersection
1189 let tilevisible layout n x
y =
1190 let rec findpageinlayout = function
1191 | l
:: _
when l
.pageno
= n -> tilevisible1 l x
y
1192 | _
:: rest
-> findpageinlayout rest
1195 findpageinlayout layout
1198 let tileready l x
y =
1199 tilevisible1 l x
y &&
1200 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
1203 let tilepage n p
layout =
1204 let rec loop = function
1208 let f col row _ _ _ _ _ _
=
1209 if state.currently
= Idle
1211 match gettileopaque l
col row with
1214 let x = col*conf.tilew
1215 and y = row*conf.tileh
in
1217 let w = l
.pagew
- x in
1221 let h = l
.pageh
- y in
1233 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1234 conf.tilew
, conf.tileh
1243 if state.invalidated
= 0 then loop layout;
1246 let preloadlayout visiblepages
=
1247 let presentation = conf.presentation in
1248 let interpagespace = conf.interpagespace in
1249 let maxy = state.maxy in
1250 conf.presentation <- false;
1251 conf.interpagespace <- 0;
1252 state.maxy <- calcheight ();
1254 match visiblepages
with
1256 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1258 let y = if y < conf.winh
then 0 else y - conf.winh
in
1259 let h = state.y - y + conf.winh
*3 in
1260 let pages = layout y h in
1261 conf.presentation <- presentation;
1262 conf.interpagespace <- interpagespace;
1268 let rec loop pages =
1269 if state.currently
!= Idle
1274 begin match getopaque l
.pageno
with
1276 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1277 state.currently
<- Loading
(l
, state.gen
);
1279 tilepage l
.pageno opaque
pages;
1284 if state.invalidated
= 0 then loop pages
1289 if conf.preload && state.currently
= Idle
1290 then load (preloadlayout pages);
1293 let layoutready layout =
1294 let rec fold all ls
=
1295 all
&& match ls
with
1297 let seen = ref false in
1298 let allvisible = ref true in
1299 let foo col row _ _ _ _ _ _
=
1301 allvisible := !allvisible &&
1302 begin match gettileopaque l
col row with
1308 fold (!seen && !allvisible) rest
1311 let alltilesvisible = fold true layout in
1316 let y = bound y 0 state.maxy in
1317 let y, layout, proceed
=
1318 match conf.maxwait
with
1319 | Some time
when state.ghyll
== noghyll ->
1320 begin match state.throttle
with
1322 let layout = layout y conf.winh
in
1323 let ready = layoutready layout in
1327 state.throttle
<- Some
(layout, y, now ());
1329 else G.postRedisplay "gotoy showall (None)";
1331 | Some
(_
, _
, started
) ->
1332 let dt = now () -. started
in
1335 state.throttle
<- None
;
1336 let layout = layout y conf.winh
in
1338 G.postRedisplay "maxwait";
1345 let layout = layout y conf.winh
in
1346 if true || layoutready layout
1347 then G.postRedisplay "gotoy ready";
1353 state.layout <- layout;
1354 begin match state.mode
with
1355 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1356 if not
(pagevisible layout pageno
)
1358 match state.layout with
1361 state.mode
<- Birdseye
(
1362 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1369 state.ghyll
<- noghyll;
1372 let conttiling pageno opaque
=
1373 tilepage pageno opaque
1374 (if conf.preload then preloadlayout state.layout else state.layout)
1377 let gotoy_and_clear_text y =
1379 if not
conf.verbose
then state.text <- "";
1383 match state.layout with
1385 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1388 let getanchory (n, top
) =
1389 let y, h = getpageyh n in
1390 y + (truncate
(top
*. float h));
1393 let gotoanchor anchor
=
1394 gotoy (getanchory anchor
);
1398 cbput state.hists
.nav
(getanchor ());
1402 let anchor = cbgetc state.hists
.nav dir
in
1407 let rec scroll f n a b =
1408 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1410 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1412 then s (float f /. float a)
1415 then 1.0 -. s ((float (f-b) /. float (n-b)))
1422 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1423 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1425 let ins = float a *. iv1
1426 and outs
= float (n-b) *. iv1 in
1428 ins +. outs
+. float ones
1430 let rec set (_N
, _A
, _B
) y sy
=
1431 let sum = summa
1.0 _N _A _B
in
1432 let dy = float (y - sy
) in
1436 then state.ghyll
<- noghyll
1439 let s = scroll n _N _A _B
in
1440 let y1 = y1 +. ((s *. dy) /. sum) in
1441 gotoy_and_clear_text (truncate
y1);
1442 state.ghyll
<- gf (n+1) y1;
1446 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1448 gf 0 (float state.y)
1451 match conf.ghyllscroll
with
1453 gotoy_and_clear_text y
1455 if state.ghyll
== noghyll
1456 then set nab
y state.y
1457 else state.ghyll
(Some
y)
1460 let gotopage n top
=
1461 let y, h = getpageyh n in
1462 let y = y + (truncate
(top
*. float h)) in
1466 let gotopage1 n top
=
1467 let y = getpagey n in
1477 state.invalidated
<- state.invalidated
+ 1;
1480 let writeopen path password
=
1481 writecmd state.sw
("open " ^ path ^
"\000" ^ password ^
"\000");
1484 let opendoc path password
=
1487 state.password
<- password
;
1488 state.gen
<- state.gen
+ 1;
1489 state.docinfo
<- [];
1491 setaalevel
conf.aalevel
;
1492 writeopen path password
;
1493 Wsi.settitle
("llpp " ^
Filename.basename path
);
1494 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1498 let c = c *. conf.colorscale
in
1502 let scalecolor2 (r
, g
, b) =
1503 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1507 let docolumns = function
1509 | Some
((columns
, coverA
, coverB
), _
) ->
1510 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1511 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1512 if pageno
= state.pagecount
1515 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1517 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1518 pdimno+1, pdim
, rest
1523 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1525 (conf.winw
- state.scrollw
- w) / 2,
1526 y + rowh
+ conf.interpagespace, h
1529 if (pageno
- coverA
) mod columns
= 0
1530 then 0, y + rowh
+ conf.interpagespace, h
1531 else x, y, max rowh
h
1534 let rec fixrow m
= if m
= pageno
then () else
1535 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1538 let y = y + (rowh
- h) / 2 in
1539 a.(m
) <- (pdimno, x, y, pdim
);
1543 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1544 then fixrow (pageno
- columns
);
1545 a.(pageno
) <- (pdimno, x, y, pdim
);
1546 let x = x + w + xoff*2 + conf.interpagespace in
1547 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1549 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1550 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1552 docolumns conf.columns
;
1553 state.maxy <- calcheight ();
1555 if state.w <= conf.winw
- state.scrollw
1559 match state.mode
with
1560 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1561 let y, h = getpageyh pageno
in
1562 let top = (conf.winh
- h) / 2 in
1563 gotoy (max
0 (y - top))
1564 | _
-> gotoanchor state.anchor
1568 let firsttime = ref true in
1570 GlDraw.viewport
0 0 w h;
1571 if state.invalidated
= 0 && not
!firsttime
1572 then state.anchor <- getanchor ();
1576 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1580 setfontsize fstate.fontsize
;
1581 GlMat.mode `modelview
;
1582 GlMat.load_identity
();
1584 GlMat.mode `projection
;
1585 GlMat.load_identity
();
1586 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1587 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1588 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1591 match conf.columns
with
1593 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1596 wcmd "geometry" [`i
w; `i
h];
1600 let len = String.length
state.text in
1603 match state.mode
with
1604 | View
-> state.hscrollh
1609 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1610 (x+.w, float (conf.winh
- hscrollh))
1613 let w = float (conf.winw
- state.scrollw
- 1) in
1614 if state.progress
>= 0.0 && state.progress
< 1.0
1616 GlDraw.color
(0.3, 0.3, 0.3);
1617 let w1 = w *. state.progress
in
1619 GlDraw.color
(0.0, 0.0, 0.0);
1623 GlDraw.color
(0.0, 0.0, 0.0);
1627 GlDraw.color
(1.0, 1.0, 1.0);
1628 drawstring fstate.fontsize
1629 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1632 match state.mode
with
1633 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1637 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1639 Printf.sprintf
"%s%s_" prefix
text
1648 if not
(istextentry state.mode
)
1650 let s1 = "(press 'e' to review error messasges)" in
1651 if String.length
s > 0 then s ^
" " ^
s1 else s1
1656 if String.length
s > 0
1661 state.text <- Printf.sprintf
"%c%s" c s;
1662 G.postRedisplay "showtext";
1666 let len = Queue.length
state.tilelru
in
1668 if state.memused
<= conf.memlimit
1673 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1674 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1675 let (_
, pw
, ph
, _
) = getpagedim n in
1678 && colorspace
= conf.colorspace
1679 && angle
= conf.angle
1684 match state.throttle
with
1687 then preloadlayout state.layout
1689 | Some
(layout, _
, _
) ->
1692 let x = col*conf.tilew
1693 and y = row*conf.tileh
in
1694 tilevisible layout n x y
1696 then Queue.push lruitem
state.tilelru
1698 wcmd "freetile" [`
s p
];
1699 state.memused
<- state.memused
- s;
1700 state.uioh#infochanged Memused
;
1701 Hashtbl.remove
state.tilemap k
;
1710 Queue.iter
(fun (k
, p
, s) ->
1711 wcmd "freetile" [`
s p
];
1712 state.memused
<- state.memused
- s;
1713 state.uioh#infochanged Memused
;
1714 Hashtbl.remove
state.tilemap k
;
1716 Queue.clear
state.tilelru
;
1720 let logcurrently = function
1721 | Idle
-> dolog "Idle"
1722 | Loading
(l
, gen
) ->
1723 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1724 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1726 "Tiling %d[%d,%d] page=%s cs=%s angle"
1727 l
.pageno
col row pageopaque
1728 (colorspace_to_string colorspace
)
1730 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1731 angle gen
conf.angle
state.gen
1733 conf.tilew
conf.tileh
1740 (* dolog "%S" cmds; *)
1743 try String.index cmds ' '
1744 with Not_found
-> -1
1749 let l = String.length cmds
in
1750 let op = String.sub cmds
0 spacepos in
1752 if l - spacepos < 2 then ""
1753 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1758 state.uioh#infochanged Pdim
;
1762 state.rects
<- state.rects1
;
1763 G.postRedisplay "clearrects";
1767 try Scanf.sscanf
args "%u" (fun n -> n)
1769 dolog "error processing 'continue' %S: %s"
1770 cmds
(Printexc.to_string exn
);
1773 state.pagecount
<- n;
1774 state.invalidated
<- state.invalidated
- 1;
1775 begin match state.currently
with
1777 state.currently
<- Idle
;
1778 state.outlines
<- Array.of_list
(List.rev
l)
1781 if state.invalidated
= 0
1783 if conf.maxwait
= None
1784 then G.postRedisplay "continue";
1794 then showtext ' '
args
1797 let progress, text =
1799 Scanf.sscanf
args "%f %n"
1801 f, String.sub
args pos
(String.length
args - pos
))
1803 dolog "error processing 'progress' %S: %s"
1804 cmds
(Printexc.to_string exn
);
1808 state.progress <- progress;
1809 G.postRedisplay "progress"
1812 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1814 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1815 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1816 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1818 dolog "error processing 'firstmatch' %S: %s"
1819 cmds
(Printexc.to_string exn
);
1822 let y = (getpagey pageno) + truncate y0
in
1825 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)]
1828 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1830 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1831 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1832 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1834 dolog "error processing 'match' %S: %s"
1835 cmds
(Printexc.to_string exn
);
1839 (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) :: state.rects1
1844 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
1846 dolog "error processing 'page' %S: %s"
1847 cmds
(Printexc.to_string exn
);
1850 begin match state.currently
with
1851 | Loading
(l, gen
) ->
1852 vlog "page %d took %f sec" l.pageno t
;
1853 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1854 begin match state.throttle
with
1856 let preloadedpages =
1858 then preloadlayout state.layout
1863 Set.Make
(struct type t
= int let compare = (-) end) in
1865 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1866 IntSet.empty
preloadedpages
1869 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
1870 if not
(IntSet.mem
pageno set)
1872 wcmd "freepage" [`
s opaque
];
1878 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1881 state.currently
<- Idle
;
1884 tilepage l.pageno pageopaque state.layout;
1886 load preloadedpages;
1887 if pagevisible state.layout l.pageno
1888 && layoutready state.layout
1889 then G.postRedisplay "page";
1892 | Some
(layout, _
, _
) ->
1893 state.currently
<- Idle
;
1894 tilepage l.pageno pageopaque layout;
1899 dolog "Inconsistent loading state";
1900 logcurrently state.currently
;
1905 let (x, y, opaque
, size
, t
) =
1907 Scanf.sscanf
args "%u %u %s %u %f"
1908 (fun x y p size t
-> (x, y, p
, size
, t
))
1910 dolog "error processing 'tile' %S: %s"
1911 cmds
(Printexc.to_string exn
);
1914 begin match state.currently
with
1915 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1916 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1918 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1920 wcmd "freetile" [`
s opaque
];
1921 state.currently
<- Idle
;
1925 puttileopaque l col row gen cs angle opaque size t
;
1926 state.memused
<- state.memused
+ size
;
1927 state.uioh#infochanged Memused
;
1929 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1930 opaque
, size
) state.tilelru
;
1933 match state.throttle
with
1934 | None
-> state.layout
1935 | Some
(layout, _
, _
) -> layout
1938 state.currently
<- Idle
;
1940 && conf.colorspace
= cs
1941 && conf.angle
= angle
1942 && tilevisible layout l.pageno x y
1943 then conttiling l.pageno pageopaque;
1945 begin match state.throttle
with
1947 preload state.layout;
1949 && conf.colorspace
= cs
1950 && conf.angle
= angle
1951 && tilevisible state.layout l.pageno x y
1952 then G.postRedisplay "tile nothrottle";
1954 | Some
(layout, y, _
) ->
1955 let ready = layoutready layout in
1959 state.layout <- layout;
1960 state.throttle
<- None
;
1961 G.postRedisplay "throttle";
1968 dolog "Inconsistent tiling state";
1969 logcurrently state.currently
;
1976 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
1978 dolog "error processing 'pdim' %S: %s"
1979 cmds
(Printexc.to_string exn
);
1982 state.uioh#infochanged Pdim
;
1983 state.pdims
<- pdim :: state.pdims
1986 let (l, n, t
, h, pos
) =
1988 Scanf.sscanf
args "%u %u %d %u %n"
1989 (fun l n t
h pos
-> l, n, t
, h, pos
)
1991 dolog "error processing 'o' %S: %s"
1992 cmds
(Printexc.to_string exn
);
1995 let s = String.sub
args pos
(String.length
args - pos
) in
1996 let outline = (s, l, (n, float t
/. float h)) in
1997 begin match state.currently
with
1998 | Outlining outlines
->
1999 state.currently
<- Outlining
(outline :: outlines
)
2001 state.currently
<- Outlining
[outline]
2003 dolog "invalid outlining state";
2004 logcurrently currently
2008 state.docinfo
<- (1, args) :: state.docinfo
2011 state.uioh#infochanged Docinfo
;
2012 state.docinfo
<- List.rev
state.docinfo
2015 dolog "unknown cmd `%S'" cmds
2020 let action = function
2021 | HCprev
-> cbget cb ~
-1
2022 | HCnext
-> cbget cb
1
2023 | HCfirst
-> cbget cb ~
-(cb
.rc)
2024 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2025 and cancel
() = cb
.rc <- rc
2029 let search pattern forward
=
2030 if String.length pattern
> 0
2033 match state.layout with
2036 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2039 let b = makecmd "search"
2040 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
2042 Buffer.add_char
b '
,'
;
2043 Buffer.add_string
b pattern
;
2044 Buffer.add_char
b '
\000'
;
2047 writecmd state.sw
cmd;
2050 let intentry text key =
2052 if key >= 32 && key < 127
2058 let text = addchar text c in
2062 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2066 let textentry text key =
2067 if key land 0xff00 = 0xff00
2069 else TEcont
(text ^
Wsi.toutf8
key)
2072 let reqlayout angle proportional
=
2073 match state.throttle
with
2075 if state.invalidated
= 0 then state.anchor <- getanchor ();
2076 conf.angle
<- angle
mod 360;
2077 conf.proportional
<- proportional
;
2079 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
2083 let settrim trimmargins trimfuzz
=
2084 if state.invalidated
= 0 then state.anchor <- getanchor ();
2085 conf.trimmargins
<- trimmargins
;
2086 conf.trimfuzz
<- trimfuzz
;
2087 let x0, y0
, x1
, y1 = trimfuzz
in
2090 `
b conf.trimmargins
;
2096 Hashtbl.iter
(fun _ opaque
->
2097 wcmd "freepage" [`
s opaque
];
2099 Hashtbl.clear
state.pagemap
;
2103 match state.throttle
with
2105 let zoom = max
0.01 zoom in
2106 if zoom <> conf.zoom
2108 state.prevzoom
<- conf.zoom;
2111 then (state.x <- 0; 0.0)
2112 else float state.x /. float state.w
2115 reshape conf.winw
conf.winh
;
2118 let x = relx *. float state.w in
2119 state.x <- truncate
x;
2121 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2124 | Some
(layout, y, started
) ->
2126 match conf.maxwait
with
2130 let dt = now () -. started
in
2138 let setcolumns columns coverA coverB
=
2141 conf.columns
<- None
;
2146 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2149 reshape conf.winw
conf.winh
;
2152 let enterbirdseye () =
2153 let zoom = float conf.thumbw
/. float conf.winw
in
2154 let birdseyepageno =
2155 let cy = conf.winh
/ 2 in
2159 let rec fold best
= function
2162 let d = cy - (l.pagedispy + l.pagevh/2)
2163 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2164 if abs
d < abs dbest
2171 state.mode
<- Birdseye
(
2172 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2175 conf.presentation <- false;
2176 conf.interpagespace <- 10;
2177 conf.hlinks
<- false;
2179 state.mstate
<- Mnone
;
2180 conf.maxwait
<- None
;
2182 match conf.beyecolumns
with
2185 Some
((c, 0, 0), [||])
2188 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2191 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2196 reshape conf.winw
conf.winh
;
2199 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2201 conf.zoom <- c.zoom;
2202 conf.presentation <- c.presentation;
2203 conf.interpagespace <- c.interpagespace;
2204 conf.maxwait
<- c.maxwait
;
2205 conf.hlinks
<- c.hlinks
;
2206 conf.beyecolumns
<- (
2207 match conf.columns
with
2208 | Some
((c, _
, _
), _
) -> Some
c
2212 match c.columns
with
2213 | Some
(c, _
) -> Some
(c, [||])
2219 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2222 reshape conf.winw
conf.winh
;
2223 state.anchor <- if goback
then anchor else (pageno, 0.0);
2226 let togglebirdseye () =
2227 match state.mode
with
2228 | Birdseye vals
-> leavebirdseye vals
true
2229 | View
-> enterbirdseye ()
2233 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2234 let pageno = max
0 (pageno - incr
) in
2235 let rec loop = function
2236 | [] -> gotopage1 pageno 0
2237 | l :: _
when l.pageno = pageno ->
2238 if l.pagedispy >= 0 && l.pagey = 0
2239 then G.postRedisplay "upbirdseye"
2240 else gotopage1 pageno 0
2241 | _
:: rest
-> loop rest
2244 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2247 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2248 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2249 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2250 let rec loop = function
2252 let y, h = getpageyh pageno in
2253 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2255 | l :: _
when l.pageno = pageno ->
2256 if l.pagevh != l.pageh
2257 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2258 else G.postRedisplay "downbirdseye"
2259 | _
:: rest
-> loop rest
2264 let optentry mode _
key =
2265 let btos b = if b then "on" else "off" in
2266 if key >= 32 && key < 127
2268 let c = Char.chr
key in
2272 try conf.scrollstep
<- int_of_string
s with exc
->
2273 state.text <- Printf.sprintf
"bad integer `%s': %s"
2274 s (Printexc.to_string exc
)
2276 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2281 conf.autoscrollstep
<- int_of_string
s;
2282 if state.autoscroll
<> None
2283 then state.autoscroll
<- Some
conf.autoscrollstep
2285 state.text <- Printf.sprintf
"bad integer `%s': %s"
2286 s (Printexc.to_string exc
)
2288 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2293 let n, a, b = columns_of_string s in
2296 state.text <- Printf.sprintf
"bad columns `%s': %s"
2297 s (Printexc.to_string exc
)
2299 TEswitch
("columns: ", "", None
, textentry, ondone)
2304 let zoom = float (int_of_string
s) /. 100.0 in
2307 state.text <- Printf.sprintf
"bad integer `%s': %s"
2308 s (Printexc.to_string exc
)
2310 TEswitch
("zoom: ", "", None
, intentry, ondone)
2315 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2317 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2318 begin match mode
with
2320 leavebirdseye beye
false;
2325 state.text <- Printf.sprintf
"bad integer `%s': %s"
2326 s (Printexc.to_string exc
)
2328 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2333 Some
(int_of_string
s)
2335 state.text <- Printf.sprintf
"bad integer `%s': %s"
2336 s (Printexc.to_string exc
);
2339 | Some angle
-> reqlayout angle
conf.proportional
2342 TEswitch
("rotation: ", "", None
, intentry, ondone)
2345 conf.icase
<- not
conf.icase
;
2346 TEdone
("case insensitive search " ^
(btos conf.icase
))
2349 conf.preload <- not
conf.preload;
2351 TEdone
("preload " ^
(btos conf.preload))
2354 conf.verbose
<- not
conf.verbose
;
2355 TEdone
("verbose " ^
(btos conf.verbose
))
2358 conf.debug
<- not
conf.debug
;
2359 TEdone
("debug " ^
(btos conf.debug
))
2362 conf.maxhfit
<- not
conf.maxhfit
;
2364 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2365 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2368 conf.crophack
<- not
conf.crophack
;
2369 TEdone
("crophack " ^
btos conf.crophack
)
2373 match conf.maxwait
with
2375 conf.maxwait
<- Some infinity
;
2376 "always wait for page to complete"
2378 conf.maxwait
<- None
;
2379 "show placeholder if page is not ready"
2384 conf.underinfo
<- not
conf.underinfo
;
2385 TEdone
("underinfo " ^
btos conf.underinfo
)
2388 conf.savebmarks
<- not
conf.savebmarks
;
2389 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2395 match state.layout with
2400 conf.interpagespace <- int_of_string
s;
2401 state.maxy <- calcheight ();
2402 let y = getpagey pageno in
2405 state.text <- Printf.sprintf
"bad integer `%s': %s"
2406 s (Printexc.to_string exc
)
2408 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2411 reqlayout conf.angle
(not
conf.proportional
);
2412 TEdone
("proportional display " ^
btos conf.proportional
)
2415 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2416 TEdone
("trim margins " ^
btos conf.trimmargins
)
2419 conf.invert
<- not
conf.invert
;
2420 TEdone
("invert colors " ^
btos conf.invert
)
2424 cbput state.hists
.sel
s;
2427 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2431 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2437 class type lvsource
= object
2438 method getitemcount
: int
2439 method getitem
: int -> (string * int)
2440 method hasaction
: int -> bool
2449 method getactive
: int
2450 method getfirst
: int
2451 method getqsearch
: string
2452 method setqsearch
: string -> unit
2456 class virtual lvsourcebase
= object
2457 val mutable m_active
= 0
2458 val mutable m_first
= 0
2459 val mutable m_qsearch
= ""
2460 val mutable m_pan
= 0
2461 method getactive
= m_active
2462 method getfirst
= m_first
2463 method getqsearch
= m_qsearch
2464 method getpan
= m_pan
2465 method setqsearch
s = m_qsearch
<- s
2468 let withoutlastutf8 s =
2469 let len = String.length
s in
2477 let b = Char.code
s.[pos
] in
2478 if b land 0b110000 = 0b11000000
2483 if Char.code
s.[len-1] land 0x80 = 0
2487 String.sub
s 0 first;
2490 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2492 state.mode
<- Textentry
(te
, onleave
);
2495 G.postRedisplay "textentrykeyboard enttext";
2497 let histaction cmd =
2500 | Some
(action, _
) ->
2501 state.mode
<- Textentry
(
2502 (c, action cmd, opthist
, onkey
, ondone), onleave
2504 G.postRedisplay "textentry histaction"
2507 | 0xff08 -> (* backspace *)
2508 let s = withoutlastutf8 text in
2509 let len = String.length
s in
2513 G.postRedisplay "textentrykeyboard after cancel";
2516 enttext (c, s, opthist
, onkey
, ondone)
2522 G.postRedisplay "textentrykeyboard after confirm"
2524 | 0xff52 -> histaction HCprev
2525 | 0xff54 -> histaction HCnext
2526 | 0xff50 -> histaction HCfirst
2527 | 0xff57 -> histaction HClast
2529 | 0xff1b -> (* escape*)
2530 if String.length
text = 0
2532 begin match opthist
with
2534 | Some
(_
, onhistcancel
) -> onhistcancel
()
2538 G.postRedisplay "textentrykeyboard after cancel2"
2541 enttext (c, "", opthist
, onkey
, ondone)
2544 | 0xff9f | 0xffff -> () (* delete *)
2546 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2547 begin match onkey
text key with
2551 G.postRedisplay "textentrykeyboard after confirm2";
2554 enttext (c, text, opthist
, onkey
, ondone);
2558 G.postRedisplay "textentrykeyboard after cancel3"
2561 state.mode
<- Textentry
(te
, onleave
);
2562 G.postRedisplay "textentrykeyboard switch";
2566 vlog "unhandled key %#x" key
2569 let firstof first active
=
2570 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2571 then max
0 (active
- (fstate.maxrows
/2))
2575 let calcfirst first active
=
2578 let rows = active
- first in
2579 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2583 let scrollph y maxy =
2584 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2585 let sh = float conf.winh
/. sh in
2586 let sh = max
sh (float conf.scrollh
) in
2591 else float y /. float maxy
2593 let position = (float conf.winh
-. sh) *. percent in
2596 if position +. sh > float conf.winh
2597 then float conf.winh
-. sh
2603 let coe s = (s :> uioh
);;
2605 class listview ~
(source
:lvsource
) ~trusted
=
2607 val m_pan
= source#getpan
2608 val m_first
= source#getfirst
2609 val m_active
= source#getactive
2610 val m_qsearch
= source#getqsearch
2611 val m_prev_uioh
= state.uioh
2613 method private elemunder
y =
2614 let n = y / (fstate.fontsize
+1) in
2615 if m_first
+ n < source#getitemcount
2617 if source#hasaction
(m_first
+ n)
2618 then Some
(m_first
+ n)
2625 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2626 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2627 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2628 GlDraw.color
(1., 1., 1.);
2629 Gl.enable `texture_2d
;
2630 let fs = fstate.fontsize
in
2632 let ww = fstate.wwidth
in
2633 let tabw = 30.0*.ww in
2634 let itemcount = source#getitemcount
in
2636 if (row - m_first
) * nfs > conf.winh
2639 if row >= 0 && row < itemcount
2641 let (s, level
) = source#getitem
row in
2642 let y = (row - m_first
) * nfs in
2643 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2646 Gl.disable `texture_2d
;
2647 GlDraw.polygon_mode `both `line
;
2648 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2649 GlDraw.rect (1., float (y + 1))
2650 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2651 GlDraw.polygon_mode `both `fill
;
2652 GlDraw.color
(1., 1., 1.);
2653 Gl.enable `texture_2d
;
2656 let drawtabularstring s =
2657 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2660 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2663 let len = String.length
s - tabpos - 1 in
2664 let s1 = String.sub
s 0 tabpos
2665 and s2
= String.sub
s (tabpos + 1) len in
2666 let nx = drawstr x s1 in
2668 let x = x +. (max
tabw sw) in
2675 let _ = drawtabularstring s in
2682 Gl.disable `texture_2d
;
2684 method updownlevel incr
=
2685 let len = source#getitemcount
in
2687 if m_active
>= 0 && m_active
< len
2688 then snd
(source#getitem m_active
)
2692 if i
= len then i
-1 else if i
= -1 then 0 else
2693 let _, l = source#getitem i
in
2694 if l != curlevel then i
else flow (i
+incr
)
2696 let active = flow m_active
in
2697 let first = calcfirst m_first
active in
2698 G.postRedisplay "outline updownlevel";
2699 {< m_active
= active; m_first
= first >}
2701 method private key1
key mask
=
2702 let set1 active first qsearch
=
2703 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2705 let search active pattern incr
=
2708 if n >= 0 && n < source#getitemcount
2710 let s, _ = source#getitem
n in
2712 (try ignore
(Str.search_forward
re s 0); true
2713 with Not_found
-> false)
2715 else loop (n + incr
)
2722 let re = Str.regexp_case_fold pattern
in
2728 let itemcount = source#getitemcount
in
2729 let find start incr
=
2731 if i
= -1 || i
= itemcount
2734 if source#hasaction i
2736 else find (i
+ incr
)
2741 let set active first =
2742 let first = bound first 0 (itemcount - fstate.maxrows
) in
2744 coe {< m_active
= active; m_first
= first >}
2747 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2749 let incr1 = if incr
> 0 then 1 else -1 in
2750 if isvisible m_first m_active
2753 let next = m_active
+ incr
in
2755 if next < 0 || next >= itemcount
2757 else find next incr1
2759 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2765 let first = m_first
+ incr
in
2766 let first = bound first 0 (itemcount - 1) in
2768 let next = m_active
+ incr
in
2769 let next = bound next 0 (itemcount - 1) in
2772 let active = if next = -1 then m_active
else next in
2775 let first = min
next m_first
in
2777 if abs
(next - first) > fstate.maxrows
2783 let first = m_first
+ incr
in
2784 let first = bound first 0 (itemcount - 1) in
2786 let next = m_active
+ incr
in
2787 let next = bound next 0 (itemcount - 1) in
2788 let next = find next incr1 in
2790 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2792 let active = if m_active
= -1 then next else m_active
in
2797 if isvisible first active
2803 G.postRedisplay "listview navigate";
2807 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
2808 let incr = if key = 0x72 then -1 else 1 in
2810 match search (m_active
+ incr) m_qsearch
incr with
2812 state.text <- m_qsearch ^
" [not found]";
2815 state.text <- m_qsearch
;
2816 active, firstof m_first
active
2818 G.postRedisplay "listview ctrl-r/s";
2819 set1 active first m_qsearch
;
2821 | 0xff08 -> (* backspace *)
2822 if String.length m_qsearch
= 0
2825 let qsearch = withoutlastutf8 m_qsearch
in
2826 let len = String.length
qsearch in
2830 G.postRedisplay "listview empty qsearch";
2831 set1 m_active m_first
"";
2835 match search m_active
qsearch ~
-1 with
2837 state.text <- qsearch ^
" [not found]";
2840 state.text <- qsearch;
2841 active, firstof m_first
active
2843 G.postRedisplay "listview backspace qsearch";
2844 set1 active first qsearch
2847 | key when ((key >= 32 && key < 127)
2848 || (key != 0 && key land 0xff00 != 0xff00)) ->
2850 if key >= 32 && key < 127
2851 then addchar m_qsearch
(Char.chr
key)
2852 else m_qsearch ^
Wsi.toutf8
key
2855 match search m_active
pattern 1 with
2857 state.text <- pattern ^
" [not found]";
2860 state.text <- pattern;
2861 active, firstof m_first
active
2863 G.postRedisplay "listview qsearch add";
2864 set1 active first pattern;
2866 | 0xff1b -> (* escape *)
2868 if String.length m_qsearch
= 0
2870 G.postRedisplay "list view escape";
2873 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2875 | None
-> m_prev_uioh
2880 G.postRedisplay "list view kill qsearch";
2881 source#setqsearch
"";
2882 coe {< m_qsearch
= "" >}
2885 | 0xff0d -> (* return *)
2887 let self = {< m_qsearch
= "" >} in
2888 source#setqsearch
"";
2890 G.postRedisplay "listview enter";
2891 if m_active
>= 0 && m_active
< source#getitemcount
2893 source#exit
(coe self) false m_active m_first m_pan
"";
2896 source#exit
(coe self) true m_active m_first m_pan
"";
2899 begin match opt with
2900 | None
-> m_prev_uioh
2904 | 0xff9f | 0xffff -> (* delete *)
2907 | 0xff52 -> navigate ~
-1 (* up *)
2908 | 0xff54 -> navigate 1 (* down *)
2909 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
2910 | 0xff56 -> navigate fstate.maxrows
(* next *)
2912 | 0xff53 -> (* right *)
2914 G.postRedisplay "listview right";
2915 coe {< m_pan
= m_pan
- 1 >}
2917 | 0xff51 -> (* left *)
2919 G.postRedisplay "listview left";
2920 coe {< m_pan
= m_pan
+ 1 >}
2922 | 0xff50 -> (* home *)
2923 let active = find 0 1 in
2924 G.postRedisplay "listview home";
2927 | 0xff57 -> (* end *)
2928 let first = max
0 (itemcount - fstate.maxrows
) in
2929 let active = find (itemcount - 1) ~
-1 in
2930 G.postRedisplay "listview end";
2933 | key when (key = 0 || key land 0xff00 = 0xff00) ->
2937 dolog "listview unknown key %#x" key; coe self
2939 method key key mask
=
2940 match state.mode
with
2941 | Textentry te
-> textentrykeyboard key mask te
; coe self
2942 | _ -> self#key1
key mask
2944 method button button down
x y _ =
2947 | 1 when x > conf.winw
- conf.scrollbw
->
2948 G.postRedisplay "listview scroll";
2951 let _, position, sh = self#
scrollph in
2952 if y > truncate
position && y < truncate
(position +. sh)
2954 state.mstate
<- Mscrolly
;
2958 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2959 let first = truncate
(s *. float source#getitemcount
) in
2960 let first = min source#getitemcount
first in
2961 Some
(coe {< m_first
= first; m_active
= first >})
2963 state.mstate
<- Mnone
;
2966 | 1 when not down
->
2967 begin match self#elemunder
y with
2969 G.postRedisplay "listview click";
2971 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
2975 | n when (n == 4 || n == 5) && not down
->
2976 let len = source#getitemcount
in
2978 if n = 5 && m_first
+ fstate.maxrows
>= len
2982 let first = m_first
+ (if n == 3 then -1 else 1) in
2983 bound first 0 (len - 1)
2985 G.postRedisplay "listview wheel";
2986 Some
(coe {< m_first
= first >})
2991 | None
-> m_prev_uioh
2995 match state.mstate
with
2997 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2998 let first = truncate
(s *. float source#getitemcount
) in
2999 let first = min source#getitemcount
first in
3000 G.postRedisplay "listview motion";
3001 coe {< m_first
= first; m_active
= first >}
3004 method pmotion
x y =
3005 if x < conf.winw
- conf.scrollbw
3008 match self#elemunder
y with
3009 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3010 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3014 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3019 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3023 method infochanged
_ = ()
3025 method scrollpw
= (0, 0.0, 0.0)
3027 let nfs = fstate.fontsize
+ 1 in
3028 let y = m_first
* nfs in
3029 let itemcount = source#getitemcount
in
3030 let maxi = max
0 (itemcount - fstate.maxrows
) in
3031 let maxy = maxi * nfs in
3032 let p, h = scrollph y maxy in
3036 class outlinelistview ~source
=
3038 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
3040 method key key mask
=
3041 let calcfirst first active =
3044 let rows = active - first in
3045 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3049 let active = m_active
+ incr in
3050 let active = bound active 0 (source#getitemcount
- 1) in
3051 let first = calcfirst m_first
active in
3052 G.postRedisplay "outline navigate";
3053 coe {< m_active
= active; m_first
= first >}
3056 | 110 when Wsi.withctrl mask
-> (* ctrl-n *)
3057 source#narrow m_qsearch
;
3058 G.postRedisplay "outline ctrl-n";
3059 coe {< m_first
= 0; m_active
= 0 >}
3061 | 117 when Wsi.withctrl mask
-> (* ctrl-u *)
3063 G.postRedisplay "outline ctrl-u";
3065 coe {< m_first
= 0; m_active
= 0 >}
3067 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
3068 let first = m_active
- (fstate.maxrows
/ 2) in
3069 G.postRedisplay "outline ctrl-l";
3070 coe {< m_first
= first >}
3072 | 0xff9f | 0xffff -> (* delete *)
3073 source#remove m_active
;
3074 G.postRedisplay "outline delete";
3075 let active = max
0 (m_active
-1) in
3076 coe {< m_first
= firstof m_first
active;
3077 m_active
= active >}
3079 | 0xff52 -> navigate ~
-1 (* up *)
3080 | 0xff54 -> navigate 1 (* down *)
3081 | 0xff55 -> (* prior *)
3082 navigate ~
-(fstate.maxrows
)
3083 | 0xff56 -> (* next *)
3084 navigate fstate.maxrows
3086 | 0xff53 -> (* [ctrl-]right *)
3088 if Wsi.withctrl mask
3090 G.postRedisplay "outline ctrl right";
3091 {< m_pan
= m_pan
+ 1 >}
3093 else self#updownlevel
1
3097 | 0xff51 -> (* [ctrl-]left *)
3099 if Wsi.withctrl mask
3101 G.postRedisplay "outline ctrl left";
3102 {< m_pan
= m_pan
- 1 >}
3104 else self#updownlevel ~
-1
3108 | 0xff50 -> (* home *)
3109 G.postRedisplay "outline home";
3110 coe {< m_first
= 0; m_active
= 0 >}
3112 | 0xff57 -> (* end *)
3113 let active = source#getitemcount
- 1 in
3114 let first = max
0 (active - fstate.maxrows
) in
3115 G.postRedisplay "outline end";
3116 coe {< m_active
= active; m_first
= first >}
3118 | _ -> super#
key key mask
3121 let outlinesource usebookmarks
=
3124 inherit lvsourcebase
3125 val mutable m_items
= empty
3126 val mutable m_orig_items
= empty
3127 val mutable m_prev_items
= empty
3128 val mutable m_narrow_pattern
= ""
3129 val mutable m_hadremovals
= false
3131 method getitemcount
=
3132 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3135 if n == Array.length m_items
&& m_hadremovals
3137 ("[Confirm removal]", 0)
3139 let s, n, _ = m_items
.(n) in
3142 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3143 ignore
(uioh
, first, qsearch);
3144 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3146 if String.length m_narrow_pattern
= 0
3152 if not
confrimremoval
3154 let _, _, anchor = m_items
.(active) in
3159 state.bookmarks
<- Array.to_list m_items
;
3160 m_orig_items
<- m_items
;
3163 else m_items
<- items;
3167 method hasaction
_ = true
3170 if Array.length m_items
!= Array.length m_orig_items
3171 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3174 method narrow
pattern =
3175 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3179 let rec loop accu n =
3182 m_narrow_pattern
<- pattern;
3183 m_items
<- Array.of_list
accu
3186 let (s, _, _) as o = m_items
.(n) in
3188 if (try ignore
(Str.search_forward
re s 0); true
3189 with Not_found
-> false)
3195 loop [] (Array.length m_items
- 1)
3200 then Array.of_list
state.bookmarks
3203 m_items
<- m_orig_items
3208 if m
>= 0 && m
< Array.length m_items
3210 m_hadremovals
<- true;
3211 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3212 let n = if n >= m
then n+1 else n in
3217 method reset
anchor items =
3218 m_hadremovals
<- false;
3219 if m_orig_items
== empty || m_prev_items
!= items
3221 m_orig_items
<- items;
3222 if String.length m_narrow_pattern
= 0
3223 then m_items
<- items;
3225 m_prev_items
<- items;
3226 let rely = getanchory anchor in
3228 let rec loop n best bestd
=
3229 if n = Array.length m_items
3232 let (_, _, anchor) = m_items
.(n) in
3233 let orely = getanchory anchor in
3234 let d = abs
(orely - rely) in
3237 else loop (n+1) best bestd
3242 m_first
<- firstof m_first
active
3246 let enterselector usebookmarks
=
3247 let source = outlinesource usebookmarks
in
3251 then Array.of_list
state.bookmarks
3254 if Array.length
outlines = 0
3256 showtext ' ' errmsg
;
3259 state.text <- source#greetmsg
;
3260 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3261 let anchor = getanchor () in
3262 source#reset
anchor outlines;
3263 state.uioh
<- coe (new outlinelistview ~
source);
3264 G.postRedisplay "enter selector";
3268 let enteroutlinemode =
3269 let f = enterselector false in
3270 fun ()-> f "Document has no outline";
3273 let enterbookmarkmode =
3274 let f = enterselector true in
3275 fun () -> f "Document has no bookmarks (yet)";
3278 let color_of_string s =
3279 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3280 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3284 let color_to_string (r
, g
, b) =
3285 let r = truncate
(r *. 256.0)
3286 and g
= truncate
(g
*. 256.0)
3287 and b = truncate
(b *. 256.0) in
3288 Printf.sprintf
"%d/%d/%d" r g
b
3291 let irect_of_string s =
3292 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1
y1 -> (x0,y0
,x1
,y1))
3295 let irect_to_string (x0,y0
,x1
,y1) =
3296 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1
y1
3299 let makecheckers () =
3300 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3302 converted by Issac Trotts. July 25, 2002 *)
3303 let image_height = 64
3304 and image_width
= 64 in
3308 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3310 for i
= 0 to image_width
- 1 do
3311 for j
= 0 to image_height - 1 do
3312 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3313 (if (i
land 8 ) lxor (j
land 8) = 0
3314 then [|255;255;255|] else [|200;200;200|])
3319 let image = make_image () in
3320 let id = GlTex.gen_texture
() in
3321 GlTex.bind_texture `texture_2d
id;
3322 GlPix.store
(`unpack_alignment
1);
3323 GlTex.image2d
image;
3324 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3327 `mag_filter `nearest
;
3328 `min_filter `nearest
];
3332 let setcheckers enabled
=
3333 match state.texid
with
3335 if enabled
then state.texid
<- Some
(makecheckers ())
3340 GlTex.delete_texture texid
;
3341 state.texid
<- None
;
3345 let int_of_string_with_suffix s =
3346 let l = String.length
s in
3350 let suffix = Char.lowercase
s.[l-1] in
3352 | 'k'
-> String.sub
s 0 (l-1), 10
3353 | 'm'
-> String.sub
s 0 (l-1), 20
3354 | 'g'
-> String.sub
s 0 (l-1), 30
3358 let n = int_of_string
s1 in
3359 let m = n lsl shift
in
3361 then raise
(Failure
"value too large")
3365 let string_with_suffix_of_int n =
3373 if n land ((1 lsl 20) - 1) = 0
3376 if n land ((1 lsl 10) - 1) = 0
3383 let h = n mod 1000 in
3386 then string_of_int
h ^
s
3388 let s = Printf.sprintf
"_%03d%s" h s in
3395 let defghyllscroll = (40, 8, 32);;
3396 let ghyllscroll_of_string s =
3397 let (n, a, b) as nab
=
3400 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3402 if n <= a || n <= b || a >= b
3403 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3407 let ghyllscroll_to_string ((n, a, b) as nab
) =
3408 if nab
= defghyllscroll
3410 else Printf.sprintf
"%d,%d,%d" n a b;
3413 let describe_location () =
3415 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3417 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3418 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3422 else (100. *. (float state.y /. float maxy))
3426 Printf.sprintf
"page %d of %d [%.2f%%]"
3427 (fn+1) state.pagecount
percent
3430 "pages %d-%d of %d [%.2f%%]"
3431 (fn+1) (ln
+1) state.pagecount
percent
3435 let btos b = if b then "\xe2\x88\x9a" else "" in
3436 let showextended = ref false in
3437 let leave mode
= function
3438 | Confirm
-> state.mode
<- mode
3439 | Cancel
-> state.mode
<- mode
in
3442 val mutable m_first_time
= true
3443 val mutable m_l
= []
3444 val mutable m_a
= [||]
3445 val mutable m_prev_uioh
= nouioh
3446 val mutable m_prev_mode
= View
3448 inherit lvsourcebase
3450 method reset prev_mode prev_uioh
=
3451 m_a
<- Array.of_list
(List.rev m_l
);
3453 m_prev_mode
<- prev_mode
;
3454 m_prev_uioh
<- prev_uioh
;
3458 if n >= Array.length m_a
3462 | _, _, _, Action
_ -> m_active
<- n
3466 m_first_time
<- false;
3469 method int name get
set =
3471 (name
, `
int get
, 1, Action
(
3474 try set (int_of_string
s)
3476 state.text <- Printf.sprintf
"bad integer `%s': %s"
3477 s (Printexc.to_string exn
)
3480 let te = name ^
": ", "", None
, intentry, ondone in
3481 state.mode
<- Textentry
(te, leave m_prev_mode
);
3485 method int_with_suffix name get
set =
3487 (name
, `intws get
, 1, Action
(
3490 try set (int_of_string_with_suffix s)
3492 state.text <- Printf.sprintf
"bad integer `%s': %s"
3493 s (Printexc.to_string exn
)
3497 name ^
": ", "", None
, intentry_with_suffix, ondone
3499 state.mode
<- Textentry
(te, leave m_prev_mode
);
3503 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3505 (name
, `
bool (btos, get
), offset
, Action
(
3512 method color name get
set =
3514 (name
, `color get
, 1, Action
(
3516 let invalid = (nan
, nan
, nan
) in
3519 try color_of_string s
3521 state.text <- Printf.sprintf
"bad color `%s': %s"
3522 s (Printexc.to_string exn
);
3528 let te = name ^
": ", "", None
, textentry, ondone in
3529 state.text <- color_to_string (get
());
3530 state.mode
<- Textentry
(te, leave m_prev_mode
);
3534 method string name get
set =
3536 (name
, `
string get
, 1, Action
(
3538 let ondone s = set s in
3539 let te = name ^
": ", "", None
, textentry, ondone in
3540 state.mode
<- Textentry
(te, leave m_prev_mode
);
3544 method colorspace name get
set =
3546 (name
, `
string get
, 1, Action
(
3549 let vals = [| "rgb"; "bgr"; "gray" |] in
3551 inherit lvsourcebase
3554 m_active
<- int_of_colorspace conf.colorspace
;
3557 method getitemcount
= Array.length
vals
3558 method getitem
n = (vals.(n), 0)
3559 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3560 ignore
(uioh
, first, pan
, qsearch);
3561 if not cancel
then set active;
3563 method hasaction
_ = true
3567 coe (new listview ~
source ~trusted
:true)
3570 method caption
s offset
=
3571 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3573 method caption2
s f offset
=
3574 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3576 method getitemcount
= Array.length m_a
3579 let tostr = function
3580 | `
int f -> string_of_int
(f ())
3581 | `intws
f -> string_with_suffix_of_int (f ())
3583 | `color
f -> color_to_string (f ())
3584 | `
bool (btos, f) -> btos (f ())
3587 let name, t
, offset
, _ = m_a
.(n) in
3588 ((let s = tostr t
in
3589 if String.length
s > 0
3590 then Printf.sprintf
"%s\t%s" name s
3594 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3598 m_qsearch
<- qsearch;
3600 match m_a
.(active) with
3601 | _, _, _, Action
f -> f uioh
3613 method hasaction
n =
3615 | _, _, _, Action
_ -> true
3619 let rec fillsrc prevmode prevuioh
=
3620 let sep () = src#caption
"" 0 in
3621 let colorp name get
set =
3623 (fun () -> color_to_string (get
()))
3626 let c = color_of_string v in
3629 state.text <- Printf.sprintf
"bad color `%s': %s"
3630 v (Printexc.to_string exn
);
3633 let oldmode = state.mode
in
3634 let birdseye = isbirdseye state.mode
in
3636 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3638 src#
bool "presentation mode"
3639 (fun () -> conf.presentation)
3641 conf.presentation <- v;
3642 state.anchor <- getanchor ();
3645 src#
bool "ignore case in searches"
3646 (fun () -> conf.icase
)
3647 (fun v -> conf.icase
<- v);
3650 (fun () -> conf.preload)
3651 (fun v -> conf.preload <- v);
3653 src#
bool "highlight links"
3654 (fun () -> conf.hlinks
)
3655 (fun v -> conf.hlinks
<- v);
3657 src#
bool "under info"
3658 (fun () -> conf.underinfo
)
3659 (fun v -> conf.underinfo
<- v);
3661 src#
bool "persistent bookmarks"
3662 (fun () -> conf.savebmarks
)
3663 (fun v -> conf.savebmarks
<- v);
3665 src#
bool "proportional display"
3666 (fun () -> conf.proportional
)
3667 (fun v -> reqlayout conf.angle
v);
3669 src#
bool "trim margins"
3670 (fun () -> conf.trimmargins
)
3671 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3673 src#
bool "persistent location"
3674 (fun () -> conf.jumpback
)
3675 (fun v -> conf.jumpback
<- v);
3678 src#
int "inter-page space"
3679 (fun () -> conf.interpagespace)
3681 conf.interpagespace <- n;
3683 match state.layout with
3688 state.maxy <- calcheight ();
3689 let y = getpagey pageno in
3694 (fun () -> conf.pagebias
)
3695 (fun v -> conf.pagebias
<- v);
3697 src#
int "scroll step"
3698 (fun () -> conf.scrollstep
)
3699 (fun n -> conf.scrollstep
<- n);
3701 src#
int "auto scroll step"
3703 match state.autoscroll
with
3705 | _ -> conf.autoscrollstep
)
3707 if state.autoscroll
<> None
3708 then state.autoscroll
<- Some
n;
3709 conf.autoscrollstep
<- n);
3712 (fun () -> truncate
(conf.zoom *. 100.))
3713 (fun v -> setzoom ((float v) /. 100.));
3716 (fun () -> conf.angle
)
3717 (fun v -> reqlayout v conf.proportional
);
3719 src#
int "scroll bar width"
3720 (fun () -> state.scrollw
)
3724 reshape conf.winw
conf.winh
;
3727 src#
int "scroll handle height"
3728 (fun () -> conf.scrollh
)
3729 (fun v -> conf.scrollh
<- v;);
3731 src#
int "thumbnail width"
3732 (fun () -> conf.thumbw
)
3734 conf.thumbw
<- min
4096 v;
3737 leavebirdseye beye
false;
3742 src#
string "columns"
3744 match conf.columns
with
3746 | Some
(multicol
, _) -> columns_to_string multicol
)
3748 let n, a, b = columns_of_string v in
3752 src#caption
"Presentation mode" 0;
3753 src#
bool "scrollbar visible"
3754 (fun () -> conf.scrollbarinpm
)
3756 if v != conf.scrollbarinpm
3758 conf.scrollbarinpm
<- v;
3759 if conf.presentation
3761 state.scrollw
<- if v then conf.scrollbw
else 0;
3762 reshape conf.winw
conf.winh
;
3768 src#caption
"Pixmap cache" 0;
3769 src#int_with_suffix
"size (advisory)"
3770 (fun () -> conf.memlimit
)
3771 (fun v -> conf.memlimit
<- v);
3774 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3775 (string_with_suffix_of_int state.memused
)
3776 (Hashtbl.length
state.tilemap
)) 1;
3779 src#caption
"Layout" 0;
3780 src#caption2
"Dimension"
3782 Printf.sprintf
"%dx%d (virtual %dx%d)"
3788 src#caption2
"Position" (fun () ->
3789 Printf.sprintf
"%dx%d" state.x state.y
3792 src#caption2
"Visible" (fun () -> describe_location ()) 1
3796 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3797 "Save these parameters as global defaults at exit"
3798 (fun () -> conf.bedefault
)
3799 (fun v -> conf.bedefault
<- v)
3803 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3804 src#
bool ~offset
:0 ~
btos "Extended parameters"
3805 (fun () -> !showextended)
3806 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3810 (fun () -> conf.checkers
)
3811 (fun v -> conf.checkers
<- v; setcheckers v);
3813 (fun () -> conf.verbose
)
3814 (fun v -> conf.verbose
<- v);
3815 src#
bool "invert colors"
3816 (fun () -> conf.invert
)
3817 (fun v -> conf.invert
<- v);
3819 (fun () -> conf.maxhfit
)
3820 (fun v -> conf.maxhfit
<- v);
3821 src#
bool "redirect stderr"
3822 (fun () -> conf.redirectstderr)
3823 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3824 src#
string "uri launcher"
3825 (fun () -> conf.urilauncher
)
3826 (fun v -> conf.urilauncher
<- v);
3827 src#
string "tile size"
3828 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3831 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3832 conf.tileh
<- max
64 w;
3833 conf.tilew
<- max
64 h;
3836 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3837 v (Printexc.to_string exn
));
3838 src#
int "texture count"
3839 (fun () -> conf.texcount
)
3842 then conf.texcount
<- v
3843 else showtext '
!'
" Failed to set texture count please retry later"
3845 src#
int "slice height"
3846 (fun () -> conf.sliceheight
)
3848 conf.sliceheight
<- v;
3849 wcmd "sliceh" [`i
conf.sliceheight
];
3851 src#
int "anti-aliasing level"
3852 (fun () -> conf.aalevel
)
3854 conf.aalevel
<- bound v 0 8;
3855 state.anchor <- getanchor ();
3856 opendoc state.path
state.password
;
3858 src#
int "ui font size"
3859 (fun () -> fstate.fontsize
)
3860 (fun v -> setfontsize (bound v 5 100));
3861 colorp "background color"
3862 (fun () -> conf.bgcolor
)
3863 (fun v -> conf.bgcolor
<- v);
3864 src#
bool "crop hack"
3865 (fun () -> conf.crophack
)
3866 (fun v -> conf.crophack
<- v);
3867 src#
string "trim fuzz"
3868 (fun () -> irect_to_string conf.trimfuzz
)
3871 conf.trimfuzz
<- irect_of_string v;
3873 then settrim true conf.trimfuzz
;
3875 state.text <- Printf.sprintf
"bad irect `%s': %s"
3876 v (Printexc.to_string exn
)
3878 src#
string "throttle"
3880 match conf.maxwait
with
3881 | None
-> "show place holder if page is not ready"
3884 then "wait for page to fully render"
3886 "wait " ^ string_of_float
time
3887 ^
" seconds before showing placeholder"
3891 let f = float_of_string
v in
3893 then conf.maxwait
<- None
3894 else conf.maxwait
<- Some
f
3896 state.text <- Printf.sprintf
"bad time `%s': %s"
3897 v (Printexc.to_string exn
)
3899 src#
string "ghyll scroll"
3901 match conf.ghyllscroll
with
3903 | Some nab
-> ghyllscroll_to_string nab
3908 if String.length
v = 0
3910 else Some
(ghyllscroll_of_string v)
3912 conf.ghyllscroll
<- gs
3914 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
3915 v (Printexc.to_string exn
)
3917 src#
string "selection command"
3918 (fun () -> conf.selcmd
)
3919 (fun v -> conf.selcmd
<- v);
3920 src#colorspace
"color space"
3921 (fun () -> colorspace_to_string conf.colorspace
)
3923 conf.colorspace
<- colorspace_of_int v;
3930 src#caption
"Document" 0;
3931 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3932 src#caption2
"Pages"
3933 (fun () -> string_of_int
state.pagecount
) 1;
3934 src#caption2
"Dimensions"
3935 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3939 src#caption
"Trimmed margins" 0;
3940 src#caption2
"Dimensions"
3941 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3944 src#reset prevmode prevuioh
;
3948 let prevmode = state.mode
3949 and prevuioh
= state.uioh in
3950 fillsrc prevmode prevuioh
;
3951 let source = (src :> lvsource
) in
3952 state.uioh <- coe (object (self)
3953 inherit listview ~
source ~trusted
:true as super
3954 val mutable m_prevmemused
= 0
3955 method infochanged
= function
3957 if m_prevmemused
!= state.memused
3959 m_prevmemused
<- state.memused
;
3960 G.postRedisplay "memusedchanged";
3962 | Pdim
-> G.postRedisplay "pdimchanged"
3963 | Docinfo
-> fillsrc prevmode prevuioh
3965 method key key mask
=
3966 if not
(Wsi.withctrl mask
)
3969 | 0xff51 -> coe (self#updownlevel ~
-1)
3970 | 0xff53 -> coe (self#updownlevel
1)
3971 | _ -> super#
key key mask
3972 else super#
key key mask
3974 G.postRedisplay "info";
3980 inherit lvsourcebase
3981 method getitemcount
= Array.length
state.help
3983 let s, n, _ = state.help
.(n) in
3986 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3990 m_qsearch
<- qsearch;
3991 match state.help
.(active) with
3992 | _, _, Action
f -> Some
(f uioh)
4002 method hasaction
n =
4003 match state.help
.(n) with
4004 | _, _, Action
_ -> true
4011 state.uioh <- coe (new listview ~
source ~trusted
:true);
4012 G.postRedisplay "help";
4017 let re = Str.regexp
"[\r\n]" in
4019 inherit lvsourcebase
4020 val mutable m_items
= [||]
4022 method getitemcount
= 1 + Array.length m_items
4027 else m_items
.(n-1), 0
4029 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4034 then Buffer.clear
state.errmsgs
;
4035 m_qsearch
<- qsearch;
4042 method hasaction
n =
4046 state.newerrmsgs
<- false;
4047 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4048 m_items
<- Array.of_list
l
4056 let source = (msgsource :> lvsource
) in
4057 state.uioh <- coe (object
4058 inherit listview ~
source ~trusted
:false as super
4061 then msgsource#reset
;
4064 G.postRedisplay "msgs";
4067 let quickbookmark ?title
() =
4068 match state.layout with
4074 let sec = Unix.gettimeofday
() in
4075 let tm = Unix.localtime
sec in
4076 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4080 (tm.Unix.tm_year
+ 1900)
4083 | Some
title -> title
4086 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4091 state.fullscreen
<- None
;
4095 let setautoscrollspeed step goingdown
=
4096 let incr = max
1 ((abs step
) / 2) in
4097 let incr = if goingdown
then incr else -incr in
4098 let astep = step
+ incr in
4099 state.autoscroll
<- Some
astep;
4102 let viewkeyboard key mask
=
4104 let mode = state.mode in
4105 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4108 G.postRedisplay "view:enttext"
4114 | 0xff1b | 113 -> (* escape / q *)
4115 begin match state.mstate
with
4117 state.mstate
<- Mnone
;
4118 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4119 G.postRedisplay "kill zoom rect";
4121 match state.ranchors
with
4122 | [] -> raise
Wsi.Quit
4123 | (path
, password
, anchor) :: rest
->
4124 state.ranchors
<- rest
;
4125 state.anchor <- anchor;
4126 opendoc path password
4129 | 0xff08 -> (* backspace *)
4130 let y = getnav ~
-1 in
4131 gotoy_and_clear_text y
4139 G.postRedisplay "dehighlight";
4141 | 47 | 63 -> (* / ? *)
4142 let ondone isforw
s =
4143 cbput state.hists
.pat
s;
4144 state.searchpattern
<- s;
4147 let s = String.create
1 in
4148 s.[0] <- Char.chr
key;
4149 enttext (s, "", Some
(onhist state.hists
.pat
),
4150 textentry, ondone (key = 47))
4152 | 43 | 0xffab when Wsi.withctrl mask
-> (* + *)
4153 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4154 setzoom (conf.zoom +. incr)
4156 | 43 | 0xffab -> (* + *)
4159 try int_of_string
s with exc
->
4160 state.text <- Printf.sprintf
"bad integer `%s': %s"
4161 s (Printexc.to_string exc
);
4167 state.text <- "page bias is now " ^ string_of_int
n;
4170 enttext ("page bias: ", "", None
, intentry, ondone)
4172 | 45 | 0xffad when Wsi.withctrl mask
-> (* - *)
4173 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4174 setzoom (max
0.01 (conf.zoom -. decr))
4176 | 45 | 0xffad -> (* - *)
4177 let ondone msg
= state.text <- msg
in
4179 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4180 optentry state.mode, ondone
4183 | 48 when Wsi.withctrl mask
-> (* 0 *)
4186 | 49 when Wsi.withctrl mask
-> (* 1 *)
4187 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4191 | 0xffc6 -> (* f9 *)
4194 | 57 when Wsi.withctrl mask
-> (* ctrl-9 *)
4197 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4198 when not
(Wsi.withctrl mask
) -> (* 0..9 *)
4201 try int_of_string
s with exc
->
4202 state.text <- Printf.sprintf
"bad integer `%s': %s"
4203 s (Printexc.to_string exc
);
4209 cbput state.hists
.pag
(string_of_int
n);
4210 gotopage1 (n + conf.pagebias
- 1) 0;
4213 let pageentry text key =
4214 match Char.unsafe_chr
key with
4215 | 'g'
-> TEdone
text
4216 | _ -> intentry text key
4218 let text = "x" in text.[0] <- Char.chr
key;
4219 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4222 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4223 reshape conf.winw
conf.winh
;
4226 conf.hlinks
<- not
conf.hlinks
;
4227 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4228 G.postRedisplay "toggle highlightlinks";
4231 begin match state.autoscroll
with
4233 conf.autoscrollstep
<- step
;
4234 state.autoscroll
<- None
4236 if conf.autoscrollstep
= 0
4237 then state.autoscroll
<- Some
1
4238 else state.autoscroll
<- Some
conf.autoscrollstep
4242 conf.presentation <- not
conf.presentation;
4243 if conf.presentation
4245 if not
conf.scrollbarinpm
4246 then state.scrollw
<- 0;
4249 state.scrollw
<- conf.scrollbw
;
4251 showtext ' '
("presentation mode " ^
4252 if conf.presentation then "on" else "off");
4253 state.anchor <- getanchor ();
4257 begin match state.fullscreen
with
4259 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4262 state.fullscreen
<- None
;
4267 gotoy_and_clear_text 0
4270 gotopage1 (state.pagecount
- 1) 0
4272 | 112 | 78 -> (* p|N *)
4273 search state.searchpattern
false
4276 search state.searchpattern
true
4279 begin match state.layout with
4282 gotoy_and_clear_text (getpagey l.pageno)
4286 begin match List.rev
state.layout with
4289 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4290 gotoy_and_clear_text (getpagey pageno)
4293 | 0xff9f | 0xffff -> (* delete *)
4294 begin match state.layout with
4297 let pageno = max
0 (l.pageno-1) in
4298 gotoy_and_clear_text (getpagey pageno)
4302 showtext ' '
(describe_location ());
4305 begin match state.layout with
4308 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4313 enterbookmarkmode ()
4321 | 101 when conf.redirectstderr -> (* e *)
4326 match state.layout with
4329 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4333 enttext ("bookmark: ", "", None
, textentry, ondone)
4337 showtext ' '
"Quick bookmark added";
4340 begin match state.layout with
4342 let rect = getpdimrect
l.pagedimno
in
4346 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4347 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4349 (truncate
(rect.(1) -. rect.(0)),
4350 truncate
(rect.(3) -. rect.(0)))
4352 let w = truncate
((float w)*.conf.zoom)
4353 and h = truncate
((float h)*.conf.zoom) in
4356 state.anchor <- getanchor ();
4357 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4359 G.postRedisplay "z";
4364 | 50 when Wsi.withctrl mask
-> (* ctrl-2 *)
4365 let maxw = getmaxw
() in
4367 then setzoom (maxw /. float conf.winw
)
4369 | 60 | 62 -> (* < > *)
4370 reqlayout (conf.angle
+ (if key = 60 then 30 else -30)) conf.proportional
4372 | 91 | 93 -> (* [ ] *)
4374 bound (conf.colorscale
+. (if key = 92 then 0.1 else -0.1)) 0.0 1.0
4376 G.postRedisplay "brightness";
4378 | 107 | 0xff52 -> (* k UP *)
4379 begin match state.autoscroll
with
4381 begin match state.mode with
4382 | Birdseye beye
-> upbirdseye 1 beye
4384 if Wsi.withctrl mask
4385 then gotoy (-clamp (conf.winh
/2))
4386 else gotoy (clamp (-conf.scrollstep
))
4389 setautoscrollspeed n false
4392 | 106 | 0xff54 -> (* j DOWN *)
4393 begin match state.autoscroll
with
4395 begin match state.mode with
4396 | Birdseye beye
-> downbirdseye 1 beye
4398 if Wsi.withctrl mask
4399 then gotoy (clamp (conf.winh
/2))
4400 else gotoy (clamp conf.scrollstep
)
4403 setautoscrollspeed n true
4406 | 0xff51 | 0xff53 (* left / right *)
4407 when conf.zoom > 1.0->
4409 if Wsi.withctrl mask
4413 let dx = if key = 0xff51 then dx else -dx in
4414 state.x <- state.x + dx;
4417 | 0xff55 -> (* prior *)
4419 if Wsi.withctrl mask
4421 match state.layout with
4423 | l :: _ -> state.y - l.pagey
4429 | 0xff56 -> (* next *)
4431 if Wsi.withctrl mask
4433 match List.rev
state.layout with
4435 | l :: _ -> getpagey l.pageno
4441 | 0xff50 -> gotoghyll 0
4442 | 0xff57 -> gotoghyll (clamp state.maxy)
4443 | 0xff53 when Wsi.withalt mask
->
4444 gotoghyll (getnav ~
-1)
4445 | 0xff51 when Wsi.withalt mask
->
4446 gotoghyll (getnav 1)
4449 state.anchor <- getanchor ();
4450 opendoc state.path
state.password
4452 | 118 when conf.debug
-> (* v *)
4455 match getopaque l.pageno with
4458 let x0, y0
, x1
, y1 = pagebbox opaque
in
4459 let a,b = float x0, float y0
in
4460 let c,d = float x1
, float y0
in
4461 let e,f = float x1
, float y1 in
4462 let h,j
= float x0, float y1 in
4463 let rect = (a,b,c,d,e,f,h,j
) in
4465 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4467 G.postRedisplay "v";
4473 let keyboard key mask
=
4474 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
4475 then wcmd "interrupt" []
4476 else state.uioh <- state.uioh#
key key mask
4479 let birdseyekeyboard key mask
4480 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
4482 match conf.columns
with
4484 | Some
((c, _, _), _) -> c
4487 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
4488 let y, h = getpageyh pageno in
4489 let top = (conf.winh
- h) / 2 in
4490 gotoy (max
0 (y - top))
4491 | 0xff0d -> leavebirdseye beye
false
4492 | 0xff1b -> leavebirdseye beye
true (* escape *)
4493 | 0xff52 -> upbirdseye incr beye
(* prior *)
4494 | 0xff54 -> downbirdseye incr beye
(* next *)
4495 | 0xff51 -> upbirdseye 1 beye
(* up *)
4496 | 0xff53 -> downbirdseye 1 beye
(* down *)
4499 begin match state.layout with
4503 state.mode <- Birdseye
(
4504 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4506 gotopage1 l.pageno 0;
4509 let layout = layout (state.y-conf.winh
) conf.winh
in
4511 | [] -> gotoy (clamp (-conf.winh
))
4513 state.mode <- Birdseye
(
4514 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4516 gotopage1 l.pageno 0
4519 | [] -> gotoy (clamp (-conf.winh
))
4523 begin match List.rev
state.layout with
4525 let layout = layout (state.y + conf.winh
) conf.winh
in
4526 begin match layout with
4528 let incr = l.pageh
- l.pagevh in
4533 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4535 G.postRedisplay "birdseye pagedown";
4537 else gotoy (clamp (incr + conf.interpagespace*2));
4541 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4542 gotopage1 l.pageno 0;
4545 | [] -> gotoy (clamp conf.winh
)
4549 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4553 let pageno = state.pagecount
- 1 in
4554 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4555 if not
(pagevisible state.layout pageno)
4558 match List.rev
state.pdims
with
4560 | (_, _, h, _) :: _ -> h
4562 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4563 else G.postRedisplay "birdseye end";
4564 | _ -> viewkeyboard key mask
4569 match state.mode with
4570 | Textentry
_ -> scalecolor 0.4
4571 | View
-> scalecolor 1.0
4572 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4573 if l.pageno = hooverpageno
4576 if l.pageno = pageno
4582 begin match getopaque l.pageno with
4584 if tileready l l.pagex l.pagey
4586 let x = l.pagedispx - l.pagex
4587 and y = l.pagedispy - l.pagey in
4588 postprocess opaque
conf.hlinks
x y;
4594 let scrollindicator () =
4595 let sbw, ph
, sh = state.uioh#
scrollph in
4596 let sbh, pw
, sw = state.uioh#scrollpw
in
4598 GlDraw.color (0.64, 0.64, 0.64);
4600 (float (conf.winw
- sbw), 0.)
4601 (float conf.winw
, float conf.winh
)
4604 (0., float (conf.winh
- sbh))
4605 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4607 GlDraw.color (0.0, 0.0, 0.0);
4610 (float (conf.winw
- sbw), ph
)
4611 (float conf.winw
, ph
+. sh)
4614 (pw
, float (conf.winh
- sbh))
4615 (pw
+. sw, float conf.winh
)
4619 let pagetranslatepoint l x y =
4620 let dy = y - l.pagedispy in
4621 let y = dy + l.pagey in
4622 let dx = x - l.pagedispx in
4623 let x = dx + l.pagex in
4628 match state.mstate
with
4629 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4632 | Msel
((x0, y0
), (x1
, y1)) ->
4633 let rec loop = function
4635 if ((y0
>= l.pagedispy && y0
<= (l.pagedispy + l.pagevh))
4636 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4637 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4638 || ((x1
>= l.pagedispx && x1
<= (l.pagedispx + l.pagevw))))
4640 match getopaque l.pageno with
4642 let dx, dy = pagetranslatepoint l 0 0 in
4647 GlMat.mode `modelview
;
4649 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4650 seltext opaque
(x0, y0
, x1
, y1);
4661 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4662 GlDraw.polygon_mode `both `fill
;
4663 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4665 (fun (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) ->
4667 if l.pageno = pageno
4669 let dx = float (l.pagedispx - l.pagex) in
4670 let dy = float (l.pagedispy - l.pagey) in
4671 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4672 GlDraw.begins `quads
;
4674 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4675 GlDraw.vertex2
(x1
+.dx, y1+.dy);
4676 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4677 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4688 GlClear.color (scalecolor2 conf.bgcolor
);
4689 GlClear.clear
[`
color];
4690 List.iter
drawpage state.layout;
4695 begin match state.mstate
with
4696 | Mzoomrect
((x0, y0
), (x1
, y1)) ->
4698 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4699 GlDraw.polygon_mode `both `fill
;
4700 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4701 GlDraw.rect (float x0, float y0
)
4702 (float x1
, float y1);
4711 let rec f = function
4713 begin match getopaque l.pageno with
4715 let x0 = l.pagedispx in
4716 let x1 = x0 + l.pagevw in
4717 let y0 = l.pagedispy in
4718 let y1 = y0 + l.pagevh in
4719 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4721 let px, py = pagetranslatepoint l x y in
4722 match whatsunder opaque
px py with
4734 let zoomrect x y x1 y1 =
4737 and y0 = min
y y1 in
4738 gotoy (state.y + y0);
4739 state.anchor <- getanchor ();
4740 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4742 if state.w < conf.winw
- state.scrollw
4743 then (conf.winw
- state.scrollw
- state.w) / 2
4746 state.x <- (state.x + margin) - x0;
4748 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4749 state.mstate
<- Mnone
;
4753 let winw = conf.winw - state.scrollw
- 1 in
4754 let s = float x /. float winw in
4755 let destx = truncate
(float (state.w + winw) *. s) in
4756 state.x <- winw - destx;
4757 gotoy_and_clear_text state.y;
4758 state.mstate
<- Mscrollx
;
4762 let s = float y /. float conf.winh
in
4763 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4764 gotoy_and_clear_text desty;
4765 state.mstate
<- Mscrolly
;
4768 let viewmouse button down
x y mask
=
4770 | n when (n == 4 || n == 5) && not down
->
4771 if Wsi.withctrl mask
4773 match state.mstate
with
4774 | Mzoom
(oldn
, i
) ->
4782 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4784 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4786 let zoom = conf.zoom -. incr in
4788 state.mstate
<- Mzoom
(n, 0);
4790 state.mstate
<- Mzoom
(n, i
+1);
4792 else state.mstate
<- Mzoom
(n, 0)
4794 | _ -> state.mstate
<- Mzoom
(n, 0)
4797 match state.autoscroll
with
4798 | Some step
-> setautoscrollspeed step
(n=4)
4802 then -conf.scrollstep
4803 else conf.scrollstep
4805 let incr = incr * 2 in
4806 let y = clamp incr in
4807 gotoy_and_clear_text y
4810 | 1 when Wsi.withctrl mask
->
4813 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
4814 state.mstate
<- Mpan
(x, y)
4817 state.mstate
<- Mnone
4822 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
4824 state.mstate
<- Mzoomrect
(p, p)
4827 match state.mstate
with
4828 | Mzoomrect
((x0, y0), _) ->
4829 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4830 then zoomrect x0 y0 x y
4832 state.mstate
<- Mnone
;
4833 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4834 G.postRedisplay "kill accidental zoom rect";
4837 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4838 state.mstate
<- Mnone
4841 | 1 when x > conf.winw - state.scrollw
->
4844 let _, position, sh = state.uioh#
scrollph in
4845 if y > truncate
position && y < truncate
(position +. sh)
4846 then state.mstate
<- Mscrolly
4849 state.mstate
<- Mnone
4851 | 1 when y > conf.winh
- state.hscrollh ->
4854 let _, position, sw = state.uioh#scrollpw
in
4855 if x > truncate
position && x < truncate
(position +. sw)
4856 then state.mstate
<- Mscrollx
4859 state.mstate
<- Mnone
4862 let dest = if down
then getunder x y else Unone
in
4863 begin match dest with
4864 | Ulinkgoto
(pageno, top) ->
4868 gotopage1 pageno top;
4874 | Uremote
(filename
, pageno) ->
4876 if Sys.file_exists filename
4879 let dir = Filename.dirname
state.path in
4880 let path = Filename.concat
dir filename
in
4881 if Sys.file_exists
path
4885 if String.length
path > 0
4887 let anchor = getanchor () in
4888 let ranchor = state.path, state.password
, anchor in
4889 state.anchor <- (pageno, 0.0);
4890 state.ranchors
<- ranchor :: state.ranchors
;
4893 else showtext '
!'
("Could not find " ^ filename
)
4895 | Uunexpected
_ | Ulaunch
_ | Unamed
_ -> ()
4897 | Unone
when down
->
4898 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
4899 state.mstate
<- Mpan
(x, y);
4901 | Unone
| Utext
_ ->
4904 if conf.angle
mod 360 = 0
4906 state.mstate
<- Msel
((x, y), (x, y));
4907 G.postRedisplay "mouse select";
4911 match state.mstate
with
4914 | Mzoom
_ | Mscrollx
| Mscrolly
->
4915 state.mstate
<- Mnone
4917 | Mzoomrect
((x0, y0), _) ->
4921 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4922 state.mstate
<- Mnone
4924 | Msel
((_, y0), (_, y1)) ->
4925 let rec loop = function
4928 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4929 || ((y1 >= l.pagedispy
4930 && y1 <= (l.pagedispy + l.pagevh)))
4932 match getopaque l.pageno with
4934 copysel
conf.selcmd opaque
;
4935 G.postRedisplay "copysel"
4940 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4941 state.mstate
<- Mnone
;
4948 let birdseyemouse button down
x y mask
4949 (conf, leftx
, _, hooverpageno
, anchor) =
4952 let rec loop = function
4955 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4956 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4958 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4964 | _ -> viewmouse button down
x y mask
4967 let mouse button down
x y mask
=
4968 state.uioh <- state.uioh#button button down
x y mask
;
4972 state.uioh <- state.uioh#
motion x y
4976 state.uioh <- state.uioh#
pmotion x y;
4982 method key key mask
=
4983 begin match state.mode with
4984 | Textentry
textentry -> textentrykeyboard key mask
textentry
4985 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
4986 | View
-> viewkeyboard key mask
4990 method button button bstate
x y mask
=
4991 begin match state.mode with
4992 | View
-> viewmouse button bstate
x y mask
4993 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
4999 begin match state.mode with
5001 | View
| Birdseye
_ ->
5002 match state.mstate
with
5003 | Mzoom
_ | Mnone
-> ()
5008 state.mstate
<- Mpan
(x, y);
5009 if conf.zoom > 1.0 then state.x <- state.x + dx;
5011 gotoy_and_clear_text y
5014 state.mstate
<- Msel
(a, (x, y));
5015 G.postRedisplay "motion select";
5018 let y = min
conf.winh
(max
0 y) in
5022 let x = min
conf.winw (max
0 x) in
5025 | Mzoomrect
(p0
, _) ->
5026 state.mstate
<- Mzoomrect
(p0
, (x, y));
5027 G.postRedisplay "motion zoomrect";
5031 method pmotion x y =
5032 begin match state.mode with
5033 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5034 let rec loop = function
5036 if hooverpageno
!= -1
5038 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5039 G.postRedisplay "pmotion birdseye no hoover";
5042 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5043 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5045 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5046 G.postRedisplay "pmotion birdseye hoover";
5055 match state.mstate
with
5057 begin match getunder x y with
5058 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
5060 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
5061 Wsi.setcursor
Wsi.CURSOR_INFO
5062 | Ulinkgoto
(page
, _) ->
5064 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
5065 Wsi.setcursor
Wsi.CURSOR_INFO
5067 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
5068 Wsi.setcursor
Wsi.CURSOR_TEXT
5070 if conf.underinfo
then showtext 'u'
("nexpected: " ^
s);
5071 Wsi.setcursor
Wsi.CURSOR_INHERIT
5073 if conf.underinfo
then showtext '
l'
("launch: " ^
s);
5074 Wsi.setcursor
Wsi.CURSOR_INHERIT
5076 if conf.underinfo
then showtext '
n'
("named: " ^
s);
5077 Wsi.setcursor
Wsi.CURSOR_INHERIT
5078 | Uremote
(filename
, pageno) ->
5079 if conf.underinfo
then showtext '
r'
5080 (Printf.sprintf
"emote: %s (%d)" filename
pageno);
5081 Wsi.setcursor
Wsi.CURSOR_INFO
5084 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5089 method infochanged
_ = ()
5092 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5093 let p, h = scrollph state.y maxy in
5097 let winw = conf.winw - state.scrollw
- 1 in
5098 let fwinw = float winw in
5100 let sw = fwinw /. float state.w in
5101 let sw = fwinw *. sw in
5102 max
sw (float conf.scrollh
)
5105 let f = state.w+winw in
5106 let r = float (winw-state.x) /. float f in
5107 let p = fwinw *. r in
5111 if position +. sw > fwinw
5112 then fwinw -. position
5115 state.hscrollh, position, sw
5122 let fontpath = ref "";;
5125 let l = String.length
s in
5126 let b = Buffer.create
l in
5132 try Sys.getenv
"HOME"
5135 ("Can not determine home directory location: " ^
5136 Printexc.to_string exn
);
5140 let config_of c attrs
=
5144 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5145 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5146 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5147 | "preload" -> { c with preload = bool_of_string
v }
5148 | "page-bias" -> { c with pagebias
= int_of_string
v }
5149 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5150 | "auto-scroll-step" ->
5151 { c with autoscrollstep
= max
0 (int_of_string
v) }
5152 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5153 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5156 match String.lowercase
v with
5157 | "true" -> Some infinity
5159 | f -> Some
(float_of_string
f)
5161 { c with maxwait
= mw}
5162 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5163 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5164 | "vertical-margin" ->
5165 { c with interpagespace = max
0 (int_of_string
v) }
5167 let zoom = float_of_string
v /. 100. in
5168 let zoom = max
zoom 0.0 in
5169 { c with zoom = zoom }
5170 | "presentation" -> { c with presentation = bool_of_string
v }
5171 | "rotation-angle" -> { c with angle
= int_of_string
v }
5172 | "width" -> { c with winw = max
20 (int_of_string
v) }
5173 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5174 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5175 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5176 | "pixmap-cache-size" ->
5177 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5178 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5179 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5180 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5181 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5182 | "background-color" -> { c with bgcolor
= color_of_string v }
5183 | "scrollbar-in-presentation" ->
5184 { c with scrollbarinpm
= bool_of_string
v }
5185 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5186 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5187 | "mupdf-store-size" ->
5188 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5189 | "checkers" -> { c with checkers
= bool_of_string
v }
5190 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5191 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5192 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5193 | "uri-launcher" -> { c with urilauncher
= unent v }
5194 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5195 | "invert-colors" -> { c with invert
= bool_of_string
v }
5196 | "brightness" -> { c with colorscale
= float_of_string
v }
5197 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5199 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5201 let nab = columns_of_string v in
5202 { c with columns
= Some
(nab, [||]) }
5203 | "birds-eye-columns" ->
5204 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5205 | "selection-command" -> { c with selcmd
= unent v }
5208 prerr_endline
("Error processing attribute (`" ^
5209 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5212 let rec fold c = function
5215 let c = apply c k
v in
5221 let fromstring f pos
n v d =
5224 dolog "Error processing attribute (%S=%S) at %d\n%s"
5225 n v pos
(Printexc.to_string exn
)
5230 let bookmark_of attrs
=
5231 let rec fold title page
rely = function
5232 | ("title", v) :: rest
-> fold v page
rely rest
5233 | ("page", v) :: rest
-> fold title v rely rest
5234 | ("rely", v) :: rest
-> fold title page
v rest
5235 | _ :: rest
-> fold title page
rely rest
5236 | [] -> title, page
, rely
5238 fold "invalid" "0" "0" attrs
5242 let rec fold path page
rely pan
= function
5243 | ("path", v) :: rest
-> fold v page
rely pan rest
5244 | ("page", v) :: rest
-> fold path v rely pan rest
5245 | ("rely", v) :: rest
-> fold path page
v pan rest
5246 | ("pan", v) :: rest
-> fold path page
rely v rest
5247 | _ :: rest
-> fold path page
rely pan rest
5248 | [] -> path, page
, rely, pan
5250 fold "" "0" "0" "0" attrs
5253 let setconf dst
src =
5254 dst
.scrollbw
<- src.scrollbw
;
5255 dst
.scrollh
<- src.scrollh
;
5256 dst
.icase
<- src.icase
;
5257 dst
.preload <- src.preload;
5258 dst
.pagebias
<- src.pagebias
;
5259 dst
.verbose
<- src.verbose
;
5260 dst
.scrollstep
<- src.scrollstep
;
5261 dst
.maxhfit
<- src.maxhfit
;
5262 dst
.crophack
<- src.crophack
;
5263 dst
.autoscrollstep
<- src.autoscrollstep
;
5264 dst
.maxwait
<- src.maxwait
;
5265 dst
.hlinks
<- src.hlinks
;
5266 dst
.underinfo
<- src.underinfo
;
5267 dst
.interpagespace <- src.interpagespace;
5268 dst
.zoom <- src.zoom;
5269 dst
.presentation <- src.presentation;
5270 dst
.angle
<- src.angle
;
5271 dst
.winw <- src.winw;
5272 dst
.winh
<- src.winh
;
5273 dst
.savebmarks
<- src.savebmarks
;
5274 dst
.memlimit
<- src.memlimit
;
5275 dst
.proportional
<- src.proportional
;
5276 dst
.texcount
<- src.texcount
;
5277 dst
.sliceheight
<- src.sliceheight
;
5278 dst
.thumbw
<- src.thumbw
;
5279 dst
.jumpback
<- src.jumpback
;
5280 dst
.bgcolor
<- src.bgcolor
;
5281 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5282 dst
.tilew
<- src.tilew
;
5283 dst
.tileh
<- src.tileh
;
5284 dst
.mustoresize
<- src.mustoresize
;
5285 dst
.checkers
<- src.checkers
;
5286 dst
.aalevel
<- src.aalevel
;
5287 dst
.trimmargins
<- src.trimmargins
;
5288 dst
.trimfuzz
<- src.trimfuzz
;
5289 dst
.urilauncher
<- src.urilauncher
;
5290 dst
.colorspace
<- src.colorspace
;
5291 dst
.invert
<- src.invert
;
5292 dst
.colorscale
<- src.colorscale
;
5293 dst
.redirectstderr <- src.redirectstderr;
5294 dst
.ghyllscroll
<- src.ghyllscroll
;
5295 dst
.columns
<- src.columns
;
5296 dst
.beyecolumns
<- src.beyecolumns
;
5297 dst
.selcmd
<- src.selcmd
;
5301 let h = Hashtbl.create
10 in
5302 let dc = { defconf with angle
= defconf.angle
} in
5303 let rec toplevel v t spos
_ =
5305 | Vdata
| Vcdata
| Vend
-> v
5306 | Vopen
("llppconfig", _, closed
) ->
5309 else { v with f = llppconfig
}
5311 error
"unexpected subelement at top level" s spos
5312 | Vclose
_ -> error
"unexpected close at top level" s spos
5314 and llppconfig
v t spos
_ =
5316 | Vdata
| Vcdata
-> v
5317 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5318 | Vopen
("defaults", attrs
, closed
) ->
5319 let c = config_of dc attrs
in
5323 else { v with f = skip
"defaults" (fun () -> v) }
5325 | Vopen
("ui-font", attrs
, closed
) ->
5326 let rec getsize size
= function
5328 | ("size", v) :: rest
->
5330 fromstring int_of_string spos
"size" v fstate.fontsize
in
5332 | l -> getsize size l
5334 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5337 else { v with f = uifont
(Buffer.create
10) }
5339 | Vopen
("doc", attrs
, closed
) ->
5340 let pathent, spage
, srely
, span
= doc_of attrs
in
5341 let path = unent pathent
5342 and pageno = fromstring int_of_string spos
"page" spage
0
5343 and rely = fromstring float_of_string spos
"rely" srely
0.0
5344 and pan
= fromstring int_of_string spos
"pan" span
0 in
5345 let c = config_of dc attrs
in
5346 let anchor = (pageno, rely) in
5348 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5349 else { v with f = doc
path pan
anchor c [] }
5352 error
"unexpected subelement in llppconfig" s spos
5354 | Vclose
"llppconfig" -> { v with f = toplevel }
5355 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5357 and uifont
b v t spos
epos =
5360 Buffer.add_substring
b s spos
(epos - spos
);
5362 | Vopen
(_, _, _) ->
5363 error
"unexpected subelement in ui-font" s spos
5364 | Vclose
"ui-font" ->
5365 if String.length
!fontpath = 0
5366 then fontpath := Buffer.contents
b;
5367 { v with f = llppconfig
}
5368 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5369 | Vend
-> error
"unexpected end of input in ui-font" s spos
5371 and doc
path pan
anchor c bookmarks
v t spos
_ =
5373 | Vdata
| Vcdata
-> v
5374 | Vend
-> error
"unexpected end of input in doc" s spos
5375 | Vopen
("bookmarks", _, closed
) ->
5378 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5380 | Vopen
(_, _, _) ->
5381 error
"unexpected subelement in doc" s spos
5384 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5385 { v with f = llppconfig
}
5387 | Vclose
_ -> error
"unexpected close in doc" s spos
5389 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5391 | Vdata
| Vcdata
-> v
5392 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5393 | Vopen
("item", attrs
, closed
) ->
5394 let titleent, spage
, srely
= bookmark_of attrs
in
5395 let page = fromstring int_of_string spos
"page" spage
0
5396 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5397 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5399 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5402 { v with f = skip
"item" f }
5405 error
"unexpected subelement in bookmarks" s spos
5407 | Vclose
"bookmarks" ->
5408 { v with f = doc
path pan
anchor c bookmarks }
5410 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5412 and skip tag
f v t spos
_ =
5414 | Vdata
| Vcdata
-> v
5416 error
("unexpected end of input in skipped " ^ tag
) s spos
5417 | Vopen
(tag'
, _, closed
) ->
5421 let f'
() = { v with f = skip tag
f } in
5422 { v with f = skip tag'
f'
}
5426 else error
("unexpected close in skipped " ^ tag
) s spos
5429 parse
{ f = toplevel; accu = () } s;
5435 let len = in_channel_length ic
in
5436 let s = String.create
len in
5437 really_input ic
s 0 len;
5440 | Parse_error
(msg
, s, pos
) ->
5441 let subs = subs s pos
in
5442 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5443 failwith
("parse error: " ^
s)
5446 failwith
("config load error: " ^
Printexc.to_string exn
)
5452 let dir = Filename.concat
home ".config" in
5453 if Sys.is_directory
dir then dir else home
5456 Filename.concat
dir "llpp.conf"
5459 let confpath = ref defconfpath;;
5462 if Sys.file_exists
!confpath
5465 (try Some
(open_in_bin
!confpath)
5468 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5469 Printexc.to_string exn
);
5478 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5479 Printexc.to_string exn
);
5485 f (Hashtbl.create
0, defconf)
5490 let pc, pb
, px, pa
=
5492 Hashtbl.find h (Filename.basename
state.path)
5493 with Not_found
-> dc, [], 0, (0, 0.0)
5497 state.bookmarks <- pb
;
5499 state.scrollw
<- conf.scrollbw
;
5501 then state.anchor <- pa
;
5502 cbput state.hists
.nav pa
;
5507 let add_attrs bb always
dc c =
5510 then Printf.bprintf bb
"\n %s='%b'" s a
5513 then Printf.bprintf bb
"\n %s='%d'" s a
5516 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5519 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5522 then Printf.bprintf bb
"\n %s='%f'" s a
5526 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5530 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5534 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5538 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5544 | Some
(_N
, _A
, _B
) ->
5545 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
5555 else string_of_float
f
5557 Printf.bprintf bb
"\n %s='%s'" s v
5562 | Some
((n, a, b), _) when n > 1 ->
5563 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
5569 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
5574 then dc.winw, dc.winh
5576 match state.fullscreen
with
5578 | None
-> c.winw, c.winh
5580 let zoom, presentation, interpagespace, maxwait
=
5582 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5584 match state.mode with
5585 | Birdseye
(bc
, _, _, _, _) ->
5586 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5587 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5589 oi
"width" w dc.winw;
5590 oi
"height" h dc.winh
;
5591 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5592 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5593 ob "case-insensitive-search" c.icase
dc.icase
;
5594 ob "preload" c.preload dc.preload;
5595 oi
"page-bias" c.pagebias
dc.pagebias
;
5596 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5597 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5598 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5599 ob "crop-hack" c.crophack
dc.crophack
;
5600 oW
"throttle" maxwait
dc.maxwait
;
5601 ob "highlight-links" c.hlinks
dc.hlinks
;
5602 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5603 oi
"vertical-margin" interpagespace dc.interpagespace;
5604 oz
"zoom" zoom dc.zoom;
5605 ob "presentation" presentation dc.presentation;
5606 oi
"rotation-angle" c.angle
dc.angle
;
5607 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5608 ob "proportional-display" c.proportional
dc.proportional
;
5609 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5610 oi
"tex-count" c.texcount
dc.texcount
;
5611 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5612 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5613 ob "persistent-location" c.jumpback
dc.jumpback
;
5614 oc
"background-color" c.bgcolor
dc.bgcolor
;
5615 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5616 oi
"tile-width" c.tilew
dc.tilew
;
5617 oi
"tile-height" c.tileh
dc.tileh
;
5618 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
5619 ob "checkers" c.checkers
dc.checkers
;
5620 oi
"aalevel" c.aalevel
dc.aalevel
;
5621 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5622 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5623 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5624 oC
"color-space" c.colorspace
dc.colorspace
;
5625 ob "invert-colors" c.invert
dc.invert
;
5626 oF
"brightness" c.colorscale
dc.colorscale
;
5627 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5628 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
5629 oco
"columns" c.columns
dc.columns
;
5630 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
5631 os
"selection-command" c.selcmd
dc.selcmd
;
5635 let uifontsize = fstate.fontsize
in
5636 let bb = Buffer.create
32768 in
5638 let dc = if conf.bedefault
then conf else dc in
5639 Buffer.add_string
bb "<llppconfig>\n";
5641 if String.length
!fontpath > 0
5643 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5649 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5652 Buffer.add_string
bb "<defaults ";
5653 add_attrs bb true dc dc;
5654 Buffer.add_string
bb "/>\n";
5656 let adddoc path pan
anchor c bookmarks =
5657 if bookmarks == [] && c = dc && anchor = emptyanchor
5660 Printf.bprintf
bb "<doc path='%s'"
5661 (enent
path 0 (String.length
path));
5663 if anchor <> emptyanchor
5665 let n, y = anchor in
5666 Printf.bprintf
bb " page='%d'" n;
5669 Printf.bprintf
bb " rely='%f'" y
5674 then Printf.bprintf
bb " pan='%d'" pan
;
5676 add_attrs bb false dc c;
5678 begin match bookmarks with
5679 | [] -> Buffer.add_string
bb "/>\n"
5681 Buffer.add_string
bb ">\n<bookmarks>\n";
5682 List.iter
(fun (title, _level
, (page, rely)) ->
5684 "<item title='%s' page='%d'"
5685 (enent
title 0 (String.length
title))
5690 Printf.bprintf
bb " rely='%f'" rely
5692 Buffer.add_string
bb "/>\n";
5694 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5700 match state.mode with
5701 | Birdseye
(c, pan, _, _, _) ->
5703 match conf.columns
with
5704 | Some
((c, _, _), _) -> Some
c
5707 match c.columns
with
5708 | Some
(c, _) -> Some
(c, [||])
5711 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
5712 | _ -> state.x, conf
5714 let basename = Filename.basename state.path in
5715 adddoc basename pan (getanchor ())
5718 match state.autoscroll
with
5720 | None
-> conf.autoscrollstep
}
5721 (if conf.savebmarks
then state.bookmarks else []);
5723 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5725 then adddoc path x y c bookmarks
5727 Buffer.add_string
bb "</llppconfig>";
5730 if Buffer.length
bb > 0
5733 let tmp = !confpath ^
".tmp" in
5734 let oc = open_out_bin
tmp in
5735 Buffer.output_buffer
oc bb;
5737 Unix.rename
tmp !confpath;
5740 ("error while saving configuration: " ^
Printexc.to_string exn
)
5747 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5748 "<password> Set password");
5750 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5751 "<path> Set path to the user interface font");
5753 ("-c", Arg.String
(fun s -> Config.confpath := s),
5754 "<path> Set path to the configuration file");
5756 ("-v", Arg.Unit
(fun () ->
5758 "%s\nconfiguration path: %s\n"
5762 exit
0), " Print version and exit");
5765 (fun s -> state.path <- s)
5766 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5768 if String.length
state.path = 0
5769 then (prerr_endline
"file name missing"; exit
1);
5773 state.wsfd
<- Wsi.init
(object
5774 method display = display ()
5775 method reshape w h = reshape w h
5776 method mouse b d x y m = mouse b d x y m
5777 method motion x y = motion x y
5778 method pmotion x y = pmotion x y
5779 method key c m = keyboard c m
5783 List.exists
GlMisc.check_extension
5784 [ "GL_ARB_texture_rectangle"
5785 ; "GL_EXT_texture_recangle"
5786 ; "GL_NV_texture_rectangle" ]
5788 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5790 let cr, sw = Unix.pipe
()
5791 and sr
, cw
= Unix.pipe
() in
5798 setcheckers conf.checkers
;
5802 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5803 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
5808 state.text <- "Opening " ^
state.path;
5809 setaalevel
conf.aalevel
;
5810 writeopen state.path state.password
;
5812 setfontsize fstate.fontsize
;
5813 doreshape conf.winw conf.winh
;
5815 let rec loop deadline
=
5817 match state.errfd
with
5818 | None
-> [state.sr
; state.wsfd
]
5819 | Some fd
-> [state.sr
; state.wsfd
; fd
]
5823 state.redisplay
<- false;
5830 if deadline
= infinity
5832 else max
0.0 (deadline
-. now)
5837 try Unix.select
r [] [] timeout
5838 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
5844 match state.autoscroll
with
5845 | Some step
when step
!= 0 ->
5846 let y = state.y + step
in
5850 else if y >= state.maxy then 0 else y
5853 if state.mode = View
5854 then state.text <- "";
5857 if state.ghyll
== noghyll then infinity
else deadline
+. 0.01
5862 let rec checkfds = function
5864 | fd
:: rest
when fd
= state.sr
->
5865 let cmd = readcmd state.sr
in
5869 | fd
:: rest
when fd
= state.wsfd
->
5874 let s = String.create
80 in
5875 let n = Unix.read fd
s 0 80 in
5876 if conf.redirectstderr
5878 Buffer.add_substring
state.errmsgs
s 0 n;
5879 state.newerrmsgs
<- true;
5880 state.redisplay
<- true;
5883 prerr_string
(String.sub
s 0 n);
5891 if deadline
= infinity
5895 match state.autoscroll
with
5896 | Some step
when step
!= 0 -> deadline1
5897 | _ -> if state.ghyll
== noghyll then infinity
else deadline1