4 | Ulinkgoto
of (int * int)
6 and facename
= string;;
8 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
9 let now = Unix.gettimeofday
;;
13 type params
= (angle
* proportional
* trimparams
14 * texcount
* sliceheight
* memsize
15 * colorspace
* wmclasshack
* fontpath
)
24 and proportional
= bool
25 and trimmargins
= bool
26 and interpagespace
= int
34 and wmclasshack
= bool
35 and irect
= (int * int * int * int)
36 and trimparams
= (trimmargins
* irect
)
37 and colorspace
= | Rgb
| Bgr
| Gray
40 type platform
= | Punknown
| Plinux
| Pwindows
| Posx
| Psun
41 | Pfreebsd
| Pdragonflybsd
| Popenbsd
| Pmingw
| Pcygwin
;;
43 external init
: Unix.file_descr
-> params
-> unit = "ml_init";;
44 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
45 external copysel
: string -> unit = "ml_copysel";;
46 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
47 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
48 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
49 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
50 external measurestr
: int -> string -> float = "ml_measure_string";;
51 external getmaxw
: unit -> float = "ml_getmaxw";;
52 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
53 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
54 external platform
: unit -> platform
= "ml_platform";;
55 external setaalevel
: int -> unit = "ml_setaalevel";;
56 external realloctexts
: int -> bool = "ml_realloctexts";;
58 let platform_to_string = function
59 | Punknown
-> "unknown"
61 | Pwindows
-> "Windows"
64 | Pfreebsd
-> "FreeBSD"
65 | Pdragonflybsd
-> "DragonflyBSD"
66 | Popenbsd
-> "OpenBSD"
71 let platform = platform ();;
75 | Pwindows
| Pmingw
-> true
83 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
86 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
90 | Msel
of (mpos
* mpos
)
93 | Mzoom
of (int * int)
94 | Mzoomrect
of (mpos
* mpos
)
98 type textentry
= string * string * onhist
option * onkey
* ondone
99 and onkey
= string -> int -> te
100 and ondone
= string -> unit
101 and histcancel
= unit -> unit
102 and onhist
= ((histcmd
-> string) * histcancel
)
103 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
108 | TEswitch
of textentry
119 let bound v minv maxv
=
120 max minv
(min maxv v
);
124 { store
= Array.create n v
131 let drawstring size x y s
=
133 Gl.enable `texture_2d
;
134 ignore
(drawstr size x y s
);
136 Gl.disable `texture_2d
;
139 let drawstring1 size x y s
=
143 let drawstring2 size x y fmt
=
144 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
147 let cbcap b
= Array.length b
.store
;;
152 b
.wc
<- (b
.wc
+ 1) mod cap;
154 b
.len
<- min
(b
.len
+ 1) cap;
157 let cbempty b
= b
.len
= 0;;
159 let cbgetg b circular dir
=
163 let rc = b
.rc + dir
in
175 else max
0 (min
rc (b
.len
-1))
181 let cbget b
= cbgetg b
false;;
182 let cbgetc b
= cbgetg b
true;;
199 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
200 dolog " WxH %dx%d" l
.pagew l
.pageh
;
201 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
202 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
203 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
207 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
209 dolog " x0,y0=(% f, % f)" x0 y0
;
210 dolog " x1,y1=(% f, % f)" x1 y1
;
211 dolog " x2,y2=(% f, % f)" x2 y2
;
212 dolog " x3,y3=(% f, % f)" x3 y3
;
217 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
218 and multicol
= columncount
* covercount
* covercount
220 and columncount
= int
221 and covercount
= int;;
224 { mutable scrollbw
: int
225 ; mutable scrollh
: int
226 ; mutable icase
: bool
227 ; mutable preload
: bool
228 ; mutable pagebias
: int
229 ; mutable verbose
: bool
230 ; mutable debug
: bool
231 ; mutable scrollstep
: int
232 ; mutable maxhfit
: bool
233 ; mutable crophack
: bool
234 ; mutable autoscrollstep
: int
235 ; mutable maxwait
: float option
236 ; mutable hlinks
: bool
237 ; mutable underinfo
: bool
238 ; mutable interpagespace
: interpagespace
239 ; mutable zoom
: float
240 ; mutable presentation
: bool
241 ; mutable angle
: angle
244 ; mutable savebmarks
: bool
245 ; mutable proportional
: proportional
246 ; mutable trimmargins
: trimmargins
247 ; mutable trimfuzz
: irect
248 ; mutable memlimit
: memsize
249 ; mutable texcount
: texcount
250 ; mutable sliceheight
: sliceheight
251 ; mutable thumbw
: width
252 ; mutable jumpback
: bool
253 ; mutable bgcolor
: float * float * float
254 ; mutable bedefault
: bool
255 ; mutable scrollbarinpm
: bool
256 ; mutable tilew
: int
257 ; mutable tileh
: int
258 ; mutable mustoresize
: memsize
259 ; mutable checkers
: bool
260 ; mutable aalevel
: int
261 ; mutable urilauncher
: string
262 ; mutable colorspace
: colorspace
263 ; mutable invert
: bool
264 ; mutable colorscale
: float
265 ; mutable redirectstderr
: bool
266 ; mutable ghyllscroll
: (int * int * int) option
267 ; mutable columns
: columns
option
268 ; mutable beyecolumns
: columncount
option
272 type anchor
= pageno
* top
;;
274 type outline
= string * int * anchor
;;
276 type rect
= float * float * float * float * float * float * float * float;;
278 type tile
= opaque
* pixmapsize
* elapsed
279 and elapsed
= float;;
280 type pagemapkey
= pageno
* gen
;;
281 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
285 let emptyanchor = (0, 0.0);;
287 type infochange
= | Memused
| Docinfo
| Pdim
;;
289 class type uioh
= object
290 method display
: unit
291 method key
: int -> uioh
292 method special
: Glut.special_key_t
-> uioh
294 Glut.button_t
-> Glut.mouse_button_state_t
-> int -> int -> uioh
295 method motion
: int -> int -> uioh
296 method pmotion
: int -> int -> uioh
297 method infochanged
: infochange
-> unit
298 method scrollpw
: (int * float * float)
299 method scrollph
: (int * float * float)
303 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
304 | Textentry
of (textentry
* onleave
)
306 and onleave
= leavetextentrystatus
-> unit
307 and leavetextentrystatus
= | Cancel
| Confirm
308 and helpitem
= string * int * action
311 | Action
of (uioh
-> uioh
)
314 let isbirdseye = function Birdseye _
-> true | _
-> false;;
315 let istextentry = function Textentry _
-> true | _
-> false;;
319 | Loading
of (page
* gen
)
321 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
323 | Outlining
of outline list
326 let nouioh : uioh
= object (self
)
329 method special _
= self
330 method button _ _ _ _
= self
331 method motion _ _
= self
332 method pmotion _ _
= self
333 method infochanged _
= ()
334 method scrollpw
= (0, nan
, nan
)
335 method scrollph
= (0, nan
, nan
)
339 { mutable csock
: Unix.file_descr
340 ; mutable ssock
: Unix.file_descr
341 ; mutable errfd
: Unix.file_descr
option
342 ; mutable stderr
: Unix.file_descr
343 ; mutable errmsgs
: Buffer.t
344 ; mutable newerrmsgs
: bool
348 ; mutable scrollw
: int
349 ; mutable hscrollh
: int
350 ; mutable anchor
: anchor
352 ; mutable layout
: page list
353 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
354 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
355 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
356 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
357 ; mutable pagecount
: int
358 ; mutable currently
: currently
359 ; mutable mstate
: mstate
360 ; mutable searchpattern
: string
361 ; mutable rects
: (pageno
* recttype
* rect
) list
362 ; mutable rects1
: (pageno
* recttype
* rect
) list
363 ; mutable text
: string
364 ; mutable fullscreen
: (width
* height
) option
365 ; mutable mode
: mode
366 ; mutable uioh
: uioh
367 ; mutable outlines
: outline array
368 ; mutable bookmarks
: outline list
369 ; mutable path
: string
370 ; mutable password
: string
371 ; mutable invalidated
: int
372 ; mutable memused
: memsize
374 ; mutable throttle
: (page list
* int * float) option
375 ; mutable autoscroll
: int option
376 ; mutable ghyll
: int option -> unit
377 ; mutable help
: helpitem array
378 ; mutable docinfo
: (int * string) list
379 ; mutable deadline
: float
380 ; mutable texid
: GlTex.texture_id
option
382 ; mutable prevzoom
: float
383 ; mutable progress
: float
386 { pat
: string circbuf
387 ; pag
: string circbuf
388 ; nav
: anchor circbuf
409 ; presentation
= false
414 ; proportional
= true
415 ; trimmargins
= false
416 ; trimfuzz
= (0,0,0,0)
417 ; memlimit
= 32 lsl 20
422 ; bgcolor
= (0.5, 0.5, 0.5)
424 ; scrollbarinpm
= true
427 ; mustoresize
= 128 lsl 20
432 | Plinux
| Pfreebsd
| Pdragonflybsd
| Popenbsd
| Psun
-> "xdg-open \"%s\""
433 | Posx
-> "open \"%s\""
434 | Pwindows
| Pcygwin
| Pmingw
-> "iexplore \"%s\""
439 ; redirectstderr
= false
446 let conf = { defconf with angle
= defconf.angle
};;
449 { mutable fontsize
: int
450 ; mutable wwidth
: float
451 ; mutable maxrows
: int
463 fstate.fontsize
<- n
;
464 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
465 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
469 if String.length
conf.urilauncher
= 0
470 then print_endline uri
472 let re = Str.regexp
"%s" in
473 let command = Str.global_replace
re uri
conf.urilauncher
in
475 try Some
(Unix.open_process_in
command)
478 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
483 | Some ic
-> close_in ic
488 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
489 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
493 let strings = version () :: "" :: Help.keys
in
495 let r = Str.regexp
"\\(http://[^ ]+\\)" in
497 if (try Str.search_forward
r s
0 with Not_found
-> -1) >= 0
499 let uri = Str.matched_string s
in
500 (s
, 0, Action
(fun u
-> gotouri uri; u
))
501 else s
, 0, Noaction
) strings
511 ; stderr
= Unix.stderr
512 ; errmsgs
= Buffer.create
0
519 ; anchor
= emptyanchor
522 ; tilelru
= Queue.create
()
523 ; pagemap
= Hashtbl.create
10
524 ; tilemap
= Hashtbl.create
10
541 { nav
= cbnew 10 (0, 0.0)
563 Printf.kprintf prerr_endline fmt
565 Printf.kprintf ignore fmt
568 let redirectstderr () =
569 if conf.redirectstderr
571 let rfd, wfd
= Unix.pipe
() in
572 state.stderr
<- Unix.dup
Unix.stderr
;
573 state.errfd
<- Some
rfd;
574 Unix.dup2 wfd
Unix.stderr
;
576 state.newerrmsgs
<- false;
577 begin match state.errfd
with
580 Unix.dup2
state.stderr
Unix.stderr
;
584 prerr_string
(Buffer.contents
state.errmsgs
);
586 Buffer.clear
state.errmsgs
;
592 let postRedisplay who
=
594 then prerr_endline
("redisplay for " ^ who
);
595 Glut.postRedisplay ();
600 let b = Buffer.create
(String.length s
+ 1) in
601 Buffer.add_string
b s
;
606 let colorspace_of_string s
=
607 match String.lowercase s
with
611 | _
-> failwith
"invalid colorspace"
614 let int_of_colorspace = function
620 let colorspace_of_int = function
624 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
627 let colorspace_to_string = function
633 let intentry_with_suffix text key
=
634 let c = Char.unsafe_chr key
in
635 match Char.lowercase
c with
637 let text = addchar text c in
641 let text = addchar text c in
645 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
649 let columns_to_string (n
, a
, b) =
651 then Printf.sprintf
"%d" n
652 else Printf.sprintf
"%d,%d,%d" n a
b;
655 let columns_of_string s
=
657 (int_of_string s
, 0, 0)
659 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
663 let len = String.length s
in
665 let b = Buffer.create
n in
666 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
667 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
668 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
669 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
670 Buffer.add_string
b s
;
671 let s'
= Buffer.contents
b in
672 let n'
= Unix.write fd
s'
0 n in
673 if n'
!= n then failwith
"write failed";
678 let n = Unix.read fd
s 0 4 in
679 if n != 4 then failwith
"incomplete read(len)";
681 lor (Char.code
s.[0] lsl 24)
682 lor (Char.code
s.[1] lsl 16)
683 lor (Char.code
s.[2] lsl 8)
684 lor (Char.code
s.[3] lsl 0)
686 let s = String.create
len in
687 let n = Unix.read fd
s 0 len in
688 if n != len then failwith
"incomplete read(data)";
693 let b = Buffer.create
10 in
694 Buffer.add_string
b s;
695 let rec combine = function
698 Buffer.add_char
b ' '
;
701 | `
b b -> if b then "1" else "0"
703 | `i i
-> string_of_int i
704 | `f f
-> string_of_float f
705 | `I f
-> string_of_int
(truncate f
)
707 Buffer.add_string
b s;
714 let cmd = Buffer.contents
(makecmd s l
) in
715 writecmd state.csock
cmd;
721 let d = conf.winh
- h
in
728 let rec f pn ph pi fh l
=
730 | (n, _
, h
, _
) :: rest
->
731 let ips = calcips h
in
736 if isbirdseye state.mode
&& pn
= 0
741 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
746 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
750 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
753 let fh = f 0 0 0 0 state.pdims
in
758 match conf.columns
with
759 | None
-> calcheight ()
761 if Array.length
b > 0
763 let (_
, _
, y
, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
768 let getpageyh pageno
=
769 let rec f pn ph pi y l
=
771 | (n, _
, h
, _
) :: rest
->
772 let ips = calcips h
in
775 let h = if n = pageno
then h else ph
in
776 if conf.presentation
&& n = pageno
778 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
780 y
+ (pageno
- pn
) * (ph
+ pi
), h
782 let y = y + (if conf.presentation
then pi
else 0) in
783 let y = y + (n - pn
) * (ph
+ pi
) in
787 y + (pageno
- pn
) * (ph
+ pi
), ph
789 f 0 0 0 0 state.pdims
792 let getpageyh pageno
=
793 match conf.columns
with
794 | None
-> getpageyh pageno
796 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
800 let getpagedim pageno
=
803 | (n, _
, _
, _
) as pdim
:: rest
->
805 then (if n = pageno
then pdim
else ppdim
)
810 f (-1, -1, -1, -1) state.pdims
813 let getpagey pageno
= fst
(getpageyh pageno
);;
816 let sh = sh - state.hscrollh
in
817 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
818 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
820 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
821 let ips = calcips h in
823 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
827 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
829 prev
, pdims
, pdimno
, 0
831 let dy = dy + yinc in
832 let py = py + yinc in
833 if pageno
= state.pagecount
|| dy >= sh
838 if py + h <= vy - yinc
840 let py = py + h + ips in
841 let dy = max
0 (py - y) in
850 let pagey = vy - py in
851 let pagevh = h - pagey in
852 let pagevh = min
(sh - dy) pagevh in
853 let off = if yinc > 0 then py - vy else 0 in
854 let py = py + h + ips in
857 if state.w
< conf.winw
- state.scrollw
858 then (conf.winw
- state.scrollw
- state.w
) / 2
861 let dispx = xoff + state.x
in
867 let lw = w
- pagex in
868 min
lw (conf.winw
- state.scrollw
)
876 ; pagey = pagey + off
878 ; pagevh = pagevh - off
880 ; pagedispy
= dy + off
883 let accu = e :: accu in
892 if state.invalidated
= 0
910 let layoutN (_
, b) y sh =
911 let sh = sh - state.hscrollh
in
912 let rec fold accu n =
913 if n = Array.length
b
916 let pdimno, dx
, vy, (_
, w
, h, xoff) = b.(n) in
923 let pagey = max
0 (y - vy) in
924 let pagedispy = if pagey > 0 then 0 else vy - y in
925 let pagedispx, pagex, pagevw =
926 let pdx = dx
+ xoff + state.x
in
928 then 0, -pdx, w
+ pdx
929 else pdx, 0, min
(conf.winw
- state.scrollw
) w
931 let pagevh = h - pagey in
932 if pagedispx < conf.winw
- state.scrollw
&& pagevw > 0 && pagevh > 0
943 ; pagedispx = pagedispx
944 ; pagedispy = pagedispy
955 if state.invalidated
= 0
956 then List.rev
(fold [] 0)
961 match conf.columns
with
962 | None
-> layout1 y sh
963 | Some
c -> layoutN c y sh
967 let y = state.y + incr
in
969 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
973 let getopaque pageno
=
974 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
975 with Not_found
-> None
978 let putopaque pageno opaque
=
979 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
983 let tilex = l
.pagex mod conf.tilew
in
984 let tiley = l
.pagey mod conf.tileh
in
986 let col = l
.pagex / conf.tilew
in
987 let row = l
.pagey / conf.tileh
in
990 let a = l
.pagew
- l
.pagex in
991 let b = conf.winw
- state.scrollw
in
995 let rec rowloop row y0 dispy
h =
999 let dh = conf.tileh
- y0
in
1000 let dh = min
h dh in
1001 let rec colloop col x0
dispx w
=
1005 let dw = conf.tilew
- x0
in
1006 let dw = min w
dw in
1008 f col row dispx dispy x0 y0
dw dh;
1009 colloop (col+1) 0 (dispx+dw) (w
-dw)
1012 colloop col tilex l
.pagedispx vw;
1013 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1017 then rowloop row tiley l
.pagedispy vh
;
1020 let gettileopaque l
col row =
1022 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1024 try Some
(Hashtbl.find
state.tilemap
key)
1025 with Not_found
-> None
1028 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1029 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1030 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1033 let drawtiles l color
=
1035 let f col row x
y tilex tiley w
h =
1036 match gettileopaque l
col row with
1037 | Some
(opaque
, _
, t
) ->
1038 let params = x
, y, w
, h, tilex, tiley in
1042 GlFunc.blend_func `zero `one_minus_src_color
;
1044 drawtile
params opaque
;
1046 then Gl.disable `blend
;
1049 let s = Printf.sprintf
1053 let w = measurestr
fstate.fontsize
s in
1054 GlMisc.push_attrib
[`current
];
1055 GlDraw.color
(0.0, 0.0, 0.0);
1057 (float (x
-2), float (y-2))
1058 (float (x
+2) +. w, float (y + fstate.fontsize
+ 2));
1059 GlDraw.color
(1.0, 1.0, 1.0);
1060 drawstring fstate.fontsize x
(y + fstate.fontsize
- 1) s;
1061 GlMisc.pop_attrib
();
1066 let lw = conf.winw
- state.scrollw
- x
in
1069 let lh = conf.winh
- y in
1072 Gl.enable `texture_2d
;
1073 begin match state.texid
with
1075 GlTex.bind_texture `texture_2d id
;
1078 and x1
= float (x
+w)
1079 and y1
= float (y+h) in
1081 let tw = float w /. 64.0
1082 and th
= float h /. 64.0 in
1083 let tx0 = float tilex /. 64.0
1084 and ty0
= float tiley /. 64.0 in
1086 and ty1
= ty0
+. th
in
1087 GlDraw.begins `quads
;
1088 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
1089 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
1090 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
1091 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
1094 Gl.disable `texture_2d
;
1096 GlDraw.color
(1.0, 1.0, 1.0);
1099 (float (x
+w), float (y+h));
1101 if w > 128 && h > fstate.fontsize
+ 10
1103 GlDraw.color
(0.0, 0.0, 0.0);
1106 then (col*conf.tilew
, row*conf.tileh
)
1109 drawstring2 fstate.fontsize x
y "Loading %d [%d,%d]" l
.pageno
c r;
1116 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1118 let tilevisible1 l x
y =
1120 and ax1
= l
.pagex + l
.pagevw
1122 and ay1
= l
.pagey + l
.pagevh in
1126 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1127 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1129 let rx0 = max
ax0 bx0
1130 and ry0
= max ay0 by0
1131 and rx1
= min ax1
bx1
1132 and ry1
= min ay1 by1
in
1134 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1135 nonemptyintersection
1138 let tilevisible layout n x
y =
1139 let rec findpageinlayout = function
1140 | l
:: _
when l
.pageno
= n -> tilevisible1 l x
y
1141 | _
:: rest
-> findpageinlayout rest
1144 findpageinlayout layout
1147 let tileready l x
y =
1148 tilevisible1 l x
y &&
1149 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
1152 let tilepage n p
layout =
1153 let rec loop = function
1157 let f col row _ _ _ _ _ _
=
1158 if state.currently
= Idle
1160 match gettileopaque l
col row with
1163 let x = col*conf.tilew
1164 and y = row*conf.tileh
in
1166 let w = l
.pagew
- x in
1170 let h = l
.pageh
- y in
1182 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1183 conf.tilew
, conf.tileh
1192 if state.invalidated
= 0 then loop layout;
1195 let preloadlayout visiblepages
=
1196 let presentation = conf.presentation in
1197 let interpagespace = conf.interpagespace in
1198 let maxy = state.maxy in
1199 conf.presentation <- false;
1200 conf.interpagespace <- 0;
1201 state.maxy <- calcheight ();
1203 match visiblepages
with
1205 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1207 let y = if y < conf.winh
then 0 else y - conf.winh
in
1208 let h = state.y - y + conf.winh
*3 in
1209 let pages = layout y h in
1210 conf.presentation <- presentation;
1211 conf.interpagespace <- interpagespace;
1217 let rec loop pages =
1218 if state.currently
!= Idle
1223 begin match getopaque l
.pageno
with
1225 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1226 state.currently
<- Loading
(l
, state.gen
);
1228 tilepage l
.pageno opaque
pages;
1233 if state.invalidated
= 0 then loop pages
1238 if conf.preload && state.currently
= Idle
1239 then load (preloadlayout pages);
1242 let layoutready layout =
1243 let rec fold all ls
=
1244 all
&& match ls
with
1246 let seen = ref false in
1247 let allvisible = ref true in
1248 let foo col row _ _ _ _ _ _
=
1250 allvisible := !allvisible &&
1251 begin match gettileopaque l
col row with
1257 fold (!seen && !allvisible) rest
1260 let alltilesvisible = fold true layout in
1265 let y = bound y 0 state.maxy in
1266 let y, layout, proceed
=
1267 match conf.maxwait
with
1268 | Some time
when state.ghyll
== noghyll ->
1269 begin match state.throttle
with
1271 let layout = layout y conf.winh
in
1272 let ready = layoutready layout in
1276 state.throttle
<- Some
(layout, y, now ());
1278 else G.postRedisplay "gotoy showall (None)";
1280 | Some
(_
, _
, started
) ->
1281 let dt = now () -. started
in
1284 state.throttle
<- None
;
1285 let layout = layout y conf.winh
in
1287 G.postRedisplay "maxwait";
1294 let layout = layout y conf.winh
in
1295 if true || layoutready layout
1296 then G.postRedisplay "gotoy ready";
1302 state.layout <- layout;
1303 begin match state.mode
with
1304 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1305 if not
(pagevisible layout pageno
)
1307 match state.layout with
1310 state.mode
<- Birdseye
(
1311 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1318 state.ghyll
<- noghyll;
1321 let conttiling pageno opaque
=
1322 tilepage pageno opaque
1323 (if conf.preload then preloadlayout state.layout else state.layout)
1326 let gotoy_and_clear_text y =
1328 if not
conf.verbose
then state.text <- "";
1332 match state.layout with
1334 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1337 let getanchory (n, top
) =
1338 let y, h = getpageyh n in
1339 y + (truncate
(top
*. float h));
1342 let gotoanchor anchor
=
1343 gotoy (getanchory anchor
);
1347 cbput state.hists
.nav
(getanchor ());
1351 let anchor = cbgetc state.hists
.nav dir
in
1356 let rec scroll f n a b =
1357 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1359 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1361 then s (float f /. float a)
1364 then 1.0 -. s ((float (f-b) /. float (n-b)))
1371 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1372 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1374 let ins = float a *. iv1
1375 and outs
= float (n-b) *. iv1 in
1377 ins +. outs
+. float ones
1379 let rec set (_N
, _A
, _B
) y sy
=
1380 let sum = summa
1.0 _N _A _B
in
1381 let dy = float (y - sy
) in
1385 then state.ghyll
<- noghyll
1388 let s = scroll n _N _A _B
in
1389 let y1 = y1 +. ((s *. dy) /. sum) in
1390 gotoy_and_clear_text (truncate
y1);
1391 state.ghyll
<- gf (n+1) y1;
1395 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1397 gf 0 (float state.y)
1400 match conf.ghyllscroll
with
1402 gotoy_and_clear_text y
1404 if state.ghyll
== noghyll
1405 then set nab
y state.y
1406 else state.ghyll
(Some
y)
1409 let gotopage n top
=
1410 let y, h = getpageyh n in
1411 let y = y + (truncate
(top
*. float h)) in
1415 let gotopage1 n top
=
1416 let y = getpagey n in
1426 state.invalidated
<- state.invalidated
+ 1;
1429 let writeopen path password
=
1430 writecmd state.csock
("open " ^ path ^
"\000" ^ password ^
"\000");
1433 let opendoc path password
=
1436 state.password
<- password
;
1437 state.gen
<- state.gen
+ 1;
1438 state.docinfo
<- [];
1440 setaalevel
conf.aalevel
;
1441 writeopen path password
;
1442 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1443 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1447 let c = c *. conf.colorscale
in
1451 let scalecolor2 (r, g
, b) =
1452 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1456 let docolumns = function
1458 | Some
((columns
, coverA
, coverB
), _
) ->
1459 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1460 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1461 if pageno
= state.pagecount
1464 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1466 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1467 pdimno+1, pdim
, rest
1472 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1474 (conf.winw
- state.scrollw
- w) / 2,
1475 y + rowh
+ conf.interpagespace, h
1478 if (pageno
- coverA
) mod columns
= 0
1479 then 0, y + rowh
+ conf.interpagespace, h
1480 else x + w + conf.interpagespace, y, max rowh
h
1483 let rec fixrow m
= if m
= pageno
then () else
1484 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1487 let y = y + (rowh
- h) / 2 in
1488 a.(m
) <- (pdimno, x, y, pdim
);
1492 if pageno
> 1 && pageno
mod columns
= 0
1493 then fixrow (pageno
- columns
);
1494 a.(pageno
) <- (pdimno, x, y, pdim
);
1495 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1497 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1498 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1500 docolumns conf.columns
;
1501 state.maxy <- calcheight ();
1503 if state.w <= conf.winw
- state.scrollw
1507 match state.mode
with
1508 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1509 let y, h = getpageyh pageno
in
1510 let top = (conf.winh
- h) / 2 in
1511 gotoy (max
0 (y - top))
1512 | _
-> gotoanchor state.anchor
1516 let firsttime = ref true in
1518 GlDraw.viewport
0 0 w h;
1519 if state.invalidated
= 0 && not
!firsttime
1520 then state.anchor <- getanchor ();
1524 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1528 setfontsize fstate.fontsize
;
1529 GlMat.mode `modelview
;
1530 GlMat.load_identity
();
1532 GlMat.mode `projection
;
1533 GlMat.load_identity
();
1534 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1535 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1536 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1539 match conf.columns
with
1541 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1544 wcmd "geometry" [`i
w; `i
h];
1548 let len = String.length
state.text in
1551 match state.mode
with
1552 | View
-> state.hscrollh
1557 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1558 (x+.w, float (conf.winh
- hscrollh))
1561 let w = float (conf.winw
- state.scrollw
- 1) in
1562 if state.progress
>= 0.0 && state.progress
< 1.0
1564 GlDraw.color
(0.3, 0.3, 0.3);
1565 let w1 = w *. state.progress
in
1567 GlDraw.color
(0.0, 0.0, 0.0);
1571 GlDraw.color
(0.0, 0.0, 0.0);
1575 GlDraw.color
(1.0, 1.0, 1.0);
1576 drawstring fstate.fontsize
1577 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1580 match state.mode
with
1581 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1585 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1587 Printf.sprintf
"%s%s_" prefix
text
1596 if not
(istextentry state.mode
)
1598 let s1 = "(press 'e' to review error messasges)" in
1599 if String.length
s > 0 then s ^
" " ^
s1 else s1
1604 if String.length
s > 0
1609 state.text <- Printf.sprintf
"%c%s" c s;
1610 G.postRedisplay "showtext";
1614 let len = Queue.length
state.tilelru
in
1616 if state.memused
<= conf.memlimit
1621 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1622 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1623 let (_
, pw
, ph
, _
) = getpagedim n in
1626 && colorspace
= conf.colorspace
1627 && angle
= conf.angle
1632 match state.throttle
with
1635 then preloadlayout state.layout
1637 | Some
(layout, _
, _
) ->
1640 let x = col*conf.tilew
1641 and y = row*conf.tileh
in
1642 tilevisible layout n x y
1644 then Queue.push lruitem
state.tilelru
1646 wcmd "freetile" [`
s p
];
1647 state.memused
<- state.memused
- s;
1648 state.uioh#infochanged Memused
;
1649 Hashtbl.remove
state.tilemap k
;
1658 Queue.iter
(fun (k
, p
, s) ->
1659 wcmd "freetile" [`
s p
];
1660 state.memused
<- state.memused
- s;
1661 state.uioh#infochanged Memused
;
1662 Hashtbl.remove
state.tilemap k
;
1664 Queue.clear
state.tilelru
;
1668 let logcurrently = function
1669 | Idle
-> dolog "Idle"
1670 | Loading
(l
, gen
) ->
1671 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1672 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1674 "Tiling %d[%d,%d] page=%s cs=%s angle"
1675 l
.pageno
col row pageopaque
1676 (colorspace_to_string colorspace
)
1678 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1679 angle gen
conf.angle
state.gen
1681 conf.tilew
conf.tileh
1688 (* dolog "%S" cmds; *)
1691 try String.index cmds ' '
1692 with Not_found
-> -1
1697 let l = String.length cmds
in
1698 let op = String.sub cmds
0 spacepos in
1700 if l - spacepos < 2 then ""
1701 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1706 state.uioh#infochanged Pdim
;
1710 state.rects
<- state.rects1
;
1711 G.postRedisplay "clearrects";
1715 try Scanf.sscanf args
"%u" (fun n -> n)
1717 dolog "error processing 'continue' %S: %s"
1718 cmds
(Printexc.to_string exn
);
1721 state.pagecount
<- n;
1722 state.invalidated
<- state.invalidated
- 1;
1723 begin match state.currently
with
1725 state.currently
<- Idle
;
1726 state.outlines
<- Array.of_list
(List.rev
l)
1729 if state.invalidated
= 0
1731 if conf.maxwait
= None
1732 then G.postRedisplay "continue";
1735 Glut.setWindowTitle args
1742 then showtext ' ' args
1745 let progress, text =
1747 Scanf.sscanf args
"%f %n"
1749 f, String.sub args pos
(String.length args
- pos
))
1751 dolog "error processing 'progress' %S: %s"
1752 cmds
(Printexc.to_string exn
);
1756 state.progress <- progress;
1757 G.postRedisplay "progress"
1760 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1762 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1763 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1764 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1766 dolog "error processing 'firstmatch' %S: %s"
1767 cmds
(Printexc.to_string exn
);
1770 let y = (getpagey pageno) + truncate y0
in
1773 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)]
1776 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1778 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1779 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1780 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1782 dolog "error processing 'match' %S: %s"
1783 cmds
(Printexc.to_string exn
);
1787 (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) :: state.rects1
1792 Scanf.sscanf args
"%s %f" (fun p t
-> p
, t
)
1794 dolog "error processing 'page' %S: %s"
1795 cmds
(Printexc.to_string exn
);
1798 begin match state.currently
with
1799 | Loading
(l, gen
) ->
1800 vlog "page %d took %f sec" l.pageno t
;
1801 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1802 begin match state.throttle
with
1804 let preloadedpages =
1806 then preloadlayout state.layout
1811 Set.Make
(struct type t
= int let compare = (-) end) in
1813 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1814 IntSet.empty
preloadedpages
1817 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
1818 if not
(IntSet.mem
pageno set)
1820 wcmd "freepage" [`
s opaque
];
1826 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1829 state.currently
<- Idle
;
1832 tilepage l.pageno pageopaque state.layout;
1834 load preloadedpages;
1835 if pagevisible state.layout l.pageno
1836 && layoutready state.layout
1837 then G.postRedisplay "page";
1840 | Some
(layout, _
, _
) ->
1841 state.currently
<- Idle
;
1842 tilepage l.pageno pageopaque layout;
1847 dolog "Inconsistent loading state";
1848 logcurrently state.currently
;
1853 let (x, y, opaque
, size
, t
) =
1855 Scanf.sscanf args
"%u %u %s %u %f"
1856 (fun x y p size t
-> (x, y, p
, size
, t
))
1858 dolog "error processing 'tile' %S: %s"
1859 cmds
(Printexc.to_string exn
);
1862 begin match state.currently
with
1863 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1864 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1866 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1868 wcmd "freetile" [`
s opaque
];
1869 state.currently
<- Idle
;
1873 puttileopaque l col row gen cs angle opaque size t
;
1874 state.memused
<- state.memused
+ size
;
1875 state.uioh#infochanged Memused
;
1877 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1878 opaque
, size
) state.tilelru
;
1881 match state.throttle
with
1882 | None
-> state.layout
1883 | Some
(layout, _
, _
) -> layout
1886 state.currently
<- Idle
;
1888 && conf.colorspace
= cs
1889 && conf.angle
= angle
1890 && tilevisible layout l.pageno x y
1891 then conttiling l.pageno pageopaque;
1893 begin match state.throttle
with
1895 preload state.layout;
1897 && conf.colorspace
= cs
1898 && conf.angle
= angle
1899 && tilevisible state.layout l.pageno x y
1900 then G.postRedisplay "tile nothrottle";
1902 | Some
(layout, y, _
) ->
1903 let ready = layoutready layout in
1907 state.layout <- layout;
1908 state.throttle
<- None
;
1909 G.postRedisplay "throttle";
1916 dolog "Inconsistent tiling state";
1917 logcurrently state.currently
;
1924 Scanf.sscanf args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1926 dolog "error processing 'pdim' %S: %s"
1927 cmds
(Printexc.to_string exn
);
1930 state.uioh#infochanged Pdim
;
1931 state.pdims
<- pdim :: state.pdims
1934 let (l, n, t
, h, pos
) =
1936 Scanf.sscanf args
"%u %u %d %u %n"
1937 (fun l n t
h pos
-> l, n, t
, h, pos
)
1939 dolog "error processing 'o' %S: %s"
1940 cmds
(Printexc.to_string exn
);
1943 let s = String.sub args pos
(String.length args
- pos
) in
1944 let outline = (s, l, (n, float t
/. float h)) in
1945 begin match state.currently
with
1946 | Outlining outlines
->
1947 state.currently
<- Outlining
(outline :: outlines
)
1949 state.currently
<- Outlining
[outline]
1951 dolog "invalid outlining state";
1952 logcurrently currently
1956 state.docinfo
<- (1, args
) :: state.docinfo
1959 state.uioh#infochanged Docinfo
;
1960 state.docinfo
<- List.rev
state.docinfo
1963 dolog "unknown cmd `%S'" cmds
1967 if state.deadline
== nan
then state.deadline
<- now ();
1969 match state.errfd
with
1970 | None
-> [state.csock
]
1971 | Some fd
-> [state.csock
; fd
]
1973 let rec loop delay
=
1975 if state.ghyll
== noghyll
1981 then max
0.0 (deadline -. now ())
1984 let r, _
, _
= Unix.select
r [] [] timeout in
1988 begin match state.autoscroll
with
1989 | Some step
when step
!= 0 ->
1990 let y = state.y + step
in
1994 else if y >= state.maxy then 0 else y
1997 if state.mode
= View
1998 then state.text <- "";
1999 state.deadline <- state.deadline +. 0.005;
2002 state.deadline <- state.deadline +. delay
;
2006 let rec checkfds c = function
2008 | fd
:: rest
when fd
= state.csock
->
2009 let cmd = readcmd state.csock
in
2013 let s = String.create
80 in
2014 let n = Unix.read fd
s 0 80 in
2015 if conf.redirectstderr
2017 Buffer.add_substring
state.errmsgs
s 0 n;
2018 state.newerrmsgs
<- true;
2019 Glut.postRedisplay ();
2022 prerr_string
(String.sub
s 0 n);
2035 let action = function
2036 | HCprev
-> cbget cb ~
-1
2037 | HCnext
-> cbget cb
1
2038 | HCfirst
-> cbget cb ~
-(cb
.rc)
2039 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2040 and cancel
() = cb
.rc <- rc
2044 let search pattern forward
=
2045 if String.length pattern
> 0
2048 match state.layout with
2051 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2054 let b = makecmd "search"
2055 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
2057 Buffer.add_char
b '
,'
;
2058 Buffer.add_string
b pattern
;
2059 Buffer.add_char
b '
\000'
;
2062 writecmd state.csock
cmd;
2065 let intentry text key =
2066 let c = Char.unsafe_chr
key in
2069 let text = addchar text c in
2073 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2077 let textentry text key =
2078 let c = Char.unsafe_chr
key in
2080 | _
when key >= 32 && key < 127 ->
2081 let text = addchar text c in
2085 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
2089 let reqlayout angle proportional
=
2090 match state.throttle
with
2092 if state.invalidated
= 0 then state.anchor <- getanchor ();
2093 conf.angle
<- angle
mod 360;
2094 conf.proportional
<- proportional
;
2096 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
2100 let settrim trimmargins trimfuzz
=
2101 if state.invalidated
= 0 then state.anchor <- getanchor ();
2102 conf.trimmargins
<- trimmargins
;
2103 conf.trimfuzz
<- trimfuzz
;
2104 let x0, y0
, x1
, y1 = trimfuzz
in
2107 `
b conf.trimmargins
;
2113 Hashtbl.iter
(fun _ opaque
->
2114 wcmd "freepage" [`
s opaque
];
2116 Hashtbl.clear
state.pagemap
;
2120 match state.throttle
with
2122 let zoom = max
0.01 zoom in
2123 if zoom <> conf.zoom
2125 state.prevzoom
<- conf.zoom;
2128 then (state.x <- 0; 0.0)
2129 else float state.x /. float state.w
2132 reshape conf.winw
conf.winh
;
2135 let x = relx *. float state.w in
2136 state.x <- truncate
x;
2138 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2141 | Some
(layout, y, started
) ->
2143 match conf.maxwait
with
2147 let dt = now () -. started
in
2155 let setcolumns columns coverA coverB
=
2158 conf.columns
<- None
;
2163 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2166 reshape conf.winw
conf.winh
;
2169 let enterbirdseye () =
2170 let zoom = float conf.thumbw
/. float conf.winw
in
2171 let birdseyepageno =
2172 let cy = conf.winh
/ 2 in
2176 let rec fold best
= function
2179 let d = cy - (l.pagedispy + l.pagevh/2)
2180 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2181 if abs
d < abs dbest
2188 state.mode
<- Birdseye
(
2189 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2192 conf.presentation <- false;
2193 conf.interpagespace <- 10;
2194 conf.hlinks
<- false;
2196 state.mstate
<- Mnone
;
2197 conf.maxwait
<- None
;
2199 match conf.beyecolumns
with
2202 Some
((c, 0, 0), [||])
2205 Glut.setCursor
Glut.CURSOR_INHERIT
;
2208 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2213 reshape conf.winw
conf.winh
;
2216 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2218 conf.zoom <- c.zoom;
2219 conf.presentation <- c.presentation;
2220 conf.interpagespace <- c.interpagespace;
2221 conf.maxwait
<- c.maxwait
;
2222 conf.hlinks
<- c.hlinks
;
2223 conf.beyecolumns
<- (
2224 match conf.columns
with
2225 | Some
((c, _
, _
), _
) -> Some
c
2229 match c.columns
with
2230 | Some
(c, _
) -> Some
(c, [||])
2236 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2239 reshape conf.winw
conf.winh
;
2240 state.anchor <- if goback
then anchor else (pageno, 0.0);
2243 let togglebirdseye () =
2244 match state.mode
with
2245 | Birdseye vals
-> leavebirdseye vals
true
2246 | View
-> enterbirdseye ()
2250 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2251 let pageno = max
0 (pageno - incr
) in
2252 let rec loop = function
2253 | [] -> gotopage1 pageno 0
2254 | l :: _
when l.pageno = pageno ->
2255 if l.pagedispy >= 0 && l.pagey = 0
2256 then G.postRedisplay "upbirdseye"
2257 else gotopage1 pageno 0
2258 | _
:: rest
-> loop rest
2261 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2264 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2265 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2266 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2267 let rec loop = function
2269 let y, h = getpageyh pageno in
2270 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2272 | l :: _
when l.pageno = pageno ->
2273 if l.pagevh != l.pageh
2274 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2275 else G.postRedisplay "downbirdseye"
2276 | _
:: rest
-> loop rest
2281 let optentry mode _
key =
2282 let btos b = if b then "on" else "off" in
2283 let c = Char.unsafe_chr
key in
2287 try conf.scrollstep
<- int_of_string
s with exc
->
2288 state.text <- Printf.sprintf
"bad integer `%s': %s"
2289 s (Printexc.to_string exc
)
2291 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2296 conf.autoscrollstep
<- int_of_string
s;
2297 if state.autoscroll
<> None
2298 then state.autoscroll
<- Some
conf.autoscrollstep
2300 state.text <- Printf.sprintf
"bad integer `%s': %s"
2301 s (Printexc.to_string exc
)
2303 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2308 let n, a, b = columns_of_string s in
2311 state.text <- Printf.sprintf
"bad columns `%s': %s"
2312 s (Printexc.to_string exc
)
2314 TEswitch
("columns: ", "", None
, textentry, ondone)
2319 let zoom = float (int_of_string
s) /. 100.0 in
2322 state.text <- Printf.sprintf
"bad integer `%s': %s"
2323 s (Printexc.to_string exc
)
2325 TEswitch
("zoom: ", "", None
, intentry, ondone)
2330 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2332 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2333 begin match mode
with
2335 leavebirdseye beye
false;
2340 state.text <- Printf.sprintf
"bad integer `%s': %s"
2341 s (Printexc.to_string exc
)
2343 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2348 Some
(int_of_string
s)
2350 state.text <- Printf.sprintf
"bad integer `%s': %s"
2351 s (Printexc.to_string exc
);
2354 | Some angle
-> reqlayout angle
conf.proportional
2357 TEswitch
("rotation: ", "", None
, intentry, ondone)
2360 conf.icase
<- not
conf.icase
;
2361 TEdone
("case insensitive search " ^
(btos conf.icase
))
2364 conf.preload <- not
conf.preload;
2366 TEdone
("preload " ^
(btos conf.preload))
2369 conf.verbose
<- not
conf.verbose
;
2370 TEdone
("verbose " ^
(btos conf.verbose
))
2373 conf.debug
<- not
conf.debug
;
2374 TEdone
("debug " ^
(btos conf.debug
))
2377 conf.maxhfit
<- not
conf.maxhfit
;
2379 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2380 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2383 conf.crophack
<- not
conf.crophack
;
2384 TEdone
("crophack " ^
btos conf.crophack
)
2388 match conf.maxwait
with
2390 conf.maxwait
<- Some infinity
;
2391 "always wait for page to complete"
2393 conf.maxwait
<- None
;
2394 "show placeholder if page is not ready"
2399 conf.underinfo
<- not
conf.underinfo
;
2400 TEdone
("underinfo " ^
btos conf.underinfo
)
2403 conf.savebmarks
<- not
conf.savebmarks
;
2404 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2410 match state.layout with
2415 conf.interpagespace <- int_of_string
s;
2416 state.maxy <- calcheight ();
2417 let y = getpagey pageno in
2420 state.text <- Printf.sprintf
"bad integer `%s': %s"
2421 s (Printexc.to_string exc
)
2423 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2426 reqlayout conf.angle
(not
conf.proportional
);
2427 TEdone
("proportional display " ^
btos conf.proportional
)
2430 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2431 TEdone
("trim margins " ^
btos conf.trimmargins
)
2434 conf.invert
<- not
conf.invert
;
2435 TEdone
("invert colors " ^
btos conf.invert
)
2438 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2442 class type lvsource
= object
2443 method getitemcount
: int
2444 method getitem
: int -> (string * int)
2445 method hasaction
: int -> bool
2454 method getactive
: int
2455 method getfirst
: int
2456 method getqsearch
: string
2457 method setqsearch
: string -> unit
2461 class virtual lvsourcebase
= object
2462 val mutable m_active
= 0
2463 val mutable m_first
= 0
2464 val mutable m_qsearch
= ""
2465 val mutable m_pan
= 0
2466 method getactive
= m_active
2467 method getfirst
= m_first
2468 method getqsearch
= m_qsearch
2469 method getpan
= m_pan
2470 method setqsearch
s = m_qsearch
<- s
2473 let textentryspecial key = function
2474 | ((c, _
, (Some
(action, _
) as onhist), onkey
, ondone), mode
) ->
2477 | Glut.KEY_UP
-> action HCprev
2478 | Glut.KEY_DOWN
-> action HCnext
2479 | Glut.KEY_HOME
-> action HCfirst
2480 | Glut.KEY_END
-> action HClast
2483 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2484 G.postRedisplay "special textentry";
2488 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2490 state.mode
<- Textentry
(te
, onleave
);
2493 G.postRedisplay "textentrykeyboard enttext";
2495 match Char.unsafe_chr
key with
2496 | '
\008'
-> (* backspace *)
2497 let len = String.length
text in
2501 G.postRedisplay "textentrykeyboard after cancel";
2504 let s = String.sub
text 0 (len - 1) in
2505 enttext (c, s, opthist
, onkey
, ondone)
2511 G.postRedisplay "textentrykeyboard after confirm"
2513 | '
\007'
(* ctrl-g *)
2514 | '
\027'
-> (* escape *)
2515 if String.length
text = 0
2517 begin match opthist
with
2519 | Some
(_
, onhistcancel
) -> onhistcancel
()
2523 G.postRedisplay "textentrykeyboard after cancel2"
2526 enttext (c, "", opthist
, onkey
, ondone)
2529 | '
\127'
-> () (* delete *)
2532 begin match onkey
text key with
2536 G.postRedisplay "textentrykeyboard after confirm2";
2539 enttext (c, text, opthist
, onkey
, ondone);
2543 G.postRedisplay "textentrykeyboard after cancel3"
2546 state.mode
<- Textentry
(te
, onleave
);
2547 G.postRedisplay "textentrykeyboard switch";
2551 let firstof first active
=
2552 if first
> active
|| abs
(first
- active
) > fstate.maxrows
- 1
2553 then max
0 (active
- (fstate.maxrows
/2))
2557 let calcfirst first active
=
2560 let rows = active
- first
in
2561 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2565 let scrollph y maxy =
2566 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2567 let sh = float conf.winh
/. sh in
2568 let sh = max
sh (float conf.scrollh
) in
2573 else float y /. float maxy
2575 let position = (float conf.winh
-. sh) *. percent in
2578 if position +. sh > float conf.winh
2579 then float conf.winh
-. sh
2585 let coe s = (s :> uioh
);;
2587 class listview ~
(source
:lvsource
) ~trusted
=
2589 val m_pan
= source#getpan
2590 val m_first
= source#getfirst
2591 val m_active
= source#getactive
2592 val m_qsearch
= source#getqsearch
2593 val m_prev_uioh
= state.uioh
2595 method private elemunder
y =
2596 let n = y / (fstate.fontsize
+1) in
2597 if m_first
+ n < source#getitemcount
2599 if source#hasaction
(m_first
+ n)
2600 then Some
(m_first
+ n)
2607 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2608 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2609 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2610 GlDraw.color
(1., 1., 1.);
2611 Gl.enable `texture_2d
;
2612 let fs = fstate.fontsize
in
2614 let ww = fstate.wwidth
in
2615 let tabw = 30.0*.ww in
2616 let itemcount = source#getitemcount
in
2618 if (row - m_first
) * nfs > conf.winh
2621 if row >= 0 && row < itemcount
2623 let (s, level
) = source#getitem
row in
2624 let y = (row - m_first
) * nfs in
2625 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2628 Gl.disable `texture_2d
;
2629 GlDraw.polygon_mode `both `line
;
2630 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2631 GlDraw.rect (1., float (y + 1))
2632 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2633 GlDraw.polygon_mode `both `fill
;
2634 GlDraw.color
(1., 1., 1.);
2635 Gl.enable `texture_2d
;
2638 let drawtabularstring s =
2639 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2642 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2645 let len = String.length
s - tabpos - 1 in
2646 let s1 = String.sub
s 0 tabpos
2647 and s2
= String.sub
s (tabpos + 1) len in
2648 let nx = drawstr x s1 in
2650 let x = x +. (max
tabw sw) in
2657 let _ = drawtabularstring s in
2664 Gl.disable `texture_2d
;
2666 method updownlevel incr
=
2667 let len = source#getitemcount
in
2669 if m_active
>= 0 && m_active
< len
2670 then snd
(source#getitem m_active
)
2674 if i
= len then i
-1 else if i
= -1 then 0 else
2675 let _, l = source#getitem i
in
2676 if l != curlevel then i
else flow (i
+incr
)
2678 let active = flow m_active
in
2679 let first = calcfirst m_first
active in
2680 G.postRedisplay "special outline updownlevel";
2681 {< m_active
= active; m_first
= first >}
2683 method private key1
key =
2684 let set active first qsearch
=
2685 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2687 let search active pattern incr
=
2690 if n >= 0 && n < source#getitemcount
2692 let s, _ = source#getitem
n in
2694 (try ignore
(Str.search_forward
re s 0); true
2695 with Not_found
-> false)
2697 else loop (n + incr
)
2704 let re = Str.regexp_case_fold pattern
in
2711 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2712 let incr = if key = 18 then -1 else 1 in
2714 match search (m_active
+ incr) m_qsearch
incr with
2716 state.text <- m_qsearch ^
" [not found]";
2719 state.text <- m_qsearch
;
2720 active, firstof m_first
active
2722 G.postRedisplay "listview ctrl-r/s";
2723 set active first m_qsearch
;
2725 | 8 -> (* backspace *)
2726 let len = String.length m_qsearch
in
2733 G.postRedisplay "listview empty qsearch";
2734 set m_active m_first
"";
2737 let qsearch = String.sub m_qsearch
0 (len - 1) in
2739 match search m_active
qsearch ~
-1 with
2741 state.text <- qsearch ^
" [not found]";
2744 state.text <- qsearch;
2745 active, firstof m_first
active
2747 G.postRedisplay "listview backspace qsearch";
2748 set active first qsearch
2751 | _ when key >= 32 && key < 127 ->
2752 let pattern = addchar m_qsearch
(Char.chr
key) in
2754 match search m_active
pattern 1 with
2756 state.text <- pattern ^
" [not found]";
2759 state.text <- pattern;
2760 active, firstof m_first
active
2762 G.postRedisplay "listview qsearch add";
2763 set active first pattern;
2765 | 27 -> (* escape *)
2767 if String.length m_qsearch
= 0
2769 G.postRedisplay "list view escape";
2772 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2774 | None
-> m_prev_uioh
2779 G.postRedisplay "list view kill qsearch";
2780 source#setqsearch
"";
2781 coe {< m_qsearch
= "" >}
2786 let self = {< m_qsearch
= "" >} in
2787 source#setqsearch
"";
2789 G.postRedisplay "listview enter";
2790 if m_active
>= 0 && m_active
< source#getitemcount
2792 source#exit
(coe self) false m_active m_first m_pan
"";
2795 source#exit
(coe self) true m_active m_first m_pan
"";
2798 begin match opt with
2799 | None
-> m_prev_uioh
2803 | 127 -> (* delete *)
2806 | _ -> dolog "unknown key %d" key; coe self
2808 method private special1
key =
2809 let itemcount = source#getitemcount
in
2810 let find start
incr =
2812 if i
= -1 || i
= itemcount
2815 if source#hasaction i
2817 else find (i
+ incr)
2822 let set active first =
2823 let first = bound first 0 (itemcount - fstate.maxrows
) in
2825 coe {< m_active
= active; m_first
= first >}
2828 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2830 let incr1 = if incr > 0 then 1 else -1 in
2831 if isvisible m_first m_active
2834 let next = m_active
+ incr in
2836 if next < 0 || next >= itemcount
2838 else find next incr1
2840 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2846 let first = m_first
+ incr in
2847 let first = bound first 0 (itemcount - 1) in
2849 let next = m_active
+ incr in
2850 let next = bound next 0 (itemcount - 1) in
2853 let active = if next = -1 then m_active
else next in
2856 let first = min
next m_first
in
2858 if abs
(next - first) > fstate.maxrows
2864 let first = m_first
+ incr in
2865 let first = bound first 0 (itemcount - 1) in
2867 let next = m_active
+ incr in
2868 let next = bound next 0 (itemcount - 1) in
2869 let next = find next incr1 in
2871 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2873 let active = if m_active
= -1 then next else m_active
in
2878 if isvisible first active
2884 G.postRedisplay "listview navigate";
2887 begin match key with
2888 | Glut.KEY_UP
-> navigate ~
-1
2889 | Glut.KEY_DOWN
-> navigate 1
2890 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2891 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2895 G.postRedisplay "listview right";
2896 coe {< m_pan
= m_pan
- 1 >}
2900 G.postRedisplay "listview left";
2901 coe {< m_pan
= m_pan
+ 1 >}
2904 let active = find 0 1 in
2905 G.postRedisplay "listview home";
2909 let first = max
0 (itemcount - fstate.maxrows
) in
2910 let active = find (itemcount - 1) ~
-1 in
2911 G.postRedisplay "listview end";
2918 match state.mode
with
2919 | Textentry te
-> textentrykeyboard key te
; coe self
2920 | _ -> self#key1
key
2922 method special
key =
2923 match state.mode
with
2924 | Textentry te
-> textentryspecial key te
; coe self
2925 | _ -> self#special1
key
2927 method button button bstate
x y =
2930 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollbw
->
2931 G.postRedisplay "listview scroll";
2932 if bstate
= Glut.DOWN
2934 let _, position, sh = self#
scrollph in
2935 if y > truncate
position && y < truncate
(position +. sh)
2937 state.mstate
<- Mscrolly
;
2941 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2942 let first = truncate
(s *. float source#getitemcount
) in
2943 let first = min source#getitemcount
first in
2944 Some
(coe {< m_first
= first; m_active
= first >})
2946 state.mstate
<- Mnone
;
2949 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2950 begin match self#elemunder
y with
2952 G.postRedisplay "listview click";
2954 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
2958 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2959 let len = source#getitemcount
in
2961 if n = 4 && m_first
+ fstate.maxrows
>= len
2965 let first = m_first
+ (if n == 3 then -1 else 1) in
2966 bound first 0 (len - 1)
2968 G.postRedisplay "listview wheel";
2969 Some
(coe {< m_first
= first >})
2974 | None
-> m_prev_uioh
2978 match state.mstate
with
2980 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2981 let first = truncate
(s *. float source#getitemcount
) in
2982 let first = min source#getitemcount
first in
2983 G.postRedisplay "listview motion";
2984 coe {< m_first
= first; m_active
= first >}
2987 method pmotion
x y =
2988 if x < conf.winw
- conf.scrollbw
2991 match self#elemunder
y with
2992 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
2993 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
2997 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3002 Glut.setCursor
Glut.CURSOR_INHERIT
;
3006 method infochanged
_ = ()
3008 method scrollpw
= (0, 0.0, 0.0)
3010 let nfs = fstate.fontsize
+ 1 in
3011 let y = m_first
* nfs in
3012 let itemcount = source#getitemcount
in
3013 let maxi = max
0 (itemcount - fstate.maxrows
) in
3014 let maxy = maxi * nfs in
3015 let p, h = scrollph y maxy in
3019 class outlinelistview ~source
=
3021 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
3025 | 14 -> (* ctrl-n *)
3026 source#narrow m_qsearch
;
3027 G.postRedisplay "outline ctrl-n";
3028 coe {< m_first
= 0; m_active
= 0 >}
3030 | 21 -> (* ctrl-u *)
3032 G.postRedisplay "outline ctrl-u";
3034 coe {< m_first
= 0; m_active
= 0 >}
3036 | 12 -> (* ctrl-l *)
3037 let first = m_active
- (fstate.maxrows
/ 2) in
3038 G.postRedisplay "outline ctrl-l";
3039 coe {< m_first
= first >}
3041 | 127 -> (* delete *)
3042 source#remove m_active
;
3043 G.postRedisplay "outline delete";
3044 let active = max
0 (m_active
-1) in
3045 coe {< m_first
= firstof m_first
active;
3046 m_active
= active >}
3048 | key -> super#
key key
3050 method special
key =
3051 let calcfirst first active =
3054 let rows = active - first in
3055 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3059 let active = m_active
+ incr in
3060 let active = bound active 0 (source#getitemcount
- 1) in
3061 let first = calcfirst m_first
active in
3062 G.postRedisplay "special outline navigate";
3063 coe {< m_active
= active; m_first
= first >}
3066 | Glut.KEY_UP
-> navigate ~
-1
3067 | Glut.KEY_DOWN
-> navigate 1
3068 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
3069 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
3073 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
3075 G.postRedisplay "special outline right";
3076 {< m_pan
= m_pan
+ 1 >}
3078 else self#updownlevel
1
3084 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
3086 G.postRedisplay "special outline left";
3087 {< m_pan
= m_pan
- 1 >}
3089 else self#updownlevel ~
-1
3094 G.postRedisplay "special outline home";
3095 coe {< m_first
= 0; m_active
= 0 >}
3098 let active = source#getitemcount
- 1 in
3099 let first = max
0 (active - fstate.maxrows
) in
3100 G.postRedisplay "special outline end";
3101 coe {< m_active
= active; m_first
= first >}
3103 | _ -> super#special
key
3106 let outlinesource usebookmarks
=
3109 inherit lvsourcebase
3110 val mutable m_items
= empty
3111 val mutable m_orig_items
= empty
3112 val mutable m_prev_items
= empty
3113 val mutable m_narrow_pattern
= ""
3114 val mutable m_hadremovals
= false
3116 method getitemcount
=
3117 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3120 if n == Array.length m_items
&& m_hadremovals
3122 ("[Confirm removal]", 0)
3124 let s, n, _ = m_items
.(n) in
3127 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3128 ignore
(uioh
, first, pan
, qsearch);
3129 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3131 if String.length m_narrow_pattern
= 0
3137 if not
confrimremoval
3139 let _, _, anchor = m_items
.(active) in
3144 state.bookmarks
<- Array.to_list m_items
;
3145 m_orig_items
<- m_items
;
3148 else m_items
<- items;
3151 method hasaction
_ = true
3154 if Array.length m_items
!= Array.length m_orig_items
3155 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3158 method narrow
pattern =
3159 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3163 let rec loop accu n =
3166 m_narrow_pattern
<- pattern;
3167 m_items
<- Array.of_list
accu
3170 let (s, _, _) as o = m_items
.(n) in
3172 if (try ignore
(Str.search_forward
re s 0); true
3173 with Not_found
-> false)
3179 loop [] (Array.length m_items
- 1)
3184 then Array.of_list
state.bookmarks
3187 m_items
<- m_orig_items
3192 if m
>= 0 && m
< Array.length m_items
3194 m_hadremovals
<- true;
3195 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3196 let n = if n >= m
then n+1 else n in
3201 method reset
anchor items =
3202 m_hadremovals
<- false;
3203 if m_orig_items
== empty || m_prev_items
!= items
3205 m_orig_items
<- items;
3206 if String.length m_narrow_pattern
= 0
3207 then m_items
<- items;
3209 m_prev_items
<- items;
3210 let rely = getanchory anchor in
3212 let rec loop n best bestd
=
3213 if n = Array.length m_items
3216 let (_, _, anchor) = m_items
.(n) in
3217 let orely = getanchory anchor in
3218 let d = abs
(orely - rely) in
3221 else loop (n+1) best bestd
3226 m_first
<- firstof m_first
active
3230 let enterselector usebookmarks
=
3231 let source = outlinesource usebookmarks
in
3235 then Array.of_list
state.bookmarks
3238 if Array.length
outlines = 0
3240 showtext ' ' errmsg
;
3243 state.text <- source#greetmsg
;
3244 Glut.setCursor
Glut.CURSOR_INHERIT
;
3245 let anchor = getanchor () in
3246 source#reset
anchor outlines;
3247 state.uioh
<- coe (new outlinelistview ~
source);
3248 G.postRedisplay "enter selector";
3252 let enteroutlinemode =
3253 let f = enterselector false in
3254 fun ()-> f "Document has no outline";
3257 let enterbookmarkmode =
3258 let f = enterselector true in
3259 fun () -> f "Document has no bookmarks (yet)";
3262 let color_of_string s =
3263 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3264 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3268 let color_to_string (r, g
, b) =
3269 let r = truncate
(r *. 256.0)
3270 and g
= truncate
(g
*. 256.0)
3271 and b = truncate
(b *. 256.0) in
3272 Printf.sprintf
"%d/%d/%d" r g
b
3275 let irect_of_string s =
3276 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1
y1 -> (x0,y0
,x1
,y1))
3279 let irect_to_string (x0,y0
,x1
,y1) =
3280 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1
y1
3283 let makecheckers () =
3284 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3286 converted by Issac Trotts. July 25, 2002 *)
3287 let image_height = 64
3288 and image_width
= 64 in
3292 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3294 for i
= 0 to image_width
- 1 do
3295 for j
= 0 to image_height - 1 do
3296 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3297 (if (i
land 8 ) lxor (j
land 8) = 0
3298 then [|255;255;255|] else [|200;200;200|])
3303 let image = make_image () in
3304 let id = GlTex.gen_texture
() in
3305 GlTex.bind_texture `texture_2d
id;
3306 GlPix.store
(`unpack_alignment
1);
3307 GlTex.image2d
image;
3308 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3311 `mag_filter `nearest
;
3312 `min_filter `nearest
];
3316 let setcheckers enabled
=
3317 match state.texid
with
3319 if enabled
then state.texid
<- Some
(makecheckers ())
3324 GlTex.delete_texture texid
;
3325 state.texid
<- None
;
3329 let int_of_string_with_suffix s =
3330 let l = String.length
s in
3334 let suffix = Char.lowercase
s.[l-1] in
3336 | 'k'
-> String.sub
s 0 (l-1), 10
3337 | 'm'
-> String.sub
s 0 (l-1), 20
3338 | 'g'
-> String.sub
s 0 (l-1), 30
3342 let n = int_of_string
s1 in
3343 let m = n lsl shift
in
3345 then raise
(Failure
"value too large")
3349 let string_with_suffix_of_int n =
3357 if n land ((1 lsl 20) - 1) = 0
3360 if n land ((1 lsl 10) - 1) = 0
3367 let h = n mod 1000 in
3370 then string_of_int
h ^
s
3372 let s = Printf.sprintf
"_%03d%s" h s in
3379 let defghyllscroll = (40, 8, 32);;
3380 let ghyllscroll_of_string s =
3381 let (n, a, b) as nab
=
3384 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3386 if n <= a || n <= b || a >= b
3387 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3391 let ghyllscroll_to_string ((n, a, b) as nab
) =
3392 if nab
= defghyllscroll
3394 else Printf.sprintf
"%d,%d,%d" n a b;
3397 let describe_location () =
3399 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3401 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3402 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3406 else (100. *. (float state.y /. float maxy))
3410 Printf.sprintf
"page %d of %d [%.2f%%]"
3411 (fn+1) state.pagecount
percent
3414 "pages %d-%d of %d [%.2f%%]"
3415 (fn+1) (ln
+1) state.pagecount
percent
3419 let btos b = if b then "\xe2\x88\x9a" else "" in
3420 let showextended = ref false in
3421 let leave mode
= function
3422 | Confirm
-> state.mode
<- mode
3423 | Cancel
-> state.mode
<- mode
in
3426 val mutable m_first_time
= true
3427 val mutable m_l
= []
3428 val mutable m_a
= [||]
3429 val mutable m_prev_uioh
= nouioh
3430 val mutable m_prev_mode
= View
3432 inherit lvsourcebase
3434 method reset prev_mode prev_uioh
=
3435 m_a
<- Array.of_list
(List.rev m_l
);
3437 m_prev_mode
<- prev_mode
;
3438 m_prev_uioh
<- prev_uioh
;
3442 if n >= Array.length m_a
3446 | _, _, _, Action
_ -> m_active
<- n
3450 m_first_time
<- false;
3453 method int name get
set =
3455 (name
, `
int get
, 1, Action
(
3458 try set (int_of_string
s)
3460 state.text <- Printf.sprintf
"bad integer `%s': %s"
3461 s (Printexc.to_string exn
)
3464 let te = name ^
": ", "", None
, intentry, ondone in
3465 state.mode
<- Textentry
(te, leave m_prev_mode
);
3469 method int_with_suffix name get
set =
3471 (name
, `intws get
, 1, Action
(
3474 try set (int_of_string_with_suffix s)
3476 state.text <- Printf.sprintf
"bad integer `%s': %s"
3477 s (Printexc.to_string exn
)
3481 name ^
": ", "", None
, intentry_with_suffix, ondone
3483 state.mode
<- Textentry
(te, leave m_prev_mode
);
3487 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3489 (name
, `
bool (btos, get
), offset
, Action
(
3496 method color name get
set =
3498 (name
, `color get
, 1, Action
(
3500 let invalid = (nan
, nan
, nan
) in
3503 try color_of_string s
3505 state.text <- Printf.sprintf
"bad color `%s': %s"
3506 s (Printexc.to_string exn
);
3512 let te = name ^
": ", "", None
, textentry, ondone in
3513 state.text <- color_to_string (get
());
3514 state.mode
<- Textentry
(te, leave m_prev_mode
);
3518 method string name get
set =
3520 (name
, `
string get
, 1, Action
(
3522 let ondone s = set s in
3523 let te = name ^
": ", "", None
, textentry, ondone in
3524 state.mode
<- Textentry
(te, leave m_prev_mode
);
3528 method colorspace name get
set =
3530 (name
, `
string get
, 1, Action
(
3533 let vals = [| "rgb"; "bgr"; "gray" |] in
3535 inherit lvsourcebase
3538 m_active
<- int_of_colorspace conf.colorspace
;
3541 method getitemcount
= Array.length
vals
3542 method getitem
n = (vals.(n), 0)
3543 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3544 ignore
(uioh
, first, pan
, qsearch);
3545 if not cancel
then set active;
3547 method hasaction
_ = true
3551 coe (new listview ~
source ~trusted
:true)
3554 method caption
s offset
=
3555 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3557 method caption2
s f offset
=
3558 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3560 method getitemcount
= Array.length m_a
3563 let tostr = function
3564 | `
int f -> string_of_int
(f ())
3565 | `intws
f -> string_with_suffix_of_int (f ())
3567 | `color
f -> color_to_string (f ())
3568 | `
bool (btos, f) -> btos (f ())
3571 let name, t
, offset
, _ = m_a
.(n) in
3572 ((let s = tostr t
in
3573 if String.length
s > 0
3574 then Printf.sprintf
"%s\t%s" name s
3578 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3582 m_qsearch
<- qsearch;
3584 match m_a
.(active) with
3585 | _, _, _, Action
f -> f uioh
3597 method hasaction
n =
3599 | _, _, _, Action
_ -> true
3603 let rec fillsrc prevmode prevuioh
=
3604 let sep () = src#caption
"" 0 in
3605 let colorp name get
set =
3607 (fun () -> color_to_string (get
()))
3610 let c = color_of_string v in
3613 state.text <- Printf.sprintf
"bad color `%s': %s"
3614 v (Printexc.to_string exn
);
3617 let oldmode = state.mode
in
3618 let birdseye = isbirdseye state.mode
in
3620 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3622 src#
bool "presentation mode"
3623 (fun () -> conf.presentation)
3625 conf.presentation <- v;
3626 state.anchor <- getanchor ();
3629 src#
bool "ignore case in searches"
3630 (fun () -> conf.icase
)
3631 (fun v -> conf.icase
<- v);
3634 (fun () -> conf.preload)
3635 (fun v -> conf.preload <- v);
3637 src#
bool "highlight links"
3638 (fun () -> conf.hlinks
)
3639 (fun v -> conf.hlinks
<- v);
3641 src#
bool "under info"
3642 (fun () -> conf.underinfo
)
3643 (fun v -> conf.underinfo
<- v);
3645 src#
bool "persistent bookmarks"
3646 (fun () -> conf.savebmarks
)
3647 (fun v -> conf.savebmarks
<- v);
3649 src#
bool "proportional display"
3650 (fun () -> conf.proportional
)
3651 (fun v -> reqlayout conf.angle
v);
3653 src#
bool "trim margins"
3654 (fun () -> conf.trimmargins
)
3655 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3657 src#
bool "persistent location"
3658 (fun () -> conf.jumpback
)
3659 (fun v -> conf.jumpback
<- v);
3662 src#
int "inter-page space"
3663 (fun () -> conf.interpagespace)
3665 conf.interpagespace <- n;
3667 match state.layout with
3672 state.maxy <- calcheight ();
3673 let y = getpagey pageno in
3678 (fun () -> conf.pagebias
)
3679 (fun v -> conf.pagebias
<- v);
3681 src#
int "scroll step"
3682 (fun () -> conf.scrollstep
)
3683 (fun n -> conf.scrollstep
<- n);
3685 src#
int "auto scroll step"
3687 match state.autoscroll
with
3689 | _ -> conf.autoscrollstep
)
3691 if state.autoscroll
<> None
3692 then state.autoscroll
<- Some
n;
3693 conf.autoscrollstep
<- n);
3696 (fun () -> truncate
(conf.zoom *. 100.))
3697 (fun v -> setzoom ((float v) /. 100.));
3700 (fun () -> conf.angle
)
3701 (fun v -> reqlayout v conf.proportional
);
3703 src#
int "scroll bar width"
3704 (fun () -> state.scrollw
)
3708 reshape conf.winw
conf.winh
;
3711 src#
int "scroll handle height"
3712 (fun () -> conf.scrollh
)
3713 (fun v -> conf.scrollh
<- v;);
3715 src#
int "thumbnail width"
3716 (fun () -> conf.thumbw
)
3718 conf.thumbw
<- min
4096 v;
3721 leavebirdseye beye
false;
3726 src#
string "columns"
3728 match conf.columns
with
3730 | Some
(multicol
, _) -> columns_to_string multicol
)
3732 let n, a, b = columns_of_string v in
3736 src#caption
"Presentation mode" 0;
3737 src#
bool "scrollbar visible"
3738 (fun () -> conf.scrollbarinpm
)
3740 if v != conf.scrollbarinpm
3742 conf.scrollbarinpm
<- v;
3743 if conf.presentation
3745 state.scrollw
<- if v then conf.scrollbw
else 0;
3746 reshape conf.winw
conf.winh
;
3752 src#caption
"Pixmap cache" 0;
3753 src#int_with_suffix
"size (advisory)"
3754 (fun () -> conf.memlimit
)
3755 (fun v -> conf.memlimit
<- v);
3758 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3759 (string_with_suffix_of_int state.memused
)
3760 (Hashtbl.length
state.tilemap
)) 1;
3763 src#caption
"Layout" 0;
3764 src#caption2
"Dimension"
3766 Printf.sprintf
"%dx%d (virtual %dx%d)"
3772 src#caption2
"Position" (fun () ->
3773 Printf.sprintf
"%dx%d" state.x state.y
3776 src#caption2
"Visible" (fun () -> describe_location ()) 1
3780 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3781 "Save these parameters as global defaults at exit"
3782 (fun () -> conf.bedefault
)
3783 (fun v -> conf.bedefault
<- v)
3787 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3788 src#
bool ~offset
:0 ~
btos "Extended parameters"
3789 (fun () -> !showextended)
3790 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3794 (fun () -> conf.checkers
)
3795 (fun v -> conf.checkers
<- v; setcheckers v);
3797 (fun () -> conf.verbose
)
3798 (fun v -> conf.verbose
<- v);
3799 src#
bool "invert colors"
3800 (fun () -> conf.invert
)
3801 (fun v -> conf.invert
<- v);
3803 (fun () -> conf.maxhfit
)
3804 (fun v -> conf.maxhfit
<- v);
3805 src#
bool "redirect stderr"
3806 (fun () -> conf.redirectstderr)
3807 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3808 src#
string "uri launcher"
3809 (fun () -> conf.urilauncher
)
3810 (fun v -> conf.urilauncher
<- v);
3811 src#
string "tile size"
3812 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3815 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3816 conf.tileh
<- max
64 w;
3817 conf.tilew
<- max
64 h;
3820 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3821 v (Printexc.to_string exn
));
3822 src#
int "texture count"
3823 (fun () -> conf.texcount
)
3826 then conf.texcount
<- v
3827 else showtext '
!'
" Failed to set texture count please retry later"
3829 src#
int "slice height"
3830 (fun () -> conf.sliceheight
)
3832 conf.sliceheight
<- v;
3833 wcmd "sliceh" [`i
conf.sliceheight
];
3835 src#
int "anti-aliasing level"
3836 (fun () -> conf.aalevel
)
3838 conf.aalevel
<- bound v 0 8;
3839 state.anchor <- getanchor ();
3840 opendoc state.path
state.password
;
3842 src#
int "ui font size"
3843 (fun () -> fstate.fontsize
)
3844 (fun v -> setfontsize (bound v 5 100));
3845 colorp "background color"
3846 (fun () -> conf.bgcolor
)
3847 (fun v -> conf.bgcolor
<- v);
3848 src#
bool "crop hack"
3849 (fun () -> conf.crophack
)
3850 (fun v -> conf.crophack
<- v);
3851 src#
string "trim fuzz"
3852 (fun () -> irect_to_string conf.trimfuzz
)
3855 conf.trimfuzz
<- irect_of_string v;
3857 then settrim true conf.trimfuzz
;
3859 state.text <- Printf.sprintf
"bad irect `%s': %s"
3860 v (Printexc.to_string exn
)
3862 src#
string "throttle"
3864 match conf.maxwait
with
3865 | None
-> "show place holder if page is not ready"
3868 then "wait for page to fully render"
3870 "wait " ^ string_of_float
time
3871 ^
" seconds before showing placeholder"
3875 let f = float_of_string
v in
3877 then conf.maxwait
<- None
3878 else conf.maxwait
<- Some
f
3880 state.text <- Printf.sprintf
"bad time `%s': %s"
3881 v (Printexc.to_string exn
)
3883 src#
string "ghyll scroll"
3885 match conf.ghyllscroll
with
3887 | Some nab
-> ghyllscroll_to_string nab
3892 if String.length
v = 0
3894 else Some
(ghyllscroll_of_string v)
3896 conf.ghyllscroll
<- gs
3898 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
3899 v (Printexc.to_string exn
)
3901 src#colorspace
"color space"
3902 (fun () -> colorspace_to_string conf.colorspace
)
3904 conf.colorspace
<- colorspace_of_int v;
3911 src#caption
"Document" 0;
3912 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3913 src#caption2
"Pages"
3914 (fun () -> string_of_int
state.pagecount
) 1;
3915 src#caption2
"Dimensions"
3916 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3920 src#caption
"Trimmed margins" 0;
3921 src#caption2
"Dimensions"
3922 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3925 src#reset prevmode prevuioh
;
3929 let prevmode = state.mode
3930 and prevuioh
= state.uioh in
3931 fillsrc prevmode prevuioh
;
3932 let source = (src :> lvsource
) in
3933 state.uioh <- coe (object (self)
3934 inherit listview ~
source ~trusted
:true as super
3935 val mutable m_prevmemused
= 0
3936 method infochanged
= function
3938 if m_prevmemused
!= state.memused
3940 m_prevmemused
<- state.memused
;
3941 G.postRedisplay "memusedchanged";
3943 | Pdim
-> G.postRedisplay "pdimchanged"
3944 | Docinfo
-> fillsrc prevmode prevuioh
3946 method special
key =
3947 if Glut.getModifiers
() land Glut.active_ctrl
= 0
3950 | Glut.KEY_LEFT
-> coe (self#updownlevel ~
-1)
3951 | Glut.KEY_RIGHT
-> coe (self#updownlevel
1)
3952 | _ -> super#special
key
3953 else super#special
key
3955 G.postRedisplay "info";
3961 inherit lvsourcebase
3962 method getitemcount
= Array.length
state.help
3964 let s, n, _ = state.help
.(n) in
3967 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3971 m_qsearch
<- qsearch;
3972 match state.help
.(active) with
3973 | _, _, Action
f -> Some
(f uioh)
3983 method hasaction
n =
3984 match state.help
.(n) with
3985 | _, _, Action
_ -> true
3992 state.uioh <- coe (new listview ~
source ~trusted
:true);
3993 G.postRedisplay "help";
3998 let re = Str.regexp
"[\r\n]" in
4000 inherit lvsourcebase
4001 val mutable m_items
= [||]
4003 method getitemcount
= 1 + Array.length m_items
4008 else m_items
.(n-1), 0
4010 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4015 then Buffer.clear
state.errmsgs
;
4016 m_qsearch
<- qsearch;
4023 method hasaction
n =
4027 state.newerrmsgs
<- false;
4028 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4029 m_items
<- Array.of_list
l
4037 let source = (msgsource :> lvsource
) in
4038 state.uioh <- coe (object
4039 inherit listview ~
source ~trusted
:false as super
4042 then msgsource#reset
;
4045 G.postRedisplay "msgs";
4048 let quickbookmark ?title
() =
4049 match state.layout with
4055 let sec = Unix.gettimeofday
() in
4056 let tm = Unix.localtime
sec in
4057 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4061 (tm.Unix.tm_year
+ 1900)
4064 | Some
title -> title
4067 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4072 state.fullscreen
<- None
;
4073 Glut.reshapeWindow
w h;
4076 let viewkeyboard key =
4078 let mode = state.mode in
4079 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4082 G.postRedisplay "view:enttext"
4084 let c = Char.chr
key in
4086 | '
\027'
| 'q'
-> (* escape *)
4087 begin match state.mstate
with
4089 state.mstate
<- Mnone
;
4090 Glut.setCursor
Glut.CURSOR_INHERIT
;
4091 G.postRedisplay "kill zoom rect";
4096 | '
\008'
-> (* backspace *)
4097 let y = getnav ~
-1 in
4098 gotoy_and_clear_text y
4106 G.postRedisplay "dehighlight";
4109 let ondone isforw
s =
4110 cbput state.hists
.pat
s;
4111 state.searchpattern
<- s;
4114 let s = String.create
1 in
4116 enttext (s, "", Some
(onhist state.hists
.pat
),
4117 textentry, ondone (c ='
/'
))
4119 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4120 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4121 setzoom (conf.zoom +. incr)
4126 try int_of_string
s with exc
->
4127 state.text <- Printf.sprintf
"bad integer `%s': %s"
4128 s (Printexc.to_string exc
);
4134 state.text <- "page bias is now " ^ string_of_int
n;
4137 enttext ("page bias: ", "", None
, intentry, ondone)
4139 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4140 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4141 setzoom (max
0.01 (conf.zoom -. decr))
4144 let ondone msg
= state.text <- msg
in
4146 "option [acfhilpstvACPRSZTI]: ", "", None
,
4147 optentry state.mode, ondone
4150 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4153 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4154 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4158 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4164 try int_of_string
s with exc
->
4165 state.text <- Printf.sprintf
"bad integer `%s': %s"
4166 s (Printexc.to_string exc
);
4172 cbput state.hists
.pag
(string_of_int
n);
4173 gotopage1 (n + conf.pagebias
- 1) 0;
4176 let pageentry text key =
4177 match Char.unsafe_chr
key with
4178 | 'g'
-> TEdone
text
4179 | _ -> intentry text key
4181 let text = "x" in text.[0] <- c;
4182 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4185 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4186 reshape conf.winw
conf.winh
;
4189 conf.hlinks
<- not
conf.hlinks
;
4190 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4191 G.postRedisplay "toggle highlightlinks";
4194 begin match state.autoscroll
with
4196 conf.autoscrollstep
<- step
;
4197 state.autoscroll
<- None
4199 if conf.autoscrollstep
= 0
4200 then state.autoscroll
<- Some
1
4201 else state.autoscroll
<- Some
conf.autoscrollstep
4205 conf.presentation <- not
conf.presentation;
4206 if conf.presentation
4208 if not
conf.scrollbarinpm
4209 then state.scrollw
<- 0;
4212 state.scrollw
<- conf.scrollbw
;
4214 showtext ' '
("presentation mode " ^
4215 if conf.presentation then "on" else "off");
4216 state.anchor <- getanchor ();
4220 begin match state.fullscreen
with
4222 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4225 state.fullscreen
<- None
;
4230 gotoy_and_clear_text 0
4233 gotopage1 (state.pagecount
- 1) 0
4236 search state.searchpattern
true
4239 search state.searchpattern
false
4242 begin match state.layout with
4245 gotoy_and_clear_text (getpagey l.pageno)
4249 begin match List.rev
state.layout with
4252 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4253 gotoy_and_clear_text (getpagey pageno)
4256 | '
\127'
-> (* del *)
4257 begin match state.layout with
4260 let pageno = max
0 (l.pageno-1) in
4261 gotoy_and_clear_text (getpagey pageno)
4265 showtext ' '
(describe_location ());
4268 begin match state.layout with
4271 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4276 enterbookmarkmode ()
4284 | '
e'
when conf.redirectstderr ->
4289 match state.layout with
4292 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4296 enttext ("bookmark: ", "", None
, textentry, ondone)
4300 showtext ' '
"Quick bookmark added";
4303 begin match state.layout with
4305 let rect = getpdimrect
l.pagedimno
in
4309 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4310 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4312 (truncate
(rect.(1) -. rect.(0)),
4313 truncate
(rect.(3) -. rect.(0)))
4315 let w = truncate
((float w)*.conf.zoom)
4316 and h = truncate
((float h)*.conf.zoom) in
4319 state.anchor <- getanchor ();
4320 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4322 G.postRedisplay "z";
4327 | '
\000'
-> (* ctrl-2 *)
4328 let maxw = getmaxw
() in
4330 then setzoom (maxw /. float conf.winw
)
4333 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
4337 bound (conf.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
4339 G.postRedisplay "brightness";
4342 begin match state.mode with
4343 | Birdseye beye
-> upbirdseye 1 beye
4344 | _ -> gotoy (clamp (-conf.scrollstep
))
4348 begin match state.mode with
4349 | Birdseye beye
-> downbirdseye 1 beye
4350 | _ -> gotoy (clamp conf.scrollstep
)
4354 state.anchor <- getanchor ();
4355 opendoc state.path
state.password
4357 | '
v'
when not
conf.debug
->
4358 List.iter
debugl state.layout;
4360 | '
v'
when conf.debug
->
4363 match getopaque l.pageno with
4366 let x0, y0
, x1
, y1 = pagebbox opaque
in
4367 let a,b = float x0, float y0
in
4368 let c,d = float x1
, float y0
in
4369 let e,f = float x1
, float y1 in
4370 let h,j
= float x0, float y1 in
4371 let rect = (a,b,c,d,e,f,h,j
) in
4373 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4375 G.postRedisplay "v";
4378 vlog "huh? %d %c" key (Char.chr
key);
4381 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
4383 | 27 -> (* escape *)
4384 leavebirdseye beye
true
4386 | 12 -> (* ctrl-l *)
4387 let y, h = getpageyh pageno in
4388 let top = (conf.winh
- h) / 2 in
4389 gotoy (max
0 (y - top))
4392 leavebirdseye beye
false
4398 let keyboard ~
key ~
x ~
y =
4401 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
4402 then wcmd "interrupt" []
4403 else state.uioh <- state.uioh#
key key
4406 let birdseyespecial key ((oconf
, leftx
, _, hooverpageno
, anchor) as beye
) =
4408 match conf.columns
with
4410 | Some
((c, _, _), _) -> c
4413 | Glut.KEY_UP
-> upbirdseye incr beye
4414 | Glut.KEY_DOWN
-> downbirdseye incr beye
4415 | Glut.KEY_LEFT
-> upbirdseye 1 beye
4416 | Glut.KEY_RIGHT
-> downbirdseye 1 beye
4418 | Glut.KEY_PAGE_UP
->
4419 begin match state.layout with
4423 state.mode <- Birdseye
(
4424 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4426 gotopage1 l.pageno 0;
4429 let layout = layout (state.y-conf.winh
) conf.winh
in
4431 | [] -> gotoy (clamp (-conf.winh
))
4433 state.mode <- Birdseye
(
4434 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4436 gotopage1 l.pageno 0
4439 | [] -> gotoy (clamp (-conf.winh
))
4442 | Glut.KEY_PAGE_DOWN
->
4443 begin match List.rev
state.layout with
4445 let layout = layout (state.y + conf.winh
) conf.winh
in
4446 begin match layout with
4448 let incr = l.pageh
- l.pagevh in
4453 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4455 G.postRedisplay "birdseye pagedown";
4457 else gotoy (clamp (incr + conf.interpagespace*2));
4461 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4462 gotopage1 l.pageno 0;
4465 | [] -> gotoy (clamp conf.winh
)
4469 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4473 let pageno = state.pagecount
- 1 in
4474 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4475 if not
(pagevisible state.layout pageno)
4478 match List.rev
state.pdims
with
4480 | (_, _, h, _) :: _ -> h
4482 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4483 else G.postRedisplay "birdseye end";
4487 let setautoscrollspeed step goingdown
=
4488 let incr = max
1 ((abs step
) / 2) in
4489 let incr = if goingdown
then incr else -incr in
4490 let astep = step
+ incr in
4491 state.autoscroll
<- Some
astep;
4494 let special ~
key ~
x ~
y =
4497 state.uioh <- state.uioh#
special key
4502 match state.mode with
4503 | Textentry
_ -> scalecolor 0.4
4504 | View
-> scalecolor 1.0
4505 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4506 if l.pageno = hooverpageno
4509 if l.pageno = pageno
4515 begin match getopaque l.pageno with
4517 if tileready l l.pagex l.pagey
4519 let x = l.pagedispx - l.pagex
4520 and y = l.pagedispy - l.pagey in
4521 postprocess opaque
conf.hlinks
x y;
4527 let scrollindicator () =
4528 let sbw, ph
, sh = state.uioh#
scrollph in
4529 let sbh, pw
, sw = state.uioh#scrollpw
in
4531 GlDraw.color (0.64, 0.64, 0.64);
4533 (float (conf.winw
- sbw), 0.)
4534 (float conf.winw
, float conf.winh
)
4537 (0., float (conf.winh
- sbh))
4538 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4540 GlDraw.color (0.0, 0.0, 0.0);
4543 (float (conf.winw
- sbw), ph
)
4544 (float conf.winw
, ph
+. sh)
4547 (pw
, float (conf.winh
- sbh))
4548 (pw
+. sw, float conf.winh
)
4552 let pagetranslatepoint l x y =
4553 let dy = y - l.pagedispy in
4554 let y = dy + l.pagey in
4555 let dx = x - l.pagedispx in
4556 let x = dx + l.pagex in
4561 match state.mstate
with
4562 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4565 | Msel
((x0, y0
), (x1
, y1)) ->
4566 let rec loop = function
4568 if ((y0
>= l.pagedispy && y0
<= (l.pagedispy + l.pagevh))
4569 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4570 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4571 || ((x1
>= l.pagedispx && x1
<= (l.pagedispx + l.pagevw))))
4573 match getopaque l.pageno with
4575 let dx, dy = pagetranslatepoint l 0 0 in
4580 GlMat.mode `modelview
;
4582 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4583 seltext opaque
(x0, y0
, x1
, y1);
4594 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4595 GlDraw.polygon_mode `both `fill
;
4596 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4598 (fun (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) ->
4600 if l.pageno = pageno
4602 let dx = float (l.pagedispx - l.pagex) in
4603 let dy = float (l.pagedispy - l.pagey) in
4604 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4605 GlDraw.begins `quads
;
4607 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4608 GlDraw.vertex2
(x1
+.dx, y1+.dy);
4609 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4610 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4621 GlClear.color (scalecolor2 conf.bgcolor
);
4622 GlClear.clear
[`
color];
4623 List.iter
drawpage state.layout;
4628 begin match state.mstate
with
4629 | Mzoomrect
((x0, y0
), (x1
, y1)) ->
4631 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4632 GlDraw.polygon_mode `both `fill
;
4633 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4634 GlDraw.rect (float x0, float y0
)
4635 (float x1
, float y1);
4640 Glut.swapBuffers
();
4644 let rec f = function
4646 begin match getopaque l.pageno with
4648 let x0 = l.pagedispx in
4649 let x1 = x0 + l.pagevw in
4650 let y0 = l.pagedispy in
4651 let y1 = y0 + l.pagevh in
4652 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4654 let px, py = pagetranslatepoint l x y in
4655 match whatsunder opaque
px py with
4667 let zoomrect x y x1 y1 =
4670 and y0 = min
y y1 in
4671 gotoy (state.y + y0);
4672 state.anchor <- getanchor ();
4673 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4675 if state.w < conf.winw
- state.scrollw
4676 then (conf.winw
- state.scrollw
- state.w) / 2
4679 state.x <- (state.x + margin) - x0;
4681 Glut.setCursor
Glut.CURSOR_INHERIT
;
4682 state.mstate
<- Mnone
;
4686 let winw = conf.winw - state.scrollw
- 1 in
4687 let s = float x /. float winw in
4688 let destx = truncate
(float (state.w + winw) *. s) in
4689 state.x <- winw - destx;
4690 gotoy_and_clear_text state.y;
4691 state.mstate
<- Mscrollx
;
4695 let s = float y /. float conf.winh
in
4696 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4697 gotoy_and_clear_text desty;
4698 state.mstate
<- Mscrolly
;
4701 let viewmouse button bstate
x y =
4703 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4704 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4706 match state.mstate
with
4707 | Mzoom
(oldn
, i
) ->
4715 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4717 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4719 let zoom = conf.zoom -. incr in
4721 state.mstate
<- Mzoom
(n, 0);
4723 state.mstate
<- Mzoom
(n, i
+1);
4725 else state.mstate
<- Mzoom
(n, 0)
4727 | _ -> state.mstate
<- Mzoom
(n, 0)
4730 match state.autoscroll
with
4731 | Some step
-> setautoscrollspeed step
(n=4)
4735 then -conf.scrollstep
4736 else conf.scrollstep
4738 let incr = incr * 2 in
4739 let y = clamp incr in
4740 gotoy_and_clear_text y
4743 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4744 if bstate
= Glut.DOWN
4746 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4747 state.mstate
<- Mpan
(x, y)
4750 state.mstate
<- Mnone
4752 | Glut.RIGHT_BUTTON
->
4753 if bstate
= Glut.DOWN
4755 Glut.setCursor
Glut.CURSOR_CYCLE
;
4757 state.mstate
<- Mzoomrect
(p, p)
4760 match state.mstate
with
4761 | Mzoomrect
((x0, y0), _) ->
4762 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4763 then zoomrect x0 y0 x y
4765 state.mstate
<- Mnone
;
4766 Glut.setCursor
Glut.CURSOR_INHERIT
;
4767 G.postRedisplay "kill accidental zoom rect";
4770 Glut.setCursor
Glut.CURSOR_INHERIT
;
4771 state.mstate
<- Mnone
4774 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4775 if bstate
= Glut.DOWN
4777 let _, position, sh = state.uioh#
scrollph in
4778 if y > truncate
position && y < truncate
(position +. sh)
4779 then state.mstate
<- Mscrolly
4782 state.mstate
<- Mnone
4784 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4785 if bstate
= Glut.DOWN
4787 let _, position, sw = state.uioh#scrollpw
in
4788 if x > truncate
position && x < truncate
(position +. sw)
4789 then state.mstate
<- Mscrollx
4792 state.mstate
<- Mnone
4794 | Glut.LEFT_BUTTON
->
4795 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4796 begin match dest with
4797 | Ulinkgoto
(pageno, top) ->
4801 gotopage1 pageno top;
4807 | Unone
when bstate
= Glut.DOWN
->
4808 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4809 state.mstate
<- Mpan
(x, y);
4811 | Unone
| Utext
_ ->
4812 if bstate
= Glut.DOWN
4814 if conf.angle
mod 360 = 0
4816 state.mstate
<- Msel
((x, y), (x, y));
4817 G.postRedisplay "mouse select";
4821 match state.mstate
with
4824 | Mzoom
_ | Mscrollx
| Mscrolly
->
4825 state.mstate
<- Mnone
4827 | Mzoomrect
((x0, y0), _) ->
4831 Glut.setCursor
Glut.CURSOR_INHERIT
;
4832 state.mstate
<- Mnone
4834 | Msel
((_, y0), (_, y1)) ->
4836 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4837 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh)))
4839 match getopaque l.pageno with
4844 List.iter
f state.layout;
4845 copysel
""; (* ugly *)
4846 Glut.setCursor
Glut.CURSOR_INHERIT
;
4847 state.mstate
<- Mnone
;
4854 let birdseyemouse button bstate
x y
4855 (conf, leftx
, _, hooverpageno
, anchor) =
4857 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4858 let rec loop = function
4861 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4862 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4864 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4869 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4873 let mouse bstate button
x y =
4874 state.uioh <- state.uioh#button button bstate
x y;
4877 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4880 state.uioh <- state.uioh#
motion x y
4884 state.uioh <- state.uioh#
pmotion x y;
4891 begin match state.mode with
4892 | Textentry
textentry -> textentrykeyboard key textentry
4893 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4894 | View
-> viewkeyboard key
4898 method special key =
4899 begin match state.mode with
4900 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4904 birdseyespecial key vals
4906 | View
when key = Glut.KEY_F1
->
4910 begin match state.autoscroll
with
4911 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4912 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4917 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4919 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4921 if Glut.getModifiers
() land Glut.active_shift
!= 0
4922 then (setzoom state.prevzoom
; state.y)
4923 else clamp (-conf.winh
/2)
4924 else clamp (-conf.scrollstep
)
4926 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4928 if Glut.getModifiers
() land Glut.active_shift
!= 0
4929 then (setzoom state.prevzoom
; state.y)
4930 else clamp (conf.winh
/2)
4931 else clamp (conf.scrollstep
)
4932 | Glut.KEY_PAGE_UP
->
4933 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4935 match state.layout with
4937 | l :: _ -> state.y - l.pagey
4940 | Glut.KEY_PAGE_DOWN
->
4941 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4943 match List.rev
state.layout with
4945 | l :: _ -> getpagey l.pageno
4953 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
4955 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
4956 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
4957 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
4959 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
4961 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4962 then (conf.winw / 2)
4965 state.x <- state.x - dx;
4967 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
4969 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4970 then (conf.winw / 2)
4973 state.x <- state.x + dx;
4978 if abs
(state.y - y) > conf.scrollstep
*2
4980 else gotoy_and_clear_text y
4983 | Textentry
te -> textentryspecial key te
4987 method button button bstate
x y =
4988 begin match state.mode with
4989 | View
-> viewmouse button bstate
x y
4990 | Birdseye beye
-> birdseyemouse button bstate
x y beye
4996 begin match state.mode with
4998 | View
| Birdseye
_ ->
4999 match state.mstate
with
5000 | Mzoom
_ | Mnone
-> ()
5005 state.mstate
<- Mpan
(x, y);
5006 if conf.zoom > 1.0 then state.x <- state.x + dx;
5008 gotoy_and_clear_text y
5011 state.mstate
<- Msel
(a, (x, y));
5012 G.postRedisplay "motion select";
5015 let y = min
conf.winh
(max
0 y) in
5019 let x = min
conf.winw (max
0 x) in
5022 | Mzoomrect
(p0
, _) ->
5023 state.mstate
<- Mzoomrect
(p0
, (x, y));
5024 G.postRedisplay "motion zoomrect";
5028 method pmotion x y =
5029 begin match state.mode with
5030 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5031 let rec loop = function
5033 if hooverpageno
!= -1
5035 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5036 G.postRedisplay "pmotion birdseye no hoover";
5039 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5040 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5042 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5043 G.postRedisplay "pmotion birdseye hoover";
5052 match state.mstate
with
5054 begin match getunder x y with
5055 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
5057 if conf.underinfo
then showtext 'u'
("ri: " ^
uri);
5058 Glut.setCursor
Glut.CURSOR_INFO
5059 | Ulinkgoto
(page
, _) ->
5061 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
5062 Glut.setCursor
Glut.CURSOR_INFO
5064 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
5065 Glut.setCursor
Glut.CURSOR_TEXT
5068 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5073 method infochanged
_ = ()
5076 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5077 let p, h = scrollph state.y maxy in
5081 let winw = conf.winw - state.scrollw
- 1 in
5082 let fwinw = float winw in
5084 let sw = fwinw /. float state.w in
5085 let sw = fwinw *. sw in
5086 max
sw (float conf.scrollh
)
5089 let f = state.w+winw in
5090 let r = float (winw-state.x) /. float f in
5091 let p = fwinw *. r in
5095 if position +. sw > fwinw
5096 then fwinw -. position
5099 state.hscrollh, position, sw
5106 let fontpath = ref "";;
5107 let wmclasshack = ref false;;
5110 let l = String.length
s in
5111 let b = Buffer.create
l in
5119 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
5120 | _ -> Sys.getenv
"HOME"
5123 ("Can not determine home directory location: " ^
5124 Printexc.to_string exn
);
5128 let config_of c attrs
=
5132 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5133 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5134 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5135 | "preload" -> { c with preload = bool_of_string
v }
5136 | "page-bias" -> { c with pagebias
= int_of_string
v }
5137 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5138 | "auto-scroll-step" ->
5139 { c with autoscrollstep
= max
0 (int_of_string
v) }
5140 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5141 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5144 match String.lowercase
v with
5145 | "true" -> Some infinity
5147 | f -> Some
(float_of_string
f)
5149 { c with maxwait
= mw}
5150 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5151 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5152 | "vertical-margin" ->
5153 { c with interpagespace = max
0 (int_of_string
v) }
5155 let zoom = float_of_string
v /. 100. in
5156 let zoom = max
zoom 0.0 in
5157 { c with zoom = zoom }
5158 | "presentation" -> { c with presentation = bool_of_string
v }
5159 | "rotation-angle" -> { c with angle
= int_of_string
v }
5160 | "width" -> { c with winw = max
20 (int_of_string
v) }
5161 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5162 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5163 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5164 | "pixmap-cache-size" ->
5165 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5166 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5167 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5168 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5169 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5170 | "background-color" -> { c with bgcolor
= color_of_string v }
5171 | "scrollbar-in-presentation" ->
5172 { c with scrollbarinpm
= bool_of_string
v }
5173 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5174 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5175 | "mupdf-store-size" ->
5176 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5177 | "checkers" -> { c with checkers
= bool_of_string
v }
5178 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5179 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5180 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5181 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
5182 | "uri-launcher" -> { c with urilauncher
= unent v }
5183 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5184 | "invert-colors" -> { c with invert
= bool_of_string
v }
5185 | "brightness" -> { c with colorscale
= float_of_string
v }
5186 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5188 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5190 let nab = columns_of_string v in
5191 { c with columns
= Some
(nab, [||]) }
5192 | "birds-eye-columns" ->
5193 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5196 prerr_endline
("Error processing attribute (`" ^
5197 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5200 let rec fold c = function
5203 let c = apply c k
v in
5209 let fromstring f pos
n v d =
5212 dolog "Error processing attribute (%S=%S) at %d\n%s"
5213 n v pos
(Printexc.to_string exn
)
5218 let bookmark_of attrs
=
5219 let rec fold title page
rely = function
5220 | ("title", v) :: rest
-> fold v page
rely rest
5221 | ("page", v) :: rest
-> fold title v rely rest
5222 | ("rely", v) :: rest
-> fold title page
v rest
5223 | _ :: rest
-> fold title page
rely rest
5224 | [] -> title, page
, rely
5226 fold "invalid" "0" "0" attrs
5230 let rec fold path page
rely pan
= function
5231 | ("path", v) :: rest
-> fold v page
rely pan rest
5232 | ("page", v) :: rest
-> fold path
v rely pan rest
5233 | ("rely", v) :: rest
-> fold path page
v pan rest
5234 | ("pan", v) :: rest
-> fold path page
rely v rest
5235 | _ :: rest
-> fold path page
rely pan rest
5236 | [] -> path
, page
, rely, pan
5238 fold "" "0" "0" "0" attrs
5241 let setconf dst
src =
5242 dst
.scrollbw
<- src.scrollbw
;
5243 dst
.scrollh
<- src.scrollh
;
5244 dst
.icase
<- src.icase
;
5245 dst
.preload <- src.preload;
5246 dst
.pagebias
<- src.pagebias
;
5247 dst
.verbose
<- src.verbose
;
5248 dst
.scrollstep
<- src.scrollstep
;
5249 dst
.maxhfit
<- src.maxhfit
;
5250 dst
.crophack
<- src.crophack
;
5251 dst
.autoscrollstep
<- src.autoscrollstep
;
5252 dst
.maxwait
<- src.maxwait
;
5253 dst
.hlinks
<- src.hlinks
;
5254 dst
.underinfo
<- src.underinfo
;
5255 dst
.interpagespace <- src.interpagespace;
5256 dst
.zoom <- src.zoom;
5257 dst
.presentation <- src.presentation;
5258 dst
.angle
<- src.angle
;
5259 dst
.winw <- src.winw;
5260 dst
.winh
<- src.winh
;
5261 dst
.savebmarks
<- src.savebmarks
;
5262 dst
.memlimit
<- src.memlimit
;
5263 dst
.proportional
<- src.proportional
;
5264 dst
.texcount
<- src.texcount
;
5265 dst
.sliceheight
<- src.sliceheight
;
5266 dst
.thumbw
<- src.thumbw
;
5267 dst
.jumpback
<- src.jumpback
;
5268 dst
.bgcolor
<- src.bgcolor
;
5269 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5270 dst
.tilew
<- src.tilew
;
5271 dst
.tileh
<- src.tileh
;
5272 dst
.mustoresize
<- src.mustoresize
;
5273 dst
.checkers
<- src.checkers
;
5274 dst
.aalevel
<- src.aalevel
;
5275 dst
.trimmargins
<- src.trimmargins
;
5276 dst
.trimfuzz
<- src.trimfuzz
;
5277 dst
.urilauncher
<- src.urilauncher
;
5278 dst
.colorspace
<- src.colorspace
;
5279 dst
.invert
<- src.invert
;
5280 dst
.colorscale
<- src.colorscale
;
5281 dst
.redirectstderr <- src.redirectstderr;
5282 dst
.ghyllscroll
<- src.ghyllscroll
;
5283 dst
.columns
<- src.columns
;
5284 dst
.beyecolumns
<- src.beyecolumns
;
5288 let h = Hashtbl.create
10 in
5289 let dc = { defconf with angle
= defconf.angle
} in
5290 let rec toplevel v t spos
_ =
5292 | Vdata
| Vcdata
| Vend
-> v
5293 | Vopen
("llppconfig", _, closed
) ->
5296 else { v with f = llppconfig
}
5298 error
"unexpected subelement at top level" s spos
5299 | Vclose
_ -> error
"unexpected close at top level" s spos
5301 and llppconfig
v t spos
_ =
5303 | Vdata
| Vcdata
-> v
5304 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5305 | Vopen
("defaults", attrs
, closed
) ->
5306 let c = config_of dc attrs
in
5310 else { v with f = skip
"defaults" (fun () -> v) }
5312 | Vopen
("ui-font", attrs
, closed
) ->
5313 let rec getsize size
= function
5315 | ("size", v) :: rest
->
5317 fromstring int_of_string spos
"size" v fstate.fontsize
in
5319 | l -> getsize size l
5321 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5324 else { v with f = uifont
(Buffer.create
10) }
5326 | Vopen
("doc", attrs
, closed
) ->
5327 let pathent, spage
, srely
, span
= doc_of attrs
in
5328 let path = unent pathent
5329 and pageno = fromstring int_of_string spos
"page" spage
0
5330 and rely = fromstring float_of_string spos
"rely" srely
0.0
5331 and pan
= fromstring int_of_string spos
"pan" span
0 in
5332 let c = config_of dc attrs
in
5333 let anchor = (pageno, rely) in
5335 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5336 else { v with f = doc
path pan
anchor c [] }
5339 error
"unexpected subelement in llppconfig" s spos
5341 | Vclose
"llppconfig" -> { v with f = toplevel }
5342 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5344 and uifont
b v t spos epos
=
5347 Buffer.add_substring
b s spos
(epos
- spos
);
5349 | Vopen
(_, _, _) ->
5350 error
"unexpected subelement in ui-font" s spos
5351 | Vclose
"ui-font" ->
5352 if String.length
!fontpath = 0
5353 then fontpath := Buffer.contents
b;
5354 { v with f = llppconfig
}
5355 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5356 | Vend
-> error
"unexpected end of input in ui-font" s spos
5358 and doc
path pan
anchor c bookmarks
v t spos
_ =
5360 | Vdata
| Vcdata
-> v
5361 | Vend
-> error
"unexpected end of input in doc" s spos
5362 | Vopen
("bookmarks", _, closed
) ->
5365 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5367 | Vopen
(_, _, _) ->
5368 error
"unexpected subelement in doc" s spos
5371 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5372 { v with f = llppconfig
}
5374 | Vclose
_ -> error
"unexpected close in doc" s spos
5376 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5378 | Vdata
| Vcdata
-> v
5379 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5380 | Vopen
("item", attrs
, closed
) ->
5381 let titleent, spage
, srely
= bookmark_of attrs
in
5382 let page = fromstring int_of_string spos
"page" spage
0
5383 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5384 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5386 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5389 { v with f = skip
"item" f }
5392 error
"unexpected subelement in bookmarks" s spos
5394 | Vclose
"bookmarks" ->
5395 { v with f = doc
path pan
anchor c bookmarks }
5397 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5399 and skip tag
f v t spos
_ =
5401 | Vdata
| Vcdata
-> v
5403 error
("unexpected end of input in skipped " ^ tag
) s spos
5404 | Vopen
(tag'
, _, closed
) ->
5408 let f'
() = { v with f = skip tag
f } in
5409 { v with f = skip tag'
f'
}
5413 else error
("unexpected close in skipped " ^ tag
) s spos
5416 parse
{ f = toplevel; accu = () } s;
5422 let len = in_channel_length ic
in
5423 let s = String.create
len in
5424 really_input ic
s 0 len;
5427 | Parse_error
(msg
, s, pos
) ->
5428 let subs = subs s pos
in
5429 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5430 failwith
("parse error: " ^
s)
5433 failwith
("config load error: " ^
Printexc.to_string exn
)
5439 let dir = Filename.concat
home ".config" in
5440 if Sys.is_directory
dir then dir else home
5443 Filename.concat
dir "llpp.conf"
5446 let confpath = ref defconfpath;;
5449 if Sys.file_exists
!confpath
5452 (try Some
(open_in_bin
!confpath)
5455 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5456 Printexc.to_string exn
);
5465 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5466 Printexc.to_string exn
);
5472 f (Hashtbl.create
0, defconf)
5477 let pc, pb
, px, pa
=
5479 Hashtbl.find h (Filename.basename
state.path)
5480 with Not_found
-> dc, [], 0, (0, 0.0)
5484 state.bookmarks <- pb
;
5486 state.scrollw
<- conf.scrollbw
;
5488 then state.anchor <- pa
;
5489 cbput state.hists
.nav pa
;
5494 let add_attrs bb always
dc c =
5497 then Printf.bprintf bb
"\n %s='%b'" s a
5500 then Printf.bprintf bb
"\n %s='%d'" s a
5503 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5506 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5509 then Printf.bprintf bb
"\n %s='%f'" s a
5513 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5517 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5521 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5525 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5531 | Some
(_N
, _A
, _B
) ->
5532 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
5542 else string_of_float
f
5544 Printf.bprintf bb
"\n %s='%s'" s v
5549 | Some
((n, a, b), _) when n > 1 ->
5550 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
5556 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
5561 then dc.winw, dc.winh
5563 match state.fullscreen
with
5565 | None
-> c.winw, c.winh
5567 let zoom, presentation, interpagespace, maxwait
=
5569 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5571 match state.mode with
5572 | Birdseye
(bc
, _, _, _, _) ->
5573 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5574 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5576 oi
"width" w dc.winw;
5577 oi
"height" h dc.winh
;
5578 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5579 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5580 ob "case-insensitive-search" c.icase
dc.icase
;
5581 ob "preload" c.preload dc.preload;
5582 oi
"page-bias" c.pagebias
dc.pagebias
;
5583 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5584 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5585 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5586 ob "crop-hack" c.crophack
dc.crophack
;
5587 oW
"throttle" maxwait
dc.maxwait
;
5588 ob "highlight-links" c.hlinks
dc.hlinks
;
5589 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5590 oi
"vertical-margin" interpagespace dc.interpagespace;
5591 oz
"zoom" zoom dc.zoom;
5592 ob "presentation" presentation dc.presentation;
5593 oi
"rotation-angle" c.angle
dc.angle
;
5594 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5595 ob "proportional-display" c.proportional
dc.proportional
;
5596 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5597 oi
"tex-count" c.texcount
dc.texcount
;
5598 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5599 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5600 ob "persistent-location" c.jumpback
dc.jumpback
;
5601 oc
"background-color" c.bgcolor
dc.bgcolor
;
5602 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5603 oi
"tile-width" c.tilew
dc.tilew
;
5604 oi
"tile-height" c.tileh
dc.tileh
;
5605 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
5606 ob "checkers" c.checkers
dc.checkers
;
5607 oi
"aalevel" c.aalevel
dc.aalevel
;
5608 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5609 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5610 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5611 oC
"color-space" c.colorspace
dc.colorspace
;
5612 ob "invert-colors" c.invert
dc.invert
;
5613 oF
"brightness" c.colorscale
dc.colorscale
;
5614 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5615 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
5616 oco
"columns" c.columns
dc.columns
;
5617 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
5619 then ob "wmclass-hack" !wmclasshack false;
5623 let uifontsize = fstate.fontsize
in
5624 let bb = Buffer.create
32768 in
5626 let dc = if conf.bedefault
then conf else dc in
5627 Buffer.add_string
bb "<llppconfig>\n";
5629 if String.length
!fontpath > 0
5631 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5637 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5640 Buffer.add_string
bb "<defaults ";
5641 add_attrs bb true dc dc;
5642 Buffer.add_string
bb "/>\n";
5644 let adddoc path pan
anchor c bookmarks =
5645 if bookmarks == [] && c = dc && anchor = emptyanchor
5648 Printf.bprintf
bb "<doc path='%s'"
5649 (enent
path 0 (String.length
path));
5651 if anchor <> emptyanchor
5653 let n, y = anchor in
5654 Printf.bprintf
bb " page='%d'" n;
5657 Printf.bprintf
bb " rely='%f'" y
5662 then Printf.bprintf
bb " pan='%d'" pan
;
5664 add_attrs bb false dc c;
5666 begin match bookmarks with
5667 | [] -> Buffer.add_string
bb "/>\n"
5669 Buffer.add_string
bb ">\n<bookmarks>\n";
5670 List.iter
(fun (title, _level
, (page, rely)) ->
5672 "<item title='%s' page='%d'"
5673 (enent
title 0 (String.length
title))
5678 Printf.bprintf
bb " rely='%f'" rely
5680 Buffer.add_string
bb "/>\n";
5682 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5688 match state.mode with
5689 | Birdseye
(_, pan, _, _, _) -> pan
5692 let basename = Filename.basename state.path in
5693 adddoc basename pan (getanchor ())
5696 match state.autoscroll
with
5698 | None
-> conf.autoscrollstep
}
5699 (if conf.savebmarks
then state.bookmarks else []);
5701 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5703 then adddoc path x y c bookmarks
5705 Buffer.add_string
bb "</llppconfig>";
5708 if Buffer.length
bb > 0
5711 let tmp = !confpath ^
".tmp" in
5712 let oc = open_out_bin
tmp in
5713 Buffer.output_buffer
oc bb;
5715 Unix.rename
tmp !confpath;
5718 ("error while saving configuration: " ^
Printexc.to_string exn
)
5725 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5726 "<password> Set password");
5728 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5729 "<path> Set path to the user interface font");
5731 ("-c", Arg.String
(fun s -> Config.confpath := s),
5732 "<path> Set path to the configuration file");
5734 ("-v", Arg.Unit
(fun () ->
5736 "%s\nconfiguration path: %s\n"
5740 exit
0), " Print version and exit");
5743 (fun s -> state.path <- s)
5744 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5746 if String.length
state.path = 0
5747 then (prerr_endline
"file name missing"; exit
1);
5751 let _ = Glut.init
Sys.argv
in
5752 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5753 let () = Glut.initWindowSize
conf.winw conf.winh
in
5754 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5756 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5757 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5758 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5763 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5765 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5766 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5767 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5768 Unix.bind
sock addr;
5770 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5771 Unix.connect
csock addr;
5772 let ssock, _ = Unix.accept
sock in
5775 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5776 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5783 let () = Glut.displayFunc
display in
5784 let () = Glut.reshapeFunc
reshape in
5785 let () = Glut.keyboardFunc
keyboard in
5786 let () = Glut.specialFunc
special in
5787 let () = Glut.idleFunc
(Some
idle) in
5788 let () = Glut.mouseFunc
mouse in
5789 let () = Glut.motionFunc
motion in
5790 let () = Glut.passiveMotionFunc
pmotion in
5792 setcheckers conf.checkers
;
5794 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5795 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
5796 !Config.wmclasshack, !Config.fontpath
5798 state.csock <- csock;
5799 state.ssock <- ssock;
5800 state.text <- "Opening " ^
state.path;
5801 setaalevel
conf.aalevel
;
5802 writeopen state.path state.password
;
5804 setfontsize fstate.fontsize
;
5812 | Glut.BadEnum
"key in special_of_int" ->
5813 showtext '
!'
" LablGlut bug: special key not recognized";
5820 | exn
when conf.redirectstderr ->
5822 Printf.sprintf
"exception %s\n%s"
5823 (Printexc.to_string exn
)
5824 (Printexc.get_backtrace
())
5827 Unix.single_write
state.stderr
s 0 (String.length
s);