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
338 | Cmulti
of multicolumns
339 | Csplit
of splitcolumns
342 type anchor
= pageno
* top
;;
344 type outline
= string * int * anchor
;;
346 type rect
= float * float * float * float * float * float * float * float;;
348 type tile
= opaque
* pixmapsize
* elapsed
349 and elapsed
= float;;
350 type pagemapkey
= pageno
* gen
;;
351 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
355 let emptyanchor = (0, 0.0);;
357 type infochange
= | Memused
| Docinfo
| Pdim
;;
359 class type uioh
= object
360 method display
: unit
361 method key
: int -> int -> uioh
362 method button
: int -> bool -> int -> int -> int -> uioh
363 method motion
: int -> int -> uioh
364 method pmotion
: int -> int -> uioh
365 method infochanged
: infochange
-> unit
366 method scrollpw
: (int * float * float)
367 method scrollph
: (int * float * float)
368 method modehash
: keyhash
372 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
373 | Textentry
of (textentry
* onleave
)
375 | LinkNav
of linktarget
376 and onleave
= leavetextentrystatus
-> unit
377 and leavetextentrystatus
= | Cancel
| Confirm
378 and helpitem
= string * int * action
381 | Action
of (uioh
-> uioh
)
383 | Ltexact
of (pageno
* int)
387 let isbirdseye = function Birdseye _
-> true | _
-> false;;
388 let istextentry = function Textentry _
-> true | _
-> false;;
392 | Loading
of (page
* gen
)
394 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
396 | Outlining
of outline list
399 let emptykeyhash = Hashtbl.create
0;;
400 let nouioh : uioh
= object (self
)
402 method key _ _
= self
403 method button _ _ _ _ _
= self
404 method motion _ _
= self
405 method pmotion _ _
= self
406 method infochanged _
= ()
407 method scrollpw
= (0, nan
, nan
)
408 method scrollph
= (0, nan
, nan
)
409 method modehash
= emptykeyhash
413 { mutable sr
: Unix.file_descr
414 ; mutable sw
: Unix.file_descr
415 ; mutable wsfd
: Unix.file_descr
416 ; mutable errfd
: Unix.file_descr
option
417 ; mutable stderr
: Unix.file_descr
418 ; mutable errmsgs
: Buffer.t
419 ; mutable newerrmsgs
: bool
423 ; mutable scrollw
: int
424 ; mutable hscrollh
: int
425 ; mutable anchor
: anchor
426 ; mutable ranchors
: (string * string * anchor
) list
428 ; mutable layout
: page list
429 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
430 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
431 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
432 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
433 ; mutable pagecount
: int
434 ; mutable currently
: currently
435 ; mutable mstate
: mstate
436 ; mutable searchpattern
: string
437 ; mutable rects
: (pageno
* recttype
* rect
) list
438 ; mutable rects1
: (pageno
* recttype
* rect
) list
439 ; mutable text
: string
440 ; mutable fullscreen
: (width
* height
) option
441 ; mutable mode
: mode
442 ; mutable uioh
: uioh
443 ; mutable outlines
: outline array
444 ; mutable bookmarks
: outline list
445 ; mutable path
: string
446 ; mutable password
: string
447 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
448 ; mutable memused
: memsize
450 ; mutable throttle
: (page list
* int * float) option
451 ; mutable autoscroll
: int option
452 ; mutable ghyll
: (int option -> unit)
453 ; mutable help
: helpitem array
454 ; mutable docinfo
: (int * string) list
455 ; mutable texid
: GlTex.texture_id
option
457 ; mutable prevzoom
: float
458 ; mutable progress
: float
459 ; mutable redisplay
: bool
460 ; mutable mpos
: mpos
461 ; mutable keystate
: keystate
462 ; mutable glinks
: bool
463 ; mutable prevcolumns
: (columns
* float) option
466 { pat
: string circbuf
467 ; pag
: string circbuf
468 ; nav
: anchor circbuf
469 ; sel
: string circbuf
491 ; presentation
= false
496 ; proportional
= true
497 ; trimmargins
= false
498 ; trimfuzz
= (0,0,0,0)
499 ; memlimit
= 32 lsl 20
504 ; bgcolor
= (0.5, 0.5, 0.5)
506 ; scrollbarinpm
= true
509 ; mustoresize
= 256 lsl 20
514 | Plinux
| Pfreebsd
| Pdragonflybsd
515 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
516 | Posx
-> "open \"%s\""
517 | Pcygwin
-> "cygstart \"%s\""
518 | Punknown
-> "echo %s")
519 ; pathlauncher
= "lp \"%s\""
522 | Plinux
| Pfreebsd
| Pdragonflybsd
523 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
530 ; redirectstderr
= false
537 let mk n
= (n
, Hashtbl.create
1) in
551 let findkeyhash c name
=
552 try List.assoc name c
.keyhashes
553 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
556 let conf = { defconf with angle
= defconf.angle
};;
559 { mutable fontsize
: int
560 ; mutable wwidth
: float
561 ; mutable maxrows
: int
573 fstate.fontsize
<- n
;
574 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
575 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
579 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
580 let len = String.length s
in
581 if colonpos >= 0 && colonpos + 3 < len
583 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
586 try String.rindex_from s
colonpos ' '
590 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
593 | "http" | "ftp" | "mailto" ->
595 try String.index_from s
colonpos ' '
596 with Not_found
-> len
598 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
606 if String.length
conf.urilauncher
= 0
607 then print_endline uri
609 let url = geturl uri
in
610 if String.length
url = 0
611 then print_endline uri
613 let re = Str.regexp
"%s" in
614 let command = Str.global_replace
re url conf.urilauncher
in
618 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
624 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
625 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
629 let strings = version () :: "" :: Help.keys
in
632 let url = geturl s
in
633 if String.length
url > 0
634 then (s
, 0, Action
(fun u
-> gotouri url; u
))
635 else (s
, 0, Noaction
)
640 let firstgeomcmds = "", [];;
647 ; stderr
= Unix.stderr
648 ; errmsgs
= Buffer.create
0
655 ; anchor
= emptyanchor
659 ; tilelru
= Queue.create
()
660 ; pagemap
= Hashtbl.create
10
661 ; tilemap
= Hashtbl.create
10
676 ; geomcmds
= firstgeomcmds
678 { nav
= cbnew 10 (0, 0.0)
705 Printf.kprintf prerr_endline fmt
707 Printf.kprintf ignore fmt
711 if String.length
conf.pathlauncher
= 0
712 then print_endline
state.path
714 let re = Str.regexp
"%s" in
715 let command = Str.global_replace
re state.path
conf.pathlauncher
in
719 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
725 type 'a t
= | Res
of 'a
| Exn
of exn
;;
728 try Res
(Unix.pipe ())
734 with exn
-> f
(Printexc.to_string exn
)
738 try Res
(Unix.dup fd
)
743 try Res
(Unix.dup2 fd1 fd2
)
748 let redirectstderr () =
749 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
750 if conf.redirectstderr
752 match Ne.pipe () with
754 dolog "failed to create stderr redirection pipes: %s"
755 (Printexc.to_string exn
)
758 begin match Ne.dup Unix.stderr
with
760 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
761 Ne.clo r
(clofail "pipe/r");
762 Ne.clo w
(clofail "pipe/w");
764 | Ne.Res dupstderr
->
765 begin match Ne.dup2 w
Unix.stderr
with
767 dolog "failed to dup2 to stderr: %s"
768 (Printexc.to_string exn
);
769 Ne.clo dupstderr
(clofail "stderr duplicate");
770 Ne.clo r
(clofail "redir pipe/r");
771 Ne.clo w
(clofail "redir pipe/w");
774 state.stderr
<- dupstderr
;
775 state.errfd
<- Some r
;
779 state.newerrmsgs
<- false;
780 begin match state.errfd
with
782 begin match Ne.dup2 state.stderr
Unix.stderr
with
784 dolog "failed to dup2 original stderr: %s"
785 (Printexc.to_string exn
)
787 Ne.clo fd
(clofail "dup of stderr");
788 Unix.dup2 state.stderr
Unix.stderr
;
793 prerr_string
(Buffer.contents
state.errmsgs
);
795 Buffer.clear
state.errmsgs
;
801 let postRedisplay who
=
803 then prerr_endline
("redisplay for " ^ who
);
804 state.redisplay
<- true;
808 let getopaque pageno
=
809 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
810 with Not_found
-> None
813 let putopaque pageno opaque
=
814 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
817 let pagetranslatepoint l x y
=
818 let dy = y
- l
.pagedispy
in
819 let y = dy + l
.pagey
in
820 let dx = x
- l
.pagedispx
in
821 let x = dx + l
.pagex
in
828 begin match getopaque l
.pageno
with
830 let x0 = l
.pagedispx
in
831 let x1 = x0 + l
.pagevw
in
832 let y0 = l
.pagedispy
in
833 let y1 = y0 + l
.pagevh
in
834 if y >= y0 && y <= y1 && x >= x0 && x <= x1
836 let px, py
= pagetranslatepoint l
x y in
837 match whatsunder opaque
px py
with
850 state.text
<- Printf.sprintf
"%c%s" c s
;
851 G.postRedisplay "showtext";
854 let undertext = function
857 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
858 | Utext s
-> "font: " ^ s
859 | Uunexpected s
-> "unexpected: " ^ s
860 | Ulaunch s
-> "launch: " ^ s
861 | Unamed s
-> "named: " ^ s
862 | Uremote
(filename
, pageno
) ->
863 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
866 let updateunder x y =
867 match getunder x y with
868 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
870 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
871 Wsi.setcursor
Wsi.CURSOR_INFO
872 | Ulinkgoto
(pageno
, _
) ->
874 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
875 Wsi.setcursor
Wsi.CURSOR_INFO
877 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
878 Wsi.setcursor
Wsi.CURSOR_TEXT
880 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
881 Wsi.setcursor
Wsi.CURSOR_INHERIT
883 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
884 Wsi.setcursor
Wsi.CURSOR_INHERIT
886 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
887 Wsi.setcursor
Wsi.CURSOR_INHERIT
888 | Uremote
(filename
, pageno
) ->
889 if conf.underinfo
then showtext 'r'
890 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
891 Wsi.setcursor
Wsi.CURSOR_INFO
894 let showlinktype under
=
900 let s = undertext under
in
905 let b = Buffer.create
(String.length
s + 1) in
906 Buffer.add_string
b s;
911 let colorspace_of_string s =
912 match String.lowercase
s with
916 | _
-> failwith
"invalid colorspace"
919 let int_of_colorspace = function
925 let colorspace_of_int = function
929 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
932 let colorspace_to_string = function
938 let intentry_with_suffix text key
=
940 if key
>= 32 && key
< 127
944 match Char.lowercase
c with
946 let text = addchar text c in
950 let text = addchar text c in
954 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
958 let multicolumns_to_string (n
, a
, b) =
960 then Printf.sprintf
"%d" n
961 else Printf.sprintf
"%d,%d,%d" n a
b;
964 let multicolumns_of_string s =
966 (int_of_string
s, 0, 0)
968 Scanf.sscanf
s "%u,%u,%u" (fun n a
b -> (n
, a
, b));
973 let n = Unix.read fd
s 0 4 in
974 if n != 4 then failwith
"incomplete read(len)";
976 lor (Char.code
s.[0] lsl 24)
977 lor (Char.code
s.[1] lsl 16)
978 lor (Char.code
s.[2] lsl 8)
979 lor (Char.code
s.[3] lsl 0)
981 let s = String.create
len in
982 let n = Unix.read fd
s 0 len in
983 if n != len then failwith
"incomplete read(data)";
987 let btod b = if b then 1 else 0;;
990 let b = Buffer.create
16 in
991 Buffer.add_string
b "llll";
994 let s = Buffer.contents
b in
995 let n = String.length
s in
997 (* dolog "wcmd %S" (String.sub s 4 len); *)
998 s.[0] <- Char.chr
((len lsr 24) land 0xff);
999 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1000 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1001 s.[3] <- Char.chr
(len land 0xff);
1002 let n'
= Unix.write
state.sw
s 0 n in
1003 if n'
!= n then failwith
"write failed";
1008 if conf.presentation
1010 let d = conf.winh
- h
in
1017 let rec f pn ph pi fh l
=
1019 | (n, _
, h
, _
) :: rest
->
1020 let ips = calcips h
in
1022 if conf.presentation
1025 if isbirdseye state.mode
&& pn
= 0
1030 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
1035 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
1039 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
1042 let fh = f 0 0 0 0 state.pdims
in
1047 match conf.columns
with
1048 | Csingle
-> calcheight ()
1049 | Cmulti
((c, _
, _
), b) ->
1050 let rec loop y h
n =
1054 if n = Array.length
b
1057 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
1063 loop max_int
0 (((Array.length
b - 1) / c) * c)
1065 if Array.length
b > 0
1067 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1072 let getpageyh pageno
=
1073 let rec f pn ph pi
y l
=
1075 | (n, _
, h
, _
) :: rest
->
1076 let ips = calcips h
in
1079 let h = if n = pageno
then h else ph
in
1080 if conf.presentation
&& n = pageno
1082 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
1084 y + (pageno
- pn
) * (ph
+ pi
), h
1086 let y = y + (if conf.presentation
then pi
else 0) in
1087 let y = y + (n - pn
) * (ph
+ pi
) in
1091 y + (pageno
- pn
) * (ph
+ pi
), ph
1093 f 0 0 0 0 state.pdims
1096 let getpageyh pageno
=
1097 match conf.columns
with
1098 | Csingle
-> getpageyh pageno
1100 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1104 let (_
, _
, y, (_
, _
, h, _
)) = b.(n) in
1108 let getpagedim pageno
=
1111 | (n, _
, _
, _
) as pdim
:: rest
->
1113 then (if n = pageno
then pdim
else ppdim
)
1118 f (-1, -1, -1, -1) state.pdims
1121 let getpagey pageno
= fst
(getpageyh pageno
);;
1123 let nogeomcmds cmds
=
1125 | s, [] -> String.length
s = 0
1130 let sh = sh - state.hscrollh
in
1131 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1132 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1134 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1135 let ips = calcips h in
1137 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1141 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1143 prev
, pdims
, pdimno
, 0
1145 let dy = dy + yinc in
1146 let py = py + yinc in
1147 if pageno
= state.pagecount
|| dy >= sh
1152 if py + h <= vy - yinc
1154 let py = py + h + ips in
1155 let dy = max
0 (py - y) in
1156 f ~pageno
:(pageno
+1)
1164 let pagey = vy - py in
1165 let pagevh = h - pagey in
1166 let pagevh = min
(sh - dy) pagevh in
1167 let off = if yinc > 0 then py - vy else 0 in
1168 let py = py + h + ips in
1171 if state.w
< conf.winw
- state.scrollw
1172 then (conf.winw
- state.scrollw
- state.w
) / 2
1175 let dispx = xoff + state.x in
1181 let lw = w
- pagex in
1182 min
lw (conf.winw
- state.scrollw
)
1186 ; pagedimno
= pdimno
1190 ; pagey = pagey + off
1192 ; pagevh = pagevh - off
1194 ; pagedispy
= dy + off
1198 let accu = e :: accu in
1199 f ~pageno
:(pageno
+1)
1220 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1221 let sh = sh - state.hscrollh
in
1222 let rec fold accu n =
1223 if n = Array.length
b
1226 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1229 || n = state.pagecount
- coverB
1230 || (n - coverA
) mod columns
= columns
- 1)
1236 let pagey = max
0 (y - vy) in
1237 let pagedispy = if pagey > 0 then 0 else vy - y in
1238 let pagedispx, pagex =
1240 if n = coverA
- 1 || n = state.pagecount
- coverB
1241 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1242 else dx + xoff + state.x
1249 let vw = conf.winw
- state.scrollw
- pagedispx in
1250 let pw = w
- pagex in
1253 let pagevh = min
(h - pagey) (sh - pagedispy) in
1254 if pagevw > 0 && pagevh > 0
1258 ; pagedimno
= pdimno
1265 ; pagedispx = pagedispx
1266 ; pagedispy = pagedispy
1278 List.rev
(fold [] 0)
1281 let layoutS (columns
, b) y sh =
1282 let sh = sh - state.hscrollh
in
1283 let rec fold accu n =
1284 if n = Array.length
b
1287 let pdimno, px, vy, (_
, pagew
, pageh
, xoff) = b.(n) in
1294 let x = xoff + state.x in
1295 let pagey = max
0 (y - vy) in
1296 let pagedispy = if pagey > 0 then 0 else vy - y in
1297 let pagedispx, pagex =
1311 let pagecolw = pagew
/columns
in
1313 if pagecolw < conf.winw
1314 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1318 let vw = conf.winw
- pagedispx - state.scrollw
in
1319 let pw = pagew
- pagex in
1322 let pagevw = min
pagevw pagecolw in
1323 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1324 if pagevw > 0 && pagevh > 0
1327 { pageno
= n/columns
1328 ; pagedimno
= pdimno
1335 ; pagedispx = pagedispx
1336 ; pagedispy = pagedispy
1337 ; pagecol
= n mod columns
1348 List.rev
(fold [] 0)
1352 if nogeomcmds state.geomcmds
1354 match conf.columns
with
1355 | Csingle
-> layout1 y sh
1356 | Cmulti
c -> layoutN c y sh
1357 | Csplit
s -> layoutS s y sh
1362 let y = state.y + incr
in
1364 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1369 let tilex = l
.pagex mod conf.tilew
in
1370 let tiley = l
.pagey mod conf.tileh
in
1372 let col = l
.pagex / conf.tilew
in
1373 let row = l
.pagey / conf.tileh
in
1375 let rec rowloop row y0 dispy
h =
1379 let dh = conf.tileh
- y0 in
1380 let dh = min
h dh in
1381 let rec colloop col x0 dispx w
=
1385 let dw = conf.tilew
- x0 in
1386 let dw = min w
dw in
1388 f col row dispx dispy
x0 y0 dw dh;
1389 colloop (col+1) 0 (dispx+dw) (w
-dw)
1392 colloop col tilex l
.pagedispx l
.pagevw;
1393 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1396 if l
.pagevw > 0 && l
.pagevh > 0
1397 then rowloop row tiley l
.pagedispy l
.pagevh;
1400 let gettileopaque l
col row =
1402 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1404 try Some
(Hashtbl.find
state.tilemap
key)
1405 with Not_found
-> None
1408 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1409 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1410 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1413 let drawtiles l color
=
1415 let f col row x y tilex tiley w
h =
1416 match gettileopaque l
col row with
1417 | Some
(opaque
, _
, t
) ->
1418 let params = x, y, w
, h, tilex, tiley in
1422 GlFunc.blend_func `zero `one_minus_src_color
;
1424 drawtile
params opaque
;
1426 then Gl.disable `blend
;
1429 let s = Printf.sprintf
1433 let w = measurestr
fstate.fontsize
s in
1434 GlMisc.push_attrib
[`current
];
1435 GlDraw.color
(0.0, 0.0, 0.0);
1437 (float (x-2), float (y-2))
1438 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1439 GlDraw.color
(1.0, 1.0, 1.0);
1440 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1441 GlMisc.pop_attrib
();
1446 let lw = conf.winw
- state.scrollw
- x in
1449 let lh = conf.winh
- y in
1452 begin match state.texid
with
1454 Gl.enable `texture_2d
;
1455 GlTex.bind_texture `texture_2d id
;
1458 and x1 = float (x+w)
1459 and y1 = float (y+h) in
1461 let tw = float w /. 64.0
1462 and th
= float h /. 64.0 in
1463 let tx0 = float tilex /. 64.0
1464 and ty0
= float tiley /. 64.0 in
1466 and ty1
= ty0
+. th
in
1467 GlDraw.begins `quads
;
1468 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1469 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1470 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1471 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1474 Gl.disable `texture_2d
;
1476 GlDraw.color
(1.0, 1.0, 1.0);
1479 (float (x+w), float (y+h));
1481 if w > 128 && h > fstate.fontsize
+ 10
1483 GlDraw.color
(0.0, 0.0, 0.0);
1486 then (col*conf.tilew
, row*conf.tileh
)
1489 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1496 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1498 let tilevisible1 l
x y =
1500 and ax1
= l
.pagex + l
.pagevw
1502 and ay1
= l
.pagey + l
.pagevh in
1506 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1507 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1509 let rx0 = max
ax0 bx0
1510 and ry0
= max ay0 by0
1511 and rx1
= min ax1
bx1
1512 and ry1
= min ay1 by1
in
1514 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1515 nonemptyintersection
1518 let tilevisible layout n x y =
1519 let rec findpageinlayout m
= function
1520 | l
:: rest
when l
.pageno
= n ->
1521 tilevisible1 l
x y || (
1522 match conf.columns
with
1523 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1526 | _
:: rest
-> findpageinlayout 0 rest
1529 findpageinlayout 0 layout;
1532 let tileready l
x y =
1533 tilevisible1 l
x y &&
1534 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1537 let tilepage n p
layout =
1538 let rec loop = function
1542 let f col row _ _ _ _ _ _
=
1543 if state.currently
= Idle
1545 match gettileopaque l
col row with
1548 let x = col*conf.tilew
1549 and y = row*conf.tileh
in
1551 let w = l
.pagew
- x in
1555 let h = l
.pageh
- y in
1558 wcmd "tile %s %d %d %d %d" p
x y w h;
1561 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1562 conf.tilew
, conf.tileh
1571 if nogeomcmds state.geomcmds
1575 let preloadlayout visiblepages
=
1576 let presentation = conf.presentation in
1577 let interpagespace = conf.interpagespace in
1578 let maxy = state.maxy in
1579 conf.presentation <- false;
1580 conf.interpagespace <- 0;
1581 state.maxy <- calcheight ();
1583 match visiblepages
with
1584 | [] -> if state.y >= maxy then maxy else 0
1585 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1587 let y = if y < conf.winh
then 0 else y - conf.winh
in
1588 let h = conf.winh
*3 in
1589 let pages = layout y h in
1590 conf.presentation <- presentation;
1591 conf.interpagespace <- interpagespace;
1597 let rec loop pages =
1598 if state.currently
!= Idle
1603 begin match getopaque l
.pageno
with
1605 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1606 state.currently
<- Loading
(l
, state.gen
);
1608 tilepage l
.pageno opaque
pages;
1613 if nogeomcmds state.geomcmds
1619 if conf.preload && state.currently
= Idle
1620 then load (preloadlayout pages);
1623 let layoutready layout =
1624 let rec fold all ls
=
1625 all
&& match ls
with
1627 let seen = ref false in
1628 let allvisible = ref true in
1629 let foo col row _ _ _ _ _ _
=
1631 allvisible := !allvisible &&
1632 begin match gettileopaque l
col row with
1638 fold (!seen && !allvisible) rest
1641 let alltilesvisible = fold true layout in
1646 let y = bound y 0 state.maxy in
1647 let y, layout, proceed
=
1648 match conf.maxwait
with
1649 | Some time
when state.ghyll
== noghyll ->
1650 begin match state.throttle
with
1652 let layout = layout y conf.winh
in
1653 let ready = layoutready layout in
1657 state.throttle
<- Some
(layout, y, now ());
1659 else G.postRedisplay "gotoy showall (None)";
1661 | Some
(_
, _
, started
) ->
1662 let dt = now () -. started
in
1665 state.throttle
<- None
;
1666 let layout = layout y conf.winh
in
1668 G.postRedisplay "maxwait";
1675 let layout = layout y conf.winh
in
1676 if true || layoutready layout
1677 then G.postRedisplay "gotoy ready";
1683 state.layout <- layout;
1684 begin match state.mode
with
1685 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
1686 let rec loop = function
1688 state.mode
<- LinkNav
(Ltgendir
0)
1689 | l
:: _
when l
.pageno
= pageno
->
1690 begin match getopaque pageno
with
1692 state.mode
<- LinkNav
(Ltgendir
0)
1694 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1695 if not
(x0 >= l
.pagex && x1 <= l
.pagex + l
.pagevw
1696 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1697 then state.mode
<- LinkNav
(Ltgendir
0)
1699 | _
:: rest
-> loop rest
1704 begin match state.mode
with
1705 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1706 if not
(pagevisible layout pageno
)
1708 match state.layout with
1711 state.mode
<- Birdseye
(
1712 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1715 | LinkNav
(Ltgendir dir
as lt
) ->
1717 let rec loop = function
1720 match getopaque l
.pageno
with
1726 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1728 if dir
> 0 then LDfirst
else LDlast
1734 | Lnotfound
-> loop rest
1736 showlinktype (getlink opaque
n);
1737 Ltexact
(l
.pageno
, n)
1741 state.mode
<- LinkNav
linknav
1746 state.ghyll
<- noghyll;
1749 let mx, my
= state.mpos
in
1754 let conttiling pageno opaque
=
1755 tilepage pageno opaque
1756 (if conf.preload then preloadlayout state.layout else state.layout)
1759 let gotoy_and_clear_text y =
1760 if not
conf.verbose
then state.text <- "";
1765 match state.layout with
1768 let coloff = l
.pagecol
* l
.pageh
in
1770 (float (l
.pagey - l
.pagedispy) +. float coloff) /. float l
.pageh
)
1773 let getanchory (n, top
) =
1774 let y, h = getpageyh n in
1775 y + (truncate
(top
*. float h));
1778 let gotoanchor anchor
=
1779 gotoy (getanchory anchor
);
1783 cbput state.hists
.nav
(getanchor ());
1787 let anchor = cbgetc state.hists
.nav dir
in
1792 let scroll f n a
b =
1793 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1795 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1797 then s (float f /. float a
)
1800 then 1.0 -. s ((float (f-b) /. float (n-b)))
1807 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1808 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1810 let ins = float a
*. iv1
1811 and outs
= float (n-b) *. iv1 in
1813 ins +. outs
+. float ones
1815 let rec set (_N
, _A
, _B
) y sy
=
1816 let sum = summa
1.0 _N _A _B
in
1817 let dy = float (y - sy
) in
1821 then state.ghyll
<- noghyll
1824 let s = scroll n _N _A _B
in
1825 let y1 = y1 +. ((s *. dy) /. sum) in
1826 gotoy_and_clear_text (truncate
y1);
1827 state.ghyll
<- gf (n+1) y1;
1831 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1833 gf 0 (float state.y)
1836 match conf.ghyllscroll
with
1838 gotoy_and_clear_text y
1840 if state.ghyll
== noghyll
1841 then set nab
y state.y
1842 else state.ghyll
(Some
y)
1845 let gotopage n top
=
1846 let y, h = getpageyh n in
1847 let y = y + (truncate
(top
*. float h)) in
1851 let gotopage1 n top
=
1852 let y = getpagey n in
1857 let invalidate s f =
1862 match state.geomcmds
with
1863 | ps
, [] when String.length ps
= 0 ->
1865 state.geomcmds
<- s, [];
1868 state.geomcmds
<- ps
, [s, f];
1870 | ps
, (s'
, _
) :: rest
when s'
= s ->
1871 state.geomcmds
<- ps
, ((s, f) :: rest
);
1874 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1877 let opendoc path password
=
1879 state.password
<- password
;
1880 state.gen
<- state.gen
+ 1;
1881 state.docinfo
<- [];
1883 setaalevel
conf.aalevel
;
1884 Wsi.settitle
("llpp " ^
Filename.basename path
);
1885 wcmd "open %s\000%s\000" path password
;
1886 invalidate "reqlayout"
1888 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1892 let c = c *. conf.colorscale
in
1896 let scalecolor2 (r
, g
, b) =
1897 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1900 let docolumns = function
1903 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1904 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1905 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1906 let rec fixrow m
= if m
= pageno
then () else
1907 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1910 let y = y + (rowh
- h) / 2 in
1911 a.(m
) <- (pdimno, x, y, pdim
);
1915 if pageno
= state.pagecount
1916 then fixrow (((pageno
- 1) / columns
) * columns
)
1918 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1920 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1921 pdimno+1, pdim
, rest
1926 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1928 (conf.winw
- state.scrollw
- w) / 2,
1929 y + rowh
+ conf.interpagespace, h
1932 if (pageno
- coverA
) mod columns
= 0
1933 then 0, y + rowh
+ conf.interpagespace, h
1934 else x, y, max rowh
h
1937 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1938 then fixrow (pageno
- columns
);
1939 a.(pageno
) <- (pdimno, x, y, pdim
);
1940 let x = x + w + xoff*2 + conf.interpagespace in
1941 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1943 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1944 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1947 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1948 let rec loop pageno
pdimno pdim
y pdims
=
1949 if pageno
= state.pagecount
1952 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1954 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1955 pdimno+1, pdim
, rest
1960 let rec loop1 n x y =
1961 if n = c then y else (
1962 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1963 loop1 (n+1) (x+cw) (y + h + conf.interpagespace)
1966 let y = loop1 0 0 y in
1967 loop (pageno
+1) pdimno pdim
y pdims
1969 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1970 conf.columns
<- Csplit
(c, a);
1974 docolumns conf.columns
;
1975 state.maxy <- calcheight ();
1977 if state.w <= conf.winw
- state.scrollw
1981 match state.mode
with
1982 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1983 let y, h = getpageyh pageno
in
1984 let top = (conf.winh
- h) / 2 in
1985 gotoy (max
0 (y - top))
1986 | _
-> gotoanchor state.anchor
1990 GlDraw.viewport
0 0 w h;
1991 let firsttime = state.geomcmds
== firstgeomcmds in
1992 if not
firsttime && nogeomcmds state.geomcmds
1993 then state.anchor <- getanchor ();
1996 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1999 setfontsize fstate.fontsize
;
2000 GlMat.mode `modelview
;
2001 GlMat.load_identity
();
2003 GlMat.mode `projection
;
2004 GlMat.load_identity
();
2005 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2006 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2007 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2012 else float state.x /. float state.w
2014 invalidate "geometry"
2018 then state.x <- truncate
(relx *. float w);
2020 match conf.columns
with
2022 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
2023 | Csplit
(c, _
) -> w * c
2025 wcmd "geometry %d %d" w h);
2029 let len = String.length
state.text in
2032 match state.mode
with
2035 let h, _
, _
= state.uioh#scrollpw
in
2041 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2042 (x+.w, float (conf.winh
- hscrollh))
2045 let w = float (conf.winw
- state.scrollw
- 1) in
2046 if state.progress
>= 0.0 && state.progress
< 1.0
2048 GlDraw.color
(0.3, 0.3, 0.3);
2049 let w1 = w *. state.progress
in
2051 GlDraw.color
(0.0, 0.0, 0.0);
2055 GlDraw.color
(0.0, 0.0, 0.0);
2059 GlDraw.color
(1.0, 1.0, 1.0);
2060 drawstring fstate.fontsize
2061 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2064 match state.mode
with
2065 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
2069 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2071 Printf.sprintf
"%s%s_" prefix
text
2080 if not
(istextentry state.mode
)
2082 let s1 = "(press 'e' to review error messasges)" in
2083 if String.length
s > 0 then s ^
" " ^
s1 else s1
2088 if String.length
s > 0
2093 let len = Queue.length
state.tilelru
in
2095 if state.memused
<= conf.memlimit
2100 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2101 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2102 let (_
, pw, ph
, _
) = getpagedim n in
2105 && colorspace
= conf.colorspace
2106 && angle
= conf.angle
2111 match state.throttle
with
2114 then preloadlayout state.layout
2116 | Some
(layout, _
, _
) ->
2119 let x = col*conf.tilew
2120 and y = row*conf.tileh
in
2121 tilevisible layout n x y
2123 then Queue.push lruitem
state.tilelru
2125 wcmd "freetile %s" p
;
2126 state.memused
<- state.memused
- s;
2127 state.uioh#infochanged Memused
;
2128 Hashtbl.remove
state.tilemap k
;
2137 Queue.iter
(fun (k
, p
, s) ->
2138 wcmd "freetile %s" p
;
2139 state.memused
<- state.memused
- s;
2140 state.uioh#infochanged Memused
;
2141 Hashtbl.remove
state.tilemap k
;
2143 Queue.clear
state.tilelru
;
2147 let logcurrently = function
2148 | Idle
-> dolog "Idle"
2149 | Loading
(l
, gen
) ->
2150 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2151 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2153 "Tiling %d[%d,%d] page=%s cs=%s angle"
2154 l
.pageno
col row pageopaque
2155 (colorspace_to_string colorspace
)
2157 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2158 angle gen
conf.angle
state.gen
2160 conf.tilew
conf.tileh
2167 (* dolog "%S" cmds; *)
2170 try String.index cmds ' '
2171 with Not_found
-> -1
2176 let l = String.length cmds
in
2177 let op = String.sub cmds
0 spacepos in
2179 if l - spacepos < 2 then ""
2180 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2185 state.uioh#infochanged Pdim
;
2189 state.rects
<- state.rects1
;
2190 G.postRedisplay "clearrects";
2194 try Scanf.sscanf
args "%u" (fun n -> n)
2196 dolog "error processing 'continue' %S: %s"
2197 cmds
(Printexc.to_string exn
);
2200 state.pagecount
<- n;
2201 begin match state.currently
with
2203 state.currently
<- Idle
;
2204 state.outlines
<- Array.of_list
(List.rev
l)
2208 let cur, cmds
= state.geomcmds
in
2209 if String.length
cur = 0
2210 then failwith
"umpossible";
2212 begin match List.rev cmds
with
2214 state.geomcmds
<- "", [];
2218 state.geomcmds
<- s, List.rev rest
;
2220 if conf.maxwait
= None
2221 then G.postRedisplay "continue";
2231 then showtext ' '
args
2234 let progress, text =
2236 Scanf.sscanf
args "%f %n"
2238 f, String.sub
args pos
(String.length
args - pos
))
2240 dolog "error processing 'progress' %S: %s"
2241 cmds
(Printexc.to_string exn
);
2245 state.progress <- progress;
2246 G.postRedisplay "progress"
2249 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2251 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2252 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2253 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2255 dolog "error processing 'firstmatch' %S: %s"
2256 cmds
(Printexc.to_string exn
);
2259 let y = (getpagey pageno) + truncate
y0 in
2262 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2265 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2267 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2268 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2269 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2271 dolog "error processing 'match' %S: %s"
2272 cmds
(Printexc.to_string exn
);
2276 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2281 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2283 dolog "error processing 'page' %S: %s"
2284 cmds
(Printexc.to_string exn
);
2287 begin match state.currently
with
2288 | Loading
(l, gen
) ->
2289 vlog "page %d took %f sec" l.pageno t
;
2290 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2291 begin match state.throttle
with
2293 let preloadedpages =
2295 then preloadlayout state.layout
2300 Set.Make
(struct type t
= int let compare = (-) end) in
2302 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2303 IntSet.empty
preloadedpages
2306 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2307 if not
(IntSet.mem
pageno set)
2309 wcmd "freepage %s" opaque
;
2315 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2318 state.currently
<- Idle
;
2321 tilepage l.pageno pageopaque state.layout;
2323 load preloadedpages;
2324 if pagevisible state.layout l.pageno
2325 && layoutready state.layout
2326 then G.postRedisplay "page";
2329 | Some
(layout, _
, _
) ->
2330 state.currently
<- Idle
;
2331 tilepage l.pageno pageopaque layout;
2336 dolog "Inconsistent loading state";
2337 logcurrently state.currently
;
2342 let (x, y, opaque
, size
, t
) =
2344 Scanf.sscanf
args "%u %u %s %u %f"
2345 (fun x y p size t
-> (x, y, p
, size
, t
))
2347 dolog "error processing 'tile' %S: %s"
2348 cmds
(Printexc.to_string exn
);
2351 begin match state.currently
with
2352 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2353 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2355 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2357 wcmd "freetile %s" opaque
;
2358 state.currently
<- Idle
;
2362 puttileopaque l col row gen cs angle opaque size t
;
2363 state.memused
<- state.memused
+ size
;
2364 state.uioh#infochanged Memused
;
2366 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2367 opaque
, size
) state.tilelru
;
2370 match state.throttle
with
2371 | None
-> state.layout
2372 | Some
(layout, _
, _
) -> layout
2375 state.currently
<- Idle
;
2377 && conf.colorspace
= cs
2378 && conf.angle
= angle
2379 && tilevisible layout l.pageno x y
2380 then conttiling l.pageno pageopaque;
2382 begin match state.throttle
with
2384 preload state.layout;
2386 && conf.colorspace
= cs
2387 && conf.angle
= angle
2388 && tilevisible state.layout l.pageno x y
2389 then G.postRedisplay "tile nothrottle";
2391 | Some
(layout, y, _
) ->
2392 let ready = layoutready layout in
2396 state.layout <- layout;
2397 state.throttle
<- None
;
2398 G.postRedisplay "throttle";
2405 dolog "Inconsistent tiling state";
2406 logcurrently state.currently
;
2413 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2415 dolog "error processing 'pdim' %S: %s"
2416 cmds
(Printexc.to_string exn
);
2419 state.uioh#infochanged Pdim
;
2420 state.pdims
<- pdim :: state.pdims
2423 let (l, n, t
, h, pos
) =
2425 Scanf.sscanf
args "%u %u %d %u %n"
2426 (fun l n t
h pos
-> l, n, t
, h, pos
)
2428 dolog "error processing 'o' %S: %s"
2429 cmds
(Printexc.to_string exn
);
2432 let s = String.sub
args pos
(String.length
args - pos
) in
2433 let outline = (s, l, (n, float t
/. float h)) in
2434 begin match state.currently
with
2435 | Outlining outlines
->
2436 state.currently
<- Outlining
(outline :: outlines
)
2438 state.currently
<- Outlining
[outline]
2440 dolog "invalid outlining state";
2441 logcurrently currently
2445 state.docinfo
<- (1, args) :: state.docinfo
2448 state.uioh#infochanged Docinfo
;
2449 state.docinfo
<- List.rev
state.docinfo
2452 dolog "unknown cmd `%S'" cmds
2457 let action = function
2458 | HCprev
-> cbget cb ~
-1
2459 | HCnext
-> cbget cb
1
2460 | HCfirst
-> cbget cb ~
-(cb
.rc)
2461 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2462 and cancel
() = cb
.rc <- rc
2466 let search pattern forward
=
2467 if String.length pattern
> 0
2470 match state.layout with
2473 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2475 wcmd "search %d %d %d %d,%s\000"
2476 (btod conf.icase
) pn py (btod forward
) pattern
;
2479 let intentry text key =
2481 if key >= 32 && key < 127
2487 let text = addchar text c in
2491 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2495 let linknentry text key =
2497 if key >= 32 && key < 127
2503 let text = addchar text c in
2507 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2512 if String.length
s > 0
2515 let l = String.length
s in
2516 let rec loop pos
n = if pos
= l then n else
2517 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2518 loop (pos
+1) (n*26 + m)
2521 let rec loop n = function
2524 match getopaque l.pageno with
2525 | None
-> loop n rest
2527 let m = getlinkcount opaque
in
2530 let under = getlink opaque
n in
2533 else loop (n-m) rest
2535 loop n state.layout;
2539 let textentry text key =
2540 if key land 0xff00 = 0xff00
2542 else TEcont
(text ^
Wsi.toutf8
key)
2545 let reqlayout angle proportional
=
2546 match state.throttle
with
2548 if nogeomcmds state.geomcmds
2549 then state.anchor <- getanchor ();
2550 conf.angle
<- angle
mod 360;
2553 match state.mode
with
2554 | LinkNav _
-> state.mode
<- View
2557 conf.proportional
<- proportional
;
2558 invalidate "reqlayout"
2559 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2563 let settrim trimmargins trimfuzz
=
2564 if nogeomcmds state.geomcmds
2565 then state.anchor <- getanchor ();
2566 conf.trimmargins
<- trimmargins
;
2567 conf.trimfuzz
<- trimfuzz
;
2568 let x0, y0, x1, y1 = trimfuzz
in
2569 invalidate "settrim"
2571 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2572 Hashtbl.iter
(fun _ opaque
->
2573 wcmd "freepage %s" opaque
;
2575 Hashtbl.clear
state.pagemap
;
2579 match state.throttle
with
2581 let zoom = max
0.01 zoom in
2582 if zoom <> conf.zoom
2584 state.prevzoom
<- conf.zoom;
2586 reshape conf.winw
conf.winh
;
2587 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2590 | Some
(layout, y, started
) ->
2592 match conf.maxwait
with
2596 let dt = now () -. started
in
2604 let setcolumns mode columns coverA coverB
=
2605 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2609 then showtext '
!'
"split mode doesn't work in bird's eye"
2611 conf.columns
<- Csplit
(-columns
, [||]);
2619 conf.columns
<- Csingle
;
2624 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2628 reshape conf.winw
conf.winh
;
2631 let enterbirdseye () =
2632 let zoom = float conf.thumbw
/. float conf.winw
in
2633 let birdseyepageno =
2634 let cy = conf.winh
/ 2 in
2638 let rec fold best
= function
2641 let d = cy - (l.pagedispy + l.pagevh/2)
2642 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2643 if abs
d < abs dbest
2650 state.mode
<- Birdseye
(
2651 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2654 conf.presentation <- false;
2655 conf.interpagespace <- 10;
2656 conf.hlinks
<- false;
2658 state.mstate
<- Mnone
;
2659 conf.maxwait
<- None
;
2661 match conf.beyecolumns
with
2664 Cmulti
((c, 0, 0), [||])
2667 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2670 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2675 reshape conf.winw
conf.winh
;
2678 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2680 conf.zoom <- c.zoom;
2681 conf.presentation <- c.presentation;
2682 conf.interpagespace <- c.interpagespace;
2683 conf.maxwait
<- c.maxwait
;
2684 conf.hlinks
<- c.hlinks
;
2685 conf.beyecolumns
<- (
2686 match conf.columns
with
2687 | Cmulti
((c, _
, _
), _
) -> Some
c
2689 | Csplit _
-> failwith
"leaving bird's eye split mode"
2692 match c.columns
with
2693 | Cmulti
(c, _
) -> Cmulti
(c, [||])
2694 | Csingle
-> Csingle
2695 | Csplit
(c, _
) -> Csplit
(c, [||])
2700 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2703 reshape conf.winw
conf.winh
;
2704 state.anchor <- if goback
then anchor else (pageno, 0.0);
2707 let togglebirdseye () =
2708 match state.mode
with
2709 | Birdseye vals
-> leavebirdseye vals
true
2710 | View
-> enterbirdseye ()
2714 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2715 let pageno = max
0 (pageno - incr
) in
2716 let rec loop = function
2717 | [] -> gotopage1 pageno 0
2718 | l :: _
when l.pageno = pageno ->
2719 if l.pagedispy >= 0 && l.pagey = 0
2720 then G.postRedisplay "upbirdseye"
2721 else gotopage1 pageno 0
2722 | _
:: rest
-> loop rest
2725 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2728 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2729 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2730 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2731 let rec loop = function
2733 let y, h = getpageyh pageno in
2734 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2736 | l :: _
when l.pageno = pageno ->
2737 if l.pagevh != l.pageh
2738 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2739 else G.postRedisplay "downbirdseye"
2740 | _
:: rest
-> loop rest
2745 let optentry mode _
key =
2746 let btos b = if b then "on" else "off" in
2747 if key >= 32 && key < 127
2749 let c = Char.chr
key in
2753 try conf.scrollstep
<- int_of_string
s with exc
->
2754 state.text <- Printf.sprintf
"bad integer `%s': %s"
2755 s (Printexc.to_string exc
)
2757 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2762 conf.autoscrollstep
<- int_of_string
s;
2763 if state.autoscroll
<> None
2764 then state.autoscroll
<- Some
conf.autoscrollstep
2766 state.text <- Printf.sprintf
"bad integer `%s': %s"
2767 s (Printexc.to_string exc
)
2769 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2774 let n, a, b = multicolumns_of_string s in
2775 setcolumns mode
n a b;
2777 state.text <- Printf.sprintf
"bad columns `%s': %s"
2778 s (Printexc.to_string exc
)
2780 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2785 let zoom = float (int_of_string
s) /. 100.0 in
2788 state.text <- Printf.sprintf
"bad integer `%s': %s"
2789 s (Printexc.to_string exc
)
2791 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2796 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2798 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2799 begin match mode
with
2801 leavebirdseye beye
false;
2806 state.text <- Printf.sprintf
"bad integer `%s': %s"
2807 s (Printexc.to_string exc
)
2809 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2814 Some
(int_of_string
s)
2816 state.text <- Printf.sprintf
"bad integer `%s': %s"
2817 s (Printexc.to_string exc
);
2820 | Some angle
-> reqlayout angle
conf.proportional
2823 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2826 conf.icase
<- not
conf.icase
;
2827 TEdone
("case insensitive search " ^
(btos conf.icase
))
2830 conf.preload <- not
conf.preload;
2832 TEdone
("preload " ^
(btos conf.preload))
2835 conf.verbose
<- not
conf.verbose
;
2836 TEdone
("verbose " ^
(btos conf.verbose
))
2839 conf.debug
<- not
conf.debug
;
2840 TEdone
("debug " ^
(btos conf.debug
))
2843 conf.maxhfit
<- not
conf.maxhfit
;
2844 state.maxy <- calcheight ();
2845 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2848 conf.crophack
<- not
conf.crophack
;
2849 TEdone
("crophack " ^
btos conf.crophack
)
2853 match conf.maxwait
with
2855 conf.maxwait
<- Some infinity
;
2856 "always wait for page to complete"
2858 conf.maxwait
<- None
;
2859 "show placeholder if page is not ready"
2864 conf.underinfo
<- not
conf.underinfo
;
2865 TEdone
("underinfo " ^
btos conf.underinfo
)
2868 conf.savebmarks
<- not
conf.savebmarks
;
2869 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2875 match state.layout with
2880 conf.interpagespace <- int_of_string
s;
2881 docolumns conf.columns
;
2882 state.maxy <- calcheight ();
2883 let y = getpagey pageno in
2886 state.text <- Printf.sprintf
"bad integer `%s': %s"
2887 s (Printexc.to_string exc
)
2889 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2892 reqlayout conf.angle
(not
conf.proportional
);
2893 TEdone
("proportional display " ^
btos conf.proportional
)
2896 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2897 TEdone
("trim margins " ^
btos conf.trimmargins
)
2900 conf.invert
<- not
conf.invert
;
2901 TEdone
("invert colors " ^
btos conf.invert
)
2905 cbput state.hists
.sel
s;
2908 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2909 textentry, ondone, true)
2912 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2918 class type lvsource
= object
2919 method getitemcount
: int
2920 method getitem
: int -> (string * int)
2921 method hasaction
: int -> bool
2930 method getactive
: int
2931 method getfirst
: int
2932 method getqsearch
: string
2933 method setqsearch
: string -> unit
2937 class virtual lvsourcebase
= object
2938 val mutable m_active
= 0
2939 val mutable m_first
= 0
2940 val mutable m_qsearch
= ""
2941 val mutable m_pan
= 0
2942 method getactive
= m_active
2943 method getfirst
= m_first
2944 method getqsearch
= m_qsearch
2945 method getpan
= m_pan
2946 method setqsearch
s = m_qsearch
<- s
2949 let withoutlastutf8 s =
2950 let len = String.length
s in
2958 let b = Char.code
s.[pos
] in
2959 if b land 0b110000 = 0b11000000
2964 if Char.code
s.[len-1] land 0x80 = 0
2968 String.sub
s 0 first;
2971 let textentrykeyboard
2972 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2974 state.mode
<- Textentry
(te
, onleave
);
2977 G.postRedisplay "textentrykeyboard enttext";
2979 let histaction cmd
=
2982 | Some
(action, _
) ->
2983 state.mode
<- Textentry
(
2984 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2986 G.postRedisplay "textentry histaction"
2989 | 0xff08 -> (* backspace *)
2990 let s = withoutlastutf8 text in
2991 let len = String.length
s in
2992 if cancelonempty
&& len = 0
2995 G.postRedisplay "textentrykeyboard after cancel";
2998 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3004 G.postRedisplay "textentrykeyboard after confirm"
3006 | 0xff52 -> histaction HCprev
3007 | 0xff54 -> histaction HCnext
3008 | 0xff50 -> histaction HCfirst
3009 | 0xff57 -> histaction HClast
3011 | 0xff1b -> (* escape*)
3012 if String.length
text = 0
3014 begin match opthist
with
3016 | Some
(_
, onhistcancel
) -> onhistcancel
()
3020 G.postRedisplay "textentrykeyboard after cancel2"
3023 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3026 | 0xff9f | 0xffff -> () (* delete *)
3028 | _
when key != 0 && key land 0xff00 != 0xff00 ->
3029 begin match onkey
text key with
3033 G.postRedisplay "textentrykeyboard after confirm2";
3036 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3040 G.postRedisplay "textentrykeyboard after cancel3"
3043 state.mode
<- Textentry
(te
, onleave
);
3044 G.postRedisplay "textentrykeyboard switch";
3048 vlog "unhandled key %s" (Wsi.keyname
key)
3051 let firstof first active
=
3052 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3053 then max
0 (active
- (fstate.maxrows
/2))
3057 let calcfirst first active
=
3060 let rows = active
- first in
3061 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3065 let scrollph y maxy =
3066 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
3067 let sh = float conf.winh
/. sh in
3068 let sh = max
sh (float conf.scrollh
) in
3073 else float y /. float maxy
3075 let position = (float conf.winh
-. sh) *. percent in
3078 if position +. sh > float conf.winh
3079 then float conf.winh
-. sh
3085 let coe s = (s :> uioh
);;
3087 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3089 val m_pan
= source#getpan
3090 val m_first
= source#getfirst
3091 val m_active
= source#getactive
3092 val m_qsearch
= source#getqsearch
3093 val m_prev_uioh
= state.uioh
3095 method private elemunder
y =
3096 let n = y / (fstate.fontsize
+1) in
3097 if m_first
+ n < source#getitemcount
3099 if source#hasaction
(m_first
+ n)
3100 then Some
(m_first
+ n)
3107 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3108 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3109 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3110 GlDraw.color
(1., 1., 1.);
3111 Gl.enable `texture_2d
;
3112 let fs = fstate.fontsize
in
3114 let ww = fstate.wwidth
in
3115 let tabw = 30.0*.ww in
3116 let itemcount = source#getitemcount
in
3118 if (row - m_first
) * nfs > conf.winh
3121 if row >= 0 && row < itemcount
3123 let (s, level
) = source#getitem
row in
3124 let y = (row - m_first
) * nfs in
3125 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3128 Gl.disable `texture_2d
;
3129 GlDraw.polygon_mode `both `line
;
3130 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3131 GlDraw.rect (1., float (y + 1))
3132 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3133 GlDraw.polygon_mode `both `fill
;
3134 GlDraw.color
(1., 1., 1.);
3135 Gl.enable `texture_2d
;
3138 let drawtabularstring s =
3139 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3142 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3145 let len = String.length
s - tabpos - 1 in
3146 let s1 = String.sub
s 0 tabpos
3147 and s2
= String.sub
s (tabpos + 1) len in
3148 let nx = drawstr x s1 in
3150 let x = x +. (max
tabw sw) in
3157 let _ = drawtabularstring s in
3164 Gl.disable `texture_2d
;
3166 method updownlevel incr
=
3167 let len = source#getitemcount
in
3169 if m_active
>= 0 && m_active
< len
3170 then snd
(source#getitem m_active
)
3174 if i
= len then i
-1 else if i
= -1 then 0 else
3175 let _, l = source#getitem i
in
3176 if l != curlevel then i
else flow (i
+incr
)
3178 let active = flow m_active
in
3179 let first = calcfirst m_first
active in
3180 G.postRedisplay "outline updownlevel";
3181 {< m_active
= active; m_first
= first >}
3183 method private key1
key mask
=
3184 let set1 active first qsearch
=
3185 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3187 let search active pattern incr
=
3190 if n >= 0 && n < source#getitemcount
3192 let s, _ = source#getitem
n in
3194 (try ignore
(Str.search_forward
re s 0); true
3195 with Not_found
-> false)
3197 else loop (n + incr
)
3204 let re = Str.regexp_case_fold pattern
in
3210 let itemcount = source#getitemcount
in
3211 let find start incr
=
3213 if i
= -1 || i
= itemcount
3216 if source#hasaction i
3218 else find (i
+ incr
)
3223 let set active first =
3224 let first = bound first 0 (itemcount - fstate.maxrows
) in
3226 coe {< m_active
= active; m_first
= first >}
3229 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3231 let incr1 = if incr
> 0 then 1 else -1 in
3232 if isvisible m_first m_active
3235 let next = m_active
+ incr
in
3237 if next < 0 || next >= itemcount
3239 else find next incr1
3241 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3247 let first = m_first
+ incr
in
3248 let first = bound first 0 (itemcount - 1) in
3250 let next = m_active
+ incr
in
3251 let next = bound next 0 (itemcount - 1) in
3254 let active = if next = -1 then m_active
else next in
3257 let first = min
next m_first
in
3259 if abs
(next - first) > fstate.maxrows
3265 let first = m_first
+ incr
in
3266 let first = bound first 0 (itemcount - 1) in
3268 let next = m_active
+ incr
in
3269 let next = bound next 0 (itemcount - 1) in
3270 let next = find next incr1 in
3272 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3274 let active = if m_active
= -1 then next else m_active
in
3279 if isvisible first active
3285 G.postRedisplay "listview navigate";
3289 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3290 let incr = if key = 0x72 then -1 else 1 in
3292 match search (m_active
+ incr) m_qsearch
incr with
3294 state.text <- m_qsearch ^
" [not found]";
3297 state.text <- m_qsearch
;
3298 active, firstof m_first
active
3300 G.postRedisplay "listview ctrl-r/s";
3301 set1 active first m_qsearch
;
3303 | 0xff08 -> (* backspace *)
3304 if String.length m_qsearch
= 0
3307 let qsearch = withoutlastutf8 m_qsearch
in
3308 let len = String.length
qsearch in
3312 G.postRedisplay "listview empty qsearch";
3313 set1 m_active m_first
"";
3317 match search m_active
qsearch ~
-1 with
3319 state.text <- qsearch ^
" [not found]";
3322 state.text <- qsearch;
3323 active, firstof m_first
active
3325 G.postRedisplay "listview backspace qsearch";
3326 set1 active first qsearch
3329 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3330 let pattern = m_qsearch ^
Wsi.toutf8
key in
3332 match search m_active
pattern 1 with
3334 state.text <- pattern ^
" [not found]";
3337 state.text <- pattern;
3338 active, firstof m_first
active
3340 G.postRedisplay "listview qsearch add";
3341 set1 active first pattern;
3343 | 0xff1b -> (* escape *)
3345 if String.length m_qsearch
= 0
3347 G.postRedisplay "list view escape";
3350 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3352 | None
-> m_prev_uioh
3357 G.postRedisplay "list view kill qsearch";
3358 source#setqsearch
"";
3359 coe {< m_qsearch
= "" >}
3362 | 0xff0d -> (* return *)
3364 let self = {< m_qsearch
= "" >} in
3365 source#setqsearch
"";
3367 G.postRedisplay "listview enter";
3368 if m_active
>= 0 && m_active
< source#getitemcount
3370 source#exit
(coe self) false m_active m_first m_pan
"";
3373 source#exit
(coe self) true m_active m_first m_pan
"";
3376 begin match opt with
3377 | None
-> m_prev_uioh
3381 | 0xff9f | 0xffff -> (* delete *)
3384 | 0xff52 -> navigate ~
-1 (* up *)
3385 | 0xff54 -> navigate 1 (* down *)
3386 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3387 | 0xff56 -> navigate fstate.maxrows
(* next *)
3389 | 0xff53 -> (* right *)
3391 G.postRedisplay "listview right";
3392 coe {< m_pan
= m_pan
- 1 >}
3394 | 0xff51 -> (* left *)
3396 G.postRedisplay "listview left";
3397 coe {< m_pan
= m_pan
+ 1 >}
3399 | 0xff50 -> (* home *)
3400 let active = find 0 1 in
3401 G.postRedisplay "listview home";
3404 | 0xff57 -> (* end *)
3405 let first = max
0 (itemcount - fstate.maxrows
) in
3406 let active = find (itemcount - 1) ~
-1 in
3407 G.postRedisplay "listview end";
3410 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3414 dolog "listview unknown key %#x" key; coe self
3416 method key key mask
=
3417 match state.mode
with
3418 | Textentry te
-> textentrykeyboard key mask te
; coe self
3419 | _ -> self#key1
key mask
3421 method button button down
x y _ =
3424 | 1 when x > conf.winw
- conf.scrollbw
->
3425 G.postRedisplay "listview scroll";
3428 let _, position, sh = self#
scrollph in
3429 if y > truncate
position && y < truncate
(position +. sh)
3431 state.mstate
<- Mscrolly
;
3435 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3436 let first = truncate
(s *. float source#getitemcount
) in
3437 let first = min source#getitemcount
first in
3438 Some
(coe {< m_first
= first; m_active
= first >})
3440 state.mstate
<- Mnone
;
3443 | 1 when not down
->
3444 begin match self#elemunder
y with
3446 G.postRedisplay "listview click";
3448 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3452 | n when (n == 4 || n == 5) && not down
->
3453 let len = source#getitemcount
in
3455 if n = 5 && m_first
+ fstate.maxrows
>= len
3459 let first = m_first
+ (if n == 4 then -1 else 1) in
3460 bound first 0 (len - 1)
3462 G.postRedisplay "listview wheel";
3463 Some
(coe {< m_first
= first >})
3464 | n when (n = 6 || n = 7) && not down
->
3465 let inc = m_first
+ (if n = 7 then -1 else 1) in
3466 G.postRedisplay "listview hwheel";
3467 Some
(coe {< m_pan
= m_pan
+ inc >})
3472 | None
-> m_prev_uioh
3476 match state.mstate
with
3478 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3479 let first = truncate
(s *. float source#getitemcount
) in
3480 let first = min source#getitemcount
first in
3481 G.postRedisplay "listview motion";
3482 coe {< m_first
= first; m_active
= first >}
3485 method pmotion
x y =
3486 if x < conf.winw
- conf.scrollbw
3489 match self#elemunder
y with
3490 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3491 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3495 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3500 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3504 method infochanged
_ = ()
3506 method scrollpw
= (0, 0.0, 0.0)
3508 let nfs = fstate.fontsize
+ 1 in
3509 let y = m_first
* nfs in
3510 let itemcount = source#getitemcount
in
3511 let maxi = max
0 (itemcount - fstate.maxrows
) in
3512 let maxy = maxi * nfs in
3513 let p, h = scrollph y maxy in
3516 method modehash
= modehash
3519 class outlinelistview ~source
=
3522 ~source
:(source
:> lvsource
)
3524 ~modehash
:(findkeyhash conf "outline")
3527 method key key mask
=
3528 let calcfirst first active =
3531 let rows = active - first in
3533 if String.length
state.text = 0
3535 else fstate.maxrows - 2
3537 if rows > maxrows then active - maxrows else first
3541 let active = m_active
+ incr in
3542 let active = bound active 0 (source#getitemcount
- 1) in
3543 let first = calcfirst m_first
active in
3544 G.postRedisplay "outline navigate";
3545 coe {< m_active
= active; m_first
= first >}
3547 let ctrl = Wsi.withctrl mask
in
3549 | 110 when ctrl -> (* ctrl-n *)
3550 source#narrow m_qsearch
;
3551 G.postRedisplay "outline ctrl-n";
3552 coe {< m_first
= 0; m_active
= 0 >}
3554 | 117 when ctrl -> (* ctrl-u *)
3556 G.postRedisplay "outline ctrl-u";
3558 coe {< m_first
= 0; m_active
= 0 >}
3560 | 108 when ctrl -> (* ctrl-l *)
3561 let first = m_active
- (fstate.maxrows / 2) in
3562 G.postRedisplay "outline ctrl-l";
3563 coe {< m_first
= first >}
3565 | 0xff9f | 0xffff -> (* delete *)
3566 source#remove m_active
;
3567 G.postRedisplay "outline delete";
3568 let active = max
0 (m_active
-1) in
3569 coe {< m_first
= firstof m_first
active;
3570 m_active
= active >}
3572 | 0xff52 -> navigate ~
-1 (* up *)
3573 | 0xff54 -> navigate 1 (* down *)
3574 | 0xff55 -> (* prior *)
3575 navigate ~
-(fstate.maxrows)
3576 | 0xff56 -> (* next *)
3577 navigate fstate.maxrows
3579 | 0xff53 -> (* [ctrl-]right *)
3583 G.postRedisplay "outline ctrl right";
3584 {< m_pan
= m_pan
+ 1 >}
3586 else self#updownlevel
1
3590 | 0xff51 -> (* [ctrl-]left *)
3594 G.postRedisplay "outline ctrl left";
3595 {< m_pan
= m_pan
- 1 >}
3597 else self#updownlevel ~
-1
3601 | 0xff50 -> (* home *)
3602 G.postRedisplay "outline home";
3603 coe {< m_first
= 0; m_active
= 0 >}
3605 | 0xff57 -> (* end *)
3606 let active = source#getitemcount
- 1 in
3607 let first = max
0 (active - fstate.maxrows) in
3608 G.postRedisplay "outline end";
3609 coe {< m_active
= active; m_first
= first >}
3611 | _ -> super#
key key mask
3614 let outlinesource usebookmarks
=
3617 inherit lvsourcebase
3618 val mutable m_items
= empty
3619 val mutable m_orig_items
= empty
3620 val mutable m_prev_items
= empty
3621 val mutable m_narrow_pattern
= ""
3622 val mutable m_hadremovals
= false
3624 method getitemcount
=
3625 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3628 if n == Array.length m_items
&& m_hadremovals
3630 ("[Confirm removal]", 0)
3632 let s, n, _ = m_items
.(n) in
3635 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3636 ignore
(uioh
, first, qsearch);
3637 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3639 if String.length m_narrow_pattern
= 0
3645 if not
confrimremoval
3647 let _, _, anchor = m_items
.(active) in
3652 state.bookmarks
<- Array.to_list m_items
;
3653 m_orig_items
<- m_items
;
3656 else m_items
<- items;
3660 method hasaction
_ = true
3663 if Array.length m_items
!= Array.length m_orig_items
3664 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3667 method narrow
pattern =
3668 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3672 let rec loop accu n =
3675 m_narrow_pattern
<- pattern;
3676 m_items
<- Array.of_list
accu
3679 let (s, _, _) as o = m_items
.(n) in
3681 if (try ignore
(Str.search_forward
re s 0); true
3682 with Not_found
-> false)
3688 loop [] (Array.length m_items
- 1)
3693 then Array.of_list
state.bookmarks
3696 m_items
<- m_orig_items
3701 if m >= 0 && m < Array.length m_items
3703 m_hadremovals
<- true;
3704 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3705 let n = if n >= m then n+1 else n in
3710 method reset
anchor items =
3711 m_hadremovals
<- false;
3712 if m_orig_items
== empty || m_prev_items
!= items
3714 m_orig_items
<- items;
3715 if String.length m_narrow_pattern
= 0
3716 then m_items
<- items;
3718 m_prev_items
<- items;
3719 let rely = getanchory anchor in
3721 let rec loop n best bestd
=
3722 if n = Array.length m_items
3725 let (_, _, anchor) = m_items
.(n) in
3726 let orely = getanchory anchor in
3727 let d = abs
(orely - rely) in
3730 else loop (n+1) best bestd
3735 m_first
<- firstof m_first
active
3739 let enterselector usebookmarks
=
3740 let source = outlinesource usebookmarks
in
3744 then Array.of_list
state.bookmarks
3747 if Array.length
outlines = 0
3749 showtext ' ' errmsg
;
3752 state.text <- source#greetmsg
;
3753 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3754 let anchor = getanchor () in
3755 source#reset
anchor outlines;
3756 state.uioh
<- coe (new outlinelistview ~
source);
3757 G.postRedisplay "enter selector";
3761 let enteroutlinemode =
3762 let f = enterselector false in
3763 fun ()-> f "Document has no outline";
3766 let enterbookmarkmode =
3767 let f = enterselector true in
3768 fun () -> f "Document has no bookmarks (yet)";
3771 let color_of_string s =
3772 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3773 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3777 let color_to_string (r
, g
, b) =
3778 let r = truncate
(r *. 256.0)
3779 and g
= truncate
(g
*. 256.0)
3780 and b = truncate
(b *. 256.0) in
3781 Printf.sprintf
"%d/%d/%d" r g
b
3784 let irect_of_string s =
3785 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3788 let irect_to_string (x0,y0,x1,y1) =
3789 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3792 let makecheckers () =
3793 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3795 converted by Issac Trotts. July 25, 2002 *)
3796 let image_height = 64
3797 and image_width
= 64 in
3801 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3803 for i
= 0 to image_width
- 1 do
3804 for j
= 0 to image_height - 1 do
3805 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3806 (if (i
land 8 ) lxor (j
land 8) = 0
3807 then [|255;255;255|] else [|200;200;200|])
3812 let image = make_image () in
3813 let id = GlTex.gen_texture
() in
3814 GlTex.bind_texture `texture_2d
id;
3815 GlPix.store
(`unpack_alignment
1);
3816 GlTex.image2d
image;
3817 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3820 `mag_filter `nearest
;
3821 `min_filter `nearest
];
3825 let setcheckers enabled
=
3826 match state.texid
with
3828 if enabled
then state.texid
<- Some
(makecheckers ())
3833 GlTex.delete_texture texid
;
3834 state.texid
<- None
;
3838 let int_of_string_with_suffix s =
3839 let l = String.length
s in
3843 let suffix = Char.lowercase
s.[l-1] in
3845 | 'k'
-> String.sub
s 0 (l-1), 10
3846 | '
m'
-> String.sub
s 0 (l-1), 20
3847 | 'g'
-> String.sub
s 0 (l-1), 30
3851 let n = int_of_string
s1 in
3852 let m = n lsl shift
in
3854 then raise
(Failure
"value too large")
3858 let string_with_suffix_of_int n =
3863 if n land ((1 lsl 20) - 1) = 0
3866 if n land ((1 lsl 10) - 1) = 0
3872 let h = n mod 1000 in
3875 then string_of_int
h ^
s
3877 let s = Printf.sprintf
"_%03d%s" h s in
3884 let defghyllscroll = (40, 8, 32);;
3885 let ghyllscroll_of_string s =
3886 let (n, a, b) as nab
=
3889 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3891 if n <= a || n <= b || a >= b
3892 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3896 let ghyllscroll_to_string ((n, a, b) as nab
) =
3897 if nab
= defghyllscroll
3899 else Printf.sprintf
"%d,%d,%d" n a b;
3902 let describe_location () =
3904 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3906 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3907 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3911 else (100. *. (float state.y /. float maxy))
3915 Printf.sprintf
"page %d of %d [%.2f%%]"
3916 (fn+1) state.pagecount
percent
3919 "pages %d-%d of %d [%.2f%%]"
3920 (fn+1) (ln
+1) state.pagecount
percent
3924 let btos b = if b then "\xe2\x88\x9a" else "" in
3925 let showextended = ref false in
3926 let leave mode
= function
3927 | Confirm
-> state.mode
<- mode
3928 | Cancel
-> state.mode
<- mode
in
3931 val mutable m_first_time
= true
3932 val mutable m_l
= []
3933 val mutable m_a
= [||]
3934 val mutable m_prev_uioh
= nouioh
3935 val mutable m_prev_mode
= View
3937 inherit lvsourcebase
3939 method reset prev_mode prev_uioh
=
3940 m_a
<- Array.of_list
(List.rev m_l
);
3942 m_prev_mode
<- prev_mode
;
3943 m_prev_uioh
<- prev_uioh
;
3947 if n >= Array.length m_a
3951 | _, _, _, Action
_ -> m_active
<- n
3955 m_first_time
<- false;
3958 method int name get
set =
3960 (name
, `
int get
, 1, Action
(
3963 try set (int_of_string
s)
3965 state.text <- Printf.sprintf
"bad integer `%s': %s"
3966 s (Printexc.to_string exn
)
3969 let te = name ^
": ", "", None
, intentry, ondone, true in
3970 state.mode
<- Textentry
(te, leave m_prev_mode
);
3974 method int_with_suffix name get
set =
3976 (name
, `intws get
, 1, Action
(
3979 try set (int_of_string_with_suffix s)
3981 state.text <- Printf.sprintf
"bad integer `%s': %s"
3982 s (Printexc.to_string exn
)
3986 name ^
": ", "", None
, intentry_with_suffix, ondone, true
3988 state.mode
<- Textentry
(te, leave m_prev_mode
);
3992 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3994 (name
, `
bool (btos, get
), offset
, Action
(
4001 method color name get
set =
4003 (name
, `color get
, 1, Action
(
4005 let invalid = (nan
, nan
, nan
) in
4008 try color_of_string s
4010 state.text <- Printf.sprintf
"bad color `%s': %s"
4011 s (Printexc.to_string exn
);
4017 let te = name ^
": ", "", None
, textentry, ondone, true in
4018 state.text <- color_to_string (get
());
4019 state.mode
<- Textentry
(te, leave m_prev_mode
);
4023 method string name get
set =
4025 (name
, `
string get
, 1, Action
(
4027 let ondone s = set s in
4028 let te = name ^
": ", "", None
, textentry, ondone, true in
4029 state.mode
<- Textentry
(te, leave m_prev_mode
);
4033 method colorspace name get
set =
4035 (name
, `
string get
, 1, Action
(
4038 let vals = [| "rgb"; "bgr"; "gray" |] in
4040 inherit lvsourcebase
4043 m_active
<- int_of_colorspace conf.colorspace
;
4046 method getitemcount
= Array.length
vals
4047 method getitem
n = (vals.(n), 0)
4048 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4049 ignore
(uioh
, first, pan
, qsearch);
4050 if not cancel
then set active;
4052 method hasaction
_ = true
4056 let modehash = findkeyhash conf "info" in
4057 coe (new listview ~
source ~trusted
:true ~
modehash)
4060 method caption
s offset
=
4061 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4063 method caption2
s f offset
=
4064 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4066 method getitemcount
= Array.length m_a
4069 let tostr = function
4070 | `
int f -> string_of_int
(f ())
4071 | `intws
f -> string_with_suffix_of_int (f ())
4073 | `color
f -> color_to_string (f ())
4074 | `
bool (btos, f) -> btos (f ())
4077 let name, t
, offset
, _ = m_a
.(n) in
4078 ((let s = tostr t
in
4079 if String.length
s > 0
4080 then Printf.sprintf
"%s\t%s" name s
4084 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4088 m_qsearch
<- qsearch;
4090 match m_a
.(active) with
4091 | _, _, _, Action
f -> f uioh
4103 method hasaction
n =
4105 | _, _, _, Action
_ -> true
4109 let rec fillsrc prevmode prevuioh
=
4110 let sep () = src#caption
"" 0 in
4111 let colorp name get
set =
4113 (fun () -> color_to_string (get
()))
4116 let c = color_of_string v in
4119 state.text <- Printf.sprintf
"bad color `%s': %s"
4120 v (Printexc.to_string exn
);
4123 let oldmode = state.mode
in
4124 let birdseye = isbirdseye state.mode
in
4126 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4128 src#
bool "presentation mode"
4129 (fun () -> conf.presentation)
4131 conf.presentation <- v;
4132 state.anchor <- getanchor ();
4135 src#
bool "ignore case in searches"
4136 (fun () -> conf.icase
)
4137 (fun v -> conf.icase
<- v);
4140 (fun () -> conf.preload)
4141 (fun v -> conf.preload <- v);
4143 src#
bool "highlight links"
4144 (fun () -> conf.hlinks
)
4145 (fun v -> conf.hlinks
<- v);
4147 src#
bool "under info"
4148 (fun () -> conf.underinfo
)
4149 (fun v -> conf.underinfo
<- v);
4151 src#
bool "persistent bookmarks"
4152 (fun () -> conf.savebmarks
)
4153 (fun v -> conf.savebmarks
<- v);
4155 src#
bool "proportional display"
4156 (fun () -> conf.proportional
)
4157 (fun v -> reqlayout conf.angle
v);
4159 src#
bool "trim margins"
4160 (fun () -> conf.trimmargins
)
4161 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4163 src#
bool "persistent location"
4164 (fun () -> conf.jumpback
)
4165 (fun v -> conf.jumpback
<- v);
4168 src#
int "inter-page space"
4169 (fun () -> conf.interpagespace)
4171 conf.interpagespace <- n;
4172 docolumns conf.columns
;
4174 match state.layout with
4179 state.maxy <- calcheight ();
4180 let y = getpagey pageno in
4185 (fun () -> conf.pagebias
)
4186 (fun v -> conf.pagebias
<- v);
4188 src#
int "scroll step"
4189 (fun () -> conf.scrollstep
)
4190 (fun n -> conf.scrollstep
<- n);
4192 src#
int "horizontal scroll step"
4193 (fun () -> conf.hscrollstep
)
4194 (fun v -> conf.hscrollstep
<- v);
4196 src#
int "auto scroll step"
4198 match state.autoscroll
with
4200 | _ -> conf.autoscrollstep
)
4202 if state.autoscroll
<> None
4203 then state.autoscroll
<- Some
n;
4204 conf.autoscrollstep
<- n);
4207 (fun () -> truncate
(conf.zoom *. 100.))
4208 (fun v -> setzoom ((float v) /. 100.));
4211 (fun () -> conf.angle
)
4212 (fun v -> reqlayout v conf.proportional
);
4214 src#
int "scroll bar width"
4215 (fun () -> state.scrollw
)
4219 reshape conf.winw
conf.winh
;
4222 src#
int "scroll handle height"
4223 (fun () -> conf.scrollh
)
4224 (fun v -> conf.scrollh
<- v;);
4226 src#
int "thumbnail width"
4227 (fun () -> conf.thumbw
)
4229 conf.thumbw
<- min
4096 v;
4232 leavebirdseye beye
false;
4237 let mode = state.mode in
4238 src#
string "columns"
4240 match conf.columns
with
4242 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4243 | Csplit
(count
, _) -> "-" ^ string_of_int count
4246 let n, a, b = multicolumns_of_string v in
4247 setcolumns mode n a b);
4250 src#caption
"Presentation mode" 0;
4251 src#
bool "scrollbar visible"
4252 (fun () -> conf.scrollbarinpm
)
4254 if v != conf.scrollbarinpm
4256 conf.scrollbarinpm
<- v;
4257 if conf.presentation
4259 state.scrollw
<- if v then conf.scrollbw
else 0;
4260 reshape conf.winw
conf.winh
;
4266 src#caption
"Pixmap cache" 0;
4267 src#int_with_suffix
"size (advisory)"
4268 (fun () -> conf.memlimit
)
4269 (fun v -> conf.memlimit
<- v);
4272 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4273 (string_with_suffix_of_int state.memused
)
4274 (Hashtbl.length
state.tilemap
)) 1;
4277 src#caption
"Layout" 0;
4278 src#caption2
"Dimension"
4280 Printf.sprintf
"%dx%d (virtual %dx%d)"
4286 src#caption2
"Position" (fun () ->
4287 Printf.sprintf
"%dx%d" state.x state.y
4290 src#caption2
"Visible" (fun () -> describe_location ()) 1
4294 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4295 "Save these parameters as global defaults at exit"
4296 (fun () -> conf.bedefault
)
4297 (fun v -> conf.bedefault
<- v)
4301 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4302 src#
bool ~offset
:0 ~
btos "Extended parameters"
4303 (fun () -> !showextended)
4304 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4308 (fun () -> conf.checkers
)
4309 (fun v -> conf.checkers
<- v; setcheckers v);
4310 src#
bool "update cursor"
4311 (fun () -> conf.updatecurs
)
4312 (fun v -> conf.updatecurs
<- v);
4314 (fun () -> conf.verbose
)
4315 (fun v -> conf.verbose
<- v);
4316 src#
bool "invert colors"
4317 (fun () -> conf.invert
)
4318 (fun v -> conf.invert
<- v);
4320 (fun () -> conf.maxhfit
)
4321 (fun v -> conf.maxhfit
<- v);
4322 src#
bool "redirect stderr"
4323 (fun () -> conf.redirectstderr)
4324 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4325 src#
string "uri launcher"
4326 (fun () -> conf.urilauncher
)
4327 (fun v -> conf.urilauncher
<- v);
4328 src#
string "path launcher"
4329 (fun () -> conf.pathlauncher
)
4330 (fun v -> conf.pathlauncher
<- v);
4331 src#
string "tile size"
4332 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4335 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4336 conf.tilew
<- max
64 w;
4337 conf.tileh
<- max
64 h;
4340 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4341 v (Printexc.to_string exn
));
4342 src#
int "texture count"
4343 (fun () -> conf.texcount
)
4346 then conf.texcount
<- v
4347 else showtext '
!'
" Failed to set texture count please retry later"
4349 src#
int "slice height"
4350 (fun () -> conf.sliceheight
)
4352 conf.sliceheight
<- v;
4353 wcmd "sliceh %d" conf.sliceheight
;
4355 src#
int "anti-aliasing level"
4356 (fun () -> conf.aalevel
)
4358 conf.aalevel
<- bound v 0 8;
4359 state.anchor <- getanchor ();
4360 opendoc state.path
state.password
;
4362 src#
int "ui font size"
4363 (fun () -> fstate.fontsize
)
4364 (fun v -> setfontsize (bound v 5 100));
4365 src#
int "hint font size"
4366 (fun () -> conf.hfsize
)
4367 (fun v -> conf.hfsize
<- bound v 5 100);
4368 colorp "background color"
4369 (fun () -> conf.bgcolor
)
4370 (fun v -> conf.bgcolor
<- v);
4371 src#
bool "crop hack"
4372 (fun () -> conf.crophack
)
4373 (fun v -> conf.crophack
<- v);
4374 src#
string "trim fuzz"
4375 (fun () -> irect_to_string conf.trimfuzz
)
4378 conf.trimfuzz
<- irect_of_string v;
4380 then settrim true conf.trimfuzz
;
4382 state.text <- Printf.sprintf
"bad irect `%s': %s"
4383 v (Printexc.to_string exn
)
4385 src#
string "throttle"
4387 match conf.maxwait
with
4388 | None
-> "show place holder if page is not ready"
4391 then "wait for page to fully render"
4393 "wait " ^ string_of_float
time
4394 ^
" seconds before showing placeholder"
4398 let f = float_of_string
v in
4400 then conf.maxwait
<- None
4401 else conf.maxwait
<- Some
f
4403 state.text <- Printf.sprintf
"bad time `%s': %s"
4404 v (Printexc.to_string exn
)
4406 src#
string "ghyll scroll"
4408 match conf.ghyllscroll
with
4410 | Some nab
-> ghyllscroll_to_string nab
4415 if String.length
v = 0
4417 else Some
(ghyllscroll_of_string v)
4419 conf.ghyllscroll
<- gs
4421 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4422 v (Printexc.to_string exn
)
4424 src#
string "selection command"
4425 (fun () -> conf.selcmd
)
4426 (fun v -> conf.selcmd
<- v);
4427 src#colorspace
"color space"
4428 (fun () -> colorspace_to_string conf.colorspace
)
4430 conf.colorspace
<- colorspace_of_int v;
4437 src#caption
"Document" 0;
4438 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4439 src#caption2
"Pages"
4440 (fun () -> string_of_int
state.pagecount
) 1;
4441 src#caption2
"Dimensions"
4442 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4446 src#caption
"Trimmed margins" 0;
4447 src#caption2
"Dimensions"
4448 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4452 src#caption
"OpenGL" 0;
4453 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4454 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4455 src#reset prevmode prevuioh
;
4459 let prevmode = state.mode
4460 and prevuioh
= state.uioh in
4461 fillsrc prevmode prevuioh
;
4462 let source = (src :> lvsource
) in
4463 let modehash = findkeyhash conf "info" in
4464 state.uioh <- coe (object (self)
4465 inherit listview ~
source ~trusted
:true ~
modehash as super
4466 val mutable m_prevmemused
= 0
4467 method infochanged
= function
4469 if m_prevmemused
!= state.memused
4471 m_prevmemused
<- state.memused
;
4472 G.postRedisplay "memusedchanged";
4474 | Pdim
-> G.postRedisplay "pdimchanged"
4475 | Docinfo
-> fillsrc prevmode prevuioh
4477 method key key mask
=
4478 if not
(Wsi.withctrl mask
)
4481 | 0xff51 -> coe (self#updownlevel ~
-1)
4482 | 0xff53 -> coe (self#updownlevel
1)
4483 | _ -> super#
key key mask
4484 else super#
key key mask
4486 G.postRedisplay "info";
4492 inherit lvsourcebase
4493 method getitemcount
= Array.length
state.help
4495 let s, n, _ = state.help
.(n) in
4498 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4502 m_qsearch
<- qsearch;
4503 match state.help
.(active) with
4504 | _, _, Action
f -> Some
(f uioh)
4514 method hasaction
n =
4515 match state.help
.(n) with
4516 | _, _, Action
_ -> true
4523 let modehash = findkeyhash conf "help" in
4524 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4525 G.postRedisplay "help";
4530 let re = Str.regexp
"[\r\n]" in
4532 inherit lvsourcebase
4533 val mutable m_items
= [||]
4535 method getitemcount
= 1 + Array.length m_items
4540 else m_items
.(n-1), 0
4542 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4547 then Buffer.clear
state.errmsgs
;
4548 m_qsearch
<- qsearch;
4555 method hasaction
n =
4559 state.newerrmsgs
<- false;
4560 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4561 m_items
<- Array.of_list
l
4569 let source = (msgsource :> lvsource
) in
4570 let modehash = findkeyhash conf "listview" in
4571 state.uioh <- coe (object
4572 inherit listview ~
source ~trusted
:false ~
modehash as super
4575 then msgsource#reset
;
4578 G.postRedisplay "msgs";
4581 let quickbookmark ?title
() =
4582 match state.layout with
4588 let sec = Unix.gettimeofday
() in
4589 let tm = Unix.localtime
sec in
4590 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4594 (tm.Unix.tm_year
+ 1900)
4597 | Some
title -> title
4600 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4605 state.fullscreen
<- None
;
4609 let setautoscrollspeed step goingdown
=
4610 let incr = max
1 ((abs step
) / 2) in
4611 let incr = if goingdown
then incr else -incr in
4612 let astep = step
+ incr in
4613 state.autoscroll
<- Some
astep;
4616 let gotounder = function
4617 | Ulinkgoto
(pageno, top) ->
4621 gotopage1 pageno top;
4627 | Uremote
(filename
, pageno) ->
4629 if Sys.file_exists filename
4632 let dir = Filename.dirname
state.path in
4633 let path = Filename.concat
dir filename
in
4634 if Sys.file_exists
path
4638 if String.length
path > 0
4640 let anchor = getanchor () in
4641 let ranchor = state.path, state.password
, anchor in
4642 state.anchor <- (pageno, 0.0);
4643 state.ranchors
<- ranchor :: state.ranchors
;
4646 else showtext '
!'
("Could not find " ^ filename
)
4648 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4652 match conf.columns
with
4654 | _ -> conf.zoom > 1.0
4657 let viewkeyboard key mask
=
4659 let mode = state.mode in
4660 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4663 G.postRedisplay "view:enttext"
4665 let ctrl = Wsi.withctrl mask
in
4670 | 0xff63 -> (* insert *)
4671 if conf.angle
mod 360 = 0
4673 state.mode <- LinkNav
(Ltgendir
0);
4676 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4678 | 0xff1b | 113 -> (* escape / q *)
4679 begin match state.mstate
with
4681 state.mstate
<- Mnone
;
4682 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4683 G.postRedisplay "kill zoom rect";
4685 match state.ranchors
with
4687 | (path, password
, anchor) :: rest
->
4688 state.ranchors
<- rest
;
4689 state.anchor <- anchor;
4690 opendoc path password
4693 | 0xff08 -> (* backspace *)
4694 let y = getnav ~
-1 in
4695 gotoy_and_clear_text y
4703 G.postRedisplay "dehighlight";
4705 | 47 | 63 -> (* / ? *)
4706 let ondone isforw
s =
4707 cbput state.hists
.pat
s;
4708 state.searchpattern
<- s;
4711 let s = String.create
1 in
4712 s.[0] <- Char.chr
key;
4713 enttext (s, "", Some
(onhist state.hists
.pat
),
4714 textentry, ondone (key = 47), true)
4716 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4717 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4718 setzoom (conf.zoom +. incr)
4720 | 43 | 0xffab -> (* + *)
4723 try int_of_string
s with exc
->
4724 state.text <- Printf.sprintf
"bad integer `%s': %s"
4725 s (Printexc.to_string exc
);
4731 state.text <- "page bias is now " ^ string_of_int
n;
4734 enttext ("page bias: ", "", None
, intentry, ondone, true)
4736 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4737 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4738 setzoom (max
0.01 (conf.zoom -. decr))
4740 | 45 | 0xffad -> (* - *)
4741 let ondone msg
= state.text <- msg
in
4743 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4744 optentry state.mode, ondone, true
4747 | 48 when ctrl -> (* ctrl-0 *)
4750 | 49 when ctrl -> (* ctrl-1 *)
4752 match conf.columns
with
4753 | Csingle
| Cmulti
_ -> 1
4754 | Csplit
(n, _) -> n
4756 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4760 | 0xffc6 -> (* f9 *)
4763 | 57 when ctrl -> (* ctrl-9 *)
4766 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4767 when not
ctrl -> (* 0..9 *)
4770 try int_of_string
s with exc
->
4771 state.text <- Printf.sprintf
"bad integer `%s': %s"
4772 s (Printexc.to_string exc
);
4778 cbput state.hists
.pag
(string_of_int
n);
4779 gotopage1 (n + conf.pagebias
- 1) 0;
4782 let pageentry text key =
4783 match Char.unsafe_chr
key with
4784 | 'g'
-> TEdone
text
4785 | _ -> intentry text key
4787 let text = "x" in text.[0] <- Char.chr
key;
4788 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4791 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4792 reshape conf.winw
conf.winh
;
4795 conf.hlinks
<- not
conf.hlinks
;
4796 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4797 G.postRedisplay "toggle highlightlinks";
4800 state.glinks
<- true;
4801 let mode = state.mode in
4802 state.mode <- Textentry
(
4803 (":", "", None
, linknentry, linkndone (fun under ->
4808 state.glinks
<- false;
4812 G.postRedisplay "view:linkent(F)"
4815 state.glinks
<- true;
4816 let mode = state.mode in
4817 state.mode <- Textentry
(
4818 (":", "", None
, linknentry, linkndone (fun under ->
4819 match Ne.pipe () with
4821 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4822 (Printexc.to_string exn
));
4825 try popen conf.selcmd
[r, 0; w, -1]; true
4828 (Printf.sprintf
"failed to execute %s: %s"
4829 conf.selcmd
(Printexc.to_string exn
));
4833 Ne.clo fd
(fun msg
->
4834 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4837 let s = undertext under in
4841 let l = String.length
s in
4842 let n = Unix.write
w s 0 l in
4847 "failed to write %d characters to sel pipe, wrote %d"
4852 (Printf.sprintf
"failed to write to sel pipe: %s"
4853 (Printexc.to_string exn
)
4862 state.glinks
<- false;
4866 G.postRedisplay "view:linkent"
4869 begin match state.autoscroll
with
4871 conf.autoscrollstep
<- step
;
4872 state.autoscroll
<- None
4874 if conf.autoscrollstep
= 0
4875 then state.autoscroll
<- Some
1
4876 else state.autoscroll
<- Some
conf.autoscrollstep
4879 | 112 when ctrl -> (* ctrl-p *)
4883 conf.presentation <- not
conf.presentation;
4884 if conf.presentation
4886 if not
conf.scrollbarinpm
4887 then state.scrollw
<- 0;
4890 state.scrollw
<- conf.scrollbw
;
4892 showtext ' '
("presentation mode " ^
4893 if conf.presentation then "on" else "off");
4894 state.anchor <- getanchor ();
4898 begin match state.fullscreen
with
4900 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4903 state.fullscreen
<- None
;
4908 gotoy_and_clear_text 0
4911 gotopage1 (state.pagecount
- 1) 0
4913 | 112 | 78 -> (* p|N *)
4914 search state.searchpattern
false
4916 | 110 | 0xffc0 -> (* n|F3 *)
4917 search state.searchpattern
true
4920 begin match state.layout with
4923 gotoy_and_clear_text (getpagey l.pageno)
4927 begin match state.layout with
4930 match conf.columns
with
4931 | Csingle
| Cmulti
_ ->
4932 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4933 gotoy_and_clear_text (getpagey pageno)
4935 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4937 let pagey, pageh
= getpageyh l.pageno in
4938 let pagey = pagey + pageh
* l.pagecol
in
4939 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace in
4940 gotoy_and_clear_text (pagey + pageh
+ ips)
4943 | 0xff9f | 0xffff -> (* delete *)
4944 begin match state.layout with
4947 match conf.columns
with
4948 | Csingle
| Cmulti
_ ->
4949 let pageno = max
0 (l.pageno-1) in
4950 gotoy_and_clear_text (getpagey pageno)
4958 let pageno = max
0 (l.pageno-1) in
4959 let pagey, pageh
= getpageyh pageno in
4962 let pagey, pageh
= getpageyh l.pageno in
4963 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4965 gotoy_and_clear_text y
4969 showtext ' '
(describe_location ());
4972 begin match state.layout with
4975 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4980 enterbookmarkmode ()
4982 | 104 | 0xffbe -> (* h|F1 *)
4988 | 101 when conf.redirectstderr -> (* e *)
4993 match state.layout with
4996 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
5000 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5004 showtext ' '
"Quick bookmark added";
5007 begin match state.layout with
5009 let rect = getpdimrect
l.pagedimno
in
5013 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5014 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5016 (truncate
(rect.(1) -. rect.(0)),
5017 truncate
(rect.(3) -. rect.(0)))
5019 let w = truncate
((float w)*.conf.zoom)
5020 and h = truncate
((float h)*.conf.zoom) in
5023 state.anchor <- getanchor ();
5024 doreshape (w + state.scrollw
) (h + conf.interpagespace)
5026 G.postRedisplay "z";
5031 | 50 when ctrl -> (* ctrl-2 *)
5032 let maxw = getmaxw
() in
5034 then setzoom (maxw /. float conf.winw
)
5036 | 60 | 62 -> (* < > *)
5037 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5039 | 91 | 93 -> (* [ ] *)
5041 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5043 G.postRedisplay "brightness";
5045 | 99 when state.mode = View
-> (* c *)
5047 match state.prevcolumns
with
5048 | None
-> (1, 0, 0), 1.0
5049 | Some
(columns
, z
) ->
5052 | Csplit
(c, _) -> -c, 0, 0
5053 | Cmulti
((c, a, b), _) -> c, a, b
5054 | Csingle
-> 1, 0, 0
5058 setcolumns View
c a b;
5061 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5062 setzoom state.prevzoom
5064 | 107 | 0xff52 -> (* k up *)
5065 begin match state.autoscroll
with
5067 begin match state.mode with
5068 | Birdseye beye
-> upbirdseye 1 beye
5071 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5072 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5075 setautoscrollspeed n false
5078 | 106 | 0xff54 -> (* j down *)
5079 begin match state.autoscroll
with
5081 begin match state.mode with
5082 | Birdseye beye
-> downbirdseye 1 beye
5085 then gotoy_and_clear_text (clamp (conf.winh
/2))
5086 else gotoy_and_clear_text (clamp conf.scrollstep
)
5089 setautoscrollspeed n true
5092 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5100 let dx = if key = 0xff51 then dx else -dx in
5101 state.x <- state.x + dx;
5102 gotoy_and_clear_text state.y
5105 G.postRedisplay "lef/right"
5108 | 0xff55 -> (* prior *)
5112 match state.layout with
5114 | l :: _ -> state.y - l.pagey
5120 | 0xff56 -> (* next *)
5124 match List.rev
state.layout with
5126 | l :: _ -> getpagey l.pageno
5132 | 0xff50 -> gotoghyll 0
5133 | 0xff57 -> gotoghyll (clamp state.maxy)
5134 | 0xff53 when Wsi.withalt mask
->
5135 gotoghyll (getnav ~
-1)
5136 | 0xff51 when Wsi.withalt mask
->
5137 gotoghyll (getnav 1)
5140 state.anchor <- getanchor ();
5141 opendoc state.path state.password
5143 | 118 when conf.debug
-> (* v *)
5146 match getopaque l.pageno with
5149 let x0, y0, x1, y1 = pagebbox opaque
in
5150 let a,b = float x0, float y0 in
5151 let c,d = float x1, float y0 in
5152 let e,f = float x1, float y1 in
5153 let h,j
= float x0, float y1 in
5154 let rect = (a,b,c,d,e,f,h,j
) in
5156 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5158 G.postRedisplay "v";
5161 vlog "huh? %s" (Wsi.keyname
key)
5164 let linknavkeyboard key mask
linknav =
5165 let getpage pageno =
5166 let rec loop = function
5168 | l :: _ when l.pageno = pageno -> Some
l
5169 | _ :: rest
-> loop rest
5170 in loop state.layout
5172 let doexact (pageno, n) =
5173 match getopaque pageno, getpage pageno with
5174 | Some opaque
, Some
l ->
5177 let under = getlink opaque
n in
5178 G.postRedisplay "link gotounder";
5184 | 0xff50 -> (* home *)
5185 Some
(findlink opaque LDfirst
), -1
5187 | 0xff57 -> (* end *)
5188 Some
(findlink opaque LDlast
), 1
5190 | 0xff51 -> (* left *)
5191 Some
(findlink opaque
(LDleft
n)), -1
5193 | 0xff53 -> (* right *)
5194 Some
(findlink opaque
(LDright
n)), 1
5196 | 0xff52 -> (* up *)
5197 Some
(findlink opaque
(LDup
n)), -1
5199 | 0xff54 -> (* down *)
5200 Some
(findlink opaque
(LDdown
n)), 1
5205 begin match findpwl
l.pageno dir with
5209 state.mode <- LinkNav
(Ltgendir
dir);
5210 let y, h = getpageyh pageno in
5213 then y + h - conf.winh
5218 begin match getopaque pageno, getpage pageno with
5219 | Some opaque
, Some
_ ->
5221 let ld = if dir > 0 then LDfirst
else LDlast
in
5224 begin match link with
5226 showlinktype (getlink opaque
m);
5227 state.mode <- LinkNav
(Ltexact
(pageno, m));
5228 G.postRedisplay "linknav jpage";
5235 begin match opt with
5236 | Some Lnotfound
-> pwl l dir;
5237 | Some
(Lfound
m) ->
5241 let _, y0, _, y1 = getlinkrect opaque
m in
5243 then gotopage1 l.pageno y0
5245 let d = fstate.fontsize
+ 1 in
5246 if y1 - l.pagey > l.pagevh - d
5247 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5248 else G.postRedisplay "linknav";
5250 showlinktype (getlink opaque
m);
5251 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5254 | None
-> viewkeyboard key mask
5256 | _ -> viewkeyboard key mask
5261 G.postRedisplay "leave linknav"
5265 | Ltgendir
_ -> viewkeyboard key mask
5266 | Ltexact exact
-> doexact exact
5269 let keyboard key mask
=
5270 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5271 then wcmd "interrupt"
5272 else state.uioh <- state.uioh#
key key mask
5275 let birdseyekeyboard key mask
5276 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5278 match conf.columns
with
5280 | Cmulti
((c, _, _), _) -> c
5281 | Csplit
_ -> failwith
"bird's eye split mode"
5284 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5285 let y, h = getpageyh pageno in
5286 let top = (conf.winh
- h) / 2 in
5287 gotoy (max
0 (y - top))
5288 | 0xff0d -> leavebirdseye beye
false
5289 | 0xff1b -> leavebirdseye beye
true (* escape *)
5290 | 0xff52 -> upbirdseye incr beye
(* prior *)
5291 | 0xff54 -> downbirdseye incr beye
(* next *)
5292 | 0xff51 -> upbirdseye 1 beye
(* up *)
5293 | 0xff53 -> downbirdseye 1 beye
(* down *)
5296 begin match state.layout with
5300 state.mode <- Birdseye
(
5301 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5303 gotopage1 l.pageno 0;
5306 let layout = layout (state.y-conf.winh
) conf.winh
in
5308 | [] -> gotoy (clamp (-conf.winh
))
5310 state.mode <- Birdseye
(
5311 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5313 gotopage1 l.pageno 0
5316 | [] -> gotoy (clamp (-conf.winh
))
5320 begin match List.rev
state.layout with
5322 let layout = layout (state.y + conf.winh
) conf.winh
in
5323 begin match layout with
5325 let incr = l.pageh
- l.pagevh in
5330 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5332 G.postRedisplay "birdseye pagedown";
5334 else gotoy (clamp (incr + conf.interpagespace*2));
5338 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5339 gotopage1 l.pageno 0;
5342 | [] -> gotoy (clamp conf.winh
)
5346 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5350 let pageno = state.pagecount
- 1 in
5351 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5352 if not
(pagevisible state.layout pageno)
5355 match List.rev
state.pdims
with
5357 | (_, _, h, _) :: _ -> h
5359 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5360 else G.postRedisplay "birdseye end";
5361 | _ -> viewkeyboard key mask
5364 let drawpage l linkindexbase
=
5366 match state.mode with
5367 | Textentry
_ -> scalecolor 0.4
5369 | View
-> scalecolor 1.0
5370 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5371 if l.pageno = hooverpageno
5374 if l.pageno = pageno
5380 begin match getopaque l.pageno with
5382 if tileready l l.pagex l.pagey
5384 let x = l.pagedispx - l.pagex
5385 and y = l.pagedispy - l.pagey in
5387 match conf.columns
with
5388 | Csingle
| Cmulti
_ ->
5389 (if conf.hlinks
then 1 else 0)
5391 && not
(isbirdseye state.mode) then 2 else 0)
5395 match state.mode with
5396 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5399 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5406 let scrollindicator () =
5407 let sbw, ph
, sh = state.uioh#
scrollph in
5408 let sbh, pw, sw = state.uioh#scrollpw
in
5410 GlDraw.color (0.64, 0.64, 0.64);
5412 (float (conf.winw
- sbw), 0.)
5413 (float conf.winw
, float conf.winh
)
5416 (0., float (conf.winh
- sbh))
5417 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5419 GlDraw.color (0.0, 0.0, 0.0);
5422 (float (conf.winw
- sbw), ph
)
5423 (float conf.winw
, ph
+. sh)
5426 (pw, float (conf.winh
- sbh))
5427 (pw +. sw, float conf.winh
)
5432 match state.mstate
with
5433 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5436 | Msel
((x0, y0), (x1, y1)) ->
5437 let rec loop = function
5439 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5440 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5441 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5442 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5444 match getopaque l.pageno with
5446 let x0, y0 = pagetranslatepoint l x0 y0 in
5447 let x1, y1 = pagetranslatepoint l x1 y1 in
5448 seltext opaque
(x0, y0, x1, y1);
5456 let showrects rects
=
5458 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5459 GlDraw.polygon_mode `both `fill
;
5460 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5462 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5464 if l.pageno = pageno
5466 let dx = float (l.pagedispx - l.pagex) in
5467 let dy = float (l.pagedispy - l.pagey) in
5468 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5469 GlDraw.begins `quads
;
5471 GlDraw.vertex2
(x0+.dx, y0+.dy);
5472 GlDraw.vertex2
(x1+.dx, y1+.dy);
5473 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5474 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5485 GlClear.color (scalecolor2 conf.bgcolor
);
5486 GlClear.clear
[`
color];
5487 let rec loop linkindexbase
= function
5489 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5490 loop linkindexbase rest
5493 loop 0 state.layout;
5495 match state.mode with
5496 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5497 begin match getopaque pageno with
5499 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5506 | None
-> state.rects
5513 begin match state.mstate
with
5514 | Mzoomrect
((x0, y0), (x1, y1)) ->
5516 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5517 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5518 GlDraw.rect (float x0, float y0)
5519 (float x1, float y1);
5528 let zoomrect x y x1 y1 =
5531 and y0 = min
y y1 in
5532 gotoy (state.y + y0);
5533 state.anchor <- getanchor ();
5534 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5536 if state.w < conf.winw
- state.scrollw
5537 then (conf.winw
- state.scrollw
- state.w) / 2
5540 state.x <- (state.x + margin) - x0;
5542 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5543 state.mstate
<- Mnone
;
5547 let winw = conf.winw - state.scrollw
- 1 in
5548 let s = float x /. float winw in
5549 let destx = truncate
(float (state.w + winw) *. s) in
5550 state.x <- winw - destx;
5551 gotoy_and_clear_text state.y;
5552 state.mstate
<- Mscrollx
;
5556 let s = float y /. float conf.winh
in
5557 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5558 gotoy_and_clear_text desty;
5559 state.mstate
<- Mscrolly
;
5562 let viewmouse button down
x y mask
=
5564 | n when (n == 4 || n == 5) && not down
->
5565 if Wsi.withctrl mask
5567 match state.mstate
with
5568 | Mzoom
(oldn
, i
) ->
5576 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5578 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5580 let zoom = conf.zoom -. incr in
5582 state.mstate
<- Mzoom
(n, 0);
5584 state.mstate
<- Mzoom
(n, i
+1);
5586 else state.mstate
<- Mzoom
(n, 0)
5588 | _ -> state.mstate
<- Mzoom
(n, 0)
5591 match state.autoscroll
with
5592 | Some step
-> setautoscrollspeed step
(n=4)
5596 then -conf.scrollstep
5597 else conf.scrollstep
5599 let incr = incr * 2 in
5600 let y = clamp incr in
5601 gotoy_and_clear_text y
5604 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5605 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5606 gotoy_and_clear_text state.y
5608 | 1 when Wsi.withctrl mask
->
5611 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5612 state.mstate
<- Mpan
(x, y)
5615 state.mstate
<- Mnone
5620 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5622 state.mstate
<- Mzoomrect
(p, p)
5625 match state.mstate
with
5626 | Mzoomrect
((x0, y0), _) ->
5627 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5628 then zoomrect x0 y0 x y
5630 state.mstate
<- Mnone
;
5631 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5632 G.postRedisplay "kill accidental zoom rect";
5635 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5636 state.mstate
<- Mnone
5639 | 1 when x > conf.winw - state.scrollw
->
5642 let _, position, sh = state.uioh#
scrollph in
5643 if y > truncate
position && y < truncate
(position +. sh)
5644 then state.mstate
<- Mscrolly
5647 state.mstate
<- Mnone
5649 | 1 when y > conf.winh
- state.hscrollh ->
5652 let _, position, sw = state.uioh#scrollpw
in
5653 if x > truncate
position && x < truncate
(position +. sw)
5654 then state.mstate
<- Mscrollx
5657 state.mstate
<- Mnone
5660 let dest = if down
then getunder x y else Unone
in
5661 begin match dest with
5665 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5668 | Unone
when down
->
5669 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5670 state.mstate
<- Mpan
(x, y);
5672 | Unone
| Utext
_ ->
5675 if conf.angle
mod 360 = 0
5677 state.mstate
<- Msel
((x, y), (x, y));
5678 G.postRedisplay "mouse select";
5682 match state.mstate
with
5685 | Mzoom
_ | Mscrollx
| Mscrolly
->
5686 state.mstate
<- Mnone
5688 | Mzoomrect
((x0, y0), _) ->
5692 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5693 state.mstate
<- Mnone
5695 | Msel
((_, y0), (_, y1)) ->
5696 let rec loop = function
5699 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5700 || ((y1 >= l.pagedispy
5701 && y1 <= (l.pagedispy + l.pagevh)))
5703 match getopaque l.pageno with
5706 match Ne.pipe () with
5710 "can not create sel pipe: %s"
5711 (Printexc.to_string exn
));
5713 let doclose what fd
=
5714 Ne.clo fd
(fun msg
->
5715 dolog "%s close failed: %s" what msg
)
5718 popen conf.selcmd
[r, 0; w, -1];
5721 G.postRedisplay "copysel";
5723 dolog "can not execute %S: %s"
5724 conf.selcmd
(Printexc.to_string exn
);
5732 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5733 state.mstate
<- Mnone
;
5740 let birdseyemouse button down
x y mask
5741 (conf, leftx
, _, hooverpageno
, anchor) =
5744 let rec loop = function
5747 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5748 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5750 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5756 | _ -> viewmouse button down
x y mask
5759 let mouse button down
x y mask
=
5760 state.uioh <- state.uioh#button button down
x y mask
;
5764 state.uioh <- state.uioh#
motion x y
5768 state.uioh <- state.uioh#
pmotion x y;
5774 method key key mask
=
5775 begin match state.mode with
5776 | Textentry
textentry -> textentrykeyboard key mask
textentry
5777 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5778 | View
-> viewkeyboard key mask
5779 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5783 method button button bstate
x y mask
=
5784 begin match state.mode with
5786 | View
-> viewmouse button bstate
x y mask
5787 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5793 begin match state.mode with
5795 | View
| Birdseye
_ | LinkNav
_ ->
5796 match state.mstate
with
5797 | Mzoom
_ | Mnone
-> ()
5802 state.mstate
<- Mpan
(x, y);
5804 then state.x <- state.x + dx;
5806 gotoy_and_clear_text y
5809 state.mstate
<- Msel
(a, (x, y));
5810 G.postRedisplay "motion select";
5813 let y = min
conf.winh
(max
0 y) in
5817 let x = min
conf.winw (max
0 x) in
5820 | Mzoomrect
(p0
, _) ->
5821 state.mstate
<- Mzoomrect
(p0
, (x, y));
5822 G.postRedisplay "motion zoomrect";
5826 method pmotion x y =
5827 begin match state.mode with
5828 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5829 let rec loop = function
5831 if hooverpageno
!= -1
5833 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5834 G.postRedisplay "pmotion birdseye no hoover";
5837 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5838 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5840 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5841 G.postRedisplay "pmotion birdseye hoover";
5851 match state.mstate
with
5852 | Mnone
-> updateunder x y
5853 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5858 method infochanged
_ = ()
5861 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5862 let p, h = scrollph state.y maxy in
5866 let winw = conf.winw - state.scrollw
- 1 in
5867 let fwinw = float winw in
5869 let sw = fwinw /. float state.w in
5870 let sw = fwinw *. sw in
5871 max
sw (float conf.scrollh
)
5874 let f = state.w+winw in
5875 let r = float (winw-state.x) /. float f in
5876 let p = fwinw *. r in
5880 if position +. sw > fwinw
5881 then fwinw -. position
5884 state.hscrollh, position, sw
5888 match state.mode with
5889 | LinkNav
_ -> "links"
5890 | Textentry
_ -> "textentry"
5891 | Birdseye
_ -> "birdseye"
5894 findkeyhash conf modename
5901 let fontpath = ref "";;
5904 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5907 let l = String.length
s in
5908 let b = Buffer.create
l in
5914 try Sys.getenv
"HOME"
5917 ("Can not determine home directory location: " ^
5918 Printexc.to_string exn
);
5922 let modifier_of_string = function
5923 | "alt" -> Wsi.altmask
5924 | "shift" -> Wsi.shiftmask
5925 | "ctrl" | "control" -> Wsi.ctrlmask
5926 | "meta" -> Wsi.metamask
5931 let r = Str.regexp
"-" in
5933 let elems = Str.full_split
r s in
5936 let m1 = modifier_of_string s in
5938 then (Wsi.namekey
s, m)
5941 | Str.Delim
s when n land 1 = 0 -> g s
5943 | Str.Delim
_ -> (k
, m)
5945 let rec loop n k
m = function
5948 let k, m = f n k m x in
5954 let keys_of_string =
5955 let r = Str.regexp
"[ \t]" in
5957 let elems = Str.split
r s in
5958 List.map
key_of_string elems
5961 let copykeyhashes c =
5962 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5965 let config_of c attrs
=
5969 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5970 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5971 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5972 | "preload" -> { c with preload = bool_of_string
v }
5973 | "page-bias" -> { c with pagebias
= int_of_string
v }
5974 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5975 | "horizontal-scroll-step" ->
5976 { c with hscrollstep
= max
(int_of_string
v) 1 }
5977 | "auto-scroll-step" ->
5978 { c with autoscrollstep
= max
0 (int_of_string
v) }
5979 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5980 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5983 match String.lowercase
v with
5984 | "true" -> Some infinity
5986 | f -> Some
(float_of_string
f)
5988 { c with maxwait
= mw}
5989 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5990 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5991 | "vertical-margin" ->
5992 { c with interpagespace = max
0 (int_of_string
v) }
5994 let zoom = float_of_string
v /. 100. in
5995 let zoom = max
zoom 0.0 in
5996 { c with zoom = zoom }
5997 | "presentation" -> { c with presentation = bool_of_string
v }
5998 | "rotation-angle" -> { c with angle
= int_of_string
v }
5999 | "width" -> { c with winw = max
20 (int_of_string
v) }
6000 | "height" -> { c with winh
= max
20 (int_of_string
v) }
6001 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6002 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6003 | "pixmap-cache-size" ->
6004 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6005 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6006 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6007 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6008 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6009 | "background-color" -> { c with bgcolor
= color_of_string v }
6010 | "scrollbar-in-presentation" ->
6011 { c with scrollbarinpm
= bool_of_string
v }
6012 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6013 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6014 | "mupdf-store-size" ->
6015 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6016 | "checkers" -> { c with checkers
= bool_of_string
v }
6017 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6018 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6019 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6020 | "uri-launcher" -> { c with urilauncher
= unent v }
6021 | "path-launcher" -> { c with pathlauncher
= unent v }
6022 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6023 | "invert-colors" -> { c with invert
= bool_of_string
v }
6024 | "brightness" -> { c with colorscale
= float_of_string
v }
6025 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6027 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6029 let (n, _, _) as nab
= multicolumns_of_string v in
6031 then { c with columns
= Csplit
(-n, [||]) }
6032 else { c with columns
= Cmulti
(nab
, [||]) }
6033 | "birds-eye-columns" ->
6034 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6035 | "selection-command" -> { c with selcmd
= unent v }
6036 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6037 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6040 prerr_endline
("Error processing attribute (`" ^
6041 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6044 let rec fold c = function
6047 let c = apply c k v in
6050 fold { c with keyhashes
= copykeyhashes c } attrs
;
6053 let fromstring f pos
n v d =
6056 dolog "Error processing attribute (%S=%S) at %d\n%s"
6057 n v pos
(Printexc.to_string exn
)
6062 let bookmark_of attrs
=
6063 let rec fold title page
rely = function
6064 | ("title", v) :: rest
-> fold v page
rely rest
6065 | ("page", v) :: rest
-> fold title v rely rest
6066 | ("rely", v) :: rest
-> fold title page
v rest
6067 | _ :: rest
-> fold title page
rely rest
6068 | [] -> title, page
, rely
6070 fold "invalid" "0" "0" attrs
6074 let rec fold path page
rely pan
= function
6075 | ("path", v) :: rest
-> fold v page
rely pan rest
6076 | ("page", v) :: rest
-> fold path v rely pan rest
6077 | ("rely", v) :: rest
-> fold path page
v pan rest
6078 | ("pan", v) :: rest
-> fold path page
rely v rest
6079 | _ :: rest
-> fold path page
rely pan rest
6080 | [] -> path, page
, rely, pan
6082 fold "" "0" "0" "0" attrs
6086 let rec fold rs ls
= function
6087 | ("out", v) :: rest
-> fold v ls rest
6088 | ("in", v) :: rest
-> fold rs
v rest
6089 | _ :: rest
-> fold ls rs rest
6095 let setconf dst
src =
6096 dst
.scrollbw
<- src.scrollbw
;
6097 dst
.scrollh
<- src.scrollh
;
6098 dst
.icase
<- src.icase
;
6099 dst
.preload <- src.preload;
6100 dst
.pagebias
<- src.pagebias
;
6101 dst
.verbose
<- src.verbose
;
6102 dst
.scrollstep
<- src.scrollstep
;
6103 dst
.maxhfit
<- src.maxhfit
;
6104 dst
.crophack
<- src.crophack
;
6105 dst
.autoscrollstep
<- src.autoscrollstep
;
6106 dst
.maxwait
<- src.maxwait
;
6107 dst
.hlinks
<- src.hlinks
;
6108 dst
.underinfo
<- src.underinfo
;
6109 dst
.interpagespace <- src.interpagespace;
6110 dst
.zoom <- src.zoom;
6111 dst
.presentation <- src.presentation;
6112 dst
.angle
<- src.angle
;
6113 dst
.winw <- src.winw;
6114 dst
.winh
<- src.winh
;
6115 dst
.savebmarks
<- src.savebmarks
;
6116 dst
.memlimit
<- src.memlimit
;
6117 dst
.proportional
<- src.proportional
;
6118 dst
.texcount
<- src.texcount
;
6119 dst
.sliceheight
<- src.sliceheight
;
6120 dst
.thumbw
<- src.thumbw
;
6121 dst
.jumpback
<- src.jumpback
;
6122 dst
.bgcolor
<- src.bgcolor
;
6123 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6124 dst
.tilew
<- src.tilew
;
6125 dst
.tileh
<- src.tileh
;
6126 dst
.mustoresize
<- src.mustoresize
;
6127 dst
.checkers
<- src.checkers
;
6128 dst
.aalevel
<- src.aalevel
;
6129 dst
.trimmargins
<- src.trimmargins
;
6130 dst
.trimfuzz
<- src.trimfuzz
;
6131 dst
.urilauncher
<- src.urilauncher
;
6132 dst
.colorspace
<- src.colorspace
;
6133 dst
.invert
<- src.invert
;
6134 dst
.colorscale
<- src.colorscale
;
6135 dst
.redirectstderr <- src.redirectstderr;
6136 dst
.ghyllscroll
<- src.ghyllscroll
;
6137 dst
.columns
<- src.columns
;
6138 dst
.beyecolumns
<- src.beyecolumns
;
6139 dst
.selcmd
<- src.selcmd
;
6140 dst
.updatecurs
<- src.updatecurs
;
6141 dst
.pathlauncher
<- src.pathlauncher
;
6142 dst
.keyhashes
<- copykeyhashes src;
6143 dst
.hfsize
<- src.hfsize
;
6144 dst
.hscrollstep
<- src.hscrollstep
;
6148 let h = Hashtbl.create
10 in
6149 let dc = { defconf with angle
= defconf.angle
} in
6150 let rec toplevel v t spos
_ =
6152 | Vdata
| Vcdata
| Vend
-> v
6153 | Vopen
("llppconfig", _, closed
) ->
6156 else { v with f = llppconfig
}
6158 error
"unexpected subelement at top level" s spos
6159 | Vclose
_ -> error
"unexpected close at top level" s spos
6161 and llppconfig
v t spos
_ =
6163 | Vdata
| Vcdata
-> v
6164 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6165 | Vopen
("defaults", attrs
, closed
) ->
6166 let c = config_of dc attrs
in
6170 else { v with f = defaults
}
6172 | Vopen
("ui-font", attrs
, closed
) ->
6173 let rec getsize size
= function
6175 | ("size", v) :: rest
->
6177 fromstring int_of_string spos
"size" v fstate.fontsize
in
6179 | l -> getsize size l
6181 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6184 else { v with f = uifont
(Buffer.create
10) }
6186 | Vopen
("doc", attrs
, closed
) ->
6187 let pathent, spage
, srely
, span
= doc_of attrs
in
6188 let path = unent pathent
6189 and pageno = fromstring int_of_string spos
"page" spage
0
6190 and rely = fromstring float_of_string spos
"rely" srely
0.0
6191 and pan
= fromstring int_of_string spos
"pan" span
0 in
6192 let c = config_of dc attrs
in
6193 let anchor = (pageno, rely) in
6195 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6196 else { v with f = doc
path pan
anchor c [] }
6199 error
"unexpected subelement in llppconfig" s spos
6201 | Vclose
"llppconfig" -> { v with f = toplevel }
6202 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6204 and defaults
v t spos
_ =
6206 | Vdata
| Vcdata
-> v
6207 | Vend
-> error
"unexpected end of input in defaults" s spos
6208 | Vopen
("keymap", attrs
, closed
) ->
6210 try List.assoc
"mode" attrs
6211 with Not_found
-> "global" in
6216 let h = findkeyhash dc modename in
6217 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6220 { v with f = pkeymap
ret KeyMap.empty }
6222 | Vopen
(_, _, _) ->
6223 error
"unexpected subelement in defaults" s spos
6225 | Vclose
"defaults" ->
6226 { v with f = llppconfig
}
6228 | Vclose
_ -> error
"unexpected close in defaults" s spos
6230 and uifont
b v t spos
epos =
6233 Buffer.add_substring
b s spos
(epos - spos
);
6235 | Vopen
(_, _, _) ->
6236 error
"unexpected subelement in ui-font" s spos
6237 | Vclose
"ui-font" ->
6238 if String.length
!fontpath = 0
6239 then fontpath := Buffer.contents
b;
6240 { v with f = llppconfig
}
6241 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6242 | Vend
-> error
"unexpected end of input in ui-font" s spos
6244 and doc
path pan
anchor c bookmarks
v t spos
_ =
6246 | Vdata
| Vcdata
-> v
6247 | Vend
-> error
"unexpected end of input in doc" s spos
6248 | Vopen
("bookmarks", _, closed
) ->
6251 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6253 | Vopen
("keymap", attrs
, closed
) ->
6255 try List.assoc
"mode" attrs
6256 with Not_found
-> "global"
6262 let h = findkeyhash c modename in
6263 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6264 doc
path pan
anchor c bookmarks
6266 { v with f = pkeymap
ret KeyMap.empty }
6268 | Vopen
(_, _, _) ->
6269 error
"unexpected subelement in doc" s spos
6272 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6273 { v with f = llppconfig
}
6275 | Vclose
_ -> error
"unexpected close in doc" s spos
6277 and pkeymap
ret keymap
v t spos
_ =
6279 | Vdata
| Vcdata
-> v
6280 | Vend
-> error
"unexpected end of input in keymap" s spos
6281 | Vopen
("map", attrs
, closed
) ->
6282 let r, l = map_of attrs
in
6283 let kss = fromstring keys_of_string spos
"in" r [] in
6284 let lss = fromstring keys_of_string spos
"out" l [] in
6288 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6289 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6292 then { v with f = pkeymap
ret keymap }
6295 { v with f = skip
"map" f }
6298 error
"unexpected subelement in keymap" s spos
6300 | Vclose
"keymap" ->
6301 { v with f = ret keymap }
6303 | Vclose
_ -> error
"unexpected close in keymap" s spos
6305 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6307 | Vdata
| Vcdata
-> v
6308 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6309 | Vopen
("item", attrs
, closed
) ->
6310 let titleent, spage
, srely
= bookmark_of attrs
in
6311 let page = fromstring int_of_string spos
"page" spage
0
6312 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6313 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6315 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6318 { v with f = skip
"item" f }
6321 error
"unexpected subelement in bookmarks" s spos
6323 | Vclose
"bookmarks" ->
6324 { v with f = doc
path pan
anchor c bookmarks }
6326 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6328 and skip tag
f v t spos
_ =
6330 | Vdata
| Vcdata
-> v
6332 error
("unexpected end of input in skipped " ^ tag
) s spos
6333 | Vopen
(tag'
, _, closed
) ->
6337 let f'
() = { v with f = skip tag
f } in
6338 { v with f = skip tag'
f'
}
6342 else error
("unexpected close in skipped " ^ tag
) s spos
6345 parse
{ f = toplevel; accu = () } s;
6351 let len = in_channel_length ic
in
6352 let s = String.create
len in
6353 really_input ic
s 0 len;
6356 | Parse_error
(msg
, s, pos
) ->
6357 let subs = subs s pos
in
6358 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6359 failwith
("parse error: " ^
s)
6362 failwith
("config load error: " ^
Printexc.to_string exn
)
6368 let dir = Filename.concat
home ".config" in
6369 if Sys.is_directory
dir then dir else home
6372 Filename.concat
dir "llpp.conf"
6375 let confpath = ref defconfpath;;
6378 if Sys.file_exists
!confpath
6381 (try Some
(open_in_bin
!confpath)
6384 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6385 Printexc.to_string exn
);
6394 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6395 Printexc.to_string exn
);
6401 f (Hashtbl.create
0, defconf)
6406 let pc, pb
, px, pa
=
6408 Hashtbl.find h (Filename.basename
state.path)
6409 with Not_found
-> dc, [], 0, (0, 0.0)
6413 state.bookmarks <- pb
;
6415 state.scrollw
<- conf.scrollbw
;
6417 then state.anchor <- pa
;
6418 cbput state.hists
.nav pa
;
6423 let add_attrs bb always
dc c =
6426 then Printf.bprintf bb
"\n %s='%b'" s a
6429 then Printf.bprintf bb
"\n %s='%d'" s a
6432 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6435 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6438 then Printf.bprintf bb
"\n %s='%f'" s a
6442 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6446 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6450 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6454 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6460 | Some
(_N
, _A
, _B
) ->
6461 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6471 else string_of_float
f
6473 Printf.bprintf bb
"\n %s='%s'" s v
6478 | Cmulti
((n, a, b), _) when n > 1 ->
6479 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6480 | Csplit
(n, _) when n > 1 ->
6481 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6487 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6492 then dc.winw, dc.winh
6494 match state.fullscreen
with
6496 | None
-> c.winw, c.winh
6498 let zoom, presentation, interpagespace, maxwait
=
6500 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6502 match state.mode with
6503 | Birdseye
(bc
, _, _, _, _) ->
6504 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6505 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6507 oi
"width" w dc.winw;
6508 oi
"height" h dc.winh
;
6509 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6510 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6511 ob "case-insensitive-search" c.icase
dc.icase
;
6512 ob "preload" c.preload dc.preload;
6513 oi
"page-bias" c.pagebias
dc.pagebias
;
6514 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6515 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6516 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6517 ob "crop-hack" c.crophack
dc.crophack
;
6518 oW
"throttle" maxwait
dc.maxwait
;
6519 ob "highlight-links" c.hlinks
dc.hlinks
;
6520 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6521 oi
"vertical-margin" interpagespace dc.interpagespace;
6522 oz
"zoom" zoom dc.zoom;
6523 ob "presentation" presentation dc.presentation;
6524 oi
"rotation-angle" c.angle
dc.angle
;
6525 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6526 ob "proportional-display" c.proportional
dc.proportional
;
6527 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6528 oi
"tex-count" c.texcount
dc.texcount
;
6529 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6530 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6531 ob "persistent-location" c.jumpback
dc.jumpback
;
6532 oc
"background-color" c.bgcolor
dc.bgcolor
;
6533 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6534 oi
"tile-width" c.tilew
dc.tilew
;
6535 oi
"tile-height" c.tileh
dc.tileh
;
6536 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6537 ob "checkers" c.checkers
dc.checkers
;
6538 oi
"aalevel" c.aalevel
dc.aalevel
;
6539 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6540 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6541 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6542 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6543 oC
"color-space" c.colorspace
dc.colorspace
;
6544 ob "invert-colors" c.invert
dc.invert
;
6545 oF
"brightness" c.colorscale
dc.colorscale
;
6546 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6547 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6548 oco
"columns" c.columns
dc.columns
;
6549 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6550 os
"selection-command" c.selcmd
dc.selcmd
;
6551 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6552 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6553 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6556 let keymapsbuf always
dc c =
6557 let bb = Buffer.create
16 in
6558 let rec loop = function
6560 | (modename, h) :: rest
->
6561 let dh = findkeyhash dc modename in
6562 if always
|| h <> dh
6564 if Hashtbl.length
h > 0
6566 if Buffer.length
bb > 0
6567 then Buffer.add_char
bb '
\n'
;
6568 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6569 Hashtbl.iter
(fun i
o ->
6570 let isdifferent = always
||
6572 let dO = Hashtbl.find dh i
in
6574 with Not_found
-> true
6579 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6580 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6581 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6582 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6583 Buffer.add_string
bb (Wsi.keyname
k);
6586 let rec loop = function
6588 | km
:: [] -> addkm km
6589 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6593 Buffer.add_string
bb "<map in='";
6597 Buffer.add_string
bb "' out='";
6599 Buffer.add_string
bb "'/>\n"
6602 Buffer.add_string
bb "' out='";
6604 Buffer.add_string
bb "'/>\n"
6606 | KMmulti
(ins, kms
) ->
6607 Buffer.add_char
bb ' '
;
6609 Buffer.add_string
bb "' out='";
6611 Buffer.add_string
bb "'/>\n"
6613 Buffer.add_string
bb "</keymap>";
6623 let uifontsize = fstate.fontsize
in
6624 let bb = Buffer.create
32768 in
6626 let dc = if conf.bedefault
then conf else dc in
6627 Buffer.add_string
bb "<llppconfig>\n";
6629 if String.length
!fontpath > 0
6631 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6637 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6640 Buffer.add_string
bb "<defaults ";
6641 add_attrs bb true dc dc;
6642 let kb = keymapsbuf true dc dc in
6643 if Buffer.length
kb > 0
6645 Buffer.add_string
bb ">\n";
6646 Buffer.add_buffer
bb kb;
6647 Buffer.add_string
bb "\n</defaults>\n";
6649 else Buffer.add_string
bb "/>\n";
6651 let adddoc path pan
anchor c bookmarks =
6652 if bookmarks == [] && c = dc && anchor = emptyanchor
6655 Printf.bprintf
bb "<doc path='%s'"
6656 (enent
path 0 (String.length
path));
6658 if anchor <> emptyanchor
6660 let n, y = anchor in
6661 Printf.bprintf
bb " page='%d'" n;
6664 Printf.bprintf
bb " rely='%f'" y
6669 then Printf.bprintf
bb " pan='%d'" pan
;
6671 add_attrs bb false dc c;
6672 let kb = keymapsbuf false dc c in
6674 begin match bookmarks with
6676 if Buffer.length
kb > 0
6678 Buffer.add_string
bb ">\n";
6679 Buffer.add_buffer
bb kb;
6680 Buffer.add_string
bb "\n</doc>\n";
6682 else Buffer.add_string
bb "/>\n"
6684 Buffer.add_string
bb ">\n<bookmarks>\n";
6685 List.iter
(fun (title, _level
, (page, rely)) ->
6687 "<item title='%s' page='%d'"
6688 (enent
title 0 (String.length
title))
6693 Printf.bprintf
bb " rely='%f'" rely
6695 Buffer.add_string
bb "/>\n";
6697 Buffer.add_string
bb "</bookmarks>";
6698 if Buffer.length
kb > 0
6700 Buffer.add_string
bb "\n";
6701 Buffer.add_buffer
bb kb;
6703 Buffer.add_string
bb "\n</doc>\n";
6709 match state.mode with
6710 | Birdseye
(c, pan, _, _, _) ->
6712 match conf.columns
with
6713 | Cmulti
((c, _, _), _) -> Some
c
6717 match c.columns
with
6718 | Cmulti
(c, _) -> Cmulti
(c, [||])
6719 | Csingle
-> Csingle
6720 | Csplit
_ -> failwith
"quit from bird's eye while split"
6722 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6723 | _ -> state.x, conf
6725 let basename = Filename.basename state.path in
6726 adddoc basename pan (getanchor ())
6729 match state.autoscroll
with
6731 | None
-> conf.autoscrollstep
}
6732 (if conf.savebmarks
then state.bookmarks else []);
6734 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6736 then adddoc path x y c bookmarks
6738 Buffer.add_string
bb "</llppconfig>";
6741 if Buffer.length
bb > 0
6744 let tmp = !confpath ^
".tmp" in
6745 let oc = open_out_bin
tmp in
6746 Buffer.output_buffer
oc bb;
6748 Unix.rename
tmp !confpath;
6751 ("error while saving configuration: " ^
Printexc.to_string exn
)
6758 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6759 "<password> Set password");
6761 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6762 "<path> Set path to the user interface font");
6764 ("-c", Arg.String
(fun s -> Config.confpath := s),
6765 "<path> Set path to the configuration file");
6767 ("-v", Arg.Unit
(fun () ->
6769 "%s\nconfiguration path: %s\n"
6773 exit
0), " Print version and exit");
6776 (fun s -> state.path <- s)
6777 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6779 if String.length
state.path = 0
6780 then (prerr_endline
"file name missing"; exit
1);
6784 let globalkeyhash = findkeyhash conf "global" in
6785 let wsfd, winw, winh
= Wsi.init
(object
6787 if nogeomcmds state.geomcmds
|| platform == Posx
6790 GlClear.color (scalecolor2 conf.bgcolor
);
6791 GlClear.clear
[`
color];
6793 method display = display ()
6794 method reshape w h = reshape w h
6795 method mouse b d x y m = mouse b d x y m
6796 method motion x y = state.mpos
<- (x, y); motion x y
6797 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6799 let mascm = m land (
6800 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6802 match state.keystate
with
6804 let km = k, mascm in
6807 let modehash = state.uioh#
modehash in
6808 try Hashtbl.find modehash km
6810 try Hashtbl.find globalkeyhash km
6811 with Not_found
-> KMinsrt
(k, m)
6813 | KMinsrt
(k, m) -> keyboard k m
6814 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6815 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6817 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6818 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6819 state.keystate
<- KSnone
6820 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6821 state.keystate
<- KSinto
(keys
, insrt
)
6823 state.keystate
<- KSnone
6825 method enter
x y = state.mpos
<- (x, y); pmotion x y
6826 method leave = state.mpos
<- (-1, -1)
6827 method quit
= raise Quit
6828 end) conf.winw conf.winh
(platform = Posx
) in
6833 List.exists
GlMisc.check_extension
6834 [ "GL_ARB_texture_rectangle"
6835 ; "GL_EXT_texture_recangle"
6836 ; "GL_NV_texture_rectangle" ]
6838 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6841 match Ne.pipe () with
6843 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6847 match Ne.pipe () with
6849 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6859 setcheckers conf.checkers
;
6863 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6864 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6869 state.text <- "Opening " ^
state.path;
6871 opendoc state.path state.password
;
6874 let rec loop deadline
=
6876 match state.errfd
with
6877 | None
-> [state.sr
; state.wsfd]
6878 | Some fd
-> [state.sr
; state.wsfd; fd
]
6882 state.redisplay
<- false;
6889 if deadline
= infinity
6891 else max
0.0 (deadline
-. now)
6896 try Unix.select
r [] [] timeout
6897 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6903 if state.ghyll
== noghyll
6905 match state.autoscroll
with
6906 | Some step
when step
!= 0 ->
6907 let y = state.y + step
in
6911 else if y >= state.maxy then 0 else y
6914 if state.mode = View
6915 then state.text <- "";
6918 else deadline
+. 0.01
6923 let rec checkfds = function
6925 | fd
:: rest
when fd
= state.sr
->
6926 let cmd = readcmd state.sr
in
6930 | fd
:: rest
when fd
= state.wsfd ->
6935 let s = String.create
80 in
6936 let n = Unix.read fd
s 0 80 in
6937 if conf.redirectstderr
6939 Buffer.add_substring
state.errmsgs
s 0 n;
6940 state.newerrmsgs
<- true;
6941 state.redisplay
<- true;
6944 prerr_string
(String.sub
s 0 n);
6952 if deadline
= infinity
6956 match state.autoscroll
with
6957 | Some step
when step
!= 0 -> deadline1
6958 | _ -> if state.ghyll
== noghyll then infinity
else deadline1