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 -> 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
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
163 | TEswitch
of textentry
174 let bound v minv maxv
=
175 max minv
(min maxv v
);
179 { store
= Array.create n v
186 let drawstring size x y s
=
188 Gl.enable `texture_2d
;
189 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
190 ignore
(drawstr size x y s
);
192 Gl.disable `texture_2d
;
195 let drawstring1 size x y s
=
199 let drawstring2 size x y fmt
=
200 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
203 let cbcap b
= Array.length b
.store
;;
208 b
.wc
<- (b
.wc
+ 1) mod cap;
210 b
.len
<- min
(b
.len
+ 1) cap;
213 let cbempty b
= b
.len
= 0;;
215 let cbgetg b circular dir
=
219 let rc = b
.rc + dir
in
231 else max
0 (min
rc (b
.len
-1))
237 let cbget b
= cbgetg b
false;;
238 let cbgetc b
= cbgetg b
true;;
256 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
257 dolog " WxH %dx%d" l
.pagew l
.pageh
;
258 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
259 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
260 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
261 dolog " column %d" l
.pagecol
;
265 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
267 dolog " x0,y0=(% f, % f)" x0 y0
;
268 dolog " x1,y1=(% f, % f)" x1 y1
;
269 dolog " x2,y2=(% f, % f)" x2 y2
;
270 dolog " x3,y3=(% f, % f)" x3 y3
;
274 type multicolumns
= multicol
* pagegeom
275 and splitcolumns
= columncount
* pagegeom
276 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
277 and multicol
= columncount
* covercount
* covercount
279 and columncount
= int
280 and covercount
= int;;
283 { mutable scrollbw
: int
284 ; mutable scrollh
: int
285 ; mutable icase
: bool
286 ; mutable preload
: bool
287 ; mutable pagebias
: int
288 ; mutable verbose
: bool
289 ; mutable debug
: bool
290 ; mutable scrollstep
: int
291 ; mutable maxhfit
: bool
292 ; mutable crophack
: bool
293 ; mutable autoscrollstep
: int
294 ; mutable maxwait
: float option
295 ; mutable hlinks
: bool
296 ; mutable underinfo
: bool
297 ; mutable interpagespace
: interpagespace
298 ; mutable zoom
: float
299 ; mutable presentation
: bool
300 ; mutable angle
: angle
303 ; mutable savebmarks
: bool
304 ; mutable proportional
: proportional
305 ; mutable trimmargins
: trimmargins
306 ; mutable trimfuzz
: irect
307 ; mutable memlimit
: memsize
308 ; mutable texcount
: texcount
309 ; mutable sliceheight
: sliceheight
310 ; mutable thumbw
: width
311 ; mutable jumpback
: bool
312 ; mutable bgcolor
: float * float * float
313 ; mutable bedefault
: bool
314 ; mutable scrollbarinpm
: bool
315 ; mutable tilew
: int
316 ; mutable tileh
: int
317 ; mutable mustoresize
: memsize
318 ; mutable checkers
: bool
319 ; mutable aalevel
: int
320 ; mutable urilauncher
: string
321 ; mutable pathlauncher
: string
322 ; mutable colorspace
: colorspace
323 ; mutable invert
: bool
324 ; mutable colorscale
: float
325 ; mutable redirectstderr
: bool
326 ; mutable ghyllscroll
: (int * int * int) option
327 ; mutable columns
: columns
328 ; mutable beyecolumns
: columncount
option
329 ; mutable selcmd
: string
330 ; mutable updatecurs
: bool
331 ; mutable keyhashes
: (string * keyhash
) list
332 ; mutable hfsize
: int
336 | Cmulti
of multicolumns
337 | Csplit
of splitcolumns
340 type anchor
= pageno
* top
;;
342 type outline
= string * int * anchor
;;
344 type rect
= float * float * float * float * float * float * float * float;;
346 type tile
= opaque
* pixmapsize
* elapsed
347 and elapsed
= float;;
348 type pagemapkey
= pageno
* gen
;;
349 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
353 let emptyanchor = (0, 0.0);;
355 type infochange
= | Memused
| Docinfo
| Pdim
;;
357 class type uioh
= object
358 method display
: unit
359 method key
: int -> int -> uioh
360 method button
: int -> bool -> int -> int -> int -> uioh
361 method motion
: int -> int -> uioh
362 method pmotion
: int -> int -> uioh
363 method infochanged
: infochange
-> unit
364 method scrollpw
: (int * float * float)
365 method scrollph
: (int * float * float)
366 method modehash
: keyhash
370 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
371 | Textentry
of (textentry
* onleave
)
373 | LinkNav
of linktarget
374 and onleave
= leavetextentrystatus
-> unit
375 and leavetextentrystatus
= | Cancel
| Confirm
376 and helpitem
= string * int * action
379 | Action
of (uioh
-> uioh
)
381 | Ltexact
of (pageno
* int)
385 let isbirdseye = function Birdseye _
-> true | _
-> false;;
386 let istextentry = function Textentry _
-> true | _
-> false;;
390 | Loading
of (page
* gen
)
392 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
394 | Outlining
of outline list
397 let emptykeyhash = Hashtbl.create
0;;
398 let nouioh : uioh
= object (self
)
400 method key _ _
= self
401 method button _ _ _ _ _
= self
402 method motion _ _
= self
403 method pmotion _ _
= self
404 method infochanged _
= ()
405 method scrollpw
= (0, nan
, nan
)
406 method scrollph
= (0, nan
, nan
)
407 method modehash
= emptykeyhash
411 { mutable sr
: Unix.file_descr
412 ; mutable sw
: Unix.file_descr
413 ; mutable wsfd
: Unix.file_descr
414 ; mutable errfd
: Unix.file_descr
option
415 ; mutable stderr
: Unix.file_descr
416 ; mutable errmsgs
: Buffer.t
417 ; mutable newerrmsgs
: bool
421 ; mutable scrollw
: int
422 ; mutable hscrollh
: int
423 ; mutable anchor
: anchor
424 ; mutable ranchors
: (string * string * anchor
) list
426 ; mutable layout
: page list
427 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
428 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
429 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
430 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
431 ; mutable pagecount
: int
432 ; mutable currently
: currently
433 ; mutable mstate
: mstate
434 ; mutable searchpattern
: string
435 ; mutable rects
: (pageno
* recttype
* rect
) list
436 ; mutable rects1
: (pageno
* recttype
* rect
) list
437 ; mutable text
: string
438 ; mutable fullscreen
: (width
* height
) option
439 ; mutable mode
: mode
440 ; mutable uioh
: uioh
441 ; mutable outlines
: outline array
442 ; mutable bookmarks
: outline list
443 ; mutable path
: string
444 ; mutable password
: string
445 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
446 ; mutable memused
: memsize
448 ; mutable throttle
: (page list
* int * float) option
449 ; mutable autoscroll
: int option
450 ; mutable ghyll
: (int option -> unit)
451 ; mutable help
: helpitem array
452 ; mutable docinfo
: (int * string) list
453 ; mutable texid
: GlTex.texture_id
option
455 ; mutable prevzoom
: float
456 ; mutable progress
: float
457 ; mutable redisplay
: bool
458 ; mutable mpos
: mpos
459 ; mutable keystate
: keystate
460 ; mutable glinks
: bool
463 { pat
: string circbuf
464 ; pag
: string circbuf
465 ; nav
: anchor circbuf
466 ; sel
: string circbuf
487 ; presentation
= false
492 ; proportional
= true
493 ; trimmargins
= false
494 ; trimfuzz
= (0,0,0,0)
495 ; memlimit
= 32 lsl 20
500 ; bgcolor
= (0.5, 0.5, 0.5)
502 ; scrollbarinpm
= true
505 ; mustoresize
= 256 lsl 20
510 | Plinux
| Pfreebsd
| Pdragonflybsd
511 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
512 | Posx
-> "open \"%s\""
513 | Pcygwin
-> "cygstart \"%s\""
514 | Punknown
-> "echo %s")
515 ; pathlauncher
= "lp \"%s\""
518 | Plinux
| Pfreebsd
| Pdragonflybsd
519 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
526 ; redirectstderr
= false
533 let mk n
= (n
, Hashtbl.create
1) in
546 let findkeyhash c name
=
547 try List.assoc name c
.keyhashes
548 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
551 let conf = { defconf with angle
= defconf.angle
};;
554 { mutable fontsize
: int
555 ; mutable wwidth
: float
556 ; mutable maxrows
: int
568 fstate.fontsize
<- n
;
569 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
570 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
574 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
575 let len = String.length s
in
576 if colonpos >= 0 && colonpos + 3 < len
578 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
581 try String.rindex_from s
colonpos ' '
585 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
588 | "http" | "ftp" | "mailto" ->
590 try String.index_from s
colonpos ' '
591 with Not_found
-> len
593 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
601 if String.length
conf.urilauncher
= 0
602 then print_endline uri
604 let url = geturl uri
in
605 if String.length
url = 0
606 then print_endline uri
608 let re = Str.regexp
"%s" in
609 let command = Str.global_replace
re url conf.urilauncher
in
613 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
619 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
620 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
624 let strings = version () :: "" :: Help.keys
in
627 let url = geturl s
in
628 if String.length
url > 0
629 then (s
, 0, Action
(fun u
-> gotouri url; u
))
630 else (s
, 0, Noaction
)
635 let firstgeomcmds = "", [];;
642 ; stderr
= Unix.stderr
643 ; errmsgs
= Buffer.create
0
650 ; anchor
= emptyanchor
654 ; tilelru
= Queue.create
()
655 ; pagemap
= Hashtbl.create
10
656 ; tilemap
= Hashtbl.create
10
671 ; geomcmds
= firstgeomcmds
673 { nav
= cbnew 10 (0, 0.0)
699 Printf.kprintf prerr_endline fmt
701 Printf.kprintf ignore fmt
705 if String.length
conf.pathlauncher
= 0
706 then print_endline
state.path
708 let re = Str.regexp
"%s" in
709 let command = Str.global_replace
re state.path
conf.pathlauncher
in
713 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
719 type 'a t
= | Res
of 'a
| Exn
of exn
;;
722 try Res
(Unix.pipe ())
728 with exn
-> f
(Printexc.to_string exn
)
732 try Res
(Unix.dup fd
)
737 try Res
(Unix.dup2 fd1 fd2
)
742 let redirectstderr () =
743 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
744 if conf.redirectstderr
746 match Ne.pipe () with
748 dolog "failed to create stderr redirection pipes: %s"
749 (Printexc.to_string exn
)
752 begin match Ne.dup Unix.stderr
with
754 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
755 Ne.clo r
(clofail "pipe/r");
756 Ne.clo w
(clofail "pipe/w");
758 | Ne.Res dupstderr
->
759 begin match Ne.dup2 w
Unix.stderr
with
761 dolog "failed to dup2 to stderr: %s"
762 (Printexc.to_string exn
);
763 Ne.clo dupstderr
(clofail "stderr duplicate");
764 Ne.clo r
(clofail "redir pipe/r");
765 Ne.clo w
(clofail "redir pipe/w");
768 state.stderr
<- dupstderr
;
769 state.errfd
<- Some r
;
773 state.newerrmsgs
<- false;
774 begin match state.errfd
with
776 begin match Ne.dup2 state.stderr
Unix.stderr
with
778 dolog "failed to dup2 original stderr: %s"
779 (Printexc.to_string exn
)
781 Ne.clo fd
(clofail "dup of stderr");
782 Unix.dup2 state.stderr
Unix.stderr
;
787 prerr_string
(Buffer.contents
state.errmsgs
);
789 Buffer.clear
state.errmsgs
;
795 let postRedisplay who
=
797 then prerr_endline
("redisplay for " ^ who
);
798 state.redisplay
<- true;
802 let getopaque pageno
=
803 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
804 with Not_found
-> None
807 let putopaque pageno opaque
=
808 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
811 let pagetranslatepoint l x y
=
812 let dy = y
- l
.pagedispy
in
813 let y = dy + l
.pagey
in
814 let dx = x
- l
.pagedispx
in
815 let x = dx + l
.pagex
in
822 begin match getopaque l
.pageno
with
824 let x0 = l
.pagedispx
in
825 let x1 = x0 + l
.pagevw
in
826 let y0 = l
.pagedispy
in
827 let y1 = y0 + l
.pagevh
in
828 if y >= y0 && y <= y1 && x >= x0 && x <= x1
830 let px, py
= pagetranslatepoint l
x y in
831 match whatsunder opaque
px py
with
844 state.text
<- Printf.sprintf
"%c%s" c s
;
845 G.postRedisplay "showtext";
848 let undertext = function
851 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
852 | Utext s
-> "font: " ^ s
853 | Uunexpected s
-> "unexpected: " ^ s
854 | Ulaunch s
-> "launch: " ^ s
855 | Unamed s
-> "named: " ^ s
856 | Uremote
(filename
, pageno
) ->
857 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
860 let updateunder x y =
861 match getunder x y with
862 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
864 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
865 Wsi.setcursor
Wsi.CURSOR_INFO
866 | Ulinkgoto
(pageno
, _
) ->
868 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
869 Wsi.setcursor
Wsi.CURSOR_INFO
871 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
872 Wsi.setcursor
Wsi.CURSOR_TEXT
874 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
875 Wsi.setcursor
Wsi.CURSOR_INHERIT
877 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
878 Wsi.setcursor
Wsi.CURSOR_INHERIT
880 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
881 Wsi.setcursor
Wsi.CURSOR_INHERIT
882 | Uremote
(filename
, pageno
) ->
883 if conf.underinfo
then showtext 'r'
884 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
885 Wsi.setcursor
Wsi.CURSOR_INFO
888 let showlinktype under
=
894 let s = undertext under
in
899 let b = Buffer.create
(String.length
s + 1) in
900 Buffer.add_string
b s;
905 let colorspace_of_string s =
906 match String.lowercase
s with
910 | _
-> failwith
"invalid colorspace"
913 let int_of_colorspace = function
919 let colorspace_of_int = function
923 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
926 let colorspace_to_string = function
932 let intentry_with_suffix text key
=
934 if key
>= 32 && key
< 127
938 match Char.lowercase
c with
940 let text = addchar text c in
944 let text = addchar text c in
948 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
952 let multicolumns_to_string (n
, a
, b) =
954 then Printf.sprintf
"%d" n
955 else Printf.sprintf
"%d,%d,%d" n a
b;
958 let multicolumns_of_string s =
960 (int_of_string
s, 0, 0)
962 Scanf.sscanf
s "%u,%u,%u" (fun n a
b -> (n
, a
, b));
967 let n = Unix.read fd
s 0 4 in
968 if n != 4 then failwith
"incomplete read(len)";
970 lor (Char.code
s.[0] lsl 24)
971 lor (Char.code
s.[1] lsl 16)
972 lor (Char.code
s.[2] lsl 8)
973 lor (Char.code
s.[3] lsl 0)
975 let s = String.create
len in
976 let n = Unix.read fd
s 0 len in
977 if n != len then failwith
"incomplete read(data)";
981 let btod b = if b then 1 else 0;;
984 let b = Buffer.create
16 in
985 Buffer.add_string
b "llll";
988 let s = Buffer.contents
b in
989 let n = String.length
s in
991 (* dolog "wcmd %S" (String.sub s 4 len); *)
992 s.[0] <- Char.chr
((len lsr 24) land 0xff);
993 s.[1] <- Char.chr
((len lsr 16) land 0xff);
994 s.[2] <- Char.chr
((len lsr 8) land 0xff);
995 s.[3] <- Char.chr
(len land 0xff);
996 let n'
= Unix.write
state.sw
s 0 n in
997 if n'
!= n then failwith
"write failed";
1002 if conf.presentation
1004 let d = conf.winh
- h
in
1011 let rec f pn ph pi fh l
=
1013 | (n, _
, h
, _
) :: rest
->
1014 let ips = calcips h
in
1016 if conf.presentation
1019 if isbirdseye state.mode
&& pn
= 0
1024 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
1029 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
1033 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
1036 let fh = f 0 0 0 0 state.pdims
in
1041 match conf.columns
with
1042 | Csingle
-> calcheight ()
1043 | Cmulti
((c, _
, _
), b) ->
1044 let rec loop y h
n =
1048 if n = Array.length
b
1051 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
1057 loop max_int
0 (((Array.length
b - 1) / c) * c)
1059 if Array.length
b > 0
1061 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1066 let getpageyh pageno
=
1067 let rec f pn ph pi
y l
=
1069 | (n, _
, h
, _
) :: rest
->
1070 let ips = calcips h
in
1073 let h = if n = pageno
then h else ph
in
1074 if conf.presentation
&& n = pageno
1076 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
1078 y + (pageno
- pn
) * (ph
+ pi
), h
1080 let y = y + (if conf.presentation
then pi
else 0) in
1081 let y = y + (n - pn
) * (ph
+ pi
) in
1085 y + (pageno
- pn
) * (ph
+ pi
), ph
1087 f 0 0 0 0 state.pdims
1090 let getpageyh pageno
=
1091 match conf.columns
with
1092 | Csingle
-> getpageyh pageno
1094 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1098 let (_
, _
, y, (_
, _
, h, _
)) = b.(n) in
1102 let getpagedim pageno
=
1105 | (n, _
, _
, _
) as pdim
:: rest
->
1107 then (if n = pageno
then pdim
else ppdim
)
1112 f (-1, -1, -1, -1) state.pdims
1115 let getpagey pageno
= fst
(getpageyh pageno
);;
1117 let nogeomcmds cmds
=
1119 | s, [] -> String.length
s = 0
1124 let sh = sh - state.hscrollh
in
1125 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1126 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1128 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1129 let ips = calcips h in
1131 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1135 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1137 prev
, pdims
, pdimno
, 0
1139 let dy = dy + yinc in
1140 let py = py + yinc in
1141 if pageno
= state.pagecount
|| dy >= sh
1146 if py + h <= vy - yinc
1148 let py = py + h + ips in
1149 let dy = max
0 (py - y) in
1150 f ~pageno
:(pageno
+1)
1158 let pagey = vy - py in
1159 let pagevh = h - pagey in
1160 let pagevh = min
(sh - dy) pagevh in
1161 let off = if yinc > 0 then py - vy else 0 in
1162 let py = py + h + ips in
1165 if state.w
< conf.winw
- state.scrollw
1166 then (conf.winw
- state.scrollw
- state.w
) / 2
1169 let dispx = xoff + state.x in
1175 let lw = w
- pagex in
1176 min
lw (conf.winw
- state.scrollw
)
1180 ; pagedimno
= pdimno
1184 ; pagey = pagey + off
1186 ; pagevh = pagevh - off
1188 ; pagedispy
= dy + off
1192 let accu = e :: accu in
1193 f ~pageno
:(pageno
+1)
1214 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1215 let sh = sh - state.hscrollh
in
1216 let rec fold accu n =
1217 if n = Array.length
b
1220 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1223 || n = state.pagecount
- coverB
1224 || (n - coverA
) mod columns
= columns
- 1)
1230 let pagey = max
0 (y - vy) in
1231 let pagedispy = if pagey > 0 then 0 else vy - y in
1232 let pagedispx, pagex =
1234 if n = coverA
- 1 || n = state.pagecount
- coverB
1235 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1236 else dx + xoff + state.x
1243 let vw = conf.winw
- state.scrollw
- pagedispx in
1244 let pw = w
- pagex in
1247 let pagevh = min
(h - pagey) (sh - pagedispy) in
1248 if pagevw > 0 && pagevh > 0
1252 ; pagedimno
= pdimno
1259 ; pagedispx = pagedispx
1260 ; pagedispy = pagedispy
1272 List.rev
(fold [] 0)
1275 let layoutS (columns
, b) y sh =
1276 let sh = sh - state.hscrollh
in
1277 let rec fold accu n =
1278 if n = Array.length
b
1281 let pdimno, px, vy, (_
, pagew
, pageh
, xoff) = b.(n) in
1288 let x = xoff + state.x in
1289 let pagey = max
0 (y - vy) in
1290 let pagedispy = if pagey > 0 then 0 else vy - y in
1291 let pagedispx, pagex =
1306 let vw = conf.winw
- pagedispx - state.scrollw
in
1307 let pw = pagew
- pagex in
1310 let pagevw = min
pagevw (pagew
/columns
) in
1311 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1312 if pagevw > 0 && pagevh > 0
1315 { pageno
= n/columns
1316 ; pagedimno
= pdimno
1323 ; pagedispx = pagedispx
1324 ; pagedispy = pagedispy
1325 ; pagecol
= n mod columns
1336 List.rev
(fold [] 0)
1340 if nogeomcmds state.geomcmds
1342 match conf.columns
with
1343 | Csingle
-> layout1 y sh
1344 | Cmulti
c -> layoutN c y sh
1345 | Csplit
s -> layoutS s y sh
1350 let y = state.y + incr
in
1352 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1357 let tilex = l
.pagex mod conf.tilew
in
1358 let tiley = l
.pagey mod conf.tileh
in
1360 let col = l
.pagex / conf.tilew
in
1361 let row = l
.pagey / conf.tileh
in
1363 let rec rowloop row y0 dispy
h =
1367 let dh = conf.tileh
- y0 in
1368 let dh = min
h dh in
1369 let rec colloop col x0 dispx w
=
1373 let dw = conf.tilew
- x0 in
1374 let dw = min w
dw in
1376 f col row dispx dispy
x0 y0 dw dh;
1377 colloop (col+1) 0 (dispx+dw) (w
-dw)
1380 colloop col tilex l
.pagedispx l
.pagevw;
1381 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1384 if l
.pagevw > 0 && l
.pagevh > 0
1385 then rowloop row tiley l
.pagedispy l
.pagevh;
1388 let gettileopaque l
col row =
1390 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1392 try Some
(Hashtbl.find
state.tilemap
key)
1393 with Not_found
-> None
1396 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1397 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1398 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1401 let drawtiles l color
=
1403 let f col row x y tilex tiley w
h =
1404 match gettileopaque l
col row with
1405 | Some
(opaque
, _
, t
) ->
1406 let params = x, y, w
, h, tilex, tiley in
1410 GlFunc.blend_func `zero `one_minus_src_color
;
1412 drawtile
params opaque
;
1414 then Gl.disable `blend
;
1417 let s = Printf.sprintf
1421 let w = measurestr
fstate.fontsize
s in
1422 GlMisc.push_attrib
[`current
];
1423 GlDraw.color
(0.0, 0.0, 0.0);
1425 (float (x-2), float (y-2))
1426 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1427 GlDraw.color
(1.0, 1.0, 1.0);
1428 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1429 GlMisc.pop_attrib
();
1434 let lw = conf.winw
- state.scrollw
- x in
1437 let lh = conf.winh
- y in
1440 Gl.enable `texture_2d
;
1441 begin match state.texid
with
1443 GlTex.bind_texture `texture_2d id
;
1446 and x1 = float (x+w)
1447 and y1 = float (y+h) in
1449 let tw = float w /. 64.0
1450 and th
= float h /. 64.0 in
1451 let tx0 = float tilex /. 64.0
1452 and ty0
= float tiley /. 64.0 in
1454 and ty1
= ty0
+. th
in
1455 GlDraw.begins `quads
;
1456 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1457 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1458 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1459 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1462 Gl.disable `texture_2d
;
1464 GlDraw.color
(1.0, 1.0, 1.0);
1467 (float (x+w), float (y+h));
1469 if w > 128 && h > fstate.fontsize
+ 10
1471 GlDraw.color
(0.0, 0.0, 0.0);
1474 then (col*conf.tilew
, row*conf.tileh
)
1477 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1484 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1486 let tilevisible1 l
x y =
1488 and ax1
= l
.pagex + l
.pagevw
1490 and ay1
= l
.pagey + l
.pagevh in
1494 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1495 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1497 let rx0 = max
ax0 bx0
1498 and ry0
= max ay0 by0
1499 and rx1
= min ax1
bx1
1500 and ry1
= min ay1 by1
in
1502 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1503 nonemptyintersection
1506 let tilevisible layout n x y =
1507 let rec findpageinlayout m
= function
1508 | l
:: rest
when l
.pageno
= n ->
1509 tilevisible1 l
x y || (
1510 match conf.columns
with
1511 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1514 | _
:: rest
-> findpageinlayout 0 rest
1517 findpageinlayout 0 layout;
1520 let tileready l
x y =
1521 tilevisible1 l
x y &&
1522 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1525 let tilepage n p
layout =
1526 let rec loop = function
1530 let f col row _ _ _ _ _ _
=
1531 if state.currently
= Idle
1533 match gettileopaque l
col row with
1536 let x = col*conf.tilew
1537 and y = row*conf.tileh
in
1539 let w = l
.pagew
- x in
1543 let h = l
.pageh
- y in
1546 wcmd "tile %s %d %d %d %d" p
x y w h;
1549 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1550 conf.tilew
, conf.tileh
1559 if nogeomcmds state.geomcmds
1563 let preloadlayout visiblepages
=
1564 let presentation = conf.presentation in
1565 let interpagespace = conf.interpagespace in
1566 let maxy = state.maxy in
1567 conf.presentation <- false;
1568 conf.interpagespace <- 0;
1569 state.maxy <- calcheight ();
1571 match visiblepages
with
1572 | [] -> if state.y >= maxy then maxy else 0
1573 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1575 let y = if y < conf.winh
then 0 else y - conf.winh
in
1576 let h = state.y - y + conf.winh
*3 in
1577 let pages = layout y h in
1578 conf.presentation <- presentation;
1579 conf.interpagespace <- interpagespace;
1585 let rec loop pages =
1586 if state.currently
!= Idle
1591 begin match getopaque l
.pageno
with
1593 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1594 state.currently
<- Loading
(l
, state.gen
);
1596 tilepage l
.pageno opaque
pages;
1601 if nogeomcmds state.geomcmds
1607 if conf.preload && state.currently
= Idle
1608 then load (preloadlayout pages);
1611 let layoutready layout =
1612 let rec fold all ls
=
1613 all
&& match ls
with
1615 let seen = ref false in
1616 let allvisible = ref true in
1617 let foo col row _ _ _ _ _ _
=
1619 allvisible := !allvisible &&
1620 begin match gettileopaque l
col row with
1626 fold (!seen && !allvisible) rest
1629 let alltilesvisible = fold true layout in
1634 let y = bound y 0 state.maxy in
1635 let y, layout, proceed
=
1636 match conf.maxwait
with
1637 | Some time
when state.ghyll
== noghyll ->
1638 begin match state.throttle
with
1640 let layout = layout y conf.winh
in
1641 let ready = layoutready layout in
1645 state.throttle
<- Some
(layout, y, now ());
1647 else G.postRedisplay "gotoy showall (None)";
1649 | Some
(_
, _
, started
) ->
1650 let dt = now () -. started
in
1653 state.throttle
<- None
;
1654 let layout = layout y conf.winh
in
1656 G.postRedisplay "maxwait";
1663 let layout = layout y conf.winh
in
1664 if true || layoutready layout
1665 then G.postRedisplay "gotoy ready";
1671 state.layout <- layout;
1672 begin match state.mode
with
1673 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
1674 let rec loop = function
1676 state.mode
<- LinkNav
(Ltgendir
0)
1677 | l
:: _
when l
.pageno
= pageno
->
1678 begin match getopaque pageno
with
1680 state.mode
<- LinkNav
(Ltgendir
0)
1682 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1683 if not
(x0 >= l
.pagex && x1 <= l
.pagex + l
.pagevw
1684 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1685 then state.mode
<- LinkNav
(Ltgendir
0)
1687 | _
:: rest
-> loop rest
1692 begin match state.mode
with
1693 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1694 if not
(pagevisible layout pageno
)
1696 match state.layout with
1699 state.mode
<- Birdseye
(
1700 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1703 | LinkNav
(Ltgendir dir
as lt
) ->
1705 let rec loop = function
1708 match getopaque l
.pageno
with
1714 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1716 if dir
> 0 then LDfirst
else LDlast
1722 | Lnotfound
-> loop rest
1724 showlinktype (getlink opaque
n);
1725 Ltexact
(l
.pageno
, n)
1729 state.mode
<- LinkNav
linknav
1734 state.ghyll
<- noghyll;
1737 let mx, my
= state.mpos
in
1742 let conttiling pageno opaque
=
1743 tilepage pageno opaque
1744 (if conf.preload then preloadlayout state.layout else state.layout)
1747 let gotoy_and_clear_text y =
1748 if not
conf.verbose
then state.text <- "";
1753 match state.layout with
1756 let coloff = l
.pagecol
* l
.pageh
in
1757 (l
.pageno
, (float l
.pagey +. float coloff) /. float l
.pageh
)
1760 let getanchory (n, top
) =
1761 let y, h = getpageyh n in
1762 y + (truncate
(top
*. float h));
1765 let gotoanchor anchor
=
1766 gotoy (getanchory anchor
);
1770 cbput state.hists
.nav
(getanchor ());
1774 let anchor = cbgetc state.hists
.nav dir
in
1779 let rec scroll f n a
b =
1780 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1782 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1784 then s (float f /. float a
)
1787 then 1.0 -. s ((float (f-b) /. float (n-b)))
1794 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1795 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1797 let ins = float a
*. iv1
1798 and outs
= float (n-b) *. iv1 in
1800 ins +. outs
+. float ones
1802 let rec set (_N
, _A
, _B
) y sy
=
1803 let sum = summa
1.0 _N _A _B
in
1804 let dy = float (y - sy
) in
1808 then state.ghyll
<- noghyll
1811 let s = scroll n _N _A _B
in
1812 let y1 = y1 +. ((s *. dy) /. sum) in
1813 gotoy_and_clear_text (truncate
y1);
1814 state.ghyll
<- gf (n+1) y1;
1818 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1820 gf 0 (float state.y)
1823 match conf.ghyllscroll
with
1825 gotoy_and_clear_text y
1827 if state.ghyll
== noghyll
1828 then set nab
y state.y
1829 else state.ghyll
(Some
y)
1832 let gotopage n top
=
1833 let y, h = getpageyh n in
1834 let y = y + (truncate
(top
*. float h)) in
1838 let gotopage1 n top
=
1839 let y = getpagey n in
1844 let invalidate s f =
1849 match state.geomcmds
with
1850 | ps
, [] when String.length ps
= 0 ->
1852 state.geomcmds
<- s, [];
1855 state.geomcmds
<- ps
, [s, f];
1857 | ps
, (s'
, _
) :: rest
when s'
= s ->
1858 state.geomcmds
<- ps
, ((s, f) :: rest
);
1861 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1864 let opendoc path password
=
1866 state.password
<- password
;
1867 state.gen
<- state.gen
+ 1;
1868 state.docinfo
<- [];
1870 setaalevel
conf.aalevel
;
1871 Wsi.settitle
("llpp " ^
Filename.basename path
);
1872 wcmd "open %s\000%s\000" path password
;
1873 invalidate "reqlayout"
1875 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1879 let c = c *. conf.colorscale
in
1883 let scalecolor2 (r
, g
, b) =
1884 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1887 let docolumns = function
1890 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1891 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1892 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1893 let rec fixrow m
= if m
= pageno
then () else
1894 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1897 let y = y + (rowh
- h) / 2 in
1898 a.(m
) <- (pdimno, x, y, pdim
);
1902 if pageno
= state.pagecount
1903 then fixrow (((pageno
- 1) / columns
) * columns
)
1905 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1907 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1908 pdimno+1, pdim
, rest
1913 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1915 (conf.winw
- state.scrollw
- w) / 2,
1916 y + rowh
+ conf.interpagespace, h
1919 if (pageno
- coverA
) mod columns
= 0
1920 then 0, y + rowh
+ conf.interpagespace, h
1921 else x, y, max rowh
h
1924 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1925 then fixrow (pageno
- columns
);
1926 a.(pageno
) <- (pdimno, x, y, pdim
);
1927 let x = x + w + xoff*2 + conf.interpagespace in
1928 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1930 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1931 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1934 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1935 let rec loop pageno
pdimno pdim
y pdims
=
1936 if pageno
= state.pagecount
1939 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1941 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1942 pdimno+1, pdim
, rest
1947 let rec loop1 n x y =
1948 if n = c then y else (
1949 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1950 loop1 (n+1) (x+cw) (y + h + conf.interpagespace)
1953 let y = loop1 0 0 y in
1954 loop (pageno
+1) pdimno pdim
y pdims
1956 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1957 conf.columns
<- Csplit
(c, a);
1961 docolumns conf.columns
;
1962 state.maxy <- calcheight ();
1964 if state.w <= conf.winw
- state.scrollw
1968 match state.mode
with
1969 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1970 let y, h = getpageyh pageno
in
1971 let top = (conf.winh
- h) / 2 in
1972 gotoy (max
0 (y - top))
1973 | _
-> gotoanchor state.anchor
1977 GlDraw.viewport
0 0 w h;
1978 let firsttime = state.geomcmds
== firstgeomcmds in
1979 if not
firsttime && nogeomcmds state.geomcmds
1980 then state.anchor <- getanchor ();
1983 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1986 setfontsize fstate.fontsize
;
1987 GlMat.mode `modelview
;
1988 GlMat.load_identity
();
1990 GlMat.mode `projection
;
1991 GlMat.load_identity
();
1992 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1993 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1994 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1999 else float state.x /. float state.w
2001 invalidate "geometry"
2005 then state.x <- truncate
(relx *. float w);
2007 match conf.columns
with
2009 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
2010 | Csplit
(c, _
) -> w * c
2012 wcmd "geometry %d %d" w h);
2016 let len = String.length
state.text in
2019 match state.mode
with
2022 let h, _
, _
= state.uioh#scrollpw
in
2028 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2029 (x+.w, float (conf.winh
- hscrollh))
2032 let w = float (conf.winw
- state.scrollw
- 1) in
2033 if state.progress
>= 0.0 && state.progress
< 1.0
2035 GlDraw.color
(0.3, 0.3, 0.3);
2036 let w1 = w *. state.progress
in
2038 GlDraw.color
(0.0, 0.0, 0.0);
2042 GlDraw.color
(0.0, 0.0, 0.0);
2046 GlDraw.color
(1.0, 1.0, 1.0);
2047 drawstring fstate.fontsize
2048 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2051 match state.mode
with
2052 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
2056 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2058 Printf.sprintf
"%s%s_" prefix
text
2067 if not
(istextentry state.mode
)
2069 let s1 = "(press 'e' to review error messasges)" in
2070 if String.length
s > 0 then s ^
" " ^
s1 else s1
2075 if String.length
s > 0
2080 let len = Queue.length
state.tilelru
in
2082 if state.memused
<= conf.memlimit
2087 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2088 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2089 let (_
, pw, ph
, _
) = getpagedim n in
2092 && colorspace
= conf.colorspace
2093 && angle
= conf.angle
2098 match state.throttle
with
2101 then preloadlayout state.layout
2103 | Some
(layout, _
, _
) ->
2106 let x = col*conf.tilew
2107 and y = row*conf.tileh
in
2108 tilevisible layout n x y
2110 then Queue.push lruitem
state.tilelru
2112 wcmd "freetile %s" p
;
2113 state.memused
<- state.memused
- s;
2114 state.uioh#infochanged Memused
;
2115 Hashtbl.remove
state.tilemap k
;
2124 Queue.iter
(fun (k
, p
, s) ->
2125 wcmd "freetile %s" p
;
2126 state.memused
<- state.memused
- s;
2127 state.uioh#infochanged Memused
;
2128 Hashtbl.remove
state.tilemap k
;
2130 Queue.clear
state.tilelru
;
2134 let logcurrently = function
2135 | Idle
-> dolog "Idle"
2136 | Loading
(l
, gen
) ->
2137 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2138 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2140 "Tiling %d[%d,%d] page=%s cs=%s angle"
2141 l
.pageno
col row pageopaque
2142 (colorspace_to_string colorspace
)
2144 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2145 angle gen
conf.angle
state.gen
2147 conf.tilew
conf.tileh
2154 (* dolog "%S" cmds; *)
2157 try String.index cmds ' '
2158 with Not_found
-> -1
2163 let l = String.length cmds
in
2164 let op = String.sub cmds
0 spacepos in
2166 if l - spacepos < 2 then ""
2167 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2172 state.uioh#infochanged Pdim
;
2176 state.rects
<- state.rects1
;
2177 G.postRedisplay "clearrects";
2181 try Scanf.sscanf
args "%u" (fun n -> n)
2183 dolog "error processing 'continue' %S: %s"
2184 cmds
(Printexc.to_string exn
);
2187 state.pagecount
<- n;
2188 begin match state.currently
with
2190 state.currently
<- Idle
;
2191 state.outlines
<- Array.of_list
(List.rev
l)
2195 let cur, cmds
= state.geomcmds
in
2196 if String.length
cur = 0
2197 then failwith
"umpossible";
2199 begin match List.rev cmds
with
2201 state.geomcmds
<- "", [];
2205 state.geomcmds
<- s, List.rev rest
;
2207 if conf.maxwait
= None
2208 then G.postRedisplay "continue";
2218 then showtext ' '
args
2221 let progress, text =
2223 Scanf.sscanf
args "%f %n"
2225 f, String.sub
args pos
(String.length
args - pos
))
2227 dolog "error processing 'progress' %S: %s"
2228 cmds
(Printexc.to_string exn
);
2232 state.progress <- progress;
2233 G.postRedisplay "progress"
2236 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2238 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2239 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2240 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2242 dolog "error processing 'firstmatch' %S: %s"
2243 cmds
(Printexc.to_string exn
);
2246 let y = (getpagey pageno) + truncate
y0 in
2249 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2252 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2254 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2255 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2256 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2258 dolog "error processing 'match' %S: %s"
2259 cmds
(Printexc.to_string exn
);
2263 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2268 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2270 dolog "error processing 'page' %S: %s"
2271 cmds
(Printexc.to_string exn
);
2274 begin match state.currently
with
2275 | Loading
(l, gen
) ->
2276 vlog "page %d took %f sec" l.pageno t
;
2277 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2278 begin match state.throttle
with
2280 let preloadedpages =
2282 then preloadlayout state.layout
2287 Set.Make
(struct type t
= int let compare = (-) end) in
2289 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2290 IntSet.empty
preloadedpages
2293 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2294 if not
(IntSet.mem
pageno set)
2296 wcmd "freepage %s" opaque
;
2302 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2305 state.currently
<- Idle
;
2308 tilepage l.pageno pageopaque state.layout;
2310 load preloadedpages;
2311 if pagevisible state.layout l.pageno
2312 && layoutready state.layout
2313 then G.postRedisplay "page";
2316 | Some
(layout, _
, _
) ->
2317 state.currently
<- Idle
;
2318 tilepage l.pageno pageopaque layout;
2323 dolog "Inconsistent loading state";
2324 logcurrently state.currently
;
2329 let (x, y, opaque
, size
, t
) =
2331 Scanf.sscanf
args "%u %u %s %u %f"
2332 (fun x y p size t
-> (x, y, p
, size
, t
))
2334 dolog "error processing 'tile' %S: %s"
2335 cmds
(Printexc.to_string exn
);
2338 begin match state.currently
with
2339 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2340 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2342 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2344 wcmd "freetile %s" opaque
;
2345 state.currently
<- Idle
;
2349 puttileopaque l col row gen cs angle opaque size t
;
2350 state.memused
<- state.memused
+ size
;
2351 state.uioh#infochanged Memused
;
2353 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2354 opaque
, size
) state.tilelru
;
2357 match state.throttle
with
2358 | None
-> state.layout
2359 | Some
(layout, _
, _
) -> layout
2362 state.currently
<- Idle
;
2364 && conf.colorspace
= cs
2365 && conf.angle
= angle
2366 && tilevisible layout l.pageno x y
2367 then conttiling l.pageno pageopaque;
2369 begin match state.throttle
with
2371 preload state.layout;
2373 && conf.colorspace
= cs
2374 && conf.angle
= angle
2375 && tilevisible state.layout l.pageno x y
2376 then G.postRedisplay "tile nothrottle";
2378 | Some
(layout, y, _
) ->
2379 let ready = layoutready layout in
2383 state.layout <- layout;
2384 state.throttle
<- None
;
2385 G.postRedisplay "throttle";
2392 dolog "Inconsistent tiling state";
2393 logcurrently state.currently
;
2400 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2402 dolog "error processing 'pdim' %S: %s"
2403 cmds
(Printexc.to_string exn
);
2406 state.uioh#infochanged Pdim
;
2407 state.pdims
<- pdim :: state.pdims
2410 let (l, n, t
, h, pos
) =
2412 Scanf.sscanf
args "%u %u %d %u %n"
2413 (fun l n t
h pos
-> l, n, t
, h, pos
)
2415 dolog "error processing 'o' %S: %s"
2416 cmds
(Printexc.to_string exn
);
2419 let s = String.sub
args pos
(String.length
args - pos
) in
2420 let outline = (s, l, (n, float t
/. float h)) in
2421 begin match state.currently
with
2422 | Outlining outlines
->
2423 state.currently
<- Outlining
(outline :: outlines
)
2425 state.currently
<- Outlining
[outline]
2427 dolog "invalid outlining state";
2428 logcurrently currently
2432 state.docinfo
<- (1, args) :: state.docinfo
2435 state.uioh#infochanged Docinfo
;
2436 state.docinfo
<- List.rev
state.docinfo
2439 dolog "unknown cmd `%S'" cmds
2444 let action = function
2445 | HCprev
-> cbget cb ~
-1
2446 | HCnext
-> cbget cb
1
2447 | HCfirst
-> cbget cb ~
-(cb
.rc)
2448 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2449 and cancel
() = cb
.rc <- rc
2453 let search pattern forward
=
2454 if String.length pattern
> 0
2457 match state.layout with
2460 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2462 wcmd "search %d %d %d %d,%s\000"
2463 (btod conf.icase
) pn py (btod forward
) pattern
;
2466 let intentry text key =
2468 if key >= 32 && key < 127
2474 let text = addchar text c in
2478 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2482 let linknentry text key =
2484 if key >= 32 && key < 127
2490 let text = addchar text c in
2494 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2499 if String.length
s > 0
2502 let l = String.length
s in
2503 let rec loop pos
n = if pos
= l then n else
2504 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2505 loop (pos
+1) (n*26 + m)
2508 let rec loop n = function
2511 match getopaque l.pageno with
2512 | None
-> loop n rest
2514 let m = getlinkcount opaque
in
2517 let under = getlink opaque
n in
2520 else loop (n-m) rest
2522 loop n state.layout;
2526 let textentry text key =
2527 if key land 0xff00 = 0xff00
2529 else TEcont
(text ^
Wsi.toutf8
key)
2532 let reqlayout angle proportional
=
2533 match state.throttle
with
2535 if nogeomcmds state.geomcmds
2536 then state.anchor <- getanchor ();
2537 conf.angle
<- angle
mod 360;
2540 match state.mode
with
2541 | LinkNav _
-> state.mode
<- View
2544 conf.proportional
<- proportional
;
2545 invalidate "reqlayout"
2546 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2550 let settrim trimmargins trimfuzz
=
2551 if nogeomcmds state.geomcmds
2552 then state.anchor <- getanchor ();
2553 conf.trimmargins
<- trimmargins
;
2554 conf.trimfuzz
<- trimfuzz
;
2555 let x0, y0, x1, y1 = trimfuzz
in
2556 invalidate "settrim"
2558 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2559 Hashtbl.iter
(fun _ opaque
->
2560 wcmd "freepage %s" opaque
;
2562 Hashtbl.clear
state.pagemap
;
2566 match state.throttle
with
2568 let zoom = max
0.01 zoom in
2569 if zoom <> conf.zoom
2571 state.prevzoom
<- conf.zoom;
2573 reshape conf.winw
conf.winh
;
2574 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2577 | Some
(layout, y, started
) ->
2579 match conf.maxwait
with
2583 let dt = now () -. started
in
2591 let setcolumns mode columns coverA coverB
=
2595 then showtext '
!'
"split mode doesn't work in bird's eye"
2597 conf.columns
<- Csplit
(-columns
, [||]);
2605 conf.columns
<- Csingle
;
2610 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2614 reshape conf.winw
conf.winh
;
2617 let enterbirdseye () =
2618 let zoom = float conf.thumbw
/. float conf.winw
in
2619 let birdseyepageno =
2620 let cy = conf.winh
/ 2 in
2624 let rec fold best
= function
2627 let d = cy - (l.pagedispy + l.pagevh/2)
2628 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2629 if abs
d < abs dbest
2636 state.mode
<- Birdseye
(
2637 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2640 conf.presentation <- false;
2641 conf.interpagespace <- 10;
2642 conf.hlinks
<- false;
2644 state.mstate
<- Mnone
;
2645 conf.maxwait
<- None
;
2647 match conf.beyecolumns
with
2650 Cmulti
((c, 0, 0), [||])
2653 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2656 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2661 reshape conf.winw
conf.winh
;
2664 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2666 conf.zoom <- c.zoom;
2667 conf.presentation <- c.presentation;
2668 conf.interpagespace <- c.interpagespace;
2669 conf.maxwait
<- c.maxwait
;
2670 conf.hlinks
<- c.hlinks
;
2671 conf.beyecolumns
<- (
2672 match conf.columns
with
2673 | Cmulti
((c, _
, _
), _
) -> Some
c
2675 | Csplit _
-> assert false
2678 match c.columns
with
2679 | Cmulti
(c, _
) -> Cmulti
(c, [||])
2680 | Csingle
-> Csingle
2681 | Csplit _
-> failwith
"leaving bird's eye split mode"
2686 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2689 reshape conf.winw
conf.winh
;
2690 state.anchor <- if goback
then anchor else (pageno, 0.0);
2693 let togglebirdseye () =
2694 match state.mode
with
2695 | Birdseye vals
-> leavebirdseye vals
true
2696 | View
-> enterbirdseye ()
2700 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2701 let pageno = max
0 (pageno - incr
) in
2702 let rec loop = function
2703 | [] -> gotopage1 pageno 0
2704 | l :: _
when l.pageno = pageno ->
2705 if l.pagedispy >= 0 && l.pagey = 0
2706 then G.postRedisplay "upbirdseye"
2707 else gotopage1 pageno 0
2708 | _
:: rest
-> loop rest
2711 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2714 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2715 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2716 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2717 let rec loop = function
2719 let y, h = getpageyh pageno in
2720 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2722 | l :: _
when l.pageno = pageno ->
2723 if l.pagevh != l.pageh
2724 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2725 else G.postRedisplay "downbirdseye"
2726 | _
:: rest
-> loop rest
2731 let optentry mode _
key =
2732 let btos b = if b then "on" else "off" in
2733 if key >= 32 && key < 127
2735 let c = Char.chr
key in
2739 try conf.scrollstep
<- int_of_string
s with exc
->
2740 state.text <- Printf.sprintf
"bad integer `%s': %s"
2741 s (Printexc.to_string exc
)
2743 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2748 conf.autoscrollstep
<- int_of_string
s;
2749 if state.autoscroll
<> None
2750 then state.autoscroll
<- Some
conf.autoscrollstep
2752 state.text <- Printf.sprintf
"bad integer `%s': %s"
2753 s (Printexc.to_string exc
)
2755 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2758 let mode = state.mode in
2761 let n, a, b = multicolumns_of_string s in
2762 setcolumns mode n a b;
2764 state.text <- Printf.sprintf
"bad columns `%s': %s"
2765 s (Printexc.to_string exc
)
2767 TEswitch
("columns: ", "", None
, textentry, ondone)
2772 let zoom = float (int_of_string
s) /. 100.0 in
2775 state.text <- Printf.sprintf
"bad integer `%s': %s"
2776 s (Printexc.to_string exc
)
2778 TEswitch
("zoom: ", "", None
, intentry, ondone)
2783 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2785 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2786 begin match mode with
2788 leavebirdseye beye
false;
2793 state.text <- Printf.sprintf
"bad integer `%s': %s"
2794 s (Printexc.to_string exc
)
2796 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2801 Some
(int_of_string
s)
2803 state.text <- Printf.sprintf
"bad integer `%s': %s"
2804 s (Printexc.to_string exc
);
2807 | Some angle
-> reqlayout angle
conf.proportional
2810 TEswitch
("rotation: ", "", None
, intentry, ondone)
2813 conf.icase
<- not
conf.icase
;
2814 TEdone
("case insensitive search " ^
(btos conf.icase
))
2817 conf.preload <- not
conf.preload;
2819 TEdone
("preload " ^
(btos conf.preload))
2822 conf.verbose
<- not
conf.verbose
;
2823 TEdone
("verbose " ^
(btos conf.verbose
))
2826 conf.debug
<- not
conf.debug
;
2827 TEdone
("debug " ^
(btos conf.debug
))
2830 conf.maxhfit
<- not
conf.maxhfit
;
2831 state.maxy <- calcheight ();
2832 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2835 conf.crophack
<- not
conf.crophack
;
2836 TEdone
("crophack " ^
btos conf.crophack
)
2840 match conf.maxwait
with
2842 conf.maxwait
<- Some infinity
;
2843 "always wait for page to complete"
2845 conf.maxwait
<- None
;
2846 "show placeholder if page is not ready"
2851 conf.underinfo
<- not
conf.underinfo
;
2852 TEdone
("underinfo " ^
btos conf.underinfo
)
2855 conf.savebmarks
<- not
conf.savebmarks
;
2856 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2862 match state.layout with
2867 conf.interpagespace <- int_of_string
s;
2868 docolumns conf.columns
;
2869 state.maxy <- calcheight ();
2870 let y = getpagey pageno in
2873 state.text <- Printf.sprintf
"bad integer `%s': %s"
2874 s (Printexc.to_string exc
)
2876 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2879 reqlayout conf.angle
(not
conf.proportional
);
2880 TEdone
("proportional display " ^
btos conf.proportional
)
2883 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2884 TEdone
("trim margins " ^
btos conf.trimmargins
)
2887 conf.invert
<- not
conf.invert
;
2888 TEdone
("invert colors " ^
btos conf.invert
)
2892 cbput state.hists
.sel
s;
2895 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2899 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2905 class type lvsource
= object
2906 method getitemcount
: int
2907 method getitem
: int -> (string * int)
2908 method hasaction
: int -> bool
2917 method getactive
: int
2918 method getfirst
: int
2919 method getqsearch
: string
2920 method setqsearch
: string -> unit
2924 class virtual lvsourcebase
= object
2925 val mutable m_active
= 0
2926 val mutable m_first
= 0
2927 val mutable m_qsearch
= ""
2928 val mutable m_pan
= 0
2929 method getactive
= m_active
2930 method getfirst
= m_first
2931 method getqsearch
= m_qsearch
2932 method getpan
= m_pan
2933 method setqsearch
s = m_qsearch
<- s
2936 let withoutlastutf8 s =
2937 let len = String.length
s in
2945 let b = Char.code
s.[pos
] in
2946 if b land 0b110000 = 0b11000000
2951 if Char.code
s.[len-1] land 0x80 = 0
2955 String.sub
s 0 first;
2958 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2960 state.mode <- Textentry
(te
, onleave
);
2963 G.postRedisplay "textentrykeyboard enttext";
2965 let histaction cmd
=
2968 | Some
(action, _
) ->
2969 state.mode <- Textentry
(
2970 (c, action cmd
, opthist
, onkey
, ondone), onleave
2972 G.postRedisplay "textentry histaction"
2975 | 0xff08 -> (* backspace *)
2976 let s = withoutlastutf8 text in
2977 let len = String.length
s in
2981 G.postRedisplay "textentrykeyboard after cancel";
2984 enttext (c, s, opthist
, onkey
, ondone)
2990 G.postRedisplay "textentrykeyboard after confirm"
2992 | 0xff52 -> histaction HCprev
2993 | 0xff54 -> histaction HCnext
2994 | 0xff50 -> histaction HCfirst
2995 | 0xff57 -> histaction HClast
2997 | 0xff1b -> (* escape*)
2998 if String.length
text = 0
3000 begin match opthist
with
3002 | Some
(_
, onhistcancel
) -> onhistcancel
()
3006 G.postRedisplay "textentrykeyboard after cancel2"
3009 enttext (c, "", opthist
, onkey
, ondone)
3012 | 0xff9f | 0xffff -> () (* delete *)
3014 | _
when key != 0 && key land 0xff00 != 0xff00 ->
3015 begin match onkey
text key with
3019 G.postRedisplay "textentrykeyboard after confirm2";
3022 enttext (c, text, opthist
, onkey
, ondone);
3026 G.postRedisplay "textentrykeyboard after cancel3"
3029 state.mode <- Textentry
(te
, onleave
);
3030 G.postRedisplay "textentrykeyboard switch";
3034 vlog "unhandled key %s" (Wsi.keyname
key)
3037 let firstof first active
=
3038 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3039 then max
0 (active
- (fstate.maxrows
/2))
3043 let calcfirst first active
=
3046 let rows = active
- first in
3047 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3051 let scrollph y maxy =
3052 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
3053 let sh = float conf.winh
/. sh in
3054 let sh = max
sh (float conf.scrollh
) in
3059 else float y /. float maxy
3061 let position = (float conf.winh
-. sh) *. percent in
3064 if position +. sh > float conf.winh
3065 then float conf.winh
-. sh
3071 let coe s = (s :> uioh
);;
3073 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3075 val m_pan
= source#getpan
3076 val m_first
= source#getfirst
3077 val m_active
= source#getactive
3078 val m_qsearch
= source#getqsearch
3079 val m_prev_uioh
= state.uioh
3081 method private elemunder
y =
3082 let n = y / (fstate.fontsize
+1) in
3083 if m_first
+ n < source#getitemcount
3085 if source#hasaction
(m_first
+ n)
3086 then Some
(m_first
+ n)
3093 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3094 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3095 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3096 GlDraw.color
(1., 1., 1.);
3097 Gl.enable `texture_2d
;
3098 let fs = fstate.fontsize
in
3100 let ww = fstate.wwidth
in
3101 let tabw = 30.0*.ww in
3102 let itemcount = source#getitemcount
in
3104 if (row - m_first
) * nfs > conf.winh
3107 if row >= 0 && row < itemcount
3109 let (s, level
) = source#getitem
row in
3110 let y = (row - m_first
) * nfs in
3111 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3114 Gl.disable `texture_2d
;
3115 GlDraw.polygon_mode `both `line
;
3116 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3117 GlDraw.rect (1., float (y + 1))
3118 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3119 GlDraw.polygon_mode `both `fill
;
3120 GlDraw.color
(1., 1., 1.);
3121 Gl.enable `texture_2d
;
3124 let drawtabularstring s =
3125 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3128 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3131 let len = String.length
s - tabpos - 1 in
3132 let s1 = String.sub
s 0 tabpos
3133 and s2
= String.sub
s (tabpos + 1) len in
3134 let nx = drawstr x s1 in
3136 let x = x +. (max
tabw sw) in
3143 let _ = drawtabularstring s in
3150 Gl.disable `texture_2d
;
3152 method updownlevel incr
=
3153 let len = source#getitemcount
in
3155 if m_active
>= 0 && m_active
< len
3156 then snd
(source#getitem m_active
)
3160 if i
= len then i
-1 else if i
= -1 then 0 else
3161 let _, l = source#getitem i
in
3162 if l != curlevel then i
else flow (i
+incr
)
3164 let active = flow m_active
in
3165 let first = calcfirst m_first
active in
3166 G.postRedisplay "outline updownlevel";
3167 {< m_active
= active; m_first
= first >}
3169 method private key1
key mask
=
3170 let set1 active first qsearch
=
3171 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3173 let search active pattern incr
=
3176 if n >= 0 && n < source#getitemcount
3178 let s, _ = source#getitem
n in
3180 (try ignore
(Str.search_forward
re s 0); true
3181 with Not_found
-> false)
3183 else loop (n + incr
)
3190 let re = Str.regexp_case_fold pattern
in
3196 let itemcount = source#getitemcount
in
3197 let find start incr
=
3199 if i
= -1 || i
= itemcount
3202 if source#hasaction i
3204 else find (i
+ incr
)
3209 let set active first =
3210 let first = bound first 0 (itemcount - fstate.maxrows
) in
3212 coe {< m_active
= active; m_first
= first >}
3215 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3217 let incr1 = if incr
> 0 then 1 else -1 in
3218 if isvisible m_first m_active
3221 let next = m_active
+ incr
in
3223 if next < 0 || next >= itemcount
3225 else find next incr1
3227 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3233 let first = m_first
+ incr
in
3234 let first = bound first 0 (itemcount - 1) in
3236 let next = m_active
+ incr
in
3237 let next = bound next 0 (itemcount - 1) in
3240 let active = if next = -1 then m_active
else next in
3243 let first = min
next m_first
in
3245 if abs
(next - first) > fstate.maxrows
3251 let first = m_first
+ incr
in
3252 let first = bound first 0 (itemcount - 1) in
3254 let next = m_active
+ incr
in
3255 let next = bound next 0 (itemcount - 1) in
3256 let next = find next incr1 in
3258 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3260 let active = if m_active
= -1 then next else m_active
in
3265 if isvisible first active
3271 G.postRedisplay "listview navigate";
3275 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3276 let incr = if key = 0x72 then -1 else 1 in
3278 match search (m_active
+ incr) m_qsearch
incr with
3280 state.text <- m_qsearch ^
" [not found]";
3283 state.text <- m_qsearch
;
3284 active, firstof m_first
active
3286 G.postRedisplay "listview ctrl-r/s";
3287 set1 active first m_qsearch
;
3289 | 0xff08 -> (* backspace *)
3290 if String.length m_qsearch
= 0
3293 let qsearch = withoutlastutf8 m_qsearch
in
3294 let len = String.length
qsearch in
3298 G.postRedisplay "listview empty qsearch";
3299 set1 m_active m_first
"";
3303 match search m_active
qsearch ~
-1 with
3305 state.text <- qsearch ^
" [not found]";
3308 state.text <- qsearch;
3309 active, firstof m_first
active
3311 G.postRedisplay "listview backspace qsearch";
3312 set1 active first qsearch
3315 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3316 let pattern = m_qsearch ^
Wsi.toutf8
key in
3318 match search m_active
pattern 1 with
3320 state.text <- pattern ^
" [not found]";
3323 state.text <- pattern;
3324 active, firstof m_first
active
3326 G.postRedisplay "listview qsearch add";
3327 set1 active first pattern;
3329 | 0xff1b -> (* escape *)
3331 if String.length m_qsearch
= 0
3333 G.postRedisplay "list view escape";
3336 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3338 | None
-> m_prev_uioh
3343 G.postRedisplay "list view kill qsearch";
3344 source#setqsearch
"";
3345 coe {< m_qsearch
= "" >}
3348 | 0xff0d -> (* return *)
3350 let self = {< m_qsearch
= "" >} in
3351 source#setqsearch
"";
3353 G.postRedisplay "listview enter";
3354 if m_active
>= 0 && m_active
< source#getitemcount
3356 source#exit
(coe self) false m_active m_first m_pan
"";
3359 source#exit
(coe self) true m_active m_first m_pan
"";
3362 begin match opt with
3363 | None
-> m_prev_uioh
3367 | 0xff9f | 0xffff -> (* delete *)
3370 | 0xff52 -> navigate ~
-1 (* up *)
3371 | 0xff54 -> navigate 1 (* down *)
3372 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3373 | 0xff56 -> navigate fstate.maxrows
(* next *)
3375 | 0xff53 -> (* right *)
3377 G.postRedisplay "listview right";
3378 coe {< m_pan
= m_pan
- 1 >}
3380 | 0xff51 -> (* left *)
3382 G.postRedisplay "listview left";
3383 coe {< m_pan
= m_pan
+ 1 >}
3385 | 0xff50 -> (* home *)
3386 let active = find 0 1 in
3387 G.postRedisplay "listview home";
3390 | 0xff57 -> (* end *)
3391 let first = max
0 (itemcount - fstate.maxrows
) in
3392 let active = find (itemcount - 1) ~
-1 in
3393 G.postRedisplay "listview end";
3396 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3400 dolog "listview unknown key %#x" key; coe self
3402 method key key mask
=
3403 match state.mode with
3404 | Textentry te
-> textentrykeyboard key mask te
; coe self
3405 | _ -> self#key1
key mask
3407 method button button down
x y _ =
3410 | 1 when x > conf.winw
- conf.scrollbw
->
3411 G.postRedisplay "listview scroll";
3414 let _, position, sh = self#
scrollph in
3415 if y > truncate
position && y < truncate
(position +. sh)
3417 state.mstate
<- Mscrolly
;
3421 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3422 let first = truncate
(s *. float source#getitemcount
) in
3423 let first = min source#getitemcount
first in
3424 Some
(coe {< m_first
= first; m_active
= first >})
3426 state.mstate
<- Mnone
;
3429 | 1 when not down
->
3430 begin match self#elemunder
y with
3432 G.postRedisplay "listview click";
3434 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3438 | n when (n == 4 || n == 5) && not down
->
3439 let len = source#getitemcount
in
3441 if n = 5 && m_first
+ fstate.maxrows
>= len
3445 let first = m_first
+ (if n == 4 then -1 else 1) in
3446 bound first 0 (len - 1)
3448 G.postRedisplay "listview wheel";
3449 Some
(coe {< m_first
= first >})
3454 | None
-> m_prev_uioh
3458 match state.mstate
with
3460 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3461 let first = truncate
(s *. float source#getitemcount
) in
3462 let first = min source#getitemcount
first in
3463 G.postRedisplay "listview motion";
3464 coe {< m_first
= first; m_active
= first >}
3467 method pmotion
x y =
3468 if x < conf.winw
- conf.scrollbw
3471 match self#elemunder
y with
3472 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3473 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3477 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3482 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3486 method infochanged
_ = ()
3488 method scrollpw
= (0, 0.0, 0.0)
3490 let nfs = fstate.fontsize
+ 1 in
3491 let y = m_first
* nfs in
3492 let itemcount = source#getitemcount
in
3493 let maxi = max
0 (itemcount - fstate.maxrows
) in
3494 let maxy = maxi * nfs in
3495 let p, h = scrollph y maxy in
3498 method modehash
= modehash
3501 class outlinelistview ~source
=
3504 ~source
:(source
:> lvsource
)
3506 ~modehash
:(findkeyhash conf "outline")
3509 method key key mask
=
3510 let calcfirst first active =
3513 let rows = active - first in
3514 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3518 let active = m_active
+ incr in
3519 let active = bound active 0 (source#getitemcount
- 1) in
3520 let first = calcfirst m_first
active in
3521 G.postRedisplay "outline navigate";
3522 coe {< m_active
= active; m_first
= first >}
3524 let ctrl = Wsi.withctrl mask
in
3526 | 110 when ctrl -> (* ctrl-n *)
3527 source#narrow m_qsearch
;
3528 G.postRedisplay "outline ctrl-n";
3529 coe {< m_first
= 0; m_active
= 0 >}
3531 | 117 when ctrl -> (* ctrl-u *)
3533 G.postRedisplay "outline ctrl-u";
3535 coe {< m_first
= 0; m_active
= 0 >}
3537 | 108 when ctrl -> (* ctrl-l *)
3538 let first = m_active
- (fstate.maxrows
/ 2) in
3539 G.postRedisplay "outline ctrl-l";
3540 coe {< m_first
= first >}
3542 | 0xff9f | 0xffff -> (* delete *)
3543 source#remove m_active
;
3544 G.postRedisplay "outline delete";
3545 let active = max
0 (m_active
-1) in
3546 coe {< m_first
= firstof m_first
active;
3547 m_active
= active >}
3549 | 0xff52 -> navigate ~
-1 (* up *)
3550 | 0xff54 -> navigate 1 (* down *)
3551 | 0xff55 -> (* prior *)
3552 navigate ~
-(fstate.maxrows
)
3553 | 0xff56 -> (* next *)
3554 navigate fstate.maxrows
3556 | 0xff53 -> (* [ctrl-]right *)
3560 G.postRedisplay "outline ctrl right";
3561 {< m_pan
= m_pan
+ 1 >}
3563 else self#updownlevel
1
3567 | 0xff51 -> (* [ctrl-]left *)
3571 G.postRedisplay "outline ctrl left";
3572 {< m_pan
= m_pan
- 1 >}
3574 else self#updownlevel ~
-1
3578 | 0xff50 -> (* home *)
3579 G.postRedisplay "outline home";
3580 coe {< m_first
= 0; m_active
= 0 >}
3582 | 0xff57 -> (* end *)
3583 let active = source#getitemcount
- 1 in
3584 let first = max
0 (active - fstate.maxrows
) in
3585 G.postRedisplay "outline end";
3586 coe {< m_active
= active; m_first
= first >}
3588 | _ -> super#
key key mask
3591 let outlinesource usebookmarks
=
3594 inherit lvsourcebase
3595 val mutable m_items
= empty
3596 val mutable m_orig_items
= empty
3597 val mutable m_prev_items
= empty
3598 val mutable m_narrow_pattern
= ""
3599 val mutable m_hadremovals
= false
3601 method getitemcount
=
3602 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3605 if n == Array.length m_items
&& m_hadremovals
3607 ("[Confirm removal]", 0)
3609 let s, n, _ = m_items
.(n) in
3612 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3613 ignore
(uioh
, first, qsearch);
3614 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3616 if String.length m_narrow_pattern
= 0
3622 if not
confrimremoval
3624 let _, _, anchor = m_items
.(active) in
3629 state.bookmarks
<- Array.to_list m_items
;
3630 m_orig_items
<- m_items
;
3633 else m_items
<- items;
3637 method hasaction
_ = true
3640 if Array.length m_items
!= Array.length m_orig_items
3641 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3644 method narrow
pattern =
3645 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3649 let rec loop accu n =
3652 m_narrow_pattern
<- pattern;
3653 m_items
<- Array.of_list
accu
3656 let (s, _, _) as o = m_items
.(n) in
3658 if (try ignore
(Str.search_forward
re s 0); true
3659 with Not_found
-> false)
3665 loop [] (Array.length m_items
- 1)
3670 then Array.of_list
state.bookmarks
3673 m_items
<- m_orig_items
3678 if m >= 0 && m < Array.length m_items
3680 m_hadremovals
<- true;
3681 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3682 let n = if n >= m then n+1 else n in
3687 method reset
anchor items =
3688 m_hadremovals
<- false;
3689 if m_orig_items
== empty || m_prev_items
!= items
3691 m_orig_items
<- items;
3692 if String.length m_narrow_pattern
= 0
3693 then m_items
<- items;
3695 m_prev_items
<- items;
3696 let rely = getanchory anchor in
3698 let rec loop n best bestd
=
3699 if n = Array.length m_items
3702 let (_, _, anchor) = m_items
.(n) in
3703 let orely = getanchory anchor in
3704 let d = abs
(orely - rely) in
3707 else loop (n+1) best bestd
3712 m_first
<- firstof m_first
active
3716 let enterselector usebookmarks
=
3717 let source = outlinesource usebookmarks
in
3721 then Array.of_list
state.bookmarks
3724 if Array.length
outlines = 0
3726 showtext ' ' errmsg
;
3729 state.text <- source#greetmsg
;
3730 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3731 let anchor = getanchor () in
3732 source#reset
anchor outlines;
3733 state.uioh
<- coe (new outlinelistview ~
source);
3734 G.postRedisplay "enter selector";
3738 let enteroutlinemode =
3739 let f = enterselector false in
3740 fun ()-> f "Document has no outline";
3743 let enterbookmarkmode =
3744 let f = enterselector true in
3745 fun () -> f "Document has no bookmarks (yet)";
3748 let color_of_string s =
3749 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3750 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3754 let color_to_string (r
, g
, b) =
3755 let r = truncate
(r *. 256.0)
3756 and g
= truncate
(g
*. 256.0)
3757 and b = truncate
(b *. 256.0) in
3758 Printf.sprintf
"%d/%d/%d" r g
b
3761 let irect_of_string s =
3762 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3765 let irect_to_string (x0,y0,x1,y1) =
3766 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3769 let makecheckers () =
3770 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3772 converted by Issac Trotts. July 25, 2002 *)
3773 let image_height = 64
3774 and image_width
= 64 in
3778 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3780 for i
= 0 to image_width
- 1 do
3781 for j
= 0 to image_height - 1 do
3782 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3783 (if (i
land 8 ) lxor (j
land 8) = 0
3784 then [|255;255;255|] else [|200;200;200|])
3789 let image = make_image () in
3790 let id = GlTex.gen_texture
() in
3791 GlTex.bind_texture `texture_2d
id;
3792 GlPix.store
(`unpack_alignment
1);
3793 GlTex.image2d
image;
3794 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3797 `mag_filter `nearest
;
3798 `min_filter `nearest
];
3802 let setcheckers enabled
=
3803 match state.texid
with
3805 if enabled
then state.texid
<- Some
(makecheckers ())
3810 GlTex.delete_texture texid
;
3811 state.texid
<- None
;
3815 let int_of_string_with_suffix s =
3816 let l = String.length
s in
3820 let suffix = Char.lowercase
s.[l-1] in
3822 | 'k'
-> String.sub
s 0 (l-1), 10
3823 | '
m'
-> String.sub
s 0 (l-1), 20
3824 | 'g'
-> String.sub
s 0 (l-1), 30
3828 let n = int_of_string
s1 in
3829 let m = n lsl shift
in
3831 then raise
(Failure
"value too large")
3835 let string_with_suffix_of_int n =
3843 if n land ((1 lsl 20) - 1) = 0
3846 if n land ((1 lsl 10) - 1) = 0
3853 let h = n mod 1000 in
3856 then string_of_int
h ^
s
3858 let s = Printf.sprintf
"_%03d%s" h s in
3865 let defghyllscroll = (40, 8, 32);;
3866 let ghyllscroll_of_string s =
3867 let (n, a, b) as nab
=
3870 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3872 if n <= a || n <= b || a >= b
3873 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3877 let ghyllscroll_to_string ((n, a, b) as nab
) =
3878 if nab
= defghyllscroll
3880 else Printf.sprintf
"%d,%d,%d" n a b;
3883 let describe_location () =
3885 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3887 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3888 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3892 else (100. *. (float state.y /. float maxy))
3896 Printf.sprintf
"page %d of %d [%.2f%%]"
3897 (fn+1) state.pagecount
percent
3900 "pages %d-%d of %d [%.2f%%]"
3901 (fn+1) (ln
+1) state.pagecount
percent
3905 let btos b = if b then "\xe2\x88\x9a" else "" in
3906 let showextended = ref false in
3907 let leave mode = function
3908 | Confirm
-> state.mode <- mode
3909 | Cancel
-> state.mode <- mode in
3912 val mutable m_first_time
= true
3913 val mutable m_l
= []
3914 val mutable m_a
= [||]
3915 val mutable m_prev_uioh
= nouioh
3916 val mutable m_prev_mode
= View
3918 inherit lvsourcebase
3920 method reset prev_mode prev_uioh
=
3921 m_a
<- Array.of_list
(List.rev m_l
);
3923 m_prev_mode
<- prev_mode
;
3924 m_prev_uioh
<- prev_uioh
;
3928 if n >= Array.length m_a
3932 | _, _, _, Action
_ -> m_active
<- n
3936 m_first_time
<- false;
3939 method int name get
set =
3941 (name
, `
int get
, 1, Action
(
3944 try set (int_of_string
s)
3946 state.text <- Printf.sprintf
"bad integer `%s': %s"
3947 s (Printexc.to_string exn
)
3950 let te = name ^
": ", "", None
, intentry, ondone in
3951 state.mode <- Textentry
(te, leave m_prev_mode
);
3955 method int_with_suffix name get
set =
3957 (name
, `intws get
, 1, Action
(
3960 try set (int_of_string_with_suffix s)
3962 state.text <- Printf.sprintf
"bad integer `%s': %s"
3963 s (Printexc.to_string exn
)
3967 name ^
": ", "", None
, intentry_with_suffix, ondone
3969 state.mode <- Textentry
(te, leave m_prev_mode
);
3973 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3975 (name
, `
bool (btos, get
), offset
, Action
(
3982 method color name get
set =
3984 (name
, `color get
, 1, Action
(
3986 let invalid = (nan
, nan
, nan
) in
3989 try color_of_string s
3991 state.text <- Printf.sprintf
"bad color `%s': %s"
3992 s (Printexc.to_string exn
);
3998 let te = name ^
": ", "", None
, textentry, ondone in
3999 state.text <- color_to_string (get
());
4000 state.mode <- Textentry
(te, leave m_prev_mode
);
4004 method string name get
set =
4006 (name
, `
string get
, 1, Action
(
4008 let ondone s = set s in
4009 let te = name ^
": ", "", None
, textentry, ondone in
4010 state.mode <- Textentry
(te, leave m_prev_mode
);
4014 method colorspace name get
set =
4016 (name
, `
string get
, 1, Action
(
4019 let vals = [| "rgb"; "bgr"; "gray" |] in
4021 inherit lvsourcebase
4024 m_active
<- int_of_colorspace conf.colorspace
;
4027 method getitemcount
= Array.length
vals
4028 method getitem
n = (vals.(n), 0)
4029 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4030 ignore
(uioh
, first, pan
, qsearch);
4031 if not cancel
then set active;
4033 method hasaction
_ = true
4037 let modehash = findkeyhash conf "info" in
4038 coe (new listview ~
source ~trusted
:true ~
modehash)
4041 method caption
s offset
=
4042 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4044 method caption2
s f offset
=
4045 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4047 method getitemcount
= Array.length m_a
4050 let tostr = function
4051 | `
int f -> string_of_int
(f ())
4052 | `intws
f -> string_with_suffix_of_int (f ())
4054 | `color
f -> color_to_string (f ())
4055 | `
bool (btos, f) -> btos (f ())
4058 let name, t
, offset
, _ = m_a
.(n) in
4059 ((let s = tostr t
in
4060 if String.length
s > 0
4061 then Printf.sprintf
"%s\t%s" name s
4065 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4069 m_qsearch
<- qsearch;
4071 match m_a
.(active) with
4072 | _, _, _, Action
f -> f uioh
4084 method hasaction
n =
4086 | _, _, _, Action
_ -> true
4090 let rec fillsrc prevmode prevuioh
=
4091 let sep () = src#caption
"" 0 in
4092 let colorp name get
set =
4094 (fun () -> color_to_string (get
()))
4097 let c = color_of_string v in
4100 state.text <- Printf.sprintf
"bad color `%s': %s"
4101 v (Printexc.to_string exn
);
4104 let oldmode = state.mode in
4105 let birdseye = isbirdseye state.mode in
4107 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4109 src#
bool "presentation mode"
4110 (fun () -> conf.presentation)
4112 conf.presentation <- v;
4113 state.anchor <- getanchor ();
4116 src#
bool "ignore case in searches"
4117 (fun () -> conf.icase
)
4118 (fun v -> conf.icase
<- v);
4121 (fun () -> conf.preload)
4122 (fun v -> conf.preload <- v);
4124 src#
bool "highlight links"
4125 (fun () -> conf.hlinks
)
4126 (fun v -> conf.hlinks
<- v);
4128 src#
bool "under info"
4129 (fun () -> conf.underinfo
)
4130 (fun v -> conf.underinfo
<- v);
4132 src#
bool "persistent bookmarks"
4133 (fun () -> conf.savebmarks
)
4134 (fun v -> conf.savebmarks
<- v);
4136 src#
bool "proportional display"
4137 (fun () -> conf.proportional
)
4138 (fun v -> reqlayout conf.angle
v);
4140 src#
bool "trim margins"
4141 (fun () -> conf.trimmargins
)
4142 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4144 src#
bool "persistent location"
4145 (fun () -> conf.jumpback
)
4146 (fun v -> conf.jumpback
<- v);
4149 src#
int "inter-page space"
4150 (fun () -> conf.interpagespace)
4152 conf.interpagespace <- n;
4153 docolumns conf.columns
;
4155 match state.layout with
4160 state.maxy <- calcheight ();
4161 let y = getpagey pageno in
4166 (fun () -> conf.pagebias
)
4167 (fun v -> conf.pagebias
<- v);
4169 src#
int "scroll step"
4170 (fun () -> conf.scrollstep
)
4171 (fun n -> conf.scrollstep
<- n);
4173 src#
int "auto scroll step"
4175 match state.autoscroll
with
4177 | _ -> conf.autoscrollstep
)
4179 if state.autoscroll
<> None
4180 then state.autoscroll
<- Some
n;
4181 conf.autoscrollstep
<- n);
4184 (fun () -> truncate
(conf.zoom *. 100.))
4185 (fun v -> setzoom ((float v) /. 100.));
4188 (fun () -> conf.angle
)
4189 (fun v -> reqlayout v conf.proportional
);
4191 src#
int "scroll bar width"
4192 (fun () -> state.scrollw
)
4196 reshape conf.winw
conf.winh
;
4199 src#
int "scroll handle height"
4200 (fun () -> conf.scrollh
)
4201 (fun v -> conf.scrollh
<- v;);
4203 src#
int "thumbnail width"
4204 (fun () -> conf.thumbw
)
4206 conf.thumbw
<- min
4096 v;
4209 leavebirdseye beye
false;
4214 let mode = state.mode in
4215 src#
string "columns"
4217 match conf.columns
with
4219 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4220 | Csplit
(count
, _) -> "-" ^ string_of_int count
4223 let n, a, b = multicolumns_of_string v in
4224 setcolumns mode n a b);
4227 src#caption
"Presentation mode" 0;
4228 src#
bool "scrollbar visible"
4229 (fun () -> conf.scrollbarinpm
)
4231 if v != conf.scrollbarinpm
4233 conf.scrollbarinpm
<- v;
4234 if conf.presentation
4236 state.scrollw
<- if v then conf.scrollbw
else 0;
4237 reshape conf.winw
conf.winh
;
4243 src#caption
"Pixmap cache" 0;
4244 src#int_with_suffix
"size (advisory)"
4245 (fun () -> conf.memlimit
)
4246 (fun v -> conf.memlimit
<- v);
4249 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4250 (string_with_suffix_of_int state.memused
)
4251 (Hashtbl.length
state.tilemap
)) 1;
4254 src#caption
"Layout" 0;
4255 src#caption2
"Dimension"
4257 Printf.sprintf
"%dx%d (virtual %dx%d)"
4263 src#caption2
"Position" (fun () ->
4264 Printf.sprintf
"%dx%d" state.x state.y
4267 src#caption2
"Visible" (fun () -> describe_location ()) 1
4271 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4272 "Save these parameters as global defaults at exit"
4273 (fun () -> conf.bedefault
)
4274 (fun v -> conf.bedefault
<- v)
4278 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4279 src#
bool ~offset
:0 ~
btos "Extended parameters"
4280 (fun () -> !showextended)
4281 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4285 (fun () -> conf.checkers
)
4286 (fun v -> conf.checkers
<- v; setcheckers v);
4287 src#
bool "update cursor"
4288 (fun () -> conf.updatecurs
)
4289 (fun v -> conf.updatecurs
<- v);
4291 (fun () -> conf.verbose
)
4292 (fun v -> conf.verbose
<- v);
4293 src#
bool "invert colors"
4294 (fun () -> conf.invert
)
4295 (fun v -> conf.invert
<- v);
4297 (fun () -> conf.maxhfit
)
4298 (fun v -> conf.maxhfit
<- v);
4299 src#
bool "redirect stderr"
4300 (fun () -> conf.redirectstderr)
4301 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4302 src#
string "uri launcher"
4303 (fun () -> conf.urilauncher
)
4304 (fun v -> conf.urilauncher
<- v);
4305 src#
string "path launcher"
4306 (fun () -> conf.pathlauncher
)
4307 (fun v -> conf.pathlauncher
<- v);
4308 src#
string "tile size"
4309 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4312 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4313 conf.tilew
<- max
64 w;
4314 conf.tileh
<- max
64 h;
4317 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4318 v (Printexc.to_string exn
));
4319 src#
int "texture count"
4320 (fun () -> conf.texcount
)
4323 then conf.texcount
<- v
4324 else showtext '
!'
" Failed to set texture count please retry later"
4326 src#
int "slice height"
4327 (fun () -> conf.sliceheight
)
4329 conf.sliceheight
<- v;
4330 wcmd "sliceh %d" conf.sliceheight
;
4332 src#
int "anti-aliasing level"
4333 (fun () -> conf.aalevel
)
4335 conf.aalevel
<- bound v 0 8;
4336 state.anchor <- getanchor ();
4337 opendoc state.path
state.password
;
4339 src#
int "ui font size"
4340 (fun () -> fstate.fontsize
)
4341 (fun v -> setfontsize (bound v 5 100));
4342 src#
int "hint font size"
4343 (fun () -> conf.hfsize
)
4344 (fun v -> conf.hfsize
<- bound v 5 100);
4345 colorp "background color"
4346 (fun () -> conf.bgcolor
)
4347 (fun v -> conf.bgcolor
<- v);
4348 src#
bool "crop hack"
4349 (fun () -> conf.crophack
)
4350 (fun v -> conf.crophack
<- v);
4351 src#
string "trim fuzz"
4352 (fun () -> irect_to_string conf.trimfuzz
)
4355 conf.trimfuzz
<- irect_of_string v;
4357 then settrim true conf.trimfuzz
;
4359 state.text <- Printf.sprintf
"bad irect `%s': %s"
4360 v (Printexc.to_string exn
)
4362 src#
string "throttle"
4364 match conf.maxwait
with
4365 | None
-> "show place holder if page is not ready"
4368 then "wait for page to fully render"
4370 "wait " ^ string_of_float
time
4371 ^
" seconds before showing placeholder"
4375 let f = float_of_string
v in
4377 then conf.maxwait
<- None
4378 else conf.maxwait
<- Some
f
4380 state.text <- Printf.sprintf
"bad time `%s': %s"
4381 v (Printexc.to_string exn
)
4383 src#
string "ghyll scroll"
4385 match conf.ghyllscroll
with
4387 | Some nab
-> ghyllscroll_to_string nab
4392 if String.length
v = 0
4394 else Some
(ghyllscroll_of_string v)
4396 conf.ghyllscroll
<- gs
4398 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4399 v (Printexc.to_string exn
)
4401 src#
string "selection command"
4402 (fun () -> conf.selcmd
)
4403 (fun v -> conf.selcmd
<- v);
4404 src#colorspace
"color space"
4405 (fun () -> colorspace_to_string conf.colorspace
)
4407 conf.colorspace
<- colorspace_of_int v;
4414 src#caption
"Document" 0;
4415 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4416 src#caption2
"Pages"
4417 (fun () -> string_of_int
state.pagecount
) 1;
4418 src#caption2
"Dimensions"
4419 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4423 src#caption
"Trimmed margins" 0;
4424 src#caption2
"Dimensions"
4425 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4428 src#reset prevmode prevuioh
;
4432 let prevmode = state.mode
4433 and prevuioh
= state.uioh in
4434 fillsrc prevmode prevuioh
;
4435 let source = (src :> lvsource
) in
4436 let modehash = findkeyhash conf "info" in
4437 state.uioh <- coe (object (self)
4438 inherit listview ~
source ~trusted
:true ~
modehash as super
4439 val mutable m_prevmemused
= 0
4440 method infochanged
= function
4442 if m_prevmemused
!= state.memused
4444 m_prevmemused
<- state.memused
;
4445 G.postRedisplay "memusedchanged";
4447 | Pdim
-> G.postRedisplay "pdimchanged"
4448 | Docinfo
-> fillsrc prevmode prevuioh
4450 method key key mask
=
4451 if not
(Wsi.withctrl mask
)
4454 | 0xff51 -> coe (self#updownlevel ~
-1)
4455 | 0xff53 -> coe (self#updownlevel
1)
4456 | _ -> super#
key key mask
4457 else super#
key key mask
4459 G.postRedisplay "info";
4465 inherit lvsourcebase
4466 method getitemcount
= Array.length
state.help
4468 let s, n, _ = state.help
.(n) in
4471 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4475 m_qsearch
<- qsearch;
4476 match state.help
.(active) with
4477 | _, _, Action
f -> Some
(f uioh)
4487 method hasaction
n =
4488 match state.help
.(n) with
4489 | _, _, Action
_ -> true
4496 let modehash = findkeyhash conf "help" in
4497 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4498 G.postRedisplay "help";
4503 let re = Str.regexp
"[\r\n]" in
4505 inherit lvsourcebase
4506 val mutable m_items
= [||]
4508 method getitemcount
= 1 + Array.length m_items
4513 else m_items
.(n-1), 0
4515 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4520 then Buffer.clear
state.errmsgs
;
4521 m_qsearch
<- qsearch;
4528 method hasaction
n =
4532 state.newerrmsgs
<- false;
4533 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4534 m_items
<- Array.of_list
l
4542 let source = (msgsource :> lvsource
) in
4543 let modehash = findkeyhash conf "listview" in
4544 state.uioh <- coe (object
4545 inherit listview ~
source ~trusted
:false ~
modehash as super
4548 then msgsource#reset
;
4551 G.postRedisplay "msgs";
4554 let quickbookmark ?title
() =
4555 match state.layout with
4561 let sec = Unix.gettimeofday
() in
4562 let tm = Unix.localtime
sec in
4563 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4567 (tm.Unix.tm_year
+ 1900)
4570 | Some
title -> title
4573 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4578 state.fullscreen
<- None
;
4582 let setautoscrollspeed step goingdown
=
4583 let incr = max
1 ((abs step
) / 2) in
4584 let incr = if goingdown
then incr else -incr in
4585 let astep = step
+ incr in
4586 state.autoscroll
<- Some
astep;
4589 let gotounder = function
4590 | Ulinkgoto
(pageno, top) ->
4594 gotopage1 pageno top;
4600 | Uremote
(filename
, pageno) ->
4602 if Sys.file_exists filename
4605 let dir = Filename.dirname
state.path in
4606 let path = Filename.concat
dir filename
in
4607 if Sys.file_exists
path
4611 if String.length
path > 0
4613 let anchor = getanchor () in
4614 let ranchor = state.path, state.password
, anchor in
4615 state.anchor <- (pageno, 0.0);
4616 state.ranchors
<- ranchor :: state.ranchors
;
4619 else showtext '
!'
("Could not find " ^ filename
)
4621 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4625 match conf.columns
with
4627 | _ -> conf.zoom > 1.0
4630 let viewkeyboard key mask
=
4632 let mode = state.mode in
4633 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4636 G.postRedisplay "view:enttext"
4638 let ctrl = Wsi.withctrl mask
in
4643 | 0xff63 -> (* insert *)
4644 if conf.angle
mod 360 = 0
4646 state.mode <- LinkNav
(Ltgendir
0);
4649 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4651 | 0xff1b | 113 -> (* escape / q *)
4652 begin match state.mstate
with
4654 state.mstate
<- Mnone
;
4655 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4656 G.postRedisplay "kill zoom rect";
4658 match state.ranchors
with
4660 | (path, password
, anchor) :: rest
->
4661 state.ranchors
<- rest
;
4662 state.anchor <- anchor;
4663 opendoc path password
4666 | 0xff08 -> (* backspace *)
4667 let y = getnav ~
-1 in
4668 gotoy_and_clear_text y
4676 G.postRedisplay "dehighlight";
4678 | 47 | 63 -> (* / ? *)
4679 let ondone isforw
s =
4680 cbput state.hists
.pat
s;
4681 state.searchpattern
<- s;
4684 let s = String.create
1 in
4685 s.[0] <- Char.chr
key;
4686 enttext (s, "", Some
(onhist state.hists
.pat
),
4687 textentry, ondone (key = 47))
4689 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4690 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4691 setzoom (conf.zoom +. incr)
4693 | 43 | 0xffab -> (* + *)
4696 try int_of_string
s with exc
->
4697 state.text <- Printf.sprintf
"bad integer `%s': %s"
4698 s (Printexc.to_string exc
);
4704 state.text <- "page bias is now " ^ string_of_int
n;
4707 enttext ("page bias: ", "", None
, intentry, ondone)
4709 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4710 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4711 setzoom (max
0.01 (conf.zoom -. decr))
4713 | 45 | 0xffad -> (* - *)
4714 let ondone msg
= state.text <- msg
in
4716 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4717 optentry state.mode, ondone
4720 | 48 when ctrl -> (* ctrl-0 *)
4723 | 49 when ctrl -> (* 1 *)
4724 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4728 | 0xffc6 -> (* f9 *)
4731 | 57 when ctrl -> (* ctrl-9 *)
4734 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4735 when not
ctrl -> (* 0..9 *)
4738 try int_of_string
s with exc
->
4739 state.text <- Printf.sprintf
"bad integer `%s': %s"
4740 s (Printexc.to_string exc
);
4746 cbput state.hists
.pag
(string_of_int
n);
4747 gotopage1 (n + conf.pagebias
- 1) 0;
4750 let pageentry text key =
4751 match Char.unsafe_chr
key with
4752 | 'g'
-> TEdone
text
4753 | _ -> intentry text key
4755 let text = "x" in text.[0] <- Char.chr
key;
4756 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4759 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4760 reshape conf.winw
conf.winh
;
4763 conf.hlinks
<- not
conf.hlinks
;
4764 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4765 G.postRedisplay "toggle highlightlinks";
4768 state.glinks
<- true;
4769 let mode = state.mode in
4770 state.mode <- Textentry
(
4771 (":", "", None
, linknentry, linkndone (fun under ->
4776 state.glinks
<- false;
4780 G.postRedisplay "view:linkent(F)"
4783 state.glinks
<- true;
4784 let mode = state.mode in
4785 state.mode <- Textentry
(
4786 (":", "", None
, linknentry, linkndone (fun under ->
4787 match Ne.pipe () with
4789 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4790 (Printexc.to_string exn
));
4793 try popen conf.selcmd
[r, 0; w, -1]; true
4796 (Printf.sprintf
"failed to execute %s: %s"
4797 conf.selcmd
(Printexc.to_string exn
));
4801 Ne.clo fd
(fun msg
->
4802 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4805 let s = undertext under in
4809 let l = String.length
s in
4810 let n = Unix.write
w s 0 l in
4815 "failed to write %d characters to sel pipe, wrote %d"
4820 (Printf.sprintf
"failed to write to sel pipe: %s"
4821 (Printexc.to_string exn
)
4830 state.glinks
<- false;
4834 G.postRedisplay "view:linkent"
4837 begin match state.autoscroll
with
4839 conf.autoscrollstep
<- step
;
4840 state.autoscroll
<- None
4842 if conf.autoscrollstep
= 0
4843 then state.autoscroll
<- Some
1
4844 else state.autoscroll
<- Some
conf.autoscrollstep
4847 | 112 when ctrl -> (* ctrl-p *)
4851 conf.presentation <- not
conf.presentation;
4852 if conf.presentation
4854 if not
conf.scrollbarinpm
4855 then state.scrollw
<- 0;
4858 state.scrollw
<- conf.scrollbw
;
4860 showtext ' '
("presentation mode " ^
4861 if conf.presentation then "on" else "off");
4862 state.anchor <- getanchor ();
4866 begin match state.fullscreen
with
4868 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4871 state.fullscreen
<- None
;
4876 gotoy_and_clear_text 0
4879 gotopage1 (state.pagecount
- 1) 0
4881 | 112 | 78 -> (* p|N *)
4882 search state.searchpattern
false
4884 | 110 | 0xffc0 -> (* n|F3 *)
4885 search state.searchpattern
true
4888 begin match state.layout with
4891 gotoy_and_clear_text (getpagey l.pageno)
4895 begin match List.rev
state.layout with
4898 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4899 gotoy_and_clear_text (getpagey pageno)
4902 | 0xff9f | 0xffff -> (* delete *)
4903 begin match state.layout with
4906 let pageno = max
0 (l.pageno-1) in
4907 gotoy_and_clear_text (getpagey pageno)
4911 showtext ' '
(describe_location ());
4914 begin match state.layout with
4917 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4922 enterbookmarkmode ()
4924 | 104 | 0xffbe -> (* h|F1 *)
4930 | 101 when conf.redirectstderr -> (* e *)
4935 match state.layout with
4938 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4942 enttext ("bookmark: ", "", None
, textentry, ondone)
4946 showtext ' '
"Quick bookmark added";
4949 begin match state.layout with
4951 let rect = getpdimrect
l.pagedimno
in
4955 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4956 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4958 (truncate
(rect.(1) -. rect.(0)),
4959 truncate
(rect.(3) -. rect.(0)))
4961 let w = truncate
((float w)*.conf.zoom)
4962 and h = truncate
((float h)*.conf.zoom) in
4965 state.anchor <- getanchor ();
4966 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4968 G.postRedisplay "z";
4973 | 50 when ctrl -> (* ctrl-2 *)
4974 let maxw = getmaxw
() in
4976 then setzoom (maxw /. float conf.winw
)
4978 | 60 | 62 -> (* < > *)
4979 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4981 | 91 | 93 -> (* [ ] *)
4983 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4985 G.postRedisplay "brightness";
4987 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4988 setzoom state.prevzoom
4990 | 107 | 0xff52 -> (* k up *)
4991 begin match state.autoscroll
with
4993 begin match state.mode with
4994 | Birdseye beye
-> upbirdseye 1 beye
4997 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4998 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5001 setautoscrollspeed n false
5004 | 106 | 0xff54 -> (* j down *)
5005 begin match state.autoscroll
with
5007 begin match state.mode with
5008 | Birdseye beye
-> downbirdseye 1 beye
5011 then gotoy_and_clear_text (clamp (conf.winh
/2))
5012 else gotoy_and_clear_text (clamp conf.scrollstep
)
5015 setautoscrollspeed n true
5018 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5026 let dx = if key = 0xff51 then dx else -dx in
5027 state.x <- state.x + dx;
5028 gotoy_and_clear_text state.y
5031 G.postRedisplay "lef/right"
5034 | 0xff55 -> (* prior *)
5038 match state.layout with
5040 | l :: _ -> state.y - l.pagey
5046 | 0xff56 -> (* next *)
5050 match List.rev
state.layout with
5052 | l :: _ -> getpagey l.pageno
5058 | 0xff50 -> gotoghyll 0
5059 | 0xff57 -> gotoghyll (clamp state.maxy)
5060 | 0xff53 when Wsi.withalt mask
->
5061 gotoghyll (getnav ~
-1)
5062 | 0xff51 when Wsi.withalt mask
->
5063 gotoghyll (getnav 1)
5066 state.anchor <- getanchor ();
5067 opendoc state.path state.password
5069 | 118 when conf.debug
-> (* v *)
5072 match getopaque l.pageno with
5075 let x0, y0, x1, y1 = pagebbox opaque
in
5076 let a,b = float x0, float y0 in
5077 let c,d = float x1, float y0 in
5078 let e,f = float x1, float y1 in
5079 let h,j
= float x0, float y1 in
5080 let rect = (a,b,c,d,e,f,h,j
) in
5082 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5084 G.postRedisplay "v";
5087 vlog "huh? %s" (Wsi.keyname
key)
5090 let linknavkeyboard key mask
linknav =
5091 let getpage pageno =
5092 let rec loop = function
5094 | l :: _ when l.pageno = pageno -> Some
l
5095 | _ :: rest
-> loop rest
5096 in loop state.layout
5098 let doexact (pageno, n) =
5099 match getopaque pageno, getpage pageno with
5100 | Some opaque
, Some
l ->
5103 let under = getlink opaque
n in
5104 G.postRedisplay "link gotounder";
5110 | 0xff50 -> (* home *)
5111 Some
(findlink opaque LDfirst
), -1
5113 | 0xff57 -> (* end *)
5114 Some
(findlink opaque LDlast
), 1
5116 | 0xff51 -> (* left *)
5117 Some
(findlink opaque
(LDleft
n)), -1
5119 | 0xff53 -> (* right *)
5120 Some
(findlink opaque
(LDright
n)), 1
5122 | 0xff52 -> (* up *)
5123 Some
(findlink opaque
(LDup
n)), -1
5125 | 0xff54 -> (* down *)
5126 Some
(findlink opaque
(LDdown
n)), 1
5131 begin match findpwl
l.pageno dir with
5135 state.mode <- LinkNav
(Ltgendir
dir);
5136 let y, h = getpageyh pageno in
5139 then y + h - conf.winh
5144 begin match getopaque pageno, getpage pageno with
5145 | Some opaque
, Some
_ ->
5147 let ld = if dir > 0 then LDfirst
else LDlast
in
5150 begin match link with
5152 showlinktype (getlink opaque
m);
5153 state.mode <- LinkNav
(Ltexact
(pageno, m));
5154 G.postRedisplay "linknav jpage";
5161 begin match opt with
5162 | Some Lnotfound
-> pwl l dir;
5163 | Some
(Lfound
m) ->
5167 let _, y0, _, y1 = getlinkrect opaque
m in
5169 then gotopage1 l.pageno y0
5171 let d = fstate.fontsize
+ 1 in
5172 if y1 - l.pagey > l.pagevh - d
5173 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5174 else G.postRedisplay "linknav";
5176 showlinktype (getlink opaque
m);
5177 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5180 | None
-> viewkeyboard key mask
5182 | _ -> viewkeyboard key mask
5187 G.postRedisplay "leave linknav"
5191 | Ltgendir
_ -> viewkeyboard key mask
5192 | Ltexact exact
-> doexact exact
5195 let keyboard key mask
=
5196 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5197 then wcmd "interrupt"
5198 else state.uioh <- state.uioh#
key key mask
5201 let birdseyekeyboard key mask
5202 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5204 match conf.columns
with
5206 | Cmulti
((c, _, _), _) -> c
5207 | Csplit
_ -> failwith
"bird's eye split mode"
5210 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5211 let y, h = getpageyh pageno in
5212 let top = (conf.winh
- h) / 2 in
5213 gotoy (max
0 (y - top))
5214 | 0xff0d -> leavebirdseye beye
false
5215 | 0xff1b -> leavebirdseye beye
true (* escape *)
5216 | 0xff52 -> upbirdseye incr beye
(* prior *)
5217 | 0xff54 -> downbirdseye incr beye
(* next *)
5218 | 0xff51 -> upbirdseye 1 beye
(* up *)
5219 | 0xff53 -> downbirdseye 1 beye
(* down *)
5222 begin match state.layout with
5226 state.mode <- Birdseye
(
5227 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5229 gotopage1 l.pageno 0;
5232 let layout = layout (state.y-conf.winh
) conf.winh
in
5234 | [] -> gotoy (clamp (-conf.winh
))
5236 state.mode <- Birdseye
(
5237 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5239 gotopage1 l.pageno 0
5242 | [] -> gotoy (clamp (-conf.winh
))
5246 begin match List.rev
state.layout with
5248 let layout = layout (state.y + conf.winh
) conf.winh
in
5249 begin match layout with
5251 let incr = l.pageh
- l.pagevh in
5256 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5258 G.postRedisplay "birdseye pagedown";
5260 else gotoy (clamp (incr + conf.interpagespace*2));
5264 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5265 gotopage1 l.pageno 0;
5268 | [] -> gotoy (clamp conf.winh
)
5272 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5276 let pageno = state.pagecount
- 1 in
5277 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5278 if not
(pagevisible state.layout pageno)
5281 match List.rev
state.pdims
with
5283 | (_, _, h, _) :: _ -> h
5285 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5286 else G.postRedisplay "birdseye end";
5287 | _ -> viewkeyboard key mask
5290 let drawpage l linkindexbase
=
5292 match state.mode with
5293 | Textentry
_ -> scalecolor 0.4
5295 | View
-> scalecolor 1.0
5296 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5297 if l.pageno = hooverpageno
5300 if l.pageno = pageno
5306 begin match getopaque l.pageno with
5308 if tileready l l.pagex l.pagey
5310 let x = l.pagedispx - l.pagex
5311 and y = l.pagedispy - l.pagey in
5312 let hlmask = (if conf.hlinks
then 1 else 0)
5313 + (if state.glinks
&& not
(isbirdseye state.mode) then 2 else 0)
5316 match state.mode with
5317 | Textentry
((_, s, _, _, _), _) when state.glinks
-> s
5320 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5327 let scrollindicator () =
5328 let sbw, ph
, sh = state.uioh#
scrollph in
5329 let sbh, pw, sw = state.uioh#scrollpw
in
5331 GlDraw.color (0.64, 0.64, 0.64);
5333 (float (conf.winw
- sbw), 0.)
5334 (float conf.winw
, float conf.winh
)
5337 (0., float (conf.winh
- sbh))
5338 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5340 GlDraw.color (0.0, 0.0, 0.0);
5343 (float (conf.winw
- sbw), ph
)
5344 (float conf.winw
, ph
+. sh)
5347 (pw, float (conf.winh
- sbh))
5348 (pw +. sw, float conf.winh
)
5353 match state.mstate
with
5354 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5357 | Msel
((x0, y0), (x1, y1)) ->
5358 let rec loop = function
5360 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5361 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5362 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5363 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5365 match getopaque l.pageno with
5367 let x0, y0 = pagetranslatepoint l x0 y0 in
5368 let x1, y1 = pagetranslatepoint l x1 y1 in
5369 seltext opaque
(x0, y0, x1, y1);
5377 let showrects rects
=
5379 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5380 GlDraw.polygon_mode `both `fill
;
5381 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5383 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5385 if l.pageno = pageno
5387 let dx = float (l.pagedispx - l.pagex) in
5388 let dy = float (l.pagedispy - l.pagey) in
5389 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5390 GlDraw.begins `quads
;
5392 GlDraw.vertex2
(x0+.dx, y0+.dy);
5393 GlDraw.vertex2
(x1+.dx, y1+.dy);
5394 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5395 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5406 GlClear.color (scalecolor2 conf.bgcolor
);
5407 GlClear.clear
[`
color];
5408 let rec loop linkindexbase
= function
5410 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5411 loop linkindexbase rest
5414 loop 0 state.layout;
5416 match state.mode with
5417 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5418 begin match getopaque pageno with
5420 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5427 | None
-> state.rects
5434 begin match state.mstate
with
5435 | Mzoomrect
((x0, y0), (x1, y1)) ->
5437 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5438 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5439 GlDraw.rect (float x0, float y0)
5440 (float x1, float y1);
5449 let zoomrect x y x1 y1 =
5452 and y0 = min
y y1 in
5453 gotoy (state.y + y0);
5454 state.anchor <- getanchor ();
5455 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5457 if state.w < conf.winw
- state.scrollw
5458 then (conf.winw
- state.scrollw
- state.w) / 2
5461 state.x <- (state.x + margin) - x0;
5463 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5464 state.mstate
<- Mnone
;
5468 let winw = conf.winw - state.scrollw
- 1 in
5469 let s = float x /. float winw in
5470 let destx = truncate
(float (state.w + winw) *. s) in
5471 state.x <- winw - destx;
5472 gotoy_and_clear_text state.y;
5473 state.mstate
<- Mscrollx
;
5477 let s = float y /. float conf.winh
in
5478 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5479 gotoy_and_clear_text desty;
5480 state.mstate
<- Mscrolly
;
5483 let viewmouse button down
x y mask
=
5485 | n when (n == 4 || n == 5) && not down
->
5486 if Wsi.withctrl mask
5488 match state.mstate
with
5489 | Mzoom
(oldn
, i
) ->
5497 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5499 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5501 let zoom = conf.zoom -. incr in
5503 state.mstate
<- Mzoom
(n, 0);
5505 state.mstate
<- Mzoom
(n, i
+1);
5507 else state.mstate
<- Mzoom
(n, 0)
5509 | _ -> state.mstate
<- Mzoom
(n, 0)
5512 match state.autoscroll
with
5513 | Some step
-> setautoscrollspeed step
(n=4)
5517 then -conf.scrollstep
5518 else conf.scrollstep
5520 let incr = incr * 2 in
5521 let y = clamp incr in
5522 gotoy_and_clear_text y
5525 | 1 when Wsi.withctrl mask
->
5528 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5529 state.mstate
<- Mpan
(x, y)
5532 state.mstate
<- Mnone
5537 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5539 state.mstate
<- Mzoomrect
(p, p)
5542 match state.mstate
with
5543 | Mzoomrect
((x0, y0), _) ->
5544 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5545 then zoomrect x0 y0 x y
5547 state.mstate
<- Mnone
;
5548 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5549 G.postRedisplay "kill accidental zoom rect";
5552 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5553 state.mstate
<- Mnone
5556 | 1 when x > conf.winw - state.scrollw
->
5559 let _, position, sh = state.uioh#
scrollph in
5560 if y > truncate
position && y < truncate
(position +. sh)
5561 then state.mstate
<- Mscrolly
5564 state.mstate
<- Mnone
5566 | 1 when y > conf.winh
- state.hscrollh ->
5569 let _, position, sw = state.uioh#scrollpw
in
5570 if x > truncate
position && x < truncate
(position +. sw)
5571 then state.mstate
<- Mscrollx
5574 state.mstate
<- Mnone
5577 let dest = if down
then getunder x y else Unone
in
5578 begin match dest with
5582 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5585 | Unone
when down
->
5586 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5587 state.mstate
<- Mpan
(x, y);
5589 | Unone
| Utext
_ ->
5592 if conf.angle
mod 360 = 0
5594 state.mstate
<- Msel
((x, y), (x, y));
5595 G.postRedisplay "mouse select";
5599 match state.mstate
with
5602 | Mzoom
_ | Mscrollx
| Mscrolly
->
5603 state.mstate
<- Mnone
5605 | Mzoomrect
((x0, y0), _) ->
5609 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5610 state.mstate
<- Mnone
5612 | Msel
((_, y0), (_, y1)) ->
5613 let rec loop = function
5616 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5617 || ((y1 >= l.pagedispy
5618 && y1 <= (l.pagedispy + l.pagevh)))
5620 match getopaque l.pageno with
5623 match Ne.pipe () with
5627 "can not create sel pipe: %s"
5628 (Printexc.to_string exn
));
5630 let doclose what fd
=
5631 Ne.clo fd
(fun msg
->
5632 dolog "%s close failed: %s" what msg
)
5635 popen conf.selcmd
[r, 0; w, -1];
5638 G.postRedisplay "copysel";
5640 dolog "can not exectute %S: %s"
5641 conf.selcmd
(Printexc.to_string exn
);
5649 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5650 state.mstate
<- Mnone
;
5657 let birdseyemouse button down
x y mask
5658 (conf, leftx
, _, hooverpageno
, anchor) =
5661 let rec loop = function
5664 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5665 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5667 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5673 | _ -> viewmouse button down
x y mask
5676 let mouse button down
x y mask
=
5677 state.uioh <- state.uioh#button button down
x y mask
;
5681 state.uioh <- state.uioh#
motion x y
5685 state.uioh <- state.uioh#
pmotion x y;
5691 method key key mask
=
5692 begin match state.mode with
5693 | Textentry
textentry -> textentrykeyboard key mask
textentry
5694 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5695 | View
-> viewkeyboard key mask
5696 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5700 method button button bstate
x y mask
=
5701 begin match state.mode with
5703 | View
-> viewmouse button bstate
x y mask
5704 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5710 begin match state.mode with
5712 | View
| Birdseye
_ | LinkNav
_ ->
5713 match state.mstate
with
5714 | Mzoom
_ | Mnone
-> ()
5719 state.mstate
<- Mpan
(x, y);
5721 then state.x <- state.x + dx;
5723 gotoy_and_clear_text y
5726 state.mstate
<- Msel
(a, (x, y));
5727 G.postRedisplay "motion select";
5730 let y = min
conf.winh
(max
0 y) in
5734 let x = min
conf.winw (max
0 x) in
5737 | Mzoomrect
(p0
, _) ->
5738 state.mstate
<- Mzoomrect
(p0
, (x, y));
5739 G.postRedisplay "motion zoomrect";
5743 method pmotion x y =
5744 begin match state.mode with
5745 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5746 let rec loop = function
5748 if hooverpageno
!= -1
5750 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5751 G.postRedisplay "pmotion birdseye no hoover";
5754 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5755 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5757 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5758 G.postRedisplay "pmotion birdseye hoover";
5768 match state.mstate
with
5769 | Mnone
-> updateunder x y
5770 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5775 method infochanged
_ = ()
5778 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5779 let p, h = scrollph state.y maxy in
5783 let winw = conf.winw - state.scrollw
- 1 in
5784 let fwinw = float winw in
5786 let sw = fwinw /. float state.w in
5787 let sw = fwinw *. sw in
5788 max
sw (float conf.scrollh
)
5791 let f = state.w+winw in
5792 let r = float (winw-state.x) /. float f in
5793 let p = fwinw *. r in
5797 if position +. sw > fwinw
5798 then fwinw -. position
5801 state.hscrollh, position, sw
5805 match state.mode with
5806 | LinkNav
_ -> "links"
5807 | Textentry
_ -> "textentry"
5808 | Birdseye
_ -> "birdseye"
5811 findkeyhash conf modename
5818 let fontpath = ref "";;
5821 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5824 let l = String.length
s in
5825 let b = Buffer.create
l in
5831 try Sys.getenv
"HOME"
5834 ("Can not determine home directory location: " ^
5835 Printexc.to_string exn
);
5839 let modifier_of_string = function
5840 | "alt" -> Wsi.altmask
5841 | "shift" -> Wsi.shiftmask
5842 | "ctrl" | "control" -> Wsi.ctrlmask
5843 | "meta" -> Wsi.metamask
5848 let r = Str.regexp
"-" in
5850 let elems = Str.full_split
r s in
5853 let m1 = modifier_of_string s in
5855 then (Wsi.namekey
s, m)
5858 | Str.Delim
s when n land 1 = 0 -> g s
5860 | Str.Delim
_ -> (k
, m)
5862 let rec loop n k
m = function
5865 let k, m = f n k m x in
5871 let keys_of_string =
5872 let r = Str.regexp
"[ \t]" in
5874 let elems = Str.split
r s in
5875 List.map
key_of_string elems
5878 let copykeyhashes c =
5879 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5882 let config_of c attrs
=
5886 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5887 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5888 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5889 | "preload" -> { c with preload = bool_of_string
v }
5890 | "page-bias" -> { c with pagebias
= int_of_string
v }
5891 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5892 | "auto-scroll-step" ->
5893 { c with autoscrollstep
= max
0 (int_of_string
v) }
5894 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5895 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5898 match String.lowercase
v with
5899 | "true" -> Some infinity
5901 | f -> Some
(float_of_string
f)
5903 { c with maxwait
= mw}
5904 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5905 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5906 | "vertical-margin" ->
5907 { c with interpagespace = max
0 (int_of_string
v) }
5909 let zoom = float_of_string
v /. 100. in
5910 let zoom = max
zoom 0.0 in
5911 { c with zoom = zoom }
5912 | "presentation" -> { c with presentation = bool_of_string
v }
5913 | "rotation-angle" -> { c with angle
= int_of_string
v }
5914 | "width" -> { c with winw = max
20 (int_of_string
v) }
5915 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5916 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5917 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5918 | "pixmap-cache-size" ->
5919 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5920 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5921 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5922 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5923 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5924 | "background-color" -> { c with bgcolor
= color_of_string v }
5925 | "scrollbar-in-presentation" ->
5926 { c with scrollbarinpm
= bool_of_string
v }
5927 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5928 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5929 | "mupdf-store-size" ->
5930 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5931 | "checkers" -> { c with checkers
= bool_of_string
v }
5932 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5933 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5934 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5935 | "uri-launcher" -> { c with urilauncher
= unent v }
5936 | "path-launcher" -> { c with pathlauncher
= unent v }
5937 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5938 | "invert-colors" -> { c with invert
= bool_of_string
v }
5939 | "brightness" -> { c with colorscale
= float_of_string
v }
5940 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5942 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5944 let (n, _, _) as nab
= multicolumns_of_string v in
5946 then { c with columns
= Csplit
(-n, [||]) }
5947 else { c with columns
= Cmulti
(nab
, [||]) }
5948 | "birds-eye-columns" ->
5949 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5950 | "selection-command" -> { c with selcmd
= unent v }
5951 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5952 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
5955 prerr_endline
("Error processing attribute (`" ^
5956 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5959 let rec fold c = function
5962 let c = apply c k v in
5965 fold { c with keyhashes
= copykeyhashes c } attrs
;
5968 let fromstring f pos
n v d =
5971 dolog "Error processing attribute (%S=%S) at %d\n%s"
5972 n v pos
(Printexc.to_string exn
)
5977 let bookmark_of attrs
=
5978 let rec fold title page
rely = function
5979 | ("title", v) :: rest
-> fold v page
rely rest
5980 | ("page", v) :: rest
-> fold title v rely rest
5981 | ("rely", v) :: rest
-> fold title page
v rest
5982 | _ :: rest
-> fold title page
rely rest
5983 | [] -> title, page
, rely
5985 fold "invalid" "0" "0" attrs
5989 let rec fold path page
rely pan
= function
5990 | ("path", v) :: rest
-> fold v page
rely pan rest
5991 | ("page", v) :: rest
-> fold path v rely pan rest
5992 | ("rely", v) :: rest
-> fold path page
v pan rest
5993 | ("pan", v) :: rest
-> fold path page
rely v rest
5994 | _ :: rest
-> fold path page
rely pan rest
5995 | [] -> path, page
, rely, pan
5997 fold "" "0" "0" "0" attrs
6001 let rec fold rs ls
= function
6002 | ("out", v) :: rest
-> fold v ls rest
6003 | ("in", v) :: rest
-> fold rs
v rest
6004 | _ :: rest
-> fold ls rs rest
6010 let setconf dst
src =
6011 dst
.scrollbw
<- src.scrollbw
;
6012 dst
.scrollh
<- src.scrollh
;
6013 dst
.icase
<- src.icase
;
6014 dst
.preload <- src.preload;
6015 dst
.pagebias
<- src.pagebias
;
6016 dst
.verbose
<- src.verbose
;
6017 dst
.scrollstep
<- src.scrollstep
;
6018 dst
.maxhfit
<- src.maxhfit
;
6019 dst
.crophack
<- src.crophack
;
6020 dst
.autoscrollstep
<- src.autoscrollstep
;
6021 dst
.maxwait
<- src.maxwait
;
6022 dst
.hlinks
<- src.hlinks
;
6023 dst
.underinfo
<- src.underinfo
;
6024 dst
.interpagespace <- src.interpagespace;
6025 dst
.zoom <- src.zoom;
6026 dst
.presentation <- src.presentation;
6027 dst
.angle
<- src.angle
;
6028 dst
.winw <- src.winw;
6029 dst
.winh
<- src.winh
;
6030 dst
.savebmarks
<- src.savebmarks
;
6031 dst
.memlimit
<- src.memlimit
;
6032 dst
.proportional
<- src.proportional
;
6033 dst
.texcount
<- src.texcount
;
6034 dst
.sliceheight
<- src.sliceheight
;
6035 dst
.thumbw
<- src.thumbw
;
6036 dst
.jumpback
<- src.jumpback
;
6037 dst
.bgcolor
<- src.bgcolor
;
6038 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6039 dst
.tilew
<- src.tilew
;
6040 dst
.tileh
<- src.tileh
;
6041 dst
.mustoresize
<- src.mustoresize
;
6042 dst
.checkers
<- src.checkers
;
6043 dst
.aalevel
<- src.aalevel
;
6044 dst
.trimmargins
<- src.trimmargins
;
6045 dst
.trimfuzz
<- src.trimfuzz
;
6046 dst
.urilauncher
<- src.urilauncher
;
6047 dst
.colorspace
<- src.colorspace
;
6048 dst
.invert
<- src.invert
;
6049 dst
.colorscale
<- src.colorscale
;
6050 dst
.redirectstderr <- src.redirectstderr;
6051 dst
.ghyllscroll
<- src.ghyllscroll
;
6052 dst
.columns
<- src.columns
;
6053 dst
.beyecolumns
<- src.beyecolumns
;
6054 dst
.selcmd
<- src.selcmd
;
6055 dst
.updatecurs
<- src.updatecurs
;
6056 dst
.pathlauncher
<- src.pathlauncher
;
6057 dst
.keyhashes
<- copykeyhashes src;
6058 dst
.hfsize
<- src.hfsize
;
6062 let h = Hashtbl.create
10 in
6063 let dc = { defconf with angle
= defconf.angle
} in
6064 let rec toplevel v t spos
_ =
6066 | Vdata
| Vcdata
| Vend
-> v
6067 | Vopen
("llppconfig", _, closed
) ->
6070 else { v with f = llppconfig
}
6072 error
"unexpected subelement at top level" s spos
6073 | Vclose
_ -> error
"unexpected close at top level" s spos
6075 and llppconfig
v t spos
_ =
6077 | Vdata
| Vcdata
-> v
6078 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6079 | Vopen
("defaults", attrs
, closed
) ->
6080 let c = config_of dc attrs
in
6084 else { v with f = defaults
}
6086 | Vopen
("ui-font", attrs
, closed
) ->
6087 let rec getsize size
= function
6089 | ("size", v) :: rest
->
6091 fromstring int_of_string spos
"size" v fstate.fontsize
in
6093 | l -> getsize size l
6095 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6098 else { v with f = uifont
(Buffer.create
10) }
6100 | Vopen
("doc", attrs
, closed
) ->
6101 let pathent, spage
, srely
, span
= doc_of attrs
in
6102 let path = unent pathent
6103 and pageno = fromstring int_of_string spos
"page" spage
0
6104 and rely = fromstring float_of_string spos
"rely" srely
0.0
6105 and pan
= fromstring int_of_string spos
"pan" span
0 in
6106 let c = config_of dc attrs
in
6107 let anchor = (pageno, rely) in
6109 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6110 else { v with f = doc
path pan
anchor c [] }
6113 error
"unexpected subelement in llppconfig" s spos
6115 | Vclose
"llppconfig" -> { v with f = toplevel }
6116 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6118 and defaults
v t spos
_ =
6120 | Vdata
| Vcdata
-> v
6121 | Vend
-> error
"unexpected end of input in defaults" s spos
6122 | Vopen
("keymap", attrs
, closed
) ->
6124 try List.assoc
"mode" attrs
6125 with Not_found
-> "global" in
6130 let h = findkeyhash dc modename in
6131 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6134 { v with f = pkeymap
ret KeyMap.empty }
6136 | Vopen
(_, _, _) ->
6137 error
"unexpected subelement in defaults" s spos
6139 | Vclose
"defaults" ->
6140 { v with f = llppconfig
}
6142 | Vclose
_ -> error
"unexpected close in defaults" s spos
6144 and uifont
b v t spos
epos =
6147 Buffer.add_substring
b s spos
(epos - spos
);
6149 | Vopen
(_, _, _) ->
6150 error
"unexpected subelement in ui-font" s spos
6151 | Vclose
"ui-font" ->
6152 if String.length
!fontpath = 0
6153 then fontpath := Buffer.contents
b;
6154 { v with f = llppconfig
}
6155 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6156 | Vend
-> error
"unexpected end of input in ui-font" s spos
6158 and doc
path pan
anchor c bookmarks
v t spos
_ =
6160 | Vdata
| Vcdata
-> v
6161 | Vend
-> error
"unexpected end of input in doc" s spos
6162 | Vopen
("bookmarks", _, closed
) ->
6165 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6167 | Vopen
("keymap", attrs
, closed
) ->
6169 try List.assoc
"mode" attrs
6170 with Not_found
-> "global"
6176 let h = findkeyhash c modename in
6177 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6178 doc
path pan
anchor c bookmarks
6180 { v with f = pkeymap
ret KeyMap.empty }
6182 | Vopen
(_, _, _) ->
6183 error
"unexpected subelement in doc" s spos
6186 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6187 { v with f = llppconfig
}
6189 | Vclose
_ -> error
"unexpected close in doc" s spos
6191 and pkeymap
ret keymap
v t spos
_ =
6193 | Vdata
| Vcdata
-> v
6194 | Vend
-> error
"unexpected end of input in keymap" s spos
6195 | Vopen
("map", attrs
, closed
) ->
6196 let r, l = map_of attrs
in
6197 let kss = fromstring keys_of_string spos
"in" r [] in
6198 let lss = fromstring keys_of_string spos
"out" l [] in
6202 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6203 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6206 then { v with f = pkeymap
ret keymap }
6209 { v with f = skip
"map" f }
6212 error
"unexpected subelement in keymap" s spos
6214 | Vclose
"keymap" ->
6215 { v with f = ret keymap }
6217 | Vclose
_ -> error
"unexpected close in keymap" s spos
6219 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6221 | Vdata
| Vcdata
-> v
6222 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6223 | Vopen
("item", attrs
, closed
) ->
6224 let titleent, spage
, srely
= bookmark_of attrs
in
6225 let page = fromstring int_of_string spos
"page" spage
0
6226 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6227 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6229 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6232 { v with f = skip
"item" f }
6235 error
"unexpected subelement in bookmarks" s spos
6237 | Vclose
"bookmarks" ->
6238 { v with f = doc
path pan
anchor c bookmarks }
6240 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6242 and skip tag
f v t spos
_ =
6244 | Vdata
| Vcdata
-> v
6246 error
("unexpected end of input in skipped " ^ tag
) s spos
6247 | Vopen
(tag'
, _, closed
) ->
6251 let f'
() = { v with f = skip tag
f } in
6252 { v with f = skip tag'
f'
}
6256 else error
("unexpected close in skipped " ^ tag
) s spos
6259 parse
{ f = toplevel; accu = () } s;
6265 let len = in_channel_length ic
in
6266 let s = String.create
len in
6267 really_input ic
s 0 len;
6270 | Parse_error
(msg
, s, pos
) ->
6271 let subs = subs s pos
in
6272 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6273 failwith
("parse error: " ^
s)
6276 failwith
("config load error: " ^
Printexc.to_string exn
)
6282 let dir = Filename.concat
home ".config" in
6283 if Sys.is_directory
dir then dir else home
6286 Filename.concat
dir "llpp.conf"
6289 let confpath = ref defconfpath;;
6292 if Sys.file_exists
!confpath
6295 (try Some
(open_in_bin
!confpath)
6298 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6299 Printexc.to_string exn
);
6308 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6309 Printexc.to_string exn
);
6315 f (Hashtbl.create
0, defconf)
6320 let pc, pb
, px, pa
=
6322 Hashtbl.find h (Filename.basename
state.path)
6323 with Not_found
-> dc, [], 0, (0, 0.0)
6327 state.bookmarks <- pb
;
6329 state.scrollw
<- conf.scrollbw
;
6331 then state.anchor <- pa
;
6332 cbput state.hists
.nav pa
;
6337 let add_attrs bb always
dc c =
6340 then Printf.bprintf bb
"\n %s='%b'" s a
6343 then Printf.bprintf bb
"\n %s='%d'" s a
6346 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6349 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6352 then Printf.bprintf bb
"\n %s='%f'" s a
6356 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6360 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6364 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6368 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6374 | Some
(_N
, _A
, _B
) ->
6375 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6385 else string_of_float
f
6387 Printf.bprintf bb
"\n %s='%s'" s v
6392 | Cmulti
((n, a, b), _) when n > 1 ->
6393 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6394 | Csplit
(n, _) when n > 1 ->
6395 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6401 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6406 then dc.winw, dc.winh
6408 match state.fullscreen
with
6410 | None
-> c.winw, c.winh
6412 let zoom, presentation, interpagespace, maxwait
=
6414 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6416 match state.mode with
6417 | Birdseye
(bc
, _, _, _, _) ->
6418 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6419 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6421 oi
"width" w dc.winw;
6422 oi
"height" h dc.winh
;
6423 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6424 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6425 ob "case-insensitive-search" c.icase
dc.icase
;
6426 ob "preload" c.preload dc.preload;
6427 oi
"page-bias" c.pagebias
dc.pagebias
;
6428 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6429 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6430 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6431 ob "crop-hack" c.crophack
dc.crophack
;
6432 oW
"throttle" maxwait
dc.maxwait
;
6433 ob "highlight-links" c.hlinks
dc.hlinks
;
6434 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6435 oi
"vertical-margin" interpagespace dc.interpagespace;
6436 oz
"zoom" zoom dc.zoom;
6437 ob "presentation" presentation dc.presentation;
6438 oi
"rotation-angle" c.angle
dc.angle
;
6439 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6440 ob "proportional-display" c.proportional
dc.proportional
;
6441 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6442 oi
"tex-count" c.texcount
dc.texcount
;
6443 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6444 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6445 ob "persistent-location" c.jumpback
dc.jumpback
;
6446 oc
"background-color" c.bgcolor
dc.bgcolor
;
6447 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6448 oi
"tile-width" c.tilew
dc.tilew
;
6449 oi
"tile-height" c.tileh
dc.tileh
;
6450 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6451 ob "checkers" c.checkers
dc.checkers
;
6452 oi
"aalevel" c.aalevel
dc.aalevel
;
6453 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6454 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6455 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6456 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6457 oC
"color-space" c.colorspace
dc.colorspace
;
6458 ob "invert-colors" c.invert
dc.invert
;
6459 oF
"brightness" c.colorscale
dc.colorscale
;
6460 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6461 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6462 oco
"columns" c.columns
dc.columns
;
6463 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6464 os
"selection-command" c.selcmd
dc.selcmd
;
6465 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6466 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6469 let keymapsbuf always
dc c =
6470 let bb = Buffer.create
16 in
6471 let rec loop = function
6473 | (modename, h) :: rest
->
6474 let dh = findkeyhash dc modename in
6475 if always
|| h <> dh
6477 if Hashtbl.length
h > 0
6479 if Buffer.length
bb > 0
6480 then Buffer.add_char
bb '
\n'
;
6481 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6482 Hashtbl.iter
(fun i
o ->
6483 let isdifferent = always
||
6485 let dO = Hashtbl.find dh i
in
6487 with Not_found
-> true
6492 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6493 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6494 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6495 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6496 Buffer.add_string
bb (Wsi.keyname
k);
6499 let rec loop = function
6501 | km
:: [] -> addkm km
6502 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6506 Buffer.add_string
bb "<map in='";
6510 Buffer.add_string
bb "' out='";
6512 Buffer.add_string
bb "'/>\n"
6515 Buffer.add_string
bb "' out='";
6517 Buffer.add_string
bb "'/>\n"
6519 | KMmulti
(ins, kms
) ->
6520 Buffer.add_char
bb ' '
;
6522 Buffer.add_string
bb "' out='";
6524 Buffer.add_string
bb "'/>\n"
6526 Buffer.add_string
bb "</keymap>";
6536 let uifontsize = fstate.fontsize
in
6537 let bb = Buffer.create
32768 in
6539 let dc = if conf.bedefault
then conf else dc in
6540 Buffer.add_string
bb "<llppconfig>\n";
6542 if String.length
!fontpath > 0
6544 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6550 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6553 Buffer.add_string
bb "<defaults ";
6554 add_attrs bb true dc dc;
6555 let kb = keymapsbuf true dc dc in
6556 if Buffer.length
kb > 0
6558 Buffer.add_string
bb ">\n";
6559 Buffer.add_buffer
bb kb;
6560 Buffer.add_string
bb "\n</defaults>\n";
6562 else Buffer.add_string
bb "/>\n";
6564 let adddoc path pan
anchor c bookmarks =
6565 if bookmarks == [] && c = dc && anchor = emptyanchor
6568 Printf.bprintf
bb "<doc path='%s'"
6569 (enent
path 0 (String.length
path));
6571 if anchor <> emptyanchor
6573 let n, y = anchor in
6574 Printf.bprintf
bb " page='%d'" n;
6577 Printf.bprintf
bb " rely='%f'" y
6582 then Printf.bprintf
bb " pan='%d'" pan
;
6584 add_attrs bb false dc c;
6585 let kb = keymapsbuf false dc c in
6587 begin match bookmarks with
6589 if Buffer.length
kb > 0
6591 Buffer.add_string
bb ">\n";
6592 Buffer.add_buffer
bb kb;
6593 Buffer.add_string
bb "\n</doc>\n";
6595 else Buffer.add_string
bb "/>\n"
6597 Buffer.add_string
bb ">\n<bookmarks>\n";
6598 List.iter
(fun (title, _level
, (page, rely)) ->
6600 "<item title='%s' page='%d'"
6601 (enent
title 0 (String.length
title))
6606 Printf.bprintf
bb " rely='%f'" rely
6608 Buffer.add_string
bb "/>\n";
6610 Buffer.add_string
bb "</bookmarks>";
6611 if Buffer.length
kb > 0
6613 Buffer.add_string
bb "\n";
6614 Buffer.add_buffer
bb kb;
6616 Buffer.add_string
bb "\n</doc>\n";
6622 match state.mode with
6623 | Birdseye
(c, pan, _, _, _) ->
6625 match conf.columns
with
6626 | Cmulti
((c, _, _), _) -> Some
c
6630 match c.columns
with
6631 | Cmulti
(c, _) -> Cmulti
(c, [||])
6632 | Csingle
-> Csingle
6633 | Csplit
_ -> failwith
"quit from bird's eye while split"
6635 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6636 | _ -> state.x, conf
6638 let basename = Filename.basename state.path in
6639 adddoc basename pan (getanchor ())
6642 match state.autoscroll
with
6644 | None
-> conf.autoscrollstep
}
6645 (if conf.savebmarks
then state.bookmarks else []);
6647 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6649 then adddoc path x y c bookmarks
6651 Buffer.add_string
bb "</llppconfig>";
6654 if Buffer.length
bb > 0
6657 let tmp = !confpath ^
".tmp" in
6658 let oc = open_out_bin
tmp in
6659 Buffer.output_buffer
oc bb;
6661 Unix.rename
tmp !confpath;
6664 ("error while saving configuration: " ^
Printexc.to_string exn
)
6671 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6672 "<password> Set password");
6674 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6675 "<path> Set path to the user interface font");
6677 ("-c", Arg.String
(fun s -> Config.confpath := s),
6678 "<path> Set path to the configuration file");
6680 ("-v", Arg.Unit
(fun () ->
6682 "%s\nconfiguration path: %s\n"
6686 exit
0), " Print version and exit");
6689 (fun s -> state.path <- s)
6690 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6692 if String.length
state.path = 0
6693 then (prerr_endline
"file name missing"; exit
1);
6697 let globalkeyhash = findkeyhash conf "global" in
6698 let wsfd, winw, winh
= Wsi.init
(object
6700 if nogeomcmds state.geomcmds
|| platform == Posx
6703 GlFunc.draw_buffer `front
;
6704 GlClear.color (scalecolor2 conf.bgcolor
);
6705 GlClear.clear
[`
color];
6706 GlFunc.draw_buffer `back
;
6708 method display = display ()
6709 method reshape w h = reshape w h
6710 method mouse b d x y m = mouse b d x y m
6711 method motion x y = state.mpos
<- (x, y); motion x y
6712 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6714 let mascm = m land (
6715 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6717 match state.keystate
with
6719 let km = k, mascm in
6722 try Hashtbl.find globalkeyhash km
6724 let modehash = state.uioh#
modehash in
6725 try Hashtbl.find modehash km
6726 with Not_found
-> KMinsrt
(k, m)
6728 | KMinsrt
(k, m) -> keyboard k m
6729 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6730 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6732 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6733 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6734 state.keystate
<- KSnone
6735 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6736 state.keystate
<- KSinto
(keys
, insrt
)
6738 state.keystate
<- KSnone
6740 method enter
x y = state.mpos
<- (x, y); pmotion x y
6741 method leave = state.mpos
<- (-1, -1)
6742 method quit
= raise Quit
6743 end) conf.winw conf.winh
(platform = Posx
) in
6748 List.exists
GlMisc.check_extension
6749 [ "GL_ARB_texture_rectangle"
6750 ; "GL_EXT_texture_recangle"
6751 ; "GL_NV_texture_rectangle" ]
6753 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6756 match Ne.pipe () with
6758 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6762 match Ne.pipe () with
6764 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6774 setcheckers conf.checkers
;
6778 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6779 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6784 state.text <- "Opening " ^
state.path;
6786 opendoc state.path state.password
;
6789 let rec loop deadline
=
6791 match state.errfd
with
6792 | None
-> [state.sr
; state.wsfd]
6793 | Some fd
-> [state.sr
; state.wsfd; fd
]
6797 state.redisplay
<- false;
6804 if deadline
= infinity
6806 else max
0.0 (deadline
-. now)
6811 try Unix.select
r [] [] timeout
6812 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6818 if state.ghyll
== noghyll
6820 match state.autoscroll
with
6821 | Some step
when step
!= 0 ->
6822 let y = state.y + step
in
6826 else if y >= state.maxy then 0 else y
6829 if state.mode = View
6830 then state.text <- "";
6833 else deadline
+. 0.01
6838 let rec checkfds = function
6840 | fd
:: rest
when fd
= state.sr
->
6841 let cmd = readcmd state.sr
in
6845 | fd
:: rest
when fd
= state.wsfd ->
6850 let s = String.create
80 in
6851 let n = Unix.read fd
s 0 80 in
6852 if conf.redirectstderr
6854 Buffer.add_substring
state.errmsgs
s 0 n;
6855 state.newerrmsgs
<- true;
6856 state.redisplay
<- true;
6859 prerr_string
(String.sub
s 0 n);
6867 if deadline
= infinity
6871 match state.autoscroll
with
6872 | Some step
when step
!= 0 -> deadline1
6873 | _ -> if state.ghyll
== noghyll then infinity
else deadline1