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 module type TextEnumType
=
1077 val names
: string array
1080 module TextEnumMake
(Ten
: TextEnumType
) =
1082 let names = Ten.names;;
1083 let to_int (t
: Ten.t
) = Obj.magic t
;;
1084 let to_string t
= names.(to_int t
);;
1085 let of_int n : Ten.t
= Obj.magic
n;;
1088 if i
= Array.length
names
1089 then failwith
("invalid " ^
Ten.name ^
": " ^
s)
1091 if Ten.names.(i
) = s
1098 module CSTE
= TextEnumMake
(struct
1099 type t
= colorspace
;;
1100 let name = "colorspace";;
1101 let names = [|"rgb"; "bgr"; "gray"|];;
1104 module MTE
= TextEnumMake
(struct
1107 let names = [|"page"; "block"; "line"; "word"|];;
1110 module FMTE
= TextEnumMake
(struct
1112 let name = "fitmodel";;
1113 let names = [|"width"; "proportional"; "page"|];;
1116 let intentry_with_suffix text key
=
1118 if key
>= 32 && key
< 127
1122 match Char.lowercase
c with
1124 let text = addchar text c in
1127 | 'k'
| 'm'
| '
g'
->
1128 let text = addchar text c in
1132 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1136 let multicolumns_to_string (n, a
, b) =
1138 then Printf.sprintf
"%d" n
1139 else Printf.sprintf
"%d,%d,%d" n a
b;
1142 let multicolumns_of_string s =
1144 (int_of_string
s, 0, 0)
1146 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1148 then failwith
"subtly broken"; (n, a
, b)
1154 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1155 if n != 4 then failwith
"incomplete read(len)";
1157 lor (Char.code
s.[0] lsl 24)
1158 lor (Char.code
s.[1] lsl 16)
1159 lor (Char.code
s.[2] lsl 8)
1160 lor (Char.code
s.[3] lsl 0)
1162 let s = String.create
len in
1163 let n = tempfailureretry
(Unix.read fd
s 0) len in
1164 if n != len then failwith
"incomplete read(data)";
1168 let btod b = if b then 1 else 0;;
1171 let b = Buffer.create
16 in
1172 Buffer.add_string
b "llll";
1175 let s = Buffer.contents
b in
1176 let n = String.length
s in
1178 (* dolog "wcmd %S" (String.sub s 4 len); *)
1179 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1180 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1181 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1182 s.[3] <- Char.chr
(len land 0xff);
1183 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1184 if n'
!= n then failwith
"write failed";
1189 let d = state.winh
- h
in
1190 max
conf.interpagespace
((d + 1) / 2)
1193 let rowyh (c, coverA
, coverB
) b n =
1194 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1196 let _, _, vy
, (_, _, h
, _) = b.(n) in
1199 let n'
= n - coverA
in
1202 let e = min
state.pagecount
(s + c) in
1203 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1204 let _, _, y, (_, _, h
, _) = b.(m
) in
1205 let miny = min
miny y in
1206 let maxh = max
maxh h
in
1207 find (m
+1) miny maxh
1212 match conf.columns
with
1213 | Cmulti
((_, _, _) as cl
, b) ->
1214 if Array.length
b > 0
1216 let y, h
= rowyh cl
b (Array.length
b - 1) in
1217 y + h
+ (if conf.presentation
then calcips h
else 0)
1220 if Array.length
b > 0
1222 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1223 y + h
+ (if conf.presentation
then calcips h
else 0)
1226 if Array.length
b > 0
1228 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1233 let getpageyh pageno
=
1234 let pageno = bound pageno 0 (state.pagecount
-1) in
1235 match conf.columns
with
1237 if Array.length
b = 0
1240 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1242 if conf.presentation
1248 if Array.length
b = 0
1251 let y, h
= rowyh cl
b pageno in
1253 if conf.presentation
1259 if Array.length
b = 0
1263 let (_, _, y, (_, _, h
, _)) = b.(n) in
1267 let getpagedim pageno =
1270 | (n, _, _, _) as pdim
:: rest
->
1272 then (if n = pageno then pdim
else ppdim
)
1277 f (-1, -1, -1, -1) state.pdims
1280 let getpagey pageno = fst
(getpageyh pageno);;
1282 let nogeomcmds cmds
=
1284 | s, [] -> String.length
s = 0
1289 let ((c, coverA
, coverB
) as cl
), b =
1290 match conf.columns
with
1291 | Csingle
b -> (1, 0, 0), b
1292 | Cmulti
(c, b) -> c, b
1293 | Csplit
(_, b) -> (1, 0, 0), b
1295 if Array.length
b = 0
1298 let rec bsearch nmin nmax
=
1300 then bound nmin
0 (state.pagecount
-1)
1302 let n = (nmax
+ nmin
) / 2 in
1303 let vy, h
= rowyh cl
b n in
1305 if conf.presentation
1307 let ips = calcips h
in
1308 let y0 = vy - ips in
1309 let y1 = vy + h
+ ips in
1313 then 0, vy + h
+ conf.interpagespace
1315 let y0 = vy - conf.interpagespace
in
1316 y0, y0 + h
+ conf.interpagespace
1319 if y >= y0 && y < y1
1326 if n < state.pagecount
- coverB
1327 then ((n-coverA
)/c)*c + coverA
1334 then bsearch (n+1) nmax
1335 else bsearch nmin
(n-1)
1338 let r = bsearch 0 (state.pagecount
-1) in
1342 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1343 let sh = sh - (hscrollh ()) in
1344 let rec fold accu
n =
1345 if n = Array.length
b
1348 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1351 || n = state.pagecount
- coverB
1352 || (n - coverA
) mod columns
= columns
- 1)
1358 let pagey = max
0 (y - vy) in
1359 let pagedispy = if pagey > 0 then 0 else vy - y in
1360 let pagedispx, pagex
=
1362 if n = coverA
- 1 || n = state.pagecount
- coverB
1363 then state.x + (wadjsb state.winw
- w
) / 2
1364 else dx + xoff
+ state.x
1371 let vw = wadjsb state.winw
- pagedispx in
1372 let pw = w
- pagex
in
1375 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1376 if pagevw > 0 && pagevh > 0
1380 ; pagedimno
= pdimno
1387 ; pagedispx = pagedispx
1388 ; pagedispy = pagedispy
1400 List.rev
(fold [] (page_of_y y));
1403 let layoutS (columns
, b) y sh =
1404 let sh = sh - hscrollh () in
1405 let rec fold accu n =
1406 if n = Array.length
b
1409 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1416 let x = xoff
+ state.x in
1417 let pagey = max
0 (y - vy) in
1418 let pagedispy = if pagey > 0 then 0 else vy - y in
1419 let pagedispx, pagex
=
1433 let pagecolw = pagew
/columns
in
1435 if pagecolw < state.winw
1436 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1440 let vw = wadjsb state.winw
- pagedispx in
1441 let pw = pagew
- pagex
in
1444 let pagevw = min
pagevw pagecolw in
1445 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1446 if pagevw > 0 && pagevh > 0
1449 { pageno = n/columns
1450 ; pagedimno
= pdimno
1457 ; pagedispx = pagedispx
1458 ; pagedispy = pagedispy
1459 ; pagecol
= n mod columns
1470 List.rev
(fold [] 0)
1474 if nogeomcmds state.geomcmds
1476 match conf.columns
with
1477 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1478 | Cmulti
c -> layoutN c y sh
1479 | Csplit
s -> layoutS s y sh
1484 let y = state.y + incr
in
1486 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1491 let tilex = l.pagex
mod conf.tilew
in
1492 let tiley = l.pagey mod conf.tileh
in
1494 let col = l.pagex
/ conf.tilew
in
1495 let row = l.pagey / conf.tileh
in
1497 let rec rowloop row y0 dispy h
=
1501 let dh = conf.tileh
- y0 in
1502 let dh = min h
dh in
1503 let rec colloop col x0 dispx w
=
1507 let dw = conf.tilew
- x0 in
1508 let dw = min w
dw in
1510 f col row dispx dispy
x0 y0 dw dh;
1511 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1514 colloop col tilex l.pagedispx l.pagevw;
1515 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1518 if l.pagevw > 0 && l.pagevh > 0
1519 then rowloop row tiley l.pagedispy l.pagevh;
1522 let gettileopaque l col row =
1524 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1526 try Some
(Hashtbl.find state.tilemap
key)
1527 with Not_found
-> None
1530 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1531 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1532 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1535 let drawtiles l color
=
1537 let f col row x y tilex tiley w h
=
1538 match gettileopaque l col row with
1539 | Some
(opaque
, _, t
) ->
1540 let params = x, y, w
, h
, tilex, tiley in
1544 GlFunc.blend_func `zero `one_minus_src_color
;
1546 drawtile
params opaque
;
1548 then Gl.disable `blend
;
1551 let s = Printf.sprintf
1555 let w = measurestr
fstate.fontsize
s in
1556 GlMisc.push_attrib
[`current
];
1557 GlDraw.color
(0.0, 0.0, 0.0);
1559 (float (x-2), float (y-2))
1560 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1561 GlDraw.color
(1.0, 1.0, 1.0);
1562 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1563 GlMisc.pop_attrib
();
1568 let lw = wadjsb state.winw
- x in
1571 let lh = state.winh
- y in
1574 begin match state.texid
with
1576 Gl.enable `texture_2d
;
1577 GlTex.bind_texture `texture_2d id
;
1580 and x1 = float (x+w)
1581 and y1 = float (y+h
) in
1583 let tw = float w /. 16.0
1584 and th
= float h
/. 16.0 in
1585 let tx0 = float tilex /. 16.0
1586 and ty0
= float tiley /. 16.0 in
1588 and ty1
= ty0
+. th
in
1589 GlDraw.begins `quads
;
1590 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1591 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1592 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1593 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1596 Gl.disable `texture_2d
;
1598 GlDraw.color
(1.0, 1.0, 1.0);
1601 (float (x+w), float (y+h
));
1603 if w > 128 && h
> fstate.fontsize
+ 10
1605 GlDraw.color
(0.0, 0.0, 0.0);
1608 then (col*conf.tilew
, row*conf.tileh
)
1611 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r;
1618 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1620 let tilevisible1 l x y =
1622 and ax1
= l.pagex
+ l.pagevw
1624 and ay1
= l.pagey + l.pagevh in
1628 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1629 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1631 let rx0 = max
ax0 bx0
1632 and ry0
= max ay0 by0
1633 and rx1
= min ax1
bx1
1634 and ry1
= min ay1 by1
in
1636 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1637 nonemptyintersection
1640 let tilevisible layout n x y =
1641 let rec findpageinlayout m
= function
1642 | l :: rest
when l.pageno = n ->
1643 tilevisible1 l x y || (
1644 match conf.columns
with
1645 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1648 | _ :: rest
-> findpageinlayout 0 rest
1651 findpageinlayout 0 layout;
1654 let tileready l x y =
1655 tilevisible1 l x y &&
1656 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1659 let tilepage n p
layout =
1660 let rec loop = function
1664 let f col row _ _ _ _ _ _ =
1665 if state.currently
= Idle
1667 match gettileopaque l col row with
1670 let x = col*conf.tilew
1671 and y = row*conf.tileh
in
1673 let w = l.pagew
- x in
1677 let h = l.pageh
- y in
1682 then getpbo
w h conf.colorspace
1685 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1688 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1689 conf.tilew
, conf.tileh
1698 if nogeomcmds state.geomcmds
1702 let preloadlayout y =
1703 let y = if y < state.winh
then 0 else y - state.winh
in
1704 let h = state.winh
*3 in
1709 let rec loop pages
=
1710 if state.currently
!= Idle
1715 begin match getopaque l.pageno with
1717 wcmd "page %d %d" l.pageno l.pagedimno
;
1718 state.currently
<- Loading
(l, state.gen
);
1720 tilepage l.pageno opaque pages
;
1725 if nogeomcmds state.geomcmds
1731 if conf.preload && state.currently
= Idle
1732 then load (preloadlayout state.y);
1735 let layoutready layout =
1736 let rec fold all ls
=
1737 all
&& match ls
with
1739 let seen = ref false in
1740 let allvisible = ref true in
1741 let foo col row _ _ _ _ _ _ =
1743 allvisible := !allvisible &&
1744 begin match gettileopaque l col row with
1750 fold (!seen && !allvisible) rest
1753 let alltilesvisible = fold true layout in
1758 let y = bound y 0 state.maxy
in
1759 let y, layout, proceed
=
1760 match conf.maxwait
with
1761 | Some time
when state.ghyll
== noghyll ->
1762 begin match state.throttle
with
1764 let layout = layout y state.winh
in
1765 let ready = layoutready layout in
1769 state.throttle
<- Some
(layout, y, now ());
1771 else G.postRedisplay "gotoy showall (None)";
1773 | Some
(_, _, started
) ->
1774 let dt = now () -. started
in
1777 state.throttle
<- None
;
1778 let layout = layout y state.winh
in
1780 G.postRedisplay "maxwait";
1787 let layout = layout y state.winh
in
1788 if not
!wtmode || layoutready layout
1789 then G.postRedisplay "gotoy ready";
1795 state.layout <- layout;
1796 begin match state.mode
with
1797 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1798 let rec loop = function
1800 state.mode
<- LinkNav
(Ltgendir
0)
1801 | l :: _ when l.pageno = pageno ->
1802 begin match getopaque pageno with
1804 state.mode
<- LinkNav
(Ltgendir
0)
1806 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1807 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1808 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1809 then state.mode
<- LinkNav
(Ltgendir
0)
1811 | _ :: rest
-> loop rest
1816 begin match state.mode
with
1817 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1818 if not
(pagevisible layout pageno)
1820 match state.layout with
1823 state.mode
<- Birdseye
(
1824 conf, leftx
, l.pageno, hooverpageno
, anchor
1827 | LinkNav
(Ltgendir dir
as lt
) ->
1829 let rec loop = function
1832 match getopaque l.pageno with
1838 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1840 if dir
> 0 then LDfirst
else LDlast
1846 | Lnotfound
-> loop rest
1848 showlinktype (getlink opaque
n);
1849 Ltexact
(l.pageno, n)
1853 state.mode
<- LinkNav
linknav
1858 state.ghyll
<- noghyll;
1861 let mx, my
= state.mpos
in
1866 let conttiling pageno opaque
=
1867 tilepage pageno opaque
1868 (if conf.preload then preloadlayout state.y else state.layout)
1871 let gotoy_and_clear_text y =
1872 if not
conf.verbose
then state.text <- "";
1878 let coloff = l.pagecol
* l.pageh
in
1879 float (l.pagey + coloff) /. float l.pageh
1886 if conf.presentation
1887 then float l.pagedispy /. float (calcips l.pageh
)
1888 else float l.pagedispy /. float conf.interpagespace
1891 (l.pageno, top, dtop)
1895 match state.layout with
1896 | l :: _ -> getanchor1 l
1898 let n = page_of_y state.y in
1902 let y, h = getpageyh n in
1903 let dy = y - state.y in
1905 if conf.presentation
1907 let ips = calcips h in
1908 float (dy + ips) /. float ips
1910 float dy /. float conf.interpagespace
1915 let getanchory (n, top, dtop) =
1916 let y, h = getpageyh n in
1917 if conf.presentation
1919 let ips = calcips h in
1920 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1922 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1925 let gotoanchor anchor
=
1926 gotoy (getanchory anchor
);
1930 cbput state.hists
.nav
(getanchor ());
1934 let anchor = cbgetc state.hists
.nav dir
in
1939 let scroll f n a
b =
1940 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1942 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1944 then s (float f /. float a
)
1947 then 1.0 -. s ((float (f-b) /. float (n-b)))
1953 (* courtesy: (calc-eval "integ(3x^2-2x^3,x)") *)
1954 let iv x = x**3.-.0.5*.x**4. in
1956 let ins = float a
*. iv1
1957 and outs
= float (n-b) *. iv1 in
1959 ins +. outs
+. float ones
1961 let rec set (_N
, _A
, _B
) y sy
=
1962 let sum = summa
1.0 _N _A _B
in
1963 let dy = float (y - sy
) in
1967 then state.ghyll
<- noghyll
1970 let s = scroll n _N _A _B
in
1971 let y1 = y1 +. ((s *. dy) /. sum) in
1972 gotoy_and_clear_text (truncate
y1);
1973 state.ghyll
<- gf (n+1) y1;
1977 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1979 gf 0 (float state.y)
1982 match conf.ghyllscroll
with
1984 gotoy_and_clear_text y
1986 if state.ghyll
== noghyll
1987 then set nab
y state.y
1988 else state.ghyll
(Some
y)
1991 let gotopage n top =
1992 let y, h = getpageyh n in
1993 let y = y + (truncate
(top *. float h)) in
1997 let gotopage1 n top =
1998 let y = getpagey n in
2003 let invalidate s f =
2008 match state.geomcmds
with
2009 | ps
, [] when String.length ps
= 0 ->
2011 state.geomcmds
<- s, [];
2014 state.geomcmds
<- ps
, [s, f];
2016 | ps
, (s'
, _) :: rest
when s'
= s ->
2017 state.geomcmds
<- ps
, ((s, f) :: rest
);
2020 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2024 Hashtbl.iter
(fun _ opaque
->
2025 wcmd "freepage %s" opaque
;
2027 Hashtbl.clear
state.pagemap
;
2031 if not
(Queue.is_empty
state.tilelru
)
2033 Queue.iter
(fun (k
, p
, s) ->
2034 wcmd "freetile %s" p
;
2035 state.memused
<- state.memused
- s;
2036 Hashtbl.remove
state.tilemap k
;
2038 state.uioh#infochanged Memused
;
2039 Queue.clear
state.tilelru
;
2045 let h = truncate
(float h*.conf.zoom
) in
2046 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2050 let opendoc path password
=
2052 state.password
<- password
;
2053 state.gen
<- state.gen
+ 1;
2054 state.docinfo
<- [];
2057 setaalevel
conf.aalevel
;
2059 if String.length
state.origin
= 0
2063 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2064 wcmd "open %d %s\000%s\000" (btod !wtmode) path password
;
2065 invalidate "reqlayout"
2067 wcmd "reqlayout %d %d %d %s\000"
2068 conf.angle
(FMTE.to_int conf.fitmodel
)
2069 (stateh state.winh
) state.nameddest
2074 state.anchor <- getanchor ();
2075 opendoc state.path
state.password
;
2079 let c = c *. conf.colorscale
in
2083 let scalecolor2 (r, g, b) =
2084 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2087 let docolumns = function
2089 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2090 let rec loop pageno pdimno pdim
y ph pdims
=
2091 if pageno = state.pagecount
2094 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2096 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2097 pdimno+1, pdim
, rest
2101 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2103 (if conf.presentation
2104 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2105 else (if pageno = 0 then 0 else conf.interpagespace
)
2108 a.(pageno) <- (pdimno, x, y, pdim
);
2109 loop (pageno+1) pdimno pdim
(y + h) h pdims
2111 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2112 conf.columns
<- Csingle
a;
2114 | Cmulti
((columns
, coverA
, coverB
), _) ->
2115 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2116 let rec loop pageno pdimno pdim
x y rowh pdims
=
2117 let rec fixrow m
= if m
= pageno then () else
2118 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2121 let y = y + (rowh
- h) / 2 in
2122 a.(m
) <- (pdimno, x, y, pdim
);
2126 if pageno = state.pagecount
2127 then fixrow (((pageno - 1) / columns
) * columns
)
2129 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2131 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2132 pdimno+1, pdim
, rest
2137 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2139 let x = (wadjsb state.winw
- w) / 2 in
2141 if conf.presentation
then calcips h else conf.interpagespace
in
2142 x, y + ips + rowh
, h
2145 if (pageno - coverA
) mod columns
= 0
2147 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2149 if conf.presentation
2151 let ips = calcips h in
2152 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2154 y + (if pageno = 0 then 0 else conf.interpagespace
)
2158 else x, y, max rowh
h
2162 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2165 if pageno = columns
&& conf.presentation
2167 let ips = calcips rowh
in
2168 for i
= 0 to pred columns
2170 let (pdimno, x, y, pdim
) = a.(i
) in
2171 a.(i
) <- (pdimno, x, y+ips, pdim
)
2177 fixrow (pageno - columns
);
2182 a.(pageno) <- (pdimno, x, y, pdim
);
2183 let x = x + w + xoff
*2 + conf.interpagespace
in
2184 loop (pageno+1) pdimno pdim
x y rowh' pdims
2186 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2187 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2190 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2191 let rec loop pageno pdimno pdim
y pdims
=
2192 if pageno = state.pagecount
2195 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2197 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2198 pdimno+1, pdim
, rest
2203 let rec loop1 n x y =
2204 if n = c then y else (
2205 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2206 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2209 let y = loop1 0 0 y in
2210 loop (pageno+1) pdimno pdim
y pdims
2212 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2213 conf.columns
<- Csplit
(c, a);
2217 docolumns conf.columns
;
2218 state.maxy
<- calcheight ();
2219 if state.reprf
== noreprf
2221 match state.mode
with
2222 | Birdseye
(_, _, pageno, _, _) ->
2223 let y, h = getpageyh pageno in
2224 let top = (state.winh
- h) / 2 in
2225 gotoy (max
0 (y - top))
2226 | _ -> gotoanchor state.anchor
2230 state.reprf
<- noreprf;
2235 GlDraw.viewport
0 0 w h;
2236 let firsttime = state.geomcmds
== firstgeomcmds in
2237 if not
firsttime && nogeomcmds state.geomcmds
2238 then state.anchor <- getanchor ();
2241 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2244 setfontsize fstate.fontsize
;
2245 GlMat.mode `modelview
;
2246 GlMat.load_identity
();
2248 GlMat.mode `projection
;
2249 GlMat.load_identity
();
2250 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2251 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2252 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2257 else float state.x /. float state.w
2259 invalidate "geometry"
2263 then state.x <- truncate
(relx *. float w);
2265 match conf.columns
with
2267 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2268 | Csplit
(c, _) -> w * c
2270 wcmd "geometry %d %d %d"
2271 w (stateh h) (FMTE.to_int conf.fitmodel
)
2276 let len = String.length
state.text in
2279 match state.mode
with
2280 | Textentry
_ | View
| LinkNav
_ ->
2281 let h, _, _ = state.uioh#scrollpw
in
2287 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2288 (x+.w, float (state.winh
- hscrollh))
2291 let w = float (wadjsb state.winw
- 1) in
2292 if state.progress
>= 0.0 && state.progress
< 1.0
2294 GlDraw.color
(0.3, 0.3, 0.3);
2295 let w1 = w *. state.progress
in
2297 GlDraw.color
(0.0, 0.0, 0.0);
2301 GlDraw.color
(0.0, 0.0, 0.0);
2305 GlDraw.color
(1.0, 1.0, 1.0);
2306 drawstring fstate.fontsize
2307 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2310 match state.mode
with
2311 | Textentry
((prefix
, text, _, _, _, _), _) ->
2315 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2317 Printf.sprintf
"%s%s_" prefix
text
2326 if not
(istextentry state.mode
) && state.uioh#eformsgs
2328 let s1 = "(press 'e' to review error messasges)" in
2329 if String.length
s > 0 then s ^
" " ^
s1 else s1
2334 if String.length
s > 0
2339 let len = Queue.length
state.tilelru
in
2341 match state.throttle
with
2344 then preloadlayout state.y
2346 | Some
(layout, _, _) ->
2350 if state.memused
<= conf.memlimit
2355 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2356 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2357 let (_, pw, ph
, _) = getpagedim n in
2360 && colorspace
= conf.colorspace
2361 && angle
= conf.angle
2365 let x = col*conf.tilew
2366 and y = row*conf.tileh
in
2367 tilevisible (Lazy.force_val
layout) n x y
2369 then Queue.push lruitem
state.tilelru
2372 wcmd "freetile %s" p
;
2373 state.memused
<- state.memused
- s;
2374 state.uioh#infochanged Memused
;
2375 Hashtbl.remove
state.tilemap k
;
2383 let logcurrently = function
2384 | Idle
-> dolog
"Idle"
2385 | Loading
(l, gen
) ->
2386 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2387 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2389 "Tiling %d[%d,%d] page=%s cs=%s angle"
2390 l.pageno col row pageopaque
2391 (CSTE.to_string colorspace
)
2393 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2394 angle gen
conf.angle
state.gen
2396 conf.tilew
conf.tileh
2403 let r = Str.regexp
" " in
2404 fun s -> Str.bounded_split
r s 2;
2407 let onpagerect pageno f =
2409 match conf.columns
with
2410 | Cmulti
(_, b) -> b
2412 | Csplit
(_, b) -> b
2414 if pageno >= 0 && pageno < Array.length
b
2416 let (pdimno, _, _, (_, _, _, _)) = b.(pageno) in
2417 let r = getpdimrect
pdimno in
2418 f (r.(1)-.r.(0)) (r.(3)-.r.(2))
2421 let gotopagexy1 pageno x y =
2422 onpagerect pageno (fun w h ->
2424 let _,w1,_,leftx
= getpagedim pageno in
2425 let wh = state.winh
- hscrollh () in
2426 let sw = float w1 /. w in
2428 let x = leftx
+ state.x + truncate
x in
2430 if x < 0 || x >= wadjsb state.winw
2434 let py, h = getpageyh pageno in
2435 let pdy = truncate
(top *. float h) in
2436 let y'
= py + pdy in
2437 let dy = y'
- state.y in
2439 if x != state.x || not
(dy > 0 && dy < wh)
2441 if conf.presentation
2443 if abs
(py - y'
) > wh
2450 if state.x != sx || state.y != sy
2455 let ww = wadjsb state.winw
in
2457 and qy
= pdy / wh in
2459 and y = py + qy
* wh in
2460 let x = if -x + ww > w1 then -(w1-ww) else x
2461 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2463 if conf.presentation
2465 if abs
(py - y'
) > wh
2475 gotoy_and_clear_text y;
2477 else gotoy_and_clear_text state.y;
2481 let gotopagexy pageno x y =
2482 match state.mode
with
2483 | Birdseye
_ -> gotopage pageno 0.0
2484 | _ -> gotopagexy1 pageno x y
2488 (* dolog "%S" cmds; *)
2489 let cl = splitatspace cmds
in
2491 try Scanf.sscanf
s fmt
f
2493 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2498 state.uioh#infochanged Pdim
;
2501 | "clearrects" :: [] ->
2502 state.rects
<- state.rects1
;
2503 G.postRedisplay "clearrects";
2505 | "continue" :: args :: [] ->
2506 let n = scan args "%u" (fun n -> n) in
2507 state.pagecount
<- n;
2508 begin match state.currently
with
2510 state.currently
<- Idle
;
2511 state.outlines
<- Array.of_list
(List.rev
l)
2515 let cur, cmds
= state.geomcmds
in
2516 if String.length
cur = 0
2517 then failwith
"umpossible";
2519 begin match List.rev cmds
with
2521 state.geomcmds
<- "", [];
2525 state.geomcmds
<- s, List.rev rest
;
2527 if conf.maxwait
= None
&& not
!wtmode
2528 then G.postRedisplay "continue";
2530 | "title" :: args :: [] ->
2533 | "msg" :: args :: [] ->
2536 | "vmsg" :: args :: [] ->
2538 then showtext ' '
args
2540 | "emsg" :: args :: [] ->
2541 Buffer.add_string
state.errmsgs
args;
2542 state.newerrmsgs
<- true;
2543 G.postRedisplay "error message"
2545 | "progress" :: args :: [] ->
2546 let progress, text =
2549 f, String.sub
args pos
(String.length
args - pos
))
2552 state.progress <- progress;
2553 G.postRedisplay "progress"
2555 | "firstmatch" :: args :: [] ->
2556 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2557 scan args "%u %d %f %f %f %f %f %f %f %f"
2558 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2559 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2561 let y = (getpagey pageno) + truncate
y0 in
2564 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2566 | "match" :: args :: [] ->
2567 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2568 scan args "%u %d %f %f %f %f %f %f %f %f"
2569 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2570 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2573 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2575 | "page" :: args :: [] ->
2576 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2577 begin match state.currently
with
2578 | Loading
(l, gen
) ->
2579 vlog "page %d took %f sec" l.pageno t
;
2580 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2581 begin match state.throttle
with
2583 let preloadedpages =
2585 then preloadlayout state.y
2590 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2591 IntSet.empty
preloadedpages
2594 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2595 if not
(IntSet.mem
pageno set)
2597 wcmd "freepage %s" opaque
;
2603 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2606 state.currently
<- Idle
;
2609 tilepage l.pageno pageopaque state.layout;
2611 load preloadedpages;
2612 if pagevisible state.layout l.pageno
2613 && layoutready state.layout
2614 then G.postRedisplay "page";
2617 | Some
(layout, _, _) ->
2618 state.currently
<- Idle
;
2619 tilepage l.pageno pageopaque layout;
2624 dolog
"Inconsistent loading state";
2625 logcurrently state.currently
;
2629 | "tile" :: args :: [] ->
2630 let (x, y, opaque
, size
, t
) =
2631 scan args "%u %u %s %u %f"
2632 (fun x y p size t
-> (x, y, p
, size
, t
))
2634 begin match state.currently
with
2635 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2636 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2639 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2641 wcmd "freetile %s" opaque
;
2642 state.currently
<- Idle
;
2646 puttileopaque l col row gen cs angle opaque size t
;
2647 state.memused
<- state.memused
+ size
;
2648 state.uioh#infochanged Memused
;
2650 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2651 opaque
, size
) state.tilelru
;
2654 match state.throttle
with
2655 | None
-> state.layout
2656 | Some
(layout, _, _) -> layout
2659 state.currently
<- Idle
;
2661 && conf.colorspace
= cs
2662 && conf.angle
= angle
2663 && tilevisible layout l.pageno x y
2664 then conttiling l.pageno pageopaque;
2666 begin match state.throttle
with
2668 preload state.layout;
2670 && conf.colorspace
= cs
2671 && conf.angle
= angle
2672 && tilevisible state.layout l.pageno x y
2673 && (not
!wtmode || layoutready state.layout)
2674 then G.postRedisplay "tile nothrottle";
2676 | Some
(layout, y, _) ->
2677 let ready = layoutready layout in
2681 state.layout <- layout;
2682 state.throttle
<- None
;
2683 G.postRedisplay "throttle";
2690 dolog
"Inconsistent tiling state";
2691 logcurrently state.currently
;
2695 | "pdim" :: args :: [] ->
2696 let (n, w, h, _) as pdim
=
2697 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2700 match conf.fitmodel
, conf.columns
with
2701 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2704 state.uioh#infochanged Pdim
;
2705 state.pdims
<- pdim :: state.pdims
2707 | "o" :: args :: [] ->
2708 let (l, n, t
, h, pos
) =
2709 scan args "%u %u %d %u %n"
2710 (fun l n t
h pos
-> l, n, t
, h, pos
)
2712 let s = String.sub
args pos
(String.length
args - pos
) in
2713 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2714 begin match state.currently
with
2715 | Outlining outlines
->
2716 state.currently
<- Outlining
(outline :: outlines
)
2718 state.currently
<- Outlining
[outline]
2720 dolog
"invalid outlining state";
2721 logcurrently currently
2724 | "a" :: args :: [] ->
2726 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2728 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2730 | "info" :: args :: [] ->
2731 state.docinfo
<- (1, args) :: state.docinfo
2733 | "infoend" :: [] ->
2734 state.uioh#infochanged Docinfo
;
2735 state.docinfo
<- List.rev
state.docinfo
2738 failwith
(Printf.sprintf
"unknown cmd `%S'" cmds
)
2743 let action = function
2744 | HCprev
-> cbget cb ~
-1
2745 | HCnext
-> cbget cb
1
2746 | HCfirst
-> cbget cb ~
-(cb
.rc)
2747 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2748 and cancel
() = cb
.rc <- rc
2752 let search pattern forward
=
2753 match conf.columns
with
2755 showtext '
!'
"searching does not work properly in split columns mode"
2757 if String.length pattern
> 0
2760 match state.layout with
2763 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2765 wcmd "search %d %d %d %d,%s\000"
2766 (btod conf.icase
) pn py (btod forward
) pattern
;
2769 let intentry text key =
2771 if key >= 32 && key < 127
2777 let text = addchar text c in
2781 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2785 let linknentry text key =
2787 if key >= 32 && key < 127
2793 let text = addchar text c in
2797 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2802 if String.length
s > 0
2805 let l = String.length
s in
2806 let rec loop pos
n = if pos
= l then n else
2807 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2808 loop (pos
+1) (n*26 + m)
2811 let rec loop n = function
2814 match getopaque l.pageno with
2815 | None
-> loop n rest
2817 let m = getlinkcount opaque
in
2820 let under = getlink opaque
n in
2823 else loop (n-m) rest
2825 loop n state.layout;
2829 let textentry text key =
2830 if key land 0xff00 = 0xff00
2832 else TEcont
(text ^ toutf8
key)
2835 let reqlayout angle fitmodel
=
2836 match state.throttle
with
2838 if nogeomcmds state.geomcmds
2839 then state.anchor <- getanchor ();
2840 conf.angle
<- angle
mod 360;
2843 match state.mode
with
2844 | LinkNav
_ -> state.mode
<- View
2847 conf.fitmodel
<- fitmodel
;
2848 invalidate "reqlayout"
2850 wcmd "reqlayout %d %d %d"
2851 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2856 let settrim trimmargins trimfuzz
=
2857 if nogeomcmds state.geomcmds
2858 then state.anchor <- getanchor ();
2859 conf.trimmargins
<- trimmargins
;
2860 conf.trimfuzz
<- trimfuzz
;
2861 let x0, y0, x1, y1 = trimfuzz
in
2862 invalidate "settrim"
2864 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2869 match state.throttle
with
2871 let zoom = max
0.0001 zoom in
2872 if zoom <> conf.zoom
2874 state.prevzoom
<- conf.zoom;
2876 reshape state.winw
state.winh
;
2877 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2880 | Some
(layout, y, started
) ->
2882 match conf.maxwait
with
2886 let dt = now () -. started
in
2894 let setcolumns mode columns coverA coverB
=
2895 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2899 then showtext '
!'
"split mode doesn't work in bird's eye"
2901 conf.columns
<- Csplit
(-columns
, [||]);
2909 conf.columns
<- Csingle
[||];
2914 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2918 reshape state.winw
state.winh
;
2921 let enterbirdseye () =
2922 let zoom = float conf.thumbw
/. float state.winw
in
2923 let birdseyepageno =
2924 let cy = state.winh
/ 2 in
2928 let rec fold best
= function
2931 let d = cy - (l.pagedispy + l.pagevh/2)
2932 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2933 if abs
d < abs dbest
2940 state.mode
<- Birdseye
(
2941 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2944 conf.presentation
<- false;
2945 conf.interpagespace
<- 10;
2946 conf.hlinks
<- false;
2947 conf.fitmodel
<- FitProportional
;
2949 state.mstate
<- Mnone
;
2950 conf.maxwait
<- None
;
2952 match conf.beyecolumns
with
2955 Cmulti
((c, 0, 0), [||])
2956 | None
-> Csingle
[||]
2958 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2961 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2966 reshape state.winw
state.winh
;
2969 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2971 conf.zoom <- c.zoom;
2972 conf.presentation
<- c.presentation
;
2973 conf.interpagespace
<- c.interpagespace
;
2974 conf.maxwait
<- c.maxwait
;
2975 conf.hlinks
<- c.hlinks
;
2976 conf.fitmodel
<- c.fitmodel
;
2977 conf.beyecolumns
<- (
2978 match conf.columns
with
2979 | Cmulti
((c, _, _), _) -> Some
c
2981 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2984 match c.columns
with
2985 | Cmulti
(c, _) -> Cmulti
(c, [||])
2986 | Csingle
_ -> Csingle
[||]
2987 | Csplit
(c, _) -> Csplit
(c, [||])
2992 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2995 reshape state.winw
state.winh
;
2996 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2999 let togglebirdseye () =
3000 match state.mode
with
3001 | Birdseye vals
-> leavebirdseye vals
true
3002 | View
-> enterbirdseye ()
3006 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3007 let pageno = max
0 (pageno - incr
) in
3008 let rec loop = function
3009 | [] -> gotopage1 pageno 0
3010 | l :: _ when l.pageno = pageno ->
3011 if l.pagedispy >= 0 && l.pagey = 0
3012 then G.postRedisplay "upbirdseye"
3013 else gotopage1 pageno 0
3014 | _ :: rest
-> loop rest
3017 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3020 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3021 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3022 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3023 let rec loop = function
3025 let y, h = getpageyh pageno in
3026 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3028 | l :: _ when l.pageno = pageno ->
3029 if l.pagevh != l.pageh
3030 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3031 else G.postRedisplay "downbirdseye"
3032 | _ :: rest
-> loop rest
3037 let optentry mode
_ key =
3038 let btos b = if b then "on" else "off" in
3039 if key >= 32 && key < 127
3041 let c = Char.chr
key in
3045 try conf.scrollstep
<- int_of_string
s with exc
->
3046 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3048 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3053 conf.autoscrollstep
<- int_of_string
s;
3054 if state.autoscroll
<> None
3055 then state.autoscroll
<- Some
conf.autoscrollstep
3057 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3059 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3064 let n, a, b = multicolumns_of_string s in
3065 setcolumns mode
n a b;
3067 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3069 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3074 let zoom = float (int_of_string
s) /. 100.0 in
3077 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3079 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3084 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3086 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3087 begin match mode
with
3089 leavebirdseye beye
false;
3094 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3096 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3101 Some
(int_of_string
s)
3103 state.text <- Printf.sprintf
"bad integer `%s': %s"
3107 | Some angle
-> reqlayout angle
conf.fitmodel
3110 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3113 conf.icase
<- not
conf.icase
;
3114 TEdone
("case insensitive search " ^
(btos conf.icase
))
3117 conf.preload <- not
conf.preload;
3119 TEdone
("preload " ^
(btos conf.preload))
3122 conf.verbose
<- not
conf.verbose
;
3123 TEdone
("verbose " ^
(btos conf.verbose
))
3126 conf.debug
<- not
conf.debug
;
3127 TEdone
("debug " ^
(btos conf.debug
))
3130 conf.maxhfit
<- not
conf.maxhfit
;
3131 state.maxy
<- calcheight ();
3132 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3135 conf.crophack
<- not
conf.crophack
;
3136 TEdone
("crophack " ^
btos conf.crophack
)
3140 match conf.maxwait
with
3142 conf.maxwait
<- Some infinity
;
3143 "always wait for page to complete"
3145 conf.maxwait
<- None
;
3146 "show placeholder if page is not ready"
3151 conf.underinfo
<- not
conf.underinfo
;
3152 TEdone
("underinfo " ^
btos conf.underinfo
)
3155 conf.savebmarks
<- not
conf.savebmarks
;
3156 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3162 match state.layout with
3167 conf.interpagespace
<- int_of_string
s;
3168 docolumns conf.columns
;
3169 state.maxy
<- calcheight ();
3170 let y = getpagey pageno in
3173 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3175 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3179 match conf.fitmodel
with
3180 | FitProportional
-> FitWidth
3181 | _ -> FitProportional
3183 reqlayout conf.angle
fm;
3184 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3187 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3188 TEdone
("trim margins " ^
btos conf.trimmargins
)
3191 conf.invert
<- not
conf.invert
;
3192 TEdone
("invert colors " ^
btos conf.invert
)
3196 cbput state.hists
.sel
s;
3199 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3200 textentry, ondone, true)
3204 then conf.pax
<- Some
(ref (0.0, 0, 0))
3205 else conf.pax
<- None
;
3206 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3209 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3215 class type lvsource
= object
3216 method getitemcount
: int
3217 method getitem
: int -> (string * int)
3218 method hasaction
: int -> bool
3227 method getactive
: int
3228 method getfirst
: int
3229 method getqsearch
: string
3230 method setqsearch
: string -> unit
3234 class virtual lvsourcebase
= object
3235 val mutable m_active
= 0
3236 val mutable m_first
= 0
3237 val mutable m_qsearch
= ""
3238 val mutable m_pan
= 0
3239 method getactive
= m_active
3240 method getfirst
= m_first
3241 method getqsearch
= m_qsearch
3242 method getpan
= m_pan
3243 method setqsearch
s = m_qsearch
<- s
3246 let withoutlastutf8 s =
3247 let len = String.length
s in
3255 let b = Char.code
s.[pos
] in
3256 if b land 0b11000000 = 0b11000000
3261 if Char.code
s.[len-1] land 0x80 = 0
3265 String.sub
s 0 first;
3268 let textentrykeyboard
3269 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3271 if key >= 0xffb0 && key <= 0xffb9
3272 then key - 0xffb0 + 48 else key
3275 state.mode
<- Textentry
(te
, onleave
);
3278 G.postRedisplay "textentrykeyboard enttext";
3280 let histaction cmd
=
3283 | Some
(action, _) ->
3284 state.mode
<- Textentry
(
3285 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3287 G.postRedisplay "textentry histaction"
3290 | 0xff08 -> (* backspace *)
3291 let s = withoutlastutf8 text in
3292 let len = String.length
s in
3293 if cancelonempty
&& len = 0
3296 G.postRedisplay "textentrykeyboard after cancel";
3299 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3302 | 0xff0d | 0xff8d -> (* (kp) enter *)
3305 G.postRedisplay "textentrykeyboard after confirm"
3307 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3308 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3309 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3310 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3312 | 0xff1b -> (* escape*)
3313 if String.length
text = 0
3315 begin match opthist
with
3317 | Some
(_, onhistcancel
) -> onhistcancel
()
3321 G.postRedisplay "textentrykeyboard after cancel2"
3324 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3327 | 0xff9f | 0xffff -> () (* delete *)
3330 && key land 0xff00 != 0xff00 (* keyboard *)
3331 && key land 0xfe00 != 0xfe00 (* xkb *)
3332 && key land 0xfd00 != 0xfd00 (* 3270 *)
3334 begin match onkey
text key with
3338 G.postRedisplay "textentrykeyboard after confirm2";
3341 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3345 G.postRedisplay "textentrykeyboard after cancel3"
3348 state.mode
<- Textentry
(te
, onleave
);
3349 G.postRedisplay "textentrykeyboard switch";
3353 vlog "unhandled key %s" (Wsi.keyname
key)
3356 let firstof first active
=
3357 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3358 then max
0 (active
- (fstate.maxrows
/2))
3362 let calcfirst first active
=
3365 let rows = active
- first in
3366 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3370 let scrollph y maxy
=
3371 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3372 let sh = float state.winh
/. sh in
3373 let sh = max
sh (float conf.scrollh
) in
3375 let percent = float y /. float maxy
in
3376 let position = (float state.winh
-. sh) *. percent in
3379 if position +. sh > float state.winh
3380 then float state.winh
-. sh
3386 let coe s = (s :> uioh
);;
3388 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3390 val m_pan
= source#getpan
3391 val m_first
= source#getfirst
3392 val m_active
= source#getactive
3393 val m_qsearch
= source#getqsearch
3394 val m_prev_uioh
= state.uioh
3396 method private elemunder
y =
3397 let n = y / (fstate.fontsize
+1) in
3398 if m_first
+ n < source#getitemcount
3400 if source#hasaction
(m_first
+ n)
3401 then Some
(m_first
+ n)
3408 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3409 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3410 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3411 GlDraw.color
(1., 1., 1.);
3412 Gl.enable `texture_2d
;
3413 let fs = fstate.fontsize
in
3415 let ww = fstate.wwidth
in
3416 let tabw = 30.0*.ww in
3417 let itemcount = source#getitemcount
in
3419 if (row - m_first
) > fstate.maxrows
3422 if row >= 0 && row < itemcount
3424 let (s, level
) = source#getitem
row in
3425 let y = (row - m_first
) * nfs in
3426 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3429 Gl.disable `texture_2d
;
3430 GlDraw.polygon_mode `both `line
;
3431 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3432 GlDraw.color
(1., 1., 1.) ~
alpha;
3433 GlDraw.rect (1., float (y + 1))
3434 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3435 GlDraw.polygon_mode `both `fill
;
3436 GlDraw.color
(1., 1., 1.);
3437 Gl.enable `texture_2d
;
3440 let drawtabularstring s =
3441 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3444 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3447 let len = String.length
s - tabpos - 1 in
3448 let s1 = String.sub
s 0 tabpos
3449 and s2
= String.sub
s (tabpos + 1) len in
3450 let nx = drawstr x s1 in
3452 let x = x +. (max
tabw sw) in
3459 let _ = drawtabularstring s in
3466 Gl.disable `texture_2d
;
3468 method updownlevel incr
=
3469 let len = source#getitemcount
in
3471 if m_active
>= 0 && m_active
< len
3472 then snd
(source#getitem m_active
)
3476 if i
= len then i
-1 else if i
= -1 then 0 else
3477 let _, l = source#getitem i
in
3478 if l != curlevel then i
else flow (i
+incr
)
3480 let active = flow m_active
in
3481 let first = calcfirst m_first
active in
3482 G.postRedisplay "outline updownlevel";
3483 {< m_active
= active; m_first
= first >}
3485 method private key1
key mask
=
3486 let set1 active first qsearch
=
3487 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3489 let search active pattern incr
=
3490 let active = if active = -1 then m_first
else active in
3493 if n >= 0 && n < source#getitemcount
3495 let s, _ = source#getitem
n in
3497 (try ignore
(Str.search_forward
re s 0); true
3498 with Not_found
-> false)
3500 else loop (n + incr
)
3507 let re = Str.regexp_case_fold pattern
in
3513 let itemcount = source#getitemcount
in
3514 let find start incr
=
3516 if i
= -1 || i
= itemcount
3519 if source#hasaction i
3521 else find (i
+ incr
)
3526 let set active first =
3527 let first = bound first 0 (itemcount - fstate.maxrows
) in
3529 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3532 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3534 let incr1 = if incr
> 0 then 1 else -1 in
3535 if isvisible m_first m_active
3538 let next = m_active
+ incr
in
3540 if next < 0 || next >= itemcount
3542 else find next incr1
3544 if abs
(m_active
- next) > fstate.maxrows
3550 let first = m_first
+ incr
in
3551 let first = bound first 0 (itemcount - fstate.maxrows
) in
3553 let next = m_active
+ incr
in
3554 let next = bound next 0 (itemcount - 1) in
3561 if isvisible first next
3568 let first = min
next m_first
in
3570 if abs
(next - first) > fstate.maxrows
3576 let first = m_first
+ incr
in
3577 let first = bound first 0 (itemcount - 1) in
3579 let next = m_active
+ incr
in
3580 let next = bound next 0 (itemcount - 1) in
3581 let next = find next incr1 in
3583 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3585 let active = if m_active
= -1 then next else m_active
in
3590 if isvisible first active
3596 G.postRedisplay "listview navigate";
3600 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3601 let incr = if key = 0x72 then -1 else 1 in
3603 match search (m_active
+ incr) m_qsearch
incr with
3605 state.text <- m_qsearch ^
" [not found]";
3608 state.text <- m_qsearch
;
3609 active, firstof m_first
active
3611 G.postRedisplay "listview ctrl-r/s";
3612 set1 active first m_qsearch
;
3614 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3615 if m_active
>= 0 && m_active
< source#getitemcount
3617 let s, _ = source#getitem m_active
in
3622 | 0xff08 -> (* backspace *)
3623 if String.length m_qsearch
= 0
3626 let qsearch = withoutlastutf8 m_qsearch
in
3627 let len = String.length
qsearch in
3631 G.postRedisplay "listview empty qsearch";
3632 set1 m_active m_first
"";
3636 match search m_active
qsearch ~
-1 with
3638 state.text <- qsearch ^
" [not found]";
3641 state.text <- qsearch;
3642 active, firstof m_first
active
3644 G.postRedisplay "listview backspace qsearch";
3645 set1 active first qsearch
3648 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3649 let pattern = m_qsearch ^ toutf8
key in
3651 match search m_active
pattern 1 with
3653 state.text <- pattern ^
" [not found]";
3656 state.text <- pattern;
3657 active, firstof m_first
active
3659 G.postRedisplay "listview qsearch add";
3660 set1 active first pattern;
3662 | 0xff1b -> (* escape *)
3664 if String.length m_qsearch
= 0
3666 G.postRedisplay "list view escape";
3669 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3671 | None
-> m_prev_uioh
3676 G.postRedisplay "list view kill qsearch";
3677 source#setqsearch
"";
3678 coe {< m_qsearch
= "" >}
3681 | 0xff0d | 0xff8d -> (* (kp) enter *)
3683 let self = {< m_qsearch
= "" >} in
3684 source#setqsearch
"";
3686 G.postRedisplay "listview enter";
3687 if m_active
>= 0 && m_active
< source#getitemcount
3689 source#exit
(coe self) false m_active m_first m_pan
"";
3692 source#exit
(coe self) true m_active m_first m_pan
"";
3695 begin match opt with
3696 | None
-> m_prev_uioh
3700 | 0xff9f | 0xffff -> (* (kp) delete *)
3703 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3704 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3705 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3706 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3708 | 0xff53 | 0xff98 -> (* (kp) right *)
3710 G.postRedisplay "listview right";
3711 coe {< m_pan
= m_pan
- 1 >}
3713 | 0xff51 | 0xff96 -> (* (kp) left *)
3715 G.postRedisplay "listview left";
3716 coe {< m_pan
= m_pan
+ 1 >}
3718 | 0xff50 | 0xff95 -> (* (kp) home *)
3719 let active = find 0 1 in
3720 G.postRedisplay "listview home";
3723 | 0xff57 | 0xff9c -> (* (kp) end *)
3724 let first = max
0 (itemcount - fstate.maxrows
) in
3725 let active = find (itemcount - 1) ~
-1 in
3726 G.postRedisplay "listview end";
3729 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3733 dolog
"listview unknown key %#x" key; coe self
3735 method key key mask
=
3736 match state.mode
with
3737 | Textentry te
-> textentrykeyboard key mask te
; coe self
3738 | _ -> self#key1
key mask
3740 method button button down
x y _ =
3743 | 1 when x > state.winw
- conf.scrollbw
->
3744 G.postRedisplay "listview scroll";
3747 let _, position, sh = self#
scrollph in
3748 if y > truncate
position && y < truncate
(position +. sh)
3750 state.mstate
<- Mscrolly
;
3754 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3755 let first = truncate
(s *. float source#getitemcount
) in
3756 let first = min source#getitemcount
first in
3757 Some
(coe {< m_first
= first; m_active
= first >})
3759 state.mstate
<- Mnone
;
3762 | 1 when not down
->
3763 begin match self#elemunder
y with
3765 G.postRedisplay "listview click";
3767 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3771 | n when (n == 4 || n == 5) && not down
->
3772 let len = source#getitemcount
in
3774 if n = 5 && m_first
+ fstate.maxrows
>= len
3778 let first = m_first
+ (if n == 4 then -1 else 1) in
3779 bound first 0 (len - 1)
3781 G.postRedisplay "listview wheel";
3782 Some
(coe {< m_first
= first >})
3783 | n when (n = 6 || n = 7) && not down
->
3784 let inc = m_first
+ (if n = 7 then -1 else 1) in
3785 G.postRedisplay "listview hwheel";
3786 Some
(coe {< m_pan
= m_pan
+ inc >})
3791 | None
-> m_prev_uioh
3795 match state.mstate
with
3797 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3798 let first = truncate
(s *. float source#getitemcount
) in
3799 let first = min source#getitemcount
first in
3800 G.postRedisplay "listview motion";
3801 coe {< m_first
= first; m_active
= first >}
3804 method pmotion
x y =
3805 if x < state.winw
- conf.scrollbw
3808 match self#elemunder
y with
3809 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3810 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3814 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3819 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3823 method infochanged
_ = ()
3825 method scrollpw
= (0, 0.0, 0.0)
3827 let nfs = fstate.fontsize
+ 1 in
3828 let y = m_first
* nfs in
3829 let itemcount = source#getitemcount
in
3830 let maxi = max
0 (itemcount - fstate.maxrows
) in
3831 let maxy = maxi * nfs in
3832 let p, h = scrollph y maxy in
3835 method modehash
= modehash
3836 method eformsgs
= false
3839 class outlinelistview ~source
=
3842 ~source
:(source
:> lvsource
)
3844 ~modehash
:(findkeyhash conf "outline")
3847 method key key mask
=
3848 let calcfirst first active =
3851 let rows = active - first in
3853 if String.length
state.text = 0
3855 else fstate.maxrows - 2
3857 if rows > maxrows then active - maxrows else first
3861 let active = m_active
+ incr in
3862 let active = bound active 0 (source#getitemcount
- 1) in
3863 let first = calcfirst m_first
active in
3864 G.postRedisplay "outline navigate";
3865 coe {< m_active
= active; m_first
= first >}
3867 let ctrl = Wsi.withctrl mask
in
3869 | 110 when ctrl -> (* ctrl-n *)
3870 source#narrow m_qsearch
;
3871 G.postRedisplay "outline ctrl-n";
3872 coe {< m_first
= 0; m_active
= 0 >}
3874 | 117 when ctrl -> (* ctrl-u *)
3876 G.postRedisplay "outline ctrl-u";
3878 coe {< m_first
= 0; m_active
= 0 >}
3880 | 108 when ctrl -> (* ctrl-l *)
3881 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3882 G.postRedisplay "outline ctrl-l";
3883 coe {< m_first
= first >}
3885 | 0xff9f | 0xffff -> (* (kp) delete *)
3886 source#remove m_active
;
3887 G.postRedisplay "outline delete";
3888 let active = max
0 (m_active
-1) in
3889 coe {< m_first
= firstof m_first
active;
3890 m_active
= active >}
3892 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3893 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3894 | 0xff55 | 0xff9a -> (* (kp) prior *)
3895 navigate ~
-(fstate.maxrows)
3896 | 0xff56 | 0xff9b -> (* (kp) next *)
3897 navigate fstate.maxrows
3899 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3903 G.postRedisplay "outline ctrl right";
3904 {< m_pan
= m_pan
+ 1 >}
3906 else self#updownlevel
1
3910 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3914 G.postRedisplay "outline ctrl left";
3915 {< m_pan
= m_pan
- 1 >}
3917 else self#updownlevel ~
-1
3921 | 0xff50 | 0xff95 -> (* (kp) home *)
3922 G.postRedisplay "outline home";
3923 coe {< m_first
= 0; m_active
= 0 >}
3925 | 0xff57 | 0xff9c -> (* (kp) end *)
3926 let active = source#getitemcount
- 1 in
3927 let first = max
0 (active - fstate.maxrows) in
3928 G.postRedisplay "outline end";
3929 coe {< m_active
= active; m_first
= first >}
3931 | _ -> super#
key key mask
3934 let outlinesource usebookmarks
=
3937 inherit lvsourcebase
3938 val mutable m_items
= empty
3939 val mutable m_orig_items
= empty
3940 val mutable m_prev_items
= empty
3941 val mutable m_narrow_pattern
= ""
3942 val mutable m_hadremovals
= false
3944 method getitemcount
=
3945 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3948 if n == Array.length m_items
&& m_hadremovals
3950 ("[Confirm removal]", 0)
3952 let s, n, _ = m_items
.(n) in
3955 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3956 ignore
(uioh
, first, qsearch);
3957 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3959 if String.length m_narrow_pattern
= 0
3965 if not
confrimremoval
3967 let _, _, anchor = m_items
.(active) in
3968 gotoghyll (getanchory anchor);
3972 state.bookmarks
<- Array.to_list m_items
;
3973 m_orig_items
<- m_items
;
3976 else m_items
<- items;
3980 method hasaction
_ = true
3983 if Array.length m_items
!= Array.length m_orig_items
3984 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3987 method narrow
pattern =
3988 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3992 let rec loop accu n =
3995 m_narrow_pattern
<- pattern;
3996 m_items
<- Array.of_list
accu
3999 let (s, _, _) as o = m_items
.(n) in
4001 if (try ignore
(Str.search_forward
re s 0); true
4002 with Not_found
-> false)
4008 loop [] (Array.length m_items
- 1)
4013 then Array.of_list
state.bookmarks
4016 m_items
<- m_orig_items
4021 if m >= 0 && m < Array.length m_items
4023 m_hadremovals
<- true;
4024 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4025 let n = if n >= m then n+1 else n in
4030 method reset
anchor items =
4031 m_hadremovals
<- false;
4032 if m_orig_items
== empty || m_prev_items
!= items
4034 m_orig_items
<- items;
4035 if String.length m_narrow_pattern
= 0
4036 then m_items
<- items;
4038 m_prev_items
<- items;
4039 let rely = getanchory anchor in
4041 let rec loop n best bestd
=
4042 if n = Array.length m_items
4045 let (_, _, anchor) = m_items
.(n) in
4046 let orely = getanchory anchor in
4047 let d = abs
(orely - rely) in
4050 else loop (n+1) best bestd
4055 m_first
<- firstof m_first
active
4059 let enterselector usebookmarks
=
4060 let source = outlinesource usebookmarks
in
4064 then Array.of_list
state.bookmarks
4067 if Array.length
outlines = 0
4069 showtext ' ' errmsg
;
4072 state.text <- source#greetmsg
;
4073 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4074 let anchor = getanchor () in
4075 source#reset
anchor outlines;
4076 state.uioh
<- coe (new outlinelistview ~
source);
4077 G.postRedisplay "enter selector";
4081 let enteroutlinemode =
4082 let f = enterselector false in
4083 fun ()-> f "Document has no outline";
4086 let enterbookmarkmode =
4087 let f = enterselector true in
4088 fun () -> f "Document has no bookmarks (yet)";
4091 let color_of_string s =
4092 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4093 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4097 let color_to_string (r, g, b) =
4098 let r = truncate
(r *. 256.0)
4099 and g = truncate
(g *. 256.0)
4100 and b = truncate
(b *. 256.0) in
4101 Printf.sprintf
"%d/%d/%d" r g b
4104 let irect_of_string s =
4105 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4108 let irect_to_string (x0,y0,x1,y1) =
4109 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4112 let makecheckers () =
4113 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4115 converted by Issac Trotts. July 25, 2002 *)
4116 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4117 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4118 let id = GlTex.gen_texture
() in
4119 GlTex.bind_texture `texture_2d
id;
4120 GlPix.store
(`unpack_alignment
1);
4121 GlTex.image2d
image;
4122 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4123 [ `mag_filter `nearest
; `min_filter `nearest
];
4127 let setcheckers enabled
=
4128 match state.texid
with
4130 if enabled
then state.texid
<- Some
(makecheckers ())
4135 GlTex.delete_texture texid
;
4136 state.texid
<- None
;
4140 let int_of_string_with_suffix s =
4141 let l = String.length
s in
4145 let suffix = Char.lowercase
s.[l-1] in
4147 | 'k'
-> String.sub
s 0 (l-1), 10
4148 | '
m'
-> String.sub
s 0 (l-1), 20
4149 | '
g'
-> String.sub
s 0 (l-1), 30
4153 let n = int_of_string
s1 in
4154 let m = n lsl shift
in
4156 then raise
(Failure
"value too large")
4160 let string_with_suffix_of_int n =
4165 if n land ((1 lsl 30) - 1) = 0
4168 if n land ((1 lsl 20) - 1) = 0
4171 if n land ((1 lsl 10) - 1) = 0
4178 let h = n mod 1000 in
4181 then string_of_int
h ^
s
4183 let s = Printf.sprintf
"_%03d%s" h s in
4190 let defghyllscroll = (40, 8, 32);;
4191 let ghyllscroll_of_string s =
4192 let (n, a, b) as nab
=
4195 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4197 if n <= a || n <= b || a >= b
4198 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4202 let ghyllscroll_to_string ((n, a, b) as nab
) =
4203 if nab
= defghyllscroll
4205 else Printf.sprintf
"%d,%d,%d" n a b;
4208 let describe_location () =
4209 let fn = page_of_y state.y in
4210 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4211 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4215 else (100. *. (float state.y /. float maxy))
4219 Printf.sprintf
"page %d of %d [%.2f%%]"
4220 (fn+1) state.pagecount
percent
4223 "pages %d-%d of %d [%.2f%%]"
4224 (fn+1) (ln+1) state.pagecount
percent
4227 let setpresentationmode v
=
4228 let n = page_of_y state.y in
4229 state.anchor <- (n, 0.0, 1.0);
4230 conf.presentation
<- v
;
4231 if conf.fitmodel
= FitPage
4232 then reqlayout conf.angle
conf.fitmodel
;
4237 let btos b = if b then "\xe2\x88\x9a" else "" in
4238 let showextended = ref false in
4239 let leave mode
= function
4240 | Confirm
-> state.mode
<- mode
4241 | Cancel
-> state.mode
<- mode
in
4244 val mutable m_first_time
= true
4245 val mutable m_l
= []
4246 val mutable m_a
= [||]
4247 val mutable m_prev_uioh
= nouioh
4248 val mutable m_prev_mode
= View
4250 inherit lvsourcebase
4252 method reset prev_mode prev_uioh
=
4253 m_a
<- Array.of_list
(List.rev m_l
);
4255 m_prev_mode
<- prev_mode
;
4256 m_prev_uioh
<- prev_uioh
;
4260 if n >= Array.length m_a
4264 | _, _, _, Action
_ -> m_active
<- n
4268 m_first_time
<- false;
4271 method int name get
set =
4273 (name, `
int get
, 1, Action
(
4276 try set (int_of_string
s)
4278 state.text <- Printf.sprintf
"bad integer `%s': %s"
4282 let te = name ^
": ", "", None
, intentry, ondone, true in
4283 state.mode
<- Textentry
(te, leave m_prev_mode
);
4287 method int_with_suffix
name get
set =
4289 (name, `intws get
, 1, Action
(
4292 try set (int_of_string_with_suffix s)
4294 state.text <- Printf.sprintf
"bad integer `%s': %s"
4299 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4301 state.mode
<- Textentry
(te, leave m_prev_mode
);
4305 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4307 (name, `
bool (btos, get
), offset
, Action
(
4314 method color
name get
set =
4316 (name, `color get
, 1, Action
(
4318 let invalid = (nan
, nan
, nan
) in
4321 try color_of_string s
4323 state.text <- Printf.sprintf
"bad color `%s': %s"
4330 let te = name ^
": ", "", None
, textentry, ondone, true in
4331 state.text <- color_to_string (get
());
4332 state.mode
<- Textentry
(te, leave m_prev_mode
);
4336 method string name get
set =
4338 (name, `
string get
, 1, Action
(
4340 let ondone s = set s in
4341 let te = name ^
": ", "", None
, textentry, ondone, true in
4342 state.mode
<- Textentry
(te, leave m_prev_mode
);
4346 method colorspace
name get
set =
4348 (name, `
string get
, 1, Action
(
4352 inherit lvsourcebase
4355 m_active
<- CSTE.to_int conf.colorspace
;
4358 method getitemcount
=
4359 Array.length
CSTE.names
4362 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4363 ignore
(uioh
, first, pan
, qsearch);
4364 if not cancel
then set active;
4366 method hasaction
_ = true
4370 let modehash = findkeyhash conf "info" in
4371 coe (new listview ~
source ~trusted
:true ~
modehash)
4374 method paxmark
name get
set =
4376 (name, `
string get
, 1, Action
(
4380 inherit lvsourcebase
4383 m_active
<- MTE.to_int conf.paxmark
;
4386 method getitemcount
= Array.length
MTE.names
4387 method getitem
n = (MTE.names.(n), 0)
4388 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4389 ignore
(uioh
, first, pan
, qsearch);
4390 if not cancel
then set active;
4392 method hasaction
_ = true
4396 let modehash = findkeyhash conf "info" in
4397 coe (new listview ~
source ~trusted
:true ~
modehash)
4400 method fitmodel
name get
set =
4402 (name, `
string get
, 1, Action
(
4406 inherit lvsourcebase
4409 m_active
<- FMTE.to_int conf.fitmodel
;
4412 method getitemcount
= Array.length
FMTE.names
4413 method getitem
n = (FMTE.names.(n), 0)
4414 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4415 ignore
(uioh
, first, pan
, qsearch);
4416 if not cancel
then set active;
4418 method hasaction
_ = true
4422 let modehash = findkeyhash conf "info" in
4423 coe (new listview ~
source ~trusted
:true ~
modehash)
4426 method caption
s offset
=
4427 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4429 method caption2
s f offset
=
4430 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4432 method getitemcount
= Array.length m_a
4435 let tostr = function
4436 | `
int f -> string_of_int
(f ())
4437 | `intws
f -> string_with_suffix_of_int (f ())
4439 | `color
f -> color_to_string (f ())
4440 | `
bool (btos, f) -> btos (f ())
4443 let name, t
, offset
, _ = m_a
.(n) in
4444 ((let s = tostr t
in
4445 if String.length
s > 0
4446 then Printf.sprintf
"%s\t%s" name s
4450 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4454 m_qsearch
<- qsearch;
4456 match m_a
.(active) with
4457 | _, _, _, Action
f -> f uioh
4469 method hasaction
n =
4471 | _, _, _, Action
_ -> true
4475 let rec fillsrc prevmode prevuioh
=
4476 let sep () = src#caption
"" 0 in
4477 let colorp name get
set =
4479 (fun () -> color_to_string (get
()))
4482 let c = color_of_string v in
4485 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4488 let oldmode = state.mode
in
4489 let birdseye = isbirdseye state.mode
in
4491 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4493 src#
bool "presentation mode"
4494 (fun () -> conf.presentation
)
4495 (fun v -> setpresentationmode v);
4497 src#
bool "ignore case in searches"
4498 (fun () -> conf.icase
)
4499 (fun v -> conf.icase
<- v);
4502 (fun () -> conf.preload)
4503 (fun v -> conf.preload <- v);
4505 src#
bool "highlight links"
4506 (fun () -> conf.hlinks
)
4507 (fun v -> conf.hlinks
<- v);
4509 src#
bool "under info"
4510 (fun () -> conf.underinfo
)
4511 (fun v -> conf.underinfo
<- v);
4513 src#
bool "persistent bookmarks"
4514 (fun () -> conf.savebmarks
)
4515 (fun v -> conf.savebmarks
<- v);
4517 src#fitmodel
"fit model"
4518 (fun () -> FMTE.to_string conf.fitmodel
)
4519 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4521 src#
bool "trim margins"
4522 (fun () -> conf.trimmargins
)
4523 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4525 src#
bool "persistent location"
4526 (fun () -> conf.jumpback
)
4527 (fun v -> conf.jumpback
<- v);
4530 src#
int "inter-page space"
4531 (fun () -> conf.interpagespace
)
4533 conf.interpagespace
<- n;
4534 docolumns conf.columns
;
4536 match state.layout with
4541 state.maxy <- calcheight ();
4542 let y = getpagey pageno in
4547 (fun () -> conf.pagebias
)
4548 (fun v -> conf.pagebias
<- v);
4550 src#
int "scroll step"
4551 (fun () -> conf.scrollstep
)
4552 (fun n -> conf.scrollstep
<- n);
4554 src#
int "horizontal scroll step"
4555 (fun () -> conf.hscrollstep
)
4556 (fun v -> conf.hscrollstep
<- v);
4558 src#
int "auto scroll step"
4560 match state.autoscroll
with
4562 | _ -> conf.autoscrollstep
)
4564 if state.autoscroll
<> None
4565 then state.autoscroll
<- Some
n;
4566 conf.autoscrollstep
<- n);
4569 (fun () -> truncate
(conf.zoom *. 100.))
4570 (fun v -> setzoom ((float v) /. 100.));
4573 (fun () -> conf.angle
)
4574 (fun v -> reqlayout v conf.fitmodel
);
4576 src#
int "scroll bar width"
4577 (fun () -> conf.scrollbw
)
4580 reshape state.winw
state.winh
;
4583 src#
int "scroll handle height"
4584 (fun () -> conf.scrollh
)
4585 (fun v -> conf.scrollh
<- v;);
4587 src#
int "thumbnail width"
4588 (fun () -> conf.thumbw
)
4590 conf.thumbw
<- min
4096 v;
4593 leavebirdseye beye
false;
4598 let mode = state.mode in
4599 src#
string "columns"
4601 match conf.columns
with
4603 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4604 | Csplit
(count
, _) -> "-" ^ string_of_int count
4607 let n, a, b = multicolumns_of_string v in
4608 setcolumns mode n a b);
4611 src#caption
"Pixmap cache" 0;
4612 src#int_with_suffix
"size (advisory)"
4613 (fun () -> conf.memlimit
)
4614 (fun v -> conf.memlimit
<- v);
4617 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4618 (string_with_suffix_of_int state.memused
)
4619 (Hashtbl.length
state.tilemap
)) 1;
4622 src#caption
"Layout" 0;
4623 src#caption2
"Dimension"
4625 Printf.sprintf
"%dx%d (virtual %dx%d)"
4626 state.winw
state.winh
4631 src#caption2
"Position" (fun () ->
4632 Printf.sprintf
"%dx%d" state.x state.y
4635 src#caption2
"Position" (fun () -> describe_location ()) 1
4639 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4640 "Save these parameters as global defaults at exit"
4641 (fun () -> conf.bedefault
)
4642 (fun v -> conf.bedefault
<- v)
4646 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4647 src#
bool ~offset
:0 ~
btos "Extended parameters"
4648 (fun () -> !showextended)
4649 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4653 (fun () -> conf.checkers
)
4654 (fun v -> conf.checkers
<- v; setcheckers v);
4655 src#
bool "update cursor"
4656 (fun () -> conf.updatecurs
)
4657 (fun v -> conf.updatecurs
<- v);
4659 (fun () -> conf.verbose
)
4660 (fun v -> conf.verbose
<- v);
4661 src#
bool "invert colors"
4662 (fun () -> conf.invert
)
4663 (fun v -> conf.invert
<- v);
4665 (fun () -> conf.maxhfit
)
4666 (fun v -> conf.maxhfit
<- v);
4667 src#
bool "redirect stderr"
4668 (fun () -> conf.redirectstderr)
4669 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4671 (fun () -> conf.pax
!= None
)
4674 then conf.pax
<- Some
(ref (now (), 0, 0))
4675 else conf.pax
<- None
);
4676 src#
string "uri launcher"
4677 (fun () -> conf.urilauncher
)
4678 (fun v -> conf.urilauncher
<- v);
4679 src#
string "path launcher"
4680 (fun () -> conf.pathlauncher
)
4681 (fun v -> conf.pathlauncher
<- v);
4682 src#
string "tile size"
4683 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4686 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4687 conf.tilew
<- max
64 w;
4688 conf.tileh
<- max
64 h;
4691 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4694 src#
int "texture count"
4695 (fun () -> conf.texcount
)
4698 then conf.texcount
<- v
4699 else showtext '
!'
" Failed to set texture count please retry later"
4701 src#
int "slice height"
4702 (fun () -> conf.sliceheight
)
4704 conf.sliceheight
<- v;
4705 wcmd "sliceh %d" conf.sliceheight
;
4707 src#
int "anti-aliasing level"
4708 (fun () -> conf.aalevel
)
4710 conf.aalevel
<- bound v 0 8;
4711 state.anchor <- getanchor ();
4712 opendoc state.path
state.password
;
4714 src#
string "page scroll scaling factor"
4715 (fun () -> string_of_float
conf.pgscale)
4718 let s = float_of_string
v in
4721 state.text <- Printf.sprintf
4722 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4725 src#
int "ui font size"
4726 (fun () -> fstate.fontsize
)
4727 (fun v -> setfontsize (bound v 5 100));
4728 src#
int "hint font size"
4729 (fun () -> conf.hfsize
)
4730 (fun v -> conf.hfsize
<- bound v 5 100);
4731 colorp "background color"
4732 (fun () -> conf.bgcolor
)
4733 (fun v -> conf.bgcolor
<- v);
4734 src#
bool "crop hack"
4735 (fun () -> conf.crophack
)
4736 (fun v -> conf.crophack
<- v);
4737 src#
string "trim fuzz"
4738 (fun () -> irect_to_string conf.trimfuzz
)
4741 conf.trimfuzz
<- irect_of_string v;
4743 then settrim true conf.trimfuzz
;
4745 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4747 src#
string "throttle"
4749 match conf.maxwait
with
4750 | None
-> "show place holder if page is not ready"
4753 then "wait for page to fully render"
4755 "wait " ^ string_of_float
time
4756 ^
" seconds before showing placeholder"
4760 let f = float_of_string
v in
4762 then conf.maxwait
<- None
4763 else conf.maxwait
<- Some
f
4765 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4767 src#
string "ghyll scroll"
4769 match conf.ghyllscroll
with
4771 | Some nab
-> ghyllscroll_to_string nab
4776 if String.length
v = 0
4778 else Some
(ghyllscroll_of_string v)
4780 conf.ghyllscroll
<- gs
4782 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4784 src#
string "selection command"
4785 (fun () -> conf.selcmd
)
4786 (fun v -> conf.selcmd
<- v);
4787 src#
string "synctex command"
4788 (fun () -> conf.stcmd
)
4789 (fun v -> conf.stcmd
<- v);
4790 src#
string "pax command"
4791 (fun () -> conf.paxcmd
)
4792 (fun v -> conf.paxcmd
<- v);
4793 src#colorspace
"color space"
4794 (fun () -> CSTE.to_string conf.colorspace
)
4796 conf.colorspace
<- CSTE.of_int v;
4800 src#paxmark
"pax mark method"
4801 (fun () -> MTE.to_string conf.paxmark
)
4802 (fun v -> conf.paxmark
<- MTE.of_int v);
4806 (fun () -> conf.usepbo
)
4807 (fun v -> conf.usepbo
<- v);
4808 src#
bool "mouse wheel scrolls pages"
4809 (fun () -> conf.wheelbypage
)
4810 (fun v -> conf.wheelbypage
<- v);
4811 src#
bool "open remote links in a new instance"
4812 (fun () -> conf.riani
)
4813 (fun v -> conf.riani
<- v);
4817 src#caption
"Document" 0;
4818 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4819 src#caption2
"Pages"
4820 (fun () -> string_of_int
state.pagecount
) 1;
4821 src#caption2
"Dimensions"
4822 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4826 src#caption
"Trimmed margins" 0;
4827 src#caption2
"Dimensions"
4828 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4832 src#caption
"OpenGL" 0;
4833 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4834 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4837 src#caption
"Location" 0;
4838 if String.length
state.origin
> 0
4839 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4840 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4842 src#reset prevmode prevuioh
;
4846 let prevmode = state.mode
4847 and prevuioh
= state.uioh in
4848 fillsrc prevmode prevuioh
;
4849 let source = (src :> lvsource
) in
4850 let modehash = findkeyhash conf "info" in
4851 state.uioh <- coe (object (self)
4852 inherit listview ~
source ~trusted
:true ~
modehash as super
4853 val mutable m_prevmemused
= 0
4854 method infochanged
= function
4856 if m_prevmemused
!= state.memused
4858 m_prevmemused
<- state.memused
;
4859 G.postRedisplay "memusedchanged";
4861 | Pdim
-> G.postRedisplay "pdimchanged"
4862 | Docinfo
-> fillsrc prevmode prevuioh
4864 method key key mask
=
4865 if not
(Wsi.withctrl mask
)
4868 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4869 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4870 | _ -> super#
key key mask
4871 else super#
key key mask
4873 G.postRedisplay "info";
4879 inherit lvsourcebase
4880 method getitemcount
= Array.length
state.help
4882 let s, l, _ = state.help
.(n) in
4885 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4889 m_qsearch
<- qsearch;
4890 match state.help
.(active) with
4891 | _, _, Action
f -> Some
(f uioh)
4901 method hasaction
n =
4902 match state.help
.(n) with
4903 | _, _, Action
_ -> true
4910 let modehash = findkeyhash conf "help" in
4911 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4912 G.postRedisplay "help";
4917 let re = Str.regexp
"[\r\n]" in
4919 inherit lvsourcebase
4920 val mutable m_items
= [||]
4922 method getitemcount
= 1 + Array.length m_items
4927 else m_items
.(n-1), 0
4929 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4934 then Buffer.clear
state.errmsgs
;
4935 m_qsearch
<- qsearch;
4942 method hasaction
n =
4946 state.newerrmsgs
<- false;
4947 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4948 m_items
<- Array.of_list
l
4956 let source = (msgsource :> lvsource
) in
4957 let modehash = findkeyhash conf "listview" in
4958 state.uioh <- coe (object
4959 inherit listview ~
source ~trusted
:false ~
modehash as super
4962 then msgsource#reset
;
4965 G.postRedisplay "msgs";
4968 let quickbookmark ?title
() =
4969 match state.layout with
4975 let sec = Unix.gettimeofday
() in
4976 let tm = Unix.localtime
sec in
4977 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4981 (tm.Unix.tm_year
+ 1900)
4984 | Some
title -> title
4986 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4989 let setautoscrollspeed step goingdown
=
4990 let incr = max
1 ((abs step
) / 2) in
4991 let incr = if goingdown
then incr else -incr in
4992 let astep = step
+ incr in
4993 state.autoscroll
<- Some
astep;
4996 let gotounder = function
4997 | Ulinkgoto
(pageno, top) ->
5001 gotopage1 pageno top;
5007 | Uremote
(filename
, pageno) ->
5009 if String.length filename
> 0
5011 if Filename.is_relative filename
5013 let dir = Filename.dirname
state.path in
5015 if Filename.is_implicit
dir
5016 then Filename.concat
(Sys.getcwd
()) dir
5019 Filename.concat
dir filename
5024 if Sys.file_exists
path
5028 if String.length
path > 0
5032 let command = !selfexec ^
" " ^
path in
5033 try popen command []
5036 "failed to execute `%s': %s\n" command (exntos exn
);
5039 let anchor = getanchor () in
5040 let ranchor = state.path, state.password
, anchor, state.origin
in
5042 state.anchor <- (pageno, 0.0, 0.0);
5043 state.ranchors
<- ranchor :: state.ranchors
;
5046 else showtext '
!'
("Could not find " ^ filename
)
5048 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
5052 match conf.columns
with
5054 | _ -> state.x != 0 || conf.zoom > 1.0
5057 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5059 let existsinrow pageno (columns
, coverA
, coverB
) p =
5060 let last = ((pageno - coverA
) mod columns
) + columns
in
5061 let rec any = function
5064 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5068 then (if l.pageno = last then false else any rest
)
5076 match state.layout with
5078 let pageno = page_of_y state.y in
5079 gotoghyll (getpagey (pageno+1))
5081 match conf.columns
with
5083 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5085 let y = clamp (pgscale state.winh
) in
5088 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5089 gotoghyll (getpagey pageno)
5090 | Cmulti
((c, _, _) as cl, _) ->
5091 if conf.presentation
5092 && (existsinrow l.pageno cl
5093 (fun l -> l.pageh
> l.pagey + l.pagevh))
5095 let y = clamp (pgscale state.winh
) in
5098 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5099 gotoghyll (getpagey pageno)
5101 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5103 let pagey, pageh
= getpageyh l.pageno in
5104 let pagey = pagey + pageh
* l.pagecol
in
5105 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5106 gotoghyll (pagey + pageh
+ ips)
5110 match state.layout with
5112 let pageno = page_of_y state.y in
5113 gotoghyll (getpagey (pageno-1))
5115 match conf.columns
with
5117 if conf.presentation
&& l.pagey != 0
5119 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5121 let pageno = max
0 (l.pageno-1) in
5122 gotoghyll (getpagey pageno)
5123 | Cmulti
((c, _, coverB
) as cl, _) ->
5124 if conf.presentation
&&
5125 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5127 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5130 if l.pageno = state.pagecount
- coverB
5134 let pageno = max
0 (l.pageno-decr) in
5135 gotoghyll (getpagey pageno)
5143 let pageno = max
0 (l.pageno-1) in
5144 let pagey, pageh
= getpageyh pageno in
5147 let pagey, pageh
= getpageyh l.pageno in
5148 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5153 let viewkeyboard key mask
=
5155 let mode = state.mode in
5156 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5159 G.postRedisplay "view:enttext"
5161 let ctrl = Wsi.withctrl mask
in
5163 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5169 | 0xff63 -> (* insert *)
5170 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5172 state.mode <- LinkNav
(Ltgendir
0);
5175 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5177 | 0xff1b | 113 -> (* escape / q *)
5178 begin match state.mstate
with
5180 state.mstate
<- Mnone
;
5181 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5182 G.postRedisplay "kill zoom rect";
5184 begin match state.mode with
5187 G.postRedisplay "esc leave linknav"
5189 match state.ranchors
with
5191 | (path, password
, anchor, origin
) :: rest
->
5192 state.ranchors
<- rest
;
5193 state.anchor <- anchor;
5194 state.origin
<- origin
;
5195 opendoc path password
5199 | 0xff08 -> (* backspace *)
5200 gotoghyll (getnav ~
-1)
5208 G.postRedisplay "dehighlight";
5210 | 47 | 63 -> (* / ? *)
5211 let ondone isforw
s =
5212 cbput state.hists
.pat
s;
5213 state.searchpattern
<- s;
5216 let s = String.create
1 in
5217 s.[0] <- Char.chr
key;
5218 enttext (s, "", Some
(onhist state.hists
.pat
),
5219 textentry, ondone (key = 47), true)
5221 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5222 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5223 setzoom (conf.zoom +. incr)
5225 | 43 | 0xffab -> (* + *)
5228 try int_of_string
s with exc
->
5229 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5235 state.text <- "page bias is now " ^ string_of_int
n;
5238 enttext ("page bias: ", "", None
, intentry, ondone, true)
5240 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5241 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5242 setzoom (max
0.01 (conf.zoom -. decr))
5244 | 45 | 0xffad -> (* - *)
5245 let ondone msg
= state.text <- msg
in
5247 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5248 optentry state.mode, ondone, true
5251 | 48 when ctrl -> (* ctrl-0 *)
5259 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5261 match conf.columns
with
5262 | Csingle
_ | Cmulti
_ -> 1
5263 | Csplit
(n, _) -> n
5265 let h = state.winh
-
5266 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5268 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5269 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5272 | 51 when ctrl -> (* ctrl-3 *)
5274 match conf.fitmodel
with
5275 | FitWidth
-> FitProportional
5276 | FitProportional
-> FitPage
5277 | FitPage
-> FitWidth
5279 state.text <- "fit model: " ^
FMTE.to_string fm;
5280 reqlayout conf.angle
fm
5282 | 0xffc6 -> (* f9 *)
5285 | 57 when ctrl -> (* ctrl-9 *)
5288 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5289 when not
ctrl -> (* 0..9 *)
5292 try int_of_string
s with exc
->
5293 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5299 cbput state.hists
.pag
(string_of_int
n);
5300 gotopage1 (n + conf.pagebias
- 1) 0;
5303 let pageentry text key =
5304 match Char.unsafe_chr
key with
5305 | '
g'
-> TEdone
text
5306 | _ -> intentry text key
5308 let text = "x" in text.[0] <- Char.chr
key;
5309 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5312 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5313 reshape state.winw
state.winh
;
5316 conf.hlinks
<- not
conf.hlinks
;
5317 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5318 G.postRedisplay "toggle highlightlinks";
5321 state.glinks
<- true;
5322 let mode = state.mode in
5323 state.mode <- Textentry
(
5324 (":", "", None
, linknentry, linkndone gotounder, false),
5326 state.glinks
<- false;
5330 G.postRedisplay "view:linkent(F)"
5333 state.glinks
<- true;
5334 let mode = state.mode in
5335 state.mode <- Textentry
(
5337 ":", "", None
, linknentry, linkndone (fun under ->
5338 selstring (undertext under);
5342 state.glinks
<- false;
5346 G.postRedisplay "view:linkent"
5349 begin match state.autoscroll
with
5351 conf.autoscrollstep
<- step
;
5352 state.autoscroll
<- None
5354 if conf.autoscrollstep
= 0
5355 then state.autoscroll
<- Some
1
5356 else state.autoscroll
<- Some
conf.autoscrollstep
5359 | 112 when ctrl -> (* ctrl-p *)
5363 setpresentationmode (not
conf.presentation
);
5364 showtext ' '
("presentation mode " ^
5365 if conf.presentation
then "on" else "off");
5368 if List.mem
Wsi.Fullscreen
state.winstate
5369 then Wsi.reshape conf.cwinw
conf.cwinh
5370 else Wsi.fullscreen
()
5372 | 112 | 78 -> (* p|N *)
5373 search state.searchpattern
false
5375 | 110 | 0xffc0 -> (* n|F3 *)
5376 search state.searchpattern
true
5379 begin match state.layout with
5382 gotoghyll (getpagey l.pageno)
5388 | 0xff9f | 0xffff -> (* delete *)
5392 showtext ' '
(describe_location ());
5395 begin match state.layout with
5398 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5403 enterbookmarkmode ()
5405 | 104 | 0xffbe -> (* h|F1 *)
5411 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5416 match state.layout with
5418 if String.length
s > 0
5420 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5423 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5427 showtext ' '
"Quick bookmark added";
5430 begin match state.layout with
5432 let rect = getpdimrect
l.pagedimno
in
5436 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5437 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5439 (truncate
(rect.(1) -. rect.(0)),
5440 truncate
(rect.(3) -. rect.(0)))
5442 let w = truncate
((float w)*.conf.zoom)
5443 and h = truncate
((float h)*.conf.zoom) in
5446 state.anchor <- getanchor ();
5447 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5449 G.postRedisplay "z";
5454 | 120 -> state.roam
()
5455 | 60 | 62 -> (* < > *)
5456 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5458 | 91 | 93 -> (* [ ] *)
5460 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5462 G.postRedisplay "brightness";
5464 | 99 when state.mode = View
-> (* [alt-]c *)
5469 let m = (wadjsb state.winw
- state.w) / 2 in
5471 gotoy_and_clear_text state.y
5475 match state.prevcolumns
with
5476 | None
-> (1, 0, 0), 1.0
5477 | Some
(columns
, z
) ->
5480 | Csplit
(c, _) -> -c, 0, 0
5481 | Cmulti
((c, a, b), _) -> c, a, b
5482 | Csingle
_ -> 1, 0, 0
5486 setcolumns View
c a b;
5489 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5490 setzoom state.prevzoom
5492 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5493 begin match state.autoscroll
with
5495 begin match state.mode with
5496 | Birdseye beye
-> upbirdseye 1 beye
5499 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5501 if not
(Wsi.withshift mask
) && conf.presentation
5503 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5507 setautoscrollspeed n false
5510 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5511 begin match state.autoscroll
with
5513 begin match state.mode with
5514 | Birdseye beye
-> downbirdseye 1 beye
5517 then gotoy_and_clear_text (clamp (state.winh
/2))
5519 if not
(Wsi.withshift mask
) && conf.presentation
5521 else gotoy_and_clear_text (clamp conf.scrollstep
)
5525 setautoscrollspeed n true
5528 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5529 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5535 else conf.hscrollstep
5537 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5538 state.x <- panbound (state.x + dx);
5539 gotoy_and_clear_text state.y
5542 G.postRedisplay "left/right"
5545 | 0xff55 | 0xff9a -> (* (kp) prior *)
5549 match state.layout with
5551 | l :: _ -> state.y - l.pagey
5553 clamp (pgscale (-state.winh
))
5557 | 0xff56 | 0xff9b -> (* (kp) next *)
5561 match List.rev
state.layout with
5563 | l :: _ -> getpagey l.pageno
5565 clamp (pgscale state.winh
)
5569 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5571 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5572 gotoghyll (clamp state.maxy)
5575 when Wsi.withalt mask
-> (* alt-(kp) right *)
5576 gotoghyll (getnav 1)
5578 when Wsi.withalt mask
-> (* alt-(kp) left *)
5579 gotoghyll (getnav ~
-1)
5584 | 118 when conf.debug
-> (* v *)
5587 match getopaque l.pageno with
5590 let x0, y0, x1, y1 = pagebbox opaque
in
5591 let a,b = float x0, float y0 in
5592 let c,d = float x1, float y0 in
5593 let e,f = float x1, float y1 in
5594 let h,j
= float x0, float y1 in
5595 let rect = (a,b,c,d,e,f,h,j
) in
5597 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5599 G.postRedisplay "v";
5602 vlog "huh? %s" (Wsi.keyname
key)
5605 let linknavkeyboard key mask
linknav =
5606 let getpage pageno =
5607 let rec loop = function
5609 | l :: _ when l.pageno = pageno -> Some
l
5610 | _ :: rest
-> loop rest
5611 in loop state.layout
5613 let doexact (pageno, n) =
5614 match getopaque pageno, getpage pageno with
5615 | Some opaque
, Some
l ->
5616 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5618 let under = getlink opaque
n in
5619 G.postRedisplay "link gotounder";
5625 | 0xff50 -> (* home *)
5626 Some
(findlink opaque LDfirst
), -1
5628 | 0xff57 -> (* end *)
5629 Some
(findlink opaque LDlast
), 1
5631 | 0xff51 -> (* left *)
5632 Some
(findlink opaque
(LDleft
n)), -1
5634 | 0xff53 -> (* right *)
5635 Some
(findlink opaque
(LDright
n)), 1
5637 | 0xff52 -> (* up *)
5638 Some
(findlink opaque
(LDup
n)), -1
5640 | 0xff54 -> (* down *)
5641 Some
(findlink opaque
(LDdown
n)), 1
5646 begin match findpwl
l.pageno dir with
5650 state.mode <- LinkNav
(Ltgendir
dir);
5651 let y, h = getpageyh pageno in
5654 then y + h - state.winh
5659 begin match getopaque pageno, getpage pageno with
5660 | Some opaque
, Some
_ ->
5662 let ld = if dir > 0 then LDfirst
else LDlast
in
5665 begin match link with
5667 showlinktype (getlink opaque
m);
5668 state.mode <- LinkNav
(Ltexact
(pageno, m));
5669 G.postRedisplay "linknav jpage";
5676 begin match opt with
5677 | Some Lnotfound
-> pwl l dir;
5678 | Some
(Lfound
m) ->
5682 let _, y0, _, y1 = getlinkrect opaque
m in
5684 then gotopage1 l.pageno y0
5686 let d = fstate.fontsize
+ 1 in
5687 if y1 - l.pagey > l.pagevh - d
5688 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5689 else G.postRedisplay "linknav";
5691 showlinktype (getlink opaque
m);
5692 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5695 | None
-> viewkeyboard key mask
5697 | _ -> viewkeyboard key mask
5702 G.postRedisplay "leave linknav"
5706 | Ltgendir
_ -> viewkeyboard key mask
5707 | Ltexact exact
-> doexact exact
5710 let keyboard key mask
=
5711 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5712 then wcmd "interrupt"
5713 else state.uioh <- state.uioh#
key key mask
5716 let birdseyekeyboard key mask
5717 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5719 match conf.columns
with
5721 | Cmulti
((c, _, _), _) -> c
5722 | Csplit
_ -> failwith
"bird's eye split mode"
5724 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5726 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5727 let y, h = getpageyh pageno in
5728 let top = (state.winh
- h) / 2 in
5729 gotoy (max
0 (y - top))
5730 | 0xff0d (* enter *)
5731 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5732 | 0xff1b -> leavebirdseye beye
true (* escape *)
5733 | 0xff52 -> upbirdseye incr beye
(* up *)
5734 | 0xff54 -> downbirdseye incr beye
(* down *)
5735 | 0xff51 -> upbirdseye 1 beye
(* left *)
5736 | 0xff53 -> downbirdseye 1 beye
(* right *)
5738 | 0xff55 -> (* prior *)
5739 begin match state.layout with
5743 state.mode <- Birdseye
(
5744 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5746 gotopage1 l.pageno 0;
5749 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5751 | [] -> gotoy (clamp (-state.winh
))
5753 state.mode <- Birdseye
(
5754 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5756 gotopage1 l.pageno 0
5759 | [] -> gotoy (clamp (-state.winh
))
5762 | 0xff56 -> (* next *)
5763 begin match List.rev
state.layout with
5765 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5766 begin match layout with
5768 let incr = l.pageh
- l.pagevh in
5773 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5775 G.postRedisplay "birdseye pagedown";
5777 else gotoy (clamp (incr + conf.interpagespace
*2));
5781 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5782 gotopage1 l.pageno 0;
5785 | [] -> gotoy (clamp state.winh
)
5788 | 0xff50 -> (* home *)
5789 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5792 | 0xff57 -> (* end *)
5793 let pageno = state.pagecount
- 1 in
5794 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5795 if not
(pagevisible state.layout pageno)
5798 match List.rev
state.pdims
with
5800 | (_, _, h, _) :: _ -> h
5802 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5803 else G.postRedisplay "birdseye end";
5804 | _ -> viewkeyboard key mask
5809 match state.mode with
5810 | Textentry
_ -> scalecolor 0.4
5812 | View
-> scalecolor 1.0
5813 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5814 if l.pageno = hooverpageno
5817 if l.pageno = pageno
5825 let postdrawpage l linkindexbase
=
5826 match getopaque l.pageno with
5828 if tileready l l.pagex
l.pagey
5830 let x = l.pagedispx - l.pagex
5831 and y = l.pagedispy - l.pagey in
5833 match conf.columns
with
5834 | Csingle
_ | Cmulti
_ ->
5835 (if conf.hlinks
then 1 else 0)
5837 && not
(isbirdseye state.mode) then 2 else 0)
5841 match state.mode with
5842 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5845 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5850 let scrollindicator () =
5851 let sbw, ph
, sh = state.uioh#
scrollph in
5852 let sbh, pw, sw = state.uioh#scrollpw
in
5854 GlDraw.color (0.64, 0.64, 0.64);
5856 (float (state.winw
- sbw), 0.)
5857 (float state.winw
, float state.winh
)
5860 (0., float (state.winh
- sbh))
5861 (float (wadjsb state.winw
- 1), float state.winh
)
5863 GlDraw.color (0.0, 0.0, 0.0);
5866 (float (state.winw
- sbw), ph
)
5867 (float state.winw
, ph
+. sh)
5870 (pw, float (state.winh
- sbh))
5871 (pw +. sw, float state.winh
)
5876 match state.mstate
with
5877 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5880 | Msel
((x0, y0), (x1, y1)) ->
5881 let rec loop = function
5883 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5884 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5885 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5886 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5888 match getopaque l.pageno with
5890 let x0, y0 = pagetranslatepoint l x0 y0 in
5891 let x1, y1 = pagetranslatepoint l x1 y1 in
5892 seltext opaque
(x0, y0, x1, y1);
5900 let showrects rects
=
5902 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5903 GlDraw.polygon_mode `both `fill
;
5904 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5906 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5908 if l.pageno = pageno
5910 let dx = float (l.pagedispx - l.pagex
) in
5911 let dy = float (l.pagedispy - l.pagey) in
5912 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
5913 GlDraw.begins `quads
;
5915 GlDraw.vertex2
(x0+.dx, y0+.dy);
5916 GlDraw.vertex2
(x1+.dx, y1+.dy);
5917 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5918 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5929 GlClear.color (scalecolor2 conf.bgcolor
);
5930 GlClear.clear
[`
color];
5931 List.iter
drawpage state.layout;
5933 match state.mode with
5934 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5935 begin match getopaque pageno with
5937 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5944 | None
-> state.rects
5949 let rec postloop linkindexbase
= function
5951 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5952 postloop linkindexbase rest
5956 postloop 0 state.layout;
5958 begin match state.mstate
with
5959 | Mzoomrect
((x0, y0), (x1, y1)) ->
5961 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5962 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5963 GlDraw.rect (float x0, float y0)
5964 (float x1, float y1);
5973 let zoomrect x y x1 y1 =
5976 and y0 = min
y y1 in
5977 gotoy (state.y + y0);
5978 state.anchor <- getanchor ();
5979 let zoom = (float state.w) /. float (x1 - x0) in
5981 match conf.fitmodel
, conf.columns
with
5982 | FitPage
, Csplit
_ ->
5983 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5986 let adjw = wadjsb state.winw
in
5988 then (adjw - state.w) / 2
5991 state.x <- (state.x + margin) - x0;
5993 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5994 state.mstate
<- Mnone
;
5998 let winw = wadjsb state.winw - 1 in
5999 let s = float x /. float winw in
6000 let destx = truncate
(float (state.w + winw) *. s) in
6001 state.x <- winw - destx;
6002 gotoy_and_clear_text state.y;
6003 state.mstate
<- Mscrollx
;
6007 let s = float y /. float state.winh
in
6008 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6009 gotoy_and_clear_text desty;
6010 state.mstate
<- Mscrolly
;
6013 let viewmouse button down
x y mask
=
6015 | n when (n == 4 || n == 5) && not down
->
6016 if Wsi.withctrl mask
6018 match state.mstate
with
6019 | Mzoom
(oldn
, i
) ->
6027 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6029 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6031 let zoom = conf.zoom -. incr in
6033 state.mstate
<- Mzoom
(n, 0);
6035 state.mstate
<- Mzoom
(n, i
+1);
6037 else state.mstate
<- Mzoom
(n, 0)
6039 | _ -> state.mstate
<- Mzoom
(n, 0)
6042 match state.autoscroll
with
6043 | Some step
-> setautoscrollspeed step
(n=4)
6045 if conf.wheelbypage
|| conf.presentation
6054 then -conf.scrollstep
6055 else conf.scrollstep
6057 let incr = incr * 2 in
6058 let y = clamp incr in
6059 gotoy_and_clear_text y
6062 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6064 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6065 gotoy_and_clear_text state.y
6067 | 1 when Wsi.withshift mask
->
6068 state.mstate
<- Mnone
;
6071 match unproject x y with
6072 | Some
(pageno, ux
, uy
) ->
6073 let cmd = Printf.sprintf
6075 conf.stcmd
state.path pageno ux uy
6081 | 1 when Wsi.withctrl mask
->
6084 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6085 state.mstate
<- Mpan
(x, y)
6088 state.mstate
<- Mnone
6093 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6095 state.mstate
<- Mzoomrect
(p, p)
6098 match state.mstate
with
6099 | Mzoomrect
((x0, y0), _) ->
6100 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6101 then zoomrect x0 y0 x y
6103 state.mstate
<- Mnone
;
6104 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6105 G.postRedisplay "kill accidental zoom rect";
6108 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6109 state.mstate
<- Mnone
6112 | 1 when x > state.winw - vscrollw () ->
6115 let _, position, sh = state.uioh#
scrollph in
6116 if y > truncate
position && y < truncate
(position +. sh)
6117 then state.mstate
<- Mscrolly
6120 state.mstate
<- Mnone
6122 | 1 when y > state.winh
- hscrollh () ->
6125 let _, position, sw = state.uioh#scrollpw
in
6126 if x > truncate
position && x < truncate
(position +. sw)
6127 then state.mstate
<- Mscrollx
6130 state.mstate
<- Mnone
6133 let dest = if down
then getunder x y else Unone
in
6134 begin match dest with
6138 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6141 | Unone
when down
->
6142 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6143 state.mstate
<- Mpan
(x, y);
6145 | Unone
| Utext
_ ->
6148 if conf.angle
mod 360 = 0
6150 state.mstate
<- Msel
((x, y), (x, y));
6151 G.postRedisplay "mouse select";
6155 match state.mstate
with
6158 | Mzoom
_ | Mscrollx
| Mscrolly
->
6159 state.mstate
<- Mnone
6161 | Mzoomrect
((x0, y0), _) ->
6165 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6166 state.mstate
<- Mnone
6168 | Msel
((x0, y0), (x1, y1)) ->
6169 let rec loop = function
6173 let a0 = l.pagedispy in
6174 let a1 = a0 + l.pagevh in
6175 let b0 = l.pagedispx in
6176 let b1 = b0 + l.pagevw in
6177 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6178 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6182 match getopaque l.pageno with
6185 match Ne.pipe () with
6189 "can not create sel pipe: %s"
6192 let doclose what fd
=
6193 Ne.clo fd
(fun msg
->
6194 dolog
"%s close failed: %s" what msg
)
6197 popen conf.selcmd
[r, 0; w, -1];
6198 copysel
w opaque
true;
6200 G.postRedisplay "copysel";
6202 dolog
"can not execute %S: %s"
6203 conf.selcmd
(exntos exn
);
6211 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6212 state.mstate
<- Mnone
;
6219 let birdseyemouse button down
x y mask
6220 (conf, leftx
, _, hooverpageno
, anchor) =
6223 let rec loop = function
6226 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6227 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6229 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6235 | _ -> viewmouse button down
x y mask
6238 let mouse button down
x y mask
=
6239 state.uioh <- state.uioh#button button down
x y mask
;
6243 state.uioh <- state.uioh#
motion x y
6247 state.uioh <- state.uioh#
pmotion x y;
6253 method key key mask
=
6254 begin match state.mode with
6255 | Textentry
textentry -> textentrykeyboard key mask
textentry
6256 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6257 | View
-> viewkeyboard key mask
6258 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6262 method button button bstate
x y mask
=
6263 begin match state.mode with
6265 | View
-> viewmouse button bstate
x y mask
6266 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6272 begin match state.mode with
6274 | View
| Birdseye
_ | LinkNav
_ ->
6275 match state.mstate
with
6276 | Mzoom
_ | Mnone
-> ()
6281 state.mstate
<- Mpan
(x, y);
6283 then state.x <- panbound (state.x + dx);
6285 gotoy_and_clear_text y
6288 state.mstate
<- Msel
(a, (x, y));
6289 G.postRedisplay "motion select";
6292 let y = min
state.winh
(max
0 y) in
6296 let x = min
state.winw (max
0 x) in
6299 | Mzoomrect
(p0
, _) ->
6300 state.mstate
<- Mzoomrect
(p0
, (x, y));
6301 G.postRedisplay "motion zoomrect";
6305 method pmotion x y =
6306 begin match state.mode with
6307 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6308 let rec loop = function
6310 if hooverpageno
!= -1
6312 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6313 G.postRedisplay "pmotion birdseye no hoover";
6316 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6317 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6319 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6320 G.postRedisplay "pmotion birdseye hoover";
6330 match state.mstate
with
6331 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6338 let past, _, _ = !r in
6340 let delta = now -. past in
6343 else r := (now, x, y)
6347 method infochanged
_ = ()
6350 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6353 then 0.0, float state.winh
6354 else scrollph state.y maxy
6359 let winw = wadjsb state.winw in
6360 let fwinw = float winw in
6362 let sw = fwinw /. float state.w in
6363 let sw = fwinw *. sw in
6364 max
sw (float conf.scrollh
)
6367 let maxx = state.w + winw in
6368 let x = winw - state.x in
6369 let percent = float x /. float maxx in
6370 (fwinw -. sw) *. percent
6372 hscrollh (), position, sw
6376 match state.mode with
6377 | LinkNav
_ -> "links"
6378 | Textentry
_ -> "textentry"
6379 | Birdseye
_ -> "birdseye"
6382 findkeyhash conf modename
6384 method eformsgs
= true
6391 let fontpath = ref "";;
6394 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6397 let l = String.length
s in
6398 let b = Buffer.create
l in
6404 try Sys.getenv
"HOME"
6407 ("Can not determine home directory location: " ^ exntos exn
);
6411 let modifier_of_string = function
6412 | "alt" -> Wsi.altmask
6413 | "shift" -> Wsi.shiftmask
6414 | "ctrl" | "control" -> Wsi.ctrlmask
6415 | "meta" -> Wsi.metamask
6420 let r = Str.regexp
"-" in
6422 let elems = Str.full_split
r s in
6425 let m1 = modifier_of_string s in
6427 then (Wsi.namekey
s, m)
6430 | Str.Delim
s when n land 1 = 0 -> g s
6432 | Str.Delim
_ -> (k
, m)
6434 let rec loop n k
m = function
6437 let k, m = f n k m x in
6443 let keys_of_string =
6444 let r = Str.regexp
"[ \t]" in
6446 let elems = Str.split
r s in
6447 List.map
key_of_string elems
6450 let copykeyhashes c =
6451 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6454 let config_of c attrs
=
6458 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6459 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6460 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6461 | "preload" -> { c with preload = bool_of_string
v }
6462 | "page-bias" -> { c with pagebias
= int_of_string
v }
6463 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6464 | "horizontal-scroll-step" ->
6465 { c with hscrollstep
= max
(int_of_string
v) 1 }
6466 | "auto-scroll-step" ->
6467 { c with autoscrollstep
= max
0 (int_of_string
v) }
6468 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6469 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6472 match String.lowercase
v with
6473 | "true" -> Some infinity
6475 | f -> Some
(float_of_string
f)
6477 { c with maxwait
= mw}
6478 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6479 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6480 | "vertical-margin" ->
6481 { c with interpagespace
= max
0 (int_of_string
v) }
6483 let zoom = float_of_string
v /. 100. in
6484 let zoom = max
zoom 0.0 in
6485 { c with zoom = zoom }
6486 | "presentation" -> { c with presentation
= bool_of_string
v }
6487 | "rotation-angle" -> { c with angle
= int_of_string
v }
6488 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6489 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6490 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6491 | "proportional-display" ->
6494 then FitProportional
6497 { c with fitmodel
= fm }
6498 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6499 | "pixmap-cache-size" ->
6500 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6501 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6502 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6503 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6504 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6505 | "background-color" -> { c with bgcolor
= color_of_string v }
6506 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6507 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6508 | "mupdf-store-size" ->
6509 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6510 | "checkers" -> { c with checkers
= bool_of_string
v }
6511 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6512 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6513 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6514 | "uri-launcher" -> { c with urilauncher
= unent v }
6515 | "path-launcher" -> { c with pathlauncher
= unent v }
6516 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6517 | "invert-colors" -> { c with invert
= bool_of_string
v }
6518 | "brightness" -> { c with colorscale
= float_of_string
v }
6519 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6521 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6523 let (n, _, _) as nab
= multicolumns_of_string v in
6525 then { c with columns
= Csplit
(-n, [||]) }
6526 else { c with columns
= Cmulti
(nab
, [||]) }
6527 | "birds-eye-columns" ->
6528 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6529 | "selection-command" -> { c with selcmd
= unent v }
6530 | "synctex-command" -> { c with stcmd
= unent v }
6531 | "pax-command" -> { c with paxcmd
= unent v }
6532 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6533 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6534 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6535 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6536 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6537 | "horizontal-scrollbar-visible" ->
6540 then c.scrollb
lor scrollbhv
6541 else c.scrollb
land (lnot
scrollbhv)
6543 { c with scrollb
= b }
6544 | "vertical-scrollbar-visible" ->
6547 then c.scrollb
lor scrollbvv
6548 else c.scrollb
land (lnot
scrollbvv)
6550 { c with scrollb
= b }
6551 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6555 then Some
(ref (0.0, 0, 0))
6557 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6560 prerr_endline
("Error processing attribute (`" ^
6561 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6564 let rec fold c = function
6567 let c = apply c k v in
6570 fold { c with keyhashes
= copykeyhashes c } attrs
;
6573 let fromstring f pos
n v d =
6576 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6577 n v pos
(exntos exn
)
6582 let bookmark_of attrs
=
6583 let rec fold title page
rely visy
= function
6584 | ("title", v) :: rest
-> fold v page
rely visy rest
6585 | ("page", v) :: rest
-> fold title v rely visy rest
6586 | ("rely", v) :: rest
-> fold title page
v visy rest
6587 | ("visy", v) :: rest
-> fold title page
rely v rest
6588 | _ :: rest
-> fold title page
rely visy rest
6589 | [] -> title, page
, rely, visy
6591 fold "invalid" "0" "0" "0" attrs
6595 let rec fold path page
rely pan visy
= function
6596 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6597 | ("page", v) :: rest
-> fold path v rely pan visy rest
6598 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6599 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6600 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6601 | _ :: rest
-> fold path page
rely pan visy rest
6602 | [] -> path, page
, rely, pan
, visy
6604 fold "" "0" "0" "0" "0" attrs
6608 let rec fold rs ls
= function
6609 | ("out", v) :: rest
-> fold v ls rest
6610 | ("in", v) :: rest
-> fold rs
v rest
6611 | _ :: rest
-> fold ls rs rest
6617 let setconf dst
src =
6618 dst
.scrollbw
<- src.scrollbw
;
6619 dst
.scrollh
<- src.scrollh
;
6620 dst
.icase
<- src.icase
;
6621 dst
.preload <- src.preload;
6622 dst
.pagebias
<- src.pagebias
;
6623 dst
.verbose
<- src.verbose
;
6624 dst
.scrollstep
<- src.scrollstep
;
6625 dst
.maxhfit
<- src.maxhfit
;
6626 dst
.crophack
<- src.crophack
;
6627 dst
.autoscrollstep
<- src.autoscrollstep
;
6628 dst
.maxwait
<- src.maxwait
;
6629 dst
.hlinks
<- src.hlinks
;
6630 dst
.underinfo
<- src.underinfo
;
6631 dst
.interpagespace
<- src.interpagespace
;
6632 dst
.zoom <- src.zoom;
6633 dst
.presentation
<- src.presentation
;
6634 dst
.angle
<- src.angle
;
6635 dst
.cwinw
<- src.cwinw
;
6636 dst
.cwinh
<- src.cwinh
;
6637 dst
.savebmarks
<- src.savebmarks
;
6638 dst
.memlimit
<- src.memlimit
;
6639 dst
.fitmodel
<- src.fitmodel
;
6640 dst
.texcount
<- src.texcount
;
6641 dst
.sliceheight
<- src.sliceheight
;
6642 dst
.thumbw
<- src.thumbw
;
6643 dst
.jumpback
<- src.jumpback
;
6644 dst
.bgcolor
<- src.bgcolor
;
6645 dst
.tilew
<- src.tilew
;
6646 dst
.tileh
<- src.tileh
;
6647 dst
.mustoresize
<- src.mustoresize
;
6648 dst
.checkers
<- src.checkers
;
6649 dst
.aalevel
<- src.aalevel
;
6650 dst
.trimmargins
<- src.trimmargins
;
6651 dst
.trimfuzz
<- src.trimfuzz
;
6652 dst
.urilauncher
<- src.urilauncher
;
6653 dst
.colorspace
<- src.colorspace
;
6654 dst
.invert
<- src.invert
;
6655 dst
.colorscale
<- src.colorscale
;
6656 dst
.redirectstderr <- src.redirectstderr;
6657 dst
.ghyllscroll
<- src.ghyllscroll
;
6658 dst
.columns
<- src.columns
;
6659 dst
.beyecolumns
<- src.beyecolumns
;
6660 dst
.selcmd
<- src.selcmd
;
6661 dst
.updatecurs
<- src.updatecurs
;
6662 dst
.pathlauncher
<- src.pathlauncher
;
6663 dst
.keyhashes
<- copykeyhashes src;
6664 dst
.hfsize
<- src.hfsize
;
6665 dst
.hscrollstep
<- src.hscrollstep
;
6666 dst
.pgscale <- src.pgscale;
6667 dst
.usepbo
<- src.usepbo
;
6668 dst
.wheelbypage
<- src.wheelbypage
;
6669 dst
.stcmd
<- src.stcmd
;
6670 dst
.paxcmd
<- src.paxcmd
;
6671 dst
.scrollb
<- src.scrollb
;
6672 dst
.riani
<- src.riani
;
6673 dst
.paxmark
<- src.paxmark
;
6677 else Some
((ref (0.0, 0, 0)));
6681 let h = Hashtbl.create
10 in
6682 let dc = { defconf with angle
= defconf.angle
} in
6683 let rec toplevel v t spos
_ =
6685 | Vdata
| Vcdata
| Vend
-> v
6686 | Vopen
("llppconfig", _, closed
) ->
6689 else { v with f = llppconfig
}
6691 error
"unexpected subelement at top level" s spos
6692 | Vclose
_ -> error
"unexpected close at top level" s spos
6694 and llppconfig
v t spos
_ =
6696 | Vdata
| Vcdata
-> v
6697 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6698 | Vopen
("defaults", attrs
, closed
) ->
6699 let c = config_of dc attrs
in
6703 else { v with f = defaults
}
6705 | Vopen
("ui-font", attrs
, closed
) ->
6706 let rec getsize size
= function
6708 | ("size", v) :: rest
->
6710 fromstring int_of_string spos
"size" v fstate.fontsize
in
6712 | l -> getsize size l
6714 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6717 else { v with f = uifont
(Buffer.create
10) }
6719 | Vopen
("doc", attrs
, closed
) ->
6720 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6721 let path = unent pathent
6722 and pageno = fromstring int_of_string spos
"page" spage
0
6723 and rely = fromstring float_of_string spos
"rely" srely
0.0
6724 and pan
= fromstring int_of_string spos
"pan" span
0
6725 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6726 let c = config_of dc attrs
in
6727 let anchor = (pageno, rely, visy
) in
6729 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6730 else { v with f = doc
path pan
anchor c [] }
6733 error
"unexpected subelement in llppconfig" s spos
6735 | Vclose
"llppconfig" -> { v with f = toplevel }
6736 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6738 and defaults
v t spos
_ =
6740 | Vdata
| Vcdata
-> v
6741 | Vend
-> error
"unexpected end of input in defaults" s spos
6742 | Vopen
("keymap", attrs
, closed
) ->
6744 try List.assoc
"mode" attrs
6745 with Not_found
-> "global" in
6750 let h = findkeyhash dc modename in
6751 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6754 { v with f = pkeymap
ret KeyMap.empty }
6756 | Vopen
(_, _, _) ->
6757 error
"unexpected subelement in defaults" s spos
6759 | Vclose
"defaults" ->
6760 { v with f = llppconfig
}
6762 | Vclose
_ -> error
"unexpected close in defaults" s spos
6764 and uifont
b v t spos
epos =
6767 Buffer.add_substring
b s spos
(epos - spos
);
6769 | Vopen
(_, _, _) ->
6770 error
"unexpected subelement in ui-font" s spos
6771 | Vclose
"ui-font" ->
6772 if String.length
!fontpath = 0
6773 then fontpath := Buffer.contents
b;
6774 { v with f = llppconfig
}
6775 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6776 | Vend
-> error
"unexpected end of input in ui-font" s spos
6778 and doc
path pan
anchor c bookmarks
v t spos
_ =
6780 | Vdata
| Vcdata
-> v
6781 | Vend
-> error
"unexpected end of input in doc" s spos
6782 | Vopen
("bookmarks", _, closed
) ->
6785 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6787 | Vopen
("keymap", attrs
, closed
) ->
6789 try List.assoc
"mode" attrs
6790 with Not_found
-> "global"
6796 let h = findkeyhash c modename in
6797 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6798 doc
path pan
anchor c bookmarks
6800 { v with f = pkeymap
ret KeyMap.empty }
6802 | Vopen
(_, _, _) ->
6803 error
"unexpected subelement in doc" s spos
6806 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6807 { v with f = llppconfig
}
6809 | Vclose
_ -> error
"unexpected close in doc" s spos
6811 and pkeymap
ret keymap
v t spos
_ =
6813 | Vdata
| Vcdata
-> v
6814 | Vend
-> error
"unexpected end of input in keymap" s spos
6815 | Vopen
("map", attrs
, closed
) ->
6816 let r, l = map_of attrs
in
6817 let kss = fromstring keys_of_string spos
"in" r [] in
6818 let lss = fromstring keys_of_string spos
"out" l [] in
6822 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6823 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6826 then { v with f = pkeymap
ret keymap }
6829 { v with f = skip
"map" f }
6832 error
"unexpected subelement in keymap" s spos
6834 | Vclose
"keymap" ->
6835 { v with f = ret keymap }
6837 | Vclose
_ -> error
"unexpected close in keymap" s spos
6839 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6841 | Vdata
| Vcdata
-> v
6842 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6843 | Vopen
("item", attrs
, closed
) ->
6844 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6845 let page = fromstring int_of_string spos
"page" spage
0
6846 and rely = fromstring float_of_string spos
"rely" srely
0.0
6847 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6849 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6852 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6855 { v with f = skip
"item" f }
6858 error
"unexpected subelement in bookmarks" s spos
6860 | Vclose
"bookmarks" ->
6861 { v with f = doc
path pan
anchor c bookmarks }
6863 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6865 and skip tag
f v t spos
_ =
6867 | Vdata
| Vcdata
-> v
6869 error
("unexpected end of input in skipped " ^ tag
) s spos
6870 | Vopen
(tag'
, _, closed
) ->
6874 let f'
() = { v with f = skip tag
f } in
6875 { v with f = skip tag'
f'
}
6879 else error
("unexpected close in skipped " ^ tag
) s spos
6882 parse
{ f = toplevel; accu = () } s;
6888 let len = in_channel_length ic
in
6889 let s = String.create
len in
6890 really_input ic
s 0 len;
6893 | Parse_error
(msg
, s, pos
) ->
6894 let subs = subs s pos
in
6895 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6896 failwith
("parse error: " ^
s)
6899 failwith
("config load error: " ^ exntos exn
)
6905 let dir = Filename.concat
home ".config" in
6906 if Sys.is_directory
dir then dir else home
6909 Filename.concat
dir "llpp.conf"
6912 let confpath = ref defconfpath;;
6915 if Sys.file_exists
!confpath
6918 (try Some
(open_in_bin
!confpath)
6921 ("Error opening configuration file `" ^
!confpath ^
"': " ^
6932 ("Error loading configuration from `" ^
!confpath ^
"': " ^
6941 f (Hashtbl.create
0, defconf)
6946 let pc, pb
, px, pa
=
6949 if String.length
state.origin
= 0
6953 Hashtbl.find h (Filename.basename
key)
6954 with Not_found
-> dc, [], 0, emptyanchor
6958 state.bookmarks <- pb
;
6961 then state.anchor <- pa
;
6962 cbput state.hists
.nav pa
;
6968 let add_attrs bb always
dc c =
6971 then Printf.bprintf bb
"\n %s='%b'" s a
6974 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
6977 then Printf.bprintf bb
"\n %s='%d'" s a
6980 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6983 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6986 then Printf.bprintf bb
"\n %s='%f'" s a
6990 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6994 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
6998 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7002 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7008 | Some
(_N
, _A
, _B
) ->
7009 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7019 else string_of_float
f
7021 Printf.bprintf bb
"\n %s='%s'" s v
7026 | Cmulti
((n, a, b), _) when n > 1 ->
7027 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7028 | Csplit
(n, _) when n > 1 ->
7029 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7035 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7040 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7044 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7048 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7050 oi
"width" c.cwinw
dc.cwinw
;
7051 oi
"height" c.cwinh
dc.cwinh
;
7052 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7053 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7054 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7055 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7056 ob "case-insensitive-search" c.icase
dc.icase
;
7057 ob "preload" c.preload dc.preload;
7058 oi
"page-bias" c.pagebias
dc.pagebias
;
7059 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7060 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7061 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7062 ob "crop-hack" c.crophack
dc.crophack
;
7063 oW
"throttle" c.maxwait
dc.maxwait
;
7064 ob "highlight-links" c.hlinks
dc.hlinks
;
7065 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7066 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7067 oz
"zoom" c.zoom dc.zoom;
7068 ob "presentation" c.presentation
dc.presentation
;
7069 oi
"rotation-angle" c.angle
dc.angle
;
7070 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7071 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7072 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7073 oi
"tex-count" c.texcount
dc.texcount
;
7074 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7075 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7076 ob "persistent-location" c.jumpback
dc.jumpback
;
7077 oc
"background-color" c.bgcolor
dc.bgcolor
;
7078 oi
"tile-width" c.tilew
dc.tilew
;
7079 oi
"tile-height" c.tileh
dc.tileh
;
7080 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7081 ob "checkers" c.checkers
dc.checkers
;
7082 oi
"aalevel" c.aalevel
dc.aalevel
;
7083 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7084 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7085 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7086 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7087 oC
"color-space" c.colorspace
dc.colorspace
;
7088 ob "invert-colors" c.invert
dc.invert
;
7089 oF
"brightness" c.colorscale
dc.colorscale
;
7090 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7091 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7092 oco
"columns" c.columns
dc.columns
;
7093 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7094 os
"selection-command" c.selcmd
dc.selcmd
;
7095 os
"synctex-command" c.stcmd
dc.stcmd
;
7096 os
"pax-command" c.paxcmd
dc.paxcmd
;
7097 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7098 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7099 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7100 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7101 ob "use-pbo" c.usepbo
dc.usepbo
;
7102 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7103 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7104 op
"point-and-x" c.pax
dc.pax
;
7105 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7108 let keymapsbuf always
dc c =
7109 let bb = Buffer.create
16 in
7110 let rec loop = function
7112 | (modename, h) :: rest
->
7113 let dh = findkeyhash dc modename in
7114 if always
|| h <> dh
7116 if Hashtbl.length
h > 0
7118 if Buffer.length
bb > 0
7119 then Buffer.add_char
bb '
\n'
;
7120 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7121 Hashtbl.iter
(fun i
o ->
7122 let isdifferent = always
||
7124 let dO = Hashtbl.find dh i
in
7126 with Not_found
-> true
7131 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7132 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7133 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7134 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7135 Buffer.add_string
bb (Wsi.keyname
k);
7138 let rec loop = function
7140 | km
:: [] -> addkm km
7141 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7145 Buffer.add_string
bb "<map in='";
7149 Buffer.add_string
bb "' out='";
7151 Buffer.add_string
bb "'/>\n"
7154 Buffer.add_string
bb "' out='";
7156 Buffer.add_string
bb "'/>\n"
7158 | KMmulti
(ins, kms
) ->
7159 Buffer.add_char
bb ' '
;
7161 Buffer.add_string
bb "' out='";
7163 Buffer.add_string
bb "'/>\n"
7165 Buffer.add_string
bb "</keymap>";
7175 let uifontsize = fstate.fontsize
in
7176 let bb = Buffer.create
32768 in
7177 let relx = float state.x /. float state.winw in
7179 let cx w = truncate
(relx *. float w) in
7181 (fun (w, h, x) ws
->
7183 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7184 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7185 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7187 (state.winw, state.winh
, state.x) state.winstate
7192 let dc = if conf.bedefault
then conf else dc in
7193 Buffer.add_string
bb "<llppconfig>\n";
7195 if String.length
!fontpath > 0
7197 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7203 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7206 Buffer.add_string
bb "<defaults ";
7207 add_attrs bb true dc dc;
7208 let kb = keymapsbuf true dc dc in
7209 if Buffer.length
kb > 0
7211 Buffer.add_string
bb ">\n";
7212 Buffer.add_buffer
bb kb;
7213 Buffer.add_string
bb "\n</defaults>\n";
7215 else Buffer.add_string
bb "/>\n";
7217 let adddoc path pan
anchor c bookmarks =
7218 if bookmarks == [] && c = dc && anchor = emptyanchor
7221 Printf.bprintf
bb "<doc path='%s'"
7222 (enent
path 0 (String.length
path));
7224 if anchor <> emptyanchor
7226 let n, rely, visy
= anchor in
7227 Printf.bprintf
bb " page='%d'" n;
7230 Printf.bprintf
bb " rely='%f'" rely
7232 if abs_float visy
> 1e-6
7234 Printf.bprintf
bb " visy='%f'" visy
7239 then Printf.bprintf
bb " pan='%d'" pan
;
7241 add_attrs bb false dc c;
7242 let kb = keymapsbuf false dc c in
7244 begin match bookmarks with
7246 if Buffer.length
kb > 0
7248 Buffer.add_string
bb ">\n";
7249 Buffer.add_buffer
bb kb;
7250 Buffer.add_string
bb "\n</doc>\n";
7252 else Buffer.add_string
bb "/>\n"
7254 Buffer.add_string
bb ">\n<bookmarks>\n";
7255 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7257 "<item title='%s' page='%d'"
7258 (enent
title 0 (String.length
title))
7263 Printf.bprintf
bb " rely='%f'" rely
7265 if abs_float visy
> 1e-6
7267 Printf.bprintf
bb " visy='%f'" visy
7269 Buffer.add_string
bb "/>\n";
7271 Buffer.add_string
bb "</bookmarks>";
7272 if Buffer.length
kb > 0
7274 Buffer.add_string
bb "\n";
7275 Buffer.add_buffer
bb kb;
7277 Buffer.add_string
bb "\n</doc>\n";
7283 match state.mode with
7284 | Birdseye
(c, pan, _, _, _) ->
7286 match conf.columns
with
7287 | Cmulti
((c, _, _), _) -> Some
c
7291 match c.columns
with
7292 | Cmulti
(c, _) -> Cmulti
(c, [||])
7293 | Csingle
_ -> Csingle
[||]
7294 | Csplit
_ -> failwith
"quit from bird's eye while split"
7296 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7299 let basename = Filename.basename
7300 (if String.length
state.origin
= 0 then state.path else state.origin
)
7302 adddoc basename pan (getanchor ())
7304 let autoscrollstep =
7305 match state.autoscroll
with
7307 | None
-> conf.autoscrollstep
7309 match state.mode with
7310 | Birdseye
(bc
, _, _, _, _) ->
7313 presentation
= bc
.presentation
;
7314 interpagespace
= bc
.interpagespace
;
7315 maxwait
= bc
.maxwait
;
7316 autoscrollstep = autoscrollstep }
7317 | _ -> { conf with autoscrollstep = autoscrollstep }
7319 (if conf.savebmarks
then state.bookmarks else []);
7321 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7323 then adddoc path x anchor c bookmarks
7325 Buffer.add_string
bb "</llppconfig>\n";
7328 if load1 f && Buffer.length
bb > 0
7331 let tmp = !confpath ^
".tmp" in
7332 let oc = open_out_bin
tmp in
7333 Buffer.output_buffer
oc bb;
7335 Unix.rename
tmp !confpath;
7338 ("error while saving configuration: " ^ exntos exn
)
7342 let adderrmsg src msg
=
7343 Buffer.add_string
state.errmsgs msg
;
7344 state.newerrmsgs
<- true;
7348 let adderrfmt src fmt
=
7349 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7353 let cl = splitatspace cmds
in
7355 try Scanf.sscanf
s fmt
f
7357 adderrfmt "remote exec"
7358 "error processing '%S': %s\n" cmds
(exntos exn
)
7361 | "reload" :: [] -> reload ()
7362 | "goto" :: args :: [] ->
7363 scan args "%u %f %f"
7365 let cmd, _ = state.geomcmds
in
7366 if String.length
cmd = 0
7367 then gotopagexy pageno x y
7370 gotopagexy pageno x y;
7373 state.reprf
<- f state.reprf
7375 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7376 | "rect" :: args :: [] ->
7377 scan args "%u %u %f %f %f %f"
7378 (fun pageno color x0 y0 x1 y1 ->
7379 onpagerect pageno (fun w h ->
7380 let _,w1,h1
,_ = getpagedim pageno in
7381 let sw = float w1 /. w
7382 and sh = float h1
/. h in
7386 and y1s
= y1 *. sh in
7387 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7389 state.rects <- (pageno, color, rect) :: state.rects;
7390 G.postRedisplay "rect";
7393 | "activatewin" :: [] -> Wsi.activatewin
()
7394 | "quit" :: [] -> raise Quit
7396 adderrfmt "remote command"
7397 "error processing remote command: %S\n" cmds
;
7401 let scratch = String.create
80 in
7402 let buf = Buffer.create
80 in
7405 try Some
(Unix.read fd
scratch 0 80)
7407 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7408 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7411 match tempfr () with
7417 if Buffer.length
buf > 0
7419 let s = Buffer.contents
buf in
7429 let pos = String.index_from
scratch ppos '
\n'
in
7430 if pos >= n then -1 else pos
7431 with Not_found
-> -1
7435 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7436 let s = Buffer.contents
buf in
7442 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7448 let remoteopen path =
7449 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7451 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7456 let trimcachepath = ref "" in
7457 let rcmdpath = ref "" in
7458 selfexec := Sys.executable_name
;
7461 [("-p", Arg.String
(fun s -> state.password
<- s),
7462 "<password> Set password");
7466 Config.fontpath := s;
7467 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7469 "<path> Set path to the user interface font");
7473 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7474 Config.confpath := s),
7475 "<path> Set path to the configuration file");
7477 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7478 "<path> Set path to the trim cache file");
7480 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7481 "<named-destination> Set named destination");
7483 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7485 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7486 "<path> Set path to the remote commands source");
7488 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7489 "<original-path> Set original path");
7491 ("-v", Arg.Unit
(fun () ->
7493 "%s\nconfiguration path: %s\n"
7497 exit
0), " Print version and exit");
7500 (fun s -> state.path <- s)
7501 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7504 then selfexec := !selfexec ^
" -wtmode";
7506 if String.length
state.path = 0
7507 then (prerr_endline
"file name missing"; exit
1);
7509 if not
(Config.load ())
7510 then prerr_endline
"failed to load configuration";
7512 let wsfd, winw, winh
= Wsi.init
(object
7513 val mutable m_hack
= false
7514 method expose
= if not m_hack
then G.postRedisplay "expose"
7515 method visible
= G.postRedisplay "visible"
7516 method display = m_hack
<- false; display ()
7517 method reshape w h =
7518 m_hack
<- w < state.winw && h < state.winh
;
7520 method mouse b d x y m = mouse b d x y m
7521 method motion x y = state.mpos
<- (x, y); motion x y
7522 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7524 let mascm = m land (
7525 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7527 match state.keystate
with
7529 let km = k, mascm in
7532 let modehash = state.uioh#
modehash in
7533 try Hashtbl.find modehash km
7535 try Hashtbl.find (findkeyhash conf "global") km
7536 with Not_found
-> KMinsrt
(k, m)
7538 | KMinsrt
(k, m) -> keyboard k m
7539 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7540 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7542 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7543 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7544 state.keystate
<- KSnone
7545 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7546 state.keystate
<- KSinto
(keys
, insrt
)
7548 state.keystate
<- KSnone
7550 method enter
x y = state.mpos
<- (x, y); pmotion x y
7551 method leave = state.mpos
<- (-1, -1)
7552 method winstate wsl
= state.winstate
<- wsl
7553 method quit
= raise Quit
7554 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7559 List.exists
GlMisc.check_extension
7560 [ "GL_ARB_texture_rectangle"
7561 ; "GL_EXT_texture_recangle"
7562 ; "GL_NV_texture_rectangle" ]
7564 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7567 let r = GlMisc.get_string `renderer
in
7568 let p = "Mesa DRI Intel(" in
7569 let l = String.length
p in
7570 String.length
r > l && String.sub
r 0 l = p
7572 then defconf.sliceheight
<- 1024;
7575 match Ne.pipe () with
7577 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7581 match Ne.pipe () with
7583 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7593 setcheckers conf.checkers
;
7597 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7598 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7599 !Config.fontpath, !trimcachepath,
7600 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7604 state.text <- "Opening " ^
(mbtoutf8
state.path);
7606 opendoc state.path state.password
;
7610 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7613 if String.length
!rcmdpath > 0
7614 then remoteopen !rcmdpath
7619 let rec loop deadline
=
7621 match state.errfd
with
7622 | None
-> [state.sr
; state.wsfd]
7623 | Some fd
-> [state.sr
; state.wsfd; fd
]
7628 | Some fd
-> fd
:: r
7632 state.redisplay
<- false;
7639 if deadline
= infinity
7641 else max
0.0 (deadline
-. now)
7646 try Unix.select
r [] [] timeout
7647 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7653 if state.ghyll
== noghyll
7655 match state.autoscroll
with
7656 | Some step
when step
!= 0 ->
7657 let y = state.y + step
in
7661 else if y >= state.maxy then 0 else y
7664 if state.mode = View
7665 then state.text <- "";
7668 else deadline
+. 0.01
7673 let rec checkfds = function
7675 | fd
:: rest
when fd
= state.sr
->
7676 let cmd = readcmd state.sr
in
7680 | fd
:: rest
when fd
= state.wsfd ->
7684 | fd
:: rest
when Some fd
= !optrfd ->
7685 begin match remote fd
with
7686 | None
-> optrfd := remoteopen !rcmdpath;
7687 | opt -> optrfd := opt
7692 let s = String.create
80 in
7693 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7694 if conf.redirectstderr
7696 Buffer.add_substring
state.errmsgs
s 0 n;
7697 state.newerrmsgs
<- true;
7698 state.redisplay
<- true;
7701 prerr_string
(String.sub
s 0 n);
7709 if deadline
= infinity
7713 match state.autoscroll
with
7714 | Some step
when step
!= 0 -> deadline1
7715 | _ -> if state.ghyll
== noghyll then infinity
else deadline1