4 | Ulinkgoto
of (int * int)
6 and facename
= string;;
8 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
9 let dolog2 fmt
= Printf.kprintf print_endline fmt
;;
10 let now = Unix.gettimeofday
;;
14 type params
= (angle
* proportional
* trimparams
15 * texcount
* sliceheight
* memsize
16 * colorspace
* wmclasshack
* fontpath
)
25 and proportional
= bool
26 and trimmargins
= bool
27 and interpagespace
= int
35 and wmclasshack
= bool
36 and irect
= (int * int * int * int)
37 and trimparams
= (trimmargins
* irect
)
38 and colorspace
= | Rgb
| Bgr
| Gray
41 type platform
= | Punknown
| Plinux
| Pwindows
| Posx
| Psun
42 | Pfreebsd
| Pdragonflybsd
| Popenbsd
| Pmingw
| Pcygwin
;;
44 external init
: Unix.file_descr
-> params
-> unit = "ml_init";;
45 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
46 external copysel
: string -> unit = "ml_copysel";;
47 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
48 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
49 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
50 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
51 external measurestr
: int -> string -> float = "ml_measure_string";;
52 external getmaxw
: unit -> float = "ml_getmaxw";;
53 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
54 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
55 external platform
: unit -> platform
= "ml_platform";;
56 external setaalevel
: int -> unit = "ml_setaalevel";;
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
-> string -> 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 mumemlimit
: 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
262 type anchor
= pageno
* top
;;
264 type outline
= string * int * anchor
;;
266 type rect
= float * float * float * float * float * float * float * float;;
268 type tile
= opaque
* pixmapsize
* elapsed
269 and elapsed
= float;;
270 type pagemapkey
= pageno
* gen
;;
271 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
275 let emptyanchor = (0, 0.0);;
277 type infochange
= | Memused
| Docinfo
| Pdim
;;
279 class type uioh
= object
280 method display
: unit
281 method key
: int -> uioh
282 method special
: Glut.special_key_t
-> uioh
284 Glut.button_t
-> Glut.mouse_button_state_t
-> int -> int -> uioh
285 method motion
: int -> int -> uioh
286 method pmotion
: int -> int -> uioh
287 method infochanged
: infochange
-> unit
291 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
292 | Textentry
of (textentry
* onleave
)
294 and onleave
= leavetextentrystatus
-> unit
295 and leavetextentrystatus
= | Cancel
| Confirm
296 and helpitem
= string * int * action
299 | Action
of (uioh
-> uioh
)
302 let isbirdseye = function Birdseye _
-> true | _
-> false;;
303 let istextentry = function Textentry _
-> true | _
-> false;;
307 | Loading
of (page
* gen
)
309 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
311 | Outlining
of outline list
314 let nouioh : uioh
= object (self
)
317 method special _
= self
318 method button _ _ _ _
= self
319 method motion _ _
= self
320 method pmotion _ _
= self
321 method infochanged _
= ()
325 { mutable csock
: Unix.file_descr
326 ; mutable ssock
: Unix.file_descr
327 ; mutable errfd
: Unix.file_descr
328 ; mutable stderr
: Unix.file_descr
329 ; mutable errmsgs
: Buffer.t
330 ; mutable newerrmsgs
: bool
334 ; mutable scrollw
: int
335 ; mutable hscrollh
: int
336 ; mutable anchor
: anchor
338 ; mutable layout
: page list
339 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
340 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
341 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
342 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
343 ; mutable pagecount
: int
344 ; mutable currently
: currently
345 ; mutable mstate
: mstate
346 ; mutable searchpattern
: string
347 ; mutable rects
: (pageno
* recttype
* rect
) list
348 ; mutable rects1
: (pageno
* recttype
* rect
) list
349 ; mutable text
: string
350 ; mutable fullscreen
: (width
* height
) option
351 ; mutable mode
: mode
352 ; mutable uioh
: uioh
353 ; mutable outlines
: outline array
354 ; mutable bookmarks
: outline list
355 ; mutable path
: string
356 ; mutable password
: string
357 ; mutable invalidated
: int
358 ; mutable memused
: memsize
360 ; mutable throttle
: (page list
* int * float) option
361 ; mutable autoscroll
: int option
362 ; mutable help
: helpitem array
363 ; mutable docinfo
: (int * string) list
364 ; mutable deadline
: float
365 ; mutable texid
: GlTex.texture_id
option
367 ; mutable prevzoom
: float
368 ; mutable progress
: float
371 { pat
: string circbuf
372 ; pag
: string circbuf
373 ; nav
: anchor circbuf
394 ; presentation
= false
399 ; proportional
= true
400 ; trimmargins
= false
401 ; trimfuzz
= (0,0,0,0)
402 ; memlimit
= 32 lsl 20
407 ; bgcolor
= (0.5, 0.5, 0.5)
409 ; scrollbarinpm
= true
412 ; mumemlimit
= 128 lsl 20
417 | Plinux
| Pfreebsd
| Pdragonflybsd
| Popenbsd
| Psun
-> "xdg-open \"%s\""
418 | Posx
-> "open \"%s\""
419 | Pwindows
| Pcygwin
| Pmingw
-> "iexplore \"%s\""
424 ; redirectstderr
= false
428 let conf = { defconf with angle
= defconf.angle
};;
431 { mutable fontsize
: int
432 ; mutable wwidth
: float
433 ; mutable maxrows
: int
445 fstate.fontsize
<- n
;
446 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
447 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
451 if String.length
conf.urilauncher
= 0
452 then print_endline uri
454 let re = Str.regexp
"%s" in
455 let command = Str.global_replace
re uri
conf.urilauncher
in
457 try Some
(Unix.open_process_in
command)
460 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
465 | Some ic
-> close_in ic
470 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
471 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
475 let strings = version () :: "" :: Help.keys
in
477 let r = Str.regexp
"\\(http://[^ ]+\\)" in
479 if (try Str.search_forward
r s
0 with Not_found
-> -1) >= 0
481 let uri = Str.matched_string s
in
482 (s
, 0, Action
(fun u
-> gotouri uri; u
))
483 else s
, 0, Noaction
) strings
491 ; stderr
= Unix.stderr
492 ; errmsgs
= Buffer.create
0
499 ; anchor
= emptyanchor
502 ; tilelru
= Queue.create
()
503 ; pagemap
= Hashtbl.create
10
504 ; tilemap
= Hashtbl.create
10
521 { nav
= cbnew 10 (0, 0.0)
542 Printf.kprintf prerr_endline fmt
544 Printf.kprintf ignore fmt
547 let redirectstderr () =
548 if conf.redirectstderr
550 let rfd, wfd
= Unix.pipe
() in
551 state.stderr
<- Unix.dup
Unix.stderr
;
553 Unix.dup2 wfd
Unix.stderr
;
555 state.newerrmsgs
<- false;
556 Unix.dup2
state.stderr
Unix.stderr
;
557 prerr_string
(Buffer.contents
state.errmsgs
);
559 Buffer.clear
state.errmsgs
;
565 let postRedisplay who
=
567 then prerr_endline
("redisplay for " ^ who
);
568 Glut.postRedisplay ();
573 let b = Buffer.create
(String.length s
+ 1) in
574 Buffer.add_string
b s
;
579 let colorspace_of_string s
=
580 match String.lowercase s
with
584 | _
-> failwith
"invalid colorspace"
587 let int_of_colorspace = function
593 let colorspace_of_int = function
597 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
600 let colorspace_to_string = function
606 let intentry_with_suffix text key
=
607 let c = Char.unsafe_chr key
in
608 match Char.lowercase
c with
610 let text = addchar text c in
614 let text = addchar text c in
618 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
623 let len = String.length s
in
625 let b = Buffer.create
n in
626 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
627 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
628 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
629 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
630 Buffer.add_string
b s
;
631 let s'
= Buffer.contents
b in
632 let n'
= Unix.write fd
s'
0 n in
633 if n'
!= n then failwith
"write failed";
638 let n = Unix.read fd
s 0 4 in
639 if n != 4 then failwith
"incomplete read(len)";
641 lor (Char.code
s.[0] lsl 24)
642 lor (Char.code
s.[1] lsl 16)
643 lor (Char.code
s.[2] lsl 8)
644 lor (Char.code
s.[3] lsl 0)
646 let s = String.create
len in
647 let n = Unix.read fd
s 0 len in
648 if n != len then failwith
"incomplete read(data)";
653 let b = Buffer.create
10 in
654 Buffer.add_string
b s;
655 let rec combine = function
658 Buffer.add_char
b ' '
;
661 | `
b b -> if b then "1" else "0"
663 | `i i
-> string_of_int i
664 | `f f
-> string_of_float f
665 | `I f
-> string_of_int
(truncate f
)
667 Buffer.add_string
b s;
674 let cmd = Buffer.contents
(makecmd s l
) in
675 writecmd state.csock
cmd;
681 let d = conf.winh
- h
in
688 let rec f pn ph pi fh l
=
690 | (n, _
, h
, _
) :: rest
->
691 let ips = calcips h
in
696 if isbirdseye state.mode
&& pn
= 0
701 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
706 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
710 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
713 let fh = f 0 0 0 0 state.pdims
in
717 let getpageyh pageno
=
718 let rec f pn ph pi y l
=
720 | (n, _
, h
, _
) :: rest
->
721 let ips = calcips h
in
724 let h = if n = pageno
then h else ph
in
725 if conf.presentation
&& n = pageno
727 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
729 y
+ (pageno
- pn
) * (ph
+ pi
), h
731 let y = y + (if conf.presentation
then pi
else 0) in
732 let y = y + (n - pn
) * (ph
+ pi
) in
736 y + (pageno
- pn
) * (ph
+ pi
), ph
738 f 0 0 0 0 state.pdims
741 let getpagedim pageno
=
744 | (n, _
, _
, _
) as pdim
:: rest
->
746 then (if n = pageno
then pdim
else ppdim
)
751 f (-1, -1, -1, -1) state.pdims
754 let getpageh pageno
=
755 let _, _, h, _ = getpagedim pageno
in
759 let getpagew pageno
=
760 let _, w
, _, _ = getpagedim pageno
in
764 let getpagey pageno
= fst
(getpageyh pageno
);;
767 let sh = sh - state.hscrollh
in
768 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
769 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
771 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
772 let ips = calcips h in
774 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
778 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
780 prev
, pdims
, pdimno
, 0
782 let dy = dy + yinc in
783 let py = py + yinc in
784 if pageno
= state.pagecount
|| dy >= sh
789 if py + h <= vy - yinc
791 let py = py + h + ips in
792 let dy = max
0 (py - y) in
801 let pagey = vy - py in
802 let pagevh = h - pagey in
803 let pagevh = min
(sh - dy) pagevh in
804 let off = if yinc > 0 then py - vy else 0 in
805 let py = py + h + ips in
808 if state.w
< conf.winw
- state.scrollw
809 then (conf.winw
- state.scrollw
- state.w
) / 2
812 let dispx = xoff + state.x
in
818 let lw = w
- pagex in
819 min
lw (conf.winw
- state.scrollw
)
827 ; pagey = pagey + off
829 ; pagevh = pagevh - off
831 ; pagedispy
= dy + off
834 let accu = e :: accu in
843 if state.invalidated
= 0
862 let y = state.y + incr
in
864 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
868 let getopaque pageno
=
869 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
870 with Not_found
-> None
873 let putopaque pageno opaque
=
874 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
878 let tilex = l
.pagex mod conf.tilew
in
879 let tiley = l
.pagey mod conf.tileh
in
881 let col = l
.pagex / conf.tilew
in
882 let row = l
.pagey / conf.tileh
in
885 let a = l
.pagew
- l
.pagex in
886 let b = conf.winw
- state.scrollw
in
890 let rec rowloop row y0 dispy
h =
894 let dh = conf.tileh
- y0
in
896 let rec colloop col x0
dispx w
=
900 let dw = conf.tilew
- x0
in
903 f col row dispx dispy x0 y0
dw dh;
904 colloop (col+1) 0 (dispx+dw) (w
-dw)
907 colloop col tilex l
.pagedispx
vw;
908 rowloop (row+1) 0 (dispy
+dh) (h-dh)
912 then rowloop row tiley l
.pagedispy vh
;
915 let gettileopaque l
col row =
917 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
919 try Some
(Hashtbl.find
state.tilemap
key)
920 with Not_found
-> None
923 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
924 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
925 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
928 let drawtiles l color
=
930 let f col row x
y tilex tiley w
h =
931 match gettileopaque l
col row with
932 | Some
(opaque
, _, t
) ->
933 let params = x
, y, w
, h, tilex, tiley in
937 GlFunc.blend_func `zero `one_minus_src_color
;
939 drawtile
params opaque
;
941 then Gl.disable `blend
;
944 let s = Printf.sprintf
948 let ww = fstate.wwidth
in
949 GlMisc.push_attrib
[`current
];
950 GlDraw.color
(0.0, 0.0, 0.0);
952 (float (x
-2), float (y-2))
953 (float (x
+2) +. ww, float (y + fstate.fontsize
+ 2));
954 GlDraw.color
(1.0, 1.0, 1.0);
955 drawstring fstate.fontsize x
(y + fstate.fontsize
- 1) s;
956 GlMisc.pop_attrib
();
961 let lw = conf.winw
- state.scrollw
- x
in
964 let lh = conf.winh
- y in
967 Gl.enable `texture_2d
;
968 begin match state.texid
with
970 GlTex.bind_texture `texture_2d id
;
974 and y1
= float (y+h) in
976 let tw = float w /. 64.0
977 and th
= float h /. 64.0 in
978 let tx0 = float tilex /. 64.0
979 and ty0
= float tiley /. 64.0 in
981 and ty1
= ty0
+. th
in
982 GlDraw.begins `quads
;
983 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
984 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
985 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
986 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
989 Gl.disable `texture_2d
;
991 GlDraw.color
(1.0, 1.0, 1.0);
994 (float (x
+w), float (y+h));
996 if w > 128 && h > fstate.fontsize
+ 10
998 GlDraw.color
(0.0, 0.0, 0.0);
1001 then (col*conf.tilew
, row*conf.tileh
)
1004 drawstring2 fstate.fontsize x
y "Loading %d [%d,%d]" l
.pageno
c r;
1011 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1013 let tilevisible1 l x
y =
1015 and ax1
= l
.pagex + l
.pagevw
1017 and ay1
= l
.pagey + l
.pagevh in
1021 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1022 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1024 let rx0 = max
ax0 bx0
1025 and ry0
= max ay0 by0
1026 and rx1
= min ax1
bx1
1027 and ry1
= min ay1 by1
in
1029 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1030 nonemptyintersection
1033 let tilevisible layout n x
y =
1034 let rec findpageinlayout = function
1035 | l
:: _ when l
.pageno
= n -> tilevisible1 l x
y
1036 | _ :: rest
-> findpageinlayout rest
1039 findpageinlayout layout
1042 let tileready l x
y =
1043 tilevisible1 l x
y &&
1044 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
1047 let tilepage n p
layout =
1048 let rec loop = function
1052 let f col row _ _ _ _ _ _ =
1053 if state.currently
= Idle
1055 match gettileopaque l
col row with
1058 let x = col*conf.tilew
1059 and y = row*conf.tileh
in
1061 let w = l
.pagew
- x in
1065 let h = l
.pageh
- y in
1077 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1078 conf.tilew
, conf.tileh
1087 if state.invalidated
= 0 then loop layout;
1090 let preloadlayout visiblepages
=
1091 let presentation = conf.presentation in
1092 let interpagespace = conf.interpagespace in
1093 let maxy = state.maxy in
1094 conf.presentation <- false;
1095 conf.interpagespace <- 0;
1096 state.maxy <- calcheight ();
1098 match visiblepages
with
1100 | l
:: _ -> getpagey l
.pageno
+ l
.pagey
1102 let y = if y < conf.winh
then 0 else y - conf.winh
in
1103 let h = state.y - y + conf.winh
*3 in
1104 let pages = layout y h in
1105 conf.presentation <- presentation;
1106 conf.interpagespace <- interpagespace;
1112 let rec loop pages =
1113 if state.currently
!= Idle
1118 begin match getopaque l
.pageno
with
1120 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1121 state.currently
<- Loading
(l
, state.gen
);
1123 tilepage l
.pageno opaque
pages;
1128 if state.invalidated
= 0 then loop pages
1133 if conf.preload && state.currently
= Idle
1134 then load (preloadlayout pages);
1137 let layoutready layout =
1138 let rec fold all ls
=
1139 all
&& match ls
with
1141 let seen = ref false in
1142 let allvisible = ref true in
1143 let foo col row _ _ _ _ _ _ =
1145 allvisible := !allvisible &&
1146 begin match gettileopaque l
col row with
1152 fold (!seen && !allvisible) rest
1155 let alltilesvisible = fold true layout in
1160 let y = bound y 0 state.maxy in
1161 let y, layout, proceed
=
1162 match conf.maxwait
with
1164 begin match state.throttle
with
1166 let layout = layout y conf.winh
in
1167 let ready = layoutready layout in
1171 state.throttle
<- Some
(layout, y, now ());
1173 else G.postRedisplay "gotoy showall (None)";
1175 | Some
(_, _, started
) ->
1176 let dt = now () -. started
in
1179 state.throttle
<- None
;
1180 let layout = layout y conf.winh
in
1182 G.postRedisplay "maxwait";
1189 let layout = layout y conf.winh
in
1190 if true || layoutready layout
1191 then G.postRedisplay "gotoy ready";
1197 state.layout <- layout;
1198 begin match state.mode
with
1199 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1200 if not
(pagevisible layout pageno
)
1202 match state.layout with
1205 state.mode
<- Birdseye
(
1206 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1215 let conttiling pageno opaque
=
1216 tilepage pageno opaque
1217 (if conf.preload then preloadlayout state.layout else state.layout)
1220 let gotoy_and_clear_text y =
1222 if not
conf.verbose
then state.text <- "";
1226 match state.layout with
1228 | l
:: _ -> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1231 let getanchory (n, top
) =
1232 let y, h = getpageyh n in
1233 y + (truncate
(top
*. float h));
1236 let gotoanchor anchor
=
1237 gotoy (getanchory anchor
);
1241 cbput state.hists
.nav
(getanchor ());
1245 let anchor = cbgetc state.hists
.nav dir
in
1249 let gotopage n top
=
1250 let y, h = getpageyh n in
1251 gotoy_and_clear_text (y + (truncate
(top
*. float h)));
1254 let gotopage1 n top
=
1255 let y = getpagey n in
1256 gotoy_and_clear_text (y + top
);
1264 state.invalidated
<- state.invalidated
+ 1;
1267 let writeopen path password
=
1268 writecmd state.csock
("open " ^ path ^
"\000" ^ password ^
"\000");
1271 let opendoc path password
=
1274 state.password
<- password
;
1275 state.gen
<- state.gen
+ 1;
1276 state.docinfo
<- [];
1278 setaalevel
conf.aalevel
;
1279 writeopen path password
;
1280 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1281 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1285 let c = c *. conf.colorscale
in
1289 let scalecolor2 (r, g
, b) =
1290 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1294 state.maxy <- calcheight ();
1296 if state.w <= conf.winw
- state.scrollw
1300 match state.mode
with
1301 | Birdseye
(_, _, pageno
, _, _) ->
1302 let y, h = getpageyh pageno
in
1303 let top = (conf.winh
- h) / 2 in
1304 gotoy (max
0 (y - top))
1305 | _ -> gotoanchor state.anchor
1309 let firsttime = ref true in
1311 GlDraw.viewport
0 0 w h;
1312 if state.invalidated
= 0 && not
!firsttime
1313 then state.anchor <- getanchor ();
1317 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1321 setfontsize fstate.fontsize
;
1322 GlMat.mode `modelview
;
1323 GlMat.load_identity
();
1325 GlMat.mode `projection
;
1326 GlMat.load_identity
();
1327 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1328 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1329 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1332 wcmd "geometry" [`i
w; `i
h];
1336 let len = String.length
state.text in
1339 match state.mode
with
1340 | View
-> state.hscrollh
1345 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1346 (x+.w, float (conf.winh
- hscrollh))
1349 let w = float (conf.winw
- state.scrollw
- 1) in
1350 if state.progress
>= 0.0 && state.progress
< 1.0
1352 GlDraw.color
(0.3, 0.3, 0.3);
1353 let w1 = w *. state.progress
in
1355 GlDraw.color
(0.0, 0.0, 0.0);
1359 GlDraw.color
(0.0, 0.0, 0.0);
1363 GlDraw.color
(1.0, 1.0, 1.0);
1364 drawstring fstate.fontsize
1365 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1368 match state.mode
with
1369 | Textentry
((prefix
, text, _, _, _), _) ->
1373 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1375 Printf.sprintf
"%s%s_" prefix
text
1384 if not
(istextentry state.mode
)
1386 let s1 = "(press 'e' to review error messasges)" in
1387 if String.length
s > 0 then s ^
" " ^
s1 else s1
1392 if String.length
s > 0
1397 state.text <- Printf.sprintf
"%c%s" c s;
1398 G.postRedisplay "showtext";
1402 let len = Queue.length
state.tilelru
in
1404 if state.memused
<= conf.memlimit
1409 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1410 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1413 && colorspace
= conf.colorspace
1414 && angle
= conf.angle
1415 && pagew
= getpagew n
1416 && pageh
= getpageh n
1420 then preloadlayout state.layout
1423 let x = col*conf.tilew
1424 and y = row*conf.tileh
in
1425 tilevisible layout n x y
1427 then Queue.push lruitem
state.tilelru
1429 wcmd "freetile" [`
s p
];
1430 state.memused
<- state.memused
- s;
1431 state.uioh#infochanged Memused
;
1432 Hashtbl.remove
state.tilemap k
;
1441 Queue.iter
(fun (k
, p
, s) ->
1442 wcmd "freetile" [`
s p
];
1443 state.memused
<- state.memused
- s;
1444 state.uioh#infochanged Memused
;
1445 Hashtbl.remove
state.tilemap k
;
1447 Queue.clear
state.tilelru
;
1451 let logcurrently = function
1452 | Idle
-> dolog "Idle"
1453 | Loading
(l
, gen
) ->
1454 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1455 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1457 "Tiling %d[%d,%d] page=%s cs=%s angle"
1458 l
.pageno
col row pageopaque
1459 (colorspace_to_string colorspace
)
1461 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1462 angle gen
conf.angle
state.gen
1464 conf.tilew
conf.tileh
1471 (* dolog "%S" cmds; *)
1474 try String.index cmds ' '
1475 with Not_found
-> -1
1480 let l = String.length cmds
in
1481 let op = String.sub cmds
0 spacepos in
1483 if l - spacepos < 2 then ""
1484 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1489 state.uioh#infochanged Pdim
;
1493 state.rects
<- state.rects1
;
1494 G.postRedisplay "clearrects";
1498 try Scanf.sscanf args
"%u" (fun n -> n)
1500 dolog "error processing 'continue' %S: %s"
1501 cmds
(Printexc.to_string exn
);
1504 state.pagecount
<- n;
1505 state.invalidated
<- state.invalidated
- 1;
1506 begin match state.currently
with
1508 state.currently
<- Idle
;
1509 state.outlines
<- Array.of_list
(List.rev
l)
1512 if state.invalidated
= 0
1514 if conf.maxwait
= None
1515 then G.postRedisplay "continue";
1518 Glut.setWindowTitle args
1525 then showtext ' ' args
1528 let progress, text =
1530 Scanf.sscanf args
"%f %n"
1532 f, String.sub args pos
(String.length args
- pos
))
1534 dolog "error processing 'progress' %S: %s"
1535 cmds
(Printexc.to_string exn
);
1539 state.progress <- progress;
1540 G.postRedisplay "progress"
1543 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1545 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1546 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1547 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1549 dolog "error processing 'firstmatch' %S: %s"
1550 cmds
(Printexc.to_string exn
);
1553 let y = (getpagey pageno) + truncate y0
in
1556 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)]
1559 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1561 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1562 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1563 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1565 dolog "error processing 'match' %S: %s"
1566 cmds
(Printexc.to_string exn
);
1570 (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) :: state.rects1
1575 Scanf.sscanf args
"%s %f" (fun p t
-> p
, t
)
1577 dolog "error processing 'page' %S: %s"
1578 cmds
(Printexc.to_string exn
);
1581 begin match state.currently
with
1582 | Loading
(l, gen
) ->
1583 vlog "page %d took %f sec" l.pageno t
;
1584 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1585 begin match state.throttle
with
1587 let preloadedpages =
1589 then preloadlayout state.layout
1594 Set.Make
(struct type t
= int let compare = (-) end) in
1596 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1597 IntSet.empty
preloadedpages
1600 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1601 if not
(IntSet.mem
pageno set)
1603 wcmd "freepage" [`
s opaque
];
1609 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1612 state.currently
<- Idle
;
1615 tilepage l.pageno pageopaque state.layout;
1617 load preloadedpages;
1618 if pagevisible state.layout l.pageno
1619 && layoutready state.layout
1620 then G.postRedisplay "page";
1623 | Some
(layout, _, _) ->
1624 state.currently
<- Idle
;
1625 tilepage l.pageno pageopaque layout;
1630 dolog "Inconsistent loading state";
1631 logcurrently state.currently
;
1636 let (x, y, opaque
, size
, t
) =
1638 Scanf.sscanf args
"%u %u %s %u %f"
1639 (fun x y p size t
-> (x, y, p
, size
, t
))
1641 dolog "error processing 'tile' %S: %s"
1642 cmds
(Printexc.to_string exn
);
1645 begin match state.currently
with
1646 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1647 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1649 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1651 wcmd "freetile" [`
s opaque
];
1652 state.currently
<- Idle
;
1656 puttileopaque l col row gen cs angle opaque size t
;
1657 state.memused
<- state.memused
+ size
;
1658 state.uioh#infochanged Memused
;
1660 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1661 opaque
, size
) state.tilelru
;
1663 state.currently
<- Idle
;
1665 && conf.colorspace
= cs
1666 && conf.angle
= angle
1667 && tilevisible state.layout l.pageno x y
1668 then conttiling l.pageno pageopaque;
1670 begin match state.throttle
with
1672 preload state.layout;
1674 && conf.colorspace
= cs
1675 && conf.angle
= angle
1676 && tilevisible state.layout l.pageno x y
1677 then G.postRedisplay "tile nothrottle";
1679 | Some
(layout, y, _) ->
1680 let ready = layoutready layout in
1684 state.layout <- layout;
1685 state.throttle
<- None
;
1686 G.postRedisplay "throttle";
1693 dolog "Inconsistent tiling state";
1694 logcurrently state.currently
;
1701 Scanf.sscanf args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1703 dolog "error processing 'pdim' %S: %s"
1704 cmds
(Printexc.to_string exn
);
1707 state.uioh#infochanged Pdim
;
1708 state.pdims
<- pdim :: state.pdims
1711 let (l, n, t
, h, pos
) =
1713 Scanf.sscanf args
"%u %u %d %u %n"
1714 (fun l n t
h pos
-> l, n, t
, h, pos
)
1716 dolog "error processing 'o' %S: %s"
1717 cmds
(Printexc.to_string exn
);
1720 let s = String.sub args pos
(String.length args
- pos
) in
1721 let outline = (s, l, (n, float t
/. float h)) in
1722 begin match state.currently
with
1723 | Outlining outlines
->
1724 state.currently
<- Outlining
(outline :: outlines
)
1726 state.currently
<- Outlining
[outline]
1728 dolog "invalid outlining state";
1729 logcurrently currently
1733 state.docinfo
<- (1, args
) :: state.docinfo
1736 state.uioh#infochanged Docinfo
;
1737 state.docinfo
<- List.rev
state.docinfo
1740 dolog "unknown cmd `%S'" cmds
1744 if state.deadline
== nan
then state.deadline
<- now ();
1745 let rec loop delay
=
1748 then max
0.0 (state.deadline
-. now ())
1751 let r, _, _ = Unix.select
[state.csock
; state.errfd
] [] [] timeout in
1754 begin match state.autoscroll
with
1755 | Some step
when step
!= 0 ->
1756 let y = state.y + step
in
1760 else if y >= state.maxy then 0 else y
1763 if state.mode
= View
1764 then state.text <- "";
1765 state.deadline
<- state.deadline
+. 0.005;
1768 state.deadline
<- state.deadline
+. delay
;
1772 let rec checkfds c = function
1774 | fd
:: rest
when fd
= state.csock
->
1775 let cmd = readcmd state.csock
in
1778 | fd
:: rest
when fd
= state.errfd
->
1779 let s = String.create
80 in
1780 let n = Unix.read fd
s 0 80 in
1781 if conf.redirectstderr
1783 Buffer.add_substring
state.errmsgs
s 0 n;
1784 state.newerrmsgs
<- true;
1785 Glut.postRedisplay ();
1788 prerr_string
(String.sub
s 0 n);
1794 failwith
"me? fail english? that's unpossible!"
1804 let action = function
1805 | HCprev
-> cbget cb ~
-1
1806 | HCnext
-> cbget cb
1
1807 | HCfirst
-> cbget cb ~
-(cb
.rc)
1808 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1809 and cancel
() = cb
.rc <- rc
1813 let search pattern forward
=
1814 if String.length pattern
> 0
1817 match state.layout with
1820 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1823 let b = makecmd "search"
1824 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
1826 Buffer.add_char
b '
,'
;
1827 Buffer.add_string
b pattern
;
1828 Buffer.add_char
b '
\000'
;
1831 writecmd state.csock
cmd;
1834 let intentry text key =
1835 let c = Char.unsafe_chr
key in
1838 let text = addchar text c in
1842 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1846 let textentry text key =
1847 let c = Char.unsafe_chr
key in
1849 | _ when key >= 32 && key < 127 ->
1850 let text = addchar text c in
1854 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
1858 let reqlayout angle proportional
=
1859 match state.throttle
with
1861 if state.invalidated
= 0 then state.anchor <- getanchor ();
1862 conf.angle
<- angle
mod 360;
1863 conf.proportional
<- proportional
;
1865 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
1869 let settrim trimmargins trimfuzz
=
1870 if state.invalidated
= 0 then state.anchor <- getanchor ();
1871 conf.trimmargins
<- trimmargins
;
1872 conf.trimfuzz
<- trimfuzz
;
1873 let x0, y0
, x1
, y1
= trimfuzz
in
1876 `
b conf.trimmargins
;
1882 Hashtbl.iter
(fun _ opaque
->
1883 wcmd "freepage" [`
s opaque
];
1885 Hashtbl.clear
state.pagemap
;
1889 match state.throttle
with
1891 let zoom = max
0.01 zoom in
1892 if zoom <> conf.zoom
1894 state.prevzoom
<- conf.zoom;
1897 then (state.x <- 0; 0.0)
1898 else float state.x /. float state.w
1901 reshape conf.winw
conf.winh
;
1904 let x = relx *. float state.w in
1905 state.x <- truncate
x;
1907 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
1910 | Some
(layout, y, started
) ->
1912 match conf.maxwait
with
1916 let dt = now () -. started
in
1924 let enterbirdseye () =
1925 let zoom = float conf.thumbw
/. float conf.winw
in
1926 let birdseyepageno =
1927 let cy = conf.winh
/ 2 in
1931 let rec fold best
= function
1934 let d = cy - (l.pagedispy
+ l.pagevh/2)
1935 and dbest
= cy - (best
.pagedispy
+ best
.pagevh/2) in
1936 if abs
d < abs dbest
1943 state.mode
<- Birdseye
(
1944 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
1947 conf.presentation <- false;
1948 conf.interpagespace <- 10;
1949 conf.hlinks
<- false;
1951 state.mstate
<- Mnone
;
1952 conf.maxwait
<- None
;
1953 Glut.setCursor
Glut.CURSOR_INHERIT
;
1956 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1961 reshape conf.winw
conf.winh
;
1964 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
1966 conf.zoom <- c.zoom;
1967 conf.presentation <- c.presentation;
1968 conf.interpagespace <- c.interpagespace;
1969 conf.maxwait
<- c.maxwait
;
1970 conf.hlinks
<- c.hlinks
;
1974 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1977 reshape conf.winw
conf.winh
;
1978 state.anchor <- if goback
then anchor else (pageno, 0.0);
1981 let togglebirdseye () =
1982 match state.mode
with
1983 | Birdseye vals
-> leavebirdseye vals
true
1984 | View
-> enterbirdseye ()
1988 let upbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
1989 let pageno = max
0 (pageno - 1) in
1990 let rec loop = function
1991 | [] -> gotopage1 pageno 0
1992 | l :: _ when l.pageno = pageno ->
1993 if l.pagedispy
>= 0 && l.pagey = 0
1994 then G.postRedisplay "upbirdseye"
1995 else gotopage1 pageno 0
1996 | _ :: rest
-> loop rest
1999 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2002 let downbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
2003 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
2004 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2005 let rec loop = function
2007 let y, h = getpageyh pageno in
2008 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2010 | l :: _ when l.pageno = pageno ->
2011 if l.pagevh != l.pageh
2012 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2013 else G.postRedisplay "downbirdseye"
2014 | _ :: rest
-> loop rest
2019 let optentry mode
_ key =
2020 let btos b = if b then "on" else "off" in
2021 let c = Char.unsafe_chr
key in
2025 try conf.scrollstep
<- int_of_string
s with exc
->
2026 state.text <- Printf.sprintf
"bad integer `%s': %s"
2027 s (Printexc.to_string exc
)
2029 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2034 conf.autoscrollstep
<- int_of_string
s;
2035 if state.autoscroll
<> None
2036 then state.autoscroll
<- Some
conf.autoscrollstep
2038 state.text <- Printf.sprintf
"bad integer `%s': %s"
2039 s (Printexc.to_string exc
)
2041 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2046 let zoom = float (int_of_string
s) /. 100.0 in
2049 state.text <- Printf.sprintf
"bad integer `%s': %s"
2050 s (Printexc.to_string exc
)
2052 TEswitch
("zoom: ", "", None
, intentry, ondone)
2057 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2059 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2060 begin match mode
with
2062 leavebirdseye beye
false;
2067 state.text <- Printf.sprintf
"bad integer `%s': %s"
2068 s (Printexc.to_string exc
)
2070 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2075 Some
(int_of_string
s)
2077 state.text <- Printf.sprintf
"bad integer `%s': %s"
2078 s (Printexc.to_string exc
);
2081 | Some angle
-> reqlayout angle
conf.proportional
2084 TEswitch
("rotation: ", "", None
, intentry, ondone)
2087 conf.icase
<- not
conf.icase
;
2088 TEdone
("case insensitive search " ^
(btos conf.icase
))
2091 conf.preload <- not
conf.preload;
2093 TEdone
("preload " ^
(btos conf.preload))
2096 conf.verbose
<- not
conf.verbose
;
2097 TEdone
("verbose " ^
(btos conf.verbose
))
2100 conf.debug
<- not
conf.debug
;
2101 TEdone
("debug " ^
(btos conf.debug
))
2104 conf.maxhfit
<- not
conf.maxhfit
;
2106 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2107 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2110 conf.crophack
<- not
conf.crophack
;
2111 TEdone
("crophack " ^
btos conf.crophack
)
2115 match conf.maxwait
with
2117 conf.maxwait
<- Some infinity
;
2118 "always wait for page to complete"
2120 conf.maxwait
<- None
;
2121 "show placeholder if page is not ready"
2126 conf.underinfo
<- not
conf.underinfo
;
2127 TEdone
("underinfo " ^
btos conf.underinfo
)
2130 conf.savebmarks
<- not
conf.savebmarks
;
2131 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2137 match state.layout with
2142 conf.interpagespace <- int_of_string
s;
2143 state.maxy <- calcheight ();
2144 let y = getpagey pageno in
2147 state.text <- Printf.sprintf
"bad integer `%s': %s"
2148 s (Printexc.to_string exc
)
2150 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2153 reqlayout conf.angle
(not
conf.proportional
);
2154 TEdone
("proportional display " ^
btos conf.proportional
)
2157 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2158 TEdone
("trim margins " ^
btos conf.trimmargins
)
2161 conf.invert
<- not
conf.invert
;
2162 TEdone
("invert colors " ^
btos conf.invert
)
2165 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2169 class type lvsource
= object
2170 method getitemcount
: int
2171 method getitem
: int -> (string * int)
2172 method hasaction
: int -> bool
2181 method getactive
: int
2182 method getfirst
: int
2183 method getqsearch
: string
2184 method setqsearch
: string -> unit
2188 class virtual lvsourcebase
= object
2189 val mutable m_active
= 0
2190 val mutable m_first
= 0
2191 val mutable m_qsearch
= ""
2192 val mutable m_pan
= 0
2193 method getactive
= m_active
2194 method getfirst
= m_first
2195 method getqsearch
= m_qsearch
2196 method getpan
= m_pan
2197 method setqsearch
s = m_qsearch
<- s
2200 let textentryspecial key = function
2201 | ((c, _, (Some
(action, _) as onhist), onkey
, ondone), mode
) ->
2204 | Glut.KEY_UP
-> action HCprev
2205 | Glut.KEY_DOWN
-> action HCnext
2206 | Glut.KEY_HOME
-> action HCfirst
2207 | Glut.KEY_END
-> action HClast
2210 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2211 G.postRedisplay "special textentry";
2215 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2217 state.mode
<- Textentry
(te
, onleave
);
2220 G.postRedisplay "textentrykeyboard enttext";
2222 match Char.unsafe_chr
key with
2223 | '
\008'
-> (* backspace *)
2224 let len = String.length
text in
2228 G.postRedisplay "textentrykeyboard after cancel";
2231 let s = String.sub
text 0 (len - 1) in
2232 enttext (c, s, opthist
, onkey
, ondone)
2238 G.postRedisplay "textentrykeyboard after confirm"
2240 | '
\007'
(* ctrl-g *)
2241 | '
\027'
-> (* escape *)
2242 if String.length
text = 0
2244 begin match opthist
with
2246 | Some
(_, onhistcancel
) -> onhistcancel
()
2250 G.postRedisplay "textentrykeyboard after cancel2"
2253 enttext (c, "", opthist
, onkey
, ondone)
2256 | '
\127'
-> () (* delete *)
2259 begin match onkey
text key with
2263 G.postRedisplay "textentrykeyboard after confirm2";
2266 enttext (c, text, opthist
, onkey
, ondone);
2271 G.postRedisplay "textentrykeyboard after cancel3"
2274 state.mode
<- Textentry
(te
, onleave
);
2275 G.postRedisplay "textentrykeyboard switch";
2279 let firstof first active
=
2280 if first
> active
|| abs
(first
- active
) > fstate.maxrows
- 1
2281 then max
0 (active
- (fstate.maxrows
/2))
2285 let calcfirst first active
=
2288 let rows = active
- first
in
2289 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2293 let coe s = (s :> uioh
);;
2295 class listview ~
(source
:lvsource
) ~trusted
=
2297 val m_pan
= source#getpan
2298 val m_first
= source#getfirst
2299 val m_active
= source#getactive
2300 val m_qsearch
= source#getqsearch
2301 val m_prev_uioh
= state.uioh
2303 method private elemunder
y =
2304 let n = y / (fstate.fontsize
+1) in
2305 if m_first
+ n < source#getitemcount
2307 if source#hasaction
(m_first
+ n)
2308 then Some
(m_first
+ n)
2315 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2316 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2317 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2318 GlDraw.color
(1., 1., 1.);
2319 Gl.enable `texture_2d
;
2320 let fs = fstate.fontsize
in
2322 let ww = fstate.wwidth
in
2323 let tabw = 30.0*.ww in
2325 if (row - m_first
) * nfs > conf.winh
2328 if row >= 0 && row < source#getitemcount
2330 let (s, level
) = source#getitem
row in
2331 let y = (row - m_first
) * nfs in
2332 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2335 Gl.disable `texture_2d
;
2336 GlDraw.polygon_mode `both `line
;
2337 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2338 GlDraw.rect (1., float (y + 1))
2339 (float (conf.winw
- 1), float (y + fs + 3));
2340 GlDraw.polygon_mode `both `fill
;
2341 GlDraw.color
(1., 1., 1.);
2342 Gl.enable `texture_2d
;
2345 let drawtabularstring s =
2346 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2349 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2352 let len = String.length
s - tabpos - 1 in
2353 let s1 = String.sub
s 0 tabpos
2354 and s2
= String.sub
s (tabpos + 1) len in
2355 let nx = drawstr x s1 in
2357 let x = x +. (max
tabw sw) in
2364 let _ = drawtabularstring s in
2371 Gl.disable `texture_2d
;
2373 method updownlevel incr
=
2374 let len = source#getitemcount
in
2375 let _, curlevel
= source#getitem m_active
in
2377 if i
= len then i
-1 else if i
= -1 then 0 else
2378 let _, l = source#getitem i
in
2379 if l != curlevel
then i
else flow (i
+incr
)
2381 let active = flow m_active
in
2382 let first = calcfirst m_first
active in
2383 G.postRedisplay "special outline updownlevel";
2384 {< m_active
= active; m_first
= first >}
2386 method private key1
key =
2387 let set active first qsearch
=
2388 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2390 let search active pattern incr
=
2393 if n >= 0 && n < source#getitemcount
2395 let s, _ = source#getitem
n in
2397 (try ignore
(Str.search_forward
re s 0); true
2398 with Not_found
-> false)
2400 else loop (n + incr
)
2407 let re = Str.regexp_case_fold pattern
in
2414 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2415 let incr = if key = 18 then -1 else 1 in
2417 match search (m_active
+ incr) m_qsearch
incr with
2419 state.text <- m_qsearch ^
" [not found]";
2422 state.text <- m_qsearch
;
2423 active, firstof m_first
active
2425 G.postRedisplay "listview ctrl-r/s";
2426 set active first m_qsearch
;
2428 | 8 -> (* backspace *)
2429 let len = String.length m_qsearch
in
2436 G.postRedisplay "listview empty qsearch";
2437 set m_active m_first
"";
2440 let qsearch = String.sub m_qsearch
0 (len - 1) in
2442 match search m_active
qsearch ~
-1 with
2444 state.text <- qsearch ^
" [not found]";
2447 state.text <- qsearch;
2448 active, firstof m_first
active
2450 G.postRedisplay "listview backspace qsearch";
2451 set active first qsearch
2454 | _ when key >= 32 && key < 127 ->
2455 let pattern = addchar m_qsearch
(Char.chr
key) in
2457 match search m_active
pattern 1 with
2459 state.text <- pattern ^
" [not found]";
2462 state.text <- pattern;
2463 active, firstof m_first
active
2465 G.postRedisplay "listview qsearch add";
2466 set active first pattern;
2468 | 27 -> (* escape *)
2470 if String.length m_qsearch
= 0
2472 G.postRedisplay "list view escape";
2475 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2477 | None
-> m_prev_uioh
2482 G.postRedisplay "list view kill qsearch";
2483 source#setqsearch
"";
2484 coe {< m_qsearch
= "" >}
2489 let self = {< m_qsearch
= "" >} in
2490 source#setqsearch
"";
2492 G.postRedisplay "listview enter";
2493 if m_active
>= 0 && m_active
< source#getitemcount
2495 source#exit
(coe self) false m_active m_first m_pan
"";
2498 source#exit
(coe self) true m_active m_first m_pan
"";
2501 begin match opt with
2502 | None
-> m_prev_uioh
2506 | 127 -> (* delete *)
2509 | _ -> dolog "unknown key %d" key; coe self
2511 method private special1
key =
2512 let itemcount = source#getitemcount
in
2513 let find start
incr =
2515 if i
= -1 || i
= itemcount
2518 if source#hasaction i
2520 else find (i
+ incr)
2525 let set active first =
2526 let first = bound first 0 (itemcount - fstate.maxrows
) in
2528 coe {< m_active
= active; m_first
= first >}
2531 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2533 let incr1 = if incr > 0 then 1 else -1 in
2534 if isvisible m_first m_active
2537 let next = m_active
+ incr in
2539 if next < 0 || next >= itemcount
2541 else find next incr1
2543 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2549 let first = m_first
+ incr in
2550 let first = bound first 0 (itemcount - 1) in
2552 let next = m_active
+ incr in
2553 let next = bound next 0 (itemcount - 1) in
2556 let active = if next = -1 then m_active
else next in
2559 let first = min
next m_first
in
2562 let first = m_first
+ incr in
2563 let first = bound first 0 (itemcount - 1) in
2565 let next = m_active
+ incr in
2566 let next = bound next 0 (itemcount - 1) in
2567 let next = find next incr1 in
2568 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2574 G.postRedisplay "listview navigate";
2577 begin match key with
2578 | Glut.KEY_UP
-> navigate ~
-1
2579 | Glut.KEY_DOWN
-> navigate 1
2580 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2581 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2585 G.postRedisplay "listview right";
2586 coe {< m_pan
= m_pan
- 1 >}
2590 G.postRedisplay "listview left";
2591 coe {< m_pan
= m_pan
+ 1 >}
2594 let active = find 0 1 in
2595 G.postRedisplay "listview home";
2599 let first = max
0 (itemcount - fstate.maxrows
) in
2600 let active = find (itemcount - 1) ~
-1 in
2601 G.postRedisplay "listview end";
2608 match state.mode
with
2609 | Textentry te
-> textentrykeyboard key te
; coe self
2610 | _ -> self#key1
key
2612 method special
key =
2613 match state.mode
with
2614 | Textentry te
-> textentryspecial key te
; coe self
2615 | _ -> self#special1
key
2617 method button button bstate
_ y =
2620 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2621 begin match self#elemunder
y with
2623 G.postRedisplay "listview click";
2625 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
2629 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2630 let len = source#getitemcount
in
2632 if m_first
+ fstate.maxrows
>= len
2636 let first = m_first
+ (if n == 3 then -1 else 1) in
2637 bound first 0 (len - 1)
2639 G.postRedisplay "listview wheel";
2640 Some
(coe {< m_first
= first >})
2645 | None
-> m_prev_uioh
2648 method motion
_ _ = coe self
2650 method pmotion
_ y =
2652 match self#elemunder
y with
2653 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
2654 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
2658 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
2663 method infochanged
_ = ()
2666 class outlinelistview ~source
=
2668 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
2672 | 14 -> (* ctrl-n *)
2673 source#narrow m_qsearch
;
2674 G.postRedisplay "outline ctrl-n";
2675 coe {< m_first
= 0; m_active
= 0 >}
2677 | 21 -> (* ctrl-u *)
2679 G.postRedisplay "outline ctrl-u";
2680 coe {< m_first
= 0; m_active
= 0 >}
2682 | 12 -> (* ctrl-l *)
2683 let first = m_active
- (fstate.maxrows
/ 2) in
2684 G.postRedisplay "outline ctrl-l";
2685 coe {< m_first
= first >}
2687 | 127 -> (* delete *)
2688 source#remove m_active
;
2689 G.postRedisplay "outline delete";
2690 let active = max
0 (m_active
-1) in
2691 coe {< m_first
= firstof m_first
active;
2692 m_active
= active >}
2694 | key -> super#
key key
2696 method special
key =
2697 let calcfirst first active =
2700 let rows = active - first in
2701 if rows > fstate.maxrows
then active - fstate.maxrows
else first
2705 let active = m_active
+ incr in
2706 let active = bound active 0 (source#getitemcount
- 1) in
2707 let first = calcfirst m_first
active in
2708 G.postRedisplay "special outline navigate";
2709 coe {< m_active
= active; m_first
= first >}
2712 | Glut.KEY_UP
-> navigate ~
-1
2713 | Glut.KEY_DOWN
-> navigate 1
2714 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2715 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2719 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2721 G.postRedisplay "special outline right";
2722 {< m_pan
= m_pan
+ 1 >}
2724 else self#updownlevel
1
2730 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2732 G.postRedisplay "special outline left";
2733 {< m_pan
= m_pan
- 1 >}
2735 else self#updownlevel ~
-1
2740 G.postRedisplay "special outline home";
2741 coe {< m_first
= 0; m_active
= 0 >}
2744 let active = source#getitemcount
- 1 in
2745 let first = max
0 (active - fstate.maxrows
) in
2746 G.postRedisplay "special outline end";
2747 coe {< m_active
= active; m_first
= first >}
2749 | _ -> super#special
key
2752 let outlinesource usebookmarks
=
2755 inherit lvsourcebase
2756 val mutable m_items
= empty
2757 val mutable m_orig_items
= empty
2758 val mutable m_prev_items
= empty
2759 val mutable m_narrow_pattern
= ""
2760 val mutable m_hadremovals
= false
2762 method getitemcount
=
2763 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
2766 if n == Array.length m_items
&& m_hadremovals
2768 ("[Confirm removal]", 0)
2770 let s, n, _ = m_items
.(n) in
2773 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
2774 ignore
(uioh
, first, pan
, qsearch);
2775 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
2777 if String.length m_narrow_pattern
= 0
2783 if not
confrimremoval
2785 let _, _, anchor = m_items
.(active) in
2790 state.bookmarks
<- Array.to_list m_items
;
2791 m_orig_items
<- m_items
;
2794 else m_items
<- items;
2797 method hasaction
_ = true
2800 if Array.length m_items
!= Array.length m_orig_items
2801 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
2804 method narrow
pattern =
2805 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
2809 let rec loop accu n =
2812 m_narrow_pattern
<- pattern;
2813 m_items
<- Array.of_list
accu
2816 let (s, _, _) as o = m_items
.(n) in
2818 if (try ignore
(Str.search_forward
re s 0); true
2819 with Not_found
-> false)
2825 loop [] (Array.length m_items
- 1)
2830 then Array.of_list
state.bookmarks
2833 m_items
<- m_orig_items
2838 if m
>= 0 && m
< Array.length m_items
2840 m_hadremovals
<- true;
2841 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
2842 let n = if n >= m
then n+1 else n in
2847 method reset
pageno items =
2848 m_hadremovals
<- false;
2849 if m_orig_items
== empty || m_prev_items
!= items
2851 m_orig_items
<- items;
2852 if String.length m_narrow_pattern
= 0
2853 then m_items
<- items;
2855 m_prev_items
<- items;
2857 let rec loop n best bestd
=
2858 if n = Array.length m_items
2861 let (_, _, (outlinepageno
, _)) = m_items
.(n) in
2862 let d = abs
(outlinepageno
- pageno) in
2865 else loop (n+1) best bestd
2870 m_first
<- firstof m_first
active
2874 let enterselector usebookmarks
=
2875 let source = outlinesource usebookmarks
in
2879 then Array.of_list
state.bookmarks
2882 if Array.length
outlines = 0
2884 showtext ' ' errmsg
;
2887 state.text <- source#greetmsg
;
2888 Glut.setCursor
Glut.CURSOR_INHERIT
;
2890 match state.layout with
2892 | {pageno=pageno} :: _ -> pageno
2894 source#reset
pageno outlines;
2895 state.uioh
<- coe (new outlinelistview ~
source);
2896 G.postRedisplay "enter selector";
2900 let enteroutlinemode =
2901 let f = enterselector false in
2902 fun ()-> f "Document has no outline";
2905 let enterbookmarkmode =
2906 let f = enterselector true in
2907 fun () -> f "Document has no bookmarks (yet)";
2910 let color_of_string s =
2911 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
2912 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
2916 let color_to_string (r, g
, b) =
2917 let r = truncate
(r *. 256.0)
2918 and g
= truncate
(g
*. 256.0)
2919 and b = truncate
(b *. 256.0) in
2920 Printf.sprintf
"%d/%d/%d" r g
b
2923 let irect_of_string s =
2924 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0,y0
,x1
,y1
))
2927 let irect_to_string (x0,y0
,x1
,y1
) =
2928 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
2931 let makecheckers () =
2932 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
2934 converted by Issac Trotts. July 25, 2002 *)
2935 let image_height = 64
2936 and image_width
= 64 in
2940 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
2942 for i
= 0 to image_width
- 1 do
2943 for j
= 0 to image_height - 1 do
2944 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
2945 (if (i
land 8 ) lxor (j
land 8) = 0
2946 then [|255;255;255|] else [|200;200;200|])
2951 let image = make_image () in
2952 let id = GlTex.gen_texture
() in
2953 GlTex.bind_texture `texture_2d
id;
2954 GlPix.store
(`unpack_alignment
1);
2955 GlTex.image2d
image;
2956 List.iter
(GlTex.parameter ~target
:`texture_2d
)
2959 `mag_filter `nearest
;
2960 `min_filter `nearest
];
2964 let setcheckers enabled
=
2965 match state.texid
with
2967 if enabled
then state.texid
<- Some
(makecheckers ())
2972 GlTex.delete_texture texid
;
2973 state.texid
<- None
;
2977 let int_of_string_with_suffix s =
2978 let l = String.length
s in
2982 let suffix = Char.lowercase
s.[l-1] in
2984 | 'k'
-> String.sub
s 0 (l-1), 10
2985 | 'm'
-> String.sub
s 0 (l-1), 20
2986 | 'g'
-> String.sub
s 0 (l-1), 30
2990 let n = int_of_string
s1 in
2991 let m = n lsl shift
in
2993 then raise
(Failure
"value too large")
2997 let string_with_suffix_of_int n =
3005 if n land ((1 lsl 20) - 1) = 0
3008 if n land ((1 lsl 10) - 1) = 0
3015 let h = n mod 1000 in
3018 then string_of_int
h ^
s
3020 let s = Printf.sprintf
"_%03d%s" h s in
3027 let describe_location () =
3029 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3031 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3032 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3036 else (100. *. (float state.y /. float maxy))
3040 Printf.sprintf
"page %d of %d [%.2f%%]"
3041 (fn+1) state.pagecount
percent
3044 "pages %d-%d of %d [%.2f%%]"
3045 (fn+1) (ln
+1) state.pagecount
percent
3049 let btos b = if b then "\xe2\x88\x9a" else "" in
3050 let showextended = ref false in
3051 let leave mode
= function
3052 | Confirm
-> state.mode
<- mode
3053 | Cancel
-> state.mode
<- mode
in
3056 val mutable m_first_time
= true
3057 val mutable m_l
= []
3058 val mutable m_a
= [||]
3059 val mutable m_prev_uioh
= nouioh
3060 val mutable m_prev_mode
= View
3062 inherit lvsourcebase
3064 method reset prev_mode prev_uioh
=
3065 m_a
<- Array.of_list
(List.rev m_l
);
3067 m_prev_mode
<- prev_mode
;
3068 m_prev_uioh
<- prev_uioh
;
3072 if n >= Array.length m_a
3076 | _, _, _, Action
_ -> m_active
<- n
3080 m_first_time
<- false;
3083 method int name get
set =
3085 (name
, `
int get
, 1, Action
(
3088 try set (int_of_string
s)
3090 state.text <- Printf.sprintf
"bad integer `%s': %s"
3091 s (Printexc.to_string exn
)
3094 let te = name ^
": ", "", None
, intentry, ondone in
3095 state.mode
<- Textentry
(te, leave m_prev_mode
);
3099 method int_with_suffix name get
set =
3101 (name
, `intws get
, 1, Action
(
3104 try set (int_of_string_with_suffix s)
3106 state.text <- Printf.sprintf
"bad integer `%s': %s"
3107 s (Printexc.to_string exn
)
3111 name ^
": ", "", None
, intentry_with_suffix, ondone
3113 state.mode
<- Textentry
(te, leave m_prev_mode
);
3117 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3119 (name
, `
bool (btos, get
), offset
, Action
(
3126 method color name get
set =
3128 (name
, `color get
, 1, Action
(
3130 let invalid = (nan
, nan
, nan
) in
3133 try color_of_string s
3135 state.text <- Printf.sprintf
"bad color `%s': %s"
3136 s (Printexc.to_string exn
);
3142 let te = name ^
": ", "", None
, textentry, ondone in
3143 state.text <- color_to_string (get
());
3144 state.mode
<- Textentry
(te, leave m_prev_mode
);
3148 method string name get
set =
3150 (name
, `
string get
, 1, Action
(
3152 let ondone s = set s in
3153 let te = name ^
": ", "", None
, textentry, ondone in
3154 state.mode
<- Textentry
(te, leave m_prev_mode
);
3158 method colorspace name get
set =
3160 (name
, `
string get
, 1, Action
(
3163 let vals = [| "rgb"; "bgr"; "gray" |] in
3165 inherit lvsourcebase
3168 m_active
<- int_of_colorspace conf.colorspace
;
3171 method getitemcount
= Array.length
vals
3172 method getitem
n = (vals.(n), 0)
3173 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3174 ignore
(uioh
, first, pan
, qsearch);
3175 if not cancel
then set active;
3177 method hasaction
_ = true
3181 coe (new listview ~
source ~trusted
:true)
3184 method caption
s offset
=
3185 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3187 method caption2
s f offset
=
3188 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3190 method getitemcount
= Array.length m_a
3193 let tostr = function
3194 | `
int f -> string_of_int
(f ())
3195 | `intws
f -> string_with_suffix_of_int (f ())
3197 | `color
f -> color_to_string (f ())
3198 | `
bool (btos, f) -> btos (f ())
3201 let name, t
, offset
, _ = m_a
.(n) in
3202 ((let s = tostr t
in
3203 if String.length
s > 0
3204 then Printf.sprintf
"%s\t%s" name s
3208 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3212 m_qsearch
<- qsearch;
3214 match m_a
.(active) with
3215 | _, _, _, Action
f -> f uioh
3227 method hasaction
n =
3229 | _, _, _, Action
_ -> true
3233 let rec fillsrc prevmode prevuioh
=
3234 let sep () = src#caption
"" 0 in
3235 let colorp name get
set =
3237 (fun () -> color_to_string (get
()))
3240 let c = color_of_string v in
3243 state.text <- Printf.sprintf
"bad color `%s': %s"
3244 v (Printexc.to_string exn
);
3247 let oldmode = state.mode
in
3248 let birdseye = isbirdseye state.mode
in
3250 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3252 src#
bool "presentation mode"
3253 (fun () -> conf.presentation)
3255 conf.presentation <- v;
3256 state.anchor <- getanchor ();
3259 src#
bool "ignore case in searches"
3260 (fun () -> conf.icase
)
3261 (fun v -> conf.icase
<- v);
3264 (fun () -> conf.preload)
3265 (fun v -> conf.preload <- v);
3267 src#
bool "highlight links"
3268 (fun () -> conf.hlinks
)
3269 (fun v -> conf.hlinks
<- v);
3271 src#
bool "under info"
3272 (fun () -> conf.underinfo
)
3273 (fun v -> conf.underinfo
<- v);
3275 src#
bool "persistent bookmarks"
3276 (fun () -> conf.savebmarks
)
3277 (fun v -> conf.savebmarks
<- v);
3279 src#
bool "proportional display"
3280 (fun () -> conf.proportional
)
3281 (fun v -> reqlayout conf.angle
v);
3283 src#
bool "trim margins"
3284 (fun () -> conf.trimmargins
)
3285 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3287 src#
bool "persistent location"
3288 (fun () -> conf.jumpback
)
3289 (fun v -> conf.jumpback
<- v);
3292 src#
int "vertical margin"
3293 (fun () -> conf.interpagespace)
3295 conf.interpagespace <- n;
3297 match state.layout with
3302 state.maxy <- calcheight ();
3303 let y = getpagey pageno in
3308 (fun () -> conf.pagebias
)
3309 (fun v -> conf.pagebias
<- v);
3311 src#
int "scroll step"
3312 (fun () -> conf.scrollstep
)
3313 (fun n -> conf.scrollstep
<- n);
3315 src#
int "auto scroll step"
3317 match state.autoscroll
with
3319 | _ -> conf.autoscrollstep
)
3321 if state.autoscroll
<> None
3322 then state.autoscroll
<- Some
n;
3323 conf.autoscrollstep
<- n);
3326 (fun () -> truncate
(conf.zoom *. 100.))
3327 (fun v -> setzoom ((float v) /. 100.));
3330 (fun () -> conf.angle
)
3331 (fun v -> reqlayout v conf.proportional
);
3333 src#
int "scroll bar width"
3334 (fun () -> state.scrollw
)
3338 reshape conf.winw
conf.winh
;
3341 src#
int "scroll handle height"
3342 (fun () -> conf.scrollh
)
3343 (fun v -> conf.scrollh
<- v;);
3345 src#
int "thumbnail width"
3346 (fun () -> conf.thumbw
)
3348 conf.thumbw
<- min
4096 v;
3351 leavebirdseye beye
false;
3357 src#caption
"Presentation mode" 0;
3358 src#
bool "scrollbar visible"
3359 (fun () -> conf.scrollbarinpm
)
3361 if v != conf.scrollbarinpm
3363 conf.scrollbarinpm
<- v;
3364 if conf.presentation
3366 state.scrollw
<- if v then conf.scrollbw
else 0;
3367 reshape conf.winw
conf.winh
;
3373 src#caption
"Pixmap cache" 0;
3374 src#int_with_suffix
"size (advisory)"
3375 (fun () -> conf.memlimit
)
3376 (fun v -> conf.memlimit
<- v);
3379 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3380 (string_with_suffix_of_int state.memused
)
3381 (Hashtbl.length
state.tilemap
)) 1;
3384 src#caption
"Layout" 0;
3385 src#caption2
"Dimension"
3387 Printf.sprintf
"%dx%d (virtual %dx%d)"
3393 src#caption2
"Position" (fun () ->
3394 Printf.sprintf
"%dx%d" state.x state.y
3397 src#caption2
"Visible" (fun () -> describe_location ()) 1
3401 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3402 "Save these parameters as global defaults at exit"
3403 (fun () -> conf.bedefault
)
3404 (fun v -> conf.bedefault
<- v)
3408 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3409 src#
bool ~offset
:0 ~
btos "Extended parameters"
3410 (fun () -> !showextended)
3411 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3415 (fun () -> conf.checkers
)
3416 (fun v -> conf.checkers
<- v; setcheckers v);
3418 (fun () -> conf.verbose
)
3419 (fun v -> conf.verbose
<- v);
3420 src#
bool "invert colors"
3421 (fun () -> conf.invert
)
3422 (fun v -> conf.invert
<- v);
3424 (fun () -> conf.maxhfit
)
3425 (fun v -> conf.maxhfit
<- v);
3426 src#
bool "redirect stderr"
3427 (fun () -> conf.redirectstderr)
3428 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3429 src#
string "uri launcher"
3430 (fun () -> conf.urilauncher
)
3431 (fun v -> conf.urilauncher
<- v);
3432 src#
string "tile size"
3433 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3436 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3437 conf.tileh
<- max
64 w;
3438 conf.tilew
<- max
64 h;
3441 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3442 v (Printexc.to_string exn
));
3443 src#
int "anti-aliasing level"
3444 (fun () -> conf.aalevel
)
3446 conf.aalevel
<- bound v 0 8;
3447 state.anchor <- getanchor ();
3448 opendoc state.path
state.password
;
3450 src#
int "ui font size"
3451 (fun () -> fstate.fontsize
)
3452 (fun v -> setfontsize (bound v 5 100));
3453 colorp "background color"
3454 (fun () -> conf.bgcolor
)
3455 (fun v -> conf.bgcolor
<- v);
3456 src#
bool "crop hack"
3457 (fun () -> conf.crophack
)
3458 (fun v -> conf.crophack
<- v);
3459 src#
string "trim fuzz"
3460 (fun () -> irect_to_string conf.trimfuzz
)
3463 conf.trimfuzz
<- irect_of_string v;
3465 then settrim true conf.trimfuzz
;
3467 state.text <- Printf.sprintf
"bad irect `%s': %s"
3468 v (Printexc.to_string exn
)
3470 src#
string "throttle"
3472 match conf.maxwait
with
3473 | None
-> "show place holder if page is not ready"
3476 then "wait for page to fully render"
3478 "wait " ^ string_of_float
time
3479 ^
" seconds before showing placeholder"
3483 let f = float_of_string
v in
3485 then conf.maxwait
<- None
3486 else conf.maxwait
<- Some
f
3488 state.text <- Printf.sprintf
"bad time `%s': %s"
3489 v (Printexc.to_string exn
)
3491 src#colorspace
"color space"
3492 (fun () -> colorspace_to_string conf.colorspace
)
3494 conf.colorspace
<- colorspace_of_int v;
3501 src#caption
"Document" 0;
3502 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3506 src#caption
"Trimmed margins" 0;
3507 src#caption2
"Dimensions"
3508 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3511 src#reset prevmode prevuioh
;
3515 let prevmode = state.mode
3516 and prevuioh
= state.uioh in
3517 fillsrc prevmode prevuioh
;
3518 let source = (src :> lvsource
) in
3519 state.uioh <- coe (object (self)
3520 inherit listview ~
source ~trusted
:true as super
3521 val mutable m_prevmemused
= 0
3522 method infochanged
= function
3524 if m_prevmemused
!= state.memused
3526 m_prevmemused
<- state.memused
;
3527 G.postRedisplay "memusedchanged";
3529 | Pdim
-> G.postRedisplay "pdimchanged"
3530 | Docinfo
-> fillsrc prevmode prevuioh
3532 method special
key =
3533 if Glut.getModifiers
() land Glut.active_ctrl
= 0
3536 | Glut.KEY_LEFT
-> coe (self#updownlevel ~
-1)
3537 | Glut.KEY_RIGHT
-> coe (self#updownlevel
1)
3538 | _ -> super#special
key
3539 else super#special
key
3541 G.postRedisplay "info";
3547 inherit lvsourcebase
3548 method getitemcount
= Array.length
state.help
3550 let s, n, _ = state.help
.(n) in
3553 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3557 m_qsearch
<- qsearch;
3558 match state.help
.(active) with
3559 | _, _, Action
f -> Some
(f uioh)
3569 method hasaction
n =
3570 match state.help
.(n) with
3571 | _, _, Action
_ -> true
3578 state.uioh <- coe (new listview ~
source ~trusted
:true);
3579 G.postRedisplay "help";
3584 let re = Str.regexp
"[\r\n]" in
3586 inherit lvsourcebase
3587 val mutable m_items
= [||]
3589 method getitemcount
=
3592 1 + Array.length m_items
3596 else m_items
.(n-1), 0
3598 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3603 then Buffer.clear
state.errmsgs
;
3604 m_qsearch
<- qsearch;
3611 method hasaction
n = n = 0
3613 state.newerrmsgs
<- false;
3614 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
3615 m_items
<- Array.of_list
l
3623 let source = (msgsource :> lvsource
) in
3624 state.uioh <- coe (new listview ~
source ~trusted
:false);
3625 G.postRedisplay "msgs";
3628 let quickbookmark ?title
() =
3629 match state.layout with
3635 let sec = Unix.gettimeofday
() in
3636 let tm = Unix.localtime
sec in
3637 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
3641 (tm.Unix.tm_year
+ 1900)
3644 | Some
title -> title
3647 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
3652 state.fullscreen
<- None
;
3653 Glut.reshapeWindow
w h;
3656 let viewkeyboard key =
3658 let mode = state.mode in
3659 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
3662 G.postRedisplay "view:enttext"
3664 let c = Char.chr
key in
3666 | '
\027'
| 'q'
-> (* escape *)
3667 begin match state.mstate
with
3669 state.mstate
<- Mnone
;
3670 Glut.setCursor
Glut.CURSOR_INHERIT
;
3671 G.postRedisplay "kill zoom rect";
3676 | '
\008'
-> (* backspace *)
3677 let y = getnav ~
-1 in
3678 gotoy_and_clear_text y
3686 G.postRedisplay "dehighlight";
3689 let ondone isforw
s =
3690 cbput state.hists
.pat
s;
3691 state.searchpattern
<- s;
3694 let s = String.create
1 in
3696 enttext (s, "", Some
(onhist state.hists
.pat
),
3697 textentry, ondone (c ='
/'
))
3699 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3700 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3701 setzoom (conf.zoom +. incr)
3706 try int_of_string
s with exc
->
3707 state.text <- Printf.sprintf
"bad integer `%s': %s"
3708 s (Printexc.to_string exc
);
3714 state.text <- "page bias is now " ^ string_of_int
n;
3717 enttext ("page bias: ", "", None
, intentry, ondone)
3719 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3720 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3721 setzoom (max
0.01 (conf.zoom -. decr))
3724 let ondone msg
= state.text <- msg
in
3726 "option [acfhilpstvAPRSZTI]: ", "", None
,
3727 optentry state.mode, ondone
3730 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3733 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3734 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
3738 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3744 try int_of_string
s with exc
->
3745 state.text <- Printf.sprintf
"bad integer `%s': %s"
3746 s (Printexc.to_string exc
);
3752 cbput state.hists
.pag
(string_of_int
n);
3753 gotoy_and_clear_text (getpagey (n + conf.pagebias
- 1))
3756 let pageentry text key =
3757 match Char.unsafe_chr
key with
3758 | 'g'
-> TEdone
text
3759 | _ -> intentry text key
3761 let text = "x" in text.[0] <- c;
3762 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
3765 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
3766 reshape conf.winw
conf.winh
;
3769 conf.hlinks
<- not
conf.hlinks
;
3770 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
3771 G.postRedisplay "toggle highlightlinks";
3774 begin match state.autoscroll
with
3776 conf.autoscrollstep
<- step
;
3777 state.autoscroll
<- None
3779 if conf.autoscrollstep
= 0
3780 then state.autoscroll
<- Some
1
3781 else state.autoscroll
<- Some
conf.autoscrollstep
3785 conf.presentation <- not
conf.presentation;
3786 if conf.presentation
3788 if not
conf.scrollbarinpm
3789 then state.scrollw
<- 0;
3792 state.scrollw
<- conf.scrollbw
;
3794 showtext ' '
("presentation mode " ^
3795 if conf.presentation then "on" else "off");
3796 state.anchor <- getanchor ();
3800 begin match state.fullscreen
with
3802 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
3805 state.fullscreen
<- None
;
3810 gotoy_and_clear_text 0
3813 gotopage1 (state.pagecount
- 1) 0
3816 search state.searchpattern
true
3819 search state.searchpattern
false
3822 begin match state.layout with
3825 gotoy_and_clear_text (getpagey l.pageno)
3829 begin match List.rev
state.layout with
3832 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
3833 gotoy_and_clear_text (getpagey pageno)
3836 | '
\127'
-> (* del *)
3837 begin match state.layout with
3840 let pageno = max
0 (l.pageno-1) in
3841 gotoy_and_clear_text (getpagey pageno)
3845 showtext ' '
(describe_location ());
3848 begin match state.layout with
3851 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
3856 enterbookmarkmode ()
3864 | '
e'
when conf.redirectstderr ->
3869 match state.layout with
3872 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
3876 enttext ("bookmark: ", "", None
, textentry, ondone)
3880 showtext ' '
"Quick bookmark added";
3883 begin match state.layout with
3885 let rect = getpdimrect
l.pagedimno
in
3889 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
3890 truncate
(1.2 *. (rect.(3) -. rect.(0))))
3892 (truncate
(rect.(1) -. rect.(0)),
3893 truncate
(rect.(3) -. rect.(0)))
3895 let w = truncate
((float w)*.conf.zoom)
3896 and h = truncate
((float h)*.conf.zoom) in
3899 state.anchor <- getanchor ();
3900 doreshape (w + state.scrollw
) (h + conf.interpagespace)
3902 G.postRedisplay "z";
3907 | '
\000'
-> (* ctrl-2 *)
3908 let maxw = getmaxw
() in
3910 then setzoom (maxw /. float conf.winw
)
3913 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
3917 bound (conf.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
3919 G.postRedisplay "brightness";
3922 begin match state.mode with
3923 | Birdseye beye
-> upbirdseye beye
3924 | _ -> gotoy (clamp (-conf.scrollstep
))
3928 begin match state.mode with
3929 | Birdseye beye
-> downbirdseye beye
3930 | _ -> gotoy (clamp conf.scrollstep
)
3934 state.anchor <- getanchor ();
3935 opendoc state.path
state.password
3937 | '
v'
when conf.debug
->
3940 match getopaque l.pageno with
3943 let x0, y0
, x1
, y1
= pagebbox opaque
in
3944 let a,b = float x0, float y0
in
3945 let c,d = float x1
, float y0
in
3946 let e,f = float x1
, float y1
in
3947 let h,j
= float x0, float y1
in
3948 let rect = (a,b,c,d,e,f,h,j
) in
3950 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
3952 G.postRedisplay "v";
3955 vlog "huh? %d %c" key (Char.chr
key);
3958 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
3960 | 27 -> (* escape *)
3961 leavebirdseye beye
true
3963 | 12 -> (* ctrl-l *)
3964 let y, h = getpageyh pageno in
3965 let top = (conf.winh
- h) / 2 in
3966 gotoy (max
0 (y - top))
3969 leavebirdseye beye
false
3975 let keyboard ~
key ~
x ~
y =
3978 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
3979 then wcmd "interrupt" []
3980 else state.uioh <- state.uioh#
key key
3983 let birdseyespecial key ((conf, leftx
, _, hooverpageno
, anchor) as beye
) =
3985 | Glut.KEY_UP
-> upbirdseye beye
3986 | Glut.KEY_DOWN
-> downbirdseye beye
3988 | Glut.KEY_PAGE_UP
->
3989 begin match state.layout with
3993 state.mode <- Birdseye
(
3994 conf, leftx
, l.pageno, hooverpageno
, anchor
3996 gotopage1 l.pageno 0;
3999 let layout = layout (state.y-conf.winh
) conf.winh
in
4001 | [] -> gotoy (clamp (-conf.winh
))
4003 state.mode <- Birdseye
(
4004 conf, leftx
, l.pageno, hooverpageno
, anchor
4006 gotopage1 l.pageno 0
4009 | [] -> gotoy (clamp (-conf.winh
))
4012 | Glut.KEY_PAGE_DOWN
->
4013 begin match List.rev
state.layout with
4015 let layout = layout (state.y + conf.winh
) conf.winh
in
4016 begin match layout with
4018 let incr = l.pageh
- l.pagevh in
4023 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4025 G.postRedisplay "birdseye pagedown";
4027 else gotoy (clamp (incr + conf.interpagespace*2));
4031 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
4032 gotopage1 l.pageno 0;
4035 | [] -> gotoy (clamp conf.winh
)
4039 state.mode <- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
4043 let pageno = state.pagecount
- 1 in
4044 state.mode <- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
4045 if not
(pagevisible state.layout pageno)
4048 match List.rev
state.pdims
with
4050 | (_, _, h, _) :: _ -> h
4052 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4053 else G.postRedisplay "birdseye end";
4057 let setautoscrollspeed step goingdown
=
4058 let incr = max
1 ((abs step
) / 2) in
4059 let incr = if goingdown
then incr else -incr in
4060 let astep = step
+ incr in
4061 state.autoscroll
<- Some
astep;
4064 let special ~
key ~
x ~
y =
4067 state.uioh <- state.uioh#
special key
4072 match state.mode with
4073 | Textentry
_ -> scalecolor 0.4
4074 | View
-> scalecolor 1.0
4075 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4076 if l.pageno = hooverpageno
4079 if l.pageno = pageno
4085 begin match getopaque l.pageno with
4087 if tileready l l.pagex l.pagey
4089 let x = l.pagedispx
- l.pagex
4090 and y = l.pagedispy
- l.pagey in
4091 postprocess opaque
conf.hlinks
x y;
4098 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
4099 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
4100 let sh = float conf.winh
/. sh in
4101 let sh = max
sh (float conf.scrollh
) in
4106 else float y /. float maxy
4108 let position = (float conf.winh
-. sh) *. percent in
4111 if position +. sh > float conf.winh
4112 then float conf.winh
-. sh
4119 let winw = conf.winw - state.scrollw
- 1 in
4120 let fwinw = float winw in
4122 let sw = fwinw /. float state.w in
4123 let sw = fwinw *. sw in
4124 max
sw (float conf.scrollh
)
4127 let f = state.w+winw in
4128 let r = float (winw-x) /. float f in
4129 let p = fwinw *. r in
4133 if position +. sw > fwinw
4134 then fwinw -. position
4140 let scrollindicator () =
4141 GlDraw.color (0.64 , 0.64, 0.64);
4143 (float (conf.winw - state.scrollw
), 0.)
4144 (float conf.winw, float conf.winh
)
4147 (0., float (conf.winh
- state.hscrollh))
4148 (float (conf.winw - state.scrollw
- 1), float conf.winh
)
4150 GlDraw.color (0.0, 0.0, 0.0);
4152 let position, sh = scrollph state.y in
4154 (float (conf.winw - state.scrollw
), position)
4155 (float conf.winw, position +. sh)
4157 let position, sw = scrollpw state.x in
4159 (position, float (conf.winh
- state.hscrollh))
4160 (position +. sw, float conf.winh
)
4164 let pagetranslatepoint l x y =
4165 let dy = y - l.pagedispy
in
4166 let y = dy + l.pagey in
4167 let dx = x - l.pagedispx
in
4168 let x = dx + l.pagex in
4173 match state.mstate
with
4174 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4177 | Msel
((x0, y0
), (x1
, y1
)) ->
4178 let rec loop = function
4180 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
4181 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
4183 match getopaque l.pageno with
4185 let dx, dy = pagetranslatepoint l 0 0 in
4190 GlMat.mode `modelview
;
4192 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4193 seltext opaque
(x0, y0
, x1
, y1
);
4204 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4205 GlDraw.polygon_mode `both `fill
;
4206 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4208 (fun (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
4210 if l.pageno = pageno
4212 let dx = float (l.pagedispx
- l.pagex) in
4213 let dy = float (l.pagedispy
- l.pagey) in
4214 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4215 GlDraw.begins `quads
;
4217 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4218 GlDraw.vertex2
(x1
+.dx, y1
+.dy);
4219 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4220 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4231 GlClear.color (scalecolor2 conf.bgcolor
);
4232 GlClear.clear
[`
color];
4233 List.iter
drawpage state.layout;
4238 begin match state.mstate
with
4239 | Mzoomrect
((x0, y0
), (x1
, y1
)) ->
4241 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4242 GlDraw.polygon_mode `both `fill
;
4243 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4244 GlDraw.rect (float x0, float y0
)
4245 (float x1
, float y1
);
4250 Glut.swapBuffers
();
4254 let rec f = function
4256 begin match getopaque l.pageno with
4258 let x0 = l.pagedispx
in
4259 let x1 = x0 + l.pagevw in
4260 let y0 = l.pagedispy
in
4261 let y1 = y0 + l.pagevh in
4262 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4264 let px, py = pagetranslatepoint l x y in
4265 match whatsunder opaque
px py with
4277 let zoomrect x y x1 y1 =
4280 and y0 = min
y y1 in
4281 gotoy (state.y + y0);
4282 state.anchor <- getanchor ();
4283 let zoom = (float conf.winw *. conf.zoom) /. float (x1 - x0) in
4285 if state.w < conf.winw - state.scrollw
4286 then (conf.winw - state.scrollw
- state.w) / 2
4289 state.x <- (state.x + margin) - x0;
4291 Glut.setCursor
Glut.CURSOR_INHERIT
;
4292 state.mstate
<- Mnone
;
4296 let winw = conf.winw - state.scrollw
- 1 in
4297 let s = float x /. float winw in
4298 let destx = truncate
(float (state.w + winw) *. s) in
4299 state.x <- winw - destx;
4300 gotoy_and_clear_text state.y;
4301 state.mstate
<- Mscrollx
;
4305 let s = float y /. float conf.winh
in
4306 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4307 gotoy_and_clear_text desty;
4308 state.mstate
<- Mscrolly
;
4311 let viewmouse button bstate
x y =
4313 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4314 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4316 match state.mstate
with
4317 | Mzoom
(oldn
, i
) ->
4325 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4327 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4329 let zoom = conf.zoom -. incr in
4331 state.mstate
<- Mzoom
(n, 0);
4333 state.mstate
<- Mzoom
(n, i
+1);
4335 else state.mstate
<- Mzoom
(n, 0)
4337 | _ -> state.mstate
<- Mzoom
(n, 0)
4340 match state.autoscroll
with
4341 | Some step
-> setautoscrollspeed step
(n=4)
4345 then -conf.scrollstep
4346 else conf.scrollstep
4348 let incr = incr * 2 in
4349 let y = clamp incr in
4350 gotoy_and_clear_text y
4353 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4354 if bstate
= Glut.DOWN
4356 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4357 state.mstate
<- Mpan
(x, y)
4360 state.mstate
<- Mnone
4362 | Glut.RIGHT_BUTTON
->
4363 if bstate
= Glut.DOWN
4365 Glut.setCursor
Glut.CURSOR_CYCLE
;
4367 state.mstate
<- Mzoomrect
(p, p)
4370 match state.mstate
with
4371 | Mzoomrect
((x0, y0), _) -> zoomrect x0 y0 x y
4373 Glut.setCursor
Glut.CURSOR_INHERIT
;
4374 state.mstate
<- Mnone
4377 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4378 if bstate
= Glut.DOWN
4380 let position, sh = scrollph state.y in
4381 if y > truncate
position && y < truncate
(position +. sh)
4382 then state.mstate
<- Mscrolly
4385 state.mstate
<- Mnone
4387 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4388 if bstate
= Glut.DOWN
4390 let position, sw = scrollpw state.x in
4391 if x > truncate
position && x < truncate
(position +. sw)
4392 then state.mstate
<- Mscrollx
4395 state.mstate
<- Mnone
4397 | Glut.LEFT_BUTTON
->
4398 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4399 begin match dest with
4400 | Ulinkgoto
(pageno, top) ->
4404 gotopage1 pageno top;
4410 | Unone
when bstate
= Glut.DOWN
->
4411 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4412 state.mstate
<- Mpan
(x, y);
4414 | Unone
| Utext
_ ->
4415 if bstate
= Glut.DOWN
4417 if conf.angle
mod 360 = 0
4419 state.mstate
<- Msel
((x, y), (x, y));
4420 G.postRedisplay "mouse select";
4424 match state.mstate
with
4427 | Mzoom
_ | Mscrollx
| Mscrolly
->
4428 state.mstate
<- Mnone
4430 | Mzoomrect
((x0, y0), _) ->
4434 Glut.setCursor
Glut.CURSOR_INHERIT
;
4435 state.mstate
<- Mnone
4437 | Msel
((_, y0), (_, y1)) ->
4439 if (y0 >= l.pagedispy
&& y0 <= (l.pagedispy
+ l.pagevh))
4440 || ((y1 >= l.pagedispy
&& y1 <= (l.pagedispy
+ l.pagevh)))
4442 match getopaque l.pageno with
4447 List.iter
f state.layout;
4448 copysel
""; (* ugly *)
4449 Glut.setCursor
Glut.CURSOR_INHERIT
;
4450 state.mstate
<- Mnone
;
4457 let birdseyemouse button bstate
x y
4458 (conf, leftx
, _, hooverpageno
, anchor) =
4460 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4461 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4462 let rec loop = function
4465 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4466 && x > margin && x < margin + l.pagew
4468 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4473 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4477 let mouse bstate button
x y =
4478 state.uioh <- state.uioh#button button bstate
x y;
4481 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4484 state.uioh <- state.uioh#
motion x y
4488 state.uioh <- state.uioh#
pmotion x y;
4495 begin match state.mode with
4496 | Textentry
textentry -> textentrykeyboard key textentry
4497 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4498 | View
-> viewkeyboard key
4502 method special key =
4503 begin match state.mode with
4504 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4508 birdseyespecial key vals
4510 | View
when key = Glut.KEY_F1
->
4514 begin match state.autoscroll
with
4515 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4516 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4521 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4523 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4525 if Glut.getModifiers
() land Glut.active_shift
!= 0
4526 then (setzoom state.prevzoom
; state.y)
4527 else clamp (-conf.winh
/2)
4528 else clamp (-conf.scrollstep
)
4530 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4532 if Glut.getModifiers
() land Glut.active_shift
!= 0
4533 then (setzoom state.prevzoom
; state.y)
4534 else clamp (conf.winh
/2)
4535 else clamp (conf.scrollstep
)
4536 | Glut.KEY_PAGE_UP
->
4537 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4539 match state.layout with
4541 | l :: _ -> state.y - l.pagey
4544 | Glut.KEY_PAGE_DOWN
->
4545 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4547 match List.rev
state.layout with
4549 | l :: _ -> getpagey l.pageno
4557 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
4559 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
4560 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
4561 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
4563 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
4565 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4566 then (conf.winw / 2)
4569 state.x <- state.x - dx;
4571 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
4573 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4574 then (conf.winw / 2)
4577 state.x <- state.x + dx;
4582 gotoy_and_clear_text y
4585 | Textentry
te -> textentryspecial key te
4589 method button button bstate
x y =
4590 begin match state.mode with
4591 | View
-> viewmouse button bstate
x y
4592 | Birdseye beye
-> birdseyemouse button bstate
x y beye
4598 begin match state.mode with
4600 | View
| Birdseye
_ ->
4601 match state.mstate
with
4602 | Mzoom
_ | Mnone
-> ()
4607 state.mstate
<- Mpan
(x, y);
4608 if conf.zoom > 1.0 then state.x <- state.x + dx;
4610 gotoy_and_clear_text y
4613 state.mstate
<- Msel
(a, (x, y));
4614 G.postRedisplay "motion select";
4617 let y = min
conf.winh
(max
0 y) in
4621 let x = min
conf.winw (max
0 x) in
4624 | Mzoomrect
(p0
, _) ->
4625 state.mstate
<- Mzoomrect
(p0
, (x, y));
4626 G.postRedisplay "motion zoomrect";
4630 method pmotion x y =
4631 begin match state.mode with
4632 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
4633 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4634 let rec loop = function
4636 if hooverpageno
!= -1
4638 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
4639 G.postRedisplay "pmotion birdseye no hoover";
4642 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4643 && x > margin && x < margin + l.pagew
4645 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
4646 G.postRedisplay "pmotion birdseye hoover";
4655 match state.mstate
with
4657 begin match getunder x y with
4658 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
4660 if conf.underinfo
then showtext 'u'
("ri: " ^
uri);
4661 Glut.setCursor
Glut.CURSOR_INFO
4662 | Ulinkgoto
(page
, _) ->
4664 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
4665 Glut.setCursor
Glut.CURSOR_INFO
4667 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
4668 Glut.setCursor
Glut.CURSOR_TEXT
4671 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
4676 method infochanged
_ = ()
4683 let fontpath = ref "";;
4684 let wmclasshack = ref false;;
4687 let l = String.length
s in
4688 let b = Buffer.create
l in
4696 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
4697 | _ -> Sys.getenv
"HOME"
4700 ("Can not determine home directory location: " ^
4701 Printexc.to_string exn
);
4705 let config_of c attrs
=
4709 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
4710 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
4711 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
4712 | "preload" -> { c with preload = bool_of_string
v }
4713 | "page-bias" -> { c with pagebias
= int_of_string
v }
4714 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
4715 | "auto-scroll-step" ->
4716 { c with autoscrollstep
= max
0 (int_of_string
v) }
4717 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
4718 | "crop-hack" -> { c with crophack
= bool_of_string
v }
4721 match String.lowercase
v with
4722 | "true" -> Some infinity
4724 | f -> Some
(float_of_string
f)
4726 { c with maxwait
= mw}
4727 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
4728 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
4729 | "vertical-margin" ->
4730 { c with interpagespace = max
0 (int_of_string
v) }
4732 let zoom = float_of_string
v /. 100. in
4733 let zoom = max
zoom 0.0 in
4734 { c with zoom = zoom }
4735 | "presentation" -> { c with presentation = bool_of_string
v }
4736 | "rotation-angle" -> { c with angle
= int_of_string
v }
4737 | "width" -> { c with winw = max
20 (int_of_string
v) }
4738 | "height" -> { c with winh
= max
20 (int_of_string
v) }
4739 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
4740 | "proportional-display" -> { c with proportional
= bool_of_string
v }
4741 | "pixmap-cache-size" ->
4742 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
4743 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
4744 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
4745 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
4746 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
4747 | "background-color" -> { c with bgcolor
= color_of_string v }
4748 | "scrollbar-in-presentation" ->
4749 { c with scrollbarinpm
= bool_of_string
v }
4750 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
4751 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
4753 { c with mumemlimit
= max
1024 (int_of_string_with_suffix v) }
4754 | "checkers" -> { c with checkers
= bool_of_string
v }
4755 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
4756 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
4757 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
4758 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
4759 | "uri-launcher" -> { c with urilauncher
= unent v }
4760 | "color-space" -> { c with colorspace
= colorspace_of_string v }
4761 | "invert-colors" -> { c with invert
= bool_of_string
v }
4762 | "brightness" -> { c with colorscale
= float_of_string
v }
4763 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
4766 prerr_endline
("Error processing attribute (`" ^
4767 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
4770 let rec fold c = function
4773 let c = apply c k
v in
4779 let fromstring f pos
n v d =
4782 dolog "Error processing attribute (%S=%S) at %d\n%s"
4783 n v pos
(Printexc.to_string exn
)
4788 let bookmark_of attrs
=
4789 let rec fold title page rely
= function
4790 | ("title", v) :: rest
-> fold v page rely rest
4791 | ("page", v) :: rest
-> fold title v rely rest
4792 | ("rely", v) :: rest
-> fold title page
v rest
4793 | _ :: rest
-> fold title page rely rest
4794 | [] -> title, page
, rely
4796 fold "invalid" "0" "0" attrs
4800 let rec fold path page rely pan
= function
4801 | ("path", v) :: rest
-> fold v page rely pan rest
4802 | ("page", v) :: rest
-> fold path
v rely pan rest
4803 | ("rely", v) :: rest
-> fold path page
v pan rest
4804 | ("pan", v) :: rest
-> fold path page rely
v rest
4805 | _ :: rest
-> fold path page rely pan rest
4806 | [] -> path
, page
, rely
, pan
4808 fold "" "0" "0" "0" attrs
4811 let setconf dst
src =
4812 dst
.scrollbw
<- src.scrollbw
;
4813 dst
.scrollh
<- src.scrollh
;
4814 dst
.icase
<- src.icase
;
4815 dst
.preload <- src.preload;
4816 dst
.pagebias
<- src.pagebias
;
4817 dst
.verbose
<- src.verbose
;
4818 dst
.scrollstep
<- src.scrollstep
;
4819 dst
.maxhfit
<- src.maxhfit
;
4820 dst
.crophack
<- src.crophack
;
4821 dst
.autoscrollstep
<- src.autoscrollstep
;
4822 dst
.maxwait
<- src.maxwait
;
4823 dst
.hlinks
<- src.hlinks
;
4824 dst
.underinfo
<- src.underinfo
;
4825 dst
.interpagespace <- src.interpagespace;
4826 dst
.zoom <- src.zoom;
4827 dst
.presentation <- src.presentation;
4828 dst
.angle
<- src.angle
;
4829 dst
.winw <- src.winw;
4830 dst
.winh
<- src.winh
;
4831 dst
.savebmarks
<- src.savebmarks
;
4832 dst
.memlimit
<- src.memlimit
;
4833 dst
.proportional
<- src.proportional
;
4834 dst
.texcount
<- src.texcount
;
4835 dst
.sliceheight
<- src.sliceheight
;
4836 dst
.thumbw
<- src.thumbw
;
4837 dst
.jumpback
<- src.jumpback
;
4838 dst
.bgcolor
<- src.bgcolor
;
4839 dst
.scrollbarinpm
<- src.scrollbarinpm
;
4840 dst
.tilew
<- src.tilew
;
4841 dst
.tileh
<- src.tileh
;
4842 dst
.mumemlimit
<- src.mumemlimit
;
4843 dst
.checkers
<- src.checkers
;
4844 dst
.aalevel
<- src.aalevel
;
4845 dst
.trimmargins
<- src.trimmargins
;
4846 dst
.trimfuzz
<- src.trimfuzz
;
4847 dst
.urilauncher
<- src.urilauncher
;
4848 dst
.colorspace
<- src.colorspace
;
4849 dst
.invert
<- src.invert
;
4850 dst
.colorscale
<- src.colorscale
;
4851 dst
.redirectstderr <- src.redirectstderr;
4855 let h = Hashtbl.create
10 in
4856 let dc = { defconf with angle
= defconf.angle
} in
4857 let rec toplevel v t spos
_ =
4859 | Vdata
| Vcdata
| Vend
-> v
4860 | Vopen
("llppconfig", _, closed
) ->
4863 else { v with f = llppconfig
}
4865 error
"unexpected subelement at top level" s spos
4866 | Vclose
_ -> error
"unexpected close at top level" s spos
4868 and llppconfig
v t spos
_ =
4870 | Vdata
| Vcdata
-> v
4871 | Vend
-> error
"unexpected end of input in llppconfig" s spos
4872 | Vopen
("defaults", attrs
, closed
) ->
4873 let c = config_of dc attrs
in
4877 else { v with f = skip
"defaults" (fun () -> v) }
4879 | Vopen
("ui-font", attrs
, closed
) ->
4880 let rec getsize size
= function
4882 | ("size", v) :: rest
->
4884 fromstring int_of_string spos
"size" v fstate.fontsize
in
4886 | l -> getsize size l
4888 fstate.fontsize
<- getsize fstate.fontsize attrs
;
4891 else { v with f = uifont
(Buffer.create
10) }
4893 | Vopen
("doc", attrs
, closed
) ->
4894 let pathent, spage
, srely
, span
= doc_of attrs
in
4895 let path = unent pathent
4896 and pageno = fromstring int_of_string spos
"page" spage
0
4897 and rely
= fromstring float_of_string spos
"rely" srely
0.0
4898 and pan
= fromstring int_of_string spos
"pan" span
0 in
4899 let c = config_of dc attrs
in
4900 let anchor = (pageno, rely
) in
4902 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
4903 else { v with f = doc
path pan
anchor c [] }
4906 error
"unexpected subelement in llppconfig" s spos
4908 | Vclose
"llppconfig" -> { v with f = toplevel }
4909 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
4911 and uifont
b v t spos epos
=
4914 Buffer.add_substring
b s spos
(epos
- spos
);
4916 | Vopen
(_, _, _) ->
4917 error
"unexpected subelement in ui-font" s spos
4918 | Vclose
"ui-font" ->
4919 if String.length
!fontpath = 0
4920 then fontpath := Buffer.contents
b;
4921 { v with f = llppconfig
}
4922 | Vclose
_ -> error
"unexpected close in ui-font" s spos
4923 | Vend
-> error
"unexpected end of input in ui-font" s spos
4925 and doc
path pan
anchor c bookmarks
v t spos
_ =
4927 | Vdata
| Vcdata
-> v
4928 | Vend
-> error
"unexpected end of input in doc" s spos
4929 | Vopen
("bookmarks", _, closed
) ->
4932 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
4934 | Vopen
(_, _, _) ->
4935 error
"unexpected subelement in doc" s spos
4938 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
4939 { v with f = llppconfig
}
4941 | Vclose
_ -> error
"unexpected close in doc" s spos
4943 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
4945 | Vdata
| Vcdata
-> v
4946 | Vend
-> error
"unexpected end of input in bookmarks" s spos
4947 | Vopen
("item", attrs
, closed
) ->
4948 let titleent, spage
, srely
= bookmark_of attrs
in
4949 let page = fromstring int_of_string spos
"page" spage
0
4950 and rely
= fromstring float_of_string spos
"rely" srely
0.0 in
4951 let bookmarks = (unent titleent, 0, (page, rely
)) :: bookmarks in
4953 then { v with f = pbookmarks
path pan
anchor c bookmarks }
4956 { v with f = skip
"item" f }
4959 error
"unexpected subelement in bookmarks" s spos
4961 | Vclose
"bookmarks" ->
4962 { v with f = doc
path pan
anchor c bookmarks }
4964 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
4966 and skip tag
f v t spos
_ =
4968 | Vdata
| Vcdata
-> v
4970 error
("unexpected end of input in skipped " ^ tag
) s spos
4971 | Vopen
(tag'
, _, closed
) ->
4975 let f'
() = { v with f = skip tag
f } in
4976 { v with f = skip tag'
f'
}
4980 else error
("unexpected close in skipped " ^ tag
) s spos
4983 parse
{ f = toplevel; accu = () } s;
4989 let len = in_channel_length ic
in
4990 let s = String.create
len in
4991 really_input ic
s 0 len;
4994 | Parse_error
(msg
, s, pos
) ->
4995 let subs = subs s pos
in
4996 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
4997 failwith
("parse error: " ^
s)
5000 failwith
("config load error: " ^
Printexc.to_string exn
)
5006 let dir = Filename.concat
home ".config" in
5007 if Sys.is_directory
dir then dir else home
5010 Filename.concat
dir "llpp.conf"
5013 let confpath = ref defconfpath;;
5016 if Sys.file_exists
!confpath
5019 (try Some
(open_in_bin
!confpath)
5022 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5023 Printexc.to_string exn
);
5032 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5033 Printexc.to_string exn
);
5039 f (Hashtbl.create
0, defconf)
5044 let pc, pb
, px, pa
=
5046 Hashtbl.find h (Filename.basename
state.path)
5047 with Not_found
-> dc, [], 0, (0, 0.0)
5051 state.bookmarks <- pb
;
5053 state.scrollw
<- conf.scrollbw
;
5055 then state.anchor <- pa
;
5056 cbput state.hists
.nav pa
;
5061 let add_attrs bb always
dc c =
5064 then Printf.bprintf bb
"\n %s='%b'" s a
5067 then Printf.bprintf bb
"\n %s='%d'" s a
5070 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5073 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5076 then Printf.bprintf bb
"\n %s='%f'" s a
5080 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5084 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5088 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5092 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5102 else string_of_float
f
5104 Printf.bprintf bb
"\n %s='%s'" s v
5108 then dc.winw, dc.winh
5110 match state.fullscreen
with
5112 | None
-> c.winw, c.winh
5114 let zoom, presentation, interpagespace, maxwait
=
5116 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5118 match state.mode with
5119 | Birdseye
(bc
, _, _, _, _) ->
5120 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5121 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5123 oi
"width" w dc.winw;
5124 oi
"height" h dc.winh
;
5125 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5126 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5127 ob "case-insensitive-search" c.icase
dc.icase
;
5128 ob "preload" c.preload dc.preload;
5129 oi
"page-bias" c.pagebias
dc.pagebias
;
5130 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5131 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5132 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5133 ob "crop-hack" c.crophack
dc.crophack
;
5134 oW
"throttle" maxwait
dc.maxwait
;
5135 ob "highlight-links" c.hlinks
dc.hlinks
;
5136 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5137 oi
"vertical-margin" interpagespace dc.interpagespace;
5138 oz
"zoom" zoom dc.zoom;
5139 ob "presentation" presentation dc.presentation;
5140 oi
"rotation-angle" c.angle
dc.angle
;
5141 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5142 ob "proportional-display" c.proportional
dc.proportional
;
5143 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5144 oi
"tex-count" c.texcount
dc.texcount
;
5145 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5146 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5147 ob "persistent-location" c.jumpback
dc.jumpback
;
5148 oc
"background-color" c.bgcolor
dc.bgcolor
;
5149 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5150 oi
"tile-width" c.tilew
dc.tilew
;
5151 oi
"tile-height" c.tileh
dc.tileh
;
5152 oI
"mupdf-memlimit" c.mumemlimit
dc.mumemlimit
;
5153 ob "checkers" c.checkers
dc.checkers
;
5154 oi
"aalevel" c.aalevel
dc.aalevel
;
5155 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5156 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5157 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5158 oC
"color-space" c.colorspace
dc.colorspace
;
5159 ob "invert-colors" c.invert
dc.invert
;
5160 oF
"brightness" c.colorscale
dc.colorscale
;
5161 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5163 then ob "wmclass-hack" !wmclasshack false;
5167 let uifontsize = fstate.fontsize
in
5168 let bb = Buffer.create
32768 in
5170 let dc = if conf.bedefault
then conf else dc in
5171 Buffer.add_string
bb "<llppconfig>\n";
5173 if String.length
!fontpath > 0
5175 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5181 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5184 Buffer.add_string
bb "<defaults ";
5185 add_attrs bb true dc dc;
5186 Buffer.add_string
bb "/>\n";
5188 let adddoc path pan
anchor c bookmarks =
5189 if bookmarks == [] && c = dc && anchor = emptyanchor
5192 Printf.bprintf
bb "<doc path='%s'"
5193 (enent
path 0 (String.length
path));
5195 if anchor <> emptyanchor
5197 let n, y = anchor in
5198 Printf.bprintf
bb " page='%d'" n;
5201 Printf.bprintf
bb " rely='%f'" y
5206 then Printf.bprintf
bb " pan='%d'" pan
;
5208 add_attrs bb false dc c;
5210 begin match bookmarks with
5211 | [] -> Buffer.add_string
bb "/>\n"
5213 Buffer.add_string
bb ">\n<bookmarks>\n";
5214 List.iter
(fun (title, _level
, (page, rely
)) ->
5216 "<item title='%s' page='%d'"
5217 (enent
title 0 (String.length
title))
5222 Printf.bprintf
bb " rely='%f'" rely
5224 Buffer.add_string
bb "/>\n";
5226 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5232 match state.mode with
5233 | Birdseye
(_, pan, _, _, _) -> pan
5236 let basename = Filename.basename state.path in
5237 adddoc basename pan (getanchor ())
5240 match state.autoscroll
with
5242 | None
-> conf.autoscrollstep
}
5243 (if conf.savebmarks
then state.bookmarks else []);
5245 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5247 then adddoc path x y c bookmarks
5249 Buffer.add_string
bb "</llppconfig>";
5252 if Buffer.length
bb > 0
5255 let tmp = !confpath ^
".tmp" in
5256 let oc = open_out_bin
tmp in
5257 Buffer.output_buffer
oc bb;
5259 Unix.rename
tmp !confpath;
5262 ("error while saving configuration: " ^
Printexc.to_string exn
)
5269 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5270 "<password> Set password");
5272 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5273 "<path> Set path to the user interface font");
5275 ("-c", Arg.String
(fun s -> Config.confpath := s),
5276 "<path> Set path to the configuration file");
5278 ("-v", Arg.Unit
(fun () ->
5280 "%s\nconfiguration path: %s\n"
5284 exit
0), " Print version and exit");
5287 (fun s -> state.path <- s)
5288 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5290 if String.length
state.path = 0
5291 then (prerr_endline
"file name missing"; exit
1);
5295 let _ = Glut.init
Sys.argv
in
5296 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5297 let () = Glut.initWindowSize
conf.winw conf.winh
in
5298 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5300 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5301 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5302 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5307 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5309 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5310 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5311 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5312 Unix.bind
sock addr;
5314 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5315 Unix.connect
csock addr;
5316 let ssock, _ = Unix.accept
sock in
5319 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5320 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5327 let () = Glut.displayFunc
display in
5328 let () = Glut.reshapeFunc
reshape in
5329 let () = Glut.keyboardFunc
keyboard in
5330 let () = Glut.specialFunc
special in
5331 let () = Glut.idleFunc
(Some
idle) in
5332 let () = Glut.mouseFunc
mouse in
5333 let () = Glut.motionFunc
motion in
5334 let () = Glut.passiveMotionFunc
pmotion in
5336 setcheckers conf.checkers
;
5338 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5339 conf.texcount
, conf.sliceheight
, conf.mumemlimit
, conf.colorspace
,
5340 !Config.wmclasshack, !Config.fontpath
5342 state.csock <- csock;
5343 state.ssock <- ssock;
5344 state.text <- "Opening " ^
state.path;
5345 setaalevel
conf.aalevel
;
5346 writeopen state.path state.password
;
5348 setfontsize fstate.fontsize
;
5356 | Glut.BadEnum
"key in special_of_int" ->
5357 showtext '
!'
" LablGlut bug: special key not recognized";
5364 | exn
when conf.redirectstderr ->
5366 Printf.sprintf
"exception %s\n%s"
5367 (Printexc.to_string exn
)
5368 (Printexc.get_backtrace
())
5371 Unix.single_write
state.stderr
s 0 (String.length
s);