8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
13 | Uremote
of (string * int)
14 and facename
= string;;
23 type params
= (angle
* fitmodel
* trimparams
24 * texcount
* sliceheight
* memsize
25 * colorspace
* fontpath
* trimcachepath
35 and trimmargins
= bool
36 and interpagespace
= int
43 and trimcachepath
= string
46 and irect
= (int * int * int * int)
47 and trimparams
= (trimmargins
* irect
)
48 and colorspace
= | Rgb
| Bgr
| Gray
49 and fitmodel
= | FitWidth
| FitProportional
| FitPage
57 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
66 | LDfirstvisible
of (int * int * int)
81 | KMmulti
of key list
* key list
83 and keyhash
= (key
, keymap
) Hashtbl.t
86 | KSinto
of (key list
* key list
)
89 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
90 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
92 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
94 external init
: pipe
-> params
-> unit = "ml_init";;
95 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
96 external copysel
: Unix.file_descr
-> opaque
-> bool -> unit = "ml_copysel";;
97 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
98 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
99 external markunder
: string -> int -> int -> mark
-> bool = "ml_markunder";;
100 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
101 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
102 external measurestr
: int -> string -> float = "ml_measure_string";;
103 external postprocess
:
104 opaque
-> int -> int -> int -> (int * string * int) -> int
106 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
107 external platform
: unit -> platform
= "ml_platform";;
108 external setaalevel
: int -> unit = "ml_setaalevel";;
109 external realloctexts
: int -> bool = "ml_realloctexts";;
110 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
111 external getlink
: opaque
-> int -> under
= "ml_getlink";;
112 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
113 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
114 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
115 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
116 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
117 external freepbo
: string -> unit = "ml_freepbo";;
118 external unmappbo
: string -> unit = "ml_unmappbo";;
119 external pbousable
: unit -> bool = "ml_pbo_usable";;
120 external unproject
: opaque
-> int -> int -> (int * int) option
122 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
124 let platform_to_string = function
125 | Punknown
-> "unknown"
129 | Pfreebsd
-> "FreeBSD"
130 | Pdragonflybsd
-> "DragonflyBSD"
131 | Popenbsd
-> "OpenBSD"
132 | Pnetbsd
-> "NetBSD"
133 | Pcygwin
-> "Cygwin"
136 let platform = platform ();;
138 let now = Unix.gettimeofday
;;
140 let selfexec = ref "";;
143 if platform = Pcygwin
145 let sh = "/bin/sh" in
146 let args = [|sh; "-c"; cmd
|] in
147 let rec std si so se
= function
149 | (fd
, 0) :: rest
-> std fd so se rest
150 | (fd
, -1) :: rest
->
151 Unix.set_close_on_exec fd
;
154 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
156 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
157 ignore
(Unix.create_process
sh args si so se
)
162 type mpos
= int * int
164 | Msel
of (mpos
* mpos
)
166 | Mscrolly
| Mscrollx
167 | Mzoom
of (int * int)
168 | Mzoomrect
of (mpos
* mpos
)
172 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
173 and onkey
= string -> int -> te
174 and ondone
= string -> unit
175 and histcancel
= unit -> unit
176 and onhist
= ((histcmd
-> string) * histcancel
)
177 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
178 and cancelonempty
= bool
183 | TEswitch
of textentry
194 let bound v minv maxv
=
195 max minv
(min maxv v
);
199 { store
= Array.create n v
206 let cbcap b
= Array.length b
.store
;;
211 b
.wc
<- (b
.wc
+ 1) mod cap;
213 b
.len
<- min
(b
.len
+ 1) cap;
216 let cbempty b
= b
.len
= 0;;
218 let cbgetg b circular dir
=
222 let rc = b
.rc + dir
in
234 else bound rc 0 (b
.len
-1)
240 let cbget b
= cbgetg b
false;;
241 let cbgetc b
= cbgetg b
true;;
243 let drawstring size x y s
=
245 Gl.enable `texture_2d
;
246 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
247 ignore
(drawstr size x y s
);
249 Gl.disable `texture_2d
;
252 let drawstring1 size x y s
=
256 let drawstring2 size x y fmt
=
257 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
276 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
277 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
278 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
279 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
280 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
281 dolog
" column %d" l
.pagecol
;
285 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
287 dolog
" x0,y0=(% f, % f)" x0 y0
;
288 dolog
" x1,y1=(% f, % f)" x1 y1
;
289 dolog
" x2,y2=(% f, % f)" x2 y2
;
290 dolog
" x3,y3=(% f, % f)" x3 y3
;
294 type multicolumns
= multicol
* pagegeom
295 and singlecolumn
= pagegeom
296 and splitcolumns
= columncount
* pagegeom
297 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
298 and multicol
= columncount
* covercount
* covercount
300 and columncount
= int
301 and covercount
= int;;
308 { mutable scrollbw
: int
309 ; mutable scrollh
: int
310 ; mutable scrollb
: scrollb
311 ; mutable icase
: bool
312 ; mutable preload
: bool
313 ; mutable pagebias
: int
314 ; mutable verbose
: bool
315 ; mutable debug
: bool
316 ; mutable scrollstep
: int
317 ; mutable hscrollstep
: int
318 ; mutable maxhfit
: bool
319 ; mutable crophack
: bool
320 ; mutable autoscrollstep
: int
321 ; mutable maxwait
: float option
322 ; mutable hlinks
: bool
323 ; mutable underinfo
: bool
324 ; mutable interpagespace
: interpagespace
325 ; mutable zoom
: float
326 ; mutable presentation
: bool
327 ; mutable angle
: angle
328 ; mutable cwinw
: int
329 ; mutable cwinh
: int
330 ; mutable savebmarks
: bool
331 ; mutable fitmodel
: fitmodel
332 ; mutable trimmargins
: trimmargins
333 ; mutable trimfuzz
: irect
334 ; mutable memlimit
: memsize
335 ; mutable texcount
: texcount
336 ; mutable sliceheight
: sliceheight
337 ; mutable thumbw
: width
338 ; mutable jumpback
: bool
339 ; mutable bgcolor
: (float * float * float)
340 ; mutable bedefault
: bool
341 ; mutable tilew
: int
342 ; mutable tileh
: int
343 ; mutable mustoresize
: memsize
344 ; mutable checkers
: bool
345 ; mutable aalevel
: int
346 ; mutable urilauncher
: string
347 ; mutable pathlauncher
: string
348 ; mutable colorspace
: colorspace
349 ; mutable invert
: bool
350 ; mutable colorscale
: float
351 ; mutable redirectstderr
: bool
352 ; mutable ghyllscroll
: (int * int * int) option
353 ; mutable columns
: columns
354 ; mutable beyecolumns
: columncount
option
355 ; mutable selcmd
: string
356 ; mutable paxcmd
: string
357 ; mutable updatecurs
: bool
358 ; mutable keyhashes
: (string * keyhash
) list
359 ; mutable hfsize
: int
360 ; mutable pgscale
: float
361 ; mutable usepbo
: bool
362 ; mutable wheelbypage
: bool
363 ; mutable stcmd
: string
364 ; mutable riani
: bool
365 ; mutable pax
: (float * int * int) ref option
366 ; mutable paxmark
: mark
369 | Csingle
of singlecolumn
370 | Cmulti
of multicolumns
371 | Csplit
of splitcolumns
374 type anchor
= pageno
* top
* dtop
;;
376 type outline
= string * int * anchor
;;
378 type rect
= float * float * float * float * float * float * float * float;;
380 type tile
= opaque
* pixmapsize
* elapsed
381 and elapsed
= float;;
382 type pagemapkey
= pageno
* gen
;;
383 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
387 let emptyanchor = (0, 0.0, 0.0);;
389 type infochange
= | Memused
| Docinfo
| Pdim
;;
391 class type uioh
= object
392 method display
: unit
393 method key
: int -> int -> uioh
394 method button
: int -> bool -> int -> int -> int -> uioh
395 method motion
: int -> int -> uioh
396 method pmotion
: int -> int -> uioh
397 method infochanged
: infochange
-> unit
398 method scrollpw
: (int * float * float)
399 method scrollph
: (int * float * float)
400 method modehash
: keyhash
401 method eformsgs
: bool
405 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
406 | Textentry
of (textentry
* onleave
)
408 | LinkNav
of linktarget
409 and onleave
= leavetextentrystatus
-> unit
410 and leavetextentrystatus
= | Cancel
| Confirm
411 and helpitem
= string * int * action
414 | Action
of (uioh
-> uioh
)
416 | Ltexact
of (pageno
* int)
420 let isbirdseye = function Birdseye _
-> true | _
-> false;;
421 let istextentry = function Textentry _
-> true | _
-> false;;
425 | Loading
of (page
* gen
)
427 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
429 | Outlining
of outline list
432 let emptykeyhash = Hashtbl.create
0;;
433 let nouioh : uioh
= object (self
)
435 method key _ _
= self
436 method button _ _ _ _ _
= self
437 method motion _ _
= self
438 method pmotion _ _
= self
439 method infochanged _
= ()
440 method scrollpw
= (0, nan
, nan
)
441 method scrollph
= (0, nan
, nan
)
442 method modehash
= emptykeyhash
443 method eformsgs
= false
447 { mutable sr
: Unix.file_descr
448 ; mutable sw
: Unix.file_descr
449 ; mutable wsfd
: Unix.file_descr
450 ; mutable errfd
: Unix.file_descr
option
451 ; mutable stderr
: Unix.file_descr
452 ; mutable errmsgs
: Buffer.t
453 ; mutable newerrmsgs
: bool
457 ; mutable anchor
: anchor
458 ; mutable ranchors
: (string * string * anchor
* string) list
460 ; mutable layout
: page list
461 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
462 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
463 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
464 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
465 ; mutable pagecount
: int
466 ; mutable currently
: currently
467 ; mutable mstate
: mstate
468 ; mutable searchpattern
: string
469 ; mutable rects
: (pageno
* recttype
* rect
) list
470 ; mutable rects1
: (pageno
* recttype
* rect
) list
471 ; mutable text
: string
472 ; mutable winstate
: Wsi.winstate list
473 ; mutable mode
: mode
474 ; mutable uioh
: uioh
475 ; mutable outlines
: outline array
476 ; mutable bookmarks
: outline list
477 ; mutable path
: string
478 ; mutable password
: string
479 ; mutable nameddest
: string
480 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
481 ; mutable memused
: memsize
483 ; mutable throttle
: (page list
* int * float) option
484 ; mutable autoscroll
: int option
485 ; mutable ghyll
: (int option -> unit)
486 ; mutable help
: helpitem array
487 ; mutable docinfo
: (int * string) list
488 ; mutable texid
: GlTex.texture_id
option
490 ; mutable prevzoom
: float
491 ; mutable progress
: float
492 ; mutable redisplay
: bool
493 ; mutable mpos
: mpos
494 ; mutable keystate
: keystate
495 ; mutable glinks
: bool
496 ; mutable prevcolumns
: (columns
* float) option
499 ; mutable reprf
: (unit -> unit)
500 ; mutable origin
: string
501 ; mutable roam
: (unit -> unit)
504 { pat
: string circbuf
505 ; pag
: string circbuf
506 ; nav
: anchor circbuf
507 ; sel
: string circbuf
514 ; scrollb
= scrollbhv lor scrollbvv
530 ; presentation
= false
535 ; fitmodel
= FitProportional
536 ; trimmargins
= false
537 ; trimfuzz
= (0,0,0,0)
538 ; memlimit
= 32 lsl 20
543 ; bgcolor
= (0.5, 0.5, 0.5)
547 ; mustoresize
= 256 lsl 20
552 | Plinux
| Pfreebsd
| Pdragonflybsd
553 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
554 | Posx
-> "open \"%s\""
555 | Pcygwin
-> "cygstart \"%s\""
556 | Punknown
-> "echo %s")
557 ; pathlauncher
= "lp \"%s\""
560 | Plinux
| Pfreebsd
| Pdragonflybsd
561 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
569 ; redirectstderr
= false
571 ; columns
= Csingle
[||]
577 ; wheelbypage
= false
578 ; stcmd
= "echo SyncTex"
581 ; paxmark
= Mark_word
583 let mk n
= (n
, Hashtbl.create
1) in
597 let wtmode = ref false;;
599 let findkeyhash c name
=
600 try List.assoc name c
.keyhashes
601 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
604 let conf = { defconf with angle
= defconf.angle
};;
606 let pgscale h
= truncate
(float h
*. conf.pgscale);;
609 { mutable fontsize
: int
610 ; mutable wwidth
: float
611 ; mutable maxrows
: int
623 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
624 let len = String.length s
in
625 if colonpos >= 0 && colonpos + 3 < len
627 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
630 try String.rindex_from s
colonpos ' '
634 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
637 | "http" | "ftp" | "mailto" ->
639 try String.index_from s
colonpos ' '
640 with Not_found
-> len
642 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
650 if String.length
conf.urilauncher
= 0
651 then print_endline uri
653 let url = geturl uri
in
654 if String.length
url = 0
655 then Printf.eprintf
"obtained empty url from uri %S" uri
657 let re = Str.regexp
"%s" in
658 let command = Str.global_replace
re url conf.urilauncher
in
662 "failed to execute `%s': %s\n" command (exntos exn
);
668 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
669 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
673 let strings = version () :: "" :: Help.keys
in
676 let url = geturl s
in
677 if String.length
url > 0
678 then (s
, 0, Action
(fun u
-> gotouri url; u
))
679 else (s
, 0, Noaction
)
684 let firstgeomcmds = "", [];;
685 let noreprf () = ();;
692 ; stderr
= Unix.stderr
693 ; errmsgs
= Buffer.create
0
698 ; anchor
= emptyanchor
702 ; tilelru
= Queue.create
()
703 ; pagemap
= Hashtbl.create
10
704 ; tilemap
= Hashtbl.create
10
720 ; geomcmds
= firstgeomcmds
722 { nav
= cbnew 10 emptyanchor
747 ; roam
= (fun () -> ())
752 if (conf.scrollb
land scrollbhv = 0)
753 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
759 if (conf.scrollb
land scrollbvv = 0)
764 let wadjsb w
= w
- vscrollw ();;
767 fstate.fontsize
<- n
;
768 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
769 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
775 Printf.kprintf prerr_endline fmt
777 Printf.kprintf ignore fmt
781 if String.length
conf.pathlauncher
= 0
782 then print_endline
state.path
784 let re = Str.regexp
"%s" in
785 let command = Str.global_replace
re state.path
conf.pathlauncher
in
788 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
794 type 'a t
= | Res
of 'a
| Exn
of exn
;;
797 try Res
(Unix.pipe ())
802 try tempfailureretry
Unix.close fd
803 with exn
-> f
(exntos exn
)
807 try Res
(tempfailureretry
Unix.dup fd
)
812 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
817 let redirectstderr () =
818 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
819 if conf.redirectstderr
821 match Ne.pipe () with
823 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
826 begin match Ne.dup Unix.stderr
with
828 dolog
"failed to dup stderr: %s" (exntos exn
);
829 Ne.clo r
(clofail "pipe/r");
830 Ne.clo w
(clofail "pipe/w");
832 | Ne.Res dupstderr
->
833 begin match Ne.dup2 w
Unix.stderr
with
835 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
836 Ne.clo dupstderr
(clofail "stderr duplicate");
837 Ne.clo r
(clofail "redir pipe/r");
838 Ne.clo w
(clofail "redir pipe/w");
841 state.stderr
<- dupstderr
;
842 state.errfd
<- Some r
;
846 state.newerrmsgs
<- false;
847 begin match state.errfd
with
849 begin match Ne.dup2 state.stderr
Unix.stderr
with
851 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
853 Ne.clo fd
(clofail "dup of stderr");
858 prerr_string
(Buffer.contents
state.errmsgs
);
860 Buffer.clear
state.errmsgs
;
866 let postRedisplay who
=
868 then prerr_endline
("redisplay for " ^ who
);
869 state.redisplay
<- true;
873 let getopaque pageno
=
874 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
875 with Not_found
-> None
878 let putopaque pageno opaque
=
879 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
882 let pagetranslatepoint l x y
=
883 let dy = y
- l
.pagedispy
in
884 let y = dy + l
.pagey
in
885 let dx = x
- l
.pagedispx
in
886 let x = dx + l
.pagex
in
890 let onppundermouse g
x y d
=
893 begin match getopaque l
.pageno
with
895 let x0 = l
.pagedispx
in
896 let x1 = x0 + l
.pagevw
in
897 let y0 = l
.pagedispy
in
898 let y1 = y0 + l
.pagevh
in
899 if y >= y0 && y <= y1 && x >= x0 && x <= x1
901 let px, py
= pagetranslatepoint l
x y in
902 match g opaque l
px py
with
915 let g opaque _
px py
=
916 match whatsunder opaque
px py
with
918 | under
-> Some under
920 onppundermouse g x y Unone
925 match unproject opaque
x y with
926 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
929 onppundermouse g x y None
;
933 state.text
<- Printf.sprintf
"%c%s" c s
;
934 G.postRedisplay "showtext";
938 let g opaque l
px py
=
939 if markunder opaque
px py
conf.paxmark
942 match getopaque l
.pageno
with
945 match Ne.pipe () with
949 "can not create mark pipe: %s"
952 let doclose what fd
=
953 Ne.clo fd
(fun msg
->
954 dolog
"%s close failed: %s" what msg
)
957 popen conf.paxcmd
[r
, 0; w
, -1];
958 copysel w opaque
false;
960 G.postRedisplay "paxunder";
962 dolog
"can not execute %S: %s"
963 conf.paxcmd
(exntos exn
);
970 G.postRedisplay "paxunder";
972 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
976 match Ne.pipe () with
978 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
981 try popen conf.selcmd
[r
, 0; w
, -1]; true
984 (Printf.sprintf
"failed to execute %s: %s"
985 conf.selcmd
(exntos exn
));
989 Ne.clo fd
(fun msg
->
990 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
996 let l = String.length s
in
997 let n = tempfailureretry
(Unix.write w s
0) l in
1002 "failed to write %d characters to sel pipe, wrote %d"
1007 (Printf.sprintf
"failed to write to sel pipe: %s"
1016 let undertext = function
1019 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
1020 | Utext s
-> "font: " ^ s
1021 | Uunexpected s
-> "unexpected: " ^ s
1022 | Ulaunch s
-> "launch: " ^ s
1023 | Unamed s
-> "named: " ^ s
1024 | Uremote
(filename
, pageno
) ->
1025 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
1028 let updateunder x y =
1029 match getunder x y with
1030 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
1032 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
1033 Wsi.setcursor
Wsi.CURSOR_INFO
1034 | Ulinkgoto
(pageno
, _
) ->
1036 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
1037 Wsi.setcursor
Wsi.CURSOR_INFO
1039 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
1040 Wsi.setcursor
Wsi.CURSOR_TEXT
1042 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
1043 Wsi.setcursor
Wsi.CURSOR_INHERIT
1045 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
1046 Wsi.setcursor
Wsi.CURSOR_INHERIT
1048 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
1049 Wsi.setcursor
Wsi.CURSOR_INHERIT
1050 | Uremote
(filename
, pageno
) ->
1051 if conf.underinfo
then showtext 'r'
1052 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
1053 Wsi.setcursor
Wsi.CURSOR_INFO
1056 let showlinktype under
=
1062 let s = undertext under
in
1067 let b = Buffer.create
(String.length
s + 1) in
1068 Buffer.add_string
b s;
1069 Buffer.add_char
b c
;
1073 let colorspace_of_string s =
1074 match String.lowercase
s with
1078 | _
-> failwith
"invalid colorspace"
1081 let int_of_colorspace = function
1087 let colorspace_of_int = function
1091 | n -> failwith
("invalid colorspace index " ^ string_of_int
n)
1094 let colorspace_to_string = function
1100 let mark_of_string s =
1101 match String.lowercase
s with
1102 | "word" -> Mark_word
1103 | "line" -> Mark_line
1104 | "block" -> Mark_block
1105 | "page" -> Mark_page
1106 | _
-> failwith
"invalid colorspace"
1109 let int_of_mark = function
1116 let mark_of_int = function
1121 | n -> failwith
("invalid mark index " ^ string_of_int
n)
1124 let mark_to_string = function
1125 | Mark_word
-> "word"
1126 | Mark_line
-> "line"
1127 | Mark_block
-> "block"
1128 | Mark_page
-> "page"
1131 let fitmodel_of_string s =
1132 match String.lowercase
s with
1133 | "width" -> FitWidth
1134 | "proportional" -> FitProportional
1136 | _
-> failwith
"invalid fit model"
1139 let int_of_fitmodel = function
1141 | FitProportional
-> 1
1145 let fitmodel_of_int = function
1147 | 1 -> FitProportional
1149 | n -> failwith
("invalid fit model index " ^ string_of_int
n)
1152 let fitmodel_to_string = function
1153 | FitWidth
-> "width"
1154 | FitProportional
-> "proportional"
1158 let intentry_with_suffix text key
=
1160 if key
>= 32 && key
< 127
1164 match Char.lowercase
c with
1166 let text = addchar text c in
1169 | 'k'
| 'm'
| '
g'
->
1170 let text = addchar text c in
1174 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1178 let multicolumns_to_string (n, a
, b) =
1180 then Printf.sprintf
"%d" n
1181 else Printf.sprintf
"%d,%d,%d" n a
b;
1184 let multicolumns_of_string s =
1186 (int_of_string
s, 0, 0)
1188 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1190 then failwith
"subtly broken"; (n, a
, b)
1196 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1197 if n != 4 then failwith
"incomplete read(len)";
1199 lor (Char.code
s.[0] lsl 24)
1200 lor (Char.code
s.[1] lsl 16)
1201 lor (Char.code
s.[2] lsl 8)
1202 lor (Char.code
s.[3] lsl 0)
1204 let s = String.create
len in
1205 let n = tempfailureretry
(Unix.read fd
s 0) len in
1206 if n != len then failwith
"incomplete read(data)";
1210 let btod b = if b then 1 else 0;;
1213 let b = Buffer.create
16 in
1214 Buffer.add_string
b "llll";
1217 let s = Buffer.contents
b in
1218 let n = String.length
s in
1220 (* dolog "wcmd %S" (String.sub s 4 len); *)
1221 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1222 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1223 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1224 s.[3] <- Char.chr
(len land 0xff);
1225 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1226 if n'
!= n then failwith
"write failed";
1231 let d = state.winh
- h
in
1232 max
conf.interpagespace
((d + 1) / 2)
1235 let rowyh (c, coverA
, coverB
) b n =
1236 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1238 let _, _, vy
, (_, _, h
, _) = b.(n) in
1241 let n'
= n - coverA
in
1244 let e = min
state.pagecount
(s + c) in
1245 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1246 let _, _, y, (_, _, h
, _) = b.(m
) in
1247 let miny = min
miny y in
1248 let maxh = max
maxh h
in
1249 find (m
+1) miny maxh
1254 match conf.columns
with
1255 | Cmulti
((_, _, _) as cl
, b) ->
1256 if Array.length
b > 0
1258 let y, h
= rowyh cl
b (Array.length
b - 1) in
1259 y + h
+ (if conf.presentation
then calcips h
else 0)
1262 if Array.length
b > 0
1264 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1265 y + h
+ (if conf.presentation
then calcips h
else 0)
1268 if Array.length
b > 0
1270 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1275 let getpageyh pageno
=
1276 let pageno = bound pageno 0 (state.pagecount
-1) in
1277 match conf.columns
with
1279 if Array.length
b = 0
1282 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1284 if conf.presentation
1290 if Array.length
b = 0
1293 let y, h
= rowyh cl
b pageno in
1295 if conf.presentation
1301 if Array.length
b = 0
1305 let (_, _, y, (_, _, h
, _)) = b.(n) in
1309 let getpagedim pageno =
1312 | (n, _, _, _) as pdim
:: rest
->
1314 then (if n = pageno then pdim
else ppdim
)
1319 f (-1, -1, -1, -1) state.pdims
1322 let getpagey pageno = fst
(getpageyh pageno);;
1324 let nogeomcmds cmds
=
1326 | s, [] -> String.length
s = 0
1331 let ((c, coverA
, coverB
) as cl
), b =
1332 match conf.columns
with
1333 | Csingle
b -> (1, 0, 0), b
1334 | Cmulti
(c, b) -> c, b
1335 | Csplit
(_, b) -> (1, 0, 0), b
1337 if Array.length
b = 0
1340 let rec bsearch nmin nmax
=
1342 then bound nmin
0 (state.pagecount
-1)
1344 let n = (nmax
+ nmin
) / 2 in
1345 let vy, h
= rowyh cl
b n in
1347 if conf.presentation
1349 let ips = calcips h
in
1350 let y0 = vy - ips in
1351 let y1 = vy + h
+ ips in
1355 then 0, vy + h
+ conf.interpagespace
1357 let y0 = vy - conf.interpagespace
in
1358 y0, y0 + h
+ conf.interpagespace
1361 if y >= y0 && y < y1
1368 if n < state.pagecount
- coverB
1369 then ((n-coverA
)/c)*c + coverA
1376 then bsearch (n+1) nmax
1377 else bsearch nmin
(n-1)
1380 let r = bsearch 0 (state.pagecount
-1) in
1384 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1385 let sh = sh - (hscrollh ()) in
1386 let rec fold accu
n =
1387 if n = Array.length
b
1390 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1393 || n = state.pagecount
- coverB
1394 || (n - coverA
) mod columns
= columns
- 1)
1400 let pagey = max
0 (y - vy) in
1401 let pagedispy = if pagey > 0 then 0 else vy - y in
1402 let pagedispx, pagex
=
1404 if n = coverA
- 1 || n = state.pagecount
- coverB
1405 then state.x + (wadjsb state.winw
- w
) / 2
1406 else dx + xoff
+ state.x
1413 let vw = wadjsb state.winw
- pagedispx in
1414 let pw = w
- pagex
in
1417 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1418 if pagevw > 0 && pagevh > 0
1422 ; pagedimno
= pdimno
1429 ; pagedispx = pagedispx
1430 ; pagedispy = pagedispy
1442 List.rev
(fold [] (page_of_y y));
1445 let layoutS (columns
, b) y sh =
1446 let sh = sh - hscrollh () in
1447 let rec fold accu n =
1448 if n = Array.length
b
1451 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1458 let x = xoff
+ state.x in
1459 let pagey = max
0 (y - vy) in
1460 let pagedispy = if pagey > 0 then 0 else vy - y in
1461 let pagedispx, pagex
=
1475 let pagecolw = pagew
/columns
in
1477 if pagecolw < state.winw
1478 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1482 let vw = wadjsb state.winw
- pagedispx in
1483 let pw = pagew
- pagex
in
1486 let pagevw = min
pagevw pagecolw in
1487 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1488 if pagevw > 0 && pagevh > 0
1491 { pageno = n/columns
1492 ; pagedimno
= pdimno
1499 ; pagedispx = pagedispx
1500 ; pagedispy = pagedispy
1501 ; pagecol
= n mod columns
1512 List.rev
(fold [] 0)
1516 if nogeomcmds state.geomcmds
1518 match conf.columns
with
1519 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1520 | Cmulti
c -> layoutN c y sh
1521 | Csplit
s -> layoutS s y sh
1526 let y = state.y + incr
in
1528 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1533 let tilex = l.pagex
mod conf.tilew
in
1534 let tiley = l.pagey mod conf.tileh
in
1536 let col = l.pagex
/ conf.tilew
in
1537 let row = l.pagey / conf.tileh
in
1539 let rec rowloop row y0 dispy h
=
1543 let dh = conf.tileh
- y0 in
1544 let dh = min h
dh in
1545 let rec colloop col x0 dispx w
=
1549 let dw = conf.tilew
- x0 in
1550 let dw = min w
dw in
1552 f col row dispx dispy
x0 y0 dw dh;
1553 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1556 colloop col tilex l.pagedispx l.pagevw;
1557 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1560 if l.pagevw > 0 && l.pagevh > 0
1561 then rowloop row tiley l.pagedispy l.pagevh;
1564 let gettileopaque l col row =
1566 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1568 try Some
(Hashtbl.find state.tilemap
key)
1569 with Not_found
-> None
1572 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1573 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1574 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1577 let drawtiles l color
=
1579 let f col row x y tilex tiley w h
=
1580 match gettileopaque l col row with
1581 | Some
(opaque
, _, t
) ->
1582 let params = x, y, w
, h
, tilex, tiley in
1586 GlFunc.blend_func `zero `one_minus_src_color
;
1588 drawtile
params opaque
;
1590 then Gl.disable `blend
;
1593 let s = Printf.sprintf
1597 let w = measurestr
fstate.fontsize
s in
1598 GlMisc.push_attrib
[`current
];
1599 GlDraw.color
(0.0, 0.0, 0.0);
1601 (float (x-2), float (y-2))
1602 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1603 GlDraw.color
(1.0, 1.0, 1.0);
1604 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1605 GlMisc.pop_attrib
();
1610 let lw = wadjsb state.winw
- x in
1613 let lh = state.winh
- y in
1616 begin match state.texid
with
1618 Gl.enable `texture_2d
;
1619 GlTex.bind_texture `texture_2d id
;
1622 and x1 = float (x+w)
1623 and y1 = float (y+h
) in
1625 let tw = float w /. 16.0
1626 and th
= float h
/. 16.0 in
1627 let tx0 = float tilex /. 16.0
1628 and ty0
= float tiley /. 16.0 in
1630 and ty1
= ty0
+. th
in
1631 GlDraw.begins `quads
;
1632 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1633 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1634 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1635 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1638 Gl.disable `texture_2d
;
1640 GlDraw.color
(1.0, 1.0, 1.0);
1643 (float (x+w), float (y+h
));
1645 if w > 128 && h
> fstate.fontsize
+ 10
1647 GlDraw.color
(0.0, 0.0, 0.0);
1650 then (col*conf.tilew
, row*conf.tileh
)
1653 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r;
1660 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1662 let tilevisible1 l x y =
1664 and ax1
= l.pagex
+ l.pagevw
1666 and ay1
= l.pagey + l.pagevh in
1670 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1671 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1673 let rx0 = max
ax0 bx0
1674 and ry0
= max ay0 by0
1675 and rx1
= min ax1
bx1
1676 and ry1
= min ay1 by1
in
1678 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1679 nonemptyintersection
1682 let tilevisible layout n x y =
1683 let rec findpageinlayout m
= function
1684 | l :: rest
when l.pageno = n ->
1685 tilevisible1 l x y || (
1686 match conf.columns
with
1687 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1690 | _ :: rest
-> findpageinlayout 0 rest
1693 findpageinlayout 0 layout;
1696 let tileready l x y =
1697 tilevisible1 l x y &&
1698 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1701 let tilepage n p
layout =
1702 let rec loop = function
1706 let f col row _ _ _ _ _ _ =
1707 if state.currently
= Idle
1709 match gettileopaque l col row with
1712 let x = col*conf.tilew
1713 and y = row*conf.tileh
in
1715 let w = l.pagew
- x in
1719 let h = l.pageh
- y in
1724 then getpbo
w h conf.colorspace
1727 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1730 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1731 conf.tilew
, conf.tileh
1740 if nogeomcmds state.geomcmds
1744 let preloadlayout y =
1745 let y = if y < state.winh
then 0 else y - state.winh
in
1746 let h = state.winh
*3 in
1751 let rec loop pages
=
1752 if state.currently
!= Idle
1757 begin match getopaque l.pageno with
1759 wcmd "page %d %d" l.pageno l.pagedimno
;
1760 state.currently
<- Loading
(l, state.gen
);
1762 tilepage l.pageno opaque pages
;
1767 if nogeomcmds state.geomcmds
1773 if conf.preload && state.currently
= Idle
1774 then load (preloadlayout state.y);
1777 let layoutready layout =
1778 let rec fold all ls
=
1779 all
&& match ls
with
1781 let seen = ref false in
1782 let allvisible = ref true in
1783 let foo col row _ _ _ _ _ _ =
1785 allvisible := !allvisible &&
1786 begin match gettileopaque l col row with
1792 fold (!seen && !allvisible) rest
1795 let alltilesvisible = fold true layout in
1800 let y = bound y 0 state.maxy
in
1801 let y, layout, proceed
=
1802 match conf.maxwait
with
1803 | Some time
when state.ghyll
== noghyll ->
1804 begin match state.throttle
with
1806 let layout = layout y state.winh
in
1807 let ready = layoutready layout in
1811 state.throttle
<- Some
(layout, y, now ());
1813 else G.postRedisplay "gotoy showall (None)";
1815 | Some
(_, _, started
) ->
1816 let dt = now () -. started
in
1819 state.throttle
<- None
;
1820 let layout = layout y state.winh
in
1822 G.postRedisplay "maxwait";
1829 let layout = layout y state.winh
in
1830 if not
!wtmode || layoutready layout
1831 then G.postRedisplay "gotoy ready";
1837 state.layout <- layout;
1838 begin match state.mode
with
1839 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1840 let rec loop = function
1842 state.mode
<- LinkNav
(Ltgendir
0)
1843 | l :: _ when l.pageno = pageno ->
1844 begin match getopaque pageno with
1846 state.mode
<- LinkNav
(Ltgendir
0)
1848 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1849 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1850 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1851 then state.mode
<- LinkNav
(Ltgendir
0)
1853 | _ :: rest
-> loop rest
1858 begin match state.mode
with
1859 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1860 if not
(pagevisible layout pageno)
1862 match state.layout with
1865 state.mode
<- Birdseye
(
1866 conf, leftx
, l.pageno, hooverpageno
, anchor
1869 | LinkNav
(Ltgendir dir
as lt
) ->
1871 let rec loop = function
1874 match getopaque l.pageno with
1880 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1882 if dir
> 0 then LDfirst
else LDlast
1888 | Lnotfound
-> loop rest
1890 showlinktype (getlink opaque
n);
1891 Ltexact
(l.pageno, n)
1895 state.mode
<- LinkNav
linknav
1900 state.ghyll
<- noghyll;
1903 let mx, my
= state.mpos
in
1908 let conttiling pageno opaque
=
1909 tilepage pageno opaque
1910 (if conf.preload then preloadlayout state.y else state.layout)
1913 let gotoy_and_clear_text y =
1914 if not
conf.verbose
then state.text <- "";
1920 let coloff = l.pagecol
* l.pageh
in
1921 float (l.pagey + coloff) /. float l.pageh
1928 if conf.presentation
1929 then float l.pagedispy /. float (calcips l.pageh
)
1930 else float l.pagedispy /. float conf.interpagespace
1933 (l.pageno, top, dtop)
1937 match state.layout with
1938 | l :: _ -> getanchor1 l
1940 let n = page_of_y state.y in
1944 let y, h = getpageyh n in
1945 let dy = y - state.y in
1947 if conf.presentation
1949 let ips = calcips h in
1950 float (dy + ips) /. float ips
1952 float dy /. float conf.interpagespace
1957 let getanchory (n, top, dtop) =
1958 let y, h = getpageyh n in
1959 if conf.presentation
1961 let ips = calcips h in
1962 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1964 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1967 let gotoanchor anchor
=
1968 gotoy (getanchory anchor
);
1972 cbput state.hists
.nav
(getanchor ());
1976 let anchor = cbgetc state.hists
.nav dir
in
1981 let scroll f n a
b =
1982 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1984 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1986 then s (float f /. float a
)
1989 then 1.0 -. s ((float (f-b) /. float (n-b)))
1995 (* courtesy: (calc-eval "integ(3x^2-2x^3,x)") *)
1996 let iv x = x**3.-.0.5*.x**4. in
1998 let ins = float a
*. iv1
1999 and outs
= float (n-b) *. iv1 in
2001 ins +. outs
+. float ones
2003 let rec set (_N
, _A
, _B
) y sy
=
2004 let sum = summa
1.0 _N _A _B
in
2005 let dy = float (y - sy
) in
2009 then state.ghyll
<- noghyll
2012 let s = scroll n _N _A _B
in
2013 let y1 = y1 +. ((s *. dy) /. sum) in
2014 gotoy_and_clear_text (truncate
y1);
2015 state.ghyll
<- gf (n+1) y1;
2019 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
2021 gf 0 (float state.y)
2024 match conf.ghyllscroll
with
2026 gotoy_and_clear_text y
2028 if state.ghyll
== noghyll
2029 then set nab
y state.y
2030 else state.ghyll
(Some
y)
2033 let gotopage n top =
2034 let y, h = getpageyh n in
2035 let y = y + (truncate
(top *. float h)) in
2039 let gotopage1 n top =
2040 let y = getpagey n in
2045 let invalidate s f =
2050 match state.geomcmds
with
2051 | ps
, [] when String.length ps
= 0 ->
2053 state.geomcmds
<- s, [];
2056 state.geomcmds
<- ps
, [s, f];
2058 | ps
, (s'
, _) :: rest
when s'
= s ->
2059 state.geomcmds
<- ps
, ((s, f) :: rest
);
2062 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2066 Hashtbl.iter
(fun _ opaque
->
2067 wcmd "freepage %s" opaque
;
2069 Hashtbl.clear
state.pagemap
;
2073 if not
(Queue.is_empty
state.tilelru
)
2075 Queue.iter
(fun (k
, p
, s) ->
2076 wcmd "freetile %s" p
;
2077 state.memused
<- state.memused
- s;
2078 Hashtbl.remove
state.tilemap k
;
2080 state.uioh#infochanged Memused
;
2081 Queue.clear
state.tilelru
;
2087 let h = truncate
(float h*.conf.zoom
) in
2088 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2092 let opendoc path password
=
2094 state.password
<- password
;
2095 state.gen
<- state.gen
+ 1;
2096 state.docinfo
<- [];
2099 setaalevel
conf.aalevel
;
2101 if String.length
state.origin
= 0
2105 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2106 wcmd "open %d %s\000%s\000" (btod !wtmode) path password
;
2107 invalidate "reqlayout"
2109 wcmd "reqlayout %d %d %d %s\000"
2110 conf.angle
(int_of_fitmodel conf.fitmodel
)
2111 (stateh state.winh
) state.nameddest
2116 state.anchor <- getanchor ();
2117 opendoc state.path
state.password
;
2121 let c = c *. conf.colorscale
in
2125 let scalecolor2 (r, g, b) =
2126 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2129 let docolumns = function
2131 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2132 let rec loop pageno pdimno pdim
y ph pdims
=
2133 if pageno = state.pagecount
2136 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2138 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2139 pdimno+1, pdim
, rest
2143 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2145 (if conf.presentation
2146 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2147 else (if pageno = 0 then 0 else conf.interpagespace
)
2150 a.(pageno) <- (pdimno, x, y, pdim
);
2151 loop (pageno+1) pdimno pdim
(y + h) h pdims
2153 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2154 conf.columns
<- Csingle
a;
2156 | Cmulti
((columns
, coverA
, coverB
), _) ->
2157 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2158 let rec loop pageno pdimno pdim
x y rowh pdims
=
2159 let rec fixrow m
= if m
= pageno then () else
2160 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2163 let y = y + (rowh
- h) / 2 in
2164 a.(m
) <- (pdimno, x, y, pdim
);
2168 if pageno = state.pagecount
2169 then fixrow (((pageno - 1) / columns
) * columns
)
2171 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2173 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2174 pdimno+1, pdim
, rest
2179 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2181 let x = (wadjsb state.winw
- w) / 2 in
2183 if conf.presentation
then calcips h else conf.interpagespace
in
2184 x, y + ips + rowh
, h
2187 if (pageno - coverA
) mod columns
= 0
2189 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2191 if conf.presentation
2193 let ips = calcips h in
2194 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2196 y + (if pageno = 0 then 0 else conf.interpagespace
)
2200 else x, y, max rowh
h
2204 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2207 if pageno = columns
&& conf.presentation
2209 let ips = calcips rowh
in
2210 for i
= 0 to pred columns
2212 let (pdimno, x, y, pdim
) = a.(i
) in
2213 a.(i
) <- (pdimno, x, y+ips, pdim
)
2219 fixrow (pageno - columns
);
2224 a.(pageno) <- (pdimno, x, y, pdim
);
2225 let x = x + w + xoff
*2 + conf.interpagespace
in
2226 loop (pageno+1) pdimno pdim
x y rowh' pdims
2228 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2229 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2232 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2233 let rec loop pageno pdimno pdim
y pdims
=
2234 if pageno = state.pagecount
2237 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2239 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2240 pdimno+1, pdim
, rest
2245 let rec loop1 n x y =
2246 if n = c then y else (
2247 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2248 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2251 let y = loop1 0 0 y in
2252 loop (pageno+1) pdimno pdim
y pdims
2254 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2255 conf.columns
<- Csplit
(c, a);
2259 docolumns conf.columns
;
2260 state.maxy
<- calcheight ();
2261 if state.reprf
== noreprf
2263 match state.mode
with
2264 | Birdseye
(_, _, pageno, _, _) ->
2265 let y, h = getpageyh pageno in
2266 let top = (state.winh
- h) / 2 in
2267 gotoy (max
0 (y - top))
2268 | _ -> gotoanchor state.anchor
2272 state.reprf
<- noreprf;
2277 GlDraw.viewport
0 0 w h;
2278 let firsttime = state.geomcmds
== firstgeomcmds in
2279 if not
firsttime && nogeomcmds state.geomcmds
2280 then state.anchor <- getanchor ();
2283 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2286 setfontsize fstate.fontsize
;
2287 GlMat.mode `modelview
;
2288 GlMat.load_identity
();
2290 GlMat.mode `projection
;
2291 GlMat.load_identity
();
2292 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2293 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2294 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2299 else float state.x /. float state.w
2301 invalidate "geometry"
2305 then state.x <- truncate
(relx *. float w);
2307 match conf.columns
with
2309 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2310 | Csplit
(c, _) -> w * c
2312 wcmd "geometry %d %d %d"
2313 w (stateh h) (int_of_fitmodel conf.fitmodel
)
2318 let len = String.length
state.text in
2321 match state.mode
with
2322 | Textentry
_ | View
| LinkNav
_ ->
2323 let h, _, _ = state.uioh#scrollpw
in
2329 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2330 (x+.w, float (state.winh
- hscrollh))
2333 let w = float (wadjsb state.winw
- 1) in
2334 if state.progress
>= 0.0 && state.progress
< 1.0
2336 GlDraw.color
(0.3, 0.3, 0.3);
2337 let w1 = w *. state.progress
in
2339 GlDraw.color
(0.0, 0.0, 0.0);
2343 GlDraw.color
(0.0, 0.0, 0.0);
2347 GlDraw.color
(1.0, 1.0, 1.0);
2348 drawstring fstate.fontsize
2349 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2352 match state.mode
with
2353 | Textentry
((prefix
, text, _, _, _, _), _) ->
2357 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2359 Printf.sprintf
"%s%s_" prefix
text
2368 if not
(istextentry state.mode
) && state.uioh#eformsgs
2370 let s1 = "(press 'e' to review error messasges)" in
2371 if String.length
s > 0 then s ^
" " ^
s1 else s1
2376 if String.length
s > 0
2381 let len = Queue.length
state.tilelru
in
2383 match state.throttle
with
2386 then preloadlayout state.y
2388 | Some
(layout, _, _) ->
2392 if state.memused
<= conf.memlimit
2397 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2398 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2399 let (_, pw, ph
, _) = getpagedim n in
2402 && colorspace
= conf.colorspace
2403 && angle
= conf.angle
2407 let x = col*conf.tilew
2408 and y = row*conf.tileh
in
2409 tilevisible (Lazy.force_val
layout) n x y
2411 then Queue.push lruitem
state.tilelru
2414 wcmd "freetile %s" p
;
2415 state.memused
<- state.memused
- s;
2416 state.uioh#infochanged Memused
;
2417 Hashtbl.remove
state.tilemap k
;
2425 let logcurrently = function
2426 | Idle
-> dolog
"Idle"
2427 | Loading
(l, gen
) ->
2428 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2429 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2431 "Tiling %d[%d,%d] page=%s cs=%s angle"
2432 l.pageno col row pageopaque
2433 (colorspace_to_string colorspace
)
2435 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2436 angle gen
conf.angle
state.gen
2438 conf.tilew
conf.tileh
2445 let r = Str.regexp
" " in
2446 fun s -> Str.bounded_split
r s 2;
2449 let onpagerect pageno f =
2451 match conf.columns
with
2452 | Cmulti
(_, b) -> b
2454 | Csplit
(_, b) -> b
2456 if pageno >= 0 && pageno < Array.length
b
2458 let (pdimno, _, _, (_, _, _, _)) = b.(pageno) in
2459 let r = getpdimrect
pdimno in
2460 f (r.(1)-.r.(0)) (r.(3)-.r.(2))
2463 let gotopagexy1 pageno x y =
2464 onpagerect pageno (fun w h ->
2466 let _,w1,_,leftx
= getpagedim pageno in
2467 let wh = state.winh
- hscrollh () in
2468 let sw = float w1 /. w in
2470 let x = leftx
+ state.x + truncate
x in
2472 if x < 0 || x >= wadjsb state.winw
2476 let py, h = getpageyh pageno in
2477 let pdy = truncate
(top *. float h) in
2478 let y'
= py + pdy in
2479 let dy = y'
- state.y in
2481 if x != state.x || not
(dy > 0 && dy < wh)
2483 if conf.presentation
2485 if abs
(py - y'
) > wh
2492 if state.x != sx || state.y != sy
2497 let ww = wadjsb state.winw
in
2499 and qy
= pdy / wh in
2501 and y = py + qy
* wh in
2502 let x = if -x + ww > w1 then -(w1-ww) else x
2503 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2505 if conf.presentation
2507 if abs
(py - y'
) > wh
2517 gotoy_and_clear_text y;
2519 else gotoy_and_clear_text state.y;
2523 let gotopagexy pageno x y =
2524 match state.mode
with
2525 | Birdseye
_ -> gotopage pageno 0.0
2526 | _ -> gotopagexy1 pageno x y
2530 (* dolog "%S" cmds; *)
2531 let cl = splitatspace cmds
in
2533 try Scanf.sscanf
s fmt
f
2535 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2540 state.uioh#infochanged Pdim
;
2543 | "clearrects" :: [] ->
2544 state.rects
<- state.rects1
;
2545 G.postRedisplay "clearrects";
2547 | "continue" :: args :: [] ->
2548 let n = scan args "%u" (fun n -> n) in
2549 state.pagecount
<- n;
2550 begin match state.currently
with
2552 state.currently
<- Idle
;
2553 state.outlines
<- Array.of_list
(List.rev
l)
2557 let cur, cmds
= state.geomcmds
in
2558 if String.length
cur = 0
2559 then failwith
"umpossible";
2561 begin match List.rev cmds
with
2563 state.geomcmds
<- "", [];
2567 state.geomcmds
<- s, List.rev rest
;
2569 if conf.maxwait
= None
&& not
!wtmode
2570 then G.postRedisplay "continue";
2572 | "title" :: args :: [] ->
2575 | "msg" :: args :: [] ->
2578 | "vmsg" :: args :: [] ->
2580 then showtext ' '
args
2582 | "emsg" :: args :: [] ->
2583 Buffer.add_string
state.errmsgs
args;
2584 state.newerrmsgs
<- true;
2585 G.postRedisplay "error message"
2587 | "progress" :: args :: [] ->
2588 let progress, text =
2591 f, String.sub
args pos
(String.length
args - pos
))
2594 state.progress <- progress;
2595 G.postRedisplay "progress"
2597 | "firstmatch" :: args :: [] ->
2598 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2599 scan args "%u %d %f %f %f %f %f %f %f %f"
2600 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2601 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2603 let y = (getpagey pageno) + truncate
y0 in
2606 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2608 | "match" :: args :: [] ->
2609 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2610 scan args "%u %d %f %f %f %f %f %f %f %f"
2611 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2612 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2615 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2617 | "page" :: args :: [] ->
2618 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2619 begin match state.currently
with
2620 | Loading
(l, gen
) ->
2621 vlog "page %d took %f sec" l.pageno t
;
2622 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2623 begin match state.throttle
with
2625 let preloadedpages =
2627 then preloadlayout state.y
2632 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2633 IntSet.empty
preloadedpages
2636 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2637 if not
(IntSet.mem
pageno set)
2639 wcmd "freepage %s" opaque
;
2645 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2648 state.currently
<- Idle
;
2651 tilepage l.pageno pageopaque state.layout;
2653 load preloadedpages;
2654 if pagevisible state.layout l.pageno
2655 && layoutready state.layout
2656 then G.postRedisplay "page";
2659 | Some
(layout, _, _) ->
2660 state.currently
<- Idle
;
2661 tilepage l.pageno pageopaque layout;
2666 dolog
"Inconsistent loading state";
2667 logcurrently state.currently
;
2671 | "tile" :: args :: [] ->
2672 let (x, y, opaque
, size
, t
) =
2673 scan args "%u %u %s %u %f"
2674 (fun x y p size t
-> (x, y, p
, size
, t
))
2676 begin match state.currently
with
2677 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2678 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2681 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2683 wcmd "freetile %s" opaque
;
2684 state.currently
<- Idle
;
2688 puttileopaque l col row gen cs angle opaque size t
;
2689 state.memused
<- state.memused
+ size
;
2690 state.uioh#infochanged Memused
;
2692 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2693 opaque
, size
) state.tilelru
;
2696 match state.throttle
with
2697 | None
-> state.layout
2698 | Some
(layout, _, _) -> layout
2701 state.currently
<- Idle
;
2703 && conf.colorspace
= cs
2704 && conf.angle
= angle
2705 && tilevisible layout l.pageno x y
2706 then conttiling l.pageno pageopaque;
2708 begin match state.throttle
with
2710 preload state.layout;
2712 && conf.colorspace
= cs
2713 && conf.angle
= angle
2714 && tilevisible state.layout l.pageno x y
2715 && (not
!wtmode || layoutready state.layout)
2716 then G.postRedisplay "tile nothrottle";
2718 | Some
(layout, y, _) ->
2719 let ready = layoutready layout in
2723 state.layout <- layout;
2724 state.throttle
<- None
;
2725 G.postRedisplay "throttle";
2732 dolog
"Inconsistent tiling state";
2733 logcurrently state.currently
;
2737 | "pdim" :: args :: [] ->
2738 let (n, w, h, _) as pdim
=
2739 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2742 match conf.fitmodel
, conf.columns
with
2743 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2746 state.uioh#infochanged Pdim
;
2747 state.pdims
<- pdim :: state.pdims
2749 | "o" :: args :: [] ->
2750 let (l, n, t
, h, pos
) =
2751 scan args "%u %u %d %u %n"
2752 (fun l n t
h pos
-> l, n, t
, h, pos
)
2754 let s = String.sub
args pos
(String.length
args - pos
) in
2755 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2756 begin match state.currently
with
2757 | Outlining outlines
->
2758 state.currently
<- Outlining
(outline :: outlines
)
2760 state.currently
<- Outlining
[outline]
2762 dolog
"invalid outlining state";
2763 logcurrently currently
2766 | "a" :: args :: [] ->
2768 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2770 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2772 | "info" :: args :: [] ->
2773 state.docinfo
<- (1, args) :: state.docinfo
2775 | "infoend" :: [] ->
2776 state.uioh#infochanged Docinfo
;
2777 state.docinfo
<- List.rev
state.docinfo
2780 failwith
(Printf.sprintf
"unknown cmd `%S'" cmds
)
2785 let action = function
2786 | HCprev
-> cbget cb ~
-1
2787 | HCnext
-> cbget cb
1
2788 | HCfirst
-> cbget cb ~
-(cb
.rc)
2789 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2790 and cancel
() = cb
.rc <- rc
2794 let search pattern forward
=
2795 match conf.columns
with
2797 showtext '
!'
"searching does not work properly in split columns mode"
2799 if String.length pattern
> 0
2802 match state.layout with
2805 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2807 wcmd "search %d %d %d %d,%s\000"
2808 (btod conf.icase
) pn py (btod forward
) pattern
;
2811 let intentry text key =
2813 if key >= 32 && key < 127
2819 let text = addchar text c in
2823 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2827 let linknentry text key =
2829 if key >= 32 && key < 127
2835 let text = addchar text c in
2839 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2844 if String.length
s > 0
2847 let l = String.length
s in
2848 let rec loop pos
n = if pos
= l then n else
2849 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2850 loop (pos
+1) (n*26 + m)
2853 let rec loop n = function
2856 match getopaque l.pageno with
2857 | None
-> loop n rest
2859 let m = getlinkcount opaque
in
2862 let under = getlink opaque
n in
2865 else loop (n-m) rest
2867 loop n state.layout;
2871 let textentry text key =
2872 if key land 0xff00 = 0xff00
2874 else TEcont
(text ^ toutf8
key)
2877 let reqlayout angle fitmodel
=
2878 match state.throttle
with
2880 if nogeomcmds state.geomcmds
2881 then state.anchor <- getanchor ();
2882 conf.angle
<- angle
mod 360;
2885 match state.mode
with
2886 | LinkNav
_ -> state.mode
<- View
2889 conf.fitmodel
<- fitmodel
;
2890 invalidate "reqlayout"
2892 wcmd "reqlayout %d %d %d"
2893 conf.angle
(int_of_fitmodel conf.fitmodel
) (stateh state.winh
)
2898 let settrim trimmargins trimfuzz
=
2899 if nogeomcmds state.geomcmds
2900 then state.anchor <- getanchor ();
2901 conf.trimmargins
<- trimmargins
;
2902 conf.trimfuzz
<- trimfuzz
;
2903 let x0, y0, x1, y1 = trimfuzz
in
2904 invalidate "settrim"
2906 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2911 match state.throttle
with
2913 let zoom = max
0.0001 zoom in
2914 if zoom <> conf.zoom
2916 state.prevzoom
<- conf.zoom;
2918 reshape state.winw
state.winh
;
2919 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2922 | Some
(layout, y, started
) ->
2924 match conf.maxwait
with
2928 let dt = now () -. started
in
2936 let setcolumns mode columns coverA coverB
=
2937 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2941 then showtext '
!'
"split mode doesn't work in bird's eye"
2943 conf.columns
<- Csplit
(-columns
, [||]);
2951 conf.columns
<- Csingle
[||];
2956 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2960 reshape state.winw
state.winh
;
2963 let enterbirdseye () =
2964 let zoom = float conf.thumbw
/. float state.winw
in
2965 let birdseyepageno =
2966 let cy = state.winh
/ 2 in
2970 let rec fold best
= function
2973 let d = cy - (l.pagedispy + l.pagevh/2)
2974 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2975 if abs
d < abs dbest
2982 state.mode
<- Birdseye
(
2983 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2986 conf.presentation
<- false;
2987 conf.interpagespace
<- 10;
2988 conf.hlinks
<- false;
2989 conf.fitmodel
<- FitProportional
;
2991 state.mstate
<- Mnone
;
2992 conf.maxwait
<- None
;
2994 match conf.beyecolumns
with
2997 Cmulti
((c, 0, 0), [||])
2998 | None
-> Csingle
[||]
3000 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3003 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
3008 reshape state.winw
state.winh
;
3011 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
3013 conf.zoom <- c.zoom;
3014 conf.presentation
<- c.presentation
;
3015 conf.interpagespace
<- c.interpagespace
;
3016 conf.maxwait
<- c.maxwait
;
3017 conf.hlinks
<- c.hlinks
;
3018 conf.fitmodel
<- c.fitmodel
;
3019 conf.beyecolumns
<- (
3020 match conf.columns
with
3021 | Cmulti
((c, _, _), _) -> Some
c
3023 | Csplit
_ -> failwith
"leaving bird's eye split mode"
3026 match c.columns
with
3027 | Cmulti
(c, _) -> Cmulti
(c, [||])
3028 | Csingle
_ -> Csingle
[||]
3029 | Csplit
(c, _) -> Csplit
(c, [||])
3034 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3037 reshape state.winw
state.winh
;
3038 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3041 let togglebirdseye () =
3042 match state.mode
with
3043 | Birdseye vals
-> leavebirdseye vals
true
3044 | View
-> enterbirdseye ()
3048 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3049 let pageno = max
0 (pageno - incr
) in
3050 let rec loop = function
3051 | [] -> gotopage1 pageno 0
3052 | l :: _ when l.pageno = pageno ->
3053 if l.pagedispy >= 0 && l.pagey = 0
3054 then G.postRedisplay "upbirdseye"
3055 else gotopage1 pageno 0
3056 | _ :: rest
-> loop rest
3059 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3062 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3063 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3064 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3065 let rec loop = function
3067 let y, h = getpageyh pageno in
3068 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3070 | l :: _ when l.pageno = pageno ->
3071 if l.pagevh != l.pageh
3072 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3073 else G.postRedisplay "downbirdseye"
3074 | _ :: rest
-> loop rest
3079 let optentry mode
_ key =
3080 let btos b = if b then "on" else "off" in
3081 if key >= 32 && key < 127
3083 let c = Char.chr
key in
3087 try conf.scrollstep
<- int_of_string
s with exc
->
3088 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3090 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3095 conf.autoscrollstep
<- int_of_string
s;
3096 if state.autoscroll
<> None
3097 then state.autoscroll
<- Some
conf.autoscrollstep
3099 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3101 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3106 let n, a, b = multicolumns_of_string s in
3107 setcolumns mode
n a b;
3109 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3111 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3116 let zoom = float (int_of_string
s) /. 100.0 in
3119 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3121 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3126 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3128 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3129 begin match mode
with
3131 leavebirdseye beye
false;
3136 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3138 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3143 Some
(int_of_string
s)
3145 state.text <- Printf.sprintf
"bad integer `%s': %s"
3149 | Some angle
-> reqlayout angle
conf.fitmodel
3152 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3155 conf.icase
<- not
conf.icase
;
3156 TEdone
("case insensitive search " ^
(btos conf.icase
))
3159 conf.preload <- not
conf.preload;
3161 TEdone
("preload " ^
(btos conf.preload))
3164 conf.verbose
<- not
conf.verbose
;
3165 TEdone
("verbose " ^
(btos conf.verbose
))
3168 conf.debug
<- not
conf.debug
;
3169 TEdone
("debug " ^
(btos conf.debug
))
3172 conf.maxhfit
<- not
conf.maxhfit
;
3173 state.maxy
<- calcheight ();
3174 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3177 conf.crophack
<- not
conf.crophack
;
3178 TEdone
("crophack " ^
btos conf.crophack
)
3182 match conf.maxwait
with
3184 conf.maxwait
<- Some infinity
;
3185 "always wait for page to complete"
3187 conf.maxwait
<- None
;
3188 "show placeholder if page is not ready"
3193 conf.underinfo
<- not
conf.underinfo
;
3194 TEdone
("underinfo " ^
btos conf.underinfo
)
3197 conf.savebmarks
<- not
conf.savebmarks
;
3198 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3204 match state.layout with
3209 conf.interpagespace
<- int_of_string
s;
3210 docolumns conf.columns
;
3211 state.maxy
<- calcheight ();
3212 let y = getpagey pageno in
3215 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3217 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3221 match conf.fitmodel
with
3222 | FitProportional
-> FitWidth
3223 | _ -> FitProportional
3225 reqlayout conf.angle
fm;
3226 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3229 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3230 TEdone
("trim margins " ^
btos conf.trimmargins
)
3233 conf.invert
<- not
conf.invert
;
3234 TEdone
("invert colors " ^
btos conf.invert
)
3238 cbput state.hists
.sel
s;
3241 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3242 textentry, ondone, true)
3246 then conf.pax
<- Some
(ref (0.0, 0, 0))
3247 else conf.pax
<- None
;
3248 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3251 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3257 class type lvsource
= object
3258 method getitemcount
: int
3259 method getitem
: int -> (string * int)
3260 method hasaction
: int -> bool
3269 method getactive
: int
3270 method getfirst
: int
3271 method getqsearch
: string
3272 method setqsearch
: string -> unit
3276 class virtual lvsourcebase
= object
3277 val mutable m_active
= 0
3278 val mutable m_first
= 0
3279 val mutable m_qsearch
= ""
3280 val mutable m_pan
= 0
3281 method getactive
= m_active
3282 method getfirst
= m_first
3283 method getqsearch
= m_qsearch
3284 method getpan
= m_pan
3285 method setqsearch
s = m_qsearch
<- s
3288 let withoutlastutf8 s =
3289 let len = String.length
s in
3297 let b = Char.code
s.[pos
] in
3298 if b land 0b11000000 = 0b11000000
3303 if Char.code
s.[len-1] land 0x80 = 0
3307 String.sub
s 0 first;
3310 let textentrykeyboard
3311 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3313 if key >= 0xffb0 && key <= 0xffb9
3314 then key - 0xffb0 + 48 else key
3317 state.mode
<- Textentry
(te
, onleave
);
3320 G.postRedisplay "textentrykeyboard enttext";
3322 let histaction cmd
=
3325 | Some
(action, _) ->
3326 state.mode
<- Textentry
(
3327 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3329 G.postRedisplay "textentry histaction"
3332 | 0xff08 -> (* backspace *)
3333 let s = withoutlastutf8 text in
3334 let len = String.length
s in
3335 if cancelonempty
&& len = 0
3338 G.postRedisplay "textentrykeyboard after cancel";
3341 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3344 | 0xff0d | 0xff8d -> (* (kp) enter *)
3347 G.postRedisplay "textentrykeyboard after confirm"
3349 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3350 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3351 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3352 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3354 | 0xff1b -> (* escape*)
3355 if String.length
text = 0
3357 begin match opthist
with
3359 | Some
(_, onhistcancel
) -> onhistcancel
()
3363 G.postRedisplay "textentrykeyboard after cancel2"
3366 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3369 | 0xff9f | 0xffff -> () (* delete *)
3372 && key land 0xff00 != 0xff00 (* keyboard *)
3373 && key land 0xfe00 != 0xfe00 (* xkb *)
3374 && key land 0xfd00 != 0xfd00 (* 3270 *)
3376 begin match onkey
text key with
3380 G.postRedisplay "textentrykeyboard after confirm2";
3383 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3387 G.postRedisplay "textentrykeyboard after cancel3"
3390 state.mode
<- Textentry
(te
, onleave
);
3391 G.postRedisplay "textentrykeyboard switch";
3395 vlog "unhandled key %s" (Wsi.keyname
key)
3398 let firstof first active
=
3399 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3400 then max
0 (active
- (fstate.maxrows
/2))
3404 let calcfirst first active
=
3407 let rows = active
- first in
3408 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3412 let scrollph y maxy
=
3413 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3414 let sh = float state.winh
/. sh in
3415 let sh = max
sh (float conf.scrollh
) in
3417 let percent = float y /. float maxy
in
3418 let position = (float state.winh
-. sh) *. percent in
3421 if position +. sh > float state.winh
3422 then float state.winh
-. sh
3428 let coe s = (s :> uioh
);;
3430 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3432 val m_pan
= source#getpan
3433 val m_first
= source#getfirst
3434 val m_active
= source#getactive
3435 val m_qsearch
= source#getqsearch
3436 val m_prev_uioh
= state.uioh
3438 method private elemunder
y =
3439 let n = y / (fstate.fontsize
+1) in
3440 if m_first
+ n < source#getitemcount
3442 if source#hasaction
(m_first
+ n)
3443 then Some
(m_first
+ n)
3450 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3451 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3452 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3453 GlDraw.color
(1., 1., 1.);
3454 Gl.enable `texture_2d
;
3455 let fs = fstate.fontsize
in
3457 let ww = fstate.wwidth
in
3458 let tabw = 30.0*.ww in
3459 let itemcount = source#getitemcount
in
3461 if (row - m_first
) > fstate.maxrows
3464 if row >= 0 && row < itemcount
3466 let (s, level
) = source#getitem
row in
3467 let y = (row - m_first
) * nfs in
3468 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3471 Gl.disable `texture_2d
;
3472 GlDraw.polygon_mode `both `line
;
3473 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3474 GlDraw.color
(1., 1., 1.) ~
alpha;
3475 GlDraw.rect (1., float (y + 1))
3476 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3477 GlDraw.polygon_mode `both `fill
;
3478 GlDraw.color
(1., 1., 1.);
3479 Gl.enable `texture_2d
;
3482 let drawtabularstring s =
3483 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3486 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3489 let len = String.length
s - tabpos - 1 in
3490 let s1 = String.sub
s 0 tabpos
3491 and s2
= String.sub
s (tabpos + 1) len in
3492 let nx = drawstr x s1 in
3494 let x = x +. (max
tabw sw) in
3501 let _ = drawtabularstring s in
3508 Gl.disable `texture_2d
;
3510 method updownlevel incr
=
3511 let len = source#getitemcount
in
3513 if m_active
>= 0 && m_active
< len
3514 then snd
(source#getitem m_active
)
3518 if i
= len then i
-1 else if i
= -1 then 0 else
3519 let _, l = source#getitem i
in
3520 if l != curlevel then i
else flow (i
+incr
)
3522 let active = flow m_active
in
3523 let first = calcfirst m_first
active in
3524 G.postRedisplay "outline updownlevel";
3525 {< m_active
= active; m_first
= first >}
3527 method private key1
key mask
=
3528 let set1 active first qsearch
=
3529 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3531 let search active pattern incr
=
3532 let active = if active = -1 then m_first
else active in
3535 if n >= 0 && n < source#getitemcount
3537 let s, _ = source#getitem
n in
3539 (try ignore
(Str.search_forward
re s 0); true
3540 with Not_found
-> false)
3542 else loop (n + incr
)
3549 let re = Str.regexp_case_fold pattern
in
3555 let itemcount = source#getitemcount
in
3556 let find start incr
=
3558 if i
= -1 || i
= itemcount
3561 if source#hasaction i
3563 else find (i
+ incr
)
3568 let set active first =
3569 let first = bound first 0 (itemcount - fstate.maxrows
) in
3571 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3574 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3576 let incr1 = if incr
> 0 then 1 else -1 in
3577 if isvisible m_first m_active
3580 let next = m_active
+ incr
in
3582 if next < 0 || next >= itemcount
3584 else find next incr1
3586 if abs
(m_active
- next) > fstate.maxrows
3592 let first = m_first
+ incr
in
3593 let first = bound first 0 (itemcount - fstate.maxrows
) in
3595 let next = m_active
+ incr
in
3596 let next = bound next 0 (itemcount - 1) in
3603 if isvisible first next
3610 let first = min
next m_first
in
3612 if abs
(next - first) > fstate.maxrows
3618 let first = m_first
+ incr
in
3619 let first = bound first 0 (itemcount - 1) in
3621 let next = m_active
+ incr
in
3622 let next = bound next 0 (itemcount - 1) in
3623 let next = find next incr1 in
3625 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3627 let active = if m_active
= -1 then next else m_active
in
3632 if isvisible first active
3638 G.postRedisplay "listview navigate";
3642 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3643 let incr = if key = 0x72 then -1 else 1 in
3645 match search (m_active
+ incr) m_qsearch
incr with
3647 state.text <- m_qsearch ^
" [not found]";
3650 state.text <- m_qsearch
;
3651 active, firstof m_first
active
3653 G.postRedisplay "listview ctrl-r/s";
3654 set1 active first m_qsearch
;
3656 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3657 if m_active
>= 0 && m_active
< source#getitemcount
3659 let s, _ = source#getitem m_active
in
3664 | 0xff08 -> (* backspace *)
3665 if String.length m_qsearch
= 0
3668 let qsearch = withoutlastutf8 m_qsearch
in
3669 let len = String.length
qsearch in
3673 G.postRedisplay "listview empty qsearch";
3674 set1 m_active m_first
"";
3678 match search m_active
qsearch ~
-1 with
3680 state.text <- qsearch ^
" [not found]";
3683 state.text <- qsearch;
3684 active, firstof m_first
active
3686 G.postRedisplay "listview backspace qsearch";
3687 set1 active first qsearch
3690 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3691 let pattern = m_qsearch ^ toutf8
key in
3693 match search m_active
pattern 1 with
3695 state.text <- pattern ^
" [not found]";
3698 state.text <- pattern;
3699 active, firstof m_first
active
3701 G.postRedisplay "listview qsearch add";
3702 set1 active first pattern;
3704 | 0xff1b -> (* escape *)
3706 if String.length m_qsearch
= 0
3708 G.postRedisplay "list view escape";
3711 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3713 | None
-> m_prev_uioh
3718 G.postRedisplay "list view kill qsearch";
3719 source#setqsearch
"";
3720 coe {< m_qsearch
= "" >}
3723 | 0xff0d | 0xff8d -> (* (kp) enter *)
3725 let self = {< m_qsearch
= "" >} in
3726 source#setqsearch
"";
3728 G.postRedisplay "listview enter";
3729 if m_active
>= 0 && m_active
< source#getitemcount
3731 source#exit
(coe self) false m_active m_first m_pan
"";
3734 source#exit
(coe self) true m_active m_first m_pan
"";
3737 begin match opt with
3738 | None
-> m_prev_uioh
3742 | 0xff9f | 0xffff -> (* (kp) delete *)
3745 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3746 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3747 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3748 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3750 | 0xff53 | 0xff98 -> (* (kp) right *)
3752 G.postRedisplay "listview right";
3753 coe {< m_pan
= m_pan
- 1 >}
3755 | 0xff51 | 0xff96 -> (* (kp) left *)
3757 G.postRedisplay "listview left";
3758 coe {< m_pan
= m_pan
+ 1 >}
3760 | 0xff50 | 0xff95 -> (* (kp) home *)
3761 let active = find 0 1 in
3762 G.postRedisplay "listview home";
3765 | 0xff57 | 0xff9c -> (* (kp) end *)
3766 let first = max
0 (itemcount - fstate.maxrows
) in
3767 let active = find (itemcount - 1) ~
-1 in
3768 G.postRedisplay "listview end";
3771 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3775 dolog
"listview unknown key %#x" key; coe self
3777 method key key mask
=
3778 match state.mode
with
3779 | Textentry te
-> textentrykeyboard key mask te
; coe self
3780 | _ -> self#key1
key mask
3782 method button button down
x y _ =
3785 | 1 when x > state.winw
- conf.scrollbw
->
3786 G.postRedisplay "listview scroll";
3789 let _, position, sh = self#
scrollph in
3790 if y > truncate
position && y < truncate
(position +. sh)
3792 state.mstate
<- Mscrolly
;
3796 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3797 let first = truncate
(s *. float source#getitemcount
) in
3798 let first = min source#getitemcount
first in
3799 Some
(coe {< m_first
= first; m_active
= first >})
3801 state.mstate
<- Mnone
;
3804 | 1 when not down
->
3805 begin match self#elemunder
y with
3807 G.postRedisplay "listview click";
3809 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3813 | n when (n == 4 || n == 5) && not down
->
3814 let len = source#getitemcount
in
3816 if n = 5 && m_first
+ fstate.maxrows
>= len
3820 let first = m_first
+ (if n == 4 then -1 else 1) in
3821 bound first 0 (len - 1)
3823 G.postRedisplay "listview wheel";
3824 Some
(coe {< m_first
= first >})
3825 | n when (n = 6 || n = 7) && not down
->
3826 let inc = m_first
+ (if n = 7 then -1 else 1) in
3827 G.postRedisplay "listview hwheel";
3828 Some
(coe {< m_pan
= m_pan
+ inc >})
3833 | None
-> m_prev_uioh
3837 match state.mstate
with
3839 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3840 let first = truncate
(s *. float source#getitemcount
) in
3841 let first = min source#getitemcount
first in
3842 G.postRedisplay "listview motion";
3843 coe {< m_first
= first; m_active
= first >}
3846 method pmotion
x y =
3847 if x < state.winw
- conf.scrollbw
3850 match self#elemunder
y with
3851 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3852 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3856 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3861 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3865 method infochanged
_ = ()
3867 method scrollpw
= (0, 0.0, 0.0)
3869 let nfs = fstate.fontsize
+ 1 in
3870 let y = m_first
* nfs in
3871 let itemcount = source#getitemcount
in
3872 let maxi = max
0 (itemcount - fstate.maxrows
) in
3873 let maxy = maxi * nfs in
3874 let p, h = scrollph y maxy in
3877 method modehash
= modehash
3878 method eformsgs
= false
3881 class outlinelistview ~source
=
3884 ~source
:(source
:> lvsource
)
3886 ~modehash
:(findkeyhash conf "outline")
3889 method key key mask
=
3890 let calcfirst first active =
3893 let rows = active - first in
3895 if String.length
state.text = 0
3897 else fstate.maxrows - 2
3899 if rows > maxrows then active - maxrows else first
3903 let active = m_active
+ incr in
3904 let active = bound active 0 (source#getitemcount
- 1) in
3905 let first = calcfirst m_first
active in
3906 G.postRedisplay "outline navigate";
3907 coe {< m_active
= active; m_first
= first >}
3909 let ctrl = Wsi.withctrl mask
in
3911 | 110 when ctrl -> (* ctrl-n *)
3912 source#narrow m_qsearch
;
3913 G.postRedisplay "outline ctrl-n";
3914 coe {< m_first
= 0; m_active
= 0 >}
3916 | 117 when ctrl -> (* ctrl-u *)
3918 G.postRedisplay "outline ctrl-u";
3920 coe {< m_first
= 0; m_active
= 0 >}
3922 | 108 when ctrl -> (* ctrl-l *)
3923 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3924 G.postRedisplay "outline ctrl-l";
3925 coe {< m_first
= first >}
3927 | 0xff9f | 0xffff -> (* (kp) delete *)
3928 source#remove m_active
;
3929 G.postRedisplay "outline delete";
3930 let active = max
0 (m_active
-1) in
3931 coe {< m_first
= firstof m_first
active;
3932 m_active
= active >}
3934 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3935 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3936 | 0xff55 | 0xff9a -> (* (kp) prior *)
3937 navigate ~
-(fstate.maxrows)
3938 | 0xff56 | 0xff9b -> (* (kp) next *)
3939 navigate fstate.maxrows
3941 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3945 G.postRedisplay "outline ctrl right";
3946 {< m_pan
= m_pan
+ 1 >}
3948 else self#updownlevel
1
3952 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3956 G.postRedisplay "outline ctrl left";
3957 {< m_pan
= m_pan
- 1 >}
3959 else self#updownlevel ~
-1
3963 | 0xff50 | 0xff95 -> (* (kp) home *)
3964 G.postRedisplay "outline home";
3965 coe {< m_first
= 0; m_active
= 0 >}
3967 | 0xff57 | 0xff9c -> (* (kp) end *)
3968 let active = source#getitemcount
- 1 in
3969 let first = max
0 (active - fstate.maxrows) in
3970 G.postRedisplay "outline end";
3971 coe {< m_active
= active; m_first
= first >}
3973 | _ -> super#
key key mask
3976 let outlinesource usebookmarks
=
3979 inherit lvsourcebase
3980 val mutable m_items
= empty
3981 val mutable m_orig_items
= empty
3982 val mutable m_prev_items
= empty
3983 val mutable m_narrow_pattern
= ""
3984 val mutable m_hadremovals
= false
3986 method getitemcount
=
3987 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3990 if n == Array.length m_items
&& m_hadremovals
3992 ("[Confirm removal]", 0)
3994 let s, n, _ = m_items
.(n) in
3997 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3998 ignore
(uioh
, first, qsearch);
3999 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
4001 if String.length m_narrow_pattern
= 0
4007 if not
confrimremoval
4009 let _, _, anchor = m_items
.(active) in
4010 gotoghyll (getanchory anchor);
4014 state.bookmarks
<- Array.to_list m_items
;
4015 m_orig_items
<- m_items
;
4018 else m_items
<- items;
4022 method hasaction
_ = true
4025 if Array.length m_items
!= Array.length m_orig_items
4026 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
4029 method narrow
pattern =
4030 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4034 let rec loop accu n =
4037 m_narrow_pattern
<- pattern;
4038 m_items
<- Array.of_list
accu
4041 let (s, _, _) as o = m_items
.(n) in
4043 if (try ignore
(Str.search_forward
re s 0); true
4044 with Not_found
-> false)
4050 loop [] (Array.length m_items
- 1)
4055 then Array.of_list
state.bookmarks
4058 m_items
<- m_orig_items
4063 if m >= 0 && m < Array.length m_items
4065 m_hadremovals
<- true;
4066 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4067 let n = if n >= m then n+1 else n in
4072 method reset
anchor items =
4073 m_hadremovals
<- false;
4074 if m_orig_items
== empty || m_prev_items
!= items
4076 m_orig_items
<- items;
4077 if String.length m_narrow_pattern
= 0
4078 then m_items
<- items;
4080 m_prev_items
<- items;
4081 let rely = getanchory anchor in
4083 let rec loop n best bestd
=
4084 if n = Array.length m_items
4087 let (_, _, anchor) = m_items
.(n) in
4088 let orely = getanchory anchor in
4089 let d = abs
(orely - rely) in
4092 else loop (n+1) best bestd
4097 m_first
<- firstof m_first
active
4101 let enterselector usebookmarks
=
4102 let source = outlinesource usebookmarks
in
4106 then Array.of_list
state.bookmarks
4109 if Array.length
outlines = 0
4111 showtext ' ' errmsg
;
4114 state.text <- source#greetmsg
;
4115 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4116 let anchor = getanchor () in
4117 source#reset
anchor outlines;
4118 state.uioh
<- coe (new outlinelistview ~
source);
4119 G.postRedisplay "enter selector";
4123 let enteroutlinemode =
4124 let f = enterselector false in
4125 fun ()-> f "Document has no outline";
4128 let enterbookmarkmode =
4129 let f = enterselector true in
4130 fun () -> f "Document has no bookmarks (yet)";
4133 let color_of_string s =
4134 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4135 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4139 let color_to_string (r, g, b) =
4140 let r = truncate
(r *. 256.0)
4141 and g = truncate
(g *. 256.0)
4142 and b = truncate
(b *. 256.0) in
4143 Printf.sprintf
"%d/%d/%d" r g b
4146 let irect_of_string s =
4147 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4150 let irect_to_string (x0,y0,x1,y1) =
4151 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4154 let makecheckers () =
4155 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4157 converted by Issac Trotts. July 25, 2002 *)
4158 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4159 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4160 let id = GlTex.gen_texture
() in
4161 GlTex.bind_texture `texture_2d
id;
4162 GlPix.store
(`unpack_alignment
1);
4163 GlTex.image2d
image;
4164 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4165 [ `mag_filter `nearest
; `min_filter `nearest
];
4169 let setcheckers enabled
=
4170 match state.texid
with
4172 if enabled
then state.texid
<- Some
(makecheckers ())
4177 GlTex.delete_texture texid
;
4178 state.texid
<- None
;
4182 let int_of_string_with_suffix s =
4183 let l = String.length
s in
4187 let suffix = Char.lowercase
s.[l-1] in
4189 | 'k'
-> String.sub
s 0 (l-1), 10
4190 | '
m'
-> String.sub
s 0 (l-1), 20
4191 | '
g'
-> String.sub
s 0 (l-1), 30
4195 let n = int_of_string
s1 in
4196 let m = n lsl shift
in
4198 then raise
(Failure
"value too large")
4202 let string_with_suffix_of_int n =
4207 if n land ((1 lsl 30) - 1) = 0
4210 if n land ((1 lsl 20) - 1) = 0
4213 if n land ((1 lsl 10) - 1) = 0
4220 let h = n mod 1000 in
4223 then string_of_int
h ^
s
4225 let s = Printf.sprintf
"_%03d%s" h s in
4232 let defghyllscroll = (40, 8, 32);;
4233 let ghyllscroll_of_string s =
4234 let (n, a, b) as nab
=
4237 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4239 if n <= a || n <= b || a >= b
4240 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4244 let ghyllscroll_to_string ((n, a, b) as nab
) =
4245 if nab
= defghyllscroll
4247 else Printf.sprintf
"%d,%d,%d" n a b;
4250 let describe_location () =
4251 let fn = page_of_y state.y in
4252 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4253 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4257 else (100. *. (float state.y /. float maxy))
4261 Printf.sprintf
"page %d of %d [%.2f%%]"
4262 (fn+1) state.pagecount
percent
4265 "pages %d-%d of %d [%.2f%%]"
4266 (fn+1) (ln+1) state.pagecount
percent
4269 let setpresentationmode v
=
4270 let n = page_of_y state.y in
4271 state.anchor <- (n, 0.0, 1.0);
4272 conf.presentation
<- v
;
4273 if conf.fitmodel
= FitPage
4274 then reqlayout conf.angle
conf.fitmodel
;
4279 let btos b = if b then "\xe2\x88\x9a" else "" in
4280 let showextended = ref false in
4281 let leave mode
= function
4282 | Confirm
-> state.mode
<- mode
4283 | Cancel
-> state.mode
<- mode
in
4286 val mutable m_first_time
= true
4287 val mutable m_l
= []
4288 val mutable m_a
= [||]
4289 val mutable m_prev_uioh
= nouioh
4290 val mutable m_prev_mode
= View
4292 inherit lvsourcebase
4294 method reset prev_mode prev_uioh
=
4295 m_a
<- Array.of_list
(List.rev m_l
);
4297 m_prev_mode
<- prev_mode
;
4298 m_prev_uioh
<- prev_uioh
;
4302 if n >= Array.length m_a
4306 | _, _, _, Action
_ -> m_active
<- n
4310 m_first_time
<- false;
4313 method int name get
set =
4315 (name
, `
int get
, 1, Action
(
4318 try set (int_of_string
s)
4320 state.text <- Printf.sprintf
"bad integer `%s': %s"
4324 let te = name ^
": ", "", None
, intentry, ondone, true in
4325 state.mode
<- Textentry
(te, leave m_prev_mode
);
4329 method int_with_suffix name get
set =
4331 (name
, `intws get
, 1, Action
(
4334 try set (int_of_string_with_suffix s)
4336 state.text <- Printf.sprintf
"bad integer `%s': %s"
4341 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4343 state.mode
<- Textentry
(te, leave m_prev_mode
);
4347 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4349 (name
, `
bool (btos, get
), offset
, Action
(
4356 method color name get
set =
4358 (name
, `color get
, 1, Action
(
4360 let invalid = (nan
, nan
, nan
) in
4363 try color_of_string s
4365 state.text <- Printf.sprintf
"bad color `%s': %s"
4372 let te = name ^
": ", "", None
, textentry, ondone, true in
4373 state.text <- color_to_string (get
());
4374 state.mode
<- Textentry
(te, leave m_prev_mode
);
4378 method string name get
set =
4380 (name
, `
string get
, 1, Action
(
4382 let ondone s = set s in
4383 let te = name ^
": ", "", None
, textentry, ondone, true in
4384 state.mode
<- Textentry
(te, leave m_prev_mode
);
4388 method colorspace name get
set =
4390 (name
, `
string get
, 1, Action
(
4393 let vals = [| "rgb"; "bgr"; "gray" |] in
4395 inherit lvsourcebase
4398 m_active
<- int_of_colorspace conf.colorspace
;
4401 method getitemcount
= Array.length
vals
4402 method getitem
n = (vals.(n), 0)
4403 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4404 ignore
(uioh
, first, pan
, qsearch);
4405 if not cancel
then set active;
4407 method hasaction
_ = true
4411 let modehash = findkeyhash conf "info" in
4412 coe (new listview ~
source ~trusted
:true ~
modehash)
4415 method roammark name get
set =
4417 (name
, `
string get
, 1, Action
(
4420 let vals = [| "page"; "block"; "line"; "word" |] in
4422 inherit lvsourcebase
4425 m_active
<- int_of_mark conf.paxmark
;
4428 method getitemcount
= Array.length
vals
4429 method getitem
n = (vals.(n), 0)
4430 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4431 ignore
(uioh
, first, pan
, qsearch);
4432 if not cancel
then set active;
4434 method hasaction
_ = true
4438 let modehash = findkeyhash conf "info" in
4439 coe (new listview ~
source ~trusted
:true ~
modehash)
4442 method fitmodel name get
set =
4444 (name
, `
string get
, 1, Action
(
4447 let vals = [| "fit width"; "proportional"; "fit page" |] in
4449 inherit lvsourcebase
4452 m_active
<- int_of_fitmodel conf.fitmodel
;
4455 method getitemcount
= Array.length
vals
4456 method getitem
n = (vals.(n), 0)
4457 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4458 ignore
(uioh
, first, pan
, qsearch);
4459 if not cancel
then set active;
4461 method hasaction
_ = true
4465 let modehash = findkeyhash conf "info" in
4466 coe (new listview ~
source ~trusted
:true ~
modehash)
4469 method caption
s offset
=
4470 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4472 method caption2
s f offset
=
4473 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4475 method getitemcount
= Array.length m_a
4478 let tostr = function
4479 | `
int f -> string_of_int
(f ())
4480 | `intws
f -> string_with_suffix_of_int (f ())
4482 | `color
f -> color_to_string (f ())
4483 | `
bool (btos, f) -> btos (f ())
4486 let name, t
, offset
, _ = m_a
.(n) in
4487 ((let s = tostr t
in
4488 if String.length
s > 0
4489 then Printf.sprintf
"%s\t%s" name s
4493 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4497 m_qsearch
<- qsearch;
4499 match m_a
.(active) with
4500 | _, _, _, Action
f -> f uioh
4512 method hasaction
n =
4514 | _, _, _, Action
_ -> true
4518 let rec fillsrc prevmode prevuioh
=
4519 let sep () = src#caption
"" 0 in
4520 let colorp name get
set =
4522 (fun () -> color_to_string (get
()))
4525 let c = color_of_string v in
4528 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4531 let oldmode = state.mode
in
4532 let birdseye = isbirdseye state.mode
in
4534 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4536 src#
bool "presentation mode"
4537 (fun () -> conf.presentation
)
4538 (fun v -> setpresentationmode v);
4540 src#
bool "ignore case in searches"
4541 (fun () -> conf.icase
)
4542 (fun v -> conf.icase
<- v);
4545 (fun () -> conf.preload)
4546 (fun v -> conf.preload <- v);
4548 src#
bool "highlight links"
4549 (fun () -> conf.hlinks
)
4550 (fun v -> conf.hlinks
<- v);
4552 src#
bool "under info"
4553 (fun () -> conf.underinfo
)
4554 (fun v -> conf.underinfo
<- v);
4556 src#
bool "persistent bookmarks"
4557 (fun () -> conf.savebmarks
)
4558 (fun v -> conf.savebmarks
<- v);
4560 src#fitmodel
"fit model"
4561 (fun () -> fitmodel_to_string conf.fitmodel
)
4562 (fun v -> reqlayout conf.angle
(fitmodel_of_int v));
4564 src#
bool "trim margins"
4565 (fun () -> conf.trimmargins
)
4566 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4568 src#
bool "persistent location"
4569 (fun () -> conf.jumpback
)
4570 (fun v -> conf.jumpback
<- v);
4573 src#
int "inter-page space"
4574 (fun () -> conf.interpagespace
)
4576 conf.interpagespace
<- n;
4577 docolumns conf.columns
;
4579 match state.layout with
4584 state.maxy <- calcheight ();
4585 let y = getpagey pageno in
4590 (fun () -> conf.pagebias
)
4591 (fun v -> conf.pagebias
<- v);
4593 src#
int "scroll step"
4594 (fun () -> conf.scrollstep
)
4595 (fun n -> conf.scrollstep
<- n);
4597 src#
int "horizontal scroll step"
4598 (fun () -> conf.hscrollstep
)
4599 (fun v -> conf.hscrollstep
<- v);
4601 src#
int "auto scroll step"
4603 match state.autoscroll
with
4605 | _ -> conf.autoscrollstep
)
4607 if state.autoscroll
<> None
4608 then state.autoscroll
<- Some
n;
4609 conf.autoscrollstep
<- n);
4612 (fun () -> truncate
(conf.zoom *. 100.))
4613 (fun v -> setzoom ((float v) /. 100.));
4616 (fun () -> conf.angle
)
4617 (fun v -> reqlayout v conf.fitmodel
);
4619 src#
int "scroll bar width"
4620 (fun () -> conf.scrollbw
)
4623 reshape state.winw
state.winh
;
4626 src#
int "scroll handle height"
4627 (fun () -> conf.scrollh
)
4628 (fun v -> conf.scrollh
<- v;);
4630 src#
int "thumbnail width"
4631 (fun () -> conf.thumbw
)
4633 conf.thumbw
<- min
4096 v;
4636 leavebirdseye beye
false;
4641 let mode = state.mode in
4642 src#
string "columns"
4644 match conf.columns
with
4646 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4647 | Csplit
(count
, _) -> "-" ^ string_of_int count
4650 let n, a, b = multicolumns_of_string v in
4651 setcolumns mode n a b);
4654 src#caption
"Pixmap cache" 0;
4655 src#int_with_suffix
"size (advisory)"
4656 (fun () -> conf.memlimit
)
4657 (fun v -> conf.memlimit
<- v);
4660 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4661 (string_with_suffix_of_int state.memused
)
4662 (Hashtbl.length
state.tilemap
)) 1;
4665 src#caption
"Layout" 0;
4666 src#caption2
"Dimension"
4668 Printf.sprintf
"%dx%d (virtual %dx%d)"
4669 state.winw
state.winh
4674 src#caption2
"Position" (fun () ->
4675 Printf.sprintf
"%dx%d" state.x state.y
4678 src#caption2
"Position" (fun () -> describe_location ()) 1
4682 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4683 "Save these parameters as global defaults at exit"
4684 (fun () -> conf.bedefault
)
4685 (fun v -> conf.bedefault
<- v)
4689 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4690 src#
bool ~offset
:0 ~
btos "Extended parameters"
4691 (fun () -> !showextended)
4692 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4696 (fun () -> conf.checkers
)
4697 (fun v -> conf.checkers
<- v; setcheckers v);
4698 src#
bool "update cursor"
4699 (fun () -> conf.updatecurs
)
4700 (fun v -> conf.updatecurs
<- v);
4702 (fun () -> conf.verbose
)
4703 (fun v -> conf.verbose
<- v);
4704 src#
bool "invert colors"
4705 (fun () -> conf.invert
)
4706 (fun v -> conf.invert
<- v);
4708 (fun () -> conf.maxhfit
)
4709 (fun v -> conf.maxhfit
<- v);
4710 src#
bool "redirect stderr"
4711 (fun () -> conf.redirectstderr)
4712 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4714 (fun () -> conf.pax
!= None
)
4717 then conf.pax
<- Some
(ref (now (), 0, 0))
4718 else conf.pax
<- None
);
4719 src#
string "uri launcher"
4720 (fun () -> conf.urilauncher
)
4721 (fun v -> conf.urilauncher
<- v);
4722 src#
string "path launcher"
4723 (fun () -> conf.pathlauncher
)
4724 (fun v -> conf.pathlauncher
<- v);
4725 src#
string "tile size"
4726 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4729 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4730 conf.tilew
<- max
64 w;
4731 conf.tileh
<- max
64 h;
4734 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4737 src#
int "texture count"
4738 (fun () -> conf.texcount
)
4741 then conf.texcount
<- v
4742 else showtext '
!'
" Failed to set texture count please retry later"
4744 src#
int "slice height"
4745 (fun () -> conf.sliceheight
)
4747 conf.sliceheight
<- v;
4748 wcmd "sliceh %d" conf.sliceheight
;
4750 src#
int "anti-aliasing level"
4751 (fun () -> conf.aalevel
)
4753 conf.aalevel
<- bound v 0 8;
4754 state.anchor <- getanchor ();
4755 opendoc state.path
state.password
;
4757 src#
string "page scroll scaling factor"
4758 (fun () -> string_of_float
conf.pgscale)
4761 let s = float_of_string
v in
4764 state.text <- Printf.sprintf
4765 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4768 src#
int "ui font size"
4769 (fun () -> fstate.fontsize
)
4770 (fun v -> setfontsize (bound v 5 100));
4771 src#
int "hint font size"
4772 (fun () -> conf.hfsize
)
4773 (fun v -> conf.hfsize
<- bound v 5 100);
4774 colorp "background color"
4775 (fun () -> conf.bgcolor
)
4776 (fun v -> conf.bgcolor
<- v);
4777 src#
bool "crop hack"
4778 (fun () -> conf.crophack
)
4779 (fun v -> conf.crophack
<- v);
4780 src#
string "trim fuzz"
4781 (fun () -> irect_to_string conf.trimfuzz
)
4784 conf.trimfuzz
<- irect_of_string v;
4786 then settrim true conf.trimfuzz
;
4788 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4790 src#
string "throttle"
4792 match conf.maxwait
with
4793 | None
-> "show place holder if page is not ready"
4796 then "wait for page to fully render"
4798 "wait " ^ string_of_float
time
4799 ^
" seconds before showing placeholder"
4803 let f = float_of_string
v in
4805 then conf.maxwait
<- None
4806 else conf.maxwait
<- Some
f
4808 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4810 src#
string "ghyll scroll"
4812 match conf.ghyllscroll
with
4814 | Some nab
-> ghyllscroll_to_string nab
4819 if String.length
v = 0
4821 else Some
(ghyllscroll_of_string v)
4823 conf.ghyllscroll
<- gs
4825 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4827 src#
string "selection command"
4828 (fun () -> conf.selcmd
)
4829 (fun v -> conf.selcmd
<- v);
4830 src#
string "synctex command"
4831 (fun () -> conf.stcmd
)
4832 (fun v -> conf.stcmd
<- v);
4833 src#
string "pax command"
4834 (fun () -> conf.paxcmd
)
4835 (fun v -> conf.paxcmd
<- v);
4836 src#colorspace
"color space"
4837 (fun () -> colorspace_to_string conf.colorspace
)
4839 conf.colorspace
<- colorspace_of_int v;
4843 src#roammark
"pax mark method"
4844 (fun () -> mark_to_string conf.paxmark
)
4845 (fun v -> conf.paxmark
<- mark_of_int v);
4849 (fun () -> conf.usepbo
)
4850 (fun v -> conf.usepbo
<- v);
4851 src#
bool "mouse wheel scrolls pages"
4852 (fun () -> conf.wheelbypage
)
4853 (fun v -> conf.wheelbypage
<- v);
4854 src#
bool "open remote links in a new instance"
4855 (fun () -> conf.riani
)
4856 (fun v -> conf.riani
<- v);
4860 src#caption
"Document" 0;
4861 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4862 src#caption2
"Pages"
4863 (fun () -> string_of_int
state.pagecount
) 1;
4864 src#caption2
"Dimensions"
4865 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4869 src#caption
"Trimmed margins" 0;
4870 src#caption2
"Dimensions"
4871 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4875 src#caption
"OpenGL" 0;
4876 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4877 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4880 src#caption
"Location" 0;
4881 if String.length
state.origin
> 0
4882 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4883 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4885 src#reset prevmode prevuioh
;
4889 let prevmode = state.mode
4890 and prevuioh
= state.uioh in
4891 fillsrc prevmode prevuioh
;
4892 let source = (src :> lvsource
) in
4893 let modehash = findkeyhash conf "info" in
4894 state.uioh <- coe (object (self)
4895 inherit listview ~
source ~trusted
:true ~
modehash as super
4896 val mutable m_prevmemused
= 0
4897 method infochanged
= function
4899 if m_prevmemused
!= state.memused
4901 m_prevmemused
<- state.memused
;
4902 G.postRedisplay "memusedchanged";
4904 | Pdim
-> G.postRedisplay "pdimchanged"
4905 | Docinfo
-> fillsrc prevmode prevuioh
4907 method key key mask
=
4908 if not
(Wsi.withctrl mask
)
4911 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4912 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4913 | _ -> super#
key key mask
4914 else super#
key key mask
4916 G.postRedisplay "info";
4922 inherit lvsourcebase
4923 method getitemcount
= Array.length
state.help
4925 let s, l, _ = state.help
.(n) in
4928 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4932 m_qsearch
<- qsearch;
4933 match state.help
.(active) with
4934 | _, _, Action
f -> Some
(f uioh)
4944 method hasaction
n =
4945 match state.help
.(n) with
4946 | _, _, Action
_ -> true
4953 let modehash = findkeyhash conf "help" in
4954 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4955 G.postRedisplay "help";
4960 let re = Str.regexp
"[\r\n]" in
4962 inherit lvsourcebase
4963 val mutable m_items
= [||]
4965 method getitemcount
= 1 + Array.length m_items
4970 else m_items
.(n-1), 0
4972 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4977 then Buffer.clear
state.errmsgs
;
4978 m_qsearch
<- qsearch;
4985 method hasaction
n =
4989 state.newerrmsgs
<- false;
4990 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4991 m_items
<- Array.of_list
l
4999 let source = (msgsource :> lvsource
) in
5000 let modehash = findkeyhash conf "listview" in
5001 state.uioh <- coe (object
5002 inherit listview ~
source ~trusted
:false ~
modehash as super
5005 then msgsource#reset
;
5008 G.postRedisplay "msgs";
5011 let quickbookmark ?title
() =
5012 match state.layout with
5018 let sec = Unix.gettimeofday
() in
5019 let tm = Unix.localtime
sec in
5020 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5024 (tm.Unix.tm_year
+ 1900)
5027 | Some
title -> title
5029 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
5032 let setautoscrollspeed step goingdown
=
5033 let incr = max
1 ((abs step
) / 2) in
5034 let incr = if goingdown
then incr else -incr in
5035 let astep = step
+ incr in
5036 state.autoscroll
<- Some
astep;
5039 let gotounder = function
5040 | Ulinkgoto
(pageno, top) ->
5044 gotopage1 pageno top;
5050 | Uremote
(filename
, pageno) ->
5052 if String.length filename
> 0
5054 if Filename.is_relative filename
5056 let dir = Filename.dirname
state.path in
5058 if Filename.is_implicit
dir
5059 then Filename.concat
(Sys.getcwd
()) dir
5062 Filename.concat
dir filename
5067 if Sys.file_exists
path
5071 if String.length
path > 0
5075 let command = !selfexec ^
" " ^
path in
5076 try popen command []
5079 "failed to execute `%s': %s\n" command (exntos exn
);
5082 let anchor = getanchor () in
5083 let ranchor = state.path, state.password
, anchor, state.origin
in
5085 state.anchor <- (pageno, 0.0, 0.0);
5086 state.ranchors
<- ranchor :: state.ranchors
;
5089 else showtext '
!'
("Could not find " ^ filename
)
5091 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
5095 match conf.columns
with
5097 | _ -> state.x != 0 || conf.zoom > 1.0
5100 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5102 let existsinrow pageno (columns
, coverA
, coverB
) p =
5103 let last = ((pageno - coverA
) mod columns
) + columns
in
5104 let rec any = function
5107 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5111 then (if l.pageno = last then false else any rest
)
5119 match state.layout with
5121 let pageno = page_of_y state.y in
5122 gotoghyll (getpagey (pageno+1))
5124 match conf.columns
with
5126 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5128 let y = clamp (pgscale state.winh
) in
5131 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5132 gotoghyll (getpagey pageno)
5133 | Cmulti
((c, _, _) as cl, _) ->
5134 if conf.presentation
5135 && (existsinrow l.pageno cl
5136 (fun l -> l.pageh
> l.pagey + l.pagevh))
5138 let y = clamp (pgscale state.winh
) in
5141 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5142 gotoghyll (getpagey pageno)
5144 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5146 let pagey, pageh
= getpageyh l.pageno in
5147 let pagey = pagey + pageh
* l.pagecol
in
5148 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5149 gotoghyll (pagey + pageh
+ ips)
5153 match state.layout with
5155 let pageno = page_of_y state.y in
5156 gotoghyll (getpagey (pageno-1))
5158 match conf.columns
with
5160 if conf.presentation
&& l.pagey != 0
5162 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5164 let pageno = max
0 (l.pageno-1) in
5165 gotoghyll (getpagey pageno)
5166 | Cmulti
((c, _, coverB
) as cl, _) ->
5167 if conf.presentation
&&
5168 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5170 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5173 if l.pageno = state.pagecount
- coverB
5177 let pageno = max
0 (l.pageno-decr) in
5178 gotoghyll (getpagey pageno)
5186 let pageno = max
0 (l.pageno-1) in
5187 let pagey, pageh
= getpageyh pageno in
5190 let pagey, pageh
= getpageyh l.pageno in
5191 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5196 let viewkeyboard key mask
=
5198 let mode = state.mode in
5199 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5202 G.postRedisplay "view:enttext"
5204 let ctrl = Wsi.withctrl mask
in
5206 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5212 | 0xff63 -> (* insert *)
5213 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5215 state.mode <- LinkNav
(Ltgendir
0);
5218 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5220 | 0xff1b | 113 -> (* escape / q *)
5221 begin match state.mstate
with
5223 state.mstate
<- Mnone
;
5224 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5225 G.postRedisplay "kill zoom rect";
5227 begin match state.mode with
5230 G.postRedisplay "esc leave linknav"
5232 match state.ranchors
with
5234 | (path, password
, anchor, origin
) :: rest
->
5235 state.ranchors
<- rest
;
5236 state.anchor <- anchor;
5237 state.origin
<- origin
;
5238 opendoc path password
5242 | 0xff08 -> (* backspace *)
5243 gotoghyll (getnav ~
-1)
5251 G.postRedisplay "dehighlight";
5253 | 47 | 63 -> (* / ? *)
5254 let ondone isforw
s =
5255 cbput state.hists
.pat
s;
5256 state.searchpattern
<- s;
5259 let s = String.create
1 in
5260 s.[0] <- Char.chr
key;
5261 enttext (s, "", Some
(onhist state.hists
.pat
),
5262 textentry, ondone (key = 47), true)
5264 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5265 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5266 setzoom (conf.zoom +. incr)
5268 | 43 | 0xffab -> (* + *)
5271 try int_of_string
s with exc
->
5272 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5278 state.text <- "page bias is now " ^ string_of_int
n;
5281 enttext ("page bias: ", "", None
, intentry, ondone, true)
5283 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5284 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5285 setzoom (max
0.01 (conf.zoom -. decr))
5287 | 45 | 0xffad -> (* - *)
5288 let ondone msg
= state.text <- msg
in
5290 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5291 optentry state.mode, ondone, true
5294 | 48 when ctrl -> (* ctrl-0 *)
5302 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5304 match conf.columns
with
5305 | Csingle
_ | Cmulti
_ -> 1
5306 | Csplit
(n, _) -> n
5308 let h = state.winh
-
5309 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5311 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5312 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5315 | 51 when ctrl -> (* ctrl-3 *)
5317 match conf.fitmodel
with
5318 | FitWidth
-> FitProportional
5319 | FitProportional
-> FitPage
5320 | FitPage
-> FitWidth
5322 state.text <- "fit model: " ^
fitmodel_to_string fm;
5323 reqlayout conf.angle
fm
5325 | 0xffc6 -> (* f9 *)
5328 | 57 when ctrl -> (* ctrl-9 *)
5331 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5332 when not
ctrl -> (* 0..9 *)
5335 try int_of_string
s with exc
->
5336 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5342 cbput state.hists
.pag
(string_of_int
n);
5343 gotopage1 (n + conf.pagebias
- 1) 0;
5346 let pageentry text key =
5347 match Char.unsafe_chr
key with
5348 | '
g'
-> TEdone
text
5349 | _ -> intentry text key
5351 let text = "x" in text.[0] <- Char.chr
key;
5352 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5355 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5356 reshape state.winw
state.winh
;
5359 conf.hlinks
<- not
conf.hlinks
;
5360 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5361 G.postRedisplay "toggle highlightlinks";
5364 state.glinks
<- true;
5365 let mode = state.mode in
5366 state.mode <- Textentry
(
5367 (":", "", None
, linknentry, linkndone gotounder, false),
5369 state.glinks
<- false;
5373 G.postRedisplay "view:linkent(F)"
5376 state.glinks
<- true;
5377 let mode = state.mode in
5378 state.mode <- Textentry
(
5380 ":", "", None
, linknentry, linkndone (fun under ->
5381 selstring (undertext under);
5385 state.glinks
<- false;
5389 G.postRedisplay "view:linkent"
5392 begin match state.autoscroll
with
5394 conf.autoscrollstep
<- step
;
5395 state.autoscroll
<- None
5397 if conf.autoscrollstep
= 0
5398 then state.autoscroll
<- Some
1
5399 else state.autoscroll
<- Some
conf.autoscrollstep
5402 | 112 when ctrl -> (* ctrl-p *)
5406 setpresentationmode (not
conf.presentation
);
5407 showtext ' '
("presentation mode " ^
5408 if conf.presentation
then "on" else "off");
5411 if List.mem
Wsi.Fullscreen
state.winstate
5412 then Wsi.reshape conf.cwinw
conf.cwinh
5413 else Wsi.fullscreen
()
5415 | 112 | 78 -> (* p|N *)
5416 search state.searchpattern
false
5418 | 110 | 0xffc0 -> (* n|F3 *)
5419 search state.searchpattern
true
5422 begin match state.layout with
5425 gotoghyll (getpagey l.pageno)
5431 | 0xff9f | 0xffff -> (* delete *)
5435 showtext ' '
(describe_location ());
5438 begin match state.layout with
5441 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5446 enterbookmarkmode ()
5448 | 104 | 0xffbe -> (* h|F1 *)
5454 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5459 match state.layout with
5461 if String.length
s > 0
5463 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5466 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5470 showtext ' '
"Quick bookmark added";
5473 begin match state.layout with
5475 let rect = getpdimrect
l.pagedimno
in
5479 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5480 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5482 (truncate
(rect.(1) -. rect.(0)),
5483 truncate
(rect.(3) -. rect.(0)))
5485 let w = truncate
((float w)*.conf.zoom)
5486 and h = truncate
((float h)*.conf.zoom) in
5489 state.anchor <- getanchor ();
5490 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5492 G.postRedisplay "z";
5497 | 120 -> state.roam
()
5498 | 60 | 62 -> (* < > *)
5499 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5501 | 91 | 93 -> (* [ ] *)
5503 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5505 G.postRedisplay "brightness";
5507 | 99 when state.mode = View
-> (* [alt]-c *)
5512 let m = (wadjsb state.winw
- state.w) / 2 in
5514 gotoy_and_clear_text state.y
5518 match state.prevcolumns
with
5519 | None
-> (1, 0, 0), 1.0
5520 | Some
(columns
, z
) ->
5523 | Csplit
(c, _) -> -c, 0, 0
5524 | Cmulti
((c, a, b), _) -> c, a, b
5525 | Csingle
_ -> 1, 0, 0
5529 setcolumns View
c a b;
5532 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5533 setzoom state.prevzoom
5535 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5536 begin match state.autoscroll
with
5538 begin match state.mode with
5539 | Birdseye beye
-> upbirdseye 1 beye
5542 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5544 if not
(Wsi.withshift mask
) && conf.presentation
5546 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5550 setautoscrollspeed n false
5553 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5554 begin match state.autoscroll
with
5556 begin match state.mode with
5557 | Birdseye beye
-> downbirdseye 1 beye
5560 then gotoy_and_clear_text (clamp (state.winh
/2))
5562 if not
(Wsi.withshift mask
) && conf.presentation
5564 else gotoy_and_clear_text (clamp conf.scrollstep
)
5568 setautoscrollspeed n true
5571 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5572 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5578 else conf.hscrollstep
5580 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5581 state.x <- panbound (state.x + dx);
5582 gotoy_and_clear_text state.y
5585 G.postRedisplay "left/right"
5588 | 0xff55 | 0xff9a -> (* (kp) prior *)
5592 match state.layout with
5594 | l :: _ -> state.y - l.pagey
5596 clamp (pgscale (-state.winh
))
5600 | 0xff56 | 0xff9b -> (* (kp) next *)
5604 match List.rev
state.layout with
5606 | l :: _ -> getpagey l.pageno
5608 clamp (pgscale state.winh
)
5612 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5614 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5615 gotoghyll (clamp state.maxy)
5618 when Wsi.withalt mask
-> (* alt-(kp) right *)
5619 gotoghyll (getnav 1)
5621 when Wsi.withalt mask
-> (* alt-(kp) left *)
5622 gotoghyll (getnav ~
-1)
5627 | 118 when conf.debug
-> (* v *)
5630 match getopaque l.pageno with
5633 let x0, y0, x1, y1 = pagebbox opaque
in
5634 let a,b = float x0, float y0 in
5635 let c,d = float x1, float y0 in
5636 let e,f = float x1, float y1 in
5637 let h,j
= float x0, float y1 in
5638 let rect = (a,b,c,d,e,f,h,j
) in
5640 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5642 G.postRedisplay "v";
5645 vlog "huh? %s" (Wsi.keyname
key)
5648 let linknavkeyboard key mask
linknav =
5649 let getpage pageno =
5650 let rec loop = function
5652 | l :: _ when l.pageno = pageno -> Some
l
5653 | _ :: rest
-> loop rest
5654 in loop state.layout
5656 let doexact (pageno, n) =
5657 match getopaque pageno, getpage pageno with
5658 | Some opaque
, Some
l ->
5659 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5661 let under = getlink opaque
n in
5662 G.postRedisplay "link gotounder";
5668 | 0xff50 -> (* home *)
5669 Some
(findlink opaque LDfirst
), -1
5671 | 0xff57 -> (* end *)
5672 Some
(findlink opaque LDlast
), 1
5674 | 0xff51 -> (* left *)
5675 Some
(findlink opaque
(LDleft
n)), -1
5677 | 0xff53 -> (* right *)
5678 Some
(findlink opaque
(LDright
n)), 1
5680 | 0xff52 -> (* up *)
5681 Some
(findlink opaque
(LDup
n)), -1
5683 | 0xff54 -> (* down *)
5684 Some
(findlink opaque
(LDdown
n)), 1
5689 begin match findpwl
l.pageno dir with
5693 state.mode <- LinkNav
(Ltgendir
dir);
5694 let y, h = getpageyh pageno in
5697 then y + h - state.winh
5702 begin match getopaque pageno, getpage pageno with
5703 | Some opaque
, Some
_ ->
5705 let ld = if dir > 0 then LDfirst
else LDlast
in
5708 begin match link with
5710 showlinktype (getlink opaque
m);
5711 state.mode <- LinkNav
(Ltexact
(pageno, m));
5712 G.postRedisplay "linknav jpage";
5719 begin match opt with
5720 | Some Lnotfound
-> pwl l dir;
5721 | Some
(Lfound
m) ->
5725 let _, y0, _, y1 = getlinkrect opaque
m in
5727 then gotopage1 l.pageno y0
5729 let d = fstate.fontsize
+ 1 in
5730 if y1 - l.pagey > l.pagevh - d
5731 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5732 else G.postRedisplay "linknav";
5734 showlinktype (getlink opaque
m);
5735 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5738 | None
-> viewkeyboard key mask
5740 | _ -> viewkeyboard key mask
5745 G.postRedisplay "leave linknav"
5749 | Ltgendir
_ -> viewkeyboard key mask
5750 | Ltexact exact
-> doexact exact
5753 let keyboard key mask
=
5754 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5755 then wcmd "interrupt"
5756 else state.uioh <- state.uioh#
key key mask
5759 let birdseyekeyboard key mask
5760 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5762 match conf.columns
with
5764 | Cmulti
((c, _, _), _) -> c
5765 | Csplit
_ -> failwith
"bird's eye split mode"
5767 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5769 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5770 let y, h = getpageyh pageno in
5771 let top = (state.winh
- h) / 2 in
5772 gotoy (max
0 (y - top))
5773 | 0xff0d (* enter *)
5774 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5775 | 0xff1b -> leavebirdseye beye
true (* escape *)
5776 | 0xff52 -> upbirdseye incr beye
(* up *)
5777 | 0xff54 -> downbirdseye incr beye
(* down *)
5778 | 0xff51 -> upbirdseye 1 beye
(* left *)
5779 | 0xff53 -> downbirdseye 1 beye
(* right *)
5781 | 0xff55 -> (* prior *)
5782 begin match state.layout with
5786 state.mode <- Birdseye
(
5787 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5789 gotopage1 l.pageno 0;
5792 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5794 | [] -> gotoy (clamp (-state.winh
))
5796 state.mode <- Birdseye
(
5797 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5799 gotopage1 l.pageno 0
5802 | [] -> gotoy (clamp (-state.winh
))
5805 | 0xff56 -> (* next *)
5806 begin match List.rev
state.layout with
5808 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5809 begin match layout with
5811 let incr = l.pageh
- l.pagevh in
5816 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5818 G.postRedisplay "birdseye pagedown";
5820 else gotoy (clamp (incr + conf.interpagespace
*2));
5824 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5825 gotopage1 l.pageno 0;
5828 | [] -> gotoy (clamp state.winh
)
5831 | 0xff50 -> (* home *)
5832 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5835 | 0xff57 -> (* end *)
5836 let pageno = state.pagecount
- 1 in
5837 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5838 if not
(pagevisible state.layout pageno)
5841 match List.rev
state.pdims
with
5843 | (_, _, h, _) :: _ -> h
5845 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5846 else G.postRedisplay "birdseye end";
5847 | _ -> viewkeyboard key mask
5852 match state.mode with
5853 | Textentry
_ -> scalecolor 0.4
5855 | View
-> scalecolor 1.0
5856 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5857 if l.pageno = hooverpageno
5860 if l.pageno = pageno
5868 let postdrawpage l linkindexbase
=
5869 match getopaque l.pageno with
5871 if tileready l l.pagex
l.pagey
5873 let x = l.pagedispx - l.pagex
5874 and y = l.pagedispy - l.pagey in
5876 match conf.columns
with
5877 | Csingle
_ | Cmulti
_ ->
5878 (if conf.hlinks
then 1 else 0)
5880 && not
(isbirdseye state.mode) then 2 else 0)
5884 match state.mode with
5885 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5888 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5893 let scrollindicator () =
5894 let sbw, ph
, sh = state.uioh#
scrollph in
5895 let sbh, pw, sw = state.uioh#scrollpw
in
5897 GlDraw.color (0.64, 0.64, 0.64);
5899 (float (state.winw
- sbw), 0.)
5900 (float state.winw
, float state.winh
)
5903 (0., float (state.winh
- sbh))
5904 (float (wadjsb state.winw
- 1), float state.winh
)
5906 GlDraw.color (0.0, 0.0, 0.0);
5909 (float (state.winw
- sbw), ph
)
5910 (float state.winw
, ph
+. sh)
5913 (pw, float (state.winh
- sbh))
5914 (pw +. sw, float state.winh
)
5919 match state.mstate
with
5920 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5923 | Msel
((x0, y0), (x1, y1)) ->
5924 let rec loop = function
5926 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5927 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5928 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5929 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5931 match getopaque l.pageno with
5933 let x0, y0 = pagetranslatepoint l x0 y0 in
5934 let x1, y1 = pagetranslatepoint l x1 y1 in
5935 seltext opaque
(x0, y0, x1, y1);
5943 let showrects rects
=
5945 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5946 GlDraw.polygon_mode `both `fill
;
5947 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5949 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5951 if l.pageno = pageno
5953 let dx = float (l.pagedispx - l.pagex
) in
5954 let dy = float (l.pagedispy - l.pagey) in
5955 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
5956 GlDraw.begins `quads
;
5958 GlDraw.vertex2
(x0+.dx, y0+.dy);
5959 GlDraw.vertex2
(x1+.dx, y1+.dy);
5960 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5961 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5972 GlClear.color (scalecolor2 conf.bgcolor
);
5973 GlClear.clear
[`
color];
5974 List.iter
drawpage state.layout;
5976 match state.mode with
5977 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5978 begin match getopaque pageno with
5980 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5987 | None
-> state.rects
5992 let rec postloop linkindexbase
= function
5994 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5995 postloop linkindexbase rest
5999 postloop 0 state.layout;
6001 begin match state.mstate
with
6002 | Mzoomrect
((x0, y0), (x1, y1)) ->
6004 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
6005 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6006 GlDraw.rect (float x0, float y0)
6007 (float x1, float y1);
6016 let zoomrect x y x1 y1 =
6019 and y0 = min
y y1 in
6020 gotoy (state.y + y0);
6021 state.anchor <- getanchor ();
6022 let zoom = (float state.w) /. float (x1 - x0) in
6024 match conf.fitmodel
, conf.columns
with
6025 | FitPage
, Csplit
_ ->
6026 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6029 let adjw = wadjsb state.winw
in
6031 then (adjw - state.w) / 2
6034 state.x <- (state.x + margin) - x0;
6036 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6037 state.mstate
<- Mnone
;
6041 let winw = wadjsb state.winw - 1 in
6042 let s = float x /. float winw in
6043 let destx = truncate
(float (state.w + winw) *. s) in
6044 state.x <- winw - destx;
6045 gotoy_and_clear_text state.y;
6046 state.mstate
<- Mscrollx
;
6050 let s = float y /. float state.winh
in
6051 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6052 gotoy_and_clear_text desty;
6053 state.mstate
<- Mscrolly
;
6056 let viewmouse button down
x y mask
=
6058 | n when (n == 4 || n == 5) && not down
->
6059 if Wsi.withctrl mask
6061 match state.mstate
with
6062 | Mzoom
(oldn
, i
) ->
6070 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6072 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6074 let zoom = conf.zoom -. incr in
6076 state.mstate
<- Mzoom
(n, 0);
6078 state.mstate
<- Mzoom
(n, i
+1);
6080 else state.mstate
<- Mzoom
(n, 0)
6082 | _ -> state.mstate
<- Mzoom
(n, 0)
6085 match state.autoscroll
with
6086 | Some step
-> setautoscrollspeed step
(n=4)
6088 if conf.wheelbypage
|| conf.presentation
6097 then -conf.scrollstep
6098 else conf.scrollstep
6100 let incr = incr * 2 in
6101 let y = clamp incr in
6102 gotoy_and_clear_text y
6105 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6107 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6108 gotoy_and_clear_text state.y
6110 | 1 when Wsi.withshift mask
->
6111 state.mstate
<- Mnone
;
6114 match unproject x y with
6115 | Some
(pageno, ux
, uy
) ->
6116 let cmd = Printf.sprintf
6118 conf.stcmd
state.path pageno ux uy
6124 | 1 when Wsi.withctrl mask
->
6127 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6128 state.mstate
<- Mpan
(x, y)
6131 state.mstate
<- Mnone
6136 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6138 state.mstate
<- Mzoomrect
(p, p)
6141 match state.mstate
with
6142 | Mzoomrect
((x0, y0), _) ->
6143 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6144 then zoomrect x0 y0 x y
6146 state.mstate
<- Mnone
;
6147 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6148 G.postRedisplay "kill accidental zoom rect";
6151 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6152 state.mstate
<- Mnone
6155 | 1 when x > state.winw - vscrollw () ->
6158 let _, position, sh = state.uioh#
scrollph in
6159 if y > truncate
position && y < truncate
(position +. sh)
6160 then state.mstate
<- Mscrolly
6163 state.mstate
<- Mnone
6165 | 1 when y > state.winh
- hscrollh () ->
6168 let _, position, sw = state.uioh#scrollpw
in
6169 if x > truncate
position && x < truncate
(position +. sw)
6170 then state.mstate
<- Mscrollx
6173 state.mstate
<- Mnone
6176 let dest = if down
then getunder x y else Unone
in
6177 begin match dest with
6181 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6184 | Unone
when down
->
6185 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6186 state.mstate
<- Mpan
(x, y);
6188 | Unone
| Utext
_ ->
6191 if conf.angle
mod 360 = 0
6193 state.mstate
<- Msel
((x, y), (x, y));
6194 G.postRedisplay "mouse select";
6198 match state.mstate
with
6201 | Mzoom
_ | Mscrollx
| Mscrolly
->
6202 state.mstate
<- Mnone
6204 | Mzoomrect
((x0, y0), _) ->
6208 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6209 state.mstate
<- Mnone
6211 | Msel
((x0, y0), (x1, y1)) ->
6212 let rec loop = function
6216 let a0 = l.pagedispy in
6217 let a1 = a0 + l.pagevh in
6218 let b0 = l.pagedispx in
6219 let b1 = b0 + l.pagevw in
6220 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6221 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6225 match getopaque l.pageno with
6228 match Ne.pipe () with
6232 "can not create sel pipe: %s"
6235 let doclose what fd
=
6236 Ne.clo fd
(fun msg
->
6237 dolog
"%s close failed: %s" what msg
)
6240 popen conf.selcmd
[r, 0; w, -1];
6241 copysel
w opaque
true;
6243 G.postRedisplay "copysel";
6245 dolog
"can not execute %S: %s"
6246 conf.selcmd
(exntos exn
);
6254 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6255 state.mstate
<- Mnone
;
6262 let birdseyemouse button down
x y mask
6263 (conf, leftx
, _, hooverpageno
, anchor) =
6266 let rec loop = function
6269 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6270 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6272 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6278 | _ -> viewmouse button down
x y mask
6281 let mouse button down
x y mask
=
6282 state.uioh <- state.uioh#button button down
x y mask
;
6286 state.uioh <- state.uioh#
motion x y
6290 state.uioh <- state.uioh#
pmotion x y;
6296 method key key mask
=
6297 begin match state.mode with
6298 | Textentry
textentry -> textentrykeyboard key mask
textentry
6299 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6300 | View
-> viewkeyboard key mask
6301 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6305 method button button bstate
x y mask
=
6306 begin match state.mode with
6308 | View
-> viewmouse button bstate
x y mask
6309 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6315 begin match state.mode with
6317 | View
| Birdseye
_ | LinkNav
_ ->
6318 match state.mstate
with
6319 | Mzoom
_ | Mnone
-> ()
6324 state.mstate
<- Mpan
(x, y);
6326 then state.x <- panbound (state.x + dx);
6328 gotoy_and_clear_text y
6331 state.mstate
<- Msel
(a, (x, y));
6332 G.postRedisplay "motion select";
6335 let y = min
state.winh
(max
0 y) in
6339 let x = min
state.winw (max
0 x) in
6342 | Mzoomrect
(p0
, _) ->
6343 state.mstate
<- Mzoomrect
(p0
, (x, y));
6344 G.postRedisplay "motion zoomrect";
6348 method pmotion x y =
6349 begin match state.mode with
6350 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6351 let rec loop = function
6353 if hooverpageno
!= -1
6355 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6356 G.postRedisplay "pmotion birdseye no hoover";
6359 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6360 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6362 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6363 G.postRedisplay "pmotion birdseye hoover";
6373 match state.mstate
with
6374 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6381 let past, _, _ = !r in
6383 let delta = now -. past in
6386 else r := (now, x, y)
6390 method infochanged
_ = ()
6393 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6396 then 0.0, float state.winh
6397 else scrollph state.y maxy
6402 let winw = wadjsb state.winw in
6403 let fwinw = float winw in
6405 let sw = fwinw /. float state.w in
6406 let sw = fwinw *. sw in
6407 max
sw (float conf.scrollh
)
6410 let maxx = state.w + winw in
6411 let x = winw - state.x in
6412 let percent = float x /. float maxx in
6413 (fwinw -. sw) *. percent
6415 hscrollh (), position, sw
6419 match state.mode with
6420 | LinkNav
_ -> "links"
6421 | Textentry
_ -> "textentry"
6422 | Birdseye
_ -> "birdseye"
6425 findkeyhash conf modename
6427 method eformsgs
= true
6434 let fontpath = ref "";;
6437 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6440 let l = String.length
s in
6441 let b = Buffer.create
l in
6447 try Sys.getenv
"HOME"
6450 ("Can not determine home directory location: " ^ exntos exn
);
6454 let modifier_of_string = function
6455 | "alt" -> Wsi.altmask
6456 | "shift" -> Wsi.shiftmask
6457 | "ctrl" | "control" -> Wsi.ctrlmask
6458 | "meta" -> Wsi.metamask
6463 let r = Str.regexp
"-" in
6465 let elems = Str.full_split
r s in
6468 let m1 = modifier_of_string s in
6470 then (Wsi.namekey
s, m)
6473 | Str.Delim
s when n land 1 = 0 -> g s
6475 | Str.Delim
_ -> (k
, m)
6477 let rec loop n k
m = function
6480 let k, m = f n k m x in
6486 let keys_of_string =
6487 let r = Str.regexp
"[ \t]" in
6489 let elems = Str.split
r s in
6490 List.map
key_of_string elems
6493 let copykeyhashes c =
6494 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6497 let config_of c attrs
=
6501 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6502 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6503 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6504 | "preload" -> { c with preload = bool_of_string
v }
6505 | "page-bias" -> { c with pagebias
= int_of_string
v }
6506 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6507 | "horizontal-scroll-step" ->
6508 { c with hscrollstep
= max
(int_of_string
v) 1 }
6509 | "auto-scroll-step" ->
6510 { c with autoscrollstep
= max
0 (int_of_string
v) }
6511 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6512 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6515 match String.lowercase
v with
6516 | "true" -> Some infinity
6518 | f -> Some
(float_of_string
f)
6520 { c with maxwait
= mw}
6521 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6522 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6523 | "vertical-margin" ->
6524 { c with interpagespace
= max
0 (int_of_string
v) }
6526 let zoom = float_of_string
v /. 100. in
6527 let zoom = max
zoom 0.0 in
6528 { c with zoom = zoom }
6529 | "presentation" -> { c with presentation
= bool_of_string
v }
6530 | "rotation-angle" -> { c with angle
= int_of_string
v }
6531 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6532 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6533 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6534 | "proportional-display" ->
6537 then FitProportional
6540 { c with fitmodel
= fm }
6541 | "fit-model" -> { c with fitmodel
= fitmodel_of_string v }
6542 | "pixmap-cache-size" ->
6543 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6544 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6545 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6546 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6547 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6548 | "background-color" -> { c with bgcolor
= color_of_string v }
6549 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6550 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6551 | "mupdf-store-size" ->
6552 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6553 | "checkers" -> { c with checkers
= bool_of_string
v }
6554 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6555 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6556 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6557 | "uri-launcher" -> { c with urilauncher
= unent v }
6558 | "path-launcher" -> { c with pathlauncher
= unent v }
6559 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6560 | "invert-colors" -> { c with invert
= bool_of_string
v }
6561 | "brightness" -> { c with colorscale
= float_of_string
v }
6562 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6564 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6566 let (n, _, _) as nab
= multicolumns_of_string v in
6568 then { c with columns
= Csplit
(-n, [||]) }
6569 else { c with columns
= Cmulti
(nab
, [||]) }
6570 | "birds-eye-columns" ->
6571 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6572 | "selection-command" -> { c with selcmd
= unent v }
6573 | "synctex-command" -> { c with stcmd
= unent v }
6574 | "pax-command" -> { c with paxcmd
= unent v }
6575 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6576 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6577 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6578 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6579 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6580 | "horizontal-scrollbar-visible" ->
6583 then c.scrollb
lor scrollbhv
6584 else c.scrollb
land (lnot
scrollbhv)
6586 { c with scrollb
= b }
6587 | "vertical-scrollbar-visible" ->
6590 then c.scrollb
lor scrollbvv
6591 else c.scrollb
land (lnot
scrollbvv)
6593 { c with scrollb
= b }
6594 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6598 then Some
(ref (0.0, 0, 0))
6602 prerr_endline
("Error processing attribute (`" ^
6603 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6606 let rec fold c = function
6609 let c = apply c k v in
6612 fold { c with keyhashes
= copykeyhashes c } attrs
;
6615 let fromstring f pos
n v d =
6618 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6619 n v pos
(exntos exn
)
6624 let bookmark_of attrs
=
6625 let rec fold title page
rely visy
= function
6626 | ("title", v) :: rest
-> fold v page
rely visy rest
6627 | ("page", v) :: rest
-> fold title v rely visy rest
6628 | ("rely", v) :: rest
-> fold title page
v visy rest
6629 | ("visy", v) :: rest
-> fold title page
rely v rest
6630 | _ :: rest
-> fold title page
rely visy rest
6631 | [] -> title, page
, rely, visy
6633 fold "invalid" "0" "0" "0" attrs
6637 let rec fold path page
rely pan visy
= function
6638 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6639 | ("page", v) :: rest
-> fold path v rely pan visy rest
6640 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6641 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6642 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6643 | _ :: rest
-> fold path page
rely pan visy rest
6644 | [] -> path, page
, rely, pan
, visy
6646 fold "" "0" "0" "0" "0" attrs
6650 let rec fold rs ls
= function
6651 | ("out", v) :: rest
-> fold v ls rest
6652 | ("in", v) :: rest
-> fold rs
v rest
6653 | _ :: rest
-> fold ls rs rest
6659 let setconf dst
src =
6660 dst
.scrollbw
<- src.scrollbw
;
6661 dst
.scrollh
<- src.scrollh
;
6662 dst
.icase
<- src.icase
;
6663 dst
.preload <- src.preload;
6664 dst
.pagebias
<- src.pagebias
;
6665 dst
.verbose
<- src.verbose
;
6666 dst
.scrollstep
<- src.scrollstep
;
6667 dst
.maxhfit
<- src.maxhfit
;
6668 dst
.crophack
<- src.crophack
;
6669 dst
.autoscrollstep
<- src.autoscrollstep
;
6670 dst
.maxwait
<- src.maxwait
;
6671 dst
.hlinks
<- src.hlinks
;
6672 dst
.underinfo
<- src.underinfo
;
6673 dst
.interpagespace
<- src.interpagespace
;
6674 dst
.zoom <- src.zoom;
6675 dst
.presentation
<- src.presentation
;
6676 dst
.angle
<- src.angle
;
6677 dst
.cwinw
<- src.cwinw
;
6678 dst
.cwinh
<- src.cwinh
;
6679 dst
.savebmarks
<- src.savebmarks
;
6680 dst
.memlimit
<- src.memlimit
;
6681 dst
.fitmodel
<- src.fitmodel
;
6682 dst
.texcount
<- src.texcount
;
6683 dst
.sliceheight
<- src.sliceheight
;
6684 dst
.thumbw
<- src.thumbw
;
6685 dst
.jumpback
<- src.jumpback
;
6686 dst
.bgcolor
<- src.bgcolor
;
6687 dst
.tilew
<- src.tilew
;
6688 dst
.tileh
<- src.tileh
;
6689 dst
.mustoresize
<- src.mustoresize
;
6690 dst
.checkers
<- src.checkers
;
6691 dst
.aalevel
<- src.aalevel
;
6692 dst
.trimmargins
<- src.trimmargins
;
6693 dst
.trimfuzz
<- src.trimfuzz
;
6694 dst
.urilauncher
<- src.urilauncher
;
6695 dst
.colorspace
<- src.colorspace
;
6696 dst
.invert
<- src.invert
;
6697 dst
.colorscale
<- src.colorscale
;
6698 dst
.redirectstderr <- src.redirectstderr;
6699 dst
.ghyllscroll
<- src.ghyllscroll
;
6700 dst
.columns
<- src.columns
;
6701 dst
.beyecolumns
<- src.beyecolumns
;
6702 dst
.selcmd
<- src.selcmd
;
6703 dst
.updatecurs
<- src.updatecurs
;
6704 dst
.pathlauncher
<- src.pathlauncher
;
6705 dst
.keyhashes
<- copykeyhashes src;
6706 dst
.hfsize
<- src.hfsize
;
6707 dst
.hscrollstep
<- src.hscrollstep
;
6708 dst
.pgscale <- src.pgscale;
6709 dst
.usepbo
<- src.usepbo
;
6710 dst
.wheelbypage
<- src.wheelbypage
;
6711 dst
.stcmd
<- src.stcmd
;
6712 dst
.paxcmd
<- src.paxcmd
;
6713 dst
.scrollb
<- src.scrollb
;
6714 dst
.riani
<- src.riani
;
6718 else Some
((ref (0.0, 0, 0)));
6722 let h = Hashtbl.create
10 in
6723 let dc = { defconf with angle
= defconf.angle
} in
6724 let rec toplevel v t spos
_ =
6726 | Vdata
| Vcdata
| Vend
-> v
6727 | Vopen
("llppconfig", _, closed
) ->
6730 else { v with f = llppconfig
}
6732 error
"unexpected subelement at top level" s spos
6733 | Vclose
_ -> error
"unexpected close at top level" s spos
6735 and llppconfig
v t spos
_ =
6737 | Vdata
| Vcdata
-> v
6738 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6739 | Vopen
("defaults", attrs
, closed
) ->
6740 let c = config_of dc attrs
in
6744 else { v with f = defaults
}
6746 | Vopen
("ui-font", attrs
, closed
) ->
6747 let rec getsize size
= function
6749 | ("size", v) :: rest
->
6751 fromstring int_of_string spos
"size" v fstate.fontsize
in
6753 | l -> getsize size l
6755 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6758 else { v with f = uifont
(Buffer.create
10) }
6760 | Vopen
("doc", attrs
, closed
) ->
6761 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6762 let path = unent pathent
6763 and pageno = fromstring int_of_string spos
"page" spage
0
6764 and rely = fromstring float_of_string spos
"rely" srely
0.0
6765 and pan
= fromstring int_of_string spos
"pan" span
0
6766 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6767 let c = config_of dc attrs
in
6768 let anchor = (pageno, rely, visy
) in
6770 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6771 else { v with f = doc
path pan
anchor c [] }
6774 error
"unexpected subelement in llppconfig" s spos
6776 | Vclose
"llppconfig" -> { v with f = toplevel }
6777 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6779 and defaults
v t spos
_ =
6781 | Vdata
| Vcdata
-> v
6782 | Vend
-> error
"unexpected end of input in defaults" s spos
6783 | Vopen
("keymap", attrs
, closed
) ->
6785 try List.assoc
"mode" attrs
6786 with Not_found
-> "global" in
6791 let h = findkeyhash dc modename in
6792 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6795 { v with f = pkeymap
ret KeyMap.empty }
6797 | Vopen
(_, _, _) ->
6798 error
"unexpected subelement in defaults" s spos
6800 | Vclose
"defaults" ->
6801 { v with f = llppconfig
}
6803 | Vclose
_ -> error
"unexpected close in defaults" s spos
6805 and uifont
b v t spos
epos =
6808 Buffer.add_substring
b s spos
(epos - spos
);
6810 | Vopen
(_, _, _) ->
6811 error
"unexpected subelement in ui-font" s spos
6812 | Vclose
"ui-font" ->
6813 if String.length
!fontpath = 0
6814 then fontpath := Buffer.contents
b;
6815 { v with f = llppconfig
}
6816 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6817 | Vend
-> error
"unexpected end of input in ui-font" s spos
6819 and doc
path pan
anchor c bookmarks
v t spos
_ =
6821 | Vdata
| Vcdata
-> v
6822 | Vend
-> error
"unexpected end of input in doc" s spos
6823 | Vopen
("bookmarks", _, closed
) ->
6826 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6828 | Vopen
("keymap", attrs
, closed
) ->
6830 try List.assoc
"mode" attrs
6831 with Not_found
-> "global"
6837 let h = findkeyhash c modename in
6838 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6839 doc
path pan
anchor c bookmarks
6841 { v with f = pkeymap
ret KeyMap.empty }
6843 | Vopen
(_, _, _) ->
6844 error
"unexpected subelement in doc" s spos
6847 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6848 { v with f = llppconfig
}
6850 | Vclose
_ -> error
"unexpected close in doc" s spos
6852 and pkeymap
ret keymap
v t spos
_ =
6854 | Vdata
| Vcdata
-> v
6855 | Vend
-> error
"unexpected end of input in keymap" s spos
6856 | Vopen
("map", attrs
, closed
) ->
6857 let r, l = map_of attrs
in
6858 let kss = fromstring keys_of_string spos
"in" r [] in
6859 let lss = fromstring keys_of_string spos
"out" l [] in
6863 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6864 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6867 then { v with f = pkeymap
ret keymap }
6870 { v with f = skip
"map" f }
6873 error
"unexpected subelement in keymap" s spos
6875 | Vclose
"keymap" ->
6876 { v with f = ret keymap }
6878 | Vclose
_ -> error
"unexpected close in keymap" s spos
6880 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6882 | Vdata
| Vcdata
-> v
6883 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6884 | Vopen
("item", attrs
, closed
) ->
6885 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6886 let page = fromstring int_of_string spos
"page" spage
0
6887 and rely = fromstring float_of_string spos
"rely" srely
0.0
6888 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6890 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6893 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6896 { v with f = skip
"item" f }
6899 error
"unexpected subelement in bookmarks" s spos
6901 | Vclose
"bookmarks" ->
6902 { v with f = doc
path pan
anchor c bookmarks }
6904 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6906 and skip tag
f v t spos
_ =
6908 | Vdata
| Vcdata
-> v
6910 error
("unexpected end of input in skipped " ^ tag
) s spos
6911 | Vopen
(tag'
, _, closed
) ->
6915 let f'
() = { v with f = skip tag
f } in
6916 { v with f = skip tag'
f'
}
6920 else error
("unexpected close in skipped " ^ tag
) s spos
6923 parse
{ f = toplevel; accu = () } s;
6929 let len = in_channel_length ic
in
6930 let s = String.create
len in
6931 really_input ic
s 0 len;
6934 | Parse_error
(msg
, s, pos
) ->
6935 let subs = subs s pos
in
6936 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6937 failwith
("parse error: " ^
s)
6940 failwith
("config load error: " ^ exntos exn
)
6946 let dir = Filename.concat
home ".config" in
6947 if Sys.is_directory
dir then dir else home
6950 Filename.concat
dir "llpp.conf"
6953 let confpath = ref defconfpath;;
6956 if Sys.file_exists
!confpath
6959 (try Some
(open_in_bin
!confpath)
6962 ("Error opening configuration file `" ^
!confpath ^
"': " ^
6973 ("Error loading configuration from `" ^
!confpath ^
"': " ^
6982 f (Hashtbl.create
0, defconf)
6987 let pc, pb
, px, pa
=
6990 if String.length
state.origin
= 0
6994 Hashtbl.find h (Filename.basename
key)
6995 with Not_found
-> dc, [], 0, emptyanchor
6999 state.bookmarks <- pb
;
7002 then state.anchor <- pa
;
7003 cbput state.hists
.nav pa
;
7009 let add_attrs bb always
dc c =
7012 then Printf.bprintf bb
"\n %s='%b'" s a
7015 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7018 then Printf.bprintf bb
"\n %s='%d'" s a
7021 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7024 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7027 then Printf.bprintf bb
"\n %s='%f'" s a
7031 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7035 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
7039 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7043 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7049 | Some
(_N
, _A
, _B
) ->
7050 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7060 else string_of_float
f
7062 Printf.bprintf bb
"\n %s='%s'" s v
7067 | Cmulti
((n, a, b), _) when n > 1 ->
7068 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7069 | Csplit
(n, _) when n > 1 ->
7070 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7076 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7081 Printf.bprintf bb
"\n %s='%s'" s (fitmodel_to_string a)
7085 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7087 oi
"width" c.cwinw
dc.cwinw
;
7088 oi
"height" c.cwinh
dc.cwinh
;
7089 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7090 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7091 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7092 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7093 ob "case-insensitive-search" c.icase
dc.icase
;
7094 ob "preload" c.preload dc.preload;
7095 oi
"page-bias" c.pagebias
dc.pagebias
;
7096 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7097 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7098 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7099 ob "crop-hack" c.crophack
dc.crophack
;
7100 oW
"throttle" c.maxwait
dc.maxwait
;
7101 ob "highlight-links" c.hlinks
dc.hlinks
;
7102 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7103 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7104 oz
"zoom" c.zoom dc.zoom;
7105 ob "presentation" c.presentation
dc.presentation
;
7106 oi
"rotation-angle" c.angle
dc.angle
;
7107 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7108 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7109 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7110 oi
"tex-count" c.texcount
dc.texcount
;
7111 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7112 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7113 ob "persistent-location" c.jumpback
dc.jumpback
;
7114 oc
"background-color" c.bgcolor
dc.bgcolor
;
7115 oi
"tile-width" c.tilew
dc.tilew
;
7116 oi
"tile-height" c.tileh
dc.tileh
;
7117 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7118 ob "checkers" c.checkers
dc.checkers
;
7119 oi
"aalevel" c.aalevel
dc.aalevel
;
7120 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7121 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7122 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7123 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7124 oC
"color-space" c.colorspace
dc.colorspace
;
7125 ob "invert-colors" c.invert
dc.invert
;
7126 oF
"brightness" c.colorscale
dc.colorscale
;
7127 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7128 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7129 oco
"columns" c.columns
dc.columns
;
7130 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7131 os
"selection-command" c.selcmd
dc.selcmd
;
7132 os
"synctex-command" c.stcmd
dc.stcmd
;
7133 os
"pax-command" c.paxcmd
dc.paxcmd
;
7134 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7135 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7136 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7137 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7138 ob "use-pbo" c.usepbo
dc.usepbo
;
7139 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7140 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7141 op
"point-and-x" c.pax
dc.pax
;
7144 let keymapsbuf always
dc c =
7145 let bb = Buffer.create
16 in
7146 let rec loop = function
7148 | (modename, h) :: rest
->
7149 let dh = findkeyhash dc modename in
7150 if always
|| h <> dh
7152 if Hashtbl.length
h > 0
7154 if Buffer.length
bb > 0
7155 then Buffer.add_char
bb '
\n'
;
7156 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7157 Hashtbl.iter
(fun i
o ->
7158 let isdifferent = always
||
7160 let dO = Hashtbl.find dh i
in
7162 with Not_found
-> true
7167 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7168 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7169 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7170 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7171 Buffer.add_string
bb (Wsi.keyname
k);
7174 let rec loop = function
7176 | km
:: [] -> addkm km
7177 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7181 Buffer.add_string
bb "<map in='";
7185 Buffer.add_string
bb "' out='";
7187 Buffer.add_string
bb "'/>\n"
7190 Buffer.add_string
bb "' out='";
7192 Buffer.add_string
bb "'/>\n"
7194 | KMmulti
(ins, kms
) ->
7195 Buffer.add_char
bb ' '
;
7197 Buffer.add_string
bb "' out='";
7199 Buffer.add_string
bb "'/>\n"
7201 Buffer.add_string
bb "</keymap>";
7211 let uifontsize = fstate.fontsize
in
7212 let bb = Buffer.create
32768 in
7213 let relx = float state.x /. float state.winw in
7215 let cx w = truncate
(relx *. float w) in
7217 (fun (w, h, x) ws
->
7219 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7220 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7221 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7223 (state.winw, state.winh
, state.x) state.winstate
7228 let dc = if conf.bedefault
then conf else dc in
7229 Buffer.add_string
bb "<llppconfig>\n";
7231 if String.length
!fontpath > 0
7233 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7239 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7242 Buffer.add_string
bb "<defaults ";
7243 add_attrs bb true dc dc;
7244 let kb = keymapsbuf true dc dc in
7245 if Buffer.length
kb > 0
7247 Buffer.add_string
bb ">\n";
7248 Buffer.add_buffer
bb kb;
7249 Buffer.add_string
bb "\n</defaults>\n";
7251 else Buffer.add_string
bb "/>\n";
7253 let adddoc path pan
anchor c bookmarks =
7254 if bookmarks == [] && c = dc && anchor = emptyanchor
7257 Printf.bprintf
bb "<doc path='%s'"
7258 (enent
path 0 (String.length
path));
7260 if anchor <> emptyanchor
7262 let n, rely, visy
= anchor in
7263 Printf.bprintf
bb " page='%d'" n;
7266 Printf.bprintf
bb " rely='%f'" rely
7268 if abs_float visy
> 1e-6
7270 Printf.bprintf
bb " visy='%f'" visy
7275 then Printf.bprintf
bb " pan='%d'" pan
;
7277 add_attrs bb false dc c;
7278 let kb = keymapsbuf false dc c in
7280 begin match bookmarks with
7282 if Buffer.length
kb > 0
7284 Buffer.add_string
bb ">\n";
7285 Buffer.add_buffer
bb kb;
7286 Buffer.add_string
bb "\n</doc>\n";
7288 else Buffer.add_string
bb "/>\n"
7290 Buffer.add_string
bb ">\n<bookmarks>\n";
7291 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7293 "<item title='%s' page='%d'"
7294 (enent
title 0 (String.length
title))
7299 Printf.bprintf
bb " rely='%f'" rely
7301 if abs_float visy
> 1e-6
7303 Printf.bprintf
bb " visy='%f'" visy
7305 Buffer.add_string
bb "/>\n";
7307 Buffer.add_string
bb "</bookmarks>";
7308 if Buffer.length
kb > 0
7310 Buffer.add_string
bb "\n";
7311 Buffer.add_buffer
bb kb;
7313 Buffer.add_string
bb "\n</doc>\n";
7319 match state.mode with
7320 | Birdseye
(c, pan, _, _, _) ->
7322 match conf.columns
with
7323 | Cmulti
((c, _, _), _) -> Some
c
7327 match c.columns
with
7328 | Cmulti
(c, _) -> Cmulti
(c, [||])
7329 | Csingle
_ -> Csingle
[||]
7330 | Csplit
_ -> failwith
"quit from bird's eye while split"
7332 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7335 let basename = Filename.basename
7336 (if String.length
state.origin
= 0 then state.path else state.origin
)
7338 adddoc basename pan (getanchor ())
7340 let autoscrollstep =
7341 match state.autoscroll
with
7343 | None
-> conf.autoscrollstep
7345 match state.mode with
7346 | Birdseye
(bc
, _, _, _, _) ->
7349 presentation
= bc
.presentation
;
7350 interpagespace
= bc
.interpagespace
;
7351 maxwait
= bc
.maxwait
;
7352 autoscrollstep = autoscrollstep }
7353 | _ -> { conf with autoscrollstep = autoscrollstep }
7355 (if conf.savebmarks
then state.bookmarks else []);
7357 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7359 then adddoc path x anchor c bookmarks
7361 Buffer.add_string
bb "</llppconfig>\n";
7364 if load1 f && Buffer.length
bb > 0
7367 let tmp = !confpath ^
".tmp" in
7368 let oc = open_out_bin
tmp in
7369 Buffer.output_buffer
oc bb;
7371 Unix.rename
tmp !confpath;
7374 ("error while saving configuration: " ^ exntos exn
)
7378 let adderrmsg src msg
=
7379 Buffer.add_string
state.errmsgs msg
;
7380 state.newerrmsgs
<- true;
7384 let adderrfmt src fmt
=
7385 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7389 let cl = splitatspace cmds
in
7391 try Scanf.sscanf
s fmt
f
7393 adderrfmt "remote exec"
7394 "error processing '%S': %s\n" cmds
(exntos exn
)
7397 | "reload" :: [] -> reload ()
7398 | "goto" :: args :: [] ->
7399 scan args "%u %f %f"
7401 let cmd, _ = state.geomcmds
in
7402 if String.length
cmd = 0
7403 then gotopagexy pageno x y
7406 gotopagexy pageno x y;
7409 state.reprf
<- f state.reprf
7411 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7412 | "rect" :: args :: [] ->
7413 scan args "%u %u %f %f %f %f"
7414 (fun pageno color x0 y0 x1 y1 ->
7415 onpagerect pageno (fun w h ->
7416 let _,w1,h1
,_ = getpagedim pageno in
7417 let sw = float w1 /. w
7418 and sh = float h1
/. h in
7422 and y1s
= y1 *. sh in
7423 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7425 state.rects <- (pageno, color, rect) :: state.rects;
7426 G.postRedisplay "rect";
7429 | "activatewin" :: [] -> Wsi.activatewin
()
7430 | "quit" :: [] -> raise Quit
7432 adderrfmt "remote command"
7433 "error processing remote command: %S\n" cmds
;
7437 let scratch = String.create
80 in
7438 let buf = Buffer.create
80 in
7441 try Some
(Unix.read fd
scratch 0 80)
7443 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7444 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7447 match tempfr () with
7453 if Buffer.length
buf > 0
7455 let s = Buffer.contents
buf in
7465 let pos = String.index_from
scratch ppos '
\n'
in
7466 if pos >= n then -1 else pos
7467 with Not_found
-> -1
7471 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7472 let s = Buffer.contents
buf in
7478 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7484 let remoteopen path =
7485 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7487 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7492 let trimcachepath = ref "" in
7493 let rcmdpath = ref "" in
7494 selfexec := Sys.executable_name
;
7497 [("-p", Arg.String
(fun s -> state.password
<- s),
7498 "<password> Set password");
7502 Config.fontpath := s;
7503 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7505 "<path> Set path to the user interface font");
7509 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7510 Config.confpath := s),
7511 "<path> Set path to the configuration file");
7513 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7514 "<path> Set path to the trim cache file");
7516 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7517 "<named-destination> Set named destination");
7519 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7521 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7522 "<path> Set path to the remote commands source");
7524 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7525 "<original-path> Set original path");
7527 ("-v", Arg.Unit
(fun () ->
7529 "%s\nconfiguration path: %s\n"
7533 exit
0), " Print version and exit");
7536 (fun s -> state.path <- s)
7537 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7540 then selfexec := !selfexec ^
" -wtmode";
7542 if String.length
state.path = 0
7543 then (prerr_endline
"file name missing"; exit
1);
7545 if not
(Config.load ())
7546 then prerr_endline
"failed to load configuration";
7548 let wsfd, winw, winh
= Wsi.init
(object
7549 val mutable m_hack
= false
7550 method expose
= if not m_hack
then G.postRedisplay "expose"
7551 method visible
= G.postRedisplay "visible"
7552 method display = m_hack
<- false; display ()
7553 method reshape w h =
7554 m_hack
<- w < state.winw && h < state.winh
;
7556 method mouse b d x y m = mouse b d x y m
7557 method motion x y = state.mpos
<- (x, y); motion x y
7558 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7560 let mascm = m land (
7561 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7563 match state.keystate
with
7565 let km = k, mascm in
7568 let modehash = state.uioh#
modehash in
7569 try Hashtbl.find modehash km
7571 try Hashtbl.find (findkeyhash conf "global") km
7572 with Not_found
-> KMinsrt
(k, m)
7574 | KMinsrt
(k, m) -> keyboard k m
7575 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7576 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7578 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7579 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7580 state.keystate
<- KSnone
7581 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7582 state.keystate
<- KSinto
(keys
, insrt
)
7584 state.keystate
<- KSnone
7586 method enter
x y = state.mpos
<- (x, y); pmotion x y
7587 method leave = state.mpos
<- (-1, -1)
7588 method winstate wsl
= state.winstate
<- wsl
7589 method quit
= raise Quit
7590 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7595 List.exists
GlMisc.check_extension
7596 [ "GL_ARB_texture_rectangle"
7597 ; "GL_EXT_texture_recangle"
7598 ; "GL_NV_texture_rectangle" ]
7600 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7603 let r = GlMisc.get_string `renderer
in
7604 let p = "Mesa DRI Intel(" in
7605 let l = String.length
p in
7606 String.length
r > l && String.sub
r 0 l = p
7608 then defconf.sliceheight
<- 1024;
7611 match Ne.pipe () with
7613 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7617 match Ne.pipe () with
7619 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7629 setcheckers conf.checkers
;
7633 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7634 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7635 !Config.fontpath, !trimcachepath,
7636 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7640 state.text <- "Opening " ^
(mbtoutf8
state.path);
7642 opendoc state.path state.password
;
7646 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7649 if String.length
!rcmdpath > 0
7650 then remoteopen !rcmdpath
7655 let rec loop deadline
=
7657 match state.errfd
with
7658 | None
-> [state.sr
; state.wsfd]
7659 | Some fd
-> [state.sr
; state.wsfd; fd
]
7664 | Some fd
-> fd
:: r
7668 state.redisplay
<- false;
7675 if deadline
= infinity
7677 else max
0.0 (deadline
-. now)
7682 try Unix.select
r [] [] timeout
7683 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7689 if state.ghyll
== noghyll
7691 match state.autoscroll
with
7692 | Some step
when step
!= 0 ->
7693 let y = state.y + step
in
7697 else if y >= state.maxy then 0 else y
7700 if state.mode = View
7701 then state.text <- "";
7704 else deadline
+. 0.01
7709 let rec checkfds = function
7711 | fd
:: rest
when fd
= state.sr
->
7712 let cmd = readcmd state.sr
in
7716 | fd
:: rest
when fd
= state.wsfd ->
7720 | fd
:: rest
when Some fd
= !optrfd ->
7721 begin match remote fd
with
7722 | None
-> optrfd := remoteopen !rcmdpath;
7723 | opt -> optrfd := opt
7728 let s = String.create
80 in
7729 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7730 if conf.redirectstderr
7732 Buffer.add_substring
state.errmsgs
s 0 n;
7733 state.newerrmsgs
<- true;
7734 state.redisplay
<- true;
7737 prerr_string
(String.sub
s 0 n);
7745 if deadline
= infinity
7749 match state.autoscroll
with
7750 | Some step
when step
!= 0 -> deadline1
7751 | _ -> if state.ghyll
== noghyll then infinity
else deadline1