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";;
57 let platform_to_string = function
58 | Punknown
-> "unknown"
60 | Pwindows
-> "Windows"
63 | Pfreebsd
-> "FreeBSD"
64 | Pdragonflybsd
-> "DragonflyBSD"
65 | Popenbsd
-> "OpenBSD"
70 let platform = platform ();;
74 | Pwindows
| Pmingw
-> true
82 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
85 external drawtile
: tileparams
-> string -> unit = "ml_drawtile";;
89 | Msel
of (mpos
* mpos
)
92 | Mzoom
of (int * int)
93 | Mzoomrect
of (mpos
* mpos
)
97 type textentry
= string * string * onhist
option * onkey
* ondone
98 and onkey
= string -> int -> te
99 and ondone
= string -> unit
100 and histcancel
= unit -> unit
101 and onhist
= ((histcmd
-> string) * histcancel
)
102 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
107 | TEswitch
of textentry
118 let bound v minv maxv
=
119 max minv
(min maxv v
);
123 { store
= Array.create n v
130 let drawstring size x y s
=
132 Gl.enable `texture_2d
;
133 ignore
(drawstr size x y s
);
135 Gl.disable `texture_2d
;
138 let drawstring1 size x y s
=
142 let drawstring2 size x y fmt
=
143 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
146 let cbcap b
= Array.length b
.store
;;
151 b
.wc
<- (b
.wc
+ 1) mod cap;
153 b
.len
<- min
(b
.len
+ 1) cap;
156 let cbempty b
= b
.len
= 0;;
158 let cbgetg b circular dir
=
162 let rc = b
.rc + dir
in
174 else max
0 (min
rc (b
.len
-1))
180 let cbget b
= cbgetg b
false;;
181 let cbgetc b
= cbgetg b
true;;
198 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
199 dolog " WxH %dx%d" l
.pagew l
.pageh
;
200 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
201 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
202 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
206 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
208 dolog " x0,y0=(% f, % f)" x0 y0
;
209 dolog " x1,y1=(% f, % f)" x1 y1
;
210 dolog " x2,y2=(% f, % f)" x2 y2
;
211 dolog " x3,y3=(% f, % f)" x3 y3
;
216 { mutable scrollbw
: int
217 ; mutable scrollh
: int
218 ; mutable icase
: bool
219 ; mutable preload
: bool
220 ; mutable pagebias
: int
221 ; mutable verbose
: bool
222 ; mutable debug
: bool
223 ; mutable scrollstep
: int
224 ; mutable maxhfit
: bool
225 ; mutable crophack
: bool
226 ; mutable autoscrollstep
: int
227 ; mutable maxwait
: float option
228 ; mutable hlinks
: bool
229 ; mutable underinfo
: bool
230 ; mutable interpagespace
: interpagespace
231 ; mutable zoom
: float
232 ; mutable presentation
: bool
233 ; mutable angle
: angle
236 ; mutable savebmarks
: bool
237 ; mutable proportional
: proportional
238 ; mutable trimmargins
: trimmargins
239 ; mutable trimfuzz
: irect
240 ; mutable memlimit
: memsize
241 ; mutable texcount
: texcount
242 ; mutable sliceheight
: sliceheight
243 ; mutable thumbw
: width
244 ; mutable jumpback
: bool
245 ; mutable bgcolor
: float * float * float
246 ; mutable bedefault
: bool
247 ; mutable scrollbarinpm
: bool
248 ; mutable tilew
: int
249 ; mutable tileh
: int
250 ; mutable mumemlimit
: memsize
251 ; mutable checkers
: bool
252 ; mutable aalevel
: int
253 ; mutable urilauncher
: string
254 ; mutable colorspace
: colorspace
255 ; mutable invert
: bool
256 ; mutable colorscale
: float
260 type anchor
= pageno
* top
;;
262 type outline
= string * int * anchor
;;
264 type rect
= float * float * float * float * float * float * float * float;;
266 type tile
= opaque
* pixmapsize
* elapsed
267 and elapsed
= float;;
268 type pagemapkey
= pageno
* gen
;;
269 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
273 let emptyanchor = (0, 0.0);;
275 type infochange
= | Memused
| Docinfo
| Pdim
;;
277 class type uioh
= object
278 method display
: unit
279 method key
: int -> uioh
280 method special
: Glut.special_key_t
-> uioh
282 Glut.button_t
-> Glut.mouse_button_state_t
-> int -> int -> uioh
283 method motion
: int -> int -> uioh
284 method pmotion
: int -> int -> uioh
285 method infochanged
: infochange
-> unit
289 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
290 | Textentry
of (textentry
* onleave
)
292 and onleave
= leavetextentrystatus
-> unit
293 and leavetextentrystatus
= | Cancel
| Confirm
294 and helpitem
= string * int * action
297 | Action
of (uioh
-> uioh
)
300 let isbirdseye = function Birdseye _
-> true | _
-> false;;
301 let istextentry = function Textentry _
-> true | _
-> false;;
305 | Loading
of (page
* gen
)
307 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
309 | Outlining
of outline list
312 let nouioh : uioh
= object (self
)
315 method special _
= self
316 method button _ _ _ _
= self
317 method motion _ _
= self
318 method pmotion _ _
= self
319 method infochanged _
= ()
323 { mutable csock
: Unix.file_descr
324 ; mutable ssock
: Unix.file_descr
328 ; mutable scrollw
: int
329 ; mutable hscrollh
: int
330 ; mutable anchor
: anchor
332 ; mutable layout
: page list
333 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
334 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
335 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
336 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
337 ; mutable pagecount
: int
338 ; mutable currently
: currently
339 ; mutable mstate
: mstate
340 ; mutable searchpattern
: string
341 ; mutable rects
: (pageno
* recttype
* rect
) list
342 ; mutable rects1
: (pageno
* recttype
* rect
) list
343 ; mutable text
: string
344 ; mutable fullscreen
: (width
* height
) option
345 ; mutable mode
: mode
346 ; mutable uioh
: uioh
347 ; mutable outlines
: outline array
348 ; mutable bookmarks
: outline list
349 ; mutable path
: string
350 ; mutable password
: string
351 ; mutable invalidated
: int
352 ; mutable memused
: memsize
354 ; mutable throttle
: (page list
* int * float) option
355 ; mutable autoscroll
: int option
356 ; mutable help
: helpitem array
357 ; mutable docinfo
: (int * string) list
358 ; mutable deadline
: float
359 ; mutable texid
: GlTex.texture_id
option
361 ; mutable prevzoom
: float
362 ; mutable progress
: float
365 { pat
: string circbuf
366 ; pag
: string circbuf
367 ; nav
: anchor circbuf
388 ; presentation
= false
393 ; proportional
= true
394 ; trimmargins
= false
395 ; trimfuzz
= (0,0,0,0)
396 ; memlimit
= 32 lsl 20
401 ; bgcolor
= (0.5, 0.5, 0.5)
403 ; scrollbarinpm
= true
406 ; mumemlimit
= 128 lsl 20
411 | Plinux
| Pfreebsd
| Pdragonflybsd
| Popenbsd
| Psun
-> "xdg-open \"%s\""
412 | Posx
-> "open \"%s\""
413 | Pwindows
| Pcygwin
| Pmingw
-> "iexplore \"%s\""
421 let conf = { defconf with angle
= defconf.angle
};;
424 { mutable fontsize
: int
425 ; mutable wwidth
: float
426 ; mutable maxrows
: int
438 fstate.fontsize
<- n
;
439 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
440 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
444 if String.length
conf.urilauncher
= 0
445 then print_endline uri
447 let re = Str.regexp
"%s" in
448 let command = Str.global_replace
re uri
conf.urilauncher
in
450 try Some
(Unix.open_process_in
command)
453 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
458 | Some ic
-> close_in ic
463 let strings = ("llpp version " ^
Help.version
) :: "" :: Help.keys
in
465 let r = Str.regexp
"\\(http://[^ ]+\\)" in
467 if (try Str.search_forward
r s
0 with Not_found
-> -1) >= 0
469 let uri = Str.matched_string s
in
470 (s
, 0, Action
(fun u
-> gotouri uri; u
))
471 else s
, 0, Noaction
) strings
483 ; anchor
= emptyanchor
486 ; tilelru
= Queue.create
()
487 ; pagemap
= Hashtbl.create
10
488 ; tilemap
= Hashtbl.create
10
505 { nav
= cbnew 10 (0, 0.0)
526 Printf.kprintf prerr_endline fmt
528 Printf.kprintf ignore fmt
533 let postRedisplay who
=
535 then prerr_endline
("redisplay for " ^ who
);
536 Glut.postRedisplay ();
541 let b = Buffer.create
(String.length s
+ 1) in
542 Buffer.add_string
b s
;
547 let colorspace_of_string s
=
548 match String.lowercase s
with
552 | _
-> failwith
"invalid colorspace"
555 let int_of_colorspace = function
561 let colorspace_of_int = function
565 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
568 let colorspace_to_string = function
574 let intentry_with_suffix text key
=
575 let c = Char.unsafe_chr key
in
576 match Char.lowercase
c with
578 let text = addchar text c in
582 let text = addchar text c in
586 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
591 let len = String.length s
in
593 let b = Buffer.create
n in
594 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
595 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
596 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
597 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
598 Buffer.add_string
b s
;
599 let s'
= Buffer.contents
b in
600 let n'
= Unix.write fd
s'
0 n in
601 if n'
!= n then failwith
"write failed";
606 let n = Unix.read fd
s 0 4 in
607 if n != 4 then failwith
"incomplete read(len)";
609 lor (Char.code
s.[0] lsl 24)
610 lor (Char.code
s.[1] lsl 16)
611 lor (Char.code
s.[2] lsl 8)
612 lor (Char.code
s.[3] lsl 0)
614 let s = String.create
len in
615 let n = Unix.read fd
s 0 len in
616 if n != len then failwith
"incomplete read(data)";
621 let b = Buffer.create
10 in
622 Buffer.add_string
b s;
623 let rec combine = function
626 Buffer.add_char
b ' '
;
629 | `
b b -> if b then "1" else "0"
631 | `i i
-> string_of_int i
632 | `f f
-> string_of_float f
633 | `I f
-> string_of_int
(truncate f
)
635 Buffer.add_string
b s;
642 let cmd = Buffer.contents
(makecmd s l
) in
643 writecmd state.csock
cmd;
649 let d = conf.winh
- h
in
656 let rec f pn ph pi fh l
=
658 | (n, _
, h
, _
) :: rest
->
659 let ips = calcips h
in
664 if isbirdseye state.mode
&& pn
= 0
669 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
674 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
678 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
681 let fh = f 0 0 0 0 state.pdims
in
685 let getpageyh pageno
=
686 let rec f pn ph pi y l
=
688 | (n, _
, h
, _
) :: rest
->
689 let ips = calcips h
in
692 let h = if n = pageno
then h else ph
in
693 if conf.presentation
&& n = pageno
695 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
697 y
+ (pageno
- pn
) * (ph
+ pi
), h
699 let y = y + (if conf.presentation
then pi
else 0) in
700 let y = y + (n - pn
) * (ph
+ pi
) in
704 y + (pageno
- pn
) * (ph
+ pi
), ph
706 f 0 0 0 0 state.pdims
709 let getpagedim pageno
=
712 | (n, _
, _
, _
) as pdim
:: rest
->
714 then (if n = pageno
then pdim
else ppdim
)
719 f (-1, -1, -1, -1) state.pdims
722 let getpageh pageno
=
723 let _, _, h, _ = getpagedim pageno
in
727 let getpagew pageno
=
728 let _, w
, _, _ = getpagedim pageno
in
732 let getpagey pageno
= fst
(getpageyh pageno
);;
735 let sh = sh - state.hscrollh
in
736 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
737 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
739 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
740 let ips = calcips h in
742 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
746 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
748 prev
, pdims
, pdimno
, 0
750 let dy = dy + yinc in
751 let py = py + yinc in
752 if pageno
= state.pagecount
|| dy >= sh
757 if py + h <= vy - yinc
759 let py = py + h + ips in
760 let dy = max
0 (py - y) in
769 let pagey = vy - py in
770 let pagevh = h - pagey in
771 let pagevh = min
(sh - dy) pagevh in
772 let off = if yinc > 0 then py - vy else 0 in
773 let py = py + h + ips in
776 if state.w
< conf.winw
- state.scrollw
777 then (conf.winw
- state.scrollw
- state.w
) / 2
780 let dispx = xoff + state.x
in
786 let lw = w
- pagex in
787 min
lw (conf.winw
- state.scrollw
)
795 ; pagey = pagey + off
797 ; pagevh = pagevh - off
799 ; pagedispy
= dy + off
802 let accu = e :: accu in
811 if state.invalidated
= 0
830 let y = state.y + incr
in
832 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
836 let getopaque pageno
=
837 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
838 with Not_found
-> None
841 let putopaque pageno opaque
=
842 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
846 let tilex = l
.pagex mod conf.tilew
in
847 let tiley = l
.pagey mod conf.tileh
in
849 let col = l
.pagex / conf.tilew
in
850 let row = l
.pagey / conf.tileh
in
853 let a = l
.pagew
- l
.pagex in
854 let b = conf.winw
- state.scrollw
in
858 let rec rowloop row y0 dispy
h =
862 let dh = conf.tileh
- y0
in
864 let rec colloop col x0
dispx w
=
868 let dw = conf.tilew
- x0
in
871 f col row dispx dispy x0 y0
dw dh;
872 colloop (col+1) 0 (dispx+dw) (w
-dw)
875 colloop col tilex l
.pagedispx
vw;
876 rowloop (row+1) 0 (dispy
+dh) (h-dh)
880 then rowloop row tiley l
.pagedispy vh
;
883 let gettileopaque l
col row =
885 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
887 try Some
(Hashtbl.find
state.tilemap
key)
888 with Not_found
-> None
891 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
892 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
893 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
896 let drawtiles l color
=
898 let f col row x
y tilex tiley w
h =
899 match gettileopaque l
col row with
900 | Some
(opaque
, _, t
) ->
901 let params = x
, y, w
, h, tilex, tiley in
905 GlFunc.blend_func `zero `one_minus_src_color
;
907 drawtile
params opaque
;
909 then Gl.disable `blend
;
912 let s = Printf.sprintf
916 let ww = fstate.wwidth
in
917 GlMisc.push_attrib
[`current
];
918 GlDraw.color
(0.0, 0.0, 0.0);
920 (float (x
-2), float (y-2))
921 (float (x
+2) +. ww, float (y + fstate.fontsize
+ 2));
922 GlDraw.color
(1.0, 1.0, 1.0);
923 drawstring fstate.fontsize x
(y + fstate.fontsize
- 1) s;
924 GlMisc.pop_attrib
();
929 let lw = conf.winw
- state.scrollw
- x
in
932 let lh = conf.winh
- y in
935 Gl.enable `texture_2d
;
936 begin match state.texid
with
938 GlTex.bind_texture `texture_2d id
;
942 and y1
= float (y+h) in
944 let tw = float w /. 64.0
945 and th
= float h /. 64.0 in
946 let tx0 = float tilex /. 64.0
947 and ty0
= float tiley /. 64.0 in
949 and ty1
= ty0
+. th
in
950 GlDraw.begins `quads
;
951 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
952 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
953 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
954 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
957 Gl.disable `texture_2d
;
959 GlDraw.color
(1.0, 1.0, 1.0);
962 (float (x
+w), float (y+h));
964 if w > 128 && h > fstate.fontsize
+ 10
966 GlDraw.color
(0.0, 0.0, 0.0);
969 then (col*conf.tilew
, row*conf.tileh
)
972 drawstring2 fstate.fontsize x
y "Loading %d [%d,%d]" l
.pageno
c r;
979 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
981 let tilevisible1 l x
y =
983 and ax1
= l
.pagex + l
.pagevw
985 and ay1
= l
.pagey + l
.pagevh in
989 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
990 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
992 let rx0 = max
ax0 bx0
993 and ry0
= max ay0 by0
994 and rx1
= min ax1
bx1
995 and ry1
= min ay1 by1
in
997 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1001 let tilevisible layout n x
y =
1002 let rec findpageinlayout = function
1003 | l
:: _ when l
.pageno
= n -> tilevisible1 l x
y
1004 | _ :: rest
-> findpageinlayout rest
1007 findpageinlayout layout
1010 let tileready l x
y =
1011 tilevisible1 l x
y &&
1012 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
1015 let tilepage n p
layout =
1016 let rec loop = function
1020 let f col row _ _ _ _ _ _ =
1021 if state.currently
= Idle
1023 match gettileopaque l
col row with
1026 let x = col*conf.tilew
1027 and y = row*conf.tileh
in
1029 let w = l
.pagew
- x in
1033 let h = l
.pageh
- y in
1045 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1046 conf.tilew
, conf.tileh
1055 if state.invalidated
= 0 then loop layout;
1058 let preloadlayout visiblepages
=
1059 let presentation = conf.presentation in
1060 let interpagespace = conf.interpagespace in
1061 let maxy = state.maxy in
1062 conf.presentation <- false;
1063 conf.interpagespace <- 0;
1064 state.maxy <- calcheight ();
1066 match visiblepages
with
1068 | l
:: _ -> getpagey l
.pageno
+ l
.pagey
1070 let y = if y < conf.winh
then 0 else y - conf.winh
in
1071 let h = state.y - y + conf.winh
*3 in
1072 let pages = layout y h in
1073 conf.presentation <- presentation;
1074 conf.interpagespace <- interpagespace;
1080 let rec loop pages =
1081 if state.currently
!= Idle
1086 begin match getopaque l
.pageno
with
1088 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1089 state.currently
<- Loading
(l
, state.gen
);
1091 tilepage l
.pageno opaque
pages;
1096 if state.invalidated
= 0 then loop pages
1101 if conf.preload && state.currently
= Idle
1102 then load (preloadlayout pages);
1105 let layoutready layout =
1106 let rec fold all ls
=
1107 all
&& match ls
with
1109 let seen = ref false in
1110 let allvisible = ref true in
1111 let foo col row _ _ _ _ _ _ =
1113 allvisible := !allvisible &&
1114 begin match gettileopaque l
col row with
1120 fold (!seen && !allvisible) rest
1123 let alltilesvisible = fold true layout in
1128 let y = bound y 0 state.maxy in
1129 let y, layout, proceed
=
1130 match conf.maxwait
with
1132 begin match state.throttle
with
1134 let layout = layout y conf.winh
in
1135 let ready = layoutready layout in
1139 state.throttle
<- Some
(layout, y, now ());
1141 else G.postRedisplay "gotoy showall (None)";
1143 | Some
(_, _, started
) ->
1144 let dt = now () -. started
in
1147 state.throttle
<- None
;
1148 let layout = layout y conf.winh
in
1150 G.postRedisplay "maxwait";
1157 let layout = layout y conf.winh
in
1158 if true || layoutready layout
1159 then G.postRedisplay "gotoy ready";
1165 state.layout <- layout;
1166 begin match state.mode
with
1167 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1168 if not
(pagevisible layout pageno
)
1170 match state.layout with
1173 state.mode
<- Birdseye
(
1174 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1183 let conttiling pageno opaque
=
1184 tilepage pageno opaque
1185 (if conf.preload then preloadlayout state.layout else state.layout)
1188 let gotoy_and_clear_text y =
1190 if not
conf.verbose
then state.text <- "";
1194 match state.layout with
1196 | l
:: _ -> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1199 let getanchory (n, top
) =
1200 let y, h = getpageyh n in
1201 y + (truncate
(top
*. float h));
1204 let gotoanchor anchor
=
1205 gotoy (getanchory anchor
);
1209 cbput state.hists
.nav
(getanchor ());
1213 let anchor = cbgetc state.hists
.nav dir
in
1217 let gotopage n top
=
1218 let y, h = getpageyh n in
1219 gotoy_and_clear_text (y + (truncate
(top
*. float h)));
1222 let gotopage1 n top
=
1223 let y = getpagey n in
1224 gotoy_and_clear_text (y + top
);
1232 state.invalidated
<- state.invalidated
+ 1;
1235 let writeopen path password
=
1236 writecmd state.csock
("open " ^ path ^
"\000" ^ password ^
"\000");
1239 let opendoc path password
=
1242 state.password
<- password
;
1243 state.gen
<- state.gen
+ 1;
1244 state.docinfo
<- [];
1246 setaalevel
conf.aalevel
;
1247 writeopen path password
;
1248 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1249 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1253 let c = c *. conf.colorscale
in
1257 let scalecolor2 (r, g
, b) =
1258 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1262 state.maxy <- calcheight ();
1264 if state.w <= conf.winw
- state.scrollw
1268 match state.mode
with
1269 | Birdseye
(_, _, pageno
, _, _) ->
1270 let y, h = getpageyh pageno
in
1271 let top = (conf.winh
- h) / 2 in
1272 gotoy (max
0 (y - top))
1273 | _ -> gotoanchor state.anchor
1277 let firsttime = ref true in
1279 GlDraw.viewport
0 0 w h;
1280 if state.invalidated
= 0 && not
!firsttime
1281 then state.anchor <- getanchor ();
1285 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1289 setfontsize fstate.fontsize
;
1290 GlMat.mode `modelview
;
1291 GlMat.load_identity
();
1293 GlMat.mode `projection
;
1294 GlMat.load_identity
();
1295 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1296 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1297 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1300 wcmd "geometry" [`i
w; `i
h];
1304 let len = String.length
state.text in
1307 match state.mode
with
1308 | View
-> state.hscrollh
1313 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1314 (x+.w, float (conf.winh
- hscrollh))
1317 let w = float (conf.winw
- state.scrollw
- 1) in
1318 if state.progress
>= 0.0 && state.progress
< 1.0
1320 GlDraw.color
(0.3, 0.3, 0.3);
1321 let w1 = w *. state.progress
in
1323 GlDraw.color
(0.0, 0.0, 0.0);
1327 GlDraw.color
(0.0, 0.0, 0.0);
1331 GlDraw.color
(1.0, 1.0, 1.0);
1332 drawstring fstate.fontsize
1333 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1335 match state.mode
with
1336 | Textentry
((prefix
, text, _, _, _), _) ->
1340 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1342 Printf.sprintf
"%s%s_" prefix
text
1347 if len > 0 then drawstring state.text
1351 state.text <- Printf.sprintf
"%c%s" c s;
1352 G.postRedisplay "showtext";
1356 let len = Queue.length
state.tilelru
in
1358 if state.memused
<= conf.memlimit
1363 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1364 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1367 && colorspace
= conf.colorspace
1368 && angle
= conf.angle
1369 && pagew
= getpagew n
1370 && pageh
= getpageh n
1374 then preloadlayout state.layout
1377 let x = col*conf.tilew
1378 and y = row*conf.tileh
in
1379 tilevisible layout n x y
1381 then Queue.push lruitem
state.tilelru
1383 wcmd "freetile" [`
s p
];
1384 state.memused
<- state.memused
- s;
1385 state.uioh#infochanged Memused
;
1386 Hashtbl.remove
state.tilemap k
;
1395 Queue.iter
(fun (k
, p
, s) ->
1396 wcmd "freetile" [`
s p
];
1397 state.memused
<- state.memused
- s;
1398 state.uioh#infochanged Memused
;
1399 Hashtbl.remove
state.tilemap k
;
1401 Queue.clear
state.tilelru
;
1405 let logcurrently = function
1406 | Idle
-> dolog "Idle"
1407 | Loading
(l
, gen
) ->
1408 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1409 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1411 "Tiling %d[%d,%d] page=%s cs=%s angle"
1412 l
.pageno
col row pageopaque
1413 (colorspace_to_string colorspace
)
1415 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1416 angle gen
conf.angle
state.gen
1418 conf.tilew
conf.tileh
1425 (* dolog "%S" cmds; *)
1428 try String.index cmds ' '
1429 with Not_found
-> -1
1434 let l = String.length cmds
in
1435 let op = String.sub cmds
0 spacepos in
1437 if l - spacepos < 2 then ""
1438 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1443 state.uioh#infochanged Pdim
;
1447 state.rects
<- state.rects1
;
1448 G.postRedisplay "clearrects";
1452 try Scanf.sscanf args
"%u" (fun n -> n)
1454 dolog "error processing 'continue' %S: %s"
1455 cmds
(Printexc.to_string exn
);
1458 state.pagecount
<- n;
1459 state.invalidated
<- state.invalidated
- 1;
1460 begin match state.currently
with
1462 state.currently
<- Idle
;
1463 state.outlines
<- Array.of_list
(List.rev
l)
1466 if state.invalidated
= 0
1468 if conf.maxwait
= None
1469 then G.postRedisplay "continue";
1472 Glut.setWindowTitle args
1479 then showtext ' ' args
1482 let progress, text =
1484 Scanf.sscanf args
"%f %n"
1486 f, String.sub args pos
(String.length args
- pos
))
1488 dolog "error processing 'progress' %S: %s"
1489 cmds
(Printexc.to_string exn
);
1493 state.progress <- progress;
1494 G.postRedisplay "progress"
1497 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1499 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1500 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1501 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1503 dolog "error processing 'firstmatch' %S: %s"
1504 cmds
(Printexc.to_string exn
);
1507 let y = (getpagey pageno) + truncate y0
in
1510 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)]
1513 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1515 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1516 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1517 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1519 dolog "error processing 'match' %S: %s"
1520 cmds
(Printexc.to_string exn
);
1524 (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) :: state.rects1
1529 Scanf.sscanf args
"%s %f" (fun p t
-> p
, t
)
1531 dolog "error processing 'page' %S: %s"
1532 cmds
(Printexc.to_string exn
);
1535 begin match state.currently
with
1536 | Loading
(l, gen
) ->
1537 vlog "page %d took %f sec" l.pageno t
;
1538 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1539 begin match state.throttle
with
1541 let preloadedpages =
1543 then preloadlayout state.layout
1548 Set.Make
(struct type t
= int let compare = (-) end) in
1550 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1551 IntSet.empty
preloadedpages
1554 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1555 if not
(IntSet.mem
pageno set)
1557 wcmd "freepage" [`
s opaque
];
1563 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1566 state.currently
<- Idle
;
1569 tilepage l.pageno pageopaque state.layout;
1571 load preloadedpages;
1572 if pagevisible state.layout l.pageno
1573 && layoutready state.layout
1574 then G.postRedisplay "page";
1577 | Some
(layout, _, _) ->
1578 state.currently
<- Idle
;
1579 tilepage l.pageno pageopaque layout;
1584 dolog "Inconsistent loading state";
1585 logcurrently state.currently
;
1590 let (x, y, opaque
, size
, t
) =
1592 Scanf.sscanf args
"%u %u %s %u %f"
1593 (fun x y p size t
-> (x, y, p
, size
, t
))
1595 dolog "error processing 'tile' %S: %s"
1596 cmds
(Printexc.to_string exn
);
1599 begin match state.currently
with
1600 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1601 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1603 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1605 wcmd "freetile" [`
s opaque
];
1606 state.currently
<- Idle
;
1610 puttileopaque l col row gen cs angle opaque size t
;
1611 state.memused
<- state.memused
+ size
;
1612 state.uioh#infochanged Memused
;
1614 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1615 opaque
, size
) state.tilelru
;
1617 state.currently
<- Idle
;
1619 && conf.colorspace
= cs
1620 && conf.angle
= angle
1621 && tilevisible state.layout l.pageno x y
1622 then conttiling l.pageno pageopaque;
1624 begin match state.throttle
with
1626 preload state.layout;
1628 && conf.colorspace
= cs
1629 && conf.angle
= angle
1630 && tilevisible state.layout l.pageno x y
1631 then G.postRedisplay "tile nothrottle";
1633 | Some
(layout, y, _) ->
1634 let ready = layoutready layout in
1638 state.layout <- layout;
1639 state.throttle
<- None
;
1640 G.postRedisplay "throttle";
1647 dolog "Inconsistent tiling state";
1648 logcurrently state.currently
;
1655 Scanf.sscanf args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1657 dolog "error processing 'pdim' %S: %s"
1658 cmds
(Printexc.to_string exn
);
1661 state.uioh#infochanged Pdim
;
1662 state.pdims
<- pdim :: state.pdims
1665 let (l, n, t
, h, pos
) =
1667 Scanf.sscanf args
"%u %u %d %u %n"
1668 (fun l n t
h pos
-> l, n, t
, h, pos
)
1670 dolog "error processing 'o' %S: %s"
1671 cmds
(Printexc.to_string exn
);
1674 let s = String.sub args pos
(String.length args
- pos
) in
1675 let outline = (s, l, (n, float t
/. float h)) in
1676 begin match state.currently
with
1677 | Outlining outlines
->
1678 state.currently
<- Outlining
(outline :: outlines
)
1680 state.currently
<- Outlining
[outline]
1682 dolog "invalid outlining state";
1683 logcurrently currently
1687 state.docinfo
<- (1, args
) :: state.docinfo
1690 state.uioh#infochanged Docinfo
;
1691 state.docinfo
<- List.rev
state.docinfo
1694 dolog "unknown cmd `%S'" cmds
1698 if state.deadline
== nan
then state.deadline
<- now ();
1699 let rec loop delay
=
1702 then max
0.0 (state.deadline
-. now ())
1705 let r, _, _ = Unix.select
[state.csock
] [] [] timeout in
1708 begin match state.autoscroll
with
1709 | Some step
when step
!= 0 ->
1710 let y = state.y + step
in
1714 else if y >= state.maxy then 0 else y
1717 if state.mode
= View
1718 then state.text <- "";
1719 state.deadline
<- state.deadline
+. 0.005;
1722 state.deadline
<- state.deadline
+. delay
;
1726 let cmd = readcmd state.csock
in
1735 let action = function
1736 | HCprev
-> cbget cb ~
-1
1737 | HCnext
-> cbget cb
1
1738 | HCfirst
-> cbget cb ~
-(cb
.rc)
1739 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1740 and cancel
() = cb
.rc <- rc
1744 let search pattern forward
=
1745 if String.length pattern
> 0
1748 match state.layout with
1751 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1754 let b = makecmd "search"
1755 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
1757 Buffer.add_char
b '
,'
;
1758 Buffer.add_string
b pattern
;
1759 Buffer.add_char
b '
\000'
;
1762 writecmd state.csock
cmd;
1765 let intentry text key =
1766 let c = Char.unsafe_chr
key in
1769 let text = addchar text c in
1773 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1777 let textentry text key =
1778 let c = Char.unsafe_chr
key in
1780 | _ when key >= 32 && key < 127 ->
1781 let text = addchar text c in
1785 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
1789 let reqlayout angle proportional
=
1790 match state.throttle
with
1792 if state.invalidated
= 0 then state.anchor <- getanchor ();
1793 conf.angle
<- angle
mod 360;
1794 conf.proportional
<- proportional
;
1796 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
1800 let settrim trimmargins trimfuzz
=
1801 if state.invalidated
= 0 then state.anchor <- getanchor ();
1802 conf.trimmargins
<- trimmargins
;
1803 conf.trimfuzz
<- trimfuzz
;
1804 let x0, y0
, x1
, y1
= trimfuzz
in
1807 `
b conf.trimmargins
;
1813 Hashtbl.iter
(fun _ opaque
->
1814 wcmd "freepage" [`
s opaque
];
1816 Hashtbl.clear
state.pagemap
;
1820 match state.throttle
with
1822 let zoom = max
0.01 zoom in
1823 if zoom <> conf.zoom
1825 state.prevzoom
<- conf.zoom;
1828 then (state.x <- 0; 0.0)
1829 else float state.x /. float state.w
1832 reshape conf.winw
conf.winh
;
1835 let x = relx *. float state.w in
1836 state.x <- truncate
x;
1838 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
1841 | Some
(layout, y, started
) ->
1843 match conf.maxwait
with
1847 let dt = now () -. started
in
1852 G.postRedisplay "zoom maxwait";
1856 let enterbirdseye () =
1857 let zoom = float conf.thumbw
/. float conf.winw
in
1858 let birdseyepageno =
1859 let cy = conf.winh
/ 2 in
1863 let rec fold best
= function
1866 let d = cy - (l.pagedispy
+ l.pagevh/2)
1867 and dbest
= cy - (best
.pagedispy
+ best
.pagevh/2) in
1868 if abs
d < abs dbest
1875 state.mode
<- Birdseye
(
1876 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
1879 conf.presentation <- false;
1880 conf.interpagespace <- 10;
1881 conf.hlinks
<- false;
1883 state.mstate
<- Mnone
;
1884 conf.maxwait
<- None
;
1885 Glut.setCursor
Glut.CURSOR_INHERIT
;
1888 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1893 reshape conf.winw
conf.winh
;
1896 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
1898 conf.zoom <- c.zoom;
1899 conf.presentation <- c.presentation;
1900 conf.interpagespace <- c.interpagespace;
1901 conf.maxwait
<- c.maxwait
;
1902 conf.hlinks
<- c.hlinks
;
1906 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1909 reshape conf.winw
conf.winh
;
1910 state.anchor <- if goback
then anchor else (pageno, 0.0);
1913 let togglebirdseye () =
1914 match state.mode
with
1915 | Birdseye vals
-> leavebirdseye vals
true
1916 | View
-> enterbirdseye ()
1920 let upbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
1921 let pageno = max
0 (pageno - 1) in
1922 let rec loop = function
1923 | [] -> gotopage1 pageno 0
1924 | l :: _ when l.pageno = pageno ->
1925 if l.pagedispy
>= 0 && l.pagey = 0
1926 then G.postRedisplay "upbirdseye"
1927 else gotopage1 pageno 0
1928 | _ :: rest
-> loop rest
1931 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
1934 let downbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
1935 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
1936 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
1937 let rec loop = function
1939 let y, h = getpageyh pageno in
1940 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
1942 | l :: _ when l.pageno = pageno ->
1943 if l.pagevh != l.pageh
1944 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
1945 else G.postRedisplay "downbirdseye"
1946 | _ :: rest
-> loop rest
1951 let optentry mode
_ key =
1952 let btos b = if b then "on" else "off" in
1953 let c = Char.unsafe_chr
key in
1957 try conf.scrollstep
<- int_of_string
s with exc
->
1958 state.text <- Printf.sprintf
"bad integer `%s': %s"
1959 s (Printexc.to_string exc
)
1961 TEswitch
("scroll step: ", "", None
, intentry, ondone)
1966 conf.autoscrollstep
<- int_of_string
s;
1967 if state.autoscroll
<> None
1968 then state.autoscroll
<- Some
conf.autoscrollstep
1970 state.text <- Printf.sprintf
"bad integer `%s': %s"
1971 s (Printexc.to_string exc
)
1973 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
1978 let zoom = float (int_of_string
s) /. 100.0 in
1981 state.text <- Printf.sprintf
"bad integer `%s': %s"
1982 s (Printexc.to_string exc
)
1984 TEswitch
("zoom: ", "", None
, intentry, ondone)
1989 conf.thumbw
<- bound (int_of_string
s) 2 4096;
1991 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
1992 begin match mode
with
1994 leavebirdseye beye
false;
1999 state.text <- Printf.sprintf
"bad integer `%s': %s"
2000 s (Printexc.to_string exc
)
2002 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2007 Some
(int_of_string
s)
2009 state.text <- Printf.sprintf
"bad integer `%s': %s"
2010 s (Printexc.to_string exc
);
2013 | Some angle
-> reqlayout angle
conf.proportional
2016 TEswitch
("rotation: ", "", None
, intentry, ondone)
2019 conf.icase
<- not
conf.icase
;
2020 TEdone
("case insensitive search " ^
(btos conf.icase
))
2023 conf.preload <- not
conf.preload;
2025 TEdone
("preload " ^
(btos conf.preload))
2028 conf.verbose
<- not
conf.verbose
;
2029 TEdone
("verbose " ^
(btos conf.verbose
))
2032 conf.debug
<- not
conf.debug
;
2033 TEdone
("debug " ^
(btos conf.debug
))
2036 conf.maxhfit
<- not
conf.maxhfit
;
2038 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2039 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2042 conf.crophack
<- not
conf.crophack
;
2043 TEdone
("crophack " ^
btos conf.crophack
)
2047 match conf.maxwait
with
2049 conf.maxwait
<- Some infinity
;
2050 "always wait for page to complete"
2052 conf.maxwait
<- None
;
2053 "show placeholder if page is not ready"
2058 conf.underinfo
<- not
conf.underinfo
;
2059 TEdone
("underinfo " ^
btos conf.underinfo
)
2062 conf.savebmarks
<- not
conf.savebmarks
;
2063 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2069 match state.layout with
2074 conf.interpagespace <- int_of_string
s;
2075 state.maxy <- calcheight ();
2076 let y = getpagey pageno in
2079 state.text <- Printf.sprintf
"bad integer `%s': %s"
2080 s (Printexc.to_string exc
)
2082 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2085 reqlayout conf.angle
(not
conf.proportional
);
2086 TEdone
("proportional display " ^
btos conf.proportional
)
2089 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2090 TEdone
("trim margins " ^
btos conf.trimmargins
)
2093 conf.invert
<- not
conf.invert
;
2094 TEdone
("invert colors " ^
btos conf.invert
)
2097 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2101 class type lvsource
= object
2102 method getitemcount
: int
2103 method getitem
: int -> (string * int)
2104 method hasaction
: int -> bool
2113 method getactive
: int
2114 method getfirst
: int
2115 method getqsearch
: string
2116 method setqsearch
: string -> unit
2120 class virtual lvsourcebase
= object
2121 val mutable m_active
= 0
2122 val mutable m_first
= 0
2123 val mutable m_qsearch
= ""
2124 val mutable m_pan
= 0
2125 method getactive
= m_active
2126 method getfirst
= m_first
2127 method getqsearch
= m_qsearch
2128 method getpan
= m_pan
2129 method setqsearch
s = m_qsearch
<- s
2132 let textentryspecial key = function
2133 | ((c, _, (Some
(action, _) as onhist), onkey
, ondone), mode
) ->
2136 | Glut.KEY_UP
-> action HCprev
2137 | Glut.KEY_DOWN
-> action HCnext
2138 | Glut.KEY_HOME
-> action HCfirst
2139 | Glut.KEY_END
-> action HClast
2142 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2143 G.postRedisplay "special textentry";
2147 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2149 state.mode
<- Textentry
(te
, onleave
);
2152 G.postRedisplay "textentrykeyboard enttext";
2154 match Char.unsafe_chr
key with
2155 | '
\008'
-> (* backspace *)
2156 let len = String.length
text in
2160 G.postRedisplay "textentrykeyboard after cancel";
2163 let s = String.sub
text 0 (len - 1) in
2164 enttext (c, s, opthist
, onkey
, ondone)
2170 G.postRedisplay "textentrykeyboard after confirm"
2172 | '
\007'
(* ctrl-g *)
2173 | '
\027'
-> (* escape *)
2174 if String.length
text = 0
2176 begin match opthist
with
2178 | Some
(_, onhistcancel
) -> onhistcancel
()
2182 G.postRedisplay "textentrykeyboard after cancel2"
2185 enttext (c, "", opthist
, onkey
, ondone)
2188 | '
\127'
-> () (* delete *)
2191 begin match onkey
text key with
2195 G.postRedisplay "textentrykeyboard after confirm2";
2198 enttext (c, text, opthist
, onkey
, ondone);
2203 G.postRedisplay "textentrykeyboard after cancel3"
2206 state.mode
<- Textentry
(te
, onleave
);
2207 G.postRedisplay "textentrykeyboard switch";
2211 let firstof first active
=
2212 if first
> active
|| abs
(first
- active
) > fstate.maxrows
- 1
2213 then max
0 (active
- (fstate.maxrows
/2))
2217 let calcfirst first active
=
2220 let rows = active
- first
in
2221 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2225 let coe s = (s :> uioh
);;
2227 class listview ~
(source
:lvsource
) ~trusted
=
2229 val m_pan
= source#getpan
2230 val m_first
= source#getfirst
2231 val m_active
= source#getactive
2232 val m_qsearch
= source#getqsearch
2233 val m_prev_uioh
= state.uioh
2235 method private elemunder
y =
2236 let n = y / (fstate.fontsize
+1) in
2237 if m_first
+ n < source#getitemcount
2239 if source#hasaction
(m_first
+ n)
2240 then Some
(m_first
+ n)
2247 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2248 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2249 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2250 GlDraw.color
(1., 1., 1.);
2251 Gl.enable `texture_2d
;
2252 let fs = fstate.fontsize
in
2254 let ww = fstate.wwidth
in
2255 let tabw = 30.0*.ww in
2257 if (row - m_first
) * nfs > conf.winh
2260 if row >= 0 && row < source#getitemcount
2262 let (s, level
) = source#getitem
row in
2263 let y = (row - m_first
) * nfs in
2264 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2267 Gl.disable `texture_2d
;
2268 GlDraw.polygon_mode `both `line
;
2269 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2270 GlDraw.rect (1., float (y + 1))
2271 (float (conf.winw
- 1), float (y + fs + 3));
2272 GlDraw.polygon_mode `both `fill
;
2273 GlDraw.color
(1., 1., 1.);
2274 Gl.enable `texture_2d
;
2277 let drawtabularstring s =
2278 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2281 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2284 let len = String.length
s - tabpos - 1 in
2285 let s1 = String.sub
s 0 tabpos
2286 and s2
= String.sub
s (tabpos + 1) len in
2287 let nx = drawstr x s1 in
2289 let x = x +. (max
tabw sw) in
2296 let _ = drawtabularstring s in
2303 Gl.disable `texture_2d
;
2305 method updownlevel incr
=
2306 let len = source#getitemcount
in
2307 let _, curlevel
= source#getitem m_active
in
2309 if i
= len then i
-1 else if i
= -1 then 0 else
2310 let _, l = source#getitem i
in
2311 if l != curlevel
then i
else flow (i
+incr
)
2313 let active = flow m_active
in
2314 let first = calcfirst m_first
active in
2315 G.postRedisplay "special outline updownlevel";
2316 {< m_active
= active; m_first
= first >}
2318 method private key1
key =
2319 let set active first qsearch
=
2320 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2322 let search active pattern incr
=
2325 if n >= 0 && n < source#getitemcount
2327 let s, _ = source#getitem
n in
2329 (try ignore
(Str.search_forward
re s 0); true
2330 with Not_found
-> false)
2332 else loop (n + incr
)
2339 let re = Str.regexp_case_fold pattern
in
2346 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2347 let incr = if key = 18 then -1 else 1 in
2349 match search (m_active
+ incr) m_qsearch
incr with
2351 state.text <- m_qsearch ^
" [not found]";
2354 state.text <- m_qsearch
;
2355 active, firstof m_first
active
2357 G.postRedisplay "listview ctrl-r/s";
2358 set active first m_qsearch
;
2360 | 8 -> (* backspace *)
2361 let len = String.length m_qsearch
in
2368 G.postRedisplay "listview empty qsearch";
2369 set m_active m_first
"";
2372 let qsearch = String.sub m_qsearch
0 (len - 1) in
2374 match search m_active
qsearch ~
-1 with
2376 state.text <- qsearch ^
" [not found]";
2379 state.text <- qsearch;
2380 active, firstof m_first
active
2382 G.postRedisplay "listview backspace qsearch";
2383 set active first qsearch
2386 | _ when key >= 32 && key < 127 ->
2387 let pattern = addchar m_qsearch
(Char.chr
key) in
2389 match search m_active
pattern 1 with
2391 state.text <- pattern ^
" [not found]";
2394 state.text <- pattern;
2395 active, firstof m_first
active
2397 G.postRedisplay "listview qsearch add";
2398 set active first pattern;
2400 | 27 -> (* escape *)
2402 if String.length m_qsearch
= 0
2404 G.postRedisplay "list view escape";
2407 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2409 | None
-> m_prev_uioh
2414 G.postRedisplay "list view kill qsearch";
2415 source#setqsearch
"";
2416 coe {< m_qsearch
= "" >}
2421 let self = {< m_qsearch
= "" >} in
2422 source#setqsearch
"";
2424 G.postRedisplay "listview enter";
2425 if m_active
>= 0 && m_active
< source#getitemcount
2427 source#exit
(coe self) false m_active m_first m_pan
"";
2430 source#exit
(coe self) true m_active m_first m_pan
"";
2433 begin match opt with
2434 | None
-> m_prev_uioh
2438 | 127 -> (* delete *)
2441 | _ -> dolog "unknown key %d" key; coe self
2443 method private special1
key =
2444 let itemcount = source#getitemcount
in
2445 let find start
incr =
2447 if i
= -1 || i
= itemcount
2450 if source#hasaction i
2452 else find (i
+ incr)
2457 let set active first =
2458 let first = bound first 0 (itemcount - fstate.maxrows
) in
2460 coe {< m_active
= active; m_first
= first >}
2463 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2465 let incr1 = if incr > 0 then 1 else -1 in
2466 if isvisible m_first m_active
2469 let next = m_active
+ incr in
2471 if next < 0 || next >= itemcount
2473 else find next incr1
2475 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2481 let first = m_first
+ incr in
2482 let first = bound first 0 (itemcount - 1) in
2484 let next = m_active
+ incr in
2485 let next = bound next 0 (itemcount - 1) in
2488 let active = if next = -1 then m_active
else next in
2491 let first = min
next m_first
in
2494 let first = m_first
+ incr in
2495 let first = bound first 0 (itemcount - 1) in
2497 let next = m_active
+ incr in
2498 let next = bound next 0 (itemcount - 1) in
2499 let next = find next incr1 in
2500 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2506 G.postRedisplay "listview navigate";
2509 begin match key with
2510 | Glut.KEY_UP
-> navigate ~
-1
2511 | Glut.KEY_DOWN
-> navigate 1
2512 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2513 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2517 G.postRedisplay "listview right";
2518 coe {< m_pan
= m_pan
- 1 >}
2522 G.postRedisplay "listview left";
2523 coe {< m_pan
= m_pan
+ 1 >}
2526 let active = find 0 1 in
2527 G.postRedisplay "listview home";
2531 let first = max
0 (itemcount - fstate.maxrows
) in
2532 let active = find (itemcount - 1) ~
-1 in
2533 G.postRedisplay "listview end";
2540 match state.mode
with
2541 | Textentry te
-> textentrykeyboard key te
; coe self
2542 | _ -> self#key1
key
2544 method special
key =
2545 match state.mode
with
2546 | Textentry te
-> textentryspecial key te
; coe self
2547 | _ -> self#special1
key
2549 method button button bstate
_ y =
2552 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2553 begin match self#elemunder
y with
2555 G.postRedisplay "listview click";
2557 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
2561 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2562 let len = source#getitemcount
in
2564 if m_first
+ fstate.maxrows
>= len
2568 let first = m_first
+ (if n == 3 then -1 else 1) in
2569 bound first 0 (len - 1)
2571 G.postRedisplay "listview wheel";
2572 Some
(coe {< m_first
= first >})
2577 | None
-> m_prev_uioh
2580 method motion
_ _ = coe self
2582 method pmotion
_ y =
2584 match self#elemunder
y with
2585 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
2586 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
2590 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
2595 method infochanged
_ = ()
2598 class outlinelistview ~source
=
2600 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
2604 | 14 -> (* ctrl-n *)
2605 source#narrow m_qsearch
;
2606 G.postRedisplay "outline ctrl-n";
2607 coe {< m_first
= 0; m_active
= 0 >}
2609 | 21 -> (* ctrl-u *)
2611 G.postRedisplay "outline ctrl-u";
2612 coe {< m_first
= 0; m_active
= 0 >}
2614 | 12 -> (* ctrl-l *)
2615 let first = m_active
- (fstate.maxrows
/ 2) in
2616 G.postRedisplay "outline ctrl-l";
2617 coe {< m_first
= first >}
2619 | 127 -> (* delete *)
2620 source#remove m_active
;
2621 G.postRedisplay "outline delete";
2622 let active = max
0 (m_active
-1) in
2623 coe {< m_first
= firstof m_first
active;
2624 m_active
= active >}
2626 | key -> super#
key key
2628 method special
key =
2629 let calcfirst first active =
2632 let rows = active - first in
2633 if rows > fstate.maxrows
then active - fstate.maxrows
else first
2637 let active = m_active
+ incr in
2638 let active = bound active 0 (source#getitemcount
- 1) in
2639 let first = calcfirst m_first
active in
2640 G.postRedisplay "special outline navigate";
2641 coe {< m_active
= active; m_first
= first >}
2644 | Glut.KEY_UP
-> navigate ~
-1
2645 | Glut.KEY_DOWN
-> navigate 1
2646 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2647 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2651 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2653 G.postRedisplay "special outline right";
2654 {< m_pan
= m_pan
+ 1 >}
2656 else self#updownlevel
1
2662 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2664 G.postRedisplay "special outline left";
2665 {< m_pan
= m_pan
- 1 >}
2667 else self#updownlevel ~
-1
2672 G.postRedisplay "special outline home";
2673 coe {< m_first
= 0; m_active
= 0 >}
2676 let active = source#getitemcount
- 1 in
2677 let first = max
0 (active - fstate.maxrows
) in
2678 G.postRedisplay "special outline end";
2679 coe {< m_active
= active; m_first
= first >}
2681 | _ -> super#special
key
2684 let outlinesource usebookmarks
=
2687 inherit lvsourcebase
2688 val mutable m_items
= empty
2689 val mutable m_orig_items
= empty
2690 val mutable m_prev_items
= empty
2691 val mutable m_narrow_pattern
= ""
2692 val mutable m_hadremovals
= false
2694 method getitemcount
=
2695 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
2698 if n == Array.length m_items
&& m_hadremovals
2700 ("[Confirm removal]", 0)
2702 let s, n, _ = m_items
.(n) in
2705 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
2706 ignore
(uioh
, first, pan
, qsearch);
2707 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
2709 if String.length m_narrow_pattern
= 0
2715 if not
confrimremoval
2717 let _, _, anchor = m_items
.(active) in
2722 state.bookmarks
<- Array.to_list m_items
;
2723 m_orig_items
<- m_items
;
2726 else m_items
<- items;
2729 method hasaction
_ = true
2732 if Array.length m_items
!= Array.length m_orig_items
2733 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
2736 method narrow
pattern =
2737 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
2741 let rec loop accu n =
2744 m_narrow_pattern
<- pattern;
2745 m_items
<- Array.of_list
accu
2748 let (s, _, _) as o = m_items
.(n) in
2750 if (try ignore
(Str.search_forward
re s 0); true
2751 with Not_found
-> false)
2757 loop [] (Array.length m_items
- 1)
2762 then Array.of_list
state.bookmarks
2765 m_items
<- m_orig_items
2770 if m
>= 0 && m
< Array.length m_items
2772 m_hadremovals
<- true;
2773 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
2774 let n = if n >= m
then n+1 else n in
2779 method reset
pageno items =
2780 m_hadremovals
<- false;
2781 if m_orig_items
== empty || m_prev_items
!= items
2783 m_orig_items
<- items;
2784 if String.length m_narrow_pattern
= 0
2785 then m_items
<- items;
2787 m_prev_items
<- items;
2789 let rec loop n best bestd
=
2790 if n = Array.length m_items
2793 let (_, _, (outlinepageno
, _)) = m_items
.(n) in
2794 let d = abs
(outlinepageno
- pageno) in
2797 else loop (n+1) best bestd
2802 m_first
<- firstof m_first
active
2806 let enterselector usebookmarks
=
2807 let source = outlinesource usebookmarks
in
2811 then Array.of_list
state.bookmarks
2814 if Array.length
outlines = 0
2816 showtext ' ' errmsg
;
2819 state.text <- source#greetmsg
;
2820 Glut.setCursor
Glut.CURSOR_INHERIT
;
2822 match state.layout with
2824 | {pageno=pageno} :: _ -> pageno
2826 source#reset
pageno outlines;
2827 state.uioh
<- coe (new outlinelistview ~
source);
2828 G.postRedisplay "enter selector";
2832 let enteroutlinemode =
2833 let f = enterselector false in
2834 fun ()-> f "Document has no outline";
2837 let enterbookmarkmode =
2838 let f = enterselector true in
2839 fun () -> f "Document has no bookmarks (yet)";
2842 let color_of_string s =
2843 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
2844 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
2848 let color_to_string (r, g
, b) =
2849 let r = truncate
(r *. 256.0)
2850 and g
= truncate
(g
*. 256.0)
2851 and b = truncate
(b *. 256.0) in
2852 Printf.sprintf
"%d/%d/%d" r g
b
2855 let irect_of_string s =
2856 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0,y0
,x1
,y1
))
2859 let irect_to_string (x0,y0
,x1
,y1
) =
2860 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
2863 let makecheckers () =
2864 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
2866 converted by Issac Trotts. July 25, 2002 *)
2867 let image_height = 64
2868 and image_width
= 64 in
2872 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
2874 for i
= 0 to image_width
- 1 do
2875 for j
= 0 to image_height - 1 do
2876 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
2877 (if (i
land 8 ) lxor (j
land 8) = 0
2878 then [|255;255;255|] else [|200;200;200|])
2883 let image = make_image () in
2884 let id = GlTex.gen_texture
() in
2885 GlTex.bind_texture `texture_2d
id;
2886 GlPix.store
(`unpack_alignment
1);
2887 GlTex.image2d
image;
2888 List.iter
(GlTex.parameter ~target
:`texture_2d
)
2891 `mag_filter `nearest
;
2892 `min_filter `nearest
];
2896 let setcheckers enabled
=
2897 match state.texid
with
2899 if enabled
then state.texid
<- Some
(makecheckers ())
2904 GlTex.delete_texture texid
;
2905 state.texid
<- None
;
2909 let int_of_string_with_suffix s =
2910 let l = String.length
s in
2914 let suffix = Char.lowercase
s.[l-1] in
2916 | 'k'
-> String.sub
s 0 (l-1), 10
2917 | 'm'
-> String.sub
s 0 (l-1), 20
2918 | 'g'
-> String.sub
s 0 (l-1), 30
2922 let n = int_of_string
s1 in
2923 let m = n lsl shift
in
2925 then raise
(Failure
"value too large")
2929 let string_with_suffix_of_int n =
2937 if n land ((1 lsl 20) - 1) = 0
2940 if n land ((1 lsl 10) - 1) = 0
2947 let h = n mod 1000 in
2950 then string_of_int
h ^
s
2952 let s = Printf.sprintf
"_%03d%s" h s in
2959 let describe_location () =
2961 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
2963 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
2964 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
2968 else (100. *. (float state.y /. float maxy))
2972 Printf.sprintf
"page %d of %d [%.2f%%]"
2973 (fn+1) state.pagecount
percent
2976 "pages %d-%d of %d [%.2f%%]"
2977 (fn+1) (ln
+1) state.pagecount
percent
2981 let btos b = if b then "\xe2\x88\x9a" else "" in
2982 let showextended = ref false in
2983 let leave mode
= function
2984 | Confirm
-> state.mode
<- mode
2985 | Cancel
-> state.mode
<- mode
in
2988 val mutable m_first_time
= true
2989 val mutable m_l
= []
2990 val mutable m_a
= [||]
2991 val mutable m_prev_uioh
= nouioh
2992 val mutable m_prev_mode
= View
2994 inherit lvsourcebase
2996 method reset prev_mode prev_uioh
=
2997 m_a
<- Array.of_list
(List.rev m_l
);
2999 m_prev_mode
<- prev_mode
;
3000 m_prev_uioh
<- prev_uioh
;
3004 if n >= Array.length m_a
3008 | _, _, _, Action
_ -> m_active
<- n
3012 m_first_time
<- false;
3015 method int name get
set =
3017 (name
, `
int get
, 1, Action
(
3020 try set (int_of_string
s)
3022 state.text <- Printf.sprintf
"bad integer `%s': %s"
3023 s (Printexc.to_string exn
)
3026 let te = name ^
": ", "", None
, intentry, ondone in
3027 state.mode
<- Textentry
(te, leave m_prev_mode
);
3031 method int_with_suffix name get
set =
3033 (name
, `intws get
, 1, Action
(
3036 try set (int_of_string_with_suffix s)
3038 state.text <- Printf.sprintf
"bad integer `%s': %s"
3039 s (Printexc.to_string exn
)
3043 name ^
": ", "", None
, intentry_with_suffix, ondone
3045 state.mode
<- Textentry
(te, leave m_prev_mode
);
3049 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3051 (name
, `
bool (btos, get
), offset
, Action
(
3058 method color name get
set =
3060 (name
, `color get
, 1, Action
(
3062 let invalid = (nan
, nan
, nan
) in
3065 try color_of_string s
3067 state.text <- Printf.sprintf
"bad color `%s': %s"
3068 s (Printexc.to_string exn
);
3074 let te = name ^
": ", "", None
, textentry, ondone in
3075 state.text <- color_to_string (get
());
3076 state.mode
<- Textentry
(te, leave m_prev_mode
);
3080 method string name get
set =
3082 (name
, `
string get
, 1, Action
(
3084 let ondone s = set s in
3085 let te = name ^
": ", "", None
, textentry, ondone in
3086 state.mode
<- Textentry
(te, leave m_prev_mode
);
3090 method colorspace name get
set =
3092 (name
, `
string get
, 1, Action
(
3095 let vals = [| "rgb"; "bgr"; "gray" |] in
3097 inherit lvsourcebase
3100 m_active
<- int_of_colorspace conf.colorspace
;
3103 method getitemcount
= Array.length
vals
3104 method getitem
n = (vals.(n), 0)
3105 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3106 ignore
(uioh
, first, pan
, qsearch);
3107 if not cancel
then set active;
3109 method hasaction
_ = true
3113 coe (new listview ~
source ~trusted
:true)
3116 method caption
s offset
=
3117 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3119 method caption2
s f offset
=
3120 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3122 method getitemcount
= Array.length m_a
3125 let tostr = function
3126 | `
int f -> string_of_int
(f ())
3127 | `intws
f -> string_with_suffix_of_int (f ())
3129 | `color
f -> color_to_string (f ())
3130 | `
bool (btos, f) -> btos (f ())
3133 let name, t
, offset
, _ = m_a
.(n) in
3134 ((let s = tostr t
in
3135 if String.length
s > 0
3136 then Printf.sprintf
"%s\t%s" name s
3140 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3144 m_qsearch
<- qsearch;
3146 match m_a
.(active) with
3147 | _, _, _, Action
f -> f uioh
3159 method hasaction
n =
3161 | _, _, _, Action
_ -> true
3165 let rec fillsrc prevmode prevuioh
=
3166 let sep () = src#caption
"" 0 in
3167 let colorp name get
set =
3169 (fun () -> color_to_string (get
()))
3172 let c = color_of_string v in
3175 state.text <- Printf.sprintf
"bad color `%s': %s"
3176 v (Printexc.to_string exn
);
3179 let oldmode = state.mode
in
3180 let birdseye = isbirdseye state.mode
in
3182 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3184 src#
bool "presentation mode"
3185 (fun () -> conf.presentation)
3187 conf.presentation <- v;
3188 state.anchor <- getanchor ();
3191 src#
bool "ignore case in searches"
3192 (fun () -> conf.icase
)
3193 (fun v -> conf.icase
<- v);
3196 (fun () -> conf.preload)
3197 (fun v -> conf.preload <- v);
3199 src#
bool "highlight links"
3200 (fun () -> conf.hlinks
)
3201 (fun v -> conf.hlinks
<- v);
3203 src#
bool "under info"
3204 (fun () -> conf.underinfo
)
3205 (fun v -> conf.underinfo
<- v);
3207 src#
bool "persistent bookmarks"
3208 (fun () -> conf.savebmarks
)
3209 (fun v -> conf.savebmarks
<- v);
3211 src#
bool "proportional display"
3212 (fun () -> conf.proportional
)
3213 (fun v -> reqlayout conf.angle
v);
3215 src#
bool "trim margins"
3216 (fun () -> conf.trimmargins
)
3217 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3219 src#
bool "persistent location"
3220 (fun () -> conf.jumpback
)
3221 (fun v -> conf.jumpback
<- v);
3224 src#
int "vertical margin"
3225 (fun () -> conf.interpagespace)
3227 conf.interpagespace <- n;
3229 match state.layout with
3234 state.maxy <- calcheight ();
3235 let y = getpagey pageno in
3240 (fun () -> conf.pagebias
)
3241 (fun v -> conf.pagebias
<- v);
3243 src#
int "scroll step"
3244 (fun () -> conf.scrollstep
)
3245 (fun n -> conf.scrollstep
<- n);
3247 src#
int "auto scroll step"
3249 match state.autoscroll
with
3251 | _ -> conf.autoscrollstep
)
3253 if state.autoscroll
<> None
3254 then state.autoscroll
<- Some
n;
3255 conf.autoscrollstep
<- n);
3258 (fun () -> truncate
(conf.zoom *. 100.))
3259 (fun v -> setzoom ((float v) /. 100.));
3262 (fun () -> conf.angle
)
3263 (fun v -> reqlayout v conf.proportional
);
3265 src#
int "scroll bar width"
3266 (fun () -> state.scrollw
)
3270 reshape conf.winw
conf.winh
;
3273 src#
int "scroll handle height"
3274 (fun () -> conf.scrollh
)
3275 (fun v -> conf.scrollh
<- v;);
3277 src#
int "thumbnail width"
3278 (fun () -> conf.thumbw
)
3280 conf.thumbw
<- min
4096 v;
3283 leavebirdseye beye
false;
3289 src#caption
"Presentation mode" 0;
3290 src#
bool "scrollbar visible"
3291 (fun () -> conf.scrollbarinpm
)
3293 if v != conf.scrollbarinpm
3295 conf.scrollbarinpm
<- v;
3296 if conf.presentation
3298 state.scrollw
<- if v then conf.scrollbw
else 0;
3299 reshape conf.winw
conf.winh
;
3305 src#caption
"Pixmap cache" 0;
3306 src#int_with_suffix
"size (advisory)"
3307 (fun () -> conf.memlimit
)
3308 (fun v -> conf.memlimit
<- v);
3311 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3312 (string_with_suffix_of_int state.memused
)
3313 (Hashtbl.length
state.tilemap
)) 1;
3316 src#caption
"Layout" 0;
3317 src#caption2
"Dimension"
3319 Printf.sprintf
"%dx%d (virtual %dx%d)"
3325 src#caption2
"Position" (fun () ->
3326 Printf.sprintf
"%dx%d" state.x state.y
3329 src#caption2
"Visible" (fun () -> describe_location ()) 1
3333 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3334 "Save these parameters as global defaults at exit"
3335 (fun () -> conf.bedefault
)
3336 (fun v -> conf.bedefault
<- v)
3340 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3341 src#
bool ~offset
:0 ~
btos "Extended parameters"
3342 (fun () -> !showextended)
3343 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3347 (fun () -> conf.checkers
)
3348 (fun v -> conf.checkers
<- v; setcheckers v);
3350 (fun () -> conf.verbose
)
3351 (fun v -> conf.verbose
<- v);
3352 src#
bool "invert colors"
3353 (fun () -> conf.invert
)
3354 (fun v -> conf.invert
<- v);
3356 (fun () -> conf.maxhfit
)
3357 (fun v -> conf.maxhfit
<- v);
3358 src#
string "uri launcher"
3359 (fun () -> conf.urilauncher
)
3360 (fun v -> conf.urilauncher
<- v);
3361 src#
string "tile size"
3362 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3365 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3366 conf.tileh
<- max
64 w;
3367 conf.tilew
<- max
64 h;
3370 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3371 v (Printexc.to_string exn
));
3372 src#
int "anti-aliasing level"
3373 (fun () -> conf.aalevel
)
3375 conf.aalevel
<- bound v 0 8;
3376 state.anchor <- getanchor ();
3377 opendoc state.path
state.password
;
3379 src#
int "ui font size"
3380 (fun () -> fstate.fontsize
)
3381 (fun v -> setfontsize (bound v 5 100));
3382 colorp "background color"
3383 (fun () -> conf.bgcolor
)
3384 (fun v -> conf.bgcolor
<- v);
3385 src#
bool "crop hack"
3386 (fun () -> conf.crophack
)
3387 (fun v -> conf.crophack
<- v);
3388 src#
string "trim fuzz"
3389 (fun () -> irect_to_string conf.trimfuzz
)
3392 conf.trimfuzz
<- irect_of_string v;
3394 then settrim true conf.trimfuzz
;
3396 state.text <- Printf.sprintf
"bad irect `%s': %s"
3397 v (Printexc.to_string exn
)
3399 src#
string "throttle"
3401 match conf.maxwait
with
3402 | None
-> "show place holder if page is not ready"
3405 then "wait for page to fully render"
3407 "wait " ^ string_of_float
time
3408 ^
" seconds before showing placeholder"
3412 let f = float_of_string
v in
3414 then conf.maxwait
<- None
3415 else conf.maxwait
<- Some
f
3417 state.text <- Printf.sprintf
"bad time `%s': %s"
3418 v (Printexc.to_string exn
)
3420 src#colorspace
"color space"
3421 (fun () -> colorspace_to_string conf.colorspace
)
3423 conf.colorspace
<- colorspace_of_int v;
3430 src#caption
"Document" 0;
3431 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3435 src#caption
"Trimmed margins" 0;
3436 src#caption2
"Dimensions"
3437 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3440 src#reset prevmode prevuioh
;
3444 let prevmode = state.mode
3445 and prevuioh
= state.uioh in
3446 fillsrc prevmode prevuioh
;
3447 let source = (src :> lvsource
) in
3448 state.uioh <- coe (object (self)
3449 inherit listview ~
source ~trusted
:true as super
3450 val mutable m_prevmemused
= 0
3451 method infochanged
= function
3453 if m_prevmemused
!= state.memused
3455 m_prevmemused
<- state.memused
;
3456 G.postRedisplay "memusedchanged";
3458 | Pdim
-> G.postRedisplay "pdimchanged"
3459 | Docinfo
-> fillsrc prevmode prevuioh
3461 method special
key =
3462 if Glut.getModifiers
() land Glut.active_ctrl
= 0
3465 | Glut.KEY_LEFT
-> coe (self#updownlevel ~
-1)
3466 | Glut.KEY_RIGHT
-> coe (self#updownlevel
1)
3467 | _ -> super#special
key
3468 else super#special
key
3470 G.postRedisplay "info";
3476 inherit lvsourcebase
3477 method getitemcount
= Array.length
state.help
3479 let s, n, _ = state.help
.(n) in
3482 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3486 m_qsearch
<- qsearch;
3487 match state.help
.(active) with
3488 | _, _, Action
f -> Some
(f uioh)
3498 method hasaction
n =
3499 match state.help
.(n) with
3500 | _, _, Action
_ -> true
3507 state.uioh <- coe (new listview ~
source ~trusted
:true);
3508 G.postRedisplay "help";
3511 let quickbookmark ?title
() =
3512 match state.layout with
3518 let sec = Unix.gettimeofday
() in
3519 let tm = Unix.localtime
sec in
3520 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
3524 (tm.Unix.tm_year
+ 1900)
3527 | Some
title -> title
3530 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
3535 state.fullscreen
<- None
;
3536 Glut.reshapeWindow
w h;
3539 let viewkeyboard key =
3541 let mode = state.mode in
3542 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
3545 G.postRedisplay "view:enttext"
3547 let c = Char.chr
key in
3549 | '
\027'
| 'q'
-> (* escape *)
3550 begin match state.mstate
with
3552 state.mstate
<- Mnone
;
3553 Glut.setCursor
Glut.CURSOR_INHERIT
;
3554 G.postRedisplay "kill zoom rect";
3559 | '
\008'
-> (* backspace *)
3560 let y = getnav ~
-1 in
3561 gotoy_and_clear_text y
3569 G.postRedisplay "dehighlight";
3572 let ondone isforw
s =
3573 cbput state.hists
.pat
s;
3574 state.searchpattern
<- s;
3577 let s = String.create
1 in
3579 enttext (s, "", Some
(onhist state.hists
.pat
),
3580 textentry, ondone (c ='
/'
))
3582 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3583 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3584 setzoom (conf.zoom +. incr)
3589 try int_of_string
s with exc
->
3590 state.text <- Printf.sprintf
"bad integer `%s': %s"
3591 s (Printexc.to_string exc
);
3597 state.text <- "page bias is now " ^ string_of_int
n;
3600 enttext ("page bias: ", "", None
, intentry, ondone)
3602 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3603 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3604 setzoom (max
0.01 (conf.zoom -. decr))
3607 let ondone msg
= state.text <- msg
in
3609 "option [acfhilpstvAPRSZTI]: ", "", None
,
3610 optentry state.mode, ondone
3613 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3616 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3617 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
3621 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3627 try int_of_string
s with exc
->
3628 state.text <- Printf.sprintf
"bad integer `%s': %s"
3629 s (Printexc.to_string exc
);
3635 cbput state.hists
.pag
(string_of_int
n);
3636 gotoy_and_clear_text (getpagey (n + conf.pagebias
- 1))
3639 let pageentry text key =
3640 match Char.unsafe_chr
key with
3641 | 'g'
-> TEdone
text
3642 | _ -> intentry text key
3644 let text = "x" in text.[0] <- c;
3645 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
3648 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
3649 reshape conf.winw
conf.winh
;
3652 conf.hlinks
<- not
conf.hlinks
;
3653 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
3654 G.postRedisplay "toggle highlightlinks";
3657 begin match state.autoscroll
with
3659 conf.autoscrollstep
<- step
;
3660 state.autoscroll
<- None
3662 if conf.autoscrollstep
= 0
3663 then state.autoscroll
<- Some
1
3664 else state.autoscroll
<- Some
conf.autoscrollstep
3668 conf.presentation <- not
conf.presentation;
3669 if conf.presentation
3671 if not
conf.scrollbarinpm
3672 then state.scrollw
<- 0;
3675 state.scrollw
<- conf.scrollbw
;
3677 showtext ' '
("presentation mode " ^
3678 if conf.presentation then "on" else "off");
3679 state.anchor <- getanchor ();
3683 begin match state.fullscreen
with
3685 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
3688 state.fullscreen
<- None
;
3693 gotoy_and_clear_text 0
3696 gotopage1 (state.pagecount
- 1) 0
3699 search state.searchpattern
true
3702 search state.searchpattern
false
3705 begin match state.layout with
3708 gotoy_and_clear_text (getpagey l.pageno)
3712 begin match List.rev
state.layout with
3715 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
3716 gotoy_and_clear_text (getpagey pageno)
3719 | '
\127'
-> (* del *)
3720 begin match state.layout with
3723 let pageno = max
0 (l.pageno-1) in
3724 gotoy_and_clear_text (getpagey pageno)
3728 showtext ' '
(describe_location ());
3731 begin match state.layout with
3734 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
3739 enterbookmarkmode ()
3749 match state.layout with
3752 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
3756 enttext ("bookmark: ", "", None
, textentry, ondone)
3760 showtext ' '
"Quick bookmark added";
3763 begin match state.layout with
3765 let rect = getpdimrect
l.pagedimno
in
3769 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
3770 truncate
(1.2 *. (rect.(3) -. rect.(0))))
3772 (truncate
(rect.(1) -. rect.(0)),
3773 truncate
(rect.(3) -. rect.(0)))
3775 let w = truncate
((float w)*.conf.zoom)
3776 and h = truncate
((float h)*.conf.zoom) in
3779 state.anchor <- getanchor ();
3780 doreshape (w + state.scrollw
) (h + conf.interpagespace)
3782 G.postRedisplay "z";
3787 | '
\000'
-> (* ctrl-2 *)
3788 let maxw = getmaxw
() in
3790 then setzoom (maxw /. float conf.winw
)
3793 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
3797 bound (conf.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
3799 G.postRedisplay "brightness";
3802 begin match state.mode with
3803 | Birdseye beye
-> upbirdseye beye
3804 | _ -> gotoy (clamp (-conf.scrollstep
))
3808 begin match state.mode with
3809 | Birdseye beye
-> downbirdseye beye
3810 | _ -> gotoy (clamp conf.scrollstep
)
3814 state.anchor <- getanchor ();
3815 opendoc state.path
state.password
3817 | '
v'
when conf.debug
->
3820 match getopaque l.pageno with
3823 let x0, y0
, x1
, y1
= pagebbox opaque
in
3824 let a,b = float x0, float y0
in
3825 let c,d = float x1
, float y0
in
3826 let e,f = float x1
, float y1
in
3827 let h,j
= float x0, float y1
in
3828 let rect = (a,b,c,d,e,f,h,j
) in
3830 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
3832 G.postRedisplay "v";
3835 vlog "huh? %d %c" key (Char.chr
key);
3838 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
3840 | 27 -> (* escape *)
3841 leavebirdseye beye
true
3843 | 12 -> (* ctrl-l *)
3844 let y, h = getpageyh pageno in
3845 let top = (conf.winh
- h) / 2 in
3846 gotoy (max
0 (y - top))
3849 leavebirdseye beye
false
3855 let keyboard ~
key ~
x ~
y =
3858 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
3859 then wcmd "interrupt" []
3860 else state.uioh <- state.uioh#
key key
3863 let birdseyespecial key ((conf, leftx
, _, hooverpageno
, anchor) as beye
) =
3865 | Glut.KEY_UP
-> upbirdseye beye
3866 | Glut.KEY_DOWN
-> downbirdseye beye
3868 | Glut.KEY_PAGE_UP
->
3869 begin match state.layout with
3873 state.mode <- Birdseye
(
3874 conf, leftx
, l.pageno, hooverpageno
, anchor
3876 gotopage1 l.pageno 0;
3879 let layout = layout (state.y-conf.winh
) conf.winh
in
3881 | [] -> gotoy (clamp (-conf.winh
))
3883 state.mode <- Birdseye
(
3884 conf, leftx
, l.pageno, hooverpageno
, anchor
3886 gotopage1 l.pageno 0
3889 | [] -> gotoy (clamp (-conf.winh
))
3892 | Glut.KEY_PAGE_DOWN
->
3893 begin match List.rev
state.layout with
3895 let layout = layout (state.y + conf.winh
) conf.winh
in
3896 begin match layout with
3898 let incr = l.pageh
- l.pagevh in
3903 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
3905 G.postRedisplay "birdseye pagedown";
3907 else gotoy (clamp (incr + conf.interpagespace*2));
3911 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
3912 gotopage1 l.pageno 0;
3915 | [] -> gotoy (clamp conf.winh
)
3919 state.mode <- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
3923 let pageno = state.pagecount
- 1 in
3924 state.mode <- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3925 if not
(pagevisible state.layout pageno)
3928 match List.rev
state.pdims
with
3930 | (_, _, h, _) :: _ -> h
3932 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
3933 else G.postRedisplay "birdseye end";
3937 let setautoscrollspeed step goingdown
=
3938 let incr = max
1 ((abs step
) / 2) in
3939 let incr = if goingdown
then incr else -incr in
3940 let astep = step
+ incr in
3941 state.autoscroll
<- Some
astep;
3944 let special ~
key ~
x ~
y =
3947 state.uioh <- state.uioh#
special key
3952 match state.mode with
3953 | Textentry
_ -> scalecolor 0.4
3954 | View
-> scalecolor 1.0
3955 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
3956 if l.pageno = hooverpageno
3959 if l.pageno = pageno
3965 begin match getopaque l.pageno with
3967 if tileready l l.pagex l.pagey
3969 let x = l.pagedispx
- l.pagex
3970 and y = l.pagedispy
- l.pagey in
3971 postprocess opaque
conf.hlinks
x y;
3978 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3979 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
3980 let sh = float conf.winh
/. sh in
3981 let sh = max
sh (float conf.scrollh
) in
3986 else float y /. float maxy
3988 let position = (float conf.winh
-. sh) *. percent in
3991 if position +. sh > float conf.winh
3992 then float conf.winh
-. sh
3999 let winw = conf.winw - state.scrollw
- 1 in
4000 let fwinw = float winw in
4002 let sw = fwinw /. float state.w in
4003 let sw = fwinw *. sw in
4004 max
sw (float conf.scrollh
)
4007 let f = state.w+winw in
4008 let r = float (winw-x) /. float f in
4009 let p = fwinw *. r in
4013 if position +. sw > fwinw
4014 then fwinw -. position
4020 let scrollindicator () =
4021 GlDraw.color (0.64 , 0.64, 0.64);
4023 (float (conf.winw - state.scrollw
), 0.)
4024 (float conf.winw, float conf.winh
)
4027 (0., float (conf.winh
- state.hscrollh))
4028 (float (conf.winw - state.scrollw
- 1), float conf.winh
)
4030 GlDraw.color (0.0, 0.0, 0.0);
4032 let position, sh = scrollph state.y in
4034 (float (conf.winw - state.scrollw
), position)
4035 (float conf.winw, position +. sh)
4037 let position, sw = scrollpw state.x in
4039 (position, float (conf.winh
- state.hscrollh))
4040 (position +. sw, float conf.winh
)
4044 let pagetranslatepoint l x y =
4045 let dy = y - l.pagedispy
in
4046 let y = dy + l.pagey in
4047 let dx = x - l.pagedispx
in
4048 let x = dx + l.pagex in
4053 match state.mstate
with
4054 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4057 | Msel
((x0, y0
), (x1
, y1
)) ->
4058 let rec loop = function
4060 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
4061 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
4063 match getopaque l.pageno with
4065 let dx, dy = pagetranslatepoint l 0 0 in
4070 GlMat.mode `modelview
;
4072 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4073 seltext opaque
(x0, y0
, x1
, y1
);
4084 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4085 GlDraw.polygon_mode `both `fill
;
4086 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4088 (fun (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
4090 if l.pageno = pageno
4092 let dx = float (l.pagedispx
- l.pagex) in
4093 let dy = float (l.pagedispy
- l.pagey) in
4094 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4095 GlDraw.begins `quads
;
4097 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4098 GlDraw.vertex2
(x1
+.dx, y1
+.dy);
4099 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4100 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4111 GlClear.color (scalecolor2 conf.bgcolor
);
4112 GlClear.clear
[`
color];
4113 List.iter
drawpage state.layout;
4118 begin match state.mstate
with
4119 | Mzoomrect
((x0, y0
), (x1
, y1
)) ->
4121 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4122 GlDraw.polygon_mode `both `fill
;
4123 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4124 GlDraw.rect (float x0, float y0
)
4125 (float x1
, float y1
);
4130 Glut.swapBuffers
();
4134 let rec f = function
4136 begin match getopaque l.pageno with
4138 let x0 = l.pagedispx
in
4139 let x1 = x0 + l.pagevw in
4140 let y0 = l.pagedispy
in
4141 let y1 = y0 + l.pagevh in
4142 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4144 let px, py = pagetranslatepoint l x y in
4145 match whatsunder opaque
px py with
4157 let zoomrect x y x1 y1 =
4160 and y0 = min
y y1 in
4161 gotoy (state.y + y0);
4162 state.anchor <- getanchor ();
4163 let zoom = (float conf.winw *. conf.zoom) /. float (x1 - x0) in
4165 if state.w < conf.winw - state.scrollw
4166 then (conf.winw - state.scrollw
- state.w) / 2
4169 state.x <- (state.x + margin) - x0;
4171 Glut.setCursor
Glut.CURSOR_INHERIT
;
4172 state.mstate
<- Mnone
;
4176 let winw = conf.winw - state.scrollw
- 1 in
4177 let s = float x /. float winw in
4178 let destx = truncate
(float (state.w + winw) *. s) in
4179 state.x <- winw - destx;
4180 gotoy_and_clear_text state.y;
4181 state.mstate
<- Mscrollx
;
4185 let s = float y /. float conf.winh
in
4186 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4187 gotoy_and_clear_text desty;
4188 state.mstate
<- Mscrolly
;
4191 let viewmouse button bstate
x y =
4193 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4194 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4196 match state.mstate
with
4197 | Mzoom
(oldn
, i
) ->
4205 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4207 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4209 let zoom = conf.zoom -. incr in
4211 state.mstate
<- Mzoom
(n, 0);
4213 state.mstate
<- Mzoom
(n, i
+1);
4215 else state.mstate
<- Mzoom
(n, 0)
4217 | _ -> state.mstate
<- Mzoom
(n, 0)
4220 match state.autoscroll
with
4221 | Some step
-> setautoscrollspeed step
(n=4)
4225 then -conf.scrollstep
4226 else conf.scrollstep
4228 let incr = incr * 2 in
4229 let y = clamp incr in
4230 gotoy_and_clear_text y
4233 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4234 if bstate
= Glut.DOWN
4236 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4237 state.mstate
<- Mpan
(x, y)
4240 state.mstate
<- Mnone
4242 | Glut.RIGHT_BUTTON
->
4243 if bstate
= Glut.DOWN
4245 Glut.setCursor
Glut.CURSOR_CYCLE
;
4247 state.mstate
<- Mzoomrect
(p, p)
4250 match state.mstate
with
4251 | Mzoomrect
((x0, y0), _) -> zoomrect x0 y0 x y
4253 Glut.setCursor
Glut.CURSOR_INHERIT
;
4254 state.mstate
<- Mnone
4257 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4258 if bstate
= Glut.DOWN
4260 let position, sh = scrollph state.y in
4261 if y > truncate
position && y < truncate
(position +. sh)
4262 then state.mstate
<- Mscrolly
4265 state.mstate
<- Mnone
4267 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4268 if bstate
= Glut.DOWN
4270 let position, sw = scrollpw state.x in
4271 if x > truncate
position && x < truncate
(position +. sw)
4272 then state.mstate
<- Mscrollx
4275 state.mstate
<- Mnone
4277 | Glut.LEFT_BUTTON
->
4278 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4279 begin match dest with
4280 | Ulinkgoto
(pageno, top) ->
4284 gotopage1 pageno top;
4290 | Unone
when bstate
= Glut.DOWN
->
4291 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4292 state.mstate
<- Mpan
(x, y);
4294 | Unone
| Utext
_ ->
4295 if bstate
= Glut.DOWN
4297 if conf.angle
mod 360 = 0
4299 state.mstate
<- Msel
((x, y), (x, y));
4300 G.postRedisplay "mouse select";
4304 match state.mstate
with
4307 | Mzoom
_ | Mscrollx
| Mscrolly
->
4308 state.mstate
<- Mnone
4310 | Mzoomrect
((x0, y0), _) ->
4314 Glut.setCursor
Glut.CURSOR_INHERIT
;
4315 state.mstate
<- Mnone
4317 | Msel
((_, y0), (_, y1)) ->
4319 if (y0 >= l.pagedispy
&& y0 <= (l.pagedispy
+ l.pagevh))
4320 || ((y1 >= l.pagedispy
&& y1 <= (l.pagedispy
+ l.pagevh)))
4322 match getopaque l.pageno with
4327 List.iter
f state.layout;
4328 copysel
""; (* ugly *)
4329 Glut.setCursor
Glut.CURSOR_INHERIT
;
4330 state.mstate
<- Mnone
;
4337 let birdseyemouse button bstate
x y
4338 (conf, leftx
, _, hooverpageno
, anchor) =
4340 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4341 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4342 let rec loop = function
4345 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4346 && x > margin && x < margin + l.pagew
4348 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4353 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4357 let mouse bstate button
x y =
4358 state.uioh <- state.uioh#button button bstate
x y;
4361 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4364 state.uioh <- state.uioh#
motion x y
4368 state.uioh <- state.uioh#
pmotion x y;
4375 begin match state.mode with
4376 | Textentry
textentry -> textentrykeyboard key textentry
4377 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4378 | View
-> viewkeyboard key
4382 method special key =
4383 begin match state.mode with
4384 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4388 birdseyespecial key vals
4390 | View
when key = Glut.KEY_F1
->
4394 begin match state.autoscroll
with
4395 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4396 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4401 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4403 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4405 if Glut.getModifiers
() land Glut.active_shift
!= 0
4406 then (setzoom state.prevzoom
; state.y)
4407 else clamp (-conf.winh
/2)
4408 else clamp (-conf.scrollstep
)
4410 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4412 if Glut.getModifiers
() land Glut.active_shift
!= 0
4413 then (setzoom state.prevzoom
; state.y)
4414 else clamp (conf.winh
/2)
4415 else clamp (conf.scrollstep
)
4416 | Glut.KEY_PAGE_UP
->
4417 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4419 match state.layout with
4421 | l :: _ -> state.y - l.pagey
4424 | Glut.KEY_PAGE_DOWN
->
4425 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4427 match List.rev
state.layout with
4429 | l :: _ -> getpagey l.pageno
4437 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
4439 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
4440 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
4441 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
4443 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
4445 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4446 then (conf.winw / 2)
4449 state.x <- state.x - dx;
4451 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
4453 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4454 then (conf.winw / 2)
4457 state.x <- state.x + dx;
4462 gotoy_and_clear_text y
4465 | Textentry
te -> textentryspecial key te
4469 method button button bstate
x y =
4470 begin match state.mode with
4471 | View
-> viewmouse button bstate
x y
4472 | Birdseye beye
-> birdseyemouse button bstate
x y beye
4478 begin match state.mode with
4480 | View
| Birdseye
_ ->
4481 match state.mstate
with
4482 | Mzoom
_ | Mnone
-> ()
4487 state.mstate
<- Mpan
(x, y);
4488 if conf.zoom > 1.0 then state.x <- state.x + dx;
4490 gotoy_and_clear_text y
4493 state.mstate
<- Msel
(a, (x, y));
4494 G.postRedisplay "motion select";
4497 let y = min
conf.winh
(max
0 y) in
4501 let x = min
conf.winw (max
0 x) in
4504 | Mzoomrect
(p0
, _) ->
4505 state.mstate
<- Mzoomrect
(p0
, (x, y));
4506 G.postRedisplay "motion zoomrect";
4510 method pmotion x y =
4511 begin match state.mode with
4512 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
4513 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4514 let rec loop = function
4516 if hooverpageno
!= -1
4518 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
4519 G.postRedisplay "pmotion birdseye no hoover";
4522 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4523 && x > margin && x < margin + l.pagew
4525 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
4526 G.postRedisplay "pmotion birdseye hoover";
4535 match state.mstate
with
4537 begin match getunder x y with
4538 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
4540 if conf.underinfo
then showtext 'u'
("ri: " ^
uri);
4541 Glut.setCursor
Glut.CURSOR_INFO
4542 | Ulinkgoto
(page
, _) ->
4544 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
4545 Glut.setCursor
Glut.CURSOR_INFO
4547 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
4548 Glut.setCursor
Glut.CURSOR_TEXT
4551 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
4556 method infochanged
_ = ()
4563 let fontpath = ref "";;
4564 let wmclasshack = ref false;;
4567 let l = String.length
s in
4568 let b = Buffer.create
l in
4576 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
4577 | _ -> Sys.getenv
"HOME"
4580 ("Can not determine home directory location: " ^
4581 Printexc.to_string exn
);
4585 let config_of c attrs
=
4589 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
4590 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
4591 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
4592 | "preload" -> { c with preload = bool_of_string
v }
4593 | "page-bias" -> { c with pagebias
= int_of_string
v }
4594 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
4595 | "auto-scroll-step" ->
4596 { c with autoscrollstep
= max
0 (int_of_string
v) }
4597 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
4598 | "crop-hack" -> { c with crophack
= bool_of_string
v }
4601 match String.lowercase
v with
4602 | "true" -> Some infinity
4604 | f -> Some
(float_of_string
f)
4606 { c with maxwait
= mw}
4607 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
4608 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
4609 | "vertical-margin" ->
4610 { c with interpagespace = max
0 (int_of_string
v) }
4612 let zoom = float_of_string
v /. 100. in
4613 let zoom = max
zoom 0.0 in
4614 { c with zoom = zoom }
4615 | "presentation" -> { c with presentation = bool_of_string
v }
4616 | "rotation-angle" -> { c with angle
= int_of_string
v }
4617 | "width" -> { c with winw = max
20 (int_of_string
v) }
4618 | "height" -> { c with winh
= max
20 (int_of_string
v) }
4619 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
4620 | "proportional-display" -> { c with proportional
= bool_of_string
v }
4621 | "pixmap-cache-size" ->
4622 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
4623 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
4624 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
4625 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
4626 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
4627 | "background-color" -> { c with bgcolor
= color_of_string v }
4628 | "scrollbar-in-presentation" ->
4629 { c with scrollbarinpm
= bool_of_string
v }
4630 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
4631 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
4633 { c with mumemlimit
= max
1024 (int_of_string_with_suffix v) }
4634 | "checkers" -> { c with checkers
= bool_of_string
v }
4635 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
4636 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
4637 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
4638 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
4639 | "uri-launcher" -> { c with urilauncher
= unent v }
4640 | "color-space" -> { c with colorspace
= colorspace_of_string v }
4641 | "invert-colors" -> { c with invert
= bool_of_string
v }
4642 | "brightness" -> { c with colorscale
= float_of_string
v }
4645 prerr_endline
("Error processing attribute (`" ^
4646 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
4649 let rec fold c = function
4652 let c = apply c k
v in
4658 let fromstring f pos
n v d =
4661 dolog "Error processing attribute (%S=%S) at %d\n%s"
4662 n v pos
(Printexc.to_string exn
)
4667 let bookmark_of attrs
=
4668 let rec fold title page rely
= function
4669 | ("title", v) :: rest
-> fold v page rely rest
4670 | ("page", v) :: rest
-> fold title v rely rest
4671 | ("rely", v) :: rest
-> fold title page
v rest
4672 | _ :: rest
-> fold title page rely rest
4673 | [] -> title, page
, rely
4675 fold "invalid" "0" "0" attrs
4679 let rec fold path page rely pan
= function
4680 | ("path", v) :: rest
-> fold v page rely pan rest
4681 | ("page", v) :: rest
-> fold path
v rely pan rest
4682 | ("rely", v) :: rest
-> fold path page
v pan rest
4683 | ("pan", v) :: rest
-> fold path page rely
v rest
4684 | _ :: rest
-> fold path page rely pan rest
4685 | [] -> path
, page
, rely
, pan
4687 fold "" "0" "0" "0" attrs
4690 let setconf dst
src =
4691 dst
.scrollbw
<- src.scrollbw
;
4692 dst
.scrollh
<- src.scrollh
;
4693 dst
.icase
<- src.icase
;
4694 dst
.preload <- src.preload;
4695 dst
.pagebias
<- src.pagebias
;
4696 dst
.verbose
<- src.verbose
;
4697 dst
.scrollstep
<- src.scrollstep
;
4698 dst
.maxhfit
<- src.maxhfit
;
4699 dst
.crophack
<- src.crophack
;
4700 dst
.autoscrollstep
<- src.autoscrollstep
;
4701 dst
.maxwait
<- src.maxwait
;
4702 dst
.hlinks
<- src.hlinks
;
4703 dst
.underinfo
<- src.underinfo
;
4704 dst
.interpagespace <- src.interpagespace;
4705 dst
.zoom <- src.zoom;
4706 dst
.presentation <- src.presentation;
4707 dst
.angle
<- src.angle
;
4708 dst
.winw <- src.winw;
4709 dst
.winh
<- src.winh
;
4710 dst
.savebmarks
<- src.savebmarks
;
4711 dst
.memlimit
<- src.memlimit
;
4712 dst
.proportional
<- src.proportional
;
4713 dst
.texcount
<- src.texcount
;
4714 dst
.sliceheight
<- src.sliceheight
;
4715 dst
.thumbw
<- src.thumbw
;
4716 dst
.jumpback
<- src.jumpback
;
4717 dst
.bgcolor
<- src.bgcolor
;
4718 dst
.scrollbarinpm
<- src.scrollbarinpm
;
4719 dst
.tilew
<- src.tilew
;
4720 dst
.tileh
<- src.tileh
;
4721 dst
.mumemlimit
<- src.mumemlimit
;
4722 dst
.checkers
<- src.checkers
;
4723 dst
.aalevel
<- src.aalevel
;
4724 dst
.trimmargins
<- src.trimmargins
;
4725 dst
.trimfuzz
<- src.trimfuzz
;
4726 dst
.urilauncher
<- src.urilauncher
;
4727 dst
.colorspace
<- src.colorspace
;
4728 dst
.invert
<- src.invert
;
4729 dst
.colorscale
<- src.colorscale
;
4733 let h = Hashtbl.create
10 in
4734 let dc = { defconf with angle
= defconf.angle
} in
4735 let rec toplevel v t spos
_ =
4737 | Vdata
| Vcdata
| Vend
-> v
4738 | Vopen
("llppconfig", _, closed
) ->
4741 else { v with f = llppconfig
}
4743 error
"unexpected subelement at top level" s spos
4744 | Vclose
_ -> error
"unexpected close at top level" s spos
4746 and llppconfig
v t spos
_ =
4748 | Vdata
| Vcdata
-> v
4749 | Vend
-> error
"unexpected end of input in llppconfig" s spos
4750 | Vopen
("defaults", attrs
, closed
) ->
4751 let c = config_of dc attrs
in
4755 else { v with f = skip
"defaults" (fun () -> v) }
4757 | Vopen
("ui-font", attrs
, closed
) ->
4758 let rec getsize size
= function
4760 | ("size", v) :: rest
->
4762 fromstring int_of_string spos
"size" v fstate.fontsize
in
4764 | l -> getsize size l
4766 fstate.fontsize
<- getsize fstate.fontsize attrs
;
4769 else { v with f = uifont
(Buffer.create
10) }
4771 | Vopen
("doc", attrs
, closed
) ->
4772 let pathent, spage
, srely
, span
= doc_of attrs
in
4773 let path = unent pathent
4774 and pageno = fromstring int_of_string spos
"page" spage
0
4775 and rely
= fromstring float_of_string spos
"rely" srely
0.0
4776 and pan
= fromstring int_of_string spos
"pan" span
0 in
4777 let c = config_of dc attrs
in
4778 let anchor = (pageno, rely
) in
4780 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
4781 else { v with f = doc
path pan
anchor c [] }
4784 error
"unexpected subelement in llppconfig" s spos
4786 | Vclose
"llppconfig" -> { v with f = toplevel }
4787 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
4789 and uifont
b v t spos epos
=
4792 Buffer.add_substring
b s spos
(epos
- spos
);
4794 | Vopen
(_, _, _) ->
4795 error
"unexpected subelement in ui-font" s spos
4796 | Vclose
"ui-font" ->
4797 if String.length
!fontpath = 0
4798 then fontpath := Buffer.contents
b;
4799 { v with f = llppconfig
}
4800 | Vclose
_ -> error
"unexpected close in ui-font" s spos
4801 | Vend
-> error
"unexpected end of input in ui-font" s spos
4803 and doc
path pan
anchor c bookmarks
v t spos
_ =
4805 | Vdata
| Vcdata
-> v
4806 | Vend
-> error
"unexpected end of input in doc" s spos
4807 | Vopen
("bookmarks", _, closed
) ->
4810 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
4812 | Vopen
(_, _, _) ->
4813 error
"unexpected subelement in doc" s spos
4816 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
4817 { v with f = llppconfig
}
4819 | Vclose
_ -> error
"unexpected close in doc" s spos
4821 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
4823 | Vdata
| Vcdata
-> v
4824 | Vend
-> error
"unexpected end of input in bookmarks" s spos
4825 | Vopen
("item", attrs
, closed
) ->
4826 let titleent, spage
, srely
= bookmark_of attrs
in
4827 let page = fromstring int_of_string spos
"page" spage
0
4828 and rely
= fromstring float_of_string spos
"rely" srely
0.0 in
4829 let bookmarks = (unent titleent, 0, (page, rely
)) :: bookmarks in
4831 then { v with f = pbookmarks
path pan
anchor c bookmarks }
4834 { v with f = skip
"item" f }
4837 error
"unexpected subelement in bookmarks" s spos
4839 | Vclose
"bookmarks" ->
4840 { v with f = doc
path pan
anchor c bookmarks }
4842 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
4844 and skip tag
f v t spos
_ =
4846 | Vdata
| Vcdata
-> v
4848 error
("unexpected end of input in skipped " ^ tag
) s spos
4849 | Vopen
(tag'
, _, closed
) ->
4853 let f'
() = { v with f = skip tag
f } in
4854 { v with f = skip tag'
f'
}
4858 else error
("unexpected close in skipped " ^ tag
) s spos
4861 parse
{ f = toplevel; accu = () } s;
4867 let len = in_channel_length ic
in
4868 let s = String.create
len in
4869 really_input ic
s 0 len;
4872 | Parse_error
(msg
, s, pos
) ->
4873 let subs = subs s pos
in
4874 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
4875 failwith
("parse error: " ^
s)
4878 failwith
("config load error: " ^
Printexc.to_string exn
)
4884 let dir = Filename.concat
home ".config" in
4885 if Sys.is_directory
dir then dir else home
4888 Filename.concat
dir "llpp.conf"
4891 let confpath = ref defconfpath;;
4894 if Sys.file_exists
!confpath
4897 (try Some
(open_in_bin
!confpath)
4900 ("Error opening configuation file `" ^
!confpath ^
"': " ^
4901 Printexc.to_string exn
);
4910 ("Error loading configuation from `" ^
!confpath ^
"': " ^
4911 Printexc.to_string exn
);
4917 f (Hashtbl.create
0, defconf)
4922 let pc, pb
, px, pa
=
4924 Hashtbl.find h (Filename.basename
state.path)
4925 with Not_found
-> dc, [], 0, (0, 0.0)
4929 state.bookmarks <- pb
;
4931 state.scrollw
<- conf.scrollbw
;
4933 then state.anchor <- pa
;
4934 cbput state.hists
.nav pa
;
4939 let add_attrs bb always
dc c =
4942 then Printf.bprintf bb
"\n %s='%b'" s a
4945 then Printf.bprintf bb
"\n %s='%d'" s a
4948 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
4951 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
4954 then Printf.bprintf bb
"\n %s='%f'" s a
4958 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
4962 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
4966 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
4970 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
4980 else string_of_float
f
4982 Printf.bprintf bb
"\n %s='%s'" s v
4986 then dc.winw, dc.winh
4988 match state.fullscreen
with
4990 | None
-> c.winw, c.winh
4992 let zoom, presentation, interpagespace, maxwait
=
4994 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
4996 match state.mode with
4997 | Birdseye
(bc
, _, _, _, _) ->
4998 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
4999 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5001 oi
"width" w dc.winw;
5002 oi
"height" h dc.winh
;
5003 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5004 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5005 ob "case-insensitive-search" c.icase
dc.icase
;
5006 ob "preload" c.preload dc.preload;
5007 oi
"page-bias" c.pagebias
dc.pagebias
;
5008 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5009 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5010 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5011 ob "crop-hack" c.crophack
dc.crophack
;
5012 oW
"throttle" maxwait
dc.maxwait
;
5013 ob "highlight-links" c.hlinks
dc.hlinks
;
5014 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5015 oi
"vertical-margin" interpagespace dc.interpagespace;
5016 oz
"zoom" zoom dc.zoom;
5017 ob "presentation" presentation dc.presentation;
5018 oi
"rotation-angle" c.angle
dc.angle
;
5019 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5020 ob "proportional-display" c.proportional
dc.proportional
;
5021 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5022 oi
"tex-count" c.texcount
dc.texcount
;
5023 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5024 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5025 ob "persistent-location" c.jumpback
dc.jumpback
;
5026 oc
"background-color" c.bgcolor
dc.bgcolor
;
5027 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5028 oi
"tile-width" c.tilew
dc.tilew
;
5029 oi
"tile-height" c.tileh
dc.tileh
;
5030 oI
"mupdf-memlimit" c.mumemlimit
dc.mumemlimit
;
5031 ob "checkers" c.checkers
dc.checkers
;
5032 oi
"aalevel" c.aalevel
dc.aalevel
;
5033 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5034 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5035 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5036 oC
"color-space" c.colorspace
dc.colorspace
;
5037 ob "invert-colors" c.invert
dc.invert
;
5038 oF
"brightness" c.colorscale
dc.colorscale
;
5040 then ob "wmclass-hack" !wmclasshack false;
5044 let uifontsize = fstate.fontsize
in
5045 let bb = Buffer.create
32768 in
5047 let dc = if conf.bedefault
then conf else dc in
5048 Buffer.add_string
bb "<llppconfig>\n";
5050 if String.length
!fontpath > 0
5052 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5058 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5061 Buffer.add_string
bb "<defaults ";
5062 add_attrs bb true dc dc;
5063 Buffer.add_string
bb "/>\n";
5065 let adddoc path pan
anchor c bookmarks =
5066 if bookmarks == [] && c = dc && anchor = emptyanchor
5069 Printf.bprintf
bb "<doc path='%s'"
5070 (enent
path 0 (String.length
path));
5072 if anchor <> emptyanchor
5074 let n, y = anchor in
5075 Printf.bprintf
bb " page='%d'" n;
5078 Printf.bprintf
bb " rely='%f'" y
5083 then Printf.bprintf
bb " pan='%d'" pan
;
5085 add_attrs bb false dc c;
5087 begin match bookmarks with
5088 | [] -> Buffer.add_string
bb "/>\n"
5090 Buffer.add_string
bb ">\n<bookmarks>\n";
5091 List.iter
(fun (title, _level
, (page, rely
)) ->
5093 "<item title='%s' page='%d'"
5094 (enent
title 0 (String.length
title))
5099 Printf.bprintf
bb " rely='%f'" rely
5101 Buffer.add_string
bb "/>\n";
5103 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5109 match state.mode with
5110 | Birdseye
(_, pan, _, _, _) -> pan
5113 let basename = Filename.basename state.path in
5114 adddoc basename pan (getanchor ())
5117 match state.autoscroll
with
5119 | None
-> conf.autoscrollstep
}
5120 (if conf.savebmarks
then state.bookmarks else []);
5122 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5124 then adddoc path x y c bookmarks
5126 Buffer.add_string
bb "</llppconfig>";
5129 if Buffer.length
bb > 0
5132 let tmp = !confpath ^
".tmp" in
5133 let oc = open_out_bin
tmp in
5134 Buffer.output_buffer
oc bb;
5136 Unix.rename
tmp !confpath;
5139 ("error while saving configuration: " ^
Printexc.to_string exn
)
5146 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5147 "<password> Set password");
5149 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5150 "<path> Set path to the user interface font");
5152 ("-c", Arg.String
(fun s -> Config.confpath := s),
5153 "<path> Set path to the configuration file");
5155 ("-v", Arg.Unit
(fun () ->
5157 "%s\nconfiguration path: %s\n"
5161 exit
0), " Print version and exit");
5164 (fun s -> state.path <- s)
5165 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5167 if String.length
state.path = 0
5168 then (prerr_endline
"file name missing"; exit
1);
5172 let _ = Glut.init
Sys.argv
in
5173 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5174 let () = Glut.initWindowSize
conf.winw conf.winh
in
5175 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5177 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5178 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5179 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5184 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5186 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5187 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5188 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5189 Unix.bind
sock addr;
5191 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5192 Unix.connect
csock addr;
5193 let ssock, _ = Unix.accept
sock in
5196 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5197 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5204 let () = Glut.displayFunc
display in
5205 let () = Glut.reshapeFunc
reshape in
5206 let () = Glut.keyboardFunc
keyboard in
5207 let () = Glut.specialFunc
special in
5208 let () = Glut.idleFunc
(Some
idle) in
5209 let () = Glut.mouseFunc
mouse in
5210 let () = Glut.motionFunc
motion in
5211 let () = Glut.passiveMotionFunc
pmotion in
5213 setcheckers conf.checkers
;
5215 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5216 conf.texcount
, conf.sliceheight
, conf.mumemlimit
, conf.colorspace
,
5217 !Config.wmclasshack, !Config.fontpath
5219 state.csock <- csock;
5220 state.ssock <- ssock;
5221 state.text <- "Opening " ^
state.path;
5222 setaalevel
conf.aalevel
;
5223 writeopen state.path state.password
;
5225 setfontsize fstate.fontsize
;
5231 | Glut.BadEnum
"key in special_of_int" ->
5232 showtext '
!'
" LablGlut bug: special key not recognized";