4 | Ulinkgoto
of (int * int)
6 | Uunexpected
of string
10 and facename
= string;;
12 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
13 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* wmclasshack
* fontpath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
38 and wmclasshack
= bool
39 and irect
= (int * int * int * int)
40 and trimparams
= (trimmargins
* irect
)
41 and colorspace
= | Rgb
| Bgr
| Gray
44 type platform
= | Punknown
| Plinux
| Pwindows
| Posx
| Psun
45 | Pfreebsd
| Pdragonflybsd
| Popenbsd
| Pnetbsd
48 external init
: Unix.file_descr
-> params
-> unit = "ml_init";;
49 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
50 external copysel
: string -> unit = "ml_copysel";;
51 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
52 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
53 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
54 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
55 external measurestr
: int -> string -> float = "ml_measure_string";;
56 external getmaxw
: unit -> float = "ml_getmaxw";;
57 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
58 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
59 external platform
: unit -> platform
= "ml_platform";;
60 external setaalevel
: int -> unit = "ml_setaalevel";;
61 external realloctexts
: int -> bool = "ml_realloctexts";;
63 let platform_to_string = function
64 | Punknown
-> "unknown"
66 | Pwindows
-> "Windows"
69 | Pfreebsd
-> "FreeBSD"
70 | Pdragonflybsd
-> "DragonflyBSD"
71 | Popenbsd
-> "OpenBSD"
77 let platform = platform ();;
81 | Pwindows
| Pmingw
-> true
89 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
92 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
96 | Msel
of (mpos
* mpos
)
99 | Mzoom
of (int * int)
100 | Mzoomrect
of (mpos
* mpos
)
104 type textentry
= string * string * onhist
option * onkey
* ondone
105 and onkey
= string -> int -> te
106 and ondone
= string -> unit
107 and histcancel
= unit -> unit
108 and onhist
= ((histcmd
-> string) * histcancel
)
109 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
114 | TEswitch
of textentry
125 let bound v minv maxv
=
126 max minv
(min maxv v
);
130 { store
= Array.create n v
137 let drawstring size x y s
=
139 Gl.enable `texture_2d
;
140 ignore
(drawstr size x y s
);
142 Gl.disable `texture_2d
;
145 let drawstring1 size x y s
=
149 let drawstring2 size x y fmt
=
150 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
153 let cbcap b
= Array.length b
.store
;;
158 b
.wc
<- (b
.wc
+ 1) mod cap;
160 b
.len
<- min
(b
.len
+ 1) cap;
163 let cbempty b
= b
.len
= 0;;
165 let cbgetg b circular dir
=
169 let rc = b
.rc + dir
in
181 else max
0 (min
rc (b
.len
-1))
187 let cbget b
= cbgetg b
false;;
188 let cbgetc b
= cbgetg b
true;;
205 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
206 dolog " WxH %dx%d" l
.pagew l
.pageh
;
207 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
208 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
209 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
213 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
215 dolog " x0,y0=(% f, % f)" x0 y0
;
216 dolog " x1,y1=(% f, % f)" x1 y1
;
217 dolog " x2,y2=(% f, % f)" x2 y2
;
218 dolog " x3,y3=(% f, % f)" x3 y3
;
223 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
224 and multicol
= columncount
* covercount
* covercount
226 and columncount
= int
227 and covercount
= int;;
230 { mutable scrollbw
: int
231 ; mutable scrollh
: int
232 ; mutable icase
: bool
233 ; mutable preload
: bool
234 ; mutable pagebias
: int
235 ; mutable verbose
: bool
236 ; mutable debug
: bool
237 ; mutable scrollstep
: int
238 ; mutable maxhfit
: bool
239 ; mutable crophack
: bool
240 ; mutable autoscrollstep
: int
241 ; mutable maxwait
: float option
242 ; mutable hlinks
: bool
243 ; mutable underinfo
: bool
244 ; mutable interpagespace
: interpagespace
245 ; mutable zoom
: float
246 ; mutable presentation
: bool
247 ; mutable angle
: angle
250 ; mutable savebmarks
: bool
251 ; mutable proportional
: proportional
252 ; mutable trimmargins
: trimmargins
253 ; mutable trimfuzz
: irect
254 ; mutable memlimit
: memsize
255 ; mutable texcount
: texcount
256 ; mutable sliceheight
: sliceheight
257 ; mutable thumbw
: width
258 ; mutable jumpback
: bool
259 ; mutable bgcolor
: float * float * float
260 ; mutable bedefault
: bool
261 ; mutable scrollbarinpm
: bool
262 ; mutable tilew
: int
263 ; mutable tileh
: int
264 ; mutable mustoresize
: memsize
265 ; mutable checkers
: bool
266 ; mutable aalevel
: int
267 ; mutable urilauncher
: string
268 ; mutable colorspace
: colorspace
269 ; mutable invert
: bool
270 ; mutable colorscale
: float
271 ; mutable redirectstderr
: bool
272 ; mutable ghyllscroll
: (int * int * int) option
273 ; mutable columns
: columns
option
274 ; mutable beyecolumns
: columncount
option
278 type anchor
= pageno
* top
;;
280 type outline
= string * int * anchor
;;
282 type rect
= float * float * float * float * float * float * float * float;;
284 type tile
= opaque
* pixmapsize
* elapsed
285 and elapsed
= float;;
286 type pagemapkey
= pageno
* gen
;;
287 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
291 let emptyanchor = (0, 0.0);;
293 type infochange
= | Memused
| Docinfo
| Pdim
;;
295 class type uioh
= object
296 method display
: unit
297 method key
: int -> uioh
298 method special
: Glut.special_key_t
-> uioh
300 Glut.button_t
-> Glut.mouse_button_state_t
-> int -> int -> uioh
301 method motion
: int -> int -> uioh
302 method pmotion
: int -> int -> uioh
303 method infochanged
: infochange
-> unit
304 method scrollpw
: (int * float * float)
305 method scrollph
: (int * float * float)
309 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
310 | Textentry
of (textentry
* onleave
)
312 and onleave
= leavetextentrystatus
-> unit
313 and leavetextentrystatus
= | Cancel
| Confirm
314 and helpitem
= string * int * action
317 | Action
of (uioh
-> uioh
)
320 let isbirdseye = function Birdseye _
-> true | _
-> false;;
321 let istextentry = function Textentry _
-> true | _
-> false;;
325 | Loading
of (page
* gen
)
327 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
329 | Outlining
of outline list
332 let nouioh : uioh
= object (self
)
335 method special _
= self
336 method button _ _ _ _
= self
337 method motion _ _
= self
338 method pmotion _ _
= self
339 method infochanged _
= ()
340 method scrollpw
= (0, nan
, nan
)
341 method scrollph
= (0, nan
, nan
)
345 { mutable csock
: Unix.file_descr
346 ; mutable ssock
: Unix.file_descr
347 ; mutable errfd
: Unix.file_descr
option
348 ; mutable stderr
: Unix.file_descr
349 ; mutable errmsgs
: Buffer.t
350 ; mutable newerrmsgs
: bool
354 ; mutable scrollw
: int
355 ; mutable hscrollh
: int
356 ; mutable anchor
: anchor
358 ; mutable layout
: page list
359 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
360 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
361 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
362 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
363 ; mutable pagecount
: int
364 ; mutable currently
: currently
365 ; mutable mstate
: mstate
366 ; mutable searchpattern
: string
367 ; mutable rects
: (pageno
* recttype
* rect
) list
368 ; mutable rects1
: (pageno
* recttype
* rect
) list
369 ; mutable text
: string
370 ; mutable fullscreen
: (width
* height
) option
371 ; mutable mode
: mode
372 ; mutable uioh
: uioh
373 ; mutable outlines
: outline array
374 ; mutable bookmarks
: outline list
375 ; mutable path
: string
376 ; mutable password
: string
377 ; mutable invalidated
: int
378 ; mutable memused
: memsize
380 ; mutable throttle
: (page list
* int * float) option
381 ; mutable autoscroll
: int option
382 ; mutable ghyll
: int option -> unit
383 ; mutable help
: helpitem array
384 ; mutable docinfo
: (int * string) list
385 ; mutable deadline
: float
386 ; mutable texid
: GlTex.texture_id
option
388 ; mutable prevzoom
: float
389 ; mutable progress
: float
392 { pat
: string circbuf
393 ; pag
: string circbuf
394 ; nav
: anchor circbuf
415 ; presentation
= false
420 ; proportional
= true
421 ; trimmargins
= false
422 ; trimfuzz
= (0,0,0,0)
423 ; memlimit
= 32 lsl 20
428 ; bgcolor
= (0.5, 0.5, 0.5)
430 ; scrollbarinpm
= true
433 ; mustoresize
= 128 lsl 20
438 | Plinux
| Pfreebsd
| Pdragonflybsd
| Popenbsd
| Psun
-> "xdg-open \"%s\""
439 | Posx
-> "open \"%s\""
440 | Pwindows
| Pcygwin
| Pmingw
-> "start %s"
445 ; redirectstderr
= false
452 let conf = { defconf with angle
= defconf.angle
};;
455 { mutable fontsize
: int
456 ; mutable wwidth
: float
457 ; mutable maxrows
: int
469 fstate.fontsize
<- n
;
470 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
471 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
475 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
476 let len = String.length s
in
477 if colonpos >= 0 && colonpos + 3 < len
479 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
482 try String.rindex_from s
colonpos ' '
486 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
489 | "http" | "ftp" | "mailto" ->
491 try String.index_from s
colonpos ' '
492 with Not_found
-> len
494 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
504 then (try Sys.getenv
"COMSPEC" with Not_found
-> "cmd"), "/c"
508 let args = [|shell; farg
; s
|] in
509 ignore
(Unix.create_process
shell args Unix.stdin
Unix.stdout
Unix.stderr
)
513 if String.length
conf.urilauncher
= 0
514 then print_endline uri
516 let url = geturl uri
in
517 if String.length
url = 0
518 then print_endline uri
520 let re = Str.regexp
"%s" in
521 let command = Str.global_replace
re url conf.urilauncher
in
525 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
531 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
532 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
536 let strings = version () :: "" :: Help.keys
in
539 let url = geturl s
in
540 if String.length
url > 0
541 then (s
, 0, Action
(fun u
-> gotouri url; u
))
542 else (s
, 0, Noaction
)
552 ; stderr
= Unix.stderr
553 ; errmsgs
= Buffer.create
0
560 ; anchor
= emptyanchor
563 ; tilelru
= Queue.create
()
564 ; pagemap
= Hashtbl.create
10
565 ; tilemap
= Hashtbl.create
10
582 { nav
= cbnew 10 (0, 0.0)
604 Printf.kprintf prerr_endline fmt
606 Printf.kprintf ignore fmt
609 let redirectstderr () =
610 if conf.redirectstderr
612 let rfd, wfd
= Unix.pipe
() in
613 state.stderr
<- Unix.dup
Unix.stderr
;
614 state.errfd
<- Some
rfd;
615 Unix.dup2 wfd
Unix.stderr
;
617 state.newerrmsgs
<- false;
618 begin match state.errfd
with
621 Unix.dup2
state.stderr
Unix.stderr
;
625 prerr_string
(Buffer.contents
state.errmsgs
);
627 Buffer.clear
state.errmsgs
;
633 let postRedisplay who
=
635 then prerr_endline
("redisplay for " ^ who
);
636 Glut.postRedisplay ();
641 let b = Buffer.create
(String.length s
+ 1) in
642 Buffer.add_string
b s
;
647 let colorspace_of_string s
=
648 match String.lowercase s
with
652 | _
-> failwith
"invalid colorspace"
655 let int_of_colorspace = function
661 let colorspace_of_int = function
665 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
668 let colorspace_to_string = function
674 let intentry_with_suffix text key
=
675 let c = Char.unsafe_chr key
in
676 match Char.lowercase
c with
678 let text = addchar text c in
682 let text = addchar text c in
686 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
690 let columns_to_string (n
, a
, b) =
692 then Printf.sprintf
"%d" n
693 else Printf.sprintf
"%d,%d,%d" n a
b;
696 let columns_of_string s
=
698 (int_of_string s
, 0, 0)
700 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
704 let len = String.length s
in
706 let b = Buffer.create
n in
707 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
708 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
709 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
710 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
711 Buffer.add_string
b s
;
712 let s'
= Buffer.contents
b in
713 let n'
= Unix.write fd
s'
0 n in
714 if n'
!= n then failwith
"write failed";
719 let n = Unix.read fd
s 0 4 in
720 if n != 4 then failwith
"incomplete read(len)";
722 lor (Char.code
s.[0] lsl 24)
723 lor (Char.code
s.[1] lsl 16)
724 lor (Char.code
s.[2] lsl 8)
725 lor (Char.code
s.[3] lsl 0)
727 let s = String.create
len in
733 then failwith
"EWOULDBLOCK encountered 10 times"
737 with Unix.Unix_error
(Unix.EWOULDBLOCK
, _
, _
) ->
738 let _, _, _ = Unix.select
[fd
] [] [] 0.01 in
744 if n != len then failwith
"incomplete read(data)";
749 let b = Buffer.create
10 in
750 Buffer.add_string
b s;
751 let rec combine = function
754 Buffer.add_char
b ' '
;
757 | `
b b -> if b then "1" else "0"
759 | `i i
-> string_of_int i
760 | `f f
-> string_of_float f
761 | `I f
-> string_of_int
(truncate f
)
763 Buffer.add_string
b s;
770 let cmd = Buffer.contents
(makecmd s l
) in
771 writecmd state.csock
cmd;
777 let d = conf.winh
- h
in
784 let rec f pn ph pi fh l
=
786 | (n, _, h
, _) :: rest
->
787 let ips = calcips h
in
792 if isbirdseye state.mode
&& pn
= 0
797 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
802 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
806 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
809 let fh = f 0 0 0 0 state.pdims
in
814 match conf.columns
with
815 | None
-> calcheight ()
817 if Array.length
b > 0
819 let (_, _, y
, (_, _, h
, _)) = b.(Array.length
b - 1) in
824 let getpageyh pageno
=
825 let rec f pn ph pi y l
=
827 | (n, _, h
, _) :: rest
->
828 let ips = calcips h
in
831 let h = if n = pageno
then h else ph
in
832 if conf.presentation
&& n = pageno
834 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
836 y
+ (pageno
- pn
) * (ph
+ pi
), h
838 let y = y + (if conf.presentation
then pi
else 0) in
839 let y = y + (n - pn
) * (ph
+ pi
) in
843 y + (pageno
- pn
) * (ph
+ pi
), ph
845 f 0 0 0 0 state.pdims
848 let getpageyh pageno
=
849 match conf.columns
with
850 | None
-> getpageyh pageno
852 let (_, _, y, (_, _, h, _)) = b.(pageno
) in
856 let getpagedim pageno
=
859 | (n, _, _, _) as pdim
:: rest
->
861 then (if n = pageno
then pdim
else ppdim
)
866 f (-1, -1, -1, -1) state.pdims
869 let getpagey pageno
= fst
(getpageyh pageno
);;
872 let sh = sh - state.hscrollh
in
873 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
874 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
876 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
877 let ips = calcips h in
879 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
883 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
885 prev
, pdims
, pdimno
, 0
887 let dy = dy + yinc in
888 let py = py + yinc in
889 if pageno
= state.pagecount
|| dy >= sh
894 if py + h <= vy - yinc
896 let py = py + h + ips in
897 let dy = max
0 (py - y) in
906 let pagey = vy - py in
907 let pagevh = h - pagey in
908 let pagevh = min
(sh - dy) pagevh in
909 let off = if yinc > 0 then py - vy else 0 in
910 let py = py + h + ips in
913 if state.w
< conf.winw
- state.scrollw
914 then (conf.winw
- state.scrollw
- state.w
) / 2
917 let dispx = xoff + state.x
in
923 let lw = w
- pagex in
924 min
lw (conf.winw
- state.scrollw
)
932 ; pagey = pagey + off
934 ; pagevh = pagevh - off
936 ; pagedispy
= dy + off
939 let accu = e :: accu in
948 if state.invalidated
= 0
966 let layoutN ((columns
, coverA
, coverB
), b) y sh =
967 let sh = sh - state.hscrollh
in
968 let rec fold accu n =
969 if n = Array.length
b
972 let pdimno, dx
, vy, (_, w
, h, xoff) = b.(n) in
975 || n = state.pagecount
- coverB
976 || (n - coverA
) mod columns
= columns
- 1)
982 let pagey = max
0 (y - vy) in
983 let pagedispy = if pagey > 0 then 0 else vy - y in
984 let pagedispx, pagex, pagevw =
986 if n = coverA
- 1 || n = state.pagecount
- coverB
987 then state.x
+ (conf.winw
- state.scrollw
- w
) / 2
988 else dx
+ xoff + state.x
991 then 0, -pdx, w
+ pdx
992 else pdx, 0, min
(conf.winw
- state.scrollw
) w
994 let pagevh = min
(h - pagey) (sh - pagedispy) in
995 if pagedispx < conf.winw
- state.scrollw
&& pagevw > 0 && pagevh > 0
1006 ; pagedispx = pagedispx
1007 ; pagedispy = pagedispy
1018 if state.invalidated
= 0
1019 then List.rev
(fold [] 0)
1024 match conf.columns
with
1025 | None
-> layout1 y sh
1026 | Some
c -> layoutN c y sh
1030 let y = state.y + incr
in
1032 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1036 let getopaque pageno
=
1037 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
1038 with Not_found
-> None
1041 let putopaque pageno opaque
=
1042 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
1046 let tilex = l
.pagex mod conf.tilew
in
1047 let tiley = l
.pagey mod conf.tileh
in
1049 let col = l
.pagex / conf.tilew
in
1050 let row = l
.pagey / conf.tileh
in
1053 let a = l
.pagew
- l
.pagex in
1054 let b = conf.winw
- state.scrollw
in
1056 and vh
= l
.pagevh in
1058 let rec rowloop row y0 dispy
h =
1062 let dh = conf.tileh
- y0
in
1063 let dh = min
h dh in
1064 let rec colloop col x0
dispx w
=
1068 let dw = conf.tilew
- x0
in
1069 let dw = min w
dw in
1071 f col row dispx dispy x0 y0
dw dh;
1072 colloop (col+1) 0 (dispx+dw) (w
-dw)
1075 colloop col tilex l
.pagedispx vw;
1076 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1080 then rowloop row tiley l
.pagedispy vh
;
1083 let gettileopaque l
col row =
1085 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1087 try Some
(Hashtbl.find
state.tilemap
key)
1088 with Not_found
-> None
1091 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1092 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1093 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1096 let drawtiles l color
=
1098 let f col row x
y tilex tiley w
h =
1099 match gettileopaque l
col row with
1100 | Some
(opaque
, _, t
) ->
1101 let params = x
, y, w
, h, tilex, tiley in
1105 GlFunc.blend_func `zero `one_minus_src_color
;
1107 drawtile
params opaque
;
1109 then Gl.disable `blend
;
1112 let s = Printf.sprintf
1116 let w = measurestr
fstate.fontsize
s in
1117 GlMisc.push_attrib
[`current
];
1118 GlDraw.color
(0.0, 0.0, 0.0);
1120 (float (x
-2), float (y-2))
1121 (float (x
+2) +. w, float (y + fstate.fontsize
+ 2));
1122 GlDraw.color
(1.0, 1.0, 1.0);
1123 drawstring fstate.fontsize x
(y + fstate.fontsize
- 1) s;
1124 GlMisc.pop_attrib
();
1129 let lw = conf.winw
- state.scrollw
- x
in
1132 let lh = conf.winh
- y in
1135 Gl.enable `texture_2d
;
1136 begin match state.texid
with
1138 GlTex.bind_texture `texture_2d id
;
1141 and x1
= float (x
+w)
1142 and y1
= float (y+h) in
1144 let tw = float w /. 64.0
1145 and th
= float h /. 64.0 in
1146 let tx0 = float tilex /. 64.0
1147 and ty0
= float tiley /. 64.0 in
1149 and ty1
= ty0
+. th
in
1150 GlDraw.begins `quads
;
1151 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
1152 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
1153 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
1154 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
1157 Gl.disable `texture_2d
;
1159 GlDraw.color
(1.0, 1.0, 1.0);
1162 (float (x
+w), float (y+h));
1164 if w > 128 && h > fstate.fontsize
+ 10
1166 GlDraw.color
(0.0, 0.0, 0.0);
1169 then (col*conf.tilew
, row*conf.tileh
)
1172 drawstring2 fstate.fontsize x
y "Loading %d [%d,%d]" l
.pageno
c r
;
1179 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1181 let tilevisible1 l x
y =
1183 and ax1
= l
.pagex + l
.pagevw
1185 and ay1
= l
.pagey + l
.pagevh in
1189 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1190 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1192 let rx0 = max
ax0 bx0
1193 and ry0
= max ay0 by0
1194 and rx1
= min ax1
bx1
1195 and ry1
= min ay1 by1
in
1197 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1198 nonemptyintersection
1201 let tilevisible layout n x
y =
1202 let rec findpageinlayout = function
1203 | l
:: _ when l
.pageno
= n -> tilevisible1 l x
y
1204 | _ :: rest
-> findpageinlayout rest
1207 findpageinlayout layout
1210 let tileready l x
y =
1211 tilevisible1 l x
y &&
1212 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
1215 let tilepage n p
layout =
1216 let rec loop = function
1220 let f col row _ _ _ _ _ _ =
1221 if state.currently
= Idle
1223 match gettileopaque l
col row with
1226 let x = col*conf.tilew
1227 and y = row*conf.tileh
in
1229 let w = l
.pagew
- x in
1233 let h = l
.pageh
- y in
1245 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1246 conf.tilew
, conf.tileh
1255 if state.invalidated
= 0 then loop layout;
1258 let preloadlayout visiblepages
=
1259 let presentation = conf.presentation in
1260 let interpagespace = conf.interpagespace in
1261 let maxy = state.maxy in
1262 conf.presentation <- false;
1263 conf.interpagespace <- 0;
1264 state.maxy <- calcheight ();
1266 match visiblepages
with
1268 | l
:: _ -> getpagey l
.pageno
+ l
.pagey
1270 let y = if y < conf.winh
then 0 else y - conf.winh
in
1271 let h = state.y - y + conf.winh
*3 in
1272 let pages = layout y h in
1273 conf.presentation <- presentation;
1274 conf.interpagespace <- interpagespace;
1280 let rec loop pages =
1281 if state.currently
!= Idle
1286 begin match getopaque l
.pageno
with
1288 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1289 state.currently
<- Loading
(l
, state.gen
);
1291 tilepage l
.pageno opaque
pages;
1296 if state.invalidated
= 0 then loop pages
1301 if conf.preload && state.currently
= Idle
1302 then load (preloadlayout pages);
1305 let layoutready layout =
1306 let rec fold all ls
=
1307 all
&& match ls
with
1309 let seen = ref false in
1310 let allvisible = ref true in
1311 let foo col row _ _ _ _ _ _ =
1313 allvisible := !allvisible &&
1314 begin match gettileopaque l
col row with
1320 fold (!seen && !allvisible) rest
1323 let alltilesvisible = fold true layout in
1328 let y = bound y 0 state.maxy in
1329 let y, layout, proceed
=
1330 match conf.maxwait
with
1331 | Some time
when state.ghyll
== noghyll ->
1332 begin match state.throttle
with
1334 let layout = layout y conf.winh
in
1335 let ready = layoutready layout in
1339 state.throttle
<- Some
(layout, y, now ());
1341 else G.postRedisplay "gotoy showall (None)";
1343 | Some
(_, _, started
) ->
1344 let dt = now () -. started
in
1347 state.throttle
<- None
;
1348 let layout = layout y conf.winh
in
1350 G.postRedisplay "maxwait";
1357 let layout = layout y conf.winh
in
1358 if true || layoutready layout
1359 then G.postRedisplay "gotoy ready";
1365 state.layout <- layout;
1366 begin match state.mode
with
1367 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1368 if not
(pagevisible layout pageno
)
1370 match state.layout with
1373 state.mode
<- Birdseye
(
1374 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1381 state.ghyll
<- noghyll;
1384 let conttiling pageno opaque
=
1385 tilepage pageno opaque
1386 (if conf.preload then preloadlayout state.layout else state.layout)
1389 let gotoy_and_clear_text y =
1391 if not
conf.verbose
then state.text <- "";
1395 match state.layout with
1397 | l
:: _ -> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1400 let getanchory (n, top
) =
1401 let y, h = getpageyh n in
1402 y + (truncate
(top
*. float h));
1405 let gotoanchor anchor
=
1406 gotoy (getanchory anchor
);
1410 cbput state.hists
.nav
(getanchor ());
1414 let anchor = cbgetc state.hists
.nav dir
in
1419 let rec scroll f n a b =
1420 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1422 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1424 then s (float f /. float a)
1427 then 1.0 -. s ((float (f-b) /. float (n-b)))
1434 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1435 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1437 let ins = float a *. iv1
1438 and outs
= float (n-b) *. iv1 in
1440 ins +. outs
+. float ones
1442 let rec set (_N
, _A
, _B
) y sy
=
1443 let sum = summa
1.0 _N _A _B
in
1444 let dy = float (y - sy
) in
1448 then state.ghyll
<- noghyll
1451 let s = scroll n _N _A _B
in
1452 let y1 = y1 +. ((s *. dy) /. sum) in
1453 gotoy_and_clear_text (truncate
y1);
1454 state.ghyll
<- gf (n+1) y1;
1458 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1460 gf 0 (float state.y)
1463 match conf.ghyllscroll
with
1465 gotoy_and_clear_text y
1467 if state.ghyll
== noghyll
1468 then set nab
y state.y
1469 else state.ghyll
(Some
y)
1472 let gotopage n top
=
1473 let y, h = getpageyh n in
1474 let y = y + (truncate
(top
*. float h)) in
1478 let gotopage1 n top
=
1479 let y = getpagey n in
1489 state.invalidated
<- state.invalidated
+ 1;
1492 let writeopen path password
=
1493 writecmd state.csock
("open " ^ path ^
"\000" ^ password ^
"\000");
1496 let opendoc path password
=
1499 state.password
<- password
;
1500 state.gen
<- state.gen
+ 1;
1501 state.docinfo
<- [];
1503 setaalevel
conf.aalevel
;
1504 writeopen path password
;
1505 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1506 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1510 let c = c *. conf.colorscale
in
1514 let scalecolor2 (r
, g
, b) =
1515 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1519 let docolumns = function
1521 | Some
((columns
, coverA
, coverB
), _) ->
1522 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1523 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1524 if pageno
= state.pagecount
1527 let pdimno, ((_, w, h, xoff) as pdim
), pdims
=
1529 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno
->
1530 pdimno+1, pdim
, rest
1535 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1537 (conf.winw
- state.scrollw
- w) / 2,
1538 y + rowh
+ conf.interpagespace, h
1541 if (pageno
- coverA
) mod columns
= 0
1542 then 0, y + rowh
+ conf.interpagespace, h
1543 else x, y, max rowh
h
1546 let rec fixrow m
= if m
= pageno
then () else
1547 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1550 let y = y + (rowh
- h) / 2 in
1551 a.(m
) <- (pdimno, x, y, pdim
);
1555 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1556 then fixrow (pageno
- columns
);
1557 a.(pageno
) <- (pdimno, x, y, pdim
);
1558 let x = x + w + xoff*2 + conf.interpagespace in
1559 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1561 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1562 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1564 docolumns conf.columns
;
1565 state.maxy <- calcheight ();
1567 if state.w <= conf.winw
- state.scrollw
1571 match state.mode
with
1572 | Birdseye
(_, _, pageno
, _, _) ->
1573 let y, h = getpageyh pageno
in
1574 let top = (conf.winh
- h) / 2 in
1575 gotoy (max
0 (y - top))
1576 | _ -> gotoanchor state.anchor
1580 let firsttime = ref true in
1582 GlDraw.viewport
0 0 w h;
1583 if state.invalidated
= 0 && not
!firsttime
1584 then state.anchor <- getanchor ();
1588 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1592 setfontsize fstate.fontsize
;
1593 GlMat.mode `modelview
;
1594 GlMat.load_identity
();
1596 GlMat.mode `projection
;
1597 GlMat.load_identity
();
1598 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1599 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1600 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1603 match conf.columns
with
1605 | Some
((c, _, _), _) -> (w - (c-1)*conf.interpagespace) / c
1608 wcmd "geometry" [`i
w; `i
h];
1612 let len = String.length
state.text in
1615 match state.mode
with
1616 | View
-> state.hscrollh
1621 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1622 (x+.w, float (conf.winh
- hscrollh))
1625 let w = float (conf.winw
- state.scrollw
- 1) in
1626 if state.progress
>= 0.0 && state.progress
< 1.0
1628 GlDraw.color
(0.3, 0.3, 0.3);
1629 let w1 = w *. state.progress
in
1631 GlDraw.color
(0.0, 0.0, 0.0);
1635 GlDraw.color
(0.0, 0.0, 0.0);
1639 GlDraw.color
(1.0, 1.0, 1.0);
1640 drawstring fstate.fontsize
1641 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1644 match state.mode
with
1645 | Textentry
((prefix
, text, _, _, _), _) ->
1649 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1651 Printf.sprintf
"%s%s_" prefix
text
1660 if not
(istextentry state.mode
)
1662 let s1 = "(press 'e' to review error messasges)" in
1663 if String.length
s > 0 then s ^
" " ^
s1 else s1
1668 if String.length
s > 0
1673 state.text <- Printf.sprintf
"%c%s" c s;
1674 G.postRedisplay "showtext";
1678 let len = Queue.length
state.tilelru
in
1680 if state.memused
<= conf.memlimit
1685 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1686 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1687 let (_, pw
, ph
, _) = getpagedim n in
1690 && colorspace
= conf.colorspace
1691 && angle
= conf.angle
1696 match state.throttle
with
1699 then preloadlayout state.layout
1701 | Some
(layout, _, _) ->
1704 let x = col*conf.tilew
1705 and y = row*conf.tileh
in
1706 tilevisible layout n x y
1708 then Queue.push lruitem
state.tilelru
1710 wcmd "freetile" [`
s p
];
1711 state.memused
<- state.memused
- s;
1712 state.uioh#infochanged Memused
;
1713 Hashtbl.remove
state.tilemap k
;
1722 Queue.iter
(fun (k
, p
, s) ->
1723 wcmd "freetile" [`
s p
];
1724 state.memused
<- state.memused
- s;
1725 state.uioh#infochanged Memused
;
1726 Hashtbl.remove
state.tilemap k
;
1728 Queue.clear
state.tilelru
;
1732 let logcurrently = function
1733 | Idle
-> dolog "Idle"
1734 | Loading
(l
, gen
) ->
1735 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1736 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1738 "Tiling %d[%d,%d] page=%s cs=%s angle"
1739 l
.pageno
col row pageopaque
1740 (colorspace_to_string colorspace
)
1742 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1743 angle gen
conf.angle
state.gen
1745 conf.tilew
conf.tileh
1752 (* dolog "%S" cmds; *)
1755 try String.index cmds ' '
1756 with Not_found
-> -1
1761 let l = String.length cmds
in
1762 let op = String.sub cmds
0 spacepos in
1764 if l - spacepos < 2 then ""
1765 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1770 state.uioh#infochanged Pdim
;
1774 state.rects
<- state.rects1
;
1775 G.postRedisplay "clearrects";
1779 try Scanf.sscanf
args "%u" (fun n -> n)
1781 dolog "error processing 'continue' %S: %s"
1782 cmds
(Printexc.to_string exn
);
1785 state.pagecount
<- n;
1786 state.invalidated
<- state.invalidated
- 1;
1787 begin match state.currently
with
1789 state.currently
<- Idle
;
1790 state.outlines
<- Array.of_list
(List.rev
l)
1793 if state.invalidated
= 0
1795 if conf.maxwait
= None
1796 then G.postRedisplay "continue";
1799 Glut.setWindowTitle
args
1806 then showtext ' '
args
1809 let progress, text =
1811 Scanf.sscanf
args "%f %n"
1813 f, String.sub
args pos
(String.length
args - pos
))
1815 dolog "error processing 'progress' %S: %s"
1816 cmds
(Printexc.to_string exn
);
1820 state.progress <- progress;
1821 G.postRedisplay "progress"
1824 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1826 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1827 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1828 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1830 dolog "error processing 'firstmatch' %S: %s"
1831 cmds
(Printexc.to_string exn
);
1834 let y = (getpagey pageno) + truncate y0
in
1837 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)]
1840 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1842 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1843 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1844 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1846 dolog "error processing 'match' %S: %s"
1847 cmds
(Printexc.to_string exn
);
1851 (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) :: state.rects1
1856 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
1858 dolog "error processing 'page' %S: %s"
1859 cmds
(Printexc.to_string exn
);
1862 begin match state.currently
with
1863 | Loading
(l, gen
) ->
1864 vlog "page %d took %f sec" l.pageno t
;
1865 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1866 begin match state.throttle
with
1868 let preloadedpages =
1870 then preloadlayout state.layout
1875 Set.Make
(struct type t
= int let compare = (-) end) in
1877 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1878 IntSet.empty
preloadedpages
1881 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1882 if not
(IntSet.mem
pageno set)
1884 wcmd "freepage" [`
s opaque
];
1890 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1893 state.currently
<- Idle
;
1896 tilepage l.pageno pageopaque state.layout;
1898 load preloadedpages;
1899 if pagevisible state.layout l.pageno
1900 && layoutready state.layout
1901 then G.postRedisplay "page";
1904 | Some
(layout, _, _) ->
1905 state.currently
<- Idle
;
1906 tilepage l.pageno pageopaque layout;
1911 dolog "Inconsistent loading state";
1912 logcurrently state.currently
;
1917 let (x, y, opaque
, size
, t
) =
1919 Scanf.sscanf
args "%u %u %s %u %f"
1920 (fun x y p size t
-> (x, y, p
, size
, t
))
1922 dolog "error processing 'tile' %S: %s"
1923 cmds
(Printexc.to_string exn
);
1926 begin match state.currently
with
1927 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1928 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1930 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1932 wcmd "freetile" [`
s opaque
];
1933 state.currently
<- Idle
;
1937 puttileopaque l col row gen cs angle opaque size t
;
1938 state.memused
<- state.memused
+ size
;
1939 state.uioh#infochanged Memused
;
1941 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1942 opaque
, size
) state.tilelru
;
1945 match state.throttle
with
1946 | None
-> state.layout
1947 | Some
(layout, _, _) -> layout
1950 state.currently
<- Idle
;
1952 && conf.colorspace
= cs
1953 && conf.angle
= angle
1954 && tilevisible layout l.pageno x y
1955 then conttiling l.pageno pageopaque;
1957 begin match state.throttle
with
1959 preload state.layout;
1961 && conf.colorspace
= cs
1962 && conf.angle
= angle
1963 && tilevisible state.layout l.pageno x y
1964 then G.postRedisplay "tile nothrottle";
1966 | Some
(layout, y, _) ->
1967 let ready = layoutready layout in
1971 state.layout <- layout;
1972 state.throttle
<- None
;
1973 G.postRedisplay "throttle";
1980 dolog "Inconsistent tiling state";
1981 logcurrently state.currently
;
1988 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
1990 dolog "error processing 'pdim' %S: %s"
1991 cmds
(Printexc.to_string exn
);
1994 state.uioh#infochanged Pdim
;
1995 state.pdims
<- pdim :: state.pdims
1998 let (l, n, t
, h, pos
) =
2000 Scanf.sscanf
args "%u %u %d %u %n"
2001 (fun l n t
h pos
-> l, n, t
, h, pos
)
2003 dolog "error processing 'o' %S: %s"
2004 cmds
(Printexc.to_string exn
);
2007 let s = String.sub
args pos
(String.length
args - pos
) in
2008 let outline = (s, l, (n, float t
/. float h)) in
2009 begin match state.currently
with
2010 | Outlining outlines
->
2011 state.currently
<- Outlining
(outline :: outlines
)
2013 state.currently
<- Outlining
[outline]
2015 dolog "invalid outlining state";
2016 logcurrently currently
2020 state.docinfo
<- (1, args) :: state.docinfo
2023 state.uioh#infochanged Docinfo
;
2024 state.docinfo
<- List.rev
state.docinfo
2027 dolog "unknown cmd `%S'" cmds
2031 if state.deadline
== nan
then state.deadline
<- now ();
2033 match state.errfd
with
2034 | None
-> [state.csock
]
2035 | Some fd
-> [state.csock
; fd
]
2037 let rec loop delay
=
2039 if state.ghyll
== noghyll
2045 then max
0.0 (deadline -. now ())
2049 try Unix.select
r [] [] timeout
2050 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [] ,[]
2055 begin match state.autoscroll
with
2056 | Some step
when step
!= 0 ->
2057 let y = state.y + step
in
2061 else if y >= state.maxy then 0 else y
2064 if state.mode
= View
2065 then state.text <- "";
2066 state.deadline <- state.deadline +. 0.005;
2069 state.deadline <- state.deadline +. delay
;
2073 let rec checkfds c = function
2075 | fd
:: rest
when fd
= state.csock
->
2076 let cmd = readcmd state.csock
in
2080 let s = String.create
80 in
2081 let n = Unix.read fd
s 0 80 in
2082 if conf.redirectstderr
2084 Buffer.add_substring
state.errmsgs
s 0 n;
2085 state.newerrmsgs
<- true;
2086 Glut.postRedisplay ();
2089 prerr_string
(String.sub
s 0 n);
2102 let action = function
2103 | HCprev
-> cbget cb ~
-1
2104 | HCnext
-> cbget cb
1
2105 | HCfirst
-> cbget cb ~
-(cb
.rc)
2106 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2107 and cancel
() = cb
.rc <- rc
2111 let search pattern forward
=
2112 if String.length pattern
> 0
2115 match state.layout with
2118 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2121 let b = makecmd "search"
2122 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
2124 Buffer.add_char
b '
,'
;
2125 Buffer.add_string
b pattern
;
2126 Buffer.add_char
b '
\000'
;
2129 writecmd state.csock
cmd;
2132 let intentry text key =
2133 let c = Char.unsafe_chr
key in
2136 let text = addchar text c in
2140 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2144 let textentry text key =
2145 let c = Char.unsafe_chr
key in
2147 | _ when key >= 32 && key < 127 ->
2148 let text = addchar text c in
2152 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
2156 let reqlayout angle proportional
=
2157 match state.throttle
with
2159 if state.invalidated
= 0 then state.anchor <- getanchor ();
2160 conf.angle
<- angle
mod 360;
2161 conf.proportional
<- proportional
;
2163 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
2167 let settrim trimmargins trimfuzz
=
2168 if state.invalidated
= 0 then state.anchor <- getanchor ();
2169 conf.trimmargins
<- trimmargins
;
2170 conf.trimfuzz
<- trimfuzz
;
2171 let x0, y0
, x1
, y1 = trimfuzz
in
2174 `
b conf.trimmargins
;
2180 Hashtbl.iter
(fun _ opaque
->
2181 wcmd "freepage" [`
s opaque
];
2183 Hashtbl.clear
state.pagemap
;
2187 match state.throttle
with
2189 let zoom = max
0.01 zoom in
2190 if zoom <> conf.zoom
2192 state.prevzoom
<- conf.zoom;
2195 then (state.x <- 0; 0.0)
2196 else float state.x /. float state.w
2199 reshape conf.winw
conf.winh
;
2202 let x = relx *. float state.w in
2203 state.x <- truncate
x;
2205 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2208 | Some
(layout, y, started
) ->
2210 match conf.maxwait
with
2214 let dt = now () -. started
in
2222 let setcolumns columns coverA coverB
=
2225 conf.columns
<- None
;
2230 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2233 reshape conf.winw
conf.winh
;
2236 let enterbirdseye () =
2237 let zoom = float conf.thumbw
/. float conf.winw
in
2238 let birdseyepageno =
2239 let cy = conf.winh
/ 2 in
2243 let rec fold best
= function
2246 let d = cy - (l.pagedispy + l.pagevh/2)
2247 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2248 if abs
d < abs dbest
2255 state.mode
<- Birdseye
(
2256 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2259 conf.presentation <- false;
2260 conf.interpagespace <- 10;
2261 conf.hlinks
<- false;
2263 state.mstate
<- Mnone
;
2264 conf.maxwait
<- None
;
2266 match conf.beyecolumns
with
2269 Some
((c, 0, 0), [||])
2272 Glut.setCursor
Glut.CURSOR_INHERIT
;
2275 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2280 reshape conf.winw
conf.winh
;
2283 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2285 conf.zoom <- c.zoom;
2286 conf.presentation <- c.presentation;
2287 conf.interpagespace <- c.interpagespace;
2288 conf.maxwait
<- c.maxwait
;
2289 conf.hlinks
<- c.hlinks
;
2290 conf.beyecolumns
<- (
2291 match conf.columns
with
2292 | Some
((c, _, _), _) -> Some
c
2296 match c.columns
with
2297 | Some
(c, _) -> Some
(c, [||])
2303 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2306 reshape conf.winw
conf.winh
;
2307 state.anchor <- if goback
then anchor else (pageno, 0.0);
2310 let togglebirdseye () =
2311 match state.mode
with
2312 | Birdseye vals
-> leavebirdseye vals
true
2313 | View
-> enterbirdseye ()
2317 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2318 let pageno = max
0 (pageno - incr
) in
2319 let rec loop = function
2320 | [] -> gotopage1 pageno 0
2321 | l :: _ when l.pageno = pageno ->
2322 if l.pagedispy >= 0 && l.pagey = 0
2323 then G.postRedisplay "upbirdseye"
2324 else gotopage1 pageno 0
2325 | _ :: rest
-> loop rest
2328 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2331 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2332 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2333 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2334 let rec loop = function
2336 let y, h = getpageyh pageno in
2337 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2339 | l :: _ when l.pageno = pageno ->
2340 if l.pagevh != l.pageh
2341 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2342 else G.postRedisplay "downbirdseye"
2343 | _ :: rest
-> loop rest
2348 let optentry mode
_ key =
2349 let btos b = if b then "on" else "off" in
2350 let c = Char.unsafe_chr
key in
2354 try conf.scrollstep
<- int_of_string
s with exc
->
2355 state.text <- Printf.sprintf
"bad integer `%s': %s"
2356 s (Printexc.to_string exc
)
2358 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2363 conf.autoscrollstep
<- int_of_string
s;
2364 if state.autoscroll
<> None
2365 then state.autoscroll
<- Some
conf.autoscrollstep
2367 state.text <- Printf.sprintf
"bad integer `%s': %s"
2368 s (Printexc.to_string exc
)
2370 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2375 let n, a, b = columns_of_string s in
2378 state.text <- Printf.sprintf
"bad columns `%s': %s"
2379 s (Printexc.to_string exc
)
2381 TEswitch
("columns: ", "", None
, textentry, ondone)
2386 let zoom = float (int_of_string
s) /. 100.0 in
2389 state.text <- Printf.sprintf
"bad integer `%s': %s"
2390 s (Printexc.to_string exc
)
2392 TEswitch
("zoom: ", "", None
, intentry, ondone)
2397 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2399 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2400 begin match mode
with
2402 leavebirdseye beye
false;
2407 state.text <- Printf.sprintf
"bad integer `%s': %s"
2408 s (Printexc.to_string exc
)
2410 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2415 Some
(int_of_string
s)
2417 state.text <- Printf.sprintf
"bad integer `%s': %s"
2418 s (Printexc.to_string exc
);
2421 | Some angle
-> reqlayout angle
conf.proportional
2424 TEswitch
("rotation: ", "", None
, intentry, ondone)
2427 conf.icase
<- not
conf.icase
;
2428 TEdone
("case insensitive search " ^
(btos conf.icase
))
2431 conf.preload <- not
conf.preload;
2433 TEdone
("preload " ^
(btos conf.preload))
2436 conf.verbose
<- not
conf.verbose
;
2437 TEdone
("verbose " ^
(btos conf.verbose
))
2440 conf.debug
<- not
conf.debug
;
2441 TEdone
("debug " ^
(btos conf.debug
))
2444 conf.maxhfit
<- not
conf.maxhfit
;
2446 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2447 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2450 conf.crophack
<- not
conf.crophack
;
2451 TEdone
("crophack " ^
btos conf.crophack
)
2455 match conf.maxwait
with
2457 conf.maxwait
<- Some infinity
;
2458 "always wait for page to complete"
2460 conf.maxwait
<- None
;
2461 "show placeholder if page is not ready"
2466 conf.underinfo
<- not
conf.underinfo
;
2467 TEdone
("underinfo " ^
btos conf.underinfo
)
2470 conf.savebmarks
<- not
conf.savebmarks
;
2471 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2477 match state.layout with
2482 conf.interpagespace <- int_of_string
s;
2483 state.maxy <- calcheight ();
2484 let y = getpagey pageno in
2487 state.text <- Printf.sprintf
"bad integer `%s': %s"
2488 s (Printexc.to_string exc
)
2490 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2493 reqlayout conf.angle
(not
conf.proportional
);
2494 TEdone
("proportional display " ^
btos conf.proportional
)
2497 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2498 TEdone
("trim margins " ^
btos conf.trimmargins
)
2501 conf.invert
<- not
conf.invert
;
2502 TEdone
("invert colors " ^
btos conf.invert
)
2505 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2509 class type lvsource
= object
2510 method getitemcount
: int
2511 method getitem
: int -> (string * int)
2512 method hasaction
: int -> bool
2521 method getactive
: int
2522 method getfirst
: int
2523 method getqsearch
: string
2524 method setqsearch
: string -> unit
2528 class virtual lvsourcebase
= object
2529 val mutable m_active
= 0
2530 val mutable m_first
= 0
2531 val mutable m_qsearch
= ""
2532 val mutable m_pan
= 0
2533 method getactive
= m_active
2534 method getfirst
= m_first
2535 method getqsearch
= m_qsearch
2536 method getpan
= m_pan
2537 method setqsearch
s = m_qsearch
<- s
2540 let textentryspecial key = function
2541 | ((c, _, (Some
(action, _) as onhist), onkey
, ondone), mode
) ->
2544 | Glut.KEY_UP
-> action HCprev
2545 | Glut.KEY_DOWN
-> action HCnext
2546 | Glut.KEY_HOME
-> action HCfirst
2547 | Glut.KEY_END
-> action HClast
2550 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2551 G.postRedisplay "special textentry";
2555 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2557 state.mode
<- Textentry
(te
, onleave
);
2560 G.postRedisplay "textentrykeyboard enttext";
2562 match Char.unsafe_chr
key with
2563 | '
\008'
-> (* backspace *)
2564 let len = String.length
text in
2568 G.postRedisplay "textentrykeyboard after cancel";
2571 let s = String.sub
text 0 (len - 1) in
2572 enttext (c, s, opthist
, onkey
, ondone)
2578 G.postRedisplay "textentrykeyboard after confirm"
2580 | '
\007'
(* ctrl-g *)
2581 | '
\027'
-> (* escape *)
2582 if String.length
text = 0
2584 begin match opthist
with
2586 | Some
(_, onhistcancel
) -> onhistcancel
()
2590 G.postRedisplay "textentrykeyboard after cancel2"
2593 enttext (c, "", opthist
, onkey
, ondone)
2596 | '
\127'
-> () (* delete *)
2599 begin match onkey
text key with
2603 G.postRedisplay "textentrykeyboard after confirm2";
2606 enttext (c, text, opthist
, onkey
, ondone);
2610 G.postRedisplay "textentrykeyboard after cancel3"
2613 state.mode
<- Textentry
(te
, onleave
);
2614 G.postRedisplay "textentrykeyboard switch";
2618 let firstof first active
=
2619 if first
> active
|| abs
(first
- active
) > fstate.maxrows
- 1
2620 then max
0 (active
- (fstate.maxrows
/2))
2624 let calcfirst first active
=
2627 let rows = active
- first
in
2628 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2632 let scrollph y maxy =
2633 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2634 let sh = float conf.winh
/. sh in
2635 let sh = max
sh (float conf.scrollh
) in
2640 else float y /. float maxy
2642 let position = (float conf.winh
-. sh) *. percent in
2645 if position +. sh > float conf.winh
2646 then float conf.winh
-. sh
2652 let coe s = (s :> uioh
);;
2654 class listview ~
(source
:lvsource
) ~trusted
=
2656 val m_pan
= source#getpan
2657 val m_first
= source#getfirst
2658 val m_active
= source#getactive
2659 val m_qsearch
= source#getqsearch
2660 val m_prev_uioh
= state.uioh
2662 method private elemunder
y =
2663 let n = y / (fstate.fontsize
+1) in
2664 if m_first
+ n < source#getitemcount
2666 if source#hasaction
(m_first
+ n)
2667 then Some
(m_first
+ n)
2674 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2675 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2676 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2677 GlDraw.color
(1., 1., 1.);
2678 Gl.enable `texture_2d
;
2679 let fs = fstate.fontsize
in
2681 let ww = fstate.wwidth
in
2682 let tabw = 30.0*.ww in
2683 let itemcount = source#getitemcount
in
2685 if (row - m_first
) * nfs > conf.winh
2688 if row >= 0 && row < itemcount
2690 let (s, level
) = source#getitem
row in
2691 let y = (row - m_first
) * nfs in
2692 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2695 Gl.disable `texture_2d
;
2696 GlDraw.polygon_mode `both `line
;
2697 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2698 GlDraw.rect (1., float (y + 1))
2699 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2700 GlDraw.polygon_mode `both `fill
;
2701 GlDraw.color
(1., 1., 1.);
2702 Gl.enable `texture_2d
;
2705 let drawtabularstring s =
2706 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2709 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2712 let len = String.length
s - tabpos - 1 in
2713 let s1 = String.sub
s 0 tabpos
2714 and s2
= String.sub
s (tabpos + 1) len in
2715 let nx = drawstr x s1 in
2717 let x = x +. (max
tabw sw) in
2724 let _ = drawtabularstring s in
2731 Gl.disable `texture_2d
;
2733 method updownlevel incr
=
2734 let len = source#getitemcount
in
2736 if m_active
>= 0 && m_active
< len
2737 then snd
(source#getitem m_active
)
2741 if i
= len then i
-1 else if i
= -1 then 0 else
2742 let _, l = source#getitem i
in
2743 if l != curlevel then i
else flow (i
+incr
)
2745 let active = flow m_active
in
2746 let first = calcfirst m_first
active in
2747 G.postRedisplay "special outline updownlevel";
2748 {< m_active
= active; m_first
= first >}
2750 method private key1
key =
2751 let set active first qsearch
=
2752 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2754 let search active pattern incr
=
2757 if n >= 0 && n < source#getitemcount
2759 let s, _ = source#getitem
n in
2761 (try ignore
(Str.search_forward
re s 0); true
2762 with Not_found
-> false)
2764 else loop (n + incr
)
2771 let re = Str.regexp_case_fold pattern
in
2778 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2779 let incr = if key = 18 then -1 else 1 in
2781 match search (m_active
+ incr) m_qsearch
incr with
2783 state.text <- m_qsearch ^
" [not found]";
2786 state.text <- m_qsearch
;
2787 active, firstof m_first
active
2789 G.postRedisplay "listview ctrl-r/s";
2790 set active first m_qsearch
;
2792 | 8 -> (* backspace *)
2793 let len = String.length m_qsearch
in
2800 G.postRedisplay "listview empty qsearch";
2801 set m_active m_first
"";
2804 let qsearch = String.sub m_qsearch
0 (len - 1) in
2806 match search m_active
qsearch ~
-1 with
2808 state.text <- qsearch ^
" [not found]";
2811 state.text <- qsearch;
2812 active, firstof m_first
active
2814 G.postRedisplay "listview backspace qsearch";
2815 set active first qsearch
2818 | _ when key >= 32 && key < 127 ->
2819 let pattern = addchar m_qsearch
(Char.chr
key) in
2821 match search m_active
pattern 1 with
2823 state.text <- pattern ^
" [not found]";
2826 state.text <- pattern;
2827 active, firstof m_first
active
2829 G.postRedisplay "listview qsearch add";
2830 set active first pattern;
2832 | 27 -> (* escape *)
2834 if String.length m_qsearch
= 0
2836 G.postRedisplay "list view escape";
2839 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2841 | None
-> m_prev_uioh
2846 G.postRedisplay "list view kill qsearch";
2847 source#setqsearch
"";
2848 coe {< m_qsearch
= "" >}
2853 let self = {< m_qsearch
= "" >} in
2854 source#setqsearch
"";
2856 G.postRedisplay "listview enter";
2857 if m_active
>= 0 && m_active
< source#getitemcount
2859 source#exit
(coe self) false m_active m_first m_pan
"";
2862 source#exit
(coe self) true m_active m_first m_pan
"";
2865 begin match opt with
2866 | None
-> m_prev_uioh
2870 | 127 -> (* delete *)
2873 | _ -> dolog "unknown key %d" key; coe self
2875 method private special1
key =
2876 let itemcount = source#getitemcount
in
2877 let find start
incr =
2879 if i
= -1 || i
= itemcount
2882 if source#hasaction i
2884 else find (i
+ incr)
2889 let set active first =
2890 let first = bound first 0 (itemcount - fstate.maxrows
) in
2892 coe {< m_active
= active; m_first
= first >}
2895 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2897 let incr1 = if incr > 0 then 1 else -1 in
2898 if isvisible m_first m_active
2901 let next = m_active
+ incr in
2903 if next < 0 || next >= itemcount
2905 else find next incr1
2907 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2913 let first = m_first
+ incr in
2914 let first = bound first 0 (itemcount - 1) in
2916 let next = m_active
+ incr in
2917 let next = bound next 0 (itemcount - 1) in
2920 let active = if next = -1 then m_active
else next in
2923 let first = min
next m_first
in
2925 if abs
(next - first) > fstate.maxrows
2931 let first = m_first
+ incr in
2932 let first = bound first 0 (itemcount - 1) in
2934 let next = m_active
+ incr in
2935 let next = bound next 0 (itemcount - 1) in
2936 let next = find next incr1 in
2938 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2940 let active = if m_active
= -1 then next else m_active
in
2945 if isvisible first active
2951 G.postRedisplay "listview navigate";
2954 begin match key with
2955 | Glut.KEY_UP
-> navigate ~
-1
2956 | Glut.KEY_DOWN
-> navigate 1
2957 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2958 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2962 G.postRedisplay "listview right";
2963 coe {< m_pan
= m_pan
- 1 >}
2967 G.postRedisplay "listview left";
2968 coe {< m_pan
= m_pan
+ 1 >}
2971 let active = find 0 1 in
2972 G.postRedisplay "listview home";
2976 let first = max
0 (itemcount - fstate.maxrows
) in
2977 let active = find (itemcount - 1) ~
-1 in
2978 G.postRedisplay "listview end";
2985 match state.mode
with
2986 | Textentry te
-> textentrykeyboard key te
; coe self
2987 | _ -> self#key1
key
2989 method special
key =
2990 match state.mode
with
2991 | Textentry te
-> textentryspecial key te
; coe self
2992 | _ -> self#special1
key
2994 method button button bstate
x y =
2997 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollbw
->
2998 G.postRedisplay "listview scroll";
2999 if bstate
= Glut.DOWN
3001 let _, position, sh = self#
scrollph in
3002 if y > truncate
position && y < truncate
(position +. sh)
3004 state.mstate
<- Mscrolly
;
3008 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3009 let first = truncate
(s *. float source#getitemcount
) in
3010 let first = min source#getitemcount
first in
3011 Some
(coe {< m_first
= first; m_active
= first >})
3013 state.mstate
<- Mnone
;
3016 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
3017 begin match self#elemunder
y with
3019 G.postRedisplay "listview click";
3021 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3025 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
3026 let len = source#getitemcount
in
3028 if n = 4 && m_first
+ fstate.maxrows
>= len
3032 let first = m_first
+ (if n == 3 then -1 else 1) in
3033 bound first 0 (len - 1)
3035 G.postRedisplay "listview wheel";
3036 Some
(coe {< m_first
= first >})
3041 | None
-> m_prev_uioh
3045 match state.mstate
with
3047 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3048 let first = truncate
(s *. float source#getitemcount
) in
3049 let first = min source#getitemcount
first in
3050 G.postRedisplay "listview motion";
3051 coe {< m_first
= first; m_active
= first >}
3054 method pmotion
x y =
3055 if x < conf.winw
- conf.scrollbw
3058 match self#elemunder
y with
3059 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
3060 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
3064 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3069 Glut.setCursor
Glut.CURSOR_INHERIT
;
3073 method infochanged
_ = ()
3075 method scrollpw
= (0, 0.0, 0.0)
3077 let nfs = fstate.fontsize
+ 1 in
3078 let y = m_first
* nfs in
3079 let itemcount = source#getitemcount
in
3080 let maxi = max
0 (itemcount - fstate.maxrows
) in
3081 let maxy = maxi * nfs in
3082 let p, h = scrollph y maxy in
3086 class outlinelistview ~source
=
3088 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
3092 | 14 -> (* ctrl-n *)
3093 source#narrow m_qsearch
;
3094 G.postRedisplay "outline ctrl-n";
3095 coe {< m_first
= 0; m_active
= 0 >}
3097 | 21 -> (* ctrl-u *)
3099 G.postRedisplay "outline ctrl-u";
3101 coe {< m_first
= 0; m_active
= 0 >}
3103 | 12 -> (* ctrl-l *)
3104 let first = m_active
- (fstate.maxrows
/ 2) in
3105 G.postRedisplay "outline ctrl-l";
3106 coe {< m_first
= first >}
3108 | 127 -> (* delete *)
3109 source#remove m_active
;
3110 G.postRedisplay "outline delete";
3111 let active = max
0 (m_active
-1) in
3112 coe {< m_first
= firstof m_first
active;
3113 m_active
= active >}
3115 | key -> super#
key key
3117 method special
key =
3118 let calcfirst first active =
3121 let rows = active - first in
3122 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3126 let active = m_active
+ incr in
3127 let active = bound active 0 (source#getitemcount
- 1) in
3128 let first = calcfirst m_first
active in
3129 G.postRedisplay "special outline navigate";
3130 coe {< m_active
= active; m_first
= first >}
3133 | Glut.KEY_UP
-> navigate ~
-1
3134 | Glut.KEY_DOWN
-> navigate 1
3135 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
3136 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
3140 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
3142 G.postRedisplay "special outline right";
3143 {< m_pan
= m_pan
+ 1 >}
3145 else self#updownlevel
1
3151 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
3153 G.postRedisplay "special outline left";
3154 {< m_pan
= m_pan
- 1 >}
3156 else self#updownlevel ~
-1
3161 G.postRedisplay "special outline home";
3162 coe {< m_first
= 0; m_active
= 0 >}
3165 let active = source#getitemcount
- 1 in
3166 let first = max
0 (active - fstate.maxrows
) in
3167 G.postRedisplay "special outline end";
3168 coe {< m_active
= active; m_first
= first >}
3170 | _ -> super#special
key
3173 let outlinesource usebookmarks
=
3176 inherit lvsourcebase
3177 val mutable m_items
= empty
3178 val mutable m_orig_items
= empty
3179 val mutable m_prev_items
= empty
3180 val mutable m_narrow_pattern
= ""
3181 val mutable m_hadremovals
= false
3183 method getitemcount
=
3184 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3187 if n == Array.length m_items
&& m_hadremovals
3189 ("[Confirm removal]", 0)
3191 let s, n, _ = m_items
.(n) in
3194 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3195 ignore
(uioh
, first, qsearch);
3196 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3198 if String.length m_narrow_pattern
= 0
3204 if not
confrimremoval
3206 let _, _, anchor = m_items
.(active) in
3211 state.bookmarks
<- Array.to_list m_items
;
3212 m_orig_items
<- m_items
;
3215 else m_items
<- items;
3219 method hasaction
_ = true
3222 if Array.length m_items
!= Array.length m_orig_items
3223 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3226 method narrow
pattern =
3227 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3231 let rec loop accu n =
3234 m_narrow_pattern
<- pattern;
3235 m_items
<- Array.of_list
accu
3238 let (s, _, _) as o = m_items
.(n) in
3240 if (try ignore
(Str.search_forward
re s 0); true
3241 with Not_found
-> false)
3247 loop [] (Array.length m_items
- 1)
3252 then Array.of_list
state.bookmarks
3255 m_items
<- m_orig_items
3260 if m
>= 0 && m
< Array.length m_items
3262 m_hadremovals
<- true;
3263 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3264 let n = if n >= m
then n+1 else n in
3269 method reset
anchor items =
3270 m_hadremovals
<- false;
3271 if m_orig_items
== empty || m_prev_items
!= items
3273 m_orig_items
<- items;
3274 if String.length m_narrow_pattern
= 0
3275 then m_items
<- items;
3277 m_prev_items
<- items;
3278 let rely = getanchory anchor in
3280 let rec loop n best bestd
=
3281 if n = Array.length m_items
3284 let (_, _, anchor) = m_items
.(n) in
3285 let orely = getanchory anchor in
3286 let d = abs
(orely - rely) in
3289 else loop (n+1) best bestd
3294 m_first
<- firstof m_first
active
3298 let enterselector usebookmarks
=
3299 let source = outlinesource usebookmarks
in
3303 then Array.of_list
state.bookmarks
3306 if Array.length
outlines = 0
3308 showtext ' ' errmsg
;
3311 state.text <- source#greetmsg
;
3312 Glut.setCursor
Glut.CURSOR_INHERIT
;
3313 let anchor = getanchor () in
3314 source#reset
anchor outlines;
3315 state.uioh
<- coe (new outlinelistview ~
source);
3316 G.postRedisplay "enter selector";
3320 let enteroutlinemode =
3321 let f = enterselector false in
3322 fun ()-> f "Document has no outline";
3325 let enterbookmarkmode =
3326 let f = enterselector true in
3327 fun () -> f "Document has no bookmarks (yet)";
3330 let color_of_string s =
3331 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3332 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3336 let color_to_string (r, g
, b) =
3337 let r = truncate
(r *. 256.0)
3338 and g
= truncate
(g
*. 256.0)
3339 and b = truncate
(b *. 256.0) in
3340 Printf.sprintf
"%d/%d/%d" r g
b
3343 let irect_of_string s =
3344 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1
y1 -> (x0,y0
,x1
,y1))
3347 let irect_to_string (x0,y0
,x1
,y1) =
3348 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1
y1
3351 let makecheckers () =
3352 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3354 converted by Issac Trotts. July 25, 2002 *)
3355 let image_height = 64
3356 and image_width
= 64 in
3360 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3362 for i
= 0 to image_width
- 1 do
3363 for j
= 0 to image_height - 1 do
3364 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3365 (if (i
land 8 ) lxor (j
land 8) = 0
3366 then [|255;255;255|] else [|200;200;200|])
3371 let image = make_image () in
3372 let id = GlTex.gen_texture
() in
3373 GlTex.bind_texture `texture_2d
id;
3374 GlPix.store
(`unpack_alignment
1);
3375 GlTex.image2d
image;
3376 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3379 `mag_filter `nearest
;
3380 `min_filter `nearest
];
3384 let setcheckers enabled
=
3385 match state.texid
with
3387 if enabled
then state.texid
<- Some
(makecheckers ())
3392 GlTex.delete_texture texid
;
3393 state.texid
<- None
;
3397 let int_of_string_with_suffix s =
3398 let l = String.length
s in
3402 let suffix = Char.lowercase
s.[l-1] in
3404 | 'k'
-> String.sub
s 0 (l-1), 10
3405 | 'm'
-> String.sub
s 0 (l-1), 20
3406 | 'g'
-> String.sub
s 0 (l-1), 30
3410 let n = int_of_string
s1 in
3411 let m = n lsl shift
in
3413 then raise
(Failure
"value too large")
3417 let string_with_suffix_of_int n =
3425 if n land ((1 lsl 20) - 1) = 0
3428 if n land ((1 lsl 10) - 1) = 0
3435 let h = n mod 1000 in
3438 then string_of_int
h ^
s
3440 let s = Printf.sprintf
"_%03d%s" h s in
3447 let defghyllscroll = (40, 8, 32);;
3448 let ghyllscroll_of_string s =
3449 let (n, a, b) as nab
=
3452 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3454 if n <= a || n <= b || a >= b
3455 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3459 let ghyllscroll_to_string ((n, a, b) as nab
) =
3460 if nab
= defghyllscroll
3462 else Printf.sprintf
"%d,%d,%d" n a b;
3465 let describe_location () =
3467 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3469 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3470 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3474 else (100. *. (float state.y /. float maxy))
3478 Printf.sprintf
"page %d of %d [%.2f%%]"
3479 (fn+1) state.pagecount
percent
3482 "pages %d-%d of %d [%.2f%%]"
3483 (fn+1) (ln
+1) state.pagecount
percent
3487 let btos b = if b then "\xe2\x88\x9a" else "" in
3488 let showextended = ref false in
3489 let leave mode
= function
3490 | Confirm
-> state.mode
<- mode
3491 | Cancel
-> state.mode
<- mode
in
3494 val mutable m_first_time
= true
3495 val mutable m_l
= []
3496 val mutable m_a
= [||]
3497 val mutable m_prev_uioh
= nouioh
3498 val mutable m_prev_mode
= View
3500 inherit lvsourcebase
3502 method reset prev_mode prev_uioh
=
3503 m_a
<- Array.of_list
(List.rev m_l
);
3505 m_prev_mode
<- prev_mode
;
3506 m_prev_uioh
<- prev_uioh
;
3510 if n >= Array.length m_a
3514 | _, _, _, Action
_ -> m_active
<- n
3518 m_first_time
<- false;
3521 method int name get
set =
3523 (name
, `
int get
, 1, Action
(
3526 try set (int_of_string
s)
3528 state.text <- Printf.sprintf
"bad integer `%s': %s"
3529 s (Printexc.to_string exn
)
3532 let te = name ^
": ", "", None
, intentry, ondone in
3533 state.mode
<- Textentry
(te, leave m_prev_mode
);
3537 method int_with_suffix name get
set =
3539 (name
, `intws get
, 1, Action
(
3542 try set (int_of_string_with_suffix s)
3544 state.text <- Printf.sprintf
"bad integer `%s': %s"
3545 s (Printexc.to_string exn
)
3549 name ^
": ", "", None
, intentry_with_suffix, ondone
3551 state.mode
<- Textentry
(te, leave m_prev_mode
);
3555 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3557 (name
, `
bool (btos, get
), offset
, Action
(
3564 method color name get
set =
3566 (name
, `color get
, 1, Action
(
3568 let invalid = (nan
, nan
, nan
) in
3571 try color_of_string s
3573 state.text <- Printf.sprintf
"bad color `%s': %s"
3574 s (Printexc.to_string exn
);
3580 let te = name ^
": ", "", None
, textentry, ondone in
3581 state.text <- color_to_string (get
());
3582 state.mode
<- Textentry
(te, leave m_prev_mode
);
3586 method string name get
set =
3588 (name
, `
string get
, 1, Action
(
3590 let ondone s = set s in
3591 let te = name ^
": ", "", None
, textentry, ondone in
3592 state.mode
<- Textentry
(te, leave m_prev_mode
);
3596 method colorspace name get
set =
3598 (name
, `
string get
, 1, Action
(
3601 let vals = [| "rgb"; "bgr"; "gray" |] in
3603 inherit lvsourcebase
3606 m_active
<- int_of_colorspace conf.colorspace
;
3609 method getitemcount
= Array.length
vals
3610 method getitem
n = (vals.(n), 0)
3611 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3612 ignore
(uioh
, first, pan
, qsearch);
3613 if not cancel
then set active;
3615 method hasaction
_ = true
3619 coe (new listview ~
source ~trusted
:true)
3622 method caption
s offset
=
3623 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3625 method caption2
s f offset
=
3626 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3628 method getitemcount
= Array.length m_a
3631 let tostr = function
3632 | `
int f -> string_of_int
(f ())
3633 | `intws
f -> string_with_suffix_of_int (f ())
3635 | `color
f -> color_to_string (f ())
3636 | `
bool (btos, f) -> btos (f ())
3639 let name, t
, offset
, _ = m_a
.(n) in
3640 ((let s = tostr t
in
3641 if String.length
s > 0
3642 then Printf.sprintf
"%s\t%s" name s
3646 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3650 m_qsearch
<- qsearch;
3652 match m_a
.(active) with
3653 | _, _, _, Action
f -> f uioh
3665 method hasaction
n =
3667 | _, _, _, Action
_ -> true
3671 let rec fillsrc prevmode prevuioh
=
3672 let sep () = src#caption
"" 0 in
3673 let colorp name get
set =
3675 (fun () -> color_to_string (get
()))
3678 let c = color_of_string v in
3681 state.text <- Printf.sprintf
"bad color `%s': %s"
3682 v (Printexc.to_string exn
);
3685 let oldmode = state.mode
in
3686 let birdseye = isbirdseye state.mode
in
3688 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3690 src#
bool "presentation mode"
3691 (fun () -> conf.presentation)
3693 conf.presentation <- v;
3694 state.anchor <- getanchor ();
3697 src#
bool "ignore case in searches"
3698 (fun () -> conf.icase
)
3699 (fun v -> conf.icase
<- v);
3702 (fun () -> conf.preload)
3703 (fun v -> conf.preload <- v);
3705 src#
bool "highlight links"
3706 (fun () -> conf.hlinks
)
3707 (fun v -> conf.hlinks
<- v);
3709 src#
bool "under info"
3710 (fun () -> conf.underinfo
)
3711 (fun v -> conf.underinfo
<- v);
3713 src#
bool "persistent bookmarks"
3714 (fun () -> conf.savebmarks
)
3715 (fun v -> conf.savebmarks
<- v);
3717 src#
bool "proportional display"
3718 (fun () -> conf.proportional
)
3719 (fun v -> reqlayout conf.angle
v);
3721 src#
bool "trim margins"
3722 (fun () -> conf.trimmargins
)
3723 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3725 src#
bool "persistent location"
3726 (fun () -> conf.jumpback
)
3727 (fun v -> conf.jumpback
<- v);
3730 src#
int "inter-page space"
3731 (fun () -> conf.interpagespace)
3733 conf.interpagespace <- n;
3735 match state.layout with
3740 state.maxy <- calcheight ();
3741 let y = getpagey pageno in
3746 (fun () -> conf.pagebias
)
3747 (fun v -> conf.pagebias
<- v);
3749 src#
int "scroll step"
3750 (fun () -> conf.scrollstep
)
3751 (fun n -> conf.scrollstep
<- n);
3753 src#
int "auto scroll step"
3755 match state.autoscroll
with
3757 | _ -> conf.autoscrollstep
)
3759 if state.autoscroll
<> None
3760 then state.autoscroll
<- Some
n;
3761 conf.autoscrollstep
<- n);
3764 (fun () -> truncate
(conf.zoom *. 100.))
3765 (fun v -> setzoom ((float v) /. 100.));
3768 (fun () -> conf.angle
)
3769 (fun v -> reqlayout v conf.proportional
);
3771 src#
int "scroll bar width"
3772 (fun () -> state.scrollw
)
3776 reshape conf.winw
conf.winh
;
3779 src#
int "scroll handle height"
3780 (fun () -> conf.scrollh
)
3781 (fun v -> conf.scrollh
<- v;);
3783 src#
int "thumbnail width"
3784 (fun () -> conf.thumbw
)
3786 conf.thumbw
<- min
4096 v;
3789 leavebirdseye beye
false;
3794 src#
string "columns"
3796 match conf.columns
with
3798 | Some
(multicol
, _) -> columns_to_string multicol
)
3800 let n, a, b = columns_of_string v in
3804 src#caption
"Presentation mode" 0;
3805 src#
bool "scrollbar visible"
3806 (fun () -> conf.scrollbarinpm
)
3808 if v != conf.scrollbarinpm
3810 conf.scrollbarinpm
<- v;
3811 if conf.presentation
3813 state.scrollw
<- if v then conf.scrollbw
else 0;
3814 reshape conf.winw
conf.winh
;
3820 src#caption
"Pixmap cache" 0;
3821 src#int_with_suffix
"size (advisory)"
3822 (fun () -> conf.memlimit
)
3823 (fun v -> conf.memlimit
<- v);
3826 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3827 (string_with_suffix_of_int state.memused
)
3828 (Hashtbl.length
state.tilemap
)) 1;
3831 src#caption
"Layout" 0;
3832 src#caption2
"Dimension"
3834 Printf.sprintf
"%dx%d (virtual %dx%d)"
3840 src#caption2
"Position" (fun () ->
3841 Printf.sprintf
"%dx%d" state.x state.y
3844 src#caption2
"Visible" (fun () -> describe_location ()) 1
3848 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3849 "Save these parameters as global defaults at exit"
3850 (fun () -> conf.bedefault
)
3851 (fun v -> conf.bedefault
<- v)
3855 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3856 src#
bool ~offset
:0 ~
btos "Extended parameters"
3857 (fun () -> !showextended)
3858 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3862 (fun () -> conf.checkers
)
3863 (fun v -> conf.checkers
<- v; setcheckers v);
3865 (fun () -> conf.verbose
)
3866 (fun v -> conf.verbose
<- v);
3867 src#
bool "invert colors"
3868 (fun () -> conf.invert
)
3869 (fun v -> conf.invert
<- v);
3871 (fun () -> conf.maxhfit
)
3872 (fun v -> conf.maxhfit
<- v);
3873 src#
bool "redirect stderr"
3874 (fun () -> conf.redirectstderr)
3875 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3876 src#
string "uri launcher"
3877 (fun () -> conf.urilauncher
)
3878 (fun v -> conf.urilauncher
<- v);
3879 src#
string "tile size"
3880 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3883 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3884 conf.tileh
<- max
64 w;
3885 conf.tilew
<- max
64 h;
3888 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3889 v (Printexc.to_string exn
));
3890 src#
int "texture count"
3891 (fun () -> conf.texcount
)
3894 then conf.texcount
<- v
3895 else showtext '
!'
" Failed to set texture count please retry later"
3897 src#
int "slice height"
3898 (fun () -> conf.sliceheight
)
3900 conf.sliceheight
<- v;
3901 wcmd "sliceh" [`i
conf.sliceheight
];
3903 src#
int "anti-aliasing level"
3904 (fun () -> conf.aalevel
)
3906 conf.aalevel
<- bound v 0 8;
3907 state.anchor <- getanchor ();
3908 opendoc state.path
state.password
;
3910 src#
int "ui font size"
3911 (fun () -> fstate.fontsize
)
3912 (fun v -> setfontsize (bound v 5 100));
3913 colorp "background color"
3914 (fun () -> conf.bgcolor
)
3915 (fun v -> conf.bgcolor
<- v);
3916 src#
bool "crop hack"
3917 (fun () -> conf.crophack
)
3918 (fun v -> conf.crophack
<- v);
3919 src#
string "trim fuzz"
3920 (fun () -> irect_to_string conf.trimfuzz
)
3923 conf.trimfuzz
<- irect_of_string v;
3925 then settrim true conf.trimfuzz
;
3927 state.text <- Printf.sprintf
"bad irect `%s': %s"
3928 v (Printexc.to_string exn
)
3930 src#
string "throttle"
3932 match conf.maxwait
with
3933 | None
-> "show place holder if page is not ready"
3936 then "wait for page to fully render"
3938 "wait " ^ string_of_float
time
3939 ^
" seconds before showing placeholder"
3943 let f = float_of_string
v in
3945 then conf.maxwait
<- None
3946 else conf.maxwait
<- Some
f
3948 state.text <- Printf.sprintf
"bad time `%s': %s"
3949 v (Printexc.to_string exn
)
3951 src#
string "ghyll scroll"
3953 match conf.ghyllscroll
with
3955 | Some nab
-> ghyllscroll_to_string nab
3960 if String.length
v = 0
3962 else Some
(ghyllscroll_of_string v)
3964 conf.ghyllscroll
<- gs
3966 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
3967 v (Printexc.to_string exn
)
3969 src#colorspace
"color space"
3970 (fun () -> colorspace_to_string conf.colorspace
)
3972 conf.colorspace
<- colorspace_of_int v;
3979 src#caption
"Document" 0;
3980 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3981 src#caption2
"Pages"
3982 (fun () -> string_of_int
state.pagecount
) 1;
3983 src#caption2
"Dimensions"
3984 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3988 src#caption
"Trimmed margins" 0;
3989 src#caption2
"Dimensions"
3990 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3993 src#reset prevmode prevuioh
;
3997 let prevmode = state.mode
3998 and prevuioh
= state.uioh in
3999 fillsrc prevmode prevuioh
;
4000 let source = (src :> lvsource
) in
4001 state.uioh <- coe (object (self)
4002 inherit listview ~
source ~trusted
:true as super
4003 val mutable m_prevmemused
= 0
4004 method infochanged
= function
4006 if m_prevmemused
!= state.memused
4008 m_prevmemused
<- state.memused
;
4009 G.postRedisplay "memusedchanged";
4011 | Pdim
-> G.postRedisplay "pdimchanged"
4012 | Docinfo
-> fillsrc prevmode prevuioh
4014 method special
key =
4015 if Glut.getModifiers
() land Glut.active_ctrl
= 0
4018 | Glut.KEY_LEFT
-> coe (self#updownlevel ~
-1)
4019 | Glut.KEY_RIGHT
-> coe (self#updownlevel
1)
4020 | _ -> super#special
key
4021 else super#special
key
4023 G.postRedisplay "info";
4029 inherit lvsourcebase
4030 method getitemcount
= Array.length
state.help
4032 let s, n, _ = state.help
.(n) in
4035 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4039 m_qsearch
<- qsearch;
4040 match state.help
.(active) with
4041 | _, _, Action
f -> Some
(f uioh)
4051 method hasaction
n =
4052 match state.help
.(n) with
4053 | _, _, Action
_ -> true
4060 state.uioh <- coe (new listview ~
source ~trusted
:true);
4061 G.postRedisplay "help";
4066 let re = Str.regexp
"[\r\n]" in
4068 inherit lvsourcebase
4069 val mutable m_items
= [||]
4071 method getitemcount
= 1 + Array.length m_items
4076 else m_items
.(n-1), 0
4078 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4083 then Buffer.clear
state.errmsgs
;
4084 m_qsearch
<- qsearch;
4091 method hasaction
n =
4095 state.newerrmsgs
<- false;
4096 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4097 m_items
<- Array.of_list
l
4105 let source = (msgsource :> lvsource
) in
4106 state.uioh <- coe (object
4107 inherit listview ~
source ~trusted
:false as super
4110 then msgsource#reset
;
4113 G.postRedisplay "msgs";
4116 let quickbookmark ?title
() =
4117 match state.layout with
4123 let sec = Unix.gettimeofday
() in
4124 let tm = Unix.localtime
sec in
4125 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4129 (tm.Unix.tm_year
+ 1900)
4132 | Some
title -> title
4135 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4140 state.fullscreen
<- None
;
4141 Glut.reshapeWindow
w h;
4144 let viewkeyboard key =
4146 let mode = state.mode in
4147 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4150 G.postRedisplay "view:enttext"
4152 let c = Char.chr
key in
4154 | '
\027'
| 'q'
-> (* escape *)
4155 begin match state.mstate
with
4157 state.mstate
<- Mnone
;
4158 Glut.setCursor
Glut.CURSOR_INHERIT
;
4159 G.postRedisplay "kill zoom rect";
4164 | '
\008'
-> (* backspace *)
4165 let y = getnav ~
-1 in
4166 gotoy_and_clear_text y
4174 G.postRedisplay "dehighlight";
4177 let ondone isforw
s =
4178 cbput state.hists
.pat
s;
4179 state.searchpattern
<- s;
4182 let s = String.create
1 in
4184 enttext (s, "", Some
(onhist state.hists
.pat
),
4185 textentry, ondone (c ='
/'
))
4187 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4188 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4189 setzoom (conf.zoom +. incr)
4194 try int_of_string
s with exc
->
4195 state.text <- Printf.sprintf
"bad integer `%s': %s"
4196 s (Printexc.to_string exc
);
4202 state.text <- "page bias is now " ^ string_of_int
n;
4205 enttext ("page bias: ", "", None
, intentry, ondone)
4207 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4208 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4209 setzoom (max
0.01 (conf.zoom -. decr))
4212 let ondone msg
= state.text <- msg
in
4214 "option [acfhilpstvACPRSZTI]: ", "", None
,
4215 optentry state.mode, ondone
4218 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4221 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4222 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4226 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4232 try int_of_string
s with exc
->
4233 state.text <- Printf.sprintf
"bad integer `%s': %s"
4234 s (Printexc.to_string exc
);
4240 cbput state.hists
.pag
(string_of_int
n);
4241 gotopage1 (n + conf.pagebias
- 1) 0;
4244 let pageentry text key =
4245 match Char.unsafe_chr
key with
4246 | 'g'
-> TEdone
text
4247 | _ -> intentry text key
4249 let text = "x" in text.[0] <- c;
4250 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4253 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4254 reshape conf.winw
conf.winh
;
4257 conf.hlinks
<- not
conf.hlinks
;
4258 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4259 G.postRedisplay "toggle highlightlinks";
4262 begin match state.autoscroll
with
4264 conf.autoscrollstep
<- step
;
4265 state.autoscroll
<- None
4267 if conf.autoscrollstep
= 0
4268 then state.autoscroll
<- Some
1
4269 else state.autoscroll
<- Some
conf.autoscrollstep
4273 conf.presentation <- not
conf.presentation;
4274 if conf.presentation
4276 if not
conf.scrollbarinpm
4277 then state.scrollw
<- 0;
4280 state.scrollw
<- conf.scrollbw
;
4282 showtext ' '
("presentation mode " ^
4283 if conf.presentation then "on" else "off");
4284 state.anchor <- getanchor ();
4288 begin match state.fullscreen
with
4290 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4293 state.fullscreen
<- None
;
4298 gotoy_and_clear_text 0
4301 gotopage1 (state.pagecount
- 1) 0
4304 search state.searchpattern
true
4307 search state.searchpattern
false
4310 begin match state.layout with
4313 gotoy_and_clear_text (getpagey l.pageno)
4317 begin match List.rev
state.layout with
4320 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4321 gotoy_and_clear_text (getpagey pageno)
4324 | '
\127'
-> (* del *)
4325 begin match state.layout with
4328 let pageno = max
0 (l.pageno-1) in
4329 gotoy_and_clear_text (getpagey pageno)
4333 showtext ' '
(describe_location ());
4336 begin match state.layout with
4339 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4344 enterbookmarkmode ()
4352 | '
e'
when conf.redirectstderr ->
4357 match state.layout with
4360 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4364 enttext ("bookmark: ", "", None
, textentry, ondone)
4368 showtext ' '
"Quick bookmark added";
4371 begin match state.layout with
4373 let rect = getpdimrect
l.pagedimno
in
4377 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4378 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4380 (truncate
(rect.(1) -. rect.(0)),
4381 truncate
(rect.(3) -. rect.(0)))
4383 let w = truncate
((float w)*.conf.zoom)
4384 and h = truncate
((float h)*.conf.zoom) in
4387 state.anchor <- getanchor ();
4388 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4390 G.postRedisplay "z";
4395 | '
\000'
-> (* ctrl-2 *)
4396 let maxw = getmaxw
() in
4398 then setzoom (maxw /. float conf.winw
)
4401 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
4405 bound (conf.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
4407 G.postRedisplay "brightness";
4410 begin match state.mode with
4411 | Birdseye beye
-> upbirdseye 1 beye
4412 | _ -> gotoy (clamp (-conf.scrollstep
))
4416 begin match state.mode with
4417 | Birdseye beye
-> downbirdseye 1 beye
4418 | _ -> gotoy (clamp conf.scrollstep
)
4422 state.anchor <- getanchor ();
4423 opendoc state.path
state.password
4425 | '
v'
when not
conf.debug
->
4426 List.iter
debugl state.layout;
4428 | '
v'
when conf.debug
->
4431 match getopaque l.pageno with
4434 let x0, y0
, x1
, y1 = pagebbox opaque
in
4435 let a,b = float x0, float y0
in
4436 let c,d = float x1
, float y0
in
4437 let e,f = float x1
, float y1 in
4438 let h,j
= float x0, float y1 in
4439 let rect = (a,b,c,d,e,f,h,j
) in
4441 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4443 G.postRedisplay "v";
4446 vlog "huh? %d %c" key (Char.chr
key);
4449 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
4451 | 27 -> (* escape *)
4452 leavebirdseye beye
true
4454 | 12 -> (* ctrl-l *)
4455 let y, h = getpageyh pageno in
4456 let top = (conf.winh
- h) / 2 in
4457 gotoy (max
0 (y - top))
4460 leavebirdseye beye
false
4466 let keyboard ~
key ~
x ~
y =
4469 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
4470 then wcmd "interrupt" []
4471 else state.uioh <- state.uioh#
key key
4474 let birdseyespecial key ((oconf
, leftx
, _, hooverpageno
, anchor) as beye
) =
4476 match conf.columns
with
4478 | Some
((c, _, _), _) -> c
4481 | Glut.KEY_UP
-> upbirdseye incr beye
4482 | Glut.KEY_DOWN
-> downbirdseye incr beye
4483 | Glut.KEY_LEFT
-> upbirdseye 1 beye
4484 | Glut.KEY_RIGHT
-> downbirdseye 1 beye
4486 | Glut.KEY_PAGE_UP
->
4487 begin match state.layout with
4491 state.mode <- Birdseye
(
4492 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4494 gotopage1 l.pageno 0;
4497 let layout = layout (state.y-conf.winh
) conf.winh
in
4499 | [] -> gotoy (clamp (-conf.winh
))
4501 state.mode <- Birdseye
(
4502 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4504 gotopage1 l.pageno 0
4507 | [] -> gotoy (clamp (-conf.winh
))
4510 | Glut.KEY_PAGE_DOWN
->
4511 begin match List.rev
state.layout with
4513 let layout = layout (state.y + conf.winh
) conf.winh
in
4514 begin match layout with
4516 let incr = l.pageh
- l.pagevh in
4521 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4523 G.postRedisplay "birdseye pagedown";
4525 else gotoy (clamp (incr + conf.interpagespace*2));
4529 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4530 gotopage1 l.pageno 0;
4533 | [] -> gotoy (clamp conf.winh
)
4537 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4541 let pageno = state.pagecount
- 1 in
4542 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4543 if not
(pagevisible state.layout pageno)
4546 match List.rev
state.pdims
with
4548 | (_, _, h, _) :: _ -> h
4550 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4551 else G.postRedisplay "birdseye end";
4555 let setautoscrollspeed step goingdown
=
4556 let incr = max
1 ((abs step
) / 2) in
4557 let incr = if goingdown
then incr else -incr in
4558 let astep = step
+ incr in
4559 state.autoscroll
<- Some
astep;
4562 let special ~
key ~
x ~
y =
4565 state.uioh <- state.uioh#
special key
4570 match state.mode with
4571 | Textentry
_ -> scalecolor 0.4
4572 | View
-> scalecolor 1.0
4573 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4574 if l.pageno = hooverpageno
4577 if l.pageno = pageno
4583 begin match getopaque l.pageno with
4585 if tileready l l.pagex l.pagey
4587 let x = l.pagedispx - l.pagex
4588 and y = l.pagedispy - l.pagey in
4589 postprocess opaque
conf.hlinks
x y;
4595 let scrollindicator () =
4596 let sbw, ph
, sh = state.uioh#
scrollph in
4597 let sbh, pw
, sw = state.uioh#scrollpw
in
4599 GlDraw.color (0.64, 0.64, 0.64);
4601 (float (conf.winw
- sbw), 0.)
4602 (float conf.winw
, float conf.winh
)
4605 (0., float (conf.winh
- sbh))
4606 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4608 GlDraw.color (0.0, 0.0, 0.0);
4611 (float (conf.winw
- sbw), ph
)
4612 (float conf.winw
, ph
+. sh)
4615 (pw
, float (conf.winh
- sbh))
4616 (pw
+. sw, float conf.winh
)
4620 let pagetranslatepoint l x y =
4621 let dy = y - l.pagedispy in
4622 let y = dy + l.pagey in
4623 let dx = x - l.pagedispx in
4624 let x = dx + l.pagex in
4629 match state.mstate
with
4630 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4633 | Msel
((x0, y0
), (x1
, y1)) ->
4634 let rec loop = function
4636 if ((y0
>= l.pagedispy && y0
<= (l.pagedispy + l.pagevh))
4637 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4638 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4639 || ((x1
>= l.pagedispx && x1
<= (l.pagedispx + l.pagevw))))
4641 match getopaque l.pageno with
4643 let dx, dy = pagetranslatepoint l 0 0 in
4648 GlMat.mode `modelview
;
4650 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4651 seltext opaque
(x0, y0
, x1
, y1);
4662 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4663 GlDraw.polygon_mode `both `fill
;
4664 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4666 (fun (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) ->
4668 if l.pageno = pageno
4670 let dx = float (l.pagedispx - l.pagex) in
4671 let dy = float (l.pagedispy - l.pagey) in
4672 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4673 GlDraw.begins `quads
;
4675 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4676 GlDraw.vertex2
(x1
+.dx, y1+.dy);
4677 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4678 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4689 GlClear.color (scalecolor2 conf.bgcolor
);
4690 GlClear.clear
[`
color];
4691 List.iter
drawpage state.layout;
4696 begin match state.mstate
with
4697 | Mzoomrect
((x0, y0
), (x1
, y1)) ->
4699 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4700 GlDraw.polygon_mode `both `fill
;
4701 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4702 GlDraw.rect (float x0, float y0
)
4703 (float x1
, float y1);
4708 Glut.swapBuffers
();
4712 let rec f = function
4714 begin match getopaque l.pageno with
4716 let x0 = l.pagedispx in
4717 let x1 = x0 + l.pagevw in
4718 let y0 = l.pagedispy in
4719 let y1 = y0 + l.pagevh in
4720 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4722 let px, py = pagetranslatepoint l x y in
4723 match whatsunder opaque
px py with
4735 let zoomrect x y x1 y1 =
4738 and y0 = min
y y1 in
4739 gotoy (state.y + y0);
4740 state.anchor <- getanchor ();
4741 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4743 if state.w < conf.winw
- state.scrollw
4744 then (conf.winw
- state.scrollw
- state.w) / 2
4747 state.x <- (state.x + margin) - x0;
4749 Glut.setCursor
Glut.CURSOR_INHERIT
;
4750 state.mstate
<- Mnone
;
4754 let winw = conf.winw - state.scrollw
- 1 in
4755 let s = float x /. float winw in
4756 let destx = truncate
(float (state.w + winw) *. s) in
4757 state.x <- winw - destx;
4758 gotoy_and_clear_text state.y;
4759 state.mstate
<- Mscrollx
;
4763 let s = float y /. float conf.winh
in
4764 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4765 gotoy_and_clear_text desty;
4766 state.mstate
<- Mscrolly
;
4769 let viewmouse button bstate
x y =
4771 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4772 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4774 match state.mstate
with
4775 | Mzoom
(oldn
, i
) ->
4783 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4785 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4787 let zoom = conf.zoom -. incr in
4789 state.mstate
<- Mzoom
(n, 0);
4791 state.mstate
<- Mzoom
(n, i
+1);
4793 else state.mstate
<- Mzoom
(n, 0)
4795 | _ -> state.mstate
<- Mzoom
(n, 0)
4798 match state.autoscroll
with
4799 | Some step
-> setautoscrollspeed step
(n=4)
4803 then -conf.scrollstep
4804 else conf.scrollstep
4806 let incr = incr * 2 in
4807 let y = clamp incr in
4808 gotoy_and_clear_text y
4811 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4812 if bstate
= Glut.DOWN
4814 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4815 state.mstate
<- Mpan
(x, y)
4818 state.mstate
<- Mnone
4820 | Glut.RIGHT_BUTTON
->
4821 if bstate
= Glut.DOWN
4823 Glut.setCursor
Glut.CURSOR_CYCLE
;
4825 state.mstate
<- Mzoomrect
(p, p)
4828 match state.mstate
with
4829 | Mzoomrect
((x0, y0), _) ->
4830 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4831 then zoomrect x0 y0 x y
4833 state.mstate
<- Mnone
;
4834 Glut.setCursor
Glut.CURSOR_INHERIT
;
4835 G.postRedisplay "kill accidental zoom rect";
4838 Glut.setCursor
Glut.CURSOR_INHERIT
;
4839 state.mstate
<- Mnone
4842 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4843 if bstate
= Glut.DOWN
4845 let _, position, sh = state.uioh#
scrollph in
4846 if y > truncate
position && y < truncate
(position +. sh)
4847 then state.mstate
<- Mscrolly
4850 state.mstate
<- Mnone
4852 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4853 if bstate
= Glut.DOWN
4855 let _, position, sw = state.uioh#scrollpw
in
4856 if x > truncate
position && x < truncate
(position +. sw)
4857 then state.mstate
<- Mscrollx
4860 state.mstate
<- Mnone
4862 | Glut.LEFT_BUTTON
->
4863 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4864 begin match dest with
4865 | Ulinkgoto
(pageno, top) ->
4869 gotopage1 pageno top;
4875 | Uremote
_ | Uunexpected
_ | Ulaunch
_ | Unamed
_ -> ()
4877 | Unone
when bstate
= Glut.DOWN
->
4878 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4879 state.mstate
<- Mpan
(x, y);
4881 | Unone
| Utext
_ ->
4882 if bstate
= Glut.DOWN
4884 if conf.angle
mod 360 = 0
4886 state.mstate
<- Msel
((x, y), (x, y));
4887 G.postRedisplay "mouse select";
4891 match state.mstate
with
4894 | Mzoom
_ | Mscrollx
| Mscrolly
->
4895 state.mstate
<- Mnone
4897 | Mzoomrect
((x0, y0), _) ->
4901 Glut.setCursor
Glut.CURSOR_INHERIT
;
4902 state.mstate
<- Mnone
4904 | Msel
((_, y0), (_, y1)) ->
4906 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4907 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh)))
4909 match getopaque l.pageno with
4914 List.iter
f state.layout;
4915 copysel
""; (* ugly *)
4916 Glut.setCursor
Glut.CURSOR_INHERIT
;
4917 state.mstate
<- Mnone
;
4924 let birdseyemouse button bstate
x y
4925 (conf, leftx
, _, hooverpageno
, anchor) =
4927 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4928 let rec loop = function
4931 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4932 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4934 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4939 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4943 let mouse bstate button
x y =
4944 state.uioh <- state.uioh#button button bstate
x y;
4947 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4950 state.uioh <- state.uioh#
motion x y
4954 state.uioh <- state.uioh#
pmotion x y;
4961 begin match state.mode with
4962 | Textentry
textentry -> textentrykeyboard key textentry
4963 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4964 | View
-> viewkeyboard key
4968 method special key =
4969 begin match state.mode with
4970 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4974 birdseyespecial key vals
4976 | View
when key = Glut.KEY_F1
->
4980 begin match state.autoscroll
with
4981 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4982 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4987 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4989 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4991 if Glut.getModifiers
() land Glut.active_shift
!= 0
4992 then (setzoom state.prevzoom
; state.y)
4993 else clamp (-conf.winh
/2)
4994 else clamp (-conf.scrollstep
)
4996 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4998 if Glut.getModifiers
() land Glut.active_shift
!= 0
4999 then (setzoom state.prevzoom
; state.y)
5000 else clamp (conf.winh
/2)
5001 else clamp (conf.scrollstep
)
5002 | Glut.KEY_PAGE_UP
->
5003 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
5005 match state.layout with
5007 | l :: _ -> state.y - l.pagey
5010 | Glut.KEY_PAGE_DOWN
->
5011 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
5013 match List.rev
state.layout with
5015 | l :: _ -> getpagey l.pageno
5023 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
5025 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
5026 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
5027 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
5029 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
5031 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
5032 then (conf.winw / 2)
5035 state.x <- state.x - dx;
5037 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
5039 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
5040 then (conf.winw / 2)
5043 state.x <- state.x + dx;
5048 if abs
(state.y - y) > conf.scrollstep
*2
5050 else gotoy_and_clear_text y
5053 | Textentry
te -> textentryspecial key te
5057 method button button bstate
x y =
5058 begin match state.mode with
5059 | View
-> viewmouse button bstate
x y
5060 | Birdseye beye
-> birdseyemouse button bstate
x y beye
5066 begin match state.mode with
5068 | View
| Birdseye
_ ->
5069 match state.mstate
with
5070 | Mzoom
_ | Mnone
-> ()
5075 state.mstate
<- Mpan
(x, y);
5076 if conf.zoom > 1.0 then state.x <- state.x + dx;
5078 gotoy_and_clear_text y
5081 state.mstate
<- Msel
(a, (x, y));
5082 G.postRedisplay "motion select";
5085 let y = min
conf.winh
(max
0 y) in
5089 let x = min
conf.winw (max
0 x) in
5092 | Mzoomrect
(p0
, _) ->
5093 state.mstate
<- Mzoomrect
(p0
, (x, y));
5094 G.postRedisplay "motion zoomrect";
5098 method pmotion x y =
5099 begin match state.mode with
5100 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5101 let rec loop = function
5103 if hooverpageno
!= -1
5105 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5106 G.postRedisplay "pmotion birdseye no hoover";
5109 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5110 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5112 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5113 G.postRedisplay "pmotion birdseye hoover";
5122 match state.mstate
with
5124 begin match getunder x y with
5125 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
5127 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
5128 Glut.setCursor
Glut.CURSOR_INFO
5129 | Ulinkgoto
(page
, _) ->
5131 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
5132 Glut.setCursor
Glut.CURSOR_INFO
5134 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
5135 Glut.setCursor
Glut.CURSOR_TEXT
5137 if conf.underinfo
then showtext 'u'
("nexpected: " ^
s);
5138 Glut.setCursor
Glut.CURSOR_INHERIT
5140 if conf.underinfo
then showtext '
l'
("launch: " ^
s);
5141 Glut.setCursor
Glut.CURSOR_INHERIT
5143 if conf.underinfo
then showtext '
n'
("named: " ^
s);
5144 Glut.setCursor
Glut.CURSOR_INHERIT
5146 if conf.underinfo
then showtext '
r'
("emote: " ^
s);
5147 Glut.setCursor
Glut.CURSOR_INHERIT
5150 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5155 method infochanged
_ = ()
5158 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5159 let p, h = scrollph state.y maxy in
5163 let winw = conf.winw - state.scrollw
- 1 in
5164 let fwinw = float winw in
5166 let sw = fwinw /. float state.w in
5167 let sw = fwinw *. sw in
5168 max
sw (float conf.scrollh
)
5171 let f = state.w+winw in
5172 let r = float (winw-state.x) /. float f in
5173 let p = fwinw *. r in
5177 if position +. sw > fwinw
5178 then fwinw -. position
5181 state.hscrollh, position, sw
5188 let fontpath = ref "";;
5189 let wmclasshack = ref false;;
5192 let l = String.length
s in
5193 let b = Buffer.create
l in
5201 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
5202 | _ -> Sys.getenv
"HOME"
5205 ("Can not determine home directory location: " ^
5206 Printexc.to_string exn
);
5210 let config_of c attrs
=
5214 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5215 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5216 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5217 | "preload" -> { c with preload = bool_of_string
v }
5218 | "page-bias" -> { c with pagebias
= int_of_string
v }
5219 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5220 | "auto-scroll-step" ->
5221 { c with autoscrollstep
= max
0 (int_of_string
v) }
5222 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5223 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5226 match String.lowercase
v with
5227 | "true" -> Some infinity
5229 | f -> Some
(float_of_string
f)
5231 { c with maxwait
= mw}
5232 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5233 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5234 | "vertical-margin" ->
5235 { c with interpagespace = max
0 (int_of_string
v) }
5237 let zoom = float_of_string
v /. 100. in
5238 let zoom = max
zoom 0.0 in
5239 { c with zoom = zoom }
5240 | "presentation" -> { c with presentation = bool_of_string
v }
5241 | "rotation-angle" -> { c with angle
= int_of_string
v }
5242 | "width" -> { c with winw = max
20 (int_of_string
v) }
5243 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5244 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5245 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5246 | "pixmap-cache-size" ->
5247 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5248 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5249 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5250 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5251 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5252 | "background-color" -> { c with bgcolor
= color_of_string v }
5253 | "scrollbar-in-presentation" ->
5254 { c with scrollbarinpm
= bool_of_string
v }
5255 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5256 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5257 | "mupdf-store-size" ->
5258 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5259 | "checkers" -> { c with checkers
= bool_of_string
v }
5260 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5261 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5262 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5263 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
5264 | "uri-launcher" -> { c with urilauncher
= unent v }
5265 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5266 | "invert-colors" -> { c with invert
= bool_of_string
v }
5267 | "brightness" -> { c with colorscale
= float_of_string
v }
5268 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5270 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5272 let nab = columns_of_string v in
5273 { c with columns
= Some
(nab, [||]) }
5274 | "birds-eye-columns" ->
5275 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5278 prerr_endline
("Error processing attribute (`" ^
5279 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5282 let rec fold c = function
5285 let c = apply c k
v in
5291 let fromstring f pos
n v d =
5294 dolog "Error processing attribute (%S=%S) at %d\n%s"
5295 n v pos
(Printexc.to_string exn
)
5300 let bookmark_of attrs
=
5301 let rec fold title page
rely = function
5302 | ("title", v) :: rest
-> fold v page
rely rest
5303 | ("page", v) :: rest
-> fold title v rely rest
5304 | ("rely", v) :: rest
-> fold title page
v rest
5305 | _ :: rest
-> fold title page
rely rest
5306 | [] -> title, page
, rely
5308 fold "invalid" "0" "0" attrs
5312 let rec fold path page
rely pan
= function
5313 | ("path", v) :: rest
-> fold v page
rely pan rest
5314 | ("page", v) :: rest
-> fold path
v rely pan rest
5315 | ("rely", v) :: rest
-> fold path page
v pan rest
5316 | ("pan", v) :: rest
-> fold path page
rely v rest
5317 | _ :: rest
-> fold path page
rely pan rest
5318 | [] -> path
, page
, rely, pan
5320 fold "" "0" "0" "0" attrs
5323 let setconf dst
src =
5324 dst
.scrollbw
<- src.scrollbw
;
5325 dst
.scrollh
<- src.scrollh
;
5326 dst
.icase
<- src.icase
;
5327 dst
.preload <- src.preload;
5328 dst
.pagebias
<- src.pagebias
;
5329 dst
.verbose
<- src.verbose
;
5330 dst
.scrollstep
<- src.scrollstep
;
5331 dst
.maxhfit
<- src.maxhfit
;
5332 dst
.crophack
<- src.crophack
;
5333 dst
.autoscrollstep
<- src.autoscrollstep
;
5334 dst
.maxwait
<- src.maxwait
;
5335 dst
.hlinks
<- src.hlinks
;
5336 dst
.underinfo
<- src.underinfo
;
5337 dst
.interpagespace <- src.interpagespace;
5338 dst
.zoom <- src.zoom;
5339 dst
.presentation <- src.presentation;
5340 dst
.angle
<- src.angle
;
5341 dst
.winw <- src.winw;
5342 dst
.winh
<- src.winh
;
5343 dst
.savebmarks
<- src.savebmarks
;
5344 dst
.memlimit
<- src.memlimit
;
5345 dst
.proportional
<- src.proportional
;
5346 dst
.texcount
<- src.texcount
;
5347 dst
.sliceheight
<- src.sliceheight
;
5348 dst
.thumbw
<- src.thumbw
;
5349 dst
.jumpback
<- src.jumpback
;
5350 dst
.bgcolor
<- src.bgcolor
;
5351 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5352 dst
.tilew
<- src.tilew
;
5353 dst
.tileh
<- src.tileh
;
5354 dst
.mustoresize
<- src.mustoresize
;
5355 dst
.checkers
<- src.checkers
;
5356 dst
.aalevel
<- src.aalevel
;
5357 dst
.trimmargins
<- src.trimmargins
;
5358 dst
.trimfuzz
<- src.trimfuzz
;
5359 dst
.urilauncher
<- src.urilauncher
;
5360 dst
.colorspace
<- src.colorspace
;
5361 dst
.invert
<- src.invert
;
5362 dst
.colorscale
<- src.colorscale
;
5363 dst
.redirectstderr <- src.redirectstderr;
5364 dst
.ghyllscroll
<- src.ghyllscroll
;
5365 dst
.columns
<- src.columns
;
5366 dst
.beyecolumns
<- src.beyecolumns
;
5370 let h = Hashtbl.create
10 in
5371 let dc = { defconf with angle
= defconf.angle
} in
5372 let rec toplevel v t spos
_ =
5374 | Vdata
| Vcdata
| Vend
-> v
5375 | Vopen
("llppconfig", _, closed
) ->
5378 else { v with f = llppconfig
}
5380 error
"unexpected subelement at top level" s spos
5381 | Vclose
_ -> error
"unexpected close at top level" s spos
5383 and llppconfig
v t spos
_ =
5385 | Vdata
| Vcdata
-> v
5386 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5387 | Vopen
("defaults", attrs
, closed
) ->
5388 let c = config_of dc attrs
in
5392 else { v with f = skip
"defaults" (fun () -> v) }
5394 | Vopen
("ui-font", attrs
, closed
) ->
5395 let rec getsize size
= function
5397 | ("size", v) :: rest
->
5399 fromstring int_of_string spos
"size" v fstate.fontsize
in
5401 | l -> getsize size l
5403 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5406 else { v with f = uifont
(Buffer.create
10) }
5408 | Vopen
("doc", attrs
, closed
) ->
5409 let pathent, spage
, srely
, span
= doc_of attrs
in
5410 let path = unent pathent
5411 and pageno = fromstring int_of_string spos
"page" spage
0
5412 and rely = fromstring float_of_string spos
"rely" srely
0.0
5413 and pan
= fromstring int_of_string spos
"pan" span
0 in
5414 let c = config_of dc attrs
in
5415 let anchor = (pageno, rely) in
5417 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5418 else { v with f = doc
path pan
anchor c [] }
5421 error
"unexpected subelement in llppconfig" s spos
5423 | Vclose
"llppconfig" -> { v with f = toplevel }
5424 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5426 and uifont
b v t spos
epos =
5429 Buffer.add_substring
b s spos
(epos - spos
);
5431 | Vopen
(_, _, _) ->
5432 error
"unexpected subelement in ui-font" s spos
5433 | Vclose
"ui-font" ->
5434 if String.length
!fontpath = 0
5435 then fontpath := Buffer.contents
b;
5436 { v with f = llppconfig
}
5437 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5438 | Vend
-> error
"unexpected end of input in ui-font" s spos
5440 and doc
path pan
anchor c bookmarks
v t spos
_ =
5442 | Vdata
| Vcdata
-> v
5443 | Vend
-> error
"unexpected end of input in doc" s spos
5444 | Vopen
("bookmarks", _, closed
) ->
5447 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5449 | Vopen
(_, _, _) ->
5450 error
"unexpected subelement in doc" s spos
5453 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5454 { v with f = llppconfig
}
5456 | Vclose
_ -> error
"unexpected close in doc" s spos
5458 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5460 | Vdata
| Vcdata
-> v
5461 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5462 | Vopen
("item", attrs
, closed
) ->
5463 let titleent, spage
, srely
= bookmark_of attrs
in
5464 let page = fromstring int_of_string spos
"page" spage
0
5465 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5466 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5468 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5471 { v with f = skip
"item" f }
5474 error
"unexpected subelement in bookmarks" s spos
5476 | Vclose
"bookmarks" ->
5477 { v with f = doc
path pan
anchor c bookmarks }
5479 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5481 and skip tag
f v t spos
_ =
5483 | Vdata
| Vcdata
-> v
5485 error
("unexpected end of input in skipped " ^ tag
) s spos
5486 | Vopen
(tag'
, _, closed
) ->
5490 let f'
() = { v with f = skip tag
f } in
5491 { v with f = skip tag'
f'
}
5495 else error
("unexpected close in skipped " ^ tag
) s spos
5498 parse
{ f = toplevel; accu = () } s;
5504 let len = in_channel_length ic
in
5505 let s = String.create
len in
5506 really_input ic
s 0 len;
5509 | Parse_error
(msg
, s, pos
) ->
5510 let subs = subs s pos
in
5511 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5512 failwith
("parse error: " ^
s)
5515 failwith
("config load error: " ^
Printexc.to_string exn
)
5521 let dir = Filename.concat
home ".config" in
5522 if Sys.is_directory
dir then dir else home
5525 Filename.concat
dir "llpp.conf"
5528 let confpath = ref defconfpath;;
5531 if Sys.file_exists
!confpath
5534 (try Some
(open_in_bin
!confpath)
5537 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5538 Printexc.to_string exn
);
5547 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5548 Printexc.to_string exn
);
5554 f (Hashtbl.create
0, defconf)
5559 let pc, pb
, px, pa
=
5561 Hashtbl.find h (Filename.basename
state.path)
5562 with Not_found
-> dc, [], 0, (0, 0.0)
5566 state.bookmarks <- pb
;
5568 state.scrollw
<- conf.scrollbw
;
5570 then state.anchor <- pa
;
5571 cbput state.hists
.nav pa
;
5576 let add_attrs bb always
dc c =
5579 then Printf.bprintf bb
"\n %s='%b'" s a
5582 then Printf.bprintf bb
"\n %s='%d'" s a
5585 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5588 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5591 then Printf.bprintf bb
"\n %s='%f'" s a
5595 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5599 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5603 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5607 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5613 | Some
(_N
, _A
, _B
) ->
5614 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
5624 else string_of_float
f
5626 Printf.bprintf bb
"\n %s='%s'" s v
5631 | Some
((n, a, b), _) when n > 1 ->
5632 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
5638 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
5643 then dc.winw, dc.winh
5645 match state.fullscreen
with
5647 | None
-> c.winw, c.winh
5649 let zoom, presentation, interpagespace, maxwait
=
5651 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5653 match state.mode with
5654 | Birdseye
(bc
, _, _, _, _) ->
5655 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5656 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5658 oi
"width" w dc.winw;
5659 oi
"height" h dc.winh
;
5660 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5661 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5662 ob "case-insensitive-search" c.icase
dc.icase
;
5663 ob "preload" c.preload dc.preload;
5664 oi
"page-bias" c.pagebias
dc.pagebias
;
5665 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5666 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5667 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5668 ob "crop-hack" c.crophack
dc.crophack
;
5669 oW
"throttle" maxwait
dc.maxwait
;
5670 ob "highlight-links" c.hlinks
dc.hlinks
;
5671 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5672 oi
"vertical-margin" interpagespace dc.interpagespace;
5673 oz
"zoom" zoom dc.zoom;
5674 ob "presentation" presentation dc.presentation;
5675 oi
"rotation-angle" c.angle
dc.angle
;
5676 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5677 ob "proportional-display" c.proportional
dc.proportional
;
5678 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5679 oi
"tex-count" c.texcount
dc.texcount
;
5680 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5681 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5682 ob "persistent-location" c.jumpback
dc.jumpback
;
5683 oc
"background-color" c.bgcolor
dc.bgcolor
;
5684 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5685 oi
"tile-width" c.tilew
dc.tilew
;
5686 oi
"tile-height" c.tileh
dc.tileh
;
5687 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
5688 ob "checkers" c.checkers
dc.checkers
;
5689 oi
"aalevel" c.aalevel
dc.aalevel
;
5690 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5691 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5692 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5693 oC
"color-space" c.colorspace
dc.colorspace
;
5694 ob "invert-colors" c.invert
dc.invert
;
5695 oF
"brightness" c.colorscale
dc.colorscale
;
5696 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5697 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
5698 oco
"columns" c.columns
dc.columns
;
5699 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
5701 then ob "wmclass-hack" !wmclasshack false;
5705 let uifontsize = fstate.fontsize
in
5706 let bb = Buffer.create
32768 in
5708 let dc = if conf.bedefault
then conf else dc in
5709 Buffer.add_string
bb "<llppconfig>\n";
5711 if String.length
!fontpath > 0
5713 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5719 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5722 Buffer.add_string
bb "<defaults ";
5723 add_attrs bb true dc dc;
5724 Buffer.add_string
bb "/>\n";
5726 let adddoc path pan
anchor c bookmarks =
5727 if bookmarks == [] && c = dc && anchor = emptyanchor
5730 Printf.bprintf
bb "<doc path='%s'"
5731 (enent
path 0 (String.length
path));
5733 if anchor <> emptyanchor
5735 let n, y = anchor in
5736 Printf.bprintf
bb " page='%d'" n;
5739 Printf.bprintf
bb " rely='%f'" y
5744 then Printf.bprintf
bb " pan='%d'" pan
;
5746 add_attrs bb false dc c;
5748 begin match bookmarks with
5749 | [] -> Buffer.add_string
bb "/>\n"
5751 Buffer.add_string
bb ">\n<bookmarks>\n";
5752 List.iter
(fun (title, _level
, (page, rely)) ->
5754 "<item title='%s' page='%d'"
5755 (enent
title 0 (String.length
title))
5760 Printf.bprintf
bb " rely='%f'" rely
5762 Buffer.add_string
bb "/>\n";
5764 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5770 match state.mode with
5771 | Birdseye
(c, pan, _, _, _) ->
5773 match conf.columns
with
5774 | Some
((c, _, _), _) -> Some
c
5777 match c.columns
with
5778 | Some
(c, _) -> Some
(c, [||])
5781 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
5782 | _ -> state.x, conf
5784 let basename = Filename.basename state.path in
5785 adddoc basename pan (getanchor ())
5788 match state.autoscroll
with
5790 | None
-> conf.autoscrollstep
}
5791 (if conf.savebmarks
then state.bookmarks else []);
5793 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5795 then adddoc path x y c bookmarks
5797 Buffer.add_string
bb "</llppconfig>";
5800 if Buffer.length
bb > 0
5803 let tmp = !confpath ^
".tmp" in
5804 let oc = open_out_bin
tmp in
5805 Buffer.output_buffer
oc bb;
5807 Unix.rename
tmp !confpath;
5810 ("error while saving configuration: " ^
Printexc.to_string exn
)
5817 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5818 "<password> Set password");
5820 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5821 "<path> Set path to the user interface font");
5823 ("-c", Arg.String
(fun s -> Config.confpath := s),
5824 "<path> Set path to the configuration file");
5826 ("-v", Arg.Unit
(fun () ->
5828 "%s\nconfiguration path: %s\n"
5832 exit
0), " Print version and exit");
5835 (fun s -> state.path <- s)
5836 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5838 if String.length
state.path = 0
5839 then (prerr_endline
"file name missing"; exit
1);
5843 let _ = Glut.init
Sys.argv
in
5844 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5845 let () = Glut.initWindowSize
conf.winw conf.winh
in
5846 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5848 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5849 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5850 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5855 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5857 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5858 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5859 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5860 Unix.bind
sock addr;
5862 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5863 Unix.connect
csock addr;
5864 let ssock, _ = Unix.accept
sock in
5867 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5868 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5875 let () = Glut.displayFunc
display in
5876 let () = Glut.reshapeFunc
reshape in
5877 let () = Glut.keyboardFunc
keyboard in
5878 let () = Glut.specialFunc
special in
5879 let () = Glut.idleFunc
(Some
idle) in
5880 let () = Glut.mouseFunc
mouse in
5881 let () = Glut.motionFunc
motion in
5882 let () = Glut.passiveMotionFunc
pmotion in
5884 setcheckers conf.checkers
;
5886 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5887 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
5888 !Config.wmclasshack, !Config.fontpath
5890 state.csock <- csock;
5891 state.ssock <- ssock;
5892 state.text <- "Opening " ^
state.path;
5893 setaalevel
conf.aalevel
;
5894 writeopen state.path state.password
;
5896 setfontsize fstate.fontsize
;
5904 | Glut.BadEnum
"key in special_of_int" ->
5905 showtext '
!'
" LablGlut bug: special key not recognized";
5912 | exn
when conf.redirectstderr ->
5914 Printf.sprintf
"exception %s\n%s"
5915 (Printexc.to_string exn
)
5916 (Printexc.get_backtrace
())
5919 Unix.single_write
state.stderr
s 0 (String.length
s);