4 | Ulinkgoto
of (int * int)
6 and facename
= string;;
8 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
9 let now = Unix.gettimeofday
;;
13 type params
= (angle
* proportional
* trimparams
14 * texcount
* sliceheight
* memsize
15 * colorspace
* wmclasshack
* fontpath
)
24 and proportional
= bool
25 and trimmargins
= bool
26 and interpagespace
= int
34 and wmclasshack
= bool
35 and irect
= (int * int * int * int)
36 and trimparams
= (trimmargins
* irect
)
37 and colorspace
= | Rgb
| Bgr
| Gray
40 type platform
= | Punknown
| Plinux
| Pwindows
| Posx
| Psun
41 | Pfreebsd
| Pdragonflybsd
| Popenbsd
| Pmingw
| Pcygwin
;;
43 external init
: Unix.file_descr
-> params
-> unit = "ml_init";;
44 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
45 external copysel
: string -> unit = "ml_copysel";;
46 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
47 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
48 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
49 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
50 external measurestr
: int -> string -> float = "ml_measure_string";;
51 external getmaxw
: unit -> float = "ml_getmaxw";;
52 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
53 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
54 external platform
: unit -> platform
= "ml_platform";;
55 external setaalevel
: int -> unit = "ml_setaalevel";;
56 external realloctexts
: int -> bool = "ml_realloctexts";;
58 let platform_to_string = function
59 | Punknown
-> "unknown"
61 | Pwindows
-> "Windows"
64 | Pfreebsd
-> "FreeBSD"
65 | Pdragonflybsd
-> "DragonflyBSD"
66 | Popenbsd
-> "OpenBSD"
71 let platform = platform ();;
75 | Pwindows
| Pmingw
-> true
83 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
86 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
90 | Msel
of (mpos
* mpos
)
93 | Mzoom
of (int * int)
94 | Mzoomrect
of (mpos
* mpos
)
98 type textentry
= string * string * onhist
option * onkey
* ondone
99 and onkey
= string -> int -> te
100 and ondone
= string -> unit
101 and histcancel
= unit -> unit
102 and onhist
= ((histcmd
-> string) * histcancel
)
103 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
108 | TEswitch
of textentry
119 let bound v minv maxv
=
120 max minv
(min maxv v
);
124 { store
= Array.create n v
131 let drawstring size x y s
=
133 Gl.enable `texture_2d
;
134 ignore
(drawstr size x y s
);
136 Gl.disable `texture_2d
;
139 let drawstring1 size x y s
=
143 let drawstring2 size x y fmt
=
144 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
147 let cbcap b
= Array.length b
.store
;;
152 b
.wc
<- (b
.wc
+ 1) mod cap;
154 b
.len
<- min
(b
.len
+ 1) cap;
157 let cbempty b
= b
.len
= 0;;
159 let cbgetg b circular dir
=
163 let rc = b
.rc + dir
in
175 else max
0 (min
rc (b
.len
-1))
181 let cbget b
= cbgetg b
false;;
182 let cbgetc b
= cbgetg b
true;;
199 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
200 dolog " WxH %dx%d" l
.pagew l
.pageh
;
201 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
202 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
203 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
207 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
209 dolog " x0,y0=(% f, % f)" x0 y0
;
210 dolog " x1,y1=(% f, % f)" x1 y1
;
211 dolog " x2,y2=(% f, % f)" x2 y2
;
212 dolog " x3,y3=(% f, % f)" x3 y3
;
217 { mutable scrollbw
: int
218 ; mutable scrollh
: int
219 ; mutable icase
: bool
220 ; mutable preload
: bool
221 ; mutable pagebias
: int
222 ; mutable verbose
: bool
223 ; mutable debug
: bool
224 ; mutable scrollstep
: int
225 ; mutable maxhfit
: bool
226 ; mutable crophack
: bool
227 ; mutable autoscrollstep
: int
228 ; mutable maxwait
: float option
229 ; mutable hlinks
: bool
230 ; mutable underinfo
: bool
231 ; mutable interpagespace
: interpagespace
232 ; mutable zoom
: float
233 ; mutable presentation
: bool
234 ; mutable angle
: angle
237 ; mutable savebmarks
: bool
238 ; mutable proportional
: proportional
239 ; mutable trimmargins
: trimmargins
240 ; mutable trimfuzz
: irect
241 ; mutable memlimit
: memsize
242 ; mutable texcount
: texcount
243 ; mutable sliceheight
: sliceheight
244 ; mutable thumbw
: width
245 ; mutable jumpback
: bool
246 ; mutable bgcolor
: float * float * float
247 ; mutable bedefault
: bool
248 ; mutable scrollbarinpm
: bool
249 ; mutable tilew
: int
250 ; mutable tileh
: int
251 ; mutable 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
option
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
;
556 state.errfd
<- Some
rfd;
557 Unix.dup2 wfd
Unix.stderr
;
559 state.newerrmsgs
<- false;
560 begin match state.errfd
with
563 Unix.dup2
state.stderr
Unix.stderr
;
567 prerr_string
(Buffer.contents
state.errmsgs
);
569 Buffer.clear
state.errmsgs
;
575 let postRedisplay who
=
577 then prerr_endline
("redisplay for " ^ who
);
578 Glut.postRedisplay ();
583 let b = Buffer.create
(String.length s
+ 1) in
584 Buffer.add_string
b s
;
589 let colorspace_of_string s
=
590 match String.lowercase s
with
594 | _
-> failwith
"invalid colorspace"
597 let int_of_colorspace = function
603 let colorspace_of_int = function
607 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
610 let colorspace_to_string = function
616 let intentry_with_suffix text key
=
617 let c = Char.unsafe_chr key
in
618 match Char.lowercase
c with
620 let text = addchar text c in
624 let text = addchar text c in
628 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
633 let len = String.length s
in
635 let b = Buffer.create
n in
636 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
637 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
638 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
639 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
640 Buffer.add_string
b s
;
641 let s'
= Buffer.contents
b in
642 let n'
= Unix.write fd
s'
0 n in
643 if n'
!= n then failwith
"write failed";
648 let n = Unix.read fd
s 0 4 in
649 if n != 4 then failwith
"incomplete read(len)";
651 lor (Char.code
s.[0] lsl 24)
652 lor (Char.code
s.[1] lsl 16)
653 lor (Char.code
s.[2] lsl 8)
654 lor (Char.code
s.[3] lsl 0)
656 let s = String.create
len in
657 let n = Unix.read fd
s 0 len in
658 if n != len then failwith
"incomplete read(data)";
663 let b = Buffer.create
10 in
664 Buffer.add_string
b s;
665 let rec combine = function
668 Buffer.add_char
b ' '
;
671 | `
b b -> if b then "1" else "0"
673 | `i i
-> string_of_int i
674 | `f f
-> string_of_float f
675 | `I f
-> string_of_int
(truncate f
)
677 Buffer.add_string
b s;
684 let cmd = Buffer.contents
(makecmd s l
) in
685 writecmd state.csock
cmd;
691 let d = conf.winh
- h
in
698 let rec f pn ph pi fh l
=
700 | (n, _
, h
, _
) :: rest
->
701 let ips = calcips h
in
706 if isbirdseye state.mode
&& pn
= 0
711 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
716 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
720 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
723 let fh = f 0 0 0 0 state.pdims
in
727 let getpageyh pageno
=
728 let rec f pn ph pi y l
=
730 | (n, _
, h
, _
) :: rest
->
731 let ips = calcips h
in
734 let h = if n = pageno
then h else ph
in
735 if conf.presentation
&& n = pageno
737 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
739 y
+ (pageno
- pn
) * (ph
+ pi
), h
741 let y = y + (if conf.presentation
then pi
else 0) in
742 let y = y + (n - pn
) * (ph
+ pi
) in
746 y + (pageno
- pn
) * (ph
+ pi
), ph
748 f 0 0 0 0 state.pdims
751 let getpagedim pageno
=
754 | (n, _
, _
, _
) as pdim
:: rest
->
756 then (if n = pageno
then pdim
else ppdim
)
761 f (-1, -1, -1, -1) state.pdims
764 let getpagey pageno
= fst
(getpageyh pageno
);;
767 let sh = sh - state.hscrollh
in
768 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
769 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
771 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
772 let ips = calcips h in
774 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
778 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
780 prev
, pdims
, pdimno
, 0
782 let dy = dy + yinc in
783 let py = py + yinc in
784 if pageno
= state.pagecount
|| dy >= sh
789 if py + h <= vy - yinc
791 let py = py + h + ips in
792 let dy = max
0 (py - y) in
801 let pagey = vy - py in
802 let pagevh = h - pagey in
803 let pagevh = min
(sh - dy) pagevh in
804 let off = if yinc > 0 then py - vy else 0 in
805 let py = py + h + ips in
808 if state.w
< conf.winw
- state.scrollw
809 then (conf.winw
- state.scrollw
- state.w
) / 2
812 let dispx = xoff + state.x
in
818 let lw = w
- pagex in
819 min
lw (conf.winw
- state.scrollw
)
827 ; pagey = pagey + off
829 ; pagevh = pagevh - off
831 ; pagedispy
= dy + off
834 let accu = e :: accu in
843 if state.invalidated
= 0
862 let y = state.y + incr
in
864 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
868 let getopaque pageno
=
869 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
870 with Not_found
-> None
873 let putopaque pageno opaque
=
874 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
878 let tilex = l
.pagex mod conf.tilew
in
879 let tiley = l
.pagey mod conf.tileh
in
881 let col = l
.pagex / conf.tilew
in
882 let row = l
.pagey / conf.tileh
in
885 let a = l
.pagew
- l
.pagex in
886 let b = conf.winw
- state.scrollw
in
890 let rec rowloop row y0 dispy
h =
894 let dh = conf.tileh
- y0
in
896 let rec colloop col x0
dispx w
=
900 let dw = conf.tilew
- x0
in
903 f col row dispx dispy x0 y0
dw dh;
904 colloop (col+1) 0 (dispx+dw) (w
-dw)
907 colloop col tilex l
.pagedispx
vw;
908 rowloop (row+1) 0 (dispy
+dh) (h-dh)
912 then rowloop row tiley l
.pagedispy vh
;
915 let gettileopaque l
col row =
917 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
919 try Some
(Hashtbl.find
state.tilemap
key)
920 with Not_found
-> None
923 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
924 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
925 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
928 let drawtiles l color
=
930 let f col row x
y tilex tiley w
h =
931 match gettileopaque l
col row with
932 | Some
(opaque
, _
, t
) ->
933 let params = x
, y, w
, h, tilex, tiley in
937 GlFunc.blend_func `zero `one_minus_src_color
;
939 drawtile
params opaque
;
941 then Gl.disable `blend
;
944 let s = Printf.sprintf
948 let w = measurestr
fstate.fontsize
s in
949 GlMisc.push_attrib
[`current
];
950 GlDraw.color
(0.0, 0.0, 0.0);
952 (float (x
-2), float (y-2))
953 (float (x
+2) +. w, float (y + fstate.fontsize
+ 2));
954 GlDraw.color
(1.0, 1.0, 1.0);
955 drawstring fstate.fontsize x
(y + fstate.fontsize
- 1) s;
956 GlMisc.pop_attrib
();
961 let lw = conf.winw
- state.scrollw
- x
in
964 let lh = conf.winh
- y in
967 Gl.enable `texture_2d
;
968 begin match state.texid
with
970 GlTex.bind_texture `texture_2d id
;
974 and y1
= float (y+h) in
976 let tw = float w /. 64.0
977 and th
= float h /. 64.0 in
978 let tx0 = float tilex /. 64.0
979 and ty0
= float tiley /. 64.0 in
981 and ty1
= ty0
+. th
in
982 GlDraw.begins `quads
;
983 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
984 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
985 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
986 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
989 Gl.disable `texture_2d
;
991 GlDraw.color
(1.0, 1.0, 1.0);
994 (float (x
+w), float (y+h));
996 if w > 128 && h > fstate.fontsize
+ 10
998 GlDraw.color
(0.0, 0.0, 0.0);
1001 then (col*conf.tilew
, row*conf.tileh
)
1004 drawstring2 fstate.fontsize x
y "Loading %d [%d,%d]" l
.pageno
c r;
1011 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1013 let tilevisible1 l x
y =
1015 and ax1
= l
.pagex + l
.pagevw
1017 and ay1
= l
.pagey + l
.pagevh in
1021 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1022 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1024 let rx0 = max
ax0 bx0
1025 and ry0
= max ay0 by0
1026 and rx1
= min ax1
bx1
1027 and ry1
= min ay1 by1
in
1029 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1030 nonemptyintersection
1033 let tilevisible layout n x
y =
1034 let rec findpageinlayout = function
1035 | l
:: _
when l
.pageno
= n -> tilevisible1 l x
y
1036 | _
:: rest
-> findpageinlayout rest
1039 findpageinlayout layout
1042 let tileready l x
y =
1043 tilevisible1 l x
y &&
1044 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
1047 let tilepage n p
layout =
1048 let rec loop = function
1052 let f col row _ _ _ _ _ _
=
1053 if state.currently
= Idle
1055 match gettileopaque l
col row with
1058 let x = col*conf.tilew
1059 and y = row*conf.tileh
in
1061 let w = l
.pagew
- x in
1065 let h = l
.pageh
- y in
1077 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1078 conf.tilew
, conf.tileh
1087 if state.invalidated
= 0 then loop layout;
1090 let preloadlayout visiblepages
=
1091 let presentation = conf.presentation in
1092 let interpagespace = conf.interpagespace in
1093 let maxy = state.maxy in
1094 conf.presentation <- false;
1095 conf.interpagespace <- 0;
1096 state.maxy <- calcheight ();
1098 match visiblepages
with
1100 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1102 let y = if y < conf.winh
then 0 else y - conf.winh
in
1103 let h = state.y - y + conf.winh
*3 in
1104 let pages = layout y h in
1105 conf.presentation <- presentation;
1106 conf.interpagespace <- interpagespace;
1112 let rec loop pages =
1113 if state.currently
!= Idle
1118 begin match getopaque l
.pageno
with
1120 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1121 state.currently
<- Loading
(l
, state.gen
);
1123 tilepage l
.pageno opaque
pages;
1128 if state.invalidated
= 0 then loop pages
1133 if conf.preload && state.currently
= Idle
1134 then load (preloadlayout pages);
1137 let layoutready layout =
1138 let rec fold all ls
=
1139 all
&& match ls
with
1141 let seen = ref false in
1142 let allvisible = ref true in
1143 let foo col row _ _ _ _ _ _
=
1145 allvisible := !allvisible &&
1146 begin match gettileopaque l
col row with
1152 fold (!seen && !allvisible) rest
1155 let alltilesvisible = fold true layout in
1160 let y = bound y 0 state.maxy in
1161 let y, layout, proceed
=
1162 match conf.maxwait
with
1164 begin match state.throttle
with
1166 let layout = layout y conf.winh
in
1167 let ready = layoutready layout in
1171 state.throttle
<- Some
(layout, y, now ());
1173 else G.postRedisplay "gotoy showall (None)";
1175 | Some
(_
, _
, started
) ->
1176 let dt = now () -. started
in
1179 state.throttle
<- None
;
1180 let layout = layout y conf.winh
in
1182 G.postRedisplay "maxwait";
1189 let layout = layout y conf.winh
in
1190 if true || layoutready layout
1191 then G.postRedisplay "gotoy ready";
1197 state.layout <- layout;
1198 begin match state.mode
with
1199 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1200 if not
(pagevisible layout pageno
)
1202 match state.layout with
1205 state.mode
<- Birdseye
(
1206 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1215 let conttiling pageno opaque
=
1216 tilepage pageno opaque
1217 (if conf.preload then preloadlayout state.layout else state.layout)
1220 let gotoy_and_clear_text y =
1222 if not
conf.verbose
then state.text <- "";
1226 match state.layout with
1228 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1231 let getanchory (n, top
) =
1232 let y, h = getpageyh n in
1233 y + (truncate
(top
*. float h));
1236 let gotoanchor anchor
=
1237 gotoy (getanchory anchor
);
1241 cbput state.hists
.nav
(getanchor ());
1245 let anchor = cbgetc state.hists
.nav dir
in
1249 let gotopage n top
=
1250 let y, h = getpageyh n in
1251 gotoy_and_clear_text (y + (truncate
(top
*. float h)));
1254 let gotopage1 n top
=
1255 let y = getpagey n in
1256 gotoy_and_clear_text (y + top
);
1264 state.invalidated
<- state.invalidated
+ 1;
1267 let writeopen path password
=
1268 writecmd state.csock
("open " ^ path ^
"\000" ^ password ^
"\000");
1271 let opendoc path password
=
1274 state.password
<- password
;
1275 state.gen
<- state.gen
+ 1;
1276 state.docinfo
<- [];
1278 setaalevel
conf.aalevel
;
1279 writeopen path password
;
1280 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1281 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1285 let c = c *. conf.colorscale
in
1289 let scalecolor2 (r, g
, b) =
1290 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1294 state.maxy <- calcheight ();
1296 if state.w <= conf.winw
- state.scrollw
1300 match state.mode
with
1301 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1302 let y, h = getpageyh pageno
in
1303 let top = (conf.winh
- h) / 2 in
1304 gotoy (max
0 (y - top))
1305 | _
-> gotoanchor state.anchor
1309 let firsttime = ref true in
1311 GlDraw.viewport
0 0 w h;
1312 if state.invalidated
= 0 && not
!firsttime
1313 then state.anchor <- getanchor ();
1317 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1321 setfontsize fstate.fontsize
;
1322 GlMat.mode `modelview
;
1323 GlMat.load_identity
();
1325 GlMat.mode `projection
;
1326 GlMat.load_identity
();
1327 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1328 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1329 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1332 wcmd "geometry" [`i
w; `i
h];
1336 let len = String.length
state.text in
1339 match state.mode
with
1340 | View
-> state.hscrollh
1345 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1346 (x+.w, float (conf.winh
- hscrollh))
1349 let w = float (conf.winw
- state.scrollw
- 1) in
1350 if state.progress
>= 0.0 && state.progress
< 1.0
1352 GlDraw.color
(0.3, 0.3, 0.3);
1353 let w1 = w *. state.progress
in
1355 GlDraw.color
(0.0, 0.0, 0.0);
1359 GlDraw.color
(0.0, 0.0, 0.0);
1363 GlDraw.color
(1.0, 1.0, 1.0);
1364 drawstring fstate.fontsize
1365 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1368 match state.mode
with
1369 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1373 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1375 Printf.sprintf
"%s%s_" prefix
text
1384 if not
(istextentry state.mode
)
1386 let s1 = "(press 'e' to review error messasges)" in
1387 if String.length
s > 0 then s ^
" " ^
s1 else s1
1392 if String.length
s > 0
1397 state.text <- Printf.sprintf
"%c%s" c s;
1398 G.postRedisplay "showtext";
1402 let len = Queue.length
state.tilelru
in
1404 if state.memused
<= conf.memlimit
1409 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1410 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1411 let (_
, pw
, ph
, _
) = getpagedim n in
1414 && colorspace
= conf.colorspace
1415 && angle
= conf.angle
1420 match state.throttle
with
1423 then preloadlayout state.layout
1425 | Some
(layout, _
, _
) ->
1428 let x = col*conf.tilew
1429 and y = row*conf.tileh
in
1430 tilevisible layout n x y
1432 then Queue.push lruitem
state.tilelru
1434 wcmd "freetile" [`
s p
];
1435 state.memused
<- state.memused
- s;
1436 state.uioh#infochanged Memused
;
1437 Hashtbl.remove
state.tilemap k
;
1446 Queue.iter
(fun (k
, p
, s) ->
1447 wcmd "freetile" [`
s p
];
1448 state.memused
<- state.memused
- s;
1449 state.uioh#infochanged Memused
;
1450 Hashtbl.remove
state.tilemap k
;
1452 Queue.clear
state.tilelru
;
1456 let logcurrently = function
1457 | Idle
-> dolog "Idle"
1458 | Loading
(l
, gen
) ->
1459 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1460 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1462 "Tiling %d[%d,%d] page=%s cs=%s angle"
1463 l
.pageno
col row pageopaque
1464 (colorspace_to_string colorspace
)
1466 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1467 angle gen
conf.angle
state.gen
1469 conf.tilew
conf.tileh
1476 (* dolog "%S" cmds; *)
1479 try String.index cmds ' '
1480 with Not_found
-> -1
1485 let l = String.length cmds
in
1486 let op = String.sub cmds
0 spacepos in
1488 if l - spacepos < 2 then ""
1489 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1494 state.uioh#infochanged Pdim
;
1498 state.rects
<- state.rects1
;
1499 G.postRedisplay "clearrects";
1503 try Scanf.sscanf args
"%u" (fun n -> n)
1505 dolog "error processing 'continue' %S: %s"
1506 cmds
(Printexc.to_string exn
);
1509 state.pagecount
<- n;
1510 state.invalidated
<- state.invalidated
- 1;
1511 begin match state.currently
with
1513 state.currently
<- Idle
;
1514 state.outlines
<- Array.of_list
(List.rev
l)
1517 if state.invalidated
= 0
1519 if conf.maxwait
= None
1520 then G.postRedisplay "continue";
1523 Glut.setWindowTitle args
1530 then showtext ' ' args
1533 let progress, text =
1535 Scanf.sscanf args
"%f %n"
1537 f, String.sub args pos
(String.length args
- pos
))
1539 dolog "error processing 'progress' %S: %s"
1540 cmds
(Printexc.to_string exn
);
1544 state.progress <- progress;
1545 G.postRedisplay "progress"
1548 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1550 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1551 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1552 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1554 dolog "error processing 'firstmatch' %S: %s"
1555 cmds
(Printexc.to_string exn
);
1558 let y = (getpagey pageno) + truncate y0
in
1561 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)]
1564 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1566 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1567 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1568 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1570 dolog "error processing 'match' %S: %s"
1571 cmds
(Printexc.to_string exn
);
1575 (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) :: state.rects1
1580 Scanf.sscanf args
"%s %f" (fun p t
-> p
, t
)
1582 dolog "error processing 'page' %S: %s"
1583 cmds
(Printexc.to_string exn
);
1586 begin match state.currently
with
1587 | Loading
(l, gen
) ->
1588 vlog "page %d took %f sec" l.pageno t
;
1589 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1590 begin match state.throttle
with
1592 let preloadedpages =
1594 then preloadlayout state.layout
1599 Set.Make
(struct type t
= int let compare = (-) end) in
1601 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1602 IntSet.empty
preloadedpages
1605 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
1606 if not
(IntSet.mem
pageno set)
1608 wcmd "freepage" [`
s opaque
];
1614 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1617 state.currently
<- Idle
;
1620 tilepage l.pageno pageopaque state.layout;
1622 load preloadedpages;
1623 if pagevisible state.layout l.pageno
1624 && layoutready state.layout
1625 then G.postRedisplay "page";
1628 | Some
(layout, _
, _
) ->
1629 state.currently
<- Idle
;
1630 tilepage l.pageno pageopaque layout;
1635 dolog "Inconsistent loading state";
1636 logcurrently state.currently
;
1641 let (x, y, opaque
, size
, t
) =
1643 Scanf.sscanf args
"%u %u %s %u %f"
1644 (fun x y p size t
-> (x, y, p
, size
, t
))
1646 dolog "error processing 'tile' %S: %s"
1647 cmds
(Printexc.to_string exn
);
1650 begin match state.currently
with
1651 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1652 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1654 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1656 wcmd "freetile" [`
s opaque
];
1657 state.currently
<- Idle
;
1661 puttileopaque l col row gen cs angle opaque size t
;
1662 state.memused
<- state.memused
+ size
;
1663 state.uioh#infochanged Memused
;
1665 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1666 opaque
, size
) state.tilelru
;
1669 match state.throttle
with
1670 | None
-> state.layout
1671 | Some
(layout, _
, _
) -> layout
1674 state.currently
<- Idle
;
1676 && conf.colorspace
= cs
1677 && conf.angle
= angle
1678 && tilevisible layout l.pageno x y
1679 then conttiling l.pageno pageopaque;
1681 begin match state.throttle
with
1683 preload state.layout;
1685 && conf.colorspace
= cs
1686 && conf.angle
= angle
1687 && tilevisible state.layout l.pageno x y
1688 then G.postRedisplay "tile nothrottle";
1690 | Some
(layout, y, _
) ->
1691 let ready = layoutready layout in
1695 state.layout <- layout;
1696 state.throttle
<- None
;
1697 G.postRedisplay "throttle";
1704 dolog "Inconsistent tiling state";
1705 logcurrently state.currently
;
1712 Scanf.sscanf args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1714 dolog "error processing 'pdim' %S: %s"
1715 cmds
(Printexc.to_string exn
);
1718 state.uioh#infochanged Pdim
;
1719 state.pdims
<- pdim :: state.pdims
1722 let (l, n, t
, h, pos
) =
1724 Scanf.sscanf args
"%u %u %d %u %n"
1725 (fun l n t
h pos
-> l, n, t
, h, pos
)
1727 dolog "error processing 'o' %S: %s"
1728 cmds
(Printexc.to_string exn
);
1731 let s = String.sub args pos
(String.length args
- pos
) in
1732 let outline = (s, l, (n, float t
/. float h)) in
1733 begin match state.currently
with
1734 | Outlining outlines
->
1735 state.currently
<- Outlining
(outline :: outlines
)
1737 state.currently
<- Outlining
[outline]
1739 dolog "invalid outlining state";
1740 logcurrently currently
1744 state.docinfo
<- (1, args
) :: state.docinfo
1747 state.uioh#infochanged Docinfo
;
1748 state.docinfo
<- List.rev
state.docinfo
1751 dolog "unknown cmd `%S'" cmds
1755 if state.deadline
== nan
then state.deadline
<- now ();
1757 match state.errfd
with
1758 | None
-> [state.csock
]
1759 | Some fd
-> [state.csock
; fd
]
1761 let rec loop delay
=
1764 then max
0.0 (state.deadline
-. now ())
1767 let r, _
, _
= Unix.select
r [] [] timeout in
1770 begin match state.autoscroll
with
1771 | Some step
when step
!= 0 ->
1772 let y = state.y + step
in
1776 else if y >= state.maxy then 0 else y
1779 if state.mode
= View
1780 then state.text <- "";
1781 state.deadline
<- state.deadline
+. 0.005;
1784 state.deadline
<- state.deadline
+. delay
;
1788 let rec checkfds c = function
1790 | fd
:: rest
when fd
= state.csock
->
1791 let cmd = readcmd state.csock
in
1795 let s = String.create
80 in
1796 let n = Unix.read fd
s 0 80 in
1797 if conf.redirectstderr
1799 Buffer.add_substring
state.errmsgs
s 0 n;
1800 state.newerrmsgs
<- true;
1801 Glut.postRedisplay ();
1804 prerr_string
(String.sub
s 0 n);
1817 let action = function
1818 | HCprev
-> cbget cb ~
-1
1819 | HCnext
-> cbget cb
1
1820 | HCfirst
-> cbget cb ~
-(cb
.rc)
1821 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1822 and cancel
() = cb
.rc <- rc
1826 let search pattern forward
=
1827 if String.length pattern
> 0
1830 match state.layout with
1833 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1836 let b = makecmd "search"
1837 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
1839 Buffer.add_char
b '
,'
;
1840 Buffer.add_string
b pattern
;
1841 Buffer.add_char
b '
\000'
;
1844 writecmd state.csock
cmd;
1847 let intentry text key =
1848 let c = Char.unsafe_chr
key in
1851 let text = addchar text c in
1855 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1859 let textentry text key =
1860 let c = Char.unsafe_chr
key in
1862 | _
when key >= 32 && key < 127 ->
1863 let text = addchar text c in
1867 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
1871 let reqlayout angle proportional
=
1872 match state.throttle
with
1874 if state.invalidated
= 0 then state.anchor <- getanchor ();
1875 conf.angle
<- angle
mod 360;
1876 conf.proportional
<- proportional
;
1878 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
1882 let settrim trimmargins trimfuzz
=
1883 if state.invalidated
= 0 then state.anchor <- getanchor ();
1884 conf.trimmargins
<- trimmargins
;
1885 conf.trimfuzz
<- trimfuzz
;
1886 let x0, y0
, x1
, y1
= trimfuzz
in
1889 `
b conf.trimmargins
;
1895 Hashtbl.iter
(fun _ opaque
->
1896 wcmd "freepage" [`
s opaque
];
1898 Hashtbl.clear
state.pagemap
;
1902 match state.throttle
with
1904 let zoom = max
0.01 zoom in
1905 if zoom <> conf.zoom
1907 state.prevzoom
<- conf.zoom;
1910 then (state.x <- 0; 0.0)
1911 else float state.x /. float state.w
1914 reshape conf.winw
conf.winh
;
1917 let x = relx *. float state.w in
1918 state.x <- truncate
x;
1920 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
1923 | Some
(layout, y, started
) ->
1925 match conf.maxwait
with
1929 let dt = now () -. started
in
1937 let enterbirdseye () =
1938 let zoom = float conf.thumbw
/. float conf.winw
in
1939 let birdseyepageno =
1940 let cy = conf.winh
/ 2 in
1944 let rec fold best
= function
1947 let d = cy - (l.pagedispy
+ l.pagevh/2)
1948 and dbest
= cy - (best
.pagedispy
+ best
.pagevh/2) in
1949 if abs
d < abs dbest
1956 state.mode
<- Birdseye
(
1957 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
1960 conf.presentation <- false;
1961 conf.interpagespace <- 10;
1962 conf.hlinks
<- false;
1964 state.mstate
<- Mnone
;
1965 conf.maxwait
<- None
;
1966 Glut.setCursor
Glut.CURSOR_INHERIT
;
1969 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1974 reshape conf.winw
conf.winh
;
1977 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
1979 conf.zoom <- c.zoom;
1980 conf.presentation <- c.presentation;
1981 conf.interpagespace <- c.interpagespace;
1982 conf.maxwait
<- c.maxwait
;
1983 conf.hlinks
<- c.hlinks
;
1987 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1990 reshape conf.winw
conf.winh
;
1991 state.anchor <- if goback
then anchor else (pageno, 0.0);
1994 let togglebirdseye () =
1995 match state.mode
with
1996 | Birdseye vals
-> leavebirdseye vals
true
1997 | View
-> enterbirdseye ()
2001 let upbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
2002 let pageno = max
0 (pageno - 1) in
2003 let rec loop = function
2004 | [] -> gotopage1 pageno 0
2005 | l :: _
when l.pageno = pageno ->
2006 if l.pagedispy
>= 0 && l.pagey = 0
2007 then G.postRedisplay "upbirdseye"
2008 else gotopage1 pageno 0
2009 | _
:: rest
-> loop rest
2012 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2015 let downbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
2016 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
2017 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2018 let rec loop = function
2020 let y, h = getpageyh pageno in
2021 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2023 | l :: _
when l.pageno = pageno ->
2024 if l.pagevh != l.pageh
2025 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2026 else G.postRedisplay "downbirdseye"
2027 | _
:: rest
-> loop rest
2032 let optentry mode _
key =
2033 let btos b = if b then "on" else "off" in
2034 let c = Char.unsafe_chr
key in
2038 try conf.scrollstep
<- int_of_string
s with exc
->
2039 state.text <- Printf.sprintf
"bad integer `%s': %s"
2040 s (Printexc.to_string exc
)
2042 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2047 conf.autoscrollstep
<- int_of_string
s;
2048 if state.autoscroll
<> None
2049 then state.autoscroll
<- Some
conf.autoscrollstep
2051 state.text <- Printf.sprintf
"bad integer `%s': %s"
2052 s (Printexc.to_string exc
)
2054 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2059 let zoom = float (int_of_string
s) /. 100.0 in
2062 state.text <- Printf.sprintf
"bad integer `%s': %s"
2063 s (Printexc.to_string exc
)
2065 TEswitch
("zoom: ", "", None
, intentry, ondone)
2070 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2072 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2073 begin match mode
with
2075 leavebirdseye beye
false;
2080 state.text <- Printf.sprintf
"bad integer `%s': %s"
2081 s (Printexc.to_string exc
)
2083 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2088 Some
(int_of_string
s)
2090 state.text <- Printf.sprintf
"bad integer `%s': %s"
2091 s (Printexc.to_string exc
);
2094 | Some angle
-> reqlayout angle
conf.proportional
2097 TEswitch
("rotation: ", "", None
, intentry, ondone)
2100 conf.icase
<- not
conf.icase
;
2101 TEdone
("case insensitive search " ^
(btos conf.icase
))
2104 conf.preload <- not
conf.preload;
2106 TEdone
("preload " ^
(btos conf.preload))
2109 conf.verbose
<- not
conf.verbose
;
2110 TEdone
("verbose " ^
(btos conf.verbose
))
2113 conf.debug
<- not
conf.debug
;
2114 TEdone
("debug " ^
(btos conf.debug
))
2117 conf.maxhfit
<- not
conf.maxhfit
;
2119 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2120 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2123 conf.crophack
<- not
conf.crophack
;
2124 TEdone
("crophack " ^
btos conf.crophack
)
2128 match conf.maxwait
with
2130 conf.maxwait
<- Some infinity
;
2131 "always wait for page to complete"
2133 conf.maxwait
<- None
;
2134 "show placeholder if page is not ready"
2139 conf.underinfo
<- not
conf.underinfo
;
2140 TEdone
("underinfo " ^
btos conf.underinfo
)
2143 conf.savebmarks
<- not
conf.savebmarks
;
2144 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2150 match state.layout with
2155 conf.interpagespace <- int_of_string
s;
2156 state.maxy <- calcheight ();
2157 let y = getpagey pageno in
2160 state.text <- Printf.sprintf
"bad integer `%s': %s"
2161 s (Printexc.to_string exc
)
2163 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2166 reqlayout conf.angle
(not
conf.proportional
);
2167 TEdone
("proportional display " ^
btos conf.proportional
)
2170 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2171 TEdone
("trim margins " ^
btos conf.trimmargins
)
2174 conf.invert
<- not
conf.invert
;
2175 TEdone
("invert colors " ^
btos conf.invert
)
2178 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2182 class type lvsource
= object
2183 method getitemcount
: int
2184 method getitem
: int -> (string * int)
2185 method hasaction
: int -> bool
2194 method getactive
: int
2195 method getfirst
: int
2196 method getqsearch
: string
2197 method setqsearch
: string -> unit
2201 class virtual lvsourcebase
= object
2202 val mutable m_active
= 0
2203 val mutable m_first
= 0
2204 val mutable m_qsearch
= ""
2205 val mutable m_pan
= 0
2206 method getactive
= m_active
2207 method getfirst
= m_first
2208 method getqsearch
= m_qsearch
2209 method getpan
= m_pan
2210 method setqsearch
s = m_qsearch
<- s
2213 let textentryspecial key = function
2214 | ((c, _
, (Some
(action, _
) as onhist), onkey
, ondone), mode
) ->
2217 | Glut.KEY_UP
-> action HCprev
2218 | Glut.KEY_DOWN
-> action HCnext
2219 | Glut.KEY_HOME
-> action HCfirst
2220 | Glut.KEY_END
-> action HClast
2223 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2224 G.postRedisplay "special textentry";
2228 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2230 state.mode
<- Textentry
(te
, onleave
);
2233 G.postRedisplay "textentrykeyboard enttext";
2235 match Char.unsafe_chr
key with
2236 | '
\008'
-> (* backspace *)
2237 let len = String.length
text in
2241 G.postRedisplay "textentrykeyboard after cancel";
2244 let s = String.sub
text 0 (len - 1) in
2245 enttext (c, s, opthist
, onkey
, ondone)
2251 G.postRedisplay "textentrykeyboard after confirm"
2253 | '
\007'
(* ctrl-g *)
2254 | '
\027'
-> (* escape *)
2255 if String.length
text = 0
2257 begin match opthist
with
2259 | Some
(_
, onhistcancel
) -> onhistcancel
()
2263 G.postRedisplay "textentrykeyboard after cancel2"
2266 enttext (c, "", opthist
, onkey
, ondone)
2269 | '
\127'
-> () (* delete *)
2272 begin match onkey
text key with
2276 G.postRedisplay "textentrykeyboard after confirm2";
2279 enttext (c, text, opthist
, onkey
, ondone);
2284 G.postRedisplay "textentrykeyboard after cancel3"
2287 state.mode
<- Textentry
(te
, onleave
);
2288 G.postRedisplay "textentrykeyboard switch";
2292 let firstof first active
=
2293 if first
> active
|| abs
(first
- active
) > fstate.maxrows
- 1
2294 then max
0 (active
- (fstate.maxrows
/2))
2298 let calcfirst first active
=
2301 let rows = active
- first
in
2302 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2306 let scrollph y maxy =
2307 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2308 let sh = float conf.winh
/. sh in
2309 let sh = max
sh (float conf.scrollh
) in
2314 else float y /. float maxy
2316 let position = (float conf.winh
-. sh) *. percent in
2319 if position +. sh > float conf.winh
2320 then float conf.winh
-. sh
2326 let coe s = (s :> uioh
);;
2328 class listview ~
(source
:lvsource
) ~trusted
=
2330 val m_pan
= source#getpan
2331 val m_first
= source#getfirst
2332 val m_active
= source#getactive
2333 val m_qsearch
= source#getqsearch
2334 val m_prev_uioh
= state.uioh
2336 method private elemunder
y =
2337 let n = y / (fstate.fontsize
+1) in
2338 if m_first
+ n < source#getitemcount
2340 if source#hasaction
(m_first
+ n)
2341 then Some
(m_first
+ n)
2348 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2349 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2350 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2351 GlDraw.color
(1., 1., 1.);
2352 Gl.enable `texture_2d
;
2353 let fs = fstate.fontsize
in
2355 let ww = fstate.wwidth
in
2356 let tabw = 30.0*.ww in
2357 let itemcount = source#getitemcount
in
2359 if (row - m_first
) * nfs > conf.winh
2362 if row >= 0 && row < itemcount
2364 let (s, level
) = source#getitem
row in
2365 let y = (row - m_first
) * nfs in
2366 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2369 Gl.disable `texture_2d
;
2370 GlDraw.polygon_mode `both `line
;
2371 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2372 GlDraw.rect (1., float (y + 1))
2373 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2374 GlDraw.polygon_mode `both `fill
;
2375 GlDraw.color
(1., 1., 1.);
2376 Gl.enable `texture_2d
;
2379 let drawtabularstring s =
2380 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2383 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2386 let len = String.length
s - tabpos - 1 in
2387 let s1 = String.sub
s 0 tabpos
2388 and s2
= String.sub
s (tabpos + 1) len in
2389 let nx = drawstr x s1 in
2391 let x = x +. (max
tabw sw) in
2398 let _ = drawtabularstring s in
2405 Gl.disable `texture_2d
;
2407 method updownlevel incr
=
2408 let len = source#getitemcount
in
2409 let _, curlevel
= source#getitem m_active
in
2411 if i
= len then i
-1 else if i
= -1 then 0 else
2412 let _, l = source#getitem i
in
2413 if l != curlevel
then i
else flow (i
+incr
)
2415 let active = flow m_active
in
2416 let first = calcfirst m_first
active in
2417 G.postRedisplay "special outline updownlevel";
2418 {< m_active
= active; m_first
= first >}
2420 method private key1
key =
2421 let set active first qsearch
=
2422 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2424 let search active pattern incr
=
2427 if n >= 0 && n < source#getitemcount
2429 let s, _ = source#getitem
n in
2431 (try ignore
(Str.search_forward
re s 0); true
2432 with Not_found
-> false)
2434 else loop (n + incr
)
2441 let re = Str.regexp_case_fold pattern
in
2448 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2449 let incr = if key = 18 then -1 else 1 in
2451 match search (m_active
+ incr) m_qsearch
incr with
2453 state.text <- m_qsearch ^
" [not found]";
2456 state.text <- m_qsearch
;
2457 active, firstof m_first
active
2459 G.postRedisplay "listview ctrl-r/s";
2460 set active first m_qsearch
;
2462 | 8 -> (* backspace *)
2463 let len = String.length m_qsearch
in
2470 G.postRedisplay "listview empty qsearch";
2471 set m_active m_first
"";
2474 let qsearch = String.sub m_qsearch
0 (len - 1) in
2476 match search m_active
qsearch ~
-1 with
2478 state.text <- qsearch ^
" [not found]";
2481 state.text <- qsearch;
2482 active, firstof m_first
active
2484 G.postRedisplay "listview backspace qsearch";
2485 set active first qsearch
2488 | _ when key >= 32 && key < 127 ->
2489 let pattern = addchar m_qsearch
(Char.chr
key) in
2491 match search m_active
pattern 1 with
2493 state.text <- pattern ^
" [not found]";
2496 state.text <- pattern;
2497 active, firstof m_first
active
2499 G.postRedisplay "listview qsearch add";
2500 set active first pattern;
2502 | 27 -> (* escape *)
2504 if String.length m_qsearch
= 0
2506 G.postRedisplay "list view escape";
2509 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2511 | None
-> m_prev_uioh
2516 G.postRedisplay "list view kill qsearch";
2517 source#setqsearch
"";
2518 coe {< m_qsearch
= "" >}
2523 let self = {< m_qsearch
= "" >} in
2524 source#setqsearch
"";
2526 G.postRedisplay "listview enter";
2527 if m_active
>= 0 && m_active
< source#getitemcount
2529 source#exit
(coe self) false m_active m_first m_pan
"";
2532 source#exit
(coe self) true m_active m_first m_pan
"";
2535 begin match opt with
2536 | None
-> m_prev_uioh
2540 | 127 -> (* delete *)
2543 | _ -> dolog "unknown key %d" key; coe self
2545 method private special1
key =
2546 let itemcount = source#getitemcount
in
2547 let find start
incr =
2549 if i
= -1 || i
= itemcount
2552 if source#hasaction i
2554 else find (i
+ incr)
2559 let set active first =
2560 let first = bound first 0 (itemcount - fstate.maxrows
) in
2562 coe {< m_active
= active; m_first
= first >}
2565 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2567 let incr1 = if incr > 0 then 1 else -1 in
2568 if isvisible m_first m_active
2571 let next = m_active
+ incr in
2573 if next < 0 || next >= itemcount
2575 else find next incr1
2577 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2583 let first = m_first
+ incr in
2584 let first = bound first 0 (itemcount - 1) in
2586 let next = m_active
+ incr in
2587 let next = bound next 0 (itemcount - 1) in
2590 let active = if next = -1 then m_active
else next in
2593 let first = min
next m_first
in
2596 let first = m_first
+ incr in
2597 let first = bound first 0 (itemcount - 1) in
2599 let next = m_active
+ incr in
2600 let next = bound next 0 (itemcount - 1) in
2601 let next = find next incr1 in
2603 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2605 let active = if m_active
= -1 then next else m_active
in
2610 if isvisible first active
2616 G.postRedisplay "listview navigate";
2619 begin match key with
2620 | Glut.KEY_UP
-> navigate ~
-1
2621 | Glut.KEY_DOWN
-> navigate 1
2622 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2623 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2627 G.postRedisplay "listview right";
2628 coe {< m_pan
= m_pan
- 1 >}
2632 G.postRedisplay "listview left";
2633 coe {< m_pan
= m_pan
+ 1 >}
2636 let active = find 0 1 in
2637 G.postRedisplay "listview home";
2641 let first = max
0 (itemcount - fstate.maxrows
) in
2642 let active = find (itemcount - 1) ~
-1 in
2643 G.postRedisplay "listview end";
2650 match state.mode
with
2651 | Textentry te
-> textentrykeyboard key te
; coe self
2652 | _ -> self#key1
key
2654 method special
key =
2655 match state.mode
with
2656 | Textentry te
-> textentryspecial key te
; coe self
2657 | _ -> self#special1
key
2659 method button button bstate
x y =
2662 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollbw
->
2663 G.postRedisplay "listview scroll";
2664 if bstate
= Glut.DOWN
2666 let _, position, sh = self#
scrollph in
2667 if y > truncate
position && y < truncate
(position +. sh)
2669 state.mstate
<- Mscrolly
;
2673 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2674 let first = truncate
(s *. float source#getitemcount
) in
2675 let first = min source#getitemcount
first in
2676 Some
(coe {< m_first
= first; m_active
= first >})
2678 state.mstate
<- Mnone
;
2681 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2682 begin match self#elemunder
y with
2684 G.postRedisplay "listview click";
2686 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
2690 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2691 let len = source#getitemcount
in
2693 if n = 4 && m_first
+ fstate.maxrows
>= len
2697 let first = m_first
+ (if n == 3 then -1 else 1) in
2698 bound first 0 (len - 1)
2700 G.postRedisplay "listview wheel";
2701 Some
(coe {< m_first
= first >})
2706 | None
-> m_prev_uioh
2710 match state.mstate
with
2712 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2713 let first = truncate
(s *. float source#getitemcount
) in
2714 let first = min source#getitemcount
first in
2715 G.postRedisplay "listview motion";
2716 coe {< m_first
= first; m_active
= first >}
2719 method pmotion
x y =
2720 if x < conf.winw
- conf.scrollbw
2723 match self#elemunder
y with
2724 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
2725 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
2729 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
2734 Glut.setCursor
Glut.CURSOR_INHERIT
;
2738 method infochanged
_ = ()
2740 method scrollpw
= (0, 0.0, 0.0)
2742 let nfs = fstate.fontsize
+ 1 in
2743 let y = m_first
* nfs in
2744 let itemcount = source#getitemcount
in
2745 let maxi = max
0 (itemcount - fstate.maxrows
) in
2746 let maxy = maxi * nfs in
2747 let p, h = scrollph y maxy in
2751 class outlinelistview ~source
=
2753 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
2757 | 14 -> (* ctrl-n *)
2758 source#narrow m_qsearch
;
2759 G.postRedisplay "outline ctrl-n";
2760 coe {< m_first
= 0; m_active
= 0 >}
2762 | 21 -> (* ctrl-u *)
2764 G.postRedisplay "outline ctrl-u";
2766 coe {< m_first
= 0; m_active
= 0 >}
2768 | 12 -> (* ctrl-l *)
2769 let first = m_active
- (fstate.maxrows
/ 2) in
2770 G.postRedisplay "outline ctrl-l";
2771 coe {< m_first
= first >}
2773 | 127 -> (* delete *)
2774 source#remove m_active
;
2775 G.postRedisplay "outline delete";
2776 let active = max
0 (m_active
-1) in
2777 coe {< m_first
= firstof m_first
active;
2778 m_active
= active >}
2780 | key -> super#
key key
2782 method special
key =
2783 let calcfirst first active =
2786 let rows = active - first in
2787 if rows > fstate.maxrows
then active - fstate.maxrows
else first
2791 let active = m_active
+ incr in
2792 let active = bound active 0 (source#getitemcount
- 1) in
2793 let first = calcfirst m_first
active in
2794 G.postRedisplay "special outline navigate";
2795 coe {< m_active
= active; m_first
= first >}
2798 | Glut.KEY_UP
-> navigate ~
-1
2799 | Glut.KEY_DOWN
-> navigate 1
2800 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2801 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2805 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2807 G.postRedisplay "special outline right";
2808 {< m_pan
= m_pan
+ 1 >}
2810 else self#updownlevel
1
2816 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2818 G.postRedisplay "special outline left";
2819 {< m_pan
= m_pan
- 1 >}
2821 else self#updownlevel ~
-1
2826 G.postRedisplay "special outline home";
2827 coe {< m_first
= 0; m_active
= 0 >}
2830 let active = source#getitemcount
- 1 in
2831 let first = max
0 (active - fstate.maxrows
) in
2832 G.postRedisplay "special outline end";
2833 coe {< m_active
= active; m_first
= first >}
2835 | _ -> super#special
key
2838 let outlinesource usebookmarks
=
2841 inherit lvsourcebase
2842 val mutable m_items
= empty
2843 val mutable m_orig_items
= empty
2844 val mutable m_prev_items
= empty
2845 val mutable m_narrow_pattern
= ""
2846 val mutable m_hadremovals
= false
2848 method getitemcount
=
2849 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
2852 if n == Array.length m_items
&& m_hadremovals
2854 ("[Confirm removal]", 0)
2856 let s, n, _ = m_items
.(n) in
2859 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
2860 ignore
(uioh
, first, pan
, qsearch);
2861 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
2863 if String.length m_narrow_pattern
= 0
2869 if not
confrimremoval
2871 let _, _, anchor = m_items
.(active) in
2876 state.bookmarks
<- Array.to_list m_items
;
2877 m_orig_items
<- m_items
;
2880 else m_items
<- items;
2883 method hasaction
_ = true
2886 if Array.length m_items
!= Array.length m_orig_items
2887 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
2890 method narrow
pattern =
2891 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
2895 let rec loop accu n =
2898 m_narrow_pattern
<- pattern;
2899 m_items
<- Array.of_list
accu
2902 let (s, _, _) as o = m_items
.(n) in
2904 if (try ignore
(Str.search_forward
re s 0); true
2905 with Not_found
-> false)
2911 loop [] (Array.length m_items
- 1)
2916 then Array.of_list
state.bookmarks
2919 m_items
<- m_orig_items
2924 if m
>= 0 && m
< Array.length m_items
2926 m_hadremovals
<- true;
2927 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
2928 let n = if n >= m
then n+1 else n in
2933 method reset
anchor items =
2934 m_hadremovals
<- false;
2935 if m_orig_items
== empty || m_prev_items
!= items
2937 m_orig_items
<- items;
2938 if String.length m_narrow_pattern
= 0
2939 then m_items
<- items;
2941 m_prev_items
<- items;
2942 let rely = getanchory anchor in
2944 let rec loop n best bestd
=
2945 if n = Array.length m_items
2948 let (_, _, anchor) = m_items
.(n) in
2949 let orely = getanchory anchor in
2950 let d = abs
(orely - rely) in
2953 else loop (n+1) best bestd
2958 m_first
<- firstof m_first
active
2962 let enterselector usebookmarks
=
2963 let source = outlinesource usebookmarks
in
2967 then Array.of_list
state.bookmarks
2970 if Array.length
outlines = 0
2972 showtext ' ' errmsg
;
2975 state.text <- source#greetmsg
;
2976 Glut.setCursor
Glut.CURSOR_INHERIT
;
2977 let anchor = getanchor () in
2978 source#reset
anchor outlines;
2979 state.uioh
<- coe (new outlinelistview ~
source);
2980 G.postRedisplay "enter selector";
2984 let enteroutlinemode =
2985 let f = enterselector false in
2986 fun ()-> f "Document has no outline";
2989 let enterbookmarkmode =
2990 let f = enterselector true in
2991 fun () -> f "Document has no bookmarks (yet)";
2994 let color_of_string s =
2995 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
2996 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3000 let color_to_string (r, g
, b) =
3001 let r = truncate
(r *. 256.0)
3002 and g
= truncate
(g
*. 256.0)
3003 and b = truncate
(b *. 256.0) in
3004 Printf.sprintf
"%d/%d/%d" r g
b
3007 let irect_of_string s =
3008 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0,y0
,x1
,y1
))
3011 let irect_to_string (x0,y0
,x1
,y1
) =
3012 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3015 let makecheckers () =
3016 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3018 converted by Issac Trotts. July 25, 2002 *)
3019 let image_height = 64
3020 and image_width
= 64 in
3024 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3026 for i
= 0 to image_width
- 1 do
3027 for j
= 0 to image_height - 1 do
3028 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3029 (if (i
land 8 ) lxor (j
land 8) = 0
3030 then [|255;255;255|] else [|200;200;200|])
3035 let image = make_image () in
3036 let id = GlTex.gen_texture
() in
3037 GlTex.bind_texture `texture_2d
id;
3038 GlPix.store
(`unpack_alignment
1);
3039 GlTex.image2d
image;
3040 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3043 `mag_filter `nearest
;
3044 `min_filter `nearest
];
3048 let setcheckers enabled
=
3049 match state.texid
with
3051 if enabled
then state.texid
<- Some
(makecheckers ())
3056 GlTex.delete_texture texid
;
3057 state.texid
<- None
;
3061 let int_of_string_with_suffix s =
3062 let l = String.length
s in
3066 let suffix = Char.lowercase
s.[l-1] in
3068 | 'k'
-> String.sub
s 0 (l-1), 10
3069 | 'm'
-> String.sub
s 0 (l-1), 20
3070 | 'g'
-> String.sub
s 0 (l-1), 30
3074 let n = int_of_string
s1 in
3075 let m = n lsl shift
in
3077 then raise
(Failure
"value too large")
3081 let string_with_suffix_of_int n =
3089 if n land ((1 lsl 20) - 1) = 0
3092 if n land ((1 lsl 10) - 1) = 0
3099 let h = n mod 1000 in
3102 then string_of_int
h ^
s
3104 let s = Printf.sprintf
"_%03d%s" h s in
3111 let describe_location () =
3113 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3115 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3116 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3120 else (100. *. (float state.y /. float maxy))
3124 Printf.sprintf
"page %d of %d [%.2f%%]"
3125 (fn+1) state.pagecount
percent
3128 "pages %d-%d of %d [%.2f%%]"
3129 (fn+1) (ln
+1) state.pagecount
percent
3133 let btos b = if b then "\xe2\x88\x9a" else "" in
3134 let showextended = ref false in
3135 let leave mode
= function
3136 | Confirm
-> state.mode
<- mode
3137 | Cancel
-> state.mode
<- mode
in
3140 val mutable m_first_time
= true
3141 val mutable m_l
= []
3142 val mutable m_a
= [||]
3143 val mutable m_prev_uioh
= nouioh
3144 val mutable m_prev_mode
= View
3146 inherit lvsourcebase
3148 method reset prev_mode prev_uioh
=
3149 m_a
<- Array.of_list
(List.rev m_l
);
3151 m_prev_mode
<- prev_mode
;
3152 m_prev_uioh
<- prev_uioh
;
3156 if n >= Array.length m_a
3160 | _, _, _, Action
_ -> m_active
<- n
3164 m_first_time
<- false;
3167 method int name get
set =
3169 (name
, `
int get
, 1, Action
(
3172 try set (int_of_string
s)
3174 state.text <- Printf.sprintf
"bad integer `%s': %s"
3175 s (Printexc.to_string exn
)
3178 let te = name ^
": ", "", None
, intentry, ondone in
3179 state.mode
<- Textentry
(te, leave m_prev_mode
);
3183 method int_with_suffix name get
set =
3185 (name
, `intws get
, 1, Action
(
3188 try set (int_of_string_with_suffix s)
3190 state.text <- Printf.sprintf
"bad integer `%s': %s"
3191 s (Printexc.to_string exn
)
3195 name ^
": ", "", None
, intentry_with_suffix, ondone
3197 state.mode
<- Textentry
(te, leave m_prev_mode
);
3201 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3203 (name
, `
bool (btos, get
), offset
, Action
(
3210 method color name get
set =
3212 (name
, `color get
, 1, Action
(
3214 let invalid = (nan
, nan
, nan
) in
3217 try color_of_string s
3219 state.text <- Printf.sprintf
"bad color `%s': %s"
3220 s (Printexc.to_string exn
);
3226 let te = name ^
": ", "", None
, textentry, ondone in
3227 state.text <- color_to_string (get
());
3228 state.mode
<- Textentry
(te, leave m_prev_mode
);
3232 method string name get
set =
3234 (name
, `
string get
, 1, Action
(
3236 let ondone s = set s in
3237 let te = name ^
": ", "", None
, textentry, ondone in
3238 state.mode
<- Textentry
(te, leave m_prev_mode
);
3242 method colorspace name get
set =
3244 (name
, `
string get
, 1, Action
(
3247 let vals = [| "rgb"; "bgr"; "gray" |] in
3249 inherit lvsourcebase
3252 m_active
<- int_of_colorspace conf.colorspace
;
3255 method getitemcount
= Array.length
vals
3256 method getitem
n = (vals.(n), 0)
3257 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3258 ignore
(uioh
, first, pan
, qsearch);
3259 if not cancel
then set active;
3261 method hasaction
_ = true
3265 coe (new listview ~
source ~trusted
:true)
3268 method caption
s offset
=
3269 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3271 method caption2
s f offset
=
3272 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3274 method getitemcount
= Array.length m_a
3277 let tostr = function
3278 | `
int f -> string_of_int
(f ())
3279 | `intws
f -> string_with_suffix_of_int (f ())
3281 | `color
f -> color_to_string (f ())
3282 | `
bool (btos, f) -> btos (f ())
3285 let name, t
, offset
, _ = m_a
.(n) in
3286 ((let s = tostr t
in
3287 if String.length
s > 0
3288 then Printf.sprintf
"%s\t%s" name s
3292 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3296 m_qsearch
<- qsearch;
3298 match m_a
.(active) with
3299 | _, _, _, Action
f -> f uioh
3311 method hasaction
n =
3313 | _, _, _, Action
_ -> true
3317 let rec fillsrc prevmode prevuioh
=
3318 let sep () = src#caption
"" 0 in
3319 let colorp name get
set =
3321 (fun () -> color_to_string (get
()))
3324 let c = color_of_string v in
3327 state.text <- Printf.sprintf
"bad color `%s': %s"
3328 v (Printexc.to_string exn
);
3331 let oldmode = state.mode
in
3332 let birdseye = isbirdseye state.mode
in
3334 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3336 src#
bool "presentation mode"
3337 (fun () -> conf.presentation)
3339 conf.presentation <- v;
3340 state.anchor <- getanchor ();
3343 src#
bool "ignore case in searches"
3344 (fun () -> conf.icase
)
3345 (fun v -> conf.icase
<- v);
3348 (fun () -> conf.preload)
3349 (fun v -> conf.preload <- v);
3351 src#
bool "highlight links"
3352 (fun () -> conf.hlinks
)
3353 (fun v -> conf.hlinks
<- v);
3355 src#
bool "under info"
3356 (fun () -> conf.underinfo
)
3357 (fun v -> conf.underinfo
<- v);
3359 src#
bool "persistent bookmarks"
3360 (fun () -> conf.savebmarks
)
3361 (fun v -> conf.savebmarks
<- v);
3363 src#
bool "proportional display"
3364 (fun () -> conf.proportional
)
3365 (fun v -> reqlayout conf.angle
v);
3367 src#
bool "trim margins"
3368 (fun () -> conf.trimmargins
)
3369 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3371 src#
bool "persistent location"
3372 (fun () -> conf.jumpback
)
3373 (fun v -> conf.jumpback
<- v);
3376 src#
int "vertical margin"
3377 (fun () -> conf.interpagespace)
3379 conf.interpagespace <- n;
3381 match state.layout with
3386 state.maxy <- calcheight ();
3387 let y = getpagey pageno in
3392 (fun () -> conf.pagebias
)
3393 (fun v -> conf.pagebias
<- v);
3395 src#
int "scroll step"
3396 (fun () -> conf.scrollstep
)
3397 (fun n -> conf.scrollstep
<- n);
3399 src#
int "auto scroll step"
3401 match state.autoscroll
with
3403 | _ -> conf.autoscrollstep
)
3405 if state.autoscroll
<> None
3406 then state.autoscroll
<- Some
n;
3407 conf.autoscrollstep
<- n);
3410 (fun () -> truncate
(conf.zoom *. 100.))
3411 (fun v -> setzoom ((float v) /. 100.));
3414 (fun () -> conf.angle
)
3415 (fun v -> reqlayout v conf.proportional
);
3417 src#
int "scroll bar width"
3418 (fun () -> state.scrollw
)
3422 reshape conf.winw
conf.winh
;
3425 src#
int "scroll handle height"
3426 (fun () -> conf.scrollh
)
3427 (fun v -> conf.scrollh
<- v;);
3429 src#
int "thumbnail width"
3430 (fun () -> conf.thumbw
)
3432 conf.thumbw
<- min
4096 v;
3435 leavebirdseye beye
false;
3441 src#caption
"Presentation mode" 0;
3442 src#
bool "scrollbar visible"
3443 (fun () -> conf.scrollbarinpm
)
3445 if v != conf.scrollbarinpm
3447 conf.scrollbarinpm
<- v;
3448 if conf.presentation
3450 state.scrollw
<- if v then conf.scrollbw
else 0;
3451 reshape conf.winw
conf.winh
;
3457 src#caption
"Pixmap cache" 0;
3458 src#int_with_suffix
"size (advisory)"
3459 (fun () -> conf.memlimit
)
3460 (fun v -> conf.memlimit
<- v);
3463 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3464 (string_with_suffix_of_int state.memused
)
3465 (Hashtbl.length
state.tilemap
)) 1;
3468 src#caption
"Layout" 0;
3469 src#caption2
"Dimension"
3471 Printf.sprintf
"%dx%d (virtual %dx%d)"
3477 src#caption2
"Position" (fun () ->
3478 Printf.sprintf
"%dx%d" state.x state.y
3481 src#caption2
"Visible" (fun () -> describe_location ()) 1
3485 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3486 "Save these parameters as global defaults at exit"
3487 (fun () -> conf.bedefault
)
3488 (fun v -> conf.bedefault
<- v)
3492 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3493 src#
bool ~offset
:0 ~
btos "Extended parameters"
3494 (fun () -> !showextended)
3495 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3499 (fun () -> conf.checkers
)
3500 (fun v -> conf.checkers
<- v; setcheckers v);
3502 (fun () -> conf.verbose
)
3503 (fun v -> conf.verbose
<- v);
3504 src#
bool "invert colors"
3505 (fun () -> conf.invert
)
3506 (fun v -> conf.invert
<- v);
3508 (fun () -> conf.maxhfit
)
3509 (fun v -> conf.maxhfit
<- v);
3510 src#
bool "redirect stderr"
3511 (fun () -> conf.redirectstderr)
3512 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3513 src#
string "uri launcher"
3514 (fun () -> conf.urilauncher
)
3515 (fun v -> conf.urilauncher
<- v);
3516 src#
string "tile size"
3517 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3520 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3521 conf.tileh
<- max
64 w;
3522 conf.tilew
<- max
64 h;
3525 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3526 v (Printexc.to_string exn
));
3527 src#
int "texture count"
3528 (fun () -> conf.texcount
)
3531 then conf.texcount
<- v
3532 else showtext '
!'
" Failed to set texture count please retry later"
3534 src#
int "slice height"
3535 (fun () -> conf.sliceheight
)
3537 conf.sliceheight
<- v;
3538 wcmd "sliceh" [`i
conf.sliceheight
];
3540 src#
int "anti-aliasing level"
3541 (fun () -> conf.aalevel
)
3543 conf.aalevel
<- bound v 0 8;
3544 state.anchor <- getanchor ();
3545 opendoc state.path
state.password
;
3547 src#
int "ui font size"
3548 (fun () -> fstate.fontsize
)
3549 (fun v -> setfontsize (bound v 5 100));
3550 colorp "background color"
3551 (fun () -> conf.bgcolor
)
3552 (fun v -> conf.bgcolor
<- v);
3553 src#
bool "crop hack"
3554 (fun () -> conf.crophack
)
3555 (fun v -> conf.crophack
<- v);
3556 src#
string "trim fuzz"
3557 (fun () -> irect_to_string conf.trimfuzz
)
3560 conf.trimfuzz
<- irect_of_string v;
3562 then settrim true conf.trimfuzz
;
3564 state.text <- Printf.sprintf
"bad irect `%s': %s"
3565 v (Printexc.to_string exn
)
3567 src#
string "throttle"
3569 match conf.maxwait
with
3570 | None
-> "show place holder if page is not ready"
3573 then "wait for page to fully render"
3575 "wait " ^ string_of_float
time
3576 ^
" seconds before showing placeholder"
3580 let f = float_of_string
v in
3582 then conf.maxwait
<- None
3583 else conf.maxwait
<- Some
f
3585 state.text <- Printf.sprintf
"bad time `%s': %s"
3586 v (Printexc.to_string exn
)
3588 src#colorspace
"color space"
3589 (fun () -> colorspace_to_string conf.colorspace
)
3591 conf.colorspace
<- colorspace_of_int v;
3598 src#caption
"Document" 0;
3599 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3600 src#caption2
"Pages"
3601 (fun () -> string_of_int
state.pagecount
) 1;
3602 src#caption2
"Dimensions"
3603 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3607 src#caption
"Trimmed margins" 0;
3608 src#caption2
"Dimensions"
3609 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3612 src#reset prevmode prevuioh
;
3616 let prevmode = state.mode
3617 and prevuioh
= state.uioh in
3618 fillsrc prevmode prevuioh
;
3619 let source = (src :> lvsource
) in
3620 state.uioh <- coe (object (self)
3621 inherit listview ~
source ~trusted
:true as super
3622 val mutable m_prevmemused
= 0
3623 method infochanged
= function
3625 if m_prevmemused
!= state.memused
3627 m_prevmemused
<- state.memused
;
3628 G.postRedisplay "memusedchanged";
3630 | Pdim
-> G.postRedisplay "pdimchanged"
3631 | Docinfo
-> fillsrc prevmode prevuioh
3633 method special
key =
3634 if Glut.getModifiers
() land Glut.active_ctrl
= 0
3637 | Glut.KEY_LEFT
-> coe (self#updownlevel ~
-1)
3638 | Glut.KEY_RIGHT
-> coe (self#updownlevel
1)
3639 | _ -> super#special
key
3640 else super#special
key
3642 G.postRedisplay "info";
3648 inherit lvsourcebase
3649 method getitemcount
= Array.length
state.help
3651 let s, n, _ = state.help
.(n) in
3654 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3658 m_qsearch
<- qsearch;
3659 match state.help
.(active) with
3660 | _, _, Action
f -> Some
(f uioh)
3670 method hasaction
n =
3671 match state.help
.(n) with
3672 | _, _, Action
_ -> true
3679 state.uioh <- coe (new listview ~
source ~trusted
:true);
3680 G.postRedisplay "help";
3685 let re = Str.regexp
"[\r\n]" in
3687 inherit lvsourcebase
3688 val mutable m_items
= [||]
3690 method getitemcount
= 1 + Array.length m_items
3695 else m_items
.(n-1), 0
3697 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3702 then Buffer.clear
state.errmsgs
;
3703 m_qsearch
<- qsearch;
3710 method hasaction
n =
3714 state.newerrmsgs
<- false;
3715 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
3716 m_items
<- Array.of_list
l
3724 let source = (msgsource :> lvsource
) in
3725 state.uioh <- coe (object
3726 inherit listview ~
source ~trusted
:false as super
3729 then msgsource#reset
;
3732 G.postRedisplay "msgs";
3735 let quickbookmark ?title
() =
3736 match state.layout with
3742 let sec = Unix.gettimeofday
() in
3743 let tm = Unix.localtime
sec in
3744 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
3748 (tm.Unix.tm_year
+ 1900)
3751 | Some
title -> title
3754 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
3759 state.fullscreen
<- None
;
3760 Glut.reshapeWindow
w h;
3763 let viewkeyboard key =
3765 let mode = state.mode in
3766 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
3769 G.postRedisplay "view:enttext"
3771 let c = Char.chr
key in
3773 | '
\027'
| 'q'
-> (* escape *)
3774 begin match state.mstate
with
3776 state.mstate
<- Mnone
;
3777 Glut.setCursor
Glut.CURSOR_INHERIT
;
3778 G.postRedisplay "kill zoom rect";
3783 | '
\008'
-> (* backspace *)
3784 let y = getnav ~
-1 in
3785 gotoy_and_clear_text y
3793 G.postRedisplay "dehighlight";
3796 let ondone isforw
s =
3797 cbput state.hists
.pat
s;
3798 state.searchpattern
<- s;
3801 let s = String.create
1 in
3803 enttext (s, "", Some
(onhist state.hists
.pat
),
3804 textentry, ondone (c ='
/'
))
3806 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3807 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3808 setzoom (conf.zoom +. incr)
3813 try int_of_string
s with exc
->
3814 state.text <- Printf.sprintf
"bad integer `%s': %s"
3815 s (Printexc.to_string exc
);
3821 state.text <- "page bias is now " ^ string_of_int
n;
3824 enttext ("page bias: ", "", None
, intentry, ondone)
3826 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3827 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3828 setzoom (max
0.01 (conf.zoom -. decr))
3831 let ondone msg
= state.text <- msg
in
3833 "option [acfhilpstvAPRSZTI]: ", "", None
,
3834 optentry state.mode, ondone
3837 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3840 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3841 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
3845 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3851 try int_of_string
s with exc
->
3852 state.text <- Printf.sprintf
"bad integer `%s': %s"
3853 s (Printexc.to_string exc
);
3859 cbput state.hists
.pag
(string_of_int
n);
3860 gotoy_and_clear_text (getpagey (n + conf.pagebias
- 1))
3863 let pageentry text key =
3864 match Char.unsafe_chr
key with
3865 | 'g'
-> TEdone
text
3866 | _ -> intentry text key
3868 let text = "x" in text.[0] <- c;
3869 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
3872 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
3873 reshape conf.winw
conf.winh
;
3876 conf.hlinks
<- not
conf.hlinks
;
3877 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
3878 G.postRedisplay "toggle highlightlinks";
3881 begin match state.autoscroll
with
3883 conf.autoscrollstep
<- step
;
3884 state.autoscroll
<- None
3886 if conf.autoscrollstep
= 0
3887 then state.autoscroll
<- Some
1
3888 else state.autoscroll
<- Some
conf.autoscrollstep
3892 conf.presentation <- not
conf.presentation;
3893 if conf.presentation
3895 if not
conf.scrollbarinpm
3896 then state.scrollw
<- 0;
3899 state.scrollw
<- conf.scrollbw
;
3901 showtext ' '
("presentation mode " ^
3902 if conf.presentation then "on" else "off");
3903 state.anchor <- getanchor ();
3907 begin match state.fullscreen
with
3909 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
3912 state.fullscreen
<- None
;
3917 gotoy_and_clear_text 0
3920 gotopage1 (state.pagecount
- 1) 0
3923 search state.searchpattern
true
3926 search state.searchpattern
false
3929 begin match state.layout with
3932 gotoy_and_clear_text (getpagey l.pageno)
3936 begin match List.rev
state.layout with
3939 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
3940 gotoy_and_clear_text (getpagey pageno)
3943 | '
\127'
-> (* del *)
3944 begin match state.layout with
3947 let pageno = max
0 (l.pageno-1) in
3948 gotoy_and_clear_text (getpagey pageno)
3952 showtext ' '
(describe_location ());
3955 begin match state.layout with
3958 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
3963 enterbookmarkmode ()
3971 | '
e'
when conf.redirectstderr ->
3976 match state.layout with
3979 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
3983 enttext ("bookmark: ", "", None
, textentry, ondone)
3987 showtext ' '
"Quick bookmark added";
3990 begin match state.layout with
3992 let rect = getpdimrect
l.pagedimno
in
3996 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
3997 truncate
(1.2 *. (rect.(3) -. rect.(0))))
3999 (truncate
(rect.(1) -. rect.(0)),
4000 truncate
(rect.(3) -. rect.(0)))
4002 let w = truncate
((float w)*.conf.zoom)
4003 and h = truncate
((float h)*.conf.zoom) in
4006 state.anchor <- getanchor ();
4007 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4009 G.postRedisplay "z";
4014 | '
\000'
-> (* ctrl-2 *)
4015 let maxw = getmaxw
() in
4017 then setzoom (maxw /. float conf.winw
)
4020 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
4024 bound (conf.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
4026 G.postRedisplay "brightness";
4029 begin match state.mode with
4030 | Birdseye beye
-> upbirdseye beye
4031 | _ -> gotoy (clamp (-conf.scrollstep
))
4035 begin match state.mode with
4036 | Birdseye beye
-> downbirdseye beye
4037 | _ -> gotoy (clamp conf.scrollstep
)
4041 state.anchor <- getanchor ();
4042 opendoc state.path
state.password
4044 | '
v'
when conf.debug
->
4047 match getopaque l.pageno with
4050 let x0, y0
, x1
, y1
= pagebbox opaque
in
4051 let a,b = float x0, float y0
in
4052 let c,d = float x1
, float y0
in
4053 let e,f = float x1
, float y1
in
4054 let h,j
= float x0, float y1
in
4055 let rect = (a,b,c,d,e,f,h,j
) in
4057 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4059 G.postRedisplay "v";
4062 vlog "huh? %d %c" key (Char.chr
key);
4065 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
4067 | 27 -> (* escape *)
4068 leavebirdseye beye
true
4070 | 12 -> (* ctrl-l *)
4071 let y, h = getpageyh pageno in
4072 let top = (conf.winh
- h) / 2 in
4073 gotoy (max
0 (y - top))
4076 leavebirdseye beye
false
4082 let keyboard ~
key ~
x ~
y =
4085 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
4086 then wcmd "interrupt" []
4087 else state.uioh <- state.uioh#
key key
4090 let birdseyespecial key ((conf, leftx
, _, hooverpageno
, anchor) as beye
) =
4092 | Glut.KEY_UP
-> upbirdseye beye
4093 | Glut.KEY_DOWN
-> downbirdseye beye
4095 | Glut.KEY_PAGE_UP
->
4096 begin match state.layout with
4100 state.mode <- Birdseye
(
4101 conf, leftx
, l.pageno, hooverpageno
, anchor
4103 gotopage1 l.pageno 0;
4106 let layout = layout (state.y-conf.winh
) conf.winh
in
4108 | [] -> gotoy (clamp (-conf.winh
))
4110 state.mode <- Birdseye
(
4111 conf, leftx
, l.pageno, hooverpageno
, anchor
4113 gotopage1 l.pageno 0
4116 | [] -> gotoy (clamp (-conf.winh
))
4119 | Glut.KEY_PAGE_DOWN
->
4120 begin match List.rev
state.layout with
4122 let layout = layout (state.y + conf.winh
) conf.winh
in
4123 begin match layout with
4125 let incr = l.pageh
- l.pagevh in
4130 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4132 G.postRedisplay "birdseye pagedown";
4134 else gotoy (clamp (incr + conf.interpagespace*2));
4138 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
4139 gotopage1 l.pageno 0;
4142 | [] -> gotoy (clamp conf.winh
)
4146 state.mode <- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
4150 let pageno = state.pagecount
- 1 in
4151 state.mode <- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
4152 if not
(pagevisible state.layout pageno)
4155 match List.rev
state.pdims
with
4157 | (_, _, h, _) :: _ -> h
4159 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4160 else G.postRedisplay "birdseye end";
4164 let setautoscrollspeed step goingdown
=
4165 let incr = max
1 ((abs step
) / 2) in
4166 let incr = if goingdown
then incr else -incr in
4167 let astep = step
+ incr in
4168 state.autoscroll
<- Some
astep;
4171 let special ~
key ~
x ~
y =
4174 state.uioh <- state.uioh#
special key
4179 match state.mode with
4180 | Textentry
_ -> scalecolor 0.4
4181 | View
-> scalecolor 1.0
4182 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4183 if l.pageno = hooverpageno
4186 if l.pageno = pageno
4192 begin match getopaque l.pageno with
4194 if tileready l l.pagex l.pagey
4196 let x = l.pagedispx
- l.pagex
4197 and y = l.pagedispy
- l.pagey in
4198 postprocess opaque
conf.hlinks
x y;
4204 let scrollindicator () =
4205 let sbw, ph
, sh = state.uioh#
scrollph in
4206 let sbh, pw
, sw = state.uioh#scrollpw
in
4208 GlDraw.color (0.64, 0.64, 0.64);
4210 (float (conf.winw
- sbw), 0.)
4211 (float conf.winw
, float conf.winh
)
4214 (0., float (conf.winh
- sbh))
4215 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4217 GlDraw.color (0.0, 0.0, 0.0);
4220 (float (conf.winw
- sbw), ph
)
4221 (float conf.winw
, ph
+. sh)
4224 (pw
, float (conf.winh
- sbh))
4225 (pw
+. sw, float conf.winh
)
4229 let pagetranslatepoint l x y =
4230 let dy = y - l.pagedispy
in
4231 let y = dy + l.pagey in
4232 let dx = x - l.pagedispx
in
4233 let x = dx + l.pagex in
4238 match state.mstate
with
4239 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4242 | Msel
((x0, y0
), (x1
, y1
)) ->
4243 let rec loop = function
4245 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
4246 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
4248 match getopaque l.pageno with
4250 let dx, dy = pagetranslatepoint l 0 0 in
4255 GlMat.mode `modelview
;
4257 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4258 seltext opaque
(x0, y0
, x1
, y1
);
4269 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4270 GlDraw.polygon_mode `both `fill
;
4271 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4273 (fun (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
4275 if l.pageno = pageno
4277 let dx = float (l.pagedispx
- l.pagex) in
4278 let dy = float (l.pagedispy
- l.pagey) in
4279 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4280 GlDraw.begins `quads
;
4282 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4283 GlDraw.vertex2
(x1
+.dx, y1
+.dy);
4284 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4285 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4296 GlClear.color (scalecolor2 conf.bgcolor
);
4297 GlClear.clear
[`
color];
4298 List.iter
drawpage state.layout;
4303 begin match state.mstate
with
4304 | Mzoomrect
((x0, y0
), (x1
, y1
)) ->
4306 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4307 GlDraw.polygon_mode `both `fill
;
4308 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4309 GlDraw.rect (float x0, float y0
)
4310 (float x1
, float y1
);
4315 Glut.swapBuffers
();
4319 let rec f = function
4321 begin match getopaque l.pageno with
4323 let x0 = l.pagedispx
in
4324 let x1 = x0 + l.pagevw in
4325 let y0 = l.pagedispy
in
4326 let y1 = y0 + l.pagevh in
4327 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4329 let px, py = pagetranslatepoint l x y in
4330 match whatsunder opaque
px py with
4342 let zoomrect x y x1 y1 =
4345 and y0 = min
y y1 in
4346 gotoy (state.y + y0);
4347 state.anchor <- getanchor ();
4348 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4350 if state.w < conf.winw
- state.scrollw
4351 then (conf.winw
- state.scrollw
- state.w) / 2
4354 state.x <- (state.x + margin) - x0;
4356 Glut.setCursor
Glut.CURSOR_INHERIT
;
4357 state.mstate
<- Mnone
;
4361 let winw = conf.winw - state.scrollw
- 1 in
4362 let s = float x /. float winw in
4363 let destx = truncate
(float (state.w + winw) *. s) in
4364 state.x <- winw - destx;
4365 gotoy_and_clear_text state.y;
4366 state.mstate
<- Mscrollx
;
4370 let s = float y /. float conf.winh
in
4371 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4372 gotoy_and_clear_text desty;
4373 state.mstate
<- Mscrolly
;
4376 let viewmouse button bstate
x y =
4378 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4379 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4381 match state.mstate
with
4382 | Mzoom
(oldn
, i
) ->
4390 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4392 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4394 let zoom = conf.zoom -. incr in
4396 state.mstate
<- Mzoom
(n, 0);
4398 state.mstate
<- Mzoom
(n, i
+1);
4400 else state.mstate
<- Mzoom
(n, 0)
4402 | _ -> state.mstate
<- Mzoom
(n, 0)
4405 match state.autoscroll
with
4406 | Some step
-> setautoscrollspeed step
(n=4)
4410 then -conf.scrollstep
4411 else conf.scrollstep
4413 let incr = incr * 2 in
4414 let y = clamp incr in
4415 gotoy_and_clear_text y
4418 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4419 if bstate
= Glut.DOWN
4421 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4422 state.mstate
<- Mpan
(x, y)
4425 state.mstate
<- Mnone
4427 | Glut.RIGHT_BUTTON
->
4428 if bstate
= Glut.DOWN
4430 Glut.setCursor
Glut.CURSOR_CYCLE
;
4432 state.mstate
<- Mzoomrect
(p, p)
4435 match state.mstate
with
4436 | Mzoomrect
((x0, y0), _) ->
4437 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4438 then zoomrect x0 y0 x y
4440 state.mstate
<- Mnone
;
4441 Glut.setCursor
Glut.CURSOR_INHERIT
;
4442 G.postRedisplay "kill accidental zoom rect";
4445 Glut.setCursor
Glut.CURSOR_INHERIT
;
4446 state.mstate
<- Mnone
4449 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4450 if bstate
= Glut.DOWN
4452 let _, position, sh = state.uioh#
scrollph in
4453 if y > truncate
position && y < truncate
(position +. sh)
4454 then state.mstate
<- Mscrolly
4457 state.mstate
<- Mnone
4459 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4460 if bstate
= Glut.DOWN
4462 let _, position, sw = state.uioh#scrollpw
in
4463 if x > truncate
position && x < truncate
(position +. sw)
4464 then state.mstate
<- Mscrollx
4467 state.mstate
<- Mnone
4469 | Glut.LEFT_BUTTON
->
4470 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4471 begin match dest with
4472 | Ulinkgoto
(pageno, top) ->
4476 gotopage1 pageno top;
4482 | Unone
when bstate
= Glut.DOWN
->
4483 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4484 state.mstate
<- Mpan
(x, y);
4486 | Unone
| Utext
_ ->
4487 if bstate
= Glut.DOWN
4489 if conf.angle
mod 360 = 0
4491 state.mstate
<- Msel
((x, y), (x, y));
4492 G.postRedisplay "mouse select";
4496 match state.mstate
with
4499 | Mzoom
_ | Mscrollx
| Mscrolly
->
4500 state.mstate
<- Mnone
4502 | Mzoomrect
((x0, y0), _) ->
4506 Glut.setCursor
Glut.CURSOR_INHERIT
;
4507 state.mstate
<- Mnone
4509 | Msel
((_, y0), (_, y1)) ->
4511 if (y0 >= l.pagedispy
&& y0 <= (l.pagedispy
+ l.pagevh))
4512 || ((y1 >= l.pagedispy
&& y1 <= (l.pagedispy
+ l.pagevh)))
4514 match getopaque l.pageno with
4519 List.iter
f state.layout;
4520 copysel
""; (* ugly *)
4521 Glut.setCursor
Glut.CURSOR_INHERIT
;
4522 state.mstate
<- Mnone
;
4529 let birdseyemouse button bstate
x y
4530 (conf, leftx
, _, hooverpageno
, anchor) =
4532 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4533 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4534 let rec loop = function
4537 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4538 && x > margin && x < margin + l.pagew
4540 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4545 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4549 let mouse bstate button
x y =
4550 state.uioh <- state.uioh#button button bstate
x y;
4553 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4556 state.uioh <- state.uioh#
motion x y
4560 state.uioh <- state.uioh#
pmotion x y;
4567 begin match state.mode with
4568 | Textentry
textentry -> textentrykeyboard key textentry
4569 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4570 | View
-> viewkeyboard key
4574 method special key =
4575 begin match state.mode with
4576 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4580 birdseyespecial key vals
4582 | View
when key = Glut.KEY_F1
->
4586 begin match state.autoscroll
with
4587 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4588 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4593 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4595 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4597 if Glut.getModifiers
() land Glut.active_shift
!= 0
4598 then (setzoom state.prevzoom
; state.y)
4599 else clamp (-conf.winh
/2)
4600 else clamp (-conf.scrollstep
)
4602 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4604 if Glut.getModifiers
() land Glut.active_shift
!= 0
4605 then (setzoom state.prevzoom
; state.y)
4606 else clamp (conf.winh
/2)
4607 else clamp (conf.scrollstep
)
4608 | Glut.KEY_PAGE_UP
->
4609 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4611 match state.layout with
4613 | l :: _ -> state.y - l.pagey
4616 | Glut.KEY_PAGE_DOWN
->
4617 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4619 match List.rev
state.layout with
4621 | l :: _ -> getpagey l.pageno
4629 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
4631 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
4632 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
4633 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
4635 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
4637 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4638 then (conf.winw / 2)
4641 state.x <- state.x - dx;
4643 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
4645 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4646 then (conf.winw / 2)
4649 state.x <- state.x + dx;
4654 gotoy_and_clear_text y
4657 | Textentry
te -> textentryspecial key te
4661 method button button bstate
x y =
4662 begin match state.mode with
4663 | View
-> viewmouse button bstate
x y
4664 | Birdseye beye
-> birdseyemouse button bstate
x y beye
4670 begin match state.mode with
4672 | View
| Birdseye
_ ->
4673 match state.mstate
with
4674 | Mzoom
_ | Mnone
-> ()
4679 state.mstate
<- Mpan
(x, y);
4680 if conf.zoom > 1.0 then state.x <- state.x + dx;
4682 gotoy_and_clear_text y
4685 state.mstate
<- Msel
(a, (x, y));
4686 G.postRedisplay "motion select";
4689 let y = min
conf.winh
(max
0 y) in
4693 let x = min
conf.winw (max
0 x) in
4696 | Mzoomrect
(p0
, _) ->
4697 state.mstate
<- Mzoomrect
(p0
, (x, y));
4698 G.postRedisplay "motion zoomrect";
4702 method pmotion x y =
4703 begin match state.mode with
4704 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
4705 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4706 let rec loop = function
4708 if hooverpageno
!= -1
4710 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
4711 G.postRedisplay "pmotion birdseye no hoover";
4714 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4715 && x > margin && x < margin + l.pagew
4717 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
4718 G.postRedisplay "pmotion birdseye hoover";
4727 match state.mstate
with
4729 begin match getunder x y with
4730 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
4732 if conf.underinfo
then showtext 'u'
("ri: " ^
uri);
4733 Glut.setCursor
Glut.CURSOR_INFO
4734 | Ulinkgoto
(page
, _) ->
4736 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
4737 Glut.setCursor
Glut.CURSOR_INFO
4739 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
4740 Glut.setCursor
Glut.CURSOR_TEXT
4743 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
4748 method infochanged
_ = ()
4751 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
4752 let p, h = scrollph state.y maxy in
4756 let winw = conf.winw - state.scrollw
- 1 in
4757 let fwinw = float winw in
4759 let sw = fwinw /. float state.w in
4760 let sw = fwinw *. sw in
4761 max
sw (float conf.scrollh
)
4764 let f = state.w+winw in
4765 let r = float (winw-state.x) /. float f in
4766 let p = fwinw *. r in
4770 if position +. sw > fwinw
4771 then fwinw -. position
4774 state.hscrollh, position, sw
4781 let fontpath = ref "";;
4782 let wmclasshack = ref false;;
4785 let l = String.length
s in
4786 let b = Buffer.create
l in
4794 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
4795 | _ -> Sys.getenv
"HOME"
4798 ("Can not determine home directory location: " ^
4799 Printexc.to_string exn
);
4803 let config_of c attrs
=
4807 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
4808 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
4809 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
4810 | "preload" -> { c with preload = bool_of_string
v }
4811 | "page-bias" -> { c with pagebias
= int_of_string
v }
4812 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
4813 | "auto-scroll-step" ->
4814 { c with autoscrollstep
= max
0 (int_of_string
v) }
4815 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
4816 | "crop-hack" -> { c with crophack
= bool_of_string
v }
4819 match String.lowercase
v with
4820 | "true" -> Some infinity
4822 | f -> Some
(float_of_string
f)
4824 { c with maxwait
= mw}
4825 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
4826 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
4827 | "vertical-margin" ->
4828 { c with interpagespace = max
0 (int_of_string
v) }
4830 let zoom = float_of_string
v /. 100. in
4831 let zoom = max
zoom 0.0 in
4832 { c with zoom = zoom }
4833 | "presentation" -> { c with presentation = bool_of_string
v }
4834 | "rotation-angle" -> { c with angle
= int_of_string
v }
4835 | "width" -> { c with winw = max
20 (int_of_string
v) }
4836 | "height" -> { c with winh
= max
20 (int_of_string
v) }
4837 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
4838 | "proportional-display" -> { c with proportional
= bool_of_string
v }
4839 | "pixmap-cache-size" ->
4840 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
4841 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
4842 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
4843 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
4844 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
4845 | "background-color" -> { c with bgcolor
= color_of_string v }
4846 | "scrollbar-in-presentation" ->
4847 { c with scrollbarinpm
= bool_of_string
v }
4848 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
4849 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
4850 | "mupdf-memlimit" ->
4851 { c with mumemlimit
= max
1024 (int_of_string_with_suffix v) }
4852 | "checkers" -> { c with checkers
= bool_of_string
v }
4853 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
4854 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
4855 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
4856 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
4857 | "uri-launcher" -> { c with urilauncher
= unent v }
4858 | "color-space" -> { c with colorspace
= colorspace_of_string v }
4859 | "invert-colors" -> { c with invert
= bool_of_string
v }
4860 | "brightness" -> { c with colorscale
= float_of_string
v }
4861 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
4864 prerr_endline
("Error processing attribute (`" ^
4865 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
4868 let rec fold c = function
4871 let c = apply c k
v in
4877 let fromstring f pos
n v d =
4880 dolog "Error processing attribute (%S=%S) at %d\n%s"
4881 n v pos
(Printexc.to_string exn
)
4886 let bookmark_of attrs
=
4887 let rec fold title page
rely = function
4888 | ("title", v) :: rest
-> fold v page
rely rest
4889 | ("page", v) :: rest
-> fold title v rely rest
4890 | ("rely", v) :: rest
-> fold title page
v rest
4891 | _ :: rest
-> fold title page
rely rest
4892 | [] -> title, page
, rely
4894 fold "invalid" "0" "0" attrs
4898 let rec fold path page
rely pan
= function
4899 | ("path", v) :: rest
-> fold v page
rely pan rest
4900 | ("page", v) :: rest
-> fold path
v rely pan rest
4901 | ("rely", v) :: rest
-> fold path page
v pan rest
4902 | ("pan", v) :: rest
-> fold path page
rely v rest
4903 | _ :: rest
-> fold path page
rely pan rest
4904 | [] -> path
, page
, rely, pan
4906 fold "" "0" "0" "0" attrs
4909 let setconf dst
src =
4910 dst
.scrollbw
<- src.scrollbw
;
4911 dst
.scrollh
<- src.scrollh
;
4912 dst
.icase
<- src.icase
;
4913 dst
.preload <- src.preload;
4914 dst
.pagebias
<- src.pagebias
;
4915 dst
.verbose
<- src.verbose
;
4916 dst
.scrollstep
<- src.scrollstep
;
4917 dst
.maxhfit
<- src.maxhfit
;
4918 dst
.crophack
<- src.crophack
;
4919 dst
.autoscrollstep
<- src.autoscrollstep
;
4920 dst
.maxwait
<- src.maxwait
;
4921 dst
.hlinks
<- src.hlinks
;
4922 dst
.underinfo
<- src.underinfo
;
4923 dst
.interpagespace <- src.interpagespace;
4924 dst
.zoom <- src.zoom;
4925 dst
.presentation <- src.presentation;
4926 dst
.angle
<- src.angle
;
4927 dst
.winw <- src.winw;
4928 dst
.winh
<- src.winh
;
4929 dst
.savebmarks
<- src.savebmarks
;
4930 dst
.memlimit
<- src.memlimit
;
4931 dst
.proportional
<- src.proportional
;
4932 dst
.texcount
<- src.texcount
;
4933 dst
.sliceheight
<- src.sliceheight
;
4934 dst
.thumbw
<- src.thumbw
;
4935 dst
.jumpback
<- src.jumpback
;
4936 dst
.bgcolor
<- src.bgcolor
;
4937 dst
.scrollbarinpm
<- src.scrollbarinpm
;
4938 dst
.tilew
<- src.tilew
;
4939 dst
.tileh
<- src.tileh
;
4940 dst
.mumemlimit
<- src.mumemlimit
;
4941 dst
.checkers
<- src.checkers
;
4942 dst
.aalevel
<- src.aalevel
;
4943 dst
.trimmargins
<- src.trimmargins
;
4944 dst
.trimfuzz
<- src.trimfuzz
;
4945 dst
.urilauncher
<- src.urilauncher
;
4946 dst
.colorspace
<- src.colorspace
;
4947 dst
.invert
<- src.invert
;
4948 dst
.colorscale
<- src.colorscale
;
4949 dst
.redirectstderr <- src.redirectstderr;
4953 let h = Hashtbl.create
10 in
4954 let dc = { defconf with angle
= defconf.angle
} in
4955 let rec toplevel v t spos
_ =
4957 | Vdata
| Vcdata
| Vend
-> v
4958 | Vopen
("llppconfig", _, closed
) ->
4961 else { v with f = llppconfig
}
4963 error
"unexpected subelement at top level" s spos
4964 | Vclose
_ -> error
"unexpected close at top level" s spos
4966 and llppconfig
v t spos
_ =
4968 | Vdata
| Vcdata
-> v
4969 | Vend
-> error
"unexpected end of input in llppconfig" s spos
4970 | Vopen
("defaults", attrs
, closed
) ->
4971 let c = config_of dc attrs
in
4975 else { v with f = skip
"defaults" (fun () -> v) }
4977 | Vopen
("ui-font", attrs
, closed
) ->
4978 let rec getsize size
= function
4980 | ("size", v) :: rest
->
4982 fromstring int_of_string spos
"size" v fstate.fontsize
in
4984 | l -> getsize size l
4986 fstate.fontsize
<- getsize fstate.fontsize attrs
;
4989 else { v with f = uifont
(Buffer.create
10) }
4991 | Vopen
("doc", attrs
, closed
) ->
4992 let pathent, spage
, srely
, span
= doc_of attrs
in
4993 let path = unent pathent
4994 and pageno = fromstring int_of_string spos
"page" spage
0
4995 and rely = fromstring float_of_string spos
"rely" srely
0.0
4996 and pan
= fromstring int_of_string spos
"pan" span
0 in
4997 let c = config_of dc attrs
in
4998 let anchor = (pageno, rely) in
5000 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5001 else { v with f = doc
path pan
anchor c [] }
5004 error
"unexpected subelement in llppconfig" s spos
5006 | Vclose
"llppconfig" -> { v with f = toplevel }
5007 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5009 and uifont
b v t spos epos
=
5012 Buffer.add_substring
b s spos
(epos
- spos
);
5014 | Vopen
(_, _, _) ->
5015 error
"unexpected subelement in ui-font" s spos
5016 | Vclose
"ui-font" ->
5017 if String.length
!fontpath = 0
5018 then fontpath := Buffer.contents
b;
5019 { v with f = llppconfig
}
5020 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5021 | Vend
-> error
"unexpected end of input in ui-font" s spos
5023 and doc
path pan
anchor c bookmarks
v t spos
_ =
5025 | Vdata
| Vcdata
-> v
5026 | Vend
-> error
"unexpected end of input in doc" s spos
5027 | Vopen
("bookmarks", _, closed
) ->
5030 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5032 | Vopen
(_, _, _) ->
5033 error
"unexpected subelement in doc" s spos
5036 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5037 { v with f = llppconfig
}
5039 | Vclose
_ -> error
"unexpected close in doc" s spos
5041 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5043 | Vdata
| Vcdata
-> v
5044 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5045 | Vopen
("item", attrs
, closed
) ->
5046 let titleent, spage
, srely
= bookmark_of attrs
in
5047 let page = fromstring int_of_string spos
"page" spage
0
5048 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5049 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5051 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5054 { v with f = skip
"item" f }
5057 error
"unexpected subelement in bookmarks" s spos
5059 | Vclose
"bookmarks" ->
5060 { v with f = doc
path pan
anchor c bookmarks }
5062 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5064 and skip tag
f v t spos
_ =
5066 | Vdata
| Vcdata
-> v
5068 error
("unexpected end of input in skipped " ^ tag
) s spos
5069 | Vopen
(tag'
, _, closed
) ->
5073 let f'
() = { v with f = skip tag
f } in
5074 { v with f = skip tag'
f'
}
5078 else error
("unexpected close in skipped " ^ tag
) s spos
5081 parse
{ f = toplevel; accu = () } s;
5087 let len = in_channel_length ic
in
5088 let s = String.create
len in
5089 really_input ic
s 0 len;
5092 | Parse_error
(msg
, s, pos
) ->
5093 let subs = subs s pos
in
5094 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5095 failwith
("parse error: " ^
s)
5098 failwith
("config load error: " ^
Printexc.to_string exn
)
5104 let dir = Filename.concat
home ".config" in
5105 if Sys.is_directory
dir then dir else home
5108 Filename.concat
dir "llpp.conf"
5111 let confpath = ref defconfpath;;
5114 if Sys.file_exists
!confpath
5117 (try Some
(open_in_bin
!confpath)
5120 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5121 Printexc.to_string exn
);
5130 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5131 Printexc.to_string exn
);
5137 f (Hashtbl.create
0, defconf)
5142 let pc, pb
, px, pa
=
5144 Hashtbl.find h (Filename.basename
state.path)
5145 with Not_found
-> dc, [], 0, (0, 0.0)
5149 state.bookmarks <- pb
;
5151 state.scrollw
<- conf.scrollbw
;
5153 then state.anchor <- pa
;
5154 cbput state.hists
.nav pa
;
5159 let add_attrs bb always
dc c =
5162 then Printf.bprintf bb
"\n %s='%b'" s a
5165 then Printf.bprintf bb
"\n %s='%d'" s a
5168 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5171 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5174 then Printf.bprintf bb
"\n %s='%f'" s a
5178 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5182 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5186 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5190 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5200 else string_of_float
f
5202 Printf.bprintf bb
"\n %s='%s'" s v
5206 then dc.winw, dc.winh
5208 match state.fullscreen
with
5210 | None
-> c.winw, c.winh
5212 let zoom, presentation, interpagespace, maxwait
=
5214 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5216 match state.mode with
5217 | Birdseye
(bc
, _, _, _, _) ->
5218 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5219 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5221 oi
"width" w dc.winw;
5222 oi
"height" h dc.winh
;
5223 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5224 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5225 ob "case-insensitive-search" c.icase
dc.icase
;
5226 ob "preload" c.preload dc.preload;
5227 oi
"page-bias" c.pagebias
dc.pagebias
;
5228 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5229 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5230 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5231 ob "crop-hack" c.crophack
dc.crophack
;
5232 oW
"throttle" maxwait
dc.maxwait
;
5233 ob "highlight-links" c.hlinks
dc.hlinks
;
5234 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5235 oi
"vertical-margin" interpagespace dc.interpagespace;
5236 oz
"zoom" zoom dc.zoom;
5237 ob "presentation" presentation dc.presentation;
5238 oi
"rotation-angle" c.angle
dc.angle
;
5239 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5240 ob "proportional-display" c.proportional
dc.proportional
;
5241 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5242 oi
"tex-count" c.texcount
dc.texcount
;
5243 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5244 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5245 ob "persistent-location" c.jumpback
dc.jumpback
;
5246 oc
"background-color" c.bgcolor
dc.bgcolor
;
5247 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5248 oi
"tile-width" c.tilew
dc.tilew
;
5249 oi
"tile-height" c.tileh
dc.tileh
;
5250 oI
"mupdf-memlimit" c.mumemlimit
dc.mumemlimit
;
5251 ob "checkers" c.checkers
dc.checkers
;
5252 oi
"aalevel" c.aalevel
dc.aalevel
;
5253 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5254 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5255 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5256 oC
"color-space" c.colorspace
dc.colorspace
;
5257 ob "invert-colors" c.invert
dc.invert
;
5258 oF
"brightness" c.colorscale
dc.colorscale
;
5259 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5261 then ob "wmclass-hack" !wmclasshack false;
5265 let uifontsize = fstate.fontsize
in
5266 let bb = Buffer.create
32768 in
5268 let dc = if conf.bedefault
then conf else dc in
5269 Buffer.add_string
bb "<llppconfig>\n";
5271 if String.length
!fontpath > 0
5273 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5279 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5282 Buffer.add_string
bb "<defaults ";
5283 add_attrs bb true dc dc;
5284 Buffer.add_string
bb "/>\n";
5286 let adddoc path pan
anchor c bookmarks =
5287 if bookmarks == [] && c = dc && anchor = emptyanchor
5290 Printf.bprintf
bb "<doc path='%s'"
5291 (enent
path 0 (String.length
path));
5293 if anchor <> emptyanchor
5295 let n, y = anchor in
5296 Printf.bprintf
bb " page='%d'" n;
5299 Printf.bprintf
bb " rely='%f'" y
5304 then Printf.bprintf
bb " pan='%d'" pan
;
5306 add_attrs bb false dc c;
5308 begin match bookmarks with
5309 | [] -> Buffer.add_string
bb "/>\n"
5311 Buffer.add_string
bb ">\n<bookmarks>\n";
5312 List.iter
(fun (title, _level
, (page, rely)) ->
5314 "<item title='%s' page='%d'"
5315 (enent
title 0 (String.length
title))
5320 Printf.bprintf
bb " rely='%f'" rely
5322 Buffer.add_string
bb "/>\n";
5324 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5330 match state.mode with
5331 | Birdseye
(_, pan, _, _, _) -> pan
5334 let basename = Filename.basename state.path in
5335 adddoc basename pan (getanchor ())
5338 match state.autoscroll
with
5340 | None
-> conf.autoscrollstep
}
5341 (if conf.savebmarks
then state.bookmarks else []);
5343 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5345 then adddoc path x y c bookmarks
5347 Buffer.add_string
bb "</llppconfig>";
5350 if Buffer.length
bb > 0
5353 let tmp = !confpath ^
".tmp" in
5354 let oc = open_out_bin
tmp in
5355 Buffer.output_buffer
oc bb;
5357 Unix.rename
tmp !confpath;
5360 ("error while saving configuration: " ^
Printexc.to_string exn
)
5367 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5368 "<password> Set password");
5370 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5371 "<path> Set path to the user interface font");
5373 ("-c", Arg.String
(fun s -> Config.confpath := s),
5374 "<path> Set path to the configuration file");
5376 ("-v", Arg.Unit
(fun () ->
5378 "%s\nconfiguration path: %s\n"
5382 exit
0), " Print version and exit");
5385 (fun s -> state.path <- s)
5386 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5388 if String.length
state.path = 0
5389 then (prerr_endline
"file name missing"; exit
1);
5393 let _ = Glut.init
Sys.argv
in
5394 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5395 let () = Glut.initWindowSize
conf.winw conf.winh
in
5396 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5398 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5399 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5400 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5405 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5407 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5408 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5409 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5410 Unix.bind
sock addr;
5412 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5413 Unix.connect
csock addr;
5414 let ssock, _ = Unix.accept
sock in
5417 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5418 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5425 let () = Glut.displayFunc
display in
5426 let () = Glut.reshapeFunc
reshape in
5427 let () = Glut.keyboardFunc
keyboard in
5428 let () = Glut.specialFunc
special in
5429 let () = Glut.idleFunc
(Some
idle) in
5430 let () = Glut.mouseFunc
mouse in
5431 let () = Glut.motionFunc
motion in
5432 let () = Glut.passiveMotionFunc
pmotion in
5434 setcheckers conf.checkers
;
5436 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5437 conf.texcount
, conf.sliceheight
, conf.mumemlimit
, conf.colorspace
,
5438 !Config.wmclasshack, !Config.fontpath
5440 state.csock <- csock;
5441 state.ssock <- ssock;
5442 state.text <- "Opening " ^
state.path;
5443 setaalevel
conf.aalevel
;
5444 writeopen state.path state.password
;
5446 setfontsize fstate.fontsize
;
5454 | Glut.BadEnum
"key in special_of_int" ->
5455 showtext '
!'
" LablGlut bug: special key not recognized";
5462 | exn
when conf.redirectstderr ->
5464 Printf.sprintf
"exception %s\n%s"
5465 (Printexc.to_string exn
)
5466 (Printexc.get_backtrace
())
5469 Unix.single_write
state.stderr
s 0 (String.length
s);