4 | Ulinkgoto
of (int * int)
6 and facename
= string;;
8 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
9 let dolog2 fmt
= Printf.kprintf print_endline fmt
;;
10 let now = Unix.gettimeofday
;;
14 type params
= (angle
* proportional
* trimparams
15 * texcount
* sliceheight
* memsize
16 * colorspace
* wmclasshack
* fontpath
)
25 and proportional
= bool
26 and trimmargins
= bool
27 and interpagespace
= int
35 and wmclasshack
= bool
36 and irect
= (int * int * int * int)
37 and trimparams
= (trimmargins
* irect
)
38 and colorspace
= | Rgb
| Bgr
| Gray
41 type platform
= | Punknown
| Plinux
| Pwindows
| Posx
| Psun
42 | Pfreebsd
| Pdragonflybsd
| Popenbsd
| Pmingw
| Pcygwin
;;
44 external init
: Unix.file_descr
-> params
-> unit = "ml_init";;
45 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
46 external copysel
: string -> unit = "ml_copysel";;
47 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
48 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
49 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
50 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
51 external measurestr
: int -> string -> float = "ml_measure_string";;
52 external getmaxw
: unit -> float = "ml_getmaxw";;
53 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
54 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
55 external platform
: unit -> platform
= "ml_platform";;
56 external setaalevel
: int -> unit = "ml_setaalevel";;
57 external realloctexts
: int -> bool = "ml_realloctexts";;
59 let platform_to_string = function
60 | Punknown
-> "unknown"
62 | Pwindows
-> "Windows"
65 | Pfreebsd
-> "FreeBSD"
66 | Pdragonflybsd
-> "DragonflyBSD"
67 | Popenbsd
-> "OpenBSD"
72 let platform = platform ();;
76 | Pwindows
| Pmingw
-> true
84 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
87 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
91 | Msel
of (mpos
* mpos
)
94 | Mzoom
of (int * int)
95 | Mzoomrect
of (mpos
* mpos
)
99 type textentry
= string * string * onhist
option * onkey
* ondone
100 and onkey
= string -> int -> te
101 and ondone
= string -> unit
102 and histcancel
= unit -> unit
103 and onhist
= ((histcmd
-> string) * histcancel
)
104 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
109 | TEswitch
of textentry
120 let bound v minv maxv
=
121 max minv
(min maxv v
);
125 { store
= Array.create n v
132 let drawstring size x y s
=
134 Gl.enable `texture_2d
;
135 ignore
(drawstr size x y s
);
137 Gl.disable `texture_2d
;
140 let drawstring1 size x y s
=
144 let drawstring2 size x y fmt
=
145 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
148 let cbcap b
= Array.length b
.store
;;
153 b
.wc
<- (b
.wc
+ 1) mod cap;
155 b
.len
<- min
(b
.len
+ 1) cap;
158 let cbempty b
= b
.len
= 0;;
160 let cbgetg b circular dir
=
164 let rc = b
.rc + dir
in
176 else max
0 (min
rc (b
.len
-1))
182 let cbget b
= cbgetg b
false;;
183 let cbgetc b
= cbgetg b
true;;
200 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
201 dolog " WxH %dx%d" l
.pagew l
.pageh
;
202 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
203 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
204 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
208 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
210 dolog " x0,y0=(% f, % f)" x0 y0
;
211 dolog " x1,y1=(% f, % f)" x1 y1
;
212 dolog " x2,y2=(% f, % f)" x2 y2
;
213 dolog " x3,y3=(% f, % f)" x3 y3
;
218 { mutable scrollbw
: int
219 ; mutable scrollh
: int
220 ; mutable icase
: bool
221 ; mutable preload
: bool
222 ; mutable pagebias
: int
223 ; mutable verbose
: bool
224 ; mutable debug
: bool
225 ; mutable scrollstep
: int
226 ; mutable maxhfit
: bool
227 ; mutable crophack
: bool
228 ; mutable autoscrollstep
: int
229 ; mutable maxwait
: float option
230 ; mutable hlinks
: bool
231 ; mutable underinfo
: bool
232 ; mutable interpagespace
: interpagespace
233 ; mutable zoom
: float
234 ; mutable presentation
: bool
235 ; mutable angle
: angle
238 ; mutable savebmarks
: bool
239 ; mutable proportional
: proportional
240 ; mutable trimmargins
: trimmargins
241 ; mutable trimfuzz
: irect
242 ; mutable memlimit
: memsize
243 ; mutable texcount
: texcount
244 ; mutable sliceheight
: sliceheight
245 ; mutable thumbw
: width
246 ; mutable jumpback
: bool
247 ; mutable bgcolor
: float * float * float
248 ; mutable bedefault
: bool
249 ; mutable scrollbarinpm
: bool
250 ; mutable tilew
: int
251 ; mutable tileh
: int
252 ; mutable mumemlimit
: memsize
253 ; mutable checkers
: bool
254 ; mutable aalevel
: int
255 ; mutable urilauncher
: string
256 ; mutable colorspace
: colorspace
257 ; mutable invert
: bool
258 ; mutable colorscale
: float
259 ; mutable redirectstderr
: bool
263 type anchor
= pageno
* top
;;
265 type outline
= string * int * anchor
;;
267 type rect
= float * float * float * float * float * float * float * float;;
269 type tile
= opaque
* pixmapsize
* elapsed
270 and elapsed
= float;;
271 type pagemapkey
= pageno
* gen
;;
272 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
276 let emptyanchor = (0, 0.0);;
278 type infochange
= | Memused
| Docinfo
| Pdim
;;
280 class type uioh
= object
281 method display
: unit
282 method key
: int -> uioh
283 method special
: Glut.special_key_t
-> uioh
285 Glut.button_t
-> Glut.mouse_button_state_t
-> int -> int -> uioh
286 method motion
: int -> int -> uioh
287 method pmotion
: int -> int -> uioh
288 method infochanged
: infochange
-> unit
289 method scrollpw
: (int * float * float)
290 method scrollph
: (int * float * float)
294 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
295 | Textentry
of (textentry
* onleave
)
297 and onleave
= leavetextentrystatus
-> unit
298 and leavetextentrystatus
= | Cancel
| Confirm
299 and helpitem
= string * int * action
302 | Action
of (uioh
-> uioh
)
305 let isbirdseye = function Birdseye _
-> true | _
-> false;;
306 let istextentry = function Textentry _
-> true | _
-> false;;
310 | Loading
of (page
* gen
)
312 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
314 | Outlining
of outline list
317 let nouioh : uioh
= object (self
)
320 method special _
= self
321 method button _ _ _ _
= self
322 method motion _ _
= self
323 method pmotion _ _
= self
324 method infochanged _
= ()
325 method scrollpw
= (0, nan
, nan
)
326 method scrollph
= (0, nan
, nan
)
330 { mutable csock
: Unix.file_descr
331 ; mutable ssock
: Unix.file_descr
332 ; mutable errfd
: Unix.file_descr
option
333 ; mutable stderr
: Unix.file_descr
334 ; mutable errmsgs
: Buffer.t
335 ; mutable newerrmsgs
: bool
339 ; mutable scrollw
: int
340 ; mutable hscrollh
: int
341 ; mutable anchor
: anchor
343 ; mutable layout
: page list
344 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
345 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
346 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
347 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
348 ; mutable pagecount
: int
349 ; mutable currently
: currently
350 ; mutable mstate
: mstate
351 ; mutable searchpattern
: string
352 ; mutable rects
: (pageno
* recttype
* rect
) list
353 ; mutable rects1
: (pageno
* recttype
* rect
) list
354 ; mutable text
: string
355 ; mutable fullscreen
: (width
* height
) option
356 ; mutable mode
: mode
357 ; mutable uioh
: uioh
358 ; mutable outlines
: outline array
359 ; mutable bookmarks
: outline list
360 ; mutable path
: string
361 ; mutable password
: string
362 ; mutable invalidated
: int
363 ; mutable memused
: memsize
365 ; mutable throttle
: (page list
* int * float) option
366 ; mutable autoscroll
: int option
367 ; mutable help
: helpitem array
368 ; mutable docinfo
: (int * string) list
369 ; mutable deadline
: float
370 ; mutable texid
: GlTex.texture_id
option
372 ; mutable prevzoom
: float
373 ; mutable progress
: float
376 { pat
: string circbuf
377 ; pag
: string circbuf
378 ; nav
: anchor circbuf
399 ; presentation
= false
404 ; proportional
= true
405 ; trimmargins
= false
406 ; trimfuzz
= (0,0,0,0)
407 ; memlimit
= 32 lsl 20
412 ; bgcolor
= (0.5, 0.5, 0.5)
414 ; scrollbarinpm
= true
417 ; mumemlimit
= 128 lsl 20
422 | Plinux
| Pfreebsd
| Pdragonflybsd
| Popenbsd
| Psun
-> "xdg-open \"%s\""
423 | Posx
-> "open \"%s\""
424 | Pwindows
| Pcygwin
| Pmingw
-> "iexplore \"%s\""
429 ; redirectstderr
= false
433 let conf = { defconf with angle
= defconf.angle
};;
436 { mutable fontsize
: int
437 ; mutable wwidth
: float
438 ; mutable maxrows
: int
450 fstate.fontsize
<- n
;
451 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
452 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
456 if String.length
conf.urilauncher
= 0
457 then print_endline uri
459 let re = Str.regexp
"%s" in
460 let command = Str.global_replace
re uri
conf.urilauncher
in
462 try Some
(Unix.open_process_in
command)
465 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
470 | Some ic
-> close_in ic
475 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
476 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
480 let strings = version () :: "" :: Help.keys
in
482 let r = Str.regexp
"\\(http://[^ ]+\\)" in
484 if (try Str.search_forward
r s
0 with Not_found
-> -1) >= 0
486 let uri = Str.matched_string s
in
487 (s
, 0, Action
(fun u
-> gotouri uri; u
))
488 else s
, 0, Noaction
) strings
496 ; stderr
= Unix.stderr
497 ; errmsgs
= Buffer.create
0
504 ; anchor
= emptyanchor
507 ; tilelru
= Queue.create
()
508 ; pagemap
= Hashtbl.create
10
509 ; tilemap
= Hashtbl.create
10
526 { nav
= cbnew 10 (0, 0.0)
547 Printf.kprintf prerr_endline fmt
549 Printf.kprintf ignore fmt
552 let redirectstderr () =
553 if conf.redirectstderr
555 let rfd, wfd
= Unix.pipe
() in
556 state.stderr
<- Unix.dup
Unix.stderr
;
557 state.errfd
<- Some
rfd;
558 Unix.dup2 wfd
Unix.stderr
;
560 state.newerrmsgs
<- false;
561 begin match state.errfd
with
564 Unix.dup2
state.stderr
Unix.stderr
;
568 prerr_string
(Buffer.contents
state.errmsgs
);
570 Buffer.clear
state.errmsgs
;
576 let postRedisplay who
=
578 then prerr_endline
("redisplay for " ^ who
);
579 Glut.postRedisplay ();
584 let b = Buffer.create
(String.length s
+ 1) in
585 Buffer.add_string
b s
;
590 let colorspace_of_string s
=
591 match String.lowercase s
with
595 | _
-> failwith
"invalid colorspace"
598 let int_of_colorspace = function
604 let colorspace_of_int = function
608 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
611 let colorspace_to_string = function
617 let intentry_with_suffix text key
=
618 let c = Char.unsafe_chr key
in
619 match Char.lowercase
c with
621 let text = addchar text c in
625 let text = addchar text c in
629 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
634 let len = String.length s
in
636 let b = Buffer.create
n in
637 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
638 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
639 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
640 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
641 Buffer.add_string
b s
;
642 let s'
= Buffer.contents
b in
643 let n'
= Unix.write fd
s'
0 n in
644 if n'
!= n then failwith
"write failed";
649 let n = Unix.read fd
s 0 4 in
650 if n != 4 then failwith
"incomplete read(len)";
652 lor (Char.code
s.[0] lsl 24)
653 lor (Char.code
s.[1] lsl 16)
654 lor (Char.code
s.[2] lsl 8)
655 lor (Char.code
s.[3] lsl 0)
657 let s = String.create
len in
658 let n = Unix.read fd
s 0 len in
659 if n != len then failwith
"incomplete read(data)";
664 let b = Buffer.create
10 in
665 Buffer.add_string
b s;
666 let rec combine = function
669 Buffer.add_char
b ' '
;
672 | `
b b -> if b then "1" else "0"
674 | `i i
-> string_of_int i
675 | `f f
-> string_of_float f
676 | `I f
-> string_of_int
(truncate f
)
678 Buffer.add_string
b s;
685 let cmd = Buffer.contents
(makecmd s l
) in
686 writecmd state.csock
cmd;
692 let d = conf.winh
- h
in
699 let rec f pn ph pi fh l
=
701 | (n, _
, h
, _
) :: rest
->
702 let ips = calcips h
in
707 if isbirdseye state.mode
&& pn
= 0
712 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
717 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
721 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
724 let fh = f 0 0 0 0 state.pdims
in
728 let getpageyh pageno
=
729 let rec f pn ph pi y l
=
731 | (n, _
, h
, _
) :: rest
->
732 let ips = calcips h
in
735 let h = if n = pageno
then h else ph
in
736 if conf.presentation
&& n = pageno
738 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
740 y
+ (pageno
- pn
) * (ph
+ pi
), h
742 let y = y + (if conf.presentation
then pi
else 0) in
743 let y = y + (n - pn
) * (ph
+ pi
) in
747 y + (pageno
- pn
) * (ph
+ pi
), ph
749 f 0 0 0 0 state.pdims
752 let getpagedim pageno
=
755 | (n, _
, _
, _
) as pdim
:: rest
->
757 then (if n = pageno
then pdim
else ppdim
)
762 f (-1, -1, -1, -1) state.pdims
765 let getpagey pageno
= fst
(getpageyh pageno
);;
768 let sh = sh - state.hscrollh
in
769 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
770 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
772 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
773 let ips = calcips h in
775 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
779 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
781 prev
, pdims
, pdimno
, 0
783 let dy = dy + yinc in
784 let py = py + yinc in
785 if pageno
= state.pagecount
|| dy >= sh
790 if py + h <= vy - yinc
792 let py = py + h + ips in
793 let dy = max
0 (py - y) in
802 let pagey = vy - py in
803 let pagevh = h - pagey in
804 let pagevh = min
(sh - dy) pagevh in
805 let off = if yinc > 0 then py - vy else 0 in
806 let py = py + h + ips in
809 if state.w
< conf.winw
- state.scrollw
810 then (conf.winw
- state.scrollw
- state.w
) / 2
813 let dispx = xoff + state.x
in
819 let lw = w
- pagex in
820 min
lw (conf.winw
- state.scrollw
)
828 ; pagey = pagey + off
830 ; pagevh = pagevh - off
832 ; pagedispy
= dy + off
835 let accu = e :: accu in
844 if state.invalidated
= 0
863 let y = state.y + incr
in
865 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
869 let getopaque pageno
=
870 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
871 with Not_found
-> None
874 let putopaque pageno opaque
=
875 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
879 let tilex = l
.pagex mod conf.tilew
in
880 let tiley = l
.pagey mod conf.tileh
in
882 let col = l
.pagex / conf.tilew
in
883 let row = l
.pagey / conf.tileh
in
886 let a = l
.pagew
- l
.pagex in
887 let b = conf.winw
- state.scrollw
in
891 let rec rowloop row y0 dispy
h =
895 let dh = conf.tileh
- y0
in
897 let rec colloop col x0
dispx w
=
901 let dw = conf.tilew
- x0
in
904 f col row dispx dispy x0 y0
dw dh;
905 colloop (col+1) 0 (dispx+dw) (w
-dw)
908 colloop col tilex l
.pagedispx
vw;
909 rowloop (row+1) 0 (dispy
+dh) (h-dh)
913 then rowloop row tiley l
.pagedispy vh
;
916 let gettileopaque l
col row =
918 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
920 try Some
(Hashtbl.find
state.tilemap
key)
921 with Not_found
-> None
924 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
925 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
926 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
929 let drawtiles l color
=
931 let f col row x
y tilex tiley w
h =
932 match gettileopaque l
col row with
933 | Some
(opaque
, _
, t
) ->
934 let params = x
, y, w
, h, tilex, tiley in
938 GlFunc.blend_func `zero `one_minus_src_color
;
940 drawtile
params opaque
;
942 then Gl.disable `blend
;
945 let s = Printf.sprintf
949 let w = measurestr
fstate.fontsize
s in
950 GlMisc.push_attrib
[`current
];
951 GlDraw.color
(0.0, 0.0, 0.0);
953 (float (x
-2), float (y-2))
954 (float (x
+2) +. w, float (y + fstate.fontsize
+ 2));
955 GlDraw.color
(1.0, 1.0, 1.0);
956 drawstring fstate.fontsize x
(y + fstate.fontsize
- 1) s;
957 GlMisc.pop_attrib
();
962 let lw = conf.winw
- state.scrollw
- x
in
965 let lh = conf.winh
- y in
968 Gl.enable `texture_2d
;
969 begin match state.texid
with
971 GlTex.bind_texture `texture_2d id
;
975 and y1
= float (y+h) in
977 let tw = float w /. 64.0
978 and th
= float h /. 64.0 in
979 let tx0 = float tilex /. 64.0
980 and ty0
= float tiley /. 64.0 in
982 and ty1
= ty0
+. th
in
983 GlDraw.begins `quads
;
984 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
985 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
986 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
987 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
990 Gl.disable `texture_2d
;
992 GlDraw.color
(1.0, 1.0, 1.0);
995 (float (x
+w), float (y+h));
997 if w > 128 && h > fstate.fontsize
+ 10
999 GlDraw.color
(0.0, 0.0, 0.0);
1002 then (col*conf.tilew
, row*conf.tileh
)
1005 drawstring2 fstate.fontsize x
y "Loading %d [%d,%d]" l
.pageno
c r;
1012 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1014 let tilevisible1 l x
y =
1016 and ax1
= l
.pagex + l
.pagevw
1018 and ay1
= l
.pagey + l
.pagevh in
1022 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1023 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1025 let rx0 = max
ax0 bx0
1026 and ry0
= max ay0 by0
1027 and rx1
= min ax1
bx1
1028 and ry1
= min ay1 by1
in
1030 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1031 nonemptyintersection
1034 let tilevisible layout n x
y =
1035 let rec findpageinlayout = function
1036 | l
:: _
when l
.pageno
= n -> tilevisible1 l x
y
1037 | _
:: rest
-> findpageinlayout rest
1040 findpageinlayout layout
1043 let tileready l x
y =
1044 tilevisible1 l x
y &&
1045 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
1048 let tilepage n p
layout =
1049 let rec loop = function
1053 let f col row _ _ _ _ _ _
=
1054 if state.currently
= Idle
1056 match gettileopaque l
col row with
1059 let x = col*conf.tilew
1060 and y = row*conf.tileh
in
1062 let w = l
.pagew
- x in
1066 let h = l
.pageh
- y in
1078 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1079 conf.tilew
, conf.tileh
1088 if state.invalidated
= 0 then loop layout;
1091 let preloadlayout visiblepages
=
1092 let presentation = conf.presentation in
1093 let interpagespace = conf.interpagespace in
1094 let maxy = state.maxy in
1095 conf.presentation <- false;
1096 conf.interpagespace <- 0;
1097 state.maxy <- calcheight ();
1099 match visiblepages
with
1101 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1103 let y = if y < conf.winh
then 0 else y - conf.winh
in
1104 let h = state.y - y + conf.winh
*3 in
1105 let pages = layout y h in
1106 conf.presentation <- presentation;
1107 conf.interpagespace <- interpagespace;
1113 let rec loop pages =
1114 if state.currently
!= Idle
1119 begin match getopaque l
.pageno
with
1121 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1122 state.currently
<- Loading
(l
, state.gen
);
1124 tilepage l
.pageno opaque
pages;
1129 if state.invalidated
= 0 then loop pages
1134 if conf.preload && state.currently
= Idle
1135 then load (preloadlayout pages);
1138 let layoutready layout =
1139 let rec fold all ls
=
1140 all
&& match ls
with
1142 let seen = ref false in
1143 let allvisible = ref true in
1144 let foo col row _ _ _ _ _ _
=
1146 allvisible := !allvisible &&
1147 begin match gettileopaque l
col row with
1153 fold (!seen && !allvisible) rest
1156 let alltilesvisible = fold true layout in
1161 let y = bound y 0 state.maxy in
1162 let y, layout, proceed
=
1163 match conf.maxwait
with
1165 begin match state.throttle
with
1167 let layout = layout y conf.winh
in
1168 let ready = layoutready layout in
1172 state.throttle
<- Some
(layout, y, now ());
1174 else G.postRedisplay "gotoy showall (None)";
1176 | Some
(_
, _
, started
) ->
1177 let dt = now () -. started
in
1180 state.throttle
<- None
;
1181 let layout = layout y conf.winh
in
1183 G.postRedisplay "maxwait";
1190 let layout = layout y conf.winh
in
1191 if true || layoutready layout
1192 then G.postRedisplay "gotoy ready";
1198 state.layout <- layout;
1199 begin match state.mode
with
1200 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1201 if not
(pagevisible layout pageno
)
1203 match state.layout with
1206 state.mode
<- Birdseye
(
1207 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1216 let conttiling pageno opaque
=
1217 tilepage pageno opaque
1218 (if conf.preload then preloadlayout state.layout else state.layout)
1221 let gotoy_and_clear_text y =
1223 if not
conf.verbose
then state.text <- "";
1227 match state.layout with
1229 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1232 let getanchory (n, top
) =
1233 let y, h = getpageyh n in
1234 y + (truncate
(top
*. float h));
1237 let gotoanchor anchor
=
1238 gotoy (getanchory anchor
);
1242 cbput state.hists
.nav
(getanchor ());
1246 let anchor = cbgetc state.hists
.nav dir
in
1250 let gotopage n top
=
1251 let y, h = getpageyh n in
1252 gotoy_and_clear_text (y + (truncate
(top
*. float h)));
1255 let gotopage1 n top
=
1256 let y = getpagey n in
1257 gotoy_and_clear_text (y + top
);
1265 state.invalidated
<- state.invalidated
+ 1;
1268 let writeopen path password
=
1269 writecmd state.csock
("open " ^ path ^
"\000" ^ password ^
"\000");
1272 let opendoc path password
=
1275 state.password
<- password
;
1276 state.gen
<- state.gen
+ 1;
1277 state.docinfo
<- [];
1279 setaalevel
conf.aalevel
;
1280 writeopen path password
;
1281 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1282 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1286 let c = c *. conf.colorscale
in
1290 let scalecolor2 (r, g
, b) =
1291 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1295 state.maxy <- calcheight ();
1297 if state.w <= conf.winw
- state.scrollw
1301 match state.mode
with
1302 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1303 let y, h = getpageyh pageno
in
1304 let top = (conf.winh
- h) / 2 in
1305 gotoy (max
0 (y - top))
1306 | _
-> gotoanchor state.anchor
1310 let firsttime = ref true in
1312 GlDraw.viewport
0 0 w h;
1313 if state.invalidated
= 0 && not
!firsttime
1314 then state.anchor <- getanchor ();
1318 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1322 setfontsize fstate.fontsize
;
1323 GlMat.mode `modelview
;
1324 GlMat.load_identity
();
1326 GlMat.mode `projection
;
1327 GlMat.load_identity
();
1328 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1329 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1330 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1333 wcmd "geometry" [`i
w; `i
h];
1337 let len = String.length
state.text in
1340 match state.mode
with
1341 | View
-> state.hscrollh
1346 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1347 (x+.w, float (conf.winh
- hscrollh))
1350 let w = float (conf.winw
- state.scrollw
- 1) in
1351 if state.progress
>= 0.0 && state.progress
< 1.0
1353 GlDraw.color
(0.3, 0.3, 0.3);
1354 let w1 = w *. state.progress
in
1356 GlDraw.color
(0.0, 0.0, 0.0);
1360 GlDraw.color
(0.0, 0.0, 0.0);
1364 GlDraw.color
(1.0, 1.0, 1.0);
1365 drawstring fstate.fontsize
1366 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1369 match state.mode
with
1370 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1374 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1376 Printf.sprintf
"%s%s_" prefix
text
1385 if not
(istextentry state.mode
)
1387 let s1 = "(press 'e' to review error messasges)" in
1388 if String.length
s > 0 then s ^
" " ^
s1 else s1
1393 if String.length
s > 0
1398 state.text <- Printf.sprintf
"%c%s" c s;
1399 G.postRedisplay "showtext";
1403 let len = Queue.length
state.tilelru
in
1405 if state.memused
<= conf.memlimit
1410 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1411 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1412 let (_
, pw
, ph
, _
) = getpagedim n in
1415 && colorspace
= conf.colorspace
1416 && angle
= conf.angle
1421 match state.throttle
with
1424 then preloadlayout state.layout
1426 | Some
(layout, _
, _
) ->
1429 let x = col*conf.tilew
1430 and y = row*conf.tileh
in
1431 tilevisible layout n x y
1433 then Queue.push lruitem
state.tilelru
1435 wcmd "freetile" [`
s p
];
1436 state.memused
<- state.memused
- s;
1437 state.uioh#infochanged Memused
;
1438 Hashtbl.remove
state.tilemap k
;
1447 Queue.iter
(fun (k
, p
, s) ->
1448 wcmd "freetile" [`
s p
];
1449 state.memused
<- state.memused
- s;
1450 state.uioh#infochanged Memused
;
1451 Hashtbl.remove
state.tilemap k
;
1453 Queue.clear
state.tilelru
;
1457 let logcurrently = function
1458 | Idle
-> dolog "Idle"
1459 | Loading
(l
, gen
) ->
1460 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1461 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1463 "Tiling %d[%d,%d] page=%s cs=%s angle"
1464 l
.pageno
col row pageopaque
1465 (colorspace_to_string colorspace
)
1467 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1468 angle gen
conf.angle
state.gen
1470 conf.tilew
conf.tileh
1477 (* dolog "%S" cmds; *)
1480 try String.index cmds ' '
1481 with Not_found
-> -1
1486 let l = String.length cmds
in
1487 let op = String.sub cmds
0 spacepos in
1489 if l - spacepos < 2 then ""
1490 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1495 state.uioh#infochanged Pdim
;
1499 state.rects
<- state.rects1
;
1500 G.postRedisplay "clearrects";
1504 try Scanf.sscanf args
"%u" (fun n -> n)
1506 dolog "error processing 'continue' %S: %s"
1507 cmds
(Printexc.to_string exn
);
1510 state.pagecount
<- n;
1511 state.invalidated
<- state.invalidated
- 1;
1512 begin match state.currently
with
1514 state.currently
<- Idle
;
1515 state.outlines
<- Array.of_list
(List.rev
l)
1518 if state.invalidated
= 0
1520 if conf.maxwait
= None
1521 then G.postRedisplay "continue";
1524 Glut.setWindowTitle args
1531 then showtext ' ' args
1534 let progress, text =
1536 Scanf.sscanf args
"%f %n"
1538 f, String.sub args pos
(String.length args
- pos
))
1540 dolog "error processing 'progress' %S: %s"
1541 cmds
(Printexc.to_string exn
);
1545 state.progress <- progress;
1546 G.postRedisplay "progress"
1549 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1551 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1552 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1553 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1555 dolog "error processing 'firstmatch' %S: %s"
1556 cmds
(Printexc.to_string exn
);
1559 let y = (getpagey pageno) + truncate y0
in
1562 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)]
1565 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1567 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1568 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1569 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1571 dolog "error processing 'match' %S: %s"
1572 cmds
(Printexc.to_string exn
);
1576 (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) :: state.rects1
1581 Scanf.sscanf args
"%s %f" (fun p t
-> p
, t
)
1583 dolog "error processing 'page' %S: %s"
1584 cmds
(Printexc.to_string exn
);
1587 begin match state.currently
with
1588 | Loading
(l, gen
) ->
1589 vlog "page %d took %f sec" l.pageno t
;
1590 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1591 begin match state.throttle
with
1593 let preloadedpages =
1595 then preloadlayout state.layout
1600 Set.Make
(struct type t
= int let compare = (-) end) in
1602 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1603 IntSet.empty
preloadedpages
1606 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
1607 if not
(IntSet.mem
pageno set)
1609 wcmd "freepage" [`
s opaque
];
1615 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1618 state.currently
<- Idle
;
1621 tilepage l.pageno pageopaque state.layout;
1623 load preloadedpages;
1624 if pagevisible state.layout l.pageno
1625 && layoutready state.layout
1626 then G.postRedisplay "page";
1629 | Some
(layout, _
, _
) ->
1630 state.currently
<- Idle
;
1631 tilepage l.pageno pageopaque layout;
1636 dolog "Inconsistent loading state";
1637 logcurrently state.currently
;
1642 let (x, y, opaque
, size
, t
) =
1644 Scanf.sscanf args
"%u %u %s %u %f"
1645 (fun x y p size t
-> (x, y, p
, size
, t
))
1647 dolog "error processing 'tile' %S: %s"
1648 cmds
(Printexc.to_string exn
);
1651 begin match state.currently
with
1652 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1653 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1655 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1657 wcmd "freetile" [`
s opaque
];
1658 state.currently
<- Idle
;
1662 puttileopaque l col row gen cs angle opaque size t
;
1663 state.memused
<- state.memused
+ size
;
1664 state.uioh#infochanged Memused
;
1666 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1667 opaque
, size
) state.tilelru
;
1670 match state.throttle
with
1671 | None
-> state.layout
1672 | Some
(layout, _
, _
) -> layout
1675 state.currently
<- Idle
;
1677 && conf.colorspace
= cs
1678 && conf.angle
= angle
1679 && tilevisible layout l.pageno x y
1680 then conttiling l.pageno pageopaque;
1682 begin match state.throttle
with
1684 preload state.layout;
1686 && conf.colorspace
= cs
1687 && conf.angle
= angle
1688 && tilevisible state.layout l.pageno x y
1689 then G.postRedisplay "tile nothrottle";
1691 | Some
(layout, y, _
) ->
1692 let ready = layoutready layout in
1696 state.layout <- layout;
1697 state.throttle
<- None
;
1698 G.postRedisplay "throttle";
1705 dolog "Inconsistent tiling state";
1706 logcurrently state.currently
;
1713 Scanf.sscanf args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1715 dolog "error processing 'pdim' %S: %s"
1716 cmds
(Printexc.to_string exn
);
1719 state.uioh#infochanged Pdim
;
1720 state.pdims
<- pdim :: state.pdims
1723 let (l, n, t
, h, pos
) =
1725 Scanf.sscanf args
"%u %u %d %u %n"
1726 (fun l n t
h pos
-> l, n, t
, h, pos
)
1728 dolog "error processing 'o' %S: %s"
1729 cmds
(Printexc.to_string exn
);
1732 let s = String.sub args pos
(String.length args
- pos
) in
1733 let outline = (s, l, (n, float t
/. float h)) in
1734 begin match state.currently
with
1735 | Outlining outlines
->
1736 state.currently
<- Outlining
(outline :: outlines
)
1738 state.currently
<- Outlining
[outline]
1740 dolog "invalid outlining state";
1741 logcurrently currently
1745 state.docinfo
<- (1, args
) :: state.docinfo
1748 state.uioh#infochanged Docinfo
;
1749 state.docinfo
<- List.rev
state.docinfo
1752 dolog "unknown cmd `%S'" cmds
1756 if state.deadline
== nan
then state.deadline
<- now ();
1758 match state.errfd
with
1759 | None
-> [state.csock
]
1760 | Some fd
-> [state.csock
; fd
]
1762 let rec loop delay
=
1765 then max
0.0 (state.deadline
-. now ())
1768 let r, _
, _
= Unix.select
r [] [] timeout in
1771 begin match state.autoscroll
with
1772 | Some step
when step
!= 0 ->
1773 let y = state.y + step
in
1777 else if y >= state.maxy then 0 else y
1780 if state.mode
= View
1781 then state.text <- "";
1782 state.deadline
<- state.deadline
+. 0.005;
1785 state.deadline
<- state.deadline
+. delay
;
1789 let rec checkfds c = function
1791 | fd
:: rest
when fd
= state.csock
->
1792 let cmd = readcmd state.csock
in
1796 let s = String.create
80 in
1797 let n = Unix.read fd
s 0 80 in
1798 if conf.redirectstderr
1800 Buffer.add_substring
state.errmsgs
s 0 n;
1801 state.newerrmsgs
<- true;
1802 Glut.postRedisplay ();
1805 prerr_string
(String.sub
s 0 n);
1818 let action = function
1819 | HCprev
-> cbget cb ~
-1
1820 | HCnext
-> cbget cb
1
1821 | HCfirst
-> cbget cb ~
-(cb
.rc)
1822 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1823 and cancel
() = cb
.rc <- rc
1827 let search pattern forward
=
1828 if String.length pattern
> 0
1831 match state.layout with
1834 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1837 let b = makecmd "search"
1838 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
1840 Buffer.add_char
b '
,'
;
1841 Buffer.add_string
b pattern
;
1842 Buffer.add_char
b '
\000'
;
1845 writecmd state.csock
cmd;
1848 let intentry text key =
1849 let c = Char.unsafe_chr
key in
1852 let text = addchar text c in
1856 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1860 let textentry text key =
1861 let c = Char.unsafe_chr
key in
1863 | _
when key >= 32 && key < 127 ->
1864 let text = addchar text c in
1868 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
1872 let reqlayout angle proportional
=
1873 match state.throttle
with
1875 if state.invalidated
= 0 then state.anchor <- getanchor ();
1876 conf.angle
<- angle
mod 360;
1877 conf.proportional
<- proportional
;
1879 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
1883 let settrim trimmargins trimfuzz
=
1884 if state.invalidated
= 0 then state.anchor <- getanchor ();
1885 conf.trimmargins
<- trimmargins
;
1886 conf.trimfuzz
<- trimfuzz
;
1887 let x0, y0
, x1
, y1
= trimfuzz
in
1890 `
b conf.trimmargins
;
1896 Hashtbl.iter
(fun _ opaque
->
1897 wcmd "freepage" [`
s opaque
];
1899 Hashtbl.clear
state.pagemap
;
1903 match state.throttle
with
1905 let zoom = max
0.01 zoom in
1906 if zoom <> conf.zoom
1908 state.prevzoom
<- conf.zoom;
1911 then (state.x <- 0; 0.0)
1912 else float state.x /. float state.w
1915 reshape conf.winw
conf.winh
;
1918 let x = relx *. float state.w in
1919 state.x <- truncate
x;
1921 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
1924 | Some
(layout, y, started
) ->
1926 match conf.maxwait
with
1930 let dt = now () -. started
in
1938 let enterbirdseye () =
1939 let zoom = float conf.thumbw
/. float conf.winw
in
1940 let birdseyepageno =
1941 let cy = conf.winh
/ 2 in
1945 let rec fold best
= function
1948 let d = cy - (l.pagedispy
+ l.pagevh/2)
1949 and dbest
= cy - (best
.pagedispy
+ best
.pagevh/2) in
1950 if abs
d < abs dbest
1957 state.mode
<- Birdseye
(
1958 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
1961 conf.presentation <- false;
1962 conf.interpagespace <- 10;
1963 conf.hlinks
<- false;
1965 state.mstate
<- Mnone
;
1966 conf.maxwait
<- None
;
1967 Glut.setCursor
Glut.CURSOR_INHERIT
;
1970 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1975 reshape conf.winw
conf.winh
;
1978 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
1980 conf.zoom <- c.zoom;
1981 conf.presentation <- c.presentation;
1982 conf.interpagespace <- c.interpagespace;
1983 conf.maxwait
<- c.maxwait
;
1984 conf.hlinks
<- c.hlinks
;
1988 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1991 reshape conf.winw
conf.winh
;
1992 state.anchor <- if goback
then anchor else (pageno, 0.0);
1995 let togglebirdseye () =
1996 match state.mode
with
1997 | Birdseye vals
-> leavebirdseye vals
true
1998 | View
-> enterbirdseye ()
2002 let upbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
2003 let pageno = max
0 (pageno - 1) in
2004 let rec loop = function
2005 | [] -> gotopage1 pageno 0
2006 | l :: _
when l.pageno = pageno ->
2007 if l.pagedispy
>= 0 && l.pagey = 0
2008 then G.postRedisplay "upbirdseye"
2009 else gotopage1 pageno 0
2010 | _
:: rest
-> loop rest
2013 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2016 let downbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
2017 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
2018 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2019 let rec loop = function
2021 let y, h = getpageyh pageno in
2022 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2024 | l :: _
when l.pageno = pageno ->
2025 if l.pagevh != l.pageh
2026 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2027 else G.postRedisplay "downbirdseye"
2028 | _
:: rest
-> loop rest
2033 let optentry mode _
key =
2034 let btos b = if b then "on" else "off" in
2035 let c = Char.unsafe_chr
key in
2039 try conf.scrollstep
<- int_of_string
s with exc
->
2040 state.text <- Printf.sprintf
"bad integer `%s': %s"
2041 s (Printexc.to_string exc
)
2043 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2048 conf.autoscrollstep
<- int_of_string
s;
2049 if state.autoscroll
<> None
2050 then state.autoscroll
<- Some
conf.autoscrollstep
2052 state.text <- Printf.sprintf
"bad integer `%s': %s"
2053 s (Printexc.to_string exc
)
2055 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2060 let zoom = float (int_of_string
s) /. 100.0 in
2063 state.text <- Printf.sprintf
"bad integer `%s': %s"
2064 s (Printexc.to_string exc
)
2066 TEswitch
("zoom: ", "", None
, intentry, ondone)
2071 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2073 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2074 begin match mode
with
2076 leavebirdseye beye
false;
2081 state.text <- Printf.sprintf
"bad integer `%s': %s"
2082 s (Printexc.to_string exc
)
2084 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2089 Some
(int_of_string
s)
2091 state.text <- Printf.sprintf
"bad integer `%s': %s"
2092 s (Printexc.to_string exc
);
2095 | Some angle
-> reqlayout angle
conf.proportional
2098 TEswitch
("rotation: ", "", None
, intentry, ondone)
2101 conf.icase
<- not
conf.icase
;
2102 TEdone
("case insensitive search " ^
(btos conf.icase
))
2105 conf.preload <- not
conf.preload;
2107 TEdone
("preload " ^
(btos conf.preload))
2110 conf.verbose
<- not
conf.verbose
;
2111 TEdone
("verbose " ^
(btos conf.verbose
))
2114 conf.debug
<- not
conf.debug
;
2115 TEdone
("debug " ^
(btos conf.debug
))
2118 conf.maxhfit
<- not
conf.maxhfit
;
2120 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2121 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2124 conf.crophack
<- not
conf.crophack
;
2125 TEdone
("crophack " ^
btos conf.crophack
)
2129 match conf.maxwait
with
2131 conf.maxwait
<- Some infinity
;
2132 "always wait for page to complete"
2134 conf.maxwait
<- None
;
2135 "show placeholder if page is not ready"
2140 conf.underinfo
<- not
conf.underinfo
;
2141 TEdone
("underinfo " ^
btos conf.underinfo
)
2144 conf.savebmarks
<- not
conf.savebmarks
;
2145 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2151 match state.layout with
2156 conf.interpagespace <- int_of_string
s;
2157 state.maxy <- calcheight ();
2158 let y = getpagey pageno in
2161 state.text <- Printf.sprintf
"bad integer `%s': %s"
2162 s (Printexc.to_string exc
)
2164 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2167 reqlayout conf.angle
(not
conf.proportional
);
2168 TEdone
("proportional display " ^
btos conf.proportional
)
2171 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2172 TEdone
("trim margins " ^
btos conf.trimmargins
)
2175 conf.invert
<- not
conf.invert
;
2176 TEdone
("invert colors " ^
btos conf.invert
)
2179 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2183 class type lvsource
= object
2184 method getitemcount
: int
2185 method getitem
: int -> (string * int)
2186 method hasaction
: int -> bool
2195 method getactive
: int
2196 method getfirst
: int
2197 method getqsearch
: string
2198 method setqsearch
: string -> unit
2202 class virtual lvsourcebase
= object
2203 val mutable m_active
= 0
2204 val mutable m_first
= 0
2205 val mutable m_qsearch
= ""
2206 val mutable m_pan
= 0
2207 method getactive
= m_active
2208 method getfirst
= m_first
2209 method getqsearch
= m_qsearch
2210 method getpan
= m_pan
2211 method setqsearch
s = m_qsearch
<- s
2214 let textentryspecial key = function
2215 | ((c, _
, (Some
(action, _
) as onhist), onkey
, ondone), mode
) ->
2218 | Glut.KEY_UP
-> action HCprev
2219 | Glut.KEY_DOWN
-> action HCnext
2220 | Glut.KEY_HOME
-> action HCfirst
2221 | Glut.KEY_END
-> action HClast
2224 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2225 G.postRedisplay "special textentry";
2229 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2231 state.mode
<- Textentry
(te
, onleave
);
2234 G.postRedisplay "textentrykeyboard enttext";
2236 match Char.unsafe_chr
key with
2237 | '
\008'
-> (* backspace *)
2238 let len = String.length
text in
2242 G.postRedisplay "textentrykeyboard after cancel";
2245 let s = String.sub
text 0 (len - 1) in
2246 enttext (c, s, opthist
, onkey
, ondone)
2252 G.postRedisplay "textentrykeyboard after confirm"
2254 | '
\007'
(* ctrl-g *)
2255 | '
\027'
-> (* escape *)
2256 if String.length
text = 0
2258 begin match opthist
with
2260 | Some
(_
, onhistcancel
) -> onhistcancel
()
2264 G.postRedisplay "textentrykeyboard after cancel2"
2267 enttext (c, "", opthist
, onkey
, ondone)
2270 | '
\127'
-> () (* delete *)
2273 begin match onkey
text key with
2277 G.postRedisplay "textentrykeyboard after confirm2";
2280 enttext (c, text, opthist
, onkey
, ondone);
2285 G.postRedisplay "textentrykeyboard after cancel3"
2288 state.mode
<- Textentry
(te
, onleave
);
2289 G.postRedisplay "textentrykeyboard switch";
2293 let firstof first active
=
2294 if first
> active
|| abs
(first
- active
) > fstate.maxrows
- 1
2295 then max
0 (active
- (fstate.maxrows
/2))
2299 let calcfirst first active
=
2302 let rows = active
- first
in
2303 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2307 let scrollph y maxy =
2308 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2309 let sh = float conf.winh
/. sh in
2310 let sh = max
sh (float conf.scrollh
) in
2315 else float y /. float maxy
2317 let position = (float conf.winh
-. sh) *. percent in
2320 if position +. sh > float conf.winh
2321 then float conf.winh
-. sh
2327 let coe s = (s :> uioh
);;
2329 class listview ~
(source
:lvsource
) ~trusted
=
2331 val m_pan
= source#getpan
2332 val m_first
= source#getfirst
2333 val m_active
= source#getactive
2334 val m_qsearch
= source#getqsearch
2335 val m_prev_uioh
= state.uioh
2337 method private elemunder
y =
2338 let n = y / (fstate.fontsize
+1) in
2339 if m_first
+ n < source#getitemcount
2341 if source#hasaction
(m_first
+ n)
2342 then Some
(m_first
+ n)
2349 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2350 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2351 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2352 GlDraw.color
(1., 1., 1.);
2353 Gl.enable `texture_2d
;
2354 let fs = fstate.fontsize
in
2356 let ww = fstate.wwidth
in
2357 let tabw = 30.0*.ww in
2358 let itemcount = source#getitemcount
in
2360 if (row - m_first
) * nfs > conf.winh
2363 if row >= 0 && row < itemcount
2365 let (s, level
) = source#getitem
row in
2366 let y = (row - m_first
) * nfs in
2367 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2370 Gl.disable `texture_2d
;
2371 GlDraw.polygon_mode `both `line
;
2372 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2373 GlDraw.rect (1., float (y + 1))
2374 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2375 GlDraw.polygon_mode `both `fill
;
2376 GlDraw.color
(1., 1., 1.);
2377 Gl.enable `texture_2d
;
2380 let drawtabularstring s =
2381 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2384 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2387 let len = String.length
s - tabpos - 1 in
2388 let s1 = String.sub
s 0 tabpos
2389 and s2
= String.sub
s (tabpos + 1) len in
2390 let nx = drawstr x s1 in
2392 let x = x +. (max
tabw sw) in
2399 let _ = drawtabularstring s in
2406 Gl.disable `texture_2d
;
2408 method updownlevel incr
=
2409 let len = source#getitemcount
in
2410 let _, curlevel
= source#getitem m_active
in
2412 if i
= len then i
-1 else if i
= -1 then 0 else
2413 let _, l = source#getitem i
in
2414 if l != curlevel
then i
else flow (i
+incr
)
2416 let active = flow m_active
in
2417 let first = calcfirst m_first
active in
2418 G.postRedisplay "special outline updownlevel";
2419 {< m_active
= active; m_first
= first >}
2421 method private key1
key =
2422 let set active first qsearch
=
2423 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2425 let search active pattern incr
=
2428 if n >= 0 && n < source#getitemcount
2430 let s, _ = source#getitem
n in
2432 (try ignore
(Str.search_forward
re s 0); true
2433 with Not_found
-> false)
2435 else loop (n + incr
)
2442 let re = Str.regexp_case_fold pattern
in
2449 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2450 let incr = if key = 18 then -1 else 1 in
2452 match search (m_active
+ incr) m_qsearch
incr with
2454 state.text <- m_qsearch ^
" [not found]";
2457 state.text <- m_qsearch
;
2458 active, firstof m_first
active
2460 G.postRedisplay "listview ctrl-r/s";
2461 set active first m_qsearch
;
2463 | 8 -> (* backspace *)
2464 let len = String.length m_qsearch
in
2471 G.postRedisplay "listview empty qsearch";
2472 set m_active m_first
"";
2475 let qsearch = String.sub m_qsearch
0 (len - 1) in
2477 match search m_active
qsearch ~
-1 with
2479 state.text <- qsearch ^
" [not found]";
2482 state.text <- qsearch;
2483 active, firstof m_first
active
2485 G.postRedisplay "listview backspace qsearch";
2486 set active first qsearch
2489 | _ when key >= 32 && key < 127 ->
2490 let pattern = addchar m_qsearch
(Char.chr
key) in
2492 match search m_active
pattern 1 with
2494 state.text <- pattern ^
" [not found]";
2497 state.text <- pattern;
2498 active, firstof m_first
active
2500 G.postRedisplay "listview qsearch add";
2501 set active first pattern;
2503 | 27 -> (* escape *)
2505 if String.length m_qsearch
= 0
2507 G.postRedisplay "list view escape";
2510 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2512 | None
-> m_prev_uioh
2517 G.postRedisplay "list view kill qsearch";
2518 source#setqsearch
"";
2519 coe {< m_qsearch
= "" >}
2524 let self = {< m_qsearch
= "" >} in
2525 source#setqsearch
"";
2527 G.postRedisplay "listview enter";
2528 if m_active
>= 0 && m_active
< source#getitemcount
2530 source#exit
(coe self) false m_active m_first m_pan
"";
2533 source#exit
(coe self) true m_active m_first m_pan
"";
2536 begin match opt with
2537 | None
-> m_prev_uioh
2541 | 127 -> (* delete *)
2544 | _ -> dolog "unknown key %d" key; coe self
2546 method private special1
key =
2547 let itemcount = source#getitemcount
in
2548 let find start
incr =
2550 if i
= -1 || i
= itemcount
2553 if source#hasaction i
2555 else find (i
+ incr)
2560 let set active first =
2561 let first = bound first 0 (itemcount - fstate.maxrows
) in
2563 coe {< m_active
= active; m_first
= first >}
2566 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2568 let incr1 = if incr > 0 then 1 else -1 in
2569 if isvisible m_first m_active
2572 let next = m_active
+ incr in
2574 if next < 0 || next >= itemcount
2576 else find next incr1
2578 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2584 let first = m_first
+ incr in
2585 let first = bound first 0 (itemcount - 1) in
2587 let next = m_active
+ incr in
2588 let next = bound next 0 (itemcount - 1) in
2591 let active = if next = -1 then m_active
else next in
2594 let first = min
next m_first
in
2597 let first = m_first
+ incr in
2598 let first = bound first 0 (itemcount - 1) in
2600 let next = m_active
+ incr in
2601 let next = bound next 0 (itemcount - 1) in
2602 let next = find next incr1 in
2604 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2606 let active = if m_active
= -1 then next else m_active
in
2611 if isvisible first active
2617 G.postRedisplay "listview navigate";
2620 begin match key with
2621 | Glut.KEY_UP
-> navigate ~
-1
2622 | Glut.KEY_DOWN
-> navigate 1
2623 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2624 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2628 G.postRedisplay "listview right";
2629 coe {< m_pan
= m_pan
- 1 >}
2633 G.postRedisplay "listview left";
2634 coe {< m_pan
= m_pan
+ 1 >}
2637 let active = find 0 1 in
2638 G.postRedisplay "listview home";
2642 let first = max
0 (itemcount - fstate.maxrows
) in
2643 let active = find (itemcount - 1) ~
-1 in
2644 G.postRedisplay "listview end";
2651 match state.mode
with
2652 | Textentry te
-> textentrykeyboard key te
; coe self
2653 | _ -> self#key1
key
2655 method special
key =
2656 match state.mode
with
2657 | Textentry te
-> textentryspecial key te
; coe self
2658 | _ -> self#special1
key
2660 method button button bstate
x y =
2663 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollbw
->
2664 G.postRedisplay "listview scroll";
2665 if bstate
= Glut.DOWN
2667 let _, position, sh = self#
scrollph in
2668 if y > truncate
position && y < truncate
(position +. sh)
2670 state.mstate
<- Mscrolly
;
2674 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2675 let first = truncate
(s *. float source#getitemcount
) in
2676 let first = min source#getitemcount
first in
2677 Some
(coe {< m_first
= first; m_active
= first >})
2679 state.mstate
<- Mnone
;
2682 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2683 begin match self#elemunder
y with
2685 G.postRedisplay "listview click";
2687 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
2691 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2692 let len = source#getitemcount
in
2694 if n = 4 && m_first
+ fstate.maxrows
>= len
2698 let first = m_first
+ (if n == 3 then -1 else 1) in
2699 bound first 0 (len - 1)
2701 G.postRedisplay "listview wheel";
2702 Some
(coe {< m_first
= first >})
2707 | None
-> m_prev_uioh
2711 match state.mstate
with
2713 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
2714 let first = truncate
(s *. float source#getitemcount
) in
2715 let first = min source#getitemcount
first in
2716 G.postRedisplay "listview motion";
2717 coe {< m_first
= first; m_active
= first >}
2720 method pmotion
x y =
2721 if x < conf.winw
- conf.scrollbw
2724 match self#elemunder
y with
2725 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
2726 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
2730 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
2735 Glut.setCursor
Glut.CURSOR_INHERIT
;
2739 method infochanged
_ = ()
2741 method scrollpw
= (0, 0.0, 0.0)
2743 let nfs = fstate.fontsize
+ 1 in
2744 let y = m_first
* nfs in
2745 let itemcount = source#getitemcount
in
2746 let maxi = max
0 (itemcount - fstate.maxrows
) in
2747 let maxy = maxi * nfs in
2748 let p, h = scrollph y maxy in
2752 class outlinelistview ~source
=
2754 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
2758 | 14 -> (* ctrl-n *)
2759 source#narrow m_qsearch
;
2760 G.postRedisplay "outline ctrl-n";
2761 coe {< m_first
= 0; m_active
= 0 >}
2763 | 21 -> (* ctrl-u *)
2765 G.postRedisplay "outline ctrl-u";
2767 coe {< m_first
= 0; m_active
= 0 >}
2769 | 12 -> (* ctrl-l *)
2770 let first = m_active
- (fstate.maxrows
/ 2) in
2771 G.postRedisplay "outline ctrl-l";
2772 coe {< m_first
= first >}
2774 | 127 -> (* delete *)
2775 source#remove m_active
;
2776 G.postRedisplay "outline delete";
2777 let active = max
0 (m_active
-1) in
2778 coe {< m_first
= firstof m_first
active;
2779 m_active
= active >}
2781 | key -> super#
key key
2783 method special
key =
2784 let calcfirst first active =
2787 let rows = active - first in
2788 if rows > fstate.maxrows
then active - fstate.maxrows
else first
2792 let active = m_active
+ incr in
2793 let active = bound active 0 (source#getitemcount
- 1) in
2794 let first = calcfirst m_first
active in
2795 G.postRedisplay "special outline navigate";
2796 coe {< m_active
= active; m_first
= first >}
2799 | Glut.KEY_UP
-> navigate ~
-1
2800 | Glut.KEY_DOWN
-> navigate 1
2801 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2802 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2806 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2808 G.postRedisplay "special outline right";
2809 {< m_pan
= m_pan
+ 1 >}
2811 else self#updownlevel
1
2817 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2819 G.postRedisplay "special outline left";
2820 {< m_pan
= m_pan
- 1 >}
2822 else self#updownlevel ~
-1
2827 G.postRedisplay "special outline home";
2828 coe {< m_first
= 0; m_active
= 0 >}
2831 let active = source#getitemcount
- 1 in
2832 let first = max
0 (active - fstate.maxrows
) in
2833 G.postRedisplay "special outline end";
2834 coe {< m_active
= active; m_first
= first >}
2836 | _ -> super#special
key
2839 let outlinesource usebookmarks
=
2842 inherit lvsourcebase
2843 val mutable m_items
= empty
2844 val mutable m_orig_items
= empty
2845 val mutable m_prev_items
= empty
2846 val mutable m_narrow_pattern
= ""
2847 val mutable m_hadremovals
= false
2849 method getitemcount
=
2850 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
2853 if n == Array.length m_items
&& m_hadremovals
2855 ("[Confirm removal]", 0)
2857 let s, n, _ = m_items
.(n) in
2860 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
2861 ignore
(uioh
, first, pan
, qsearch);
2862 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
2864 if String.length m_narrow_pattern
= 0
2870 if not
confrimremoval
2872 let _, _, anchor = m_items
.(active) in
2877 state.bookmarks
<- Array.to_list m_items
;
2878 m_orig_items
<- m_items
;
2881 else m_items
<- items;
2884 method hasaction
_ = true
2887 if Array.length m_items
!= Array.length m_orig_items
2888 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
2891 method narrow
pattern =
2892 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
2896 let rec loop accu n =
2899 m_narrow_pattern
<- pattern;
2900 m_items
<- Array.of_list
accu
2903 let (s, _, _) as o = m_items
.(n) in
2905 if (try ignore
(Str.search_forward
re s 0); true
2906 with Not_found
-> false)
2912 loop [] (Array.length m_items
- 1)
2917 then Array.of_list
state.bookmarks
2920 m_items
<- m_orig_items
2925 if m
>= 0 && m
< Array.length m_items
2927 m_hadremovals
<- true;
2928 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
2929 let n = if n >= m
then n+1 else n in
2934 method reset
anchor items =
2935 m_hadremovals
<- false;
2936 if m_orig_items
== empty || m_prev_items
!= items
2938 m_orig_items
<- items;
2939 if String.length m_narrow_pattern
= 0
2940 then m_items
<- items;
2942 m_prev_items
<- items;
2943 let rely = getanchory anchor in
2945 let rec loop n best bestd
=
2946 if n = Array.length m_items
2949 let (_, _, anchor) = m_items
.(n) in
2950 let orely = getanchory anchor in
2951 let d = abs
(orely - rely) in
2954 else loop (n+1) best bestd
2959 m_first
<- firstof m_first
active
2963 let enterselector usebookmarks
=
2964 let source = outlinesource usebookmarks
in
2968 then Array.of_list
state.bookmarks
2971 if Array.length
outlines = 0
2973 showtext ' ' errmsg
;
2976 state.text <- source#greetmsg
;
2977 Glut.setCursor
Glut.CURSOR_INHERIT
;
2978 let anchor = getanchor () in
2979 source#reset
anchor outlines;
2980 state.uioh
<- coe (new outlinelistview ~
source);
2981 G.postRedisplay "enter selector";
2985 let enteroutlinemode =
2986 let f = enterselector false in
2987 fun ()-> f "Document has no outline";
2990 let enterbookmarkmode =
2991 let f = enterselector true in
2992 fun () -> f "Document has no bookmarks (yet)";
2995 let color_of_string s =
2996 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
2997 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3001 let color_to_string (r, g
, b) =
3002 let r = truncate
(r *. 256.0)
3003 and g
= truncate
(g
*. 256.0)
3004 and b = truncate
(b *. 256.0) in
3005 Printf.sprintf
"%d/%d/%d" r g
b
3008 let irect_of_string s =
3009 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0,y0
,x1
,y1
))
3012 let irect_to_string (x0,y0
,x1
,y1
) =
3013 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3016 let makecheckers () =
3017 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3019 converted by Issac Trotts. July 25, 2002 *)
3020 let image_height = 64
3021 and image_width
= 64 in
3025 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3027 for i
= 0 to image_width
- 1 do
3028 for j
= 0 to image_height - 1 do
3029 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3030 (if (i
land 8 ) lxor (j
land 8) = 0
3031 then [|255;255;255|] else [|200;200;200|])
3036 let image = make_image () in
3037 let id = GlTex.gen_texture
() in
3038 GlTex.bind_texture `texture_2d
id;
3039 GlPix.store
(`unpack_alignment
1);
3040 GlTex.image2d
image;
3041 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3044 `mag_filter `nearest
;
3045 `min_filter `nearest
];
3049 let setcheckers enabled
=
3050 match state.texid
with
3052 if enabled
then state.texid
<- Some
(makecheckers ())
3057 GlTex.delete_texture texid
;
3058 state.texid
<- None
;
3062 let int_of_string_with_suffix s =
3063 let l = String.length
s in
3067 let suffix = Char.lowercase
s.[l-1] in
3069 | 'k'
-> String.sub
s 0 (l-1), 10
3070 | 'm'
-> String.sub
s 0 (l-1), 20
3071 | 'g'
-> String.sub
s 0 (l-1), 30
3075 let n = int_of_string
s1 in
3076 let m = n lsl shift
in
3078 then raise
(Failure
"value too large")
3082 let string_with_suffix_of_int n =
3090 if n land ((1 lsl 20) - 1) = 0
3093 if n land ((1 lsl 10) - 1) = 0
3100 let h = n mod 1000 in
3103 then string_of_int
h ^
s
3105 let s = Printf.sprintf
"_%03d%s" h s in
3112 let describe_location () =
3114 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3116 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3117 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3121 else (100. *. (float state.y /. float maxy))
3125 Printf.sprintf
"page %d of %d [%.2f%%]"
3126 (fn+1) state.pagecount
percent
3129 "pages %d-%d of %d [%.2f%%]"
3130 (fn+1) (ln
+1) state.pagecount
percent
3134 let btos b = if b then "\xe2\x88\x9a" else "" in
3135 let showextended = ref false in
3136 let leave mode
= function
3137 | Confirm
-> state.mode
<- mode
3138 | Cancel
-> state.mode
<- mode
in
3141 val mutable m_first_time
= true
3142 val mutable m_l
= []
3143 val mutable m_a
= [||]
3144 val mutable m_prev_uioh
= nouioh
3145 val mutable m_prev_mode
= View
3147 inherit lvsourcebase
3149 method reset prev_mode prev_uioh
=
3150 m_a
<- Array.of_list
(List.rev m_l
);
3152 m_prev_mode
<- prev_mode
;
3153 m_prev_uioh
<- prev_uioh
;
3157 if n >= Array.length m_a
3161 | _, _, _, Action
_ -> m_active
<- n
3165 m_first_time
<- false;
3168 method int name get
set =
3170 (name
, `
int get
, 1, Action
(
3173 try set (int_of_string
s)
3175 state.text <- Printf.sprintf
"bad integer `%s': %s"
3176 s (Printexc.to_string exn
)
3179 let te = name ^
": ", "", None
, intentry, ondone in
3180 state.mode
<- Textentry
(te, leave m_prev_mode
);
3184 method int_with_suffix name get
set =
3186 (name
, `intws get
, 1, Action
(
3189 try set (int_of_string_with_suffix s)
3191 state.text <- Printf.sprintf
"bad integer `%s': %s"
3192 s (Printexc.to_string exn
)
3196 name ^
": ", "", None
, intentry_with_suffix, ondone
3198 state.mode
<- Textentry
(te, leave m_prev_mode
);
3202 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3204 (name
, `
bool (btos, get
), offset
, Action
(
3211 method color name get
set =
3213 (name
, `color get
, 1, Action
(
3215 let invalid = (nan
, nan
, nan
) in
3218 try color_of_string s
3220 state.text <- Printf.sprintf
"bad color `%s': %s"
3221 s (Printexc.to_string exn
);
3227 let te = name ^
": ", "", None
, textentry, ondone in
3228 state.text <- color_to_string (get
());
3229 state.mode
<- Textentry
(te, leave m_prev_mode
);
3233 method string name get
set =
3235 (name
, `
string get
, 1, Action
(
3237 let ondone s = set s in
3238 let te = name ^
": ", "", None
, textentry, ondone in
3239 state.mode
<- Textentry
(te, leave m_prev_mode
);
3243 method colorspace name get
set =
3245 (name
, `
string get
, 1, Action
(
3248 let vals = [| "rgb"; "bgr"; "gray" |] in
3250 inherit lvsourcebase
3253 m_active
<- int_of_colorspace conf.colorspace
;
3256 method getitemcount
= Array.length
vals
3257 method getitem
n = (vals.(n), 0)
3258 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3259 ignore
(uioh
, first, pan
, qsearch);
3260 if not cancel
then set active;
3262 method hasaction
_ = true
3266 coe (new listview ~
source ~trusted
:true)
3269 method caption
s offset
=
3270 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3272 method caption2
s f offset
=
3273 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3275 method getitemcount
= Array.length m_a
3278 let tostr = function
3279 | `
int f -> string_of_int
(f ())
3280 | `intws
f -> string_with_suffix_of_int (f ())
3282 | `color
f -> color_to_string (f ())
3283 | `
bool (btos, f) -> btos (f ())
3286 let name, t
, offset
, _ = m_a
.(n) in
3287 ((let s = tostr t
in
3288 if String.length
s > 0
3289 then Printf.sprintf
"%s\t%s" name s
3293 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3297 m_qsearch
<- qsearch;
3299 match m_a
.(active) with
3300 | _, _, _, Action
f -> f uioh
3312 method hasaction
n =
3314 | _, _, _, Action
_ -> true
3318 let rec fillsrc prevmode prevuioh
=
3319 let sep () = src#caption
"" 0 in
3320 let colorp name get
set =
3322 (fun () -> color_to_string (get
()))
3325 let c = color_of_string v in
3328 state.text <- Printf.sprintf
"bad color `%s': %s"
3329 v (Printexc.to_string exn
);
3332 let oldmode = state.mode
in
3333 let birdseye = isbirdseye state.mode
in
3335 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3337 src#
bool "presentation mode"
3338 (fun () -> conf.presentation)
3340 conf.presentation <- v;
3341 state.anchor <- getanchor ();
3344 src#
bool "ignore case in searches"
3345 (fun () -> conf.icase
)
3346 (fun v -> conf.icase
<- v);
3349 (fun () -> conf.preload)
3350 (fun v -> conf.preload <- v);
3352 src#
bool "highlight links"
3353 (fun () -> conf.hlinks
)
3354 (fun v -> conf.hlinks
<- v);
3356 src#
bool "under info"
3357 (fun () -> conf.underinfo
)
3358 (fun v -> conf.underinfo
<- v);
3360 src#
bool "persistent bookmarks"
3361 (fun () -> conf.savebmarks
)
3362 (fun v -> conf.savebmarks
<- v);
3364 src#
bool "proportional display"
3365 (fun () -> conf.proportional
)
3366 (fun v -> reqlayout conf.angle
v);
3368 src#
bool "trim margins"
3369 (fun () -> conf.trimmargins
)
3370 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3372 src#
bool "persistent location"
3373 (fun () -> conf.jumpback
)
3374 (fun v -> conf.jumpback
<- v);
3377 src#
int "vertical margin"
3378 (fun () -> conf.interpagespace)
3380 conf.interpagespace <- n;
3382 match state.layout with
3387 state.maxy <- calcheight ();
3388 let y = getpagey pageno in
3393 (fun () -> conf.pagebias
)
3394 (fun v -> conf.pagebias
<- v);
3396 src#
int "scroll step"
3397 (fun () -> conf.scrollstep
)
3398 (fun n -> conf.scrollstep
<- n);
3400 src#
int "auto scroll step"
3402 match state.autoscroll
with
3404 | _ -> conf.autoscrollstep
)
3406 if state.autoscroll
<> None
3407 then state.autoscroll
<- Some
n;
3408 conf.autoscrollstep
<- n);
3411 (fun () -> truncate
(conf.zoom *. 100.))
3412 (fun v -> setzoom ((float v) /. 100.));
3415 (fun () -> conf.angle
)
3416 (fun v -> reqlayout v conf.proportional
);
3418 src#
int "scroll bar width"
3419 (fun () -> state.scrollw
)
3423 reshape conf.winw
conf.winh
;
3426 src#
int "scroll handle height"
3427 (fun () -> conf.scrollh
)
3428 (fun v -> conf.scrollh
<- v;);
3430 src#
int "thumbnail width"
3431 (fun () -> conf.thumbw
)
3433 conf.thumbw
<- min
4096 v;
3436 leavebirdseye beye
false;
3442 src#caption
"Presentation mode" 0;
3443 src#
bool "scrollbar visible"
3444 (fun () -> conf.scrollbarinpm
)
3446 if v != conf.scrollbarinpm
3448 conf.scrollbarinpm
<- v;
3449 if conf.presentation
3451 state.scrollw
<- if v then conf.scrollbw
else 0;
3452 reshape conf.winw
conf.winh
;
3458 src#caption
"Pixmap cache" 0;
3459 src#int_with_suffix
"size (advisory)"
3460 (fun () -> conf.memlimit
)
3461 (fun v -> conf.memlimit
<- v);
3464 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3465 (string_with_suffix_of_int state.memused
)
3466 (Hashtbl.length
state.tilemap
)) 1;
3469 src#caption
"Layout" 0;
3470 src#caption2
"Dimension"
3472 Printf.sprintf
"%dx%d (virtual %dx%d)"
3478 src#caption2
"Position" (fun () ->
3479 Printf.sprintf
"%dx%d" state.x state.y
3482 src#caption2
"Visible" (fun () -> describe_location ()) 1
3486 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3487 "Save these parameters as global defaults at exit"
3488 (fun () -> conf.bedefault
)
3489 (fun v -> conf.bedefault
<- v)
3493 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3494 src#
bool ~offset
:0 ~
btos "Extended parameters"
3495 (fun () -> !showextended)
3496 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3500 (fun () -> conf.checkers
)
3501 (fun v -> conf.checkers
<- v; setcheckers v);
3503 (fun () -> conf.verbose
)
3504 (fun v -> conf.verbose
<- v);
3505 src#
bool "invert colors"
3506 (fun () -> conf.invert
)
3507 (fun v -> conf.invert
<- v);
3509 (fun () -> conf.maxhfit
)
3510 (fun v -> conf.maxhfit
<- v);
3511 src#
bool "redirect stderr"
3512 (fun () -> conf.redirectstderr)
3513 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3514 src#
string "uri launcher"
3515 (fun () -> conf.urilauncher
)
3516 (fun v -> conf.urilauncher
<- v);
3517 src#
string "tile size"
3518 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3521 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3522 conf.tileh
<- max
64 w;
3523 conf.tilew
<- max
64 h;
3526 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3527 v (Printexc.to_string exn
));
3528 src#
int "texture count"
3529 (fun () -> conf.texcount
)
3532 then conf.texcount
<- v
3533 else showtext '
!'
" Failed to set texture count please retry later"
3535 src#
int "slice height"
3536 (fun () -> conf.sliceheight
)
3538 conf.sliceheight
<- v;
3539 wcmd "sliceh" [`i
conf.sliceheight
];
3541 src#
int "anti-aliasing level"
3542 (fun () -> conf.aalevel
)
3544 conf.aalevel
<- bound v 0 8;
3545 state.anchor <- getanchor ();
3546 opendoc state.path
state.password
;
3548 src#
int "ui font size"
3549 (fun () -> fstate.fontsize
)
3550 (fun v -> setfontsize (bound v 5 100));
3551 colorp "background color"
3552 (fun () -> conf.bgcolor
)
3553 (fun v -> conf.bgcolor
<- v);
3554 src#
bool "crop hack"
3555 (fun () -> conf.crophack
)
3556 (fun v -> conf.crophack
<- v);
3557 src#
string "trim fuzz"
3558 (fun () -> irect_to_string conf.trimfuzz
)
3561 conf.trimfuzz
<- irect_of_string v;
3563 then settrim true conf.trimfuzz
;
3565 state.text <- Printf.sprintf
"bad irect `%s': %s"
3566 v (Printexc.to_string exn
)
3568 src#
string "throttle"
3570 match conf.maxwait
with
3571 | None
-> "show place holder if page is not ready"
3574 then "wait for page to fully render"
3576 "wait " ^ string_of_float
time
3577 ^
" seconds before showing placeholder"
3581 let f = float_of_string
v in
3583 then conf.maxwait
<- None
3584 else conf.maxwait
<- Some
f
3586 state.text <- Printf.sprintf
"bad time `%s': %s"
3587 v (Printexc.to_string exn
)
3589 src#colorspace
"color space"
3590 (fun () -> colorspace_to_string conf.colorspace
)
3592 conf.colorspace
<- colorspace_of_int v;
3599 src#caption
"Document" 0;
3600 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3601 src#caption2
"Pages"
3602 (fun () -> string_of_int
state.pagecount
) 1;
3603 src#caption2
"Dimensions"
3604 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3608 src#caption
"Trimmed margins" 0;
3609 src#caption2
"Dimensions"
3610 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3613 src#reset prevmode prevuioh
;
3617 let prevmode = state.mode
3618 and prevuioh
= state.uioh in
3619 fillsrc prevmode prevuioh
;
3620 let source = (src :> lvsource
) in
3621 state.uioh <- coe (object (self)
3622 inherit listview ~
source ~trusted
:true as super
3623 val mutable m_prevmemused
= 0
3624 method infochanged
= function
3626 if m_prevmemused
!= state.memused
3628 m_prevmemused
<- state.memused
;
3629 G.postRedisplay "memusedchanged";
3631 | Pdim
-> G.postRedisplay "pdimchanged"
3632 | Docinfo
-> fillsrc prevmode prevuioh
3634 method special
key =
3635 if Glut.getModifiers
() land Glut.active_ctrl
= 0
3638 | Glut.KEY_LEFT
-> coe (self#updownlevel ~
-1)
3639 | Glut.KEY_RIGHT
-> coe (self#updownlevel
1)
3640 | _ -> super#special
key
3641 else super#special
key
3643 G.postRedisplay "info";
3649 inherit lvsourcebase
3650 method getitemcount
= Array.length
state.help
3652 let s, n, _ = state.help
.(n) in
3655 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3659 m_qsearch
<- qsearch;
3660 match state.help
.(active) with
3661 | _, _, Action
f -> Some
(f uioh)
3671 method hasaction
n =
3672 match state.help
.(n) with
3673 | _, _, Action
_ -> true
3680 state.uioh <- coe (new listview ~
source ~trusted
:true);
3681 G.postRedisplay "help";
3686 let re = Str.regexp
"[\r\n]" in
3688 inherit lvsourcebase
3689 val mutable m_items
= [||]
3691 method getitemcount
= 1 + Array.length m_items
3696 else m_items
.(n-1), 0
3698 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3703 then Buffer.clear
state.errmsgs
;
3704 m_qsearch
<- qsearch;
3711 method hasaction
n =
3715 state.newerrmsgs
<- false;
3716 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
3717 m_items
<- Array.of_list
l
3725 let source = (msgsource :> lvsource
) in
3726 state.uioh <- coe (object
3727 inherit listview ~
source ~trusted
:false as super
3730 then msgsource#reset
;
3733 G.postRedisplay "msgs";
3736 let quickbookmark ?title
() =
3737 match state.layout with
3743 let sec = Unix.gettimeofday
() in
3744 let tm = Unix.localtime
sec in
3745 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
3749 (tm.Unix.tm_year
+ 1900)
3752 | Some
title -> title
3755 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
3760 state.fullscreen
<- None
;
3761 Glut.reshapeWindow
w h;
3764 let viewkeyboard key =
3766 let mode = state.mode in
3767 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
3770 G.postRedisplay "view:enttext"
3772 let c = Char.chr
key in
3774 | '
\027'
| 'q'
-> (* escape *)
3775 begin match state.mstate
with
3777 state.mstate
<- Mnone
;
3778 Glut.setCursor
Glut.CURSOR_INHERIT
;
3779 G.postRedisplay "kill zoom rect";
3784 | '
\008'
-> (* backspace *)
3785 let y = getnav ~
-1 in
3786 gotoy_and_clear_text y
3794 G.postRedisplay "dehighlight";
3797 let ondone isforw
s =
3798 cbput state.hists
.pat
s;
3799 state.searchpattern
<- s;
3802 let s = String.create
1 in
3804 enttext (s, "", Some
(onhist state.hists
.pat
),
3805 textentry, ondone (c ='
/'
))
3807 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3808 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3809 setzoom (conf.zoom +. incr)
3814 try int_of_string
s with exc
->
3815 state.text <- Printf.sprintf
"bad integer `%s': %s"
3816 s (Printexc.to_string exc
);
3822 state.text <- "page bias is now " ^ string_of_int
n;
3825 enttext ("page bias: ", "", None
, intentry, ondone)
3827 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3828 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3829 setzoom (max
0.01 (conf.zoom -. decr))
3832 let ondone msg
= state.text <- msg
in
3834 "option [acfhilpstvAPRSZTI]: ", "", None
,
3835 optentry state.mode, ondone
3838 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3841 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3842 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
3846 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3852 try int_of_string
s with exc
->
3853 state.text <- Printf.sprintf
"bad integer `%s': %s"
3854 s (Printexc.to_string exc
);
3860 cbput state.hists
.pag
(string_of_int
n);
3861 gotoy_and_clear_text (getpagey (n + conf.pagebias
- 1))
3864 let pageentry text key =
3865 match Char.unsafe_chr
key with
3866 | 'g'
-> TEdone
text
3867 | _ -> intentry text key
3869 let text = "x" in text.[0] <- c;
3870 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
3873 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
3874 reshape conf.winw
conf.winh
;
3877 conf.hlinks
<- not
conf.hlinks
;
3878 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
3879 G.postRedisplay "toggle highlightlinks";
3882 begin match state.autoscroll
with
3884 conf.autoscrollstep
<- step
;
3885 state.autoscroll
<- None
3887 if conf.autoscrollstep
= 0
3888 then state.autoscroll
<- Some
1
3889 else state.autoscroll
<- Some
conf.autoscrollstep
3893 conf.presentation <- not
conf.presentation;
3894 if conf.presentation
3896 if not
conf.scrollbarinpm
3897 then state.scrollw
<- 0;
3900 state.scrollw
<- conf.scrollbw
;
3902 showtext ' '
("presentation mode " ^
3903 if conf.presentation then "on" else "off");
3904 state.anchor <- getanchor ();
3908 begin match state.fullscreen
with
3910 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
3913 state.fullscreen
<- None
;
3918 gotoy_and_clear_text 0
3921 gotopage1 (state.pagecount
- 1) 0
3924 search state.searchpattern
true
3927 search state.searchpattern
false
3930 begin match state.layout with
3933 gotoy_and_clear_text (getpagey l.pageno)
3937 begin match List.rev
state.layout with
3940 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
3941 gotoy_and_clear_text (getpagey pageno)
3944 | '
\127'
-> (* del *)
3945 begin match state.layout with
3948 let pageno = max
0 (l.pageno-1) in
3949 gotoy_and_clear_text (getpagey pageno)
3953 showtext ' '
(describe_location ());
3956 begin match state.layout with
3959 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
3964 enterbookmarkmode ()
3972 | '
e'
when conf.redirectstderr ->
3977 match state.layout with
3980 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
3984 enttext ("bookmark: ", "", None
, textentry, ondone)
3988 showtext ' '
"Quick bookmark added";
3991 begin match state.layout with
3993 let rect = getpdimrect
l.pagedimno
in
3997 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
3998 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4000 (truncate
(rect.(1) -. rect.(0)),
4001 truncate
(rect.(3) -. rect.(0)))
4003 let w = truncate
((float w)*.conf.zoom)
4004 and h = truncate
((float h)*.conf.zoom) in
4007 state.anchor <- getanchor ();
4008 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4010 G.postRedisplay "z";
4015 | '
\000'
-> (* ctrl-2 *)
4016 let maxw = getmaxw
() in
4018 then setzoom (maxw /. float conf.winw
)
4021 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
4025 bound (conf.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
4027 G.postRedisplay "brightness";
4030 begin match state.mode with
4031 | Birdseye beye
-> upbirdseye beye
4032 | _ -> gotoy (clamp (-conf.scrollstep
))
4036 begin match state.mode with
4037 | Birdseye beye
-> downbirdseye beye
4038 | _ -> gotoy (clamp conf.scrollstep
)
4042 state.anchor <- getanchor ();
4043 opendoc state.path
state.password
4045 | '
v'
when conf.debug
->
4048 match getopaque l.pageno with
4051 let x0, y0
, x1
, y1
= pagebbox opaque
in
4052 let a,b = float x0, float y0
in
4053 let c,d = float x1
, float y0
in
4054 let e,f = float x1
, float y1
in
4055 let h,j
= float x0, float y1
in
4056 let rect = (a,b,c,d,e,f,h,j
) in
4058 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4060 G.postRedisplay "v";
4063 vlog "huh? %d %c" key (Char.chr
key);
4066 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
4068 | 27 -> (* escape *)
4069 leavebirdseye beye
true
4071 | 12 -> (* ctrl-l *)
4072 let y, h = getpageyh pageno in
4073 let top = (conf.winh
- h) / 2 in
4074 gotoy (max
0 (y - top))
4077 leavebirdseye beye
false
4083 let keyboard ~
key ~
x ~
y =
4086 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
4087 then wcmd "interrupt" []
4088 else state.uioh <- state.uioh#
key key
4091 let birdseyespecial key ((conf, leftx
, _, hooverpageno
, anchor) as beye
) =
4093 | Glut.KEY_UP
-> upbirdseye beye
4094 | Glut.KEY_DOWN
-> downbirdseye beye
4096 | Glut.KEY_PAGE_UP
->
4097 begin match state.layout with
4101 state.mode <- Birdseye
(
4102 conf, leftx
, l.pageno, hooverpageno
, anchor
4104 gotopage1 l.pageno 0;
4107 let layout = layout (state.y-conf.winh
) conf.winh
in
4109 | [] -> gotoy (clamp (-conf.winh
))
4111 state.mode <- Birdseye
(
4112 conf, leftx
, l.pageno, hooverpageno
, anchor
4114 gotopage1 l.pageno 0
4117 | [] -> gotoy (clamp (-conf.winh
))
4120 | Glut.KEY_PAGE_DOWN
->
4121 begin match List.rev
state.layout with
4123 let layout = layout (state.y + conf.winh
) conf.winh
in
4124 begin match layout with
4126 let incr = l.pageh
- l.pagevh in
4131 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4133 G.postRedisplay "birdseye pagedown";
4135 else gotoy (clamp (incr + conf.interpagespace*2));
4139 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
4140 gotopage1 l.pageno 0;
4143 | [] -> gotoy (clamp conf.winh
)
4147 state.mode <- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
4151 let pageno = state.pagecount
- 1 in
4152 state.mode <- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
4153 if not
(pagevisible state.layout pageno)
4156 match List.rev
state.pdims
with
4158 | (_, _, h, _) :: _ -> h
4160 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4161 else G.postRedisplay "birdseye end";
4165 let setautoscrollspeed step goingdown
=
4166 let incr = max
1 ((abs step
) / 2) in
4167 let incr = if goingdown
then incr else -incr in
4168 let astep = step
+ incr in
4169 state.autoscroll
<- Some
astep;
4172 let special ~
key ~
x ~
y =
4175 state.uioh <- state.uioh#
special key
4180 match state.mode with
4181 | Textentry
_ -> scalecolor 0.4
4182 | View
-> scalecolor 1.0
4183 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4184 if l.pageno = hooverpageno
4187 if l.pageno = pageno
4193 begin match getopaque l.pageno with
4195 if tileready l l.pagex l.pagey
4197 let x = l.pagedispx
- l.pagex
4198 and y = l.pagedispy
- l.pagey in
4199 postprocess opaque
conf.hlinks
x y;
4205 let scrollindicator () =
4206 let sbw, ph
, sh = state.uioh#
scrollph in
4207 let sbh, pw
, sw = state.uioh#scrollpw
in
4209 GlDraw.color (0.64, 0.64, 0.64);
4211 (float (conf.winw
- sbw), 0.)
4212 (float conf.winw
, float conf.winh
)
4215 (0., float (conf.winh
- sbh))
4216 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4218 GlDraw.color (0.0, 0.0, 0.0);
4221 (float (conf.winw
- sbw), ph
)
4222 (float conf.winw
, ph
+. sh)
4225 (pw
, float (conf.winh
- sbh))
4226 (pw
+. sw, float conf.winh
)
4230 let pagetranslatepoint l x y =
4231 let dy = y - l.pagedispy
in
4232 let y = dy + l.pagey in
4233 let dx = x - l.pagedispx
in
4234 let x = dx + l.pagex in
4239 match state.mstate
with
4240 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4243 | Msel
((x0, y0
), (x1
, y1
)) ->
4244 let rec loop = function
4246 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
4247 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
4249 match getopaque l.pageno with
4251 let dx, dy = pagetranslatepoint l 0 0 in
4256 GlMat.mode `modelview
;
4258 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4259 seltext opaque
(x0, y0
, x1
, y1
);
4270 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4271 GlDraw.polygon_mode `both `fill
;
4272 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4274 (fun (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
4276 if l.pageno = pageno
4278 let dx = float (l.pagedispx
- l.pagex) in
4279 let dy = float (l.pagedispy
- l.pagey) in
4280 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4281 GlDraw.begins `quads
;
4283 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4284 GlDraw.vertex2
(x1
+.dx, y1
+.dy);
4285 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4286 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4297 GlClear.color (scalecolor2 conf.bgcolor
);
4298 GlClear.clear
[`
color];
4299 List.iter
drawpage state.layout;
4304 begin match state.mstate
with
4305 | Mzoomrect
((x0, y0
), (x1
, y1
)) ->
4307 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4308 GlDraw.polygon_mode `both `fill
;
4309 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4310 GlDraw.rect (float x0, float y0
)
4311 (float x1
, float y1
);
4316 Glut.swapBuffers
();
4320 let rec f = function
4322 begin match getopaque l.pageno with
4324 let x0 = l.pagedispx
in
4325 let x1 = x0 + l.pagevw in
4326 let y0 = l.pagedispy
in
4327 let y1 = y0 + l.pagevh in
4328 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4330 let px, py = pagetranslatepoint l x y in
4331 match whatsunder opaque
px py with
4343 let zoomrect x y x1 y1 =
4346 and y0 = min
y y1 in
4347 gotoy (state.y + y0);
4348 state.anchor <- getanchor ();
4349 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4351 if state.w < conf.winw
- state.scrollw
4352 then (conf.winw
- state.scrollw
- state.w) / 2
4355 state.x <- (state.x + margin) - x0;
4357 Glut.setCursor
Glut.CURSOR_INHERIT
;
4358 state.mstate
<- Mnone
;
4362 let winw = conf.winw - state.scrollw
- 1 in
4363 let s = float x /. float winw in
4364 let destx = truncate
(float (state.w + winw) *. s) in
4365 state.x <- winw - destx;
4366 gotoy_and_clear_text state.y;
4367 state.mstate
<- Mscrollx
;
4371 let s = float y /. float conf.winh
in
4372 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4373 gotoy_and_clear_text desty;
4374 state.mstate
<- Mscrolly
;
4377 let viewmouse button bstate
x y =
4379 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4380 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4382 match state.mstate
with
4383 | Mzoom
(oldn
, i
) ->
4391 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4393 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4395 let zoom = conf.zoom -. incr in
4397 state.mstate
<- Mzoom
(n, 0);
4399 state.mstate
<- Mzoom
(n, i
+1);
4401 else state.mstate
<- Mzoom
(n, 0)
4403 | _ -> state.mstate
<- Mzoom
(n, 0)
4406 match state.autoscroll
with
4407 | Some step
-> setautoscrollspeed step
(n=4)
4411 then -conf.scrollstep
4412 else conf.scrollstep
4414 let incr = incr * 2 in
4415 let y = clamp incr in
4416 gotoy_and_clear_text y
4419 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4420 if bstate
= Glut.DOWN
4422 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4423 state.mstate
<- Mpan
(x, y)
4426 state.mstate
<- Mnone
4428 | Glut.RIGHT_BUTTON
->
4429 if bstate
= Glut.DOWN
4431 Glut.setCursor
Glut.CURSOR_CYCLE
;
4433 state.mstate
<- Mzoomrect
(p, p)
4436 match state.mstate
with
4437 | Mzoomrect
((x0, y0), _) ->
4438 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4439 then zoomrect x0 y0 x y
4441 state.mstate
<- Mnone
;
4442 Glut.setCursor
Glut.CURSOR_INHERIT
;
4443 G.postRedisplay "kill accidental zoom rect";
4446 Glut.setCursor
Glut.CURSOR_INHERIT
;
4447 state.mstate
<- Mnone
4450 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4451 if bstate
= Glut.DOWN
4453 let _, position, sh = state.uioh#
scrollph in
4454 if y > truncate
position && y < truncate
(position +. sh)
4455 then state.mstate
<- Mscrolly
4458 state.mstate
<- Mnone
4460 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4461 if bstate
= Glut.DOWN
4463 let _, position, sw = state.uioh#scrollpw
in
4464 if x > truncate
position && x < truncate
(position +. sw)
4465 then state.mstate
<- Mscrollx
4468 state.mstate
<- Mnone
4470 | Glut.LEFT_BUTTON
->
4471 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4472 begin match dest with
4473 | Ulinkgoto
(pageno, top) ->
4477 gotopage1 pageno top;
4483 | Unone
when bstate
= Glut.DOWN
->
4484 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4485 state.mstate
<- Mpan
(x, y);
4487 | Unone
| Utext
_ ->
4488 if bstate
= Glut.DOWN
4490 if conf.angle
mod 360 = 0
4492 state.mstate
<- Msel
((x, y), (x, y));
4493 G.postRedisplay "mouse select";
4497 match state.mstate
with
4500 | Mzoom
_ | Mscrollx
| Mscrolly
->
4501 state.mstate
<- Mnone
4503 | Mzoomrect
((x0, y0), _) ->
4507 Glut.setCursor
Glut.CURSOR_INHERIT
;
4508 state.mstate
<- Mnone
4510 | Msel
((_, y0), (_, y1)) ->
4512 if (y0 >= l.pagedispy
&& y0 <= (l.pagedispy
+ l.pagevh))
4513 || ((y1 >= l.pagedispy
&& y1 <= (l.pagedispy
+ l.pagevh)))
4515 match getopaque l.pageno with
4520 List.iter
f state.layout;
4521 copysel
""; (* ugly *)
4522 Glut.setCursor
Glut.CURSOR_INHERIT
;
4523 state.mstate
<- Mnone
;
4530 let birdseyemouse button bstate
x y
4531 (conf, leftx
, _, hooverpageno
, anchor) =
4533 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4534 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4535 let rec loop = function
4538 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4539 && x > margin && x < margin + l.pagew
4541 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4546 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4550 let mouse bstate button
x y =
4551 state.uioh <- state.uioh#button button bstate
x y;
4554 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4557 state.uioh <- state.uioh#
motion x y
4561 state.uioh <- state.uioh#
pmotion x y;
4568 begin match state.mode with
4569 | Textentry
textentry -> textentrykeyboard key textentry
4570 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4571 | View
-> viewkeyboard key
4575 method special key =
4576 begin match state.mode with
4577 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4581 birdseyespecial key vals
4583 | View
when key = Glut.KEY_F1
->
4587 begin match state.autoscroll
with
4588 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4589 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4594 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4596 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4598 if Glut.getModifiers
() land Glut.active_shift
!= 0
4599 then (setzoom state.prevzoom
; state.y)
4600 else clamp (-conf.winh
/2)
4601 else clamp (-conf.scrollstep
)
4603 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4605 if Glut.getModifiers
() land Glut.active_shift
!= 0
4606 then (setzoom state.prevzoom
; state.y)
4607 else clamp (conf.winh
/2)
4608 else clamp (conf.scrollstep
)
4609 | Glut.KEY_PAGE_UP
->
4610 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4612 match state.layout with
4614 | l :: _ -> state.y - l.pagey
4617 | Glut.KEY_PAGE_DOWN
->
4618 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4620 match List.rev
state.layout with
4622 | l :: _ -> getpagey l.pageno
4630 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
4632 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
4633 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
4634 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
4636 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
4638 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4639 then (conf.winw / 2)
4642 state.x <- state.x - dx;
4644 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
4646 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4647 then (conf.winw / 2)
4650 state.x <- state.x + dx;
4655 gotoy_and_clear_text y
4658 | Textentry
te -> textentryspecial key te
4662 method button button bstate
x y =
4663 begin match state.mode with
4664 | View
-> viewmouse button bstate
x y
4665 | Birdseye beye
-> birdseyemouse button bstate
x y beye
4671 begin match state.mode with
4673 | View
| Birdseye
_ ->
4674 match state.mstate
with
4675 | Mzoom
_ | Mnone
-> ()
4680 state.mstate
<- Mpan
(x, y);
4681 if conf.zoom > 1.0 then state.x <- state.x + dx;
4683 gotoy_and_clear_text y
4686 state.mstate
<- Msel
(a, (x, y));
4687 G.postRedisplay "motion select";
4690 let y = min
conf.winh
(max
0 y) in
4694 let x = min
conf.winw (max
0 x) in
4697 | Mzoomrect
(p0
, _) ->
4698 state.mstate
<- Mzoomrect
(p0
, (x, y));
4699 G.postRedisplay "motion zoomrect";
4703 method pmotion x y =
4704 begin match state.mode with
4705 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
4706 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4707 let rec loop = function
4709 if hooverpageno
!= -1
4711 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
4712 G.postRedisplay "pmotion birdseye no hoover";
4715 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4716 && x > margin && x < margin + l.pagew
4718 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
4719 G.postRedisplay "pmotion birdseye hoover";
4728 match state.mstate
with
4730 begin match getunder x y with
4731 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
4733 if conf.underinfo
then showtext 'u'
("ri: " ^
uri);
4734 Glut.setCursor
Glut.CURSOR_INFO
4735 | Ulinkgoto
(page
, _) ->
4737 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
4738 Glut.setCursor
Glut.CURSOR_INFO
4740 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
4741 Glut.setCursor
Glut.CURSOR_TEXT
4744 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
4749 method infochanged
_ = ()
4752 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
4753 let p, h = scrollph state.y maxy in
4757 let winw = conf.winw - state.scrollw
- 1 in
4758 let fwinw = float winw in
4760 let sw = fwinw /. float state.w in
4761 let sw = fwinw *. sw in
4762 max
sw (float conf.scrollh
)
4765 let f = state.w+winw in
4766 let r = float (winw-state.x) /. float f in
4767 let p = fwinw *. r in
4771 if position +. sw > fwinw
4772 then fwinw -. position
4775 state.hscrollh, position, sw
4782 let fontpath = ref "";;
4783 let wmclasshack = ref false;;
4786 let l = String.length
s in
4787 let b = Buffer.create
l in
4795 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
4796 | _ -> Sys.getenv
"HOME"
4799 ("Can not determine home directory location: " ^
4800 Printexc.to_string exn
);
4804 let config_of c attrs
=
4808 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
4809 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
4810 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
4811 | "preload" -> { c with preload = bool_of_string
v }
4812 | "page-bias" -> { c with pagebias
= int_of_string
v }
4813 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
4814 | "auto-scroll-step" ->
4815 { c with autoscrollstep
= max
0 (int_of_string
v) }
4816 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
4817 | "crop-hack" -> { c with crophack
= bool_of_string
v }
4820 match String.lowercase
v with
4821 | "true" -> Some infinity
4823 | f -> Some
(float_of_string
f)
4825 { c with maxwait
= mw}
4826 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
4827 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
4828 | "vertical-margin" ->
4829 { c with interpagespace = max
0 (int_of_string
v) }
4831 let zoom = float_of_string
v /. 100. in
4832 let zoom = max
zoom 0.0 in
4833 { c with zoom = zoom }
4834 | "presentation" -> { c with presentation = bool_of_string
v }
4835 | "rotation-angle" -> { c with angle
= int_of_string
v }
4836 | "width" -> { c with winw = max
20 (int_of_string
v) }
4837 | "height" -> { c with winh
= max
20 (int_of_string
v) }
4838 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
4839 | "proportional-display" -> { c with proportional
= bool_of_string
v }
4840 | "pixmap-cache-size" ->
4841 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
4842 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
4843 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
4844 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
4845 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
4846 | "background-color" -> { c with bgcolor
= color_of_string v }
4847 | "scrollbar-in-presentation" ->
4848 { c with scrollbarinpm
= bool_of_string
v }
4849 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
4850 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
4851 | "mupdf-memlimit" ->
4852 { c with mumemlimit
= max
1024 (int_of_string_with_suffix v) }
4853 | "checkers" -> { c with checkers
= bool_of_string
v }
4854 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
4855 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
4856 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
4857 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
4858 | "uri-launcher" -> { c with urilauncher
= unent v }
4859 | "color-space" -> { c with colorspace
= colorspace_of_string v }
4860 | "invert-colors" -> { c with invert
= bool_of_string
v }
4861 | "brightness" -> { c with colorscale
= float_of_string
v }
4862 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
4865 prerr_endline
("Error processing attribute (`" ^
4866 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
4869 let rec fold c = function
4872 let c = apply c k
v in
4878 let fromstring f pos
n v d =
4881 dolog "Error processing attribute (%S=%S) at %d\n%s"
4882 n v pos
(Printexc.to_string exn
)
4887 let bookmark_of attrs
=
4888 let rec fold title page
rely = function
4889 | ("title", v) :: rest
-> fold v page
rely rest
4890 | ("page", v) :: rest
-> fold title v rely rest
4891 | ("rely", v) :: rest
-> fold title page
v rest
4892 | _ :: rest
-> fold title page
rely rest
4893 | [] -> title, page
, rely
4895 fold "invalid" "0" "0" attrs
4899 let rec fold path page
rely pan
= function
4900 | ("path", v) :: rest
-> fold v page
rely pan rest
4901 | ("page", v) :: rest
-> fold path
v rely pan rest
4902 | ("rely", v) :: rest
-> fold path page
v pan rest
4903 | ("pan", v) :: rest
-> fold path page
rely v rest
4904 | _ :: rest
-> fold path page
rely pan rest
4905 | [] -> path
, page
, rely, pan
4907 fold "" "0" "0" "0" attrs
4910 let setconf dst
src =
4911 dst
.scrollbw
<- src.scrollbw
;
4912 dst
.scrollh
<- src.scrollh
;
4913 dst
.icase
<- src.icase
;
4914 dst
.preload <- src.preload;
4915 dst
.pagebias
<- src.pagebias
;
4916 dst
.verbose
<- src.verbose
;
4917 dst
.scrollstep
<- src.scrollstep
;
4918 dst
.maxhfit
<- src.maxhfit
;
4919 dst
.crophack
<- src.crophack
;
4920 dst
.autoscrollstep
<- src.autoscrollstep
;
4921 dst
.maxwait
<- src.maxwait
;
4922 dst
.hlinks
<- src.hlinks
;
4923 dst
.underinfo
<- src.underinfo
;
4924 dst
.interpagespace <- src.interpagespace;
4925 dst
.zoom <- src.zoom;
4926 dst
.presentation <- src.presentation;
4927 dst
.angle
<- src.angle
;
4928 dst
.winw <- src.winw;
4929 dst
.winh
<- src.winh
;
4930 dst
.savebmarks
<- src.savebmarks
;
4931 dst
.memlimit
<- src.memlimit
;
4932 dst
.proportional
<- src.proportional
;
4933 dst
.texcount
<- src.texcount
;
4934 dst
.sliceheight
<- src.sliceheight
;
4935 dst
.thumbw
<- src.thumbw
;
4936 dst
.jumpback
<- src.jumpback
;
4937 dst
.bgcolor
<- src.bgcolor
;
4938 dst
.scrollbarinpm
<- src.scrollbarinpm
;
4939 dst
.tilew
<- src.tilew
;
4940 dst
.tileh
<- src.tileh
;
4941 dst
.mumemlimit
<- src.mumemlimit
;
4942 dst
.checkers
<- src.checkers
;
4943 dst
.aalevel
<- src.aalevel
;
4944 dst
.trimmargins
<- src.trimmargins
;
4945 dst
.trimfuzz
<- src.trimfuzz
;
4946 dst
.urilauncher
<- src.urilauncher
;
4947 dst
.colorspace
<- src.colorspace
;
4948 dst
.invert
<- src.invert
;
4949 dst
.colorscale
<- src.colorscale
;
4950 dst
.redirectstderr <- src.redirectstderr;
4954 let h = Hashtbl.create
10 in
4955 let dc = { defconf with angle
= defconf.angle
} in
4956 let rec toplevel v t spos
_ =
4958 | Vdata
| Vcdata
| Vend
-> v
4959 | Vopen
("llppconfig", _, closed
) ->
4962 else { v with f = llppconfig
}
4964 error
"unexpected subelement at top level" s spos
4965 | Vclose
_ -> error
"unexpected close at top level" s spos
4967 and llppconfig
v t spos
_ =
4969 | Vdata
| Vcdata
-> v
4970 | Vend
-> error
"unexpected end of input in llppconfig" s spos
4971 | Vopen
("defaults", attrs
, closed
) ->
4972 let c = config_of dc attrs
in
4976 else { v with f = skip
"defaults" (fun () -> v) }
4978 | Vopen
("ui-font", attrs
, closed
) ->
4979 let rec getsize size
= function
4981 | ("size", v) :: rest
->
4983 fromstring int_of_string spos
"size" v fstate.fontsize
in
4985 | l -> getsize size l
4987 fstate.fontsize
<- getsize fstate.fontsize attrs
;
4990 else { v with f = uifont
(Buffer.create
10) }
4992 | Vopen
("doc", attrs
, closed
) ->
4993 let pathent, spage
, srely
, span
= doc_of attrs
in
4994 let path = unent pathent
4995 and pageno = fromstring int_of_string spos
"page" spage
0
4996 and rely = fromstring float_of_string spos
"rely" srely
0.0
4997 and pan
= fromstring int_of_string spos
"pan" span
0 in
4998 let c = config_of dc attrs
in
4999 let anchor = (pageno, rely) in
5001 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5002 else { v with f = doc
path pan
anchor c [] }
5005 error
"unexpected subelement in llppconfig" s spos
5007 | Vclose
"llppconfig" -> { v with f = toplevel }
5008 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5010 and uifont
b v t spos epos
=
5013 Buffer.add_substring
b s spos
(epos
- spos
);
5015 | Vopen
(_, _, _) ->
5016 error
"unexpected subelement in ui-font" s spos
5017 | Vclose
"ui-font" ->
5018 if String.length
!fontpath = 0
5019 then fontpath := Buffer.contents
b;
5020 { v with f = llppconfig
}
5021 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5022 | Vend
-> error
"unexpected end of input in ui-font" s spos
5024 and doc
path pan
anchor c bookmarks
v t spos
_ =
5026 | Vdata
| Vcdata
-> v
5027 | Vend
-> error
"unexpected end of input in doc" s spos
5028 | Vopen
("bookmarks", _, closed
) ->
5031 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5033 | Vopen
(_, _, _) ->
5034 error
"unexpected subelement in doc" s spos
5037 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5038 { v with f = llppconfig
}
5040 | Vclose
_ -> error
"unexpected close in doc" s spos
5042 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5044 | Vdata
| Vcdata
-> v
5045 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5046 | Vopen
("item", attrs
, closed
) ->
5047 let titleent, spage
, srely
= bookmark_of attrs
in
5048 let page = fromstring int_of_string spos
"page" spage
0
5049 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5050 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5052 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5055 { v with f = skip
"item" f }
5058 error
"unexpected subelement in bookmarks" s spos
5060 | Vclose
"bookmarks" ->
5061 { v with f = doc
path pan
anchor c bookmarks }
5063 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5065 and skip tag
f v t spos
_ =
5067 | Vdata
| Vcdata
-> v
5069 error
("unexpected end of input in skipped " ^ tag
) s spos
5070 | Vopen
(tag'
, _, closed
) ->
5074 let f'
() = { v with f = skip tag
f } in
5075 { v with f = skip tag'
f'
}
5079 else error
("unexpected close in skipped " ^ tag
) s spos
5082 parse
{ f = toplevel; accu = () } s;
5088 let len = in_channel_length ic
in
5089 let s = String.create
len in
5090 really_input ic
s 0 len;
5093 | Parse_error
(msg
, s, pos
) ->
5094 let subs = subs s pos
in
5095 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5096 failwith
("parse error: " ^
s)
5099 failwith
("config load error: " ^
Printexc.to_string exn
)
5105 let dir = Filename.concat
home ".config" in
5106 if Sys.is_directory
dir then dir else home
5109 Filename.concat
dir "llpp.conf"
5112 let confpath = ref defconfpath;;
5115 if Sys.file_exists
!confpath
5118 (try Some
(open_in_bin
!confpath)
5121 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5122 Printexc.to_string exn
);
5131 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5132 Printexc.to_string exn
);
5138 f (Hashtbl.create
0, defconf)
5143 let pc, pb
, px, pa
=
5145 Hashtbl.find h (Filename.basename
state.path)
5146 with Not_found
-> dc, [], 0, (0, 0.0)
5150 state.bookmarks <- pb
;
5152 state.scrollw
<- conf.scrollbw
;
5154 then state.anchor <- pa
;
5155 cbput state.hists
.nav pa
;
5160 let add_attrs bb always
dc c =
5163 then Printf.bprintf bb
"\n %s='%b'" s a
5166 then Printf.bprintf bb
"\n %s='%d'" s a
5169 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5172 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5175 then Printf.bprintf bb
"\n %s='%f'" s a
5179 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5183 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5187 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5191 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5201 else string_of_float
f
5203 Printf.bprintf bb
"\n %s='%s'" s v
5207 then dc.winw, dc.winh
5209 match state.fullscreen
with
5211 | None
-> c.winw, c.winh
5213 let zoom, presentation, interpagespace, maxwait
=
5215 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5217 match state.mode with
5218 | Birdseye
(bc
, _, _, _, _) ->
5219 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5220 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5222 oi
"width" w dc.winw;
5223 oi
"height" h dc.winh
;
5224 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5225 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5226 ob "case-insensitive-search" c.icase
dc.icase
;
5227 ob "preload" c.preload dc.preload;
5228 oi
"page-bias" c.pagebias
dc.pagebias
;
5229 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5230 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5231 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5232 ob "crop-hack" c.crophack
dc.crophack
;
5233 oW
"throttle" maxwait
dc.maxwait
;
5234 ob "highlight-links" c.hlinks
dc.hlinks
;
5235 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5236 oi
"vertical-margin" interpagespace dc.interpagespace;
5237 oz
"zoom" zoom dc.zoom;
5238 ob "presentation" presentation dc.presentation;
5239 oi
"rotation-angle" c.angle
dc.angle
;
5240 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5241 ob "proportional-display" c.proportional
dc.proportional
;
5242 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5243 oi
"tex-count" c.texcount
dc.texcount
;
5244 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5245 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5246 ob "persistent-location" c.jumpback
dc.jumpback
;
5247 oc
"background-color" c.bgcolor
dc.bgcolor
;
5248 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5249 oi
"tile-width" c.tilew
dc.tilew
;
5250 oi
"tile-height" c.tileh
dc.tileh
;
5251 oI
"mupdf-memlimit" c.mumemlimit
dc.mumemlimit
;
5252 ob "checkers" c.checkers
dc.checkers
;
5253 oi
"aalevel" c.aalevel
dc.aalevel
;
5254 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5255 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5256 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5257 oC
"color-space" c.colorspace
dc.colorspace
;
5258 ob "invert-colors" c.invert
dc.invert
;
5259 oF
"brightness" c.colorscale
dc.colorscale
;
5260 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5262 then ob "wmclass-hack" !wmclasshack false;
5266 let uifontsize = fstate.fontsize
in
5267 let bb = Buffer.create
32768 in
5269 let dc = if conf.bedefault
then conf else dc in
5270 Buffer.add_string
bb "<llppconfig>\n";
5272 if String.length
!fontpath > 0
5274 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5280 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5283 Buffer.add_string
bb "<defaults ";
5284 add_attrs bb true dc dc;
5285 Buffer.add_string
bb "/>\n";
5287 let adddoc path pan
anchor c bookmarks =
5288 if bookmarks == [] && c = dc && anchor = emptyanchor
5291 Printf.bprintf
bb "<doc path='%s'"
5292 (enent
path 0 (String.length
path));
5294 if anchor <> emptyanchor
5296 let n, y = anchor in
5297 Printf.bprintf
bb " page='%d'" n;
5300 Printf.bprintf
bb " rely='%f'" y
5305 then Printf.bprintf
bb " pan='%d'" pan
;
5307 add_attrs bb false dc c;
5309 begin match bookmarks with
5310 | [] -> Buffer.add_string
bb "/>\n"
5312 Buffer.add_string
bb ">\n<bookmarks>\n";
5313 List.iter
(fun (title, _level
, (page, rely)) ->
5315 "<item title='%s' page='%d'"
5316 (enent
title 0 (String.length
title))
5321 Printf.bprintf
bb " rely='%f'" rely
5323 Buffer.add_string
bb "/>\n";
5325 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5331 match state.mode with
5332 | Birdseye
(_, pan, _, _, _) -> pan
5335 let basename = Filename.basename state.path in
5336 adddoc basename pan (getanchor ())
5339 match state.autoscroll
with
5341 | None
-> conf.autoscrollstep
}
5342 (if conf.savebmarks
then state.bookmarks else []);
5344 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5346 then adddoc path x y c bookmarks
5348 Buffer.add_string
bb "</llppconfig>";
5351 if Buffer.length
bb > 0
5354 let tmp = !confpath ^
".tmp" in
5355 let oc = open_out_bin
tmp in
5356 Buffer.output_buffer
oc bb;
5358 Unix.rename
tmp !confpath;
5361 ("error while saving configuration: " ^
Printexc.to_string exn
)
5368 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5369 "<password> Set password");
5371 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5372 "<path> Set path to the user interface font");
5374 ("-c", Arg.String
(fun s -> Config.confpath := s),
5375 "<path> Set path to the configuration file");
5377 ("-v", Arg.Unit
(fun () ->
5379 "%s\nconfiguration path: %s\n"
5383 exit
0), " Print version and exit");
5386 (fun s -> state.path <- s)
5387 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5389 if String.length
state.path = 0
5390 then (prerr_endline
"file name missing"; exit
1);
5394 let _ = Glut.init
Sys.argv
in
5395 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5396 let () = Glut.initWindowSize
conf.winw conf.winh
in
5397 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5399 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5400 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5401 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5406 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5408 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5409 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5410 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5411 Unix.bind
sock addr;
5413 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5414 Unix.connect
csock addr;
5415 let ssock, _ = Unix.accept
sock in
5418 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5419 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5426 let () = Glut.displayFunc
display in
5427 let () = Glut.reshapeFunc
reshape in
5428 let () = Glut.keyboardFunc
keyboard in
5429 let () = Glut.specialFunc
special in
5430 let () = Glut.idleFunc
(Some
idle) in
5431 let () = Glut.mouseFunc
mouse in
5432 let () = Glut.motionFunc
motion in
5433 let () = Glut.passiveMotionFunc
pmotion in
5435 setcheckers conf.checkers
;
5437 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5438 conf.texcount
, conf.sliceheight
, conf.mumemlimit
, conf.colorspace
,
5439 !Config.wmclasshack, !Config.fontpath
5441 state.csock <- csock;
5442 state.ssock <- ssock;
5443 state.text <- "Opening " ^
state.path;
5444 setaalevel
conf.aalevel
;
5445 writeopen state.path state.password
;
5447 setfontsize fstate.fontsize
;
5455 | Glut.BadEnum
"key in special_of_int" ->
5456 showtext '
!'
" LablGlut bug: special key not recognized";
5463 | exn
when conf.redirectstderr ->
5465 Printf.sprintf
"exception %s\n%s"
5466 (Printexc.to_string exn
)
5467 (Printexc.get_backtrace
())
5470 Unix.single_write
state.stderr
s 0 (String.length
s);