8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
13 | Uremote
of (string * int)
14 | Uremotedest
of (string * string)
15 and facename
= string;;
24 type params
= (angle
* fitmodel
* trimparams
25 * texcount
* sliceheight
* memsize
26 * colorspace
* fontpath
* trimcachepath
36 and trimmargins
= bool
37 and interpagespace
= int
44 and trimcachepath
= string
47 and irect
= (int * int * int * int)
48 and trimparams
= (trimmargins
* irect
)
49 and colorspace
= | Rgb
| Bgr
| Gray
50 and fitmodel
= | FitWidth
| FitProportional
| FitPage
58 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
67 | LDfirstvisible
of (int * int * int)
82 | KMmulti
of key list
* key list
84 and keyhash
= (key
, keymap
) Hashtbl.t
87 | KSinto
of (key list
* key list
)
90 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
91 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
93 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
95 external init
: pipe
-> params
-> unit = "ml_init";;
96 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
97 external copysel
: Unix.file_descr
-> opaque
-> bool -> unit = "ml_copysel";;
98 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
99 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
100 external markunder
: string -> int -> int -> mark
-> bool = "ml_markunder";;
101 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
102 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
103 external measurestr
: int -> string -> float = "ml_measure_string";;
104 external postprocess
:
105 opaque
-> int -> int -> int -> (int * string * int) -> int
107 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
108 external platform
: unit -> platform
= "ml_platform";;
109 external setaalevel
: int -> unit = "ml_setaalevel";;
110 external realloctexts
: int -> bool = "ml_realloctexts";;
111 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
112 external getlink
: opaque
-> int -> under
= "ml_getlink";;
113 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
114 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
115 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
116 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
117 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
118 external freepbo
: string -> unit = "ml_freepbo";;
119 external unmappbo
: string -> unit = "ml_unmappbo";;
120 external pbousable
: unit -> bool = "ml_pbo_usable";;
121 external unproject
: opaque
-> int -> int -> (int * int) option
123 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
124 external rectofblock
: opaque
-> int -> int -> float array
option
127 let platform_to_string = function
128 | Punknown
-> "unknown"
132 | Pfreebsd
-> "FreeBSD"
133 | Pdragonflybsd
-> "DragonflyBSD"
134 | Popenbsd
-> "OpenBSD"
135 | Pnetbsd
-> "NetBSD"
136 | Pcygwin
-> "Cygwin"
139 let platform = platform ();;
141 let now = Unix.gettimeofday
;;
143 let selfexec = ref "";;
146 if platform = Pcygwin
148 let sh = "/bin/sh" in
149 let args = [|sh; "-c"; cmd
|] in
150 let rec std si so se
= function
152 | (fd
, 0) :: rest
-> std fd so se rest
153 | (fd
, -1) :: rest
->
154 Unix.set_close_on_exec fd
;
157 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
159 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
160 ignore
(Unix.create_process
sh args si so se
)
165 type mpos
= int * int
167 | Msel
of (mpos
* mpos
)
169 | Mscrolly
| Mscrollx
170 | Mzoom
of (int * int)
171 | Mzoomrect
of (mpos
* mpos
)
175 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
176 and onkey
= string -> int -> te
177 and ondone
= string -> unit
178 and histcancel
= unit -> unit
179 and onhist
= ((histcmd
-> string) * histcancel
)
180 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
181 and cancelonempty
= bool
186 | TEswitch
of textentry
197 let bound v minv maxv
=
198 max minv
(min maxv v
);
202 { store
= Array.create n v
209 let cbcap b
= Array.length b
.store
;;
214 b
.wc
<- (b
.wc
+ 1) mod cap;
216 b
.len
<- min
(b
.len
+ 1) cap;
219 let cbempty b
= b
.len
= 0;;
221 let cbgetg b circular dir
=
225 let rc = b
.rc + dir
in
237 else bound rc 0 (b
.len
-1)
243 let cbget b
= cbgetg b
false;;
244 let cbgetc b
= cbgetg b
true;;
246 let drawstring size x y s
=
248 Gl.enable `texture_2d
;
249 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
250 ignore
(drawstr size x y s
);
252 Gl.disable `texture_2d
;
255 let drawstring1 size x y s
=
259 let drawstring2 size x y fmt
=
260 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
279 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
280 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
281 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
282 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
283 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
284 dolog
" column %d" l
.pagecol
;
288 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
290 dolog
" x0,y0=(% f, % f)" x0 y0
;
291 dolog
" x1,y1=(% f, % f)" x1 y1
;
292 dolog
" x2,y2=(% f, % f)" x2 y2
;
293 dolog
" x3,y3=(% f, % f)" x3 y3
;
297 type multicolumns
= multicol
* pagegeom
298 and singlecolumn
= pagegeom
299 and splitcolumns
= columncount
* pagegeom
300 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
301 and multicol
= columncount
* covercount
* covercount
303 and columncount
= int
304 and covercount
= int;;
311 { mutable scrollbw
: int
312 ; mutable scrollh
: int
313 ; mutable scrollb
: scrollb
314 ; mutable icase
: bool
315 ; mutable preload
: bool
316 ; mutable pagebias
: int
317 ; mutable verbose
: bool
318 ; mutable debug
: bool
319 ; mutable scrollstep
: int
320 ; mutable hscrollstep
: int
321 ; mutable maxhfit
: bool
322 ; mutable crophack
: bool
323 ; mutable autoscrollstep
: int
324 ; mutable maxwait
: float option
325 ; mutable hlinks
: bool
326 ; mutable underinfo
: bool
327 ; mutable interpagespace
: interpagespace
328 ; mutable zoom
: float
329 ; mutable presentation
: bool
330 ; mutable angle
: angle
331 ; mutable cwinw
: int
332 ; mutable cwinh
: int
333 ; mutable savebmarks
: bool
334 ; mutable fitmodel
: fitmodel
335 ; mutable trimmargins
: trimmargins
336 ; mutable trimfuzz
: irect
337 ; mutable memlimit
: memsize
338 ; mutable texcount
: texcount
339 ; mutable sliceheight
: sliceheight
340 ; mutable thumbw
: width
341 ; mutable jumpback
: bool
342 ; mutable bgcolor
: (float * float * float)
343 ; mutable bedefault
: bool
344 ; mutable tilew
: int
345 ; mutable tileh
: int
346 ; mutable mustoresize
: memsize
347 ; mutable checkers
: bool
348 ; mutable aalevel
: int
349 ; mutable urilauncher
: string
350 ; mutable pathlauncher
: string
351 ; mutable colorspace
: colorspace
352 ; mutable invert
: bool
353 ; mutable colorscale
: float
354 ; mutable redirectstderr
: bool
355 ; mutable ghyllscroll
: (int * int * int) option
356 ; mutable columns
: columns
357 ; mutable beyecolumns
: columncount
option
358 ; mutable selcmd
: string
359 ; mutable paxcmd
: string
360 ; mutable updatecurs
: bool
361 ; mutable keyhashes
: (string * keyhash
) list
362 ; mutable hfsize
: int
363 ; mutable pgscale
: float
364 ; mutable usepbo
: bool
365 ; mutable wheelbypage
: bool
366 ; mutable stcmd
: string
367 ; mutable riani
: bool
368 ; mutable pax
: (float * int * int) ref option
369 ; mutable paxmark
: mark
372 | Csingle
of singlecolumn
373 | Cmulti
of multicolumns
374 | Csplit
of splitcolumns
377 type anchor
= pageno
* top
* dtop
;;
379 type outline
= string * int * anchor
;;
381 type rect
= float * float * float * float * float * float * float * float;;
383 type tile
= opaque
* pixmapsize
* elapsed
384 and elapsed
= float;;
385 type pagemapkey
= pageno
* gen
;;
386 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
390 let emptyanchor = (0, 0.0, 0.0);;
392 type infochange
= | Memused
| Docinfo
| Pdim
;;
394 class type uioh
= object
395 method display
: unit
396 method key
: int -> int -> uioh
397 method button
: int -> bool -> int -> int -> int -> uioh
398 method motion
: int -> int -> uioh
399 method pmotion
: int -> int -> uioh
400 method infochanged
: infochange
-> unit
401 method scrollpw
: (int * float * float)
402 method scrollph
: (int * float * float)
403 method modehash
: keyhash
404 method eformsgs
: bool
408 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
409 | Textentry
of (textentry
* onleave
)
411 | LinkNav
of linktarget
412 and onleave
= leavetextentrystatus
-> unit
413 and leavetextentrystatus
= | Cancel
| Confirm
414 and helpitem
= string * int * action
417 | Action
of (uioh
-> uioh
)
419 | Ltexact
of (pageno
* int)
423 let isbirdseye = function Birdseye _
-> true | _
-> false;;
424 let istextentry = function Textentry _
-> true | _
-> false;;
428 | Loading
of (page
* gen
)
430 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
432 | Outlining
of outline list
435 let emptykeyhash = Hashtbl.create
0;;
436 let nouioh : uioh
= object (self
)
438 method key _ _
= self
439 method button _ _ _ _ _
= self
440 method motion _ _
= self
441 method pmotion _ _
= self
442 method infochanged _
= ()
443 method scrollpw
= (0, nan
, nan
)
444 method scrollph
= (0, nan
, nan
)
445 method modehash
= emptykeyhash
446 method eformsgs
= false
450 { mutable sr
: Unix.file_descr
451 ; mutable sw
: Unix.file_descr
452 ; mutable wsfd
: Unix.file_descr
453 ; mutable errfd
: Unix.file_descr
option
454 ; mutable stderr
: Unix.file_descr
455 ; mutable errmsgs
: Buffer.t
456 ; mutable newerrmsgs
: bool
460 ; mutable anchor
: anchor
461 ; mutable ranchors
: (string * string * anchor
* string) list
463 ; mutable layout
: page list
464 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
465 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
466 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
467 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
468 ; mutable pagecount
: int
469 ; mutable currently
: currently
470 ; mutable mstate
: mstate
471 ; mutable searchpattern
: string
472 ; mutable rects
: (pageno
* recttype
* rect
) list
473 ; mutable rects1
: (pageno
* recttype
* rect
) list
474 ; mutable text
: string
475 ; mutable winstate
: Wsi.winstate list
476 ; mutable mode
: mode
477 ; mutable uioh
: uioh
478 ; mutable outlines
: outline array
479 ; mutable bookmarks
: outline list
480 ; mutable path
: string
481 ; mutable password
: string
482 ; mutable nameddest
: string
483 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
484 ; mutable memused
: memsize
486 ; mutable throttle
: (page list
* int * float) option
487 ; mutable autoscroll
: int option
488 ; mutable ghyll
: (int option -> unit)
489 ; mutable help
: helpitem array
490 ; mutable docinfo
: (int * string) list
491 ; mutable texid
: GlTex.texture_id
option
493 ; mutable prevzoom
: (float * int)
494 ; mutable progress
: float
495 ; mutable redisplay
: bool
496 ; mutable mpos
: mpos
497 ; mutable keystate
: keystate
498 ; mutable glinks
: bool
499 ; mutable prevcolumns
: (columns
* float) option
502 ; mutable reprf
: (unit -> unit)
503 ; mutable origin
: string
504 ; mutable roam
: (unit -> unit)
505 ; mutable bzoom
: bool
508 { pat
: string circbuf
509 ; pag
: string circbuf
510 ; nav
: anchor circbuf
511 ; sel
: string circbuf
518 ; scrollb
= scrollbhv lor scrollbvv
534 ; presentation
= false
539 ; fitmodel
= FitProportional
540 ; trimmargins
= false
541 ; trimfuzz
= (0,0,0,0)
542 ; memlimit
= 32 lsl 20
547 ; bgcolor
= (0.5, 0.5, 0.5)
551 ; mustoresize
= 256 lsl 20
556 | Plinux
| Pfreebsd
| Pdragonflybsd
557 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
558 | Posx
-> "open \"%s\""
559 | Pcygwin
-> "cygstart \"%s\""
560 | Punknown
-> "echo %s")
561 ; pathlauncher
= "lp \"%s\""
564 | Plinux
| Pfreebsd
| Pdragonflybsd
565 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
573 ; redirectstderr
= false
575 ; columns
= Csingle
[||]
581 ; wheelbypage
= false
582 ; stcmd
= "echo SyncTex"
585 ; paxmark
= Mark_word
587 let mk n
= (n
, Hashtbl.create
1) in
601 let wtmode = ref false;;
602 let cxack = ref false;;
604 let findkeyhash c name
=
605 try List.assoc name c
.keyhashes
606 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
609 let conf = { defconf with angle
= defconf.angle
};;
611 let pgscale h
= truncate
(float h
*. conf.pgscale);;
614 { mutable fontsize
: int
615 ; mutable wwidth
: float
616 ; mutable maxrows
: int
628 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
629 let len = String.length s
in
630 if colonpos >= 0 && colonpos + 3 < len
632 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
635 try String.rindex_from s
colonpos ' '
639 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
642 | "http" | "ftp" | "mailto" ->
644 try String.index_from s
colonpos ' '
645 with Not_found
-> len
647 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
655 if emptystr
conf.urilauncher
656 then print_endline uri
658 let url = geturl uri
in
660 then Printf.eprintf
"obtained empty url from uri %S" uri
662 let re = Str.regexp
"%s" in
663 let command = Str.global_replace
re url conf.urilauncher
in
667 "failed to execute `%s': %s\n" command (exntos exn
);
673 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
674 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
678 let strings = version () :: "" :: Help.keys
in
681 let url = geturl s
in
683 then (s
, 0, Action
(fun u
-> gotouri url; u
))
684 else (s
, 0, Noaction
)
689 let firstgeomcmds = "", [];;
690 let noreprf () = ();;
697 ; stderr
= Unix.stderr
698 ; errmsgs
= Buffer.create
0
703 ; anchor
= emptyanchor
707 ; tilelru
= Queue.create
()
708 ; pagemap
= Hashtbl.create
10
709 ; tilemap
= Hashtbl.create
10
725 ; geomcmds
= firstgeomcmds
727 { nav
= cbnew 10 emptyanchor
740 ; prevzoom
= (1.0, 0)
752 ; roam
= (fun () -> ())
758 if (conf.scrollb
land scrollbhv = 0)
759 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
765 if (conf.scrollb
land scrollbvv = 0)
770 let wadjsb w
= w
- vscrollw ();;
773 fstate.fontsize
<- n
;
774 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
775 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
781 Printf.kprintf prerr_endline fmt
783 Printf.kprintf ignore fmt
787 if emptystr
conf.pathlauncher
788 then print_endline
state.path
790 let re = Str.regexp
"%s" in
791 let command = Str.global_replace
re state.path
conf.pathlauncher
in
794 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
800 type 'a t
= | Res
of 'a
| Exn
of exn
;;
803 try Res
(Unix.pipe ())
808 try tempfailureretry
Unix.close fd
809 with exn
-> f
(exntos exn
)
813 try Res
(tempfailureretry
Unix.dup fd
)
818 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
823 let redirectstderr () =
824 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
825 if conf.redirectstderr
827 match Ne.pipe () with
829 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
832 begin match Ne.dup Unix.stderr
with
834 dolog
"failed to dup stderr: %s" (exntos exn
);
835 Ne.clo r
(clofail "pipe/r");
836 Ne.clo w
(clofail "pipe/w");
838 | Ne.Res dupstderr
->
839 begin match Ne.dup2 w
Unix.stderr
with
841 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
842 Ne.clo dupstderr
(clofail "stderr duplicate");
843 Ne.clo r
(clofail "redir pipe/r");
844 Ne.clo w
(clofail "redir pipe/w");
847 state.stderr
<- dupstderr
;
848 state.errfd
<- Some r
;
852 state.newerrmsgs
<- false;
853 begin match state.errfd
with
855 begin match Ne.dup2 state.stderr
Unix.stderr
with
857 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
859 Ne.clo fd
(clofail "dup of stderr");
864 prerr_string
(Buffer.contents
state.errmsgs
);
866 Buffer.clear
state.errmsgs
;
872 let postRedisplay who
=
874 then prerr_endline
("redisplay for " ^ who
);
875 state.redisplay
<- true;
879 let getopaque pageno
=
880 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
881 with Not_found
-> None
884 let putopaque pageno opaque
=
885 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
888 let pagetranslatepoint l x y
=
889 let dy = y
- l
.pagedispy
in
890 let y = dy + l
.pagey
in
891 let dx = x
- l
.pagedispx
in
892 let x = dx + l
.pagex
in
896 let onppundermouse g
x y d
=
899 begin match getopaque l
.pageno
with
901 let x0 = l
.pagedispx
in
902 let x1 = x0 + l
.pagevw
in
903 let y0 = l
.pagedispy
in
904 let y1 = y0 + l
.pagevh
in
905 if y >= y0 && y <= y1 && x >= x0 && x <= x1
907 let px, py
= pagetranslatepoint l
x y in
908 match g opaque l
px py
with
921 let g opaque l
px py
=
924 match rectofblock opaque
px py
with
926 let rect = (a
.(0),a
.(2),a
.(1),a
.(2),a
.(1),a
.(3),a
.(0),a
.(3)) in
927 state.rects
<- [l
.pageno
, l
.pageno
mod 3, rect];
928 G.postRedisplay "getunder";
931 match whatsunder opaque
px py
with
933 | under
-> Some under
935 onppundermouse g x y Unone
940 match unproject opaque
x y with
941 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
944 onppundermouse g x y None
;
948 state.text
<- Printf.sprintf
"%c%s" c s
;
949 G.postRedisplay "showtext";
953 let g opaque l
px py
=
954 if markunder opaque
px py
conf.paxmark
957 match getopaque l
.pageno
with
960 match Ne.pipe () with
964 "can not create mark pipe: %s"
967 let doclose what fd
=
968 Ne.clo fd
(fun msg
->
969 dolog
"%s close failed: %s" what msg
)
972 popen conf.paxcmd
[r
, 0; w
, -1];
973 copysel w opaque
false;
975 G.postRedisplay "paxunder";
977 dolog
"can not execute %S: %s"
978 conf.paxcmd
(exntos exn
);
985 G.postRedisplay "paxunder";
987 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
991 match Ne.pipe () with
993 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
996 try popen conf.selcmd
[r
, 0; w
, -1]; true
999 (Printf.sprintf
"failed to execute %s: %s"
1000 conf.selcmd
(exntos exn
));
1004 Ne.clo fd
(fun msg
->
1005 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
1011 let l = String.length s
in
1012 let n = tempfailureretry
(Unix.write w s
0) l in
1017 "failed to write %d characters to sel pipe, wrote %d"
1022 (Printf.sprintf
"failed to write to sel pipe: %s"
1031 let undertext = function
1034 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
1035 | Utext s
-> "font: " ^ s
1036 | Uunexpected s
-> "unexpected: " ^ s
1037 | Ulaunch s
-> "launch: " ^ s
1038 | Unamed s
-> "named: " ^ s
1039 | Uremote
(filename
, pageno
) ->
1040 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
1041 | Uremotedest
(filename
, destname
) ->
1042 Printf.sprintf
"%s: destination %S" filename destname
1045 let updateunder x y =
1046 match getunder x y with
1047 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
1049 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
1050 Wsi.setcursor
Wsi.CURSOR_INFO
1051 | Ulinkgoto
(pageno
, _
) ->
1053 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
1054 Wsi.setcursor
Wsi.CURSOR_INFO
1056 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
1057 Wsi.setcursor
Wsi.CURSOR_TEXT
1059 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
1060 Wsi.setcursor
Wsi.CURSOR_INHERIT
1062 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
1063 Wsi.setcursor
Wsi.CURSOR_INHERIT
1065 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
1066 Wsi.setcursor
Wsi.CURSOR_INHERIT
1067 | Uremote
(filename
, pageno
) ->
1068 if conf.underinfo
then showtext 'r'
1069 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
1070 Wsi.setcursor
Wsi.CURSOR_INFO
1071 | Uremotedest
(filename
, destname
) ->
1072 if conf.underinfo
then showtext 'r'
1073 (Printf.sprintf
"emote destination: %s (%S)" filename destname
);
1074 Wsi.setcursor
Wsi.CURSOR_INFO
1077 let showlinktype under
=
1083 let s = undertext under
in
1088 let b = Buffer.create
(String.length
s + 1) in
1089 Buffer.add_string
b s;
1090 Buffer.add_char
b c
;
1094 module type TextEnumType
=
1098 val names
: string array
1101 module TextEnumMake
(Ten
: TextEnumType
) =
1103 let names = Ten.names;;
1104 let to_int (t
: Ten.t
) = Obj.magic t
;;
1105 let to_string t
= names.(to_int t
);;
1106 let of_int n : Ten.t
= Obj.magic
n;;
1109 if i
= Array.length
names
1110 then failwith
("invalid " ^
Ten.name ^
": " ^
s)
1112 if Ten.names.(i
) = s
1119 module CSTE
= TextEnumMake
(struct
1120 type t
= colorspace
;;
1121 let name = "colorspace";;
1122 let names = [|"rgb"; "bgr"; "gray"|];;
1125 module MTE
= TextEnumMake
(struct
1128 let names = [|"page"; "block"; "line"; "word"|];;
1131 module FMTE
= TextEnumMake
(struct
1133 let name = "fitmodel";;
1134 let names = [|"width"; "proportional"; "page"|];;
1137 let intentry_with_suffix text key
=
1139 if key
>= 32 && key
< 127
1143 match Char.lowercase
c with
1145 let text = addchar text c in
1148 | 'k'
| 'm'
| '
g'
->
1149 let text = addchar text c in
1153 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1157 let multicolumns_to_string (n, a
, b) =
1159 then Printf.sprintf
"%d" n
1160 else Printf.sprintf
"%d,%d,%d" n a
b;
1163 let multicolumns_of_string s =
1165 (int_of_string
s, 0, 0)
1167 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1169 then failwith
"subtly broken"; (n, a
, b)
1175 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1176 if n != 4 then error
"incomplete read(len) = %d" n;
1178 lor (Char.code
s.[0] lsl 24)
1179 lor (Char.code
s.[1] lsl 16)
1180 lor (Char.code
s.[2] lsl 8)
1181 lor (Char.code
s.[3] lsl 0)
1183 let s = String.create
len in
1184 let n = tempfailureretry
(Unix.read fd
s 0) len in
1185 if n != len then error
"incomplete read(data) %d vs %d" n len;
1189 let btod b = if b then 1 else 0;;
1192 let b = Buffer.create
16 in
1193 Buffer.add_string
b "llll";
1196 let s = Buffer.contents
b in
1197 let n = String.length
s in
1199 (* dolog "wcmd %S" (String.sub s 4 len); *)
1200 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1201 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1202 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1203 s.[3] <- Char.chr
(len land 0xff);
1204 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1205 if n'
!= n then error
"write failed %d vs %d" n'
n;
1210 let d = state.winh
- h
in
1211 max
conf.interpagespace
((d + 1) / 2)
1214 let rowyh (c, coverA
, coverB
) b n =
1215 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1217 let _, _, vy
, (_, _, h
, _) = b.(n) in
1220 let n'
= n - coverA
in
1223 let e = min
state.pagecount
(s + c) in
1224 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1225 let _, _, y, (_, _, h
, _) = b.(m
) in
1226 let miny = min
miny y in
1227 let maxh = max
maxh h
in
1228 find (m
+1) miny maxh
1233 match conf.columns
with
1234 | Cmulti
((_, _, _) as cl
, b) ->
1235 if Array.length
b > 0
1237 let y, h
= rowyh cl
b (Array.length
b - 1) in
1238 y + h
+ (if conf.presentation
then calcips h
else 0)
1241 if Array.length
b > 0
1243 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1244 y + h
+ (if conf.presentation
then calcips h
else 0)
1247 if Array.length
b > 0
1249 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1254 let getpageywh pageno
=
1255 let pageno = bound pageno 0 (state.pagecount
-1) in
1256 match conf.columns
with
1258 if Array.length
b = 0
1261 let (_, _, y, (_, w
, h
, _)) = b.(pageno) in
1263 if conf.presentation
1269 if Array.length
b = 0
1272 let y, h
= rowyh cl
b pageno in
1273 let (_, _, _, (_, w
, _, _)) = b.(pageno) in
1275 if conf.presentation
1281 if Array.length
b = 0
1285 let (_, _, y, (_, w
, h
, _)) = b.(n) in
1289 let getpageyh pageno =
1290 let y,_,h
= getpageywh pageno in
1294 let getpagedim pageno =
1297 | (n, _, _, _) as pdim
:: rest
->
1299 then (if n = pageno then pdim
else ppdim
)
1304 f (-1, -1, -1, -1) state.pdims
1307 let getpagey pageno = fst
(getpageyh pageno);;
1309 let nogeomcmds cmds
=
1311 | s, [] -> emptystr
s
1316 let ((c, coverA
, coverB
) as cl
), b =
1317 match conf.columns
with
1318 | Csingle
b -> (1, 0, 0), b
1319 | Cmulti
(c, b) -> c, b
1320 | Csplit
(_, b) -> (1, 0, 0), b
1322 if Array.length
b = 0
1325 let rec bsearch nmin nmax
=
1327 then bound nmin
0 (state.pagecount
-1)
1329 let n = (nmax
+ nmin
) / 2 in
1330 let vy, h
= rowyh cl
b n in
1332 if conf.presentation
1334 let ips = calcips h
in
1335 let y0 = vy - ips in
1336 let y1 = vy + h
+ ips in
1340 then 0, vy + h
+ conf.interpagespace
1342 let y0 = vy - conf.interpagespace
in
1343 y0, y0 + h
+ conf.interpagespace
1346 if y >= y0 && y < y1
1353 if n < state.pagecount
- coverB
1354 then ((n-coverA
)/c)*c + coverA
1361 then bsearch (n+1) nmax
1362 else bsearch nmin
(n-1)
1365 let r = bsearch 0 (state.pagecount
-1) in
1369 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1370 let sh = sh - (hscrollh ()) in
1371 let rec fold accu
n =
1372 if n = Array.length
b
1375 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1378 || n = state.pagecount
- coverB
1379 || (n - coverA
) mod columns
= columns
- 1)
1385 let pagey = max
0 (y - vy) in
1386 let pagedispy = if pagey > 0 then 0 else vy - y in
1387 let pagedispx, pagex
=
1389 if n = coverA
- 1 || n = state.pagecount
- coverB
1390 then state.x + (wadjsb state.winw
- w
) / 2
1391 else dx + xoff
+ state.x
1398 let vw = wadjsb state.winw
- pagedispx in
1399 let pw = w
- pagex
in
1402 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1403 if pagevw > 0 && pagevh > 0
1407 ; pagedimno
= pdimno
1414 ; pagedispx = pagedispx
1415 ; pagedispy = pagedispy
1427 if Array.length
b = 0
1429 else List.rev
(fold [] (page_of_y y))
1432 let layoutS (columns
, b) y sh =
1433 let sh = sh - hscrollh () in
1434 let rec fold accu n =
1435 if n = Array.length
b
1438 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1445 let x = xoff
+ state.x in
1446 let pagey = max
0 (y - vy) in
1447 let pagedispy = if pagey > 0 then 0 else vy - y in
1448 let pagedispx, pagex
=
1462 let pagecolw = pagew
/columns
in
1464 if pagecolw < state.winw
1465 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1469 let vw = wadjsb state.winw
- pagedispx in
1470 let pw = pagew
- pagex
in
1473 let pagevw = min
pagevw pagecolw in
1474 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1475 if pagevw > 0 && pagevh > 0
1478 { pageno = n/columns
1479 ; pagedimno
= pdimno
1486 ; pagedispx = pagedispx
1487 ; pagedispy = pagedispy
1488 ; pagecol
= n mod columns
1499 List.rev
(fold [] 0)
1503 if nogeomcmds state.geomcmds
1505 match conf.columns
with
1506 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1507 | Cmulti
c -> layoutN c y sh
1508 | Csplit
s -> layoutS s y sh
1513 let y = state.y + incr
in
1515 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1520 let tilex = l.pagex
mod conf.tilew
in
1521 let tiley = l.pagey mod conf.tileh
in
1523 let col = l.pagex
/ conf.tilew
in
1524 let row = l.pagey / conf.tileh
in
1526 let rec rowloop row y0 dispy h
=
1530 let dh = conf.tileh
- y0 in
1531 let dh = min h
dh in
1532 let rec colloop col x0 dispx w
=
1536 let dw = conf.tilew
- x0 in
1537 let dw = min w
dw in
1539 f col row dispx dispy
x0 y0 dw dh;
1540 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1543 colloop col tilex l.pagedispx l.pagevw;
1544 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1547 if l.pagevw > 0 && l.pagevh > 0
1548 then rowloop row tiley l.pagedispy l.pagevh;
1551 let gettileopaque l col row =
1553 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1555 try Some
(Hashtbl.find state.tilemap
key)
1556 with Not_found
-> None
1559 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1560 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1561 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1564 let drawtiles l color
=
1566 let f col row x y tilex tiley w h
=
1567 match gettileopaque l col row with
1568 | Some
(opaque
, _, t
) ->
1569 let params = x, y, w
, h
, tilex, tiley in
1573 GlFunc.blend_func `zero `one_minus_src_color
;
1575 drawtile
params opaque
;
1577 then Gl.disable `blend
;
1580 let s = Printf.sprintf
1584 let w = measurestr
fstate.fontsize
s in
1585 GlMisc.push_attrib
[`current
];
1586 GlDraw.color
(0.0, 0.0, 0.0);
1588 (float (x-2), float (y-2))
1589 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1590 GlDraw.color
(1.0, 1.0, 1.0);
1591 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1592 GlMisc.pop_attrib
();
1597 let lw = wadjsb state.winw
- x in
1600 let lh = state.winh
- y in
1603 begin match state.texid
with
1605 Gl.enable `texture_2d
;
1606 GlTex.bind_texture `texture_2d id
;
1609 and x1 = float (x+w)
1610 and y1 = float (y+h
) in
1612 let tw = float w /. 16.0
1613 and th
= float h
/. 16.0 in
1614 let tx0 = float tilex /. 16.0
1615 and ty0
= float tiley /. 16.0 in
1617 and ty1
= ty0
+. th
in
1618 GlDraw.begins `quads
;
1619 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1620 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1621 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1622 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1625 Gl.disable `texture_2d
;
1627 GlDraw.color
(1.0, 1.0, 1.0);
1630 (float (x+w), float (y+h
));
1632 if w > 128 && h
> fstate.fontsize
+ 10
1634 GlDraw.color
(0.0, 0.0, 0.0);
1637 then (col*conf.tilew
, row*conf.tileh
)
1640 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r;
1647 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1649 let tilevisible1 l x y =
1651 and ax1
= l.pagex
+ l.pagevw
1653 and ay1
= l.pagey + l.pagevh in
1657 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1658 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1660 let rx0 = max
ax0 bx0
1661 and ry0
= max ay0 by0
1662 and rx1
= min ax1
bx1
1663 and ry1
= min ay1 by1
in
1665 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1666 nonemptyintersection
1669 let tilevisible layout n x y =
1670 let rec findpageinlayout m
= function
1671 | l :: rest
when l.pageno = n ->
1672 tilevisible1 l x y || (
1673 match conf.columns
with
1674 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1677 | _ :: rest
-> findpageinlayout 0 rest
1680 findpageinlayout 0 layout;
1683 let tileready l x y =
1684 tilevisible1 l x y &&
1685 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1688 let tilepage n p
layout =
1689 let rec loop = function
1693 let f col row _ _ _ _ _ _ =
1694 if state.currently
= Idle
1696 match gettileopaque l col row with
1699 let x = col*conf.tilew
1700 and y = row*conf.tileh
in
1702 let w = l.pagew
- x in
1706 let h = l.pageh
- y in
1711 then getpbo
w h conf.colorspace
1714 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1717 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1718 conf.tilew
, conf.tileh
1727 if nogeomcmds state.geomcmds
1731 let preloadlayout y =
1732 let y = if y < state.winh
then 0 else y - state.winh
in
1733 let h = state.winh
*3 in
1738 let rec loop pages
=
1739 if state.currently
!= Idle
1744 begin match getopaque l.pageno with
1746 wcmd "page %d %d" l.pageno l.pagedimno
;
1747 state.currently
<- Loading
(l, state.gen
);
1749 tilepage l.pageno opaque pages
;
1754 if nogeomcmds state.geomcmds
1760 if conf.preload && state.currently
= Idle
1761 then load (preloadlayout state.y);
1764 let layoutready layout =
1765 let rec fold all ls
=
1766 all
&& match ls
with
1768 let seen = ref false in
1769 let allvisible = ref true in
1770 let foo col row _ _ _ _ _ _ =
1772 allvisible := !allvisible &&
1773 begin match gettileopaque l col row with
1779 fold (!seen && !allvisible) rest
1782 let alltilesvisible = fold true layout in
1787 let y = bound y 0 state.maxy
in
1788 let y, layout, proceed
=
1789 match conf.maxwait
with
1790 | Some time
when state.ghyll
== noghyll ->
1791 begin match state.throttle
with
1793 let layout = layout y state.winh
in
1794 let ready = layoutready layout in
1798 state.throttle
<- Some
(layout, y, now ());
1800 else G.postRedisplay "gotoy showall (None)";
1802 | Some
(_, _, started
) ->
1803 let dt = now () -. started
in
1806 state.throttle
<- None
;
1807 let layout = layout y state.winh
in
1809 G.postRedisplay "maxwait";
1816 let layout = layout y state.winh
in
1817 if not
!wtmode || layoutready layout
1818 then G.postRedisplay "gotoy ready";
1824 state.layout <- layout;
1825 begin match state.mode
with
1826 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1827 let rec loop = function
1829 state.mode
<- LinkNav
(Ltgendir
0)
1830 | l :: _ when l.pageno = pageno ->
1831 begin match getopaque pageno with
1833 state.mode
<- LinkNav
(Ltgendir
0)
1835 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1836 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1837 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1838 then state.mode
<- LinkNav
(Ltgendir
0)
1840 | _ :: rest
-> loop rest
1845 begin match state.mode
with
1846 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1847 if not
(pagevisible layout pageno)
1849 match state.layout with
1852 state.mode
<- Birdseye
(
1853 conf, leftx
, l.pageno, hooverpageno
, anchor
1856 | LinkNav
(Ltgendir dir
as lt
) ->
1858 let rec loop = function
1861 match getopaque l.pageno with
1867 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1869 if dir
> 0 then LDfirst
else LDlast
1875 | Lnotfound
-> loop rest
1877 showlinktype (getlink opaque
n);
1878 Ltexact
(l.pageno, n)
1882 state.mode
<- LinkNav
linknav
1887 state.ghyll
<- noghyll;
1890 let mx, my
= state.mpos
in
1895 let conttiling pageno opaque
=
1896 tilepage pageno opaque
1897 (if conf.preload then preloadlayout state.y else state.layout)
1900 let gotoy_and_clear_text y =
1901 if not
conf.verbose
then state.text <- "";
1907 let coloff = l.pagecol
* l.pageh
in
1908 float (l.pagey + coloff) /. float l.pageh
1915 if conf.presentation
1916 then float l.pagedispy /. float (calcips l.pageh
)
1917 else float l.pagedispy /. float conf.interpagespace
1920 (l.pageno, top, dtop)
1924 match state.layout with
1925 | l :: _ -> getanchor1 l
1927 let n = page_of_y state.y in
1931 let y, h = getpageyh n in
1932 let dy = y - state.y in
1934 if conf.presentation
1936 let ips = calcips h in
1937 float (dy + ips) /. float ips
1939 float dy /. float conf.interpagespace
1944 let getanchory (n, top, dtop) =
1945 let y, h = getpageyh n in
1946 if conf.presentation
1948 let ips = calcips h in
1949 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1951 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1954 let gotoanchor anchor
=
1955 gotoy (getanchory anchor
);
1959 cbput state.hists
.nav
(getanchor ());
1963 let anchor = cbgetc state.hists
.nav dir
in
1968 let scroll f n a
b =
1969 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1971 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1973 then s (float f /. float a
)
1976 then 1.0 -. s ((float (f-b) /. float (n-b)))
1982 let ins = float a
*. 0.5
1983 and outs
= float (n-b) *. 0.5 in
1985 ins +. outs
+. float ones
1987 let rec set (_N
, _A
, _B
) y sy
=
1988 let sum = summa _N _A _B
in
1989 let dy = float (y - sy
) in
1993 then state.ghyll
<- noghyll
1996 let s = scroll n _N _A _B
in
1997 let y1 = y1 +. ((s *. dy) /. sum) in
1998 gotoy_and_clear_text (truncate
y1);
1999 state.ghyll
<- gf (n+1) y1;
2003 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
2005 gf 0 (float state.y)
2008 match conf.ghyllscroll
with
2010 gotoy_and_clear_text y
2012 if state.ghyll
== noghyll
2013 then set nab
y state.y
2014 else state.ghyll
(Some
y)
2017 let gotopage n top =
2018 let y, h = getpageyh n in
2019 let y = y + (truncate
(top *. float h)) in
2023 let gotopage1 n top =
2024 let y = getpagey n in
2029 let invalidate s f =
2034 match state.geomcmds
with
2035 | ps
, [] when emptystr ps
->
2037 state.geomcmds
<- s, [];
2040 state.geomcmds
<- ps
, [s, f];
2042 | ps
, (s'
, _) :: rest
when s'
= s ->
2043 state.geomcmds
<- ps
, ((s, f) :: rest
);
2046 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2050 Hashtbl.iter
(fun _ opaque
->
2051 wcmd "freepage %s" opaque
;
2053 Hashtbl.clear
state.pagemap
;
2057 if not
(Queue.is_empty
state.tilelru
)
2059 Queue.iter
(fun (k
, p
, s) ->
2060 wcmd "freetile %s" p
;
2061 state.memused
<- state.memused
- s;
2062 Hashtbl.remove
state.tilemap k
;
2064 state.uioh#infochanged Memused
;
2065 Queue.clear
state.tilelru
;
2071 let h = truncate
(float h*.conf.zoom
) in
2072 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2076 let opendoc path password
=
2078 state.password
<- password
;
2079 state.gen
<- state.gen
+ 1;
2080 state.docinfo
<- [];
2083 setaalevel
conf.aalevel
;
2085 if emptystr
state.origin
2089 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2090 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2091 invalidate "reqlayout"
2093 wcmd "reqlayout %d %d %d %s\000"
2094 conf.angle
(FMTE.to_int conf.fitmodel
)
2095 (stateh state.winh
) state.nameddest
2100 state.anchor <- getanchor ();
2101 opendoc state.path
state.password
;
2105 let c = c *. conf.colorscale
in
2109 let scalecolor2 (r, g, b) =
2110 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2113 let docolumns = function
2115 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2116 let rec loop pageno pdimno pdim
y ph pdims
=
2117 if pageno = state.pagecount
2120 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2122 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2123 pdimno+1, pdim
, rest
2127 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2129 (if conf.presentation
2130 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2131 else (if pageno = 0 then 0 else conf.interpagespace
)
2134 a.(pageno) <- (pdimno, x, y, pdim
);
2135 loop (pageno+1) pdimno pdim
(y + h) h pdims
2137 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2138 conf.columns
<- Csingle
a;
2140 | Cmulti
((columns
, coverA
, coverB
), _) ->
2141 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2142 let rec loop pageno pdimno pdim
x y rowh pdims
=
2143 let rec fixrow m
= if m
= pageno then () else
2144 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2147 let y = y + (rowh
- h) / 2 in
2148 a.(m
) <- (pdimno, x, y, pdim
);
2152 if pageno = state.pagecount
2153 then fixrow (((pageno - 1) / columns
) * columns
)
2155 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2157 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2158 pdimno+1, pdim
, rest
2163 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2165 let x = (wadjsb state.winw
- w) / 2 in
2167 if conf.presentation
then calcips h else conf.interpagespace
in
2168 x, y + ips + rowh
, h
2171 if (pageno - coverA
) mod columns
= 0
2173 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2175 if conf.presentation
2177 let ips = calcips h in
2178 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2180 y + (if pageno = 0 then 0 else conf.interpagespace
)
2184 else x, y, max rowh
h
2188 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2191 if pageno = columns
&& conf.presentation
2193 let ips = calcips rowh
in
2194 for i
= 0 to pred columns
2196 let (pdimno, x, y, pdim
) = a.(i
) in
2197 a.(i
) <- (pdimno, x, y+ips, pdim
)
2203 fixrow (pageno - columns
);
2208 a.(pageno) <- (pdimno, x, y, pdim
);
2209 let x = x + w + xoff
*2 + conf.interpagespace
in
2210 loop (pageno+1) pdimno pdim
x y rowh' pdims
2212 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2213 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2216 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2217 let rec loop pageno pdimno pdim
y pdims
=
2218 if pageno = state.pagecount
2221 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2223 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2224 pdimno+1, pdim
, rest
2229 let rec loop1 n x y =
2230 if n = c then y else (
2231 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2232 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2235 let y = loop1 0 0 y in
2236 loop (pageno+1) pdimno pdim
y pdims
2238 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2239 conf.columns
<- Csplit
(c, a);
2243 docolumns conf.columns
;
2244 state.maxy
<- calcheight ();
2245 if state.reprf
== noreprf
2247 match state.mode
with
2248 | Birdseye
(_, _, pageno, _, _) ->
2249 let y, h = getpageyh pageno in
2250 let top = (state.winh
- h) / 2 in
2251 gotoy (max
0 (y - top))
2252 | _ -> gotoanchor state.anchor
2256 state.reprf
<- noreprf;
2261 GlDraw.viewport
0 0 w h;
2262 let firsttime = state.geomcmds
== firstgeomcmds in
2263 if not
firsttime && nogeomcmds state.geomcmds
2264 then state.anchor <- getanchor ();
2267 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2270 setfontsize fstate.fontsize
;
2271 GlMat.mode `modelview
;
2272 GlMat.load_identity
();
2274 GlMat.mode `projection
;
2275 GlMat.load_identity
();
2276 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2277 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2278 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2283 else float state.x /. float state.w
2285 invalidate "geometry"
2289 then state.x <- truncate
(relx *. float w);
2291 match conf.columns
with
2293 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2294 | Csplit
(c, _) -> w * c
2296 wcmd "geometry %d %d %d"
2297 w (stateh h) (FMTE.to_int conf.fitmodel
)
2302 let len = String.length
state.text in
2305 match state.mode
with
2306 | Textentry
_ | View
| LinkNav
_ ->
2307 let h, _, _ = state.uioh#scrollpw
in
2313 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2314 (x+.w, float (state.winh
- hscrollh))
2317 let w = float (wadjsb state.winw
- 1) in
2318 if state.progress
>= 0.0 && state.progress
< 1.0
2320 GlDraw.color
(0.3, 0.3, 0.3);
2321 let w1 = w *. state.progress
in
2323 GlDraw.color
(0.0, 0.0, 0.0);
2327 GlDraw.color
(0.0, 0.0, 0.0);
2331 GlDraw.color
(1.0, 1.0, 1.0);
2332 drawstring fstate.fontsize
2333 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2336 match state.mode
with
2337 | Textentry
((prefix
, text, _, _, _, _), _) ->
2341 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2343 Printf.sprintf
"%s%s_" prefix
text
2352 if not
(istextentry state.mode
) && state.uioh#eformsgs
2354 let s1 = "(press 'e' to review error messasges)" in
2355 if nonemptystr
s then s ^
" " ^
s1 else s1
2365 let len = Queue.length
state.tilelru
in
2367 match state.throttle
with
2370 then preloadlayout state.y
2372 | Some
(layout, _, _) ->
2376 if state.memused
<= conf.memlimit
2381 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2382 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2383 let (_, pw, ph
, _) = getpagedim n in
2386 && colorspace
= conf.colorspace
2387 && angle
= conf.angle
2391 let x = col*conf.tilew
2392 and y = row*conf.tileh
in
2393 tilevisible (Lazy.force_val
layout) n x y
2395 then Queue.push lruitem
state.tilelru
2398 wcmd "freetile %s" p
;
2399 state.memused
<- state.memused
- s;
2400 state.uioh#infochanged Memused
;
2401 Hashtbl.remove
state.tilemap k
;
2409 let logcurrently = function
2410 | Idle
-> dolog
"Idle"
2411 | Loading
(l, gen
) ->
2412 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2413 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2415 "Tiling %d[%d,%d] page=%s cs=%s angle"
2416 l.pageno col row pageopaque
2417 (CSTE.to_string colorspace
)
2419 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2420 angle gen
conf.angle
state.gen
2422 conf.tilew
conf.tileh
2429 let r = Str.regexp
" " in
2430 fun s -> Str.bounded_split
r s 2;
2433 let onpagerect pageno f =
2435 match conf.columns
with
2436 | Cmulti
(_, b) -> b
2438 | Csplit
(_, b) -> b
2440 if pageno >= 0 && pageno < Array.length
b
2442 let (_, _, _, (w, h, _, _)) = b.(pageno) in
2446 let gotopagexy1 pageno x y =
2447 let _,w1,h1
,leftx
= getpagedim pageno in
2448 let top = y /. (float h1
) in
2449 let left = x /. (float w1) in
2450 let py, w, h = getpageywh pageno in
2451 let wh = state.winh
- hscrollh () in
2452 let x = left *. (float w) in
2453 let x = leftx
+ state.x + truncate
x in
2455 if x < 0 || x >= wadjsb state.winw
2459 let pdy = truncate
(top *. float h) in
2460 let y'
= py + pdy in
2461 let dy = y'
- state.y in
2463 if x != state.x || not
(dy > 0 && dy < wh)
2465 if conf.presentation
2467 if abs
(py - y'
) > wh
2474 if state.x != sx || state.y != sy
2479 let ww = wadjsb state.winw
in
2481 and qy
= pdy / wh in
2483 and y = py + qy
* wh in
2484 let x = if -x + ww > w1 then -(w1-ww) else x
2485 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2487 if conf.presentation
2489 if abs
(py - y'
) > wh
2499 gotoy_and_clear_text y;
2501 else gotoy_and_clear_text state.y;
2504 let gotopagexy pageno x y =
2505 match state.mode
with
2506 | Birdseye
_ -> gotopage pageno 0.0
2507 | _ -> gotopagexy1 pageno x y
2511 (* dolog "%S" cmds; *)
2512 let cl = splitatspace cmds
in
2514 try Scanf.sscanf
s fmt
f
2516 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2521 state.uioh#infochanged Pdim
;
2524 | "clearrects" :: [] ->
2525 state.rects
<- state.rects1
;
2526 G.postRedisplay "clearrects";
2528 | "continue" :: args :: [] ->
2529 let n = scan args "%u" (fun n -> n) in
2530 state.pagecount
<- n;
2531 begin match state.currently
with
2533 state.currently
<- Idle
;
2534 state.outlines
<- Array.of_list
(List.rev
l)
2538 let cur, cmds
= state.geomcmds
in
2540 then failwith
"umpossible";
2542 begin match List.rev cmds
with
2544 state.geomcmds
<- "", [];
2548 state.geomcmds
<- s, List.rev rest
;
2550 if conf.maxwait
= None
&& not
!wtmode
2551 then G.postRedisplay "continue";
2553 | "title" :: args :: [] ->
2556 | "msg" :: args :: [] ->
2559 | "vmsg" :: args :: [] ->
2561 then showtext ' '
args
2563 | "emsg" :: args :: [] ->
2564 Buffer.add_string
state.errmsgs
args;
2565 state.newerrmsgs
<- true;
2566 G.postRedisplay "error message"
2568 | "progress" :: args :: [] ->
2569 let progress, text =
2572 f, String.sub
args pos
(String.length
args - pos
))
2575 state.progress <- progress;
2576 G.postRedisplay "progress"
2578 | "firstmatch" :: args :: [] ->
2579 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2580 scan args "%u %d %f %f %f %f %f %f %f %f"
2581 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2582 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2584 let y = (getpagey pageno) + truncate
y0 in
2587 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2589 | "match" :: args :: [] ->
2590 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2591 scan args "%u %d %f %f %f %f %f %f %f %f"
2592 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2593 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2596 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2598 | "page" :: args :: [] ->
2599 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2600 begin match state.currently
with
2601 | Loading
(l, gen
) ->
2602 vlog "page %d took %f sec" l.pageno t
;
2603 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2604 begin match state.throttle
with
2606 let preloadedpages =
2608 then preloadlayout state.y
2613 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2614 IntSet.empty
preloadedpages
2617 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2618 if not
(IntSet.mem
pageno set)
2620 wcmd "freepage %s" opaque
;
2626 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2629 state.currently
<- Idle
;
2632 tilepage l.pageno pageopaque state.layout;
2634 load preloadedpages;
2635 if pagevisible state.layout l.pageno
2636 && layoutready state.layout
2637 then G.postRedisplay "page";
2640 | Some
(layout, _, _) ->
2641 state.currently
<- Idle
;
2642 tilepage l.pageno pageopaque layout;
2647 dolog
"Inconsistent loading state";
2648 logcurrently state.currently
;
2652 | "tile" :: args :: [] ->
2653 let (x, y, opaque
, size
, t
) =
2654 scan args "%u %u %s %u %f"
2655 (fun x y p size t
-> (x, y, p
, size
, t
))
2657 begin match state.currently
with
2658 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2659 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2662 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2664 wcmd "freetile %s" opaque
;
2665 state.currently
<- Idle
;
2669 puttileopaque l col row gen cs angle opaque size t
;
2670 state.memused
<- state.memused
+ size
;
2671 state.uioh#infochanged Memused
;
2673 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2674 opaque
, size
) state.tilelru
;
2677 match state.throttle
with
2678 | None
-> state.layout
2679 | Some
(layout, _, _) -> layout
2682 state.currently
<- Idle
;
2684 && conf.colorspace
= cs
2685 && conf.angle
= angle
2686 && tilevisible layout l.pageno x y
2687 then conttiling l.pageno pageopaque;
2689 begin match state.throttle
with
2691 preload state.layout;
2693 && conf.colorspace
= cs
2694 && conf.angle
= angle
2695 && tilevisible state.layout l.pageno x y
2696 && (not
!wtmode || layoutready state.layout)
2697 then G.postRedisplay "tile nothrottle";
2699 | Some
(layout, y, _) ->
2700 let ready = layoutready layout in
2704 state.layout <- layout;
2705 state.throttle
<- None
;
2706 G.postRedisplay "throttle";
2713 dolog
"Inconsistent tiling state";
2714 logcurrently state.currently
;
2718 | "pdim" :: args :: [] ->
2719 let (n, w, h, _) as pdim
=
2720 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2723 match conf.fitmodel
, conf.columns
with
2724 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2727 state.uioh#infochanged Pdim
;
2728 state.pdims
<- pdim :: state.pdims
2730 | "o" :: args :: [] ->
2731 let (l, n, t
, h, pos
) =
2732 scan args "%u %u %d %u %n"
2733 (fun l n t
h pos
-> l, n, t
, h, pos
)
2735 let s = String.sub
args pos
(String.length
args - pos
) in
2736 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2737 begin match state.currently
with
2738 | Outlining outlines
->
2739 state.currently
<- Outlining
(outline :: outlines
)
2741 state.currently
<- Outlining
[outline]
2743 dolog
"invalid outlining state";
2744 logcurrently currently
2747 | "a" :: args :: [] ->
2749 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2751 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2753 | "info" :: args :: [] ->
2754 state.docinfo
<- (1, args) :: state.docinfo
2756 | "infoend" :: [] ->
2757 state.uioh#infochanged Docinfo
;
2758 state.docinfo
<- List.rev
state.docinfo
2761 error
"unknown cmd `%S'" cmds
2766 let action = function
2767 | HCprev
-> cbget cb ~
-1
2768 | HCnext
-> cbget cb
1
2769 | HCfirst
-> cbget cb ~
-(cb
.rc)
2770 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2771 and cancel
() = cb
.rc <- rc
2775 let search pattern forward
=
2776 match conf.columns
with
2778 showtext '
!'
"searching does not work properly in split columns mode"
2780 if nonemptystr pattern
2783 match state.layout with
2786 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2788 wcmd "search %d %d %d %d,%s\000"
2789 (btod conf.icase
) pn py (btod forward
) pattern
;
2792 let intentry text key =
2794 if key >= 32 && key < 127
2800 let text = addchar text c in
2804 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2808 let linknentry text key =
2810 if key >= 32 && key < 127
2816 let text = addchar text c in
2820 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2828 let l = String.length
s in
2829 let rec loop pos
n = if pos
= l then n else
2830 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2831 loop (pos
+1) (n*26 + m)
2834 let rec loop n = function
2837 match getopaque l.pageno with
2838 | None
-> loop n rest
2840 let m = getlinkcount opaque
in
2843 let under = getlink opaque
n in
2846 else loop (n-m) rest
2848 loop n state.layout;
2852 let textentry text key =
2853 if key land 0xff00 = 0xff00
2855 else TEcont
(text ^ toutf8
key)
2858 let reqlayout angle fitmodel
=
2859 match state.throttle
with
2861 if nogeomcmds state.geomcmds
2862 then state.anchor <- getanchor ();
2863 conf.angle
<- angle
mod 360;
2866 match state.mode
with
2867 | LinkNav
_ -> state.mode
<- View
2870 conf.fitmodel
<- fitmodel
;
2871 invalidate "reqlayout"
2873 wcmd "reqlayout %d %d %d"
2874 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2879 let settrim trimmargins trimfuzz
=
2880 if nogeomcmds state.geomcmds
2881 then state.anchor <- getanchor ();
2882 conf.trimmargins
<- trimmargins
;
2883 conf.trimfuzz
<- trimfuzz
;
2884 let x0, y0, x1, y1 = trimfuzz
in
2885 invalidate "settrim"
2887 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2892 match state.throttle
with
2894 let zoom = max
0.0001 zoom in
2895 if zoom <> conf.zoom
2897 state.prevzoom
<- (conf.zoom, state.x);
2899 reshape state.winw
state.winh
;
2900 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2903 | Some
(layout, y, started
) ->
2905 match conf.maxwait
with
2909 let dt = now () -. started
in
2917 let setcolumns mode columns coverA coverB
=
2918 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2922 then showtext '
!'
"split mode doesn't work in bird's eye"
2924 conf.columns
<- Csplit
(-columns
, [||]);
2932 conf.columns
<- Csingle
[||];
2937 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2941 reshape state.winw
state.winh
;
2944 let enterbirdseye () =
2945 let zoom = float conf.thumbw
/. float state.winw
in
2946 let birdseyepageno =
2947 let cy = state.winh
/ 2 in
2951 let rec fold best
= function
2954 let d = cy - (l.pagedispy + l.pagevh/2)
2955 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2956 if abs
d < abs dbest
2963 state.mode
<- Birdseye
(
2964 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2967 conf.presentation
<- false;
2968 conf.interpagespace
<- 10;
2969 conf.hlinks
<- false;
2970 conf.fitmodel
<- FitProportional
;
2972 state.mstate
<- Mnone
;
2973 conf.maxwait
<- None
;
2975 match conf.beyecolumns
with
2978 Cmulti
((c, 0, 0), [||])
2979 | None
-> Csingle
[||]
2981 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2984 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2989 reshape state.winw
state.winh
;
2992 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2994 conf.zoom <- c.zoom;
2995 conf.presentation
<- c.presentation
;
2996 conf.interpagespace
<- c.interpagespace
;
2997 conf.maxwait
<- c.maxwait
;
2998 conf.hlinks
<- c.hlinks
;
2999 conf.fitmodel
<- c.fitmodel
;
3000 conf.beyecolumns
<- (
3001 match conf.columns
with
3002 | Cmulti
((c, _, _), _) -> Some
c
3004 | Csplit
_ -> failwith
"leaving bird's eye split mode"
3007 match c.columns
with
3008 | Cmulti
(c, _) -> Cmulti
(c, [||])
3009 | Csingle
_ -> Csingle
[||]
3010 | Csplit
(c, _) -> Csplit
(c, [||])
3014 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3017 reshape state.winw
state.winh
;
3018 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3022 let togglebirdseye () =
3023 match state.mode
with
3024 | Birdseye vals
-> leavebirdseye vals
true
3025 | View
-> enterbirdseye ()
3029 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3030 let pageno = max
0 (pageno - incr
) in
3031 let rec loop = function
3032 | [] -> gotopage1 pageno 0
3033 | l :: _ when l.pageno = pageno ->
3034 if l.pagedispy >= 0 && l.pagey = 0
3035 then G.postRedisplay "upbirdseye"
3036 else gotopage1 pageno 0
3037 | _ :: rest
-> loop rest
3040 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3043 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3044 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3045 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3046 let rec loop = function
3048 let y, h = getpageyh pageno in
3049 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3051 | l :: _ when l.pageno = pageno ->
3052 if l.pagevh != l.pageh
3053 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3054 else G.postRedisplay "downbirdseye"
3055 | _ :: rest
-> loop rest
3060 let optentry mode
_ key =
3061 let btos b = if b then "on" else "off" in
3062 if key >= 32 && key < 127
3064 let c = Char.chr
key in
3068 try conf.scrollstep
<- int_of_string
s with exc
->
3069 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3071 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3076 conf.autoscrollstep
<- int_of_string
s;
3077 if state.autoscroll
<> None
3078 then state.autoscroll
<- Some
conf.autoscrollstep
3080 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3082 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3087 let n, a, b = multicolumns_of_string s in
3088 setcolumns mode
n a b;
3090 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3092 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3097 let zoom = float (int_of_string
s) /. 100.0 in
3100 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3102 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3107 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3109 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3110 begin match mode
with
3112 leavebirdseye beye
false;
3117 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3119 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3124 Some
(int_of_string
s)
3126 state.text <- Printf.sprintf
"bad integer `%s': %s"
3130 | Some angle
-> reqlayout angle
conf.fitmodel
3133 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3136 conf.icase
<- not
conf.icase
;
3137 TEdone
("case insensitive search " ^
(btos conf.icase
))
3140 conf.preload <- not
conf.preload;
3142 TEdone
("preload " ^
(btos conf.preload))
3145 conf.verbose
<- not
conf.verbose
;
3146 TEdone
("verbose " ^
(btos conf.verbose
))
3149 conf.debug
<- not
conf.debug
;
3150 TEdone
("debug " ^
(btos conf.debug
))
3153 conf.maxhfit
<- not
conf.maxhfit
;
3154 state.maxy
<- calcheight ();
3155 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3158 conf.crophack
<- not
conf.crophack
;
3159 TEdone
("crophack " ^
btos conf.crophack
)
3163 match conf.maxwait
with
3165 conf.maxwait
<- Some infinity
;
3166 "always wait for page to complete"
3168 conf.maxwait
<- None
;
3169 "show placeholder if page is not ready"
3174 conf.underinfo
<- not
conf.underinfo
;
3175 TEdone
("underinfo " ^
btos conf.underinfo
)
3178 conf.savebmarks
<- not
conf.savebmarks
;
3179 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3185 match state.layout with
3190 conf.interpagespace
<- int_of_string
s;
3191 docolumns conf.columns
;
3192 state.maxy
<- calcheight ();
3193 let y = getpagey pageno in
3196 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3198 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3202 match conf.fitmodel
with
3203 | FitProportional
-> FitWidth
3204 | _ -> FitProportional
3206 reqlayout conf.angle
fm;
3207 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3210 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3211 TEdone
("trim margins " ^
btos conf.trimmargins
)
3214 conf.invert
<- not
conf.invert
;
3215 TEdone
("invert colors " ^
btos conf.invert
)
3219 cbput state.hists
.sel
s;
3222 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3223 textentry, ondone, true)
3227 then conf.pax
<- Some
(ref (0.0, 0, 0))
3228 else conf.pax
<- None
;
3229 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3232 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3238 class type lvsource
= object
3239 method getitemcount
: int
3240 method getitem
: int -> (string * int)
3241 method hasaction
: int -> bool
3250 method getactive
: int
3251 method getfirst
: int
3252 method getqsearch
: string
3253 method setqsearch
: string -> unit
3257 class virtual lvsourcebase
= object
3258 val mutable m_active
= 0
3259 val mutable m_first
= 0
3260 val mutable m_qsearch
= ""
3261 val mutable m_pan
= 0
3262 method getactive
= m_active
3263 method getfirst
= m_first
3264 method getqsearch
= m_qsearch
3265 method getpan
= m_pan
3266 method setqsearch
s = m_qsearch
<- s
3269 let withoutlastutf8 s =
3270 let len = String.length
s in
3278 let b = Char.code
s.[pos
] in
3279 if b land 0b11000000 = 0b11000000
3284 if Char.code
s.[len-1] land 0x80 = 0
3288 String.sub
s 0 first;
3291 let textentrykeyboard
3292 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3294 if key >= 0xffb0 && key <= 0xffb9
3295 then key - 0xffb0 + 48 else key
3298 state.mode
<- Textentry
(te
, onleave
);
3301 G.postRedisplay "textentrykeyboard enttext";
3303 let histaction cmd
=
3306 | Some
(action, _) ->
3307 state.mode
<- Textentry
(
3308 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3310 G.postRedisplay "textentry histaction"
3313 | 0xff08 -> (* backspace *)
3314 let s = withoutlastutf8 text in
3315 let len = String.length
s in
3316 if cancelonempty
&& len = 0
3319 G.postRedisplay "textentrykeyboard after cancel";
3322 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3325 | 0xff0d | 0xff8d -> (* (kp) enter *)
3328 G.postRedisplay "textentrykeyboard after confirm"
3330 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3331 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3332 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3333 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3335 | 0xff1b -> (* escape*)
3338 begin match opthist
with
3340 | Some
(_, onhistcancel
) -> onhistcancel
()
3344 G.postRedisplay "textentrykeyboard after cancel2"
3347 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3350 | 0xff9f | 0xffff -> () (* delete *)
3353 && key land 0xff00 != 0xff00 (* keyboard *)
3354 && key land 0xfe00 != 0xfe00 (* xkb *)
3355 && key land 0xfd00 != 0xfd00 (* 3270 *)
3357 begin match onkey
text key with
3361 G.postRedisplay "textentrykeyboard after confirm2";
3364 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3368 G.postRedisplay "textentrykeyboard after cancel3"
3371 state.mode
<- Textentry
(te
, onleave
);
3372 G.postRedisplay "textentrykeyboard switch";
3376 vlog "unhandled key %s" (Wsi.keyname
key)
3379 let firstof first active
=
3380 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3381 then max
0 (active
- (fstate.maxrows
/2))
3385 let calcfirst first active
=
3388 let rows = active
- first in
3389 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3393 let scrollph y maxy
=
3394 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3395 let sh = float state.winh
/. sh in
3396 let sh = max
sh (float conf.scrollh
) in
3398 let percent = float y /. float maxy
in
3399 let position = (float state.winh
-. sh) *. percent in
3402 if position +. sh > float state.winh
3403 then float state.winh
-. sh
3409 let coe s = (s :> uioh
);;
3411 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3413 val m_pan
= source#getpan
3414 val m_first
= source#getfirst
3415 val m_active
= source#getactive
3416 val m_qsearch
= source#getqsearch
3417 val m_prev_uioh
= state.uioh
3419 method private elemunder
y =
3420 let n = y / (fstate.fontsize
+1) in
3421 if m_first
+ n < source#getitemcount
3423 if source#hasaction
(m_first
+ n)
3424 then Some
(m_first
+ n)
3431 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3432 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3433 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3434 GlDraw.color
(1., 1., 1.);
3435 Gl.enable `texture_2d
;
3436 let fs = fstate.fontsize
in
3438 let ww = fstate.wwidth
in
3439 let tabw = 30.0*.ww in
3440 let itemcount = source#getitemcount
in
3442 if (row - m_first
) > fstate.maxrows
3445 if row >= 0 && row < itemcount
3447 let (s, level
) = source#getitem
row in
3448 let y = (row - m_first
) * nfs in
3449 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3452 Gl.disable `texture_2d
;
3453 GlDraw.polygon_mode `both `line
;
3454 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3455 GlDraw.color
(1., 1., 1.) ~
alpha;
3456 GlDraw.rect (1., float (y + 1))
3457 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3458 GlDraw.polygon_mode `both `fill
;
3459 GlDraw.color
(1., 1., 1.);
3460 Gl.enable `texture_2d
;
3463 let drawtabularstring s =
3464 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3467 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3470 let len = String.length
s - tabpos - 1 in
3471 let s1 = String.sub
s 0 tabpos
3472 and s2
= String.sub
s (tabpos + 1) len in
3473 let nx = drawstr x s1 in
3475 let x = x +. (max
tabw sw) in
3482 let _ = drawtabularstring s in
3489 Gl.disable `texture_2d
;
3491 method updownlevel incr
=
3492 let len = source#getitemcount
in
3494 if m_active
>= 0 && m_active
< len
3495 then snd
(source#getitem m_active
)
3499 if i
= len then i
-1 else if i
= -1 then 0 else
3500 let _, l = source#getitem i
in
3501 if l != curlevel then i
else flow (i
+incr
)
3503 let active = flow m_active
in
3504 let first = calcfirst m_first
active in
3505 G.postRedisplay "outline updownlevel";
3506 {< m_active
= active; m_first
= first >}
3508 method private key1
key mask
=
3509 let set1 active first qsearch
=
3510 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3512 let search active pattern incr
=
3513 let active = if active = -1 then m_first
else active in
3516 if n >= 0 && n < source#getitemcount
3518 let s, _ = source#getitem
n in
3520 (try ignore
(Str.search_forward
re s 0); true
3521 with Not_found
-> false)
3523 else loop (n + incr
)
3530 let re = Str.regexp_case_fold pattern
in
3536 let itemcount = source#getitemcount
in
3537 let find start incr
=
3539 if i
= -1 || i
= itemcount
3542 if source#hasaction i
3544 else find (i
+ incr
)
3549 let set active first =
3550 let first = bound first 0 (itemcount - fstate.maxrows
) in
3552 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3555 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3557 let incr1 = if incr
> 0 then 1 else -1 in
3558 if isvisible m_first m_active
3561 let next = m_active
+ incr
in
3563 if next < 0 || next >= itemcount
3565 else find next incr1
3567 if abs
(m_active
- next) > fstate.maxrows
3573 let first = m_first
+ incr
in
3574 let first = bound first 0 (itemcount - fstate.maxrows
) in
3576 let next = m_active
+ incr
in
3577 let next = bound next 0 (itemcount - 1) in
3584 if isvisible first next
3591 let first = min
next m_first
in
3593 if abs
(next - first) > fstate.maxrows
3599 let first = m_first
+ incr
in
3600 let first = bound first 0 (itemcount - 1) in
3602 let next = m_active
+ incr
in
3603 let next = bound next 0 (itemcount - 1) in
3604 let next = find next incr1 in
3606 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3608 let active = if m_active
= -1 then next else m_active
in
3613 if isvisible first active
3619 G.postRedisplay "listview navigate";
3623 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3624 let incr = if key = 0x72 then -1 else 1 in
3626 match search (m_active
+ incr) m_qsearch
incr with
3628 state.text <- m_qsearch ^
" [not found]";
3631 state.text <- m_qsearch
;
3632 active, firstof m_first
active
3634 G.postRedisplay "listview ctrl-r/s";
3635 set1 active first m_qsearch
;
3637 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3638 if m_active
>= 0 && m_active
< source#getitemcount
3640 let s, _ = source#getitem m_active
in
3645 | 0xff08 -> (* backspace *)
3646 if emptystr m_qsearch
3649 let qsearch = withoutlastutf8 m_qsearch
in
3653 G.postRedisplay "listview empty qsearch";
3654 set1 m_active m_first
"";
3658 match search m_active
qsearch ~
-1 with
3660 state.text <- qsearch ^
" [not found]";
3663 state.text <- qsearch;
3664 active, firstof m_first
active
3666 G.postRedisplay "listview backspace qsearch";
3667 set1 active first qsearch
3670 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3671 let pattern = m_qsearch ^ toutf8
key in
3673 match search m_active
pattern 1 with
3675 state.text <- pattern ^
" [not found]";
3678 state.text <- pattern;
3679 active, firstof m_first
active
3681 G.postRedisplay "listview qsearch add";
3682 set1 active first pattern;
3684 | 0xff1b -> (* escape *)
3686 if emptystr m_qsearch
3688 G.postRedisplay "list view escape";
3691 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3693 | None
-> m_prev_uioh
3698 G.postRedisplay "list view kill qsearch";
3699 source#setqsearch
"";
3700 coe {< m_qsearch
= "" >}
3703 | 0xff0d | 0xff8d -> (* (kp) enter *)
3705 let self = {< m_qsearch
= "" >} in
3706 source#setqsearch
"";
3708 G.postRedisplay "listview enter";
3709 if m_active
>= 0 && m_active
< source#getitemcount
3711 source#exit
(coe self) false m_active m_first m_pan
"";
3714 source#exit
(coe self) true m_active m_first m_pan
"";
3717 begin match opt with
3718 | None
-> m_prev_uioh
3722 | 0xff9f | 0xffff -> (* (kp) delete *)
3725 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3726 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3727 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3728 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3730 | 0xff53 | 0xff98 -> (* (kp) right *)
3732 G.postRedisplay "listview right";
3733 coe {< m_pan
= m_pan
- 1 >}
3735 | 0xff51 | 0xff96 -> (* (kp) left *)
3737 G.postRedisplay "listview left";
3738 coe {< m_pan
= m_pan
+ 1 >}
3740 | 0xff50 | 0xff95 -> (* (kp) home *)
3741 let active = find 0 1 in
3742 G.postRedisplay "listview home";
3745 | 0xff57 | 0xff9c -> (* (kp) end *)
3746 let first = max
0 (itemcount - fstate.maxrows
) in
3747 let active = find (itemcount - 1) ~
-1 in
3748 G.postRedisplay "listview end";
3751 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3755 dolog
"listview unknown key %#x" key; coe self
3757 method key key mask
=
3758 match state.mode
with
3759 | Textentry te
-> textentrykeyboard key mask te
; coe self
3760 | _ -> self#key1
key mask
3762 method button button down
x y _ =
3765 | 1 when x > state.winw
- conf.scrollbw
->
3766 G.postRedisplay "listview scroll";
3769 let _, position, sh = self#
scrollph in
3770 if y > truncate
position && y < truncate
(position +. sh)
3772 state.mstate
<- Mscrolly
;
3776 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3777 let first = truncate
(s *. float source#getitemcount
) in
3778 let first = min source#getitemcount
first in
3779 Some
(coe {< m_first
= first; m_active
= first >})
3781 state.mstate
<- Mnone
;
3784 | 1 when not down
->
3785 begin match self#elemunder
y with
3787 G.postRedisplay "listview click";
3789 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3793 | n when (n == 4 || n == 5) && not down
->
3794 let len = source#getitemcount
in
3796 if n = 5 && m_first
+ fstate.maxrows
>= len
3800 let first = m_first
+ (if n == 4 then -1 else 1) in
3801 bound first 0 (len - 1)
3803 G.postRedisplay "listview wheel";
3804 Some
(coe {< m_first
= first >})
3805 | n when (n = 6 || n = 7) && not down
->
3806 let inc = if n = 7 then -1 else 1 in
3807 G.postRedisplay "listview hwheel";
3808 Some
(coe {< m_pan
= m_pan
+ inc >})
3813 | None
-> m_prev_uioh
3817 match state.mstate
with
3819 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3820 let first = truncate
(s *. float source#getitemcount
) in
3821 let first = min source#getitemcount
first in
3822 G.postRedisplay "listview motion";
3823 coe {< m_first
= first; m_active
= first >}
3826 method pmotion
x y =
3827 if x < state.winw
- conf.scrollbw
3830 match self#elemunder
y with
3831 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3832 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3836 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3841 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3845 method infochanged
_ = ()
3847 method scrollpw
= (0, 0.0, 0.0)
3849 let nfs = fstate.fontsize
+ 1 in
3850 let y = m_first
* nfs in
3851 let itemcount = source#getitemcount
in
3852 let maxi = max
0 (itemcount - fstate.maxrows
) in
3853 let maxy = maxi * nfs in
3854 let p, h = scrollph y maxy in
3857 method modehash
= modehash
3858 method eformsgs
= false
3861 class outlinelistview ~source
=
3862 let settext autonarrow
s =
3864 then state.text <- "[" ^
s ^
"]"
3865 else state.text <- s
3869 ~source
:(source
:> lvsource
)
3871 ~modehash
:(findkeyhash conf "outline")
3874 val m_autonarrow
= false
3876 method key key mask
=
3878 if emptystr
state.text
3880 else fstate.maxrows - 2
3882 let calcfirst first active =
3885 let rows = active - first in
3886 if rows > maxrows then active - maxrows else first
3890 let active = m_active
+ incr in
3891 let active = bound active 0 (source#getitemcount
- 1) in
3892 let first = calcfirst m_first
active in
3893 G.postRedisplay "outline navigate";
3894 coe {< m_active
= active; m_first
= first >}
3896 let navscroll first =
3898 let dist = m_active
- first in
3904 else first + maxrows
3907 G.postRedisplay "outline navscroll";
3908 coe {< m_first
= first; m_active
= active >}
3910 let ctrl = Wsi.withctrl mask
in
3912 | 97 when ctrl -> (* ctrl-a *)
3914 then source#denarrow
3915 else source#narrow m_qsearch
;
3916 settext (not m_autonarrow
) m_qsearch
;
3917 G.postRedisplay "toggle auto narrowing";
3918 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3920 | 110 when ctrl -> (* ctrl-n *)
3921 source#narrow m_qsearch
;
3923 then source#add_narrow_pattern m_qsearch
;
3924 G.postRedisplay "outline ctrl-n";
3925 coe {< m_first
= 0; m_active
= 0 >}
3927 | 117 when ctrl -> (* ctrl-u *)
3928 source#del_narrow_pattern
;
3929 let pattern = source#renarrow
in
3930 G.postRedisplay "outline ctrl-u";
3932 if emptystr
pattern then "" else "Narrowed to " ^
pattern
3934 settext m_autonarrow
text;
3935 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
3937 | 108 when ctrl -> (* ctrl-l *)
3938 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3939 G.postRedisplay "outline ctrl-l";
3940 coe {< m_first
= first >}
3942 | 0xff1b -> (* escape *)
3943 let o = super#
key key mask
in
3946 if nonemptystr m_qsearch
3948 source#add_narrow_pattern m_qsearch
;
3954 | 0xff0d | 0xff8d when m_autonarrow
-> (* (kp) enter *)
3955 if nonemptystr m_qsearch
3956 then source#add_narrow_pattern m_qsearch
;
3959 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
3960 let pattern = m_qsearch ^ toutf8
key in
3961 G.postRedisplay "outlinelistview autonarrow add";
3962 source#narrow
pattern;
3963 settext true pattern;
3964 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3966 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
3967 if emptystr m_qsearch
3970 let pattern = withoutlastutf8 m_qsearch
in
3971 G.postRedisplay "outlinelistview autonarrow backspace";
3972 ignore
(source#renarrow
);
3973 source#narrow
pattern;
3974 settext true pattern;
3975 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3977 | 0xff9f | 0xffff -> (* (kp) delete *)
3978 source#remove m_active
;
3979 G.postRedisplay "outline delete";
3980 let active = max
0 (m_active
-1) in
3981 coe {< m_first
= firstof m_first
active;
3982 m_active
= active >}
3984 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
3985 navscroll (max
0 (m_first
- 1))
3987 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
3988 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3990 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3991 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3992 | 0xff55 | 0xff9a -> (* (kp) prior *)
3993 navigate ~
-(fstate.maxrows)
3994 | 0xff56 | 0xff9b -> (* (kp) next *)
3995 navigate fstate.maxrows
3997 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
4001 G.postRedisplay "outline ctrl right";
4002 {< m_pan
= m_pan
+ 1 >}
4004 else self#updownlevel
1
4008 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
4012 G.postRedisplay "outline ctrl left";
4013 {< m_pan
= m_pan
- 1 >}
4015 else self#updownlevel ~
-1
4019 | 0xff50 | 0xff95 -> (* (kp) home *)
4020 G.postRedisplay "outline home";
4021 coe {< m_first
= 0; m_active
= 0 >}
4023 | 0xff57 | 0xff9c -> (* (kp) end *)
4024 let active = source#getitemcount
- 1 in
4025 let first = max
0 (active - fstate.maxrows) in
4026 G.postRedisplay "outline end";
4027 coe {< m_active
= active; m_first
= first >}
4029 | _ -> super#
key key mask
4032 let outlinesource usebookmarks
=
4035 inherit lvsourcebase
4036 val mutable m_items
= empty
4037 val mutable m_orig_items
= empty
4038 val mutable m_narrow_patterns
= []
4039 val mutable m_hadremovals
= false
4041 method getitemcount
=
4042 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
4045 if n == Array.length m_items
&& m_hadremovals
4047 ("[Confirm removal]", 0)
4049 let s, n, _ = m_items
.(n) in
4052 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4053 ignore
(uioh
, first, qsearch);
4054 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
4056 if m_narrow_patterns
= []
4062 if not
confrimremoval
4064 let _, _, ((pageno, y, _) as anchor) = m_items
.(active) in
4066 (if conf.presentation
then (pageno, y, 1.0) else anchor)
4072 state.bookmarks
<- Array.to_list m_items
;
4073 m_orig_items
<- m_items
;
4076 else m_items
<- items;
4080 method hasaction
_ = true
4083 if Array.length m_items
!= Array.length m_orig_items
4086 match m_narrow_patterns
with
4088 | many
-> String.concat
" --> " (List.rev many
)
4090 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4093 method narrow
pattern =
4094 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4098 let rec loop accu n =
4100 then m_items
<- Array.of_list
accu
4102 let (s, _, _) as o = m_items
.(n) in
4104 if (try ignore
(Str.search_forward
re s 0); true
4105 with Not_found
-> false)
4111 loop [] (Array.length m_items
- 1)
4116 then Array.of_list
state.bookmarks
4119 m_items
<- m_orig_items
4124 if m >= 0 && m < Array.length m_items
4126 m_hadremovals
<- true;
4127 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4128 let n = if n >= m then n+1 else n in
4133 method add_narrow_pattern
pattern =
4134 m_narrow_patterns
<- pattern :: m_narrow_patterns
4136 method del_narrow_pattern
=
4137 match m_narrow_patterns
with
4138 | _ :: rest
-> m_narrow_patterns
<- rest
4143 match m_narrow_patterns
with
4144 | pattern :: [] -> self#narrow
pattern; pattern
4146 List.fold_left
(fun accu pattern ->
4147 self#narrow
pattern;
4148 accu ^
" --> " ^
pattern) "" list
4150 method reset
anchor items =
4151 m_hadremovals
<- false;
4152 if m_orig_items
== empty
4154 m_orig_items
<- items;
4155 if m_narrow_patterns
== []
4156 then m_items
<- items;
4158 let rely = getanchory anchor in
4160 let rec loop n best bestd
=
4161 if n = Array.length m_items
4164 let (_, _, anchor) = m_items
.(n) in
4165 let orely = getanchory anchor in
4166 let d = abs
(orely - rely) in
4169 else loop (n+1) best bestd
4174 m_first
<- firstof m_first
active
4178 let enterselector usebookmarks
=
4179 let source = outlinesource usebookmarks
in
4183 then Array.of_list
state.bookmarks
4186 if Array.length
outlines = 0
4188 showtext ' ' errmsg
;
4191 state.text <- source#greetmsg
;
4192 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4193 let anchor = getanchor () in
4194 source#reset
anchor outlines;
4195 state.uioh
<- coe (new outlinelistview ~
source);
4196 G.postRedisplay "enter selector";
4200 let enteroutlinemode =
4201 let f = enterselector false in
4202 fun ()-> f "Document has no outline";
4205 let enterbookmarkmode =
4206 let f = enterselector true in
4207 fun () -> f "Document has no bookmarks (yet)";
4210 let color_of_string s =
4211 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4212 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4216 let color_to_string (r, g, b) =
4217 let r = truncate
(r *. 256.0)
4218 and g = truncate
(g *. 256.0)
4219 and b = truncate
(b *. 256.0) in
4220 Printf.sprintf
"%d/%d/%d" r g b
4223 let irect_of_string s =
4224 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4227 let irect_to_string (x0,y0,x1,y1) =
4228 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4231 let makecheckers () =
4232 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4234 converted by Issac Trotts. July 25, 2002 *)
4235 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4236 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4237 let id = GlTex.gen_texture
() in
4238 GlTex.bind_texture `texture_2d
id;
4239 GlPix.store
(`unpack_alignment
1);
4240 GlTex.image2d
image;
4241 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4242 [ `mag_filter `nearest
; `min_filter `nearest
];
4246 let setcheckers enabled
=
4247 match state.texid
with
4249 if enabled
then state.texid
<- Some
(makecheckers ())
4254 GlTex.delete_texture texid
;
4255 state.texid
<- None
;
4259 let int_of_string_with_suffix s =
4260 let l = String.length
s in
4264 let suffix = Char.lowercase
s.[l-1] in
4266 | 'k'
-> String.sub
s 0 (l-1), 10
4267 | '
m'
-> String.sub
s 0 (l-1), 20
4268 | '
g'
-> String.sub
s 0 (l-1), 30
4272 let n = int_of_string
s1 in
4273 let m = n lsl shift
in
4275 then raise
(Failure
"value too large")
4279 let string_with_suffix_of_int n =
4283 let units = [(30, "G"); (20, "M"); (10, "K")] in
4286 let h = n mod 1000 in
4289 then string_of_int
h ^
s
4291 let s = Printf.sprintf
"_%03d%s" h s in
4297 let rec find = function
4299 | (shift
, suffix) :: rest
->
4300 if (n land ((1 lsl shift
) - 1)) = 0
4301 then prettyint (n lsr shift
) ^
suffix
4307 let defghyllscroll = (40, 8, 32);;
4308 let ghyllscroll_of_string s =
4309 let (n, a, b) as nab
=
4312 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4314 if n <= a || n <= b || a >= b
4315 then error
"invalid ghyll N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)"
4320 let ghyllscroll_to_string ((n, a, b) as nab
) =
4321 if nab
= defghyllscroll
4323 else Printf.sprintf
"%d,%d,%d" n a b;
4326 let describe_location () =
4327 let fn = page_of_y state.y in
4328 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4329 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4333 else (100. *. (float state.y /. float maxy))
4337 Printf.sprintf
"page %d of %d [%.2f%%]"
4338 (fn+1) state.pagecount
percent
4341 "pages %d-%d of %d [%.2f%%]"
4342 (fn+1) (ln+1) state.pagecount
percent
4345 let setpresentationmode v
=
4346 let n = page_of_y state.y in
4347 state.anchor <- (n, 0.0, 1.0);
4348 conf.presentation
<- v
;
4349 if conf.fitmodel
= FitPage
4350 then reqlayout conf.angle
conf.fitmodel
;
4355 let btos b = if b then "\xe2\x88\x9a" else "" in
4356 let showextended = ref false in
4357 let leave mode
= function
4358 | Confirm
-> state.mode
<- mode
4359 | Cancel
-> state.mode
<- mode
in
4362 val mutable m_first_time
= true
4363 val mutable m_l
= []
4364 val mutable m_a
= [||]
4365 val mutable m_prev_uioh
= nouioh
4366 val mutable m_prev_mode
= View
4368 inherit lvsourcebase
4370 method reset prev_mode prev_uioh
=
4371 m_a
<- Array.of_list
(List.rev m_l
);
4373 m_prev_mode
<- prev_mode
;
4374 m_prev_uioh
<- prev_uioh
;
4378 if n >= Array.length m_a
4382 | _, _, _, Action
_ -> m_active
<- n
4386 m_first_time
<- false;
4389 method int name get
set =
4391 (name, `
int get
, 1, Action
(
4394 try set (int_of_string
s)
4396 state.text <- Printf.sprintf
"bad integer `%s': %s"
4400 let te = name ^
": ", "", None
, intentry, ondone, true in
4401 state.mode
<- Textentry
(te, leave m_prev_mode
);
4405 method int_with_suffix
name get
set =
4407 (name, `intws get
, 1, Action
(
4410 try set (int_of_string_with_suffix s)
4412 state.text <- Printf.sprintf
"bad integer `%s': %s"
4417 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4419 state.mode
<- Textentry
(te, leave m_prev_mode
);
4423 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4425 (name, `
bool (btos, get
), offset
, Action
(
4432 method color
name get
set =
4434 (name, `color get
, 1, Action
(
4436 let invalid = (nan
, nan
, nan
) in
4439 try color_of_string s
4441 state.text <- Printf.sprintf
"bad color `%s': %s"
4448 let te = name ^
": ", "", None
, textentry, ondone, true in
4449 state.text <- color_to_string (get
());
4450 state.mode
<- Textentry
(te, leave m_prev_mode
);
4454 method string name get
set =
4456 (name, `
string get
, 1, Action
(
4458 let ondone s = set s in
4459 let te = name ^
": ", "", None
, textentry, ondone, true in
4460 state.mode
<- Textentry
(te, leave m_prev_mode
);
4464 method colorspace
name get
set =
4466 (name, `
string get
, 1, Action
(
4470 inherit lvsourcebase
4473 m_active
<- CSTE.to_int conf.colorspace
;
4476 method getitemcount
=
4477 Array.length
CSTE.names
4480 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4481 ignore
(uioh
, first, pan
, qsearch);
4482 if not cancel
then set active;
4484 method hasaction
_ = true
4488 let modehash = findkeyhash conf "info" in
4489 coe (new listview ~
source ~trusted
:true ~
modehash)
4492 method paxmark
name get
set =
4494 (name, `
string get
, 1, Action
(
4498 inherit lvsourcebase
4501 m_active
<- MTE.to_int conf.paxmark
;
4504 method getitemcount
= Array.length
MTE.names
4505 method getitem
n = (MTE.names.(n), 0)
4506 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4507 ignore
(uioh
, first, pan
, qsearch);
4508 if not cancel
then set active;
4510 method hasaction
_ = true
4514 let modehash = findkeyhash conf "info" in
4515 coe (new listview ~
source ~trusted
:true ~
modehash)
4518 method fitmodel
name get
set =
4520 (name, `
string get
, 1, Action
(
4524 inherit lvsourcebase
4527 m_active
<- FMTE.to_int conf.fitmodel
;
4530 method getitemcount
= Array.length
FMTE.names
4531 method getitem
n = (FMTE.names.(n), 0)
4532 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4533 ignore
(uioh
, first, pan
, qsearch);
4534 if not cancel
then set active;
4536 method hasaction
_ = true
4540 let modehash = findkeyhash conf "info" in
4541 coe (new listview ~
source ~trusted
:true ~
modehash)
4544 method caption
s offset
=
4545 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4547 method caption2
s f offset
=
4548 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4550 method getitemcount
= Array.length m_a
4553 let tostr = function
4554 | `
int f -> string_of_int
(f ())
4555 | `intws
f -> string_with_suffix_of_int (f ())
4557 | `color
f -> color_to_string (f ())
4558 | `
bool (btos, f) -> btos (f ())
4561 let name, t
, offset
, _ = m_a
.(n) in
4562 ((let s = tostr t
in
4564 then Printf.sprintf
"%s\t%s" name s
4568 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4572 m_qsearch
<- qsearch;
4574 match m_a
.(active) with
4575 | _, _, _, Action
f -> f uioh
4587 method hasaction
n =
4589 | _, _, _, Action
_ -> true
4593 let rec fillsrc prevmode prevuioh
=
4594 let sep () = src#caption
"" 0 in
4595 let colorp name get
set =
4597 (fun () -> color_to_string (get
()))
4600 let c = color_of_string v in
4603 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4606 let oldmode = state.mode
in
4607 let birdseye = isbirdseye state.mode
in
4609 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4611 src#
bool "presentation mode"
4612 (fun () -> conf.presentation
)
4613 (fun v -> setpresentationmode v);
4615 src#
bool "ignore case in searches"
4616 (fun () -> conf.icase
)
4617 (fun v -> conf.icase
<- v);
4620 (fun () -> conf.preload)
4621 (fun v -> conf.preload <- v);
4623 src#
bool "highlight links"
4624 (fun () -> conf.hlinks
)
4625 (fun v -> conf.hlinks
<- v);
4627 src#
bool "under info"
4628 (fun () -> conf.underinfo
)
4629 (fun v -> conf.underinfo
<- v);
4631 src#
bool "persistent bookmarks"
4632 (fun () -> conf.savebmarks
)
4633 (fun v -> conf.savebmarks
<- v);
4635 src#fitmodel
"fit model"
4636 (fun () -> FMTE.to_string conf.fitmodel
)
4637 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4639 src#
bool "trim margins"
4640 (fun () -> conf.trimmargins
)
4641 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4643 src#
bool "persistent location"
4644 (fun () -> conf.jumpback
)
4645 (fun v -> conf.jumpback
<- v);
4648 src#
int "inter-page space"
4649 (fun () -> conf.interpagespace
)
4651 conf.interpagespace
<- n;
4652 docolumns conf.columns
;
4654 match state.layout with
4659 state.maxy <- calcheight ();
4660 let y = getpagey pageno in
4665 (fun () -> conf.pagebias
)
4666 (fun v -> conf.pagebias
<- v);
4668 src#
int "scroll step"
4669 (fun () -> conf.scrollstep
)
4670 (fun n -> conf.scrollstep
<- n);
4672 src#
int "horizontal scroll step"
4673 (fun () -> conf.hscrollstep
)
4674 (fun v -> conf.hscrollstep
<- v);
4676 src#
int "auto scroll step"
4678 match state.autoscroll
with
4680 | _ -> conf.autoscrollstep
)
4682 if state.autoscroll
<> None
4683 then state.autoscroll
<- Some
n;
4684 conf.autoscrollstep
<- n);
4687 (fun () -> truncate
(conf.zoom *. 100.))
4688 (fun v -> setzoom ((float v) /. 100.));
4691 (fun () -> conf.angle
)
4692 (fun v -> reqlayout v conf.fitmodel
);
4694 src#
int "scroll bar width"
4695 (fun () -> conf.scrollbw
)
4698 reshape state.winw
state.winh
;
4701 src#
int "scroll handle height"
4702 (fun () -> conf.scrollh
)
4703 (fun v -> conf.scrollh
<- v;);
4705 src#
int "thumbnail width"
4706 (fun () -> conf.thumbw
)
4708 conf.thumbw
<- min
4096 v;
4711 leavebirdseye beye
false;
4716 let mode = state.mode in
4717 src#
string "columns"
4719 match conf.columns
with
4721 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4722 | Csplit
(count
, _) -> "-" ^ string_of_int count
4725 let n, a, b = multicolumns_of_string v in
4726 setcolumns mode n a b);
4729 src#caption
"Pixmap cache" 0;
4730 src#int_with_suffix
"size (advisory)"
4731 (fun () -> conf.memlimit
)
4732 (fun v -> conf.memlimit
<- v);
4735 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4736 (string_with_suffix_of_int state.memused
)
4737 (Hashtbl.length
state.tilemap
)) 1;
4740 src#caption
"Layout" 0;
4741 src#caption2
"Dimension"
4743 Printf.sprintf
"%dx%d (virtual %dx%d)"
4744 state.winw
state.winh
4749 src#caption2
"Position" (fun () ->
4750 Printf.sprintf
"%dx%d" state.x state.y
4753 src#caption2
"Position" (fun () -> describe_location ()) 1
4757 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4758 "Save these parameters as global defaults at exit"
4759 (fun () -> conf.bedefault
)
4760 (fun v -> conf.bedefault
<- v)
4764 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4765 src#
bool ~offset
:0 ~
btos "Extended parameters"
4766 (fun () -> !showextended)
4767 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4771 (fun () -> conf.checkers
)
4772 (fun v -> conf.checkers
<- v; setcheckers v);
4773 src#
bool "update cursor"
4774 (fun () -> conf.updatecurs
)
4775 (fun v -> conf.updatecurs
<- v);
4777 (fun () -> conf.verbose
)
4778 (fun v -> conf.verbose
<- v);
4779 src#
bool "invert colors"
4780 (fun () -> conf.invert
)
4781 (fun v -> conf.invert
<- v);
4783 (fun () -> conf.maxhfit
)
4784 (fun v -> conf.maxhfit
<- v);
4785 src#
bool "redirect stderr"
4786 (fun () -> conf.redirectstderr)
4787 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4789 (fun () -> conf.pax
!= None
)
4792 then conf.pax
<- Some
(ref (now (), 0, 0))
4793 else conf.pax
<- None
);
4794 src#
string "uri launcher"
4795 (fun () -> conf.urilauncher
)
4796 (fun v -> conf.urilauncher
<- v);
4797 src#
string "path launcher"
4798 (fun () -> conf.pathlauncher
)
4799 (fun v -> conf.pathlauncher
<- v);
4800 src#
string "tile size"
4801 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4804 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4805 conf.tilew
<- max
64 w;
4806 conf.tileh
<- max
64 h;
4809 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4812 src#
int "texture count"
4813 (fun () -> conf.texcount
)
4816 then conf.texcount
<- v
4817 else showtext '
!'
" Failed to set texture count please retry later"
4819 src#
int "slice height"
4820 (fun () -> conf.sliceheight
)
4822 conf.sliceheight
<- v;
4823 wcmd "sliceh %d" conf.sliceheight
;
4825 src#
int "anti-aliasing level"
4826 (fun () -> conf.aalevel
)
4828 conf.aalevel
<- bound v 0 8;
4829 state.anchor <- getanchor ();
4830 opendoc state.path
state.password
;
4832 src#
string "page scroll scaling factor"
4833 (fun () -> string_of_float
conf.pgscale)
4836 let s = float_of_string
v in
4839 state.text <- Printf.sprintf
4840 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4843 src#
int "ui font size"
4844 (fun () -> fstate.fontsize
)
4845 (fun v -> setfontsize (bound v 5 100));
4846 src#
int "hint font size"
4847 (fun () -> conf.hfsize
)
4848 (fun v -> conf.hfsize
<- bound v 5 100);
4849 colorp "background color"
4850 (fun () -> conf.bgcolor
)
4851 (fun v -> conf.bgcolor
<- v);
4852 src#
bool "crop hack"
4853 (fun () -> conf.crophack
)
4854 (fun v -> conf.crophack
<- v);
4855 src#
string "trim fuzz"
4856 (fun () -> irect_to_string conf.trimfuzz
)
4859 conf.trimfuzz
<- irect_of_string v;
4861 then settrim true conf.trimfuzz
;
4863 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4865 src#
string "throttle"
4867 match conf.maxwait
with
4868 | None
-> "show place holder if page is not ready"
4871 then "wait for page to fully render"
4873 "wait " ^ string_of_float
time
4874 ^
" seconds before showing placeholder"
4878 let f = float_of_string
v in
4880 then conf.maxwait
<- None
4881 else conf.maxwait
<- Some
f
4883 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4885 src#
string "ghyll scroll"
4887 match conf.ghyllscroll
with
4889 | Some nab
-> ghyllscroll_to_string nab
4896 else Some
(ghyllscroll_of_string v)
4898 conf.ghyllscroll
<- gs
4900 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4902 src#
string "selection command"
4903 (fun () -> conf.selcmd
)
4904 (fun v -> conf.selcmd
<- v);
4905 src#
string "synctex command"
4906 (fun () -> conf.stcmd
)
4907 (fun v -> conf.stcmd
<- v);
4908 src#
string "pax command"
4909 (fun () -> conf.paxcmd
)
4910 (fun v -> conf.paxcmd
<- v);
4911 src#colorspace
"color space"
4912 (fun () -> CSTE.to_string conf.colorspace
)
4914 conf.colorspace
<- CSTE.of_int v;
4918 src#paxmark
"pax mark method"
4919 (fun () -> MTE.to_string conf.paxmark
)
4920 (fun v -> conf.paxmark
<- MTE.of_int v);
4924 (fun () -> conf.usepbo
)
4925 (fun v -> conf.usepbo
<- v);
4926 src#
bool "mouse wheel scrolls pages"
4927 (fun () -> conf.wheelbypage
)
4928 (fun v -> conf.wheelbypage
<- v);
4929 src#
bool "open remote links in a new instance"
4930 (fun () -> conf.riani
)
4931 (fun v -> conf.riani
<- v);
4935 src#caption
"Document" 0;
4936 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4937 src#caption2
"Pages"
4938 (fun () -> string_of_int
state.pagecount
) 1;
4939 src#caption2
"Dimensions"
4940 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4944 src#caption
"Trimmed margins" 0;
4945 src#caption2
"Dimensions"
4946 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4950 src#caption
"OpenGL" 0;
4951 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4952 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4955 src#caption
"Location" 0;
4956 if nonemptystr
state.origin
4957 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4958 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4960 src#reset prevmode prevuioh
;
4964 let prevmode = state.mode
4965 and prevuioh
= state.uioh in
4966 fillsrc prevmode prevuioh
;
4967 let source = (src :> lvsource
) in
4968 let modehash = findkeyhash conf "info" in
4969 state.uioh <- coe (object (self)
4970 inherit listview ~
source ~trusted
:true ~
modehash as super
4971 val mutable m_prevmemused
= 0
4972 method infochanged
= function
4974 if m_prevmemused
!= state.memused
4976 m_prevmemused
<- state.memused
;
4977 G.postRedisplay "memusedchanged";
4979 | Pdim
-> G.postRedisplay "pdimchanged"
4980 | Docinfo
-> fillsrc prevmode prevuioh
4982 method key key mask
=
4983 if not
(Wsi.withctrl mask
)
4986 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4987 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4988 | _ -> super#
key key mask
4989 else super#
key key mask
4991 G.postRedisplay "info";
4997 inherit lvsourcebase
4998 method getitemcount
= Array.length
state.help
5000 let s, l, _ = state.help
.(n) in
5003 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5007 m_qsearch
<- qsearch;
5008 match state.help
.(active) with
5009 | _, _, Action
f -> Some
(f uioh)
5019 method hasaction
n =
5020 match state.help
.(n) with
5021 | _, _, Action
_ -> true
5028 let modehash = findkeyhash conf "help" in
5029 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
5030 G.postRedisplay "help";
5035 let re = Str.regexp
"[\r\n]" in
5037 inherit lvsourcebase
5038 val mutable m_items
= [||]
5040 method getitemcount
= 1 + Array.length m_items
5045 else m_items
.(n-1), 0
5047 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5052 then Buffer.clear
state.errmsgs
;
5053 m_qsearch
<- qsearch;
5060 method hasaction
n =
5064 state.newerrmsgs
<- false;
5065 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
5066 m_items
<- Array.of_list
l
5074 let source = (msgsource :> lvsource
) in
5075 let modehash = findkeyhash conf "listview" in
5076 state.uioh <- coe (object
5077 inherit listview ~
source ~trusted
:false ~
modehash as super
5080 then msgsource#reset
;
5083 G.postRedisplay "msgs";
5086 let quickbookmark ?title
() =
5087 match state.layout with
5093 let sec = Unix.gettimeofday
() in
5094 let tm = Unix.localtime
sec in
5095 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5099 (tm.Unix.tm_year
+ 1900)
5102 | Some
title -> title
5104 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
5107 let setautoscrollspeed step goingdown
=
5108 let incr = max
1 ((abs step
) / 2) in
5109 let incr = if goingdown
then incr else -incr in
5110 let astep = step
+ incr in
5111 state.autoscroll
<- Some
astep;
5114 let gotounder under =
5115 let getpath filename
=
5117 if nonemptystr filename
5119 if Filename.is_relative filename
5121 let dir = Filename.dirname
state.path in
5123 if Filename.is_implicit
dir
5124 then Filename.concat
(Sys.getcwd
()) dir
5127 Filename.concat
dir filename
5131 if Sys.file_exists
path
5136 | Ulinkgoto
(pageno, top) ->
5140 gotopage1 pageno top;
5146 | Uremote
(filename
, pageno) ->
5147 let path = getpath filename
in
5152 let command = !selfexec ^
" " ^
path in
5153 try popen command []
5156 "failed to execute `%s': %s\n" command (exntos exn
);
5159 let anchor = getanchor () in
5160 let ranchor = state.path, state.password
, anchor, state.origin
in
5162 state.anchor <- (pageno, 0.0, 0.0);
5163 state.ranchors
<- ranchor :: state.ranchors
;
5166 else showtext '
!'
("Could not find " ^ filename
)
5168 | Uremotedest
(filename
, destname
) ->
5169 let path = getpath filename
in
5174 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
5175 try popen command []
5178 "failed to execute `%s': %s\n" command (exntos exn
);
5181 let anchor = getanchor () in
5182 let ranchor = state.path, state.password
, anchor, state.origin
in
5184 state.nameddest
<- destname
;
5185 state.ranchors
<- ranchor :: state.ranchors
;
5188 else showtext '
!'
("Could not find " ^ filename
)
5190 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
5194 match conf.columns
with
5196 | _ -> state.x != 0 || conf.zoom > 1.0
5199 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5201 let existsinrow pageno (columns
, coverA
, coverB
) p =
5202 let last = ((pageno - coverA
) mod columns
) + columns
in
5203 let rec any = function
5206 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5210 then (if l.pageno = last then false else any rest
)
5218 match state.layout with
5220 let pageno = page_of_y state.y in
5221 gotoghyll (getpagey (pageno+1))
5223 match conf.columns
with
5225 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5227 let y = clamp (pgscale state.winh
) in
5230 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5231 gotoghyll (getpagey pageno)
5232 | Cmulti
((c, _, _) as cl, _) ->
5233 if conf.presentation
5234 && (existsinrow l.pageno cl
5235 (fun l -> l.pageh
> l.pagey + l.pagevh))
5237 let y = clamp (pgscale state.winh
) in
5240 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5241 gotoghyll (getpagey pageno)
5243 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5245 let pagey, pageh
= getpageyh l.pageno in
5246 let pagey = pagey + pageh
* l.pagecol
in
5247 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5248 gotoghyll (pagey + pageh
+ ips)
5252 match state.layout with
5254 let pageno = page_of_y state.y in
5255 gotoghyll (getpagey (pageno-1))
5257 match conf.columns
with
5259 if conf.presentation
&& l.pagey != 0
5261 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5263 let pageno = max
0 (l.pageno-1) in
5264 gotoghyll (getpagey pageno)
5265 | Cmulti
((c, _, coverB
) as cl, _) ->
5266 if conf.presentation
&&
5267 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5269 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5272 if l.pageno = state.pagecount
- coverB
5276 let pageno = max
0 (l.pageno-decr) in
5277 gotoghyll (getpagey pageno)
5285 let pageno = max
0 (l.pageno-1) in
5286 let pagey, pageh
= getpageyh pageno in
5289 let pagey, pageh
= getpageyh l.pageno in
5290 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5295 let viewkeyboard key mask
=
5297 let mode = state.mode in
5298 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5301 G.postRedisplay "view:enttext"
5303 let ctrl = Wsi.withctrl mask
in
5305 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5311 | 0xff63 -> (* insert *)
5312 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5314 state.mode <- LinkNav
(Ltgendir
0);
5317 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5319 | 0xff1b | 113 -> (* escape / q *)
5320 begin match state.mstate
with
5322 state.mstate
<- Mnone
;
5323 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5324 G.postRedisplay "kill zoom rect";
5326 begin match state.mode with
5329 G.postRedisplay "esc leave linknav"
5331 match state.ranchors
with
5333 | (path, password
, anchor, origin
) :: rest
->
5334 state.ranchors
<- rest
;
5335 state.anchor <- anchor;
5336 state.origin
<- origin
;
5337 state.nameddest
<- "";
5338 opendoc path password
5342 | 0xff08 -> (* backspace *)
5343 gotoghyll (getnav ~
-1)
5351 G.postRedisplay "dehighlight";
5353 | 47 | 63 -> (* / ? *)
5354 let ondone isforw
s =
5355 cbput state.hists
.pat
s;
5356 state.searchpattern
<- s;
5359 let s = String.create
1 in
5360 s.[0] <- Char.chr
key;
5361 enttext (s, "", Some
(onhist state.hists
.pat
),
5362 textentry, ondone (key = 47), true)
5364 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5365 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5366 setzoom (conf.zoom +. incr)
5368 | 43 | 0xffab -> (* + *)
5371 try int_of_string
s with exc
->
5372 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5378 state.text <- "page bias is now " ^ string_of_int
n;
5381 enttext ("page bias: ", "", None
, intentry, ondone, true)
5383 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5384 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5385 setzoom (max
0.01 (conf.zoom -. decr))
5387 | 45 | 0xffad -> (* - *)
5388 let ondone msg
= state.text <- msg
in
5390 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5391 optentry state.mode, ondone, true
5394 | 48 when ctrl -> (* ctrl-0 *)
5402 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5404 match conf.columns
with
5405 | Csingle
_ | Cmulti
_ -> 1
5406 | Csplit
(n, _) -> n
5408 let h = state.winh
-
5409 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5411 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5412 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5415 | 51 when ctrl -> (* ctrl-3 *)
5417 match conf.fitmodel
with
5418 | FitWidth
-> FitProportional
5419 | FitProportional
-> FitPage
5420 | FitPage
-> FitWidth
5422 state.text <- "fit model: " ^
FMTE.to_string fm;
5423 reqlayout conf.angle
fm
5425 | 0xffc6 -> (* f9 *)
5428 | 57 when ctrl -> (* ctrl-9 *)
5431 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5432 when not
ctrl -> (* 0..9 *)
5435 try int_of_string
s with exc
->
5436 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5442 cbput state.hists
.pag
(string_of_int
n);
5443 gotopage1 (n + conf.pagebias
- 1) 0;
5446 let pageentry text key =
5447 match Char.unsafe_chr
key with
5448 | '
g'
-> TEdone
text
5449 | _ -> intentry text key
5451 let text = "x" in text.[0] <- Char.chr
key;
5452 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5455 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5456 reshape state.winw
state.winh
;
5459 state.bzoom
<- not
state.bzoom
;
5461 showtext ' '
("block zoom " ^
if state.bzoom
then "on" else "off")
5464 conf.hlinks
<- not
conf.hlinks
;
5465 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5466 G.postRedisplay "toggle highlightlinks";
5469 state.glinks
<- true;
5470 let mode = state.mode in
5471 state.mode <- Textentry
(
5472 (":", "", None
, linknentry, linkndone gotounder, false),
5474 state.glinks
<- false;
5478 G.postRedisplay "view:linkent(F)"
5481 state.glinks
<- true;
5482 let mode = state.mode in
5483 state.mode <- Textentry
(
5485 ":", "", None
, linknentry, linkndone (fun under ->
5486 selstring (undertext under);
5490 state.glinks
<- false;
5494 G.postRedisplay "view:linkent"
5497 begin match state.autoscroll
with
5499 conf.autoscrollstep
<- step
;
5500 state.autoscroll
<- None
5502 if conf.autoscrollstep
= 0
5503 then state.autoscroll
<- Some
1
5504 else state.autoscroll
<- Some
conf.autoscrollstep
5507 | 112 when ctrl -> (* ctrl-p *)
5511 setpresentationmode (not
conf.presentation
);
5512 showtext ' '
("presentation mode " ^
5513 if conf.presentation
then "on" else "off");
5516 if List.mem
Wsi.Fullscreen
state.winstate
5517 then Wsi.reshape conf.cwinw
conf.cwinh
5518 else Wsi.fullscreen
()
5520 | 112 | 78 -> (* p|N *)
5521 search state.searchpattern
false
5523 | 110 | 0xffc0 -> (* n|F3 *)
5524 search state.searchpattern
true
5527 begin match state.layout with
5530 gotoghyll (getpagey l.pageno)
5536 | 0xff9f | 0xffff -> (* delete *)
5540 showtext ' '
(describe_location ());
5543 begin match state.layout with
5546 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5551 enterbookmarkmode ()
5553 | 104 | 0xffbe -> (* h|F1 *)
5559 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5564 match state.layout with
5568 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5571 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5575 showtext ' '
"Quick bookmark added";
5578 begin match state.layout with
5580 let rect = getpdimrect
l.pagedimno
in
5584 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5585 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5587 (truncate
(rect.(1) -. rect.(0)),
5588 truncate
(rect.(3) -. rect.(0)))
5590 let w = truncate
((float w)*.conf.zoom)
5591 and h = truncate
((float h)*.conf.zoom) in
5594 state.anchor <- getanchor ();
5595 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5597 G.postRedisplay "z";
5602 | 120 -> state.roam
()
5603 | 60 | 62 -> (* < > *)
5604 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5606 | 91 | 93 -> (* [ ] *)
5608 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5610 G.postRedisplay "brightness";
5612 | 99 when state.mode = View
-> (* [alt-]c *)
5617 let m = (wadjsb state.winw
- state.w) / 2 in
5619 gotoy_and_clear_text state.y
5623 match state.prevcolumns
with
5624 | None
-> (1, 0, 0), 1.0
5625 | Some
(columns
, z
) ->
5628 | Csplit
(c, _) -> -c, 0, 0
5629 | Cmulti
((c, a, b), _) -> c, a, b
5630 | Csingle
_ -> 1, 0, 0
5634 setcolumns View
c a b;
5637 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
5638 -> (* ctrl-shift- (kp) [up|down] *)
5639 let zoom, x = state.prevzoom
in
5643 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5644 begin match state.autoscroll
with
5646 begin match state.mode with
5647 | Birdseye beye
-> upbirdseye 1 beye
5650 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5652 if not
(Wsi.withshift mask
) && conf.presentation
5654 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5658 setautoscrollspeed n false
5661 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5662 begin match state.autoscroll
with
5664 begin match state.mode with
5665 | Birdseye beye
-> downbirdseye 1 beye
5668 then gotoy_and_clear_text (clamp (state.winh
/2))
5670 if not
(Wsi.withshift mask
) && conf.presentation
5672 else gotoy_and_clear_text (clamp conf.scrollstep
)
5676 setautoscrollspeed n true
5679 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5680 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5686 else conf.hscrollstep
5688 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5689 state.x <- panbound (state.x + dx);
5690 gotoy_and_clear_text state.y
5693 G.postRedisplay "left/right"
5696 | 0xff55 | 0xff9a -> (* (kp) prior *)
5700 match state.layout with
5702 | l :: _ -> state.y - l.pagey
5704 clamp (pgscale (-state.winh
))
5708 | 0xff56 | 0xff9b -> (* (kp) next *)
5712 match List.rev
state.layout with
5714 | l :: _ -> getpagey l.pageno
5716 clamp (pgscale state.winh
)
5720 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5722 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5723 gotoghyll (clamp state.maxy)
5726 when Wsi.withalt mask
-> (* alt-(kp) right *)
5727 gotoghyll (getnav 1)
5729 when Wsi.withalt mask
-> (* alt-(kp) left *)
5730 gotoghyll (getnav ~
-1)
5735 | 118 when conf.debug
-> (* v *)
5738 match getopaque l.pageno with
5741 let x0, y0, x1, y1 = pagebbox opaque
in
5742 let a,b = float x0, float y0 in
5743 let c,d = float x1, float y0 in
5744 let e,f = float x1, float y1 in
5745 let h,j
= float x0, float y1 in
5746 let rect = (a,b,c,d,e,f,h,j
) in
5748 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5750 G.postRedisplay "v";
5753 vlog "huh? %s" (Wsi.keyname
key)
5756 let linknavkeyboard key mask
linknav =
5757 let getpage pageno =
5758 let rec loop = function
5760 | l :: _ when l.pageno = pageno -> Some
l
5761 | _ :: rest
-> loop rest
5762 in loop state.layout
5764 let doexact (pageno, n) =
5765 match getopaque pageno, getpage pageno with
5766 | Some opaque
, Some
l ->
5767 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5769 let under = getlink opaque
n in
5770 G.postRedisplay "link gotounder";
5776 | 0xff50 -> (* home *)
5777 Some
(findlink opaque LDfirst
), -1
5779 | 0xff57 -> (* end *)
5780 Some
(findlink opaque LDlast
), 1
5782 | 0xff51 -> (* left *)
5783 Some
(findlink opaque
(LDleft
n)), -1
5785 | 0xff53 -> (* right *)
5786 Some
(findlink opaque
(LDright
n)), 1
5788 | 0xff52 -> (* up *)
5789 Some
(findlink opaque
(LDup
n)), -1
5791 | 0xff54 -> (* down *)
5792 Some
(findlink opaque
(LDdown
n)), 1
5797 begin match findpwl
l.pageno dir with
5801 state.mode <- LinkNav
(Ltgendir
dir);
5802 let y, h = getpageyh pageno in
5805 then y + h - state.winh
5810 begin match getopaque pageno, getpage pageno with
5811 | Some opaque
, Some
_ ->
5813 let ld = if dir > 0 then LDfirst
else LDlast
in
5816 begin match link with
5818 showlinktype (getlink opaque
m);
5819 state.mode <- LinkNav
(Ltexact
(pageno, m));
5820 G.postRedisplay "linknav jpage";
5827 begin match opt with
5828 | Some Lnotfound
-> pwl l dir;
5829 | Some
(Lfound
m) ->
5833 let _, y0, _, y1 = getlinkrect opaque
m in
5835 then gotopage1 l.pageno y0
5837 let d = fstate.fontsize
+ 1 in
5838 if y1 - l.pagey > l.pagevh - d
5839 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5840 else G.postRedisplay "linknav";
5842 showlinktype (getlink opaque
m);
5843 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5846 | None
-> viewkeyboard key mask
5848 | _ -> viewkeyboard key mask
5853 G.postRedisplay "leave linknav"
5857 | Ltgendir
_ -> viewkeyboard key mask
5858 | Ltexact exact
-> doexact exact
5861 let keyboard key mask
=
5862 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5863 then wcmd "interrupt"
5864 else state.uioh <- state.uioh#
key key mask
5867 let birdseyekeyboard key mask
5868 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5870 match conf.columns
with
5872 | Cmulti
((c, _, _), _) -> c
5873 | Csplit
_ -> failwith
"bird's eye split mode"
5875 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5877 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5878 let y, h = getpageyh pageno in
5879 let top = (state.winh
- h) / 2 in
5880 gotoy (max
0 (y - top))
5881 | 0xff0d (* enter *)
5882 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5883 | 0xff1b -> leavebirdseye beye
true (* escape *)
5884 | 0xff52 -> upbirdseye incr beye
(* up *)
5885 | 0xff54 -> downbirdseye incr beye
(* down *)
5886 | 0xff51 -> upbirdseye 1 beye
(* left *)
5887 | 0xff53 -> downbirdseye 1 beye
(* right *)
5889 | 0xff55 -> (* prior *)
5890 begin match state.layout with
5894 state.mode <- Birdseye
(
5895 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5897 gotopage1 l.pageno 0;
5900 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5902 | [] -> gotoy (clamp (-state.winh
))
5904 state.mode <- Birdseye
(
5905 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5907 gotopage1 l.pageno 0
5910 | [] -> gotoy (clamp (-state.winh
))
5913 | 0xff56 -> (* next *)
5914 begin match List.rev
state.layout with
5916 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5917 begin match layout with
5919 let incr = l.pageh
- l.pagevh in
5924 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5926 G.postRedisplay "birdseye pagedown";
5928 else gotoy (clamp (incr + conf.interpagespace
*2));
5932 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5933 gotopage1 l.pageno 0;
5936 | [] -> gotoy (clamp state.winh
)
5939 | 0xff50 -> (* home *)
5940 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5943 | 0xff57 -> (* end *)
5944 let pageno = state.pagecount
- 1 in
5945 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5946 if not
(pagevisible state.layout pageno)
5949 match List.rev
state.pdims
with
5951 | (_, _, h, _) :: _ -> h
5953 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5954 else G.postRedisplay "birdseye end";
5955 | _ -> viewkeyboard key mask
5960 match state.mode with
5961 | Textentry
_ -> scalecolor 0.4
5963 | View
-> scalecolor 1.0
5964 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5965 if l.pageno = hooverpageno
5968 if l.pageno = pageno
5976 let postdrawpage l linkindexbase
=
5977 match getopaque l.pageno with
5979 if tileready l l.pagex
l.pagey
5981 let x = l.pagedispx - l.pagex
5982 and y = l.pagedispy - l.pagey in
5984 match conf.columns
with
5985 | Csingle
_ | Cmulti
_ ->
5986 (if conf.hlinks
then 1 else 0)
5988 && not
(isbirdseye state.mode) then 2 else 0)
5992 match state.mode with
5993 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5996 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
6001 let scrollindicator () =
6002 let sbw, ph
, sh = state.uioh#
scrollph in
6003 let sbh, pw, sw = state.uioh#scrollpw
in
6005 GlDraw.color (0.64, 0.64, 0.64);
6007 (float (state.winw
- sbw), 0.)
6008 (float state.winw
, float state.winh
)
6011 (0., float (state.winh
- sbh))
6012 (float (wadjsb state.winw
- 1), float state.winh
)
6014 GlDraw.color (0.0, 0.0, 0.0);
6017 (float (state.winw
- sbw), ph
)
6018 (float state.winw
, ph
+. sh)
6021 (pw, float (state.winh
- sbh))
6022 (pw +. sw, float state.winh
)
6027 match state.mstate
with
6028 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
6031 | Msel
((x0, y0), (x1, y1)) ->
6032 let rec loop = function
6034 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
6035 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
6036 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
6037 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
6039 match getopaque l.pageno with
6041 let x0, y0 = pagetranslatepoint l x0 y0 in
6042 let x1, y1 = pagetranslatepoint l x1 y1 in
6043 seltext opaque
(x0, y0, x1, y1);
6051 let showrects rects
=
6053 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
6054 GlDraw.polygon_mode `both `fill
;
6055 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6057 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
6059 if l.pageno = pageno
6061 let dx = float (l.pagedispx - l.pagex
) in
6062 let dy = float (l.pagedispy - l.pagey) in
6063 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
6064 GlDraw.begins `quads
;
6066 GlDraw.vertex2
(x0+.dx, y0+.dy);
6067 GlDraw.vertex2
(x1+.dx, y1+.dy);
6068 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
6069 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
6080 GlClear.color (scalecolor2 conf.bgcolor
);
6081 GlClear.clear
[`
color];
6082 List.iter
drawpage state.layout;
6084 match state.mode with
6085 | LinkNav
(Ltexact
(pageno, linkno
)) ->
6086 begin match getopaque pageno with
6088 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
6095 | None
-> state.rects
6100 let rec postloop linkindexbase
= function
6102 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
6103 postloop linkindexbase rest
6107 postloop 0 state.layout;
6109 begin match state.mstate
with
6110 | Mzoomrect
((x0, y0), (x1, y1)) ->
6112 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
6113 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6114 GlDraw.rect (float x0, float y0)
6115 (float x1, float y1);
6124 let zoomrect x y x1 y1 =
6127 and y0 = min
y y1 in
6128 gotoy (state.y + y0);
6129 state.anchor <- getanchor ();
6130 let zoom = (float state.w) /. float (x1 - x0) in
6132 match conf.fitmodel
, conf.columns
with
6133 | FitPage
, Csplit
_ ->
6134 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6137 let adjw = wadjsb state.winw
in
6139 then (adjw - state.w) / 2
6142 state.x <- (state.x + margin) - x0;
6144 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6145 state.mstate
<- Mnone
;
6149 let g opaque
l px py =
6150 match rectofblock opaque
px py with
6152 let x0 = a.(0) -. 20. in
6153 let x1 = a.(1) +. 20. in
6154 let y0 = a.(2) -. 20. in
6155 let zoom = (float state.w) /. (x1 -. x0) in
6156 let pagey = getpagey l.pageno in
6157 gotoy_and_clear_text (pagey + truncate
y0);
6158 state.anchor <- getanchor ();
6159 let margin = (state.w - l.pagew
)/2 in
6160 state.x <- -truncate
x0 - margin;
6165 match conf.columns
with
6167 showtext '
!'
"block zooming does not work properly in split columns mode"
6168 | _ -> onppundermouse g x y ()
6172 let winw = wadjsb state.winw - 1 in
6173 let s = float x /. float winw in
6174 let destx = truncate
(float (state.w + winw) *. s) in
6175 state.x <- winw - destx;
6176 gotoy_and_clear_text state.y;
6177 state.mstate
<- Mscrollx
;
6181 let s = float y /. float state.winh
in
6182 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6183 gotoy_and_clear_text desty;
6184 state.mstate
<- Mscrolly
;
6187 let viewmouse button down
x y mask
=
6189 | n when (n == 4 || n == 5) && not down
->
6190 if Wsi.withctrl mask
6192 match state.mstate
with
6193 | Mzoom
(oldn
, i
) ->
6201 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6203 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6205 let zoom = conf.zoom -. incr in
6207 state.mstate
<- Mzoom
(n, 0);
6209 state.mstate
<- Mzoom
(n, i
+1);
6211 else state.mstate
<- Mzoom
(n, 0)
6213 | _ -> state.mstate
<- Mzoom
(n, 0)
6216 match state.autoscroll
with
6217 | Some step
-> setautoscrollspeed step
(n=4)
6219 if conf.wheelbypage
|| conf.presentation
6228 then -conf.scrollstep
6229 else conf.scrollstep
6231 let incr = incr * 2 in
6232 let y = clamp incr in
6233 gotoy_and_clear_text y
6236 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6238 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6239 gotoy_and_clear_text state.y
6241 | 1 when Wsi.withshift mask
->
6242 state.mstate
<- Mnone
;
6245 match unproject x y with
6246 | Some
(pageno, ux
, uy
) ->
6247 let cmd = Printf.sprintf
6249 conf.stcmd
state.path pageno ux uy
6255 | 1 when Wsi.withctrl mask
->
6258 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6259 state.mstate
<- Mpan
(x, y)
6262 state.mstate
<- Mnone
6267 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6269 state.mstate
<- Mzoomrect
(p, p)
6272 match state.mstate
with
6273 | Mzoomrect
((x0, y0), _) ->
6274 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6275 then zoomrect x0 y0 x y
6277 state.mstate
<- Mnone
;
6278 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6279 G.postRedisplay "kill accidental zoom rect";
6282 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6283 state.mstate
<- Mnone
6286 | 1 when x > state.winw - vscrollw () ->
6289 let _, position, sh = state.uioh#
scrollph in
6290 if y > truncate
position && y < truncate
(position +. sh)
6291 then state.mstate
<- Mscrolly
6294 state.mstate
<- Mnone
6296 | 1 when y > state.winh
- hscrollh () ->
6299 let _, position, sw = state.uioh#scrollpw
in
6300 if x > truncate
position && x < truncate
(position +. sw)
6301 then state.mstate
<- Mscrollx
6304 state.mstate
<- Mnone
6306 | 1 when state.bzoom
-> if not down
then zoomblock x y
6309 let dest = if down
then getunder x y else Unone
in
6310 begin match dest with
6313 | Uremote
_ | Uremotedest
_
6314 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6317 | Unone
when down
->
6318 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6319 state.mstate
<- Mpan
(x, y);
6321 | Unone
| Utext
_ ->
6324 if conf.angle
mod 360 = 0
6326 state.mstate
<- Msel
((x, y), (x, y));
6327 G.postRedisplay "mouse select";
6331 match state.mstate
with
6334 | Mzoom
_ | Mscrollx
| Mscrolly
->
6335 state.mstate
<- Mnone
6337 | Mzoomrect
((x0, y0), _) ->
6341 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6342 state.mstate
<- Mnone
6344 | Msel
((x0, y0), (x1, y1)) ->
6345 let rec loop = function
6349 let a0 = l.pagedispy in
6350 let a1 = a0 + l.pagevh in
6351 let b0 = l.pagedispx in
6352 let b1 = b0 + l.pagevw in
6353 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6354 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6358 match getopaque l.pageno with
6361 match Ne.pipe () with
6365 "can not create sel pipe: %s"
6368 let doclose what fd
=
6369 Ne.clo fd
(fun msg
->
6370 dolog
"%s close failed: %s" what msg
)
6373 popen conf.selcmd
[r, 0; w, -1];
6374 copysel
w opaque
true;
6376 G.postRedisplay "copysel";
6378 dolog
"can not execute %S: %s"
6379 conf.selcmd
(exntos exn
);
6387 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6388 state.mstate
<- Mnone
;
6395 let birdseyemouse button down
x y mask
6396 (conf, leftx
, _, hooverpageno
, anchor) =
6399 let rec loop = function
6402 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6403 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6405 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6411 | _ -> viewmouse button down
x y mask
6414 let mouse button down
x y mask
=
6415 state.uioh <- state.uioh#button button down
x y mask
;
6419 state.uioh <- state.uioh#
motion x y
6423 state.uioh <- state.uioh#
pmotion x y;
6429 method key key mask
=
6430 begin match state.mode with
6431 | Textentry
textentry -> textentrykeyboard key mask
textentry
6432 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6433 | View
-> viewkeyboard key mask
6434 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6438 method button button bstate
x y mask
=
6439 begin match state.mode with
6441 | View
-> viewmouse button bstate
x y mask
6442 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6448 begin match state.mode with
6450 | View
| Birdseye
_ | LinkNav
_ ->
6451 match state.mstate
with
6452 | Mzoom
_ | Mnone
-> ()
6457 state.mstate
<- Mpan
(x, y);
6459 then state.x <- panbound (state.x + dx);
6461 gotoy_and_clear_text y
6464 state.mstate
<- Msel
(a, (x, y));
6465 G.postRedisplay "motion select";
6468 let y = min
state.winh
(max
0 y) in
6472 let x = min
state.winw (max
0 x) in
6475 | Mzoomrect
(p0
, _) ->
6476 state.mstate
<- Mzoomrect
(p0
, (x, y));
6477 G.postRedisplay "motion zoomrect";
6481 method pmotion x y =
6482 begin match state.mode with
6483 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6484 let rec loop = function
6486 if hooverpageno
!= -1
6488 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6489 G.postRedisplay "pmotion birdseye no hoover";
6492 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6493 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6495 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6496 G.postRedisplay "pmotion birdseye hoover";
6506 match state.mstate
with
6507 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6514 let past, _, _ = !r in
6516 let delta = now -. past in
6519 else r := (now, x, y)
6523 method infochanged
_ = ()
6526 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6529 then 0.0, float state.winh
6530 else scrollph state.y maxy
6535 let winw = wadjsb state.winw in
6536 let fwinw = float winw in
6538 let sw = fwinw /. float state.w in
6539 let sw = fwinw *. sw in
6540 max
sw (float conf.scrollh
)
6543 let maxx = state.w + winw in
6544 let x = winw - state.x in
6545 let percent = float x /. float maxx in
6546 (fwinw -. sw) *. percent
6548 hscrollh (), position, sw
6552 match state.mode with
6553 | LinkNav
_ -> "links"
6554 | Textentry
_ -> "textentry"
6555 | Birdseye
_ -> "birdseye"
6558 findkeyhash conf modename
6560 method eformsgs
= true
6567 let fontpath = ref "";;
6570 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6573 let l = String.length
s in
6574 let b = Buffer.create
l in
6580 try Sys.getenv
"HOME"
6583 ("Can not determine home directory location: " ^ exntos exn
);
6587 let modifier_of_string = function
6588 | "alt" -> Wsi.altmask
6589 | "shift" -> Wsi.shiftmask
6590 | "ctrl" | "control" -> Wsi.ctrlmask
6591 | "meta" -> Wsi.metamask
6596 let r = Str.regexp
"-" in
6598 let elems = Str.full_split
r s in
6601 let m1 = modifier_of_string s in
6603 then (Wsi.namekey
s, m)
6606 | Str.Delim
s when n land 1 = 0 -> g s
6608 | Str.Delim
_ -> (k
, m)
6610 let rec loop n k
m = function
6613 let k, m = f n k m x in
6619 let keys_of_string =
6620 let r = Str.regexp
"[ \t]" in
6622 let elems = Str.split
r s in
6623 List.map
key_of_string elems
6626 let copykeyhashes c =
6627 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6630 let config_of c attrs
=
6634 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6635 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6636 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6637 | "preload" -> { c with preload = bool_of_string
v }
6638 | "page-bias" -> { c with pagebias
= int_of_string
v }
6639 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6640 | "horizontal-scroll-step" ->
6641 { c with hscrollstep
= max
(int_of_string
v) 1 }
6642 | "auto-scroll-step" ->
6643 { c with autoscrollstep
= max
0 (int_of_string
v) }
6644 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6645 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6648 match String.lowercase
v with
6649 | "true" -> Some infinity
6651 | f -> Some
(float_of_string
f)
6653 { c with maxwait
= mw}
6654 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6655 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6656 | "vertical-margin" ->
6657 { c with interpagespace
= max
0 (int_of_string
v) }
6659 let zoom = float_of_string
v /. 100. in
6660 let zoom = max
zoom 0.0 in
6661 { c with zoom = zoom }
6662 | "presentation" -> { c with presentation
= bool_of_string
v }
6663 | "rotation-angle" -> { c with angle
= int_of_string
v }
6664 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6665 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6666 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6667 | "proportional-display" ->
6670 then FitProportional
6673 { c with fitmodel
= fm }
6674 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6675 | "pixmap-cache-size" ->
6676 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6677 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6678 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6679 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6680 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6681 | "background-color" -> { c with bgcolor
= color_of_string v }
6682 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6683 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6684 | "mupdf-store-size" ->
6685 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6686 | "checkers" -> { c with checkers
= bool_of_string
v }
6687 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6688 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6689 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6690 | "uri-launcher" -> { c with urilauncher
= unent v }
6691 | "path-launcher" -> { c with pathlauncher
= unent v }
6692 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6693 | "invert-colors" -> { c with invert
= bool_of_string
v }
6694 | "brightness" -> { c with colorscale
= float_of_string
v }
6695 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6697 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6699 let (n, _, _) as nab
= multicolumns_of_string v in
6701 then { c with columns
= Csplit
(-n, [||]) }
6702 else { c with columns
= Cmulti
(nab
, [||]) }
6703 | "birds-eye-columns" ->
6704 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6705 | "selection-command" -> { c with selcmd
= unent v }
6706 | "synctex-command" -> { c with stcmd
= unent v }
6707 | "pax-command" -> { c with paxcmd
= unent v }
6708 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6709 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6710 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6711 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6712 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6713 | "horizontal-scrollbar-visible" ->
6716 then c.scrollb
lor scrollbhv
6717 else c.scrollb
land (lnot
scrollbhv)
6719 { c with scrollb
= b }
6720 | "vertical-scrollbar-visible" ->
6723 then c.scrollb
lor scrollbvv
6724 else c.scrollb
land (lnot
scrollbvv)
6726 { c with scrollb
= b }
6727 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6731 then Some
(ref (0.0, 0, 0))
6733 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6736 prerr_endline
("Error processing attribute (`" ^
6737 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6740 let rec fold c = function
6743 let c = apply c k v in
6746 fold { c with keyhashes
= copykeyhashes c } attrs
;
6749 let fromstring f pos
n v d =
6752 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6753 n v pos
(exntos exn
)
6758 let bookmark_of attrs
=
6759 let rec fold title page
rely visy
= function
6760 | ("title", v) :: rest
-> fold v page
rely visy rest
6761 | ("page", v) :: rest
-> fold title v rely visy rest
6762 | ("rely", v) :: rest
-> fold title page
v visy rest
6763 | ("visy", v) :: rest
-> fold title page
rely v rest
6764 | _ :: rest
-> fold title page
rely visy rest
6765 | [] -> title, page
, rely, visy
6767 fold "invalid" "0" "0" "0" attrs
6771 let rec fold path page
rely pan visy
= function
6772 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6773 | ("page", v) :: rest
-> fold path v rely pan visy rest
6774 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6775 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6776 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6777 | _ :: rest
-> fold path page
rely pan visy rest
6778 | [] -> path, page
, rely, pan
, visy
6780 fold "" "0" "0" "0" "0" attrs
6784 let rec fold rs ls
= function
6785 | ("out", v) :: rest
-> fold v ls rest
6786 | ("in", v) :: rest
-> fold rs
v rest
6787 | _ :: rest
-> fold ls rs rest
6793 let setconf dst
src =
6794 dst
.scrollbw
<- src.scrollbw
;
6795 dst
.scrollh
<- src.scrollh
;
6796 dst
.icase
<- src.icase
;
6797 dst
.preload <- src.preload;
6798 dst
.pagebias
<- src.pagebias
;
6799 dst
.verbose
<- src.verbose
;
6800 dst
.scrollstep
<- src.scrollstep
;
6801 dst
.maxhfit
<- src.maxhfit
;
6802 dst
.crophack
<- src.crophack
;
6803 dst
.autoscrollstep
<- src.autoscrollstep
;
6804 dst
.maxwait
<- src.maxwait
;
6805 dst
.hlinks
<- src.hlinks
;
6806 dst
.underinfo
<- src.underinfo
;
6807 dst
.interpagespace
<- src.interpagespace
;
6808 dst
.zoom <- src.zoom;
6809 dst
.presentation
<- src.presentation
;
6810 dst
.angle
<- src.angle
;
6811 dst
.cwinw
<- src.cwinw
;
6812 dst
.cwinh
<- src.cwinh
;
6813 dst
.savebmarks
<- src.savebmarks
;
6814 dst
.memlimit
<- src.memlimit
;
6815 dst
.fitmodel
<- src.fitmodel
;
6816 dst
.texcount
<- src.texcount
;
6817 dst
.sliceheight
<- src.sliceheight
;
6818 dst
.thumbw
<- src.thumbw
;
6819 dst
.jumpback
<- src.jumpback
;
6820 dst
.bgcolor
<- src.bgcolor
;
6821 dst
.tilew
<- src.tilew
;
6822 dst
.tileh
<- src.tileh
;
6823 dst
.mustoresize
<- src.mustoresize
;
6824 dst
.checkers
<- src.checkers
;
6825 dst
.aalevel
<- src.aalevel
;
6826 dst
.trimmargins
<- src.trimmargins
;
6827 dst
.trimfuzz
<- src.trimfuzz
;
6828 dst
.urilauncher
<- src.urilauncher
;
6829 dst
.colorspace
<- src.colorspace
;
6830 dst
.invert
<- src.invert
;
6831 dst
.colorscale
<- src.colorscale
;
6832 dst
.redirectstderr <- src.redirectstderr;
6833 dst
.ghyllscroll
<- src.ghyllscroll
;
6834 dst
.columns
<- src.columns
;
6835 dst
.beyecolumns
<- src.beyecolumns
;
6836 dst
.selcmd
<- src.selcmd
;
6837 dst
.updatecurs
<- src.updatecurs
;
6838 dst
.pathlauncher
<- src.pathlauncher
;
6839 dst
.keyhashes
<- copykeyhashes src;
6840 dst
.hfsize
<- src.hfsize
;
6841 dst
.hscrollstep
<- src.hscrollstep
;
6842 dst
.pgscale <- src.pgscale;
6843 dst
.usepbo
<- src.usepbo
;
6844 dst
.wheelbypage
<- src.wheelbypage
;
6845 dst
.stcmd
<- src.stcmd
;
6846 dst
.paxcmd
<- src.paxcmd
;
6847 dst
.scrollb
<- src.scrollb
;
6848 dst
.riani
<- src.riani
;
6849 dst
.paxmark
<- src.paxmark
;
6853 else Some
((ref (0.0, 0, 0)));
6857 let h = Hashtbl.create
10 in
6858 let dc = { defconf with angle
= defconf.angle
} in
6859 let rec toplevel v t spos
_ =
6861 | Vdata
| Vcdata
| Vend
-> v
6862 | Vopen
("llppconfig", _, closed
) ->
6865 else { v with f = llppconfig
}
6867 error
"unexpected subelement at top level" s spos
6868 | Vclose
_ -> error
"unexpected close at top level" s spos
6870 and llppconfig
v t spos
_ =
6872 | Vdata
| Vcdata
-> v
6873 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6874 | Vopen
("defaults", attrs
, closed
) ->
6875 let c = config_of dc attrs
in
6879 else { v with f = defaults
}
6881 | Vopen
("ui-font", attrs
, closed
) ->
6882 let rec getsize size
= function
6884 | ("size", v) :: rest
->
6886 fromstring int_of_string spos
"size" v fstate.fontsize
in
6888 | l -> getsize size l
6890 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6893 else { v with f = uifont
(Buffer.create
10) }
6895 | Vopen
("doc", attrs
, closed
) ->
6896 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6897 let path = unent pathent
6898 and pageno = fromstring int_of_string spos
"page" spage
0
6899 and rely = fromstring float_of_string spos
"rely" srely
0.0
6900 and pan
= fromstring int_of_string spos
"pan" span
0
6901 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6902 let c = config_of dc attrs
in
6903 let anchor = (pageno, rely, visy
) in
6905 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6906 else { v with f = doc
path pan
anchor c [] }
6909 error
"unexpected subelement in llppconfig" s spos
6911 | Vclose
"llppconfig" -> { v with f = toplevel }
6912 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6914 and defaults
v t spos
_ =
6916 | Vdata
| Vcdata
-> v
6917 | Vend
-> error
"unexpected end of input in defaults" s spos
6918 | Vopen
("keymap", attrs
, closed
) ->
6920 try List.assoc
"mode" attrs
6921 with Not_found
-> "global" in
6926 let h = findkeyhash dc modename in
6927 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6930 { v with f = pkeymap
ret KeyMap.empty }
6932 | Vopen
(_, _, _) ->
6933 error
"unexpected subelement in defaults" s spos
6935 | Vclose
"defaults" ->
6936 { v with f = llppconfig
}
6938 | Vclose
_ -> error
"unexpected close in defaults" s spos
6940 and uifont
b v t spos
epos =
6943 Buffer.add_substring
b s spos
(epos - spos
);
6945 | Vopen
(_, _, _) ->
6946 error
"unexpected subelement in ui-font" s spos
6947 | Vclose
"ui-font" ->
6948 if emptystr
!fontpath
6949 then fontpath := Buffer.contents
b;
6950 { v with f = llppconfig
}
6951 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6952 | Vend
-> error
"unexpected end of input in ui-font" s spos
6954 and doc
path pan
anchor c bookmarks
v t spos
_ =
6956 | Vdata
| Vcdata
-> v
6957 | Vend
-> error
"unexpected end of input in doc" s spos
6958 | Vopen
("bookmarks", _, closed
) ->
6961 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6963 | Vopen
("keymap", attrs
, closed
) ->
6965 try List.assoc
"mode" attrs
6966 with Not_found
-> "global"
6972 let h = findkeyhash c modename in
6973 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6974 doc
path pan
anchor c bookmarks
6976 { v with f = pkeymap
ret KeyMap.empty }
6978 | Vopen
(_, _, _) ->
6979 error
"unexpected subelement in doc" s spos
6982 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6983 { v with f = llppconfig
}
6985 | Vclose
_ -> error
"unexpected close in doc" s spos
6987 and pkeymap
ret keymap
v t spos
_ =
6989 | Vdata
| Vcdata
-> v
6990 | Vend
-> error
"unexpected end of input in keymap" s spos
6991 | Vopen
("map", attrs
, closed
) ->
6992 let r, l = map_of attrs
in
6993 let kss = fromstring keys_of_string spos
"in" r [] in
6994 let lss = fromstring keys_of_string spos
"out" l [] in
6998 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6999 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
7002 then { v with f = pkeymap
ret keymap }
7005 { v with f = skip
"map" f }
7008 error
"unexpected subelement in keymap" s spos
7010 | Vclose
"keymap" ->
7011 { v with f = ret keymap }
7013 | Vclose
_ -> error
"unexpected close in keymap" s spos
7015 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
7017 | Vdata
| Vcdata
-> v
7018 | Vend
-> error
"unexpected end of input in bookmarks" s spos
7019 | Vopen
("item", attrs
, closed
) ->
7020 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
7021 let page = fromstring int_of_string spos
"page" spage
0
7022 and rely = fromstring float_of_string spos
"rely" srely
0.0
7023 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7025 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
7028 then { v with f = pbookmarks
path pan
anchor c bookmarks }
7031 { v with f = skip
"item" f }
7034 error
"unexpected subelement in bookmarks" s spos
7036 | Vclose
"bookmarks" ->
7037 { v with f = doc
path pan
anchor c bookmarks }
7039 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
7041 and skip tag
f v t spos
_ =
7043 | Vdata
| Vcdata
-> v
7045 error
("unexpected end of input in skipped " ^ tag
) s spos
7046 | Vopen
(tag'
, _, closed
) ->
7050 let f'
() = { v with f = skip tag
f } in
7051 { v with f = skip tag'
f'
}
7055 else error
("unexpected close in skipped " ^ tag
) s spos
7058 parse
{ f = toplevel; accu = () } s;
7064 let len = in_channel_length ic
in
7065 let s = String.create
len in
7066 really_input ic
s 0 len;
7069 | Parse_error
(msg
, s, pos
) ->
7070 let subs = subs s pos
in
7071 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
7074 failwith
("config load error: " ^ exntos exn
)
7080 let dir = Filename.concat
home ".config" in
7081 if Sys.is_directory
dir then dir else home
7084 Filename.concat
dir "llpp.conf"
7087 let confpath = ref defconfpath;;
7090 if Sys.file_exists
!confpath
7093 (try Some
(open_in_bin
!confpath)
7096 ("Error opening configuration file `" ^
!confpath ^
"': " ^
7107 ("Error loading configuration from `" ^
!confpath ^
"': " ^
7116 f (Hashtbl.create
0, defconf)
7121 let pc, pb
, px, pa
=
7124 if emptystr
state.origin
7128 Hashtbl.find h (Filename.basename
key)
7129 with Not_found
-> dc, [], 0, emptyanchor
7133 state.bookmarks <- pb
;
7136 then state.anchor <- pa
;
7137 cbput state.hists
.nav pa
;
7143 let add_attrs bb always
dc c =
7146 then Printf.bprintf bb
"\n %s='%b'" s a
7149 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7152 then Printf.bprintf bb
"\n %s='%d'" s a
7155 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7158 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7161 then Printf.bprintf bb
"\n %s='%f'" s a
7165 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7169 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7173 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7177 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7183 | Some
(_N
, _A
, _B
) ->
7184 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7194 else string_of_float
f
7196 Printf.bprintf bb
"\n %s='%s'" s v
7201 | Cmulti
((n, a, b), _) when n > 1 ->
7202 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7203 | Csplit
(n, _) when n > 1 ->
7204 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7210 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7215 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7219 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7223 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7225 oi
"width" c.cwinw
dc.cwinw
;
7226 oi
"height" c.cwinh
dc.cwinh
;
7227 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7228 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7229 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7230 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7231 ob "case-insensitive-search" c.icase
dc.icase
;
7232 ob "preload" c.preload dc.preload;
7233 oi
"page-bias" c.pagebias
dc.pagebias
;
7234 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7235 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7236 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7237 ob "crop-hack" c.crophack
dc.crophack
;
7238 oW
"throttle" c.maxwait
dc.maxwait
;
7239 ob "highlight-links" c.hlinks
dc.hlinks
;
7240 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7241 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7242 oz
"zoom" c.zoom dc.zoom;
7243 ob "presentation" c.presentation
dc.presentation
;
7244 oi
"rotation-angle" c.angle
dc.angle
;
7245 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7246 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7247 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7248 oi
"tex-count" c.texcount
dc.texcount
;
7249 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7250 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7251 ob "persistent-location" c.jumpback
dc.jumpback
;
7252 oc
"background-color" c.bgcolor
dc.bgcolor
;
7253 oi
"tile-width" c.tilew
dc.tilew
;
7254 oi
"tile-height" c.tileh
dc.tileh
;
7255 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7256 ob "checkers" c.checkers
dc.checkers
;
7257 oi
"aalevel" c.aalevel
dc.aalevel
;
7258 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7259 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7260 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7261 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7262 oC
"color-space" c.colorspace
dc.colorspace
;
7263 ob "invert-colors" c.invert
dc.invert
;
7264 oF
"brightness" c.colorscale
dc.colorscale
;
7265 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7266 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7267 oco
"columns" c.columns
dc.columns
;
7268 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7269 os
"selection-command" c.selcmd
dc.selcmd
;
7270 os
"synctex-command" c.stcmd
dc.stcmd
;
7271 os
"pax-command" c.paxcmd
dc.paxcmd
;
7272 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7273 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7274 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7275 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7276 ob "use-pbo" c.usepbo
dc.usepbo
;
7277 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7278 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7279 op
"point-and-x" c.pax
dc.pax
;
7280 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7283 let keymapsbuf always
dc c =
7284 let bb = Buffer.create
16 in
7285 let rec loop = function
7287 | (modename, h) :: rest
->
7288 let dh = findkeyhash dc modename in
7289 if always
|| h <> dh
7291 if Hashtbl.length
h > 0
7293 if Buffer.length
bb > 0
7294 then Buffer.add_char
bb '
\n'
;
7295 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7296 Hashtbl.iter
(fun i
o ->
7297 let isdifferent = always
||
7299 let dO = Hashtbl.find dh i
in
7301 with Not_found
-> true
7306 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7307 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7308 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7309 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7310 Buffer.add_string
bb (Wsi.keyname
k);
7313 let rec loop = function
7315 | km
:: [] -> addkm km
7316 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7320 Buffer.add_string
bb "<map in='";
7324 Buffer.add_string
bb "' out='";
7326 Buffer.add_string
bb "'/>\n"
7329 Buffer.add_string
bb "' out='";
7331 Buffer.add_string
bb "'/>\n"
7333 | KMmulti
(ins, kms
) ->
7334 Buffer.add_char
bb ' '
;
7336 Buffer.add_string
bb "' out='";
7338 Buffer.add_string
bb "'/>\n"
7340 Buffer.add_string
bb "</keymap>";
7350 let uifontsize = fstate.fontsize
in
7351 let bb = Buffer.create
32768 in
7352 let relx = float state.x /. float state.winw in
7354 let cx w = truncate
(relx *. float w) in
7356 (fun (w, h, x) ws
->
7358 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7359 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7360 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7362 (state.winw, state.winh
, state.x) state.winstate
7367 let dc = if conf.bedefault
then conf else dc in
7368 Buffer.add_string
bb "<llppconfig>\n";
7370 if nonemptystr
!fontpath
7372 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7378 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7381 Buffer.add_string
bb "<defaults ";
7382 add_attrs bb true dc dc;
7383 let kb = keymapsbuf true dc dc in
7384 if Buffer.length
kb > 0
7386 Buffer.add_string
bb ">\n";
7387 Buffer.add_buffer
bb kb;
7388 Buffer.add_string
bb "\n</defaults>\n";
7390 else Buffer.add_string
bb "/>\n";
7392 let adddoc path pan
anchor c bookmarks =
7393 if bookmarks == [] && c = dc && anchor = emptyanchor
7396 Printf.bprintf
bb "<doc path='%s'"
7397 (enent
path 0 (String.length
path));
7399 if anchor <> emptyanchor
7401 let n, rely, visy
= anchor in
7402 Printf.bprintf
bb " page='%d'" n;
7405 Printf.bprintf
bb " rely='%f'" rely
7407 if abs_float visy
> 1e-6
7409 Printf.bprintf
bb " visy='%f'" visy
7414 then Printf.bprintf
bb " pan='%d'" pan
;
7416 add_attrs bb false dc c;
7417 let kb = keymapsbuf false dc c in
7419 begin match bookmarks with
7421 if Buffer.length
kb > 0
7423 Buffer.add_string
bb ">\n";
7424 Buffer.add_buffer
bb kb;
7425 Buffer.add_string
bb "\n</doc>\n";
7427 else Buffer.add_string
bb "/>\n"
7429 Buffer.add_string
bb ">\n<bookmarks>\n";
7430 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7432 "<item title='%s' page='%d'"
7433 (enent
title 0 (String.length
title))
7438 Printf.bprintf
bb " rely='%f'" rely
7440 if abs_float visy
> 1e-6
7442 Printf.bprintf
bb " visy='%f'" visy
7444 Buffer.add_string
bb "/>\n";
7446 Buffer.add_string
bb "</bookmarks>";
7447 if Buffer.length
kb > 0
7449 Buffer.add_string
bb "\n";
7450 Buffer.add_buffer
bb kb;
7452 Buffer.add_string
bb "\n</doc>\n";
7458 match state.mode with
7459 | Birdseye
(c, pan, _, _, _) ->
7461 match conf.columns
with
7462 | Cmulti
((c, _, _), _) -> Some
c
7466 match c.columns
with
7467 | Cmulti
(c, _) -> Cmulti
(c, [||])
7468 | Csingle
_ -> Csingle
[||]
7469 | Csplit
_ -> failwith
"quit from bird's eye while split"
7471 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7474 let basename = Filename.basename
7475 (if emptystr
state.origin
then state.path else state.origin
)
7477 adddoc basename pan (getanchor ())
7479 let autoscrollstep =
7480 match state.autoscroll
with
7482 | None
-> conf.autoscrollstep
7484 match state.mode with
7485 | Birdseye
(bc
, _, _, _, _) ->
7488 presentation
= bc
.presentation
;
7489 interpagespace
= bc
.interpagespace
;
7490 maxwait
= bc
.maxwait
;
7491 autoscrollstep = autoscrollstep }
7492 | _ -> { conf with autoscrollstep = autoscrollstep }
7494 (if conf.savebmarks
then state.bookmarks else []);
7496 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7498 then adddoc path x anchor c bookmarks
7500 Buffer.add_string
bb "</llppconfig>\n";
7503 if load1 f && Buffer.length
bb > 0
7506 let tmp = !confpath ^
".tmp" in
7507 let oc = open_out_bin
tmp in
7508 Buffer.output_buffer
oc bb;
7510 Unix.rename
tmp !confpath;
7513 ("error while saving configuration: " ^ exntos exn
)
7517 let adderrmsg src msg
=
7518 Buffer.add_string
state.errmsgs msg
;
7519 state.newerrmsgs
<- true;
7523 let adderrfmt src fmt
=
7524 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7528 let cl = splitatspace cmds
in
7530 try Scanf.sscanf
s fmt
f
7532 adderrfmt "remote exec"
7533 "error processing '%S': %s\n" cmds
(exntos exn
)
7536 | "reload" :: [] -> reload ()
7537 | "goto" :: args :: [] ->
7538 scan args "%u %f %f"
7540 let cmd, _ = state.geomcmds
in
7542 then gotopagexy pageno x y
7545 gotopagexy pageno x y;
7548 state.reprf
<- f state.reprf
7550 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7551 | "rect" :: args :: [] ->
7552 scan args "%u %u %f %f %f %f"
7553 (fun pageno color x0 y0 x1 y1 ->
7554 onpagerect pageno (fun w h ->
7555 let _,w1,h1
,_ = getpagedim pageno in
7556 let sw = float w1 /. float w
7557 and sh = float h1
/. float h in
7561 and y1s
= y1 *. sh in
7562 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7564 state.rects <- (pageno, color, rect) :: state.rects;
7565 G.postRedisplay "rect";
7568 | "activatewin" :: [] -> Wsi.activatewin
()
7569 | "quit" :: [] -> raise Quit
7571 adderrfmt "remote command"
7572 "error processing remote command: %S\n" cmds
;
7576 let scratch = String.create
80 in
7577 let buf = Buffer.create
80 in
7580 try Some
(Unix.read fd
scratch 0 80)
7582 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7583 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7586 match tempfr () with
7592 if Buffer.length
buf > 0
7594 let s = Buffer.contents
buf in
7604 let pos = String.index_from
scratch ppos '
\n'
in
7605 if pos >= n then -1 else pos
7606 with Not_found
-> -1
7610 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7611 let s = Buffer.contents
buf in
7617 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7623 let remoteopen path =
7624 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7626 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7631 let trimcachepath = ref "" in
7632 let rcmdpath = ref "" in
7633 selfexec := Sys.executable_name
;
7636 [("-p", Arg.String
(fun s -> state.password
<- s),
7637 "<password> Set password");
7641 Config.fontpath := s;
7642 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7644 "<path> Set path to the user interface font");
7648 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7649 Config.confpath := s),
7650 "<path> Set path to the configuration file");
7652 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7653 "<path> Set path to the trim cache file");
7655 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7656 "<named-destination> Set named destination");
7658 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7659 ("-cxack", Arg.Set
cxack, " Cut corners");
7661 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7662 "<path> Set path to the remote commands source");
7664 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7665 "<original-path> Set original path");
7667 ("-v", Arg.Unit
(fun () ->
7669 "%s\nconfiguration path: %s\n"
7673 exit
0), " Print version and exit");
7676 (fun s -> state.path <- s)
7677 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7680 then selfexec := !selfexec ^
" -wtmode";
7682 if emptystr
state.path
7683 then (prerr_endline
"file name missing"; exit
1);
7685 if not
(Config.load ())
7686 then prerr_endline
"failed to load configuration";
7688 let wsfd, winw, winh
= Wsi.init
(object
7689 val mutable m_hack
= false
7690 method expose
= if not m_hack
then G.postRedisplay "expose"
7691 method visible
= G.postRedisplay "visible"
7692 method display = m_hack
<- false; display ()
7693 method reshape w h =
7694 m_hack
<- w < state.winw && h < state.winh
;
7696 method mouse b d x y m = mouse b d x y m
7697 method motion x y = state.mpos
<- (x, y); motion x y
7698 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7700 let mascm = m land (
7701 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7703 match state.keystate
with
7705 let km = k, mascm in
7708 let modehash = state.uioh#
modehash in
7709 try Hashtbl.find modehash km
7711 try Hashtbl.find (findkeyhash conf "global") km
7712 with Not_found
-> KMinsrt
(k, m)
7714 | KMinsrt
(k, m) -> keyboard k m
7715 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7716 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7718 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7719 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7720 state.keystate
<- KSnone
7721 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7722 state.keystate
<- KSinto
(keys
, insrt
)
7724 state.keystate
<- KSnone
7726 method enter
x y = state.mpos
<- (x, y); pmotion x y
7727 method leave = state.mpos
<- (-1, -1)
7728 method winstate wsl
= state.winstate
<- wsl
; m_hack
<- false
7729 method quit
= raise Quit
7730 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7735 List.exists
GlMisc.check_extension
7736 [ "GL_ARB_texture_rectangle"
7737 ; "GL_EXT_texture_recangle"
7738 ; "GL_NV_texture_rectangle" ]
7740 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7743 let r = GlMisc.get_string `renderer
in
7744 let p = "Mesa DRI Intel(" in
7745 let l = String.length
p in
7746 String.length
r > l && String.sub
r 0 l = p
7749 defconf.sliceheight
<- 1024;
7750 defconf.texcount
<- 32;
7751 defconf.usepbo
<- true;
7755 match Ne.pipe () with
7757 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7761 match Ne.pipe () with
7763 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7773 setcheckers conf.checkers
;
7775 if conf.redirectstderr
7778 let s = Buffer.contents
state.errmsgs ^
7779 (match state.errfd
with
7781 let s = String.create
(80*24) in
7784 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
7786 then Unix.read fd
s 0 (String.length
s)
7792 else String.sub
s 0 n
7796 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
7797 with exn
-> print_endline
(exntos exn
)
7802 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7803 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7804 !Config.fontpath, !trimcachepath,
7805 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7809 state.text <- "Opening " ^
(mbtoutf8
state.path);
7811 opendoc state.path state.password
;
7815 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7818 if nonemptystr
!rcmdpath
7819 then remoteopen !rcmdpath
7824 let rec loop deadline
=
7826 match state.errfd
with
7827 | None
-> [state.sr
; state.wsfd]
7828 | Some fd
-> [state.sr
; state.wsfd; fd
]
7833 | Some fd
-> fd
:: r
7837 state.redisplay
<- false;
7844 if deadline
= infinity
7846 else max
0.0 (deadline
-. now)
7851 try Unix.select
r [] [] timeout
7852 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7858 if state.ghyll
== noghyll
7860 match state.autoscroll
with
7861 | Some step
when step
!= 0 ->
7862 let y = state.y + step
in
7866 else if y >= state.maxy then 0 else y
7869 if state.mode = View
7870 then state.text <- "";
7873 else deadline
+. 0.01
7878 let rec checkfds = function
7880 | fd
:: rest
when fd
= state.sr
->
7881 let cmd = readcmd state.sr
in
7885 | fd
:: rest
when fd
= state.wsfd ->
7889 | fd
:: rest
when Some fd
= !optrfd ->
7890 begin match remote fd
with
7891 | None
-> optrfd := remoteopen !rcmdpath;
7892 | opt -> optrfd := opt
7897 let s = String.create
80 in
7898 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7899 if conf.redirectstderr
7901 Buffer.add_substring
state.errmsgs
s 0 n;
7902 state.newerrmsgs
<- true;
7903 state.redisplay
<- true;
7906 prerr_string
(String.sub
s 0 n);
7914 if deadline
= infinity
7918 match state.autoscroll
with
7919 | Some step
when step
!= 0 -> deadline1
7920 | _ -> if state.ghyll
== noghyll then infinity
else deadline1