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
=
514 then prerr_endline
("redisplay for " ^ who
);
515 Glut.postRedisplay ();
520 let b = Buffer.create
(String.length s
+ 1) in
521 Buffer.add_string
b s
;
526 let colorspace_of_string s
=
527 match String.lowercase s
with
531 | _
-> failwith
"invalid colorspace"
534 let int_of_colorspace = function
540 let colorspace_of_int = function
544 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
547 let colorspace_to_string = function
553 let intentry_with_suffix text key
=
554 let c = Char.unsafe_chr key
in
555 match Char.lowercase
c with
557 let text = addchar text c in
561 let text = addchar text c in
565 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
570 let len = String.length s
in
572 let b = Buffer.create
n in
573 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
574 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
575 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
576 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
577 Buffer.add_string
b s
;
578 let s'
= Buffer.contents
b in
579 let n'
= Unix.write fd
s'
0 n in
580 if n'
!= n then failwith
"write failed";
585 let n = Unix.read fd
s 0 4 in
586 if n != 4 then failwith
"incomplete read(len)";
588 lor (Char.code
s.[0] lsl 24)
589 lor (Char.code
s.[1] lsl 16)
590 lor (Char.code
s.[2] lsl 8)
591 lor (Char.code
s.[3] lsl 0)
593 let s = String.create
len in
594 let n = Unix.read fd
s 0 len in
595 if n != len then failwith
"incomplete read(data)";
600 let b = Buffer.create
10 in
601 Buffer.add_string
b s;
602 let rec combine = function
605 Buffer.add_char
b ' '
;
608 | `
b b -> if b then "1" else "0"
610 | `i i
-> string_of_int i
611 | `f f
-> string_of_float f
612 | `I f
-> string_of_int
(truncate f
)
614 Buffer.add_string
b s;
621 let cmd = Buffer.contents
(makecmd s l
) in
622 writecmd state.csock
cmd;
628 let d = conf.winh
- h
in
635 let rec f pn ph pi fh l
=
637 | (n, _
, h
, _
) :: rest
->
638 let ips = calcips h
in
643 if isbirdseye state.mode
&& pn
= 0
648 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
653 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
657 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
660 let fh = f 0 0 0 0 state.pdims
in
664 let getpageyh pageno
=
665 let rec f pn ph pi y l
=
667 | (n, _
, h
, _
) :: rest
->
668 let ips = calcips h
in
671 let h = if n = pageno
then h else ph
in
672 if conf.presentation
&& n = pageno
674 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
676 y
+ (pageno
- pn
) * (ph
+ pi
), h
678 let y = y + (if conf.presentation
then pi
else 0) in
679 let y = y + (n - pn
) * (ph
+ pi
) in
683 y + (pageno
- pn
) * (ph
+ pi
), ph
685 f 0 0 0 0 state.pdims
688 let getpagedim pageno
=
691 | (n, _
, _
, _
) as pdim
:: rest
->
693 then (if n = pageno
then pdim
else ppdim
)
698 f (-1, -1, -1, -1) state.pdims
701 let getpageh pageno
=
702 let _, _, h, _ = getpagedim pageno
in
706 let getpagew pageno
=
707 let _, w
, _, _ = getpagedim pageno
in
711 let getpagey pageno
= fst
(getpageyh pageno
);;
714 let sh = sh - state.hscrollh
in
715 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
716 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
718 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
719 let ips = calcips h in
721 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
725 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
727 prev
, pdims
, pdimno
, 0
729 let dy = dy + yinc in
730 let py = py + yinc in
731 if pageno
= state.pagecount
|| dy >= sh
736 if py + h <= vy - yinc
738 let py = py + h + ips in
739 let dy = max
0 (py - y) in
748 let pagey = vy - py in
749 let pagevh = h - pagey in
750 let pagevh = min
(sh - dy) pagevh in
751 let off = if yinc > 0 then py - vy else 0 in
752 let py = py + h + ips in
755 if state.w
< conf.winw
- state.scrollw
756 then (conf.winw
- state.scrollw
- state.w
) / 2
759 let dispx = xoff + state.x
in
765 let lw = w
- pagex in
766 min
lw (conf.winw
- state.scrollw
)
774 ; pagey = pagey + off
776 ; pagevh = pagevh - off
778 ; pagedispy
= dy + off
781 let accu = e :: accu in
790 if state.invalidated
= 0
809 let y = state.y + incr
in
811 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
815 let getopaque pageno
=
816 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
817 with Not_found
-> None
820 let putopaque pageno opaque
=
821 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
825 let tilex = l
.pagex mod conf.tilew
in
826 let tiley = l
.pagey mod conf.tileh
in
828 let col = l
.pagex / conf.tilew
in
829 let row = l
.pagey / conf.tileh
in
832 let a = l
.pagew
- l
.pagex in
833 let b = conf.winw
- state.scrollw
in
837 let rec rowloop row y0 dispy
h =
841 let dh = conf.tileh
- y0
in
843 let rec colloop col x0
dispx w
=
847 let dw = conf.tilew
- x0
in
850 f col row dispx dispy x0 y0
dw dh;
851 colloop (col+1) 0 (dispx+dw) (w
-dw)
854 colloop col tilex l
.pagedispx
vw;
855 rowloop (row+1) 0 (dispy
+dh) (h-dh)
859 then rowloop row tiley l
.pagedispy vh
;
862 let gettileopaque l
col row =
864 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
866 try Some
(Hashtbl.find
state.tilemap
key)
867 with Not_found
-> None
870 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
871 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
872 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
875 let drawtiles l color
=
877 let f col row x
y tilex tiley w
h =
878 match gettileopaque l
col row with
879 | Some
(opaque
, _, t
) ->
880 let params = x
, y, w
, h, tilex, tiley in
884 GlFunc.blend_func `zero `one_minus_src_color
;
886 drawtile
params opaque
;
888 then Gl.disable `blend
;
891 let s = Printf.sprintf
895 let w = measurestr
!uifontsize s in
896 GlMisc.push_attrib
[`current
];
897 GlDraw.color
(0.0, 0.0, 0.0);
899 (float (x
-2), float (y-2))
900 (float (x
+2) +. w, float (y + !uifontsize + 2));
901 GlDraw.color
(1.0, 1.0, 1.0);
902 drawstring !uifontsize x
(y + !uifontsize - 1) s;
903 GlMisc.pop_attrib
();
908 let lw = conf.winw
- state.scrollw
- x
in
911 let lh = conf.winh
- y in
914 Gl.enable `texture_2d
;
915 begin match state.texid
with
917 GlTex.bind_texture `texture_2d id
;
921 and y1
= float (y+h) in
923 let tw = float w /. 64.0
924 and th
= float h /. 64.0 in
925 let tx0 = float tilex /. 64.0
926 and ty0
= float tiley /. 64.0 in
928 and ty1
= ty0
+. th
in
929 GlDraw.begins `quads
;
930 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
931 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
932 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
933 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
936 Gl.disable `texture_2d
;
938 GlDraw.color
(1.0, 1.0, 1.0);
941 (float (x
+w), float (y+h));
943 if w > 128 && h > !uifontsize + 10
945 GlDraw.color
(0.0, 0.0, 0.0);
948 then (col*conf.tilew
, row*conf.tileh
)
951 drawstring2 !uifontsize x
y "Loading %d [%d,%d]" l
.pageno
c r;
958 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
960 let tilevisible1 l x
y =
962 and ax1
= l
.pagex + l
.pagevw
964 and ay1
= l
.pagey + l
.pagevh in
968 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
969 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
971 let rx0 = max
ax0 bx0
972 and ry0
= max ay0 by0
973 and rx1
= min ax1
bx1
974 and ry1
= min ay1 by1
in
976 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
980 let tilevisible layout n x
y =
981 let rec findpageinlayout = function
982 | l
:: _ when l
.pageno
= n -> tilevisible1 l x
y
983 | _ :: rest
-> findpageinlayout rest
986 findpageinlayout layout
989 let tileready l x
y =
990 tilevisible1 l x
y &&
991 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
994 let tilepage n p
layout =
995 let rec loop = function
999 let f col row _ _ _ _ _ _ =
1000 if state.currently
= Idle
1002 match gettileopaque l
col row with
1005 let x = col*conf.tilew
1006 and y = row*conf.tileh
in
1008 let w = l
.pagew
- x in
1012 let h = l
.pageh
- y in
1024 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1025 conf.tilew
, conf.tileh
1034 if state.invalidated
= 0 then loop layout;
1037 let preloadlayout visiblepages
=
1038 let presentation = conf.presentation in
1039 let interpagespace = conf.interpagespace in
1040 let maxy = state.maxy in
1041 conf.presentation <- false;
1042 conf.interpagespace <- 0;
1043 state.maxy <- calcheight ();
1045 match visiblepages
with
1047 | l
:: _ -> getpagey l
.pageno
+ l
.pagey
1049 let y = if y < conf.winh
then 0 else y - conf.winh
in
1050 let h = state.y - y + conf.winh
*3 in
1051 let pages = layout y h in
1052 conf.presentation <- presentation;
1053 conf.interpagespace <- interpagespace;
1059 let rec loop pages =
1060 if state.currently
!= Idle
1065 begin match getopaque l
.pageno
with
1067 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1068 state.currently
<- Loading
(l
, state.gen
);
1070 tilepage l
.pageno opaque
pages;
1075 if state.invalidated
= 0 then loop pages
1080 if conf.preload && state.currently
= Idle
1081 then load (preloadlayout pages);
1084 let layoutready layout =
1085 let rec fold all ls
=
1086 all
&& match ls
with
1088 let seen = ref false in
1089 let allvisible = ref true in
1090 let foo col row _ _ _ _ _ _ =
1092 allvisible := !allvisible &&
1093 begin match gettileopaque l
col row with
1099 fold (!seen && !allvisible) rest
1102 let alltilesvisible = fold true layout in
1107 let y = bound y 0 state.maxy in
1108 let y, layout, proceed
=
1111 match state.throttle
with
1113 let layout = layout y conf.winh
in
1114 let ready = layoutready layout in
1118 state.throttle
<- Some
(layout, y);
1120 else G.postRedisplay "gotoy showall (None)";
1122 | Some
_ -> -1, [], false
1124 let layout = layout y conf.winh
in
1125 if true || layoutready layout
1126 then G.postRedisplay "gotoy ready";
1132 state.layout <- layout;
1133 begin match state.mode
with
1134 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1135 if not
(pagevisible layout pageno
)
1137 match state.layout with
1140 state.mode
<- Birdseye
(
1141 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1150 let conttiling pageno opaque
=
1151 tilepage pageno opaque
1152 (if conf.preload then preloadlayout state.layout else state.layout)
1155 let gotoy_and_clear_text y =
1157 if not
conf.verbose
then state.text <- "";
1161 match state.layout with
1163 | l
:: _ -> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1166 let getanchory (n, top
) =
1167 let y, h = getpageyh n in
1168 y + (truncate
(top
*. float h));
1171 let gotoanchor anchor
=
1172 gotoy (getanchory anchor
);
1176 cbput state.hists
.nav
(getanchor ());
1180 let anchor = cbgetc state.hists
.nav dir
in
1184 let gotopage n top
=
1185 let y, h = getpageyh n in
1186 gotoy_and_clear_text (y + (truncate
(top
*. float h)));
1189 let gotopage1 n top
=
1190 let y = getpagey n in
1191 gotoy_and_clear_text (y + top
);
1199 state.invalidated
<- state.invalidated
+ 1;
1202 let writeopen path password
=
1203 writecmd state.csock
("open " ^ path ^
"\000" ^ password ^
"\000");
1206 let opendoc path password
=
1209 state.password
<- password
;
1210 state.gen
<- state.gen
+ 1;
1211 state.docinfo
<- [];
1213 setaalevel
conf.aalevel
;
1214 writeopen path password
;
1215 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1216 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1220 let c = c *. state.colorscale
in
1224 let scalecolor2 (r, g
, b) =
1225 (r *. state.colorscale
, g
*. state.colorscale
, b *. state.colorscale
);
1229 state.maxy <- calcheight ();
1231 if state.w <= conf.winw
- state.scrollw
1235 match state.mode
with
1236 | Birdseye
(_, _, pageno
, _, _) ->
1237 let y, h = getpageyh pageno
in
1238 let top = (conf.winh
- h) / 2 in
1239 gotoy (max
0 (y - top))
1240 | _ -> gotoanchor state.anchor
1244 let firsttime = ref true in
1246 GlDraw.viewport
0 0 w h;
1247 if state.invalidated
= 0 && not
!firsttime
1248 then state.anchor <- getanchor ();
1252 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1256 GlMat.mode `modelview
;
1257 GlMat.load_identity
();
1259 GlMat.mode `projection
;
1260 GlMat.load_identity
();
1261 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1262 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1263 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1266 wcmd "geometry" [`i
w; `i
h];
1270 let len = String.length
state.text in
1273 match state.mode
with
1274 | View
-> state.hscrollh
1279 (x, float (conf.winh
- (!uifontsize + 4) - hscrollh))
1280 (x+.w, float (conf.winh
- hscrollh))
1283 let w = float (conf.winw
- state.scrollw
- 1) in
1284 if state.progress
>= 0.0 && state.progress
< 1.0
1286 GlDraw.color
(0.3, 0.3, 0.3);
1287 let w1 = w *. state.progress
in
1289 GlDraw.color
(0.0, 0.0, 0.0);
1293 GlDraw.color
(0.0, 0.0, 0.0);
1297 GlDraw.color
(1.0, 1.0, 1.0);
1298 drawstring !uifontsize
1299 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1301 match state.mode
with
1302 | Textentry
((prefix
, text, _, _, _), _) ->
1306 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1308 Printf.sprintf
"%s%s_" prefix
text
1313 if len > 0 then drawstring state.text
1317 state.text <- Printf.sprintf
"%c%s" c s;
1318 G.postRedisplay "showtext";
1322 let len = Queue.length
state.tilelru
in
1324 if state.memused
<= conf.memlimit
1329 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1330 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1333 && colorspace
= conf.colorspace
1334 && angle
= conf.angle
1335 && pagew
= getpagew n
1336 && pageh
= getpageh n
1340 then preloadlayout state.layout
1343 let x = col*conf.tilew
1344 and y = row*conf.tileh
in
1345 tilevisible layout n x y
1347 then Queue.push lruitem
state.tilelru
1349 wcmd "freetile" [`
s p
];
1350 state.memused
<- state.memused
- s;
1351 state.uioh#memusedchanged
;
1352 Hashtbl.remove
state.tilemap k
;
1361 Queue.iter
(fun (k
, p
, s) ->
1362 wcmd "freetile" [`
s p
];
1363 state.memused
<- state.memused
- s;
1364 state.uioh#memusedchanged
;
1365 Hashtbl.remove
state.tilemap k
;
1367 Queue.clear
state.tilelru
;
1371 let logcurrently = function
1372 | Idle
-> dolog "Idle"
1373 | Loading
(l
, gen
) ->
1374 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1375 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1377 "Tiling %d[%d,%d] page=%s cs=%s angle"
1378 l
.pageno
col row pageopaque
1379 (colorspace_to_string colorspace
)
1381 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1382 angle gen
conf.angle
state.gen
1384 conf.tilew
conf.tileh
1391 (* dolog "%S" cmds; *)
1394 try String.index cmds ' '
1395 with Not_found
-> -1
1400 let l = String.length cmds
in
1401 let op = String.sub cmds
0 spacepos in
1403 if l - spacepos < 2 then ""
1404 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1412 state.rects
<- state.rects1
;
1413 G.postRedisplay "clearrects";
1416 let n = Scanf.sscanf args
"%u" (fun n -> n) in
1417 state.pagecount
<- n;
1418 state.invalidated
<- state.invalidated
- 1;
1419 begin match state.currently
with
1421 state.currently
<- Idle
;
1422 state.outlines
<- Array.of_list
(List.rev
l)
1425 if state.invalidated
= 0
1428 then G.postRedisplay "continue";
1431 Glut.setWindowTitle args
1438 then showtext ' ' args
1441 let progress, text = Scanf.sscanf args
"%f %n"
1443 f, String.sub args pos
(String.length args
- pos
)
1447 state.progress <- progress;
1448 G.postRedisplay "progress"
1451 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1452 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1453 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1454 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1456 let y = (getpagey pageno) + truncate y0
in
1459 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)]
1462 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1463 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1464 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1465 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1468 (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) :: state.rects1
1471 let pageopaque, t
= Scanf.sscanf args
"%s %f" (fun p t
-> p
, t
) in
1472 begin match state.currently
with
1473 | Loading
(l, gen
) ->
1474 vlog "page %d took %f sec" l.pageno t
;
1475 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1476 begin match state.throttle
with
1478 let preloadedpages =
1480 then preloadlayout state.layout
1485 Set.Make
(struct type t
= int let compare = (-) end) in
1487 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1488 IntSet.empty
preloadedpages
1491 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1492 if not
(IntSet.mem
pageno set)
1494 wcmd "freepage" [`
s opaque
];
1500 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1503 state.currently
<- Idle
;
1506 tilepage l.pageno pageopaque state.layout;
1508 load preloadedpages;
1509 if pagevisible state.layout l.pageno
1510 && layoutready state.layout
1511 then G.postRedisplay "page";
1514 | Some
(layout, _) ->
1515 state.currently
<- Idle
;
1516 tilepage l.pageno pageopaque layout;
1521 dolog "Inconsistent loading state";
1522 logcurrently state.currently
;
1527 let (x, y, opaque
, size
, t
) =
1528 Scanf.sscanf args
"%u %u %s %u %f"
1529 (fun x y p size t
-> (x, y, p
, size
, t
))
1531 begin match state.currently
with
1532 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1533 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1535 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1537 wcmd "freetile" [`
s opaque
];
1538 state.currently
<- Idle
;
1542 puttileopaque l col row gen cs angle opaque size t
;
1543 state.memused
<- state.memused
+ size
;
1544 state.uioh#memusedchanged
;
1546 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1547 opaque
, size
) state.tilelru
;
1549 state.currently
<- Idle
;
1551 && conf.colorspace
= cs
1552 && conf.angle
= angle
1553 && tilevisible state.layout l.pageno x y
1554 then conttiling l.pageno pageopaque;
1556 begin match state.throttle
with
1558 preload state.layout;
1560 && conf.colorspace
= cs
1561 && conf.angle
= angle
1562 && tilevisible state.layout l.pageno x y
1563 then G.postRedisplay "tile nothrottle";
1565 | Some
(layout, y) ->
1566 let ready = layoutready layout in
1570 state.layout <- layout;
1571 state.throttle
<- None
;
1572 G.postRedisplay "throttle";
1579 dolog "Inconsistent tiling state";
1580 logcurrently state.currently
;
1586 Scanf.sscanf args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1588 state.pdims
<- pdim :: state.pdims
1591 let (l, n, t
, h, pos
) =
1592 Scanf.sscanf args
"%u %u %d %u %n" (fun l n t
h pos
-> l, n, t
, h, pos
)
1594 let s = String.sub args pos
(String.length args
- pos
) in
1595 let outline = (s, l, (n, float t
/. float h)) in
1596 begin match state.currently
with
1597 | Outlining outlines
->
1598 state.currently
<- Outlining
(outline :: outlines
)
1600 state.currently
<- Outlining
[outline]
1602 dolog "invalid outlining state";
1603 logcurrently currently
1607 state.docinfo
<- (1, args
) :: state.docinfo
1610 state.docinfo
<- List.rev
state.docinfo
1613 dolog "unknown cmd `%S'" cmds
1616 let now = Unix.gettimeofday
;;
1619 if state.deadline
== nan
then state.deadline
<- now ();
1620 let rec loop delay
=
1623 then max
0.0 (state.deadline
-. now ())
1626 let r, _, _ = Unix.select
[state.csock
] [] [] timeout in
1629 begin match state.autoscroll
with
1630 | Some step
when step
!= 0 ->
1631 let y = state.y + step
in
1635 else if y >= state.maxy then 0 else y
1638 if state.mode
= View
1639 then state.text <- "";
1640 state.deadline
<- state.deadline
+. 0.005;
1643 state.deadline
<- state.deadline
+. delay
;
1647 let cmd = readcmd state.csock
in
1656 let action = function
1657 | HCprev
-> cbget cb ~
-1
1658 | HCnext
-> cbget cb
1
1659 | HCfirst
-> cbget cb ~
-(cb
.rc)
1660 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1661 and cancel
() = cb
.rc <- rc
1665 let search pattern forward
=
1666 if String.length pattern
> 0
1669 match state.layout with
1672 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1675 let b = makecmd "search"
1676 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
1678 Buffer.add_char
b '
,'
;
1679 Buffer.add_string
b pattern
;
1680 Buffer.add_char
b '
\000'
;
1683 writecmd state.csock
cmd;
1686 let intentry text key =
1687 let c = Char.unsafe_chr
key in
1690 let text = addchar text c in
1694 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1698 let textentry text key =
1699 let c = Char.unsafe_chr
key in
1701 | _ when key >= 32 && key < 127 ->
1702 let text = addchar text c in
1706 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
1710 let reqlayout angle proportional
=
1711 match state.throttle
with
1713 if state.invalidated
= 0 then state.anchor <- getanchor ();
1714 conf.angle
<- angle
mod 360;
1715 conf.proportional
<- proportional
;
1717 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
1721 let settrim trimmargins trimfuzz
=
1722 if state.invalidated
= 0 then state.anchor <- getanchor ();
1723 conf.trimmargins
<- trimmargins
;
1724 conf.trimfuzz
<- trimfuzz
;
1725 let x0, y0
, x1
, y1
= trimfuzz
in
1728 `
b conf.trimmargins
;
1734 Hashtbl.iter
(fun _ opaque
->
1735 wcmd "freepage" [`
s opaque
];
1737 Hashtbl.clear
state.pagemap
;
1741 match state.throttle
with
1743 let zoom = max
0.01 zoom in
1744 if zoom <> conf.zoom
1746 state.prevzoom
<- conf.zoom;
1749 then (state.x <- 0; 0.0)
1750 else float state.x /. float state.w
1753 reshape conf.winw
conf.winh
;
1756 let x = relx *. float state.w in
1757 state.x <- truncate
x;
1759 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
1765 let enterbirdseye () =
1766 let zoom = float conf.thumbw
/. float conf.winw
in
1767 let birdseyepageno =
1768 let cy = conf.winh
/ 2 in
1772 let rec fold best
= function
1775 let d = cy - (l.pagedispy
+ l.pagevh/2)
1776 and dbest
= cy - (best
.pagedispy
+ best
.pagevh/2) in
1777 if abs
d < abs dbest
1784 state.mode
<- Birdseye
(
1785 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
1788 conf.presentation <- false;
1789 conf.interpagespace <- 10;
1790 conf.hlinks
<- false;
1792 state.mstate
<- Mnone
;
1793 conf.showall
<- false;
1794 Glut.setCursor
Glut.CURSOR_INHERIT
;
1797 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1802 reshape conf.winw
conf.winh
;
1805 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
1807 conf.zoom <- c.zoom;
1808 conf.presentation <- c.presentation;
1809 conf.interpagespace <- c.interpagespace;
1810 conf.showall
<- c.showall
;
1811 conf.hlinks
<- c.hlinks
;
1815 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1818 reshape conf.winw
conf.winh
;
1819 state.anchor <- if goback
then anchor else (pageno, 0.0);
1822 let togglebirdseye () =
1823 match state.mode
with
1824 | Birdseye vals
-> leavebirdseye vals
true
1825 | View
-> enterbirdseye ()
1829 let upbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
1830 let pageno = max
0 (pageno - 1) in
1831 let rec loop = function
1832 | [] -> gotopage1 pageno 0
1833 | l :: _ when l.pageno = pageno ->
1834 if l.pagedispy
>= 0 && l.pagey = 0
1835 then G.postRedisplay "upbirdseye"
1836 else gotopage1 pageno 0
1837 | _ :: rest
-> loop rest
1840 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
1843 let downbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
1844 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
1845 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
1846 let rec loop = function
1848 let y, h = getpageyh pageno in
1849 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
1851 | l :: _ when l.pageno = pageno ->
1852 if l.pagevh != l.pageh
1853 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
1854 else G.postRedisplay "downbirdseye"
1855 | _ :: rest
-> loop rest
1860 let optentry mode
_ key =
1861 let btos b = if b then "on" else "off" in
1862 let c = Char.unsafe_chr
key in
1866 try conf.scrollstep
<- int_of_string
s with exc
->
1867 state.text <- Printf.sprintf
"bad integer `%s': %s"
1868 s (Printexc.to_string exc
)
1870 TEswitch
("scroll step: ", "", None
, intentry, ondone)
1875 conf.autoscrollstep
<- int_of_string
s;
1876 if state.autoscroll
<> None
1877 then state.autoscroll
<- Some
conf.autoscrollstep
1879 state.text <- Printf.sprintf
"bad integer `%s': %s"
1880 s (Printexc.to_string exc
)
1882 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
1887 let zoom = float (int_of_string
s) /. 100.0 in
1890 state.text <- Printf.sprintf
"bad integer `%s': %s"
1891 s (Printexc.to_string exc
)
1893 TEswitch
("zoom: ", "", None
, intentry, ondone)
1898 conf.thumbw
<- bound (int_of_string
s) 2 4096;
1900 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
1901 begin match mode
with
1903 leavebirdseye beye
false;
1908 state.text <- Printf.sprintf
"bad integer `%s': %s"
1909 s (Printexc.to_string exc
)
1911 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
1916 Some
(int_of_string
s)
1918 state.text <- Printf.sprintf
"bad integer `%s': %s"
1919 s (Printexc.to_string exc
);
1922 | Some angle
-> reqlayout angle
conf.proportional
1925 TEswitch
("rotation: ", "", None
, intentry, ondone)
1928 conf.icase
<- not
conf.icase
;
1929 TEdone
("case insensitive search " ^
(btos conf.icase
))
1932 conf.preload <- not
conf.preload;
1934 TEdone
("preload " ^
(btos conf.preload))
1937 conf.verbose
<- not
conf.verbose
;
1938 TEdone
("verbose " ^
(btos conf.verbose
))
1941 conf.debug
<- not
conf.debug
;
1942 TEdone
("debug " ^
(btos conf.debug
))
1945 conf.maxhfit
<- not
conf.maxhfit
;
1946 state.maxy <- state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
1947 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
1950 conf.crophack
<- not
conf.crophack
;
1951 TEdone
("crophack " ^
btos conf.crophack
)
1954 conf.showall
<- not
conf.showall
;
1955 TEdone
("throttle " ^
btos conf.showall
)
1958 conf.underinfo
<- not
conf.underinfo
;
1959 TEdone
("underinfo " ^
btos conf.underinfo
)
1962 conf.savebmarks
<- not
conf.savebmarks
;
1963 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
1969 match state.layout with
1974 conf.interpagespace <- int_of_string
s;
1975 state.maxy <- calcheight ();
1976 let y = getpagey pageno in
1979 state.text <- Printf.sprintf
"bad integer `%s': %s"
1980 s (Printexc.to_string exc
)
1982 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
1985 reqlayout conf.angle
(not
conf.proportional
);
1986 TEdone
("proportional display " ^
btos conf.proportional
)
1989 settrim (not
conf.trimmargins
) conf.trimfuzz
;
1990 TEdone
("trim margins " ^
btos conf.trimmargins
)
1993 conf.invert
<- not
conf.invert
;
1994 TEdone
("invert colors " ^
btos conf.invert
)
1997 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2001 let maxoutlinerows () = (conf.winh
- !uifontsize - 1) / (!uifontsize + 1);;
2003 class type lvsource
= object
2004 method getitemcount
: int
2005 method getitem
: int -> (string * int)
2006 method hasaction
: int -> bool
2015 method getactive
: int
2016 method getfirst
: int
2017 method getqsearch
: string
2018 method setqsearch
: string -> unit
2022 class virtual lvsourcebase
= object
2023 val mutable m_active
= 0
2024 val mutable m_first
= 0
2025 val mutable m_qsearch
= ""
2026 val mutable m_pan
= 0
2027 method getactive
= m_active
2028 method getfirst
= m_first
2029 method getqsearch
= m_qsearch
2030 method getpan
= m_pan
2031 method setqsearch
s = m_qsearch
<- s
2034 let textentryspecial key = function
2035 | ((c, _, (Some
(action, _) as onhist), onkey
, ondone), mode
) ->
2038 | Glut.KEY_UP
-> action HCprev
2039 | Glut.KEY_DOWN
-> action HCnext
2040 | Glut.KEY_HOME
-> action HCfirst
2041 | Glut.KEY_END
-> action HClast
2044 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2045 G.postRedisplay "special textentry";
2049 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2051 state.mode
<- Textentry
(te
, onleave
);
2054 G.postRedisplay "textentrykeyboard enttext";
2056 match Char.unsafe_chr
key with
2057 | '
\008'
-> (* backspace *)
2058 let len = String.length
text in
2062 G.postRedisplay "textentrykeyboard after cancel";
2065 let s = String.sub
text 0 (len - 1) in
2066 enttext (c, s, opthist
, onkey
, ondone)
2072 G.postRedisplay "textentrykeyboard after confirm"
2074 | '
\007'
(* ctrl-g *)
2075 | '
\027'
-> (* escape *)
2076 if String.length
text = 0
2078 begin match opthist
with
2080 | Some
(_, onhistcancel
) -> onhistcancel
()
2084 G.postRedisplay "textentrykeyboard after cancel2"
2087 enttext (c, "", opthist
, onkey
, ondone)
2090 | '
\127'
-> () (* delete *)
2093 begin match onkey
text key with
2097 G.postRedisplay "textentrykeyboard after confirm2";
2100 enttext (c, text, opthist
, onkey
, ondone);
2105 G.postRedisplay "textentrykeyboard after cancel3"
2108 state.mode
<- Textentry
(te
, onleave
);
2109 G.postRedisplay "textentrykeyboard switch";
2113 let firstof first active
=
2114 let maxrows = maxoutlinerows () in
2115 if first
> active
|| abs
(first
- active
) > maxrows - 1
2116 then max
0 (active
- (maxrows/2))
2120 class listview ~
(source
:lvsource
) ~trusted
=
2121 let coe s = (s :> uioh
) in
2123 val m_pan
= source#getpan
2124 val m_first
= source#getfirst
2125 val m_active
= source#getactive
2126 val m_qsearch
= source#getqsearch
2127 val m_prev_uioh
= state.uioh
2129 method private elemunder
y =
2130 let n = y / (!uifontsize+1) in
2131 if m_first
+ n < source#getitemcount
2133 if source#hasaction
(m_first
+ n)
2134 then Some
(m_first
+ n)
2141 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2142 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2143 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2144 GlDraw.color
(1., 1., 1.);
2145 Gl.enable `texture_2d
;
2146 let fs = !uifontsize in
2148 let ww = measurestr
fs "w" in
2149 let tabw = 30.0*.ww in
2151 if (row - m_first
) * nfs > conf.winh
2154 if row >= 0 && row < source#getitemcount
2156 let (s, level
) = source#getitem
row in
2157 let y = (row - m_first
) * nfs in
2158 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2161 Gl.disable `texture_2d
;
2162 GlDraw.polygon_mode `both `line
;
2163 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2164 GlDraw.rect (1., float (y + 1))
2165 (float (conf.winw
- 1), float (y + fs + 3));
2166 GlDraw.polygon_mode `both `fill
;
2167 GlDraw.color
(1., 1., 1.);
2168 Gl.enable `texture_2d
;
2171 let drawtabularstring s =
2172 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2175 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2178 let len = String.length
s - tabpos - 1 in
2179 let s1 = String.sub
s 0 tabpos
2180 and s2
= String.sub
s (tabpos + 1) len in
2181 let nx = drawstr x s1 in
2183 let x = x +. (max
tabw sw) in
2190 let _ = drawtabularstring s in
2197 Gl.disable `texture_2d
;
2199 method private key1
key =
2200 let set active first qsearch
=
2201 coe {< m_active
= active
; m_first
= first
; m_qsearch
= qsearch
>}
2203 let search active pattern incr
=
2206 if n >= 0 && n < source#getitemcount
2208 let s, _ = source#getitem
n in
2210 (try ignore
(Str.search_forward
re s 0); true
2211 with Not_found
-> false)
2213 else loop (n + incr
)
2220 let re = Str.regexp_case_fold pattern
in
2227 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2228 let incr = if key = 18 then -1 else 1 in
2230 match search (m_active
+ incr) m_qsearch
incr with
2232 state.text <- m_qsearch ^
" [not found]";
2235 state.text <- m_qsearch
;
2236 active, firstof m_first
active
2238 G.postRedisplay "listview ctrl-r/s";
2239 set active first m_qsearch
;
2241 | 8 -> (* backspace *)
2242 let len = String.length m_qsearch
in
2249 G.postRedisplay "listview empty qsearch";
2250 set m_active m_first
"";
2253 let qsearch = String.sub m_qsearch
0 (len - 1) in
2255 match search m_active
qsearch ~
-1 with
2257 state.text <- qsearch ^
" [not found]";
2260 state.text <- qsearch;
2261 active, firstof m_first
active
2263 G.postRedisplay "listview backspace qsearch";
2264 set active first
qsearch
2267 | _ when key >= 32 && key < 127 ->
2268 let pattern = addchar m_qsearch
(Char.chr
key) in
2270 match search m_active
pattern 1 with
2272 state.text <- pattern ^
" [not found]";
2275 state.text <- pattern;
2276 active, firstof m_first
active
2278 G.postRedisplay "listview qsearch add";
2279 set active first
pattern;
2281 | 27 -> (* escape *)
2283 if String.length m_qsearch
= 0
2285 G.postRedisplay "list view escape";
2288 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2290 | None
-> m_prev_uioh
2295 G.postRedisplay "list view kill qsearch";
2296 source#setqsearch
"";
2297 coe {< m_qsearch
= "" >}
2302 let self = {< m_qsearch
= "" >} in
2303 source#setqsearch
"";
2305 G.postRedisplay "listview enter";
2306 if m_active
>= 0 && m_active
< source#getitemcount
2308 source#exit
(coe self) false m_active m_first m_pan
"";
2311 source#exit
(coe self) true m_active m_first m_pan
"";
2314 begin match opt with
2315 | None
-> m_prev_uioh
2319 | 127 -> (* delete *)
2322 | _ -> dolog "unknown key %d" key; coe self
2324 method private special1
key =
2325 let maxrows = maxoutlinerows () in
2326 let itemcount = source#getitemcount
in
2327 let find start
incr =
2329 if i
= -1 || i
= itemcount
2332 if source#hasaction i
2334 else find (i
+ incr)
2339 let set active first
=
2340 let first = bound first 0 (itemcount - maxrows) in
2342 coe {< m_active
= active; m_first
= first >}
2345 let isvisible first n = n >= first && n - first <= maxrows in
2347 let incr1 = if incr > 0 then 1 else -1 in
2348 if isvisible m_first m_active
2351 let next = m_active
+ incr in
2353 if next < 0 || next >= itemcount
2355 else find next incr1
2357 if next = -1 || abs
(m_active
- next) > maxrows
2363 let first = m_first
+ incr in
2364 let first = bound first 0 (itemcount - 1) in
2366 let next = m_active
+ incr in
2367 let next = bound next 0 (itemcount - 1) in
2370 let active = if next = -1 then m_active
else next in
2373 let first = min
next m_first
in
2376 let first = m_first
+ incr in
2377 let first = bound first 0 (itemcount - 1) in
2379 let next = m_active
+ incr in
2380 let next = bound next 0 (itemcount - 1) in
2381 let next = find next incr1 in
2382 if next = -1 || abs
(m_active
- first) > maxrows
2388 G.postRedisplay "listview navigate";
2391 begin match key with
2392 | Glut.KEY_UP
-> navigate ~
-1
2393 | Glut.KEY_DOWN
-> navigate 1
2394 | Glut.KEY_PAGE_UP
-> navigate ~
-maxrows
2395 | Glut.KEY_PAGE_DOWN
-> navigate maxrows
2399 G.postRedisplay "listview right";
2400 coe {< m_pan
= m_pan
- 1 >}
2404 G.postRedisplay "listview left";
2405 coe {< m_pan
= m_pan
+ 1 >}
2408 let active = find 0 1 in
2409 G.postRedisplay "listview home";
2413 let first = max
0 (itemcount - maxrows) in
2414 let active = find (itemcount - 1) ~
-1 in
2415 G.postRedisplay "listview end";
2422 match state.mode
with
2423 | Textentry te
-> textentrykeyboard key te
; coe self
2424 | _ -> self#key1
key
2426 method special
key =
2427 match state.mode
with
2428 | Textentry te
-> textentryspecial key te
; coe self
2429 | _ -> self#special1
key
2431 method button button bstate
_ y =
2434 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2435 begin match self#elemunder
y with
2437 G.postRedisplay "listview click";
2438 source#exit
(coe {< m_active
= n >}) false n m_first m_pan m_qsearch
2442 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2443 let len = source#getitemcount
in
2445 if m_first
+ maxoutlinerows () >= len
2449 let first = m_first
+ (if n == 3 then -1 else 1) in
2450 bound first 0 (len - 1)
2452 G.postRedisplay "listview wheel";
2453 Some
(coe {< m_first
= first >})
2458 | None
-> m_prev_uioh
2461 method motion
_ _ = coe self
2463 method pmotion
_ y =
2465 match self#elemunder
y with
2466 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
2467 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
2471 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
2476 method memusedchanged
= ()
2479 class outlinelistview ~source
: uioh
=
2480 let coe o = (o :> uioh
) in
2482 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
2486 | 14 -> (* ctrl-n *)
2487 source#narrow m_qsearch
;
2488 G.postRedisplay "outline ctrl-n";
2489 coe {< m_first
= 0; m_active
= 0 >}
2491 | 21 -> (* ctrl-u *)
2493 G.postRedisplay "outline ctrl-u";
2494 coe {< m_first
= 0; m_active
= 0 >}
2496 | 12 -> (* ctrl-l *)
2497 let first = m_active
- (maxoutlinerows () / 2) in
2498 G.postRedisplay "outline ctrl-l";
2499 coe {< m_first
= first >}
2501 | 127 -> (* delete *)
2502 source#remove m_active
;
2503 G.postRedisplay "outline delete";
2504 let active = max
0 (m_active
-1) in
2505 coe {< m_first
= firstof m_first
active; m_active
= active >}
2507 | key -> super#
key key
2509 method special
key =
2510 let maxrows = maxoutlinerows () in
2511 let calcfirst first active =
2514 let rows = active - first in
2515 if rows > maxrows then active - maxrows else first
2519 let active = m_active
+ incr in
2520 let active = bound active 0 (source#getitemcount
- 1) in
2521 let first = calcfirst m_first
active in
2522 G.postRedisplay "special outline navigate";
2523 coe {< m_active
= active; m_first
= first >}
2525 let updownlevel incr =
2526 let len = source#getitemcount
in
2527 let _, curlevel
= source#getitem m_active
in
2529 if i
= len then i
-1 else if i
= -1 then 0 else
2530 let _, l = source#getitem i
in
2531 if l != curlevel
then i
else flow (i
+incr)
2533 let active = flow m_active
in
2534 let first = calcfirst m_first
active in
2535 G.postRedisplay "special outline updownlevel";
2536 {< m_active
= active; m_first
= first >}
2539 | Glut.KEY_UP
-> navigate ~
-1
2540 | Glut.KEY_DOWN
-> navigate 1
2541 | Glut.KEY_PAGE_UP
-> navigate ~
-maxrows
2542 | Glut.KEY_PAGE_DOWN
-> navigate maxrows
2546 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2548 G.postRedisplay "special outline right";
2549 {< m_pan
= m_pan
+ 1 >}
2557 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2559 G.postRedisplay "special outline left";
2560 {< m_pan
= m_pan
- 1 >}
2562 else updownlevel ~
-1
2567 G.postRedisplay "special outline home";
2568 coe {< m_first
= 0; m_active
= 0 >}
2571 let active = source#getitemcount
- 1 in
2572 let first = max
0 (active - maxrows) in
2573 G.postRedisplay "special outline end";
2574 coe {< m_active
= active; m_first
= first >}
2576 | _ -> super#special
key
2579 let outlinesource usebookmarks
=
2582 inherit lvsourcebase
2583 val mutable m_items
= empty
2584 val mutable m_orig_items
= empty
2585 val mutable m_prev_items
= empty
2586 val mutable m_narrow_pattern
= ""
2587 val mutable m_hadremovals
= false
2589 method getitemcount
= Array.length m_items
+ (if m_hadremovals
then 1 else 0)
2592 if n == Array.length m_items
&& m_hadremovals
2594 ("[Confirm removal]", 0)
2596 let s, n, _ = m_items
.(n) in
2599 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
2600 ignore
(uioh
, first, pan
, qsearch);
2601 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
2603 if String.length m_narrow_pattern
= 0
2609 if not
confrimremoval
2611 let _, _, anchor = m_items
.(active) in
2616 state.bookmarks
<- Array.to_list m_items
;
2617 m_orig_items
<- m_items
;
2620 else m_items
<- items;
2623 method hasaction
_ = true
2626 if Array.length m_items
!= Array.length m_orig_items
2627 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
2630 method narrow
pattern =
2631 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
2635 let rec loop accu n =
2638 m_narrow_pattern
<- pattern;
2639 m_items
<- Array.of_list
accu
2642 let (s, _, _) as o = m_items
.(n) in
2644 if (try ignore
(Str.search_forward
re s 0); true
2645 with Not_found
-> false)
2651 loop [] (Array.length m_items
- 1)
2656 then Array.of_list
state.bookmarks
2659 m_items
<- m_orig_items
2664 if m
>= 0 && m
< Array.length m_items
2666 m_hadremovals
<- true;
2667 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
2668 let n = if n >= m
then n+1 else n in
2673 method reset
pageno items =
2674 m_hadremovals
<- false;
2675 if m_orig_items
== empty || m_prev_items
!= items
2677 m_orig_items
<- items;
2678 if String.length m_narrow_pattern
= 0
2679 then m_items
<- items;
2681 m_prev_items
<- items;
2683 let rec loop n best bestd
=
2684 if n = Array.length m_items
2687 let (_, _, (outlinepageno
, _)) = m_items
.(n) in
2688 let d = abs
(outlinepageno
- pageno) in
2691 else loop (n+1) best bestd
2696 m_first
<- firstof m_first
active
2700 let enterselector usebookmarks
=
2701 let source = outlinesource usebookmarks
in
2705 then Array.of_list
state.bookmarks
2708 if Array.length
outlines = 0
2710 showtext ' ' errmsg
;
2713 state.text <- source#greetmsg
;
2714 Glut.setCursor
Glut.CURSOR_INHERIT
;
2716 match state.layout with
2718 | {pageno=pageno} :: _ -> pageno
2720 source#reset
pageno outlines;
2721 state.uioh
<- new outlinelistview ~
source;
2722 G.postRedisplay "enter selector";
2726 let enteroutlinemode =
2727 let f = enterselector false in
2728 fun ()-> f "Document has no outline";
2731 let enterbookmarkmode =
2732 let f = enterselector true in
2733 fun () -> f "Document has no bookmarks (yet)";
2736 let color_of_string s =
2737 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
2738 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
2742 let color_to_string (r, g
, b) =
2743 let r = truncate
(r *. 256.0)
2744 and g
= truncate
(g
*. 256.0)
2745 and b = truncate
(b *. 256.0) in
2746 Printf.sprintf
"%d/%d/%d" r g
b
2749 let irect_of_string s =
2750 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0,y0
,x1
,y1
))
2753 let irect_to_string (x0,y0
,x1
,y1
) =
2754 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
2757 let makecheckers () =
2758 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
2760 converted by Issac Trotts. July 25, 2002 *)
2761 let image_height = 64
2762 and image_width
= 64 in
2766 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height in
2767 for i
= 0 to image_width
- 1 do
2768 for j
= 0 to image_height - 1 do
2769 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
2770 (if (i
land 8 ) lxor (j
land 8) = 0
2771 then [|255;255;255|] else [|200;200;200|])
2776 let image = make_image () in
2777 let id = GlTex.gen_texture
() in
2778 GlTex.bind_texture `texture_2d
id;
2779 GlPix.store
(`unpack_alignment
1);
2780 GlTex.image2d
image;
2781 List.iter
(GlTex.parameter ~target
:`texture_2d
)
2784 `mag_filter `nearest
;
2785 `min_filter `nearest
];
2789 let setcheckers enabled
=
2790 match state.texid
with
2792 if enabled
then state.texid
<- Some
(makecheckers ())
2797 GlTex.delete_texture texid
;
2798 state.texid
<- None
;
2802 let int_of_string_with_suffix s =
2803 let l = String.length
s in
2807 let suffix = Char.lowercase
s.[l-1] in
2809 | 'k'
-> String.sub
s 0 (l-1), 10
2810 | 'm'
-> String.sub
s 0 (l-1), 20
2811 | 'g'
-> String.sub
s 0 (l-1), 30
2815 let n = int_of_string
s1 in
2816 let m = n lsl shift
in
2818 then raise
(Failure
"value too large")
2822 let string_with_suffix_of_int n =
2830 if n land ((1 lsl 20) - 1) = 0
2833 if n land ((1 lsl 10) - 1) = 0
2840 let h = n mod 1000 in
2843 then string_of_int
h ^
s
2845 let s = Printf.sprintf
"_%03d%s" h s in
2852 let describe_location () =
2854 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
2856 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
2857 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
2861 else (100. *. (float state.y /. float maxy))
2865 Printf.sprintf
"page %d of %d [%.2f%%]"
2866 (fn+1) state.pagecount
percent
2869 "pages %d-%d of %d [%.2f%%]"
2870 (fn+1) (ln
+1) state.pagecount
percent
2873 let rec enterinfomode =
2874 let btos b = if b then "\xe2\x88\x9a" else "" in
2875 let showextended = ref false in
2876 let leave mode
= function
2877 | Confirm
-> state.mode
<- mode
2878 | Cancel
-> state.mode
<- mode
in
2881 val mutable m_first_time
= true
2882 val mutable m_l
= []
2883 val mutable m_a
= [||]
2884 val mutable m_prev_uioh
= nouioh
2885 val mutable m_prev_mode
= View
2887 inherit lvsourcebase
2889 method reset prev_mode prev_uioh
=
2890 m_a
<- Array.of_list
(List.rev m_l
);
2892 m_prev_mode
<- prev_mode
;
2893 m_prev_uioh
<- prev_uioh
;
2897 if n >= Array.length m_a
2901 | _, _, _, Action
_ -> m_active
<- n
2905 m_first_time
<- false;
2908 method int name get
set =
2910 (name
, `
int get
, 1, Action
(
2913 try set (int_of_string
s)
2915 state.text <- Printf.sprintf
"bad integer `%s': %s"
2916 s (Printexc.to_string exn
)
2919 let te = name ^
": ", "", None
, intentry, ondone in
2920 state.mode
<- Textentry
(te, leave m_prev_mode
);
2924 method int_with_suffix name get
set =
2926 (name
, `intws get
, 1, Action
(
2929 try set (int_of_string_with_suffix s)
2931 state.text <- Printf.sprintf
"bad integer `%s': %s"
2932 s (Printexc.to_string exn
)
2936 name ^
": ", "", None
, intentry_with_suffix, ondone
2938 state.mode
<- Textentry
(te, leave m_prev_mode
);
2942 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
2944 (name
, `
bool (btos, get
), offset
, Action
(
2951 method color name get
set =
2953 (name
, `color get
, 1, Action
(
2955 let invalid = (nan
, nan
, nan
) in
2958 try color_of_string s
2960 state.text <- Printf.sprintf
"bad color `%s': %s"
2961 s (Printexc.to_string exn
);
2967 let te = name ^
": ", "", None
, textentry, ondone in
2968 state.text <- color_to_string (get
());
2969 state.mode
<- Textentry
(te, leave m_prev_mode
);
2973 method string name get
set =
2975 (name
, `
string get
, 1, Action
(
2977 let ondone s = set s in
2978 let te = name ^
": ", "", None
, textentry, ondone in
2979 state.mode
<- Textentry
(te, leave m_prev_mode
);
2983 method colorspace name get
set =
2985 (name
, `
string get
, 1, Action
(
2988 let vals = [| "rgb"; "bgr"; "gray" |] in
2990 inherit lvsourcebase
2993 m_active
<- int_of_colorspace conf.colorspace
;
2996 method getitemcount
= Array.length
vals
2997 method getitem
n = (vals.(n), 0)
2998 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
2999 ignore
(uioh
, first, pan
, qsearch);
3000 if not cancel
then set active;
3002 method hasaction
_ = true
3006 new listview ~
source ~trusted
:true
3009 method caption
s offset
=
3010 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3012 method caption2
s f offset
=
3013 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3015 method getitemcount
= Array.length m_a
3018 let tostr = function
3019 | `
int f -> string_of_int
(f ())
3020 | `intws
f -> string_with_suffix_of_int (f ())
3022 | `color
f -> color_to_string (f ())
3023 | `
bool (btos, f) -> btos (f ())
3026 let name, t
, offset
, _ = m_a
.(n) in
3027 ((let s = tostr t
in
3028 if String.length
s > 0
3029 then Printf.sprintf
"%s\t%s" name s
3033 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3037 m_qsearch
<- qsearch;
3039 match m_a
.(active) with
3040 | _, _, _, Action
f -> f uioh
3052 method hasaction
n =
3054 | _, _, _, Action
_ -> true
3059 let sep () = src#caption
"" 0 in
3060 let colorp name get
set =
3062 (fun () -> color_to_string (get
()))
3065 let c = color_of_string v in
3068 state.text <- Printf.sprintf
"bad color `%s': %s"
3069 v (Printexc.to_string exn
);
3072 let oldmode = state.mode
in
3073 let birdseye = isbirdseye state.mode
in
3076 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3078 src#
bool "presentation mode"
3079 (fun () -> conf.presentation)
3081 conf.presentation <- v;
3082 state.anchor <- getanchor ();
3085 src#
bool "ignore case in searches"
3086 (fun () -> conf.icase
)
3087 (fun v -> conf.icase
<- v);
3090 (fun () -> conf.preload)
3091 (fun v -> conf.preload <- v);
3094 (fun () -> conf.showall
)
3095 (fun v -> conf.showall
<- v);
3097 src#
bool "highlight links"
3098 (fun () -> conf.hlinks
)
3099 (fun v -> conf.hlinks
<- v);
3101 src#
bool "under info"
3102 (fun () -> conf.underinfo
)
3103 (fun v -> conf.underinfo
<- v);
3105 src#
bool "persistent bookmarks"
3106 (fun () -> conf.savebmarks
)
3107 (fun v -> conf.savebmarks
<- v);
3109 src#
bool "proportional display"
3110 (fun () -> conf.proportional
)
3111 (fun v -> reqlayout conf.angle
v);
3113 src#
bool "trim margins"
3114 (fun () -> conf.trimmargins
)
3115 (fun v -> settrim v conf.trimfuzz
);
3117 src#
bool "persistent location"
3118 (fun () -> conf.jumpback
)
3119 (fun v -> conf.jumpback
<- v);
3122 src#
int "vertical margin"
3123 (fun () -> conf.interpagespace)
3125 conf.interpagespace <- n;
3127 match state.layout with
3132 state.maxy <- calcheight ();
3133 let y = getpagey pageno in
3138 (fun () -> conf.pagebias
)
3139 (fun v -> conf.pagebias
<- v);
3141 src#
int "scroll step"
3142 (fun () -> conf.scrollstep
)
3143 (fun n -> conf.scrollstep
<- n);
3145 src#
int "auto scroll step"
3147 match state.autoscroll
with
3149 | _ -> conf.autoscrollstep
)
3151 if state.autoscroll
<> None
3152 then state.autoscroll
<- Some
n;
3153 conf.autoscrollstep
<- n);
3156 (fun () -> truncate
(conf.zoom *. 100.))
3157 (fun v -> setzoom ((float v) /. 100.));
3160 (fun () -> conf.angle
)
3161 (fun v -> reqlayout v conf.proportional
);
3163 src#
int "scroll bar width"
3164 (fun () -> state.scrollw
)
3168 reshape conf.winw
conf.winh
;
3171 src#
int "scroll handle height"
3172 (fun () -> conf.scrollh
)
3173 (fun v -> conf.scrollh
<- v;);
3175 src#
int "thumbnail width"
3176 (fun () -> conf.thumbw
)
3178 conf.thumbw
<- min
4096 v;
3181 leavebirdseye beye
false;
3187 src#caption
"Presentation mode" 0;
3188 src#
bool "scrollbar visible"
3189 (fun () -> conf.scrollbarinpm
)
3191 if v != conf.scrollbarinpm
3193 conf.scrollbarinpm
<- v;
3194 if conf.presentation
3196 state.scrollw
<- if v then conf.scrollbw
else 0;
3197 reshape conf.winw
conf.winh
;
3203 src#caption
"Pixmap cache" 0;
3204 src#int_with_suffix
"size (advisory)"
3205 (fun () -> conf.memlimit
)
3206 (fun v -> conf.memlimit
<- v);
3209 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3210 (string_with_suffix_of_int state.memused
)
3211 (Hashtbl.length
state.tilemap
)) 1;
3214 src#caption
"Layout" 0;
3215 src#caption2
"Dimension"
3217 Printf.sprintf
"%dx%d (virtual %dx%d)"
3223 src#caption2
"Position" (fun () ->
3224 Printf.sprintf
"%dx%d" state.x state.y
3227 src#caption2
"Visible" (fun () -> describe_location ()) 1
3231 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3232 "Save these parameters as global defaults at exit"
3233 (fun () -> conf.bedefault
)
3234 (fun v -> conf.bedefault
<- v)
3238 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3239 src#
bool ~offset
:0 ~
btos "Extended parameters"
3240 (fun () -> !showextended)
3241 (fun v -> showextended := v; enterinfomode ());
3245 (fun () -> conf.checkers
)
3246 (fun v -> conf.checkers
<- v; setcheckers v);
3248 (fun () -> conf.verbose
)
3249 (fun v -> conf.verbose
<- v);
3250 src#
bool "invert colors"
3251 (fun () -> conf.invert
)
3252 (fun v -> conf.invert
<- v);
3254 (fun () -> conf.maxhfit
)
3255 (fun v -> conf.maxhfit
<- v);
3256 src#
string "uri launcher"
3257 (fun () -> conf.urilauncher
)
3258 (fun v -> conf.urilauncher
<- v);
3259 src#
string "tile size"
3260 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3263 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3264 conf.tileh
<- max
64 w;
3265 conf.tilew
<- max
64 h;
3268 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3269 v (Printexc.to_string exn
));
3270 src#
int "anti-aliasing level"
3271 (fun () -> conf.aalevel
)
3273 conf.aalevel
<- bound v 0 8;
3274 state.anchor <- getanchor ();
3275 opendoc state.path
state.password
;
3277 src#
int "ui font size"
3278 (fun () -> !uifontsize)
3279 (fun v -> uifontsize := bound v 5 100);
3280 colorp "background color"
3281 (fun () -> conf.bgcolor
)
3282 (fun v -> conf.bgcolor
<- v);
3283 src#
bool "crop hack"
3284 (fun () -> conf.crophack
)
3285 (fun v -> conf.crophack
<- v);
3286 src#
string "trim fuzz"
3287 (fun () -> irect_to_string conf.trimfuzz
)
3290 conf.trimfuzz
<- irect_of_string v;
3292 then settrim true conf.trimfuzz
;
3294 state.text <- Printf.sprintf
"bad irect `%s': %s"
3295 v (Printexc.to_string exn
)
3297 src#colorspace
"color space"
3298 (fun () -> colorspace_to_string conf.colorspace
)
3300 conf.colorspace
<- colorspace_of_int v;
3307 src#caption
"Document" 0;
3308 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3310 src#reset
state.mode
state.uioh;
3311 let source = (src :> lvsource
) in
3312 state.uioh <- object
3313 inherit listview ~
source ~trusted
:true
3314 val mutable m_prevmemused
= 0
3315 method memusedchanged
=
3316 if m_prevmemused
!= state.memused
3318 m_prevmemused
<- state.memused
;
3319 G.postRedisplay "memusedchanged";
3322 G.postRedisplay "info";
3328 inherit lvsourcebase
3329 method getitemcount
= Array.length
state.help
3331 let s, n, _ = state.help
.(n) in
3334 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3338 m_qsearch
<- qsearch;
3339 match state.help
.(active) with
3340 | _, _, Action
f -> Some
(f uioh)
3350 method hasaction
n =
3351 match state.help
.(n) with
3352 | _, _, Action
_ -> true
3359 state.uioh <- new listview ~
source ~trusted
:true;
3360 G.postRedisplay "help";
3363 let quickbookmark ?title
() =
3364 match state.layout with
3370 let sec = Unix.gettimeofday
() in
3371 let tm = Unix.localtime
sec in
3372 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
3376 (tm.Unix.tm_year
+ 1900)
3379 | Some
title -> title
3382 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
3387 state.fullscreen
<- None
;
3388 Glut.reshapeWindow
w h;
3391 let viewkeyboard key =
3393 let mode = state.mode in
3394 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
3397 G.postRedisplay "view:enttext"
3399 let c = Char.chr
key in
3401 | '
\027'
| 'q'
-> (* escape *)
3402 begin match state.mstate
with
3404 state.mstate
<- Mnone
;
3405 Glut.setCursor
Glut.CURSOR_INHERIT
;
3406 G.postRedisplay "kill zoom rect";
3411 | '
\008'
-> (* backspace *)
3412 let y = getnav ~
-1 in
3413 gotoy_and_clear_text y
3421 G.postRedisplay "dehighlight";
3424 let ondone isforw
s =
3425 cbput state.hists
.pat
s;
3426 state.searchpattern
<- s;
3429 let s = String.create
1 in
3431 enttext (s, "", Some
(onhist state.hists
.pat
),
3432 textentry, ondone (c ='
/'
))
3434 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3435 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3436 setzoom (conf.zoom +. incr)
3441 try int_of_string
s with exc
->
3442 state.text <- Printf.sprintf
"bad integer `%s': %s"
3443 s (Printexc.to_string exc
);
3449 state.text <- "page bias is now " ^ string_of_int
n;
3452 enttext ("page bias: ", "", None
, intentry, ondone)
3454 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3455 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3456 setzoom (max
0.01 (conf.zoom -. decr))
3459 let ondone msg
= state.text <- msg
in
3461 "option [acfhilpstvAPRSZTI]: ", "", None
,
3462 optentry state.mode, ondone
3465 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3468 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3469 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
3473 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3479 try int_of_string
s with exc
->
3480 state.text <- Printf.sprintf
"bad integer `%s': %s"
3481 s (Printexc.to_string exc
);
3487 cbput state.hists
.pag
(string_of_int
n);
3488 gotoy_and_clear_text (getpagey (n + conf.pagebias
- 1))
3491 let pageentry text key =
3492 match Char.unsafe_chr
key with
3493 | 'g'
-> TEdone
text
3494 | _ -> intentry text key
3496 let text = "x" in text.[0] <- c;
3497 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
3500 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
3501 reshape conf.winw
conf.winh
;
3504 conf.hlinks
<- not
conf.hlinks
;
3505 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
3506 G.postRedisplay "toggle highlightlinks";
3509 begin match state.autoscroll
with
3511 conf.autoscrollstep
<- step
;
3512 state.autoscroll
<- None
3514 if conf.autoscrollstep
= 0
3515 then state.autoscroll
<- Some
1
3516 else state.autoscroll
<- Some
conf.autoscrollstep
3520 conf.presentation <- not
conf.presentation;
3521 if conf.presentation
3523 if not
conf.scrollbarinpm
3524 then state.scrollw
<- 0;
3527 state.scrollw
<- conf.scrollbw
;
3529 showtext ' '
("presentation mode " ^
3530 if conf.presentation then "on" else "off");
3531 state.anchor <- getanchor ();
3535 begin match state.fullscreen
with
3537 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
3540 state.fullscreen
<- None
;
3545 gotoy_and_clear_text 0
3548 gotopage1 (state.pagecount
- 1) 0
3551 search state.searchpattern
true
3554 search state.searchpattern
false
3557 begin match state.layout with
3560 gotoy_and_clear_text (getpagey l.pageno)
3564 begin match List.rev
state.layout with
3567 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
3568 gotoy_and_clear_text (getpagey pageno)
3571 | '
\127'
-> (* del *)
3572 begin match state.layout with
3575 let pageno = max
0 (l.pageno-1) in
3576 gotoy_and_clear_text (getpagey pageno)
3580 showtext ' '
(describe_location ());
3583 begin match state.layout with
3586 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
3591 enterbookmarkmode ()
3601 match state.layout with
3604 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
3608 enttext ("bookmark: ", "", None
, textentry, ondone)
3612 showtext ' '
"Quick bookmark added";
3615 begin match state.layout with
3617 let rect = getpdimrect
l.pagedimno
in
3621 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
3622 truncate
(1.2 *. (rect.(3) -. rect.(0))))
3624 (truncate
(rect.(1) -. rect.(0)),
3625 truncate
(rect.(3) -. rect.(0)))
3627 let w = truncate
((float w)*.conf.zoom)
3628 and h = truncate
((float h)*.conf.zoom) in
3631 state.anchor <- getanchor ();
3632 doreshape (w + state.scrollw
) (h + conf.interpagespace)
3634 G.postRedisplay "z";
3639 | '
\000'
-> (* ctrl-2 *)
3640 let maxw = getmaxw
() in
3642 then setzoom (maxw /. float conf.winw
)
3645 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
3649 bound (state.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
3651 G.postRedisplay "brightness";
3654 begin match state.mode with
3655 | Birdseye beye
-> upbirdseye beye
3656 | _ -> gotoy (clamp (-conf.scrollstep
))
3660 begin match state.mode with
3661 | Birdseye beye
-> downbirdseye beye
3662 | _ -> gotoy (clamp conf.scrollstep
)
3666 state.anchor <- getanchor ();
3667 opendoc state.path
state.password
3669 | '
v'
when conf.debug
->
3672 match getopaque l.pageno with
3675 let x0, y0
, x1
, y1
= pagebbox opaque
in
3676 let a,b = float x0, float y0
in
3677 let c,d = float x1
, float y0
in
3678 let e,f = float x1
, float y1
in
3679 let h,j
= float x0, float y1
in
3680 let rect = (a,b,c,d,e,f,h,j
) in
3682 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
3684 G.postRedisplay "v";
3687 vlog "huh? %d %c" key (Char.chr
key);
3690 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
3692 | 27 -> (* escape *)
3693 leavebirdseye beye
true
3695 | 12 -> (* ctrl-l *)
3696 let y, h = getpageyh pageno in
3697 let top = (conf.winh
- h) / 2 in
3698 gotoy (max
0 (y - top))
3701 leavebirdseye beye
false
3707 let keyboard ~
key ~
x ~
y =
3710 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
3711 then wcmd "interrupt" []
3712 else state.uioh <- state.uioh#
key key
3715 let birdseyespecial key ((conf, leftx
, _, hooverpageno
, anchor) as beye
) =
3717 | Glut.KEY_UP
-> upbirdseye beye
3718 | Glut.KEY_DOWN
-> downbirdseye beye
3720 | Glut.KEY_PAGE_UP
->
3721 begin match state.layout with
3725 state.mode <- Birdseye
(
3726 conf, leftx
, l.pageno, hooverpageno
, anchor
3728 gotopage1 l.pageno 0;
3731 let layout = layout (state.y-conf.winh
) conf.winh
in
3733 | [] -> gotoy (clamp (-conf.winh
))
3735 state.mode <- Birdseye
(
3736 conf, leftx
, l.pageno, hooverpageno
, anchor
3738 gotopage1 l.pageno 0
3741 | [] -> gotoy (clamp (-conf.winh
))
3744 | Glut.KEY_PAGE_DOWN
->
3745 begin match List.rev
state.layout with
3747 let layout = layout (state.y + conf.winh
) conf.winh
in
3748 begin match layout with
3750 let incr = l.pageh
- l.pagevh in
3755 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
3757 G.postRedisplay "birdseye pagedown";
3759 else gotoy (clamp (incr + conf.interpagespace*2));
3763 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
3764 gotopage1 l.pageno 0;
3767 | [] -> gotoy (clamp conf.winh
)
3771 state.mode <- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
3775 let pageno = state.pagecount
- 1 in
3776 state.mode <- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3777 if not
(pagevisible state.layout pageno)
3780 match List.rev
state.pdims
with
3782 | (_, _, h, _) :: _ -> h
3784 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
3785 else G.postRedisplay "birdseye end";
3789 let setautoscrollspeed step goingdown
=
3790 let incr = max
1 ((abs step
) / 2) in
3791 let incr = if goingdown
then incr else -incr in
3792 let astep = step
+ incr in
3793 state.autoscroll
<- Some
astep;
3796 let special ~
key ~
x ~
y =
3799 state.uioh <- state.uioh#
special key
3804 match state.mode with
3805 | Textentry
_ -> scalecolor 0.4
3806 | View
-> scalecolor 1.0
3807 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
3808 if l.pageno = hooverpageno
3811 if l.pageno = pageno
3817 begin match getopaque l.pageno with
3819 if tileready l l.pagex l.pagey
3821 let x = l.pagedispx
- l.pagex
3822 and y = l.pagedispy
- l.pagey in
3823 postprocess opaque
conf.hlinks
x y;
3830 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3831 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
3832 let sh = float conf.winh
/. sh in
3833 let sh = max
sh (float conf.scrollh
) in
3838 else float y /. float maxy
3840 let position = (float conf.winh
-. sh) *. percent in
3843 if position +. sh > float conf.winh
3844 then float conf.winh
-. sh
3851 let winw = conf.winw - state.scrollw
- 1 in
3852 let fwinw = float winw in
3854 let sw = fwinw /. float state.w in
3855 let sw = fwinw *. sw in
3856 max
sw (float conf.scrollh
)
3859 let f = state.w+winw in
3860 let r = float (winw-x) /. float f in
3861 let p = fwinw *. r in
3865 if position +. sw > fwinw
3866 then fwinw -. position
3872 let scrollindicator () =
3873 GlDraw.color (0.64 , 0.64, 0.64);
3875 (float (conf.winw - state.scrollw
), 0.)
3876 (float conf.winw, float conf.winh
)
3879 (0., float (conf.winh
- state.hscrollh))
3880 (float (conf.winw - state.scrollw
- 1), float conf.winh
)
3882 GlDraw.color (0.0, 0.0, 0.0);
3884 let position, sh = scrollph state.y in
3886 (float (conf.winw - state.scrollw
), position)
3887 (float conf.winw, position +. sh)
3889 let position, sw = scrollpw state.x in
3891 (position, float (conf.winh
- state.hscrollh))
3892 (position +. sw, float conf.winh
)
3896 let pagetranslatepoint l x y =
3897 let dy = y - l.pagedispy
in
3898 let y = dy + l.pagey in
3899 let dx = x - l.pagedispx
in
3900 let x = dx + l.pagex in
3905 match state.mstate
with
3906 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
3909 | Msel
((x0, y0
), (x1
, y1
)) ->
3910 let rec loop = function
3912 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
3913 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
3915 match getopaque l.pageno with
3917 let dx, dy = pagetranslatepoint l 0 0 in
3922 GlMat.mode `modelview
;
3924 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
3925 seltext opaque
(x0, y0
, x1
, y1
);
3936 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
3937 GlDraw.polygon_mode `both `fill
;
3938 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3940 (fun (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
3942 if l.pageno = pageno
3944 let dx = float (l.pagedispx
- l.pagex) in
3945 let dy = float (l.pagedispy
- l.pagey) in
3946 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
3947 GlDraw.begins `quads
;
3949 GlDraw.vertex2
(x0+.dx, y0
+.dy);
3950 GlDraw.vertex2
(x1
+.dx, y1
+.dy);
3951 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
3952 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
3963 GlClear.color (scalecolor2 conf.bgcolor
);
3964 GlClear.clear
[`
color];
3965 List.iter
drawpage state.layout;
3970 begin match state.mstate
with
3971 | Mzoomrect
((x0, y0
), (x1
, y1
)) ->
3973 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
3974 GlDraw.polygon_mode `both `fill
;
3975 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3976 GlDraw.rect (float x0, float y0
)
3977 (float x1
, float y1
);
3982 Glut.swapBuffers
();
3986 let rec f = function
3988 begin match getopaque l.pageno with
3990 let x0 = l.pagedispx
in
3991 let x1 = x0 + l.pagevw in
3992 let y0 = l.pagedispy
in
3993 let y1 = y0 + l.pagevh in
3994 if y >= y0 && y <= y1 && x >= x0 && x <= x1
3996 let px, py = pagetranslatepoint l x y in
3997 match whatsunder opaque
px py with
4009 let zoomrect x y x1 y1 =
4012 and y0 = min
y y1 in
4013 gotoy (state.y + y0);
4014 state.anchor <- getanchor ();
4015 let zoom = (float conf.winw *. conf.zoom) /. float (x1 - x0) in
4016 state.x <- state.x - x0;
4018 Glut.setCursor
Glut.CURSOR_INHERIT
;
4019 state.mstate
<- Mnone
;
4023 let winw = conf.winw - state.scrollw
- 1 in
4024 let s = float x /. float winw in
4025 let destx = truncate
(float (state.w + winw) *. s) in
4026 state.x <- winw - destx;
4027 gotoy_and_clear_text state.y;
4028 state.mstate
<- Mscrollx
;
4032 let s = float y /. float conf.winh
in
4033 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4034 gotoy_and_clear_text desty;
4035 state.mstate
<- Mscrolly
;
4038 let viewmouse button bstate
x y =
4040 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4041 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4043 match state.mstate
with
4044 | Mzoom
(oldn
, i
) ->
4052 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4054 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4056 let zoom = conf.zoom -. incr in
4058 state.mstate
<- Mzoom
(n, 0);
4060 state.mstate
<- Mzoom
(n, i
+1);
4062 else state.mstate
<- Mzoom
(n, 0)
4064 | _ -> state.mstate
<- Mzoom
(n, 0)
4067 match state.autoscroll
with
4068 | Some step
-> setautoscrollspeed step
(n=4)
4072 then -conf.scrollstep
4073 else conf.scrollstep
4075 let incr = incr * 2 in
4076 let y = clamp incr in
4077 gotoy_and_clear_text y
4080 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4081 if bstate
= Glut.DOWN
4083 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4084 state.mstate
<- Mpan
(x, y)
4087 state.mstate
<- Mnone
4089 | Glut.RIGHT_BUTTON
->
4090 if bstate
= Glut.DOWN
4092 Glut.setCursor
Glut.CURSOR_CYCLE
;
4094 state.mstate
<- Mzoomrect
(p, p)
4097 match state.mstate
with
4098 | Mzoomrect
((x0, y0), _) -> zoomrect x0 y0 x y
4100 Glut.setCursor
Glut.CURSOR_INHERIT
;
4101 state.mstate
<- Mnone
4104 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4105 if bstate
= Glut.DOWN
4107 let position, sh = scrollph state.y in
4108 if y > truncate
position && y < truncate
(position +. sh)
4109 then state.mstate
<- Mscrolly
4112 state.mstate
<- Mnone
4114 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4115 if bstate
= Glut.DOWN
4117 let position, sw = scrollpw state.x in
4118 if x > truncate
position && x < truncate
(position +. sw)
4119 then state.mstate
<- Mscrollx
4122 state.mstate
<- Mnone
4124 | Glut.LEFT_BUTTON
->
4125 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4126 begin match dest with
4127 | Ulinkgoto
(pageno, top) ->
4131 gotopage1 pageno top;
4137 | Unone
when bstate
= Glut.DOWN
->
4138 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4139 state.mstate
<- Mpan
(x, y);
4141 | Unone
| Utext
_ ->
4142 if bstate
= Glut.DOWN
4144 if conf.angle
mod 360 = 0
4146 state.mstate
<- Msel
((x, y), (x, y));
4147 G.postRedisplay "mouse select";
4151 match state.mstate
with
4154 | Mzoom
_ | Mscrollx
| Mscrolly
->
4155 state.mstate
<- Mnone
4157 | Mzoomrect
((x0, y0), _) ->
4161 Glut.setCursor
Glut.CURSOR_INHERIT
;
4162 state.mstate
<- Mnone
4164 | Msel
((_, y0), (_, y1)) ->
4166 if (y0 >= l.pagedispy
&& y0 <= (l.pagedispy
+ l.pagevh))
4167 || ((y1 >= l.pagedispy
&& y1 <= (l.pagedispy
+ l.pagevh)))
4169 match getopaque l.pageno with
4174 List.iter
f state.layout;
4175 copysel
""; (* ugly *)
4176 Glut.setCursor
Glut.CURSOR_INHERIT
;
4177 state.mstate
<- Mnone
;
4184 let birdseyemouse button bstate
x y
4185 (conf, leftx
, _, hooverpageno
, anchor) =
4187 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4188 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4189 let rec loop = function
4192 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4193 && x > margin && x < margin + l.pagew
4195 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4200 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4204 let mouse bstate button
x y =
4205 state.uioh <- state.uioh#button button bstate
x y;
4208 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4211 state.uioh <- state.uioh#
motion x y
4215 state.uioh <- state.uioh#
pmotion x y;
4222 begin match state.mode with
4223 | Textentry
textentry -> textentrykeyboard key textentry
4224 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4225 | View
-> viewkeyboard key
4229 method special key =
4230 begin match state.mode with
4231 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4235 birdseyespecial key vals
4237 | View
when key = Glut.KEY_F1
->
4241 begin match state.autoscroll
with
4242 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4243 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4248 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4250 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4252 if Glut.getModifiers
() land Glut.active_shift
!= 0
4253 then (setzoom state.prevzoom
; state.y)
4254 else clamp (-conf.winh
/2)
4255 else clamp (-conf.scrollstep
)
4257 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4259 if Glut.getModifiers
() land Glut.active_shift
!= 0
4260 then (setzoom state.prevzoom
; state.y)
4261 else clamp (conf.winh
/2)
4262 else clamp (conf.scrollstep
)
4263 | Glut.KEY_PAGE_UP
->
4264 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4266 match state.layout with
4268 | l :: _ -> state.y - l.pagey
4271 | Glut.KEY_PAGE_DOWN
->
4272 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4274 match List.rev
state.layout with
4276 | l :: _ -> getpagey l.pageno
4284 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
4286 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
4287 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
4288 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
4290 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
4292 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4293 then (conf.winw / 2)
4296 state.x <- state.x - dx;
4298 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
4300 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4301 then (conf.winw / 2)
4304 state.x <- state.x + dx;
4309 gotoy_and_clear_text y
4312 | Textentry
te -> textentryspecial key te
4316 method button button bstate
x y =
4317 begin match state.mode with
4318 | View
-> viewmouse button bstate
x y
4319 | Birdseye beye
-> birdseyemouse button bstate
x y beye
4325 begin match state.mode with
4327 | View
| Birdseye
_ ->
4328 match state.mstate
with
4329 | Mzoom
_ | Mnone
-> ()
4334 state.mstate
<- Mpan
(x, y);
4335 if conf.zoom > 1.0 then state.x <- state.x + dx;
4337 gotoy_and_clear_text y
4340 state.mstate
<- Msel
(a, (x, y));
4341 G.postRedisplay "motion select";
4344 let y = min
conf.winh
(max
0 y) in
4348 let x = min
conf.winw (max
0 x) in
4351 | Mzoomrect
(p0
, _) ->
4352 state.mstate
<- Mzoomrect
(p0
, (x, y));
4353 G.postRedisplay "motion zoomrect";
4357 method pmotion x y =
4358 begin match state.mode with
4359 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
4360 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4361 let rec loop = function
4363 if hooverpageno
!= -1
4365 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
4366 G.postRedisplay "pmotion birdseye no hoover";
4369 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4370 && x > margin && x < margin + l.pagew
4372 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
4373 G.postRedisplay "pmotion birdseye hoover";
4382 match state.mstate
with
4384 begin match getunder x y with
4385 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
4387 if conf.underinfo
then showtext 'u'
("ri: " ^
uri);
4388 Glut.setCursor
Glut.CURSOR_INFO
4389 | Ulinkgoto
(page
, _) ->
4391 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
4392 Glut.setCursor
Glut.CURSOR_INFO
4394 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
4395 Glut.setCursor
Glut.CURSOR_TEXT
4398 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
4403 method memusedchanged
= ()
4410 let fontpath = ref "";;
4411 let wmclasshack = ref false;;
4414 let l = String.length
s in
4415 let b = Buffer.create
l in
4423 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
4424 | _ -> Sys.getenv
"HOME"
4427 ("Can not determine home directory location: " ^
4428 Printexc.to_string exn
);
4432 let config_of c attrs
=
4436 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
4437 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
4438 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
4439 | "preload" -> { c with preload = bool_of_string
v }
4440 | "page-bias" -> { c with pagebias
= int_of_string
v }
4441 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
4442 | "auto-scroll-step" ->
4443 { c with autoscrollstep
= max
0 (int_of_string
v) }
4444 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
4445 | "crop-hack" -> { c with crophack
= bool_of_string
v }
4446 | "throttle" -> { c with showall
= bool_of_string
v }
4447 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
4448 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
4449 | "vertical-margin" ->
4450 { c with interpagespace = max
0 (int_of_string
v) }
4452 let zoom = float_of_string
v /. 100. in
4453 let zoom = max
zoom 0.0 in
4454 { c with zoom = zoom }
4455 | "presentation" -> { c with presentation = bool_of_string
v }
4456 | "rotation-angle" -> { c with angle
= int_of_string
v }
4457 | "width" -> { c with winw = max
20 (int_of_string
v) }
4458 | "height" -> { c with winh
= max
20 (int_of_string
v) }
4459 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
4460 | "proportional-display" -> { c with proportional
= bool_of_string
v }
4461 | "pixmap-cache-size" ->
4462 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
4463 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
4464 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
4465 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
4466 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
4467 | "background-color" -> { c with bgcolor
= color_of_string v }
4468 | "scrollbar-in-presentation" ->
4469 { c with scrollbarinpm
= bool_of_string
v }
4470 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
4471 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
4473 { c with mumemlimit
= max
1024 (int_of_string_with_suffix v) }
4474 | "checkers" -> { c with checkers
= bool_of_string
v }
4475 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
4476 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
4477 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
4478 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
4479 | "uri-launcher" -> { c with urilauncher
= unent v }
4480 | "color-space" -> { c with colorspace
= colorspace_of_string v }
4481 | "invert-colors" -> { c with invert
= bool_of_string
v }
4484 prerr_endline
("Error processing attribute (`" ^
4485 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
4488 let rec fold c = function
4491 let c = apply c k
v in
4497 let fromstring f pos
n v d =
4500 dolog "Error processing attribute (%S=%S) at %d\n%s"
4501 n v pos
(Printexc.to_string exn
)
4506 let bookmark_of attrs
=
4507 let rec fold title page rely
= function
4508 | ("title", v) :: rest
-> fold v page rely rest
4509 | ("page", v) :: rest
-> fold title v rely rest
4510 | ("rely", v) :: rest
-> fold title page
v rest
4511 | _ :: rest
-> fold title page rely rest
4512 | [] -> title, page
, rely
4514 fold "invalid" "0" "0" attrs
4518 let rec fold path page rely pan
= function
4519 | ("path", v) :: rest
-> fold v page rely pan rest
4520 | ("page", v) :: rest
-> fold path
v rely pan rest
4521 | ("rely", v) :: rest
-> fold path page
v pan rest
4522 | ("pan", v) :: rest
-> fold path page rely
v rest
4523 | _ :: rest
-> fold path page rely pan rest
4524 | [] -> path
, page
, rely
, pan
4526 fold "" "0" "0" "0" attrs
4529 let setconf dst
src =
4530 dst
.scrollbw
<- src.scrollbw
;
4531 dst
.scrollh
<- src.scrollh
;
4532 dst
.icase
<- src.icase
;
4533 dst
.preload <- src.preload;
4534 dst
.pagebias
<- src.pagebias
;
4535 dst
.verbose
<- src.verbose
;
4536 dst
.scrollstep
<- src.scrollstep
;
4537 dst
.maxhfit
<- src.maxhfit
;
4538 dst
.crophack
<- src.crophack
;
4539 dst
.autoscrollstep
<- src.autoscrollstep
;
4540 dst
.showall
<- src.showall
;
4541 dst
.hlinks
<- src.hlinks
;
4542 dst
.underinfo
<- src.underinfo
;
4543 dst
.interpagespace <- src.interpagespace;
4544 dst
.zoom <- src.zoom;
4545 dst
.presentation <- src.presentation;
4546 dst
.angle
<- src.angle
;
4547 dst
.winw <- src.winw;
4548 dst
.winh
<- src.winh
;
4549 dst
.savebmarks
<- src.savebmarks
;
4550 dst
.memlimit
<- src.memlimit
;
4551 dst
.proportional
<- src.proportional
;
4552 dst
.texcount
<- src.texcount
;
4553 dst
.sliceheight
<- src.sliceheight
;
4554 dst
.thumbw
<- src.thumbw
;
4555 dst
.jumpback
<- src.jumpback
;
4556 dst
.bgcolor
<- src.bgcolor
;
4557 dst
.scrollbarinpm
<- src.scrollbarinpm
;
4558 dst
.tilew
<- src.tilew
;
4559 dst
.tileh
<- src.tileh
;
4560 dst
.mumemlimit
<- src.mumemlimit
;
4561 dst
.checkers
<- src.checkers
;
4562 dst
.aalevel
<- src.aalevel
;
4563 dst
.trimmargins
<- src.trimmargins
;
4564 dst
.trimfuzz
<- src.trimfuzz
;
4565 dst
.urilauncher
<- src.urilauncher
;
4566 dst
.colorspace
<- src.colorspace
;
4567 dst
.invert
<- src.invert
;
4571 let h = Hashtbl.create
10 in
4572 let dc = { defconf with angle
= defconf.angle
} in
4573 let rec toplevel v t spos
_ =
4575 | Vdata
| Vcdata
| Vend
-> v
4576 | Vopen
("llppconfig", _, closed
) ->
4579 else { v with f = llppconfig
}
4581 error
"unexpected subelement at top level" s spos
4582 | Vclose
_ -> error
"unexpected close at top level" s spos
4584 and llppconfig
v t spos
_ =
4586 | Vdata
| Vcdata
-> v
4587 | Vend
-> error
"unexpected end of input in llppconfig" s spos
4588 | Vopen
("defaults", attrs
, closed
) ->
4589 let c = config_of dc attrs
in
4593 else { v with f = skip
"defaults" (fun () -> v) }
4595 | Vopen
("ui-font", attrs
, closed
) ->
4596 let rec getsize size
= function
4598 | ("size", v) :: rest
->
4600 fromstring int_of_string spos
"size" v !uifontsize in
4602 | l -> getsize size l
4604 uifontsize := getsize !uifontsize attrs
;
4607 else { v with f = uifont
(Buffer.create
10) }
4609 | Vopen
("doc", attrs
, closed
) ->
4610 let pathent, spage
, srely
, span
= doc_of attrs
in
4611 let path = unent pathent
4612 and pageno = fromstring int_of_string spos
"page" spage
0
4613 and rely
= fromstring float_of_string spos
"rely" srely
0.0
4614 and pan
= fromstring int_of_string spos
"pan" span
0 in
4615 let c = config_of dc attrs
in
4616 let anchor = (pageno, rely
) in
4618 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
4619 else { v with f = doc
path pan
anchor c [] }
4622 error
"unexpected subelement in llppconfig" s spos
4624 | Vclose
"llppconfig" -> { v with f = toplevel }
4625 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
4627 and uifont
b v t spos epos
=
4630 Buffer.add_substring
b s spos
(epos
- spos
);
4632 | Vopen
(_, _, _) ->
4633 error
"unexpected subelement in ui-font" s spos
4634 | Vclose
"ui-font" ->
4635 if String.length
!fontpath = 0
4636 then fontpath := Buffer.contents
b;
4637 { v with f = llppconfig
}
4638 | Vclose
_ -> error
"unexpected close in ui-font" s spos
4639 | Vend
-> error
"unexpected end of input in ui-font" s spos
4641 and doc
path pan
anchor c bookmarks
v t spos
_ =
4643 | Vdata
| Vcdata
-> v
4644 | Vend
-> error
"unexpected end of input in doc" s spos
4645 | Vopen
("bookmarks", _, closed
) ->
4648 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
4650 | Vopen
(_, _, _) ->
4651 error
"unexpected subelement in doc" s spos
4654 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
4655 { v with f = llppconfig
}
4657 | Vclose
_ -> error
"unexpected close in doc" s spos
4659 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
4661 | Vdata
| Vcdata
-> v
4662 | Vend
-> error
"unexpected end of input in bookmarks" s spos
4663 | Vopen
("item", attrs
, closed
) ->
4664 let titleent, spage
, srely
= bookmark_of attrs
in
4665 let page = fromstring int_of_string spos
"page" spage
0
4666 and rely
= fromstring float_of_string spos
"rely" srely
0.0 in
4667 let bookmarks = (unent titleent, 0, (page, rely
)) :: bookmarks in
4669 then { v with f = pbookmarks
path pan
anchor c bookmarks }
4672 { v with f = skip
"item" f }
4675 error
"unexpected subelement in bookmarks" s spos
4677 | Vclose
"bookmarks" ->
4678 { v with f = doc
path pan
anchor c bookmarks }
4680 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
4682 and skip tag
f v t spos
_ =
4684 | Vdata
| Vcdata
-> v
4686 error
("unexpected end of input in skipped " ^ tag
) s spos
4687 | Vopen
(tag'
, _, closed
) ->
4691 let f'
() = { v with f = skip tag
f } in
4692 { v with f = skip tag'
f'
}
4696 else error
("unexpected close in skipped " ^ tag
) s spos
4699 parse
{ f = toplevel; accu = () } s;
4705 let len = in_channel_length ic
in
4706 let s = String.create
len in
4707 really_input ic
s 0 len;
4710 | Parse_error
(msg
, s, pos
) ->
4711 let subs = subs s pos
in
4712 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
4713 failwith
("parse error: " ^
s)
4716 failwith
("config load error: " ^
Printexc.to_string exn
)
4722 let dir = Filename.concat
home ".config" in
4723 if Sys.is_directory
dir then dir else home
4726 Filename.concat
dir "llpp.conf"
4729 let confpath = ref defconfpath;;
4732 if Sys.file_exists
!confpath
4735 (try Some
(open_in_bin
!confpath)
4738 ("Error opening configuation file `" ^
!confpath ^
"': " ^
4739 Printexc.to_string exn
);
4748 ("Error loading configuation from `" ^
!confpath ^
"': " ^
4749 Printexc.to_string exn
);
4755 f (Hashtbl.create
0, defconf)
4760 let pc, pb
, px, pa
=
4762 Hashtbl.find h (Filename.basename
state.path)
4763 with Not_found
-> dc, [], 0, (0, 0.0)
4767 state.bookmarks <- pb
;
4769 state.scrollw
<- conf.scrollbw
;
4771 then state.anchor <- pa
;
4772 cbput state.hists
.nav pa
;
4777 let add_attrs bb always
dc c =
4780 then Printf.bprintf bb
"\n %s='%b'" s a
4783 then Printf.bprintf bb
"\n %s='%d'" s a
4786 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
4789 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
4793 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
4797 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
4801 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
4805 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
4809 then dc.winw, dc.winh
4811 match state.fullscreen
with
4813 | None
-> c.winw, c.winh
4815 let zoom, presentation, interpagespace, showall
=
4817 then dc.zoom, dc.presentation, dc.interpagespace, dc.showall
4819 match state.mode with
4820 | Birdseye
(bc
, _, _, _, _) ->
4821 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.showall
4822 | _ -> c.zoom, c.presentation, c.interpagespace, c.showall
4824 oi
"width" w dc.winw;
4825 oi
"height" h dc.winh
;
4826 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
4827 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
4828 ob "case-insensitive-search" c.icase
dc.icase
;
4829 ob "preload" c.preload dc.preload;
4830 oi
"page-bias" c.pagebias
dc.pagebias
;
4831 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
4832 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
4833 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
4834 ob "crop-hack" c.crophack
dc.crophack
;
4835 ob "throttle" showall
dc.showall
;
4836 ob "highlight-links" c.hlinks
dc.hlinks
;
4837 ob "under-cursor-info" c.underinfo
dc.underinfo
;
4838 oi
"vertical-margin" interpagespace dc.interpagespace;
4839 oz
"zoom" zoom dc.zoom;
4840 ob "presentation" presentation dc.presentation;
4841 oi
"rotation-angle" c.angle
dc.angle
;
4842 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
4843 ob "proportional-display" c.proportional
dc.proportional
;
4844 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
4845 oi
"tex-count" c.texcount
dc.texcount
;
4846 oi
"slice-height" c.sliceheight
dc.sliceheight
;
4847 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
4848 ob "persistent-location" c.jumpback
dc.jumpback
;
4849 oc
"background-color" c.bgcolor
dc.bgcolor
;
4850 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
4851 oi
"tile-width" c.tilew
dc.tilew
;
4852 oi
"tile-height" c.tileh
dc.tileh
;
4853 oI
"mupdf-memlimit" c.mumemlimit
dc.mumemlimit
;
4854 ob "checkers" c.checkers
dc.checkers
;
4855 oi
"aalevel" c.aalevel
dc.aalevel
;
4856 ob "trim-margins" c.trimmargins
dc.trimmargins
;
4857 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
4858 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
4859 oC
"color-space" c.colorspace
dc.colorspace
;
4860 ob "invert-colors" c.invert
dc.invert
;
4862 then ob "wmclass-hack" !wmclasshack false;
4866 let uifontsize = !uifontsize in
4867 let bb = Buffer.create
32768 in
4869 let dc = if conf.bedefault
then conf else dc in
4870 Buffer.add_string
bb "<llppconfig>\n";
4872 if String.length
!fontpath > 0
4874 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
4880 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
4883 Buffer.add_string
bb "<defaults ";
4884 add_attrs bb true dc dc;
4885 Buffer.add_string
bb "/>\n";
4887 let adddoc path pan
anchor c bookmarks =
4888 if bookmarks == [] && c = dc && anchor = emptyanchor
4891 Printf.bprintf
bb "<doc path='%s'"
4892 (enent
path 0 (String.length
path));
4894 if anchor <> emptyanchor
4896 let n, y = anchor in
4897 Printf.bprintf
bb " page='%d'" n;
4900 Printf.bprintf
bb " rely='%f'" y
4905 then Printf.bprintf
bb " pan='%d'" pan
;
4907 add_attrs bb false dc c;
4909 begin match bookmarks with
4910 | [] -> Buffer.add_string
bb "/>\n"
4912 Buffer.add_string
bb ">\n<bookmarks>\n";
4913 List.iter
(fun (title, _level
, (page, rely
)) ->
4915 "<item title='%s' page='%d'"
4916 (enent
title 0 (String.length
title))
4921 Printf.bprintf
bb " rely='%f'" rely
4923 Buffer.add_string
bb "/>\n";
4925 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
4931 match state.mode with
4932 | Birdseye
(_, pan, _, _, _) -> pan
4935 let basename = Filename.basename state.path in
4936 adddoc basename pan (getanchor ())
4939 match state.autoscroll
with
4941 | None
-> conf.autoscrollstep
}
4942 (if conf.savebmarks
then state.bookmarks else []);
4944 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
4946 then adddoc path x y c bookmarks
4948 Buffer.add_string
bb "</llppconfig>";
4951 if Buffer.length
bb > 0
4954 let tmp = !confpath ^
".tmp" in
4955 let oc = open_out_bin
tmp in
4956 Buffer.output_buffer
oc bb;
4958 Unix.rename
tmp !confpath;
4961 ("error while saving configuration: " ^
Printexc.to_string exn
)
4968 [("-p", Arg.String
(fun s -> state.password
<- s) ,
4969 "<password> Set password");
4971 ("-f", Arg.String
(fun s -> Config.fontpath := s),
4972 "<path> Set path to the user interface font");
4974 ("-c", Arg.String
(fun s -> Config.confpath := s),
4975 "<path> Set path to the configuration file");
4977 ("-v", Arg.Unit
(fun () ->
4979 "%s\nconfiguration path: %s\n"
4983 exit
0), " Print version and exit");
4986 (fun s -> state.path <- s)
4987 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
4989 if String.length
state.path = 0
4990 then (prerr_endline
"file name missing"; exit
1);
4994 let _ = Glut.init
Sys.argv
in
4995 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
4996 let () = Glut.initWindowSize
conf.winw conf.winh
in
4997 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
4999 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5000 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5001 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5006 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5008 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5009 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5010 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5011 Unix.bind
sock addr;
5013 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5014 Unix.connect
csock addr;
5015 let ssock, _ = Unix.accept
sock in
5018 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5019 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5026 let () = Glut.displayFunc
display in
5027 let () = Glut.reshapeFunc
reshape in
5028 let () = Glut.keyboardFunc
keyboard in
5029 let () = Glut.specialFunc
special in
5030 let () = Glut.idleFunc
(Some
idle) in
5031 let () = Glut.mouseFunc
mouse in
5032 let () = Glut.motionFunc
motion in
5033 let () = Glut.passiveMotionFunc
pmotion in
5035 setcheckers conf.checkers
;
5037 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5038 conf.texcount
, conf.sliceheight
, conf.mumemlimit
, conf.colorspace
,
5039 !Config.wmclasshack, !Config.fontpath
5041 state.csock <- csock;
5042 state.ssock <- ssock;
5043 state.text <- "Opening " ^
state.path;
5044 setaalevel
conf.aalevel
;
5045 writeopen state.path state.password
;
5052 | Glut.BadEnum
"key in special_of_int" ->
5053 showtext '
!'
" LablGlut bug: special key not recognized";