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
-> opaque
-> unit = "ml_drawtile";;
90 | Msel
of (mpos
* mpos
)
93 | Mzoom
of (int * int)
94 | Mzoomrect
of (mpos
* mpos
)
98 type textentry
= string * string * onhist
option * onkey
* ondone
99 and onkey
= string -> int -> te
100 and ondone
= string -> unit
101 and histcancel
= unit -> unit
102 and onhist
= ((histcmd
-> string) * histcancel
)
103 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
108 | TEswitch
of textentry
119 let bound v minv maxv
=
120 max minv
(min maxv v
);
124 { store
= Array.create n v
131 let drawstring size x y s
=
133 Gl.enable `texture_2d
;
134 ignore
(drawstr size x y s
);
136 Gl.disable `texture_2d
;
139 let drawstring1 size x y s
=
143 let drawstring2 size x y fmt
=
144 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
147 let cbcap b
= Array.length b
.store
;;
152 b
.wc
<- (b
.wc
+ 1) mod cap;
154 b
.len
<- min
(b
.len
+ 1) cap;
157 let cbempty b
= b
.len
= 0;;
159 let cbgetg b circular dir
=
163 let rc = b
.rc + dir
in
175 else max
0 (min
rc (b
.len
-1))
181 let cbget b
= cbgetg b
false;;
182 let cbgetc b
= cbgetg b
true;;
199 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
200 dolog " WxH %dx%d" l
.pagew l
.pageh
;
201 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
202 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
203 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
207 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
209 dolog " x0,y0=(% f, % f)" x0 y0
;
210 dolog " x1,y1=(% f, % f)" x1 y1
;
211 dolog " x2,y2=(% f, % f)" x2 y2
;
212 dolog " x3,y3=(% f, % f)" x3 y3
;
217 { mutable scrollbw
: int
218 ; mutable scrollh
: int
219 ; mutable icase
: bool
220 ; mutable preload
: bool
221 ; mutable pagebias
: int
222 ; mutable verbose
: bool
223 ; mutable debug
: bool
224 ; mutable scrollstep
: int
225 ; mutable maxhfit
: bool
226 ; mutable crophack
: bool
227 ; mutable autoscrollstep
: int
228 ; mutable maxwait
: float option
229 ; mutable hlinks
: bool
230 ; mutable underinfo
: bool
231 ; mutable interpagespace
: interpagespace
232 ; mutable zoom
: float
233 ; mutable presentation
: bool
234 ; mutable angle
: angle
237 ; mutable savebmarks
: bool
238 ; mutable proportional
: proportional
239 ; mutable trimmargins
: trimmargins
240 ; mutable trimfuzz
: irect
241 ; mutable memlimit
: memsize
242 ; mutable texcount
: texcount
243 ; mutable sliceheight
: sliceheight
244 ; mutable thumbw
: width
245 ; mutable jumpback
: bool
246 ; mutable bgcolor
: float * float * float
247 ; mutable bedefault
: bool
248 ; mutable scrollbarinpm
: bool
249 ; mutable tilew
: int
250 ; mutable tileh
: int
251 ; mutable 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
288 method scrollpw
: (int * float * float)
289 method scrollph
: (int * float * float)
293 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
294 | Textentry
of (textentry
* onleave
)
296 and onleave
= leavetextentrystatus
-> unit
297 and leavetextentrystatus
= | Cancel
| Confirm
298 and helpitem
= string * int * action
301 | Action
of (uioh
-> uioh
)
304 let isbirdseye = function Birdseye _
-> true | _
-> false;;
305 let istextentry = function Textentry _
-> true | _
-> false;;
309 | Loading
of (page
* gen
)
311 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
313 | Outlining
of outline list
316 let nouioh : uioh
= object (self
)
319 method special _
= self
320 method button _ _ _ _
= self
321 method motion _ _
= self
322 method pmotion _ _
= self
323 method infochanged _
= ()
324 method scrollpw
= (0, nan
, nan
)
325 method scrollph
= (0, nan
, nan
)
329 { mutable csock
: Unix.file_descr
330 ; mutable ssock
: Unix.file_descr
331 ; mutable errfd
: Unix.file_descr
332 ; mutable stderr
: Unix.file_descr
333 ; mutable errmsgs
: Buffer.t
334 ; mutable newerrmsgs
: bool
338 ; mutable scrollw
: int
339 ; mutable hscrollh
: int
340 ; mutable anchor
: anchor
342 ; mutable layout
: page list
343 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
344 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
345 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
346 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
347 ; mutable pagecount
: int
348 ; mutable currently
: currently
349 ; mutable mstate
: mstate
350 ; mutable searchpattern
: string
351 ; mutable rects
: (pageno
* recttype
* rect
) list
352 ; mutable rects1
: (pageno
* recttype
* rect
) list
353 ; mutable text
: string
354 ; mutable fullscreen
: (width
* height
) option
355 ; mutable mode
: mode
356 ; mutable uioh
: uioh
357 ; mutable outlines
: outline array
358 ; mutable bookmarks
: outline list
359 ; mutable path
: string
360 ; mutable password
: string
361 ; mutable invalidated
: int
362 ; mutable memused
: memsize
364 ; mutable throttle
: (page list
* int * float) option
365 ; mutable autoscroll
: int option
366 ; mutable help
: helpitem array
367 ; mutable docinfo
: (int * string) list
368 ; mutable deadline
: float
369 ; mutable texid
: GlTex.texture_id
option
371 ; mutable prevzoom
: float
372 ; mutable progress
: float
375 { pat
: string circbuf
376 ; pag
: string circbuf
377 ; nav
: anchor circbuf
398 ; presentation
= false
403 ; proportional
= true
404 ; trimmargins
= false
405 ; trimfuzz
= (0,0,0,0)
406 ; memlimit
= 32 lsl 20
411 ; bgcolor
= (0.5, 0.5, 0.5)
413 ; scrollbarinpm
= true
416 ; mumemlimit
= 128 lsl 20
421 | Plinux
| Pfreebsd
| Pdragonflybsd
| Popenbsd
| Psun
-> "xdg-open \"%s\""
422 | Posx
-> "open \"%s\""
423 | Pwindows
| Pcygwin
| Pmingw
-> "iexplore \"%s\""
428 ; redirectstderr
= false
432 let conf = { defconf with angle
= defconf.angle
};;
435 { mutable fontsize
: int
436 ; mutable wwidth
: float
437 ; mutable maxrows
: int
449 fstate.fontsize
<- n
;
450 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
451 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
455 if String.length
conf.urilauncher
= 0
456 then print_endline uri
458 let re = Str.regexp
"%s" in
459 let command = Str.global_replace
re uri
conf.urilauncher
in
461 try Some
(Unix.open_process_in
command)
464 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
469 | Some ic
-> close_in ic
474 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
475 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
479 let strings = version () :: "" :: Help.keys
in
481 let r = Str.regexp
"\\(http://[^ ]+\\)" in
483 if (try Str.search_forward
r s
0 with Not_found
-> -1) >= 0
485 let uri = Str.matched_string s
in
486 (s
, 0, Action
(fun u
-> gotouri uri; u
))
487 else s
, 0, Noaction
) strings
495 ; stderr
= Unix.stderr
496 ; errmsgs
= Buffer.create
0
503 ; anchor
= emptyanchor
506 ; tilelru
= Queue.create
()
507 ; pagemap
= Hashtbl.create
10
508 ; tilemap
= Hashtbl.create
10
525 { nav
= cbnew 10 (0, 0.0)
546 Printf.kprintf prerr_endline fmt
548 Printf.kprintf ignore fmt
551 let redirectstderr () =
552 if conf.redirectstderr
554 let rfd, wfd
= Unix.pipe
() in
555 state.stderr
<- Unix.dup
Unix.stderr
;
557 Unix.dup2 wfd
Unix.stderr
;
559 state.newerrmsgs
<- false;
560 Unix.dup2
state.stderr
Unix.stderr
;
561 prerr_string
(Buffer.contents
state.errmsgs
);
563 Buffer.clear
state.errmsgs
;
569 let postRedisplay who
=
571 then prerr_endline
("redisplay for " ^ who
);
572 Glut.postRedisplay ();
577 let b = Buffer.create
(String.length s
+ 1) in
578 Buffer.add_string
b s
;
583 let colorspace_of_string s
=
584 match String.lowercase s
with
588 | _
-> failwith
"invalid colorspace"
591 let int_of_colorspace = function
597 let colorspace_of_int = function
601 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
604 let colorspace_to_string = function
610 let intentry_with_suffix text key
=
611 let c = Char.unsafe_chr key
in
612 match Char.lowercase
c with
614 let text = addchar text c in
618 let text = addchar text c in
622 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
627 let len = String.length s
in
629 let b = Buffer.create
n in
630 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
631 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
632 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
633 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
634 Buffer.add_string
b s
;
635 let s'
= Buffer.contents
b in
636 let n'
= Unix.write fd
s'
0 n in
637 if n'
!= n then failwith
"write failed";
642 let n = Unix.read fd
s 0 4 in
643 if n != 4 then failwith
"incomplete read(len)";
645 lor (Char.code
s.[0] lsl 24)
646 lor (Char.code
s.[1] lsl 16)
647 lor (Char.code
s.[2] lsl 8)
648 lor (Char.code
s.[3] lsl 0)
650 let s = String.create
len in
651 let n = Unix.read fd
s 0 len in
652 if n != len then failwith
"incomplete read(data)";
657 let b = Buffer.create
10 in
658 Buffer.add_string
b s;
659 let rec combine = function
662 Buffer.add_char
b ' '
;
665 | `
b b -> if b then "1" else "0"
667 | `i i
-> string_of_int i
668 | `f f
-> string_of_float f
669 | `I f
-> string_of_int
(truncate f
)
671 Buffer.add_string
b s;
678 let cmd = Buffer.contents
(makecmd s l
) in
679 writecmd state.csock
cmd;
685 let d = conf.winh
- h
in
692 let rec f pn ph pi fh l
=
694 | (n, _
, h
, _
) :: rest
->
695 let ips = calcips h
in
700 if isbirdseye state.mode
&& pn
= 0
705 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
710 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
714 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
717 let fh = f 0 0 0 0 state.pdims
in
721 let getpageyh pageno
=
722 let rec f pn ph pi y l
=
724 | (n, _
, h
, _
) :: rest
->
725 let ips = calcips h
in
728 let h = if n = pageno
then h else ph
in
729 if conf.presentation
&& n = pageno
731 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
733 y
+ (pageno
- pn
) * (ph
+ pi
), h
735 let y = y + (if conf.presentation
then pi
else 0) in
736 let y = y + (n - pn
) * (ph
+ pi
) in
740 y + (pageno
- pn
) * (ph
+ pi
), ph
742 f 0 0 0 0 state.pdims
745 let getpagedim pageno
=
748 | (n, _
, _
, _
) as pdim
:: rest
->
750 then (if n = pageno
then pdim
else ppdim
)
755 f (-1, -1, -1, -1) state.pdims
758 let getpagey pageno
= fst
(getpageyh pageno
);;
761 let sh = sh - state.hscrollh
in
762 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
763 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
765 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
766 let ips = calcips h in
768 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
772 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
774 prev
, pdims
, pdimno
, 0
776 let dy = dy + yinc in
777 let py = py + yinc in
778 if pageno
= state.pagecount
|| dy >= sh
783 if py + h <= vy - yinc
785 let py = py + h + ips in
786 let dy = max
0 (py - y) in
795 let pagey = vy - py in
796 let pagevh = h - pagey in
797 let pagevh = min
(sh - dy) pagevh in
798 let off = if yinc > 0 then py - vy else 0 in
799 let py = py + h + ips in
802 if state.w
< conf.winw
- state.scrollw
803 then (conf.winw
- state.scrollw
- state.w
) / 2
806 let dispx = xoff + state.x
in
812 let lw = w
- pagex in
813 min
lw (conf.winw
- state.scrollw
)
821 ; pagey = pagey + off
823 ; pagevh = pagevh - off
825 ; pagedispy
= dy + off
828 let accu = e :: accu in
837 if state.invalidated
= 0
856 let y = state.y + incr
in
858 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
862 let getopaque pageno
=
863 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
864 with Not_found
-> None
867 let putopaque pageno opaque
=
868 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
872 let tilex = l
.pagex mod conf.tilew
in
873 let tiley = l
.pagey mod conf.tileh
in
875 let col = l
.pagex / conf.tilew
in
876 let row = l
.pagey / conf.tileh
in
879 let a = l
.pagew
- l
.pagex in
880 let b = conf.winw
- state.scrollw
in
884 let rec rowloop row y0 dispy
h =
888 let dh = conf.tileh
- y0
in
890 let rec colloop col x0
dispx w
=
894 let dw = conf.tilew
- x0
in
897 f col row dispx dispy x0 y0
dw dh;
898 colloop (col+1) 0 (dispx+dw) (w
-dw)
901 colloop col tilex l
.pagedispx
vw;
902 rowloop (row+1) 0 (dispy
+dh) (h-dh)
906 then rowloop row tiley l
.pagedispy vh
;
909 let gettileopaque l
col row =
911 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
913 try Some
(Hashtbl.find
state.tilemap
key)
914 with Not_found
-> None
917 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
918 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
919 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
922 let drawtiles l color
=
924 let f col row x
y tilex tiley w
h =
925 match gettileopaque l
col row with
926 | Some
(opaque
, _
, t
) ->
927 let params = x
, y, w
, h, tilex, tiley in
931 GlFunc.blend_func `zero `one_minus_src_color
;
933 drawtile
params opaque
;
935 then Gl.disable `blend
;
938 let s = Printf.sprintf
942 let w = measurestr
fstate.fontsize
s in
943 GlMisc.push_attrib
[`current
];
944 GlDraw.color
(0.0, 0.0, 0.0);
946 (float (x
-2), float (y-2))
947 (float (x
+2) +. w, float (y + fstate.fontsize
+ 2));
948 GlDraw.color
(1.0, 1.0, 1.0);
949 drawstring fstate.fontsize x
(y + fstate.fontsize
- 1) s;
950 GlMisc.pop_attrib
();
955 let lw = conf.winw
- state.scrollw
- x
in
958 let lh = conf.winh
- y in
961 Gl.enable `texture_2d
;
962 begin match state.texid
with
964 GlTex.bind_texture `texture_2d id
;
968 and y1
= float (y+h) in
970 let tw = float w /. 64.0
971 and th
= float h /. 64.0 in
972 let tx0 = float tilex /. 64.0
973 and ty0
= float tiley /. 64.0 in
975 and ty1
= ty0
+. th
in
976 GlDraw.begins `quads
;
977 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
978 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
979 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
980 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
983 Gl.disable `texture_2d
;
985 GlDraw.color
(1.0, 1.0, 1.0);
988 (float (x
+w), float (y+h));
990 if w > 128 && h > fstate.fontsize
+ 10
992 GlDraw.color
(0.0, 0.0, 0.0);
995 then (col*conf.tilew
, row*conf.tileh
)
998 drawstring2 fstate.fontsize x
y "Loading %d [%d,%d]" l
.pageno
c r;
1005 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1007 let tilevisible1 l x
y =
1009 and ax1
= l
.pagex + l
.pagevw
1011 and ay1
= l
.pagey + l
.pagevh in
1015 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1016 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1018 let rx0 = max
ax0 bx0
1019 and ry0
= max ay0 by0
1020 and rx1
= min ax1
bx1
1021 and ry1
= min ay1 by1
in
1023 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1024 nonemptyintersection
1027 let tilevisible layout n x
y =
1028 let rec findpageinlayout = function
1029 | l
:: _
when l
.pageno
= n -> tilevisible1 l x
y
1030 | _
:: rest
-> findpageinlayout rest
1033 findpageinlayout layout
1036 let tileready l x
y =
1037 tilevisible1 l x
y &&
1038 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
1041 let tilepage n p
layout =
1042 let rec loop = function
1046 let f col row _ _ _ _ _ _
=
1047 if state.currently
= Idle
1049 match gettileopaque l
col row with
1052 let x = col*conf.tilew
1053 and y = row*conf.tileh
in
1055 let w = l
.pagew
- x in
1059 let h = l
.pageh
- y in
1071 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1072 conf.tilew
, conf.tileh
1081 if state.invalidated
= 0 then loop layout;
1084 let preloadlayout visiblepages
=
1085 let presentation = conf.presentation in
1086 let interpagespace = conf.interpagespace in
1087 let maxy = state.maxy in
1088 conf.presentation <- false;
1089 conf.interpagespace <- 0;
1090 state.maxy <- calcheight ();
1092 match visiblepages
with
1094 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1096 let y = if y < conf.winh
then 0 else y - conf.winh
in
1097 let h = state.y - y + conf.winh
*3 in
1098 let pages = layout y h in
1099 conf.presentation <- presentation;
1100 conf.interpagespace <- interpagespace;
1106 let rec loop pages =
1107 if state.currently
!= Idle
1112 begin match getopaque l
.pageno
with
1114 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1115 state.currently
<- Loading
(l
, state.gen
);
1117 tilepage l
.pageno opaque
pages;
1122 if state.invalidated
= 0 then loop pages
1127 if conf.preload && state.currently
= Idle
1128 then load (preloadlayout pages);
1131 let layoutready layout =
1132 let rec fold all ls
=
1133 all
&& match ls
with
1135 let seen = ref false in
1136 let allvisible = ref true in
1137 let foo col row _ _ _ _ _ _
=
1139 allvisible := !allvisible &&
1140 begin match gettileopaque l
col row with
1146 fold (!seen && !allvisible) rest
1149 let alltilesvisible = fold true layout in
1154 let y = bound y 0 state.maxy in
1155 let y, layout, proceed
=
1156 match conf.maxwait
with
1158 begin match state.throttle
with
1160 let layout = layout y conf.winh
in
1161 let ready = layoutready layout in
1165 state.throttle
<- Some
(layout, y, now ());
1167 else G.postRedisplay "gotoy showall (None)";
1169 | Some
(_
, _
, started
) ->
1170 let dt = now () -. started
in
1173 state.throttle
<- None
;
1174 let layout = layout y conf.winh
in
1176 G.postRedisplay "maxwait";
1183 let layout = layout y conf.winh
in
1184 if true || layoutready layout
1185 then G.postRedisplay "gotoy ready";
1191 state.layout <- layout;
1192 begin match state.mode
with
1193 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1194 if not
(pagevisible layout pageno
)
1196 match state.layout with
1199 state.mode
<- Birdseye
(
1200 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1209 let conttiling pageno opaque
=
1210 tilepage pageno opaque
1211 (if conf.preload then preloadlayout state.layout else state.layout)
1214 let gotoy_and_clear_text y =
1216 if not
conf.verbose
then state.text <- "";
1220 match state.layout with
1222 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1225 let getanchory (n, top
) =
1226 let y, h = getpageyh n in
1227 y + (truncate
(top
*. float h));
1230 let gotoanchor anchor
=
1231 gotoy (getanchory anchor
);
1235 cbput state.hists
.nav
(getanchor ());
1239 let anchor = cbgetc state.hists
.nav dir
in
1243 let gotopage n top
=
1244 let y, h = getpageyh n in
1245 gotoy_and_clear_text (y + (truncate
(top
*. float h)));
1248 let gotopage1 n top
=
1249 let y = getpagey n in
1250 gotoy_and_clear_text (y + top
);
1258 state.invalidated
<- state.invalidated
+ 1;
1261 let writeopen path password
=
1262 writecmd state.csock
("open " ^ path ^
"\000" ^ password ^
"\000");
1265 let opendoc path password
=
1268 state.password
<- password
;
1269 state.gen
<- state.gen
+ 1;
1270 state.docinfo
<- [];
1272 setaalevel
conf.aalevel
;
1273 writeopen path password
;
1274 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1275 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1279 let c = c *. conf.colorscale
in
1283 let scalecolor2 (r, g
, b) =
1284 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1288 state.maxy <- calcheight ();
1290 if state.w <= conf.winw
- state.scrollw
1294 match state.mode
with
1295 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1296 let y, h = getpageyh pageno
in
1297 let top = (conf.winh
- h) / 2 in
1298 gotoy (max
0 (y - top))
1299 | _
-> gotoanchor state.anchor
1303 let firsttime = ref true in
1305 GlDraw.viewport
0 0 w h;
1306 if state.invalidated
= 0 && not
!firsttime
1307 then state.anchor <- getanchor ();
1311 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1315 setfontsize fstate.fontsize
;
1316 GlMat.mode `modelview
;
1317 GlMat.load_identity
();
1319 GlMat.mode `projection
;
1320 GlMat.load_identity
();
1321 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1322 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1323 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1326 wcmd "geometry" [`i
w; `i
h];
1330 let len = String.length
state.text in
1333 match state.mode
with
1334 | View
-> state.hscrollh
1339 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1340 (x+.w, float (conf.winh
- hscrollh))
1343 let w = float (conf.winw
- state.scrollw
- 1) in
1344 if state.progress
>= 0.0 && state.progress
< 1.0
1346 GlDraw.color
(0.3, 0.3, 0.3);
1347 let w1 = w *. state.progress
in
1349 GlDraw.color
(0.0, 0.0, 0.0);
1353 GlDraw.color
(0.0, 0.0, 0.0);
1357 GlDraw.color
(1.0, 1.0, 1.0);
1358 drawstring fstate.fontsize
1359 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1362 match state.mode
with
1363 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1367 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1369 Printf.sprintf
"%s%s_" prefix
text
1378 if not
(istextentry state.mode
)
1380 let s1 = "(press 'e' to review error messasges)" in
1381 if String.length
s > 0 then s ^
" " ^
s1 else s1
1386 if String.length
s > 0
1391 state.text <- Printf.sprintf
"%c%s" c s;
1392 G.postRedisplay "showtext";
1396 let len = Queue.length
state.tilelru
in
1398 if state.memused
<= conf.memlimit
1403 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1404 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1405 let (_
, pw
, ph
, _
) = getpagedim n in
1408 && colorspace
= conf.colorspace
1409 && angle
= conf.angle
1414 match state.throttle
with
1417 then preloadlayout state.layout
1419 | Some
(layout, _
, _
) ->
1422 let x = col*conf.tilew
1423 and y = row*conf.tileh
in
1424 tilevisible layout n x y
1426 then Queue.push lruitem
state.tilelru
1428 wcmd "freetile" [`
s p
];
1429 state.memused
<- state.memused
- s;
1430 state.uioh#infochanged Memused
;
1431 Hashtbl.remove
state.tilemap k
;
1440 Queue.iter
(fun (k
, p
, s) ->
1441 wcmd "freetile" [`
s p
];
1442 state.memused
<- state.memused
- s;
1443 state.uioh#infochanged Memused
;
1444 Hashtbl.remove
state.tilemap k
;
1446 Queue.clear
state.tilelru
;
1450 let logcurrently = function
1451 | Idle
-> dolog "Idle"
1452 | Loading
(l
, gen
) ->
1453 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1454 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1456 "Tiling %d[%d,%d] page=%s cs=%s angle"
1457 l
.pageno
col row pageopaque
1458 (colorspace_to_string colorspace
)
1460 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1461 angle gen
conf.angle
state.gen
1463 conf.tilew
conf.tileh
1470 (* dolog "%S" cmds; *)
1473 try String.index cmds ' '
1474 with Not_found
-> -1
1479 let l = String.length cmds
in
1480 let op = String.sub cmds
0 spacepos in
1482 if l - spacepos < 2 then ""
1483 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1488 state.uioh#infochanged Pdim
;
1492 state.rects
<- state.rects1
;
1493 G.postRedisplay "clearrects";
1497 try Scanf.sscanf args
"%u" (fun n -> n)
1499 dolog "error processing 'continue' %S: %s"
1500 cmds
(Printexc.to_string exn
);
1503 state.pagecount
<- n;
1504 state.invalidated
<- state.invalidated
- 1;
1505 begin match state.currently
with
1507 state.currently
<- Idle
;
1508 state.outlines
<- Array.of_list
(List.rev
l)
1511 if state.invalidated
= 0
1513 if conf.maxwait
= None
1514 then G.postRedisplay "continue";
1517 Glut.setWindowTitle args
1524 then showtext ' ' args
1527 let progress, text =
1529 Scanf.sscanf args
"%f %n"
1531 f, String.sub args pos
(String.length args
- pos
))
1533 dolog "error processing 'progress' %S: %s"
1534 cmds
(Printexc.to_string exn
);
1538 state.progress <- progress;
1539 G.postRedisplay "progress"
1542 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1544 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1545 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1546 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1548 dolog "error processing 'firstmatch' %S: %s"
1549 cmds
(Printexc.to_string exn
);
1552 let y = (getpagey pageno) + truncate y0
in
1555 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)]
1558 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1560 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1561 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1562 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1564 dolog "error processing 'match' %S: %s"
1565 cmds
(Printexc.to_string exn
);
1569 (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) :: state.rects1
1574 Scanf.sscanf args
"%s %f" (fun p t
-> p
, t
)
1576 dolog "error processing 'page' %S: %s"
1577 cmds
(Printexc.to_string exn
);
1580 begin match state.currently
with
1581 | Loading
(l, gen
) ->
1582 vlog "page %d took %f sec" l.pageno t
;
1583 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1584 begin match state.throttle
with
1586 let preloadedpages =
1588 then preloadlayout state.layout
1593 Set.Make
(struct type t
= int let compare = (-) end) in
1595 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1596 IntSet.empty
preloadedpages
1599 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
1600 if not
(IntSet.mem
pageno set)
1602 wcmd "freepage" [`
s opaque
];
1608 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1611 state.currently
<- Idle
;
1614 tilepage l.pageno pageopaque state.layout;
1616 load preloadedpages;
1617 if pagevisible state.layout l.pageno
1618 && layoutready state.layout
1619 then G.postRedisplay "page";
1622 | Some
(layout, _
, _
) ->
1623 state.currently
<- Idle
;
1624 tilepage l.pageno pageopaque layout;
1629 dolog "Inconsistent loading state";
1630 logcurrently state.currently
;
1635 let (x, y, opaque
, size
, t
) =
1637 Scanf.sscanf args
"%u %u %s %u %f"
1638 (fun x y p size t
-> (x, y, p
, size
, t
))
1640 dolog "error processing 'tile' %S: %s"
1641 cmds
(Printexc.to_string exn
);
1644 begin match state.currently
with
1645 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1646 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1648 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1650 wcmd "freetile" [`
s opaque
];
1651 state.currently
<- Idle
;
1655 puttileopaque l col row gen cs angle opaque size t
;
1656 state.memused
<- state.memused
+ size
;
1657 state.uioh#infochanged Memused
;
1659 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1660 opaque
, size
) state.tilelru
;
1663 match state.throttle
with
1664 | None
-> state.layout
1665 | Some
(layout, _
, _
) -> layout
1668 state.currently
<- Idle
;
1670 && conf.colorspace
= cs
1671 && conf.angle
= angle
1672 && tilevisible layout l.pageno x y
1673 then conttiling l.pageno pageopaque;
1675 begin match state.throttle
with
1677 preload state.layout;
1679 && conf.colorspace
= cs
1680 && conf.angle
= angle
1681 && tilevisible state.layout l.pageno x y
1682 then G.postRedisplay "tile nothrottle";
1684 | Some
(layout, y, _
) ->
1685 let ready = layoutready layout in
1689 state.layout <- layout;
1690 state.throttle
<- None
;
1691 G.postRedisplay "throttle";
1698 dolog "Inconsistent tiling state";
1699 logcurrently state.currently
;
1706 Scanf.sscanf args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1708 dolog "error processing 'pdim' %S: %s"
1709 cmds
(Printexc.to_string exn
);
1712 state.uioh#infochanged Pdim
;
1713 state.pdims
<- pdim :: state.pdims
1716 let (l, n, t
, h, pos
) =
1718 Scanf.sscanf args
"%u %u %d %u %n"
1719 (fun l n t
h pos
-> l, n, t
, h, pos
)
1721 dolog "error processing 'o' %S: %s"
1722 cmds
(Printexc.to_string exn
);
1725 let s = String.sub args pos
(String.length args
- pos
) in
1726 let outline = (s, l, (n, float t
/. float h)) in
1727 begin match state.currently
with
1728 | Outlining outlines
->
1729 state.currently
<- Outlining
(outline :: outlines
)
1731 state.currently
<- Outlining
[outline]
1733 dolog "invalid outlining state";
1734 logcurrently currently
1738 state.docinfo
<- (1, args
) :: state.docinfo
1741 state.uioh#infochanged Docinfo
;
1742 state.docinfo
<- List.rev
state.docinfo
1745 dolog "unknown cmd `%S'" cmds
1749 if state.deadline
== nan
then state.deadline
<- now ();
1750 let rec loop delay
=
1753 then max
0.0 (state.deadline
-. now ())
1756 let r, _
, _
= Unix.select
[state.csock
; state.errfd
] [] [] timeout in
1759 begin match state.autoscroll
with
1760 | Some step
when step
!= 0 ->
1761 let y = state.y + step
in
1765 else if y >= state.maxy then 0 else y
1768 if state.mode
= View
1769 then state.text <- "";
1770 state.deadline
<- state.deadline
+. 0.005;
1773 state.deadline
<- state.deadline
+. delay
;
1777 let rec checkfds c = function
1779 | fd
:: rest
when fd
= state.csock
->
1780 let cmd = readcmd state.csock
in
1783 | fd
:: rest
when fd
= state.errfd
->
1784 let s = String.create
80 in
1785 let n = Unix.read fd
s 0 80 in
1786 if conf.redirectstderr
1788 Buffer.add_substring
state.errmsgs
s 0 n;
1789 state.newerrmsgs
<- true;
1790 Glut.postRedisplay ();
1793 prerr_string
(String.sub
s 0 n);
1799 failwith
"me? fail english? that's unpossible!"
1809 let action = function
1810 | HCprev
-> cbget cb ~
-1
1811 | HCnext
-> cbget cb
1
1812 | HCfirst
-> cbget cb ~
-(cb
.rc)
1813 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1814 and cancel
() = cb
.rc <- rc
1818 let search pattern forward
=
1819 if String.length pattern
> 0
1822 match state.layout with
1825 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1828 let b = makecmd "search"
1829 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
1831 Buffer.add_char
b '
,'
;
1832 Buffer.add_string
b pattern
;
1833 Buffer.add_char
b '
\000'
;
1836 writecmd state.csock
cmd;
1839 let intentry text key =
1840 let c = Char.unsafe_chr
key in
1843 let text = addchar text c in
1847 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1851 let textentry text key =
1852 let c = Char.unsafe_chr
key in
1854 | _
when key >= 32 && key < 127 ->
1855 let text = addchar text c in
1859 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
1863 let reqlayout angle proportional
=
1864 match state.throttle
with
1866 if state.invalidated
= 0 then state.anchor <- getanchor ();
1867 conf.angle
<- angle
mod 360;
1868 conf.proportional
<- proportional
;
1870 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
1874 let settrim trimmargins trimfuzz
=
1875 if state.invalidated
= 0 then state.anchor <- getanchor ();
1876 conf.trimmargins
<- trimmargins
;
1877 conf.trimfuzz
<- trimfuzz
;
1878 let x0, y0
, x1
, y1
= trimfuzz
in
1881 `
b conf.trimmargins
;
1887 Hashtbl.iter
(fun _ opaque
->
1888 wcmd "freepage" [`
s opaque
];
1890 Hashtbl.clear
state.pagemap
;
1894 match state.throttle
with
1896 let zoom = max
0.01 zoom in
1897 if zoom <> conf.zoom
1899 state.prevzoom
<- conf.zoom;
1902 then (state.x <- 0; 0.0)
1903 else float state.x /. float state.w
1906 reshape conf.winw
conf.winh
;
1909 let x = relx *. float state.w in
1910 state.x <- truncate
x;
1912 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
1915 | Some
(layout, y, started
) ->
1917 match conf.maxwait
with
1921 let dt = now () -. started
in
1929 let enterbirdseye () =
1930 let zoom = float conf.thumbw
/. float conf.winw
in
1931 let birdseyepageno =
1932 let cy = conf.winh
/ 2 in
1936 let rec fold best
= function
1939 let d = cy - (l.pagedispy
+ l.pagevh/2)
1940 and dbest
= cy - (best
.pagedispy
+ best
.pagevh/2) in
1941 if abs
d < abs dbest
1948 state.mode
<- Birdseye
(
1949 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
1952 conf.presentation <- false;
1953 conf.interpagespace <- 10;
1954 conf.hlinks
<- false;
1956 state.mstate
<- Mnone
;
1957 conf.maxwait
<- None
;
1958 Glut.setCursor
Glut.CURSOR_INHERIT
;
1961 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1966 reshape conf.winw
conf.winh
;
1969 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
1971 conf.zoom <- c.zoom;
1972 conf.presentation <- c.presentation;
1973 conf.interpagespace <- c.interpagespace;
1974 conf.maxwait
<- c.maxwait
;
1975 conf.hlinks
<- c.hlinks
;
1979 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1982 reshape conf.winw
conf.winh
;
1983 state.anchor <- if goback
then anchor else (pageno, 0.0);
1986 let togglebirdseye () =
1987 match state.mode
with
1988 | Birdseye vals
-> leavebirdseye vals
true
1989 | View
-> enterbirdseye ()
1993 let upbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
1994 let pageno = max
0 (pageno - 1) in
1995 let rec loop = function
1996 | [] -> gotopage1 pageno 0
1997 | l :: _
when l.pageno = pageno ->
1998 if l.pagedispy
>= 0 && l.pagey = 0
1999 then G.postRedisplay "upbirdseye"
2000 else gotopage1 pageno 0
2001 | _
:: rest
-> loop rest
2004 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2007 let downbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
2008 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
2009 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2010 let rec loop = function
2012 let y, h = getpageyh pageno in
2013 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2015 | l :: _
when l.pageno = pageno ->
2016 if l.pagevh != l.pageh
2017 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2018 else G.postRedisplay "downbirdseye"
2019 | _
:: rest
-> loop rest
2024 let optentry mode _
key =
2025 let btos b = if b then "on" else "off" in
2026 let c = Char.unsafe_chr
key in
2030 try conf.scrollstep
<- int_of_string
s with exc
->
2031 state.text <- Printf.sprintf
"bad integer `%s': %s"
2032 s (Printexc.to_string exc
)
2034 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2039 conf.autoscrollstep
<- int_of_string
s;
2040 if state.autoscroll
<> None
2041 then state.autoscroll
<- Some
conf.autoscrollstep
2043 state.text <- Printf.sprintf
"bad integer `%s': %s"
2044 s (Printexc.to_string exc
)
2046 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2051 let zoom = float (int_of_string
s) /. 100.0 in
2054 state.text <- Printf.sprintf
"bad integer `%s': %s"
2055 s (Printexc.to_string exc
)
2057 TEswitch
("zoom: ", "", None
, intentry, ondone)
2062 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2064 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2065 begin match mode
with
2067 leavebirdseye beye
false;
2072 state.text <- Printf.sprintf
"bad integer `%s': %s"
2073 s (Printexc.to_string exc
)
2075 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2080 Some
(int_of_string
s)
2082 state.text <- Printf.sprintf
"bad integer `%s': %s"
2083 s (Printexc.to_string exc
);
2086 | Some angle
-> reqlayout angle
conf.proportional
2089 TEswitch
("rotation: ", "", None
, intentry, ondone)
2092 conf.icase
<- not
conf.icase
;
2093 TEdone
("case insensitive search " ^
(btos conf.icase
))
2096 conf.preload <- not
conf.preload;
2098 TEdone
("preload " ^
(btos conf.preload))
2101 conf.verbose
<- not
conf.verbose
;
2102 TEdone
("verbose " ^
(btos conf.verbose
))
2105 conf.debug
<- not
conf.debug
;
2106 TEdone
("debug " ^
(btos conf.debug
))
2109 conf.maxhfit
<- not
conf.maxhfit
;
2111 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2112 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2115 conf.crophack
<- not
conf.crophack
;
2116 TEdone
("crophack " ^
btos conf.crophack
)
2120 match conf.maxwait
with
2122 conf.maxwait
<- Some infinity
;
2123 "always wait for page to complete"
2125 conf.maxwait
<- None
;
2126 "show placeholder if page is not ready"
2131 conf.underinfo
<- not
conf.underinfo
;
2132 TEdone
("underinfo " ^
btos conf.underinfo
)
2135 conf.savebmarks
<- not
conf.savebmarks
;
2136 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2142 match state.layout with
2147 conf.interpagespace <- int_of_string
s;
2148 state.maxy <- calcheight ();
2149 let y = getpagey pageno in
2152 state.text <- Printf.sprintf
"bad integer `%s': %s"
2153 s (Printexc.to_string exc
)
2155 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2158 reqlayout conf.angle
(not
conf.proportional
);
2159 TEdone
("proportional display " ^
btos conf.proportional
)
2162 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2163 TEdone
("trim margins " ^
btos conf.trimmargins
)
2166 conf.invert
<- not
conf.invert
;
2167 TEdone
("invert colors " ^
btos conf.invert
)
2170 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2174 class type lvsource
= object
2175 method getitemcount
: int
2176 method getitem
: int -> (string * int)
2177 method hasaction
: int -> bool
2186 method getactive
: int
2187 method getfirst
: int
2188 method getqsearch
: string
2189 method setqsearch
: string -> unit
2193 class virtual lvsourcebase
= object
2194 val mutable m_active
= 0
2195 val mutable m_first
= 0
2196 val mutable m_qsearch
= ""
2197 val mutable m_pan
= 0
2198 method getactive
= m_active
2199 method getfirst
= m_first
2200 method getqsearch
= m_qsearch
2201 method getpan
= m_pan
2202 method setqsearch
s = m_qsearch
<- s
2205 let textentryspecial key = function
2206 | ((c, _
, (Some
(action, _
) as onhist), onkey
, ondone), mode
) ->
2209 | Glut.KEY_UP
-> action HCprev
2210 | Glut.KEY_DOWN
-> action HCnext
2211 | Glut.KEY_HOME
-> action HCfirst
2212 | Glut.KEY_END
-> action HClast
2215 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2216 G.postRedisplay "special textentry";
2220 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2222 state.mode
<- Textentry
(te
, onleave
);
2225 G.postRedisplay "textentrykeyboard enttext";
2227 match Char.unsafe_chr
key with
2228 | '
\008'
-> (* backspace *)
2229 let len = String.length
text in
2233 G.postRedisplay "textentrykeyboard after cancel";
2236 let s = String.sub
text 0 (len - 1) in
2237 enttext (c, s, opthist
, onkey
, ondone)
2243 G.postRedisplay "textentrykeyboard after confirm"
2245 | '
\007'
(* ctrl-g *)
2246 | '
\027'
-> (* escape *)
2247 if String.length
text = 0
2249 begin match opthist
with
2251 | Some
(_
, onhistcancel
) -> onhistcancel
()
2255 G.postRedisplay "textentrykeyboard after cancel2"
2258 enttext (c, "", opthist
, onkey
, ondone)
2261 | '
\127'
-> () (* delete *)
2264 begin match onkey
text key with
2268 G.postRedisplay "textentrykeyboard after confirm2";
2271 enttext (c, text, opthist
, onkey
, ondone);
2276 G.postRedisplay "textentrykeyboard after cancel3"
2279 state.mode
<- Textentry
(te
, onleave
);
2280 G.postRedisplay "textentrykeyboard switch";
2284 let firstof first active
=
2285 if first
> active
|| abs
(first
- active
) > fstate.maxrows
- 1
2286 then max
0 (active
- (fstate.maxrows
/2))
2290 let calcfirst first active
=
2293 let rows = active
- first
in
2294 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2298 let scrollph y maxy =
2299 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2300 let sh = float conf.winh
/. sh in
2301 let sh = max
sh (float conf.scrollh
) in
2306 else float y /. float maxy
2308 let position = (float conf.winh
-. sh) *. percent in
2311 if position +. sh > float conf.winh
2312 then float conf.winh
-. sh
2318 let coe s = (s :> uioh
);;
2320 class listview ~
(source
:lvsource
) ~trusted
=
2322 val m_pan
= source#getpan
2323 val m_first
= source#getfirst
2324 val m_active
= source#getactive
2325 val m_qsearch
= source#getqsearch
2326 val m_prev_uioh
= state.uioh
2328 method private elemunder
y =
2329 let n = y / (fstate.fontsize
+1) in
2330 if m_first
+ n < source#getitemcount
2332 if source#hasaction
(m_first
+ n)
2333 then Some
(m_first
+ n)
2340 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2341 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2342 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2343 GlDraw.color
(1., 1., 1.);
2344 Gl.enable `texture_2d
;
2345 let fs = fstate.fontsize
in
2347 let ww = fstate.wwidth
in
2348 let tabw = 30.0*.ww in
2350 if (row - m_first
) * nfs > conf.winh
2353 if row >= 0 && row < source#getitemcount
2355 let (s, level
) = source#getitem
row in
2356 let y = (row - m_first
) * nfs in
2357 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2360 Gl.disable `texture_2d
;
2361 GlDraw.polygon_mode `both `line
;
2362 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2363 GlDraw.rect (1., float (y + 1))
2364 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2365 GlDraw.polygon_mode `both `fill
;
2366 GlDraw.color
(1., 1., 1.);
2367 Gl.enable `texture_2d
;
2370 let drawtabularstring s =
2371 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2374 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2377 let len = String.length
s - tabpos - 1 in
2378 let s1 = String.sub
s 0 tabpos
2379 and s2
= String.sub
s (tabpos + 1) len in
2380 let nx = drawstr x s1 in
2382 let x = x +. (max
tabw sw) in
2389 let _ = drawtabularstring s in
2396 Gl.disable `texture_2d
;
2398 method updownlevel incr
=
2399 let len = source#getitemcount
in
2400 let _, curlevel
= source#getitem m_active
in
2402 if i
= len then i
-1 else if i
= -1 then 0 else
2403 let _, l = source#getitem i
in
2404 if l != curlevel
then i
else flow (i
+incr
)
2406 let active = flow m_active
in
2407 let first = calcfirst m_first
active in
2408 G.postRedisplay "special outline updownlevel";
2409 {< m_active
= active; m_first
= first >}
2411 method private key1
key =
2412 let set active first qsearch
=
2413 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2415 let search active pattern incr
=
2418 if n >= 0 && n < source#getitemcount
2420 let s, _ = source#getitem
n in
2422 (try ignore
(Str.search_forward
re s 0); true
2423 with Not_found
-> false)
2425 else loop (n + incr
)
2432 let re = Str.regexp_case_fold pattern
in
2439 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2440 let incr = if key = 18 then -1 else 1 in
2442 match search (m_active
+ incr) m_qsearch
incr with
2444 state.text <- m_qsearch ^
" [not found]";
2447 state.text <- m_qsearch
;
2448 active, firstof m_first
active
2450 G.postRedisplay "listview ctrl-r/s";
2451 set active first m_qsearch
;
2453 | 8 -> (* backspace *)
2454 let len = String.length m_qsearch
in
2461 G.postRedisplay "listview empty qsearch";
2462 set m_active m_first
"";
2465 let qsearch = String.sub m_qsearch
0 (len - 1) in
2467 match search m_active
qsearch ~
-1 with
2469 state.text <- qsearch ^
" [not found]";
2472 state.text <- qsearch;
2473 active, firstof m_first
active
2475 G.postRedisplay "listview backspace qsearch";
2476 set active first qsearch
2479 | _ when key >= 32 && key < 127 ->
2480 let pattern = addchar m_qsearch
(Char.chr
key) in
2482 match search m_active
pattern 1 with
2484 state.text <- pattern ^
" [not found]";
2487 state.text <- pattern;
2488 active, firstof m_first
active
2490 G.postRedisplay "listview qsearch add";
2491 set active first pattern;
2493 | 27 -> (* escape *)
2495 if String.length m_qsearch
= 0
2497 G.postRedisplay "list view escape";
2500 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2502 | None
-> m_prev_uioh
2507 G.postRedisplay "list view kill qsearch";
2508 source#setqsearch
"";
2509 coe {< m_qsearch
= "" >}
2514 let self = {< m_qsearch
= "" >} in
2515 source#setqsearch
"";
2517 G.postRedisplay "listview enter";
2518 if m_active
>= 0 && m_active
< source#getitemcount
2520 source#exit
(coe self) false m_active m_first m_pan
"";
2523 source#exit
(coe self) true m_active m_first m_pan
"";
2526 begin match opt with
2527 | None
-> m_prev_uioh
2531 | 127 -> (* delete *)
2534 | _ -> dolog "unknown key %d" key; coe self
2536 method private special1
key =
2537 let itemcount = source#getitemcount
in
2538 let find start
incr =
2540 if i
= -1 || i
= itemcount
2543 if source#hasaction i
2545 else find (i
+ incr)
2550 let set active first =
2551 let first = bound first 0 (itemcount - fstate.maxrows
) in
2553 coe {< m_active
= active; m_first
= first >}
2556 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2558 let incr1 = if incr > 0 then 1 else -1 in
2559 if isvisible m_first m_active
2562 let next = m_active
+ incr in
2564 if next < 0 || next >= itemcount
2566 else find next incr1
2568 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2574 let first = m_first
+ incr in
2575 let first = bound first 0 (itemcount - 1) in
2577 let next = m_active
+ incr in
2578 let next = bound next 0 (itemcount - 1) in
2581 let active = if next = -1 then m_active
else next in
2584 let first = min
next m_first
in
2587 let first = m_first
+ incr in
2588 let first = bound first 0 (itemcount - 1) in
2590 let next = m_active
+ incr in
2591 let next = bound next 0 (itemcount - 1) in
2592 let next = find next incr1 in
2593 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2599 G.postRedisplay "listview navigate";
2602 begin match key with
2603 | Glut.KEY_UP
-> navigate ~
-1
2604 | Glut.KEY_DOWN
-> navigate 1
2605 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2606 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2610 G.postRedisplay "listview right";
2611 coe {< m_pan
= m_pan
- 1 >}
2615 G.postRedisplay "listview left";
2616 coe {< m_pan
= m_pan
+ 1 >}
2619 let active = find 0 1 in
2620 G.postRedisplay "listview home";
2624 let first = max
0 (itemcount - fstate.maxrows
) in
2625 let active = find (itemcount - 1) ~
-1 in
2626 G.postRedisplay "listview end";
2633 match state.mode
with
2634 | Textentry te
-> textentrykeyboard key te
; coe self
2635 | _ -> self#key1
key
2637 method special
key =
2638 match state.mode
with
2639 | Textentry te
-> textentryspecial key te
; coe self
2640 | _ -> self#special1
key
2642 method button button bstate
x y =
2645 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollbw
->
2646 G.postRedisplay "listview scroll";
2647 if bstate
= Glut.DOWN
2649 let _, position, sh = self#
scrollph in
2650 if y > truncate
position && y < truncate
(position +. sh)
2652 state.mstate
<- Mscrolly
;
2656 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2657 let first = truncate
(s *. float source#getitemcount
) in
2658 let first = min source#getitemcount
first in
2659 Some
(coe {< m_first
= first; m_active
= first >})
2661 state.mstate
<- Mnone
;
2664 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2665 begin match self#elemunder
y with
2667 G.postRedisplay "listview click";
2669 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
2673 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2674 let len = source#getitemcount
in
2676 if m_first
+ fstate.maxrows
>= len
2680 let first = m_first
+ (if n == 3 then -1 else 1) in
2681 bound first 0 (len - 1)
2683 G.postRedisplay "listview wheel";
2684 Some
(coe {< m_first
= first >})
2689 | None
-> m_prev_uioh
2693 match state.mstate
with
2695 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2696 let first = truncate
(s *. float source#getitemcount
) in
2697 let first = min source#getitemcount
first in
2698 G.postRedisplay "listview motion";
2699 coe {< m_first
= first; m_active
= first >}
2702 method pmotion
x y =
2703 if x < conf.winw
- conf.scrollbw
2706 match self#elemunder
y with
2707 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
2708 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
2712 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
2717 Glut.setCursor
Glut.CURSOR_INHERIT
;
2721 method infochanged
_ = ()
2723 method scrollpw
= (0, 0.0, 0.0)
2725 let nfs = fstate.fontsize
+ 1 in
2726 let y = m_first
* nfs in
2727 let itemcount = source#getitemcount
in
2728 let maxi = max
0 (itemcount - fstate.maxrows
) in
2729 let maxy = maxi * nfs in
2730 let p, h = scrollph y maxy in
2734 class outlinelistview ~source
=
2736 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
2740 | 14 -> (* ctrl-n *)
2741 source#narrow m_qsearch
;
2742 G.postRedisplay "outline ctrl-n";
2743 coe {< m_first
= 0; m_active
= 0 >}
2745 | 21 -> (* ctrl-u *)
2747 G.postRedisplay "outline ctrl-u";
2749 coe {< m_first
= 0; m_active
= 0 >}
2751 | 12 -> (* ctrl-l *)
2752 let first = m_active
- (fstate.maxrows
/ 2) in
2753 G.postRedisplay "outline ctrl-l";
2754 coe {< m_first
= first >}
2756 | 127 -> (* delete *)
2757 source#remove m_active
;
2758 G.postRedisplay "outline delete";
2759 let active = max
0 (m_active
-1) in
2760 coe {< m_first
= firstof m_first
active;
2761 m_active
= active >}
2763 | key -> super#
key key
2765 method special
key =
2766 let calcfirst first active =
2769 let rows = active - first in
2770 if rows > fstate.maxrows
then active - fstate.maxrows
else first
2774 let active = m_active
+ incr in
2775 let active = bound active 0 (source#getitemcount
- 1) in
2776 let first = calcfirst m_first
active in
2777 G.postRedisplay "special outline navigate";
2778 coe {< m_active
= active; m_first
= first >}
2781 | Glut.KEY_UP
-> navigate ~
-1
2782 | Glut.KEY_DOWN
-> navigate 1
2783 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2784 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2788 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2790 G.postRedisplay "special outline right";
2791 {< m_pan
= m_pan
+ 1 >}
2793 else self#updownlevel
1
2799 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2801 G.postRedisplay "special outline left";
2802 {< m_pan
= m_pan
- 1 >}
2804 else self#updownlevel ~
-1
2809 G.postRedisplay "special outline home";
2810 coe {< m_first
= 0; m_active
= 0 >}
2813 let active = source#getitemcount
- 1 in
2814 let first = max
0 (active - fstate.maxrows
) in
2815 G.postRedisplay "special outline end";
2816 coe {< m_active
= active; m_first
= first >}
2818 | _ -> super#special
key
2821 let outlinesource usebookmarks
=
2824 inherit lvsourcebase
2825 val mutable m_items
= empty
2826 val mutable m_orig_items
= empty
2827 val mutable m_prev_items
= empty
2828 val mutable m_narrow_pattern
= ""
2829 val mutable m_hadremovals
= false
2831 method getitemcount
=
2832 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
2835 if n == Array.length m_items
&& m_hadremovals
2837 ("[Confirm removal]", 0)
2839 let s, n, _ = m_items
.(n) in
2842 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
2843 ignore
(uioh
, first, pan
, qsearch);
2844 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
2846 if String.length m_narrow_pattern
= 0
2852 if not
confrimremoval
2854 let _, _, anchor = m_items
.(active) in
2859 state.bookmarks
<- Array.to_list m_items
;
2860 m_orig_items
<- m_items
;
2863 else m_items
<- items;
2866 method hasaction
_ = true
2869 if Array.length m_items
!= Array.length m_orig_items
2870 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
2873 method narrow
pattern =
2874 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
2878 let rec loop accu n =
2881 m_narrow_pattern
<- pattern;
2882 m_items
<- Array.of_list
accu
2885 let (s, _, _) as o = m_items
.(n) in
2887 if (try ignore
(Str.search_forward
re s 0); true
2888 with Not_found
-> false)
2894 loop [] (Array.length m_items
- 1)
2899 then Array.of_list
state.bookmarks
2902 m_items
<- m_orig_items
2907 if m
>= 0 && m
< Array.length m_items
2909 m_hadremovals
<- true;
2910 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
2911 let n = if n >= m
then n+1 else n in
2916 method reset
pageno items =
2917 m_hadremovals
<- false;
2918 if m_orig_items
== empty || m_prev_items
!= items
2920 m_orig_items
<- items;
2921 if String.length m_narrow_pattern
= 0
2922 then m_items
<- items;
2924 m_prev_items
<- items;
2926 let rec loop n best bestd
=
2927 if n = Array.length m_items
2930 let (_, _, (outlinepageno
, _)) = m_items
.(n) in
2931 let d = abs
(outlinepageno
- pageno) in
2934 else loop (n+1) best bestd
2939 m_first
<- firstof m_first
active
2943 let enterselector usebookmarks
=
2944 let source = outlinesource usebookmarks
in
2948 then Array.of_list
state.bookmarks
2951 if Array.length
outlines = 0
2953 showtext ' ' errmsg
;
2956 state.text <- source#greetmsg
;
2957 Glut.setCursor
Glut.CURSOR_INHERIT
;
2959 match state.layout with
2961 | {pageno=pageno} :: _ -> pageno
2963 source#reset
pageno outlines;
2964 state.uioh
<- coe (new outlinelistview ~
source);
2965 G.postRedisplay "enter selector";
2969 let enteroutlinemode =
2970 let f = enterselector false in
2971 fun ()-> f "Document has no outline";
2974 let enterbookmarkmode =
2975 let f = enterselector true in
2976 fun () -> f "Document has no bookmarks (yet)";
2979 let color_of_string s =
2980 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
2981 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
2985 let color_to_string (r, g
, b) =
2986 let r = truncate
(r *. 256.0)
2987 and g
= truncate
(g
*. 256.0)
2988 and b = truncate
(b *. 256.0) in
2989 Printf.sprintf
"%d/%d/%d" r g
b
2992 let irect_of_string s =
2993 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0,y0
,x1
,y1
))
2996 let irect_to_string (x0,y0
,x1
,y1
) =
2997 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3000 let makecheckers () =
3001 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3003 converted by Issac Trotts. July 25, 2002 *)
3004 let image_height = 64
3005 and image_width
= 64 in
3009 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3011 for i
= 0 to image_width
- 1 do
3012 for j
= 0 to image_height - 1 do
3013 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3014 (if (i
land 8 ) lxor (j
land 8) = 0
3015 then [|255;255;255|] else [|200;200;200|])
3020 let image = make_image () in
3021 let id = GlTex.gen_texture
() in
3022 GlTex.bind_texture `texture_2d
id;
3023 GlPix.store
(`unpack_alignment
1);
3024 GlTex.image2d
image;
3025 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3028 `mag_filter `nearest
;
3029 `min_filter `nearest
];
3033 let setcheckers enabled
=
3034 match state.texid
with
3036 if enabled
then state.texid
<- Some
(makecheckers ())
3041 GlTex.delete_texture texid
;
3042 state.texid
<- None
;
3046 let int_of_string_with_suffix s =
3047 let l = String.length
s in
3051 let suffix = Char.lowercase
s.[l-1] in
3053 | 'k'
-> String.sub
s 0 (l-1), 10
3054 | 'm'
-> String.sub
s 0 (l-1), 20
3055 | 'g'
-> String.sub
s 0 (l-1), 30
3059 let n = int_of_string
s1 in
3060 let m = n lsl shift
in
3062 then raise
(Failure
"value too large")
3066 let string_with_suffix_of_int n =
3074 if n land ((1 lsl 20) - 1) = 0
3077 if n land ((1 lsl 10) - 1) = 0
3084 let h = n mod 1000 in
3087 then string_of_int
h ^
s
3089 let s = Printf.sprintf
"_%03d%s" h s in
3096 let describe_location () =
3098 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3100 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3101 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3105 else (100. *. (float state.y /. float maxy))
3109 Printf.sprintf
"page %d of %d [%.2f%%]"
3110 (fn+1) state.pagecount
percent
3113 "pages %d-%d of %d [%.2f%%]"
3114 (fn+1) (ln
+1) state.pagecount
percent
3118 let btos b = if b then "\xe2\x88\x9a" else "" in
3119 let showextended = ref false in
3120 let leave mode
= function
3121 | Confirm
-> state.mode
<- mode
3122 | Cancel
-> state.mode
<- mode
in
3125 val mutable m_first_time
= true
3126 val mutable m_l
= []
3127 val mutable m_a
= [||]
3128 val mutable m_prev_uioh
= nouioh
3129 val mutable m_prev_mode
= View
3131 inherit lvsourcebase
3133 method reset prev_mode prev_uioh
=
3134 m_a
<- Array.of_list
(List.rev m_l
);
3136 m_prev_mode
<- prev_mode
;
3137 m_prev_uioh
<- prev_uioh
;
3141 if n >= Array.length m_a
3145 | _, _, _, Action
_ -> m_active
<- n
3149 m_first_time
<- false;
3152 method int name get
set =
3154 (name
, `
int get
, 1, Action
(
3157 try set (int_of_string
s)
3159 state.text <- Printf.sprintf
"bad integer `%s': %s"
3160 s (Printexc.to_string exn
)
3163 let te = name ^
": ", "", None
, intentry, ondone in
3164 state.mode
<- Textentry
(te, leave m_prev_mode
);
3168 method int_with_suffix name get
set =
3170 (name
, `intws get
, 1, Action
(
3173 try set (int_of_string_with_suffix s)
3175 state.text <- Printf.sprintf
"bad integer `%s': %s"
3176 s (Printexc.to_string exn
)
3180 name ^
": ", "", None
, intentry_with_suffix, ondone
3182 state.mode
<- Textentry
(te, leave m_prev_mode
);
3186 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3188 (name
, `
bool (btos, get
), offset
, Action
(
3195 method color name get
set =
3197 (name
, `color get
, 1, Action
(
3199 let invalid = (nan
, nan
, nan
) in
3202 try color_of_string s
3204 state.text <- Printf.sprintf
"bad color `%s': %s"
3205 s (Printexc.to_string exn
);
3211 let te = name ^
": ", "", None
, textentry, ondone in
3212 state.text <- color_to_string (get
());
3213 state.mode
<- Textentry
(te, leave m_prev_mode
);
3217 method string name get
set =
3219 (name
, `
string get
, 1, Action
(
3221 let ondone s = set s in
3222 let te = name ^
": ", "", None
, textentry, ondone in
3223 state.mode
<- Textentry
(te, leave m_prev_mode
);
3227 method colorspace name get
set =
3229 (name
, `
string get
, 1, Action
(
3232 let vals = [| "rgb"; "bgr"; "gray" |] in
3234 inherit lvsourcebase
3237 m_active
<- int_of_colorspace conf.colorspace
;
3240 method getitemcount
= Array.length
vals
3241 method getitem
n = (vals.(n), 0)
3242 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3243 ignore
(uioh
, first, pan
, qsearch);
3244 if not cancel
then set active;
3246 method hasaction
_ = true
3250 coe (new listview ~
source ~trusted
:true)
3253 method caption
s offset
=
3254 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3256 method caption2
s f offset
=
3257 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3259 method getitemcount
= Array.length m_a
3262 let tostr = function
3263 | `
int f -> string_of_int
(f ())
3264 | `intws
f -> string_with_suffix_of_int (f ())
3266 | `color
f -> color_to_string (f ())
3267 | `
bool (btos, f) -> btos (f ())
3270 let name, t
, offset
, _ = m_a
.(n) in
3271 ((let s = tostr t
in
3272 if String.length
s > 0
3273 then Printf.sprintf
"%s\t%s" name s
3277 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3281 m_qsearch
<- qsearch;
3283 match m_a
.(active) with
3284 | _, _, _, Action
f -> f uioh
3296 method hasaction
n =
3298 | _, _, _, Action
_ -> true
3302 let rec fillsrc prevmode prevuioh
=
3303 let sep () = src#caption
"" 0 in
3304 let colorp name get
set =
3306 (fun () -> color_to_string (get
()))
3309 let c = color_of_string v in
3312 state.text <- Printf.sprintf
"bad color `%s': %s"
3313 v (Printexc.to_string exn
);
3316 let oldmode = state.mode
in
3317 let birdseye = isbirdseye state.mode
in
3319 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3321 src#
bool "presentation mode"
3322 (fun () -> conf.presentation)
3324 conf.presentation <- v;
3325 state.anchor <- getanchor ();
3328 src#
bool "ignore case in searches"
3329 (fun () -> conf.icase
)
3330 (fun v -> conf.icase
<- v);
3333 (fun () -> conf.preload)
3334 (fun v -> conf.preload <- v);
3336 src#
bool "highlight links"
3337 (fun () -> conf.hlinks
)
3338 (fun v -> conf.hlinks
<- v);
3340 src#
bool "under info"
3341 (fun () -> conf.underinfo
)
3342 (fun v -> conf.underinfo
<- v);
3344 src#
bool "persistent bookmarks"
3345 (fun () -> conf.savebmarks
)
3346 (fun v -> conf.savebmarks
<- v);
3348 src#
bool "proportional display"
3349 (fun () -> conf.proportional
)
3350 (fun v -> reqlayout conf.angle
v);
3352 src#
bool "trim margins"
3353 (fun () -> conf.trimmargins
)
3354 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3356 src#
bool "persistent location"
3357 (fun () -> conf.jumpback
)
3358 (fun v -> conf.jumpback
<- v);
3361 src#
int "vertical margin"
3362 (fun () -> conf.interpagespace)
3364 conf.interpagespace <- n;
3366 match state.layout with
3371 state.maxy <- calcheight ();
3372 let y = getpagey pageno in
3377 (fun () -> conf.pagebias
)
3378 (fun v -> conf.pagebias
<- v);
3380 src#
int "scroll step"
3381 (fun () -> conf.scrollstep
)
3382 (fun n -> conf.scrollstep
<- n);
3384 src#
int "auto scroll step"
3386 match state.autoscroll
with
3388 | _ -> conf.autoscrollstep
)
3390 if state.autoscroll
<> None
3391 then state.autoscroll
<- Some
n;
3392 conf.autoscrollstep
<- n);
3395 (fun () -> truncate
(conf.zoom *. 100.))
3396 (fun v -> setzoom ((float v) /. 100.));
3399 (fun () -> conf.angle
)
3400 (fun v -> reqlayout v conf.proportional
);
3402 src#
int "scroll bar width"
3403 (fun () -> state.scrollw
)
3407 reshape conf.winw
conf.winh
;
3410 src#
int "scroll handle height"
3411 (fun () -> conf.scrollh
)
3412 (fun v -> conf.scrollh
<- v;);
3414 src#
int "thumbnail width"
3415 (fun () -> conf.thumbw
)
3417 conf.thumbw
<- min
4096 v;
3420 leavebirdseye beye
false;
3426 src#caption
"Presentation mode" 0;
3427 src#
bool "scrollbar visible"
3428 (fun () -> conf.scrollbarinpm
)
3430 if v != conf.scrollbarinpm
3432 conf.scrollbarinpm
<- v;
3433 if conf.presentation
3435 state.scrollw
<- if v then conf.scrollbw
else 0;
3436 reshape conf.winw
conf.winh
;
3442 src#caption
"Pixmap cache" 0;
3443 src#int_with_suffix
"size (advisory)"
3444 (fun () -> conf.memlimit
)
3445 (fun v -> conf.memlimit
<- v);
3448 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3449 (string_with_suffix_of_int state.memused
)
3450 (Hashtbl.length
state.tilemap
)) 1;
3453 src#caption
"Layout" 0;
3454 src#caption2
"Dimension"
3456 Printf.sprintf
"%dx%d (virtual %dx%d)"
3462 src#caption2
"Position" (fun () ->
3463 Printf.sprintf
"%dx%d" state.x state.y
3466 src#caption2
"Visible" (fun () -> describe_location ()) 1
3470 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3471 "Save these parameters as global defaults at exit"
3472 (fun () -> conf.bedefault
)
3473 (fun v -> conf.bedefault
<- v)
3477 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3478 src#
bool ~offset
:0 ~
btos "Extended parameters"
3479 (fun () -> !showextended)
3480 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3484 (fun () -> conf.checkers
)
3485 (fun v -> conf.checkers
<- v; setcheckers v);
3487 (fun () -> conf.verbose
)
3488 (fun v -> conf.verbose
<- v);
3489 src#
bool "invert colors"
3490 (fun () -> conf.invert
)
3491 (fun v -> conf.invert
<- v);
3493 (fun () -> conf.maxhfit
)
3494 (fun v -> conf.maxhfit
<- v);
3495 src#
bool "redirect stderr"
3496 (fun () -> conf.redirectstderr)
3497 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3498 src#
string "uri launcher"
3499 (fun () -> conf.urilauncher
)
3500 (fun v -> conf.urilauncher
<- v);
3501 src#
string "tile size"
3502 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3505 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3506 conf.tileh
<- max
64 w;
3507 conf.tilew
<- max
64 h;
3510 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3511 v (Printexc.to_string exn
));
3512 src#
int "texture count"
3513 (fun () -> conf.texcount
)
3516 wcmd "texcount" [`i
conf.texcount
];
3518 src#
int "slice height"
3519 (fun () -> conf.sliceheight
)
3521 conf.sliceheight
<- v;
3522 wcmd "sliceh" [`i
conf.sliceheight
];
3524 src#
int "anti-aliasing level"
3525 (fun () -> conf.aalevel
)
3527 conf.aalevel
<- bound v 0 8;
3528 state.anchor <- getanchor ();
3529 opendoc state.path
state.password
;
3531 src#
int "ui font size"
3532 (fun () -> fstate.fontsize
)
3533 (fun v -> setfontsize (bound v 5 100));
3534 colorp "background color"
3535 (fun () -> conf.bgcolor
)
3536 (fun v -> conf.bgcolor
<- v);
3537 src#
bool "crop hack"
3538 (fun () -> conf.crophack
)
3539 (fun v -> conf.crophack
<- v);
3540 src#
string "trim fuzz"
3541 (fun () -> irect_to_string conf.trimfuzz
)
3544 conf.trimfuzz
<- irect_of_string v;
3546 then settrim true conf.trimfuzz
;
3548 state.text <- Printf.sprintf
"bad irect `%s': %s"
3549 v (Printexc.to_string exn
)
3551 src#
string "throttle"
3553 match conf.maxwait
with
3554 | None
-> "show place holder if page is not ready"
3557 then "wait for page to fully render"
3559 "wait " ^ string_of_float
time
3560 ^
" seconds before showing placeholder"
3564 let f = float_of_string
v in
3566 then conf.maxwait
<- None
3567 else conf.maxwait
<- Some
f
3569 state.text <- Printf.sprintf
"bad time `%s': %s"
3570 v (Printexc.to_string exn
)
3572 src#colorspace
"color space"
3573 (fun () -> colorspace_to_string conf.colorspace
)
3575 conf.colorspace
<- colorspace_of_int v;
3582 src#caption
"Document" 0;
3583 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3587 src#caption
"Trimmed margins" 0;
3588 src#caption2
"Dimensions"
3589 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3592 src#reset prevmode prevuioh
;
3596 let prevmode = state.mode
3597 and prevuioh
= state.uioh in
3598 fillsrc prevmode prevuioh
;
3599 let source = (src :> lvsource
) in
3600 state.uioh <- coe (object (self)
3601 inherit listview ~
source ~trusted
:true as super
3602 val mutable m_prevmemused
= 0
3603 method infochanged
= function
3605 if m_prevmemused
!= state.memused
3607 m_prevmemused
<- state.memused
;
3608 G.postRedisplay "memusedchanged";
3610 | Pdim
-> G.postRedisplay "pdimchanged"
3611 | Docinfo
-> fillsrc prevmode prevuioh
3613 method special
key =
3614 if Glut.getModifiers
() land Glut.active_ctrl
= 0
3617 | Glut.KEY_LEFT
-> coe (self#updownlevel ~
-1)
3618 | Glut.KEY_RIGHT
-> coe (self#updownlevel
1)
3619 | _ -> super#special
key
3620 else super#special
key
3622 G.postRedisplay "info";
3628 inherit lvsourcebase
3629 method getitemcount
= Array.length
state.help
3631 let s, n, _ = state.help
.(n) in
3634 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3638 m_qsearch
<- qsearch;
3639 match state.help
.(active) with
3640 | _, _, Action
f -> Some
(f uioh)
3650 method hasaction
n =
3651 match state.help
.(n) with
3652 | _, _, Action
_ -> true
3659 state.uioh <- coe (new listview ~
source ~trusted
:true);
3660 G.postRedisplay "help";
3665 let re = Str.regexp
"[\r\n]" in
3667 inherit lvsourcebase
3668 val mutable m_items
= [||]
3670 method getitemcount
= 1 + Array.length m_items
3675 else m_items
.(n-1), 0
3677 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3682 then Buffer.clear
state.errmsgs
;
3683 m_qsearch
<- qsearch;
3690 method hasaction
n =
3694 state.newerrmsgs
<- false;
3695 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
3696 m_items
<- Array.of_list
l
3704 let source = (msgsource :> lvsource
) in
3705 state.uioh <- coe (object
3706 inherit listview ~
source ~trusted
:false as super
3709 then msgsource#reset
;
3712 G.postRedisplay "msgs";
3715 let quickbookmark ?title
() =
3716 match state.layout with
3722 let sec = Unix.gettimeofday
() in
3723 let tm = Unix.localtime
sec in
3724 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
3728 (tm.Unix.tm_year
+ 1900)
3731 | Some
title -> title
3734 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
3739 state.fullscreen
<- None
;
3740 Glut.reshapeWindow
w h;
3743 let viewkeyboard key =
3745 let mode = state.mode in
3746 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
3749 G.postRedisplay "view:enttext"
3751 let c = Char.chr
key in
3753 | '
\027'
| 'q'
-> (* escape *)
3754 begin match state.mstate
with
3756 state.mstate
<- Mnone
;
3757 Glut.setCursor
Glut.CURSOR_INHERIT
;
3758 G.postRedisplay "kill zoom rect";
3763 | '
\008'
-> (* backspace *)
3764 let y = getnav ~
-1 in
3765 gotoy_and_clear_text y
3773 G.postRedisplay "dehighlight";
3776 let ondone isforw
s =
3777 cbput state.hists
.pat
s;
3778 state.searchpattern
<- s;
3781 let s = String.create
1 in
3783 enttext (s, "", Some
(onhist state.hists
.pat
),
3784 textentry, ondone (c ='
/'
))
3786 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3787 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3788 setzoom (conf.zoom +. incr)
3793 try int_of_string
s with exc
->
3794 state.text <- Printf.sprintf
"bad integer `%s': %s"
3795 s (Printexc.to_string exc
);
3801 state.text <- "page bias is now " ^ string_of_int
n;
3804 enttext ("page bias: ", "", None
, intentry, ondone)
3806 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3807 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3808 setzoom (max
0.01 (conf.zoom -. decr))
3811 let ondone msg
= state.text <- msg
in
3813 "option [acfhilpstvAPRSZTI]: ", "", None
,
3814 optentry state.mode, ondone
3817 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3820 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3821 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
3825 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3831 try int_of_string
s with exc
->
3832 state.text <- Printf.sprintf
"bad integer `%s': %s"
3833 s (Printexc.to_string exc
);
3839 cbput state.hists
.pag
(string_of_int
n);
3840 gotoy_and_clear_text (getpagey (n + conf.pagebias
- 1))
3843 let pageentry text key =
3844 match Char.unsafe_chr
key with
3845 | 'g'
-> TEdone
text
3846 | _ -> intentry text key
3848 let text = "x" in text.[0] <- c;
3849 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
3852 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
3853 reshape conf.winw
conf.winh
;
3856 conf.hlinks
<- not
conf.hlinks
;
3857 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
3858 G.postRedisplay "toggle highlightlinks";
3861 begin match state.autoscroll
with
3863 conf.autoscrollstep
<- step
;
3864 state.autoscroll
<- None
3866 if conf.autoscrollstep
= 0
3867 then state.autoscroll
<- Some
1
3868 else state.autoscroll
<- Some
conf.autoscrollstep
3872 conf.presentation <- not
conf.presentation;
3873 if conf.presentation
3875 if not
conf.scrollbarinpm
3876 then state.scrollw
<- 0;
3879 state.scrollw
<- conf.scrollbw
;
3881 showtext ' '
("presentation mode " ^
3882 if conf.presentation then "on" else "off");
3883 state.anchor <- getanchor ();
3887 begin match state.fullscreen
with
3889 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
3892 state.fullscreen
<- None
;
3897 gotoy_and_clear_text 0
3900 gotopage1 (state.pagecount
- 1) 0
3903 search state.searchpattern
true
3906 search state.searchpattern
false
3909 begin match state.layout with
3912 gotoy_and_clear_text (getpagey l.pageno)
3916 begin match List.rev
state.layout with
3919 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
3920 gotoy_and_clear_text (getpagey pageno)
3923 | '
\127'
-> (* del *)
3924 begin match state.layout with
3927 let pageno = max
0 (l.pageno-1) in
3928 gotoy_and_clear_text (getpagey pageno)
3932 showtext ' '
(describe_location ());
3935 begin match state.layout with
3938 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
3943 enterbookmarkmode ()
3951 | '
e'
when conf.redirectstderr ->
3956 match state.layout with
3959 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
3963 enttext ("bookmark: ", "", None
, textentry, ondone)
3967 showtext ' '
"Quick bookmark added";
3970 begin match state.layout with
3972 let rect = getpdimrect
l.pagedimno
in
3976 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
3977 truncate
(1.2 *. (rect.(3) -. rect.(0))))
3979 (truncate
(rect.(1) -. rect.(0)),
3980 truncate
(rect.(3) -. rect.(0)))
3982 let w = truncate
((float w)*.conf.zoom)
3983 and h = truncate
((float h)*.conf.zoom) in
3986 state.anchor <- getanchor ();
3987 doreshape (w + state.scrollw
) (h + conf.interpagespace)
3989 G.postRedisplay "z";
3994 | '
\000'
-> (* ctrl-2 *)
3995 let maxw = getmaxw
() in
3997 then setzoom (maxw /. float conf.winw
)
4000 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
4004 bound (conf.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
4006 G.postRedisplay "brightness";
4009 begin match state.mode with
4010 | Birdseye beye
-> upbirdseye beye
4011 | _ -> gotoy (clamp (-conf.scrollstep
))
4015 begin match state.mode with
4016 | Birdseye beye
-> downbirdseye beye
4017 | _ -> gotoy (clamp conf.scrollstep
)
4021 state.anchor <- getanchor ();
4022 opendoc state.path
state.password
4024 | '
v'
when conf.debug
->
4027 match getopaque l.pageno with
4030 let x0, y0
, x1
, y1
= pagebbox opaque
in
4031 let a,b = float x0, float y0
in
4032 let c,d = float x1
, float y0
in
4033 let e,f = float x1
, float y1
in
4034 let h,j
= float x0, float y1
in
4035 let rect = (a,b,c,d,e,f,h,j
) in
4037 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4039 G.postRedisplay "v";
4042 vlog "huh? %d %c" key (Char.chr
key);
4045 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
4047 | 27 -> (* escape *)
4048 leavebirdseye beye
true
4050 | 12 -> (* ctrl-l *)
4051 let y, h = getpageyh pageno in
4052 let top = (conf.winh
- h) / 2 in
4053 gotoy (max
0 (y - top))
4056 leavebirdseye beye
false
4062 let keyboard ~
key ~
x ~
y =
4065 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
4066 then wcmd "interrupt" []
4067 else state.uioh <- state.uioh#
key key
4070 let birdseyespecial key ((conf, leftx
, _, hooverpageno
, anchor) as beye
) =
4072 | Glut.KEY_UP
-> upbirdseye beye
4073 | Glut.KEY_DOWN
-> downbirdseye beye
4075 | Glut.KEY_PAGE_UP
->
4076 begin match state.layout with
4080 state.mode <- Birdseye
(
4081 conf, leftx
, l.pageno, hooverpageno
, anchor
4083 gotopage1 l.pageno 0;
4086 let layout = layout (state.y-conf.winh
) conf.winh
in
4088 | [] -> gotoy (clamp (-conf.winh
))
4090 state.mode <- Birdseye
(
4091 conf, leftx
, l.pageno, hooverpageno
, anchor
4093 gotopage1 l.pageno 0
4096 | [] -> gotoy (clamp (-conf.winh
))
4099 | Glut.KEY_PAGE_DOWN
->
4100 begin match List.rev
state.layout with
4102 let layout = layout (state.y + conf.winh
) conf.winh
in
4103 begin match layout with
4105 let incr = l.pageh
- l.pagevh in
4110 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4112 G.postRedisplay "birdseye pagedown";
4114 else gotoy (clamp (incr + conf.interpagespace*2));
4118 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
4119 gotopage1 l.pageno 0;
4122 | [] -> gotoy (clamp conf.winh
)
4126 state.mode <- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
4130 let pageno = state.pagecount
- 1 in
4131 state.mode <- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
4132 if not
(pagevisible state.layout pageno)
4135 match List.rev
state.pdims
with
4137 | (_, _, h, _) :: _ -> h
4139 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4140 else G.postRedisplay "birdseye end";
4144 let setautoscrollspeed step goingdown
=
4145 let incr = max
1 ((abs step
) / 2) in
4146 let incr = if goingdown
then incr else -incr in
4147 let astep = step
+ incr in
4148 state.autoscroll
<- Some
astep;
4151 let special ~
key ~
x ~
y =
4154 state.uioh <- state.uioh#
special key
4159 match state.mode with
4160 | Textentry
_ -> scalecolor 0.4
4161 | View
-> scalecolor 1.0
4162 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4163 if l.pageno = hooverpageno
4166 if l.pageno = pageno
4172 begin match getopaque l.pageno with
4174 if tileready l l.pagex l.pagey
4176 let x = l.pagedispx
- l.pagex
4177 and y = l.pagedispy
- l.pagey in
4178 postprocess opaque
conf.hlinks
x y;
4184 let scrollindicator () =
4185 let sbw, ph
, sh = state.uioh#
scrollph in
4186 let sbh, pw
, sw = state.uioh#scrollpw
in
4188 GlDraw.color (0.64, 0.64, 0.64);
4190 (float (conf.winw
- sbw), 0.)
4191 (float conf.winw
, float conf.winh
)
4194 (0., float (conf.winh
- sbh))
4195 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4197 GlDraw.color (0.0, 0.0, 0.0);
4200 (float (conf.winw
- sbw), ph
)
4201 (float conf.winw
, ph
+. sh)
4204 (pw
, float (conf.winh
- sbh))
4205 (pw
+. sw, float conf.winh
)
4209 let pagetranslatepoint l x y =
4210 let dy = y - l.pagedispy
in
4211 let y = dy + l.pagey in
4212 let dx = x - l.pagedispx
in
4213 let x = dx + l.pagex in
4218 match state.mstate
with
4219 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4222 | Msel
((x0, y0
), (x1
, y1
)) ->
4223 let rec loop = function
4225 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
4226 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
4228 match getopaque l.pageno with
4230 let dx, dy = pagetranslatepoint l 0 0 in
4235 GlMat.mode `modelview
;
4237 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4238 seltext opaque
(x0, y0
, x1
, y1
);
4249 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4250 GlDraw.polygon_mode `both `fill
;
4251 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4253 (fun (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
4255 if l.pageno = pageno
4257 let dx = float (l.pagedispx
- l.pagex) in
4258 let dy = float (l.pagedispy
- l.pagey) in
4259 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4260 GlDraw.begins `quads
;
4262 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4263 GlDraw.vertex2
(x1
+.dx, y1
+.dy);
4264 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4265 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4276 GlClear.color (scalecolor2 conf.bgcolor
);
4277 GlClear.clear
[`
color];
4278 List.iter
drawpage state.layout;
4283 begin match state.mstate
with
4284 | Mzoomrect
((x0, y0
), (x1
, y1
)) ->
4286 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4287 GlDraw.polygon_mode `both `fill
;
4288 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4289 GlDraw.rect (float x0, float y0
)
4290 (float x1
, float y1
);
4295 Glut.swapBuffers
();
4299 let rec f = function
4301 begin match getopaque l.pageno with
4303 let x0 = l.pagedispx
in
4304 let x1 = x0 + l.pagevw in
4305 let y0 = l.pagedispy
in
4306 let y1 = y0 + l.pagevh in
4307 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4309 let px, py = pagetranslatepoint l x y in
4310 match whatsunder opaque
px py with
4322 let zoomrect x y x1 y1 =
4325 and y0 = min
y y1 in
4326 gotoy (state.y + y0);
4327 state.anchor <- getanchor ();
4328 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4330 if state.w < conf.winw
- state.scrollw
4331 then (conf.winw
- state.scrollw
- state.w) / 2
4334 state.x <- (state.x + margin) - x0;
4336 Glut.setCursor
Glut.CURSOR_INHERIT
;
4337 state.mstate
<- Mnone
;
4341 let winw = conf.winw - state.scrollw
- 1 in
4342 let s = float x /. float winw in
4343 let destx = truncate
(float (state.w + winw) *. s) in
4344 state.x <- winw - destx;
4345 gotoy_and_clear_text state.y;
4346 state.mstate
<- Mscrollx
;
4350 let s = float y /. float conf.winh
in
4351 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4352 gotoy_and_clear_text desty;
4353 state.mstate
<- Mscrolly
;
4356 let viewmouse button bstate
x y =
4358 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4359 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4361 match state.mstate
with
4362 | Mzoom
(oldn
, i
) ->
4370 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4372 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4374 let zoom = conf.zoom -. incr in
4376 state.mstate
<- Mzoom
(n, 0);
4378 state.mstate
<- Mzoom
(n, i
+1);
4380 else state.mstate
<- Mzoom
(n, 0)
4382 | _ -> state.mstate
<- Mzoom
(n, 0)
4385 match state.autoscroll
with
4386 | Some step
-> setautoscrollspeed step
(n=4)
4390 then -conf.scrollstep
4391 else conf.scrollstep
4393 let incr = incr * 2 in
4394 let y = clamp incr in
4395 gotoy_and_clear_text y
4398 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4399 if bstate
= Glut.DOWN
4401 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4402 state.mstate
<- Mpan
(x, y)
4405 state.mstate
<- Mnone
4407 | Glut.RIGHT_BUTTON
->
4408 if bstate
= Glut.DOWN
4410 Glut.setCursor
Glut.CURSOR_CYCLE
;
4412 state.mstate
<- Mzoomrect
(p, p)
4415 match state.mstate
with
4416 | Mzoomrect
((x0, y0), _) -> zoomrect x0 y0 x y
4418 Glut.setCursor
Glut.CURSOR_INHERIT
;
4419 state.mstate
<- Mnone
4422 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4423 if bstate
= Glut.DOWN
4425 let _, position, sh = state.uioh#
scrollph in
4426 if y > truncate
position && y < truncate
(position +. sh)
4427 then state.mstate
<- Mscrolly
4430 state.mstate
<- Mnone
4432 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4433 if bstate
= Glut.DOWN
4435 let _, position, sw = state.uioh#scrollpw
in
4436 if x > truncate
position && x < truncate
(position +. sw)
4437 then state.mstate
<- Mscrollx
4440 state.mstate
<- Mnone
4442 | Glut.LEFT_BUTTON
->
4443 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4444 begin match dest with
4445 | Ulinkgoto
(pageno, top) ->
4449 gotopage1 pageno top;
4455 | Unone
when bstate
= Glut.DOWN
->
4456 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4457 state.mstate
<- Mpan
(x, y);
4459 | Unone
| Utext
_ ->
4460 if bstate
= Glut.DOWN
4462 if conf.angle
mod 360 = 0
4464 state.mstate
<- Msel
((x, y), (x, y));
4465 G.postRedisplay "mouse select";
4469 match state.mstate
with
4472 | Mzoom
_ | Mscrollx
| Mscrolly
->
4473 state.mstate
<- Mnone
4475 | Mzoomrect
((x0, y0), _) ->
4479 Glut.setCursor
Glut.CURSOR_INHERIT
;
4480 state.mstate
<- Mnone
4482 | Msel
((_, y0), (_, y1)) ->
4484 if (y0 >= l.pagedispy
&& y0 <= (l.pagedispy
+ l.pagevh))
4485 || ((y1 >= l.pagedispy
&& y1 <= (l.pagedispy
+ l.pagevh)))
4487 match getopaque l.pageno with
4492 List.iter
f state.layout;
4493 copysel
""; (* ugly *)
4494 Glut.setCursor
Glut.CURSOR_INHERIT
;
4495 state.mstate
<- Mnone
;
4502 let birdseyemouse button bstate
x y
4503 (conf, leftx
, _, hooverpageno
, anchor) =
4505 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4506 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4507 let rec loop = function
4510 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4511 && x > margin && x < margin + l.pagew
4513 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4518 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4522 let mouse bstate button
x y =
4523 state.uioh <- state.uioh#button button bstate
x y;
4526 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4529 state.uioh <- state.uioh#
motion x y
4533 state.uioh <- state.uioh#
pmotion x y;
4540 begin match state.mode with
4541 | Textentry
textentry -> textentrykeyboard key textentry
4542 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4543 | View
-> viewkeyboard key
4547 method special key =
4548 begin match state.mode with
4549 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4553 birdseyespecial key vals
4555 | View
when key = Glut.KEY_F1
->
4559 begin match state.autoscroll
with
4560 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4561 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4566 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4568 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4570 if Glut.getModifiers
() land Glut.active_shift
!= 0
4571 then (setzoom state.prevzoom
; state.y)
4572 else clamp (-conf.winh
/2)
4573 else clamp (-conf.scrollstep
)
4575 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4577 if Glut.getModifiers
() land Glut.active_shift
!= 0
4578 then (setzoom state.prevzoom
; state.y)
4579 else clamp (conf.winh
/2)
4580 else clamp (conf.scrollstep
)
4581 | Glut.KEY_PAGE_UP
->
4582 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4584 match state.layout with
4586 | l :: _ -> state.y - l.pagey
4589 | Glut.KEY_PAGE_DOWN
->
4590 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4592 match List.rev
state.layout with
4594 | l :: _ -> getpagey l.pageno
4602 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
4604 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
4605 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
4606 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
4608 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
4610 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4611 then (conf.winw / 2)
4614 state.x <- state.x - dx;
4616 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
4618 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4619 then (conf.winw / 2)
4622 state.x <- state.x + dx;
4627 gotoy_and_clear_text y
4630 | Textentry
te -> textentryspecial key te
4634 method button button bstate
x y =
4635 begin match state.mode with
4636 | View
-> viewmouse button bstate
x y
4637 | Birdseye beye
-> birdseyemouse button bstate
x y beye
4643 begin match state.mode with
4645 | View
| Birdseye
_ ->
4646 match state.mstate
with
4647 | Mzoom
_ | Mnone
-> ()
4652 state.mstate
<- Mpan
(x, y);
4653 if conf.zoom > 1.0 then state.x <- state.x + dx;
4655 gotoy_and_clear_text y
4658 state.mstate
<- Msel
(a, (x, y));
4659 G.postRedisplay "motion select";
4662 let y = min
conf.winh
(max
0 y) in
4666 let x = min
conf.winw (max
0 x) in
4669 | Mzoomrect
(p0
, _) ->
4670 state.mstate
<- Mzoomrect
(p0
, (x, y));
4671 G.postRedisplay "motion zoomrect";
4675 method pmotion x y =
4676 begin match state.mode with
4677 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
4678 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4679 let rec loop = function
4681 if hooverpageno
!= -1
4683 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
4684 G.postRedisplay "pmotion birdseye no hoover";
4687 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4688 && x > margin && x < margin + l.pagew
4690 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
4691 G.postRedisplay "pmotion birdseye hoover";
4700 match state.mstate
with
4702 begin match getunder x y with
4703 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
4705 if conf.underinfo
then showtext 'u'
("ri: " ^
uri);
4706 Glut.setCursor
Glut.CURSOR_INFO
4707 | Ulinkgoto
(page
, _) ->
4709 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
4710 Glut.setCursor
Glut.CURSOR_INFO
4712 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
4713 Glut.setCursor
Glut.CURSOR_TEXT
4716 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
4721 method infochanged
_ = ()
4724 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
4725 let p, h = scrollph state.y maxy in
4729 let winw = conf.winw - state.scrollw
- 1 in
4730 let fwinw = float winw in
4732 let sw = fwinw /. float state.w in
4733 let sw = fwinw *. sw in
4734 max
sw (float conf.scrollh
)
4737 let f = state.w+winw in
4738 let r = float (winw-state.x) /. float f in
4739 let p = fwinw *. r in
4743 if position +. sw > fwinw
4744 then fwinw -. position
4747 state.hscrollh, position, sw
4754 let fontpath = ref "";;
4755 let wmclasshack = ref false;;
4758 let l = String.length
s in
4759 let b = Buffer.create
l in
4767 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
4768 | _ -> Sys.getenv
"HOME"
4771 ("Can not determine home directory location: " ^
4772 Printexc.to_string exn
);
4776 let config_of c attrs
=
4780 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
4781 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
4782 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
4783 | "preload" -> { c with preload = bool_of_string
v }
4784 | "page-bias" -> { c with pagebias
= int_of_string
v }
4785 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
4786 | "auto-scroll-step" ->
4787 { c with autoscrollstep
= max
0 (int_of_string
v) }
4788 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
4789 | "crop-hack" -> { c with crophack
= bool_of_string
v }
4792 match String.lowercase
v with
4793 | "true" -> Some infinity
4795 | f -> Some
(float_of_string
f)
4797 { c with maxwait
= mw}
4798 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
4799 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
4800 | "vertical-margin" ->
4801 { c with interpagespace = max
0 (int_of_string
v) }
4803 let zoom = float_of_string
v /. 100. in
4804 let zoom = max
zoom 0.0 in
4805 { c with zoom = zoom }
4806 | "presentation" -> { c with presentation = bool_of_string
v }
4807 | "rotation-angle" -> { c with angle
= int_of_string
v }
4808 | "width" -> { c with winw = max
20 (int_of_string
v) }
4809 | "height" -> { c with winh
= max
20 (int_of_string
v) }
4810 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
4811 | "proportional-display" -> { c with proportional
= bool_of_string
v }
4812 | "pixmap-cache-size" ->
4813 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
4814 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
4815 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
4816 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
4817 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
4818 | "background-color" -> { c with bgcolor
= color_of_string v }
4819 | "scrollbar-in-presentation" ->
4820 { c with scrollbarinpm
= bool_of_string
v }
4821 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
4822 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
4823 | "mupdf-memlimit" ->
4824 { c with mumemlimit
= max
1024 (int_of_string_with_suffix v) }
4825 | "checkers" -> { c with checkers
= bool_of_string
v }
4826 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
4827 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
4828 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
4829 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
4830 | "uri-launcher" -> { c with urilauncher
= unent v }
4831 | "color-space" -> { c with colorspace
= colorspace_of_string v }
4832 | "invert-colors" -> { c with invert
= bool_of_string
v }
4833 | "brightness" -> { c with colorscale
= float_of_string
v }
4834 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
4837 prerr_endline
("Error processing attribute (`" ^
4838 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
4841 let rec fold c = function
4844 let c = apply c k
v in
4850 let fromstring f pos
n v d =
4853 dolog "Error processing attribute (%S=%S) at %d\n%s"
4854 n v pos
(Printexc.to_string exn
)
4859 let bookmark_of attrs
=
4860 let rec fold title page rely
= function
4861 | ("title", v) :: rest
-> fold v page rely rest
4862 | ("page", v) :: rest
-> fold title v rely rest
4863 | ("rely", v) :: rest
-> fold title page
v rest
4864 | _ :: rest
-> fold title page rely rest
4865 | [] -> title, page
, rely
4867 fold "invalid" "0" "0" attrs
4871 let rec fold path page rely pan
= function
4872 | ("path", v) :: rest
-> fold v page rely pan rest
4873 | ("page", v) :: rest
-> fold path
v rely pan rest
4874 | ("rely", v) :: rest
-> fold path page
v pan rest
4875 | ("pan", v) :: rest
-> fold path page rely
v rest
4876 | _ :: rest
-> fold path page rely pan rest
4877 | [] -> path
, page
, rely
, pan
4879 fold "" "0" "0" "0" attrs
4882 let setconf dst
src =
4883 dst
.scrollbw
<- src.scrollbw
;
4884 dst
.scrollh
<- src.scrollh
;
4885 dst
.icase
<- src.icase
;
4886 dst
.preload <- src.preload;
4887 dst
.pagebias
<- src.pagebias
;
4888 dst
.verbose
<- src.verbose
;
4889 dst
.scrollstep
<- src.scrollstep
;
4890 dst
.maxhfit
<- src.maxhfit
;
4891 dst
.crophack
<- src.crophack
;
4892 dst
.autoscrollstep
<- src.autoscrollstep
;
4893 dst
.maxwait
<- src.maxwait
;
4894 dst
.hlinks
<- src.hlinks
;
4895 dst
.underinfo
<- src.underinfo
;
4896 dst
.interpagespace <- src.interpagespace;
4897 dst
.zoom <- src.zoom;
4898 dst
.presentation <- src.presentation;
4899 dst
.angle
<- src.angle
;
4900 dst
.winw <- src.winw;
4901 dst
.winh
<- src.winh
;
4902 dst
.savebmarks
<- src.savebmarks
;
4903 dst
.memlimit
<- src.memlimit
;
4904 dst
.proportional
<- src.proportional
;
4905 dst
.texcount
<- src.texcount
;
4906 dst
.sliceheight
<- src.sliceheight
;
4907 dst
.thumbw
<- src.thumbw
;
4908 dst
.jumpback
<- src.jumpback
;
4909 dst
.bgcolor
<- src.bgcolor
;
4910 dst
.scrollbarinpm
<- src.scrollbarinpm
;
4911 dst
.tilew
<- src.tilew
;
4912 dst
.tileh
<- src.tileh
;
4913 dst
.mumemlimit
<- src.mumemlimit
;
4914 dst
.checkers
<- src.checkers
;
4915 dst
.aalevel
<- src.aalevel
;
4916 dst
.trimmargins
<- src.trimmargins
;
4917 dst
.trimfuzz
<- src.trimfuzz
;
4918 dst
.urilauncher
<- src.urilauncher
;
4919 dst
.colorspace
<- src.colorspace
;
4920 dst
.invert
<- src.invert
;
4921 dst
.colorscale
<- src.colorscale
;
4922 dst
.redirectstderr <- src.redirectstderr;
4926 let h = Hashtbl.create
10 in
4927 let dc = { defconf with angle
= defconf.angle
} in
4928 let rec toplevel v t spos
_ =
4930 | Vdata
| Vcdata
| Vend
-> v
4931 | Vopen
("llppconfig", _, closed
) ->
4934 else { v with f = llppconfig
}
4936 error
"unexpected subelement at top level" s spos
4937 | Vclose
_ -> error
"unexpected close at top level" s spos
4939 and llppconfig
v t spos
_ =
4941 | Vdata
| Vcdata
-> v
4942 | Vend
-> error
"unexpected end of input in llppconfig" s spos
4943 | Vopen
("defaults", attrs
, closed
) ->
4944 let c = config_of dc attrs
in
4948 else { v with f = skip
"defaults" (fun () -> v) }
4950 | Vopen
("ui-font", attrs
, closed
) ->
4951 let rec getsize size
= function
4953 | ("size", v) :: rest
->
4955 fromstring int_of_string spos
"size" v fstate.fontsize
in
4957 | l -> getsize size l
4959 fstate.fontsize
<- getsize fstate.fontsize attrs
;
4962 else { v with f = uifont
(Buffer.create
10) }
4964 | Vopen
("doc", attrs
, closed
) ->
4965 let pathent, spage
, srely
, span
= doc_of attrs
in
4966 let path = unent pathent
4967 and pageno = fromstring int_of_string spos
"page" spage
0
4968 and rely
= fromstring float_of_string spos
"rely" srely
0.0
4969 and pan
= fromstring int_of_string spos
"pan" span
0 in
4970 let c = config_of dc attrs
in
4971 let anchor = (pageno, rely
) in
4973 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
4974 else { v with f = doc
path pan
anchor c [] }
4977 error
"unexpected subelement in llppconfig" s spos
4979 | Vclose
"llppconfig" -> { v with f = toplevel }
4980 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
4982 and uifont
b v t spos epos
=
4985 Buffer.add_substring
b s spos
(epos
- spos
);
4987 | Vopen
(_, _, _) ->
4988 error
"unexpected subelement in ui-font" s spos
4989 | Vclose
"ui-font" ->
4990 if String.length
!fontpath = 0
4991 then fontpath := Buffer.contents
b;
4992 { v with f = llppconfig
}
4993 | Vclose
_ -> error
"unexpected close in ui-font" s spos
4994 | Vend
-> error
"unexpected end of input in ui-font" s spos
4996 and doc
path pan
anchor c bookmarks
v t spos
_ =
4998 | Vdata
| Vcdata
-> v
4999 | Vend
-> error
"unexpected end of input in doc" s spos
5000 | Vopen
("bookmarks", _, closed
) ->
5003 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5005 | Vopen
(_, _, _) ->
5006 error
"unexpected subelement in doc" s spos
5009 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5010 { v with f = llppconfig
}
5012 | Vclose
_ -> error
"unexpected close in doc" s spos
5014 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5016 | Vdata
| Vcdata
-> v
5017 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5018 | Vopen
("item", attrs
, closed
) ->
5019 let titleent, spage
, srely
= bookmark_of attrs
in
5020 let page = fromstring int_of_string spos
"page" spage
0
5021 and rely
= fromstring float_of_string spos
"rely" srely
0.0 in
5022 let bookmarks = (unent titleent, 0, (page, rely
)) :: bookmarks in
5024 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5027 { v with f = skip
"item" f }
5030 error
"unexpected subelement in bookmarks" s spos
5032 | Vclose
"bookmarks" ->
5033 { v with f = doc
path pan
anchor c bookmarks }
5035 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5037 and skip tag
f v t spos
_ =
5039 | Vdata
| Vcdata
-> v
5041 error
("unexpected end of input in skipped " ^ tag
) s spos
5042 | Vopen
(tag'
, _, closed
) ->
5046 let f'
() = { v with f = skip tag
f } in
5047 { v with f = skip tag'
f'
}
5051 else error
("unexpected close in skipped " ^ tag
) s spos
5054 parse
{ f = toplevel; accu = () } s;
5060 let len = in_channel_length ic
in
5061 let s = String.create
len in
5062 really_input ic
s 0 len;
5065 | Parse_error
(msg
, s, pos
) ->
5066 let subs = subs s pos
in
5067 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5068 failwith
("parse error: " ^
s)
5071 failwith
("config load error: " ^
Printexc.to_string exn
)
5077 let dir = Filename.concat
home ".config" in
5078 if Sys.is_directory
dir then dir else home
5081 Filename.concat
dir "llpp.conf"
5084 let confpath = ref defconfpath;;
5087 if Sys.file_exists
!confpath
5090 (try Some
(open_in_bin
!confpath)
5093 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5094 Printexc.to_string exn
);
5103 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5104 Printexc.to_string exn
);
5110 f (Hashtbl.create
0, defconf)
5115 let pc, pb
, px, pa
=
5117 Hashtbl.find h (Filename.basename
state.path)
5118 with Not_found
-> dc, [], 0, (0, 0.0)
5122 state.bookmarks <- pb
;
5124 state.scrollw
<- conf.scrollbw
;
5126 then state.anchor <- pa
;
5127 cbput state.hists
.nav pa
;
5132 let add_attrs bb always
dc c =
5135 then Printf.bprintf bb
"\n %s='%b'" s a
5138 then Printf.bprintf bb
"\n %s='%d'" s a
5141 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5144 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5147 then Printf.bprintf bb
"\n %s='%f'" s a
5151 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5155 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5159 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5163 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5173 else string_of_float
f
5175 Printf.bprintf bb
"\n %s='%s'" s v
5179 then dc.winw, dc.winh
5181 match state.fullscreen
with
5183 | None
-> c.winw, c.winh
5185 let zoom, presentation, interpagespace, maxwait
=
5187 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5189 match state.mode with
5190 | Birdseye
(bc
, _, _, _, _) ->
5191 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5192 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5194 oi
"width" w dc.winw;
5195 oi
"height" h dc.winh
;
5196 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5197 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5198 ob "case-insensitive-search" c.icase
dc.icase
;
5199 ob "preload" c.preload dc.preload;
5200 oi
"page-bias" c.pagebias
dc.pagebias
;
5201 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5202 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5203 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5204 ob "crop-hack" c.crophack
dc.crophack
;
5205 oW
"throttle" maxwait
dc.maxwait
;
5206 ob "highlight-links" c.hlinks
dc.hlinks
;
5207 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5208 oi
"vertical-margin" interpagespace dc.interpagespace;
5209 oz
"zoom" zoom dc.zoom;
5210 ob "presentation" presentation dc.presentation;
5211 oi
"rotation-angle" c.angle
dc.angle
;
5212 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5213 ob "proportional-display" c.proportional
dc.proportional
;
5214 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5215 oi
"tex-count" c.texcount
dc.texcount
;
5216 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5217 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5218 ob "persistent-location" c.jumpback
dc.jumpback
;
5219 oc
"background-color" c.bgcolor
dc.bgcolor
;
5220 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5221 oi
"tile-width" c.tilew
dc.tilew
;
5222 oi
"tile-height" c.tileh
dc.tileh
;
5223 oI
"mupdf-memlimit" c.mumemlimit
dc.mumemlimit
;
5224 ob "checkers" c.checkers
dc.checkers
;
5225 oi
"aalevel" c.aalevel
dc.aalevel
;
5226 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5227 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5228 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5229 oC
"color-space" c.colorspace
dc.colorspace
;
5230 ob "invert-colors" c.invert
dc.invert
;
5231 oF
"brightness" c.colorscale
dc.colorscale
;
5232 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5234 then ob "wmclass-hack" !wmclasshack false;
5238 let uifontsize = fstate.fontsize
in
5239 let bb = Buffer.create
32768 in
5241 let dc = if conf.bedefault
then conf else dc in
5242 Buffer.add_string
bb "<llppconfig>\n";
5244 if String.length
!fontpath > 0
5246 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5252 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5255 Buffer.add_string
bb "<defaults ";
5256 add_attrs bb true dc dc;
5257 Buffer.add_string
bb "/>\n";
5259 let adddoc path pan
anchor c bookmarks =
5260 if bookmarks == [] && c = dc && anchor = emptyanchor
5263 Printf.bprintf
bb "<doc path='%s'"
5264 (enent
path 0 (String.length
path));
5266 if anchor <> emptyanchor
5268 let n, y = anchor in
5269 Printf.bprintf
bb " page='%d'" n;
5272 Printf.bprintf
bb " rely='%f'" y
5277 then Printf.bprintf
bb " pan='%d'" pan
;
5279 add_attrs bb false dc c;
5281 begin match bookmarks with
5282 | [] -> Buffer.add_string
bb "/>\n"
5284 Buffer.add_string
bb ">\n<bookmarks>\n";
5285 List.iter
(fun (title, _level
, (page, rely
)) ->
5287 "<item title='%s' page='%d'"
5288 (enent
title 0 (String.length
title))
5293 Printf.bprintf
bb " rely='%f'" rely
5295 Buffer.add_string
bb "/>\n";
5297 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5303 match state.mode with
5304 | Birdseye
(_, pan, _, _, _) -> pan
5307 let basename = Filename.basename state.path in
5308 adddoc basename pan (getanchor ())
5311 match state.autoscroll
with
5313 | None
-> conf.autoscrollstep
}
5314 (if conf.savebmarks
then state.bookmarks else []);
5316 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5318 then adddoc path x y c bookmarks
5320 Buffer.add_string
bb "</llppconfig>";
5323 if Buffer.length
bb > 0
5326 let tmp = !confpath ^
".tmp" in
5327 let oc = open_out_bin
tmp in
5328 Buffer.output_buffer
oc bb;
5330 Unix.rename
tmp !confpath;
5333 ("error while saving configuration: " ^
Printexc.to_string exn
)
5340 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5341 "<password> Set password");
5343 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5344 "<path> Set path to the user interface font");
5346 ("-c", Arg.String
(fun s -> Config.confpath := s),
5347 "<path> Set path to the configuration file");
5349 ("-v", Arg.Unit
(fun () ->
5351 "%s\nconfiguration path: %s\n"
5355 exit
0), " Print version and exit");
5358 (fun s -> state.path <- s)
5359 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5361 if String.length
state.path = 0
5362 then (prerr_endline
"file name missing"; exit
1);
5366 let _ = Glut.init
Sys.argv
in
5367 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5368 let () = Glut.initWindowSize
conf.winw conf.winh
in
5369 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5371 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5372 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5373 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5378 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5380 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5381 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5382 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5383 Unix.bind
sock addr;
5385 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5386 Unix.connect
csock addr;
5387 let ssock, _ = Unix.accept
sock in
5390 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5391 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5398 let () = Glut.displayFunc
display in
5399 let () = Glut.reshapeFunc
reshape in
5400 let () = Glut.keyboardFunc
keyboard in
5401 let () = Glut.specialFunc
special in
5402 let () = Glut.idleFunc
(Some
idle) in
5403 let () = Glut.mouseFunc
mouse in
5404 let () = Glut.motionFunc
motion in
5405 let () = Glut.passiveMotionFunc
pmotion in
5407 setcheckers conf.checkers
;
5409 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5410 conf.texcount
, conf.sliceheight
, conf.mumemlimit
, conf.colorspace
,
5411 !Config.wmclasshack, !Config.fontpath
5413 state.csock <- csock;
5414 state.ssock <- ssock;
5415 state.text <- "Opening " ^
state.path;
5416 setaalevel
conf.aalevel
;
5417 writeopen state.path state.password
;
5419 setfontsize fstate.fontsize
;
5427 | Glut.BadEnum
"key in special_of_int" ->
5428 showtext '
!'
" LablGlut bug: special key not recognized";
5435 | exn
when conf.redirectstderr ->
5437 Printf.sprintf
"exception %s\n%s"
5438 (Printexc.to_string exn
)
5439 (Printexc.get_backtrace
())
5442 Unix.single_write
state.stderr
s 0 (String.length
s);