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 { mutable scrollbw
: int
218 ; mutable scrollh
: int
219 ; mutable icase
: bool
220 ; mutable preload
: bool
221 ; mutable pagebias
: int
222 ; mutable verbose
: bool
223 ; mutable debug
: bool
224 ; mutable scrollstep
: int
225 ; mutable maxhfit
: bool
226 ; mutable crophack
: bool
227 ; mutable autoscrollstep
: int
228 ; mutable maxwait
: float option
229 ; mutable hlinks
: bool
230 ; mutable underinfo
: bool
231 ; mutable interpagespace
: interpagespace
232 ; mutable zoom
: float
233 ; mutable presentation
: bool
234 ; mutable angle
: angle
237 ; mutable savebmarks
: bool
238 ; mutable proportional
: proportional
239 ; mutable trimmargins
: trimmargins
240 ; mutable trimfuzz
: irect
241 ; mutable memlimit
: memsize
242 ; mutable texcount
: texcount
243 ; mutable sliceheight
: sliceheight
244 ; mutable thumbw
: width
245 ; mutable jumpback
: bool
246 ; mutable bgcolor
: float * float * float
247 ; mutable bedefault
: bool
248 ; mutable scrollbarinpm
: bool
249 ; mutable tilew
: int
250 ; mutable tileh
: int
251 ; mutable mustoresize
: memsize
252 ; mutable checkers
: bool
253 ; mutable aalevel
: int
254 ; mutable urilauncher
: string
255 ; mutable colorspace
: colorspace
256 ; mutable invert
: bool
257 ; mutable colorscale
: float
258 ; mutable redirectstderr
: bool
259 ; mutable ghyllscroll
: (int * int * int) option
263 type anchor
= pageno
* top
;;
265 type outline
= string * int * anchor
;;
267 type rect
= float * float * float * float * float * float * float * float;;
269 type tile
= opaque
* pixmapsize
* elapsed
270 and elapsed
= float;;
271 type pagemapkey
= pageno
* gen
;;
272 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
276 let emptyanchor = (0, 0.0);;
278 type infochange
= | Memused
| Docinfo
| Pdim
;;
280 class type uioh
= object
281 method display
: unit
282 method key
: int -> uioh
283 method special
: Glut.special_key_t
-> uioh
285 Glut.button_t
-> Glut.mouse_button_state_t
-> int -> int -> uioh
286 method motion
: int -> int -> uioh
287 method pmotion
: int -> int -> uioh
288 method infochanged
: infochange
-> unit
289 method scrollpw
: (int * float * float)
290 method scrollph
: (int * float * float)
294 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
295 | Textentry
of (textentry
* onleave
)
297 and onleave
= leavetextentrystatus
-> unit
298 and leavetextentrystatus
= | Cancel
| Confirm
299 and helpitem
= string * int * action
302 | Action
of (uioh
-> uioh
)
305 let isbirdseye = function Birdseye _
-> true | _
-> false;;
306 let istextentry = function Textentry _
-> true | _
-> false;;
310 | Loading
of (page
* gen
)
312 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
314 | Outlining
of outline list
317 let nouioh : uioh
= object (self
)
320 method special _
= self
321 method button _ _ _ _
= self
322 method motion _ _
= self
323 method pmotion _ _
= self
324 method infochanged _
= ()
325 method scrollpw
= (0, nan
, nan
)
326 method scrollph
= (0, nan
, nan
)
330 { mutable csock
: Unix.file_descr
331 ; mutable ssock
: Unix.file_descr
332 ; mutable errfd
: Unix.file_descr
option
333 ; mutable stderr
: Unix.file_descr
334 ; mutable errmsgs
: Buffer.t
335 ; mutable newerrmsgs
: bool
339 ; mutable scrollw
: int
340 ; mutable hscrollh
: int
341 ; mutable anchor
: anchor
343 ; mutable layout
: page list
344 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
345 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
346 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
347 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
348 ; mutable pagecount
: int
349 ; mutable currently
: currently
350 ; mutable mstate
: mstate
351 ; mutable searchpattern
: string
352 ; mutable rects
: (pageno
* recttype
* rect
) list
353 ; mutable rects1
: (pageno
* recttype
* rect
) list
354 ; mutable text
: string
355 ; mutable fullscreen
: (width
* height
) option
356 ; mutable mode
: mode
357 ; mutable uioh
: uioh
358 ; mutable outlines
: outline array
359 ; mutable bookmarks
: outline list
360 ; mutable path
: string
361 ; mutable password
: string
362 ; mutable invalidated
: int
363 ; mutable memused
: memsize
365 ; mutable throttle
: (page list
* int * float) option
366 ; mutable autoscroll
: int option
367 ; mutable ghyll
: int option -> unit
368 ; mutable help
: helpitem array
369 ; mutable docinfo
: (int * string) list
370 ; mutable deadline
: float
371 ; mutable texid
: GlTex.texture_id
option
373 ; mutable prevzoom
: float
374 ; mutable progress
: float
377 { pat
: string circbuf
378 ; pag
: string circbuf
379 ; nav
: anchor circbuf
400 ; presentation
= false
405 ; proportional
= true
406 ; trimmargins
= false
407 ; trimfuzz
= (0,0,0,0)
408 ; memlimit
= 32 lsl 20
413 ; bgcolor
= (0.5, 0.5, 0.5)
415 ; scrollbarinpm
= true
418 ; mustoresize
= 128 lsl 20
423 | Plinux
| Pfreebsd
| Pdragonflybsd
| Popenbsd
| Psun
-> "xdg-open \"%s\""
424 | Posx
-> "open \"%s\""
425 | Pwindows
| Pcygwin
| Pmingw
-> "iexplore \"%s\""
430 ; redirectstderr
= false
435 let conf = { defconf with angle
= defconf.angle
};;
438 { mutable fontsize
: int
439 ; mutable wwidth
: float
440 ; mutable maxrows
: int
452 fstate.fontsize
<- n
;
453 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
454 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
458 if String.length
conf.urilauncher
= 0
459 then print_endline uri
461 let re = Str.regexp
"%s" in
462 let command = Str.global_replace
re uri
conf.urilauncher
in
464 try Some
(Unix.open_process_in
command)
467 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
472 | Some ic
-> close_in ic
477 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
478 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
482 let strings = version () :: "" :: Help.keys
in
484 let r = Str.regexp
"\\(http://[^ ]+\\)" in
486 if (try Str.search_forward
r s
0 with Not_found
-> -1) >= 0
488 let uri = Str.matched_string s
in
489 (s
, 0, Action
(fun u
-> gotouri uri; u
))
490 else s
, 0, Noaction
) strings
500 ; stderr
= Unix.stderr
501 ; errmsgs
= Buffer.create
0
508 ; anchor
= emptyanchor
511 ; tilelru
= Queue.create
()
512 ; pagemap
= Hashtbl.create
10
513 ; tilemap
= Hashtbl.create
10
530 { nav
= cbnew 10 (0, 0.0)
552 Printf.kprintf prerr_endline fmt
554 Printf.kprintf ignore fmt
557 let redirectstderr () =
558 if conf.redirectstderr
560 let rfd, wfd
= Unix.pipe
() in
561 state.stderr
<- Unix.dup
Unix.stderr
;
562 state.errfd
<- Some
rfd;
563 Unix.dup2 wfd
Unix.stderr
;
565 state.newerrmsgs
<- false;
566 begin match state.errfd
with
569 Unix.dup2
state.stderr
Unix.stderr
;
573 prerr_string
(Buffer.contents
state.errmsgs
);
575 Buffer.clear
state.errmsgs
;
581 let postRedisplay who
=
583 then prerr_endline
("redisplay for " ^ who
);
584 Glut.postRedisplay ();
589 let b = Buffer.create
(String.length s
+ 1) in
590 Buffer.add_string
b s
;
595 let colorspace_of_string s
=
596 match String.lowercase s
with
600 | _
-> failwith
"invalid colorspace"
603 let int_of_colorspace = function
609 let colorspace_of_int = function
613 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
616 let colorspace_to_string = function
622 let intentry_with_suffix text key
=
623 let c = Char.unsafe_chr key
in
624 match Char.lowercase
c with
626 let text = addchar text c in
630 let text = addchar text c in
634 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
639 let len = String.length s
in
641 let b = Buffer.create
n in
642 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
643 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
644 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
645 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
646 Buffer.add_string
b s
;
647 let s'
= Buffer.contents
b in
648 let n'
= Unix.write fd
s'
0 n in
649 if n'
!= n then failwith
"write failed";
654 let n = Unix.read fd
s 0 4 in
655 if n != 4 then failwith
"incomplete read(len)";
657 lor (Char.code
s.[0] lsl 24)
658 lor (Char.code
s.[1] lsl 16)
659 lor (Char.code
s.[2] lsl 8)
660 lor (Char.code
s.[3] lsl 0)
662 let s = String.create
len in
663 let n = Unix.read fd
s 0 len in
664 if n != len then failwith
"incomplete read(data)";
669 let b = Buffer.create
10 in
670 Buffer.add_string
b s;
671 let rec combine = function
674 Buffer.add_char
b ' '
;
677 | `
b b -> if b then "1" else "0"
679 | `i i
-> string_of_int i
680 | `f f
-> string_of_float f
681 | `I f
-> string_of_int
(truncate f
)
683 Buffer.add_string
b s;
690 let cmd = Buffer.contents
(makecmd s l
) in
691 writecmd state.csock
cmd;
697 let d = conf.winh
- h
in
704 let rec f pn ph pi fh l
=
706 | (n, _
, h
, _
) :: rest
->
707 let ips = calcips h
in
712 if isbirdseye state.mode
&& pn
= 0
717 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
722 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
726 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
729 let fh = f 0 0 0 0 state.pdims
in
733 let getpageyh pageno
=
734 let rec f pn ph pi y l
=
736 | (n, _
, h
, _
) :: rest
->
737 let ips = calcips h
in
740 let h = if n = pageno
then h else ph
in
741 if conf.presentation
&& n = pageno
743 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
745 y
+ (pageno
- pn
) * (ph
+ pi
), h
747 let y = y + (if conf.presentation
then pi
else 0) in
748 let y = y + (n - pn
) * (ph
+ pi
) in
752 y + (pageno
- pn
) * (ph
+ pi
), ph
754 f 0 0 0 0 state.pdims
757 let getpagedim pageno
=
760 | (n, _
, _
, _
) as pdim
:: rest
->
762 then (if n = pageno
then pdim
else ppdim
)
767 f (-1, -1, -1, -1) state.pdims
770 let getpagey pageno
= fst
(getpageyh pageno
);;
773 let sh = sh - state.hscrollh
in
774 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
775 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
777 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
778 let ips = calcips h in
780 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
784 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
786 prev
, pdims
, pdimno
, 0
788 let dy = dy + yinc in
789 let py = py + yinc in
790 if pageno
= state.pagecount
|| dy >= sh
795 if py + h <= vy - yinc
797 let py = py + h + ips in
798 let dy = max
0 (py - y) in
807 let pagey = vy - py in
808 let pagevh = h - pagey in
809 let pagevh = min
(sh - dy) pagevh in
810 let off = if yinc > 0 then py - vy else 0 in
811 let py = py + h + ips in
814 if state.w
< conf.winw
- state.scrollw
815 then (conf.winw
- state.scrollw
- state.w
) / 2
818 let dispx = xoff + state.x
in
824 let lw = w
- pagex in
825 min
lw (conf.winw
- state.scrollw
)
833 ; pagey = pagey + off
835 ; pagevh = pagevh - off
837 ; pagedispy
= dy + off
840 let accu = e :: accu in
849 if state.invalidated
= 0
868 let y = state.y + incr
in
870 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
874 let getopaque pageno
=
875 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
876 with Not_found
-> None
879 let putopaque pageno opaque
=
880 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
884 let tilex = l
.pagex mod conf.tilew
in
885 let tiley = l
.pagey mod conf.tileh
in
887 let col = l
.pagex / conf.tilew
in
888 let row = l
.pagey / conf.tileh
in
891 let a = l
.pagew
- l
.pagex in
892 let b = conf.winw
- state.scrollw
in
896 let rec rowloop row y0 dispy
h =
900 let dh = conf.tileh
- y0
in
902 let rec colloop col x0
dispx w
=
906 let dw = conf.tilew
- x0
in
909 f col row dispx dispy x0 y0
dw dh;
910 colloop (col+1) 0 (dispx+dw) (w
-dw)
913 colloop col tilex l
.pagedispx
vw;
914 rowloop (row+1) 0 (dispy
+dh) (h-dh)
918 then rowloop row tiley l
.pagedispy vh
;
921 let gettileopaque l
col row =
923 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
925 try Some
(Hashtbl.find
state.tilemap
key)
926 with Not_found
-> None
929 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
930 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
931 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
934 let drawtiles l color
=
936 let f col row x
y tilex tiley w
h =
937 match gettileopaque l
col row with
938 | Some
(opaque
, _
, t
) ->
939 let params = x
, y, w
, h, tilex, tiley in
943 GlFunc.blend_func `zero `one_minus_src_color
;
945 drawtile
params opaque
;
947 then Gl.disable `blend
;
950 let s = Printf.sprintf
954 let w = measurestr
fstate.fontsize
s in
955 GlMisc.push_attrib
[`current
];
956 GlDraw.color
(0.0, 0.0, 0.0);
958 (float (x
-2), float (y-2))
959 (float (x
+2) +. w, float (y + fstate.fontsize
+ 2));
960 GlDraw.color
(1.0, 1.0, 1.0);
961 drawstring fstate.fontsize x
(y + fstate.fontsize
- 1) s;
962 GlMisc.pop_attrib
();
967 let lw = conf.winw
- state.scrollw
- x
in
970 let lh = conf.winh
- y in
973 Gl.enable `texture_2d
;
974 begin match state.texid
with
976 GlTex.bind_texture `texture_2d id
;
980 and y1
= float (y+h) in
982 let tw = float w /. 64.0
983 and th
= float h /. 64.0 in
984 let tx0 = float tilex /. 64.0
985 and ty0
= float tiley /. 64.0 in
987 and ty1
= ty0
+. th
in
988 GlDraw.begins `quads
;
989 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
990 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
991 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
992 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
995 Gl.disable `texture_2d
;
997 GlDraw.color
(1.0, 1.0, 1.0);
1000 (float (x
+w), float (y+h));
1002 if w > 128 && h > fstate.fontsize
+ 10
1004 GlDraw.color
(0.0, 0.0, 0.0);
1007 then (col*conf.tilew
, row*conf.tileh
)
1010 drawstring2 fstate.fontsize x
y "Loading %d [%d,%d]" l
.pageno
c r;
1017 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1019 let tilevisible1 l x
y =
1021 and ax1
= l
.pagex + l
.pagevw
1023 and ay1
= l
.pagey + l
.pagevh in
1027 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1028 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1030 let rx0 = max
ax0 bx0
1031 and ry0
= max ay0 by0
1032 and rx1
= min ax1
bx1
1033 and ry1
= min ay1 by1
in
1035 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1036 nonemptyintersection
1039 let tilevisible layout n x
y =
1040 let rec findpageinlayout = function
1041 | l
:: _
when l
.pageno
= n -> tilevisible1 l x
y
1042 | _
:: rest
-> findpageinlayout rest
1045 findpageinlayout layout
1048 let tileready l x
y =
1049 tilevisible1 l x
y &&
1050 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
1053 let tilepage n p
layout =
1054 let rec loop = function
1058 let f col row _ _ _ _ _ _
=
1059 if state.currently
= Idle
1061 match gettileopaque l
col row with
1064 let x = col*conf.tilew
1065 and y = row*conf.tileh
in
1067 let w = l
.pagew
- x in
1071 let h = l
.pageh
- y in
1083 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1084 conf.tilew
, conf.tileh
1093 if state.invalidated
= 0 then loop layout;
1096 let preloadlayout visiblepages
=
1097 let presentation = conf.presentation in
1098 let interpagespace = conf.interpagespace in
1099 let maxy = state.maxy in
1100 conf.presentation <- false;
1101 conf.interpagespace <- 0;
1102 state.maxy <- calcheight ();
1104 match visiblepages
with
1106 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1108 let y = if y < conf.winh
then 0 else y - conf.winh
in
1109 let h = state.y - y + conf.winh
*3 in
1110 let pages = layout y h in
1111 conf.presentation <- presentation;
1112 conf.interpagespace <- interpagespace;
1118 let rec loop pages =
1119 if state.currently
!= Idle
1124 begin match getopaque l
.pageno
with
1126 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1127 state.currently
<- Loading
(l
, state.gen
);
1129 tilepage l
.pageno opaque
pages;
1134 if state.invalidated
= 0 then loop pages
1139 if conf.preload && state.currently
= Idle
1140 then load (preloadlayout pages);
1143 let layoutready layout =
1144 let rec fold all ls
=
1145 all
&& match ls
with
1147 let seen = ref false in
1148 let allvisible = ref true in
1149 let foo col row _ _ _ _ _ _
=
1151 allvisible := !allvisible &&
1152 begin match gettileopaque l
col row with
1158 fold (!seen && !allvisible) rest
1161 let alltilesvisible = fold true layout in
1166 let y = bound y 0 state.maxy in
1167 let y, layout, proceed
=
1168 match conf.maxwait
with
1169 | Some time
when state.ghyll
== noghyll ->
1170 begin match state.throttle
with
1172 let layout = layout y conf.winh
in
1173 let ready = layoutready layout in
1177 state.throttle
<- Some
(layout, y, now ());
1179 else G.postRedisplay "gotoy showall (None)";
1181 | Some
(_
, _
, started
) ->
1182 let dt = now () -. started
in
1185 state.throttle
<- None
;
1186 let layout = layout y conf.winh
in
1188 G.postRedisplay "maxwait";
1195 let layout = layout y conf.winh
in
1196 if true || layoutready layout
1197 then G.postRedisplay "gotoy ready";
1203 state.layout <- layout;
1204 begin match state.mode
with
1205 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1206 if not
(pagevisible layout pageno
)
1208 match state.layout with
1211 state.mode
<- Birdseye
(
1212 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1219 state.ghyll
<- noghyll;
1222 let conttiling pageno opaque
=
1223 tilepage pageno opaque
1224 (if conf.preload then preloadlayout state.layout else state.layout)
1227 let gotoy_and_clear_text y =
1229 if not
conf.verbose
then state.text <- "";
1233 match state.layout with
1235 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1238 let getanchory (n, top
) =
1239 let y, h = getpageyh n in
1240 y + (truncate
(top
*. float h));
1243 let gotoanchor anchor
=
1244 gotoy (getanchory anchor
);
1248 cbput state.hists
.nav
(getanchor ());
1252 let anchor = cbgetc state.hists
.nav dir
in
1257 let rec scroll f n a b =
1258 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1260 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1262 then s (float f /. float a)
1265 then 1.0 -. s ((float (f-b) /. float (n-b)))
1272 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1273 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1275 let ins = float a *. iv1
1276 and outs
= float (n-b) *. iv1 in
1278 ins +. outs
+. float ones
1280 let rec set (_N
, _A
, _B
) y sy
=
1281 let sum = summa
1.0 _N _A _B
in
1282 let dy = float (y - sy
) in
1286 then state.ghyll
<- noghyll
1289 let s = scroll n _N _A _B
in
1290 let y1 = y1 +. ((s *. dy) /. sum) in
1291 gotoy_and_clear_text (truncate
y1);
1292 state.ghyll
<- gf (n+1) y1;
1296 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1298 gf 0 (float state.y)
1301 match conf.ghyllscroll
with
1303 gotoy_and_clear_text y
1305 if state.ghyll
== noghyll
1306 then set nab
y state.y
1307 else state.ghyll
(Some
y)
1310 let gotopage n top
=
1311 let y, h = getpageyh n in
1312 let y = y + (truncate
(top
*. float h)) in
1316 let gotopage1 n top
=
1317 let y = getpagey n in
1327 state.invalidated
<- state.invalidated
+ 1;
1330 let writeopen path password
=
1331 writecmd state.csock
("open " ^ path ^
"\000" ^ password ^
"\000");
1334 let opendoc path password
=
1337 state.password
<- password
;
1338 state.gen
<- state.gen
+ 1;
1339 state.docinfo
<- [];
1341 setaalevel
conf.aalevel
;
1342 writeopen path password
;
1343 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1344 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1348 let c = c *. conf.colorscale
in
1352 let scalecolor2 (r, g
, b) =
1353 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1357 state.maxy <- calcheight ();
1359 if state.w <= conf.winw
- state.scrollw
1363 match state.mode
with
1364 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1365 let y, h = getpageyh pageno
in
1366 let top = (conf.winh
- h) / 2 in
1367 gotoy (max
0 (y - top))
1368 | _
-> gotoanchor state.anchor
1372 let firsttime = ref true in
1374 GlDraw.viewport
0 0 w h;
1375 if state.invalidated
= 0 && not
!firsttime
1376 then state.anchor <- getanchor ();
1380 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1384 setfontsize fstate.fontsize
;
1385 GlMat.mode `modelview
;
1386 GlMat.load_identity
();
1388 GlMat.mode `projection
;
1389 GlMat.load_identity
();
1390 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1391 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1392 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1395 wcmd "geometry" [`i
w; `i
h];
1399 let len = String.length
state.text in
1402 match state.mode
with
1403 | View
-> state.hscrollh
1408 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1409 (x+.w, float (conf.winh
- hscrollh))
1412 let w = float (conf.winw
- state.scrollw
- 1) in
1413 if state.progress
>= 0.0 && state.progress
< 1.0
1415 GlDraw.color
(0.3, 0.3, 0.3);
1416 let w1 = w *. state.progress
in
1418 GlDraw.color
(0.0, 0.0, 0.0);
1422 GlDraw.color
(0.0, 0.0, 0.0);
1426 GlDraw.color
(1.0, 1.0, 1.0);
1427 drawstring fstate.fontsize
1428 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1431 match state.mode
with
1432 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1436 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1438 Printf.sprintf
"%s%s_" prefix
text
1447 if not
(istextentry state.mode
)
1449 let s1 = "(press 'e' to review error messasges)" in
1450 if String.length
s > 0 then s ^
" " ^
s1 else s1
1455 if String.length
s > 0
1460 state.text <- Printf.sprintf
"%c%s" c s;
1461 G.postRedisplay "showtext";
1465 let len = Queue.length
state.tilelru
in
1467 if state.memused
<= conf.memlimit
1472 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1473 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1474 let (_
, pw
, ph
, _
) = getpagedim n in
1477 && colorspace
= conf.colorspace
1478 && angle
= conf.angle
1483 match state.throttle
with
1486 then preloadlayout state.layout
1488 | Some
(layout, _
, _
) ->
1491 let x = col*conf.tilew
1492 and y = row*conf.tileh
in
1493 tilevisible layout n x y
1495 then Queue.push lruitem
state.tilelru
1497 wcmd "freetile" [`
s p
];
1498 state.memused
<- state.memused
- s;
1499 state.uioh#infochanged Memused
;
1500 Hashtbl.remove
state.tilemap k
;
1509 Queue.iter
(fun (k
, p
, s) ->
1510 wcmd "freetile" [`
s p
];
1511 state.memused
<- state.memused
- s;
1512 state.uioh#infochanged Memused
;
1513 Hashtbl.remove
state.tilemap k
;
1515 Queue.clear
state.tilelru
;
1519 let logcurrently = function
1520 | Idle
-> dolog "Idle"
1521 | Loading
(l
, gen
) ->
1522 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1523 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1525 "Tiling %d[%d,%d] page=%s cs=%s angle"
1526 l
.pageno
col row pageopaque
1527 (colorspace_to_string colorspace
)
1529 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1530 angle gen
conf.angle
state.gen
1532 conf.tilew
conf.tileh
1539 (* dolog "%S" cmds; *)
1542 try String.index cmds ' '
1543 with Not_found
-> -1
1548 let l = String.length cmds
in
1549 let op = String.sub cmds
0 spacepos in
1551 if l - spacepos < 2 then ""
1552 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1557 state.uioh#infochanged Pdim
;
1561 state.rects
<- state.rects1
;
1562 G.postRedisplay "clearrects";
1566 try Scanf.sscanf args
"%u" (fun n -> n)
1568 dolog "error processing 'continue' %S: %s"
1569 cmds
(Printexc.to_string exn
);
1572 state.pagecount
<- n;
1573 state.invalidated
<- state.invalidated
- 1;
1574 begin match state.currently
with
1576 state.currently
<- Idle
;
1577 state.outlines
<- Array.of_list
(List.rev
l)
1580 if state.invalidated
= 0
1582 if conf.maxwait
= None
1583 then G.postRedisplay "continue";
1586 Glut.setWindowTitle args
1593 then showtext ' ' args
1596 let progress, text =
1598 Scanf.sscanf args
"%f %n"
1600 f, String.sub args pos
(String.length args
- pos
))
1602 dolog "error processing 'progress' %S: %s"
1603 cmds
(Printexc.to_string exn
);
1607 state.progress <- progress;
1608 G.postRedisplay "progress"
1611 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1613 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1614 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1615 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1617 dolog "error processing 'firstmatch' %S: %s"
1618 cmds
(Printexc.to_string exn
);
1621 let y = (getpagey pageno) + truncate y0
in
1624 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)]
1627 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1629 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1630 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1631 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1633 dolog "error processing 'match' %S: %s"
1634 cmds
(Printexc.to_string exn
);
1638 (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) :: state.rects1
1643 Scanf.sscanf args
"%s %f" (fun p t
-> p
, t
)
1645 dolog "error processing 'page' %S: %s"
1646 cmds
(Printexc.to_string exn
);
1649 begin match state.currently
with
1650 | Loading
(l, gen
) ->
1651 vlog "page %d took %f sec" l.pageno t
;
1652 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1653 begin match state.throttle
with
1655 let preloadedpages =
1657 then preloadlayout state.layout
1662 Set.Make
(struct type t
= int let compare = (-) end) in
1664 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1665 IntSet.empty
preloadedpages
1668 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
1669 if not
(IntSet.mem
pageno set)
1671 wcmd "freepage" [`
s opaque
];
1677 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1680 state.currently
<- Idle
;
1683 tilepage l.pageno pageopaque state.layout;
1685 load preloadedpages;
1686 if pagevisible state.layout l.pageno
1687 && layoutready state.layout
1688 then G.postRedisplay "page";
1691 | Some
(layout, _
, _
) ->
1692 state.currently
<- Idle
;
1693 tilepage l.pageno pageopaque layout;
1698 dolog "Inconsistent loading state";
1699 logcurrently state.currently
;
1704 let (x, y, opaque
, size
, t
) =
1706 Scanf.sscanf args
"%u %u %s %u %f"
1707 (fun x y p size t
-> (x, y, p
, size
, t
))
1709 dolog "error processing 'tile' %S: %s"
1710 cmds
(Printexc.to_string exn
);
1713 begin match state.currently
with
1714 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1715 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1717 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1719 wcmd "freetile" [`
s opaque
];
1720 state.currently
<- Idle
;
1724 puttileopaque l col row gen cs angle opaque size t
;
1725 state.memused
<- state.memused
+ size
;
1726 state.uioh#infochanged Memused
;
1728 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1729 opaque
, size
) state.tilelru
;
1732 match state.throttle
with
1733 | None
-> state.layout
1734 | Some
(layout, _
, _
) -> layout
1737 state.currently
<- Idle
;
1739 && conf.colorspace
= cs
1740 && conf.angle
= angle
1741 && tilevisible layout l.pageno x y
1742 then conttiling l.pageno pageopaque;
1744 begin match state.throttle
with
1746 preload state.layout;
1748 && conf.colorspace
= cs
1749 && conf.angle
= angle
1750 && tilevisible state.layout l.pageno x y
1751 then G.postRedisplay "tile nothrottle";
1753 | Some
(layout, y, _
) ->
1754 let ready = layoutready layout in
1758 state.layout <- layout;
1759 state.throttle
<- None
;
1760 G.postRedisplay "throttle";
1767 dolog "Inconsistent tiling state";
1768 logcurrently state.currently
;
1775 Scanf.sscanf args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1777 dolog "error processing 'pdim' %S: %s"
1778 cmds
(Printexc.to_string exn
);
1781 state.uioh#infochanged Pdim
;
1782 state.pdims
<- pdim :: state.pdims
1785 let (l, n, t
, h, pos
) =
1787 Scanf.sscanf args
"%u %u %d %u %n"
1788 (fun l n t
h pos
-> l, n, t
, h, pos
)
1790 dolog "error processing 'o' %S: %s"
1791 cmds
(Printexc.to_string exn
);
1794 let s = String.sub args pos
(String.length args
- pos
) in
1795 let outline = (s, l, (n, float t
/. float h)) in
1796 begin match state.currently
with
1797 | Outlining outlines
->
1798 state.currently
<- Outlining
(outline :: outlines
)
1800 state.currently
<- Outlining
[outline]
1802 dolog "invalid outlining state";
1803 logcurrently currently
1807 state.docinfo
<- (1, args
) :: state.docinfo
1810 state.uioh#infochanged Docinfo
;
1811 state.docinfo
<- List.rev
state.docinfo
1814 dolog "unknown cmd `%S'" cmds
1818 if state.deadline
== nan
then state.deadline
<- now ();
1820 match state.errfd
with
1821 | None
-> [state.csock
]
1822 | Some fd
-> [state.csock
; fd
]
1824 let rec loop delay
=
1826 if state.ghyll
== noghyll
1832 then max
0.0 (deadline -. now ())
1835 let r, _
, _
= Unix.select
r [] [] timeout in
1839 begin match state.autoscroll
with
1840 | Some step
when step
!= 0 ->
1841 let y = state.y + step
in
1845 else if y >= state.maxy then 0 else y
1848 if state.mode
= View
1849 then state.text <- "";
1850 state.deadline <- state.deadline +. 0.005;
1853 state.deadline <- state.deadline +. delay
;
1857 let rec checkfds c = function
1859 | fd
:: rest
when fd
= state.csock
->
1860 let cmd = readcmd state.csock
in
1864 let s = String.create
80 in
1865 let n = Unix.read fd
s 0 80 in
1866 if conf.redirectstderr
1868 Buffer.add_substring
state.errmsgs
s 0 n;
1869 state.newerrmsgs
<- true;
1870 Glut.postRedisplay ();
1873 prerr_string
(String.sub
s 0 n);
1886 let action = function
1887 | HCprev
-> cbget cb ~
-1
1888 | HCnext
-> cbget cb
1
1889 | HCfirst
-> cbget cb ~
-(cb
.rc)
1890 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1891 and cancel
() = cb
.rc <- rc
1895 let search pattern forward
=
1896 if String.length pattern
> 0
1899 match state.layout with
1902 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1905 let b = makecmd "search"
1906 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
1908 Buffer.add_char
b '
,'
;
1909 Buffer.add_string
b pattern
;
1910 Buffer.add_char
b '
\000'
;
1913 writecmd state.csock
cmd;
1916 let intentry text key =
1917 let c = Char.unsafe_chr
key in
1920 let text = addchar text c in
1924 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1928 let textentry text key =
1929 let c = Char.unsafe_chr
key in
1931 | _
when key >= 32 && key < 127 ->
1932 let text = addchar text c in
1936 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
1940 let reqlayout angle proportional
=
1941 match state.throttle
with
1943 if state.invalidated
= 0 then state.anchor <- getanchor ();
1944 conf.angle
<- angle
mod 360;
1945 conf.proportional
<- proportional
;
1947 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
1951 let settrim trimmargins trimfuzz
=
1952 if state.invalidated
= 0 then state.anchor <- getanchor ();
1953 conf.trimmargins
<- trimmargins
;
1954 conf.trimfuzz
<- trimfuzz
;
1955 let x0, y0
, x1
, y1 = trimfuzz
in
1958 `
b conf.trimmargins
;
1964 Hashtbl.iter
(fun _ opaque
->
1965 wcmd "freepage" [`
s opaque
];
1967 Hashtbl.clear
state.pagemap
;
1971 match state.throttle
with
1973 let zoom = max
0.01 zoom in
1974 if zoom <> conf.zoom
1976 state.prevzoom
<- conf.zoom;
1979 then (state.x <- 0; 0.0)
1980 else float state.x /. float state.w
1983 reshape conf.winw
conf.winh
;
1986 let x = relx *. float state.w in
1987 state.x <- truncate
x;
1989 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
1992 | Some
(layout, y, started
) ->
1994 match conf.maxwait
with
1998 let dt = now () -. started
in
2006 let enterbirdseye () =
2007 let zoom = float conf.thumbw
/. float conf.winw
in
2008 let birdseyepageno =
2009 let cy = conf.winh
/ 2 in
2013 let rec fold best
= function
2016 let d = cy - (l.pagedispy
+ l.pagevh/2)
2017 and dbest
= cy - (best
.pagedispy
+ best
.pagevh/2) in
2018 if abs
d < abs dbest
2025 state.mode
<- Birdseye
(
2026 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2029 conf.presentation <- false;
2030 conf.interpagespace <- 10;
2031 conf.hlinks
<- false;
2033 state.mstate
<- Mnone
;
2034 conf.maxwait
<- None
;
2035 Glut.setCursor
Glut.CURSOR_INHERIT
;
2038 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2043 reshape conf.winw
conf.winh
;
2046 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2048 conf.zoom <- c.zoom;
2049 conf.presentation <- c.presentation;
2050 conf.interpagespace <- c.interpagespace;
2051 conf.maxwait
<- c.maxwait
;
2052 conf.hlinks
<- c.hlinks
;
2056 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2059 reshape conf.winw
conf.winh
;
2060 state.anchor <- if goback
then anchor else (pageno, 0.0);
2063 let togglebirdseye () =
2064 match state.mode
with
2065 | Birdseye vals
-> leavebirdseye vals
true
2066 | View
-> enterbirdseye ()
2070 let upbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
2071 let pageno = max
0 (pageno - 1) in
2072 let rec loop = function
2073 | [] -> gotopage1 pageno 0
2074 | l :: _
when l.pageno = pageno ->
2075 if l.pagedispy
>= 0 && l.pagey = 0
2076 then G.postRedisplay "upbirdseye"
2077 else gotopage1 pageno 0
2078 | _
:: rest
-> loop rest
2081 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2084 let downbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
2085 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
2086 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2087 let rec loop = function
2089 let y, h = getpageyh pageno in
2090 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2092 | l :: _
when l.pageno = pageno ->
2093 if l.pagevh != l.pageh
2094 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2095 else G.postRedisplay "downbirdseye"
2096 | _
:: rest
-> loop rest
2101 let optentry mode _
key =
2102 let btos b = if b then "on" else "off" in
2103 let c = Char.unsafe_chr
key in
2107 try conf.scrollstep
<- int_of_string
s with exc
->
2108 state.text <- Printf.sprintf
"bad integer `%s': %s"
2109 s (Printexc.to_string exc
)
2111 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2116 conf.autoscrollstep
<- int_of_string
s;
2117 if state.autoscroll
<> None
2118 then state.autoscroll
<- Some
conf.autoscrollstep
2120 state.text <- Printf.sprintf
"bad integer `%s': %s"
2121 s (Printexc.to_string exc
)
2123 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2128 let zoom = float (int_of_string
s) /. 100.0 in
2131 state.text <- Printf.sprintf
"bad integer `%s': %s"
2132 s (Printexc.to_string exc
)
2134 TEswitch
("zoom: ", "", None
, intentry, ondone)
2139 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2141 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2142 begin match mode
with
2144 leavebirdseye beye
false;
2149 state.text <- Printf.sprintf
"bad integer `%s': %s"
2150 s (Printexc.to_string exc
)
2152 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2157 Some
(int_of_string
s)
2159 state.text <- Printf.sprintf
"bad integer `%s': %s"
2160 s (Printexc.to_string exc
);
2163 | Some angle
-> reqlayout angle
conf.proportional
2166 TEswitch
("rotation: ", "", None
, intentry, ondone)
2169 conf.icase
<- not
conf.icase
;
2170 TEdone
("case insensitive search " ^
(btos conf.icase
))
2173 conf.preload <- not
conf.preload;
2175 TEdone
("preload " ^
(btos conf.preload))
2178 conf.verbose
<- not
conf.verbose
;
2179 TEdone
("verbose " ^
(btos conf.verbose
))
2182 conf.debug
<- not
conf.debug
;
2183 TEdone
("debug " ^
(btos conf.debug
))
2186 conf.maxhfit
<- not
conf.maxhfit
;
2188 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2189 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2192 conf.crophack
<- not
conf.crophack
;
2193 TEdone
("crophack " ^
btos conf.crophack
)
2197 match conf.maxwait
with
2199 conf.maxwait
<- Some infinity
;
2200 "always wait for page to complete"
2202 conf.maxwait
<- None
;
2203 "show placeholder if page is not ready"
2208 conf.underinfo
<- not
conf.underinfo
;
2209 TEdone
("underinfo " ^
btos conf.underinfo
)
2212 conf.savebmarks
<- not
conf.savebmarks
;
2213 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2219 match state.layout with
2224 conf.interpagespace <- int_of_string
s;
2225 state.maxy <- calcheight ();
2226 let y = getpagey pageno in
2229 state.text <- Printf.sprintf
"bad integer `%s': %s"
2230 s (Printexc.to_string exc
)
2232 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2235 reqlayout conf.angle
(not
conf.proportional
);
2236 TEdone
("proportional display " ^
btos conf.proportional
)
2239 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2240 TEdone
("trim margins " ^
btos conf.trimmargins
)
2243 conf.invert
<- not
conf.invert
;
2244 TEdone
("invert colors " ^
btos conf.invert
)
2247 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2251 class type lvsource
= object
2252 method getitemcount
: int
2253 method getitem
: int -> (string * int)
2254 method hasaction
: int -> bool
2263 method getactive
: int
2264 method getfirst
: int
2265 method getqsearch
: string
2266 method setqsearch
: string -> unit
2270 class virtual lvsourcebase
= object
2271 val mutable m_active
= 0
2272 val mutable m_first
= 0
2273 val mutable m_qsearch
= ""
2274 val mutable m_pan
= 0
2275 method getactive
= m_active
2276 method getfirst
= m_first
2277 method getqsearch
= m_qsearch
2278 method getpan
= m_pan
2279 method setqsearch
s = m_qsearch
<- s
2282 let textentryspecial key = function
2283 | ((c, _
, (Some
(action, _
) as onhist), onkey
, ondone), mode
) ->
2286 | Glut.KEY_UP
-> action HCprev
2287 | Glut.KEY_DOWN
-> action HCnext
2288 | Glut.KEY_HOME
-> action HCfirst
2289 | Glut.KEY_END
-> action HClast
2292 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2293 G.postRedisplay "special textentry";
2297 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2299 state.mode
<- Textentry
(te
, onleave
);
2302 G.postRedisplay "textentrykeyboard enttext";
2304 match Char.unsafe_chr
key with
2305 | '
\008'
-> (* backspace *)
2306 let len = String.length
text in
2310 G.postRedisplay "textentrykeyboard after cancel";
2313 let s = String.sub
text 0 (len - 1) in
2314 enttext (c, s, opthist
, onkey
, ondone)
2320 G.postRedisplay "textentrykeyboard after confirm"
2322 | '
\007'
(* ctrl-g *)
2323 | '
\027'
-> (* escape *)
2324 if String.length
text = 0
2326 begin match opthist
with
2328 | Some
(_
, onhistcancel
) -> onhistcancel
()
2332 G.postRedisplay "textentrykeyboard after cancel2"
2335 enttext (c, "", opthist
, onkey
, ondone)
2338 | '
\127'
-> () (* delete *)
2341 begin match onkey
text key with
2345 G.postRedisplay "textentrykeyboard after confirm2";
2348 enttext (c, text, opthist
, onkey
, ondone);
2352 G.postRedisplay "textentrykeyboard after cancel3"
2355 state.mode
<- Textentry
(te
, onleave
);
2356 G.postRedisplay "textentrykeyboard switch";
2360 let firstof first active
=
2361 if first
> active
|| abs
(first
- active
) > fstate.maxrows
- 1
2362 then max
0 (active
- (fstate.maxrows
/2))
2366 let calcfirst first active
=
2369 let rows = active
- first
in
2370 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2374 let scrollph y maxy =
2375 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2376 let sh = float conf.winh
/. sh in
2377 let sh = max
sh (float conf.scrollh
) in
2382 else float y /. float maxy
2384 let position = (float conf.winh
-. sh) *. percent in
2387 if position +. sh > float conf.winh
2388 then float conf.winh
-. sh
2394 let coe s = (s :> uioh
);;
2396 class listview ~
(source
:lvsource
) ~trusted
=
2398 val m_pan
= source#getpan
2399 val m_first
= source#getfirst
2400 val m_active
= source#getactive
2401 val m_qsearch
= source#getqsearch
2402 val m_prev_uioh
= state.uioh
2404 method private elemunder
y =
2405 let n = y / (fstate.fontsize
+1) in
2406 if m_first
+ n < source#getitemcount
2408 if source#hasaction
(m_first
+ n)
2409 then Some
(m_first
+ n)
2416 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2417 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2418 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2419 GlDraw.color
(1., 1., 1.);
2420 Gl.enable `texture_2d
;
2421 let fs = fstate.fontsize
in
2423 let ww = fstate.wwidth
in
2424 let tabw = 30.0*.ww in
2425 let itemcount = source#getitemcount
in
2427 if (row - m_first
) * nfs > conf.winh
2430 if row >= 0 && row < itemcount
2432 let (s, level
) = source#getitem
row in
2433 let y = (row - m_first
) * nfs in
2434 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2437 Gl.disable `texture_2d
;
2438 GlDraw.polygon_mode `both `line
;
2439 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2440 GlDraw.rect (1., float (y + 1))
2441 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2442 GlDraw.polygon_mode `both `fill
;
2443 GlDraw.color
(1., 1., 1.);
2444 Gl.enable `texture_2d
;
2447 let drawtabularstring s =
2448 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2451 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2454 let len = String.length
s - tabpos - 1 in
2455 let s1 = String.sub
s 0 tabpos
2456 and s2
= String.sub
s (tabpos + 1) len in
2457 let nx = drawstr x s1 in
2459 let x = x +. (max
tabw sw) in
2466 let _ = drawtabularstring s in
2473 Gl.disable `texture_2d
;
2475 method updownlevel incr
=
2476 let len = source#getitemcount
in
2477 let _, curlevel
= source#getitem m_active
in
2479 if i
= len then i
-1 else if i
= -1 then 0 else
2480 let _, l = source#getitem i
in
2481 if l != curlevel
then i
else flow (i
+incr
)
2483 let active = flow m_active
in
2484 let first = calcfirst m_first
active in
2485 G.postRedisplay "special outline updownlevel";
2486 {< m_active
= active; m_first
= first >}
2488 method private key1
key =
2489 let set active first qsearch
=
2490 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2492 let search active pattern incr
=
2495 if n >= 0 && n < source#getitemcount
2497 let s, _ = source#getitem
n in
2499 (try ignore
(Str.search_forward
re s 0); true
2500 with Not_found
-> false)
2502 else loop (n + incr
)
2509 let re = Str.regexp_case_fold pattern
in
2516 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2517 let incr = if key = 18 then -1 else 1 in
2519 match search (m_active
+ incr) m_qsearch
incr with
2521 state.text <- m_qsearch ^
" [not found]";
2524 state.text <- m_qsearch
;
2525 active, firstof m_first
active
2527 G.postRedisplay "listview ctrl-r/s";
2528 set active first m_qsearch
;
2530 | 8 -> (* backspace *)
2531 let len = String.length m_qsearch
in
2538 G.postRedisplay "listview empty qsearch";
2539 set m_active m_first
"";
2542 let qsearch = String.sub m_qsearch
0 (len - 1) in
2544 match search m_active
qsearch ~
-1 with
2546 state.text <- qsearch ^
" [not found]";
2549 state.text <- qsearch;
2550 active, firstof m_first
active
2552 G.postRedisplay "listview backspace qsearch";
2553 set active first qsearch
2556 | _ when key >= 32 && key < 127 ->
2557 let pattern = addchar m_qsearch
(Char.chr
key) in
2559 match search m_active
pattern 1 with
2561 state.text <- pattern ^
" [not found]";
2564 state.text <- pattern;
2565 active, firstof m_first
active
2567 G.postRedisplay "listview qsearch add";
2568 set active first pattern;
2570 | 27 -> (* escape *)
2572 if String.length m_qsearch
= 0
2574 G.postRedisplay "list view escape";
2577 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2579 | None
-> m_prev_uioh
2584 G.postRedisplay "list view kill qsearch";
2585 source#setqsearch
"";
2586 coe {< m_qsearch
= "" >}
2591 let self = {< m_qsearch
= "" >} in
2592 source#setqsearch
"";
2594 G.postRedisplay "listview enter";
2595 if m_active
>= 0 && m_active
< source#getitemcount
2597 source#exit
(coe self) false m_active m_first m_pan
"";
2600 source#exit
(coe self) true m_active m_first m_pan
"";
2603 begin match opt with
2604 | None
-> m_prev_uioh
2608 | 127 -> (* delete *)
2611 | _ -> dolog "unknown key %d" key; coe self
2613 method private special1
key =
2614 let itemcount = source#getitemcount
in
2615 let find start
incr =
2617 if i
= -1 || i
= itemcount
2620 if source#hasaction i
2622 else find (i
+ incr)
2627 let set active first =
2628 let first = bound first 0 (itemcount - fstate.maxrows
) in
2630 coe {< m_active
= active; m_first
= first >}
2633 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2635 let incr1 = if incr > 0 then 1 else -1 in
2636 if isvisible m_first m_active
2639 let next = m_active
+ incr in
2641 if next < 0 || next >= itemcount
2643 else find next incr1
2645 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2651 let first = m_first
+ incr in
2652 let first = bound first 0 (itemcount - 1) in
2654 let next = m_active
+ incr in
2655 let next = bound next 0 (itemcount - 1) in
2658 let active = if next = -1 then m_active
else next in
2661 let first = min
next m_first
in
2663 if abs
(next - first) > fstate.maxrows
2669 let first = m_first
+ incr in
2670 let first = bound first 0 (itemcount - 1) in
2672 let next = m_active
+ incr in
2673 let next = bound next 0 (itemcount - 1) in
2674 let next = find next incr1 in
2676 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2678 let active = if m_active
= -1 then next else m_active
in
2683 if isvisible first active
2689 G.postRedisplay "listview navigate";
2692 begin match key with
2693 | Glut.KEY_UP
-> navigate ~
-1
2694 | Glut.KEY_DOWN
-> navigate 1
2695 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2696 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2700 G.postRedisplay "listview right";
2701 coe {< m_pan
= m_pan
- 1 >}
2705 G.postRedisplay "listview left";
2706 coe {< m_pan
= m_pan
+ 1 >}
2709 let active = find 0 1 in
2710 G.postRedisplay "listview home";
2714 let first = max
0 (itemcount - fstate.maxrows
) in
2715 let active = find (itemcount - 1) ~
-1 in
2716 G.postRedisplay "listview end";
2723 match state.mode
with
2724 | Textentry te
-> textentrykeyboard key te
; coe self
2725 | _ -> self#key1
key
2727 method special
key =
2728 match state.mode
with
2729 | Textentry te
-> textentryspecial key te
; coe self
2730 | _ -> self#special1
key
2732 method button button bstate
x y =
2735 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollbw
->
2736 G.postRedisplay "listview scroll";
2737 if bstate
= Glut.DOWN
2739 let _, position, sh = self#
scrollph in
2740 if y > truncate
position && y < truncate
(position +. sh)
2742 state.mstate
<- Mscrolly
;
2746 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2747 let first = truncate
(s *. float source#getitemcount
) in
2748 let first = min source#getitemcount
first in
2749 Some
(coe {< m_first
= first; m_active
= first >})
2751 state.mstate
<- Mnone
;
2754 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2755 begin match self#elemunder
y with
2757 G.postRedisplay "listview click";
2759 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
2763 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2764 let len = source#getitemcount
in
2766 if n = 4 && m_first
+ fstate.maxrows
>= len
2770 let first = m_first
+ (if n == 3 then -1 else 1) in
2771 bound first 0 (len - 1)
2773 G.postRedisplay "listview wheel";
2774 Some
(coe {< m_first
= first >})
2779 | None
-> m_prev_uioh
2783 match state.mstate
with
2785 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2786 let first = truncate
(s *. float source#getitemcount
) in
2787 let first = min source#getitemcount
first in
2788 G.postRedisplay "listview motion";
2789 coe {< m_first
= first; m_active
= first >}
2792 method pmotion
x y =
2793 if x < conf.winw
- conf.scrollbw
2796 match self#elemunder
y with
2797 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
2798 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
2802 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
2807 Glut.setCursor
Glut.CURSOR_INHERIT
;
2811 method infochanged
_ = ()
2813 method scrollpw
= (0, 0.0, 0.0)
2815 let nfs = fstate.fontsize
+ 1 in
2816 let y = m_first
* nfs in
2817 let itemcount = source#getitemcount
in
2818 let maxi = max
0 (itemcount - fstate.maxrows
) in
2819 let maxy = maxi * nfs in
2820 let p, h = scrollph y maxy in
2824 class outlinelistview ~source
=
2826 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
2830 | 14 -> (* ctrl-n *)
2831 source#narrow m_qsearch
;
2832 G.postRedisplay "outline ctrl-n";
2833 coe {< m_first
= 0; m_active
= 0 >}
2835 | 21 -> (* ctrl-u *)
2837 G.postRedisplay "outline ctrl-u";
2839 coe {< m_first
= 0; m_active
= 0 >}
2841 | 12 -> (* ctrl-l *)
2842 let first = m_active
- (fstate.maxrows
/ 2) in
2843 G.postRedisplay "outline ctrl-l";
2844 coe {< m_first
= first >}
2846 | 127 -> (* delete *)
2847 source#remove m_active
;
2848 G.postRedisplay "outline delete";
2849 let active = max
0 (m_active
-1) in
2850 coe {< m_first
= firstof m_first
active;
2851 m_active
= active >}
2853 | key -> super#
key key
2855 method special
key =
2856 let calcfirst first active =
2859 let rows = active - first in
2860 if rows > fstate.maxrows
then active - fstate.maxrows
else first
2864 let active = m_active
+ incr in
2865 let active = bound active 0 (source#getitemcount
- 1) in
2866 let first = calcfirst m_first
active in
2867 G.postRedisplay "special outline navigate";
2868 coe {< m_active
= active; m_first
= first >}
2871 | Glut.KEY_UP
-> navigate ~
-1
2872 | Glut.KEY_DOWN
-> navigate 1
2873 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2874 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2878 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2880 G.postRedisplay "special outline right";
2881 {< m_pan
= m_pan
+ 1 >}
2883 else self#updownlevel
1
2889 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2891 G.postRedisplay "special outline left";
2892 {< m_pan
= m_pan
- 1 >}
2894 else self#updownlevel ~
-1
2899 G.postRedisplay "special outline home";
2900 coe {< m_first
= 0; m_active
= 0 >}
2903 let active = source#getitemcount
- 1 in
2904 let first = max
0 (active - fstate.maxrows
) in
2905 G.postRedisplay "special outline end";
2906 coe {< m_active
= active; m_first
= first >}
2908 | _ -> super#special
key
2911 let outlinesource usebookmarks
=
2914 inherit lvsourcebase
2915 val mutable m_items
= empty
2916 val mutable m_orig_items
= empty
2917 val mutable m_prev_items
= empty
2918 val mutable m_narrow_pattern
= ""
2919 val mutable m_hadremovals
= false
2921 method getitemcount
=
2922 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
2925 if n == Array.length m_items
&& m_hadremovals
2927 ("[Confirm removal]", 0)
2929 let s, n, _ = m_items
.(n) in
2932 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
2933 ignore
(uioh
, first, pan
, qsearch);
2934 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
2936 if String.length m_narrow_pattern
= 0
2942 if not
confrimremoval
2944 let _, _, anchor = m_items
.(active) in
2949 state.bookmarks
<- Array.to_list m_items
;
2950 m_orig_items
<- m_items
;
2953 else m_items
<- items;
2956 method hasaction
_ = true
2959 if Array.length m_items
!= Array.length m_orig_items
2960 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
2963 method narrow
pattern =
2964 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
2968 let rec loop accu n =
2971 m_narrow_pattern
<- pattern;
2972 m_items
<- Array.of_list
accu
2975 let (s, _, _) as o = m_items
.(n) in
2977 if (try ignore
(Str.search_forward
re s 0); true
2978 with Not_found
-> false)
2984 loop [] (Array.length m_items
- 1)
2989 then Array.of_list
state.bookmarks
2992 m_items
<- m_orig_items
2997 if m
>= 0 && m
< Array.length m_items
2999 m_hadremovals
<- true;
3000 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3001 let n = if n >= m
then n+1 else n in
3006 method reset
anchor items =
3007 m_hadremovals
<- false;
3008 if m_orig_items
== empty || m_prev_items
!= items
3010 m_orig_items
<- items;
3011 if String.length m_narrow_pattern
= 0
3012 then m_items
<- items;
3014 m_prev_items
<- items;
3015 let rely = getanchory anchor in
3017 let rec loop n best bestd
=
3018 if n = Array.length m_items
3021 let (_, _, anchor) = m_items
.(n) in
3022 let orely = getanchory anchor in
3023 let d = abs
(orely - rely) in
3026 else loop (n+1) best bestd
3031 m_first
<- firstof m_first
active
3035 let enterselector usebookmarks
=
3036 let source = outlinesource usebookmarks
in
3040 then Array.of_list
state.bookmarks
3043 if Array.length
outlines = 0
3045 showtext ' ' errmsg
;
3048 state.text <- source#greetmsg
;
3049 Glut.setCursor
Glut.CURSOR_INHERIT
;
3050 let anchor = getanchor () in
3051 source#reset
anchor outlines;
3052 state.uioh
<- coe (new outlinelistview ~
source);
3053 G.postRedisplay "enter selector";
3057 let enteroutlinemode =
3058 let f = enterselector false in
3059 fun ()-> f "Document has no outline";
3062 let enterbookmarkmode =
3063 let f = enterselector true in
3064 fun () -> f "Document has no bookmarks (yet)";
3067 let color_of_string s =
3068 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3069 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3073 let color_to_string (r, g
, b) =
3074 let r = truncate
(r *. 256.0)
3075 and g
= truncate
(g
*. 256.0)
3076 and b = truncate
(b *. 256.0) in
3077 Printf.sprintf
"%d/%d/%d" r g
b
3080 let irect_of_string s =
3081 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1
y1 -> (x0,y0
,x1
,y1))
3084 let irect_to_string (x0,y0
,x1
,y1) =
3085 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1
y1
3088 let makecheckers () =
3089 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3091 converted by Issac Trotts. July 25, 2002 *)
3092 let image_height = 64
3093 and image_width
= 64 in
3097 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3099 for i
= 0 to image_width
- 1 do
3100 for j
= 0 to image_height - 1 do
3101 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3102 (if (i
land 8 ) lxor (j
land 8) = 0
3103 then [|255;255;255|] else [|200;200;200|])
3108 let image = make_image () in
3109 let id = GlTex.gen_texture
() in
3110 GlTex.bind_texture `texture_2d
id;
3111 GlPix.store
(`unpack_alignment
1);
3112 GlTex.image2d
image;
3113 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3116 `mag_filter `nearest
;
3117 `min_filter `nearest
];
3121 let setcheckers enabled
=
3122 match state.texid
with
3124 if enabled
then state.texid
<- Some
(makecheckers ())
3129 GlTex.delete_texture texid
;
3130 state.texid
<- None
;
3134 let int_of_string_with_suffix s =
3135 let l = String.length
s in
3139 let suffix = Char.lowercase
s.[l-1] in
3141 | 'k'
-> String.sub
s 0 (l-1), 10
3142 | 'm'
-> String.sub
s 0 (l-1), 20
3143 | 'g'
-> String.sub
s 0 (l-1), 30
3147 let n = int_of_string
s1 in
3148 let m = n lsl shift
in
3150 then raise
(Failure
"value too large")
3154 let string_with_suffix_of_int n =
3162 if n land ((1 lsl 20) - 1) = 0
3165 if n land ((1 lsl 10) - 1) = 0
3172 let h = n mod 1000 in
3175 then string_of_int
h ^
s
3177 let s = Printf.sprintf
"_%03d%s" h s in
3184 let defghyllscroll = (40, 8, 32);;
3185 let ghyllscroll_of_string s =
3186 let (n, a, b) as nab
=
3189 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3191 if n <= a || n <= b || a >= b
3192 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3196 let ghyllscroll_to_string ((n, a, b) as nab
) =
3197 if nab
= defghyllscroll
3199 else Printf.sprintf
"%d,%d,%d" n a b;
3202 let describe_location () =
3204 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3206 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3207 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3211 else (100. *. (float state.y /. float maxy))
3215 Printf.sprintf
"page %d of %d [%.2f%%]"
3216 (fn+1) state.pagecount
percent
3219 "pages %d-%d of %d [%.2f%%]"
3220 (fn+1) (ln
+1) state.pagecount
percent
3224 let btos b = if b then "\xe2\x88\x9a" else "" in
3225 let showextended = ref false in
3226 let leave mode
= function
3227 | Confirm
-> state.mode
<- mode
3228 | Cancel
-> state.mode
<- mode
in
3231 val mutable m_first_time
= true
3232 val mutable m_l
= []
3233 val mutable m_a
= [||]
3234 val mutable m_prev_uioh
= nouioh
3235 val mutable m_prev_mode
= View
3237 inherit lvsourcebase
3239 method reset prev_mode prev_uioh
=
3240 m_a
<- Array.of_list
(List.rev m_l
);
3242 m_prev_mode
<- prev_mode
;
3243 m_prev_uioh
<- prev_uioh
;
3247 if n >= Array.length m_a
3251 | _, _, _, Action
_ -> m_active
<- n
3255 m_first_time
<- false;
3258 method int name get
set =
3260 (name
, `
int get
, 1, Action
(
3263 try set (int_of_string
s)
3265 state.text <- Printf.sprintf
"bad integer `%s': %s"
3266 s (Printexc.to_string exn
)
3269 let te = name ^
": ", "", None
, intentry, ondone in
3270 state.mode
<- Textentry
(te, leave m_prev_mode
);
3274 method int_with_suffix name get
set =
3276 (name
, `intws get
, 1, Action
(
3279 try set (int_of_string_with_suffix s)
3281 state.text <- Printf.sprintf
"bad integer `%s': %s"
3282 s (Printexc.to_string exn
)
3286 name ^
": ", "", None
, intentry_with_suffix, ondone
3288 state.mode
<- Textentry
(te, leave m_prev_mode
);
3292 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3294 (name
, `
bool (btos, get
), offset
, Action
(
3301 method color name get
set =
3303 (name
, `color get
, 1, Action
(
3305 let invalid = (nan
, nan
, nan
) in
3308 try color_of_string s
3310 state.text <- Printf.sprintf
"bad color `%s': %s"
3311 s (Printexc.to_string exn
);
3317 let te = name ^
": ", "", None
, textentry, ondone in
3318 state.text <- color_to_string (get
());
3319 state.mode
<- Textentry
(te, leave m_prev_mode
);
3323 method string name get
set =
3325 (name
, `
string get
, 1, Action
(
3327 let ondone s = set s in
3328 let te = name ^
": ", "", None
, textentry, ondone in
3329 state.mode
<- Textentry
(te, leave m_prev_mode
);
3333 method colorspace name get
set =
3335 (name
, `
string get
, 1, Action
(
3338 let vals = [| "rgb"; "bgr"; "gray" |] in
3340 inherit lvsourcebase
3343 m_active
<- int_of_colorspace conf.colorspace
;
3346 method getitemcount
= Array.length
vals
3347 method getitem
n = (vals.(n), 0)
3348 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3349 ignore
(uioh
, first, pan
, qsearch);
3350 if not cancel
then set active;
3352 method hasaction
_ = true
3356 coe (new listview ~
source ~trusted
:true)
3359 method caption
s offset
=
3360 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3362 method caption2
s f offset
=
3363 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3365 method getitemcount
= Array.length m_a
3368 let tostr = function
3369 | `
int f -> string_of_int
(f ())
3370 | `intws
f -> string_with_suffix_of_int (f ())
3372 | `color
f -> color_to_string (f ())
3373 | `
bool (btos, f) -> btos (f ())
3376 let name, t
, offset
, _ = m_a
.(n) in
3377 ((let s = tostr t
in
3378 if String.length
s > 0
3379 then Printf.sprintf
"%s\t%s" name s
3383 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3387 m_qsearch
<- qsearch;
3389 match m_a
.(active) with
3390 | _, _, _, Action
f -> f uioh
3402 method hasaction
n =
3404 | _, _, _, Action
_ -> true
3408 let rec fillsrc prevmode prevuioh
=
3409 let sep () = src#caption
"" 0 in
3410 let colorp name get
set =
3412 (fun () -> color_to_string (get
()))
3415 let c = color_of_string v in
3418 state.text <- Printf.sprintf
"bad color `%s': %s"
3419 v (Printexc.to_string exn
);
3422 let oldmode = state.mode
in
3423 let birdseye = isbirdseye state.mode
in
3425 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3427 src#
bool "presentation mode"
3428 (fun () -> conf.presentation)
3430 conf.presentation <- v;
3431 state.anchor <- getanchor ();
3434 src#
bool "ignore case in searches"
3435 (fun () -> conf.icase
)
3436 (fun v -> conf.icase
<- v);
3439 (fun () -> conf.preload)
3440 (fun v -> conf.preload <- v);
3442 src#
bool "highlight links"
3443 (fun () -> conf.hlinks
)
3444 (fun v -> conf.hlinks
<- v);
3446 src#
bool "under info"
3447 (fun () -> conf.underinfo
)
3448 (fun v -> conf.underinfo
<- v);
3450 src#
bool "persistent bookmarks"
3451 (fun () -> conf.savebmarks
)
3452 (fun v -> conf.savebmarks
<- v);
3454 src#
bool "proportional display"
3455 (fun () -> conf.proportional
)
3456 (fun v -> reqlayout conf.angle
v);
3458 src#
bool "trim margins"
3459 (fun () -> conf.trimmargins
)
3460 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3462 src#
bool "persistent location"
3463 (fun () -> conf.jumpback
)
3464 (fun v -> conf.jumpback
<- v);
3467 src#
int "vertical margin"
3468 (fun () -> conf.interpagespace)
3470 conf.interpagespace <- n;
3472 match state.layout with
3477 state.maxy <- calcheight ();
3478 let y = getpagey pageno in
3483 (fun () -> conf.pagebias
)
3484 (fun v -> conf.pagebias
<- v);
3486 src#
int "scroll step"
3487 (fun () -> conf.scrollstep
)
3488 (fun n -> conf.scrollstep
<- n);
3490 src#
int "auto scroll step"
3492 match state.autoscroll
with
3494 | _ -> conf.autoscrollstep
)
3496 if state.autoscroll
<> None
3497 then state.autoscroll
<- Some
n;
3498 conf.autoscrollstep
<- n);
3501 (fun () -> truncate
(conf.zoom *. 100.))
3502 (fun v -> setzoom ((float v) /. 100.));
3505 (fun () -> conf.angle
)
3506 (fun v -> reqlayout v conf.proportional
);
3508 src#
int "scroll bar width"
3509 (fun () -> state.scrollw
)
3513 reshape conf.winw
conf.winh
;
3516 src#
int "scroll handle height"
3517 (fun () -> conf.scrollh
)
3518 (fun v -> conf.scrollh
<- v;);
3520 src#
int "thumbnail width"
3521 (fun () -> conf.thumbw
)
3523 conf.thumbw
<- min
4096 v;
3526 leavebirdseye beye
false;
3532 src#caption
"Presentation mode" 0;
3533 src#
bool "scrollbar visible"
3534 (fun () -> conf.scrollbarinpm
)
3536 if v != conf.scrollbarinpm
3538 conf.scrollbarinpm
<- v;
3539 if conf.presentation
3541 state.scrollw
<- if v then conf.scrollbw
else 0;
3542 reshape conf.winw
conf.winh
;
3548 src#caption
"Pixmap cache" 0;
3549 src#int_with_suffix
"size (advisory)"
3550 (fun () -> conf.memlimit
)
3551 (fun v -> conf.memlimit
<- v);
3554 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3555 (string_with_suffix_of_int state.memused
)
3556 (Hashtbl.length
state.tilemap
)) 1;
3559 src#caption
"Layout" 0;
3560 src#caption2
"Dimension"
3562 Printf.sprintf
"%dx%d (virtual %dx%d)"
3568 src#caption2
"Position" (fun () ->
3569 Printf.sprintf
"%dx%d" state.x state.y
3572 src#caption2
"Visible" (fun () -> describe_location ()) 1
3576 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3577 "Save these parameters as global defaults at exit"
3578 (fun () -> conf.bedefault
)
3579 (fun v -> conf.bedefault
<- v)
3583 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3584 src#
bool ~offset
:0 ~
btos "Extended parameters"
3585 (fun () -> !showextended)
3586 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3590 (fun () -> conf.checkers
)
3591 (fun v -> conf.checkers
<- v; setcheckers v);
3593 (fun () -> conf.verbose
)
3594 (fun v -> conf.verbose
<- v);
3595 src#
bool "invert colors"
3596 (fun () -> conf.invert
)
3597 (fun v -> conf.invert
<- v);
3599 (fun () -> conf.maxhfit
)
3600 (fun v -> conf.maxhfit
<- v);
3601 src#
bool "redirect stderr"
3602 (fun () -> conf.redirectstderr)
3603 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3604 src#
string "uri launcher"
3605 (fun () -> conf.urilauncher
)
3606 (fun v -> conf.urilauncher
<- v);
3607 src#
string "tile size"
3608 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3611 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3612 conf.tileh
<- max
64 w;
3613 conf.tilew
<- max
64 h;
3616 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3617 v (Printexc.to_string exn
));
3618 src#
int "texture count"
3619 (fun () -> conf.texcount
)
3622 then conf.texcount
<- v
3623 else showtext '
!'
" Failed to set texture count please retry later"
3625 src#
int "slice height"
3626 (fun () -> conf.sliceheight
)
3628 conf.sliceheight
<- v;
3629 wcmd "sliceh" [`i
conf.sliceheight
];
3631 src#
int "anti-aliasing level"
3632 (fun () -> conf.aalevel
)
3634 conf.aalevel
<- bound v 0 8;
3635 state.anchor <- getanchor ();
3636 opendoc state.path
state.password
;
3638 src#
int "ui font size"
3639 (fun () -> fstate.fontsize
)
3640 (fun v -> setfontsize (bound v 5 100));
3641 colorp "background color"
3642 (fun () -> conf.bgcolor
)
3643 (fun v -> conf.bgcolor
<- v);
3644 src#
bool "crop hack"
3645 (fun () -> conf.crophack
)
3646 (fun v -> conf.crophack
<- v);
3647 src#
string "trim fuzz"
3648 (fun () -> irect_to_string conf.trimfuzz
)
3651 conf.trimfuzz
<- irect_of_string v;
3653 then settrim true conf.trimfuzz
;
3655 state.text <- Printf.sprintf
"bad irect `%s': %s"
3656 v (Printexc.to_string exn
)
3658 src#
string "throttle"
3660 match conf.maxwait
with
3661 | None
-> "show place holder if page is not ready"
3664 then "wait for page to fully render"
3666 "wait " ^ string_of_float
time
3667 ^
" seconds before showing placeholder"
3671 let f = float_of_string
v in
3673 then conf.maxwait
<- None
3674 else conf.maxwait
<- Some
f
3676 state.text <- Printf.sprintf
"bad time `%s': %s"
3677 v (Printexc.to_string exn
)
3679 src#
string "ghyll scroll"
3681 match conf.ghyllscroll
with
3683 | Some nab
-> ghyllscroll_to_string nab
3688 if String.length
v = 0
3690 else Some
(ghyllscroll_of_string v)
3692 conf.ghyllscroll
<- gs
3694 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
3695 v (Printexc.to_string exn
)
3697 src#colorspace
"color space"
3698 (fun () -> colorspace_to_string conf.colorspace
)
3700 conf.colorspace
<- colorspace_of_int v;
3707 src#caption
"Document" 0;
3708 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3709 src#caption2
"Pages"
3710 (fun () -> string_of_int
state.pagecount
) 1;
3711 src#caption2
"Dimensions"
3712 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3716 src#caption
"Trimmed margins" 0;
3717 src#caption2
"Dimensions"
3718 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3721 src#reset prevmode prevuioh
;
3725 let prevmode = state.mode
3726 and prevuioh
= state.uioh in
3727 fillsrc prevmode prevuioh
;
3728 let source = (src :> lvsource
) in
3729 state.uioh <- coe (object (self)
3730 inherit listview ~
source ~trusted
:true as super
3731 val mutable m_prevmemused
= 0
3732 method infochanged
= function
3734 if m_prevmemused
!= state.memused
3736 m_prevmemused
<- state.memused
;
3737 G.postRedisplay "memusedchanged";
3739 | Pdim
-> G.postRedisplay "pdimchanged"
3740 | Docinfo
-> fillsrc prevmode prevuioh
3742 method special
key =
3743 if Glut.getModifiers
() land Glut.active_ctrl
= 0
3746 | Glut.KEY_LEFT
-> coe (self#updownlevel ~
-1)
3747 | Glut.KEY_RIGHT
-> coe (self#updownlevel
1)
3748 | _ -> super#special
key
3749 else super#special
key
3751 G.postRedisplay "info";
3757 inherit lvsourcebase
3758 method getitemcount
= Array.length
state.help
3760 let s, n, _ = state.help
.(n) in
3763 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3767 m_qsearch
<- qsearch;
3768 match state.help
.(active) with
3769 | _, _, Action
f -> Some
(f uioh)
3779 method hasaction
n =
3780 match state.help
.(n) with
3781 | _, _, Action
_ -> true
3788 state.uioh <- coe (new listview ~
source ~trusted
:true);
3789 G.postRedisplay "help";
3794 let re = Str.regexp
"[\r\n]" in
3796 inherit lvsourcebase
3797 val mutable m_items
= [||]
3799 method getitemcount
= 1 + Array.length m_items
3804 else m_items
.(n-1), 0
3806 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3811 then Buffer.clear
state.errmsgs
;
3812 m_qsearch
<- qsearch;
3819 method hasaction
n =
3823 state.newerrmsgs
<- false;
3824 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
3825 m_items
<- Array.of_list
l
3833 let source = (msgsource :> lvsource
) in
3834 state.uioh <- coe (object
3835 inherit listview ~
source ~trusted
:false as super
3838 then msgsource#reset
;
3841 G.postRedisplay "msgs";
3844 let quickbookmark ?title
() =
3845 match state.layout with
3851 let sec = Unix.gettimeofday
() in
3852 let tm = Unix.localtime
sec in
3853 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
3857 (tm.Unix.tm_year
+ 1900)
3860 | Some
title -> title
3863 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
3868 state.fullscreen
<- None
;
3869 Glut.reshapeWindow
w h;
3872 let viewkeyboard key =
3874 let mode = state.mode in
3875 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
3878 G.postRedisplay "view:enttext"
3880 let c = Char.chr
key in
3882 | '
\027'
| 'q'
-> (* escape *)
3883 begin match state.mstate
with
3885 state.mstate
<- Mnone
;
3886 Glut.setCursor
Glut.CURSOR_INHERIT
;
3887 G.postRedisplay "kill zoom rect";
3892 | '
\008'
-> (* backspace *)
3893 let y = getnav ~
-1 in
3894 gotoy_and_clear_text y
3902 G.postRedisplay "dehighlight";
3905 let ondone isforw
s =
3906 cbput state.hists
.pat
s;
3907 state.searchpattern
<- s;
3910 let s = String.create
1 in
3912 enttext (s, "", Some
(onhist state.hists
.pat
),
3913 textentry, ondone (c ='
/'
))
3915 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3916 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3917 setzoom (conf.zoom +. incr)
3922 try int_of_string
s with exc
->
3923 state.text <- Printf.sprintf
"bad integer `%s': %s"
3924 s (Printexc.to_string exc
);
3930 state.text <- "page bias is now " ^ string_of_int
n;
3933 enttext ("page bias: ", "", None
, intentry, ondone)
3935 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3936 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3937 setzoom (max
0.01 (conf.zoom -. decr))
3940 let ondone msg
= state.text <- msg
in
3942 "option [acfhilpstvAPRSZTI]: ", "", None
,
3943 optentry state.mode, ondone
3946 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3949 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3950 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
3954 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3960 try int_of_string
s with exc
->
3961 state.text <- Printf.sprintf
"bad integer `%s': %s"
3962 s (Printexc.to_string exc
);
3968 cbput state.hists
.pag
(string_of_int
n);
3969 gotopage1 (n + conf.pagebias
- 1) 0;
3972 let pageentry text key =
3973 match Char.unsafe_chr
key with
3974 | 'g'
-> TEdone
text
3975 | _ -> intentry text key
3977 let text = "x" in text.[0] <- c;
3978 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
3981 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
3982 reshape conf.winw
conf.winh
;
3985 conf.hlinks
<- not
conf.hlinks
;
3986 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
3987 G.postRedisplay "toggle highlightlinks";
3990 begin match state.autoscroll
with
3992 conf.autoscrollstep
<- step
;
3993 state.autoscroll
<- None
3995 if conf.autoscrollstep
= 0
3996 then state.autoscroll
<- Some
1
3997 else state.autoscroll
<- Some
conf.autoscrollstep
4001 conf.presentation <- not
conf.presentation;
4002 if conf.presentation
4004 if not
conf.scrollbarinpm
4005 then state.scrollw
<- 0;
4008 state.scrollw
<- conf.scrollbw
;
4010 showtext ' '
("presentation mode " ^
4011 if conf.presentation then "on" else "off");
4012 state.anchor <- getanchor ();
4016 begin match state.fullscreen
with
4018 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4021 state.fullscreen
<- None
;
4026 gotoy_and_clear_text 0
4029 gotopage1 (state.pagecount
- 1) 0
4032 search state.searchpattern
true
4035 search state.searchpattern
false
4038 begin match state.layout with
4041 gotoy_and_clear_text (getpagey l.pageno)
4045 begin match List.rev
state.layout with
4048 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4049 gotoy_and_clear_text (getpagey pageno)
4052 | '
\127'
-> (* del *)
4053 begin match state.layout with
4056 let pageno = max
0 (l.pageno-1) in
4057 gotoy_and_clear_text (getpagey pageno)
4061 showtext ' '
(describe_location ());
4064 begin match state.layout with
4067 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4072 enterbookmarkmode ()
4080 | '
e'
when conf.redirectstderr ->
4085 match state.layout with
4088 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4092 enttext ("bookmark: ", "", None
, textentry, ondone)
4096 showtext ' '
"Quick bookmark added";
4099 begin match state.layout with
4101 let rect = getpdimrect
l.pagedimno
in
4105 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4106 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4108 (truncate
(rect.(1) -. rect.(0)),
4109 truncate
(rect.(3) -. rect.(0)))
4111 let w = truncate
((float w)*.conf.zoom)
4112 and h = truncate
((float h)*.conf.zoom) in
4115 state.anchor <- getanchor ();
4116 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4118 G.postRedisplay "z";
4123 | '
\000'
-> (* ctrl-2 *)
4124 let maxw = getmaxw
() in
4126 then setzoom (maxw /. float conf.winw
)
4129 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
4133 bound (conf.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
4135 G.postRedisplay "brightness";
4138 begin match state.mode with
4139 | Birdseye beye
-> upbirdseye beye
4140 | _ -> gotoy (clamp (-conf.scrollstep
))
4144 begin match state.mode with
4145 | Birdseye beye
-> downbirdseye beye
4146 | _ -> gotoy (clamp conf.scrollstep
)
4150 state.anchor <- getanchor ();
4151 opendoc state.path
state.password
4153 | '
v'
when conf.debug
->
4156 match getopaque l.pageno with
4159 let x0, y0
, x1
, y1 = pagebbox opaque
in
4160 let a,b = float x0, float y0
in
4161 let c,d = float x1
, float y0
in
4162 let e,f = float x1
, float y1 in
4163 let h,j
= float x0, float y1 in
4164 let rect = (a,b,c,d,e,f,h,j
) in
4166 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4168 G.postRedisplay "v";
4171 vlog "huh? %d %c" key (Char.chr
key);
4174 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
4176 | 27 -> (* escape *)
4177 leavebirdseye beye
true
4179 | 12 -> (* ctrl-l *)
4180 let y, h = getpageyh pageno in
4181 let top = (conf.winh
- h) / 2 in
4182 gotoy (max
0 (y - top))
4185 leavebirdseye beye
false
4191 let keyboard ~
key ~
x ~
y =
4194 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
4195 then wcmd "interrupt" []
4196 else state.uioh <- state.uioh#
key key
4199 let birdseyespecial key ((conf, leftx
, _, hooverpageno
, anchor) as beye
) =
4201 | Glut.KEY_UP
-> upbirdseye beye
4202 | Glut.KEY_DOWN
-> downbirdseye beye
4204 | Glut.KEY_PAGE_UP
->
4205 begin match state.layout with
4209 state.mode <- Birdseye
(
4210 conf, leftx
, l.pageno, hooverpageno
, anchor
4212 gotopage1 l.pageno 0;
4215 let layout = layout (state.y-conf.winh
) conf.winh
in
4217 | [] -> gotoy (clamp (-conf.winh
))
4219 state.mode <- Birdseye
(
4220 conf, leftx
, l.pageno, hooverpageno
, anchor
4222 gotopage1 l.pageno 0
4225 | [] -> gotoy (clamp (-conf.winh
))
4228 | Glut.KEY_PAGE_DOWN
->
4229 begin match List.rev
state.layout with
4231 let layout = layout (state.y + conf.winh
) conf.winh
in
4232 begin match layout with
4234 let incr = l.pageh
- l.pagevh in
4239 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4241 G.postRedisplay "birdseye pagedown";
4243 else gotoy (clamp (incr + conf.interpagespace*2));
4247 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
4248 gotopage1 l.pageno 0;
4251 | [] -> gotoy (clamp conf.winh
)
4255 state.mode <- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
4259 let pageno = state.pagecount
- 1 in
4260 state.mode <- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
4261 if not
(pagevisible state.layout pageno)
4264 match List.rev
state.pdims
with
4266 | (_, _, h, _) :: _ -> h
4268 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4269 else G.postRedisplay "birdseye end";
4273 let setautoscrollspeed step goingdown
=
4274 let incr = max
1 ((abs step
) / 2) in
4275 let incr = if goingdown
then incr else -incr in
4276 let astep = step
+ incr in
4277 state.autoscroll
<- Some
astep;
4280 let special ~
key ~
x ~
y =
4283 state.uioh <- state.uioh#
special key
4288 match state.mode with
4289 | Textentry
_ -> scalecolor 0.4
4290 | View
-> scalecolor 1.0
4291 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4292 if l.pageno = hooverpageno
4295 if l.pageno = pageno
4301 begin match getopaque l.pageno with
4303 if tileready l l.pagex l.pagey
4305 let x = l.pagedispx
- l.pagex
4306 and y = l.pagedispy
- l.pagey in
4307 postprocess opaque
conf.hlinks
x y;
4313 let scrollindicator () =
4314 let sbw, ph
, sh = state.uioh#
scrollph in
4315 let sbh, pw
, sw = state.uioh#scrollpw
in
4317 GlDraw.color (0.64, 0.64, 0.64);
4319 (float (conf.winw
- sbw), 0.)
4320 (float conf.winw
, float conf.winh
)
4323 (0., float (conf.winh
- sbh))
4324 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4326 GlDraw.color (0.0, 0.0, 0.0);
4329 (float (conf.winw
- sbw), ph
)
4330 (float conf.winw
, ph
+. sh)
4333 (pw
, float (conf.winh
- sbh))
4334 (pw
+. sw, float conf.winh
)
4338 let pagetranslatepoint l x y =
4339 let dy = y - l.pagedispy
in
4340 let y = dy + l.pagey in
4341 let dx = x - l.pagedispx
in
4342 let x = dx + l.pagex in
4347 match state.mstate
with
4348 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4351 | Msel
((x0, y0
), (x1
, y1)) ->
4352 let rec loop = function
4354 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
4355 || ((y1 >= l.pagedispy
&& y1 <= (l.pagedispy
+ l.pagevh)))
4357 match getopaque l.pageno with
4359 let dx, dy = pagetranslatepoint l 0 0 in
4364 GlMat.mode `modelview
;
4366 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4367 seltext opaque
(x0, y0
, x1
, y1);
4378 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4379 GlDraw.polygon_mode `both `fill
;
4380 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4382 (fun (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) ->
4384 if l.pageno = pageno
4386 let dx = float (l.pagedispx
- l.pagex) in
4387 let dy = float (l.pagedispy
- l.pagey) in
4388 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4389 GlDraw.begins `quads
;
4391 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4392 GlDraw.vertex2
(x1
+.dx, y1+.dy);
4393 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4394 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4405 GlClear.color (scalecolor2 conf.bgcolor
);
4406 GlClear.clear
[`
color];
4407 List.iter
drawpage state.layout;
4412 begin match state.mstate
with
4413 | Mzoomrect
((x0, y0
), (x1
, y1)) ->
4415 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4416 GlDraw.polygon_mode `both `fill
;
4417 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4418 GlDraw.rect (float x0, float y0
)
4419 (float x1
, float y1);
4424 Glut.swapBuffers
();
4428 let rec f = function
4430 begin match getopaque l.pageno with
4432 let x0 = l.pagedispx
in
4433 let x1 = x0 + l.pagevw in
4434 let y0 = l.pagedispy
in
4435 let y1 = y0 + l.pagevh in
4436 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4438 let px, py = pagetranslatepoint l x y in
4439 match whatsunder opaque
px py with
4451 let zoomrect x y x1 y1 =
4454 and y0 = min
y y1 in
4455 gotoy (state.y + y0);
4456 state.anchor <- getanchor ();
4457 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4459 if state.w < conf.winw
- state.scrollw
4460 then (conf.winw
- state.scrollw
- state.w) / 2
4463 state.x <- (state.x + margin) - x0;
4465 Glut.setCursor
Glut.CURSOR_INHERIT
;
4466 state.mstate
<- Mnone
;
4470 let winw = conf.winw - state.scrollw
- 1 in
4471 let s = float x /. float winw in
4472 let destx = truncate
(float (state.w + winw) *. s) in
4473 state.x <- winw - destx;
4474 gotoy_and_clear_text state.y;
4475 state.mstate
<- Mscrollx
;
4479 let s = float y /. float conf.winh
in
4480 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4481 gotoy_and_clear_text desty;
4482 state.mstate
<- Mscrolly
;
4485 let viewmouse button bstate
x y =
4487 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4488 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4490 match state.mstate
with
4491 | Mzoom
(oldn
, i
) ->
4499 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4501 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4503 let zoom = conf.zoom -. incr in
4505 state.mstate
<- Mzoom
(n, 0);
4507 state.mstate
<- Mzoom
(n, i
+1);
4509 else state.mstate
<- Mzoom
(n, 0)
4511 | _ -> state.mstate
<- Mzoom
(n, 0)
4514 match state.autoscroll
with
4515 | Some step
-> setautoscrollspeed step
(n=4)
4519 then -conf.scrollstep
4520 else conf.scrollstep
4522 let incr = incr * 2 in
4523 let y = clamp incr in
4524 gotoy_and_clear_text y
4527 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4528 if bstate
= Glut.DOWN
4530 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4531 state.mstate
<- Mpan
(x, y)
4534 state.mstate
<- Mnone
4536 | Glut.RIGHT_BUTTON
->
4537 if bstate
= Glut.DOWN
4539 Glut.setCursor
Glut.CURSOR_CYCLE
;
4541 state.mstate
<- Mzoomrect
(p, p)
4544 match state.mstate
with
4545 | Mzoomrect
((x0, y0), _) ->
4546 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4547 then zoomrect x0 y0 x y
4549 state.mstate
<- Mnone
;
4550 Glut.setCursor
Glut.CURSOR_INHERIT
;
4551 G.postRedisplay "kill accidental zoom rect";
4554 Glut.setCursor
Glut.CURSOR_INHERIT
;
4555 state.mstate
<- Mnone
4558 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4559 if bstate
= Glut.DOWN
4561 let _, position, sh = state.uioh#
scrollph in
4562 if y > truncate
position && y < truncate
(position +. sh)
4563 then state.mstate
<- Mscrolly
4566 state.mstate
<- Mnone
4568 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4569 if bstate
= Glut.DOWN
4571 let _, position, sw = state.uioh#scrollpw
in
4572 if x > truncate
position && x < truncate
(position +. sw)
4573 then state.mstate
<- Mscrollx
4576 state.mstate
<- Mnone
4578 | Glut.LEFT_BUTTON
->
4579 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4580 begin match dest with
4581 | Ulinkgoto
(pageno, top) ->
4585 gotopage1 pageno top;
4591 | Unone
when bstate
= Glut.DOWN
->
4592 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4593 state.mstate
<- Mpan
(x, y);
4595 | Unone
| Utext
_ ->
4596 if bstate
= Glut.DOWN
4598 if conf.angle
mod 360 = 0
4600 state.mstate
<- Msel
((x, y), (x, y));
4601 G.postRedisplay "mouse select";
4605 match state.mstate
with
4608 | Mzoom
_ | Mscrollx
| Mscrolly
->
4609 state.mstate
<- Mnone
4611 | Mzoomrect
((x0, y0), _) ->
4615 Glut.setCursor
Glut.CURSOR_INHERIT
;
4616 state.mstate
<- Mnone
4618 | Msel
((_, y0), (_, y1)) ->
4620 if (y0 >= l.pagedispy
&& y0 <= (l.pagedispy
+ l.pagevh))
4621 || ((y1 >= l.pagedispy
&& y1 <= (l.pagedispy
+ l.pagevh)))
4623 match getopaque l.pageno with
4628 List.iter
f state.layout;
4629 copysel
""; (* ugly *)
4630 Glut.setCursor
Glut.CURSOR_INHERIT
;
4631 state.mstate
<- Mnone
;
4638 let birdseyemouse button bstate
x y
4639 (conf, leftx
, _, hooverpageno
, anchor) =
4641 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4642 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4643 let rec loop = function
4646 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4647 && x > margin && x < margin + l.pagew
4649 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4654 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4658 let mouse bstate button
x y =
4659 state.uioh <- state.uioh#button button bstate
x y;
4662 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4665 state.uioh <- state.uioh#
motion x y
4669 state.uioh <- state.uioh#
pmotion x y;
4676 begin match state.mode with
4677 | Textentry
textentry -> textentrykeyboard key textentry
4678 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4679 | View
-> viewkeyboard key
4683 method special key =
4684 begin match state.mode with
4685 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4689 birdseyespecial key vals
4691 | View
when key = Glut.KEY_F1
->
4695 begin match state.autoscroll
with
4696 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4697 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4702 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4704 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4706 if Glut.getModifiers
() land Glut.active_shift
!= 0
4707 then (setzoom state.prevzoom
; state.y)
4708 else clamp (-conf.winh
/2)
4709 else clamp (-conf.scrollstep
)
4711 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4713 if Glut.getModifiers
() land Glut.active_shift
!= 0
4714 then (setzoom state.prevzoom
; state.y)
4715 else clamp (conf.winh
/2)
4716 else clamp (conf.scrollstep
)
4717 | Glut.KEY_PAGE_UP
->
4718 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4720 match state.layout with
4722 | l :: _ -> state.y - l.pagey
4725 | Glut.KEY_PAGE_DOWN
->
4726 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4728 match List.rev
state.layout with
4730 | l :: _ -> getpagey l.pageno
4738 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
4740 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
4741 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
4742 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
4744 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
4746 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4747 then (conf.winw / 2)
4750 state.x <- state.x - dx;
4752 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
4754 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4755 then (conf.winw / 2)
4758 state.x <- state.x + dx;
4763 if abs
(state.y - y) > conf.scrollstep
*2
4765 else gotoy_and_clear_text y
4768 | Textentry
te -> textentryspecial key te
4772 method button button bstate
x y =
4773 begin match state.mode with
4774 | View
-> viewmouse button bstate
x y
4775 | Birdseye beye
-> birdseyemouse button bstate
x y beye
4781 begin match state.mode with
4783 | View
| Birdseye
_ ->
4784 match state.mstate
with
4785 | Mzoom
_ | Mnone
-> ()
4790 state.mstate
<- Mpan
(x, y);
4791 if conf.zoom > 1.0 then state.x <- state.x + dx;
4793 gotoy_and_clear_text y
4796 state.mstate
<- Msel
(a, (x, y));
4797 G.postRedisplay "motion select";
4800 let y = min
conf.winh
(max
0 y) in
4804 let x = min
conf.winw (max
0 x) in
4807 | Mzoomrect
(p0
, _) ->
4808 state.mstate
<- Mzoomrect
(p0
, (x, y));
4809 G.postRedisplay "motion zoomrect";
4813 method pmotion x y =
4814 begin match state.mode with
4815 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
4816 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4817 let rec loop = function
4819 if hooverpageno
!= -1
4821 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
4822 G.postRedisplay "pmotion birdseye no hoover";
4825 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4826 && x > margin && x < margin + l.pagew
4828 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
4829 G.postRedisplay "pmotion birdseye hoover";
4838 match state.mstate
with
4840 begin match getunder x y with
4841 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
4843 if conf.underinfo
then showtext 'u'
("ri: " ^
uri);
4844 Glut.setCursor
Glut.CURSOR_INFO
4845 | Ulinkgoto
(page
, _) ->
4847 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
4848 Glut.setCursor
Glut.CURSOR_INFO
4850 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
4851 Glut.setCursor
Glut.CURSOR_TEXT
4854 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
4859 method infochanged
_ = ()
4862 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
4863 let p, h = scrollph state.y maxy in
4867 let winw = conf.winw - state.scrollw
- 1 in
4868 let fwinw = float winw in
4870 let sw = fwinw /. float state.w in
4871 let sw = fwinw *. sw in
4872 max
sw (float conf.scrollh
)
4875 let f = state.w+winw in
4876 let r = float (winw-state.x) /. float f in
4877 let p = fwinw *. r in
4881 if position +. sw > fwinw
4882 then fwinw -. position
4885 state.hscrollh, position, sw
4892 let fontpath = ref "";;
4893 let wmclasshack = ref false;;
4896 let l = String.length
s in
4897 let b = Buffer.create
l in
4905 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
4906 | _ -> Sys.getenv
"HOME"
4909 ("Can not determine home directory location: " ^
4910 Printexc.to_string exn
);
4914 let config_of c attrs
=
4918 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
4919 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
4920 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
4921 | "preload" -> { c with preload = bool_of_string
v }
4922 | "page-bias" -> { c with pagebias
= int_of_string
v }
4923 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
4924 | "auto-scroll-step" ->
4925 { c with autoscrollstep
= max
0 (int_of_string
v) }
4926 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
4927 | "crop-hack" -> { c with crophack
= bool_of_string
v }
4930 match String.lowercase
v with
4931 | "true" -> Some infinity
4933 | f -> Some
(float_of_string
f)
4935 { c with maxwait
= mw}
4936 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
4937 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
4938 | "vertical-margin" ->
4939 { c with interpagespace = max
0 (int_of_string
v) }
4941 let zoom = float_of_string
v /. 100. in
4942 let zoom = max
zoom 0.0 in
4943 { c with zoom = zoom }
4944 | "presentation" -> { c with presentation = bool_of_string
v }
4945 | "rotation-angle" -> { c with angle
= int_of_string
v }
4946 | "width" -> { c with winw = max
20 (int_of_string
v) }
4947 | "height" -> { c with winh
= max
20 (int_of_string
v) }
4948 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
4949 | "proportional-display" -> { c with proportional
= bool_of_string
v }
4950 | "pixmap-cache-size" ->
4951 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
4952 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
4953 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
4954 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
4955 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
4956 | "background-color" -> { c with bgcolor
= color_of_string v }
4957 | "scrollbar-in-presentation" ->
4958 { c with scrollbarinpm
= bool_of_string
v }
4959 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
4960 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
4961 | "mupdf-store-size" ->
4962 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
4963 | "checkers" -> { c with checkers
= bool_of_string
v }
4964 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
4965 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
4966 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
4967 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
4968 | "uri-launcher" -> { c with urilauncher
= unent v }
4969 | "color-space" -> { c with colorspace
= colorspace_of_string v }
4970 | "invert-colors" -> { c with invert
= bool_of_string
v }
4971 | "brightness" -> { c with colorscale
= float_of_string
v }
4972 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
4974 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
4977 prerr_endline
("Error processing attribute (`" ^
4978 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
4981 let rec fold c = function
4984 let c = apply c k
v in
4990 let fromstring f pos
n v d =
4993 dolog "Error processing attribute (%S=%S) at %d\n%s"
4994 n v pos
(Printexc.to_string exn
)
4999 let bookmark_of attrs
=
5000 let rec fold title page
rely = function
5001 | ("title", v) :: rest
-> fold v page
rely rest
5002 | ("page", v) :: rest
-> fold title v rely rest
5003 | ("rely", v) :: rest
-> fold title page
v rest
5004 | _ :: rest
-> fold title page
rely rest
5005 | [] -> title, page
, rely
5007 fold "invalid" "0" "0" attrs
5011 let rec fold path page
rely pan
= function
5012 | ("path", v) :: rest
-> fold v page
rely pan rest
5013 | ("page", v) :: rest
-> fold path
v rely pan rest
5014 | ("rely", v) :: rest
-> fold path page
v pan rest
5015 | ("pan", v) :: rest
-> fold path page
rely v rest
5016 | _ :: rest
-> fold path page
rely pan rest
5017 | [] -> path
, page
, rely, pan
5019 fold "" "0" "0" "0" attrs
5022 let setconf dst
src =
5023 dst
.scrollbw
<- src.scrollbw
;
5024 dst
.scrollh
<- src.scrollh
;
5025 dst
.icase
<- src.icase
;
5026 dst
.preload <- src.preload;
5027 dst
.pagebias
<- src.pagebias
;
5028 dst
.verbose
<- src.verbose
;
5029 dst
.scrollstep
<- src.scrollstep
;
5030 dst
.maxhfit
<- src.maxhfit
;
5031 dst
.crophack
<- src.crophack
;
5032 dst
.autoscrollstep
<- src.autoscrollstep
;
5033 dst
.maxwait
<- src.maxwait
;
5034 dst
.hlinks
<- src.hlinks
;
5035 dst
.underinfo
<- src.underinfo
;
5036 dst
.interpagespace <- src.interpagespace;
5037 dst
.zoom <- src.zoom;
5038 dst
.presentation <- src.presentation;
5039 dst
.angle
<- src.angle
;
5040 dst
.winw <- src.winw;
5041 dst
.winh
<- src.winh
;
5042 dst
.savebmarks
<- src.savebmarks
;
5043 dst
.memlimit
<- src.memlimit
;
5044 dst
.proportional
<- src.proportional
;
5045 dst
.texcount
<- src.texcount
;
5046 dst
.sliceheight
<- src.sliceheight
;
5047 dst
.thumbw
<- src.thumbw
;
5048 dst
.jumpback
<- src.jumpback
;
5049 dst
.bgcolor
<- src.bgcolor
;
5050 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5051 dst
.tilew
<- src.tilew
;
5052 dst
.tileh
<- src.tileh
;
5053 dst
.mustoresize
<- src.mustoresize
;
5054 dst
.checkers
<- src.checkers
;
5055 dst
.aalevel
<- src.aalevel
;
5056 dst
.trimmargins
<- src.trimmargins
;
5057 dst
.trimfuzz
<- src.trimfuzz
;
5058 dst
.urilauncher
<- src.urilauncher
;
5059 dst
.colorspace
<- src.colorspace
;
5060 dst
.invert
<- src.invert
;
5061 dst
.colorscale
<- src.colorscale
;
5062 dst
.redirectstderr <- src.redirectstderr;
5063 dst
.ghyllscroll
<- src.ghyllscroll
;
5067 let h = Hashtbl.create
10 in
5068 let dc = { defconf with angle
= defconf.angle
} in
5069 let rec toplevel v t spos
_ =
5071 | Vdata
| Vcdata
| Vend
-> v
5072 | Vopen
("llppconfig", _, closed
) ->
5075 else { v with f = llppconfig
}
5077 error
"unexpected subelement at top level" s spos
5078 | Vclose
_ -> error
"unexpected close at top level" s spos
5080 and llppconfig
v t spos
_ =
5082 | Vdata
| Vcdata
-> v
5083 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5084 | Vopen
("defaults", attrs
, closed
) ->
5085 let c = config_of dc attrs
in
5089 else { v with f = skip
"defaults" (fun () -> v) }
5091 | Vopen
("ui-font", attrs
, closed
) ->
5092 let rec getsize size
= function
5094 | ("size", v) :: rest
->
5096 fromstring int_of_string spos
"size" v fstate.fontsize
in
5098 | l -> getsize size l
5100 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5103 else { v with f = uifont
(Buffer.create
10) }
5105 | Vopen
("doc", attrs
, closed
) ->
5106 let pathent, spage
, srely
, span
= doc_of attrs
in
5107 let path = unent pathent
5108 and pageno = fromstring int_of_string spos
"page" spage
0
5109 and rely = fromstring float_of_string spos
"rely" srely
0.0
5110 and pan
= fromstring int_of_string spos
"pan" span
0 in
5111 let c = config_of dc attrs
in
5112 let anchor = (pageno, rely) in
5114 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5115 else { v with f = doc
path pan
anchor c [] }
5118 error
"unexpected subelement in llppconfig" s spos
5120 | Vclose
"llppconfig" -> { v with f = toplevel }
5121 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5123 and uifont
b v t spos epos
=
5126 Buffer.add_substring
b s spos
(epos
- spos
);
5128 | Vopen
(_, _, _) ->
5129 error
"unexpected subelement in ui-font" s spos
5130 | Vclose
"ui-font" ->
5131 if String.length
!fontpath = 0
5132 then fontpath := Buffer.contents
b;
5133 { v with f = llppconfig
}
5134 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5135 | Vend
-> error
"unexpected end of input in ui-font" s spos
5137 and doc
path pan
anchor c bookmarks
v t spos
_ =
5139 | Vdata
| Vcdata
-> v
5140 | Vend
-> error
"unexpected end of input in doc" s spos
5141 | Vopen
("bookmarks", _, closed
) ->
5144 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5146 | Vopen
(_, _, _) ->
5147 error
"unexpected subelement in doc" s spos
5150 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5151 { v with f = llppconfig
}
5153 | Vclose
_ -> error
"unexpected close in doc" s spos
5155 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5157 | Vdata
| Vcdata
-> v
5158 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5159 | Vopen
("item", attrs
, closed
) ->
5160 let titleent, spage
, srely
= bookmark_of attrs
in
5161 let page = fromstring int_of_string spos
"page" spage
0
5162 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5163 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5165 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5168 { v with f = skip
"item" f }
5171 error
"unexpected subelement in bookmarks" s spos
5173 | Vclose
"bookmarks" ->
5174 { v with f = doc
path pan
anchor c bookmarks }
5176 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5178 and skip tag
f v t spos
_ =
5180 | Vdata
| Vcdata
-> v
5182 error
("unexpected end of input in skipped " ^ tag
) s spos
5183 | Vopen
(tag'
, _, closed
) ->
5187 let f'
() = { v with f = skip tag
f } in
5188 { v with f = skip tag'
f'
}
5192 else error
("unexpected close in skipped " ^ tag
) s spos
5195 parse
{ f = toplevel; accu = () } s;
5201 let len = in_channel_length ic
in
5202 let s = String.create
len in
5203 really_input ic
s 0 len;
5206 | Parse_error
(msg
, s, pos
) ->
5207 let subs = subs s pos
in
5208 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5209 failwith
("parse error: " ^
s)
5212 failwith
("config load error: " ^
Printexc.to_string exn
)
5218 let dir = Filename.concat
home ".config" in
5219 if Sys.is_directory
dir then dir else home
5222 Filename.concat
dir "llpp.conf"
5225 let confpath = ref defconfpath;;
5228 if Sys.file_exists
!confpath
5231 (try Some
(open_in_bin
!confpath)
5234 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5235 Printexc.to_string exn
);
5244 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5245 Printexc.to_string exn
);
5251 f (Hashtbl.create
0, defconf)
5256 let pc, pb
, px, pa
=
5258 Hashtbl.find h (Filename.basename
state.path)
5259 with Not_found
-> dc, [], 0, (0, 0.0)
5263 state.bookmarks <- pb
;
5265 state.scrollw
<- conf.scrollbw
;
5267 then state.anchor <- pa
;
5268 cbput state.hists
.nav pa
;
5273 let add_attrs bb always
dc c =
5276 then Printf.bprintf bb
"\n %s='%b'" s a
5279 then Printf.bprintf bb
"\n %s='%d'" s a
5282 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5285 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5288 then Printf.bprintf bb
"\n %s='%f'" s a
5292 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5296 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5300 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5304 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5310 | Some
(_N
, _A
, _B
) ->
5311 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
5321 else string_of_float
f
5323 Printf.bprintf bb
"\n %s='%s'" s v
5327 then dc.winw, dc.winh
5329 match state.fullscreen
with
5331 | None
-> c.winw, c.winh
5333 let zoom, presentation, interpagespace, maxwait
=
5335 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5337 match state.mode with
5338 | Birdseye
(bc
, _, _, _, _) ->
5339 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5340 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5342 oi
"width" w dc.winw;
5343 oi
"height" h dc.winh
;
5344 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5345 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5346 ob "case-insensitive-search" c.icase
dc.icase
;
5347 ob "preload" c.preload dc.preload;
5348 oi
"page-bias" c.pagebias
dc.pagebias
;
5349 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5350 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5351 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5352 ob "crop-hack" c.crophack
dc.crophack
;
5353 oW
"throttle" maxwait
dc.maxwait
;
5354 ob "highlight-links" c.hlinks
dc.hlinks
;
5355 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5356 oi
"vertical-margin" interpagespace dc.interpagespace;
5357 oz
"zoom" zoom dc.zoom;
5358 ob "presentation" presentation dc.presentation;
5359 oi
"rotation-angle" c.angle
dc.angle
;
5360 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5361 ob "proportional-display" c.proportional
dc.proportional
;
5362 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5363 oi
"tex-count" c.texcount
dc.texcount
;
5364 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5365 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5366 ob "persistent-location" c.jumpback
dc.jumpback
;
5367 oc
"background-color" c.bgcolor
dc.bgcolor
;
5368 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5369 oi
"tile-width" c.tilew
dc.tilew
;
5370 oi
"tile-height" c.tileh
dc.tileh
;
5371 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
5372 ob "checkers" c.checkers
dc.checkers
;
5373 oi
"aalevel" c.aalevel
dc.aalevel
;
5374 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5375 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5376 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5377 oC
"color-space" c.colorspace
dc.colorspace
;
5378 ob "invert-colors" c.invert
dc.invert
;
5379 oF
"brightness" c.colorscale
dc.colorscale
;
5380 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5381 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
5383 then ob "wmclass-hack" !wmclasshack false;
5387 let uifontsize = fstate.fontsize
in
5388 let bb = Buffer.create
32768 in
5390 let dc = if conf.bedefault
then conf else dc in
5391 Buffer.add_string
bb "<llppconfig>\n";
5393 if String.length
!fontpath > 0
5395 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5401 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5404 Buffer.add_string
bb "<defaults ";
5405 add_attrs bb true dc dc;
5406 Buffer.add_string
bb "/>\n";
5408 let adddoc path pan
anchor c bookmarks =
5409 if bookmarks == [] && c = dc && anchor = emptyanchor
5412 Printf.bprintf
bb "<doc path='%s'"
5413 (enent
path 0 (String.length
path));
5415 if anchor <> emptyanchor
5417 let n, y = anchor in
5418 Printf.bprintf
bb " page='%d'" n;
5421 Printf.bprintf
bb " rely='%f'" y
5426 then Printf.bprintf
bb " pan='%d'" pan
;
5428 add_attrs bb false dc c;
5430 begin match bookmarks with
5431 | [] -> Buffer.add_string
bb "/>\n"
5433 Buffer.add_string
bb ">\n<bookmarks>\n";
5434 List.iter
(fun (title, _level
, (page, rely)) ->
5436 "<item title='%s' page='%d'"
5437 (enent
title 0 (String.length
title))
5442 Printf.bprintf
bb " rely='%f'" rely
5444 Buffer.add_string
bb "/>\n";
5446 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5452 match state.mode with
5453 | Birdseye
(_, pan, _, _, _) -> pan
5456 let basename = Filename.basename state.path in
5457 adddoc basename pan (getanchor ())
5460 match state.autoscroll
with
5462 | None
-> conf.autoscrollstep
}
5463 (if conf.savebmarks
then state.bookmarks else []);
5465 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5467 then adddoc path x y c bookmarks
5469 Buffer.add_string
bb "</llppconfig>";
5472 if Buffer.length
bb > 0
5475 let tmp = !confpath ^
".tmp" in
5476 let oc = open_out_bin
tmp in
5477 Buffer.output_buffer
oc bb;
5479 Unix.rename
tmp !confpath;
5482 ("error while saving configuration: " ^
Printexc.to_string exn
)
5489 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5490 "<password> Set password");
5492 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5493 "<path> Set path to the user interface font");
5495 ("-c", Arg.String
(fun s -> Config.confpath := s),
5496 "<path> Set path to the configuration file");
5498 ("-v", Arg.Unit
(fun () ->
5500 "%s\nconfiguration path: %s\n"
5504 exit
0), " Print version and exit");
5507 (fun s -> state.path <- s)
5508 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5510 if String.length
state.path = 0
5511 then (prerr_endline
"file name missing"; exit
1);
5515 let _ = Glut.init
Sys.argv
in
5516 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5517 let () = Glut.initWindowSize
conf.winw conf.winh
in
5518 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5520 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5521 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5522 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5527 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5529 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5530 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5531 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5532 Unix.bind
sock addr;
5534 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5535 Unix.connect
csock addr;
5536 let ssock, _ = Unix.accept
sock in
5539 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5540 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5547 let () = Glut.displayFunc
display in
5548 let () = Glut.reshapeFunc
reshape in
5549 let () = Glut.keyboardFunc
keyboard in
5550 let () = Glut.specialFunc
special in
5551 let () = Glut.idleFunc
(Some
idle) in
5552 let () = Glut.mouseFunc
mouse in
5553 let () = Glut.motionFunc
motion in
5554 let () = Glut.passiveMotionFunc
pmotion in
5556 setcheckers conf.checkers
;
5558 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5559 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
5560 !Config.wmclasshack, !Config.fontpath
5562 state.csock <- csock;
5563 state.ssock <- ssock;
5564 state.text <- "Opening " ^
state.path;
5565 setaalevel
conf.aalevel
;
5566 writeopen state.path state.password
;
5568 setfontsize fstate.fontsize
;
5576 | Glut.BadEnum
"key in special_of_int" ->
5577 showtext '
!'
" LablGlut bug: special key not recognized";
5584 | exn
when conf.redirectstderr ->
5586 Printf.sprintf
"exception %s\n%s"
5587 (Printexc.to_string exn
)
5588 (Printexc.get_backtrace
())
5591 Unix.single_write
state.stderr
s 0 (String.length
s);