4 | Ulinkgoto
of (int * int)
6 and facename
= string;;
8 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
9 let now = Unix.gettimeofday
;;
13 type params
= (angle
* proportional
* trimparams
14 * texcount
* sliceheight
* memsize
15 * colorspace
* wmclasshack
* fontpath
)
24 and proportional
= bool
25 and trimmargins
= bool
26 and interpagespace
= int
34 and wmclasshack
= bool
35 and irect
= (int * int * int * int)
36 and trimparams
= (trimmargins
* irect
)
37 and colorspace
= | Rgb
| Bgr
| Gray
40 type platform
= | Punknown
| Plinux
| Pwindows
| Posx
| Psun
41 | Pfreebsd
| Pdragonflybsd
| Popenbsd
| Pnetbsd
44 external init
: Unix.file_descr
-> params
-> unit = "ml_init";;
45 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
46 external copysel
: string -> unit = "ml_copysel";;
47 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
48 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
49 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
50 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
51 external measurestr
: int -> string -> float = "ml_measure_string";;
52 external getmaxw
: unit -> float = "ml_getmaxw";;
53 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
54 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
55 external platform
: unit -> platform
= "ml_platform";;
56 external setaalevel
: int -> unit = "ml_setaalevel";;
57 external realloctexts
: int -> bool = "ml_realloctexts";;
59 let platform_to_string = function
60 | Punknown
-> "unknown"
62 | Pwindows
-> "Windows"
65 | Pfreebsd
-> "FreeBSD"
66 | Pdragonflybsd
-> "DragonflyBSD"
67 | Popenbsd
-> "OpenBSD"
73 let platform = platform ();;
77 | Pwindows
| Pmingw
-> true
85 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
88 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
92 | Msel
of (mpos
* mpos
)
95 | Mzoom
of (int * int)
96 | Mzoomrect
of (mpos
* mpos
)
100 type textentry
= string * string * onhist
option * onkey
* ondone
101 and onkey
= string -> int -> te
102 and ondone
= string -> unit
103 and histcancel
= unit -> unit
104 and onhist
= ((histcmd
-> string) * histcancel
)
105 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
110 | TEswitch
of textentry
121 let bound v minv maxv
=
122 max minv
(min maxv v
);
126 { store
= Array.create n v
133 let drawstring size x y s
=
135 Gl.enable `texture_2d
;
136 ignore
(drawstr size x y s
);
138 Gl.disable `texture_2d
;
141 let drawstring1 size x y s
=
145 let drawstring2 size x y fmt
=
146 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
149 let cbcap b
= Array.length b
.store
;;
154 b
.wc
<- (b
.wc
+ 1) mod cap;
156 b
.len
<- min
(b
.len
+ 1) cap;
159 let cbempty b
= b
.len
= 0;;
161 let cbgetg b circular dir
=
165 let rc = b
.rc + dir
in
177 else max
0 (min
rc (b
.len
-1))
183 let cbget b
= cbgetg b
false;;
184 let cbgetc b
= cbgetg b
true;;
201 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
202 dolog " WxH %dx%d" l
.pagew l
.pageh
;
203 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
204 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
205 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
209 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
211 dolog " x0,y0=(% f, % f)" x0 y0
;
212 dolog " x1,y1=(% f, % f)" x1 y1
;
213 dolog " x2,y2=(% f, % f)" x2 y2
;
214 dolog " x3,y3=(% f, % f)" x3 y3
;
219 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
220 and multicol
= columncount
* covercount
* covercount
222 and columncount
= int
223 and covercount
= int;;
226 { mutable scrollbw
: int
227 ; mutable scrollh
: int
228 ; mutable icase
: bool
229 ; mutable preload
: bool
230 ; mutable pagebias
: int
231 ; mutable verbose
: bool
232 ; mutable debug
: bool
233 ; mutable scrollstep
: int
234 ; mutable maxhfit
: bool
235 ; mutable crophack
: bool
236 ; mutable autoscrollstep
: int
237 ; mutable maxwait
: float option
238 ; mutable hlinks
: bool
239 ; mutable underinfo
: bool
240 ; mutable interpagespace
: interpagespace
241 ; mutable zoom
: float
242 ; mutable presentation
: bool
243 ; mutable angle
: angle
246 ; mutable savebmarks
: bool
247 ; mutable proportional
: proportional
248 ; mutable trimmargins
: trimmargins
249 ; mutable trimfuzz
: irect
250 ; mutable memlimit
: memsize
251 ; mutable texcount
: texcount
252 ; mutable sliceheight
: sliceheight
253 ; mutable thumbw
: width
254 ; mutable jumpback
: bool
255 ; mutable bgcolor
: float * float * float
256 ; mutable bedefault
: bool
257 ; mutable scrollbarinpm
: bool
258 ; mutable tilew
: int
259 ; mutable tileh
: int
260 ; mutable mustoresize
: memsize
261 ; mutable checkers
: bool
262 ; mutable aalevel
: int
263 ; mutable urilauncher
: string
264 ; mutable colorspace
: colorspace
265 ; mutable invert
: bool
266 ; mutable colorscale
: float
267 ; mutable redirectstderr
: bool
268 ; mutable ghyllscroll
: (int * int * int) option
269 ; mutable columns
: columns
option
270 ; mutable beyecolumns
: columncount
option
274 type anchor
= pageno
* top
;;
276 type outline
= string * int * anchor
;;
278 type rect
= float * float * float * float * float * float * float * float;;
280 type tile
= opaque
* pixmapsize
* elapsed
281 and elapsed
= float;;
282 type pagemapkey
= pageno
* gen
;;
283 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
287 let emptyanchor = (0, 0.0);;
289 type infochange
= | Memused
| Docinfo
| Pdim
;;
291 class type uioh
= object
292 method display
: unit
293 method key
: int -> uioh
294 method special
: Glut.special_key_t
-> uioh
296 Glut.button_t
-> Glut.mouse_button_state_t
-> int -> int -> uioh
297 method motion
: int -> int -> uioh
298 method pmotion
: int -> int -> uioh
299 method infochanged
: infochange
-> unit
300 method scrollpw
: (int * float * float)
301 method scrollph
: (int * float * float)
305 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
306 | Textentry
of (textentry
* onleave
)
308 and onleave
= leavetextentrystatus
-> unit
309 and leavetextentrystatus
= | Cancel
| Confirm
310 and helpitem
= string * int * action
313 | Action
of (uioh
-> uioh
)
316 let isbirdseye = function Birdseye _
-> true | _
-> false;;
317 let istextentry = function Textentry _
-> true | _
-> false;;
321 | Loading
of (page
* gen
)
323 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
325 | Outlining
of outline list
328 let nouioh : uioh
= object (self
)
331 method special _
= self
332 method button _ _ _ _
= self
333 method motion _ _
= self
334 method pmotion _ _
= self
335 method infochanged _
= ()
336 method scrollpw
= (0, nan
, nan
)
337 method scrollph
= (0, nan
, nan
)
341 { mutable csock
: Unix.file_descr
342 ; mutable ssock
: Unix.file_descr
343 ; mutable errfd
: Unix.file_descr
option
344 ; mutable stderr
: Unix.file_descr
345 ; mutable errmsgs
: Buffer.t
346 ; mutable newerrmsgs
: bool
350 ; mutable scrollw
: int
351 ; mutable hscrollh
: int
352 ; mutable anchor
: anchor
354 ; mutable layout
: page list
355 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
356 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
357 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
358 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
359 ; mutable pagecount
: int
360 ; mutable currently
: currently
361 ; mutable mstate
: mstate
362 ; mutable searchpattern
: string
363 ; mutable rects
: (pageno
* recttype
* rect
) list
364 ; mutable rects1
: (pageno
* recttype
* rect
) list
365 ; mutable text
: string
366 ; mutable fullscreen
: (width
* height
) option
367 ; mutable mode
: mode
368 ; mutable uioh
: uioh
369 ; mutable outlines
: outline array
370 ; mutable bookmarks
: outline list
371 ; mutable path
: string
372 ; mutable password
: string
373 ; mutable invalidated
: int
374 ; mutable memused
: memsize
376 ; mutable throttle
: (page list
* int * float) option
377 ; mutable autoscroll
: int option
378 ; mutable ghyll
: int option -> unit
379 ; mutable help
: helpitem array
380 ; mutable docinfo
: (int * string) list
381 ; mutable deadline
: float
382 ; mutable texid
: GlTex.texture_id
option
384 ; mutable prevzoom
: float
385 ; mutable progress
: float
388 { pat
: string circbuf
389 ; pag
: string circbuf
390 ; nav
: anchor circbuf
411 ; presentation
= false
416 ; proportional
= true
417 ; trimmargins
= false
418 ; trimfuzz
= (0,0,0,0)
419 ; memlimit
= 32 lsl 20
424 ; bgcolor
= (0.5, 0.5, 0.5)
426 ; scrollbarinpm
= true
429 ; mustoresize
= 128 lsl 20
434 | Plinux
| Pfreebsd
| Pdragonflybsd
| Popenbsd
| Psun
-> "xdg-open \"%s\""
435 | Posx
-> "open \"%s\""
436 | Pwindows
| Pcygwin
| Pmingw
-> "iexplore \"%s\""
441 ; redirectstderr
= false
448 let conf = { defconf with angle
= defconf.angle
};;
451 { mutable fontsize
: int
452 ; mutable wwidth
: float
453 ; mutable maxrows
: int
465 fstate.fontsize
<- n
;
466 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
467 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
471 if String.length
conf.urilauncher
= 0
472 then print_endline uri
474 let re = Str.regexp
"%s" in
475 let command = Str.global_replace
re uri
conf.urilauncher
in
477 try Some
(Unix.open_process_in
command)
480 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
485 | Some ic
-> close_in ic
490 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
491 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
495 let strings = version () :: "" :: Help.keys
in
497 let r = Str.regexp
"\\(http://[^ ]+\\)" in
499 if (try Str.search_forward
r s
0 with Not_found
-> -1) >= 0
501 let uri = Str.matched_string s
in
502 (s
, 0, Action
(fun u
-> gotouri uri; u
))
503 else s
, 0, Noaction
) strings
513 ; stderr
= Unix.stderr
514 ; errmsgs
= Buffer.create
0
521 ; anchor
= emptyanchor
524 ; tilelru
= Queue.create
()
525 ; pagemap
= Hashtbl.create
10
526 ; tilemap
= Hashtbl.create
10
543 { nav
= cbnew 10 (0, 0.0)
565 Printf.kprintf prerr_endline fmt
567 Printf.kprintf ignore fmt
570 let redirectstderr () =
571 if conf.redirectstderr
573 let rfd, wfd
= Unix.pipe
() in
574 state.stderr
<- Unix.dup
Unix.stderr
;
575 state.errfd
<- Some
rfd;
576 Unix.dup2 wfd
Unix.stderr
;
578 state.newerrmsgs
<- false;
579 begin match state.errfd
with
582 Unix.dup2
state.stderr
Unix.stderr
;
586 prerr_string
(Buffer.contents
state.errmsgs
);
588 Buffer.clear
state.errmsgs
;
594 let postRedisplay who
=
596 then prerr_endline
("redisplay for " ^ who
);
597 Glut.postRedisplay ();
602 let b = Buffer.create
(String.length s
+ 1) in
603 Buffer.add_string
b s
;
608 let colorspace_of_string s
=
609 match String.lowercase s
with
613 | _
-> failwith
"invalid colorspace"
616 let int_of_colorspace = function
622 let colorspace_of_int = function
626 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
629 let colorspace_to_string = function
635 let intentry_with_suffix text key
=
636 let c = Char.unsafe_chr key
in
637 match Char.lowercase
c with
639 let text = addchar text c in
643 let text = addchar text c in
647 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
651 let columns_to_string (n
, a
, b) =
653 then Printf.sprintf
"%d" n
654 else Printf.sprintf
"%d,%d,%d" n a
b;
657 let columns_of_string s
=
659 (int_of_string s
, 0, 0)
661 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
665 let len = String.length s
in
667 let b = Buffer.create
n in
668 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
669 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
670 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
671 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
672 Buffer.add_string
b s
;
673 let s'
= Buffer.contents
b in
674 let n'
= Unix.write fd
s'
0 n in
675 if n'
!= n then failwith
"write failed";
680 let n = Unix.read fd
s 0 4 in
681 if n != 4 then failwith
"incomplete read(len)";
683 lor (Char.code
s.[0] lsl 24)
684 lor (Char.code
s.[1] lsl 16)
685 lor (Char.code
s.[2] lsl 8)
686 lor (Char.code
s.[3] lsl 0)
688 let s = String.create
len in
689 let n = Unix.read fd
s 0 len in
690 if n != len then failwith
"incomplete read(data)";
695 let b = Buffer.create
10 in
696 Buffer.add_string
b s;
697 let rec combine = function
700 Buffer.add_char
b ' '
;
703 | `
b b -> if b then "1" else "0"
705 | `i i
-> string_of_int i
706 | `f f
-> string_of_float f
707 | `I f
-> string_of_int
(truncate f
)
709 Buffer.add_string
b s;
716 let cmd = Buffer.contents
(makecmd s l
) in
717 writecmd state.csock
cmd;
723 let d = conf.winh
- h
in
730 let rec f pn ph pi fh l
=
732 | (n, _
, h
, _
) :: rest
->
733 let ips = calcips h
in
738 if isbirdseye state.mode
&& pn
= 0
743 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
748 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
752 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
755 let fh = f 0 0 0 0 state.pdims
in
760 match conf.columns
with
761 | None
-> calcheight ()
763 if Array.length
b > 0
765 let (_
, _
, y
, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
770 let getpageyh pageno
=
771 let rec f pn ph pi y l
=
773 | (n, _
, h
, _
) :: rest
->
774 let ips = calcips h
in
777 let h = if n = pageno
then h else ph
in
778 if conf.presentation
&& n = pageno
780 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
782 y
+ (pageno
- pn
) * (ph
+ pi
), h
784 let y = y + (if conf.presentation
then pi
else 0) in
785 let y = y + (n - pn
) * (ph
+ pi
) in
789 y + (pageno
- pn
) * (ph
+ pi
), ph
791 f 0 0 0 0 state.pdims
794 let getpageyh pageno
=
795 match conf.columns
with
796 | None
-> getpageyh pageno
798 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
802 let getpagedim pageno
=
805 | (n, _
, _
, _
) as pdim
:: rest
->
807 then (if n = pageno
then pdim
else ppdim
)
812 f (-1, -1, -1, -1) state.pdims
815 let getpagey pageno
= fst
(getpageyh pageno
);;
818 let sh = sh - state.hscrollh
in
819 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
820 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
822 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
823 let ips = calcips h in
825 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
829 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
831 prev
, pdims
, pdimno
, 0
833 let dy = dy + yinc in
834 let py = py + yinc in
835 if pageno
= state.pagecount
|| dy >= sh
840 if py + h <= vy - yinc
842 let py = py + h + ips in
843 let dy = max
0 (py - y) in
852 let pagey = vy - py in
853 let pagevh = h - pagey in
854 let pagevh = min
(sh - dy) pagevh in
855 let off = if yinc > 0 then py - vy else 0 in
856 let py = py + h + ips in
859 if state.w
< conf.winw
- state.scrollw
860 then (conf.winw
- state.scrollw
- state.w
) / 2
863 let dispx = xoff + state.x
in
869 let lw = w
- pagex in
870 min
lw (conf.winw
- state.scrollw
)
878 ; pagey = pagey + off
880 ; pagevh = pagevh - off
882 ; pagedispy
= dy + off
885 let accu = e :: accu in
894 if state.invalidated
= 0
912 let layoutN ((columns
, coverA
, coverB
), b) y sh =
913 let sh = sh - state.hscrollh
in
914 let rec fold accu n =
915 if n = Array.length
b
918 let pdimno, dx
, vy, (_
, w
, h, xoff) = b.(n) in
921 || n = state.pagecount
- coverB
922 || (n - coverA
) mod columns
= columns
- 1)
928 let pagey = max
0 (y - vy) in
929 let pagedispy = if pagey > 0 then 0 else vy - y in
930 let pagedispx, pagex, pagevw =
932 if n = coverA
- 1 || n = state.pagecount
- coverB
933 then state.x
+ (conf.winw
- state.scrollw
- w
) / 2
934 else dx
+ xoff + state.x
937 then 0, -pdx, w
+ pdx
938 else pdx, 0, min
(conf.winw
- state.scrollw
) w
940 let pagevh = min
(h - pagey) (sh - pagedispy) in
941 if pagedispx < conf.winw
- state.scrollw
&& pagevw > 0 && pagevh > 0
952 ; pagedispx = pagedispx
953 ; pagedispy = pagedispy
964 if state.invalidated
= 0
965 then List.rev
(fold [] 0)
970 match conf.columns
with
971 | None
-> layout1 y sh
972 | Some
c -> layoutN c y sh
976 let y = state.y + incr
in
978 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
982 let getopaque pageno
=
983 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
984 with Not_found
-> None
987 let putopaque pageno opaque
=
988 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
992 let tilex = l
.pagex mod conf.tilew
in
993 let tiley = l
.pagey mod conf.tileh
in
995 let col = l
.pagex / conf.tilew
in
996 let row = l
.pagey / conf.tileh
in
999 let a = l
.pagew
- l
.pagex in
1000 let b = conf.winw
- state.scrollw
in
1002 and vh
= l
.pagevh in
1004 let rec rowloop row y0 dispy
h =
1008 let dh = conf.tileh
- y0
in
1009 let dh = min
h dh in
1010 let rec colloop col x0
dispx w
=
1014 let dw = conf.tilew
- x0
in
1015 let dw = min w
dw in
1017 f col row dispx dispy x0 y0
dw dh;
1018 colloop (col+1) 0 (dispx+dw) (w
-dw)
1021 colloop col tilex l
.pagedispx vw;
1022 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1026 then rowloop row tiley l
.pagedispy vh
;
1029 let gettileopaque l
col row =
1031 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1033 try Some
(Hashtbl.find
state.tilemap
key)
1034 with Not_found
-> None
1037 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1038 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1039 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1042 let drawtiles l color
=
1044 let f col row x
y tilex tiley w
h =
1045 match gettileopaque l
col row with
1046 | Some
(opaque
, _
, t
) ->
1047 let params = x
, y, w
, h, tilex, tiley in
1051 GlFunc.blend_func `zero `one_minus_src_color
;
1053 drawtile
params opaque
;
1055 then Gl.disable `blend
;
1058 let s = Printf.sprintf
1062 let w = measurestr
fstate.fontsize
s in
1063 GlMisc.push_attrib
[`current
];
1064 GlDraw.color
(0.0, 0.0, 0.0);
1066 (float (x
-2), float (y-2))
1067 (float (x
+2) +. w, float (y + fstate.fontsize
+ 2));
1068 GlDraw.color
(1.0, 1.0, 1.0);
1069 drawstring fstate.fontsize x
(y + fstate.fontsize
- 1) s;
1070 GlMisc.pop_attrib
();
1075 let lw = conf.winw
- state.scrollw
- x
in
1078 let lh = conf.winh
- y in
1081 Gl.enable `texture_2d
;
1082 begin match state.texid
with
1084 GlTex.bind_texture `texture_2d id
;
1087 and x1
= float (x
+w)
1088 and y1
= float (y+h) in
1090 let tw = float w /. 64.0
1091 and th
= float h /. 64.0 in
1092 let tx0 = float tilex /. 64.0
1093 and ty0
= float tiley /. 64.0 in
1095 and ty1
= ty0
+. th
in
1096 GlDraw.begins `quads
;
1097 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
1098 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
1099 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
1100 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
1103 Gl.disable `texture_2d
;
1105 GlDraw.color
(1.0, 1.0, 1.0);
1108 (float (x
+w), float (y+h));
1110 if w > 128 && h > fstate.fontsize
+ 10
1112 GlDraw.color
(0.0, 0.0, 0.0);
1115 then (col*conf.tilew
, row*conf.tileh
)
1118 drawstring2 fstate.fontsize x
y "Loading %d [%d,%d]" l
.pageno
c r;
1125 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1127 let tilevisible1 l x
y =
1129 and ax1
= l
.pagex + l
.pagevw
1131 and ay1
= l
.pagey + l
.pagevh in
1135 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1136 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1138 let rx0 = max
ax0 bx0
1139 and ry0
= max ay0 by0
1140 and rx1
= min ax1
bx1
1141 and ry1
= min ay1 by1
in
1143 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1144 nonemptyintersection
1147 let tilevisible layout n x
y =
1148 let rec findpageinlayout = function
1149 | l
:: _
when l
.pageno
= n -> tilevisible1 l x
y
1150 | _
:: rest
-> findpageinlayout rest
1153 findpageinlayout layout
1156 let tileready l x
y =
1157 tilevisible1 l x
y &&
1158 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
1161 let tilepage n p
layout =
1162 let rec loop = function
1166 let f col row _ _ _ _ _ _
=
1167 if state.currently
= Idle
1169 match gettileopaque l
col row with
1172 let x = col*conf.tilew
1173 and y = row*conf.tileh
in
1175 let w = l
.pagew
- x in
1179 let h = l
.pageh
- y in
1191 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1192 conf.tilew
, conf.tileh
1201 if state.invalidated
= 0 then loop layout;
1204 let preloadlayout visiblepages
=
1205 let presentation = conf.presentation in
1206 let interpagespace = conf.interpagespace in
1207 let maxy = state.maxy in
1208 conf.presentation <- false;
1209 conf.interpagespace <- 0;
1210 state.maxy <- calcheight ();
1212 match visiblepages
with
1214 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1216 let y = if y < conf.winh
then 0 else y - conf.winh
in
1217 let h = state.y - y + conf.winh
*3 in
1218 let pages = layout y h in
1219 conf.presentation <- presentation;
1220 conf.interpagespace <- interpagespace;
1226 let rec loop pages =
1227 if state.currently
!= Idle
1232 begin match getopaque l
.pageno
with
1234 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1235 state.currently
<- Loading
(l
, state.gen
);
1237 tilepage l
.pageno opaque
pages;
1242 if state.invalidated
= 0 then loop pages
1247 if conf.preload && state.currently
= Idle
1248 then load (preloadlayout pages);
1251 let layoutready layout =
1252 let rec fold all ls
=
1253 all
&& match ls
with
1255 let seen = ref false in
1256 let allvisible = ref true in
1257 let foo col row _ _ _ _ _ _
=
1259 allvisible := !allvisible &&
1260 begin match gettileopaque l
col row with
1266 fold (!seen && !allvisible) rest
1269 let alltilesvisible = fold true layout in
1274 let y = bound y 0 state.maxy in
1275 let y, layout, proceed
=
1276 match conf.maxwait
with
1277 | Some time
when state.ghyll
== noghyll ->
1278 begin match state.throttle
with
1280 let layout = layout y conf.winh
in
1281 let ready = layoutready layout in
1285 state.throttle
<- Some
(layout, y, now ());
1287 else G.postRedisplay "gotoy showall (None)";
1289 | Some
(_
, _
, started
) ->
1290 let dt = now () -. started
in
1293 state.throttle
<- None
;
1294 let layout = layout y conf.winh
in
1296 G.postRedisplay "maxwait";
1303 let layout = layout y conf.winh
in
1304 if true || layoutready layout
1305 then G.postRedisplay "gotoy ready";
1311 state.layout <- layout;
1312 begin match state.mode
with
1313 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1314 if not
(pagevisible layout pageno
)
1316 match state.layout with
1319 state.mode
<- Birdseye
(
1320 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1327 state.ghyll
<- noghyll;
1330 let conttiling pageno opaque
=
1331 tilepage pageno opaque
1332 (if conf.preload then preloadlayout state.layout else state.layout)
1335 let gotoy_and_clear_text y =
1337 if not
conf.verbose
then state.text <- "";
1341 match state.layout with
1343 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1346 let getanchory (n, top
) =
1347 let y, h = getpageyh n in
1348 y + (truncate
(top
*. float h));
1351 let gotoanchor anchor
=
1352 gotoy (getanchory anchor
);
1356 cbput state.hists
.nav
(getanchor ());
1360 let anchor = cbgetc state.hists
.nav dir
in
1365 let rec scroll f n a b =
1366 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1368 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1370 then s (float f /. float a)
1373 then 1.0 -. s ((float (f-b) /. float (n-b)))
1380 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1381 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1383 let ins = float a *. iv1
1384 and outs
= float (n-b) *. iv1 in
1386 ins +. outs
+. float ones
1388 let rec set (_N
, _A
, _B
) y sy
=
1389 let sum = summa
1.0 _N _A _B
in
1390 let dy = float (y - sy
) in
1394 then state.ghyll
<- noghyll
1397 let s = scroll n _N _A _B
in
1398 let y1 = y1 +. ((s *. dy) /. sum) in
1399 gotoy_and_clear_text (truncate
y1);
1400 state.ghyll
<- gf (n+1) y1;
1404 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1406 gf 0 (float state.y)
1409 match conf.ghyllscroll
with
1411 gotoy_and_clear_text y
1413 if state.ghyll
== noghyll
1414 then set nab
y state.y
1415 else state.ghyll
(Some
y)
1418 let gotopage n top
=
1419 let y, h = getpageyh n in
1420 let y = y + (truncate
(top
*. float h)) in
1424 let gotopage1 n top
=
1425 let y = getpagey n in
1435 state.invalidated
<- state.invalidated
+ 1;
1438 let writeopen path password
=
1439 writecmd state.csock
("open " ^ path ^
"\000" ^ password ^
"\000");
1442 let opendoc path password
=
1445 state.password
<- password
;
1446 state.gen
<- state.gen
+ 1;
1447 state.docinfo
<- [];
1449 setaalevel
conf.aalevel
;
1450 writeopen path password
;
1451 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1452 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1456 let c = c *. conf.colorscale
in
1460 let scalecolor2 (r, g
, b) =
1461 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1465 let docolumns = function
1467 | Some
((columns
, coverA
, coverB
), _
) ->
1468 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1469 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1470 if pageno
= state.pagecount
1473 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1475 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1476 pdimno+1, pdim
, rest
1481 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1483 (conf.winw
- state.scrollw
- w) / 2,
1484 y + rowh
+ conf.interpagespace, h
1487 if (pageno
- coverA
) mod columns
= 0
1488 then 0, y + rowh
+ conf.interpagespace, h
1489 else x, y, max rowh
h
1492 let rec fixrow m
= if m
= pageno
then () else
1493 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1496 let y = y + (rowh
- h) / 2 in
1497 a.(m
) <- (pdimno, x, y, pdim
);
1501 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1502 then fixrow (pageno
- columns
);
1503 a.(pageno
) <- (pdimno, x, y, pdim
);
1504 let x = x + w + xoff*2 + conf.interpagespace in
1505 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1507 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1508 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1510 docolumns conf.columns
;
1511 state.maxy <- calcheight ();
1513 if state.w <= conf.winw
- state.scrollw
1517 match state.mode
with
1518 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1519 let y, h = getpageyh pageno
in
1520 let top = (conf.winh
- h) / 2 in
1521 gotoy (max
0 (y - top))
1522 | _
-> gotoanchor state.anchor
1526 let firsttime = ref true in
1528 GlDraw.viewport
0 0 w h;
1529 if state.invalidated
= 0 && not
!firsttime
1530 then state.anchor <- getanchor ();
1534 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1538 setfontsize fstate.fontsize
;
1539 GlMat.mode `modelview
;
1540 GlMat.load_identity
();
1542 GlMat.mode `projection
;
1543 GlMat.load_identity
();
1544 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1545 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1546 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1549 match conf.columns
with
1551 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1554 wcmd "geometry" [`i
w; `i
h];
1558 let len = String.length
state.text in
1561 match state.mode
with
1562 | View
-> state.hscrollh
1567 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1568 (x+.w, float (conf.winh
- hscrollh))
1571 let w = float (conf.winw
- state.scrollw
- 1) in
1572 if state.progress
>= 0.0 && state.progress
< 1.0
1574 GlDraw.color
(0.3, 0.3, 0.3);
1575 let w1 = w *. state.progress
in
1577 GlDraw.color
(0.0, 0.0, 0.0);
1581 GlDraw.color
(0.0, 0.0, 0.0);
1585 GlDraw.color
(1.0, 1.0, 1.0);
1586 drawstring fstate.fontsize
1587 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1590 match state.mode
with
1591 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1595 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1597 Printf.sprintf
"%s%s_" prefix
text
1606 if not
(istextentry state.mode
)
1608 let s1 = "(press 'e' to review error messasges)" in
1609 if String.length
s > 0 then s ^
" " ^
s1 else s1
1614 if String.length
s > 0
1619 state.text <- Printf.sprintf
"%c%s" c s;
1620 G.postRedisplay "showtext";
1624 let len = Queue.length
state.tilelru
in
1626 if state.memused
<= conf.memlimit
1631 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1632 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1633 let (_
, pw
, ph
, _
) = getpagedim n in
1636 && colorspace
= conf.colorspace
1637 && angle
= conf.angle
1642 match state.throttle
with
1645 then preloadlayout state.layout
1647 | Some
(layout, _
, _
) ->
1650 let x = col*conf.tilew
1651 and y = row*conf.tileh
in
1652 tilevisible layout n x y
1654 then Queue.push lruitem
state.tilelru
1656 wcmd "freetile" [`
s p
];
1657 state.memused
<- state.memused
- s;
1658 state.uioh#infochanged Memused
;
1659 Hashtbl.remove
state.tilemap k
;
1668 Queue.iter
(fun (k
, p
, s) ->
1669 wcmd "freetile" [`
s p
];
1670 state.memused
<- state.memused
- s;
1671 state.uioh#infochanged Memused
;
1672 Hashtbl.remove
state.tilemap k
;
1674 Queue.clear
state.tilelru
;
1678 let logcurrently = function
1679 | Idle
-> dolog "Idle"
1680 | Loading
(l
, gen
) ->
1681 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1682 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1684 "Tiling %d[%d,%d] page=%s cs=%s angle"
1685 l
.pageno
col row pageopaque
1686 (colorspace_to_string colorspace
)
1688 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1689 angle gen
conf.angle
state.gen
1691 conf.tilew
conf.tileh
1698 (* dolog "%S" cmds; *)
1701 try String.index cmds ' '
1702 with Not_found
-> -1
1707 let l = String.length cmds
in
1708 let op = String.sub cmds
0 spacepos in
1710 if l - spacepos < 2 then ""
1711 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1716 state.uioh#infochanged Pdim
;
1720 state.rects
<- state.rects1
;
1721 G.postRedisplay "clearrects";
1725 try Scanf.sscanf args
"%u" (fun n -> n)
1727 dolog "error processing 'continue' %S: %s"
1728 cmds
(Printexc.to_string exn
);
1731 state.pagecount
<- n;
1732 state.invalidated
<- state.invalidated
- 1;
1733 begin match state.currently
with
1735 state.currently
<- Idle
;
1736 state.outlines
<- Array.of_list
(List.rev
l)
1739 if state.invalidated
= 0
1741 if conf.maxwait
= None
1742 then G.postRedisplay "continue";
1745 Glut.setWindowTitle args
1752 then showtext ' ' args
1755 let progress, text =
1757 Scanf.sscanf args
"%f %n"
1759 f, String.sub args pos
(String.length args
- pos
))
1761 dolog "error processing 'progress' %S: %s"
1762 cmds
(Printexc.to_string exn
);
1766 state.progress <- progress;
1767 G.postRedisplay "progress"
1770 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1772 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1773 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1774 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1776 dolog "error processing 'firstmatch' %S: %s"
1777 cmds
(Printexc.to_string exn
);
1780 let y = (getpagey pageno) + truncate y0
in
1783 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)]
1786 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1788 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1789 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1790 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1792 dolog "error processing 'match' %S: %s"
1793 cmds
(Printexc.to_string exn
);
1797 (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) :: state.rects1
1802 Scanf.sscanf args
"%s %f" (fun p t
-> p
, t
)
1804 dolog "error processing 'page' %S: %s"
1805 cmds
(Printexc.to_string exn
);
1808 begin match state.currently
with
1809 | Loading
(l, gen
) ->
1810 vlog "page %d took %f sec" l.pageno t
;
1811 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1812 begin match state.throttle
with
1814 let preloadedpages =
1816 then preloadlayout state.layout
1821 Set.Make
(struct type t
= int let compare = (-) end) in
1823 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1824 IntSet.empty
preloadedpages
1827 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
1828 if not
(IntSet.mem
pageno set)
1830 wcmd "freepage" [`
s opaque
];
1836 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1839 state.currently
<- Idle
;
1842 tilepage l.pageno pageopaque state.layout;
1844 load preloadedpages;
1845 if pagevisible state.layout l.pageno
1846 && layoutready state.layout
1847 then G.postRedisplay "page";
1850 | Some
(layout, _
, _
) ->
1851 state.currently
<- Idle
;
1852 tilepage l.pageno pageopaque layout;
1857 dolog "Inconsistent loading state";
1858 logcurrently state.currently
;
1863 let (x, y, opaque
, size
, t
) =
1865 Scanf.sscanf args
"%u %u %s %u %f"
1866 (fun x y p size t
-> (x, y, p
, size
, t
))
1868 dolog "error processing 'tile' %S: %s"
1869 cmds
(Printexc.to_string exn
);
1872 begin match state.currently
with
1873 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1874 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1876 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1878 wcmd "freetile" [`
s opaque
];
1879 state.currently
<- Idle
;
1883 puttileopaque l col row gen cs angle opaque size t
;
1884 state.memused
<- state.memused
+ size
;
1885 state.uioh#infochanged Memused
;
1887 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1888 opaque
, size
) state.tilelru
;
1891 match state.throttle
with
1892 | None
-> state.layout
1893 | Some
(layout, _
, _
) -> layout
1896 state.currently
<- Idle
;
1898 && conf.colorspace
= cs
1899 && conf.angle
= angle
1900 && tilevisible layout l.pageno x y
1901 then conttiling l.pageno pageopaque;
1903 begin match state.throttle
with
1905 preload state.layout;
1907 && conf.colorspace
= cs
1908 && conf.angle
= angle
1909 && tilevisible state.layout l.pageno x y
1910 then G.postRedisplay "tile nothrottle";
1912 | Some
(layout, y, _
) ->
1913 let ready = layoutready layout in
1917 state.layout <- layout;
1918 state.throttle
<- None
;
1919 G.postRedisplay "throttle";
1926 dolog "Inconsistent tiling state";
1927 logcurrently state.currently
;
1934 Scanf.sscanf args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1936 dolog "error processing 'pdim' %S: %s"
1937 cmds
(Printexc.to_string exn
);
1940 state.uioh#infochanged Pdim
;
1941 state.pdims
<- pdim :: state.pdims
1944 let (l, n, t
, h, pos
) =
1946 Scanf.sscanf args
"%u %u %d %u %n"
1947 (fun l n t
h pos
-> l, n, t
, h, pos
)
1949 dolog "error processing 'o' %S: %s"
1950 cmds
(Printexc.to_string exn
);
1953 let s = String.sub args pos
(String.length args
- pos
) in
1954 let outline = (s, l, (n, float t
/. float h)) in
1955 begin match state.currently
with
1956 | Outlining outlines
->
1957 state.currently
<- Outlining
(outline :: outlines
)
1959 state.currently
<- Outlining
[outline]
1961 dolog "invalid outlining state";
1962 logcurrently currently
1966 state.docinfo
<- (1, args
) :: state.docinfo
1969 state.uioh#infochanged Docinfo
;
1970 state.docinfo
<- List.rev
state.docinfo
1973 dolog "unknown cmd `%S'" cmds
1977 if state.deadline
== nan
then state.deadline
<- now ();
1979 match state.errfd
with
1980 | None
-> [state.csock
]
1981 | Some fd
-> [state.csock
; fd
]
1983 let rec loop delay
=
1985 if state.ghyll
== noghyll
1991 then max
0.0 (deadline -. now ())
1994 let r, _
, _
= Unix.select
r [] [] timeout in
1998 begin match state.autoscroll
with
1999 | Some step
when step
!= 0 ->
2000 let y = state.y + step
in
2004 else if y >= state.maxy then 0 else y
2007 if state.mode
= View
2008 then state.text <- "";
2009 state.deadline <- state.deadline +. 0.005;
2012 state.deadline <- state.deadline +. delay
;
2016 let rec checkfds c = function
2018 | fd
:: rest
when fd
= state.csock
->
2019 let cmd = readcmd state.csock
in
2023 let s = String.create
80 in
2024 let n = Unix.read fd
s 0 80 in
2025 if conf.redirectstderr
2027 Buffer.add_substring
state.errmsgs
s 0 n;
2028 state.newerrmsgs
<- true;
2029 Glut.postRedisplay ();
2032 prerr_string
(String.sub
s 0 n);
2045 let action = function
2046 | HCprev
-> cbget cb ~
-1
2047 | HCnext
-> cbget cb
1
2048 | HCfirst
-> cbget cb ~
-(cb
.rc)
2049 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2050 and cancel
() = cb
.rc <- rc
2054 let search pattern forward
=
2055 if String.length pattern
> 0
2058 match state.layout with
2061 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2064 let b = makecmd "search"
2065 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
2067 Buffer.add_char
b '
,'
;
2068 Buffer.add_string
b pattern
;
2069 Buffer.add_char
b '
\000'
;
2072 writecmd state.csock
cmd;
2075 let intentry text key =
2076 let c = Char.unsafe_chr
key in
2079 let text = addchar text c in
2083 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2087 let textentry text key =
2088 let c = Char.unsafe_chr
key in
2090 | _
when key >= 32 && key < 127 ->
2091 let text = addchar text c in
2095 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
2099 let reqlayout angle proportional
=
2100 match state.throttle
with
2102 if state.invalidated
= 0 then state.anchor <- getanchor ();
2103 conf.angle
<- angle
mod 360;
2104 conf.proportional
<- proportional
;
2106 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
2110 let settrim trimmargins trimfuzz
=
2111 if state.invalidated
= 0 then state.anchor <- getanchor ();
2112 conf.trimmargins
<- trimmargins
;
2113 conf.trimfuzz
<- trimfuzz
;
2114 let x0, y0
, x1
, y1 = trimfuzz
in
2117 `
b conf.trimmargins
;
2123 Hashtbl.iter
(fun _ opaque
->
2124 wcmd "freepage" [`
s opaque
];
2126 Hashtbl.clear
state.pagemap
;
2130 match state.throttle
with
2132 let zoom = max
0.01 zoom in
2133 if zoom <> conf.zoom
2135 state.prevzoom
<- conf.zoom;
2138 then (state.x <- 0; 0.0)
2139 else float state.x /. float state.w
2142 reshape conf.winw
conf.winh
;
2145 let x = relx *. float state.w in
2146 state.x <- truncate
x;
2148 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2151 | Some
(layout, y, started
) ->
2153 match conf.maxwait
with
2157 let dt = now () -. started
in
2165 let setcolumns columns coverA coverB
=
2168 conf.columns
<- None
;
2173 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2176 reshape conf.winw
conf.winh
;
2179 let enterbirdseye () =
2180 let zoom = float conf.thumbw
/. float conf.winw
in
2181 let birdseyepageno =
2182 let cy = conf.winh
/ 2 in
2186 let rec fold best
= function
2189 let d = cy - (l.pagedispy + l.pagevh/2)
2190 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2191 if abs
d < abs dbest
2198 state.mode
<- Birdseye
(
2199 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2202 conf.presentation <- false;
2203 conf.interpagespace <- 10;
2204 conf.hlinks
<- false;
2206 state.mstate
<- Mnone
;
2207 conf.maxwait
<- None
;
2209 match conf.beyecolumns
with
2212 Some
((c, 0, 0), [||])
2215 Glut.setCursor
Glut.CURSOR_INHERIT
;
2218 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2223 reshape conf.winw
conf.winh
;
2226 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2228 conf.zoom <- c.zoom;
2229 conf.presentation <- c.presentation;
2230 conf.interpagespace <- c.interpagespace;
2231 conf.maxwait
<- c.maxwait
;
2232 conf.hlinks
<- c.hlinks
;
2233 conf.beyecolumns
<- (
2234 match conf.columns
with
2235 | Some
((c, _
, _
), _
) -> Some
c
2239 match c.columns
with
2240 | Some
(c, _
) -> Some
(c, [||])
2246 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2249 reshape conf.winw
conf.winh
;
2250 state.anchor <- if goback
then anchor else (pageno, 0.0);
2253 let togglebirdseye () =
2254 match state.mode
with
2255 | Birdseye vals
-> leavebirdseye vals
true
2256 | View
-> enterbirdseye ()
2260 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2261 let pageno = max
0 (pageno - incr
) in
2262 let rec loop = function
2263 | [] -> gotopage1 pageno 0
2264 | l :: _
when l.pageno = pageno ->
2265 if l.pagedispy >= 0 && l.pagey = 0
2266 then G.postRedisplay "upbirdseye"
2267 else gotopage1 pageno 0
2268 | _
:: rest
-> loop rest
2271 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2274 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2275 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2276 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2277 let rec loop = function
2279 let y, h = getpageyh pageno in
2280 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2282 | l :: _
when l.pageno = pageno ->
2283 if l.pagevh != l.pageh
2284 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2285 else G.postRedisplay "downbirdseye"
2286 | _
:: rest
-> loop rest
2291 let optentry mode _
key =
2292 let btos b = if b then "on" else "off" in
2293 let c = Char.unsafe_chr
key in
2297 try conf.scrollstep
<- int_of_string
s with exc
->
2298 state.text <- Printf.sprintf
"bad integer `%s': %s"
2299 s (Printexc.to_string exc
)
2301 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2306 conf.autoscrollstep
<- int_of_string
s;
2307 if state.autoscroll
<> None
2308 then state.autoscroll
<- Some
conf.autoscrollstep
2310 state.text <- Printf.sprintf
"bad integer `%s': %s"
2311 s (Printexc.to_string exc
)
2313 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2318 let n, a, b = columns_of_string s in
2321 state.text <- Printf.sprintf
"bad columns `%s': %s"
2322 s (Printexc.to_string exc
)
2324 TEswitch
("columns: ", "", None
, textentry, ondone)
2329 let zoom = float (int_of_string
s) /. 100.0 in
2332 state.text <- Printf.sprintf
"bad integer `%s': %s"
2333 s (Printexc.to_string exc
)
2335 TEswitch
("zoom: ", "", None
, intentry, ondone)
2340 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2342 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2343 begin match mode
with
2345 leavebirdseye beye
false;
2350 state.text <- Printf.sprintf
"bad integer `%s': %s"
2351 s (Printexc.to_string exc
)
2353 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2358 Some
(int_of_string
s)
2360 state.text <- Printf.sprintf
"bad integer `%s': %s"
2361 s (Printexc.to_string exc
);
2364 | Some angle
-> reqlayout angle
conf.proportional
2367 TEswitch
("rotation: ", "", None
, intentry, ondone)
2370 conf.icase
<- not
conf.icase
;
2371 TEdone
("case insensitive search " ^
(btos conf.icase
))
2374 conf.preload <- not
conf.preload;
2376 TEdone
("preload " ^
(btos conf.preload))
2379 conf.verbose
<- not
conf.verbose
;
2380 TEdone
("verbose " ^
(btos conf.verbose
))
2383 conf.debug
<- not
conf.debug
;
2384 TEdone
("debug " ^
(btos conf.debug
))
2387 conf.maxhfit
<- not
conf.maxhfit
;
2389 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2390 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2393 conf.crophack
<- not
conf.crophack
;
2394 TEdone
("crophack " ^
btos conf.crophack
)
2398 match conf.maxwait
with
2400 conf.maxwait
<- Some infinity
;
2401 "always wait for page to complete"
2403 conf.maxwait
<- None
;
2404 "show placeholder if page is not ready"
2409 conf.underinfo
<- not
conf.underinfo
;
2410 TEdone
("underinfo " ^
btos conf.underinfo
)
2413 conf.savebmarks
<- not
conf.savebmarks
;
2414 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2420 match state.layout with
2425 conf.interpagespace <- int_of_string
s;
2426 state.maxy <- calcheight ();
2427 let y = getpagey pageno in
2430 state.text <- Printf.sprintf
"bad integer `%s': %s"
2431 s (Printexc.to_string exc
)
2433 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2436 reqlayout conf.angle
(not
conf.proportional
);
2437 TEdone
("proportional display " ^
btos conf.proportional
)
2440 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2441 TEdone
("trim margins " ^
btos conf.trimmargins
)
2444 conf.invert
<- not
conf.invert
;
2445 TEdone
("invert colors " ^
btos conf.invert
)
2448 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2452 class type lvsource
= object
2453 method getitemcount
: int
2454 method getitem
: int -> (string * int)
2455 method hasaction
: int -> bool
2464 method getactive
: int
2465 method getfirst
: int
2466 method getqsearch
: string
2467 method setqsearch
: string -> unit
2471 class virtual lvsourcebase
= object
2472 val mutable m_active
= 0
2473 val mutable m_first
= 0
2474 val mutable m_qsearch
= ""
2475 val mutable m_pan
= 0
2476 method getactive
= m_active
2477 method getfirst
= m_first
2478 method getqsearch
= m_qsearch
2479 method getpan
= m_pan
2480 method setqsearch
s = m_qsearch
<- s
2483 let textentryspecial key = function
2484 | ((c, _
, (Some
(action, _
) as onhist), onkey
, ondone), mode
) ->
2487 | Glut.KEY_UP
-> action HCprev
2488 | Glut.KEY_DOWN
-> action HCnext
2489 | Glut.KEY_HOME
-> action HCfirst
2490 | Glut.KEY_END
-> action HClast
2493 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2494 G.postRedisplay "special textentry";
2498 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2500 state.mode
<- Textentry
(te
, onleave
);
2503 G.postRedisplay "textentrykeyboard enttext";
2505 match Char.unsafe_chr
key with
2506 | '
\008'
-> (* backspace *)
2507 let len = String.length
text in
2511 G.postRedisplay "textentrykeyboard after cancel";
2514 let s = String.sub
text 0 (len - 1) in
2515 enttext (c, s, opthist
, onkey
, ondone)
2521 G.postRedisplay "textentrykeyboard after confirm"
2523 | '
\007'
(* ctrl-g *)
2524 | '
\027'
-> (* escape *)
2525 if String.length
text = 0
2527 begin match opthist
with
2529 | Some
(_
, onhistcancel
) -> onhistcancel
()
2533 G.postRedisplay "textentrykeyboard after cancel2"
2536 enttext (c, "", opthist
, onkey
, ondone)
2539 | '
\127'
-> () (* delete *)
2542 begin match onkey
text key with
2546 G.postRedisplay "textentrykeyboard after confirm2";
2549 enttext (c, text, opthist
, onkey
, ondone);
2553 G.postRedisplay "textentrykeyboard after cancel3"
2556 state.mode
<- Textentry
(te
, onleave
);
2557 G.postRedisplay "textentrykeyboard switch";
2561 let firstof first active
=
2562 if first
> active
|| abs
(first
- active
) > fstate.maxrows
- 1
2563 then max
0 (active
- (fstate.maxrows
/2))
2567 let calcfirst first active
=
2570 let rows = active
- first
in
2571 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2575 let scrollph y maxy =
2576 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2577 let sh = float conf.winh
/. sh in
2578 let sh = max
sh (float conf.scrollh
) in
2583 else float y /. float maxy
2585 let position = (float conf.winh
-. sh) *. percent in
2588 if position +. sh > float conf.winh
2589 then float conf.winh
-. sh
2595 let coe s = (s :> uioh
);;
2597 class listview ~
(source
:lvsource
) ~trusted
=
2599 val m_pan
= source#getpan
2600 val m_first
= source#getfirst
2601 val m_active
= source#getactive
2602 val m_qsearch
= source#getqsearch
2603 val m_prev_uioh
= state.uioh
2605 method private elemunder
y =
2606 let n = y / (fstate.fontsize
+1) in
2607 if m_first
+ n < source#getitemcount
2609 if source#hasaction
(m_first
+ n)
2610 then Some
(m_first
+ n)
2617 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2618 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2619 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2620 GlDraw.color
(1., 1., 1.);
2621 Gl.enable `texture_2d
;
2622 let fs = fstate.fontsize
in
2624 let ww = fstate.wwidth
in
2625 let tabw = 30.0*.ww in
2626 let itemcount = source#getitemcount
in
2628 if (row - m_first
) * nfs > conf.winh
2631 if row >= 0 && row < itemcount
2633 let (s, level
) = source#getitem
row in
2634 let y = (row - m_first
) * nfs in
2635 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2638 Gl.disable `texture_2d
;
2639 GlDraw.polygon_mode `both `line
;
2640 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2641 GlDraw.rect (1., float (y + 1))
2642 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2643 GlDraw.polygon_mode `both `fill
;
2644 GlDraw.color
(1., 1., 1.);
2645 Gl.enable `texture_2d
;
2648 let drawtabularstring s =
2649 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2652 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2655 let len = String.length
s - tabpos - 1 in
2656 let s1 = String.sub
s 0 tabpos
2657 and s2
= String.sub
s (tabpos + 1) len in
2658 let nx = drawstr x s1 in
2660 let x = x +. (max
tabw sw) in
2667 let _ = drawtabularstring s in
2674 Gl.disable `texture_2d
;
2676 method updownlevel incr
=
2677 let len = source#getitemcount
in
2679 if m_active
>= 0 && m_active
< len
2680 then snd
(source#getitem m_active
)
2684 if i
= len then i
-1 else if i
= -1 then 0 else
2685 let _, l = source#getitem i
in
2686 if l != curlevel then i
else flow (i
+incr
)
2688 let active = flow m_active
in
2689 let first = calcfirst m_first
active in
2690 G.postRedisplay "special outline updownlevel";
2691 {< m_active
= active; m_first
= first >}
2693 method private key1
key =
2694 let set active first qsearch
=
2695 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2697 let search active pattern incr
=
2700 if n >= 0 && n < source#getitemcount
2702 let s, _ = source#getitem
n in
2704 (try ignore
(Str.search_forward
re s 0); true
2705 with Not_found
-> false)
2707 else loop (n + incr
)
2714 let re = Str.regexp_case_fold pattern
in
2721 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2722 let incr = if key = 18 then -1 else 1 in
2724 match search (m_active
+ incr) m_qsearch
incr with
2726 state.text <- m_qsearch ^
" [not found]";
2729 state.text <- m_qsearch
;
2730 active, firstof m_first
active
2732 G.postRedisplay "listview ctrl-r/s";
2733 set active first m_qsearch
;
2735 | 8 -> (* backspace *)
2736 let len = String.length m_qsearch
in
2743 G.postRedisplay "listview empty qsearch";
2744 set m_active m_first
"";
2747 let qsearch = String.sub m_qsearch
0 (len - 1) in
2749 match search m_active
qsearch ~
-1 with
2751 state.text <- qsearch ^
" [not found]";
2754 state.text <- qsearch;
2755 active, firstof m_first
active
2757 G.postRedisplay "listview backspace qsearch";
2758 set active first qsearch
2761 | _ when key >= 32 && key < 127 ->
2762 let pattern = addchar m_qsearch
(Char.chr
key) in
2764 match search m_active
pattern 1 with
2766 state.text <- pattern ^
" [not found]";
2769 state.text <- pattern;
2770 active, firstof m_first
active
2772 G.postRedisplay "listview qsearch add";
2773 set active first pattern;
2775 | 27 -> (* escape *)
2777 if String.length m_qsearch
= 0
2779 G.postRedisplay "list view escape";
2782 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2784 | None
-> m_prev_uioh
2789 G.postRedisplay "list view kill qsearch";
2790 source#setqsearch
"";
2791 coe {< m_qsearch
= "" >}
2796 let self = {< m_qsearch
= "" >} in
2797 source#setqsearch
"";
2799 G.postRedisplay "listview enter";
2800 if m_active
>= 0 && m_active
< source#getitemcount
2802 source#exit
(coe self) false m_active m_first m_pan
"";
2805 source#exit
(coe self) true m_active m_first m_pan
"";
2808 begin match opt with
2809 | None
-> m_prev_uioh
2813 | 127 -> (* delete *)
2816 | _ -> dolog "unknown key %d" key; coe self
2818 method private special1
key =
2819 let itemcount = source#getitemcount
in
2820 let find start
incr =
2822 if i
= -1 || i
= itemcount
2825 if source#hasaction i
2827 else find (i
+ incr)
2832 let set active first =
2833 let first = bound first 0 (itemcount - fstate.maxrows
) in
2835 coe {< m_active
= active; m_first
= first >}
2838 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2840 let incr1 = if incr > 0 then 1 else -1 in
2841 if isvisible m_first m_active
2844 let next = m_active
+ incr in
2846 if next < 0 || next >= itemcount
2848 else find next incr1
2850 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2856 let first = m_first
+ incr in
2857 let first = bound first 0 (itemcount - 1) in
2859 let next = m_active
+ incr in
2860 let next = bound next 0 (itemcount - 1) in
2863 let active = if next = -1 then m_active
else next in
2866 let first = min
next m_first
in
2868 if abs
(next - first) > fstate.maxrows
2874 let first = m_first
+ incr in
2875 let first = bound first 0 (itemcount - 1) in
2877 let next = m_active
+ incr in
2878 let next = bound next 0 (itemcount - 1) in
2879 let next = find next incr1 in
2881 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2883 let active = if m_active
= -1 then next else m_active
in
2888 if isvisible first active
2894 G.postRedisplay "listview navigate";
2897 begin match key with
2898 | Glut.KEY_UP
-> navigate ~
-1
2899 | Glut.KEY_DOWN
-> navigate 1
2900 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2901 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2905 G.postRedisplay "listview right";
2906 coe {< m_pan
= m_pan
- 1 >}
2910 G.postRedisplay "listview left";
2911 coe {< m_pan
= m_pan
+ 1 >}
2914 let active = find 0 1 in
2915 G.postRedisplay "listview home";
2919 let first = max
0 (itemcount - fstate.maxrows
) in
2920 let active = find (itemcount - 1) ~
-1 in
2921 G.postRedisplay "listview end";
2928 match state.mode
with
2929 | Textentry te
-> textentrykeyboard key te
; coe self
2930 | _ -> self#key1
key
2932 method special
key =
2933 match state.mode
with
2934 | Textentry te
-> textentryspecial key te
; coe self
2935 | _ -> self#special1
key
2937 method button button bstate
x y =
2940 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollbw
->
2941 G.postRedisplay "listview scroll";
2942 if bstate
= Glut.DOWN
2944 let _, position, sh = self#
scrollph in
2945 if y > truncate
position && y < truncate
(position +. sh)
2947 state.mstate
<- Mscrolly
;
2951 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2952 let first = truncate
(s *. float source#getitemcount
) in
2953 let first = min source#getitemcount
first in
2954 Some
(coe {< m_first
= first; m_active
= first >})
2956 state.mstate
<- Mnone
;
2959 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2960 begin match self#elemunder
y with
2962 G.postRedisplay "listview click";
2964 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
2968 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2969 let len = source#getitemcount
in
2971 if n = 4 && m_first
+ fstate.maxrows
>= len
2975 let first = m_first
+ (if n == 3 then -1 else 1) in
2976 bound first 0 (len - 1)
2978 G.postRedisplay "listview wheel";
2979 Some
(coe {< m_first
= first >})
2984 | None
-> m_prev_uioh
2988 match state.mstate
with
2990 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2991 let first = truncate
(s *. float source#getitemcount
) in
2992 let first = min source#getitemcount
first in
2993 G.postRedisplay "listview motion";
2994 coe {< m_first
= first; m_active
= first >}
2997 method pmotion
x y =
2998 if x < conf.winw
- conf.scrollbw
3001 match self#elemunder
y with
3002 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
3003 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
3007 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3012 Glut.setCursor
Glut.CURSOR_INHERIT
;
3016 method infochanged
_ = ()
3018 method scrollpw
= (0, 0.0, 0.0)
3020 let nfs = fstate.fontsize
+ 1 in
3021 let y = m_first
* nfs in
3022 let itemcount = source#getitemcount
in
3023 let maxi = max
0 (itemcount - fstate.maxrows
) in
3024 let maxy = maxi * nfs in
3025 let p, h = scrollph y maxy in
3029 class outlinelistview ~source
=
3031 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
3035 | 14 -> (* ctrl-n *)
3036 source#narrow m_qsearch
;
3037 G.postRedisplay "outline ctrl-n";
3038 coe {< m_first
= 0; m_active
= 0 >}
3040 | 21 -> (* ctrl-u *)
3042 G.postRedisplay "outline ctrl-u";
3044 coe {< m_first
= 0; m_active
= 0 >}
3046 | 12 -> (* ctrl-l *)
3047 let first = m_active
- (fstate.maxrows
/ 2) in
3048 G.postRedisplay "outline ctrl-l";
3049 coe {< m_first
= first >}
3051 | 127 -> (* delete *)
3052 source#remove m_active
;
3053 G.postRedisplay "outline delete";
3054 let active = max
0 (m_active
-1) in
3055 coe {< m_first
= firstof m_first
active;
3056 m_active
= active >}
3058 | key -> super#
key key
3060 method special
key =
3061 let calcfirst first active =
3064 let rows = active - first in
3065 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3069 let active = m_active
+ incr in
3070 let active = bound active 0 (source#getitemcount
- 1) in
3071 let first = calcfirst m_first
active in
3072 G.postRedisplay "special outline navigate";
3073 coe {< m_active
= active; m_first
= first >}
3076 | Glut.KEY_UP
-> navigate ~
-1
3077 | Glut.KEY_DOWN
-> navigate 1
3078 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
3079 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
3083 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
3085 G.postRedisplay "special outline right";
3086 {< m_pan
= m_pan
+ 1 >}
3088 else self#updownlevel
1
3094 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
3096 G.postRedisplay "special outline left";
3097 {< m_pan
= m_pan
- 1 >}
3099 else self#updownlevel ~
-1
3104 G.postRedisplay "special outline home";
3105 coe {< m_first
= 0; m_active
= 0 >}
3108 let active = source#getitemcount
- 1 in
3109 let first = max
0 (active - fstate.maxrows
) in
3110 G.postRedisplay "special outline end";
3111 coe {< m_active
= active; m_first
= first >}
3113 | _ -> super#special
key
3116 let outlinesource usebookmarks
=
3119 inherit lvsourcebase
3120 val mutable m_items
= empty
3121 val mutable m_orig_items
= empty
3122 val mutable m_prev_items
= empty
3123 val mutable m_narrow_pattern
= ""
3124 val mutable m_hadremovals
= false
3126 method getitemcount
=
3127 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3130 if n == Array.length m_items
&& m_hadremovals
3132 ("[Confirm removal]", 0)
3134 let s, n, _ = m_items
.(n) in
3137 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3138 ignore
(uioh
, first, pan
, qsearch);
3139 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3141 if String.length m_narrow_pattern
= 0
3147 if not
confrimremoval
3149 let _, _, anchor = m_items
.(active) in
3154 state.bookmarks
<- Array.to_list m_items
;
3155 m_orig_items
<- m_items
;
3158 else m_items
<- items;
3161 method hasaction
_ = true
3164 if Array.length m_items
!= Array.length m_orig_items
3165 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3168 method narrow
pattern =
3169 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3173 let rec loop accu n =
3176 m_narrow_pattern
<- pattern;
3177 m_items
<- Array.of_list
accu
3180 let (s, _, _) as o = m_items
.(n) in
3182 if (try ignore
(Str.search_forward
re s 0); true
3183 with Not_found
-> false)
3189 loop [] (Array.length m_items
- 1)
3194 then Array.of_list
state.bookmarks
3197 m_items
<- m_orig_items
3202 if m
>= 0 && m
< Array.length m_items
3204 m_hadremovals
<- true;
3205 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3206 let n = if n >= m
then n+1 else n in
3211 method reset
anchor items =
3212 m_hadremovals
<- false;
3213 if m_orig_items
== empty || m_prev_items
!= items
3215 m_orig_items
<- items;
3216 if String.length m_narrow_pattern
= 0
3217 then m_items
<- items;
3219 m_prev_items
<- items;
3220 let rely = getanchory anchor in
3222 let rec loop n best bestd
=
3223 if n = Array.length m_items
3226 let (_, _, anchor) = m_items
.(n) in
3227 let orely = getanchory anchor in
3228 let d = abs
(orely - rely) in
3231 else loop (n+1) best bestd
3236 m_first
<- firstof m_first
active
3240 let enterselector usebookmarks
=
3241 let source = outlinesource usebookmarks
in
3245 then Array.of_list
state.bookmarks
3248 if Array.length
outlines = 0
3250 showtext ' ' errmsg
;
3253 state.text <- source#greetmsg
;
3254 Glut.setCursor
Glut.CURSOR_INHERIT
;
3255 let anchor = getanchor () in
3256 source#reset
anchor outlines;
3257 state.uioh
<- coe (new outlinelistview ~
source);
3258 G.postRedisplay "enter selector";
3262 let enteroutlinemode =
3263 let f = enterselector false in
3264 fun ()-> f "Document has no outline";
3267 let enterbookmarkmode =
3268 let f = enterselector true in
3269 fun () -> f "Document has no bookmarks (yet)";
3272 let color_of_string s =
3273 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3274 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3278 let color_to_string (r, g
, b) =
3279 let r = truncate
(r *. 256.0)
3280 and g
= truncate
(g
*. 256.0)
3281 and b = truncate
(b *. 256.0) in
3282 Printf.sprintf
"%d/%d/%d" r g
b
3285 let irect_of_string s =
3286 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1
y1 -> (x0,y0
,x1
,y1))
3289 let irect_to_string (x0,y0
,x1
,y1) =
3290 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1
y1
3293 let makecheckers () =
3294 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3296 converted by Issac Trotts. July 25, 2002 *)
3297 let image_height = 64
3298 and image_width
= 64 in
3302 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3304 for i
= 0 to image_width
- 1 do
3305 for j
= 0 to image_height - 1 do
3306 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3307 (if (i
land 8 ) lxor (j
land 8) = 0
3308 then [|255;255;255|] else [|200;200;200|])
3313 let image = make_image () in
3314 let id = GlTex.gen_texture
() in
3315 GlTex.bind_texture `texture_2d
id;
3316 GlPix.store
(`unpack_alignment
1);
3317 GlTex.image2d
image;
3318 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3321 `mag_filter `nearest
;
3322 `min_filter `nearest
];
3326 let setcheckers enabled
=
3327 match state.texid
with
3329 if enabled
then state.texid
<- Some
(makecheckers ())
3334 GlTex.delete_texture texid
;
3335 state.texid
<- None
;
3339 let int_of_string_with_suffix s =
3340 let l = String.length
s in
3344 let suffix = Char.lowercase
s.[l-1] in
3346 | 'k'
-> String.sub
s 0 (l-1), 10
3347 | 'm'
-> String.sub
s 0 (l-1), 20
3348 | 'g'
-> String.sub
s 0 (l-1), 30
3352 let n = int_of_string
s1 in
3353 let m = n lsl shift
in
3355 then raise
(Failure
"value too large")
3359 let string_with_suffix_of_int n =
3367 if n land ((1 lsl 20) - 1) = 0
3370 if n land ((1 lsl 10) - 1) = 0
3377 let h = n mod 1000 in
3380 then string_of_int
h ^
s
3382 let s = Printf.sprintf
"_%03d%s" h s in
3389 let defghyllscroll = (40, 8, 32);;
3390 let ghyllscroll_of_string s =
3391 let (n, a, b) as nab
=
3394 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3396 if n <= a || n <= b || a >= b
3397 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3401 let ghyllscroll_to_string ((n, a, b) as nab
) =
3402 if nab
= defghyllscroll
3404 else Printf.sprintf
"%d,%d,%d" n a b;
3407 let describe_location () =
3409 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3411 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3412 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3416 else (100. *. (float state.y /. float maxy))
3420 Printf.sprintf
"page %d of %d [%.2f%%]"
3421 (fn+1) state.pagecount
percent
3424 "pages %d-%d of %d [%.2f%%]"
3425 (fn+1) (ln
+1) state.pagecount
percent
3429 let btos b = if b then "\xe2\x88\x9a" else "" in
3430 let showextended = ref false in
3431 let leave mode
= function
3432 | Confirm
-> state.mode
<- mode
3433 | Cancel
-> state.mode
<- mode
in
3436 val mutable m_first_time
= true
3437 val mutable m_l
= []
3438 val mutable m_a
= [||]
3439 val mutable m_prev_uioh
= nouioh
3440 val mutable m_prev_mode
= View
3442 inherit lvsourcebase
3444 method reset prev_mode prev_uioh
=
3445 m_a
<- Array.of_list
(List.rev m_l
);
3447 m_prev_mode
<- prev_mode
;
3448 m_prev_uioh
<- prev_uioh
;
3452 if n >= Array.length m_a
3456 | _, _, _, Action
_ -> m_active
<- n
3460 m_first_time
<- false;
3463 method int name get
set =
3465 (name
, `
int get
, 1, Action
(
3468 try set (int_of_string
s)
3470 state.text <- Printf.sprintf
"bad integer `%s': %s"
3471 s (Printexc.to_string exn
)
3474 let te = name ^
": ", "", None
, intentry, ondone in
3475 state.mode
<- Textentry
(te, leave m_prev_mode
);
3479 method int_with_suffix name get
set =
3481 (name
, `intws get
, 1, Action
(
3484 try set (int_of_string_with_suffix s)
3486 state.text <- Printf.sprintf
"bad integer `%s': %s"
3487 s (Printexc.to_string exn
)
3491 name ^
": ", "", None
, intentry_with_suffix, ondone
3493 state.mode
<- Textentry
(te, leave m_prev_mode
);
3497 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3499 (name
, `
bool (btos, get
), offset
, Action
(
3506 method color name get
set =
3508 (name
, `color get
, 1, Action
(
3510 let invalid = (nan
, nan
, nan
) in
3513 try color_of_string s
3515 state.text <- Printf.sprintf
"bad color `%s': %s"
3516 s (Printexc.to_string exn
);
3522 let te = name ^
": ", "", None
, textentry, ondone in
3523 state.text <- color_to_string (get
());
3524 state.mode
<- Textentry
(te, leave m_prev_mode
);
3528 method string name get
set =
3530 (name
, `
string get
, 1, Action
(
3532 let ondone s = set s in
3533 let te = name ^
": ", "", None
, textentry, ondone in
3534 state.mode
<- Textentry
(te, leave m_prev_mode
);
3538 method colorspace name get
set =
3540 (name
, `
string get
, 1, Action
(
3543 let vals = [| "rgb"; "bgr"; "gray" |] in
3545 inherit lvsourcebase
3548 m_active
<- int_of_colorspace conf.colorspace
;
3551 method getitemcount
= Array.length
vals
3552 method getitem
n = (vals.(n), 0)
3553 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3554 ignore
(uioh
, first, pan
, qsearch);
3555 if not cancel
then set active;
3557 method hasaction
_ = true
3561 coe (new listview ~
source ~trusted
:true)
3564 method caption
s offset
=
3565 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3567 method caption2
s f offset
=
3568 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3570 method getitemcount
= Array.length m_a
3573 let tostr = function
3574 | `
int f -> string_of_int
(f ())
3575 | `intws
f -> string_with_suffix_of_int (f ())
3577 | `color
f -> color_to_string (f ())
3578 | `
bool (btos, f) -> btos (f ())
3581 let name, t
, offset
, _ = m_a
.(n) in
3582 ((let s = tostr t
in
3583 if String.length
s > 0
3584 then Printf.sprintf
"%s\t%s" name s
3588 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3592 m_qsearch
<- qsearch;
3594 match m_a
.(active) with
3595 | _, _, _, Action
f -> f uioh
3607 method hasaction
n =
3609 | _, _, _, Action
_ -> true
3613 let rec fillsrc prevmode prevuioh
=
3614 let sep () = src#caption
"" 0 in
3615 let colorp name get
set =
3617 (fun () -> color_to_string (get
()))
3620 let c = color_of_string v in
3623 state.text <- Printf.sprintf
"bad color `%s': %s"
3624 v (Printexc.to_string exn
);
3627 let oldmode = state.mode
in
3628 let birdseye = isbirdseye state.mode
in
3630 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3632 src#
bool "presentation mode"
3633 (fun () -> conf.presentation)
3635 conf.presentation <- v;
3636 state.anchor <- getanchor ();
3639 src#
bool "ignore case in searches"
3640 (fun () -> conf.icase
)
3641 (fun v -> conf.icase
<- v);
3644 (fun () -> conf.preload)
3645 (fun v -> conf.preload <- v);
3647 src#
bool "highlight links"
3648 (fun () -> conf.hlinks
)
3649 (fun v -> conf.hlinks
<- v);
3651 src#
bool "under info"
3652 (fun () -> conf.underinfo
)
3653 (fun v -> conf.underinfo
<- v);
3655 src#
bool "persistent bookmarks"
3656 (fun () -> conf.savebmarks
)
3657 (fun v -> conf.savebmarks
<- v);
3659 src#
bool "proportional display"
3660 (fun () -> conf.proportional
)
3661 (fun v -> reqlayout conf.angle
v);
3663 src#
bool "trim margins"
3664 (fun () -> conf.trimmargins
)
3665 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3667 src#
bool "persistent location"
3668 (fun () -> conf.jumpback
)
3669 (fun v -> conf.jumpback
<- v);
3672 src#
int "inter-page space"
3673 (fun () -> conf.interpagespace)
3675 conf.interpagespace <- n;
3677 match state.layout with
3682 state.maxy <- calcheight ();
3683 let y = getpagey pageno in
3688 (fun () -> conf.pagebias
)
3689 (fun v -> conf.pagebias
<- v);
3691 src#
int "scroll step"
3692 (fun () -> conf.scrollstep
)
3693 (fun n -> conf.scrollstep
<- n);
3695 src#
int "auto scroll step"
3697 match state.autoscroll
with
3699 | _ -> conf.autoscrollstep
)
3701 if state.autoscroll
<> None
3702 then state.autoscroll
<- Some
n;
3703 conf.autoscrollstep
<- n);
3706 (fun () -> truncate
(conf.zoom *. 100.))
3707 (fun v -> setzoom ((float v) /. 100.));
3710 (fun () -> conf.angle
)
3711 (fun v -> reqlayout v conf.proportional
);
3713 src#
int "scroll bar width"
3714 (fun () -> state.scrollw
)
3718 reshape conf.winw
conf.winh
;
3721 src#
int "scroll handle height"
3722 (fun () -> conf.scrollh
)
3723 (fun v -> conf.scrollh
<- v;);
3725 src#
int "thumbnail width"
3726 (fun () -> conf.thumbw
)
3728 conf.thumbw
<- min
4096 v;
3731 leavebirdseye beye
false;
3736 src#
string "columns"
3738 match conf.columns
with
3740 | Some
(multicol
, _) -> columns_to_string multicol
)
3742 let n, a, b = columns_of_string v in
3746 src#caption
"Presentation mode" 0;
3747 src#
bool "scrollbar visible"
3748 (fun () -> conf.scrollbarinpm
)
3750 if v != conf.scrollbarinpm
3752 conf.scrollbarinpm
<- v;
3753 if conf.presentation
3755 state.scrollw
<- if v then conf.scrollbw
else 0;
3756 reshape conf.winw
conf.winh
;
3762 src#caption
"Pixmap cache" 0;
3763 src#int_with_suffix
"size (advisory)"
3764 (fun () -> conf.memlimit
)
3765 (fun v -> conf.memlimit
<- v);
3768 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3769 (string_with_suffix_of_int state.memused
)
3770 (Hashtbl.length
state.tilemap
)) 1;
3773 src#caption
"Layout" 0;
3774 src#caption2
"Dimension"
3776 Printf.sprintf
"%dx%d (virtual %dx%d)"
3782 src#caption2
"Position" (fun () ->
3783 Printf.sprintf
"%dx%d" state.x state.y
3786 src#caption2
"Visible" (fun () -> describe_location ()) 1
3790 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3791 "Save these parameters as global defaults at exit"
3792 (fun () -> conf.bedefault
)
3793 (fun v -> conf.bedefault
<- v)
3797 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3798 src#
bool ~offset
:0 ~
btos "Extended parameters"
3799 (fun () -> !showextended)
3800 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3804 (fun () -> conf.checkers
)
3805 (fun v -> conf.checkers
<- v; setcheckers v);
3807 (fun () -> conf.verbose
)
3808 (fun v -> conf.verbose
<- v);
3809 src#
bool "invert colors"
3810 (fun () -> conf.invert
)
3811 (fun v -> conf.invert
<- v);
3813 (fun () -> conf.maxhfit
)
3814 (fun v -> conf.maxhfit
<- v);
3815 src#
bool "redirect stderr"
3816 (fun () -> conf.redirectstderr)
3817 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3818 src#
string "uri launcher"
3819 (fun () -> conf.urilauncher
)
3820 (fun v -> conf.urilauncher
<- v);
3821 src#
string "tile size"
3822 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3825 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3826 conf.tileh
<- max
64 w;
3827 conf.tilew
<- max
64 h;
3830 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3831 v (Printexc.to_string exn
));
3832 src#
int "texture count"
3833 (fun () -> conf.texcount
)
3836 then conf.texcount
<- v
3837 else showtext '
!'
" Failed to set texture count please retry later"
3839 src#
int "slice height"
3840 (fun () -> conf.sliceheight
)
3842 conf.sliceheight
<- v;
3843 wcmd "sliceh" [`i
conf.sliceheight
];
3845 src#
int "anti-aliasing level"
3846 (fun () -> conf.aalevel
)
3848 conf.aalevel
<- bound v 0 8;
3849 state.anchor <- getanchor ();
3850 opendoc state.path
state.password
;
3852 src#
int "ui font size"
3853 (fun () -> fstate.fontsize
)
3854 (fun v -> setfontsize (bound v 5 100));
3855 colorp "background color"
3856 (fun () -> conf.bgcolor
)
3857 (fun v -> conf.bgcolor
<- v);
3858 src#
bool "crop hack"
3859 (fun () -> conf.crophack
)
3860 (fun v -> conf.crophack
<- v);
3861 src#
string "trim fuzz"
3862 (fun () -> irect_to_string conf.trimfuzz
)
3865 conf.trimfuzz
<- irect_of_string v;
3867 then settrim true conf.trimfuzz
;
3869 state.text <- Printf.sprintf
"bad irect `%s': %s"
3870 v (Printexc.to_string exn
)
3872 src#
string "throttle"
3874 match conf.maxwait
with
3875 | None
-> "show place holder if page is not ready"
3878 then "wait for page to fully render"
3880 "wait " ^ string_of_float
time
3881 ^
" seconds before showing placeholder"
3885 let f = float_of_string
v in
3887 then conf.maxwait
<- None
3888 else conf.maxwait
<- Some
f
3890 state.text <- Printf.sprintf
"bad time `%s': %s"
3891 v (Printexc.to_string exn
)
3893 src#
string "ghyll scroll"
3895 match conf.ghyllscroll
with
3897 | Some nab
-> ghyllscroll_to_string nab
3902 if String.length
v = 0
3904 else Some
(ghyllscroll_of_string v)
3906 conf.ghyllscroll
<- gs
3908 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
3909 v (Printexc.to_string exn
)
3911 src#colorspace
"color space"
3912 (fun () -> colorspace_to_string conf.colorspace
)
3914 conf.colorspace
<- colorspace_of_int v;
3921 src#caption
"Document" 0;
3922 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3923 src#caption2
"Pages"
3924 (fun () -> string_of_int
state.pagecount
) 1;
3925 src#caption2
"Dimensions"
3926 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3930 src#caption
"Trimmed margins" 0;
3931 src#caption2
"Dimensions"
3932 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3935 src#reset prevmode prevuioh
;
3939 let prevmode = state.mode
3940 and prevuioh
= state.uioh in
3941 fillsrc prevmode prevuioh
;
3942 let source = (src :> lvsource
) in
3943 state.uioh <- coe (object (self)
3944 inherit listview ~
source ~trusted
:true as super
3945 val mutable m_prevmemused
= 0
3946 method infochanged
= function
3948 if m_prevmemused
!= state.memused
3950 m_prevmemused
<- state.memused
;
3951 G.postRedisplay "memusedchanged";
3953 | Pdim
-> G.postRedisplay "pdimchanged"
3954 | Docinfo
-> fillsrc prevmode prevuioh
3956 method special
key =
3957 if Glut.getModifiers
() land Glut.active_ctrl
= 0
3960 | Glut.KEY_LEFT
-> coe (self#updownlevel ~
-1)
3961 | Glut.KEY_RIGHT
-> coe (self#updownlevel
1)
3962 | _ -> super#special
key
3963 else super#special
key
3965 G.postRedisplay "info";
3971 inherit lvsourcebase
3972 method getitemcount
= Array.length
state.help
3974 let s, n, _ = state.help
.(n) in
3977 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3981 m_qsearch
<- qsearch;
3982 match state.help
.(active) with
3983 | _, _, Action
f -> Some
(f uioh)
3993 method hasaction
n =
3994 match state.help
.(n) with
3995 | _, _, Action
_ -> true
4002 state.uioh <- coe (new listview ~
source ~trusted
:true);
4003 G.postRedisplay "help";
4008 let re = Str.regexp
"[\r\n]" in
4010 inherit lvsourcebase
4011 val mutable m_items
= [||]
4013 method getitemcount
= 1 + Array.length m_items
4018 else m_items
.(n-1), 0
4020 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4025 then Buffer.clear
state.errmsgs
;
4026 m_qsearch
<- qsearch;
4033 method hasaction
n =
4037 state.newerrmsgs
<- false;
4038 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4039 m_items
<- Array.of_list
l
4047 let source = (msgsource :> lvsource
) in
4048 state.uioh <- coe (object
4049 inherit listview ~
source ~trusted
:false as super
4052 then msgsource#reset
;
4055 G.postRedisplay "msgs";
4058 let quickbookmark ?title
() =
4059 match state.layout with
4065 let sec = Unix.gettimeofday
() in
4066 let tm = Unix.localtime
sec in
4067 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4071 (tm.Unix.tm_year
+ 1900)
4074 | Some
title -> title
4077 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4082 state.fullscreen
<- None
;
4083 Glut.reshapeWindow
w h;
4086 let viewkeyboard key =
4088 let mode = state.mode in
4089 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4092 G.postRedisplay "view:enttext"
4094 let c = Char.chr
key in
4096 | '
\027'
| 'q'
-> (* escape *)
4097 begin match state.mstate
with
4099 state.mstate
<- Mnone
;
4100 Glut.setCursor
Glut.CURSOR_INHERIT
;
4101 G.postRedisplay "kill zoom rect";
4106 | '
\008'
-> (* backspace *)
4107 let y = getnav ~
-1 in
4108 gotoy_and_clear_text y
4116 G.postRedisplay "dehighlight";
4119 let ondone isforw
s =
4120 cbput state.hists
.pat
s;
4121 state.searchpattern
<- s;
4124 let s = String.create
1 in
4126 enttext (s, "", Some
(onhist state.hists
.pat
),
4127 textentry, ondone (c ='
/'
))
4129 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4130 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4131 setzoom (conf.zoom +. incr)
4136 try int_of_string
s with exc
->
4137 state.text <- Printf.sprintf
"bad integer `%s': %s"
4138 s (Printexc.to_string exc
);
4144 state.text <- "page bias is now " ^ string_of_int
n;
4147 enttext ("page bias: ", "", None
, intentry, ondone)
4149 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4150 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4151 setzoom (max
0.01 (conf.zoom -. decr))
4154 let ondone msg
= state.text <- msg
in
4156 "option [acfhilpstvACPRSZTI]: ", "", None
,
4157 optentry state.mode, ondone
4160 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4163 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4164 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4168 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4174 try int_of_string
s with exc
->
4175 state.text <- Printf.sprintf
"bad integer `%s': %s"
4176 s (Printexc.to_string exc
);
4182 cbput state.hists
.pag
(string_of_int
n);
4183 gotopage1 (n + conf.pagebias
- 1) 0;
4186 let pageentry text key =
4187 match Char.unsafe_chr
key with
4188 | 'g'
-> TEdone
text
4189 | _ -> intentry text key
4191 let text = "x" in text.[0] <- c;
4192 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4195 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4196 reshape conf.winw
conf.winh
;
4199 conf.hlinks
<- not
conf.hlinks
;
4200 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4201 G.postRedisplay "toggle highlightlinks";
4204 begin match state.autoscroll
with
4206 conf.autoscrollstep
<- step
;
4207 state.autoscroll
<- None
4209 if conf.autoscrollstep
= 0
4210 then state.autoscroll
<- Some
1
4211 else state.autoscroll
<- Some
conf.autoscrollstep
4215 conf.presentation <- not
conf.presentation;
4216 if conf.presentation
4218 if not
conf.scrollbarinpm
4219 then state.scrollw
<- 0;
4222 state.scrollw
<- conf.scrollbw
;
4224 showtext ' '
("presentation mode " ^
4225 if conf.presentation then "on" else "off");
4226 state.anchor <- getanchor ();
4230 begin match state.fullscreen
with
4232 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4235 state.fullscreen
<- None
;
4240 gotoy_and_clear_text 0
4243 gotopage1 (state.pagecount
- 1) 0
4246 search state.searchpattern
true
4249 search state.searchpattern
false
4252 begin match state.layout with
4255 gotoy_and_clear_text (getpagey l.pageno)
4259 begin match List.rev
state.layout with
4262 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4263 gotoy_and_clear_text (getpagey pageno)
4266 | '
\127'
-> (* del *)
4267 begin match state.layout with
4270 let pageno = max
0 (l.pageno-1) in
4271 gotoy_and_clear_text (getpagey pageno)
4275 showtext ' '
(describe_location ());
4278 begin match state.layout with
4281 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4286 enterbookmarkmode ()
4294 | '
e'
when conf.redirectstderr ->
4299 match state.layout with
4302 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4306 enttext ("bookmark: ", "", None
, textentry, ondone)
4310 showtext ' '
"Quick bookmark added";
4313 begin match state.layout with
4315 let rect = getpdimrect
l.pagedimno
in
4319 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4320 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4322 (truncate
(rect.(1) -. rect.(0)),
4323 truncate
(rect.(3) -. rect.(0)))
4325 let w = truncate
((float w)*.conf.zoom)
4326 and h = truncate
((float h)*.conf.zoom) in
4329 state.anchor <- getanchor ();
4330 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4332 G.postRedisplay "z";
4337 | '
\000'
-> (* ctrl-2 *)
4338 let maxw = getmaxw
() in
4340 then setzoom (maxw /. float conf.winw
)
4343 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
4347 bound (conf.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
4349 G.postRedisplay "brightness";
4352 begin match state.mode with
4353 | Birdseye beye
-> upbirdseye 1 beye
4354 | _ -> gotoy (clamp (-conf.scrollstep
))
4358 begin match state.mode with
4359 | Birdseye beye
-> downbirdseye 1 beye
4360 | _ -> gotoy (clamp conf.scrollstep
)
4364 state.anchor <- getanchor ();
4365 opendoc state.path
state.password
4367 | '
v'
when not
conf.debug
->
4368 List.iter
debugl state.layout;
4370 | '
v'
when conf.debug
->
4373 match getopaque l.pageno with
4376 let x0, y0
, x1
, y1 = pagebbox opaque
in
4377 let a,b = float x0, float y0
in
4378 let c,d = float x1
, float y0
in
4379 let e,f = float x1
, float y1 in
4380 let h,j
= float x0, float y1 in
4381 let rect = (a,b,c,d,e,f,h,j
) in
4383 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4385 G.postRedisplay "v";
4388 vlog "huh? %d %c" key (Char.chr
key);
4391 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
4393 | 27 -> (* escape *)
4394 leavebirdseye beye
true
4396 | 12 -> (* ctrl-l *)
4397 let y, h = getpageyh pageno in
4398 let top = (conf.winh
- h) / 2 in
4399 gotoy (max
0 (y - top))
4402 leavebirdseye beye
false
4408 let keyboard ~
key ~
x ~
y =
4411 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
4412 then wcmd "interrupt" []
4413 else state.uioh <- state.uioh#
key key
4416 let birdseyespecial key ((oconf
, leftx
, _, hooverpageno
, anchor) as beye
) =
4418 match conf.columns
with
4420 | Some
((c, _, _), _) -> c
4423 | Glut.KEY_UP
-> upbirdseye incr beye
4424 | Glut.KEY_DOWN
-> downbirdseye incr beye
4425 | Glut.KEY_LEFT
-> upbirdseye 1 beye
4426 | Glut.KEY_RIGHT
-> downbirdseye 1 beye
4428 | Glut.KEY_PAGE_UP
->
4429 begin match state.layout with
4433 state.mode <- Birdseye
(
4434 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4436 gotopage1 l.pageno 0;
4439 let layout = layout (state.y-conf.winh
) conf.winh
in
4441 | [] -> gotoy (clamp (-conf.winh
))
4443 state.mode <- Birdseye
(
4444 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4446 gotopage1 l.pageno 0
4449 | [] -> gotoy (clamp (-conf.winh
))
4452 | Glut.KEY_PAGE_DOWN
->
4453 begin match List.rev
state.layout with
4455 let layout = layout (state.y + conf.winh
) conf.winh
in
4456 begin match layout with
4458 let incr = l.pageh
- l.pagevh in
4463 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4465 G.postRedisplay "birdseye pagedown";
4467 else gotoy (clamp (incr + conf.interpagespace*2));
4471 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4472 gotopage1 l.pageno 0;
4475 | [] -> gotoy (clamp conf.winh
)
4479 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4483 let pageno = state.pagecount
- 1 in
4484 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4485 if not
(pagevisible state.layout pageno)
4488 match List.rev
state.pdims
with
4490 | (_, _, h, _) :: _ -> h
4492 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4493 else G.postRedisplay "birdseye end";
4497 let setautoscrollspeed step goingdown
=
4498 let incr = max
1 ((abs step
) / 2) in
4499 let incr = if goingdown
then incr else -incr in
4500 let astep = step
+ incr in
4501 state.autoscroll
<- Some
astep;
4504 let special ~
key ~
x ~
y =
4507 state.uioh <- state.uioh#
special key
4512 match state.mode with
4513 | Textentry
_ -> scalecolor 0.4
4514 | View
-> scalecolor 1.0
4515 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4516 if l.pageno = hooverpageno
4519 if l.pageno = pageno
4525 begin match getopaque l.pageno with
4527 if tileready l l.pagex l.pagey
4529 let x = l.pagedispx - l.pagex
4530 and y = l.pagedispy - l.pagey in
4531 postprocess opaque
conf.hlinks
x y;
4537 let scrollindicator () =
4538 let sbw, ph
, sh = state.uioh#
scrollph in
4539 let sbh, pw
, sw = state.uioh#scrollpw
in
4541 GlDraw.color (0.64, 0.64, 0.64);
4543 (float (conf.winw
- sbw), 0.)
4544 (float conf.winw
, float conf.winh
)
4547 (0., float (conf.winh
- sbh))
4548 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4550 GlDraw.color (0.0, 0.0, 0.0);
4553 (float (conf.winw
- sbw), ph
)
4554 (float conf.winw
, ph
+. sh)
4557 (pw
, float (conf.winh
- sbh))
4558 (pw
+. sw, float conf.winh
)
4562 let pagetranslatepoint l x y =
4563 let dy = y - l.pagedispy in
4564 let y = dy + l.pagey in
4565 let dx = x - l.pagedispx in
4566 let x = dx + l.pagex in
4571 match state.mstate
with
4572 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4575 | Msel
((x0, y0
), (x1
, y1)) ->
4576 let rec loop = function
4578 if ((y0
>= l.pagedispy && y0
<= (l.pagedispy + l.pagevh))
4579 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4580 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4581 || ((x1
>= l.pagedispx && x1
<= (l.pagedispx + l.pagevw))))
4583 match getopaque l.pageno with
4585 let dx, dy = pagetranslatepoint l 0 0 in
4590 GlMat.mode `modelview
;
4592 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4593 seltext opaque
(x0, y0
, x1
, y1);
4604 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4605 GlDraw.polygon_mode `both `fill
;
4606 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4608 (fun (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) ->
4610 if l.pageno = pageno
4612 let dx = float (l.pagedispx - l.pagex) in
4613 let dy = float (l.pagedispy - l.pagey) in
4614 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4615 GlDraw.begins `quads
;
4617 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4618 GlDraw.vertex2
(x1
+.dx, y1+.dy);
4619 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4620 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4631 GlClear.color (scalecolor2 conf.bgcolor
);
4632 GlClear.clear
[`
color];
4633 List.iter
drawpage state.layout;
4638 begin match state.mstate
with
4639 | Mzoomrect
((x0, y0
), (x1
, y1)) ->
4641 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4642 GlDraw.polygon_mode `both `fill
;
4643 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4644 GlDraw.rect (float x0, float y0
)
4645 (float x1
, float y1);
4650 Glut.swapBuffers
();
4654 let rec f = function
4656 begin match getopaque l.pageno with
4658 let x0 = l.pagedispx in
4659 let x1 = x0 + l.pagevw in
4660 let y0 = l.pagedispy in
4661 let y1 = y0 + l.pagevh in
4662 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4664 let px, py = pagetranslatepoint l x y in
4665 match whatsunder opaque
px py with
4677 let zoomrect x y x1 y1 =
4680 and y0 = min
y y1 in
4681 gotoy (state.y + y0);
4682 state.anchor <- getanchor ();
4683 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4685 if state.w < conf.winw
- state.scrollw
4686 then (conf.winw
- state.scrollw
- state.w) / 2
4689 state.x <- (state.x + margin) - x0;
4691 Glut.setCursor
Glut.CURSOR_INHERIT
;
4692 state.mstate
<- Mnone
;
4696 let winw = conf.winw - state.scrollw
- 1 in
4697 let s = float x /. float winw in
4698 let destx = truncate
(float (state.w + winw) *. s) in
4699 state.x <- winw - destx;
4700 gotoy_and_clear_text state.y;
4701 state.mstate
<- Mscrollx
;
4705 let s = float y /. float conf.winh
in
4706 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4707 gotoy_and_clear_text desty;
4708 state.mstate
<- Mscrolly
;
4711 let viewmouse button bstate
x y =
4713 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4714 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4716 match state.mstate
with
4717 | Mzoom
(oldn
, i
) ->
4725 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4727 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4729 let zoom = conf.zoom -. incr in
4731 state.mstate
<- Mzoom
(n, 0);
4733 state.mstate
<- Mzoom
(n, i
+1);
4735 else state.mstate
<- Mzoom
(n, 0)
4737 | _ -> state.mstate
<- Mzoom
(n, 0)
4740 match state.autoscroll
with
4741 | Some step
-> setautoscrollspeed step
(n=4)
4745 then -conf.scrollstep
4746 else conf.scrollstep
4748 let incr = incr * 2 in
4749 let y = clamp incr in
4750 gotoy_and_clear_text y
4753 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4754 if bstate
= Glut.DOWN
4756 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4757 state.mstate
<- Mpan
(x, y)
4760 state.mstate
<- Mnone
4762 | Glut.RIGHT_BUTTON
->
4763 if bstate
= Glut.DOWN
4765 Glut.setCursor
Glut.CURSOR_CYCLE
;
4767 state.mstate
<- Mzoomrect
(p, p)
4770 match state.mstate
with
4771 | Mzoomrect
((x0, y0), _) ->
4772 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4773 then zoomrect x0 y0 x y
4775 state.mstate
<- Mnone
;
4776 Glut.setCursor
Glut.CURSOR_INHERIT
;
4777 G.postRedisplay "kill accidental zoom rect";
4780 Glut.setCursor
Glut.CURSOR_INHERIT
;
4781 state.mstate
<- Mnone
4784 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4785 if bstate
= Glut.DOWN
4787 let _, position, sh = state.uioh#
scrollph in
4788 if y > truncate
position && y < truncate
(position +. sh)
4789 then state.mstate
<- Mscrolly
4792 state.mstate
<- Mnone
4794 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4795 if bstate
= Glut.DOWN
4797 let _, position, sw = state.uioh#scrollpw
in
4798 if x > truncate
position && x < truncate
(position +. sw)
4799 then state.mstate
<- Mscrollx
4802 state.mstate
<- Mnone
4804 | Glut.LEFT_BUTTON
->
4805 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4806 begin match dest with
4807 | Ulinkgoto
(pageno, top) ->
4811 gotopage1 pageno top;
4817 | Unone
when bstate
= Glut.DOWN
->
4818 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4819 state.mstate
<- Mpan
(x, y);
4821 | Unone
| Utext
_ ->
4822 if bstate
= Glut.DOWN
4824 if conf.angle
mod 360 = 0
4826 state.mstate
<- Msel
((x, y), (x, y));
4827 G.postRedisplay "mouse select";
4831 match state.mstate
with
4834 | Mzoom
_ | Mscrollx
| Mscrolly
->
4835 state.mstate
<- Mnone
4837 | Mzoomrect
((x0, y0), _) ->
4841 Glut.setCursor
Glut.CURSOR_INHERIT
;
4842 state.mstate
<- Mnone
4844 | Msel
((_, y0), (_, y1)) ->
4846 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4847 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh)))
4849 match getopaque l.pageno with
4854 List.iter
f state.layout;
4855 copysel
""; (* ugly *)
4856 Glut.setCursor
Glut.CURSOR_INHERIT
;
4857 state.mstate
<- Mnone
;
4864 let birdseyemouse button bstate
x y
4865 (conf, leftx
, _, hooverpageno
, anchor) =
4867 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4868 let rec loop = function
4871 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4872 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4874 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4879 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4883 let mouse bstate button
x y =
4884 state.uioh <- state.uioh#button button bstate
x y;
4887 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4890 state.uioh <- state.uioh#
motion x y
4894 state.uioh <- state.uioh#
pmotion x y;
4901 begin match state.mode with
4902 | Textentry
textentry -> textentrykeyboard key textentry
4903 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4904 | View
-> viewkeyboard key
4908 method special key =
4909 begin match state.mode with
4910 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4914 birdseyespecial key vals
4916 | View
when key = Glut.KEY_F1
->
4920 begin match state.autoscroll
with
4921 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4922 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4927 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4929 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4931 if Glut.getModifiers
() land Glut.active_shift
!= 0
4932 then (setzoom state.prevzoom
; state.y)
4933 else clamp (-conf.winh
/2)
4934 else clamp (-conf.scrollstep
)
4936 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4938 if Glut.getModifiers
() land Glut.active_shift
!= 0
4939 then (setzoom state.prevzoom
; state.y)
4940 else clamp (conf.winh
/2)
4941 else clamp (conf.scrollstep
)
4942 | Glut.KEY_PAGE_UP
->
4943 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4945 match state.layout with
4947 | l :: _ -> state.y - l.pagey
4950 | Glut.KEY_PAGE_DOWN
->
4951 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4953 match List.rev
state.layout with
4955 | l :: _ -> getpagey l.pageno
4963 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
4965 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
4966 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
4967 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
4969 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
4971 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4972 then (conf.winw / 2)
4975 state.x <- state.x - dx;
4977 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
4979 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4980 then (conf.winw / 2)
4983 state.x <- state.x + dx;
4988 if abs
(state.y - y) > conf.scrollstep
*2
4990 else gotoy_and_clear_text y
4993 | Textentry
te -> textentryspecial key te
4997 method button button bstate
x y =
4998 begin match state.mode with
4999 | View
-> viewmouse button bstate
x y
5000 | Birdseye beye
-> birdseyemouse button bstate
x y beye
5006 begin match state.mode with
5008 | View
| Birdseye
_ ->
5009 match state.mstate
with
5010 | Mzoom
_ | Mnone
-> ()
5015 state.mstate
<- Mpan
(x, y);
5016 if conf.zoom > 1.0 then state.x <- state.x + dx;
5018 gotoy_and_clear_text y
5021 state.mstate
<- Msel
(a, (x, y));
5022 G.postRedisplay "motion select";
5025 let y = min
conf.winh
(max
0 y) in
5029 let x = min
conf.winw (max
0 x) in
5032 | Mzoomrect
(p0
, _) ->
5033 state.mstate
<- Mzoomrect
(p0
, (x, y));
5034 G.postRedisplay "motion zoomrect";
5038 method pmotion x y =
5039 begin match state.mode with
5040 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5041 let rec loop = function
5043 if hooverpageno
!= -1
5045 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5046 G.postRedisplay "pmotion birdseye no hoover";
5049 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5050 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5052 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5053 G.postRedisplay "pmotion birdseye hoover";
5062 match state.mstate
with
5064 begin match getunder x y with
5065 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
5067 if conf.underinfo
then showtext 'u'
("ri: " ^
uri);
5068 Glut.setCursor
Glut.CURSOR_INFO
5069 | Ulinkgoto
(page
, _) ->
5071 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
5072 Glut.setCursor
Glut.CURSOR_INFO
5074 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
5075 Glut.setCursor
Glut.CURSOR_TEXT
5078 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5083 method infochanged
_ = ()
5086 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5087 let p, h = scrollph state.y maxy in
5091 let winw = conf.winw - state.scrollw
- 1 in
5092 let fwinw = float winw in
5094 let sw = fwinw /. float state.w in
5095 let sw = fwinw *. sw in
5096 max
sw (float conf.scrollh
)
5099 let f = state.w+winw in
5100 let r = float (winw-state.x) /. float f in
5101 let p = fwinw *. r in
5105 if position +. sw > fwinw
5106 then fwinw -. position
5109 state.hscrollh, position, sw
5116 let fontpath = ref "";;
5117 let wmclasshack = ref false;;
5120 let l = String.length
s in
5121 let b = Buffer.create
l in
5129 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
5130 | _ -> Sys.getenv
"HOME"
5133 ("Can not determine home directory location: " ^
5134 Printexc.to_string exn
);
5138 let config_of c attrs
=
5142 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5143 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5144 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5145 | "preload" -> { c with preload = bool_of_string
v }
5146 | "page-bias" -> { c with pagebias
= int_of_string
v }
5147 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5148 | "auto-scroll-step" ->
5149 { c with autoscrollstep
= max
0 (int_of_string
v) }
5150 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5151 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5154 match String.lowercase
v with
5155 | "true" -> Some infinity
5157 | f -> Some
(float_of_string
f)
5159 { c with maxwait
= mw}
5160 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5161 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5162 | "vertical-margin" ->
5163 { c with interpagespace = max
0 (int_of_string
v) }
5165 let zoom = float_of_string
v /. 100. in
5166 let zoom = max
zoom 0.0 in
5167 { c with zoom = zoom }
5168 | "presentation" -> { c with presentation = bool_of_string
v }
5169 | "rotation-angle" -> { c with angle
= int_of_string
v }
5170 | "width" -> { c with winw = max
20 (int_of_string
v) }
5171 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5172 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5173 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5174 | "pixmap-cache-size" ->
5175 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5176 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5177 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5178 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5179 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5180 | "background-color" -> { c with bgcolor
= color_of_string v }
5181 | "scrollbar-in-presentation" ->
5182 { c with scrollbarinpm
= bool_of_string
v }
5183 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5184 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5185 | "mupdf-store-size" ->
5186 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5187 | "checkers" -> { c with checkers
= bool_of_string
v }
5188 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5189 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5190 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5191 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
5192 | "uri-launcher" -> { c with urilauncher
= unent v }
5193 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5194 | "invert-colors" -> { c with invert
= bool_of_string
v }
5195 | "brightness" -> { c with colorscale
= float_of_string
v }
5196 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5198 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5200 let nab = columns_of_string v in
5201 { c with columns
= Some
(nab, [||]) }
5202 | "birds-eye-columns" ->
5203 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5206 prerr_endline
("Error processing attribute (`" ^
5207 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5210 let rec fold c = function
5213 let c = apply c k
v in
5219 let fromstring f pos
n v d =
5222 dolog "Error processing attribute (%S=%S) at %d\n%s"
5223 n v pos
(Printexc.to_string exn
)
5228 let bookmark_of attrs
=
5229 let rec fold title page
rely = function
5230 | ("title", v) :: rest
-> fold v page
rely rest
5231 | ("page", v) :: rest
-> fold title v rely rest
5232 | ("rely", v) :: rest
-> fold title page
v rest
5233 | _ :: rest
-> fold title page
rely rest
5234 | [] -> title, page
, rely
5236 fold "invalid" "0" "0" attrs
5240 let rec fold path page
rely pan
= function
5241 | ("path", v) :: rest
-> fold v page
rely pan rest
5242 | ("page", v) :: rest
-> fold path
v rely pan rest
5243 | ("rely", v) :: rest
-> fold path page
v pan rest
5244 | ("pan", v) :: rest
-> fold path page
rely v rest
5245 | _ :: rest
-> fold path page
rely pan rest
5246 | [] -> path
, page
, rely, pan
5248 fold "" "0" "0" "0" attrs
5251 let setconf dst
src =
5252 dst
.scrollbw
<- src.scrollbw
;
5253 dst
.scrollh
<- src.scrollh
;
5254 dst
.icase
<- src.icase
;
5255 dst
.preload <- src.preload;
5256 dst
.pagebias
<- src.pagebias
;
5257 dst
.verbose
<- src.verbose
;
5258 dst
.scrollstep
<- src.scrollstep
;
5259 dst
.maxhfit
<- src.maxhfit
;
5260 dst
.crophack
<- src.crophack
;
5261 dst
.autoscrollstep
<- src.autoscrollstep
;
5262 dst
.maxwait
<- src.maxwait
;
5263 dst
.hlinks
<- src.hlinks
;
5264 dst
.underinfo
<- src.underinfo
;
5265 dst
.interpagespace <- src.interpagespace;
5266 dst
.zoom <- src.zoom;
5267 dst
.presentation <- src.presentation;
5268 dst
.angle
<- src.angle
;
5269 dst
.winw <- src.winw;
5270 dst
.winh
<- src.winh
;
5271 dst
.savebmarks
<- src.savebmarks
;
5272 dst
.memlimit
<- src.memlimit
;
5273 dst
.proportional
<- src.proportional
;
5274 dst
.texcount
<- src.texcount
;
5275 dst
.sliceheight
<- src.sliceheight
;
5276 dst
.thumbw
<- src.thumbw
;
5277 dst
.jumpback
<- src.jumpback
;
5278 dst
.bgcolor
<- src.bgcolor
;
5279 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5280 dst
.tilew
<- src.tilew
;
5281 dst
.tileh
<- src.tileh
;
5282 dst
.mustoresize
<- src.mustoresize
;
5283 dst
.checkers
<- src.checkers
;
5284 dst
.aalevel
<- src.aalevel
;
5285 dst
.trimmargins
<- src.trimmargins
;
5286 dst
.trimfuzz
<- src.trimfuzz
;
5287 dst
.urilauncher
<- src.urilauncher
;
5288 dst
.colorspace
<- src.colorspace
;
5289 dst
.invert
<- src.invert
;
5290 dst
.colorscale
<- src.colorscale
;
5291 dst
.redirectstderr <- src.redirectstderr;
5292 dst
.ghyllscroll
<- src.ghyllscroll
;
5293 dst
.columns
<- src.columns
;
5294 dst
.beyecolumns
<- src.beyecolumns
;
5298 let h = Hashtbl.create
10 in
5299 let dc = { defconf with angle
= defconf.angle
} in
5300 let rec toplevel v t spos
_ =
5302 | Vdata
| Vcdata
| Vend
-> v
5303 | Vopen
("llppconfig", _, closed
) ->
5306 else { v with f = llppconfig
}
5308 error
"unexpected subelement at top level" s spos
5309 | Vclose
_ -> error
"unexpected close at top level" s spos
5311 and llppconfig
v t spos
_ =
5313 | Vdata
| Vcdata
-> v
5314 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5315 | Vopen
("defaults", attrs
, closed
) ->
5316 let c = config_of dc attrs
in
5320 else { v with f = skip
"defaults" (fun () -> v) }
5322 | Vopen
("ui-font", attrs
, closed
) ->
5323 let rec getsize size
= function
5325 | ("size", v) :: rest
->
5327 fromstring int_of_string spos
"size" v fstate.fontsize
in
5329 | l -> getsize size l
5331 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5334 else { v with f = uifont
(Buffer.create
10) }
5336 | Vopen
("doc", attrs
, closed
) ->
5337 let pathent, spage
, srely
, span
= doc_of attrs
in
5338 let path = unent pathent
5339 and pageno = fromstring int_of_string spos
"page" spage
0
5340 and rely = fromstring float_of_string spos
"rely" srely
0.0
5341 and pan
= fromstring int_of_string spos
"pan" span
0 in
5342 let c = config_of dc attrs
in
5343 let anchor = (pageno, rely) in
5345 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5346 else { v with f = doc
path pan
anchor c [] }
5349 error
"unexpected subelement in llppconfig" s spos
5351 | Vclose
"llppconfig" -> { v with f = toplevel }
5352 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5354 and uifont
b v t spos epos
=
5357 Buffer.add_substring
b s spos
(epos
- spos
);
5359 | Vopen
(_, _, _) ->
5360 error
"unexpected subelement in ui-font" s spos
5361 | Vclose
"ui-font" ->
5362 if String.length
!fontpath = 0
5363 then fontpath := Buffer.contents
b;
5364 { v with f = llppconfig
}
5365 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5366 | Vend
-> error
"unexpected end of input in ui-font" s spos
5368 and doc
path pan
anchor c bookmarks
v t spos
_ =
5370 | Vdata
| Vcdata
-> v
5371 | Vend
-> error
"unexpected end of input in doc" s spos
5372 | Vopen
("bookmarks", _, closed
) ->
5375 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5377 | Vopen
(_, _, _) ->
5378 error
"unexpected subelement in doc" s spos
5381 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5382 { v with f = llppconfig
}
5384 | Vclose
_ -> error
"unexpected close in doc" s spos
5386 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5388 | Vdata
| Vcdata
-> v
5389 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5390 | Vopen
("item", attrs
, closed
) ->
5391 let titleent, spage
, srely
= bookmark_of attrs
in
5392 let page = fromstring int_of_string spos
"page" spage
0
5393 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5394 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5396 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5399 { v with f = skip
"item" f }
5402 error
"unexpected subelement in bookmarks" s spos
5404 | Vclose
"bookmarks" ->
5405 { v with f = doc
path pan
anchor c bookmarks }
5407 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5409 and skip tag
f v t spos
_ =
5411 | Vdata
| Vcdata
-> v
5413 error
("unexpected end of input in skipped " ^ tag
) s spos
5414 | Vopen
(tag'
, _, closed
) ->
5418 let f'
() = { v with f = skip tag
f } in
5419 { v with f = skip tag'
f'
}
5423 else error
("unexpected close in skipped " ^ tag
) s spos
5426 parse
{ f = toplevel; accu = () } s;
5432 let len = in_channel_length ic
in
5433 let s = String.create
len in
5434 really_input ic
s 0 len;
5437 | Parse_error
(msg
, s, pos
) ->
5438 let subs = subs s pos
in
5439 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5440 failwith
("parse error: " ^
s)
5443 failwith
("config load error: " ^
Printexc.to_string exn
)
5449 let dir = Filename.concat
home ".config" in
5450 if Sys.is_directory
dir then dir else home
5453 Filename.concat
dir "llpp.conf"
5456 let confpath = ref defconfpath;;
5459 if Sys.file_exists
!confpath
5462 (try Some
(open_in_bin
!confpath)
5465 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5466 Printexc.to_string exn
);
5475 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5476 Printexc.to_string exn
);
5482 f (Hashtbl.create
0, defconf)
5487 let pc, pb
, px, pa
=
5489 Hashtbl.find h (Filename.basename
state.path)
5490 with Not_found
-> dc, [], 0, (0, 0.0)
5494 state.bookmarks <- pb
;
5496 state.scrollw
<- conf.scrollbw
;
5498 then state.anchor <- pa
;
5499 cbput state.hists
.nav pa
;
5504 let add_attrs bb always
dc c =
5507 then Printf.bprintf bb
"\n %s='%b'" s a
5510 then Printf.bprintf bb
"\n %s='%d'" s a
5513 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5516 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5519 then Printf.bprintf bb
"\n %s='%f'" s a
5523 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5527 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5531 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5535 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5541 | Some
(_N
, _A
, _B
) ->
5542 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
5552 else string_of_float
f
5554 Printf.bprintf bb
"\n %s='%s'" s v
5559 | Some
((n, a, b), _) when n > 1 ->
5560 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
5566 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
5571 then dc.winw, dc.winh
5573 match state.fullscreen
with
5575 | None
-> c.winw, c.winh
5577 let zoom, presentation, interpagespace, maxwait
=
5579 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5581 match state.mode with
5582 | Birdseye
(bc
, _, _, _, _) ->
5583 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5584 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5586 oi
"width" w dc.winw;
5587 oi
"height" h dc.winh
;
5588 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5589 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5590 ob "case-insensitive-search" c.icase
dc.icase
;
5591 ob "preload" c.preload dc.preload;
5592 oi
"page-bias" c.pagebias
dc.pagebias
;
5593 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5594 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5595 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5596 ob "crop-hack" c.crophack
dc.crophack
;
5597 oW
"throttle" maxwait
dc.maxwait
;
5598 ob "highlight-links" c.hlinks
dc.hlinks
;
5599 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5600 oi
"vertical-margin" interpagespace dc.interpagespace;
5601 oz
"zoom" zoom dc.zoom;
5602 ob "presentation" presentation dc.presentation;
5603 oi
"rotation-angle" c.angle
dc.angle
;
5604 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5605 ob "proportional-display" c.proportional
dc.proportional
;
5606 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5607 oi
"tex-count" c.texcount
dc.texcount
;
5608 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5609 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5610 ob "persistent-location" c.jumpback
dc.jumpback
;
5611 oc
"background-color" c.bgcolor
dc.bgcolor
;
5612 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5613 oi
"tile-width" c.tilew
dc.tilew
;
5614 oi
"tile-height" c.tileh
dc.tileh
;
5615 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
5616 ob "checkers" c.checkers
dc.checkers
;
5617 oi
"aalevel" c.aalevel
dc.aalevel
;
5618 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5619 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5620 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5621 oC
"color-space" c.colorspace
dc.colorspace
;
5622 ob "invert-colors" c.invert
dc.invert
;
5623 oF
"brightness" c.colorscale
dc.colorscale
;
5624 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5625 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
5626 oco
"columns" c.columns
dc.columns
;
5627 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
5629 then ob "wmclass-hack" !wmclasshack false;
5633 let uifontsize = fstate.fontsize
in
5634 let bb = Buffer.create
32768 in
5636 let dc = if conf.bedefault
then conf else dc in
5637 Buffer.add_string
bb "<llppconfig>\n";
5639 if String.length
!fontpath > 0
5641 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5647 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5650 Buffer.add_string
bb "<defaults ";
5651 add_attrs bb true dc dc;
5652 Buffer.add_string
bb "/>\n";
5654 let adddoc path pan
anchor c bookmarks =
5655 if bookmarks == [] && c = dc && anchor = emptyanchor
5658 Printf.bprintf
bb "<doc path='%s'"
5659 (enent
path 0 (String.length
path));
5661 if anchor <> emptyanchor
5663 let n, y = anchor in
5664 Printf.bprintf
bb " page='%d'" n;
5667 Printf.bprintf
bb " rely='%f'" y
5672 then Printf.bprintf
bb " pan='%d'" pan
;
5674 add_attrs bb false dc c;
5676 begin match bookmarks with
5677 | [] -> Buffer.add_string
bb "/>\n"
5679 Buffer.add_string
bb ">\n<bookmarks>\n";
5680 List.iter
(fun (title, _level
, (page, rely)) ->
5682 "<item title='%s' page='%d'"
5683 (enent
title 0 (String.length
title))
5688 Printf.bprintf
bb " rely='%f'" rely
5690 Buffer.add_string
bb "/>\n";
5692 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5698 match state.mode with
5699 | Birdseye
(c, pan, _, _, _) ->
5701 match conf.columns
with
5702 | Some
((c, _, _), _) -> Some
c
5705 match c.columns
with
5706 | Some
(c, _) -> Some
(c, [||])
5709 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
5710 | _ -> state.x, conf
5712 let basename = Filename.basename state.path in
5713 adddoc basename pan (getanchor ())
5716 match state.autoscroll
with
5718 | None
-> conf.autoscrollstep
}
5719 (if conf.savebmarks
then state.bookmarks else []);
5721 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5723 then adddoc path x y c bookmarks
5725 Buffer.add_string
bb "</llppconfig>";
5728 if Buffer.length
bb > 0
5731 let tmp = !confpath ^
".tmp" in
5732 let oc = open_out_bin
tmp in
5733 Buffer.output_buffer
oc bb;
5735 Unix.rename
tmp !confpath;
5738 ("error while saving configuration: " ^
Printexc.to_string exn
)
5745 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5746 "<password> Set password");
5748 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5749 "<path> Set path to the user interface font");
5751 ("-c", Arg.String
(fun s -> Config.confpath := s),
5752 "<path> Set path to the configuration file");
5754 ("-v", Arg.Unit
(fun () ->
5756 "%s\nconfiguration path: %s\n"
5760 exit
0), " Print version and exit");
5763 (fun s -> state.path <- s)
5764 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5766 if String.length
state.path = 0
5767 then (prerr_endline
"file name missing"; exit
1);
5771 let _ = Glut.init
Sys.argv
in
5772 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5773 let () = Glut.initWindowSize
conf.winw conf.winh
in
5774 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5776 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5777 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5778 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5783 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5785 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5786 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5787 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5788 Unix.bind
sock addr;
5790 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5791 Unix.connect
csock addr;
5792 let ssock, _ = Unix.accept
sock in
5795 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5796 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5803 let () = Glut.displayFunc
display in
5804 let () = Glut.reshapeFunc
reshape in
5805 let () = Glut.keyboardFunc
keyboard in
5806 let () = Glut.specialFunc
special in
5807 let () = Glut.idleFunc
(Some
idle) in
5808 let () = Glut.mouseFunc
mouse in
5809 let () = Glut.motionFunc
motion in
5810 let () = Glut.passiveMotionFunc
pmotion in
5812 setcheckers conf.checkers
;
5814 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5815 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
5816 !Config.wmclasshack, !Config.fontpath
5818 state.csock <- csock;
5819 state.ssock <- ssock;
5820 state.text <- "Opening " ^
state.path;
5821 setaalevel
conf.aalevel
;
5822 writeopen state.path state.password
;
5824 setfontsize fstate.fontsize
;
5832 | Glut.BadEnum
"key in special_of_int" ->
5833 showtext '
!'
" LablGlut bug: special key not recognized";
5840 | exn
when conf.redirectstderr ->
5842 Printf.sprintf
"exception %s\n%s"
5843 (Printexc.to_string exn
)
5844 (Printexc.get_backtrace
())
5847 Unix.single_write
state.stderr
s 0 (String.length
s);