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
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
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;
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.bzoom
<- not
state.bzoom
;
3225 TEdone
("block zoom " ^
btos (state.bzoom
))
3228 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3234 class type lvsource
= object
3235 method getitemcount
: int
3236 method getitem
: int -> (string * int)
3237 method hasaction
: int -> bool
3246 method getactive
: int
3247 method getfirst
: int
3248 method getqsearch
: string
3249 method setqsearch
: string -> unit
3253 class virtual lvsourcebase
= object
3254 val mutable m_active
= 0
3255 val mutable m_first
= 0
3256 val mutable m_qsearch
= ""
3257 val mutable m_pan
= 0
3258 method getactive
= m_active
3259 method getfirst
= m_first
3260 method getqsearch
= m_qsearch
3261 method getpan
= m_pan
3262 method setqsearch
s = m_qsearch
<- s
3265 let withoutlastutf8 s =
3266 let len = String.length
s in
3274 let b = Char.code
s.[pos
] in
3275 if b land 0b11000000 = 0b11000000
3280 if Char.code
s.[len-1] land 0x80 = 0
3284 String.sub
s 0 first;
3287 let textentrykeyboard
3288 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3290 if key >= 0xffb0 && key <= 0xffb9
3291 then key - 0xffb0 + 48 else key
3294 state.mode
<- Textentry
(te
, onleave
);
3297 G.postRedisplay "textentrykeyboard enttext";
3299 let histaction cmd
=
3302 | Some
(action, _) ->
3303 state.mode
<- Textentry
(
3304 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3306 G.postRedisplay "textentry histaction"
3309 | 0xff08 -> (* backspace *)
3310 let s = withoutlastutf8 text in
3311 let len = String.length
s in
3312 if cancelonempty
&& len = 0
3315 G.postRedisplay "textentrykeyboard after cancel";
3318 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3321 | 0xff0d | 0xff8d -> (* (kp) enter *)
3324 G.postRedisplay "textentrykeyboard after confirm"
3326 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3327 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3328 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3329 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3331 | 0xff1b -> (* escape*)
3332 if String.length
text = 0
3334 begin match opthist
with
3336 | Some
(_, onhistcancel
) -> onhistcancel
()
3340 G.postRedisplay "textentrykeyboard after cancel2"
3343 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3346 | 0xff9f | 0xffff -> () (* delete *)
3349 && key land 0xff00 != 0xff00 (* keyboard *)
3350 && key land 0xfe00 != 0xfe00 (* xkb *)
3351 && key land 0xfd00 != 0xfd00 (* 3270 *)
3353 begin match onkey
text key with
3357 G.postRedisplay "textentrykeyboard after confirm2";
3360 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3364 G.postRedisplay "textentrykeyboard after cancel3"
3367 state.mode
<- Textentry
(te
, onleave
);
3368 G.postRedisplay "textentrykeyboard switch";
3372 vlog "unhandled key %s" (Wsi.keyname
key)
3375 let firstof first active
=
3376 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3377 then max
0 (active
- (fstate.maxrows
/2))
3381 let calcfirst first active
=
3384 let rows = active
- first in
3385 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3389 let scrollph y maxy
=
3390 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3391 let sh = float state.winh
/. sh in
3392 let sh = max
sh (float conf.scrollh
) in
3394 let percent = float y /. float maxy
in
3395 let position = (float state.winh
-. sh) *. percent in
3398 if position +. sh > float state.winh
3399 then float state.winh
-. sh
3405 let coe s = (s :> uioh
);;
3407 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3409 val m_pan
= source#getpan
3410 val m_first
= source#getfirst
3411 val m_active
= source#getactive
3412 val m_qsearch
= source#getqsearch
3413 val m_prev_uioh
= state.uioh
3415 method private elemunder
y =
3416 let n = y / (fstate.fontsize
+1) in
3417 if m_first
+ n < source#getitemcount
3419 if source#hasaction
(m_first
+ n)
3420 then Some
(m_first
+ n)
3427 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3428 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3429 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3430 GlDraw.color
(1., 1., 1.);
3431 Gl.enable `texture_2d
;
3432 let fs = fstate.fontsize
in
3434 let ww = fstate.wwidth
in
3435 let tabw = 30.0*.ww in
3436 let itemcount = source#getitemcount
in
3438 if (row - m_first
) > fstate.maxrows
3441 if row >= 0 && row < itemcount
3443 let (s, level
) = source#getitem
row in
3444 let y = (row - m_first
) * nfs in
3445 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3448 Gl.disable `texture_2d
;
3449 GlDraw.polygon_mode `both `line
;
3450 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3451 GlDraw.color
(1., 1., 1.) ~
alpha;
3452 GlDraw.rect (1., float (y + 1))
3453 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3454 GlDraw.polygon_mode `both `fill
;
3455 GlDraw.color
(1., 1., 1.);
3456 Gl.enable `texture_2d
;
3459 let drawtabularstring s =
3460 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3463 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3466 let len = String.length
s - tabpos - 1 in
3467 let s1 = String.sub
s 0 tabpos
3468 and s2
= String.sub
s (tabpos + 1) len in
3469 let nx = drawstr x s1 in
3471 let x = x +. (max
tabw sw) in
3478 let _ = drawtabularstring s in
3485 Gl.disable `texture_2d
;
3487 method updownlevel incr
=
3488 let len = source#getitemcount
in
3490 if m_active
>= 0 && m_active
< len
3491 then snd
(source#getitem m_active
)
3495 if i
= len then i
-1 else if i
= -1 then 0 else
3496 let _, l = source#getitem i
in
3497 if l != curlevel then i
else flow (i
+incr
)
3499 let active = flow m_active
in
3500 let first = calcfirst m_first
active in
3501 G.postRedisplay "outline updownlevel";
3502 {< m_active
= active; m_first
= first >}
3504 method private key1
key mask
=
3505 let set1 active first qsearch
=
3506 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3508 let search active pattern incr
=
3509 let active = if active = -1 then m_first
else active in
3512 if n >= 0 && n < source#getitemcount
3514 let s, _ = source#getitem
n in
3516 (try ignore
(Str.search_forward
re s 0); true
3517 with Not_found
-> false)
3519 else loop (n + incr
)
3526 let re = Str.regexp_case_fold pattern
in
3532 let itemcount = source#getitemcount
in
3533 let find start incr
=
3535 if i
= -1 || i
= itemcount
3538 if source#hasaction i
3540 else find (i
+ incr
)
3545 let set active first =
3546 let first = bound first 0 (itemcount - fstate.maxrows
) in
3548 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3551 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3553 let incr1 = if incr
> 0 then 1 else -1 in
3554 if isvisible m_first m_active
3557 let next = m_active
+ incr
in
3559 if next < 0 || next >= itemcount
3561 else find next incr1
3563 if abs
(m_active
- next) > fstate.maxrows
3569 let first = m_first
+ incr
in
3570 let first = bound first 0 (itemcount - fstate.maxrows
) in
3572 let next = m_active
+ incr
in
3573 let next = bound next 0 (itemcount - 1) in
3580 if isvisible first next
3587 let first = min
next m_first
in
3589 if abs
(next - first) > fstate.maxrows
3595 let first = m_first
+ incr
in
3596 let first = bound first 0 (itemcount - 1) in
3598 let next = m_active
+ incr
in
3599 let next = bound next 0 (itemcount - 1) in
3600 let next = find next incr1 in
3602 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3604 let active = if m_active
= -1 then next else m_active
in
3609 if isvisible first active
3615 G.postRedisplay "listview navigate";
3619 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3620 let incr = if key = 0x72 then -1 else 1 in
3622 match search (m_active
+ incr) m_qsearch
incr with
3624 state.text <- m_qsearch ^
" [not found]";
3627 state.text <- m_qsearch
;
3628 active, firstof m_first
active
3630 G.postRedisplay "listview ctrl-r/s";
3631 set1 active first m_qsearch
;
3633 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3634 if m_active
>= 0 && m_active
< source#getitemcount
3636 let s, _ = source#getitem m_active
in
3641 | 0xff08 -> (* backspace *)
3642 if String.length m_qsearch
= 0
3645 let qsearch = withoutlastutf8 m_qsearch
in
3646 let len = String.length
qsearch in
3650 G.postRedisplay "listview empty qsearch";
3651 set1 m_active m_first
"";
3655 match search m_active
qsearch ~
-1 with
3657 state.text <- qsearch ^
" [not found]";
3660 state.text <- qsearch;
3661 active, firstof m_first
active
3663 G.postRedisplay "listview backspace qsearch";
3664 set1 active first qsearch
3667 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3668 let pattern = m_qsearch ^ toutf8
key in
3670 match search m_active
pattern 1 with
3672 state.text <- pattern ^
" [not found]";
3675 state.text <- pattern;
3676 active, firstof m_first
active
3678 G.postRedisplay "listview qsearch add";
3679 set1 active first pattern;
3681 | 0xff1b -> (* escape *)
3683 if String.length m_qsearch
= 0
3685 G.postRedisplay "list view escape";
3688 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3690 | None
-> m_prev_uioh
3695 G.postRedisplay "list view kill qsearch";
3696 source#setqsearch
"";
3697 coe {< m_qsearch
= "" >}
3700 | 0xff0d | 0xff8d -> (* (kp) enter *)
3702 let self = {< m_qsearch
= "" >} in
3703 source#setqsearch
"";
3705 G.postRedisplay "listview enter";
3706 if m_active
>= 0 && m_active
< source#getitemcount
3708 source#exit
(coe self) false m_active m_first m_pan
"";
3711 source#exit
(coe self) true m_active m_first m_pan
"";
3714 begin match opt with
3715 | None
-> m_prev_uioh
3719 | 0xff9f | 0xffff -> (* (kp) delete *)
3722 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3723 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3724 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3725 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3727 | 0xff53 | 0xff98 -> (* (kp) right *)
3729 G.postRedisplay "listview right";
3730 coe {< m_pan
= m_pan
- 1 >}
3732 | 0xff51 | 0xff96 -> (* (kp) left *)
3734 G.postRedisplay "listview left";
3735 coe {< m_pan
= m_pan
+ 1 >}
3737 | 0xff50 | 0xff95 -> (* (kp) home *)
3738 let active = find 0 1 in
3739 G.postRedisplay "listview home";
3742 | 0xff57 | 0xff9c -> (* (kp) end *)
3743 let first = max
0 (itemcount - fstate.maxrows
) in
3744 let active = find (itemcount - 1) ~
-1 in
3745 G.postRedisplay "listview end";
3748 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3752 dolog
"listview unknown key %#x" key; coe self
3754 method key key mask
=
3755 match state.mode
with
3756 | Textentry te
-> textentrykeyboard key mask te
; coe self
3757 | _ -> self#key1
key mask
3759 method button button down
x y _ =
3762 | 1 when x > state.winw
- conf.scrollbw
->
3763 G.postRedisplay "listview scroll";
3766 let _, position, sh = self#
scrollph in
3767 if y > truncate
position && y < truncate
(position +. sh)
3769 state.mstate
<- Mscrolly
;
3773 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3774 let first = truncate
(s *. float source#getitemcount
) in
3775 let first = min source#getitemcount
first in
3776 Some
(coe {< m_first
= first; m_active
= first >})
3778 state.mstate
<- Mnone
;
3781 | 1 when not down
->
3782 begin match self#elemunder
y with
3784 G.postRedisplay "listview click";
3786 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3790 | n when (n == 4 || n == 5) && not down
->
3791 let len = source#getitemcount
in
3793 if n = 5 && m_first
+ fstate.maxrows
>= len
3797 let first = m_first
+ (if n == 4 then -1 else 1) in
3798 bound first 0 (len - 1)
3800 G.postRedisplay "listview wheel";
3801 Some
(coe {< m_first
= first >})
3802 | n when (n = 6 || n = 7) && not down
->
3803 let inc = m_first
+ (if n = 7 then -1 else 1) in
3804 G.postRedisplay "listview hwheel";
3805 Some
(coe {< m_pan
= m_pan
+ inc >})
3810 | None
-> m_prev_uioh
3814 match state.mstate
with
3816 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3817 let first = truncate
(s *. float source#getitemcount
) in
3818 let first = min source#getitemcount
first in
3819 G.postRedisplay "listview motion";
3820 coe {< m_first
= first; m_active
= first >}
3823 method pmotion
x y =
3824 if x < state.winw
- conf.scrollbw
3827 match self#elemunder
y with
3828 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3829 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3833 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3838 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3842 method infochanged
_ = ()
3844 method scrollpw
= (0, 0.0, 0.0)
3846 let nfs = fstate.fontsize
+ 1 in
3847 let y = m_first
* nfs in
3848 let itemcount = source#getitemcount
in
3849 let maxi = max
0 (itemcount - fstate.maxrows
) in
3850 let maxy = maxi * nfs in
3851 let p, h = scrollph y maxy in
3854 method modehash
= modehash
3855 method eformsgs
= false
3858 class outlinelistview ~source
=
3861 ~source
:(source
:> lvsource
)
3863 ~modehash
:(findkeyhash conf "outline")
3866 method key key mask
=
3867 let calcfirst first active =
3870 let rows = active - first in
3872 if String.length
state.text = 0
3874 else fstate.maxrows - 2
3876 if rows > maxrows then active - maxrows else first
3880 let active = m_active
+ incr in
3881 let active = bound active 0 (source#getitemcount
- 1) in
3882 let first = calcfirst m_first
active in
3883 G.postRedisplay "outline navigate";
3884 coe {< m_active
= active; m_first
= first >}
3886 let ctrl = Wsi.withctrl mask
in
3888 | 110 when ctrl -> (* ctrl-n *)
3889 source#narrow m_qsearch
;
3890 G.postRedisplay "outline ctrl-n";
3891 coe {< m_first
= 0; m_active
= 0 >}
3893 | 117 when ctrl -> (* ctrl-u *)
3895 G.postRedisplay "outline ctrl-u";
3897 coe {< m_first
= 0; m_active
= 0 >}
3899 | 108 when ctrl -> (* ctrl-l *)
3900 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3901 G.postRedisplay "outline ctrl-l";
3902 coe {< m_first
= first >}
3904 | 0xff9f | 0xffff -> (* (kp) delete *)
3905 source#remove m_active
;
3906 G.postRedisplay "outline delete";
3907 let active = max
0 (m_active
-1) in
3908 coe {< m_first
= firstof m_first
active;
3909 m_active
= active >}
3911 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3912 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3913 | 0xff55 | 0xff9a -> (* (kp) prior *)
3914 navigate ~
-(fstate.maxrows)
3915 | 0xff56 | 0xff9b -> (* (kp) next *)
3916 navigate fstate.maxrows
3918 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3922 G.postRedisplay "outline ctrl right";
3923 {< m_pan
= m_pan
+ 1 >}
3925 else self#updownlevel
1
3929 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3933 G.postRedisplay "outline ctrl left";
3934 {< m_pan
= m_pan
- 1 >}
3936 else self#updownlevel ~
-1
3940 | 0xff50 | 0xff95 -> (* (kp) home *)
3941 G.postRedisplay "outline home";
3942 coe {< m_first
= 0; m_active
= 0 >}
3944 | 0xff57 | 0xff9c -> (* (kp) end *)
3945 let active = source#getitemcount
- 1 in
3946 let first = max
0 (active - fstate.maxrows) in
3947 G.postRedisplay "outline end";
3948 coe {< m_active
= active; m_first
= first >}
3950 | _ -> super#
key key mask
3953 let outlinesource usebookmarks
=
3956 inherit lvsourcebase
3957 val mutable m_items
= empty
3958 val mutable m_orig_items
= empty
3959 val mutable m_prev_items
= empty
3960 val mutable m_narrow_pattern
= ""
3961 val mutable m_hadremovals
= false
3963 method getitemcount
=
3964 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3967 if n == Array.length m_items
&& m_hadremovals
3969 ("[Confirm removal]", 0)
3971 let s, n, _ = m_items
.(n) in
3974 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3975 ignore
(uioh
, first, qsearch);
3976 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3978 if String.length m_narrow_pattern
= 0
3984 if not
confrimremoval
3986 let _, _, anchor = m_items
.(active) in
3987 gotoghyll (getanchory anchor);
3991 state.bookmarks
<- Array.to_list m_items
;
3992 m_orig_items
<- m_items
;
3995 else m_items
<- items;
3999 method hasaction
_ = true
4002 if Array.length m_items
!= Array.length m_orig_items
4003 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
4006 method narrow
pattern =
4007 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4011 let rec loop accu n =
4014 m_narrow_pattern
<- pattern;
4015 m_items
<- Array.of_list
accu
4018 let (s, _, _) as o = m_items
.(n) in
4020 if (try ignore
(Str.search_forward
re s 0); true
4021 with Not_found
-> false)
4027 loop [] (Array.length m_items
- 1)
4032 then Array.of_list
state.bookmarks
4035 m_items
<- m_orig_items
4040 if m >= 0 && m < Array.length m_items
4042 m_hadremovals
<- true;
4043 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4044 let n = if n >= m then n+1 else n in
4049 method reset
anchor items =
4050 m_hadremovals
<- false;
4051 if m_orig_items
== empty || m_prev_items
!= items
4053 m_orig_items
<- items;
4054 if String.length m_narrow_pattern
= 0
4055 then m_items
<- items;
4057 m_prev_items
<- items;
4058 let rely = getanchory anchor in
4060 let rec loop n best bestd
=
4061 if n = Array.length m_items
4064 let (_, _, anchor) = m_items
.(n) in
4065 let orely = getanchory anchor in
4066 let d = abs
(orely - rely) in
4069 else loop (n+1) best bestd
4074 m_first
<- firstof m_first
active
4078 let enterselector usebookmarks
=
4079 let source = outlinesource usebookmarks
in
4083 then Array.of_list
state.bookmarks
4086 if Array.length
outlines = 0
4088 showtext ' ' errmsg
;
4091 state.text <- source#greetmsg
;
4092 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4093 let anchor = getanchor () in
4094 source#reset
anchor outlines;
4095 state.uioh
<- coe (new outlinelistview ~
source);
4096 G.postRedisplay "enter selector";
4100 let enteroutlinemode =
4101 let f = enterselector false in
4102 fun ()-> f "Document has no outline";
4105 let enterbookmarkmode =
4106 let f = enterselector true in
4107 fun () -> f "Document has no bookmarks (yet)";
4110 let color_of_string s =
4111 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4112 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4116 let color_to_string (r, g, b) =
4117 let r = truncate
(r *. 256.0)
4118 and g = truncate
(g *. 256.0)
4119 and b = truncate
(b *. 256.0) in
4120 Printf.sprintf
"%d/%d/%d" r g b
4123 let irect_of_string s =
4124 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4127 let irect_to_string (x0,y0,x1,y1) =
4128 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4131 let makecheckers () =
4132 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4134 converted by Issac Trotts. July 25, 2002 *)
4135 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4136 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4137 let id = GlTex.gen_texture
() in
4138 GlTex.bind_texture `texture_2d
id;
4139 GlPix.store
(`unpack_alignment
1);
4140 GlTex.image2d
image;
4141 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4142 [ `mag_filter `nearest
; `min_filter `nearest
];
4146 let setcheckers enabled
=
4147 match state.texid
with
4149 if enabled
then state.texid
<- Some
(makecheckers ())
4154 GlTex.delete_texture texid
;
4155 state.texid
<- None
;
4159 let int_of_string_with_suffix s =
4160 let l = String.length
s in
4164 let suffix = Char.lowercase
s.[l-1] in
4166 | 'k'
-> String.sub
s 0 (l-1), 10
4167 | '
m'
-> String.sub
s 0 (l-1), 20
4168 | '
g'
-> String.sub
s 0 (l-1), 30
4172 let n = int_of_string
s1 in
4173 let m = n lsl shift
in
4175 then raise
(Failure
"value too large")
4179 let string_with_suffix_of_int n =
4184 if n land ((1 lsl 30) - 1) = 0
4187 if n land ((1 lsl 20) - 1) = 0
4190 if n land ((1 lsl 10) - 1) = 0
4197 let h = n mod 1000 in
4200 then string_of_int
h ^
s
4202 let s = Printf.sprintf
"_%03d%s" h s in
4209 let defghyllscroll = (40, 8, 32);;
4210 let ghyllscroll_of_string s =
4211 let (n, a, b) as nab
=
4214 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4216 if n <= a || n <= b || a >= b
4217 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4221 let ghyllscroll_to_string ((n, a, b) as nab
) =
4222 if nab
= defghyllscroll
4224 else Printf.sprintf
"%d,%d,%d" n a b;
4227 let describe_location () =
4228 let fn = page_of_y state.y in
4229 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4230 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4234 else (100. *. (float state.y /. float maxy))
4238 Printf.sprintf
"page %d of %d [%.2f%%]"
4239 (fn+1) state.pagecount
percent
4242 "pages %d-%d of %d [%.2f%%]"
4243 (fn+1) (ln+1) state.pagecount
percent
4246 let setpresentationmode v
=
4247 let n = page_of_y state.y in
4248 state.anchor <- (n, 0.0, 1.0);
4249 conf.presentation
<- v
;
4250 if conf.fitmodel
= FitPage
4251 then reqlayout conf.angle
conf.fitmodel
;
4256 let btos b = if b then "\xe2\x88\x9a" else "" in
4257 let showextended = ref false in
4258 let leave mode
= function
4259 | Confirm
-> state.mode
<- mode
4260 | Cancel
-> state.mode
<- mode
in
4263 val mutable m_first_time
= true
4264 val mutable m_l
= []
4265 val mutable m_a
= [||]
4266 val mutable m_prev_uioh
= nouioh
4267 val mutable m_prev_mode
= View
4269 inherit lvsourcebase
4271 method reset prev_mode prev_uioh
=
4272 m_a
<- Array.of_list
(List.rev m_l
);
4274 m_prev_mode
<- prev_mode
;
4275 m_prev_uioh
<- prev_uioh
;
4279 if n >= Array.length m_a
4283 | _, _, _, Action
_ -> m_active
<- n
4287 m_first_time
<- false;
4290 method int name get
set =
4292 (name, `
int get
, 1, Action
(
4295 try set (int_of_string
s)
4297 state.text <- Printf.sprintf
"bad integer `%s': %s"
4301 let te = name ^
": ", "", None
, intentry, ondone, true in
4302 state.mode
<- Textentry
(te, leave m_prev_mode
);
4306 method int_with_suffix
name get
set =
4308 (name, `intws get
, 1, Action
(
4311 try set (int_of_string_with_suffix s)
4313 state.text <- Printf.sprintf
"bad integer `%s': %s"
4318 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4320 state.mode
<- Textentry
(te, leave m_prev_mode
);
4324 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4326 (name, `
bool (btos, get
), offset
, Action
(
4333 method color
name get
set =
4335 (name, `color get
, 1, Action
(
4337 let invalid = (nan
, nan
, nan
) in
4340 try color_of_string s
4342 state.text <- Printf.sprintf
"bad color `%s': %s"
4349 let te = name ^
": ", "", None
, textentry, ondone, true in
4350 state.text <- color_to_string (get
());
4351 state.mode
<- Textentry
(te, leave m_prev_mode
);
4355 method string name get
set =
4357 (name, `
string get
, 1, Action
(
4359 let ondone s = set s in
4360 let te = name ^
": ", "", None
, textentry, ondone, true in
4361 state.mode
<- Textentry
(te, leave m_prev_mode
);
4365 method colorspace
name get
set =
4367 (name, `
string get
, 1, Action
(
4371 inherit lvsourcebase
4374 m_active
<- CSTE.to_int conf.colorspace
;
4377 method getitemcount
=
4378 Array.length
CSTE.names
4381 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4382 ignore
(uioh
, first, pan
, qsearch);
4383 if not cancel
then set active;
4385 method hasaction
_ = true
4389 let modehash = findkeyhash conf "info" in
4390 coe (new listview ~
source ~trusted
:true ~
modehash)
4393 method paxmark
name get
set =
4395 (name, `
string get
, 1, Action
(
4399 inherit lvsourcebase
4402 m_active
<- MTE.to_int conf.paxmark
;
4405 method getitemcount
= Array.length
MTE.names
4406 method getitem
n = (MTE.names.(n), 0)
4407 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4408 ignore
(uioh
, first, pan
, qsearch);
4409 if not cancel
then set active;
4411 method hasaction
_ = true
4415 let modehash = findkeyhash conf "info" in
4416 coe (new listview ~
source ~trusted
:true ~
modehash)
4419 method fitmodel
name get
set =
4421 (name, `
string get
, 1, Action
(
4425 inherit lvsourcebase
4428 m_active
<- FMTE.to_int conf.fitmodel
;
4431 method getitemcount
= Array.length
FMTE.names
4432 method getitem
n = (FMTE.names.(n), 0)
4433 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4434 ignore
(uioh
, first, pan
, qsearch);
4435 if not cancel
then set active;
4437 method hasaction
_ = true
4441 let modehash = findkeyhash conf "info" in
4442 coe (new listview ~
source ~trusted
:true ~
modehash)
4445 method caption
s offset
=
4446 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4448 method caption2
s f offset
=
4449 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4451 method getitemcount
= Array.length m_a
4454 let tostr = function
4455 | `
int f -> string_of_int
(f ())
4456 | `intws
f -> string_with_suffix_of_int (f ())
4458 | `color
f -> color_to_string (f ())
4459 | `
bool (btos, f) -> btos (f ())
4462 let name, t
, offset
, _ = m_a
.(n) in
4463 ((let s = tostr t
in
4464 if String.length
s > 0
4465 then Printf.sprintf
"%s\t%s" name s
4469 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4473 m_qsearch
<- qsearch;
4475 match m_a
.(active) with
4476 | _, _, _, Action
f -> f uioh
4488 method hasaction
n =
4490 | _, _, _, Action
_ -> true
4494 let rec fillsrc prevmode prevuioh
=
4495 let sep () = src#caption
"" 0 in
4496 let colorp name get
set =
4498 (fun () -> color_to_string (get
()))
4501 let c = color_of_string v in
4504 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4507 let oldmode = state.mode
in
4508 let birdseye = isbirdseye state.mode
in
4510 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4512 src#
bool "presentation mode"
4513 (fun () -> conf.presentation
)
4514 (fun v -> setpresentationmode v);
4516 src#
bool "ignore case in searches"
4517 (fun () -> conf.icase
)
4518 (fun v -> conf.icase
<- v);
4521 (fun () -> conf.preload)
4522 (fun v -> conf.preload <- v);
4524 src#
bool "highlight links"
4525 (fun () -> conf.hlinks
)
4526 (fun v -> conf.hlinks
<- v);
4528 src#
bool "under info"
4529 (fun () -> conf.underinfo
)
4530 (fun v -> conf.underinfo
<- v);
4532 src#
bool "persistent bookmarks"
4533 (fun () -> conf.savebmarks
)
4534 (fun v -> conf.savebmarks
<- v);
4536 src#fitmodel
"fit model"
4537 (fun () -> FMTE.to_string conf.fitmodel
)
4538 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4540 src#
bool "trim margins"
4541 (fun () -> conf.trimmargins
)
4542 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4544 src#
bool "persistent location"
4545 (fun () -> conf.jumpback
)
4546 (fun v -> conf.jumpback
<- v);
4549 src#
int "inter-page space"
4550 (fun () -> conf.interpagespace
)
4552 conf.interpagespace
<- n;
4553 docolumns conf.columns
;
4555 match state.layout with
4560 state.maxy <- calcheight ();
4561 let y = getpagey pageno in
4566 (fun () -> conf.pagebias
)
4567 (fun v -> conf.pagebias
<- v);
4569 src#
int "scroll step"
4570 (fun () -> conf.scrollstep
)
4571 (fun n -> conf.scrollstep
<- n);
4573 src#
int "horizontal scroll step"
4574 (fun () -> conf.hscrollstep
)
4575 (fun v -> conf.hscrollstep
<- v);
4577 src#
int "auto scroll step"
4579 match state.autoscroll
with
4581 | _ -> conf.autoscrollstep
)
4583 if state.autoscroll
<> None
4584 then state.autoscroll
<- Some
n;
4585 conf.autoscrollstep
<- n);
4588 (fun () -> truncate
(conf.zoom *. 100.))
4589 (fun v -> setzoom ((float v) /. 100.));
4592 (fun () -> conf.angle
)
4593 (fun v -> reqlayout v conf.fitmodel
);
4595 src#
int "scroll bar width"
4596 (fun () -> conf.scrollbw
)
4599 reshape state.winw
state.winh
;
4602 src#
int "scroll handle height"
4603 (fun () -> conf.scrollh
)
4604 (fun v -> conf.scrollh
<- v;);
4606 src#
int "thumbnail width"
4607 (fun () -> conf.thumbw
)
4609 conf.thumbw
<- min
4096 v;
4612 leavebirdseye beye
false;
4617 let mode = state.mode in
4618 src#
string "columns"
4620 match conf.columns
with
4622 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4623 | Csplit
(count
, _) -> "-" ^ string_of_int count
4626 let n, a, b = multicolumns_of_string v in
4627 setcolumns mode n a b);
4630 src#caption
"Pixmap cache" 0;
4631 src#int_with_suffix
"size (advisory)"
4632 (fun () -> conf.memlimit
)
4633 (fun v -> conf.memlimit
<- v);
4636 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4637 (string_with_suffix_of_int state.memused
)
4638 (Hashtbl.length
state.tilemap
)) 1;
4641 src#caption
"Layout" 0;
4642 src#caption2
"Dimension"
4644 Printf.sprintf
"%dx%d (virtual %dx%d)"
4645 state.winw
state.winh
4650 src#caption2
"Position" (fun () ->
4651 Printf.sprintf
"%dx%d" state.x state.y
4654 src#caption2
"Position" (fun () -> describe_location ()) 1
4658 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4659 "Save these parameters as global defaults at exit"
4660 (fun () -> conf.bedefault
)
4661 (fun v -> conf.bedefault
<- v)
4665 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4666 src#
bool ~offset
:0 ~
btos "Extended parameters"
4667 (fun () -> !showextended)
4668 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4672 (fun () -> conf.checkers
)
4673 (fun v -> conf.checkers
<- v; setcheckers v);
4674 src#
bool "update cursor"
4675 (fun () -> conf.updatecurs
)
4676 (fun v -> conf.updatecurs
<- v);
4678 (fun () -> conf.verbose
)
4679 (fun v -> conf.verbose
<- v);
4680 src#
bool "invert colors"
4681 (fun () -> conf.invert
)
4682 (fun v -> conf.invert
<- v);
4684 (fun () -> conf.maxhfit
)
4685 (fun v -> conf.maxhfit
<- v);
4686 src#
bool "redirect stderr"
4687 (fun () -> conf.redirectstderr)
4688 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4690 (fun () -> conf.pax
!= None
)
4693 then conf.pax
<- Some
(ref (now (), 0, 0))
4694 else conf.pax
<- None
);
4695 src#
string "uri launcher"
4696 (fun () -> conf.urilauncher
)
4697 (fun v -> conf.urilauncher
<- v);
4698 src#
string "path launcher"
4699 (fun () -> conf.pathlauncher
)
4700 (fun v -> conf.pathlauncher
<- v);
4701 src#
string "tile size"
4702 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4705 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4706 conf.tilew
<- max
64 w;
4707 conf.tileh
<- max
64 h;
4710 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4713 src#
int "texture count"
4714 (fun () -> conf.texcount
)
4717 then conf.texcount
<- v
4718 else showtext '
!'
" Failed to set texture count please retry later"
4720 src#
int "slice height"
4721 (fun () -> conf.sliceheight
)
4723 conf.sliceheight
<- v;
4724 wcmd "sliceh %d" conf.sliceheight
;
4726 src#
int "anti-aliasing level"
4727 (fun () -> conf.aalevel
)
4729 conf.aalevel
<- bound v 0 8;
4730 state.anchor <- getanchor ();
4731 opendoc state.path
state.password
;
4733 src#
string "page scroll scaling factor"
4734 (fun () -> string_of_float
conf.pgscale)
4737 let s = float_of_string
v in
4740 state.text <- Printf.sprintf
4741 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4744 src#
int "ui font size"
4745 (fun () -> fstate.fontsize
)
4746 (fun v -> setfontsize (bound v 5 100));
4747 src#
int "hint font size"
4748 (fun () -> conf.hfsize
)
4749 (fun v -> conf.hfsize
<- bound v 5 100);
4750 colorp "background color"
4751 (fun () -> conf.bgcolor
)
4752 (fun v -> conf.bgcolor
<- v);
4753 src#
bool "crop hack"
4754 (fun () -> conf.crophack
)
4755 (fun v -> conf.crophack
<- v);
4756 src#
string "trim fuzz"
4757 (fun () -> irect_to_string conf.trimfuzz
)
4760 conf.trimfuzz
<- irect_of_string v;
4762 then settrim true conf.trimfuzz
;
4764 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4766 src#
string "throttle"
4768 match conf.maxwait
with
4769 | None
-> "show place holder if page is not ready"
4772 then "wait for page to fully render"
4774 "wait " ^ string_of_float
time
4775 ^
" seconds before showing placeholder"
4779 let f = float_of_string
v in
4781 then conf.maxwait
<- None
4782 else conf.maxwait
<- Some
f
4784 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4786 src#
string "ghyll scroll"
4788 match conf.ghyllscroll
with
4790 | Some nab
-> ghyllscroll_to_string nab
4795 if String.length
v = 0
4797 else Some
(ghyllscroll_of_string v)
4799 conf.ghyllscroll
<- gs
4801 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4803 src#
string "selection command"
4804 (fun () -> conf.selcmd
)
4805 (fun v -> conf.selcmd
<- v);
4806 src#
string "synctex command"
4807 (fun () -> conf.stcmd
)
4808 (fun v -> conf.stcmd
<- v);
4809 src#
string "pax command"
4810 (fun () -> conf.paxcmd
)
4811 (fun v -> conf.paxcmd
<- v);
4812 src#colorspace
"color space"
4813 (fun () -> CSTE.to_string conf.colorspace
)
4815 conf.colorspace
<- CSTE.of_int v;
4819 src#paxmark
"pax mark method"
4820 (fun () -> MTE.to_string conf.paxmark
)
4821 (fun v -> conf.paxmark
<- MTE.of_int v);
4825 (fun () -> conf.usepbo
)
4826 (fun v -> conf.usepbo
<- v);
4827 src#
bool "mouse wheel scrolls pages"
4828 (fun () -> conf.wheelbypage
)
4829 (fun v -> conf.wheelbypage
<- v);
4830 src#
bool "open remote links in a new instance"
4831 (fun () -> conf.riani
)
4832 (fun v -> conf.riani
<- v);
4836 src#caption
"Document" 0;
4837 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4838 src#caption2
"Pages"
4839 (fun () -> string_of_int
state.pagecount
) 1;
4840 src#caption2
"Dimensions"
4841 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4845 src#caption
"Trimmed margins" 0;
4846 src#caption2
"Dimensions"
4847 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4851 src#caption
"OpenGL" 0;
4852 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4853 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4856 src#caption
"Location" 0;
4857 if String.length
state.origin
> 0
4858 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4859 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4861 src#reset prevmode prevuioh
;
4865 let prevmode = state.mode
4866 and prevuioh
= state.uioh in
4867 fillsrc prevmode prevuioh
;
4868 let source = (src :> lvsource
) in
4869 let modehash = findkeyhash conf "info" in
4870 state.uioh <- coe (object (self)
4871 inherit listview ~
source ~trusted
:true ~
modehash as super
4872 val mutable m_prevmemused
= 0
4873 method infochanged
= function
4875 if m_prevmemused
!= state.memused
4877 m_prevmemused
<- state.memused
;
4878 G.postRedisplay "memusedchanged";
4880 | Pdim
-> G.postRedisplay "pdimchanged"
4881 | Docinfo
-> fillsrc prevmode prevuioh
4883 method key key mask
=
4884 if not
(Wsi.withctrl mask
)
4887 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4888 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4889 | _ -> super#
key key mask
4890 else super#
key key mask
4892 G.postRedisplay "info";
4898 inherit lvsourcebase
4899 method getitemcount
= Array.length
state.help
4901 let s, l, _ = state.help
.(n) in
4904 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4908 m_qsearch
<- qsearch;
4909 match state.help
.(active) with
4910 | _, _, Action
f -> Some
(f uioh)
4920 method hasaction
n =
4921 match state.help
.(n) with
4922 | _, _, Action
_ -> true
4929 let modehash = findkeyhash conf "help" in
4930 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4931 G.postRedisplay "help";
4936 let re = Str.regexp
"[\r\n]" in
4938 inherit lvsourcebase
4939 val mutable m_items
= [||]
4941 method getitemcount
= 1 + Array.length m_items
4946 else m_items
.(n-1), 0
4948 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4953 then Buffer.clear
state.errmsgs
;
4954 m_qsearch
<- qsearch;
4961 method hasaction
n =
4965 state.newerrmsgs
<- false;
4966 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4967 m_items
<- Array.of_list
l
4975 let source = (msgsource :> lvsource
) in
4976 let modehash = findkeyhash conf "listview" in
4977 state.uioh <- coe (object
4978 inherit listview ~
source ~trusted
:false ~
modehash as super
4981 then msgsource#reset
;
4984 G.postRedisplay "msgs";
4987 let quickbookmark ?title
() =
4988 match state.layout with
4994 let sec = Unix.gettimeofday
() in
4995 let tm = Unix.localtime
sec in
4996 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5000 (tm.Unix.tm_year
+ 1900)
5003 | Some
title -> title
5005 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
5008 let setautoscrollspeed step goingdown
=
5009 let incr = max
1 ((abs step
) / 2) in
5010 let incr = if goingdown
then incr else -incr in
5011 let astep = step
+ incr in
5012 state.autoscroll
<- Some
astep;
5015 let gotounder = function
5016 | Ulinkgoto
(pageno, top) ->
5020 gotopage1 pageno top;
5026 | Uremote
(filename
, pageno) ->
5028 if String.length filename
> 0
5030 if Filename.is_relative filename
5032 let dir = Filename.dirname
state.path in
5034 if Filename.is_implicit
dir
5035 then Filename.concat
(Sys.getcwd
()) dir
5038 Filename.concat
dir filename
5043 if Sys.file_exists
path
5047 if String.length
path > 0
5051 let command = !selfexec ^
" " ^
path in
5052 try popen command []
5055 "failed to execute `%s': %s\n" command (exntos exn
);
5058 let anchor = getanchor () in
5059 let ranchor = state.path, state.password
, anchor, state.origin
in
5061 state.anchor <- (pageno, 0.0, 0.0);
5062 state.ranchors
<- ranchor :: state.ranchors
;
5065 else showtext '
!'
("Could not find " ^ filename
)
5067 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
5071 match conf.columns
with
5073 | _ -> state.x != 0 || conf.zoom > 1.0
5076 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5078 let existsinrow pageno (columns
, coverA
, coverB
) p =
5079 let last = ((pageno - coverA
) mod columns
) + columns
in
5080 let rec any = function
5083 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5087 then (if l.pageno = last then false else any rest
)
5095 match state.layout with
5097 let pageno = page_of_y state.y in
5098 gotoghyll (getpagey (pageno+1))
5100 match conf.columns
with
5102 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5104 let y = clamp (pgscale state.winh
) in
5107 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5108 gotoghyll (getpagey pageno)
5109 | Cmulti
((c, _, _) as cl, _) ->
5110 if conf.presentation
5111 && (existsinrow l.pageno cl
5112 (fun l -> l.pageh
> l.pagey + l.pagevh))
5114 let y = clamp (pgscale state.winh
) in
5117 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5118 gotoghyll (getpagey pageno)
5120 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5122 let pagey, pageh
= getpageyh l.pageno in
5123 let pagey = pagey + pageh
* l.pagecol
in
5124 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5125 gotoghyll (pagey + pageh
+ ips)
5129 match state.layout with
5131 let pageno = page_of_y state.y in
5132 gotoghyll (getpagey (pageno-1))
5134 match conf.columns
with
5136 if conf.presentation
&& l.pagey != 0
5138 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5140 let pageno = max
0 (l.pageno-1) in
5141 gotoghyll (getpagey pageno)
5142 | Cmulti
((c, _, coverB
) as cl, _) ->
5143 if conf.presentation
&&
5144 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5146 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5149 if l.pageno = state.pagecount
- coverB
5153 let pageno = max
0 (l.pageno-decr) in
5154 gotoghyll (getpagey pageno)
5162 let pageno = max
0 (l.pageno-1) in
5163 let pagey, pageh
= getpageyh pageno in
5166 let pagey, pageh
= getpageyh l.pageno in
5167 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5172 let viewkeyboard key mask
=
5174 let mode = state.mode in
5175 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5178 G.postRedisplay "view:enttext"
5180 let ctrl = Wsi.withctrl mask
in
5182 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5188 | 0xff63 -> (* insert *)
5189 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5191 state.mode <- LinkNav
(Ltgendir
0);
5194 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5196 | 0xff1b | 113 -> (* escape / q *)
5197 begin match state.mstate
with
5199 state.mstate
<- Mnone
;
5200 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5201 G.postRedisplay "kill zoom rect";
5203 begin match state.mode with
5206 G.postRedisplay "esc leave linknav"
5208 match state.ranchors
with
5210 | (path, password
, anchor, origin
) :: rest
->
5211 state.ranchors
<- rest
;
5212 state.anchor <- anchor;
5213 state.origin
<- origin
;
5214 opendoc path password
5218 | 0xff08 -> (* backspace *)
5219 gotoghyll (getnav ~
-1)
5227 G.postRedisplay "dehighlight";
5229 | 47 | 63 -> (* / ? *)
5230 let ondone isforw
s =
5231 cbput state.hists
.pat
s;
5232 state.searchpattern
<- s;
5235 let s = String.create
1 in
5236 s.[0] <- Char.chr
key;
5237 enttext (s, "", Some
(onhist state.hists
.pat
),
5238 textentry, ondone (key = 47), true)
5240 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5241 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5242 setzoom (conf.zoom +. incr)
5244 | 43 | 0xffab -> (* + *)
5247 try int_of_string
s with exc
->
5248 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5254 state.text <- "page bias is now " ^ string_of_int
n;
5257 enttext ("page bias: ", "", None
, intentry, ondone, true)
5259 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5260 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5261 setzoom (max
0.01 (conf.zoom -. decr))
5263 | 45 | 0xffad -> (* - *)
5264 let ondone msg
= state.text <- msg
in
5266 "option [acfhilpstvxACFPRSZTISMB]: ", "", None
,
5267 optentry state.mode, ondone, true
5270 | 48 when ctrl -> (* ctrl-0 *)
5278 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5280 match conf.columns
with
5281 | Csingle
_ | Cmulti
_ -> 1
5282 | Csplit
(n, _) -> n
5284 let h = state.winh
-
5285 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5287 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5288 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5291 | 51 when ctrl -> (* ctrl-3 *)
5293 match conf.fitmodel
with
5294 | FitWidth
-> FitProportional
5295 | FitProportional
-> FitPage
5296 | FitPage
-> FitWidth
5298 state.text <- "fit model: " ^
FMTE.to_string fm;
5299 reqlayout conf.angle
fm
5301 | 0xffc6 -> (* f9 *)
5304 | 57 when ctrl -> (* ctrl-9 *)
5307 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5308 when not
ctrl -> (* 0..9 *)
5311 try int_of_string
s with exc
->
5312 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5318 cbput state.hists
.pag
(string_of_int
n);
5319 gotopage1 (n + conf.pagebias
- 1) 0;
5322 let pageentry text key =
5323 match Char.unsafe_chr
key with
5324 | '
g'
-> TEdone
text
5325 | _ -> intentry text key
5327 let text = "x" in text.[0] <- Char.chr
key;
5328 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5331 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5332 reshape state.winw
state.winh
;
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 setzoom state.prevzoom
5511 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5512 begin match state.autoscroll
with
5514 begin match state.mode with
5515 | Birdseye beye
-> upbirdseye 1 beye
5518 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5520 if not
(Wsi.withshift mask
) && conf.presentation
5522 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5526 setautoscrollspeed n false
5529 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5530 begin match state.autoscroll
with
5532 begin match state.mode with
5533 | Birdseye beye
-> downbirdseye 1 beye
5536 then gotoy_and_clear_text (clamp (state.winh
/2))
5538 if not
(Wsi.withshift mask
) && conf.presentation
5540 else gotoy_and_clear_text (clamp conf.scrollstep
)
5544 setautoscrollspeed n true
5547 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5548 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5554 else conf.hscrollstep
5556 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5557 state.x <- panbound (state.x + dx);
5558 gotoy_and_clear_text state.y
5561 G.postRedisplay "left/right"
5564 | 0xff55 | 0xff9a -> (* (kp) prior *)
5568 match state.layout with
5570 | l :: _ -> state.y - l.pagey
5572 clamp (pgscale (-state.winh
))
5576 | 0xff56 | 0xff9b -> (* (kp) next *)
5580 match List.rev
state.layout with
5582 | l :: _ -> getpagey l.pageno
5584 clamp (pgscale state.winh
)
5588 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5590 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5591 gotoghyll (clamp state.maxy)
5594 when Wsi.withalt mask
-> (* alt-(kp) right *)
5595 gotoghyll (getnav 1)
5597 when Wsi.withalt mask
-> (* alt-(kp) left *)
5598 gotoghyll (getnav ~
-1)
5603 | 118 when conf.debug
-> (* v *)
5606 match getopaque l.pageno with
5609 let x0, y0, x1, y1 = pagebbox opaque
in
5610 let a,b = float x0, float y0 in
5611 let c,d = float x1, float y0 in
5612 let e,f = float x1, float y1 in
5613 let h,j
= float x0, float y1 in
5614 let rect = (a,b,c,d,e,f,h,j
) in
5616 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5618 G.postRedisplay "v";
5621 vlog "huh? %s" (Wsi.keyname
key)
5624 let linknavkeyboard key mask
linknav =
5625 let getpage pageno =
5626 let rec loop = function
5628 | l :: _ when l.pageno = pageno -> Some
l
5629 | _ :: rest
-> loop rest
5630 in loop state.layout
5632 let doexact (pageno, n) =
5633 match getopaque pageno, getpage pageno with
5634 | Some opaque
, Some
l ->
5635 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5637 let under = getlink opaque
n in
5638 G.postRedisplay "link gotounder";
5644 | 0xff50 -> (* home *)
5645 Some
(findlink opaque LDfirst
), -1
5647 | 0xff57 -> (* end *)
5648 Some
(findlink opaque LDlast
), 1
5650 | 0xff51 -> (* left *)
5651 Some
(findlink opaque
(LDleft
n)), -1
5653 | 0xff53 -> (* right *)
5654 Some
(findlink opaque
(LDright
n)), 1
5656 | 0xff52 -> (* up *)
5657 Some
(findlink opaque
(LDup
n)), -1
5659 | 0xff54 -> (* down *)
5660 Some
(findlink opaque
(LDdown
n)), 1
5665 begin match findpwl
l.pageno dir with
5669 state.mode <- LinkNav
(Ltgendir
dir);
5670 let y, h = getpageyh pageno in
5673 then y + h - state.winh
5678 begin match getopaque pageno, getpage pageno with
5679 | Some opaque
, Some
_ ->
5681 let ld = if dir > 0 then LDfirst
else LDlast
in
5684 begin match link with
5686 showlinktype (getlink opaque
m);
5687 state.mode <- LinkNav
(Ltexact
(pageno, m));
5688 G.postRedisplay "linknav jpage";
5695 begin match opt with
5696 | Some Lnotfound
-> pwl l dir;
5697 | Some
(Lfound
m) ->
5701 let _, y0, _, y1 = getlinkrect opaque
m in
5703 then gotopage1 l.pageno y0
5705 let d = fstate.fontsize
+ 1 in
5706 if y1 - l.pagey > l.pagevh - d
5707 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5708 else G.postRedisplay "linknav";
5710 showlinktype (getlink opaque
m);
5711 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5714 | None
-> viewkeyboard key mask
5716 | _ -> viewkeyboard key mask
5721 G.postRedisplay "leave linknav"
5725 | Ltgendir
_ -> viewkeyboard key mask
5726 | Ltexact exact
-> doexact exact
5729 let keyboard key mask
=
5730 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5731 then wcmd "interrupt"
5732 else state.uioh <- state.uioh#
key key mask
5735 let birdseyekeyboard key mask
5736 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5738 match conf.columns
with
5740 | Cmulti
((c, _, _), _) -> c
5741 | Csplit
_ -> failwith
"bird's eye split mode"
5743 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5745 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5746 let y, h = getpageyh pageno in
5747 let top = (state.winh
- h) / 2 in
5748 gotoy (max
0 (y - top))
5749 | 0xff0d (* enter *)
5750 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5751 | 0xff1b -> leavebirdseye beye
true (* escape *)
5752 | 0xff52 -> upbirdseye incr beye
(* up *)
5753 | 0xff54 -> downbirdseye incr beye
(* down *)
5754 | 0xff51 -> upbirdseye 1 beye
(* left *)
5755 | 0xff53 -> downbirdseye 1 beye
(* right *)
5757 | 0xff55 -> (* prior *)
5758 begin match state.layout with
5762 state.mode <- Birdseye
(
5763 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5765 gotopage1 l.pageno 0;
5768 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5770 | [] -> gotoy (clamp (-state.winh
))
5772 state.mode <- Birdseye
(
5773 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5775 gotopage1 l.pageno 0
5778 | [] -> gotoy (clamp (-state.winh
))
5781 | 0xff56 -> (* next *)
5782 begin match List.rev
state.layout with
5784 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5785 begin match layout with
5787 let incr = l.pageh
- l.pagevh in
5792 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5794 G.postRedisplay "birdseye pagedown";
5796 else gotoy (clamp (incr + conf.interpagespace
*2));
5800 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5801 gotopage1 l.pageno 0;
5804 | [] -> gotoy (clamp state.winh
)
5807 | 0xff50 -> (* home *)
5808 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5811 | 0xff57 -> (* end *)
5812 let pageno = state.pagecount
- 1 in
5813 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5814 if not
(pagevisible state.layout pageno)
5817 match List.rev
state.pdims
with
5819 | (_, _, h, _) :: _ -> h
5821 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5822 else G.postRedisplay "birdseye end";
5823 | _ -> viewkeyboard key mask
5828 match state.mode with
5829 | Textentry
_ -> scalecolor 0.4
5831 | View
-> scalecolor 1.0
5832 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5833 if l.pageno = hooverpageno
5836 if l.pageno = pageno
5844 let postdrawpage l linkindexbase
=
5845 match getopaque l.pageno with
5847 if tileready l l.pagex
l.pagey
5849 let x = l.pagedispx - l.pagex
5850 and y = l.pagedispy - l.pagey in
5852 match conf.columns
with
5853 | Csingle
_ | Cmulti
_ ->
5854 (if conf.hlinks
then 1 else 0)
5856 && not
(isbirdseye state.mode) then 2 else 0)
5860 match state.mode with
5861 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5864 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5869 let scrollindicator () =
5870 let sbw, ph
, sh = state.uioh#
scrollph in
5871 let sbh, pw, sw = state.uioh#scrollpw
in
5873 GlDraw.color (0.64, 0.64, 0.64);
5875 (float (state.winw
- sbw), 0.)
5876 (float state.winw
, float state.winh
)
5879 (0., float (state.winh
- sbh))
5880 (float (wadjsb state.winw
- 1), float state.winh
)
5882 GlDraw.color (0.0, 0.0, 0.0);
5885 (float (state.winw
- sbw), ph
)
5886 (float state.winw
, ph
+. sh)
5889 (pw, float (state.winh
- sbh))
5890 (pw +. sw, float state.winh
)
5895 match state.mstate
with
5896 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5899 | Msel
((x0, y0), (x1, y1)) ->
5900 let rec loop = function
5902 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5903 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5904 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5905 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5907 match getopaque l.pageno with
5909 let x0, y0 = pagetranslatepoint l x0 y0 in
5910 let x1, y1 = pagetranslatepoint l x1 y1 in
5911 seltext opaque
(x0, y0, x1, y1);
5919 let showrects rects
=
5921 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5922 GlDraw.polygon_mode `both `fill
;
5923 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5925 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5927 if l.pageno = pageno
5929 let dx = float (l.pagedispx - l.pagex
) in
5930 let dy = float (l.pagedispy - l.pagey) in
5931 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
5932 GlDraw.begins `quads
;
5934 GlDraw.vertex2
(x0+.dx, y0+.dy);
5935 GlDraw.vertex2
(x1+.dx, y1+.dy);
5936 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5937 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5948 GlClear.color (scalecolor2 conf.bgcolor
);
5949 GlClear.clear
[`
color];
5950 List.iter
drawpage state.layout;
5952 match state.mode with
5953 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5954 begin match getopaque pageno with
5956 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5963 | None
-> state.rects
5968 let rec postloop linkindexbase
= function
5970 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5971 postloop linkindexbase rest
5975 postloop 0 state.layout;
5977 begin match state.mstate
with
5978 | Mzoomrect
((x0, y0), (x1, y1)) ->
5980 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5981 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5982 GlDraw.rect (float x0, float y0)
5983 (float x1, float y1);
5992 let zoomrect x y x1 y1 =
5995 and y0 = min
y y1 in
5996 gotoy (state.y + y0);
5997 state.anchor <- getanchor ();
5998 let zoom = (float state.w) /. float (x1 - x0) in
6000 match conf.fitmodel
, conf.columns
with
6001 | FitPage
, Csplit
_ ->
6002 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6005 let adjw = wadjsb state.winw
in
6007 then (adjw - state.w) / 2
6010 state.x <- (state.x + margin) - x0;
6012 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6013 state.mstate
<- Mnone
;
6017 let g opaque
l px py =
6018 match rectofblock opaque
px py with
6020 let x0 = a.(0) -. 20. in
6021 let x1 = a.(1) +. 20. in
6022 let y0 = a.(2) -. 20. in
6024 gotoy (getpagey l.pageno + truncate
y0);
6025 state.anchor <- getanchor ();
6026 let zoom = (float state.w) /. (x1 -. x0) in
6028 match conf.fitmodel
, conf.columns
with
6029 | FitPage
, Csplit
_ ->
6030 onppundermouse (fun _ l _ _ -> Some
l.pagedispx)
6031 (truncate
x0) (truncate
y0) 0
6034 let adjw = wadjsb state.winw
in
6036 then (adjw - state.w) / 2
6039 state.x <- margin - truncate
x0;
6041 state.bzoom
<- false;
6045 onppundermouse g x y ()
6049 let winw = wadjsb state.winw - 1 in
6050 let s = float x /. float winw in
6051 let destx = truncate
(float (state.w + winw) *. s) in
6052 state.x <- winw - destx;
6053 gotoy_and_clear_text state.y;
6054 state.mstate
<- Mscrollx
;
6058 let s = float y /. float state.winh
in
6059 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6060 gotoy_and_clear_text desty;
6061 state.mstate
<- Mscrolly
;
6064 let viewmouse button down
x y mask
=
6066 | n when (n == 4 || n == 5) && not down
->
6067 if Wsi.withctrl mask
6069 match state.mstate
with
6070 | Mzoom
(oldn
, i
) ->
6078 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6080 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6082 let zoom = conf.zoom -. incr in
6084 state.mstate
<- Mzoom
(n, 0);
6086 state.mstate
<- Mzoom
(n, i
+1);
6088 else state.mstate
<- Mzoom
(n, 0)
6090 | _ -> state.mstate
<- Mzoom
(n, 0)
6093 match state.autoscroll
with
6094 | Some step
-> setautoscrollspeed step
(n=4)
6096 if conf.wheelbypage
|| conf.presentation
6105 then -conf.scrollstep
6106 else conf.scrollstep
6108 let incr = incr * 2 in
6109 let y = clamp incr in
6110 gotoy_and_clear_text y
6113 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6115 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6116 gotoy_and_clear_text state.y
6118 | 1 when Wsi.withshift mask
->
6119 state.mstate
<- Mnone
;
6122 match unproject x y with
6123 | Some
(pageno, ux
, uy
) ->
6124 let cmd = Printf.sprintf
6126 conf.stcmd
state.path pageno ux uy
6132 | 1 when Wsi.withctrl mask
->
6135 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6136 state.mstate
<- Mpan
(x, y)
6139 state.mstate
<- Mnone
6144 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6146 state.mstate
<- Mzoomrect
(p, p)
6149 match state.mstate
with
6150 | Mzoomrect
((x0, y0), _) ->
6151 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6152 then zoomrect x0 y0 x y
6154 state.mstate
<- Mnone
;
6155 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6156 G.postRedisplay "kill accidental zoom rect";
6159 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6160 state.mstate
<- Mnone
6163 | 1 when x > state.winw - vscrollw () ->
6166 let _, position, sh = state.uioh#
scrollph in
6167 if y > truncate
position && y < truncate
(position +. sh)
6168 then state.mstate
<- Mscrolly
6171 state.mstate
<- Mnone
6173 | 1 when y > state.winh
- hscrollh () ->
6176 let _, position, sw = state.uioh#scrollpw
in
6177 if x > truncate
position && x < truncate
(position +. sw)
6178 then state.mstate
<- Mscrollx
6181 state.mstate
<- Mnone
6183 | 1 when state.bzoom
-> zoomblock x y
6186 let dest = if down
then getunder x y else Unone
in
6187 begin match dest with
6191 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6194 | Unone
when down
->
6195 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6196 state.mstate
<- Mpan
(x, y);
6198 | Unone
| Utext
_ ->
6201 if conf.angle
mod 360 = 0
6203 state.mstate
<- Msel
((x, y), (x, y));
6204 G.postRedisplay "mouse select";
6208 match state.mstate
with
6211 | Mzoom
_ | Mscrollx
| Mscrolly
->
6212 state.mstate
<- Mnone
6214 | Mzoomrect
((x0, y0), _) ->
6218 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6219 state.mstate
<- Mnone
6221 | Msel
((x0, y0), (x1, y1)) ->
6222 let rec loop = function
6226 let a0 = l.pagedispy in
6227 let a1 = a0 + l.pagevh in
6228 let b0 = l.pagedispx in
6229 let b1 = b0 + l.pagevw in
6230 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6231 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6235 match getopaque l.pageno with
6238 match Ne.pipe () with
6242 "can not create sel pipe: %s"
6245 let doclose what fd
=
6246 Ne.clo fd
(fun msg
->
6247 dolog
"%s close failed: %s" what msg
)
6250 popen conf.selcmd
[r, 0; w, -1];
6251 copysel
w opaque
true;
6253 G.postRedisplay "copysel";
6255 dolog
"can not execute %S: %s"
6256 conf.selcmd
(exntos exn
);
6264 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6265 state.mstate
<- Mnone
;
6272 let birdseyemouse button down
x y mask
6273 (conf, leftx
, _, hooverpageno
, anchor) =
6276 let rec loop = function
6279 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6280 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6282 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6288 | _ -> viewmouse button down
x y mask
6291 let mouse button down
x y mask
=
6292 state.uioh <- state.uioh#button button down
x y mask
;
6296 state.uioh <- state.uioh#
motion x y
6300 state.uioh <- state.uioh#
pmotion x y;
6306 method key key mask
=
6307 begin match state.mode with
6308 | Textentry
textentry -> textentrykeyboard key mask
textentry
6309 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6310 | View
-> viewkeyboard key mask
6311 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6315 method button button bstate
x y mask
=
6316 begin match state.mode with
6318 | View
-> viewmouse button bstate
x y mask
6319 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6325 begin match state.mode with
6327 | View
| Birdseye
_ | LinkNav
_ ->
6328 match state.mstate
with
6329 | Mzoom
_ | Mnone
-> ()
6334 state.mstate
<- Mpan
(x, y);
6336 then state.x <- panbound (state.x + dx);
6338 gotoy_and_clear_text y
6341 state.mstate
<- Msel
(a, (x, y));
6342 G.postRedisplay "motion select";
6345 let y = min
state.winh
(max
0 y) in
6349 let x = min
state.winw (max
0 x) in
6352 | Mzoomrect
(p0
, _) ->
6353 state.mstate
<- Mzoomrect
(p0
, (x, y));
6354 G.postRedisplay "motion zoomrect";
6358 method pmotion x y =
6359 begin match state.mode with
6360 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6361 let rec loop = function
6363 if hooverpageno
!= -1
6365 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6366 G.postRedisplay "pmotion birdseye no hoover";
6369 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6370 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6372 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6373 G.postRedisplay "pmotion birdseye hoover";
6383 match state.mstate
with
6384 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6391 let past, _, _ = !r in
6393 let delta = now -. past in
6396 else r := (now, x, y)
6400 method infochanged
_ = ()
6403 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6406 then 0.0, float state.winh
6407 else scrollph state.y maxy
6412 let winw = wadjsb state.winw in
6413 let fwinw = float winw in
6415 let sw = fwinw /. float state.w in
6416 let sw = fwinw *. sw in
6417 max
sw (float conf.scrollh
)
6420 let maxx = state.w + winw in
6421 let x = winw - state.x in
6422 let percent = float x /. float maxx in
6423 (fwinw -. sw) *. percent
6425 hscrollh (), position, sw
6429 match state.mode with
6430 | LinkNav
_ -> "links"
6431 | Textentry
_ -> "textentry"
6432 | Birdseye
_ -> "birdseye"
6435 findkeyhash conf modename
6437 method eformsgs
= true
6444 let fontpath = ref "";;
6447 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6450 let l = String.length
s in
6451 let b = Buffer.create
l in
6457 try Sys.getenv
"HOME"
6460 ("Can not determine home directory location: " ^ exntos exn
);
6464 let modifier_of_string = function
6465 | "alt" -> Wsi.altmask
6466 | "shift" -> Wsi.shiftmask
6467 | "ctrl" | "control" -> Wsi.ctrlmask
6468 | "meta" -> Wsi.metamask
6473 let r = Str.regexp
"-" in
6475 let elems = Str.full_split
r s in
6478 let m1 = modifier_of_string s in
6480 then (Wsi.namekey
s, m)
6483 | Str.Delim
s when n land 1 = 0 -> g s
6485 | Str.Delim
_ -> (k
, m)
6487 let rec loop n k
m = function
6490 let k, m = f n k m x in
6496 let keys_of_string =
6497 let r = Str.regexp
"[ \t]" in
6499 let elems = Str.split
r s in
6500 List.map
key_of_string elems
6503 let copykeyhashes c =
6504 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6507 let config_of c attrs
=
6511 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6512 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6513 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6514 | "preload" -> { c with preload = bool_of_string
v }
6515 | "page-bias" -> { c with pagebias
= int_of_string
v }
6516 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6517 | "horizontal-scroll-step" ->
6518 { c with hscrollstep
= max
(int_of_string
v) 1 }
6519 | "auto-scroll-step" ->
6520 { c with autoscrollstep
= max
0 (int_of_string
v) }
6521 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6522 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6525 match String.lowercase
v with
6526 | "true" -> Some infinity
6528 | f -> Some
(float_of_string
f)
6530 { c with maxwait
= mw}
6531 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6532 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6533 | "vertical-margin" ->
6534 { c with interpagespace
= max
0 (int_of_string
v) }
6536 let zoom = float_of_string
v /. 100. in
6537 let zoom = max
zoom 0.0 in
6538 { c with zoom = zoom }
6539 | "presentation" -> { c with presentation
= bool_of_string
v }
6540 | "rotation-angle" -> { c with angle
= int_of_string
v }
6541 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6542 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6543 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6544 | "proportional-display" ->
6547 then FitProportional
6550 { c with fitmodel
= fm }
6551 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6552 | "pixmap-cache-size" ->
6553 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6554 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6555 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6556 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6557 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6558 | "background-color" -> { c with bgcolor
= color_of_string v }
6559 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6560 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6561 | "mupdf-store-size" ->
6562 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6563 | "checkers" -> { c with checkers
= bool_of_string
v }
6564 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6565 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6566 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6567 | "uri-launcher" -> { c with urilauncher
= unent v }
6568 | "path-launcher" -> { c with pathlauncher
= unent v }
6569 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6570 | "invert-colors" -> { c with invert
= bool_of_string
v }
6571 | "brightness" -> { c with colorscale
= float_of_string
v }
6572 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6574 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6576 let (n, _, _) as nab
= multicolumns_of_string v in
6578 then { c with columns
= Csplit
(-n, [||]) }
6579 else { c with columns
= Cmulti
(nab
, [||]) }
6580 | "birds-eye-columns" ->
6581 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6582 | "selection-command" -> { c with selcmd
= unent v }
6583 | "synctex-command" -> { c with stcmd
= unent v }
6584 | "pax-command" -> { c with paxcmd
= unent v }
6585 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6586 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6587 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6588 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6589 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6590 | "horizontal-scrollbar-visible" ->
6593 then c.scrollb
lor scrollbhv
6594 else c.scrollb
land (lnot
scrollbhv)
6596 { c with scrollb
= b }
6597 | "vertical-scrollbar-visible" ->
6600 then c.scrollb
lor scrollbvv
6601 else c.scrollb
land (lnot
scrollbvv)
6603 { c with scrollb
= b }
6604 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6608 then Some
(ref (0.0, 0, 0))
6610 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6613 prerr_endline
("Error processing attribute (`" ^
6614 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6617 let rec fold c = function
6620 let c = apply c k v in
6623 fold { c with keyhashes
= copykeyhashes c } attrs
;
6626 let fromstring f pos
n v d =
6629 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6630 n v pos
(exntos exn
)
6635 let bookmark_of attrs
=
6636 let rec fold title page
rely visy
= function
6637 | ("title", v) :: rest
-> fold v page
rely visy rest
6638 | ("page", v) :: rest
-> fold title v rely visy rest
6639 | ("rely", v) :: rest
-> fold title page
v visy rest
6640 | ("visy", v) :: rest
-> fold title page
rely v rest
6641 | _ :: rest
-> fold title page
rely visy rest
6642 | [] -> title, page
, rely, visy
6644 fold "invalid" "0" "0" "0" attrs
6648 let rec fold path page
rely pan visy
= function
6649 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6650 | ("page", v) :: rest
-> fold path v rely pan visy rest
6651 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6652 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6653 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6654 | _ :: rest
-> fold path page
rely pan visy rest
6655 | [] -> path, page
, rely, pan
, visy
6657 fold "" "0" "0" "0" "0" attrs
6661 let rec fold rs ls
= function
6662 | ("out", v) :: rest
-> fold v ls rest
6663 | ("in", v) :: rest
-> fold rs
v rest
6664 | _ :: rest
-> fold ls rs rest
6670 let setconf dst
src =
6671 dst
.scrollbw
<- src.scrollbw
;
6672 dst
.scrollh
<- src.scrollh
;
6673 dst
.icase
<- src.icase
;
6674 dst
.preload <- src.preload;
6675 dst
.pagebias
<- src.pagebias
;
6676 dst
.verbose
<- src.verbose
;
6677 dst
.scrollstep
<- src.scrollstep
;
6678 dst
.maxhfit
<- src.maxhfit
;
6679 dst
.crophack
<- src.crophack
;
6680 dst
.autoscrollstep
<- src.autoscrollstep
;
6681 dst
.maxwait
<- src.maxwait
;
6682 dst
.hlinks
<- src.hlinks
;
6683 dst
.underinfo
<- src.underinfo
;
6684 dst
.interpagespace
<- src.interpagespace
;
6685 dst
.zoom <- src.zoom;
6686 dst
.presentation
<- src.presentation
;
6687 dst
.angle
<- src.angle
;
6688 dst
.cwinw
<- src.cwinw
;
6689 dst
.cwinh
<- src.cwinh
;
6690 dst
.savebmarks
<- src.savebmarks
;
6691 dst
.memlimit
<- src.memlimit
;
6692 dst
.fitmodel
<- src.fitmodel
;
6693 dst
.texcount
<- src.texcount
;
6694 dst
.sliceheight
<- src.sliceheight
;
6695 dst
.thumbw
<- src.thumbw
;
6696 dst
.jumpback
<- src.jumpback
;
6697 dst
.bgcolor
<- src.bgcolor
;
6698 dst
.tilew
<- src.tilew
;
6699 dst
.tileh
<- src.tileh
;
6700 dst
.mustoresize
<- src.mustoresize
;
6701 dst
.checkers
<- src.checkers
;
6702 dst
.aalevel
<- src.aalevel
;
6703 dst
.trimmargins
<- src.trimmargins
;
6704 dst
.trimfuzz
<- src.trimfuzz
;
6705 dst
.urilauncher
<- src.urilauncher
;
6706 dst
.colorspace
<- src.colorspace
;
6707 dst
.invert
<- src.invert
;
6708 dst
.colorscale
<- src.colorscale
;
6709 dst
.redirectstderr <- src.redirectstderr;
6710 dst
.ghyllscroll
<- src.ghyllscroll
;
6711 dst
.columns
<- src.columns
;
6712 dst
.beyecolumns
<- src.beyecolumns
;
6713 dst
.selcmd
<- src.selcmd
;
6714 dst
.updatecurs
<- src.updatecurs
;
6715 dst
.pathlauncher
<- src.pathlauncher
;
6716 dst
.keyhashes
<- copykeyhashes src;
6717 dst
.hfsize
<- src.hfsize
;
6718 dst
.hscrollstep
<- src.hscrollstep
;
6719 dst
.pgscale <- src.pgscale;
6720 dst
.usepbo
<- src.usepbo
;
6721 dst
.wheelbypage
<- src.wheelbypage
;
6722 dst
.stcmd
<- src.stcmd
;
6723 dst
.paxcmd
<- src.paxcmd
;
6724 dst
.scrollb
<- src.scrollb
;
6725 dst
.riani
<- src.riani
;
6726 dst
.paxmark
<- src.paxmark
;
6730 else Some
((ref (0.0, 0, 0)));
6734 let h = Hashtbl.create
10 in
6735 let dc = { defconf with angle
= defconf.angle
} in
6736 let rec toplevel v t spos
_ =
6738 | Vdata
| Vcdata
| Vend
-> v
6739 | Vopen
("llppconfig", _, closed
) ->
6742 else { v with f = llppconfig
}
6744 error
"unexpected subelement at top level" s spos
6745 | Vclose
_ -> error
"unexpected close at top level" s spos
6747 and llppconfig
v t spos
_ =
6749 | Vdata
| Vcdata
-> v
6750 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6751 | Vopen
("defaults", attrs
, closed
) ->
6752 let c = config_of dc attrs
in
6756 else { v with f = defaults
}
6758 | Vopen
("ui-font", attrs
, closed
) ->
6759 let rec getsize size
= function
6761 | ("size", v) :: rest
->
6763 fromstring int_of_string spos
"size" v fstate.fontsize
in
6765 | l -> getsize size l
6767 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6770 else { v with f = uifont
(Buffer.create
10) }
6772 | Vopen
("doc", attrs
, closed
) ->
6773 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6774 let path = unent pathent
6775 and pageno = fromstring int_of_string spos
"page" spage
0
6776 and rely = fromstring float_of_string spos
"rely" srely
0.0
6777 and pan
= fromstring int_of_string spos
"pan" span
0
6778 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6779 let c = config_of dc attrs
in
6780 let anchor = (pageno, rely, visy
) in
6782 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6783 else { v with f = doc
path pan
anchor c [] }
6786 error
"unexpected subelement in llppconfig" s spos
6788 | Vclose
"llppconfig" -> { v with f = toplevel }
6789 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6791 and defaults
v t spos
_ =
6793 | Vdata
| Vcdata
-> v
6794 | Vend
-> error
"unexpected end of input in defaults" s spos
6795 | Vopen
("keymap", attrs
, closed
) ->
6797 try List.assoc
"mode" attrs
6798 with Not_found
-> "global" in
6803 let h = findkeyhash dc modename in
6804 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6807 { v with f = pkeymap
ret KeyMap.empty }
6809 | Vopen
(_, _, _) ->
6810 error
"unexpected subelement in defaults" s spos
6812 | Vclose
"defaults" ->
6813 { v with f = llppconfig
}
6815 | Vclose
_ -> error
"unexpected close in defaults" s spos
6817 and uifont
b v t spos
epos =
6820 Buffer.add_substring
b s spos
(epos - spos
);
6822 | Vopen
(_, _, _) ->
6823 error
"unexpected subelement in ui-font" s spos
6824 | Vclose
"ui-font" ->
6825 if String.length
!fontpath = 0
6826 then fontpath := Buffer.contents
b;
6827 { v with f = llppconfig
}
6828 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6829 | Vend
-> error
"unexpected end of input in ui-font" s spos
6831 and doc
path pan
anchor c bookmarks
v t spos
_ =
6833 | Vdata
| Vcdata
-> v
6834 | Vend
-> error
"unexpected end of input in doc" s spos
6835 | Vopen
("bookmarks", _, closed
) ->
6838 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6840 | Vopen
("keymap", attrs
, closed
) ->
6842 try List.assoc
"mode" attrs
6843 with Not_found
-> "global"
6849 let h = findkeyhash c modename in
6850 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6851 doc
path pan
anchor c bookmarks
6853 { v with f = pkeymap
ret KeyMap.empty }
6855 | Vopen
(_, _, _) ->
6856 error
"unexpected subelement in doc" s spos
6859 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6860 { v with f = llppconfig
}
6862 | Vclose
_ -> error
"unexpected close in doc" s spos
6864 and pkeymap
ret keymap
v t spos
_ =
6866 | Vdata
| Vcdata
-> v
6867 | Vend
-> error
"unexpected end of input in keymap" s spos
6868 | Vopen
("map", attrs
, closed
) ->
6869 let r, l = map_of attrs
in
6870 let kss = fromstring keys_of_string spos
"in" r [] in
6871 let lss = fromstring keys_of_string spos
"out" l [] in
6875 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6876 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6879 then { v with f = pkeymap
ret keymap }
6882 { v with f = skip
"map" f }
6885 error
"unexpected subelement in keymap" s spos
6887 | Vclose
"keymap" ->
6888 { v with f = ret keymap }
6890 | Vclose
_ -> error
"unexpected close in keymap" s spos
6892 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6894 | Vdata
| Vcdata
-> v
6895 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6896 | Vopen
("item", attrs
, closed
) ->
6897 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6898 let page = fromstring int_of_string spos
"page" spage
0
6899 and rely = fromstring float_of_string spos
"rely" srely
0.0
6900 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6902 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6905 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6908 { v with f = skip
"item" f }
6911 error
"unexpected subelement in bookmarks" s spos
6913 | Vclose
"bookmarks" ->
6914 { v with f = doc
path pan
anchor c bookmarks }
6916 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6918 and skip tag
f v t spos
_ =
6920 | Vdata
| Vcdata
-> v
6922 error
("unexpected end of input in skipped " ^ tag
) s spos
6923 | Vopen
(tag'
, _, closed
) ->
6927 let f'
() = { v with f = skip tag
f } in
6928 { v with f = skip tag'
f'
}
6932 else error
("unexpected close in skipped " ^ tag
) s spos
6935 parse
{ f = toplevel; accu = () } s;
6941 let len = in_channel_length ic
in
6942 let s = String.create
len in
6943 really_input ic
s 0 len;
6946 | Parse_error
(msg
, s, pos
) ->
6947 let subs = subs s pos
in
6948 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6949 failwith
("parse error: " ^
s)
6952 failwith
("config load error: " ^ exntos exn
)
6958 let dir = Filename.concat
home ".config" in
6959 if Sys.is_directory
dir then dir else home
6962 Filename.concat
dir "llpp.conf"
6965 let confpath = ref defconfpath;;
6968 if Sys.file_exists
!confpath
6971 (try Some
(open_in_bin
!confpath)
6974 ("Error opening configuration file `" ^
!confpath ^
"': " ^
6985 ("Error loading configuration from `" ^
!confpath ^
"': " ^
6994 f (Hashtbl.create
0, defconf)
6999 let pc, pb
, px, pa
=
7002 if String.length
state.origin
= 0
7006 Hashtbl.find h (Filename.basename
key)
7007 with Not_found
-> dc, [], 0, emptyanchor
7011 state.bookmarks <- pb
;
7014 then state.anchor <- pa
;
7015 cbput state.hists
.nav pa
;
7021 let add_attrs bb always
dc c =
7024 then Printf.bprintf bb
"\n %s='%b'" s a
7027 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7030 then Printf.bprintf bb
"\n %s='%d'" s a
7033 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7036 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7039 then Printf.bprintf bb
"\n %s='%f'" s a
7043 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7047 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7051 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7055 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7061 | Some
(_N
, _A
, _B
) ->
7062 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7072 else string_of_float
f
7074 Printf.bprintf bb
"\n %s='%s'" s v
7079 | Cmulti
((n, a, b), _) when n > 1 ->
7080 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7081 | Csplit
(n, _) when n > 1 ->
7082 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7088 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7093 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7097 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7101 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7103 oi
"width" c.cwinw
dc.cwinw
;
7104 oi
"height" c.cwinh
dc.cwinh
;
7105 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7106 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7107 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7108 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7109 ob "case-insensitive-search" c.icase
dc.icase
;
7110 ob "preload" c.preload dc.preload;
7111 oi
"page-bias" c.pagebias
dc.pagebias
;
7112 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7113 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7114 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7115 ob "crop-hack" c.crophack
dc.crophack
;
7116 oW
"throttle" c.maxwait
dc.maxwait
;
7117 ob "highlight-links" c.hlinks
dc.hlinks
;
7118 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7119 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7120 oz
"zoom" c.zoom dc.zoom;
7121 ob "presentation" c.presentation
dc.presentation
;
7122 oi
"rotation-angle" c.angle
dc.angle
;
7123 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7124 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7125 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7126 oi
"tex-count" c.texcount
dc.texcount
;
7127 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7128 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7129 ob "persistent-location" c.jumpback
dc.jumpback
;
7130 oc
"background-color" c.bgcolor
dc.bgcolor
;
7131 oi
"tile-width" c.tilew
dc.tilew
;
7132 oi
"tile-height" c.tileh
dc.tileh
;
7133 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7134 ob "checkers" c.checkers
dc.checkers
;
7135 oi
"aalevel" c.aalevel
dc.aalevel
;
7136 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7137 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7138 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7139 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7140 oC
"color-space" c.colorspace
dc.colorspace
;
7141 ob "invert-colors" c.invert
dc.invert
;
7142 oF
"brightness" c.colorscale
dc.colorscale
;
7143 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7144 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7145 oco
"columns" c.columns
dc.columns
;
7146 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7147 os
"selection-command" c.selcmd
dc.selcmd
;
7148 os
"synctex-command" c.stcmd
dc.stcmd
;
7149 os
"pax-command" c.paxcmd
dc.paxcmd
;
7150 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7151 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7152 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7153 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7154 ob "use-pbo" c.usepbo
dc.usepbo
;
7155 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7156 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7157 op
"point-and-x" c.pax
dc.pax
;
7158 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7161 let keymapsbuf always
dc c =
7162 let bb = Buffer.create
16 in
7163 let rec loop = function
7165 | (modename, h) :: rest
->
7166 let dh = findkeyhash dc modename in
7167 if always
|| h <> dh
7169 if Hashtbl.length
h > 0
7171 if Buffer.length
bb > 0
7172 then Buffer.add_char
bb '
\n'
;
7173 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7174 Hashtbl.iter
(fun i
o ->
7175 let isdifferent = always
||
7177 let dO = Hashtbl.find dh i
in
7179 with Not_found
-> true
7184 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7185 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7186 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7187 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7188 Buffer.add_string
bb (Wsi.keyname
k);
7191 let rec loop = function
7193 | km
:: [] -> addkm km
7194 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7198 Buffer.add_string
bb "<map in='";
7202 Buffer.add_string
bb "' out='";
7204 Buffer.add_string
bb "'/>\n"
7207 Buffer.add_string
bb "' out='";
7209 Buffer.add_string
bb "'/>\n"
7211 | KMmulti
(ins, kms
) ->
7212 Buffer.add_char
bb ' '
;
7214 Buffer.add_string
bb "' out='";
7216 Buffer.add_string
bb "'/>\n"
7218 Buffer.add_string
bb "</keymap>";
7228 let uifontsize = fstate.fontsize
in
7229 let bb = Buffer.create
32768 in
7230 let relx = float state.x /. float state.winw in
7232 let cx w = truncate
(relx *. float w) in
7234 (fun (w, h, x) ws
->
7236 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7237 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7238 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7240 (state.winw, state.winh
, state.x) state.winstate
7245 let dc = if conf.bedefault
then conf else dc in
7246 Buffer.add_string
bb "<llppconfig>\n";
7248 if String.length
!fontpath > 0
7250 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7256 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7259 Buffer.add_string
bb "<defaults ";
7260 add_attrs bb true dc dc;
7261 let kb = keymapsbuf true dc dc in
7262 if Buffer.length
kb > 0
7264 Buffer.add_string
bb ">\n";
7265 Buffer.add_buffer
bb kb;
7266 Buffer.add_string
bb "\n</defaults>\n";
7268 else Buffer.add_string
bb "/>\n";
7270 let adddoc path pan
anchor c bookmarks =
7271 if bookmarks == [] && c = dc && anchor = emptyanchor
7274 Printf.bprintf
bb "<doc path='%s'"
7275 (enent
path 0 (String.length
path));
7277 if anchor <> emptyanchor
7279 let n, rely, visy
= anchor in
7280 Printf.bprintf
bb " page='%d'" n;
7283 Printf.bprintf
bb " rely='%f'" rely
7285 if abs_float visy
> 1e-6
7287 Printf.bprintf
bb " visy='%f'" visy
7292 then Printf.bprintf
bb " pan='%d'" pan
;
7294 add_attrs bb false dc c;
7295 let kb = keymapsbuf false dc c in
7297 begin match bookmarks with
7299 if Buffer.length
kb > 0
7301 Buffer.add_string
bb ">\n";
7302 Buffer.add_buffer
bb kb;
7303 Buffer.add_string
bb "\n</doc>\n";
7305 else Buffer.add_string
bb "/>\n"
7307 Buffer.add_string
bb ">\n<bookmarks>\n";
7308 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7310 "<item title='%s' page='%d'"
7311 (enent
title 0 (String.length
title))
7316 Printf.bprintf
bb " rely='%f'" rely
7318 if abs_float visy
> 1e-6
7320 Printf.bprintf
bb " visy='%f'" visy
7322 Buffer.add_string
bb "/>\n";
7324 Buffer.add_string
bb "</bookmarks>";
7325 if Buffer.length
kb > 0
7327 Buffer.add_string
bb "\n";
7328 Buffer.add_buffer
bb kb;
7330 Buffer.add_string
bb "\n</doc>\n";
7336 match state.mode with
7337 | Birdseye
(c, pan, _, _, _) ->
7339 match conf.columns
with
7340 | Cmulti
((c, _, _), _) -> Some
c
7344 match c.columns
with
7345 | Cmulti
(c, _) -> Cmulti
(c, [||])
7346 | Csingle
_ -> Csingle
[||]
7347 | Csplit
_ -> failwith
"quit from bird's eye while split"
7349 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7352 let basename = Filename.basename
7353 (if String.length
state.origin
= 0 then state.path else state.origin
)
7355 adddoc basename pan (getanchor ())
7357 let autoscrollstep =
7358 match state.autoscroll
with
7360 | None
-> conf.autoscrollstep
7362 match state.mode with
7363 | Birdseye
(bc
, _, _, _, _) ->
7366 presentation
= bc
.presentation
;
7367 interpagespace
= bc
.interpagespace
;
7368 maxwait
= bc
.maxwait
;
7369 autoscrollstep = autoscrollstep }
7370 | _ -> { conf with autoscrollstep = autoscrollstep }
7372 (if conf.savebmarks
then state.bookmarks else []);
7374 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7376 then adddoc path x anchor c bookmarks
7378 Buffer.add_string
bb "</llppconfig>\n";
7381 if load1 f && Buffer.length
bb > 0
7384 let tmp = !confpath ^
".tmp" in
7385 let oc = open_out_bin
tmp in
7386 Buffer.output_buffer
oc bb;
7388 Unix.rename
tmp !confpath;
7391 ("error while saving configuration: " ^ exntos exn
)
7395 let adderrmsg src msg
=
7396 Buffer.add_string
state.errmsgs msg
;
7397 state.newerrmsgs
<- true;
7401 let adderrfmt src fmt
=
7402 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7406 let cl = splitatspace cmds
in
7408 try Scanf.sscanf
s fmt
f
7410 adderrfmt "remote exec"
7411 "error processing '%S': %s\n" cmds
(exntos exn
)
7414 | "reload" :: [] -> reload ()
7415 | "goto" :: args :: [] ->
7416 scan args "%u %f %f"
7418 let cmd, _ = state.geomcmds
in
7419 if String.length
cmd = 0
7420 then gotopagexy pageno x y
7423 gotopagexy pageno x y;
7426 state.reprf
<- f state.reprf
7428 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7429 | "rect" :: args :: [] ->
7430 scan args "%u %u %f %f %f %f"
7431 (fun pageno color x0 y0 x1 y1 ->
7432 onpagerect pageno (fun w h ->
7433 let _,w1,h1
,_ = getpagedim pageno in
7434 let sw = float w1 /. w
7435 and sh = float h1
/. h in
7439 and y1s
= y1 *. sh in
7440 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7442 state.rects <- (pageno, color, rect) :: state.rects;
7443 G.postRedisplay "rect";
7446 | "activatewin" :: [] -> Wsi.activatewin
()
7447 | "quit" :: [] -> raise Quit
7449 adderrfmt "remote command"
7450 "error processing remote command: %S\n" cmds
;
7454 let scratch = String.create
80 in
7455 let buf = Buffer.create
80 in
7458 try Some
(Unix.read fd
scratch 0 80)
7460 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7461 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7464 match tempfr () with
7470 if Buffer.length
buf > 0
7472 let s = Buffer.contents
buf in
7482 let pos = String.index_from
scratch ppos '
\n'
in
7483 if pos >= n then -1 else pos
7484 with Not_found
-> -1
7488 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7489 let s = Buffer.contents
buf in
7495 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7501 let remoteopen path =
7502 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7504 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7509 let trimcachepath = ref "" in
7510 let rcmdpath = ref "" in
7511 selfexec := Sys.executable_name
;
7514 [("-p", Arg.String
(fun s -> state.password
<- s),
7515 "<password> Set password");
7519 Config.fontpath := s;
7520 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7522 "<path> Set path to the user interface font");
7526 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7527 Config.confpath := s),
7528 "<path> Set path to the configuration file");
7530 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7531 "<path> Set path to the trim cache file");
7533 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7534 "<named-destination> Set named destination");
7536 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7537 ("-cxack", Arg.Set
cxack, " Cut corners");
7539 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7540 "<path> Set path to the remote commands source");
7542 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7543 "<original-path> Set original path");
7545 ("-v", Arg.Unit
(fun () ->
7547 "%s\nconfiguration path: %s\n"
7551 exit
0), " Print version and exit");
7554 (fun s -> state.path <- s)
7555 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7558 then selfexec := !selfexec ^
" -wtmode";
7560 if String.length
state.path = 0
7561 then (prerr_endline
"file name missing"; exit
1);
7563 if not
(Config.load ())
7564 then prerr_endline
"failed to load configuration";
7566 let wsfd, winw, winh
= Wsi.init
(object
7567 val mutable m_hack
= false
7568 method expose
= if not m_hack
then G.postRedisplay "expose"
7569 method visible
= G.postRedisplay "visible"
7570 method display = m_hack
<- false; display ()
7571 method reshape w h =
7572 m_hack
<- w < state.winw && h < state.winh
;
7574 method mouse b d x y m = mouse b d x y m
7575 method motion x y = state.mpos
<- (x, y); motion x y
7576 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7578 let mascm = m land (
7579 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7581 match state.keystate
with
7583 let km = k, mascm in
7586 let modehash = state.uioh#
modehash in
7587 try Hashtbl.find modehash km
7589 try Hashtbl.find (findkeyhash conf "global") km
7590 with Not_found
-> KMinsrt
(k, m)
7592 | KMinsrt
(k, m) -> keyboard k m
7593 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7594 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7596 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7597 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7598 state.keystate
<- KSnone
7599 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7600 state.keystate
<- KSinto
(keys
, insrt
)
7602 state.keystate
<- KSnone
7604 method enter
x y = state.mpos
<- (x, y); pmotion x y
7605 method leave = state.mpos
<- (-1, -1)
7606 method winstate wsl
= state.winstate
<- wsl
7607 method quit
= raise Quit
7608 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7613 List.exists
GlMisc.check_extension
7614 [ "GL_ARB_texture_rectangle"
7615 ; "GL_EXT_texture_recangle"
7616 ; "GL_NV_texture_rectangle" ]
7618 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7621 let r = GlMisc.get_string `renderer
in
7622 let p = "Mesa DRI Intel(" in
7623 let l = String.length
p in
7624 String.length
r > l && String.sub
r 0 l = p
7626 then defconf.sliceheight
<- 1024;
7629 match Ne.pipe () with
7631 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7635 match Ne.pipe () with
7637 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7647 setcheckers conf.checkers
;
7649 if conf.redirectstderr
7652 let s = Buffer.contents
state.errmsgs ^
7653 (match state.errfd
with
7655 let s = String.create
(80*24) in
7658 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
7660 then Unix.read fd
s 0 (String.length
s)
7666 else String.sub
s 0 n
7670 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
7671 with exn
-> print_endline
(exntos exn
)
7676 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7677 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7678 !Config.fontpath, !trimcachepath,
7679 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7683 state.text <- "Opening " ^
(mbtoutf8
state.path);
7685 opendoc state.path state.password
;
7689 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7692 if String.length
!rcmdpath > 0
7693 then remoteopen !rcmdpath
7698 let rec loop deadline
=
7700 match state.errfd
with
7701 | None
-> [state.sr
; state.wsfd]
7702 | Some fd
-> [state.sr
; state.wsfd; fd
]
7707 | Some fd
-> fd
:: r
7711 state.redisplay
<- false;
7718 if deadline
= infinity
7720 else max
0.0 (deadline
-. now)
7725 try Unix.select
r [] [] timeout
7726 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7732 if state.ghyll
== noghyll
7734 match state.autoscroll
with
7735 | Some step
when step
!= 0 ->
7736 let y = state.y + step
in
7740 else if y >= state.maxy then 0 else y
7743 if state.mode = View
7744 then state.text <- "";
7747 else deadline
+. 0.01
7752 let rec checkfds = function
7754 | fd
:: rest
when fd
= state.sr
->
7755 let cmd = readcmd state.sr
in
7759 | fd
:: rest
when fd
= state.wsfd ->
7763 | fd
:: rest
when Some fd
= !optrfd ->
7764 begin match remote fd
with
7765 | None
-> optrfd := remoteopen !rcmdpath;
7766 | opt -> optrfd := opt
7771 let s = String.create
80 in
7772 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7773 if conf.redirectstderr
7775 Buffer.add_substring
state.errmsgs
s 0 n;
7776 state.newerrmsgs
<- true;
7777 state.redisplay
<- true;
7780 prerr_string
(String.sub
s 0 n);
7788 if deadline
= infinity
7792 match state.autoscroll
with
7793 | Some step
when step
!= 0 -> deadline1
7794 | _ -> if state.ghyll
== noghyll then infinity
else deadline1