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";;
123 external rectofblock
: opaque
-> int -> int -> float array
option
126 let platform_to_string = function
127 | Punknown
-> "unknown"
131 | Pfreebsd
-> "FreeBSD"
132 | Pdragonflybsd
-> "DragonflyBSD"
133 | Popenbsd
-> "OpenBSD"
134 | Pnetbsd
-> "NetBSD"
135 | Pcygwin
-> "Cygwin"
138 let platform = platform ();;
140 let now = Unix.gettimeofday
;;
142 let selfexec = ref "";;
145 if platform = Pcygwin
147 let sh = "/bin/sh" in
148 let args = [|sh; "-c"; cmd
|] in
149 let rec std si so se
= function
151 | (fd
, 0) :: rest
-> std fd so se rest
152 | (fd
, -1) :: rest
->
153 Unix.set_close_on_exec fd
;
156 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
158 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
159 ignore
(Unix.create_process
sh args si so se
)
164 type mpos
= int * int
166 | Msel
of (mpos
* mpos
)
168 | Mscrolly
| Mscrollx
169 | Mzoom
of (int * int)
170 | Mzoomrect
of (mpos
* mpos
)
174 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
175 and onkey
= string -> int -> te
176 and ondone
= string -> unit
177 and histcancel
= unit -> unit
178 and onhist
= ((histcmd
-> string) * histcancel
)
179 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
180 and cancelonempty
= bool
185 | TEswitch
of textentry
196 let bound v minv maxv
=
197 max minv
(min maxv v
);
201 { store
= Array.create n v
208 let cbcap b
= Array.length b
.store
;;
213 b
.wc
<- (b
.wc
+ 1) mod cap;
215 b
.len
<- min
(b
.len
+ 1) cap;
218 let cbempty b
= b
.len
= 0;;
220 let cbgetg b circular dir
=
224 let rc = b
.rc + dir
in
236 else bound rc 0 (b
.len
-1)
242 let cbget b
= cbgetg b
false;;
243 let cbgetc b
= cbgetg b
true;;
245 let drawstring size x y s
=
247 Gl.enable `texture_2d
;
248 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
249 ignore
(drawstr size x y s
);
251 Gl.disable `texture_2d
;
254 let drawstring1 size x y s
=
258 let drawstring2 size x y fmt
=
259 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
278 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
279 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
280 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
281 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
282 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
283 dolog
" column %d" l
.pagecol
;
287 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
289 dolog
" x0,y0=(% f, % f)" x0 y0
;
290 dolog
" x1,y1=(% f, % f)" x1 y1
;
291 dolog
" x2,y2=(% f, % f)" x2 y2
;
292 dolog
" x3,y3=(% f, % f)" x3 y3
;
296 type multicolumns
= multicol
* pagegeom
297 and singlecolumn
= pagegeom
298 and splitcolumns
= columncount
* pagegeom
299 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
300 and multicol
= columncount
* covercount
* covercount
302 and columncount
= int
303 and covercount
= int;;
310 { mutable scrollbw
: int
311 ; mutable scrollh
: int
312 ; mutable scrollb
: scrollb
313 ; mutable icase
: bool
314 ; mutable preload
: bool
315 ; mutable pagebias
: int
316 ; mutable verbose
: bool
317 ; mutable debug
: bool
318 ; mutable scrollstep
: int
319 ; mutable hscrollstep
: int
320 ; mutable maxhfit
: bool
321 ; mutable crophack
: bool
322 ; mutable autoscrollstep
: int
323 ; mutable maxwait
: float option
324 ; mutable hlinks
: bool
325 ; mutable underinfo
: bool
326 ; mutable interpagespace
: interpagespace
327 ; mutable zoom
: float
328 ; mutable presentation
: bool
329 ; mutable angle
: angle
330 ; mutable cwinw
: int
331 ; mutable cwinh
: int
332 ; mutable savebmarks
: bool
333 ; mutable fitmodel
: fitmodel
334 ; mutable trimmargins
: trimmargins
335 ; mutable trimfuzz
: irect
336 ; mutable memlimit
: memsize
337 ; mutable texcount
: texcount
338 ; mutable sliceheight
: sliceheight
339 ; mutable thumbw
: width
340 ; mutable jumpback
: bool
341 ; mutable bgcolor
: (float * float * float)
342 ; mutable bedefault
: bool
343 ; mutable tilew
: int
344 ; mutable tileh
: int
345 ; mutable mustoresize
: memsize
346 ; mutable checkers
: bool
347 ; mutable aalevel
: int
348 ; mutable urilauncher
: string
349 ; mutable pathlauncher
: string
350 ; mutable colorspace
: colorspace
351 ; mutable invert
: bool
352 ; mutable colorscale
: float
353 ; mutable redirectstderr
: bool
354 ; mutable ghyllscroll
: (int * int * int) option
355 ; mutable columns
: columns
356 ; mutable beyecolumns
: columncount
option
357 ; mutable selcmd
: string
358 ; mutable paxcmd
: string
359 ; mutable updatecurs
: bool
360 ; mutable keyhashes
: (string * keyhash
) list
361 ; mutable hfsize
: int
362 ; mutable pgscale
: float
363 ; mutable usepbo
: bool
364 ; mutable wheelbypage
: bool
365 ; mutable stcmd
: string
366 ; mutable riani
: bool
367 ; mutable pax
: (float * int * int) ref option
368 ; mutable paxmark
: mark
371 | Csingle
of singlecolumn
372 | Cmulti
of multicolumns
373 | Csplit
of splitcolumns
376 type anchor
= pageno
* top
* dtop
;;
378 type outline
= string * int * anchor
;;
380 type rect
= float * float * float * float * float * float * float * float;;
382 type tile
= opaque
* pixmapsize
* elapsed
383 and elapsed
= float;;
384 type pagemapkey
= pageno
* gen
;;
385 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
389 let emptyanchor = (0, 0.0, 0.0);;
391 type infochange
= | Memused
| Docinfo
| Pdim
;;
393 class type uioh
= object
394 method display
: unit
395 method key
: int -> int -> uioh
396 method button
: int -> bool -> int -> int -> int -> uioh
397 method motion
: int -> int -> uioh
398 method pmotion
: int -> int -> uioh
399 method infochanged
: infochange
-> unit
400 method scrollpw
: (int * float * float)
401 method scrollph
: (int * float * float)
402 method modehash
: keyhash
403 method eformsgs
: bool
407 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
408 | Textentry
of (textentry
* onleave
)
410 | LinkNav
of linktarget
411 and onleave
= leavetextentrystatus
-> unit
412 and leavetextentrystatus
= | Cancel
| Confirm
413 and helpitem
= string * int * action
416 | Action
of (uioh
-> uioh
)
418 | Ltexact
of (pageno
* int)
422 let isbirdseye = function Birdseye _
-> true | _
-> false;;
423 let istextentry = function Textentry _
-> true | _
-> false;;
427 | Loading
of (page
* gen
)
429 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
431 | Outlining
of outline list
434 let emptykeyhash = Hashtbl.create
0;;
435 let nouioh : uioh
= object (self
)
437 method key _ _
= self
438 method button _ _ _ _ _
= self
439 method motion _ _
= self
440 method pmotion _ _
= self
441 method infochanged _
= ()
442 method scrollpw
= (0, nan
, nan
)
443 method scrollph
= (0, nan
, nan
)
444 method modehash
= emptykeyhash
445 method eformsgs
= false
449 { mutable sr
: Unix.file_descr
450 ; mutable sw
: Unix.file_descr
451 ; mutable wsfd
: Unix.file_descr
452 ; mutable errfd
: Unix.file_descr
option
453 ; mutable stderr
: Unix.file_descr
454 ; mutable errmsgs
: Buffer.t
455 ; mutable newerrmsgs
: bool
459 ; mutable anchor
: anchor
460 ; mutable ranchors
: (string * string * anchor
* string) list
462 ; mutable layout
: page list
463 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
464 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
465 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
466 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
467 ; mutable pagecount
: int
468 ; mutable currently
: currently
469 ; mutable mstate
: mstate
470 ; mutable searchpattern
: string
471 ; mutable rects
: (pageno
* recttype
* rect
) list
472 ; mutable rects1
: (pageno
* recttype
* rect
) list
473 ; mutable text
: string
474 ; mutable winstate
: Wsi.winstate list
475 ; mutable mode
: mode
476 ; mutable uioh
: uioh
477 ; mutable outlines
: outline array
478 ; mutable bookmarks
: outline list
479 ; mutable path
: string
480 ; mutable password
: string
481 ; mutable nameddest
: string
482 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
483 ; mutable memused
: memsize
485 ; mutable throttle
: (page list
* int * float) option
486 ; mutable autoscroll
: int option
487 ; mutable ghyll
: (int option -> unit)
488 ; mutable help
: helpitem array
489 ; mutable docinfo
: (int * string) list
490 ; mutable texid
: GlTex.texture_id
option
492 ; mutable prevzoom
: (float * int)
493 ; mutable progress
: float
494 ; mutable redisplay
: bool
495 ; mutable mpos
: mpos
496 ; mutable keystate
: keystate
497 ; mutable glinks
: bool
498 ; mutable prevcolumns
: (columns
* float) option
501 ; mutable reprf
: (unit -> unit)
502 ; mutable origin
: string
503 ; mutable roam
: (unit -> unit)
504 ; mutable bzoom
: bool
507 { pat
: string circbuf
508 ; pag
: string circbuf
509 ; nav
: anchor circbuf
510 ; sel
: string circbuf
517 ; scrollb
= scrollbhv lor scrollbvv
533 ; presentation
= false
538 ; fitmodel
= FitProportional
539 ; trimmargins
= false
540 ; trimfuzz
= (0,0,0,0)
541 ; memlimit
= 32 lsl 20
546 ; bgcolor
= (0.5, 0.5, 0.5)
550 ; mustoresize
= 256 lsl 20
555 | Plinux
| Pfreebsd
| Pdragonflybsd
556 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
557 | Posx
-> "open \"%s\""
558 | Pcygwin
-> "cygstart \"%s\""
559 | Punknown
-> "echo %s")
560 ; pathlauncher
= "lp \"%s\""
563 | Plinux
| Pfreebsd
| Pdragonflybsd
564 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
572 ; redirectstderr
= false
574 ; columns
= Csingle
[||]
580 ; wheelbypage
= false
581 ; stcmd
= "echo SyncTex"
584 ; paxmark
= Mark_word
586 let mk n
= (n
, Hashtbl.create
1) in
600 let wtmode = ref false;;
601 let cxack = ref false;;
603 let findkeyhash c name
=
604 try List.assoc name c
.keyhashes
605 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
608 let conf = { defconf with angle
= defconf.angle
};;
610 let pgscale h
= truncate
(float h
*. conf.pgscale);;
613 { mutable fontsize
: int
614 ; mutable wwidth
: float
615 ; mutable maxrows
: int
627 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
628 let len = String.length s
in
629 if colonpos >= 0 && colonpos + 3 < len
631 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
634 try String.rindex_from s
colonpos ' '
638 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
641 | "http" | "ftp" | "mailto" ->
643 try String.index_from s
colonpos ' '
644 with Not_found
-> len
646 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
654 if String.length
conf.urilauncher
= 0
655 then print_endline uri
657 let url = geturl uri
in
658 if String.length
url = 0
659 then Printf.eprintf
"obtained empty url from uri %S" uri
661 let re = Str.regexp
"%s" in
662 let command = Str.global_replace
re url conf.urilauncher
in
666 "failed to execute `%s': %s\n" command (exntos exn
);
672 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
673 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
677 let strings = version () :: "" :: Help.keys
in
680 let url = geturl s
in
681 if String.length
url > 0
682 then (s
, 0, Action
(fun u
-> gotouri url; u
))
683 else (s
, 0, Noaction
)
688 let firstgeomcmds = "", [];;
689 let noreprf () = ();;
696 ; stderr
= Unix.stderr
697 ; errmsgs
= Buffer.create
0
702 ; anchor
= emptyanchor
706 ; tilelru
= Queue.create
()
707 ; pagemap
= Hashtbl.create
10
708 ; tilemap
= Hashtbl.create
10
724 ; geomcmds
= firstgeomcmds
726 { nav
= cbnew 10 emptyanchor
739 ; prevzoom
= (1.0, 0)
751 ; roam
= (fun () -> ())
757 if (conf.scrollb
land scrollbhv = 0)
758 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
764 if (conf.scrollb
land scrollbvv = 0)
769 let wadjsb w
= w
- vscrollw ();;
772 fstate.fontsize
<- n
;
773 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
774 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
780 Printf.kprintf prerr_endline fmt
782 Printf.kprintf ignore fmt
786 if String.length
conf.pathlauncher
= 0
787 then print_endline
state.path
789 let re = Str.regexp
"%s" in
790 let command = Str.global_replace
re state.path
conf.pathlauncher
in
793 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
799 type 'a t
= | Res
of 'a
| Exn
of exn
;;
802 try Res
(Unix.pipe ())
807 try tempfailureretry
Unix.close fd
808 with exn
-> f
(exntos exn
)
812 try Res
(tempfailureretry
Unix.dup fd
)
817 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
822 let redirectstderr () =
823 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
824 if conf.redirectstderr
826 match Ne.pipe () with
828 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
831 begin match Ne.dup Unix.stderr
with
833 dolog
"failed to dup stderr: %s" (exntos exn
);
834 Ne.clo r
(clofail "pipe/r");
835 Ne.clo w
(clofail "pipe/w");
837 | Ne.Res dupstderr
->
838 begin match Ne.dup2 w
Unix.stderr
with
840 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
841 Ne.clo dupstderr
(clofail "stderr duplicate");
842 Ne.clo r
(clofail "redir pipe/r");
843 Ne.clo w
(clofail "redir pipe/w");
846 state.stderr
<- dupstderr
;
847 state.errfd
<- Some r
;
851 state.newerrmsgs
<- false;
852 begin match state.errfd
with
854 begin match Ne.dup2 state.stderr
Unix.stderr
with
856 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
858 Ne.clo fd
(clofail "dup of stderr");
863 prerr_string
(Buffer.contents
state.errmsgs
);
865 Buffer.clear
state.errmsgs
;
871 let postRedisplay who
=
873 then prerr_endline
("redisplay for " ^ who
);
874 state.redisplay
<- true;
878 let getopaque pageno
=
879 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
880 with Not_found
-> None
883 let putopaque pageno opaque
=
884 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
887 let pagetranslatepoint l x y
=
888 let dy = y
- l
.pagedispy
in
889 let y = dy + l
.pagey
in
890 let dx = x
- l
.pagedispx
in
891 let x = dx + l
.pagex
in
895 let onppundermouse g
x y d
=
898 begin match getopaque l
.pageno
with
900 let x0 = l
.pagedispx
in
901 let x1 = x0 + l
.pagevw
in
902 let y0 = l
.pagedispy
in
903 let y1 = y0 + l
.pagevh
in
904 if y >= y0 && y <= y1 && x >= x0 && x <= x1
906 let px, py
= pagetranslatepoint l
x y in
907 match g opaque l
px py
with
920 let g opaque l
px py
=
923 match rectofblock opaque
px py
with
925 let rect = (a
.(0),a
.(2),a
.(1),a
.(2),a
.(1),a
.(3),a
.(0),a
.(3)) in
926 state.rects
<- [l
.pageno
, l
.pageno
mod 3, rect];
927 G.postRedisplay "rectofblock";
930 match whatsunder opaque
px py
with
932 | under
-> Some under
934 onppundermouse g x y Unone
939 match unproject opaque
x y with
940 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
943 onppundermouse g x y None
;
947 state.text
<- Printf.sprintf
"%c%s" c s
;
948 G.postRedisplay "showtext";
952 let g opaque l
px py
=
953 if markunder opaque
px py
conf.paxmark
956 match getopaque l
.pageno
with
959 match Ne.pipe () with
963 "can not create mark pipe: %s"
966 let doclose what fd
=
967 Ne.clo fd
(fun msg
->
968 dolog
"%s close failed: %s" what msg
)
971 popen conf.paxcmd
[r
, 0; w
, -1];
972 copysel w opaque
false;
974 G.postRedisplay "paxunder";
976 dolog
"can not execute %S: %s"
977 conf.paxcmd
(exntos exn
);
984 G.postRedisplay "paxunder";
986 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
990 match Ne.pipe () with
992 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
995 try popen conf.selcmd
[r
, 0; w
, -1]; true
998 (Printf.sprintf
"failed to execute %s: %s"
999 conf.selcmd
(exntos exn
));
1003 Ne.clo fd
(fun msg
->
1004 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
1010 let l = String.length s
in
1011 let n = tempfailureretry
(Unix.write w s
0) l in
1016 "failed to write %d characters to sel pipe, wrote %d"
1021 (Printf.sprintf
"failed to write to sel pipe: %s"
1030 let undertext = function
1033 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
1034 | Utext s
-> "font: " ^ s
1035 | Uunexpected s
-> "unexpected: " ^ s
1036 | Ulaunch s
-> "launch: " ^ s
1037 | Unamed s
-> "named: " ^ s
1038 | Uremote
(filename
, pageno
) ->
1039 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
1042 let updateunder x y =
1043 match getunder x y with
1044 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
1046 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
1047 Wsi.setcursor
Wsi.CURSOR_INFO
1048 | Ulinkgoto
(pageno
, _
) ->
1050 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
1051 Wsi.setcursor
Wsi.CURSOR_INFO
1053 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
1054 Wsi.setcursor
Wsi.CURSOR_TEXT
1056 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
1057 Wsi.setcursor
Wsi.CURSOR_INHERIT
1059 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
1060 Wsi.setcursor
Wsi.CURSOR_INHERIT
1062 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
1063 Wsi.setcursor
Wsi.CURSOR_INHERIT
1064 | Uremote
(filename
, pageno
) ->
1065 if conf.underinfo
then showtext 'r'
1066 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
1067 Wsi.setcursor
Wsi.CURSOR_INFO
1070 let showlinktype under
=
1076 let s = undertext under
in
1081 let b = Buffer.create
(String.length
s + 1) in
1082 Buffer.add_string
b s;
1083 Buffer.add_char
b c
;
1087 module type TextEnumType
=
1091 val names
: string array
1094 module TextEnumMake
(Ten
: TextEnumType
) =
1096 let names = Ten.names;;
1097 let to_int (t
: Ten.t
) = Obj.magic t
;;
1098 let to_string t
= names.(to_int t
);;
1099 let of_int n : Ten.t
= Obj.magic
n;;
1102 if i
= Array.length
names
1103 then failwith
("invalid " ^
Ten.name ^
": " ^
s)
1105 if Ten.names.(i
) = s
1112 module CSTE
= TextEnumMake
(struct
1113 type t
= colorspace
;;
1114 let name = "colorspace";;
1115 let names = [|"rgb"; "bgr"; "gray"|];;
1118 module MTE
= TextEnumMake
(struct
1121 let names = [|"page"; "block"; "line"; "word"|];;
1124 module FMTE
= TextEnumMake
(struct
1126 let name = "fitmodel";;
1127 let names = [|"width"; "proportional"; "page"|];;
1130 let intentry_with_suffix text key
=
1132 if key
>= 32 && key
< 127
1136 match Char.lowercase
c with
1138 let text = addchar text c in
1141 | 'k'
| 'm'
| '
g'
->
1142 let text = addchar text c in
1146 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1150 let multicolumns_to_string (n, a
, b) =
1152 then Printf.sprintf
"%d" n
1153 else Printf.sprintf
"%d,%d,%d" n a
b;
1156 let multicolumns_of_string s =
1158 (int_of_string
s, 0, 0)
1160 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1162 then failwith
"subtly broken"; (n, a
, b)
1168 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1169 if n != 4 then failwith
"incomplete read(len)";
1171 lor (Char.code
s.[0] lsl 24)
1172 lor (Char.code
s.[1] lsl 16)
1173 lor (Char.code
s.[2] lsl 8)
1174 lor (Char.code
s.[3] lsl 0)
1176 let s = String.create
len in
1177 let n = tempfailureretry
(Unix.read fd
s 0) len in
1178 if n != len then failwith
"incomplete read(data)";
1182 let btod b = if b then 1 else 0;;
1185 let b = Buffer.create
16 in
1186 Buffer.add_string
b "llll";
1189 let s = Buffer.contents
b in
1190 let n = String.length
s in
1192 (* dolog "wcmd %S" (String.sub s 4 len); *)
1193 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1194 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1195 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1196 s.[3] <- Char.chr
(len land 0xff);
1197 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1198 if n'
!= n then failwith
"write failed";
1203 let d = state.winh
- h
in
1204 max
conf.interpagespace
((d + 1) / 2)
1207 let rowyh (c, coverA
, coverB
) b n =
1208 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1210 let _, _, vy
, (_, _, h
, _) = b.(n) in
1213 let n'
= n - coverA
in
1216 let e = min
state.pagecount
(s + c) in
1217 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1218 let _, _, y, (_, _, h
, _) = b.(m
) in
1219 let miny = min
miny y in
1220 let maxh = max
maxh h
in
1221 find (m
+1) miny maxh
1226 match conf.columns
with
1227 | Cmulti
((_, _, _) as cl
, b) ->
1228 if Array.length
b > 0
1230 let y, h
= rowyh cl
b (Array.length
b - 1) in
1231 y + h
+ (if conf.presentation
then calcips h
else 0)
1234 if Array.length
b > 0
1236 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1237 y + h
+ (if conf.presentation
then calcips h
else 0)
1240 if Array.length
b > 0
1242 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1247 let getpageyh pageno
=
1248 let pageno = bound pageno 0 (state.pagecount
-1) in
1249 match conf.columns
with
1251 if Array.length
b = 0
1254 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1256 if conf.presentation
1262 if Array.length
b = 0
1265 let y, h
= rowyh cl
b pageno in
1267 if conf.presentation
1273 if Array.length
b = 0
1277 let (_, _, y, (_, _, h
, _)) = b.(n) in
1281 let getpagedim pageno =
1284 | (n, _, _, _) as pdim
:: rest
->
1286 then (if n = pageno then pdim
else ppdim
)
1291 f (-1, -1, -1, -1) state.pdims
1294 let getpagey pageno = fst
(getpageyh pageno);;
1296 let nogeomcmds cmds
=
1298 | s, [] -> String.length
s = 0
1303 let ((c, coverA
, coverB
) as cl
), b =
1304 match conf.columns
with
1305 | Csingle
b -> (1, 0, 0), b
1306 | Cmulti
(c, b) -> c, b
1307 | Csplit
(_, b) -> (1, 0, 0), b
1309 if Array.length
b = 0
1312 let rec bsearch nmin nmax
=
1314 then bound nmin
0 (state.pagecount
-1)
1316 let n = (nmax
+ nmin
) / 2 in
1317 let vy, h
= rowyh cl
b n in
1319 if conf.presentation
1321 let ips = calcips h
in
1322 let y0 = vy - ips in
1323 let y1 = vy + h
+ ips in
1327 then 0, vy + h
+ conf.interpagespace
1329 let y0 = vy - conf.interpagespace
in
1330 y0, y0 + h
+ conf.interpagespace
1333 if y >= y0 && y < y1
1340 if n < state.pagecount
- coverB
1341 then ((n-coverA
)/c)*c + coverA
1348 then bsearch (n+1) nmax
1349 else bsearch nmin
(n-1)
1352 let r = bsearch 0 (state.pagecount
-1) in
1356 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1357 let sh = sh - (hscrollh ()) in
1358 let rec fold accu
n =
1359 if n = Array.length
b
1362 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1365 || n = state.pagecount
- coverB
1366 || (n - coverA
) mod columns
= columns
- 1)
1372 let pagey = max
0 (y - vy) in
1373 let pagedispy = if pagey > 0 then 0 else vy - y in
1374 let pagedispx, pagex
=
1376 if n = coverA
- 1 || n = state.pagecount
- coverB
1377 then state.x + (wadjsb state.winw
- w
) / 2
1378 else dx + xoff
+ state.x
1385 let vw = wadjsb state.winw
- pagedispx in
1386 let pw = w
- pagex
in
1389 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1390 if pagevw > 0 && pagevh > 0
1394 ; pagedimno
= pdimno
1401 ; pagedispx = pagedispx
1402 ; pagedispy = pagedispy
1414 List.rev
(fold [] (page_of_y y));
1417 let layoutS (columns
, b) y sh =
1418 let sh = sh - hscrollh () in
1419 let rec fold accu n =
1420 if n = Array.length
b
1423 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1430 let x = xoff
+ state.x in
1431 let pagey = max
0 (y - vy) in
1432 let pagedispy = if pagey > 0 then 0 else vy - y in
1433 let pagedispx, pagex
=
1447 let pagecolw = pagew
/columns
in
1449 if pagecolw < state.winw
1450 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1454 let vw = wadjsb state.winw
- pagedispx in
1455 let pw = pagew
- pagex
in
1458 let pagevw = min
pagevw pagecolw in
1459 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1460 if pagevw > 0 && pagevh > 0
1463 { pageno = n/columns
1464 ; pagedimno
= pdimno
1471 ; pagedispx = pagedispx
1472 ; pagedispy = pagedispy
1473 ; pagecol
= n mod columns
1484 List.rev
(fold [] 0)
1488 if nogeomcmds state.geomcmds
1490 match conf.columns
with
1491 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1492 | Cmulti
c -> layoutN c y sh
1493 | Csplit
s -> layoutS s y sh
1498 let y = state.y + incr
in
1500 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1505 let tilex = l.pagex
mod conf.tilew
in
1506 let tiley = l.pagey mod conf.tileh
in
1508 let col = l.pagex
/ conf.tilew
in
1509 let row = l.pagey / conf.tileh
in
1511 let rec rowloop row y0 dispy h
=
1515 let dh = conf.tileh
- y0 in
1516 let dh = min h
dh in
1517 let rec colloop col x0 dispx w
=
1521 let dw = conf.tilew
- x0 in
1522 let dw = min w
dw in
1524 f col row dispx dispy
x0 y0 dw dh;
1525 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1528 colloop col tilex l.pagedispx l.pagevw;
1529 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1532 if l.pagevw > 0 && l.pagevh > 0
1533 then rowloop row tiley l.pagedispy l.pagevh;
1536 let gettileopaque l col row =
1538 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1540 try Some
(Hashtbl.find state.tilemap
key)
1541 with Not_found
-> None
1544 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1545 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1546 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1549 let drawtiles l color
=
1551 let f col row x y tilex tiley w h
=
1552 match gettileopaque l col row with
1553 | Some
(opaque
, _, t
) ->
1554 let params = x, y, w
, h
, tilex, tiley in
1558 GlFunc.blend_func `zero `one_minus_src_color
;
1560 drawtile
params opaque
;
1562 then Gl.disable `blend
;
1565 let s = Printf.sprintf
1569 let w = measurestr
fstate.fontsize
s in
1570 GlMisc.push_attrib
[`current
];
1571 GlDraw.color
(0.0, 0.0, 0.0);
1573 (float (x-2), float (y-2))
1574 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1575 GlDraw.color
(1.0, 1.0, 1.0);
1576 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1577 GlMisc.pop_attrib
();
1582 let lw = wadjsb state.winw
- x in
1585 let lh = state.winh
- y in
1588 begin match state.texid
with
1590 Gl.enable `texture_2d
;
1591 GlTex.bind_texture `texture_2d id
;
1594 and x1 = float (x+w)
1595 and y1 = float (y+h
) in
1597 let tw = float w /. 16.0
1598 and th
= float h
/. 16.0 in
1599 let tx0 = float tilex /. 16.0
1600 and ty0
= float tiley /. 16.0 in
1602 and ty1
= ty0
+. th
in
1603 GlDraw.begins `quads
;
1604 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1605 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1606 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1607 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1610 Gl.disable `texture_2d
;
1612 GlDraw.color
(1.0, 1.0, 1.0);
1615 (float (x+w), float (y+h
));
1617 if w > 128 && h
> fstate.fontsize
+ 10
1619 GlDraw.color
(0.0, 0.0, 0.0);
1622 then (col*conf.tilew
, row*conf.tileh
)
1625 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r;
1632 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1634 let tilevisible1 l x y =
1636 and ax1
= l.pagex
+ l.pagevw
1638 and ay1
= l.pagey + l.pagevh in
1642 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1643 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1645 let rx0 = max
ax0 bx0
1646 and ry0
= max ay0 by0
1647 and rx1
= min ax1
bx1
1648 and ry1
= min ay1 by1
in
1650 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1651 nonemptyintersection
1654 let tilevisible layout n x y =
1655 let rec findpageinlayout m
= function
1656 | l :: rest
when l.pageno = n ->
1657 tilevisible1 l x y || (
1658 match conf.columns
with
1659 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1662 | _ :: rest
-> findpageinlayout 0 rest
1665 findpageinlayout 0 layout;
1668 let tileready l x y =
1669 tilevisible1 l x y &&
1670 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1673 let tilepage n p
layout =
1674 let rec loop = function
1678 let f col row _ _ _ _ _ _ =
1679 if state.currently
= Idle
1681 match gettileopaque l col row with
1684 let x = col*conf.tilew
1685 and y = row*conf.tileh
in
1687 let w = l.pagew
- x in
1691 let h = l.pageh
- y in
1696 then getpbo
w h conf.colorspace
1699 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1702 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1703 conf.tilew
, conf.tileh
1712 if nogeomcmds state.geomcmds
1716 let preloadlayout y =
1717 let y = if y < state.winh
then 0 else y - state.winh
in
1718 let h = state.winh
*3 in
1723 let rec loop pages
=
1724 if state.currently
!= Idle
1729 begin match getopaque l.pageno with
1731 wcmd "page %d %d" l.pageno l.pagedimno
;
1732 state.currently
<- Loading
(l, state.gen
);
1734 tilepage l.pageno opaque pages
;
1739 if nogeomcmds state.geomcmds
1745 if conf.preload && state.currently
= Idle
1746 then load (preloadlayout state.y);
1749 let layoutready layout =
1750 let rec fold all ls
=
1751 all
&& match ls
with
1753 let seen = ref false in
1754 let allvisible = ref true in
1755 let foo col row _ _ _ _ _ _ =
1757 allvisible := !allvisible &&
1758 begin match gettileopaque l col row with
1764 fold (!seen && !allvisible) rest
1767 let alltilesvisible = fold true layout in
1772 let y = bound y 0 state.maxy
in
1773 let y, layout, proceed
=
1774 match conf.maxwait
with
1775 | Some time
when state.ghyll
== noghyll ->
1776 begin match state.throttle
with
1778 let layout = layout y state.winh
in
1779 let ready = layoutready layout in
1783 state.throttle
<- Some
(layout, y, now ());
1785 else G.postRedisplay "gotoy showall (None)";
1787 | Some
(_, _, started
) ->
1788 let dt = now () -. started
in
1791 state.throttle
<- None
;
1792 let layout = layout y state.winh
in
1794 G.postRedisplay "maxwait";
1801 let layout = layout y state.winh
in
1802 if not
!wtmode || layoutready layout
1803 then G.postRedisplay "gotoy ready";
1809 state.layout <- layout;
1810 begin match state.mode
with
1811 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1812 let rec loop = function
1814 state.mode
<- LinkNav
(Ltgendir
0)
1815 | l :: _ when l.pageno = pageno ->
1816 begin match getopaque pageno with
1818 state.mode
<- LinkNav
(Ltgendir
0)
1820 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1821 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1822 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1823 then state.mode
<- LinkNav
(Ltgendir
0)
1825 | _ :: rest
-> loop rest
1830 begin match state.mode
with
1831 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1832 if not
(pagevisible layout pageno)
1834 match state.layout with
1837 state.mode
<- Birdseye
(
1838 conf, leftx
, l.pageno, hooverpageno
, anchor
1841 | LinkNav
(Ltgendir dir
as lt
) ->
1843 let rec loop = function
1846 match getopaque l.pageno with
1852 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1854 if dir
> 0 then LDfirst
else LDlast
1860 | Lnotfound
-> loop rest
1862 showlinktype (getlink opaque
n);
1863 Ltexact
(l.pageno, n)
1867 state.mode
<- LinkNav
linknav
1872 state.ghyll
<- noghyll;
1875 let mx, my
= state.mpos
in
1880 let conttiling pageno opaque
=
1881 tilepage pageno opaque
1882 (if conf.preload then preloadlayout state.y else state.layout)
1885 let gotoy_and_clear_text y =
1886 if not
conf.verbose
then state.text <- "";
1892 let coloff = l.pagecol
* l.pageh
in
1893 float (l.pagey + coloff) /. float l.pageh
1900 if conf.presentation
1901 then float l.pagedispy /. float (calcips l.pageh
)
1902 else float l.pagedispy /. float conf.interpagespace
1905 (l.pageno, top, dtop)
1909 match state.layout with
1910 | l :: _ -> getanchor1 l
1912 let n = page_of_y state.y in
1916 let y, h = getpageyh n in
1917 let dy = y - state.y in
1919 if conf.presentation
1921 let ips = calcips h in
1922 float (dy + ips) /. float ips
1924 float dy /. float conf.interpagespace
1929 let getanchory (n, top, dtop) =
1930 let y, h = getpageyh n in
1931 if conf.presentation
1933 let ips = calcips h in
1934 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1936 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1939 let gotoanchor anchor
=
1940 gotoy (getanchory anchor
);
1944 cbput state.hists
.nav
(getanchor ());
1948 let anchor = cbgetc state.hists
.nav dir
in
1953 let scroll f n a
b =
1954 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1956 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1958 then s (float f /. float a
)
1961 then 1.0 -. s ((float (f-b) /. float (n-b)))
1967 (* courtesy: (calc-eval "integ(3x^2-2x^3,x)") *)
1968 let iv x = x**3.-.0.5*.x**4. in
1970 let ins = float a
*. iv1
1971 and outs
= float (n-b) *. iv1 in
1973 ins +. outs
+. float ones
1975 let rec set (_N
, _A
, _B
) y sy
=
1976 let sum = summa
1.0 _N _A _B
in
1977 let dy = float (y - sy
) in
1981 then state.ghyll
<- noghyll
1984 let s = scroll n _N _A _B
in
1985 let y1 = y1 +. ((s *. dy) /. sum) in
1986 gotoy_and_clear_text (truncate
y1);
1987 state.ghyll
<- gf (n+1) y1;
1991 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1993 gf 0 (float state.y)
1996 match conf.ghyllscroll
with
1998 gotoy_and_clear_text y
2000 if state.ghyll
== noghyll
2001 then set nab
y state.y
2002 else state.ghyll
(Some
y)
2005 let gotopage n top =
2006 let y, h = getpageyh n in
2007 let y = y + (truncate
(top *. float h)) in
2011 let gotopage1 n top =
2012 let y = getpagey n in
2017 let invalidate s f =
2022 match state.geomcmds
with
2023 | ps
, [] when String.length ps
= 0 ->
2025 state.geomcmds
<- s, [];
2028 state.geomcmds
<- ps
, [s, f];
2030 | ps
, (s'
, _) :: rest
when s'
= s ->
2031 state.geomcmds
<- ps
, ((s, f) :: rest
);
2034 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2038 Hashtbl.iter
(fun _ opaque
->
2039 wcmd "freepage %s" opaque
;
2041 Hashtbl.clear
state.pagemap
;
2045 if not
(Queue.is_empty
state.tilelru
)
2047 Queue.iter
(fun (k
, p
, s) ->
2048 wcmd "freetile %s" p
;
2049 state.memused
<- state.memused
- s;
2050 Hashtbl.remove
state.tilemap k
;
2052 state.uioh#infochanged Memused
;
2053 Queue.clear
state.tilelru
;
2059 let h = truncate
(float h*.conf.zoom
) in
2060 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2064 let opendoc path password
=
2066 state.password
<- password
;
2067 state.gen
<- state.gen
+ 1;
2068 state.docinfo
<- [];
2071 setaalevel
conf.aalevel
;
2073 if String.length
state.origin
= 0
2077 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2078 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2079 invalidate "reqlayout"
2081 wcmd "reqlayout %d %d %d %s\000"
2082 conf.angle
(FMTE.to_int conf.fitmodel
)
2083 (stateh state.winh
) state.nameddest
2088 state.anchor <- getanchor ();
2089 opendoc state.path
state.password
;
2093 let c = c *. conf.colorscale
in
2097 let scalecolor2 (r, g, b) =
2098 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2101 let docolumns = function
2103 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2104 let rec loop pageno pdimno pdim
y ph pdims
=
2105 if pageno = state.pagecount
2108 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2110 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2111 pdimno+1, pdim
, rest
2115 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2117 (if conf.presentation
2118 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2119 else (if pageno = 0 then 0 else conf.interpagespace
)
2122 a.(pageno) <- (pdimno, x, y, pdim
);
2123 loop (pageno+1) pdimno pdim
(y + h) h pdims
2125 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2126 conf.columns
<- Csingle
a;
2128 | Cmulti
((columns
, coverA
, coverB
), _) ->
2129 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2130 let rec loop pageno pdimno pdim
x y rowh pdims
=
2131 let rec fixrow m
= if m
= pageno then () else
2132 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2135 let y = y + (rowh
- h) / 2 in
2136 a.(m
) <- (pdimno, x, y, pdim
);
2140 if pageno = state.pagecount
2141 then fixrow (((pageno - 1) / columns
) * columns
)
2143 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2145 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2146 pdimno+1, pdim
, rest
2151 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2153 let x = (wadjsb state.winw
- w) / 2 in
2155 if conf.presentation
then calcips h else conf.interpagespace
in
2156 x, y + ips + rowh
, h
2159 if (pageno - coverA
) mod columns
= 0
2161 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2163 if conf.presentation
2165 let ips = calcips h in
2166 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2168 y + (if pageno = 0 then 0 else conf.interpagespace
)
2172 else x, y, max rowh
h
2176 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2179 if pageno = columns
&& conf.presentation
2181 let ips = calcips rowh
in
2182 for i
= 0 to pred columns
2184 let (pdimno, x, y, pdim
) = a.(i
) in
2185 a.(i
) <- (pdimno, x, y+ips, pdim
)
2191 fixrow (pageno - columns
);
2196 a.(pageno) <- (pdimno, x, y, pdim
);
2197 let x = x + w + xoff
*2 + conf.interpagespace
in
2198 loop (pageno+1) pdimno pdim
x y rowh' pdims
2200 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2201 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2204 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2205 let rec loop pageno pdimno pdim
y pdims
=
2206 if pageno = state.pagecount
2209 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2211 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2212 pdimno+1, pdim
, rest
2217 let rec loop1 n x y =
2218 if n = c then y else (
2219 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2220 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2223 let y = loop1 0 0 y in
2224 loop (pageno+1) pdimno pdim
y pdims
2226 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2227 conf.columns
<- Csplit
(c, a);
2231 docolumns conf.columns
;
2232 state.maxy
<- calcheight ();
2233 if state.reprf
== noreprf
2235 match state.mode
with
2236 | Birdseye
(_, _, pageno, _, _) ->
2237 let y, h = getpageyh pageno in
2238 let top = (state.winh
- h) / 2 in
2239 gotoy (max
0 (y - top))
2240 | _ -> gotoanchor state.anchor
2244 state.reprf
<- noreprf;
2249 GlDraw.viewport
0 0 w h;
2250 let firsttime = state.geomcmds
== firstgeomcmds in
2251 if not
firsttime && nogeomcmds state.geomcmds
2252 then state.anchor <- getanchor ();
2255 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2258 setfontsize fstate.fontsize
;
2259 GlMat.mode `modelview
;
2260 GlMat.load_identity
();
2262 GlMat.mode `projection
;
2263 GlMat.load_identity
();
2264 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2265 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2266 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2271 else float state.x /. float state.w
2273 invalidate "geometry"
2277 then state.x <- truncate
(relx *. float w);
2279 match conf.columns
with
2281 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2282 | Csplit
(c, _) -> w * c
2284 wcmd "geometry %d %d %d"
2285 w (stateh h) (FMTE.to_int conf.fitmodel
)
2290 let len = String.length
state.text in
2293 match state.mode
with
2294 | Textentry
_ | View
| LinkNav
_ ->
2295 let h, _, _ = state.uioh#scrollpw
in
2301 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2302 (x+.w, float (state.winh
- hscrollh))
2305 let w = float (wadjsb state.winw
- 1) in
2306 if state.progress
>= 0.0 && state.progress
< 1.0
2308 GlDraw.color
(0.3, 0.3, 0.3);
2309 let w1 = w *. state.progress
in
2311 GlDraw.color
(0.0, 0.0, 0.0);
2315 GlDraw.color
(0.0, 0.0, 0.0);
2319 GlDraw.color
(1.0, 1.0, 1.0);
2320 drawstring fstate.fontsize
2321 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2324 match state.mode
with
2325 | Textentry
((prefix
, text, _, _, _, _), _) ->
2329 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2331 Printf.sprintf
"%s%s_" prefix
text
2340 if not
(istextentry state.mode
) && state.uioh#eformsgs
2342 let s1 = "(press 'e' to review error messasges)" in
2343 if String.length
s > 0 then s ^
" " ^
s1 else s1
2348 if String.length
s > 0
2353 let len = Queue.length
state.tilelru
in
2355 match state.throttle
with
2358 then preloadlayout state.y
2360 | Some
(layout, _, _) ->
2364 if state.memused
<= conf.memlimit
2369 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2370 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2371 let (_, pw, ph
, _) = getpagedim n in
2374 && colorspace
= conf.colorspace
2375 && angle
= conf.angle
2379 let x = col*conf.tilew
2380 and y = row*conf.tileh
in
2381 tilevisible (Lazy.force_val
layout) n x y
2383 then Queue.push lruitem
state.tilelru
2386 wcmd "freetile %s" p
;
2387 state.memused
<- state.memused
- s;
2388 state.uioh#infochanged Memused
;
2389 Hashtbl.remove
state.tilemap k
;
2397 let logcurrently = function
2398 | Idle
-> dolog
"Idle"
2399 | Loading
(l, gen
) ->
2400 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2401 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2403 "Tiling %d[%d,%d] page=%s cs=%s angle"
2404 l.pageno col row pageopaque
2405 (CSTE.to_string colorspace
)
2407 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2408 angle gen
conf.angle
state.gen
2410 conf.tilew
conf.tileh
2417 let r = Str.regexp
" " in
2418 fun s -> Str.bounded_split
r s 2;
2421 let onpagerect pageno f =
2423 match conf.columns
with
2424 | Cmulti
(_, b) -> b
2426 | Csplit
(_, b) -> b
2428 if pageno >= 0 && pageno < Array.length
b
2430 let (pdimno, _, _, (_, _, _, _)) = b.(pageno) in
2431 let r = getpdimrect
pdimno in
2432 f (r.(1)-.r.(0)) (r.(3)-.r.(2))
2435 let gotopagexy1 pageno x y =
2436 onpagerect pageno (fun w h ->
2438 let _,w1,_,leftx
= getpagedim pageno in
2439 let wh = state.winh
- hscrollh () in
2440 let sw = float w1 /. w in
2442 let x = leftx
+ state.x + truncate
x in
2444 if x < 0 || x >= wadjsb state.winw
2448 let py, h = getpageyh pageno in
2449 let pdy = truncate
(top *. float h) in
2450 let y'
= py + pdy in
2451 let dy = y'
- state.y in
2453 if x != state.x || not
(dy > 0 && dy < wh)
2455 if conf.presentation
2457 if abs
(py - y'
) > wh
2464 if state.x != sx || state.y != sy
2469 let ww = wadjsb state.winw
in
2471 and qy
= pdy / wh in
2473 and y = py + qy
* wh in
2474 let x = if -x + ww > w1 then -(w1-ww) else x
2475 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2477 if conf.presentation
2479 if abs
(py - y'
) > wh
2489 gotoy_and_clear_text y;
2491 else gotoy_and_clear_text state.y;
2495 let gotopagexy pageno x y =
2496 match state.mode
with
2497 | Birdseye
_ -> gotopage pageno 0.0
2498 | _ -> gotopagexy1 pageno x y
2502 (* dolog "%S" cmds; *)
2503 let cl = splitatspace cmds
in
2505 try Scanf.sscanf
s fmt
f
2507 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2512 state.uioh#infochanged Pdim
;
2515 | "clearrects" :: [] ->
2516 state.rects
<- state.rects1
;
2517 G.postRedisplay "clearrects";
2519 | "continue" :: args :: [] ->
2520 let n = scan args "%u" (fun n -> n) in
2521 state.pagecount
<- n;
2522 begin match state.currently
with
2524 state.currently
<- Idle
;
2525 state.outlines
<- Array.of_list
(List.rev
l)
2529 let cur, cmds
= state.geomcmds
in
2530 if String.length
cur = 0
2531 then failwith
"umpossible";
2533 begin match List.rev cmds
with
2535 state.geomcmds
<- "", [];
2539 state.geomcmds
<- s, List.rev rest
;
2541 if conf.maxwait
= None
&& not
!wtmode
2542 then G.postRedisplay "continue";
2544 | "title" :: args :: [] ->
2547 | "msg" :: args :: [] ->
2550 | "vmsg" :: args :: [] ->
2552 then showtext ' '
args
2554 | "emsg" :: args :: [] ->
2555 Buffer.add_string
state.errmsgs
args;
2556 state.newerrmsgs
<- true;
2557 G.postRedisplay "error message"
2559 | "progress" :: args :: [] ->
2560 let progress, text =
2563 f, String.sub
args pos
(String.length
args - pos
))
2566 state.progress <- progress;
2567 G.postRedisplay "progress"
2569 | "firstmatch" :: args :: [] ->
2570 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2571 scan args "%u %d %f %f %f %f %f %f %f %f"
2572 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2573 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2575 let y = (getpagey pageno) + truncate
y0 in
2578 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2580 | "match" :: args :: [] ->
2581 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2582 scan args "%u %d %f %f %f %f %f %f %f %f"
2583 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2584 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2587 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2589 | "page" :: args :: [] ->
2590 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2591 begin match state.currently
with
2592 | Loading
(l, gen
) ->
2593 vlog "page %d took %f sec" l.pageno t
;
2594 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2595 begin match state.throttle
with
2597 let preloadedpages =
2599 then preloadlayout state.y
2604 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2605 IntSet.empty
preloadedpages
2608 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2609 if not
(IntSet.mem
pageno set)
2611 wcmd "freepage %s" opaque
;
2617 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2620 state.currently
<- Idle
;
2623 tilepage l.pageno pageopaque state.layout;
2625 load preloadedpages;
2626 if pagevisible state.layout l.pageno
2627 && layoutready state.layout
2628 then G.postRedisplay "page";
2631 | Some
(layout, _, _) ->
2632 state.currently
<- Idle
;
2633 tilepage l.pageno pageopaque layout;
2638 dolog
"Inconsistent loading state";
2639 logcurrently state.currently
;
2643 | "tile" :: args :: [] ->
2644 let (x, y, opaque
, size
, t
) =
2645 scan args "%u %u %s %u %f"
2646 (fun x y p size t
-> (x, y, p
, size
, t
))
2648 begin match state.currently
with
2649 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2650 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2653 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2655 wcmd "freetile %s" opaque
;
2656 state.currently
<- Idle
;
2660 puttileopaque l col row gen cs angle opaque size t
;
2661 state.memused
<- state.memused
+ size
;
2662 state.uioh#infochanged Memused
;
2664 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2665 opaque
, size
) state.tilelru
;
2668 match state.throttle
with
2669 | None
-> state.layout
2670 | Some
(layout, _, _) -> layout
2673 state.currently
<- Idle
;
2675 && conf.colorspace
= cs
2676 && conf.angle
= angle
2677 && tilevisible layout l.pageno x y
2678 then conttiling l.pageno pageopaque;
2680 begin match state.throttle
with
2682 preload state.layout;
2684 && conf.colorspace
= cs
2685 && conf.angle
= angle
2686 && tilevisible state.layout l.pageno x y
2687 && (not
!wtmode || layoutready state.layout)
2688 then G.postRedisplay "tile nothrottle";
2690 | Some
(layout, y, _) ->
2691 let ready = layoutready layout in
2695 state.layout <- layout;
2696 state.throttle
<- None
;
2697 G.postRedisplay "throttle";
2704 dolog
"Inconsistent tiling state";
2705 logcurrently state.currently
;
2709 | "pdim" :: args :: [] ->
2710 let (n, w, h, _) as pdim
=
2711 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2714 match conf.fitmodel
, conf.columns
with
2715 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2718 state.uioh#infochanged Pdim
;
2719 state.pdims
<- pdim :: state.pdims
2721 | "o" :: args :: [] ->
2722 let (l, n, t
, h, pos
) =
2723 scan args "%u %u %d %u %n"
2724 (fun l n t
h pos
-> l, n, t
, h, pos
)
2726 let s = String.sub
args pos
(String.length
args - pos
) in
2727 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2728 begin match state.currently
with
2729 | Outlining outlines
->
2730 state.currently
<- Outlining
(outline :: outlines
)
2732 state.currently
<- Outlining
[outline]
2734 dolog
"invalid outlining state";
2735 logcurrently currently
2738 | "a" :: args :: [] ->
2740 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2742 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2744 | "info" :: args :: [] ->
2745 state.docinfo
<- (1, args) :: state.docinfo
2747 | "infoend" :: [] ->
2748 state.uioh#infochanged Docinfo
;
2749 state.docinfo
<- List.rev
state.docinfo
2752 failwith
(Printf.sprintf
"unknown cmd `%S'" cmds
)
2757 let action = function
2758 | HCprev
-> cbget cb ~
-1
2759 | HCnext
-> cbget cb
1
2760 | HCfirst
-> cbget cb ~
-(cb
.rc)
2761 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2762 and cancel
() = cb
.rc <- rc
2766 let search pattern forward
=
2767 match conf.columns
with
2769 showtext '
!'
"searching does not work properly in split columns mode"
2771 if String.length pattern
> 0
2774 match state.layout with
2777 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2779 wcmd "search %d %d %d %d,%s\000"
2780 (btod conf.icase
) pn py (btod forward
) pattern
;
2783 let intentry text key =
2785 if key >= 32 && key < 127
2791 let text = addchar text c in
2795 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2799 let linknentry text key =
2801 if key >= 32 && key < 127
2807 let text = addchar text c in
2811 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2816 if String.length
s > 0
2819 let l = String.length
s in
2820 let rec loop pos
n = if pos
= l then n else
2821 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2822 loop (pos
+1) (n*26 + m)
2825 let rec loop n = function
2828 match getopaque l.pageno with
2829 | None
-> loop n rest
2831 let m = getlinkcount opaque
in
2834 let under = getlink opaque
n in
2837 else loop (n-m) rest
2839 loop n state.layout;
2843 let textentry text key =
2844 if key land 0xff00 = 0xff00
2846 else TEcont
(text ^ toutf8
key)
2849 let reqlayout angle fitmodel
=
2850 match state.throttle
with
2852 if nogeomcmds state.geomcmds
2853 then state.anchor <- getanchor ();
2854 conf.angle
<- angle
mod 360;
2857 match state.mode
with
2858 | LinkNav
_ -> state.mode
<- View
2861 conf.fitmodel
<- fitmodel
;
2862 invalidate "reqlayout"
2864 wcmd "reqlayout %d %d %d"
2865 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2870 let settrim trimmargins trimfuzz
=
2871 if nogeomcmds state.geomcmds
2872 then state.anchor <- getanchor ();
2873 conf.trimmargins
<- trimmargins
;
2874 conf.trimfuzz
<- trimfuzz
;
2875 let x0, y0, x1, y1 = trimfuzz
in
2876 invalidate "settrim"
2878 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2883 match state.throttle
with
2885 let zoom = max
0.0001 zoom in
2886 if zoom <> conf.zoom
2888 state.prevzoom
<- (conf.zoom, state.x);
2890 reshape state.winw
state.winh
;
2891 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2894 | Some
(layout, y, started
) ->
2896 match conf.maxwait
with
2900 let dt = now () -. started
in
2908 let setcolumns mode columns coverA coverB
=
2909 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2913 then showtext '
!'
"split mode doesn't work in bird's eye"
2915 conf.columns
<- Csplit
(-columns
, [||]);
2923 conf.columns
<- Csingle
[||];
2928 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2932 reshape state.winw
state.winh
;
2935 let enterbirdseye () =
2936 let zoom = float conf.thumbw
/. float state.winw
in
2937 let birdseyepageno =
2938 let cy = state.winh
/ 2 in
2942 let rec fold best
= function
2945 let d = cy - (l.pagedispy + l.pagevh/2)
2946 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2947 if abs
d < abs dbest
2954 state.mode
<- Birdseye
(
2955 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2958 conf.presentation
<- false;
2959 conf.interpagespace
<- 10;
2960 conf.hlinks
<- false;
2961 conf.fitmodel
<- FitProportional
;
2963 state.mstate
<- Mnone
;
2964 conf.maxwait
<- None
;
2966 match conf.beyecolumns
with
2969 Cmulti
((c, 0, 0), [||])
2970 | None
-> Csingle
[||]
2972 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2975 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2980 reshape state.winw
state.winh
;
2983 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2985 conf.zoom <- c.zoom;
2986 conf.presentation
<- c.presentation
;
2987 conf.interpagespace
<- c.interpagespace
;
2988 conf.maxwait
<- c.maxwait
;
2989 conf.hlinks
<- c.hlinks
;
2990 conf.fitmodel
<- c.fitmodel
;
2991 conf.beyecolumns
<- (
2992 match conf.columns
with
2993 | Cmulti
((c, _, _), _) -> Some
c
2995 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2998 match c.columns
with
2999 | Cmulti
(c, _) -> Cmulti
(c, [||])
3000 | Csingle
_ -> Csingle
[||]
3001 | Csplit
(c, _) -> Csplit
(c, [||])
3006 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3009 reshape state.winw
state.winh
;
3010 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3013 let togglebirdseye () =
3014 match state.mode
with
3015 | Birdseye vals
-> leavebirdseye vals
true
3016 | View
-> enterbirdseye ()
3020 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3021 let pageno = max
0 (pageno - incr
) in
3022 let rec loop = function
3023 | [] -> gotopage1 pageno 0
3024 | l :: _ when l.pageno = pageno ->
3025 if l.pagedispy >= 0 && l.pagey = 0
3026 then G.postRedisplay "upbirdseye"
3027 else gotopage1 pageno 0
3028 | _ :: rest
-> loop rest
3031 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3034 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3035 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3036 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3037 let rec loop = function
3039 let y, h = getpageyh pageno in
3040 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3042 | l :: _ when l.pageno = pageno ->
3043 if l.pagevh != l.pageh
3044 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3045 else G.postRedisplay "downbirdseye"
3046 | _ :: rest
-> loop rest
3051 let optentry mode
_ key =
3052 let btos b = if b then "on" else "off" in
3053 if key >= 32 && key < 127
3055 let c = Char.chr
key in
3059 try conf.scrollstep
<- int_of_string
s with exc
->
3060 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3062 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3067 conf.autoscrollstep
<- int_of_string
s;
3068 if state.autoscroll
<> None
3069 then state.autoscroll
<- Some
conf.autoscrollstep
3071 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3073 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3078 let n, a, b = multicolumns_of_string s in
3079 setcolumns mode
n a b;
3081 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3083 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3088 let zoom = float (int_of_string
s) /. 100.0 in
3091 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3093 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3098 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3100 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3101 begin match mode
with
3103 leavebirdseye beye
false;
3108 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3110 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3115 Some
(int_of_string
s)
3117 state.text <- Printf.sprintf
"bad integer `%s': %s"
3121 | Some angle
-> reqlayout angle
conf.fitmodel
3124 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3127 conf.icase
<- not
conf.icase
;
3128 TEdone
("case insensitive search " ^
(btos conf.icase
))
3131 conf.preload <- not
conf.preload;
3133 TEdone
("preload " ^
(btos conf.preload))
3136 conf.verbose
<- not
conf.verbose
;
3137 TEdone
("verbose " ^
(btos conf.verbose
))
3140 conf.debug
<- not
conf.debug
;
3141 TEdone
("debug " ^
(btos conf.debug
))
3144 conf.maxhfit
<- not
conf.maxhfit
;
3145 state.maxy
<- calcheight ();
3146 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3149 conf.crophack
<- not
conf.crophack
;
3150 TEdone
("crophack " ^
btos conf.crophack
)
3154 match conf.maxwait
with
3156 conf.maxwait
<- Some infinity
;
3157 "always wait for page to complete"
3159 conf.maxwait
<- None
;
3160 "show placeholder if page is not ready"
3165 conf.underinfo
<- not
conf.underinfo
;
3166 TEdone
("underinfo " ^
btos conf.underinfo
)
3169 conf.savebmarks
<- not
conf.savebmarks
;
3170 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3176 match state.layout with
3181 conf.interpagespace
<- int_of_string
s;
3182 docolumns conf.columns
;
3183 state.maxy
<- calcheight ();
3184 let y = getpagey pageno in
3187 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3189 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3193 match conf.fitmodel
with
3194 | FitProportional
-> FitWidth
3195 | _ -> FitProportional
3197 reqlayout conf.angle
fm;
3198 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3201 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3202 TEdone
("trim margins " ^
btos conf.trimmargins
)
3205 conf.invert
<- not
conf.invert
;
3206 TEdone
("invert colors " ^
btos conf.invert
)
3210 cbput state.hists
.sel
s;
3213 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3214 textentry, ondone, true)
3218 then conf.pax
<- Some
(ref (0.0, 0, 0))
3219 else conf.pax
<- None
;
3220 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3223 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3229 class type lvsource
= object
3230 method getitemcount
: int
3231 method getitem
: int -> (string * int)
3232 method hasaction
: int -> bool
3241 method getactive
: int
3242 method getfirst
: int
3243 method getqsearch
: string
3244 method setqsearch
: string -> unit
3248 class virtual lvsourcebase
= object
3249 val mutable m_active
= 0
3250 val mutable m_first
= 0
3251 val mutable m_qsearch
= ""
3252 val mutable m_pan
= 0
3253 method getactive
= m_active
3254 method getfirst
= m_first
3255 method getqsearch
= m_qsearch
3256 method getpan
= m_pan
3257 method setqsearch
s = m_qsearch
<- s
3260 let withoutlastutf8 s =
3261 let len = String.length
s in
3269 let b = Char.code
s.[pos
] in
3270 if b land 0b11000000 = 0b11000000
3275 if Char.code
s.[len-1] land 0x80 = 0
3279 String.sub
s 0 first;
3282 let textentrykeyboard
3283 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3285 if key >= 0xffb0 && key <= 0xffb9
3286 then key - 0xffb0 + 48 else key
3289 state.mode
<- Textentry
(te
, onleave
);
3292 G.postRedisplay "textentrykeyboard enttext";
3294 let histaction cmd
=
3297 | Some
(action, _) ->
3298 state.mode
<- Textentry
(
3299 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3301 G.postRedisplay "textentry histaction"
3304 | 0xff08 -> (* backspace *)
3305 let s = withoutlastutf8 text in
3306 let len = String.length
s in
3307 if cancelonempty
&& len = 0
3310 G.postRedisplay "textentrykeyboard after cancel";
3313 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3316 | 0xff0d | 0xff8d -> (* (kp) enter *)
3319 G.postRedisplay "textentrykeyboard after confirm"
3321 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3322 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3323 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3324 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3326 | 0xff1b -> (* escape*)
3327 if String.length
text = 0
3329 begin match opthist
with
3331 | Some
(_, onhistcancel
) -> onhistcancel
()
3335 G.postRedisplay "textentrykeyboard after cancel2"
3338 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3341 | 0xff9f | 0xffff -> () (* delete *)
3344 && key land 0xff00 != 0xff00 (* keyboard *)
3345 && key land 0xfe00 != 0xfe00 (* xkb *)
3346 && key land 0xfd00 != 0xfd00 (* 3270 *)
3348 begin match onkey
text key with
3352 G.postRedisplay "textentrykeyboard after confirm2";
3355 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3359 G.postRedisplay "textentrykeyboard after cancel3"
3362 state.mode
<- Textentry
(te
, onleave
);
3363 G.postRedisplay "textentrykeyboard switch";
3367 vlog "unhandled key %s" (Wsi.keyname
key)
3370 let firstof first active
=
3371 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3372 then max
0 (active
- (fstate.maxrows
/2))
3376 let calcfirst first active
=
3379 let rows = active
- first in
3380 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3384 let scrollph y maxy
=
3385 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3386 let sh = float state.winh
/. sh in
3387 let sh = max
sh (float conf.scrollh
) in
3389 let percent = float y /. float maxy
in
3390 let position = (float state.winh
-. sh) *. percent in
3393 if position +. sh > float state.winh
3394 then float state.winh
-. sh
3400 let coe s = (s :> uioh
);;
3402 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3404 val m_pan
= source#getpan
3405 val m_first
= source#getfirst
3406 val m_active
= source#getactive
3407 val m_qsearch
= source#getqsearch
3408 val m_prev_uioh
= state.uioh
3410 method private elemunder
y =
3411 let n = y / (fstate.fontsize
+1) in
3412 if m_first
+ n < source#getitemcount
3414 if source#hasaction
(m_first
+ n)
3415 then Some
(m_first
+ n)
3422 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3423 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3424 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3425 GlDraw.color
(1., 1., 1.);
3426 Gl.enable `texture_2d
;
3427 let fs = fstate.fontsize
in
3429 let ww = fstate.wwidth
in
3430 let tabw = 30.0*.ww in
3431 let itemcount = source#getitemcount
in
3433 if (row - m_first
) > fstate.maxrows
3436 if row >= 0 && row < itemcount
3438 let (s, level
) = source#getitem
row in
3439 let y = (row - m_first
) * nfs in
3440 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3443 Gl.disable `texture_2d
;
3444 GlDraw.polygon_mode `both `line
;
3445 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3446 GlDraw.color
(1., 1., 1.) ~
alpha;
3447 GlDraw.rect (1., float (y + 1))
3448 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3449 GlDraw.polygon_mode `both `fill
;
3450 GlDraw.color
(1., 1., 1.);
3451 Gl.enable `texture_2d
;
3454 let drawtabularstring s =
3455 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3458 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3461 let len = String.length
s - tabpos - 1 in
3462 let s1 = String.sub
s 0 tabpos
3463 and s2
= String.sub
s (tabpos + 1) len in
3464 let nx = drawstr x s1 in
3466 let x = x +. (max
tabw sw) in
3473 let _ = drawtabularstring s in
3480 Gl.disable `texture_2d
;
3482 method updownlevel incr
=
3483 let len = source#getitemcount
in
3485 if m_active
>= 0 && m_active
< len
3486 then snd
(source#getitem m_active
)
3490 if i
= len then i
-1 else if i
= -1 then 0 else
3491 let _, l = source#getitem i
in
3492 if l != curlevel then i
else flow (i
+incr
)
3494 let active = flow m_active
in
3495 let first = calcfirst m_first
active in
3496 G.postRedisplay "outline updownlevel";
3497 {< m_active
= active; m_first
= first >}
3499 method private key1
key mask
=
3500 let set1 active first qsearch
=
3501 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3503 let search active pattern incr
=
3504 let active = if active = -1 then m_first
else active in
3507 if n >= 0 && n < source#getitemcount
3509 let s, _ = source#getitem
n in
3511 (try ignore
(Str.search_forward
re s 0); true
3512 with Not_found
-> false)
3514 else loop (n + incr
)
3521 let re = Str.regexp_case_fold pattern
in
3527 let itemcount = source#getitemcount
in
3528 let find start incr
=
3530 if i
= -1 || i
= itemcount
3533 if source#hasaction i
3535 else find (i
+ incr
)
3540 let set active first =
3541 let first = bound first 0 (itemcount - fstate.maxrows
) in
3543 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3546 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3548 let incr1 = if incr
> 0 then 1 else -1 in
3549 if isvisible m_first m_active
3552 let next = m_active
+ incr
in
3554 if next < 0 || next >= itemcount
3556 else find next incr1
3558 if abs
(m_active
- next) > fstate.maxrows
3564 let first = m_first
+ incr
in
3565 let first = bound first 0 (itemcount - fstate.maxrows
) in
3567 let next = m_active
+ incr
in
3568 let next = bound next 0 (itemcount - 1) in
3575 if isvisible first next
3582 let first = min
next m_first
in
3584 if abs
(next - first) > fstate.maxrows
3590 let first = m_first
+ incr
in
3591 let first = bound first 0 (itemcount - 1) in
3593 let next = m_active
+ incr
in
3594 let next = bound next 0 (itemcount - 1) in
3595 let next = find next incr1 in
3597 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3599 let active = if m_active
= -1 then next else m_active
in
3604 if isvisible first active
3610 G.postRedisplay "listview navigate";
3614 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3615 let incr = if key = 0x72 then -1 else 1 in
3617 match search (m_active
+ incr) m_qsearch
incr with
3619 state.text <- m_qsearch ^
" [not found]";
3622 state.text <- m_qsearch
;
3623 active, firstof m_first
active
3625 G.postRedisplay "listview ctrl-r/s";
3626 set1 active first m_qsearch
;
3628 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3629 if m_active
>= 0 && m_active
< source#getitemcount
3631 let s, _ = source#getitem m_active
in
3636 | 0xff08 -> (* backspace *)
3637 if String.length m_qsearch
= 0
3640 let qsearch = withoutlastutf8 m_qsearch
in
3641 let len = String.length
qsearch in
3645 G.postRedisplay "listview empty qsearch";
3646 set1 m_active m_first
"";
3650 match search m_active
qsearch ~
-1 with
3652 state.text <- qsearch ^
" [not found]";
3655 state.text <- qsearch;
3656 active, firstof m_first
active
3658 G.postRedisplay "listview backspace qsearch";
3659 set1 active first qsearch
3662 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3663 let pattern = m_qsearch ^ toutf8
key in
3665 match search m_active
pattern 1 with
3667 state.text <- pattern ^
" [not found]";
3670 state.text <- pattern;
3671 active, firstof m_first
active
3673 G.postRedisplay "listview qsearch add";
3674 set1 active first pattern;
3676 | 0xff1b -> (* escape *)
3678 if String.length m_qsearch
= 0
3680 G.postRedisplay "list view escape";
3683 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3685 | None
-> m_prev_uioh
3690 G.postRedisplay "list view kill qsearch";
3691 source#setqsearch
"";
3692 coe {< m_qsearch
= "" >}
3695 | 0xff0d | 0xff8d -> (* (kp) enter *)
3697 let self = {< m_qsearch
= "" >} in
3698 source#setqsearch
"";
3700 G.postRedisplay "listview enter";
3701 if m_active
>= 0 && m_active
< source#getitemcount
3703 source#exit
(coe self) false m_active m_first m_pan
"";
3706 source#exit
(coe self) true m_active m_first m_pan
"";
3709 begin match opt with
3710 | None
-> m_prev_uioh
3714 | 0xff9f | 0xffff -> (* (kp) delete *)
3717 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3718 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3719 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3720 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3722 | 0xff53 | 0xff98 -> (* (kp) right *)
3724 G.postRedisplay "listview right";
3725 coe {< m_pan
= m_pan
- 1 >}
3727 | 0xff51 | 0xff96 -> (* (kp) left *)
3729 G.postRedisplay "listview left";
3730 coe {< m_pan
= m_pan
+ 1 >}
3732 | 0xff50 | 0xff95 -> (* (kp) home *)
3733 let active = find 0 1 in
3734 G.postRedisplay "listview home";
3737 | 0xff57 | 0xff9c -> (* (kp) end *)
3738 let first = max
0 (itemcount - fstate.maxrows
) in
3739 let active = find (itemcount - 1) ~
-1 in
3740 G.postRedisplay "listview end";
3743 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3747 dolog
"listview unknown key %#x" key; coe self
3749 method key key mask
=
3750 match state.mode
with
3751 | Textentry te
-> textentrykeyboard key mask te
; coe self
3752 | _ -> self#key1
key mask
3754 method button button down
x y _ =
3757 | 1 when x > state.winw
- conf.scrollbw
->
3758 G.postRedisplay "listview scroll";
3761 let _, position, sh = self#
scrollph in
3762 if y > truncate
position && y < truncate
(position +. sh)
3764 state.mstate
<- Mscrolly
;
3768 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3769 let first = truncate
(s *. float source#getitemcount
) in
3770 let first = min source#getitemcount
first in
3771 Some
(coe {< m_first
= first; m_active
= first >})
3773 state.mstate
<- Mnone
;
3776 | 1 when not down
->
3777 begin match self#elemunder
y with
3779 G.postRedisplay "listview click";
3781 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3785 | n when (n == 4 || n == 5) && not down
->
3786 let len = source#getitemcount
in
3788 if n = 5 && m_first
+ fstate.maxrows
>= len
3792 let first = m_first
+ (if n == 4 then -1 else 1) in
3793 bound first 0 (len - 1)
3795 G.postRedisplay "listview wheel";
3796 Some
(coe {< m_first
= first >})
3797 | n when (n = 6 || n = 7) && not down
->
3798 let inc = m_first
+ (if n = 7 then -1 else 1) in
3799 G.postRedisplay "listview hwheel";
3800 Some
(coe {< m_pan
= m_pan
+ inc >})
3805 | None
-> m_prev_uioh
3809 match state.mstate
with
3811 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3812 let first = truncate
(s *. float source#getitemcount
) in
3813 let first = min source#getitemcount
first in
3814 G.postRedisplay "listview motion";
3815 coe {< m_first
= first; m_active
= first >}
3818 method pmotion
x y =
3819 if x < state.winw
- conf.scrollbw
3822 match self#elemunder
y with
3823 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3824 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3828 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3833 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3837 method infochanged
_ = ()
3839 method scrollpw
= (0, 0.0, 0.0)
3841 let nfs = fstate.fontsize
+ 1 in
3842 let y = m_first
* nfs in
3843 let itemcount = source#getitemcount
in
3844 let maxi = max
0 (itemcount - fstate.maxrows
) in
3845 let maxy = maxi * nfs in
3846 let p, h = scrollph y maxy in
3849 method modehash
= modehash
3850 method eformsgs
= false
3853 class outlinelistview ~source
=
3856 ~source
:(source
:> lvsource
)
3858 ~modehash
:(findkeyhash conf "outline")
3861 method key key mask
=
3862 let calcfirst first active =
3865 let rows = active - first in
3867 if String.length
state.text = 0
3869 else fstate.maxrows - 2
3871 if rows > maxrows then active - maxrows else first
3875 let active = m_active
+ incr in
3876 let active = bound active 0 (source#getitemcount
- 1) in
3877 let first = calcfirst m_first
active in
3878 G.postRedisplay "outline navigate";
3879 coe {< m_active
= active; m_first
= first >}
3881 let ctrl = Wsi.withctrl mask
in
3883 | 110 when ctrl -> (* ctrl-n *)
3884 source#narrow m_qsearch
;
3885 G.postRedisplay "outline ctrl-n";
3886 coe {< m_first
= 0; m_active
= 0 >}
3888 | 117 when ctrl -> (* ctrl-u *)
3890 G.postRedisplay "outline ctrl-u";
3892 coe {< m_first
= 0; m_active
= 0 >}
3894 | 108 when ctrl -> (* ctrl-l *)
3895 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3896 G.postRedisplay "outline ctrl-l";
3897 coe {< m_first
= first >}
3899 | 0xff9f | 0xffff -> (* (kp) delete *)
3900 source#remove m_active
;
3901 G.postRedisplay "outline delete";
3902 let active = max
0 (m_active
-1) in
3903 coe {< m_first
= firstof m_first
active;
3904 m_active
= active >}
3906 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3907 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3908 | 0xff55 | 0xff9a -> (* (kp) prior *)
3909 navigate ~
-(fstate.maxrows)
3910 | 0xff56 | 0xff9b -> (* (kp) next *)
3911 navigate fstate.maxrows
3913 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3917 G.postRedisplay "outline ctrl right";
3918 {< m_pan
= m_pan
+ 1 >}
3920 else self#updownlevel
1
3924 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3928 G.postRedisplay "outline ctrl left";
3929 {< m_pan
= m_pan
- 1 >}
3931 else self#updownlevel ~
-1
3935 | 0xff50 | 0xff95 -> (* (kp) home *)
3936 G.postRedisplay "outline home";
3937 coe {< m_first
= 0; m_active
= 0 >}
3939 | 0xff57 | 0xff9c -> (* (kp) end *)
3940 let active = source#getitemcount
- 1 in
3941 let first = max
0 (active - fstate.maxrows) in
3942 G.postRedisplay "outline end";
3943 coe {< m_active
= active; m_first
= first >}
3945 | _ -> super#
key key mask
3948 let outlinesource usebookmarks
=
3951 inherit lvsourcebase
3952 val mutable m_items
= empty
3953 val mutable m_orig_items
= empty
3954 val mutable m_prev_items
= empty
3955 val mutable m_narrow_pattern
= ""
3956 val mutable m_hadremovals
= false
3958 method getitemcount
=
3959 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3962 if n == Array.length m_items
&& m_hadremovals
3964 ("[Confirm removal]", 0)
3966 let s, n, _ = m_items
.(n) in
3969 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3970 ignore
(uioh
, first, qsearch);
3971 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3973 if String.length m_narrow_pattern
= 0
3979 if not
confrimremoval
3981 let _, _, anchor = m_items
.(active) in
3982 gotoghyll (getanchory anchor);
3986 state.bookmarks
<- Array.to_list m_items
;
3987 m_orig_items
<- m_items
;
3990 else m_items
<- items;
3994 method hasaction
_ = true
3997 if Array.length m_items
!= Array.length m_orig_items
3998 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
4001 method narrow
pattern =
4002 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4006 let rec loop accu n =
4009 m_narrow_pattern
<- pattern;
4010 m_items
<- Array.of_list
accu
4013 let (s, _, _) as o = m_items
.(n) in
4015 if (try ignore
(Str.search_forward
re s 0); true
4016 with Not_found
-> false)
4022 loop [] (Array.length m_items
- 1)
4027 then Array.of_list
state.bookmarks
4030 m_items
<- m_orig_items
4035 if m >= 0 && m < Array.length m_items
4037 m_hadremovals
<- true;
4038 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4039 let n = if n >= m then n+1 else n in
4044 method reset
anchor items =
4045 m_hadremovals
<- false;
4046 if m_orig_items
== empty || m_prev_items
!= items
4048 m_orig_items
<- items;
4049 if String.length m_narrow_pattern
= 0
4050 then m_items
<- items;
4052 m_prev_items
<- items;
4053 let rely = getanchory anchor in
4055 let rec loop n best bestd
=
4056 if n = Array.length m_items
4059 let (_, _, anchor) = m_items
.(n) in
4060 let orely = getanchory anchor in
4061 let d = abs
(orely - rely) in
4064 else loop (n+1) best bestd
4069 m_first
<- firstof m_first
active
4073 let enterselector usebookmarks
=
4074 let source = outlinesource usebookmarks
in
4078 then Array.of_list
state.bookmarks
4081 if Array.length
outlines = 0
4083 showtext ' ' errmsg
;
4086 state.text <- source#greetmsg
;
4087 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4088 let anchor = getanchor () in
4089 source#reset
anchor outlines;
4090 state.uioh
<- coe (new outlinelistview ~
source);
4091 G.postRedisplay "enter selector";
4095 let enteroutlinemode =
4096 let f = enterselector false in
4097 fun ()-> f "Document has no outline";
4100 let enterbookmarkmode =
4101 let f = enterselector true in
4102 fun () -> f "Document has no bookmarks (yet)";
4105 let color_of_string s =
4106 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4107 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4111 let color_to_string (r, g, b) =
4112 let r = truncate
(r *. 256.0)
4113 and g = truncate
(g *. 256.0)
4114 and b = truncate
(b *. 256.0) in
4115 Printf.sprintf
"%d/%d/%d" r g b
4118 let irect_of_string s =
4119 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4122 let irect_to_string (x0,y0,x1,y1) =
4123 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4126 let makecheckers () =
4127 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4129 converted by Issac Trotts. July 25, 2002 *)
4130 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4131 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4132 let id = GlTex.gen_texture
() in
4133 GlTex.bind_texture `texture_2d
id;
4134 GlPix.store
(`unpack_alignment
1);
4135 GlTex.image2d
image;
4136 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4137 [ `mag_filter `nearest
; `min_filter `nearest
];
4141 let setcheckers enabled
=
4142 match state.texid
with
4144 if enabled
then state.texid
<- Some
(makecheckers ())
4149 GlTex.delete_texture texid
;
4150 state.texid
<- None
;
4154 let int_of_string_with_suffix s =
4155 let l = String.length
s in
4159 let suffix = Char.lowercase
s.[l-1] in
4161 | 'k'
-> String.sub
s 0 (l-1), 10
4162 | '
m'
-> String.sub
s 0 (l-1), 20
4163 | '
g'
-> String.sub
s 0 (l-1), 30
4167 let n = int_of_string
s1 in
4168 let m = n lsl shift
in
4170 then raise
(Failure
"value too large")
4174 let string_with_suffix_of_int n =
4179 if n land ((1 lsl 30) - 1) = 0
4182 if n land ((1 lsl 20) - 1) = 0
4185 if n land ((1 lsl 10) - 1) = 0
4192 let h = n mod 1000 in
4195 then string_of_int
h ^
s
4197 let s = Printf.sprintf
"_%03d%s" h s in
4204 let defghyllscroll = (40, 8, 32);;
4205 let ghyllscroll_of_string s =
4206 let (n, a, b) as nab
=
4209 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4211 if n <= a || n <= b || a >= b
4212 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4216 let ghyllscroll_to_string ((n, a, b) as nab
) =
4217 if nab
= defghyllscroll
4219 else Printf.sprintf
"%d,%d,%d" n a b;
4222 let describe_location () =
4223 let fn = page_of_y state.y in
4224 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4225 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4229 else (100. *. (float state.y /. float maxy))
4233 Printf.sprintf
"page %d of %d [%.2f%%]"
4234 (fn+1) state.pagecount
percent
4237 "pages %d-%d of %d [%.2f%%]"
4238 (fn+1) (ln+1) state.pagecount
percent
4241 let setpresentationmode v
=
4242 let n = page_of_y state.y in
4243 state.anchor <- (n, 0.0, 1.0);
4244 conf.presentation
<- v
;
4245 if conf.fitmodel
= FitPage
4246 then reqlayout conf.angle
conf.fitmodel
;
4251 let btos b = if b then "\xe2\x88\x9a" else "" in
4252 let showextended = ref false in
4253 let leave mode
= function
4254 | Confirm
-> state.mode
<- mode
4255 | Cancel
-> state.mode
<- mode
in
4258 val mutable m_first_time
= true
4259 val mutable m_l
= []
4260 val mutable m_a
= [||]
4261 val mutable m_prev_uioh
= nouioh
4262 val mutable m_prev_mode
= View
4264 inherit lvsourcebase
4266 method reset prev_mode prev_uioh
=
4267 m_a
<- Array.of_list
(List.rev m_l
);
4269 m_prev_mode
<- prev_mode
;
4270 m_prev_uioh
<- prev_uioh
;
4274 if n >= Array.length m_a
4278 | _, _, _, Action
_ -> m_active
<- n
4282 m_first_time
<- false;
4285 method int name get
set =
4287 (name, `
int get
, 1, Action
(
4290 try set (int_of_string
s)
4292 state.text <- Printf.sprintf
"bad integer `%s': %s"
4296 let te = name ^
": ", "", None
, intentry, ondone, true in
4297 state.mode
<- Textentry
(te, leave m_prev_mode
);
4301 method int_with_suffix
name get
set =
4303 (name, `intws get
, 1, Action
(
4306 try set (int_of_string_with_suffix s)
4308 state.text <- Printf.sprintf
"bad integer `%s': %s"
4313 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4315 state.mode
<- Textentry
(te, leave m_prev_mode
);
4319 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4321 (name, `
bool (btos, get
), offset
, Action
(
4328 method color
name get
set =
4330 (name, `color get
, 1, Action
(
4332 let invalid = (nan
, nan
, nan
) in
4335 try color_of_string s
4337 state.text <- Printf.sprintf
"bad color `%s': %s"
4344 let te = name ^
": ", "", None
, textentry, ondone, true in
4345 state.text <- color_to_string (get
());
4346 state.mode
<- Textentry
(te, leave m_prev_mode
);
4350 method string name get
set =
4352 (name, `
string get
, 1, Action
(
4354 let ondone s = set s in
4355 let te = name ^
": ", "", None
, textentry, ondone, true in
4356 state.mode
<- Textentry
(te, leave m_prev_mode
);
4360 method colorspace
name get
set =
4362 (name, `
string get
, 1, Action
(
4366 inherit lvsourcebase
4369 m_active
<- CSTE.to_int conf.colorspace
;
4372 method getitemcount
=
4373 Array.length
CSTE.names
4376 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4377 ignore
(uioh
, first, pan
, qsearch);
4378 if not cancel
then set active;
4380 method hasaction
_ = true
4384 let modehash = findkeyhash conf "info" in
4385 coe (new listview ~
source ~trusted
:true ~
modehash)
4388 method paxmark
name get
set =
4390 (name, `
string get
, 1, Action
(
4394 inherit lvsourcebase
4397 m_active
<- MTE.to_int conf.paxmark
;
4400 method getitemcount
= Array.length
MTE.names
4401 method getitem
n = (MTE.names.(n), 0)
4402 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4403 ignore
(uioh
, first, pan
, qsearch);
4404 if not cancel
then set active;
4406 method hasaction
_ = true
4410 let modehash = findkeyhash conf "info" in
4411 coe (new listview ~
source ~trusted
:true ~
modehash)
4414 method fitmodel
name get
set =
4416 (name, `
string get
, 1, Action
(
4420 inherit lvsourcebase
4423 m_active
<- FMTE.to_int conf.fitmodel
;
4426 method getitemcount
= Array.length
FMTE.names
4427 method getitem
n = (FMTE.names.(n), 0)
4428 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4429 ignore
(uioh
, first, pan
, qsearch);
4430 if not cancel
then set active;
4432 method hasaction
_ = true
4436 let modehash = findkeyhash conf "info" in
4437 coe (new listview ~
source ~trusted
:true ~
modehash)
4440 method caption
s offset
=
4441 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4443 method caption2
s f offset
=
4444 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4446 method getitemcount
= Array.length m_a
4449 let tostr = function
4450 | `
int f -> string_of_int
(f ())
4451 | `intws
f -> string_with_suffix_of_int (f ())
4453 | `color
f -> color_to_string (f ())
4454 | `
bool (btos, f) -> btos (f ())
4457 let name, t
, offset
, _ = m_a
.(n) in
4458 ((let s = tostr t
in
4459 if String.length
s > 0
4460 then Printf.sprintf
"%s\t%s" name s
4464 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4468 m_qsearch
<- qsearch;
4470 match m_a
.(active) with
4471 | _, _, _, Action
f -> f uioh
4483 method hasaction
n =
4485 | _, _, _, Action
_ -> true
4489 let rec fillsrc prevmode prevuioh
=
4490 let sep () = src#caption
"" 0 in
4491 let colorp name get
set =
4493 (fun () -> color_to_string (get
()))
4496 let c = color_of_string v in
4499 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4502 let oldmode = state.mode
in
4503 let birdseye = isbirdseye state.mode
in
4505 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4507 src#
bool "presentation mode"
4508 (fun () -> conf.presentation
)
4509 (fun v -> setpresentationmode v);
4511 src#
bool "ignore case in searches"
4512 (fun () -> conf.icase
)
4513 (fun v -> conf.icase
<- v);
4516 (fun () -> conf.preload)
4517 (fun v -> conf.preload <- v);
4519 src#
bool "highlight links"
4520 (fun () -> conf.hlinks
)
4521 (fun v -> conf.hlinks
<- v);
4523 src#
bool "under info"
4524 (fun () -> conf.underinfo
)
4525 (fun v -> conf.underinfo
<- v);
4527 src#
bool "persistent bookmarks"
4528 (fun () -> conf.savebmarks
)
4529 (fun v -> conf.savebmarks
<- v);
4531 src#fitmodel
"fit model"
4532 (fun () -> FMTE.to_string conf.fitmodel
)
4533 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4535 src#
bool "trim margins"
4536 (fun () -> conf.trimmargins
)
4537 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4539 src#
bool "persistent location"
4540 (fun () -> conf.jumpback
)
4541 (fun v -> conf.jumpback
<- v);
4544 src#
int "inter-page space"
4545 (fun () -> conf.interpagespace
)
4547 conf.interpagespace
<- n;
4548 docolumns conf.columns
;
4550 match state.layout with
4555 state.maxy <- calcheight ();
4556 let y = getpagey pageno in
4561 (fun () -> conf.pagebias
)
4562 (fun v -> conf.pagebias
<- v);
4564 src#
int "scroll step"
4565 (fun () -> conf.scrollstep
)
4566 (fun n -> conf.scrollstep
<- n);
4568 src#
int "horizontal scroll step"
4569 (fun () -> conf.hscrollstep
)
4570 (fun v -> conf.hscrollstep
<- v);
4572 src#
int "auto scroll step"
4574 match state.autoscroll
with
4576 | _ -> conf.autoscrollstep
)
4578 if state.autoscroll
<> None
4579 then state.autoscroll
<- Some
n;
4580 conf.autoscrollstep
<- n);
4583 (fun () -> truncate
(conf.zoom *. 100.))
4584 (fun v -> setzoom ((float v) /. 100.));
4587 (fun () -> conf.angle
)
4588 (fun v -> reqlayout v conf.fitmodel
);
4590 src#
int "scroll bar width"
4591 (fun () -> conf.scrollbw
)
4594 reshape state.winw
state.winh
;
4597 src#
int "scroll handle height"
4598 (fun () -> conf.scrollh
)
4599 (fun v -> conf.scrollh
<- v;);
4601 src#
int "thumbnail width"
4602 (fun () -> conf.thumbw
)
4604 conf.thumbw
<- min
4096 v;
4607 leavebirdseye beye
false;
4612 let mode = state.mode in
4613 src#
string "columns"
4615 match conf.columns
with
4617 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4618 | Csplit
(count
, _) -> "-" ^ string_of_int count
4621 let n, a, b = multicolumns_of_string v in
4622 setcolumns mode n a b);
4625 src#caption
"Pixmap cache" 0;
4626 src#int_with_suffix
"size (advisory)"
4627 (fun () -> conf.memlimit
)
4628 (fun v -> conf.memlimit
<- v);
4631 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4632 (string_with_suffix_of_int state.memused
)
4633 (Hashtbl.length
state.tilemap
)) 1;
4636 src#caption
"Layout" 0;
4637 src#caption2
"Dimension"
4639 Printf.sprintf
"%dx%d (virtual %dx%d)"
4640 state.winw
state.winh
4645 src#caption2
"Position" (fun () ->
4646 Printf.sprintf
"%dx%d" state.x state.y
4649 src#caption2
"Position" (fun () -> describe_location ()) 1
4653 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4654 "Save these parameters as global defaults at exit"
4655 (fun () -> conf.bedefault
)
4656 (fun v -> conf.bedefault
<- v)
4660 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4661 src#
bool ~offset
:0 ~
btos "Extended parameters"
4662 (fun () -> !showextended)
4663 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4667 (fun () -> conf.checkers
)
4668 (fun v -> conf.checkers
<- v; setcheckers v);
4669 src#
bool "update cursor"
4670 (fun () -> conf.updatecurs
)
4671 (fun v -> conf.updatecurs
<- v);
4673 (fun () -> conf.verbose
)
4674 (fun v -> conf.verbose
<- v);
4675 src#
bool "invert colors"
4676 (fun () -> conf.invert
)
4677 (fun v -> conf.invert
<- v);
4679 (fun () -> conf.maxhfit
)
4680 (fun v -> conf.maxhfit
<- v);
4681 src#
bool "redirect stderr"
4682 (fun () -> conf.redirectstderr)
4683 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4685 (fun () -> conf.pax
!= None
)
4688 then conf.pax
<- Some
(ref (now (), 0, 0))
4689 else conf.pax
<- None
);
4690 src#
string "uri launcher"
4691 (fun () -> conf.urilauncher
)
4692 (fun v -> conf.urilauncher
<- v);
4693 src#
string "path launcher"
4694 (fun () -> conf.pathlauncher
)
4695 (fun v -> conf.pathlauncher
<- v);
4696 src#
string "tile size"
4697 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4700 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4701 conf.tilew
<- max
64 w;
4702 conf.tileh
<- max
64 h;
4705 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4708 src#
int "texture count"
4709 (fun () -> conf.texcount
)
4712 then conf.texcount
<- v
4713 else showtext '
!'
" Failed to set texture count please retry later"
4715 src#
int "slice height"
4716 (fun () -> conf.sliceheight
)
4718 conf.sliceheight
<- v;
4719 wcmd "sliceh %d" conf.sliceheight
;
4721 src#
int "anti-aliasing level"
4722 (fun () -> conf.aalevel
)
4724 conf.aalevel
<- bound v 0 8;
4725 state.anchor <- getanchor ();
4726 opendoc state.path
state.password
;
4728 src#
string "page scroll scaling factor"
4729 (fun () -> string_of_float
conf.pgscale)
4732 let s = float_of_string
v in
4735 state.text <- Printf.sprintf
4736 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4739 src#
int "ui font size"
4740 (fun () -> fstate.fontsize
)
4741 (fun v -> setfontsize (bound v 5 100));
4742 src#
int "hint font size"
4743 (fun () -> conf.hfsize
)
4744 (fun v -> conf.hfsize
<- bound v 5 100);
4745 colorp "background color"
4746 (fun () -> conf.bgcolor
)
4747 (fun v -> conf.bgcolor
<- v);
4748 src#
bool "crop hack"
4749 (fun () -> conf.crophack
)
4750 (fun v -> conf.crophack
<- v);
4751 src#
string "trim fuzz"
4752 (fun () -> irect_to_string conf.trimfuzz
)
4755 conf.trimfuzz
<- irect_of_string v;
4757 then settrim true conf.trimfuzz
;
4759 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4761 src#
string "throttle"
4763 match conf.maxwait
with
4764 | None
-> "show place holder if page is not ready"
4767 then "wait for page to fully render"
4769 "wait " ^ string_of_float
time
4770 ^
" seconds before showing placeholder"
4774 let f = float_of_string
v in
4776 then conf.maxwait
<- None
4777 else conf.maxwait
<- Some
f
4779 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4781 src#
string "ghyll scroll"
4783 match conf.ghyllscroll
with
4785 | Some nab
-> ghyllscroll_to_string nab
4790 if String.length
v = 0
4792 else Some
(ghyllscroll_of_string v)
4794 conf.ghyllscroll
<- gs
4796 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4798 src#
string "selection command"
4799 (fun () -> conf.selcmd
)
4800 (fun v -> conf.selcmd
<- v);
4801 src#
string "synctex command"
4802 (fun () -> conf.stcmd
)
4803 (fun v -> conf.stcmd
<- v);
4804 src#
string "pax command"
4805 (fun () -> conf.paxcmd
)
4806 (fun v -> conf.paxcmd
<- v);
4807 src#colorspace
"color space"
4808 (fun () -> CSTE.to_string conf.colorspace
)
4810 conf.colorspace
<- CSTE.of_int v;
4814 src#paxmark
"pax mark method"
4815 (fun () -> MTE.to_string conf.paxmark
)
4816 (fun v -> conf.paxmark
<- MTE.of_int v);
4820 (fun () -> conf.usepbo
)
4821 (fun v -> conf.usepbo
<- v);
4822 src#
bool "mouse wheel scrolls pages"
4823 (fun () -> conf.wheelbypage
)
4824 (fun v -> conf.wheelbypage
<- v);
4825 src#
bool "open remote links in a new instance"
4826 (fun () -> conf.riani
)
4827 (fun v -> conf.riani
<- v);
4831 src#caption
"Document" 0;
4832 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4833 src#caption2
"Pages"
4834 (fun () -> string_of_int
state.pagecount
) 1;
4835 src#caption2
"Dimensions"
4836 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4840 src#caption
"Trimmed margins" 0;
4841 src#caption2
"Dimensions"
4842 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4846 src#caption
"OpenGL" 0;
4847 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4848 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4851 src#caption
"Location" 0;
4852 if String.length
state.origin
> 0
4853 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4854 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4856 src#reset prevmode prevuioh
;
4860 let prevmode = state.mode
4861 and prevuioh
= state.uioh in
4862 fillsrc prevmode prevuioh
;
4863 let source = (src :> lvsource
) in
4864 let modehash = findkeyhash conf "info" in
4865 state.uioh <- coe (object (self)
4866 inherit listview ~
source ~trusted
:true ~
modehash as super
4867 val mutable m_prevmemused
= 0
4868 method infochanged
= function
4870 if m_prevmemused
!= state.memused
4872 m_prevmemused
<- state.memused
;
4873 G.postRedisplay "memusedchanged";
4875 | Pdim
-> G.postRedisplay "pdimchanged"
4876 | Docinfo
-> fillsrc prevmode prevuioh
4878 method key key mask
=
4879 if not
(Wsi.withctrl mask
)
4882 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4883 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4884 | _ -> super#
key key mask
4885 else super#
key key mask
4887 G.postRedisplay "info";
4893 inherit lvsourcebase
4894 method getitemcount
= Array.length
state.help
4896 let s, l, _ = state.help
.(n) in
4899 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4903 m_qsearch
<- qsearch;
4904 match state.help
.(active) with
4905 | _, _, Action
f -> Some
(f uioh)
4915 method hasaction
n =
4916 match state.help
.(n) with
4917 | _, _, Action
_ -> true
4924 let modehash = findkeyhash conf "help" in
4925 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4926 G.postRedisplay "help";
4931 let re = Str.regexp
"[\r\n]" in
4933 inherit lvsourcebase
4934 val mutable m_items
= [||]
4936 method getitemcount
= 1 + Array.length m_items
4941 else m_items
.(n-1), 0
4943 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4948 then Buffer.clear
state.errmsgs
;
4949 m_qsearch
<- qsearch;
4956 method hasaction
n =
4960 state.newerrmsgs
<- false;
4961 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4962 m_items
<- Array.of_list
l
4970 let source = (msgsource :> lvsource
) in
4971 let modehash = findkeyhash conf "listview" in
4972 state.uioh <- coe (object
4973 inherit listview ~
source ~trusted
:false ~
modehash as super
4976 then msgsource#reset
;
4979 G.postRedisplay "msgs";
4982 let quickbookmark ?title
() =
4983 match state.layout with
4989 let sec = Unix.gettimeofday
() in
4990 let tm = Unix.localtime
sec in
4991 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4995 (tm.Unix.tm_year
+ 1900)
4998 | Some
title -> title
5000 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
5003 let setautoscrollspeed step goingdown
=
5004 let incr = max
1 ((abs step
) / 2) in
5005 let incr = if goingdown
then incr else -incr in
5006 let astep = step
+ incr in
5007 state.autoscroll
<- Some
astep;
5010 let gotounder = function
5011 | Ulinkgoto
(pageno, top) ->
5015 gotopage1 pageno top;
5021 | Uremote
(filename
, pageno) ->
5023 if String.length filename
> 0
5025 if Filename.is_relative filename
5027 let dir = Filename.dirname
state.path in
5029 if Filename.is_implicit
dir
5030 then Filename.concat
(Sys.getcwd
()) dir
5033 Filename.concat
dir filename
5038 if Sys.file_exists
path
5042 if String.length
path > 0
5046 let command = !selfexec ^
" " ^
path in
5047 try popen command []
5050 "failed to execute `%s': %s\n" command (exntos exn
);
5053 let anchor = getanchor () in
5054 let ranchor = state.path, state.password
, anchor, state.origin
in
5056 state.anchor <- (pageno, 0.0, 0.0);
5057 state.ranchors
<- ranchor :: state.ranchors
;
5060 else showtext '
!'
("Could not find " ^ filename
)
5062 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
5066 match conf.columns
with
5068 | _ -> state.x != 0 || conf.zoom > 1.0
5071 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5073 let existsinrow pageno (columns
, coverA
, coverB
) p =
5074 let last = ((pageno - coverA
) mod columns
) + columns
in
5075 let rec any = function
5078 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5082 then (if l.pageno = last then false else any rest
)
5090 match state.layout with
5092 let pageno = page_of_y state.y in
5093 gotoghyll (getpagey (pageno+1))
5095 match conf.columns
with
5097 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5099 let y = clamp (pgscale state.winh
) in
5102 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5103 gotoghyll (getpagey pageno)
5104 | Cmulti
((c, _, _) as cl, _) ->
5105 if conf.presentation
5106 && (existsinrow l.pageno cl
5107 (fun l -> l.pageh
> l.pagey + l.pagevh))
5109 let y = clamp (pgscale state.winh
) in
5112 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5113 gotoghyll (getpagey pageno)
5115 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5117 let pagey, pageh
= getpageyh l.pageno in
5118 let pagey = pagey + pageh
* l.pagecol
in
5119 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5120 gotoghyll (pagey + pageh
+ ips)
5124 match state.layout with
5126 let pageno = page_of_y state.y in
5127 gotoghyll (getpagey (pageno-1))
5129 match conf.columns
with
5131 if conf.presentation
&& l.pagey != 0
5133 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5135 let pageno = max
0 (l.pageno-1) in
5136 gotoghyll (getpagey pageno)
5137 | Cmulti
((c, _, coverB
) as cl, _) ->
5138 if conf.presentation
&&
5139 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5141 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5144 if l.pageno = state.pagecount
- coverB
5148 let pageno = max
0 (l.pageno-decr) in
5149 gotoghyll (getpagey pageno)
5157 let pageno = max
0 (l.pageno-1) in
5158 let pagey, pageh
= getpageyh pageno in
5161 let pagey, pageh
= getpageyh l.pageno in
5162 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5167 let viewkeyboard key mask
=
5169 let mode = state.mode in
5170 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5173 G.postRedisplay "view:enttext"
5175 let ctrl = Wsi.withctrl mask
in
5177 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5183 | 0xff63 -> (* insert *)
5184 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5186 state.mode <- LinkNav
(Ltgendir
0);
5189 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5191 | 0xff1b | 113 -> (* escape / q *)
5192 begin match state.mstate
with
5194 state.mstate
<- Mnone
;
5195 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5196 G.postRedisplay "kill zoom rect";
5198 begin match state.mode with
5201 G.postRedisplay "esc leave linknav"
5203 match state.ranchors
with
5205 | (path, password
, anchor, origin
) :: rest
->
5206 state.ranchors
<- rest
;
5207 state.anchor <- anchor;
5208 state.origin
<- origin
;
5209 opendoc path password
5213 | 0xff08 -> (* backspace *)
5214 gotoghyll (getnav ~
-1)
5222 G.postRedisplay "dehighlight";
5224 | 47 | 63 -> (* / ? *)
5225 let ondone isforw
s =
5226 cbput state.hists
.pat
s;
5227 state.searchpattern
<- s;
5230 let s = String.create
1 in
5231 s.[0] <- Char.chr
key;
5232 enttext (s, "", Some
(onhist state.hists
.pat
),
5233 textentry, ondone (key = 47), true)
5235 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5236 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5237 setzoom (conf.zoom +. incr)
5239 | 43 | 0xffab -> (* + *)
5242 try int_of_string
s with exc
->
5243 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5249 state.text <- "page bias is now " ^ string_of_int
n;
5252 enttext ("page bias: ", "", None
, intentry, ondone, true)
5254 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5255 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5256 setzoom (max
0.01 (conf.zoom -. decr))
5258 | 45 | 0xffad -> (* - *)
5259 let ondone msg
= state.text <- msg
in
5261 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5262 optentry state.mode, ondone, true
5265 | 48 when ctrl -> (* ctrl-0 *)
5273 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5275 match conf.columns
with
5276 | Csingle
_ | Cmulti
_ -> 1
5277 | Csplit
(n, _) -> n
5279 let h = state.winh
-
5280 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5282 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5283 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5286 | 51 when ctrl -> (* ctrl-3 *)
5288 match conf.fitmodel
with
5289 | FitWidth
-> FitProportional
5290 | FitProportional
-> FitPage
5291 | FitPage
-> FitWidth
5293 state.text <- "fit model: " ^
FMTE.to_string fm;
5294 reqlayout conf.angle
fm
5296 | 0xffc6 -> (* f9 *)
5299 | 57 when ctrl -> (* ctrl-9 *)
5302 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5303 when not
ctrl -> (* 0..9 *)
5306 try int_of_string
s with exc
->
5307 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5313 cbput state.hists
.pag
(string_of_int
n);
5314 gotopage1 (n + conf.pagebias
- 1) 0;
5317 let pageentry text key =
5318 match Char.unsafe_chr
key with
5319 | '
g'
-> TEdone
text
5320 | _ -> intentry text key
5322 let text = "x" in text.[0] <- Char.chr
key;
5323 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5326 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5327 reshape state.winw
state.winh
;
5330 state.bzoom
<- not
state.bzoom
;
5332 showtext ' '
("block zoom " ^
if state.bzoom
then "on" else "off")
5335 conf.hlinks
<- not
conf.hlinks
;
5336 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5337 G.postRedisplay "toggle highlightlinks";
5340 state.glinks
<- true;
5341 let mode = state.mode in
5342 state.mode <- Textentry
(
5343 (":", "", None
, linknentry, linkndone gotounder, false),
5345 state.glinks
<- false;
5349 G.postRedisplay "view:linkent(F)"
5352 state.glinks
<- true;
5353 let mode = state.mode in
5354 state.mode <- Textentry
(
5356 ":", "", None
, linknentry, linkndone (fun under ->
5357 selstring (undertext under);
5361 state.glinks
<- false;
5365 G.postRedisplay "view:linkent"
5368 begin match state.autoscroll
with
5370 conf.autoscrollstep
<- step
;
5371 state.autoscroll
<- None
5373 if conf.autoscrollstep
= 0
5374 then state.autoscroll
<- Some
1
5375 else state.autoscroll
<- Some
conf.autoscrollstep
5378 | 112 when ctrl -> (* ctrl-p *)
5382 setpresentationmode (not
conf.presentation
);
5383 showtext ' '
("presentation mode " ^
5384 if conf.presentation
then "on" else "off");
5387 if List.mem
Wsi.Fullscreen
state.winstate
5388 then Wsi.reshape conf.cwinw
conf.cwinh
5389 else Wsi.fullscreen
()
5391 | 112 | 78 -> (* p|N *)
5392 search state.searchpattern
false
5394 | 110 | 0xffc0 -> (* n|F3 *)
5395 search state.searchpattern
true
5398 begin match state.layout with
5401 gotoghyll (getpagey l.pageno)
5407 | 0xff9f | 0xffff -> (* delete *)
5411 showtext ' '
(describe_location ());
5414 begin match state.layout with
5417 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5422 enterbookmarkmode ()
5424 | 104 | 0xffbe -> (* h|F1 *)
5430 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5435 match state.layout with
5437 if String.length
s > 0
5439 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5442 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5446 showtext ' '
"Quick bookmark added";
5449 begin match state.layout with
5451 let rect = getpdimrect
l.pagedimno
in
5455 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5456 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5458 (truncate
(rect.(1) -. rect.(0)),
5459 truncate
(rect.(3) -. rect.(0)))
5461 let w = truncate
((float w)*.conf.zoom)
5462 and h = truncate
((float h)*.conf.zoom) in
5465 state.anchor <- getanchor ();
5466 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5468 G.postRedisplay "z";
5473 | 120 -> state.roam
()
5474 | 60 | 62 -> (* < > *)
5475 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5477 | 91 | 93 -> (* [ ] *)
5479 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5481 G.postRedisplay "brightness";
5483 | 99 when state.mode = View
-> (* [alt-]c *)
5488 let m = (wadjsb state.winw
- state.w) / 2 in
5490 gotoy_and_clear_text state.y
5494 match state.prevcolumns
with
5495 | None
-> (1, 0, 0), 1.0
5496 | Some
(columns
, z
) ->
5499 | Csplit
(c, _) -> -c, 0, 0
5500 | Cmulti
((c, a, b), _) -> c, a, b
5501 | Csingle
_ -> 1, 0, 0
5505 setcolumns View
c a b;
5508 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
5509 -> (* ctrl-shift- (kp) [up|down] *)
5510 let zoom, x = state.prevzoom
in
5514 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5515 begin match state.autoscroll
with
5517 begin match state.mode with
5518 | Birdseye beye
-> upbirdseye 1 beye
5521 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5523 if not
(Wsi.withshift mask
) && conf.presentation
5525 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5529 setautoscrollspeed n false
5532 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5533 begin match state.autoscroll
with
5535 begin match state.mode with
5536 | Birdseye beye
-> downbirdseye 1 beye
5539 then gotoy_and_clear_text (clamp (state.winh
/2))
5541 if not
(Wsi.withshift mask
) && conf.presentation
5543 else gotoy_and_clear_text (clamp conf.scrollstep
)
5547 setautoscrollspeed n true
5550 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5551 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5557 else conf.hscrollstep
5559 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5560 state.x <- panbound (state.x + dx);
5561 gotoy_and_clear_text state.y
5564 G.postRedisplay "left/right"
5567 | 0xff55 | 0xff9a -> (* (kp) prior *)
5571 match state.layout with
5573 | l :: _ -> state.y - l.pagey
5575 clamp (pgscale (-state.winh
))
5579 | 0xff56 | 0xff9b -> (* (kp) next *)
5583 match List.rev
state.layout with
5585 | l :: _ -> getpagey l.pageno
5587 clamp (pgscale state.winh
)
5591 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5593 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5594 gotoghyll (clamp state.maxy)
5597 when Wsi.withalt mask
-> (* alt-(kp) right *)
5598 gotoghyll (getnav 1)
5600 when Wsi.withalt mask
-> (* alt-(kp) left *)
5601 gotoghyll (getnav ~
-1)
5606 | 118 when conf.debug
-> (* v *)
5609 match getopaque l.pageno with
5612 let x0, y0, x1, y1 = pagebbox opaque
in
5613 let a,b = float x0, float y0 in
5614 let c,d = float x1, float y0 in
5615 let e,f = float x1, float y1 in
5616 let h,j
= float x0, float y1 in
5617 let rect = (a,b,c,d,e,f,h,j
) in
5619 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5621 G.postRedisplay "v";
5624 vlog "huh? %s" (Wsi.keyname
key)
5627 let linknavkeyboard key mask
linknav =
5628 let getpage pageno =
5629 let rec loop = function
5631 | l :: _ when l.pageno = pageno -> Some
l
5632 | _ :: rest
-> loop rest
5633 in loop state.layout
5635 let doexact (pageno, n) =
5636 match getopaque pageno, getpage pageno with
5637 | Some opaque
, Some
l ->
5638 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5640 let under = getlink opaque
n in
5641 G.postRedisplay "link gotounder";
5647 | 0xff50 -> (* home *)
5648 Some
(findlink opaque LDfirst
), -1
5650 | 0xff57 -> (* end *)
5651 Some
(findlink opaque LDlast
), 1
5653 | 0xff51 -> (* left *)
5654 Some
(findlink opaque
(LDleft
n)), -1
5656 | 0xff53 -> (* right *)
5657 Some
(findlink opaque
(LDright
n)), 1
5659 | 0xff52 -> (* up *)
5660 Some
(findlink opaque
(LDup
n)), -1
5662 | 0xff54 -> (* down *)
5663 Some
(findlink opaque
(LDdown
n)), 1
5668 begin match findpwl
l.pageno dir with
5672 state.mode <- LinkNav
(Ltgendir
dir);
5673 let y, h = getpageyh pageno in
5676 then y + h - state.winh
5681 begin match getopaque pageno, getpage pageno with
5682 | Some opaque
, Some
_ ->
5684 let ld = if dir > 0 then LDfirst
else LDlast
in
5687 begin match link with
5689 showlinktype (getlink opaque
m);
5690 state.mode <- LinkNav
(Ltexact
(pageno, m));
5691 G.postRedisplay "linknav jpage";
5698 begin match opt with
5699 | Some Lnotfound
-> pwl l dir;
5700 | Some
(Lfound
m) ->
5704 let _, y0, _, y1 = getlinkrect opaque
m in
5706 then gotopage1 l.pageno y0
5708 let d = fstate.fontsize
+ 1 in
5709 if y1 - l.pagey > l.pagevh - d
5710 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5711 else G.postRedisplay "linknav";
5713 showlinktype (getlink opaque
m);
5714 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5717 | None
-> viewkeyboard key mask
5719 | _ -> viewkeyboard key mask
5724 G.postRedisplay "leave linknav"
5728 | Ltgendir
_ -> viewkeyboard key mask
5729 | Ltexact exact
-> doexact exact
5732 let keyboard key mask
=
5733 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5734 then wcmd "interrupt"
5735 else state.uioh <- state.uioh#
key key mask
5738 let birdseyekeyboard key mask
5739 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5741 match conf.columns
with
5743 | Cmulti
((c, _, _), _) -> c
5744 | Csplit
_ -> failwith
"bird's eye split mode"
5746 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5748 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5749 let y, h = getpageyh pageno in
5750 let top = (state.winh
- h) / 2 in
5751 gotoy (max
0 (y - top))
5752 | 0xff0d (* enter *)
5753 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5754 | 0xff1b -> leavebirdseye beye
true (* escape *)
5755 | 0xff52 -> upbirdseye incr beye
(* up *)
5756 | 0xff54 -> downbirdseye incr beye
(* down *)
5757 | 0xff51 -> upbirdseye 1 beye
(* left *)
5758 | 0xff53 -> downbirdseye 1 beye
(* right *)
5760 | 0xff55 -> (* prior *)
5761 begin match state.layout with
5765 state.mode <- Birdseye
(
5766 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5768 gotopage1 l.pageno 0;
5771 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5773 | [] -> gotoy (clamp (-state.winh
))
5775 state.mode <- Birdseye
(
5776 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5778 gotopage1 l.pageno 0
5781 | [] -> gotoy (clamp (-state.winh
))
5784 | 0xff56 -> (* next *)
5785 begin match List.rev
state.layout with
5787 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5788 begin match layout with
5790 let incr = l.pageh
- l.pagevh in
5795 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5797 G.postRedisplay "birdseye pagedown";
5799 else gotoy (clamp (incr + conf.interpagespace
*2));
5803 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5804 gotopage1 l.pageno 0;
5807 | [] -> gotoy (clamp state.winh
)
5810 | 0xff50 -> (* home *)
5811 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5814 | 0xff57 -> (* end *)
5815 let pageno = state.pagecount
- 1 in
5816 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5817 if not
(pagevisible state.layout pageno)
5820 match List.rev
state.pdims
with
5822 | (_, _, h, _) :: _ -> h
5824 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5825 else G.postRedisplay "birdseye end";
5826 | _ -> viewkeyboard key mask
5831 match state.mode with
5832 | Textentry
_ -> scalecolor 0.4
5834 | View
-> scalecolor 1.0
5835 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5836 if l.pageno = hooverpageno
5839 if l.pageno = pageno
5847 let postdrawpage l linkindexbase
=
5848 match getopaque l.pageno with
5850 if tileready l l.pagex
l.pagey
5852 let x = l.pagedispx - l.pagex
5853 and y = l.pagedispy - l.pagey in
5855 match conf.columns
with
5856 | Csingle
_ | Cmulti
_ ->
5857 (if conf.hlinks
then 1 else 0)
5859 && not
(isbirdseye state.mode) then 2 else 0)
5863 match state.mode with
5864 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5867 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5872 let scrollindicator () =
5873 let sbw, ph
, sh = state.uioh#
scrollph in
5874 let sbh, pw, sw = state.uioh#scrollpw
in
5876 GlDraw.color (0.64, 0.64, 0.64);
5878 (float (state.winw
- sbw), 0.)
5879 (float state.winw
, float state.winh
)
5882 (0., float (state.winh
- sbh))
5883 (float (wadjsb state.winw
- 1), float state.winh
)
5885 GlDraw.color (0.0, 0.0, 0.0);
5888 (float (state.winw
- sbw), ph
)
5889 (float state.winw
, ph
+. sh)
5892 (pw, float (state.winh
- sbh))
5893 (pw +. sw, float state.winh
)
5898 match state.mstate
with
5899 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5902 | Msel
((x0, y0), (x1, y1)) ->
5903 let rec loop = function
5905 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5906 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5907 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5908 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5910 match getopaque l.pageno with
5912 let x0, y0 = pagetranslatepoint l x0 y0 in
5913 let x1, y1 = pagetranslatepoint l x1 y1 in
5914 seltext opaque
(x0, y0, x1, y1);
5922 let showrects rects
=
5924 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5925 GlDraw.polygon_mode `both `fill
;
5926 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5928 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5930 if l.pageno = pageno
5932 let dx = float (l.pagedispx - l.pagex
) in
5933 let dy = float (l.pagedispy - l.pagey) in
5934 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
5935 GlDraw.begins `quads
;
5937 GlDraw.vertex2
(x0+.dx, y0+.dy);
5938 GlDraw.vertex2
(x1+.dx, y1+.dy);
5939 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5940 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5951 GlClear.color (scalecolor2 conf.bgcolor
);
5952 GlClear.clear
[`
color];
5953 List.iter
drawpage state.layout;
5955 match state.mode with
5956 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5957 begin match getopaque pageno with
5959 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5966 | None
-> state.rects
5971 let rec postloop linkindexbase
= function
5973 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5974 postloop linkindexbase rest
5978 postloop 0 state.layout;
5980 begin match state.mstate
with
5981 | Mzoomrect
((x0, y0), (x1, y1)) ->
5983 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5984 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5985 GlDraw.rect (float x0, float y0)
5986 (float x1, float y1);
5995 let zoomrect x y x1 y1 =
5998 and y0 = min
y y1 in
5999 gotoy (state.y + y0);
6000 state.anchor <- getanchor ();
6001 let zoom = (float state.w) /. float (x1 - x0) in
6003 match conf.fitmodel
, conf.columns
with
6004 | FitPage
, Csplit
_ ->
6005 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6008 let adjw = wadjsb state.winw
in
6010 then (adjw - state.w) / 2
6013 state.x <- (state.x + margin) - x0;
6015 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6016 state.mstate
<- Mnone
;
6020 let g opaque
l px py =
6021 match rectofblock opaque
px py with
6023 let x0 = a.(0) -. 20. in
6024 let x1 = a.(1) +. 20. in
6025 let y0 = a.(2) -. 20. in
6027 gotoy_and_clear_text (getpagey l.pageno + truncate
y0);
6028 state.anchor <- getanchor ();
6029 let zoom = (float state.w) /. (x1 -. x0) in
6030 state.x <- -truncate
x0 - l.pagedispx;
6035 onppundermouse g x y ()
6039 let winw = wadjsb state.winw - 1 in
6040 let s = float x /. float winw in
6041 let destx = truncate
(float (state.w + winw) *. s) in
6042 state.x <- winw - destx;
6043 gotoy_and_clear_text state.y;
6044 state.mstate
<- Mscrollx
;
6048 let s = float y /. float state.winh
in
6049 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6050 gotoy_and_clear_text desty;
6051 state.mstate
<- Mscrolly
;
6054 let viewmouse button down
x y mask
=
6056 | n when (n == 4 || n == 5) && not down
->
6057 if Wsi.withctrl mask
6059 match state.mstate
with
6060 | Mzoom
(oldn
, i
) ->
6068 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6070 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6072 let zoom = conf.zoom -. incr in
6074 state.mstate
<- Mzoom
(n, 0);
6076 state.mstate
<- Mzoom
(n, i
+1);
6078 else state.mstate
<- Mzoom
(n, 0)
6080 | _ -> state.mstate
<- Mzoom
(n, 0)
6083 match state.autoscroll
with
6084 | Some step
-> setautoscrollspeed step
(n=4)
6086 if conf.wheelbypage
|| conf.presentation
6095 then -conf.scrollstep
6096 else conf.scrollstep
6098 let incr = incr * 2 in
6099 let y = clamp incr in
6100 gotoy_and_clear_text y
6103 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6105 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6106 gotoy_and_clear_text state.y
6108 | 1 when Wsi.withshift mask
->
6109 state.mstate
<- Mnone
;
6112 match unproject x y with
6113 | Some
(pageno, ux
, uy
) ->
6114 let cmd = Printf.sprintf
6116 conf.stcmd
state.path pageno ux uy
6122 | 1 when Wsi.withctrl mask
->
6125 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6126 state.mstate
<- Mpan
(x, y)
6129 state.mstate
<- Mnone
6134 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6136 state.mstate
<- Mzoomrect
(p, p)
6139 match state.mstate
with
6140 | Mzoomrect
((x0, y0), _) ->
6141 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6142 then zoomrect x0 y0 x y
6144 state.mstate
<- Mnone
;
6145 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6146 G.postRedisplay "kill accidental zoom rect";
6149 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6150 state.mstate
<- Mnone
6153 | 1 when x > state.winw - vscrollw () ->
6156 let _, position, sh = state.uioh#
scrollph in
6157 if y > truncate
position && y < truncate
(position +. sh)
6158 then state.mstate
<- Mscrolly
6161 state.mstate
<- Mnone
6163 | 1 when y > state.winh
- hscrollh () ->
6166 let _, position, sw = state.uioh#scrollpw
in
6167 if x > truncate
position && x < truncate
(position +. sw)
6168 then state.mstate
<- Mscrollx
6171 state.mstate
<- Mnone
6173 | 1 when state.bzoom
-> zoomblock x y
6176 let dest = if down
then getunder x y else Unone
in
6177 begin match dest with
6181 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6184 | Unone
when down
->
6185 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6186 state.mstate
<- Mpan
(x, y);
6188 | Unone
| Utext
_ ->
6191 if conf.angle
mod 360 = 0
6193 state.mstate
<- Msel
((x, y), (x, y));
6194 G.postRedisplay "mouse select";
6198 match state.mstate
with
6201 | Mzoom
_ | Mscrollx
| Mscrolly
->
6202 state.mstate
<- Mnone
6204 | Mzoomrect
((x0, y0), _) ->
6208 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6209 state.mstate
<- Mnone
6211 | Msel
((x0, y0), (x1, y1)) ->
6212 let rec loop = function
6216 let a0 = l.pagedispy in
6217 let a1 = a0 + l.pagevh in
6218 let b0 = l.pagedispx in
6219 let b1 = b0 + l.pagevw in
6220 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6221 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6225 match getopaque l.pageno with
6228 match Ne.pipe () with
6232 "can not create sel pipe: %s"
6235 let doclose what fd
=
6236 Ne.clo fd
(fun msg
->
6237 dolog
"%s close failed: %s" what msg
)
6240 popen conf.selcmd
[r, 0; w, -1];
6241 copysel
w opaque
true;
6243 G.postRedisplay "copysel";
6245 dolog
"can not execute %S: %s"
6246 conf.selcmd
(exntos exn
);
6254 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6255 state.mstate
<- Mnone
;
6262 let birdseyemouse button down
x y mask
6263 (conf, leftx
, _, hooverpageno
, anchor) =
6266 let rec loop = function
6269 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6270 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6272 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6278 | _ -> viewmouse button down
x y mask
6281 let mouse button down
x y mask
=
6282 state.uioh <- state.uioh#button button down
x y mask
;
6286 state.uioh <- state.uioh#
motion x y
6290 state.uioh <- state.uioh#
pmotion x y;
6296 method key key mask
=
6297 begin match state.mode with
6298 | Textentry
textentry -> textentrykeyboard key mask
textentry
6299 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6300 | View
-> viewkeyboard key mask
6301 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6305 method button button bstate
x y mask
=
6306 begin match state.mode with
6308 | View
-> viewmouse button bstate
x y mask
6309 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6315 begin match state.mode with
6317 | View
| Birdseye
_ | LinkNav
_ ->
6318 match state.mstate
with
6319 | Mzoom
_ | Mnone
-> ()
6324 state.mstate
<- Mpan
(x, y);
6326 then state.x <- panbound (state.x + dx);
6328 gotoy_and_clear_text y
6331 state.mstate
<- Msel
(a, (x, y));
6332 G.postRedisplay "motion select";
6335 let y = min
state.winh
(max
0 y) in
6339 let x = min
state.winw (max
0 x) in
6342 | Mzoomrect
(p0
, _) ->
6343 state.mstate
<- Mzoomrect
(p0
, (x, y));
6344 G.postRedisplay "motion zoomrect";
6348 method pmotion x y =
6349 begin match state.mode with
6350 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6351 let rec loop = function
6353 if hooverpageno
!= -1
6355 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6356 G.postRedisplay "pmotion birdseye no hoover";
6359 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6360 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6362 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6363 G.postRedisplay "pmotion birdseye hoover";
6373 match state.mstate
with
6374 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6381 let past, _, _ = !r in
6383 let delta = now -. past in
6386 else r := (now, x, y)
6390 method infochanged
_ = ()
6393 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6396 then 0.0, float state.winh
6397 else scrollph state.y maxy
6402 let winw = wadjsb state.winw in
6403 let fwinw = float winw in
6405 let sw = fwinw /. float state.w in
6406 let sw = fwinw *. sw in
6407 max
sw (float conf.scrollh
)
6410 let maxx = state.w + winw in
6411 let x = winw - state.x in
6412 let percent = float x /. float maxx in
6413 (fwinw -. sw) *. percent
6415 hscrollh (), position, sw
6419 match state.mode with
6420 | LinkNav
_ -> "links"
6421 | Textentry
_ -> "textentry"
6422 | Birdseye
_ -> "birdseye"
6425 findkeyhash conf modename
6427 method eformsgs
= true
6434 let fontpath = ref "";;
6437 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6440 let l = String.length
s in
6441 let b = Buffer.create
l in
6447 try Sys.getenv
"HOME"
6450 ("Can not determine home directory location: " ^ exntos exn
);
6454 let modifier_of_string = function
6455 | "alt" -> Wsi.altmask
6456 | "shift" -> Wsi.shiftmask
6457 | "ctrl" | "control" -> Wsi.ctrlmask
6458 | "meta" -> Wsi.metamask
6463 let r = Str.regexp
"-" in
6465 let elems = Str.full_split
r s in
6468 let m1 = modifier_of_string s in
6470 then (Wsi.namekey
s, m)
6473 | Str.Delim
s when n land 1 = 0 -> g s
6475 | Str.Delim
_ -> (k
, m)
6477 let rec loop n k
m = function
6480 let k, m = f n k m x in
6486 let keys_of_string =
6487 let r = Str.regexp
"[ \t]" in
6489 let elems = Str.split
r s in
6490 List.map
key_of_string elems
6493 let copykeyhashes c =
6494 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6497 let config_of c attrs
=
6501 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6502 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6503 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6504 | "preload" -> { c with preload = bool_of_string
v }
6505 | "page-bias" -> { c with pagebias
= int_of_string
v }
6506 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6507 | "horizontal-scroll-step" ->
6508 { c with hscrollstep
= max
(int_of_string
v) 1 }
6509 | "auto-scroll-step" ->
6510 { c with autoscrollstep
= max
0 (int_of_string
v) }
6511 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6512 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6515 match String.lowercase
v with
6516 | "true" -> Some infinity
6518 | f -> Some
(float_of_string
f)
6520 { c with maxwait
= mw}
6521 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6522 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6523 | "vertical-margin" ->
6524 { c with interpagespace
= max
0 (int_of_string
v) }
6526 let zoom = float_of_string
v /. 100. in
6527 let zoom = max
zoom 0.0 in
6528 { c with zoom = zoom }
6529 | "presentation" -> { c with presentation
= bool_of_string
v }
6530 | "rotation-angle" -> { c with angle
= int_of_string
v }
6531 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6532 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6533 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6534 | "proportional-display" ->
6537 then FitProportional
6540 { c with fitmodel
= fm }
6541 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6542 | "pixmap-cache-size" ->
6543 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6544 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6545 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6546 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6547 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6548 | "background-color" -> { c with bgcolor
= color_of_string v }
6549 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6550 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6551 | "mupdf-store-size" ->
6552 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6553 | "checkers" -> { c with checkers
= bool_of_string
v }
6554 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6555 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6556 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6557 | "uri-launcher" -> { c with urilauncher
= unent v }
6558 | "path-launcher" -> { c with pathlauncher
= unent v }
6559 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6560 | "invert-colors" -> { c with invert
= bool_of_string
v }
6561 | "brightness" -> { c with colorscale
= float_of_string
v }
6562 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6564 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6566 let (n, _, _) as nab
= multicolumns_of_string v in
6568 then { c with columns
= Csplit
(-n, [||]) }
6569 else { c with columns
= Cmulti
(nab
, [||]) }
6570 | "birds-eye-columns" ->
6571 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6572 | "selection-command" -> { c with selcmd
= unent v }
6573 | "synctex-command" -> { c with stcmd
= unent v }
6574 | "pax-command" -> { c with paxcmd
= unent v }
6575 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6576 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6577 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6578 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6579 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6580 | "horizontal-scrollbar-visible" ->
6583 then c.scrollb
lor scrollbhv
6584 else c.scrollb
land (lnot
scrollbhv)
6586 { c with scrollb
= b }
6587 | "vertical-scrollbar-visible" ->
6590 then c.scrollb
lor scrollbvv
6591 else c.scrollb
land (lnot
scrollbvv)
6593 { c with scrollb
= b }
6594 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6598 then Some
(ref (0.0, 0, 0))
6600 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6603 prerr_endline
("Error processing attribute (`" ^
6604 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6607 let rec fold c = function
6610 let c = apply c k v in
6613 fold { c with keyhashes
= copykeyhashes c } attrs
;
6616 let fromstring f pos
n v d =
6619 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6620 n v pos
(exntos exn
)
6625 let bookmark_of attrs
=
6626 let rec fold title page
rely visy
= function
6627 | ("title", v) :: rest
-> fold v page
rely visy rest
6628 | ("page", v) :: rest
-> fold title v rely visy rest
6629 | ("rely", v) :: rest
-> fold title page
v visy rest
6630 | ("visy", v) :: rest
-> fold title page
rely v rest
6631 | _ :: rest
-> fold title page
rely visy rest
6632 | [] -> title, page
, rely, visy
6634 fold "invalid" "0" "0" "0" attrs
6638 let rec fold path page
rely pan visy
= function
6639 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6640 | ("page", v) :: rest
-> fold path v rely pan visy rest
6641 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6642 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6643 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6644 | _ :: rest
-> fold path page
rely pan visy rest
6645 | [] -> path, page
, rely, pan
, visy
6647 fold "" "0" "0" "0" "0" attrs
6651 let rec fold rs ls
= function
6652 | ("out", v) :: rest
-> fold v ls rest
6653 | ("in", v) :: rest
-> fold rs
v rest
6654 | _ :: rest
-> fold ls rs rest
6660 let setconf dst
src =
6661 dst
.scrollbw
<- src.scrollbw
;
6662 dst
.scrollh
<- src.scrollh
;
6663 dst
.icase
<- src.icase
;
6664 dst
.preload <- src.preload;
6665 dst
.pagebias
<- src.pagebias
;
6666 dst
.verbose
<- src.verbose
;
6667 dst
.scrollstep
<- src.scrollstep
;
6668 dst
.maxhfit
<- src.maxhfit
;
6669 dst
.crophack
<- src.crophack
;
6670 dst
.autoscrollstep
<- src.autoscrollstep
;
6671 dst
.maxwait
<- src.maxwait
;
6672 dst
.hlinks
<- src.hlinks
;
6673 dst
.underinfo
<- src.underinfo
;
6674 dst
.interpagespace
<- src.interpagespace
;
6675 dst
.zoom <- src.zoom;
6676 dst
.presentation
<- src.presentation
;
6677 dst
.angle
<- src.angle
;
6678 dst
.cwinw
<- src.cwinw
;
6679 dst
.cwinh
<- src.cwinh
;
6680 dst
.savebmarks
<- src.savebmarks
;
6681 dst
.memlimit
<- src.memlimit
;
6682 dst
.fitmodel
<- src.fitmodel
;
6683 dst
.texcount
<- src.texcount
;
6684 dst
.sliceheight
<- src.sliceheight
;
6685 dst
.thumbw
<- src.thumbw
;
6686 dst
.jumpback
<- src.jumpback
;
6687 dst
.bgcolor
<- src.bgcolor
;
6688 dst
.tilew
<- src.tilew
;
6689 dst
.tileh
<- src.tileh
;
6690 dst
.mustoresize
<- src.mustoresize
;
6691 dst
.checkers
<- src.checkers
;
6692 dst
.aalevel
<- src.aalevel
;
6693 dst
.trimmargins
<- src.trimmargins
;
6694 dst
.trimfuzz
<- src.trimfuzz
;
6695 dst
.urilauncher
<- src.urilauncher
;
6696 dst
.colorspace
<- src.colorspace
;
6697 dst
.invert
<- src.invert
;
6698 dst
.colorscale
<- src.colorscale
;
6699 dst
.redirectstderr <- src.redirectstderr;
6700 dst
.ghyllscroll
<- src.ghyllscroll
;
6701 dst
.columns
<- src.columns
;
6702 dst
.beyecolumns
<- src.beyecolumns
;
6703 dst
.selcmd
<- src.selcmd
;
6704 dst
.updatecurs
<- src.updatecurs
;
6705 dst
.pathlauncher
<- src.pathlauncher
;
6706 dst
.keyhashes
<- copykeyhashes src;
6707 dst
.hfsize
<- src.hfsize
;
6708 dst
.hscrollstep
<- src.hscrollstep
;
6709 dst
.pgscale <- src.pgscale;
6710 dst
.usepbo
<- src.usepbo
;
6711 dst
.wheelbypage
<- src.wheelbypage
;
6712 dst
.stcmd
<- src.stcmd
;
6713 dst
.paxcmd
<- src.paxcmd
;
6714 dst
.scrollb
<- src.scrollb
;
6715 dst
.riani
<- src.riani
;
6716 dst
.paxmark
<- src.paxmark
;
6720 else Some
((ref (0.0, 0, 0)));
6724 let h = Hashtbl.create
10 in
6725 let dc = { defconf with angle
= defconf.angle
} in
6726 let rec toplevel v t spos
_ =
6728 | Vdata
| Vcdata
| Vend
-> v
6729 | Vopen
("llppconfig", _, closed
) ->
6732 else { v with f = llppconfig
}
6734 error
"unexpected subelement at top level" s spos
6735 | Vclose
_ -> error
"unexpected close at top level" s spos
6737 and llppconfig
v t spos
_ =
6739 | Vdata
| Vcdata
-> v
6740 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6741 | Vopen
("defaults", attrs
, closed
) ->
6742 let c = config_of dc attrs
in
6746 else { v with f = defaults
}
6748 | Vopen
("ui-font", attrs
, closed
) ->
6749 let rec getsize size
= function
6751 | ("size", v) :: rest
->
6753 fromstring int_of_string spos
"size" v fstate.fontsize
in
6755 | l -> getsize size l
6757 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6760 else { v with f = uifont
(Buffer.create
10) }
6762 | Vopen
("doc", attrs
, closed
) ->
6763 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6764 let path = unent pathent
6765 and pageno = fromstring int_of_string spos
"page" spage
0
6766 and rely = fromstring float_of_string spos
"rely" srely
0.0
6767 and pan
= fromstring int_of_string spos
"pan" span
0
6768 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6769 let c = config_of dc attrs
in
6770 let anchor = (pageno, rely, visy
) in
6772 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6773 else { v with f = doc
path pan
anchor c [] }
6776 error
"unexpected subelement in llppconfig" s spos
6778 | Vclose
"llppconfig" -> { v with f = toplevel }
6779 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6781 and defaults
v t spos
_ =
6783 | Vdata
| Vcdata
-> v
6784 | Vend
-> error
"unexpected end of input in defaults" s spos
6785 | Vopen
("keymap", attrs
, closed
) ->
6787 try List.assoc
"mode" attrs
6788 with Not_found
-> "global" in
6793 let h = findkeyhash dc modename in
6794 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6797 { v with f = pkeymap
ret KeyMap.empty }
6799 | Vopen
(_, _, _) ->
6800 error
"unexpected subelement in defaults" s spos
6802 | Vclose
"defaults" ->
6803 { v with f = llppconfig
}
6805 | Vclose
_ -> error
"unexpected close in defaults" s spos
6807 and uifont
b v t spos
epos =
6810 Buffer.add_substring
b s spos
(epos - spos
);
6812 | Vopen
(_, _, _) ->
6813 error
"unexpected subelement in ui-font" s spos
6814 | Vclose
"ui-font" ->
6815 if String.length
!fontpath = 0
6816 then fontpath := Buffer.contents
b;
6817 { v with f = llppconfig
}
6818 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6819 | Vend
-> error
"unexpected end of input in ui-font" s spos
6821 and doc
path pan
anchor c bookmarks
v t spos
_ =
6823 | Vdata
| Vcdata
-> v
6824 | Vend
-> error
"unexpected end of input in doc" s spos
6825 | Vopen
("bookmarks", _, closed
) ->
6828 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6830 | Vopen
("keymap", attrs
, closed
) ->
6832 try List.assoc
"mode" attrs
6833 with Not_found
-> "global"
6839 let h = findkeyhash c modename in
6840 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6841 doc
path pan
anchor c bookmarks
6843 { v with f = pkeymap
ret KeyMap.empty }
6845 | Vopen
(_, _, _) ->
6846 error
"unexpected subelement in doc" s spos
6849 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6850 { v with f = llppconfig
}
6852 | Vclose
_ -> error
"unexpected close in doc" s spos
6854 and pkeymap
ret keymap
v t spos
_ =
6856 | Vdata
| Vcdata
-> v
6857 | Vend
-> error
"unexpected end of input in keymap" s spos
6858 | Vopen
("map", attrs
, closed
) ->
6859 let r, l = map_of attrs
in
6860 let kss = fromstring keys_of_string spos
"in" r [] in
6861 let lss = fromstring keys_of_string spos
"out" l [] in
6865 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6866 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6869 then { v with f = pkeymap
ret keymap }
6872 { v with f = skip
"map" f }
6875 error
"unexpected subelement in keymap" s spos
6877 | Vclose
"keymap" ->
6878 { v with f = ret keymap }
6880 | Vclose
_ -> error
"unexpected close in keymap" s spos
6882 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6884 | Vdata
| Vcdata
-> v
6885 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6886 | Vopen
("item", attrs
, closed
) ->
6887 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6888 let page = fromstring int_of_string spos
"page" spage
0
6889 and rely = fromstring float_of_string spos
"rely" srely
0.0
6890 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6892 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6895 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6898 { v with f = skip
"item" f }
6901 error
"unexpected subelement in bookmarks" s spos
6903 | Vclose
"bookmarks" ->
6904 { v with f = doc
path pan
anchor c bookmarks }
6906 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6908 and skip tag
f v t spos
_ =
6910 | Vdata
| Vcdata
-> v
6912 error
("unexpected end of input in skipped " ^ tag
) s spos
6913 | Vopen
(tag'
, _, closed
) ->
6917 let f'
() = { v with f = skip tag
f } in
6918 { v with f = skip tag'
f'
}
6922 else error
("unexpected close in skipped " ^ tag
) s spos
6925 parse
{ f = toplevel; accu = () } s;
6931 let len = in_channel_length ic
in
6932 let s = String.create
len in
6933 really_input ic
s 0 len;
6936 | Parse_error
(msg
, s, pos
) ->
6937 let subs = subs s pos
in
6938 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6939 failwith
("parse error: " ^
s)
6942 failwith
("config load error: " ^ exntos exn
)
6948 let dir = Filename.concat
home ".config" in
6949 if Sys.is_directory
dir then dir else home
6952 Filename.concat
dir "llpp.conf"
6955 let confpath = ref defconfpath;;
6958 if Sys.file_exists
!confpath
6961 (try Some
(open_in_bin
!confpath)
6964 ("Error opening configuration file `" ^
!confpath ^
"': " ^
6975 ("Error loading configuration from `" ^
!confpath ^
"': " ^
6984 f (Hashtbl.create
0, defconf)
6989 let pc, pb
, px, pa
=
6992 if String.length
state.origin
= 0
6996 Hashtbl.find h (Filename.basename
key)
6997 with Not_found
-> dc, [], 0, emptyanchor
7001 state.bookmarks <- pb
;
7004 then state.anchor <- pa
;
7005 cbput state.hists
.nav pa
;
7011 let add_attrs bb always
dc c =
7014 then Printf.bprintf bb
"\n %s='%b'" s a
7017 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7020 then Printf.bprintf bb
"\n %s='%d'" s a
7023 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7026 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7029 then Printf.bprintf bb
"\n %s='%f'" s a
7033 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7037 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7041 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7045 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7051 | Some
(_N
, _A
, _B
) ->
7052 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7062 else string_of_float
f
7064 Printf.bprintf bb
"\n %s='%s'" s v
7069 | Cmulti
((n, a, b), _) when n > 1 ->
7070 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7071 | Csplit
(n, _) when n > 1 ->
7072 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7078 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7083 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7087 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7091 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7093 oi
"width" c.cwinw
dc.cwinw
;
7094 oi
"height" c.cwinh
dc.cwinh
;
7095 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7096 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7097 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7098 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7099 ob "case-insensitive-search" c.icase
dc.icase
;
7100 ob "preload" c.preload dc.preload;
7101 oi
"page-bias" c.pagebias
dc.pagebias
;
7102 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7103 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7104 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7105 ob "crop-hack" c.crophack
dc.crophack
;
7106 oW
"throttle" c.maxwait
dc.maxwait
;
7107 ob "highlight-links" c.hlinks
dc.hlinks
;
7108 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7109 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7110 oz
"zoom" c.zoom dc.zoom;
7111 ob "presentation" c.presentation
dc.presentation
;
7112 oi
"rotation-angle" c.angle
dc.angle
;
7113 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7114 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7115 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7116 oi
"tex-count" c.texcount
dc.texcount
;
7117 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7118 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7119 ob "persistent-location" c.jumpback
dc.jumpback
;
7120 oc
"background-color" c.bgcolor
dc.bgcolor
;
7121 oi
"tile-width" c.tilew
dc.tilew
;
7122 oi
"tile-height" c.tileh
dc.tileh
;
7123 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7124 ob "checkers" c.checkers
dc.checkers
;
7125 oi
"aalevel" c.aalevel
dc.aalevel
;
7126 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7127 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7128 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7129 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7130 oC
"color-space" c.colorspace
dc.colorspace
;
7131 ob "invert-colors" c.invert
dc.invert
;
7132 oF
"brightness" c.colorscale
dc.colorscale
;
7133 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7134 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7135 oco
"columns" c.columns
dc.columns
;
7136 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7137 os
"selection-command" c.selcmd
dc.selcmd
;
7138 os
"synctex-command" c.stcmd
dc.stcmd
;
7139 os
"pax-command" c.paxcmd
dc.paxcmd
;
7140 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7141 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7142 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7143 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7144 ob "use-pbo" c.usepbo
dc.usepbo
;
7145 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7146 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7147 op
"point-and-x" c.pax
dc.pax
;
7148 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7151 let keymapsbuf always
dc c =
7152 let bb = Buffer.create
16 in
7153 let rec loop = function
7155 | (modename, h) :: rest
->
7156 let dh = findkeyhash dc modename in
7157 if always
|| h <> dh
7159 if Hashtbl.length
h > 0
7161 if Buffer.length
bb > 0
7162 then Buffer.add_char
bb '
\n'
;
7163 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7164 Hashtbl.iter
(fun i
o ->
7165 let isdifferent = always
||
7167 let dO = Hashtbl.find dh i
in
7169 with Not_found
-> true
7174 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7175 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7176 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7177 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7178 Buffer.add_string
bb (Wsi.keyname
k);
7181 let rec loop = function
7183 | km
:: [] -> addkm km
7184 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7188 Buffer.add_string
bb "<map in='";
7192 Buffer.add_string
bb "' out='";
7194 Buffer.add_string
bb "'/>\n"
7197 Buffer.add_string
bb "' out='";
7199 Buffer.add_string
bb "'/>\n"
7201 | KMmulti
(ins, kms
) ->
7202 Buffer.add_char
bb ' '
;
7204 Buffer.add_string
bb "' out='";
7206 Buffer.add_string
bb "'/>\n"
7208 Buffer.add_string
bb "</keymap>";
7218 let uifontsize = fstate.fontsize
in
7219 let bb = Buffer.create
32768 in
7220 let relx = float state.x /. float state.winw in
7222 let cx w = truncate
(relx *. float w) in
7224 (fun (w, h, x) ws
->
7226 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7227 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7228 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7230 (state.winw, state.winh
, state.x) state.winstate
7235 let dc = if conf.bedefault
then conf else dc in
7236 Buffer.add_string
bb "<llppconfig>\n";
7238 if String.length
!fontpath > 0
7240 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7246 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7249 Buffer.add_string
bb "<defaults ";
7250 add_attrs bb true dc dc;
7251 let kb = keymapsbuf true dc dc in
7252 if Buffer.length
kb > 0
7254 Buffer.add_string
bb ">\n";
7255 Buffer.add_buffer
bb kb;
7256 Buffer.add_string
bb "\n</defaults>\n";
7258 else Buffer.add_string
bb "/>\n";
7260 let adddoc path pan
anchor c bookmarks =
7261 if bookmarks == [] && c = dc && anchor = emptyanchor
7264 Printf.bprintf
bb "<doc path='%s'"
7265 (enent
path 0 (String.length
path));
7267 if anchor <> emptyanchor
7269 let n, rely, visy
= anchor in
7270 Printf.bprintf
bb " page='%d'" n;
7273 Printf.bprintf
bb " rely='%f'" rely
7275 if abs_float visy
> 1e-6
7277 Printf.bprintf
bb " visy='%f'" visy
7282 then Printf.bprintf
bb " pan='%d'" pan
;
7284 add_attrs bb false dc c;
7285 let kb = keymapsbuf false dc c in
7287 begin match bookmarks with
7289 if Buffer.length
kb > 0
7291 Buffer.add_string
bb ">\n";
7292 Buffer.add_buffer
bb kb;
7293 Buffer.add_string
bb "\n</doc>\n";
7295 else Buffer.add_string
bb "/>\n"
7297 Buffer.add_string
bb ">\n<bookmarks>\n";
7298 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7300 "<item title='%s' page='%d'"
7301 (enent
title 0 (String.length
title))
7306 Printf.bprintf
bb " rely='%f'" rely
7308 if abs_float visy
> 1e-6
7310 Printf.bprintf
bb " visy='%f'" visy
7312 Buffer.add_string
bb "/>\n";
7314 Buffer.add_string
bb "</bookmarks>";
7315 if Buffer.length
kb > 0
7317 Buffer.add_string
bb "\n";
7318 Buffer.add_buffer
bb kb;
7320 Buffer.add_string
bb "\n</doc>\n";
7326 match state.mode with
7327 | Birdseye
(c, pan, _, _, _) ->
7329 match conf.columns
with
7330 | Cmulti
((c, _, _), _) -> Some
c
7334 match c.columns
with
7335 | Cmulti
(c, _) -> Cmulti
(c, [||])
7336 | Csingle
_ -> Csingle
[||]
7337 | Csplit
_ -> failwith
"quit from bird's eye while split"
7339 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7342 let basename = Filename.basename
7343 (if String.length
state.origin
= 0 then state.path else state.origin
)
7345 adddoc basename pan (getanchor ())
7347 let autoscrollstep =
7348 match state.autoscroll
with
7350 | None
-> conf.autoscrollstep
7352 match state.mode with
7353 | Birdseye
(bc
, _, _, _, _) ->
7356 presentation
= bc
.presentation
;
7357 interpagespace
= bc
.interpagespace
;
7358 maxwait
= bc
.maxwait
;
7359 autoscrollstep = autoscrollstep }
7360 | _ -> { conf with autoscrollstep = autoscrollstep }
7362 (if conf.savebmarks
then state.bookmarks else []);
7364 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7366 then adddoc path x anchor c bookmarks
7368 Buffer.add_string
bb "</llppconfig>\n";
7371 if load1 f && Buffer.length
bb > 0
7374 let tmp = !confpath ^
".tmp" in
7375 let oc = open_out_bin
tmp in
7376 Buffer.output_buffer
oc bb;
7378 Unix.rename
tmp !confpath;
7381 ("error while saving configuration: " ^ exntos exn
)
7385 let adderrmsg src msg
=
7386 Buffer.add_string
state.errmsgs msg
;
7387 state.newerrmsgs
<- true;
7391 let adderrfmt src fmt
=
7392 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7396 let cl = splitatspace cmds
in
7398 try Scanf.sscanf
s fmt
f
7400 adderrfmt "remote exec"
7401 "error processing '%S': %s\n" cmds
(exntos exn
)
7404 | "reload" :: [] -> reload ()
7405 | "goto" :: args :: [] ->
7406 scan args "%u %f %f"
7408 let cmd, _ = state.geomcmds
in
7409 if String.length
cmd = 0
7410 then gotopagexy pageno x y
7413 gotopagexy pageno x y;
7416 state.reprf
<- f state.reprf
7418 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7419 | "rect" :: args :: [] ->
7420 scan args "%u %u %f %f %f %f"
7421 (fun pageno color x0 y0 x1 y1 ->
7422 onpagerect pageno (fun w h ->
7423 let _,w1,h1
,_ = getpagedim pageno in
7424 let sw = float w1 /. w
7425 and sh = float h1
/. h in
7429 and y1s
= y1 *. sh in
7430 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7432 state.rects <- (pageno, color, rect) :: state.rects;
7433 G.postRedisplay "rect";
7436 | "activatewin" :: [] -> Wsi.activatewin
()
7437 | "quit" :: [] -> raise Quit
7439 adderrfmt "remote command"
7440 "error processing remote command: %S\n" cmds
;
7444 let scratch = String.create
80 in
7445 let buf = Buffer.create
80 in
7448 try Some
(Unix.read fd
scratch 0 80)
7450 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7451 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7454 match tempfr () with
7460 if Buffer.length
buf > 0
7462 let s = Buffer.contents
buf in
7472 let pos = String.index_from
scratch ppos '
\n'
in
7473 if pos >= n then -1 else pos
7474 with Not_found
-> -1
7478 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7479 let s = Buffer.contents
buf in
7485 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7491 let remoteopen path =
7492 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7494 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7499 let trimcachepath = ref "" in
7500 let rcmdpath = ref "" in
7501 selfexec := Sys.executable_name
;
7504 [("-p", Arg.String
(fun s -> state.password
<- s),
7505 "<password> Set password");
7509 Config.fontpath := s;
7510 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7512 "<path> Set path to the user interface font");
7516 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7517 Config.confpath := s),
7518 "<path> Set path to the configuration file");
7520 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7521 "<path> Set path to the trim cache file");
7523 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7524 "<named-destination> Set named destination");
7526 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7527 ("-cxack", Arg.Set
cxack, " Cut corners");
7529 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7530 "<path> Set path to the remote commands source");
7532 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7533 "<original-path> Set original path");
7535 ("-v", Arg.Unit
(fun () ->
7537 "%s\nconfiguration path: %s\n"
7541 exit
0), " Print version and exit");
7544 (fun s -> state.path <- s)
7545 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7548 then selfexec := !selfexec ^
" -wtmode";
7550 if String.length
state.path = 0
7551 then (prerr_endline
"file name missing"; exit
1);
7553 if not
(Config.load ())
7554 then prerr_endline
"failed to load configuration";
7556 let wsfd, winw, winh
= Wsi.init
(object
7557 val mutable m_hack
= false
7558 method expose
= if not m_hack
then G.postRedisplay "expose"
7559 method visible
= G.postRedisplay "visible"
7560 method display = m_hack
<- false; display ()
7561 method reshape w h =
7562 m_hack
<- w < state.winw && h < state.winh
;
7564 method mouse b d x y m = mouse b d x y m
7565 method motion x y = state.mpos
<- (x, y); motion x y
7566 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7568 let mascm = m land (
7569 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7571 match state.keystate
with
7573 let km = k, mascm in
7576 let modehash = state.uioh#
modehash in
7577 try Hashtbl.find modehash km
7579 try Hashtbl.find (findkeyhash conf "global") km
7580 with Not_found
-> KMinsrt
(k, m)
7582 | KMinsrt
(k, m) -> keyboard k m
7583 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7584 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7586 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7587 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7588 state.keystate
<- KSnone
7589 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7590 state.keystate
<- KSinto
(keys
, insrt
)
7592 state.keystate
<- KSnone
7594 method enter
x y = state.mpos
<- (x, y); pmotion x y
7595 method leave = state.mpos
<- (-1, -1)
7596 method winstate wsl
= state.winstate
<- wsl
7597 method quit
= raise Quit
7598 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7603 List.exists
GlMisc.check_extension
7604 [ "GL_ARB_texture_rectangle"
7605 ; "GL_EXT_texture_recangle"
7606 ; "GL_NV_texture_rectangle" ]
7608 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7611 let r = GlMisc.get_string `renderer
in
7612 let p = "Mesa DRI Intel(" in
7613 let l = String.length
p in
7614 String.length
r > l && String.sub
r 0 l = p
7616 then defconf.sliceheight
<- 1024;
7619 match Ne.pipe () with
7621 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7625 match Ne.pipe () with
7627 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7637 setcheckers conf.checkers
;
7639 if conf.redirectstderr
7642 let s = Buffer.contents
state.errmsgs ^
7643 (match state.errfd
with
7645 let s = String.create
(80*24) in
7648 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
7650 then Unix.read fd
s 0 (String.length
s)
7656 else String.sub
s 0 n
7660 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
7661 with exn
-> print_endline
(exntos exn
)
7666 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7667 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7668 !Config.fontpath, !trimcachepath,
7669 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7673 state.text <- "Opening " ^
(mbtoutf8
state.path);
7675 opendoc state.path state.password
;
7679 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7682 if String.length
!rcmdpath > 0
7683 then remoteopen !rcmdpath
7688 let rec loop deadline
=
7690 match state.errfd
with
7691 | None
-> [state.sr
; state.wsfd]
7692 | Some fd
-> [state.sr
; state.wsfd; fd
]
7697 | Some fd
-> fd
:: r
7701 state.redisplay
<- false;
7708 if deadline
= infinity
7710 else max
0.0 (deadline
-. now)
7715 try Unix.select
r [] [] timeout
7716 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7722 if state.ghyll
== noghyll
7724 match state.autoscroll
with
7725 | Some step
when step
!= 0 ->
7726 let y = state.y + step
in
7730 else if y >= state.maxy then 0 else y
7733 if state.mode = View
7734 then state.text <- "";
7737 else deadline
+. 0.01
7742 let rec checkfds = function
7744 | fd
:: rest
when fd
= state.sr
->
7745 let cmd = readcmd state.sr
in
7749 | fd
:: rest
when fd
= state.wsfd ->
7753 | fd
:: rest
when Some fd
= !optrfd ->
7754 begin match remote fd
with
7755 | None
-> optrfd := remoteopen !rcmdpath;
7756 | opt -> optrfd := opt
7761 let s = String.create
80 in
7762 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7763 if conf.redirectstderr
7765 Buffer.add_substring
state.errmsgs
s 0 n;
7766 state.newerrmsgs
<- true;
7767 state.redisplay
<- true;
7770 prerr_string
(String.sub
s 0 n);
7778 if deadline
= infinity
7782 match state.autoscroll
with
7783 | Some step
when step
!= 0 -> deadline1
7784 | _ -> if state.ghyll
== noghyll then infinity
else deadline1