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 a.(pageno
) <- (pdimno, x, y, pdim
);
1484 loop (pageno
+1) pdimno pdim
x y rowh pdims
1486 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1487 let rec fix n rowh
= if n = Array.length
a then () else
1488 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(n) in
1490 if n mod columns
= 0
1496 let y = y + (rowh - h) / 2 in
1497 a.(n) <- (pdimno, x, y, pdim
);
1502 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1504 docolumns conf.columns
;
1505 state.maxy <- calcheight ();
1507 if state.w <= conf.winw
- state.scrollw
1511 match state.mode
with
1512 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1513 let y, h = getpageyh pageno
in
1514 let top = (conf.winh
- h) / 2 in
1515 gotoy (max
0 (y - top))
1516 | _
-> gotoanchor state.anchor
1520 let firsttime = ref true in
1522 GlDraw.viewport
0 0 w h;
1523 if state.invalidated
= 0 && not
!firsttime
1524 then state.anchor <- getanchor ();
1528 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1532 setfontsize fstate.fontsize
;
1533 GlMat.mode `modelview
;
1534 GlMat.load_identity
();
1536 GlMat.mode `projection
;
1537 GlMat.load_identity
();
1538 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1539 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1540 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1543 match conf.columns
with
1545 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1548 wcmd "geometry" [`i
w; `i
h];
1552 let len = String.length
state.text in
1555 match state.mode
with
1556 | View
-> state.hscrollh
1561 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1562 (x+.w, float (conf.winh
- hscrollh))
1565 let w = float (conf.winw
- state.scrollw
- 1) in
1566 if state.progress
>= 0.0 && state.progress
< 1.0
1568 GlDraw.color
(0.3, 0.3, 0.3);
1569 let w1 = w *. state.progress
in
1571 GlDraw.color
(0.0, 0.0, 0.0);
1575 GlDraw.color
(0.0, 0.0, 0.0);
1579 GlDraw.color
(1.0, 1.0, 1.0);
1580 drawstring fstate.fontsize
1581 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1584 match state.mode
with
1585 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1589 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1591 Printf.sprintf
"%s%s_" prefix
text
1600 if not
(istextentry state.mode
)
1602 let s1 = "(press 'e' to review error messasges)" in
1603 if String.length
s > 0 then s ^
" " ^
s1 else s1
1608 if String.length
s > 0
1613 state.text <- Printf.sprintf
"%c%s" c s;
1614 G.postRedisplay "showtext";
1618 let len = Queue.length
state.tilelru
in
1620 if state.memused
<= conf.memlimit
1625 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1626 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1627 let (_
, pw
, ph
, _
) = getpagedim n in
1630 && colorspace
= conf.colorspace
1631 && angle
= conf.angle
1636 match state.throttle
with
1639 then preloadlayout state.layout
1641 | Some
(layout, _
, _
) ->
1644 let x = col*conf.tilew
1645 and y = row*conf.tileh
in
1646 tilevisible layout n x y
1648 then Queue.push lruitem
state.tilelru
1650 wcmd "freetile" [`
s p
];
1651 state.memused
<- state.memused
- s;
1652 state.uioh#infochanged Memused
;
1653 Hashtbl.remove
state.tilemap k
;
1662 Queue.iter
(fun (k
, p
, s) ->
1663 wcmd "freetile" [`
s p
];
1664 state.memused
<- state.memused
- s;
1665 state.uioh#infochanged Memused
;
1666 Hashtbl.remove
state.tilemap k
;
1668 Queue.clear
state.tilelru
;
1672 let logcurrently = function
1673 | Idle
-> dolog "Idle"
1674 | Loading
(l
, gen
) ->
1675 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1676 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1678 "Tiling %d[%d,%d] page=%s cs=%s angle"
1679 l
.pageno
col row pageopaque
1680 (colorspace_to_string colorspace
)
1682 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1683 angle gen
conf.angle
state.gen
1685 conf.tilew
conf.tileh
1692 (* dolog "%S" cmds; *)
1695 try String.index cmds ' '
1696 with Not_found
-> -1
1701 let l = String.length cmds
in
1702 let op = String.sub cmds
0 spacepos in
1704 if l - spacepos < 2 then ""
1705 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1710 state.uioh#infochanged Pdim
;
1714 state.rects
<- state.rects1
;
1715 G.postRedisplay "clearrects";
1719 try Scanf.sscanf args
"%u" (fun n -> n)
1721 dolog "error processing 'continue' %S: %s"
1722 cmds
(Printexc.to_string exn
);
1725 state.pagecount
<- n;
1726 state.invalidated
<- state.invalidated
- 1;
1727 begin match state.currently
with
1729 state.currently
<- Idle
;
1730 state.outlines
<- Array.of_list
(List.rev
l)
1733 if state.invalidated
= 0
1735 if conf.maxwait
= None
1736 then G.postRedisplay "continue";
1739 Glut.setWindowTitle args
1746 then showtext ' ' args
1749 let progress, text =
1751 Scanf.sscanf args
"%f %n"
1753 f, String.sub args pos
(String.length args
- pos
))
1755 dolog "error processing 'progress' %S: %s"
1756 cmds
(Printexc.to_string exn
);
1760 state.progress <- progress;
1761 G.postRedisplay "progress"
1764 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1766 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1767 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1768 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1770 dolog "error processing 'firstmatch' %S: %s"
1771 cmds
(Printexc.to_string exn
);
1774 let y = (getpagey pageno) + truncate y0
in
1777 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)]
1780 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1782 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1783 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1784 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1786 dolog "error processing 'match' %S: %s"
1787 cmds
(Printexc.to_string exn
);
1791 (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) :: state.rects1
1796 Scanf.sscanf args
"%s %f" (fun p t
-> p
, t
)
1798 dolog "error processing 'page' %S: %s"
1799 cmds
(Printexc.to_string exn
);
1802 begin match state.currently
with
1803 | Loading
(l, gen
) ->
1804 vlog "page %d took %f sec" l.pageno t
;
1805 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1806 begin match state.throttle
with
1808 let preloadedpages =
1810 then preloadlayout state.layout
1815 Set.Make
(struct type t
= int let compare = (-) end) in
1817 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1818 IntSet.empty
preloadedpages
1821 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
1822 if not
(IntSet.mem
pageno set)
1824 wcmd "freepage" [`
s opaque
];
1830 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1833 state.currently
<- Idle
;
1836 tilepage l.pageno pageopaque state.layout;
1838 load preloadedpages;
1839 if pagevisible state.layout l.pageno
1840 && layoutready state.layout
1841 then G.postRedisplay "page";
1844 | Some
(layout, _
, _
) ->
1845 state.currently
<- Idle
;
1846 tilepage l.pageno pageopaque layout;
1851 dolog "Inconsistent loading state";
1852 logcurrently state.currently
;
1857 let (x, y, opaque
, size
, t
) =
1859 Scanf.sscanf args
"%u %u %s %u %f"
1860 (fun x y p size t
-> (x, y, p
, size
, t
))
1862 dolog "error processing 'tile' %S: %s"
1863 cmds
(Printexc.to_string exn
);
1866 begin match state.currently
with
1867 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1868 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1870 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1872 wcmd "freetile" [`
s opaque
];
1873 state.currently
<- Idle
;
1877 puttileopaque l col row gen cs angle opaque size t
;
1878 state.memused
<- state.memused
+ size
;
1879 state.uioh#infochanged Memused
;
1881 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1882 opaque
, size
) state.tilelru
;
1885 match state.throttle
with
1886 | None
-> state.layout
1887 | Some
(layout, _
, _
) -> layout
1890 state.currently
<- Idle
;
1892 && conf.colorspace
= cs
1893 && conf.angle
= angle
1894 && tilevisible layout l.pageno x y
1895 then conttiling l.pageno pageopaque;
1897 begin match state.throttle
with
1899 preload state.layout;
1901 && conf.colorspace
= cs
1902 && conf.angle
= angle
1903 && tilevisible state.layout l.pageno x y
1904 then G.postRedisplay "tile nothrottle";
1906 | Some
(layout, y, _
) ->
1907 let ready = layoutready layout in
1911 state.layout <- layout;
1912 state.throttle
<- None
;
1913 G.postRedisplay "throttle";
1920 dolog "Inconsistent tiling state";
1921 logcurrently state.currently
;
1928 Scanf.sscanf args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1930 dolog "error processing 'pdim' %S: %s"
1931 cmds
(Printexc.to_string exn
);
1934 state.uioh#infochanged Pdim
;
1935 state.pdims
<- pdim :: state.pdims
1938 let (l, n, t
, h, pos
) =
1940 Scanf.sscanf args
"%u %u %d %u %n"
1941 (fun l n t
h pos
-> l, n, t
, h, pos
)
1943 dolog "error processing 'o' %S: %s"
1944 cmds
(Printexc.to_string exn
);
1947 let s = String.sub args pos
(String.length args
- pos
) in
1948 let outline = (s, l, (n, float t
/. float h)) in
1949 begin match state.currently
with
1950 | Outlining outlines
->
1951 state.currently
<- Outlining
(outline :: outlines
)
1953 state.currently
<- Outlining
[outline]
1955 dolog "invalid outlining state";
1956 logcurrently currently
1960 state.docinfo
<- (1, args
) :: state.docinfo
1963 state.uioh#infochanged Docinfo
;
1964 state.docinfo
<- List.rev
state.docinfo
1967 dolog "unknown cmd `%S'" cmds
1971 if state.deadline
== nan
then state.deadline
<- now ();
1973 match state.errfd
with
1974 | None
-> [state.csock
]
1975 | Some fd
-> [state.csock
; fd
]
1977 let rec loop delay
=
1979 if state.ghyll
== noghyll
1985 then max
0.0 (deadline -. now ())
1988 let r, _
, _
= Unix.select
r [] [] timeout in
1992 begin match state.autoscroll
with
1993 | Some step
when step
!= 0 ->
1994 let y = state.y + step
in
1998 else if y >= state.maxy then 0 else y
2001 if state.mode
= View
2002 then state.text <- "";
2003 state.deadline <- state.deadline +. 0.005;
2006 state.deadline <- state.deadline +. delay
;
2010 let rec checkfds c = function
2012 | fd
:: rest
when fd
= state.csock
->
2013 let cmd = readcmd state.csock
in
2017 let s = String.create
80 in
2018 let n = Unix.read fd
s 0 80 in
2019 if conf.redirectstderr
2021 Buffer.add_substring
state.errmsgs
s 0 n;
2022 state.newerrmsgs
<- true;
2023 Glut.postRedisplay ();
2026 prerr_string
(String.sub
s 0 n);
2039 let action = function
2040 | HCprev
-> cbget cb ~
-1
2041 | HCnext
-> cbget cb
1
2042 | HCfirst
-> cbget cb ~
-(cb
.rc)
2043 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2044 and cancel
() = cb
.rc <- rc
2048 let search pattern forward
=
2049 if String.length pattern
> 0
2052 match state.layout with
2055 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2058 let b = makecmd "search"
2059 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
2061 Buffer.add_char
b '
,'
;
2062 Buffer.add_string
b pattern
;
2063 Buffer.add_char
b '
\000'
;
2066 writecmd state.csock
cmd;
2069 let intentry text key =
2070 let c = Char.unsafe_chr
key in
2073 let text = addchar text c in
2077 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2081 let textentry text key =
2082 let c = Char.unsafe_chr
key in
2084 | _
when key >= 32 && key < 127 ->
2085 let text = addchar text c in
2089 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
2093 let reqlayout angle proportional
=
2094 match state.throttle
with
2096 if state.invalidated
= 0 then state.anchor <- getanchor ();
2097 conf.angle
<- angle
mod 360;
2098 conf.proportional
<- proportional
;
2100 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
2104 let settrim trimmargins trimfuzz
=
2105 if state.invalidated
= 0 then state.anchor <- getanchor ();
2106 conf.trimmargins
<- trimmargins
;
2107 conf.trimfuzz
<- trimfuzz
;
2108 let x0, y0
, x1
, y1 = trimfuzz
in
2111 `
b conf.trimmargins
;
2117 Hashtbl.iter
(fun _ opaque
->
2118 wcmd "freepage" [`
s opaque
];
2120 Hashtbl.clear
state.pagemap
;
2124 match state.throttle
with
2126 let zoom = max
0.01 zoom in
2127 if zoom <> conf.zoom
2129 state.prevzoom
<- conf.zoom;
2132 then (state.x <- 0; 0.0)
2133 else float state.x /. float state.w
2136 reshape conf.winw
conf.winh
;
2139 let x = relx *. float state.w in
2140 state.x <- truncate
x;
2142 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2145 | Some
(layout, y, started
) ->
2147 match conf.maxwait
with
2151 let dt = now () -. started
in
2159 let setcolumns columns coverA coverB
=
2162 conf.columns
<- None
;
2167 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2170 reshape conf.winw
conf.winh
;
2173 let enterbirdseye () =
2174 let zoom = float conf.thumbw
/. float conf.winw
in
2175 let birdseyepageno =
2176 let cy = conf.winh
/ 2 in
2180 let rec fold best
= function
2183 let d = cy - (l.pagedispy + l.pagevh/2)
2184 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2185 if abs
d < abs dbest
2192 state.mode
<- Birdseye
(
2193 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2196 conf.presentation <- false;
2197 conf.interpagespace <- 10;
2198 conf.hlinks
<- false;
2200 state.mstate
<- Mnone
;
2201 conf.maxwait
<- None
;
2203 match conf.beyecolumns
with
2206 Some
((c, 0, 0), [||])
2209 Glut.setCursor
Glut.CURSOR_INHERIT
;
2212 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2217 reshape conf.winw
conf.winh
;
2220 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2222 conf.zoom <- c.zoom;
2223 conf.presentation <- c.presentation;
2224 conf.interpagespace <- c.interpagespace;
2225 conf.maxwait
<- c.maxwait
;
2226 conf.hlinks
<- c.hlinks
;
2227 conf.beyecolumns
<- (
2228 match conf.columns
with
2229 | Some
((c, _
, _
), _
) -> Some
c
2233 match c.columns
with
2234 | Some
(c, _
) -> Some
(c, [||])
2240 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2243 reshape conf.winw
conf.winh
;
2244 state.anchor <- if goback
then anchor else (pageno, 0.0);
2247 let togglebirdseye () =
2248 match state.mode
with
2249 | Birdseye vals
-> leavebirdseye vals
true
2250 | View
-> enterbirdseye ()
2254 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2255 let pageno = max
0 (pageno - incr
) in
2256 let rec loop = function
2257 | [] -> gotopage1 pageno 0
2258 | l :: _
when l.pageno = pageno ->
2259 if l.pagedispy >= 0 && l.pagey = 0
2260 then G.postRedisplay "upbirdseye"
2261 else gotopage1 pageno 0
2262 | _
:: rest
-> loop rest
2265 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2268 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2269 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2270 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2271 let rec loop = function
2273 let y, h = getpageyh pageno in
2274 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2276 | l :: _
when l.pageno = pageno ->
2277 if l.pagevh != l.pageh
2278 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2279 else G.postRedisplay "downbirdseye"
2280 | _
:: rest
-> loop rest
2285 let optentry mode _
key =
2286 let btos b = if b then "on" else "off" in
2287 let c = Char.unsafe_chr
key in
2291 try conf.scrollstep
<- int_of_string
s with exc
->
2292 state.text <- Printf.sprintf
"bad integer `%s': %s"
2293 s (Printexc.to_string exc
)
2295 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2300 conf.autoscrollstep
<- int_of_string
s;
2301 if state.autoscroll
<> None
2302 then state.autoscroll
<- Some
conf.autoscrollstep
2304 state.text <- Printf.sprintf
"bad integer `%s': %s"
2305 s (Printexc.to_string exc
)
2307 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2312 let n, a, b = columns_of_string s in
2315 state.text <- Printf.sprintf
"bad columns `%s': %s"
2316 s (Printexc.to_string exc
)
2318 TEswitch
("columns: ", "", None
, textentry, ondone)
2323 let zoom = float (int_of_string
s) /. 100.0 in
2326 state.text <- Printf.sprintf
"bad integer `%s': %s"
2327 s (Printexc.to_string exc
)
2329 TEswitch
("zoom: ", "", None
, intentry, ondone)
2334 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2336 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2337 begin match mode
with
2339 leavebirdseye beye
false;
2344 state.text <- Printf.sprintf
"bad integer `%s': %s"
2345 s (Printexc.to_string exc
)
2347 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2352 Some
(int_of_string
s)
2354 state.text <- Printf.sprintf
"bad integer `%s': %s"
2355 s (Printexc.to_string exc
);
2358 | Some angle
-> reqlayout angle
conf.proportional
2361 TEswitch
("rotation: ", "", None
, intentry, ondone)
2364 conf.icase
<- not
conf.icase
;
2365 TEdone
("case insensitive search " ^
(btos conf.icase
))
2368 conf.preload <- not
conf.preload;
2370 TEdone
("preload " ^
(btos conf.preload))
2373 conf.verbose
<- not
conf.verbose
;
2374 TEdone
("verbose " ^
(btos conf.verbose
))
2377 conf.debug
<- not
conf.debug
;
2378 TEdone
("debug " ^
(btos conf.debug
))
2381 conf.maxhfit
<- not
conf.maxhfit
;
2383 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2384 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2387 conf.crophack
<- not
conf.crophack
;
2388 TEdone
("crophack " ^
btos conf.crophack
)
2392 match conf.maxwait
with
2394 conf.maxwait
<- Some infinity
;
2395 "always wait for page to complete"
2397 conf.maxwait
<- None
;
2398 "show placeholder if page is not ready"
2403 conf.underinfo
<- not
conf.underinfo
;
2404 TEdone
("underinfo " ^
btos conf.underinfo
)
2407 conf.savebmarks
<- not
conf.savebmarks
;
2408 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2414 match state.layout with
2419 conf.interpagespace <- int_of_string
s;
2420 state.maxy <- calcheight ();
2421 let y = getpagey pageno in
2424 state.text <- Printf.sprintf
"bad integer `%s': %s"
2425 s (Printexc.to_string exc
)
2427 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2430 reqlayout conf.angle
(not
conf.proportional
);
2431 TEdone
("proportional display " ^
btos conf.proportional
)
2434 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2435 TEdone
("trim margins " ^
btos conf.trimmargins
)
2438 conf.invert
<- not
conf.invert
;
2439 TEdone
("invert colors " ^
btos conf.invert
)
2442 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2446 class type lvsource
= object
2447 method getitemcount
: int
2448 method getitem
: int -> (string * int)
2449 method hasaction
: int -> bool
2458 method getactive
: int
2459 method getfirst
: int
2460 method getqsearch
: string
2461 method setqsearch
: string -> unit
2465 class virtual lvsourcebase
= object
2466 val mutable m_active
= 0
2467 val mutable m_first
= 0
2468 val mutable m_qsearch
= ""
2469 val mutable m_pan
= 0
2470 method getactive
= m_active
2471 method getfirst
= m_first
2472 method getqsearch
= m_qsearch
2473 method getpan
= m_pan
2474 method setqsearch
s = m_qsearch
<- s
2477 let textentryspecial key = function
2478 | ((c, _
, (Some
(action, _
) as onhist), onkey
, ondone), mode
) ->
2481 | Glut.KEY_UP
-> action HCprev
2482 | Glut.KEY_DOWN
-> action HCnext
2483 | Glut.KEY_HOME
-> action HCfirst
2484 | Glut.KEY_END
-> action HClast
2487 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2488 G.postRedisplay "special textentry";
2492 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2494 state.mode
<- Textentry
(te
, onleave
);
2497 G.postRedisplay "textentrykeyboard enttext";
2499 match Char.unsafe_chr
key with
2500 | '
\008'
-> (* backspace *)
2501 let len = String.length
text in
2505 G.postRedisplay "textentrykeyboard after cancel";
2508 let s = String.sub
text 0 (len - 1) in
2509 enttext (c, s, opthist
, onkey
, ondone)
2515 G.postRedisplay "textentrykeyboard after confirm"
2517 | '
\007'
(* ctrl-g *)
2518 | '
\027'
-> (* escape *)
2519 if String.length
text = 0
2521 begin match opthist
with
2523 | Some
(_
, onhistcancel
) -> onhistcancel
()
2527 G.postRedisplay "textentrykeyboard after cancel2"
2530 enttext (c, "", opthist
, onkey
, ondone)
2533 | '
\127'
-> () (* delete *)
2536 begin match onkey
text key with
2540 G.postRedisplay "textentrykeyboard after confirm2";
2543 enttext (c, text, opthist
, onkey
, ondone);
2547 G.postRedisplay "textentrykeyboard after cancel3"
2550 state.mode
<- Textentry
(te
, onleave
);
2551 G.postRedisplay "textentrykeyboard switch";
2555 let firstof first active
=
2556 if first
> active
|| abs
(first
- active
) > fstate.maxrows
- 1
2557 then max
0 (active
- (fstate.maxrows
/2))
2561 let calcfirst first active
=
2564 let rows = active
- first
in
2565 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2569 let scrollph y maxy =
2570 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2571 let sh = float conf.winh
/. sh in
2572 let sh = max
sh (float conf.scrollh
) in
2577 else float y /. float maxy
2579 let position = (float conf.winh
-. sh) *. percent in
2582 if position +. sh > float conf.winh
2583 then float conf.winh
-. sh
2589 let coe s = (s :> uioh
);;
2591 class listview ~
(source
:lvsource
) ~trusted
=
2593 val m_pan
= source#getpan
2594 val m_first
= source#getfirst
2595 val m_active
= source#getactive
2596 val m_qsearch
= source#getqsearch
2597 val m_prev_uioh
= state.uioh
2599 method private elemunder
y =
2600 let n = y / (fstate.fontsize
+1) in
2601 if m_first
+ n < source#getitemcount
2603 if source#hasaction
(m_first
+ n)
2604 then Some
(m_first
+ n)
2611 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2612 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2613 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2614 GlDraw.color
(1., 1., 1.);
2615 Gl.enable `texture_2d
;
2616 let fs = fstate.fontsize
in
2618 let ww = fstate.wwidth
in
2619 let tabw = 30.0*.ww in
2620 let itemcount = source#getitemcount
in
2622 if (row - m_first
) * nfs > conf.winh
2625 if row >= 0 && row < itemcount
2627 let (s, level
) = source#getitem
row in
2628 let y = (row - m_first
) * nfs in
2629 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2632 Gl.disable `texture_2d
;
2633 GlDraw.polygon_mode `both `line
;
2634 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2635 GlDraw.rect (1., float (y + 1))
2636 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2637 GlDraw.polygon_mode `both `fill
;
2638 GlDraw.color
(1., 1., 1.);
2639 Gl.enable `texture_2d
;
2642 let drawtabularstring s =
2643 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2646 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2649 let len = String.length
s - tabpos - 1 in
2650 let s1 = String.sub
s 0 tabpos
2651 and s2
= String.sub
s (tabpos + 1) len in
2652 let nx = drawstr x s1 in
2654 let x = x +. (max
tabw sw) in
2661 let _ = drawtabularstring s in
2668 Gl.disable `texture_2d
;
2670 method updownlevel incr
=
2671 let len = source#getitemcount
in
2673 if m_active
>= 0 && m_active
< len
2674 then snd
(source#getitem m_active
)
2678 if i
= len then i
-1 else if i
= -1 then 0 else
2679 let _, l = source#getitem i
in
2680 if l != curlevel then i
else flow (i
+incr
)
2682 let active = flow m_active
in
2683 let first = calcfirst m_first
active in
2684 G.postRedisplay "special outline updownlevel";
2685 {< m_active
= active; m_first
= first >}
2687 method private key1
key =
2688 let set active first qsearch
=
2689 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2691 let search active pattern incr
=
2694 if n >= 0 && n < source#getitemcount
2696 let s, _ = source#getitem
n in
2698 (try ignore
(Str.search_forward
re s 0); true
2699 with Not_found
-> false)
2701 else loop (n + incr
)
2708 let re = Str.regexp_case_fold pattern
in
2715 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2716 let incr = if key = 18 then -1 else 1 in
2718 match search (m_active
+ incr) m_qsearch
incr with
2720 state.text <- m_qsearch ^
" [not found]";
2723 state.text <- m_qsearch
;
2724 active, firstof m_first
active
2726 G.postRedisplay "listview ctrl-r/s";
2727 set active first m_qsearch
;
2729 | 8 -> (* backspace *)
2730 let len = String.length m_qsearch
in
2737 G.postRedisplay "listview empty qsearch";
2738 set m_active m_first
"";
2741 let qsearch = String.sub m_qsearch
0 (len - 1) in
2743 match search m_active
qsearch ~
-1 with
2745 state.text <- qsearch ^
" [not found]";
2748 state.text <- qsearch;
2749 active, firstof m_first
active
2751 G.postRedisplay "listview backspace qsearch";
2752 set active first qsearch
2755 | _ when key >= 32 && key < 127 ->
2756 let pattern = addchar m_qsearch
(Char.chr
key) in
2758 match search m_active
pattern 1 with
2760 state.text <- pattern ^
" [not found]";
2763 state.text <- pattern;
2764 active, firstof m_first
active
2766 G.postRedisplay "listview qsearch add";
2767 set active first pattern;
2769 | 27 -> (* escape *)
2771 if String.length m_qsearch
= 0
2773 G.postRedisplay "list view escape";
2776 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2778 | None
-> m_prev_uioh
2783 G.postRedisplay "list view kill qsearch";
2784 source#setqsearch
"";
2785 coe {< m_qsearch
= "" >}
2790 let self = {< m_qsearch
= "" >} in
2791 source#setqsearch
"";
2793 G.postRedisplay "listview enter";
2794 if m_active
>= 0 && m_active
< source#getitemcount
2796 source#exit
(coe self) false m_active m_first m_pan
"";
2799 source#exit
(coe self) true m_active m_first m_pan
"";
2802 begin match opt with
2803 | None
-> m_prev_uioh
2807 | 127 -> (* delete *)
2810 | _ -> dolog "unknown key %d" key; coe self
2812 method private special1
key =
2813 let itemcount = source#getitemcount
in
2814 let find start
incr =
2816 if i
= -1 || i
= itemcount
2819 if source#hasaction i
2821 else find (i
+ incr)
2826 let set active first =
2827 let first = bound first 0 (itemcount - fstate.maxrows
) in
2829 coe {< m_active
= active; m_first
= first >}
2832 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2834 let incr1 = if incr > 0 then 1 else -1 in
2835 if isvisible m_first m_active
2838 let next = m_active
+ incr in
2840 if next < 0 || next >= itemcount
2842 else find next incr1
2844 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2850 let first = m_first
+ incr in
2851 let first = bound first 0 (itemcount - 1) in
2853 let next = m_active
+ incr in
2854 let next = bound next 0 (itemcount - 1) in
2857 let active = if next = -1 then m_active
else next in
2860 let first = min
next m_first
in
2862 if abs
(next - first) > fstate.maxrows
2868 let first = m_first
+ incr in
2869 let first = bound first 0 (itemcount - 1) in
2871 let next = m_active
+ incr in
2872 let next = bound next 0 (itemcount - 1) in
2873 let next = find next incr1 in
2875 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2877 let active = if m_active
= -1 then next else m_active
in
2882 if isvisible first active
2888 G.postRedisplay "listview navigate";
2891 begin match key with
2892 | Glut.KEY_UP
-> navigate ~
-1
2893 | Glut.KEY_DOWN
-> navigate 1
2894 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2895 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2899 G.postRedisplay "listview right";
2900 coe {< m_pan
= m_pan
- 1 >}
2904 G.postRedisplay "listview left";
2905 coe {< m_pan
= m_pan
+ 1 >}
2908 let active = find 0 1 in
2909 G.postRedisplay "listview home";
2913 let first = max
0 (itemcount - fstate.maxrows
) in
2914 let active = find (itemcount - 1) ~
-1 in
2915 G.postRedisplay "listview end";
2922 match state.mode
with
2923 | Textentry te
-> textentrykeyboard key te
; coe self
2924 | _ -> self#key1
key
2926 method special
key =
2927 match state.mode
with
2928 | Textentry te
-> textentryspecial key te
; coe self
2929 | _ -> self#special1
key
2931 method button button bstate
x y =
2934 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollbw
->
2935 G.postRedisplay "listview scroll";
2936 if bstate
= Glut.DOWN
2938 let _, position, sh = self#
scrollph in
2939 if y > truncate
position && y < truncate
(position +. sh)
2941 state.mstate
<- Mscrolly
;
2945 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2946 let first = truncate
(s *. float source#getitemcount
) in
2947 let first = min source#getitemcount
first in
2948 Some
(coe {< m_first
= first; m_active
= first >})
2950 state.mstate
<- Mnone
;
2953 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2954 begin match self#elemunder
y with
2956 G.postRedisplay "listview click";
2958 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
2962 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2963 let len = source#getitemcount
in
2965 if n = 4 && m_first
+ fstate.maxrows
>= len
2969 let first = m_first
+ (if n == 3 then -1 else 1) in
2970 bound first 0 (len - 1)
2972 G.postRedisplay "listview wheel";
2973 Some
(coe {< m_first
= first >})
2978 | None
-> m_prev_uioh
2982 match state.mstate
with
2984 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2985 let first = truncate
(s *. float source#getitemcount
) in
2986 let first = min source#getitemcount
first in
2987 G.postRedisplay "listview motion";
2988 coe {< m_first
= first; m_active
= first >}
2991 method pmotion
x y =
2992 if x < conf.winw
- conf.scrollbw
2995 match self#elemunder
y with
2996 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
2997 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
3001 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3006 Glut.setCursor
Glut.CURSOR_INHERIT
;
3010 method infochanged
_ = ()
3012 method scrollpw
= (0, 0.0, 0.0)
3014 let nfs = fstate.fontsize
+ 1 in
3015 let y = m_first
* nfs in
3016 let itemcount = source#getitemcount
in
3017 let maxi = max
0 (itemcount - fstate.maxrows
) in
3018 let maxy = maxi * nfs in
3019 let p, h = scrollph y maxy in
3023 class outlinelistview ~source
=
3025 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
3029 | 14 -> (* ctrl-n *)
3030 source#narrow m_qsearch
;
3031 G.postRedisplay "outline ctrl-n";
3032 coe {< m_first
= 0; m_active
= 0 >}
3034 | 21 -> (* ctrl-u *)
3036 G.postRedisplay "outline ctrl-u";
3038 coe {< m_first
= 0; m_active
= 0 >}
3040 | 12 -> (* ctrl-l *)
3041 let first = m_active
- (fstate.maxrows
/ 2) in
3042 G.postRedisplay "outline ctrl-l";
3043 coe {< m_first
= first >}
3045 | 127 -> (* delete *)
3046 source#remove m_active
;
3047 G.postRedisplay "outline delete";
3048 let active = max
0 (m_active
-1) in
3049 coe {< m_first
= firstof m_first
active;
3050 m_active
= active >}
3052 | key -> super#
key key
3054 method special
key =
3055 let calcfirst first active =
3058 let rows = active - first in
3059 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3063 let active = m_active
+ incr in
3064 let active = bound active 0 (source#getitemcount
- 1) in
3065 let first = calcfirst m_first
active in
3066 G.postRedisplay "special outline navigate";
3067 coe {< m_active
= active; m_first
= first >}
3070 | Glut.KEY_UP
-> navigate ~
-1
3071 | Glut.KEY_DOWN
-> navigate 1
3072 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
3073 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
3077 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
3079 G.postRedisplay "special outline right";
3080 {< m_pan
= m_pan
+ 1 >}
3082 else self#updownlevel
1
3088 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
3090 G.postRedisplay "special outline left";
3091 {< m_pan
= m_pan
- 1 >}
3093 else self#updownlevel ~
-1
3098 G.postRedisplay "special outline home";
3099 coe {< m_first
= 0; m_active
= 0 >}
3102 let active = source#getitemcount
- 1 in
3103 let first = max
0 (active - fstate.maxrows
) in
3104 G.postRedisplay "special outline end";
3105 coe {< m_active
= active; m_first
= first >}
3107 | _ -> super#special
key
3110 let outlinesource usebookmarks
=
3113 inherit lvsourcebase
3114 val mutable m_items
= empty
3115 val mutable m_orig_items
= empty
3116 val mutable m_prev_items
= empty
3117 val mutable m_narrow_pattern
= ""
3118 val mutable m_hadremovals
= false
3120 method getitemcount
=
3121 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3124 if n == Array.length m_items
&& m_hadremovals
3126 ("[Confirm removal]", 0)
3128 let s, n, _ = m_items
.(n) in
3131 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3132 ignore
(uioh
, first, pan
, qsearch);
3133 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3135 if String.length m_narrow_pattern
= 0
3141 if not
confrimremoval
3143 let _, _, anchor = m_items
.(active) in
3148 state.bookmarks
<- Array.to_list m_items
;
3149 m_orig_items
<- m_items
;
3152 else m_items
<- items;
3155 method hasaction
_ = true
3158 if Array.length m_items
!= Array.length m_orig_items
3159 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3162 method narrow
pattern =
3163 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3167 let rec loop accu n =
3170 m_narrow_pattern
<- pattern;
3171 m_items
<- Array.of_list
accu
3174 let (s, _, _) as o = m_items
.(n) in
3176 if (try ignore
(Str.search_forward
re s 0); true
3177 with Not_found
-> false)
3183 loop [] (Array.length m_items
- 1)
3188 then Array.of_list
state.bookmarks
3191 m_items
<- m_orig_items
3196 if m
>= 0 && m
< Array.length m_items
3198 m_hadremovals
<- true;
3199 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3200 let n = if n >= m
then n+1 else n in
3205 method reset
anchor items =
3206 m_hadremovals
<- false;
3207 if m_orig_items
== empty || m_prev_items
!= items
3209 m_orig_items
<- items;
3210 if String.length m_narrow_pattern
= 0
3211 then m_items
<- items;
3213 m_prev_items
<- items;
3214 let rely = getanchory anchor in
3216 let rec loop n best bestd
=
3217 if n = Array.length m_items
3220 let (_, _, anchor) = m_items
.(n) in
3221 let orely = getanchory anchor in
3222 let d = abs
(orely - rely) in
3225 else loop (n+1) best bestd
3230 m_first
<- firstof m_first
active
3234 let enterselector usebookmarks
=
3235 let source = outlinesource usebookmarks
in
3239 then Array.of_list
state.bookmarks
3242 if Array.length
outlines = 0
3244 showtext ' ' errmsg
;
3247 state.text <- source#greetmsg
;
3248 Glut.setCursor
Glut.CURSOR_INHERIT
;
3249 let anchor = getanchor () in
3250 source#reset
anchor outlines;
3251 state.uioh
<- coe (new outlinelistview ~
source);
3252 G.postRedisplay "enter selector";
3256 let enteroutlinemode =
3257 let f = enterselector false in
3258 fun ()-> f "Document has no outline";
3261 let enterbookmarkmode =
3262 let f = enterselector true in
3263 fun () -> f "Document has no bookmarks (yet)";
3266 let color_of_string s =
3267 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3268 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3272 let color_to_string (r, g
, b) =
3273 let r = truncate
(r *. 256.0)
3274 and g
= truncate
(g
*. 256.0)
3275 and b = truncate
(b *. 256.0) in
3276 Printf.sprintf
"%d/%d/%d" r g
b
3279 let irect_of_string s =
3280 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1
y1 -> (x0,y0
,x1
,y1))
3283 let irect_to_string (x0,y0
,x1
,y1) =
3284 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1
y1
3287 let makecheckers () =
3288 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3290 converted by Issac Trotts. July 25, 2002 *)
3291 let image_height = 64
3292 and image_width
= 64 in
3296 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3298 for i
= 0 to image_width
- 1 do
3299 for j
= 0 to image_height - 1 do
3300 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3301 (if (i
land 8 ) lxor (j
land 8) = 0
3302 then [|255;255;255|] else [|200;200;200|])
3307 let image = make_image () in
3308 let id = GlTex.gen_texture
() in
3309 GlTex.bind_texture `texture_2d
id;
3310 GlPix.store
(`unpack_alignment
1);
3311 GlTex.image2d
image;
3312 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3315 `mag_filter `nearest
;
3316 `min_filter `nearest
];
3320 let setcheckers enabled
=
3321 match state.texid
with
3323 if enabled
then state.texid
<- Some
(makecheckers ())
3328 GlTex.delete_texture texid
;
3329 state.texid
<- None
;
3333 let int_of_string_with_suffix s =
3334 let l = String.length
s in
3338 let suffix = Char.lowercase
s.[l-1] in
3340 | 'k'
-> String.sub
s 0 (l-1), 10
3341 | 'm'
-> String.sub
s 0 (l-1), 20
3342 | 'g'
-> String.sub
s 0 (l-1), 30
3346 let n = int_of_string
s1 in
3347 let m = n lsl shift
in
3349 then raise
(Failure
"value too large")
3353 let string_with_suffix_of_int n =
3361 if n land ((1 lsl 20) - 1) = 0
3364 if n land ((1 lsl 10) - 1) = 0
3371 let h = n mod 1000 in
3374 then string_of_int
h ^
s
3376 let s = Printf.sprintf
"_%03d%s" h s in
3383 let defghyllscroll = (40, 8, 32);;
3384 let ghyllscroll_of_string s =
3385 let (n, a, b) as nab
=
3388 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3390 if n <= a || n <= b || a >= b
3391 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3395 let ghyllscroll_to_string ((n, a, b) as nab
) =
3396 if nab
= defghyllscroll
3398 else Printf.sprintf
"%d,%d,%d" n a b;
3401 let describe_location () =
3403 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3405 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3406 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3410 else (100. *. (float state.y /. float maxy))
3414 Printf.sprintf
"page %d of %d [%.2f%%]"
3415 (fn+1) state.pagecount
percent
3418 "pages %d-%d of %d [%.2f%%]"
3419 (fn+1) (ln
+1) state.pagecount
percent
3423 let btos b = if b then "\xe2\x88\x9a" else "" in
3424 let showextended = ref false in
3425 let leave mode
= function
3426 | Confirm
-> state.mode
<- mode
3427 | Cancel
-> state.mode
<- mode
in
3430 val mutable m_first_time
= true
3431 val mutable m_l
= []
3432 val mutable m_a
= [||]
3433 val mutable m_prev_uioh
= nouioh
3434 val mutable m_prev_mode
= View
3436 inherit lvsourcebase
3438 method reset prev_mode prev_uioh
=
3439 m_a
<- Array.of_list
(List.rev m_l
);
3441 m_prev_mode
<- prev_mode
;
3442 m_prev_uioh
<- prev_uioh
;
3446 if n >= Array.length m_a
3450 | _, _, _, Action
_ -> m_active
<- n
3454 m_first_time
<- false;
3457 method int name get
set =
3459 (name
, `
int get
, 1, Action
(
3462 try set (int_of_string
s)
3464 state.text <- Printf.sprintf
"bad integer `%s': %s"
3465 s (Printexc.to_string exn
)
3468 let te = name ^
": ", "", None
, intentry, ondone in
3469 state.mode
<- Textentry
(te, leave m_prev_mode
);
3473 method int_with_suffix name get
set =
3475 (name
, `intws get
, 1, Action
(
3478 try set (int_of_string_with_suffix s)
3480 state.text <- Printf.sprintf
"bad integer `%s': %s"
3481 s (Printexc.to_string exn
)
3485 name ^
": ", "", None
, intentry_with_suffix, ondone
3487 state.mode
<- Textentry
(te, leave m_prev_mode
);
3491 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3493 (name
, `
bool (btos, get
), offset
, Action
(
3500 method color name get
set =
3502 (name
, `color get
, 1, Action
(
3504 let invalid = (nan
, nan
, nan
) in
3507 try color_of_string s
3509 state.text <- Printf.sprintf
"bad color `%s': %s"
3510 s (Printexc.to_string exn
);
3516 let te = name ^
": ", "", None
, textentry, ondone in
3517 state.text <- color_to_string (get
());
3518 state.mode
<- Textentry
(te, leave m_prev_mode
);
3522 method string name get
set =
3524 (name
, `
string get
, 1, Action
(
3526 let ondone s = set s in
3527 let te = name ^
": ", "", None
, textentry, ondone in
3528 state.mode
<- Textentry
(te, leave m_prev_mode
);
3532 method colorspace name get
set =
3534 (name
, `
string get
, 1, Action
(
3537 let vals = [| "rgb"; "bgr"; "gray" |] in
3539 inherit lvsourcebase
3542 m_active
<- int_of_colorspace conf.colorspace
;
3545 method getitemcount
= Array.length
vals
3546 method getitem
n = (vals.(n), 0)
3547 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3548 ignore
(uioh
, first, pan
, qsearch);
3549 if not cancel
then set active;
3551 method hasaction
_ = true
3555 coe (new listview ~
source ~trusted
:true)
3558 method caption
s offset
=
3559 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3561 method caption2
s f offset
=
3562 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3564 method getitemcount
= Array.length m_a
3567 let tostr = function
3568 | `
int f -> string_of_int
(f ())
3569 | `intws
f -> string_with_suffix_of_int (f ())
3571 | `color
f -> color_to_string (f ())
3572 | `
bool (btos, f) -> btos (f ())
3575 let name, t
, offset
, _ = m_a
.(n) in
3576 ((let s = tostr t
in
3577 if String.length
s > 0
3578 then Printf.sprintf
"%s\t%s" name s
3582 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3586 m_qsearch
<- qsearch;
3588 match m_a
.(active) with
3589 | _, _, _, Action
f -> f uioh
3601 method hasaction
n =
3603 | _, _, _, Action
_ -> true
3607 let rec fillsrc prevmode prevuioh
=
3608 let sep () = src#caption
"" 0 in
3609 let colorp name get
set =
3611 (fun () -> color_to_string (get
()))
3614 let c = color_of_string v in
3617 state.text <- Printf.sprintf
"bad color `%s': %s"
3618 v (Printexc.to_string exn
);
3621 let oldmode = state.mode
in
3622 let birdseye = isbirdseye state.mode
in
3624 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3626 src#
bool "presentation mode"
3627 (fun () -> conf.presentation)
3629 conf.presentation <- v;
3630 state.anchor <- getanchor ();
3633 src#
bool "ignore case in searches"
3634 (fun () -> conf.icase
)
3635 (fun v -> conf.icase
<- v);
3638 (fun () -> conf.preload)
3639 (fun v -> conf.preload <- v);
3641 src#
bool "highlight links"
3642 (fun () -> conf.hlinks
)
3643 (fun v -> conf.hlinks
<- v);
3645 src#
bool "under info"
3646 (fun () -> conf.underinfo
)
3647 (fun v -> conf.underinfo
<- v);
3649 src#
bool "persistent bookmarks"
3650 (fun () -> conf.savebmarks
)
3651 (fun v -> conf.savebmarks
<- v);
3653 src#
bool "proportional display"
3654 (fun () -> conf.proportional
)
3655 (fun v -> reqlayout conf.angle
v);
3657 src#
bool "trim margins"
3658 (fun () -> conf.trimmargins
)
3659 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3661 src#
bool "persistent location"
3662 (fun () -> conf.jumpback
)
3663 (fun v -> conf.jumpback
<- v);
3666 src#
int "inter-page space"
3667 (fun () -> conf.interpagespace)
3669 conf.interpagespace <- n;
3671 match state.layout with
3676 state.maxy <- calcheight ();
3677 let y = getpagey pageno in
3682 (fun () -> conf.pagebias
)
3683 (fun v -> conf.pagebias
<- v);
3685 src#
int "scroll step"
3686 (fun () -> conf.scrollstep
)
3687 (fun n -> conf.scrollstep
<- n);
3689 src#
int "auto scroll step"
3691 match state.autoscroll
with
3693 | _ -> conf.autoscrollstep
)
3695 if state.autoscroll
<> None
3696 then state.autoscroll
<- Some
n;
3697 conf.autoscrollstep
<- n);
3700 (fun () -> truncate
(conf.zoom *. 100.))
3701 (fun v -> setzoom ((float v) /. 100.));
3704 (fun () -> conf.angle
)
3705 (fun v -> reqlayout v conf.proportional
);
3707 src#
int "scroll bar width"
3708 (fun () -> state.scrollw
)
3712 reshape conf.winw
conf.winh
;
3715 src#
int "scroll handle height"
3716 (fun () -> conf.scrollh
)
3717 (fun v -> conf.scrollh
<- v;);
3719 src#
int "thumbnail width"
3720 (fun () -> conf.thumbw
)
3722 conf.thumbw
<- min
4096 v;
3725 leavebirdseye beye
false;
3730 src#
string "columns"
3732 match conf.columns
with
3734 | Some
(multicol
, _) -> columns_to_string multicol
)
3736 let n, a, b = columns_of_string v in
3740 src#caption
"Presentation mode" 0;
3741 src#
bool "scrollbar visible"
3742 (fun () -> conf.scrollbarinpm
)
3744 if v != conf.scrollbarinpm
3746 conf.scrollbarinpm
<- v;
3747 if conf.presentation
3749 state.scrollw
<- if v then conf.scrollbw
else 0;
3750 reshape conf.winw
conf.winh
;
3756 src#caption
"Pixmap cache" 0;
3757 src#int_with_suffix
"size (advisory)"
3758 (fun () -> conf.memlimit
)
3759 (fun v -> conf.memlimit
<- v);
3762 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3763 (string_with_suffix_of_int state.memused
)
3764 (Hashtbl.length
state.tilemap
)) 1;
3767 src#caption
"Layout" 0;
3768 src#caption2
"Dimension"
3770 Printf.sprintf
"%dx%d (virtual %dx%d)"
3776 src#caption2
"Position" (fun () ->
3777 Printf.sprintf
"%dx%d" state.x state.y
3780 src#caption2
"Visible" (fun () -> describe_location ()) 1
3784 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3785 "Save these parameters as global defaults at exit"
3786 (fun () -> conf.bedefault
)
3787 (fun v -> conf.bedefault
<- v)
3791 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3792 src#
bool ~offset
:0 ~
btos "Extended parameters"
3793 (fun () -> !showextended)
3794 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3798 (fun () -> conf.checkers
)
3799 (fun v -> conf.checkers
<- v; setcheckers v);
3801 (fun () -> conf.verbose
)
3802 (fun v -> conf.verbose
<- v);
3803 src#
bool "invert colors"
3804 (fun () -> conf.invert
)
3805 (fun v -> conf.invert
<- v);
3807 (fun () -> conf.maxhfit
)
3808 (fun v -> conf.maxhfit
<- v);
3809 src#
bool "redirect stderr"
3810 (fun () -> conf.redirectstderr)
3811 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3812 src#
string "uri launcher"
3813 (fun () -> conf.urilauncher
)
3814 (fun v -> conf.urilauncher
<- v);
3815 src#
string "tile size"
3816 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3819 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3820 conf.tileh
<- max
64 w;
3821 conf.tilew
<- max
64 h;
3824 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3825 v (Printexc.to_string exn
));
3826 src#
int "texture count"
3827 (fun () -> conf.texcount
)
3830 then conf.texcount
<- v
3831 else showtext '
!'
" Failed to set texture count please retry later"
3833 src#
int "slice height"
3834 (fun () -> conf.sliceheight
)
3836 conf.sliceheight
<- v;
3837 wcmd "sliceh" [`i
conf.sliceheight
];
3839 src#
int "anti-aliasing level"
3840 (fun () -> conf.aalevel
)
3842 conf.aalevel
<- bound v 0 8;
3843 state.anchor <- getanchor ();
3844 opendoc state.path
state.password
;
3846 src#
int "ui font size"
3847 (fun () -> fstate.fontsize
)
3848 (fun v -> setfontsize (bound v 5 100));
3849 colorp "background color"
3850 (fun () -> conf.bgcolor
)
3851 (fun v -> conf.bgcolor
<- v);
3852 src#
bool "crop hack"
3853 (fun () -> conf.crophack
)
3854 (fun v -> conf.crophack
<- v);
3855 src#
string "trim fuzz"
3856 (fun () -> irect_to_string conf.trimfuzz
)
3859 conf.trimfuzz
<- irect_of_string v;
3861 then settrim true conf.trimfuzz
;
3863 state.text <- Printf.sprintf
"bad irect `%s': %s"
3864 v (Printexc.to_string exn
)
3866 src#
string "throttle"
3868 match conf.maxwait
with
3869 | None
-> "show place holder if page is not ready"
3872 then "wait for page to fully render"
3874 "wait " ^ string_of_float
time
3875 ^
" seconds before showing placeholder"
3879 let f = float_of_string
v in
3881 then conf.maxwait
<- None
3882 else conf.maxwait
<- Some
f
3884 state.text <- Printf.sprintf
"bad time `%s': %s"
3885 v (Printexc.to_string exn
)
3887 src#
string "ghyll scroll"
3889 match conf.ghyllscroll
with
3891 | Some nab
-> ghyllscroll_to_string nab
3896 if String.length
v = 0
3898 else Some
(ghyllscroll_of_string v)
3900 conf.ghyllscroll
<- gs
3902 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
3903 v (Printexc.to_string exn
)
3905 src#colorspace
"color space"
3906 (fun () -> colorspace_to_string conf.colorspace
)
3908 conf.colorspace
<- colorspace_of_int v;
3915 src#caption
"Document" 0;
3916 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3917 src#caption2
"Pages"
3918 (fun () -> string_of_int
state.pagecount
) 1;
3919 src#caption2
"Dimensions"
3920 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3924 src#caption
"Trimmed margins" 0;
3925 src#caption2
"Dimensions"
3926 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3929 src#reset prevmode prevuioh
;
3933 let prevmode = state.mode
3934 and prevuioh
= state.uioh in
3935 fillsrc prevmode prevuioh
;
3936 let source = (src :> lvsource
) in
3937 state.uioh <- coe (object (self)
3938 inherit listview ~
source ~trusted
:true as super
3939 val mutable m_prevmemused
= 0
3940 method infochanged
= function
3942 if m_prevmemused
!= state.memused
3944 m_prevmemused
<- state.memused
;
3945 G.postRedisplay "memusedchanged";
3947 | Pdim
-> G.postRedisplay "pdimchanged"
3948 | Docinfo
-> fillsrc prevmode prevuioh
3950 method special
key =
3951 if Glut.getModifiers
() land Glut.active_ctrl
= 0
3954 | Glut.KEY_LEFT
-> coe (self#updownlevel ~
-1)
3955 | Glut.KEY_RIGHT
-> coe (self#updownlevel
1)
3956 | _ -> super#special
key
3957 else super#special
key
3959 G.postRedisplay "info";
3965 inherit lvsourcebase
3966 method getitemcount
= Array.length
state.help
3968 let s, n, _ = state.help
.(n) in
3971 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3975 m_qsearch
<- qsearch;
3976 match state.help
.(active) with
3977 | _, _, Action
f -> Some
(f uioh)
3987 method hasaction
n =
3988 match state.help
.(n) with
3989 | _, _, Action
_ -> true
3996 state.uioh <- coe (new listview ~
source ~trusted
:true);
3997 G.postRedisplay "help";
4002 let re = Str.regexp
"[\r\n]" in
4004 inherit lvsourcebase
4005 val mutable m_items
= [||]
4007 method getitemcount
= 1 + Array.length m_items
4012 else m_items
.(n-1), 0
4014 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4019 then Buffer.clear
state.errmsgs
;
4020 m_qsearch
<- qsearch;
4027 method hasaction
n =
4031 state.newerrmsgs
<- false;
4032 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4033 m_items
<- Array.of_list
l
4041 let source = (msgsource :> lvsource
) in
4042 state.uioh <- coe (object
4043 inherit listview ~
source ~trusted
:false as super
4046 then msgsource#reset
;
4049 G.postRedisplay "msgs";
4052 let quickbookmark ?title
() =
4053 match state.layout with
4059 let sec = Unix.gettimeofday
() in
4060 let tm = Unix.localtime
sec in
4061 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4065 (tm.Unix.tm_year
+ 1900)
4068 | Some
title -> title
4071 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4076 state.fullscreen
<- None
;
4077 Glut.reshapeWindow
w h;
4080 let viewkeyboard key =
4082 let mode = state.mode in
4083 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4086 G.postRedisplay "view:enttext"
4088 let c = Char.chr
key in
4090 | '
\027'
| 'q'
-> (* escape *)
4091 begin match state.mstate
with
4093 state.mstate
<- Mnone
;
4094 Glut.setCursor
Glut.CURSOR_INHERIT
;
4095 G.postRedisplay "kill zoom rect";
4100 | '
\008'
-> (* backspace *)
4101 let y = getnav ~
-1 in
4102 gotoy_and_clear_text y
4110 G.postRedisplay "dehighlight";
4113 let ondone isforw
s =
4114 cbput state.hists
.pat
s;
4115 state.searchpattern
<- s;
4118 let s = String.create
1 in
4120 enttext (s, "", Some
(onhist state.hists
.pat
),
4121 textentry, ondone (c ='
/'
))
4123 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4124 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4125 setzoom (conf.zoom +. incr)
4130 try int_of_string
s with exc
->
4131 state.text <- Printf.sprintf
"bad integer `%s': %s"
4132 s (Printexc.to_string exc
);
4138 state.text <- "page bias is now " ^ string_of_int
n;
4141 enttext ("page bias: ", "", None
, intentry, ondone)
4143 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4144 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4145 setzoom (max
0.01 (conf.zoom -. decr))
4148 let ondone msg
= state.text <- msg
in
4150 "option [acfhilpstvACPRSZTI]: ", "", None
,
4151 optentry state.mode, ondone
4154 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4157 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4158 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4162 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4168 try int_of_string
s with exc
->
4169 state.text <- Printf.sprintf
"bad integer `%s': %s"
4170 s (Printexc.to_string exc
);
4176 cbput state.hists
.pag
(string_of_int
n);
4177 gotopage1 (n + conf.pagebias
- 1) 0;
4180 let pageentry text key =
4181 match Char.unsafe_chr
key with
4182 | 'g'
-> TEdone
text
4183 | _ -> intentry text key
4185 let text = "x" in text.[0] <- c;
4186 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4189 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4190 reshape conf.winw
conf.winh
;
4193 conf.hlinks
<- not
conf.hlinks
;
4194 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4195 G.postRedisplay "toggle highlightlinks";
4198 begin match state.autoscroll
with
4200 conf.autoscrollstep
<- step
;
4201 state.autoscroll
<- None
4203 if conf.autoscrollstep
= 0
4204 then state.autoscroll
<- Some
1
4205 else state.autoscroll
<- Some
conf.autoscrollstep
4209 conf.presentation <- not
conf.presentation;
4210 if conf.presentation
4212 if not
conf.scrollbarinpm
4213 then state.scrollw
<- 0;
4216 state.scrollw
<- conf.scrollbw
;
4218 showtext ' '
("presentation mode " ^
4219 if conf.presentation then "on" else "off");
4220 state.anchor <- getanchor ();
4224 begin match state.fullscreen
with
4226 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4229 state.fullscreen
<- None
;
4234 gotoy_and_clear_text 0
4237 gotopage1 (state.pagecount
- 1) 0
4240 search state.searchpattern
true
4243 search state.searchpattern
false
4246 begin match state.layout with
4249 gotoy_and_clear_text (getpagey l.pageno)
4253 begin match List.rev
state.layout with
4256 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4257 gotoy_and_clear_text (getpagey pageno)
4260 | '
\127'
-> (* del *)
4261 begin match state.layout with
4264 let pageno = max
0 (l.pageno-1) in
4265 gotoy_and_clear_text (getpagey pageno)
4269 showtext ' '
(describe_location ());
4272 begin match state.layout with
4275 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4280 enterbookmarkmode ()
4288 | '
e'
when conf.redirectstderr ->
4293 match state.layout with
4296 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4300 enttext ("bookmark: ", "", None
, textentry, ondone)
4304 showtext ' '
"Quick bookmark added";
4307 begin match state.layout with
4309 let rect = getpdimrect
l.pagedimno
in
4313 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4314 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4316 (truncate
(rect.(1) -. rect.(0)),
4317 truncate
(rect.(3) -. rect.(0)))
4319 let w = truncate
((float w)*.conf.zoom)
4320 and h = truncate
((float h)*.conf.zoom) in
4323 state.anchor <- getanchor ();
4324 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4326 G.postRedisplay "z";
4331 | '
\000'
-> (* ctrl-2 *)
4332 let maxw = getmaxw
() in
4334 then setzoom (maxw /. float conf.winw
)
4337 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
4341 bound (conf.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
4343 G.postRedisplay "brightness";
4346 begin match state.mode with
4347 | Birdseye beye
-> upbirdseye 1 beye
4348 | _ -> gotoy (clamp (-conf.scrollstep
))
4352 begin match state.mode with
4353 | Birdseye beye
-> downbirdseye 1 beye
4354 | _ -> gotoy (clamp conf.scrollstep
)
4358 state.anchor <- getanchor ();
4359 opendoc state.path
state.password
4361 | '
v'
when not
conf.debug
->
4362 List.iter
debugl state.layout;
4364 | '
v'
when conf.debug
->
4367 match getopaque l.pageno with
4370 let x0, y0
, x1
, y1 = pagebbox opaque
in
4371 let a,b = float x0, float y0
in
4372 let c,d = float x1
, float y0
in
4373 let e,f = float x1
, float y1 in
4374 let h,j
= float x0, float y1 in
4375 let rect = (a,b,c,d,e,f,h,j
) in
4377 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4379 G.postRedisplay "v";
4382 vlog "huh? %d %c" key (Char.chr
key);
4385 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
4387 | 27 -> (* escape *)
4388 leavebirdseye beye
true
4390 | 12 -> (* ctrl-l *)
4391 let y, h = getpageyh pageno in
4392 let top = (conf.winh
- h) / 2 in
4393 gotoy (max
0 (y - top))
4396 leavebirdseye beye
false
4402 let keyboard ~
key ~
x ~
y =
4405 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
4406 then wcmd "interrupt" []
4407 else state.uioh <- state.uioh#
key key
4410 let birdseyespecial key ((oconf
, leftx
, _, hooverpageno
, anchor) as beye
) =
4412 match conf.columns
with
4414 | Some
((c, _, _), _) -> c
4417 | Glut.KEY_UP
-> upbirdseye incr beye
4418 | Glut.KEY_DOWN
-> downbirdseye incr beye
4419 | Glut.KEY_LEFT
-> upbirdseye 1 beye
4420 | Glut.KEY_RIGHT
-> downbirdseye 1 beye
4422 | Glut.KEY_PAGE_UP
->
4423 begin match state.layout with
4427 state.mode <- Birdseye
(
4428 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4430 gotopage1 l.pageno 0;
4433 let layout = layout (state.y-conf.winh
) conf.winh
in
4435 | [] -> gotoy (clamp (-conf.winh
))
4437 state.mode <- Birdseye
(
4438 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4440 gotopage1 l.pageno 0
4443 | [] -> gotoy (clamp (-conf.winh
))
4446 | Glut.KEY_PAGE_DOWN
->
4447 begin match List.rev
state.layout with
4449 let layout = layout (state.y + conf.winh
) conf.winh
in
4450 begin match layout with
4452 let incr = l.pageh
- l.pagevh in
4457 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4459 G.postRedisplay "birdseye pagedown";
4461 else gotoy (clamp (incr + conf.interpagespace*2));
4465 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4466 gotopage1 l.pageno 0;
4469 | [] -> gotoy (clamp conf.winh
)
4473 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4477 let pageno = state.pagecount
- 1 in
4478 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4479 if not
(pagevisible state.layout pageno)
4482 match List.rev
state.pdims
with
4484 | (_, _, h, _) :: _ -> h
4486 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4487 else G.postRedisplay "birdseye end";
4491 let setautoscrollspeed step goingdown
=
4492 let incr = max
1 ((abs step
) / 2) in
4493 let incr = if goingdown
then incr else -incr in
4494 let astep = step
+ incr in
4495 state.autoscroll
<- Some
astep;
4498 let special ~
key ~
x ~
y =
4501 state.uioh <- state.uioh#
special key
4506 match state.mode with
4507 | Textentry
_ -> scalecolor 0.4
4508 | View
-> scalecolor 1.0
4509 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4510 if l.pageno = hooverpageno
4513 if l.pageno = pageno
4519 begin match getopaque l.pageno with
4521 if tileready l l.pagex l.pagey
4523 let x = l.pagedispx - l.pagex
4524 and y = l.pagedispy - l.pagey in
4525 postprocess opaque
conf.hlinks
x y;
4531 let scrollindicator () =
4532 let sbw, ph
, sh = state.uioh#
scrollph in
4533 let sbh, pw
, sw = state.uioh#scrollpw
in
4535 GlDraw.color (0.64, 0.64, 0.64);
4537 (float (conf.winw
- sbw), 0.)
4538 (float conf.winw
, float conf.winh
)
4541 (0., float (conf.winh
- sbh))
4542 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4544 GlDraw.color (0.0, 0.0, 0.0);
4547 (float (conf.winw
- sbw), ph
)
4548 (float conf.winw
, ph
+. sh)
4551 (pw
, float (conf.winh
- sbh))
4552 (pw
+. sw, float conf.winh
)
4556 let pagetranslatepoint l x y =
4557 let dy = y - l.pagedispy in
4558 let y = dy + l.pagey in
4559 let dx = x - l.pagedispx in
4560 let x = dx + l.pagex in
4565 match state.mstate
with
4566 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4569 | Msel
((x0, y0
), (x1
, y1)) ->
4570 let rec loop = function
4572 if ((y0
>= l.pagedispy && y0
<= (l.pagedispy + l.pagevh))
4573 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4574 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4575 || ((x1
>= l.pagedispx && x1
<= (l.pagedispx + l.pagevw))))
4577 match getopaque l.pageno with
4579 let dx, dy = pagetranslatepoint l 0 0 in
4584 GlMat.mode `modelview
;
4586 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4587 seltext opaque
(x0, y0
, x1
, y1);
4598 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4599 GlDraw.polygon_mode `both `fill
;
4600 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4602 (fun (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) ->
4604 if l.pageno = pageno
4606 let dx = float (l.pagedispx - l.pagex) in
4607 let dy = float (l.pagedispy - l.pagey) in
4608 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4609 GlDraw.begins `quads
;
4611 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4612 GlDraw.vertex2
(x1
+.dx, y1+.dy);
4613 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4614 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4625 GlClear.color (scalecolor2 conf.bgcolor
);
4626 GlClear.clear
[`
color];
4627 List.iter
drawpage state.layout;
4632 begin match state.mstate
with
4633 | Mzoomrect
((x0, y0
), (x1
, y1)) ->
4635 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4636 GlDraw.polygon_mode `both `fill
;
4637 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4638 GlDraw.rect (float x0, float y0
)
4639 (float x1
, float y1);
4644 Glut.swapBuffers
();
4648 let rec f = function
4650 begin match getopaque l.pageno with
4652 let x0 = l.pagedispx in
4653 let x1 = x0 + l.pagevw in
4654 let y0 = l.pagedispy in
4655 let y1 = y0 + l.pagevh in
4656 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4658 let px, py = pagetranslatepoint l x y in
4659 match whatsunder opaque
px py with
4671 let zoomrect x y x1 y1 =
4674 and y0 = min
y y1 in
4675 gotoy (state.y + y0);
4676 state.anchor <- getanchor ();
4677 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4679 if state.w < conf.winw
- state.scrollw
4680 then (conf.winw
- state.scrollw
- state.w) / 2
4683 state.x <- (state.x + margin) - x0;
4685 Glut.setCursor
Glut.CURSOR_INHERIT
;
4686 state.mstate
<- Mnone
;
4690 let winw = conf.winw - state.scrollw
- 1 in
4691 let s = float x /. float winw in
4692 let destx = truncate
(float (state.w + winw) *. s) in
4693 state.x <- winw - destx;
4694 gotoy_and_clear_text state.y;
4695 state.mstate
<- Mscrollx
;
4699 let s = float y /. float conf.winh
in
4700 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4701 gotoy_and_clear_text desty;
4702 state.mstate
<- Mscrolly
;
4705 let viewmouse button bstate
x y =
4707 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4708 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4710 match state.mstate
with
4711 | Mzoom
(oldn
, i
) ->
4719 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4721 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4723 let zoom = conf.zoom -. incr in
4725 state.mstate
<- Mzoom
(n, 0);
4727 state.mstate
<- Mzoom
(n, i
+1);
4729 else state.mstate
<- Mzoom
(n, 0)
4731 | _ -> state.mstate
<- Mzoom
(n, 0)
4734 match state.autoscroll
with
4735 | Some step
-> setautoscrollspeed step
(n=4)
4739 then -conf.scrollstep
4740 else conf.scrollstep
4742 let incr = incr * 2 in
4743 let y = clamp incr in
4744 gotoy_and_clear_text y
4747 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4748 if bstate
= Glut.DOWN
4750 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4751 state.mstate
<- Mpan
(x, y)
4754 state.mstate
<- Mnone
4756 | Glut.RIGHT_BUTTON
->
4757 if bstate
= Glut.DOWN
4759 Glut.setCursor
Glut.CURSOR_CYCLE
;
4761 state.mstate
<- Mzoomrect
(p, p)
4764 match state.mstate
with
4765 | Mzoomrect
((x0, y0), _) ->
4766 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4767 then zoomrect x0 y0 x y
4769 state.mstate
<- Mnone
;
4770 Glut.setCursor
Glut.CURSOR_INHERIT
;
4771 G.postRedisplay "kill accidental zoom rect";
4774 Glut.setCursor
Glut.CURSOR_INHERIT
;
4775 state.mstate
<- Mnone
4778 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4779 if bstate
= Glut.DOWN
4781 let _, position, sh = state.uioh#
scrollph in
4782 if y > truncate
position && y < truncate
(position +. sh)
4783 then state.mstate
<- Mscrolly
4786 state.mstate
<- Mnone
4788 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4789 if bstate
= Glut.DOWN
4791 let _, position, sw = state.uioh#scrollpw
in
4792 if x > truncate
position && x < truncate
(position +. sw)
4793 then state.mstate
<- Mscrollx
4796 state.mstate
<- Mnone
4798 | Glut.LEFT_BUTTON
->
4799 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4800 begin match dest with
4801 | Ulinkgoto
(pageno, top) ->
4805 gotopage1 pageno top;
4811 | Unone
when bstate
= Glut.DOWN
->
4812 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4813 state.mstate
<- Mpan
(x, y);
4815 | Unone
| Utext
_ ->
4816 if bstate
= Glut.DOWN
4818 if conf.angle
mod 360 = 0
4820 state.mstate
<- Msel
((x, y), (x, y));
4821 G.postRedisplay "mouse select";
4825 match state.mstate
with
4828 | Mzoom
_ | Mscrollx
| Mscrolly
->
4829 state.mstate
<- Mnone
4831 | Mzoomrect
((x0, y0), _) ->
4835 Glut.setCursor
Glut.CURSOR_INHERIT
;
4836 state.mstate
<- Mnone
4838 | Msel
((_, y0), (_, y1)) ->
4840 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4841 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh)))
4843 match getopaque l.pageno with
4848 List.iter
f state.layout;
4849 copysel
""; (* ugly *)
4850 Glut.setCursor
Glut.CURSOR_INHERIT
;
4851 state.mstate
<- Mnone
;
4858 let birdseyemouse button bstate
x y
4859 (conf, leftx
, _, hooverpageno
, anchor) =
4861 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4862 let rec loop = function
4865 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4866 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4868 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4873 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4877 let mouse bstate button
x y =
4878 state.uioh <- state.uioh#button button bstate
x y;
4881 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4884 state.uioh <- state.uioh#
motion x y
4888 state.uioh <- state.uioh#
pmotion x y;
4895 begin match state.mode with
4896 | Textentry
textentry -> textentrykeyboard key textentry
4897 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4898 | View
-> viewkeyboard key
4902 method special key =
4903 begin match state.mode with
4904 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4908 birdseyespecial key vals
4910 | View
when key = Glut.KEY_F1
->
4914 begin match state.autoscroll
with
4915 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4916 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4921 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4923 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4925 if Glut.getModifiers
() land Glut.active_shift
!= 0
4926 then (setzoom state.prevzoom
; state.y)
4927 else clamp (-conf.winh
/2)
4928 else clamp (-conf.scrollstep
)
4930 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4932 if Glut.getModifiers
() land Glut.active_shift
!= 0
4933 then (setzoom state.prevzoom
; state.y)
4934 else clamp (conf.winh
/2)
4935 else clamp (conf.scrollstep
)
4936 | Glut.KEY_PAGE_UP
->
4937 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4939 match state.layout with
4941 | l :: _ -> state.y - l.pagey
4944 | Glut.KEY_PAGE_DOWN
->
4945 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4947 match List.rev
state.layout with
4949 | l :: _ -> getpagey l.pageno
4957 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
4959 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
4960 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
4961 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
4963 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
4965 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4966 then (conf.winw / 2)
4969 state.x <- state.x - dx;
4971 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
4973 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4974 then (conf.winw / 2)
4977 state.x <- state.x + dx;
4982 if abs
(state.y - y) > conf.scrollstep
*2
4984 else gotoy_and_clear_text y
4987 | Textentry
te -> textentryspecial key te
4991 method button button bstate
x y =
4992 begin match state.mode with
4993 | View
-> viewmouse button bstate
x y
4994 | Birdseye beye
-> birdseyemouse button bstate
x y beye
5000 begin match state.mode with
5002 | View
| Birdseye
_ ->
5003 match state.mstate
with
5004 | Mzoom
_ | Mnone
-> ()
5009 state.mstate
<- Mpan
(x, y);
5010 if conf.zoom > 1.0 then state.x <- state.x + dx;
5012 gotoy_and_clear_text y
5015 state.mstate
<- Msel
(a, (x, y));
5016 G.postRedisplay "motion select";
5019 let y = min
conf.winh
(max
0 y) in
5023 let x = min
conf.winw (max
0 x) in
5026 | Mzoomrect
(p0
, _) ->
5027 state.mstate
<- Mzoomrect
(p0
, (x, y));
5028 G.postRedisplay "motion zoomrect";
5032 method pmotion x y =
5033 begin match state.mode with
5034 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5035 let rec loop = function
5037 if hooverpageno
!= -1
5039 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5040 G.postRedisplay "pmotion birdseye no hoover";
5043 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5044 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5046 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5047 G.postRedisplay "pmotion birdseye hoover";
5056 match state.mstate
with
5058 begin match getunder x y with
5059 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
5061 if conf.underinfo
then showtext 'u'
("ri: " ^
uri);
5062 Glut.setCursor
Glut.CURSOR_INFO
5063 | Ulinkgoto
(page
, _) ->
5065 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
5066 Glut.setCursor
Glut.CURSOR_INFO
5068 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
5069 Glut.setCursor
Glut.CURSOR_TEXT
5072 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5077 method infochanged
_ = ()
5080 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5081 let p, h = scrollph state.y maxy in
5085 let winw = conf.winw - state.scrollw
- 1 in
5086 let fwinw = float winw in
5088 let sw = fwinw /. float state.w in
5089 let sw = fwinw *. sw in
5090 max
sw (float conf.scrollh
)
5093 let f = state.w+winw in
5094 let r = float (winw-state.x) /. float f in
5095 let p = fwinw *. r in
5099 if position +. sw > fwinw
5100 then fwinw -. position
5103 state.hscrollh, position, sw
5110 let fontpath = ref "";;
5111 let wmclasshack = ref false;;
5114 let l = String.length
s in
5115 let b = Buffer.create
l in
5123 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
5124 | _ -> Sys.getenv
"HOME"
5127 ("Can not determine home directory location: " ^
5128 Printexc.to_string exn
);
5132 let config_of c attrs
=
5136 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5137 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5138 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5139 | "preload" -> { c with preload = bool_of_string
v }
5140 | "page-bias" -> { c with pagebias
= int_of_string
v }
5141 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5142 | "auto-scroll-step" ->
5143 { c with autoscrollstep
= max
0 (int_of_string
v) }
5144 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5145 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5148 match String.lowercase
v with
5149 | "true" -> Some infinity
5151 | f -> Some
(float_of_string
f)
5153 { c with maxwait
= mw}
5154 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5155 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5156 | "vertical-margin" ->
5157 { c with interpagespace = max
0 (int_of_string
v) }
5159 let zoom = float_of_string
v /. 100. in
5160 let zoom = max
zoom 0.0 in
5161 { c with zoom = zoom }
5162 | "presentation" -> { c with presentation = bool_of_string
v }
5163 | "rotation-angle" -> { c with angle
= int_of_string
v }
5164 | "width" -> { c with winw = max
20 (int_of_string
v) }
5165 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5166 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5167 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5168 | "pixmap-cache-size" ->
5169 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5170 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5171 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5172 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5173 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5174 | "background-color" -> { c with bgcolor
= color_of_string v }
5175 | "scrollbar-in-presentation" ->
5176 { c with scrollbarinpm
= bool_of_string
v }
5177 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5178 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5179 | "mupdf-store-size" ->
5180 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5181 | "checkers" -> { c with checkers
= bool_of_string
v }
5182 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5183 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5184 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5185 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
5186 | "uri-launcher" -> { c with urilauncher
= unent v }
5187 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5188 | "invert-colors" -> { c with invert
= bool_of_string
v }
5189 | "brightness" -> { c with colorscale
= float_of_string
v }
5190 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5192 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5194 let nab = columns_of_string v in
5195 { c with columns
= Some
(nab, [||]) }
5196 | "birds-eye-columns" ->
5197 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5200 prerr_endline
("Error processing attribute (`" ^
5201 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5204 let rec fold c = function
5207 let c = apply c k
v in
5213 let fromstring f pos
n v d =
5216 dolog "Error processing attribute (%S=%S) at %d\n%s"
5217 n v pos
(Printexc.to_string exn
)
5222 let bookmark_of attrs
=
5223 let rec fold title page
rely = function
5224 | ("title", v) :: rest
-> fold v page
rely rest
5225 | ("page", v) :: rest
-> fold title v rely rest
5226 | ("rely", v) :: rest
-> fold title page
v rest
5227 | _ :: rest
-> fold title page
rely rest
5228 | [] -> title, page
, rely
5230 fold "invalid" "0" "0" attrs
5234 let rec fold path page
rely pan
= function
5235 | ("path", v) :: rest
-> fold v page
rely pan rest
5236 | ("page", v) :: rest
-> fold path
v rely pan rest
5237 | ("rely", v) :: rest
-> fold path page
v pan rest
5238 | ("pan", v) :: rest
-> fold path page
rely v rest
5239 | _ :: rest
-> fold path page
rely pan rest
5240 | [] -> path
, page
, rely, pan
5242 fold "" "0" "0" "0" attrs
5245 let setconf dst
src =
5246 dst
.scrollbw
<- src.scrollbw
;
5247 dst
.scrollh
<- src.scrollh
;
5248 dst
.icase
<- src.icase
;
5249 dst
.preload <- src.preload;
5250 dst
.pagebias
<- src.pagebias
;
5251 dst
.verbose
<- src.verbose
;
5252 dst
.scrollstep
<- src.scrollstep
;
5253 dst
.maxhfit
<- src.maxhfit
;
5254 dst
.crophack
<- src.crophack
;
5255 dst
.autoscrollstep
<- src.autoscrollstep
;
5256 dst
.maxwait
<- src.maxwait
;
5257 dst
.hlinks
<- src.hlinks
;
5258 dst
.underinfo
<- src.underinfo
;
5259 dst
.interpagespace <- src.interpagespace;
5260 dst
.zoom <- src.zoom;
5261 dst
.presentation <- src.presentation;
5262 dst
.angle
<- src.angle
;
5263 dst
.winw <- src.winw;
5264 dst
.winh
<- src.winh
;
5265 dst
.savebmarks
<- src.savebmarks
;
5266 dst
.memlimit
<- src.memlimit
;
5267 dst
.proportional
<- src.proportional
;
5268 dst
.texcount
<- src.texcount
;
5269 dst
.sliceheight
<- src.sliceheight
;
5270 dst
.thumbw
<- src.thumbw
;
5271 dst
.jumpback
<- src.jumpback
;
5272 dst
.bgcolor
<- src.bgcolor
;
5273 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5274 dst
.tilew
<- src.tilew
;
5275 dst
.tileh
<- src.tileh
;
5276 dst
.mustoresize
<- src.mustoresize
;
5277 dst
.checkers
<- src.checkers
;
5278 dst
.aalevel
<- src.aalevel
;
5279 dst
.trimmargins
<- src.trimmargins
;
5280 dst
.trimfuzz
<- src.trimfuzz
;
5281 dst
.urilauncher
<- src.urilauncher
;
5282 dst
.colorspace
<- src.colorspace
;
5283 dst
.invert
<- src.invert
;
5284 dst
.colorscale
<- src.colorscale
;
5285 dst
.redirectstderr <- src.redirectstderr;
5286 dst
.ghyllscroll
<- src.ghyllscroll
;
5287 dst
.columns
<- src.columns
;
5288 dst
.beyecolumns
<- src.beyecolumns
;
5292 let h = Hashtbl.create
10 in
5293 let dc = { defconf with angle
= defconf.angle
} in
5294 let rec toplevel v t spos
_ =
5296 | Vdata
| Vcdata
| Vend
-> v
5297 | Vopen
("llppconfig", _, closed
) ->
5300 else { v with f = llppconfig
}
5302 error
"unexpected subelement at top level" s spos
5303 | Vclose
_ -> error
"unexpected close at top level" s spos
5305 and llppconfig
v t spos
_ =
5307 | Vdata
| Vcdata
-> v
5308 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5309 | Vopen
("defaults", attrs
, closed
) ->
5310 let c = config_of dc attrs
in
5314 else { v with f = skip
"defaults" (fun () -> v) }
5316 | Vopen
("ui-font", attrs
, closed
) ->
5317 let rec getsize size
= function
5319 | ("size", v) :: rest
->
5321 fromstring int_of_string spos
"size" v fstate.fontsize
in
5323 | l -> getsize size l
5325 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5328 else { v with f = uifont
(Buffer.create
10) }
5330 | Vopen
("doc", attrs
, closed
) ->
5331 let pathent, spage
, srely
, span
= doc_of attrs
in
5332 let path = unent pathent
5333 and pageno = fromstring int_of_string spos
"page" spage
0
5334 and rely = fromstring float_of_string spos
"rely" srely
0.0
5335 and pan
= fromstring int_of_string spos
"pan" span
0 in
5336 let c = config_of dc attrs
in
5337 let anchor = (pageno, rely) in
5339 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5340 else { v with f = doc
path pan
anchor c [] }
5343 error
"unexpected subelement in llppconfig" s spos
5345 | Vclose
"llppconfig" -> { v with f = toplevel }
5346 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5348 and uifont
b v t spos epos
=
5351 Buffer.add_substring
b s spos
(epos
- spos
);
5353 | Vopen
(_, _, _) ->
5354 error
"unexpected subelement in ui-font" s spos
5355 | Vclose
"ui-font" ->
5356 if String.length
!fontpath = 0
5357 then fontpath := Buffer.contents
b;
5358 { v with f = llppconfig
}
5359 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5360 | Vend
-> error
"unexpected end of input in ui-font" s spos
5362 and doc
path pan
anchor c bookmarks
v t spos
_ =
5364 | Vdata
| Vcdata
-> v
5365 | Vend
-> error
"unexpected end of input in doc" s spos
5366 | Vopen
("bookmarks", _, closed
) ->
5369 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5371 | Vopen
(_, _, _) ->
5372 error
"unexpected subelement in doc" s spos
5375 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5376 { v with f = llppconfig
}
5378 | Vclose
_ -> error
"unexpected close in doc" s spos
5380 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5382 | Vdata
| Vcdata
-> v
5383 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5384 | Vopen
("item", attrs
, closed
) ->
5385 let titleent, spage
, srely
= bookmark_of attrs
in
5386 let page = fromstring int_of_string spos
"page" spage
0
5387 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5388 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5390 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5393 { v with f = skip
"item" f }
5396 error
"unexpected subelement in bookmarks" s spos
5398 | Vclose
"bookmarks" ->
5399 { v with f = doc
path pan
anchor c bookmarks }
5401 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5403 and skip tag
f v t spos
_ =
5405 | Vdata
| Vcdata
-> v
5407 error
("unexpected end of input in skipped " ^ tag
) s spos
5408 | Vopen
(tag'
, _, closed
) ->
5412 let f'
() = { v with f = skip tag
f } in
5413 { v with f = skip tag'
f'
}
5417 else error
("unexpected close in skipped " ^ tag
) s spos
5420 parse
{ f = toplevel; accu = () } s;
5426 let len = in_channel_length ic
in
5427 let s = String.create
len in
5428 really_input ic
s 0 len;
5431 | Parse_error
(msg
, s, pos
) ->
5432 let subs = subs s pos
in
5433 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5434 failwith
("parse error: " ^
s)
5437 failwith
("config load error: " ^
Printexc.to_string exn
)
5443 let dir = Filename.concat
home ".config" in
5444 if Sys.is_directory
dir then dir else home
5447 Filename.concat
dir "llpp.conf"
5450 let confpath = ref defconfpath;;
5453 if Sys.file_exists
!confpath
5456 (try Some
(open_in_bin
!confpath)
5459 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5460 Printexc.to_string exn
);
5469 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5470 Printexc.to_string exn
);
5476 f (Hashtbl.create
0, defconf)
5481 let pc, pb
, px, pa
=
5483 Hashtbl.find h (Filename.basename
state.path)
5484 with Not_found
-> dc, [], 0, (0, 0.0)
5488 state.bookmarks <- pb
;
5490 state.scrollw
<- conf.scrollbw
;
5492 then state.anchor <- pa
;
5493 cbput state.hists
.nav pa
;
5498 let add_attrs bb always
dc c =
5501 then Printf.bprintf bb
"\n %s='%b'" s a
5504 then Printf.bprintf bb
"\n %s='%d'" s a
5507 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5510 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5513 then Printf.bprintf bb
"\n %s='%f'" s a
5517 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5521 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5525 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5529 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5535 | Some
(_N
, _A
, _B
) ->
5536 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
5546 else string_of_float
f
5548 Printf.bprintf bb
"\n %s='%s'" s v
5553 | Some
((n, a, b), _) when n > 1 ->
5554 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
5560 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
5565 then dc.winw, dc.winh
5567 match state.fullscreen
with
5569 | None
-> c.winw, c.winh
5571 let zoom, presentation, interpagespace, maxwait
=
5573 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5575 match state.mode with
5576 | Birdseye
(bc
, _, _, _, _) ->
5577 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5578 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5580 oi
"width" w dc.winw;
5581 oi
"height" h dc.winh
;
5582 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5583 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5584 ob "case-insensitive-search" c.icase
dc.icase
;
5585 ob "preload" c.preload dc.preload;
5586 oi
"page-bias" c.pagebias
dc.pagebias
;
5587 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5588 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5589 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5590 ob "crop-hack" c.crophack
dc.crophack
;
5591 oW
"throttle" maxwait
dc.maxwait
;
5592 ob "highlight-links" c.hlinks
dc.hlinks
;
5593 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5594 oi
"vertical-margin" interpagespace dc.interpagespace;
5595 oz
"zoom" zoom dc.zoom;
5596 ob "presentation" presentation dc.presentation;
5597 oi
"rotation-angle" c.angle
dc.angle
;
5598 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5599 ob "proportional-display" c.proportional
dc.proportional
;
5600 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5601 oi
"tex-count" c.texcount
dc.texcount
;
5602 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5603 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5604 ob "persistent-location" c.jumpback
dc.jumpback
;
5605 oc
"background-color" c.bgcolor
dc.bgcolor
;
5606 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5607 oi
"tile-width" c.tilew
dc.tilew
;
5608 oi
"tile-height" c.tileh
dc.tileh
;
5609 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
5610 ob "checkers" c.checkers
dc.checkers
;
5611 oi
"aalevel" c.aalevel
dc.aalevel
;
5612 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5613 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5614 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5615 oC
"color-space" c.colorspace
dc.colorspace
;
5616 ob "invert-colors" c.invert
dc.invert
;
5617 oF
"brightness" c.colorscale
dc.colorscale
;
5618 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5619 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
5620 oco
"columns" c.columns
dc.columns
;
5621 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
5623 then ob "wmclass-hack" !wmclasshack false;
5627 let uifontsize = fstate.fontsize
in
5628 let bb = Buffer.create
32768 in
5630 let dc = if conf.bedefault
then conf else dc in
5631 Buffer.add_string
bb "<llppconfig>\n";
5633 if String.length
!fontpath > 0
5635 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5641 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5644 Buffer.add_string
bb "<defaults ";
5645 add_attrs bb true dc dc;
5646 Buffer.add_string
bb "/>\n";
5648 let adddoc path pan
anchor c bookmarks =
5649 if bookmarks == [] && c = dc && anchor = emptyanchor
5652 Printf.bprintf
bb "<doc path='%s'"
5653 (enent
path 0 (String.length
path));
5655 if anchor <> emptyanchor
5657 let n, y = anchor in
5658 Printf.bprintf
bb " page='%d'" n;
5661 Printf.bprintf
bb " rely='%f'" y
5666 then Printf.bprintf
bb " pan='%d'" pan
;
5668 add_attrs bb false dc c;
5670 begin match bookmarks with
5671 | [] -> Buffer.add_string
bb "/>\n"
5673 Buffer.add_string
bb ">\n<bookmarks>\n";
5674 List.iter
(fun (title, _level
, (page, rely)) ->
5676 "<item title='%s' page='%d'"
5677 (enent
title 0 (String.length
title))
5682 Printf.bprintf
bb " rely='%f'" rely
5684 Buffer.add_string
bb "/>\n";
5686 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5692 match state.mode with
5693 | Birdseye
(_, pan, _, _, _) -> pan
5696 let basename = Filename.basename state.path in
5697 adddoc basename pan (getanchor ())
5700 match state.autoscroll
with
5702 | None
-> conf.autoscrollstep
}
5703 (if conf.savebmarks
then state.bookmarks else []);
5705 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5707 then adddoc path x y c bookmarks
5709 Buffer.add_string
bb "</llppconfig>";
5712 if Buffer.length
bb > 0
5715 let tmp = !confpath ^
".tmp" in
5716 let oc = open_out_bin
tmp in
5717 Buffer.output_buffer
oc bb;
5719 Unix.rename
tmp !confpath;
5722 ("error while saving configuration: " ^
Printexc.to_string exn
)
5729 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5730 "<password> Set password");
5732 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5733 "<path> Set path to the user interface font");
5735 ("-c", Arg.String
(fun s -> Config.confpath := s),
5736 "<path> Set path to the configuration file");
5738 ("-v", Arg.Unit
(fun () ->
5740 "%s\nconfiguration path: %s\n"
5744 exit
0), " Print version and exit");
5747 (fun s -> state.path <- s)
5748 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5750 if String.length
state.path = 0
5751 then (prerr_endline
"file name missing"; exit
1);
5755 let _ = Glut.init
Sys.argv
in
5756 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5757 let () = Glut.initWindowSize
conf.winw conf.winh
in
5758 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5760 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5761 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5762 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5767 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5769 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5770 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5771 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5772 Unix.bind
sock addr;
5774 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5775 Unix.connect
csock addr;
5776 let ssock, _ = Unix.accept
sock in
5779 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5780 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5787 let () = Glut.displayFunc
display in
5788 let () = Glut.reshapeFunc
reshape in
5789 let () = Glut.keyboardFunc
keyboard in
5790 let () = Glut.specialFunc
special in
5791 let () = Glut.idleFunc
(Some
idle) in
5792 let () = Glut.mouseFunc
mouse in
5793 let () = Glut.motionFunc
motion in
5794 let () = Glut.passiveMotionFunc
pmotion in
5796 setcheckers conf.checkers
;
5798 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5799 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
5800 !Config.wmclasshack, !Config.fontpath
5802 state.csock <- csock;
5803 state.ssock <- ssock;
5804 state.text <- "Opening " ^
state.path;
5805 setaalevel
conf.aalevel
;
5806 writeopen state.path state.password
;
5808 setfontsize fstate.fontsize
;
5816 | Glut.BadEnum
"key in special_of_int" ->
5817 showtext '
!'
" LablGlut bug: special key not recognized";
5824 | exn
when conf.redirectstderr ->
5826 Printf.sprintf
"exception %s\n%s"
5827 (Printexc.to_string exn
)
5828 (Printexc.get_backtrace
())
5831 Unix.single_write
state.stderr
s 0 (String.length
s);