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
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
38 and irect
= (int * int * int * int)
39 and trimparams
= (trimmargins
* irect
)
40 and colorspace
= | Rgb
| Bgr
| Gray
49 | LDfirstvisible
of (int * int * int)
64 | KMmulti
of key list
* key list
66 and keyhash
= (key
, keymap
) Hashtbl.t
69 | KSinto
of (key list
* key list
)
72 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
73 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
75 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
77 external init
: pipe
-> params
-> unit = "ml_init";;
78 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
79 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
80 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
81 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
82 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
83 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
84 external measurestr
: int -> string -> float = "ml_measure_string";;
85 external getmaxw
: unit -> float = "ml_getmaxw";;
86 external postprocess
:
87 opaque
-> int -> int -> int -> (int * string * int) -> int = "ml_postprocess";;
88 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
89 external platform
: unit -> platform
= "ml_platform";;
90 external setaalevel
: int -> unit = "ml_setaalevel";;
91 external realloctexts
: int -> bool = "ml_realloctexts";;
92 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
93 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
94 external getlink
: opaque
-> int -> under
= "ml_getlink";;
95 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
96 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
97 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
98 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
100 let platform_to_string = function
101 | Punknown
-> "unknown"
105 | Pfreebsd
-> "FreeBSD"
106 | Pdragonflybsd
-> "DragonflyBSD"
107 | Popenbsd
-> "OpenBSD"
108 | Pnetbsd
-> "NetBSD"
109 | Pcygwin
-> "Cygwin"
112 let platform = platform ();;
115 if platform = Pcygwin
117 let sh = "/bin/sh" in
118 let args = [|sh; "-c"; cmd
|] in
119 let rec std si so se
= function
121 | (fd
, 0) :: rest
-> std fd so se rest
122 | (fd
, -1) :: rest
->
123 Unix.set_close_on_exec fd
;
126 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
128 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
129 ignore
(Unix.create_process
sh args si so se
)
138 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
141 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
143 type mpos
= int * int
145 | Msel
of (mpos
* mpos
)
147 | Mscrolly
| Mscrollx
148 | Mzoom
of (int * int)
149 | Mzoomrect
of (mpos
* mpos
)
153 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
154 and onkey
= string -> int -> te
155 and ondone
= string -> unit
156 and histcancel
= unit -> unit
157 and onhist
= ((histcmd
-> string) * histcancel
)
158 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
159 and cancelonempty
= bool
164 | TEswitch
of textentry
175 let bound v minv maxv
=
176 max minv
(min maxv v
);
180 { store
= Array.create n v
187 let drawstring size x y s
=
189 Gl.enable `texture_2d
;
190 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
191 ignore
(drawstr size x y s
);
193 Gl.disable `texture_2d
;
196 let drawstring1 size x y s
=
200 let drawstring2 size x y fmt
=
201 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
204 let cbcap b
= Array.length b
.store
;;
209 b
.wc
<- (b
.wc
+ 1) mod cap;
211 b
.len
<- min
(b
.len
+ 1) cap;
214 let cbempty b
= b
.len
= 0;;
216 let cbgetg b circular dir
=
220 let rc = b
.rc + dir
in
232 else max
0 (min
rc (b
.len
-1))
238 let cbget b
= cbgetg b
false;;
239 let cbgetc b
= cbgetg b
true;;
257 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
258 dolog " WxH %dx%d" l
.pagew l
.pageh
;
259 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
260 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
261 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
262 dolog " column %d" l
.pagecol
;
266 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
268 dolog " x0,y0=(% f, % f)" x0 y0
;
269 dolog " x1,y1=(% f, % f)" x1 y1
;
270 dolog " x2,y2=(% f, % f)" x2 y2
;
271 dolog " x3,y3=(% f, % f)" x3 y3
;
275 type multicolumns
= multicol
* pagegeom
276 and splitcolumns
= columncount
* pagegeom
277 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
278 and multicol
= columncount
* covercount
* covercount
280 and columncount
= int
281 and covercount
= int;;
284 { mutable scrollbw
: int
285 ; mutable scrollh
: int
286 ; mutable icase
: bool
287 ; mutable preload
: bool
288 ; mutable pagebias
: int
289 ; mutable verbose
: bool
290 ; mutable debug
: bool
291 ; mutable scrollstep
: int
292 ; mutable hscrollstep
: int
293 ; mutable maxhfit
: bool
294 ; mutable crophack
: bool
295 ; mutable autoscrollstep
: int
296 ; mutable maxwait
: float option
297 ; mutable hlinks
: bool
298 ; mutable underinfo
: bool
299 ; mutable interpagespace
: interpagespace
300 ; mutable zoom
: float
301 ; mutable presentation
: bool
302 ; mutable angle
: angle
305 ; mutable savebmarks
: bool
306 ; mutable proportional
: proportional
307 ; mutable trimmargins
: trimmargins
308 ; mutable trimfuzz
: irect
309 ; mutable memlimit
: memsize
310 ; mutable texcount
: texcount
311 ; mutable sliceheight
: sliceheight
312 ; mutable thumbw
: width
313 ; mutable jumpback
: bool
314 ; mutable bgcolor
: float * float * float
315 ; mutable bedefault
: bool
316 ; mutable scrollbarinpm
: bool
317 ; mutable tilew
: int
318 ; mutable tileh
: int
319 ; mutable mustoresize
: memsize
320 ; mutable checkers
: bool
321 ; mutable aalevel
: int
322 ; mutable urilauncher
: string
323 ; mutable pathlauncher
: string
324 ; mutable colorspace
: colorspace
325 ; mutable invert
: bool
326 ; mutable colorscale
: float
327 ; mutable redirectstderr
: bool
328 ; mutable ghyllscroll
: (int * int * int) option
329 ; mutable columns
: columns
330 ; mutable beyecolumns
: columncount
option
331 ; mutable selcmd
: string
332 ; mutable updatecurs
: bool
333 ; mutable keyhashes
: (string * keyhash
) list
334 ; mutable hfsize
: int
335 ; mutable pgscale
: float
339 | Cmulti
of multicolumns
340 | Csplit
of splitcolumns
343 type anchor
= pageno
* top
;;
345 type outline
= string * int * anchor
;;
347 type rect
= float * float * float * float * float * float * float * float;;
349 type tile
= opaque
* pixmapsize
* elapsed
350 and elapsed
= float;;
351 type pagemapkey
= pageno
* gen
;;
352 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
356 let emptyanchor = (0, 0.0);;
358 type infochange
= | Memused
| Docinfo
| Pdim
;;
360 class type uioh
= object
361 method display
: unit
362 method key
: int -> int -> uioh
363 method button
: int -> bool -> int -> int -> int -> uioh
364 method motion
: int -> int -> uioh
365 method pmotion
: int -> int -> uioh
366 method infochanged
: infochange
-> unit
367 method scrollpw
: (int * float * float)
368 method scrollph
: (int * float * float)
369 method modehash
: keyhash
373 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
374 | Textentry
of (textentry
* onleave
)
376 | LinkNav
of linktarget
377 and onleave
= leavetextentrystatus
-> unit
378 and leavetextentrystatus
= | Cancel
| Confirm
379 and helpitem
= string * int * action
382 | Action
of (uioh
-> uioh
)
384 | Ltexact
of (pageno
* int)
388 let isbirdseye = function Birdseye _
-> true | _
-> false;;
389 let istextentry = function Textentry _
-> true | _
-> false;;
393 | Loading
of (page
* gen
)
395 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
397 | Outlining
of outline list
400 let emptykeyhash = Hashtbl.create
0;;
401 let nouioh : uioh
= object (self
)
403 method key _ _
= self
404 method button _ _ _ _ _
= self
405 method motion _ _
= self
406 method pmotion _ _
= self
407 method infochanged _
= ()
408 method scrollpw
= (0, nan
, nan
)
409 method scrollph
= (0, nan
, nan
)
410 method modehash
= emptykeyhash
414 { mutable sr
: Unix.file_descr
415 ; mutable sw
: Unix.file_descr
416 ; mutable wsfd
: Unix.file_descr
417 ; mutable errfd
: Unix.file_descr
option
418 ; mutable stderr
: Unix.file_descr
419 ; mutable errmsgs
: Buffer.t
420 ; mutable newerrmsgs
: bool
424 ; mutable scrollw
: int
425 ; mutable hscrollh
: int
426 ; mutable anchor
: anchor
427 ; mutable ranchors
: (string * string * anchor
) list
429 ; mutable layout
: page list
430 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
431 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
432 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
433 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
434 ; mutable pagecount
: int
435 ; mutable currently
: currently
436 ; mutable mstate
: mstate
437 ; mutable searchpattern
: string
438 ; mutable rects
: (pageno
* recttype
* rect
) list
439 ; mutable rects1
: (pageno
* recttype
* rect
) list
440 ; mutable text
: string
441 ; mutable fullscreen
: (width
* height
) option
442 ; mutable mode
: mode
443 ; mutable uioh
: uioh
444 ; mutable outlines
: outline array
445 ; mutable bookmarks
: outline list
446 ; mutable path
: string
447 ; mutable password
: string
448 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
449 ; mutable memused
: memsize
451 ; mutable throttle
: (page list
* int * float) option
452 ; mutable autoscroll
: int option
453 ; mutable ghyll
: (int option -> unit)
454 ; mutable help
: helpitem array
455 ; mutable docinfo
: (int * string) list
456 ; mutable texid
: GlTex.texture_id
option
458 ; mutable prevzoom
: float
459 ; mutable progress
: float
460 ; mutable redisplay
: bool
461 ; mutable mpos
: mpos
462 ; mutable keystate
: keystate
463 ; mutable glinks
: bool
464 ; mutable prevcolumns
: (columns
* float) option
467 { pat
: string circbuf
468 ; pag
: string circbuf
469 ; nav
: anchor circbuf
470 ; sel
: string circbuf
492 ; presentation
= false
497 ; proportional
= true
498 ; trimmargins
= false
499 ; trimfuzz
= (0,0,0,0)
500 ; memlimit
= 32 lsl 20
505 ; bgcolor
= (0.5, 0.5, 0.5)
507 ; scrollbarinpm
= true
510 ; mustoresize
= 256 lsl 20
515 | Plinux
| Pfreebsd
| Pdragonflybsd
516 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
517 | Posx
-> "open \"%s\""
518 | Pcygwin
-> "cygstart \"%s\""
519 | Punknown
-> "echo %s")
520 ; pathlauncher
= "lp \"%s\""
523 | Plinux
| Pfreebsd
| Pdragonflybsd
524 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
531 ; redirectstderr
= false
539 let mk n
= (n
, Hashtbl.create
1) in
553 let findkeyhash c name
=
554 try List.assoc name c
.keyhashes
555 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
558 let conf = { defconf with angle
= defconf.angle
};;
560 let pgscale h
= truncate
(float h
*. conf.pgscale);;
563 { mutable fontsize
: int
564 ; mutable wwidth
: float
565 ; mutable maxrows
: int
577 fstate.fontsize
<- n
;
578 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
579 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
583 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
584 let len = String.length s
in
585 if colonpos >= 0 && colonpos + 3 < len
587 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
590 try String.rindex_from s
colonpos ' '
594 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
597 | "http" | "ftp" | "mailto" ->
599 try String.index_from s
colonpos ' '
600 with Not_found
-> len
602 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
610 if String.length
conf.urilauncher
= 0
611 then print_endline uri
613 let url = geturl uri
in
614 if String.length
url = 0
615 then print_endline uri
617 let re = Str.regexp
"%s" in
618 let command = Str.global_replace
re url conf.urilauncher
in
622 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
628 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
629 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
633 let strings = version () :: "" :: Help.keys
in
636 let url = geturl s
in
637 if String.length
url > 0
638 then (s
, 0, Action
(fun u
-> gotouri url; u
))
639 else (s
, 0, Noaction
)
644 let firstgeomcmds = "", [];;
651 ; stderr
= Unix.stderr
652 ; errmsgs
= Buffer.create
0
659 ; anchor
= emptyanchor
663 ; tilelru
= Queue.create
()
664 ; pagemap
= Hashtbl.create
10
665 ; tilemap
= Hashtbl.create
10
680 ; geomcmds
= firstgeomcmds
682 { nav
= cbnew 10 (0, 0.0)
709 Printf.kprintf prerr_endline fmt
711 Printf.kprintf ignore fmt
715 if String.length
conf.pathlauncher
= 0
716 then print_endline
state.path
718 let re = Str.regexp
"%s" in
719 let command = Str.global_replace
re state.path
conf.pathlauncher
in
723 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
729 type 'a t
= | Res
of 'a
| Exn
of exn
;;
732 try Res
(Unix.pipe ())
738 with exn
-> f
(Printexc.to_string exn
)
742 try Res
(Unix.dup fd
)
747 try Res
(Unix.dup2 fd1 fd2
)
752 let redirectstderr () =
753 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
754 if conf.redirectstderr
756 match Ne.pipe () with
758 dolog "failed to create stderr redirection pipes: %s"
759 (Printexc.to_string exn
)
762 begin match Ne.dup Unix.stderr
with
764 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
765 Ne.clo r
(clofail "pipe/r");
766 Ne.clo w
(clofail "pipe/w");
768 | Ne.Res dupstderr
->
769 begin match Ne.dup2 w
Unix.stderr
with
771 dolog "failed to dup2 to stderr: %s"
772 (Printexc.to_string exn
);
773 Ne.clo dupstderr
(clofail "stderr duplicate");
774 Ne.clo r
(clofail "redir pipe/r");
775 Ne.clo w
(clofail "redir pipe/w");
778 state.stderr
<- dupstderr
;
779 state.errfd
<- Some r
;
783 state.newerrmsgs
<- false;
784 begin match state.errfd
with
786 begin match Ne.dup2 state.stderr
Unix.stderr
with
788 dolog "failed to dup2 original stderr: %s"
789 (Printexc.to_string exn
)
791 Ne.clo fd
(clofail "dup of stderr");
792 Unix.dup2 state.stderr
Unix.stderr
;
797 prerr_string
(Buffer.contents
state.errmsgs
);
799 Buffer.clear
state.errmsgs
;
805 let postRedisplay who
=
807 then prerr_endline
("redisplay for " ^ who
);
808 state.redisplay
<- true;
812 let getopaque pageno
=
813 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
814 with Not_found
-> None
817 let putopaque pageno opaque
=
818 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
821 let pagetranslatepoint l x y
=
822 let dy = y
- l
.pagedispy
in
823 let y = dy + l
.pagey
in
824 let dx = x
- l
.pagedispx
in
825 let x = dx + l
.pagex
in
832 begin match getopaque l
.pageno
with
834 let x0 = l
.pagedispx
in
835 let x1 = x0 + l
.pagevw
in
836 let y0 = l
.pagedispy
in
837 let y1 = y0 + l
.pagevh
in
838 if y >= y0 && y <= y1 && x >= x0 && x <= x1
840 let px, py
= pagetranslatepoint l
x y in
841 match whatsunder opaque
px py
with
854 state.text
<- Printf.sprintf
"%c%s" c s
;
855 G.postRedisplay "showtext";
858 let undertext = function
861 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
862 | Utext s
-> "font: " ^ s
863 | Uunexpected s
-> "unexpected: " ^ s
864 | Ulaunch s
-> "launch: " ^ s
865 | Unamed s
-> "named: " ^ s
866 | Uremote
(filename
, pageno
) ->
867 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
870 let updateunder x y =
871 match getunder x y with
872 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
874 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
875 Wsi.setcursor
Wsi.CURSOR_INFO
876 | Ulinkgoto
(pageno
, _
) ->
878 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
879 Wsi.setcursor
Wsi.CURSOR_INFO
881 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
882 Wsi.setcursor
Wsi.CURSOR_TEXT
884 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
885 Wsi.setcursor
Wsi.CURSOR_INHERIT
887 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
888 Wsi.setcursor
Wsi.CURSOR_INHERIT
890 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
891 Wsi.setcursor
Wsi.CURSOR_INHERIT
892 | Uremote
(filename
, pageno
) ->
893 if conf.underinfo
then showtext 'r'
894 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
895 Wsi.setcursor
Wsi.CURSOR_INFO
898 let showlinktype under
=
904 let s = undertext under
in
909 let b = Buffer.create
(String.length
s + 1) in
910 Buffer.add_string
b s;
915 let colorspace_of_string s =
916 match String.lowercase
s with
920 | _
-> failwith
"invalid colorspace"
923 let int_of_colorspace = function
929 let colorspace_of_int = function
933 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
936 let colorspace_to_string = function
942 let intentry_with_suffix text key
=
944 if key
>= 32 && key
< 127
948 match Char.lowercase
c with
950 let text = addchar text c in
954 let text = addchar text c in
958 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
962 let multicolumns_to_string (n
, a
, b) =
964 then Printf.sprintf
"%d" n
965 else Printf.sprintf
"%d,%d,%d" n a
b;
968 let multicolumns_of_string s =
970 (int_of_string
s, 0, 0)
972 Scanf.sscanf
s "%u,%u,%u" (fun n a
b -> (n
, a
, b));
977 let n = Unix.read fd
s 0 4 in
978 if n != 4 then failwith
"incomplete read(len)";
980 lor (Char.code
s.[0] lsl 24)
981 lor (Char.code
s.[1] lsl 16)
982 lor (Char.code
s.[2] lsl 8)
983 lor (Char.code
s.[3] lsl 0)
985 let s = String.create
len in
986 let n = Unix.read fd
s 0 len in
987 if n != len then failwith
"incomplete read(data)";
991 let btod b = if b then 1 else 0;;
994 let b = Buffer.create
16 in
995 Buffer.add_string
b "llll";
998 let s = Buffer.contents
b in
999 let n = String.length
s in
1001 (* dolog "wcmd %S" (String.sub s 4 len); *)
1002 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1003 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1004 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1005 s.[3] <- Char.chr
(len land 0xff);
1006 let n'
= Unix.write
state.sw
s 0 n in
1007 if n'
!= n then failwith
"write failed";
1012 if conf.presentation
1014 let d = conf.winh
- h
in
1021 let rec f pn ph pi fh l
=
1023 | (n, _
, h
, _
) :: rest
->
1024 let ips = calcips h
in
1026 if conf.presentation
1029 if isbirdseye state.mode
&& pn
= 0
1034 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
1039 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
1043 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
1046 let fh = f 0 0 0 0 state.pdims
in
1051 match conf.columns
with
1052 | Csingle
-> calcheight ()
1053 | Cmulti
((c, _
, _
), b) ->
1054 let rec loop y h
n =
1058 if n = Array.length
b
1061 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
1067 loop max_int
0 (((Array.length
b - 1) / c) * c)
1069 if Array.length
b > 0
1071 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1076 let getpageyh pageno
=
1077 let rec f pn ph pi
y l
=
1079 | (n, _
, h
, _
) :: rest
->
1080 let ips = calcips h
in
1083 let h = if n = pageno
then h else ph
in
1084 if conf.presentation
&& n = pageno
1086 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
1088 y + (pageno
- pn
) * (ph
+ pi
), h
1090 let y = y + (if conf.presentation
then pi
else 0) in
1091 let y = y + (n - pn
) * (ph
+ pi
) in
1095 y + (pageno
- pn
) * (ph
+ pi
), ph
1097 f 0 0 0 0 state.pdims
1100 let getpageyh pageno
=
1101 match conf.columns
with
1102 | Csingle
-> getpageyh pageno
1104 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1108 let (_
, _
, y, (_
, _
, h, _
)) = b.(n) in
1112 let getpagedim pageno
=
1115 | (n, _
, _
, _
) as pdim
:: rest
->
1117 then (if n = pageno
then pdim
else ppdim
)
1122 f (-1, -1, -1, -1) state.pdims
1125 let getpagey pageno
= fst
(getpageyh pageno
);;
1127 let nogeomcmds cmds
=
1129 | s, [] -> String.length
s = 0
1134 let sh = sh - state.hscrollh
in
1135 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1136 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1138 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1139 let ips = calcips h in
1141 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1145 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1147 prev
, pdims
, pdimno
, 0
1149 let dy = dy + yinc in
1150 let py = py + yinc in
1151 if pageno
= state.pagecount
|| dy >= sh
1156 if py + h <= vy - yinc
1158 let py = py + h + ips in
1159 let dy = max
0 (py - y) in
1160 f ~pageno
:(pageno
+1)
1168 let pagey = vy - py in
1169 let pagevh = h - pagey in
1170 let pagevh = min
(sh - dy) pagevh in
1171 let off = if yinc > 0 then py - vy else 0 in
1172 let py = py + h + ips in
1175 if state.w
< conf.winw
- state.scrollw
1176 then (conf.winw
- state.scrollw
- state.w
) / 2
1179 let dispx = xoff + state.x in
1185 let lw = w
- pagex in
1186 min
lw (conf.winw
- state.scrollw
)
1190 ; pagedimno
= pdimno
1194 ; pagey = pagey + off
1196 ; pagevh = pagevh - off
1198 ; pagedispy
= dy + off
1202 let accu = e :: accu in
1203 f ~pageno
:(pageno
+1)
1224 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1225 let sh = sh - state.hscrollh
in
1226 let rec fold accu n =
1227 if n = Array.length
b
1230 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1233 || n = state.pagecount
- coverB
1234 || (n - coverA
) mod columns
= columns
- 1)
1240 let pagey = max
0 (y - vy) in
1241 let pagedispy = if pagey > 0 then 0 else vy - y in
1242 let pagedispx, pagex =
1244 if n = coverA
- 1 || n = state.pagecount
- coverB
1245 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1246 else dx + xoff + state.x
1253 let vw = conf.winw
- state.scrollw
- pagedispx in
1254 let pw = w
- pagex in
1257 let pagevh = min
(h - pagey) (sh - pagedispy) in
1258 if pagevw > 0 && pagevh > 0
1262 ; pagedimno
= pdimno
1269 ; pagedispx = pagedispx
1270 ; pagedispy = pagedispy
1282 List.rev
(fold [] 0)
1285 let layoutS (columns
, b) y sh =
1286 let sh = sh - state.hscrollh
in
1287 let rec fold accu n =
1288 if n = Array.length
b
1291 let pdimno, px, vy, (_
, pagew
, pageh
, xoff) = b.(n) in
1298 let x = xoff + state.x in
1299 let pagey = max
0 (y - vy) in
1300 let pagedispy = if pagey > 0 then 0 else vy - y in
1301 let pagedispx, pagex =
1315 let pagecolw = pagew
/columns
in
1317 if pagecolw < conf.winw
1318 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1322 let vw = conf.winw
- pagedispx - state.scrollw
in
1323 let pw = pagew
- pagex in
1326 let pagevw = min
pagevw pagecolw in
1327 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1328 if pagevw > 0 && pagevh > 0
1331 { pageno
= n/columns
1332 ; pagedimno
= pdimno
1339 ; pagedispx = pagedispx
1340 ; pagedispy = pagedispy
1341 ; pagecol
= n mod columns
1352 List.rev
(fold [] 0)
1356 if nogeomcmds state.geomcmds
1358 match conf.columns
with
1359 | Csingle
-> layout1 y sh
1360 | Cmulti
c -> layoutN c y sh
1361 | Csplit
s -> layoutS s y sh
1366 let y = state.y + incr
in
1368 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1373 let tilex = l
.pagex mod conf.tilew
in
1374 let tiley = l
.pagey mod conf.tileh
in
1376 let col = l
.pagex / conf.tilew
in
1377 let row = l
.pagey / conf.tileh
in
1379 let rec rowloop row y0 dispy
h =
1383 let dh = conf.tileh
- y0 in
1384 let dh = min
h dh in
1385 let rec colloop col x0 dispx w
=
1389 let dw = conf.tilew
- x0 in
1390 let dw = min w
dw in
1392 f col row dispx dispy
x0 y0 dw dh;
1393 colloop (col+1) 0 (dispx+dw) (w
-dw)
1396 colloop col tilex l
.pagedispx l
.pagevw;
1397 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1400 if l
.pagevw > 0 && l
.pagevh > 0
1401 then rowloop row tiley l
.pagedispy l
.pagevh;
1404 let gettileopaque l
col row =
1406 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1408 try Some
(Hashtbl.find
state.tilemap
key)
1409 with Not_found
-> None
1412 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1413 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1414 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1417 let drawtiles l color
=
1419 let f col row x y tilex tiley w
h =
1420 match gettileopaque l
col row with
1421 | Some
(opaque
, _
, t
) ->
1422 let params = x, y, w
, h, tilex, tiley in
1426 GlFunc.blend_func `zero `one_minus_src_color
;
1428 drawtile
params opaque
;
1430 then Gl.disable `blend
;
1433 let s = Printf.sprintf
1437 let w = measurestr
fstate.fontsize
s in
1438 GlMisc.push_attrib
[`current
];
1439 GlDraw.color
(0.0, 0.0, 0.0);
1441 (float (x-2), float (y-2))
1442 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1443 GlDraw.color
(1.0, 1.0, 1.0);
1444 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1445 GlMisc.pop_attrib
();
1450 let lw = conf.winw
- state.scrollw
- x in
1453 let lh = conf.winh
- y in
1456 begin match state.texid
with
1458 Gl.enable `texture_2d
;
1459 GlTex.bind_texture `texture_2d id
;
1462 and x1 = float (x+w)
1463 and y1 = float (y+h) in
1465 let tw = float w /. 64.0
1466 and th
= float h /. 64.0 in
1467 let tx0 = float tilex /. 64.0
1468 and ty0
= float tiley /. 64.0 in
1470 and ty1
= ty0
+. th
in
1471 GlDraw.begins `quads
;
1472 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1473 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1474 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1475 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1478 Gl.disable `texture_2d
;
1480 GlDraw.color
(1.0, 1.0, 1.0);
1483 (float (x+w), float (y+h));
1485 if w > 128 && h > fstate.fontsize
+ 10
1487 GlDraw.color
(0.0, 0.0, 0.0);
1490 then (col*conf.tilew
, row*conf.tileh
)
1493 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1500 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1502 let tilevisible1 l
x y =
1504 and ax1
= l
.pagex + l
.pagevw
1506 and ay1
= l
.pagey + l
.pagevh in
1510 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1511 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1513 let rx0 = max
ax0 bx0
1514 and ry0
= max ay0 by0
1515 and rx1
= min ax1
bx1
1516 and ry1
= min ay1 by1
in
1518 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1519 nonemptyintersection
1522 let tilevisible layout n x y =
1523 let rec findpageinlayout m
= function
1524 | l
:: rest
when l
.pageno
= n ->
1525 tilevisible1 l
x y || (
1526 match conf.columns
with
1527 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1530 | _
:: rest
-> findpageinlayout 0 rest
1533 findpageinlayout 0 layout;
1536 let tileready l
x y =
1537 tilevisible1 l
x y &&
1538 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1541 let tilepage n p
layout =
1542 let rec loop = function
1546 let f col row _ _ _ _ _ _
=
1547 if state.currently
= Idle
1549 match gettileopaque l
col row with
1552 let x = col*conf.tilew
1553 and y = row*conf.tileh
in
1555 let w = l
.pagew
- x in
1559 let h = l
.pageh
- y in
1562 wcmd "tile %s %d %d %d %d" p
x y w h;
1565 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1566 conf.tilew
, conf.tileh
1575 if nogeomcmds state.geomcmds
1579 let preloadlayout visiblepages
=
1580 let presentation = conf.presentation in
1581 let interpagespace = conf.interpagespace in
1582 conf.presentation <- false;
1583 conf.interpagespace <- 0;
1585 match visiblepages
with
1586 | [] -> if state.y >= state.maxy
then state.maxy
else 0
1587 | l
:: _
-> getpagey l
.pageno
+ (l
.pagey - min
0 l
.pagedispy)
1589 let y = if y < conf.winh
then 0 else y - conf.winh
in
1590 let h = conf.winh
*3 in
1591 let pages = layout y h in
1592 conf.presentation <- presentation;
1593 conf.interpagespace <- interpagespace;
1598 let rec loop pages =
1599 if state.currently
!= Idle
1604 begin match getopaque l
.pageno
with
1606 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1607 state.currently
<- Loading
(l
, state.gen
);
1609 tilepage l
.pageno opaque
pages;
1614 if nogeomcmds state.geomcmds
1620 if conf.preload && state.currently
= Idle
1621 then load (preloadlayout pages);
1624 let layoutready layout =
1625 let rec fold all ls
=
1626 all
&& match ls
with
1628 let seen = ref false in
1629 let allvisible = ref true in
1630 let foo col row _ _ _ _ _ _
=
1632 allvisible := !allvisible &&
1633 begin match gettileopaque l
col row with
1639 fold (!seen && !allvisible) rest
1642 let alltilesvisible = fold true layout in
1647 let y = bound y 0 state.maxy
in
1648 let y, layout, proceed
=
1649 match conf.maxwait
with
1650 | Some time
when state.ghyll
== noghyll ->
1651 begin match state.throttle
with
1653 let layout = layout y conf.winh
in
1654 let ready = layoutready layout in
1658 state.throttle
<- Some
(layout, y, now ());
1660 else G.postRedisplay "gotoy showall (None)";
1662 | Some
(_
, _
, started
) ->
1663 let dt = now () -. started
in
1666 state.throttle
<- None
;
1667 let layout = layout y conf.winh
in
1669 G.postRedisplay "maxwait";
1676 let layout = layout y conf.winh
in
1677 if true || layoutready layout
1678 then G.postRedisplay "gotoy ready";
1684 state.layout <- layout;
1685 begin match state.mode
with
1686 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
1687 let rec loop = function
1689 state.mode
<- LinkNav
(Ltgendir
0)
1690 | l
:: _
when l
.pageno
= pageno
->
1691 begin match getopaque pageno
with
1693 state.mode
<- LinkNav
(Ltgendir
0)
1695 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1696 if not
(x0 >= l
.pagex && x1 <= l
.pagex + l
.pagevw
1697 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1698 then state.mode
<- LinkNav
(Ltgendir
0)
1700 | _
:: rest
-> loop rest
1705 begin match state.mode
with
1706 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1707 if not
(pagevisible layout pageno
)
1709 match state.layout with
1712 state.mode
<- Birdseye
(
1713 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1716 | LinkNav
(Ltgendir dir
as lt
) ->
1718 let rec loop = function
1721 match getopaque l
.pageno
with
1727 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1729 if dir
> 0 then LDfirst
else LDlast
1735 | Lnotfound
-> loop rest
1737 showlinktype (getlink opaque
n);
1738 Ltexact
(l
.pageno
, n)
1742 state.mode
<- LinkNav
linknav
1747 state.ghyll
<- noghyll;
1750 let mx, my
= state.mpos
in
1755 let conttiling pageno opaque
=
1756 tilepage pageno opaque
1757 (if conf.preload then preloadlayout state.layout else state.layout)
1760 let gotoy_and_clear_text y =
1761 if not
conf.verbose
then state.text <- "";
1766 match state.layout with
1769 let coloff = l
.pagecol
* l
.pageh
in
1771 (float (l
.pagey - l
.pagedispy) +. float coloff) /. float l
.pageh
)
1774 let getanchory (n, top
) =
1775 let y, h = getpageyh n in
1776 y + (truncate
(top
*. float h));
1779 let gotoanchor anchor
=
1780 gotoy (getanchory anchor
);
1784 cbput state.hists
.nav
(getanchor ());
1788 let anchor = cbgetc state.hists
.nav dir
in
1793 let scroll f n a
b =
1794 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1796 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1798 then s (float f /. float a
)
1801 then 1.0 -. s ((float (f-b) /. float (n-b)))
1808 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1809 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1811 let ins = float a
*. iv1
1812 and outs
= float (n-b) *. iv1 in
1814 ins +. outs
+. float ones
1816 let rec set (_N
, _A
, _B
) y sy
=
1817 let sum = summa
1.0 _N _A _B
in
1818 let dy = float (y - sy
) in
1822 then state.ghyll
<- noghyll
1825 let s = scroll n _N _A _B
in
1826 let y1 = y1 +. ((s *. dy) /. sum) in
1827 gotoy_and_clear_text (truncate
y1);
1828 state.ghyll
<- gf (n+1) y1;
1832 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1834 gf 0 (float state.y)
1837 match conf.ghyllscroll
with
1839 gotoy_and_clear_text y
1841 if state.ghyll
== noghyll
1842 then set nab
y state.y
1843 else state.ghyll
(Some
y)
1846 let gotopage n top
=
1847 let y, h = getpageyh n in
1848 let y = y + (truncate
(top
*. float h)) in
1852 let gotopage1 n top
=
1853 let y = getpagey n in
1858 let invalidate s f =
1863 match state.geomcmds
with
1864 | ps
, [] when String.length ps
= 0 ->
1866 state.geomcmds
<- s, [];
1869 state.geomcmds
<- ps
, [s, f];
1871 | ps
, (s'
, _
) :: rest
when s'
= s ->
1872 state.geomcmds
<- ps
, ((s, f) :: rest
);
1875 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1878 let opendoc path password
=
1880 state.password
<- password
;
1881 state.gen
<- state.gen
+ 1;
1882 state.docinfo
<- [];
1884 setaalevel
conf.aalevel
;
1885 Wsi.settitle
("llpp " ^
Filename.basename path
);
1886 wcmd "open %s\000%s\000" path password
;
1887 invalidate "reqlayout"
1889 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1893 let c = c *. conf.colorscale
in
1897 let scalecolor2 (r
, g
, b) =
1898 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1901 let docolumns = function
1904 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1905 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1906 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1907 let rec fixrow m
= if m
= pageno
then () else
1908 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1911 let y = y + (rowh
- h) / 2 in
1912 a.(m
) <- (pdimno, x, y, pdim
);
1916 if pageno
= state.pagecount
1917 then fixrow (((pageno
- 1) / columns
) * columns
)
1919 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1921 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1922 pdimno+1, pdim
, rest
1927 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1929 (conf.winw
- state.scrollw
- w) / 2,
1930 y + rowh
+ conf.interpagespace, h
1933 if (pageno
- coverA
) mod columns
= 0
1934 then 0, y + rowh
+ conf.interpagespace, h
1935 else x, y, max rowh
h
1938 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1939 then fixrow (pageno
- columns
);
1940 a.(pageno
) <- (pdimno, x, y, pdim
);
1941 let x = x + w + xoff*2 + conf.interpagespace in
1942 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1944 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1945 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1948 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1949 let rec loop pageno
pdimno pdim
y pdims
=
1950 if pageno
= state.pagecount
1953 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1955 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1956 pdimno+1, pdim
, rest
1961 let rec loop1 n x y =
1962 if n = c then y else (
1963 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1964 loop1 (n+1) (x+cw) (y + h + conf.interpagespace)
1967 let y = loop1 0 0 y in
1968 loop (pageno
+1) pdimno pdim
y pdims
1970 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1971 conf.columns
<- Csplit
(c, a);
1975 docolumns conf.columns
;
1976 state.maxy
<- calcheight ();
1978 if state.w <= conf.winw
- state.scrollw
1982 match state.mode
with
1983 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1984 let y, h = getpageyh pageno
in
1985 let top = (conf.winh
- h) / 2 in
1986 gotoy (max
0 (y - top))
1987 | _
-> gotoanchor state.anchor
1991 GlDraw.viewport
0 0 w h;
1992 let firsttime = state.geomcmds
== firstgeomcmds in
1993 if not
firsttime && nogeomcmds state.geomcmds
1994 then state.anchor <- getanchor ();
1997 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2000 setfontsize fstate.fontsize
;
2001 GlMat.mode `modelview
;
2002 GlMat.load_identity
();
2004 GlMat.mode `projection
;
2005 GlMat.load_identity
();
2006 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2007 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2008 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2013 else float state.x /. float state.w
2015 invalidate "geometry"
2019 then state.x <- truncate
(relx *. float w);
2021 match conf.columns
with
2023 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
2024 | Csplit
(c, _
) -> w * c
2026 wcmd "geometry %d %d" w h);
2030 let len = String.length
state.text in
2033 match state.mode
with
2036 let h, _
, _
= state.uioh#scrollpw
in
2042 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2043 (x+.w, float (conf.winh
- hscrollh))
2046 let w = float (conf.winw
- state.scrollw
- 1) in
2047 if state.progress
>= 0.0 && state.progress
< 1.0
2049 GlDraw.color
(0.3, 0.3, 0.3);
2050 let w1 = w *. state.progress
in
2052 GlDraw.color
(0.0, 0.0, 0.0);
2056 GlDraw.color
(0.0, 0.0, 0.0);
2060 GlDraw.color
(1.0, 1.0, 1.0);
2061 drawstring fstate.fontsize
2062 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2065 match state.mode
with
2066 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
2070 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2072 Printf.sprintf
"%s%s_" prefix
text
2081 if not
(istextentry state.mode
)
2083 let s1 = "(press 'e' to review error messasges)" in
2084 if String.length
s > 0 then s ^
" " ^
s1 else s1
2089 if String.length
s > 0
2094 let len = Queue.length
state.tilelru
in
2096 if state.memused
<= conf.memlimit
2101 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2102 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2103 let (_
, pw, ph
, _
) = getpagedim n in
2106 && colorspace
= conf.colorspace
2107 && angle
= conf.angle
2112 match state.throttle
with
2115 then preloadlayout state.layout
2117 | Some
(layout, _
, _
) ->
2120 let x = col*conf.tilew
2121 and y = row*conf.tileh
in
2122 tilevisible layout n x y
2124 then Queue.push lruitem
state.tilelru
2126 wcmd "freetile %s" p
;
2127 state.memused
<- state.memused
- s;
2128 state.uioh#infochanged Memused
;
2129 Hashtbl.remove
state.tilemap k
;
2138 Queue.iter
(fun (k
, p
, s) ->
2139 wcmd "freetile %s" p
;
2140 state.memused
<- state.memused
- s;
2141 state.uioh#infochanged Memused
;
2142 Hashtbl.remove
state.tilemap k
;
2144 Queue.clear
state.tilelru
;
2148 let logcurrently = function
2149 | Idle
-> dolog "Idle"
2150 | Loading
(l
, gen
) ->
2151 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2152 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2154 "Tiling %d[%d,%d] page=%s cs=%s angle"
2155 l
.pageno
col row pageopaque
2156 (colorspace_to_string colorspace
)
2158 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2159 angle gen
conf.angle
state.gen
2161 conf.tilew
conf.tileh
2168 (* dolog "%S" cmds; *)
2171 try String.index cmds ' '
2172 with Not_found
-> -1
2177 let l = String.length cmds
in
2178 let op = String.sub cmds
0 spacepos in
2180 if l - spacepos < 2 then ""
2181 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2186 state.uioh#infochanged Pdim
;
2190 state.rects
<- state.rects1
;
2191 G.postRedisplay "clearrects";
2195 try Scanf.sscanf
args "%u" (fun n -> n)
2197 dolog "error processing 'continue' %S: %s"
2198 cmds
(Printexc.to_string exn
);
2201 state.pagecount
<- n;
2202 begin match state.currently
with
2204 state.currently
<- Idle
;
2205 state.outlines
<- Array.of_list
(List.rev
l)
2209 let cur, cmds
= state.geomcmds
in
2210 if String.length
cur = 0
2211 then failwith
"umpossible";
2213 begin match List.rev cmds
with
2215 state.geomcmds
<- "", [];
2219 state.geomcmds
<- s, List.rev rest
;
2221 if conf.maxwait
= None
2222 then G.postRedisplay "continue";
2232 then showtext ' '
args
2235 let progress, text =
2237 Scanf.sscanf
args "%f %n"
2239 f, String.sub
args pos
(String.length
args - pos
))
2241 dolog "error processing 'progress' %S: %s"
2242 cmds
(Printexc.to_string exn
);
2246 state.progress <- progress;
2247 G.postRedisplay "progress"
2250 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2252 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2253 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2254 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2256 dolog "error processing 'firstmatch' %S: %s"
2257 cmds
(Printexc.to_string exn
);
2260 let y = (getpagey pageno) + truncate
y0 in
2263 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2266 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2268 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2269 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2270 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2272 dolog "error processing 'match' %S: %s"
2273 cmds
(Printexc.to_string exn
);
2277 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2282 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2284 dolog "error processing 'page' %S: %s"
2285 cmds
(Printexc.to_string exn
);
2288 begin match state.currently
with
2289 | Loading
(l, gen
) ->
2290 vlog "page %d took %f sec" l.pageno t
;
2291 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2292 begin match state.throttle
with
2294 let preloadedpages =
2296 then preloadlayout state.layout
2301 Set.Make
(struct type t
= int let compare = (-) end) in
2303 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2304 IntSet.empty
preloadedpages
2307 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2308 if not
(IntSet.mem
pageno set)
2310 wcmd "freepage %s" opaque
;
2316 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2319 state.currently
<- Idle
;
2322 tilepage l.pageno pageopaque state.layout;
2324 load preloadedpages;
2325 if pagevisible state.layout l.pageno
2326 && layoutready state.layout
2327 then G.postRedisplay "page";
2330 | Some
(layout, _
, _
) ->
2331 state.currently
<- Idle
;
2332 tilepage l.pageno pageopaque layout;
2337 dolog "Inconsistent loading state";
2338 logcurrently state.currently
;
2343 let (x, y, opaque
, size
, t
) =
2345 Scanf.sscanf
args "%u %u %s %u %f"
2346 (fun x y p size t
-> (x, y, p
, size
, t
))
2348 dolog "error processing 'tile' %S: %s"
2349 cmds
(Printexc.to_string exn
);
2352 begin match state.currently
with
2353 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2354 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2356 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2358 wcmd "freetile %s" opaque
;
2359 state.currently
<- Idle
;
2363 puttileopaque l col row gen cs angle opaque size t
;
2364 state.memused
<- state.memused
+ size
;
2365 state.uioh#infochanged Memused
;
2367 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2368 opaque
, size
) state.tilelru
;
2371 match state.throttle
with
2372 | None
-> state.layout
2373 | Some
(layout, _
, _
) -> layout
2376 state.currently
<- Idle
;
2378 && conf.colorspace
= cs
2379 && conf.angle
= angle
2380 && tilevisible layout l.pageno x y
2381 then conttiling l.pageno pageopaque;
2383 begin match state.throttle
with
2385 preload state.layout;
2387 && conf.colorspace
= cs
2388 && conf.angle
= angle
2389 && tilevisible state.layout l.pageno x y
2390 then G.postRedisplay "tile nothrottle";
2392 | Some
(layout, y, _
) ->
2393 let ready = layoutready layout in
2397 state.layout <- layout;
2398 state.throttle
<- None
;
2399 G.postRedisplay "throttle";
2406 dolog "Inconsistent tiling state";
2407 logcurrently state.currently
;
2414 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2416 dolog "error processing 'pdim' %S: %s"
2417 cmds
(Printexc.to_string exn
);
2420 state.uioh#infochanged Pdim
;
2421 state.pdims
<- pdim :: state.pdims
2424 let (l, n, t
, h, pos
) =
2426 Scanf.sscanf
args "%u %u %d %u %n"
2427 (fun l n t
h pos
-> l, n, t
, h, pos
)
2429 dolog "error processing 'o' %S: %s"
2430 cmds
(Printexc.to_string exn
);
2433 let s = String.sub
args pos
(String.length
args - pos
) in
2434 let outline = (s, l, (n, float t
/. float h)) in
2435 begin match state.currently
with
2436 | Outlining outlines
->
2437 state.currently
<- Outlining
(outline :: outlines
)
2439 state.currently
<- Outlining
[outline]
2441 dolog "invalid outlining state";
2442 logcurrently currently
2446 state.docinfo
<- (1, args) :: state.docinfo
2449 state.uioh#infochanged Docinfo
;
2450 state.docinfo
<- List.rev
state.docinfo
2453 dolog "unknown cmd `%S'" cmds
2458 let action = function
2459 | HCprev
-> cbget cb ~
-1
2460 | HCnext
-> cbget cb
1
2461 | HCfirst
-> cbget cb ~
-(cb
.rc)
2462 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2463 and cancel
() = cb
.rc <- rc
2467 let search pattern forward
=
2468 if String.length pattern
> 0
2471 match state.layout with
2474 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2476 wcmd "search %d %d %d %d,%s\000"
2477 (btod conf.icase
) pn py (btod forward
) pattern
;
2480 let intentry text key =
2482 if key >= 32 && key < 127
2488 let text = addchar text c in
2492 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2496 let linknentry text key =
2498 if key >= 32 && key < 127
2504 let text = addchar text c in
2508 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2513 if String.length
s > 0
2516 let l = String.length
s in
2517 let rec loop pos
n = if pos
= l then n else
2518 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2519 loop (pos
+1) (n*26 + m)
2522 let rec loop n = function
2525 match getopaque l.pageno with
2526 | None
-> loop n rest
2528 let m = getlinkcount opaque
in
2531 let under = getlink opaque
n in
2534 else loop (n-m) rest
2536 loop n state.layout;
2540 let textentry text key =
2541 if key land 0xff00 = 0xff00
2543 else TEcont
(text ^
Wsi.toutf8
key)
2546 let reqlayout angle proportional
=
2547 match state.throttle
with
2549 if nogeomcmds state.geomcmds
2550 then state.anchor <- getanchor ();
2551 conf.angle
<- angle
mod 360;
2554 match state.mode
with
2555 | LinkNav _
-> state.mode
<- View
2558 conf.proportional
<- proportional
;
2559 invalidate "reqlayout"
2560 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2564 let settrim trimmargins trimfuzz
=
2565 if nogeomcmds state.geomcmds
2566 then state.anchor <- getanchor ();
2567 conf.trimmargins
<- trimmargins
;
2568 conf.trimfuzz
<- trimfuzz
;
2569 let x0, y0, x1, y1 = trimfuzz
in
2570 invalidate "settrim"
2572 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2573 Hashtbl.iter
(fun _ opaque
->
2574 wcmd "freepage %s" opaque
;
2576 Hashtbl.clear
state.pagemap
;
2580 match state.throttle
with
2582 let zoom = max
0.01 zoom in
2583 if zoom <> conf.zoom
2585 state.prevzoom
<- conf.zoom;
2587 reshape conf.winw
conf.winh
;
2588 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2591 | Some
(layout, y, started
) ->
2593 match conf.maxwait
with
2597 let dt = now () -. started
in
2605 let setcolumns mode columns coverA coverB
=
2606 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2610 then showtext '
!'
"split mode doesn't work in bird's eye"
2612 conf.columns
<- Csplit
(-columns
, [||]);
2620 conf.columns
<- Csingle
;
2625 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2629 reshape conf.winw
conf.winh
;
2632 let enterbirdseye () =
2633 let zoom = float conf.thumbw
/. float conf.winw
in
2634 let birdseyepageno =
2635 let cy = conf.winh
/ 2 in
2639 let rec fold best
= function
2642 let d = cy - (l.pagedispy + l.pagevh/2)
2643 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2644 if abs
d < abs dbest
2651 state.mode
<- Birdseye
(
2652 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2655 conf.presentation <- false;
2656 conf.interpagespace <- 10;
2657 conf.hlinks
<- false;
2659 state.mstate
<- Mnone
;
2660 conf.maxwait
<- None
;
2662 match conf.beyecolumns
with
2665 Cmulti
((c, 0, 0), [||])
2668 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2671 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2676 reshape conf.winw
conf.winh
;
2679 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2681 conf.zoom <- c.zoom;
2682 conf.presentation <- c.presentation;
2683 conf.interpagespace <- c.interpagespace;
2684 conf.maxwait
<- c.maxwait
;
2685 conf.hlinks
<- c.hlinks
;
2686 conf.beyecolumns
<- (
2687 match conf.columns
with
2688 | Cmulti
((c, _
, _
), _
) -> Some
c
2690 | Csplit _
-> failwith
"leaving bird's eye split mode"
2693 match c.columns
with
2694 | Cmulti
(c, _
) -> Cmulti
(c, [||])
2695 | Csingle
-> Csingle
2696 | Csplit
(c, _
) -> Csplit
(c, [||])
2701 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2704 reshape conf.winw
conf.winh
;
2705 state.anchor <- if goback
then anchor else (pageno, 0.0);
2708 let togglebirdseye () =
2709 match state.mode
with
2710 | Birdseye vals
-> leavebirdseye vals
true
2711 | View
-> enterbirdseye ()
2715 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2716 let pageno = max
0 (pageno - incr
) in
2717 let rec loop = function
2718 | [] -> gotopage1 pageno 0
2719 | l :: _
when l.pageno = pageno ->
2720 if l.pagedispy >= 0 && l.pagey = 0
2721 then G.postRedisplay "upbirdseye"
2722 else gotopage1 pageno 0
2723 | _
:: rest
-> loop rest
2726 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2729 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2730 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2731 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2732 let rec loop = function
2734 let y, h = getpageyh pageno in
2735 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2737 | l :: _
when l.pageno = pageno ->
2738 if l.pagevh != l.pageh
2739 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2740 else G.postRedisplay "downbirdseye"
2741 | _
:: rest
-> loop rest
2746 let optentry mode _
key =
2747 let btos b = if b then "on" else "off" in
2748 if key >= 32 && key < 127
2750 let c = Char.chr
key in
2754 try conf.scrollstep
<- int_of_string
s with exc
->
2755 state.text <- Printf.sprintf
"bad integer `%s': %s"
2756 s (Printexc.to_string exc
)
2758 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2763 conf.autoscrollstep
<- int_of_string
s;
2764 if state.autoscroll
<> None
2765 then state.autoscroll
<- Some
conf.autoscrollstep
2767 state.text <- Printf.sprintf
"bad integer `%s': %s"
2768 s (Printexc.to_string exc
)
2770 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2775 let n, a, b = multicolumns_of_string s in
2776 setcolumns mode
n a b;
2778 state.text <- Printf.sprintf
"bad columns `%s': %s"
2779 s (Printexc.to_string exc
)
2781 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2786 let zoom = float (int_of_string
s) /. 100.0 in
2789 state.text <- Printf.sprintf
"bad integer `%s': %s"
2790 s (Printexc.to_string exc
)
2792 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2797 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2799 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2800 begin match mode
with
2802 leavebirdseye beye
false;
2807 state.text <- Printf.sprintf
"bad integer `%s': %s"
2808 s (Printexc.to_string exc
)
2810 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2815 Some
(int_of_string
s)
2817 state.text <- Printf.sprintf
"bad integer `%s': %s"
2818 s (Printexc.to_string exc
);
2821 | Some angle
-> reqlayout angle
conf.proportional
2824 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2827 conf.icase
<- not
conf.icase
;
2828 TEdone
("case insensitive search " ^
(btos conf.icase
))
2831 conf.preload <- not
conf.preload;
2833 TEdone
("preload " ^
(btos conf.preload))
2836 conf.verbose
<- not
conf.verbose
;
2837 TEdone
("verbose " ^
(btos conf.verbose
))
2840 conf.debug
<- not
conf.debug
;
2841 TEdone
("debug " ^
(btos conf.debug
))
2844 conf.maxhfit
<- not
conf.maxhfit
;
2845 state.maxy
<- calcheight ();
2846 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2849 conf.crophack
<- not
conf.crophack
;
2850 TEdone
("crophack " ^
btos conf.crophack
)
2854 match conf.maxwait
with
2856 conf.maxwait
<- Some infinity
;
2857 "always wait for page to complete"
2859 conf.maxwait
<- None
;
2860 "show placeholder if page is not ready"
2865 conf.underinfo
<- not
conf.underinfo
;
2866 TEdone
("underinfo " ^
btos conf.underinfo
)
2869 conf.savebmarks
<- not
conf.savebmarks
;
2870 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2876 match state.layout with
2881 conf.interpagespace <- int_of_string
s;
2882 docolumns conf.columns
;
2883 state.maxy
<- calcheight ();
2884 let y = getpagey pageno in
2887 state.text <- Printf.sprintf
"bad integer `%s': %s"
2888 s (Printexc.to_string exc
)
2890 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2893 reqlayout conf.angle
(not
conf.proportional
);
2894 TEdone
("proportional display " ^
btos conf.proportional
)
2897 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2898 TEdone
("trim margins " ^
btos conf.trimmargins
)
2901 conf.invert
<- not
conf.invert
;
2902 TEdone
("invert colors " ^
btos conf.invert
)
2906 cbput state.hists
.sel
s;
2909 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2910 textentry, ondone, true)
2913 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2919 class type lvsource
= object
2920 method getitemcount
: int
2921 method getitem
: int -> (string * int)
2922 method hasaction
: int -> bool
2931 method getactive
: int
2932 method getfirst
: int
2933 method getqsearch
: string
2934 method setqsearch
: string -> unit
2938 class virtual lvsourcebase
= object
2939 val mutable m_active
= 0
2940 val mutable m_first
= 0
2941 val mutable m_qsearch
= ""
2942 val mutable m_pan
= 0
2943 method getactive
= m_active
2944 method getfirst
= m_first
2945 method getqsearch
= m_qsearch
2946 method getpan
= m_pan
2947 method setqsearch
s = m_qsearch
<- s
2950 let withoutlastutf8 s =
2951 let len = String.length
s in
2959 let b = Char.code
s.[pos
] in
2960 if b land 0b110000 = 0b11000000
2965 if Char.code
s.[len-1] land 0x80 = 0
2969 String.sub
s 0 first;
2972 let textentrykeyboard
2973 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2975 state.mode
<- Textentry
(te
, onleave
);
2978 G.postRedisplay "textentrykeyboard enttext";
2980 let histaction cmd
=
2983 | Some
(action, _
) ->
2984 state.mode
<- Textentry
(
2985 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2987 G.postRedisplay "textentry histaction"
2990 | 0xff08 -> (* backspace *)
2991 let s = withoutlastutf8 text in
2992 let len = String.length
s in
2993 if cancelonempty
&& len = 0
2996 G.postRedisplay "textentrykeyboard after cancel";
2999 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3005 G.postRedisplay "textentrykeyboard after confirm"
3007 | 0xff52 -> histaction HCprev
3008 | 0xff54 -> histaction HCnext
3009 | 0xff50 -> histaction HCfirst
3010 | 0xff57 -> histaction HClast
3012 | 0xff1b -> (* escape*)
3013 if String.length
text = 0
3015 begin match opthist
with
3017 | Some
(_
, onhistcancel
) -> onhistcancel
()
3021 G.postRedisplay "textentrykeyboard after cancel2"
3024 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3027 | 0xff9f | 0xffff -> () (* delete *)
3029 | _
when key != 0 && key land 0xff00 != 0xff00 ->
3030 begin match onkey
text key with
3034 G.postRedisplay "textentrykeyboard after confirm2";
3037 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3041 G.postRedisplay "textentrykeyboard after cancel3"
3044 state.mode
<- Textentry
(te
, onleave
);
3045 G.postRedisplay "textentrykeyboard switch";
3049 vlog "unhandled key %s" (Wsi.keyname
key)
3052 let firstof first active
=
3053 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3054 then max
0 (active
- (fstate.maxrows
/2))
3058 let calcfirst first active
=
3061 let rows = active
- first in
3062 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3066 let scrollph y maxy
=
3067 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3068 let sh = float conf.winh
/. sh in
3069 let sh = max
sh (float conf.scrollh
) in
3074 else float y /. float maxy
3076 let position = (float conf.winh
-. sh) *. percent in
3079 if position +. sh > float conf.winh
3080 then float conf.winh
-. sh
3086 let coe s = (s :> uioh
);;
3088 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3090 val m_pan
= source#getpan
3091 val m_first
= source#getfirst
3092 val m_active
= source#getactive
3093 val m_qsearch
= source#getqsearch
3094 val m_prev_uioh
= state.uioh
3096 method private elemunder
y =
3097 let n = y / (fstate.fontsize
+1) in
3098 if m_first
+ n < source#getitemcount
3100 if source#hasaction
(m_first
+ n)
3101 then Some
(m_first
+ n)
3108 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3109 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3110 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3111 GlDraw.color
(1., 1., 1.);
3112 Gl.enable `texture_2d
;
3113 let fs = fstate.fontsize
in
3115 let ww = fstate.wwidth
in
3116 let tabw = 30.0*.ww in
3117 let itemcount = source#getitemcount
in
3119 if (row - m_first
) * nfs > conf.winh
3122 if row >= 0 && row < itemcount
3124 let (s, level
) = source#getitem
row in
3125 let y = (row - m_first
) * nfs in
3126 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3129 Gl.disable `texture_2d
;
3130 GlDraw.polygon_mode `both `line
;
3131 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3132 GlDraw.rect (1., float (y + 1))
3133 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3134 GlDraw.polygon_mode `both `fill
;
3135 GlDraw.color
(1., 1., 1.);
3136 Gl.enable `texture_2d
;
3139 let drawtabularstring s =
3140 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3143 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3146 let len = String.length
s - tabpos - 1 in
3147 let s1 = String.sub
s 0 tabpos
3148 and s2
= String.sub
s (tabpos + 1) len in
3149 let nx = drawstr x s1 in
3151 let x = x +. (max
tabw sw) in
3158 let _ = drawtabularstring s in
3165 Gl.disable `texture_2d
;
3167 method updownlevel incr
=
3168 let len = source#getitemcount
in
3170 if m_active
>= 0 && m_active
< len
3171 then snd
(source#getitem m_active
)
3175 if i
= len then i
-1 else if i
= -1 then 0 else
3176 let _, l = source#getitem i
in
3177 if l != curlevel then i
else flow (i
+incr
)
3179 let active = flow m_active
in
3180 let first = calcfirst m_first
active in
3181 G.postRedisplay "outline updownlevel";
3182 {< m_active
= active; m_first
= first >}
3184 method private key1
key mask
=
3185 let set1 active first qsearch
=
3186 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3188 let search active pattern incr
=
3191 if n >= 0 && n < source#getitemcount
3193 let s, _ = source#getitem
n in
3195 (try ignore
(Str.search_forward
re s 0); true
3196 with Not_found
-> false)
3198 else loop (n + incr
)
3205 let re = Str.regexp_case_fold pattern
in
3211 let itemcount = source#getitemcount
in
3212 let find start incr
=
3214 if i
= -1 || i
= itemcount
3217 if source#hasaction i
3219 else find (i
+ incr
)
3224 let set active first =
3225 let first = bound first 0 (itemcount - fstate.maxrows
) in
3227 coe {< m_active
= active; m_first
= first >}
3230 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3232 let incr1 = if incr
> 0 then 1 else -1 in
3233 if isvisible m_first m_active
3236 let next = m_active
+ incr
in
3238 if next < 0 || next >= itemcount
3240 else find next incr1
3242 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3248 let first = m_first
+ incr
in
3249 let first = bound first 0 (itemcount - 1) in
3251 let next = m_active
+ incr
in
3252 let next = bound next 0 (itemcount - 1) in
3255 let active = if next = -1 then m_active
else next in
3258 let first = min
next m_first
in
3260 if abs
(next - first) > fstate.maxrows
3266 let first = m_first
+ incr
in
3267 let first = bound first 0 (itemcount - 1) in
3269 let next = m_active
+ incr
in
3270 let next = bound next 0 (itemcount - 1) in
3271 let next = find next incr1 in
3273 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3275 let active = if m_active
= -1 then next else m_active
in
3280 if isvisible first active
3286 G.postRedisplay "listview navigate";
3290 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3291 let incr = if key = 0x72 then -1 else 1 in
3293 match search (m_active
+ incr) m_qsearch
incr with
3295 state.text <- m_qsearch ^
" [not found]";
3298 state.text <- m_qsearch
;
3299 active, firstof m_first
active
3301 G.postRedisplay "listview ctrl-r/s";
3302 set1 active first m_qsearch
;
3304 | 0xff08 -> (* backspace *)
3305 if String.length m_qsearch
= 0
3308 let qsearch = withoutlastutf8 m_qsearch
in
3309 let len = String.length
qsearch in
3313 G.postRedisplay "listview empty qsearch";
3314 set1 m_active m_first
"";
3318 match search m_active
qsearch ~
-1 with
3320 state.text <- qsearch ^
" [not found]";
3323 state.text <- qsearch;
3324 active, firstof m_first
active
3326 G.postRedisplay "listview backspace qsearch";
3327 set1 active first qsearch
3330 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3331 let pattern = m_qsearch ^
Wsi.toutf8
key in
3333 match search m_active
pattern 1 with
3335 state.text <- pattern ^
" [not found]";
3338 state.text <- pattern;
3339 active, firstof m_first
active
3341 G.postRedisplay "listview qsearch add";
3342 set1 active first pattern;
3344 | 0xff1b -> (* escape *)
3346 if String.length m_qsearch
= 0
3348 G.postRedisplay "list view escape";
3351 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3353 | None
-> m_prev_uioh
3358 G.postRedisplay "list view kill qsearch";
3359 source#setqsearch
"";
3360 coe {< m_qsearch
= "" >}
3363 | 0xff0d -> (* return *)
3365 let self = {< m_qsearch
= "" >} in
3366 source#setqsearch
"";
3368 G.postRedisplay "listview enter";
3369 if m_active
>= 0 && m_active
< source#getitemcount
3371 source#exit
(coe self) false m_active m_first m_pan
"";
3374 source#exit
(coe self) true m_active m_first m_pan
"";
3377 begin match opt with
3378 | None
-> m_prev_uioh
3382 | 0xff9f | 0xffff -> (* delete *)
3385 | 0xff52 -> navigate ~
-1 (* up *)
3386 | 0xff54 -> navigate 1 (* down *)
3387 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3388 | 0xff56 -> navigate fstate.maxrows
(* next *)
3390 | 0xff53 -> (* right *)
3392 G.postRedisplay "listview right";
3393 coe {< m_pan
= m_pan
- 1 >}
3395 | 0xff51 -> (* left *)
3397 G.postRedisplay "listview left";
3398 coe {< m_pan
= m_pan
+ 1 >}
3400 | 0xff50 -> (* home *)
3401 let active = find 0 1 in
3402 G.postRedisplay "listview home";
3405 | 0xff57 -> (* end *)
3406 let first = max
0 (itemcount - fstate.maxrows
) in
3407 let active = find (itemcount - 1) ~
-1 in
3408 G.postRedisplay "listview end";
3411 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3415 dolog "listview unknown key %#x" key; coe self
3417 method key key mask
=
3418 match state.mode
with
3419 | Textentry te
-> textentrykeyboard key mask te
; coe self
3420 | _ -> self#key1
key mask
3422 method button button down
x y _ =
3425 | 1 when x > conf.winw
- conf.scrollbw
->
3426 G.postRedisplay "listview scroll";
3429 let _, position, sh = self#
scrollph in
3430 if y > truncate
position && y < truncate
(position +. sh)
3432 state.mstate
<- Mscrolly
;
3436 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3437 let first = truncate
(s *. float source#getitemcount
) in
3438 let first = min source#getitemcount
first in
3439 Some
(coe {< m_first
= first; m_active
= first >})
3441 state.mstate
<- Mnone
;
3444 | 1 when not down
->
3445 begin match self#elemunder
y with
3447 G.postRedisplay "listview click";
3449 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3453 | n when (n == 4 || n == 5) && not down
->
3454 let len = source#getitemcount
in
3456 if n = 5 && m_first
+ fstate.maxrows
>= len
3460 let first = m_first
+ (if n == 4 then -1 else 1) in
3461 bound first 0 (len - 1)
3463 G.postRedisplay "listview wheel";
3464 Some
(coe {< m_first
= first >})
3465 | n when (n = 6 || n = 7) && not down
->
3466 let inc = m_first
+ (if n = 7 then -1 else 1) in
3467 G.postRedisplay "listview hwheel";
3468 Some
(coe {< m_pan
= m_pan
+ inc >})
3473 | None
-> m_prev_uioh
3477 match state.mstate
with
3479 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3480 let first = truncate
(s *. float source#getitemcount
) in
3481 let first = min source#getitemcount
first in
3482 G.postRedisplay "listview motion";
3483 coe {< m_first
= first; m_active
= first >}
3486 method pmotion
x y =
3487 if x < conf.winw
- conf.scrollbw
3490 match self#elemunder
y with
3491 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3492 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3496 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3501 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3505 method infochanged
_ = ()
3507 method scrollpw
= (0, 0.0, 0.0)
3509 let nfs = fstate.fontsize
+ 1 in
3510 let y = m_first
* nfs in
3511 let itemcount = source#getitemcount
in
3512 let maxi = max
0 (itemcount - fstate.maxrows
) in
3513 let maxy = maxi * nfs in
3514 let p, h = scrollph y maxy in
3517 method modehash
= modehash
3520 class outlinelistview ~source
=
3523 ~source
:(source
:> lvsource
)
3525 ~modehash
:(findkeyhash conf "outline")
3528 method key key mask
=
3529 let calcfirst first active =
3532 let rows = active - first in
3534 if String.length
state.text = 0
3536 else fstate.maxrows - 2
3538 if rows > maxrows then active - maxrows else first
3542 let active = m_active
+ incr in
3543 let active = bound active 0 (source#getitemcount
- 1) in
3544 let first = calcfirst m_first
active in
3545 G.postRedisplay "outline navigate";
3546 coe {< m_active
= active; m_first
= first >}
3548 let ctrl = Wsi.withctrl mask
in
3550 | 110 when ctrl -> (* ctrl-n *)
3551 source#narrow m_qsearch
;
3552 G.postRedisplay "outline ctrl-n";
3553 coe {< m_first
= 0; m_active
= 0 >}
3555 | 117 when ctrl -> (* ctrl-u *)
3557 G.postRedisplay "outline ctrl-u";
3559 coe {< m_first
= 0; m_active
= 0 >}
3561 | 108 when ctrl -> (* ctrl-l *)
3562 let first = m_active
- (fstate.maxrows / 2) in
3563 G.postRedisplay "outline ctrl-l";
3564 coe {< m_first
= first >}
3566 | 0xff9f | 0xffff -> (* delete *)
3567 source#remove m_active
;
3568 G.postRedisplay "outline delete";
3569 let active = max
0 (m_active
-1) in
3570 coe {< m_first
= firstof m_first
active;
3571 m_active
= active >}
3573 | 0xff52 -> navigate ~
-1 (* up *)
3574 | 0xff54 -> navigate 1 (* down *)
3575 | 0xff55 -> (* prior *)
3576 navigate ~
-(fstate.maxrows)
3577 | 0xff56 -> (* next *)
3578 navigate fstate.maxrows
3580 | 0xff53 -> (* [ctrl-]right *)
3584 G.postRedisplay "outline ctrl right";
3585 {< m_pan
= m_pan
+ 1 >}
3587 else self#updownlevel
1
3591 | 0xff51 -> (* [ctrl-]left *)
3595 G.postRedisplay "outline ctrl left";
3596 {< m_pan
= m_pan
- 1 >}
3598 else self#updownlevel ~
-1
3602 | 0xff50 -> (* home *)
3603 G.postRedisplay "outline home";
3604 coe {< m_first
= 0; m_active
= 0 >}
3606 | 0xff57 -> (* end *)
3607 let active = source#getitemcount
- 1 in
3608 let first = max
0 (active - fstate.maxrows) in
3609 G.postRedisplay "outline end";
3610 coe {< m_active
= active; m_first
= first >}
3612 | _ -> super#
key key mask
3615 let outlinesource usebookmarks
=
3618 inherit lvsourcebase
3619 val mutable m_items
= empty
3620 val mutable m_orig_items
= empty
3621 val mutable m_prev_items
= empty
3622 val mutable m_narrow_pattern
= ""
3623 val mutable m_hadremovals
= false
3625 method getitemcount
=
3626 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3629 if n == Array.length m_items
&& m_hadremovals
3631 ("[Confirm removal]", 0)
3633 let s, n, _ = m_items
.(n) in
3636 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3637 ignore
(uioh
, first, qsearch);
3638 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3640 if String.length m_narrow_pattern
= 0
3646 if not
confrimremoval
3648 let _, _, anchor = m_items
.(active) in
3653 state.bookmarks
<- Array.to_list m_items
;
3654 m_orig_items
<- m_items
;
3657 else m_items
<- items;
3661 method hasaction
_ = true
3664 if Array.length m_items
!= Array.length m_orig_items
3665 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3668 method narrow
pattern =
3669 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3673 let rec loop accu n =
3676 m_narrow_pattern
<- pattern;
3677 m_items
<- Array.of_list
accu
3680 let (s, _, _) as o = m_items
.(n) in
3682 if (try ignore
(Str.search_forward
re s 0); true
3683 with Not_found
-> false)
3689 loop [] (Array.length m_items
- 1)
3694 then Array.of_list
state.bookmarks
3697 m_items
<- m_orig_items
3702 if m >= 0 && m < Array.length m_items
3704 m_hadremovals
<- true;
3705 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3706 let n = if n >= m then n+1 else n in
3711 method reset
anchor items =
3712 m_hadremovals
<- false;
3713 if m_orig_items
== empty || m_prev_items
!= items
3715 m_orig_items
<- items;
3716 if String.length m_narrow_pattern
= 0
3717 then m_items
<- items;
3719 m_prev_items
<- items;
3720 let rely = getanchory anchor in
3722 let rec loop n best bestd
=
3723 if n = Array.length m_items
3726 let (_, _, anchor) = m_items
.(n) in
3727 let orely = getanchory anchor in
3728 let d = abs
(orely - rely) in
3731 else loop (n+1) best bestd
3736 m_first
<- firstof m_first
active
3740 let enterselector usebookmarks
=
3741 let source = outlinesource usebookmarks
in
3745 then Array.of_list
state.bookmarks
3748 if Array.length
outlines = 0
3750 showtext ' ' errmsg
;
3753 state.text <- source#greetmsg
;
3754 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3755 let anchor = getanchor () in
3756 source#reset
anchor outlines;
3757 state.uioh
<- coe (new outlinelistview ~
source);
3758 G.postRedisplay "enter selector";
3762 let enteroutlinemode =
3763 let f = enterselector false in
3764 fun ()-> f "Document has no outline";
3767 let enterbookmarkmode =
3768 let f = enterselector true in
3769 fun () -> f "Document has no bookmarks (yet)";
3772 let color_of_string s =
3773 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3774 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3778 let color_to_string (r
, g
, b) =
3779 let r = truncate
(r *. 256.0)
3780 and g
= truncate
(g
*. 256.0)
3781 and b = truncate
(b *. 256.0) in
3782 Printf.sprintf
"%d/%d/%d" r g
b
3785 let irect_of_string s =
3786 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3789 let irect_to_string (x0,y0,x1,y1) =
3790 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3793 let makecheckers () =
3794 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3796 converted by Issac Trotts. July 25, 2002 *)
3797 let image_height = 64
3798 and image_width
= 64 in
3802 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3804 for i
= 0 to image_width
- 1 do
3805 for j
= 0 to image_height - 1 do
3806 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3807 (if (i
land 8 ) lxor (j
land 8) = 0
3808 then [|255;255;255|] else [|200;200;200|])
3813 let image = make_image () in
3814 let id = GlTex.gen_texture
() in
3815 GlTex.bind_texture `texture_2d
id;
3816 GlPix.store
(`unpack_alignment
1);
3817 GlTex.image2d
image;
3818 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3821 `mag_filter `nearest
;
3822 `min_filter `nearest
];
3826 let setcheckers enabled
=
3827 match state.texid
with
3829 if enabled
then state.texid
<- Some
(makecheckers ())
3834 GlTex.delete_texture texid
;
3835 state.texid
<- None
;
3839 let int_of_string_with_suffix s =
3840 let l = String.length
s in
3844 let suffix = Char.lowercase
s.[l-1] in
3846 | 'k'
-> String.sub
s 0 (l-1), 10
3847 | '
m'
-> String.sub
s 0 (l-1), 20
3848 | 'g'
-> String.sub
s 0 (l-1), 30
3852 let n = int_of_string
s1 in
3853 let m = n lsl shift
in
3855 then raise
(Failure
"value too large")
3859 let string_with_suffix_of_int n =
3864 if n land ((1 lsl 20) - 1) = 0
3867 if n land ((1 lsl 10) - 1) = 0
3873 let h = n mod 1000 in
3876 then string_of_int
h ^
s
3878 let s = Printf.sprintf
"_%03d%s" h s in
3885 let defghyllscroll = (40, 8, 32);;
3886 let ghyllscroll_of_string s =
3887 let (n, a, b) as nab
=
3890 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3892 if n <= a || n <= b || a >= b
3893 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3897 let ghyllscroll_to_string ((n, a, b) as nab
) =
3898 if nab
= defghyllscroll
3900 else Printf.sprintf
"%d,%d,%d" n a b;
3903 let describe_location () =
3905 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3907 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3908 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3912 else (100. *. (float state.y /. float maxy))
3916 Printf.sprintf
"page %d of %d [%.2f%%]"
3917 (fn+1) state.pagecount
percent
3920 "pages %d-%d of %d [%.2f%%]"
3921 (fn+1) (ln
+1) state.pagecount
percent
3925 let btos b = if b then "\xe2\x88\x9a" else "" in
3926 let showextended = ref false in
3927 let leave mode
= function
3928 | Confirm
-> state.mode
<- mode
3929 | Cancel
-> state.mode
<- mode
in
3932 val mutable m_first_time
= true
3933 val mutable m_l
= []
3934 val mutable m_a
= [||]
3935 val mutable m_prev_uioh
= nouioh
3936 val mutable m_prev_mode
= View
3938 inherit lvsourcebase
3940 method reset prev_mode prev_uioh
=
3941 m_a
<- Array.of_list
(List.rev m_l
);
3943 m_prev_mode
<- prev_mode
;
3944 m_prev_uioh
<- prev_uioh
;
3948 if n >= Array.length m_a
3952 | _, _, _, Action
_ -> m_active
<- n
3956 m_first_time
<- false;
3959 method int name get
set =
3961 (name
, `
int get
, 1, Action
(
3964 try set (int_of_string
s)
3966 state.text <- Printf.sprintf
"bad integer `%s': %s"
3967 s (Printexc.to_string exn
)
3970 let te = name ^
": ", "", None
, intentry, ondone, true in
3971 state.mode
<- Textentry
(te, leave m_prev_mode
);
3975 method int_with_suffix name get
set =
3977 (name
, `intws get
, 1, Action
(
3980 try set (int_of_string_with_suffix s)
3982 state.text <- Printf.sprintf
"bad integer `%s': %s"
3983 s (Printexc.to_string exn
)
3987 name ^
": ", "", None
, intentry_with_suffix, ondone, true
3989 state.mode
<- Textentry
(te, leave m_prev_mode
);
3993 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3995 (name
, `
bool (btos, get
), offset
, Action
(
4002 method color name get
set =
4004 (name
, `color get
, 1, Action
(
4006 let invalid = (nan
, nan
, nan
) in
4009 try color_of_string s
4011 state.text <- Printf.sprintf
"bad color `%s': %s"
4012 s (Printexc.to_string exn
);
4018 let te = name ^
": ", "", None
, textentry, ondone, true in
4019 state.text <- color_to_string (get
());
4020 state.mode
<- Textentry
(te, leave m_prev_mode
);
4024 method string name get
set =
4026 (name
, `
string get
, 1, Action
(
4028 let ondone s = set s in
4029 let te = name ^
": ", "", None
, textentry, ondone, true in
4030 state.mode
<- Textentry
(te, leave m_prev_mode
);
4034 method colorspace name get
set =
4036 (name
, `
string get
, 1, Action
(
4039 let vals = [| "rgb"; "bgr"; "gray" |] in
4041 inherit lvsourcebase
4044 m_active
<- int_of_colorspace conf.colorspace
;
4047 method getitemcount
= Array.length
vals
4048 method getitem
n = (vals.(n), 0)
4049 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4050 ignore
(uioh
, first, pan
, qsearch);
4051 if not cancel
then set active;
4053 method hasaction
_ = true
4057 let modehash = findkeyhash conf "info" in
4058 coe (new listview ~
source ~trusted
:true ~
modehash)
4061 method caption
s offset
=
4062 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4064 method caption2
s f offset
=
4065 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4067 method getitemcount
= Array.length m_a
4070 let tostr = function
4071 | `
int f -> string_of_int
(f ())
4072 | `intws
f -> string_with_suffix_of_int (f ())
4074 | `color
f -> color_to_string (f ())
4075 | `
bool (btos, f) -> btos (f ())
4078 let name, t
, offset
, _ = m_a
.(n) in
4079 ((let s = tostr t
in
4080 if String.length
s > 0
4081 then Printf.sprintf
"%s\t%s" name s
4085 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4089 m_qsearch
<- qsearch;
4091 match m_a
.(active) with
4092 | _, _, _, Action
f -> f uioh
4104 method hasaction
n =
4106 | _, _, _, Action
_ -> true
4110 let rec fillsrc prevmode prevuioh
=
4111 let sep () = src#caption
"" 0 in
4112 let colorp name get
set =
4114 (fun () -> color_to_string (get
()))
4117 let c = color_of_string v in
4120 state.text <- Printf.sprintf
"bad color `%s': %s"
4121 v (Printexc.to_string exn
);
4124 let oldmode = state.mode
in
4125 let birdseye = isbirdseye state.mode
in
4127 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4129 src#
bool "presentation mode"
4130 (fun () -> conf.presentation)
4132 conf.presentation <- v;
4133 state.anchor <- getanchor ();
4136 src#
bool "ignore case in searches"
4137 (fun () -> conf.icase
)
4138 (fun v -> conf.icase
<- v);
4141 (fun () -> conf.preload)
4142 (fun v -> conf.preload <- v);
4144 src#
bool "highlight links"
4145 (fun () -> conf.hlinks
)
4146 (fun v -> conf.hlinks
<- v);
4148 src#
bool "under info"
4149 (fun () -> conf.underinfo
)
4150 (fun v -> conf.underinfo
<- v);
4152 src#
bool "persistent bookmarks"
4153 (fun () -> conf.savebmarks
)
4154 (fun v -> conf.savebmarks
<- v);
4156 src#
bool "proportional display"
4157 (fun () -> conf.proportional
)
4158 (fun v -> reqlayout conf.angle
v);
4160 src#
bool "trim margins"
4161 (fun () -> conf.trimmargins
)
4162 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4164 src#
bool "persistent location"
4165 (fun () -> conf.jumpback
)
4166 (fun v -> conf.jumpback
<- v);
4169 src#
int "inter-page space"
4170 (fun () -> conf.interpagespace)
4172 conf.interpagespace <- n;
4173 docolumns conf.columns
;
4175 match state.layout with
4180 state.maxy <- calcheight ();
4181 let y = getpagey pageno in
4186 (fun () -> conf.pagebias
)
4187 (fun v -> conf.pagebias
<- v);
4189 src#
int "scroll step"
4190 (fun () -> conf.scrollstep
)
4191 (fun n -> conf.scrollstep
<- n);
4193 src#
int "horizontal scroll step"
4194 (fun () -> conf.hscrollstep
)
4195 (fun v -> conf.hscrollstep
<- v);
4197 src#
int "auto scroll step"
4199 match state.autoscroll
with
4201 | _ -> conf.autoscrollstep
)
4203 if state.autoscroll
<> None
4204 then state.autoscroll
<- Some
n;
4205 conf.autoscrollstep
<- n);
4208 (fun () -> truncate
(conf.zoom *. 100.))
4209 (fun v -> setzoom ((float v) /. 100.));
4212 (fun () -> conf.angle
)
4213 (fun v -> reqlayout v conf.proportional
);
4215 src#
int "scroll bar width"
4216 (fun () -> state.scrollw
)
4220 reshape conf.winw
conf.winh
;
4223 src#
int "scroll handle height"
4224 (fun () -> conf.scrollh
)
4225 (fun v -> conf.scrollh
<- v;);
4227 src#
int "thumbnail width"
4228 (fun () -> conf.thumbw
)
4230 conf.thumbw
<- min
4096 v;
4233 leavebirdseye beye
false;
4238 let mode = state.mode in
4239 src#
string "columns"
4241 match conf.columns
with
4243 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4244 | Csplit
(count
, _) -> "-" ^ string_of_int count
4247 let n, a, b = multicolumns_of_string v in
4248 setcolumns mode n a b);
4251 src#caption
"Presentation mode" 0;
4252 src#
bool "scrollbar visible"
4253 (fun () -> conf.scrollbarinpm
)
4255 if v != conf.scrollbarinpm
4257 conf.scrollbarinpm
<- v;
4258 if conf.presentation
4260 state.scrollw
<- if v then conf.scrollbw
else 0;
4261 reshape conf.winw
conf.winh
;
4267 src#caption
"Pixmap cache" 0;
4268 src#int_with_suffix
"size (advisory)"
4269 (fun () -> conf.memlimit
)
4270 (fun v -> conf.memlimit
<- v);
4273 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4274 (string_with_suffix_of_int state.memused
)
4275 (Hashtbl.length
state.tilemap
)) 1;
4278 src#caption
"Layout" 0;
4279 src#caption2
"Dimension"
4281 Printf.sprintf
"%dx%d (virtual %dx%d)"
4287 src#caption2
"Position" (fun () ->
4288 Printf.sprintf
"%dx%d" state.x state.y
4291 src#caption2
"Visible" (fun () -> describe_location ()) 1
4295 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4296 "Save these parameters as global defaults at exit"
4297 (fun () -> conf.bedefault
)
4298 (fun v -> conf.bedefault
<- v)
4302 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4303 src#
bool ~offset
:0 ~
btos "Extended parameters"
4304 (fun () -> !showextended)
4305 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4309 (fun () -> conf.checkers
)
4310 (fun v -> conf.checkers
<- v; setcheckers v);
4311 src#
bool "update cursor"
4312 (fun () -> conf.updatecurs
)
4313 (fun v -> conf.updatecurs
<- v);
4315 (fun () -> conf.verbose
)
4316 (fun v -> conf.verbose
<- v);
4317 src#
bool "invert colors"
4318 (fun () -> conf.invert
)
4319 (fun v -> conf.invert
<- v);
4321 (fun () -> conf.maxhfit
)
4322 (fun v -> conf.maxhfit
<- v);
4323 src#
bool "redirect stderr"
4324 (fun () -> conf.redirectstderr)
4325 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4326 src#
string "uri launcher"
4327 (fun () -> conf.urilauncher
)
4328 (fun v -> conf.urilauncher
<- v);
4329 src#
string "path launcher"
4330 (fun () -> conf.pathlauncher
)
4331 (fun v -> conf.pathlauncher
<- v);
4332 src#
string "tile size"
4333 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4336 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4337 conf.tilew
<- max
64 w;
4338 conf.tileh
<- max
64 h;
4341 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4342 v (Printexc.to_string exn
));
4343 src#
int "texture count"
4344 (fun () -> conf.texcount
)
4347 then conf.texcount
<- v
4348 else showtext '
!'
" Failed to set texture count please retry later"
4350 src#
int "slice height"
4351 (fun () -> conf.sliceheight
)
4353 conf.sliceheight
<- v;
4354 wcmd "sliceh %d" conf.sliceheight
;
4356 src#
int "anti-aliasing level"
4357 (fun () -> conf.aalevel
)
4359 conf.aalevel
<- bound v 0 8;
4360 state.anchor <- getanchor ();
4361 opendoc state.path
state.password
;
4363 src#
string "page scroll scaling factor"
4364 (fun () -> string_of_float
conf.pgscale)
4367 let s = float_of_string
v in
4370 state.text <- Printf.sprintf
4371 "bad page scroll scaling factor `%s': %s"
4372 v (Printexc.to_string exn
)
4375 src#
int "ui font size"
4376 (fun () -> fstate.fontsize
)
4377 (fun v -> setfontsize (bound v 5 100));
4378 src#
int "hint font size"
4379 (fun () -> conf.hfsize
)
4380 (fun v -> conf.hfsize
<- bound v 5 100);
4381 colorp "background color"
4382 (fun () -> conf.bgcolor
)
4383 (fun v -> conf.bgcolor
<- v);
4384 src#
bool "crop hack"
4385 (fun () -> conf.crophack
)
4386 (fun v -> conf.crophack
<- v);
4387 src#
string "trim fuzz"
4388 (fun () -> irect_to_string conf.trimfuzz
)
4391 conf.trimfuzz
<- irect_of_string v;
4393 then settrim true conf.trimfuzz
;
4395 state.text <- Printf.sprintf
"bad irect `%s': %s"
4396 v (Printexc.to_string exn
)
4398 src#
string "throttle"
4400 match conf.maxwait
with
4401 | None
-> "show place holder if page is not ready"
4404 then "wait for page to fully render"
4406 "wait " ^ string_of_float
time
4407 ^
" seconds before showing placeholder"
4411 let f = float_of_string
v in
4413 then conf.maxwait
<- None
4414 else conf.maxwait
<- Some
f
4416 state.text <- Printf.sprintf
"bad time `%s': %s"
4417 v (Printexc.to_string exn
)
4419 src#
string "ghyll scroll"
4421 match conf.ghyllscroll
with
4423 | Some nab
-> ghyllscroll_to_string nab
4428 if String.length
v = 0
4430 else Some
(ghyllscroll_of_string v)
4432 conf.ghyllscroll
<- gs
4434 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4435 v (Printexc.to_string exn
)
4437 src#
string "selection command"
4438 (fun () -> conf.selcmd
)
4439 (fun v -> conf.selcmd
<- v);
4440 src#colorspace
"color space"
4441 (fun () -> colorspace_to_string conf.colorspace
)
4443 conf.colorspace
<- colorspace_of_int v;
4450 src#caption
"Document" 0;
4451 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4452 src#caption2
"Pages"
4453 (fun () -> string_of_int
state.pagecount
) 1;
4454 src#caption2
"Dimensions"
4455 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4459 src#caption
"Trimmed margins" 0;
4460 src#caption2
"Dimensions"
4461 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4465 src#caption
"OpenGL" 0;
4466 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4467 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4468 src#reset prevmode prevuioh
;
4472 let prevmode = state.mode
4473 and prevuioh
= state.uioh in
4474 fillsrc prevmode prevuioh
;
4475 let source = (src :> lvsource
) in
4476 let modehash = findkeyhash conf "info" in
4477 state.uioh <- coe (object (self)
4478 inherit listview ~
source ~trusted
:true ~
modehash as super
4479 val mutable m_prevmemused
= 0
4480 method infochanged
= function
4482 if m_prevmemused
!= state.memused
4484 m_prevmemused
<- state.memused
;
4485 G.postRedisplay "memusedchanged";
4487 | Pdim
-> G.postRedisplay "pdimchanged"
4488 | Docinfo
-> fillsrc prevmode prevuioh
4490 method key key mask
=
4491 if not
(Wsi.withctrl mask
)
4494 | 0xff51 -> coe (self#updownlevel ~
-1)
4495 | 0xff53 -> coe (self#updownlevel
1)
4496 | _ -> super#
key key mask
4497 else super#
key key mask
4499 G.postRedisplay "info";
4505 inherit lvsourcebase
4506 method getitemcount
= Array.length
state.help
4508 let s, n, _ = state.help
.(n) in
4511 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4515 m_qsearch
<- qsearch;
4516 match state.help
.(active) with
4517 | _, _, Action
f -> Some
(f uioh)
4527 method hasaction
n =
4528 match state.help
.(n) with
4529 | _, _, Action
_ -> true
4536 let modehash = findkeyhash conf "help" in
4537 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4538 G.postRedisplay "help";
4543 let re = Str.regexp
"[\r\n]" in
4545 inherit lvsourcebase
4546 val mutable m_items
= [||]
4548 method getitemcount
= 1 + Array.length m_items
4553 else m_items
.(n-1), 0
4555 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4560 then Buffer.clear
state.errmsgs
;
4561 m_qsearch
<- qsearch;
4568 method hasaction
n =
4572 state.newerrmsgs
<- false;
4573 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4574 m_items
<- Array.of_list
l
4582 let source = (msgsource :> lvsource
) in
4583 let modehash = findkeyhash conf "listview" in
4584 state.uioh <- coe (object
4585 inherit listview ~
source ~trusted
:false ~
modehash as super
4588 then msgsource#reset
;
4591 G.postRedisplay "msgs";
4594 let quickbookmark ?title
() =
4595 match state.layout with
4601 let sec = Unix.gettimeofday
() in
4602 let tm = Unix.localtime
sec in
4603 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4607 (tm.Unix.tm_year
+ 1900)
4610 | Some
title -> title
4613 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4618 state.fullscreen
<- None
;
4622 let setautoscrollspeed step goingdown
=
4623 let incr = max
1 ((abs step
) / 2) in
4624 let incr = if goingdown
then incr else -incr in
4625 let astep = step
+ incr in
4626 state.autoscroll
<- Some
astep;
4629 let gotounder = function
4630 | Ulinkgoto
(pageno, top) ->
4634 gotopage1 pageno top;
4640 | Uremote
(filename
, pageno) ->
4642 if Sys.file_exists filename
4645 let dir = Filename.dirname
state.path in
4646 let path = Filename.concat
dir filename
in
4647 if Sys.file_exists
path
4651 if String.length
path > 0
4653 let anchor = getanchor () in
4654 let ranchor = state.path, state.password
, anchor in
4655 state.anchor <- (pageno, 0.0);
4656 state.ranchors
<- ranchor :: state.ranchors
;
4659 else showtext '
!'
("Could not find " ^ filename
)
4661 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4665 match conf.columns
with
4667 | _ -> conf.zoom > 1.0
4670 let viewkeyboard key mask
=
4672 let mode = state.mode in
4673 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4676 G.postRedisplay "view:enttext"
4678 let ctrl = Wsi.withctrl mask
in
4683 | 0xff63 -> (* insert *)
4684 if conf.angle
mod 360 = 0
4686 state.mode <- LinkNav
(Ltgendir
0);
4689 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4691 | 0xff1b | 113 -> (* escape / q *)
4692 begin match state.mstate
with
4694 state.mstate
<- Mnone
;
4695 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4696 G.postRedisplay "kill zoom rect";
4698 match state.ranchors
with
4700 | (path, password
, anchor) :: rest
->
4701 state.ranchors
<- rest
;
4702 state.anchor <- anchor;
4703 opendoc path password
4706 | 0xff08 -> (* backspace *)
4707 let y = getnav ~
-1 in
4708 gotoy_and_clear_text y
4716 G.postRedisplay "dehighlight";
4718 | 47 | 63 -> (* / ? *)
4719 let ondone isforw
s =
4720 cbput state.hists
.pat
s;
4721 state.searchpattern
<- s;
4724 let s = String.create
1 in
4725 s.[0] <- Char.chr
key;
4726 enttext (s, "", Some
(onhist state.hists
.pat
),
4727 textentry, ondone (key = 47), true)
4729 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-=*)
4730 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4731 setzoom (conf.zoom +. incr)
4733 | 43 | 0xffab -> (* + *)
4736 try int_of_string
s with exc
->
4737 state.text <- Printf.sprintf
"bad integer `%s': %s"
4738 s (Printexc.to_string exc
);
4744 state.text <- "page bias is now " ^ string_of_int
n;
4747 enttext ("page bias: ", "", None
, intentry, ondone, true)
4749 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4750 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4751 setzoom (max
0.01 (conf.zoom -. decr))
4753 | 45 | 0xffad -> (* - *)
4754 let ondone msg
= state.text <- msg
in
4756 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4757 optentry state.mode, ondone, true
4760 | 48 when ctrl -> (* ctrl-0 *)
4763 | 49 when ctrl -> (* ctrl-1 *)
4765 match conf.columns
with
4766 | Csingle
| Cmulti
_ -> 1
4767 | Csplit
(n, _) -> n
4769 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4773 | 0xffc6 -> (* f9 *)
4776 | 57 when ctrl -> (* ctrl-9 *)
4779 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4780 when not
ctrl -> (* 0..9 *)
4783 try int_of_string
s with exc
->
4784 state.text <- Printf.sprintf
"bad integer `%s': %s"
4785 s (Printexc.to_string exc
);
4791 cbput state.hists
.pag
(string_of_int
n);
4792 gotopage1 (n + conf.pagebias
- 1) 0;
4795 let pageentry text key =
4796 match Char.unsafe_chr
key with
4797 | 'g'
-> TEdone
text
4798 | _ -> intentry text key
4800 let text = "x" in text.[0] <- Char.chr
key;
4801 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4804 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4805 reshape conf.winw
conf.winh
;
4808 conf.hlinks
<- not
conf.hlinks
;
4809 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4810 G.postRedisplay "toggle highlightlinks";
4813 state.glinks
<- true;
4814 let mode = state.mode in
4815 state.mode <- Textentry
(
4816 (":", "", None
, linknentry, linkndone (fun under ->
4821 state.glinks
<- false;
4825 G.postRedisplay "view:linkent(F)"
4828 state.glinks
<- true;
4829 let mode = state.mode in
4830 state.mode <- Textentry
(
4831 (":", "", None
, linknentry, linkndone (fun under ->
4832 match Ne.pipe () with
4834 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4835 (Printexc.to_string exn
));
4838 try popen conf.selcmd
[r, 0; w, -1]; true
4841 (Printf.sprintf
"failed to execute %s: %s"
4842 conf.selcmd
(Printexc.to_string exn
));
4846 Ne.clo fd
(fun msg
->
4847 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4850 let s = undertext under in
4854 let l = String.length
s in
4855 let n = Unix.write
w s 0 l in
4860 "failed to write %d characters to sel pipe, wrote %d"
4865 (Printf.sprintf
"failed to write to sel pipe: %s"
4866 (Printexc.to_string exn
)
4875 state.glinks
<- false;
4879 G.postRedisplay "view:linkent"
4882 begin match state.autoscroll
with
4884 conf.autoscrollstep
<- step
;
4885 state.autoscroll
<- None
4887 if conf.autoscrollstep
= 0
4888 then state.autoscroll
<- Some
1
4889 else state.autoscroll
<- Some
conf.autoscrollstep
4892 | 112 when ctrl -> (* ctrl-p *)
4896 conf.presentation <- not
conf.presentation;
4897 if conf.presentation
4899 if not
conf.scrollbarinpm
4900 then state.scrollw
<- 0;
4903 state.scrollw
<- conf.scrollbw
;
4905 showtext ' '
("presentation mode " ^
4906 if conf.presentation then "on" else "off");
4907 state.anchor <- getanchor ();
4911 begin match state.fullscreen
with
4913 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4916 state.fullscreen
<- None
;
4921 gotoy_and_clear_text 0
4924 gotopage1 (state.pagecount
- 1) 0
4926 | 112 | 78 -> (* p|N *)
4927 search state.searchpattern
false
4929 | 110 | 0xffc0 -> (* n|F3 *)
4930 search state.searchpattern
true
4933 begin match state.layout with
4936 gotoy_and_clear_text (getpagey l.pageno)
4940 begin match state.layout with
4943 match conf.columns
with
4944 | Csingle
| Cmulti
_ ->
4945 if conf.presentation && rest
== [] && l.pageh
> l.pagey + l.pagevh
4947 let y = clamp (pgscale conf.winh
) in
4948 gotoy_and_clear_text y
4950 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4951 gotoy_and_clear_text (getpagey pageno)
4953 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4955 let pagey, pageh
= getpageyh l.pageno in
4956 let pagey = pagey + pageh
* l.pagecol
in
4957 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace in
4958 gotoy_and_clear_text (pagey + pageh
+ ips)
4961 | 0xff9f | 0xffff -> (* delete *)
4962 begin match state.layout with
4965 match conf.columns
with
4966 | Csingle
| Cmulti
_ ->
4967 if conf.presentation && l.pagey != 0
4969 gotoy_and_clear_text (clamp (pgscale ~
-(conf.winh
)))
4971 let pageno = max
0 (l.pageno-1) in
4972 gotoy_and_clear_text (getpagey pageno)
4980 let pageno = max
0 (l.pageno-1) in
4981 let pagey, pageh
= getpageyh pageno in
4984 let pagey, pageh
= getpageyh l.pageno in
4985 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4987 gotoy_and_clear_text y
4991 showtext ' '
(describe_location ());
4994 begin match state.layout with
4997 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5002 enterbookmarkmode ()
5004 | 104 | 0xffbe -> (* h|F1 *)
5010 | 101 when conf.redirectstderr -> (* e *)
5015 match state.layout with
5018 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
5022 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5026 showtext ' '
"Quick bookmark added";
5029 begin match state.layout with
5031 let rect = getpdimrect
l.pagedimno
in
5035 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5036 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5038 (truncate
(rect.(1) -. rect.(0)),
5039 truncate
(rect.(3) -. rect.(0)))
5041 let w = truncate
((float w)*.conf.zoom)
5042 and h = truncate
((float h)*.conf.zoom) in
5045 state.anchor <- getanchor ();
5046 doreshape (w + state.scrollw
) (h + conf.interpagespace)
5048 G.postRedisplay "z";
5053 | 50 when ctrl -> (* ctrl-2 *)
5054 let maxw = getmaxw
() in
5056 then setzoom (maxw /. float conf.winw
)
5058 | 60 | 62 -> (* < > *)
5059 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5061 | 91 | 93 -> (* [ ] *)
5063 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5065 G.postRedisplay "brightness";
5067 | 99 when state.mode = View
-> (* c *)
5069 match state.prevcolumns
with
5070 | None
-> (1, 0, 0), 1.0
5071 | Some
(columns
, z
) ->
5074 | Csplit
(c, _) -> -c, 0, 0
5075 | Cmulti
((c, a, b), _) -> c, a, b
5076 | Csingle
-> 1, 0, 0
5080 setcolumns View
c a b;
5083 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5084 setzoom state.prevzoom
5086 | 107 | 0xff52 -> (* k up *)
5087 begin match state.autoscroll
with
5089 begin match state.mode with
5090 | Birdseye beye
-> upbirdseye 1 beye
5093 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5094 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5097 setautoscrollspeed n false
5100 | 106 | 0xff54 -> (* j down *)
5101 begin match state.autoscroll
with
5103 begin match state.mode with
5104 | Birdseye beye
-> downbirdseye 1 beye
5107 then gotoy_and_clear_text (clamp (conf.winh
/2))
5108 else gotoy_and_clear_text (clamp conf.scrollstep
)
5111 setautoscrollspeed n true
5114 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5122 let dx = if key = 0xff51 then dx else -dx in
5123 state.x <- state.x + dx;
5124 gotoy_and_clear_text state.y
5127 G.postRedisplay "lef/right"
5130 | 0xff55 -> (* prior *)
5134 match state.layout with
5136 | l :: _ -> state.y - l.pagey
5138 clamp (pgscale (-conf.winh
))
5142 | 0xff56 -> (* next *)
5146 match List.rev
state.layout with
5148 | l :: _ -> getpagey l.pageno
5150 clamp (pgscale conf.winh
)
5154 | 0xff50 -> gotoghyll 0
5155 | 0xff57 -> gotoghyll (clamp state.maxy)
5156 | 0xff53 when Wsi.withalt mask
->
5157 gotoghyll (getnav ~
-1)
5158 | 0xff51 when Wsi.withalt mask
->
5159 gotoghyll (getnav 1)
5162 state.anchor <- getanchor ();
5163 opendoc state.path state.password
5165 | 118 when conf.debug
-> (* v *)
5168 match getopaque l.pageno with
5171 let x0, y0, x1, y1 = pagebbox opaque
in
5172 let a,b = float x0, float y0 in
5173 let c,d = float x1, float y0 in
5174 let e,f = float x1, float y1 in
5175 let h,j
= float x0, float y1 in
5176 let rect = (a,b,c,d,e,f,h,j
) in
5178 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5180 G.postRedisplay "v";
5183 vlog "huh? %s" (Wsi.keyname
key)
5186 let linknavkeyboard key mask
linknav =
5187 let getpage pageno =
5188 let rec loop = function
5190 | l :: _ when l.pageno = pageno -> Some
l
5191 | _ :: rest
-> loop rest
5192 in loop state.layout
5194 let doexact (pageno, n) =
5195 match getopaque pageno, getpage pageno with
5196 | Some opaque
, Some
l ->
5199 let under = getlink opaque
n in
5200 G.postRedisplay "link gotounder";
5206 | 0xff50 -> (* home *)
5207 Some
(findlink opaque LDfirst
), -1
5209 | 0xff57 -> (* end *)
5210 Some
(findlink opaque LDlast
), 1
5212 | 0xff51 -> (* left *)
5213 Some
(findlink opaque
(LDleft
n)), -1
5215 | 0xff53 -> (* right *)
5216 Some
(findlink opaque
(LDright
n)), 1
5218 | 0xff52 -> (* up *)
5219 Some
(findlink opaque
(LDup
n)), -1
5221 | 0xff54 -> (* down *)
5222 Some
(findlink opaque
(LDdown
n)), 1
5227 begin match findpwl
l.pageno dir with
5231 state.mode <- LinkNav
(Ltgendir
dir);
5232 let y, h = getpageyh pageno in
5235 then y + h - conf.winh
5240 begin match getopaque pageno, getpage pageno with
5241 | Some opaque
, Some
_ ->
5243 let ld = if dir > 0 then LDfirst
else LDlast
in
5246 begin match link with
5248 showlinktype (getlink opaque
m);
5249 state.mode <- LinkNav
(Ltexact
(pageno, m));
5250 G.postRedisplay "linknav jpage";
5257 begin match opt with
5258 | Some Lnotfound
-> pwl l dir;
5259 | Some
(Lfound
m) ->
5263 let _, y0, _, y1 = getlinkrect opaque
m in
5265 then gotopage1 l.pageno y0
5267 let d = fstate.fontsize
+ 1 in
5268 if y1 - l.pagey > l.pagevh - d
5269 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5270 else G.postRedisplay "linknav";
5272 showlinktype (getlink opaque
m);
5273 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5276 | None
-> viewkeyboard key mask
5278 | _ -> viewkeyboard key mask
5283 G.postRedisplay "leave linknav"
5287 | Ltgendir
_ -> viewkeyboard key mask
5288 | Ltexact exact
-> doexact exact
5291 let keyboard key mask
=
5292 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5293 then wcmd "interrupt"
5294 else state.uioh <- state.uioh#
key key mask
5297 let birdseyekeyboard key mask
5298 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5300 match conf.columns
with
5302 | Cmulti
((c, _, _), _) -> c
5303 | Csplit
_ -> failwith
"bird's eye split mode"
5306 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5307 let y, h = getpageyh pageno in
5308 let top = (conf.winh
- h) / 2 in
5309 gotoy (max
0 (y - top))
5310 | 0xff0d -> leavebirdseye beye
false
5311 | 0xff1b -> leavebirdseye beye
true (* escape *)
5312 | 0xff52 -> upbirdseye incr beye
(* prior *)
5313 | 0xff54 -> downbirdseye incr beye
(* next *)
5314 | 0xff51 -> upbirdseye 1 beye
(* up *)
5315 | 0xff53 -> downbirdseye 1 beye
(* down *)
5318 begin match state.layout with
5322 state.mode <- Birdseye
(
5323 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5325 gotopage1 l.pageno 0;
5328 let layout = layout (state.y-conf.winh
) conf.winh
in
5330 | [] -> gotoy (clamp (-conf.winh
))
5332 state.mode <- Birdseye
(
5333 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5335 gotopage1 l.pageno 0
5338 | [] -> gotoy (clamp (-conf.winh
))
5342 begin match List.rev
state.layout with
5344 let layout = layout (state.y + conf.winh
) conf.winh
in
5345 begin match layout with
5347 let incr = l.pageh
- l.pagevh in
5352 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5354 G.postRedisplay "birdseye pagedown";
5356 else gotoy (clamp (incr + conf.interpagespace*2));
5360 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5361 gotopage1 l.pageno 0;
5364 | [] -> gotoy (clamp conf.winh
)
5368 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5372 let pageno = state.pagecount
- 1 in
5373 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5374 if not
(pagevisible state.layout pageno)
5377 match List.rev
state.pdims
with
5379 | (_, _, h, _) :: _ -> h
5381 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5382 else G.postRedisplay "birdseye end";
5383 | _ -> viewkeyboard key mask
5386 let drawpage l linkindexbase
=
5388 match state.mode with
5389 | Textentry
_ -> scalecolor 0.4
5391 | View
-> scalecolor 1.0
5392 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5393 if l.pageno = hooverpageno
5396 if l.pageno = pageno
5402 begin match getopaque l.pageno with
5404 if tileready l l.pagex l.pagey
5406 let x = l.pagedispx - l.pagex
5407 and y = l.pagedispy - l.pagey in
5409 match conf.columns
with
5410 | Csingle
| Cmulti
_ ->
5411 (if conf.hlinks
then 1 else 0)
5413 && not
(isbirdseye state.mode) then 2 else 0)
5417 match state.mode with
5418 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5421 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5428 let scrollindicator () =
5429 let sbw, ph
, sh = state.uioh#
scrollph in
5430 let sbh, pw, sw = state.uioh#scrollpw
in
5432 GlDraw.color (0.64, 0.64, 0.64);
5434 (float (conf.winw
- sbw), 0.)
5435 (float conf.winw
, float conf.winh
)
5438 (0., float (conf.winh
- sbh))
5439 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5441 GlDraw.color (0.0, 0.0, 0.0);
5444 (float (conf.winw
- sbw), ph
)
5445 (float conf.winw
, ph
+. sh)
5448 (pw, float (conf.winh
- sbh))
5449 (pw +. sw, float conf.winh
)
5454 match state.mstate
with
5455 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5458 | Msel
((x0, y0), (x1, y1)) ->
5459 let rec loop = function
5461 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5462 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5463 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5464 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5466 match getopaque l.pageno with
5468 let x0, y0 = pagetranslatepoint l x0 y0 in
5469 let x1, y1 = pagetranslatepoint l x1 y1 in
5470 seltext opaque
(x0, y0, x1, y1);
5478 let showrects rects
=
5480 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5481 GlDraw.polygon_mode `both `fill
;
5482 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5484 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5486 if l.pageno = pageno
5488 let dx = float (l.pagedispx - l.pagex) in
5489 let dy = float (l.pagedispy - l.pagey) in
5490 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5491 GlDraw.begins `quads
;
5493 GlDraw.vertex2
(x0+.dx, y0+.dy);
5494 GlDraw.vertex2
(x1+.dx, y1+.dy);
5495 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5496 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5507 GlClear.color (scalecolor2 conf.bgcolor
);
5508 GlClear.clear
[`
color];
5509 let rec loop linkindexbase
= function
5511 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5512 loop linkindexbase rest
5515 loop 0 state.layout;
5517 match state.mode with
5518 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5519 begin match getopaque pageno with
5521 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5528 | None
-> state.rects
5535 begin match state.mstate
with
5536 | Mzoomrect
((x0, y0), (x1, y1)) ->
5538 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5539 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5540 GlDraw.rect (float x0, float y0)
5541 (float x1, float y1);
5550 let zoomrect x y x1 y1 =
5553 and y0 = min
y y1 in
5554 gotoy (state.y + y0);
5555 state.anchor <- getanchor ();
5556 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5558 if state.w < conf.winw
- state.scrollw
5559 then (conf.winw
- state.scrollw
- state.w) / 2
5562 state.x <- (state.x + margin) - x0;
5564 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5565 state.mstate
<- Mnone
;
5569 let winw = conf.winw - state.scrollw
- 1 in
5570 let s = float x /. float winw in
5571 let destx = truncate
(float (state.w + winw) *. s) in
5572 state.x <- winw - destx;
5573 gotoy_and_clear_text state.y;
5574 state.mstate
<- Mscrollx
;
5578 let s = float y /. float conf.winh
in
5579 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5580 gotoy_and_clear_text desty;
5581 state.mstate
<- Mscrolly
;
5584 let viewmouse button down
x y mask
=
5586 | n when (n == 4 || n == 5) && not down
->
5587 if Wsi.withctrl mask
5589 match state.mstate
with
5590 | Mzoom
(oldn
, i
) ->
5598 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5600 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5602 let zoom = conf.zoom -. incr in
5604 state.mstate
<- Mzoom
(n, 0);
5606 state.mstate
<- Mzoom
(n, i
+1);
5608 else state.mstate
<- Mzoom
(n, 0)
5610 | _ -> state.mstate
<- Mzoom
(n, 0)
5613 match state.autoscroll
with
5614 | Some step
-> setautoscrollspeed step
(n=4)
5618 then -conf.scrollstep
5619 else conf.scrollstep
5621 let incr = incr * 2 in
5622 let y = clamp incr in
5623 gotoy_and_clear_text y
5626 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5627 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5628 gotoy_and_clear_text state.y
5630 | 1 when Wsi.withctrl mask
->
5633 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5634 state.mstate
<- Mpan
(x, y)
5637 state.mstate
<- Mnone
5642 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5644 state.mstate
<- Mzoomrect
(p, p)
5647 match state.mstate
with
5648 | Mzoomrect
((x0, y0), _) ->
5649 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5650 then zoomrect x0 y0 x y
5652 state.mstate
<- Mnone
;
5653 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5654 G.postRedisplay "kill accidental zoom rect";
5657 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5658 state.mstate
<- Mnone
5661 | 1 when x > conf.winw - state.scrollw
->
5664 let _, position, sh = state.uioh#
scrollph in
5665 if y > truncate
position && y < truncate
(position +. sh)
5666 then state.mstate
<- Mscrolly
5669 state.mstate
<- Mnone
5671 | 1 when y > conf.winh
- state.hscrollh ->
5674 let _, position, sw = state.uioh#scrollpw
in
5675 if x > truncate
position && x < truncate
(position +. sw)
5676 then state.mstate
<- Mscrollx
5679 state.mstate
<- Mnone
5682 let dest = if down
then getunder x y else Unone
in
5683 begin match dest with
5687 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5690 | Unone
when down
->
5691 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5692 state.mstate
<- Mpan
(x, y);
5694 | Unone
| Utext
_ ->
5697 if conf.angle
mod 360 = 0
5699 state.mstate
<- Msel
((x, y), (x, y));
5700 G.postRedisplay "mouse select";
5704 match state.mstate
with
5707 | Mzoom
_ | Mscrollx
| Mscrolly
->
5708 state.mstate
<- Mnone
5710 | Mzoomrect
((x0, y0), _) ->
5714 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5715 state.mstate
<- Mnone
5717 | Msel
((_, y0), (_, y1)) ->
5718 let rec loop = function
5721 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5722 || ((y1 >= l.pagedispy
5723 && y1 <= (l.pagedispy + l.pagevh)))
5725 match getopaque l.pageno with
5728 match Ne.pipe () with
5732 "can not create sel pipe: %s"
5733 (Printexc.to_string exn
));
5735 let doclose what fd
=
5736 Ne.clo fd
(fun msg
->
5737 dolog "%s close failed: %s" what msg
)
5740 popen conf.selcmd
[r, 0; w, -1];
5743 G.postRedisplay "copysel";
5745 dolog "can not execute %S: %s"
5746 conf.selcmd
(Printexc.to_string exn
);
5754 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5755 state.mstate
<- Mnone
;
5762 let birdseyemouse button down
x y mask
5763 (conf, leftx
, _, hooverpageno
, anchor) =
5766 let rec loop = function
5769 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5770 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5772 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5778 | _ -> viewmouse button down
x y mask
5781 let mouse button down
x y mask
=
5782 state.uioh <- state.uioh#button button down
x y mask
;
5786 state.uioh <- state.uioh#
motion x y
5790 state.uioh <- state.uioh#
pmotion x y;
5796 method key key mask
=
5797 begin match state.mode with
5798 | Textentry
textentry -> textentrykeyboard key mask
textentry
5799 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5800 | View
-> viewkeyboard key mask
5801 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5805 method button button bstate
x y mask
=
5806 begin match state.mode with
5808 | View
-> viewmouse button bstate
x y mask
5809 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5815 begin match state.mode with
5817 | View
| Birdseye
_ | LinkNav
_ ->
5818 match state.mstate
with
5819 | Mzoom
_ | Mnone
-> ()
5824 state.mstate
<- Mpan
(x, y);
5826 then state.x <- state.x + dx;
5828 gotoy_and_clear_text y
5831 state.mstate
<- Msel
(a, (x, y));
5832 G.postRedisplay "motion select";
5835 let y = min
conf.winh
(max
0 y) in
5839 let x = min
conf.winw (max
0 x) in
5842 | Mzoomrect
(p0
, _) ->
5843 state.mstate
<- Mzoomrect
(p0
, (x, y));
5844 G.postRedisplay "motion zoomrect";
5848 method pmotion x y =
5849 begin match state.mode with
5850 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5851 let rec loop = function
5853 if hooverpageno
!= -1
5855 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5856 G.postRedisplay "pmotion birdseye no hoover";
5859 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5860 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5862 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5863 G.postRedisplay "pmotion birdseye hoover";
5873 match state.mstate
with
5874 | Mnone
-> updateunder x y
5875 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5880 method infochanged
_ = ()
5883 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5884 let p, h = scrollph state.y maxy in
5888 let winw = conf.winw - state.scrollw
- 1 in
5889 let fwinw = float winw in
5891 let sw = fwinw /. float state.w in
5892 let sw = fwinw *. sw in
5893 max
sw (float conf.scrollh
)
5896 let f = state.w+winw in
5897 let r = float (winw-state.x) /. float f in
5898 let p = fwinw *. r in
5902 if position +. sw > fwinw
5903 then fwinw -. position
5906 state.hscrollh, position, sw
5910 match state.mode with
5911 | LinkNav
_ -> "links"
5912 | Textentry
_ -> "textentry"
5913 | Birdseye
_ -> "birdseye"
5916 findkeyhash conf modename
5923 let fontpath = ref "";;
5926 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5929 let l = String.length
s in
5930 let b = Buffer.create
l in
5936 try Sys.getenv
"HOME"
5939 ("Can not determine home directory location: " ^
5940 Printexc.to_string exn
);
5944 let modifier_of_string = function
5945 | "alt" -> Wsi.altmask
5946 | "shift" -> Wsi.shiftmask
5947 | "ctrl" | "control" -> Wsi.ctrlmask
5948 | "meta" -> Wsi.metamask
5953 let r = Str.regexp
"-" in
5955 let elems = Str.full_split
r s in
5958 let m1 = modifier_of_string s in
5960 then (Wsi.namekey
s, m)
5963 | Str.Delim
s when n land 1 = 0 -> g s
5965 | Str.Delim
_ -> (k
, m)
5967 let rec loop n k
m = function
5970 let k, m = f n k m x in
5976 let keys_of_string =
5977 let r = Str.regexp
"[ \t]" in
5979 let elems = Str.split
r s in
5980 List.map
key_of_string elems
5983 let copykeyhashes c =
5984 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5987 let config_of c attrs
=
5991 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5992 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5993 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5994 | "preload" -> { c with preload = bool_of_string
v }
5995 | "page-bias" -> { c with pagebias
= int_of_string
v }
5996 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5997 | "horizontal-scroll-step" ->
5998 { c with hscrollstep
= max
(int_of_string
v) 1 }
5999 | "auto-scroll-step" ->
6000 { c with autoscrollstep
= max
0 (int_of_string
v) }
6001 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6002 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6005 match String.lowercase
v with
6006 | "true" -> Some infinity
6008 | f -> Some
(float_of_string
f)
6010 { c with maxwait
= mw}
6011 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6012 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6013 | "vertical-margin" ->
6014 { c with interpagespace = max
0 (int_of_string
v) }
6016 let zoom = float_of_string
v /. 100. in
6017 let zoom = max
zoom 0.0 in
6018 { c with zoom = zoom }
6019 | "presentation" -> { c with presentation = bool_of_string
v }
6020 | "rotation-angle" -> { c with angle
= int_of_string
v }
6021 | "width" -> { c with winw = max
20 (int_of_string
v) }
6022 | "height" -> { c with winh
= max
20 (int_of_string
v) }
6023 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6024 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6025 | "pixmap-cache-size" ->
6026 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6027 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6028 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6029 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6030 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6031 | "background-color" -> { c with bgcolor
= color_of_string v }
6032 | "scrollbar-in-presentation" ->
6033 { c with scrollbarinpm
= bool_of_string
v }
6034 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6035 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6036 | "mupdf-store-size" ->
6037 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6038 | "checkers" -> { c with checkers
= bool_of_string
v }
6039 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6040 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6041 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6042 | "uri-launcher" -> { c with urilauncher
= unent v }
6043 | "path-launcher" -> { c with pathlauncher
= unent v }
6044 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6045 | "invert-colors" -> { c with invert
= bool_of_string
v }
6046 | "brightness" -> { c with colorscale
= float_of_string
v }
6047 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6049 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6051 let (n, _, _) as nab
= multicolumns_of_string v in
6053 then { c with columns
= Csplit
(-n, [||]) }
6054 else { c with columns
= Cmulti
(nab
, [||]) }
6055 | "birds-eye-columns" ->
6056 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6057 | "selection-command" -> { c with selcmd
= unent v }
6058 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6059 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6060 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6063 prerr_endline
("Error processing attribute (`" ^
6064 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6067 let rec fold c = function
6070 let c = apply c k v in
6073 fold { c with keyhashes
= copykeyhashes c } attrs
;
6076 let fromstring f pos
n v d =
6079 dolog "Error processing attribute (%S=%S) at %d\n%s"
6080 n v pos
(Printexc.to_string exn
)
6085 let bookmark_of attrs
=
6086 let rec fold title page
rely = function
6087 | ("title", v) :: rest
-> fold v page
rely rest
6088 | ("page", v) :: rest
-> fold title v rely rest
6089 | ("rely", v) :: rest
-> fold title page
v rest
6090 | _ :: rest
-> fold title page
rely rest
6091 | [] -> title, page
, rely
6093 fold "invalid" "0" "0" attrs
6097 let rec fold path page
rely pan
= function
6098 | ("path", v) :: rest
-> fold v page
rely pan rest
6099 | ("page", v) :: rest
-> fold path v rely pan rest
6100 | ("rely", v) :: rest
-> fold path page
v pan rest
6101 | ("pan", v) :: rest
-> fold path page
rely v rest
6102 | _ :: rest
-> fold path page
rely pan rest
6103 | [] -> path, page
, rely, pan
6105 fold "" "0" "0" "0" attrs
6109 let rec fold rs ls
= function
6110 | ("out", v) :: rest
-> fold v ls rest
6111 | ("in", v) :: rest
-> fold rs
v rest
6112 | _ :: rest
-> fold ls rs rest
6118 let setconf dst
src =
6119 dst
.scrollbw
<- src.scrollbw
;
6120 dst
.scrollh
<- src.scrollh
;
6121 dst
.icase
<- src.icase
;
6122 dst
.preload <- src.preload;
6123 dst
.pagebias
<- src.pagebias
;
6124 dst
.verbose
<- src.verbose
;
6125 dst
.scrollstep
<- src.scrollstep
;
6126 dst
.maxhfit
<- src.maxhfit
;
6127 dst
.crophack
<- src.crophack
;
6128 dst
.autoscrollstep
<- src.autoscrollstep
;
6129 dst
.maxwait
<- src.maxwait
;
6130 dst
.hlinks
<- src.hlinks
;
6131 dst
.underinfo
<- src.underinfo
;
6132 dst
.interpagespace <- src.interpagespace;
6133 dst
.zoom <- src.zoom;
6134 dst
.presentation <- src.presentation;
6135 dst
.angle
<- src.angle
;
6136 dst
.winw <- src.winw;
6137 dst
.winh
<- src.winh
;
6138 dst
.savebmarks
<- src.savebmarks
;
6139 dst
.memlimit
<- src.memlimit
;
6140 dst
.proportional
<- src.proportional
;
6141 dst
.texcount
<- src.texcount
;
6142 dst
.sliceheight
<- src.sliceheight
;
6143 dst
.thumbw
<- src.thumbw
;
6144 dst
.jumpback
<- src.jumpback
;
6145 dst
.bgcolor
<- src.bgcolor
;
6146 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6147 dst
.tilew
<- src.tilew
;
6148 dst
.tileh
<- src.tileh
;
6149 dst
.mustoresize
<- src.mustoresize
;
6150 dst
.checkers
<- src.checkers
;
6151 dst
.aalevel
<- src.aalevel
;
6152 dst
.trimmargins
<- src.trimmargins
;
6153 dst
.trimfuzz
<- src.trimfuzz
;
6154 dst
.urilauncher
<- src.urilauncher
;
6155 dst
.colorspace
<- src.colorspace
;
6156 dst
.invert
<- src.invert
;
6157 dst
.colorscale
<- src.colorscale
;
6158 dst
.redirectstderr <- src.redirectstderr;
6159 dst
.ghyllscroll
<- src.ghyllscroll
;
6160 dst
.columns
<- src.columns
;
6161 dst
.beyecolumns
<- src.beyecolumns
;
6162 dst
.selcmd
<- src.selcmd
;
6163 dst
.updatecurs
<- src.updatecurs
;
6164 dst
.pathlauncher
<- src.pathlauncher
;
6165 dst
.keyhashes
<- copykeyhashes src;
6166 dst
.hfsize
<- src.hfsize
;
6167 dst
.hscrollstep
<- src.hscrollstep
;
6168 dst
.pgscale <- src.pgscale;
6172 let h = Hashtbl.create
10 in
6173 let dc = { defconf with angle
= defconf.angle
} in
6174 let rec toplevel v t spos
_ =
6176 | Vdata
| Vcdata
| Vend
-> v
6177 | Vopen
("llppconfig", _, closed
) ->
6180 else { v with f = llppconfig
}
6182 error
"unexpected subelement at top level" s spos
6183 | Vclose
_ -> error
"unexpected close at top level" s spos
6185 and llppconfig
v t spos
_ =
6187 | Vdata
| Vcdata
-> v
6188 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6189 | Vopen
("defaults", attrs
, closed
) ->
6190 let c = config_of dc attrs
in
6194 else { v with f = defaults
}
6196 | Vopen
("ui-font", attrs
, closed
) ->
6197 let rec getsize size
= function
6199 | ("size", v) :: rest
->
6201 fromstring int_of_string spos
"size" v fstate.fontsize
in
6203 | l -> getsize size l
6205 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6208 else { v with f = uifont
(Buffer.create
10) }
6210 | Vopen
("doc", attrs
, closed
) ->
6211 let pathent, spage
, srely
, span
= doc_of attrs
in
6212 let path = unent pathent
6213 and pageno = fromstring int_of_string spos
"page" spage
0
6214 and rely = fromstring float_of_string spos
"rely" srely
0.0
6215 and pan
= fromstring int_of_string spos
"pan" span
0 in
6216 let c = config_of dc attrs
in
6217 let anchor = (pageno, rely) in
6219 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6220 else { v with f = doc
path pan
anchor c [] }
6223 error
"unexpected subelement in llppconfig" s spos
6225 | Vclose
"llppconfig" -> { v with f = toplevel }
6226 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6228 and defaults
v t spos
_ =
6230 | Vdata
| Vcdata
-> v
6231 | Vend
-> error
"unexpected end of input in defaults" s spos
6232 | Vopen
("keymap", attrs
, closed
) ->
6234 try List.assoc
"mode" attrs
6235 with Not_found
-> "global" in
6240 let h = findkeyhash dc modename in
6241 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6244 { v with f = pkeymap
ret KeyMap.empty }
6246 | Vopen
(_, _, _) ->
6247 error
"unexpected subelement in defaults" s spos
6249 | Vclose
"defaults" ->
6250 { v with f = llppconfig
}
6252 | Vclose
_ -> error
"unexpected close in defaults" s spos
6254 and uifont
b v t spos
epos =
6257 Buffer.add_substring
b s spos
(epos - spos
);
6259 | Vopen
(_, _, _) ->
6260 error
"unexpected subelement in ui-font" s spos
6261 | Vclose
"ui-font" ->
6262 if String.length
!fontpath = 0
6263 then fontpath := Buffer.contents
b;
6264 { v with f = llppconfig
}
6265 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6266 | Vend
-> error
"unexpected end of input in ui-font" s spos
6268 and doc
path pan
anchor c bookmarks
v t spos
_ =
6270 | Vdata
| Vcdata
-> v
6271 | Vend
-> error
"unexpected end of input in doc" s spos
6272 | Vopen
("bookmarks", _, closed
) ->
6275 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6277 | Vopen
("keymap", attrs
, closed
) ->
6279 try List.assoc
"mode" attrs
6280 with Not_found
-> "global"
6286 let h = findkeyhash c modename in
6287 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6288 doc
path pan
anchor c bookmarks
6290 { v with f = pkeymap
ret KeyMap.empty }
6292 | Vopen
(_, _, _) ->
6293 error
"unexpected subelement in doc" s spos
6296 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6297 { v with f = llppconfig
}
6299 | Vclose
_ -> error
"unexpected close in doc" s spos
6301 and pkeymap
ret keymap
v t spos
_ =
6303 | Vdata
| Vcdata
-> v
6304 | Vend
-> error
"unexpected end of input in keymap" s spos
6305 | Vopen
("map", attrs
, closed
) ->
6306 let r, l = map_of attrs
in
6307 let kss = fromstring keys_of_string spos
"in" r [] in
6308 let lss = fromstring keys_of_string spos
"out" l [] in
6312 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6313 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6316 then { v with f = pkeymap
ret keymap }
6319 { v with f = skip
"map" f }
6322 error
"unexpected subelement in keymap" s spos
6324 | Vclose
"keymap" ->
6325 { v with f = ret keymap }
6327 | Vclose
_ -> error
"unexpected close in keymap" s spos
6329 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6331 | Vdata
| Vcdata
-> v
6332 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6333 | Vopen
("item", attrs
, closed
) ->
6334 let titleent, spage
, srely
= bookmark_of attrs
in
6335 let page = fromstring int_of_string spos
"page" spage
0
6336 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6337 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6339 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6342 { v with f = skip
"item" f }
6345 error
"unexpected subelement in bookmarks" s spos
6347 | Vclose
"bookmarks" ->
6348 { v with f = doc
path pan
anchor c bookmarks }
6350 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6352 and skip tag
f v t spos
_ =
6354 | Vdata
| Vcdata
-> v
6356 error
("unexpected end of input in skipped " ^ tag
) s spos
6357 | Vopen
(tag'
, _, closed
) ->
6361 let f'
() = { v with f = skip tag
f } in
6362 { v with f = skip tag'
f'
}
6366 else error
("unexpected close in skipped " ^ tag
) s spos
6369 parse
{ f = toplevel; accu = () } s;
6375 let len = in_channel_length ic
in
6376 let s = String.create
len in
6377 really_input ic
s 0 len;
6380 | Parse_error
(msg
, s, pos
) ->
6381 let subs = subs s pos
in
6382 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6383 failwith
("parse error: " ^
s)
6386 failwith
("config load error: " ^
Printexc.to_string exn
)
6392 let dir = Filename.concat
home ".config" in
6393 if Sys.is_directory
dir then dir else home
6396 Filename.concat
dir "llpp.conf"
6399 let confpath = ref defconfpath;;
6402 if Sys.file_exists
!confpath
6405 (try Some
(open_in_bin
!confpath)
6408 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6409 Printexc.to_string exn
);
6418 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6419 Printexc.to_string exn
);
6425 f (Hashtbl.create
0, defconf)
6430 let pc, pb
, px, pa
=
6432 Hashtbl.find h (Filename.basename
state.path)
6433 with Not_found
-> dc, [], 0, (0, 0.0)
6437 state.bookmarks <- pb
;
6439 state.scrollw
<- conf.scrollbw
;
6441 then state.anchor <- pa
;
6442 cbput state.hists
.nav pa
;
6447 let add_attrs bb always
dc c =
6450 then Printf.bprintf bb
"\n %s='%b'" s a
6453 then Printf.bprintf bb
"\n %s='%d'" s a
6456 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6459 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6462 then Printf.bprintf bb
"\n %s='%f'" s a
6466 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6470 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6474 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6478 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6484 | Some
(_N
, _A
, _B
) ->
6485 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6495 else string_of_float
f
6497 Printf.bprintf bb
"\n %s='%s'" s v
6502 | Cmulti
((n, a, b), _) when n > 1 ->
6503 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6504 | Csplit
(n, _) when n > 1 ->
6505 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6511 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6516 then dc.winw, dc.winh
6518 match state.fullscreen
with
6520 | None
-> c.winw, c.winh
6522 let zoom, presentation, interpagespace, maxwait
=
6524 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6526 match state.mode with
6527 | Birdseye
(bc
, _, _, _, _) ->
6528 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6529 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6531 oi
"width" w dc.winw;
6532 oi
"height" h dc.winh
;
6533 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6534 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6535 ob "case-insensitive-search" c.icase
dc.icase
;
6536 ob "preload" c.preload dc.preload;
6537 oi
"page-bias" c.pagebias
dc.pagebias
;
6538 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6539 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6540 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6541 ob "crop-hack" c.crophack
dc.crophack
;
6542 oW
"throttle" maxwait
dc.maxwait
;
6543 ob "highlight-links" c.hlinks
dc.hlinks
;
6544 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6545 oi
"vertical-margin" interpagespace dc.interpagespace;
6546 oz
"zoom" zoom dc.zoom;
6547 ob "presentation" presentation dc.presentation;
6548 oi
"rotation-angle" c.angle
dc.angle
;
6549 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6550 ob "proportional-display" c.proportional
dc.proportional
;
6551 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6552 oi
"tex-count" c.texcount
dc.texcount
;
6553 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6554 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6555 ob "persistent-location" c.jumpback
dc.jumpback
;
6556 oc
"background-color" c.bgcolor
dc.bgcolor
;
6557 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6558 oi
"tile-width" c.tilew
dc.tilew
;
6559 oi
"tile-height" c.tileh
dc.tileh
;
6560 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6561 ob "checkers" c.checkers
dc.checkers
;
6562 oi
"aalevel" c.aalevel
dc.aalevel
;
6563 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6564 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6565 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6566 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6567 oC
"color-space" c.colorspace
dc.colorspace
;
6568 ob "invert-colors" c.invert
dc.invert
;
6569 oF
"brightness" c.colorscale
dc.colorscale
;
6570 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6571 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6572 oco
"columns" c.columns
dc.columns
;
6573 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6574 os
"selection-command" c.selcmd
dc.selcmd
;
6575 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6576 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6577 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6578 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6581 let keymapsbuf always
dc c =
6582 let bb = Buffer.create
16 in
6583 let rec loop = function
6585 | (modename, h) :: rest
->
6586 let dh = findkeyhash dc modename in
6587 if always
|| h <> dh
6589 if Hashtbl.length
h > 0
6591 if Buffer.length
bb > 0
6592 then Buffer.add_char
bb '
\n'
;
6593 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6594 Hashtbl.iter
(fun i
o ->
6595 let isdifferent = always
||
6597 let dO = Hashtbl.find dh i
in
6599 with Not_found
-> true
6604 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6605 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6606 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6607 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6608 Buffer.add_string
bb (Wsi.keyname
k);
6611 let rec loop = function
6613 | km
:: [] -> addkm km
6614 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6618 Buffer.add_string
bb "<map in='";
6622 Buffer.add_string
bb "' out='";
6624 Buffer.add_string
bb "'/>\n"
6627 Buffer.add_string
bb "' out='";
6629 Buffer.add_string
bb "'/>\n"
6631 | KMmulti
(ins, kms
) ->
6632 Buffer.add_char
bb ' '
;
6634 Buffer.add_string
bb "' out='";
6636 Buffer.add_string
bb "'/>\n"
6638 Buffer.add_string
bb "</keymap>";
6648 let uifontsize = fstate.fontsize
in
6649 let bb = Buffer.create
32768 in
6651 let dc = if conf.bedefault
then conf else dc in
6652 Buffer.add_string
bb "<llppconfig>\n";
6654 if String.length
!fontpath > 0
6656 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6662 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6665 Buffer.add_string
bb "<defaults ";
6666 add_attrs bb true dc dc;
6667 let kb = keymapsbuf true dc dc in
6668 if Buffer.length
kb > 0
6670 Buffer.add_string
bb ">\n";
6671 Buffer.add_buffer
bb kb;
6672 Buffer.add_string
bb "\n</defaults>\n";
6674 else Buffer.add_string
bb "/>\n";
6676 let adddoc path pan
anchor c bookmarks =
6677 if bookmarks == [] && c = dc && anchor = emptyanchor
6680 Printf.bprintf
bb "<doc path='%s'"
6681 (enent
path 0 (String.length
path));
6683 if anchor <> emptyanchor
6685 let n, y = anchor in
6686 Printf.bprintf
bb " page='%d'" n;
6689 Printf.bprintf
bb " rely='%f'" y
6694 then Printf.bprintf
bb " pan='%d'" pan
;
6696 add_attrs bb false dc c;
6697 let kb = keymapsbuf false dc c in
6699 begin match bookmarks with
6701 if Buffer.length
kb > 0
6703 Buffer.add_string
bb ">\n";
6704 Buffer.add_buffer
bb kb;
6705 Buffer.add_string
bb "\n</doc>\n";
6707 else Buffer.add_string
bb "/>\n"
6709 Buffer.add_string
bb ">\n<bookmarks>\n";
6710 List.iter
(fun (title, _level
, (page, rely)) ->
6712 "<item title='%s' page='%d'"
6713 (enent
title 0 (String.length
title))
6718 Printf.bprintf
bb " rely='%f'" rely
6720 Buffer.add_string
bb "/>\n";
6722 Buffer.add_string
bb "</bookmarks>";
6723 if Buffer.length
kb > 0
6725 Buffer.add_string
bb "\n";
6726 Buffer.add_buffer
bb kb;
6728 Buffer.add_string
bb "\n</doc>\n";
6734 match state.mode with
6735 | Birdseye
(c, pan, _, _, _) ->
6737 match conf.columns
with
6738 | Cmulti
((c, _, _), _) -> Some
c
6742 match c.columns
with
6743 | Cmulti
(c, _) -> Cmulti
(c, [||])
6744 | Csingle
-> Csingle
6745 | Csplit
_ -> failwith
"quit from bird's eye while split"
6747 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6748 | _ -> state.x, conf
6750 let basename = Filename.basename state.path in
6751 adddoc basename pan (getanchor ())
6754 match state.autoscroll
with
6756 | None
-> conf.autoscrollstep
}
6757 (if conf.savebmarks
then state.bookmarks else []);
6759 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6761 then adddoc path x y c bookmarks
6763 Buffer.add_string
bb "</llppconfig>";
6766 if Buffer.length
bb > 0
6769 let tmp = !confpath ^
".tmp" in
6770 let oc = open_out_bin
tmp in
6771 Buffer.output_buffer
oc bb;
6773 Unix.rename
tmp !confpath;
6776 ("error while saving configuration: " ^
Printexc.to_string exn
)
6783 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6784 "<password> Set password");
6786 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6787 "<path> Set path to the user interface font");
6789 ("-c", Arg.String
(fun s -> Config.confpath := s),
6790 "<path> Set path to the configuration file");
6792 ("-v", Arg.Unit
(fun () ->
6794 "%s\nconfiguration path: %s\n"
6798 exit
0), " Print version and exit");
6801 (fun s -> state.path <- s)
6802 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6804 if String.length
state.path = 0
6805 then (prerr_endline
"file name missing"; exit
1);
6809 let globalkeyhash = findkeyhash conf "global" in
6810 let wsfd, winw, winh
= Wsi.init
(object
6812 if nogeomcmds state.geomcmds
|| platform == Posx
6815 GlClear.color (scalecolor2 conf.bgcolor
);
6816 GlClear.clear
[`
color];
6818 method display = display ()
6819 method reshape w h = reshape w h
6820 method mouse b d x y m = mouse b d x y m
6821 method motion x y = state.mpos
<- (x, y); motion x y
6822 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6824 let mascm = m land (
6825 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6827 match state.keystate
with
6829 let km = k, mascm in
6832 let modehash = state.uioh#
modehash in
6833 try Hashtbl.find modehash km
6835 try Hashtbl.find globalkeyhash km
6836 with Not_found
-> KMinsrt
(k, m)
6838 | KMinsrt
(k, m) -> keyboard k m
6839 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6840 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6842 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6843 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6844 state.keystate
<- KSnone
6845 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6846 state.keystate
<- KSinto
(keys
, insrt
)
6848 state.keystate
<- KSnone
6850 method enter
x y = state.mpos
<- (x, y); pmotion x y
6851 method leave = state.mpos
<- (-1, -1)
6852 method quit
= raise Quit
6853 end) conf.winw conf.winh
(platform = Posx
) in
6858 List.exists
GlMisc.check_extension
6859 [ "GL_ARB_texture_rectangle"
6860 ; "GL_EXT_texture_recangle"
6861 ; "GL_NV_texture_rectangle" ]
6863 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6866 match Ne.pipe () with
6868 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6872 match Ne.pipe () with
6874 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6884 setcheckers conf.checkers
;
6888 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6889 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6894 state.text <- "Opening " ^
state.path;
6896 opendoc state.path state.password
;
6899 let rec loop deadline
=
6901 match state.errfd
with
6902 | None
-> [state.sr
; state.wsfd]
6903 | Some fd
-> [state.sr
; state.wsfd; fd
]
6907 state.redisplay
<- false;
6914 if deadline
= infinity
6916 else max
0.0 (deadline
-. now)
6921 try Unix.select
r [] [] timeout
6922 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6928 if state.ghyll
== noghyll
6930 match state.autoscroll
with
6931 | Some step
when step
!= 0 ->
6932 let y = state.y + step
in
6936 else if y >= state.maxy then 0 else y
6939 if state.mode = View
6940 then state.text <- "";
6943 else deadline
+. 0.01
6948 let rec checkfds = function
6950 | fd
:: rest
when fd
= state.sr
->
6951 let cmd = readcmd state.sr
in
6955 | fd
:: rest
when fd
= state.wsfd ->
6960 let s = String.create
80 in
6961 let n = Unix.read fd
s 0 80 in
6962 if conf.redirectstderr
6964 Buffer.add_substring
state.errmsgs
s 0 n;
6965 state.newerrmsgs
<- true;
6966 state.redisplay
<- true;
6969 prerr_string
(String.sub
s 0 n);
6977 if deadline
= infinity
6981 match state.autoscroll
with
6982 | Some step
when step
!= 0 -> deadline1
6983 | _ -> if state.ghyll
== noghyll then infinity
else deadline1