6 | Ulinkgoto
of (int * int)
8 | Uunexpected
of string
11 | Uremote
of (string * int)
12 and facename
= string;;
14 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
15 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* fontpath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
38 and irect
= (int * int * int * int)
39 and trimparams
= (trimmargins
* irect
)
40 and colorspace
= | Rgb
| Bgr
| Gray
49 | LDfirstvisible
of (int * int * int)
64 | KMmulti
of key list
* key list
66 and keyhash
= (key
, keymap
) Hashtbl.t
69 | KSinto
of (key list
* key list
)
72 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
73 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
75 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
77 external init
: pipe
-> params
-> unit = "ml_init";;
78 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
79 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
80 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
81 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
82 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
83 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
84 external measurestr
: int -> string -> float = "ml_measure_string";;
85 external getmaxw
: unit -> float = "ml_getmaxw";;
86 external postprocess
:
87 opaque
-> int -> int -> int -> (int * string * int) -> int = "ml_postprocess";;
88 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
89 external platform
: unit -> platform
= "ml_platform";;
90 external setaalevel
: int -> unit = "ml_setaalevel";;
91 external realloctexts
: int -> bool = "ml_realloctexts";;
92 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
93 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
94 external getlink
: opaque
-> int -> under
= "ml_getlink";;
95 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
96 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
97 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
98 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
100 let platform_to_string = function
101 | Punknown
-> "unknown"
105 | Pfreebsd
-> "FreeBSD"
106 | Pdragonflybsd
-> "DragonflyBSD"
107 | Popenbsd
-> "OpenBSD"
108 | Pnetbsd
-> "NetBSD"
109 | Pcygwin
-> "Cygwin"
112 let platform = platform ();;
115 if platform = Pcygwin
117 let sh = "/bin/sh" in
118 let args = [|sh; "-c"; cmd
|] in
119 let rec std si so se
= function
121 | (fd
, 0) :: rest
-> std fd so se rest
122 | (fd
, -1) :: rest
->
123 Unix.set_close_on_exec fd
;
126 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
128 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
129 ignore
(Unix.create_process
sh args si so se
)
138 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
141 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
143 type mpos
= int * int
145 | Msel
of (mpos
* mpos
)
147 | Mscrolly
| Mscrollx
148 | Mzoom
of (int * int)
149 | Mzoomrect
of (mpos
* mpos
)
153 type textentry
= string * string * onhist
option * onkey
* ondone
154 and onkey
= string -> int -> te
155 and ondone
= string -> unit
156 and histcancel
= unit -> unit
157 and onhist
= ((histcmd
-> string) * histcancel
)
158 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
163 | TEswitch
of textentry
174 let bound v minv maxv
=
175 max minv
(min maxv v
);
179 { store
= Array.create n v
186 let drawstring size x y s
=
188 Gl.enable `texture_2d
;
189 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
190 ignore
(drawstr size x y s
);
192 Gl.disable `texture_2d
;
195 let drawstring1 size x y s
=
199 let drawstring2 size x y fmt
=
200 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
203 let cbcap b
= Array.length b
.store
;;
208 b
.wc
<- (b
.wc
+ 1) mod cap;
210 b
.len
<- min
(b
.len
+ 1) cap;
213 let cbempty b
= b
.len
= 0;;
215 let cbgetg b circular dir
=
219 let rc = b
.rc + dir
in
231 else max
0 (min
rc (b
.len
-1))
237 let cbget b
= cbgetg b
false;;
238 let cbgetc b
= cbgetg b
true;;
256 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
257 dolog " WxH %dx%d" l
.pagew l
.pageh
;
258 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
259 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
260 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
261 dolog " column %d" l
.pagecol
;
265 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
267 dolog " x0,y0=(% f, % f)" x0 y0
;
268 dolog " x1,y1=(% f, % f)" x1 y1
;
269 dolog " x2,y2=(% f, % f)" x2 y2
;
270 dolog " x3,y3=(% f, % f)" x3 y3
;
274 type multicolumns
= multicol
* pagegeom
275 and splitcolumns
= columncount
* pagegeom
276 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
277 and multicol
= columncount
* covercount
* covercount
279 and columncount
= int
280 and covercount
= int;;
283 { mutable scrollbw
: int
284 ; mutable scrollh
: int
285 ; mutable icase
: bool
286 ; mutable preload
: bool
287 ; mutable pagebias
: int
288 ; mutable verbose
: bool
289 ; mutable debug
: bool
290 ; mutable scrollstep
: int
291 ; mutable maxhfit
: bool
292 ; mutable crophack
: bool
293 ; mutable autoscrollstep
: int
294 ; mutable maxwait
: float option
295 ; mutable hlinks
: bool
296 ; mutable underinfo
: bool
297 ; mutable interpagespace
: interpagespace
298 ; mutable zoom
: float
299 ; mutable presentation
: bool
300 ; mutable angle
: angle
303 ; mutable savebmarks
: bool
304 ; mutable proportional
: proportional
305 ; mutable trimmargins
: trimmargins
306 ; mutable trimfuzz
: irect
307 ; mutable memlimit
: memsize
308 ; mutable texcount
: texcount
309 ; mutable sliceheight
: sliceheight
310 ; mutable thumbw
: width
311 ; mutable jumpback
: bool
312 ; mutable bgcolor
: float * float * float
313 ; mutable bedefault
: bool
314 ; mutable scrollbarinpm
: bool
315 ; mutable tilew
: int
316 ; mutable tileh
: int
317 ; mutable mustoresize
: memsize
318 ; mutable checkers
: bool
319 ; mutable aalevel
: int
320 ; mutable urilauncher
: string
321 ; mutable pathlauncher
: string
322 ; mutable colorspace
: colorspace
323 ; mutable invert
: bool
324 ; mutable colorscale
: float
325 ; mutable redirectstderr
: bool
326 ; mutable ghyllscroll
: (int * int * int) option
327 ; mutable columns
: columns
328 ; mutable beyecolumns
: columncount
option
329 ; mutable selcmd
: string
330 ; mutable updatecurs
: bool
331 ; mutable keyhashes
: (string * keyhash
) list
332 ; mutable hfsize
: int
336 | Cmulti
of multicolumns
337 | Csplit
of splitcolumns
340 type anchor
= pageno
* top
;;
342 type outline
= string * int * anchor
;;
344 type rect
= float * float * float * float * float * float * float * float;;
346 type tile
= opaque
* pixmapsize
* elapsed
347 and elapsed
= float;;
348 type pagemapkey
= pageno
* gen
;;
349 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
353 let emptyanchor = (0, 0.0);;
355 type infochange
= | Memused
| Docinfo
| Pdim
;;
357 class type uioh
= object
358 method display
: unit
359 method key
: int -> int -> uioh
360 method button
: int -> bool -> int -> int -> int -> uioh
361 method motion
: int -> int -> uioh
362 method pmotion
: int -> int -> uioh
363 method infochanged
: infochange
-> unit
364 method scrollpw
: (int * float * float)
365 method scrollph
: (int * float * float)
366 method modehash
: keyhash
370 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
371 | Textentry
of (textentry
* onleave
)
373 | LinkNav
of linktarget
374 and onleave
= leavetextentrystatus
-> unit
375 and leavetextentrystatus
= | Cancel
| Confirm
376 and helpitem
= string * int * action
379 | Action
of (uioh
-> uioh
)
381 | Ltexact
of (pageno
* int)
385 let isbirdseye = function Birdseye _
-> true | _
-> false;;
386 let istextentry = function Textentry _
-> true | _
-> false;;
390 | Loading
of (page
* gen
)
392 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
394 | Outlining
of outline list
397 let emptykeyhash = Hashtbl.create
0;;
398 let nouioh : uioh
= object (self
)
400 method key _ _
= self
401 method button _ _ _ _ _
= self
402 method motion _ _
= self
403 method pmotion _ _
= self
404 method infochanged _
= ()
405 method scrollpw
= (0, nan
, nan
)
406 method scrollph
= (0, nan
, nan
)
407 method modehash
= emptykeyhash
411 { mutable sr
: Unix.file_descr
412 ; mutable sw
: Unix.file_descr
413 ; mutable wsfd
: Unix.file_descr
414 ; mutable errfd
: Unix.file_descr
option
415 ; mutable stderr
: Unix.file_descr
416 ; mutable errmsgs
: Buffer.t
417 ; mutable newerrmsgs
: bool
421 ; mutable scrollw
: int
422 ; mutable hscrollh
: int
423 ; mutable anchor
: anchor
424 ; mutable ranchors
: (string * string * anchor
) list
426 ; mutable layout
: page list
427 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
428 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
429 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
430 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
431 ; mutable pagecount
: int
432 ; mutable currently
: currently
433 ; mutable mstate
: mstate
434 ; mutable searchpattern
: string
435 ; mutable rects
: (pageno
* recttype
* rect
) list
436 ; mutable rects1
: (pageno
* recttype
* rect
) list
437 ; mutable text
: string
438 ; mutable fullscreen
: (width
* height
) option
439 ; mutable mode
: mode
440 ; mutable uioh
: uioh
441 ; mutable outlines
: outline array
442 ; mutable bookmarks
: outline list
443 ; mutable path
: string
444 ; mutable password
: string
445 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
446 ; mutable memused
: memsize
448 ; mutable throttle
: (page list
* int * float) option
449 ; mutable autoscroll
: int option
450 ; mutable ghyll
: (int option -> unit)
451 ; mutable help
: helpitem array
452 ; mutable docinfo
: (int * string) list
453 ; mutable texid
: GlTex.texture_id
option
455 ; mutable prevzoom
: float
456 ; mutable progress
: float
457 ; mutable redisplay
: bool
458 ; mutable mpos
: mpos
459 ; mutable keystate
: keystate
460 ; mutable glinks
: bool
463 { pat
: string circbuf
464 ; pag
: string circbuf
465 ; nav
: anchor circbuf
466 ; sel
: string circbuf
487 ; presentation
= false
492 ; proportional
= true
493 ; trimmargins
= false
494 ; trimfuzz
= (0,0,0,0)
495 ; memlimit
= 32 lsl 20
500 ; bgcolor
= (0.5, 0.5, 0.5)
502 ; scrollbarinpm
= true
505 ; mustoresize
= 256 lsl 20
510 | Plinux
| Pfreebsd
| Pdragonflybsd
511 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
512 | Posx
-> "open \"%s\""
513 | Pcygwin
-> "cygstart \"%s\""
514 | Punknown
-> "echo %s")
515 ; pathlauncher
= "lp \"%s\""
518 | Plinux
| Pfreebsd
| Pdragonflybsd
519 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
526 ; redirectstderr
= false
533 let mk n
= (n
, Hashtbl.create
1) in
547 let findkeyhash c name
=
548 try List.assoc name c
.keyhashes
549 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
552 let conf = { defconf with angle
= defconf.angle
};;
555 { mutable fontsize
: int
556 ; mutable wwidth
: float
557 ; mutable maxrows
: int
569 fstate.fontsize
<- n
;
570 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
571 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
575 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
576 let len = String.length s
in
577 if colonpos >= 0 && colonpos + 3 < len
579 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
582 try String.rindex_from s
colonpos ' '
586 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
589 | "http" | "ftp" | "mailto" ->
591 try String.index_from s
colonpos ' '
592 with Not_found
-> len
594 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
602 if String.length
conf.urilauncher
= 0
603 then print_endline uri
605 let url = geturl uri
in
606 if String.length
url = 0
607 then print_endline uri
609 let re = Str.regexp
"%s" in
610 let command = Str.global_replace
re url conf.urilauncher
in
614 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
620 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
621 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
625 let strings = version () :: "" :: Help.keys
in
628 let url = geturl s
in
629 if String.length
url > 0
630 then (s
, 0, Action
(fun u
-> gotouri url; u
))
631 else (s
, 0, Noaction
)
636 let firstgeomcmds = "", [];;
643 ; stderr
= Unix.stderr
644 ; errmsgs
= Buffer.create
0
651 ; anchor
= emptyanchor
655 ; tilelru
= Queue.create
()
656 ; pagemap
= Hashtbl.create
10
657 ; tilemap
= Hashtbl.create
10
672 ; geomcmds
= firstgeomcmds
674 { nav
= cbnew 10 (0, 0.0)
700 Printf.kprintf prerr_endline fmt
702 Printf.kprintf ignore fmt
706 if String.length
conf.pathlauncher
= 0
707 then print_endline
state.path
709 let re = Str.regexp
"%s" in
710 let command = Str.global_replace
re state.path
conf.pathlauncher
in
714 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
720 type 'a t
= | Res
of 'a
| Exn
of exn
;;
723 try Res
(Unix.pipe ())
729 with exn
-> f
(Printexc.to_string exn
)
733 try Res
(Unix.dup fd
)
738 try Res
(Unix.dup2 fd1 fd2
)
743 let redirectstderr () =
744 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
745 if conf.redirectstderr
747 match Ne.pipe () with
749 dolog "failed to create stderr redirection pipes: %s"
750 (Printexc.to_string exn
)
753 begin match Ne.dup Unix.stderr
with
755 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
756 Ne.clo r
(clofail "pipe/r");
757 Ne.clo w
(clofail "pipe/w");
759 | Ne.Res dupstderr
->
760 begin match Ne.dup2 w
Unix.stderr
with
762 dolog "failed to dup2 to stderr: %s"
763 (Printexc.to_string exn
);
764 Ne.clo dupstderr
(clofail "stderr duplicate");
765 Ne.clo r
(clofail "redir pipe/r");
766 Ne.clo w
(clofail "redir pipe/w");
769 state.stderr
<- dupstderr
;
770 state.errfd
<- Some r
;
774 state.newerrmsgs
<- false;
775 begin match state.errfd
with
777 begin match Ne.dup2 state.stderr
Unix.stderr
with
779 dolog "failed to dup2 original stderr: %s"
780 (Printexc.to_string exn
)
782 Ne.clo fd
(clofail "dup of stderr");
783 Unix.dup2 state.stderr
Unix.stderr
;
788 prerr_string
(Buffer.contents
state.errmsgs
);
790 Buffer.clear
state.errmsgs
;
796 let postRedisplay who
=
798 then prerr_endline
("redisplay for " ^ who
);
799 state.redisplay
<- true;
803 let getopaque pageno
=
804 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
805 with Not_found
-> None
808 let putopaque pageno opaque
=
809 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
812 let pagetranslatepoint l x y
=
813 let dy = y
- l
.pagedispy
in
814 let y = dy + l
.pagey
in
815 let dx = x
- l
.pagedispx
in
816 let x = dx + l
.pagex
in
823 begin match getopaque l
.pageno
with
825 let x0 = l
.pagedispx
in
826 let x1 = x0 + l
.pagevw
in
827 let y0 = l
.pagedispy
in
828 let y1 = y0 + l
.pagevh
in
829 if y >= y0 && y <= y1 && x >= x0 && x <= x1
831 let px, py
= pagetranslatepoint l
x y in
832 match whatsunder opaque
px py
with
845 state.text
<- Printf.sprintf
"%c%s" c s
;
846 G.postRedisplay "showtext";
849 let undertext = function
852 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
853 | Utext s
-> "font: " ^ s
854 | Uunexpected s
-> "unexpected: " ^ s
855 | Ulaunch s
-> "launch: " ^ s
856 | Unamed s
-> "named: " ^ s
857 | Uremote
(filename
, pageno
) ->
858 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
861 let updateunder x y =
862 match getunder x y with
863 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
865 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
866 Wsi.setcursor
Wsi.CURSOR_INFO
867 | Ulinkgoto
(pageno
, _
) ->
869 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
870 Wsi.setcursor
Wsi.CURSOR_INFO
872 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
873 Wsi.setcursor
Wsi.CURSOR_TEXT
875 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
876 Wsi.setcursor
Wsi.CURSOR_INHERIT
878 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
879 Wsi.setcursor
Wsi.CURSOR_INHERIT
881 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
882 Wsi.setcursor
Wsi.CURSOR_INHERIT
883 | Uremote
(filename
, pageno
) ->
884 if conf.underinfo
then showtext 'r'
885 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
886 Wsi.setcursor
Wsi.CURSOR_INFO
889 let showlinktype under
=
895 let s = undertext under
in
900 let b = Buffer.create
(String.length
s + 1) in
901 Buffer.add_string
b s;
906 let colorspace_of_string s =
907 match String.lowercase
s with
911 | _
-> failwith
"invalid colorspace"
914 let int_of_colorspace = function
920 let colorspace_of_int = function
924 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
927 let colorspace_to_string = function
933 let intentry_with_suffix text key
=
935 if key
>= 32 && key
< 127
939 match Char.lowercase
c with
941 let text = addchar text c in
945 let text = addchar text c in
949 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
953 let multicolumns_to_string (n
, a
, b) =
955 then Printf.sprintf
"%d" n
956 else Printf.sprintf
"%d,%d,%d" n a
b;
959 let multicolumns_of_string s =
961 (int_of_string
s, 0, 0)
963 Scanf.sscanf
s "%u,%u,%u" (fun n a
b -> (n
, a
, b));
968 let n = Unix.read fd
s 0 4 in
969 if n != 4 then failwith
"incomplete read(len)";
971 lor (Char.code
s.[0] lsl 24)
972 lor (Char.code
s.[1] lsl 16)
973 lor (Char.code
s.[2] lsl 8)
974 lor (Char.code
s.[3] lsl 0)
976 let s = String.create
len in
977 let n = Unix.read fd
s 0 len in
978 if n != len then failwith
"incomplete read(data)";
982 let btod b = if b then 1 else 0;;
985 let b = Buffer.create
16 in
986 Buffer.add_string
b "llll";
989 let s = Buffer.contents
b in
990 let n = String.length
s in
992 (* dolog "wcmd %S" (String.sub s 4 len); *)
993 s.[0] <- Char.chr
((len lsr 24) land 0xff);
994 s.[1] <- Char.chr
((len lsr 16) land 0xff);
995 s.[2] <- Char.chr
((len lsr 8) land 0xff);
996 s.[3] <- Char.chr
(len land 0xff);
997 let n'
= Unix.write
state.sw
s 0 n in
998 if n'
!= n then failwith
"write failed";
1003 if conf.presentation
1005 let d = conf.winh
- h
in
1012 let rec f pn ph pi fh l
=
1014 | (n, _
, h
, _
) :: rest
->
1015 let ips = calcips h
in
1017 if conf.presentation
1020 if isbirdseye state.mode
&& pn
= 0
1025 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
1030 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
1034 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
1037 let fh = f 0 0 0 0 state.pdims
in
1042 match conf.columns
with
1043 | Csingle
-> calcheight ()
1044 | Cmulti
((c, _
, _
), b) ->
1045 let rec loop y h
n =
1049 if n = Array.length
b
1052 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
1058 loop max_int
0 (((Array.length
b - 1) / c) * c)
1060 if Array.length
b > 0
1062 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1067 let getpageyh pageno
=
1068 let rec f pn ph pi
y l
=
1070 | (n, _
, h
, _
) :: rest
->
1071 let ips = calcips h
in
1074 let h = if n = pageno
then h else ph
in
1075 if conf.presentation
&& n = pageno
1077 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
1079 y + (pageno
- pn
) * (ph
+ pi
), h
1081 let y = y + (if conf.presentation
then pi
else 0) in
1082 let y = y + (n - pn
) * (ph
+ pi
) in
1086 y + (pageno
- pn
) * (ph
+ pi
), ph
1088 f 0 0 0 0 state.pdims
1091 let getpageyh pageno
=
1092 match conf.columns
with
1093 | Csingle
-> getpageyh pageno
1095 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1099 let (_
, _
, y, (_
, _
, h, _
)) = b.(n) in
1103 let getpagedim pageno
=
1106 | (n, _
, _
, _
) as pdim
:: rest
->
1108 then (if n = pageno
then pdim
else ppdim
)
1113 f (-1, -1, -1, -1) state.pdims
1116 let getpagey pageno
= fst
(getpageyh pageno
);;
1118 let nogeomcmds cmds
=
1120 | s, [] -> String.length
s = 0
1125 let sh = sh - state.hscrollh
in
1126 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1127 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1129 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1130 let ips = calcips h in
1132 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1136 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1138 prev
, pdims
, pdimno
, 0
1140 let dy = dy + yinc in
1141 let py = py + yinc in
1142 if pageno
= state.pagecount
|| dy >= sh
1147 if py + h <= vy - yinc
1149 let py = py + h + ips in
1150 let dy = max
0 (py - y) in
1151 f ~pageno
:(pageno
+1)
1159 let pagey = vy - py in
1160 let pagevh = h - pagey in
1161 let pagevh = min
(sh - dy) pagevh in
1162 let off = if yinc > 0 then py - vy else 0 in
1163 let py = py + h + ips in
1166 if state.w
< conf.winw
- state.scrollw
1167 then (conf.winw
- state.scrollw
- state.w
) / 2
1170 let dispx = xoff + state.x in
1176 let lw = w
- pagex in
1177 min
lw (conf.winw
- state.scrollw
)
1181 ; pagedimno
= pdimno
1185 ; pagey = pagey + off
1187 ; pagevh = pagevh - off
1189 ; pagedispy
= dy + off
1193 let accu = e :: accu in
1194 f ~pageno
:(pageno
+1)
1215 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1216 let sh = sh - state.hscrollh
in
1217 let rec fold accu n =
1218 if n = Array.length
b
1221 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1224 || n = state.pagecount
- coverB
1225 || (n - coverA
) mod columns
= columns
- 1)
1231 let pagey = max
0 (y - vy) in
1232 let pagedispy = if pagey > 0 then 0 else vy - y in
1233 let pagedispx, pagex =
1235 if n = coverA
- 1 || n = state.pagecount
- coverB
1236 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1237 else dx + xoff + state.x
1244 let vw = conf.winw
- state.scrollw
- pagedispx in
1245 let pw = w
- pagex in
1248 let pagevh = min
(h - pagey) (sh - pagedispy) in
1249 if pagevw > 0 && pagevh > 0
1253 ; pagedimno
= pdimno
1260 ; pagedispx = pagedispx
1261 ; pagedispy = pagedispy
1273 List.rev
(fold [] 0)
1276 let layoutS (columns
, b) y sh =
1277 let sh = sh - state.hscrollh
in
1278 let rec fold accu n =
1279 if n = Array.length
b
1282 let pdimno, px, vy, (_
, pagew
, pageh
, xoff) = b.(n) in
1289 let x = xoff + state.x in
1290 let pagey = max
0 (y - vy) in
1291 let pagedispy = if pagey > 0 then 0 else vy - y in
1292 let pagedispx, pagex =
1306 let pagecolw = pagew
/columns
in
1308 if pagecolw < conf.winw
1309 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1313 let vw = conf.winw
- pagedispx - state.scrollw
in
1314 let pw = pagew
- pagex in
1317 let pagevw = min
pagevw pagecolw in
1318 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1319 if pagevw > 0 && pagevh > 0
1322 { pageno
= n/columns
1323 ; pagedimno
= pdimno
1330 ; pagedispx = pagedispx
1331 ; pagedispy = pagedispy
1332 ; pagecol
= n mod columns
1343 List.rev
(fold [] 0)
1347 if nogeomcmds state.geomcmds
1349 match conf.columns
with
1350 | Csingle
-> layout1 y sh
1351 | Cmulti
c -> layoutN c y sh
1352 | Csplit
s -> layoutS s y sh
1357 let y = state.y + incr
in
1359 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1364 let tilex = l
.pagex mod conf.tilew
in
1365 let tiley = l
.pagey mod conf.tileh
in
1367 let col = l
.pagex / conf.tilew
in
1368 let row = l
.pagey / conf.tileh
in
1370 let rec rowloop row y0 dispy
h =
1374 let dh = conf.tileh
- y0 in
1375 let dh = min
h dh in
1376 let rec colloop col x0 dispx w
=
1380 let dw = conf.tilew
- x0 in
1381 let dw = min w
dw in
1383 f col row dispx dispy
x0 y0 dw dh;
1384 colloop (col+1) 0 (dispx+dw) (w
-dw)
1387 colloop col tilex l
.pagedispx l
.pagevw;
1388 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1391 if l
.pagevw > 0 && l
.pagevh > 0
1392 then rowloop row tiley l
.pagedispy l
.pagevh;
1395 let gettileopaque l
col row =
1397 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1399 try Some
(Hashtbl.find
state.tilemap
key)
1400 with Not_found
-> None
1403 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1404 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1405 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1408 let drawtiles l color
=
1410 let f col row x y tilex tiley w
h =
1411 match gettileopaque l
col row with
1412 | Some
(opaque
, _
, t
) ->
1413 let params = x, y, w
, h, tilex, tiley in
1417 GlFunc.blend_func `zero `one_minus_src_color
;
1419 drawtile
params opaque
;
1421 then Gl.disable `blend
;
1424 let s = Printf.sprintf
1428 let w = measurestr
fstate.fontsize
s in
1429 GlMisc.push_attrib
[`current
];
1430 GlDraw.color
(0.0, 0.0, 0.0);
1432 (float (x-2), float (y-2))
1433 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1434 GlDraw.color
(1.0, 1.0, 1.0);
1435 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1436 GlMisc.pop_attrib
();
1441 let lw = conf.winw
- state.scrollw
- x in
1444 let lh = conf.winh
- y in
1447 Gl.enable `texture_2d
;
1448 begin match state.texid
with
1450 GlTex.bind_texture `texture_2d id
;
1453 and x1 = float (x+w)
1454 and y1 = float (y+h) in
1456 let tw = float w /. 64.0
1457 and th
= float h /. 64.0 in
1458 let tx0 = float tilex /. 64.0
1459 and ty0
= float tiley /. 64.0 in
1461 and ty1
= ty0
+. th
in
1462 GlDraw.begins `quads
;
1463 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1464 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1465 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1466 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1469 Gl.disable `texture_2d
;
1471 GlDraw.color
(1.0, 1.0, 1.0);
1474 (float (x+w), float (y+h));
1476 if w > 128 && h > fstate.fontsize
+ 10
1478 GlDraw.color
(0.0, 0.0, 0.0);
1481 then (col*conf.tilew
, row*conf.tileh
)
1484 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1491 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1493 let tilevisible1 l
x y =
1495 and ax1
= l
.pagex + l
.pagevw
1497 and ay1
= l
.pagey + l
.pagevh in
1501 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1502 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1504 let rx0 = max
ax0 bx0
1505 and ry0
= max ay0 by0
1506 and rx1
= min ax1
bx1
1507 and ry1
= min ay1 by1
in
1509 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1510 nonemptyintersection
1513 let tilevisible layout n x y =
1514 let rec findpageinlayout m
= function
1515 | l
:: rest
when l
.pageno
= n ->
1516 tilevisible1 l
x y || (
1517 match conf.columns
with
1518 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1521 | _
:: rest
-> findpageinlayout 0 rest
1524 findpageinlayout 0 layout;
1527 let tileready l
x y =
1528 tilevisible1 l
x y &&
1529 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1532 let tilepage n p
layout =
1533 let rec loop = function
1537 let f col row _ _ _ _ _ _
=
1538 if state.currently
= Idle
1540 match gettileopaque l
col row with
1543 let x = col*conf.tilew
1544 and y = row*conf.tileh
in
1546 let w = l
.pagew
- x in
1550 let h = l
.pageh
- y in
1553 wcmd "tile %s %d %d %d %d" p
x y w h;
1556 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1557 conf.tilew
, conf.tileh
1566 if nogeomcmds state.geomcmds
1570 let preloadlayout visiblepages
=
1571 let presentation = conf.presentation in
1572 let interpagespace = conf.interpagespace in
1573 let maxy = state.maxy in
1574 conf.presentation <- false;
1575 conf.interpagespace <- 0;
1576 state.maxy <- calcheight ();
1578 match visiblepages
with
1579 | [] -> if state.y >= maxy then maxy else 0
1580 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1582 let y = if y < conf.winh
then 0 else y - conf.winh
in
1583 let h = state.y - y + conf.winh
*3 in
1584 let pages = layout y h in
1585 conf.presentation <- presentation;
1586 conf.interpagespace <- interpagespace;
1592 let rec loop pages =
1593 if state.currently
!= Idle
1598 begin match getopaque l
.pageno
with
1600 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1601 state.currently
<- Loading
(l
, state.gen
);
1603 tilepage l
.pageno opaque
pages;
1608 if nogeomcmds state.geomcmds
1614 if conf.preload && state.currently
= Idle
1615 then load (preloadlayout pages);
1618 let layoutready layout =
1619 let rec fold all ls
=
1620 all
&& match ls
with
1622 let seen = ref false in
1623 let allvisible = ref true in
1624 let foo col row _ _ _ _ _ _
=
1626 allvisible := !allvisible &&
1627 begin match gettileopaque l
col row with
1633 fold (!seen && !allvisible) rest
1636 let alltilesvisible = fold true layout in
1641 let y = bound y 0 state.maxy in
1642 let y, layout, proceed
=
1643 match conf.maxwait
with
1644 | Some time
when state.ghyll
== noghyll ->
1645 begin match state.throttle
with
1647 let layout = layout y conf.winh
in
1648 let ready = layoutready layout in
1652 state.throttle
<- Some
(layout, y, now ());
1654 else G.postRedisplay "gotoy showall (None)";
1656 | Some
(_
, _
, started
) ->
1657 let dt = now () -. started
in
1660 state.throttle
<- None
;
1661 let layout = layout y conf.winh
in
1663 G.postRedisplay "maxwait";
1670 let layout = layout y conf.winh
in
1671 if true || layoutready layout
1672 then G.postRedisplay "gotoy ready";
1678 state.layout <- layout;
1679 begin match state.mode
with
1680 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
1681 let rec loop = function
1683 state.mode
<- LinkNav
(Ltgendir
0)
1684 | l
:: _
when l
.pageno
= pageno
->
1685 begin match getopaque pageno
with
1687 state.mode
<- LinkNav
(Ltgendir
0)
1689 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1690 if not
(x0 >= l
.pagex && x1 <= l
.pagex + l
.pagevw
1691 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1692 then state.mode
<- LinkNav
(Ltgendir
0)
1694 | _
:: rest
-> loop rest
1699 begin match state.mode
with
1700 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1701 if not
(pagevisible layout pageno
)
1703 match state.layout with
1706 state.mode
<- Birdseye
(
1707 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1710 | LinkNav
(Ltgendir dir
as lt
) ->
1712 let rec loop = function
1715 match getopaque l
.pageno
with
1721 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1723 if dir
> 0 then LDfirst
else LDlast
1729 | Lnotfound
-> loop rest
1731 showlinktype (getlink opaque
n);
1732 Ltexact
(l
.pageno
, n)
1736 state.mode
<- LinkNav
linknav
1741 state.ghyll
<- noghyll;
1744 let mx, my
= state.mpos
in
1749 let conttiling pageno opaque
=
1750 tilepage pageno opaque
1751 (if conf.preload then preloadlayout state.layout else state.layout)
1754 let gotoy_and_clear_text y =
1755 if not
conf.verbose
then state.text <- "";
1760 match state.layout with
1763 let coloff = l
.pagecol
* l
.pageh
in
1764 (l
.pageno
, (float l
.pagey +. float coloff) /. float l
.pageh
)
1767 let getanchory (n, top
) =
1768 let y, h = getpageyh n in
1769 y + (truncate
(top
*. float h));
1772 let gotoanchor anchor
=
1773 gotoy (getanchory anchor
);
1777 cbput state.hists
.nav
(getanchor ());
1781 let anchor = cbgetc state.hists
.nav dir
in
1786 let rec scroll f n a
b =
1787 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1789 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1791 then s (float f /. float a
)
1794 then 1.0 -. s ((float (f-b) /. float (n-b)))
1801 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1802 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1804 let ins = float a
*. iv1
1805 and outs
= float (n-b) *. iv1 in
1807 ins +. outs
+. float ones
1809 let rec set (_N
, _A
, _B
) y sy
=
1810 let sum = summa
1.0 _N _A _B
in
1811 let dy = float (y - sy
) in
1815 then state.ghyll
<- noghyll
1818 let s = scroll n _N _A _B
in
1819 let y1 = y1 +. ((s *. dy) /. sum) in
1820 gotoy_and_clear_text (truncate
y1);
1821 state.ghyll
<- gf (n+1) y1;
1825 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1827 gf 0 (float state.y)
1830 match conf.ghyllscroll
with
1832 gotoy_and_clear_text y
1834 if state.ghyll
== noghyll
1835 then set nab
y state.y
1836 else state.ghyll
(Some
y)
1839 let gotopage n top
=
1840 let y, h = getpageyh n in
1841 let y = y + (truncate
(top
*. float h)) in
1845 let gotopage1 n top
=
1846 let y = getpagey n in
1851 let invalidate s f =
1856 match state.geomcmds
with
1857 | ps
, [] when String.length ps
= 0 ->
1859 state.geomcmds
<- s, [];
1862 state.geomcmds
<- ps
, [s, f];
1864 | ps
, (s'
, _
) :: rest
when s'
= s ->
1865 state.geomcmds
<- ps
, ((s, f) :: rest
);
1868 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1871 let opendoc path password
=
1873 state.password
<- password
;
1874 state.gen
<- state.gen
+ 1;
1875 state.docinfo
<- [];
1877 setaalevel
conf.aalevel
;
1878 Wsi.settitle
("llpp " ^
Filename.basename path
);
1879 wcmd "open %s\000%s\000" path password
;
1880 invalidate "reqlayout"
1882 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1886 let c = c *. conf.colorscale
in
1890 let scalecolor2 (r
, g
, b) =
1891 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1894 let docolumns = function
1897 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1898 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1899 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1900 let rec fixrow m
= if m
= pageno
then () else
1901 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1904 let y = y + (rowh
- h) / 2 in
1905 a.(m
) <- (pdimno, x, y, pdim
);
1909 if pageno
= state.pagecount
1910 then fixrow (((pageno
- 1) / columns
) * columns
)
1912 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1914 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1915 pdimno+1, pdim
, rest
1920 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1922 (conf.winw
- state.scrollw
- w) / 2,
1923 y + rowh
+ conf.interpagespace, h
1926 if (pageno
- coverA
) mod columns
= 0
1927 then 0, y + rowh
+ conf.interpagespace, h
1928 else x, y, max rowh
h
1931 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1932 then fixrow (pageno
- columns
);
1933 a.(pageno
) <- (pdimno, x, y, pdim
);
1934 let x = x + w + xoff*2 + conf.interpagespace in
1935 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1937 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1938 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1941 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1942 let rec loop pageno
pdimno pdim
y pdims
=
1943 if pageno
= state.pagecount
1946 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1948 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1949 pdimno+1, pdim
, rest
1954 let rec loop1 n x y =
1955 if n = c then y else (
1956 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1957 loop1 (n+1) (x+cw) (y + h + conf.interpagespace)
1960 let y = loop1 0 0 y in
1961 loop (pageno
+1) pdimno pdim
y pdims
1963 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1964 conf.columns
<- Csplit
(c, a);
1968 docolumns conf.columns
;
1969 state.maxy <- calcheight ();
1971 if state.w <= conf.winw
- state.scrollw
1975 match state.mode
with
1976 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1977 let y, h = getpageyh pageno
in
1978 let top = (conf.winh
- h) / 2 in
1979 gotoy (max
0 (y - top))
1980 | _
-> gotoanchor state.anchor
1984 GlDraw.viewport
0 0 w h;
1985 let firsttime = state.geomcmds
== firstgeomcmds in
1986 if not
firsttime && nogeomcmds state.geomcmds
1987 then state.anchor <- getanchor ();
1990 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1993 setfontsize fstate.fontsize
;
1994 GlMat.mode `modelview
;
1995 GlMat.load_identity
();
1997 GlMat.mode `projection
;
1998 GlMat.load_identity
();
1999 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2000 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2001 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2006 else float state.x /. float state.w
2008 invalidate "geometry"
2012 then state.x <- truncate
(relx *. float w);
2014 match conf.columns
with
2016 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
2017 | Csplit
(c, _
) -> w * c
2019 wcmd "geometry %d %d" w h);
2023 let len = String.length
state.text in
2026 match state.mode
with
2029 let h, _
, _
= state.uioh#scrollpw
in
2035 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2036 (x+.w, float (conf.winh
- hscrollh))
2039 let w = float (conf.winw
- state.scrollw
- 1) in
2040 if state.progress
>= 0.0 && state.progress
< 1.0
2042 GlDraw.color
(0.3, 0.3, 0.3);
2043 let w1 = w *. state.progress
in
2045 GlDraw.color
(0.0, 0.0, 0.0);
2049 GlDraw.color
(0.0, 0.0, 0.0);
2053 GlDraw.color
(1.0, 1.0, 1.0);
2054 drawstring fstate.fontsize
2055 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2058 match state.mode
with
2059 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
2063 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2065 Printf.sprintf
"%s%s_" prefix
text
2074 if not
(istextentry state.mode
)
2076 let s1 = "(press 'e' to review error messasges)" in
2077 if String.length
s > 0 then s ^
" " ^
s1 else s1
2082 if String.length
s > 0
2087 let len = Queue.length
state.tilelru
in
2089 if state.memused
<= conf.memlimit
2094 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2095 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2096 let (_
, pw, ph
, _
) = getpagedim n in
2099 && colorspace
= conf.colorspace
2100 && angle
= conf.angle
2105 match state.throttle
with
2108 then preloadlayout state.layout
2110 | Some
(layout, _
, _
) ->
2113 let x = col*conf.tilew
2114 and y = row*conf.tileh
in
2115 tilevisible layout n x y
2117 then Queue.push lruitem
state.tilelru
2119 wcmd "freetile %s" p
;
2120 state.memused
<- state.memused
- s;
2121 state.uioh#infochanged Memused
;
2122 Hashtbl.remove
state.tilemap k
;
2131 Queue.iter
(fun (k
, p
, s) ->
2132 wcmd "freetile %s" p
;
2133 state.memused
<- state.memused
- s;
2134 state.uioh#infochanged Memused
;
2135 Hashtbl.remove
state.tilemap k
;
2137 Queue.clear
state.tilelru
;
2141 let logcurrently = function
2142 | Idle
-> dolog "Idle"
2143 | Loading
(l
, gen
) ->
2144 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2145 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2147 "Tiling %d[%d,%d] page=%s cs=%s angle"
2148 l
.pageno
col row pageopaque
2149 (colorspace_to_string colorspace
)
2151 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2152 angle gen
conf.angle
state.gen
2154 conf.tilew
conf.tileh
2161 (* dolog "%S" cmds; *)
2164 try String.index cmds ' '
2165 with Not_found
-> -1
2170 let l = String.length cmds
in
2171 let op = String.sub cmds
0 spacepos in
2173 if l - spacepos < 2 then ""
2174 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2179 state.uioh#infochanged Pdim
;
2183 state.rects
<- state.rects1
;
2184 G.postRedisplay "clearrects";
2188 try Scanf.sscanf
args "%u" (fun n -> n)
2190 dolog "error processing 'continue' %S: %s"
2191 cmds
(Printexc.to_string exn
);
2194 state.pagecount
<- n;
2195 begin match state.currently
with
2197 state.currently
<- Idle
;
2198 state.outlines
<- Array.of_list
(List.rev
l)
2202 let cur, cmds
= state.geomcmds
in
2203 if String.length
cur = 0
2204 then failwith
"umpossible";
2206 begin match List.rev cmds
with
2208 state.geomcmds
<- "", [];
2212 state.geomcmds
<- s, List.rev rest
;
2214 if conf.maxwait
= None
2215 then G.postRedisplay "continue";
2225 then showtext ' '
args
2228 let progress, text =
2230 Scanf.sscanf
args "%f %n"
2232 f, String.sub
args pos
(String.length
args - pos
))
2234 dolog "error processing 'progress' %S: %s"
2235 cmds
(Printexc.to_string exn
);
2239 state.progress <- progress;
2240 G.postRedisplay "progress"
2243 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2245 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2246 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2247 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2249 dolog "error processing 'firstmatch' %S: %s"
2250 cmds
(Printexc.to_string exn
);
2253 let y = (getpagey pageno) + truncate
y0 in
2256 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2259 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2261 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2262 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2263 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2265 dolog "error processing 'match' %S: %s"
2266 cmds
(Printexc.to_string exn
);
2270 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2275 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2277 dolog "error processing 'page' %S: %s"
2278 cmds
(Printexc.to_string exn
);
2281 begin match state.currently
with
2282 | Loading
(l, gen
) ->
2283 vlog "page %d took %f sec" l.pageno t
;
2284 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2285 begin match state.throttle
with
2287 let preloadedpages =
2289 then preloadlayout state.layout
2294 Set.Make
(struct type t
= int let compare = (-) end) in
2296 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2297 IntSet.empty
preloadedpages
2300 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2301 if not
(IntSet.mem
pageno set)
2303 wcmd "freepage %s" opaque
;
2309 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2312 state.currently
<- Idle
;
2315 tilepage l.pageno pageopaque state.layout;
2317 load preloadedpages;
2318 if pagevisible state.layout l.pageno
2319 && layoutready state.layout
2320 then G.postRedisplay "page";
2323 | Some
(layout, _
, _
) ->
2324 state.currently
<- Idle
;
2325 tilepage l.pageno pageopaque layout;
2330 dolog "Inconsistent loading state";
2331 logcurrently state.currently
;
2336 let (x, y, opaque
, size
, t
) =
2338 Scanf.sscanf
args "%u %u %s %u %f"
2339 (fun x y p size t
-> (x, y, p
, size
, t
))
2341 dolog "error processing 'tile' %S: %s"
2342 cmds
(Printexc.to_string exn
);
2345 begin match state.currently
with
2346 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2347 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2349 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2351 wcmd "freetile %s" opaque
;
2352 state.currently
<- Idle
;
2356 puttileopaque l col row gen cs angle opaque size t
;
2357 state.memused
<- state.memused
+ size
;
2358 state.uioh#infochanged Memused
;
2360 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2361 opaque
, size
) state.tilelru
;
2364 match state.throttle
with
2365 | None
-> state.layout
2366 | Some
(layout, _
, _
) -> layout
2369 state.currently
<- Idle
;
2371 && conf.colorspace
= cs
2372 && conf.angle
= angle
2373 && tilevisible layout l.pageno x y
2374 then conttiling l.pageno pageopaque;
2376 begin match state.throttle
with
2378 preload state.layout;
2380 && conf.colorspace
= cs
2381 && conf.angle
= angle
2382 && tilevisible state.layout l.pageno x y
2383 then G.postRedisplay "tile nothrottle";
2385 | Some
(layout, y, _
) ->
2386 let ready = layoutready layout in
2390 state.layout <- layout;
2391 state.throttle
<- None
;
2392 G.postRedisplay "throttle";
2399 dolog "Inconsistent tiling state";
2400 logcurrently state.currently
;
2407 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2409 dolog "error processing 'pdim' %S: %s"
2410 cmds
(Printexc.to_string exn
);
2413 state.uioh#infochanged Pdim
;
2414 state.pdims
<- pdim :: state.pdims
2417 let (l, n, t
, h, pos
) =
2419 Scanf.sscanf
args "%u %u %d %u %n"
2420 (fun l n t
h pos
-> l, n, t
, h, pos
)
2422 dolog "error processing 'o' %S: %s"
2423 cmds
(Printexc.to_string exn
);
2426 let s = String.sub
args pos
(String.length
args - pos
) in
2427 let outline = (s, l, (n, float t
/. float h)) in
2428 begin match state.currently
with
2429 | Outlining outlines
->
2430 state.currently
<- Outlining
(outline :: outlines
)
2432 state.currently
<- Outlining
[outline]
2434 dolog "invalid outlining state";
2435 logcurrently currently
2439 state.docinfo
<- (1, args) :: state.docinfo
2442 state.uioh#infochanged Docinfo
;
2443 state.docinfo
<- List.rev
state.docinfo
2446 dolog "unknown cmd `%S'" cmds
2451 let action = function
2452 | HCprev
-> cbget cb ~
-1
2453 | HCnext
-> cbget cb
1
2454 | HCfirst
-> cbget cb ~
-(cb
.rc)
2455 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2456 and cancel
() = cb
.rc <- rc
2460 let search pattern forward
=
2461 if String.length pattern
> 0
2464 match state.layout with
2467 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2469 wcmd "search %d %d %d %d,%s\000"
2470 (btod conf.icase
) pn py (btod forward
) pattern
;
2473 let intentry text key =
2475 if key >= 32 && key < 127
2481 let text = addchar text c in
2485 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2489 let linknentry text key =
2491 if key >= 32 && key < 127
2497 let text = addchar text c in
2501 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2506 if String.length
s > 0
2509 let l = String.length
s in
2510 let rec loop pos
n = if pos
= l then n else
2511 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2512 loop (pos
+1) (n*26 + m)
2515 let rec loop n = function
2518 match getopaque l.pageno with
2519 | None
-> loop n rest
2521 let m = getlinkcount opaque
in
2524 let under = getlink opaque
n in
2527 else loop (n-m) rest
2529 loop n state.layout;
2533 let textentry text key =
2534 if key land 0xff00 = 0xff00
2536 else TEcont
(text ^
Wsi.toutf8
key)
2539 let reqlayout angle proportional
=
2540 match state.throttle
with
2542 if nogeomcmds state.geomcmds
2543 then state.anchor <- getanchor ();
2544 conf.angle
<- angle
mod 360;
2547 match state.mode
with
2548 | LinkNav _
-> state.mode
<- View
2551 conf.proportional
<- proportional
;
2552 invalidate "reqlayout"
2553 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2557 let settrim trimmargins trimfuzz
=
2558 if nogeomcmds state.geomcmds
2559 then state.anchor <- getanchor ();
2560 conf.trimmargins
<- trimmargins
;
2561 conf.trimfuzz
<- trimfuzz
;
2562 let x0, y0, x1, y1 = trimfuzz
in
2563 invalidate "settrim"
2565 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2566 Hashtbl.iter
(fun _ opaque
->
2567 wcmd "freepage %s" opaque
;
2569 Hashtbl.clear
state.pagemap
;
2573 match state.throttle
with
2575 let zoom = max
0.01 zoom in
2576 if zoom <> conf.zoom
2578 state.prevzoom
<- conf.zoom;
2580 reshape conf.winw
conf.winh
;
2581 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2584 | Some
(layout, y, started
) ->
2586 match conf.maxwait
with
2590 let dt = now () -. started
in
2598 let setcolumns mode columns coverA coverB
=
2602 then showtext '
!'
"split mode doesn't work in bird's eye"
2604 conf.columns
<- Csplit
(-columns
, [||]);
2612 conf.columns
<- Csingle
;
2617 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2621 reshape conf.winw
conf.winh
;
2624 let enterbirdseye () =
2625 let zoom = float conf.thumbw
/. float conf.winw
in
2626 let birdseyepageno =
2627 let cy = conf.winh
/ 2 in
2631 let rec fold best
= function
2634 let d = cy - (l.pagedispy + l.pagevh/2)
2635 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2636 if abs
d < abs dbest
2643 state.mode
<- Birdseye
(
2644 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2647 conf.presentation <- false;
2648 conf.interpagespace <- 10;
2649 conf.hlinks
<- false;
2651 state.mstate
<- Mnone
;
2652 conf.maxwait
<- None
;
2654 match conf.beyecolumns
with
2657 Cmulti
((c, 0, 0), [||])
2660 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2663 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2668 reshape conf.winw
conf.winh
;
2671 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2673 conf.zoom <- c.zoom;
2674 conf.presentation <- c.presentation;
2675 conf.interpagespace <- c.interpagespace;
2676 conf.maxwait
<- c.maxwait
;
2677 conf.hlinks
<- c.hlinks
;
2678 conf.beyecolumns
<- (
2679 match conf.columns
with
2680 | Cmulti
((c, _
, _
), _
) -> Some
c
2682 | Csplit _
-> failwith
"leaving bird's eye split mode"
2685 match c.columns
with
2686 | Cmulti
(c, _
) -> Cmulti
(c, [||])
2687 | Csingle
-> Csingle
2688 | Csplit
(c, _
) -> Csplit
(c, [||])
2693 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2696 reshape conf.winw
conf.winh
;
2697 state.anchor <- if goback
then anchor else (pageno, 0.0);
2700 let togglebirdseye () =
2701 match state.mode
with
2702 | Birdseye vals
-> leavebirdseye vals
true
2703 | View
-> enterbirdseye ()
2707 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2708 let pageno = max
0 (pageno - incr
) in
2709 let rec loop = function
2710 | [] -> gotopage1 pageno 0
2711 | l :: _
when l.pageno = pageno ->
2712 if l.pagedispy >= 0 && l.pagey = 0
2713 then G.postRedisplay "upbirdseye"
2714 else gotopage1 pageno 0
2715 | _
:: rest
-> loop rest
2718 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2721 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2722 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2723 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2724 let rec loop = function
2726 let y, h = getpageyh pageno in
2727 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2729 | l :: _
when l.pageno = pageno ->
2730 if l.pagevh != l.pageh
2731 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2732 else G.postRedisplay "downbirdseye"
2733 | _
:: rest
-> loop rest
2738 let optentry mode _
key =
2739 let btos b = if b then "on" else "off" in
2740 if key >= 32 && key < 127
2742 let c = Char.chr
key in
2746 try conf.scrollstep
<- int_of_string
s with exc
->
2747 state.text <- Printf.sprintf
"bad integer `%s': %s"
2748 s (Printexc.to_string exc
)
2750 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2755 conf.autoscrollstep
<- int_of_string
s;
2756 if state.autoscroll
<> None
2757 then state.autoscroll
<- Some
conf.autoscrollstep
2759 state.text <- Printf.sprintf
"bad integer `%s': %s"
2760 s (Printexc.to_string exc
)
2762 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2765 let mode = state.mode in
2768 let n, a, b = multicolumns_of_string s in
2769 setcolumns mode n a b;
2771 state.text <- Printf.sprintf
"bad columns `%s': %s"
2772 s (Printexc.to_string exc
)
2774 TEswitch
("columns: ", "", None
, textentry, ondone)
2779 let zoom = float (int_of_string
s) /. 100.0 in
2782 state.text <- Printf.sprintf
"bad integer `%s': %s"
2783 s (Printexc.to_string exc
)
2785 TEswitch
("zoom: ", "", None
, intentry, ondone)
2790 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2792 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2793 begin match mode with
2795 leavebirdseye beye
false;
2800 state.text <- Printf.sprintf
"bad integer `%s': %s"
2801 s (Printexc.to_string exc
)
2803 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2808 Some
(int_of_string
s)
2810 state.text <- Printf.sprintf
"bad integer `%s': %s"
2811 s (Printexc.to_string exc
);
2814 | Some angle
-> reqlayout angle
conf.proportional
2817 TEswitch
("rotation: ", "", None
, intentry, ondone)
2820 conf.icase
<- not
conf.icase
;
2821 TEdone
("case insensitive search " ^
(btos conf.icase
))
2824 conf.preload <- not
conf.preload;
2826 TEdone
("preload " ^
(btos conf.preload))
2829 conf.verbose
<- not
conf.verbose
;
2830 TEdone
("verbose " ^
(btos conf.verbose
))
2833 conf.debug
<- not
conf.debug
;
2834 TEdone
("debug " ^
(btos conf.debug
))
2837 conf.maxhfit
<- not
conf.maxhfit
;
2838 state.maxy <- calcheight ();
2839 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2842 conf.crophack
<- not
conf.crophack
;
2843 TEdone
("crophack " ^
btos conf.crophack
)
2847 match conf.maxwait
with
2849 conf.maxwait
<- Some infinity
;
2850 "always wait for page to complete"
2852 conf.maxwait
<- None
;
2853 "show placeholder if page is not ready"
2858 conf.underinfo
<- not
conf.underinfo
;
2859 TEdone
("underinfo " ^
btos conf.underinfo
)
2862 conf.savebmarks
<- not
conf.savebmarks
;
2863 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2869 match state.layout with
2874 conf.interpagespace <- int_of_string
s;
2875 docolumns conf.columns
;
2876 state.maxy <- calcheight ();
2877 let y = getpagey pageno in
2880 state.text <- Printf.sprintf
"bad integer `%s': %s"
2881 s (Printexc.to_string exc
)
2883 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2886 reqlayout conf.angle
(not
conf.proportional
);
2887 TEdone
("proportional display " ^
btos conf.proportional
)
2890 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2891 TEdone
("trim margins " ^
btos conf.trimmargins
)
2894 conf.invert
<- not
conf.invert
;
2895 TEdone
("invert colors " ^
btos conf.invert
)
2899 cbput state.hists
.sel
s;
2902 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2906 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2912 class type lvsource
= object
2913 method getitemcount
: int
2914 method getitem
: int -> (string * int)
2915 method hasaction
: int -> bool
2924 method getactive
: int
2925 method getfirst
: int
2926 method getqsearch
: string
2927 method setqsearch
: string -> unit
2931 class virtual lvsourcebase
= object
2932 val mutable m_active
= 0
2933 val mutable m_first
= 0
2934 val mutable m_qsearch
= ""
2935 val mutable m_pan
= 0
2936 method getactive
= m_active
2937 method getfirst
= m_first
2938 method getqsearch
= m_qsearch
2939 method getpan
= m_pan
2940 method setqsearch
s = m_qsearch
<- s
2943 let withoutlastutf8 s =
2944 let len = String.length
s in
2952 let b = Char.code
s.[pos
] in
2953 if b land 0b110000 = 0b11000000
2958 if Char.code
s.[len-1] land 0x80 = 0
2962 String.sub
s 0 first;
2965 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2967 state.mode <- Textentry
(te
, onleave
);
2970 G.postRedisplay "textentrykeyboard enttext";
2972 let histaction cmd
=
2975 | Some
(action, _
) ->
2976 state.mode <- Textentry
(
2977 (c, action cmd
, opthist
, onkey
, ondone), onleave
2979 G.postRedisplay "textentry histaction"
2982 | 0xff08 -> (* backspace *)
2983 let s = withoutlastutf8 text in
2984 let len = String.length
s in
2988 G.postRedisplay "textentrykeyboard after cancel";
2991 enttext (c, s, opthist
, onkey
, ondone)
2997 G.postRedisplay "textentrykeyboard after confirm"
2999 | 0xff52 -> histaction HCprev
3000 | 0xff54 -> histaction HCnext
3001 | 0xff50 -> histaction HCfirst
3002 | 0xff57 -> histaction HClast
3004 | 0xff1b -> (* escape*)
3005 if String.length
text = 0
3007 begin match opthist
with
3009 | Some
(_
, onhistcancel
) -> onhistcancel
()
3013 G.postRedisplay "textentrykeyboard after cancel2"
3016 enttext (c, "", opthist
, onkey
, ondone)
3019 | 0xff9f | 0xffff -> () (* delete *)
3021 | _
when key != 0 && key land 0xff00 != 0xff00 ->
3022 begin match onkey
text key with
3026 G.postRedisplay "textentrykeyboard after confirm2";
3029 enttext (c, text, opthist
, onkey
, ondone);
3033 G.postRedisplay "textentrykeyboard after cancel3"
3036 state.mode <- Textentry
(te
, onleave
);
3037 G.postRedisplay "textentrykeyboard switch";
3041 vlog "unhandled key %s" (Wsi.keyname
key)
3044 let firstof first active
=
3045 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3046 then max
0 (active
- (fstate.maxrows
/2))
3050 let calcfirst first active
=
3053 let rows = active
- first in
3054 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3058 let scrollph y maxy =
3059 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
3060 let sh = float conf.winh
/. sh in
3061 let sh = max
sh (float conf.scrollh
) in
3066 else float y /. float maxy
3068 let position = (float conf.winh
-. sh) *. percent in
3071 if position +. sh > float conf.winh
3072 then float conf.winh
-. sh
3078 let coe s = (s :> uioh
);;
3080 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3082 val m_pan
= source#getpan
3083 val m_first
= source#getfirst
3084 val m_active
= source#getactive
3085 val m_qsearch
= source#getqsearch
3086 val m_prev_uioh
= state.uioh
3088 method private elemunder
y =
3089 let n = y / (fstate.fontsize
+1) in
3090 if m_first
+ n < source#getitemcount
3092 if source#hasaction
(m_first
+ n)
3093 then Some
(m_first
+ n)
3100 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3101 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3102 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3103 GlDraw.color
(1., 1., 1.);
3104 Gl.enable `texture_2d
;
3105 let fs = fstate.fontsize
in
3107 let ww = fstate.wwidth
in
3108 let tabw = 30.0*.ww in
3109 let itemcount = source#getitemcount
in
3111 if (row - m_first
) * nfs > conf.winh
3114 if row >= 0 && row < itemcount
3116 let (s, level
) = source#getitem
row in
3117 let y = (row - m_first
) * nfs in
3118 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3121 Gl.disable `texture_2d
;
3122 GlDraw.polygon_mode `both `line
;
3123 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3124 GlDraw.rect (1., float (y + 1))
3125 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3126 GlDraw.polygon_mode `both `fill
;
3127 GlDraw.color
(1., 1., 1.);
3128 Gl.enable `texture_2d
;
3131 let drawtabularstring s =
3132 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3135 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3138 let len = String.length
s - tabpos - 1 in
3139 let s1 = String.sub
s 0 tabpos
3140 and s2
= String.sub
s (tabpos + 1) len in
3141 let nx = drawstr x s1 in
3143 let x = x +. (max
tabw sw) in
3150 let _ = drawtabularstring s in
3157 Gl.disable `texture_2d
;
3159 method updownlevel incr
=
3160 let len = source#getitemcount
in
3162 if m_active
>= 0 && m_active
< len
3163 then snd
(source#getitem m_active
)
3167 if i
= len then i
-1 else if i
= -1 then 0 else
3168 let _, l = source#getitem i
in
3169 if l != curlevel then i
else flow (i
+incr
)
3171 let active = flow m_active
in
3172 let first = calcfirst m_first
active in
3173 G.postRedisplay "outline updownlevel";
3174 {< m_active
= active; m_first
= first >}
3176 method private key1
key mask
=
3177 let set1 active first qsearch
=
3178 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3180 let search active pattern incr
=
3183 if n >= 0 && n < source#getitemcount
3185 let s, _ = source#getitem
n in
3187 (try ignore
(Str.search_forward
re s 0); true
3188 with Not_found
-> false)
3190 else loop (n + incr
)
3197 let re = Str.regexp_case_fold pattern
in
3203 let itemcount = source#getitemcount
in
3204 let find start incr
=
3206 if i
= -1 || i
= itemcount
3209 if source#hasaction i
3211 else find (i
+ incr
)
3216 let set active first =
3217 let first = bound first 0 (itemcount - fstate.maxrows
) in
3219 coe {< m_active
= active; m_first
= first >}
3222 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3224 let incr1 = if incr
> 0 then 1 else -1 in
3225 if isvisible m_first m_active
3228 let next = m_active
+ incr
in
3230 if next < 0 || next >= itemcount
3232 else find next incr1
3234 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3240 let first = m_first
+ incr
in
3241 let first = bound first 0 (itemcount - 1) in
3243 let next = m_active
+ incr
in
3244 let next = bound next 0 (itemcount - 1) in
3247 let active = if next = -1 then m_active
else next in
3250 let first = min
next m_first
in
3252 if abs
(next - first) > fstate.maxrows
3258 let first = m_first
+ incr
in
3259 let first = bound first 0 (itemcount - 1) in
3261 let next = m_active
+ incr
in
3262 let next = bound next 0 (itemcount - 1) in
3263 let next = find next incr1 in
3265 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3267 let active = if m_active
= -1 then next else m_active
in
3272 if isvisible first active
3278 G.postRedisplay "listview navigate";
3282 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3283 let incr = if key = 0x72 then -1 else 1 in
3285 match search (m_active
+ incr) m_qsearch
incr with
3287 state.text <- m_qsearch ^
" [not found]";
3290 state.text <- m_qsearch
;
3291 active, firstof m_first
active
3293 G.postRedisplay "listview ctrl-r/s";
3294 set1 active first m_qsearch
;
3296 | 0xff08 -> (* backspace *)
3297 if String.length m_qsearch
= 0
3300 let qsearch = withoutlastutf8 m_qsearch
in
3301 let len = String.length
qsearch in
3305 G.postRedisplay "listview empty qsearch";
3306 set1 m_active m_first
"";
3310 match search m_active
qsearch ~
-1 with
3312 state.text <- qsearch ^
" [not found]";
3315 state.text <- qsearch;
3316 active, firstof m_first
active
3318 G.postRedisplay "listview backspace qsearch";
3319 set1 active first qsearch
3322 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3323 let pattern = m_qsearch ^
Wsi.toutf8
key in
3325 match search m_active
pattern 1 with
3327 state.text <- pattern ^
" [not found]";
3330 state.text <- pattern;
3331 active, firstof m_first
active
3333 G.postRedisplay "listview qsearch add";
3334 set1 active first pattern;
3336 | 0xff1b -> (* escape *)
3338 if String.length m_qsearch
= 0
3340 G.postRedisplay "list view escape";
3343 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3345 | None
-> m_prev_uioh
3350 G.postRedisplay "list view kill qsearch";
3351 source#setqsearch
"";
3352 coe {< m_qsearch
= "" >}
3355 | 0xff0d -> (* return *)
3357 let self = {< m_qsearch
= "" >} in
3358 source#setqsearch
"";
3360 G.postRedisplay "listview enter";
3361 if m_active
>= 0 && m_active
< source#getitemcount
3363 source#exit
(coe self) false m_active m_first m_pan
"";
3366 source#exit
(coe self) true m_active m_first m_pan
"";
3369 begin match opt with
3370 | None
-> m_prev_uioh
3374 | 0xff9f | 0xffff -> (* delete *)
3377 | 0xff52 -> navigate ~
-1 (* up *)
3378 | 0xff54 -> navigate 1 (* down *)
3379 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3380 | 0xff56 -> navigate fstate.maxrows
(* next *)
3382 | 0xff53 -> (* right *)
3384 G.postRedisplay "listview right";
3385 coe {< m_pan
= m_pan
- 1 >}
3387 | 0xff51 -> (* left *)
3389 G.postRedisplay "listview left";
3390 coe {< m_pan
= m_pan
+ 1 >}
3392 | 0xff50 -> (* home *)
3393 let active = find 0 1 in
3394 G.postRedisplay "listview home";
3397 | 0xff57 -> (* end *)
3398 let first = max
0 (itemcount - fstate.maxrows
) in
3399 let active = find (itemcount - 1) ~
-1 in
3400 G.postRedisplay "listview end";
3403 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3407 dolog "listview unknown key %#x" key; coe self
3409 method key key mask
=
3410 match state.mode with
3411 | Textentry te
-> textentrykeyboard key mask te
; coe self
3412 | _ -> self#key1
key mask
3414 method button button down
x y _ =
3417 | 1 when x > conf.winw
- conf.scrollbw
->
3418 G.postRedisplay "listview scroll";
3421 let _, position, sh = self#
scrollph in
3422 if y > truncate
position && y < truncate
(position +. sh)
3424 state.mstate
<- Mscrolly
;
3428 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3429 let first = truncate
(s *. float source#getitemcount
) in
3430 let first = min source#getitemcount
first in
3431 Some
(coe {< m_first
= first; m_active
= first >})
3433 state.mstate
<- Mnone
;
3436 | 1 when not down
->
3437 begin match self#elemunder
y with
3439 G.postRedisplay "listview click";
3441 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3445 | n when (n == 4 || n == 5) && not down
->
3446 let len = source#getitemcount
in
3448 if n = 5 && m_first
+ fstate.maxrows
>= len
3452 let first = m_first
+ (if n == 4 then -1 else 1) in
3453 bound first 0 (len - 1)
3455 G.postRedisplay "listview wheel";
3456 Some
(coe {< m_first
= first >})
3461 | None
-> m_prev_uioh
3465 match state.mstate
with
3467 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3468 let first = truncate
(s *. float source#getitemcount
) in
3469 let first = min source#getitemcount
first in
3470 G.postRedisplay "listview motion";
3471 coe {< m_first
= first; m_active
= first >}
3474 method pmotion
x y =
3475 if x < conf.winw
- conf.scrollbw
3478 match self#elemunder
y with
3479 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3480 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3484 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3489 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3493 method infochanged
_ = ()
3495 method scrollpw
= (0, 0.0, 0.0)
3497 let nfs = fstate.fontsize
+ 1 in
3498 let y = m_first
* nfs in
3499 let itemcount = source#getitemcount
in
3500 let maxi = max
0 (itemcount - fstate.maxrows
) in
3501 let maxy = maxi * nfs in
3502 let p, h = scrollph y maxy in
3505 method modehash
= modehash
3508 class outlinelistview ~source
=
3511 ~source
:(source
:> lvsource
)
3513 ~modehash
:(findkeyhash conf "outline")
3516 method key key mask
=
3517 let calcfirst first active =
3520 let rows = active - first in
3521 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3525 let active = m_active
+ incr in
3526 let active = bound active 0 (source#getitemcount
- 1) in
3527 let first = calcfirst m_first
active in
3528 G.postRedisplay "outline navigate";
3529 coe {< m_active
= active; m_first
= first >}
3531 let ctrl = Wsi.withctrl mask
in
3533 | 110 when ctrl -> (* ctrl-n *)
3534 source#narrow m_qsearch
;
3535 G.postRedisplay "outline ctrl-n";
3536 coe {< m_first
= 0; m_active
= 0 >}
3538 | 117 when ctrl -> (* ctrl-u *)
3540 G.postRedisplay "outline ctrl-u";
3542 coe {< m_first
= 0; m_active
= 0 >}
3544 | 108 when ctrl -> (* ctrl-l *)
3545 let first = m_active
- (fstate.maxrows
/ 2) in
3546 G.postRedisplay "outline ctrl-l";
3547 coe {< m_first
= first >}
3549 | 0xff9f | 0xffff -> (* delete *)
3550 source#remove m_active
;
3551 G.postRedisplay "outline delete";
3552 let active = max
0 (m_active
-1) in
3553 coe {< m_first
= firstof m_first
active;
3554 m_active
= active >}
3556 | 0xff52 -> navigate ~
-1 (* up *)
3557 | 0xff54 -> navigate 1 (* down *)
3558 | 0xff55 -> (* prior *)
3559 navigate ~
-(fstate.maxrows
)
3560 | 0xff56 -> (* next *)
3561 navigate fstate.maxrows
3563 | 0xff53 -> (* [ctrl-]right *)
3567 G.postRedisplay "outline ctrl right";
3568 {< m_pan
= m_pan
+ 1 >}
3570 else self#updownlevel
1
3574 | 0xff51 -> (* [ctrl-]left *)
3578 G.postRedisplay "outline ctrl left";
3579 {< m_pan
= m_pan
- 1 >}
3581 else self#updownlevel ~
-1
3585 | 0xff50 -> (* home *)
3586 G.postRedisplay "outline home";
3587 coe {< m_first
= 0; m_active
= 0 >}
3589 | 0xff57 -> (* end *)
3590 let active = source#getitemcount
- 1 in
3591 let first = max
0 (active - fstate.maxrows
) in
3592 G.postRedisplay "outline end";
3593 coe {< m_active
= active; m_first
= first >}
3595 | _ -> super#
key key mask
3598 let outlinesource usebookmarks
=
3601 inherit lvsourcebase
3602 val mutable m_items
= empty
3603 val mutable m_orig_items
= empty
3604 val mutable m_prev_items
= empty
3605 val mutable m_narrow_pattern
= ""
3606 val mutable m_hadremovals
= false
3608 method getitemcount
=
3609 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3612 if n == Array.length m_items
&& m_hadremovals
3614 ("[Confirm removal]", 0)
3616 let s, n, _ = m_items
.(n) in
3619 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3620 ignore
(uioh
, first, qsearch);
3621 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3623 if String.length m_narrow_pattern
= 0
3629 if not
confrimremoval
3631 let _, _, anchor = m_items
.(active) in
3636 state.bookmarks
<- Array.to_list m_items
;
3637 m_orig_items
<- m_items
;
3640 else m_items
<- items;
3644 method hasaction
_ = true
3647 if Array.length m_items
!= Array.length m_orig_items
3648 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3651 method narrow
pattern =
3652 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3656 let rec loop accu n =
3659 m_narrow_pattern
<- pattern;
3660 m_items
<- Array.of_list
accu
3663 let (s, _, _) as o = m_items
.(n) in
3665 if (try ignore
(Str.search_forward
re s 0); true
3666 with Not_found
-> false)
3672 loop [] (Array.length m_items
- 1)
3677 then Array.of_list
state.bookmarks
3680 m_items
<- m_orig_items
3685 if m >= 0 && m < Array.length m_items
3687 m_hadremovals
<- true;
3688 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3689 let n = if n >= m then n+1 else n in
3694 method reset
anchor items =
3695 m_hadremovals
<- false;
3696 if m_orig_items
== empty || m_prev_items
!= items
3698 m_orig_items
<- items;
3699 if String.length m_narrow_pattern
= 0
3700 then m_items
<- items;
3702 m_prev_items
<- items;
3703 let rely = getanchory anchor in
3705 let rec loop n best bestd
=
3706 if n = Array.length m_items
3709 let (_, _, anchor) = m_items
.(n) in
3710 let orely = getanchory anchor in
3711 let d = abs
(orely - rely) in
3714 else loop (n+1) best bestd
3719 m_first
<- firstof m_first
active
3723 let enterselector usebookmarks
=
3724 let source = outlinesource usebookmarks
in
3728 then Array.of_list
state.bookmarks
3731 if Array.length
outlines = 0
3733 showtext ' ' errmsg
;
3736 state.text <- source#greetmsg
;
3737 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3738 let anchor = getanchor () in
3739 source#reset
anchor outlines;
3740 state.uioh
<- coe (new outlinelistview ~
source);
3741 G.postRedisplay "enter selector";
3745 let enteroutlinemode =
3746 let f = enterselector false in
3747 fun ()-> f "Document has no outline";
3750 let enterbookmarkmode =
3751 let f = enterselector true in
3752 fun () -> f "Document has no bookmarks (yet)";
3755 let color_of_string s =
3756 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3757 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3761 let color_to_string (r
, g
, b) =
3762 let r = truncate
(r *. 256.0)
3763 and g
= truncate
(g
*. 256.0)
3764 and b = truncate
(b *. 256.0) in
3765 Printf.sprintf
"%d/%d/%d" r g
b
3768 let irect_of_string s =
3769 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3772 let irect_to_string (x0,y0,x1,y1) =
3773 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3776 let makecheckers () =
3777 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3779 converted by Issac Trotts. July 25, 2002 *)
3780 let image_height = 64
3781 and image_width
= 64 in
3785 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3787 for i
= 0 to image_width
- 1 do
3788 for j
= 0 to image_height - 1 do
3789 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3790 (if (i
land 8 ) lxor (j
land 8) = 0
3791 then [|255;255;255|] else [|200;200;200|])
3796 let image = make_image () in
3797 let id = GlTex.gen_texture
() in
3798 GlTex.bind_texture `texture_2d
id;
3799 GlPix.store
(`unpack_alignment
1);
3800 GlTex.image2d
image;
3801 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3804 `mag_filter `nearest
;
3805 `min_filter `nearest
];
3809 let setcheckers enabled
=
3810 match state.texid
with
3812 if enabled
then state.texid
<- Some
(makecheckers ())
3817 GlTex.delete_texture texid
;
3818 state.texid
<- None
;
3822 let int_of_string_with_suffix s =
3823 let l = String.length
s in
3827 let suffix = Char.lowercase
s.[l-1] in
3829 | 'k'
-> String.sub
s 0 (l-1), 10
3830 | '
m'
-> String.sub
s 0 (l-1), 20
3831 | 'g'
-> String.sub
s 0 (l-1), 30
3835 let n = int_of_string
s1 in
3836 let m = n lsl shift
in
3838 then raise
(Failure
"value too large")
3842 let string_with_suffix_of_int n =
3850 if n land ((1 lsl 20) - 1) = 0
3853 if n land ((1 lsl 10) - 1) = 0
3860 let h = n mod 1000 in
3863 then string_of_int
h ^
s
3865 let s = Printf.sprintf
"_%03d%s" h s in
3872 let defghyllscroll = (40, 8, 32);;
3873 let ghyllscroll_of_string s =
3874 let (n, a, b) as nab
=
3877 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3879 if n <= a || n <= b || a >= b
3880 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3884 let ghyllscroll_to_string ((n, a, b) as nab
) =
3885 if nab
= defghyllscroll
3887 else Printf.sprintf
"%d,%d,%d" n a b;
3890 let describe_location () =
3892 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3894 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3895 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3899 else (100. *. (float state.y /. float maxy))
3903 Printf.sprintf
"page %d of %d [%.2f%%]"
3904 (fn+1) state.pagecount
percent
3907 "pages %d-%d of %d [%.2f%%]"
3908 (fn+1) (ln
+1) state.pagecount
percent
3912 let btos b = if b then "\xe2\x88\x9a" else "" in
3913 let showextended = ref false in
3914 let leave mode = function
3915 | Confirm
-> state.mode <- mode
3916 | Cancel
-> state.mode <- mode in
3919 val mutable m_first_time
= true
3920 val mutable m_l
= []
3921 val mutable m_a
= [||]
3922 val mutable m_prev_uioh
= nouioh
3923 val mutable m_prev_mode
= View
3925 inherit lvsourcebase
3927 method reset prev_mode prev_uioh
=
3928 m_a
<- Array.of_list
(List.rev m_l
);
3930 m_prev_mode
<- prev_mode
;
3931 m_prev_uioh
<- prev_uioh
;
3935 if n >= Array.length m_a
3939 | _, _, _, Action
_ -> m_active
<- n
3943 m_first_time
<- false;
3946 method int name get
set =
3948 (name
, `
int get
, 1, Action
(
3951 try set (int_of_string
s)
3953 state.text <- Printf.sprintf
"bad integer `%s': %s"
3954 s (Printexc.to_string exn
)
3957 let te = name ^
": ", "", None
, intentry, ondone in
3958 state.mode <- Textentry
(te, leave m_prev_mode
);
3962 method int_with_suffix name get
set =
3964 (name
, `intws get
, 1, Action
(
3967 try set (int_of_string_with_suffix s)
3969 state.text <- Printf.sprintf
"bad integer `%s': %s"
3970 s (Printexc.to_string exn
)
3974 name ^
": ", "", None
, intentry_with_suffix, ondone
3976 state.mode <- Textentry
(te, leave m_prev_mode
);
3980 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3982 (name
, `
bool (btos, get
), offset
, Action
(
3989 method color name get
set =
3991 (name
, `color get
, 1, Action
(
3993 let invalid = (nan
, nan
, nan
) in
3996 try color_of_string s
3998 state.text <- Printf.sprintf
"bad color `%s': %s"
3999 s (Printexc.to_string exn
);
4005 let te = name ^
": ", "", None
, textentry, ondone in
4006 state.text <- color_to_string (get
());
4007 state.mode <- Textentry
(te, leave m_prev_mode
);
4011 method string name get
set =
4013 (name
, `
string get
, 1, Action
(
4015 let ondone s = set s in
4016 let te = name ^
": ", "", None
, textentry, ondone in
4017 state.mode <- Textentry
(te, leave m_prev_mode
);
4021 method colorspace name get
set =
4023 (name
, `
string get
, 1, Action
(
4026 let vals = [| "rgb"; "bgr"; "gray" |] in
4028 inherit lvsourcebase
4031 m_active
<- int_of_colorspace conf.colorspace
;
4034 method getitemcount
= Array.length
vals
4035 method getitem
n = (vals.(n), 0)
4036 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4037 ignore
(uioh
, first, pan
, qsearch);
4038 if not cancel
then set active;
4040 method hasaction
_ = true
4044 let modehash = findkeyhash conf "info" in
4045 coe (new listview ~
source ~trusted
:true ~
modehash)
4048 method caption
s offset
=
4049 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4051 method caption2
s f offset
=
4052 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4054 method getitemcount
= Array.length m_a
4057 let tostr = function
4058 | `
int f -> string_of_int
(f ())
4059 | `intws
f -> string_with_suffix_of_int (f ())
4061 | `color
f -> color_to_string (f ())
4062 | `
bool (btos, f) -> btos (f ())
4065 let name, t
, offset
, _ = m_a
.(n) in
4066 ((let s = tostr t
in
4067 if String.length
s > 0
4068 then Printf.sprintf
"%s\t%s" name s
4072 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4076 m_qsearch
<- qsearch;
4078 match m_a
.(active) with
4079 | _, _, _, Action
f -> f uioh
4091 method hasaction
n =
4093 | _, _, _, Action
_ -> true
4097 let rec fillsrc prevmode prevuioh
=
4098 let sep () = src#caption
"" 0 in
4099 let colorp name get
set =
4101 (fun () -> color_to_string (get
()))
4104 let c = color_of_string v in
4107 state.text <- Printf.sprintf
"bad color `%s': %s"
4108 v (Printexc.to_string exn
);
4111 let oldmode = state.mode in
4112 let birdseye = isbirdseye state.mode in
4114 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4116 src#
bool "presentation mode"
4117 (fun () -> conf.presentation)
4119 conf.presentation <- v;
4120 state.anchor <- getanchor ();
4123 src#
bool "ignore case in searches"
4124 (fun () -> conf.icase
)
4125 (fun v -> conf.icase
<- v);
4128 (fun () -> conf.preload)
4129 (fun v -> conf.preload <- v);
4131 src#
bool "highlight links"
4132 (fun () -> conf.hlinks
)
4133 (fun v -> conf.hlinks
<- v);
4135 src#
bool "under info"
4136 (fun () -> conf.underinfo
)
4137 (fun v -> conf.underinfo
<- v);
4139 src#
bool "persistent bookmarks"
4140 (fun () -> conf.savebmarks
)
4141 (fun v -> conf.savebmarks
<- v);
4143 src#
bool "proportional display"
4144 (fun () -> conf.proportional
)
4145 (fun v -> reqlayout conf.angle
v);
4147 src#
bool "trim margins"
4148 (fun () -> conf.trimmargins
)
4149 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4151 src#
bool "persistent location"
4152 (fun () -> conf.jumpback
)
4153 (fun v -> conf.jumpback
<- v);
4156 src#
int "inter-page space"
4157 (fun () -> conf.interpagespace)
4159 conf.interpagespace <- n;
4160 docolumns conf.columns
;
4162 match state.layout with
4167 state.maxy <- calcheight ();
4168 let y = getpagey pageno in
4173 (fun () -> conf.pagebias
)
4174 (fun v -> conf.pagebias
<- v);
4176 src#
int "scroll step"
4177 (fun () -> conf.scrollstep
)
4178 (fun n -> conf.scrollstep
<- n);
4180 src#
int "auto scroll step"
4182 match state.autoscroll
with
4184 | _ -> conf.autoscrollstep
)
4186 if state.autoscroll
<> None
4187 then state.autoscroll
<- Some
n;
4188 conf.autoscrollstep
<- n);
4191 (fun () -> truncate
(conf.zoom *. 100.))
4192 (fun v -> setzoom ((float v) /. 100.));
4195 (fun () -> conf.angle
)
4196 (fun v -> reqlayout v conf.proportional
);
4198 src#
int "scroll bar width"
4199 (fun () -> state.scrollw
)
4203 reshape conf.winw
conf.winh
;
4206 src#
int "scroll handle height"
4207 (fun () -> conf.scrollh
)
4208 (fun v -> conf.scrollh
<- v;);
4210 src#
int "thumbnail width"
4211 (fun () -> conf.thumbw
)
4213 conf.thumbw
<- min
4096 v;
4216 leavebirdseye beye
false;
4221 let mode = state.mode in
4222 src#
string "columns"
4224 match conf.columns
with
4226 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4227 | Csplit
(count
, _) -> "-" ^ string_of_int count
4230 let n, a, b = multicolumns_of_string v in
4231 setcolumns mode n a b);
4234 src#caption
"Presentation mode" 0;
4235 src#
bool "scrollbar visible"
4236 (fun () -> conf.scrollbarinpm
)
4238 if v != conf.scrollbarinpm
4240 conf.scrollbarinpm
<- v;
4241 if conf.presentation
4243 state.scrollw
<- if v then conf.scrollbw
else 0;
4244 reshape conf.winw
conf.winh
;
4250 src#caption
"Pixmap cache" 0;
4251 src#int_with_suffix
"size (advisory)"
4252 (fun () -> conf.memlimit
)
4253 (fun v -> conf.memlimit
<- v);
4256 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4257 (string_with_suffix_of_int state.memused
)
4258 (Hashtbl.length
state.tilemap
)) 1;
4261 src#caption
"Layout" 0;
4262 src#caption2
"Dimension"
4264 Printf.sprintf
"%dx%d (virtual %dx%d)"
4270 src#caption2
"Position" (fun () ->
4271 Printf.sprintf
"%dx%d" state.x state.y
4274 src#caption2
"Visible" (fun () -> describe_location ()) 1
4278 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4279 "Save these parameters as global defaults at exit"
4280 (fun () -> conf.bedefault
)
4281 (fun v -> conf.bedefault
<- v)
4285 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4286 src#
bool ~offset
:0 ~
btos "Extended parameters"
4287 (fun () -> !showextended)
4288 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4292 (fun () -> conf.checkers
)
4293 (fun v -> conf.checkers
<- v; setcheckers v);
4294 src#
bool "update cursor"
4295 (fun () -> conf.updatecurs
)
4296 (fun v -> conf.updatecurs
<- v);
4298 (fun () -> conf.verbose
)
4299 (fun v -> conf.verbose
<- v);
4300 src#
bool "invert colors"
4301 (fun () -> conf.invert
)
4302 (fun v -> conf.invert
<- v);
4304 (fun () -> conf.maxhfit
)
4305 (fun v -> conf.maxhfit
<- v);
4306 src#
bool "redirect stderr"
4307 (fun () -> conf.redirectstderr)
4308 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4309 src#
string "uri launcher"
4310 (fun () -> conf.urilauncher
)
4311 (fun v -> conf.urilauncher
<- v);
4312 src#
string "path launcher"
4313 (fun () -> conf.pathlauncher
)
4314 (fun v -> conf.pathlauncher
<- v);
4315 src#
string "tile size"
4316 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4319 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4320 conf.tilew
<- max
64 w;
4321 conf.tileh
<- max
64 h;
4324 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4325 v (Printexc.to_string exn
));
4326 src#
int "texture count"
4327 (fun () -> conf.texcount
)
4330 then conf.texcount
<- v
4331 else showtext '
!'
" Failed to set texture count please retry later"
4333 src#
int "slice height"
4334 (fun () -> conf.sliceheight
)
4336 conf.sliceheight
<- v;
4337 wcmd "sliceh %d" conf.sliceheight
;
4339 src#
int "anti-aliasing level"
4340 (fun () -> conf.aalevel
)
4342 conf.aalevel
<- bound v 0 8;
4343 state.anchor <- getanchor ();
4344 opendoc state.path
state.password
;
4346 src#
int "ui font size"
4347 (fun () -> fstate.fontsize
)
4348 (fun v -> setfontsize (bound v 5 100));
4349 src#
int "hint font size"
4350 (fun () -> conf.hfsize
)
4351 (fun v -> conf.hfsize
<- bound v 5 100);
4352 colorp "background color"
4353 (fun () -> conf.bgcolor
)
4354 (fun v -> conf.bgcolor
<- v);
4355 src#
bool "crop hack"
4356 (fun () -> conf.crophack
)
4357 (fun v -> conf.crophack
<- v);
4358 src#
string "trim fuzz"
4359 (fun () -> irect_to_string conf.trimfuzz
)
4362 conf.trimfuzz
<- irect_of_string v;
4364 then settrim true conf.trimfuzz
;
4366 state.text <- Printf.sprintf
"bad irect `%s': %s"
4367 v (Printexc.to_string exn
)
4369 src#
string "throttle"
4371 match conf.maxwait
with
4372 | None
-> "show place holder if page is not ready"
4375 then "wait for page to fully render"
4377 "wait " ^ string_of_float
time
4378 ^
" seconds before showing placeholder"
4382 let f = float_of_string
v in
4384 then conf.maxwait
<- None
4385 else conf.maxwait
<- Some
f
4387 state.text <- Printf.sprintf
"bad time `%s': %s"
4388 v (Printexc.to_string exn
)
4390 src#
string "ghyll scroll"
4392 match conf.ghyllscroll
with
4394 | Some nab
-> ghyllscroll_to_string nab
4399 if String.length
v = 0
4401 else Some
(ghyllscroll_of_string v)
4403 conf.ghyllscroll
<- gs
4405 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4406 v (Printexc.to_string exn
)
4408 src#
string "selection command"
4409 (fun () -> conf.selcmd
)
4410 (fun v -> conf.selcmd
<- v);
4411 src#colorspace
"color space"
4412 (fun () -> colorspace_to_string conf.colorspace
)
4414 conf.colorspace
<- colorspace_of_int v;
4421 src#caption
"Document" 0;
4422 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4423 src#caption2
"Pages"
4424 (fun () -> string_of_int
state.pagecount
) 1;
4425 src#caption2
"Dimensions"
4426 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4430 src#caption
"Trimmed margins" 0;
4431 src#caption2
"Dimensions"
4432 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4435 src#reset prevmode prevuioh
;
4439 let prevmode = state.mode
4440 and prevuioh
= state.uioh in
4441 fillsrc prevmode prevuioh
;
4442 let source = (src :> lvsource
) in
4443 let modehash = findkeyhash conf "info" in
4444 state.uioh <- coe (object (self)
4445 inherit listview ~
source ~trusted
:true ~
modehash as super
4446 val mutable m_prevmemused
= 0
4447 method infochanged
= function
4449 if m_prevmemused
!= state.memused
4451 m_prevmemused
<- state.memused
;
4452 G.postRedisplay "memusedchanged";
4454 | Pdim
-> G.postRedisplay "pdimchanged"
4455 | Docinfo
-> fillsrc prevmode prevuioh
4457 method key key mask
=
4458 if not
(Wsi.withctrl mask
)
4461 | 0xff51 -> coe (self#updownlevel ~
-1)
4462 | 0xff53 -> coe (self#updownlevel
1)
4463 | _ -> super#
key key mask
4464 else super#
key key mask
4466 G.postRedisplay "info";
4472 inherit lvsourcebase
4473 method getitemcount
= Array.length
state.help
4475 let s, n, _ = state.help
.(n) in
4478 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4482 m_qsearch
<- qsearch;
4483 match state.help
.(active) with
4484 | _, _, Action
f -> Some
(f uioh)
4494 method hasaction
n =
4495 match state.help
.(n) with
4496 | _, _, Action
_ -> true
4503 let modehash = findkeyhash conf "help" in
4504 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4505 G.postRedisplay "help";
4510 let re = Str.regexp
"[\r\n]" in
4512 inherit lvsourcebase
4513 val mutable m_items
= [||]
4515 method getitemcount
= 1 + Array.length m_items
4520 else m_items
.(n-1), 0
4522 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4527 then Buffer.clear
state.errmsgs
;
4528 m_qsearch
<- qsearch;
4535 method hasaction
n =
4539 state.newerrmsgs
<- false;
4540 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4541 m_items
<- Array.of_list
l
4549 let source = (msgsource :> lvsource
) in
4550 let modehash = findkeyhash conf "listview" in
4551 state.uioh <- coe (object
4552 inherit listview ~
source ~trusted
:false ~
modehash as super
4555 then msgsource#reset
;
4558 G.postRedisplay "msgs";
4561 let quickbookmark ?title
() =
4562 match state.layout with
4568 let sec = Unix.gettimeofday
() in
4569 let tm = Unix.localtime
sec in
4570 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4574 (tm.Unix.tm_year
+ 1900)
4577 | Some
title -> title
4580 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4585 state.fullscreen
<- None
;
4589 let setautoscrollspeed step goingdown
=
4590 let incr = max
1 ((abs step
) / 2) in
4591 let incr = if goingdown
then incr else -incr in
4592 let astep = step
+ incr in
4593 state.autoscroll
<- Some
astep;
4596 let gotounder = function
4597 | Ulinkgoto
(pageno, top) ->
4601 gotopage1 pageno top;
4607 | Uremote
(filename
, pageno) ->
4609 if Sys.file_exists filename
4612 let dir = Filename.dirname
state.path in
4613 let path = Filename.concat
dir filename
in
4614 if Sys.file_exists
path
4618 if String.length
path > 0
4620 let anchor = getanchor () in
4621 let ranchor = state.path, state.password
, anchor in
4622 state.anchor <- (pageno, 0.0);
4623 state.ranchors
<- ranchor :: state.ranchors
;
4626 else showtext '
!'
("Could not find " ^ filename
)
4628 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4632 match conf.columns
with
4634 | _ -> conf.zoom > 1.0
4637 let viewkeyboard key mask
=
4639 let mode = state.mode in
4640 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4643 G.postRedisplay "view:enttext"
4645 let ctrl = Wsi.withctrl mask
in
4650 | 0xff63 -> (* insert *)
4651 if conf.angle
mod 360 = 0
4653 state.mode <- LinkNav
(Ltgendir
0);
4656 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4658 | 0xff1b | 113 -> (* escape / q *)
4659 begin match state.mstate
with
4661 state.mstate
<- Mnone
;
4662 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4663 G.postRedisplay "kill zoom rect";
4665 match state.ranchors
with
4667 | (path, password
, anchor) :: rest
->
4668 state.ranchors
<- rest
;
4669 state.anchor <- anchor;
4670 opendoc path password
4673 | 0xff08 -> (* backspace *)
4674 let y = getnav ~
-1 in
4675 gotoy_and_clear_text y
4683 G.postRedisplay "dehighlight";
4685 | 47 | 63 -> (* / ? *)
4686 let ondone isforw
s =
4687 cbput state.hists
.pat
s;
4688 state.searchpattern
<- s;
4691 let s = String.create
1 in
4692 s.[0] <- Char.chr
key;
4693 enttext (s, "", Some
(onhist state.hists
.pat
),
4694 textentry, ondone (key = 47))
4696 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4697 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4698 setzoom (conf.zoom +. incr)
4700 | 43 | 0xffab -> (* + *)
4703 try int_of_string
s with exc
->
4704 state.text <- Printf.sprintf
"bad integer `%s': %s"
4705 s (Printexc.to_string exc
);
4711 state.text <- "page bias is now " ^ string_of_int
n;
4714 enttext ("page bias: ", "", None
, intentry, ondone)
4716 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4717 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4718 setzoom (max
0.01 (conf.zoom -. decr))
4720 | 45 | 0xffad -> (* - *)
4721 let ondone msg
= state.text <- msg
in
4723 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4724 optentry state.mode, ondone
4727 | 48 when ctrl -> (* ctrl-0 *)
4730 | 49 when ctrl -> (* 1 *)
4731 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4735 | 0xffc6 -> (* f9 *)
4738 | 57 when ctrl -> (* ctrl-9 *)
4741 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4742 when not
ctrl -> (* 0..9 *)
4745 try int_of_string
s with exc
->
4746 state.text <- Printf.sprintf
"bad integer `%s': %s"
4747 s (Printexc.to_string exc
);
4753 cbput state.hists
.pag
(string_of_int
n);
4754 gotopage1 (n + conf.pagebias
- 1) 0;
4757 let pageentry text key =
4758 match Char.unsafe_chr
key with
4759 | 'g'
-> TEdone
text
4760 | _ -> intentry text key
4762 let text = "x" in text.[0] <- Char.chr
key;
4763 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4766 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4767 reshape conf.winw
conf.winh
;
4770 conf.hlinks
<- not
conf.hlinks
;
4771 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4772 G.postRedisplay "toggle highlightlinks";
4775 state.glinks
<- true;
4776 let mode = state.mode in
4777 state.mode <- Textentry
(
4778 (":", "", None
, linknentry, linkndone (fun under ->
4783 state.glinks
<- false;
4787 G.postRedisplay "view:linkent(F)"
4790 state.glinks
<- true;
4791 let mode = state.mode in
4792 state.mode <- Textentry
(
4793 (":", "", None
, linknentry, linkndone (fun under ->
4794 match Ne.pipe () with
4796 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4797 (Printexc.to_string exn
));
4800 try popen conf.selcmd
[r, 0; w, -1]; true
4803 (Printf.sprintf
"failed to execute %s: %s"
4804 conf.selcmd
(Printexc.to_string exn
));
4808 Ne.clo fd
(fun msg
->
4809 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4812 let s = undertext under in
4816 let l = String.length
s in
4817 let n = Unix.write
w s 0 l in
4822 "failed to write %d characters to sel pipe, wrote %d"
4827 (Printf.sprintf
"failed to write to sel pipe: %s"
4828 (Printexc.to_string exn
)
4837 state.glinks
<- false;
4841 G.postRedisplay "view:linkent"
4844 begin match state.autoscroll
with
4846 conf.autoscrollstep
<- step
;
4847 state.autoscroll
<- None
4849 if conf.autoscrollstep
= 0
4850 then state.autoscroll
<- Some
1
4851 else state.autoscroll
<- Some
conf.autoscrollstep
4854 | 112 when ctrl -> (* ctrl-p *)
4858 conf.presentation <- not
conf.presentation;
4859 if conf.presentation
4861 if not
conf.scrollbarinpm
4862 then state.scrollw
<- 0;
4865 state.scrollw
<- conf.scrollbw
;
4867 showtext ' '
("presentation mode " ^
4868 if conf.presentation then "on" else "off");
4869 state.anchor <- getanchor ();
4873 begin match state.fullscreen
with
4875 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4878 state.fullscreen
<- None
;
4883 gotoy_and_clear_text 0
4886 gotopage1 (state.pagecount
- 1) 0
4888 | 112 | 78 -> (* p|N *)
4889 search state.searchpattern
false
4891 | 110 | 0xffc0 -> (* n|F3 *)
4892 search state.searchpattern
true
4895 begin match state.layout with
4898 gotoy_and_clear_text (getpagey l.pageno)
4902 begin match List.rev
state.layout with
4905 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4906 gotoy_and_clear_text (getpagey pageno)
4909 | 0xff9f | 0xffff -> (* delete *)
4910 begin match state.layout with
4913 let pageno = max
0 (l.pageno-1) in
4914 gotoy_and_clear_text (getpagey pageno)
4918 showtext ' '
(describe_location ());
4921 begin match state.layout with
4924 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4929 enterbookmarkmode ()
4931 | 104 | 0xffbe -> (* h|F1 *)
4937 | 101 when conf.redirectstderr -> (* e *)
4942 match state.layout with
4945 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4949 enttext ("bookmark: ", "", None
, textentry, ondone)
4953 showtext ' '
"Quick bookmark added";
4956 begin match state.layout with
4958 let rect = getpdimrect
l.pagedimno
in
4962 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4963 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4965 (truncate
(rect.(1) -. rect.(0)),
4966 truncate
(rect.(3) -. rect.(0)))
4968 let w = truncate
((float w)*.conf.zoom)
4969 and h = truncate
((float h)*.conf.zoom) in
4972 state.anchor <- getanchor ();
4973 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4975 G.postRedisplay "z";
4980 | 50 when ctrl -> (* ctrl-2 *)
4981 let maxw = getmaxw
() in
4983 then setzoom (maxw /. float conf.winw
)
4985 | 60 | 62 -> (* < > *)
4986 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4988 | 91 | 93 -> (* [ ] *)
4990 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4992 G.postRedisplay "brightness";
4994 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4995 setzoom state.prevzoom
4997 | 107 | 0xff52 -> (* k up *)
4998 begin match state.autoscroll
with
5000 begin match state.mode with
5001 | Birdseye beye
-> upbirdseye 1 beye
5004 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5005 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5008 setautoscrollspeed n false
5011 | 106 | 0xff54 -> (* j down *)
5012 begin match state.autoscroll
with
5014 begin match state.mode with
5015 | Birdseye beye
-> downbirdseye 1 beye
5018 then gotoy_and_clear_text (clamp (conf.winh
/2))
5019 else gotoy_and_clear_text (clamp conf.scrollstep
)
5022 setautoscrollspeed n true
5025 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5033 let dx = if key = 0xff51 then dx else -dx in
5034 state.x <- state.x + dx;
5035 gotoy_and_clear_text state.y
5038 G.postRedisplay "lef/right"
5041 | 0xff55 -> (* prior *)
5045 match state.layout with
5047 | l :: _ -> state.y - l.pagey
5053 | 0xff56 -> (* next *)
5057 match List.rev
state.layout with
5059 | l :: _ -> getpagey l.pageno
5065 | 0xff50 -> gotoghyll 0
5066 | 0xff57 -> gotoghyll (clamp state.maxy)
5067 | 0xff53 when Wsi.withalt mask
->
5068 gotoghyll (getnav ~
-1)
5069 | 0xff51 when Wsi.withalt mask
->
5070 gotoghyll (getnav 1)
5073 state.anchor <- getanchor ();
5074 opendoc state.path state.password
5076 | 118 when conf.debug
-> (* v *)
5079 match getopaque l.pageno with
5082 let x0, y0, x1, y1 = pagebbox opaque
in
5083 let a,b = float x0, float y0 in
5084 let c,d = float x1, float y0 in
5085 let e,f = float x1, float y1 in
5086 let h,j
= float x0, float y1 in
5087 let rect = (a,b,c,d,e,f,h,j
) in
5089 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5091 G.postRedisplay "v";
5094 vlog "huh? %s" (Wsi.keyname
key)
5097 let linknavkeyboard key mask
linknav =
5098 let getpage pageno =
5099 let rec loop = function
5101 | l :: _ when l.pageno = pageno -> Some
l
5102 | _ :: rest
-> loop rest
5103 in loop state.layout
5105 let doexact (pageno, n) =
5106 match getopaque pageno, getpage pageno with
5107 | Some opaque
, Some
l ->
5110 let under = getlink opaque
n in
5111 G.postRedisplay "link gotounder";
5117 | 0xff50 -> (* home *)
5118 Some
(findlink opaque LDfirst
), -1
5120 | 0xff57 -> (* end *)
5121 Some
(findlink opaque LDlast
), 1
5123 | 0xff51 -> (* left *)
5124 Some
(findlink opaque
(LDleft
n)), -1
5126 | 0xff53 -> (* right *)
5127 Some
(findlink opaque
(LDright
n)), 1
5129 | 0xff52 -> (* up *)
5130 Some
(findlink opaque
(LDup
n)), -1
5132 | 0xff54 -> (* down *)
5133 Some
(findlink opaque
(LDdown
n)), 1
5138 begin match findpwl
l.pageno dir with
5142 state.mode <- LinkNav
(Ltgendir
dir);
5143 let y, h = getpageyh pageno in
5146 then y + h - conf.winh
5151 begin match getopaque pageno, getpage pageno with
5152 | Some opaque
, Some
_ ->
5154 let ld = if dir > 0 then LDfirst
else LDlast
in
5157 begin match link with
5159 showlinktype (getlink opaque
m);
5160 state.mode <- LinkNav
(Ltexact
(pageno, m));
5161 G.postRedisplay "linknav jpage";
5168 begin match opt with
5169 | Some Lnotfound
-> pwl l dir;
5170 | Some
(Lfound
m) ->
5174 let _, y0, _, y1 = getlinkrect opaque
m in
5176 then gotopage1 l.pageno y0
5178 let d = fstate.fontsize
+ 1 in
5179 if y1 - l.pagey > l.pagevh - d
5180 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5181 else G.postRedisplay "linknav";
5183 showlinktype (getlink opaque
m);
5184 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5187 | None
-> viewkeyboard key mask
5189 | _ -> viewkeyboard key mask
5194 G.postRedisplay "leave linknav"
5198 | Ltgendir
_ -> viewkeyboard key mask
5199 | Ltexact exact
-> doexact exact
5202 let keyboard key mask
=
5203 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5204 then wcmd "interrupt"
5205 else state.uioh <- state.uioh#
key key mask
5208 let birdseyekeyboard key mask
5209 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5211 match conf.columns
with
5213 | Cmulti
((c, _, _), _) -> c
5214 | Csplit
_ -> failwith
"bird's eye split mode"
5217 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5218 let y, h = getpageyh pageno in
5219 let top = (conf.winh
- h) / 2 in
5220 gotoy (max
0 (y - top))
5221 | 0xff0d -> leavebirdseye beye
false
5222 | 0xff1b -> leavebirdseye beye
true (* escape *)
5223 | 0xff52 -> upbirdseye incr beye
(* prior *)
5224 | 0xff54 -> downbirdseye incr beye
(* next *)
5225 | 0xff51 -> upbirdseye 1 beye
(* up *)
5226 | 0xff53 -> downbirdseye 1 beye
(* down *)
5229 begin match state.layout with
5233 state.mode <- Birdseye
(
5234 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5236 gotopage1 l.pageno 0;
5239 let layout = layout (state.y-conf.winh
) conf.winh
in
5241 | [] -> gotoy (clamp (-conf.winh
))
5243 state.mode <- Birdseye
(
5244 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5246 gotopage1 l.pageno 0
5249 | [] -> gotoy (clamp (-conf.winh
))
5253 begin match List.rev
state.layout with
5255 let layout = layout (state.y + conf.winh
) conf.winh
in
5256 begin match layout with
5258 let incr = l.pageh
- l.pagevh in
5263 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5265 G.postRedisplay "birdseye pagedown";
5267 else gotoy (clamp (incr + conf.interpagespace*2));
5271 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5272 gotopage1 l.pageno 0;
5275 | [] -> gotoy (clamp conf.winh
)
5279 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5283 let pageno = state.pagecount
- 1 in
5284 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5285 if not
(pagevisible state.layout pageno)
5288 match List.rev
state.pdims
with
5290 | (_, _, h, _) :: _ -> h
5292 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5293 else G.postRedisplay "birdseye end";
5294 | _ -> viewkeyboard key mask
5297 let drawpage l linkindexbase
=
5299 match state.mode with
5300 | Textentry
_ -> scalecolor 0.4
5302 | View
-> scalecolor 1.0
5303 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5304 if l.pageno = hooverpageno
5307 if l.pageno = pageno
5313 begin match getopaque l.pageno with
5315 if tileready l l.pagex l.pagey
5317 let x = l.pagedispx - l.pagex
5318 and y = l.pagedispy - l.pagey in
5319 let hlmask = (if conf.hlinks
then 1 else 0)
5320 + (if state.glinks
&& not
(isbirdseye state.mode) then 2 else 0)
5323 match state.mode with
5324 | Textentry
((_, s, _, _, _), _) when state.glinks
-> s
5327 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5334 let scrollindicator () =
5335 let sbw, ph
, sh = state.uioh#
scrollph in
5336 let sbh, pw, sw = state.uioh#scrollpw
in
5338 GlDraw.color (0.64, 0.64, 0.64);
5340 (float (conf.winw
- sbw), 0.)
5341 (float conf.winw
, float conf.winh
)
5344 (0., float (conf.winh
- sbh))
5345 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5347 GlDraw.color (0.0, 0.0, 0.0);
5350 (float (conf.winw
- sbw), ph
)
5351 (float conf.winw
, ph
+. sh)
5354 (pw, float (conf.winh
- sbh))
5355 (pw +. sw, float conf.winh
)
5360 match state.mstate
with
5361 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5364 | Msel
((x0, y0), (x1, y1)) ->
5365 let rec loop = function
5367 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5368 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5369 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5370 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5372 match getopaque l.pageno with
5374 let x0, y0 = pagetranslatepoint l x0 y0 in
5375 let x1, y1 = pagetranslatepoint l x1 y1 in
5376 seltext opaque
(x0, y0, x1, y1);
5384 let showrects rects
=
5386 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5387 GlDraw.polygon_mode `both `fill
;
5388 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5390 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5392 if l.pageno = pageno
5394 let dx = float (l.pagedispx - l.pagex) in
5395 let dy = float (l.pagedispy - l.pagey) in
5396 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5397 GlDraw.begins `quads
;
5399 GlDraw.vertex2
(x0+.dx, y0+.dy);
5400 GlDraw.vertex2
(x1+.dx, y1+.dy);
5401 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5402 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5413 GlClear.color (scalecolor2 conf.bgcolor
);
5414 GlClear.clear
[`
color];
5415 let rec loop linkindexbase
= function
5417 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5418 loop linkindexbase rest
5421 loop 0 state.layout;
5423 match state.mode with
5424 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5425 begin match getopaque pageno with
5427 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5434 | None
-> state.rects
5441 begin match state.mstate
with
5442 | Mzoomrect
((x0, y0), (x1, y1)) ->
5444 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5445 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5446 GlDraw.rect (float x0, float y0)
5447 (float x1, float y1);
5456 let zoomrect x y x1 y1 =
5459 and y0 = min
y y1 in
5460 gotoy (state.y + y0);
5461 state.anchor <- getanchor ();
5462 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5464 if state.w < conf.winw
- state.scrollw
5465 then (conf.winw
- state.scrollw
- state.w) / 2
5468 state.x <- (state.x + margin) - x0;
5470 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5471 state.mstate
<- Mnone
;
5475 let winw = conf.winw - state.scrollw
- 1 in
5476 let s = float x /. float winw in
5477 let destx = truncate
(float (state.w + winw) *. s) in
5478 state.x <- winw - destx;
5479 gotoy_and_clear_text state.y;
5480 state.mstate
<- Mscrollx
;
5484 let s = float y /. float conf.winh
in
5485 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5486 gotoy_and_clear_text desty;
5487 state.mstate
<- Mscrolly
;
5490 let viewmouse button down
x y mask
=
5492 | n when (n == 4 || n == 5) && not down
->
5493 if Wsi.withctrl mask
5495 match state.mstate
with
5496 | Mzoom
(oldn
, i
) ->
5504 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5506 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5508 let zoom = conf.zoom -. incr in
5510 state.mstate
<- Mzoom
(n, 0);
5512 state.mstate
<- Mzoom
(n, i
+1);
5514 else state.mstate
<- Mzoom
(n, 0)
5516 | _ -> state.mstate
<- Mzoom
(n, 0)
5519 match state.autoscroll
with
5520 | Some step
-> setautoscrollspeed step
(n=4)
5524 then -conf.scrollstep
5525 else conf.scrollstep
5527 let incr = incr * 2 in
5528 let y = clamp incr in
5529 gotoy_and_clear_text y
5532 | 1 when Wsi.withctrl mask
->
5535 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5536 state.mstate
<- Mpan
(x, y)
5539 state.mstate
<- Mnone
5544 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5546 state.mstate
<- Mzoomrect
(p, p)
5549 match state.mstate
with
5550 | Mzoomrect
((x0, y0), _) ->
5551 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5552 then zoomrect x0 y0 x y
5554 state.mstate
<- Mnone
;
5555 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5556 G.postRedisplay "kill accidental zoom rect";
5559 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5560 state.mstate
<- Mnone
5563 | 1 when x > conf.winw - state.scrollw
->
5566 let _, position, sh = state.uioh#
scrollph in
5567 if y > truncate
position && y < truncate
(position +. sh)
5568 then state.mstate
<- Mscrolly
5571 state.mstate
<- Mnone
5573 | 1 when y > conf.winh
- state.hscrollh ->
5576 let _, position, sw = state.uioh#scrollpw
in
5577 if x > truncate
position && x < truncate
(position +. sw)
5578 then state.mstate
<- Mscrollx
5581 state.mstate
<- Mnone
5584 let dest = if down
then getunder x y else Unone
in
5585 begin match dest with
5589 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5592 | Unone
when down
->
5593 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5594 state.mstate
<- Mpan
(x, y);
5596 | Unone
| Utext
_ ->
5599 if conf.angle
mod 360 = 0
5601 state.mstate
<- Msel
((x, y), (x, y));
5602 G.postRedisplay "mouse select";
5606 match state.mstate
with
5609 | Mzoom
_ | Mscrollx
| Mscrolly
->
5610 state.mstate
<- Mnone
5612 | Mzoomrect
((x0, y0), _) ->
5616 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5617 state.mstate
<- Mnone
5619 | Msel
((_, y0), (_, y1)) ->
5620 let rec loop = function
5623 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5624 || ((y1 >= l.pagedispy
5625 && y1 <= (l.pagedispy + l.pagevh)))
5627 match getopaque l.pageno with
5630 match Ne.pipe () with
5634 "can not create sel pipe: %s"
5635 (Printexc.to_string exn
));
5637 let doclose what fd
=
5638 Ne.clo fd
(fun msg
->
5639 dolog "%s close failed: %s" what msg
)
5642 popen conf.selcmd
[r, 0; w, -1];
5645 G.postRedisplay "copysel";
5647 dolog "can not exectute %S: %s"
5648 conf.selcmd
(Printexc.to_string exn
);
5656 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5657 state.mstate
<- Mnone
;
5664 let birdseyemouse button down
x y mask
5665 (conf, leftx
, _, hooverpageno
, anchor) =
5668 let rec loop = function
5671 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5672 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5674 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5680 | _ -> viewmouse button down
x y mask
5683 let mouse button down
x y mask
=
5684 state.uioh <- state.uioh#button button down
x y mask
;
5688 state.uioh <- state.uioh#
motion x y
5692 state.uioh <- state.uioh#
pmotion x y;
5698 method key key mask
=
5699 begin match state.mode with
5700 | Textentry
textentry -> textentrykeyboard key mask
textentry
5701 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5702 | View
-> viewkeyboard key mask
5703 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5707 method button button bstate
x y mask
=
5708 begin match state.mode with
5710 | View
-> viewmouse button bstate
x y mask
5711 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5717 begin match state.mode with
5719 | View
| Birdseye
_ | LinkNav
_ ->
5720 match state.mstate
with
5721 | Mzoom
_ | Mnone
-> ()
5726 state.mstate
<- Mpan
(x, y);
5728 then state.x <- state.x + dx;
5730 gotoy_and_clear_text y
5733 state.mstate
<- Msel
(a, (x, y));
5734 G.postRedisplay "motion select";
5737 let y = min
conf.winh
(max
0 y) in
5741 let x = min
conf.winw (max
0 x) in
5744 | Mzoomrect
(p0
, _) ->
5745 state.mstate
<- Mzoomrect
(p0
, (x, y));
5746 G.postRedisplay "motion zoomrect";
5750 method pmotion x y =
5751 begin match state.mode with
5752 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5753 let rec loop = function
5755 if hooverpageno
!= -1
5757 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5758 G.postRedisplay "pmotion birdseye no hoover";
5761 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5762 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5764 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5765 G.postRedisplay "pmotion birdseye hoover";
5775 match state.mstate
with
5776 | Mnone
-> updateunder x y
5777 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5782 method infochanged
_ = ()
5785 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5786 let p, h = scrollph state.y maxy in
5790 let winw = conf.winw - state.scrollw
- 1 in
5791 let fwinw = float winw in
5793 let sw = fwinw /. float state.w in
5794 let sw = fwinw *. sw in
5795 max
sw (float conf.scrollh
)
5798 let f = state.w+winw in
5799 let r = float (winw-state.x) /. float f in
5800 let p = fwinw *. r in
5804 if position +. sw > fwinw
5805 then fwinw -. position
5808 state.hscrollh, position, sw
5812 match state.mode with
5813 | LinkNav
_ -> "links"
5814 | Textentry
_ -> "textentry"
5815 | Birdseye
_ -> "birdseye"
5818 findkeyhash conf modename
5825 let fontpath = ref "";;
5828 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5831 let l = String.length
s in
5832 let b = Buffer.create
l in
5838 try Sys.getenv
"HOME"
5841 ("Can not determine home directory location: " ^
5842 Printexc.to_string exn
);
5846 let modifier_of_string = function
5847 | "alt" -> Wsi.altmask
5848 | "shift" -> Wsi.shiftmask
5849 | "ctrl" | "control" -> Wsi.ctrlmask
5850 | "meta" -> Wsi.metamask
5855 let r = Str.regexp
"-" in
5857 let elems = Str.full_split
r s in
5860 let m1 = modifier_of_string s in
5862 then (Wsi.namekey
s, m)
5865 | Str.Delim
s when n land 1 = 0 -> g s
5867 | Str.Delim
_ -> (k
, m)
5869 let rec loop n k
m = function
5872 let k, m = f n k m x in
5878 let keys_of_string =
5879 let r = Str.regexp
"[ \t]" in
5881 let elems = Str.split
r s in
5882 List.map
key_of_string elems
5885 let copykeyhashes c =
5886 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5889 let config_of c attrs
=
5893 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5894 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5895 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5896 | "preload" -> { c with preload = bool_of_string
v }
5897 | "page-bias" -> { c with pagebias
= int_of_string
v }
5898 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5899 | "auto-scroll-step" ->
5900 { c with autoscrollstep
= max
0 (int_of_string
v) }
5901 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5902 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5905 match String.lowercase
v with
5906 | "true" -> Some infinity
5908 | f -> Some
(float_of_string
f)
5910 { c with maxwait
= mw}
5911 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5912 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5913 | "vertical-margin" ->
5914 { c with interpagespace = max
0 (int_of_string
v) }
5916 let zoom = float_of_string
v /. 100. in
5917 let zoom = max
zoom 0.0 in
5918 { c with zoom = zoom }
5919 | "presentation" -> { c with presentation = bool_of_string
v }
5920 | "rotation-angle" -> { c with angle
= int_of_string
v }
5921 | "width" -> { c with winw = max
20 (int_of_string
v) }
5922 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5923 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5924 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5925 | "pixmap-cache-size" ->
5926 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5927 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5928 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5929 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5930 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5931 | "background-color" -> { c with bgcolor
= color_of_string v }
5932 | "scrollbar-in-presentation" ->
5933 { c with scrollbarinpm
= bool_of_string
v }
5934 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5935 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5936 | "mupdf-store-size" ->
5937 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5938 | "checkers" -> { c with checkers
= bool_of_string
v }
5939 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5940 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5941 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5942 | "uri-launcher" -> { c with urilauncher
= unent v }
5943 | "path-launcher" -> { c with pathlauncher
= unent v }
5944 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5945 | "invert-colors" -> { c with invert
= bool_of_string
v }
5946 | "brightness" -> { c with colorscale
= float_of_string
v }
5947 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5949 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5951 let (n, _, _) as nab
= multicolumns_of_string v in
5953 then { c with columns
= Csplit
(-n, [||]) }
5954 else { c with columns
= Cmulti
(nab
, [||]) }
5955 | "birds-eye-columns" ->
5956 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5957 | "selection-command" -> { c with selcmd
= unent v }
5958 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5959 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
5962 prerr_endline
("Error processing attribute (`" ^
5963 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5966 let rec fold c = function
5969 let c = apply c k v in
5972 fold { c with keyhashes
= copykeyhashes c } attrs
;
5975 let fromstring f pos
n v d =
5978 dolog "Error processing attribute (%S=%S) at %d\n%s"
5979 n v pos
(Printexc.to_string exn
)
5984 let bookmark_of attrs
=
5985 let rec fold title page
rely = function
5986 | ("title", v) :: rest
-> fold v page
rely rest
5987 | ("page", v) :: rest
-> fold title v rely rest
5988 | ("rely", v) :: rest
-> fold title page
v rest
5989 | _ :: rest
-> fold title page
rely rest
5990 | [] -> title, page
, rely
5992 fold "invalid" "0" "0" attrs
5996 let rec fold path page
rely pan
= function
5997 | ("path", v) :: rest
-> fold v page
rely pan rest
5998 | ("page", v) :: rest
-> fold path v rely pan rest
5999 | ("rely", v) :: rest
-> fold path page
v pan rest
6000 | ("pan", v) :: rest
-> fold path page
rely v rest
6001 | _ :: rest
-> fold path page
rely pan rest
6002 | [] -> path, page
, rely, pan
6004 fold "" "0" "0" "0" attrs
6008 let rec fold rs ls
= function
6009 | ("out", v) :: rest
-> fold v ls rest
6010 | ("in", v) :: rest
-> fold rs
v rest
6011 | _ :: rest
-> fold ls rs rest
6017 let setconf dst
src =
6018 dst
.scrollbw
<- src.scrollbw
;
6019 dst
.scrollh
<- src.scrollh
;
6020 dst
.icase
<- src.icase
;
6021 dst
.preload <- src.preload;
6022 dst
.pagebias
<- src.pagebias
;
6023 dst
.verbose
<- src.verbose
;
6024 dst
.scrollstep
<- src.scrollstep
;
6025 dst
.maxhfit
<- src.maxhfit
;
6026 dst
.crophack
<- src.crophack
;
6027 dst
.autoscrollstep
<- src.autoscrollstep
;
6028 dst
.maxwait
<- src.maxwait
;
6029 dst
.hlinks
<- src.hlinks
;
6030 dst
.underinfo
<- src.underinfo
;
6031 dst
.interpagespace <- src.interpagespace;
6032 dst
.zoom <- src.zoom;
6033 dst
.presentation <- src.presentation;
6034 dst
.angle
<- src.angle
;
6035 dst
.winw <- src.winw;
6036 dst
.winh
<- src.winh
;
6037 dst
.savebmarks
<- src.savebmarks
;
6038 dst
.memlimit
<- src.memlimit
;
6039 dst
.proportional
<- src.proportional
;
6040 dst
.texcount
<- src.texcount
;
6041 dst
.sliceheight
<- src.sliceheight
;
6042 dst
.thumbw
<- src.thumbw
;
6043 dst
.jumpback
<- src.jumpback
;
6044 dst
.bgcolor
<- src.bgcolor
;
6045 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6046 dst
.tilew
<- src.tilew
;
6047 dst
.tileh
<- src.tileh
;
6048 dst
.mustoresize
<- src.mustoresize
;
6049 dst
.checkers
<- src.checkers
;
6050 dst
.aalevel
<- src.aalevel
;
6051 dst
.trimmargins
<- src.trimmargins
;
6052 dst
.trimfuzz
<- src.trimfuzz
;
6053 dst
.urilauncher
<- src.urilauncher
;
6054 dst
.colorspace
<- src.colorspace
;
6055 dst
.invert
<- src.invert
;
6056 dst
.colorscale
<- src.colorscale
;
6057 dst
.redirectstderr <- src.redirectstderr;
6058 dst
.ghyllscroll
<- src.ghyllscroll
;
6059 dst
.columns
<- src.columns
;
6060 dst
.beyecolumns
<- src.beyecolumns
;
6061 dst
.selcmd
<- src.selcmd
;
6062 dst
.updatecurs
<- src.updatecurs
;
6063 dst
.pathlauncher
<- src.pathlauncher
;
6064 dst
.keyhashes
<- copykeyhashes src;
6065 dst
.hfsize
<- src.hfsize
;
6069 let h = Hashtbl.create
10 in
6070 let dc = { defconf with angle
= defconf.angle
} in
6071 let rec toplevel v t spos
_ =
6073 | Vdata
| Vcdata
| Vend
-> v
6074 | Vopen
("llppconfig", _, closed
) ->
6077 else { v with f = llppconfig
}
6079 error
"unexpected subelement at top level" s spos
6080 | Vclose
_ -> error
"unexpected close at top level" s spos
6082 and llppconfig
v t spos
_ =
6084 | Vdata
| Vcdata
-> v
6085 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6086 | Vopen
("defaults", attrs
, closed
) ->
6087 let c = config_of dc attrs
in
6091 else { v with f = defaults
}
6093 | Vopen
("ui-font", attrs
, closed
) ->
6094 let rec getsize size
= function
6096 | ("size", v) :: rest
->
6098 fromstring int_of_string spos
"size" v fstate.fontsize
in
6100 | l -> getsize size l
6102 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6105 else { v with f = uifont
(Buffer.create
10) }
6107 | Vopen
("doc", attrs
, closed
) ->
6108 let pathent, spage
, srely
, span
= doc_of attrs
in
6109 let path = unent pathent
6110 and pageno = fromstring int_of_string spos
"page" spage
0
6111 and rely = fromstring float_of_string spos
"rely" srely
0.0
6112 and pan
= fromstring int_of_string spos
"pan" span
0 in
6113 let c = config_of dc attrs
in
6114 let anchor = (pageno, rely) in
6116 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6117 else { v with f = doc
path pan
anchor c [] }
6120 error
"unexpected subelement in llppconfig" s spos
6122 | Vclose
"llppconfig" -> { v with f = toplevel }
6123 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6125 and defaults
v t spos
_ =
6127 | Vdata
| Vcdata
-> v
6128 | Vend
-> error
"unexpected end of input in defaults" s spos
6129 | Vopen
("keymap", attrs
, closed
) ->
6131 try List.assoc
"mode" attrs
6132 with Not_found
-> "global" in
6137 let h = findkeyhash dc modename in
6138 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6141 { v with f = pkeymap
ret KeyMap.empty }
6143 | Vopen
(_, _, _) ->
6144 error
"unexpected subelement in defaults" s spos
6146 | Vclose
"defaults" ->
6147 { v with f = llppconfig
}
6149 | Vclose
_ -> error
"unexpected close in defaults" s spos
6151 and uifont
b v t spos
epos =
6154 Buffer.add_substring
b s spos
(epos - spos
);
6156 | Vopen
(_, _, _) ->
6157 error
"unexpected subelement in ui-font" s spos
6158 | Vclose
"ui-font" ->
6159 if String.length
!fontpath = 0
6160 then fontpath := Buffer.contents
b;
6161 { v with f = llppconfig
}
6162 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6163 | Vend
-> error
"unexpected end of input in ui-font" s spos
6165 and doc
path pan
anchor c bookmarks
v t spos
_ =
6167 | Vdata
| Vcdata
-> v
6168 | Vend
-> error
"unexpected end of input in doc" s spos
6169 | Vopen
("bookmarks", _, closed
) ->
6172 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6174 | Vopen
("keymap", attrs
, closed
) ->
6176 try List.assoc
"mode" attrs
6177 with Not_found
-> "global"
6183 let h = findkeyhash c modename in
6184 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6185 doc
path pan
anchor c bookmarks
6187 { v with f = pkeymap
ret KeyMap.empty }
6189 | Vopen
(_, _, _) ->
6190 error
"unexpected subelement in doc" s spos
6193 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6194 { v with f = llppconfig
}
6196 | Vclose
_ -> error
"unexpected close in doc" s spos
6198 and pkeymap
ret keymap
v t spos
_ =
6200 | Vdata
| Vcdata
-> v
6201 | Vend
-> error
"unexpected end of input in keymap" s spos
6202 | Vopen
("map", attrs
, closed
) ->
6203 let r, l = map_of attrs
in
6204 let kss = fromstring keys_of_string spos
"in" r [] in
6205 let lss = fromstring keys_of_string spos
"out" l [] in
6209 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6210 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6213 then { v with f = pkeymap
ret keymap }
6216 { v with f = skip
"map" f }
6219 error
"unexpected subelement in keymap" s spos
6221 | Vclose
"keymap" ->
6222 { v with f = ret keymap }
6224 | Vclose
_ -> error
"unexpected close in keymap" s spos
6226 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6228 | Vdata
| Vcdata
-> v
6229 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6230 | Vopen
("item", attrs
, closed
) ->
6231 let titleent, spage
, srely
= bookmark_of attrs
in
6232 let page = fromstring int_of_string spos
"page" spage
0
6233 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6234 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6236 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6239 { v with f = skip
"item" f }
6242 error
"unexpected subelement in bookmarks" s spos
6244 | Vclose
"bookmarks" ->
6245 { v with f = doc
path pan
anchor c bookmarks }
6247 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6249 and skip tag
f v t spos
_ =
6251 | Vdata
| Vcdata
-> v
6253 error
("unexpected end of input in skipped " ^ tag
) s spos
6254 | Vopen
(tag'
, _, closed
) ->
6258 let f'
() = { v with f = skip tag
f } in
6259 { v with f = skip tag'
f'
}
6263 else error
("unexpected close in skipped " ^ tag
) s spos
6266 parse
{ f = toplevel; accu = () } s;
6272 let len = in_channel_length ic
in
6273 let s = String.create
len in
6274 really_input ic
s 0 len;
6277 | Parse_error
(msg
, s, pos
) ->
6278 let subs = subs s pos
in
6279 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6280 failwith
("parse error: " ^
s)
6283 failwith
("config load error: " ^
Printexc.to_string exn
)
6289 let dir = Filename.concat
home ".config" in
6290 if Sys.is_directory
dir then dir else home
6293 Filename.concat
dir "llpp.conf"
6296 let confpath = ref defconfpath;;
6299 if Sys.file_exists
!confpath
6302 (try Some
(open_in_bin
!confpath)
6305 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6306 Printexc.to_string exn
);
6315 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6316 Printexc.to_string exn
);
6322 f (Hashtbl.create
0, defconf)
6327 let pc, pb
, px, pa
=
6329 Hashtbl.find h (Filename.basename
state.path)
6330 with Not_found
-> dc, [], 0, (0, 0.0)
6334 state.bookmarks <- pb
;
6336 state.scrollw
<- conf.scrollbw
;
6338 then state.anchor <- pa
;
6339 cbput state.hists
.nav pa
;
6344 let add_attrs bb always
dc c =
6347 then Printf.bprintf bb
"\n %s='%b'" s a
6350 then Printf.bprintf bb
"\n %s='%d'" s a
6353 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6356 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6359 then Printf.bprintf bb
"\n %s='%f'" s a
6363 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6367 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6371 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6375 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6381 | Some
(_N
, _A
, _B
) ->
6382 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6392 else string_of_float
f
6394 Printf.bprintf bb
"\n %s='%s'" s v
6399 | Cmulti
((n, a, b), _) when n > 1 ->
6400 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6401 | Csplit
(n, _) when n > 1 ->
6402 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6408 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6413 then dc.winw, dc.winh
6415 match state.fullscreen
with
6417 | None
-> c.winw, c.winh
6419 let zoom, presentation, interpagespace, maxwait
=
6421 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6423 match state.mode with
6424 | Birdseye
(bc
, _, _, _, _) ->
6425 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6426 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6428 oi
"width" w dc.winw;
6429 oi
"height" h dc.winh
;
6430 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6431 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6432 ob "case-insensitive-search" c.icase
dc.icase
;
6433 ob "preload" c.preload dc.preload;
6434 oi
"page-bias" c.pagebias
dc.pagebias
;
6435 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6436 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6437 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6438 ob "crop-hack" c.crophack
dc.crophack
;
6439 oW
"throttle" maxwait
dc.maxwait
;
6440 ob "highlight-links" c.hlinks
dc.hlinks
;
6441 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6442 oi
"vertical-margin" interpagespace dc.interpagespace;
6443 oz
"zoom" zoom dc.zoom;
6444 ob "presentation" presentation dc.presentation;
6445 oi
"rotation-angle" c.angle
dc.angle
;
6446 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6447 ob "proportional-display" c.proportional
dc.proportional
;
6448 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6449 oi
"tex-count" c.texcount
dc.texcount
;
6450 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6451 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6452 ob "persistent-location" c.jumpback
dc.jumpback
;
6453 oc
"background-color" c.bgcolor
dc.bgcolor
;
6454 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6455 oi
"tile-width" c.tilew
dc.tilew
;
6456 oi
"tile-height" c.tileh
dc.tileh
;
6457 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6458 ob "checkers" c.checkers
dc.checkers
;
6459 oi
"aalevel" c.aalevel
dc.aalevel
;
6460 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6461 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6462 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6463 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6464 oC
"color-space" c.colorspace
dc.colorspace
;
6465 ob "invert-colors" c.invert
dc.invert
;
6466 oF
"brightness" c.colorscale
dc.colorscale
;
6467 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6468 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6469 oco
"columns" c.columns
dc.columns
;
6470 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6471 os
"selection-command" c.selcmd
dc.selcmd
;
6472 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6473 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6476 let keymapsbuf always
dc c =
6477 let bb = Buffer.create
16 in
6478 let rec loop = function
6480 | (modename, h) :: rest
->
6481 let dh = findkeyhash dc modename in
6482 if always
|| h <> dh
6484 if Hashtbl.length
h > 0
6486 if Buffer.length
bb > 0
6487 then Buffer.add_char
bb '
\n'
;
6488 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6489 Hashtbl.iter
(fun i
o ->
6490 let isdifferent = always
||
6492 let dO = Hashtbl.find dh i
in
6494 with Not_found
-> true
6499 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6500 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6501 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6502 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6503 Buffer.add_string
bb (Wsi.keyname
k);
6506 let rec loop = function
6508 | km
:: [] -> addkm km
6509 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6513 Buffer.add_string
bb "<map in='";
6517 Buffer.add_string
bb "' out='";
6519 Buffer.add_string
bb "'/>\n"
6522 Buffer.add_string
bb "' out='";
6524 Buffer.add_string
bb "'/>\n"
6526 | KMmulti
(ins, kms
) ->
6527 Buffer.add_char
bb ' '
;
6529 Buffer.add_string
bb "' out='";
6531 Buffer.add_string
bb "'/>\n"
6533 Buffer.add_string
bb "</keymap>";
6543 let uifontsize = fstate.fontsize
in
6544 let bb = Buffer.create
32768 in
6546 let dc = if conf.bedefault
then conf else dc in
6547 Buffer.add_string
bb "<llppconfig>\n";
6549 if String.length
!fontpath > 0
6551 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6557 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6560 Buffer.add_string
bb "<defaults ";
6561 add_attrs bb true dc dc;
6562 let kb = keymapsbuf true dc dc in
6563 if Buffer.length
kb > 0
6565 Buffer.add_string
bb ">\n";
6566 Buffer.add_buffer
bb kb;
6567 Buffer.add_string
bb "\n</defaults>\n";
6569 else Buffer.add_string
bb "/>\n";
6571 let adddoc path pan
anchor c bookmarks =
6572 if bookmarks == [] && c = dc && anchor = emptyanchor
6575 Printf.bprintf
bb "<doc path='%s'"
6576 (enent
path 0 (String.length
path));
6578 if anchor <> emptyanchor
6580 let n, y = anchor in
6581 Printf.bprintf
bb " page='%d'" n;
6584 Printf.bprintf
bb " rely='%f'" y
6589 then Printf.bprintf
bb " pan='%d'" pan
;
6591 add_attrs bb false dc c;
6592 let kb = keymapsbuf false dc c in
6594 begin match bookmarks with
6596 if Buffer.length
kb > 0
6598 Buffer.add_string
bb ">\n";
6599 Buffer.add_buffer
bb kb;
6600 Buffer.add_string
bb "\n</doc>\n";
6602 else Buffer.add_string
bb "/>\n"
6604 Buffer.add_string
bb ">\n<bookmarks>\n";
6605 List.iter
(fun (title, _level
, (page, rely)) ->
6607 "<item title='%s' page='%d'"
6608 (enent
title 0 (String.length
title))
6613 Printf.bprintf
bb " rely='%f'" rely
6615 Buffer.add_string
bb "/>\n";
6617 Buffer.add_string
bb "</bookmarks>";
6618 if Buffer.length
kb > 0
6620 Buffer.add_string
bb "\n";
6621 Buffer.add_buffer
bb kb;
6623 Buffer.add_string
bb "\n</doc>\n";
6629 match state.mode with
6630 | Birdseye
(c, pan, _, _, _) ->
6632 match conf.columns
with
6633 | Cmulti
((c, _, _), _) -> Some
c
6637 match c.columns
with
6638 | Cmulti
(c, _) -> Cmulti
(c, [||])
6639 | Csingle
-> Csingle
6640 | Csplit
_ -> failwith
"quit from bird's eye while split"
6642 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6643 | _ -> state.x, conf
6645 let basename = Filename.basename state.path in
6646 adddoc basename pan (getanchor ())
6649 match state.autoscroll
with
6651 | None
-> conf.autoscrollstep
}
6652 (if conf.savebmarks
then state.bookmarks else []);
6654 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6656 then adddoc path x y c bookmarks
6658 Buffer.add_string
bb "</llppconfig>";
6661 if Buffer.length
bb > 0
6664 let tmp = !confpath ^
".tmp" in
6665 let oc = open_out_bin
tmp in
6666 Buffer.output_buffer
oc bb;
6668 Unix.rename
tmp !confpath;
6671 ("error while saving configuration: " ^
Printexc.to_string exn
)
6678 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6679 "<password> Set password");
6681 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6682 "<path> Set path to the user interface font");
6684 ("-c", Arg.String
(fun s -> Config.confpath := s),
6685 "<path> Set path to the configuration file");
6687 ("-v", Arg.Unit
(fun () ->
6689 "%s\nconfiguration path: %s\n"
6693 exit
0), " Print version and exit");
6696 (fun s -> state.path <- s)
6697 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6699 if String.length
state.path = 0
6700 then (prerr_endline
"file name missing"; exit
1);
6704 let globalkeyhash = findkeyhash conf "global" in
6705 let wsfd, winw, winh
= Wsi.init
(object
6707 if nogeomcmds state.geomcmds
|| platform == Posx
6710 GlFunc.draw_buffer `front
;
6711 GlClear.color (scalecolor2 conf.bgcolor
);
6712 GlClear.clear
[`
color];
6713 GlFunc.draw_buffer `back
;
6715 method display = display ()
6716 method reshape w h = reshape w h
6717 method mouse b d x y m = mouse b d x y m
6718 method motion x y = state.mpos
<- (x, y); motion x y
6719 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6721 let mascm = m land (
6722 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6724 match state.keystate
with
6726 let km = k, mascm in
6729 let modehash = state.uioh#
modehash in
6730 try Hashtbl.find modehash km
6732 try Hashtbl.find globalkeyhash km
6733 with Not_found
-> KMinsrt
(k, m)
6735 | KMinsrt
(k, m) -> keyboard k m
6736 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6737 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6739 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6740 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6741 state.keystate
<- KSnone
6742 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6743 state.keystate
<- KSinto
(keys
, insrt
)
6745 state.keystate
<- KSnone
6747 method enter
x y = state.mpos
<- (x, y); pmotion x y
6748 method leave = state.mpos
<- (-1, -1)
6749 method quit
= raise Quit
6750 end) conf.winw conf.winh
(platform = Posx
) in
6755 List.exists
GlMisc.check_extension
6756 [ "GL_ARB_texture_rectangle"
6757 ; "GL_EXT_texture_recangle"
6758 ; "GL_NV_texture_rectangle" ]
6760 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6763 match Ne.pipe () with
6765 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6769 match Ne.pipe () with
6771 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6781 setcheckers conf.checkers
;
6785 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6786 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6791 state.text <- "Opening " ^
state.path;
6793 opendoc state.path state.password
;
6796 let rec loop deadline
=
6798 match state.errfd
with
6799 | None
-> [state.sr
; state.wsfd]
6800 | Some fd
-> [state.sr
; state.wsfd; fd
]
6804 state.redisplay
<- false;
6811 if deadline
= infinity
6813 else max
0.0 (deadline
-. now)
6818 try Unix.select
r [] [] timeout
6819 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6825 if state.ghyll
== noghyll
6827 match state.autoscroll
with
6828 | Some step
when step
!= 0 ->
6829 let y = state.y + step
in
6833 else if y >= state.maxy then 0 else y
6836 if state.mode = View
6837 then state.text <- "";
6840 else deadline
+. 0.01
6845 let rec checkfds = function
6847 | fd
:: rest
when fd
= state.sr
->
6848 let cmd = readcmd state.sr
in
6852 | fd
:: rest
when fd
= state.wsfd ->
6857 let s = String.create
80 in
6858 let n = Unix.read fd
s 0 80 in
6859 if conf.redirectstderr
6861 Buffer.add_substring
state.errmsgs
s 0 n;
6862 state.newerrmsgs
<- true;
6863 state.redisplay
<- true;
6866 prerr_string
(String.sub
s 0 n);
6874 if deadline
= infinity
6878 match state.autoscroll
with
6879 | Some step
when step
!= 0 -> deadline1
6880 | _ -> if state.ghyll
== noghyll then infinity
else deadline1