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";
1451 let n = Scanf.sscanf args
"%u" (fun n -> n) in
1452 state.pagecount
<- n;
1453 state.invalidated
<- state.invalidated
- 1;
1454 begin match state.currently
with
1456 state.currently
<- Idle
;
1457 state.outlines
<- Array.of_list
(List.rev
l)
1460 if state.invalidated
= 0
1462 if conf.maxwait
= None
1463 then G.postRedisplay "continue";
1466 Glut.setWindowTitle args
1473 then showtext ' ' args
1476 let progress, text = Scanf.sscanf args
"%f %n"
1478 f, String.sub args pos
(String.length args
- pos
)
1482 state.progress <- progress;
1483 G.postRedisplay "progress"
1486 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1487 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1488 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1489 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1491 let y = (getpagey pageno) + truncate y0
in
1494 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)]
1497 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1498 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1499 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1500 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1503 (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) :: state.rects1
1506 let pageopaque, t
= Scanf.sscanf args
"%s %f" (fun p t
-> p
, t
) in
1507 begin match state.currently
with
1508 | Loading
(l, gen
) ->
1509 vlog "page %d took %f sec" l.pageno t
;
1510 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1511 begin match state.throttle
with
1513 let preloadedpages =
1515 then preloadlayout state.layout
1520 Set.Make
(struct type t
= int let compare = (-) end) in
1522 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1523 IntSet.empty
preloadedpages
1526 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1527 if not
(IntSet.mem
pageno set)
1529 wcmd "freepage" [`
s opaque
];
1535 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1538 state.currently
<- Idle
;
1541 tilepage l.pageno pageopaque state.layout;
1543 load preloadedpages;
1544 if pagevisible state.layout l.pageno
1545 && layoutready state.layout
1546 then G.postRedisplay "page";
1549 | Some
(layout, _, _) ->
1550 state.currently
<- Idle
;
1551 tilepage l.pageno pageopaque layout;
1556 dolog "Inconsistent loading state";
1557 logcurrently state.currently
;
1562 let (x, y, opaque
, size
, t
) =
1563 Scanf.sscanf args
"%u %u %s %u %f"
1564 (fun x y p size t
-> (x, y, p
, size
, t
))
1566 begin match state.currently
with
1567 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1568 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1570 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1572 wcmd "freetile" [`
s opaque
];
1573 state.currently
<- Idle
;
1577 puttileopaque l col row gen cs angle opaque size t
;
1578 state.memused
<- state.memused
+ size
;
1579 state.uioh#infochanged Memused
;
1581 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1582 opaque
, size
) state.tilelru
;
1584 state.currently
<- Idle
;
1586 && conf.colorspace
= cs
1587 && conf.angle
= angle
1588 && tilevisible state.layout l.pageno x y
1589 then conttiling l.pageno pageopaque;
1591 begin match state.throttle
with
1593 preload state.layout;
1595 && conf.colorspace
= cs
1596 && conf.angle
= angle
1597 && tilevisible state.layout l.pageno x y
1598 then G.postRedisplay "tile nothrottle";
1600 | Some
(layout, y, _) ->
1601 let ready = layoutready layout in
1605 state.layout <- layout;
1606 state.throttle
<- None
;
1607 G.postRedisplay "throttle";
1614 dolog "Inconsistent tiling state";
1615 logcurrently state.currently
;
1621 Scanf.sscanf args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1623 state.uioh#infochanged Pdim
;
1624 state.pdims
<- pdim :: state.pdims
1627 let (l, n, t
, h, pos
) =
1628 Scanf.sscanf args
"%u %u %d %u %n" (fun l n t
h pos
-> l, n, t
, h, pos
)
1630 let s = String.sub args pos
(String.length args
- pos
) in
1631 let outline = (s, l, (n, float t
/. float h)) in
1632 begin match state.currently
with
1633 | Outlining outlines
->
1634 state.currently
<- Outlining
(outline :: outlines
)
1636 state.currently
<- Outlining
[outline]
1638 dolog "invalid outlining state";
1639 logcurrently currently
1643 state.docinfo
<- (1, args
) :: state.docinfo
1646 state.uioh#infochanged Docinfo
;
1647 state.docinfo
<- List.rev
state.docinfo
1650 dolog "unknown cmd `%S'" cmds
1654 if state.deadline
== nan
then state.deadline
<- now ();
1655 let rec loop delay
=
1658 then max
0.0 (state.deadline
-. now ())
1661 let r, _, _ = Unix.select
[state.csock
] [] [] timeout in
1664 begin match state.autoscroll
with
1665 | Some step
when step
!= 0 ->
1666 let y = state.y + step
in
1670 else if y >= state.maxy then 0 else y
1673 if state.mode
= View
1674 then state.text <- "";
1675 state.deadline
<- state.deadline
+. 0.005;
1678 state.deadline
<- state.deadline
+. delay
;
1682 let cmd = readcmd state.csock
in
1691 let action = function
1692 | HCprev
-> cbget cb ~
-1
1693 | HCnext
-> cbget cb
1
1694 | HCfirst
-> cbget cb ~
-(cb
.rc)
1695 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1696 and cancel
() = cb
.rc <- rc
1700 let search pattern forward
=
1701 if String.length pattern
> 0
1704 match state.layout with
1707 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1710 let b = makecmd "search"
1711 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
1713 Buffer.add_char
b '
,'
;
1714 Buffer.add_string
b pattern
;
1715 Buffer.add_char
b '
\000'
;
1718 writecmd state.csock
cmd;
1721 let intentry text key =
1722 let c = Char.unsafe_chr
key in
1725 let text = addchar text c in
1729 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1733 let textentry text key =
1734 let c = Char.unsafe_chr
key in
1736 | _ when key >= 32 && key < 127 ->
1737 let text = addchar text c in
1741 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
1745 let reqlayout angle proportional
=
1746 match state.throttle
with
1748 if state.invalidated
= 0 then state.anchor <- getanchor ();
1749 conf.angle
<- angle
mod 360;
1750 conf.proportional
<- proportional
;
1752 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
1756 let settrim trimmargins trimfuzz
=
1757 if state.invalidated
= 0 then state.anchor <- getanchor ();
1758 conf.trimmargins
<- trimmargins
;
1759 conf.trimfuzz
<- trimfuzz
;
1760 let x0, y0
, x1
, y1
= trimfuzz
in
1763 `
b conf.trimmargins
;
1769 Hashtbl.iter
(fun _ opaque
->
1770 wcmd "freepage" [`
s opaque
];
1772 Hashtbl.clear
state.pagemap
;
1776 match state.throttle
with
1778 let zoom = max
0.01 zoom in
1779 if zoom <> conf.zoom
1781 state.prevzoom
<- conf.zoom;
1784 then (state.x <- 0; 0.0)
1785 else float state.x /. float state.w
1788 reshape conf.winw
conf.winh
;
1791 let x = relx *. float state.w in
1792 state.x <- truncate
x;
1794 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
1800 let enterbirdseye () =
1801 let zoom = float conf.thumbw
/. float conf.winw
in
1802 let birdseyepageno =
1803 let cy = conf.winh
/ 2 in
1807 let rec fold best
= function
1810 let d = cy - (l.pagedispy
+ l.pagevh/2)
1811 and dbest
= cy - (best
.pagedispy
+ best
.pagevh/2) in
1812 if abs
d < abs dbest
1819 state.mode
<- Birdseye
(
1820 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
1823 conf.presentation <- false;
1824 conf.interpagespace <- 10;
1825 conf.hlinks
<- false;
1827 state.mstate
<- Mnone
;
1828 conf.maxwait
<- None
;
1829 Glut.setCursor
Glut.CURSOR_INHERIT
;
1832 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1837 reshape conf.winw
conf.winh
;
1840 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
1842 conf.zoom <- c.zoom;
1843 conf.presentation <- c.presentation;
1844 conf.interpagespace <- c.interpagespace;
1845 conf.maxwait
<- c.maxwait
;
1846 conf.hlinks
<- c.hlinks
;
1850 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1853 reshape conf.winw
conf.winh
;
1854 state.anchor <- if goback
then anchor else (pageno, 0.0);
1857 let togglebirdseye () =
1858 match state.mode
with
1859 | Birdseye vals
-> leavebirdseye vals
true
1860 | View
-> enterbirdseye ()
1864 let upbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
1865 let pageno = max
0 (pageno - 1) in
1866 let rec loop = function
1867 | [] -> gotopage1 pageno 0
1868 | l :: _ when l.pageno = pageno ->
1869 if l.pagedispy
>= 0 && l.pagey = 0
1870 then G.postRedisplay "upbirdseye"
1871 else gotopage1 pageno 0
1872 | _ :: rest
-> loop rest
1875 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
1878 let downbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
1879 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
1880 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
1881 let rec loop = function
1883 let y, h = getpageyh pageno in
1884 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
1886 | l :: _ when l.pageno = pageno ->
1887 if l.pagevh != l.pageh
1888 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
1889 else G.postRedisplay "downbirdseye"
1890 | _ :: rest
-> loop rest
1895 let optentry mode
_ key =
1896 let btos b = if b then "on" else "off" in
1897 let c = Char.unsafe_chr
key in
1901 try conf.scrollstep
<- int_of_string
s with exc
->
1902 state.text <- Printf.sprintf
"bad integer `%s': %s"
1903 s (Printexc.to_string exc
)
1905 TEswitch
("scroll step: ", "", None
, intentry, ondone)
1910 conf.autoscrollstep
<- int_of_string
s;
1911 if state.autoscroll
<> None
1912 then state.autoscroll
<- Some
conf.autoscrollstep
1914 state.text <- Printf.sprintf
"bad integer `%s': %s"
1915 s (Printexc.to_string exc
)
1917 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
1922 let zoom = float (int_of_string
s) /. 100.0 in
1925 state.text <- Printf.sprintf
"bad integer `%s': %s"
1926 s (Printexc.to_string exc
)
1928 TEswitch
("zoom: ", "", None
, intentry, ondone)
1933 conf.thumbw
<- bound (int_of_string
s) 2 4096;
1935 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
1936 begin match mode
with
1938 leavebirdseye beye
false;
1943 state.text <- Printf.sprintf
"bad integer `%s': %s"
1944 s (Printexc.to_string exc
)
1946 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
1951 Some
(int_of_string
s)
1953 state.text <- Printf.sprintf
"bad integer `%s': %s"
1954 s (Printexc.to_string exc
);
1957 | Some angle
-> reqlayout angle
conf.proportional
1960 TEswitch
("rotation: ", "", None
, intentry, ondone)
1963 conf.icase
<- not
conf.icase
;
1964 TEdone
("case insensitive search " ^
(btos conf.icase
))
1967 conf.preload <- not
conf.preload;
1969 TEdone
("preload " ^
(btos conf.preload))
1972 conf.verbose
<- not
conf.verbose
;
1973 TEdone
("verbose " ^
(btos conf.verbose
))
1976 conf.debug
<- not
conf.debug
;
1977 TEdone
("debug " ^
(btos conf.debug
))
1980 conf.maxhfit
<- not
conf.maxhfit
;
1982 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
1983 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
1986 conf.crophack
<- not
conf.crophack
;
1987 TEdone
("crophack " ^
btos conf.crophack
)
1991 match conf.maxwait
with
1993 conf.maxwait
<- Some infinity
;
1994 "always wait for page to complete"
1996 conf.maxwait
<- None
;
1997 "show placeholder if page is not ready"
2002 conf.underinfo
<- not
conf.underinfo
;
2003 TEdone
("underinfo " ^
btos conf.underinfo
)
2006 conf.savebmarks
<- not
conf.savebmarks
;
2007 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2013 match state.layout with
2018 conf.interpagespace <- int_of_string
s;
2019 state.maxy <- calcheight ();
2020 let y = getpagey pageno in
2023 state.text <- Printf.sprintf
"bad integer `%s': %s"
2024 s (Printexc.to_string exc
)
2026 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2029 reqlayout conf.angle
(not
conf.proportional
);
2030 TEdone
("proportional display " ^
btos conf.proportional
)
2033 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2034 TEdone
("trim margins " ^
btos conf.trimmargins
)
2037 conf.invert
<- not
conf.invert
;
2038 TEdone
("invert colors " ^
btos conf.invert
)
2041 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2045 class type lvsource
= object
2046 method getitemcount
: int
2047 method getitem
: int -> (string * int)
2048 method hasaction
: int -> bool
2057 method getactive
: int
2058 method getfirst
: int
2059 method getqsearch
: string
2060 method setqsearch
: string -> unit
2064 class virtual lvsourcebase
= object
2065 val mutable m_active
= 0
2066 val mutable m_first
= 0
2067 val mutable m_qsearch
= ""
2068 val mutable m_pan
= 0
2069 method getactive
= m_active
2070 method getfirst
= m_first
2071 method getqsearch
= m_qsearch
2072 method getpan
= m_pan
2073 method setqsearch
s = m_qsearch
<- s
2076 let textentryspecial key = function
2077 | ((c, _, (Some
(action, _) as onhist), onkey
, ondone), mode
) ->
2080 | Glut.KEY_UP
-> action HCprev
2081 | Glut.KEY_DOWN
-> action HCnext
2082 | Glut.KEY_HOME
-> action HCfirst
2083 | Glut.KEY_END
-> action HClast
2086 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2087 G.postRedisplay "special textentry";
2091 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2093 state.mode
<- Textentry
(te
, onleave
);
2096 G.postRedisplay "textentrykeyboard enttext";
2098 match Char.unsafe_chr
key with
2099 | '
\008'
-> (* backspace *)
2100 let len = String.length
text in
2104 G.postRedisplay "textentrykeyboard after cancel";
2107 let s = String.sub
text 0 (len - 1) in
2108 enttext (c, s, opthist
, onkey
, ondone)
2114 G.postRedisplay "textentrykeyboard after confirm"
2116 | '
\007'
(* ctrl-g *)
2117 | '
\027'
-> (* escape *)
2118 if String.length
text = 0
2120 begin match opthist
with
2122 | Some
(_, onhistcancel
) -> onhistcancel
()
2126 G.postRedisplay "textentrykeyboard after cancel2"
2129 enttext (c, "", opthist
, onkey
, ondone)
2132 | '
\127'
-> () (* delete *)
2135 begin match onkey
text key with
2139 G.postRedisplay "textentrykeyboard after confirm2";
2142 enttext (c, text, opthist
, onkey
, ondone);
2147 G.postRedisplay "textentrykeyboard after cancel3"
2150 state.mode
<- Textentry
(te
, onleave
);
2151 G.postRedisplay "textentrykeyboard switch";
2155 let firstof first active
=
2156 if first
> active
|| abs
(first
- active
) > fstate.maxrows
- 1
2157 then max
0 (active
- (fstate.maxrows
/2))
2161 let calcfirst first active
=
2164 let rows = active
- first
in
2165 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2169 let coe s = (s :> uioh
);;
2171 class listview ~
(source
:lvsource
) ~trusted
=
2173 val m_pan
= source#getpan
2174 val m_first
= source#getfirst
2175 val m_active
= source#getactive
2176 val m_qsearch
= source#getqsearch
2177 val m_prev_uioh
= state.uioh
2179 method private elemunder
y =
2180 let n = y / (fstate.fontsize
+1) in
2181 if m_first
+ n < source#getitemcount
2183 if source#hasaction
(m_first
+ n)
2184 then Some
(m_first
+ n)
2191 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2192 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2193 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2194 GlDraw.color
(1., 1., 1.);
2195 Gl.enable `texture_2d
;
2196 let fs = fstate.fontsize
in
2198 let ww = fstate.wwidth
in
2199 let tabw = 30.0*.ww in
2201 if (row - m_first
) * nfs > conf.winh
2204 if row >= 0 && row < source#getitemcount
2206 let (s, level
) = source#getitem
row in
2207 let y = (row - m_first
) * nfs in
2208 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2211 Gl.disable `texture_2d
;
2212 GlDraw.polygon_mode `both `line
;
2213 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2214 GlDraw.rect (1., float (y + 1))
2215 (float (conf.winw
- 1), float (y + fs + 3));
2216 GlDraw.polygon_mode `both `fill
;
2217 GlDraw.color
(1., 1., 1.);
2218 Gl.enable `texture_2d
;
2221 let drawtabularstring s =
2222 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2225 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2228 let len = String.length
s - tabpos - 1 in
2229 let s1 = String.sub
s 0 tabpos
2230 and s2
= String.sub
s (tabpos + 1) len in
2231 let nx = drawstr x s1 in
2233 let x = x +. (max
tabw sw) in
2240 let _ = drawtabularstring s in
2247 Gl.disable `texture_2d
;
2249 method updownlevel incr
=
2250 let len = source#getitemcount
in
2251 let _, curlevel
= source#getitem m_active
in
2253 if i
= len then i
-1 else if i
= -1 then 0 else
2254 let _, l = source#getitem i
in
2255 if l != curlevel
then i
else flow (i
+incr
)
2257 let active = flow m_active
in
2258 let first = calcfirst m_first
active in
2259 G.postRedisplay "special outline updownlevel";
2260 {< m_active
= active; m_first
= first >}
2262 method private key1
key =
2263 let set active first qsearch
=
2264 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2266 let search active pattern incr
=
2269 if n >= 0 && n < source#getitemcount
2271 let s, _ = source#getitem
n in
2273 (try ignore
(Str.search_forward
re s 0); true
2274 with Not_found
-> false)
2276 else loop (n + incr
)
2283 let re = Str.regexp_case_fold pattern
in
2290 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2291 let incr = if key = 18 then -1 else 1 in
2293 match search (m_active
+ incr) m_qsearch
incr with
2295 state.text <- m_qsearch ^
" [not found]";
2298 state.text <- m_qsearch
;
2299 active, firstof m_first
active
2301 G.postRedisplay "listview ctrl-r/s";
2302 set active first m_qsearch
;
2304 | 8 -> (* backspace *)
2305 let len = String.length m_qsearch
in
2312 G.postRedisplay "listview empty qsearch";
2313 set m_active m_first
"";
2316 let qsearch = String.sub m_qsearch
0 (len - 1) in
2318 match search m_active
qsearch ~
-1 with
2320 state.text <- qsearch ^
" [not found]";
2323 state.text <- qsearch;
2324 active, firstof m_first
active
2326 G.postRedisplay "listview backspace qsearch";
2327 set active first qsearch
2330 | _ when key >= 32 && key < 127 ->
2331 let pattern = addchar m_qsearch
(Char.chr
key) in
2333 match search m_active
pattern 1 with
2335 state.text <- pattern ^
" [not found]";
2338 state.text <- pattern;
2339 active, firstof m_first
active
2341 G.postRedisplay "listview qsearch add";
2342 set active first pattern;
2344 | 27 -> (* escape *)
2346 if String.length m_qsearch
= 0
2348 G.postRedisplay "list view escape";
2351 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2353 | None
-> m_prev_uioh
2358 G.postRedisplay "list view kill qsearch";
2359 source#setqsearch
"";
2360 coe {< m_qsearch
= "" >}
2365 let self = {< m_qsearch
= "" >} in
2366 source#setqsearch
"";
2368 G.postRedisplay "listview enter";
2369 if m_active
>= 0 && m_active
< source#getitemcount
2371 source#exit
(coe self) false m_active m_first m_pan
"";
2374 source#exit
(coe self) true m_active m_first m_pan
"";
2377 begin match opt with
2378 | None
-> m_prev_uioh
2382 | 127 -> (* delete *)
2385 | _ -> dolog "unknown key %d" key; coe self
2387 method private special1
key =
2388 let itemcount = source#getitemcount
in
2389 let find start
incr =
2391 if i
= -1 || i
= itemcount
2394 if source#hasaction i
2396 else find (i
+ incr)
2401 let set active first =
2402 let first = bound first 0 (itemcount - fstate.maxrows
) in
2404 coe {< m_active
= active; m_first
= first >}
2407 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2409 let incr1 = if incr > 0 then 1 else -1 in
2410 if isvisible m_first m_active
2413 let next = m_active
+ incr in
2415 if next < 0 || next >= itemcount
2417 else find next incr1
2419 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2425 let first = m_first
+ incr in
2426 let first = bound first 0 (itemcount - 1) in
2428 let next = m_active
+ incr in
2429 let next = bound next 0 (itemcount - 1) in
2432 let active = if next = -1 then m_active
else next in
2435 let first = min
next m_first
in
2438 let first = m_first
+ incr in
2439 let first = bound first 0 (itemcount - 1) in
2441 let next = m_active
+ incr in
2442 let next = bound next 0 (itemcount - 1) in
2443 let next = find next incr1 in
2444 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2450 G.postRedisplay "listview navigate";
2453 begin match key with
2454 | Glut.KEY_UP
-> navigate ~
-1
2455 | Glut.KEY_DOWN
-> navigate 1
2456 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2457 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2461 G.postRedisplay "listview right";
2462 coe {< m_pan
= m_pan
- 1 >}
2466 G.postRedisplay "listview left";
2467 coe {< m_pan
= m_pan
+ 1 >}
2470 let active = find 0 1 in
2471 G.postRedisplay "listview home";
2475 let first = max
0 (itemcount - fstate.maxrows
) in
2476 let active = find (itemcount - 1) ~
-1 in
2477 G.postRedisplay "listview end";
2484 match state.mode
with
2485 | Textentry te
-> textentrykeyboard key te
; coe self
2486 | _ -> self#key1
key
2488 method special
key =
2489 match state.mode
with
2490 | Textentry te
-> textentryspecial key te
; coe self
2491 | _ -> self#special1
key
2493 method button button bstate
_ y =
2496 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2497 begin match self#elemunder
y with
2499 G.postRedisplay "listview click";
2501 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
2505 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2506 let len = source#getitemcount
in
2508 if m_first
+ fstate.maxrows
>= len
2512 let first = m_first
+ (if n == 3 then -1 else 1) in
2513 bound first 0 (len - 1)
2515 G.postRedisplay "listview wheel";
2516 Some
(coe {< m_first
= first >})
2521 | None
-> m_prev_uioh
2524 method motion
_ _ = coe self
2526 method pmotion
_ y =
2528 match self#elemunder
y with
2529 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
2530 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
2534 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
2539 method infochanged
_ = ()
2542 class outlinelistview ~source
=
2544 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
2548 | 14 -> (* ctrl-n *)
2549 source#narrow m_qsearch
;
2550 G.postRedisplay "outline ctrl-n";
2551 coe {< m_first
= 0; m_active
= 0 >}
2553 | 21 -> (* ctrl-u *)
2555 G.postRedisplay "outline ctrl-u";
2556 coe {< m_first
= 0; m_active
= 0 >}
2558 | 12 -> (* ctrl-l *)
2559 let first = m_active
- (fstate.maxrows
/ 2) in
2560 G.postRedisplay "outline ctrl-l";
2561 coe {< m_first
= first >}
2563 | 127 -> (* delete *)
2564 source#remove m_active
;
2565 G.postRedisplay "outline delete";
2566 let active = max
0 (m_active
-1) in
2567 coe {< m_first
= firstof m_first
active;
2568 m_active
= active >}
2570 | key -> super#
key key
2572 method special
key =
2573 let calcfirst first active =
2576 let rows = active - first in
2577 if rows > fstate.maxrows
then active - fstate.maxrows
else first
2581 let active = m_active
+ incr in
2582 let active = bound active 0 (source#getitemcount
- 1) in
2583 let first = calcfirst m_first
active in
2584 G.postRedisplay "special outline navigate";
2585 coe {< m_active
= active; m_first
= first >}
2588 | Glut.KEY_UP
-> navigate ~
-1
2589 | Glut.KEY_DOWN
-> navigate 1
2590 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2591 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2595 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2597 G.postRedisplay "special outline right";
2598 {< m_pan
= m_pan
+ 1 >}
2600 else self#updownlevel
1
2606 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2608 G.postRedisplay "special outline left";
2609 {< m_pan
= m_pan
- 1 >}
2611 else self#updownlevel ~
-1
2616 G.postRedisplay "special outline home";
2617 coe {< m_first
= 0; m_active
= 0 >}
2620 let active = source#getitemcount
- 1 in
2621 let first = max
0 (active - fstate.maxrows
) in
2622 G.postRedisplay "special outline end";
2623 coe {< m_active
= active; m_first
= first >}
2625 | _ -> super#special
key
2628 let outlinesource usebookmarks
=
2631 inherit lvsourcebase
2632 val mutable m_items
= empty
2633 val mutable m_orig_items
= empty
2634 val mutable m_prev_items
= empty
2635 val mutable m_narrow_pattern
= ""
2636 val mutable m_hadremovals
= false
2638 method getitemcount
=
2639 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
2642 if n == Array.length m_items
&& m_hadremovals
2644 ("[Confirm removal]", 0)
2646 let s, n, _ = m_items
.(n) in
2649 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
2650 ignore
(uioh
, first, pan
, qsearch);
2651 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
2653 if String.length m_narrow_pattern
= 0
2659 if not
confrimremoval
2661 let _, _, anchor = m_items
.(active) in
2666 state.bookmarks
<- Array.to_list m_items
;
2667 m_orig_items
<- m_items
;
2670 else m_items
<- items;
2673 method hasaction
_ = true
2676 if Array.length m_items
!= Array.length m_orig_items
2677 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
2680 method narrow
pattern =
2681 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
2685 let rec loop accu n =
2688 m_narrow_pattern
<- pattern;
2689 m_items
<- Array.of_list
accu
2692 let (s, _, _) as o = m_items
.(n) in
2694 if (try ignore
(Str.search_forward
re s 0); true
2695 with Not_found
-> false)
2701 loop [] (Array.length m_items
- 1)
2706 then Array.of_list
state.bookmarks
2709 m_items
<- m_orig_items
2714 if m
>= 0 && m
< Array.length m_items
2716 m_hadremovals
<- true;
2717 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
2718 let n = if n >= m
then n+1 else n in
2723 method reset
pageno items =
2724 m_hadremovals
<- false;
2725 if m_orig_items
== empty || m_prev_items
!= items
2727 m_orig_items
<- items;
2728 if String.length m_narrow_pattern
= 0
2729 then m_items
<- items;
2731 m_prev_items
<- items;
2733 let rec loop n best bestd
=
2734 if n = Array.length m_items
2737 let (_, _, (outlinepageno
, _)) = m_items
.(n) in
2738 let d = abs
(outlinepageno
- pageno) in
2741 else loop (n+1) best bestd
2746 m_first
<- firstof m_first
active
2750 let enterselector usebookmarks
=
2751 let source = outlinesource usebookmarks
in
2755 then Array.of_list
state.bookmarks
2758 if Array.length
outlines = 0
2760 showtext ' ' errmsg
;
2763 state.text <- source#greetmsg
;
2764 Glut.setCursor
Glut.CURSOR_INHERIT
;
2766 match state.layout with
2768 | {pageno=pageno} :: _ -> pageno
2770 source#reset
pageno outlines;
2771 state.uioh
<- coe (new outlinelistview ~
source);
2772 G.postRedisplay "enter selector";
2776 let enteroutlinemode =
2777 let f = enterselector false in
2778 fun ()-> f "Document has no outline";
2781 let enterbookmarkmode =
2782 let f = enterselector true in
2783 fun () -> f "Document has no bookmarks (yet)";
2786 let color_of_string s =
2787 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
2788 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
2792 let color_to_string (r, g
, b) =
2793 let r = truncate
(r *. 256.0)
2794 and g
= truncate
(g
*. 256.0)
2795 and b = truncate
(b *. 256.0) in
2796 Printf.sprintf
"%d/%d/%d" r g
b
2799 let irect_of_string s =
2800 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0,y0
,x1
,y1
))
2803 let irect_to_string (x0,y0
,x1
,y1
) =
2804 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
2807 let makecheckers () =
2808 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
2810 converted by Issac Trotts. July 25, 2002 *)
2811 let image_height = 64
2812 and image_width
= 64 in
2816 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
2818 for i
= 0 to image_width
- 1 do
2819 for j
= 0 to image_height - 1 do
2820 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
2821 (if (i
land 8 ) lxor (j
land 8) = 0
2822 then [|255;255;255|] else [|200;200;200|])
2827 let image = make_image () in
2828 let id = GlTex.gen_texture
() in
2829 GlTex.bind_texture `texture_2d
id;
2830 GlPix.store
(`unpack_alignment
1);
2831 GlTex.image2d
image;
2832 List.iter
(GlTex.parameter ~target
:`texture_2d
)
2835 `mag_filter `nearest
;
2836 `min_filter `nearest
];
2840 let setcheckers enabled
=
2841 match state.texid
with
2843 if enabled
then state.texid
<- Some
(makecheckers ())
2848 GlTex.delete_texture texid
;
2849 state.texid
<- None
;
2853 let int_of_string_with_suffix s =
2854 let l = String.length
s in
2858 let suffix = Char.lowercase
s.[l-1] in
2860 | 'k'
-> String.sub
s 0 (l-1), 10
2861 | 'm'
-> String.sub
s 0 (l-1), 20
2862 | 'g'
-> String.sub
s 0 (l-1), 30
2866 let n = int_of_string
s1 in
2867 let m = n lsl shift
in
2869 then raise
(Failure
"value too large")
2873 let string_with_suffix_of_int n =
2881 if n land ((1 lsl 20) - 1) = 0
2884 if n land ((1 lsl 10) - 1) = 0
2891 let h = n mod 1000 in
2894 then string_of_int
h ^
s
2896 let s = Printf.sprintf
"_%03d%s" h s in
2903 let describe_location () =
2905 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
2907 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
2908 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
2912 else (100. *. (float state.y /. float maxy))
2916 Printf.sprintf
"page %d of %d [%.2f%%]"
2917 (fn+1) state.pagecount
percent
2920 "pages %d-%d of %d [%.2f%%]"
2921 (fn+1) (ln
+1) state.pagecount
percent
2925 let btos b = if b then "\xe2\x88\x9a" else "" in
2926 let showextended = ref false in
2927 let leave mode
= function
2928 | Confirm
-> state.mode
<- mode
2929 | Cancel
-> state.mode
<- mode
in
2932 val mutable m_first_time
= true
2933 val mutable m_l
= []
2934 val mutable m_a
= [||]
2935 val mutable m_prev_uioh
= nouioh
2936 val mutable m_prev_mode
= View
2938 inherit lvsourcebase
2940 method reset prev_mode prev_uioh
=
2941 m_a
<- Array.of_list
(List.rev m_l
);
2943 m_prev_mode
<- prev_mode
;
2944 m_prev_uioh
<- prev_uioh
;
2948 if n >= Array.length m_a
2952 | _, _, _, Action
_ -> m_active
<- n
2956 m_first_time
<- false;
2959 method int name get
set =
2961 (name
, `
int get
, 1, Action
(
2964 try set (int_of_string
s)
2966 state.text <- Printf.sprintf
"bad integer `%s': %s"
2967 s (Printexc.to_string exn
)
2970 let te = name ^
": ", "", None
, intentry, ondone in
2971 state.mode
<- Textentry
(te, leave m_prev_mode
);
2975 method int_with_suffix name get
set =
2977 (name
, `intws get
, 1, Action
(
2980 try set (int_of_string_with_suffix s)
2982 state.text <- Printf.sprintf
"bad integer `%s': %s"
2983 s (Printexc.to_string exn
)
2987 name ^
": ", "", None
, intentry_with_suffix, ondone
2989 state.mode
<- Textentry
(te, leave m_prev_mode
);
2993 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
2995 (name
, `
bool (btos, get
), offset
, Action
(
3002 method color name get
set =
3004 (name
, `color get
, 1, Action
(
3006 let invalid = (nan
, nan
, nan
) in
3009 try color_of_string s
3011 state.text <- Printf.sprintf
"bad color `%s': %s"
3012 s (Printexc.to_string exn
);
3018 let te = name ^
": ", "", None
, textentry, ondone in
3019 state.text <- color_to_string (get
());
3020 state.mode
<- Textentry
(te, leave m_prev_mode
);
3024 method string name get
set =
3026 (name
, `
string get
, 1, Action
(
3028 let ondone s = set s in
3029 let te = name ^
": ", "", None
, textentry, ondone in
3030 state.mode
<- Textentry
(te, leave m_prev_mode
);
3034 method colorspace name get
set =
3036 (name
, `
string get
, 1, Action
(
3039 let vals = [| "rgb"; "bgr"; "gray" |] in
3041 inherit lvsourcebase
3044 m_active
<- int_of_colorspace conf.colorspace
;
3047 method getitemcount
= Array.length
vals
3048 method getitem
n = (vals.(n), 0)
3049 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3050 ignore
(uioh
, first, pan
, qsearch);
3051 if not cancel
then set active;
3053 method hasaction
_ = true
3057 coe (new listview ~
source ~trusted
:true)
3060 method caption
s offset
=
3061 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3063 method caption2
s f offset
=
3064 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3066 method getitemcount
= Array.length m_a
3069 let tostr = function
3070 | `
int f -> string_of_int
(f ())
3071 | `intws
f -> string_with_suffix_of_int (f ())
3073 | `color
f -> color_to_string (f ())
3074 | `
bool (btos, f) -> btos (f ())
3077 let name, t
, offset
, _ = m_a
.(n) in
3078 ((let s = tostr t
in
3079 if String.length
s > 0
3080 then Printf.sprintf
"%s\t%s" name s
3084 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3088 m_qsearch
<- qsearch;
3090 match m_a
.(active) with
3091 | _, _, _, Action
f -> f uioh
3103 method hasaction
n =
3105 | _, _, _, Action
_ -> true
3109 let rec fillsrc prevmode prevuioh
=
3110 let sep () = src#caption
"" 0 in
3111 let colorp name get
set =
3113 (fun () -> color_to_string (get
()))
3116 let c = color_of_string v in
3119 state.text <- Printf.sprintf
"bad color `%s': %s"
3120 v (Printexc.to_string exn
);
3123 let oldmode = state.mode
in
3124 let birdseye = isbirdseye state.mode
in
3126 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3128 src#
bool "presentation mode"
3129 (fun () -> conf.presentation)
3131 conf.presentation <- v;
3132 state.anchor <- getanchor ();
3135 src#
bool "ignore case in searches"
3136 (fun () -> conf.icase
)
3137 (fun v -> conf.icase
<- v);
3140 (fun () -> conf.preload)
3141 (fun v -> conf.preload <- v);
3143 src#
bool "highlight links"
3144 (fun () -> conf.hlinks
)
3145 (fun v -> conf.hlinks
<- v);
3147 src#
bool "under info"
3148 (fun () -> conf.underinfo
)
3149 (fun v -> conf.underinfo
<- v);
3151 src#
bool "persistent bookmarks"
3152 (fun () -> conf.savebmarks
)
3153 (fun v -> conf.savebmarks
<- v);
3155 src#
bool "proportional display"
3156 (fun () -> conf.proportional
)
3157 (fun v -> reqlayout conf.angle
v);
3159 src#
bool "trim margins"
3160 (fun () -> conf.trimmargins
)
3161 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3163 src#
bool "persistent location"
3164 (fun () -> conf.jumpback
)
3165 (fun v -> conf.jumpback
<- v);
3168 src#
int "vertical margin"
3169 (fun () -> conf.interpagespace)
3171 conf.interpagespace <- n;
3173 match state.layout with
3178 state.maxy <- calcheight ();
3179 let y = getpagey pageno in
3184 (fun () -> conf.pagebias
)
3185 (fun v -> conf.pagebias
<- v);
3187 src#
int "scroll step"
3188 (fun () -> conf.scrollstep
)
3189 (fun n -> conf.scrollstep
<- n);
3191 src#
int "auto scroll step"
3193 match state.autoscroll
with
3195 | _ -> conf.autoscrollstep
)
3197 if state.autoscroll
<> None
3198 then state.autoscroll
<- Some
n;
3199 conf.autoscrollstep
<- n);
3202 (fun () -> truncate
(conf.zoom *. 100.))
3203 (fun v -> setzoom ((float v) /. 100.));
3206 (fun () -> conf.angle
)
3207 (fun v -> reqlayout v conf.proportional
);
3209 src#
int "scroll bar width"
3210 (fun () -> state.scrollw
)
3214 reshape conf.winw
conf.winh
;
3217 src#
int "scroll handle height"
3218 (fun () -> conf.scrollh
)
3219 (fun v -> conf.scrollh
<- v;);
3221 src#
int "thumbnail width"
3222 (fun () -> conf.thumbw
)
3224 conf.thumbw
<- min
4096 v;
3227 leavebirdseye beye
false;
3233 src#caption
"Presentation mode" 0;
3234 src#
bool "scrollbar visible"
3235 (fun () -> conf.scrollbarinpm
)
3237 if v != conf.scrollbarinpm
3239 conf.scrollbarinpm
<- v;
3240 if conf.presentation
3242 state.scrollw
<- if v then conf.scrollbw
else 0;
3243 reshape conf.winw
conf.winh
;
3249 src#caption
"Pixmap cache" 0;
3250 src#int_with_suffix
"size (advisory)"
3251 (fun () -> conf.memlimit
)
3252 (fun v -> conf.memlimit
<- v);
3255 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3256 (string_with_suffix_of_int state.memused
)
3257 (Hashtbl.length
state.tilemap
)) 1;
3260 src#caption
"Layout" 0;
3261 src#caption2
"Dimension"
3263 Printf.sprintf
"%dx%d (virtual %dx%d)"
3269 src#caption2
"Position" (fun () ->
3270 Printf.sprintf
"%dx%d" state.x state.y
3273 src#caption2
"Visible" (fun () -> describe_location ()) 1
3277 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3278 "Save these parameters as global defaults at exit"
3279 (fun () -> conf.bedefault
)
3280 (fun v -> conf.bedefault
<- v)
3284 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3285 src#
bool ~offset
:0 ~
btos "Extended parameters"
3286 (fun () -> !showextended)
3287 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3291 (fun () -> conf.checkers
)
3292 (fun v -> conf.checkers
<- v; setcheckers v);
3294 (fun () -> conf.verbose
)
3295 (fun v -> conf.verbose
<- v);
3296 src#
bool "invert colors"
3297 (fun () -> conf.invert
)
3298 (fun v -> conf.invert
<- v);
3300 (fun () -> conf.maxhfit
)
3301 (fun v -> conf.maxhfit
<- v);
3302 src#
string "uri launcher"
3303 (fun () -> conf.urilauncher
)
3304 (fun v -> conf.urilauncher
<- v);
3305 src#
string "tile size"
3306 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3309 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3310 conf.tileh
<- max
64 w;
3311 conf.tilew
<- max
64 h;
3314 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3315 v (Printexc.to_string exn
));
3316 src#
int "anti-aliasing level"
3317 (fun () -> conf.aalevel
)
3319 conf.aalevel
<- bound v 0 8;
3320 state.anchor <- getanchor ();
3321 opendoc state.path
state.password
;
3323 src#
int "ui font size"
3324 (fun () -> fstate.fontsize
)
3325 (fun v -> setfontsize (bound v 5 100));
3326 colorp "background color"
3327 (fun () -> conf.bgcolor
)
3328 (fun v -> conf.bgcolor
<- v);
3329 src#
bool "crop hack"
3330 (fun () -> conf.crophack
)
3331 (fun v -> conf.crophack
<- v);
3332 src#
string "trim fuzz"
3333 (fun () -> irect_to_string conf.trimfuzz
)
3336 conf.trimfuzz
<- irect_of_string v;
3338 then settrim true conf.trimfuzz
;
3340 state.text <- Printf.sprintf
"bad irect `%s': %s"
3341 v (Printexc.to_string exn
)
3343 src#
string "throttle"
3345 match conf.maxwait
with
3346 | None
-> "show place holder if page is not ready"
3349 then "wait for page to fully render"
3351 "wait " ^ string_of_float time
3352 ^
" seconds before showing placeholder"
3356 let f = float_of_string
v in
3358 then conf.maxwait
<- None
3359 else conf.maxwait
<- Some
f
3361 state.text <- Printf.sprintf
"bad time `%s': %s"
3362 v (Printexc.to_string exn
)
3364 src#colorspace
"color space"
3365 (fun () -> colorspace_to_string conf.colorspace
)
3367 conf.colorspace
<- colorspace_of_int v;
3374 src#caption
"Document" 0;
3375 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3379 src#caption
"Trimmed margins" 0;
3380 src#caption2
"Dimensions"
3381 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3384 src#reset prevmode prevuioh
;
3388 let prevmode = state.mode
3389 and prevuioh
= state.uioh in
3390 fillsrc prevmode prevuioh
;
3391 let source = (src :> lvsource
) in
3392 state.uioh <- coe (object (self)
3393 inherit listview ~
source ~trusted
:true as super
3394 val mutable m_prevmemused
= 0
3395 method infochanged
= function
3397 if m_prevmemused
!= state.memused
3399 m_prevmemused
<- state.memused
;
3400 G.postRedisplay "memusedchanged";
3402 | Pdim
-> G.postRedisplay "pdimchanged"
3403 | Docinfo
-> fillsrc prevmode prevuioh
3405 method special
key =
3406 if Glut.getModifiers
() land Glut.active_ctrl
= 0
3409 | Glut.KEY_LEFT
-> coe (self#updownlevel ~
-1)
3410 | Glut.KEY_RIGHT
-> coe (self#updownlevel
1)
3411 | _ -> super#special
key
3412 else super#special
key
3414 G.postRedisplay "info";
3420 inherit lvsourcebase
3421 method getitemcount
= Array.length
state.help
3423 let s, n, _ = state.help
.(n) in
3426 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3430 m_qsearch
<- qsearch;
3431 match state.help
.(active) with
3432 | _, _, Action
f -> Some
(f uioh)
3442 method hasaction
n =
3443 match state.help
.(n) with
3444 | _, _, Action
_ -> true
3451 state.uioh <- coe (new listview ~
source ~trusted
:true);
3452 G.postRedisplay "help";
3455 let quickbookmark ?title
() =
3456 match state.layout with
3462 let sec = Unix.gettimeofday
() in
3463 let tm = Unix.localtime
sec in
3464 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
3468 (tm.Unix.tm_year
+ 1900)
3471 | Some
title -> title
3474 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
3479 state.fullscreen
<- None
;
3480 Glut.reshapeWindow
w h;
3483 let viewkeyboard key =
3485 let mode = state.mode in
3486 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
3489 G.postRedisplay "view:enttext"
3491 let c = Char.chr
key in
3493 | '
\027'
| 'q'
-> (* escape *)
3494 begin match state.mstate
with
3496 state.mstate
<- Mnone
;
3497 Glut.setCursor
Glut.CURSOR_INHERIT
;
3498 G.postRedisplay "kill zoom rect";
3503 | '
\008'
-> (* backspace *)
3504 let y = getnav ~
-1 in
3505 gotoy_and_clear_text y
3513 G.postRedisplay "dehighlight";
3516 let ondone isforw
s =
3517 cbput state.hists
.pat
s;
3518 state.searchpattern
<- s;
3521 let s = String.create
1 in
3523 enttext (s, "", Some
(onhist state.hists
.pat
),
3524 textentry, ondone (c ='
/'
))
3526 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3527 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3528 setzoom (conf.zoom +. incr)
3533 try int_of_string
s with exc
->
3534 state.text <- Printf.sprintf
"bad integer `%s': %s"
3535 s (Printexc.to_string exc
);
3541 state.text <- "page bias is now " ^ string_of_int
n;
3544 enttext ("page bias: ", "", None
, intentry, ondone)
3546 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3547 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3548 setzoom (max
0.01 (conf.zoom -. decr))
3551 let ondone msg
= state.text <- msg
in
3553 "option [acfhilpstvAPRSZTI]: ", "", None
,
3554 optentry state.mode, ondone
3557 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3560 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3561 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
3565 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3571 try int_of_string
s with exc
->
3572 state.text <- Printf.sprintf
"bad integer `%s': %s"
3573 s (Printexc.to_string exc
);
3579 cbput state.hists
.pag
(string_of_int
n);
3580 gotoy_and_clear_text (getpagey (n + conf.pagebias
- 1))
3583 let pageentry text key =
3584 match Char.unsafe_chr
key with
3585 | 'g'
-> TEdone
text
3586 | _ -> intentry text key
3588 let text = "x" in text.[0] <- c;
3589 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
3592 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
3593 reshape conf.winw
conf.winh
;
3596 conf.hlinks
<- not
conf.hlinks
;
3597 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
3598 G.postRedisplay "toggle highlightlinks";
3601 begin match state.autoscroll
with
3603 conf.autoscrollstep
<- step
;
3604 state.autoscroll
<- None
3606 if conf.autoscrollstep
= 0
3607 then state.autoscroll
<- Some
1
3608 else state.autoscroll
<- Some
conf.autoscrollstep
3612 conf.presentation <- not
conf.presentation;
3613 if conf.presentation
3615 if not
conf.scrollbarinpm
3616 then state.scrollw
<- 0;
3619 state.scrollw
<- conf.scrollbw
;
3621 showtext ' '
("presentation mode " ^
3622 if conf.presentation then "on" else "off");
3623 state.anchor <- getanchor ();
3627 begin match state.fullscreen
with
3629 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
3632 state.fullscreen
<- None
;
3637 gotoy_and_clear_text 0
3640 gotopage1 (state.pagecount
- 1) 0
3643 search state.searchpattern
true
3646 search state.searchpattern
false
3649 begin match state.layout with
3652 gotoy_and_clear_text (getpagey l.pageno)
3656 begin match List.rev
state.layout with
3659 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
3660 gotoy_and_clear_text (getpagey pageno)
3663 | '
\127'
-> (* del *)
3664 begin match state.layout with
3667 let pageno = max
0 (l.pageno-1) in
3668 gotoy_and_clear_text (getpagey pageno)
3672 showtext ' '
(describe_location ());
3675 begin match state.layout with
3678 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
3683 enterbookmarkmode ()
3693 match state.layout with
3696 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
3700 enttext ("bookmark: ", "", None
, textentry, ondone)
3704 showtext ' '
"Quick bookmark added";
3707 begin match state.layout with
3709 let rect = getpdimrect
l.pagedimno
in
3713 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
3714 truncate
(1.2 *. (rect.(3) -. rect.(0))))
3716 (truncate
(rect.(1) -. rect.(0)),
3717 truncate
(rect.(3) -. rect.(0)))
3719 let w = truncate
((float w)*.conf.zoom)
3720 and h = truncate
((float h)*.conf.zoom) in
3723 state.anchor <- getanchor ();
3724 doreshape (w + state.scrollw
) (h + conf.interpagespace)
3726 G.postRedisplay "z";
3731 | '
\000'
-> (* ctrl-2 *)
3732 let maxw = getmaxw
() in
3734 then setzoom (maxw /. float conf.winw
)
3737 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
3741 bound (conf.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
3743 G.postRedisplay "brightness";
3746 begin match state.mode with
3747 | Birdseye beye
-> upbirdseye beye
3748 | _ -> gotoy (clamp (-conf.scrollstep
))
3752 begin match state.mode with
3753 | Birdseye beye
-> downbirdseye beye
3754 | _ -> gotoy (clamp conf.scrollstep
)
3758 state.anchor <- getanchor ();
3759 opendoc state.path
state.password
3761 | '
v'
when conf.debug
->
3764 match getopaque l.pageno with
3767 let x0, y0
, x1
, y1
= pagebbox opaque
in
3768 let a,b = float x0, float y0
in
3769 let c,d = float x1
, float y0
in
3770 let e,f = float x1
, float y1
in
3771 let h,j
= float x0, float y1
in
3772 let rect = (a,b,c,d,e,f,h,j
) in
3774 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
3776 G.postRedisplay "v";
3779 vlog "huh? %d %c" key (Char.chr
key);
3782 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
3784 | 27 -> (* escape *)
3785 leavebirdseye beye
true
3787 | 12 -> (* ctrl-l *)
3788 let y, h = getpageyh pageno in
3789 let top = (conf.winh
- h) / 2 in
3790 gotoy (max
0 (y - top))
3793 leavebirdseye beye
false
3799 let keyboard ~
key ~
x ~
y =
3802 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
3803 then wcmd "interrupt" []
3804 else state.uioh <- state.uioh#
key key
3807 let birdseyespecial key ((conf, leftx
, _, hooverpageno
, anchor) as beye
) =
3809 | Glut.KEY_UP
-> upbirdseye beye
3810 | Glut.KEY_DOWN
-> downbirdseye beye
3812 | Glut.KEY_PAGE_UP
->
3813 begin match state.layout with
3817 state.mode <- Birdseye
(
3818 conf, leftx
, l.pageno, hooverpageno
, anchor
3820 gotopage1 l.pageno 0;
3823 let layout = layout (state.y-conf.winh
) conf.winh
in
3825 | [] -> gotoy (clamp (-conf.winh
))
3827 state.mode <- Birdseye
(
3828 conf, leftx
, l.pageno, hooverpageno
, anchor
3830 gotopage1 l.pageno 0
3833 | [] -> gotoy (clamp (-conf.winh
))
3836 | Glut.KEY_PAGE_DOWN
->
3837 begin match List.rev
state.layout with
3839 let layout = layout (state.y + conf.winh
) conf.winh
in
3840 begin match layout with
3842 let incr = l.pageh
- l.pagevh in
3847 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
3849 G.postRedisplay "birdseye pagedown";
3851 else gotoy (clamp (incr + conf.interpagespace*2));
3855 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
3856 gotopage1 l.pageno 0;
3859 | [] -> gotoy (clamp conf.winh
)
3863 state.mode <- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
3867 let pageno = state.pagecount
- 1 in
3868 state.mode <- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3869 if not
(pagevisible state.layout pageno)
3872 match List.rev
state.pdims
with
3874 | (_, _, h, _) :: _ -> h
3876 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
3877 else G.postRedisplay "birdseye end";
3881 let setautoscrollspeed step goingdown
=
3882 let incr = max
1 ((abs step
) / 2) in
3883 let incr = if goingdown
then incr else -incr in
3884 let astep = step
+ incr in
3885 state.autoscroll
<- Some
astep;
3888 let special ~
key ~
x ~
y =
3891 state.uioh <- state.uioh#
special key
3896 match state.mode with
3897 | Textentry
_ -> scalecolor 0.4
3898 | View
-> scalecolor 1.0
3899 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
3900 if l.pageno = hooverpageno
3903 if l.pageno = pageno
3909 begin match getopaque l.pageno with
3911 if tileready l l.pagex l.pagey
3913 let x = l.pagedispx
- l.pagex
3914 and y = l.pagedispy
- l.pagey in
3915 postprocess opaque
conf.hlinks
x y;
3922 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3923 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
3924 let sh = float conf.winh
/. sh in
3925 let sh = max
sh (float conf.scrollh
) in
3930 else float y /. float maxy
3932 let position = (float conf.winh
-. sh) *. percent in
3935 if position +. sh > float conf.winh
3936 then float conf.winh
-. sh
3943 let winw = conf.winw - state.scrollw
- 1 in
3944 let fwinw = float winw in
3946 let sw = fwinw /. float state.w in
3947 let sw = fwinw *. sw in
3948 max
sw (float conf.scrollh
)
3951 let f = state.w+winw in
3952 let r = float (winw-x) /. float f in
3953 let p = fwinw *. r in
3957 if position +. sw > fwinw
3958 then fwinw -. position
3964 let scrollindicator () =
3965 GlDraw.color (0.64 , 0.64, 0.64);
3967 (float (conf.winw - state.scrollw
), 0.)
3968 (float conf.winw, float conf.winh
)
3971 (0., float (conf.winh
- state.hscrollh))
3972 (float (conf.winw - state.scrollw
- 1), float conf.winh
)
3974 GlDraw.color (0.0, 0.0, 0.0);
3976 let position, sh = scrollph state.y in
3978 (float (conf.winw - state.scrollw
), position)
3979 (float conf.winw, position +. sh)
3981 let position, sw = scrollpw state.x in
3983 (position, float (conf.winh
- state.hscrollh))
3984 (position +. sw, float conf.winh
)
3988 let pagetranslatepoint l x y =
3989 let dy = y - l.pagedispy
in
3990 let y = dy + l.pagey in
3991 let dx = x - l.pagedispx
in
3992 let x = dx + l.pagex in
3997 match state.mstate
with
3998 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4001 | Msel
((x0, y0
), (x1
, y1
)) ->
4002 let rec loop = function
4004 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
4005 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
4007 match getopaque l.pageno with
4009 let dx, dy = pagetranslatepoint l 0 0 in
4014 GlMat.mode `modelview
;
4016 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4017 seltext opaque
(x0, y0
, x1
, y1
);
4028 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4029 GlDraw.polygon_mode `both `fill
;
4030 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4032 (fun (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
4034 if l.pageno = pageno
4036 let dx = float (l.pagedispx
- l.pagex) in
4037 let dy = float (l.pagedispy
- l.pagey) in
4038 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4039 GlDraw.begins `quads
;
4041 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4042 GlDraw.vertex2
(x1
+.dx, y1
+.dy);
4043 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4044 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4055 GlClear.color (scalecolor2 conf.bgcolor
);
4056 GlClear.clear
[`
color];
4057 List.iter
drawpage state.layout;
4062 begin match state.mstate
with
4063 | Mzoomrect
((x0, y0
), (x1
, y1
)) ->
4065 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4066 GlDraw.polygon_mode `both `fill
;
4067 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4068 GlDraw.rect (float x0, float y0
)
4069 (float x1
, float y1
);
4074 Glut.swapBuffers
();
4078 let rec f = function
4080 begin match getopaque l.pageno with
4082 let x0 = l.pagedispx
in
4083 let x1 = x0 + l.pagevw in
4084 let y0 = l.pagedispy
in
4085 let y1 = y0 + l.pagevh in
4086 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4088 let px, py = pagetranslatepoint l x y in
4089 match whatsunder opaque
px py with
4101 let zoomrect x y x1 y1 =
4104 and y0 = min
y y1 in
4105 gotoy (state.y + y0);
4106 state.anchor <- getanchor ();
4107 let zoom = (float conf.winw *. conf.zoom) /. float (x1 - x0) in
4109 if state.w < conf.winw - state.scrollw
4110 then (conf.winw - state.scrollw
- state.w) / 2
4113 state.x <- (state.x + margin) - x0;
4115 Glut.setCursor
Glut.CURSOR_INHERIT
;
4116 state.mstate
<- Mnone
;
4120 let winw = conf.winw - state.scrollw
- 1 in
4121 let s = float x /. float winw in
4122 let destx = truncate
(float (state.w + winw) *. s) in
4123 state.x <- winw - destx;
4124 gotoy_and_clear_text state.y;
4125 state.mstate
<- Mscrollx
;
4129 let s = float y /. float conf.winh
in
4130 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4131 gotoy_and_clear_text desty;
4132 state.mstate
<- Mscrolly
;
4135 let viewmouse button bstate
x y =
4137 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4138 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4140 match state.mstate
with
4141 | Mzoom
(oldn
, i
) ->
4149 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4151 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4153 let zoom = conf.zoom -. incr in
4155 state.mstate
<- Mzoom
(n, 0);
4157 state.mstate
<- Mzoom
(n, i
+1);
4159 else state.mstate
<- Mzoom
(n, 0)
4161 | _ -> state.mstate
<- Mzoom
(n, 0)
4164 match state.autoscroll
with
4165 | Some step
-> setautoscrollspeed step
(n=4)
4169 then -conf.scrollstep
4170 else conf.scrollstep
4172 let incr = incr * 2 in
4173 let y = clamp incr in
4174 gotoy_and_clear_text y
4177 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4178 if bstate
= Glut.DOWN
4180 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4181 state.mstate
<- Mpan
(x, y)
4184 state.mstate
<- Mnone
4186 | Glut.RIGHT_BUTTON
->
4187 if bstate
= Glut.DOWN
4189 Glut.setCursor
Glut.CURSOR_CYCLE
;
4191 state.mstate
<- Mzoomrect
(p, p)
4194 match state.mstate
with
4195 | Mzoomrect
((x0, y0), _) -> zoomrect x0 y0 x y
4197 Glut.setCursor
Glut.CURSOR_INHERIT
;
4198 state.mstate
<- Mnone
4201 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4202 if bstate
= Glut.DOWN
4204 let position, sh = scrollph state.y in
4205 if y > truncate
position && y < truncate
(position +. sh)
4206 then state.mstate
<- Mscrolly
4209 state.mstate
<- Mnone
4211 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4212 if bstate
= Glut.DOWN
4214 let position, sw = scrollpw state.x in
4215 if x > truncate
position && x < truncate
(position +. sw)
4216 then state.mstate
<- Mscrollx
4219 state.mstate
<- Mnone
4221 | Glut.LEFT_BUTTON
->
4222 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4223 begin match dest with
4224 | Ulinkgoto
(pageno, top) ->
4228 gotopage1 pageno top;
4234 | Unone
when bstate
= Glut.DOWN
->
4235 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4236 state.mstate
<- Mpan
(x, y);
4238 | Unone
| Utext
_ ->
4239 if bstate
= Glut.DOWN
4241 if conf.angle
mod 360 = 0
4243 state.mstate
<- Msel
((x, y), (x, y));
4244 G.postRedisplay "mouse select";
4248 match state.mstate
with
4251 | Mzoom
_ | Mscrollx
| Mscrolly
->
4252 state.mstate
<- Mnone
4254 | Mzoomrect
((x0, y0), _) ->
4258 Glut.setCursor
Glut.CURSOR_INHERIT
;
4259 state.mstate
<- Mnone
4261 | Msel
((_, y0), (_, y1)) ->
4263 if (y0 >= l.pagedispy
&& y0 <= (l.pagedispy
+ l.pagevh))
4264 || ((y1 >= l.pagedispy
&& y1 <= (l.pagedispy
+ l.pagevh)))
4266 match getopaque l.pageno with
4271 List.iter
f state.layout;
4272 copysel
""; (* ugly *)
4273 Glut.setCursor
Glut.CURSOR_INHERIT
;
4274 state.mstate
<- Mnone
;
4281 let birdseyemouse button bstate
x y
4282 (conf, leftx
, _, hooverpageno
, anchor) =
4284 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4285 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4286 let rec loop = function
4289 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4290 && x > margin && x < margin + l.pagew
4292 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4297 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4301 let mouse bstate button
x y =
4302 state.uioh <- state.uioh#button button bstate
x y;
4305 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4308 state.uioh <- state.uioh#
motion x y
4312 state.uioh <- state.uioh#
pmotion x y;
4319 begin match state.mode with
4320 | Textentry
textentry -> textentrykeyboard key textentry
4321 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4322 | View
-> viewkeyboard key
4326 method special key =
4327 begin match state.mode with
4328 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4332 birdseyespecial key vals
4334 | View
when key = Glut.KEY_F1
->
4338 begin match state.autoscroll
with
4339 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4340 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4345 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4347 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4349 if Glut.getModifiers
() land Glut.active_shift
!= 0
4350 then (setzoom state.prevzoom
; state.y)
4351 else clamp (-conf.winh
/2)
4352 else clamp (-conf.scrollstep
)
4354 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4356 if Glut.getModifiers
() land Glut.active_shift
!= 0
4357 then (setzoom state.prevzoom
; state.y)
4358 else clamp (conf.winh
/2)
4359 else clamp (conf.scrollstep
)
4360 | Glut.KEY_PAGE_UP
->
4361 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4363 match state.layout with
4365 | l :: _ -> state.y - l.pagey
4368 | Glut.KEY_PAGE_DOWN
->
4369 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4371 match List.rev
state.layout with
4373 | l :: _ -> getpagey l.pageno
4381 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
4383 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
4384 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
4385 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
4387 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
4389 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4390 then (conf.winw / 2)
4393 state.x <- state.x - dx;
4395 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
4397 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4398 then (conf.winw / 2)
4401 state.x <- state.x + dx;
4406 gotoy_and_clear_text y
4409 | Textentry
te -> textentryspecial key te
4413 method button button bstate
x y =
4414 begin match state.mode with
4415 | View
-> viewmouse button bstate
x y
4416 | Birdseye beye
-> birdseyemouse button bstate
x y beye
4422 begin match state.mode with
4424 | View
| Birdseye
_ ->
4425 match state.mstate
with
4426 | Mzoom
_ | Mnone
-> ()
4431 state.mstate
<- Mpan
(x, y);
4432 if conf.zoom > 1.0 then state.x <- state.x + dx;
4434 gotoy_and_clear_text y
4437 state.mstate
<- Msel
(a, (x, y));
4438 G.postRedisplay "motion select";
4441 let y = min
conf.winh
(max
0 y) in
4445 let x = min
conf.winw (max
0 x) in
4448 | Mzoomrect
(p0
, _) ->
4449 state.mstate
<- Mzoomrect
(p0
, (x, y));
4450 G.postRedisplay "motion zoomrect";
4454 method pmotion x y =
4455 begin match state.mode with
4456 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
4457 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4458 let rec loop = function
4460 if hooverpageno
!= -1
4462 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
4463 G.postRedisplay "pmotion birdseye no hoover";
4466 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4467 && x > margin && x < margin + l.pagew
4469 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
4470 G.postRedisplay "pmotion birdseye hoover";
4479 match state.mstate
with
4481 begin match getunder x y with
4482 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
4484 if conf.underinfo
then showtext 'u'
("ri: " ^
uri);
4485 Glut.setCursor
Glut.CURSOR_INFO
4486 | Ulinkgoto
(page
, _) ->
4488 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
4489 Glut.setCursor
Glut.CURSOR_INFO
4491 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
4492 Glut.setCursor
Glut.CURSOR_TEXT
4495 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
4500 method infochanged
_ = ()
4507 let fontpath = ref "";;
4508 let wmclasshack = ref false;;
4511 let l = String.length
s in
4512 let b = Buffer.create
l in
4520 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
4521 | _ -> Sys.getenv
"HOME"
4524 ("Can not determine home directory location: " ^
4525 Printexc.to_string exn
);
4529 let config_of c attrs
=
4533 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
4534 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
4535 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
4536 | "preload" -> { c with preload = bool_of_string
v }
4537 | "page-bias" -> { c with pagebias
= int_of_string
v }
4538 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
4539 | "auto-scroll-step" ->
4540 { c with autoscrollstep
= max
0 (int_of_string
v) }
4541 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
4542 | "crop-hack" -> { c with crophack
= bool_of_string
v }
4545 match String.lowercase
v with
4546 | "true" -> Some infinity
4548 | f -> Some
(float_of_string
f)
4550 { c with maxwait
= mw}
4551 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
4552 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
4553 | "vertical-margin" ->
4554 { c with interpagespace = max
0 (int_of_string
v) }
4556 let zoom = float_of_string
v /. 100. in
4557 let zoom = max
zoom 0.0 in
4558 { c with zoom = zoom }
4559 | "presentation" -> { c with presentation = bool_of_string
v }
4560 | "rotation-angle" -> { c with angle
= int_of_string
v }
4561 | "width" -> { c with winw = max
20 (int_of_string
v) }
4562 | "height" -> { c with winh
= max
20 (int_of_string
v) }
4563 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
4564 | "proportional-display" -> { c with proportional
= bool_of_string
v }
4565 | "pixmap-cache-size" ->
4566 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
4567 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
4568 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
4569 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
4570 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
4571 | "background-color" -> { c with bgcolor
= color_of_string v }
4572 | "scrollbar-in-presentation" ->
4573 { c with scrollbarinpm
= bool_of_string
v }
4574 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
4575 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
4577 { c with mumemlimit
= max
1024 (int_of_string_with_suffix v) }
4578 | "checkers" -> { c with checkers
= bool_of_string
v }
4579 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
4580 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
4581 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
4582 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
4583 | "uri-launcher" -> { c with urilauncher
= unent v }
4584 | "color-space" -> { c with colorspace
= colorspace_of_string v }
4585 | "invert-colors" -> { c with invert
= bool_of_string
v }
4586 | "brightness" -> { c with colorscale
= float_of_string
v }
4589 prerr_endline
("Error processing attribute (`" ^
4590 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
4593 let rec fold c = function
4596 let c = apply c k
v in
4602 let fromstring f pos
n v d =
4605 dolog "Error processing attribute (%S=%S) at %d\n%s"
4606 n v pos
(Printexc.to_string exn
)
4611 let bookmark_of attrs
=
4612 let rec fold title page rely
= function
4613 | ("title", v) :: rest
-> fold v page rely rest
4614 | ("page", v) :: rest
-> fold title v rely rest
4615 | ("rely", v) :: rest
-> fold title page
v rest
4616 | _ :: rest
-> fold title page rely rest
4617 | [] -> title, page
, rely
4619 fold "invalid" "0" "0" attrs
4623 let rec fold path page rely pan
= function
4624 | ("path", v) :: rest
-> fold v page rely pan rest
4625 | ("page", v) :: rest
-> fold path
v rely pan rest
4626 | ("rely", v) :: rest
-> fold path page
v pan rest
4627 | ("pan", v) :: rest
-> fold path page rely
v rest
4628 | _ :: rest
-> fold path page rely pan rest
4629 | [] -> path
, page
, rely
, pan
4631 fold "" "0" "0" "0" attrs
4634 let setconf dst
src =
4635 dst
.scrollbw
<- src.scrollbw
;
4636 dst
.scrollh
<- src.scrollh
;
4637 dst
.icase
<- src.icase
;
4638 dst
.preload <- src.preload;
4639 dst
.pagebias
<- src.pagebias
;
4640 dst
.verbose
<- src.verbose
;
4641 dst
.scrollstep
<- src.scrollstep
;
4642 dst
.maxhfit
<- src.maxhfit
;
4643 dst
.crophack
<- src.crophack
;
4644 dst
.autoscrollstep
<- src.autoscrollstep
;
4645 dst
.maxwait
<- src.maxwait
;
4646 dst
.hlinks
<- src.hlinks
;
4647 dst
.underinfo
<- src.underinfo
;
4648 dst
.interpagespace <- src.interpagespace;
4649 dst
.zoom <- src.zoom;
4650 dst
.presentation <- src.presentation;
4651 dst
.angle
<- src.angle
;
4652 dst
.winw <- src.winw;
4653 dst
.winh
<- src.winh
;
4654 dst
.savebmarks
<- src.savebmarks
;
4655 dst
.memlimit
<- src.memlimit
;
4656 dst
.proportional
<- src.proportional
;
4657 dst
.texcount
<- src.texcount
;
4658 dst
.sliceheight
<- src.sliceheight
;
4659 dst
.thumbw
<- src.thumbw
;
4660 dst
.jumpback
<- src.jumpback
;
4661 dst
.bgcolor
<- src.bgcolor
;
4662 dst
.scrollbarinpm
<- src.scrollbarinpm
;
4663 dst
.tilew
<- src.tilew
;
4664 dst
.tileh
<- src.tileh
;
4665 dst
.mumemlimit
<- src.mumemlimit
;
4666 dst
.checkers
<- src.checkers
;
4667 dst
.aalevel
<- src.aalevel
;
4668 dst
.trimmargins
<- src.trimmargins
;
4669 dst
.trimfuzz
<- src.trimfuzz
;
4670 dst
.urilauncher
<- src.urilauncher
;
4671 dst
.colorspace
<- src.colorspace
;
4672 dst
.invert
<- src.invert
;
4673 dst
.colorscale
<- src.colorscale
;
4677 let h = Hashtbl.create
10 in
4678 let dc = { defconf with angle
= defconf.angle
} in
4679 let rec toplevel v t spos
_ =
4681 | Vdata
| Vcdata
| Vend
-> v
4682 | Vopen
("llppconfig", _, closed
) ->
4685 else { v with f = llppconfig
}
4687 error
"unexpected subelement at top level" s spos
4688 | Vclose
_ -> error
"unexpected close at top level" s spos
4690 and llppconfig
v t spos
_ =
4692 | Vdata
| Vcdata
-> v
4693 | Vend
-> error
"unexpected end of input in llppconfig" s spos
4694 | Vopen
("defaults", attrs
, closed
) ->
4695 let c = config_of dc attrs
in
4699 else { v with f = skip
"defaults" (fun () -> v) }
4701 | Vopen
("ui-font", attrs
, closed
) ->
4702 let rec getsize size
= function
4704 | ("size", v) :: rest
->
4706 fromstring int_of_string spos
"size" v fstate.fontsize
in
4708 | l -> getsize size l
4710 fstate.fontsize
<- getsize fstate.fontsize attrs
;
4713 else { v with f = uifont
(Buffer.create
10) }
4715 | Vopen
("doc", attrs
, closed
) ->
4716 let pathent, spage
, srely
, span
= doc_of attrs
in
4717 let path = unent pathent
4718 and pageno = fromstring int_of_string spos
"page" spage
0
4719 and rely
= fromstring float_of_string spos
"rely" srely
0.0
4720 and pan
= fromstring int_of_string spos
"pan" span
0 in
4721 let c = config_of dc attrs
in
4722 let anchor = (pageno, rely
) in
4724 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
4725 else { v with f = doc
path pan
anchor c [] }
4728 error
"unexpected subelement in llppconfig" s spos
4730 | Vclose
"llppconfig" -> { v with f = toplevel }
4731 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
4733 and uifont
b v t spos epos
=
4736 Buffer.add_substring
b s spos
(epos
- spos
);
4738 | Vopen
(_, _, _) ->
4739 error
"unexpected subelement in ui-font" s spos
4740 | Vclose
"ui-font" ->
4741 if String.length
!fontpath = 0
4742 then fontpath := Buffer.contents
b;
4743 { v with f = llppconfig
}
4744 | Vclose
_ -> error
"unexpected close in ui-font" s spos
4745 | Vend
-> error
"unexpected end of input in ui-font" s spos
4747 and doc
path pan
anchor c bookmarks
v t spos
_ =
4749 | Vdata
| Vcdata
-> v
4750 | Vend
-> error
"unexpected end of input in doc" s spos
4751 | Vopen
("bookmarks", _, closed
) ->
4754 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
4756 | Vopen
(_, _, _) ->
4757 error
"unexpected subelement in doc" s spos
4760 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
4761 { v with f = llppconfig
}
4763 | Vclose
_ -> error
"unexpected close in doc" s spos
4765 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
4767 | Vdata
| Vcdata
-> v
4768 | Vend
-> error
"unexpected end of input in bookmarks" s spos
4769 | Vopen
("item", attrs
, closed
) ->
4770 let titleent, spage
, srely
= bookmark_of attrs
in
4771 let page = fromstring int_of_string spos
"page" spage
0
4772 and rely
= fromstring float_of_string spos
"rely" srely
0.0 in
4773 let bookmarks = (unent titleent, 0, (page, rely
)) :: bookmarks in
4775 then { v with f = pbookmarks
path pan
anchor c bookmarks }
4778 { v with f = skip
"item" f }
4781 error
"unexpected subelement in bookmarks" s spos
4783 | Vclose
"bookmarks" ->
4784 { v with f = doc
path pan
anchor c bookmarks }
4786 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
4788 and skip tag
f v t spos
_ =
4790 | Vdata
| Vcdata
-> v
4792 error
("unexpected end of input in skipped " ^ tag
) s spos
4793 | Vopen
(tag'
, _, closed
) ->
4797 let f'
() = { v with f = skip tag
f } in
4798 { v with f = skip tag'
f'
}
4802 else error
("unexpected close in skipped " ^ tag
) s spos
4805 parse
{ f = toplevel; accu = () } s;
4811 let len = in_channel_length ic
in
4812 let s = String.create
len in
4813 really_input ic
s 0 len;
4816 | Parse_error
(msg
, s, pos
) ->
4817 let subs = subs s pos
in
4818 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
4819 failwith
("parse error: " ^
s)
4822 failwith
("config load error: " ^
Printexc.to_string exn
)
4828 let dir = Filename.concat
home ".config" in
4829 if Sys.is_directory
dir then dir else home
4832 Filename.concat
dir "llpp.conf"
4835 let confpath = ref defconfpath;;
4838 if Sys.file_exists
!confpath
4841 (try Some
(open_in_bin
!confpath)
4844 ("Error opening configuation file `" ^
!confpath ^
"': " ^
4845 Printexc.to_string exn
);
4854 ("Error loading configuation from `" ^
!confpath ^
"': " ^
4855 Printexc.to_string exn
);
4861 f (Hashtbl.create
0, defconf)
4866 let pc, pb
, px, pa
=
4868 Hashtbl.find h (Filename.basename
state.path)
4869 with Not_found
-> dc, [], 0, (0, 0.0)
4873 state.bookmarks <- pb
;
4875 state.scrollw
<- conf.scrollbw
;
4877 then state.anchor <- pa
;
4878 cbput state.hists
.nav pa
;
4883 let add_attrs bb always
dc c =
4886 then Printf.bprintf bb
"\n %s='%b'" s a
4889 then Printf.bprintf bb
"\n %s='%d'" s a
4892 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
4895 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
4898 then Printf.bprintf bb
"\n %s='%f'" s a
4902 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
4906 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
4910 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
4914 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
4924 else string_of_float
f
4926 Printf.bprintf bb
"\n %s='%s'" s v
4930 then dc.winw, dc.winh
4932 match state.fullscreen
with
4934 | None
-> c.winw, c.winh
4936 let zoom, presentation, interpagespace, maxwait
=
4938 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
4940 match state.mode with
4941 | Birdseye
(bc
, _, _, _, _) ->
4942 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
4943 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
4945 oi
"width" w dc.winw;
4946 oi
"height" h dc.winh
;
4947 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
4948 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
4949 ob "case-insensitive-search" c.icase
dc.icase
;
4950 ob "preload" c.preload dc.preload;
4951 oi
"page-bias" c.pagebias
dc.pagebias
;
4952 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
4953 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
4954 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
4955 ob "crop-hack" c.crophack
dc.crophack
;
4956 oW
"throttle" maxwait
dc.maxwait
;
4957 ob "highlight-links" c.hlinks
dc.hlinks
;
4958 ob "under-cursor-info" c.underinfo
dc.underinfo
;
4959 oi
"vertical-margin" interpagespace dc.interpagespace;
4960 oz
"zoom" zoom dc.zoom;
4961 ob "presentation" presentation dc.presentation;
4962 oi
"rotation-angle" c.angle
dc.angle
;
4963 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
4964 ob "proportional-display" c.proportional
dc.proportional
;
4965 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
4966 oi
"tex-count" c.texcount
dc.texcount
;
4967 oi
"slice-height" c.sliceheight
dc.sliceheight
;
4968 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
4969 ob "persistent-location" c.jumpback
dc.jumpback
;
4970 oc
"background-color" c.bgcolor
dc.bgcolor
;
4971 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
4972 oi
"tile-width" c.tilew
dc.tilew
;
4973 oi
"tile-height" c.tileh
dc.tileh
;
4974 oI
"mupdf-memlimit" c.mumemlimit
dc.mumemlimit
;
4975 ob "checkers" c.checkers
dc.checkers
;
4976 oi
"aalevel" c.aalevel
dc.aalevel
;
4977 ob "trim-margins" c.trimmargins
dc.trimmargins
;
4978 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
4979 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
4980 oC
"color-space" c.colorspace
dc.colorspace
;
4981 ob "invert-colors" c.invert
dc.invert
;
4982 oF
"brightness" c.colorscale
dc.colorscale
;
4984 then ob "wmclass-hack" !wmclasshack false;
4988 let uifontsize = fstate.fontsize
in
4989 let bb = Buffer.create
32768 in
4991 let dc = if conf.bedefault
then conf else dc in
4992 Buffer.add_string
bb "<llppconfig>\n";
4994 if String.length
!fontpath > 0
4996 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5002 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5005 Buffer.add_string
bb "<defaults ";
5006 add_attrs bb true dc dc;
5007 Buffer.add_string
bb "/>\n";
5009 let adddoc path pan
anchor c bookmarks =
5010 if bookmarks == [] && c = dc && anchor = emptyanchor
5013 Printf.bprintf
bb "<doc path='%s'"
5014 (enent
path 0 (String.length
path));
5016 if anchor <> emptyanchor
5018 let n, y = anchor in
5019 Printf.bprintf
bb " page='%d'" n;
5022 Printf.bprintf
bb " rely='%f'" y
5027 then Printf.bprintf
bb " pan='%d'" pan
;
5029 add_attrs bb false dc c;
5031 begin match bookmarks with
5032 | [] -> Buffer.add_string
bb "/>\n"
5034 Buffer.add_string
bb ">\n<bookmarks>\n";
5035 List.iter
(fun (title, _level
, (page, rely
)) ->
5037 "<item title='%s' page='%d'"
5038 (enent
title 0 (String.length
title))
5043 Printf.bprintf
bb " rely='%f'" rely
5045 Buffer.add_string
bb "/>\n";
5047 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5053 match state.mode with
5054 | Birdseye
(_, pan, _, _, _) -> pan
5057 let basename = Filename.basename state.path in
5058 adddoc basename pan (getanchor ())
5061 match state.autoscroll
with
5063 | None
-> conf.autoscrollstep
}
5064 (if conf.savebmarks
then state.bookmarks else []);
5066 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5068 then adddoc path x y c bookmarks
5070 Buffer.add_string
bb "</llppconfig>";
5073 if Buffer.length
bb > 0
5076 let tmp = !confpath ^
".tmp" in
5077 let oc = open_out_bin
tmp in
5078 Buffer.output_buffer
oc bb;
5080 Unix.rename
tmp !confpath;
5083 ("error while saving configuration: " ^
Printexc.to_string exn
)
5090 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5091 "<password> Set password");
5093 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5094 "<path> Set path to the user interface font");
5096 ("-c", Arg.String
(fun s -> Config.confpath := s),
5097 "<path> Set path to the configuration file");
5099 ("-v", Arg.Unit
(fun () ->
5101 "%s\nconfiguration path: %s\n"
5105 exit
0), " Print version and exit");
5108 (fun s -> state.path <- s)
5109 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5111 if String.length
state.path = 0
5112 then (prerr_endline
"file name missing"; exit
1);
5116 let _ = Glut.init
Sys.argv
in
5117 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5118 let () = Glut.initWindowSize
conf.winw conf.winh
in
5119 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5121 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5122 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5123 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5128 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5130 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5131 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5132 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5133 Unix.bind
sock addr;
5135 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5136 Unix.connect
csock addr;
5137 let ssock, _ = Unix.accept
sock in
5140 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5141 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5148 let () = Glut.displayFunc
display in
5149 let () = Glut.reshapeFunc
reshape in
5150 let () = Glut.keyboardFunc
keyboard in
5151 let () = Glut.specialFunc
special in
5152 let () = Glut.idleFunc
(Some
idle) in
5153 let () = Glut.mouseFunc
mouse in
5154 let () = Glut.motionFunc
motion in
5155 let () = Glut.passiveMotionFunc
pmotion in
5157 setcheckers conf.checkers
;
5159 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5160 conf.texcount
, conf.sliceheight
, conf.mumemlimit
, conf.colorspace
,
5161 !Config.wmclasshack, !Config.fontpath
5163 state.csock <- csock;
5164 state.ssock <- ssock;
5165 state.text <- "Opening " ^
state.path;
5166 setaalevel
conf.aalevel
;
5167 writeopen state.path state.password
;
5169 setfontsize fstate.fontsize
;
5175 | Glut.BadEnum
"key in special_of_int" ->
5176 showtext '
!'
" LablGlut bug: special key not recognized";