6 | Ulinkgoto
of (int * int)
8 | Uunexpected
of string
11 | Uremote
of (string * int)
12 and facename
= string;;
14 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
15 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* fontpath
* trimcachepath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
37 and trimcachepath
= string
40 and irect
= (int * int * int * int)
41 and trimparams
= (trimmargins
* irect
)
42 and colorspace
= | Rgb
| Bgr
| Gray
51 | LDfirstvisible
of (int * int * int)
66 | KMmulti
of key list
* key list
68 and keyhash
= (key
, keymap
) Hashtbl.t
71 | KSinto
of (key list
* key list
)
74 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
75 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
77 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
79 external init
: pipe
-> params
-> unit = "ml_init";;
80 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
81 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
82 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
83 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
84 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
85 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
86 external measurestr
: int -> string -> float = "ml_measure_string";;
87 external getmaxw
: unit -> float = "ml_getmaxw";;
88 external postprocess
:
89 opaque
-> int -> int -> int -> (int * string * int) -> int = "ml_postprocess";;
90 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
91 external platform
: unit -> platform
= "ml_platform";;
92 external setaalevel
: int -> unit = "ml_setaalevel";;
93 external realloctexts
: int -> bool = "ml_realloctexts";;
94 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
95 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
96 external getlink
: opaque
-> int -> under
= "ml_getlink";;
97 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
98 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
99 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
100 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
102 let platform_to_string = function
103 | Punknown
-> "unknown"
107 | Pfreebsd
-> "FreeBSD"
108 | Pdragonflybsd
-> "DragonflyBSD"
109 | Popenbsd
-> "OpenBSD"
110 | Pnetbsd
-> "NetBSD"
111 | Pcygwin
-> "Cygwin"
114 let platform = platform ();;
117 if platform = Pcygwin
119 let sh = "/bin/sh" in
120 let args = [|sh; "-c"; cmd
|] in
121 let rec std si so se
= function
123 | (fd
, 0) :: rest
-> std fd so se rest
124 | (fd
, -1) :: rest
->
125 Unix.set_close_on_exec fd
;
128 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
130 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
131 ignore
(Unix.create_process
sh args si so se
)
140 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
143 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
145 type mpos
= int * int
147 | Msel
of (mpos
* mpos
)
149 | Mscrolly
| Mscrollx
150 | Mzoom
of (int * int)
151 | Mzoomrect
of (mpos
* mpos
)
155 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
156 and onkey
= string -> int -> te
157 and ondone
= string -> unit
158 and histcancel
= unit -> unit
159 and onhist
= ((histcmd
-> string) * histcancel
)
160 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
161 and cancelonempty
= bool
166 | TEswitch
of textentry
177 let bound v minv maxv
=
178 max minv
(min maxv v
);
182 { store
= Array.create n v
189 let drawstring size x y s
=
191 Gl.enable `texture_2d
;
192 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
193 ignore
(drawstr size x y s
);
195 Gl.disable `texture_2d
;
198 let drawstring1 size x y s
=
202 let drawstring2 size x y fmt
=
203 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
206 let cbcap b
= Array.length b
.store
;;
211 b
.wc
<- (b
.wc
+ 1) mod cap;
213 b
.len
<- min
(b
.len
+ 1) cap;
216 let cbempty b
= b
.len
= 0;;
218 let cbgetg b circular dir
=
222 let rc = b
.rc + dir
in
234 else max
0 (min
rc (b
.len
-1))
240 let cbget b
= cbgetg b
false;;
241 let cbgetc b
= cbgetg b
true;;
259 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
260 dolog " WxH %dx%d" l
.pagew l
.pageh
;
261 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
262 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
263 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
264 dolog " column %d" l
.pagecol
;
268 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
270 dolog " x0,y0=(% f, % f)" x0 y0
;
271 dolog " x1,y1=(% f, % f)" x1 y1
;
272 dolog " x2,y2=(% f, % f)" x2 y2
;
273 dolog " x3,y3=(% f, % f)" x3 y3
;
277 type multicolumns
= multicol
* pagegeom
278 and singlecolumn
= pagegeom
279 and splitcolumns
= columncount
* pagegeom
280 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
281 and multicol
= columncount
* covercount
* covercount
283 and columncount
= int
284 and covercount
= int;;
287 { mutable scrollbw
: int
288 ; mutable scrollh
: int
289 ; mutable icase
: bool
290 ; mutable preload
: bool
291 ; mutable pagebias
: int
292 ; mutable verbose
: bool
293 ; mutable debug
: bool
294 ; mutable scrollstep
: int
295 ; mutable hscrollstep
: int
296 ; mutable maxhfit
: bool
297 ; mutable crophack
: bool
298 ; mutable autoscrollstep
: int
299 ; mutable maxwait
: float option
300 ; mutable hlinks
: bool
301 ; mutable underinfo
: bool
302 ; mutable interpagespace
: interpagespace
303 ; mutable zoom
: float
304 ; mutable presentation
: bool
305 ; mutable angle
: angle
308 ; mutable savebmarks
: bool
309 ; mutable proportional
: proportional
310 ; mutable trimmargins
: trimmargins
311 ; mutable trimfuzz
: irect
312 ; mutable memlimit
: memsize
313 ; mutable texcount
: texcount
314 ; mutable sliceheight
: sliceheight
315 ; mutable thumbw
: width
316 ; mutable jumpback
: bool
317 ; mutable bgcolor
: float * float * float
318 ; mutable bedefault
: bool
319 ; mutable scrollbarinpm
: bool
320 ; mutable tilew
: int
321 ; mutable tileh
: int
322 ; mutable mustoresize
: memsize
323 ; mutable checkers
: bool
324 ; mutable aalevel
: int
325 ; mutable urilauncher
: string
326 ; mutable pathlauncher
: string
327 ; mutable colorspace
: colorspace
328 ; mutable invert
: bool
329 ; mutable colorscale
: float
330 ; mutable redirectstderr
: bool
331 ; mutable ghyllscroll
: (int * int * int) option
332 ; mutable columns
: columns
333 ; mutable beyecolumns
: columncount
option
334 ; mutable selcmd
: string
335 ; mutable updatecurs
: bool
336 ; mutable keyhashes
: (string * keyhash
) list
337 ; mutable hfsize
: int
338 ; mutable pgscale
: float
339 ; mutable multicenter
: bool
342 | Csingle
of singlecolumn
343 | Cmulti
of multicolumns
344 | Csplit
of splitcolumns
347 type anchor
= pageno
* top
* dtop
;;
349 type outline
= string * int * anchor
;;
351 type rect
= float * float * float * float * float * float * float * float;;
353 type tile
= opaque
* pixmapsize
* elapsed
354 and elapsed
= float;;
355 type pagemapkey
= pageno
* gen
;;
356 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
360 let emptyanchor = (0, 0.0, 0.0);;
362 type infochange
= | Memused
| Docinfo
| Pdim
;;
364 class type uioh
= object
365 method display
: unit
366 method key
: int -> int -> uioh
367 method button
: int -> bool -> int -> int -> int -> uioh
368 method motion
: int -> int -> uioh
369 method pmotion
: int -> int -> uioh
370 method infochanged
: infochange
-> unit
371 method scrollpw
: (int * float * float)
372 method scrollph
: (int * float * float)
373 method modehash
: keyhash
377 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
378 | Textentry
of (textentry
* onleave
)
380 | LinkNav
of linktarget
381 and onleave
= leavetextentrystatus
-> unit
382 and leavetextentrystatus
= | Cancel
| Confirm
383 and helpitem
= string * int * action
386 | Action
of (uioh
-> uioh
)
388 | Ltexact
of (pageno
* int)
392 let isbirdseye = function Birdseye _
-> true | _
-> false;;
393 let istextentry = function Textentry _
-> true | _
-> false;;
397 | Loading
of (page
* gen
)
399 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
401 | Outlining
of outline list
404 let emptykeyhash = Hashtbl.create
0;;
405 let nouioh : uioh
= object (self
)
407 method key _ _
= self
408 method button _ _ _ _ _
= self
409 method motion _ _
= self
410 method pmotion _ _
= self
411 method infochanged _
= ()
412 method scrollpw
= (0, nan
, nan
)
413 method scrollph
= (0, nan
, nan
)
414 method modehash
= emptykeyhash
418 { mutable sr
: Unix.file_descr
419 ; mutable sw
: Unix.file_descr
420 ; mutable wsfd
: Unix.file_descr
421 ; mutable errfd
: Unix.file_descr
option
422 ; mutable stderr
: Unix.file_descr
423 ; mutable errmsgs
: Buffer.t
424 ; mutable newerrmsgs
: bool
428 ; mutable scrollw
: int
429 ; mutable hscrollh
: int
430 ; mutable anchor
: anchor
431 ; mutable ranchors
: (string * string * anchor
) list
433 ; mutable layout
: page list
434 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
435 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
436 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
437 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
438 ; mutable pagecount
: int
439 ; mutable currently
: currently
440 ; mutable mstate
: mstate
441 ; mutable searchpattern
: string
442 ; mutable rects
: (pageno
* recttype
* rect
) list
443 ; mutable rects1
: (pageno
* recttype
* rect
) list
444 ; mutable text
: string
445 ; mutable fullscreen
: (width
* height
) option
446 ; mutable mode
: mode
447 ; mutable uioh
: uioh
448 ; mutable outlines
: outline array
449 ; mutable bookmarks
: outline list
450 ; mutable path
: string
451 ; mutable password
: string
452 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
453 ; mutable memused
: memsize
455 ; mutable throttle
: (page list
* int * float) option
456 ; mutable autoscroll
: int option
457 ; mutable ghyll
: (int option -> unit)
458 ; mutable help
: helpitem array
459 ; mutable docinfo
: (int * string) list
460 ; mutable texid
: GlTex.texture_id
option
462 ; mutable prevzoom
: float
463 ; mutable progress
: float
464 ; mutable redisplay
: bool
465 ; mutable mpos
: mpos
466 ; mutable keystate
: keystate
467 ; mutable glinks
: bool
468 ; mutable prevcolumns
: (columns
* float) option
471 { pat
: string circbuf
472 ; pag
: string circbuf
473 ; nav
: anchor circbuf
474 ; sel
: string circbuf
496 ; presentation
= false
501 ; proportional
= true
502 ; trimmargins
= false
503 ; trimfuzz
= (0,0,0,0)
504 ; memlimit
= 32 lsl 20
509 ; bgcolor
= (0.5, 0.5, 0.5)
511 ; scrollbarinpm
= true
514 ; mustoresize
= 256 lsl 20
519 | Plinux
| Pfreebsd
| Pdragonflybsd
520 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
521 | Posx
-> "open \"%s\""
522 | Pcygwin
-> "cygstart \"%s\""
523 | Punknown
-> "echo %s")
524 ; pathlauncher
= "lp \"%s\""
527 | Plinux
| Pfreebsd
| Pdragonflybsd
528 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
535 ; redirectstderr
= false
537 ; columns
= Csingle
[||]
542 ; multicenter
= false
544 let mk n
= (n
, Hashtbl.create
1) in
558 let findkeyhash c name
=
559 try List.assoc name c
.keyhashes
560 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
563 let conf = { defconf with angle
= defconf.angle
};;
565 let pgscale h
= truncate
(float h
*. conf.pgscale);;
568 { mutable fontsize
: int
569 ; mutable wwidth
: float
570 ; mutable maxrows
: int
582 fstate.fontsize
<- n
;
583 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
584 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
588 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
589 let len = String.length s
in
590 if colonpos >= 0 && colonpos + 3 < len
592 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
595 try String.rindex_from s
colonpos ' '
599 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
602 | "http" | "ftp" | "mailto" ->
604 try String.index_from s
colonpos ' '
605 with Not_found
-> len
607 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
615 if String.length
conf.urilauncher
= 0
616 then print_endline uri
618 let url = geturl uri
in
619 if String.length
url = 0
620 then print_endline uri
622 let re = Str.regexp
"%s" in
623 let command = Str.global_replace
re url conf.urilauncher
in
627 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
633 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
634 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
638 let strings = version () :: "" :: Help.keys
in
641 let url = geturl s
in
642 if String.length
url > 0
643 then (s
, 0, Action
(fun u
-> gotouri url; u
))
644 else (s
, 0, Noaction
)
649 let firstgeomcmds = "", [];;
656 ; stderr
= Unix.stderr
657 ; errmsgs
= Buffer.create
0
664 ; anchor
= emptyanchor
668 ; tilelru
= Queue.create
()
669 ; pagemap
= Hashtbl.create
10
670 ; tilemap
= Hashtbl.create
10
685 ; geomcmds
= firstgeomcmds
687 { nav
= cbnew 10 emptyanchor
714 Printf.kprintf prerr_endline fmt
716 Printf.kprintf ignore fmt
720 if String.length
conf.pathlauncher
= 0
721 then print_endline
state.path
723 let re = Str.regexp
"%s" in
724 let command = Str.global_replace
re state.path
conf.pathlauncher
in
728 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
734 type 'a t
= | Res
of 'a
| Exn
of exn
;;
737 try Res
(Unix.pipe ())
743 with exn
-> f
(Printexc.to_string exn
)
747 try Res
(Unix.dup fd
)
752 try Res
(Unix.dup2 fd1 fd2
)
757 let redirectstderr () =
758 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
759 if conf.redirectstderr
761 match Ne.pipe () with
763 dolog "failed to create stderr redirection pipes: %s"
764 (Printexc.to_string exn
)
767 begin match Ne.dup Unix.stderr
with
769 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
770 Ne.clo r
(clofail "pipe/r");
771 Ne.clo w
(clofail "pipe/w");
773 | Ne.Res dupstderr
->
774 begin match Ne.dup2 w
Unix.stderr
with
776 dolog "failed to dup2 to stderr: %s"
777 (Printexc.to_string exn
);
778 Ne.clo dupstderr
(clofail "stderr duplicate");
779 Ne.clo r
(clofail "redir pipe/r");
780 Ne.clo w
(clofail "redir pipe/w");
783 state.stderr
<- dupstderr
;
784 state.errfd
<- Some r
;
788 state.newerrmsgs
<- false;
789 begin match state.errfd
with
791 begin match Ne.dup2 state.stderr
Unix.stderr
with
793 dolog "failed to dup2 original stderr: %s"
794 (Printexc.to_string exn
)
796 Ne.clo fd
(clofail "dup of stderr");
797 Unix.dup2 state.stderr
Unix.stderr
;
802 prerr_string
(Buffer.contents
state.errmsgs
);
804 Buffer.clear
state.errmsgs
;
810 let postRedisplay who
=
812 then prerr_endline
("redisplay for " ^ who
);
813 state.redisplay
<- true;
817 let getopaque pageno
=
818 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
819 with Not_found
-> None
822 let putopaque pageno opaque
=
823 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
826 let pagetranslatepoint l x y
=
827 let dy = y
- l
.pagedispy
in
828 let y = dy + l
.pagey
in
829 let dx = x
- l
.pagedispx
in
830 let x = dx + l
.pagex
in
837 begin match getopaque l
.pageno
with
839 let x0 = l
.pagedispx
in
840 let x1 = x0 + l
.pagevw
in
841 let y0 = l
.pagedispy
in
842 let y1 = y0 + l
.pagevh
in
843 if y >= y0 && y <= y1 && x >= x0 && x <= x1
845 let px, py
= pagetranslatepoint l
x y in
846 match whatsunder opaque
px py
with
859 state.text
<- Printf.sprintf
"%c%s" c s
;
860 G.postRedisplay "showtext";
863 let undertext = function
866 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
867 | Utext s
-> "font: " ^ s
868 | Uunexpected s
-> "unexpected: " ^ s
869 | Ulaunch s
-> "launch: " ^ s
870 | Unamed s
-> "named: " ^ s
871 | Uremote
(filename
, pageno
) ->
872 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
875 let updateunder x y =
876 match getunder x y with
877 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
879 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
880 Wsi.setcursor
Wsi.CURSOR_INFO
881 | Ulinkgoto
(pageno
, _
) ->
883 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
884 Wsi.setcursor
Wsi.CURSOR_INFO
886 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
887 Wsi.setcursor
Wsi.CURSOR_TEXT
889 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
890 Wsi.setcursor
Wsi.CURSOR_INHERIT
892 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
893 Wsi.setcursor
Wsi.CURSOR_INHERIT
895 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
896 Wsi.setcursor
Wsi.CURSOR_INHERIT
897 | Uremote
(filename
, pageno
) ->
898 if conf.underinfo
then showtext 'r'
899 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
900 Wsi.setcursor
Wsi.CURSOR_INFO
903 let showlinktype under
=
909 let s = undertext under
in
914 let b = Buffer.create
(String.length
s + 1) in
915 Buffer.add_string
b s;
920 let colorspace_of_string s =
921 match String.lowercase
s with
925 | _
-> failwith
"invalid colorspace"
928 let int_of_colorspace = function
934 let colorspace_of_int = function
938 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
941 let colorspace_to_string = function
947 let intentry_with_suffix text key
=
949 if key
>= 32 && key
< 127
953 match Char.lowercase
c with
955 let text = addchar text c in
959 let text = addchar text c in
963 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
967 let multicolumns_to_string (n
, a
, b) =
969 then Printf.sprintf
"%d" n
970 else Printf.sprintf
"%d,%d,%d" n a
b;
973 let multicolumns_of_string s =
975 (int_of_string
s, 0, 0)
977 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
979 then failwith
"subtly broken"; (n
, a
, b)
985 let n = Unix.read fd
s 0 4 in
986 if n != 4 then failwith
"incomplete read(len)";
988 lor (Char.code
s.[0] lsl 24)
989 lor (Char.code
s.[1] lsl 16)
990 lor (Char.code
s.[2] lsl 8)
991 lor (Char.code
s.[3] lsl 0)
993 let s = String.create
len in
994 let n = Unix.read fd
s 0 len in
995 if n != len then failwith
"incomplete read(data)";
999 let btod b = if b then 1 else 0;;
1002 let b = Buffer.create
16 in
1003 Buffer.add_string
b "llll";
1006 let s = Buffer.contents
b in
1007 let n = String.length
s in
1009 (* dolog "wcmd %S" (String.sub s 4 len); *)
1010 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1011 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1012 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1013 s.[3] <- Char.chr
(len land 0xff);
1014 let n'
= Unix.write
state.sw
s 0 n in
1015 if n'
!= n then failwith
"write failed";
1020 if conf.presentation
1022 let d = conf.winh
- h
in
1023 max
conf.interpagespace
((d + 1) / 2)
1029 match conf.columns
with
1030 | Cmulti
((c, _
, _
), b) ->
1031 let rec loop y h
n =
1035 if n = Array.length
b
1038 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
1044 loop max_int
0 (((Array.length
b - 1) / c) * c)
1046 if Array.length
b > 0
1048 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1049 y + h
+ (if conf.presentation
then calcips h
else 0)
1052 if Array.length
b > 0
1054 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1059 let getpageyh pageno
=
1060 let pageno = bound pageno 0 (state.pagecount
-1) in
1061 match conf.columns
with
1063 let (_
, _
, y, (_
, _
, h
, _
)) = b.(pageno) in
1065 if conf.presentation
1071 let (_
, _
, y, (_
, _
, h
, _
)) = b.(pageno) in
1075 let (_
, _
, y, (_
, _
, h
, _
)) = b.(n) in
1079 let getpagedim pageno =
1082 | (n, _
, _
, _
) as pdim
:: rest
->
1084 then (if n = pageno then pdim
else ppdim
)
1089 f (-1, -1, -1, -1) state.pdims
1092 let getpagey pageno = fst
(getpageyh pageno);;
1094 let nogeomcmds cmds
=
1096 | s, [] -> String.length
s = 0
1101 let (c, coverA
, coverB
), b =
1102 match conf.columns
with
1103 | Csingle
b -> (1, 0, 0), b
1104 | Cmulti
(c, b) -> c, b
1105 | Csplit
(_
, b) -> (1, 0, 0), b
1107 let rec bsearch nmin nmax
=
1109 then bound nmin
0 (state.pagecount
-1)
1111 let n = (nmax
+ nmin
) / 2 in
1112 let _, _, vy
, (_, _, h
, _) = b.(n) in
1114 if conf.presentation
1116 let ips = calcips h
in
1117 let y0 = vy
- ips in
1118 let y1 = vy
+ h
+ ips in
1122 then 0, vy
+ h
+ conf.interpagespace
1124 let y0 = vy
- conf.interpagespace
in
1125 y0, y0 + h
+ conf.interpagespace
1128 if y >= y0 && y < y1
1135 if n < state.pagecount
- coverB
1136 then ((n-coverA
)/c)*c + coverA
1143 then bsearch (n+1) nmax
1144 else bsearch nmin
(n-1)
1147 let r = bsearch 0 (state.pagecount
-1) in
1151 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1152 let sh = sh - state.hscrollh
in
1153 let rec fold accu
n =
1154 if n = Array.length
b
1157 let pdimno, dx, vy
, (_, w
, h
, xoff
) = b.(n) in
1160 || n = state.pagecount
- coverB
1161 || (n - coverA
) mod columns
= columns
- 1)
1167 let pagey = max
0 (y - vy
) in
1168 let pagedispy = if pagey > 0 then 0 else vy
- y in
1169 let pagedispx, pagex
=
1171 if n = coverA
- 1 || n = state.pagecount
- coverB
1172 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1173 else dx + xoff
+ state.x
1180 let vw = conf.winw
- state.scrollw
- pagedispx in
1181 let pw = w
- pagex
in
1184 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1185 if pagevw > 0 && pagevh > 0
1189 ; pagedimno
= pdimno
1196 ; pagedispx = pagedispx
1197 ; pagedispy = pagedispy
1209 List.rev
(fold [] (page_of_y y));
1212 let layoutS (columns
, b) y sh =
1213 let sh = sh - state.hscrollh
in
1214 let rec fold accu n =
1215 if n = Array.length
b
1218 let pdimno, px, vy
, (_, pagew
, pageh
, xoff
) = b.(n) in
1225 let x = xoff
+ state.x in
1226 let pagey = max
0 (y - vy
) in
1227 let pagedispy = if pagey > 0 then 0 else vy
- y in
1228 let pagedispx, pagex
=
1242 let pagecolw = pagew
/columns
in
1244 if pagecolw < conf.winw
1245 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1249 let vw = conf.winw
- pagedispx - state.scrollw
in
1250 let pw = pagew
- pagex
in
1253 let pagevw = min
pagevw pagecolw in
1254 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1255 if pagevw > 0 && pagevh > 0
1258 { pageno = n/columns
1259 ; pagedimno
= pdimno
1266 ; pagedispx = pagedispx
1267 ; pagedispy = pagedispy
1268 ; pagecol
= n mod columns
1279 List.rev
(fold [] 0)
1283 if nogeomcmds state.geomcmds
1285 match conf.columns
with
1286 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1287 | Cmulti
c -> layoutN c y sh
1288 | Csplit
s -> layoutS s y sh
1293 let y = state.y + incr
in
1295 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1300 let tilex = l
.pagex
mod conf.tilew
in
1301 let tiley = l
.pagey mod conf.tileh
in
1303 let col = l
.pagex
/ conf.tilew
in
1304 let row = l
.pagey / conf.tileh
in
1306 let rec rowloop row y0 dispy h
=
1310 let dh = conf.tileh
- y0 in
1311 let dh = min h
dh in
1312 let rec colloop col x0 dispx w
=
1316 let dw = conf.tilew
- x0 in
1317 let dw = min w
dw in
1319 f col row dispx dispy
x0 y0 dw dh;
1320 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1323 colloop col tilex l
.pagedispx l
.pagevw;
1324 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1327 if l
.pagevw > 0 && l
.pagevh > 0
1328 then rowloop row tiley l
.pagedispy l
.pagevh;
1331 let gettileopaque l
col row =
1333 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1335 try Some
(Hashtbl.find
state.tilemap
key)
1336 with Not_found
-> None
1339 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1340 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1341 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1344 let drawtiles l color
=
1346 let f col row x y tilex tiley w h
=
1347 match gettileopaque l
col row with
1348 | Some
(opaque
, _, t
) ->
1349 let params = x, y, w
, h
, tilex, tiley in
1353 GlFunc.blend_func `zero `one_minus_src_color
;
1355 drawtile
params opaque
;
1357 then Gl.disable `blend
;
1360 let s = Printf.sprintf
1364 let w = measurestr
fstate.fontsize
s in
1365 GlMisc.push_attrib
[`current
];
1366 GlDraw.color
(0.0, 0.0, 0.0);
1368 (float (x-2), float (y-2))
1369 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1370 GlDraw.color
(1.0, 1.0, 1.0);
1371 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1372 GlMisc.pop_attrib
();
1377 let lw = conf.winw
- state.scrollw
- x in
1380 let lh = conf.winh
- y in
1383 begin match state.texid
with
1385 Gl.enable `texture_2d
;
1386 GlTex.bind_texture `texture_2d id
;
1389 and x1 = float (x+w)
1390 and y1 = float (y+h
) in
1392 let tw = float w /. 64.0
1393 and th
= float h
/. 64.0 in
1394 let tx0 = float tilex /. 64.0
1395 and ty0
= float tiley /. 64.0 in
1397 and ty1
= ty0
+. th
in
1398 GlDraw.begins `quads
;
1399 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1400 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1401 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1402 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1405 Gl.disable `texture_2d
;
1407 GlDraw.color
(1.0, 1.0, 1.0);
1410 (float (x+w), float (y+h
));
1412 if w > 128 && h
> fstate.fontsize
+ 10
1414 GlDraw.color
(0.0, 0.0, 0.0);
1417 then (col*conf.tilew
, row*conf.tileh
)
1420 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1427 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1429 let tilevisible1 l
x y =
1431 and ax1
= l
.pagex
+ l
.pagevw
1433 and ay1
= l
.pagey + l
.pagevh in
1437 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1438 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1440 let rx0 = max
ax0 bx0
1441 and ry0
= max ay0 by0
1442 and rx1
= min ax1
bx1
1443 and ry1
= min ay1 by1
in
1445 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1446 nonemptyintersection
1449 let tilevisible layout n x y =
1450 let rec findpageinlayout m
= function
1451 | l
:: rest
when l
.pageno = n ->
1452 tilevisible1 l
x y || (
1453 match conf.columns
with
1454 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1457 | _ :: rest
-> findpageinlayout 0 rest
1460 findpageinlayout 0 layout;
1463 let tileready l
x y =
1464 tilevisible1 l
x y &&
1465 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1468 let tilepage n p
layout =
1469 let rec loop = function
1473 let f col row _ _ _ _ _ _ =
1474 if state.currently
= Idle
1476 match gettileopaque l
col row with
1479 let x = col*conf.tilew
1480 and y = row*conf.tileh
in
1482 let w = l
.pagew
- x in
1486 let h = l
.pageh
- y in
1489 wcmd "tile %s %d %d %d %d" p
x y w h;
1492 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1493 conf.tilew
, conf.tileh
1502 if nogeomcmds state.geomcmds
1506 let preloadlayout y =
1507 let y = if y < conf.winh
then 0 else y - conf.winh
in
1508 let h = conf.winh
*3 in
1513 let rec loop pages
=
1514 if state.currently
!= Idle
1519 begin match getopaque l
.pageno with
1521 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1522 state.currently
<- Loading
(l
, state.gen
);
1524 tilepage l
.pageno opaque pages
;
1529 if nogeomcmds state.geomcmds
1535 if conf.preload && state.currently
= Idle
1536 then load (preloadlayout state.y);
1539 let layoutready layout =
1540 let rec fold all ls
=
1541 all
&& match ls
with
1543 let seen = ref false in
1544 let allvisible = ref true in
1545 let foo col row _ _ _ _ _ _ =
1547 allvisible := !allvisible &&
1548 begin match gettileopaque l
col row with
1554 fold (!seen && !allvisible) rest
1557 let alltilesvisible = fold true layout in
1562 let y = bound y 0 state.maxy
in
1563 let y, layout, proceed
=
1564 match conf.maxwait
with
1565 | Some time
when state.ghyll
== noghyll ->
1566 begin match state.throttle
with
1568 let layout = layout y conf.winh
in
1569 let ready = layoutready layout in
1573 state.throttle
<- Some
(layout, y, now ());
1575 else G.postRedisplay "gotoy showall (None)";
1577 | Some
(_, _, started
) ->
1578 let dt = now () -. started
in
1581 state.throttle
<- None
;
1582 let layout = layout y conf.winh
in
1584 G.postRedisplay "maxwait";
1591 let layout = layout y conf.winh
in
1592 if true || layoutready layout
1593 then G.postRedisplay "gotoy ready";
1599 state.layout <- layout;
1600 begin match state.mode
with
1601 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1602 let rec loop = function
1604 state.mode
<- LinkNav
(Ltgendir
0)
1605 | l
:: _ when l
.pageno = pageno ->
1606 begin match getopaque pageno with
1608 state.mode
<- LinkNav
(Ltgendir
0)
1610 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1611 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1612 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1613 then state.mode
<- LinkNav
(Ltgendir
0)
1615 | _ :: rest
-> loop rest
1620 begin match state.mode
with
1621 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1622 if not
(pagevisible layout pageno)
1624 match state.layout with
1627 state.mode
<- Birdseye
(
1628 conf, leftx
, l
.pageno, hooverpageno
, anchor
1631 | LinkNav
(Ltgendir dir
as lt
) ->
1633 let rec loop = function
1636 match getopaque l
.pageno with
1642 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1644 if dir
> 0 then LDfirst
else LDlast
1650 | Lnotfound
-> loop rest
1652 showlinktype (getlink opaque
n);
1653 Ltexact
(l
.pageno, n)
1657 state.mode
<- LinkNav
linknav
1662 state.ghyll
<- noghyll;
1665 let mx, my
= state.mpos
in
1670 let conttiling pageno opaque
=
1671 tilepage pageno opaque
1672 (if conf.preload then preloadlayout state.y else state.layout)
1675 let gotoy_and_clear_text y =
1676 if not
conf.verbose
then state.text <- "";
1682 let coloff = l
.pagecol
* l
.pageh
in
1683 float (l
.pagey + coloff) /. float l
.pageh
1690 if conf.presentation
1691 then float l
.pagedispy /. float (calcips l
.pageh
)
1692 else float l
.pagedispy /. float conf.interpagespace
1694 (l
.pageno, top, dtop)
1698 match state.layout with
1699 | l
:: _ -> getanchor1 l
1701 let n = page_of_y state.y in
1702 let y, h = getpageyh n in
1703 let dy = y - state.y in
1705 if conf.presentation
1707 let ips = calcips h in
1708 float (dy + ips) /. float ips
1710 float dy /. float conf.interpagespace
1715 let getanchory (n, top, dtop) =
1716 let y, h = getpageyh n in
1717 if conf.presentation
1719 let ips = calcips h in
1720 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1722 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1725 let gotoanchor anchor
=
1726 gotoy (getanchory anchor
);
1730 cbput state.hists
.nav
(getanchor ());
1734 let anchor = cbgetc state.hists
.nav dir
in
1739 let scroll f n a
b =
1740 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1742 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1744 then s (float f /. float a
)
1747 then 1.0 -. s ((float (f-b) /. float (n-b)))
1754 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1755 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1757 let ins = float a
*. iv1
1758 and outs
= float (n-b) *. iv1 in
1760 ins +. outs
+. float ones
1762 let rec set (_N
, _A
, _B
) y sy
=
1763 let sum = summa
1.0 _N _A _B
in
1764 let dy = float (y - sy
) in
1768 then state.ghyll
<- noghyll
1771 let s = scroll n _N _A _B
in
1772 let y1 = y1 +. ((s *. dy) /. sum) in
1773 gotoy_and_clear_text (truncate
y1);
1774 state.ghyll
<- gf (n+1) y1;
1778 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1780 gf 0 (float state.y)
1783 match conf.ghyllscroll
with
1785 gotoy_and_clear_text y
1787 if state.ghyll
== noghyll
1788 then set nab
y state.y
1789 else state.ghyll
(Some
y)
1792 let gotopage n top =
1793 let y, h = getpageyh n in
1794 let y = y + (truncate
(top *. float h)) in
1798 let gotopage1 n top =
1799 let y = getpagey n in
1804 let invalidate s f =
1809 match state.geomcmds
with
1810 | ps
, [] when String.length ps
= 0 ->
1812 state.geomcmds
<- s, [];
1815 state.geomcmds
<- ps
, [s, f];
1817 | ps
, (s'
, _) :: rest
when s'
= s ->
1818 state.geomcmds
<- ps
, ((s, f) :: rest
);
1821 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1824 let opendoc path password
=
1826 state.password
<- password
;
1827 state.gen
<- state.gen
+ 1;
1828 state.docinfo
<- [];
1830 setaalevel
conf.aalevel
;
1831 Wsi.settitle
("llpp " ^
Filename.basename path
);
1832 wcmd "open %s\000%s\000" path password
;
1833 invalidate "reqlayout"
1835 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1839 let c = c *. conf.colorscale
in
1843 let scalecolor2 (r, g
, b) =
1844 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1847 let docolumns = function
1849 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1850 let rec loop pageno pdimno pdim
y ph pdims
=
1851 if pageno = state.pagecount
1854 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1856 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1857 pdimno+1, pdim
, rest
1861 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1863 (if conf.presentation
1864 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1865 else (if pageno = 0 then 0 else calcips h)
1868 a.(pageno) <- (pdimno, x, y, pdim
);
1869 loop (pageno+1) pdimno pdim
(y + h) h pdims
1871 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1872 conf.columns
<- Csingle
a;
1874 | Cmulti
((columns
, coverA
, coverB
), _) ->
1875 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1876 let rec loop pageno pdimno pdim
x y rowh pdims
=
1877 let rec fixrow m
= if m
= pageno then () else
1878 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1881 let y = y + (rowh
- h) / 2 in
1882 a.(m
) <- (pdimno, x, y, pdim
);
1886 if pageno = state.pagecount
1887 then fixrow (((pageno - 1) / columns
) * columns
)
1889 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1891 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1892 pdimno+1, pdim
, rest
1897 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1899 (conf.winw
- state.scrollw
- w) / 2,
1900 y + rowh
+ conf.interpagespace
, h
1903 if (pageno - coverA
) mod columns
= 0
1905 (if conf.multicenter
then
1906 (conf.winw
- state.scrollw
- state.w) / 2 else 0),
1907 y + rowh
+ (if pageno = 0 then 0 else conf.interpagespace
), h
1909 else x, y, max rowh
h
1912 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1913 then fixrow (pageno - columns
);
1914 a.(pageno) <- (pdimno, x, y, pdim
);
1915 let x = x + w + xoff
*2 + conf.interpagespace
in
1916 loop (pageno+1) pdimno pdim
x y rowh' pdims
1918 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1919 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1922 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1923 let rec loop pageno pdimno pdim
y pdims
=
1924 if pageno = state.pagecount
1927 let pdimno, ((_, w, h, _) as pdim
), pdims
=
1929 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1930 pdimno+1, pdim
, rest
1935 let rec loop1 n x y =
1936 if n = c then y else (
1937 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
1938 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
1941 let y = loop1 0 0 y in
1942 loop (pageno+1) pdimno pdim
y pdims
1944 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1945 conf.columns
<- Csplit
(c, a);
1949 docolumns conf.columns
;
1950 state.maxy
<- calcheight ();
1952 if state.w <= conf.winw
- state.scrollw
1956 match state.mode
with
1957 | Birdseye
(_, _, pageno, _, _) ->
1958 let y, h = getpageyh pageno in
1959 let top = (conf.winh
- h) / 2 in
1960 gotoy (max
0 (y - top))
1961 | _ -> gotoanchor state.anchor
1965 GlDraw.viewport
0 0 w h;
1966 let firsttime = state.geomcmds
== firstgeomcmds in
1967 if not
firsttime && nogeomcmds state.geomcmds
1968 then state.anchor <- getanchor ();
1971 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1974 setfontsize fstate.fontsize
;
1975 GlMat.mode `modelview
;
1976 GlMat.load_identity
();
1978 GlMat.mode `projection
;
1979 GlMat.load_identity
();
1980 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1981 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1982 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1987 else float state.x /. float state.w
1989 invalidate "geometry"
1993 then state.x <- truncate
(relx *. float w);
1995 match conf.columns
with
1997 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
1998 | Csplit
(c, _) -> w * c
2000 wcmd "geometry %d %d" w h);
2004 let len = String.length
state.text in
2007 match state.mode
with
2010 let h, _, _ = state.uioh#scrollpw
in
2016 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2017 (x+.w, float (conf.winh
- hscrollh))
2020 let w = float (conf.winw
- state.scrollw
- 1) in
2021 if state.progress
>= 0.0 && state.progress
< 1.0
2023 GlDraw.color
(0.3, 0.3, 0.3);
2024 let w1 = w *. state.progress
in
2026 GlDraw.color
(0.0, 0.0, 0.0);
2030 GlDraw.color
(0.0, 0.0, 0.0);
2034 GlDraw.color
(1.0, 1.0, 1.0);
2035 drawstring fstate.fontsize
2036 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2039 match state.mode
with
2040 | Textentry
((prefix
, text, _, _, _, _), _) ->
2044 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2046 Printf.sprintf
"%s%s_" prefix
text
2055 if not
(istextentry state.mode
)
2057 let s1 = "(press 'e' to review error messasges)" in
2058 if String.length
s > 0 then s ^
" " ^
s1 else s1
2063 if String.length
s > 0
2068 let len = Queue.length
state.tilelru
in
2070 match state.throttle
with
2073 then preloadlayout state.y
2075 | Some
(layout, _, _) ->
2079 if state.memused
<= conf.memlimit
2084 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2085 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2086 let (_, pw, ph
, _) = getpagedim n in
2089 && colorspace
= conf.colorspace
2090 && angle
= conf.angle
2094 let x = col*conf.tilew
2095 and y = row*conf.tileh
in
2096 tilevisible (Lazy.force_val
layout) n x y
2098 then Queue.push lruitem
state.tilelru
2100 wcmd "freetile %s" p
;
2101 state.memused
<- state.memused
- s;
2102 state.uioh#infochanged Memused
;
2103 Hashtbl.remove
state.tilemap k
;
2112 Queue.iter
(fun (k
, p
, s) ->
2113 wcmd "freetile %s" p
;
2114 state.memused
<- state.memused
- s;
2115 state.uioh#infochanged Memused
;
2116 Hashtbl.remove
state.tilemap k
;
2118 Queue.clear
state.tilelru
;
2122 let logcurrently = function
2123 | Idle
-> dolog "Idle"
2124 | Loading
(l
, gen
) ->
2125 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2126 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2128 "Tiling %d[%d,%d] page=%s cs=%s angle"
2129 l
.pageno col row pageopaque
2130 (colorspace_to_string colorspace
)
2132 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2133 angle gen
conf.angle
state.gen
2135 conf.tilew
conf.tileh
2142 (* dolog "%S" cmds; *)
2145 try String.index cmds ' '
2146 with Not_found
-> -1
2151 let l = String.length cmds
in
2152 let op = String.sub cmds
0 spacepos in
2154 if l - spacepos < 2 then ""
2155 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2160 state.uioh#infochanged Pdim
;
2164 state.rects
<- state.rects1
;
2165 G.postRedisplay "clearrects";
2169 try Scanf.sscanf
args "%u" (fun n -> n)
2171 dolog "error processing 'continue' %S: %s"
2172 cmds
(Printexc.to_string exn
);
2175 state.pagecount
<- n;
2176 begin match state.currently
with
2178 state.currently
<- Idle
;
2179 state.outlines
<- Array.of_list
(List.rev
l)
2183 let cur, cmds
= state.geomcmds
in
2184 if String.length
cur = 0
2185 then failwith
"umpossible";
2187 begin match List.rev cmds
with
2189 state.geomcmds
<- "", [];
2193 state.geomcmds
<- s, List.rev rest
;
2195 if conf.maxwait
= None
2196 then G.postRedisplay "continue";
2206 then showtext ' '
args
2209 let progress, text =
2211 Scanf.sscanf
args "%f %n"
2213 f, String.sub
args pos
(String.length
args - pos
))
2215 dolog "error processing 'progress' %S: %s"
2216 cmds
(Printexc.to_string exn
);
2220 state.progress <- progress;
2221 G.postRedisplay "progress"
2224 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2226 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2227 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2228 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2230 dolog "error processing 'firstmatch' %S: %s"
2231 cmds
(Printexc.to_string exn
);
2234 let y = (getpagey pageno) + truncate
y0 in
2237 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2240 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2242 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2243 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2244 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2246 dolog "error processing 'match' %S: %s"
2247 cmds
(Printexc.to_string exn
);
2251 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2256 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2258 dolog "error processing 'page' %S: %s"
2259 cmds
(Printexc.to_string exn
);
2262 begin match state.currently
with
2263 | Loading
(l, gen
) ->
2264 vlog "page %d took %f sec" l.pageno t
;
2265 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2266 begin match state.throttle
with
2268 let preloadedpages =
2270 then preloadlayout state.y
2275 Set.Make
(struct type t
= int let compare = (-) end) in
2277 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2278 IntSet.empty
preloadedpages
2281 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2282 if not
(IntSet.mem
pageno set)
2284 wcmd "freepage %s" opaque
;
2290 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2293 state.currently
<- Idle
;
2296 tilepage l.pageno pageopaque state.layout;
2298 load preloadedpages;
2299 if pagevisible state.layout l.pageno
2300 && layoutready state.layout
2301 then G.postRedisplay "page";
2304 | Some
(layout, _, _) ->
2305 state.currently
<- Idle
;
2306 tilepage l.pageno pageopaque layout;
2311 dolog "Inconsistent loading state";
2312 logcurrently state.currently
;
2317 let (x, y, opaque
, size
, t
) =
2319 Scanf.sscanf
args "%u %u %s %u %f"
2320 (fun x y p size t
-> (x, y, p
, size
, t
))
2322 dolog "error processing 'tile' %S: %s"
2323 cmds
(Printexc.to_string exn
);
2326 begin match state.currently
with
2327 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2328 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2330 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2332 wcmd "freetile %s" opaque
;
2333 state.currently
<- Idle
;
2337 puttileopaque l col row gen cs angle opaque size t
;
2338 state.memused
<- state.memused
+ size
;
2339 state.uioh#infochanged Memused
;
2341 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2342 opaque
, size
) state.tilelru
;
2345 match state.throttle
with
2346 | None
-> state.layout
2347 | Some
(layout, _, _) -> layout
2350 state.currently
<- Idle
;
2352 && conf.colorspace
= cs
2353 && conf.angle
= angle
2354 && tilevisible layout l.pageno x y
2355 then conttiling l.pageno pageopaque;
2357 begin match state.throttle
with
2359 preload state.layout;
2361 && conf.colorspace
= cs
2362 && conf.angle
= angle
2363 && tilevisible state.layout l.pageno x y
2364 then G.postRedisplay "tile nothrottle";
2366 | Some
(layout, y, _) ->
2367 let ready = layoutready layout in
2371 state.layout <- layout;
2372 state.throttle
<- None
;
2373 G.postRedisplay "throttle";
2380 dolog "Inconsistent tiling state";
2381 logcurrently state.currently
;
2388 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2390 dolog "error processing 'pdim' %S: %s"
2391 cmds
(Printexc.to_string exn
);
2394 state.uioh#infochanged Pdim
;
2395 state.pdims
<- pdim :: state.pdims
2398 let (l, n, t
, h, pos
) =
2400 Scanf.sscanf
args "%u %u %d %u %n"
2401 (fun l n t
h pos
-> l, n, t
, h, pos
)
2403 dolog "error processing 'o' %S: %s"
2404 cmds
(Printexc.to_string exn
);
2407 let s = String.sub
args pos
(String.length
args - pos
) in
2408 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2409 begin match state.currently
with
2410 | Outlining outlines
->
2411 state.currently
<- Outlining
(outline :: outlines
)
2413 state.currently
<- Outlining
[outline]
2415 dolog "invalid outlining state";
2416 logcurrently currently
2420 state.docinfo
<- (1, args) :: state.docinfo
2423 state.uioh#infochanged Docinfo
;
2424 state.docinfo
<- List.rev
state.docinfo
2427 dolog "unknown cmd `%S'" cmds
2432 let action = function
2433 | HCprev
-> cbget cb ~
-1
2434 | HCnext
-> cbget cb
1
2435 | HCfirst
-> cbget cb ~
-(cb
.rc)
2436 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2437 and cancel
() = cb
.rc <- rc
2441 let search pattern forward
=
2442 if String.length pattern
> 0
2445 match state.layout with
2448 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2450 wcmd "search %d %d %d %d,%s\000"
2451 (btod conf.icase
) pn py
(btod forward
) pattern
;
2454 let intentry text key =
2456 if key >= 32 && key < 127
2462 let text = addchar text c in
2466 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2470 let linknentry text key =
2472 if key >= 32 && key < 127
2478 let text = addchar text c in
2482 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2487 if String.length
s > 0
2490 let l = String.length
s in
2491 let rec loop pos
n = if pos
= l then n else
2492 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2493 loop (pos
+1) (n*26 + m)
2496 let rec loop n = function
2499 match getopaque l.pageno with
2500 | None
-> loop n rest
2502 let m = getlinkcount opaque
in
2505 let under = getlink opaque
n in
2508 else loop (n-m) rest
2510 loop n state.layout;
2514 let textentry text key =
2515 if key land 0xff00 = 0xff00
2517 else TEcont
(text ^
Wsi.toutf8
key)
2520 let reqlayout angle proportional
=
2521 match state.throttle
with
2523 if nogeomcmds state.geomcmds
2524 then state.anchor <- getanchor ();
2525 conf.angle
<- angle
mod 360;
2528 match state.mode
with
2529 | LinkNav
_ -> state.mode
<- View
2532 conf.proportional
<- proportional
;
2533 invalidate "reqlayout"
2534 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2538 let settrim trimmargins trimfuzz
=
2539 if nogeomcmds state.geomcmds
2540 then state.anchor <- getanchor ();
2541 conf.trimmargins
<- trimmargins
;
2542 conf.trimfuzz
<- trimfuzz
;
2543 let x0, y0, x1, y1 = trimfuzz
in
2544 invalidate "settrim"
2546 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2547 Hashtbl.iter
(fun _ opaque
->
2548 wcmd "freepage %s" opaque
;
2550 Hashtbl.clear
state.pagemap
;
2554 match state.throttle
with
2556 let zoom = max
0.01 zoom in
2557 if zoom <> conf.zoom
2559 state.prevzoom
<- conf.zoom;
2561 reshape conf.winw
conf.winh
;
2562 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2565 | Some
(layout, y, started
) ->
2567 match conf.maxwait
with
2571 let dt = now () -. started
in
2579 let setcolumns mode columns coverA coverB
=
2580 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2584 then showtext '
!'
"split mode doesn't work in bird's eye"
2586 conf.columns
<- Csplit
(-columns
, [||]);
2594 conf.columns
<- Csingle
[||];
2599 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2603 reshape conf.winw
conf.winh
;
2606 let enterbirdseye () =
2607 let zoom = float conf.thumbw
/. float conf.winw
in
2608 let birdseyepageno =
2609 let cy = conf.winh
/ 2 in
2613 let rec fold best
= function
2616 let d = cy - (l.pagedispy + l.pagevh/2)
2617 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2618 if abs
d < abs dbest
2625 state.mode
<- Birdseye
(
2626 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2629 conf.presentation
<- false;
2630 conf.interpagespace
<- 10;
2631 conf.hlinks
<- false;
2633 state.mstate
<- Mnone
;
2634 conf.maxwait
<- None
;
2636 match conf.beyecolumns
with
2639 Cmulti
((c, 0, 0), [||])
2640 | None
-> Csingle
[||]
2642 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2645 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2650 reshape conf.winw
conf.winh
;
2653 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2655 conf.zoom <- c.zoom;
2656 conf.presentation
<- c.presentation
;
2657 conf.interpagespace
<- c.interpagespace
;
2658 conf.maxwait
<- c.maxwait
;
2659 conf.hlinks
<- c.hlinks
;
2660 conf.beyecolumns
<- (
2661 match conf.columns
with
2662 | Cmulti
((c, _, _), _) -> Some
c
2664 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2667 match c.columns
with
2668 | Cmulti
(c, _) -> Cmulti
(c, [||])
2669 | Csingle
_ -> Csingle
[||]
2670 | Csplit
(c, _) -> Csplit
(c, [||])
2675 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2678 reshape conf.winw
conf.winh
;
2679 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2682 let togglebirdseye () =
2683 match state.mode
with
2684 | Birdseye vals
-> leavebirdseye vals
true
2685 | View
-> enterbirdseye ()
2689 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2690 let pageno = max
0 (pageno - incr
) in
2691 let rec loop = function
2692 | [] -> gotopage1 pageno 0
2693 | l :: _ when l.pageno = pageno ->
2694 if l.pagedispy >= 0 && l.pagey = 0
2695 then G.postRedisplay "upbirdseye"
2696 else gotopage1 pageno 0
2697 | _ :: rest
-> loop rest
2700 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2703 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2704 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2705 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2706 let rec loop = function
2708 let y, h = getpageyh pageno in
2709 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2711 | l :: _ when l.pageno = pageno ->
2712 if l.pagevh != l.pageh
2713 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2714 else G.postRedisplay "downbirdseye"
2715 | _ :: rest
-> loop rest
2720 let optentry mode
_ key =
2721 let btos b = if b then "on" else "off" in
2722 if key >= 32 && key < 127
2724 let c = Char.chr
key in
2728 try conf.scrollstep
<- int_of_string
s with exc
->
2729 state.text <- Printf.sprintf
"bad integer `%s': %s"
2730 s (Printexc.to_string exc
)
2732 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2737 conf.autoscrollstep
<- int_of_string
s;
2738 if state.autoscroll
<> None
2739 then state.autoscroll
<- Some
conf.autoscrollstep
2741 state.text <- Printf.sprintf
"bad integer `%s': %s"
2742 s (Printexc.to_string exc
)
2744 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2749 let n, a, b = multicolumns_of_string s in
2750 setcolumns mode
n a b;
2752 state.text <- Printf.sprintf
"bad columns `%s': %s"
2753 s (Printexc.to_string exc
)
2755 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2760 let zoom = float (int_of_string
s) /. 100.0 in
2763 state.text <- Printf.sprintf
"bad integer `%s': %s"
2764 s (Printexc.to_string exc
)
2766 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2771 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2773 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2774 begin match mode
with
2776 leavebirdseye beye
false;
2781 state.text <- Printf.sprintf
"bad integer `%s': %s"
2782 s (Printexc.to_string exc
)
2784 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2789 Some
(int_of_string
s)
2791 state.text <- Printf.sprintf
"bad integer `%s': %s"
2792 s (Printexc.to_string exc
);
2795 | Some angle
-> reqlayout angle
conf.proportional
2798 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2801 conf.icase
<- not
conf.icase
;
2802 TEdone
("case insensitive search " ^
(btos conf.icase
))
2805 conf.preload <- not
conf.preload;
2807 TEdone
("preload " ^
(btos conf.preload))
2810 conf.verbose
<- not
conf.verbose
;
2811 TEdone
("verbose " ^
(btos conf.verbose
))
2814 conf.debug
<- not
conf.debug
;
2815 TEdone
("debug " ^
(btos conf.debug
))
2818 conf.maxhfit
<- not
conf.maxhfit
;
2819 state.maxy
<- calcheight ();
2820 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2823 conf.crophack
<- not
conf.crophack
;
2824 TEdone
("crophack " ^
btos conf.crophack
)
2828 match conf.maxwait
with
2830 conf.maxwait
<- Some infinity
;
2831 "always wait for page to complete"
2833 conf.maxwait
<- None
;
2834 "show placeholder if page is not ready"
2839 conf.underinfo
<- not
conf.underinfo
;
2840 TEdone
("underinfo " ^
btos conf.underinfo
)
2843 conf.savebmarks
<- not
conf.savebmarks
;
2844 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2850 match state.layout with
2855 conf.interpagespace
<- int_of_string
s;
2856 docolumns conf.columns
;
2857 state.maxy
<- calcheight ();
2858 let y = getpagey pageno in
2861 state.text <- Printf.sprintf
"bad integer `%s': %s"
2862 s (Printexc.to_string exc
)
2864 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2867 reqlayout conf.angle
(not
conf.proportional
);
2868 TEdone
("proportional display " ^
btos conf.proportional
)
2871 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2872 TEdone
("trim margins " ^
btos conf.trimmargins
)
2875 conf.invert
<- not
conf.invert
;
2876 TEdone
("invert colors " ^
btos conf.invert
)
2880 cbput state.hists
.sel
s;
2883 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2884 textentry, ondone, true)
2887 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2893 class type lvsource
= object
2894 method getitemcount
: int
2895 method getitem
: int -> (string * int)
2896 method hasaction
: int -> bool
2905 method getactive
: int
2906 method getfirst
: int
2907 method getqsearch
: string
2908 method setqsearch
: string -> unit
2912 class virtual lvsourcebase
= object
2913 val mutable m_active
= 0
2914 val mutable m_first
= 0
2915 val mutable m_qsearch
= ""
2916 val mutable m_pan
= 0
2917 method getactive
= m_active
2918 method getfirst
= m_first
2919 method getqsearch
= m_qsearch
2920 method getpan
= m_pan
2921 method setqsearch
s = m_qsearch
<- s
2924 let withoutlastutf8 s =
2925 let len = String.length
s in
2933 let b = Char.code
s.[pos
] in
2934 if b land 0b110000 = 0b11000000
2939 if Char.code
s.[len-1] land 0x80 = 0
2943 String.sub
s 0 first;
2946 let textentrykeyboard
2947 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2949 state.mode
<- Textentry
(te
, onleave
);
2952 G.postRedisplay "textentrykeyboard enttext";
2954 let histaction cmd
=
2957 | Some
(action, _) ->
2958 state.mode
<- Textentry
(
2959 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2961 G.postRedisplay "textentry histaction"
2964 | 0xff08 -> (* backspace *)
2965 let s = withoutlastutf8 text in
2966 let len = String.length
s in
2967 if cancelonempty
&& len = 0
2970 G.postRedisplay "textentrykeyboard after cancel";
2973 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2979 G.postRedisplay "textentrykeyboard after confirm"
2981 | 0xff52 -> histaction HCprev
2982 | 0xff54 -> histaction HCnext
2983 | 0xff50 -> histaction HCfirst
2984 | 0xff57 -> histaction HClast
2986 | 0xff1b -> (* escape*)
2987 if String.length
text = 0
2989 begin match opthist
with
2991 | Some
(_, onhistcancel
) -> onhistcancel
()
2995 G.postRedisplay "textentrykeyboard after cancel2"
2998 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3001 | 0xff9f | 0xffff -> () (* delete *)
3003 | _ when key != 0 && key land 0xff00 != 0xff00 ->
3004 begin match onkey
text key with
3008 G.postRedisplay "textentrykeyboard after confirm2";
3011 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3015 G.postRedisplay "textentrykeyboard after cancel3"
3018 state.mode
<- Textentry
(te
, onleave
);
3019 G.postRedisplay "textentrykeyboard switch";
3023 vlog "unhandled key %s" (Wsi.keyname
key)
3026 let firstof first active
=
3027 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3028 then max
0 (active
- (fstate.maxrows
/2))
3032 let calcfirst first active
=
3035 let rows = active
- first in
3036 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3040 let scrollph y maxy
=
3041 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3042 let sh = float conf.winh
/. sh in
3043 let sh = max
sh (float conf.scrollh
) in
3048 else float y /. float maxy
3050 let position = (float conf.winh
-. sh) *. percent in
3053 if position +. sh > float conf.winh
3054 then float conf.winh
-. sh
3060 let coe s = (s :> uioh
);;
3062 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3064 val m_pan
= source#getpan
3065 val m_first
= source#getfirst
3066 val m_active
= source#getactive
3067 val m_qsearch
= source#getqsearch
3068 val m_prev_uioh
= state.uioh
3070 method private elemunder
y =
3071 let n = y / (fstate.fontsize
+1) in
3072 if m_first
+ n < source#getitemcount
3074 if source#hasaction
(m_first
+ n)
3075 then Some
(m_first
+ n)
3082 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3083 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3084 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3085 GlDraw.color
(1., 1., 1.);
3086 Gl.enable `texture_2d
;
3087 let fs = fstate.fontsize
in
3089 let ww = fstate.wwidth
in
3090 let tabw = 30.0*.ww in
3091 let itemcount = source#getitemcount
in
3093 if (row - m_first
) * nfs > conf.winh
3096 if row >= 0 && row < itemcount
3098 let (s, level
) = source#getitem
row in
3099 let y = (row - m_first
) * nfs in
3100 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3103 Gl.disable `texture_2d
;
3104 GlDraw.polygon_mode `both `line
;
3105 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3106 GlDraw.rect (1., float (y + 1))
3107 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3108 GlDraw.polygon_mode `both `fill
;
3109 GlDraw.color
(1., 1., 1.);
3110 Gl.enable `texture_2d
;
3113 let drawtabularstring s =
3114 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3117 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3120 let len = String.length
s - tabpos - 1 in
3121 let s1 = String.sub
s 0 tabpos
3122 and s2
= String.sub
s (tabpos + 1) len in
3123 let nx = drawstr x s1 in
3125 let x = x +. (max
tabw sw) in
3132 let _ = drawtabularstring s in
3139 Gl.disable `texture_2d
;
3141 method updownlevel incr
=
3142 let len = source#getitemcount
in
3144 if m_active
>= 0 && m_active
< len
3145 then snd
(source#getitem m_active
)
3149 if i
= len then i
-1 else if i
= -1 then 0 else
3150 let _, l = source#getitem i
in
3151 if l != curlevel then i
else flow (i
+incr
)
3153 let active = flow m_active
in
3154 let first = calcfirst m_first
active in
3155 G.postRedisplay "outline updownlevel";
3156 {< m_active
= active; m_first
= first >}
3158 method private key1
key mask
=
3159 let set1 active first qsearch
=
3160 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3162 let search active pattern incr
=
3165 if n >= 0 && n < source#getitemcount
3167 let s, _ = source#getitem
n in
3169 (try ignore
(Str.search_forward
re s 0); true
3170 with Not_found
-> false)
3172 else loop (n + incr
)
3179 let re = Str.regexp_case_fold pattern
in
3185 let itemcount = source#getitemcount
in
3186 let find start incr
=
3188 if i
= -1 || i
= itemcount
3191 if source#hasaction i
3193 else find (i
+ incr
)
3198 let set active first =
3199 let first = bound first 0 (itemcount - fstate.maxrows
) in
3201 coe {< m_active
= active; m_first
= first >}
3204 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3206 let incr1 = if incr
> 0 then 1 else -1 in
3207 if isvisible m_first m_active
3210 let next = m_active
+ incr
in
3212 if next < 0 || next >= itemcount
3214 else find next incr1
3216 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3222 let first = m_first
+ incr
in
3223 let first = bound first 0 (itemcount - 1) in
3225 let next = m_active
+ incr
in
3226 let next = bound next 0 (itemcount - 1) in
3229 let active = if next = -1 then m_active
else next in
3232 let first = min
next m_first
in
3234 if abs
(next - first) > fstate.maxrows
3240 let first = m_first
+ incr
in
3241 let first = bound first 0 (itemcount - 1) in
3243 let next = m_active
+ incr
in
3244 let next = bound next 0 (itemcount - 1) in
3245 let next = find next incr1 in
3247 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3249 let active = if m_active
= -1 then next else m_active
in
3254 if isvisible first active
3260 G.postRedisplay "listview navigate";
3264 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3265 let incr = if key = 0x72 then -1 else 1 in
3267 match search (m_active
+ incr) m_qsearch
incr with
3269 state.text <- m_qsearch ^
" [not found]";
3272 state.text <- m_qsearch
;
3273 active, firstof m_first
active
3275 G.postRedisplay "listview ctrl-r/s";
3276 set1 active first m_qsearch
;
3278 | 0xff08 -> (* backspace *)
3279 if String.length m_qsearch
= 0
3282 let qsearch = withoutlastutf8 m_qsearch
in
3283 let len = String.length
qsearch in
3287 G.postRedisplay "listview empty qsearch";
3288 set1 m_active m_first
"";
3292 match search m_active
qsearch ~
-1 with
3294 state.text <- qsearch ^
" [not found]";
3297 state.text <- qsearch;
3298 active, firstof m_first
active
3300 G.postRedisplay "listview backspace qsearch";
3301 set1 active first qsearch
3304 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3305 let pattern = m_qsearch ^
Wsi.toutf8
key in
3307 match search m_active
pattern 1 with
3309 state.text <- pattern ^
" [not found]";
3312 state.text <- pattern;
3313 active, firstof m_first
active
3315 G.postRedisplay "listview qsearch add";
3316 set1 active first pattern;
3318 | 0xff1b -> (* escape *)
3320 if String.length m_qsearch
= 0
3322 G.postRedisplay "list view escape";
3325 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3327 | None
-> m_prev_uioh
3332 G.postRedisplay "list view kill qsearch";
3333 source#setqsearch
"";
3334 coe {< m_qsearch
= "" >}
3337 | 0xff0d -> (* return *)
3339 let self = {< m_qsearch
= "" >} in
3340 source#setqsearch
"";
3342 G.postRedisplay "listview enter";
3343 if m_active
>= 0 && m_active
< source#getitemcount
3345 source#exit
(coe self) false m_active m_first m_pan
"";
3348 source#exit
(coe self) true m_active m_first m_pan
"";
3351 begin match opt with
3352 | None
-> m_prev_uioh
3356 | 0xff9f | 0xffff -> (* delete *)
3359 | 0xff52 -> navigate ~
-1 (* up *)
3360 | 0xff54 -> navigate 1 (* down *)
3361 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3362 | 0xff56 -> navigate fstate.maxrows
(* next *)
3364 | 0xff53 -> (* right *)
3366 G.postRedisplay "listview right";
3367 coe {< m_pan
= m_pan
- 1 >}
3369 | 0xff51 -> (* left *)
3371 G.postRedisplay "listview left";
3372 coe {< m_pan
= m_pan
+ 1 >}
3374 | 0xff50 -> (* home *)
3375 let active = find 0 1 in
3376 G.postRedisplay "listview home";
3379 | 0xff57 -> (* end *)
3380 let first = max
0 (itemcount - fstate.maxrows
) in
3381 let active = find (itemcount - 1) ~
-1 in
3382 G.postRedisplay "listview end";
3385 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3389 dolog "listview unknown key %#x" key; coe self
3391 method key key mask
=
3392 match state.mode
with
3393 | Textentry te
-> textentrykeyboard key mask te
; coe self
3394 | _ -> self#key1
key mask
3396 method button button down
x y _ =
3399 | 1 when x > conf.winw
- conf.scrollbw
->
3400 G.postRedisplay "listview scroll";
3403 let _, position, sh = self#
scrollph in
3404 if y > truncate
position && y < truncate
(position +. sh)
3406 state.mstate
<- Mscrolly
;
3410 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3411 let first = truncate
(s *. float source#getitemcount
) in
3412 let first = min source#getitemcount
first in
3413 Some
(coe {< m_first
= first; m_active
= first >})
3415 state.mstate
<- Mnone
;
3418 | 1 when not down
->
3419 begin match self#elemunder
y with
3421 G.postRedisplay "listview click";
3423 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3427 | n when (n == 4 || n == 5) && not down
->
3428 let len = source#getitemcount
in
3430 if n = 5 && m_first
+ fstate.maxrows
>= len
3434 let first = m_first
+ (if n == 4 then -1 else 1) in
3435 bound first 0 (len - 1)
3437 G.postRedisplay "listview wheel";
3438 Some
(coe {< m_first
= first >})
3439 | n when (n = 6 || n = 7) && not down
->
3440 let inc = m_first
+ (if n = 7 then -1 else 1) in
3441 G.postRedisplay "listview hwheel";
3442 Some
(coe {< m_pan
= m_pan
+ inc >})
3447 | None
-> m_prev_uioh
3451 match state.mstate
with
3453 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3454 let first = truncate
(s *. float source#getitemcount
) in
3455 let first = min source#getitemcount
first in
3456 G.postRedisplay "listview motion";
3457 coe {< m_first
= first; m_active
= first >}
3460 method pmotion
x y =
3461 if x < conf.winw
- conf.scrollbw
3464 match self#elemunder
y with
3465 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3466 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3470 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3475 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3479 method infochanged
_ = ()
3481 method scrollpw
= (0, 0.0, 0.0)
3483 let nfs = fstate.fontsize
+ 1 in
3484 let y = m_first
* nfs in
3485 let itemcount = source#getitemcount
in
3486 let maxi = max
0 (itemcount - fstate.maxrows
) in
3487 let maxy = maxi * nfs in
3488 let p, h = scrollph y maxy in
3491 method modehash
= modehash
3494 class outlinelistview ~source
=
3497 ~source
:(source
:> lvsource
)
3499 ~modehash
:(findkeyhash conf "outline")
3502 method key key mask
=
3503 let calcfirst first active =
3506 let rows = active - first in
3508 if String.length
state.text = 0
3510 else fstate.maxrows - 2
3512 if rows > maxrows then active - maxrows else first
3516 let active = m_active
+ incr in
3517 let active = bound active 0 (source#getitemcount
- 1) in
3518 let first = calcfirst m_first
active in
3519 G.postRedisplay "outline navigate";
3520 coe {< m_active
= active; m_first
= first >}
3522 let ctrl = Wsi.withctrl mask
in
3524 | 110 when ctrl -> (* ctrl-n *)
3525 source#narrow m_qsearch
;
3526 G.postRedisplay "outline ctrl-n";
3527 coe {< m_first
= 0; m_active
= 0 >}
3529 | 117 when ctrl -> (* ctrl-u *)
3531 G.postRedisplay "outline ctrl-u";
3533 coe {< m_first
= 0; m_active
= 0 >}
3535 | 108 when ctrl -> (* ctrl-l *)
3536 let first = m_active
- (fstate.maxrows / 2) in
3537 G.postRedisplay "outline ctrl-l";
3538 coe {< m_first
= first >}
3540 | 0xff9f | 0xffff -> (* delete *)
3541 source#remove m_active
;
3542 G.postRedisplay "outline delete";
3543 let active = max
0 (m_active
-1) in
3544 coe {< m_first
= firstof m_first
active;
3545 m_active
= active >}
3547 | 0xff52 -> navigate ~
-1 (* up *)
3548 | 0xff54 -> navigate 1 (* down *)
3549 | 0xff55 -> (* prior *)
3550 navigate ~
-(fstate.maxrows)
3551 | 0xff56 -> (* next *)
3552 navigate fstate.maxrows
3554 | 0xff53 -> (* [ctrl-]right *)
3558 G.postRedisplay "outline ctrl right";
3559 {< m_pan
= m_pan
+ 1 >}
3561 else self#updownlevel
1
3565 | 0xff51 -> (* [ctrl-]left *)
3569 G.postRedisplay "outline ctrl left";
3570 {< m_pan
= m_pan
- 1 >}
3572 else self#updownlevel ~
-1
3576 | 0xff50 -> (* home *)
3577 G.postRedisplay "outline home";
3578 coe {< m_first
= 0; m_active
= 0 >}
3580 | 0xff57 -> (* end *)
3581 let active = source#getitemcount
- 1 in
3582 let first = max
0 (active - fstate.maxrows) in
3583 G.postRedisplay "outline end";
3584 coe {< m_active
= active; m_first
= first >}
3586 | _ -> super#
key key mask
3589 let outlinesource usebookmarks
=
3592 inherit lvsourcebase
3593 val mutable m_items
= empty
3594 val mutable m_orig_items
= empty
3595 val mutable m_prev_items
= empty
3596 val mutable m_narrow_pattern
= ""
3597 val mutable m_hadremovals
= false
3599 method getitemcount
=
3600 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3603 if n == Array.length m_items
&& m_hadremovals
3605 ("[Confirm removal]", 0)
3607 let s, n, _ = m_items
.(n) in
3610 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3611 ignore
(uioh
, first, qsearch);
3612 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3614 if String.length m_narrow_pattern
= 0
3620 if not
confrimremoval
3622 let _, _, anchor = m_items
.(active) in
3627 state.bookmarks
<- Array.to_list m_items
;
3628 m_orig_items
<- m_items
;
3631 else m_items
<- items;
3635 method hasaction
_ = true
3638 if Array.length m_items
!= Array.length m_orig_items
3639 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3642 method narrow
pattern =
3643 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3647 let rec loop accu n =
3650 m_narrow_pattern
<- pattern;
3651 m_items
<- Array.of_list
accu
3654 let (s, _, _) as o = m_items
.(n) in
3656 if (try ignore
(Str.search_forward
re s 0); true
3657 with Not_found
-> false)
3663 loop [] (Array.length m_items
- 1)
3668 then Array.of_list
state.bookmarks
3671 m_items
<- m_orig_items
3676 if m >= 0 && m < Array.length m_items
3678 m_hadremovals
<- true;
3679 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3680 let n = if n >= m then n+1 else n in
3685 method reset
anchor items =
3686 m_hadremovals
<- false;
3687 if m_orig_items
== empty || m_prev_items
!= items
3689 m_orig_items
<- items;
3690 if String.length m_narrow_pattern
= 0
3691 then m_items
<- items;
3693 m_prev_items
<- items;
3694 let rely = getanchory anchor in
3696 let rec loop n best bestd
=
3697 if n = Array.length m_items
3700 let (_, _, anchor) = m_items
.(n) in
3701 let orely = getanchory anchor in
3702 let d = abs
(orely - rely) in
3705 else loop (n+1) best bestd
3710 m_first
<- firstof m_first
active
3714 let enterselector usebookmarks
=
3715 let source = outlinesource usebookmarks
in
3719 then Array.of_list
state.bookmarks
3722 if Array.length
outlines = 0
3724 showtext ' ' errmsg
;
3727 state.text <- source#greetmsg
;
3728 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3729 let anchor = getanchor () in
3730 source#reset
anchor outlines;
3731 state.uioh
<- coe (new outlinelistview ~
source);
3732 G.postRedisplay "enter selector";
3736 let enteroutlinemode =
3737 let f = enterselector false in
3738 fun ()-> f "Document has no outline";
3741 let enterbookmarkmode =
3742 let f = enterselector true in
3743 fun () -> f "Document has no bookmarks (yet)";
3746 let color_of_string s =
3747 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3748 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3752 let color_to_string (r, g
, b) =
3753 let r = truncate
(r *. 256.0)
3754 and g
= truncate
(g
*. 256.0)
3755 and b = truncate
(b *. 256.0) in
3756 Printf.sprintf
"%d/%d/%d" r g
b
3759 let irect_of_string s =
3760 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3763 let irect_to_string (x0,y0,x1,y1) =
3764 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3767 let makecheckers () =
3768 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3770 converted by Issac Trotts. July 25, 2002 *)
3771 let image_height = 64
3772 and image_width
= 64 in
3776 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3778 for i
= 0 to image_width
- 1 do
3779 for j
= 0 to image_height - 1 do
3780 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3781 (if (i
land 8 ) lxor (j
land 8) = 0
3782 then [|255;255;255|] else [|200;200;200|])
3787 let image = make_image () in
3788 let id = GlTex.gen_texture
() in
3789 GlTex.bind_texture `texture_2d
id;
3790 GlPix.store
(`unpack_alignment
1);
3791 GlTex.image2d
image;
3792 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3795 `mag_filter `nearest
;
3796 `min_filter `nearest
];
3800 let setcheckers enabled
=
3801 match state.texid
with
3803 if enabled
then state.texid
<- Some
(makecheckers ())
3808 GlTex.delete_texture texid
;
3809 state.texid
<- None
;
3813 let int_of_string_with_suffix s =
3814 let l = String.length
s in
3818 let suffix = Char.lowercase
s.[l-1] in
3820 | 'k'
-> String.sub
s 0 (l-1), 10
3821 | '
m'
-> String.sub
s 0 (l-1), 20
3822 | 'g'
-> String.sub
s 0 (l-1), 30
3826 let n = int_of_string
s1 in
3827 let m = n lsl shift
in
3829 then raise
(Failure
"value too large")
3833 let string_with_suffix_of_int n =
3838 if n land ((1 lsl 20) - 1) = 0
3841 if n land ((1 lsl 10) - 1) = 0
3847 let h = n mod 1000 in
3850 then string_of_int
h ^
s
3852 let s = Printf.sprintf
"_%03d%s" h s in
3859 let defghyllscroll = (40, 8, 32);;
3860 let ghyllscroll_of_string s =
3861 let (n, a, b) as nab
=
3864 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3866 if n <= a || n <= b || a >= b
3867 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3871 let ghyllscroll_to_string ((n, a, b) as nab
) =
3872 if nab
= defghyllscroll
3874 else Printf.sprintf
"%d,%d,%d" n a b;
3877 let describe_location () =
3879 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3881 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3882 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3886 else (100. *. (float state.y /. float maxy))
3890 Printf.sprintf
"page %d of %d [%.2f%%]"
3891 (fn+1) state.pagecount
percent
3894 "pages %d-%d of %d [%.2f%%]"
3895 (fn+1) (ln
+1) state.pagecount
percent
3898 let setpresentationmode v
=
3899 let (n, _, _) = getanchor () in
3900 let _, h = getpageyh n in
3901 state.anchor <- (n, 0.0, float (calcips h));
3902 conf.presentation
<- v
;
3903 if conf.presentation
3905 if not
conf.scrollbarinpm
3906 then state.scrollw
<- 0;
3908 else state.scrollw
<- conf.scrollbw
;
3913 let btos b = if b then "\xe2\x88\x9a" else "" in
3914 let showextended = ref false in
3915 let leave mode
= function
3916 | Confirm
-> state.mode
<- mode
3917 | Cancel
-> state.mode
<- mode
in
3920 val mutable m_first_time
= true
3921 val mutable m_l
= []
3922 val mutable m_a
= [||]
3923 val mutable m_prev_uioh
= nouioh
3924 val mutable m_prev_mode
= View
3926 inherit lvsourcebase
3928 method reset prev_mode prev_uioh
=
3929 m_a
<- Array.of_list
(List.rev m_l
);
3931 m_prev_mode
<- prev_mode
;
3932 m_prev_uioh
<- prev_uioh
;
3936 if n >= Array.length m_a
3940 | _, _, _, Action
_ -> m_active
<- n
3944 m_first_time
<- false;
3947 method int name get
set =
3949 (name
, `
int get
, 1, Action
(
3952 try set (int_of_string
s)
3954 state.text <- Printf.sprintf
"bad integer `%s': %s"
3955 s (Printexc.to_string exn
)
3958 let te = name ^
": ", "", None
, intentry, ondone, true in
3959 state.mode
<- Textentry
(te, leave m_prev_mode
);
3963 method int_with_suffix name get
set =
3965 (name
, `intws get
, 1, Action
(
3968 try set (int_of_string_with_suffix s)
3970 state.text <- Printf.sprintf
"bad integer `%s': %s"
3971 s (Printexc.to_string exn
)
3975 name ^
": ", "", None
, intentry_with_suffix, ondone, true
3977 state.mode
<- Textentry
(te, leave m_prev_mode
);
3981 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3983 (name
, `
bool (btos, get
), offset
, Action
(
3990 method color name get
set =
3992 (name
, `color get
, 1, Action
(
3994 let invalid = (nan
, nan
, nan
) in
3997 try color_of_string s
3999 state.text <- Printf.sprintf
"bad color `%s': %s"
4000 s (Printexc.to_string exn
);
4006 let te = name ^
": ", "", None
, textentry, ondone, true in
4007 state.text <- color_to_string (get
());
4008 state.mode
<- Textentry
(te, leave m_prev_mode
);
4012 method string name get
set =
4014 (name
, `
string get
, 1, Action
(
4016 let ondone s = set s in
4017 let te = name ^
": ", "", None
, textentry, ondone, true in
4018 state.mode
<- Textentry
(te, leave m_prev_mode
);
4022 method colorspace name get
set =
4024 (name
, `
string get
, 1, Action
(
4027 let vals = [| "rgb"; "bgr"; "gray" |] in
4029 inherit lvsourcebase
4032 m_active
<- int_of_colorspace conf.colorspace
;
4035 method getitemcount
= Array.length
vals
4036 method getitem
n = (vals.(n), 0)
4037 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4038 ignore
(uioh
, first, pan
, qsearch);
4039 if not cancel
then set active;
4041 method hasaction
_ = true
4045 let modehash = findkeyhash conf "info" in
4046 coe (new listview ~
source ~trusted
:true ~
modehash)
4049 method caption
s offset
=
4050 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4052 method caption2
s f offset
=
4053 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4055 method getitemcount
= Array.length m_a
4058 let tostr = function
4059 | `
int f -> string_of_int
(f ())
4060 | `intws
f -> string_with_suffix_of_int (f ())
4062 | `color
f -> color_to_string (f ())
4063 | `
bool (btos, f) -> btos (f ())
4066 let name, t
, offset
, _ = m_a
.(n) in
4067 ((let s = tostr t
in
4068 if String.length
s > 0
4069 then Printf.sprintf
"%s\t%s" name s
4073 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4077 m_qsearch
<- qsearch;
4079 match m_a
.(active) with
4080 | _, _, _, Action
f -> f uioh
4092 method hasaction
n =
4094 | _, _, _, Action
_ -> true
4098 let rec fillsrc prevmode prevuioh
=
4099 let sep () = src#caption
"" 0 in
4100 let colorp name get
set =
4102 (fun () -> color_to_string (get
()))
4105 let c = color_of_string v in
4108 state.text <- Printf.sprintf
"bad color `%s': %s"
4109 v (Printexc.to_string exn
);
4112 let oldmode = state.mode
in
4113 let birdseye = isbirdseye state.mode
in
4115 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4117 src#
bool "presentation mode"
4118 (fun () -> conf.presentation
)
4119 (fun v -> setpresentationmode v);
4121 src#
bool "ignore case in searches"
4122 (fun () -> conf.icase
)
4123 (fun v -> conf.icase
<- v);
4126 (fun () -> conf.preload)
4127 (fun v -> conf.preload <- v);
4129 src#
bool "highlight links"
4130 (fun () -> conf.hlinks
)
4131 (fun v -> conf.hlinks
<- v);
4133 src#
bool "under info"
4134 (fun () -> conf.underinfo
)
4135 (fun v -> conf.underinfo
<- v);
4137 src#
bool "persistent bookmarks"
4138 (fun () -> conf.savebmarks
)
4139 (fun v -> conf.savebmarks
<- v);
4141 src#
bool "proportional display"
4142 (fun () -> conf.proportional
)
4143 (fun v -> reqlayout conf.angle
v);
4145 src#
bool "trim margins"
4146 (fun () -> conf.trimmargins
)
4147 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4149 src#
bool "persistent location"
4150 (fun () -> conf.jumpback
)
4151 (fun v -> conf.jumpback
<- v);
4154 src#
int "inter-page space"
4155 (fun () -> conf.interpagespace
)
4157 conf.interpagespace
<- n;
4158 docolumns conf.columns
;
4160 match state.layout with
4165 state.maxy <- calcheight ();
4166 let y = getpagey pageno in
4171 (fun () -> conf.pagebias
)
4172 (fun v -> conf.pagebias
<- v);
4174 src#
int "scroll step"
4175 (fun () -> conf.scrollstep
)
4176 (fun n -> conf.scrollstep
<- n);
4178 src#
int "horizontal scroll step"
4179 (fun () -> conf.hscrollstep
)
4180 (fun v -> conf.hscrollstep
<- v);
4182 src#
int "auto scroll step"
4184 match state.autoscroll
with
4186 | _ -> conf.autoscrollstep
)
4188 if state.autoscroll
<> None
4189 then state.autoscroll
<- Some
n;
4190 conf.autoscrollstep
<- n);
4193 (fun () -> truncate
(conf.zoom *. 100.))
4194 (fun v -> setzoom ((float v) /. 100.));
4197 (fun () -> conf.angle
)
4198 (fun v -> reqlayout v conf.proportional
);
4200 src#
int "scroll bar width"
4201 (fun () -> state.scrollw
)
4205 reshape conf.winw
conf.winh
;
4208 src#
int "scroll handle height"
4209 (fun () -> conf.scrollh
)
4210 (fun v -> conf.scrollh
<- v;);
4212 src#
int "thumbnail width"
4213 (fun () -> conf.thumbw
)
4215 conf.thumbw
<- min
4096 v;
4218 leavebirdseye beye
false;
4223 let mode = state.mode in
4224 src#
string "columns"
4226 match conf.columns
with
4228 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4229 | Csplit
(count
, _) -> "-" ^ string_of_int count
4232 let n, a, b = multicolumns_of_string v in
4233 setcolumns mode n a b);
4236 src#caption
"Presentation mode" 0;
4237 src#
bool "scrollbar visible"
4238 (fun () -> conf.scrollbarinpm
)
4240 if v != conf.scrollbarinpm
4242 conf.scrollbarinpm
<- v;
4243 if conf.presentation
4245 state.scrollw
<- if v then conf.scrollbw
else 0;
4246 reshape conf.winw
conf.winh
;
4252 src#caption
"Pixmap cache" 0;
4253 src#int_with_suffix
"size (advisory)"
4254 (fun () -> conf.memlimit
)
4255 (fun v -> conf.memlimit
<- v);
4258 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4259 (string_with_suffix_of_int state.memused
)
4260 (Hashtbl.length
state.tilemap
)) 1;
4263 src#caption
"Layout" 0;
4264 src#caption2
"Dimension"
4266 Printf.sprintf
"%dx%d (virtual %dx%d)"
4272 src#caption2
"Position" (fun () ->
4273 Printf.sprintf
"%dx%d" state.x state.y
4276 src#caption2
"Visible" (fun () -> describe_location ()) 1
4280 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4281 "Save these parameters as global defaults at exit"
4282 (fun () -> conf.bedefault
)
4283 (fun v -> conf.bedefault
<- v)
4287 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4288 src#
bool ~offset
:0 ~
btos "Extended parameters"
4289 (fun () -> !showextended)
4290 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4294 (fun () -> conf.checkers
)
4295 (fun v -> conf.checkers
<- v; setcheckers v);
4296 src#
bool "update cursor"
4297 (fun () -> conf.updatecurs
)
4298 (fun v -> conf.updatecurs
<- v);
4300 (fun () -> conf.verbose
)
4301 (fun v -> conf.verbose
<- v);
4302 src#
bool "invert colors"
4303 (fun () -> conf.invert
)
4304 (fun v -> conf.invert
<- v);
4306 (fun () -> conf.maxhfit
)
4307 (fun v -> conf.maxhfit
<- v);
4308 src#
bool "redirect stderr"
4309 (fun () -> conf.redirectstderr)
4310 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4311 src#
string "uri launcher"
4312 (fun () -> conf.urilauncher
)
4313 (fun v -> conf.urilauncher
<- v);
4314 src#
string "path launcher"
4315 (fun () -> conf.pathlauncher
)
4316 (fun v -> conf.pathlauncher
<- v);
4317 src#
string "tile size"
4318 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4321 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4322 conf.tilew
<- max
64 w;
4323 conf.tileh
<- max
64 h;
4326 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4327 v (Printexc.to_string exn
));
4328 src#
int "texture count"
4329 (fun () -> conf.texcount
)
4332 then conf.texcount
<- v
4333 else showtext '
!'
" Failed to set texture count please retry later"
4335 src#
int "slice height"
4336 (fun () -> conf.sliceheight
)
4338 conf.sliceheight
<- v;
4339 wcmd "sliceh %d" conf.sliceheight
;
4341 src#
int "anti-aliasing level"
4342 (fun () -> conf.aalevel
)
4344 conf.aalevel
<- bound v 0 8;
4345 state.anchor <- getanchor ();
4346 opendoc state.path
state.password
;
4348 src#
string "page scroll scaling factor"
4349 (fun () -> string_of_float
conf.pgscale)
4352 let s = float_of_string
v in
4355 state.text <- Printf.sprintf
4356 "bad page scroll scaling factor `%s': %s"
4357 v (Printexc.to_string exn
)
4360 src#
int "ui font size"
4361 (fun () -> fstate.fontsize
)
4362 (fun v -> setfontsize (bound v 5 100));
4363 src#
int "hint font size"
4364 (fun () -> conf.hfsize
)
4365 (fun v -> conf.hfsize
<- bound v 5 100);
4366 colorp "background color"
4367 (fun () -> conf.bgcolor
)
4368 (fun v -> conf.bgcolor
<- v);
4369 src#
bool "crop hack"
4370 (fun () -> conf.crophack
)
4371 (fun v -> conf.crophack
<- v);
4372 src#
bool "multi column centering"
4373 (fun () -> conf.multicenter
)
4374 (fun v -> conf.multicenter
<- v; represent ());
4375 src#
string "trim fuzz"
4376 (fun () -> irect_to_string conf.trimfuzz
)
4379 conf.trimfuzz
<- irect_of_string v;
4381 then settrim true conf.trimfuzz
;
4383 state.text <- Printf.sprintf
"bad irect `%s': %s"
4384 v (Printexc.to_string exn
)
4386 src#
string "throttle"
4388 match conf.maxwait
with
4389 | None
-> "show place holder if page is not ready"
4392 then "wait for page to fully render"
4394 "wait " ^ string_of_float
time
4395 ^
" seconds before showing placeholder"
4399 let f = float_of_string
v in
4401 then conf.maxwait
<- None
4402 else conf.maxwait
<- Some
f
4404 state.text <- Printf.sprintf
"bad time `%s': %s"
4405 v (Printexc.to_string exn
)
4407 src#
string "ghyll scroll"
4409 match conf.ghyllscroll
with
4411 | Some nab
-> ghyllscroll_to_string nab
4416 if String.length
v = 0
4418 else Some
(ghyllscroll_of_string v)
4420 conf.ghyllscroll
<- gs
4422 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4423 v (Printexc.to_string exn
)
4425 src#
string "selection command"
4426 (fun () -> conf.selcmd
)
4427 (fun v -> conf.selcmd
<- v);
4428 src#colorspace
"color space"
4429 (fun () -> colorspace_to_string conf.colorspace
)
4431 conf.colorspace
<- colorspace_of_int v;
4438 src#caption
"Document" 0;
4439 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4440 src#caption2
"Pages"
4441 (fun () -> string_of_int
state.pagecount
) 1;
4442 src#caption2
"Dimensions"
4443 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4447 src#caption
"Trimmed margins" 0;
4448 src#caption2
"Dimensions"
4449 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4453 src#caption
"OpenGL" 0;
4454 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4455 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4456 src#reset prevmode prevuioh
;
4460 let prevmode = state.mode
4461 and prevuioh
= state.uioh in
4462 fillsrc prevmode prevuioh
;
4463 let source = (src :> lvsource
) in
4464 let modehash = findkeyhash conf "info" in
4465 state.uioh <- coe (object (self)
4466 inherit listview ~
source ~trusted
:true ~
modehash as super
4467 val mutable m_prevmemused
= 0
4468 method infochanged
= function
4470 if m_prevmemused
!= state.memused
4472 m_prevmemused
<- state.memused
;
4473 G.postRedisplay "memusedchanged";
4475 | Pdim
-> G.postRedisplay "pdimchanged"
4476 | Docinfo
-> fillsrc prevmode prevuioh
4478 method key key mask
=
4479 if not
(Wsi.withctrl mask
)
4482 | 0xff51 -> coe (self#updownlevel ~
-1)
4483 | 0xff53 -> coe (self#updownlevel
1)
4484 | _ -> super#
key key mask
4485 else super#
key key mask
4487 G.postRedisplay "info";
4493 inherit lvsourcebase
4494 method getitemcount
= Array.length
state.help
4496 let s, n, _ = state.help
.(n) in
4499 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4503 m_qsearch
<- qsearch;
4504 match state.help
.(active) with
4505 | _, _, Action
f -> Some
(f uioh)
4515 method hasaction
n =
4516 match state.help
.(n) with
4517 | _, _, Action
_ -> true
4524 let modehash = findkeyhash conf "help" in
4525 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4526 G.postRedisplay "help";
4531 let re = Str.regexp
"[\r\n]" in
4533 inherit lvsourcebase
4534 val mutable m_items
= [||]
4536 method getitemcount
= 1 + Array.length m_items
4541 else m_items
.(n-1), 0
4543 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4548 then Buffer.clear
state.errmsgs
;
4549 m_qsearch
<- qsearch;
4556 method hasaction
n =
4560 state.newerrmsgs
<- false;
4561 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4562 m_items
<- Array.of_list
l
4570 let source = (msgsource :> lvsource
) in
4571 let modehash = findkeyhash conf "listview" in
4572 state.uioh <- coe (object
4573 inherit listview ~
source ~trusted
:false ~
modehash as super
4576 then msgsource#reset
;
4579 G.postRedisplay "msgs";
4582 let quickbookmark ?title
() =
4583 match state.layout with
4589 let sec = Unix.gettimeofday
() in
4590 let tm = Unix.localtime
sec in
4591 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4595 (tm.Unix.tm_year
+ 1900)
4598 | Some
title -> title
4600 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4604 state.fullscreen
<- None
;
4608 let setautoscrollspeed step goingdown
=
4609 let incr = max
1 ((abs step
) / 2) in
4610 let incr = if goingdown
then incr else -incr in
4611 let astep = step
+ incr in
4612 state.autoscroll
<- Some
astep;
4615 let gotounder = function
4616 | Ulinkgoto
(pageno, top) ->
4620 gotopage1 pageno top;
4626 | Uremote
(filename
, pageno) ->
4628 if Sys.file_exists filename
4631 let dir = Filename.dirname
state.path in
4632 let path = Filename.concat
dir filename
in
4633 if Sys.file_exists
path
4637 if String.length
path > 0
4639 let anchor = getanchor () in
4640 let ranchor = state.path, state.password
, anchor in
4641 state.anchor <- (pageno, 0.0, 0.0);
4642 state.ranchors
<- ranchor :: state.ranchors
;
4645 else showtext '
!'
("Could not find " ^ filename
)
4647 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4651 match conf.columns
with
4653 | _ -> conf.zoom > 1.0
4656 let viewkeyboard key mask
=
4658 let mode = state.mode in
4659 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4662 G.postRedisplay "view:enttext"
4664 let ctrl = Wsi.withctrl mask
in
4669 | 0xff63 -> (* insert *)
4670 if conf.angle
mod 360 = 0
4672 state.mode <- LinkNav
(Ltgendir
0);
4675 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4677 | 0xff1b | 113 -> (* escape / q *)
4678 begin match state.mstate
with
4680 state.mstate
<- Mnone
;
4681 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4682 G.postRedisplay "kill zoom rect";
4684 match state.ranchors
with
4686 | (path, password
, anchor) :: rest
->
4687 state.ranchors
<- rest
;
4688 state.anchor <- anchor;
4689 opendoc path password
4692 | 0xff08 -> (* backspace *)
4693 let y = getnav ~
-1 in
4694 gotoy_and_clear_text y
4702 G.postRedisplay "dehighlight";
4704 | 47 | 63 -> (* / ? *)
4705 let ondone isforw
s =
4706 cbput state.hists
.pat
s;
4707 state.searchpattern
<- s;
4710 let s = String.create
1 in
4711 s.[0] <- Char.chr
key;
4712 enttext (s, "", Some
(onhist state.hists
.pat
),
4713 textentry, ondone (key = 47), true)
4715 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4716 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4717 setzoom (conf.zoom +. incr)
4719 | 43 | 0xffab -> (* + *)
4722 try int_of_string
s with exc
->
4723 state.text <- Printf.sprintf
"bad integer `%s': %s"
4724 s (Printexc.to_string exc
);
4730 state.text <- "page bias is now " ^ string_of_int
n;
4733 enttext ("page bias: ", "", None
, intentry, ondone, true)
4735 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4736 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4737 setzoom (max
0.01 (conf.zoom -. decr))
4739 | 45 | 0xffad -> (* - *)
4740 let ondone msg
= state.text <- msg
in
4742 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4743 optentry state.mode, ondone, true
4746 | 48 when ctrl -> (* ctrl-0 *)
4749 | 49 when ctrl -> (* ctrl-1 *)
4751 match conf.columns
with
4752 | Csingle
_ | Cmulti
_ -> 1
4753 | Csplit
(n, _) -> n
4755 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4759 | 0xffc6 -> (* f9 *)
4762 | 57 when ctrl -> (* ctrl-9 *)
4765 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4766 when not
ctrl -> (* 0..9 *)
4769 try int_of_string
s with exc
->
4770 state.text <- Printf.sprintf
"bad integer `%s': %s"
4771 s (Printexc.to_string exc
);
4777 cbput state.hists
.pag
(string_of_int
n);
4778 gotopage1 (n + conf.pagebias
- 1) 0;
4781 let pageentry text key =
4782 match Char.unsafe_chr
key with
4783 | 'g'
-> TEdone
text
4784 | _ -> intentry text key
4786 let text = "x" in text.[0] <- Char.chr
key;
4787 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4790 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4791 reshape conf.winw
conf.winh
;
4794 conf.hlinks
<- not
conf.hlinks
;
4795 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4796 G.postRedisplay "toggle highlightlinks";
4799 state.glinks
<- true;
4800 let mode = state.mode in
4801 state.mode <- Textentry
(
4802 (":", "", None
, linknentry, linkndone (fun under ->
4807 state.glinks
<- false;
4811 G.postRedisplay "view:linkent(F)"
4814 state.glinks
<- true;
4815 let mode = state.mode in
4816 state.mode <- Textentry
(
4817 (":", "", None
, linknentry, linkndone (fun under ->
4818 match Ne.pipe () with
4820 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4821 (Printexc.to_string exn
));
4824 try popen conf.selcmd
[r, 0; w, -1]; true
4827 (Printf.sprintf
"failed to execute %s: %s"
4828 conf.selcmd
(Printexc.to_string exn
));
4832 Ne.clo fd
(fun msg
->
4833 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4836 let s = undertext under in
4840 let l = String.length
s in
4841 let n = Unix.write
w s 0 l in
4846 "failed to write %d characters to sel pipe, wrote %d"
4851 (Printf.sprintf
"failed to write to sel pipe: %s"
4852 (Printexc.to_string exn
)
4861 state.glinks
<- false;
4865 G.postRedisplay "view:linkent"
4868 begin match state.autoscroll
with
4870 conf.autoscrollstep
<- step
;
4871 state.autoscroll
<- None
4873 if conf.autoscrollstep
= 0
4874 then state.autoscroll
<- Some
1
4875 else state.autoscroll
<- Some
conf.autoscrollstep
4878 | 112 when ctrl -> (* ctrl-p *)
4882 setpresentationmode (not
conf.presentation
);
4883 showtext ' '
("presentation mode " ^
4884 if conf.presentation
then "on" else "off");
4887 begin match state.fullscreen
with
4889 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4892 state.fullscreen
<- None
;
4897 gotoy_and_clear_text 0
4900 gotopage1 (state.pagecount
- 1) 0
4902 | 112 | 78 -> (* p|N *)
4903 search state.searchpattern
false
4905 | 110 | 0xffc0 -> (* n|F3 *)
4906 search state.searchpattern
true
4909 begin match state.layout with
4912 gotoy_and_clear_text (getpagey l.pageno)
4916 begin match state.layout with
4919 match conf.columns
with
4920 | Csingle
_ | Cmulti
_ ->
4921 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4923 let y = clamp (pgscale conf.winh
) in
4924 gotoy_and_clear_text y
4926 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4927 gotoy_and_clear_text (getpagey pageno)
4929 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4931 let pagey, pageh
= getpageyh l.pageno in
4932 let pagey = pagey + pageh
* l.pagecol
in
4933 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4934 gotoy_and_clear_text (pagey + pageh
+ ips)
4937 | 0xff9f | 0xffff -> (* delete *)
4938 begin match state.layout with
4941 match conf.columns
with
4942 | Csingle
_ | Cmulti
_ ->
4943 if conf.presentation
&& l.pagey != 0
4945 gotoy_and_clear_text (clamp (pgscale ~
-(conf.winh
)))
4947 let pageno = max
0 (l.pageno-1) in
4948 gotoy_and_clear_text (getpagey pageno)
4956 let pageno = max
0 (l.pageno-1) in
4957 let pagey, pageh
= getpageyh pageno in
4960 let pagey, pageh
= getpageyh l.pageno in
4961 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4963 gotoy_and_clear_text y
4967 showtext ' '
(describe_location ());
4970 begin match state.layout with
4973 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4978 enterbookmarkmode ()
4980 | 104 | 0xffbe -> (* h|F1 *)
4986 | 101 when conf.redirectstderr -> (* e *)
4991 match state.layout with
4992 | l :: _ -> state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
4995 enttext ("bookmark: ", "", None
, textentry, ondone, true)
4999 showtext ' '
"Quick bookmark added";
5002 begin match state.layout with
5004 let rect = getpdimrect
l.pagedimno
in
5008 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5009 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5011 (truncate
(rect.(1) -. rect.(0)),
5012 truncate
(rect.(3) -. rect.(0)))
5014 let w = truncate
((float w)*.conf.zoom)
5015 and h = truncate
((float h)*.conf.zoom) in
5018 state.anchor <- getanchor ();
5019 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5021 G.postRedisplay "z";
5026 | 50 when ctrl -> (* ctrl-2 *)
5027 let maxw = getmaxw
() in
5029 then setzoom (maxw /. float conf.winw
)
5031 | 60 | 62 -> (* < > *)
5032 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5034 | 91 | 93 -> (* [ ] *)
5036 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5038 G.postRedisplay "brightness";
5040 | 99 when state.mode = View
-> (* c *)
5042 match state.prevcolumns
with
5043 | None
-> (1, 0, 0), 1.0
5044 | Some
(columns
, z
) ->
5047 | Csplit
(c, _) -> -c, 0, 0
5048 | Cmulti
((c, a, b), _) -> c, a, b
5049 | Csingle
_ -> 1, 0, 0
5053 setcolumns View
c a b;
5056 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5057 setzoom state.prevzoom
5059 | 107 | 0xff52 -> (* k up *)
5060 begin match state.autoscroll
with
5062 begin match state.mode with
5063 | Birdseye beye
-> upbirdseye 1 beye
5066 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5067 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5070 setautoscrollspeed n false
5073 | 106 | 0xff54 -> (* j down *)
5074 begin match state.autoscroll
with
5076 begin match state.mode with
5077 | Birdseye beye
-> downbirdseye 1 beye
5080 then gotoy_and_clear_text (clamp (conf.winh
/2))
5081 else gotoy_and_clear_text (clamp conf.scrollstep
)
5084 setautoscrollspeed n true
5087 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5095 let dx = if key = 0xff51 then dx else -dx in
5096 state.x <- state.x + dx;
5097 gotoy_and_clear_text state.y
5100 G.postRedisplay "lef/right"
5103 | 0xff55 -> (* prior *)
5107 match state.layout with
5109 | l :: _ -> state.y - l.pagey
5111 clamp (pgscale (-conf.winh
))
5115 | 0xff56 -> (* next *)
5119 match List.rev
state.layout with
5121 | l :: _ -> getpagey l.pageno
5123 clamp (pgscale conf.winh
)
5127 | 0xff50 -> (* home *)
5129 | 0xff57 -> (* end *)
5130 gotoghyll (clamp state.maxy)
5131 | 0xff53 when Wsi.withalt mask
-> (* right *)
5132 gotoghyll (getnav ~
-1)
5133 | 0xff51 when Wsi.withalt mask
-> (* left *)
5134 gotoghyll (getnav 1)
5137 state.anchor <- getanchor ();
5138 opendoc state.path state.password
5140 | 118 when conf.debug
-> (* v *)
5143 match getopaque l.pageno with
5146 let x0, y0, x1, y1 = pagebbox opaque
in
5147 let a,b = float x0, float y0 in
5148 let c,d = float x1, float y0 in
5149 let e,f = float x1, float y1 in
5150 let h,j
= float x0, float y1 in
5151 let rect = (a,b,c,d,e,f,h,j
) in
5153 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5155 G.postRedisplay "v";
5158 vlog "huh? %s" (Wsi.keyname
key)
5161 let linknavkeyboard key mask
linknav =
5162 let getpage pageno =
5163 let rec loop = function
5165 | l :: _ when l.pageno = pageno -> Some
l
5166 | _ :: rest
-> loop rest
5167 in loop state.layout
5169 let doexact (pageno, n) =
5170 match getopaque pageno, getpage pageno with
5171 | Some opaque
, Some
l ->
5174 let under = getlink opaque
n in
5175 G.postRedisplay "link gotounder";
5181 | 0xff50 -> (* home *)
5182 Some
(findlink opaque LDfirst
), -1
5184 | 0xff57 -> (* end *)
5185 Some
(findlink opaque LDlast
), 1
5187 | 0xff51 -> (* left *)
5188 Some
(findlink opaque
(LDleft
n)), -1
5190 | 0xff53 -> (* right *)
5191 Some
(findlink opaque
(LDright
n)), 1
5193 | 0xff52 -> (* up *)
5194 Some
(findlink opaque
(LDup
n)), -1
5196 | 0xff54 -> (* down *)
5197 Some
(findlink opaque
(LDdown
n)), 1
5202 begin match findpwl
l.pageno dir with
5206 state.mode <- LinkNav
(Ltgendir
dir);
5207 let y, h = getpageyh pageno in
5210 then y + h - conf.winh
5215 begin match getopaque pageno, getpage pageno with
5216 | Some opaque
, Some
_ ->
5218 let ld = if dir > 0 then LDfirst
else LDlast
in
5221 begin match link with
5223 showlinktype (getlink opaque
m);
5224 state.mode <- LinkNav
(Ltexact
(pageno, m));
5225 G.postRedisplay "linknav jpage";
5232 begin match opt with
5233 | Some Lnotfound
-> pwl l dir;
5234 | Some
(Lfound
m) ->
5238 let _, y0, _, y1 = getlinkrect opaque
m in
5240 then gotopage1 l.pageno y0
5242 let d = fstate.fontsize
+ 1 in
5243 if y1 - l.pagey > l.pagevh - d
5244 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5245 else G.postRedisplay "linknav";
5247 showlinktype (getlink opaque
m);
5248 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5251 | None
-> viewkeyboard key mask
5253 | _ -> viewkeyboard key mask
5258 G.postRedisplay "leave linknav"
5262 | Ltgendir
_ -> viewkeyboard key mask
5263 | Ltexact exact
-> doexact exact
5266 let keyboard key mask
=
5267 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5268 then wcmd "interrupt"
5269 else state.uioh <- state.uioh#
key key mask
5272 let birdseyekeyboard key mask
5273 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5275 match conf.columns
with
5277 | Cmulti
((c, _, _), _) -> c
5278 | Csplit
_ -> failwith
"bird's eye split mode"
5280 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5282 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5283 let y, h = getpageyh pageno in
5284 let top = (conf.winh
- h) / 2 in
5285 gotoy (max
0 (y - top))
5286 | 0xff0d -> leavebirdseye beye
false
5287 | 0xff1b -> leavebirdseye beye
true (* escape *)
5288 | 0xff52 -> upbirdseye incr beye
(* up *)
5289 | 0xff54 -> downbirdseye incr beye
(* down *)
5290 | 0xff51 -> upbirdseye 1 beye
(* left *)
5291 | 0xff53 -> downbirdseye 1 beye
(* right *)
5293 | 0xff55 -> (* prior *)
5294 begin match state.layout with
5298 state.mode <- Birdseye
(
5299 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5301 gotopage1 l.pageno 0;
5304 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5306 | [] -> gotoy (clamp (-conf.winh
))
5308 state.mode <- Birdseye
(
5309 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5311 gotopage1 l.pageno 0
5314 | [] -> gotoy (clamp (-conf.winh
))
5317 | 0xff56 -> (* next *)
5318 begin match List.rev
state.layout with
5320 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5321 begin match layout with
5323 let incr = l.pageh
- l.pagevh in
5328 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5330 G.postRedisplay "birdseye pagedown";
5332 else gotoy (clamp (incr + conf.interpagespace
*2));
5336 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5337 gotopage1 l.pageno 0;
5340 | [] -> gotoy (clamp conf.winh
)
5343 | 0xff50 -> (* home *)
5344 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5347 | 0xff57 -> (* end *)
5348 let pageno = state.pagecount
- 1 in
5349 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5350 if not
(pagevisible state.layout pageno)
5353 match List.rev
state.pdims
with
5355 | (_, _, h, _) :: _ -> h
5357 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5358 else G.postRedisplay "birdseye end";
5359 | _ -> viewkeyboard key mask
5362 let drawpage l linkindexbase
=
5364 match state.mode with
5365 | Textentry
_ -> scalecolor 0.4
5367 | View
-> scalecolor 1.0
5368 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5369 if l.pageno = hooverpageno
5372 if l.pageno = pageno
5378 begin match getopaque l.pageno with
5380 if tileready l l.pagex
l.pagey
5382 let x = l.pagedispx - l.pagex
5383 and y = l.pagedispy - l.pagey in
5385 match conf.columns
with
5386 | Csingle
_ | Cmulti
_ ->
5387 (if conf.hlinks
then 1 else 0)
5389 && not
(isbirdseye state.mode) then 2 else 0)
5393 match state.mode with
5394 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5397 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5404 let scrollindicator () =
5405 let sbw, ph
, sh = state.uioh#
scrollph in
5406 let sbh, pw, sw = state.uioh#scrollpw
in
5408 GlDraw.color (0.64, 0.64, 0.64);
5410 (float (conf.winw
- sbw), 0.)
5411 (float conf.winw
, float conf.winh
)
5414 (0., float (conf.winh
- sbh))
5415 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5417 GlDraw.color (0.0, 0.0, 0.0);
5420 (float (conf.winw
- sbw), ph
)
5421 (float conf.winw
, ph
+. sh)
5424 (pw, float (conf.winh
- sbh))
5425 (pw +. sw, float conf.winh
)
5430 match state.mstate
with
5431 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5434 | Msel
((x0, y0), (x1, y1)) ->
5435 let rec loop = function
5437 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5438 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5439 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5440 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5442 match getopaque l.pageno with
5444 let x0, y0 = pagetranslatepoint l x0 y0 in
5445 let x1, y1 = pagetranslatepoint l x1 y1 in
5446 seltext opaque
(x0, y0, x1, y1);
5454 let showrects rects
=
5456 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5457 GlDraw.polygon_mode `both `fill
;
5458 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5460 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5462 if l.pageno = pageno
5464 let dx = float (l.pagedispx - l.pagex
) in
5465 let dy = float (l.pagedispy - l.pagey) in
5466 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5467 GlDraw.begins `quads
;
5469 GlDraw.vertex2
(x0+.dx, y0+.dy);
5470 GlDraw.vertex2
(x1+.dx, y1+.dy);
5471 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5472 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5483 GlClear.color (scalecolor2 conf.bgcolor
);
5484 GlClear.clear
[`
color];
5485 let rec loop linkindexbase
= function
5487 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5488 loop linkindexbase rest
5491 loop 0 state.layout;
5493 match state.mode with
5494 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5495 begin match getopaque pageno with
5497 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5504 | None
-> state.rects
5511 begin match state.mstate
with
5512 | Mzoomrect
((x0, y0), (x1, y1)) ->
5514 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5515 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5516 GlDraw.rect (float x0, float y0)
5517 (float x1, float y1);
5526 let zoomrect x y x1 y1 =
5529 and y0 = min
y y1 in
5530 gotoy (state.y + y0);
5531 state.anchor <- getanchor ();
5532 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5534 if state.w < conf.winw
- state.scrollw
5535 then (conf.winw
- state.scrollw
- state.w) / 2
5538 state.x <- (state.x + margin) - x0;
5540 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5541 state.mstate
<- Mnone
;
5545 let winw = conf.winw - state.scrollw
- 1 in
5546 let s = float x /. float winw in
5547 let destx = truncate
(float (state.w + winw) *. s) in
5548 state.x <- winw - destx;
5549 gotoy_and_clear_text state.y;
5550 state.mstate
<- Mscrollx
;
5554 let s = float y /. float conf.winh
in
5555 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5556 gotoy_and_clear_text desty;
5557 state.mstate
<- Mscrolly
;
5560 let viewmouse button down
x y mask
=
5562 | n when (n == 4 || n == 5) && not down
->
5563 if Wsi.withctrl mask
5565 match state.mstate
with
5566 | Mzoom
(oldn
, i
) ->
5574 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5576 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5578 let zoom = conf.zoom -. incr in
5580 state.mstate
<- Mzoom
(n, 0);
5582 state.mstate
<- Mzoom
(n, i
+1);
5584 else state.mstate
<- Mzoom
(n, 0)
5586 | _ -> state.mstate
<- Mzoom
(n, 0)
5589 match state.autoscroll
with
5590 | Some step
-> setautoscrollspeed step
(n=4)
5594 then -conf.scrollstep
5595 else conf.scrollstep
5597 let incr = incr * 2 in
5598 let y = clamp incr in
5599 gotoy_and_clear_text y
5602 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5603 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5604 gotoy_and_clear_text state.y
5606 | 1 when Wsi.withctrl mask
->
5609 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5610 state.mstate
<- Mpan
(x, y)
5613 state.mstate
<- Mnone
5618 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5620 state.mstate
<- Mzoomrect
(p, p)
5623 match state.mstate
with
5624 | Mzoomrect
((x0, y0), _) ->
5625 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5626 then zoomrect x0 y0 x y
5628 state.mstate
<- Mnone
;
5629 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5630 G.postRedisplay "kill accidental zoom rect";
5633 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5634 state.mstate
<- Mnone
5637 | 1 when x > conf.winw - state.scrollw
->
5640 let _, position, sh = state.uioh#
scrollph in
5641 if y > truncate
position && y < truncate
(position +. sh)
5642 then state.mstate
<- Mscrolly
5645 state.mstate
<- Mnone
5647 | 1 when y > conf.winh
- state.hscrollh ->
5650 let _, position, sw = state.uioh#scrollpw
in
5651 if x > truncate
position && x < truncate
(position +. sw)
5652 then state.mstate
<- Mscrollx
5655 state.mstate
<- Mnone
5658 let dest = if down
then getunder x y else Unone
in
5659 begin match dest with
5663 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5666 | Unone
when down
->
5667 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5668 state.mstate
<- Mpan
(x, y);
5670 | Unone
| Utext
_ ->
5673 if conf.angle
mod 360 = 0
5675 state.mstate
<- Msel
((x, y), (x, y));
5676 G.postRedisplay "mouse select";
5680 match state.mstate
with
5683 | Mzoom
_ | Mscrollx
| Mscrolly
->
5684 state.mstate
<- Mnone
5686 | Mzoomrect
((x0, y0), _) ->
5690 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5691 state.mstate
<- Mnone
5693 | Msel
((_, y0), (_, y1)) ->
5694 let rec loop = function
5697 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5698 || ((y1 >= l.pagedispy
5699 && y1 <= (l.pagedispy + l.pagevh)))
5701 match getopaque l.pageno with
5704 match Ne.pipe () with
5708 "can not create sel pipe: %s"
5709 (Printexc.to_string exn
));
5711 let doclose what fd
=
5712 Ne.clo fd
(fun msg
->
5713 dolog "%s close failed: %s" what msg
)
5716 popen conf.selcmd
[r, 0; w, -1];
5719 G.postRedisplay "copysel";
5721 dolog "can not execute %S: %s"
5722 conf.selcmd
(Printexc.to_string exn
);
5730 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5731 state.mstate
<- Mnone
;
5738 let birdseyemouse button down
x y mask
5739 (conf, leftx
, _, hooverpageno
, anchor) =
5742 let rec loop = function
5745 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5746 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5748 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5754 | _ -> viewmouse button down
x y mask
5757 let mouse button down
x y mask
=
5758 state.uioh <- state.uioh#button button down
x y mask
;
5762 state.uioh <- state.uioh#
motion x y
5766 state.uioh <- state.uioh#
pmotion x y;
5772 method key key mask
=
5773 begin match state.mode with
5774 | Textentry
textentry -> textentrykeyboard key mask
textentry
5775 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5776 | View
-> viewkeyboard key mask
5777 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5781 method button button bstate
x y mask
=
5782 begin match state.mode with
5784 | View
-> viewmouse button bstate
x y mask
5785 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5791 begin match state.mode with
5793 | View
| Birdseye
_ | LinkNav
_ ->
5794 match state.mstate
with
5795 | Mzoom
_ | Mnone
-> ()
5800 state.mstate
<- Mpan
(x, y);
5802 then state.x <- state.x + dx;
5804 gotoy_and_clear_text y
5807 state.mstate
<- Msel
(a, (x, y));
5808 G.postRedisplay "motion select";
5811 let y = min
conf.winh
(max
0 y) in
5815 let x = min
conf.winw (max
0 x) in
5818 | Mzoomrect
(p0
, _) ->
5819 state.mstate
<- Mzoomrect
(p0
, (x, y));
5820 G.postRedisplay "motion zoomrect";
5824 method pmotion x y =
5825 begin match state.mode with
5826 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5827 let rec loop = function
5829 if hooverpageno
!= -1
5831 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5832 G.postRedisplay "pmotion birdseye no hoover";
5835 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5836 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5838 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5839 G.postRedisplay "pmotion birdseye hoover";
5849 match state.mstate
with
5850 | Mnone
-> updateunder x y
5851 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5856 method infochanged
_ = ()
5859 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5860 let p, h = scrollph state.y maxy in
5864 let winw = conf.winw - state.scrollw
- 1 in
5865 let fwinw = float winw in
5867 let sw = fwinw /. float state.w in
5868 let sw = fwinw *. sw in
5869 max
sw (float conf.scrollh
)
5872 let f = state.w+winw in
5873 let r = float (winw-state.x) /. float f in
5874 let p = fwinw *. r in
5878 if position +. sw > fwinw
5879 then fwinw -. position
5882 state.hscrollh, position, sw
5886 match state.mode with
5887 | LinkNav
_ -> "links"
5888 | Textentry
_ -> "textentry"
5889 | Birdseye
_ -> "birdseye"
5892 findkeyhash conf modename
5899 let fontpath = ref "";;
5902 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5905 let l = String.length
s in
5906 let b = Buffer.create
l in
5912 try Sys.getenv
"HOME"
5915 ("Can not determine home directory location: " ^
5916 Printexc.to_string exn
);
5920 let modifier_of_string = function
5921 | "alt" -> Wsi.altmask
5922 | "shift" -> Wsi.shiftmask
5923 | "ctrl" | "control" -> Wsi.ctrlmask
5924 | "meta" -> Wsi.metamask
5929 let r = Str.regexp
"-" in
5931 let elems = Str.full_split
r s in
5934 let m1 = modifier_of_string s in
5936 then (Wsi.namekey
s, m)
5939 | Str.Delim
s when n land 1 = 0 -> g s
5941 | Str.Delim
_ -> (k
, m)
5943 let rec loop n k
m = function
5946 let k, m = f n k m x in
5952 let keys_of_string =
5953 let r = Str.regexp
"[ \t]" in
5955 let elems = Str.split
r s in
5956 List.map
key_of_string elems
5959 let copykeyhashes c =
5960 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5963 let config_of c attrs
=
5967 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5968 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5969 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5970 | "preload" -> { c with preload = bool_of_string
v }
5971 | "page-bias" -> { c with pagebias
= int_of_string
v }
5972 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5973 | "horizontal-scroll-step" ->
5974 { c with hscrollstep
= max
(int_of_string
v) 1 }
5975 | "auto-scroll-step" ->
5976 { c with autoscrollstep
= max
0 (int_of_string
v) }
5977 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5978 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5981 match String.lowercase
v with
5982 | "true" -> Some infinity
5984 | f -> Some
(float_of_string
f)
5986 { c with maxwait
= mw}
5987 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5988 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5989 | "vertical-margin" ->
5990 { c with interpagespace
= max
0 (int_of_string
v) }
5992 let zoom = float_of_string
v /. 100. in
5993 let zoom = max
zoom 0.0 in
5994 { c with zoom = zoom }
5995 | "presentation" -> { c with presentation
= bool_of_string
v }
5996 | "rotation-angle" -> { c with angle
= int_of_string
v }
5997 | "width" -> { c with winw = max
20 (int_of_string
v) }
5998 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5999 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6000 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6001 | "pixmap-cache-size" ->
6002 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6003 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6004 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6005 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6006 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6007 | "background-color" -> { c with bgcolor
= color_of_string v }
6008 | "scrollbar-in-presentation" ->
6009 { c with scrollbarinpm
= bool_of_string
v }
6010 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6011 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6012 | "mupdf-store-size" ->
6013 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6014 | "checkers" -> { c with checkers
= bool_of_string
v }
6015 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6016 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6017 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6018 | "uri-launcher" -> { c with urilauncher
= unent v }
6019 | "path-launcher" -> { c with pathlauncher
= unent v }
6020 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6021 | "invert-colors" -> { c with invert
= bool_of_string
v }
6022 | "brightness" -> { c with colorscale
= float_of_string
v }
6023 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6025 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6027 let (n, _, _) as nab
= multicolumns_of_string v in
6029 then { c with columns
= Csplit
(-n, [||]) }
6030 else { c with columns
= Cmulti
(nab
, [||]) }
6031 | "birds-eye-columns" ->
6032 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6033 | "selection-command" -> { c with selcmd
= unent v }
6034 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6035 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6036 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6037 | "multi-column-centering" -> { c with multicenter
= bool_of_string
v }
6040 prerr_endline
("Error processing attribute (`" ^
6041 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6044 let rec fold c = function
6047 let c = apply c k v in
6050 fold { c with keyhashes
= copykeyhashes c } attrs
;
6053 let fromstring f pos
n v d =
6056 dolog "Error processing attribute (%S=%S) at %d\n%s"
6057 n v pos
(Printexc.to_string exn
)
6062 let bookmark_of attrs
=
6063 let rec fold title page
rely visy
= function
6064 | ("title", v) :: rest
-> fold v page
rely visy rest
6065 | ("page", v) :: rest
-> fold title v rely visy rest
6066 | ("rely", v) :: rest
-> fold title page
v visy rest
6067 | ("visy", v) :: rest
-> fold title page
rely v rest
6068 | _ :: rest
-> fold title page
rely visy rest
6069 | [] -> title, page
, rely, visy
6071 fold "invalid" "0" "0" "0" attrs
6075 let rec fold path page
rely pan visy
= function
6076 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6077 | ("page", v) :: rest
-> fold path v rely pan visy rest
6078 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6079 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6080 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6081 | _ :: rest
-> fold path page
rely pan visy rest
6082 | [] -> path, page
, rely, pan
, visy
6084 fold "" "0" "0" "0" "0" attrs
6088 let rec fold rs ls
= function
6089 | ("out", v) :: rest
-> fold v ls rest
6090 | ("in", v) :: rest
-> fold rs
v rest
6091 | _ :: rest
-> fold ls rs rest
6097 let setconf dst
src =
6098 dst
.scrollbw
<- src.scrollbw
;
6099 dst
.scrollh
<- src.scrollh
;
6100 dst
.icase
<- src.icase
;
6101 dst
.preload <- src.preload;
6102 dst
.pagebias
<- src.pagebias
;
6103 dst
.verbose
<- src.verbose
;
6104 dst
.scrollstep
<- src.scrollstep
;
6105 dst
.maxhfit
<- src.maxhfit
;
6106 dst
.crophack
<- src.crophack
;
6107 dst
.autoscrollstep
<- src.autoscrollstep
;
6108 dst
.maxwait
<- src.maxwait
;
6109 dst
.hlinks
<- src.hlinks
;
6110 dst
.underinfo
<- src.underinfo
;
6111 dst
.interpagespace
<- src.interpagespace
;
6112 dst
.zoom <- src.zoom;
6113 dst
.presentation
<- src.presentation
;
6114 dst
.angle
<- src.angle
;
6115 dst
.winw <- src.winw;
6116 dst
.winh
<- src.winh
;
6117 dst
.savebmarks
<- src.savebmarks
;
6118 dst
.memlimit
<- src.memlimit
;
6119 dst
.proportional
<- src.proportional
;
6120 dst
.texcount
<- src.texcount
;
6121 dst
.sliceheight
<- src.sliceheight
;
6122 dst
.thumbw
<- src.thumbw
;
6123 dst
.jumpback
<- src.jumpback
;
6124 dst
.bgcolor
<- src.bgcolor
;
6125 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6126 dst
.tilew
<- src.tilew
;
6127 dst
.tileh
<- src.tileh
;
6128 dst
.mustoresize
<- src.mustoresize
;
6129 dst
.checkers
<- src.checkers
;
6130 dst
.aalevel
<- src.aalevel
;
6131 dst
.trimmargins
<- src.trimmargins
;
6132 dst
.trimfuzz
<- src.trimfuzz
;
6133 dst
.urilauncher
<- src.urilauncher
;
6134 dst
.colorspace
<- src.colorspace
;
6135 dst
.invert
<- src.invert
;
6136 dst
.colorscale
<- src.colorscale
;
6137 dst
.redirectstderr <- src.redirectstderr;
6138 dst
.ghyllscroll
<- src.ghyllscroll
;
6139 dst
.columns
<- src.columns
;
6140 dst
.beyecolumns
<- src.beyecolumns
;
6141 dst
.selcmd
<- src.selcmd
;
6142 dst
.updatecurs
<- src.updatecurs
;
6143 dst
.pathlauncher
<- src.pathlauncher
;
6144 dst
.keyhashes
<- copykeyhashes src;
6145 dst
.hfsize
<- src.hfsize
;
6146 dst
.hscrollstep
<- src.hscrollstep
;
6147 dst
.pgscale <- src.pgscale;
6148 dst
.multicenter
<- src.multicenter
;
6152 let h = Hashtbl.create
10 in
6153 let dc = { defconf with angle
= defconf.angle
} in
6154 let rec toplevel v t spos
_ =
6156 | Vdata
| Vcdata
| Vend
-> v
6157 | Vopen
("llppconfig", _, closed
) ->
6160 else { v with f = llppconfig
}
6162 error
"unexpected subelement at top level" s spos
6163 | Vclose
_ -> error
"unexpected close at top level" s spos
6165 and llppconfig
v t spos
_ =
6167 | Vdata
| Vcdata
-> v
6168 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6169 | Vopen
("defaults", attrs
, closed
) ->
6170 let c = config_of dc attrs
in
6174 else { v with f = defaults
}
6176 | Vopen
("ui-font", attrs
, closed
) ->
6177 let rec getsize size
= function
6179 | ("size", v) :: rest
->
6181 fromstring int_of_string spos
"size" v fstate.fontsize
in
6183 | l -> getsize size l
6185 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6188 else { v with f = uifont
(Buffer.create
10) }
6190 | Vopen
("doc", attrs
, closed
) ->
6191 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6192 let path = unent pathent
6193 and pageno = fromstring int_of_string spos
"page" spage
0
6194 and rely = fromstring float_of_string spos
"rely" srely
0.0
6195 and pan
= fromstring int_of_string spos
"pan" span
0
6196 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6197 let c = config_of dc attrs
in
6198 let anchor = (pageno, rely, visy
) in
6200 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6201 else { v with f = doc
path pan
anchor c [] }
6204 error
"unexpected subelement in llppconfig" s spos
6206 | Vclose
"llppconfig" -> { v with f = toplevel }
6207 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6209 and defaults
v t spos
_ =
6211 | Vdata
| Vcdata
-> v
6212 | Vend
-> error
"unexpected end of input in defaults" s spos
6213 | Vopen
("keymap", attrs
, closed
) ->
6215 try List.assoc
"mode" attrs
6216 with Not_found
-> "global" in
6221 let h = findkeyhash dc modename in
6222 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6225 { v with f = pkeymap
ret KeyMap.empty }
6227 | Vopen
(_, _, _) ->
6228 error
"unexpected subelement in defaults" s spos
6230 | Vclose
"defaults" ->
6231 { v with f = llppconfig
}
6233 | Vclose
_ -> error
"unexpected close in defaults" s spos
6235 and uifont
b v t spos
epos =
6238 Buffer.add_substring
b s spos
(epos - spos
);
6240 | Vopen
(_, _, _) ->
6241 error
"unexpected subelement in ui-font" s spos
6242 | Vclose
"ui-font" ->
6243 if String.length
!fontpath = 0
6244 then fontpath := Buffer.contents
b;
6245 { v with f = llppconfig
}
6246 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6247 | Vend
-> error
"unexpected end of input in ui-font" s spos
6249 and doc
path pan
anchor c bookmarks
v t spos
_ =
6251 | Vdata
| Vcdata
-> v
6252 | Vend
-> error
"unexpected end of input in doc" s spos
6253 | Vopen
("bookmarks", _, closed
) ->
6256 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6258 | Vopen
("keymap", attrs
, closed
) ->
6260 try List.assoc
"mode" attrs
6261 with Not_found
-> "global"
6267 let h = findkeyhash c modename in
6268 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6269 doc
path pan
anchor c bookmarks
6271 { v with f = pkeymap
ret KeyMap.empty }
6273 | Vopen
(_, _, _) ->
6274 error
"unexpected subelement in doc" s spos
6277 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6278 { v with f = llppconfig
}
6280 | Vclose
_ -> error
"unexpected close in doc" s spos
6282 and pkeymap
ret keymap
v t spos
_ =
6284 | Vdata
| Vcdata
-> v
6285 | Vend
-> error
"unexpected end of input in keymap" s spos
6286 | Vopen
("map", attrs
, closed
) ->
6287 let r, l = map_of attrs
in
6288 let kss = fromstring keys_of_string spos
"in" r [] in
6289 let lss = fromstring keys_of_string spos
"out" l [] in
6293 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6294 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6297 then { v with f = pkeymap
ret keymap }
6300 { v with f = skip
"map" f }
6303 error
"unexpected subelement in keymap" s spos
6305 | Vclose
"keymap" ->
6306 { v with f = ret keymap }
6308 | Vclose
_ -> error
"unexpected close in keymap" s spos
6310 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6312 | Vdata
| Vcdata
-> v
6313 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6314 | Vopen
("item", attrs
, closed
) ->
6315 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6316 let page = fromstring int_of_string spos
"page" spage
0
6317 and rely = fromstring float_of_string spos
"rely" srely
0.0
6318 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6320 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6323 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6326 { v with f = skip
"item" f }
6329 error
"unexpected subelement in bookmarks" s spos
6331 | Vclose
"bookmarks" ->
6332 { v with f = doc
path pan
anchor c bookmarks }
6334 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6336 and skip tag
f v t spos
_ =
6338 | Vdata
| Vcdata
-> v
6340 error
("unexpected end of input in skipped " ^ tag
) s spos
6341 | Vopen
(tag'
, _, closed
) ->
6345 let f'
() = { v with f = skip tag
f } in
6346 { v with f = skip tag'
f'
}
6350 else error
("unexpected close in skipped " ^ tag
) s spos
6353 parse
{ f = toplevel; accu = () } s;
6359 let len = in_channel_length ic
in
6360 let s = String.create
len in
6361 really_input ic
s 0 len;
6364 | Parse_error
(msg
, s, pos
) ->
6365 let subs = subs s pos
in
6366 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6367 failwith
("parse error: " ^
s)
6370 failwith
("config load error: " ^
Printexc.to_string exn
)
6376 let dir = Filename.concat
home ".config" in
6377 if Sys.is_directory
dir then dir else home
6380 Filename.concat
dir "llpp.conf"
6383 let confpath = ref defconfpath;;
6386 if Sys.file_exists
!confpath
6389 (try Some
(open_in_bin
!confpath)
6392 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6393 Printexc.to_string exn
);
6402 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6403 Printexc.to_string exn
);
6409 f (Hashtbl.create
0, defconf)
6414 let pc, pb
, px, pa
=
6416 Hashtbl.find h (Filename.basename
state.path)
6417 with Not_found
-> dc, [], 0, emptyanchor
6421 state.bookmarks <- pb
;
6423 state.scrollw
<- conf.scrollbw
;
6425 then state.anchor <- pa
;
6426 cbput state.hists
.nav pa
;
6431 let add_attrs bb always
dc c =
6434 then Printf.bprintf bb
"\n %s='%b'" s a
6437 then Printf.bprintf bb
"\n %s='%d'" s a
6440 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6443 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6446 then Printf.bprintf bb
"\n %s='%f'" s a
6450 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6454 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6458 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6462 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6468 | Some
(_N
, _A
, _B
) ->
6469 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6479 else string_of_float
f
6481 Printf.bprintf bb
"\n %s='%s'" s v
6486 | Cmulti
((n, a, b), _) when n > 1 ->
6487 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6488 | Csplit
(n, _) when n > 1 ->
6489 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6495 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6500 then dc.winw, dc.winh
6502 match state.fullscreen
with
6504 | None
-> c.winw, c.winh
6506 oi
"width" w dc.winw;
6507 oi
"height" h dc.winh
;
6508 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6509 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6510 ob "case-insensitive-search" c.icase
dc.icase
;
6511 ob "preload" c.preload dc.preload;
6512 oi
"page-bias" c.pagebias
dc.pagebias
;
6513 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6514 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6515 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6516 ob "crop-hack" c.crophack
dc.crophack
;
6517 oW
"throttle" c.maxwait
dc.maxwait
;
6518 ob "highlight-links" c.hlinks
dc.hlinks
;
6519 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6520 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6521 oz
"zoom" c.zoom dc.zoom;
6522 ob "presentation" c.presentation
dc.presentation
;
6523 oi
"rotation-angle" c.angle
dc.angle
;
6524 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6525 ob "proportional-display" c.proportional
dc.proportional
;
6526 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6527 oi
"tex-count" c.texcount
dc.texcount
;
6528 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6529 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6530 ob "persistent-location" c.jumpback
dc.jumpback
;
6531 oc
"background-color" c.bgcolor
dc.bgcolor
;
6532 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6533 oi
"tile-width" c.tilew
dc.tilew
;
6534 oi
"tile-height" c.tileh
dc.tileh
;
6535 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6536 ob "checkers" c.checkers
dc.checkers
;
6537 oi
"aalevel" c.aalevel
dc.aalevel
;
6538 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6539 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6540 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6541 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6542 oC
"color-space" c.colorspace
dc.colorspace
;
6543 ob "invert-colors" c.invert
dc.invert
;
6544 oF
"brightness" c.colorscale
dc.colorscale
;
6545 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6546 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6547 oco
"columns" c.columns
dc.columns
;
6548 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6549 os
"selection-command" c.selcmd
dc.selcmd
;
6550 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6551 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6552 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6553 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6554 ob "multi-column-centering" c.multicenter
dc.multicenter
;
6557 let keymapsbuf always
dc c =
6558 let bb = Buffer.create
16 in
6559 let rec loop = function
6561 | (modename, h) :: rest
->
6562 let dh = findkeyhash dc modename in
6563 if always
|| h <> dh
6565 if Hashtbl.length
h > 0
6567 if Buffer.length
bb > 0
6568 then Buffer.add_char
bb '
\n'
;
6569 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6570 Hashtbl.iter
(fun i
o ->
6571 let isdifferent = always
||
6573 let dO = Hashtbl.find dh i
in
6575 with Not_found
-> true
6580 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6581 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6582 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6583 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6584 Buffer.add_string
bb (Wsi.keyname
k);
6587 let rec loop = function
6589 | km
:: [] -> addkm km
6590 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6594 Buffer.add_string
bb "<map in='";
6598 Buffer.add_string
bb "' out='";
6600 Buffer.add_string
bb "'/>\n"
6603 Buffer.add_string
bb "' out='";
6605 Buffer.add_string
bb "'/>\n"
6607 | KMmulti
(ins, kms
) ->
6608 Buffer.add_char
bb ' '
;
6610 Buffer.add_string
bb "' out='";
6612 Buffer.add_string
bb "'/>\n"
6614 Buffer.add_string
bb "</keymap>";
6624 let uifontsize = fstate.fontsize
in
6625 let bb = Buffer.create
32768 in
6627 let dc = if conf.bedefault
then conf else dc in
6628 Buffer.add_string
bb "<llppconfig>\n";
6630 if String.length
!fontpath > 0
6632 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6638 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6641 Buffer.add_string
bb "<defaults ";
6642 add_attrs bb true dc dc;
6643 let kb = keymapsbuf true dc dc in
6644 if Buffer.length
kb > 0
6646 Buffer.add_string
bb ">\n";
6647 Buffer.add_buffer
bb kb;
6648 Buffer.add_string
bb "\n</defaults>\n";
6650 else Buffer.add_string
bb "/>\n";
6652 let adddoc path pan
anchor c bookmarks =
6653 if bookmarks == [] && c = dc && anchor = emptyanchor
6656 Printf.bprintf
bb "<doc path='%s'"
6657 (enent
path 0 (String.length
path));
6659 if anchor <> emptyanchor
6661 let n, rely, visy
= anchor in
6662 Printf.bprintf
bb " page='%d'" n;
6665 Printf.bprintf
bb " rely='%f'" rely
6667 if abs_float visy
> 1e-6
6669 Printf.bprintf
bb " visy='%f'" visy
6674 then Printf.bprintf
bb " pan='%d'" pan
;
6676 add_attrs bb false dc c;
6677 let kb = keymapsbuf false dc c in
6679 begin match bookmarks with
6681 if Buffer.length
kb > 0
6683 Buffer.add_string
bb ">\n";
6684 Buffer.add_buffer
bb kb;
6685 Buffer.add_string
bb "\n</doc>\n";
6687 else Buffer.add_string
bb "/>\n"
6689 Buffer.add_string
bb ">\n<bookmarks>\n";
6690 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6692 "<item title='%s' page='%d'"
6693 (enent
title 0 (String.length
title))
6698 Printf.bprintf
bb " rely='%f'" rely
6700 if abs_float visy
> 1e-6
6702 Printf.bprintf
bb " visy='%f'" visy
6704 Buffer.add_string
bb "/>\n";
6706 Buffer.add_string
bb "</bookmarks>";
6707 if Buffer.length
kb > 0
6709 Buffer.add_string
bb "\n";
6710 Buffer.add_buffer
bb kb;
6712 Buffer.add_string
bb "\n</doc>\n";
6718 match state.mode with
6719 | Birdseye
(c, pan, _, _, _) ->
6721 match conf.columns
with
6722 | Cmulti
((c, _, _), _) -> Some
c
6726 match c.columns
with
6727 | Cmulti
(c, _) -> Cmulti
(c, [||])
6728 | Csingle
_ -> Csingle
[||]
6729 | Csplit
_ -> failwith
"quit from bird's eye while split"
6731 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6732 | _ -> state.x, conf
6734 let basename = Filename.basename state.path in
6735 adddoc basename pan (getanchor ())
6737 let autoscrollstep =
6738 match state.autoscroll
with
6740 | None
-> conf.autoscrollstep
6742 match state.mode with
6743 | Birdseye
(bc
, _, _, _, _) ->
6746 presentation
= bc
.presentation
;
6747 interpagespace
= bc
.interpagespace
;
6748 maxwait
= bc
.maxwait
;
6749 autoscrollstep = autoscrollstep }
6750 | _ -> { conf with autoscrollstep = autoscrollstep }
6752 (if conf.savebmarks
then state.bookmarks else []);
6754 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6756 then adddoc path x anchor c bookmarks
6758 Buffer.add_string
bb "</llppconfig>";
6761 if Buffer.length
bb > 0
6764 let tmp = !confpath ^
".tmp" in
6765 let oc = open_out_bin
tmp in
6766 Buffer.output_buffer
oc bb;
6768 Unix.rename
tmp !confpath;
6771 ("error while saving configuration: " ^
Printexc.to_string exn
)
6776 let trimcachepath = ref "" in
6779 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6780 "<password> Set password");
6782 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6783 "<path> Set path to the user interface font");
6785 ("-c", Arg.String
(fun s -> Config.confpath := s),
6786 "<path> Set path to the configuration file");
6788 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6789 "<path> Set path to the trim cache file");
6791 ("-v", Arg.Unit
(fun () ->
6793 "%s\nconfiguration path: %s\n"
6797 exit
0), " Print version and exit");
6800 (fun s -> state.path <- s)
6801 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6803 if String.length
state.path = 0
6804 then (prerr_endline
"file name missing"; exit
1);
6808 let globalkeyhash = findkeyhash conf "global" in
6809 let wsfd, winw, winh
= Wsi.init
(object
6811 if nogeomcmds state.geomcmds
|| platform == Posx
6814 GlClear.color (scalecolor2 conf.bgcolor
);
6815 GlClear.clear
[`
color];
6817 method display = display ()
6818 method reshape w h = reshape w h
6819 method mouse b d x y m = mouse b d x y m
6820 method motion x y = state.mpos
<- (x, y); motion x y
6821 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6823 let mascm = m land (
6824 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6826 match state.keystate
with
6828 let km = k, mascm in
6831 let modehash = state.uioh#
modehash in
6832 try Hashtbl.find modehash km
6834 try Hashtbl.find globalkeyhash km
6835 with Not_found
-> KMinsrt
(k, m)
6837 | KMinsrt
(k, m) -> keyboard k m
6838 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6839 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6841 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6842 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6843 state.keystate
<- KSnone
6844 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6845 state.keystate
<- KSinto
(keys
, insrt
)
6847 state.keystate
<- KSnone
6849 method enter
x y = state.mpos
<- (x, y); pmotion x y
6850 method leave = state.mpos
<- (-1, -1)
6851 method quit
= raise Quit
6852 end) conf.winw conf.winh
(platform = Posx
) in
6857 List.exists
GlMisc.check_extension
6858 [ "GL_ARB_texture_rectangle"
6859 ; "GL_EXT_texture_recangle"
6860 ; "GL_NV_texture_rectangle" ]
6862 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6865 match Ne.pipe () with
6867 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6871 match Ne.pipe () with
6873 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6883 setcheckers conf.checkers
;
6887 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6888 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6889 !Config.fontpath, !trimcachepath
6893 state.text <- "Opening " ^
state.path;
6895 opendoc state.path state.password
;
6898 let rec loop deadline
=
6900 match state.errfd
with
6901 | None
-> [state.sr
; state.wsfd]
6902 | Some fd
-> [state.sr
; state.wsfd; fd
]
6906 state.redisplay
<- false;
6913 if deadline
= infinity
6915 else max
0.0 (deadline
-. now)
6920 try Unix.select
r [] [] timeout
6921 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6927 if state.ghyll
== noghyll
6929 match state.autoscroll
with
6930 | Some step
when step
!= 0 ->
6931 let y = state.y + step
in
6935 else if y >= state.maxy then 0 else y
6938 if state.mode = View
6939 then state.text <- "";
6942 else deadline
+. 0.01
6947 let rec checkfds = function
6949 | fd
:: rest
when fd
= state.sr
->
6950 let cmd = readcmd state.sr
in
6954 | fd
:: rest
when fd
= state.wsfd ->
6959 let s = String.create
80 in
6960 let n = Unix.read fd
s 0 80 in
6961 if conf.redirectstderr
6963 Buffer.add_substring
state.errmsgs
s 0 n;
6964 state.newerrmsgs
<- true;
6965 state.redisplay
<- true;
6968 prerr_string
(String.sub
s 0 n);
6976 if deadline
= infinity
6980 match state.autoscroll
with
6981 | Some step
when step
!= 0 -> deadline1
6982 | _ -> if state.ghyll
== noghyll then infinity
else deadline1