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
;
3604 src#caption
"Trimmed margins" 0;
3605 src#caption2
"Dimensions"
3606 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3609 src#reset prevmode prevuioh
;
3613 let prevmode = state.mode
3614 and prevuioh
= state.uioh in
3615 fillsrc prevmode prevuioh
;
3616 let source = (src :> lvsource
) in
3617 state.uioh <- coe (object (self)
3618 inherit listview ~
source ~trusted
:true as super
3619 val mutable m_prevmemused
= 0
3620 method infochanged
= function
3622 if m_prevmemused
!= state.memused
3624 m_prevmemused
<- state.memused
;
3625 G.postRedisplay "memusedchanged";
3627 | Pdim
-> G.postRedisplay "pdimchanged"
3628 | Docinfo
-> fillsrc prevmode prevuioh
3630 method special
key =
3631 if Glut.getModifiers
() land Glut.active_ctrl
= 0
3634 | Glut.KEY_LEFT
-> coe (self#updownlevel ~
-1)
3635 | Glut.KEY_RIGHT
-> coe (self#updownlevel
1)
3636 | _ -> super#special
key
3637 else super#special
key
3639 G.postRedisplay "info";
3645 inherit lvsourcebase
3646 method getitemcount
= Array.length
state.help
3648 let s, n, _ = state.help
.(n) in
3651 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3655 m_qsearch
<- qsearch;
3656 match state.help
.(active) with
3657 | _, _, Action
f -> Some
(f uioh)
3667 method hasaction
n =
3668 match state.help
.(n) with
3669 | _, _, Action
_ -> true
3676 state.uioh <- coe (new listview ~
source ~trusted
:true);
3677 G.postRedisplay "help";
3682 let re = Str.regexp
"[\r\n]" in
3684 inherit lvsourcebase
3685 val mutable m_items
= [||]
3687 method getitemcount
= 1 + Array.length m_items
3692 else m_items
.(n-1), 0
3694 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3699 then Buffer.clear
state.errmsgs
;
3700 m_qsearch
<- qsearch;
3707 method hasaction
n =
3711 state.newerrmsgs
<- false;
3712 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
3713 m_items
<- Array.of_list
l
3721 let source = (msgsource :> lvsource
) in
3722 state.uioh <- coe (object
3723 inherit listview ~
source ~trusted
:false as super
3726 then msgsource#reset
;
3729 G.postRedisplay "msgs";
3732 let quickbookmark ?title
() =
3733 match state.layout with
3739 let sec = Unix.gettimeofday
() in
3740 let tm = Unix.localtime
sec in
3741 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
3745 (tm.Unix.tm_year
+ 1900)
3748 | Some
title -> title
3751 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
3756 state.fullscreen
<- None
;
3757 Glut.reshapeWindow
w h;
3760 let viewkeyboard key =
3762 let mode = state.mode in
3763 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
3766 G.postRedisplay "view:enttext"
3768 let c = Char.chr
key in
3770 | '
\027'
| 'q'
-> (* escape *)
3771 begin match state.mstate
with
3773 state.mstate
<- Mnone
;
3774 Glut.setCursor
Glut.CURSOR_INHERIT
;
3775 G.postRedisplay "kill zoom rect";
3780 | '
\008'
-> (* backspace *)
3781 let y = getnav ~
-1 in
3782 gotoy_and_clear_text y
3790 G.postRedisplay "dehighlight";
3793 let ondone isforw
s =
3794 cbput state.hists
.pat
s;
3795 state.searchpattern
<- s;
3798 let s = String.create
1 in
3800 enttext (s, "", Some
(onhist state.hists
.pat
),
3801 textentry, ondone (c ='
/'
))
3803 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3804 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3805 setzoom (conf.zoom +. incr)
3810 try int_of_string
s with exc
->
3811 state.text <- Printf.sprintf
"bad integer `%s': %s"
3812 s (Printexc.to_string exc
);
3818 state.text <- "page bias is now " ^ string_of_int
n;
3821 enttext ("page bias: ", "", None
, intentry, ondone)
3823 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3824 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3825 setzoom (max
0.01 (conf.zoom -. decr))
3828 let ondone msg
= state.text <- msg
in
3830 "option [acfhilpstvAPRSZTI]: ", "", None
,
3831 optentry state.mode, ondone
3834 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3837 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3838 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
3842 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3848 try int_of_string
s with exc
->
3849 state.text <- Printf.sprintf
"bad integer `%s': %s"
3850 s (Printexc.to_string exc
);
3856 cbput state.hists
.pag
(string_of_int
n);
3857 gotoy_and_clear_text (getpagey (n + conf.pagebias
- 1))
3860 let pageentry text key =
3861 match Char.unsafe_chr
key with
3862 | 'g'
-> TEdone
text
3863 | _ -> intentry text key
3865 let text = "x" in text.[0] <- c;
3866 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
3869 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
3870 reshape conf.winw
conf.winh
;
3873 conf.hlinks
<- not
conf.hlinks
;
3874 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
3875 G.postRedisplay "toggle highlightlinks";
3878 begin match state.autoscroll
with
3880 conf.autoscrollstep
<- step
;
3881 state.autoscroll
<- None
3883 if conf.autoscrollstep
= 0
3884 then state.autoscroll
<- Some
1
3885 else state.autoscroll
<- Some
conf.autoscrollstep
3889 conf.presentation <- not
conf.presentation;
3890 if conf.presentation
3892 if not
conf.scrollbarinpm
3893 then state.scrollw
<- 0;
3896 state.scrollw
<- conf.scrollbw
;
3898 showtext ' '
("presentation mode " ^
3899 if conf.presentation then "on" else "off");
3900 state.anchor <- getanchor ();
3904 begin match state.fullscreen
with
3906 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
3909 state.fullscreen
<- None
;
3914 gotoy_and_clear_text 0
3917 gotopage1 (state.pagecount
- 1) 0
3920 search state.searchpattern
true
3923 search state.searchpattern
false
3926 begin match state.layout with
3929 gotoy_and_clear_text (getpagey l.pageno)
3933 begin match List.rev
state.layout with
3936 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
3937 gotoy_and_clear_text (getpagey pageno)
3940 | '
\127'
-> (* del *)
3941 begin match state.layout with
3944 let pageno = max
0 (l.pageno-1) in
3945 gotoy_and_clear_text (getpagey pageno)
3949 showtext ' '
(describe_location ());
3952 begin match state.layout with
3955 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
3960 enterbookmarkmode ()
3968 | '
e'
when conf.redirectstderr ->
3973 match state.layout with
3976 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
3980 enttext ("bookmark: ", "", None
, textentry, ondone)
3984 showtext ' '
"Quick bookmark added";
3987 begin match state.layout with
3989 let rect = getpdimrect
l.pagedimno
in
3993 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
3994 truncate
(1.2 *. (rect.(3) -. rect.(0))))
3996 (truncate
(rect.(1) -. rect.(0)),
3997 truncate
(rect.(3) -. rect.(0)))
3999 let w = truncate
((float w)*.conf.zoom)
4000 and h = truncate
((float h)*.conf.zoom) in
4003 state.anchor <- getanchor ();
4004 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4006 G.postRedisplay "z";
4011 | '
\000'
-> (* ctrl-2 *)
4012 let maxw = getmaxw
() in
4014 then setzoom (maxw /. float conf.winw
)
4017 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
4021 bound (conf.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
4023 G.postRedisplay "brightness";
4026 begin match state.mode with
4027 | Birdseye beye
-> upbirdseye beye
4028 | _ -> gotoy (clamp (-conf.scrollstep
))
4032 begin match state.mode with
4033 | Birdseye beye
-> downbirdseye beye
4034 | _ -> gotoy (clamp conf.scrollstep
)
4038 state.anchor <- getanchor ();
4039 opendoc state.path
state.password
4041 | '
v'
when conf.debug
->
4044 match getopaque l.pageno with
4047 let x0, y0
, x1
, y1
= pagebbox opaque
in
4048 let a,b = float x0, float y0
in
4049 let c,d = float x1
, float y0
in
4050 let e,f = float x1
, float y1
in
4051 let h,j
= float x0, float y1
in
4052 let rect = (a,b,c,d,e,f,h,j
) in
4054 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4056 G.postRedisplay "v";
4059 vlog "huh? %d %c" key (Char.chr
key);
4062 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
4064 | 27 -> (* escape *)
4065 leavebirdseye beye
true
4067 | 12 -> (* ctrl-l *)
4068 let y, h = getpageyh pageno in
4069 let top = (conf.winh
- h) / 2 in
4070 gotoy (max
0 (y - top))
4073 leavebirdseye beye
false
4079 let keyboard ~
key ~
x ~
y =
4082 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
4083 then wcmd "interrupt" []
4084 else state.uioh <- state.uioh#
key key
4087 let birdseyespecial key ((conf, leftx
, _, hooverpageno
, anchor) as beye
) =
4089 | Glut.KEY_UP
-> upbirdseye beye
4090 | Glut.KEY_DOWN
-> downbirdseye beye
4092 | Glut.KEY_PAGE_UP
->
4093 begin match state.layout with
4097 state.mode <- Birdseye
(
4098 conf, leftx
, l.pageno, hooverpageno
, anchor
4100 gotopage1 l.pageno 0;
4103 let layout = layout (state.y-conf.winh
) conf.winh
in
4105 | [] -> gotoy (clamp (-conf.winh
))
4107 state.mode <- Birdseye
(
4108 conf, leftx
, l.pageno, hooverpageno
, anchor
4110 gotopage1 l.pageno 0
4113 | [] -> gotoy (clamp (-conf.winh
))
4116 | Glut.KEY_PAGE_DOWN
->
4117 begin match List.rev
state.layout with
4119 let layout = layout (state.y + conf.winh
) conf.winh
in
4120 begin match layout with
4122 let incr = l.pageh
- l.pagevh in
4127 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4129 G.postRedisplay "birdseye pagedown";
4131 else gotoy (clamp (incr + conf.interpagespace*2));
4135 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
4136 gotopage1 l.pageno 0;
4139 | [] -> gotoy (clamp conf.winh
)
4143 state.mode <- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
4147 let pageno = state.pagecount
- 1 in
4148 state.mode <- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
4149 if not
(pagevisible state.layout pageno)
4152 match List.rev
state.pdims
with
4154 | (_, _, h, _) :: _ -> h
4156 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4157 else G.postRedisplay "birdseye end";
4161 let setautoscrollspeed step goingdown
=
4162 let incr = max
1 ((abs step
) / 2) in
4163 let incr = if goingdown
then incr else -incr in
4164 let astep = step
+ incr in
4165 state.autoscroll
<- Some
astep;
4168 let special ~
key ~
x ~
y =
4171 state.uioh <- state.uioh#
special key
4176 match state.mode with
4177 | Textentry
_ -> scalecolor 0.4
4178 | View
-> scalecolor 1.0
4179 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4180 if l.pageno = hooverpageno
4183 if l.pageno = pageno
4189 begin match getopaque l.pageno with
4191 if tileready l l.pagex l.pagey
4193 let x = l.pagedispx
- l.pagex
4194 and y = l.pagedispy
- l.pagey in
4195 postprocess opaque
conf.hlinks
x y;
4201 let scrollindicator () =
4202 let sbw, ph
, sh = state.uioh#
scrollph in
4203 let sbh, pw
, sw = state.uioh#scrollpw
in
4205 GlDraw.color (0.64, 0.64, 0.64);
4207 (float (conf.winw
- sbw), 0.)
4208 (float conf.winw
, float conf.winh
)
4211 (0., float (conf.winh
- sbh))
4212 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4214 GlDraw.color (0.0, 0.0, 0.0);
4217 (float (conf.winw
- sbw), ph
)
4218 (float conf.winw
, ph
+. sh)
4221 (pw
, float (conf.winh
- sbh))
4222 (pw
+. sw, float conf.winh
)
4226 let pagetranslatepoint l x y =
4227 let dy = y - l.pagedispy
in
4228 let y = dy + l.pagey in
4229 let dx = x - l.pagedispx
in
4230 let x = dx + l.pagex in
4235 match state.mstate
with
4236 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4239 | Msel
((x0, y0
), (x1
, y1
)) ->
4240 let rec loop = function
4242 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
4243 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
4245 match getopaque l.pageno with
4247 let dx, dy = pagetranslatepoint l 0 0 in
4252 GlMat.mode `modelview
;
4254 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4255 seltext opaque
(x0, y0
, x1
, y1
);
4266 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4267 GlDraw.polygon_mode `both `fill
;
4268 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4270 (fun (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
4272 if l.pageno = pageno
4274 let dx = float (l.pagedispx
- l.pagex) in
4275 let dy = float (l.pagedispy
- l.pagey) in
4276 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4277 GlDraw.begins `quads
;
4279 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4280 GlDraw.vertex2
(x1
+.dx, y1
+.dy);
4281 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4282 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4293 GlClear.color (scalecolor2 conf.bgcolor
);
4294 GlClear.clear
[`
color];
4295 List.iter
drawpage state.layout;
4300 begin match state.mstate
with
4301 | Mzoomrect
((x0, y0
), (x1
, y1
)) ->
4303 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4304 GlDraw.polygon_mode `both `fill
;
4305 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4306 GlDraw.rect (float x0, float y0
)
4307 (float x1
, float y1
);
4312 Glut.swapBuffers
();
4316 let rec f = function
4318 begin match getopaque l.pageno with
4320 let x0 = l.pagedispx
in
4321 let x1 = x0 + l.pagevw in
4322 let y0 = l.pagedispy
in
4323 let y1 = y0 + l.pagevh in
4324 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4326 let px, py = pagetranslatepoint l x y in
4327 match whatsunder opaque
px py with
4339 let zoomrect x y x1 y1 =
4342 and y0 = min
y y1 in
4343 gotoy (state.y + y0);
4344 state.anchor <- getanchor ();
4345 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4347 if state.w < conf.winw
- state.scrollw
4348 then (conf.winw
- state.scrollw
- state.w) / 2
4351 state.x <- (state.x + margin) - x0;
4353 Glut.setCursor
Glut.CURSOR_INHERIT
;
4354 state.mstate
<- Mnone
;
4358 let winw = conf.winw - state.scrollw
- 1 in
4359 let s = float x /. float winw in
4360 let destx = truncate
(float (state.w + winw) *. s) in
4361 state.x <- winw - destx;
4362 gotoy_and_clear_text state.y;
4363 state.mstate
<- Mscrollx
;
4367 let s = float y /. float conf.winh
in
4368 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4369 gotoy_and_clear_text desty;
4370 state.mstate
<- Mscrolly
;
4373 let viewmouse button bstate
x y =
4375 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4376 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4378 match state.mstate
with
4379 | Mzoom
(oldn
, i
) ->
4387 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4389 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4391 let zoom = conf.zoom -. incr in
4393 state.mstate
<- Mzoom
(n, 0);
4395 state.mstate
<- Mzoom
(n, i
+1);
4397 else state.mstate
<- Mzoom
(n, 0)
4399 | _ -> state.mstate
<- Mzoom
(n, 0)
4402 match state.autoscroll
with
4403 | Some step
-> setautoscrollspeed step
(n=4)
4407 then -conf.scrollstep
4408 else conf.scrollstep
4410 let incr = incr * 2 in
4411 let y = clamp incr in
4412 gotoy_and_clear_text y
4415 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4416 if bstate
= Glut.DOWN
4418 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4419 state.mstate
<- Mpan
(x, y)
4422 state.mstate
<- Mnone
4424 | Glut.RIGHT_BUTTON
->
4425 if bstate
= Glut.DOWN
4427 Glut.setCursor
Glut.CURSOR_CYCLE
;
4429 state.mstate
<- Mzoomrect
(p, p)
4432 match state.mstate
with
4433 | Mzoomrect
((x0, y0), _) ->
4434 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4435 then zoomrect x0 y0 x y
4437 state.mstate
<- Mnone
;
4438 Glut.setCursor
Glut.CURSOR_INHERIT
;
4439 G.postRedisplay "kill accidental zoom rect";
4442 Glut.setCursor
Glut.CURSOR_INHERIT
;
4443 state.mstate
<- Mnone
4446 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4447 if bstate
= Glut.DOWN
4449 let _, position, sh = state.uioh#
scrollph in
4450 if y > truncate
position && y < truncate
(position +. sh)
4451 then state.mstate
<- Mscrolly
4454 state.mstate
<- Mnone
4456 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4457 if bstate
= Glut.DOWN
4459 let _, position, sw = state.uioh#scrollpw
in
4460 if x > truncate
position && x < truncate
(position +. sw)
4461 then state.mstate
<- Mscrollx
4464 state.mstate
<- Mnone
4466 | Glut.LEFT_BUTTON
->
4467 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4468 begin match dest with
4469 | Ulinkgoto
(pageno, top) ->
4473 gotopage1 pageno top;
4479 | Unone
when bstate
= Glut.DOWN
->
4480 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4481 state.mstate
<- Mpan
(x, y);
4483 | Unone
| Utext
_ ->
4484 if bstate
= Glut.DOWN
4486 if conf.angle
mod 360 = 0
4488 state.mstate
<- Msel
((x, y), (x, y));
4489 G.postRedisplay "mouse select";
4493 match state.mstate
with
4496 | Mzoom
_ | Mscrollx
| Mscrolly
->
4497 state.mstate
<- Mnone
4499 | Mzoomrect
((x0, y0), _) ->
4503 Glut.setCursor
Glut.CURSOR_INHERIT
;
4504 state.mstate
<- Mnone
4506 | Msel
((_, y0), (_, y1)) ->
4508 if (y0 >= l.pagedispy
&& y0 <= (l.pagedispy
+ l.pagevh))
4509 || ((y1 >= l.pagedispy
&& y1 <= (l.pagedispy
+ l.pagevh)))
4511 match getopaque l.pageno with
4516 List.iter
f state.layout;
4517 copysel
""; (* ugly *)
4518 Glut.setCursor
Glut.CURSOR_INHERIT
;
4519 state.mstate
<- Mnone
;
4526 let birdseyemouse button bstate
x y
4527 (conf, leftx
, _, hooverpageno
, anchor) =
4529 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4530 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4531 let rec loop = function
4534 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4535 && x > margin && x < margin + l.pagew
4537 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4542 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4546 let mouse bstate button
x y =
4547 state.uioh <- state.uioh#button button bstate
x y;
4550 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4553 state.uioh <- state.uioh#
motion x y
4557 state.uioh <- state.uioh#
pmotion x y;
4564 begin match state.mode with
4565 | Textentry
textentry -> textentrykeyboard key textentry
4566 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4567 | View
-> viewkeyboard key
4571 method special key =
4572 begin match state.mode with
4573 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4577 birdseyespecial key vals
4579 | View
when key = Glut.KEY_F1
->
4583 begin match state.autoscroll
with
4584 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4585 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4590 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4592 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4594 if Glut.getModifiers
() land Glut.active_shift
!= 0
4595 then (setzoom state.prevzoom
; state.y)
4596 else clamp (-conf.winh
/2)
4597 else clamp (-conf.scrollstep
)
4599 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4601 if Glut.getModifiers
() land Glut.active_shift
!= 0
4602 then (setzoom state.prevzoom
; state.y)
4603 else clamp (conf.winh
/2)
4604 else clamp (conf.scrollstep
)
4605 | Glut.KEY_PAGE_UP
->
4606 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4608 match state.layout with
4610 | l :: _ -> state.y - l.pagey
4613 | Glut.KEY_PAGE_DOWN
->
4614 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4616 match List.rev
state.layout with
4618 | l :: _ -> getpagey l.pageno
4626 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
4628 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
4629 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
4630 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
4632 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
4634 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4635 then (conf.winw / 2)
4638 state.x <- state.x - dx;
4640 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
4642 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4643 then (conf.winw / 2)
4646 state.x <- state.x + dx;
4651 gotoy_and_clear_text y
4654 | Textentry
te -> textentryspecial key te
4658 method button button bstate
x y =
4659 begin match state.mode with
4660 | View
-> viewmouse button bstate
x y
4661 | Birdseye beye
-> birdseyemouse button bstate
x y beye
4667 begin match state.mode with
4669 | View
| Birdseye
_ ->
4670 match state.mstate
with
4671 | Mzoom
_ | Mnone
-> ()
4676 state.mstate
<- Mpan
(x, y);
4677 if conf.zoom > 1.0 then state.x <- state.x + dx;
4679 gotoy_and_clear_text y
4682 state.mstate
<- Msel
(a, (x, y));
4683 G.postRedisplay "motion select";
4686 let y = min
conf.winh
(max
0 y) in
4690 let x = min
conf.winw (max
0 x) in
4693 | Mzoomrect
(p0
, _) ->
4694 state.mstate
<- Mzoomrect
(p0
, (x, y));
4695 G.postRedisplay "motion zoomrect";
4699 method pmotion x y =
4700 begin match state.mode with
4701 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
4702 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4703 let rec loop = function
4705 if hooverpageno
!= -1
4707 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
4708 G.postRedisplay "pmotion birdseye no hoover";
4711 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4712 && x > margin && x < margin + l.pagew
4714 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
4715 G.postRedisplay "pmotion birdseye hoover";
4724 match state.mstate
with
4726 begin match getunder x y with
4727 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
4729 if conf.underinfo
then showtext 'u'
("ri: " ^
uri);
4730 Glut.setCursor
Glut.CURSOR_INFO
4731 | Ulinkgoto
(page
, _) ->
4733 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
4734 Glut.setCursor
Glut.CURSOR_INFO
4736 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
4737 Glut.setCursor
Glut.CURSOR_TEXT
4740 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
4745 method infochanged
_ = ()
4748 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
4749 let p, h = scrollph state.y maxy in
4753 let winw = conf.winw - state.scrollw
- 1 in
4754 let fwinw = float winw in
4756 let sw = fwinw /. float state.w in
4757 let sw = fwinw *. sw in
4758 max
sw (float conf.scrollh
)
4761 let f = state.w+winw in
4762 let r = float (winw-state.x) /. float f in
4763 let p = fwinw *. r in
4767 if position +. sw > fwinw
4768 then fwinw -. position
4771 state.hscrollh, position, sw
4778 let fontpath = ref "";;
4779 let wmclasshack = ref false;;
4782 let l = String.length
s in
4783 let b = Buffer.create
l in
4791 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
4792 | _ -> Sys.getenv
"HOME"
4795 ("Can not determine home directory location: " ^
4796 Printexc.to_string exn
);
4800 let config_of c attrs
=
4804 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
4805 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
4806 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
4807 | "preload" -> { c with preload = bool_of_string
v }
4808 | "page-bias" -> { c with pagebias
= int_of_string
v }
4809 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
4810 | "auto-scroll-step" ->
4811 { c with autoscrollstep
= max
0 (int_of_string
v) }
4812 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
4813 | "crop-hack" -> { c with crophack
= bool_of_string
v }
4816 match String.lowercase
v with
4817 | "true" -> Some infinity
4819 | f -> Some
(float_of_string
f)
4821 { c with maxwait
= mw}
4822 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
4823 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
4824 | "vertical-margin" ->
4825 { c with interpagespace = max
0 (int_of_string
v) }
4827 let zoom = float_of_string
v /. 100. in
4828 let zoom = max
zoom 0.0 in
4829 { c with zoom = zoom }
4830 | "presentation" -> { c with presentation = bool_of_string
v }
4831 | "rotation-angle" -> { c with angle
= int_of_string
v }
4832 | "width" -> { c with winw = max
20 (int_of_string
v) }
4833 | "height" -> { c with winh
= max
20 (int_of_string
v) }
4834 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
4835 | "proportional-display" -> { c with proportional
= bool_of_string
v }
4836 | "pixmap-cache-size" ->
4837 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
4838 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
4839 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
4840 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
4841 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
4842 | "background-color" -> { c with bgcolor
= color_of_string v }
4843 | "scrollbar-in-presentation" ->
4844 { c with scrollbarinpm
= bool_of_string
v }
4845 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
4846 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
4847 | "mupdf-memlimit" ->
4848 { c with mumemlimit
= max
1024 (int_of_string_with_suffix v) }
4849 | "checkers" -> { c with checkers
= bool_of_string
v }
4850 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
4851 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
4852 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
4853 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
4854 | "uri-launcher" -> { c with urilauncher
= unent v }
4855 | "color-space" -> { c with colorspace
= colorspace_of_string v }
4856 | "invert-colors" -> { c with invert
= bool_of_string
v }
4857 | "brightness" -> { c with colorscale
= float_of_string
v }
4858 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
4861 prerr_endline
("Error processing attribute (`" ^
4862 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
4865 let rec fold c = function
4868 let c = apply c k
v in
4874 let fromstring f pos
n v d =
4877 dolog "Error processing attribute (%S=%S) at %d\n%s"
4878 n v pos
(Printexc.to_string exn
)
4883 let bookmark_of attrs
=
4884 let rec fold title page
rely = function
4885 | ("title", v) :: rest
-> fold v page
rely rest
4886 | ("page", v) :: rest
-> fold title v rely rest
4887 | ("rely", v) :: rest
-> fold title page
v rest
4888 | _ :: rest
-> fold title page
rely rest
4889 | [] -> title, page
, rely
4891 fold "invalid" "0" "0" attrs
4895 let rec fold path page
rely pan
= function
4896 | ("path", v) :: rest
-> fold v page
rely pan rest
4897 | ("page", v) :: rest
-> fold path
v rely pan rest
4898 | ("rely", v) :: rest
-> fold path page
v pan rest
4899 | ("pan", v) :: rest
-> fold path page
rely v rest
4900 | _ :: rest
-> fold path page
rely pan rest
4901 | [] -> path
, page
, rely, pan
4903 fold "" "0" "0" "0" attrs
4906 let setconf dst
src =
4907 dst
.scrollbw
<- src.scrollbw
;
4908 dst
.scrollh
<- src.scrollh
;
4909 dst
.icase
<- src.icase
;
4910 dst
.preload <- src.preload;
4911 dst
.pagebias
<- src.pagebias
;
4912 dst
.verbose
<- src.verbose
;
4913 dst
.scrollstep
<- src.scrollstep
;
4914 dst
.maxhfit
<- src.maxhfit
;
4915 dst
.crophack
<- src.crophack
;
4916 dst
.autoscrollstep
<- src.autoscrollstep
;
4917 dst
.maxwait
<- src.maxwait
;
4918 dst
.hlinks
<- src.hlinks
;
4919 dst
.underinfo
<- src.underinfo
;
4920 dst
.interpagespace <- src.interpagespace;
4921 dst
.zoom <- src.zoom;
4922 dst
.presentation <- src.presentation;
4923 dst
.angle
<- src.angle
;
4924 dst
.winw <- src.winw;
4925 dst
.winh
<- src.winh
;
4926 dst
.savebmarks
<- src.savebmarks
;
4927 dst
.memlimit
<- src.memlimit
;
4928 dst
.proportional
<- src.proportional
;
4929 dst
.texcount
<- src.texcount
;
4930 dst
.sliceheight
<- src.sliceheight
;
4931 dst
.thumbw
<- src.thumbw
;
4932 dst
.jumpback
<- src.jumpback
;
4933 dst
.bgcolor
<- src.bgcolor
;
4934 dst
.scrollbarinpm
<- src.scrollbarinpm
;
4935 dst
.tilew
<- src.tilew
;
4936 dst
.tileh
<- src.tileh
;
4937 dst
.mumemlimit
<- src.mumemlimit
;
4938 dst
.checkers
<- src.checkers
;
4939 dst
.aalevel
<- src.aalevel
;
4940 dst
.trimmargins
<- src.trimmargins
;
4941 dst
.trimfuzz
<- src.trimfuzz
;
4942 dst
.urilauncher
<- src.urilauncher
;
4943 dst
.colorspace
<- src.colorspace
;
4944 dst
.invert
<- src.invert
;
4945 dst
.colorscale
<- src.colorscale
;
4946 dst
.redirectstderr <- src.redirectstderr;
4950 let h = Hashtbl.create
10 in
4951 let dc = { defconf with angle
= defconf.angle
} in
4952 let rec toplevel v t spos
_ =
4954 | Vdata
| Vcdata
| Vend
-> v
4955 | Vopen
("llppconfig", _, closed
) ->
4958 else { v with f = llppconfig
}
4960 error
"unexpected subelement at top level" s spos
4961 | Vclose
_ -> error
"unexpected close at top level" s spos
4963 and llppconfig
v t spos
_ =
4965 | Vdata
| Vcdata
-> v
4966 | Vend
-> error
"unexpected end of input in llppconfig" s spos
4967 | Vopen
("defaults", attrs
, closed
) ->
4968 let c = config_of dc attrs
in
4972 else { v with f = skip
"defaults" (fun () -> v) }
4974 | Vopen
("ui-font", attrs
, closed
) ->
4975 let rec getsize size
= function
4977 | ("size", v) :: rest
->
4979 fromstring int_of_string spos
"size" v fstate.fontsize
in
4981 | l -> getsize size l
4983 fstate.fontsize
<- getsize fstate.fontsize attrs
;
4986 else { v with f = uifont
(Buffer.create
10) }
4988 | Vopen
("doc", attrs
, closed
) ->
4989 let pathent, spage
, srely
, span
= doc_of attrs
in
4990 let path = unent pathent
4991 and pageno = fromstring int_of_string spos
"page" spage
0
4992 and rely = fromstring float_of_string spos
"rely" srely
0.0
4993 and pan
= fromstring int_of_string spos
"pan" span
0 in
4994 let c = config_of dc attrs
in
4995 let anchor = (pageno, rely) in
4997 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
4998 else { v with f = doc
path pan
anchor c [] }
5001 error
"unexpected subelement in llppconfig" s spos
5003 | Vclose
"llppconfig" -> { v with f = toplevel }
5004 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5006 and uifont
b v t spos epos
=
5009 Buffer.add_substring
b s spos
(epos
- spos
);
5011 | Vopen
(_, _, _) ->
5012 error
"unexpected subelement in ui-font" s spos
5013 | Vclose
"ui-font" ->
5014 if String.length
!fontpath = 0
5015 then fontpath := Buffer.contents
b;
5016 { v with f = llppconfig
}
5017 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5018 | Vend
-> error
"unexpected end of input in ui-font" s spos
5020 and doc
path pan
anchor c bookmarks
v t spos
_ =
5022 | Vdata
| Vcdata
-> v
5023 | Vend
-> error
"unexpected end of input in doc" s spos
5024 | Vopen
("bookmarks", _, closed
) ->
5027 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5029 | Vopen
(_, _, _) ->
5030 error
"unexpected subelement in doc" s spos
5033 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5034 { v with f = llppconfig
}
5036 | Vclose
_ -> error
"unexpected close in doc" s spos
5038 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5040 | Vdata
| Vcdata
-> v
5041 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5042 | Vopen
("item", attrs
, closed
) ->
5043 let titleent, spage
, srely
= bookmark_of attrs
in
5044 let page = fromstring int_of_string spos
"page" spage
0
5045 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5046 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5048 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5051 { v with f = skip
"item" f }
5054 error
"unexpected subelement in bookmarks" s spos
5056 | Vclose
"bookmarks" ->
5057 { v with f = doc
path pan
anchor c bookmarks }
5059 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5061 and skip tag
f v t spos
_ =
5063 | Vdata
| Vcdata
-> v
5065 error
("unexpected end of input in skipped " ^ tag
) s spos
5066 | Vopen
(tag'
, _, closed
) ->
5070 let f'
() = { v with f = skip tag
f } in
5071 { v with f = skip tag'
f'
}
5075 else error
("unexpected close in skipped " ^ tag
) s spos
5078 parse
{ f = toplevel; accu = () } s;
5084 let len = in_channel_length ic
in
5085 let s = String.create
len in
5086 really_input ic
s 0 len;
5089 | Parse_error
(msg
, s, pos
) ->
5090 let subs = subs s pos
in
5091 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5092 failwith
("parse error: " ^
s)
5095 failwith
("config load error: " ^
Printexc.to_string exn
)
5101 let dir = Filename.concat
home ".config" in
5102 if Sys.is_directory
dir then dir else home
5105 Filename.concat
dir "llpp.conf"
5108 let confpath = ref defconfpath;;
5111 if Sys.file_exists
!confpath
5114 (try Some
(open_in_bin
!confpath)
5117 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5118 Printexc.to_string exn
);
5127 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5128 Printexc.to_string exn
);
5134 f (Hashtbl.create
0, defconf)
5139 let pc, pb
, px, pa
=
5141 Hashtbl.find h (Filename.basename
state.path)
5142 with Not_found
-> dc, [], 0, (0, 0.0)
5146 state.bookmarks <- pb
;
5148 state.scrollw
<- conf.scrollbw
;
5150 then state.anchor <- pa
;
5151 cbput state.hists
.nav pa
;
5156 let add_attrs bb always
dc c =
5159 then Printf.bprintf bb
"\n %s='%b'" s a
5162 then Printf.bprintf bb
"\n %s='%d'" s a
5165 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5168 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5171 then Printf.bprintf bb
"\n %s='%f'" s a
5175 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5179 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5183 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5187 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5197 else string_of_float
f
5199 Printf.bprintf bb
"\n %s='%s'" s v
5203 then dc.winw, dc.winh
5205 match state.fullscreen
with
5207 | None
-> c.winw, c.winh
5209 let zoom, presentation, interpagespace, maxwait
=
5211 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5213 match state.mode with
5214 | Birdseye
(bc
, _, _, _, _) ->
5215 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5216 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5218 oi
"width" w dc.winw;
5219 oi
"height" h dc.winh
;
5220 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5221 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5222 ob "case-insensitive-search" c.icase
dc.icase
;
5223 ob "preload" c.preload dc.preload;
5224 oi
"page-bias" c.pagebias
dc.pagebias
;
5225 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5226 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5227 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5228 ob "crop-hack" c.crophack
dc.crophack
;
5229 oW
"throttle" maxwait
dc.maxwait
;
5230 ob "highlight-links" c.hlinks
dc.hlinks
;
5231 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5232 oi
"vertical-margin" interpagespace dc.interpagespace;
5233 oz
"zoom" zoom dc.zoom;
5234 ob "presentation" presentation dc.presentation;
5235 oi
"rotation-angle" c.angle
dc.angle
;
5236 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5237 ob "proportional-display" c.proportional
dc.proportional
;
5238 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5239 oi
"tex-count" c.texcount
dc.texcount
;
5240 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5241 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5242 ob "persistent-location" c.jumpback
dc.jumpback
;
5243 oc
"background-color" c.bgcolor
dc.bgcolor
;
5244 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5245 oi
"tile-width" c.tilew
dc.tilew
;
5246 oi
"tile-height" c.tileh
dc.tileh
;
5247 oI
"mupdf-memlimit" c.mumemlimit
dc.mumemlimit
;
5248 ob "checkers" c.checkers
dc.checkers
;
5249 oi
"aalevel" c.aalevel
dc.aalevel
;
5250 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5251 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5252 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5253 oC
"color-space" c.colorspace
dc.colorspace
;
5254 ob "invert-colors" c.invert
dc.invert
;
5255 oF
"brightness" c.colorscale
dc.colorscale
;
5256 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5258 then ob "wmclass-hack" !wmclasshack false;
5262 let uifontsize = fstate.fontsize
in
5263 let bb = Buffer.create
32768 in
5265 let dc = if conf.bedefault
then conf else dc in
5266 Buffer.add_string
bb "<llppconfig>\n";
5268 if String.length
!fontpath > 0
5270 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5276 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5279 Buffer.add_string
bb "<defaults ";
5280 add_attrs bb true dc dc;
5281 Buffer.add_string
bb "/>\n";
5283 let adddoc path pan
anchor c bookmarks =
5284 if bookmarks == [] && c = dc && anchor = emptyanchor
5287 Printf.bprintf
bb "<doc path='%s'"
5288 (enent
path 0 (String.length
path));
5290 if anchor <> emptyanchor
5292 let n, y = anchor in
5293 Printf.bprintf
bb " page='%d'" n;
5296 Printf.bprintf
bb " rely='%f'" y
5301 then Printf.bprintf
bb " pan='%d'" pan
;
5303 add_attrs bb false dc c;
5305 begin match bookmarks with
5306 | [] -> Buffer.add_string
bb "/>\n"
5308 Buffer.add_string
bb ">\n<bookmarks>\n";
5309 List.iter
(fun (title, _level
, (page, rely)) ->
5311 "<item title='%s' page='%d'"
5312 (enent
title 0 (String.length
title))
5317 Printf.bprintf
bb " rely='%f'" rely
5319 Buffer.add_string
bb "/>\n";
5321 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5327 match state.mode with
5328 | Birdseye
(_, pan, _, _, _) -> pan
5331 let basename = Filename.basename state.path in
5332 adddoc basename pan (getanchor ())
5335 match state.autoscroll
with
5337 | None
-> conf.autoscrollstep
}
5338 (if conf.savebmarks
then state.bookmarks else []);
5340 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5342 then adddoc path x y c bookmarks
5344 Buffer.add_string
bb "</llppconfig>";
5347 if Buffer.length
bb > 0
5350 let tmp = !confpath ^
".tmp" in
5351 let oc = open_out_bin
tmp in
5352 Buffer.output_buffer
oc bb;
5354 Unix.rename
tmp !confpath;
5357 ("error while saving configuration: " ^
Printexc.to_string exn
)
5364 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5365 "<password> Set password");
5367 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5368 "<path> Set path to the user interface font");
5370 ("-c", Arg.String
(fun s -> Config.confpath := s),
5371 "<path> Set path to the configuration file");
5373 ("-v", Arg.Unit
(fun () ->
5375 "%s\nconfiguration path: %s\n"
5379 exit
0), " Print version and exit");
5382 (fun s -> state.path <- s)
5383 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5385 if String.length
state.path = 0
5386 then (prerr_endline
"file name missing"; exit
1);
5390 let _ = Glut.init
Sys.argv
in
5391 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5392 let () = Glut.initWindowSize
conf.winw conf.winh
in
5393 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5395 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5396 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5397 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5402 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5404 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5405 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5406 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5407 Unix.bind
sock addr;
5409 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5410 Unix.connect
csock addr;
5411 let ssock, _ = Unix.accept
sock in
5414 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5415 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5422 let () = Glut.displayFunc
display in
5423 let () = Glut.reshapeFunc
reshape in
5424 let () = Glut.keyboardFunc
keyboard in
5425 let () = Glut.specialFunc
special in
5426 let () = Glut.idleFunc
(Some
idle) in
5427 let () = Glut.mouseFunc
mouse in
5428 let () = Glut.motionFunc
motion in
5429 let () = Glut.passiveMotionFunc
pmotion in
5431 setcheckers conf.checkers
;
5433 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5434 conf.texcount
, conf.sliceheight
, conf.mumemlimit
, conf.colorspace
,
5435 !Config.wmclasshack, !Config.fontpath
5437 state.csock <- csock;
5438 state.ssock <- ssock;
5439 state.text <- "Opening " ^
state.path;
5440 setaalevel
conf.aalevel
;
5441 writeopen state.path state.password
;
5443 setfontsize fstate.fontsize
;
5451 | Glut.BadEnum
"key in special_of_int" ->
5452 showtext '
!'
" LablGlut bug: special key not recognized";
5459 | exn
when conf.redirectstderr ->
5461 Printf.sprintf
"exception %s\n%s"
5462 (Printexc.to_string exn
)
5463 (Printexc.get_backtrace
())
5466 Unix.single_write
state.stderr
s 0 (String.length
s);