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 type infochange
= | Memused
| Docinfo
| Pdim
;;
275 class type uioh
= object
276 method display
: unit
277 method key
: int -> uioh
278 method special
: Glut.special_key_t
-> uioh
280 Glut.button_t
-> Glut.mouse_button_state_t
-> int -> int -> uioh
281 method motion
: int -> int -> uioh
282 method pmotion
: int -> int -> uioh
283 method infochanged
: infochange
-> unit
287 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
288 | Textentry
of (textentry
* onleave
)
290 and onleave
= leavetextentrystatus
-> unit
291 and leavetextentrystatus
= | Cancel
| Confirm
292 and helpitem
= string * int * action
295 | Action
of (uioh
-> uioh
)
298 let isbirdseye = function Birdseye _
-> true | _
-> false;;
299 let istextentry = function Textentry _
-> true | _
-> false;;
303 | Loading
of (page
* gen
)
305 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
307 | Outlining
of outline list
310 let nouioh : uioh
= object (self
)
313 method special _
= self
314 method button _ _ _ _
= self
315 method motion _ _
= self
316 method pmotion _ _
= self
317 method infochanged _
= ()
321 { mutable csock
: Unix.file_descr
322 ; mutable ssock
: Unix.file_descr
326 ; mutable scrollw
: int
327 ; mutable hscrollh
: int
328 ; mutable anchor
: anchor
330 ; mutable layout
: page list
331 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
332 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
333 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
334 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
335 ; mutable pagecount
: int
336 ; mutable currently
: currently
337 ; mutable mstate
: mstate
338 ; mutable searchpattern
: string
339 ; mutable rects
: (pageno
* recttype
* rect
) list
340 ; mutable rects1
: (pageno
* recttype
* rect
) list
341 ; mutable text
: string
342 ; mutable fullscreen
: (width
* height
) option
343 ; mutable mode
: mode
344 ; mutable uioh
: uioh
345 ; mutable outlines
: outline array
346 ; mutable bookmarks
: outline list
347 ; mutable path
: string
348 ; mutable password
: string
349 ; mutable invalidated
: int
350 ; mutable colorscale
: float
351 ; mutable memused
: memsize
353 ; mutable throttle
: (page list
* int) option
354 ; mutable autoscroll
: int option
355 ; mutable help
: helpitem array
356 ; mutable docinfo
: (int * string) list
357 ; mutable deadline
: float
358 ; mutable texid
: GlTex.texture_id
option
360 ; mutable prevzoom
: float
361 ; mutable progress
: float
364 { pat
: string circbuf
365 ; pag
: string circbuf
366 ; nav
: anchor circbuf
387 ; presentation
= false
392 ; proportional
= true
393 ; trimmargins
= false
394 ; trimfuzz
= (0,0,0,0)
395 ; memlimit
= 32 lsl 20
400 ; bgcolor
= (0.5, 0.5, 0.5)
402 ; scrollbarinpm
= true
405 ; mumemlimit
= 128 lsl 20
410 | Plinux
| Pfreebsd
| Pdragonflybsd
| Popenbsd
| Psun
-> "xdg-open \"%s\""
411 | Posx
-> "open \"%s\""
412 | Pwindows
| Pcygwin
| Pmingw
-> "iexplore \"%s\""
419 let conf = { defconf with angle
= defconf.angle
};;
421 let uifontsize = ref 14;;
424 if String.length
conf.urilauncher
= 0
425 then print_endline uri
427 let re = Str.regexp
"%s" in
428 let command = Str.global_replace
re uri
conf.urilauncher
in
430 try Some
(Unix.open_process_in
command)
433 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
438 | Some ic
-> close_in ic
443 let strings = ("llpp version " ^
Help.version
) :: "" :: Help.keys
in
445 let r = Str.regexp
"\\(http://[^ ]+\\)" in
447 if (try Str.search_forward
r s
0 with Not_found
-> -1) >= 0
449 let uri = Str.matched_string s
in
450 (s
, 0, Action
(fun u
-> gotouri uri; u
))
451 else s
, 0, Noaction
) strings
463 ; anchor
= emptyanchor
466 ; tilelru
= Queue.create
()
467 ; pagemap
= Hashtbl.create
10
468 ; tilemap
= Hashtbl.create
10
485 { nav
= cbnew 10 (0, 0.0)
507 Printf.kprintf prerr_endline fmt
509 Printf.kprintf ignore fmt
514 let postRedisplay who
=
516 then prerr_endline
("redisplay for " ^ who
);
517 Glut.postRedisplay ();
522 let b = Buffer.create
(String.length s
+ 1) in
523 Buffer.add_string
b s
;
528 let colorspace_of_string s
=
529 match String.lowercase s
with
533 | _
-> failwith
"invalid colorspace"
536 let int_of_colorspace = function
542 let colorspace_of_int = function
546 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
549 let colorspace_to_string = function
555 let intentry_with_suffix text key
=
556 let c = Char.unsafe_chr key
in
557 match Char.lowercase
c with
559 let text = addchar text c in
563 let text = addchar text c in
567 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
572 let len = String.length s
in
574 let b = Buffer.create
n in
575 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
576 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
577 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
578 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
579 Buffer.add_string
b s
;
580 let s'
= Buffer.contents
b in
581 let n'
= Unix.write fd
s'
0 n in
582 if n'
!= n then failwith
"write failed";
587 let n = Unix.read fd
s 0 4 in
588 if n != 4 then failwith
"incomplete read(len)";
590 lor (Char.code
s.[0] lsl 24)
591 lor (Char.code
s.[1] lsl 16)
592 lor (Char.code
s.[2] lsl 8)
593 lor (Char.code
s.[3] lsl 0)
595 let s = String.create
len in
596 let n = Unix.read fd
s 0 len in
597 if n != len then failwith
"incomplete read(data)";
602 let b = Buffer.create
10 in
603 Buffer.add_string
b s;
604 let rec combine = function
607 Buffer.add_char
b ' '
;
610 | `
b b -> if b then "1" else "0"
612 | `i i
-> string_of_int i
613 | `f f
-> string_of_float f
614 | `I f
-> string_of_int
(truncate f
)
616 Buffer.add_string
b s;
623 let cmd = Buffer.contents
(makecmd s l
) in
624 writecmd state.csock
cmd;
630 let d = conf.winh
- h
in
637 let rec f pn ph pi fh l
=
639 | (n, _
, h
, _
) :: rest
->
640 let ips = calcips h
in
645 if isbirdseye state.mode
&& pn
= 0
650 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
655 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
659 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
662 let fh = f 0 0 0 0 state.pdims
in
666 let getpageyh pageno
=
667 let rec f pn ph pi y l
=
669 | (n, _
, h
, _
) :: rest
->
670 let ips = calcips h
in
673 let h = if n = pageno
then h else ph
in
674 if conf.presentation
&& n = pageno
676 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
678 y
+ (pageno
- pn
) * (ph
+ pi
), h
680 let y = y + (if conf.presentation
then pi
else 0) in
681 let y = y + (n - pn
) * (ph
+ pi
) in
685 y + (pageno
- pn
) * (ph
+ pi
), ph
687 f 0 0 0 0 state.pdims
690 let getpagedim pageno
=
693 | (n, _
, _
, _
) as pdim
:: rest
->
695 then (if n = pageno
then pdim
else ppdim
)
700 f (-1, -1, -1, -1) state.pdims
703 let getpageh pageno
=
704 let _, _, h, _ = getpagedim pageno
in
708 let getpagew pageno
=
709 let _, w
, _, _ = getpagedim pageno
in
713 let getpagey pageno
= fst
(getpageyh pageno
);;
716 let sh = sh - state.hscrollh
in
717 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
718 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
720 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
721 let ips = calcips h in
723 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
727 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
729 prev
, pdims
, pdimno
, 0
731 let dy = dy + yinc in
732 let py = py + yinc in
733 if pageno
= state.pagecount
|| dy >= sh
738 if py + h <= vy - yinc
740 let py = py + h + ips in
741 let dy = max
0 (py - y) in
750 let pagey = vy - py in
751 let pagevh = h - pagey in
752 let pagevh = min
(sh - dy) pagevh in
753 let off = if yinc > 0 then py - vy else 0 in
754 let py = py + h + ips in
757 if state.w
< conf.winw
- state.scrollw
758 then (conf.winw
- state.scrollw
- state.w
) / 2
761 let dispx = xoff + state.x
in
767 let lw = w
- pagex in
768 min
lw (conf.winw
- state.scrollw
)
776 ; pagey = pagey + off
778 ; pagevh = pagevh - off
780 ; pagedispy
= dy + off
783 let accu = e :: accu in
792 if state.invalidated
= 0
811 let y = state.y + incr
in
813 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
817 let getopaque pageno
=
818 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
819 with Not_found
-> None
822 let putopaque pageno opaque
=
823 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
827 let tilex = l
.pagex mod conf.tilew
in
828 let tiley = l
.pagey mod conf.tileh
in
830 let col = l
.pagex / conf.tilew
in
831 let row = l
.pagey / conf.tileh
in
834 let a = l
.pagew
- l
.pagex in
835 let b = conf.winw
- state.scrollw
in
839 let rec rowloop row y0 dispy
h =
843 let dh = conf.tileh
- y0
in
845 let rec colloop col x0
dispx w
=
849 let dw = conf.tilew
- x0
in
852 f col row dispx dispy x0 y0
dw dh;
853 colloop (col+1) 0 (dispx+dw) (w
-dw)
856 colloop col tilex l
.pagedispx
vw;
857 rowloop (row+1) 0 (dispy
+dh) (h-dh)
861 then rowloop row tiley l
.pagedispy vh
;
864 let gettileopaque l
col row =
866 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
868 try Some
(Hashtbl.find
state.tilemap
key)
869 with Not_found
-> None
872 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
873 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
874 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
877 let drawtiles l color
=
879 let f col row x
y tilex tiley w
h =
880 match gettileopaque l
col row with
881 | Some
(opaque
, _, t
) ->
882 let params = x
, y, w
, h, tilex, tiley in
886 GlFunc.blend_func `zero `one_minus_src_color
;
888 drawtile
params opaque
;
890 then Gl.disable `blend
;
893 let s = Printf.sprintf
897 let w = measurestr
!uifontsize s in
898 GlMisc.push_attrib
[`current
];
899 GlDraw.color
(0.0, 0.0, 0.0);
901 (float (x
-2), float (y-2))
902 (float (x
+2) +. w, float (y + !uifontsize + 2));
903 GlDraw.color
(1.0, 1.0, 1.0);
904 drawstring !uifontsize x
(y + !uifontsize - 1) s;
905 GlMisc.pop_attrib
();
910 let lw = conf.winw
- state.scrollw
- x
in
913 let lh = conf.winh
- y in
916 Gl.enable `texture_2d
;
917 begin match state.texid
with
919 GlTex.bind_texture `texture_2d id
;
923 and y1
= float (y+h) in
925 let tw = float w /. 64.0
926 and th
= float h /. 64.0 in
927 let tx0 = float tilex /. 64.0
928 and ty0
= float tiley /. 64.0 in
930 and ty1
= ty0
+. th
in
931 GlDraw.begins `quads
;
932 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
933 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
934 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
935 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
938 Gl.disable `texture_2d
;
940 GlDraw.color
(1.0, 1.0, 1.0);
943 (float (x
+w), float (y+h));
945 if w > 128 && h > !uifontsize + 10
947 GlDraw.color
(0.0, 0.0, 0.0);
950 then (col*conf.tilew
, row*conf.tileh
)
953 drawstring2 !uifontsize x
y "Loading %d [%d,%d]" l
.pageno
c r;
960 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
962 let tilevisible1 l x
y =
964 and ax1
= l
.pagex + l
.pagevw
966 and ay1
= l
.pagey + l
.pagevh in
970 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
971 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
973 let rx0 = max
ax0 bx0
974 and ry0
= max ay0 by0
975 and rx1
= min ax1
bx1
976 and ry1
= min ay1 by1
in
978 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
982 let tilevisible layout n x
y =
983 let rec findpageinlayout = function
984 | l
:: _ when l
.pageno
= n -> tilevisible1 l x
y
985 | _ :: rest
-> findpageinlayout rest
988 findpageinlayout layout
991 let tileready l x
y =
992 tilevisible1 l x
y &&
993 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
996 let tilepage n p
layout =
997 let rec loop = function
1001 let f col row _ _ _ _ _ _ =
1002 if state.currently
= Idle
1004 match gettileopaque l
col row with
1007 let x = col*conf.tilew
1008 and y = row*conf.tileh
in
1010 let w = l
.pagew
- x in
1014 let h = l
.pageh
- y in
1026 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1027 conf.tilew
, conf.tileh
1036 if state.invalidated
= 0 then loop layout;
1039 let preloadlayout visiblepages
=
1040 let presentation = conf.presentation in
1041 let interpagespace = conf.interpagespace in
1042 let maxy = state.maxy in
1043 conf.presentation <- false;
1044 conf.interpagespace <- 0;
1045 state.maxy <- calcheight ();
1047 match visiblepages
with
1049 | l
:: _ -> getpagey l
.pageno
+ l
.pagey
1051 let y = if y < conf.winh
then 0 else y - conf.winh
in
1052 let h = state.y - y + conf.winh
*3 in
1053 let pages = layout y h in
1054 conf.presentation <- presentation;
1055 conf.interpagespace <- interpagespace;
1061 let rec loop pages =
1062 if state.currently
!= Idle
1067 begin match getopaque l
.pageno
with
1069 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1070 state.currently
<- Loading
(l
, state.gen
);
1072 tilepage l
.pageno opaque
pages;
1077 if state.invalidated
= 0 then loop pages
1082 if conf.preload && state.currently
= Idle
1083 then load (preloadlayout pages);
1086 let layoutready layout =
1087 let rec fold all ls
=
1088 all
&& match ls
with
1090 let seen = ref false in
1091 let allvisible = ref true in
1092 let foo col row _ _ _ _ _ _ =
1094 allvisible := !allvisible &&
1095 begin match gettileopaque l
col row with
1101 fold (!seen && !allvisible) rest
1104 let alltilesvisible = fold true layout in
1109 let y = bound y 0 state.maxy in
1110 let y, layout, proceed
=
1113 match state.throttle
with
1115 let layout = layout y conf.winh
in
1116 let ready = layoutready layout in
1120 state.throttle
<- Some
(layout, y);
1122 else G.postRedisplay "gotoy showall (None)";
1124 | Some
_ -> -1, [], false
1126 let layout = layout y conf.winh
in
1127 if true || layoutready layout
1128 then G.postRedisplay "gotoy ready";
1134 state.layout <- layout;
1135 begin match state.mode
with
1136 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1137 if not
(pagevisible layout pageno
)
1139 match state.layout with
1142 state.mode
<- Birdseye
(
1143 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1152 let conttiling pageno opaque
=
1153 tilepage pageno opaque
1154 (if conf.preload then preloadlayout state.layout else state.layout)
1157 let gotoy_and_clear_text y =
1159 if not
conf.verbose
then state.text <- "";
1163 match state.layout with
1165 | l
:: _ -> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1168 let getanchory (n, top
) =
1169 let y, h = getpageyh n in
1170 y + (truncate
(top
*. float h));
1173 let gotoanchor anchor
=
1174 gotoy (getanchory anchor
);
1178 cbput state.hists
.nav
(getanchor ());
1182 let anchor = cbgetc state.hists
.nav dir
in
1186 let gotopage n top
=
1187 let y, h = getpageyh n in
1188 gotoy_and_clear_text (y + (truncate
(top
*. float h)));
1191 let gotopage1 n top
=
1192 let y = getpagey n in
1193 gotoy_and_clear_text (y + top
);
1201 state.invalidated
<- state.invalidated
+ 1;
1204 let writeopen path password
=
1205 writecmd state.csock
("open " ^ path ^
"\000" ^ password ^
"\000");
1208 let opendoc path password
=
1211 state.password
<- password
;
1212 state.gen
<- state.gen
+ 1;
1213 state.docinfo
<- [];
1215 setaalevel
conf.aalevel
;
1216 writeopen path password
;
1217 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1218 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1222 let c = c *. state.colorscale
in
1226 let scalecolor2 (r, g
, b) =
1227 (r *. state.colorscale
, g
*. state.colorscale
, b *. state.colorscale
);
1231 state.maxy <- calcheight ();
1233 if state.w <= conf.winw
- state.scrollw
1237 match state.mode
with
1238 | Birdseye
(_, _, pageno
, _, _) ->
1239 let y, h = getpageyh pageno
in
1240 let top = (conf.winh
- h) / 2 in
1241 gotoy (max
0 (y - top))
1242 | _ -> gotoanchor state.anchor
1246 let firsttime = ref true in
1248 GlDraw.viewport
0 0 w h;
1249 if state.invalidated
= 0 && not
!firsttime
1250 then state.anchor <- getanchor ();
1254 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1258 GlMat.mode `modelview
;
1259 GlMat.load_identity
();
1261 GlMat.mode `projection
;
1262 GlMat.load_identity
();
1263 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1264 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1265 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1268 wcmd "geometry" [`i
w; `i
h];
1272 let len = String.length
state.text in
1275 match state.mode
with
1276 | View
-> state.hscrollh
1281 (x, float (conf.winh
- (!uifontsize + 4) - hscrollh))
1282 (x+.w, float (conf.winh
- hscrollh))
1285 let w = float (conf.winw
- state.scrollw
- 1) in
1286 if state.progress
>= 0.0 && state.progress
< 1.0
1288 GlDraw.color
(0.3, 0.3, 0.3);
1289 let w1 = w *. state.progress
in
1291 GlDraw.color
(0.0, 0.0, 0.0);
1295 GlDraw.color
(0.0, 0.0, 0.0);
1299 GlDraw.color
(1.0, 1.0, 1.0);
1300 drawstring !uifontsize
1301 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1303 match state.mode
with
1304 | Textentry
((prefix
, text, _, _, _), _) ->
1308 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1310 Printf.sprintf
"%s%s_" prefix
text
1315 if len > 0 then drawstring state.text
1319 state.text <- Printf.sprintf
"%c%s" c s;
1320 G.postRedisplay "showtext";
1324 let len = Queue.length
state.tilelru
in
1326 if state.memused
<= conf.memlimit
1331 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1332 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1335 && colorspace
= conf.colorspace
1336 && angle
= conf.angle
1337 && pagew
= getpagew n
1338 && pageh
= getpageh n
1342 then preloadlayout state.layout
1345 let x = col*conf.tilew
1346 and y = row*conf.tileh
in
1347 tilevisible layout n x y
1349 then Queue.push lruitem
state.tilelru
1351 wcmd "freetile" [`
s p
];
1352 state.memused
<- state.memused
- s;
1353 state.uioh#infochanged Memused
;
1354 Hashtbl.remove
state.tilemap k
;
1363 Queue.iter
(fun (k
, p
, s) ->
1364 wcmd "freetile" [`
s p
];
1365 state.memused
<- state.memused
- s;
1366 state.uioh#infochanged Memused
;
1367 Hashtbl.remove
state.tilemap k
;
1369 Queue.clear
state.tilelru
;
1373 let logcurrently = function
1374 | Idle
-> dolog "Idle"
1375 | Loading
(l
, gen
) ->
1376 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1377 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1379 "Tiling %d[%d,%d] page=%s cs=%s angle"
1380 l
.pageno
col row pageopaque
1381 (colorspace_to_string colorspace
)
1383 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1384 angle gen
conf.angle
state.gen
1386 conf.tilew
conf.tileh
1393 (* dolog "%S" cmds; *)
1396 try String.index cmds ' '
1397 with Not_found
-> -1
1402 let l = String.length cmds
in
1403 let op = String.sub cmds
0 spacepos in
1405 if l - spacepos < 2 then ""
1406 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1411 state.uioh#infochanged Pdim
;
1415 state.rects
<- state.rects1
;
1416 G.postRedisplay "clearrects";
1419 let n = Scanf.sscanf args
"%u" (fun n -> n) in
1420 state.pagecount
<- n;
1421 state.invalidated
<- state.invalidated
- 1;
1422 begin match state.currently
with
1424 state.currently
<- Idle
;
1425 state.outlines
<- Array.of_list
(List.rev
l)
1428 if state.invalidated
= 0
1431 then G.postRedisplay "continue";
1434 Glut.setWindowTitle args
1441 then showtext ' ' args
1444 let progress, text = Scanf.sscanf args
"%f %n"
1446 f, String.sub args pos
(String.length args
- pos
)
1450 state.progress <- progress;
1451 G.postRedisplay "progress"
1454 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1455 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1456 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1457 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1459 let y = (getpagey pageno) + truncate y0
in
1462 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)]
1465 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1466 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1467 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1468 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1471 (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) :: state.rects1
1474 let pageopaque, t
= Scanf.sscanf args
"%s %f" (fun p t
-> p
, t
) in
1475 begin match state.currently
with
1476 | Loading
(l, gen
) ->
1477 vlog "page %d took %f sec" l.pageno t
;
1478 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1479 begin match state.throttle
with
1481 let preloadedpages =
1483 then preloadlayout state.layout
1488 Set.Make
(struct type t
= int let compare = (-) end) in
1490 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1491 IntSet.empty
preloadedpages
1494 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1495 if not
(IntSet.mem
pageno set)
1497 wcmd "freepage" [`
s opaque
];
1503 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1506 state.currently
<- Idle
;
1509 tilepage l.pageno pageopaque state.layout;
1511 load preloadedpages;
1512 if pagevisible state.layout l.pageno
1513 && layoutready state.layout
1514 then G.postRedisplay "page";
1517 | Some
(layout, _) ->
1518 state.currently
<- Idle
;
1519 tilepage l.pageno pageopaque layout;
1524 dolog "Inconsistent loading state";
1525 logcurrently state.currently
;
1530 let (x, y, opaque
, size
, t
) =
1531 Scanf.sscanf args
"%u %u %s %u %f"
1532 (fun x y p size t
-> (x, y, p
, size
, t
))
1534 begin match state.currently
with
1535 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1536 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1538 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1540 wcmd "freetile" [`
s opaque
];
1541 state.currently
<- Idle
;
1545 puttileopaque l col row gen cs angle opaque size t
;
1546 state.memused
<- state.memused
+ size
;
1547 state.uioh#infochanged Memused
;
1549 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1550 opaque
, size
) state.tilelru
;
1552 state.currently
<- Idle
;
1554 && conf.colorspace
= cs
1555 && conf.angle
= angle
1556 && tilevisible state.layout l.pageno x y
1557 then conttiling l.pageno pageopaque;
1559 begin match state.throttle
with
1561 preload state.layout;
1563 && conf.colorspace
= cs
1564 && conf.angle
= angle
1565 && tilevisible state.layout l.pageno x y
1566 then G.postRedisplay "tile nothrottle";
1568 | Some
(layout, y) ->
1569 let ready = layoutready layout in
1573 state.layout <- layout;
1574 state.throttle
<- None
;
1575 G.postRedisplay "throttle";
1582 dolog "Inconsistent tiling state";
1583 logcurrently state.currently
;
1589 Scanf.sscanf args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1591 state.uioh#infochanged Pdim
;
1592 state.pdims
<- pdim :: state.pdims
1595 let (l, n, t
, h, pos
) =
1596 Scanf.sscanf args
"%u %u %d %u %n" (fun l n t
h pos
-> l, n, t
, h, pos
)
1598 let s = String.sub args pos
(String.length args
- pos
) in
1599 let outline = (s, l, (n, float t
/. float h)) in
1600 begin match state.currently
with
1601 | Outlining outlines
->
1602 state.currently
<- Outlining
(outline :: outlines
)
1604 state.currently
<- Outlining
[outline]
1606 dolog "invalid outlining state";
1607 logcurrently currently
1611 state.docinfo
<- (1, args
) :: state.docinfo
1614 state.uioh#infochanged Docinfo
;
1615 state.docinfo
<- List.rev
state.docinfo
1618 dolog "unknown cmd `%S'" cmds
1621 let now = Unix.gettimeofday
;;
1624 if state.deadline
== nan
then state.deadline
<- now ();
1625 let rec loop delay
=
1628 then max
0.0 (state.deadline
-. now ())
1631 let r, _, _ = Unix.select
[state.csock
] [] [] timeout in
1634 begin match state.autoscroll
with
1635 | Some step
when step
!= 0 ->
1636 let y = state.y + step
in
1640 else if y >= state.maxy then 0 else y
1643 if state.mode
= View
1644 then state.text <- "";
1645 state.deadline
<- state.deadline
+. 0.005;
1648 state.deadline
<- state.deadline
+. delay
;
1652 let cmd = readcmd state.csock
in
1661 let action = function
1662 | HCprev
-> cbget cb ~
-1
1663 | HCnext
-> cbget cb
1
1664 | HCfirst
-> cbget cb ~
-(cb
.rc)
1665 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1666 and cancel
() = cb
.rc <- rc
1670 let search pattern forward
=
1671 if String.length pattern
> 0
1674 match state.layout with
1677 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1680 let b = makecmd "search"
1681 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
1683 Buffer.add_char
b '
,'
;
1684 Buffer.add_string
b pattern
;
1685 Buffer.add_char
b '
\000'
;
1688 writecmd state.csock
cmd;
1691 let intentry text key =
1692 let c = Char.unsafe_chr
key in
1695 let text = addchar text c in
1699 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1703 let textentry text key =
1704 let c = Char.unsafe_chr
key in
1706 | _ when key >= 32 && key < 127 ->
1707 let text = addchar text c in
1711 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
1715 let reqlayout angle proportional
=
1716 match state.throttle
with
1718 if state.invalidated
= 0 then state.anchor <- getanchor ();
1719 conf.angle
<- angle
mod 360;
1720 conf.proportional
<- proportional
;
1722 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
1726 let settrim trimmargins trimfuzz
=
1727 if state.invalidated
= 0 then state.anchor <- getanchor ();
1728 conf.trimmargins
<- trimmargins
;
1729 conf.trimfuzz
<- trimfuzz
;
1730 let x0, y0
, x1
, y1
= trimfuzz
in
1733 `
b conf.trimmargins
;
1739 Hashtbl.iter
(fun _ opaque
->
1740 wcmd "freepage" [`
s opaque
];
1742 Hashtbl.clear
state.pagemap
;
1746 match state.throttle
with
1748 let zoom = max
0.01 zoom in
1749 if zoom <> conf.zoom
1751 state.prevzoom
<- conf.zoom;
1754 then (state.x <- 0; 0.0)
1755 else float state.x /. float state.w
1758 reshape conf.winw
conf.winh
;
1761 let x = relx *. float state.w in
1762 state.x <- truncate
x;
1764 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
1770 let enterbirdseye () =
1771 let zoom = float conf.thumbw
/. float conf.winw
in
1772 let birdseyepageno =
1773 let cy = conf.winh
/ 2 in
1777 let rec fold best
= function
1780 let d = cy - (l.pagedispy
+ l.pagevh/2)
1781 and dbest
= cy - (best
.pagedispy
+ best
.pagevh/2) in
1782 if abs
d < abs dbest
1789 state.mode
<- Birdseye
(
1790 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
1793 conf.presentation <- false;
1794 conf.interpagespace <- 10;
1795 conf.hlinks
<- false;
1797 state.mstate
<- Mnone
;
1798 conf.showall
<- false;
1799 Glut.setCursor
Glut.CURSOR_INHERIT
;
1802 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1807 reshape conf.winw
conf.winh
;
1810 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
1812 conf.zoom <- c.zoom;
1813 conf.presentation <- c.presentation;
1814 conf.interpagespace <- c.interpagespace;
1815 conf.showall
<- c.showall
;
1816 conf.hlinks
<- c.hlinks
;
1820 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1823 reshape conf.winw
conf.winh
;
1824 state.anchor <- if goback
then anchor else (pageno, 0.0);
1827 let togglebirdseye () =
1828 match state.mode
with
1829 | Birdseye vals
-> leavebirdseye vals
true
1830 | View
-> enterbirdseye ()
1834 let upbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
1835 let pageno = max
0 (pageno - 1) in
1836 let rec loop = function
1837 | [] -> gotopage1 pageno 0
1838 | l :: _ when l.pageno = pageno ->
1839 if l.pagedispy
>= 0 && l.pagey = 0
1840 then G.postRedisplay "upbirdseye"
1841 else gotopage1 pageno 0
1842 | _ :: rest
-> loop rest
1845 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
1848 let downbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
1849 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
1850 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
1851 let rec loop = function
1853 let y, h = getpageyh pageno in
1854 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
1856 | l :: _ when l.pageno = pageno ->
1857 if l.pagevh != l.pageh
1858 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
1859 else G.postRedisplay "downbirdseye"
1860 | _ :: rest
-> loop rest
1865 let optentry mode
_ key =
1866 let btos b = if b then "on" else "off" in
1867 let c = Char.unsafe_chr
key in
1871 try conf.scrollstep
<- int_of_string
s with exc
->
1872 state.text <- Printf.sprintf
"bad integer `%s': %s"
1873 s (Printexc.to_string exc
)
1875 TEswitch
("scroll step: ", "", None
, intentry, ondone)
1880 conf.autoscrollstep
<- int_of_string
s;
1881 if state.autoscroll
<> None
1882 then state.autoscroll
<- Some
conf.autoscrollstep
1884 state.text <- Printf.sprintf
"bad integer `%s': %s"
1885 s (Printexc.to_string exc
)
1887 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
1892 let zoom = float (int_of_string
s) /. 100.0 in
1895 state.text <- Printf.sprintf
"bad integer `%s': %s"
1896 s (Printexc.to_string exc
)
1898 TEswitch
("zoom: ", "", None
, intentry, ondone)
1903 conf.thumbw
<- bound (int_of_string
s) 2 4096;
1905 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
1906 begin match mode
with
1908 leavebirdseye beye
false;
1913 state.text <- Printf.sprintf
"bad integer `%s': %s"
1914 s (Printexc.to_string exc
)
1916 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
1921 Some
(int_of_string
s)
1923 state.text <- Printf.sprintf
"bad integer `%s': %s"
1924 s (Printexc.to_string exc
);
1927 | Some angle
-> reqlayout angle
conf.proportional
1930 TEswitch
("rotation: ", "", None
, intentry, ondone)
1933 conf.icase
<- not
conf.icase
;
1934 TEdone
("case insensitive search " ^
(btos conf.icase
))
1937 conf.preload <- not
conf.preload;
1939 TEdone
("preload " ^
(btos conf.preload))
1942 conf.verbose
<- not
conf.verbose
;
1943 TEdone
("verbose " ^
(btos conf.verbose
))
1946 conf.debug
<- not
conf.debug
;
1947 TEdone
("debug " ^
(btos conf.debug
))
1950 conf.maxhfit
<- not
conf.maxhfit
;
1951 state.maxy <- state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
1952 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
1955 conf.crophack
<- not
conf.crophack
;
1956 TEdone
("crophack " ^
btos conf.crophack
)
1959 conf.showall
<- not
conf.showall
;
1960 TEdone
("throttle " ^
btos conf.showall
)
1963 conf.underinfo
<- not
conf.underinfo
;
1964 TEdone
("underinfo " ^
btos conf.underinfo
)
1967 conf.savebmarks
<- not
conf.savebmarks
;
1968 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
1974 match state.layout with
1979 conf.interpagespace <- int_of_string
s;
1980 state.maxy <- calcheight ();
1981 let y = getpagey pageno in
1984 state.text <- Printf.sprintf
"bad integer `%s': %s"
1985 s (Printexc.to_string exc
)
1987 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
1990 reqlayout conf.angle
(not
conf.proportional
);
1991 TEdone
("proportional display " ^
btos conf.proportional
)
1994 settrim (not
conf.trimmargins
) conf.trimfuzz
;
1995 TEdone
("trim margins " ^
btos conf.trimmargins
)
1998 conf.invert
<- not
conf.invert
;
1999 TEdone
("invert colors " ^
btos conf.invert
)
2002 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2006 let maxoutlinerows () = (conf.winh
- !uifontsize - 1) / (!uifontsize + 1);;
2008 class type lvsource
= object
2009 method getitemcount
: int
2010 method getitem
: int -> (string * int)
2011 method hasaction
: int -> bool
2020 method getactive
: int
2021 method getfirst
: int
2022 method getqsearch
: string
2023 method setqsearch
: string -> unit
2027 class virtual lvsourcebase
= object
2028 val mutable m_active
= 0
2029 val mutable m_first
= 0
2030 val mutable m_qsearch
= ""
2031 val mutable m_pan
= 0
2032 method getactive
= m_active
2033 method getfirst
= m_first
2034 method getqsearch
= m_qsearch
2035 method getpan
= m_pan
2036 method setqsearch
s = m_qsearch
<- s
2039 let textentryspecial key = function
2040 | ((c, _, (Some
(action, _) as onhist), onkey
, ondone), mode
) ->
2043 | Glut.KEY_UP
-> action HCprev
2044 | Glut.KEY_DOWN
-> action HCnext
2045 | Glut.KEY_HOME
-> action HCfirst
2046 | Glut.KEY_END
-> action HClast
2049 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2050 G.postRedisplay "special textentry";
2054 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2056 state.mode
<- Textentry
(te
, onleave
);
2059 G.postRedisplay "textentrykeyboard enttext";
2061 match Char.unsafe_chr
key with
2062 | '
\008'
-> (* backspace *)
2063 let len = String.length
text in
2067 G.postRedisplay "textentrykeyboard after cancel";
2070 let s = String.sub
text 0 (len - 1) in
2071 enttext (c, s, opthist
, onkey
, ondone)
2077 G.postRedisplay "textentrykeyboard after confirm"
2079 | '
\007'
(* ctrl-g *)
2080 | '
\027'
-> (* escape *)
2081 if String.length
text = 0
2083 begin match opthist
with
2085 | Some
(_, onhistcancel
) -> onhistcancel
()
2089 G.postRedisplay "textentrykeyboard after cancel2"
2092 enttext (c, "", opthist
, onkey
, ondone)
2095 | '
\127'
-> () (* delete *)
2098 begin match onkey
text key with
2102 G.postRedisplay "textentrykeyboard after confirm2";
2105 enttext (c, text, opthist
, onkey
, ondone);
2110 G.postRedisplay "textentrykeyboard after cancel3"
2113 state.mode
<- Textentry
(te
, onleave
);
2114 G.postRedisplay "textentrykeyboard switch";
2118 let firstof first active
=
2119 let maxrows = maxoutlinerows () in
2120 if first
> active
|| abs
(first
- active
) > maxrows - 1
2121 then max
0 (active
- (maxrows/2))
2125 class listview ~
(source
:lvsource
) ~trusted
=
2126 let coe s = (s :> uioh
) in
2128 val m_pan
= source#getpan
2129 val m_first
= source#getfirst
2130 val m_active
= source#getactive
2131 val m_qsearch
= source#getqsearch
2132 val m_prev_uioh
= state.uioh
2134 method private elemunder
y =
2135 let n = y / (!uifontsize+1) in
2136 if m_first
+ n < source#getitemcount
2138 if source#hasaction
(m_first
+ n)
2139 then Some
(m_first
+ n)
2146 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2147 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2148 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2149 GlDraw.color
(1., 1., 1.);
2150 Gl.enable `texture_2d
;
2151 let fs = !uifontsize in
2153 let ww = measurestr
fs "w" in
2154 let tabw = 30.0*.ww in
2156 if (row - m_first
) * nfs > conf.winh
2159 if row >= 0 && row < source#getitemcount
2161 let (s, level
) = source#getitem
row in
2162 let y = (row - m_first
) * nfs in
2163 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2166 Gl.disable `texture_2d
;
2167 GlDraw.polygon_mode `both `line
;
2168 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2169 GlDraw.rect (1., float (y + 1))
2170 (float (conf.winw
- 1), float (y + fs + 3));
2171 GlDraw.polygon_mode `both `fill
;
2172 GlDraw.color
(1., 1., 1.);
2173 Gl.enable `texture_2d
;
2176 let drawtabularstring s =
2177 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2180 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2183 let len = String.length
s - tabpos - 1 in
2184 let s1 = String.sub
s 0 tabpos
2185 and s2
= String.sub
s (tabpos + 1) len in
2186 let nx = drawstr x s1 in
2188 let x = x +. (max
tabw sw) in
2195 let _ = drawtabularstring s in
2202 Gl.disable `texture_2d
;
2204 method private key1
key =
2205 let set active first qsearch
=
2206 coe {< m_active
= active
; m_first
= first
; m_qsearch
= qsearch
>}
2208 let search active pattern incr
=
2211 if n >= 0 && n < source#getitemcount
2213 let s, _ = source#getitem
n in
2215 (try ignore
(Str.search_forward
re s 0); true
2216 with Not_found
-> false)
2218 else loop (n + incr
)
2225 let re = Str.regexp_case_fold pattern
in
2232 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2233 let incr = if key = 18 then -1 else 1 in
2235 match search (m_active
+ incr) m_qsearch
incr with
2237 state.text <- m_qsearch ^
" [not found]";
2240 state.text <- m_qsearch
;
2241 active, firstof m_first
active
2243 G.postRedisplay "listview ctrl-r/s";
2244 set active first m_qsearch
;
2246 | 8 -> (* backspace *)
2247 let len = String.length m_qsearch
in
2254 G.postRedisplay "listview empty qsearch";
2255 set m_active m_first
"";
2258 let qsearch = String.sub m_qsearch
0 (len - 1) in
2260 match search m_active
qsearch ~
-1 with
2262 state.text <- qsearch ^
" [not found]";
2265 state.text <- qsearch;
2266 active, firstof m_first
active
2268 G.postRedisplay "listview backspace qsearch";
2269 set active first
qsearch
2272 | _ when key >= 32 && key < 127 ->
2273 let pattern = addchar m_qsearch
(Char.chr
key) in
2275 match search m_active
pattern 1 with
2277 state.text <- pattern ^
" [not found]";
2280 state.text <- pattern;
2281 active, firstof m_first
active
2283 G.postRedisplay "listview qsearch add";
2284 set active first
pattern;
2286 | 27 -> (* escape *)
2288 if String.length m_qsearch
= 0
2290 G.postRedisplay "list view escape";
2293 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2295 | None
-> m_prev_uioh
2300 G.postRedisplay "list view kill qsearch";
2301 source#setqsearch
"";
2302 coe {< m_qsearch
= "" >}
2307 let self = {< m_qsearch
= "" >} in
2308 source#setqsearch
"";
2310 G.postRedisplay "listview enter";
2311 if m_active
>= 0 && m_active
< source#getitemcount
2313 source#exit
(coe self) false m_active m_first m_pan
"";
2316 source#exit
(coe self) true m_active m_first m_pan
"";
2319 begin match opt with
2320 | None
-> m_prev_uioh
2324 | 127 -> (* delete *)
2327 | _ -> dolog "unknown key %d" key; coe self
2329 method private special1
key =
2330 let maxrows = maxoutlinerows () in
2331 let itemcount = source#getitemcount
in
2332 let find start
incr =
2334 if i
= -1 || i
= itemcount
2337 if source#hasaction i
2339 else find (i
+ incr)
2344 let set active first
=
2345 let first = bound first 0 (itemcount - maxrows) in
2347 coe {< m_active
= active; m_first
= first >}
2350 let isvisible first n = n >= first && n - first <= maxrows in
2352 let incr1 = if incr > 0 then 1 else -1 in
2353 if isvisible m_first m_active
2356 let next = m_active
+ incr in
2358 if next < 0 || next >= itemcount
2360 else find next incr1
2362 if next = -1 || abs
(m_active
- next) > maxrows
2368 let first = m_first
+ incr in
2369 let first = bound first 0 (itemcount - 1) in
2371 let next = m_active
+ incr in
2372 let next = bound next 0 (itemcount - 1) in
2375 let active = if next = -1 then m_active
else next in
2378 let first = min
next m_first
in
2381 let first = m_first
+ incr in
2382 let first = bound first 0 (itemcount - 1) in
2384 let next = m_active
+ incr in
2385 let next = bound next 0 (itemcount - 1) in
2386 let next = find next incr1 in
2387 if next = -1 || abs
(m_active
- first) > maxrows
2393 G.postRedisplay "listview navigate";
2396 begin match key with
2397 | Glut.KEY_UP
-> navigate ~
-1
2398 | Glut.KEY_DOWN
-> navigate 1
2399 | Glut.KEY_PAGE_UP
-> navigate ~
-maxrows
2400 | Glut.KEY_PAGE_DOWN
-> navigate maxrows
2404 G.postRedisplay "listview right";
2405 coe {< m_pan
= m_pan
- 1 >}
2409 G.postRedisplay "listview left";
2410 coe {< m_pan
= m_pan
+ 1 >}
2413 let active = find 0 1 in
2414 G.postRedisplay "listview home";
2418 let first = max
0 (itemcount - maxrows) in
2419 let active = find (itemcount - 1) ~
-1 in
2420 G.postRedisplay "listview end";
2427 match state.mode
with
2428 | Textentry te
-> textentrykeyboard key te
; coe self
2429 | _ -> self#key1
key
2431 method special
key =
2432 match state.mode
with
2433 | Textentry te
-> textentryspecial key te
; coe self
2434 | _ -> self#special1
key
2436 method button button bstate
_ y =
2439 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2440 begin match self#elemunder
y with
2442 G.postRedisplay "listview click";
2443 source#exit
(coe {< m_active
= n >}) false n m_first m_pan m_qsearch
2447 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2448 let len = source#getitemcount
in
2450 if m_first
+ maxoutlinerows () >= len
2454 let first = m_first
+ (if n == 3 then -1 else 1) in
2455 bound first 0 (len - 1)
2457 G.postRedisplay "listview wheel";
2458 Some
(coe {< m_first
= first >})
2463 | None
-> m_prev_uioh
2466 method motion
_ _ = coe self
2468 method pmotion
_ y =
2470 match self#elemunder
y with
2471 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
2472 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
2476 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
2481 method infochanged
_ = ()
2484 class outlinelistview ~source
: uioh
=
2485 let coe o = (o :> uioh
) in
2487 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
2491 | 14 -> (* ctrl-n *)
2492 source#narrow m_qsearch
;
2493 G.postRedisplay "outline ctrl-n";
2494 coe {< m_first
= 0; m_active
= 0 >}
2496 | 21 -> (* ctrl-u *)
2498 G.postRedisplay "outline ctrl-u";
2499 coe {< m_first
= 0; m_active
= 0 >}
2501 | 12 -> (* ctrl-l *)
2502 let first = m_active
- (maxoutlinerows () / 2) in
2503 G.postRedisplay "outline ctrl-l";
2504 coe {< m_first
= first >}
2506 | 127 -> (* delete *)
2507 source#remove m_active
;
2508 G.postRedisplay "outline delete";
2509 let active = max
0 (m_active
-1) in
2510 coe {< m_first
= firstof m_first
active; m_active
= active >}
2512 | key -> super#
key key
2514 method special
key =
2515 let maxrows = maxoutlinerows () in
2516 let calcfirst first active =
2519 let rows = active - first in
2520 if rows > maxrows then active - maxrows else first
2524 let active = m_active
+ incr in
2525 let active = bound active 0 (source#getitemcount
- 1) in
2526 let first = calcfirst m_first
active in
2527 G.postRedisplay "special outline navigate";
2528 coe {< m_active
= active; m_first
= first >}
2530 let updownlevel incr =
2531 let len = source#getitemcount
in
2532 let _, curlevel
= source#getitem m_active
in
2534 if i
= len then i
-1 else if i
= -1 then 0 else
2535 let _, l = source#getitem i
in
2536 if l != curlevel
then i
else flow (i
+incr)
2538 let active = flow m_active
in
2539 let first = calcfirst m_first
active in
2540 G.postRedisplay "special outline updownlevel";
2541 {< m_active
= active; m_first
= first >}
2544 | Glut.KEY_UP
-> navigate ~
-1
2545 | Glut.KEY_DOWN
-> navigate 1
2546 | Glut.KEY_PAGE_UP
-> navigate ~
-maxrows
2547 | Glut.KEY_PAGE_DOWN
-> navigate maxrows
2551 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2553 G.postRedisplay "special outline right";
2554 {< m_pan
= m_pan
+ 1 >}
2562 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2564 G.postRedisplay "special outline left";
2565 {< m_pan
= m_pan
- 1 >}
2567 else updownlevel ~
-1
2572 G.postRedisplay "special outline home";
2573 coe {< m_first
= 0; m_active
= 0 >}
2576 let active = source#getitemcount
- 1 in
2577 let first = max
0 (active - maxrows) in
2578 G.postRedisplay "special outline end";
2579 coe {< m_active
= active; m_first
= first >}
2581 | _ -> super#special
key
2584 let outlinesource usebookmarks
=
2587 inherit lvsourcebase
2588 val mutable m_items
= empty
2589 val mutable m_orig_items
= empty
2590 val mutable m_prev_items
= empty
2591 val mutable m_narrow_pattern
= ""
2592 val mutable m_hadremovals
= false
2594 method getitemcount
= Array.length m_items
+ (if m_hadremovals
then 1 else 0)
2597 if n == Array.length m_items
&& m_hadremovals
2599 ("[Confirm removal]", 0)
2601 let s, n, _ = m_items
.(n) in
2604 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
2605 ignore
(uioh
, first, pan
, qsearch);
2606 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
2608 if String.length m_narrow_pattern
= 0
2614 if not
confrimremoval
2616 let _, _, anchor = m_items
.(active) in
2621 state.bookmarks
<- Array.to_list m_items
;
2622 m_orig_items
<- m_items
;
2625 else m_items
<- items;
2628 method hasaction
_ = true
2631 if Array.length m_items
!= Array.length m_orig_items
2632 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
2635 method narrow
pattern =
2636 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
2640 let rec loop accu n =
2643 m_narrow_pattern
<- pattern;
2644 m_items
<- Array.of_list
accu
2647 let (s, _, _) as o = m_items
.(n) in
2649 if (try ignore
(Str.search_forward
re s 0); true
2650 with Not_found
-> false)
2656 loop [] (Array.length m_items
- 1)
2661 then Array.of_list
state.bookmarks
2664 m_items
<- m_orig_items
2669 if m
>= 0 && m
< Array.length m_items
2671 m_hadremovals
<- true;
2672 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
2673 let n = if n >= m
then n+1 else n in
2678 method reset
pageno items =
2679 m_hadremovals
<- false;
2680 if m_orig_items
== empty || m_prev_items
!= items
2682 m_orig_items
<- items;
2683 if String.length m_narrow_pattern
= 0
2684 then m_items
<- items;
2686 m_prev_items
<- items;
2688 let rec loop n best bestd
=
2689 if n = Array.length m_items
2692 let (_, _, (outlinepageno
, _)) = m_items
.(n) in
2693 let d = abs
(outlinepageno
- pageno) in
2696 else loop (n+1) best bestd
2701 m_first
<- firstof m_first
active
2705 let enterselector usebookmarks
=
2706 let source = outlinesource usebookmarks
in
2710 then Array.of_list
state.bookmarks
2713 if Array.length
outlines = 0
2715 showtext ' ' errmsg
;
2718 state.text <- source#greetmsg
;
2719 Glut.setCursor
Glut.CURSOR_INHERIT
;
2721 match state.layout with
2723 | {pageno=pageno} :: _ -> pageno
2725 source#reset
pageno outlines;
2726 state.uioh
<- new outlinelistview ~
source;
2727 G.postRedisplay "enter selector";
2731 let enteroutlinemode =
2732 let f = enterselector false in
2733 fun ()-> f "Document has no outline";
2736 let enterbookmarkmode =
2737 let f = enterselector true in
2738 fun () -> f "Document has no bookmarks (yet)";
2741 let color_of_string s =
2742 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
2743 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
2747 let color_to_string (r, g
, b) =
2748 let r = truncate
(r *. 256.0)
2749 and g
= truncate
(g
*. 256.0)
2750 and b = truncate
(b *. 256.0) in
2751 Printf.sprintf
"%d/%d/%d" r g
b
2754 let irect_of_string s =
2755 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0,y0
,x1
,y1
))
2758 let irect_to_string (x0,y0
,x1
,y1
) =
2759 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
2762 let makecheckers () =
2763 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
2765 converted by Issac Trotts. July 25, 2002 *)
2766 let image_height = 64
2767 and image_width
= 64 in
2771 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height in
2772 for i
= 0 to image_width
- 1 do
2773 for j
= 0 to image_height - 1 do
2774 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
2775 (if (i
land 8 ) lxor (j
land 8) = 0
2776 then [|255;255;255|] else [|200;200;200|])
2781 let image = make_image () in
2782 let id = GlTex.gen_texture
() in
2783 GlTex.bind_texture `texture_2d
id;
2784 GlPix.store
(`unpack_alignment
1);
2785 GlTex.image2d
image;
2786 List.iter
(GlTex.parameter ~target
:`texture_2d
)
2789 `mag_filter `nearest
;
2790 `min_filter `nearest
];
2794 let setcheckers enabled
=
2795 match state.texid
with
2797 if enabled
then state.texid
<- Some
(makecheckers ())
2802 GlTex.delete_texture texid
;
2803 state.texid
<- None
;
2807 let int_of_string_with_suffix s =
2808 let l = String.length
s in
2812 let suffix = Char.lowercase
s.[l-1] in
2814 | 'k'
-> String.sub
s 0 (l-1), 10
2815 | 'm'
-> String.sub
s 0 (l-1), 20
2816 | 'g'
-> String.sub
s 0 (l-1), 30
2820 let n = int_of_string
s1 in
2821 let m = n lsl shift
in
2823 then raise
(Failure
"value too large")
2827 let string_with_suffix_of_int n =
2835 if n land ((1 lsl 20) - 1) = 0
2838 if n land ((1 lsl 10) - 1) = 0
2845 let h = n mod 1000 in
2848 then string_of_int
h ^
s
2850 let s = Printf.sprintf
"_%03d%s" h s in
2857 let describe_location () =
2859 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
2861 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
2862 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
2866 else (100. *. (float state.y /. float maxy))
2870 Printf.sprintf
"page %d of %d [%.2f%%]"
2871 (fn+1) state.pagecount
percent
2874 "pages %d-%d of %d [%.2f%%]"
2875 (fn+1) (ln
+1) state.pagecount
percent
2879 let btos b = if b then "\xe2\x88\x9a" else "" in
2880 let showextended = ref false in
2881 let leave mode
= function
2882 | Confirm
-> state.mode
<- mode
2883 | Cancel
-> state.mode
<- mode
in
2886 val mutable m_first_time
= true
2887 val mutable m_l
= []
2888 val mutable m_a
= [||]
2889 val mutable m_prev_uioh
= nouioh
2890 val mutable m_prev_mode
= View
2892 inherit lvsourcebase
2894 method reset prev_mode prev_uioh
=
2895 m_a
<- Array.of_list
(List.rev m_l
);
2897 m_prev_mode
<- prev_mode
;
2898 m_prev_uioh
<- prev_uioh
;
2902 if n >= Array.length m_a
2906 | _, _, _, Action
_ -> m_active
<- n
2910 m_first_time
<- false;
2913 method int name get
set =
2915 (name
, `
int get
, 1, Action
(
2918 try set (int_of_string
s)
2920 state.text <- Printf.sprintf
"bad integer `%s': %s"
2921 s (Printexc.to_string exn
)
2924 let te = name ^
": ", "", None
, intentry, ondone in
2925 state.mode
<- Textentry
(te, leave m_prev_mode
);
2929 method int_with_suffix name get
set =
2931 (name
, `intws get
, 1, Action
(
2934 try set (int_of_string_with_suffix s)
2936 state.text <- Printf.sprintf
"bad integer `%s': %s"
2937 s (Printexc.to_string exn
)
2941 name ^
": ", "", None
, intentry_with_suffix, ondone
2943 state.mode
<- Textentry
(te, leave m_prev_mode
);
2947 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
2949 (name
, `
bool (btos, get
), offset
, Action
(
2956 method color name get
set =
2958 (name
, `color get
, 1, Action
(
2960 let invalid = (nan
, nan
, nan
) in
2963 try color_of_string s
2965 state.text <- Printf.sprintf
"bad color `%s': %s"
2966 s (Printexc.to_string exn
);
2972 let te = name ^
": ", "", None
, textentry, ondone in
2973 state.text <- color_to_string (get
());
2974 state.mode
<- Textentry
(te, leave m_prev_mode
);
2978 method string name get
set =
2980 (name
, `
string get
, 1, Action
(
2982 let ondone s = set s in
2983 let te = name ^
": ", "", None
, textentry, ondone in
2984 state.mode
<- Textentry
(te, leave m_prev_mode
);
2988 method colorspace name get
set =
2990 (name
, `
string get
, 1, Action
(
2993 let vals = [| "rgb"; "bgr"; "gray" |] in
2995 inherit lvsourcebase
2998 m_active
<- int_of_colorspace conf.colorspace
;
3001 method getitemcount
= Array.length
vals
3002 method getitem
n = (vals.(n), 0)
3003 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3004 ignore
(uioh
, first, pan
, qsearch);
3005 if not cancel
then set active;
3007 method hasaction
_ = true
3011 new listview ~
source ~trusted
:true
3014 method caption
s offset
=
3015 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3017 method caption2
s f offset
=
3018 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3020 method getitemcount
= Array.length m_a
3023 let tostr = function
3024 | `
int f -> string_of_int
(f ())
3025 | `intws
f -> string_with_suffix_of_int (f ())
3027 | `color
f -> color_to_string (f ())
3028 | `
bool (btos, f) -> btos (f ())
3031 let name, t
, offset
, _ = m_a
.(n) in
3032 ((let s = tostr t
in
3033 if String.length
s > 0
3034 then Printf.sprintf
"%s\t%s" name s
3038 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3042 m_qsearch
<- qsearch;
3044 match m_a
.(active) with
3045 | _, _, _, Action
f -> f uioh
3057 method hasaction
n =
3059 | _, _, _, Action
_ -> true
3063 let rec fillsrc () =
3064 let sep () = src#caption
"" 0 in
3065 let colorp name get
set =
3067 (fun () -> color_to_string (get
()))
3070 let c = color_of_string v in
3073 state.text <- Printf.sprintf
"bad color `%s': %s"
3074 v (Printexc.to_string exn
);
3077 let oldmode = state.mode
in
3078 let birdseye = isbirdseye state.mode
in
3080 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3082 src#
bool "presentation mode"
3083 (fun () -> conf.presentation)
3085 conf.presentation <- v;
3086 state.anchor <- getanchor ();
3089 src#
bool "ignore case in searches"
3090 (fun () -> conf.icase
)
3091 (fun v -> conf.icase
<- v);
3094 (fun () -> conf.preload)
3095 (fun v -> conf.preload <- v);
3098 (fun () -> conf.showall
)
3099 (fun v -> conf.showall
<- v);
3101 src#
bool "highlight links"
3102 (fun () -> conf.hlinks
)
3103 (fun v -> conf.hlinks
<- v);
3105 src#
bool "under info"
3106 (fun () -> conf.underinfo
)
3107 (fun v -> conf.underinfo
<- v);
3109 src#
bool "persistent bookmarks"
3110 (fun () -> conf.savebmarks
)
3111 (fun v -> conf.savebmarks
<- v);
3113 src#
bool "proportional display"
3114 (fun () -> conf.proportional
)
3115 (fun v -> reqlayout conf.angle
v);
3117 src#
bool "trim margins"
3118 (fun () -> conf.trimmargins
)
3119 (fun v -> settrim v conf.trimfuzz
; fillsrc ());
3121 src#
bool "persistent location"
3122 (fun () -> conf.jumpback
)
3123 (fun v -> conf.jumpback
<- v);
3126 src#
int "vertical margin"
3127 (fun () -> conf.interpagespace)
3129 conf.interpagespace <- n;
3131 match state.layout with
3136 state.maxy <- calcheight ();
3137 let y = getpagey pageno in
3142 (fun () -> conf.pagebias
)
3143 (fun v -> conf.pagebias
<- v);
3145 src#
int "scroll step"
3146 (fun () -> conf.scrollstep
)
3147 (fun n -> conf.scrollstep
<- n);
3149 src#
int "auto scroll step"
3151 match state.autoscroll
with
3153 | _ -> conf.autoscrollstep
)
3155 if state.autoscroll
<> None
3156 then state.autoscroll
<- Some
n;
3157 conf.autoscrollstep
<- n);
3160 (fun () -> truncate
(conf.zoom *. 100.))
3161 (fun v -> setzoom ((float v) /. 100.));
3164 (fun () -> conf.angle
)
3165 (fun v -> reqlayout v conf.proportional
);
3167 src#
int "scroll bar width"
3168 (fun () -> state.scrollw
)
3172 reshape conf.winw
conf.winh
;
3175 src#
int "scroll handle height"
3176 (fun () -> conf.scrollh
)
3177 (fun v -> conf.scrollh
<- v;);
3179 src#
int "thumbnail width"
3180 (fun () -> conf.thumbw
)
3182 conf.thumbw
<- min
4096 v;
3185 leavebirdseye beye
false;
3191 src#caption
"Presentation mode" 0;
3192 src#
bool "scrollbar visible"
3193 (fun () -> conf.scrollbarinpm
)
3195 if v != conf.scrollbarinpm
3197 conf.scrollbarinpm
<- v;
3198 if conf.presentation
3200 state.scrollw
<- if v then conf.scrollbw
else 0;
3201 reshape conf.winw
conf.winh
;
3207 src#caption
"Pixmap cache" 0;
3208 src#int_with_suffix
"size (advisory)"
3209 (fun () -> conf.memlimit
)
3210 (fun v -> conf.memlimit
<- v);
3213 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3214 (string_with_suffix_of_int state.memused
)
3215 (Hashtbl.length
state.tilemap
)) 1;
3218 src#caption
"Layout" 0;
3219 src#caption2
"Dimension"
3221 Printf.sprintf
"%dx%d (virtual %dx%d)"
3227 src#caption2
"Position" (fun () ->
3228 Printf.sprintf
"%dx%d" state.x state.y
3231 src#caption2
"Visible" (fun () -> describe_location ()) 1
3235 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3236 "Save these parameters as global defaults at exit"
3237 (fun () -> conf.bedefault
)
3238 (fun v -> conf.bedefault
<- v)
3242 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3243 src#
bool ~offset
:0 ~
btos "Extended parameters"
3244 (fun () -> !showextended)
3245 (fun v -> showextended := v; fillsrc ());
3249 (fun () -> conf.checkers
)
3250 (fun v -> conf.checkers
<- v; setcheckers v);
3252 (fun () -> conf.verbose
)
3253 (fun v -> conf.verbose
<- v);
3254 src#
bool "invert colors"
3255 (fun () -> conf.invert
)
3256 (fun v -> conf.invert
<- v);
3258 (fun () -> conf.maxhfit
)
3259 (fun v -> conf.maxhfit
<- v);
3260 src#
string "uri launcher"
3261 (fun () -> conf.urilauncher
)
3262 (fun v -> conf.urilauncher
<- v);
3263 src#
string "tile size"
3264 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3267 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3268 conf.tileh
<- max
64 w;
3269 conf.tilew
<- max
64 h;
3272 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3273 v (Printexc.to_string exn
));
3274 src#
int "anti-aliasing level"
3275 (fun () -> conf.aalevel
)
3277 conf.aalevel
<- bound v 0 8;
3278 state.anchor <- getanchor ();
3279 opendoc state.path
state.password
;
3281 src#
int "ui font size"
3282 (fun () -> !uifontsize)
3283 (fun v -> uifontsize := bound v 5 100);
3284 colorp "background color"
3285 (fun () -> conf.bgcolor
)
3286 (fun v -> conf.bgcolor
<- v);
3287 src#
bool "crop hack"
3288 (fun () -> conf.crophack
)
3289 (fun v -> conf.crophack
<- v);
3290 src#
string "trim fuzz"
3291 (fun () -> irect_to_string conf.trimfuzz
)
3294 conf.trimfuzz
<- irect_of_string v;
3296 then settrim true conf.trimfuzz
;
3298 state.text <- Printf.sprintf
"bad irect `%s': %s"
3299 v (Printexc.to_string exn
)
3301 src#colorspace
"color space"
3302 (fun () -> colorspace_to_string conf.colorspace
)
3304 conf.colorspace
<- colorspace_of_int v;
3311 src#caption
"Document" 0;
3312 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3316 src#caption
"Trimmed margins" 0;
3317 src#caption2
"Dimensions"
3318 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3321 src#reset
state.mode
state.uioh;
3326 let source = (src :> lvsource
) in
3327 state.uioh <- object
3328 inherit listview ~
source ~trusted
:true
3329 val mutable m_prevmemused
= 0
3330 method infochanged
= function
3332 if m_prevmemused
!= state.memused
3334 m_prevmemused
<- state.memused
;
3335 G.postRedisplay "memusedchanged";
3337 | Pdim
-> G.postRedisplay "pdimchanged"
3338 | Docinfo
-> fillsrc ()
3340 G.postRedisplay "info";
3346 inherit lvsourcebase
3347 method getitemcount
= Array.length
state.help
3349 let s, n, _ = state.help
.(n) in
3352 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3356 m_qsearch
<- qsearch;
3357 match state.help
.(active) with
3358 | _, _, Action
f -> Some
(f uioh)
3368 method hasaction
n =
3369 match state.help
.(n) with
3370 | _, _, Action
_ -> true
3377 state.uioh <- new listview ~
source ~trusted
:true;
3378 G.postRedisplay "help";
3381 let quickbookmark ?title
() =
3382 match state.layout with
3388 let sec = Unix.gettimeofday
() in
3389 let tm = Unix.localtime
sec in
3390 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
3394 (tm.Unix.tm_year
+ 1900)
3397 | Some
title -> title
3400 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
3405 state.fullscreen
<- None
;
3406 Glut.reshapeWindow
w h;
3409 let viewkeyboard key =
3411 let mode = state.mode in
3412 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
3415 G.postRedisplay "view:enttext"
3417 let c = Char.chr
key in
3419 | '
\027'
| 'q'
-> (* escape *)
3420 begin match state.mstate
with
3422 state.mstate
<- Mnone
;
3423 Glut.setCursor
Glut.CURSOR_INHERIT
;
3424 G.postRedisplay "kill zoom rect";
3429 | '
\008'
-> (* backspace *)
3430 let y = getnav ~
-1 in
3431 gotoy_and_clear_text y
3439 G.postRedisplay "dehighlight";
3442 let ondone isforw
s =
3443 cbput state.hists
.pat
s;
3444 state.searchpattern
<- s;
3447 let s = String.create
1 in
3449 enttext (s, "", Some
(onhist state.hists
.pat
),
3450 textentry, ondone (c ='
/'
))
3452 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3453 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3454 setzoom (conf.zoom +. incr)
3459 try int_of_string
s with exc
->
3460 state.text <- Printf.sprintf
"bad integer `%s': %s"
3461 s (Printexc.to_string exc
);
3467 state.text <- "page bias is now " ^ string_of_int
n;
3470 enttext ("page bias: ", "", None
, intentry, ondone)
3472 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3473 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3474 setzoom (max
0.01 (conf.zoom -. decr))
3477 let ondone msg
= state.text <- msg
in
3479 "option [acfhilpstvAPRSZTI]: ", "", None
,
3480 optentry state.mode, ondone
3483 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3486 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3487 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
3491 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3497 try int_of_string
s with exc
->
3498 state.text <- Printf.sprintf
"bad integer `%s': %s"
3499 s (Printexc.to_string exc
);
3505 cbput state.hists
.pag
(string_of_int
n);
3506 gotoy_and_clear_text (getpagey (n + conf.pagebias
- 1))
3509 let pageentry text key =
3510 match Char.unsafe_chr
key with
3511 | 'g'
-> TEdone
text
3512 | _ -> intentry text key
3514 let text = "x" in text.[0] <- c;
3515 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
3518 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
3519 reshape conf.winw
conf.winh
;
3522 conf.hlinks
<- not
conf.hlinks
;
3523 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
3524 G.postRedisplay "toggle highlightlinks";
3527 begin match state.autoscroll
with
3529 conf.autoscrollstep
<- step
;
3530 state.autoscroll
<- None
3532 if conf.autoscrollstep
= 0
3533 then state.autoscroll
<- Some
1
3534 else state.autoscroll
<- Some
conf.autoscrollstep
3538 conf.presentation <- not
conf.presentation;
3539 if conf.presentation
3541 if not
conf.scrollbarinpm
3542 then state.scrollw
<- 0;
3545 state.scrollw
<- conf.scrollbw
;
3547 showtext ' '
("presentation mode " ^
3548 if conf.presentation then "on" else "off");
3549 state.anchor <- getanchor ();
3553 begin match state.fullscreen
with
3555 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
3558 state.fullscreen
<- None
;
3563 gotoy_and_clear_text 0
3566 gotopage1 (state.pagecount
- 1) 0
3569 search state.searchpattern
true
3572 search state.searchpattern
false
3575 begin match state.layout with
3578 gotoy_and_clear_text (getpagey l.pageno)
3582 begin match List.rev
state.layout with
3585 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
3586 gotoy_and_clear_text (getpagey pageno)
3589 | '
\127'
-> (* del *)
3590 begin match state.layout with
3593 let pageno = max
0 (l.pageno-1) in
3594 gotoy_and_clear_text (getpagey pageno)
3598 showtext ' '
(describe_location ());
3601 begin match state.layout with
3604 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
3609 enterbookmarkmode ()
3619 match state.layout with
3622 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
3626 enttext ("bookmark: ", "", None
, textentry, ondone)
3630 showtext ' '
"Quick bookmark added";
3633 begin match state.layout with
3635 let rect = getpdimrect
l.pagedimno
in
3639 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
3640 truncate
(1.2 *. (rect.(3) -. rect.(0))))
3642 (truncate
(rect.(1) -. rect.(0)),
3643 truncate
(rect.(3) -. rect.(0)))
3645 let w = truncate
((float w)*.conf.zoom)
3646 and h = truncate
((float h)*.conf.zoom) in
3649 state.anchor <- getanchor ();
3650 doreshape (w + state.scrollw
) (h + conf.interpagespace)
3652 G.postRedisplay "z";
3657 | '
\000'
-> (* ctrl-2 *)
3658 let maxw = getmaxw
() in
3660 then setzoom (maxw /. float conf.winw
)
3663 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
3667 bound (state.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
3669 G.postRedisplay "brightness";
3672 begin match state.mode with
3673 | Birdseye beye
-> upbirdseye beye
3674 | _ -> gotoy (clamp (-conf.scrollstep
))
3678 begin match state.mode with
3679 | Birdseye beye
-> downbirdseye beye
3680 | _ -> gotoy (clamp conf.scrollstep
)
3684 state.anchor <- getanchor ();
3685 opendoc state.path
state.password
3687 | '
v'
when conf.debug
->
3690 match getopaque l.pageno with
3693 let x0, y0
, x1
, y1
= pagebbox opaque
in
3694 let a,b = float x0, float y0
in
3695 let c,d = float x1
, float y0
in
3696 let e,f = float x1
, float y1
in
3697 let h,j
= float x0, float y1
in
3698 let rect = (a,b,c,d,e,f,h,j
) in
3700 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
3702 G.postRedisplay "v";
3705 vlog "huh? %d %c" key (Char.chr
key);
3708 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
3710 | 27 -> (* escape *)
3711 leavebirdseye beye
true
3713 | 12 -> (* ctrl-l *)
3714 let y, h = getpageyh pageno in
3715 let top = (conf.winh
- h) / 2 in
3716 gotoy (max
0 (y - top))
3719 leavebirdseye beye
false
3725 let keyboard ~
key ~
x ~
y =
3728 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
3729 then wcmd "interrupt" []
3730 else state.uioh <- state.uioh#
key key
3733 let birdseyespecial key ((conf, leftx
, _, hooverpageno
, anchor) as beye
) =
3735 | Glut.KEY_UP
-> upbirdseye beye
3736 | Glut.KEY_DOWN
-> downbirdseye beye
3738 | Glut.KEY_PAGE_UP
->
3739 begin match state.layout with
3743 state.mode <- Birdseye
(
3744 conf, leftx
, l.pageno, hooverpageno
, anchor
3746 gotopage1 l.pageno 0;
3749 let layout = layout (state.y-conf.winh
) conf.winh
in
3751 | [] -> gotoy (clamp (-conf.winh
))
3753 state.mode <- Birdseye
(
3754 conf, leftx
, l.pageno, hooverpageno
, anchor
3756 gotopage1 l.pageno 0
3759 | [] -> gotoy (clamp (-conf.winh
))
3762 | Glut.KEY_PAGE_DOWN
->
3763 begin match List.rev
state.layout with
3765 let layout = layout (state.y + conf.winh
) conf.winh
in
3766 begin match layout with
3768 let incr = l.pageh
- l.pagevh in
3773 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
3775 G.postRedisplay "birdseye pagedown";
3777 else gotoy (clamp (incr + conf.interpagespace*2));
3781 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
3782 gotopage1 l.pageno 0;
3785 | [] -> gotoy (clamp conf.winh
)
3789 state.mode <- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
3793 let pageno = state.pagecount
- 1 in
3794 state.mode <- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3795 if not
(pagevisible state.layout pageno)
3798 match List.rev
state.pdims
with
3800 | (_, _, h, _) :: _ -> h
3802 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
3803 else G.postRedisplay "birdseye end";
3807 let setautoscrollspeed step goingdown
=
3808 let incr = max
1 ((abs step
) / 2) in
3809 let incr = if goingdown
then incr else -incr in
3810 let astep = step
+ incr in
3811 state.autoscroll
<- Some
astep;
3814 let special ~
key ~
x ~
y =
3817 state.uioh <- state.uioh#
special key
3822 match state.mode with
3823 | Textentry
_ -> scalecolor 0.4
3824 | View
-> scalecolor 1.0
3825 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
3826 if l.pageno = hooverpageno
3829 if l.pageno = pageno
3835 begin match getopaque l.pageno with
3837 if tileready l l.pagex l.pagey
3839 let x = l.pagedispx
- l.pagex
3840 and y = l.pagedispy
- l.pagey in
3841 postprocess opaque
conf.hlinks
x y;
3848 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3849 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
3850 let sh = float conf.winh
/. sh in
3851 let sh = max
sh (float conf.scrollh
) in
3856 else float y /. float maxy
3858 let position = (float conf.winh
-. sh) *. percent in
3861 if position +. sh > float conf.winh
3862 then float conf.winh
-. sh
3869 let winw = conf.winw - state.scrollw
- 1 in
3870 let fwinw = float winw in
3872 let sw = fwinw /. float state.w in
3873 let sw = fwinw *. sw in
3874 max
sw (float conf.scrollh
)
3877 let f = state.w+winw in
3878 let r = float (winw-x) /. float f in
3879 let p = fwinw *. r in
3883 if position +. sw > fwinw
3884 then fwinw -. position
3890 let scrollindicator () =
3891 GlDraw.color (0.64 , 0.64, 0.64);
3893 (float (conf.winw - state.scrollw
), 0.)
3894 (float conf.winw, float conf.winh
)
3897 (0., float (conf.winh
- state.hscrollh))
3898 (float (conf.winw - state.scrollw
- 1), float conf.winh
)
3900 GlDraw.color (0.0, 0.0, 0.0);
3902 let position, sh = scrollph state.y in
3904 (float (conf.winw - state.scrollw
), position)
3905 (float conf.winw, position +. sh)
3907 let position, sw = scrollpw state.x in
3909 (position, float (conf.winh
- state.hscrollh))
3910 (position +. sw, float conf.winh
)
3914 let pagetranslatepoint l x y =
3915 let dy = y - l.pagedispy
in
3916 let y = dy + l.pagey in
3917 let dx = x - l.pagedispx
in
3918 let x = dx + l.pagex in
3923 match state.mstate
with
3924 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
3927 | Msel
((x0, y0
), (x1
, y1
)) ->
3928 let rec loop = function
3930 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
3931 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
3933 match getopaque l.pageno with
3935 let dx, dy = pagetranslatepoint l 0 0 in
3940 GlMat.mode `modelview
;
3942 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
3943 seltext opaque
(x0, y0
, x1
, y1
);
3954 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
3955 GlDraw.polygon_mode `both `fill
;
3956 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3958 (fun (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
3960 if l.pageno = pageno
3962 let dx = float (l.pagedispx
- l.pagex) in
3963 let dy = float (l.pagedispy
- l.pagey) in
3964 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
3965 GlDraw.begins `quads
;
3967 GlDraw.vertex2
(x0+.dx, y0
+.dy);
3968 GlDraw.vertex2
(x1
+.dx, y1
+.dy);
3969 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
3970 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
3981 GlClear.color (scalecolor2 conf.bgcolor
);
3982 GlClear.clear
[`
color];
3983 List.iter
drawpage state.layout;
3988 begin match state.mstate
with
3989 | Mzoomrect
((x0, y0
), (x1
, y1
)) ->
3991 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
3992 GlDraw.polygon_mode `both `fill
;
3993 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3994 GlDraw.rect (float x0, float y0
)
3995 (float x1
, float y1
);
4000 Glut.swapBuffers
();
4004 let rec f = function
4006 begin match getopaque l.pageno with
4008 let x0 = l.pagedispx
in
4009 let x1 = x0 + l.pagevw in
4010 let y0 = l.pagedispy
in
4011 let y1 = y0 + l.pagevh in
4012 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4014 let px, py = pagetranslatepoint l x y in
4015 match whatsunder opaque
px py with
4027 let zoomrect x y x1 y1 =
4030 and y0 = min
y y1 in
4031 gotoy (state.y + y0);
4032 state.anchor <- getanchor ();
4033 let zoom = (float conf.winw *. conf.zoom) /. float (x1 - x0) in
4034 state.x <- state.x - x0;
4036 Glut.setCursor
Glut.CURSOR_INHERIT
;
4037 state.mstate
<- Mnone
;
4041 let winw = conf.winw - state.scrollw
- 1 in
4042 let s = float x /. float winw in
4043 let destx = truncate
(float (state.w + winw) *. s) in
4044 state.x <- winw - destx;
4045 gotoy_and_clear_text state.y;
4046 state.mstate
<- Mscrollx
;
4050 let s = float y /. float conf.winh
in
4051 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4052 gotoy_and_clear_text desty;
4053 state.mstate
<- Mscrolly
;
4056 let viewmouse button bstate
x y =
4058 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4059 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4061 match state.mstate
with
4062 | Mzoom
(oldn
, i
) ->
4070 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4072 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4074 let zoom = conf.zoom -. incr in
4076 state.mstate
<- Mzoom
(n, 0);
4078 state.mstate
<- Mzoom
(n, i
+1);
4080 else state.mstate
<- Mzoom
(n, 0)
4082 | _ -> state.mstate
<- Mzoom
(n, 0)
4085 match state.autoscroll
with
4086 | Some step
-> setautoscrollspeed step
(n=4)
4090 then -conf.scrollstep
4091 else conf.scrollstep
4093 let incr = incr * 2 in
4094 let y = clamp incr in
4095 gotoy_and_clear_text y
4098 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4099 if bstate
= Glut.DOWN
4101 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4102 state.mstate
<- Mpan
(x, y)
4105 state.mstate
<- Mnone
4107 | Glut.RIGHT_BUTTON
->
4108 if bstate
= Glut.DOWN
4110 Glut.setCursor
Glut.CURSOR_CYCLE
;
4112 state.mstate
<- Mzoomrect
(p, p)
4115 match state.mstate
with
4116 | Mzoomrect
((x0, y0), _) -> zoomrect x0 y0 x y
4118 Glut.setCursor
Glut.CURSOR_INHERIT
;
4119 state.mstate
<- Mnone
4122 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4123 if bstate
= Glut.DOWN
4125 let position, sh = scrollph state.y in
4126 if y > truncate
position && y < truncate
(position +. sh)
4127 then state.mstate
<- Mscrolly
4130 state.mstate
<- Mnone
4132 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4133 if bstate
= Glut.DOWN
4135 let position, sw = scrollpw state.x in
4136 if x > truncate
position && x < truncate
(position +. sw)
4137 then state.mstate
<- Mscrollx
4140 state.mstate
<- Mnone
4142 | Glut.LEFT_BUTTON
->
4143 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4144 begin match dest with
4145 | Ulinkgoto
(pageno, top) ->
4149 gotopage1 pageno top;
4155 | Unone
when bstate
= Glut.DOWN
->
4156 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4157 state.mstate
<- Mpan
(x, y);
4159 | Unone
| Utext
_ ->
4160 if bstate
= Glut.DOWN
4162 if conf.angle
mod 360 = 0
4164 state.mstate
<- Msel
((x, y), (x, y));
4165 G.postRedisplay "mouse select";
4169 match state.mstate
with
4172 | Mzoom
_ | Mscrollx
| Mscrolly
->
4173 state.mstate
<- Mnone
4175 | Mzoomrect
((x0, y0), _) ->
4179 Glut.setCursor
Glut.CURSOR_INHERIT
;
4180 state.mstate
<- Mnone
4182 | Msel
((_, y0), (_, y1)) ->
4184 if (y0 >= l.pagedispy
&& y0 <= (l.pagedispy
+ l.pagevh))
4185 || ((y1 >= l.pagedispy
&& y1 <= (l.pagedispy
+ l.pagevh)))
4187 match getopaque l.pageno with
4192 List.iter
f state.layout;
4193 copysel
""; (* ugly *)
4194 Glut.setCursor
Glut.CURSOR_INHERIT
;
4195 state.mstate
<- Mnone
;
4202 let birdseyemouse button bstate
x y
4203 (conf, leftx
, _, hooverpageno
, anchor) =
4205 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4206 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4207 let rec loop = function
4210 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4211 && x > margin && x < margin + l.pagew
4213 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4218 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4222 let mouse bstate button
x y =
4223 state.uioh <- state.uioh#button button bstate
x y;
4226 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4229 state.uioh <- state.uioh#
motion x y
4233 state.uioh <- state.uioh#
pmotion x y;
4240 begin match state.mode with
4241 | Textentry
textentry -> textentrykeyboard key textentry
4242 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4243 | View
-> viewkeyboard key
4247 method special key =
4248 begin match state.mode with
4249 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4253 birdseyespecial key vals
4255 | View
when key = Glut.KEY_F1
->
4259 begin match state.autoscroll
with
4260 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4261 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4266 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4268 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4270 if Glut.getModifiers
() land Glut.active_shift
!= 0
4271 then (setzoom state.prevzoom
; state.y)
4272 else clamp (-conf.winh
/2)
4273 else clamp (-conf.scrollstep
)
4275 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4277 if Glut.getModifiers
() land Glut.active_shift
!= 0
4278 then (setzoom state.prevzoom
; state.y)
4279 else clamp (conf.winh
/2)
4280 else clamp (conf.scrollstep
)
4281 | Glut.KEY_PAGE_UP
->
4282 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4284 match state.layout with
4286 | l :: _ -> state.y - l.pagey
4289 | Glut.KEY_PAGE_DOWN
->
4290 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4292 match List.rev
state.layout with
4294 | l :: _ -> getpagey l.pageno
4302 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
4304 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
4305 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
4306 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
4308 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
4310 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4311 then (conf.winw / 2)
4314 state.x <- state.x - dx;
4316 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
4318 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4319 then (conf.winw / 2)
4322 state.x <- state.x + dx;
4327 gotoy_and_clear_text y
4330 | Textentry
te -> textentryspecial key te
4334 method button button bstate
x y =
4335 begin match state.mode with
4336 | View
-> viewmouse button bstate
x y
4337 | Birdseye beye
-> birdseyemouse button bstate
x y beye
4343 begin match state.mode with
4345 | View
| Birdseye
_ ->
4346 match state.mstate
with
4347 | Mzoom
_ | Mnone
-> ()
4352 state.mstate
<- Mpan
(x, y);
4353 if conf.zoom > 1.0 then state.x <- state.x + dx;
4355 gotoy_and_clear_text y
4358 state.mstate
<- Msel
(a, (x, y));
4359 G.postRedisplay "motion select";
4362 let y = min
conf.winh
(max
0 y) in
4366 let x = min
conf.winw (max
0 x) in
4369 | Mzoomrect
(p0
, _) ->
4370 state.mstate
<- Mzoomrect
(p0
, (x, y));
4371 G.postRedisplay "motion zoomrect";
4375 method pmotion x y =
4376 begin match state.mode with
4377 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
4378 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4379 let rec loop = function
4381 if hooverpageno
!= -1
4383 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
4384 G.postRedisplay "pmotion birdseye no hoover";
4387 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4388 && x > margin && x < margin + l.pagew
4390 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
4391 G.postRedisplay "pmotion birdseye hoover";
4400 match state.mstate
with
4402 begin match getunder x y with
4403 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
4405 if conf.underinfo
then showtext 'u'
("ri: " ^
uri);
4406 Glut.setCursor
Glut.CURSOR_INFO
4407 | Ulinkgoto
(page
, _) ->
4409 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
4410 Glut.setCursor
Glut.CURSOR_INFO
4412 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
4413 Glut.setCursor
Glut.CURSOR_TEXT
4416 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
4421 method infochanged
_ = ()
4428 let fontpath = ref "";;
4429 let wmclasshack = ref false;;
4432 let l = String.length
s in
4433 let b = Buffer.create
l in
4441 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
4442 | _ -> Sys.getenv
"HOME"
4445 ("Can not determine home directory location: " ^
4446 Printexc.to_string exn
);
4450 let config_of c attrs
=
4454 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
4455 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
4456 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
4457 | "preload" -> { c with preload = bool_of_string
v }
4458 | "page-bias" -> { c with pagebias
= int_of_string
v }
4459 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
4460 | "auto-scroll-step" ->
4461 { c with autoscrollstep
= max
0 (int_of_string
v) }
4462 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
4463 | "crop-hack" -> { c with crophack
= bool_of_string
v }
4464 | "throttle" -> { c with showall
= bool_of_string
v }
4465 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
4466 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
4467 | "vertical-margin" ->
4468 { c with interpagespace = max
0 (int_of_string
v) }
4470 let zoom = float_of_string
v /. 100. in
4471 let zoom = max
zoom 0.0 in
4472 { c with zoom = zoom }
4473 | "presentation" -> { c with presentation = bool_of_string
v }
4474 | "rotation-angle" -> { c with angle
= int_of_string
v }
4475 | "width" -> { c with winw = max
20 (int_of_string
v) }
4476 | "height" -> { c with winh
= max
20 (int_of_string
v) }
4477 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
4478 | "proportional-display" -> { c with proportional
= bool_of_string
v }
4479 | "pixmap-cache-size" ->
4480 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
4481 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
4482 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
4483 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
4484 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
4485 | "background-color" -> { c with bgcolor
= color_of_string v }
4486 | "scrollbar-in-presentation" ->
4487 { c with scrollbarinpm
= bool_of_string
v }
4488 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
4489 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
4491 { c with mumemlimit
= max
1024 (int_of_string_with_suffix v) }
4492 | "checkers" -> { c with checkers
= bool_of_string
v }
4493 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
4494 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
4495 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
4496 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
4497 | "uri-launcher" -> { c with urilauncher
= unent v }
4498 | "color-space" -> { c with colorspace
= colorspace_of_string v }
4499 | "invert-colors" -> { c with invert
= bool_of_string
v }
4502 prerr_endline
("Error processing attribute (`" ^
4503 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
4506 let rec fold c = function
4509 let c = apply c k
v in
4515 let fromstring f pos
n v d =
4518 dolog "Error processing attribute (%S=%S) at %d\n%s"
4519 n v pos
(Printexc.to_string exn
)
4524 let bookmark_of attrs
=
4525 let rec fold title page rely
= function
4526 | ("title", v) :: rest
-> fold v page rely rest
4527 | ("page", v) :: rest
-> fold title v rely rest
4528 | ("rely", v) :: rest
-> fold title page
v rest
4529 | _ :: rest
-> fold title page rely rest
4530 | [] -> title, page
, rely
4532 fold "invalid" "0" "0" attrs
4536 let rec fold path page rely pan
= function
4537 | ("path", v) :: rest
-> fold v page rely pan rest
4538 | ("page", v) :: rest
-> fold path
v rely pan rest
4539 | ("rely", v) :: rest
-> fold path page
v pan rest
4540 | ("pan", v) :: rest
-> fold path page rely
v rest
4541 | _ :: rest
-> fold path page rely pan rest
4542 | [] -> path
, page
, rely
, pan
4544 fold "" "0" "0" "0" attrs
4547 let setconf dst
src =
4548 dst
.scrollbw
<- src.scrollbw
;
4549 dst
.scrollh
<- src.scrollh
;
4550 dst
.icase
<- src.icase
;
4551 dst
.preload <- src.preload;
4552 dst
.pagebias
<- src.pagebias
;
4553 dst
.verbose
<- src.verbose
;
4554 dst
.scrollstep
<- src.scrollstep
;
4555 dst
.maxhfit
<- src.maxhfit
;
4556 dst
.crophack
<- src.crophack
;
4557 dst
.autoscrollstep
<- src.autoscrollstep
;
4558 dst
.showall
<- src.showall
;
4559 dst
.hlinks
<- src.hlinks
;
4560 dst
.underinfo
<- src.underinfo
;
4561 dst
.interpagespace <- src.interpagespace;
4562 dst
.zoom <- src.zoom;
4563 dst
.presentation <- src.presentation;
4564 dst
.angle
<- src.angle
;
4565 dst
.winw <- src.winw;
4566 dst
.winh
<- src.winh
;
4567 dst
.savebmarks
<- src.savebmarks
;
4568 dst
.memlimit
<- src.memlimit
;
4569 dst
.proportional
<- src.proportional
;
4570 dst
.texcount
<- src.texcount
;
4571 dst
.sliceheight
<- src.sliceheight
;
4572 dst
.thumbw
<- src.thumbw
;
4573 dst
.jumpback
<- src.jumpback
;
4574 dst
.bgcolor
<- src.bgcolor
;
4575 dst
.scrollbarinpm
<- src.scrollbarinpm
;
4576 dst
.tilew
<- src.tilew
;
4577 dst
.tileh
<- src.tileh
;
4578 dst
.mumemlimit
<- src.mumemlimit
;
4579 dst
.checkers
<- src.checkers
;
4580 dst
.aalevel
<- src.aalevel
;
4581 dst
.trimmargins
<- src.trimmargins
;
4582 dst
.trimfuzz
<- src.trimfuzz
;
4583 dst
.urilauncher
<- src.urilauncher
;
4584 dst
.colorspace
<- src.colorspace
;
4585 dst
.invert
<- src.invert
;
4589 let h = Hashtbl.create
10 in
4590 let dc = { defconf with angle
= defconf.angle
} in
4591 let rec toplevel v t spos
_ =
4593 | Vdata
| Vcdata
| Vend
-> v
4594 | Vopen
("llppconfig", _, closed
) ->
4597 else { v with f = llppconfig
}
4599 error
"unexpected subelement at top level" s spos
4600 | Vclose
_ -> error
"unexpected close at top level" s spos
4602 and llppconfig
v t spos
_ =
4604 | Vdata
| Vcdata
-> v
4605 | Vend
-> error
"unexpected end of input in llppconfig" s spos
4606 | Vopen
("defaults", attrs
, closed
) ->
4607 let c = config_of dc attrs
in
4611 else { v with f = skip
"defaults" (fun () -> v) }
4613 | Vopen
("ui-font", attrs
, closed
) ->
4614 let rec getsize size
= function
4616 | ("size", v) :: rest
->
4618 fromstring int_of_string spos
"size" v !uifontsize in
4620 | l -> getsize size l
4622 uifontsize := getsize !uifontsize attrs
;
4625 else { v with f = uifont
(Buffer.create
10) }
4627 | Vopen
("doc", attrs
, closed
) ->
4628 let pathent, spage
, srely
, span
= doc_of attrs
in
4629 let path = unent pathent
4630 and pageno = fromstring int_of_string spos
"page" spage
0
4631 and rely
= fromstring float_of_string spos
"rely" srely
0.0
4632 and pan
= fromstring int_of_string spos
"pan" span
0 in
4633 let c = config_of dc attrs
in
4634 let anchor = (pageno, rely
) in
4636 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
4637 else { v with f = doc
path pan
anchor c [] }
4640 error
"unexpected subelement in llppconfig" s spos
4642 | Vclose
"llppconfig" -> { v with f = toplevel }
4643 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
4645 and uifont
b v t spos epos
=
4648 Buffer.add_substring
b s spos
(epos
- spos
);
4650 | Vopen
(_, _, _) ->
4651 error
"unexpected subelement in ui-font" s spos
4652 | Vclose
"ui-font" ->
4653 if String.length
!fontpath = 0
4654 then fontpath := Buffer.contents
b;
4655 { v with f = llppconfig
}
4656 | Vclose
_ -> error
"unexpected close in ui-font" s spos
4657 | Vend
-> error
"unexpected end of input in ui-font" s spos
4659 and doc
path pan
anchor c bookmarks
v t spos
_ =
4661 | Vdata
| Vcdata
-> v
4662 | Vend
-> error
"unexpected end of input in doc" s spos
4663 | Vopen
("bookmarks", _, closed
) ->
4666 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
4668 | Vopen
(_, _, _) ->
4669 error
"unexpected subelement in doc" s spos
4672 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
4673 { v with f = llppconfig
}
4675 | Vclose
_ -> error
"unexpected close in doc" s spos
4677 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
4679 | Vdata
| Vcdata
-> v
4680 | Vend
-> error
"unexpected end of input in bookmarks" s spos
4681 | Vopen
("item", attrs
, closed
) ->
4682 let titleent, spage
, srely
= bookmark_of attrs
in
4683 let page = fromstring int_of_string spos
"page" spage
0
4684 and rely
= fromstring float_of_string spos
"rely" srely
0.0 in
4685 let bookmarks = (unent titleent, 0, (page, rely
)) :: bookmarks in
4687 then { v with f = pbookmarks
path pan
anchor c bookmarks }
4690 { v with f = skip
"item" f }
4693 error
"unexpected subelement in bookmarks" s spos
4695 | Vclose
"bookmarks" ->
4696 { v with f = doc
path pan
anchor c bookmarks }
4698 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
4700 and skip tag
f v t spos
_ =
4702 | Vdata
| Vcdata
-> v
4704 error
("unexpected end of input in skipped " ^ tag
) s spos
4705 | Vopen
(tag'
, _, closed
) ->
4709 let f'
() = { v with f = skip tag
f } in
4710 { v with f = skip tag'
f'
}
4714 else error
("unexpected close in skipped " ^ tag
) s spos
4717 parse
{ f = toplevel; accu = () } s;
4723 let len = in_channel_length ic
in
4724 let s = String.create
len in
4725 really_input ic
s 0 len;
4728 | Parse_error
(msg
, s, pos
) ->
4729 let subs = subs s pos
in
4730 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
4731 failwith
("parse error: " ^
s)
4734 failwith
("config load error: " ^
Printexc.to_string exn
)
4740 let dir = Filename.concat
home ".config" in
4741 if Sys.is_directory
dir then dir else home
4744 Filename.concat
dir "llpp.conf"
4747 let confpath = ref defconfpath;;
4750 if Sys.file_exists
!confpath
4753 (try Some
(open_in_bin
!confpath)
4756 ("Error opening configuation file `" ^
!confpath ^
"': " ^
4757 Printexc.to_string exn
);
4766 ("Error loading configuation from `" ^
!confpath ^
"': " ^
4767 Printexc.to_string exn
);
4773 f (Hashtbl.create
0, defconf)
4778 let pc, pb
, px, pa
=
4780 Hashtbl.find h (Filename.basename
state.path)
4781 with Not_found
-> dc, [], 0, (0, 0.0)
4785 state.bookmarks <- pb
;
4787 state.scrollw
<- conf.scrollbw
;
4789 then state.anchor <- pa
;
4790 cbput state.hists
.nav pa
;
4795 let add_attrs bb always
dc c =
4798 then Printf.bprintf bb
"\n %s='%b'" s a
4801 then Printf.bprintf bb
"\n %s='%d'" s a
4804 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
4807 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
4811 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
4815 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
4819 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
4823 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
4827 then dc.winw, dc.winh
4829 match state.fullscreen
with
4831 | None
-> c.winw, c.winh
4833 let zoom, presentation, interpagespace, showall
=
4835 then dc.zoom, dc.presentation, dc.interpagespace, dc.showall
4837 match state.mode with
4838 | Birdseye
(bc
, _, _, _, _) ->
4839 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.showall
4840 | _ -> c.zoom, c.presentation, c.interpagespace, c.showall
4842 oi
"width" w dc.winw;
4843 oi
"height" h dc.winh
;
4844 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
4845 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
4846 ob "case-insensitive-search" c.icase
dc.icase
;
4847 ob "preload" c.preload dc.preload;
4848 oi
"page-bias" c.pagebias
dc.pagebias
;
4849 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
4850 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
4851 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
4852 ob "crop-hack" c.crophack
dc.crophack
;
4853 ob "throttle" showall
dc.showall
;
4854 ob "highlight-links" c.hlinks
dc.hlinks
;
4855 ob "under-cursor-info" c.underinfo
dc.underinfo
;
4856 oi
"vertical-margin" interpagespace dc.interpagespace;
4857 oz
"zoom" zoom dc.zoom;
4858 ob "presentation" presentation dc.presentation;
4859 oi
"rotation-angle" c.angle
dc.angle
;
4860 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
4861 ob "proportional-display" c.proportional
dc.proportional
;
4862 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
4863 oi
"tex-count" c.texcount
dc.texcount
;
4864 oi
"slice-height" c.sliceheight
dc.sliceheight
;
4865 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
4866 ob "persistent-location" c.jumpback
dc.jumpback
;
4867 oc
"background-color" c.bgcolor
dc.bgcolor
;
4868 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
4869 oi
"tile-width" c.tilew
dc.tilew
;
4870 oi
"tile-height" c.tileh
dc.tileh
;
4871 oI
"mupdf-memlimit" c.mumemlimit
dc.mumemlimit
;
4872 ob "checkers" c.checkers
dc.checkers
;
4873 oi
"aalevel" c.aalevel
dc.aalevel
;
4874 ob "trim-margins" c.trimmargins
dc.trimmargins
;
4875 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
4876 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
4877 oC
"color-space" c.colorspace
dc.colorspace
;
4878 ob "invert-colors" c.invert
dc.invert
;
4880 then ob "wmclass-hack" !wmclasshack false;
4884 let uifontsize = !uifontsize in
4885 let bb = Buffer.create
32768 in
4887 let dc = if conf.bedefault
then conf else dc in
4888 Buffer.add_string
bb "<llppconfig>\n";
4890 if String.length
!fontpath > 0
4892 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
4898 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
4901 Buffer.add_string
bb "<defaults ";
4902 add_attrs bb true dc dc;
4903 Buffer.add_string
bb "/>\n";
4905 let adddoc path pan
anchor c bookmarks =
4906 if bookmarks == [] && c = dc && anchor = emptyanchor
4909 Printf.bprintf
bb "<doc path='%s'"
4910 (enent
path 0 (String.length
path));
4912 if anchor <> emptyanchor
4914 let n, y = anchor in
4915 Printf.bprintf
bb " page='%d'" n;
4918 Printf.bprintf
bb " rely='%f'" y
4923 then Printf.bprintf
bb " pan='%d'" pan
;
4925 add_attrs bb false dc c;
4927 begin match bookmarks with
4928 | [] -> Buffer.add_string
bb "/>\n"
4930 Buffer.add_string
bb ">\n<bookmarks>\n";
4931 List.iter
(fun (title, _level
, (page, rely
)) ->
4933 "<item title='%s' page='%d'"
4934 (enent
title 0 (String.length
title))
4939 Printf.bprintf
bb " rely='%f'" rely
4941 Buffer.add_string
bb "/>\n";
4943 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
4949 match state.mode with
4950 | Birdseye
(_, pan, _, _, _) -> pan
4953 let basename = Filename.basename state.path in
4954 adddoc basename pan (getanchor ())
4957 match state.autoscroll
with
4959 | None
-> conf.autoscrollstep
}
4960 (if conf.savebmarks
then state.bookmarks else []);
4962 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
4964 then adddoc path x y c bookmarks
4966 Buffer.add_string
bb "</llppconfig>";
4969 if Buffer.length
bb > 0
4972 let tmp = !confpath ^
".tmp" in
4973 let oc = open_out_bin
tmp in
4974 Buffer.output_buffer
oc bb;
4976 Unix.rename
tmp !confpath;
4979 ("error while saving configuration: " ^
Printexc.to_string exn
)
4986 [("-p", Arg.String
(fun s -> state.password
<- s) ,
4987 "<password> Set password");
4989 ("-f", Arg.String
(fun s -> Config.fontpath := s),
4990 "<path> Set path to the user interface font");
4992 ("-c", Arg.String
(fun s -> Config.confpath := s),
4993 "<path> Set path to the configuration file");
4995 ("-v", Arg.Unit
(fun () ->
4997 "%s\nconfiguration path: %s\n"
5001 exit
0), " Print version and exit");
5004 (fun s -> state.path <- s)
5005 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5007 if String.length
state.path = 0
5008 then (prerr_endline
"file name missing"; exit
1);
5012 let _ = Glut.init
Sys.argv
in
5013 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5014 let () = Glut.initWindowSize
conf.winw conf.winh
in
5015 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5017 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5018 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5019 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5024 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5026 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5027 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5028 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5029 Unix.bind
sock addr;
5031 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5032 Unix.connect
csock addr;
5033 let ssock, _ = Unix.accept
sock in
5036 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5037 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5044 let () = Glut.displayFunc
display in
5045 let () = Glut.reshapeFunc
reshape in
5046 let () = Glut.keyboardFunc
keyboard in
5047 let () = Glut.specialFunc
special in
5048 let () = Glut.idleFunc
(Some
idle) in
5049 let () = Glut.mouseFunc
mouse in
5050 let () = Glut.motionFunc
motion in
5051 let () = Glut.passiveMotionFunc
pmotion in
5053 setcheckers conf.checkers
;
5055 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5056 conf.texcount
, conf.sliceheight
, conf.mumemlimit
, conf.colorspace
,
5057 !Config.wmclasshack, !Config.fontpath
5059 state.csock <- csock;
5060 state.ssock <- ssock;
5061 state.text <- "Opening " ^
state.path;
5062 setaalevel
conf.aalevel
;
5063 writeopen state.path state.password
;
5070 | Glut.BadEnum
"key in special_of_int" ->
5071 showtext '
!'
" LablGlut bug: special key not recognized";