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
| Pmingw
| Pcygwin
;;
43 external init
: Unix.file_descr
-> params
-> unit = "ml_init";;
44 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
45 external copysel
: string -> unit = "ml_copysel";;
46 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
47 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
48 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
49 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
50 external measurestr
: int -> string -> float = "ml_measure_string";;
51 external getmaxw
: unit -> float = "ml_getmaxw";;
52 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
53 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
54 external platform
: unit -> platform
= "ml_platform";;
55 external setaalevel
: int -> unit = "ml_setaalevel";;
56 external realloctexts
: int -> bool = "ml_realloctexts";;
58 let platform_to_string = function
59 | Punknown
-> "unknown"
61 | Pwindows
-> "Windows"
64 | Pfreebsd
-> "FreeBSD"
65 | Pdragonflybsd
-> "DragonflyBSD"
66 | Popenbsd
-> "OpenBSD"
71 let platform = platform ();;
75 | Pwindows
| Pmingw
-> true
83 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
86 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
90 | Msel
of (mpos
* mpos
)
93 | Mzoom
of (int * int)
94 | Mzoomrect
of (mpos
* mpos
)
98 type textentry
= string * string * onhist
option * onkey
* ondone
99 and onkey
= string -> int -> te
100 and ondone
= string -> unit
101 and histcancel
= unit -> unit
102 and onhist
= ((histcmd
-> string) * histcancel
)
103 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
108 | TEswitch
of textentry
119 let bound v minv maxv
=
120 max minv
(min maxv v
);
124 { store
= Array.create n v
131 let drawstring size x y s
=
133 Gl.enable `texture_2d
;
134 ignore
(drawstr size x y s
);
136 Gl.disable `texture_2d
;
139 let drawstring1 size x y s
=
143 let drawstring2 size x y fmt
=
144 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
147 let cbcap b
= Array.length b
.store
;;
152 b
.wc
<- (b
.wc
+ 1) mod cap;
154 b
.len
<- min
(b
.len
+ 1) cap;
157 let cbempty b
= b
.len
= 0;;
159 let cbgetg b circular dir
=
163 let rc = b
.rc + dir
in
175 else max
0 (min
rc (b
.len
-1))
181 let cbget b
= cbgetg b
false;;
182 let cbgetc b
= cbgetg b
true;;
199 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
200 dolog " WxH %dx%d" l
.pagew l
.pageh
;
201 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
202 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
203 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
207 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
209 dolog " x0,y0=(% f, % f)" x0 y0
;
210 dolog " x1,y1=(% f, % f)" x1 y1
;
211 dolog " x2,y2=(% f, % f)" x2 y2
;
212 dolog " x3,y3=(% f, % f)" x3 y3
;
217 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
218 and multicol
= columncount
* covercount
* covercount
220 and columncount
= int
221 and covercount
= int;;
224 { mutable scrollbw
: int
225 ; mutable scrollh
: int
226 ; mutable icase
: bool
227 ; mutable preload
: bool
228 ; mutable pagebias
: int
229 ; mutable verbose
: bool
230 ; mutable debug
: bool
231 ; mutable scrollstep
: int
232 ; mutable maxhfit
: bool
233 ; mutable crophack
: bool
234 ; mutable autoscrollstep
: int
235 ; mutable maxwait
: float option
236 ; mutable hlinks
: bool
237 ; mutable underinfo
: bool
238 ; mutable interpagespace
: interpagespace
239 ; mutable zoom
: float
240 ; mutable presentation
: bool
241 ; mutable angle
: angle
244 ; mutable savebmarks
: bool
245 ; mutable proportional
: proportional
246 ; mutable trimmargins
: trimmargins
247 ; mutable trimfuzz
: irect
248 ; mutable memlimit
: memsize
249 ; mutable texcount
: texcount
250 ; mutable sliceheight
: sliceheight
251 ; mutable thumbw
: width
252 ; mutable jumpback
: bool
253 ; mutable bgcolor
: float * float * float
254 ; mutable bedefault
: bool
255 ; mutable scrollbarinpm
: bool
256 ; mutable tilew
: int
257 ; mutable tileh
: int
258 ; mutable mustoresize
: memsize
259 ; mutable checkers
: bool
260 ; mutable aalevel
: int
261 ; mutable urilauncher
: string
262 ; mutable colorspace
: colorspace
263 ; mutable invert
: bool
264 ; mutable colorscale
: float
265 ; mutable redirectstderr
: bool
266 ; mutable ghyllscroll
: (int * int * int) option
267 ; mutable columns
: columns
option
268 ; mutable beyecolumns
: columncount
option
272 type anchor
= pageno
* top
;;
274 type outline
= string * int * anchor
;;
276 type rect
= float * float * float * float * float * float * float * float;;
278 type tile
= opaque
* pixmapsize
* elapsed
279 and elapsed
= float;;
280 type pagemapkey
= pageno
* gen
;;
281 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
285 let emptyanchor = (0, 0.0);;
287 type infochange
= | Memused
| Docinfo
| Pdim
;;
289 class type uioh
= object
290 method display
: unit
291 method key
: int -> uioh
292 method special
: Glut.special_key_t
-> uioh
294 Glut.button_t
-> Glut.mouse_button_state_t
-> int -> int -> uioh
295 method motion
: int -> int -> uioh
296 method pmotion
: int -> int -> uioh
297 method infochanged
: infochange
-> unit
298 method scrollpw
: (int * float * float)
299 method scrollph
: (int * float * float)
303 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
304 | Textentry
of (textentry
* onleave
)
306 and onleave
= leavetextentrystatus
-> unit
307 and leavetextentrystatus
= | Cancel
| Confirm
308 and helpitem
= string * int * action
311 | Action
of (uioh
-> uioh
)
314 let isbirdseye = function Birdseye _
-> true | _
-> false;;
315 let istextentry = function Textentry _
-> true | _
-> false;;
319 | Loading
of (page
* gen
)
321 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
323 | Outlining
of outline list
326 let nouioh : uioh
= object (self
)
329 method special _
= self
330 method button _ _ _ _
= self
331 method motion _ _
= self
332 method pmotion _ _
= self
333 method infochanged _
= ()
334 method scrollpw
= (0, nan
, nan
)
335 method scrollph
= (0, nan
, nan
)
339 { mutable csock
: Unix.file_descr
340 ; mutable ssock
: Unix.file_descr
341 ; mutable errfd
: Unix.file_descr
option
342 ; mutable stderr
: Unix.file_descr
343 ; mutable errmsgs
: Buffer.t
344 ; mutable newerrmsgs
: bool
348 ; mutable scrollw
: int
349 ; mutable hscrollh
: int
350 ; mutable anchor
: anchor
352 ; mutable layout
: page list
353 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
354 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
355 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
356 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
357 ; mutable pagecount
: int
358 ; mutable currently
: currently
359 ; mutable mstate
: mstate
360 ; mutable searchpattern
: string
361 ; mutable rects
: (pageno
* recttype
* rect
) list
362 ; mutable rects1
: (pageno
* recttype
* rect
) list
363 ; mutable text
: string
364 ; mutable fullscreen
: (width
* height
) option
365 ; mutable mode
: mode
366 ; mutable uioh
: uioh
367 ; mutable outlines
: outline array
368 ; mutable bookmarks
: outline list
369 ; mutable path
: string
370 ; mutable password
: string
371 ; mutable invalidated
: int
372 ; mutable memused
: memsize
374 ; mutable throttle
: (page list
* int * float) option
375 ; mutable autoscroll
: int option
376 ; mutable ghyll
: int option -> unit
377 ; mutable help
: helpitem array
378 ; mutable docinfo
: (int * string) list
379 ; mutable deadline
: float
380 ; mutable texid
: GlTex.texture_id
option
382 ; mutable prevzoom
: float
383 ; mutable progress
: float
386 { pat
: string circbuf
387 ; pag
: string circbuf
388 ; nav
: anchor circbuf
409 ; presentation
= false
414 ; proportional
= true
415 ; trimmargins
= false
416 ; trimfuzz
= (0,0,0,0)
417 ; memlimit
= 32 lsl 20
422 ; bgcolor
= (0.5, 0.5, 0.5)
424 ; scrollbarinpm
= true
427 ; mustoresize
= 128 lsl 20
432 | Plinux
| Pfreebsd
| Pdragonflybsd
| Popenbsd
| Psun
-> "xdg-open \"%s\""
433 | Posx
-> "open \"%s\""
434 | Pwindows
| Pcygwin
| Pmingw
-> "iexplore \"%s\""
439 ; redirectstderr
= false
446 let conf = { defconf with angle
= defconf.angle
};;
449 { mutable fontsize
: int
450 ; mutable wwidth
: float
451 ; mutable maxrows
: int
463 fstate.fontsize
<- n
;
464 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
465 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
469 if String.length
conf.urilauncher
= 0
470 then print_endline uri
472 let re = Str.regexp
"%s" in
473 let command = Str.global_replace
re uri
conf.urilauncher
in
475 try Some
(Unix.open_process_in
command)
478 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
483 | Some ic
-> close_in ic
488 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
489 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
493 let strings = version () :: "" :: Help.keys
in
495 let r = Str.regexp
"\\(http://[^ ]+\\)" in
497 if (try Str.search_forward
r s
0 with Not_found
-> -1) >= 0
499 let uri = Str.matched_string s
in
500 (s
, 0, Action
(fun u
-> gotouri uri; u
))
501 else s
, 0, Noaction
) strings
511 ; stderr
= Unix.stderr
512 ; errmsgs
= Buffer.create
0
519 ; anchor
= emptyanchor
522 ; tilelru
= Queue.create
()
523 ; pagemap
= Hashtbl.create
10
524 ; tilemap
= Hashtbl.create
10
541 { nav
= cbnew 10 (0, 0.0)
563 Printf.kprintf prerr_endline fmt
565 Printf.kprintf ignore fmt
568 let redirectstderr () =
569 if conf.redirectstderr
571 let rfd, wfd
= Unix.pipe
() in
572 state.stderr
<- Unix.dup
Unix.stderr
;
573 state.errfd
<- Some
rfd;
574 Unix.dup2 wfd
Unix.stderr
;
576 state.newerrmsgs
<- false;
577 begin match state.errfd
with
580 Unix.dup2
state.stderr
Unix.stderr
;
584 prerr_string
(Buffer.contents
state.errmsgs
);
586 Buffer.clear
state.errmsgs
;
592 let postRedisplay who
=
594 then prerr_endline
("redisplay for " ^ who
);
595 Glut.postRedisplay ();
600 let b = Buffer.create
(String.length s
+ 1) in
601 Buffer.add_string
b s
;
606 let colorspace_of_string s
=
607 match String.lowercase s
with
611 | _
-> failwith
"invalid colorspace"
614 let int_of_colorspace = function
620 let colorspace_of_int = function
624 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
627 let colorspace_to_string = function
633 let intentry_with_suffix text key
=
634 let c = Char.unsafe_chr key
in
635 match Char.lowercase
c with
637 let text = addchar text c in
641 let text = addchar text c in
645 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
650 let len = String.length s
in
652 let b = Buffer.create
n in
653 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
654 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
655 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
656 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
657 Buffer.add_string
b s
;
658 let s'
= Buffer.contents
b in
659 let n'
= Unix.write fd
s'
0 n in
660 if n'
!= n then failwith
"write failed";
665 let n = Unix.read fd
s 0 4 in
666 if n != 4 then failwith
"incomplete read(len)";
668 lor (Char.code
s.[0] lsl 24)
669 lor (Char.code
s.[1] lsl 16)
670 lor (Char.code
s.[2] lsl 8)
671 lor (Char.code
s.[3] lsl 0)
673 let s = String.create
len in
674 let n = Unix.read fd
s 0 len in
675 if n != len then failwith
"incomplete read(data)";
680 let b = Buffer.create
10 in
681 Buffer.add_string
b s;
682 let rec combine = function
685 Buffer.add_char
b ' '
;
688 | `
b b -> if b then "1" else "0"
690 | `i i
-> string_of_int i
691 | `f f
-> string_of_float f
692 | `I f
-> string_of_int
(truncate f
)
694 Buffer.add_string
b s;
701 let cmd = Buffer.contents
(makecmd s l
) in
702 writecmd state.csock
cmd;
708 let d = conf.winh
- h
in
715 let rec f pn ph pi fh l
=
717 | (n, _
, h
, _
) :: rest
->
718 let ips = calcips h
in
723 if isbirdseye state.mode
&& pn
= 0
728 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
733 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
737 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
740 let fh = f 0 0 0 0 state.pdims
in
745 match conf.columns
with
746 | None
-> calcheight ()
748 let (_
, _
, y
, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
752 let getpageyh pageno
=
753 let rec f pn ph pi y l
=
755 | (n, _
, h
, _
) :: rest
->
756 let ips = calcips h
in
759 let h = if n = pageno
then h else ph
in
760 if conf.presentation
&& n = pageno
762 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
764 y
+ (pageno
- pn
) * (ph
+ pi
), h
766 let y = y + (if conf.presentation
then pi
else 0) in
767 let y = y + (n - pn
) * (ph
+ pi
) in
771 y + (pageno
- pn
) * (ph
+ pi
), ph
773 f 0 0 0 0 state.pdims
776 let getpageyh pageno
=
777 match conf.columns
with
778 | None
-> getpageyh pageno
780 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
784 let getpagedim pageno
=
787 | (n, _
, _
, _
) as pdim
:: rest
->
789 then (if n = pageno
then pdim
else ppdim
)
794 f (-1, -1, -1, -1) state.pdims
797 let getpagey pageno
= fst
(getpageyh pageno
);;
800 let sh = sh - state.hscrollh
in
801 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
802 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
804 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
805 let ips = calcips h in
807 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
811 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
813 prev
, pdims
, pdimno
, 0
815 let dy = dy + yinc in
816 let py = py + yinc in
817 if pageno
= state.pagecount
|| dy >= sh
822 if py + h <= vy - yinc
824 let py = py + h + ips in
825 let dy = max
0 (py - y) in
834 let pagey = vy - py in
835 let pagevh = h - pagey in
836 let pagevh = min
(sh - dy) pagevh in
837 let off = if yinc > 0 then py - vy else 0 in
838 let py = py + h + ips in
841 if state.w
< conf.winw
- state.scrollw
842 then (conf.winw
- state.scrollw
- state.w
) / 2
845 let dispx = xoff + state.x
in
851 let lw = w
- pagex in
852 min
lw (conf.winw
- state.scrollw
)
860 ; pagey = pagey + off
862 ; pagevh = pagevh - off
864 ; pagedispy
= dy + off
867 let accu = e :: accu in
876 if state.invalidated
= 0
894 let layoutN (_
, b) y sh =
895 let sh = sh - state.hscrollh
in
896 let rec fold accu n =
897 if n = Array.length
b
900 let pdimno, dx
, vy, (_
, w
, h, xoff) = b.(n) in
907 let pagey = max
0 (y - vy) in
917 ; pagedispx
= dx
+ xoff + state.x
918 ; pagedispy
= if pagey > 0 then 0 else vy - y
927 if state.invalidated
= 0
928 then List.rev
(fold [] 0)
933 match conf.columns
with
934 | None
-> layout1 y sh
935 | Some
c -> layoutN c y sh
939 let y = state.y + incr
in
941 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
945 let getopaque pageno
=
946 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
947 with Not_found
-> None
950 let putopaque pageno opaque
=
951 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
955 let tilex = l
.pagex mod conf.tilew
in
956 let tiley = l
.pagey mod conf.tileh
in
958 let col = l
.pagex / conf.tilew
in
959 let row = l
.pagey / conf.tileh
in
962 let a = l
.pagew
- l
.pagex in
963 let b = conf.winw
- state.scrollw
in
967 let rec rowloop row y0 dispy
h =
971 let dh = conf.tileh
- y0
in
973 let rec colloop col x0
dispx w
=
977 let dw = conf.tilew
- x0
in
980 f col row dispx dispy x0 y0
dw dh;
981 colloop (col+1) 0 (dispx+dw) (w
-dw)
984 colloop col tilex l
.pagedispx
vw;
985 rowloop (row+1) 0 (dispy
+dh) (h-dh)
989 then rowloop row tiley l
.pagedispy vh
;
992 let gettileopaque l
col row =
994 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
996 try Some
(Hashtbl.find
state.tilemap
key)
997 with Not_found
-> None
1000 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1001 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1002 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1005 let drawtiles l color
=
1007 let f col row x
y tilex tiley w
h =
1008 match gettileopaque l
col row with
1009 | Some
(opaque
, _
, t
) ->
1010 let params = x
, y, w
, h, tilex, tiley in
1014 GlFunc.blend_func `zero `one_minus_src_color
;
1016 drawtile
params opaque
;
1018 then Gl.disable `blend
;
1021 let s = Printf.sprintf
1025 let w = measurestr
fstate.fontsize
s in
1026 GlMisc.push_attrib
[`current
];
1027 GlDraw.color
(0.0, 0.0, 0.0);
1029 (float (x
-2), float (y-2))
1030 (float (x
+2) +. w, float (y + fstate.fontsize
+ 2));
1031 GlDraw.color
(1.0, 1.0, 1.0);
1032 drawstring fstate.fontsize x
(y + fstate.fontsize
- 1) s;
1033 GlMisc.pop_attrib
();
1038 let lw = conf.winw
- state.scrollw
- x
in
1041 let lh = conf.winh
- y in
1044 Gl.enable `texture_2d
;
1045 begin match state.texid
with
1047 GlTex.bind_texture `texture_2d id
;
1050 and x1
= float (x
+w)
1051 and y1
= float (y+h) in
1053 let tw = float w /. 64.0
1054 and th
= float h /. 64.0 in
1055 let tx0 = float tilex /. 64.0
1056 and ty0
= float tiley /. 64.0 in
1058 and ty1
= ty0
+. th
in
1059 GlDraw.begins `quads
;
1060 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
1061 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
1062 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
1063 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
1066 Gl.disable `texture_2d
;
1068 GlDraw.color
(1.0, 1.0, 1.0);
1071 (float (x
+w), float (y+h));
1073 if w > 128 && h > fstate.fontsize
+ 10
1075 GlDraw.color
(0.0, 0.0, 0.0);
1078 then (col*conf.tilew
, row*conf.tileh
)
1081 drawstring2 fstate.fontsize x
y "Loading %d [%d,%d]" l
.pageno
c r;
1088 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1090 let tilevisible1 l x
y =
1092 and ax1
= l
.pagex + l
.pagevw
1094 and ay1
= l
.pagey + l
.pagevh in
1098 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1099 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1101 let rx0 = max
ax0 bx0
1102 and ry0
= max ay0 by0
1103 and rx1
= min ax1
bx1
1104 and ry1
= min ay1 by1
in
1106 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1107 nonemptyintersection
1110 let tilevisible layout n x
y =
1111 let rec findpageinlayout = function
1112 | l
:: _
when l
.pageno
= n -> tilevisible1 l x
y
1113 | _
:: rest
-> findpageinlayout rest
1116 findpageinlayout layout
1119 let tileready l x
y =
1120 tilevisible1 l x
y &&
1121 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
1124 let tilepage n p
layout =
1125 let rec loop = function
1129 let f col row _ _ _ _ _ _
=
1130 if state.currently
= Idle
1132 match gettileopaque l
col row with
1135 let x = col*conf.tilew
1136 and y = row*conf.tileh
in
1138 let w = l
.pagew
- x in
1142 let h = l
.pageh
- y in
1154 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1155 conf.tilew
, conf.tileh
1164 if state.invalidated
= 0 then loop layout;
1167 let preloadlayout visiblepages
=
1168 let presentation = conf.presentation in
1169 let interpagespace = conf.interpagespace in
1170 let maxy = state.maxy in
1171 conf.presentation <- false;
1172 conf.interpagespace <- 0;
1173 state.maxy <- calcheight ();
1175 match visiblepages
with
1177 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1179 let y = if y < conf.winh
then 0 else y - conf.winh
in
1180 let h = state.y - y + conf.winh
*3 in
1181 let pages = layout y h in
1182 conf.presentation <- presentation;
1183 conf.interpagespace <- interpagespace;
1189 let rec loop pages =
1190 if state.currently
!= Idle
1195 begin match getopaque l
.pageno
with
1197 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1198 state.currently
<- Loading
(l
, state.gen
);
1200 tilepage l
.pageno opaque
pages;
1205 if state.invalidated
= 0 then loop pages
1210 if conf.preload && state.currently
= Idle
1211 then load (preloadlayout pages);
1214 let layoutready layout =
1215 let rec fold all ls
=
1216 all
&& match ls
with
1218 let seen = ref false in
1219 let allvisible = ref true in
1220 let foo col row _ _ _ _ _ _
=
1222 allvisible := !allvisible &&
1223 begin match gettileopaque l
col row with
1229 fold (!seen && !allvisible) rest
1232 let alltilesvisible = fold true layout in
1237 let y = bound y 0 state.maxy in
1238 let y, layout, proceed
=
1239 match conf.maxwait
with
1240 | Some time
when state.ghyll
== noghyll ->
1241 begin match state.throttle
with
1243 let layout = layout y conf.winh
in
1244 let ready = layoutready layout in
1248 state.throttle
<- Some
(layout, y, now ());
1250 else G.postRedisplay "gotoy showall (None)";
1252 | Some
(_
, _
, started
) ->
1253 let dt = now () -. started
in
1256 state.throttle
<- None
;
1257 let layout = layout y conf.winh
in
1259 G.postRedisplay "maxwait";
1266 let layout = layout y conf.winh
in
1267 if true || layoutready layout
1268 then G.postRedisplay "gotoy ready";
1274 state.layout <- layout;
1275 begin match state.mode
with
1276 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1277 if not
(pagevisible layout pageno
)
1279 match state.layout with
1282 state.mode
<- Birdseye
(
1283 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1290 state.ghyll
<- noghyll;
1293 let conttiling pageno opaque
=
1294 tilepage pageno opaque
1295 (if conf.preload then preloadlayout state.layout else state.layout)
1298 let gotoy_and_clear_text y =
1300 if not
conf.verbose
then state.text <- "";
1304 match state.layout with
1306 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1309 let getanchory (n, top
) =
1310 let y, h = getpageyh n in
1311 y + (truncate
(top
*. float h));
1314 let gotoanchor anchor
=
1315 gotoy (getanchory anchor
);
1319 cbput state.hists
.nav
(getanchor ());
1323 let anchor = cbgetc state.hists
.nav dir
in
1328 let rec scroll f n a b =
1329 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1331 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1333 then s (float f /. float a)
1336 then 1.0 -. s ((float (f-b) /. float (n-b)))
1343 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1344 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1346 let ins = float a *. iv1
1347 and outs
= float (n-b) *. iv1 in
1349 ins +. outs
+. float ones
1351 let rec set (_N
, _A
, _B
) y sy
=
1352 let sum = summa
1.0 _N _A _B
in
1353 let dy = float (y - sy
) in
1357 then state.ghyll
<- noghyll
1360 let s = scroll n _N _A _B
in
1361 let y1 = y1 +. ((s *. dy) /. sum) in
1362 gotoy_and_clear_text (truncate
y1);
1363 state.ghyll
<- gf (n+1) y1;
1367 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1369 gf 0 (float state.y)
1372 match conf.ghyllscroll
with
1374 gotoy_and_clear_text y
1376 if state.ghyll
== noghyll
1377 then set nab
y state.y
1378 else state.ghyll
(Some
y)
1381 let gotopage n top
=
1382 let y, h = getpageyh n in
1383 let y = y + (truncate
(top
*. float h)) in
1387 let gotopage1 n top
=
1388 let y = getpagey n in
1398 state.invalidated
<- state.invalidated
+ 1;
1401 let writeopen path password
=
1402 writecmd state.csock
("open " ^ path ^
"\000" ^ password ^
"\000");
1405 let opendoc path password
=
1408 state.password
<- password
;
1409 state.gen
<- state.gen
+ 1;
1410 state.docinfo
<- [];
1412 setaalevel
conf.aalevel
;
1413 writeopen path password
;
1414 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1415 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1419 let c = c *. conf.colorscale
in
1423 let scalecolor2 (r, g
, b) =
1424 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1428 let docolumns = function
1430 | Some
((columns
, coverA
, coverB
), _
) ->
1431 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1432 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1433 if pageno
= state.pagecount
1436 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1438 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1439 pdimno+1, pdim
, rest
1444 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1446 (conf.winw
- state.scrollw
- w) / 2,
1447 y + rowh
+ conf.interpagespace, h
1450 if (pageno
- coverA
) mod columns
= 0
1451 then 0, y + rowh
+ conf.interpagespace, h
1452 else x + w + conf.interpagespace, y, max rowh
h
1455 a.(pageno
) <- (pdimno, x, y, pdim
);
1456 loop (pageno
+1) pdimno pdim
x y rowh pdims
1458 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1459 let rec fix n rowh
= if n = Array.length
a then () else
1460 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(n) in
1462 if n mod columns
= 0
1468 let y = y + (rowh - h) / 2 in
1469 a.(n) <- (pdimno, x, y, pdim
);
1474 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1476 docolumns conf.columns
;
1477 state.maxy <- calcheight ();
1479 if state.w <= conf.winw
- state.scrollw
1483 match state.mode
with
1484 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1485 let y, h = getpageyh pageno
in
1486 let top = (conf.winh
- h) / 2 in
1487 gotoy (max
0 (y - top))
1488 | _
-> gotoanchor state.anchor
1492 let firsttime = ref true in
1494 GlDraw.viewport
0 0 w h;
1495 if state.invalidated
= 0 && not
!firsttime
1496 then state.anchor <- getanchor ();
1500 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1504 setfontsize fstate.fontsize
;
1505 GlMat.mode `modelview
;
1506 GlMat.load_identity
();
1508 GlMat.mode `projection
;
1509 GlMat.load_identity
();
1510 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1511 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1512 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1515 match conf.columns
with
1517 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1520 wcmd "geometry" [`i
w; `i
h];
1524 let len = String.length
state.text in
1527 match state.mode
with
1528 | View
-> state.hscrollh
1533 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1534 (x+.w, float (conf.winh
- hscrollh))
1537 let w = float (conf.winw
- state.scrollw
- 1) in
1538 if state.progress
>= 0.0 && state.progress
< 1.0
1540 GlDraw.color
(0.3, 0.3, 0.3);
1541 let w1 = w *. state.progress
in
1543 GlDraw.color
(0.0, 0.0, 0.0);
1547 GlDraw.color
(0.0, 0.0, 0.0);
1551 GlDraw.color
(1.0, 1.0, 1.0);
1552 drawstring fstate.fontsize
1553 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1556 match state.mode
with
1557 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1561 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1563 Printf.sprintf
"%s%s_" prefix
text
1572 if not
(istextentry state.mode
)
1574 let s1 = "(press 'e' to review error messasges)" in
1575 if String.length
s > 0 then s ^
" " ^
s1 else s1
1580 if String.length
s > 0
1585 state.text <- Printf.sprintf
"%c%s" c s;
1586 G.postRedisplay "showtext";
1590 let len = Queue.length
state.tilelru
in
1592 if state.memused
<= conf.memlimit
1597 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1598 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1599 let (_
, pw
, ph
, _
) = getpagedim n in
1602 && colorspace
= conf.colorspace
1603 && angle
= conf.angle
1608 match state.throttle
with
1611 then preloadlayout state.layout
1613 | Some
(layout, _
, _
) ->
1616 let x = col*conf.tilew
1617 and y = row*conf.tileh
in
1618 tilevisible layout n x y
1620 then Queue.push lruitem
state.tilelru
1622 wcmd "freetile" [`
s p
];
1623 state.memused
<- state.memused
- s;
1624 state.uioh#infochanged Memused
;
1625 Hashtbl.remove
state.tilemap k
;
1634 Queue.iter
(fun (k
, p
, s) ->
1635 wcmd "freetile" [`
s p
];
1636 state.memused
<- state.memused
- s;
1637 state.uioh#infochanged Memused
;
1638 Hashtbl.remove
state.tilemap k
;
1640 Queue.clear
state.tilelru
;
1644 let logcurrently = function
1645 | Idle
-> dolog "Idle"
1646 | Loading
(l
, gen
) ->
1647 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1648 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1650 "Tiling %d[%d,%d] page=%s cs=%s angle"
1651 l
.pageno
col row pageopaque
1652 (colorspace_to_string colorspace
)
1654 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1655 angle gen
conf.angle
state.gen
1657 conf.tilew
conf.tileh
1664 (* dolog "%S" cmds; *)
1667 try String.index cmds ' '
1668 with Not_found
-> -1
1673 let l = String.length cmds
in
1674 let op = String.sub cmds
0 spacepos in
1676 if l - spacepos < 2 then ""
1677 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1682 state.uioh#infochanged Pdim
;
1686 state.rects
<- state.rects1
;
1687 G.postRedisplay "clearrects";
1691 try Scanf.sscanf args
"%u" (fun n -> n)
1693 dolog "error processing 'continue' %S: %s"
1694 cmds
(Printexc.to_string exn
);
1697 state.pagecount
<- n;
1698 state.invalidated
<- state.invalidated
- 1;
1699 begin match state.currently
with
1701 state.currently
<- Idle
;
1702 state.outlines
<- Array.of_list
(List.rev
l)
1705 if state.invalidated
= 0
1707 if conf.maxwait
= None
1708 then G.postRedisplay "continue";
1711 Glut.setWindowTitle args
1718 then showtext ' ' args
1721 let progress, text =
1723 Scanf.sscanf args
"%f %n"
1725 f, String.sub args pos
(String.length args
- pos
))
1727 dolog "error processing 'progress' %S: %s"
1728 cmds
(Printexc.to_string exn
);
1732 state.progress <- progress;
1733 G.postRedisplay "progress"
1736 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1738 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1739 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1740 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1742 dolog "error processing 'firstmatch' %S: %s"
1743 cmds
(Printexc.to_string exn
);
1746 let y = (getpagey pageno) + truncate y0
in
1749 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)]
1752 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1754 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1755 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1756 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1758 dolog "error processing 'match' %S: %s"
1759 cmds
(Printexc.to_string exn
);
1763 (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) :: state.rects1
1768 Scanf.sscanf args
"%s %f" (fun p t
-> p
, t
)
1770 dolog "error processing 'page' %S: %s"
1771 cmds
(Printexc.to_string exn
);
1774 begin match state.currently
with
1775 | Loading
(l, gen
) ->
1776 vlog "page %d took %f sec" l.pageno t
;
1777 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1778 begin match state.throttle
with
1780 let preloadedpages =
1782 then preloadlayout state.layout
1787 Set.Make
(struct type t
= int let compare = (-) end) in
1789 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1790 IntSet.empty
preloadedpages
1793 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
1794 if not
(IntSet.mem
pageno set)
1796 wcmd "freepage" [`
s opaque
];
1802 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1805 state.currently
<- Idle
;
1808 tilepage l.pageno pageopaque state.layout;
1810 load preloadedpages;
1811 if pagevisible state.layout l.pageno
1812 && layoutready state.layout
1813 then G.postRedisplay "page";
1816 | Some
(layout, _
, _
) ->
1817 state.currently
<- Idle
;
1818 tilepage l.pageno pageopaque layout;
1823 dolog "Inconsistent loading state";
1824 logcurrently state.currently
;
1829 let (x, y, opaque
, size
, t
) =
1831 Scanf.sscanf args
"%u %u %s %u %f"
1832 (fun x y p size t
-> (x, y, p
, size
, t
))
1834 dolog "error processing 'tile' %S: %s"
1835 cmds
(Printexc.to_string exn
);
1838 begin match state.currently
with
1839 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1840 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1842 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1844 wcmd "freetile" [`
s opaque
];
1845 state.currently
<- Idle
;
1849 puttileopaque l col row gen cs angle opaque size t
;
1850 state.memused
<- state.memused
+ size
;
1851 state.uioh#infochanged Memused
;
1853 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1854 opaque
, size
) state.tilelru
;
1857 match state.throttle
with
1858 | None
-> state.layout
1859 | Some
(layout, _
, _
) -> layout
1862 state.currently
<- Idle
;
1864 && conf.colorspace
= cs
1865 && conf.angle
= angle
1866 && tilevisible layout l.pageno x y
1867 then conttiling l.pageno pageopaque;
1869 begin match state.throttle
with
1871 preload state.layout;
1873 && conf.colorspace
= cs
1874 && conf.angle
= angle
1875 && tilevisible state.layout l.pageno x y
1876 then G.postRedisplay "tile nothrottle";
1878 | Some
(layout, y, _
) ->
1879 let ready = layoutready layout in
1883 state.layout <- layout;
1884 state.throttle
<- None
;
1885 G.postRedisplay "throttle";
1892 dolog "Inconsistent tiling state";
1893 logcurrently state.currently
;
1900 Scanf.sscanf args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1902 dolog "error processing 'pdim' %S: %s"
1903 cmds
(Printexc.to_string exn
);
1906 state.uioh#infochanged Pdim
;
1907 state.pdims
<- pdim :: state.pdims
1910 let (l, n, t
, h, pos
) =
1912 Scanf.sscanf args
"%u %u %d %u %n"
1913 (fun l n t
h pos
-> l, n, t
, h, pos
)
1915 dolog "error processing 'o' %S: %s"
1916 cmds
(Printexc.to_string exn
);
1919 let s = String.sub args pos
(String.length args
- pos
) in
1920 let outline = (s, l, (n, float t
/. float h)) in
1921 begin match state.currently
with
1922 | Outlining outlines
->
1923 state.currently
<- Outlining
(outline :: outlines
)
1925 state.currently
<- Outlining
[outline]
1927 dolog "invalid outlining state";
1928 logcurrently currently
1932 state.docinfo
<- (1, args
) :: state.docinfo
1935 state.uioh#infochanged Docinfo
;
1936 state.docinfo
<- List.rev
state.docinfo
1939 dolog "unknown cmd `%S'" cmds
1943 if state.deadline
== nan
then state.deadline
<- now ();
1945 match state.errfd
with
1946 | None
-> [state.csock
]
1947 | Some fd
-> [state.csock
; fd
]
1949 let rec loop delay
=
1951 if state.ghyll
== noghyll
1957 then max
0.0 (deadline -. now ())
1960 let r, _
, _
= Unix.select
r [] [] timeout in
1964 begin match state.autoscroll
with
1965 | Some step
when step
!= 0 ->
1966 let y = state.y + step
in
1970 else if y >= state.maxy then 0 else y
1973 if state.mode
= View
1974 then state.text <- "";
1975 state.deadline <- state.deadline +. 0.005;
1978 state.deadline <- state.deadline +. delay
;
1982 let rec checkfds c = function
1984 | fd
:: rest
when fd
= state.csock
->
1985 let cmd = readcmd state.csock
in
1989 let s = String.create
80 in
1990 let n = Unix.read fd
s 0 80 in
1991 if conf.redirectstderr
1993 Buffer.add_substring
state.errmsgs
s 0 n;
1994 state.newerrmsgs
<- true;
1995 Glut.postRedisplay ();
1998 prerr_string
(String.sub
s 0 n);
2011 let action = function
2012 | HCprev
-> cbget cb ~
-1
2013 | HCnext
-> cbget cb
1
2014 | HCfirst
-> cbget cb ~
-(cb
.rc)
2015 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2016 and cancel
() = cb
.rc <- rc
2020 let search pattern forward
=
2021 if String.length pattern
> 0
2024 match state.layout with
2027 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2030 let b = makecmd "search"
2031 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
2033 Buffer.add_char
b '
,'
;
2034 Buffer.add_string
b pattern
;
2035 Buffer.add_char
b '
\000'
;
2038 writecmd state.csock
cmd;
2041 let intentry text key =
2042 let c = Char.unsafe_chr
key in
2045 let text = addchar text c in
2049 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2053 let textentry text key =
2054 let c = Char.unsafe_chr
key in
2056 | _
when key >= 32 && key < 127 ->
2057 let text = addchar text c in
2061 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
2065 let reqlayout angle proportional
=
2066 match state.throttle
with
2068 if state.invalidated
= 0 then state.anchor <- getanchor ();
2069 conf.angle
<- angle
mod 360;
2070 conf.proportional
<- proportional
;
2072 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
2076 let settrim trimmargins trimfuzz
=
2077 if state.invalidated
= 0 then state.anchor <- getanchor ();
2078 conf.trimmargins
<- trimmargins
;
2079 conf.trimfuzz
<- trimfuzz
;
2080 let x0, y0
, x1
, y1 = trimfuzz
in
2083 `
b conf.trimmargins
;
2089 Hashtbl.iter
(fun _ opaque
->
2090 wcmd "freepage" [`
s opaque
];
2092 Hashtbl.clear
state.pagemap
;
2096 match state.throttle
with
2098 let zoom = max
0.01 zoom in
2099 if zoom <> conf.zoom
2101 state.prevzoom
<- conf.zoom;
2104 then (state.x <- 0; 0.0)
2105 else float state.x /. float state.w
2108 reshape conf.winw
conf.winh
;
2111 let x = relx *. float state.w in
2112 state.x <- truncate
x;
2114 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2117 | Some
(layout, y, started
) ->
2119 match conf.maxwait
with
2123 let dt = now () -. started
in
2131 let setcolumns columns coverA coverB
=
2134 conf.columns
<- None
;
2139 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2142 reshape conf.winw
conf.winh
;
2145 let enterbirdseye () =
2146 let zoom = float conf.thumbw
/. float conf.winw
in
2147 let birdseyepageno =
2148 let cy = conf.winh
/ 2 in
2152 let rec fold best
= function
2155 let d = cy - (l.pagedispy
+ l.pagevh/2)
2156 and dbest
= cy - (best
.pagedispy
+ best
.pagevh/2) in
2157 if abs
d < abs dbest
2164 state.mode
<- Birdseye
(
2165 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2168 conf.presentation <- false;
2169 conf.interpagespace <- 10;
2170 conf.hlinks
<- false;
2172 state.mstate
<- Mnone
;
2173 conf.maxwait
<- None
;
2175 match conf.beyecolumns
with
2178 Some
((c, 0, 0), [||])
2181 Glut.setCursor
Glut.CURSOR_INHERIT
;
2184 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2189 reshape conf.winw
conf.winh
;
2192 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2194 conf.zoom <- c.zoom;
2195 conf.presentation <- c.presentation;
2196 conf.interpagespace <- c.interpagespace;
2197 conf.maxwait
<- c.maxwait
;
2198 conf.hlinks
<- c.hlinks
;
2199 conf.beyecolumns
<- (
2200 match conf.columns
with
2201 | Some
((c, _
, _
), _
) -> Some
c
2205 match c.columns
with
2206 | Some
(c, _
) -> Some
(c, [||])
2212 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2215 reshape conf.winw
conf.winh
;
2216 state.anchor <- if goback
then anchor else (pageno, 0.0);
2219 let togglebirdseye () =
2220 match state.mode
with
2221 | Birdseye vals
-> leavebirdseye vals
true
2222 | View
-> enterbirdseye ()
2226 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2227 let pageno = max
0 (pageno - incr
) in
2228 let rec loop = function
2229 | [] -> gotopage1 pageno 0
2230 | l :: _
when l.pageno = pageno ->
2231 if l.pagedispy
>= 0 && l.pagey = 0
2232 then G.postRedisplay "upbirdseye"
2233 else gotopage1 pageno 0
2234 | _
:: rest
-> loop rest
2237 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2240 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2241 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2242 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2243 let rec loop = function
2245 let y, h = getpageyh pageno in
2246 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2248 | l :: _
when l.pageno = pageno ->
2249 if l.pagevh != l.pageh
2250 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2251 else G.postRedisplay "downbirdseye"
2252 | _
:: rest
-> loop rest
2257 let optentry mode _
key =
2258 let btos b = if b then "on" else "off" in
2259 let c = Char.unsafe_chr
key in
2263 try conf.scrollstep
<- int_of_string
s with exc
->
2264 state.text <- Printf.sprintf
"bad integer `%s': %s"
2265 s (Printexc.to_string exc
)
2267 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2272 conf.autoscrollstep
<- int_of_string
s;
2273 if state.autoscroll
<> None
2274 then state.autoscroll
<- Some
conf.autoscrollstep
2276 state.text <- Printf.sprintf
"bad integer `%s': %s"
2277 s (Printexc.to_string exc
)
2279 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2284 let zoom = float (int_of_string
s) /. 100.0 in
2287 state.text <- Printf.sprintf
"bad integer `%s': %s"
2288 s (Printexc.to_string exc
)
2290 TEswitch
("zoom: ", "", None
, intentry, ondone)
2295 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2297 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2298 begin match mode
with
2300 leavebirdseye beye
false;
2305 state.text <- Printf.sprintf
"bad integer `%s': %s"
2306 s (Printexc.to_string exc
)
2308 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2313 Some
(int_of_string
s)
2315 state.text <- Printf.sprintf
"bad integer `%s': %s"
2316 s (Printexc.to_string exc
);
2319 | Some angle
-> reqlayout angle
conf.proportional
2322 TEswitch
("rotation: ", "", None
, intentry, ondone)
2325 conf.icase
<- not
conf.icase
;
2326 TEdone
("case insensitive search " ^
(btos conf.icase
))
2329 conf.preload <- not
conf.preload;
2331 TEdone
("preload " ^
(btos conf.preload))
2334 conf.verbose
<- not
conf.verbose
;
2335 TEdone
("verbose " ^
(btos conf.verbose
))
2338 conf.debug
<- not
conf.debug
;
2339 TEdone
("debug " ^
(btos conf.debug
))
2342 conf.maxhfit
<- not
conf.maxhfit
;
2344 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2345 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2348 conf.crophack
<- not
conf.crophack
;
2349 TEdone
("crophack " ^
btos conf.crophack
)
2353 match conf.maxwait
with
2355 conf.maxwait
<- Some infinity
;
2356 "always wait for page to complete"
2358 conf.maxwait
<- None
;
2359 "show placeholder if page is not ready"
2364 conf.underinfo
<- not
conf.underinfo
;
2365 TEdone
("underinfo " ^
btos conf.underinfo
)
2368 conf.savebmarks
<- not
conf.savebmarks
;
2369 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2375 match state.layout with
2380 conf.interpagespace <- int_of_string
s;
2381 state.maxy <- calcheight ();
2382 let y = getpagey pageno in
2385 state.text <- Printf.sprintf
"bad integer `%s': %s"
2386 s (Printexc.to_string exc
)
2388 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2391 reqlayout conf.angle
(not
conf.proportional
);
2392 TEdone
("proportional display " ^
btos conf.proportional
)
2395 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2396 TEdone
("trim margins " ^
btos conf.trimmargins
)
2399 conf.invert
<- not
conf.invert
;
2400 TEdone
("invert colors " ^
btos conf.invert
)
2403 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2407 class type lvsource
= object
2408 method getitemcount
: int
2409 method getitem
: int -> (string * int)
2410 method hasaction
: int -> bool
2419 method getactive
: int
2420 method getfirst
: int
2421 method getqsearch
: string
2422 method setqsearch
: string -> unit
2426 class virtual lvsourcebase
= object
2427 val mutable m_active
= 0
2428 val mutable m_first
= 0
2429 val mutable m_qsearch
= ""
2430 val mutable m_pan
= 0
2431 method getactive
= m_active
2432 method getfirst
= m_first
2433 method getqsearch
= m_qsearch
2434 method getpan
= m_pan
2435 method setqsearch
s = m_qsearch
<- s
2438 let textentryspecial key = function
2439 | ((c, _
, (Some
(action, _
) as onhist), onkey
, ondone), mode
) ->
2442 | Glut.KEY_UP
-> action HCprev
2443 | Glut.KEY_DOWN
-> action HCnext
2444 | Glut.KEY_HOME
-> action HCfirst
2445 | Glut.KEY_END
-> action HClast
2448 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2449 G.postRedisplay "special textentry";
2453 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2455 state.mode
<- Textentry
(te
, onleave
);
2458 G.postRedisplay "textentrykeyboard enttext";
2460 match Char.unsafe_chr
key with
2461 | '
\008'
-> (* backspace *)
2462 let len = String.length
text in
2466 G.postRedisplay "textentrykeyboard after cancel";
2469 let s = String.sub
text 0 (len - 1) in
2470 enttext (c, s, opthist
, onkey
, ondone)
2476 G.postRedisplay "textentrykeyboard after confirm"
2478 | '
\007'
(* ctrl-g *)
2479 | '
\027'
-> (* escape *)
2480 if String.length
text = 0
2482 begin match opthist
with
2484 | Some
(_
, onhistcancel
) -> onhistcancel
()
2488 G.postRedisplay "textentrykeyboard after cancel2"
2491 enttext (c, "", opthist
, onkey
, ondone)
2494 | '
\127'
-> () (* delete *)
2497 begin match onkey
text key with
2501 G.postRedisplay "textentrykeyboard after confirm2";
2504 enttext (c, text, opthist
, onkey
, ondone);
2508 G.postRedisplay "textentrykeyboard after cancel3"
2511 state.mode
<- Textentry
(te
, onleave
);
2512 G.postRedisplay "textentrykeyboard switch";
2516 let firstof first active
=
2517 if first
> active
|| abs
(first
- active
) > fstate.maxrows
- 1
2518 then max
0 (active
- (fstate.maxrows
/2))
2522 let calcfirst first active
=
2525 let rows = active
- first
in
2526 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2530 let scrollph y maxy =
2531 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2532 let sh = float conf.winh
/. sh in
2533 let sh = max
sh (float conf.scrollh
) in
2538 else float y /. float maxy
2540 let position = (float conf.winh
-. sh) *. percent in
2543 if position +. sh > float conf.winh
2544 then float conf.winh
-. sh
2550 let coe s = (s :> uioh
);;
2552 class listview ~
(source
:lvsource
) ~trusted
=
2554 val m_pan
= source#getpan
2555 val m_first
= source#getfirst
2556 val m_active
= source#getactive
2557 val m_qsearch
= source#getqsearch
2558 val m_prev_uioh
= state.uioh
2560 method private elemunder
y =
2561 let n = y / (fstate.fontsize
+1) in
2562 if m_first
+ n < source#getitemcount
2564 if source#hasaction
(m_first
+ n)
2565 then Some
(m_first
+ n)
2572 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2573 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2574 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2575 GlDraw.color
(1., 1., 1.);
2576 Gl.enable `texture_2d
;
2577 let fs = fstate.fontsize
in
2579 let ww = fstate.wwidth
in
2580 let tabw = 30.0*.ww in
2581 let itemcount = source#getitemcount
in
2583 if (row - m_first
) * nfs > conf.winh
2586 if row >= 0 && row < itemcount
2588 let (s, level
) = source#getitem
row in
2589 let y = (row - m_first
) * nfs in
2590 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2593 Gl.disable `texture_2d
;
2594 GlDraw.polygon_mode `both `line
;
2595 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2596 GlDraw.rect (1., float (y + 1))
2597 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2598 GlDraw.polygon_mode `both `fill
;
2599 GlDraw.color
(1., 1., 1.);
2600 Gl.enable `texture_2d
;
2603 let drawtabularstring s =
2604 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2607 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2610 let len = String.length
s - tabpos - 1 in
2611 let s1 = String.sub
s 0 tabpos
2612 and s2
= String.sub
s (tabpos + 1) len in
2613 let nx = drawstr x s1 in
2615 let x = x +. (max
tabw sw) in
2622 let _ = drawtabularstring s in
2629 Gl.disable `texture_2d
;
2631 method updownlevel incr
=
2632 let len = source#getitemcount
in
2634 if m_active
>= 0 && m_active
< len
2635 then snd
(source#getitem m_active
)
2639 if i
= len then i
-1 else if i
= -1 then 0 else
2640 let _, l = source#getitem i
in
2641 if l != curlevel then i
else flow (i
+incr
)
2643 let active = flow m_active
in
2644 let first = calcfirst m_first
active in
2645 G.postRedisplay "special outline updownlevel";
2646 {< m_active
= active; m_first
= first >}
2648 method private key1
key =
2649 let set active first qsearch
=
2650 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2652 let search active pattern incr
=
2655 if n >= 0 && n < source#getitemcount
2657 let s, _ = source#getitem
n in
2659 (try ignore
(Str.search_forward
re s 0); true
2660 with Not_found
-> false)
2662 else loop (n + incr
)
2669 let re = Str.regexp_case_fold pattern
in
2676 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2677 let incr = if key = 18 then -1 else 1 in
2679 match search (m_active
+ incr) m_qsearch
incr with
2681 state.text <- m_qsearch ^
" [not found]";
2684 state.text <- m_qsearch
;
2685 active, firstof m_first
active
2687 G.postRedisplay "listview ctrl-r/s";
2688 set active first m_qsearch
;
2690 | 8 -> (* backspace *)
2691 let len = String.length m_qsearch
in
2698 G.postRedisplay "listview empty qsearch";
2699 set m_active m_first
"";
2702 let qsearch = String.sub m_qsearch
0 (len - 1) in
2704 match search m_active
qsearch ~
-1 with
2706 state.text <- qsearch ^
" [not found]";
2709 state.text <- qsearch;
2710 active, firstof m_first
active
2712 G.postRedisplay "listview backspace qsearch";
2713 set active first qsearch
2716 | _ when key >= 32 && key < 127 ->
2717 let pattern = addchar m_qsearch
(Char.chr
key) in
2719 match search m_active
pattern 1 with
2721 state.text <- pattern ^
" [not found]";
2724 state.text <- pattern;
2725 active, firstof m_first
active
2727 G.postRedisplay "listview qsearch add";
2728 set active first pattern;
2730 | 27 -> (* escape *)
2732 if String.length m_qsearch
= 0
2734 G.postRedisplay "list view escape";
2737 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2739 | None
-> m_prev_uioh
2744 G.postRedisplay "list view kill qsearch";
2745 source#setqsearch
"";
2746 coe {< m_qsearch
= "" >}
2751 let self = {< m_qsearch
= "" >} in
2752 source#setqsearch
"";
2754 G.postRedisplay "listview enter";
2755 if m_active
>= 0 && m_active
< source#getitemcount
2757 source#exit
(coe self) false m_active m_first m_pan
"";
2760 source#exit
(coe self) true m_active m_first m_pan
"";
2763 begin match opt with
2764 | None
-> m_prev_uioh
2768 | 127 -> (* delete *)
2771 | _ -> dolog "unknown key %d" key; coe self
2773 method private special1
key =
2774 let itemcount = source#getitemcount
in
2775 let find start
incr =
2777 if i
= -1 || i
= itemcount
2780 if source#hasaction i
2782 else find (i
+ incr)
2787 let set active first =
2788 let first = bound first 0 (itemcount - fstate.maxrows
) in
2790 coe {< m_active
= active; m_first
= first >}
2793 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2795 let incr1 = if incr > 0 then 1 else -1 in
2796 if isvisible m_first m_active
2799 let next = m_active
+ incr in
2801 if next < 0 || next >= itemcount
2803 else find next incr1
2805 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2811 let first = m_first
+ incr in
2812 let first = bound first 0 (itemcount - 1) in
2814 let next = m_active
+ incr in
2815 let next = bound next 0 (itemcount - 1) in
2818 let active = if next = -1 then m_active
else next in
2821 let first = min
next m_first
in
2823 if abs
(next - first) > fstate.maxrows
2829 let first = m_first
+ incr in
2830 let first = bound first 0 (itemcount - 1) in
2832 let next = m_active
+ incr in
2833 let next = bound next 0 (itemcount - 1) in
2834 let next = find next incr1 in
2836 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2838 let active = if m_active
= -1 then next else m_active
in
2843 if isvisible first active
2849 G.postRedisplay "listview navigate";
2852 begin match key with
2853 | Glut.KEY_UP
-> navigate ~
-1
2854 | Glut.KEY_DOWN
-> navigate 1
2855 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2856 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2860 G.postRedisplay "listview right";
2861 coe {< m_pan
= m_pan
- 1 >}
2865 G.postRedisplay "listview left";
2866 coe {< m_pan
= m_pan
+ 1 >}
2869 let active = find 0 1 in
2870 G.postRedisplay "listview home";
2874 let first = max
0 (itemcount - fstate.maxrows
) in
2875 let active = find (itemcount - 1) ~
-1 in
2876 G.postRedisplay "listview end";
2883 match state.mode
with
2884 | Textentry te
-> textentrykeyboard key te
; coe self
2885 | _ -> self#key1
key
2887 method special
key =
2888 match state.mode
with
2889 | Textentry te
-> textentryspecial key te
; coe self
2890 | _ -> self#special1
key
2892 method button button bstate
x y =
2895 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollbw
->
2896 G.postRedisplay "listview scroll";
2897 if bstate
= Glut.DOWN
2899 let _, position, sh = self#
scrollph in
2900 if y > truncate
position && y < truncate
(position +. sh)
2902 state.mstate
<- Mscrolly
;
2906 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2907 let first = truncate
(s *. float source#getitemcount
) in
2908 let first = min source#getitemcount
first in
2909 Some
(coe {< m_first
= first; m_active
= first >})
2911 state.mstate
<- Mnone
;
2914 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2915 begin match self#elemunder
y with
2917 G.postRedisplay "listview click";
2919 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
2923 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2924 let len = source#getitemcount
in
2926 if n = 4 && m_first
+ fstate.maxrows
>= len
2930 let first = m_first
+ (if n == 3 then -1 else 1) in
2931 bound first 0 (len - 1)
2933 G.postRedisplay "listview wheel";
2934 Some
(coe {< m_first
= first >})
2939 | None
-> m_prev_uioh
2943 match state.mstate
with
2945 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2946 let first = truncate
(s *. float source#getitemcount
) in
2947 let first = min source#getitemcount
first in
2948 G.postRedisplay "listview motion";
2949 coe {< m_first
= first; m_active
= first >}
2952 method pmotion
x y =
2953 if x < conf.winw
- conf.scrollbw
2956 match self#elemunder
y with
2957 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
2958 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
2962 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
2967 Glut.setCursor
Glut.CURSOR_INHERIT
;
2971 method infochanged
_ = ()
2973 method scrollpw
= (0, 0.0, 0.0)
2975 let nfs = fstate.fontsize
+ 1 in
2976 let y = m_first
* nfs in
2977 let itemcount = source#getitemcount
in
2978 let maxi = max
0 (itemcount - fstate.maxrows
) in
2979 let maxy = maxi * nfs in
2980 let p, h = scrollph y maxy in
2984 class outlinelistview ~source
=
2986 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
2990 | 14 -> (* ctrl-n *)
2991 source#narrow m_qsearch
;
2992 G.postRedisplay "outline ctrl-n";
2993 coe {< m_first
= 0; m_active
= 0 >}
2995 | 21 -> (* ctrl-u *)
2997 G.postRedisplay "outline ctrl-u";
2999 coe {< m_first
= 0; m_active
= 0 >}
3001 | 12 -> (* ctrl-l *)
3002 let first = m_active
- (fstate.maxrows
/ 2) in
3003 G.postRedisplay "outline ctrl-l";
3004 coe {< m_first
= first >}
3006 | 127 -> (* delete *)
3007 source#remove m_active
;
3008 G.postRedisplay "outline delete";
3009 let active = max
0 (m_active
-1) in
3010 coe {< m_first
= firstof m_first
active;
3011 m_active
= active >}
3013 | key -> super#
key key
3015 method special
key =
3016 let calcfirst first active =
3019 let rows = active - first in
3020 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3024 let active = m_active
+ incr in
3025 let active = bound active 0 (source#getitemcount
- 1) in
3026 let first = calcfirst m_first
active in
3027 G.postRedisplay "special outline navigate";
3028 coe {< m_active
= active; m_first
= first >}
3031 | Glut.KEY_UP
-> navigate ~
-1
3032 | Glut.KEY_DOWN
-> navigate 1
3033 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
3034 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
3038 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
3040 G.postRedisplay "special outline right";
3041 {< m_pan
= m_pan
+ 1 >}
3043 else self#updownlevel
1
3049 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
3051 G.postRedisplay "special outline left";
3052 {< m_pan
= m_pan
- 1 >}
3054 else self#updownlevel ~
-1
3059 G.postRedisplay "special outline home";
3060 coe {< m_first
= 0; m_active
= 0 >}
3063 let active = source#getitemcount
- 1 in
3064 let first = max
0 (active - fstate.maxrows
) in
3065 G.postRedisplay "special outline end";
3066 coe {< m_active
= active; m_first
= first >}
3068 | _ -> super#special
key
3071 let outlinesource usebookmarks
=
3074 inherit lvsourcebase
3075 val mutable m_items
= empty
3076 val mutable m_orig_items
= empty
3077 val mutable m_prev_items
= empty
3078 val mutable m_narrow_pattern
= ""
3079 val mutable m_hadremovals
= false
3081 method getitemcount
=
3082 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3085 if n == Array.length m_items
&& m_hadremovals
3087 ("[Confirm removal]", 0)
3089 let s, n, _ = m_items
.(n) in
3092 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3093 ignore
(uioh
, first, pan
, qsearch);
3094 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3096 if String.length m_narrow_pattern
= 0
3102 if not
confrimremoval
3104 let _, _, anchor = m_items
.(active) in
3109 state.bookmarks
<- Array.to_list m_items
;
3110 m_orig_items
<- m_items
;
3113 else m_items
<- items;
3116 method hasaction
_ = true
3119 if Array.length m_items
!= Array.length m_orig_items
3120 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3123 method narrow
pattern =
3124 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3128 let rec loop accu n =
3131 m_narrow_pattern
<- pattern;
3132 m_items
<- Array.of_list
accu
3135 let (s, _, _) as o = m_items
.(n) in
3137 if (try ignore
(Str.search_forward
re s 0); true
3138 with Not_found
-> false)
3144 loop [] (Array.length m_items
- 1)
3149 then Array.of_list
state.bookmarks
3152 m_items
<- m_orig_items
3157 if m
>= 0 && m
< Array.length m_items
3159 m_hadremovals
<- true;
3160 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3161 let n = if n >= m
then n+1 else n in
3166 method reset
anchor items =
3167 m_hadremovals
<- false;
3168 if m_orig_items
== empty || m_prev_items
!= items
3170 m_orig_items
<- items;
3171 if String.length m_narrow_pattern
= 0
3172 then m_items
<- items;
3174 m_prev_items
<- items;
3175 let rely = getanchory anchor in
3177 let rec loop n best bestd
=
3178 if n = Array.length m_items
3181 let (_, _, anchor) = m_items
.(n) in
3182 let orely = getanchory anchor in
3183 let d = abs
(orely - rely) in
3186 else loop (n+1) best bestd
3191 m_first
<- firstof m_first
active
3195 let enterselector usebookmarks
=
3196 let source = outlinesource usebookmarks
in
3200 then Array.of_list
state.bookmarks
3203 if Array.length
outlines = 0
3205 showtext ' ' errmsg
;
3208 state.text <- source#greetmsg
;
3209 Glut.setCursor
Glut.CURSOR_INHERIT
;
3210 let anchor = getanchor () in
3211 source#reset
anchor outlines;
3212 state.uioh
<- coe (new outlinelistview ~
source);
3213 G.postRedisplay "enter selector";
3217 let enteroutlinemode =
3218 let f = enterselector false in
3219 fun ()-> f "Document has no outline";
3222 let enterbookmarkmode =
3223 let f = enterselector true in
3224 fun () -> f "Document has no bookmarks (yet)";
3227 let color_of_string s =
3228 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3229 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3233 let color_to_string (r, g
, b) =
3234 let r = truncate
(r *. 256.0)
3235 and g
= truncate
(g
*. 256.0)
3236 and b = truncate
(b *. 256.0) in
3237 Printf.sprintf
"%d/%d/%d" r g
b
3240 let irect_of_string s =
3241 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1
y1 -> (x0,y0
,x1
,y1))
3244 let irect_to_string (x0,y0
,x1
,y1) =
3245 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1
y1
3248 let makecheckers () =
3249 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3251 converted by Issac Trotts. July 25, 2002 *)
3252 let image_height = 64
3253 and image_width
= 64 in
3257 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3259 for i
= 0 to image_width
- 1 do
3260 for j
= 0 to image_height - 1 do
3261 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3262 (if (i
land 8 ) lxor (j
land 8) = 0
3263 then [|255;255;255|] else [|200;200;200|])
3268 let image = make_image () in
3269 let id = GlTex.gen_texture
() in
3270 GlTex.bind_texture `texture_2d
id;
3271 GlPix.store
(`unpack_alignment
1);
3272 GlTex.image2d
image;
3273 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3276 `mag_filter `nearest
;
3277 `min_filter `nearest
];
3281 let setcheckers enabled
=
3282 match state.texid
with
3284 if enabled
then state.texid
<- Some
(makecheckers ())
3289 GlTex.delete_texture texid
;
3290 state.texid
<- None
;
3294 let int_of_string_with_suffix s =
3295 let l = String.length
s in
3299 let suffix = Char.lowercase
s.[l-1] in
3301 | 'k'
-> String.sub
s 0 (l-1), 10
3302 | 'm'
-> String.sub
s 0 (l-1), 20
3303 | 'g'
-> String.sub
s 0 (l-1), 30
3307 let n = int_of_string
s1 in
3308 let m = n lsl shift
in
3310 then raise
(Failure
"value too large")
3314 let string_with_suffix_of_int n =
3322 if n land ((1 lsl 20) - 1) = 0
3325 if n land ((1 lsl 10) - 1) = 0
3332 let h = n mod 1000 in
3335 then string_of_int
h ^
s
3337 let s = Printf.sprintf
"_%03d%s" h s in
3344 let defghyllscroll = (40, 8, 32);;
3345 let ghyllscroll_of_string s =
3346 let (n, a, b) as nab
=
3349 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3351 if n <= a || n <= b || a >= b
3352 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3356 let ghyllscroll_to_string ((n, a, b) as nab
) =
3357 if nab
= defghyllscroll
3359 else Printf.sprintf
"%d,%d,%d" n a b;
3362 let describe_location () =
3364 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3366 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3367 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3371 else (100. *. (float state.y /. float maxy))
3375 Printf.sprintf
"page %d of %d [%.2f%%]"
3376 (fn+1) state.pagecount
percent
3379 "pages %d-%d of %d [%.2f%%]"
3380 (fn+1) (ln
+1) state.pagecount
percent
3383 let columns_to_string (n, a, b) =
3385 then Printf.sprintf
"%d" n
3386 else Printf.sprintf
"%d,%d,%d" n a b;
3389 let columns_of_string s =
3391 (int_of_string
s, 0, 0)
3393 Scanf.sscanf
s "%u,%u,%u" (fun n a b -> (n, a, b));
3397 let btos b = if b then "\xe2\x88\x9a" else "" in
3398 let showextended = ref false in
3399 let leave mode
= function
3400 | Confirm
-> state.mode
<- mode
3401 | Cancel
-> state.mode
<- mode
in
3404 val mutable m_first_time
= true
3405 val mutable m_l
= []
3406 val mutable m_a
= [||]
3407 val mutable m_prev_uioh
= nouioh
3408 val mutable m_prev_mode
= View
3410 inherit lvsourcebase
3412 method reset prev_mode prev_uioh
=
3413 m_a
<- Array.of_list
(List.rev m_l
);
3415 m_prev_mode
<- prev_mode
;
3416 m_prev_uioh
<- prev_uioh
;
3420 if n >= Array.length m_a
3424 | _, _, _, Action
_ -> m_active
<- n
3428 m_first_time
<- false;
3431 method int name get
set =
3433 (name
, `
int get
, 1, Action
(
3436 try set (int_of_string
s)
3438 state.text <- Printf.sprintf
"bad integer `%s': %s"
3439 s (Printexc.to_string exn
)
3442 let te = name ^
": ", "", None
, intentry, ondone in
3443 state.mode
<- Textentry
(te, leave m_prev_mode
);
3447 method int_with_suffix name get
set =
3449 (name
, `intws get
, 1, Action
(
3452 try set (int_of_string_with_suffix s)
3454 state.text <- Printf.sprintf
"bad integer `%s': %s"
3455 s (Printexc.to_string exn
)
3459 name ^
": ", "", None
, intentry_with_suffix, ondone
3461 state.mode
<- Textentry
(te, leave m_prev_mode
);
3465 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3467 (name
, `
bool (btos, get
), offset
, Action
(
3474 method color name get
set =
3476 (name
, `color get
, 1, Action
(
3478 let invalid = (nan
, nan
, nan
) in
3481 try color_of_string s
3483 state.text <- Printf.sprintf
"bad color `%s': %s"
3484 s (Printexc.to_string exn
);
3490 let te = name ^
": ", "", None
, textentry, ondone in
3491 state.text <- color_to_string (get
());
3492 state.mode
<- Textentry
(te, leave m_prev_mode
);
3496 method string name get
set =
3498 (name
, `
string get
, 1, Action
(
3500 let ondone s = set s in
3501 let te = name ^
": ", "", None
, textentry, ondone in
3502 state.mode
<- Textentry
(te, leave m_prev_mode
);
3506 method colorspace name get
set =
3508 (name
, `
string get
, 1, Action
(
3511 let vals = [| "rgb"; "bgr"; "gray" |] in
3513 inherit lvsourcebase
3516 m_active
<- int_of_colorspace conf.colorspace
;
3519 method getitemcount
= Array.length
vals
3520 method getitem
n = (vals.(n), 0)
3521 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3522 ignore
(uioh
, first, pan
, qsearch);
3523 if not cancel
then set active;
3525 method hasaction
_ = true
3529 coe (new listview ~
source ~trusted
:true)
3532 method caption
s offset
=
3533 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3535 method caption2
s f offset
=
3536 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3538 method getitemcount
= Array.length m_a
3541 let tostr = function
3542 | `
int f -> string_of_int
(f ())
3543 | `intws
f -> string_with_suffix_of_int (f ())
3545 | `color
f -> color_to_string (f ())
3546 | `
bool (btos, f) -> btos (f ())
3549 let name, t
, offset
, _ = m_a
.(n) in
3550 ((let s = tostr t
in
3551 if String.length
s > 0
3552 then Printf.sprintf
"%s\t%s" name s
3556 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3560 m_qsearch
<- qsearch;
3562 match m_a
.(active) with
3563 | _, _, _, Action
f -> f uioh
3575 method hasaction
n =
3577 | _, _, _, Action
_ -> true
3581 let rec fillsrc prevmode prevuioh
=
3582 let sep () = src#caption
"" 0 in
3583 let colorp name get
set =
3585 (fun () -> color_to_string (get
()))
3588 let c = color_of_string v in
3591 state.text <- Printf.sprintf
"bad color `%s': %s"
3592 v (Printexc.to_string exn
);
3595 let oldmode = state.mode
in
3596 let birdseye = isbirdseye state.mode
in
3598 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3600 src#
bool "presentation mode"
3601 (fun () -> conf.presentation)
3603 conf.presentation <- v;
3604 state.anchor <- getanchor ();
3607 src#
bool "ignore case in searches"
3608 (fun () -> conf.icase
)
3609 (fun v -> conf.icase
<- v);
3612 (fun () -> conf.preload)
3613 (fun v -> conf.preload <- v);
3615 src#
bool "highlight links"
3616 (fun () -> conf.hlinks
)
3617 (fun v -> conf.hlinks
<- v);
3619 src#
bool "under info"
3620 (fun () -> conf.underinfo
)
3621 (fun v -> conf.underinfo
<- v);
3623 src#
bool "persistent bookmarks"
3624 (fun () -> conf.savebmarks
)
3625 (fun v -> conf.savebmarks
<- v);
3627 src#
bool "proportional display"
3628 (fun () -> conf.proportional
)
3629 (fun v -> reqlayout conf.angle
v);
3631 src#
bool "trim margins"
3632 (fun () -> conf.trimmargins
)
3633 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3635 src#
bool "persistent location"
3636 (fun () -> conf.jumpback
)
3637 (fun v -> conf.jumpback
<- v);
3640 src#
int "inter-page space"
3641 (fun () -> conf.interpagespace)
3643 conf.interpagespace <- n;
3645 match state.layout with
3650 state.maxy <- calcheight ();
3651 let y = getpagey pageno in
3656 (fun () -> conf.pagebias
)
3657 (fun v -> conf.pagebias
<- v);
3659 src#
int "scroll step"
3660 (fun () -> conf.scrollstep
)
3661 (fun n -> conf.scrollstep
<- n);
3663 src#
int "auto scroll step"
3665 match state.autoscroll
with
3667 | _ -> conf.autoscrollstep
)
3669 if state.autoscroll
<> None
3670 then state.autoscroll
<- Some
n;
3671 conf.autoscrollstep
<- n);
3674 (fun () -> truncate
(conf.zoom *. 100.))
3675 (fun v -> setzoom ((float v) /. 100.));
3678 (fun () -> conf.angle
)
3679 (fun v -> reqlayout v conf.proportional
);
3681 src#
int "scroll bar width"
3682 (fun () -> state.scrollw
)
3686 reshape conf.winw
conf.winh
;
3689 src#
int "scroll handle height"
3690 (fun () -> conf.scrollh
)
3691 (fun v -> conf.scrollh
<- v;);
3693 src#
int "thumbnail width"
3694 (fun () -> conf.thumbw
)
3696 conf.thumbw
<- min
4096 v;
3699 leavebirdseye beye
false;
3704 src#
string "columns"
3706 match conf.columns
with
3708 | Some
(multicol
, _) -> columns_to_string multicol
)
3710 let n, a, b = columns_of_string v in
3714 src#caption
"Presentation mode" 0;
3715 src#
bool "scrollbar visible"
3716 (fun () -> conf.scrollbarinpm
)
3718 if v != conf.scrollbarinpm
3720 conf.scrollbarinpm
<- v;
3721 if conf.presentation
3723 state.scrollw
<- if v then conf.scrollbw
else 0;
3724 reshape conf.winw
conf.winh
;
3730 src#caption
"Pixmap cache" 0;
3731 src#int_with_suffix
"size (advisory)"
3732 (fun () -> conf.memlimit
)
3733 (fun v -> conf.memlimit
<- v);
3736 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3737 (string_with_suffix_of_int state.memused
)
3738 (Hashtbl.length
state.tilemap
)) 1;
3741 src#caption
"Layout" 0;
3742 src#caption2
"Dimension"
3744 Printf.sprintf
"%dx%d (virtual %dx%d)"
3750 src#caption2
"Position" (fun () ->
3751 Printf.sprintf
"%dx%d" state.x state.y
3754 src#caption2
"Visible" (fun () -> describe_location ()) 1
3758 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3759 "Save these parameters as global defaults at exit"
3760 (fun () -> conf.bedefault
)
3761 (fun v -> conf.bedefault
<- v)
3765 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3766 src#
bool ~offset
:0 ~
btos "Extended parameters"
3767 (fun () -> !showextended)
3768 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3772 (fun () -> conf.checkers
)
3773 (fun v -> conf.checkers
<- v; setcheckers v);
3775 (fun () -> conf.verbose
)
3776 (fun v -> conf.verbose
<- v);
3777 src#
bool "invert colors"
3778 (fun () -> conf.invert
)
3779 (fun v -> conf.invert
<- v);
3781 (fun () -> conf.maxhfit
)
3782 (fun v -> conf.maxhfit
<- v);
3783 src#
bool "redirect stderr"
3784 (fun () -> conf.redirectstderr)
3785 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3786 src#
string "uri launcher"
3787 (fun () -> conf.urilauncher
)
3788 (fun v -> conf.urilauncher
<- v);
3789 src#
string "tile size"
3790 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3793 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3794 conf.tileh
<- max
64 w;
3795 conf.tilew
<- max
64 h;
3798 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3799 v (Printexc.to_string exn
));
3800 src#
int "texture count"
3801 (fun () -> conf.texcount
)
3804 then conf.texcount
<- v
3805 else showtext '
!'
" Failed to set texture count please retry later"
3807 src#
int "slice height"
3808 (fun () -> conf.sliceheight
)
3810 conf.sliceheight
<- v;
3811 wcmd "sliceh" [`i
conf.sliceheight
];
3813 src#
int "anti-aliasing level"
3814 (fun () -> conf.aalevel
)
3816 conf.aalevel
<- bound v 0 8;
3817 state.anchor <- getanchor ();
3818 opendoc state.path
state.password
;
3820 src#
int "ui font size"
3821 (fun () -> fstate.fontsize
)
3822 (fun v -> setfontsize (bound v 5 100));
3823 colorp "background color"
3824 (fun () -> conf.bgcolor
)
3825 (fun v -> conf.bgcolor
<- v);
3826 src#
bool "crop hack"
3827 (fun () -> conf.crophack
)
3828 (fun v -> conf.crophack
<- v);
3829 src#
string "trim fuzz"
3830 (fun () -> irect_to_string conf.trimfuzz
)
3833 conf.trimfuzz
<- irect_of_string v;
3835 then settrim true conf.trimfuzz
;
3837 state.text <- Printf.sprintf
"bad irect `%s': %s"
3838 v (Printexc.to_string exn
)
3840 src#
string "throttle"
3842 match conf.maxwait
with
3843 | None
-> "show place holder if page is not ready"
3846 then "wait for page to fully render"
3848 "wait " ^ string_of_float
time
3849 ^
" seconds before showing placeholder"
3853 let f = float_of_string
v in
3855 then conf.maxwait
<- None
3856 else conf.maxwait
<- Some
f
3858 state.text <- Printf.sprintf
"bad time `%s': %s"
3859 v (Printexc.to_string exn
)
3861 src#
string "ghyll scroll"
3863 match conf.ghyllscroll
with
3865 | Some nab
-> ghyllscroll_to_string nab
3870 if String.length
v = 0
3872 else Some
(ghyllscroll_of_string v)
3874 conf.ghyllscroll
<- gs
3876 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
3877 v (Printexc.to_string exn
)
3879 src#colorspace
"color space"
3880 (fun () -> colorspace_to_string conf.colorspace
)
3882 conf.colorspace
<- colorspace_of_int v;
3889 src#caption
"Document" 0;
3890 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3891 src#caption2
"Pages"
3892 (fun () -> string_of_int
state.pagecount
) 1;
3893 src#caption2
"Dimensions"
3894 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3898 src#caption
"Trimmed margins" 0;
3899 src#caption2
"Dimensions"
3900 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3903 src#reset prevmode prevuioh
;
3907 let prevmode = state.mode
3908 and prevuioh
= state.uioh in
3909 fillsrc prevmode prevuioh
;
3910 let source = (src :> lvsource
) in
3911 state.uioh <- coe (object (self)
3912 inherit listview ~
source ~trusted
:true as super
3913 val mutable m_prevmemused
= 0
3914 method infochanged
= function
3916 if m_prevmemused
!= state.memused
3918 m_prevmemused
<- state.memused
;
3919 G.postRedisplay "memusedchanged";
3921 | Pdim
-> G.postRedisplay "pdimchanged"
3922 | Docinfo
-> fillsrc prevmode prevuioh
3924 method special
key =
3925 if Glut.getModifiers
() land Glut.active_ctrl
= 0
3928 | Glut.KEY_LEFT
-> coe (self#updownlevel ~
-1)
3929 | Glut.KEY_RIGHT
-> coe (self#updownlevel
1)
3930 | _ -> super#special
key
3931 else super#special
key
3933 G.postRedisplay "info";
3939 inherit lvsourcebase
3940 method getitemcount
= Array.length
state.help
3942 let s, n, _ = state.help
.(n) in
3945 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3949 m_qsearch
<- qsearch;
3950 match state.help
.(active) with
3951 | _, _, Action
f -> Some
(f uioh)
3961 method hasaction
n =
3962 match state.help
.(n) with
3963 | _, _, Action
_ -> true
3970 state.uioh <- coe (new listview ~
source ~trusted
:true);
3971 G.postRedisplay "help";
3976 let re = Str.regexp
"[\r\n]" in
3978 inherit lvsourcebase
3979 val mutable m_items
= [||]
3981 method getitemcount
= 1 + Array.length m_items
3986 else m_items
.(n-1), 0
3988 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3993 then Buffer.clear
state.errmsgs
;
3994 m_qsearch
<- qsearch;
4001 method hasaction
n =
4005 state.newerrmsgs
<- false;
4006 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4007 m_items
<- Array.of_list
l
4015 let source = (msgsource :> lvsource
) in
4016 state.uioh <- coe (object
4017 inherit listview ~
source ~trusted
:false as super
4020 then msgsource#reset
;
4023 G.postRedisplay "msgs";
4026 let quickbookmark ?title
() =
4027 match state.layout with
4033 let sec = Unix.gettimeofday
() in
4034 let tm = Unix.localtime
sec in
4035 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4039 (tm.Unix.tm_year
+ 1900)
4042 | Some
title -> title
4045 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4050 state.fullscreen
<- None
;
4051 Glut.reshapeWindow
w h;
4054 let viewkeyboard key =
4056 let mode = state.mode in
4057 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4060 G.postRedisplay "view:enttext"
4062 let c = Char.chr
key in
4064 | '
\027'
| 'q'
-> (* escape *)
4065 begin match state.mstate
with
4067 state.mstate
<- Mnone
;
4068 Glut.setCursor
Glut.CURSOR_INHERIT
;
4069 G.postRedisplay "kill zoom rect";
4074 | '
\008'
-> (* backspace *)
4075 let y = getnav ~
-1 in
4076 gotoy_and_clear_text y
4084 G.postRedisplay "dehighlight";
4087 let ondone isforw
s =
4088 cbput state.hists
.pat
s;
4089 state.searchpattern
<- s;
4092 let s = String.create
1 in
4094 enttext (s, "", Some
(onhist state.hists
.pat
),
4095 textentry, ondone (c ='
/'
))
4097 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4098 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4099 setzoom (conf.zoom +. incr)
4104 try int_of_string
s with exc
->
4105 state.text <- Printf.sprintf
"bad integer `%s': %s"
4106 s (Printexc.to_string exc
);
4112 state.text <- "page bias is now " ^ string_of_int
n;
4115 enttext ("page bias: ", "", None
, intentry, ondone)
4117 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4118 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4119 setzoom (max
0.01 (conf.zoom -. decr))
4122 let ondone msg
= state.text <- msg
in
4124 "option [acfhilpstvAPRSZTI]: ", "", None
,
4125 optentry state.mode, ondone
4128 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4131 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4132 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4136 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4142 try int_of_string
s with exc
->
4143 state.text <- Printf.sprintf
"bad integer `%s': %s"
4144 s (Printexc.to_string exc
);
4150 cbput state.hists
.pag
(string_of_int
n);
4151 gotopage1 (n + conf.pagebias
- 1) 0;
4154 let pageentry text key =
4155 match Char.unsafe_chr
key with
4156 | 'g'
-> TEdone
text
4157 | _ -> intentry text key
4159 let text = "x" in text.[0] <- c;
4160 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4163 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4164 reshape conf.winw
conf.winh
;
4167 conf.hlinks
<- not
conf.hlinks
;
4168 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4169 G.postRedisplay "toggle highlightlinks";
4172 begin match state.autoscroll
with
4174 conf.autoscrollstep
<- step
;
4175 state.autoscroll
<- None
4177 if conf.autoscrollstep
= 0
4178 then state.autoscroll
<- Some
1
4179 else state.autoscroll
<- Some
conf.autoscrollstep
4183 conf.presentation <- not
conf.presentation;
4184 if conf.presentation
4186 if not
conf.scrollbarinpm
4187 then state.scrollw
<- 0;
4190 state.scrollw
<- conf.scrollbw
;
4192 showtext ' '
("presentation mode " ^
4193 if conf.presentation then "on" else "off");
4194 state.anchor <- getanchor ();
4198 begin match state.fullscreen
with
4200 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4203 state.fullscreen
<- None
;
4208 gotoy_and_clear_text 0
4211 gotopage1 (state.pagecount
- 1) 0
4214 search state.searchpattern
true
4217 search state.searchpattern
false
4220 begin match state.layout with
4223 gotoy_and_clear_text (getpagey l.pageno)
4227 begin match List.rev
state.layout with
4230 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4231 gotoy_and_clear_text (getpagey pageno)
4234 | '
\127'
-> (* del *)
4235 begin match state.layout with
4238 let pageno = max
0 (l.pageno-1) in
4239 gotoy_and_clear_text (getpagey pageno)
4243 showtext ' '
(describe_location ());
4246 begin match state.layout with
4249 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4254 enterbookmarkmode ()
4262 | '
e'
when conf.redirectstderr ->
4267 match state.layout with
4270 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4274 enttext ("bookmark: ", "", None
, textentry, ondone)
4278 showtext ' '
"Quick bookmark added";
4281 begin match state.layout with
4283 let rect = getpdimrect
l.pagedimno
in
4287 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4288 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4290 (truncate
(rect.(1) -. rect.(0)),
4291 truncate
(rect.(3) -. rect.(0)))
4293 let w = truncate
((float w)*.conf.zoom)
4294 and h = truncate
((float h)*.conf.zoom) in
4297 state.anchor <- getanchor ();
4298 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4300 G.postRedisplay "z";
4305 | '
\000'
-> (* ctrl-2 *)
4306 let maxw = getmaxw
() in
4308 then setzoom (maxw /. float conf.winw
)
4311 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
4315 bound (conf.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
4317 G.postRedisplay "brightness";
4320 begin match state.mode with
4321 | Birdseye beye
-> upbirdseye 1 beye
4322 | _ -> gotoy (clamp (-conf.scrollstep
))
4326 begin match state.mode with
4327 | Birdseye beye
-> downbirdseye 1 beye
4328 | _ -> gotoy (clamp conf.scrollstep
)
4332 state.anchor <- getanchor ();
4333 opendoc state.path
state.password
4335 | '
v'
when not
conf.debug
->
4336 List.iter
debugl state.layout;
4338 | '
v'
when conf.debug
->
4341 match getopaque l.pageno with
4344 let x0, y0
, x1
, y1 = pagebbox opaque
in
4345 let a,b = float x0, float y0
in
4346 let c,d = float x1
, float y0
in
4347 let e,f = float x1
, float y1 in
4348 let h,j
= float x0, float y1 in
4349 let rect = (a,b,c,d,e,f,h,j
) in
4351 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4353 G.postRedisplay "v";
4356 vlog "huh? %d %c" key (Char.chr
key);
4359 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
4361 | 27 -> (* escape *)
4362 leavebirdseye beye
true
4364 | 12 -> (* ctrl-l *)
4365 let y, h = getpageyh pageno in
4366 let top = (conf.winh
- h) / 2 in
4367 gotoy (max
0 (y - top))
4370 leavebirdseye beye
false
4376 let keyboard ~
key ~
x ~
y =
4379 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
4380 then wcmd "interrupt" []
4381 else state.uioh <- state.uioh#
key key
4384 let birdseyespecial key ((oconf
, leftx
, _, hooverpageno
, anchor) as beye
) =
4386 match conf.columns
with
4388 | Some
((c, _, _), _) -> c
4391 | Glut.KEY_UP
-> upbirdseye incr beye
4392 | Glut.KEY_DOWN
-> downbirdseye incr beye
4393 | Glut.KEY_LEFT
-> upbirdseye 1 beye
4394 | Glut.KEY_RIGHT
-> downbirdseye 1 beye
4396 | Glut.KEY_PAGE_UP
->
4397 begin match state.layout with
4401 state.mode <- Birdseye
(
4402 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4404 gotopage1 l.pageno 0;
4407 let layout = layout (state.y-conf.winh
) conf.winh
in
4409 | [] -> gotoy (clamp (-conf.winh
))
4411 state.mode <- Birdseye
(
4412 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4414 gotopage1 l.pageno 0
4417 | [] -> gotoy (clamp (-conf.winh
))
4420 | Glut.KEY_PAGE_DOWN
->
4421 begin match List.rev
state.layout with
4423 let layout = layout (state.y + conf.winh
) conf.winh
in
4424 begin match layout with
4426 let incr = l.pageh
- l.pagevh in
4431 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4433 G.postRedisplay "birdseye pagedown";
4435 else gotoy (clamp (incr + conf.interpagespace*2));
4439 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4440 gotopage1 l.pageno 0;
4443 | [] -> gotoy (clamp conf.winh
)
4447 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4451 let pageno = state.pagecount
- 1 in
4452 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4453 if not
(pagevisible state.layout pageno)
4456 match List.rev
state.pdims
with
4458 | (_, _, h, _) :: _ -> h
4460 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4461 else G.postRedisplay "birdseye end";
4465 let setautoscrollspeed step goingdown
=
4466 let incr = max
1 ((abs step
) / 2) in
4467 let incr = if goingdown
then incr else -incr in
4468 let astep = step
+ incr in
4469 state.autoscroll
<- Some
astep;
4472 let special ~
key ~
x ~
y =
4475 state.uioh <- state.uioh#
special key
4480 match state.mode with
4481 | Textentry
_ -> scalecolor 0.4
4482 | View
-> scalecolor 1.0
4483 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4484 if l.pageno = hooverpageno
4487 if l.pageno = pageno
4493 begin match getopaque l.pageno with
4495 if tileready l l.pagex l.pagey
4497 let x = l.pagedispx
- l.pagex
4498 and y = l.pagedispy
- l.pagey in
4499 postprocess opaque
conf.hlinks
x y;
4505 let scrollindicator () =
4506 let sbw, ph
, sh = state.uioh#
scrollph in
4507 let sbh, pw
, sw = state.uioh#scrollpw
in
4509 GlDraw.color (0.64, 0.64, 0.64);
4511 (float (conf.winw
- sbw), 0.)
4512 (float conf.winw
, float conf.winh
)
4515 (0., float (conf.winh
- sbh))
4516 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4518 GlDraw.color (0.0, 0.0, 0.0);
4521 (float (conf.winw
- sbw), ph
)
4522 (float conf.winw
, ph
+. sh)
4525 (pw
, float (conf.winh
- sbh))
4526 (pw
+. sw, float conf.winh
)
4530 let pagetranslatepoint l x y =
4531 let dy = y - l.pagedispy
in
4532 let y = dy + l.pagey in
4533 let dx = x - l.pagedispx
in
4534 let x = dx + l.pagex in
4539 match state.mstate
with
4540 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4543 | Msel
((x0, y0
), (x1
, y1)) ->
4544 let rec loop = function
4546 if ((y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
4547 || ((y1 >= l.pagedispy
&& y1 <= (l.pagedispy
+ l.pagevh))))
4548 && ((x0 >= l.pagedispx
&& x0 <= (l.pagedispx
+ l.pagevw))
4549 || ((x1
>= l.pagedispx
&& x1
<= (l.pagedispx
+ l.pagevw))))
4551 match getopaque l.pageno with
4553 let dx, dy = pagetranslatepoint l 0 0 in
4558 GlMat.mode `modelview
;
4560 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4561 seltext opaque
(x0, y0
, x1
, y1);
4572 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4573 GlDraw.polygon_mode `both `fill
;
4574 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4576 (fun (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) ->
4578 if l.pageno = pageno
4580 let dx = float (l.pagedispx
- l.pagex) in
4581 let dy = float (l.pagedispy
- l.pagey) in
4582 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4583 GlDraw.begins `quads
;
4585 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4586 GlDraw.vertex2
(x1
+.dx, y1+.dy);
4587 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4588 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4599 GlClear.color (scalecolor2 conf.bgcolor
);
4600 GlClear.clear
[`
color];
4601 List.iter
drawpage state.layout;
4606 begin match state.mstate
with
4607 | Mzoomrect
((x0, y0
), (x1
, y1)) ->
4609 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4610 GlDraw.polygon_mode `both `fill
;
4611 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4612 GlDraw.rect (float x0, float y0
)
4613 (float x1
, float y1);
4618 Glut.swapBuffers
();
4622 let rec f = function
4624 begin match getopaque l.pageno with
4626 let x0 = l.pagedispx
in
4627 let x1 = x0 + l.pagevw in
4628 let y0 = l.pagedispy
in
4629 let y1 = y0 + l.pagevh in
4630 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4632 let px, py = pagetranslatepoint l x y in
4633 match whatsunder opaque
px py with
4645 let zoomrect x y x1 y1 =
4648 and y0 = min
y y1 in
4649 gotoy (state.y + y0);
4650 state.anchor <- getanchor ();
4651 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4653 if state.w < conf.winw
- state.scrollw
4654 then (conf.winw
- state.scrollw
- state.w) / 2
4657 state.x <- (state.x + margin) - x0;
4659 Glut.setCursor
Glut.CURSOR_INHERIT
;
4660 state.mstate
<- Mnone
;
4664 let winw = conf.winw - state.scrollw
- 1 in
4665 let s = float x /. float winw in
4666 let destx = truncate
(float (state.w + winw) *. s) in
4667 state.x <- winw - destx;
4668 gotoy_and_clear_text state.y;
4669 state.mstate
<- Mscrollx
;
4673 let s = float y /. float conf.winh
in
4674 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4675 gotoy_and_clear_text desty;
4676 state.mstate
<- Mscrolly
;
4679 let viewmouse button bstate
x y =
4681 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4682 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4684 match state.mstate
with
4685 | Mzoom
(oldn
, i
) ->
4693 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4695 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4697 let zoom = conf.zoom -. incr in
4699 state.mstate
<- Mzoom
(n, 0);
4701 state.mstate
<- Mzoom
(n, i
+1);
4703 else state.mstate
<- Mzoom
(n, 0)
4705 | _ -> state.mstate
<- Mzoom
(n, 0)
4708 match state.autoscroll
with
4709 | Some step
-> setautoscrollspeed step
(n=4)
4713 then -conf.scrollstep
4714 else conf.scrollstep
4716 let incr = incr * 2 in
4717 let y = clamp incr in
4718 gotoy_and_clear_text y
4721 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4722 if bstate
= Glut.DOWN
4724 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4725 state.mstate
<- Mpan
(x, y)
4728 state.mstate
<- Mnone
4730 | Glut.RIGHT_BUTTON
->
4731 if bstate
= Glut.DOWN
4733 Glut.setCursor
Glut.CURSOR_CYCLE
;
4735 state.mstate
<- Mzoomrect
(p, p)
4738 match state.mstate
with
4739 | Mzoomrect
((x0, y0), _) ->
4740 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4741 then zoomrect x0 y0 x y
4743 state.mstate
<- Mnone
;
4744 Glut.setCursor
Glut.CURSOR_INHERIT
;
4745 G.postRedisplay "kill accidental zoom rect";
4748 Glut.setCursor
Glut.CURSOR_INHERIT
;
4749 state.mstate
<- Mnone
4752 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4753 if bstate
= Glut.DOWN
4755 let _, position, sh = state.uioh#
scrollph in
4756 if y > truncate
position && y < truncate
(position +. sh)
4757 then state.mstate
<- Mscrolly
4760 state.mstate
<- Mnone
4762 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4763 if bstate
= Glut.DOWN
4765 let _, position, sw = state.uioh#scrollpw
in
4766 if x > truncate
position && x < truncate
(position +. sw)
4767 then state.mstate
<- Mscrollx
4770 state.mstate
<- Mnone
4772 | Glut.LEFT_BUTTON
->
4773 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4774 begin match dest with
4775 | Ulinkgoto
(pageno, top) ->
4779 gotopage1 pageno top;
4785 | Unone
when bstate
= Glut.DOWN
->
4786 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4787 state.mstate
<- Mpan
(x, y);
4789 | Unone
| Utext
_ ->
4790 if bstate
= Glut.DOWN
4792 if conf.angle
mod 360 = 0
4794 state.mstate
<- Msel
((x, y), (x, y));
4795 G.postRedisplay "mouse select";
4799 match state.mstate
with
4802 | Mzoom
_ | Mscrollx
| Mscrolly
->
4803 state.mstate
<- Mnone
4805 | Mzoomrect
((x0, y0), _) ->
4809 Glut.setCursor
Glut.CURSOR_INHERIT
;
4810 state.mstate
<- Mnone
4812 | Msel
((_, y0), (_, y1)) ->
4814 if (y0 >= l.pagedispy
&& y0 <= (l.pagedispy
+ l.pagevh))
4815 || ((y1 >= l.pagedispy
&& y1 <= (l.pagedispy
+ l.pagevh)))
4817 match getopaque l.pageno with
4822 List.iter
f state.layout;
4823 copysel
""; (* ugly *)
4824 Glut.setCursor
Glut.CURSOR_INHERIT
;
4825 state.mstate
<- Mnone
;
4832 let birdseyemouse button bstate
x y
4833 (conf, leftx
, _, hooverpageno
, anchor) =
4835 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4836 let rec loop = function
4839 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4840 && x > l.pagedispx
&& x < l.pagedispx
+ l.pagevw
4842 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4847 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4851 let mouse bstate button
x y =
4852 state.uioh <- state.uioh#button button bstate
x y;
4855 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4858 state.uioh <- state.uioh#
motion x y
4862 state.uioh <- state.uioh#
pmotion x y;
4869 begin match state.mode with
4870 | Textentry
textentry -> textentrykeyboard key textentry
4871 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4872 | View
-> viewkeyboard key
4876 method special key =
4877 begin match state.mode with
4878 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4882 birdseyespecial key vals
4884 | View
when key = Glut.KEY_F1
->
4888 begin match state.autoscroll
with
4889 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4890 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4895 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4897 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4899 if Glut.getModifiers
() land Glut.active_shift
!= 0
4900 then (setzoom state.prevzoom
; state.y)
4901 else clamp (-conf.winh
/2)
4902 else clamp (-conf.scrollstep
)
4904 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4906 if Glut.getModifiers
() land Glut.active_shift
!= 0
4907 then (setzoom state.prevzoom
; state.y)
4908 else clamp (conf.winh
/2)
4909 else clamp (conf.scrollstep
)
4910 | Glut.KEY_PAGE_UP
->
4911 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4913 match state.layout with
4915 | l :: _ -> state.y - l.pagey
4918 | Glut.KEY_PAGE_DOWN
->
4919 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4921 match List.rev
state.layout with
4923 | l :: _ -> getpagey l.pageno
4931 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
4933 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
4934 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
4935 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
4937 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
4939 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4940 then (conf.winw / 2)
4943 state.x <- state.x - dx;
4945 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
4947 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4948 then (conf.winw / 2)
4951 state.x <- state.x + dx;
4956 if abs
(state.y - y) > conf.scrollstep
*2
4958 else gotoy_and_clear_text y
4961 | Textentry
te -> textentryspecial key te
4965 method button button bstate
x y =
4966 begin match state.mode with
4967 | View
-> viewmouse button bstate
x y
4968 | Birdseye beye
-> birdseyemouse button bstate
x y beye
4974 begin match state.mode with
4976 | View
| Birdseye
_ ->
4977 match state.mstate
with
4978 | Mzoom
_ | Mnone
-> ()
4983 state.mstate
<- Mpan
(x, y);
4984 if conf.zoom > 1.0 then state.x <- state.x + dx;
4986 gotoy_and_clear_text y
4989 state.mstate
<- Msel
(a, (x, y));
4990 G.postRedisplay "motion select";
4993 let y = min
conf.winh
(max
0 y) in
4997 let x = min
conf.winw (max
0 x) in
5000 | Mzoomrect
(p0
, _) ->
5001 state.mstate
<- Mzoomrect
(p0
, (x, y));
5002 G.postRedisplay "motion zoomrect";
5006 method pmotion x y =
5007 begin match state.mode with
5008 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5009 let rec loop = function
5011 if hooverpageno
!= -1
5013 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5014 G.postRedisplay "pmotion birdseye no hoover";
5017 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
5018 && x > l.pagedispx
&& x < l.pagedispx
+ l.pagevw
5020 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5021 G.postRedisplay "pmotion birdseye hoover";
5030 match state.mstate
with
5032 begin match getunder x y with
5033 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
5035 if conf.underinfo
then showtext 'u'
("ri: " ^
uri);
5036 Glut.setCursor
Glut.CURSOR_INFO
5037 | Ulinkgoto
(page
, _) ->
5039 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
5040 Glut.setCursor
Glut.CURSOR_INFO
5042 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
5043 Glut.setCursor
Glut.CURSOR_TEXT
5046 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5051 method infochanged
_ = ()
5054 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5055 let p, h = scrollph state.y maxy in
5059 let winw = conf.winw - state.scrollw
- 1 in
5060 let fwinw = float winw in
5062 let sw = fwinw /. float state.w in
5063 let sw = fwinw *. sw in
5064 max
sw (float conf.scrollh
)
5067 let f = state.w+winw in
5068 let r = float (winw-state.x) /. float f in
5069 let p = fwinw *. r in
5073 if position +. sw > fwinw
5074 then fwinw -. position
5077 state.hscrollh, position, sw
5084 let fontpath = ref "";;
5085 let wmclasshack = ref false;;
5088 let l = String.length
s in
5089 let b = Buffer.create
l in
5097 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
5098 | _ -> Sys.getenv
"HOME"
5101 ("Can not determine home directory location: " ^
5102 Printexc.to_string exn
);
5106 let config_of c attrs
=
5110 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5111 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5112 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5113 | "preload" -> { c with preload = bool_of_string
v }
5114 | "page-bias" -> { c with pagebias
= int_of_string
v }
5115 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5116 | "auto-scroll-step" ->
5117 { c with autoscrollstep
= max
0 (int_of_string
v) }
5118 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5119 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5122 match String.lowercase
v with
5123 | "true" -> Some infinity
5125 | f -> Some
(float_of_string
f)
5127 { c with maxwait
= mw}
5128 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5129 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5130 | "vertical-margin" ->
5131 { c with interpagespace = max
0 (int_of_string
v) }
5133 let zoom = float_of_string
v /. 100. in
5134 let zoom = max
zoom 0.0 in
5135 { c with zoom = zoom }
5136 | "presentation" -> { c with presentation = bool_of_string
v }
5137 | "rotation-angle" -> { c with angle
= int_of_string
v }
5138 | "width" -> { c with winw = max
20 (int_of_string
v) }
5139 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5140 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5141 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5142 | "pixmap-cache-size" ->
5143 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5144 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5145 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5146 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5147 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5148 | "background-color" -> { c with bgcolor
= color_of_string v }
5149 | "scrollbar-in-presentation" ->
5150 { c with scrollbarinpm
= bool_of_string
v }
5151 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5152 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5153 | "mupdf-store-size" ->
5154 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5155 | "checkers" -> { c with checkers
= bool_of_string
v }
5156 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5157 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5158 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5159 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
5160 | "uri-launcher" -> { c with urilauncher
= unent v }
5161 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5162 | "invert-colors" -> { c with invert
= bool_of_string
v }
5163 | "brightness" -> { c with colorscale
= float_of_string
v }
5164 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5166 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5168 let nab = columns_of_string v in
5169 { c with columns
= Some
(nab, [||]) }
5170 | "birds-eye-columns" ->
5171 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5174 prerr_endline
("Error processing attribute (`" ^
5175 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5178 let rec fold c = function
5181 let c = apply c k
v in
5187 let fromstring f pos
n v d =
5190 dolog "Error processing attribute (%S=%S) at %d\n%s"
5191 n v pos
(Printexc.to_string exn
)
5196 let bookmark_of attrs
=
5197 let rec fold title page
rely = function
5198 | ("title", v) :: rest
-> fold v page
rely rest
5199 | ("page", v) :: rest
-> fold title v rely rest
5200 | ("rely", v) :: rest
-> fold title page
v rest
5201 | _ :: rest
-> fold title page
rely rest
5202 | [] -> title, page
, rely
5204 fold "invalid" "0" "0" attrs
5208 let rec fold path page
rely pan
= function
5209 | ("path", v) :: rest
-> fold v page
rely pan rest
5210 | ("page", v) :: rest
-> fold path
v rely pan rest
5211 | ("rely", v) :: rest
-> fold path page
v pan rest
5212 | ("pan", v) :: rest
-> fold path page
rely v rest
5213 | _ :: rest
-> fold path page
rely pan rest
5214 | [] -> path
, page
, rely, pan
5216 fold "" "0" "0" "0" attrs
5219 let setconf dst
src =
5220 dst
.scrollbw
<- src.scrollbw
;
5221 dst
.scrollh
<- src.scrollh
;
5222 dst
.icase
<- src.icase
;
5223 dst
.preload <- src.preload;
5224 dst
.pagebias
<- src.pagebias
;
5225 dst
.verbose
<- src.verbose
;
5226 dst
.scrollstep
<- src.scrollstep
;
5227 dst
.maxhfit
<- src.maxhfit
;
5228 dst
.crophack
<- src.crophack
;
5229 dst
.autoscrollstep
<- src.autoscrollstep
;
5230 dst
.maxwait
<- src.maxwait
;
5231 dst
.hlinks
<- src.hlinks
;
5232 dst
.underinfo
<- src.underinfo
;
5233 dst
.interpagespace <- src.interpagespace;
5234 dst
.zoom <- src.zoom;
5235 dst
.presentation <- src.presentation;
5236 dst
.angle
<- src.angle
;
5237 dst
.winw <- src.winw;
5238 dst
.winh
<- src.winh
;
5239 dst
.savebmarks
<- src.savebmarks
;
5240 dst
.memlimit
<- src.memlimit
;
5241 dst
.proportional
<- src.proportional
;
5242 dst
.texcount
<- src.texcount
;
5243 dst
.sliceheight
<- src.sliceheight
;
5244 dst
.thumbw
<- src.thumbw
;
5245 dst
.jumpback
<- src.jumpback
;
5246 dst
.bgcolor
<- src.bgcolor
;
5247 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5248 dst
.tilew
<- src.tilew
;
5249 dst
.tileh
<- src.tileh
;
5250 dst
.mustoresize
<- src.mustoresize
;
5251 dst
.checkers
<- src.checkers
;
5252 dst
.aalevel
<- src.aalevel
;
5253 dst
.trimmargins
<- src.trimmargins
;
5254 dst
.trimfuzz
<- src.trimfuzz
;
5255 dst
.urilauncher
<- src.urilauncher
;
5256 dst
.colorspace
<- src.colorspace
;
5257 dst
.invert
<- src.invert
;
5258 dst
.colorscale
<- src.colorscale
;
5259 dst
.redirectstderr <- src.redirectstderr;
5260 dst
.ghyllscroll
<- src.ghyllscroll
;
5261 dst
.columns
<- src.columns
;
5262 dst
.beyecolumns
<- src.beyecolumns
;
5266 let h = Hashtbl.create
10 in
5267 let dc = { defconf with angle
= defconf.angle
} in
5268 let rec toplevel v t spos
_ =
5270 | Vdata
| Vcdata
| Vend
-> v
5271 | Vopen
("llppconfig", _, closed
) ->
5274 else { v with f = llppconfig
}
5276 error
"unexpected subelement at top level" s spos
5277 | Vclose
_ -> error
"unexpected close at top level" s spos
5279 and llppconfig
v t spos
_ =
5281 | Vdata
| Vcdata
-> v
5282 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5283 | Vopen
("defaults", attrs
, closed
) ->
5284 let c = config_of dc attrs
in
5288 else { v with f = skip
"defaults" (fun () -> v) }
5290 | Vopen
("ui-font", attrs
, closed
) ->
5291 let rec getsize size
= function
5293 | ("size", v) :: rest
->
5295 fromstring int_of_string spos
"size" v fstate.fontsize
in
5297 | l -> getsize size l
5299 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5302 else { v with f = uifont
(Buffer.create
10) }
5304 | Vopen
("doc", attrs
, closed
) ->
5305 let pathent, spage
, srely
, span
= doc_of attrs
in
5306 let path = unent pathent
5307 and pageno = fromstring int_of_string spos
"page" spage
0
5308 and rely = fromstring float_of_string spos
"rely" srely
0.0
5309 and pan
= fromstring int_of_string spos
"pan" span
0 in
5310 let c = config_of dc attrs
in
5311 let anchor = (pageno, rely) in
5313 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5314 else { v with f = doc
path pan
anchor c [] }
5317 error
"unexpected subelement in llppconfig" s spos
5319 | Vclose
"llppconfig" -> { v with f = toplevel }
5320 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5322 and uifont
b v t spos epos
=
5325 Buffer.add_substring
b s spos
(epos
- spos
);
5327 | Vopen
(_, _, _) ->
5328 error
"unexpected subelement in ui-font" s spos
5329 | Vclose
"ui-font" ->
5330 if String.length
!fontpath = 0
5331 then fontpath := Buffer.contents
b;
5332 { v with f = llppconfig
}
5333 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5334 | Vend
-> error
"unexpected end of input in ui-font" s spos
5336 and doc
path pan
anchor c bookmarks
v t spos
_ =
5338 | Vdata
| Vcdata
-> v
5339 | Vend
-> error
"unexpected end of input in doc" s spos
5340 | Vopen
("bookmarks", _, closed
) ->
5343 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5345 | Vopen
(_, _, _) ->
5346 error
"unexpected subelement in doc" s spos
5349 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5350 { v with f = llppconfig
}
5352 | Vclose
_ -> error
"unexpected close in doc" s spos
5354 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5356 | Vdata
| Vcdata
-> v
5357 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5358 | Vopen
("item", attrs
, closed
) ->
5359 let titleent, spage
, srely
= bookmark_of attrs
in
5360 let page = fromstring int_of_string spos
"page" spage
0
5361 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5362 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5364 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5367 { v with f = skip
"item" f }
5370 error
"unexpected subelement in bookmarks" s spos
5372 | Vclose
"bookmarks" ->
5373 { v with f = doc
path pan
anchor c bookmarks }
5375 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5377 and skip tag
f v t spos
_ =
5379 | Vdata
| Vcdata
-> v
5381 error
("unexpected end of input in skipped " ^ tag
) s spos
5382 | Vopen
(tag'
, _, closed
) ->
5386 let f'
() = { v with f = skip tag
f } in
5387 { v with f = skip tag'
f'
}
5391 else error
("unexpected close in skipped " ^ tag
) s spos
5394 parse
{ f = toplevel; accu = () } s;
5400 let len = in_channel_length ic
in
5401 let s = String.create
len in
5402 really_input ic
s 0 len;
5405 | Parse_error
(msg
, s, pos
) ->
5406 let subs = subs s pos
in
5407 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5408 failwith
("parse error: " ^
s)
5411 failwith
("config load error: " ^
Printexc.to_string exn
)
5417 let dir = Filename.concat
home ".config" in
5418 if Sys.is_directory
dir then dir else home
5421 Filename.concat
dir "llpp.conf"
5424 let confpath = ref defconfpath;;
5427 if Sys.file_exists
!confpath
5430 (try Some
(open_in_bin
!confpath)
5433 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5434 Printexc.to_string exn
);
5443 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5444 Printexc.to_string exn
);
5450 f (Hashtbl.create
0, defconf)
5455 let pc, pb
, px, pa
=
5457 Hashtbl.find h (Filename.basename
state.path)
5458 with Not_found
-> dc, [], 0, (0, 0.0)
5462 state.bookmarks <- pb
;
5464 state.scrollw
<- conf.scrollbw
;
5466 then state.anchor <- pa
;
5467 cbput state.hists
.nav pa
;
5472 let add_attrs bb always
dc c =
5475 then Printf.bprintf bb
"\n %s='%b'" s a
5478 then Printf.bprintf bb
"\n %s='%d'" s a
5481 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5484 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5487 then Printf.bprintf bb
"\n %s='%f'" s a
5491 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5495 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5499 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5503 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5509 | Some
(_N
, _A
, _B
) ->
5510 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
5520 else string_of_float
f
5522 Printf.bprintf bb
"\n %s='%s'" s v
5527 | Some
((n, a, b), _) when n > 1 ->
5528 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
5534 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
5539 then dc.winw, dc.winh
5541 match state.fullscreen
with
5543 | None
-> c.winw, c.winh
5545 let zoom, presentation, interpagespace, maxwait
=
5547 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5549 match state.mode with
5550 | Birdseye
(bc
, _, _, _, _) ->
5551 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5552 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5554 oi
"width" w dc.winw;
5555 oi
"height" h dc.winh
;
5556 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5557 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5558 ob "case-insensitive-search" c.icase
dc.icase
;
5559 ob "preload" c.preload dc.preload;
5560 oi
"page-bias" c.pagebias
dc.pagebias
;
5561 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5562 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5563 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5564 ob "crop-hack" c.crophack
dc.crophack
;
5565 oW
"throttle" maxwait
dc.maxwait
;
5566 ob "highlight-links" c.hlinks
dc.hlinks
;
5567 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5568 oi
"vertical-margin" interpagespace dc.interpagespace;
5569 oz
"zoom" zoom dc.zoom;
5570 ob "presentation" presentation dc.presentation;
5571 oi
"rotation-angle" c.angle
dc.angle
;
5572 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5573 ob "proportional-display" c.proportional
dc.proportional
;
5574 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5575 oi
"tex-count" c.texcount
dc.texcount
;
5576 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5577 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5578 ob "persistent-location" c.jumpback
dc.jumpback
;
5579 oc
"background-color" c.bgcolor
dc.bgcolor
;
5580 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5581 oi
"tile-width" c.tilew
dc.tilew
;
5582 oi
"tile-height" c.tileh
dc.tileh
;
5583 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
5584 ob "checkers" c.checkers
dc.checkers
;
5585 oi
"aalevel" c.aalevel
dc.aalevel
;
5586 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5587 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5588 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5589 oC
"color-space" c.colorspace
dc.colorspace
;
5590 ob "invert-colors" c.invert
dc.invert
;
5591 oF
"brightness" c.colorscale
dc.colorscale
;
5592 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5593 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
5594 oco
"columns" c.columns
dc.columns
;
5595 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
5597 then ob "wmclass-hack" !wmclasshack false;
5601 let uifontsize = fstate.fontsize
in
5602 let bb = Buffer.create
32768 in
5604 let dc = if conf.bedefault
then conf else dc in
5605 Buffer.add_string
bb "<llppconfig>\n";
5607 if String.length
!fontpath > 0
5609 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5615 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5618 Buffer.add_string
bb "<defaults ";
5619 add_attrs bb true dc dc;
5620 Buffer.add_string
bb "/>\n";
5622 let adddoc path pan
anchor c bookmarks =
5623 if bookmarks == [] && c = dc && anchor = emptyanchor
5626 Printf.bprintf
bb "<doc path='%s'"
5627 (enent
path 0 (String.length
path));
5629 if anchor <> emptyanchor
5631 let n, y = anchor in
5632 Printf.bprintf
bb " page='%d'" n;
5635 Printf.bprintf
bb " rely='%f'" y
5640 then Printf.bprintf
bb " pan='%d'" pan
;
5642 add_attrs bb false dc c;
5644 begin match bookmarks with
5645 | [] -> Buffer.add_string
bb "/>\n"
5647 Buffer.add_string
bb ">\n<bookmarks>\n";
5648 List.iter
(fun (title, _level
, (page, rely)) ->
5650 "<item title='%s' page='%d'"
5651 (enent
title 0 (String.length
title))
5656 Printf.bprintf
bb " rely='%f'" rely
5658 Buffer.add_string
bb "/>\n";
5660 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5666 match state.mode with
5667 | Birdseye
(_, pan, _, _, _) -> pan
5670 let basename = Filename.basename state.path in
5671 adddoc basename pan (getanchor ())
5674 match state.autoscroll
with
5676 | None
-> conf.autoscrollstep
}
5677 (if conf.savebmarks
then state.bookmarks else []);
5679 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5681 then adddoc path x y c bookmarks
5683 Buffer.add_string
bb "</llppconfig>";
5686 if Buffer.length
bb > 0
5689 let tmp = !confpath ^
".tmp" in
5690 let oc = open_out_bin
tmp in
5691 Buffer.output_buffer
oc bb;
5693 Unix.rename
tmp !confpath;
5696 ("error while saving configuration: " ^
Printexc.to_string exn
)
5703 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5704 "<password> Set password");
5706 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5707 "<path> Set path to the user interface font");
5709 ("-c", Arg.String
(fun s -> Config.confpath := s),
5710 "<path> Set path to the configuration file");
5712 ("-v", Arg.Unit
(fun () ->
5714 "%s\nconfiguration path: %s\n"
5718 exit
0), " Print version and exit");
5721 (fun s -> state.path <- s)
5722 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5724 if String.length
state.path = 0
5725 then (prerr_endline
"file name missing"; exit
1);
5729 let _ = Glut.init
Sys.argv
in
5730 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5731 let () = Glut.initWindowSize
conf.winw conf.winh
in
5732 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5734 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5735 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5736 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5741 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5743 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5744 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5745 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5746 Unix.bind
sock addr;
5748 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5749 Unix.connect
csock addr;
5750 let ssock, _ = Unix.accept
sock in
5753 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5754 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5761 let () = Glut.displayFunc
display in
5762 let () = Glut.reshapeFunc
reshape in
5763 let () = Glut.keyboardFunc
keyboard in
5764 let () = Glut.specialFunc
special in
5765 let () = Glut.idleFunc
(Some
idle) in
5766 let () = Glut.mouseFunc
mouse in
5767 let () = Glut.motionFunc
motion in
5768 let () = Glut.passiveMotionFunc
pmotion in
5770 setcheckers conf.checkers
;
5772 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5773 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
5774 !Config.wmclasshack, !Config.fontpath
5776 state.csock <- csock;
5777 state.ssock <- ssock;
5778 state.text <- "Opening " ^
state.path;
5779 setaalevel
conf.aalevel
;
5780 writeopen state.path state.password
;
5782 setfontsize fstate.fontsize
;
5790 | Glut.BadEnum
"key in special_of_int" ->
5791 showtext '
!'
" LablGlut bug: special key not recognized";
5798 | exn
when conf.redirectstderr ->
5800 Printf.sprintf
"exception %s\n%s"
5801 (Printexc.to_string exn
)
5802 (Printexc.get_backtrace
())
5805 Unix.single_write
state.stderr
s 0 (String.length
s);