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
333 ; mutable fullsplit
: bool
337 | Cmulti
of multicolumns
338 | Csplit
of splitcolumns
341 type anchor
= pageno
* top
;;
343 type outline
= string * int * anchor
;;
345 type rect
= float * float * float * float * float * float * float * float;;
347 type tile
= opaque
* pixmapsize
* elapsed
348 and elapsed
= float;;
349 type pagemapkey
= pageno
* gen
;;
350 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
354 let emptyanchor = (0, 0.0);;
356 type infochange
= | Memused
| Docinfo
| Pdim
;;
358 class type uioh
= object
359 method display
: unit
360 method key
: int -> int -> uioh
361 method button
: int -> bool -> int -> int -> int -> uioh
362 method motion
: int -> int -> uioh
363 method pmotion
: int -> int -> uioh
364 method infochanged
: infochange
-> unit
365 method scrollpw
: (int * float * float)
366 method scrollph
: (int * float * float)
367 method modehash
: keyhash
371 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
372 | Textentry
of (textentry
* onleave
)
374 | LinkNav
of linktarget
375 and onleave
= leavetextentrystatus
-> unit
376 and leavetextentrystatus
= | Cancel
| Confirm
377 and helpitem
= string * int * action
380 | Action
of (uioh
-> uioh
)
382 | Ltexact
of (pageno
* int)
386 let isbirdseye = function Birdseye _
-> true | _
-> false;;
387 let istextentry = function Textentry _
-> true | _
-> false;;
391 | Loading
of (page
* gen
)
393 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
395 | Outlining
of outline list
398 let emptykeyhash = Hashtbl.create
0;;
399 let nouioh : uioh
= object (self
)
401 method key _ _
= self
402 method button _ _ _ _ _
= self
403 method motion _ _
= self
404 method pmotion _ _
= self
405 method infochanged _
= ()
406 method scrollpw
= (0, nan
, nan
)
407 method scrollph
= (0, nan
, nan
)
408 method modehash
= emptykeyhash
412 { mutable sr
: Unix.file_descr
413 ; mutable sw
: Unix.file_descr
414 ; mutable wsfd
: Unix.file_descr
415 ; mutable errfd
: Unix.file_descr
option
416 ; mutable stderr
: Unix.file_descr
417 ; mutable errmsgs
: Buffer.t
418 ; mutable newerrmsgs
: bool
422 ; mutable scrollw
: int
423 ; mutable hscrollh
: int
424 ; mutable anchor
: anchor
425 ; mutable ranchors
: (string * string * anchor
) list
427 ; mutable layout
: page list
428 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
429 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
430 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
431 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
432 ; mutable pagecount
: int
433 ; mutable currently
: currently
434 ; mutable mstate
: mstate
435 ; mutable searchpattern
: string
436 ; mutable rects
: (pageno
* recttype
* rect
) list
437 ; mutable rects1
: (pageno
* recttype
* rect
) list
438 ; mutable text
: string
439 ; mutable fullscreen
: (width
* height
) option
440 ; mutable mode
: mode
441 ; mutable uioh
: uioh
442 ; mutable outlines
: outline array
443 ; mutable bookmarks
: outline list
444 ; mutable path
: string
445 ; mutable password
: string
446 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
447 ; mutable memused
: memsize
449 ; mutable throttle
: (page list
* int * float) option
450 ; mutable autoscroll
: int option
451 ; mutable ghyll
: (int option -> unit)
452 ; mutable help
: helpitem array
453 ; mutable docinfo
: (int * string) list
454 ; mutable texid
: GlTex.texture_id
option
456 ; mutable prevzoom
: float
457 ; mutable progress
: float
458 ; mutable redisplay
: bool
459 ; mutable mpos
: mpos
460 ; mutable keystate
: keystate
461 ; mutable glinks
: bool
464 { pat
: string circbuf
465 ; pag
: string circbuf
466 ; nav
: anchor circbuf
467 ; sel
: string circbuf
488 ; presentation
= false
493 ; proportional
= true
494 ; trimmargins
= false
495 ; trimfuzz
= (0,0,0,0)
496 ; memlimit
= 32 lsl 20
501 ; bgcolor
= (0.5, 0.5, 0.5)
503 ; scrollbarinpm
= true
506 ; mustoresize
= 256 lsl 20
511 | Plinux
| Pfreebsd
| Pdragonflybsd
512 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
513 | Posx
-> "open \"%s\""
514 | Pcygwin
-> "cygstart \"%s\""
515 | Punknown
-> "echo %s")
516 ; pathlauncher
= "lp \"%s\""
519 | Plinux
| Pfreebsd
| Pdragonflybsd
520 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
527 ; redirectstderr
= false
535 let mk n
= (n
, Hashtbl.create
1) in
549 let findkeyhash c name
=
550 try List.assoc name c
.keyhashes
551 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
554 let conf = { defconf with angle
= defconf.angle
};;
557 { mutable fontsize
: int
558 ; mutable wwidth
: float
559 ; mutable maxrows
: int
571 fstate.fontsize
<- n
;
572 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
573 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
577 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
578 let len = String.length s
in
579 if colonpos >= 0 && colonpos + 3 < len
581 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
584 try String.rindex_from s
colonpos ' '
588 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
591 | "http" | "ftp" | "mailto" ->
593 try String.index_from s
colonpos ' '
594 with Not_found
-> len
596 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
604 if String.length
conf.urilauncher
= 0
605 then print_endline uri
607 let url = geturl uri
in
608 if String.length
url = 0
609 then print_endline uri
611 let re = Str.regexp
"%s" in
612 let command = Str.global_replace
re url conf.urilauncher
in
616 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
622 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
623 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
627 let strings = version () :: "" :: Help.keys
in
630 let url = geturl s
in
631 if String.length
url > 0
632 then (s
, 0, Action
(fun u
-> gotouri url; u
))
633 else (s
, 0, Noaction
)
638 let firstgeomcmds = "", [];;
645 ; stderr
= Unix.stderr
646 ; errmsgs
= Buffer.create
0
653 ; anchor
= emptyanchor
657 ; tilelru
= Queue.create
()
658 ; pagemap
= Hashtbl.create
10
659 ; tilemap
= Hashtbl.create
10
674 ; geomcmds
= firstgeomcmds
676 { nav
= cbnew 10 (0, 0.0)
702 Printf.kprintf prerr_endline fmt
704 Printf.kprintf ignore fmt
708 if String.length
conf.pathlauncher
= 0
709 then print_endline
state.path
711 let re = Str.regexp
"%s" in
712 let command = Str.global_replace
re state.path
conf.pathlauncher
in
716 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
722 type 'a t
= | Res
of 'a
| Exn
of exn
;;
725 try Res
(Unix.pipe ())
731 with exn
-> f
(Printexc.to_string exn
)
735 try Res
(Unix.dup fd
)
740 try Res
(Unix.dup2 fd1 fd2
)
745 let redirectstderr () =
746 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
747 if conf.redirectstderr
749 match Ne.pipe () with
751 dolog "failed to create stderr redirection pipes: %s"
752 (Printexc.to_string exn
)
755 begin match Ne.dup Unix.stderr
with
757 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
758 Ne.clo r
(clofail "pipe/r");
759 Ne.clo w
(clofail "pipe/w");
761 | Ne.Res dupstderr
->
762 begin match Ne.dup2 w
Unix.stderr
with
764 dolog "failed to dup2 to stderr: %s"
765 (Printexc.to_string exn
);
766 Ne.clo dupstderr
(clofail "stderr duplicate");
767 Ne.clo r
(clofail "redir pipe/r");
768 Ne.clo w
(clofail "redir pipe/w");
771 state.stderr
<- dupstderr
;
772 state.errfd
<- Some r
;
776 state.newerrmsgs
<- false;
777 begin match state.errfd
with
779 begin match Ne.dup2 state.stderr
Unix.stderr
with
781 dolog "failed to dup2 original stderr: %s"
782 (Printexc.to_string exn
)
784 Ne.clo fd
(clofail "dup of stderr");
785 Unix.dup2 state.stderr
Unix.stderr
;
790 prerr_string
(Buffer.contents
state.errmsgs
);
792 Buffer.clear
state.errmsgs
;
798 let postRedisplay who
=
800 then prerr_endline
("redisplay for " ^ who
);
801 state.redisplay
<- true;
805 let getopaque pageno
=
806 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
807 with Not_found
-> None
810 let putopaque pageno opaque
=
811 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
814 let pagetranslatepoint l x y
=
815 let dy = y
- l
.pagedispy
in
816 let y = dy + l
.pagey
in
817 let dx = x
- l
.pagedispx
in
818 let x = dx + l
.pagex
in
825 begin match getopaque l
.pageno
with
827 let x0 = l
.pagedispx
in
828 let x1 = x0 + l
.pagevw
in
829 let y0 = l
.pagedispy
in
830 let y1 = y0 + l
.pagevh
in
831 if y >= y0 && y <= y1 && x >= x0 && x <= x1
833 let px, py
= pagetranslatepoint l
x y in
834 match whatsunder opaque
px py
with
847 state.text
<- Printf.sprintf
"%c%s" c s
;
848 G.postRedisplay "showtext";
851 let undertext = function
854 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
855 | Utext s
-> "font: " ^ s
856 | Uunexpected s
-> "unexpected: " ^ s
857 | Ulaunch s
-> "launch: " ^ s
858 | Unamed s
-> "named: " ^ s
859 | Uremote
(filename
, pageno
) ->
860 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
863 let updateunder x y =
864 match getunder x y with
865 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
867 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
868 Wsi.setcursor
Wsi.CURSOR_INFO
869 | Ulinkgoto
(pageno
, _
) ->
871 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
872 Wsi.setcursor
Wsi.CURSOR_INFO
874 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
875 Wsi.setcursor
Wsi.CURSOR_TEXT
877 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
878 Wsi.setcursor
Wsi.CURSOR_INHERIT
880 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
881 Wsi.setcursor
Wsi.CURSOR_INHERIT
883 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
884 Wsi.setcursor
Wsi.CURSOR_INHERIT
885 | Uremote
(filename
, pageno
) ->
886 if conf.underinfo
then showtext 'r'
887 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
888 Wsi.setcursor
Wsi.CURSOR_INFO
891 let showlinktype under
=
897 let s = undertext under
in
902 let b = Buffer.create
(String.length
s + 1) in
903 Buffer.add_string
b s;
908 let colorspace_of_string s =
909 match String.lowercase
s with
913 | _
-> failwith
"invalid colorspace"
916 let int_of_colorspace = function
922 let colorspace_of_int = function
926 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
929 let colorspace_to_string = function
935 let intentry_with_suffix text key
=
937 if key
>= 32 && key
< 127
941 match Char.lowercase
c with
943 let text = addchar text c in
947 let text = addchar text c in
951 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
955 let multicolumns_to_string (n
, a
, b) =
957 then Printf.sprintf
"%d" n
958 else Printf.sprintf
"%d,%d,%d" n a
b;
961 let multicolumns_of_string s =
963 (int_of_string
s, 0, 0)
965 Scanf.sscanf
s "%u,%u,%u" (fun n a
b -> (n
, a
, b));
970 let n = Unix.read fd
s 0 4 in
971 if n != 4 then failwith
"incomplete read(len)";
973 lor (Char.code
s.[0] lsl 24)
974 lor (Char.code
s.[1] lsl 16)
975 lor (Char.code
s.[2] lsl 8)
976 lor (Char.code
s.[3] lsl 0)
978 let s = String.create
len in
979 let n = Unix.read fd
s 0 len in
980 if n != len then failwith
"incomplete read(data)";
984 let btod b = if b then 1 else 0;;
987 let b = Buffer.create
16 in
988 Buffer.add_string
b "llll";
991 let s = Buffer.contents
b in
992 let n = String.length
s in
994 (* dolog "wcmd %S" (String.sub s 4 len); *)
995 s.[0] <- Char.chr
((len lsr 24) land 0xff);
996 s.[1] <- Char.chr
((len lsr 16) land 0xff);
997 s.[2] <- Char.chr
((len lsr 8) land 0xff);
998 s.[3] <- Char.chr
(len land 0xff);
999 let n'
= Unix.write
state.sw
s 0 n in
1000 if n'
!= n then failwith
"write failed";
1005 if conf.presentation
1007 let d = conf.winh
- h
in
1014 let rec f pn ph pi fh l
=
1016 | (n, _
, h
, _
) :: rest
->
1017 let ips = calcips h
in
1019 if conf.presentation
1022 if isbirdseye state.mode
&& pn
= 0
1027 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
1032 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
1036 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
1039 let fh = f 0 0 0 0 state.pdims
in
1044 match conf.columns
with
1045 | Csingle
-> calcheight ()
1046 | Cmulti
((c, _
, _
), b) ->
1047 let rec loop y h
n =
1051 if n = Array.length
b
1054 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
1060 loop max_int
0 (((Array.length
b - 1) / c) * c)
1062 if Array.length
b > 0
1064 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1069 let getpageyh pageno
=
1070 let rec f pn ph pi
y l
=
1072 | (n, _
, h
, _
) :: rest
->
1073 let ips = calcips h
in
1076 let h = if n = pageno
then h else ph
in
1077 if conf.presentation
&& n = pageno
1079 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
1081 y + (pageno
- pn
) * (ph
+ pi
), h
1083 let y = y + (if conf.presentation
then pi
else 0) in
1084 let y = y + (n - pn
) * (ph
+ pi
) in
1088 y + (pageno
- pn
) * (ph
+ pi
), ph
1090 f 0 0 0 0 state.pdims
1093 let getpageyh pageno
=
1094 match conf.columns
with
1095 | Csingle
-> getpageyh pageno
1097 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1101 let (_
, _
, y, (_
, _
, h, _
)) = b.(n) in
1105 let getpagedim pageno
=
1108 | (n, _
, _
, _
) as pdim
:: rest
->
1110 then (if n = pageno
then pdim
else ppdim
)
1115 f (-1, -1, -1, -1) state.pdims
1118 let getpagey pageno
= fst
(getpageyh pageno
);;
1120 let nogeomcmds cmds
=
1122 | s, [] -> String.length
s = 0
1127 let sh = sh - state.hscrollh
in
1128 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1129 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1131 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1132 let ips = calcips h in
1134 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1138 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1140 prev
, pdims
, pdimno
, 0
1142 let dy = dy + yinc in
1143 let py = py + yinc in
1144 if pageno
= state.pagecount
|| dy >= sh
1149 if py + h <= vy - yinc
1151 let py = py + h + ips in
1152 let dy = max
0 (py - y) in
1153 f ~pageno
:(pageno
+1)
1161 let pagey = vy - py in
1162 let pagevh = h - pagey in
1163 let pagevh = min
(sh - dy) pagevh in
1164 let off = if yinc > 0 then py - vy else 0 in
1165 let py = py + h + ips in
1168 if state.w
< conf.winw
- state.scrollw
1169 then (conf.winw
- state.scrollw
- state.w
) / 2
1172 let dispx = xoff + state.x in
1178 let lw = w
- pagex in
1179 min
lw (conf.winw
- state.scrollw
)
1183 ; pagedimno
= pdimno
1187 ; pagey = pagey + off
1189 ; pagevh = pagevh - off
1191 ; pagedispy
= dy + off
1195 let accu = e :: accu in
1196 f ~pageno
:(pageno
+1)
1217 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1218 let sh = sh - state.hscrollh
in
1219 let rec fold accu n =
1220 if n = Array.length
b
1223 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1226 || n = state.pagecount
- coverB
1227 || (n - coverA
) mod columns
= columns
- 1)
1233 let pagey = max
0 (y - vy) in
1234 let pagedispy = if pagey > 0 then 0 else vy - y in
1235 let pagedispx, pagex =
1237 if n = coverA
- 1 || n = state.pagecount
- coverB
1238 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1239 else dx + xoff + state.x
1246 let vw = conf.winw
- state.scrollw
- pagedispx in
1247 let pw = w
- pagex in
1250 let pagevh = min
(h - pagey) (sh - pagedispy) in
1251 if pagevw > 0 && pagevh > 0
1255 ; pagedimno
= pdimno
1262 ; pagedispx = pagedispx
1263 ; pagedispy = pagedispy
1275 List.rev
(fold [] 0)
1278 let layoutS (columns
, b) y sh =
1279 let sh = sh - state.hscrollh
in
1280 let rec fold accu n =
1281 if n = Array.length
b
1284 let pdimno, px, vy, (_
, pagew
, pageh
, xoff) = b.(n) in
1291 let x = xoff + state.x in
1292 let pagey = max
0 (y - vy) in
1293 let pagedispy = if pagey > 0 then 0 else vy - y in
1294 let pagedispx, pagex =
1308 let pagecolw = pagew
/columns
in
1310 if pagecolw < conf.winw
1311 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1315 let vw = conf.winw
- pagedispx - state.scrollw
in
1316 let pw = pagew
- pagex in
1322 else min
pagevw pagecolw
1324 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1325 if pagevw > 0 && pagevh > 0
1328 { pageno
= n/columns
1329 ; pagedimno
= pdimno
1336 ; pagedispx = pagedispx
1337 ; pagedispy = pagedispy
1338 ; pagecol
= n mod columns
1349 List.rev
(fold [] 0)
1353 if nogeomcmds state.geomcmds
1355 match conf.columns
with
1356 | Csingle
-> layout1 y sh
1357 | Cmulti
c -> layoutN c y sh
1358 | Csplit
s -> layoutS s y sh
1363 let y = state.y + incr
in
1365 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1370 let tilex = l
.pagex mod conf.tilew
in
1371 let tiley = l
.pagey mod conf.tileh
in
1373 let col = l
.pagex / conf.tilew
in
1374 let row = l
.pagey / conf.tileh
in
1376 let rec rowloop row y0 dispy
h =
1380 let dh = conf.tileh
- y0 in
1381 let dh = min
h dh in
1382 let rec colloop col x0 dispx w
=
1386 let dw = conf.tilew
- x0 in
1387 let dw = min w
dw in
1389 f col row dispx dispy
x0 y0 dw dh;
1390 colloop (col+1) 0 (dispx+dw) (w
-dw)
1393 colloop col tilex l
.pagedispx l
.pagevw;
1394 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1397 if l
.pagevw > 0 && l
.pagevh > 0
1398 then rowloop row tiley l
.pagedispy l
.pagevh;
1401 let gettileopaque l
col row =
1403 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1405 try Some
(Hashtbl.find
state.tilemap
key)
1406 with Not_found
-> None
1409 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1410 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1411 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1414 let drawtiles l color
=
1416 let f col row x y tilex tiley w
h =
1417 match gettileopaque l
col row with
1418 | Some
(opaque
, _
, t
) ->
1419 let params = x, y, w
, h, tilex, tiley in
1423 GlFunc.blend_func `zero `one_minus_src_color
;
1425 drawtile
params opaque
;
1427 then Gl.disable `blend
;
1430 let s = Printf.sprintf
1434 let w = measurestr
fstate.fontsize
s in
1435 GlMisc.push_attrib
[`current
];
1436 GlDraw.color
(0.0, 0.0, 0.0);
1438 (float (x-2), float (y-2))
1439 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1440 GlDraw.color
(1.0, 1.0, 1.0);
1441 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1442 GlMisc.pop_attrib
();
1447 let lw = conf.winw
- state.scrollw
- x in
1450 let lh = conf.winh
- y in
1453 Gl.enable `texture_2d
;
1454 begin match state.texid
with
1456 GlTex.bind_texture `texture_2d id
;
1459 and x1 = float (x+w)
1460 and y1 = float (y+h) in
1462 let tw = float w /. 64.0
1463 and th
= float h /. 64.0 in
1464 let tx0 = float tilex /. 64.0
1465 and ty0
= float tiley /. 64.0 in
1467 and ty1
= ty0
+. th
in
1468 GlDraw.begins `quads
;
1469 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1470 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1471 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1472 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1475 Gl.disable `texture_2d
;
1477 GlDraw.color
(1.0, 1.0, 1.0);
1480 (float (x+w), float (y+h));
1482 if w > 128 && h > fstate.fontsize
+ 10
1484 GlDraw.color
(0.0, 0.0, 0.0);
1487 then (col*conf.tilew
, row*conf.tileh
)
1490 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1497 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1499 let tilevisible1 l
x y =
1501 and ax1
= l
.pagex + l
.pagevw
1503 and ay1
= l
.pagey + l
.pagevh in
1507 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1508 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1510 let rx0 = max
ax0 bx0
1511 and ry0
= max ay0 by0
1512 and rx1
= min ax1
bx1
1513 and ry1
= min ay1 by1
in
1515 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1516 nonemptyintersection
1519 let tilevisible layout n x y =
1520 let rec findpageinlayout m
= function
1521 | l
:: rest
when l
.pageno
= n ->
1522 tilevisible1 l
x y || (
1523 match conf.columns
with
1524 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1527 | _
:: rest
-> findpageinlayout 0 rest
1530 findpageinlayout 0 layout;
1533 let tileready l
x y =
1534 tilevisible1 l
x y &&
1535 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1538 let tilepage n p
layout =
1539 let rec loop = function
1543 let f col row _ _ _ _ _ _
=
1544 if state.currently
= Idle
1546 match gettileopaque l
col row with
1549 let x = col*conf.tilew
1550 and y = row*conf.tileh
in
1552 let w = l
.pagew
- x in
1556 let h = l
.pageh
- y in
1559 wcmd "tile %s %d %d %d %d" p
x y w h;
1562 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1563 conf.tilew
, conf.tileh
1572 if nogeomcmds state.geomcmds
1576 let preloadlayout visiblepages
=
1577 let presentation = conf.presentation in
1578 let interpagespace = conf.interpagespace in
1579 let maxy = state.maxy in
1580 conf.presentation <- false;
1581 conf.interpagespace <- 0;
1582 state.maxy <- calcheight ();
1584 match visiblepages
with
1585 | [] -> if state.y >= maxy then maxy else 0
1586 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1588 let y = if y < conf.winh
then 0 else y - conf.winh
in
1589 let h = state.y - y + conf.winh
*3 in
1590 let pages = layout y h in
1591 conf.presentation <- presentation;
1592 conf.interpagespace <- interpagespace;
1598 let rec loop pages =
1599 if state.currently
!= Idle
1604 begin match getopaque l
.pageno
with
1606 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1607 state.currently
<- Loading
(l
, state.gen
);
1609 tilepage l
.pageno opaque
pages;
1614 if nogeomcmds state.geomcmds
1620 if conf.preload && state.currently
= Idle
1621 then load (preloadlayout pages);
1624 let layoutready layout =
1625 let rec fold all ls
=
1626 all
&& match ls
with
1628 let seen = ref false in
1629 let allvisible = ref true in
1630 let foo col row _ _ _ _ _ _
=
1632 allvisible := !allvisible &&
1633 begin match gettileopaque l
col row with
1639 fold (!seen && !allvisible) rest
1642 let alltilesvisible = fold true layout in
1647 let y = bound y 0 state.maxy in
1648 let y, layout, proceed
=
1649 match conf.maxwait
with
1650 | Some time
when state.ghyll
== noghyll ->
1651 begin match state.throttle
with
1653 let layout = layout y conf.winh
in
1654 let ready = layoutready layout in
1658 state.throttle
<- Some
(layout, y, now ());
1660 else G.postRedisplay "gotoy showall (None)";
1662 | Some
(_
, _
, started
) ->
1663 let dt = now () -. started
in
1666 state.throttle
<- None
;
1667 let layout = layout y conf.winh
in
1669 G.postRedisplay "maxwait";
1676 let layout = layout y conf.winh
in
1677 if true || layoutready layout
1678 then G.postRedisplay "gotoy ready";
1684 state.layout <- layout;
1685 begin match state.mode
with
1686 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
1687 let rec loop = function
1689 state.mode
<- LinkNav
(Ltgendir
0)
1690 | l
:: _
when l
.pageno
= pageno
->
1691 begin match getopaque pageno
with
1693 state.mode
<- LinkNav
(Ltgendir
0)
1695 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1696 if not
(x0 >= l
.pagex && x1 <= l
.pagex + l
.pagevw
1697 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1698 then state.mode
<- LinkNav
(Ltgendir
0)
1700 | _
:: rest
-> loop rest
1705 begin match state.mode
with
1706 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1707 if not
(pagevisible layout pageno
)
1709 match state.layout with
1712 state.mode
<- Birdseye
(
1713 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1716 | LinkNav
(Ltgendir dir
as lt
) ->
1718 let rec loop = function
1721 match getopaque l
.pageno
with
1727 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1729 if dir
> 0 then LDfirst
else LDlast
1735 | Lnotfound
-> loop rest
1737 showlinktype (getlink opaque
n);
1738 Ltexact
(l
.pageno
, n)
1742 state.mode
<- LinkNav
linknav
1747 state.ghyll
<- noghyll;
1750 let mx, my
= state.mpos
in
1755 let conttiling pageno opaque
=
1756 tilepage pageno opaque
1757 (if conf.preload then preloadlayout state.layout else state.layout)
1760 let gotoy_and_clear_text y =
1761 if not
conf.verbose
then state.text <- "";
1766 match state.layout with
1769 let coloff = l
.pagecol
* l
.pageh
in
1770 (l
.pageno
, (float l
.pagey +. float coloff) /. float l
.pageh
)
1773 let getanchory (n, top
) =
1774 let y, h = getpageyh n in
1775 y + (truncate
(top
*. float h));
1778 let gotoanchor anchor
=
1779 gotoy (getanchory anchor
);
1783 cbput state.hists
.nav
(getanchor ());
1787 let anchor = cbgetc state.hists
.nav dir
in
1792 let rec scroll f n a
b =
1793 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1795 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1797 then s (float f /. float a
)
1800 then 1.0 -. s ((float (f-b) /. float (n-b)))
1807 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1808 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1810 let ins = float a
*. iv1
1811 and outs
= float (n-b) *. iv1 in
1813 ins +. outs
+. float ones
1815 let rec set (_N
, _A
, _B
) y sy
=
1816 let sum = summa
1.0 _N _A _B
in
1817 let dy = float (y - sy
) in
1821 then state.ghyll
<- noghyll
1824 let s = scroll n _N _A _B
in
1825 let y1 = y1 +. ((s *. dy) /. sum) in
1826 gotoy_and_clear_text (truncate
y1);
1827 state.ghyll
<- gf (n+1) y1;
1831 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1833 gf 0 (float state.y)
1836 match conf.ghyllscroll
with
1838 gotoy_and_clear_text y
1840 if state.ghyll
== noghyll
1841 then set nab
y state.y
1842 else state.ghyll
(Some
y)
1845 let gotopage n top
=
1846 let y, h = getpageyh n in
1847 let y = y + (truncate
(top
*. float h)) in
1851 let gotopage1 n top
=
1852 let y = getpagey n in
1857 let invalidate s f =
1862 match state.geomcmds
with
1863 | ps
, [] when String.length ps
= 0 ->
1865 state.geomcmds
<- s, [];
1868 state.geomcmds
<- ps
, [s, f];
1870 | ps
, (s'
, _
) :: rest
when s'
= s ->
1871 state.geomcmds
<- ps
, ((s, f) :: rest
);
1874 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1877 let opendoc path password
=
1879 state.password
<- password
;
1880 state.gen
<- state.gen
+ 1;
1881 state.docinfo
<- [];
1883 setaalevel
conf.aalevel
;
1884 Wsi.settitle
("llpp " ^
Filename.basename path
);
1885 wcmd "open %s\000%s\000" path password
;
1886 invalidate "reqlayout"
1888 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1892 let c = c *. conf.colorscale
in
1896 let scalecolor2 (r
, g
, b) =
1897 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1900 let docolumns = function
1903 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1904 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1905 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1906 let rec fixrow m
= if m
= pageno
then () else
1907 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1910 let y = y + (rowh
- h) / 2 in
1911 a.(m
) <- (pdimno, x, y, pdim
);
1915 if pageno
= state.pagecount
1916 then fixrow (((pageno
- 1) / columns
) * columns
)
1918 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1920 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1921 pdimno+1, pdim
, rest
1926 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1928 (conf.winw
- state.scrollw
- w) / 2,
1929 y + rowh
+ conf.interpagespace, h
1932 if (pageno
- coverA
) mod columns
= 0
1933 then 0, y + rowh
+ conf.interpagespace, h
1934 else x, y, max rowh
h
1937 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1938 then fixrow (pageno
- columns
);
1939 a.(pageno
) <- (pdimno, x, y, pdim
);
1940 let x = x + w + xoff*2 + conf.interpagespace in
1941 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1943 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1944 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1947 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1948 let rec loop pageno
pdimno pdim
y pdims
=
1949 if pageno
= state.pagecount
1952 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1954 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1955 pdimno+1, pdim
, rest
1960 let rec loop1 n x y =
1961 if n = c then y else (
1962 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1963 loop1 (n+1) (x+cw) (y + h + conf.interpagespace)
1966 let y = loop1 0 0 y in
1967 loop (pageno
+1) pdimno pdim
y pdims
1969 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1970 conf.columns
<- Csplit
(c, a);
1974 docolumns conf.columns
;
1975 state.maxy <- calcheight ();
1977 if state.w <= conf.winw
- state.scrollw
1981 match state.mode
with
1982 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1983 let y, h = getpageyh pageno
in
1984 let top = (conf.winh
- h) / 2 in
1985 gotoy (max
0 (y - top))
1986 | _
-> gotoanchor state.anchor
1990 GlDraw.viewport
0 0 w h;
1991 let firsttime = state.geomcmds
== firstgeomcmds in
1992 if not
firsttime && nogeomcmds state.geomcmds
1993 then state.anchor <- getanchor ();
1996 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1999 setfontsize fstate.fontsize
;
2000 GlMat.mode `modelview
;
2001 GlMat.load_identity
();
2003 GlMat.mode `projection
;
2004 GlMat.load_identity
();
2005 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2006 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2007 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2012 else float state.x /. float state.w
2014 invalidate "geometry"
2018 then state.x <- truncate
(relx *. float w);
2020 match conf.columns
with
2022 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
2023 | Csplit
(c, _
) -> w * c
2025 wcmd "geometry %d %d" w h);
2029 let len = String.length
state.text in
2032 match state.mode
with
2035 let h, _
, _
= state.uioh#scrollpw
in
2041 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2042 (x+.w, float (conf.winh
- hscrollh))
2045 let w = float (conf.winw
- state.scrollw
- 1) in
2046 if state.progress
>= 0.0 && state.progress
< 1.0
2048 GlDraw.color
(0.3, 0.3, 0.3);
2049 let w1 = w *. state.progress
in
2051 GlDraw.color
(0.0, 0.0, 0.0);
2055 GlDraw.color
(0.0, 0.0, 0.0);
2059 GlDraw.color
(1.0, 1.0, 1.0);
2060 drawstring fstate.fontsize
2061 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2064 match state.mode
with
2065 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
2069 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2071 Printf.sprintf
"%s%s_" prefix
text
2080 if not
(istextentry state.mode
)
2082 let s1 = "(press 'e' to review error messasges)" in
2083 if String.length
s > 0 then s ^
" " ^
s1 else s1
2088 if String.length
s > 0
2093 let len = Queue.length
state.tilelru
in
2095 if state.memused
<= conf.memlimit
2100 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2101 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2102 let (_
, pw, ph
, _
) = getpagedim n in
2105 && colorspace
= conf.colorspace
2106 && angle
= conf.angle
2111 match state.throttle
with
2114 then preloadlayout state.layout
2116 | Some
(layout, _
, _
) ->
2119 let x = col*conf.tilew
2120 and y = row*conf.tileh
in
2121 tilevisible layout n x y
2123 then Queue.push lruitem
state.tilelru
2125 wcmd "freetile %s" p
;
2126 state.memused
<- state.memused
- s;
2127 state.uioh#infochanged Memused
;
2128 Hashtbl.remove
state.tilemap k
;
2137 Queue.iter
(fun (k
, p
, s) ->
2138 wcmd "freetile %s" p
;
2139 state.memused
<- state.memused
- s;
2140 state.uioh#infochanged Memused
;
2141 Hashtbl.remove
state.tilemap k
;
2143 Queue.clear
state.tilelru
;
2147 let logcurrently = function
2148 | Idle
-> dolog "Idle"
2149 | Loading
(l
, gen
) ->
2150 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2151 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2153 "Tiling %d[%d,%d] page=%s cs=%s angle"
2154 l
.pageno
col row pageopaque
2155 (colorspace_to_string colorspace
)
2157 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2158 angle gen
conf.angle
state.gen
2160 conf.tilew
conf.tileh
2167 (* dolog "%S" cmds; *)
2170 try String.index cmds ' '
2171 with Not_found
-> -1
2176 let l = String.length cmds
in
2177 let op = String.sub cmds
0 spacepos in
2179 if l - spacepos < 2 then ""
2180 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2185 state.uioh#infochanged Pdim
;
2189 state.rects
<- state.rects1
;
2190 G.postRedisplay "clearrects";
2194 try Scanf.sscanf
args "%u" (fun n -> n)
2196 dolog "error processing 'continue' %S: %s"
2197 cmds
(Printexc.to_string exn
);
2200 state.pagecount
<- n;
2201 begin match state.currently
with
2203 state.currently
<- Idle
;
2204 state.outlines
<- Array.of_list
(List.rev
l)
2208 let cur, cmds
= state.geomcmds
in
2209 if String.length
cur = 0
2210 then failwith
"umpossible";
2212 begin match List.rev cmds
with
2214 state.geomcmds
<- "", [];
2218 state.geomcmds
<- s, List.rev rest
;
2220 if conf.maxwait
= None
2221 then G.postRedisplay "continue";
2231 then showtext ' '
args
2234 let progress, text =
2236 Scanf.sscanf
args "%f %n"
2238 f, String.sub
args pos
(String.length
args - pos
))
2240 dolog "error processing 'progress' %S: %s"
2241 cmds
(Printexc.to_string exn
);
2245 state.progress <- progress;
2246 G.postRedisplay "progress"
2249 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2251 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2252 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2253 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2255 dolog "error processing 'firstmatch' %S: %s"
2256 cmds
(Printexc.to_string exn
);
2259 let y = (getpagey pageno) + truncate
y0 in
2262 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2265 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2267 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2268 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2269 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2271 dolog "error processing 'match' %S: %s"
2272 cmds
(Printexc.to_string exn
);
2276 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2281 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2283 dolog "error processing 'page' %S: %s"
2284 cmds
(Printexc.to_string exn
);
2287 begin match state.currently
with
2288 | Loading
(l, gen
) ->
2289 vlog "page %d took %f sec" l.pageno t
;
2290 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2291 begin match state.throttle
with
2293 let preloadedpages =
2295 then preloadlayout state.layout
2300 Set.Make
(struct type t
= int let compare = (-) end) in
2302 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2303 IntSet.empty
preloadedpages
2306 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2307 if not
(IntSet.mem
pageno set)
2309 wcmd "freepage %s" opaque
;
2315 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2318 state.currently
<- Idle
;
2321 tilepage l.pageno pageopaque state.layout;
2323 load preloadedpages;
2324 if pagevisible state.layout l.pageno
2325 && layoutready state.layout
2326 then G.postRedisplay "page";
2329 | Some
(layout, _
, _
) ->
2330 state.currently
<- Idle
;
2331 tilepage l.pageno pageopaque layout;
2336 dolog "Inconsistent loading state";
2337 logcurrently state.currently
;
2342 let (x, y, opaque
, size
, t
) =
2344 Scanf.sscanf
args "%u %u %s %u %f"
2345 (fun x y p size t
-> (x, y, p
, size
, t
))
2347 dolog "error processing 'tile' %S: %s"
2348 cmds
(Printexc.to_string exn
);
2351 begin match state.currently
with
2352 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2353 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2355 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2357 wcmd "freetile %s" opaque
;
2358 state.currently
<- Idle
;
2362 puttileopaque l col row gen cs angle opaque size t
;
2363 state.memused
<- state.memused
+ size
;
2364 state.uioh#infochanged Memused
;
2366 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2367 opaque
, size
) state.tilelru
;
2370 match state.throttle
with
2371 | None
-> state.layout
2372 | Some
(layout, _
, _
) -> layout
2375 state.currently
<- Idle
;
2377 && conf.colorspace
= cs
2378 && conf.angle
= angle
2379 && tilevisible layout l.pageno x y
2380 then conttiling l.pageno pageopaque;
2382 begin match state.throttle
with
2384 preload state.layout;
2386 && conf.colorspace
= cs
2387 && conf.angle
= angle
2388 && tilevisible state.layout l.pageno x y
2389 then G.postRedisplay "tile nothrottle";
2391 | Some
(layout, y, _
) ->
2392 let ready = layoutready layout in
2396 state.layout <- layout;
2397 state.throttle
<- None
;
2398 G.postRedisplay "throttle";
2405 dolog "Inconsistent tiling state";
2406 logcurrently state.currently
;
2413 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2415 dolog "error processing 'pdim' %S: %s"
2416 cmds
(Printexc.to_string exn
);
2419 state.uioh#infochanged Pdim
;
2420 state.pdims
<- pdim :: state.pdims
2423 let (l, n, t
, h, pos
) =
2425 Scanf.sscanf
args "%u %u %d %u %n"
2426 (fun l n t
h pos
-> l, n, t
, h, pos
)
2428 dolog "error processing 'o' %S: %s"
2429 cmds
(Printexc.to_string exn
);
2432 let s = String.sub
args pos
(String.length
args - pos
) in
2433 let outline = (s, l, (n, float t
/. float h)) in
2434 begin match state.currently
with
2435 | Outlining outlines
->
2436 state.currently
<- Outlining
(outline :: outlines
)
2438 state.currently
<- Outlining
[outline]
2440 dolog "invalid outlining state";
2441 logcurrently currently
2445 state.docinfo
<- (1, args) :: state.docinfo
2448 state.uioh#infochanged Docinfo
;
2449 state.docinfo
<- List.rev
state.docinfo
2452 dolog "unknown cmd `%S'" cmds
2457 let action = function
2458 | HCprev
-> cbget cb ~
-1
2459 | HCnext
-> cbget cb
1
2460 | HCfirst
-> cbget cb ~
-(cb
.rc)
2461 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2462 and cancel
() = cb
.rc <- rc
2466 let search pattern forward
=
2467 if String.length pattern
> 0
2470 match state.layout with
2473 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2475 wcmd "search %d %d %d %d,%s\000"
2476 (btod conf.icase
) pn py (btod forward
) pattern
;
2479 let intentry text key =
2481 if key >= 32 && key < 127
2487 let text = addchar text c in
2491 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2495 let linknentry text key =
2497 if key >= 32 && key < 127
2503 let text = addchar text c in
2507 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2512 if String.length
s > 0
2515 let l = String.length
s in
2516 let rec loop pos
n = if pos
= l then n else
2517 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2518 loop (pos
+1) (n*26 + m)
2521 let rec loop n = function
2524 match getopaque l.pageno with
2525 | None
-> loop n rest
2527 let m = getlinkcount opaque
in
2530 let under = getlink opaque
n in
2533 else loop (n-m) rest
2535 loop n state.layout;
2539 let textentry text key =
2540 if key land 0xff00 = 0xff00
2542 else TEcont
(text ^
Wsi.toutf8
key)
2545 let reqlayout angle proportional
=
2546 match state.throttle
with
2548 if nogeomcmds state.geomcmds
2549 then state.anchor <- getanchor ();
2550 conf.angle
<- angle
mod 360;
2553 match state.mode
with
2554 | LinkNav _
-> state.mode
<- View
2557 conf.proportional
<- proportional
;
2558 invalidate "reqlayout"
2559 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2563 let settrim trimmargins trimfuzz
=
2564 if nogeomcmds state.geomcmds
2565 then state.anchor <- getanchor ();
2566 conf.trimmargins
<- trimmargins
;
2567 conf.trimfuzz
<- trimfuzz
;
2568 let x0, y0, x1, y1 = trimfuzz
in
2569 invalidate "settrim"
2571 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2572 Hashtbl.iter
(fun _ opaque
->
2573 wcmd "freepage %s" opaque
;
2575 Hashtbl.clear
state.pagemap
;
2579 match state.throttle
with
2581 let zoom = max
0.01 zoom in
2582 if zoom <> conf.zoom
2584 state.prevzoom
<- conf.zoom;
2586 reshape conf.winw
conf.winh
;
2587 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2590 | Some
(layout, y, started
) ->
2592 match conf.maxwait
with
2596 let dt = now () -. started
in
2604 let setcolumns mode columns coverA coverB
=
2608 then showtext '
!'
"split mode doesn't work in bird's eye"
2610 conf.columns
<- Csplit
(-columns
, [||]);
2618 conf.columns
<- Csingle
;
2623 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2627 reshape conf.winw
conf.winh
;
2630 let enterbirdseye () =
2631 let zoom = float conf.thumbw
/. float conf.winw
in
2632 let birdseyepageno =
2633 let cy = conf.winh
/ 2 in
2637 let rec fold best
= function
2640 let d = cy - (l.pagedispy + l.pagevh/2)
2641 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2642 if abs
d < abs dbest
2649 state.mode
<- Birdseye
(
2650 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2653 conf.presentation <- false;
2654 conf.interpagespace <- 10;
2655 conf.hlinks
<- false;
2657 state.mstate
<- Mnone
;
2658 conf.maxwait
<- None
;
2660 match conf.beyecolumns
with
2663 Cmulti
((c, 0, 0), [||])
2666 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2669 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2674 reshape conf.winw
conf.winh
;
2677 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2679 conf.zoom <- c.zoom;
2680 conf.presentation <- c.presentation;
2681 conf.interpagespace <- c.interpagespace;
2682 conf.maxwait
<- c.maxwait
;
2683 conf.hlinks
<- c.hlinks
;
2684 conf.beyecolumns
<- (
2685 match conf.columns
with
2686 | Cmulti
((c, _
, _
), _
) -> Some
c
2688 | Csplit _
-> failwith
"leaving bird's eye split mode"
2691 match c.columns
with
2692 | Cmulti
(c, _
) -> Cmulti
(c, [||])
2693 | Csingle
-> Csingle
2694 | Csplit
(c, _
) -> Csplit
(c, [||])
2699 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2702 reshape conf.winw
conf.winh
;
2703 state.anchor <- if goback
then anchor else (pageno, 0.0);
2706 let togglebirdseye () =
2707 match state.mode
with
2708 | Birdseye vals
-> leavebirdseye vals
true
2709 | View
-> enterbirdseye ()
2713 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2714 let pageno = max
0 (pageno - incr
) in
2715 let rec loop = function
2716 | [] -> gotopage1 pageno 0
2717 | l :: _
when l.pageno = pageno ->
2718 if l.pagedispy >= 0 && l.pagey = 0
2719 then G.postRedisplay "upbirdseye"
2720 else gotopage1 pageno 0
2721 | _
:: rest
-> loop rest
2724 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2727 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2728 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2729 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2730 let rec loop = function
2732 let y, h = getpageyh pageno in
2733 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2735 | l :: _
when l.pageno = pageno ->
2736 if l.pagevh != l.pageh
2737 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2738 else G.postRedisplay "downbirdseye"
2739 | _
:: rest
-> loop rest
2744 let optentry mode _
key =
2745 let btos b = if b then "on" else "off" in
2746 if key >= 32 && key < 127
2748 let c = Char.chr
key in
2752 try conf.scrollstep
<- int_of_string
s with exc
->
2753 state.text <- Printf.sprintf
"bad integer `%s': %s"
2754 s (Printexc.to_string exc
)
2756 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2761 conf.autoscrollstep
<- int_of_string
s;
2762 if state.autoscroll
<> None
2763 then state.autoscroll
<- Some
conf.autoscrollstep
2765 state.text <- Printf.sprintf
"bad integer `%s': %s"
2766 s (Printexc.to_string exc
)
2768 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2771 let mode = state.mode in
2774 let n, a, b = multicolumns_of_string s in
2775 setcolumns mode n a b;
2777 state.text <- Printf.sprintf
"bad columns `%s': %s"
2778 s (Printexc.to_string exc
)
2780 TEswitch
("columns: ", "", None
, textentry, ondone)
2785 let zoom = float (int_of_string
s) /. 100.0 in
2788 state.text <- Printf.sprintf
"bad integer `%s': %s"
2789 s (Printexc.to_string exc
)
2791 TEswitch
("zoom: ", "", None
, intentry, ondone)
2796 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2798 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2799 begin match mode with
2801 leavebirdseye beye
false;
2806 state.text <- Printf.sprintf
"bad integer `%s': %s"
2807 s (Printexc.to_string exc
)
2809 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2814 Some
(int_of_string
s)
2816 state.text <- Printf.sprintf
"bad integer `%s': %s"
2817 s (Printexc.to_string exc
);
2820 | Some angle
-> reqlayout angle
conf.proportional
2823 TEswitch
("rotation: ", "", None
, intentry, ondone)
2826 conf.icase
<- not
conf.icase
;
2827 TEdone
("case insensitive search " ^
(btos conf.icase
))
2830 conf.preload <- not
conf.preload;
2832 TEdone
("preload " ^
(btos conf.preload))
2835 conf.verbose
<- not
conf.verbose
;
2836 TEdone
("verbose " ^
(btos conf.verbose
))
2839 conf.debug
<- not
conf.debug
;
2840 TEdone
("debug " ^
(btos conf.debug
))
2843 conf.maxhfit
<- not
conf.maxhfit
;
2844 state.maxy <- calcheight ();
2845 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2848 conf.crophack
<- not
conf.crophack
;
2849 TEdone
("crophack " ^
btos conf.crophack
)
2853 match conf.maxwait
with
2855 conf.maxwait
<- Some infinity
;
2856 "always wait for page to complete"
2858 conf.maxwait
<- None
;
2859 "show placeholder if page is not ready"
2864 conf.underinfo
<- not
conf.underinfo
;
2865 TEdone
("underinfo " ^
btos conf.underinfo
)
2868 conf.savebmarks
<- not
conf.savebmarks
;
2869 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2875 match state.layout with
2880 conf.interpagespace <- int_of_string
s;
2881 docolumns conf.columns
;
2882 state.maxy <- calcheight ();
2883 let y = getpagey pageno in
2886 state.text <- Printf.sprintf
"bad integer `%s': %s"
2887 s (Printexc.to_string exc
)
2889 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2892 reqlayout conf.angle
(not
conf.proportional
);
2893 TEdone
("proportional display " ^
btos conf.proportional
)
2896 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2897 TEdone
("trim margins " ^
btos conf.trimmargins
)
2900 conf.invert
<- not
conf.invert
;
2901 TEdone
("invert colors " ^
btos conf.invert
)
2905 cbput state.hists
.sel
s;
2908 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2912 conf.fullsplit
<- not
conf.fullsplit
;
2914 TEdone
("full split " ^
btos conf.fullsplit
)
2917 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2923 class type lvsource
= object
2924 method getitemcount
: int
2925 method getitem
: int -> (string * int)
2926 method hasaction
: int -> bool
2935 method getactive
: int
2936 method getfirst
: int
2937 method getqsearch
: string
2938 method setqsearch
: string -> unit
2942 class virtual lvsourcebase
= object
2943 val mutable m_active
= 0
2944 val mutable m_first
= 0
2945 val mutable m_qsearch
= ""
2946 val mutable m_pan
= 0
2947 method getactive
= m_active
2948 method getfirst
= m_first
2949 method getqsearch
= m_qsearch
2950 method getpan
= m_pan
2951 method setqsearch
s = m_qsearch
<- s
2954 let withoutlastutf8 s =
2955 let len = String.length
s in
2963 let b = Char.code
s.[pos
] in
2964 if b land 0b110000 = 0b11000000
2969 if Char.code
s.[len-1] land 0x80 = 0
2973 String.sub
s 0 first;
2976 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2978 state.mode <- Textentry
(te
, onleave
);
2981 G.postRedisplay "textentrykeyboard enttext";
2983 let histaction cmd
=
2986 | Some
(action, _
) ->
2987 state.mode <- Textentry
(
2988 (c, action cmd
, opthist
, onkey
, ondone), onleave
2990 G.postRedisplay "textentry histaction"
2993 | 0xff08 -> (* backspace *)
2994 let s = withoutlastutf8 text in
2995 let len = String.length
s in
2999 G.postRedisplay "textentrykeyboard after cancel";
3002 enttext (c, s, opthist
, onkey
, ondone)
3008 G.postRedisplay "textentrykeyboard after confirm"
3010 | 0xff52 -> histaction HCprev
3011 | 0xff54 -> histaction HCnext
3012 | 0xff50 -> histaction HCfirst
3013 | 0xff57 -> histaction HClast
3015 | 0xff1b -> (* escape*)
3016 if String.length
text = 0
3018 begin match opthist
with
3020 | Some
(_
, onhistcancel
) -> onhistcancel
()
3024 G.postRedisplay "textentrykeyboard after cancel2"
3027 enttext (c, "", opthist
, onkey
, ondone)
3030 | 0xff9f | 0xffff -> () (* delete *)
3032 | _
when key != 0 && key land 0xff00 != 0xff00 ->
3033 begin match onkey
text key with
3037 G.postRedisplay "textentrykeyboard after confirm2";
3040 enttext (c, text, opthist
, onkey
, ondone);
3044 G.postRedisplay "textentrykeyboard after cancel3"
3047 state.mode <- Textentry
(te
, onleave
);
3048 G.postRedisplay "textentrykeyboard switch";
3052 vlog "unhandled key %s" (Wsi.keyname
key)
3055 let firstof first active
=
3056 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3057 then max
0 (active
- (fstate.maxrows
/2))
3061 let calcfirst first active
=
3064 let rows = active
- first in
3065 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3069 let scrollph y maxy =
3070 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
3071 let sh = float conf.winh
/. sh in
3072 let sh = max
sh (float conf.scrollh
) in
3077 else float y /. float maxy
3079 let position = (float conf.winh
-. sh) *. percent in
3082 if position +. sh > float conf.winh
3083 then float conf.winh
-. sh
3089 let coe s = (s :> uioh
);;
3091 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3093 val m_pan
= source#getpan
3094 val m_first
= source#getfirst
3095 val m_active
= source#getactive
3096 val m_qsearch
= source#getqsearch
3097 val m_prev_uioh
= state.uioh
3099 method private elemunder
y =
3100 let n = y / (fstate.fontsize
+1) in
3101 if m_first
+ n < source#getitemcount
3103 if source#hasaction
(m_first
+ n)
3104 then Some
(m_first
+ n)
3111 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3112 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3113 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3114 GlDraw.color
(1., 1., 1.);
3115 Gl.enable `texture_2d
;
3116 let fs = fstate.fontsize
in
3118 let ww = fstate.wwidth
in
3119 let tabw = 30.0*.ww in
3120 let itemcount = source#getitemcount
in
3122 if (row - m_first
) * nfs > conf.winh
3125 if row >= 0 && row < itemcount
3127 let (s, level
) = source#getitem
row in
3128 let y = (row - m_first
) * nfs in
3129 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3132 Gl.disable `texture_2d
;
3133 GlDraw.polygon_mode `both `line
;
3134 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3135 GlDraw.rect (1., float (y + 1))
3136 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3137 GlDraw.polygon_mode `both `fill
;
3138 GlDraw.color
(1., 1., 1.);
3139 Gl.enable `texture_2d
;
3142 let drawtabularstring s =
3143 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3146 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3149 let len = String.length
s - tabpos - 1 in
3150 let s1 = String.sub
s 0 tabpos
3151 and s2
= String.sub
s (tabpos + 1) len in
3152 let nx = drawstr x s1 in
3154 let x = x +. (max
tabw sw) in
3161 let _ = drawtabularstring s in
3168 Gl.disable `texture_2d
;
3170 method updownlevel incr
=
3171 let len = source#getitemcount
in
3173 if m_active
>= 0 && m_active
< len
3174 then snd
(source#getitem m_active
)
3178 if i
= len then i
-1 else if i
= -1 then 0 else
3179 let _, l = source#getitem i
in
3180 if l != curlevel then i
else flow (i
+incr
)
3182 let active = flow m_active
in
3183 let first = calcfirst m_first
active in
3184 G.postRedisplay "outline updownlevel";
3185 {< m_active
= active; m_first
= first >}
3187 method private key1
key mask
=
3188 let set1 active first qsearch
=
3189 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3191 let search active pattern incr
=
3194 if n >= 0 && n < source#getitemcount
3196 let s, _ = source#getitem
n in
3198 (try ignore
(Str.search_forward
re s 0); true
3199 with Not_found
-> false)
3201 else loop (n + incr
)
3208 let re = Str.regexp_case_fold pattern
in
3214 let itemcount = source#getitemcount
in
3215 let find start incr
=
3217 if i
= -1 || i
= itemcount
3220 if source#hasaction i
3222 else find (i
+ incr
)
3227 let set active first =
3228 let first = bound first 0 (itemcount - fstate.maxrows
) in
3230 coe {< m_active
= active; m_first
= first >}
3233 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3235 let incr1 = if incr
> 0 then 1 else -1 in
3236 if isvisible m_first m_active
3239 let next = m_active
+ incr
in
3241 if next < 0 || next >= itemcount
3243 else find next incr1
3245 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3251 let first = m_first
+ incr
in
3252 let first = bound first 0 (itemcount - 1) in
3254 let next = m_active
+ incr
in
3255 let next = bound next 0 (itemcount - 1) in
3258 let active = if next = -1 then m_active
else next in
3261 let first = min
next m_first
in
3263 if abs
(next - first) > fstate.maxrows
3269 let first = m_first
+ incr
in
3270 let first = bound first 0 (itemcount - 1) in
3272 let next = m_active
+ incr
in
3273 let next = bound next 0 (itemcount - 1) in
3274 let next = find next incr1 in
3276 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3278 let active = if m_active
= -1 then next else m_active
in
3283 if isvisible first active
3289 G.postRedisplay "listview navigate";
3293 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3294 let incr = if key = 0x72 then -1 else 1 in
3296 match search (m_active
+ incr) m_qsearch
incr with
3298 state.text <- m_qsearch ^
" [not found]";
3301 state.text <- m_qsearch
;
3302 active, firstof m_first
active
3304 G.postRedisplay "listview ctrl-r/s";
3305 set1 active first m_qsearch
;
3307 | 0xff08 -> (* backspace *)
3308 if String.length m_qsearch
= 0
3311 let qsearch = withoutlastutf8 m_qsearch
in
3312 let len = String.length
qsearch in
3316 G.postRedisplay "listview empty qsearch";
3317 set1 m_active m_first
"";
3321 match search m_active
qsearch ~
-1 with
3323 state.text <- qsearch ^
" [not found]";
3326 state.text <- qsearch;
3327 active, firstof m_first
active
3329 G.postRedisplay "listview backspace qsearch";
3330 set1 active first qsearch
3333 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3334 let pattern = m_qsearch ^
Wsi.toutf8
key in
3336 match search m_active
pattern 1 with
3338 state.text <- pattern ^
" [not found]";
3341 state.text <- pattern;
3342 active, firstof m_first
active
3344 G.postRedisplay "listview qsearch add";
3345 set1 active first pattern;
3347 | 0xff1b -> (* escape *)
3349 if String.length m_qsearch
= 0
3351 G.postRedisplay "list view escape";
3354 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3356 | None
-> m_prev_uioh
3361 G.postRedisplay "list view kill qsearch";
3362 source#setqsearch
"";
3363 coe {< m_qsearch
= "" >}
3366 | 0xff0d -> (* return *)
3368 let self = {< m_qsearch
= "" >} in
3369 source#setqsearch
"";
3371 G.postRedisplay "listview enter";
3372 if m_active
>= 0 && m_active
< source#getitemcount
3374 source#exit
(coe self) false m_active m_first m_pan
"";
3377 source#exit
(coe self) true m_active m_first m_pan
"";
3380 begin match opt with
3381 | None
-> m_prev_uioh
3385 | 0xff9f | 0xffff -> (* delete *)
3388 | 0xff52 -> navigate ~
-1 (* up *)
3389 | 0xff54 -> navigate 1 (* down *)
3390 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3391 | 0xff56 -> navigate fstate.maxrows
(* next *)
3393 | 0xff53 -> (* right *)
3395 G.postRedisplay "listview right";
3396 coe {< m_pan
= m_pan
- 1 >}
3398 | 0xff51 -> (* left *)
3400 G.postRedisplay "listview left";
3401 coe {< m_pan
= m_pan
+ 1 >}
3403 | 0xff50 -> (* home *)
3404 let active = find 0 1 in
3405 G.postRedisplay "listview home";
3408 | 0xff57 -> (* end *)
3409 let first = max
0 (itemcount - fstate.maxrows
) in
3410 let active = find (itemcount - 1) ~
-1 in
3411 G.postRedisplay "listview end";
3414 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3418 dolog "listview unknown key %#x" key; coe self
3420 method key key mask
=
3421 match state.mode with
3422 | Textentry te
-> textentrykeyboard key mask te
; coe self
3423 | _ -> self#key1
key mask
3425 method button button down
x y _ =
3428 | 1 when x > conf.winw
- conf.scrollbw
->
3429 G.postRedisplay "listview scroll";
3432 let _, position, sh = self#
scrollph in
3433 if y > truncate
position && y < truncate
(position +. sh)
3435 state.mstate
<- Mscrolly
;
3439 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3440 let first = truncate
(s *. float source#getitemcount
) in
3441 let first = min source#getitemcount
first in
3442 Some
(coe {< m_first
= first; m_active
= first >})
3444 state.mstate
<- Mnone
;
3447 | 1 when not down
->
3448 begin match self#elemunder
y with
3450 G.postRedisplay "listview click";
3452 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3456 | n when (n == 4 || n == 5) && not down
->
3457 let len = source#getitemcount
in
3459 if n = 5 && m_first
+ fstate.maxrows
>= len
3463 let first = m_first
+ (if n == 4 then -1 else 1) in
3464 bound first 0 (len - 1)
3466 G.postRedisplay "listview wheel";
3467 Some
(coe {< m_first
= first >})
3472 | None
-> m_prev_uioh
3476 match state.mstate
with
3478 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3479 let first = truncate
(s *. float source#getitemcount
) in
3480 let first = min source#getitemcount
first in
3481 G.postRedisplay "listview motion";
3482 coe {< m_first
= first; m_active
= first >}
3485 method pmotion
x y =
3486 if x < conf.winw
- conf.scrollbw
3489 match self#elemunder
y with
3490 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3491 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3495 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3500 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3504 method infochanged
_ = ()
3506 method scrollpw
= (0, 0.0, 0.0)
3508 let nfs = fstate.fontsize
+ 1 in
3509 let y = m_first
* nfs in
3510 let itemcount = source#getitemcount
in
3511 let maxi = max
0 (itemcount - fstate.maxrows
) in
3512 let maxy = maxi * nfs in
3513 let p, h = scrollph y maxy in
3516 method modehash
= modehash
3519 class outlinelistview ~source
=
3522 ~source
:(source
:> lvsource
)
3524 ~modehash
:(findkeyhash conf "outline")
3527 method key key mask
=
3528 let calcfirst first active =
3531 let rows = active - first in
3532 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3536 let active = m_active
+ incr in
3537 let active = bound active 0 (source#getitemcount
- 1) in
3538 let first = calcfirst m_first
active in
3539 G.postRedisplay "outline navigate";
3540 coe {< m_active
= active; m_first
= first >}
3542 let ctrl = Wsi.withctrl mask
in
3544 | 110 when ctrl -> (* ctrl-n *)
3545 source#narrow m_qsearch
;
3546 G.postRedisplay "outline ctrl-n";
3547 coe {< m_first
= 0; m_active
= 0 >}
3549 | 117 when ctrl -> (* ctrl-u *)
3551 G.postRedisplay "outline ctrl-u";
3553 coe {< m_first
= 0; m_active
= 0 >}
3555 | 108 when ctrl -> (* ctrl-l *)
3556 let first = m_active
- (fstate.maxrows
/ 2) in
3557 G.postRedisplay "outline ctrl-l";
3558 coe {< m_first
= first >}
3560 | 0xff9f | 0xffff -> (* delete *)
3561 source#remove m_active
;
3562 G.postRedisplay "outline delete";
3563 let active = max
0 (m_active
-1) in
3564 coe {< m_first
= firstof m_first
active;
3565 m_active
= active >}
3567 | 0xff52 -> navigate ~
-1 (* up *)
3568 | 0xff54 -> navigate 1 (* down *)
3569 | 0xff55 -> (* prior *)
3570 navigate ~
-(fstate.maxrows
)
3571 | 0xff56 -> (* next *)
3572 navigate fstate.maxrows
3574 | 0xff53 -> (* [ctrl-]right *)
3578 G.postRedisplay "outline ctrl right";
3579 {< m_pan
= m_pan
+ 1 >}
3581 else self#updownlevel
1
3585 | 0xff51 -> (* [ctrl-]left *)
3589 G.postRedisplay "outline ctrl left";
3590 {< m_pan
= m_pan
- 1 >}
3592 else self#updownlevel ~
-1
3596 | 0xff50 -> (* home *)
3597 G.postRedisplay "outline home";
3598 coe {< m_first
= 0; m_active
= 0 >}
3600 | 0xff57 -> (* end *)
3601 let active = source#getitemcount
- 1 in
3602 let first = max
0 (active - fstate.maxrows
) in
3603 G.postRedisplay "outline end";
3604 coe {< m_active
= active; m_first
= first >}
3606 | _ -> super#
key key mask
3609 let outlinesource usebookmarks
=
3612 inherit lvsourcebase
3613 val mutable m_items
= empty
3614 val mutable m_orig_items
= empty
3615 val mutable m_prev_items
= empty
3616 val mutable m_narrow_pattern
= ""
3617 val mutable m_hadremovals
= false
3619 method getitemcount
=
3620 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3623 if n == Array.length m_items
&& m_hadremovals
3625 ("[Confirm removal]", 0)
3627 let s, n, _ = m_items
.(n) in
3630 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3631 ignore
(uioh
, first, qsearch);
3632 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3634 if String.length m_narrow_pattern
= 0
3640 if not
confrimremoval
3642 let _, _, anchor = m_items
.(active) in
3647 state.bookmarks
<- Array.to_list m_items
;
3648 m_orig_items
<- m_items
;
3651 else m_items
<- items;
3655 method hasaction
_ = true
3658 if Array.length m_items
!= Array.length m_orig_items
3659 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3662 method narrow
pattern =
3663 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3667 let rec loop accu n =
3670 m_narrow_pattern
<- pattern;
3671 m_items
<- Array.of_list
accu
3674 let (s, _, _) as o = m_items
.(n) in
3676 if (try ignore
(Str.search_forward
re s 0); true
3677 with Not_found
-> false)
3683 loop [] (Array.length m_items
- 1)
3688 then Array.of_list
state.bookmarks
3691 m_items
<- m_orig_items
3696 if m >= 0 && m < Array.length m_items
3698 m_hadremovals
<- true;
3699 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3700 let n = if n >= m then n+1 else n in
3705 method reset
anchor items =
3706 m_hadremovals
<- false;
3707 if m_orig_items
== empty || m_prev_items
!= items
3709 m_orig_items
<- items;
3710 if String.length m_narrow_pattern
= 0
3711 then m_items
<- items;
3713 m_prev_items
<- items;
3714 let rely = getanchory anchor in
3716 let rec loop n best bestd
=
3717 if n = Array.length m_items
3720 let (_, _, anchor) = m_items
.(n) in
3721 let orely = getanchory anchor in
3722 let d = abs
(orely - rely) in
3725 else loop (n+1) best bestd
3730 m_first
<- firstof m_first
active
3734 let enterselector usebookmarks
=
3735 let source = outlinesource usebookmarks
in
3739 then Array.of_list
state.bookmarks
3742 if Array.length
outlines = 0
3744 showtext ' ' errmsg
;
3747 state.text <- source#greetmsg
;
3748 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3749 let anchor = getanchor () in
3750 source#reset
anchor outlines;
3751 state.uioh
<- coe (new outlinelistview ~
source);
3752 G.postRedisplay "enter selector";
3756 let enteroutlinemode =
3757 let f = enterselector false in
3758 fun ()-> f "Document has no outline";
3761 let enterbookmarkmode =
3762 let f = enterselector true in
3763 fun () -> f "Document has no bookmarks (yet)";
3766 let color_of_string s =
3767 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3768 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3772 let color_to_string (r
, g
, b) =
3773 let r = truncate
(r *. 256.0)
3774 and g
= truncate
(g
*. 256.0)
3775 and b = truncate
(b *. 256.0) in
3776 Printf.sprintf
"%d/%d/%d" r g
b
3779 let irect_of_string s =
3780 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3783 let irect_to_string (x0,y0,x1,y1) =
3784 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3787 let makecheckers () =
3788 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3790 converted by Issac Trotts. July 25, 2002 *)
3791 let image_height = 64
3792 and image_width
= 64 in
3796 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3798 for i
= 0 to image_width
- 1 do
3799 for j
= 0 to image_height - 1 do
3800 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3801 (if (i
land 8 ) lxor (j
land 8) = 0
3802 then [|255;255;255|] else [|200;200;200|])
3807 let image = make_image () in
3808 let id = GlTex.gen_texture
() in
3809 GlTex.bind_texture `texture_2d
id;
3810 GlPix.store
(`unpack_alignment
1);
3811 GlTex.image2d
image;
3812 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3815 `mag_filter `nearest
;
3816 `min_filter `nearest
];
3820 let setcheckers enabled
=
3821 match state.texid
with
3823 if enabled
then state.texid
<- Some
(makecheckers ())
3828 GlTex.delete_texture texid
;
3829 state.texid
<- None
;
3833 let int_of_string_with_suffix s =
3834 let l = String.length
s in
3838 let suffix = Char.lowercase
s.[l-1] in
3840 | 'k'
-> String.sub
s 0 (l-1), 10
3841 | '
m'
-> String.sub
s 0 (l-1), 20
3842 | 'g'
-> String.sub
s 0 (l-1), 30
3846 let n = int_of_string
s1 in
3847 let m = n lsl shift
in
3849 then raise
(Failure
"value too large")
3853 let string_with_suffix_of_int n =
3861 if n land ((1 lsl 20) - 1) = 0
3864 if n land ((1 lsl 10) - 1) = 0
3871 let h = n mod 1000 in
3874 then string_of_int
h ^
s
3876 let s = Printf.sprintf
"_%03d%s" h s in
3883 let defghyllscroll = (40, 8, 32);;
3884 let ghyllscroll_of_string s =
3885 let (n, a, b) as nab
=
3888 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3890 if n <= a || n <= b || a >= b
3891 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3895 let ghyllscroll_to_string ((n, a, b) as nab
) =
3896 if nab
= defghyllscroll
3898 else Printf.sprintf
"%d,%d,%d" n a b;
3901 let describe_location () =
3903 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3905 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3906 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3910 else (100. *. (float state.y /. float maxy))
3914 Printf.sprintf
"page %d of %d [%.2f%%]"
3915 (fn+1) state.pagecount
percent
3918 "pages %d-%d of %d [%.2f%%]"
3919 (fn+1) (ln
+1) state.pagecount
percent
3923 let btos b = if b then "\xe2\x88\x9a" else "" in
3924 let showextended = ref false in
3925 let leave mode = function
3926 | Confirm
-> state.mode <- mode
3927 | Cancel
-> state.mode <- mode in
3930 val mutable m_first_time
= true
3931 val mutable m_l
= []
3932 val mutable m_a
= [||]
3933 val mutable m_prev_uioh
= nouioh
3934 val mutable m_prev_mode
= View
3936 inherit lvsourcebase
3938 method reset prev_mode prev_uioh
=
3939 m_a
<- Array.of_list
(List.rev m_l
);
3941 m_prev_mode
<- prev_mode
;
3942 m_prev_uioh
<- prev_uioh
;
3946 if n >= Array.length m_a
3950 | _, _, _, Action
_ -> m_active
<- n
3954 m_first_time
<- false;
3957 method int name get
set =
3959 (name
, `
int get
, 1, Action
(
3962 try set (int_of_string
s)
3964 state.text <- Printf.sprintf
"bad integer `%s': %s"
3965 s (Printexc.to_string exn
)
3968 let te = name ^
": ", "", None
, intentry, ondone in
3969 state.mode <- Textentry
(te, leave m_prev_mode
);
3973 method int_with_suffix name get
set =
3975 (name
, `intws get
, 1, Action
(
3978 try set (int_of_string_with_suffix s)
3980 state.text <- Printf.sprintf
"bad integer `%s': %s"
3981 s (Printexc.to_string exn
)
3985 name ^
": ", "", None
, intentry_with_suffix, ondone
3987 state.mode <- Textentry
(te, leave m_prev_mode
);
3991 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3993 (name
, `
bool (btos, get
), offset
, Action
(
4000 method color name get
set =
4002 (name
, `color get
, 1, Action
(
4004 let invalid = (nan
, nan
, nan
) in
4007 try color_of_string s
4009 state.text <- Printf.sprintf
"bad color `%s': %s"
4010 s (Printexc.to_string exn
);
4016 let te = name ^
": ", "", None
, textentry, ondone in
4017 state.text <- color_to_string (get
());
4018 state.mode <- Textentry
(te, leave m_prev_mode
);
4022 method string name get
set =
4024 (name
, `
string get
, 1, Action
(
4026 let ondone s = set s in
4027 let te = name ^
": ", "", None
, textentry, ondone in
4028 state.mode <- Textentry
(te, leave m_prev_mode
);
4032 method colorspace name get
set =
4034 (name
, `
string get
, 1, Action
(
4037 let vals = [| "rgb"; "bgr"; "gray" |] in
4039 inherit lvsourcebase
4042 m_active
<- int_of_colorspace conf.colorspace
;
4045 method getitemcount
= Array.length
vals
4046 method getitem
n = (vals.(n), 0)
4047 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4048 ignore
(uioh
, first, pan
, qsearch);
4049 if not cancel
then set active;
4051 method hasaction
_ = true
4055 let modehash = findkeyhash conf "info" in
4056 coe (new listview ~
source ~trusted
:true ~
modehash)
4059 method caption
s offset
=
4060 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4062 method caption2
s f offset
=
4063 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4065 method getitemcount
= Array.length m_a
4068 let tostr = function
4069 | `
int f -> string_of_int
(f ())
4070 | `intws
f -> string_with_suffix_of_int (f ())
4072 | `color
f -> color_to_string (f ())
4073 | `
bool (btos, f) -> btos (f ())
4076 let name, t
, offset
, _ = m_a
.(n) in
4077 ((let s = tostr t
in
4078 if String.length
s > 0
4079 then Printf.sprintf
"%s\t%s" name s
4083 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4087 m_qsearch
<- qsearch;
4089 match m_a
.(active) with
4090 | _, _, _, Action
f -> f uioh
4102 method hasaction
n =
4104 | _, _, _, Action
_ -> true
4108 let rec fillsrc prevmode prevuioh
=
4109 let sep () = src#caption
"" 0 in
4110 let colorp name get
set =
4112 (fun () -> color_to_string (get
()))
4115 let c = color_of_string v in
4118 state.text <- Printf.sprintf
"bad color `%s': %s"
4119 v (Printexc.to_string exn
);
4122 let oldmode = state.mode in
4123 let birdseye = isbirdseye state.mode in
4125 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4127 src#
bool "presentation mode"
4128 (fun () -> conf.presentation)
4130 conf.presentation <- v;
4131 state.anchor <- getanchor ();
4134 src#
bool "ignore case in searches"
4135 (fun () -> conf.icase
)
4136 (fun v -> conf.icase
<- v);
4139 (fun () -> conf.preload)
4140 (fun v -> conf.preload <- v);
4142 src#
bool "highlight links"
4143 (fun () -> conf.hlinks
)
4144 (fun v -> conf.hlinks
<- v);
4146 src#
bool "under info"
4147 (fun () -> conf.underinfo
)
4148 (fun v -> conf.underinfo
<- v);
4150 src#
bool "persistent bookmarks"
4151 (fun () -> conf.savebmarks
)
4152 (fun v -> conf.savebmarks
<- v);
4154 src#
bool "proportional display"
4155 (fun () -> conf.proportional
)
4156 (fun v -> reqlayout conf.angle
v);
4158 src#
bool "trim margins"
4159 (fun () -> conf.trimmargins
)
4160 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4162 src#
bool "persistent location"
4163 (fun () -> conf.jumpback
)
4164 (fun v -> conf.jumpback
<- v);
4167 src#
int "inter-page space"
4168 (fun () -> conf.interpagespace)
4170 conf.interpagespace <- n;
4171 docolumns conf.columns
;
4173 match state.layout with
4178 state.maxy <- calcheight ();
4179 let y = getpagey pageno in
4184 (fun () -> conf.pagebias
)
4185 (fun v -> conf.pagebias
<- v);
4187 src#
int "scroll step"
4188 (fun () -> conf.scrollstep
)
4189 (fun n -> conf.scrollstep
<- n);
4191 src#
int "auto scroll step"
4193 match state.autoscroll
with
4195 | _ -> conf.autoscrollstep
)
4197 if state.autoscroll
<> None
4198 then state.autoscroll
<- Some
n;
4199 conf.autoscrollstep
<- n);
4202 (fun () -> truncate
(conf.zoom *. 100.))
4203 (fun v -> setzoom ((float v) /. 100.));
4206 (fun () -> conf.angle
)
4207 (fun v -> reqlayout v conf.proportional
);
4209 src#
int "scroll bar width"
4210 (fun () -> state.scrollw
)
4214 reshape conf.winw
conf.winh
;
4217 src#
int "scroll handle height"
4218 (fun () -> conf.scrollh
)
4219 (fun v -> conf.scrollh
<- v;);
4221 src#
int "thumbnail width"
4222 (fun () -> conf.thumbw
)
4224 conf.thumbw
<- min
4096 v;
4227 leavebirdseye beye
false;
4232 let mode = state.mode in
4233 src#
string "columns"
4235 match conf.columns
with
4237 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4238 | Csplit
(count
, _) -> "-" ^ string_of_int count
4241 let n, a, b = multicolumns_of_string v in
4242 setcolumns mode n a b);
4245 src#caption
"Presentation mode" 0;
4246 src#
bool "scrollbar visible"
4247 (fun () -> conf.scrollbarinpm
)
4249 if v != conf.scrollbarinpm
4251 conf.scrollbarinpm
<- v;
4252 if conf.presentation
4254 state.scrollw
<- if v then conf.scrollbw
else 0;
4255 reshape conf.winw
conf.winh
;
4261 src#caption
"Pixmap cache" 0;
4262 src#int_with_suffix
"size (advisory)"
4263 (fun () -> conf.memlimit
)
4264 (fun v -> conf.memlimit
<- v);
4267 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4268 (string_with_suffix_of_int state.memused
)
4269 (Hashtbl.length
state.tilemap
)) 1;
4272 src#caption
"Layout" 0;
4273 src#caption2
"Dimension"
4275 Printf.sprintf
"%dx%d (virtual %dx%d)"
4281 src#caption2
"Position" (fun () ->
4282 Printf.sprintf
"%dx%d" state.x state.y
4285 src#caption2
"Visible" (fun () -> describe_location ()) 1
4289 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4290 "Save these parameters as global defaults at exit"
4291 (fun () -> conf.bedefault
)
4292 (fun v -> conf.bedefault
<- v)
4296 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4297 src#
bool ~offset
:0 ~
btos "Extended parameters"
4298 (fun () -> !showextended)
4299 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4303 (fun () -> conf.checkers
)
4304 (fun v -> conf.checkers
<- v; setcheckers v);
4305 src#
bool "update cursor"
4306 (fun () -> conf.updatecurs
)
4307 (fun v -> conf.updatecurs
<- v);
4309 (fun () -> conf.verbose
)
4310 (fun v -> conf.verbose
<- v);
4311 src#
bool "full split"
4312 (fun () -> conf.fullsplit
)
4313 (fun v -> conf.fullsplit
<- v; gotoy state.y);
4314 src#
bool "invert colors"
4315 (fun () -> conf.invert
)
4316 (fun v -> conf.invert
<- v);
4318 (fun () -> conf.maxhfit
)
4319 (fun v -> conf.maxhfit
<- v);
4320 src#
bool "redirect stderr"
4321 (fun () -> conf.redirectstderr)
4322 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4323 src#
string "uri launcher"
4324 (fun () -> conf.urilauncher
)
4325 (fun v -> conf.urilauncher
<- v);
4326 src#
string "path launcher"
4327 (fun () -> conf.pathlauncher
)
4328 (fun v -> conf.pathlauncher
<- v);
4329 src#
string "tile size"
4330 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4333 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4334 conf.tilew
<- max
64 w;
4335 conf.tileh
<- max
64 h;
4338 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4339 v (Printexc.to_string exn
));
4340 src#
int "texture count"
4341 (fun () -> conf.texcount
)
4344 then conf.texcount
<- v
4345 else showtext '
!'
" Failed to set texture count please retry later"
4347 src#
int "slice height"
4348 (fun () -> conf.sliceheight
)
4350 conf.sliceheight
<- v;
4351 wcmd "sliceh %d" conf.sliceheight
;
4353 src#
int "anti-aliasing level"
4354 (fun () -> conf.aalevel
)
4356 conf.aalevel
<- bound v 0 8;
4357 state.anchor <- getanchor ();
4358 opendoc state.path
state.password
;
4360 src#
int "ui font size"
4361 (fun () -> fstate.fontsize
)
4362 (fun v -> setfontsize (bound v 5 100));
4363 src#
int "hint font size"
4364 (fun () -> conf.hfsize
)
4365 (fun v -> conf.hfsize
<- bound v 5 100);
4366 colorp "background color"
4367 (fun () -> conf.bgcolor
)
4368 (fun v -> conf.bgcolor
<- v);
4369 src#
bool "crop hack"
4370 (fun () -> conf.crophack
)
4371 (fun v -> conf.crophack
<- v);
4372 src#
string "trim fuzz"
4373 (fun () -> irect_to_string conf.trimfuzz
)
4376 conf.trimfuzz
<- irect_of_string v;
4378 then settrim true conf.trimfuzz
;
4380 state.text <- Printf.sprintf
"bad irect `%s': %s"
4381 v (Printexc.to_string exn
)
4383 src#
string "throttle"
4385 match conf.maxwait
with
4386 | None
-> "show place holder if page is not ready"
4389 then "wait for page to fully render"
4391 "wait " ^ string_of_float
time
4392 ^
" seconds before showing placeholder"
4396 let f = float_of_string
v in
4398 then conf.maxwait
<- None
4399 else conf.maxwait
<- Some
f
4401 state.text <- Printf.sprintf
"bad time `%s': %s"
4402 v (Printexc.to_string exn
)
4404 src#
string "ghyll scroll"
4406 match conf.ghyllscroll
with
4408 | Some nab
-> ghyllscroll_to_string nab
4413 if String.length
v = 0
4415 else Some
(ghyllscroll_of_string v)
4417 conf.ghyllscroll
<- gs
4419 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4420 v (Printexc.to_string exn
)
4422 src#
string "selection command"
4423 (fun () -> conf.selcmd
)
4424 (fun v -> conf.selcmd
<- v);
4425 src#colorspace
"color space"
4426 (fun () -> colorspace_to_string conf.colorspace
)
4428 conf.colorspace
<- colorspace_of_int v;
4435 src#caption
"Document" 0;
4436 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4437 src#caption2
"Pages"
4438 (fun () -> string_of_int
state.pagecount
) 1;
4439 src#caption2
"Dimensions"
4440 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4444 src#caption
"Trimmed margins" 0;
4445 src#caption2
"Dimensions"
4446 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4449 src#reset prevmode prevuioh
;
4453 let prevmode = state.mode
4454 and prevuioh
= state.uioh in
4455 fillsrc prevmode prevuioh
;
4456 let source = (src :> lvsource
) in
4457 let modehash = findkeyhash conf "info" in
4458 state.uioh <- coe (object (self)
4459 inherit listview ~
source ~trusted
:true ~
modehash as super
4460 val mutable m_prevmemused
= 0
4461 method infochanged
= function
4463 if m_prevmemused
!= state.memused
4465 m_prevmemused
<- state.memused
;
4466 G.postRedisplay "memusedchanged";
4468 | Pdim
-> G.postRedisplay "pdimchanged"
4469 | Docinfo
-> fillsrc prevmode prevuioh
4471 method key key mask
=
4472 if not
(Wsi.withctrl mask
)
4475 | 0xff51 -> coe (self#updownlevel ~
-1)
4476 | 0xff53 -> coe (self#updownlevel
1)
4477 | _ -> super#
key key mask
4478 else super#
key key mask
4480 G.postRedisplay "info";
4486 inherit lvsourcebase
4487 method getitemcount
= Array.length
state.help
4489 let s, n, _ = state.help
.(n) in
4492 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4496 m_qsearch
<- qsearch;
4497 match state.help
.(active) with
4498 | _, _, Action
f -> Some
(f uioh)
4508 method hasaction
n =
4509 match state.help
.(n) with
4510 | _, _, Action
_ -> true
4517 let modehash = findkeyhash conf "help" in
4518 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4519 G.postRedisplay "help";
4524 let re = Str.regexp
"[\r\n]" in
4526 inherit lvsourcebase
4527 val mutable m_items
= [||]
4529 method getitemcount
= 1 + Array.length m_items
4534 else m_items
.(n-1), 0
4536 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4541 then Buffer.clear
state.errmsgs
;
4542 m_qsearch
<- qsearch;
4549 method hasaction
n =
4553 state.newerrmsgs
<- false;
4554 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4555 m_items
<- Array.of_list
l
4563 let source = (msgsource :> lvsource
) in
4564 let modehash = findkeyhash conf "listview" in
4565 state.uioh <- coe (object
4566 inherit listview ~
source ~trusted
:false ~
modehash as super
4569 then msgsource#reset
;
4572 G.postRedisplay "msgs";
4575 let quickbookmark ?title
() =
4576 match state.layout with
4582 let sec = Unix.gettimeofday
() in
4583 let tm = Unix.localtime
sec in
4584 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4588 (tm.Unix.tm_year
+ 1900)
4591 | Some
title -> title
4594 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4599 state.fullscreen
<- None
;
4603 let setautoscrollspeed step goingdown
=
4604 let incr = max
1 ((abs step
) / 2) in
4605 let incr = if goingdown
then incr else -incr in
4606 let astep = step
+ incr in
4607 state.autoscroll
<- Some
astep;
4610 let gotounder = function
4611 | Ulinkgoto
(pageno, top) ->
4615 gotopage1 pageno top;
4621 | Uremote
(filename
, pageno) ->
4623 if Sys.file_exists filename
4626 let dir = Filename.dirname
state.path in
4627 let path = Filename.concat
dir filename
in
4628 if Sys.file_exists
path
4632 if String.length
path > 0
4634 let anchor = getanchor () in
4635 let ranchor = state.path, state.password
, anchor in
4636 state.anchor <- (pageno, 0.0);
4637 state.ranchors
<- ranchor :: state.ranchors
;
4640 else showtext '
!'
("Could not find " ^ filename
)
4642 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4646 match conf.columns
with
4648 | _ -> conf.zoom > 1.0
4651 let viewkeyboard key mask
=
4653 let mode = state.mode in
4654 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4657 G.postRedisplay "view:enttext"
4659 let ctrl = Wsi.withctrl mask
in
4664 | 0xff63 -> (* insert *)
4665 if conf.angle
mod 360 = 0
4667 state.mode <- LinkNav
(Ltgendir
0);
4670 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4672 | 0xff1b | 113 -> (* escape / q *)
4673 begin match state.mstate
with
4675 state.mstate
<- Mnone
;
4676 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4677 G.postRedisplay "kill zoom rect";
4679 match state.ranchors
with
4681 | (path, password
, anchor) :: rest
->
4682 state.ranchors
<- rest
;
4683 state.anchor <- anchor;
4684 opendoc path password
4687 | 0xff08 -> (* backspace *)
4688 let y = getnav ~
-1 in
4689 gotoy_and_clear_text y
4697 G.postRedisplay "dehighlight";
4699 | 47 | 63 -> (* / ? *)
4700 let ondone isforw
s =
4701 cbput state.hists
.pat
s;
4702 state.searchpattern
<- s;
4705 let s = String.create
1 in
4706 s.[0] <- Char.chr
key;
4707 enttext (s, "", Some
(onhist state.hists
.pat
),
4708 textentry, ondone (key = 47))
4710 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4711 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4712 setzoom (conf.zoom +. incr)
4714 | 43 | 0xffab -> (* + *)
4717 try int_of_string
s with exc
->
4718 state.text <- Printf.sprintf
"bad integer `%s': %s"
4719 s (Printexc.to_string exc
);
4725 state.text <- "page bias is now " ^ string_of_int
n;
4728 enttext ("page bias: ", "", None
, intentry, ondone)
4730 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4731 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4732 setzoom (max
0.01 (conf.zoom -. decr))
4734 | 45 | 0xffad -> (* - *)
4735 let ondone msg
= state.text <- msg
in
4737 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4738 optentry state.mode, ondone
4741 | 48 when ctrl -> (* ctrl-0 *)
4744 | 49 when ctrl -> (* 1 *)
4745 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4749 | 0xffc6 -> (* f9 *)
4752 | 57 when ctrl -> (* ctrl-9 *)
4755 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4756 when not
ctrl -> (* 0..9 *)
4759 try int_of_string
s with exc
->
4760 state.text <- Printf.sprintf
"bad integer `%s': %s"
4761 s (Printexc.to_string exc
);
4767 cbput state.hists
.pag
(string_of_int
n);
4768 gotopage1 (n + conf.pagebias
- 1) 0;
4771 let pageentry text key =
4772 match Char.unsafe_chr
key with
4773 | 'g'
-> TEdone
text
4774 | _ -> intentry text key
4776 let text = "x" in text.[0] <- Char.chr
key;
4777 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4780 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4781 reshape conf.winw
conf.winh
;
4784 conf.hlinks
<- not
conf.hlinks
;
4785 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4786 G.postRedisplay "toggle highlightlinks";
4789 state.glinks
<- true;
4790 let mode = state.mode in
4791 state.mode <- Textentry
(
4792 (":", "", None
, linknentry, linkndone (fun under ->
4797 state.glinks
<- false;
4801 G.postRedisplay "view:linkent(F)"
4804 state.glinks
<- true;
4805 let mode = state.mode in
4806 state.mode <- Textentry
(
4807 (":", "", None
, linknentry, linkndone (fun under ->
4808 match Ne.pipe () with
4810 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4811 (Printexc.to_string exn
));
4814 try popen conf.selcmd
[r, 0; w, -1]; true
4817 (Printf.sprintf
"failed to execute %s: %s"
4818 conf.selcmd
(Printexc.to_string exn
));
4822 Ne.clo fd
(fun msg
->
4823 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4826 let s = undertext under in
4830 let l = String.length
s in
4831 let n = Unix.write
w s 0 l in
4836 "failed to write %d characters to sel pipe, wrote %d"
4841 (Printf.sprintf
"failed to write to sel pipe: %s"
4842 (Printexc.to_string exn
)
4851 state.glinks
<- false;
4855 G.postRedisplay "view:linkent"
4858 begin match state.autoscroll
with
4860 conf.autoscrollstep
<- step
;
4861 state.autoscroll
<- None
4863 if conf.autoscrollstep
= 0
4864 then state.autoscroll
<- Some
1
4865 else state.autoscroll
<- Some
conf.autoscrollstep
4868 | 112 when ctrl -> (* ctrl-p *)
4872 conf.presentation <- not
conf.presentation;
4873 if conf.presentation
4875 if not
conf.scrollbarinpm
4876 then state.scrollw
<- 0;
4879 state.scrollw
<- conf.scrollbw
;
4881 showtext ' '
("presentation mode " ^
4882 if conf.presentation then "on" else "off");
4883 state.anchor <- getanchor ();
4887 begin match state.fullscreen
with
4889 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4892 state.fullscreen
<- None
;
4897 gotoy_and_clear_text 0
4900 gotopage1 (state.pagecount
- 1) 0
4902 | 112 | 78 -> (* p|N *)
4903 search state.searchpattern
false
4905 | 110 | 0xffc0 -> (* n|F3 *)
4906 search state.searchpattern
true
4909 begin match state.layout with
4912 gotoy_and_clear_text (getpagey l.pageno)
4916 begin match List.rev
state.layout with
4919 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4920 gotoy_and_clear_text (getpagey pageno)
4923 | 0xff9f | 0xffff -> (* delete *)
4924 begin match state.layout with
4927 let pageno = max
0 (l.pageno-1) in
4928 gotoy_and_clear_text (getpagey pageno)
4932 showtext ' '
(describe_location ());
4935 begin match state.layout with
4938 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4943 enterbookmarkmode ()
4945 | 104 | 0xffbe -> (* h|F1 *)
4951 | 101 when conf.redirectstderr -> (* e *)
4956 match state.layout with
4959 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4963 enttext ("bookmark: ", "", None
, textentry, ondone)
4967 showtext ' '
"Quick bookmark added";
4970 begin match state.layout with
4972 let rect = getpdimrect
l.pagedimno
in
4976 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4977 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4979 (truncate
(rect.(1) -. rect.(0)),
4980 truncate
(rect.(3) -. rect.(0)))
4982 let w = truncate
((float w)*.conf.zoom)
4983 and h = truncate
((float h)*.conf.zoom) in
4986 state.anchor <- getanchor ();
4987 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4989 G.postRedisplay "z";
4994 | 50 when ctrl -> (* ctrl-2 *)
4995 let maxw = getmaxw
() in
4997 then setzoom (maxw /. float conf.winw
)
4999 | 60 | 62 -> (* < > *)
5000 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5002 | 91 | 93 -> (* [ ] *)
5004 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5006 G.postRedisplay "brightness";
5008 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5009 setzoom state.prevzoom
5011 | 107 | 0xff52 -> (* k up *)
5012 begin match state.autoscroll
with
5014 begin match state.mode with
5015 | Birdseye beye
-> upbirdseye 1 beye
5018 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5019 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5022 setautoscrollspeed n false
5025 | 106 | 0xff54 -> (* j down *)
5026 begin match state.autoscroll
with
5028 begin match state.mode with
5029 | Birdseye beye
-> downbirdseye 1 beye
5032 then gotoy_and_clear_text (clamp (conf.winh
/2))
5033 else gotoy_and_clear_text (clamp conf.scrollstep
)
5036 setautoscrollspeed n true
5039 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5047 let dx = if key = 0xff51 then dx else -dx in
5048 state.x <- state.x + dx;
5049 gotoy_and_clear_text state.y
5052 G.postRedisplay "lef/right"
5055 | 0xff55 -> (* prior *)
5059 match state.layout with
5061 | l :: _ -> state.y - l.pagey
5067 | 0xff56 -> (* next *)
5071 match List.rev
state.layout with
5073 | l :: _ -> getpagey l.pageno
5079 | 0xff50 -> gotoghyll 0
5080 | 0xff57 -> gotoghyll (clamp state.maxy)
5081 | 0xff53 when Wsi.withalt mask
->
5082 gotoghyll (getnav ~
-1)
5083 | 0xff51 when Wsi.withalt mask
->
5084 gotoghyll (getnav 1)
5087 state.anchor <- getanchor ();
5088 opendoc state.path state.password
5090 | 118 when conf.debug
-> (* v *)
5093 match getopaque l.pageno with
5096 let x0, y0, x1, y1 = pagebbox opaque
in
5097 let a,b = float x0, float y0 in
5098 let c,d = float x1, float y0 in
5099 let e,f = float x1, float y1 in
5100 let h,j
= float x0, float y1 in
5101 let rect = (a,b,c,d,e,f,h,j
) in
5103 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5105 G.postRedisplay "v";
5108 vlog "huh? %s" (Wsi.keyname
key)
5111 let linknavkeyboard key mask
linknav =
5112 let getpage pageno =
5113 let rec loop = function
5115 | l :: _ when l.pageno = pageno -> Some
l
5116 | _ :: rest
-> loop rest
5117 in loop state.layout
5119 let doexact (pageno, n) =
5120 match getopaque pageno, getpage pageno with
5121 | Some opaque
, Some
l ->
5124 let under = getlink opaque
n in
5125 G.postRedisplay "link gotounder";
5131 | 0xff50 -> (* home *)
5132 Some
(findlink opaque LDfirst
), -1
5134 | 0xff57 -> (* end *)
5135 Some
(findlink opaque LDlast
), 1
5137 | 0xff51 -> (* left *)
5138 Some
(findlink opaque
(LDleft
n)), -1
5140 | 0xff53 -> (* right *)
5141 Some
(findlink opaque
(LDright
n)), 1
5143 | 0xff52 -> (* up *)
5144 Some
(findlink opaque
(LDup
n)), -1
5146 | 0xff54 -> (* down *)
5147 Some
(findlink opaque
(LDdown
n)), 1
5152 begin match findpwl
l.pageno dir with
5156 state.mode <- LinkNav
(Ltgendir
dir);
5157 let y, h = getpageyh pageno in
5160 then y + h - conf.winh
5165 begin match getopaque pageno, getpage pageno with
5166 | Some opaque
, Some
_ ->
5168 let ld = if dir > 0 then LDfirst
else LDlast
in
5171 begin match link with
5173 showlinktype (getlink opaque
m);
5174 state.mode <- LinkNav
(Ltexact
(pageno, m));
5175 G.postRedisplay "linknav jpage";
5182 begin match opt with
5183 | Some Lnotfound
-> pwl l dir;
5184 | Some
(Lfound
m) ->
5188 let _, y0, _, y1 = getlinkrect opaque
m in
5190 then gotopage1 l.pageno y0
5192 let d = fstate.fontsize
+ 1 in
5193 if y1 - l.pagey > l.pagevh - d
5194 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5195 else G.postRedisplay "linknav";
5197 showlinktype (getlink opaque
m);
5198 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5201 | None
-> viewkeyboard key mask
5203 | _ -> viewkeyboard key mask
5208 G.postRedisplay "leave linknav"
5212 | Ltgendir
_ -> viewkeyboard key mask
5213 | Ltexact exact
-> doexact exact
5216 let keyboard key mask
=
5217 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5218 then wcmd "interrupt"
5219 else state.uioh <- state.uioh#
key key mask
5222 let birdseyekeyboard key mask
5223 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5225 match conf.columns
with
5227 | Cmulti
((c, _, _), _) -> c
5228 | Csplit
_ -> failwith
"bird's eye split mode"
5231 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5232 let y, h = getpageyh pageno in
5233 let top = (conf.winh
- h) / 2 in
5234 gotoy (max
0 (y - top))
5235 | 0xff0d -> leavebirdseye beye
false
5236 | 0xff1b -> leavebirdseye beye
true (* escape *)
5237 | 0xff52 -> upbirdseye incr beye
(* prior *)
5238 | 0xff54 -> downbirdseye incr beye
(* next *)
5239 | 0xff51 -> upbirdseye 1 beye
(* up *)
5240 | 0xff53 -> downbirdseye 1 beye
(* down *)
5243 begin match state.layout with
5247 state.mode <- Birdseye
(
5248 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5250 gotopage1 l.pageno 0;
5253 let layout = layout (state.y-conf.winh
) conf.winh
in
5255 | [] -> gotoy (clamp (-conf.winh
))
5257 state.mode <- Birdseye
(
5258 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5260 gotopage1 l.pageno 0
5263 | [] -> gotoy (clamp (-conf.winh
))
5267 begin match List.rev
state.layout with
5269 let layout = layout (state.y + conf.winh
) conf.winh
in
5270 begin match layout with
5272 let incr = l.pageh
- l.pagevh in
5277 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5279 G.postRedisplay "birdseye pagedown";
5281 else gotoy (clamp (incr + conf.interpagespace*2));
5285 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5286 gotopage1 l.pageno 0;
5289 | [] -> gotoy (clamp conf.winh
)
5293 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5297 let pageno = state.pagecount
- 1 in
5298 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5299 if not
(pagevisible state.layout pageno)
5302 match List.rev
state.pdims
with
5304 | (_, _, h, _) :: _ -> h
5306 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5307 else G.postRedisplay "birdseye end";
5308 | _ -> viewkeyboard key mask
5311 let drawpage l linkindexbase
=
5313 match state.mode with
5314 | Textentry
_ -> scalecolor 0.4
5316 | View
-> scalecolor 1.0
5317 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5318 if l.pageno = hooverpageno
5321 if l.pageno = pageno
5327 begin match getopaque l.pageno with
5329 if tileready l l.pagex l.pagey
5331 let x = l.pagedispx - l.pagex
5332 and y = l.pagedispy - l.pagey in
5333 let hlmask = (if conf.hlinks
then 1 else 0)
5334 + (if state.glinks
&& not
(isbirdseye state.mode) then 2 else 0)
5337 match state.mode with
5338 | Textentry
((_, s, _, _, _), _) when state.glinks
-> s
5341 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5348 let scrollindicator () =
5349 let sbw, ph
, sh = state.uioh#
scrollph in
5350 let sbh, pw, sw = state.uioh#scrollpw
in
5352 GlDraw.color (0.64, 0.64, 0.64);
5354 (float (conf.winw
- sbw), 0.)
5355 (float conf.winw
, float conf.winh
)
5358 (0., float (conf.winh
- sbh))
5359 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5361 GlDraw.color (0.0, 0.0, 0.0);
5364 (float (conf.winw
- sbw), ph
)
5365 (float conf.winw
, ph
+. sh)
5368 (pw, float (conf.winh
- sbh))
5369 (pw +. sw, float conf.winh
)
5374 match state.mstate
with
5375 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5378 | Msel
((x0, y0), (x1, y1)) ->
5379 let rec loop = function
5381 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5382 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5383 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5384 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5386 match getopaque l.pageno with
5388 let x0, y0 = pagetranslatepoint l x0 y0 in
5389 let x1, y1 = pagetranslatepoint l x1 y1 in
5390 seltext opaque
(x0, y0, x1, y1);
5398 let showrects rects
=
5400 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5401 GlDraw.polygon_mode `both `fill
;
5402 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5404 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5406 if l.pageno = pageno
5408 let dx = float (l.pagedispx - l.pagex) in
5409 let dy = float (l.pagedispy - l.pagey) in
5410 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5411 GlDraw.begins `quads
;
5413 GlDraw.vertex2
(x0+.dx, y0+.dy);
5414 GlDraw.vertex2
(x1+.dx, y1+.dy);
5415 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5416 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5427 GlClear.color (scalecolor2 conf.bgcolor
);
5428 GlClear.clear
[`
color];
5429 let rec loop linkindexbase
= function
5431 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5432 loop linkindexbase rest
5435 loop 0 state.layout;
5437 match state.mode with
5438 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5439 begin match getopaque pageno with
5441 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5448 | None
-> state.rects
5455 begin match state.mstate
with
5456 | Mzoomrect
((x0, y0), (x1, y1)) ->
5458 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5459 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5460 GlDraw.rect (float x0, float y0)
5461 (float x1, float y1);
5470 let zoomrect x y x1 y1 =
5473 and y0 = min
y y1 in
5474 gotoy (state.y + y0);
5475 state.anchor <- getanchor ();
5476 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5478 if state.w < conf.winw
- state.scrollw
5479 then (conf.winw
- state.scrollw
- state.w) / 2
5482 state.x <- (state.x + margin) - x0;
5484 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5485 state.mstate
<- Mnone
;
5489 let winw = conf.winw - state.scrollw
- 1 in
5490 let s = float x /. float winw in
5491 let destx = truncate
(float (state.w + winw) *. s) in
5492 state.x <- winw - destx;
5493 gotoy_and_clear_text state.y;
5494 state.mstate
<- Mscrollx
;
5498 let s = float y /. float conf.winh
in
5499 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5500 gotoy_and_clear_text desty;
5501 state.mstate
<- Mscrolly
;
5504 let viewmouse button down
x y mask
=
5506 | n when (n == 4 || n == 5) && not down
->
5507 if Wsi.withctrl mask
5509 match state.mstate
with
5510 | Mzoom
(oldn
, i
) ->
5518 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5520 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5522 let zoom = conf.zoom -. incr in
5524 state.mstate
<- Mzoom
(n, 0);
5526 state.mstate
<- Mzoom
(n, i
+1);
5528 else state.mstate
<- Mzoom
(n, 0)
5530 | _ -> state.mstate
<- Mzoom
(n, 0)
5533 match state.autoscroll
with
5534 | Some step
-> setautoscrollspeed step
(n=4)
5538 then -conf.scrollstep
5539 else conf.scrollstep
5541 let incr = incr * 2 in
5542 let y = clamp incr in
5543 gotoy_and_clear_text y
5546 | 1 when Wsi.withctrl mask
->
5549 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5550 state.mstate
<- Mpan
(x, y)
5553 state.mstate
<- Mnone
5558 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5560 state.mstate
<- Mzoomrect
(p, p)
5563 match state.mstate
with
5564 | Mzoomrect
((x0, y0), _) ->
5565 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5566 then zoomrect x0 y0 x y
5568 state.mstate
<- Mnone
;
5569 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5570 G.postRedisplay "kill accidental zoom rect";
5573 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5574 state.mstate
<- Mnone
5577 | 1 when x > conf.winw - state.scrollw
->
5580 let _, position, sh = state.uioh#
scrollph in
5581 if y > truncate
position && y < truncate
(position +. sh)
5582 then state.mstate
<- Mscrolly
5585 state.mstate
<- Mnone
5587 | 1 when y > conf.winh
- state.hscrollh ->
5590 let _, position, sw = state.uioh#scrollpw
in
5591 if x > truncate
position && x < truncate
(position +. sw)
5592 then state.mstate
<- Mscrollx
5595 state.mstate
<- Mnone
5598 let dest = if down
then getunder x y else Unone
in
5599 begin match dest with
5603 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5606 | Unone
when down
->
5607 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5608 state.mstate
<- Mpan
(x, y);
5610 | Unone
| Utext
_ ->
5613 if conf.angle
mod 360 = 0
5615 state.mstate
<- Msel
((x, y), (x, y));
5616 G.postRedisplay "mouse select";
5620 match state.mstate
with
5623 | Mzoom
_ | Mscrollx
| Mscrolly
->
5624 state.mstate
<- Mnone
5626 | Mzoomrect
((x0, y0), _) ->
5630 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5631 state.mstate
<- Mnone
5633 | Msel
((_, y0), (_, y1)) ->
5634 let rec loop = function
5637 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5638 || ((y1 >= l.pagedispy
5639 && y1 <= (l.pagedispy + l.pagevh)))
5641 match getopaque l.pageno with
5644 match Ne.pipe () with
5648 "can not create sel pipe: %s"
5649 (Printexc.to_string exn
));
5651 let doclose what fd
=
5652 Ne.clo fd
(fun msg
->
5653 dolog "%s close failed: %s" what msg
)
5656 popen conf.selcmd
[r, 0; w, -1];
5659 G.postRedisplay "copysel";
5661 dolog "can not exectute %S: %s"
5662 conf.selcmd
(Printexc.to_string exn
);
5670 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5671 state.mstate
<- Mnone
;
5678 let birdseyemouse button down
x y mask
5679 (conf, leftx
, _, hooverpageno
, anchor) =
5682 let rec loop = function
5685 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5686 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5688 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5694 | _ -> viewmouse button down
x y mask
5697 let mouse button down
x y mask
=
5698 state.uioh <- state.uioh#button button down
x y mask
;
5702 state.uioh <- state.uioh#
motion x y
5706 state.uioh <- state.uioh#
pmotion x y;
5712 method key key mask
=
5713 begin match state.mode with
5714 | Textentry
textentry -> textentrykeyboard key mask
textentry
5715 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5716 | View
-> viewkeyboard key mask
5717 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5721 method button button bstate
x y mask
=
5722 begin match state.mode with
5724 | View
-> viewmouse button bstate
x y mask
5725 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5731 begin match state.mode with
5733 | View
| Birdseye
_ | LinkNav
_ ->
5734 match state.mstate
with
5735 | Mzoom
_ | Mnone
-> ()
5740 state.mstate
<- Mpan
(x, y);
5742 then state.x <- state.x + dx;
5744 gotoy_and_clear_text y
5747 state.mstate
<- Msel
(a, (x, y));
5748 G.postRedisplay "motion select";
5751 let y = min
conf.winh
(max
0 y) in
5755 let x = min
conf.winw (max
0 x) in
5758 | Mzoomrect
(p0
, _) ->
5759 state.mstate
<- Mzoomrect
(p0
, (x, y));
5760 G.postRedisplay "motion zoomrect";
5764 method pmotion x y =
5765 begin match state.mode with
5766 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5767 let rec loop = function
5769 if hooverpageno
!= -1
5771 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5772 G.postRedisplay "pmotion birdseye no hoover";
5775 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5776 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5778 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5779 G.postRedisplay "pmotion birdseye hoover";
5789 match state.mstate
with
5790 | Mnone
-> updateunder x y
5791 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5796 method infochanged
_ = ()
5799 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5800 let p, h = scrollph state.y maxy in
5804 let winw = conf.winw - state.scrollw
- 1 in
5805 let fwinw = float winw in
5807 let sw = fwinw /. float state.w in
5808 let sw = fwinw *. sw in
5809 max
sw (float conf.scrollh
)
5812 let f = state.w+winw in
5813 let r = float (winw-state.x) /. float f in
5814 let p = fwinw *. r in
5818 if position +. sw > fwinw
5819 then fwinw -. position
5822 state.hscrollh, position, sw
5826 match state.mode with
5827 | LinkNav
_ -> "links"
5828 | Textentry
_ -> "textentry"
5829 | Birdseye
_ -> "birdseye"
5832 findkeyhash conf modename
5839 let fontpath = ref "";;
5842 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5845 let l = String.length
s in
5846 let b = Buffer.create
l in
5852 try Sys.getenv
"HOME"
5855 ("Can not determine home directory location: " ^
5856 Printexc.to_string exn
);
5860 let modifier_of_string = function
5861 | "alt" -> Wsi.altmask
5862 | "shift" -> Wsi.shiftmask
5863 | "ctrl" | "control" -> Wsi.ctrlmask
5864 | "meta" -> Wsi.metamask
5869 let r = Str.regexp
"-" in
5871 let elems = Str.full_split
r s in
5874 let m1 = modifier_of_string s in
5876 then (Wsi.namekey
s, m)
5879 | Str.Delim
s when n land 1 = 0 -> g s
5881 | Str.Delim
_ -> (k
, m)
5883 let rec loop n k
m = function
5886 let k, m = f n k m x in
5892 let keys_of_string =
5893 let r = Str.regexp
"[ \t]" in
5895 let elems = Str.split
r s in
5896 List.map
key_of_string elems
5899 let copykeyhashes c =
5900 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5903 let config_of c attrs
=
5907 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5908 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5909 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5910 | "preload" -> { c with preload = bool_of_string
v }
5911 | "page-bias" -> { c with pagebias
= int_of_string
v }
5912 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5913 | "auto-scroll-step" ->
5914 { c with autoscrollstep
= max
0 (int_of_string
v) }
5915 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5916 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5919 match String.lowercase
v with
5920 | "true" -> Some infinity
5922 | f -> Some
(float_of_string
f)
5924 { c with maxwait
= mw}
5925 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5926 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5927 | "vertical-margin" ->
5928 { c with interpagespace = max
0 (int_of_string
v) }
5930 let zoom = float_of_string
v /. 100. in
5931 let zoom = max
zoom 0.0 in
5932 { c with zoom = zoom }
5933 | "presentation" -> { c with presentation = bool_of_string
v }
5934 | "rotation-angle" -> { c with angle
= int_of_string
v }
5935 | "width" -> { c with winw = max
20 (int_of_string
v) }
5936 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5937 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5938 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5939 | "pixmap-cache-size" ->
5940 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5941 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5942 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5943 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5944 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5945 | "background-color" -> { c with bgcolor
= color_of_string v }
5946 | "scrollbar-in-presentation" ->
5947 { c with scrollbarinpm
= bool_of_string
v }
5948 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5949 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5950 | "mupdf-store-size" ->
5951 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5952 | "checkers" -> { c with checkers
= bool_of_string
v }
5953 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5954 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5955 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5956 | "uri-launcher" -> { c with urilauncher
= unent v }
5957 | "path-launcher" -> { c with pathlauncher
= unent v }
5958 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5959 | "invert-colors" -> { c with invert
= bool_of_string
v }
5960 | "brightness" -> { c with colorscale
= float_of_string
v }
5961 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5963 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5965 let (n, _, _) as nab
= multicolumns_of_string v in
5967 then { c with columns
= Csplit
(-n, [||]) }
5968 else { c with columns
= Cmulti
(nab
, [||]) }
5969 | "birds-eye-columns" ->
5970 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5971 | "selection-command" -> { c with selcmd
= unent v }
5972 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5973 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
5974 | "full-split" -> { c with fullsplit
= bool_of_string
v }
5977 prerr_endline
("Error processing attribute (`" ^
5978 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5981 let rec fold c = function
5984 let c = apply c k v in
5987 fold { c with keyhashes
= copykeyhashes c } attrs
;
5990 let fromstring f pos
n v d =
5993 dolog "Error processing attribute (%S=%S) at %d\n%s"
5994 n v pos
(Printexc.to_string exn
)
5999 let bookmark_of attrs
=
6000 let rec fold title page
rely = function
6001 | ("title", v) :: rest
-> fold v page
rely rest
6002 | ("page", v) :: rest
-> fold title v rely rest
6003 | ("rely", v) :: rest
-> fold title page
v rest
6004 | _ :: rest
-> fold title page
rely rest
6005 | [] -> title, page
, rely
6007 fold "invalid" "0" "0" attrs
6011 let rec fold path page
rely pan
= function
6012 | ("path", v) :: rest
-> fold v page
rely pan rest
6013 | ("page", v) :: rest
-> fold path v rely pan rest
6014 | ("rely", v) :: rest
-> fold path page
v pan rest
6015 | ("pan", v) :: rest
-> fold path page
rely v rest
6016 | _ :: rest
-> fold path page
rely pan rest
6017 | [] -> path, page
, rely, pan
6019 fold "" "0" "0" "0" attrs
6023 let rec fold rs ls
= function
6024 | ("out", v) :: rest
-> fold v ls rest
6025 | ("in", v) :: rest
-> fold rs
v rest
6026 | _ :: rest
-> fold ls rs rest
6032 let setconf dst
src =
6033 dst
.scrollbw
<- src.scrollbw
;
6034 dst
.scrollh
<- src.scrollh
;
6035 dst
.icase
<- src.icase
;
6036 dst
.preload <- src.preload;
6037 dst
.pagebias
<- src.pagebias
;
6038 dst
.verbose
<- src.verbose
;
6039 dst
.scrollstep
<- src.scrollstep
;
6040 dst
.maxhfit
<- src.maxhfit
;
6041 dst
.crophack
<- src.crophack
;
6042 dst
.autoscrollstep
<- src.autoscrollstep
;
6043 dst
.maxwait
<- src.maxwait
;
6044 dst
.hlinks
<- src.hlinks
;
6045 dst
.underinfo
<- src.underinfo
;
6046 dst
.interpagespace <- src.interpagespace;
6047 dst
.zoom <- src.zoom;
6048 dst
.presentation <- src.presentation;
6049 dst
.angle
<- src.angle
;
6050 dst
.winw <- src.winw;
6051 dst
.winh
<- src.winh
;
6052 dst
.savebmarks
<- src.savebmarks
;
6053 dst
.memlimit
<- src.memlimit
;
6054 dst
.proportional
<- src.proportional
;
6055 dst
.texcount
<- src.texcount
;
6056 dst
.sliceheight
<- src.sliceheight
;
6057 dst
.thumbw
<- src.thumbw
;
6058 dst
.jumpback
<- src.jumpback
;
6059 dst
.bgcolor
<- src.bgcolor
;
6060 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6061 dst
.tilew
<- src.tilew
;
6062 dst
.tileh
<- src.tileh
;
6063 dst
.mustoresize
<- src.mustoresize
;
6064 dst
.checkers
<- src.checkers
;
6065 dst
.aalevel
<- src.aalevel
;
6066 dst
.trimmargins
<- src.trimmargins
;
6067 dst
.trimfuzz
<- src.trimfuzz
;
6068 dst
.urilauncher
<- src.urilauncher
;
6069 dst
.colorspace
<- src.colorspace
;
6070 dst
.invert
<- src.invert
;
6071 dst
.colorscale
<- src.colorscale
;
6072 dst
.redirectstderr <- src.redirectstderr;
6073 dst
.ghyllscroll
<- src.ghyllscroll
;
6074 dst
.columns
<- src.columns
;
6075 dst
.beyecolumns
<- src.beyecolumns
;
6076 dst
.selcmd
<- src.selcmd
;
6077 dst
.updatecurs
<- src.updatecurs
;
6078 dst
.pathlauncher
<- src.pathlauncher
;
6079 dst
.keyhashes
<- copykeyhashes src;
6080 dst
.hfsize
<- src.hfsize
;
6081 dst
.fullsplit
<- src.fullsplit
;
6085 let h = Hashtbl.create
10 in
6086 let dc = { defconf with angle
= defconf.angle
} in
6087 let rec toplevel v t spos
_ =
6089 | Vdata
| Vcdata
| Vend
-> v
6090 | Vopen
("llppconfig", _, closed
) ->
6093 else { v with f = llppconfig
}
6095 error
"unexpected subelement at top level" s spos
6096 | Vclose
_ -> error
"unexpected close at top level" s spos
6098 and llppconfig
v t spos
_ =
6100 | Vdata
| Vcdata
-> v
6101 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6102 | Vopen
("defaults", attrs
, closed
) ->
6103 let c = config_of dc attrs
in
6107 else { v with f = defaults
}
6109 | Vopen
("ui-font", attrs
, closed
) ->
6110 let rec getsize size
= function
6112 | ("size", v) :: rest
->
6114 fromstring int_of_string spos
"size" v fstate.fontsize
in
6116 | l -> getsize size l
6118 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6121 else { v with f = uifont
(Buffer.create
10) }
6123 | Vopen
("doc", attrs
, closed
) ->
6124 let pathent, spage
, srely
, span
= doc_of attrs
in
6125 let path = unent pathent
6126 and pageno = fromstring int_of_string spos
"page" spage
0
6127 and rely = fromstring float_of_string spos
"rely" srely
0.0
6128 and pan
= fromstring int_of_string spos
"pan" span
0 in
6129 let c = config_of dc attrs
in
6130 let anchor = (pageno, rely) in
6132 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6133 else { v with f = doc
path pan
anchor c [] }
6136 error
"unexpected subelement in llppconfig" s spos
6138 | Vclose
"llppconfig" -> { v with f = toplevel }
6139 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6141 and defaults
v t spos
_ =
6143 | Vdata
| Vcdata
-> v
6144 | Vend
-> error
"unexpected end of input in defaults" s spos
6145 | Vopen
("keymap", attrs
, closed
) ->
6147 try List.assoc
"mode" attrs
6148 with Not_found
-> "global" in
6153 let h = findkeyhash dc modename in
6154 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6157 { v with f = pkeymap
ret KeyMap.empty }
6159 | Vopen
(_, _, _) ->
6160 error
"unexpected subelement in defaults" s spos
6162 | Vclose
"defaults" ->
6163 { v with f = llppconfig
}
6165 | Vclose
_ -> error
"unexpected close in defaults" s spos
6167 and uifont
b v t spos
epos =
6170 Buffer.add_substring
b s spos
(epos - spos
);
6172 | Vopen
(_, _, _) ->
6173 error
"unexpected subelement in ui-font" s spos
6174 | Vclose
"ui-font" ->
6175 if String.length
!fontpath = 0
6176 then fontpath := Buffer.contents
b;
6177 { v with f = llppconfig
}
6178 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6179 | Vend
-> error
"unexpected end of input in ui-font" s spos
6181 and doc
path pan
anchor c bookmarks
v t spos
_ =
6183 | Vdata
| Vcdata
-> v
6184 | Vend
-> error
"unexpected end of input in doc" s spos
6185 | Vopen
("bookmarks", _, closed
) ->
6188 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6190 | Vopen
("keymap", attrs
, closed
) ->
6192 try List.assoc
"mode" attrs
6193 with Not_found
-> "global"
6199 let h = findkeyhash c modename in
6200 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6201 doc
path pan
anchor c bookmarks
6203 { v with f = pkeymap
ret KeyMap.empty }
6205 | Vopen
(_, _, _) ->
6206 error
"unexpected subelement in doc" s spos
6209 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6210 { v with f = llppconfig
}
6212 | Vclose
_ -> error
"unexpected close in doc" s spos
6214 and pkeymap
ret keymap
v t spos
_ =
6216 | Vdata
| Vcdata
-> v
6217 | Vend
-> error
"unexpected end of input in keymap" s spos
6218 | Vopen
("map", attrs
, closed
) ->
6219 let r, l = map_of attrs
in
6220 let kss = fromstring keys_of_string spos
"in" r [] in
6221 let lss = fromstring keys_of_string spos
"out" l [] in
6225 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6226 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6229 then { v with f = pkeymap
ret keymap }
6232 { v with f = skip
"map" f }
6235 error
"unexpected subelement in keymap" s spos
6237 | Vclose
"keymap" ->
6238 { v with f = ret keymap }
6240 | Vclose
_ -> error
"unexpected close in keymap" s spos
6242 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6244 | Vdata
| Vcdata
-> v
6245 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6246 | Vopen
("item", attrs
, closed
) ->
6247 let titleent, spage
, srely
= bookmark_of attrs
in
6248 let page = fromstring int_of_string spos
"page" spage
0
6249 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6250 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6252 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6255 { v with f = skip
"item" f }
6258 error
"unexpected subelement in bookmarks" s spos
6260 | Vclose
"bookmarks" ->
6261 { v with f = doc
path pan
anchor c bookmarks }
6263 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6265 and skip tag
f v t spos
_ =
6267 | Vdata
| Vcdata
-> v
6269 error
("unexpected end of input in skipped " ^ tag
) s spos
6270 | Vopen
(tag'
, _, closed
) ->
6274 let f'
() = { v with f = skip tag
f } in
6275 { v with f = skip tag'
f'
}
6279 else error
("unexpected close in skipped " ^ tag
) s spos
6282 parse
{ f = toplevel; accu = () } s;
6288 let len = in_channel_length ic
in
6289 let s = String.create
len in
6290 really_input ic
s 0 len;
6293 | Parse_error
(msg
, s, pos
) ->
6294 let subs = subs s pos
in
6295 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6296 failwith
("parse error: " ^
s)
6299 failwith
("config load error: " ^
Printexc.to_string exn
)
6305 let dir = Filename.concat
home ".config" in
6306 if Sys.is_directory
dir then dir else home
6309 Filename.concat
dir "llpp.conf"
6312 let confpath = ref defconfpath;;
6315 if Sys.file_exists
!confpath
6318 (try Some
(open_in_bin
!confpath)
6321 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6322 Printexc.to_string exn
);
6331 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6332 Printexc.to_string exn
);
6338 f (Hashtbl.create
0, defconf)
6343 let pc, pb
, px, pa
=
6345 Hashtbl.find h (Filename.basename
state.path)
6346 with Not_found
-> dc, [], 0, (0, 0.0)
6350 state.bookmarks <- pb
;
6352 state.scrollw
<- conf.scrollbw
;
6354 then state.anchor <- pa
;
6355 cbput state.hists
.nav pa
;
6360 let add_attrs bb always
dc c =
6363 then Printf.bprintf bb
"\n %s='%b'" s a
6366 then Printf.bprintf bb
"\n %s='%d'" s a
6369 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6372 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6375 then Printf.bprintf bb
"\n %s='%f'" s a
6379 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6383 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6387 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6391 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6397 | Some
(_N
, _A
, _B
) ->
6398 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6408 else string_of_float
f
6410 Printf.bprintf bb
"\n %s='%s'" s v
6415 | Cmulti
((n, a, b), _) when n > 1 ->
6416 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6417 | Csplit
(n, _) when n > 1 ->
6418 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6424 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6429 then dc.winw, dc.winh
6431 match state.fullscreen
with
6433 | None
-> c.winw, c.winh
6435 let zoom, presentation, interpagespace, maxwait
=
6437 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6439 match state.mode with
6440 | Birdseye
(bc
, _, _, _, _) ->
6441 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6442 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6444 oi
"width" w dc.winw;
6445 oi
"height" h dc.winh
;
6446 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6447 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6448 ob "case-insensitive-search" c.icase
dc.icase
;
6449 ob "preload" c.preload dc.preload;
6450 oi
"page-bias" c.pagebias
dc.pagebias
;
6451 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6452 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6453 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6454 ob "crop-hack" c.crophack
dc.crophack
;
6455 oW
"throttle" maxwait
dc.maxwait
;
6456 ob "highlight-links" c.hlinks
dc.hlinks
;
6457 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6458 oi
"vertical-margin" interpagespace dc.interpagespace;
6459 oz
"zoom" zoom dc.zoom;
6460 ob "presentation" presentation dc.presentation;
6461 oi
"rotation-angle" c.angle
dc.angle
;
6462 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6463 ob "proportional-display" c.proportional
dc.proportional
;
6464 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6465 oi
"tex-count" c.texcount
dc.texcount
;
6466 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6467 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6468 ob "persistent-location" c.jumpback
dc.jumpback
;
6469 oc
"background-color" c.bgcolor
dc.bgcolor
;
6470 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6471 oi
"tile-width" c.tilew
dc.tilew
;
6472 oi
"tile-height" c.tileh
dc.tileh
;
6473 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6474 ob "checkers" c.checkers
dc.checkers
;
6475 oi
"aalevel" c.aalevel
dc.aalevel
;
6476 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6477 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6478 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6479 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6480 oC
"color-space" c.colorspace
dc.colorspace
;
6481 ob "invert-colors" c.invert
dc.invert
;
6482 oF
"brightness" c.colorscale
dc.colorscale
;
6483 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6484 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6485 oco
"columns" c.columns
dc.columns
;
6486 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6487 os
"selection-command" c.selcmd
dc.selcmd
;
6488 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6489 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6490 ob "full-split" c.fullsplit
dc.fullsplit
;
6493 let keymapsbuf always
dc c =
6494 let bb = Buffer.create
16 in
6495 let rec loop = function
6497 | (modename, h) :: rest
->
6498 let dh = findkeyhash dc modename in
6499 if always
|| h <> dh
6501 if Hashtbl.length
h > 0
6503 if Buffer.length
bb > 0
6504 then Buffer.add_char
bb '
\n'
;
6505 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6506 Hashtbl.iter
(fun i
o ->
6507 let isdifferent = always
||
6509 let dO = Hashtbl.find dh i
in
6511 with Not_found
-> true
6516 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6517 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6518 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6519 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6520 Buffer.add_string
bb (Wsi.keyname
k);
6523 let rec loop = function
6525 | km
:: [] -> addkm km
6526 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6530 Buffer.add_string
bb "<map in='";
6534 Buffer.add_string
bb "' out='";
6536 Buffer.add_string
bb "'/>\n"
6539 Buffer.add_string
bb "' out='";
6541 Buffer.add_string
bb "'/>\n"
6543 | KMmulti
(ins, kms
) ->
6544 Buffer.add_char
bb ' '
;
6546 Buffer.add_string
bb "' out='";
6548 Buffer.add_string
bb "'/>\n"
6550 Buffer.add_string
bb "</keymap>";
6560 let uifontsize = fstate.fontsize
in
6561 let bb = Buffer.create
32768 in
6563 let dc = if conf.bedefault
then conf else dc in
6564 Buffer.add_string
bb "<llppconfig>\n";
6566 if String.length
!fontpath > 0
6568 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6574 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6577 Buffer.add_string
bb "<defaults ";
6578 add_attrs bb true dc dc;
6579 let kb = keymapsbuf true dc dc in
6580 if Buffer.length
kb > 0
6582 Buffer.add_string
bb ">\n";
6583 Buffer.add_buffer
bb kb;
6584 Buffer.add_string
bb "\n</defaults>\n";
6586 else Buffer.add_string
bb "/>\n";
6588 let adddoc path pan
anchor c bookmarks =
6589 if bookmarks == [] && c = dc && anchor = emptyanchor
6592 Printf.bprintf
bb "<doc path='%s'"
6593 (enent
path 0 (String.length
path));
6595 if anchor <> emptyanchor
6597 let n, y = anchor in
6598 Printf.bprintf
bb " page='%d'" n;
6601 Printf.bprintf
bb " rely='%f'" y
6606 then Printf.bprintf
bb " pan='%d'" pan
;
6608 add_attrs bb false dc c;
6609 let kb = keymapsbuf false dc c in
6611 begin match bookmarks with
6613 if Buffer.length
kb > 0
6615 Buffer.add_string
bb ">\n";
6616 Buffer.add_buffer
bb kb;
6617 Buffer.add_string
bb "\n</doc>\n";
6619 else Buffer.add_string
bb "/>\n"
6621 Buffer.add_string
bb ">\n<bookmarks>\n";
6622 List.iter
(fun (title, _level
, (page, rely)) ->
6624 "<item title='%s' page='%d'"
6625 (enent
title 0 (String.length
title))
6630 Printf.bprintf
bb " rely='%f'" rely
6632 Buffer.add_string
bb "/>\n";
6634 Buffer.add_string
bb "</bookmarks>";
6635 if Buffer.length
kb > 0
6637 Buffer.add_string
bb "\n";
6638 Buffer.add_buffer
bb kb;
6640 Buffer.add_string
bb "\n</doc>\n";
6646 match state.mode with
6647 | Birdseye
(c, pan, _, _, _) ->
6649 match conf.columns
with
6650 | Cmulti
((c, _, _), _) -> Some
c
6654 match c.columns
with
6655 | Cmulti
(c, _) -> Cmulti
(c, [||])
6656 | Csingle
-> Csingle
6657 | Csplit
_ -> failwith
"quit from bird's eye while split"
6659 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6660 | _ -> state.x, conf
6662 let basename = Filename.basename state.path in
6663 adddoc basename pan (getanchor ())
6666 match state.autoscroll
with
6668 | None
-> conf.autoscrollstep
}
6669 (if conf.savebmarks
then state.bookmarks else []);
6671 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6673 then adddoc path x y c bookmarks
6675 Buffer.add_string
bb "</llppconfig>";
6678 if Buffer.length
bb > 0
6681 let tmp = !confpath ^
".tmp" in
6682 let oc = open_out_bin
tmp in
6683 Buffer.output_buffer
oc bb;
6685 Unix.rename
tmp !confpath;
6688 ("error while saving configuration: " ^
Printexc.to_string exn
)
6695 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6696 "<password> Set password");
6698 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6699 "<path> Set path to the user interface font");
6701 ("-c", Arg.String
(fun s -> Config.confpath := s),
6702 "<path> Set path to the configuration file");
6704 ("-v", Arg.Unit
(fun () ->
6706 "%s\nconfiguration path: %s\n"
6710 exit
0), " Print version and exit");
6713 (fun s -> state.path <- s)
6714 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6716 if String.length
state.path = 0
6717 then (prerr_endline
"file name missing"; exit
1);
6721 let globalkeyhash = findkeyhash conf "global" in
6722 let wsfd, winw, winh
= Wsi.init
(object
6724 if nogeomcmds state.geomcmds
|| platform == Posx
6727 GlFunc.draw_buffer `front
;
6728 GlClear.color (scalecolor2 conf.bgcolor
);
6729 GlClear.clear
[`
color];
6730 GlFunc.draw_buffer `back
;
6732 method display = display ()
6733 method reshape w h = reshape w h
6734 method mouse b d x y m = mouse b d x y m
6735 method motion x y = state.mpos
<- (x, y); motion x y
6736 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6738 let mascm = m land (
6739 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6741 match state.keystate
with
6743 let km = k, mascm in
6746 let modehash = state.uioh#
modehash in
6747 try Hashtbl.find modehash km
6749 try Hashtbl.find globalkeyhash km
6750 with Not_found
-> KMinsrt
(k, m)
6752 | KMinsrt
(k, m) -> keyboard k m
6753 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6754 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6756 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6757 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6758 state.keystate
<- KSnone
6759 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6760 state.keystate
<- KSinto
(keys
, insrt
)
6762 state.keystate
<- KSnone
6764 method enter
x y = state.mpos
<- (x, y); pmotion x y
6765 method leave = state.mpos
<- (-1, -1)
6766 method quit
= raise Quit
6767 end) conf.winw conf.winh
(platform = Posx
) in
6772 List.exists
GlMisc.check_extension
6773 [ "GL_ARB_texture_rectangle"
6774 ; "GL_EXT_texture_recangle"
6775 ; "GL_NV_texture_rectangle" ]
6777 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6780 match Ne.pipe () with
6782 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6786 match Ne.pipe () with
6788 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6798 setcheckers conf.checkers
;
6802 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6803 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6808 state.text <- "Opening " ^
state.path;
6810 opendoc state.path state.password
;
6813 let rec loop deadline
=
6815 match state.errfd
with
6816 | None
-> [state.sr
; state.wsfd]
6817 | Some fd
-> [state.sr
; state.wsfd; fd
]
6821 state.redisplay
<- false;
6828 if deadline
= infinity
6830 else max
0.0 (deadline
-. now)
6835 try Unix.select
r [] [] timeout
6836 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6842 if state.ghyll
== noghyll
6844 match state.autoscroll
with
6845 | Some step
when step
!= 0 ->
6846 let y = state.y + step
in
6850 else if y >= state.maxy then 0 else y
6853 if state.mode = View
6854 then state.text <- "";
6857 else deadline
+. 0.01
6862 let rec checkfds = function
6864 | fd
:: rest
when fd
= state.sr
->
6865 let cmd = readcmd state.sr
in
6869 | fd
:: rest
when fd
= state.wsfd ->
6874 let s = String.create
80 in
6875 let n = Unix.read fd
s 0 80 in
6876 if conf.redirectstderr
6878 Buffer.add_substring
state.errmsgs
s 0 n;
6879 state.newerrmsgs
<- true;
6880 state.redisplay
<- true;
6883 prerr_string
(String.sub
s 0 n);
6891 if deadline
= infinity
6895 match state.autoscroll
with
6896 | Some step
when step
!= 0 -> deadline1
6897 | _ -> if state.ghyll
== noghyll then infinity
else deadline1