4 | Ulinkgoto
of (int * int)
6 | Uunexpected
of string
9 | Uremote
of (string * int)
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
| Pwindowsgui
| Posx
| Psun
45 | Pfreebsd
| Pdragonflybsd
| Popenbsd
| Pnetbsd
46 | Pmingw
| Pmingwgui
| Pcygwin
;;
48 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
50 external init
: pipe
-> params
-> unit = "ml_init";;
51 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
52 external copysel
: string -> opaque
-> unit = "ml_copysel";;
53 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
54 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
55 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
56 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
57 external measurestr
: int -> string -> float = "ml_measure_string";;
58 external getmaxw
: unit -> float = "ml_getmaxw";;
59 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
60 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
61 external platform
: unit -> platform
= "ml_platform";;
62 external setaalevel
: int -> unit = "ml_setaalevel";;
63 external realloctexts
: int -> bool = "ml_realloctexts";;
64 external seterrhandle
: bool -> Unix.file_descr
-> unit = "ml_seterrhandle";;
66 let platform_to_string = function
67 | Punknown
-> "unknown"
69 | Pwindows
-> "Windows"
70 | Pwindowsgui
-> "Windows/GUI"
73 | Pfreebsd
-> "FreeBSD"
74 | Pdragonflybsd
-> "DragonflyBSD"
75 | Popenbsd
-> "OpenBSD"
79 | Pmingwgui
-> "MingW/GUI"
82 let platform = platform ();;
86 | Pwindows
| Pwindowsgui
| Pmingw
| Pmingwgui
-> true
92 | Pwindowsgui
| Pmingwgui
-> true
100 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
103 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
105 type mpos
= int * int
107 | Msel
of (mpos
* mpos
)
109 | Mscrolly
| Mscrollx
110 | Mzoom
of (int * int)
111 | Mzoomrect
of (mpos
* mpos
)
115 type textentry
= string * string * onhist
option * onkey
* ondone
116 and onkey
= string -> int -> te
117 and ondone
= string -> unit
118 and histcancel
= unit -> unit
119 and onhist
= ((histcmd
-> string) * histcancel
)
120 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
125 | TEswitch
of textentry
136 let bound v minv maxv
=
137 max minv
(min maxv v
);
141 { store
= Array.create n v
148 let drawstring size x y s
=
150 Gl.enable `texture_2d
;
151 ignore
(drawstr size x y s
);
153 Gl.disable `texture_2d
;
156 let drawstring1 size x y s
=
160 let drawstring2 size x y fmt
=
161 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
164 let cbcap b
= Array.length b
.store
;;
169 b
.wc
<- (b
.wc
+ 1) mod cap;
171 b
.len
<- min
(b
.len
+ 1) cap;
174 let cbempty b
= b
.len
= 0;;
176 let cbgetg b circular dir
=
180 let rc = b
.rc + dir
in
192 else max
0 (min
rc (b
.len
-1))
198 let cbget b
= cbgetg b
false;;
199 let cbgetc b
= cbgetg b
true;;
216 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
217 dolog " WxH %dx%d" l
.pagew l
.pageh
;
218 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
219 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
220 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
224 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
226 dolog " x0,y0=(% f, % f)" x0 y0
;
227 dolog " x1,y1=(% f, % f)" x1 y1
;
228 dolog " x2,y2=(% f, % f)" x2 y2
;
229 dolog " x3,y3=(% f, % f)" x3 y3
;
234 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
235 and multicol
= columncount
* covercount
* covercount
237 and columncount
= int
238 and covercount
= int;;
241 { mutable scrollbw
: int
242 ; mutable scrollh
: int
243 ; mutable icase
: bool
244 ; mutable preload
: bool
245 ; mutable pagebias
: int
246 ; mutable verbose
: bool
247 ; mutable debug
: bool
248 ; mutable scrollstep
: int
249 ; mutable maxhfit
: bool
250 ; mutable crophack
: bool
251 ; mutable autoscrollstep
: int
252 ; mutable maxwait
: float option
253 ; mutable hlinks
: bool
254 ; mutable underinfo
: bool
255 ; mutable interpagespace
: interpagespace
256 ; mutable zoom
: float
257 ; mutable presentation
: bool
258 ; mutable angle
: angle
261 ; mutable savebmarks
: bool
262 ; mutable proportional
: proportional
263 ; mutable trimmargins
: trimmargins
264 ; mutable trimfuzz
: irect
265 ; mutable memlimit
: memsize
266 ; mutable texcount
: texcount
267 ; mutable sliceheight
: sliceheight
268 ; mutable thumbw
: width
269 ; mutable jumpback
: bool
270 ; mutable bgcolor
: float * float * float
271 ; mutable bedefault
: bool
272 ; mutable scrollbarinpm
: bool
273 ; mutable tilew
: int
274 ; mutable tileh
: int
275 ; mutable mustoresize
: memsize
276 ; mutable checkers
: bool
277 ; mutable aalevel
: int
278 ; mutable urilauncher
: string
279 ; mutable colorspace
: colorspace
280 ; mutable invert
: bool
281 ; mutable colorscale
: float
282 ; mutable redirectstderr
: bool
283 ; mutable ghyllscroll
: (int * int * int) option
284 ; mutable columns
: columns
option
285 ; mutable beyecolumns
: columncount
option
286 ; mutable selcmd
: string
290 type anchor
= pageno
* top
;;
292 type outline
= string * int * anchor
;;
294 type rect
= float * float * float * float * float * float * float * float;;
296 type tile
= opaque
* pixmapsize
* elapsed
297 and elapsed
= float;;
298 type pagemapkey
= pageno
* gen
;;
299 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
303 let emptyanchor = (0, 0.0);;
305 type infochange
= | Memused
| Docinfo
| Pdim
;;
307 class type uioh
= object
308 method display
: unit
309 method key
: int -> uioh
310 method special
: Glut.special_key_t
-> uioh
312 Glut.button_t
-> Glut.mouse_button_state_t
-> int -> int -> uioh
313 method motion
: int -> int -> uioh
314 method pmotion
: int -> int -> uioh
315 method infochanged
: infochange
-> unit
316 method scrollpw
: (int * float * float)
317 method scrollph
: (int * float * float)
321 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
322 | Textentry
of (textentry
* onleave
)
324 and onleave
= leavetextentrystatus
-> unit
325 and leavetextentrystatus
= | Cancel
| Confirm
326 and helpitem
= string * int * action
329 | Action
of (uioh
-> uioh
)
332 let isbirdseye = function Birdseye _
-> true | _
-> false;;
333 let istextentry = function Textentry _
-> true | _
-> false;;
337 | Loading
of (page
* gen
)
339 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
341 | Outlining
of outline list
344 let nouioh : uioh
= object (self
)
347 method special _
= self
348 method button _ _ _ _
= self
349 method motion _ _
= self
350 method pmotion _ _
= self
351 method infochanged _
= ()
352 method scrollpw
= (0, nan
, nan
)
353 method scrollph
= (0, nan
, nan
)
357 { mutable sr
: Unix.file_descr
358 ; mutable sw
: Unix.file_descr
359 ; mutable errfd
: Unix.file_descr
option
360 ; mutable stderr
: Unix.file_descr
361 ; mutable errmsgs
: Buffer.t
362 ; mutable newerrmsgs
: bool
366 ; mutable scrollw
: int
367 ; mutable hscrollh
: int
368 ; mutable anchor
: anchor
369 ; mutable ranchors
: (string * string * anchor
) list
371 ; mutable layout
: page list
372 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
373 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
374 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
375 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
376 ; mutable pagecount
: int
377 ; mutable currently
: currently
378 ; mutable mstate
: mstate
379 ; mutable searchpattern
: string
380 ; mutable rects
: (pageno
* recttype
* rect
) list
381 ; mutable rects1
: (pageno
* recttype
* rect
) list
382 ; mutable text
: string
383 ; mutable fullscreen
: (width
* height
) option
384 ; mutable mode
: mode
385 ; mutable uioh
: uioh
386 ; mutable outlines
: outline array
387 ; mutable bookmarks
: outline list
388 ; mutable path
: string
389 ; mutable password
: string
390 ; mutable invalidated
: int
391 ; mutable memused
: memsize
393 ; mutable throttle
: (page list
* int * float) option
394 ; mutable autoscroll
: int option
395 ; mutable ghyll
: int option -> unit
396 ; mutable help
: helpitem array
397 ; mutable docinfo
: (int * string) list
398 ; mutable deadline
: float
399 ; mutable texid
: GlTex.texture_id
option
401 ; mutable prevzoom
: float
402 ; mutable progress
: float
405 { pat
: string circbuf
406 ; pag
: string circbuf
407 ; nav
: anchor circbuf
408 ; sel
: string circbuf
429 ; presentation
= false
434 ; proportional
= true
435 ; trimmargins
= false
436 ; trimfuzz
= (0,0,0,0)
437 ; memlimit
= 32 lsl 20
442 ; bgcolor
= (0.5, 0.5, 0.5)
444 ; scrollbarinpm
= true
447 ; mustoresize
= 128 lsl 20
453 | Pfreebsd
| Pdragonflybsd
| Popenbsd
| Pnetbsd
454 | Psun
-> "xdg-open \"%s\""
455 | Posx
-> "open \"%s\""
456 | Pwindows
| Pwindowsgui
| Pcygwin
| Pmingw
| Pmingwgui
-> "start %s"
457 | Punknown
-> "echo %s")
461 | Pfreebsd
| Pdragonflybsd
| Popenbsd
| Pnetbsd
464 | Pwindows
| Pwindowsgui
| Pcygwin
| Pmingw
| Pmingwgui
-> "wsel"
469 ; redirectstderr
= false
476 let conf = { defconf with angle
= defconf.angle
};;
479 { mutable fontsize
: int
480 ; mutable wwidth
: float
481 ; mutable maxrows
: int
493 fstate.fontsize
<- n
;
494 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
495 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
499 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
500 let len = String.length s
in
501 if colonpos >= 0 && colonpos + 3 < len
503 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
506 try String.rindex_from s
colonpos ' '
510 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
513 | "http" | "ftp" | "mailto" ->
515 try String.index_from s
colonpos ' '
516 with Not_found
-> len
518 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
528 then (try Sys.getenv
"COMSPEC" with Not_found
-> "cmd"), "/c"
532 let args = [|shell; farg
; s
|] in
533 ignore
(Unix.create_process
shell args Unix.stdin
Unix.stdout
Unix.stderr
)
537 if String.length
conf.urilauncher
= 0
538 then print_endline uri
540 let url = geturl uri
in
541 if String.length
url = 0
542 then print_endline uri
544 let re = Str.regexp
"%s" in
545 let command = Str.global_replace
re url conf.urilauncher
in
549 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
555 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
556 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
560 let strings = version () :: "" :: Help.keys
in
563 let url = geturl s
in
564 if String.length
url > 0
565 then (s
, 0, Action
(fun u
-> gotouri url; u
))
566 else (s
, 0, Noaction
)
576 ; stderr
= Unix.stderr
577 ; errmsgs
= Buffer.create
0
584 ; anchor
= emptyanchor
588 ; tilelru
= Queue.create
()
589 ; pagemap
= Hashtbl.create
10
590 ; tilemap
= Hashtbl.create
10
607 { nav
= cbnew 10 (0, 0.0)
630 Printf.kprintf prerr_endline fmt
632 Printf.kprintf ignore fmt
637 let rfd, wfd
= Unix.pipe
() in
638 state.errfd
<- Some
rfd;
639 seterrhandle
true wfd
;
640 Unix.dup2 wfd
Unix.stderr
;
644 let redirectstderr () =
647 if conf.redirectstderr
649 let rfd, wfd
= Unix.pipe
() in
650 state.stderr
<- Unix.dup
Unix.stderr
;
651 state.errfd
<- Some
rfd;
652 seterrhandle
false wfd
;
653 Unix.dup2 wfd
Unix.stderr
;
655 state.newerrmsgs
<- false;
656 begin match state.errfd
with
659 seterrhandle
false state.stderr
;
660 Unix.dup2
state.stderr
Unix.stderr
;
664 prerr_string
(Buffer.contents
state.errmsgs
);
666 Buffer.clear
state.errmsgs
;
673 let postRedisplay who
=
675 then prerr_endline
("redisplay for " ^ who
);
676 Glut.postRedisplay ();
681 let b = Buffer.create
(String.length s
+ 1) in
682 Buffer.add_string
b s
;
687 let colorspace_of_string s
=
688 match String.lowercase s
with
692 | _
-> failwith
"invalid colorspace"
695 let int_of_colorspace = function
701 let colorspace_of_int = function
705 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
708 let colorspace_to_string = function
714 let intentry_with_suffix text key
=
715 let c = Char.unsafe_chr key
in
716 match Char.lowercase
c with
718 let text = addchar text c in
722 let text = addchar text c in
726 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
730 let columns_to_string (n
, a
, b) =
732 then Printf.sprintf
"%d" n
733 else Printf.sprintf
"%d,%d,%d" n a
b;
736 let columns_of_string s
=
738 (int_of_string s
, 0, 0)
740 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
744 let len = String.length s
in
746 let b = Buffer.create
n in
747 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
748 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
749 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
750 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
751 Buffer.add_string
b s
;
752 let s'
= Buffer.contents
b in
753 let n'
= Unix.write fd
s'
0 n in
754 if n'
!= n then failwith
"write failed";
759 let n = Unix.read fd
s 0 4 in
760 if n != 4 then failwith
"incomplete read(len)";
762 lor (Char.code
s.[0] lsl 24)
763 lor (Char.code
s.[1] lsl 16)
764 lor (Char.code
s.[2] lsl 8)
765 lor (Char.code
s.[3] lsl 0)
767 let s = String.create
len in
768 let n = Unix.read fd
s 0 len in
769 if n != len then failwith
"incomplete read(data)";
774 let b = Buffer.create
10 in
775 Buffer.add_string
b s;
776 let rec combine = function
779 Buffer.add_char
b ' '
;
782 | `
b b -> if b then "1" else "0"
784 | `i i
-> string_of_int i
785 | `f f
-> string_of_float f
786 | `I f
-> string_of_int
(truncate f
)
788 Buffer.add_string
b s;
795 let cmd = Buffer.contents
(makecmd s l
) in
796 writecmd state.sw
cmd;
802 let d = conf.winh
- h
in
809 let rec f pn ph pi fh l
=
811 | (n, _
, h
, _
) :: rest
->
812 let ips = calcips h
in
817 if isbirdseye state.mode
&& pn
= 0
822 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
827 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
831 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
834 let fh = f 0 0 0 0 state.pdims
in
839 match conf.columns
with
840 | None
-> calcheight ()
842 if Array.length
b > 0
844 let (_
, _
, y
, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
849 let getpageyh pageno
=
850 let rec f pn ph pi y l
=
852 | (n, _
, h
, _
) :: rest
->
853 let ips = calcips h
in
856 let h = if n = pageno
then h else ph
in
857 if conf.presentation
&& n = pageno
859 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
861 y
+ (pageno
- pn
) * (ph
+ pi
), h
863 let y = y + (if conf.presentation
then pi
else 0) in
864 let y = y + (n - pn
) * (ph
+ pi
) in
868 y + (pageno
- pn
) * (ph
+ pi
), ph
870 f 0 0 0 0 state.pdims
873 let getpageyh pageno
=
874 match conf.columns
with
875 | None
-> getpageyh pageno
877 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
881 let getpagedim pageno
=
884 | (n, _
, _
, _
) as pdim
:: rest
->
886 then (if n = pageno
then pdim
else ppdim
)
891 f (-1, -1, -1, -1) state.pdims
894 let getpagey pageno
= fst
(getpageyh pageno
);;
897 let sh = sh - state.hscrollh
in
898 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
899 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
901 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
902 let ips = calcips h in
904 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
908 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
910 prev
, pdims
, pdimno
, 0
912 let dy = dy + yinc in
913 let py = py + yinc in
914 if pageno
= state.pagecount
|| dy >= sh
919 if py + h <= vy - yinc
921 let py = py + h + ips in
922 let dy = max
0 (py - y) in
931 let pagey = vy - py in
932 let pagevh = h - pagey in
933 let pagevh = min
(sh - dy) pagevh in
934 let off = if yinc > 0 then py - vy else 0 in
935 let py = py + h + ips in
938 if state.w
< conf.winw
- state.scrollw
939 then (conf.winw
- state.scrollw
- state.w
) / 2
942 let dispx = xoff + state.x
in
948 let lw = w
- pagex in
949 min
lw (conf.winw
- state.scrollw
)
957 ; pagey = pagey + off
959 ; pagevh = pagevh - off
961 ; pagedispy
= dy + off
964 let accu = e :: accu in
973 if state.invalidated
= 0
991 let layoutN ((columns
, coverA
, coverB
), b) y sh =
992 let sh = sh - state.hscrollh
in
993 let rec fold accu n =
994 if n = Array.length
b
997 let pdimno, dx
, vy, (_
, w
, h, xoff) = b.(n) in
1000 || n = state.pagecount
- coverB
1001 || (n - coverA
) mod columns
= columns
- 1)
1007 let pagey = max
0 (y - vy) in
1008 let pagedispy = if pagey > 0 then 0 else vy - y in
1009 let pagedispx, pagex, pagevw =
1011 if n = coverA
- 1 || n = state.pagecount
- coverB
1012 then state.x
+ (conf.winw
- state.scrollw
- w
) / 2
1013 else dx
+ xoff + state.x
1016 then 0, -pdx, w
+ pdx
1017 else pdx, 0, min
(conf.winw
- state.scrollw
) w
1019 let pagevh = min
(h - pagey) (sh - pagedispy) in
1020 if pagedispx < conf.winw
- state.scrollw
&& pagevw > 0 && pagevh > 0
1024 ; pagedimno
= pdimno
1031 ; pagedispx = pagedispx
1032 ; pagedispy = pagedispy
1043 if state.invalidated
= 0
1044 then List.rev
(fold [] 0)
1049 match conf.columns
with
1050 | None
-> layout1 y sh
1051 | Some
c -> layoutN c y sh
1055 let y = state.y + incr
in
1057 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1061 let getopaque pageno
=
1062 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
1063 with Not_found
-> None
1066 let putopaque pageno opaque
=
1067 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
1071 let tilex = l
.pagex mod conf.tilew
in
1072 let tiley = l
.pagey mod conf.tileh
in
1074 let col = l
.pagex / conf.tilew
in
1075 let row = l
.pagey / conf.tileh
in
1078 let a = l
.pagew
- l
.pagex in
1079 let b = conf.winw
- state.scrollw
in
1081 and vh
= l
.pagevh in
1083 let rec rowloop row y0 dispy
h =
1087 let dh = conf.tileh
- y0
in
1088 let dh = min
h dh in
1089 let rec colloop col x0
dispx w
=
1093 let dw = conf.tilew
- x0
in
1094 let dw = min w
dw in
1096 f col row dispx dispy x0 y0
dw dh;
1097 colloop (col+1) 0 (dispx+dw) (w
-dw)
1100 colloop col tilex l
.pagedispx vw;
1101 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1105 then rowloop row tiley l
.pagedispy vh
;
1108 let gettileopaque l
col row =
1110 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1112 try Some
(Hashtbl.find
state.tilemap
key)
1113 with Not_found
-> None
1116 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1117 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1118 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1121 let drawtiles l color
=
1123 let f col row x
y tilex tiley w
h =
1124 match gettileopaque l
col row with
1125 | Some
(opaque
, _
, t
) ->
1126 let params = x
, y, w
, h, tilex, tiley in
1130 GlFunc.blend_func `zero `one_minus_src_color
;
1132 drawtile
params opaque
;
1134 then Gl.disable `blend
;
1137 let s = Printf.sprintf
1141 let w = measurestr
fstate.fontsize
s in
1142 GlMisc.push_attrib
[`current
];
1143 GlDraw.color
(0.0, 0.0, 0.0);
1145 (float (x
-2), float (y-2))
1146 (float (x
+2) +. w, float (y + fstate.fontsize
+ 2));
1147 GlDraw.color
(1.0, 1.0, 1.0);
1148 drawstring fstate.fontsize x
(y + fstate.fontsize
- 1) s;
1149 GlMisc.pop_attrib
();
1154 let lw = conf.winw
- state.scrollw
- x
in
1157 let lh = conf.winh
- y in
1160 Gl.enable `texture_2d
;
1161 begin match state.texid
with
1163 GlTex.bind_texture `texture_2d id
;
1166 and x1
= float (x
+w)
1167 and y1
= float (y+h) in
1169 let tw = float w /. 64.0
1170 and th
= float h /. 64.0 in
1171 let tx0 = float tilex /. 64.0
1172 and ty0
= float tiley /. 64.0 in
1174 and ty1
= ty0
+. th
in
1175 GlDraw.begins `quads
;
1176 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
1177 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
1178 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
1179 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
1182 Gl.disable `texture_2d
;
1184 GlDraw.color
(1.0, 1.0, 1.0);
1187 (float (x
+w), float (y+h));
1189 if w > 128 && h > fstate.fontsize
+ 10
1191 GlDraw.color
(0.0, 0.0, 0.0);
1194 then (col*conf.tilew
, row*conf.tileh
)
1197 drawstring2 fstate.fontsize x
y "Loading %d [%d,%d]" l
.pageno
c r
;
1204 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1206 let tilevisible1 l x
y =
1208 and ax1
= l
.pagex + l
.pagevw
1210 and ay1
= l
.pagey + l
.pagevh in
1214 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1215 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1217 let rx0 = max
ax0 bx0
1218 and ry0
= max ay0 by0
1219 and rx1
= min ax1
bx1
1220 and ry1
= min ay1 by1
in
1222 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1223 nonemptyintersection
1226 let tilevisible layout n x
y =
1227 let rec findpageinlayout = function
1228 | l
:: _
when l
.pageno
= n -> tilevisible1 l x
y
1229 | _
:: rest
-> findpageinlayout rest
1232 findpageinlayout layout
1235 let tileready l x
y =
1236 tilevisible1 l x
y &&
1237 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
1240 let tilepage n p
layout =
1241 let rec loop = function
1245 let f col row _ _ _ _ _ _
=
1246 if state.currently
= Idle
1248 match gettileopaque l
col row with
1251 let x = col*conf.tilew
1252 and y = row*conf.tileh
in
1254 let w = l
.pagew
- x in
1258 let h = l
.pageh
- y in
1270 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1271 conf.tilew
, conf.tileh
1280 if state.invalidated
= 0 then loop layout;
1283 let preloadlayout visiblepages
=
1284 let presentation = conf.presentation in
1285 let interpagespace = conf.interpagespace in
1286 let maxy = state.maxy in
1287 conf.presentation <- false;
1288 conf.interpagespace <- 0;
1289 state.maxy <- calcheight ();
1291 match visiblepages
with
1293 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1295 let y = if y < conf.winh
then 0 else y - conf.winh
in
1296 let h = state.y - y + conf.winh
*3 in
1297 let pages = layout y h in
1298 conf.presentation <- presentation;
1299 conf.interpagespace <- interpagespace;
1305 let rec loop pages =
1306 if state.currently
!= Idle
1311 begin match getopaque l
.pageno
with
1313 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1314 state.currently
<- Loading
(l
, state.gen
);
1316 tilepage l
.pageno opaque
pages;
1321 if state.invalidated
= 0 then loop pages
1326 if conf.preload && state.currently
= Idle
1327 then load (preloadlayout pages);
1330 let layoutready layout =
1331 let rec fold all ls
=
1332 all
&& match ls
with
1334 let seen = ref false in
1335 let allvisible = ref true in
1336 let foo col row _ _ _ _ _ _
=
1338 allvisible := !allvisible &&
1339 begin match gettileopaque l
col row with
1345 fold (!seen && !allvisible) rest
1348 let alltilesvisible = fold true layout in
1353 let y = bound y 0 state.maxy in
1354 let y, layout, proceed
=
1355 match conf.maxwait
with
1356 | Some time
when state.ghyll
== noghyll ->
1357 begin match state.throttle
with
1359 let layout = layout y conf.winh
in
1360 let ready = layoutready layout in
1364 state.throttle
<- Some
(layout, y, now ());
1366 else G.postRedisplay "gotoy showall (None)";
1368 | Some
(_
, _
, started
) ->
1369 let dt = now () -. started
in
1372 state.throttle
<- None
;
1373 let layout = layout y conf.winh
in
1375 G.postRedisplay "maxwait";
1382 let layout = layout y conf.winh
in
1383 if true || layoutready layout
1384 then G.postRedisplay "gotoy ready";
1390 state.layout <- layout;
1391 begin match state.mode
with
1392 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1393 if not
(pagevisible layout pageno
)
1395 match state.layout with
1398 state.mode
<- Birdseye
(
1399 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1406 state.ghyll
<- noghyll;
1409 let conttiling pageno opaque
=
1410 tilepage pageno opaque
1411 (if conf.preload then preloadlayout state.layout else state.layout)
1414 let gotoy_and_clear_text y =
1416 if not
conf.verbose
then state.text <- "";
1420 match state.layout with
1422 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1425 let getanchory (n, top
) =
1426 let y, h = getpageyh n in
1427 y + (truncate
(top
*. float h));
1430 let gotoanchor anchor
=
1431 gotoy (getanchory anchor
);
1435 cbput state.hists
.nav
(getanchor ());
1439 let anchor = cbgetc state.hists
.nav dir
in
1444 let rec scroll f n a b =
1445 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1447 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1449 then s (float f /. float a)
1452 then 1.0 -. s ((float (f-b) /. float (n-b)))
1459 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1460 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1462 let ins = float a *. iv1
1463 and outs
= float (n-b) *. iv1 in
1465 ins +. outs
+. float ones
1467 let rec set (_N
, _A
, _B
) y sy
=
1468 let sum = summa
1.0 _N _A _B
in
1469 let dy = float (y - sy
) in
1473 then state.ghyll
<- noghyll
1476 let s = scroll n _N _A _B
in
1477 let y1 = y1 +. ((s *. dy) /. sum) in
1478 gotoy_and_clear_text (truncate
y1);
1479 state.ghyll
<- gf (n+1) y1;
1483 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1485 gf 0 (float state.y)
1488 match conf.ghyllscroll
with
1490 gotoy_and_clear_text y
1492 if state.ghyll
== noghyll
1493 then set nab
y state.y
1494 else state.ghyll
(Some
y)
1497 let gotopage n top
=
1498 let y, h = getpageyh n in
1499 let y = y + (truncate
(top
*. float h)) in
1503 let gotopage1 n top
=
1504 let y = getpagey n in
1514 state.invalidated
<- state.invalidated
+ 1;
1517 let writeopen path password
=
1518 writecmd state.sw
("open " ^ path ^
"\000" ^ password ^
"\000");
1521 let opendoc path password
=
1524 state.password
<- password
;
1525 state.gen
<- state.gen
+ 1;
1526 state.docinfo
<- [];
1528 setaalevel
conf.aalevel
;
1529 writeopen path password
;
1530 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1531 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1535 let c = c *. conf.colorscale
in
1539 let scalecolor2 (r
, g
, b) =
1540 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1544 let docolumns = function
1546 | Some
((columns
, coverA
, coverB
), _
) ->
1547 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1548 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1549 if pageno
= state.pagecount
1552 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1554 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1555 pdimno+1, pdim
, rest
1560 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1562 (conf.winw
- state.scrollw
- w) / 2,
1563 y + rowh
+ conf.interpagespace, h
1566 if (pageno
- coverA
) mod columns
= 0
1567 then 0, y + rowh
+ conf.interpagespace, h
1568 else x, y, max rowh
h
1571 let rec fixrow m
= if m
= pageno
then () else
1572 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1575 let y = y + (rowh
- h) / 2 in
1576 a.(m
) <- (pdimno, x, y, pdim
);
1580 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1581 then fixrow (pageno
- columns
);
1582 a.(pageno
) <- (pdimno, x, y, pdim
);
1583 let x = x + w + xoff*2 + conf.interpagespace in
1584 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1586 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1587 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1589 docolumns conf.columns
;
1590 state.maxy <- calcheight ();
1592 if state.w <= conf.winw
- state.scrollw
1596 match state.mode
with
1597 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1598 let y, h = getpageyh pageno
in
1599 let top = (conf.winh
- h) / 2 in
1600 gotoy (max
0 (y - top))
1601 | _
-> gotoanchor state.anchor
1605 let firsttime = ref true in
1607 GlDraw.viewport
0 0 w h;
1608 if state.invalidated
= 0 && not
!firsttime
1609 then state.anchor <- getanchor ();
1613 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1617 setfontsize fstate.fontsize
;
1618 GlMat.mode `modelview
;
1619 GlMat.load_identity
();
1621 GlMat.mode `projection
;
1622 GlMat.load_identity
();
1623 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1624 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1625 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1628 match conf.columns
with
1630 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1633 wcmd "geometry" [`i
w; `i
h];
1637 let len = String.length
state.text in
1640 match state.mode
with
1641 | View
-> state.hscrollh
1646 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1647 (x+.w, float (conf.winh
- hscrollh))
1650 let w = float (conf.winw
- state.scrollw
- 1) in
1651 if state.progress
>= 0.0 && state.progress
< 1.0
1653 GlDraw.color
(0.3, 0.3, 0.3);
1654 let w1 = w *. state.progress
in
1656 GlDraw.color
(0.0, 0.0, 0.0);
1660 GlDraw.color
(0.0, 0.0, 0.0);
1664 GlDraw.color
(1.0, 1.0, 1.0);
1665 drawstring fstate.fontsize
1666 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1669 match state.mode
with
1670 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1674 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1676 Printf.sprintf
"%s%s_" prefix
text
1685 if not
(istextentry state.mode
)
1687 let s1 = "(press 'e' to review error messasges)" in
1688 if String.length
s > 0 then s ^
" " ^
s1 else s1
1693 if String.length
s > 0
1698 state.text <- Printf.sprintf
"%c%s" c s;
1699 G.postRedisplay "showtext";
1703 let len = Queue.length
state.tilelru
in
1705 if state.memused
<= conf.memlimit
1710 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1711 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1712 let (_
, pw
, ph
, _
) = getpagedim n in
1715 && colorspace
= conf.colorspace
1716 && angle
= conf.angle
1721 match state.throttle
with
1724 then preloadlayout state.layout
1726 | Some
(layout, _
, _
) ->
1729 let x = col*conf.tilew
1730 and y = row*conf.tileh
in
1731 tilevisible layout n x y
1733 then Queue.push lruitem
state.tilelru
1735 wcmd "freetile" [`
s p
];
1736 state.memused
<- state.memused
- s;
1737 state.uioh#infochanged Memused
;
1738 Hashtbl.remove
state.tilemap k
;
1747 Queue.iter
(fun (k
, p
, s) ->
1748 wcmd "freetile" [`
s p
];
1749 state.memused
<- state.memused
- s;
1750 state.uioh#infochanged Memused
;
1751 Hashtbl.remove
state.tilemap k
;
1753 Queue.clear
state.tilelru
;
1757 let logcurrently = function
1758 | Idle
-> dolog "Idle"
1759 | Loading
(l
, gen
) ->
1760 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1761 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1763 "Tiling %d[%d,%d] page=%s cs=%s angle"
1764 l
.pageno
col row pageopaque
1765 (colorspace_to_string colorspace
)
1767 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1768 angle gen
conf.angle
state.gen
1770 conf.tilew
conf.tileh
1777 (* dolog "%S" cmds; *)
1780 try String.index cmds ' '
1781 with Not_found
-> -1
1786 let l = String.length cmds
in
1787 let op = String.sub cmds
0 spacepos in
1789 if l - spacepos < 2 then ""
1790 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1795 state.uioh#infochanged Pdim
;
1799 state.rects
<- state.rects1
;
1800 G.postRedisplay "clearrects";
1804 try Scanf.sscanf
args "%u" (fun n -> n)
1806 dolog "error processing 'continue' %S: %s"
1807 cmds
(Printexc.to_string exn
);
1810 state.pagecount
<- n;
1811 state.invalidated
<- state.invalidated
- 1;
1812 begin match state.currently
with
1814 state.currently
<- Idle
;
1815 state.outlines
<- Array.of_list
(List.rev
l)
1818 if state.invalidated
= 0
1820 if conf.maxwait
= None
1821 then G.postRedisplay "continue";
1824 Glut.setWindowTitle
args
1831 then showtext ' '
args
1834 let progress, text =
1836 Scanf.sscanf
args "%f %n"
1838 f, String.sub
args pos
(String.length
args - pos
))
1840 dolog "error processing 'progress' %S: %s"
1841 cmds
(Printexc.to_string exn
);
1845 state.progress <- progress;
1846 G.postRedisplay "progress"
1849 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1851 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1852 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1853 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1855 dolog "error processing 'firstmatch' %S: %s"
1856 cmds
(Printexc.to_string exn
);
1859 let y = (getpagey pageno) + truncate y0
in
1862 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)]
1865 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1867 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1868 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1869 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1871 dolog "error processing 'match' %S: %s"
1872 cmds
(Printexc.to_string exn
);
1876 (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) :: state.rects1
1881 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
1883 dolog "error processing 'page' %S: %s"
1884 cmds
(Printexc.to_string exn
);
1887 begin match state.currently
with
1888 | Loading
(l, gen
) ->
1889 vlog "page %d took %f sec" l.pageno t
;
1890 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1891 begin match state.throttle
with
1893 let preloadedpages =
1895 then preloadlayout state.layout
1900 Set.Make
(struct type t
= int let compare = (-) end) in
1902 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1903 IntSet.empty
preloadedpages
1906 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
1907 if not
(IntSet.mem
pageno set)
1909 wcmd "freepage" [`
s opaque
];
1915 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1918 state.currently
<- Idle
;
1921 tilepage l.pageno pageopaque state.layout;
1923 load preloadedpages;
1924 if pagevisible state.layout l.pageno
1925 && layoutready state.layout
1926 then G.postRedisplay "page";
1929 | Some
(layout, _
, _
) ->
1930 state.currently
<- Idle
;
1931 tilepage l.pageno pageopaque layout;
1936 dolog "Inconsistent loading state";
1937 logcurrently state.currently
;
1942 let (x, y, opaque
, size
, t
) =
1944 Scanf.sscanf
args "%u %u %s %u %f"
1945 (fun x y p size t
-> (x, y, p
, size
, t
))
1947 dolog "error processing 'tile' %S: %s"
1948 cmds
(Printexc.to_string exn
);
1951 begin match state.currently
with
1952 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1953 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1955 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1957 wcmd "freetile" [`
s opaque
];
1958 state.currently
<- Idle
;
1962 puttileopaque l col row gen cs angle opaque size t
;
1963 state.memused
<- state.memused
+ size
;
1964 state.uioh#infochanged Memused
;
1966 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1967 opaque
, size
) state.tilelru
;
1970 match state.throttle
with
1971 | None
-> state.layout
1972 | Some
(layout, _
, _
) -> layout
1975 state.currently
<- Idle
;
1977 && conf.colorspace
= cs
1978 && conf.angle
= angle
1979 && tilevisible layout l.pageno x y
1980 then conttiling l.pageno pageopaque;
1982 begin match state.throttle
with
1984 preload state.layout;
1986 && conf.colorspace
= cs
1987 && conf.angle
= angle
1988 && tilevisible state.layout l.pageno x y
1989 then G.postRedisplay "tile nothrottle";
1991 | Some
(layout, y, _
) ->
1992 let ready = layoutready layout in
1996 state.layout <- layout;
1997 state.throttle
<- None
;
1998 G.postRedisplay "throttle";
2005 dolog "Inconsistent tiling state";
2006 logcurrently state.currently
;
2013 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2015 dolog "error processing 'pdim' %S: %s"
2016 cmds
(Printexc.to_string exn
);
2019 state.uioh#infochanged Pdim
;
2020 state.pdims
<- pdim :: state.pdims
2023 let (l, n, t
, h, pos
) =
2025 Scanf.sscanf
args "%u %u %d %u %n"
2026 (fun l n t
h pos
-> l, n, t
, h, pos
)
2028 dolog "error processing 'o' %S: %s"
2029 cmds
(Printexc.to_string exn
);
2032 let s = String.sub
args pos
(String.length
args - pos
) in
2033 let outline = (s, l, (n, float t
/. float h)) in
2034 begin match state.currently
with
2035 | Outlining outlines
->
2036 state.currently
<- Outlining
(outline :: outlines
)
2038 state.currently
<- Outlining
[outline]
2040 dolog "invalid outlining state";
2041 logcurrently currently
2045 state.docinfo
<- (1, args) :: state.docinfo
2048 state.uioh#infochanged Docinfo
;
2049 state.docinfo
<- List.rev
state.docinfo
2052 dolog "unknown cmd `%S'" cmds
2056 if state.deadline
== nan
then state.deadline
<- now ();
2058 match state.errfd
with
2059 | None
-> [state.sr
]
2060 | Some fd
-> [state.sr
; fd
]
2062 let rec loop delay
=
2064 if state.ghyll
== noghyll
2070 then max
0.0 (deadline -. now ())
2074 try Unix.select
r [] [] timeout
2075 with Unix.Unix_error
(Unix.EINTR
, _
, _
) -> [], [] ,[]
2080 begin match state.autoscroll
with
2081 | Some step
when step
!= 0 ->
2082 let y = state.y + step
in
2086 else if y >= state.maxy then 0 else y
2089 if state.mode
= View
2090 then state.text <- "";
2091 state.deadline <- state.deadline +. 0.005;
2094 state.deadline <- state.deadline +. delay
;
2098 let rec checkfds c = function
2100 | fd
:: rest
when fd
= state.sr
->
2101 let cmd = readcmd state.sr
in
2105 let s = String.create
80 in
2106 let n = Unix.read fd
s 0 80 in
2107 if conf.redirectstderr || is_gui
2109 Buffer.add_substring
state.errmsgs
s 0 n;
2110 state.newerrmsgs
<- true;
2111 Glut.postRedisplay ();
2114 prerr_string
(String.sub
s 0 n);
2127 let action = function
2128 | HCprev
-> cbget cb ~
-1
2129 | HCnext
-> cbget cb
1
2130 | HCfirst
-> cbget cb ~
-(cb
.rc)
2131 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2132 and cancel
() = cb
.rc <- rc
2136 let search pattern forward
=
2137 if String.length pattern
> 0
2140 match state.layout with
2143 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2146 let b = makecmd "search"
2147 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
2149 Buffer.add_char
b '
,'
;
2150 Buffer.add_string
b pattern
;
2151 Buffer.add_char
b '
\000'
;
2154 writecmd state.sw
cmd;
2157 let intentry text key =
2158 let c = Char.unsafe_chr
key in
2161 let text = addchar text c in
2165 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2169 let textentry text key =
2170 let c = Char.unsafe_chr
key in
2172 | _
when key >= 32 && key < 127 ->
2173 let text = addchar text c in
2177 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
2181 let reqlayout angle proportional
=
2182 match state.throttle
with
2184 if state.invalidated
= 0 then state.anchor <- getanchor ();
2185 conf.angle
<- angle
mod 360;
2186 conf.proportional
<- proportional
;
2188 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
2192 let settrim trimmargins trimfuzz
=
2193 if state.invalidated
= 0 then state.anchor <- getanchor ();
2194 conf.trimmargins
<- trimmargins
;
2195 conf.trimfuzz
<- trimfuzz
;
2196 let x0, y0
, x1
, y1 = trimfuzz
in
2199 `
b conf.trimmargins
;
2205 Hashtbl.iter
(fun _ opaque
->
2206 wcmd "freepage" [`
s opaque
];
2208 Hashtbl.clear
state.pagemap
;
2212 match state.throttle
with
2214 let zoom = max
0.01 zoom in
2215 if zoom <> conf.zoom
2217 state.prevzoom
<- conf.zoom;
2220 then (state.x <- 0; 0.0)
2221 else float state.x /. float state.w
2224 reshape conf.winw
conf.winh
;
2227 let x = relx *. float state.w in
2228 state.x <- truncate
x;
2230 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2233 | Some
(layout, y, started
) ->
2235 match conf.maxwait
with
2239 let dt = now () -. started
in
2247 let setcolumns columns coverA coverB
=
2250 conf.columns
<- None
;
2255 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2258 reshape conf.winw
conf.winh
;
2261 let enterbirdseye () =
2262 let zoom = float conf.thumbw
/. float conf.winw
in
2263 let birdseyepageno =
2264 let cy = conf.winh
/ 2 in
2268 let rec fold best
= function
2271 let d = cy - (l.pagedispy + l.pagevh/2)
2272 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2273 if abs
d < abs dbest
2280 state.mode
<- Birdseye
(
2281 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2284 conf.presentation <- false;
2285 conf.interpagespace <- 10;
2286 conf.hlinks
<- false;
2288 state.mstate
<- Mnone
;
2289 conf.maxwait
<- None
;
2291 match conf.beyecolumns
with
2294 Some
((c, 0, 0), [||])
2297 Glut.setCursor
Glut.CURSOR_INHERIT
;
2300 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2305 reshape conf.winw
conf.winh
;
2308 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2310 conf.zoom <- c.zoom;
2311 conf.presentation <- c.presentation;
2312 conf.interpagespace <- c.interpagespace;
2313 conf.maxwait
<- c.maxwait
;
2314 conf.hlinks
<- c.hlinks
;
2315 conf.beyecolumns
<- (
2316 match conf.columns
with
2317 | Some
((c, _
, _
), _
) -> Some
c
2321 match c.columns
with
2322 | Some
(c, _
) -> Some
(c, [||])
2328 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2331 reshape conf.winw
conf.winh
;
2332 state.anchor <- if goback
then anchor else (pageno, 0.0);
2335 let togglebirdseye () =
2336 match state.mode
with
2337 | Birdseye vals
-> leavebirdseye vals
true
2338 | View
-> enterbirdseye ()
2342 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2343 let pageno = max
0 (pageno - incr
) in
2344 let rec loop = function
2345 | [] -> gotopage1 pageno 0
2346 | l :: _
when l.pageno = pageno ->
2347 if l.pagedispy >= 0 && l.pagey = 0
2348 then G.postRedisplay "upbirdseye"
2349 else gotopage1 pageno 0
2350 | _
:: rest
-> loop rest
2353 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2356 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2357 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2358 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2359 let rec loop = function
2361 let y, h = getpageyh pageno in
2362 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2364 | l :: _
when l.pageno = pageno ->
2365 if l.pagevh != l.pageh
2366 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2367 else G.postRedisplay "downbirdseye"
2368 | _
:: rest
-> loop rest
2373 let optentry mode _
key =
2374 let btos b = if b then "on" else "off" in
2375 let c = Char.unsafe_chr
key in
2379 try conf.scrollstep
<- int_of_string
s with exc
->
2380 state.text <- Printf.sprintf
"bad integer `%s': %s"
2381 s (Printexc.to_string exc
)
2383 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2388 conf.autoscrollstep
<- int_of_string
s;
2389 if state.autoscroll
<> None
2390 then state.autoscroll
<- Some
conf.autoscrollstep
2392 state.text <- Printf.sprintf
"bad integer `%s': %s"
2393 s (Printexc.to_string exc
)
2395 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2400 let n, a, b = columns_of_string s in
2403 state.text <- Printf.sprintf
"bad columns `%s': %s"
2404 s (Printexc.to_string exc
)
2406 TEswitch
("columns: ", "", None
, textentry, ondone)
2411 let zoom = float (int_of_string
s) /. 100.0 in
2414 state.text <- Printf.sprintf
"bad integer `%s': %s"
2415 s (Printexc.to_string exc
)
2417 TEswitch
("zoom: ", "", None
, intentry, ondone)
2422 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2424 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2425 begin match mode
with
2427 leavebirdseye beye
false;
2432 state.text <- Printf.sprintf
"bad integer `%s': %s"
2433 s (Printexc.to_string exc
)
2435 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2440 Some
(int_of_string
s)
2442 state.text <- Printf.sprintf
"bad integer `%s': %s"
2443 s (Printexc.to_string exc
);
2446 | Some angle
-> reqlayout angle
conf.proportional
2449 TEswitch
("rotation: ", "", None
, intentry, ondone)
2452 conf.icase
<- not
conf.icase
;
2453 TEdone
("case insensitive search " ^
(btos conf.icase
))
2456 conf.preload <- not
conf.preload;
2458 TEdone
("preload " ^
(btos conf.preload))
2461 conf.verbose
<- not
conf.verbose
;
2462 TEdone
("verbose " ^
(btos conf.verbose
))
2465 conf.debug
<- not
conf.debug
;
2466 TEdone
("debug " ^
(btos conf.debug
))
2469 conf.maxhfit
<- not
conf.maxhfit
;
2471 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2472 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2475 conf.crophack
<- not
conf.crophack
;
2476 TEdone
("crophack " ^
btos conf.crophack
)
2480 match conf.maxwait
with
2482 conf.maxwait
<- Some infinity
;
2483 "always wait for page to complete"
2485 conf.maxwait
<- None
;
2486 "show placeholder if page is not ready"
2491 conf.underinfo
<- not
conf.underinfo
;
2492 TEdone
("underinfo " ^
btos conf.underinfo
)
2495 conf.savebmarks
<- not
conf.savebmarks
;
2496 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2502 match state.layout with
2507 conf.interpagespace <- int_of_string
s;
2508 state.maxy <- calcheight ();
2509 let y = getpagey pageno in
2512 state.text <- Printf.sprintf
"bad integer `%s': %s"
2513 s (Printexc.to_string exc
)
2515 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2518 reqlayout conf.angle
(not
conf.proportional
);
2519 TEdone
("proportional display " ^
btos conf.proportional
)
2522 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2523 TEdone
("trim margins " ^
btos conf.trimmargins
)
2526 conf.invert
<- not
conf.invert
;
2527 TEdone
("invert colors " ^
btos conf.invert
)
2531 cbput state.hists
.sel
s;
2534 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2538 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2542 class type lvsource
= object
2543 method getitemcount
: int
2544 method getitem
: int -> (string * int)
2545 method hasaction
: int -> bool
2554 method getactive
: int
2555 method getfirst
: int
2556 method getqsearch
: string
2557 method setqsearch
: string -> unit
2561 class virtual lvsourcebase
= object
2562 val mutable m_active
= 0
2563 val mutable m_first
= 0
2564 val mutable m_qsearch
= ""
2565 val mutable m_pan
= 0
2566 method getactive
= m_active
2567 method getfirst
= m_first
2568 method getqsearch
= m_qsearch
2569 method getpan
= m_pan
2570 method setqsearch
s = m_qsearch
<- s
2573 let textentryspecial key = function
2574 | ((c, _
, (Some
(action, _
) as onhist), onkey
, ondone), mode
) ->
2577 | Glut.KEY_UP
-> action HCprev
2578 | Glut.KEY_DOWN
-> action HCnext
2579 | Glut.KEY_HOME
-> action HCfirst
2580 | Glut.KEY_END
-> action HClast
2583 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2584 G.postRedisplay "special textentry";
2588 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2590 state.mode
<- Textentry
(te
, onleave
);
2593 G.postRedisplay "textentrykeyboard enttext";
2595 match Char.unsafe_chr
key with
2596 | '
\008'
-> (* backspace *)
2597 let len = String.length
text in
2601 G.postRedisplay "textentrykeyboard after cancel";
2604 let s = String.sub
text 0 (len - 1) in
2605 enttext (c, s, opthist
, onkey
, ondone)
2611 G.postRedisplay "textentrykeyboard after confirm"
2613 | '
\007'
(* ctrl-g *)
2614 | '
\027'
-> (* escape *)
2615 if String.length
text = 0
2617 begin match opthist
with
2619 | Some
(_
, onhistcancel
) -> onhistcancel
()
2623 G.postRedisplay "textentrykeyboard after cancel2"
2626 enttext (c, "", opthist
, onkey
, ondone)
2629 | '
\127'
-> () (* delete *)
2632 begin match onkey
text key with
2636 G.postRedisplay "textentrykeyboard after confirm2";
2639 enttext (c, text, opthist
, onkey
, ondone);
2643 G.postRedisplay "textentrykeyboard after cancel3"
2646 state.mode
<- Textentry
(te
, onleave
);
2647 G.postRedisplay "textentrykeyboard switch";
2651 let firstof first active
=
2652 if first
> active
|| abs
(first
- active
) > fstate.maxrows
- 1
2653 then max
0 (active
- (fstate.maxrows
/2))
2657 let calcfirst first active
=
2660 let rows = active
- first
in
2661 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2665 let scrollph y maxy =
2666 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2667 let sh = float conf.winh
/. sh in
2668 let sh = max
sh (float conf.scrollh
) in
2673 else float y /. float maxy
2675 let position = (float conf.winh
-. sh) *. percent in
2678 if position +. sh > float conf.winh
2679 then float conf.winh
-. sh
2685 let coe s = (s :> uioh
);;
2687 class listview ~
(source
:lvsource
) ~trusted
=
2689 val m_pan
= source#getpan
2690 val m_first
= source#getfirst
2691 val m_active
= source#getactive
2692 val m_qsearch
= source#getqsearch
2693 val m_prev_uioh
= state.uioh
2695 method private elemunder
y =
2696 let n = y / (fstate.fontsize
+1) in
2697 if m_first
+ n < source#getitemcount
2699 if source#hasaction
(m_first
+ n)
2700 then Some
(m_first
+ n)
2707 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2708 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2709 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2710 GlDraw.color
(1., 1., 1.);
2711 Gl.enable `texture_2d
;
2712 let fs = fstate.fontsize
in
2714 let ww = fstate.wwidth
in
2715 let tabw = 30.0*.ww in
2716 let itemcount = source#getitemcount
in
2718 if (row - m_first
) * nfs > conf.winh
2721 if row >= 0 && row < itemcount
2723 let (s, level
) = source#getitem
row in
2724 let y = (row - m_first
) * nfs in
2725 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2728 Gl.disable `texture_2d
;
2729 GlDraw.polygon_mode `both `line
;
2730 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2731 GlDraw.rect (1., float (y + 1))
2732 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2733 GlDraw.polygon_mode `both `fill
;
2734 GlDraw.color
(1., 1., 1.);
2735 Gl.enable `texture_2d
;
2738 let drawtabularstring s =
2739 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2742 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2745 let len = String.length
s - tabpos - 1 in
2746 let s1 = String.sub
s 0 tabpos
2747 and s2
= String.sub
s (tabpos + 1) len in
2748 let nx = drawstr x s1 in
2750 let x = x +. (max
tabw sw) in
2757 let _ = drawtabularstring s in
2764 Gl.disable `texture_2d
;
2766 method updownlevel incr
=
2767 let len = source#getitemcount
in
2769 if m_active
>= 0 && m_active
< len
2770 then snd
(source#getitem m_active
)
2774 if i
= len then i
-1 else if i
= -1 then 0 else
2775 let _, l = source#getitem i
in
2776 if l != curlevel then i
else flow (i
+incr
)
2778 let active = flow m_active
in
2779 let first = calcfirst m_first
active in
2780 G.postRedisplay "special outline updownlevel";
2781 {< m_active
= active; m_first
= first >}
2783 method private key1
key =
2784 let set active first qsearch
=
2785 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2787 let search active pattern incr
=
2790 if n >= 0 && n < source#getitemcount
2792 let s, _ = source#getitem
n in
2794 (try ignore
(Str.search_forward
re s 0); true
2795 with Not_found
-> false)
2797 else loop (n + incr
)
2804 let re = Str.regexp_case_fold pattern
in
2811 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2812 let incr = if key = 18 then -1 else 1 in
2814 match search (m_active
+ incr) m_qsearch
incr with
2816 state.text <- m_qsearch ^
" [not found]";
2819 state.text <- m_qsearch
;
2820 active, firstof m_first
active
2822 G.postRedisplay "listview ctrl-r/s";
2823 set active first m_qsearch
;
2825 | 8 -> (* backspace *)
2826 let len = String.length m_qsearch
in
2833 G.postRedisplay "listview empty qsearch";
2834 set m_active m_first
"";
2837 let qsearch = String.sub m_qsearch
0 (len - 1) in
2839 match search m_active
qsearch ~
-1 with
2841 state.text <- qsearch ^
" [not found]";
2844 state.text <- qsearch;
2845 active, firstof m_first
active
2847 G.postRedisplay "listview backspace qsearch";
2848 set active first qsearch
2851 | _ when key >= 32 && key < 127 ->
2852 let pattern = addchar m_qsearch
(Char.chr
key) in
2854 match search m_active
pattern 1 with
2856 state.text <- pattern ^
" [not found]";
2859 state.text <- pattern;
2860 active, firstof m_first
active
2862 G.postRedisplay "listview qsearch add";
2863 set active first pattern;
2865 | 27 -> (* escape *)
2867 if String.length m_qsearch
= 0
2869 G.postRedisplay "list view escape";
2872 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2874 | None
-> m_prev_uioh
2879 G.postRedisplay "list view kill qsearch";
2880 source#setqsearch
"";
2881 coe {< m_qsearch
= "" >}
2886 let self = {< m_qsearch
= "" >} in
2887 source#setqsearch
"";
2889 G.postRedisplay "listview enter";
2890 if m_active
>= 0 && m_active
< source#getitemcount
2892 source#exit
(coe self) false m_active m_first m_pan
"";
2895 source#exit
(coe self) true m_active m_first m_pan
"";
2898 begin match opt with
2899 | None
-> m_prev_uioh
2903 | 127 -> (* delete *)
2906 | _ -> dolog "unknown key %d" key; coe self
2908 method private special1
key =
2909 let itemcount = source#getitemcount
in
2910 let find start
incr =
2912 if i
= -1 || i
= itemcount
2915 if source#hasaction i
2917 else find (i
+ incr)
2922 let set active first =
2923 let first = bound first 0 (itemcount - fstate.maxrows
) in
2925 coe {< m_active
= active; m_first
= first >}
2928 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2930 let incr1 = if incr > 0 then 1 else -1 in
2931 if isvisible m_first m_active
2934 let next = m_active
+ incr in
2936 if next < 0 || next >= itemcount
2938 else find next incr1
2940 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2946 let first = m_first
+ incr in
2947 let first = bound first 0 (itemcount - 1) in
2949 let next = m_active
+ incr in
2950 let next = bound next 0 (itemcount - 1) in
2953 let active = if next = -1 then m_active
else next in
2956 let first = min
next m_first
in
2958 if abs
(next - first) > fstate.maxrows
2964 let first = m_first
+ incr in
2965 let first = bound first 0 (itemcount - 1) in
2967 let next = m_active
+ incr in
2968 let next = bound next 0 (itemcount - 1) in
2969 let next = find next incr1 in
2971 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2973 let active = if m_active
= -1 then next else m_active
in
2978 if isvisible first active
2984 G.postRedisplay "listview navigate";
2987 begin match key with
2988 | Glut.KEY_UP
-> navigate ~
-1
2989 | Glut.KEY_DOWN
-> navigate 1
2990 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2991 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2995 G.postRedisplay "listview right";
2996 coe {< m_pan
= m_pan
- 1 >}
3000 G.postRedisplay "listview left";
3001 coe {< m_pan
= m_pan
+ 1 >}
3004 let active = find 0 1 in
3005 G.postRedisplay "listview home";
3009 let first = max
0 (itemcount - fstate.maxrows
) in
3010 let active = find (itemcount - 1) ~
-1 in
3011 G.postRedisplay "listview end";
3018 match state.mode
with
3019 | Textentry te
-> textentrykeyboard key te
; coe self
3020 | _ -> self#key1
key
3022 method special
key =
3023 match state.mode
with
3024 | Textentry te
-> textentryspecial key te
; coe self
3025 | _ -> self#special1
key
3027 method button button bstate
x y =
3030 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollbw
->
3031 G.postRedisplay "listview scroll";
3032 if bstate
= Glut.DOWN
3034 let _, position, sh = self#
scrollph in
3035 if y > truncate
position && y < truncate
(position +. sh)
3037 state.mstate
<- Mscrolly
;
3041 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3042 let first = truncate
(s *. float source#getitemcount
) in
3043 let first = min source#getitemcount
first in
3044 Some
(coe {< m_first
= first; m_active
= first >})
3046 state.mstate
<- Mnone
;
3049 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
3050 begin match self#elemunder
y with
3052 G.postRedisplay "listview click";
3054 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3058 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
3059 let len = source#getitemcount
in
3061 if n = 4 && m_first
+ fstate.maxrows
>= len
3065 let first = m_first
+ (if n == 3 then -1 else 1) in
3066 bound first 0 (len - 1)
3068 G.postRedisplay "listview wheel";
3069 Some
(coe {< m_first
= first >})
3074 | None
-> m_prev_uioh
3078 match state.mstate
with
3080 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3081 let first = truncate
(s *. float source#getitemcount
) in
3082 let first = min source#getitemcount
first in
3083 G.postRedisplay "listview motion";
3084 coe {< m_first
= first; m_active
= first >}
3087 method pmotion
x y =
3088 if x < conf.winw
- conf.scrollbw
3091 match self#elemunder
y with
3092 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
3093 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
3097 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3102 Glut.setCursor
Glut.CURSOR_INHERIT
;
3106 method infochanged
_ = ()
3108 method scrollpw
= (0, 0.0, 0.0)
3110 let nfs = fstate.fontsize
+ 1 in
3111 let y = m_first
* nfs in
3112 let itemcount = source#getitemcount
in
3113 let maxi = max
0 (itemcount - fstate.maxrows
) in
3114 let maxy = maxi * nfs in
3115 let p, h = scrollph y maxy in
3119 class outlinelistview ~source
=
3121 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
3125 | 14 -> (* ctrl-n *)
3126 source#narrow m_qsearch
;
3127 G.postRedisplay "outline ctrl-n";
3128 coe {< m_first
= 0; m_active
= 0 >}
3130 | 21 -> (* ctrl-u *)
3132 G.postRedisplay "outline ctrl-u";
3134 coe {< m_first
= 0; m_active
= 0 >}
3136 | 12 -> (* ctrl-l *)
3137 let first = m_active
- (fstate.maxrows
/ 2) in
3138 G.postRedisplay "outline ctrl-l";
3139 coe {< m_first
= first >}
3141 | 127 -> (* delete *)
3142 source#remove m_active
;
3143 G.postRedisplay "outline delete";
3144 let active = max
0 (m_active
-1) in
3145 coe {< m_first
= firstof m_first
active;
3146 m_active
= active >}
3148 | key -> super#
key key
3150 method special
key =
3151 let calcfirst first active =
3154 let rows = active - first in
3155 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3159 let active = m_active
+ incr in
3160 let active = bound active 0 (source#getitemcount
- 1) in
3161 let first = calcfirst m_first
active in
3162 G.postRedisplay "special outline navigate";
3163 coe {< m_active
= active; m_first
= first >}
3166 | Glut.KEY_UP
-> navigate ~
-1
3167 | Glut.KEY_DOWN
-> navigate 1
3168 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
3169 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
3173 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
3175 G.postRedisplay "special outline right";
3176 {< m_pan
= m_pan
+ 1 >}
3178 else self#updownlevel
1
3184 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
3186 G.postRedisplay "special outline left";
3187 {< m_pan
= m_pan
- 1 >}
3189 else self#updownlevel ~
-1
3194 G.postRedisplay "special outline home";
3195 coe {< m_first
= 0; m_active
= 0 >}
3198 let active = source#getitemcount
- 1 in
3199 let first = max
0 (active - fstate.maxrows
) in
3200 G.postRedisplay "special outline end";
3201 coe {< m_active
= active; m_first
= first >}
3203 | _ -> super#special
key
3206 let outlinesource usebookmarks
=
3209 inherit lvsourcebase
3210 val mutable m_items
= empty
3211 val mutable m_orig_items
= empty
3212 val mutable m_prev_items
= empty
3213 val mutable m_narrow_pattern
= ""
3214 val mutable m_hadremovals
= false
3216 method getitemcount
=
3217 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3220 if n == Array.length m_items
&& m_hadremovals
3222 ("[Confirm removal]", 0)
3224 let s, n, _ = m_items
.(n) in
3227 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3228 ignore
(uioh
, first, qsearch);
3229 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3231 if String.length m_narrow_pattern
= 0
3237 if not
confrimremoval
3239 let _, _, anchor = m_items
.(active) in
3244 state.bookmarks
<- Array.to_list m_items
;
3245 m_orig_items
<- m_items
;
3248 else m_items
<- items;
3252 method hasaction
_ = true
3255 if Array.length m_items
!= Array.length m_orig_items
3256 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3259 method narrow
pattern =
3260 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3264 let rec loop accu n =
3267 m_narrow_pattern
<- pattern;
3268 m_items
<- Array.of_list
accu
3271 let (s, _, _) as o = m_items
.(n) in
3273 if (try ignore
(Str.search_forward
re s 0); true
3274 with Not_found
-> false)
3280 loop [] (Array.length m_items
- 1)
3285 then Array.of_list
state.bookmarks
3288 m_items
<- m_orig_items
3293 if m
>= 0 && m
< Array.length m_items
3295 m_hadremovals
<- true;
3296 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3297 let n = if n >= m
then n+1 else n in
3302 method reset
anchor items =
3303 m_hadremovals
<- false;
3304 if m_orig_items
== empty || m_prev_items
!= items
3306 m_orig_items
<- items;
3307 if String.length m_narrow_pattern
= 0
3308 then m_items
<- items;
3310 m_prev_items
<- items;
3311 let rely = getanchory anchor in
3313 let rec loop n best bestd
=
3314 if n = Array.length m_items
3317 let (_, _, anchor) = m_items
.(n) in
3318 let orely = getanchory anchor in
3319 let d = abs
(orely - rely) in
3322 else loop (n+1) best bestd
3327 m_first
<- firstof m_first
active
3331 let enterselector usebookmarks
=
3332 let source = outlinesource usebookmarks
in
3336 then Array.of_list
state.bookmarks
3339 if Array.length
outlines = 0
3341 showtext ' ' errmsg
;
3344 state.text <- source#greetmsg
;
3345 Glut.setCursor
Glut.CURSOR_INHERIT
;
3346 let anchor = getanchor () in
3347 source#reset
anchor outlines;
3348 state.uioh
<- coe (new outlinelistview ~
source);
3349 G.postRedisplay "enter selector";
3353 let enteroutlinemode =
3354 let f = enterselector false in
3355 fun ()-> f "Document has no outline";
3358 let enterbookmarkmode =
3359 let f = enterselector true in
3360 fun () -> f "Document has no bookmarks (yet)";
3363 let color_of_string s =
3364 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3365 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3369 let color_to_string (r, g
, b) =
3370 let r = truncate
(r *. 256.0)
3371 and g
= truncate
(g
*. 256.0)
3372 and b = truncate
(b *. 256.0) in
3373 Printf.sprintf
"%d/%d/%d" r g
b
3376 let irect_of_string s =
3377 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1
y1 -> (x0,y0
,x1
,y1))
3380 let irect_to_string (x0,y0
,x1
,y1) =
3381 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1
y1
3384 let makecheckers () =
3385 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3387 converted by Issac Trotts. July 25, 2002 *)
3388 let image_height = 64
3389 and image_width
= 64 in
3393 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3395 for i
= 0 to image_width
- 1 do
3396 for j
= 0 to image_height - 1 do
3397 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3398 (if (i
land 8 ) lxor (j
land 8) = 0
3399 then [|255;255;255|] else [|200;200;200|])
3404 let image = make_image () in
3405 let id = GlTex.gen_texture
() in
3406 GlTex.bind_texture `texture_2d
id;
3407 GlPix.store
(`unpack_alignment
1);
3408 GlTex.image2d
image;
3409 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3412 `mag_filter `nearest
;
3413 `min_filter `nearest
];
3417 let setcheckers enabled
=
3418 match state.texid
with
3420 if enabled
then state.texid
<- Some
(makecheckers ())
3425 GlTex.delete_texture texid
;
3426 state.texid
<- None
;
3430 let int_of_string_with_suffix s =
3431 let l = String.length
s in
3435 let suffix = Char.lowercase
s.[l-1] in
3437 | 'k'
-> String.sub
s 0 (l-1), 10
3438 | 'm'
-> String.sub
s 0 (l-1), 20
3439 | 'g'
-> String.sub
s 0 (l-1), 30
3443 let n = int_of_string
s1 in
3444 let m = n lsl shift
in
3446 then raise
(Failure
"value too large")
3450 let string_with_suffix_of_int n =
3458 if n land ((1 lsl 20) - 1) = 0
3461 if n land ((1 lsl 10) - 1) = 0
3468 let h = n mod 1000 in
3471 then string_of_int
h ^
s
3473 let s = Printf.sprintf
"_%03d%s" h s in
3480 let defghyllscroll = (40, 8, 32);;
3481 let ghyllscroll_of_string s =
3482 let (n, a, b) as nab
=
3485 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3487 if n <= a || n <= b || a >= b
3488 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3492 let ghyllscroll_to_string ((n, a, b) as nab
) =
3493 if nab
= defghyllscroll
3495 else Printf.sprintf
"%d,%d,%d" n a b;
3498 let describe_location () =
3500 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3502 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3503 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3507 else (100. *. (float state.y /. float maxy))
3511 Printf.sprintf
"page %d of %d [%.2f%%]"
3512 (fn+1) state.pagecount
percent
3515 "pages %d-%d of %d [%.2f%%]"
3516 (fn+1) (ln
+1) state.pagecount
percent
3520 let btos b = if b then "\xe2\x88\x9a" else "" in
3521 let showextended = ref false in
3522 let leave mode
= function
3523 | Confirm
-> state.mode
<- mode
3524 | Cancel
-> state.mode
<- mode
in
3527 val mutable m_first_time
= true
3528 val mutable m_l
= []
3529 val mutable m_a
= [||]
3530 val mutable m_prev_uioh
= nouioh
3531 val mutable m_prev_mode
= View
3533 inherit lvsourcebase
3535 method reset prev_mode prev_uioh
=
3536 m_a
<- Array.of_list
(List.rev m_l
);
3538 m_prev_mode
<- prev_mode
;
3539 m_prev_uioh
<- prev_uioh
;
3543 if n >= Array.length m_a
3547 | _, _, _, Action
_ -> m_active
<- n
3551 m_first_time
<- false;
3554 method int name get
set =
3556 (name
, `
int get
, 1, Action
(
3559 try set (int_of_string
s)
3561 state.text <- Printf.sprintf
"bad integer `%s': %s"
3562 s (Printexc.to_string exn
)
3565 let te = name ^
": ", "", None
, intentry, ondone in
3566 state.mode
<- Textentry
(te, leave m_prev_mode
);
3570 method int_with_suffix name get
set =
3572 (name
, `intws get
, 1, Action
(
3575 try set (int_of_string_with_suffix s)
3577 state.text <- Printf.sprintf
"bad integer `%s': %s"
3578 s (Printexc.to_string exn
)
3582 name ^
": ", "", None
, intentry_with_suffix, ondone
3584 state.mode
<- Textentry
(te, leave m_prev_mode
);
3588 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3590 (name
, `
bool (btos, get
), offset
, Action
(
3597 method color name get
set =
3599 (name
, `color get
, 1, Action
(
3601 let invalid = (nan
, nan
, nan
) in
3604 try color_of_string s
3606 state.text <- Printf.sprintf
"bad color `%s': %s"
3607 s (Printexc.to_string exn
);
3613 let te = name ^
": ", "", None
, textentry, ondone in
3614 state.text <- color_to_string (get
());
3615 state.mode
<- Textentry
(te, leave m_prev_mode
);
3619 method string name get
set =
3621 (name
, `
string get
, 1, Action
(
3623 let ondone s = set s in
3624 let te = name ^
": ", "", None
, textentry, ondone in
3625 state.mode
<- Textentry
(te, leave m_prev_mode
);
3629 method colorspace name get
set =
3631 (name
, `
string get
, 1, Action
(
3634 let vals = [| "rgb"; "bgr"; "gray" |] in
3636 inherit lvsourcebase
3639 m_active
<- int_of_colorspace conf.colorspace
;
3642 method getitemcount
= Array.length
vals
3643 method getitem
n = (vals.(n), 0)
3644 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3645 ignore
(uioh
, first, pan
, qsearch);
3646 if not cancel
then set active;
3648 method hasaction
_ = true
3652 coe (new listview ~
source ~trusted
:true)
3655 method caption
s offset
=
3656 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3658 method caption2
s f offset
=
3659 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3661 method getitemcount
= Array.length m_a
3664 let tostr = function
3665 | `
int f -> string_of_int
(f ())
3666 | `intws
f -> string_with_suffix_of_int (f ())
3668 | `color
f -> color_to_string (f ())
3669 | `
bool (btos, f) -> btos (f ())
3672 let name, t
, offset
, _ = m_a
.(n) in
3673 ((let s = tostr t
in
3674 if String.length
s > 0
3675 then Printf.sprintf
"%s\t%s" name s
3679 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3683 m_qsearch
<- qsearch;
3685 match m_a
.(active) with
3686 | _, _, _, Action
f -> f uioh
3698 method hasaction
n =
3700 | _, _, _, Action
_ -> true
3704 let rec fillsrc prevmode prevuioh
=
3705 let sep () = src#caption
"" 0 in
3706 let colorp name get
set =
3708 (fun () -> color_to_string (get
()))
3711 let c = color_of_string v in
3714 state.text <- Printf.sprintf
"bad color `%s': %s"
3715 v (Printexc.to_string exn
);
3718 let oldmode = state.mode
in
3719 let birdseye = isbirdseye state.mode
in
3721 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3723 src#
bool "presentation mode"
3724 (fun () -> conf.presentation)
3726 conf.presentation <- v;
3727 state.anchor <- getanchor ();
3730 src#
bool "ignore case in searches"
3731 (fun () -> conf.icase
)
3732 (fun v -> conf.icase
<- v);
3735 (fun () -> conf.preload)
3736 (fun v -> conf.preload <- v);
3738 src#
bool "highlight links"
3739 (fun () -> conf.hlinks
)
3740 (fun v -> conf.hlinks
<- v);
3742 src#
bool "under info"
3743 (fun () -> conf.underinfo
)
3744 (fun v -> conf.underinfo
<- v);
3746 src#
bool "persistent bookmarks"
3747 (fun () -> conf.savebmarks
)
3748 (fun v -> conf.savebmarks
<- v);
3750 src#
bool "proportional display"
3751 (fun () -> conf.proportional
)
3752 (fun v -> reqlayout conf.angle
v);
3754 src#
bool "trim margins"
3755 (fun () -> conf.trimmargins
)
3756 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3758 src#
bool "persistent location"
3759 (fun () -> conf.jumpback
)
3760 (fun v -> conf.jumpback
<- v);
3763 src#
int "inter-page space"
3764 (fun () -> conf.interpagespace)
3766 conf.interpagespace <- n;
3768 match state.layout with
3773 state.maxy <- calcheight ();
3774 let y = getpagey pageno in
3779 (fun () -> conf.pagebias
)
3780 (fun v -> conf.pagebias
<- v);
3782 src#
int "scroll step"
3783 (fun () -> conf.scrollstep
)
3784 (fun n -> conf.scrollstep
<- n);
3786 src#
int "auto scroll step"
3788 match state.autoscroll
with
3790 | _ -> conf.autoscrollstep
)
3792 if state.autoscroll
<> None
3793 then state.autoscroll
<- Some
n;
3794 conf.autoscrollstep
<- n);
3797 (fun () -> truncate
(conf.zoom *. 100.))
3798 (fun v -> setzoom ((float v) /. 100.));
3801 (fun () -> conf.angle
)
3802 (fun v -> reqlayout v conf.proportional
);
3804 src#
int "scroll bar width"
3805 (fun () -> state.scrollw
)
3809 reshape conf.winw
conf.winh
;
3812 src#
int "scroll handle height"
3813 (fun () -> conf.scrollh
)
3814 (fun v -> conf.scrollh
<- v;);
3816 src#
int "thumbnail width"
3817 (fun () -> conf.thumbw
)
3819 conf.thumbw
<- min
4096 v;
3822 leavebirdseye beye
false;
3827 src#
string "columns"
3829 match conf.columns
with
3831 | Some
(multicol
, _) -> columns_to_string multicol
)
3833 let n, a, b = columns_of_string v in
3837 src#caption
"Presentation mode" 0;
3838 src#
bool "scrollbar visible"
3839 (fun () -> conf.scrollbarinpm
)
3841 if v != conf.scrollbarinpm
3843 conf.scrollbarinpm
<- v;
3844 if conf.presentation
3846 state.scrollw
<- if v then conf.scrollbw
else 0;
3847 reshape conf.winw
conf.winh
;
3853 src#caption
"Pixmap cache" 0;
3854 src#int_with_suffix
"size (advisory)"
3855 (fun () -> conf.memlimit
)
3856 (fun v -> conf.memlimit
<- v);
3859 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3860 (string_with_suffix_of_int state.memused
)
3861 (Hashtbl.length
state.tilemap
)) 1;
3864 src#caption
"Layout" 0;
3865 src#caption2
"Dimension"
3867 Printf.sprintf
"%dx%d (virtual %dx%d)"
3873 src#caption2
"Position" (fun () ->
3874 Printf.sprintf
"%dx%d" state.x state.y
3877 src#caption2
"Visible" (fun () -> describe_location ()) 1
3881 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3882 "Save these parameters as global defaults at exit"
3883 (fun () -> conf.bedefault
)
3884 (fun v -> conf.bedefault
<- v)
3888 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3889 src#
bool ~offset
:0 ~
btos "Extended parameters"
3890 (fun () -> !showextended)
3891 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3895 (fun () -> conf.checkers
)
3896 (fun v -> conf.checkers
<- v; setcheckers v);
3898 (fun () -> conf.verbose
)
3899 (fun v -> conf.verbose
<- v);
3900 src#
bool "invert colors"
3901 (fun () -> conf.invert
)
3902 (fun v -> conf.invert
<- v);
3904 (fun () -> conf.maxhfit
)
3905 (fun v -> conf.maxhfit
<- v);
3908 src#
bool "redirect stderr"
3909 (fun () -> conf.redirectstderr)
3910 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3911 src#
string "uri launcher"
3912 (fun () -> conf.urilauncher
)
3913 (fun v -> conf.urilauncher
<- v);
3914 src#
string "tile size"
3915 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3918 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3919 conf.tileh
<- max
64 w;
3920 conf.tilew
<- max
64 h;
3923 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3924 v (Printexc.to_string exn
));
3925 src#
int "texture count"
3926 (fun () -> conf.texcount
)
3929 then conf.texcount
<- v
3930 else showtext '
!'
" Failed to set texture count please retry later"
3932 src#
int "slice height"
3933 (fun () -> conf.sliceheight
)
3935 conf.sliceheight
<- v;
3936 wcmd "sliceh" [`i
conf.sliceheight
];
3938 src#
int "anti-aliasing level"
3939 (fun () -> conf.aalevel
)
3941 conf.aalevel
<- bound v 0 8;
3942 state.anchor <- getanchor ();
3943 opendoc state.path
state.password
;
3945 src#
int "ui font size"
3946 (fun () -> fstate.fontsize
)
3947 (fun v -> setfontsize (bound v 5 100));
3948 colorp "background color"
3949 (fun () -> conf.bgcolor
)
3950 (fun v -> conf.bgcolor
<- v);
3951 src#
bool "crop hack"
3952 (fun () -> conf.crophack
)
3953 (fun v -> conf.crophack
<- v);
3954 src#
string "trim fuzz"
3955 (fun () -> irect_to_string conf.trimfuzz
)
3958 conf.trimfuzz
<- irect_of_string v;
3960 then settrim true conf.trimfuzz
;
3962 state.text <- Printf.sprintf
"bad irect `%s': %s"
3963 v (Printexc.to_string exn
)
3965 src#
string "throttle"
3967 match conf.maxwait
with
3968 | None
-> "show place holder if page is not ready"
3971 then "wait for page to fully render"
3973 "wait " ^ string_of_float
time
3974 ^
" seconds before showing placeholder"
3978 let f = float_of_string
v in
3980 then conf.maxwait
<- None
3981 else conf.maxwait
<- Some
f
3983 state.text <- Printf.sprintf
"bad time `%s': %s"
3984 v (Printexc.to_string exn
)
3986 src#
string "ghyll scroll"
3988 match conf.ghyllscroll
with
3990 | Some nab
-> ghyllscroll_to_string nab
3995 if String.length
v = 0
3997 else Some
(ghyllscroll_of_string v)
3999 conf.ghyllscroll
<- gs
4001 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4002 v (Printexc.to_string exn
)
4004 src#
string "selection command"
4005 (fun () -> conf.selcmd
)
4006 (fun v -> conf.selcmd
<- v);
4007 src#colorspace
"color space"
4008 (fun () -> colorspace_to_string conf.colorspace
)
4010 conf.colorspace
<- colorspace_of_int v;
4017 src#caption
"Document" 0;
4018 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4019 src#caption2
"Pages"
4020 (fun () -> string_of_int
state.pagecount
) 1;
4021 src#caption2
"Dimensions"
4022 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4026 src#caption
"Trimmed margins" 0;
4027 src#caption2
"Dimensions"
4028 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4031 src#reset prevmode prevuioh
;
4035 let prevmode = state.mode
4036 and prevuioh
= state.uioh in
4037 fillsrc prevmode prevuioh
;
4038 let source = (src :> lvsource
) in
4039 state.uioh <- coe (object (self)
4040 inherit listview ~
source ~trusted
:true as super
4041 val mutable m_prevmemused
= 0
4042 method infochanged
= function
4044 if m_prevmemused
!= state.memused
4046 m_prevmemused
<- state.memused
;
4047 G.postRedisplay "memusedchanged";
4049 | Pdim
-> G.postRedisplay "pdimchanged"
4050 | Docinfo
-> fillsrc prevmode prevuioh
4052 method special
key =
4053 if Glut.getModifiers
() land Glut.active_ctrl
= 0
4056 | Glut.KEY_LEFT
-> coe (self#updownlevel ~
-1)
4057 | Glut.KEY_RIGHT
-> coe (self#updownlevel
1)
4058 | _ -> super#special
key
4059 else super#special
key
4061 G.postRedisplay "info";
4067 inherit lvsourcebase
4068 method getitemcount
= Array.length
state.help
4070 let s, n, _ = state.help
.(n) in
4073 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4077 m_qsearch
<- qsearch;
4078 match state.help
.(active) with
4079 | _, _, Action
f -> Some
(f uioh)
4089 method hasaction
n =
4090 match state.help
.(n) with
4091 | _, _, Action
_ -> true
4098 state.uioh <- coe (new listview ~
source ~trusted
:true);
4099 G.postRedisplay "help";
4104 let re = Str.regexp
"[\r\n]" in
4106 inherit lvsourcebase
4107 val mutable m_items
= [||]
4109 method getitemcount
= 1 + Array.length m_items
4114 else m_items
.(n-1), 0
4116 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4121 then Buffer.clear
state.errmsgs
;
4122 m_qsearch
<- qsearch;
4129 method hasaction
n =
4133 state.newerrmsgs
<- false;
4134 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4135 m_items
<- Array.of_list
l
4143 let source = (msgsource :> lvsource
) in
4144 state.uioh <- coe (object
4145 inherit listview ~
source ~trusted
:false as super
4148 then msgsource#reset
;
4151 G.postRedisplay "msgs";
4154 let quickbookmark ?title
() =
4155 match state.layout with
4161 let sec = Unix.gettimeofday
() in
4162 let tm = Unix.localtime
sec in
4163 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4167 (tm.Unix.tm_year
+ 1900)
4170 | Some
title -> title
4173 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4178 state.fullscreen
<- None
;
4179 Glut.reshapeWindow
w h;
4182 let viewkeyboard key =
4184 let mode = state.mode in
4185 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4188 G.postRedisplay "view:enttext"
4190 let c = Char.chr
key in
4192 | '
\027'
| 'q'
-> (* escape *)
4193 begin match state.mstate
with
4195 state.mstate
<- Mnone
;
4196 Glut.setCursor
Glut.CURSOR_INHERIT
;
4197 G.postRedisplay "kill zoom rect";
4199 match state.ranchors
with
4201 | (path
, password
, anchor) :: rest
->
4202 state.ranchors
<- rest
;
4203 state.anchor <- anchor;
4204 opendoc path password
4207 | '
\008'
-> (* backspace *)
4208 let y = getnav ~
-1 in
4209 gotoy_and_clear_text y
4217 G.postRedisplay "dehighlight";
4220 let ondone isforw
s =
4221 cbput state.hists
.pat
s;
4222 state.searchpattern
<- s;
4225 let s = String.create
1 in
4227 enttext (s, "", Some
(onhist state.hists
.pat
),
4228 textentry, ondone (c ='
/'
))
4230 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4231 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4232 setzoom (conf.zoom +. incr)
4237 try int_of_string
s with exc
->
4238 state.text <- Printf.sprintf
"bad integer `%s': %s"
4239 s (Printexc.to_string exc
);
4245 state.text <- "page bias is now " ^ string_of_int
n;
4248 enttext ("page bias: ", "", None
, intentry, ondone)
4250 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4251 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4252 setzoom (max
0.01 (conf.zoom -. decr))
4255 let ondone msg
= state.text <- msg
in
4257 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4258 optentry state.mode, ondone
4261 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4264 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4265 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4269 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4275 try int_of_string
s with exc
->
4276 state.text <- Printf.sprintf
"bad integer `%s': %s"
4277 s (Printexc.to_string exc
);
4283 cbput state.hists
.pag
(string_of_int
n);
4284 gotopage1 (n + conf.pagebias
- 1) 0;
4287 let pageentry text key =
4288 match Char.unsafe_chr
key with
4289 | 'g'
-> TEdone
text
4290 | _ -> intentry text key
4292 let text = "x" in text.[0] <- c;
4293 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4296 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4297 reshape conf.winw
conf.winh
;
4300 conf.hlinks
<- not
conf.hlinks
;
4301 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4302 G.postRedisplay "toggle highlightlinks";
4305 begin match state.autoscroll
with
4307 conf.autoscrollstep
<- step
;
4308 state.autoscroll
<- None
4310 if conf.autoscrollstep
= 0
4311 then state.autoscroll
<- Some
1
4312 else state.autoscroll
<- Some
conf.autoscrollstep
4316 conf.presentation <- not
conf.presentation;
4317 if conf.presentation
4319 if not
conf.scrollbarinpm
4320 then state.scrollw
<- 0;
4323 state.scrollw
<- conf.scrollbw
;
4325 showtext ' '
("presentation mode " ^
4326 if conf.presentation then "on" else "off");
4327 state.anchor <- getanchor ();
4331 begin match state.fullscreen
with
4333 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4336 state.fullscreen
<- None
;
4341 gotoy_and_clear_text 0
4344 gotopage1 (state.pagecount
- 1) 0
4347 search state.searchpattern
true
4350 search state.searchpattern
false
4353 begin match state.layout with
4356 gotoy_and_clear_text (getpagey l.pageno)
4360 begin match List.rev
state.layout with
4363 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4364 gotoy_and_clear_text (getpagey pageno)
4367 | '
\127'
-> (* del *)
4368 begin match state.layout with
4371 let pageno = max
0 (l.pageno-1) in
4372 gotoy_and_clear_text (getpagey pageno)
4376 showtext ' '
(describe_location ());
4379 begin match state.layout with
4382 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4387 enterbookmarkmode ()
4395 | '
e'
when conf.redirectstderr || is_gui ->
4400 match state.layout with
4403 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4407 enttext ("bookmark: ", "", None
, textentry, ondone)
4411 showtext ' '
"Quick bookmark added";
4414 begin match state.layout with
4416 let rect = getpdimrect
l.pagedimno
in
4420 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4421 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4423 (truncate
(rect.(1) -. rect.(0)),
4424 truncate
(rect.(3) -. rect.(0)))
4426 let w = truncate
((float w)*.conf.zoom)
4427 and h = truncate
((float h)*.conf.zoom) in
4430 state.anchor <- getanchor ();
4431 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4433 G.postRedisplay "z";
4438 | '
\000'
-> (* ctrl-2 *)
4439 let maxw = getmaxw
() in
4441 then setzoom (maxw /. float conf.winw
)
4444 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
4448 bound (conf.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
4450 G.postRedisplay "brightness";
4453 begin match state.mode with
4454 | Birdseye beye
-> upbirdseye 1 beye
4455 | _ -> gotoy (clamp (-conf.scrollstep
))
4459 begin match state.mode with
4460 | Birdseye beye
-> downbirdseye 1 beye
4461 | _ -> gotoy (clamp conf.scrollstep
)
4465 state.anchor <- getanchor ();
4466 opendoc state.path
state.password
4468 | '
v'
when not
conf.debug
->
4469 List.iter
debugl state.layout;
4471 | '
v'
when conf.debug
->
4474 match getopaque l.pageno with
4477 let x0, y0
, x1
, y1 = pagebbox opaque
in
4478 let a,b = float x0, float y0
in
4479 let c,d = float x1
, float y0
in
4480 let e,f = float x1
, float y1 in
4481 let h,j
= float x0, float y1 in
4482 let rect = (a,b,c,d,e,f,h,j
) in
4484 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4486 G.postRedisplay "v";
4489 vlog "huh? %d %c" key (Char.chr
key);
4492 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
4494 | 27 -> (* escape *)
4495 leavebirdseye beye
true
4497 | 12 -> (* ctrl-l *)
4498 let y, h = getpageyh pageno in
4499 let top = (conf.winh
- h) / 2 in
4500 gotoy (max
0 (y - top))
4503 leavebirdseye beye
false
4509 let keyboard ~
key ~
x ~
y =
4512 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
4513 then wcmd "interrupt" []
4514 else state.uioh <- state.uioh#
key key
4517 let birdseyespecial key ((oconf
, leftx
, _, hooverpageno
, anchor) as beye
) =
4519 match conf.columns
with
4521 | Some
((c, _, _), _) -> c
4524 | Glut.KEY_UP
-> upbirdseye incr beye
4525 | Glut.KEY_DOWN
-> downbirdseye incr beye
4526 | Glut.KEY_LEFT
-> upbirdseye 1 beye
4527 | Glut.KEY_RIGHT
-> downbirdseye 1 beye
4529 | Glut.KEY_PAGE_UP
->
4530 begin match state.layout with
4534 state.mode <- Birdseye
(
4535 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4537 gotopage1 l.pageno 0;
4540 let layout = layout (state.y-conf.winh
) conf.winh
in
4542 | [] -> gotoy (clamp (-conf.winh
))
4544 state.mode <- Birdseye
(
4545 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4547 gotopage1 l.pageno 0
4550 | [] -> gotoy (clamp (-conf.winh
))
4553 | Glut.KEY_PAGE_DOWN
->
4554 begin match List.rev
state.layout with
4556 let layout = layout (state.y + conf.winh
) conf.winh
in
4557 begin match layout with
4559 let incr = l.pageh
- l.pagevh in
4564 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4566 G.postRedisplay "birdseye pagedown";
4568 else gotoy (clamp (incr + conf.interpagespace*2));
4572 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4573 gotopage1 l.pageno 0;
4576 | [] -> gotoy (clamp conf.winh
)
4580 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4584 let pageno = state.pagecount
- 1 in
4585 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4586 if not
(pagevisible state.layout pageno)
4589 match List.rev
state.pdims
with
4591 | (_, _, h, _) :: _ -> h
4593 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4594 else G.postRedisplay "birdseye end";
4598 let setautoscrollspeed step goingdown
=
4599 let incr = max
1 ((abs step
) / 2) in
4600 let incr = if goingdown
then incr else -incr in
4601 let astep = step
+ incr in
4602 state.autoscroll
<- Some
astep;
4605 let special ~
key ~
x ~
y =
4608 state.uioh <- state.uioh#
special key
4613 match state.mode with
4614 | Textentry
_ -> scalecolor 0.4
4615 | View
-> scalecolor 1.0
4616 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4617 if l.pageno = hooverpageno
4620 if l.pageno = pageno
4626 begin match getopaque l.pageno with
4628 if tileready l l.pagex l.pagey
4630 let x = l.pagedispx - l.pagex
4631 and y = l.pagedispy - l.pagey in
4632 postprocess opaque
conf.hlinks
x y;
4638 let scrollindicator () =
4639 let sbw, ph
, sh = state.uioh#
scrollph in
4640 let sbh, pw
, sw = state.uioh#scrollpw
in
4642 GlDraw.color (0.64, 0.64, 0.64);
4644 (float (conf.winw
- sbw), 0.)
4645 (float conf.winw
, float conf.winh
)
4648 (0., float (conf.winh
- sbh))
4649 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4651 GlDraw.color (0.0, 0.0, 0.0);
4654 (float (conf.winw
- sbw), ph
)
4655 (float conf.winw
, ph
+. sh)
4658 (pw
, float (conf.winh
- sbh))
4659 (pw
+. sw, float conf.winh
)
4663 let pagetranslatepoint l x y =
4664 let dy = y - l.pagedispy in
4665 let y = dy + l.pagey in
4666 let dx = x - l.pagedispx in
4667 let x = dx + l.pagex in
4672 match state.mstate
with
4673 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4676 | Msel
((x0, y0
), (x1
, y1)) ->
4677 let rec loop = function
4679 if ((y0
>= l.pagedispy && y0
<= (l.pagedispy + l.pagevh))
4680 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4681 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4682 || ((x1
>= l.pagedispx && x1
<= (l.pagedispx + l.pagevw))))
4684 match getopaque l.pageno with
4686 let dx, dy = pagetranslatepoint l 0 0 in
4691 GlMat.mode `modelview
;
4693 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4694 seltext opaque
(x0, y0
, x1
, y1);
4705 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4706 GlDraw.polygon_mode `both `fill
;
4707 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4709 (fun (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) ->
4711 if l.pageno = pageno
4713 let dx = float (l.pagedispx - l.pagex) in
4714 let dy = float (l.pagedispy - l.pagey) in
4715 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4716 GlDraw.begins `quads
;
4718 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4719 GlDraw.vertex2
(x1
+.dx, y1+.dy);
4720 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4721 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4732 GlClear.color (scalecolor2 conf.bgcolor
);
4733 GlClear.clear
[`
color];
4734 List.iter
drawpage state.layout;
4739 begin match state.mstate
with
4740 | Mzoomrect
((x0, y0
), (x1
, y1)) ->
4742 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4743 GlDraw.polygon_mode `both `fill
;
4744 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4745 GlDraw.rect (float x0, float y0
)
4746 (float x1
, float y1);
4751 Glut.swapBuffers
();
4755 let rec f = function
4757 begin match getopaque l.pageno with
4759 let x0 = l.pagedispx in
4760 let x1 = x0 + l.pagevw in
4761 let y0 = l.pagedispy in
4762 let y1 = y0 + l.pagevh in
4763 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4765 let px, py = pagetranslatepoint l x y in
4766 match whatsunder opaque
px py with
4778 let zoomrect x y x1 y1 =
4781 and y0 = min
y y1 in
4782 gotoy (state.y + y0);
4783 state.anchor <- getanchor ();
4784 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4786 if state.w < conf.winw
- state.scrollw
4787 then (conf.winw
- state.scrollw
- state.w) / 2
4790 state.x <- (state.x + margin) - x0;
4792 Glut.setCursor
Glut.CURSOR_INHERIT
;
4793 state.mstate
<- Mnone
;
4797 let winw = conf.winw - state.scrollw
- 1 in
4798 let s = float x /. float winw in
4799 let destx = truncate
(float (state.w + winw) *. s) in
4800 state.x <- winw - destx;
4801 gotoy_and_clear_text state.y;
4802 state.mstate
<- Mscrollx
;
4806 let s = float y /. float conf.winh
in
4807 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4808 gotoy_and_clear_text desty;
4809 state.mstate
<- Mscrolly
;
4812 let viewmouse button bstate
x y =
4814 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4815 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4817 match state.mstate
with
4818 | Mzoom
(oldn
, i
) ->
4826 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4828 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4830 let zoom = conf.zoom -. incr in
4832 state.mstate
<- Mzoom
(n, 0);
4834 state.mstate
<- Mzoom
(n, i
+1);
4836 else state.mstate
<- Mzoom
(n, 0)
4838 | _ -> state.mstate
<- Mzoom
(n, 0)
4841 match state.autoscroll
with
4842 | Some step
-> setautoscrollspeed step
(n=4)
4846 then -conf.scrollstep
4847 else conf.scrollstep
4849 let incr = incr * 2 in
4850 let y = clamp incr in
4851 gotoy_and_clear_text y
4854 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4855 if bstate
= Glut.DOWN
4857 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4858 state.mstate
<- Mpan
(x, y)
4861 state.mstate
<- Mnone
4863 | Glut.RIGHT_BUTTON
->
4864 if bstate
= Glut.DOWN
4866 Glut.setCursor
Glut.CURSOR_CYCLE
;
4868 state.mstate
<- Mzoomrect
(p, p)
4871 match state.mstate
with
4872 | Mzoomrect
((x0, y0), _) ->
4873 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4874 then zoomrect x0 y0 x y
4876 state.mstate
<- Mnone
;
4877 Glut.setCursor
Glut.CURSOR_INHERIT
;
4878 G.postRedisplay "kill accidental zoom rect";
4881 Glut.setCursor
Glut.CURSOR_INHERIT
;
4882 state.mstate
<- Mnone
4885 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4886 if bstate
= Glut.DOWN
4888 let _, position, sh = state.uioh#
scrollph in
4889 if y > truncate
position && y < truncate
(position +. sh)
4890 then state.mstate
<- Mscrolly
4893 state.mstate
<- Mnone
4895 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4896 if bstate
= Glut.DOWN
4898 let _, position, sw = state.uioh#scrollpw
in
4899 if x > truncate
position && x < truncate
(position +. sw)
4900 then state.mstate
<- Mscrollx
4903 state.mstate
<- Mnone
4905 | Glut.LEFT_BUTTON
->
4906 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4907 begin match dest with
4908 | Ulinkgoto
(pageno, top) ->
4912 gotopage1 pageno top;
4918 | Uremote
(filename
, pageno) ->
4920 if Sys.file_exists filename
4923 let dir = Filename.dirname
state.path in
4924 let path = Filename.concat
dir filename
in
4925 if Sys.file_exists
path
4929 if String.length
path > 0
4931 let anchor = getanchor () in
4932 let ranchor = state.path, state.password
, anchor in
4933 state.anchor <- (pageno, 0.0);
4934 state.ranchors
<- ranchor :: state.ranchors
;
4937 else showtext '
!'
("Could not find " ^ filename
)
4939 | Uunexpected
_ | Ulaunch
_ | Unamed
_ -> ()
4941 | Unone
when bstate
= Glut.DOWN
->
4942 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4943 state.mstate
<- Mpan
(x, y);
4945 | Unone
| Utext
_ ->
4946 if bstate
= Glut.DOWN
4948 if conf.angle
mod 360 = 0
4950 state.mstate
<- Msel
((x, y), (x, y));
4951 G.postRedisplay "mouse select";
4955 match state.mstate
with
4958 | Mzoom
_ | Mscrollx
| Mscrolly
->
4959 state.mstate
<- Mnone
4961 | Mzoomrect
((x0, y0), _) ->
4965 Glut.setCursor
Glut.CURSOR_INHERIT
;
4966 state.mstate
<- Mnone
4968 | Msel
((_, y0), (_, y1)) ->
4969 let rec loop = function
4972 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4973 || ((y1 >= l.pagedispy
4974 && y1 <= (l.pagedispy + l.pagevh)))
4976 match getopaque l.pageno with
4978 copysel
conf.selcmd opaque
;
4979 G.postRedisplay "copysel"
4984 Glut.setCursor
Glut.CURSOR_INHERIT
;
4985 state.mstate
<- Mnone
;
4992 let birdseyemouse button bstate
x y
4993 (conf, leftx
, _, hooverpageno
, anchor) =
4995 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4996 let rec loop = function
4999 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5000 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5002 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5007 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
5011 let mouse bstate button
x y =
5012 state.uioh <- state.uioh#button button bstate
x y;
5015 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
5018 state.uioh <- state.uioh#
motion x y
5022 state.uioh <- state.uioh#
pmotion x y;
5029 begin match state.mode with
5030 | Textentry
textentry -> textentrykeyboard key textentry
5031 | Birdseye
birdseye -> birdseyekeyboard key birdseye
5032 | View
-> viewkeyboard key
5036 method special key =
5037 begin match state.mode with
5038 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
5042 birdseyespecial key vals
5044 | View
when key = Glut.KEY_F1
->
5048 begin match state.autoscroll
with
5049 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
5050 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
5055 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
5057 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
5059 if Glut.getModifiers
() land Glut.active_shift
!= 0
5060 then (setzoom state.prevzoom
; state.y)
5061 else clamp (-conf.winh
/2)
5062 else clamp (-conf.scrollstep
)
5064 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
5066 if Glut.getModifiers
() land Glut.active_shift
!= 0
5067 then (setzoom state.prevzoom
; state.y)
5068 else clamp (conf.winh
/2)
5069 else clamp (conf.scrollstep
)
5070 | Glut.KEY_PAGE_UP
->
5071 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
5073 match state.layout with
5075 | l :: _ -> state.y - l.pagey
5078 | Glut.KEY_PAGE_DOWN
->
5079 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
5081 match List.rev
state.layout with
5083 | l :: _ -> getpagey l.pageno
5091 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
5093 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
5094 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
5095 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
5097 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
5099 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
5100 then (conf.winw / 2)
5103 state.x <- state.x - dx;
5105 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
5107 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
5108 then (conf.winw / 2)
5111 state.x <- state.x + dx;
5116 if abs
(state.y - y) > conf.scrollstep
*2
5118 else gotoy_and_clear_text y
5121 | Textentry
te -> textentryspecial key te
5125 method button button bstate
x y =
5126 begin match state.mode with
5127 | View
-> viewmouse button bstate
x y
5128 | Birdseye beye
-> birdseyemouse button bstate
x y beye
5134 begin match state.mode with
5136 | View
| Birdseye
_ ->
5137 match state.mstate
with
5138 | Mzoom
_ | Mnone
-> ()
5143 state.mstate
<- Mpan
(x, y);
5144 if conf.zoom > 1.0 then state.x <- state.x + dx;
5146 gotoy_and_clear_text y
5149 state.mstate
<- Msel
(a, (x, y));
5150 G.postRedisplay "motion select";
5153 let y = min
conf.winh
(max
0 y) in
5157 let x = min
conf.winw (max
0 x) in
5160 | Mzoomrect
(p0
, _) ->
5161 state.mstate
<- Mzoomrect
(p0
, (x, y));
5162 G.postRedisplay "motion zoomrect";
5166 method pmotion x y =
5167 begin match state.mode with
5168 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5169 let rec loop = function
5171 if hooverpageno
!= -1
5173 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5174 G.postRedisplay "pmotion birdseye no hoover";
5177 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5178 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5180 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5181 G.postRedisplay "pmotion birdseye hoover";
5190 match state.mstate
with
5192 begin match getunder x y with
5193 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
5195 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
5196 Glut.setCursor
Glut.CURSOR_INFO
5197 | Ulinkgoto
(page
, _) ->
5199 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
5200 Glut.setCursor
Glut.CURSOR_INFO
5202 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
5203 Glut.setCursor
Glut.CURSOR_TEXT
5205 if conf.underinfo
then showtext 'u'
("nexpected: " ^
s);
5206 Glut.setCursor
Glut.CURSOR_INHERIT
5208 if conf.underinfo
then showtext '
l'
("launch: " ^
s);
5209 Glut.setCursor
Glut.CURSOR_INHERIT
5211 if conf.underinfo
then showtext '
n'
("named: " ^
s);
5212 Glut.setCursor
Glut.CURSOR_INHERIT
5213 | Uremote
(filename
, pageno) ->
5214 if conf.underinfo
then showtext '
r'
5215 (Printf.sprintf
"emote: %s (%d)" filename
pageno);
5216 Glut.setCursor
Glut.CURSOR_INFO
5219 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5224 method infochanged
_ = ()
5227 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5228 let p, h = scrollph state.y maxy in
5232 let winw = conf.winw - state.scrollw
- 1 in
5233 let fwinw = float winw in
5235 let sw = fwinw /. float state.w in
5236 let sw = fwinw *. sw in
5237 max
sw (float conf.scrollh
)
5240 let f = state.w+winw in
5241 let r = float (winw-state.x) /. float f in
5242 let p = fwinw *. r in
5246 if position +. sw > fwinw
5247 then fwinw -. position
5250 state.hscrollh, position, sw
5257 let fontpath = ref "";;
5258 let wmclasshack = ref false;;
5261 let l = String.length
s in
5262 let b = Buffer.create
l in
5270 then Sys.getenv
"HOMEPATH"
5271 else Sys.getenv
"HOME"
5274 ("Can not determine home directory location: " ^
5275 Printexc.to_string exn
);
5279 let config_of c attrs
=
5283 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5284 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5285 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5286 | "preload" -> { c with preload = bool_of_string
v }
5287 | "page-bias" -> { c with pagebias
= int_of_string
v }
5288 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5289 | "auto-scroll-step" ->
5290 { c with autoscrollstep
= max
0 (int_of_string
v) }
5291 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5292 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5295 match String.lowercase
v with
5296 | "true" -> Some infinity
5298 | f -> Some
(float_of_string
f)
5300 { c with maxwait
= mw}
5301 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5302 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5303 | "vertical-margin" ->
5304 { c with interpagespace = max
0 (int_of_string
v) }
5306 let zoom = float_of_string
v /. 100. in
5307 let zoom = max
zoom 0.0 in
5308 { c with zoom = zoom }
5309 | "presentation" -> { c with presentation = bool_of_string
v }
5310 | "rotation-angle" -> { c with angle
= int_of_string
v }
5311 | "width" -> { c with winw = max
20 (int_of_string
v) }
5312 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5313 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5314 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5315 | "pixmap-cache-size" ->
5316 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5317 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5318 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5319 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5320 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5321 | "background-color" -> { c with bgcolor
= color_of_string v }
5322 | "scrollbar-in-presentation" ->
5323 { c with scrollbarinpm
= bool_of_string
v }
5324 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5325 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5326 | "mupdf-store-size" ->
5327 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5328 | "checkers" -> { c with checkers
= bool_of_string
v }
5329 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5330 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5331 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5332 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
5333 | "uri-launcher" -> { c with urilauncher
= unent v }
5334 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5335 | "invert-colors" -> { c with invert
= bool_of_string
v }
5336 | "brightness" -> { c with colorscale
= float_of_string
v }
5337 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5339 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5341 let nab = columns_of_string v in
5342 { c with columns
= Some
(nab, [||]) }
5343 | "birds-eye-columns" ->
5344 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5345 | "selection-command" -> { c with selcmd
= unent v }
5348 prerr_endline
("Error processing attribute (`" ^
5349 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5352 let rec fold c = function
5355 let c = apply c k
v in
5361 let fromstring f pos
n v d =
5364 dolog "Error processing attribute (%S=%S) at %d\n%s"
5365 n v pos
(Printexc.to_string exn
)
5370 let bookmark_of attrs
=
5371 let rec fold title page
rely = function
5372 | ("title", v) :: rest
-> fold v page
rely rest
5373 | ("page", v) :: rest
-> fold title v rely rest
5374 | ("rely", v) :: rest
-> fold title page
v rest
5375 | _ :: rest
-> fold title page
rely rest
5376 | [] -> title, page
, rely
5378 fold "invalid" "0" "0" attrs
5382 let rec fold path page
rely pan
= function
5383 | ("path", v) :: rest
-> fold v page
rely pan rest
5384 | ("page", v) :: rest
-> fold path v rely pan rest
5385 | ("rely", v) :: rest
-> fold path page
v pan rest
5386 | ("pan", v) :: rest
-> fold path page
rely v rest
5387 | _ :: rest
-> fold path page
rely pan rest
5388 | [] -> path, page
, rely, pan
5390 fold "" "0" "0" "0" attrs
5393 let setconf dst
src =
5394 dst
.scrollbw
<- src.scrollbw
;
5395 dst
.scrollh
<- src.scrollh
;
5396 dst
.icase
<- src.icase
;
5397 dst
.preload <- src.preload;
5398 dst
.pagebias
<- src.pagebias
;
5399 dst
.verbose
<- src.verbose
;
5400 dst
.scrollstep
<- src.scrollstep
;
5401 dst
.maxhfit
<- src.maxhfit
;
5402 dst
.crophack
<- src.crophack
;
5403 dst
.autoscrollstep
<- src.autoscrollstep
;
5404 dst
.maxwait
<- src.maxwait
;
5405 dst
.hlinks
<- src.hlinks
;
5406 dst
.underinfo
<- src.underinfo
;
5407 dst
.interpagespace <- src.interpagespace;
5408 dst
.zoom <- src.zoom;
5409 dst
.presentation <- src.presentation;
5410 dst
.angle
<- src.angle
;
5411 dst
.winw <- src.winw;
5412 dst
.winh
<- src.winh
;
5413 dst
.savebmarks
<- src.savebmarks
;
5414 dst
.memlimit
<- src.memlimit
;
5415 dst
.proportional
<- src.proportional
;
5416 dst
.texcount
<- src.texcount
;
5417 dst
.sliceheight
<- src.sliceheight
;
5418 dst
.thumbw
<- src.thumbw
;
5419 dst
.jumpback
<- src.jumpback
;
5420 dst
.bgcolor
<- src.bgcolor
;
5421 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5422 dst
.tilew
<- src.tilew
;
5423 dst
.tileh
<- src.tileh
;
5424 dst
.mustoresize
<- src.mustoresize
;
5425 dst
.checkers
<- src.checkers
;
5426 dst
.aalevel
<- src.aalevel
;
5427 dst
.trimmargins
<- src.trimmargins
;
5428 dst
.trimfuzz
<- src.trimfuzz
;
5429 dst
.urilauncher
<- src.urilauncher
;
5430 dst
.colorspace
<- src.colorspace
;
5431 dst
.invert
<- src.invert
;
5432 dst
.colorscale
<- src.colorscale
;
5433 dst
.redirectstderr <- src.redirectstderr;
5434 dst
.ghyllscroll
<- src.ghyllscroll
;
5435 dst
.columns
<- src.columns
;
5436 dst
.beyecolumns
<- src.beyecolumns
;
5437 dst
.selcmd
<- src.selcmd
;
5441 let h = Hashtbl.create
10 in
5442 let dc = { defconf with angle
= defconf.angle
} in
5443 let rec toplevel v t spos
_ =
5445 | Vdata
| Vcdata
| Vend
-> v
5446 | Vopen
("llppconfig", _, closed
) ->
5449 else { v with f = llppconfig
}
5451 error
"unexpected subelement at top level" s spos
5452 | Vclose
_ -> error
"unexpected close at top level" s spos
5454 and llppconfig
v t spos
_ =
5456 | Vdata
| Vcdata
-> v
5457 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5458 | Vopen
("defaults", attrs
, closed
) ->
5459 let c = config_of dc attrs
in
5463 else { v with f = skip
"defaults" (fun () -> v) }
5465 | Vopen
("ui-font", attrs
, closed
) ->
5466 let rec getsize size
= function
5468 | ("size", v) :: rest
->
5470 fromstring int_of_string spos
"size" v fstate.fontsize
in
5472 | l -> getsize size l
5474 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5477 else { v with f = uifont
(Buffer.create
10) }
5479 | Vopen
("doc", attrs
, closed
) ->
5480 let pathent, spage
, srely
, span
= doc_of attrs
in
5481 let path = unent pathent
5482 and pageno = fromstring int_of_string spos
"page" spage
0
5483 and rely = fromstring float_of_string spos
"rely" srely
0.0
5484 and pan
= fromstring int_of_string spos
"pan" span
0 in
5485 let c = config_of dc attrs
in
5486 let anchor = (pageno, rely) in
5488 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5489 else { v with f = doc
path pan
anchor c [] }
5492 error
"unexpected subelement in llppconfig" s spos
5494 | Vclose
"llppconfig" -> { v with f = toplevel }
5495 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5497 and uifont
b v t spos
epos =
5500 Buffer.add_substring
b s spos
(epos - spos
);
5502 | Vopen
(_, _, _) ->
5503 error
"unexpected subelement in ui-font" s spos
5504 | Vclose
"ui-font" ->
5505 if String.length
!fontpath = 0
5506 then fontpath := Buffer.contents
b;
5507 { v with f = llppconfig
}
5508 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5509 | Vend
-> error
"unexpected end of input in ui-font" s spos
5511 and doc
path pan
anchor c bookmarks
v t spos
_ =
5513 | Vdata
| Vcdata
-> v
5514 | Vend
-> error
"unexpected end of input in doc" s spos
5515 | Vopen
("bookmarks", _, closed
) ->
5518 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5520 | Vopen
(_, _, _) ->
5521 error
"unexpected subelement in doc" s spos
5524 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5525 { v with f = llppconfig
}
5527 | Vclose
_ -> error
"unexpected close in doc" s spos
5529 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5531 | Vdata
| Vcdata
-> v
5532 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5533 | Vopen
("item", attrs
, closed
) ->
5534 let titleent, spage
, srely
= bookmark_of attrs
in
5535 let page = fromstring int_of_string spos
"page" spage
0
5536 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5537 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5539 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5542 { v with f = skip
"item" f }
5545 error
"unexpected subelement in bookmarks" s spos
5547 | Vclose
"bookmarks" ->
5548 { v with f = doc
path pan
anchor c bookmarks }
5550 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5552 and skip tag
f v t spos
_ =
5554 | Vdata
| Vcdata
-> v
5556 error
("unexpected end of input in skipped " ^ tag
) s spos
5557 | Vopen
(tag'
, _, closed
) ->
5561 let f'
() = { v with f = skip tag
f } in
5562 { v with f = skip tag'
f'
}
5566 else error
("unexpected close in skipped " ^ tag
) s spos
5569 parse
{ f = toplevel; accu = () } s;
5575 let len = in_channel_length ic
in
5576 let s = String.create
len in
5577 really_input ic
s 0 len;
5580 | Parse_error
(msg
, s, pos
) ->
5581 let subs = subs s pos
in
5582 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5583 failwith
("parse error: " ^
s)
5586 failwith
("config load error: " ^
Printexc.to_string exn
)
5592 let dir = Filename.concat
home ".config" in
5593 if Sys.is_directory
dir then dir else home
5596 Filename.concat
dir "llpp.conf"
5599 let confpath = ref defconfpath;;
5602 if Sys.file_exists
!confpath
5605 (try Some
(open_in_bin
!confpath)
5608 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5609 Printexc.to_string exn
);
5618 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5619 Printexc.to_string exn
);
5625 f (Hashtbl.create
0, defconf)
5630 let pc, pb
, px, pa
=
5632 Hashtbl.find h (Filename.basename
state.path)
5633 with Not_found
-> dc, [], 0, (0, 0.0)
5637 state.bookmarks <- pb
;
5639 state.scrollw
<- conf.scrollbw
;
5641 then state.anchor <- pa
;
5642 cbput state.hists
.nav pa
;
5647 let add_attrs bb always
dc c =
5650 then Printf.bprintf bb
"\n %s='%b'" s a
5653 then Printf.bprintf bb
"\n %s='%d'" s a
5656 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5659 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5662 then Printf.bprintf bb
"\n %s='%f'" s a
5666 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5670 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5674 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5678 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5684 | Some
(_N
, _A
, _B
) ->
5685 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
5695 else string_of_float
f
5697 Printf.bprintf bb
"\n %s='%s'" s v
5702 | Some
((n, a, b), _) when n > 1 ->
5703 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
5709 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
5714 then dc.winw, dc.winh
5716 match state.fullscreen
with
5718 | None
-> c.winw, c.winh
5720 let zoom, presentation, interpagespace, maxwait
=
5722 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5724 match state.mode with
5725 | Birdseye
(bc
, _, _, _, _) ->
5726 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5727 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5729 oi
"width" w dc.winw;
5730 oi
"height" h dc.winh
;
5731 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5732 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5733 ob "case-insensitive-search" c.icase
dc.icase
;
5734 ob "preload" c.preload dc.preload;
5735 oi
"page-bias" c.pagebias
dc.pagebias
;
5736 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5737 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5738 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5739 ob "crop-hack" c.crophack
dc.crophack
;
5740 oW
"throttle" maxwait
dc.maxwait
;
5741 ob "highlight-links" c.hlinks
dc.hlinks
;
5742 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5743 oi
"vertical-margin" interpagespace dc.interpagespace;
5744 oz
"zoom" zoom dc.zoom;
5745 ob "presentation" presentation dc.presentation;
5746 oi
"rotation-angle" c.angle
dc.angle
;
5747 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5748 ob "proportional-display" c.proportional
dc.proportional
;
5749 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5750 oi
"tex-count" c.texcount
dc.texcount
;
5751 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5752 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5753 ob "persistent-location" c.jumpback
dc.jumpback
;
5754 oc
"background-color" c.bgcolor
dc.bgcolor
;
5755 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5756 oi
"tile-width" c.tilew
dc.tilew
;
5757 oi
"tile-height" c.tileh
dc.tileh
;
5758 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
5759 ob "checkers" c.checkers
dc.checkers
;
5760 oi
"aalevel" c.aalevel
dc.aalevel
;
5761 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5762 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5763 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5764 oC
"color-space" c.colorspace
dc.colorspace
;
5765 ob "invert-colors" c.invert
dc.invert
;
5766 oF
"brightness" c.colorscale
dc.colorscale
;
5767 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5768 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
5769 oco
"columns" c.columns
dc.columns
;
5770 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
5772 then ob "wmclass-hack" !wmclasshack false;
5773 os
"selection-command" c.selcmd
dc.selcmd
;
5777 let uifontsize = fstate.fontsize
in
5778 let bb = Buffer.create
32768 in
5780 let dc = if conf.bedefault
then conf else dc in
5781 Buffer.add_string
bb "<llppconfig>\n";
5783 if String.length
!fontpath > 0
5785 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5791 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5794 Buffer.add_string
bb "<defaults ";
5795 add_attrs bb true dc dc;
5796 Buffer.add_string
bb "/>\n";
5798 let adddoc path pan
anchor c bookmarks =
5799 if bookmarks == [] && c = dc && anchor = emptyanchor
5802 Printf.bprintf
bb "<doc path='%s'"
5803 (enent
path 0 (String.length
path));
5805 if anchor <> emptyanchor
5807 let n, y = anchor in
5808 Printf.bprintf
bb " page='%d'" n;
5811 Printf.bprintf
bb " rely='%f'" y
5816 then Printf.bprintf
bb " pan='%d'" pan
;
5818 add_attrs bb false dc c;
5820 begin match bookmarks with
5821 | [] -> Buffer.add_string
bb "/>\n"
5823 Buffer.add_string
bb ">\n<bookmarks>\n";
5824 List.iter
(fun (title, _level
, (page, rely)) ->
5826 "<item title='%s' page='%d'"
5827 (enent
title 0 (String.length
title))
5832 Printf.bprintf
bb " rely='%f'" rely
5834 Buffer.add_string
bb "/>\n";
5836 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5842 match state.mode with
5843 | Birdseye
(c, pan, _, _, _) ->
5845 match conf.columns
with
5846 | Some
((c, _, _), _) -> Some
c
5849 match c.columns
with
5850 | Some
(c, _) -> Some
(c, [||])
5853 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
5854 | _ -> state.x, conf
5856 let basename = Filename.basename state.path in
5857 adddoc basename pan (getanchor ())
5860 match state.autoscroll
with
5862 | None
-> conf.autoscrollstep
}
5863 (if conf.savebmarks
then state.bookmarks else []);
5865 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5867 then adddoc path x y c bookmarks
5869 Buffer.add_string
bb "</llppconfig>";
5872 if Buffer.length
bb > 0
5875 let tmp = !confpath ^
".tmp" in
5876 let oc = open_out_bin
tmp in
5877 Buffer.output_buffer
oc bb;
5879 Unix.rename
tmp !confpath;
5882 ("error while saving configuration: " ^
Printexc.to_string exn
)
5889 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5890 "<password> Set password");
5892 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5893 "<path> Set path to the user interface font");
5895 ("-c", Arg.String
(fun s -> Config.confpath := s),
5896 "<path> Set path to the configuration file");
5898 ("-v", Arg.Unit
(fun () ->
5900 "%s\nconfiguration path: %s\n"
5904 exit
0), " Print version and exit");
5907 (fun s -> state.path <- s)
5908 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5910 if String.length
state.path = 0
5911 then (prerr_endline
"file name missing"; exit
1);
5915 let _ = Glut.init
Sys.argv
in
5916 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5917 let () = Glut.initWindowSize
conf.winw conf.winh
in
5918 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5920 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5921 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5922 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5924 let () = Glut.displayFunc
display in
5925 let () = Glut.reshapeFunc
reshape in
5926 let () = Glut.keyboardFunc
keyboard in
5927 let () = Glut.specialFunc
special in
5928 let () = Glut.idleFunc
(Some
idle) in
5929 let () = Glut.mouseFunc
mouse in
5930 let () = Glut.motionFunc
motion in
5931 let () = Glut.passiveMotionFunc
pmotion in
5933 let cr, sw = Unix.pipe
()
5934 and sr
, cw
= Unix.pipe
() in
5936 setcheckers conf.checkers
;
5940 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5941 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
5942 !Config.wmclasshack, !Config.fontpath
5946 state.text <- "Opening " ^
state.path;
5947 setaalevel
conf.aalevel
;
5948 writeopen state.path state.password
;
5950 setfontsize fstate.fontsize
;
5956 | Glut.BadEnum
"key in special_of_int" ->
5957 showtext '
!'
" LablGlut bug: special key not recognized";
5964 | exn
when conf.redirectstderr && not
is_gui ->
5966 Printf.sprintf
"exception %s\n%s"
5967 (Printexc.to_string exn
)
5968 (Printexc.get_backtrace
())
5971 Unix.single_write
state.stderr
s 0 (String.length
s);