6 | Ulinkgoto
of (int * int)
8 | Uunexpected
of string
11 | Uremote
of (string * int)
12 and facename
= string;;
14 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
15 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* fontpath
* trimcachepath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
36 and trimcachepath
= string
39 and irect
= (int * int * int * int)
40 and trimparams
= (trimmargins
* irect
)
41 and colorspace
= | Rgb
| Bgr
| Gray
50 | LDfirstvisible
of (int * int * int)
65 | KMmulti
of key list
* key list
67 and keyhash
= (key
, keymap
) Hashtbl.t
70 | KSinto
of (key list
* key list
)
73 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
74 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
76 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
78 external init
: pipe
-> params
-> unit = "ml_init";;
79 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
80 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
81 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
82 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
83 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
84 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
85 external measurestr
: int -> string -> float = "ml_measure_string";;
86 external getmaxw
: unit -> float = "ml_getmaxw";;
87 external postprocess
:
88 opaque
-> int -> int -> int -> (int * string * int) -> int = "ml_postprocess";;
89 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
90 external platform
: unit -> platform
= "ml_platform";;
91 external setaalevel
: int -> unit = "ml_setaalevel";;
92 external realloctexts
: int -> bool = "ml_realloctexts";;
93 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
94 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
95 external getlink
: opaque
-> int -> under
= "ml_getlink";;
96 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
97 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
98 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
99 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
101 let platform_to_string = function
102 | Punknown
-> "unknown"
106 | Pfreebsd
-> "FreeBSD"
107 | Pdragonflybsd
-> "DragonflyBSD"
108 | Popenbsd
-> "OpenBSD"
109 | Pnetbsd
-> "NetBSD"
110 | Pcygwin
-> "Cygwin"
113 let platform = platform ();;
116 if platform = Pcygwin
118 let sh = "/bin/sh" in
119 let args = [|sh; "-c"; cmd
|] in
120 let rec std si so se
= function
122 | (fd
, 0) :: rest
-> std fd so se rest
123 | (fd
, -1) :: rest
->
124 Unix.set_close_on_exec fd
;
127 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
129 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
130 ignore
(Unix.create_process
sh args si so se
)
139 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
142 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
144 type mpos
= int * int
146 | Msel
of (mpos
* mpos
)
148 | Mscrolly
| Mscrollx
149 | Mzoom
of (int * int)
150 | Mzoomrect
of (mpos
* mpos
)
154 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
155 and onkey
= string -> int -> te
156 and ondone
= string -> unit
157 and histcancel
= unit -> unit
158 and onhist
= ((histcmd
-> string) * histcancel
)
159 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
160 and cancelonempty
= bool
165 | TEswitch
of textentry
176 let bound v minv maxv
=
177 max minv
(min maxv v
);
181 { store
= Array.create n v
188 let drawstring size x y s
=
190 Gl.enable `texture_2d
;
191 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
192 ignore
(drawstr size x y s
);
194 Gl.disable `texture_2d
;
197 let drawstring1 size x y s
=
201 let drawstring2 size x y fmt
=
202 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
205 let cbcap b
= Array.length b
.store
;;
210 b
.wc
<- (b
.wc
+ 1) mod cap;
212 b
.len
<- min
(b
.len
+ 1) cap;
215 let cbempty b
= b
.len
= 0;;
217 let cbgetg b circular dir
=
221 let rc = b
.rc + dir
in
233 else max
0 (min
rc (b
.len
-1))
239 let cbget b
= cbgetg b
false;;
240 let cbgetc b
= cbgetg b
true;;
258 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
259 dolog " WxH %dx%d" l
.pagew l
.pageh
;
260 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
261 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
262 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
263 dolog " column %d" l
.pagecol
;
267 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
269 dolog " x0,y0=(% f, % f)" x0 y0
;
270 dolog " x1,y1=(% f, % f)" x1 y1
;
271 dolog " x2,y2=(% f, % f)" x2 y2
;
272 dolog " x3,y3=(% f, % f)" x3 y3
;
276 type multicolumns
= multicol
* pagegeom
277 and splitcolumns
= columncount
* pagegeom
278 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
279 and multicol
= columncount
* covercount
* covercount
281 and columncount
= int
282 and covercount
= int;;
285 { mutable scrollbw
: int
286 ; mutable scrollh
: int
287 ; mutable icase
: bool
288 ; mutable preload
: bool
289 ; mutable pagebias
: int
290 ; mutable verbose
: bool
291 ; mutable debug
: bool
292 ; mutable scrollstep
: int
293 ; mutable hscrollstep
: int
294 ; mutable maxhfit
: bool
295 ; mutable crophack
: bool
296 ; mutable autoscrollstep
: int
297 ; mutable maxwait
: float option
298 ; mutable hlinks
: bool
299 ; mutable underinfo
: bool
300 ; mutable interpagespace
: interpagespace
301 ; mutable zoom
: float
302 ; mutable presentation
: bool
303 ; mutable angle
: angle
306 ; mutable savebmarks
: bool
307 ; mutable proportional
: proportional
308 ; mutable trimmargins
: trimmargins
309 ; mutable trimfuzz
: irect
310 ; mutable memlimit
: memsize
311 ; mutable texcount
: texcount
312 ; mutable sliceheight
: sliceheight
313 ; mutable thumbw
: width
314 ; mutable jumpback
: bool
315 ; mutable bgcolor
: float * float * float
316 ; mutable bedefault
: bool
317 ; mutable scrollbarinpm
: bool
318 ; mutable tilew
: int
319 ; mutable tileh
: int
320 ; mutable mustoresize
: memsize
321 ; mutable checkers
: bool
322 ; mutable aalevel
: int
323 ; mutable urilauncher
: string
324 ; mutable pathlauncher
: string
325 ; mutable colorspace
: colorspace
326 ; mutable invert
: bool
327 ; mutable colorscale
: float
328 ; mutable redirectstderr
: bool
329 ; mutable ghyllscroll
: (int * int * int) option
330 ; mutable columns
: columns
331 ; mutable beyecolumns
: columncount
option
332 ; mutable selcmd
: string
333 ; mutable updatecurs
: bool
334 ; mutable keyhashes
: (string * keyhash
) list
335 ; mutable hfsize
: int
336 ; mutable pgscale
: float
340 | Cmulti
of multicolumns
341 | Csplit
of splitcolumns
344 type anchor
= pageno
* top
;;
346 type outline
= string * int * anchor
;;
348 type rect
= float * float * float * float * float * float * float * float;;
350 type tile
= opaque
* pixmapsize
* elapsed
351 and elapsed
= float;;
352 type pagemapkey
= pageno
* gen
;;
353 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
357 let emptyanchor = (0, 0.0);;
359 type infochange
= | Memused
| Docinfo
| Pdim
;;
361 class type uioh
= object
362 method display
: unit
363 method key
: int -> int -> uioh
364 method button
: int -> bool -> int -> int -> int -> uioh
365 method motion
: int -> int -> uioh
366 method pmotion
: int -> int -> uioh
367 method infochanged
: infochange
-> unit
368 method scrollpw
: (int * float * float)
369 method scrollph
: (int * float * float)
370 method modehash
: keyhash
374 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
375 | Textentry
of (textentry
* onleave
)
377 | LinkNav
of linktarget
378 and onleave
= leavetextentrystatus
-> unit
379 and leavetextentrystatus
= | Cancel
| Confirm
380 and helpitem
= string * int * action
383 | Action
of (uioh
-> uioh
)
385 | Ltexact
of (pageno
* int)
389 let isbirdseye = function Birdseye _
-> true | _
-> false;;
390 let istextentry = function Textentry _
-> true | _
-> false;;
394 | Loading
of (page
* gen
)
396 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
398 | Outlining
of outline list
401 let emptykeyhash = Hashtbl.create
0;;
402 let nouioh : uioh
= object (self
)
404 method key _ _
= self
405 method button _ _ _ _ _
= self
406 method motion _ _
= self
407 method pmotion _ _
= self
408 method infochanged _
= ()
409 method scrollpw
= (0, nan
, nan
)
410 method scrollph
= (0, nan
, nan
)
411 method modehash
= emptykeyhash
415 { mutable sr
: Unix.file_descr
416 ; mutable sw
: Unix.file_descr
417 ; mutable wsfd
: Unix.file_descr
418 ; mutable errfd
: Unix.file_descr
option
419 ; mutable stderr
: Unix.file_descr
420 ; mutable errmsgs
: Buffer.t
421 ; mutable newerrmsgs
: bool
425 ; mutable scrollw
: int
426 ; mutable hscrollh
: int
427 ; mutable anchor
: anchor
428 ; mutable ranchors
: (string * string * anchor
) list
430 ; mutable layout
: page list
431 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
432 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
433 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
434 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
435 ; mutable pagecount
: int
436 ; mutable currently
: currently
437 ; mutable mstate
: mstate
438 ; mutable searchpattern
: string
439 ; mutable rects
: (pageno
* recttype
* rect
) list
440 ; mutable rects1
: (pageno
* recttype
* rect
) list
441 ; mutable text
: string
442 ; mutable fullscreen
: (width
* height
) option
443 ; mutable mode
: mode
444 ; mutable uioh
: uioh
445 ; mutable outlines
: outline array
446 ; mutable bookmarks
: outline list
447 ; mutable path
: string
448 ; mutable password
: string
449 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
450 ; mutable memused
: memsize
452 ; mutable throttle
: (page list
* int * float) option
453 ; mutable autoscroll
: int option
454 ; mutable ghyll
: (int option -> unit)
455 ; mutable help
: helpitem array
456 ; mutable docinfo
: (int * string) list
457 ; mutable texid
: GlTex.texture_id
option
459 ; mutable prevzoom
: float
460 ; mutable progress
: float
461 ; mutable redisplay
: bool
462 ; mutable mpos
: mpos
463 ; mutable keystate
: keystate
464 ; mutable glinks
: bool
465 ; mutable prevcolumns
: (columns
* float) option
468 { pat
: string circbuf
469 ; pag
: string circbuf
470 ; nav
: anchor circbuf
471 ; sel
: string circbuf
493 ; presentation
= false
498 ; proportional
= true
499 ; trimmargins
= false
500 ; trimfuzz
= (0,0,0,0)
501 ; memlimit
= 32 lsl 20
506 ; bgcolor
= (0.5, 0.5, 0.5)
508 ; scrollbarinpm
= true
511 ; mustoresize
= 256 lsl 20
516 | Plinux
| Pfreebsd
| Pdragonflybsd
517 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
518 | Posx
-> "open \"%s\""
519 | Pcygwin
-> "cygstart \"%s\""
520 | Punknown
-> "echo %s")
521 ; pathlauncher
= "lp \"%s\""
524 | Plinux
| Pfreebsd
| Pdragonflybsd
525 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
532 ; redirectstderr
= false
540 let mk n
= (n
, Hashtbl.create
1) in
554 let findkeyhash c name
=
555 try List.assoc name c
.keyhashes
556 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
559 let conf = { defconf with angle
= defconf.angle
};;
561 let pgscale h
= truncate
(float h
*. conf.pgscale);;
564 { mutable fontsize
: int
565 ; mutable wwidth
: float
566 ; mutable maxrows
: int
578 fstate.fontsize
<- n
;
579 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
580 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
584 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
585 let len = String.length s
in
586 if colonpos >= 0 && colonpos + 3 < len
588 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
591 try String.rindex_from s
colonpos ' '
595 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
598 | "http" | "ftp" | "mailto" ->
600 try String.index_from s
colonpos ' '
601 with Not_found
-> len
603 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
611 if String.length
conf.urilauncher
= 0
612 then print_endline uri
614 let url = geturl uri
in
615 if String.length
url = 0
616 then print_endline uri
618 let re = Str.regexp
"%s" in
619 let command = Str.global_replace
re url conf.urilauncher
in
623 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
629 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
630 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
634 let strings = version () :: "" :: Help.keys
in
637 let url = geturl s
in
638 if String.length
url > 0
639 then (s
, 0, Action
(fun u
-> gotouri url; u
))
640 else (s
, 0, Noaction
)
645 let firstgeomcmds = "", [];;
652 ; stderr
= Unix.stderr
653 ; errmsgs
= Buffer.create
0
660 ; anchor
= emptyanchor
664 ; tilelru
= Queue.create
()
665 ; pagemap
= Hashtbl.create
10
666 ; tilemap
= Hashtbl.create
10
681 ; geomcmds
= firstgeomcmds
683 { nav
= cbnew 10 (0, 0.0)
710 Printf.kprintf prerr_endline fmt
712 Printf.kprintf ignore fmt
716 if String.length
conf.pathlauncher
= 0
717 then print_endline
state.path
719 let re = Str.regexp
"%s" in
720 let command = Str.global_replace
re state.path
conf.pathlauncher
in
724 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
730 type 'a t
= | Res
of 'a
| Exn
of exn
;;
733 try Res
(Unix.pipe ())
739 with exn
-> f
(Printexc.to_string exn
)
743 try Res
(Unix.dup fd
)
748 try Res
(Unix.dup2 fd1 fd2
)
753 let redirectstderr () =
754 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
755 if conf.redirectstderr
757 match Ne.pipe () with
759 dolog "failed to create stderr redirection pipes: %s"
760 (Printexc.to_string exn
)
763 begin match Ne.dup Unix.stderr
with
765 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
766 Ne.clo r
(clofail "pipe/r");
767 Ne.clo w
(clofail "pipe/w");
769 | Ne.Res dupstderr
->
770 begin match Ne.dup2 w
Unix.stderr
with
772 dolog "failed to dup2 to stderr: %s"
773 (Printexc.to_string exn
);
774 Ne.clo dupstderr
(clofail "stderr duplicate");
775 Ne.clo r
(clofail "redir pipe/r");
776 Ne.clo w
(clofail "redir pipe/w");
779 state.stderr
<- dupstderr
;
780 state.errfd
<- Some r
;
784 state.newerrmsgs
<- false;
785 begin match state.errfd
with
787 begin match Ne.dup2 state.stderr
Unix.stderr
with
789 dolog "failed to dup2 original stderr: %s"
790 (Printexc.to_string exn
)
792 Ne.clo fd
(clofail "dup of stderr");
793 Unix.dup2 state.stderr
Unix.stderr
;
798 prerr_string
(Buffer.contents
state.errmsgs
);
800 Buffer.clear
state.errmsgs
;
806 let postRedisplay who
=
808 then prerr_endline
("redisplay for " ^ who
);
809 state.redisplay
<- true;
813 let getopaque pageno
=
814 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
815 with Not_found
-> None
818 let putopaque pageno opaque
=
819 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
822 let pagetranslatepoint l x y
=
823 let dy = y
- l
.pagedispy
in
824 let y = dy + l
.pagey
in
825 let dx = x
- l
.pagedispx
in
826 let x = dx + l
.pagex
in
833 begin match getopaque l
.pageno
with
835 let x0 = l
.pagedispx
in
836 let x1 = x0 + l
.pagevw
in
837 let y0 = l
.pagedispy
in
838 let y1 = y0 + l
.pagevh
in
839 if y >= y0 && y <= y1 && x >= x0 && x <= x1
841 let px, py
= pagetranslatepoint l
x y in
842 match whatsunder opaque
px py
with
855 state.text
<- Printf.sprintf
"%c%s" c s
;
856 G.postRedisplay "showtext";
859 let undertext = function
862 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
863 | Utext s
-> "font: " ^ s
864 | Uunexpected s
-> "unexpected: " ^ s
865 | Ulaunch s
-> "launch: " ^ s
866 | Unamed s
-> "named: " ^ s
867 | Uremote
(filename
, pageno
) ->
868 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
871 let updateunder x y =
872 match getunder x y with
873 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
875 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
876 Wsi.setcursor
Wsi.CURSOR_INFO
877 | Ulinkgoto
(pageno
, _
) ->
879 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
880 Wsi.setcursor
Wsi.CURSOR_INFO
882 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
883 Wsi.setcursor
Wsi.CURSOR_TEXT
885 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
886 Wsi.setcursor
Wsi.CURSOR_INHERIT
888 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
889 Wsi.setcursor
Wsi.CURSOR_INHERIT
891 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
892 Wsi.setcursor
Wsi.CURSOR_INHERIT
893 | Uremote
(filename
, pageno
) ->
894 if conf.underinfo
then showtext 'r'
895 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
896 Wsi.setcursor
Wsi.CURSOR_INFO
899 let showlinktype under
=
905 let s = undertext under
in
910 let b = Buffer.create
(String.length
s + 1) in
911 Buffer.add_string
b s;
916 let colorspace_of_string s =
917 match String.lowercase
s with
921 | _
-> failwith
"invalid colorspace"
924 let int_of_colorspace = function
930 let colorspace_of_int = function
934 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
937 let colorspace_to_string = function
943 let intentry_with_suffix text key
=
945 if key
>= 32 && key
< 127
949 match Char.lowercase
c with
951 let text = addchar text c in
955 let text = addchar text c in
959 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
963 let multicolumns_to_string (n
, a
, b) =
965 then Printf.sprintf
"%d" n
966 else Printf.sprintf
"%d,%d,%d" n a
b;
969 let multicolumns_of_string s =
971 (int_of_string
s, 0, 0)
973 Scanf.sscanf
s "%u,%u,%u" (fun n a
b -> (n
, a
, b));
978 let n = Unix.read fd
s 0 4 in
979 if n != 4 then failwith
"incomplete read(len)";
981 lor (Char.code
s.[0] lsl 24)
982 lor (Char.code
s.[1] lsl 16)
983 lor (Char.code
s.[2] lsl 8)
984 lor (Char.code
s.[3] lsl 0)
986 let s = String.create
len in
987 let n = Unix.read fd
s 0 len in
988 if n != len then failwith
"incomplete read(data)";
992 let btod b = if b then 1 else 0;;
995 let b = Buffer.create
16 in
996 Buffer.add_string
b "llll";
999 let s = Buffer.contents
b in
1000 let n = String.length
s in
1002 (* dolog "wcmd %S" (String.sub s 4 len); *)
1003 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1004 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1005 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1006 s.[3] <- Char.chr
(len land 0xff);
1007 let n'
= Unix.write
state.sw
s 0 n in
1008 if n'
!= n then failwith
"write failed";
1013 if conf.presentation
1015 let d = conf.winh
- h
in
1016 max
conf.interpagespace
((d + 1) / 2)
1022 let rec f pn ph pi fh l
=
1024 | (n, _
, h
, _
) :: rest
->
1025 let ips = calcips h
in
1027 if conf.presentation
1030 if isbirdseye state.mode
&& pn
= 0
1035 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
1040 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
1044 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
1047 let fh = f 0 0 0 0 state.pdims
in
1052 match conf.columns
with
1053 | Csingle
-> calcheight ()
1054 | Cmulti
((c, _
, _
), b) ->
1055 let rec loop y h
n =
1059 if n = Array.length
b
1062 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
1068 loop max_int
0 (((Array.length
b - 1) / c) * c)
1070 if Array.length
b > 0
1072 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1077 let getpageyh pageno
=
1078 let rec f pn ph pi
y l
=
1080 | (n, _
, h
, _
) :: rest
->
1081 let ips = calcips h
in
1084 let h = if n = pageno
then h else ph
in
1085 if conf.presentation
&& n = pageno
1087 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
1089 y + (pageno
- pn
) * (ph
+ pi
), h
1091 let y = y + (if conf.presentation
then pi
else 0) in
1092 let y = y + (n - pn
) * (ph
+ pi
) in
1096 y + (pageno
- pn
) * (ph
+ pi
), ph
1098 f 0 0 0 0 state.pdims
1101 let getpageyh pageno
=
1102 match conf.columns
with
1103 | Csingle
-> getpageyh pageno
1105 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1109 let (_
, _
, y, (_
, _
, h, _
)) = b.(n) in
1113 let getpagedim pageno
=
1116 | (n, _
, _
, _
) as pdim
:: rest
->
1118 then (if n = pageno
then pdim
else ppdim
)
1123 f (-1, -1, -1, -1) state.pdims
1126 let getpagey pageno
= fst
(getpageyh pageno
);;
1128 let nogeomcmds cmds
=
1130 | s, [] -> String.length
s = 0
1135 let sh = sh - state.hscrollh
in
1136 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1137 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1139 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1140 let ips = calcips h in
1142 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1146 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1148 prev
, pdims
, pdimno
, 0
1150 let dy = dy + yinc in
1151 let py = py + yinc in
1152 if pageno
= state.pagecount
|| dy >= sh
1157 if py + h <= vy - yinc
1159 let py = py + h + ips in
1160 let dy = max
0 (py - y) in
1161 f ~pageno
:(pageno
+1)
1169 let pagey = vy - py in
1170 let pagevh = h - pagey in
1171 let pagevh = min
(sh - dy) pagevh in
1172 let off = if yinc > 0 then py - vy else 0 in
1173 let py = py + h + ips in
1176 if state.w
< conf.winw
- state.scrollw
1177 then (conf.winw
- state.scrollw
- state.w
) / 2
1180 let dispx = xoff + state.x in
1186 let lw = w
- pagex in
1187 min
lw (conf.winw
- state.scrollw
)
1191 ; pagedimno
= pdimno
1195 ; pagey = pagey + off
1197 ; pagevh = pagevh - off
1199 ; pagedispy
= dy + off
1203 let accu = e :: accu in
1204 f ~pageno
:(pageno
+1)
1225 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1226 let sh = sh - state.hscrollh
in
1227 let rec fold accu n =
1228 if n = Array.length
b
1231 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1234 || n = state.pagecount
- coverB
1235 || (n - coverA
) mod columns
= columns
- 1)
1241 let pagey = max
0 (y - vy) in
1242 let pagedispy = if pagey > 0 then 0 else vy - y in
1243 let pagedispx, pagex =
1245 if n = coverA
- 1 || n = state.pagecount
- coverB
1246 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1247 else dx + xoff + state.x
1254 let vw = conf.winw
- state.scrollw
- pagedispx in
1255 let pw = w
- pagex in
1258 let pagevh = min
(h - pagey) (sh - pagedispy) in
1259 if pagevw > 0 && pagevh > 0
1263 ; pagedimno
= pdimno
1270 ; pagedispx = pagedispx
1271 ; pagedispy = pagedispy
1283 List.rev
(fold [] 0)
1286 let layoutS (columns
, b) y sh =
1287 let sh = sh - state.hscrollh
in
1288 let rec fold accu n =
1289 if n = Array.length
b
1292 let pdimno, px, vy, (_
, pagew
, pageh
, xoff) = b.(n) in
1299 let x = xoff + state.x in
1300 let pagey = max
0 (y - vy) in
1301 let pagedispy = if pagey > 0 then 0 else vy - y in
1302 let pagedispx, pagex =
1316 let pagecolw = pagew
/columns
in
1318 if pagecolw < conf.winw
1319 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1323 let vw = conf.winw
- pagedispx - state.scrollw
in
1324 let pw = pagew
- pagex in
1327 let pagevw = min
pagevw pagecolw in
1328 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1329 if pagevw > 0 && pagevh > 0
1332 { pageno
= n/columns
1333 ; pagedimno
= pdimno
1340 ; pagedispx = pagedispx
1341 ; pagedispy = pagedispy
1342 ; pagecol
= n mod columns
1353 List.rev
(fold [] 0)
1357 if nogeomcmds state.geomcmds
1359 match conf.columns
with
1360 | Csingle
-> layout1 y sh
1361 | Cmulti
c -> layoutN c y sh
1362 | Csplit
s -> layoutS s y sh
1367 let y = state.y + incr
in
1369 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1374 let tilex = l
.pagex mod conf.tilew
in
1375 let tiley = l
.pagey mod conf.tileh
in
1377 let col = l
.pagex / conf.tilew
in
1378 let row = l
.pagey / conf.tileh
in
1380 let rec rowloop row y0 dispy
h =
1384 let dh = conf.tileh
- y0 in
1385 let dh = min
h dh in
1386 let rec colloop col x0 dispx w
=
1390 let dw = conf.tilew
- x0 in
1391 let dw = min w
dw in
1393 f col row dispx dispy
x0 y0 dw dh;
1394 colloop (col+1) 0 (dispx+dw) (w
-dw)
1397 colloop col tilex l
.pagedispx l
.pagevw;
1398 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1401 if l
.pagevw > 0 && l
.pagevh > 0
1402 then rowloop row tiley l
.pagedispy l
.pagevh;
1405 let gettileopaque l
col row =
1407 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1409 try Some
(Hashtbl.find
state.tilemap
key)
1410 with Not_found
-> None
1413 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1414 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1415 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1418 let drawtiles l color
=
1420 let f col row x y tilex tiley w
h =
1421 match gettileopaque l
col row with
1422 | Some
(opaque
, _
, t
) ->
1423 let params = x, y, w
, h, tilex, tiley in
1427 GlFunc.blend_func `zero `one_minus_src_color
;
1429 drawtile
params opaque
;
1431 then Gl.disable `blend
;
1434 let s = Printf.sprintf
1438 let w = measurestr
fstate.fontsize
s in
1439 GlMisc.push_attrib
[`current
];
1440 GlDraw.color
(0.0, 0.0, 0.0);
1442 (float (x-2), float (y-2))
1443 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1444 GlDraw.color
(1.0, 1.0, 1.0);
1445 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1446 GlMisc.pop_attrib
();
1451 let lw = conf.winw
- state.scrollw
- x in
1454 let lh = conf.winh
- y in
1457 begin match state.texid
with
1459 Gl.enable `texture_2d
;
1460 GlTex.bind_texture `texture_2d id
;
1463 and x1 = float (x+w)
1464 and y1 = float (y+h) in
1466 let tw = float w /. 64.0
1467 and th
= float h /. 64.0 in
1468 let tx0 = float tilex /. 64.0
1469 and ty0
= float tiley /. 64.0 in
1471 and ty1
= ty0
+. th
in
1472 GlDraw.begins `quads
;
1473 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1474 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1475 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1476 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1479 Gl.disable `texture_2d
;
1481 GlDraw.color
(1.0, 1.0, 1.0);
1484 (float (x+w), float (y+h));
1486 if w > 128 && h > fstate.fontsize
+ 10
1488 GlDraw.color
(0.0, 0.0, 0.0);
1491 then (col*conf.tilew
, row*conf.tileh
)
1494 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1501 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1503 let tilevisible1 l
x y =
1505 and ax1
= l
.pagex + l
.pagevw
1507 and ay1
= l
.pagey + l
.pagevh in
1511 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1512 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1514 let rx0 = max
ax0 bx0
1515 and ry0
= max ay0 by0
1516 and rx1
= min ax1
bx1
1517 and ry1
= min ay1 by1
in
1519 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1520 nonemptyintersection
1523 let tilevisible layout n x y =
1524 let rec findpageinlayout m
= function
1525 | l
:: rest
when l
.pageno
= n ->
1526 tilevisible1 l
x y || (
1527 match conf.columns
with
1528 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1531 | _
:: rest
-> findpageinlayout 0 rest
1534 findpageinlayout 0 layout;
1537 let tileready l
x y =
1538 tilevisible1 l
x y &&
1539 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1542 let tilepage n p
layout =
1543 let rec loop = function
1547 let f col row _ _ _ _ _ _
=
1548 if state.currently
= Idle
1550 match gettileopaque l
col row with
1553 let x = col*conf.tilew
1554 and y = row*conf.tileh
in
1556 let w = l
.pagew
- x in
1560 let h = l
.pageh
- y in
1563 wcmd "tile %s %d %d %d %d" p
x y w h;
1566 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1567 conf.tilew
, conf.tileh
1576 if nogeomcmds state.geomcmds
1580 let preloadlayout visiblepages
=
1581 let presentation = conf.presentation in
1582 let interpagespace = conf.interpagespace in
1583 conf.presentation <- false;
1584 conf.interpagespace <- 0;
1586 match visiblepages
with
1587 | [] -> if state.y >= state.maxy
then state.maxy
else 0
1588 | l
:: _
-> getpagey l
.pageno
+ (l
.pagey - min
0 l
.pagedispy)
1590 let y = if y < conf.winh
then 0 else y - conf.winh
in
1591 let h = conf.winh
*3 in
1592 let pages = layout y h in
1593 conf.presentation <- presentation;
1594 conf.interpagespace <- interpagespace;
1599 let rec loop pages =
1600 if state.currently
!= Idle
1605 begin match getopaque l
.pageno
with
1607 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1608 state.currently
<- Loading
(l
, state.gen
);
1610 tilepage l
.pageno opaque
pages;
1615 if nogeomcmds state.geomcmds
1621 if conf.preload && state.currently
= Idle
1622 then load (preloadlayout pages);
1625 let layoutready layout =
1626 let rec fold all ls
=
1627 all
&& match ls
with
1629 let seen = ref false in
1630 let allvisible = ref true in
1631 let foo col row _ _ _ _ _ _
=
1633 allvisible := !allvisible &&
1634 begin match gettileopaque l
col row with
1640 fold (!seen && !allvisible) rest
1643 let alltilesvisible = fold true layout in
1648 let y = bound y 0 state.maxy
in
1649 let y, layout, proceed
=
1650 match conf.maxwait
with
1651 | Some time
when state.ghyll
== noghyll ->
1652 begin match state.throttle
with
1654 let layout = layout y conf.winh
in
1655 let ready = layoutready layout in
1659 state.throttle
<- Some
(layout, y, now ());
1661 else G.postRedisplay "gotoy showall (None)";
1663 | Some
(_
, _
, started
) ->
1664 let dt = now () -. started
in
1667 state.throttle
<- None
;
1668 let layout = layout y conf.winh
in
1670 G.postRedisplay "maxwait";
1677 let layout = layout y conf.winh
in
1678 if true || layoutready layout
1679 then G.postRedisplay "gotoy ready";
1685 state.layout <- layout;
1686 begin match state.mode
with
1687 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
1688 let rec loop = function
1690 state.mode
<- LinkNav
(Ltgendir
0)
1691 | l
:: _
when l
.pageno
= pageno
->
1692 begin match getopaque pageno
with
1694 state.mode
<- LinkNav
(Ltgendir
0)
1696 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1697 if not
(x0 >= l
.pagex && x1 <= l
.pagex + l
.pagevw
1698 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1699 then state.mode
<- LinkNav
(Ltgendir
0)
1701 | _
:: rest
-> loop rest
1706 begin match state.mode
with
1707 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1708 if not
(pagevisible layout pageno
)
1710 match state.layout with
1713 state.mode
<- Birdseye
(
1714 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1717 | LinkNav
(Ltgendir dir
as lt
) ->
1719 let rec loop = function
1722 match getopaque l
.pageno
with
1728 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1730 if dir
> 0 then LDfirst
else LDlast
1736 | Lnotfound
-> loop rest
1738 showlinktype (getlink opaque
n);
1739 Ltexact
(l
.pageno
, n)
1743 state.mode
<- LinkNav
linknav
1748 state.ghyll
<- noghyll;
1751 let mx, my
= state.mpos
in
1756 let conttiling pageno opaque
=
1757 tilepage pageno opaque
1758 (if conf.preload then preloadlayout state.layout else state.layout)
1761 let gotoy_and_clear_text y =
1762 if not
conf.verbose
then state.text <- "";
1767 match state.layout with
1770 let coloff = l
.pagecol
* l
.pageh
in
1772 (float (l
.pagey - l
.pagedispy) +. float coloff) /. float l
.pageh
)
1775 let getanchory (n, top
) =
1776 let y, h = getpageyh n in
1777 y + (truncate
(top
*. float h));
1780 let gotoanchor anchor
=
1781 gotoy (getanchory anchor
);
1785 cbput state.hists
.nav
(getanchor ());
1789 let anchor = cbgetc state.hists
.nav dir
in
1794 let scroll f n a
b =
1795 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1797 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1799 then s (float f /. float a
)
1802 then 1.0 -. s ((float (f-b) /. float (n-b)))
1809 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1810 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1812 let ins = float a
*. iv1
1813 and outs
= float (n-b) *. iv1 in
1815 ins +. outs
+. float ones
1817 let rec set (_N
, _A
, _B
) y sy
=
1818 let sum = summa
1.0 _N _A _B
in
1819 let dy = float (y - sy
) in
1823 then state.ghyll
<- noghyll
1826 let s = scroll n _N _A _B
in
1827 let y1 = y1 +. ((s *. dy) /. sum) in
1828 gotoy_and_clear_text (truncate
y1);
1829 state.ghyll
<- gf (n+1) y1;
1833 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1835 gf 0 (float state.y)
1838 match conf.ghyllscroll
with
1840 gotoy_and_clear_text y
1842 if state.ghyll
== noghyll
1843 then set nab
y state.y
1844 else state.ghyll
(Some
y)
1847 let gotopage n top
=
1848 let y, h = getpageyh n in
1849 let y = y + (truncate
(top
*. float h)) in
1853 let gotopage1 n top
=
1854 let y = getpagey n in
1859 let invalidate s f =
1864 match state.geomcmds
with
1865 | ps
, [] when String.length ps
= 0 ->
1867 state.geomcmds
<- s, [];
1870 state.geomcmds
<- ps
, [s, f];
1872 | ps
, (s'
, _
) :: rest
when s'
= s ->
1873 state.geomcmds
<- ps
, ((s, f) :: rest
);
1876 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1879 let opendoc path password
=
1881 state.password
<- password
;
1882 state.gen
<- state.gen
+ 1;
1883 state.docinfo
<- [];
1885 setaalevel
conf.aalevel
;
1886 Wsi.settitle
("llpp " ^
Filename.basename path
);
1887 wcmd "open %s\000%s\000" path password
;
1888 invalidate "reqlayout"
1890 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1894 let c = c *. conf.colorscale
in
1898 let scalecolor2 (r
, g
, b) =
1899 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1902 let docolumns = function
1905 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1906 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1907 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1908 let rec fixrow m
= if m
= pageno
then () else
1909 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1912 let y = y + (rowh
- h) / 2 in
1913 a.(m
) <- (pdimno, x, y, pdim
);
1917 if pageno
= state.pagecount
1918 then fixrow (((pageno
- 1) / columns
) * columns
)
1920 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1922 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1923 pdimno+1, pdim
, rest
1928 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1930 (conf.winw
- state.scrollw
- w) / 2,
1931 y + rowh
+ conf.interpagespace, h
1934 if (pageno
- coverA
) mod columns
= 0
1935 then 0, y + rowh
+ conf.interpagespace, h
1936 else x, y, max rowh
h
1939 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1940 then fixrow (pageno
- columns
);
1941 a.(pageno
) <- (pdimno, x, y, pdim
);
1942 let x = x + w + xoff*2 + conf.interpagespace in
1943 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1945 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1946 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1949 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1950 let rec loop pageno
pdimno pdim
y pdims
=
1951 if pageno
= state.pagecount
1954 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1956 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1957 pdimno+1, pdim
, rest
1962 let rec loop1 n x y =
1963 if n = c then y else (
1964 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1965 loop1 (n+1) (x+cw) (y + h + conf.interpagespace)
1968 let y = loop1 0 0 y in
1969 loop (pageno
+1) pdimno pdim
y pdims
1971 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1972 conf.columns
<- Csplit
(c, a);
1976 docolumns conf.columns
;
1977 state.maxy
<- calcheight ();
1979 if state.w <= conf.winw
- state.scrollw
1983 match state.mode
with
1984 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1985 let y, h = getpageyh pageno
in
1986 let top = (conf.winh
- h) / 2 in
1987 gotoy (max
0 (y - top))
1988 | _
-> gotoanchor state.anchor
1992 GlDraw.viewport
0 0 w h;
1993 let firsttime = state.geomcmds
== firstgeomcmds in
1994 if not
firsttime && nogeomcmds state.geomcmds
1995 then state.anchor <- getanchor ();
1998 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2001 setfontsize fstate.fontsize
;
2002 GlMat.mode `modelview
;
2003 GlMat.load_identity
();
2005 GlMat.mode `projection
;
2006 GlMat.load_identity
();
2007 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2008 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2009 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2014 else float state.x /. float state.w
2016 invalidate "geometry"
2020 then state.x <- truncate
(relx *. float w);
2022 match conf.columns
with
2024 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
2025 | Csplit
(c, _
) -> w * c
2027 wcmd "geometry %d %d" w h);
2031 let len = String.length
state.text in
2034 match state.mode
with
2037 let h, _
, _
= state.uioh#scrollpw
in
2043 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2044 (x+.w, float (conf.winh
- hscrollh))
2047 let w = float (conf.winw
- state.scrollw
- 1) in
2048 if state.progress
>= 0.0 && state.progress
< 1.0
2050 GlDraw.color
(0.3, 0.3, 0.3);
2051 let w1 = w *. state.progress
in
2053 GlDraw.color
(0.0, 0.0, 0.0);
2057 GlDraw.color
(0.0, 0.0, 0.0);
2061 GlDraw.color
(1.0, 1.0, 1.0);
2062 drawstring fstate.fontsize
2063 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2066 match state.mode
with
2067 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
2071 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2073 Printf.sprintf
"%s%s_" prefix
text
2082 if not
(istextentry state.mode
)
2084 let s1 = "(press 'e' to review error messasges)" in
2085 if String.length
s > 0 then s ^
" " ^
s1 else s1
2090 if String.length
s > 0
2095 let len = Queue.length
state.tilelru
in
2097 if state.memused
<= conf.memlimit
2102 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2103 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2104 let (_
, pw, ph
, _
) = getpagedim n in
2107 && colorspace
= conf.colorspace
2108 && angle
= conf.angle
2113 match state.throttle
with
2116 then preloadlayout state.layout
2118 | Some
(layout, _
, _
) ->
2121 let x = col*conf.tilew
2122 and y = row*conf.tileh
in
2123 tilevisible layout n x y
2125 then Queue.push lruitem
state.tilelru
2127 wcmd "freetile %s" p
;
2128 state.memused
<- state.memused
- s;
2129 state.uioh#infochanged Memused
;
2130 Hashtbl.remove
state.tilemap k
;
2139 Queue.iter
(fun (k
, p
, s) ->
2140 wcmd "freetile %s" p
;
2141 state.memused
<- state.memused
- s;
2142 state.uioh#infochanged Memused
;
2143 Hashtbl.remove
state.tilemap k
;
2145 Queue.clear
state.tilelru
;
2149 let logcurrently = function
2150 | Idle
-> dolog "Idle"
2151 | Loading
(l
, gen
) ->
2152 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2153 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2155 "Tiling %d[%d,%d] page=%s cs=%s angle"
2156 l
.pageno
col row pageopaque
2157 (colorspace_to_string colorspace
)
2159 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2160 angle gen
conf.angle
state.gen
2162 conf.tilew
conf.tileh
2169 (* dolog "%S" cmds; *)
2172 try String.index cmds ' '
2173 with Not_found
-> -1
2178 let l = String.length cmds
in
2179 let op = String.sub cmds
0 spacepos in
2181 if l - spacepos < 2 then ""
2182 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2187 state.uioh#infochanged Pdim
;
2191 state.rects
<- state.rects1
;
2192 G.postRedisplay "clearrects";
2196 try Scanf.sscanf
args "%u" (fun n -> n)
2198 dolog "error processing 'continue' %S: %s"
2199 cmds
(Printexc.to_string exn
);
2202 state.pagecount
<- n;
2203 begin match state.currently
with
2205 state.currently
<- Idle
;
2206 state.outlines
<- Array.of_list
(List.rev
l)
2210 let cur, cmds
= state.geomcmds
in
2211 if String.length
cur = 0
2212 then failwith
"umpossible";
2214 begin match List.rev cmds
with
2216 state.geomcmds
<- "", [];
2220 state.geomcmds
<- s, List.rev rest
;
2222 if conf.maxwait
= None
2223 then G.postRedisplay "continue";
2233 then showtext ' '
args
2236 let progress, text =
2238 Scanf.sscanf
args "%f %n"
2240 f, String.sub
args pos
(String.length
args - pos
))
2242 dolog "error processing 'progress' %S: %s"
2243 cmds
(Printexc.to_string exn
);
2247 state.progress <- progress;
2248 G.postRedisplay "progress"
2251 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2253 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2254 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2255 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2257 dolog "error processing 'firstmatch' %S: %s"
2258 cmds
(Printexc.to_string exn
);
2261 let y = (getpagey pageno) + truncate
y0 in
2264 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2267 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2269 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2270 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2271 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2273 dolog "error processing 'match' %S: %s"
2274 cmds
(Printexc.to_string exn
);
2278 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2283 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2285 dolog "error processing 'page' %S: %s"
2286 cmds
(Printexc.to_string exn
);
2289 begin match state.currently
with
2290 | Loading
(l, gen
) ->
2291 vlog "page %d took %f sec" l.pageno t
;
2292 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2293 begin match state.throttle
with
2295 let preloadedpages =
2297 then preloadlayout state.layout
2302 Set.Make
(struct type t
= int let compare = (-) end) in
2304 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2305 IntSet.empty
preloadedpages
2308 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2309 if not
(IntSet.mem
pageno set)
2311 wcmd "freepage %s" opaque
;
2317 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2320 state.currently
<- Idle
;
2323 tilepage l.pageno pageopaque state.layout;
2325 load preloadedpages;
2326 if pagevisible state.layout l.pageno
2327 && layoutready state.layout
2328 then G.postRedisplay "page";
2331 | Some
(layout, _
, _
) ->
2332 state.currently
<- Idle
;
2333 tilepage l.pageno pageopaque layout;
2338 dolog "Inconsistent loading state";
2339 logcurrently state.currently
;
2344 let (x, y, opaque
, size
, t
) =
2346 Scanf.sscanf
args "%u %u %s %u %f"
2347 (fun x y p size t
-> (x, y, p
, size
, t
))
2349 dolog "error processing 'tile' %S: %s"
2350 cmds
(Printexc.to_string exn
);
2353 begin match state.currently
with
2354 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2355 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2357 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2359 wcmd "freetile %s" opaque
;
2360 state.currently
<- Idle
;
2364 puttileopaque l col row gen cs angle opaque size t
;
2365 state.memused
<- state.memused
+ size
;
2366 state.uioh#infochanged Memused
;
2368 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2369 opaque
, size
) state.tilelru
;
2372 match state.throttle
with
2373 | None
-> state.layout
2374 | Some
(layout, _
, _
) -> layout
2377 state.currently
<- Idle
;
2379 && conf.colorspace
= cs
2380 && conf.angle
= angle
2381 && tilevisible layout l.pageno x y
2382 then conttiling l.pageno pageopaque;
2384 begin match state.throttle
with
2386 preload state.layout;
2388 && conf.colorspace
= cs
2389 && conf.angle
= angle
2390 && tilevisible state.layout l.pageno x y
2391 then G.postRedisplay "tile nothrottle";
2393 | Some
(layout, y, _
) ->
2394 let ready = layoutready layout in
2398 state.layout <- layout;
2399 state.throttle
<- None
;
2400 G.postRedisplay "throttle";
2407 dolog "Inconsistent tiling state";
2408 logcurrently state.currently
;
2415 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2417 dolog "error processing 'pdim' %S: %s"
2418 cmds
(Printexc.to_string exn
);
2421 state.uioh#infochanged Pdim
;
2422 state.pdims
<- pdim :: state.pdims
2425 let (l, n, t
, h, pos
) =
2427 Scanf.sscanf
args "%u %u %d %u %n"
2428 (fun l n t
h pos
-> l, n, t
, h, pos
)
2430 dolog "error processing 'o' %S: %s"
2431 cmds
(Printexc.to_string exn
);
2434 let s = String.sub
args pos
(String.length
args - pos
) in
2435 let outline = (s, l, (n, float t
/. float h)) in
2436 begin match state.currently
with
2437 | Outlining outlines
->
2438 state.currently
<- Outlining
(outline :: outlines
)
2440 state.currently
<- Outlining
[outline]
2442 dolog "invalid outlining state";
2443 logcurrently currently
2447 state.docinfo
<- (1, args) :: state.docinfo
2450 state.uioh#infochanged Docinfo
;
2451 state.docinfo
<- List.rev
state.docinfo
2454 dolog "unknown cmd `%S'" cmds
2459 let action = function
2460 | HCprev
-> cbget cb ~
-1
2461 | HCnext
-> cbget cb
1
2462 | HCfirst
-> cbget cb ~
-(cb
.rc)
2463 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2464 and cancel
() = cb
.rc <- rc
2468 let search pattern forward
=
2469 if String.length pattern
> 0
2472 match state.layout with
2475 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2477 wcmd "search %d %d %d %d,%s\000"
2478 (btod conf.icase
) pn py (btod forward
) pattern
;
2481 let intentry text key =
2483 if key >= 32 && key < 127
2489 let text = addchar text c in
2493 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2497 let linknentry text key =
2499 if key >= 32 && key < 127
2505 let text = addchar text c in
2509 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2514 if String.length
s > 0
2517 let l = String.length
s in
2518 let rec loop pos
n = if pos
= l then n else
2519 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2520 loop (pos
+1) (n*26 + m)
2523 let rec loop n = function
2526 match getopaque l.pageno with
2527 | None
-> loop n rest
2529 let m = getlinkcount opaque
in
2532 let under = getlink opaque
n in
2535 else loop (n-m) rest
2537 loop n state.layout;
2541 let textentry text key =
2542 if key land 0xff00 = 0xff00
2544 else TEcont
(text ^
Wsi.toutf8
key)
2547 let reqlayout angle proportional
=
2548 match state.throttle
with
2550 if nogeomcmds state.geomcmds
2551 then state.anchor <- getanchor ();
2552 conf.angle
<- angle
mod 360;
2555 match state.mode
with
2556 | LinkNav _
-> state.mode
<- View
2559 conf.proportional
<- proportional
;
2560 invalidate "reqlayout"
2561 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2565 let settrim trimmargins trimfuzz
=
2566 if nogeomcmds state.geomcmds
2567 then state.anchor <- getanchor ();
2568 conf.trimmargins
<- trimmargins
;
2569 conf.trimfuzz
<- trimfuzz
;
2570 let x0, y0, x1, y1 = trimfuzz
in
2571 invalidate "settrim"
2573 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2574 Hashtbl.iter
(fun _ opaque
->
2575 wcmd "freepage %s" opaque
;
2577 Hashtbl.clear
state.pagemap
;
2581 match state.throttle
with
2583 let zoom = max
0.01 zoom in
2584 if zoom <> conf.zoom
2586 state.prevzoom
<- conf.zoom;
2588 reshape conf.winw
conf.winh
;
2589 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2592 | Some
(layout, y, started
) ->
2594 match conf.maxwait
with
2598 let dt = now () -. started
in
2606 let setcolumns mode columns coverA coverB
=
2607 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2611 then showtext '
!'
"split mode doesn't work in bird's eye"
2613 conf.columns
<- Csplit
(-columns
, [||]);
2621 conf.columns
<- Csingle
;
2626 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2630 reshape conf.winw
conf.winh
;
2633 let enterbirdseye () =
2634 let zoom = float conf.thumbw
/. float conf.winw
in
2635 let birdseyepageno =
2636 let cy = conf.winh
/ 2 in
2640 let rec fold best
= function
2643 let d = cy - (l.pagedispy + l.pagevh/2)
2644 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2645 if abs
d < abs dbest
2652 state.mode
<- Birdseye
(
2653 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2656 conf.presentation <- false;
2657 conf.interpagespace <- 10;
2658 conf.hlinks
<- false;
2660 state.mstate
<- Mnone
;
2661 conf.maxwait
<- None
;
2663 match conf.beyecolumns
with
2666 Cmulti
((c, 0, 0), [||])
2669 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2672 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2677 reshape conf.winw
conf.winh
;
2680 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2682 conf.zoom <- c.zoom;
2683 conf.presentation <- c.presentation;
2684 conf.interpagespace <- c.interpagespace;
2685 conf.maxwait
<- c.maxwait
;
2686 conf.hlinks
<- c.hlinks
;
2687 conf.beyecolumns
<- (
2688 match conf.columns
with
2689 | Cmulti
((c, _
, _
), _
) -> Some
c
2691 | Csplit _
-> failwith
"leaving bird's eye split mode"
2694 match c.columns
with
2695 | Cmulti
(c, _
) -> Cmulti
(c, [||])
2696 | Csingle
-> Csingle
2697 | Csplit
(c, _
) -> Csplit
(c, [||])
2702 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2705 reshape conf.winw
conf.winh
;
2706 state.anchor <- if goback
then anchor else (pageno, 0.0);
2709 let togglebirdseye () =
2710 match state.mode
with
2711 | Birdseye vals
-> leavebirdseye vals
true
2712 | View
-> enterbirdseye ()
2716 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2717 let pageno = max
0 (pageno - incr
) in
2718 let rec loop = function
2719 | [] -> gotopage1 pageno 0
2720 | l :: _
when l.pageno = pageno ->
2721 if l.pagedispy >= 0 && l.pagey = 0
2722 then G.postRedisplay "upbirdseye"
2723 else gotopage1 pageno 0
2724 | _
:: rest
-> loop rest
2727 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2730 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2731 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2732 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2733 let rec loop = function
2735 let y, h = getpageyh pageno in
2736 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2738 | l :: _
when l.pageno = pageno ->
2739 if l.pagevh != l.pageh
2740 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2741 else G.postRedisplay "downbirdseye"
2742 | _
:: rest
-> loop rest
2747 let optentry mode _
key =
2748 let btos b = if b then "on" else "off" in
2749 if key >= 32 && key < 127
2751 let c = Char.chr
key in
2755 try conf.scrollstep
<- int_of_string
s with exc
->
2756 state.text <- Printf.sprintf
"bad integer `%s': %s"
2757 s (Printexc.to_string exc
)
2759 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2764 conf.autoscrollstep
<- int_of_string
s;
2765 if state.autoscroll
<> None
2766 then state.autoscroll
<- Some
conf.autoscrollstep
2768 state.text <- Printf.sprintf
"bad integer `%s': %s"
2769 s (Printexc.to_string exc
)
2771 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2776 let n, a, b = multicolumns_of_string s in
2777 setcolumns mode
n a b;
2779 state.text <- Printf.sprintf
"bad columns `%s': %s"
2780 s (Printexc.to_string exc
)
2782 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2787 let zoom = float (int_of_string
s) /. 100.0 in
2790 state.text <- Printf.sprintf
"bad integer `%s': %s"
2791 s (Printexc.to_string exc
)
2793 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2798 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2800 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2801 begin match mode
with
2803 leavebirdseye beye
false;
2808 state.text <- Printf.sprintf
"bad integer `%s': %s"
2809 s (Printexc.to_string exc
)
2811 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2816 Some
(int_of_string
s)
2818 state.text <- Printf.sprintf
"bad integer `%s': %s"
2819 s (Printexc.to_string exc
);
2822 | Some angle
-> reqlayout angle
conf.proportional
2825 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2828 conf.icase
<- not
conf.icase
;
2829 TEdone
("case insensitive search " ^
(btos conf.icase
))
2832 conf.preload <- not
conf.preload;
2834 TEdone
("preload " ^
(btos conf.preload))
2837 conf.verbose
<- not
conf.verbose
;
2838 TEdone
("verbose " ^
(btos conf.verbose
))
2841 conf.debug
<- not
conf.debug
;
2842 TEdone
("debug " ^
(btos conf.debug
))
2845 conf.maxhfit
<- not
conf.maxhfit
;
2846 state.maxy
<- calcheight ();
2847 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2850 conf.crophack
<- not
conf.crophack
;
2851 TEdone
("crophack " ^
btos conf.crophack
)
2855 match conf.maxwait
with
2857 conf.maxwait
<- Some infinity
;
2858 "always wait for page to complete"
2860 conf.maxwait
<- None
;
2861 "show placeholder if page is not ready"
2866 conf.underinfo
<- not
conf.underinfo
;
2867 TEdone
("underinfo " ^
btos conf.underinfo
)
2870 conf.savebmarks
<- not
conf.savebmarks
;
2871 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2877 match state.layout with
2882 conf.interpagespace <- int_of_string
s;
2883 docolumns conf.columns
;
2884 state.maxy
<- calcheight ();
2885 let y = getpagey pageno in
2888 state.text <- Printf.sprintf
"bad integer `%s': %s"
2889 s (Printexc.to_string exc
)
2891 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2894 reqlayout conf.angle
(not
conf.proportional
);
2895 TEdone
("proportional display " ^
btos conf.proportional
)
2898 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2899 TEdone
("trim margins " ^
btos conf.trimmargins
)
2902 conf.invert
<- not
conf.invert
;
2903 TEdone
("invert colors " ^
btos conf.invert
)
2907 cbput state.hists
.sel
s;
2910 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2911 textentry, ondone, true)
2914 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2920 class type lvsource
= object
2921 method getitemcount
: int
2922 method getitem
: int -> (string * int)
2923 method hasaction
: int -> bool
2932 method getactive
: int
2933 method getfirst
: int
2934 method getqsearch
: string
2935 method setqsearch
: string -> unit
2939 class virtual lvsourcebase
= object
2940 val mutable m_active
= 0
2941 val mutable m_first
= 0
2942 val mutable m_qsearch
= ""
2943 val mutable m_pan
= 0
2944 method getactive
= m_active
2945 method getfirst
= m_first
2946 method getqsearch
= m_qsearch
2947 method getpan
= m_pan
2948 method setqsearch
s = m_qsearch
<- s
2951 let withoutlastutf8 s =
2952 let len = String.length
s in
2960 let b = Char.code
s.[pos
] in
2961 if b land 0b110000 = 0b11000000
2966 if Char.code
s.[len-1] land 0x80 = 0
2970 String.sub
s 0 first;
2973 let textentrykeyboard
2974 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2976 state.mode
<- Textentry
(te
, onleave
);
2979 G.postRedisplay "textentrykeyboard enttext";
2981 let histaction cmd
=
2984 | Some
(action, _
) ->
2985 state.mode
<- Textentry
(
2986 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2988 G.postRedisplay "textentry histaction"
2991 | 0xff08 -> (* backspace *)
2992 let s = withoutlastutf8 text in
2993 let len = String.length
s in
2994 if cancelonempty
&& len = 0
2997 G.postRedisplay "textentrykeyboard after cancel";
3000 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3006 G.postRedisplay "textentrykeyboard after confirm"
3008 | 0xff52 -> histaction HCprev
3009 | 0xff54 -> histaction HCnext
3010 | 0xff50 -> histaction HCfirst
3011 | 0xff57 -> histaction HClast
3013 | 0xff1b -> (* escape*)
3014 if String.length
text = 0
3016 begin match opthist
with
3018 | Some
(_
, onhistcancel
) -> onhistcancel
()
3022 G.postRedisplay "textentrykeyboard after cancel2"
3025 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3028 | 0xff9f | 0xffff -> () (* delete *)
3030 | _
when key != 0 && key land 0xff00 != 0xff00 ->
3031 begin match onkey
text key with
3035 G.postRedisplay "textentrykeyboard after confirm2";
3038 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3042 G.postRedisplay "textentrykeyboard after cancel3"
3045 state.mode
<- Textentry
(te
, onleave
);
3046 G.postRedisplay "textentrykeyboard switch";
3050 vlog "unhandled key %s" (Wsi.keyname
key)
3053 let firstof first active
=
3054 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3055 then max
0 (active
- (fstate.maxrows
/2))
3059 let calcfirst first active
=
3062 let rows = active
- first in
3063 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3067 let scrollph y maxy
=
3068 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3069 let sh = float conf.winh
/. sh in
3070 let sh = max
sh (float conf.scrollh
) in
3075 else float y /. float maxy
3077 let position = (float conf.winh
-. sh) *. percent in
3080 if position +. sh > float conf.winh
3081 then float conf.winh
-. sh
3087 let coe s = (s :> uioh
);;
3089 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3091 val m_pan
= source#getpan
3092 val m_first
= source#getfirst
3093 val m_active
= source#getactive
3094 val m_qsearch
= source#getqsearch
3095 val m_prev_uioh
= state.uioh
3097 method private elemunder
y =
3098 let n = y / (fstate.fontsize
+1) in
3099 if m_first
+ n < source#getitemcount
3101 if source#hasaction
(m_first
+ n)
3102 then Some
(m_first
+ n)
3109 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3110 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3111 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3112 GlDraw.color
(1., 1., 1.);
3113 Gl.enable `texture_2d
;
3114 let fs = fstate.fontsize
in
3116 let ww = fstate.wwidth
in
3117 let tabw = 30.0*.ww in
3118 let itemcount = source#getitemcount
in
3120 if (row - m_first
) * nfs > conf.winh
3123 if row >= 0 && row < itemcount
3125 let (s, level
) = source#getitem
row in
3126 let y = (row - m_first
) * nfs in
3127 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3130 Gl.disable `texture_2d
;
3131 GlDraw.polygon_mode `both `line
;
3132 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3133 GlDraw.rect (1., float (y + 1))
3134 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3135 GlDraw.polygon_mode `both `fill
;
3136 GlDraw.color
(1., 1., 1.);
3137 Gl.enable `texture_2d
;
3140 let drawtabularstring s =
3141 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3144 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3147 let len = String.length
s - tabpos - 1 in
3148 let s1 = String.sub
s 0 tabpos
3149 and s2
= String.sub
s (tabpos + 1) len in
3150 let nx = drawstr x s1 in
3152 let x = x +. (max
tabw sw) in
3159 let _ = drawtabularstring s in
3166 Gl.disable `texture_2d
;
3168 method updownlevel incr
=
3169 let len = source#getitemcount
in
3171 if m_active
>= 0 && m_active
< len
3172 then snd
(source#getitem m_active
)
3176 if i
= len then i
-1 else if i
= -1 then 0 else
3177 let _, l = source#getitem i
in
3178 if l != curlevel then i
else flow (i
+incr
)
3180 let active = flow m_active
in
3181 let first = calcfirst m_first
active in
3182 G.postRedisplay "outline updownlevel";
3183 {< m_active
= active; m_first
= first >}
3185 method private key1
key mask
=
3186 let set1 active first qsearch
=
3187 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3189 let search active pattern incr
=
3192 if n >= 0 && n < source#getitemcount
3194 let s, _ = source#getitem
n in
3196 (try ignore
(Str.search_forward
re s 0); true
3197 with Not_found
-> false)
3199 else loop (n + incr
)
3206 let re = Str.regexp_case_fold pattern
in
3212 let itemcount = source#getitemcount
in
3213 let find start incr
=
3215 if i
= -1 || i
= itemcount
3218 if source#hasaction i
3220 else find (i
+ incr
)
3225 let set active first =
3226 let first = bound first 0 (itemcount - fstate.maxrows
) in
3228 coe {< m_active
= active; m_first
= first >}
3231 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3233 let incr1 = if incr
> 0 then 1 else -1 in
3234 if isvisible m_first m_active
3237 let next = m_active
+ incr
in
3239 if next < 0 || next >= itemcount
3241 else find next incr1
3243 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3249 let first = m_first
+ incr
in
3250 let first = bound first 0 (itemcount - 1) in
3252 let next = m_active
+ incr
in
3253 let next = bound next 0 (itemcount - 1) in
3256 let active = if next = -1 then m_active
else next in
3259 let first = min
next m_first
in
3261 if abs
(next - first) > fstate.maxrows
3267 let first = m_first
+ incr
in
3268 let first = bound first 0 (itemcount - 1) in
3270 let next = m_active
+ incr
in
3271 let next = bound next 0 (itemcount - 1) in
3272 let next = find next incr1 in
3274 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3276 let active = if m_active
= -1 then next else m_active
in
3281 if isvisible first active
3287 G.postRedisplay "listview navigate";
3291 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3292 let incr = if key = 0x72 then -1 else 1 in
3294 match search (m_active
+ incr) m_qsearch
incr with
3296 state.text <- m_qsearch ^
" [not found]";
3299 state.text <- m_qsearch
;
3300 active, firstof m_first
active
3302 G.postRedisplay "listview ctrl-r/s";
3303 set1 active first m_qsearch
;
3305 | 0xff08 -> (* backspace *)
3306 if String.length m_qsearch
= 0
3309 let qsearch = withoutlastutf8 m_qsearch
in
3310 let len = String.length
qsearch in
3314 G.postRedisplay "listview empty qsearch";
3315 set1 m_active m_first
"";
3319 match search m_active
qsearch ~
-1 with
3321 state.text <- qsearch ^
" [not found]";
3324 state.text <- qsearch;
3325 active, firstof m_first
active
3327 G.postRedisplay "listview backspace qsearch";
3328 set1 active first qsearch
3331 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3332 let pattern = m_qsearch ^
Wsi.toutf8
key in
3334 match search m_active
pattern 1 with
3336 state.text <- pattern ^
" [not found]";
3339 state.text <- pattern;
3340 active, firstof m_first
active
3342 G.postRedisplay "listview qsearch add";
3343 set1 active first pattern;
3345 | 0xff1b -> (* escape *)
3347 if String.length m_qsearch
= 0
3349 G.postRedisplay "list view escape";
3352 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3354 | None
-> m_prev_uioh
3359 G.postRedisplay "list view kill qsearch";
3360 source#setqsearch
"";
3361 coe {< m_qsearch
= "" >}
3364 | 0xff0d -> (* return *)
3366 let self = {< m_qsearch
= "" >} in
3367 source#setqsearch
"";
3369 G.postRedisplay "listview enter";
3370 if m_active
>= 0 && m_active
< source#getitemcount
3372 source#exit
(coe self) false m_active m_first m_pan
"";
3375 source#exit
(coe self) true m_active m_first m_pan
"";
3378 begin match opt with
3379 | None
-> m_prev_uioh
3383 | 0xff9f | 0xffff -> (* delete *)
3386 | 0xff52 -> navigate ~
-1 (* up *)
3387 | 0xff54 -> navigate 1 (* down *)
3388 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3389 | 0xff56 -> navigate fstate.maxrows
(* next *)
3391 | 0xff53 -> (* right *)
3393 G.postRedisplay "listview right";
3394 coe {< m_pan
= m_pan
- 1 >}
3396 | 0xff51 -> (* left *)
3398 G.postRedisplay "listview left";
3399 coe {< m_pan
= m_pan
+ 1 >}
3401 | 0xff50 -> (* home *)
3402 let active = find 0 1 in
3403 G.postRedisplay "listview home";
3406 | 0xff57 -> (* end *)
3407 let first = max
0 (itemcount - fstate.maxrows
) in
3408 let active = find (itemcount - 1) ~
-1 in
3409 G.postRedisplay "listview end";
3412 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3416 dolog "listview unknown key %#x" key; coe self
3418 method key key mask
=
3419 match state.mode
with
3420 | Textentry te
-> textentrykeyboard key mask te
; coe self
3421 | _ -> self#key1
key mask
3423 method button button down
x y _ =
3426 | 1 when x > conf.winw
- conf.scrollbw
->
3427 G.postRedisplay "listview scroll";
3430 let _, position, sh = self#
scrollph in
3431 if y > truncate
position && y < truncate
(position +. sh)
3433 state.mstate
<- Mscrolly
;
3437 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3438 let first = truncate
(s *. float source#getitemcount
) in
3439 let first = min source#getitemcount
first in
3440 Some
(coe {< m_first
= first; m_active
= first >})
3442 state.mstate
<- Mnone
;
3445 | 1 when not down
->
3446 begin match self#elemunder
y with
3448 G.postRedisplay "listview click";
3450 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3454 | n when (n == 4 || n == 5) && not down
->
3455 let len = source#getitemcount
in
3457 if n = 5 && m_first
+ fstate.maxrows
>= len
3461 let first = m_first
+ (if n == 4 then -1 else 1) in
3462 bound first 0 (len - 1)
3464 G.postRedisplay "listview wheel";
3465 Some
(coe {< m_first
= first >})
3466 | n when (n = 6 || n = 7) && not down
->
3467 let inc = m_first
+ (if n = 7 then -1 else 1) in
3468 G.postRedisplay "listview hwheel";
3469 Some
(coe {< m_pan
= m_pan
+ inc >})
3474 | None
-> m_prev_uioh
3478 match state.mstate
with
3480 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3481 let first = truncate
(s *. float source#getitemcount
) in
3482 let first = min source#getitemcount
first in
3483 G.postRedisplay "listview motion";
3484 coe {< m_first
= first; m_active
= first >}
3487 method pmotion
x y =
3488 if x < conf.winw
- conf.scrollbw
3491 match self#elemunder
y with
3492 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3493 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3497 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3502 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3506 method infochanged
_ = ()
3508 method scrollpw
= (0, 0.0, 0.0)
3510 let nfs = fstate.fontsize
+ 1 in
3511 let y = m_first
* nfs in
3512 let itemcount = source#getitemcount
in
3513 let maxi = max
0 (itemcount - fstate.maxrows
) in
3514 let maxy = maxi * nfs in
3515 let p, h = scrollph y maxy in
3518 method modehash
= modehash
3521 class outlinelistview ~source
=
3524 ~source
:(source
:> lvsource
)
3526 ~modehash
:(findkeyhash conf "outline")
3529 method key key mask
=
3530 let calcfirst first active =
3533 let rows = active - first in
3535 if String.length
state.text = 0
3537 else fstate.maxrows - 2
3539 if rows > maxrows then active - maxrows else first
3543 let active = m_active
+ incr in
3544 let active = bound active 0 (source#getitemcount
- 1) in
3545 let first = calcfirst m_first
active in
3546 G.postRedisplay "outline navigate";
3547 coe {< m_active
= active; m_first
= first >}
3549 let ctrl = Wsi.withctrl mask
in
3551 | 110 when ctrl -> (* ctrl-n *)
3552 source#narrow m_qsearch
;
3553 G.postRedisplay "outline ctrl-n";
3554 coe {< m_first
= 0; m_active
= 0 >}
3556 | 117 when ctrl -> (* ctrl-u *)
3558 G.postRedisplay "outline ctrl-u";
3560 coe {< m_first
= 0; m_active
= 0 >}
3562 | 108 when ctrl -> (* ctrl-l *)
3563 let first = m_active
- (fstate.maxrows / 2) in
3564 G.postRedisplay "outline ctrl-l";
3565 coe {< m_first
= first >}
3567 | 0xff9f | 0xffff -> (* delete *)
3568 source#remove m_active
;
3569 G.postRedisplay "outline delete";
3570 let active = max
0 (m_active
-1) in
3571 coe {< m_first
= firstof m_first
active;
3572 m_active
= active >}
3574 | 0xff52 -> navigate ~
-1 (* up *)
3575 | 0xff54 -> navigate 1 (* down *)
3576 | 0xff55 -> (* prior *)
3577 navigate ~
-(fstate.maxrows)
3578 | 0xff56 -> (* next *)
3579 navigate fstate.maxrows
3581 | 0xff53 -> (* [ctrl-]right *)
3585 G.postRedisplay "outline ctrl right";
3586 {< m_pan
= m_pan
+ 1 >}
3588 else self#updownlevel
1
3592 | 0xff51 -> (* [ctrl-]left *)
3596 G.postRedisplay "outline ctrl left";
3597 {< m_pan
= m_pan
- 1 >}
3599 else self#updownlevel ~
-1
3603 | 0xff50 -> (* home *)
3604 G.postRedisplay "outline home";
3605 coe {< m_first
= 0; m_active
= 0 >}
3607 | 0xff57 -> (* end *)
3608 let active = source#getitemcount
- 1 in
3609 let first = max
0 (active - fstate.maxrows) in
3610 G.postRedisplay "outline end";
3611 coe {< m_active
= active; m_first
= first >}
3613 | _ -> super#
key key mask
3616 let outlinesource usebookmarks
=
3619 inherit lvsourcebase
3620 val mutable m_items
= empty
3621 val mutable m_orig_items
= empty
3622 val mutable m_prev_items
= empty
3623 val mutable m_narrow_pattern
= ""
3624 val mutable m_hadremovals
= false
3626 method getitemcount
=
3627 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3630 if n == Array.length m_items
&& m_hadremovals
3632 ("[Confirm removal]", 0)
3634 let s, n, _ = m_items
.(n) in
3637 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3638 ignore
(uioh
, first, qsearch);
3639 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3641 if String.length m_narrow_pattern
= 0
3647 if not
confrimremoval
3649 let _, _, anchor = m_items
.(active) in
3654 state.bookmarks
<- Array.to_list m_items
;
3655 m_orig_items
<- m_items
;
3658 else m_items
<- items;
3662 method hasaction
_ = true
3665 if Array.length m_items
!= Array.length m_orig_items
3666 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3669 method narrow
pattern =
3670 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3674 let rec loop accu n =
3677 m_narrow_pattern
<- pattern;
3678 m_items
<- Array.of_list
accu
3681 let (s, _, _) as o = m_items
.(n) in
3683 if (try ignore
(Str.search_forward
re s 0); true
3684 with Not_found
-> false)
3690 loop [] (Array.length m_items
- 1)
3695 then Array.of_list
state.bookmarks
3698 m_items
<- m_orig_items
3703 if m >= 0 && m < Array.length m_items
3705 m_hadremovals
<- true;
3706 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3707 let n = if n >= m then n+1 else n in
3712 method reset
anchor items =
3713 m_hadremovals
<- false;
3714 if m_orig_items
== empty || m_prev_items
!= items
3716 m_orig_items
<- items;
3717 if String.length m_narrow_pattern
= 0
3718 then m_items
<- items;
3720 m_prev_items
<- items;
3721 let rely = getanchory anchor in
3723 let rec loop n best bestd
=
3724 if n = Array.length m_items
3727 let (_, _, anchor) = m_items
.(n) in
3728 let orely = getanchory anchor in
3729 let d = abs
(orely - rely) in
3732 else loop (n+1) best bestd
3737 m_first
<- firstof m_first
active
3741 let enterselector usebookmarks
=
3742 let source = outlinesource usebookmarks
in
3746 then Array.of_list
state.bookmarks
3749 if Array.length
outlines = 0
3751 showtext ' ' errmsg
;
3754 state.text <- source#greetmsg
;
3755 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3756 let anchor = getanchor () in
3757 source#reset
anchor outlines;
3758 state.uioh
<- coe (new outlinelistview ~
source);
3759 G.postRedisplay "enter selector";
3763 let enteroutlinemode =
3764 let f = enterselector false in
3765 fun ()-> f "Document has no outline";
3768 let enterbookmarkmode =
3769 let f = enterselector true in
3770 fun () -> f "Document has no bookmarks (yet)";
3773 let color_of_string s =
3774 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3775 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3779 let color_to_string (r
, g
, b) =
3780 let r = truncate
(r *. 256.0)
3781 and g
= truncate
(g
*. 256.0)
3782 and b = truncate
(b *. 256.0) in
3783 Printf.sprintf
"%d/%d/%d" r g
b
3786 let irect_of_string s =
3787 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3790 let irect_to_string (x0,y0,x1,y1) =
3791 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3794 let makecheckers () =
3795 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3797 converted by Issac Trotts. July 25, 2002 *)
3798 let image_height = 64
3799 and image_width
= 64 in
3803 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3805 for i
= 0 to image_width
- 1 do
3806 for j
= 0 to image_height - 1 do
3807 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3808 (if (i
land 8 ) lxor (j
land 8) = 0
3809 then [|255;255;255|] else [|200;200;200|])
3814 let image = make_image () in
3815 let id = GlTex.gen_texture
() in
3816 GlTex.bind_texture `texture_2d
id;
3817 GlPix.store
(`unpack_alignment
1);
3818 GlTex.image2d
image;
3819 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3822 `mag_filter `nearest
;
3823 `min_filter `nearest
];
3827 let setcheckers enabled
=
3828 match state.texid
with
3830 if enabled
then state.texid
<- Some
(makecheckers ())
3835 GlTex.delete_texture texid
;
3836 state.texid
<- None
;
3840 let int_of_string_with_suffix s =
3841 let l = String.length
s in
3845 let suffix = Char.lowercase
s.[l-1] in
3847 | 'k'
-> String.sub
s 0 (l-1), 10
3848 | '
m'
-> String.sub
s 0 (l-1), 20
3849 | 'g'
-> String.sub
s 0 (l-1), 30
3853 let n = int_of_string
s1 in
3854 let m = n lsl shift
in
3856 then raise
(Failure
"value too large")
3860 let string_with_suffix_of_int n =
3865 if n land ((1 lsl 20) - 1) = 0
3868 if n land ((1 lsl 10) - 1) = 0
3874 let h = n mod 1000 in
3877 then string_of_int
h ^
s
3879 let s = Printf.sprintf
"_%03d%s" h s in
3886 let defghyllscroll = (40, 8, 32);;
3887 let ghyllscroll_of_string s =
3888 let (n, a, b) as nab
=
3891 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3893 if n <= a || n <= b || a >= b
3894 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3898 let ghyllscroll_to_string ((n, a, b) as nab
) =
3899 if nab
= defghyllscroll
3901 else Printf.sprintf
"%d,%d,%d" n a b;
3904 let describe_location () =
3906 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3908 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3909 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3913 else (100. *. (float state.y /. float maxy))
3917 Printf.sprintf
"page %d of %d [%.2f%%]"
3918 (fn+1) state.pagecount
percent
3921 "pages %d-%d of %d [%.2f%%]"
3922 (fn+1) (ln
+1) state.pagecount
percent
3926 let btos b = if b then "\xe2\x88\x9a" else "" in
3927 let showextended = ref false in
3928 let leave mode
= function
3929 | Confirm
-> state.mode
<- mode
3930 | Cancel
-> state.mode
<- mode
in
3933 val mutable m_first_time
= true
3934 val mutable m_l
= []
3935 val mutable m_a
= [||]
3936 val mutable m_prev_uioh
= nouioh
3937 val mutable m_prev_mode
= View
3939 inherit lvsourcebase
3941 method reset prev_mode prev_uioh
=
3942 m_a
<- Array.of_list
(List.rev m_l
);
3944 m_prev_mode
<- prev_mode
;
3945 m_prev_uioh
<- prev_uioh
;
3949 if n >= Array.length m_a
3953 | _, _, _, Action
_ -> m_active
<- n
3957 m_first_time
<- false;
3960 method int name get
set =
3962 (name
, `
int get
, 1, Action
(
3965 try set (int_of_string
s)
3967 state.text <- Printf.sprintf
"bad integer `%s': %s"
3968 s (Printexc.to_string exn
)
3971 let te = name ^
": ", "", None
, intentry, ondone, true in
3972 state.mode
<- Textentry
(te, leave m_prev_mode
);
3976 method int_with_suffix name get
set =
3978 (name
, `intws get
, 1, Action
(
3981 try set (int_of_string_with_suffix s)
3983 state.text <- Printf.sprintf
"bad integer `%s': %s"
3984 s (Printexc.to_string exn
)
3988 name ^
": ", "", None
, intentry_with_suffix, ondone, true
3990 state.mode
<- Textentry
(te, leave m_prev_mode
);
3994 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3996 (name
, `
bool (btos, get
), offset
, Action
(
4003 method color name get
set =
4005 (name
, `color get
, 1, Action
(
4007 let invalid = (nan
, nan
, nan
) in
4010 try color_of_string s
4012 state.text <- Printf.sprintf
"bad color `%s': %s"
4013 s (Printexc.to_string exn
);
4019 let te = name ^
": ", "", None
, textentry, ondone, true in
4020 state.text <- color_to_string (get
());
4021 state.mode
<- Textentry
(te, leave m_prev_mode
);
4025 method string name get
set =
4027 (name
, `
string get
, 1, Action
(
4029 let ondone s = set s in
4030 let te = name ^
": ", "", None
, textentry, ondone, true in
4031 state.mode
<- Textentry
(te, leave m_prev_mode
);
4035 method colorspace name get
set =
4037 (name
, `
string get
, 1, Action
(
4040 let vals = [| "rgb"; "bgr"; "gray" |] in
4042 inherit lvsourcebase
4045 m_active
<- int_of_colorspace conf.colorspace
;
4048 method getitemcount
= Array.length
vals
4049 method getitem
n = (vals.(n), 0)
4050 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4051 ignore
(uioh
, first, pan
, qsearch);
4052 if not cancel
then set active;
4054 method hasaction
_ = true
4058 let modehash = findkeyhash conf "info" in
4059 coe (new listview ~
source ~trusted
:true ~
modehash)
4062 method caption
s offset
=
4063 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4065 method caption2
s f offset
=
4066 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4068 method getitemcount
= Array.length m_a
4071 let tostr = function
4072 | `
int f -> string_of_int
(f ())
4073 | `intws
f -> string_with_suffix_of_int (f ())
4075 | `color
f -> color_to_string (f ())
4076 | `
bool (btos, f) -> btos (f ())
4079 let name, t
, offset
, _ = m_a
.(n) in
4080 ((let s = tostr t
in
4081 if String.length
s > 0
4082 then Printf.sprintf
"%s\t%s" name s
4086 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4090 m_qsearch
<- qsearch;
4092 match m_a
.(active) with
4093 | _, _, _, Action
f -> f uioh
4105 method hasaction
n =
4107 | _, _, _, Action
_ -> true
4111 let rec fillsrc prevmode prevuioh
=
4112 let sep () = src#caption
"" 0 in
4113 let colorp name get
set =
4115 (fun () -> color_to_string (get
()))
4118 let c = color_of_string v in
4121 state.text <- Printf.sprintf
"bad color `%s': %s"
4122 v (Printexc.to_string exn
);
4125 let oldmode = state.mode
in
4126 let birdseye = isbirdseye state.mode
in
4128 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4130 src#
bool "presentation mode"
4131 (fun () -> conf.presentation)
4133 conf.presentation <- v;
4134 state.anchor <- getanchor ();
4137 src#
bool "ignore case in searches"
4138 (fun () -> conf.icase
)
4139 (fun v -> conf.icase
<- v);
4142 (fun () -> conf.preload)
4143 (fun v -> conf.preload <- v);
4145 src#
bool "highlight links"
4146 (fun () -> conf.hlinks
)
4147 (fun v -> conf.hlinks
<- v);
4149 src#
bool "under info"
4150 (fun () -> conf.underinfo
)
4151 (fun v -> conf.underinfo
<- v);
4153 src#
bool "persistent bookmarks"
4154 (fun () -> conf.savebmarks
)
4155 (fun v -> conf.savebmarks
<- v);
4157 src#
bool "proportional display"
4158 (fun () -> conf.proportional
)
4159 (fun v -> reqlayout conf.angle
v);
4161 src#
bool "trim margins"
4162 (fun () -> conf.trimmargins
)
4163 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4165 src#
bool "persistent location"
4166 (fun () -> conf.jumpback
)
4167 (fun v -> conf.jumpback
<- v);
4170 src#
int "inter-page space"
4171 (fun () -> conf.interpagespace)
4173 conf.interpagespace <- n;
4174 docolumns conf.columns
;
4176 match state.layout with
4181 state.maxy <- calcheight ();
4182 let y = getpagey pageno in
4187 (fun () -> conf.pagebias
)
4188 (fun v -> conf.pagebias
<- v);
4190 src#
int "scroll step"
4191 (fun () -> conf.scrollstep
)
4192 (fun n -> conf.scrollstep
<- n);
4194 src#
int "horizontal scroll step"
4195 (fun () -> conf.hscrollstep
)
4196 (fun v -> conf.hscrollstep
<- v);
4198 src#
int "auto scroll step"
4200 match state.autoscroll
with
4202 | _ -> conf.autoscrollstep
)
4204 if state.autoscroll
<> None
4205 then state.autoscroll
<- Some
n;
4206 conf.autoscrollstep
<- n);
4209 (fun () -> truncate
(conf.zoom *. 100.))
4210 (fun v -> setzoom ((float v) /. 100.));
4213 (fun () -> conf.angle
)
4214 (fun v -> reqlayout v conf.proportional
);
4216 src#
int "scroll bar width"
4217 (fun () -> state.scrollw
)
4221 reshape conf.winw
conf.winh
;
4224 src#
int "scroll handle height"
4225 (fun () -> conf.scrollh
)
4226 (fun v -> conf.scrollh
<- v;);
4228 src#
int "thumbnail width"
4229 (fun () -> conf.thumbw
)
4231 conf.thumbw
<- min
4096 v;
4234 leavebirdseye beye
false;
4239 let mode = state.mode in
4240 src#
string "columns"
4242 match conf.columns
with
4244 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4245 | Csplit
(count
, _) -> "-" ^ string_of_int count
4248 let n, a, b = multicolumns_of_string v in
4249 setcolumns mode n a b);
4252 src#caption
"Presentation mode" 0;
4253 src#
bool "scrollbar visible"
4254 (fun () -> conf.scrollbarinpm
)
4256 if v != conf.scrollbarinpm
4258 conf.scrollbarinpm
<- v;
4259 if conf.presentation
4261 state.scrollw
<- if v then conf.scrollbw
else 0;
4262 reshape conf.winw
conf.winh
;
4268 src#caption
"Pixmap cache" 0;
4269 src#int_with_suffix
"size (advisory)"
4270 (fun () -> conf.memlimit
)
4271 (fun v -> conf.memlimit
<- v);
4274 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4275 (string_with_suffix_of_int state.memused
)
4276 (Hashtbl.length
state.tilemap
)) 1;
4279 src#caption
"Layout" 0;
4280 src#caption2
"Dimension"
4282 Printf.sprintf
"%dx%d (virtual %dx%d)"
4288 src#caption2
"Position" (fun () ->
4289 Printf.sprintf
"%dx%d" state.x state.y
4292 src#caption2
"Visible" (fun () -> describe_location ()) 1
4296 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4297 "Save these parameters as global defaults at exit"
4298 (fun () -> conf.bedefault
)
4299 (fun v -> conf.bedefault
<- v)
4303 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4304 src#
bool ~offset
:0 ~
btos "Extended parameters"
4305 (fun () -> !showextended)
4306 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4310 (fun () -> conf.checkers
)
4311 (fun v -> conf.checkers
<- v; setcheckers v);
4312 src#
bool "update cursor"
4313 (fun () -> conf.updatecurs
)
4314 (fun v -> conf.updatecurs
<- v);
4316 (fun () -> conf.verbose
)
4317 (fun v -> conf.verbose
<- v);
4318 src#
bool "invert colors"
4319 (fun () -> conf.invert
)
4320 (fun v -> conf.invert
<- v);
4322 (fun () -> conf.maxhfit
)
4323 (fun v -> conf.maxhfit
<- v);
4324 src#
bool "redirect stderr"
4325 (fun () -> conf.redirectstderr)
4326 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4327 src#
string "uri launcher"
4328 (fun () -> conf.urilauncher
)
4329 (fun v -> conf.urilauncher
<- v);
4330 src#
string "path launcher"
4331 (fun () -> conf.pathlauncher
)
4332 (fun v -> conf.pathlauncher
<- v);
4333 src#
string "tile size"
4334 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4337 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4338 conf.tilew
<- max
64 w;
4339 conf.tileh
<- max
64 h;
4342 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4343 v (Printexc.to_string exn
));
4344 src#
int "texture count"
4345 (fun () -> conf.texcount
)
4348 then conf.texcount
<- v
4349 else showtext '
!'
" Failed to set texture count please retry later"
4351 src#
int "slice height"
4352 (fun () -> conf.sliceheight
)
4354 conf.sliceheight
<- v;
4355 wcmd "sliceh %d" conf.sliceheight
;
4357 src#
int "anti-aliasing level"
4358 (fun () -> conf.aalevel
)
4360 conf.aalevel
<- bound v 0 8;
4361 state.anchor <- getanchor ();
4362 opendoc state.path
state.password
;
4364 src#
string "page scroll scaling factor"
4365 (fun () -> string_of_float
conf.pgscale)
4368 let s = float_of_string
v in
4371 state.text <- Printf.sprintf
4372 "bad page scroll scaling factor `%s': %s"
4373 v (Printexc.to_string exn
)
4376 src#
int "ui font size"
4377 (fun () -> fstate.fontsize
)
4378 (fun v -> setfontsize (bound v 5 100));
4379 src#
int "hint font size"
4380 (fun () -> conf.hfsize
)
4381 (fun v -> conf.hfsize
<- bound v 5 100);
4382 colorp "background color"
4383 (fun () -> conf.bgcolor
)
4384 (fun v -> conf.bgcolor
<- v);
4385 src#
bool "crop hack"
4386 (fun () -> conf.crophack
)
4387 (fun v -> conf.crophack
<- v);
4388 src#
string "trim fuzz"
4389 (fun () -> irect_to_string conf.trimfuzz
)
4392 conf.trimfuzz
<- irect_of_string v;
4394 then settrim true conf.trimfuzz
;
4396 state.text <- Printf.sprintf
"bad irect `%s': %s"
4397 v (Printexc.to_string exn
)
4399 src#
string "throttle"
4401 match conf.maxwait
with
4402 | None
-> "show place holder if page is not ready"
4405 then "wait for page to fully render"
4407 "wait " ^ string_of_float
time
4408 ^
" seconds before showing placeholder"
4412 let f = float_of_string
v in
4414 then conf.maxwait
<- None
4415 else conf.maxwait
<- Some
f
4417 state.text <- Printf.sprintf
"bad time `%s': %s"
4418 v (Printexc.to_string exn
)
4420 src#
string "ghyll scroll"
4422 match conf.ghyllscroll
with
4424 | Some nab
-> ghyllscroll_to_string nab
4429 if String.length
v = 0
4431 else Some
(ghyllscroll_of_string v)
4433 conf.ghyllscroll
<- gs
4435 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4436 v (Printexc.to_string exn
)
4438 src#
string "selection command"
4439 (fun () -> conf.selcmd
)
4440 (fun v -> conf.selcmd
<- v);
4441 src#colorspace
"color space"
4442 (fun () -> colorspace_to_string conf.colorspace
)
4444 conf.colorspace
<- colorspace_of_int v;
4451 src#caption
"Document" 0;
4452 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4453 src#caption2
"Pages"
4454 (fun () -> string_of_int
state.pagecount
) 1;
4455 src#caption2
"Dimensions"
4456 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4460 src#caption
"Trimmed margins" 0;
4461 src#caption2
"Dimensions"
4462 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4466 src#caption
"OpenGL" 0;
4467 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4468 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4469 src#reset prevmode prevuioh
;
4473 let prevmode = state.mode
4474 and prevuioh
= state.uioh in
4475 fillsrc prevmode prevuioh
;
4476 let source = (src :> lvsource
) in
4477 let modehash = findkeyhash conf "info" in
4478 state.uioh <- coe (object (self)
4479 inherit listview ~
source ~trusted
:true ~
modehash as super
4480 val mutable m_prevmemused
= 0
4481 method infochanged
= function
4483 if m_prevmemused
!= state.memused
4485 m_prevmemused
<- state.memused
;
4486 G.postRedisplay "memusedchanged";
4488 | Pdim
-> G.postRedisplay "pdimchanged"
4489 | Docinfo
-> fillsrc prevmode prevuioh
4491 method key key mask
=
4492 if not
(Wsi.withctrl mask
)
4495 | 0xff51 -> coe (self#updownlevel ~
-1)
4496 | 0xff53 -> coe (self#updownlevel
1)
4497 | _ -> super#
key key mask
4498 else super#
key key mask
4500 G.postRedisplay "info";
4506 inherit lvsourcebase
4507 method getitemcount
= Array.length
state.help
4509 let s, n, _ = state.help
.(n) in
4512 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4516 m_qsearch
<- qsearch;
4517 match state.help
.(active) with
4518 | _, _, Action
f -> Some
(f uioh)
4528 method hasaction
n =
4529 match state.help
.(n) with
4530 | _, _, Action
_ -> true
4537 let modehash = findkeyhash conf "help" in
4538 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4539 G.postRedisplay "help";
4544 let re = Str.regexp
"[\r\n]" in
4546 inherit lvsourcebase
4547 val mutable m_items
= [||]
4549 method getitemcount
= 1 + Array.length m_items
4554 else m_items
.(n-1), 0
4556 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4561 then Buffer.clear
state.errmsgs
;
4562 m_qsearch
<- qsearch;
4569 method hasaction
n =
4573 state.newerrmsgs
<- false;
4574 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4575 m_items
<- Array.of_list
l
4583 let source = (msgsource :> lvsource
) in
4584 let modehash = findkeyhash conf "listview" in
4585 state.uioh <- coe (object
4586 inherit listview ~
source ~trusted
:false ~
modehash as super
4589 then msgsource#reset
;
4592 G.postRedisplay "msgs";
4595 let quickbookmark ?title
() =
4596 match state.layout with
4602 let sec = Unix.gettimeofday
() in
4603 let tm = Unix.localtime
sec in
4604 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4608 (tm.Unix.tm_year
+ 1900)
4611 | Some
title -> title
4614 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4619 state.fullscreen
<- None
;
4623 let setautoscrollspeed step goingdown
=
4624 let incr = max
1 ((abs step
) / 2) in
4625 let incr = if goingdown
then incr else -incr in
4626 let astep = step
+ incr in
4627 state.autoscroll
<- Some
astep;
4630 let gotounder = function
4631 | Ulinkgoto
(pageno, top) ->
4635 gotopage1 pageno top;
4641 | Uremote
(filename
, pageno) ->
4643 if Sys.file_exists filename
4646 let dir = Filename.dirname
state.path in
4647 let path = Filename.concat
dir filename
in
4648 if Sys.file_exists
path
4652 if String.length
path > 0
4654 let anchor = getanchor () in
4655 let ranchor = state.path, state.password
, anchor in
4656 state.anchor <- (pageno, 0.0);
4657 state.ranchors
<- ranchor :: state.ranchors
;
4660 else showtext '
!'
("Could not find " ^ filename
)
4662 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4666 match conf.columns
with
4668 | _ -> conf.zoom > 1.0
4671 let viewkeyboard key mask
=
4673 let mode = state.mode in
4674 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4677 G.postRedisplay "view:enttext"
4679 let ctrl = Wsi.withctrl mask
in
4684 | 0xff63 -> (* insert *)
4685 if conf.angle
mod 360 = 0
4687 state.mode <- LinkNav
(Ltgendir
0);
4690 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4692 | 0xff1b | 113 -> (* escape / q *)
4693 begin match state.mstate
with
4695 state.mstate
<- Mnone
;
4696 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4697 G.postRedisplay "kill zoom rect";
4699 match state.ranchors
with
4701 | (path, password
, anchor) :: rest
->
4702 state.ranchors
<- rest
;
4703 state.anchor <- anchor;
4704 opendoc path password
4707 | 0xff08 -> (* backspace *)
4708 let y = getnav ~
-1 in
4709 gotoy_and_clear_text y
4717 G.postRedisplay "dehighlight";
4719 | 47 | 63 -> (* / ? *)
4720 let ondone isforw
s =
4721 cbput state.hists
.pat
s;
4722 state.searchpattern
<- s;
4725 let s = String.create
1 in
4726 s.[0] <- Char.chr
key;
4727 enttext (s, "", Some
(onhist state.hists
.pat
),
4728 textentry, ondone (key = 47), true)
4730 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-=*)
4731 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4732 setzoom (conf.zoom +. incr)
4734 | 43 | 0xffab -> (* + *)
4737 try int_of_string
s with exc
->
4738 state.text <- Printf.sprintf
"bad integer `%s': %s"
4739 s (Printexc.to_string exc
);
4745 state.text <- "page bias is now " ^ string_of_int
n;
4748 enttext ("page bias: ", "", None
, intentry, ondone, true)
4750 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4751 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4752 setzoom (max
0.01 (conf.zoom -. decr))
4754 | 45 | 0xffad -> (* - *)
4755 let ondone msg
= state.text <- msg
in
4757 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4758 optentry state.mode, ondone, true
4761 | 48 when ctrl -> (* ctrl-0 *)
4764 | 49 when ctrl -> (* ctrl-1 *)
4766 match conf.columns
with
4767 | Csingle
| Cmulti
_ -> 1
4768 | Csplit
(n, _) -> n
4770 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4774 | 0xffc6 -> (* f9 *)
4777 | 57 when ctrl -> (* ctrl-9 *)
4780 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4781 when not
ctrl -> (* 0..9 *)
4784 try int_of_string
s with exc
->
4785 state.text <- Printf.sprintf
"bad integer `%s': %s"
4786 s (Printexc.to_string exc
);
4792 cbput state.hists
.pag
(string_of_int
n);
4793 gotopage1 (n + conf.pagebias
- 1) 0;
4796 let pageentry text key =
4797 match Char.unsafe_chr
key with
4798 | 'g'
-> TEdone
text
4799 | _ -> intentry text key
4801 let text = "x" in text.[0] <- Char.chr
key;
4802 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4805 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4806 reshape conf.winw
conf.winh
;
4809 conf.hlinks
<- not
conf.hlinks
;
4810 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4811 G.postRedisplay "toggle highlightlinks";
4814 state.glinks
<- true;
4815 let mode = state.mode in
4816 state.mode <- Textentry
(
4817 (":", "", None
, linknentry, linkndone (fun under ->
4822 state.glinks
<- false;
4826 G.postRedisplay "view:linkent(F)"
4829 state.glinks
<- true;
4830 let mode = state.mode in
4831 state.mode <- Textentry
(
4832 (":", "", None
, linknentry, linkndone (fun under ->
4833 match Ne.pipe () with
4835 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4836 (Printexc.to_string exn
));
4839 try popen conf.selcmd
[r, 0; w, -1]; true
4842 (Printf.sprintf
"failed to execute %s: %s"
4843 conf.selcmd
(Printexc.to_string exn
));
4847 Ne.clo fd
(fun msg
->
4848 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4851 let s = undertext under in
4855 let l = String.length
s in
4856 let n = Unix.write
w s 0 l in
4861 "failed to write %d characters to sel pipe, wrote %d"
4866 (Printf.sprintf
"failed to write to sel pipe: %s"
4867 (Printexc.to_string exn
)
4876 state.glinks
<- false;
4880 G.postRedisplay "view:linkent"
4883 begin match state.autoscroll
with
4885 conf.autoscrollstep
<- step
;
4886 state.autoscroll
<- None
4888 if conf.autoscrollstep
= 0
4889 then state.autoscroll
<- Some
1
4890 else state.autoscroll
<- Some
conf.autoscrollstep
4893 | 112 when ctrl -> (* ctrl-p *)
4897 conf.presentation <- not
conf.presentation;
4898 if conf.presentation
4900 if not
conf.scrollbarinpm
4901 then state.scrollw
<- 0;
4904 state.scrollw
<- conf.scrollbw
;
4906 showtext ' '
("presentation mode " ^
4907 if conf.presentation then "on" else "off");
4908 state.anchor <- getanchor ();
4912 begin match state.fullscreen
with
4914 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4917 state.fullscreen
<- None
;
4922 gotoy_and_clear_text 0
4925 gotopage1 (state.pagecount
- 1) 0
4927 | 112 | 78 -> (* p|N *)
4928 search state.searchpattern
false
4930 | 110 | 0xffc0 -> (* n|F3 *)
4931 search state.searchpattern
true
4934 begin match state.layout with
4937 gotoy_and_clear_text (getpagey l.pageno)
4941 begin match state.layout with
4944 match conf.columns
with
4945 | Csingle
| Cmulti
_ ->
4946 if conf.presentation && rest
== [] && l.pageh
> l.pagey + l.pagevh
4948 let y = clamp (pgscale conf.winh
) in
4949 gotoy_and_clear_text y
4951 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4952 gotoy_and_clear_text (getpagey pageno)
4954 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4956 let pagey, pageh
= getpageyh l.pageno in
4957 let pagey = pagey + pageh
* l.pagecol
in
4958 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace in
4959 gotoy_and_clear_text (pagey + pageh
+ ips)
4962 | 0xff9f | 0xffff -> (* delete *)
4963 begin match state.layout with
4966 match conf.columns
with
4967 | Csingle
| Cmulti
_ ->
4968 if conf.presentation && (l.pagey != 0 || l.pagedispy < 0)
4970 gotoy_and_clear_text (clamp (pgscale ~
-(conf.winh
)))
4972 let pageno = max
0 (l.pageno-1) in
4973 gotoy_and_clear_text (getpagey pageno)
4981 let pageno = max
0 (l.pageno-1) in
4982 let pagey, pageh
= getpageyh pageno in
4985 let pagey, pageh
= getpageyh l.pageno in
4986 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4988 gotoy_and_clear_text y
4992 showtext ' '
(describe_location ());
4995 begin match state.layout with
4998 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5003 enterbookmarkmode ()
5005 | 104 | 0xffbe -> (* h|F1 *)
5011 | 101 when conf.redirectstderr -> (* e *)
5016 match state.layout with
5019 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
5023 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5027 showtext ' '
"Quick bookmark added";
5030 begin match state.layout with
5032 let rect = getpdimrect
l.pagedimno
in
5036 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5037 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5039 (truncate
(rect.(1) -. rect.(0)),
5040 truncate
(rect.(3) -. rect.(0)))
5042 let w = truncate
((float w)*.conf.zoom)
5043 and h = truncate
((float h)*.conf.zoom) in
5046 state.anchor <- getanchor ();
5047 doreshape (w + state.scrollw
) (h + conf.interpagespace)
5049 G.postRedisplay "z";
5054 | 50 when ctrl -> (* ctrl-2 *)
5055 let maxw = getmaxw
() in
5057 then setzoom (maxw /. float conf.winw
)
5059 | 60 | 62 -> (* < > *)
5060 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5062 | 91 | 93 -> (* [ ] *)
5064 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5066 G.postRedisplay "brightness";
5068 | 99 when state.mode = View
-> (* c *)
5070 match state.prevcolumns
with
5071 | None
-> (1, 0, 0), 1.0
5072 | Some
(columns
, z
) ->
5075 | Csplit
(c, _) -> -c, 0, 0
5076 | Cmulti
((c, a, b), _) -> c, a, b
5077 | Csingle
-> 1, 0, 0
5081 setcolumns View
c a b;
5084 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5085 setzoom state.prevzoom
5087 | 107 | 0xff52 -> (* k up *)
5088 begin match state.autoscroll
with
5090 begin match state.mode with
5091 | Birdseye beye
-> upbirdseye 1 beye
5094 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5095 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5098 setautoscrollspeed n false
5101 | 106 | 0xff54 -> (* j down *)
5102 begin match state.autoscroll
with
5104 begin match state.mode with
5105 | Birdseye beye
-> downbirdseye 1 beye
5108 then gotoy_and_clear_text (clamp (conf.winh
/2))
5109 else gotoy_and_clear_text (clamp conf.scrollstep
)
5112 setautoscrollspeed n true
5115 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5123 let dx = if key = 0xff51 then dx else -dx in
5124 state.x <- state.x + dx;
5125 gotoy_and_clear_text state.y
5128 G.postRedisplay "lef/right"
5131 | 0xff55 -> (* prior *)
5135 match state.layout with
5137 | l :: _ -> state.y - l.pagey
5139 clamp (pgscale (-conf.winh
))
5143 | 0xff56 -> (* next *)
5147 match List.rev
state.layout with
5149 | l :: _ -> getpagey l.pageno
5151 clamp (pgscale conf.winh
)
5155 | 0xff50 -> gotoghyll 0
5156 | 0xff57 -> gotoghyll (clamp state.maxy)
5157 | 0xff53 when Wsi.withalt mask
->
5158 gotoghyll (getnav ~
-1)
5159 | 0xff51 when Wsi.withalt mask
->
5160 gotoghyll (getnav 1)
5163 state.anchor <- getanchor ();
5164 opendoc state.path state.password
5166 | 118 when conf.debug
-> (* v *)
5169 match getopaque l.pageno with
5172 let x0, y0, x1, y1 = pagebbox opaque
in
5173 let a,b = float x0, float y0 in
5174 let c,d = float x1, float y0 in
5175 let e,f = float x1, float y1 in
5176 let h,j
= float x0, float y1 in
5177 let rect = (a,b,c,d,e,f,h,j
) in
5179 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5181 G.postRedisplay "v";
5184 vlog "huh? %s" (Wsi.keyname
key)
5187 let linknavkeyboard key mask
linknav =
5188 let getpage pageno =
5189 let rec loop = function
5191 | l :: _ when l.pageno = pageno -> Some
l
5192 | _ :: rest
-> loop rest
5193 in loop state.layout
5195 let doexact (pageno, n) =
5196 match getopaque pageno, getpage pageno with
5197 | Some opaque
, Some
l ->
5200 let under = getlink opaque
n in
5201 G.postRedisplay "link gotounder";
5207 | 0xff50 -> (* home *)
5208 Some
(findlink opaque LDfirst
), -1
5210 | 0xff57 -> (* end *)
5211 Some
(findlink opaque LDlast
), 1
5213 | 0xff51 -> (* left *)
5214 Some
(findlink opaque
(LDleft
n)), -1
5216 | 0xff53 -> (* right *)
5217 Some
(findlink opaque
(LDright
n)), 1
5219 | 0xff52 -> (* up *)
5220 Some
(findlink opaque
(LDup
n)), -1
5222 | 0xff54 -> (* down *)
5223 Some
(findlink opaque
(LDdown
n)), 1
5228 begin match findpwl
l.pageno dir with
5232 state.mode <- LinkNav
(Ltgendir
dir);
5233 let y, h = getpageyh pageno in
5236 then y + h - conf.winh
5241 begin match getopaque pageno, getpage pageno with
5242 | Some opaque
, Some
_ ->
5244 let ld = if dir > 0 then LDfirst
else LDlast
in
5247 begin match link with
5249 showlinktype (getlink opaque
m);
5250 state.mode <- LinkNav
(Ltexact
(pageno, m));
5251 G.postRedisplay "linknav jpage";
5258 begin match opt with
5259 | Some Lnotfound
-> pwl l dir;
5260 | Some
(Lfound
m) ->
5264 let _, y0, _, y1 = getlinkrect opaque
m in
5266 then gotopage1 l.pageno y0
5268 let d = fstate.fontsize
+ 1 in
5269 if y1 - l.pagey > l.pagevh - d
5270 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5271 else G.postRedisplay "linknav";
5273 showlinktype (getlink opaque
m);
5274 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5277 | None
-> viewkeyboard key mask
5279 | _ -> viewkeyboard key mask
5284 G.postRedisplay "leave linknav"
5288 | Ltgendir
_ -> viewkeyboard key mask
5289 | Ltexact exact
-> doexact exact
5292 let keyboard key mask
=
5293 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5294 then wcmd "interrupt"
5295 else state.uioh <- state.uioh#
key key mask
5298 let birdseyekeyboard key mask
5299 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5301 match conf.columns
with
5303 | Cmulti
((c, _, _), _) -> c
5304 | Csplit
_ -> failwith
"bird's eye split mode"
5307 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5308 let y, h = getpageyh pageno in
5309 let top = (conf.winh
- h) / 2 in
5310 gotoy (max
0 (y - top))
5311 | 0xff0d -> leavebirdseye beye
false
5312 | 0xff1b -> leavebirdseye beye
true (* escape *)
5313 | 0xff52 -> upbirdseye incr beye
(* prior *)
5314 | 0xff54 -> downbirdseye incr beye
(* next *)
5315 | 0xff51 -> upbirdseye 1 beye
(* up *)
5316 | 0xff53 -> downbirdseye 1 beye
(* down *)
5319 begin match state.layout with
5323 state.mode <- Birdseye
(
5324 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5326 gotopage1 l.pageno 0;
5329 let layout = layout (state.y-conf.winh
) conf.winh
in
5331 | [] -> gotoy (clamp (-conf.winh
))
5333 state.mode <- Birdseye
(
5334 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5336 gotopage1 l.pageno 0
5339 | [] -> gotoy (clamp (-conf.winh
))
5343 begin match List.rev
state.layout with
5345 let layout = layout (state.y + conf.winh
) conf.winh
in
5346 begin match layout with
5348 let incr = l.pageh
- l.pagevh in
5353 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5355 G.postRedisplay "birdseye pagedown";
5357 else gotoy (clamp (incr + conf.interpagespace*2));
5361 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5362 gotopage1 l.pageno 0;
5365 | [] -> gotoy (clamp conf.winh
)
5369 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5373 let pageno = state.pagecount
- 1 in
5374 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5375 if not
(pagevisible state.layout pageno)
5378 match List.rev
state.pdims
with
5380 | (_, _, h, _) :: _ -> h
5382 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5383 else G.postRedisplay "birdseye end";
5384 | _ -> viewkeyboard key mask
5387 let drawpage l linkindexbase
=
5389 match state.mode with
5390 | Textentry
_ -> scalecolor 0.4
5392 | View
-> scalecolor 1.0
5393 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5394 if l.pageno = hooverpageno
5397 if l.pageno = pageno
5403 begin match getopaque l.pageno with
5405 if tileready l l.pagex l.pagey
5407 let x = l.pagedispx - l.pagex
5408 and y = l.pagedispy - l.pagey in
5410 match conf.columns
with
5411 | Csingle
| Cmulti
_ ->
5412 (if conf.hlinks
then 1 else 0)
5414 && not
(isbirdseye state.mode) then 2 else 0)
5418 match state.mode with
5419 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5422 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5429 let scrollindicator () =
5430 let sbw, ph
, sh = state.uioh#
scrollph in
5431 let sbh, pw, sw = state.uioh#scrollpw
in
5433 GlDraw.color (0.64, 0.64, 0.64);
5435 (float (conf.winw
- sbw), 0.)
5436 (float conf.winw
, float conf.winh
)
5439 (0., float (conf.winh
- sbh))
5440 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5442 GlDraw.color (0.0, 0.0, 0.0);
5445 (float (conf.winw
- sbw), ph
)
5446 (float conf.winw
, ph
+. sh)
5449 (pw, float (conf.winh
- sbh))
5450 (pw +. sw, float conf.winh
)
5455 match state.mstate
with
5456 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5459 | Msel
((x0, y0), (x1, y1)) ->
5460 let rec loop = function
5462 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5463 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5464 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5465 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5467 match getopaque l.pageno with
5469 let x0, y0 = pagetranslatepoint l x0 y0 in
5470 let x1, y1 = pagetranslatepoint l x1 y1 in
5471 seltext opaque
(x0, y0, x1, y1);
5479 let showrects rects
=
5481 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5482 GlDraw.polygon_mode `both `fill
;
5483 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5485 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5487 if l.pageno = pageno
5489 let dx = float (l.pagedispx - l.pagex) in
5490 let dy = float (l.pagedispy - l.pagey) in
5491 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5492 GlDraw.begins `quads
;
5494 GlDraw.vertex2
(x0+.dx, y0+.dy);
5495 GlDraw.vertex2
(x1+.dx, y1+.dy);
5496 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5497 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5508 GlClear.color (scalecolor2 conf.bgcolor
);
5509 GlClear.clear
[`
color];
5510 let rec loop linkindexbase
= function
5512 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5513 loop linkindexbase rest
5516 loop 0 state.layout;
5518 match state.mode with
5519 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5520 begin match getopaque pageno with
5522 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5529 | None
-> state.rects
5536 begin match state.mstate
with
5537 | Mzoomrect
((x0, y0), (x1, y1)) ->
5539 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5540 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5541 GlDraw.rect (float x0, float y0)
5542 (float x1, float y1);
5551 let zoomrect x y x1 y1 =
5554 and y0 = min
y y1 in
5555 gotoy (state.y + y0);
5556 state.anchor <- getanchor ();
5557 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5559 if state.w < conf.winw
- state.scrollw
5560 then (conf.winw
- state.scrollw
- state.w) / 2
5563 state.x <- (state.x + margin) - x0;
5565 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5566 state.mstate
<- Mnone
;
5570 let winw = conf.winw - state.scrollw
- 1 in
5571 let s = float x /. float winw in
5572 let destx = truncate
(float (state.w + winw) *. s) in
5573 state.x <- winw - destx;
5574 gotoy_and_clear_text state.y;
5575 state.mstate
<- Mscrollx
;
5579 let s = float y /. float conf.winh
in
5580 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5581 gotoy_and_clear_text desty;
5582 state.mstate
<- Mscrolly
;
5585 let viewmouse button down
x y mask
=
5587 | n when (n == 4 || n == 5) && not down
->
5588 if Wsi.withctrl mask
5590 match state.mstate
with
5591 | Mzoom
(oldn
, i
) ->
5599 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5601 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5603 let zoom = conf.zoom -. incr in
5605 state.mstate
<- Mzoom
(n, 0);
5607 state.mstate
<- Mzoom
(n, i
+1);
5609 else state.mstate
<- Mzoom
(n, 0)
5611 | _ -> state.mstate
<- Mzoom
(n, 0)
5614 match state.autoscroll
with
5615 | Some step
-> setautoscrollspeed step
(n=4)
5619 then -conf.scrollstep
5620 else conf.scrollstep
5622 let incr = incr * 2 in
5623 let y = clamp incr in
5624 gotoy_and_clear_text y
5627 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5628 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5629 gotoy_and_clear_text state.y
5631 | 1 when Wsi.withctrl mask
->
5634 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5635 state.mstate
<- Mpan
(x, y)
5638 state.mstate
<- Mnone
5643 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5645 state.mstate
<- Mzoomrect
(p, p)
5648 match state.mstate
with
5649 | Mzoomrect
((x0, y0), _) ->
5650 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5651 then zoomrect x0 y0 x y
5653 state.mstate
<- Mnone
;
5654 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5655 G.postRedisplay "kill accidental zoom rect";
5658 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5659 state.mstate
<- Mnone
5662 | 1 when x > conf.winw - state.scrollw
->
5665 let _, position, sh = state.uioh#
scrollph in
5666 if y > truncate
position && y < truncate
(position +. sh)
5667 then state.mstate
<- Mscrolly
5670 state.mstate
<- Mnone
5672 | 1 when y > conf.winh
- state.hscrollh ->
5675 let _, position, sw = state.uioh#scrollpw
in
5676 if x > truncate
position && x < truncate
(position +. sw)
5677 then state.mstate
<- Mscrollx
5680 state.mstate
<- Mnone
5683 let dest = if down
then getunder x y else Unone
in
5684 begin match dest with
5688 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5691 | Unone
when down
->
5692 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5693 state.mstate
<- Mpan
(x, y);
5695 | Unone
| Utext
_ ->
5698 if conf.angle
mod 360 = 0
5700 state.mstate
<- Msel
((x, y), (x, y));
5701 G.postRedisplay "mouse select";
5705 match state.mstate
with
5708 | Mzoom
_ | Mscrollx
| Mscrolly
->
5709 state.mstate
<- Mnone
5711 | Mzoomrect
((x0, y0), _) ->
5715 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5716 state.mstate
<- Mnone
5718 | Msel
((_, y0), (_, y1)) ->
5719 let rec loop = function
5722 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5723 || ((y1 >= l.pagedispy
5724 && y1 <= (l.pagedispy + l.pagevh)))
5726 match getopaque l.pageno with
5729 match Ne.pipe () with
5733 "can not create sel pipe: %s"
5734 (Printexc.to_string exn
));
5736 let doclose what fd
=
5737 Ne.clo fd
(fun msg
->
5738 dolog "%s close failed: %s" what msg
)
5741 popen conf.selcmd
[r, 0; w, -1];
5744 G.postRedisplay "copysel";
5746 dolog "can not execute %S: %s"
5747 conf.selcmd
(Printexc.to_string exn
);
5755 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5756 state.mstate
<- Mnone
;
5763 let birdseyemouse button down
x y mask
5764 (conf, leftx
, _, hooverpageno
, anchor) =
5767 let rec loop = function
5770 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5771 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5773 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5779 | _ -> viewmouse button down
x y mask
5782 let mouse button down
x y mask
=
5783 state.uioh <- state.uioh#button button down
x y mask
;
5787 state.uioh <- state.uioh#
motion x y
5791 state.uioh <- state.uioh#
pmotion x y;
5797 method key key mask
=
5798 begin match state.mode with
5799 | Textentry
textentry -> textentrykeyboard key mask
textentry
5800 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5801 | View
-> viewkeyboard key mask
5802 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5806 method button button bstate
x y mask
=
5807 begin match state.mode with
5809 | View
-> viewmouse button bstate
x y mask
5810 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5816 begin match state.mode with
5818 | View
| Birdseye
_ | LinkNav
_ ->
5819 match state.mstate
with
5820 | Mzoom
_ | Mnone
-> ()
5825 state.mstate
<- Mpan
(x, y);
5827 then state.x <- state.x + dx;
5829 gotoy_and_clear_text y
5832 state.mstate
<- Msel
(a, (x, y));
5833 G.postRedisplay "motion select";
5836 let y = min
conf.winh
(max
0 y) in
5840 let x = min
conf.winw (max
0 x) in
5843 | Mzoomrect
(p0
, _) ->
5844 state.mstate
<- Mzoomrect
(p0
, (x, y));
5845 G.postRedisplay "motion zoomrect";
5849 method pmotion x y =
5850 begin match state.mode with
5851 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5852 let rec loop = function
5854 if hooverpageno
!= -1
5856 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5857 G.postRedisplay "pmotion birdseye no hoover";
5860 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5861 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5863 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5864 G.postRedisplay "pmotion birdseye hoover";
5874 match state.mstate
with
5875 | Mnone
-> updateunder x y
5876 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5881 method infochanged
_ = ()
5884 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5885 let p, h = scrollph state.y maxy in
5889 let winw = conf.winw - state.scrollw
- 1 in
5890 let fwinw = float winw in
5892 let sw = fwinw /. float state.w in
5893 let sw = fwinw *. sw in
5894 max
sw (float conf.scrollh
)
5897 let f = state.w+winw in
5898 let r = float (winw-state.x) /. float f in
5899 let p = fwinw *. r in
5903 if position +. sw > fwinw
5904 then fwinw -. position
5907 state.hscrollh, position, sw
5911 match state.mode with
5912 | LinkNav
_ -> "links"
5913 | Textentry
_ -> "textentry"
5914 | Birdseye
_ -> "birdseye"
5917 findkeyhash conf modename
5924 let fontpath = ref "";;
5927 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5930 let l = String.length
s in
5931 let b = Buffer.create
l in
5937 try Sys.getenv
"HOME"
5940 ("Can not determine home directory location: " ^
5941 Printexc.to_string exn
);
5945 let modifier_of_string = function
5946 | "alt" -> Wsi.altmask
5947 | "shift" -> Wsi.shiftmask
5948 | "ctrl" | "control" -> Wsi.ctrlmask
5949 | "meta" -> Wsi.metamask
5954 let r = Str.regexp
"-" in
5956 let elems = Str.full_split
r s in
5959 let m1 = modifier_of_string s in
5961 then (Wsi.namekey
s, m)
5964 | Str.Delim
s when n land 1 = 0 -> g s
5966 | Str.Delim
_ -> (k
, m)
5968 let rec loop n k
m = function
5971 let k, m = f n k m x in
5977 let keys_of_string =
5978 let r = Str.regexp
"[ \t]" in
5980 let elems = Str.split
r s in
5981 List.map
key_of_string elems
5984 let copykeyhashes c =
5985 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5988 let config_of c attrs
=
5992 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5993 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5994 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5995 | "preload" -> { c with preload = bool_of_string
v }
5996 | "page-bias" -> { c with pagebias
= int_of_string
v }
5997 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5998 | "horizontal-scroll-step" ->
5999 { c with hscrollstep
= max
(int_of_string
v) 1 }
6000 | "auto-scroll-step" ->
6001 { c with autoscrollstep
= max
0 (int_of_string
v) }
6002 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6003 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6006 match String.lowercase
v with
6007 | "true" -> Some infinity
6009 | f -> Some
(float_of_string
f)
6011 { c with maxwait
= mw}
6012 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6013 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6014 | "vertical-margin" ->
6015 { c with interpagespace = max
0 (int_of_string
v) }
6017 let zoom = float_of_string
v /. 100. in
6018 let zoom = max
zoom 0.0 in
6019 { c with zoom = zoom }
6020 | "presentation" -> { c with presentation = bool_of_string
v }
6021 | "rotation-angle" -> { c with angle
= int_of_string
v }
6022 | "width" -> { c with winw = max
20 (int_of_string
v) }
6023 | "height" -> { c with winh
= max
20 (int_of_string
v) }
6024 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6025 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6026 | "pixmap-cache-size" ->
6027 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6028 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6029 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6030 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6031 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6032 | "background-color" -> { c with bgcolor
= color_of_string v }
6033 | "scrollbar-in-presentation" ->
6034 { c with scrollbarinpm
= bool_of_string
v }
6035 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6036 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6037 | "mupdf-store-size" ->
6038 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6039 | "checkers" -> { c with checkers
= bool_of_string
v }
6040 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6041 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6042 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6043 | "uri-launcher" -> { c with urilauncher
= unent v }
6044 | "path-launcher" -> { c with pathlauncher
= unent v }
6045 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6046 | "invert-colors" -> { c with invert
= bool_of_string
v }
6047 | "brightness" -> { c with colorscale
= float_of_string
v }
6048 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6050 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6052 let (n, _, _) as nab
= multicolumns_of_string v in
6054 then { c with columns
= Csplit
(-n, [||]) }
6055 else { c with columns
= Cmulti
(nab
, [||]) }
6056 | "birds-eye-columns" ->
6057 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6058 | "selection-command" -> { c with selcmd
= unent v }
6059 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6060 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6061 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6064 prerr_endline
("Error processing attribute (`" ^
6065 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6068 let rec fold c = function
6071 let c = apply c k v in
6074 fold { c with keyhashes
= copykeyhashes c } attrs
;
6077 let fromstring f pos
n v d =
6080 dolog "Error processing attribute (%S=%S) at %d\n%s"
6081 n v pos
(Printexc.to_string exn
)
6086 let bookmark_of attrs
=
6087 let rec fold title page
rely = function
6088 | ("title", v) :: rest
-> fold v page
rely rest
6089 | ("page", v) :: rest
-> fold title v rely rest
6090 | ("rely", v) :: rest
-> fold title page
v rest
6091 | _ :: rest
-> fold title page
rely rest
6092 | [] -> title, page
, rely
6094 fold "invalid" "0" "0" attrs
6098 let rec fold path page
rely pan
= function
6099 | ("path", v) :: rest
-> fold v page
rely pan rest
6100 | ("page", v) :: rest
-> fold path v rely pan rest
6101 | ("rely", v) :: rest
-> fold path page
v pan rest
6102 | ("pan", v) :: rest
-> fold path page
rely v rest
6103 | _ :: rest
-> fold path page
rely pan rest
6104 | [] -> path, page
, rely, pan
6106 fold "" "0" "0" "0" attrs
6110 let rec fold rs ls
= function
6111 | ("out", v) :: rest
-> fold v ls rest
6112 | ("in", v) :: rest
-> fold rs
v rest
6113 | _ :: rest
-> fold ls rs rest
6119 let setconf dst
src =
6120 dst
.scrollbw
<- src.scrollbw
;
6121 dst
.scrollh
<- src.scrollh
;
6122 dst
.icase
<- src.icase
;
6123 dst
.preload <- src.preload;
6124 dst
.pagebias
<- src.pagebias
;
6125 dst
.verbose
<- src.verbose
;
6126 dst
.scrollstep
<- src.scrollstep
;
6127 dst
.maxhfit
<- src.maxhfit
;
6128 dst
.crophack
<- src.crophack
;
6129 dst
.autoscrollstep
<- src.autoscrollstep
;
6130 dst
.maxwait
<- src.maxwait
;
6131 dst
.hlinks
<- src.hlinks
;
6132 dst
.underinfo
<- src.underinfo
;
6133 dst
.interpagespace <- src.interpagespace;
6134 dst
.zoom <- src.zoom;
6135 dst
.presentation <- src.presentation;
6136 dst
.angle
<- src.angle
;
6137 dst
.winw <- src.winw;
6138 dst
.winh
<- src.winh
;
6139 dst
.savebmarks
<- src.savebmarks
;
6140 dst
.memlimit
<- src.memlimit
;
6141 dst
.proportional
<- src.proportional
;
6142 dst
.texcount
<- src.texcount
;
6143 dst
.sliceheight
<- src.sliceheight
;
6144 dst
.thumbw
<- src.thumbw
;
6145 dst
.jumpback
<- src.jumpback
;
6146 dst
.bgcolor
<- src.bgcolor
;
6147 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6148 dst
.tilew
<- src.tilew
;
6149 dst
.tileh
<- src.tileh
;
6150 dst
.mustoresize
<- src.mustoresize
;
6151 dst
.checkers
<- src.checkers
;
6152 dst
.aalevel
<- src.aalevel
;
6153 dst
.trimmargins
<- src.trimmargins
;
6154 dst
.trimfuzz
<- src.trimfuzz
;
6155 dst
.urilauncher
<- src.urilauncher
;
6156 dst
.colorspace
<- src.colorspace
;
6157 dst
.invert
<- src.invert
;
6158 dst
.colorscale
<- src.colorscale
;
6159 dst
.redirectstderr <- src.redirectstderr;
6160 dst
.ghyllscroll
<- src.ghyllscroll
;
6161 dst
.columns
<- src.columns
;
6162 dst
.beyecolumns
<- src.beyecolumns
;
6163 dst
.selcmd
<- src.selcmd
;
6164 dst
.updatecurs
<- src.updatecurs
;
6165 dst
.pathlauncher
<- src.pathlauncher
;
6166 dst
.keyhashes
<- copykeyhashes src;
6167 dst
.hfsize
<- src.hfsize
;
6168 dst
.hscrollstep
<- src.hscrollstep
;
6169 dst
.pgscale <- src.pgscale;
6173 let h = Hashtbl.create
10 in
6174 let dc = { defconf with angle
= defconf.angle
} in
6175 let rec toplevel v t spos
_ =
6177 | Vdata
| Vcdata
| Vend
-> v
6178 | Vopen
("llppconfig", _, closed
) ->
6181 else { v with f = llppconfig
}
6183 error
"unexpected subelement at top level" s spos
6184 | Vclose
_ -> error
"unexpected close at top level" s spos
6186 and llppconfig
v t spos
_ =
6188 | Vdata
| Vcdata
-> v
6189 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6190 | Vopen
("defaults", attrs
, closed
) ->
6191 let c = config_of dc attrs
in
6195 else { v with f = defaults
}
6197 | Vopen
("ui-font", attrs
, closed
) ->
6198 let rec getsize size
= function
6200 | ("size", v) :: rest
->
6202 fromstring int_of_string spos
"size" v fstate.fontsize
in
6204 | l -> getsize size l
6206 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6209 else { v with f = uifont
(Buffer.create
10) }
6211 | Vopen
("doc", attrs
, closed
) ->
6212 let pathent, spage
, srely
, span
= doc_of attrs
in
6213 let path = unent pathent
6214 and pageno = fromstring int_of_string spos
"page" spage
0
6215 and rely = fromstring float_of_string spos
"rely" srely
0.0
6216 and pan
= fromstring int_of_string spos
"pan" span
0 in
6217 let c = config_of dc attrs
in
6218 let anchor = (pageno, rely) in
6220 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6221 else { v with f = doc
path pan
anchor c [] }
6224 error
"unexpected subelement in llppconfig" s spos
6226 | Vclose
"llppconfig" -> { v with f = toplevel }
6227 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6229 and defaults
v t spos
_ =
6231 | Vdata
| Vcdata
-> v
6232 | Vend
-> error
"unexpected end of input in defaults" s spos
6233 | Vopen
("keymap", attrs
, closed
) ->
6235 try List.assoc
"mode" attrs
6236 with Not_found
-> "global" in
6241 let h = findkeyhash dc modename in
6242 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6245 { v with f = pkeymap
ret KeyMap.empty }
6247 | Vopen
(_, _, _) ->
6248 error
"unexpected subelement in defaults" s spos
6250 | Vclose
"defaults" ->
6251 { v with f = llppconfig
}
6253 | Vclose
_ -> error
"unexpected close in defaults" s spos
6255 and uifont
b v t spos
epos =
6258 Buffer.add_substring
b s spos
(epos - spos
);
6260 | Vopen
(_, _, _) ->
6261 error
"unexpected subelement in ui-font" s spos
6262 | Vclose
"ui-font" ->
6263 if String.length
!fontpath = 0
6264 then fontpath := Buffer.contents
b;
6265 { v with f = llppconfig
}
6266 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6267 | Vend
-> error
"unexpected end of input in ui-font" s spos
6269 and doc
path pan
anchor c bookmarks
v t spos
_ =
6271 | Vdata
| Vcdata
-> v
6272 | Vend
-> error
"unexpected end of input in doc" s spos
6273 | Vopen
("bookmarks", _, closed
) ->
6276 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6278 | Vopen
("keymap", attrs
, closed
) ->
6280 try List.assoc
"mode" attrs
6281 with Not_found
-> "global"
6287 let h = findkeyhash c modename in
6288 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6289 doc
path pan
anchor c bookmarks
6291 { v with f = pkeymap
ret KeyMap.empty }
6293 | Vopen
(_, _, _) ->
6294 error
"unexpected subelement in doc" s spos
6297 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6298 { v with f = llppconfig
}
6300 | Vclose
_ -> error
"unexpected close in doc" s spos
6302 and pkeymap
ret keymap
v t spos
_ =
6304 | Vdata
| Vcdata
-> v
6305 | Vend
-> error
"unexpected end of input in keymap" s spos
6306 | Vopen
("map", attrs
, closed
) ->
6307 let r, l = map_of attrs
in
6308 let kss = fromstring keys_of_string spos
"in" r [] in
6309 let lss = fromstring keys_of_string spos
"out" l [] in
6313 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6314 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6317 then { v with f = pkeymap
ret keymap }
6320 { v with f = skip
"map" f }
6323 error
"unexpected subelement in keymap" s spos
6325 | Vclose
"keymap" ->
6326 { v with f = ret keymap }
6328 | Vclose
_ -> error
"unexpected close in keymap" s spos
6330 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6332 | Vdata
| Vcdata
-> v
6333 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6334 | Vopen
("item", attrs
, closed
) ->
6335 let titleent, spage
, srely
= bookmark_of attrs
in
6336 let page = fromstring int_of_string spos
"page" spage
0
6337 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6338 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6340 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6343 { v with f = skip
"item" f }
6346 error
"unexpected subelement in bookmarks" s spos
6348 | Vclose
"bookmarks" ->
6349 { v with f = doc
path pan
anchor c bookmarks }
6351 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6353 and skip tag
f v t spos
_ =
6355 | Vdata
| Vcdata
-> v
6357 error
("unexpected end of input in skipped " ^ tag
) s spos
6358 | Vopen
(tag'
, _, closed
) ->
6362 let f'
() = { v with f = skip tag
f } in
6363 { v with f = skip tag'
f'
}
6367 else error
("unexpected close in skipped " ^ tag
) s spos
6370 parse
{ f = toplevel; accu = () } s;
6376 let len = in_channel_length ic
in
6377 let s = String.create
len in
6378 really_input ic
s 0 len;
6381 | Parse_error
(msg
, s, pos
) ->
6382 let subs = subs s pos
in
6383 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6384 failwith
("parse error: " ^
s)
6387 failwith
("config load error: " ^
Printexc.to_string exn
)
6393 let dir = Filename.concat
home ".config" in
6394 if Sys.is_directory
dir then dir else home
6397 Filename.concat
dir "llpp.conf"
6400 let confpath = ref defconfpath;;
6403 if Sys.file_exists
!confpath
6406 (try Some
(open_in_bin
!confpath)
6409 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6410 Printexc.to_string exn
);
6419 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6420 Printexc.to_string exn
);
6426 f (Hashtbl.create
0, defconf)
6431 let pc, pb
, px, pa
=
6433 Hashtbl.find h (Filename.basename
state.path)
6434 with Not_found
-> dc, [], 0, (0, 0.0)
6438 state.bookmarks <- pb
;
6440 state.scrollw
<- conf.scrollbw
;
6442 then state.anchor <- pa
;
6443 cbput state.hists
.nav pa
;
6448 let add_attrs bb always
dc c =
6451 then Printf.bprintf bb
"\n %s='%b'" s a
6454 then Printf.bprintf bb
"\n %s='%d'" s a
6457 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6460 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6463 then Printf.bprintf bb
"\n %s='%f'" s a
6467 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6471 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6475 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6479 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6485 | Some
(_N
, _A
, _B
) ->
6486 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6496 else string_of_float
f
6498 Printf.bprintf bb
"\n %s='%s'" s v
6503 | Cmulti
((n, a, b), _) when n > 1 ->
6504 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6505 | Csplit
(n, _) when n > 1 ->
6506 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6512 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6517 then dc.winw, dc.winh
6519 match state.fullscreen
with
6521 | None
-> c.winw, c.winh
6523 let zoom, presentation, interpagespace, maxwait
=
6525 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6527 match state.mode with
6528 | Birdseye
(bc
, _, _, _, _) ->
6529 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6530 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6532 oi
"width" w dc.winw;
6533 oi
"height" h dc.winh
;
6534 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6535 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6536 ob "case-insensitive-search" c.icase
dc.icase
;
6537 ob "preload" c.preload dc.preload;
6538 oi
"page-bias" c.pagebias
dc.pagebias
;
6539 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6540 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6541 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6542 ob "crop-hack" c.crophack
dc.crophack
;
6543 oW
"throttle" maxwait
dc.maxwait
;
6544 ob "highlight-links" c.hlinks
dc.hlinks
;
6545 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6546 oi
"vertical-margin" interpagespace dc.interpagespace;
6547 oz
"zoom" zoom dc.zoom;
6548 ob "presentation" presentation dc.presentation;
6549 oi
"rotation-angle" c.angle
dc.angle
;
6550 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6551 ob "proportional-display" c.proportional
dc.proportional
;
6552 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6553 oi
"tex-count" c.texcount
dc.texcount
;
6554 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6555 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6556 ob "persistent-location" c.jumpback
dc.jumpback
;
6557 oc
"background-color" c.bgcolor
dc.bgcolor
;
6558 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6559 oi
"tile-width" c.tilew
dc.tilew
;
6560 oi
"tile-height" c.tileh
dc.tileh
;
6561 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6562 ob "checkers" c.checkers
dc.checkers
;
6563 oi
"aalevel" c.aalevel
dc.aalevel
;
6564 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6565 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6566 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6567 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6568 oC
"color-space" c.colorspace
dc.colorspace
;
6569 ob "invert-colors" c.invert
dc.invert
;
6570 oF
"brightness" c.colorscale
dc.colorscale
;
6571 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6572 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6573 oco
"columns" c.columns
dc.columns
;
6574 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6575 os
"selection-command" c.selcmd
dc.selcmd
;
6576 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6577 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6578 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6579 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6582 let keymapsbuf always
dc c =
6583 let bb = Buffer.create
16 in
6584 let rec loop = function
6586 | (modename, h) :: rest
->
6587 let dh = findkeyhash dc modename in
6588 if always
|| h <> dh
6590 if Hashtbl.length
h > 0
6592 if Buffer.length
bb > 0
6593 then Buffer.add_char
bb '
\n'
;
6594 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6595 Hashtbl.iter
(fun i
o ->
6596 let isdifferent = always
||
6598 let dO = Hashtbl.find dh i
in
6600 with Not_found
-> true
6605 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6606 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6607 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6608 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6609 Buffer.add_string
bb (Wsi.keyname
k);
6612 let rec loop = function
6614 | km
:: [] -> addkm km
6615 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6619 Buffer.add_string
bb "<map in='";
6623 Buffer.add_string
bb "' out='";
6625 Buffer.add_string
bb "'/>\n"
6628 Buffer.add_string
bb "' out='";
6630 Buffer.add_string
bb "'/>\n"
6632 | KMmulti
(ins, kms
) ->
6633 Buffer.add_char
bb ' '
;
6635 Buffer.add_string
bb "' out='";
6637 Buffer.add_string
bb "'/>\n"
6639 Buffer.add_string
bb "</keymap>";
6649 let uifontsize = fstate.fontsize
in
6650 let bb = Buffer.create
32768 in
6652 let dc = if conf.bedefault
then conf else dc in
6653 Buffer.add_string
bb "<llppconfig>\n";
6655 if String.length
!fontpath > 0
6657 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6663 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6666 Buffer.add_string
bb "<defaults ";
6667 add_attrs bb true dc dc;
6668 let kb = keymapsbuf true dc dc in
6669 if Buffer.length
kb > 0
6671 Buffer.add_string
bb ">\n";
6672 Buffer.add_buffer
bb kb;
6673 Buffer.add_string
bb "\n</defaults>\n";
6675 else Buffer.add_string
bb "/>\n";
6677 let adddoc path pan
anchor c bookmarks =
6678 if bookmarks == [] && c = dc && anchor = emptyanchor
6681 Printf.bprintf
bb "<doc path='%s'"
6682 (enent
path 0 (String.length
path));
6684 if anchor <> emptyanchor
6686 let n, y = anchor in
6687 Printf.bprintf
bb " page='%d'" n;
6690 Printf.bprintf
bb " rely='%f'" y
6695 then Printf.bprintf
bb " pan='%d'" pan
;
6697 add_attrs bb false dc c;
6698 let kb = keymapsbuf false dc c in
6700 begin match bookmarks with
6702 if Buffer.length
kb > 0
6704 Buffer.add_string
bb ">\n";
6705 Buffer.add_buffer
bb kb;
6706 Buffer.add_string
bb "\n</doc>\n";
6708 else Buffer.add_string
bb "/>\n"
6710 Buffer.add_string
bb ">\n<bookmarks>\n";
6711 List.iter
(fun (title, _level
, (page, rely)) ->
6713 "<item title='%s' page='%d'"
6714 (enent
title 0 (String.length
title))
6719 Printf.bprintf
bb " rely='%f'" rely
6721 Buffer.add_string
bb "/>\n";
6723 Buffer.add_string
bb "</bookmarks>";
6724 if Buffer.length
kb > 0
6726 Buffer.add_string
bb "\n";
6727 Buffer.add_buffer
bb kb;
6729 Buffer.add_string
bb "\n</doc>\n";
6735 match state.mode with
6736 | Birdseye
(c, pan, _, _, _) ->
6738 match conf.columns
with
6739 | Cmulti
((c, _, _), _) -> Some
c
6743 match c.columns
with
6744 | Cmulti
(c, _) -> Cmulti
(c, [||])
6745 | Csingle
-> Csingle
6746 | Csplit
_ -> failwith
"quit from bird's eye while split"
6748 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6749 | _ -> state.x, conf
6751 let basename = Filename.basename state.path in
6752 adddoc basename pan (getanchor ())
6755 match state.autoscroll
with
6757 | None
-> conf.autoscrollstep
}
6758 (if conf.savebmarks
then state.bookmarks else []);
6760 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6762 then adddoc path x y c bookmarks
6764 Buffer.add_string
bb "</llppconfig>";
6767 if Buffer.length
bb > 0
6770 let tmp = !confpath ^
".tmp" in
6771 let oc = open_out_bin
tmp in
6772 Buffer.output_buffer
oc bb;
6774 Unix.rename
tmp !confpath;
6777 ("error while saving configuration: " ^
Printexc.to_string exn
)
6782 let trimcachepath = ref "" in
6785 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6786 "<password> Set password");
6788 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6789 "<path> Set path to the user interface font");
6791 ("-c", Arg.String
(fun s -> Config.confpath := s),
6792 "<path> Set path to the configuration file");
6794 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6795 "<path> Set path to the trim cache file");
6797 ("-v", Arg.Unit
(fun () ->
6799 "%s\nconfiguration path: %s\n"
6803 exit
0), " Print version and exit");
6806 (fun s -> state.path <- s)
6807 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6809 if String.length
state.path = 0
6810 then (prerr_endline
"file name missing"; exit
1);
6814 let globalkeyhash = findkeyhash conf "global" in
6815 let wsfd, winw, winh
= Wsi.init
(object
6817 if nogeomcmds state.geomcmds
|| platform == Posx
6820 GlClear.color (scalecolor2 conf.bgcolor
);
6821 GlClear.clear
[`
color];
6823 method display = display ()
6824 method reshape w h = reshape w h
6825 method mouse b d x y m = mouse b d x y m
6826 method motion x y = state.mpos
<- (x, y); motion x y
6827 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6829 let mascm = m land (
6830 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6832 match state.keystate
with
6834 let km = k, mascm in
6837 let modehash = state.uioh#
modehash in
6838 try Hashtbl.find modehash km
6840 try Hashtbl.find globalkeyhash km
6841 with Not_found
-> KMinsrt
(k, m)
6843 | KMinsrt
(k, m) -> keyboard k m
6844 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6845 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6847 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6848 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6849 state.keystate
<- KSnone
6850 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6851 state.keystate
<- KSinto
(keys
, insrt
)
6853 state.keystate
<- KSnone
6855 method enter
x y = state.mpos
<- (x, y); pmotion x y
6856 method leave = state.mpos
<- (-1, -1)
6857 method quit
= raise Quit
6858 end) conf.winw conf.winh
(platform = Posx
) in
6863 List.exists
GlMisc.check_extension
6864 [ "GL_ARB_texture_rectangle"
6865 ; "GL_EXT_texture_recangle"
6866 ; "GL_NV_texture_rectangle" ]
6868 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6871 match Ne.pipe () with
6873 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6877 match Ne.pipe () with
6879 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6889 setcheckers conf.checkers
;
6893 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6894 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6895 !Config.fontpath, !trimcachepath
6899 state.text <- "Opening " ^
state.path;
6901 opendoc state.path state.password
;
6904 let rec loop deadline
=
6906 match state.errfd
with
6907 | None
-> [state.sr
; state.wsfd]
6908 | Some fd
-> [state.sr
; state.wsfd; fd
]
6912 state.redisplay
<- false;
6919 if deadline
= infinity
6921 else max
0.0 (deadline
-. now)
6926 try Unix.select
r [] [] timeout
6927 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6933 if state.ghyll
== noghyll
6935 match state.autoscroll
with
6936 | Some step
when step
!= 0 ->
6937 let y = state.y + step
in
6941 else if y >= state.maxy then 0 else y
6944 if state.mode = View
6945 then state.text <- "";
6948 else deadline
+. 0.01
6953 let rec checkfds = function
6955 | fd
:: rest
when fd
= state.sr
->
6956 let cmd = readcmd state.sr
in
6960 | fd
:: rest
when fd
= state.wsfd ->
6965 let s = String.create
80 in
6966 let n = Unix.read fd
s 0 80 in
6967 if conf.redirectstderr
6969 Buffer.add_substring
state.errmsgs
s 0 n;
6970 state.newerrmsgs
<- true;
6971 state.redisplay
<- true;
6974 prerr_string
(String.sub
s 0 n);
6982 if deadline
= infinity
6986 match state.autoscroll
with
6987 | Some step
when step
!= 0 -> deadline1
6988 | _ -> if state.ghyll
== noghyll then infinity
else deadline1