4 | Ulinkgoto
of (int * int)
6 and facename
= string;;
8 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
12 type params
= (angle
* proportional
* trimparams
13 * texcount
* sliceheight
* memsize
14 * colorspace
* wmclasshack
* fontpath
)
23 and proportional
= bool
24 and trimmargins
= bool
25 and interpagespace
= int
33 and wmclasshack
= bool
34 and irect
= (int * int * int * int)
35 and trimparams
= (trimmargins
* irect
)
36 and colorspace
= | Rgb
| Bgr
| Gray
39 type platform
= | Punknown
| Plinux
| Pwindows
| Posx
| Psun
40 | Pfreebsd
| Pdragonflybsd
| Popenbsd
| Pmingw
| Pcygwin
;;
42 external init
: Unix.file_descr
-> params
-> unit = "ml_init";;
43 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
44 external copysel
: string -> unit = "ml_copysel";;
45 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
46 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
47 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
48 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
49 external measurestr
: int -> string -> float = "ml_measure_string";;
50 external getmaxw
: unit -> float = "ml_getmaxw";;
51 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
52 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
53 external platform
: unit -> platform
= "ml_platform";;
54 external setaalevel
: int -> unit = "ml_setaalevel";;
56 let platform_to_string = function
57 | Punknown
-> "unknown"
59 | Pwindows
-> "Windows"
62 | Pfreebsd
-> "FreeBSD"
63 | Pdragonflybsd
-> "DragonflyBSD"
64 | Popenbsd
-> "OpenBSD"
69 let platform = platform ();;
73 | Pwindows
| Pmingw
-> true
81 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
84 external drawtile
: tileparams
-> string -> unit = "ml_drawtile";;
88 | Msel
of (mpos
* mpos
)
91 | Mzoom
of (int * int)
92 | Mzoomrect
of (mpos
* mpos
)
96 type textentry
= string * string * onhist
option * onkey
* ondone
97 and onkey
= string -> int -> te
98 and ondone
= string -> unit
99 and histcancel
= unit -> unit
100 and onhist
= ((histcmd
-> string) * histcancel
)
101 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
106 | TEswitch
of textentry
117 let bound v minv maxv
=
118 max minv
(min maxv v
);
122 { store
= Array.create n v
129 let drawstring size x y s
=
131 Gl.enable `texture_2d
;
132 ignore
(drawstr size x y s
);
134 Gl.disable `texture_2d
;
137 let drawstring1 size x y s
=
141 let drawstring2 size x y fmt
=
142 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
145 let cbcap b
= Array.length b
.store
;;
150 b
.wc
<- (b
.wc
+ 1) mod cap;
152 b
.len
<- min
(b
.len
+ 1) cap;
155 let cbempty b
= b
.len
= 0;;
157 let cbgetg b circular dir
=
161 let rc = b
.rc + dir
in
173 else max
0 (min
rc (b
.len
-1))
179 let cbget b
= cbgetg b
false;;
180 let cbgetc b
= cbgetg b
true;;
197 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
198 dolog " WxH %dx%d" l
.pagew l
.pageh
;
199 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
200 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
201 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
205 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
207 dolog " x0,y0=(% f, % f)" x0 y0
;
208 dolog " x1,y1=(% f, % f)" x1 y1
;
209 dolog " x2,y2=(% f, % f)" x2 y2
;
210 dolog " x3,y3=(% f, % f)" x3 y3
;
215 { mutable scrollbw
: int
216 ; mutable scrollh
: int
217 ; mutable icase
: bool
218 ; mutable preload
: bool
219 ; mutable pagebias
: int
220 ; mutable verbose
: bool
221 ; mutable debug
: bool
222 ; mutable scrollstep
: int
223 ; mutable maxhfit
: bool
224 ; mutable crophack
: bool
225 ; mutable autoscrollstep
: int
226 ; mutable showall
: bool
227 ; mutable hlinks
: bool
228 ; mutable underinfo
: bool
229 ; mutable interpagespace
: interpagespace
230 ; mutable zoom
: float
231 ; mutable presentation
: bool
232 ; mutable angle
: angle
235 ; mutable savebmarks
: bool
236 ; mutable proportional
: proportional
237 ; mutable trimmargins
: trimmargins
238 ; mutable trimfuzz
: irect
239 ; mutable memlimit
: memsize
240 ; mutable texcount
: texcount
241 ; mutable sliceheight
: sliceheight
242 ; mutable thumbw
: width
243 ; mutable jumpback
: bool
244 ; mutable bgcolor
: float * float * float
245 ; mutable bedefault
: bool
246 ; mutable scrollbarinpm
: bool
247 ; mutable tilew
: int
248 ; mutable tileh
: int
249 ; mutable mumemlimit
: memsize
250 ; mutable checkers
: bool
251 ; mutable aalevel
: int
252 ; mutable urilauncher
: string
253 ; mutable colorspace
: colorspace
254 ; mutable invert
: bool
258 type anchor
= pageno
* top
;;
260 type outline
= string * int * anchor
;;
262 type rect
= float * float * float * float * float * float * float * float;;
264 type tile
= opaque
* pixmapsize
* elapsed
265 and elapsed
= float;;
266 type pagemapkey
= pageno
* gen
;;
267 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
271 let emptyanchor = (0, 0.0);;
273 class type uioh
= object
274 method display
: unit
275 method key
: int -> uioh
276 method special
: Glut.special_key_t
-> uioh
278 Glut.button_t
-> Glut.mouse_button_state_t
-> int -> int -> uioh
279 method motion
: int -> int -> uioh
280 method pmotion
: int -> int -> uioh
281 method memusedchanged
: unit
285 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
286 | Textentry
of (textentry
* onleave
)
288 and onleave
= leavetextentrystatus
-> unit
289 and leavetextentrystatus
= | Cancel
| Confirm
290 and helpitem
= string * int * action
293 | Action
of (uioh
-> uioh
)
296 let isbirdseye = function Birdseye _
-> true | _
-> false;;
297 let istextentry = function Textentry _
-> true | _
-> false;;
301 | Loading
of (page
* gen
)
303 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
305 | Outlining
of outline list
308 let nouioh : uioh
= object (self
)
311 method special _
= self
312 method button _ _ _ _
= self
313 method motion _ _
= self
314 method pmotion _ _
= self
315 method memusedchanged
= ()
319 { mutable csock
: Unix.file_descr
320 ; mutable ssock
: Unix.file_descr
324 ; mutable scrollw
: int
325 ; mutable hscrollh
: int
326 ; mutable anchor
: anchor
328 ; mutable layout
: page list
329 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
330 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
331 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
332 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
333 ; mutable pagecount
: int
334 ; mutable currently
: currently
335 ; mutable mstate
: mstate
336 ; mutable searchpattern
: string
337 ; mutable rects
: (pageno
* recttype
* rect
) list
338 ; mutable rects1
: (pageno
* recttype
* rect
) list
339 ; mutable text
: string
340 ; mutable fullscreen
: (width
* height
) option
341 ; mutable mode
: mode
342 ; mutable uioh
: uioh
343 ; mutable outlines
: outline array
344 ; mutable bookmarks
: outline list
345 ; mutable path
: string
346 ; mutable password
: string
347 ; mutable invalidated
: int
348 ; mutable colorscale
: float
349 ; mutable memused
: memsize
351 ; mutable throttle
: (page list
* int) option
352 ; mutable autoscroll
: int option
353 ; mutable help
: helpitem array
354 ; mutable docinfo
: (int * string) list
355 ; mutable deadline
: float
356 ; mutable texid
: GlTex.texture_id
option
358 ; mutable prevzoom
: float
359 ; mutable progress
: float
362 { pat
: string circbuf
363 ; pag
: string circbuf
364 ; nav
: anchor circbuf
385 ; presentation
= false
390 ; proportional
= true
391 ; trimmargins
= false
392 ; trimfuzz
= (0,0,0,0)
393 ; memlimit
= 32 lsl 20
398 ; bgcolor
= (0.5, 0.5, 0.5)
400 ; scrollbarinpm
= true
403 ; mumemlimit
= 128 lsl 20
408 | Plinux
| Pfreebsd
| Pdragonflybsd
| Popenbsd
| Psun
-> "xdg-open \"%s\""
409 | Posx
-> "open \"%s\""
410 | Pwindows
| Pcygwin
| Pmingw
-> "iexplore \"%s\""
417 let conf = { defconf with angle
= defconf.angle
};;
419 let uifontsize = ref 14;;
422 if String.length
conf.urilauncher
= 0
423 then print_endline uri
425 let re = Str.regexp
"%s" in
426 let command = Str.global_replace
re uri
conf.urilauncher
in
428 try Some
(Unix.open_process_in
command)
431 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
436 | Some ic
-> close_in ic
441 let strings = ("llpp version " ^
Help.version
) :: "" :: Help.keys
in
443 let r = Str.regexp
"\\(http://[^ ]+\\)" in
445 if (try Str.search_forward
r s
0 with Not_found
-> -1) >= 0
447 let uri = Str.matched_string s
in
448 (s
, 0, Action
(fun u
-> gotouri uri; u
))
449 else s
, 0, Noaction
) strings
461 ; anchor
= emptyanchor
464 ; tilelru
= Queue.create
()
465 ; pagemap
= Hashtbl.create
10
466 ; tilemap
= Hashtbl.create
10
483 { nav
= cbnew 10 (0, 0.0)
505 Printf.kprintf prerr_endline fmt
507 Printf.kprintf ignore fmt
512 let postRedisplay who
=
513 vlog "redisplay for %s" who
;
514 Glut.postRedisplay ();
519 let b = Buffer.create
(String.length s
+ 1) in
520 Buffer.add_string
b s
;
525 let colorspace_of_string s
=
526 match String.lowercase s
with
530 | _
-> failwith
"invalid colorspace"
533 let int_of_colorspace = function
539 let colorspace_of_int = function
543 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
546 let colorspace_to_string = function
552 let intentry_with_suffix text key
=
553 let c = Char.unsafe_chr key
in
554 match Char.lowercase
c with
556 let text = addchar text c in
560 let text = addchar text c in
564 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
569 let len = String.length s
in
571 let b = Buffer.create
n in
572 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
573 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
574 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
575 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
576 Buffer.add_string
b s
;
577 let s'
= Buffer.contents
b in
578 let n'
= Unix.write fd
s'
0 n in
579 if n'
!= n then failwith
"write failed";
584 let n = Unix.read fd
s 0 4 in
585 if n != 4 then failwith
"incomplete read(len)";
587 lor (Char.code
s.[0] lsl 24)
588 lor (Char.code
s.[1] lsl 16)
589 lor (Char.code
s.[2] lsl 8)
590 lor (Char.code
s.[3] lsl 0)
592 let s = String.create
len in
593 let n = Unix.read fd
s 0 len in
594 if n != len then failwith
"incomplete read(data)";
599 let b = Buffer.create
10 in
600 Buffer.add_string
b s;
601 let rec combine = function
604 Buffer.add_char
b ' '
;
607 | `
b b -> if b then "1" else "0"
609 | `i i
-> string_of_int i
610 | `f f
-> string_of_float f
611 | `I f
-> string_of_int
(truncate f
)
613 Buffer.add_string
b s;
620 let cmd = Buffer.contents
(makecmd s l
) in
621 writecmd state.csock
cmd;
627 let d = conf.winh
- h
in
634 let rec f pn ph pi fh l
=
636 | (n, _
, h
, _
) :: rest
->
637 let ips = calcips h
in
642 if isbirdseye state.mode
&& pn
= 0
647 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
652 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
656 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
659 let fh = f 0 0 0 0 state.pdims
in
663 let getpageyh pageno
=
664 let rec f pn ph pi y l
=
666 | (n, _
, h
, _
) :: rest
->
667 let ips = calcips h
in
670 let h = if n = pageno
then h else ph
in
671 if conf.presentation
&& n = pageno
673 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
675 y
+ (pageno
- pn
) * (ph
+ pi
), h
677 let y = y + (if conf.presentation
then pi
else 0) in
678 let y = y + (n - pn
) * (ph
+ pi
) in
682 y + (pageno
- pn
) * (ph
+ pi
), ph
684 f 0 0 0 0 state.pdims
687 let getpagedim pageno
=
690 | (n, _
, _
, _
) as pdim
:: rest
->
692 then (if n = pageno
then pdim
else ppdim
)
697 f (-1, -1, -1, -1) state.pdims
700 let getpageh pageno
=
701 let _, _, h, _ = getpagedim pageno
in
705 let getpagew pageno
=
706 let _, w
, _, _ = getpagedim pageno
in
710 let getpagey pageno
= fst
(getpageyh pageno
);;
713 let sh = sh - state.hscrollh
in
714 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
715 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
717 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
718 let ips = calcips h in
720 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
724 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
726 prev
, pdims
, pdimno
, 0
728 let dy = dy + yinc in
729 let py = py + yinc in
730 if pageno
= state.pagecount
|| dy >= sh
735 if py + h <= vy - yinc
737 let py = py + h + ips in
738 let dy = max
0 (py - y) in
747 let pagey = vy - py in
748 let pagevh = h - pagey in
749 let pagevh = min
(sh - dy) pagevh in
750 let off = if yinc > 0 then py - vy else 0 in
751 let py = py + h + ips in
754 if state.w
< conf.winw
- state.scrollw
755 then (conf.winw
- state.scrollw
- state.w
) / 2
758 let dispx = xoff + state.x
in
764 let lw = w
- pagex in
765 min
lw (conf.winw
- state.scrollw
)
773 ; pagey = pagey + off
775 ; pagevh = pagevh - off
777 ; pagedispy
= dy + off
780 let accu = e :: accu in
789 if state.invalidated
= 0
808 let y = state.y + incr
in
810 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
814 let getopaque pageno
=
815 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
816 with Not_found
-> None
819 let putopaque pageno opaque
=
820 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
824 let tilex = l
.pagex mod conf.tilew
in
825 let tiley = l
.pagey mod conf.tileh
in
827 let col = l
.pagex / conf.tilew
in
828 let row = l
.pagey / conf.tileh
in
831 let a = l
.pagew
- l
.pagex in
832 let b = conf.winw
- state.scrollw
in
836 let rec rowloop row y0 dispy
h =
840 let dh = conf.tileh
- y0
in
842 let rec colloop col x0
dispx w
=
846 let dw = conf.tilew
- x0
in
849 f col row dispx dispy x0 y0
dw dh;
850 colloop (col+1) 0 (dispx+dw) (w
-dw)
853 colloop col tilex l
.pagedispx
vw;
854 rowloop (row+1) 0 (dispy
+dh) (h-dh)
858 then rowloop row tiley l
.pagedispy vh
;
861 let gettileopaque l
col row =
863 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
865 try Some
(Hashtbl.find
state.tilemap
key)
866 with Not_found
-> None
869 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
870 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
871 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
874 let drawtiles l color
=
876 let f col row x
y tilex tiley w
h =
877 match gettileopaque l
col row with
878 | Some
(opaque
, _, t
) ->
879 let params = x
, y, w
, h, tilex, tiley in
883 GlFunc.blend_func `zero `one_minus_src_color
;
885 drawtile
params opaque
;
887 then Gl.disable `blend
;
890 let s = Printf.sprintf
894 let w = measurestr
!uifontsize s in
895 GlMisc.push_attrib
[`current
];
896 GlDraw.color
(0.0, 0.0, 0.0);
898 (float (x
-2), float (y-2))
899 (float (x
+2) +. w, float (y + !uifontsize + 2));
900 GlDraw.color
(1.0, 1.0, 1.0);
901 drawstring !uifontsize x
(y + !uifontsize - 1) s;
902 GlMisc.pop_attrib
();
907 let lw = conf.winw
- state.scrollw
- x
in
910 let lh = conf.winh
- y in
913 Gl.enable `texture_2d
;
914 begin match state.texid
with
916 GlTex.bind_texture `texture_2d id
;
920 and y1
= float (y+h) in
922 let tw = float w /. 64.0
923 and th
= float h /. 64.0 in
924 let tx0 = float tilex /. 64.0
925 and ty0
= float tiley /. 64.0 in
927 and ty1
= ty0
+. th
in
928 GlDraw.begins `quads
;
929 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
930 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
931 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
932 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
935 Gl.disable `texture_2d
;
937 GlDraw.color
(1.0, 1.0, 1.0);
940 (float (x
+w), float (y+h));
942 if w > 128 && h > !uifontsize + 10
944 GlDraw.color
(0.0, 0.0, 0.0);
947 then (col*conf.tilew
, row*conf.tileh
)
950 drawstring2 !uifontsize x
y "Loading %d [%d,%d]" l
.pageno
c r;
957 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
959 let tilevisible1 l x
y =
961 and ax1
= l
.pagex + l
.pagevw
963 and ay1
= l
.pagey + l
.pagevh in
967 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
968 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
970 let rx0 = max
ax0 bx0
971 and ry0
= max ay0 by0
972 and rx1
= min ax1
bx1
973 and ry1
= min ay1 by1
in
975 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
979 let tilevisible layout n x
y =
980 let rec findpageinlayout = function
981 | l
:: _ when l
.pageno
= n -> tilevisible1 l x
y
982 | _ :: rest
-> findpageinlayout rest
985 findpageinlayout layout
988 let tileready l x
y =
989 tilevisible1 l x
y &&
990 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
993 let tilepage n p
layout =
994 let rec loop = function
998 let f col row _ _ _ _ _ _ =
999 if state.currently
= Idle
1001 match gettileopaque l
col row with
1004 let x = col*conf.tilew
1005 and y = row*conf.tileh
in
1007 let w = l
.pagew
- x in
1011 let h = l
.pageh
- y in
1023 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1024 conf.tilew
, conf.tileh
1033 if state.invalidated
= 0 then loop layout;
1036 let preloadlayout visiblepages
=
1037 let presentation = conf.presentation in
1038 let interpagespace = conf.interpagespace in
1039 let maxy = state.maxy in
1040 conf.presentation <- false;
1041 conf.interpagespace <- 0;
1042 state.maxy <- calcheight ();
1044 match visiblepages
with
1046 | l
:: _ -> getpagey l
.pageno
+ l
.pagey
1048 let y = if y < conf.winh
then 0 else y - conf.winh
in
1049 let h = state.y - y + conf.winh
*3 in
1050 let pages = layout y h in
1051 conf.presentation <- presentation;
1052 conf.interpagespace <- interpagespace;
1058 let rec loop pages =
1059 if state.currently
!= Idle
1064 begin match getopaque l
.pageno
with
1066 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1067 state.currently
<- Loading
(l
, state.gen
);
1069 tilepage l
.pageno opaque
pages;
1074 if state.invalidated
= 0 then loop pages
1079 if conf.preload && state.currently
= Idle
1080 then load (preloadlayout pages);
1083 let layoutready layout =
1084 let rec fold all ls
=
1085 all
&& match ls
with
1087 let seen = ref false in
1088 let allvisible = ref true in
1089 let foo col row _ _ _ _ _ _ =
1091 allvisible := !allvisible &&
1092 begin match gettileopaque l
col row with
1098 fold (!seen && !allvisible) rest
1101 let alltilesvisible = fold true layout in
1106 let y = bound y 0 state.maxy in
1107 let y, layout, proceed
=
1110 match state.throttle
with
1112 let layout = layout y conf.winh
in
1113 let ready = layoutready layout in
1117 state.throttle
<- Some
(layout, y);
1119 else G.postRedisplay "gotoy showall (None)";
1121 | Some
_ -> -1, [], false
1123 let layout = layout y conf.winh
in
1124 if true || layoutready layout
1125 then G.postRedisplay "gotoy ready";
1131 state.layout <- layout;
1132 begin match state.mode
with
1133 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1134 if not
(pagevisible layout pageno
)
1136 match state.layout with
1139 state.mode
<- Birdseye
(
1140 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1149 let conttiling pageno opaque
=
1150 tilepage pageno opaque
1151 (if conf.preload then preloadlayout state.layout else state.layout)
1154 let gotoy_and_clear_text y =
1156 if not
conf.verbose
then state.text <- "";
1160 match state.layout with
1162 | l
:: _ -> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1165 let getanchory (n, top
) =
1166 let y, h = getpageyh n in
1167 y + (truncate
(top
*. float h));
1170 let gotoanchor anchor
=
1171 gotoy (getanchory anchor
);
1175 cbput state.hists
.nav
(getanchor ());
1179 let anchor = cbgetc state.hists
.nav dir
in
1183 let gotopage n top
=
1184 let y, h = getpageyh n in
1185 gotoy_and_clear_text (y + (truncate
(top
*. float h)));
1188 let gotopage1 n top
=
1189 let y = getpagey n in
1190 gotoy_and_clear_text (y + top
);
1198 state.invalidated
<- state.invalidated
+ 1;
1201 let writeopen path password
=
1202 writecmd state.csock
("open " ^ path ^
"\000" ^ password ^
"\000");
1205 let opendoc path password
=
1208 state.password
<- password
;
1209 state.gen
<- state.gen
+ 1;
1210 state.docinfo
<- [];
1212 setaalevel
conf.aalevel
;
1213 writeopen path password
;
1214 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1215 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1219 let c = c *. state.colorscale
in
1223 let scalecolor2 (r, g
, b) =
1224 (r *. state.colorscale
, g
*. state.colorscale
, b *. state.colorscale
);
1228 state.maxy <- calcheight ();
1230 if state.w <= conf.winw
- state.scrollw
1234 match state.mode
with
1235 | Birdseye
(_, _, pageno
, _, _) ->
1236 let y, h = getpageyh pageno
in
1237 let top = (conf.winh
- h) / 2 in
1238 gotoy (max
0 (y - top))
1239 | _ -> gotoanchor state.anchor
1243 let firsttime = ref true in
1245 GlDraw.viewport
0 0 w h;
1246 if state.invalidated
= 0 && not
!firsttime
1247 then state.anchor <- getanchor ();
1251 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1255 GlMat.mode `modelview
;
1256 GlMat.load_identity
();
1258 GlMat.mode `projection
;
1259 GlMat.load_identity
();
1260 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1261 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1262 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1265 wcmd "geometry" [`i
w; `i
h];
1269 let len = String.length
state.text in
1272 match state.mode
with
1273 | View
-> state.hscrollh
1278 (x, float (conf.winh
- (!uifontsize + 4) - hscrollh))
1279 (x+.w, float (conf.winh
- hscrollh))
1282 let w = float (conf.winw
- state.scrollw
- 1) in
1283 if state.progress
>= 0.0 && state.progress
< 1.0
1285 GlDraw.color
(0.3, 0.3, 0.3);
1286 let w1 = w *. state.progress
in
1288 GlDraw.color
(0.0, 0.0, 0.0);
1292 GlDraw.color
(0.0, 0.0, 0.0);
1296 GlDraw.color
(1.0, 1.0, 1.0);
1297 drawstring !uifontsize
1298 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1300 match state.mode
with
1301 | Textentry
((prefix
, text, _, _, _), _) ->
1305 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1307 Printf.sprintf
"%s%s_" prefix
text
1312 if len > 0 then drawstring state.text
1316 state.text <- Printf.sprintf
"%c%s" c s;
1317 G.postRedisplay "showtext";
1321 let len = Queue.length
state.tilelru
in
1323 if state.memused
<= conf.memlimit
1328 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1329 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1332 && colorspace
= conf.colorspace
1333 && angle
= conf.angle
1334 && pagew
= getpagew n
1335 && pageh
= getpageh n
1339 then preloadlayout state.layout
1342 let x = col*conf.tilew
1343 and y = row*conf.tileh
in
1344 tilevisible layout n x y
1346 then Queue.push lruitem
state.tilelru
1348 wcmd "freetile" [`
s p
];
1349 state.memused
<- state.memused
- s;
1350 state.uioh#memusedchanged
;
1351 Hashtbl.remove
state.tilemap k
;
1360 Queue.iter
(fun (k
, p
, s) ->
1361 wcmd "freetile" [`
s p
];
1362 state.memused
<- state.memused
- s;
1363 state.uioh#memusedchanged
;
1364 Hashtbl.remove
state.tilemap k
;
1366 Queue.clear
state.tilelru
;
1370 let logcurrently = function
1371 | Idle
-> dolog "Idle"
1372 | Loading
(l
, gen
) ->
1373 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1374 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1376 "Tiling %d[%d,%d] page=%s cs=%s angle"
1377 l
.pageno
col row pageopaque
1378 (colorspace_to_string colorspace
)
1380 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1381 angle gen
conf.angle
state.gen
1383 conf.tilew
conf.tileh
1390 (* dolog "%S" cmds; *)
1393 try String.index cmds ' '
1394 with Not_found
-> -1
1399 let l = String.length cmds
in
1400 let op = String.sub cmds
0 spacepos in
1402 if l - spacepos < 2 then ""
1403 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1411 state.rects
<- state.rects1
;
1412 G.postRedisplay "clearrects";
1415 let n = Scanf.sscanf args
"%u" (fun n -> n) in
1416 state.pagecount
<- n;
1417 state.invalidated
<- state.invalidated
- 1;
1418 begin match state.currently
with
1420 state.currently
<- Idle
;
1421 state.outlines
<- Array.of_list
(List.rev
l)
1424 if state.invalidated
= 0
1427 then G.postRedisplay "continue";
1430 Glut.setWindowTitle args
1437 then showtext ' ' args
1440 let progress, text = Scanf.sscanf args
"%f %n"
1442 f, String.sub args pos
(String.length args
- pos
)
1446 state.progress <- progress;
1447 G.postRedisplay "progress"
1450 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1451 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1452 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1453 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1455 let y = (getpagey pageno) + truncate y0
in
1458 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)]
1461 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1462 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1463 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1464 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1467 (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) :: state.rects1
1470 let pageopaque, t
= Scanf.sscanf args
"%s %f" (fun p t
-> p
, t
) in
1471 begin match state.currently
with
1472 | Loading
(l, gen
) ->
1473 vlog "page %d took %f sec" l.pageno t
;
1474 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1475 begin match state.throttle
with
1477 let preloadedpages =
1479 then preloadlayout state.layout
1484 Set.Make
(struct type t
= int let compare = (-) end) in
1486 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1487 IntSet.empty
preloadedpages
1490 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1491 if not
(IntSet.mem
pageno set)
1493 wcmd "freepage" [`
s opaque
];
1499 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1502 state.currently
<- Idle
;
1505 tilepage l.pageno pageopaque state.layout;
1507 load preloadedpages;
1508 if pagevisible state.layout l.pageno
1509 && layoutready state.layout
1510 then G.postRedisplay "page";
1513 | Some
(layout, _) ->
1514 state.currently
<- Idle
;
1515 tilepage l.pageno pageopaque layout;
1520 dolog "Inconsistent loading state";
1521 logcurrently state.currently
;
1526 let (x, y, opaque
, size
, t
) =
1527 Scanf.sscanf args
"%u %u %s %u %f"
1528 (fun x y p size t
-> (x, y, p
, size
, t
))
1530 begin match state.currently
with
1531 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1532 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1534 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1536 wcmd "freetile" [`
s opaque
];
1537 state.currently
<- Idle
;
1541 puttileopaque l col row gen cs angle opaque size t
;
1542 state.memused
<- state.memused
+ size
;
1543 state.uioh#memusedchanged
;
1545 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1546 opaque
, size
) state.tilelru
;
1548 state.currently
<- Idle
;
1550 && conf.colorspace
= cs
1551 && conf.angle
= angle
1552 && tilevisible state.layout l.pageno x y
1553 then conttiling l.pageno pageopaque;
1555 begin match state.throttle
with
1557 preload state.layout;
1559 && conf.colorspace
= cs
1560 && conf.angle
= angle
1561 && tilevisible state.layout l.pageno x y
1562 then G.postRedisplay "tile nothrottle";
1564 | Some
(layout, y) ->
1565 let ready = layoutready layout in
1569 state.layout <- layout;
1570 state.throttle
<- None
;
1571 G.postRedisplay "throttle";
1578 dolog "Inconsistent tiling state";
1579 logcurrently state.currently
;
1585 Scanf.sscanf args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1587 state.pdims
<- pdim :: state.pdims
1590 let (l, n, t
, h, pos
) =
1591 Scanf.sscanf args
"%u %u %d %u %n" (fun l n t
h pos
-> l, n, t
, h, pos
)
1593 let s = String.sub args pos
(String.length args
- pos
) in
1594 let outline = (s, l, (n, float t
/. float h)) in
1595 begin match state.currently
with
1596 | Outlining outlines
->
1597 state.currently
<- Outlining
(outline :: outlines
)
1599 state.currently
<- Outlining
[outline]
1601 dolog "invalid outlining state";
1602 logcurrently currently
1606 state.docinfo
<- (1, args
) :: state.docinfo
1609 state.docinfo
<- List.rev
state.docinfo
1612 dolog "unknown cmd `%S'" cmds
1615 let now = Unix.gettimeofday
;;
1618 if state.deadline
== nan
then state.deadline
<- now ();
1619 let rec loop delay
=
1622 then max
0.0 (state.deadline
-. now ())
1625 let r, _, _ = Unix.select
[state.csock
] [] [] timeout in
1628 begin match state.autoscroll
with
1629 | Some step
when step
!= 0 ->
1630 let y = state.y + step
in
1634 else if y >= state.maxy then 0 else y
1637 if state.mode
= View
1638 then state.text <- "";
1639 state.deadline
<- state.deadline
+. 0.005;
1642 state.deadline
<- state.deadline
+. delay
;
1646 let cmd = readcmd state.csock
in
1655 let action = function
1656 | HCprev
-> cbget cb ~
-1
1657 | HCnext
-> cbget cb
1
1658 | HCfirst
-> cbget cb ~
-(cb
.rc)
1659 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1660 and cancel
() = cb
.rc <- rc
1664 let search pattern forward
=
1665 if String.length pattern
> 0
1668 match state.layout with
1671 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1674 let b = makecmd "search"
1675 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
1677 Buffer.add_char
b '
,'
;
1678 Buffer.add_string
b pattern
;
1679 Buffer.add_char
b '
\000'
;
1682 writecmd state.csock
cmd;
1685 let intentry text key =
1686 let c = Char.unsafe_chr
key in
1689 let text = addchar text c in
1693 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1697 let textentry text key =
1698 let c = Char.unsafe_chr
key in
1700 | _ when key >= 32 && key < 127 ->
1701 let text = addchar text c in
1705 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
1709 let reqlayout angle proportional
=
1710 match state.throttle
with
1712 if state.invalidated
= 0 then state.anchor <- getanchor ();
1713 conf.angle
<- angle
mod 360;
1714 conf.proportional
<- proportional
;
1716 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
1720 let settrim trimmargins trimfuzz
=
1721 if state.invalidated
= 0 then state.anchor <- getanchor ();
1722 conf.trimmargins
<- trimmargins
;
1723 conf.trimfuzz
<- trimfuzz
;
1724 let x0, y0
, x1
, y1
= trimfuzz
in
1727 `
b conf.trimmargins
;
1733 Hashtbl.iter
(fun _ opaque
->
1734 wcmd "freepage" [`
s opaque
];
1736 Hashtbl.clear
state.pagemap
;
1740 match state.throttle
with
1742 let zoom = max
0.01 zoom in
1743 if zoom <> conf.zoom
1745 state.prevzoom
<- conf.zoom;
1748 then (state.x <- 0; 0.0)
1749 else float state.x /. float state.w
1752 reshape conf.winw
conf.winh
;
1755 let x = relx *. float state.w in
1756 state.x <- truncate
x;
1758 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
1764 let enterbirdseye () =
1765 let zoom = float conf.thumbw
/. float conf.winw
in
1766 let birdseyepageno =
1767 let cy = conf.winh
/ 2 in
1771 let rec fold best
= function
1774 let d = cy - (l.pagedispy
+ l.pagevh/2)
1775 and dbest
= cy - (best
.pagedispy
+ best
.pagevh/2) in
1776 if abs
d < abs dbest
1783 state.mode
<- Birdseye
(
1784 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
1787 conf.presentation <- false;
1788 conf.interpagespace <- 10;
1789 conf.hlinks
<- false;
1791 state.mstate
<- Mnone
;
1792 conf.showall
<- false;
1793 Glut.setCursor
Glut.CURSOR_INHERIT
;
1796 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1801 reshape conf.winw
conf.winh
;
1804 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
1806 conf.zoom <- c.zoom;
1807 conf.presentation <- c.presentation;
1808 conf.interpagespace <- c.interpagespace;
1809 conf.showall
<- c.showall
;
1810 conf.hlinks
<- c.hlinks
;
1814 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1817 reshape conf.winw
conf.winh
;
1818 state.anchor <- if goback
then anchor else (pageno, 0.0);
1821 let togglebirdseye () =
1822 match state.mode
with
1823 | Birdseye vals
-> leavebirdseye vals
true
1824 | View
-> enterbirdseye ()
1828 let upbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
1829 let pageno = max
0 (pageno - 1) in
1830 let rec loop = function
1831 | [] -> gotopage1 pageno 0
1832 | l :: _ when l.pageno = pageno ->
1833 if l.pagedispy
>= 0 && l.pagey = 0
1834 then G.postRedisplay "upbirdseye"
1835 else gotopage1 pageno 0
1836 | _ :: rest
-> loop rest
1839 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
1842 let downbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
1843 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
1844 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
1845 let rec loop = function
1847 let y, h = getpageyh pageno in
1848 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
1850 | l :: _ when l.pageno = pageno ->
1851 if l.pagevh != l.pageh
1852 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
1853 else G.postRedisplay "downbirdseye"
1854 | _ :: rest
-> loop rest
1859 let optentry mode
_ key =
1860 let btos b = if b then "on" else "off" in
1861 let c = Char.unsafe_chr
key in
1865 try conf.scrollstep
<- int_of_string
s with exc
->
1866 state.text <- Printf.sprintf
"bad integer `%s': %s"
1867 s (Printexc.to_string exc
)
1869 TEswitch
("scroll step: ", "", None
, intentry, ondone)
1874 conf.autoscrollstep
<- int_of_string
s;
1875 if state.autoscroll
<> None
1876 then state.autoscroll
<- Some
conf.autoscrollstep
1878 state.text <- Printf.sprintf
"bad integer `%s': %s"
1879 s (Printexc.to_string exc
)
1881 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
1886 let zoom = float (int_of_string
s) /. 100.0 in
1889 state.text <- Printf.sprintf
"bad integer `%s': %s"
1890 s (Printexc.to_string exc
)
1892 TEswitch
("zoom: ", "", None
, intentry, ondone)
1897 conf.thumbw
<- bound (int_of_string
s) 2 4096;
1899 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
1900 begin match mode
with
1902 leavebirdseye beye
false;
1907 state.text <- Printf.sprintf
"bad integer `%s': %s"
1908 s (Printexc.to_string exc
)
1910 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
1915 Some
(int_of_string
s)
1917 state.text <- Printf.sprintf
"bad integer `%s': %s"
1918 s (Printexc.to_string exc
);
1921 | Some angle
-> reqlayout angle
conf.proportional
1924 TEswitch
("rotation: ", "", None
, intentry, ondone)
1927 conf.icase
<- not
conf.icase
;
1928 TEdone
("case insensitive search " ^
(btos conf.icase
))
1931 conf.preload <- not
conf.preload;
1933 TEdone
("preload " ^
(btos conf.preload))
1936 conf.verbose
<- not
conf.verbose
;
1937 TEdone
("verbose " ^
(btos conf.verbose
))
1940 conf.debug
<- not
conf.debug
;
1941 TEdone
("debug " ^
(btos conf.debug
))
1944 conf.maxhfit
<- not
conf.maxhfit
;
1945 state.maxy <- state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
1946 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
1949 conf.crophack
<- not
conf.crophack
;
1950 TEdone
("crophack " ^
btos conf.crophack
)
1953 conf.showall
<- not
conf.showall
;
1954 TEdone
("throttle " ^
btos conf.showall
)
1957 conf.underinfo
<- not
conf.underinfo
;
1958 TEdone
("underinfo " ^
btos conf.underinfo
)
1961 conf.savebmarks
<- not
conf.savebmarks
;
1962 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
1968 match state.layout with
1973 conf.interpagespace <- int_of_string
s;
1974 state.maxy <- calcheight ();
1975 let y = getpagey pageno in
1978 state.text <- Printf.sprintf
"bad integer `%s': %s"
1979 s (Printexc.to_string exc
)
1981 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
1984 reqlayout conf.angle
(not
conf.proportional
);
1985 TEdone
("proportional display " ^
btos conf.proportional
)
1988 settrim (not
conf.trimmargins
) conf.trimfuzz
;
1989 TEdone
("trim margins " ^
btos conf.trimmargins
)
1992 conf.invert
<- not
conf.invert
;
1993 TEdone
("invert colors " ^
btos conf.invert
)
1996 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2000 let maxoutlinerows () = (conf.winh
- !uifontsize - 1) / (!uifontsize + 1);;
2002 class type lvsource
= object
2003 method getitemcount
: int
2004 method getitem
: int -> (string * int)
2005 method hasaction
: int -> bool
2014 method getactive
: int
2015 method getfirst
: int
2016 method getqsearch
: string
2017 method setqsearch
: string -> unit
2021 class virtual lvsourcebase
= object
2022 val mutable m_active
= 0
2023 val mutable m_first
= 0
2024 val mutable m_qsearch
= ""
2025 val mutable m_pan
= 0
2026 method getactive
= m_active
2027 method getfirst
= m_first
2028 method getqsearch
= m_qsearch
2029 method getpan
= m_pan
2030 method setqsearch
s = m_qsearch
<- s
2033 let textentryspecial key = function
2034 | ((c, _, (Some
(action, _) as onhist), onkey
, ondone), mode
) ->
2037 | Glut.KEY_UP
-> action HCprev
2038 | Glut.KEY_DOWN
-> action HCnext
2039 | Glut.KEY_HOME
-> action HCfirst
2040 | Glut.KEY_END
-> action HClast
2043 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2044 G.postRedisplay "special textentry";
2048 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2050 state.mode
<- Textentry
(te
, onleave
);
2053 G.postRedisplay "textentrykeyboard enttext";
2055 match Char.unsafe_chr
key with
2056 | '
\008'
-> (* backspace *)
2057 let len = String.length
text in
2061 G.postRedisplay "textentrykeyboard after cancel";
2064 let s = String.sub
text 0 (len - 1) in
2065 enttext (c, s, opthist
, onkey
, ondone)
2071 G.postRedisplay "textentrykeyboard after confirm"
2073 | '
\007'
(* ctrl-g *)
2074 | '
\027'
-> (* escape *)
2075 if String.length
text = 0
2077 begin match opthist
with
2079 | Some
(_, onhistcancel
) -> onhistcancel
()
2083 G.postRedisplay "textentrykeyboard after cancel2"
2086 enttext (c, "", opthist
, onkey
, ondone)
2089 | '
\127'
-> () (* delete *)
2092 begin match onkey
text key with
2096 G.postRedisplay "textentrykeyboard after confirm2";
2099 enttext (c, text, opthist
, onkey
, ondone);
2104 G.postRedisplay "textentrykeyboard after cancel3"
2107 state.mode
<- Textentry
(te
, onleave
);
2108 G.postRedisplay "textentrykeyboard switch";
2112 let firstof first active
=
2113 let maxrows = maxoutlinerows () in
2114 if first
> active
|| abs
(first
- active
) > maxrows - 1
2115 then max
0 (active
- (maxrows/2))
2119 class listview ~
(source
:lvsource
) ~trusted
=
2120 let coe s = (s :> uioh
) in
2122 val m_pan
= source#getpan
2123 val m_first
= source#getfirst
2124 val m_active
= source#getactive
2125 val m_qsearch
= source#getqsearch
2126 val m_prev_uioh
= state.uioh
2128 method private elemunder
y =
2129 let n = y / (!uifontsize+1) in
2130 if m_first
+ n < source#getitemcount
2132 if source#hasaction
(m_first
+ n)
2133 then Some
(m_first
+ n)
2140 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2141 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2142 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2143 GlDraw.color
(1., 1., 1.);
2144 Gl.enable `texture_2d
;
2145 let fs = !uifontsize in
2147 let wx = measurestr
fs "w" in
2148 let tabx = 30.0*.wx +. float (m_pan
* fs) in
2150 if (row - m_first
) * nfs > conf.winh
2153 if row >= 0 && row < source#getitemcount
2155 let (s, level
) = source#getitem
row in
2156 let y = (row - m_first
) * nfs in
2157 let x = 5 + fs*(max
0 (level
+m_pan
)) in
2160 Gl.disable `texture_2d
;
2161 GlDraw.polygon_mode `both `line
;
2162 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2163 GlDraw.rect (1., float (y + 1))
2164 (float (conf.winw
- 1), float (y + fs + 3));
2165 GlDraw.polygon_mode `both `fill
;
2166 GlDraw.color
(1., 1., 1.);
2167 Gl.enable `texture_2d
;
2170 let drawtabularstring x s =
2173 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2176 let len = String.length
s - tabpos - 1 in
2177 let s1 = String.sub
s 0 tabpos
2178 and s2
= String.sub
s (tabpos + 1) len in
2179 let xx = wx +. drawstring1 fs x (y + !uifontsize+1) s1 in
2180 let x = truncate
(max
xx tabx) in
2181 drawstring1 nfs x (y + (!uifontsize+1)) s2
2183 drawstring1 fs x (y + nfs) s
2185 drawstring1 fs x (y + nfs) s
2187 let _w = drawtabularstring (x + m_pan
*nfs) s in
2194 Gl.disable `texture_2d
;
2196 method private key1
key =
2197 let set active first qsearch
=
2198 coe {< m_active
= active
; m_first
= first
; m_qsearch
= qsearch
>}
2200 let search active pattern incr
=
2203 if n >= 0 && n < source#getitemcount
2205 let s, _ = source#getitem
n in
2207 (try ignore
(Str.search_forward
re s 0); true
2208 with Not_found
-> false)
2210 else loop (n + incr
)
2217 let re = Str.regexp_case_fold pattern
in
2224 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2225 let incr = if key = 18 then -1 else 1 in
2227 match search (m_active
+ incr) m_qsearch
incr with
2229 state.text <- m_qsearch ^
" [not found]";
2232 state.text <- m_qsearch
;
2233 active, firstof m_first
active
2235 G.postRedisplay "listview ctrl-r/s";
2236 set active first m_qsearch
;
2238 | 8 -> (* backspace *)
2239 let len = String.length m_qsearch
in
2246 G.postRedisplay "listview empty qsearch";
2247 set m_active m_first
"";
2250 let qsearch = String.sub m_qsearch
0 (len - 1) in
2252 match search m_active
qsearch ~
-1 with
2254 state.text <- qsearch ^
" [not found]";
2257 state.text <- qsearch;
2258 active, firstof m_first
active
2260 G.postRedisplay "listview backspace qsearch";
2261 set active first
qsearch
2264 | _ when key >= 32 && key < 127 ->
2265 let pattern = addchar m_qsearch
(Char.chr
key) in
2267 match search m_active
pattern 1 with
2269 state.text <- pattern ^
" [not found]";
2272 state.text <- pattern;
2273 active, firstof m_first
active
2275 G.postRedisplay "listview qsearch add";
2276 set active first
pattern;
2278 | 27 -> (* escape *)
2280 if String.length m_qsearch
= 0
2282 G.postRedisplay "list view escape";
2285 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2287 | None
-> m_prev_uioh
2292 G.postRedisplay "list view kill qsearch";
2293 source#setqsearch
"";
2294 coe {< m_qsearch
= "" >}
2299 let self = {< m_qsearch
= "" >} in
2300 source#setqsearch
"";
2302 G.postRedisplay "listview enter";
2303 if m_active
>= 0 && m_active
< source#getitemcount
2305 source#exit
(coe self) false m_active m_first m_pan
"";
2308 source#exit
(coe self) true m_active m_first m_pan
"";
2311 begin match opt with
2312 | None
-> m_prev_uioh
2316 | 127 -> (* delete *)
2319 | _ -> dolog "unknown key %d" key; coe self
2321 method private special1
key =
2322 let maxrows = maxoutlinerows () in
2323 let itemcount = source#getitemcount
in
2324 let find start
incr =
2326 if i
= -1 || i
= itemcount
2329 if source#hasaction i
2331 else find (i
+ incr)
2336 let set active first
=
2337 let first = bound first 0 (itemcount - maxrows) in
2339 coe {< m_active
= active; m_first
= first >}
2342 let isvisible first n = n >= first && n - first <= maxrows in
2344 let incr1 = if incr > 0 then 1 else -1 in
2345 if isvisible m_first m_active
2348 let next = m_active
+ incr in
2350 if next < 0 || next >= itemcount
2352 else find next incr1
2354 if next = -1 || abs
(m_active
- next) > maxrows
2360 let first = m_first
+ incr in
2361 let first = bound first 0 (itemcount - 1) in
2363 let next = m_active
+ incr in
2364 let next = bound next 0 (itemcount - 1) in
2367 let active = if next = -1 then m_active
else next in
2370 let first = min
next m_first
in
2373 let first = m_first
+ incr in
2374 let first = bound first 0 (itemcount - 1) in
2376 let next = m_active
+ incr in
2377 let next = bound next 0 (itemcount - 1) in
2378 let next = find next incr1 in
2379 if next = -1 || abs
(m_active
- first) > maxrows
2385 G.postRedisplay "listview navigate";
2388 begin match key with
2389 | Glut.KEY_UP
-> navigate ~
-1
2390 | Glut.KEY_DOWN
-> navigate 1
2391 | Glut.KEY_PAGE_UP
-> navigate ~
-maxrows
2392 | Glut.KEY_PAGE_DOWN
-> navigate maxrows
2396 G.postRedisplay "listview right";
2397 coe {< m_pan
= m_pan
- 1 >}
2401 G.postRedisplay "listview left";
2402 coe {< m_pan
= m_pan
+ 1 >}
2405 let active = find 0 1 in
2406 G.postRedisplay "listview home";
2410 let first = max
0 (itemcount - maxrows) in
2411 let active = find (itemcount - 1) ~
-1 in
2412 G.postRedisplay "listview end";
2419 match state.mode
with
2420 | Textentry te
-> textentrykeyboard key te
; coe self
2421 | _ -> self#key1
key
2423 method special
key =
2424 match state.mode
with
2425 | Textentry te
-> textentryspecial key te
; coe self
2426 | _ -> self#special1
key
2428 method button button bstate
_ y =
2431 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2432 begin match self#elemunder
y with
2434 G.postRedisplay "listview click";
2435 source#exit
(coe {< m_active
= n >}) false n m_first m_pan m_qsearch
2439 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2440 let len = source#getitemcount
in
2442 if m_first
+ maxoutlinerows () >= len
2446 let first = m_first
+ (if n == 3 then -1 else 1) in
2447 bound first 0 (len - 1)
2449 G.postRedisplay "listview wheel";
2450 Some
(coe {< m_first
= first >})
2455 | None
-> m_prev_uioh
2458 method motion
_ _ = coe self
2460 method pmotion
_ y =
2462 match self#elemunder
y with
2463 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
2464 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
2468 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
2473 method memusedchanged
= ()
2476 class outlinelistview ~source
: uioh
=
2477 let coe o = (o :> uioh
) in
2479 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
2483 | 14 -> (* ctrl-n *)
2484 source#narrow m_qsearch
;
2485 G.postRedisplay "outline ctrl-n";
2486 coe {< m_first
= 0; m_active
= 0 >}
2488 | 21 -> (* ctrl-u *)
2490 G.postRedisplay "outline ctrl-u";
2491 coe {< m_first
= 0; m_active
= 0 >}
2493 | 12 -> (* ctrl-l *)
2494 let first = m_active
- (maxoutlinerows () / 2) in
2495 G.postRedisplay "outline ctrl-l";
2496 coe {< m_first
= first >}
2498 | 127 -> (* delete *)
2499 source#remove m_active
;
2500 G.postRedisplay "outline delete";
2501 let active = max
0 (m_active
-1) in
2502 coe {< m_first
= firstof m_first
active; m_active
= active >}
2504 | key -> super#
key key
2506 method special
key =
2507 let maxrows = maxoutlinerows () in
2508 let calcfirst first active =
2511 let rows = active - first in
2512 if rows > maxrows then active - maxrows else first
2516 let active = m_active
+ incr in
2517 let active = bound active 0 (source#getitemcount
- 1) in
2518 let first = calcfirst m_first
active in
2519 G.postRedisplay "special outline navigate";
2520 coe {< m_active
= active; m_first
= first >}
2522 let updownlevel incr =
2523 let len = source#getitemcount
in
2524 let _, curlevel
= source#getitem m_active
in
2526 if i
= len then i
-1 else if i
= -1 then 0 else
2527 let _, l = source#getitem i
in
2528 if l != curlevel
then i
else flow (i
+incr)
2530 let active = flow m_active
in
2531 let first = calcfirst m_first
active in
2532 G.postRedisplay "special outline updownlevel";
2533 {< m_active
= active; m_first
= first >}
2536 | Glut.KEY_UP
-> navigate ~
-1
2537 | Glut.KEY_DOWN
-> navigate 1
2538 | Glut.KEY_PAGE_UP
-> navigate ~
-maxrows
2539 | Glut.KEY_PAGE_DOWN
-> navigate maxrows
2543 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2545 G.postRedisplay "special outline right";
2546 {< m_pan
= m_pan
+ 1 >}
2554 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2556 G.postRedisplay "special outline left";
2557 {< m_pan
= m_pan
- 1 >}
2559 else updownlevel ~
-1
2564 G.postRedisplay "special outline home";
2565 coe {< m_first
= 0; m_active
= 0 >}
2568 let active = source#getitemcount
- 1 in
2569 let first = max
0 (active - maxrows) in
2570 G.postRedisplay "special outline end";
2571 coe {< m_active
= active; m_first
= first >}
2573 | _ -> super#special
key
2576 let outlinesource usebookmarks
=
2579 inherit lvsourcebase
2580 val mutable m_items
= empty
2581 val mutable m_orig_items
= empty
2582 val mutable m_prev_items
= empty
2583 val mutable m_narrow_pattern
= ""
2584 val mutable m_hadremovals
= false
2586 method getitemcount
= Array.length m_items
+ (if m_hadremovals
then 1 else 0)
2589 if n == Array.length m_items
&& m_hadremovals
2591 ("[Confirm removal]", 0)
2593 let s, n, _ = m_items
.(n) in
2596 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
2597 ignore
(uioh
, first, pan
, qsearch);
2598 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
2600 if String.length m_narrow_pattern
= 0
2606 if not
confrimremoval
2608 let _, _, anchor = m_items
.(active) in
2613 state.bookmarks
<- Array.to_list m_items
;
2614 m_orig_items
<- m_items
;
2617 else m_items
<- items;
2620 method hasaction
_ = true
2623 if Array.length m_items
!= Array.length m_orig_items
2624 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
2627 method narrow
pattern =
2628 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
2632 let rec loop accu n =
2635 m_narrow_pattern
<- pattern;
2636 m_items
<- Array.of_list
accu
2639 let (s, _, _) as o = m_items
.(n) in
2641 if (try ignore
(Str.search_forward
re s 0); true
2642 with Not_found
-> false)
2648 loop [] (Array.length m_items
- 1)
2653 then Array.of_list
state.bookmarks
2656 m_items
<- m_orig_items
2661 if m
>= 0 && m
< Array.length m_items
2663 m_hadremovals
<- true;
2664 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
2665 let n = if n >= m
then n+1 else n in
2670 method reset
pageno items =
2671 m_hadremovals
<- false;
2672 if m_orig_items
== empty || m_prev_items
!= items
2674 m_orig_items
<- items;
2675 if String.length m_narrow_pattern
= 0
2676 then m_items
<- items;
2678 m_prev_items
<- items;
2680 let rec loop n best bestd
=
2681 if n = Array.length m_items
2684 let (_, _, (outlinepageno
, _)) = m_items
.(n) in
2685 let d = abs
(outlinepageno
- pageno) in
2688 else loop (n+1) best bestd
2693 m_first
<- firstof m_first
active
2697 let enterselector usebookmarks
=
2698 let source = outlinesource usebookmarks
in
2702 then Array.of_list
state.bookmarks
2705 if Array.length
outlines = 0
2707 showtext ' ' errmsg
;
2710 state.text <- source#greetmsg
;
2711 Glut.setCursor
Glut.CURSOR_INHERIT
;
2713 match state.layout with
2715 | {pageno=pageno} :: _ -> pageno
2717 source#reset
pageno outlines;
2718 state.uioh
<- new outlinelistview ~
source;
2719 G.postRedisplay "enter selector";
2723 let enteroutlinemode =
2724 let f = enterselector false in
2725 fun ()-> f "Document has no outline";
2728 let enterbookmarkmode =
2729 let f = enterselector true in
2730 fun () -> f "Document has no bookmarks (yet)";
2733 let color_of_string s =
2734 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
2735 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
2739 let color_to_string (r, g
, b) =
2740 let r = truncate
(r *. 256.0)
2741 and g
= truncate
(g
*. 256.0)
2742 and b = truncate
(b *. 256.0) in
2743 Printf.sprintf
"%d/%d/%d" r g
b
2746 let irect_of_string s =
2747 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0,y0
,x1
,y1
))
2750 let irect_to_string (x0,y0
,x1
,y1
) =
2751 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
2754 let makecheckers () =
2755 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
2757 converted by Issac Trotts. July 25, 2002 *)
2758 let image_height = 64
2759 and image_width
= 64 in
2763 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height in
2764 for i
= 0 to image_width
- 1 do
2765 for j
= 0 to image_height - 1 do
2766 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
2767 (if (i
land 8 ) lxor (j
land 8) = 0
2768 then [|255;255;255|] else [|200;200;200|])
2773 let image = make_image () in
2774 let id = GlTex.gen_texture
() in
2775 GlTex.bind_texture `texture_2d
id;
2776 GlPix.store
(`unpack_alignment
1);
2777 GlTex.image2d
image;
2778 List.iter
(GlTex.parameter ~target
:`texture_2d
)
2781 `mag_filter `nearest
;
2782 `min_filter `nearest
];
2786 let setcheckers enabled
=
2787 match state.texid
with
2789 if enabled
then state.texid
<- Some
(makecheckers ())
2794 GlTex.delete_texture texid
;
2795 state.texid
<- None
;
2799 let int_of_string_with_suffix s =
2800 let l = String.length
s in
2804 let suffix = Char.lowercase
s.[l-1] in
2806 | 'k'
-> String.sub
s 0 (l-1), 10
2807 | 'm'
-> String.sub
s 0 (l-1), 20
2808 | 'g'
-> String.sub
s 0 (l-1), 30
2812 let n = int_of_string
s1 in
2813 let m = n lsl shift
in
2815 then raise
(Failure
"value too large")
2819 let string_with_suffix_of_int n =
2827 if n land ((1 lsl 20) - 1) = 0
2830 if n land ((1 lsl 10) - 1) = 0
2837 let h = n mod 1000 in
2840 then string_of_int
h ^
s
2842 let s = Printf.sprintf
"_%03d%s" h s in
2849 let describe_location () =
2851 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
2853 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
2854 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
2858 else (100. *. (float state.y /. float maxy))
2862 Printf.sprintf
"page %d of %d [%.2f%%]"
2863 (fn+1) state.pagecount
percent
2866 "pages %d-%d of %d [%.2f%%]"
2867 (fn+1) (ln
+1) state.pagecount
percent
2870 let rec enterinfomode =
2871 let btos b = if b then "\xe2\x88\x9a" else "" in
2872 let showextended = ref false in
2873 let leave mode
= function
2874 | Confirm
-> state.mode
<- mode
2875 | Cancel
-> state.mode
<- mode
in
2878 val mutable m_first_time
= true
2879 val mutable m_l
= []
2880 val mutable m_a
= [||]
2881 val mutable m_prev_uioh
= nouioh
2882 val mutable m_prev_mode
= View
2884 inherit lvsourcebase
2886 method reset prev_mode prev_uioh
=
2887 m_a
<- Array.of_list
(List.rev m_l
);
2889 m_prev_mode
<- prev_mode
;
2890 m_prev_uioh
<- prev_uioh
;
2894 if n >= Array.length m_a
2898 | _, _, _, Action
_ -> m_active
<- n
2902 m_first_time
<- false;
2905 method int name get
set =
2907 (name
, `
int get
, 1, Action
(
2910 try set (int_of_string
s)
2912 state.text <- Printf.sprintf
"bad integer `%s': %s"
2913 s (Printexc.to_string exn
)
2916 let te = name ^
": ", "", None
, intentry, ondone in
2917 state.mode
<- Textentry
(te, leave m_prev_mode
);
2921 method int_with_suffix name get
set =
2923 (name
, `intws get
, 1, Action
(
2926 try set (int_of_string_with_suffix s)
2928 state.text <- Printf.sprintf
"bad integer `%s': %s"
2929 s (Printexc.to_string exn
)
2933 name ^
": ", "", None
, intentry_with_suffix, ondone
2935 state.mode
<- Textentry
(te, leave m_prev_mode
);
2939 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
2941 (name
, `
bool (btos, get
), offset
, Action
(
2948 method color name get
set =
2950 (name
, `color get
, 1, Action
(
2952 let invalid = (nan
, nan
, nan
) in
2955 try color_of_string s
2957 state.text <- Printf.sprintf
"bad color `%s': %s"
2958 s (Printexc.to_string exn
);
2964 let te = name ^
": ", "", None
, textentry, ondone in
2965 state.text <- color_to_string (get
());
2966 state.mode
<- Textentry
(te, leave m_prev_mode
);
2970 method string name get
set =
2972 (name
, `
string get
, 1, Action
(
2974 let ondone s = set s in
2975 let te = name ^
": ", "", None
, textentry, ondone in
2976 state.mode
<- Textentry
(te, leave m_prev_mode
);
2980 method colorspace name get
set =
2982 (name
, `
string get
, 1, Action
(
2985 let vals = [| "rgb"; "bgr"; "gray" |] in
2987 inherit lvsourcebase
2990 m_active
<- int_of_colorspace conf.colorspace
;
2993 method getitemcount
= Array.length
vals
2994 method getitem
n = (vals.(n), 0)
2995 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
2996 ignore
(uioh
, first, pan
, qsearch);
2997 if not cancel
then set active;
2999 method hasaction
_ = true
3003 new listview ~
source ~trusted
:true
3006 method caption
s offset
=
3007 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3009 method caption2
s f offset
=
3010 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3012 method getitemcount
= Array.length m_a
3015 let tostr = function
3016 | `
int f -> string_of_int
(f ())
3017 | `intws
f -> string_with_suffix_of_int (f ())
3019 | `color
f -> color_to_string (f ())
3020 | `
bool (btos, f) -> btos (f ())
3023 let name, t
, offset
, _ = m_a
.(n) in
3024 ((let s = tostr t
in
3025 if String.length
s > 0
3026 then Printf.sprintf
"%s\t%s" name s
3030 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3034 m_qsearch
<- qsearch;
3036 match m_a
.(active) with
3037 | _, _, _, Action
f -> f uioh
3049 method hasaction
n =
3051 | _, _, _, Action
_ -> true
3056 let sep () = src#caption
"" 0 in
3057 let colorp name get
set =
3059 (fun () -> color_to_string (get
()))
3062 let c = color_of_string v in
3065 state.text <- Printf.sprintf
"bad color `%s': %s"
3066 v (Printexc.to_string exn
);
3069 let oldmode = state.mode
in
3070 let birdseye = isbirdseye state.mode
in
3073 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3075 src#
bool "presentation mode"
3076 (fun () -> conf.presentation)
3078 conf.presentation <- v;
3079 state.anchor <- getanchor ();
3082 src#
bool "ignore case in searches"
3083 (fun () -> conf.icase
)
3084 (fun v -> conf.icase
<- v);
3087 (fun () -> conf.preload)
3088 (fun v -> conf.preload <- v);
3091 (fun () -> conf.showall
)
3092 (fun v -> conf.showall
<- v);
3094 src#
bool "highlight links"
3095 (fun () -> conf.hlinks
)
3096 (fun v -> conf.hlinks
<- v);
3098 src#
bool "under info"
3099 (fun () -> conf.underinfo
)
3100 (fun v -> conf.underinfo
<- v);
3102 src#
bool "persistent bookmarks"
3103 (fun () -> conf.savebmarks
)
3104 (fun v -> conf.savebmarks
<- v);
3106 src#
bool "proportional display"
3107 (fun () -> conf.proportional
)
3108 (fun v -> reqlayout conf.angle
v);
3110 src#
bool "trim margins"
3111 (fun () -> conf.trimmargins
)
3112 (fun v -> settrim v conf.trimfuzz
);
3114 src#
bool "persistent location"
3115 (fun () -> conf.jumpback
)
3116 (fun v -> conf.jumpback
<- v);
3119 src#
int "vertical margin"
3120 (fun () -> conf.interpagespace)
3122 conf.interpagespace <- n;
3124 match state.layout with
3129 state.maxy <- calcheight ();
3130 let y = getpagey pageno in
3135 (fun () -> conf.pagebias
)
3136 (fun v -> conf.pagebias
<- v);
3138 src#
int "scroll step"
3139 (fun () -> conf.scrollstep
)
3140 (fun n -> conf.scrollstep
<- n);
3142 src#
int "auto scroll step"
3144 match state.autoscroll
with
3146 | _ -> conf.autoscrollstep
)
3148 if state.autoscroll
<> None
3149 then state.autoscroll
<- Some
n;
3150 conf.autoscrollstep
<- n);
3153 (fun () -> truncate
(conf.zoom *. 100.))
3154 (fun v -> setzoom ((float v) /. 100.));
3157 (fun () -> conf.angle
)
3158 (fun v -> reqlayout v conf.proportional
);
3160 src#
int "scroll bar width"
3161 (fun () -> state.scrollw
)
3165 reshape conf.winw
conf.winh
;
3168 src#
int "scroll handle height"
3169 (fun () -> conf.scrollh
)
3170 (fun v -> conf.scrollh
<- v;);
3172 src#
int "thumbnail width"
3173 (fun () -> conf.thumbw
)
3175 conf.thumbw
<- min
4096 v;
3178 leavebirdseye beye
false;
3184 src#caption
"Presentation mode" 0;
3185 src#
bool "scrollbar visible"
3186 (fun () -> conf.scrollbarinpm
)
3188 if v != conf.scrollbarinpm
3190 conf.scrollbarinpm
<- v;
3191 if conf.presentation
3193 state.scrollw
<- if v then conf.scrollbw
else 0;
3194 reshape conf.winw
conf.winh
;
3200 src#caption
"Pixmap cache" 0;
3201 src#int_with_suffix
"size (advisory)"
3202 (fun () -> conf.memlimit
)
3203 (fun v -> conf.memlimit
<- v);
3206 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3207 (string_with_suffix_of_int state.memused
)
3208 (Hashtbl.length
state.tilemap
)) 1;
3211 src#caption
"Layout" 0;
3212 src#caption2
"Dimension"
3214 Printf.sprintf
"%dx%d (virtual %dx%d)"
3220 src#caption2
"Position" (fun () ->
3221 Printf.sprintf
"%dx%d" state.x state.y
3224 src#caption2
"Visible" (fun () -> describe_location ()) 1
3228 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3229 "Save these parameters as global defaults at exit"
3230 (fun () -> conf.bedefault
)
3231 (fun v -> conf.bedefault
<- v)
3235 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3236 src#
bool ~offset
:0 ~
btos "Extended parameters"
3237 (fun () -> !showextended)
3238 (fun v -> showextended := v; enterinfomode ());
3242 (fun () -> conf.checkers
)
3243 (fun v -> conf.checkers
<- v; setcheckers v);
3245 (fun () -> conf.verbose
)
3246 (fun v -> conf.verbose
<- v);
3247 src#
bool "invert colors"
3248 (fun () -> conf.invert
)
3249 (fun v -> conf.invert
<- v);
3251 (fun () -> conf.maxhfit
)
3252 (fun v -> conf.maxhfit
<- v);
3253 src#
string "uri launcher"
3254 (fun () -> conf.urilauncher
)
3255 (fun v -> conf.urilauncher
<- v);
3256 src#
string "tile size"
3257 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3260 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3261 conf.tileh
<- max
64 w;
3262 conf.tilew
<- max
64 h;
3265 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3266 v (Printexc.to_string exn
));
3267 src#
int "anti-aliasing level"
3268 (fun () -> conf.aalevel
)
3270 conf.aalevel
<- bound v 0 8;
3271 state.anchor <- getanchor ();
3272 opendoc state.path
state.password
;
3274 src#
int "ui font size"
3275 (fun () -> !uifontsize)
3276 (fun v -> uifontsize := bound v 5 100);
3277 colorp "background color"
3278 (fun () -> conf.bgcolor
)
3279 (fun v -> conf.bgcolor
<- v);
3280 src#
bool "crop hack"
3281 (fun () -> conf.crophack
)
3282 (fun v -> conf.crophack
<- v);
3283 src#
string "trim fuzz"
3284 (fun () -> irect_to_string conf.trimfuzz
)
3287 conf.trimfuzz
<- irect_of_string v;
3289 then settrim true conf.trimfuzz
;
3291 state.text <- Printf.sprintf
"bad irect `%s': %s"
3292 v (Printexc.to_string exn
)
3294 src#colorspace
"color space"
3295 (fun () -> colorspace_to_string conf.colorspace
)
3297 conf.colorspace
<- colorspace_of_int v;
3304 src#caption
"Document" 0;
3305 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3307 src#reset
state.mode
state.uioh;
3308 let source = (src :> lvsource
) in
3309 state.uioh <- object
3310 inherit listview ~
source ~trusted
:true
3311 val mutable m_prevmemused
= 0
3312 method memusedchanged
=
3313 if m_prevmemused
!= state.memused
3315 m_prevmemused
<- state.memused
;
3316 G.postRedisplay "memusedchanged";
3319 G.postRedisplay "info";
3325 inherit lvsourcebase
3326 method getitemcount
= Array.length
state.help
3328 let s, n, _ = state.help
.(n) in
3331 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3335 m_qsearch
<- qsearch;
3336 match state.help
.(active) with
3337 | _, _, Action
f -> Some
(f uioh)
3347 method hasaction
n =
3348 match state.help
.(n) with
3349 | _, _, Action
_ -> true
3356 state.uioh <- new listview ~
source ~trusted
:true;
3357 G.postRedisplay "help";
3360 let quickbookmark ?title
() =
3361 match state.layout with
3367 let sec = Unix.gettimeofday
() in
3368 let tm = Unix.localtime
sec in
3369 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
3373 (tm.Unix.tm_year
+ 1900)
3376 | Some
title -> title
3379 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
3384 state.fullscreen
<- None
;
3385 Glut.reshapeWindow
w h;
3388 let viewkeyboard key =
3390 let mode = state.mode in
3391 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
3394 G.postRedisplay "view:enttext"
3396 let c = Char.chr
key in
3398 | '
\027'
| 'q'
-> (* escape *)
3399 begin match state.mstate
with
3401 state.mstate
<- Mnone
;
3402 Glut.setCursor
Glut.CURSOR_INHERIT
;
3403 G.postRedisplay "kill zoom rect";
3408 | '
\008'
-> (* backspace *)
3409 let y = getnav ~
-1 in
3410 gotoy_and_clear_text y
3418 G.postRedisplay "dehighlight";
3421 let ondone isforw
s =
3422 cbput state.hists
.pat
s;
3423 state.searchpattern
<- s;
3426 let s = String.create
1 in
3428 enttext (s, "", Some
(onhist state.hists
.pat
),
3429 textentry, ondone (c ='
/'
))
3431 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3432 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3433 setzoom (conf.zoom +. incr)
3438 try int_of_string
s with exc
->
3439 state.text <- Printf.sprintf
"bad integer `%s': %s"
3440 s (Printexc.to_string exc
);
3446 state.text <- "page bias is now " ^ string_of_int
n;
3449 enttext ("page bias: ", "", None
, intentry, ondone)
3451 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3452 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3453 setzoom (max
0.01 (conf.zoom -. decr))
3456 let ondone msg
= state.text <- msg
in
3458 "option [acfhilpstvAPRSZTI]: ", "", None
,
3459 optentry state.mode, ondone
3462 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3465 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3466 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
3470 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3476 try int_of_string
s with exc
->
3477 state.text <- Printf.sprintf
"bad integer `%s': %s"
3478 s (Printexc.to_string exc
);
3484 cbput state.hists
.pag
(string_of_int
n);
3485 gotoy_and_clear_text (getpagey (n + conf.pagebias
- 1))
3488 let pageentry text key =
3489 match Char.unsafe_chr
key with
3490 | 'g'
-> TEdone
text
3491 | _ -> intentry text key
3493 let text = "x" in text.[0] <- c;
3494 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
3497 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
3498 reshape conf.winw
conf.winh
;
3501 conf.hlinks
<- not
conf.hlinks
;
3502 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
3503 G.postRedisplay "toggle highlightlinks";
3506 begin match state.autoscroll
with
3508 conf.autoscrollstep
<- step
;
3509 state.autoscroll
<- None
3511 if conf.autoscrollstep
= 0
3512 then state.autoscroll
<- Some
1
3513 else state.autoscroll
<- Some
conf.autoscrollstep
3517 conf.presentation <- not
conf.presentation;
3518 if conf.presentation
3520 if not
conf.scrollbarinpm
3521 then state.scrollw
<- 0;
3524 state.scrollw
<- conf.scrollbw
;
3526 showtext ' '
("presentation mode " ^
3527 if conf.presentation then "on" else "off");
3528 state.anchor <- getanchor ();
3532 begin match state.fullscreen
with
3534 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
3537 state.fullscreen
<- None
;
3542 gotoy_and_clear_text 0
3545 gotopage1 (state.pagecount
- 1) 0
3548 search state.searchpattern
true
3551 search state.searchpattern
false
3554 begin match state.layout with
3557 gotoy_and_clear_text (getpagey l.pageno)
3561 begin match List.rev
state.layout with
3564 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
3565 gotoy_and_clear_text (getpagey pageno)
3568 | '
\127'
-> (* del *)
3569 begin match state.layout with
3572 let pageno = max
0 (l.pageno-1) in
3573 gotoy_and_clear_text (getpagey pageno)
3577 showtext ' '
(describe_location ());
3580 begin match state.layout with
3583 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
3588 enterbookmarkmode ()
3598 match state.layout with
3601 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
3605 enttext ("bookmark: ", "", None
, textentry, ondone)
3609 showtext ' '
"Quick bookmark added";
3612 begin match state.layout with
3614 let rect = getpdimrect
l.pagedimno
in
3618 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
3619 truncate
(1.2 *. (rect.(3) -. rect.(0))))
3621 (truncate
(rect.(1) -. rect.(0)),
3622 truncate
(rect.(3) -. rect.(0)))
3624 let w = truncate
((float w)*.conf.zoom)
3625 and h = truncate
((float h)*.conf.zoom) in
3628 state.anchor <- getanchor ();
3629 doreshape (w + state.scrollw
) (h + conf.interpagespace)
3631 G.postRedisplay "z";
3636 | '
\000'
-> (* ctrl-2 *)
3637 let maxw = getmaxw
() in
3639 then setzoom (maxw /. float conf.winw
)
3642 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
3646 bound (state.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
3648 G.postRedisplay "brightness";
3651 begin match state.mode with
3652 | Birdseye beye
-> upbirdseye beye
3653 | _ -> gotoy (clamp (-conf.scrollstep
))
3657 begin match state.mode with
3658 | Birdseye beye
-> downbirdseye beye
3659 | _ -> gotoy (clamp conf.scrollstep
)
3663 state.anchor <- getanchor ();
3664 opendoc state.path
state.password
3666 | '
v'
when conf.debug
->
3669 match getopaque l.pageno with
3672 let x0, y0
, x1
, y1
= pagebbox opaque
in
3673 let a,b = float x0, float y0
in
3674 let c,d = float x1
, float y0
in
3675 let e,f = float x1
, float y1
in
3676 let h,j
= float x0, float y1
in
3677 let rect = (a,b,c,d,e,f,h,j
) in
3679 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
3681 G.postRedisplay "v";
3684 vlog "huh? %d %c" key (Char.chr
key);
3687 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
3689 | 27 -> (* escape *)
3690 leavebirdseye beye
true
3692 | 12 -> (* ctrl-l *)
3693 let y, h = getpageyh pageno in
3694 let top = (conf.winh
- h) / 2 in
3695 gotoy (max
0 (y - top))
3698 leavebirdseye beye
false
3704 let keyboard ~
key ~
x ~
y =
3707 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
3708 then wcmd "interrupt" []
3709 else state.uioh <- state.uioh#
key key
3712 let birdseyespecial key ((conf, leftx
, _, hooverpageno
, anchor) as beye
) =
3714 | Glut.KEY_UP
-> upbirdseye beye
3715 | Glut.KEY_DOWN
-> downbirdseye beye
3717 | Glut.KEY_PAGE_UP
->
3718 begin match state.layout with
3722 state.mode <- Birdseye
(
3723 conf, leftx
, l.pageno, hooverpageno
, anchor
3725 gotopage1 l.pageno 0;
3728 let layout = layout (state.y-conf.winh
) conf.winh
in
3730 | [] -> gotoy (clamp (-conf.winh
))
3732 state.mode <- Birdseye
(
3733 conf, leftx
, l.pageno, hooverpageno
, anchor
3735 gotopage1 l.pageno 0
3738 | [] -> gotoy (clamp (-conf.winh
))
3741 | Glut.KEY_PAGE_DOWN
->
3742 begin match List.rev
state.layout with
3744 let layout = layout (state.y + conf.winh
) conf.winh
in
3745 begin match layout with
3747 let incr = l.pageh
- l.pagevh in
3752 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
3754 G.postRedisplay "birdseye pagedown";
3756 else gotoy (clamp (incr + conf.interpagespace*2));
3760 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
3761 gotopage1 l.pageno 0;
3764 | [] -> gotoy (clamp conf.winh
)
3768 state.mode <- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
3772 let pageno = state.pagecount
- 1 in
3773 state.mode <- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3774 if not
(pagevisible state.layout pageno)
3777 match List.rev
state.pdims
with
3779 | (_, _, h, _) :: _ -> h
3781 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
3782 else G.postRedisplay "birdseye end";
3786 let setautoscrollspeed step goingdown
=
3787 let incr = max
1 ((abs step
) / 2) in
3788 let incr = if goingdown
then incr else -incr in
3789 let astep = step
+ incr in
3790 state.autoscroll
<- Some
astep;
3793 let special ~
key ~
x ~
y =
3796 state.uioh <- state.uioh#
special key
3801 match state.mode with
3802 | Textentry
_ -> scalecolor 0.4
3803 | View
-> scalecolor 1.0
3804 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
3805 if l.pageno = hooverpageno
3808 if l.pageno = pageno
3814 begin match getopaque l.pageno with
3816 if tileready l l.pagex l.pagey
3818 let x = l.pagedispx
- l.pagex
3819 and y = l.pagedispy
- l.pagey in
3820 postprocess opaque
conf.hlinks
x y;
3827 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3828 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
3829 let sh = float conf.winh
/. sh in
3830 let sh = max
sh (float conf.scrollh
) in
3835 else float y /. float maxy
3837 let position = (float conf.winh
-. sh) *. percent in
3840 if position +. sh > float conf.winh
3841 then float conf.winh
-. sh
3848 let winw = conf.winw - state.scrollw
- 1 in
3849 let fwinw = float winw in
3851 let sw = fwinw /. float state.w in
3852 let sw = fwinw *. sw in
3853 max
sw (float conf.scrollh
)
3856 let f = state.w+winw in
3857 let r = float (winw-x) /. float f in
3858 let p = fwinw *. r in
3862 if position +. sw > fwinw
3863 then fwinw -. position
3869 let scrollindicator () =
3870 GlDraw.color (0.64 , 0.64, 0.64);
3872 (float (conf.winw - state.scrollw
), 0.)
3873 (float conf.winw, float conf.winh
)
3876 (0., float (conf.winh
- state.hscrollh))
3877 (float (conf.winw - state.scrollw
- 1), float conf.winh
)
3879 GlDraw.color (0.0, 0.0, 0.0);
3881 let position, sh = scrollph state.y in
3883 (float (conf.winw - state.scrollw
), position)
3884 (float conf.winw, position +. sh)
3886 let position, sw = scrollpw state.x in
3888 (position, float (conf.winh
- state.hscrollh))
3889 (position +. sw, float conf.winh
)
3893 let pagetranslatepoint l x y =
3894 let dy = y - l.pagedispy
in
3895 let y = dy + l.pagey in
3896 let dx = x - l.pagedispx
in
3897 let x = dx + l.pagex in
3902 match state.mstate
with
3903 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
3906 | Msel
((x0, y0
), (x1
, y1
)) ->
3907 let rec loop = function
3909 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
3910 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
3912 match getopaque l.pageno with
3914 let dx, dy = pagetranslatepoint l 0 0 in
3919 GlMat.mode `modelview
;
3921 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
3922 seltext opaque
(x0, y0
, x1
, y1
);
3933 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
3934 GlDraw.polygon_mode `both `fill
;
3935 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3937 (fun (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
3939 if l.pageno = pageno
3941 let dx = float (l.pagedispx
- l.pagex) in
3942 let dy = float (l.pagedispy
- l.pagey) in
3943 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
3944 GlDraw.begins `quads
;
3946 GlDraw.vertex2
(x0+.dx, y0
+.dy);
3947 GlDraw.vertex2
(x1
+.dx, y1
+.dy);
3948 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
3949 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
3960 GlClear.color (scalecolor2 conf.bgcolor
);
3961 GlClear.clear
[`
color];
3962 List.iter
drawpage state.layout;
3967 begin match state.mstate
with
3968 | Mzoomrect
((x0, y0
), (x1
, y1
)) ->
3970 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
3971 GlDraw.polygon_mode `both `fill
;
3972 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3973 GlDraw.rect (float x0, float y0
)
3974 (float x1
, float y1
);
3979 Glut.swapBuffers
();
3983 let rec f = function
3985 begin match getopaque l.pageno with
3987 let x0 = l.pagedispx
in
3988 let x1 = x0 + l.pagevw in
3989 let y0 = l.pagedispy
in
3990 let y1 = y0 + l.pagevh in
3991 if y >= y0 && y <= y1 && x >= x0 && x <= x1
3993 let px, py = pagetranslatepoint l x y in
3994 match whatsunder opaque
px py with
4006 let zoomrect x y x1 y1 =
4009 and y0 = min
y y1 in
4010 gotoy (state.y + y0);
4011 state.anchor <- getanchor ();
4012 let zoom = (float conf.winw *. conf.zoom) /. float (x1 - x0) in
4013 state.x <- state.x - x0;
4015 Glut.setCursor
Glut.CURSOR_INHERIT
;
4016 state.mstate
<- Mnone
;
4020 let winw = conf.winw - state.scrollw
- 1 in
4021 let s = float x /. float winw in
4022 let destx = truncate
(float (state.w + winw) *. s) in
4023 state.x <- winw - destx;
4024 gotoy_and_clear_text state.y;
4025 state.mstate
<- Mscrollx
;
4029 let s = float y /. float conf.winh
in
4030 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4031 gotoy_and_clear_text desty;
4032 state.mstate
<- Mscrolly
;
4035 let viewmouse button bstate
x y =
4037 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4038 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4040 match state.mstate
with
4041 | Mzoom
(oldn
, i
) ->
4049 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4051 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4053 let zoom = conf.zoom -. incr in
4055 state.mstate
<- Mzoom
(n, 0);
4057 state.mstate
<- Mzoom
(n, i
+1);
4059 else state.mstate
<- Mzoom
(n, 0)
4061 | _ -> state.mstate
<- Mzoom
(n, 0)
4064 match state.autoscroll
with
4065 | Some step
-> setautoscrollspeed step
(n=4)
4069 then -conf.scrollstep
4070 else conf.scrollstep
4072 let incr = incr * 2 in
4073 let y = clamp incr in
4074 gotoy_and_clear_text y
4077 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4078 if bstate
= Glut.DOWN
4080 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4081 state.mstate
<- Mpan
(x, y)
4084 state.mstate
<- Mnone
4086 | Glut.RIGHT_BUTTON
->
4087 if bstate
= Glut.DOWN
4089 Glut.setCursor
Glut.CURSOR_CYCLE
;
4091 state.mstate
<- Mzoomrect
(p, p)
4094 match state.mstate
with
4095 | Mzoomrect
((x0, y0), _) -> zoomrect x0 y0 x y
4097 Glut.setCursor
Glut.CURSOR_INHERIT
;
4098 state.mstate
<- Mnone
4101 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4102 if bstate
= Glut.DOWN
4104 let position, sh = scrollph state.y in
4105 if y > truncate
position && y < truncate
(position +. sh)
4106 then state.mstate
<- Mscrolly
4109 state.mstate
<- Mnone
4111 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4112 if bstate
= Glut.DOWN
4114 let position, sw = scrollpw state.x in
4115 if x > truncate
position && x < truncate
(position +. sw)
4116 then state.mstate
<- Mscrollx
4119 state.mstate
<- Mnone
4121 | Glut.LEFT_BUTTON
->
4122 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4123 begin match dest with
4124 | Ulinkgoto
(pageno, top) ->
4128 gotopage1 pageno top;
4134 | Unone
when bstate
= Glut.DOWN
->
4135 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4136 state.mstate
<- Mpan
(x, y);
4138 | Unone
| Utext
_ ->
4139 if bstate
= Glut.DOWN
4141 if conf.angle
mod 360 = 0
4143 state.mstate
<- Msel
((x, y), (x, y));
4144 G.postRedisplay "mouse select";
4148 match state.mstate
with
4151 | Mzoom
_ | Mscrollx
| Mscrolly
->
4152 state.mstate
<- Mnone
4154 | Mzoomrect
((x0, y0), _) ->
4158 Glut.setCursor
Glut.CURSOR_INHERIT
;
4159 state.mstate
<- Mnone
4161 | Msel
((_, y0), (_, y1)) ->
4163 if (y0 >= l.pagedispy
&& y0 <= (l.pagedispy
+ l.pagevh))
4164 || ((y1 >= l.pagedispy
&& y1 <= (l.pagedispy
+ l.pagevh)))
4166 match getopaque l.pageno with
4171 List.iter
f state.layout;
4172 copysel
""; (* ugly *)
4173 Glut.setCursor
Glut.CURSOR_INHERIT
;
4174 state.mstate
<- Mnone
;
4181 let birdseyemouse button bstate
x y
4182 (conf, leftx
, _, hooverpageno
, anchor) =
4184 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4185 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4186 let rec loop = function
4189 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4190 && x > margin && x < margin + l.pagew
4192 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4197 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4201 let mouse bstate button
x y =
4202 state.uioh <- state.uioh#button button bstate
x y;
4205 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4208 state.uioh <- state.uioh#
motion x y
4212 state.uioh <- state.uioh#
pmotion x y;
4219 begin match state.mode with
4220 | Textentry
textentry -> textentrykeyboard key textentry
4221 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4222 | View
-> viewkeyboard key
4226 method special key =
4227 begin match state.mode with
4228 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4232 birdseyespecial key vals
4234 | View
when key = Glut.KEY_F1
->
4238 begin match state.autoscroll
with
4239 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4240 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4245 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4247 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4249 if Glut.getModifiers
() land Glut.active_shift
!= 0
4250 then (setzoom state.prevzoom
; state.y)
4251 else clamp (-conf.winh
/2)
4252 else clamp (-conf.scrollstep
)
4254 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4256 if Glut.getModifiers
() land Glut.active_shift
!= 0
4257 then (setzoom state.prevzoom
; state.y)
4258 else clamp (conf.winh
/2)
4259 else clamp (conf.scrollstep
)
4260 | Glut.KEY_PAGE_UP
->
4261 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4263 match state.layout with
4265 | l :: _ -> state.y - l.pagey
4268 | Glut.KEY_PAGE_DOWN
->
4269 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4271 match List.rev
state.layout with
4273 | l :: _ -> getpagey l.pageno
4281 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
4283 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
4284 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
4285 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
4287 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
4289 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4290 then (conf.winw / 2)
4293 state.x <- state.x - dx;
4295 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
4297 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4298 then (conf.winw / 2)
4301 state.x <- state.x + dx;
4306 gotoy_and_clear_text y
4309 | Textentry
te -> textentryspecial key te
4313 method button button bstate
x y =
4314 begin match state.mode with
4315 | View
-> viewmouse button bstate
x y
4316 | Birdseye beye
-> birdseyemouse button bstate
x y beye
4322 begin match state.mode with
4324 | View
| Birdseye
_ ->
4325 match state.mstate
with
4326 | Mzoom
_ | Mnone
-> ()
4331 state.mstate
<- Mpan
(x, y);
4332 if conf.zoom > 1.0 then state.x <- state.x + dx;
4334 gotoy_and_clear_text y
4337 state.mstate
<- Msel
(a, (x, y));
4338 G.postRedisplay "motion select";
4341 let y = min
conf.winh
(max
0 y) in
4345 let x = min
conf.winw (max
0 x) in
4348 | Mzoomrect
(p0
, _) ->
4349 state.mstate
<- Mzoomrect
(p0
, (x, y));
4350 G.postRedisplay "motion zoomrect";
4354 method pmotion x y =
4355 begin match state.mode with
4356 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
4357 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4358 let rec loop = function
4360 if hooverpageno
!= -1
4362 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
4363 G.postRedisplay "pmotion birdseye no hoover";
4366 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4367 && x > margin && x < margin + l.pagew
4369 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
4370 G.postRedisplay "pmotion birdseye hoover";
4379 match state.mstate
with
4381 begin match getunder x y with
4382 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
4384 if conf.underinfo
then showtext 'u'
("ri: " ^
uri);
4385 Glut.setCursor
Glut.CURSOR_INFO
4386 | Ulinkgoto
(page
, _) ->
4388 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
4389 Glut.setCursor
Glut.CURSOR_INFO
4391 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
4392 Glut.setCursor
Glut.CURSOR_TEXT
4395 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
4400 method memusedchanged
= ()
4407 let fontpath = ref "";;
4408 let wmclasshack = ref false;;
4411 let l = String.length
s in
4412 let b = Buffer.create
l in
4420 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
4421 | _ -> Sys.getenv
"HOME"
4424 ("Can not determine home directory location: " ^
4425 Printexc.to_string exn
);
4429 let config_of c attrs
=
4433 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
4434 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
4435 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
4436 | "preload" -> { c with preload = bool_of_string
v }
4437 | "page-bias" -> { c with pagebias
= int_of_string
v }
4438 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
4439 | "auto-scroll-step" ->
4440 { c with autoscrollstep
= max
0 (int_of_string
v) }
4441 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
4442 | "crop-hack" -> { c with crophack
= bool_of_string
v }
4443 | "throttle" -> { c with showall
= bool_of_string
v }
4444 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
4445 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
4446 | "vertical-margin" ->
4447 { c with interpagespace = max
0 (int_of_string
v) }
4449 let zoom = float_of_string
v /. 100. in
4450 let zoom = max
zoom 0.0 in
4451 { c with zoom = zoom }
4452 | "presentation" -> { c with presentation = bool_of_string
v }
4453 | "rotation-angle" -> { c with angle
= int_of_string
v }
4454 | "width" -> { c with winw = max
20 (int_of_string
v) }
4455 | "height" -> { c with winh
= max
20 (int_of_string
v) }
4456 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
4457 | "proportional-display" -> { c with proportional
= bool_of_string
v }
4458 | "pixmap-cache-size" ->
4459 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
4460 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
4461 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
4462 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
4463 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
4464 | "background-color" -> { c with bgcolor
= color_of_string v }
4465 | "scrollbar-in-presentation" ->
4466 { c with scrollbarinpm
= bool_of_string
v }
4467 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
4468 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
4470 { c with mumemlimit
= max
1024 (int_of_string_with_suffix v) }
4471 | "checkers" -> { c with checkers
= bool_of_string
v }
4472 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
4473 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
4474 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
4475 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
4476 | "uri-launcher" -> { c with urilauncher
= unent v }
4477 | "color-space" -> { c with colorspace
= colorspace_of_string v }
4478 | "invert-colors" -> { c with invert
= bool_of_string
v }
4481 prerr_endline
("Error processing attribute (`" ^
4482 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
4485 let rec fold c = function
4488 let c = apply c k
v in
4494 let fromstring f pos
n v d =
4497 dolog "Error processing attribute (%S=%S) at %d\n%s"
4498 n v pos
(Printexc.to_string exn
)
4503 let bookmark_of attrs
=
4504 let rec fold title page rely
= function
4505 | ("title", v) :: rest
-> fold v page rely rest
4506 | ("page", v) :: rest
-> fold title v rely rest
4507 | ("rely", v) :: rest
-> fold title page
v rest
4508 | _ :: rest
-> fold title page rely rest
4509 | [] -> title, page
, rely
4511 fold "invalid" "0" "0" attrs
4515 let rec fold path page rely pan
= function
4516 | ("path", v) :: rest
-> fold v page rely pan rest
4517 | ("page", v) :: rest
-> fold path
v rely pan rest
4518 | ("rely", v) :: rest
-> fold path page
v pan rest
4519 | ("pan", v) :: rest
-> fold path page rely
v rest
4520 | _ :: rest
-> fold path page rely pan rest
4521 | [] -> path
, page
, rely
, pan
4523 fold "" "0" "0" "0" attrs
4526 let setconf dst
src =
4527 dst
.scrollbw
<- src.scrollbw
;
4528 dst
.scrollh
<- src.scrollh
;
4529 dst
.icase
<- src.icase
;
4530 dst
.preload <- src.preload;
4531 dst
.pagebias
<- src.pagebias
;
4532 dst
.verbose
<- src.verbose
;
4533 dst
.scrollstep
<- src.scrollstep
;
4534 dst
.maxhfit
<- src.maxhfit
;
4535 dst
.crophack
<- src.crophack
;
4536 dst
.autoscrollstep
<- src.autoscrollstep
;
4537 dst
.showall
<- src.showall
;
4538 dst
.hlinks
<- src.hlinks
;
4539 dst
.underinfo
<- src.underinfo
;
4540 dst
.interpagespace <- src.interpagespace;
4541 dst
.zoom <- src.zoom;
4542 dst
.presentation <- src.presentation;
4543 dst
.angle
<- src.angle
;
4544 dst
.winw <- src.winw;
4545 dst
.winh
<- src.winh
;
4546 dst
.savebmarks
<- src.savebmarks
;
4547 dst
.memlimit
<- src.memlimit
;
4548 dst
.proportional
<- src.proportional
;
4549 dst
.texcount
<- src.texcount
;
4550 dst
.sliceheight
<- src.sliceheight
;
4551 dst
.thumbw
<- src.thumbw
;
4552 dst
.jumpback
<- src.jumpback
;
4553 dst
.bgcolor
<- src.bgcolor
;
4554 dst
.scrollbarinpm
<- src.scrollbarinpm
;
4555 dst
.tilew
<- src.tilew
;
4556 dst
.tileh
<- src.tileh
;
4557 dst
.mumemlimit
<- src.mumemlimit
;
4558 dst
.checkers
<- src.checkers
;
4559 dst
.aalevel
<- src.aalevel
;
4560 dst
.trimmargins
<- src.trimmargins
;
4561 dst
.trimfuzz
<- src.trimfuzz
;
4562 dst
.urilauncher
<- src.urilauncher
;
4563 dst
.colorspace
<- src.colorspace
;
4564 dst
.invert
<- src.invert
;
4568 let h = Hashtbl.create
10 in
4569 let dc = { defconf with angle
= defconf.angle
} in
4570 let rec toplevel v t spos
_ =
4572 | Vdata
| Vcdata
| Vend
-> v
4573 | Vopen
("llppconfig", _, closed
) ->
4576 else { v with f = llppconfig
}
4578 error
"unexpected subelement at top level" s spos
4579 | Vclose
_ -> error
"unexpected close at top level" s spos
4581 and llppconfig
v t spos
_ =
4583 | Vdata
| Vcdata
-> v
4584 | Vend
-> error
"unexpected end of input in llppconfig" s spos
4585 | Vopen
("defaults", attrs
, closed
) ->
4586 let c = config_of dc attrs
in
4590 else { v with f = skip
"defaults" (fun () -> v) }
4592 | Vopen
("ui-font", attrs
, closed
) ->
4593 let rec getsize size
= function
4595 | ("size", v) :: rest
->
4597 fromstring int_of_string spos
"size" v !uifontsize in
4599 | l -> getsize size l
4601 uifontsize := getsize !uifontsize attrs
;
4604 else { v with f = uifont
(Buffer.create
10) }
4606 | Vopen
("doc", attrs
, closed
) ->
4607 let pathent, spage
, srely
, span
= doc_of attrs
in
4608 let path = unent pathent
4609 and pageno = fromstring int_of_string spos
"page" spage
0
4610 and rely
= fromstring float_of_string spos
"rely" srely
0.0
4611 and pan
= fromstring int_of_string spos
"pan" span
0 in
4612 let c = config_of dc attrs
in
4613 let anchor = (pageno, rely
) in
4615 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
4616 else { v with f = doc
path pan
anchor c [] }
4619 error
"unexpected subelement in llppconfig" s spos
4621 | Vclose
"llppconfig" -> { v with f = toplevel }
4622 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
4624 and uifont
b v t spos epos
=
4627 Buffer.add_substring
b s spos
(epos
- spos
);
4629 | Vopen
(_, _, _) ->
4630 error
"unexpected subelement in ui-font" s spos
4631 | Vclose
"ui-font" ->
4632 if String.length
!fontpath = 0
4633 then fontpath := Buffer.contents
b;
4634 { v with f = llppconfig
}
4635 | Vclose
_ -> error
"unexpected close in ui-font" s spos
4636 | Vend
-> error
"unexpected end of input in ui-font" s spos
4638 and doc
path pan
anchor c bookmarks
v t spos
_ =
4640 | Vdata
| Vcdata
-> v
4641 | Vend
-> error
"unexpected end of input in doc" s spos
4642 | Vopen
("bookmarks", _, closed
) ->
4645 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
4647 | Vopen
(_, _, _) ->
4648 error
"unexpected subelement in doc" s spos
4651 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
4652 { v with f = llppconfig
}
4654 | Vclose
_ -> error
"unexpected close in doc" s spos
4656 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
4658 | Vdata
| Vcdata
-> v
4659 | Vend
-> error
"unexpected end of input in bookmarks" s spos
4660 | Vopen
("item", attrs
, closed
) ->
4661 let titleent, spage
, srely
= bookmark_of attrs
in
4662 let page = fromstring int_of_string spos
"page" spage
0
4663 and rely
= fromstring float_of_string spos
"rely" srely
0.0 in
4664 let bookmarks = (unent titleent, 0, (page, rely
)) :: bookmarks in
4666 then { v with f = pbookmarks
path pan
anchor c bookmarks }
4669 { v with f = skip
"item" f }
4672 error
"unexpected subelement in bookmarks" s spos
4674 | Vclose
"bookmarks" ->
4675 { v with f = doc
path pan
anchor c bookmarks }
4677 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
4679 and skip tag
f v t spos
_ =
4681 | Vdata
| Vcdata
-> v
4683 error
("unexpected end of input in skipped " ^ tag
) s spos
4684 | Vopen
(tag'
, _, closed
) ->
4688 let f'
() = { v with f = skip tag
f } in
4689 { v with f = skip tag'
f'
}
4693 else error
("unexpected close in skipped " ^ tag
) s spos
4696 parse
{ f = toplevel; accu = () } s;
4702 let len = in_channel_length ic
in
4703 let s = String.create
len in
4704 really_input ic
s 0 len;
4707 | Parse_error
(msg
, s, pos
) ->
4708 let subs = subs s pos
in
4709 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
4710 failwith
("parse error: " ^
s)
4713 failwith
("config load error: " ^
Printexc.to_string exn
)
4719 let dir = Filename.concat
home ".config" in
4720 if Sys.is_directory
dir then dir else home
4723 Filename.concat
dir "llpp.conf"
4726 let confpath = ref defconfpath;;
4729 if Sys.file_exists
!confpath
4732 (try Some
(open_in_bin
!confpath)
4735 ("Error opening configuation file `" ^
!confpath ^
"': " ^
4736 Printexc.to_string exn
);
4745 ("Error loading configuation from `" ^
!confpath ^
"': " ^
4746 Printexc.to_string exn
);
4752 f (Hashtbl.create
0, defconf)
4757 let pc, pb
, px, pa
=
4759 Hashtbl.find h (Filename.basename
state.path)
4760 with Not_found
-> dc, [], 0, (0, 0.0)
4764 state.bookmarks <- pb
;
4766 state.scrollw
<- conf.scrollbw
;
4768 then state.anchor <- pa
;
4769 cbput state.hists
.nav pa
;
4774 let add_attrs bb always
dc c =
4777 then Printf.bprintf bb
"\n %s='%b'" s a
4780 then Printf.bprintf bb
"\n %s='%d'" s a
4783 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
4786 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
4790 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
4794 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
4798 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
4802 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
4806 then dc.winw, dc.winh
4808 match state.fullscreen
with
4810 | None
-> c.winw, c.winh
4812 let zoom, presentation, interpagespace, showall
=
4814 then dc.zoom, dc.presentation, dc.interpagespace, dc.showall
4816 match state.mode with
4817 | Birdseye
(bc
, _, _, _, _) ->
4818 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.showall
4819 | _ -> c.zoom, c.presentation, c.interpagespace, c.showall
4821 oi
"width" w dc.winw;
4822 oi
"height" h dc.winh
;
4823 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
4824 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
4825 ob "case-insensitive-search" c.icase
dc.icase
;
4826 ob "preload" c.preload dc.preload;
4827 oi
"page-bias" c.pagebias
dc.pagebias
;
4828 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
4829 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
4830 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
4831 ob "crop-hack" c.crophack
dc.crophack
;
4832 ob "throttle" showall
dc.showall
;
4833 ob "highlight-links" c.hlinks
dc.hlinks
;
4834 ob "under-cursor-info" c.underinfo
dc.underinfo
;
4835 oi
"vertical-margin" interpagespace dc.interpagespace;
4836 oz
"zoom" zoom dc.zoom;
4837 ob "presentation" presentation dc.presentation;
4838 oi
"rotation-angle" c.angle
dc.angle
;
4839 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
4840 ob "proportional-display" c.proportional
dc.proportional
;
4841 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
4842 oi
"tex-count" c.texcount
dc.texcount
;
4843 oi
"slice-height" c.sliceheight
dc.sliceheight
;
4844 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
4845 ob "persistent-location" c.jumpback
dc.jumpback
;
4846 oc
"background-color" c.bgcolor
dc.bgcolor
;
4847 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
4848 oi
"tile-width" c.tilew
dc.tilew
;
4849 oi
"tile-height" c.tileh
dc.tileh
;
4850 oI
"mupdf-memlimit" c.mumemlimit
dc.mumemlimit
;
4851 ob "checkers" c.checkers
dc.checkers
;
4852 oi
"aalevel" c.aalevel
dc.aalevel
;
4853 ob "trim-margins" c.trimmargins
dc.trimmargins
;
4854 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
4855 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
4856 oC
"color-space" c.colorspace
dc.colorspace
;
4857 ob "invert-colors" c.invert
dc.invert
;
4859 then ob "wmclass-hack" !wmclasshack false;
4863 let uifontsize = !uifontsize in
4864 let bb = Buffer.create
32768 in
4866 let dc = if conf.bedefault
then conf else dc in
4867 Buffer.add_string
bb "<llppconfig>\n";
4869 if String.length
!fontpath > 0
4871 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
4877 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
4880 Buffer.add_string
bb "<defaults ";
4881 add_attrs bb true dc dc;
4882 Buffer.add_string
bb "/>\n";
4884 let adddoc path pan
anchor c bookmarks =
4885 if bookmarks == [] && c = dc && anchor = emptyanchor
4888 Printf.bprintf
bb "<doc path='%s'"
4889 (enent
path 0 (String.length
path));
4891 if anchor <> emptyanchor
4893 let n, y = anchor in
4894 Printf.bprintf
bb " page='%d'" n;
4897 Printf.bprintf
bb " rely='%f'" y
4902 then Printf.bprintf
bb " pan='%d'" pan
;
4904 add_attrs bb false dc c;
4906 begin match bookmarks with
4907 | [] -> Buffer.add_string
bb "/>\n"
4909 Buffer.add_string
bb ">\n<bookmarks>\n";
4910 List.iter
(fun (title, _level
, (page, rely
)) ->
4912 "<item title='%s' page='%d'"
4913 (enent
title 0 (String.length
title))
4918 Printf.bprintf
bb " rely='%f'" rely
4920 Buffer.add_string
bb "/>\n";
4922 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
4928 match state.mode with
4929 | Birdseye
(_, pan, _, _, _) -> pan
4932 let basename = Filename.basename state.path in
4933 adddoc basename pan (getanchor ())
4936 match state.autoscroll
with
4938 | None
-> conf.autoscrollstep
}
4939 (if conf.savebmarks
then state.bookmarks else []);
4941 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
4943 then adddoc path x y c bookmarks
4945 Buffer.add_string
bb "</llppconfig>";
4948 if Buffer.length
bb > 0
4951 let tmp = !confpath ^
".tmp" in
4952 let oc = open_out_bin
tmp in
4953 Buffer.output_buffer
oc bb;
4955 Unix.rename
tmp !confpath;
4958 ("error while saving configuration: " ^
Printexc.to_string exn
)
4965 [("-p", Arg.String
(fun s -> state.password
<- s) ,
4966 "<password> Set password");
4968 ("-f", Arg.String
(fun s -> Config.fontpath := s),
4969 "<path> Set path to the user interface font");
4971 ("-c", Arg.String
(fun s -> Config.confpath := s),
4972 "<path> Set path to the configuration file");
4974 ("-v", Arg.Unit
(fun () ->
4976 "%s\nconfiguration path: %s\n"
4980 exit
0), " Print version and exit");
4983 (fun s -> state.path <- s)
4984 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
4986 if String.length
state.path = 0
4987 then (prerr_endline
"file name missing"; exit
1);
4991 let _ = Glut.init
Sys.argv
in
4992 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
4993 let () = Glut.initWindowSize
conf.winw conf.winh
in
4994 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
4996 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
4997 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
4998 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5003 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5005 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5006 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5007 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5008 Unix.bind
sock addr;
5010 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5011 Unix.connect
csock addr;
5012 let ssock, _ = Unix.accept
sock in
5015 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5016 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5023 let () = Glut.displayFunc
display in
5024 let () = Glut.reshapeFunc
reshape in
5025 let () = Glut.keyboardFunc
keyboard in
5026 let () = Glut.specialFunc
special in
5027 let () = Glut.idleFunc
(Some
idle) in
5028 let () = Glut.mouseFunc
mouse in
5029 let () = Glut.motionFunc
motion in
5030 let () = Glut.passiveMotionFunc
pmotion in
5032 setcheckers conf.checkers
;
5034 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5035 conf.texcount
, conf.sliceheight
, conf.mumemlimit
, conf.colorspace
,
5036 !Config.wmclasshack, !Config.fontpath
5038 state.csock <- csock;
5039 state.ssock <- ssock;
5040 state.text <- "Opening " ^
state.path;
5041 setaalevel
conf.aalevel
;
5042 writeopen state.path state.password
;
5049 | Glut.BadEnum
"key in special_of_int" ->
5050 showtext '
!'
" LablGlut bug: special key not recognized";