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 if Array.length
b = 0
1066 let (_
, _
, y, (_
, _
, h
, _
)) = b.(pageno) in
1068 if conf.presentation
1074 if Array.length
b = 0
1077 let (_
, _
, y, (_
, _
, h
, _
)) = b.(pageno) in
1080 if Array.length
b = 0
1084 let (_
, _
, y, (_
, _
, h
, _
)) = b.(n) in
1088 let getpagedim pageno =
1091 | (n, _
, _
, _
) as pdim
:: rest
->
1093 then (if n = pageno then pdim
else ppdim
)
1098 f (-1, -1, -1, -1) state.pdims
1101 let getpagey pageno = fst
(getpageyh pageno);;
1103 let nogeomcmds cmds
=
1105 | s, [] -> String.length
s = 0
1110 let (c, coverA
, coverB
), b =
1111 match conf.columns
with
1112 | Csingle
b -> (1, 0, 0), b
1113 | Cmulti
(c, b) -> c, b
1114 | Csplit
(_
, b) -> (1, 0, 0), b
1116 let rec bsearch nmin nmax
=
1118 then bound nmin
0 (state.pagecount
-1)
1120 let n = (nmax
+ nmin
) / 2 in
1121 let _, _, vy
, (_, _, h
, _) = b.(n) in
1123 if conf.presentation
1125 let ips = calcips h
in
1126 let y0 = vy
- ips in
1127 let y1 = vy
+ h
+ ips in
1131 then 0, vy
+ h
+ conf.interpagespace
1133 let y0 = vy
- conf.interpagespace
in
1134 y0, y0 + h
+ conf.interpagespace
1137 if y >= y0 && y < y1
1144 if n < state.pagecount
- coverB
1145 then ((n-coverA
)/c)*c + coverA
1152 then bsearch (n+1) nmax
1153 else bsearch nmin
(n-1)
1156 let r = bsearch 0 (state.pagecount
-1) in
1160 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1161 let sh = sh - state.hscrollh
in
1162 let rec fold accu
n =
1163 if n = Array.length
b
1166 let pdimno, dx, vy
, (_, w
, h
, xoff
) = b.(n) in
1169 || n = state.pagecount
- coverB
1170 || (n - coverA
) mod columns
= columns
- 1)
1176 let pagey = max
0 (y - vy
) in
1177 let pagedispy = if pagey > 0 then 0 else vy
- y in
1178 let pagedispx, pagex
=
1180 if n = coverA
- 1 || n = state.pagecount
- coverB
1181 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1182 else dx + xoff
+ state.x
1189 let vw = conf.winw
- state.scrollw
- pagedispx in
1190 let pw = w
- pagex
in
1193 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1194 if pagevw > 0 && pagevh > 0
1198 ; pagedimno
= pdimno
1205 ; pagedispx = pagedispx
1206 ; pagedispy = pagedispy
1218 List.rev
(fold [] (page_of_y y));
1221 let layoutS (columns
, b) y sh =
1222 let sh = sh - state.hscrollh
in
1223 let rec fold accu n =
1224 if n = Array.length
b
1227 let pdimno, px, vy
, (_, pagew
, pageh
, xoff
) = b.(n) in
1234 let x = xoff
+ state.x in
1235 let pagey = max
0 (y - vy
) in
1236 let pagedispy = if pagey > 0 then 0 else vy
- y in
1237 let pagedispx, pagex
=
1251 let pagecolw = pagew
/columns
in
1253 if pagecolw < conf.winw
1254 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1258 let vw = conf.winw
- pagedispx - state.scrollw
in
1259 let pw = pagew
- pagex
in
1262 let pagevw = min
pagevw pagecolw in
1263 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1264 if pagevw > 0 && pagevh > 0
1267 { pageno = n/columns
1268 ; pagedimno
= pdimno
1275 ; pagedispx = pagedispx
1276 ; pagedispy = pagedispy
1277 ; pagecol
= n mod columns
1288 List.rev
(fold [] 0)
1292 if nogeomcmds state.geomcmds
1294 match conf.columns
with
1295 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1296 | Cmulti
c -> layoutN c y sh
1297 | Csplit
s -> layoutS s y sh
1302 let y = state.y + incr
in
1304 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1309 let tilex = l
.pagex
mod conf.tilew
in
1310 let tiley = l
.pagey mod conf.tileh
in
1312 let col = l
.pagex
/ conf.tilew
in
1313 let row = l
.pagey / conf.tileh
in
1315 let rec rowloop row y0 dispy h
=
1319 let dh = conf.tileh
- y0 in
1320 let dh = min h
dh in
1321 let rec colloop col x0 dispx w
=
1325 let dw = conf.tilew
- x0 in
1326 let dw = min w
dw in
1328 f col row dispx dispy
x0 y0 dw dh;
1329 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1332 colloop col tilex l
.pagedispx l
.pagevw;
1333 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1336 if l
.pagevw > 0 && l
.pagevh > 0
1337 then rowloop row tiley l
.pagedispy l
.pagevh;
1340 let gettileopaque l
col row =
1342 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1344 try Some
(Hashtbl.find
state.tilemap
key)
1345 with Not_found
-> None
1348 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1349 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1350 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1353 let drawtiles l color
=
1355 let f col row x y tilex tiley w h
=
1356 match gettileopaque l
col row with
1357 | Some
(opaque
, _, t
) ->
1358 let params = x, y, w
, h
, tilex, tiley in
1362 GlFunc.blend_func `zero `one_minus_src_color
;
1364 drawtile
params opaque
;
1366 then Gl.disable `blend
;
1369 let s = Printf.sprintf
1373 let w = measurestr
fstate.fontsize
s in
1374 GlMisc.push_attrib
[`current
];
1375 GlDraw.color
(0.0, 0.0, 0.0);
1377 (float (x-2), float (y-2))
1378 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1379 GlDraw.color
(1.0, 1.0, 1.0);
1380 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1381 GlMisc.pop_attrib
();
1386 let lw = conf.winw
- state.scrollw
- x in
1389 let lh = conf.winh
- y in
1392 begin match state.texid
with
1394 Gl.enable `texture_2d
;
1395 GlTex.bind_texture `texture_2d id
;
1398 and x1 = float (x+w)
1399 and y1 = float (y+h
) in
1401 let tw = float w /. 64.0
1402 and th
= float h
/. 64.0 in
1403 let tx0 = float tilex /. 64.0
1404 and ty0
= float tiley /. 64.0 in
1406 and ty1
= ty0
+. th
in
1407 GlDraw.begins `quads
;
1408 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1409 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1410 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1411 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1414 Gl.disable `texture_2d
;
1416 GlDraw.color
(1.0, 1.0, 1.0);
1419 (float (x+w), float (y+h
));
1421 if w > 128 && h
> fstate.fontsize
+ 10
1423 GlDraw.color
(0.0, 0.0, 0.0);
1426 then (col*conf.tilew
, row*conf.tileh
)
1429 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1436 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1438 let tilevisible1 l
x y =
1440 and ax1
= l
.pagex
+ l
.pagevw
1442 and ay1
= l
.pagey + l
.pagevh in
1446 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1447 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1449 let rx0 = max
ax0 bx0
1450 and ry0
= max ay0 by0
1451 and rx1
= min ax1
bx1
1452 and ry1
= min ay1 by1
in
1454 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1455 nonemptyintersection
1458 let tilevisible layout n x y =
1459 let rec findpageinlayout m
= function
1460 | l
:: rest
when l
.pageno = n ->
1461 tilevisible1 l
x y || (
1462 match conf.columns
with
1463 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1466 | _ :: rest
-> findpageinlayout 0 rest
1469 findpageinlayout 0 layout;
1472 let tileready l
x y =
1473 tilevisible1 l
x y &&
1474 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1477 let tilepage n p
layout =
1478 let rec loop = function
1482 let f col row _ _ _ _ _ _ =
1483 if state.currently
= Idle
1485 match gettileopaque l
col row with
1488 let x = col*conf.tilew
1489 and y = row*conf.tileh
in
1491 let w = l
.pagew
- x in
1495 let h = l
.pageh
- y in
1498 wcmd "tile %s %d %d %d %d" p
x y w h;
1501 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1502 conf.tilew
, conf.tileh
1511 if nogeomcmds state.geomcmds
1515 let preloadlayout y =
1516 let y = if y < conf.winh
then 0 else y - conf.winh
in
1517 let h = conf.winh
*3 in
1522 let rec loop pages
=
1523 if state.currently
!= Idle
1528 begin match getopaque l
.pageno with
1530 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1531 state.currently
<- Loading
(l
, state.gen
);
1533 tilepage l
.pageno opaque pages
;
1538 if nogeomcmds state.geomcmds
1544 if conf.preload && state.currently
= Idle
1545 then load (preloadlayout state.y);
1548 let layoutready layout =
1549 let rec fold all ls
=
1550 all
&& match ls
with
1552 let seen = ref false in
1553 let allvisible = ref true in
1554 let foo col row _ _ _ _ _ _ =
1556 allvisible := !allvisible &&
1557 begin match gettileopaque l
col row with
1563 fold (!seen && !allvisible) rest
1566 let alltilesvisible = fold true layout in
1571 let y = bound y 0 state.maxy
in
1572 let y, layout, proceed
=
1573 match conf.maxwait
with
1574 | Some time
when state.ghyll
== noghyll ->
1575 begin match state.throttle
with
1577 let layout = layout y conf.winh
in
1578 let ready = layoutready layout in
1582 state.throttle
<- Some
(layout, y, now ());
1584 else G.postRedisplay "gotoy showall (None)";
1586 | Some
(_, _, started
) ->
1587 let dt = now () -. started
in
1590 state.throttle
<- None
;
1591 let layout = layout y conf.winh
in
1593 G.postRedisplay "maxwait";
1600 let layout = layout y conf.winh
in
1601 if true || layoutready layout
1602 then G.postRedisplay "gotoy ready";
1608 state.layout <- layout;
1609 begin match state.mode
with
1610 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1611 let rec loop = function
1613 state.mode
<- LinkNav
(Ltgendir
0)
1614 | l
:: _ when l
.pageno = pageno ->
1615 begin match getopaque pageno with
1617 state.mode
<- LinkNav
(Ltgendir
0)
1619 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1620 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1621 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1622 then state.mode
<- LinkNav
(Ltgendir
0)
1624 | _ :: rest
-> loop rest
1629 begin match state.mode
with
1630 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1631 if not
(pagevisible layout pageno)
1633 match state.layout with
1636 state.mode
<- Birdseye
(
1637 conf, leftx
, l
.pageno, hooverpageno
, anchor
1640 | LinkNav
(Ltgendir dir
as lt
) ->
1642 let rec loop = function
1645 match getopaque l
.pageno with
1651 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1653 if dir
> 0 then LDfirst
else LDlast
1659 | Lnotfound
-> loop rest
1661 showlinktype (getlink opaque
n);
1662 Ltexact
(l
.pageno, n)
1666 state.mode
<- LinkNav
linknav
1671 state.ghyll
<- noghyll;
1674 let mx, my
= state.mpos
in
1679 let conttiling pageno opaque
=
1680 tilepage pageno opaque
1681 (if conf.preload then preloadlayout state.y else state.layout)
1684 let gotoy_and_clear_text y =
1685 if not
conf.verbose
then state.text <- "";
1691 let coloff = l
.pagecol
* l
.pageh
in
1692 float (l
.pagey + coloff) /. float l
.pageh
1699 if conf.presentation
1700 then float l
.pagedispy /. float (calcips l
.pageh
)
1701 else float l
.pagedispy /. float conf.interpagespace
1703 (l
.pageno, top, dtop)
1707 match state.layout with
1708 | l
:: _ -> getanchor1 l
1710 let n = page_of_y state.y in
1711 let y, h = getpageyh n in
1712 let dy = y - state.y in
1714 if conf.presentation
1716 let ips = calcips h in
1717 float (dy + ips) /. float ips
1719 float dy /. float conf.interpagespace
1724 let getanchory (n, top, dtop) =
1725 let y, h = getpageyh n in
1726 if conf.presentation
1728 let ips = calcips h in
1729 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1731 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1734 let gotoanchor anchor
=
1735 gotoy (getanchory anchor
);
1739 cbput state.hists
.nav
(getanchor ());
1743 let anchor = cbgetc state.hists
.nav dir
in
1748 let scroll f n a
b =
1749 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1751 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1753 then s (float f /. float a
)
1756 then 1.0 -. s ((float (f-b) /. float (n-b)))
1763 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1764 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1766 let ins = float a
*. iv1
1767 and outs
= float (n-b) *. iv1 in
1769 ins +. outs
+. float ones
1771 let rec set (_N
, _A
, _B
) y sy
=
1772 let sum = summa
1.0 _N _A _B
in
1773 let dy = float (y - sy
) in
1777 then state.ghyll
<- noghyll
1780 let s = scroll n _N _A _B
in
1781 let y1 = y1 +. ((s *. dy) /. sum) in
1782 gotoy_and_clear_text (truncate
y1);
1783 state.ghyll
<- gf (n+1) y1;
1787 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1789 gf 0 (float state.y)
1792 match conf.ghyllscroll
with
1794 gotoy_and_clear_text y
1796 if state.ghyll
== noghyll
1797 then set nab
y state.y
1798 else state.ghyll
(Some
y)
1801 let gotopage n top =
1802 let y, h = getpageyh n in
1803 let y = y + (truncate
(top *. float h)) in
1807 let gotopage1 n top =
1808 let y = getpagey n in
1813 let invalidate s f =
1818 match state.geomcmds
with
1819 | ps
, [] when String.length ps
= 0 ->
1821 state.geomcmds
<- s, [];
1824 state.geomcmds
<- ps
, [s, f];
1826 | ps
, (s'
, _) :: rest
when s'
= s ->
1827 state.geomcmds
<- ps
, ((s, f) :: rest
);
1830 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1833 let opendoc path password
=
1835 state.password
<- password
;
1836 state.gen
<- state.gen
+ 1;
1837 state.docinfo
<- [];
1839 setaalevel
conf.aalevel
;
1840 Wsi.settitle
("llpp " ^
Filename.basename path
);
1841 wcmd "open %s\000%s\000" path password
;
1842 invalidate "reqlayout"
1844 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1848 let c = c *. conf.colorscale
in
1852 let scalecolor2 (r, g
, b) =
1853 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1856 let docolumns = function
1858 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1859 let rec loop pageno pdimno pdim
y ph pdims
=
1860 if pageno = state.pagecount
1863 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1865 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1866 pdimno+1, pdim
, rest
1870 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1872 (if conf.presentation
1873 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1874 else (if pageno = 0 then 0 else calcips h)
1877 a.(pageno) <- (pdimno, x, y, pdim
);
1878 loop (pageno+1) pdimno pdim
(y + h) h pdims
1880 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1881 conf.columns
<- Csingle
a;
1883 | Cmulti
((columns
, coverA
, coverB
), _) ->
1884 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1885 let rec loop pageno pdimno pdim
x y rowh pdims
=
1886 let rec fixrow m
= if m
= pageno then () else
1887 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1890 let y = y + (rowh
- h) / 2 in
1891 a.(m
) <- (pdimno, x, y, pdim
);
1895 if pageno = state.pagecount
1896 then fixrow (((pageno - 1) / columns
) * columns
)
1898 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1900 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1901 pdimno+1, pdim
, rest
1906 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1908 (conf.winw
- state.scrollw
- w) / 2,
1909 y + rowh
+ conf.interpagespace
, h
1912 if (pageno - coverA
) mod columns
= 0
1914 (if conf.multicenter
then
1915 (conf.winw
- state.scrollw
- state.w) / 2 else 0),
1916 y + rowh
+ (if pageno = 0 then 0 else conf.interpagespace
), h
1918 else x, y, max rowh
h
1921 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1922 then fixrow (pageno - columns
);
1923 a.(pageno) <- (pdimno, x, y, pdim
);
1924 let x = x + w + xoff
*2 + conf.interpagespace
in
1925 loop (pageno+1) pdimno pdim
x y rowh' pdims
1927 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1928 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1931 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1932 let rec loop pageno pdimno pdim
y pdims
=
1933 if pageno = state.pagecount
1936 let pdimno, ((_, w, h, _) as pdim
), pdims
=
1938 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1939 pdimno+1, pdim
, rest
1944 let rec loop1 n x y =
1945 if n = c then y else (
1946 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
1947 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
1950 let y = loop1 0 0 y in
1951 loop (pageno+1) pdimno pdim
y pdims
1953 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1954 conf.columns
<- Csplit
(c, a);
1958 docolumns conf.columns
;
1959 state.maxy
<- calcheight ();
1961 if state.w <= conf.winw
- state.scrollw
1965 match state.mode
with
1966 | Birdseye
(_, _, pageno, _, _) ->
1967 let y, h = getpageyh pageno in
1968 let top = (conf.winh
- h) / 2 in
1969 gotoy (max
0 (y - top))
1970 | _ -> gotoanchor state.anchor
1974 GlDraw.viewport
0 0 w h;
1975 let firsttime = state.geomcmds
== firstgeomcmds in
1976 if not
firsttime && nogeomcmds state.geomcmds
1977 then state.anchor <- getanchor ();
1980 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1983 setfontsize fstate.fontsize
;
1984 GlMat.mode `modelview
;
1985 GlMat.load_identity
();
1987 GlMat.mode `projection
;
1988 GlMat.load_identity
();
1989 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1990 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1991 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1996 else float state.x /. float state.w
1998 invalidate "geometry"
2002 then state.x <- truncate
(relx *. float w);
2004 match conf.columns
with
2006 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2007 | Csplit
(c, _) -> w * c
2009 wcmd "geometry %d %d" w h);
2013 let len = String.length
state.text in
2016 match state.mode
with
2019 let h, _, _ = state.uioh#scrollpw
in
2025 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2026 (x+.w, float (conf.winh
- hscrollh))
2029 let w = float (conf.winw
- state.scrollw
- 1) in
2030 if state.progress
>= 0.0 && state.progress
< 1.0
2032 GlDraw.color
(0.3, 0.3, 0.3);
2033 let w1 = w *. state.progress
in
2035 GlDraw.color
(0.0, 0.0, 0.0);
2039 GlDraw.color
(0.0, 0.0, 0.0);
2043 GlDraw.color
(1.0, 1.0, 1.0);
2044 drawstring fstate.fontsize
2045 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2048 match state.mode
with
2049 | Textentry
((prefix
, text, _, _, _, _), _) ->
2053 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2055 Printf.sprintf
"%s%s_" prefix
text
2064 if not
(istextentry state.mode
)
2066 let s1 = "(press 'e' to review error messasges)" in
2067 if String.length
s > 0 then s ^
" " ^
s1 else s1
2072 if String.length
s > 0
2077 let len = Queue.length
state.tilelru
in
2079 match state.throttle
with
2082 then preloadlayout state.y
2084 | Some
(layout, _, _) ->
2088 if state.memused
<= conf.memlimit
2093 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2094 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2095 let (_, pw, ph
, _) = getpagedim n in
2098 && colorspace
= conf.colorspace
2099 && angle
= conf.angle
2103 let x = col*conf.tilew
2104 and y = row*conf.tileh
in
2105 tilevisible (Lazy.force_val
layout) n x y
2107 then Queue.push lruitem
state.tilelru
2109 wcmd "freetile %s" p
;
2110 state.memused
<- state.memused
- s;
2111 state.uioh#infochanged Memused
;
2112 Hashtbl.remove
state.tilemap k
;
2121 Queue.iter
(fun (k
, p
, s) ->
2122 wcmd "freetile %s" p
;
2123 state.memused
<- state.memused
- s;
2124 state.uioh#infochanged Memused
;
2125 Hashtbl.remove
state.tilemap k
;
2127 Queue.clear
state.tilelru
;
2131 let logcurrently = function
2132 | Idle
-> dolog "Idle"
2133 | Loading
(l
, gen
) ->
2134 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2135 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2137 "Tiling %d[%d,%d] page=%s cs=%s angle"
2138 l
.pageno col row pageopaque
2139 (colorspace_to_string colorspace
)
2141 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2142 angle gen
conf.angle
state.gen
2144 conf.tilew
conf.tileh
2151 (* dolog "%S" cmds; *)
2154 try String.index cmds ' '
2155 with Not_found
-> -1
2160 let l = String.length cmds
in
2161 let op = String.sub cmds
0 spacepos in
2163 if l - spacepos < 2 then ""
2164 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2169 state.uioh#infochanged Pdim
;
2173 state.rects
<- state.rects1
;
2174 G.postRedisplay "clearrects";
2178 try Scanf.sscanf
args "%u" (fun n -> n)
2180 dolog "error processing 'continue' %S: %s"
2181 cmds
(Printexc.to_string exn
);
2184 state.pagecount
<- n;
2185 begin match state.currently
with
2187 state.currently
<- Idle
;
2188 state.outlines
<- Array.of_list
(List.rev
l)
2192 let cur, cmds
= state.geomcmds
in
2193 if String.length
cur = 0
2194 then failwith
"umpossible";
2196 begin match List.rev cmds
with
2198 state.geomcmds
<- "", [];
2202 state.geomcmds
<- s, List.rev rest
;
2204 if conf.maxwait
= None
2205 then G.postRedisplay "continue";
2215 then showtext ' '
args
2218 let progress, text =
2220 Scanf.sscanf
args "%f %n"
2222 f, String.sub
args pos
(String.length
args - pos
))
2224 dolog "error processing 'progress' %S: %s"
2225 cmds
(Printexc.to_string exn
);
2229 state.progress <- progress;
2230 G.postRedisplay "progress"
2233 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2235 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2236 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2237 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2239 dolog "error processing 'firstmatch' %S: %s"
2240 cmds
(Printexc.to_string exn
);
2243 let y = (getpagey pageno) + truncate
y0 in
2246 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2249 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2251 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2252 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2253 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2255 dolog "error processing 'match' %S: %s"
2256 cmds
(Printexc.to_string exn
);
2260 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2265 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2267 dolog "error processing 'page' %S: %s"
2268 cmds
(Printexc.to_string exn
);
2271 begin match state.currently
with
2272 | Loading
(l, gen
) ->
2273 vlog "page %d took %f sec" l.pageno t
;
2274 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2275 begin match state.throttle
with
2277 let preloadedpages =
2279 then preloadlayout state.y
2284 Set.Make
(struct type t
= int let compare = (-) end) in
2286 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2287 IntSet.empty
preloadedpages
2290 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2291 if not
(IntSet.mem
pageno set)
2293 wcmd "freepage %s" opaque
;
2299 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2302 state.currently
<- Idle
;
2305 tilepage l.pageno pageopaque state.layout;
2307 load preloadedpages;
2308 if pagevisible state.layout l.pageno
2309 && layoutready state.layout
2310 then G.postRedisplay "page";
2313 | Some
(layout, _, _) ->
2314 state.currently
<- Idle
;
2315 tilepage l.pageno pageopaque layout;
2320 dolog "Inconsistent loading state";
2321 logcurrently state.currently
;
2326 let (x, y, opaque
, size
, t
) =
2328 Scanf.sscanf
args "%u %u %s %u %f"
2329 (fun x y p size t
-> (x, y, p
, size
, t
))
2331 dolog "error processing 'tile' %S: %s"
2332 cmds
(Printexc.to_string exn
);
2335 begin match state.currently
with
2336 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2337 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2339 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2341 wcmd "freetile %s" opaque
;
2342 state.currently
<- Idle
;
2346 puttileopaque l col row gen cs angle opaque size t
;
2347 state.memused
<- state.memused
+ size
;
2348 state.uioh#infochanged Memused
;
2350 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2351 opaque
, size
) state.tilelru
;
2354 match state.throttle
with
2355 | None
-> state.layout
2356 | Some
(layout, _, _) -> layout
2359 state.currently
<- Idle
;
2361 && conf.colorspace
= cs
2362 && conf.angle
= angle
2363 && tilevisible layout l.pageno x y
2364 then conttiling l.pageno pageopaque;
2366 begin match state.throttle
with
2368 preload state.layout;
2370 && conf.colorspace
= cs
2371 && conf.angle
= angle
2372 && tilevisible state.layout l.pageno x y
2373 then G.postRedisplay "tile nothrottle";
2375 | Some
(layout, y, _) ->
2376 let ready = layoutready layout in
2380 state.layout <- layout;
2381 state.throttle
<- None
;
2382 G.postRedisplay "throttle";
2389 dolog "Inconsistent tiling state";
2390 logcurrently state.currently
;
2397 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2399 dolog "error processing 'pdim' %S: %s"
2400 cmds
(Printexc.to_string exn
);
2403 state.uioh#infochanged Pdim
;
2404 state.pdims
<- pdim :: state.pdims
2407 let (l, n, t
, h, pos
) =
2409 Scanf.sscanf
args "%u %u %d %u %n"
2410 (fun l n t
h pos
-> l, n, t
, h, pos
)
2412 dolog "error processing 'o' %S: %s"
2413 cmds
(Printexc.to_string exn
);
2416 let s = String.sub
args pos
(String.length
args - pos
) in
2417 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2418 begin match state.currently
with
2419 | Outlining outlines
->
2420 state.currently
<- Outlining
(outline :: outlines
)
2422 state.currently
<- Outlining
[outline]
2424 dolog "invalid outlining state";
2425 logcurrently currently
2429 state.docinfo
<- (1, args) :: state.docinfo
2432 state.uioh#infochanged Docinfo
;
2433 state.docinfo
<- List.rev
state.docinfo
2436 dolog "unknown cmd `%S'" cmds
2441 let action = function
2442 | HCprev
-> cbget cb ~
-1
2443 | HCnext
-> cbget cb
1
2444 | HCfirst
-> cbget cb ~
-(cb
.rc)
2445 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2446 and cancel
() = cb
.rc <- rc
2450 let search pattern forward
=
2451 if String.length pattern
> 0
2454 match state.layout with
2457 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2459 wcmd "search %d %d %d %d,%s\000"
2460 (btod conf.icase
) pn py
(btod forward
) pattern
;
2463 let intentry text key =
2465 if key >= 32 && key < 127
2471 let text = addchar text c in
2475 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2479 let linknentry text key =
2481 if key >= 32 && key < 127
2487 let text = addchar text c in
2491 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2496 if String.length
s > 0
2499 let l = String.length
s in
2500 let rec loop pos
n = if pos
= l then n else
2501 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2502 loop (pos
+1) (n*26 + m)
2505 let rec loop n = function
2508 match getopaque l.pageno with
2509 | None
-> loop n rest
2511 let m = getlinkcount opaque
in
2514 let under = getlink opaque
n in
2517 else loop (n-m) rest
2519 loop n state.layout;
2523 let textentry text key =
2524 if key land 0xff00 = 0xff00
2526 else TEcont
(text ^
Wsi.toutf8
key)
2529 let reqlayout angle proportional
=
2530 match state.throttle
with
2532 if nogeomcmds state.geomcmds
2533 then state.anchor <- getanchor ();
2534 conf.angle
<- angle
mod 360;
2537 match state.mode
with
2538 | LinkNav
_ -> state.mode
<- View
2541 conf.proportional
<- proportional
;
2542 invalidate "reqlayout"
2543 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2547 let settrim trimmargins trimfuzz
=
2548 if nogeomcmds state.geomcmds
2549 then state.anchor <- getanchor ();
2550 conf.trimmargins
<- trimmargins
;
2551 conf.trimfuzz
<- trimfuzz
;
2552 let x0, y0, x1, y1 = trimfuzz
in
2553 invalidate "settrim"
2555 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2556 Hashtbl.iter
(fun _ opaque
->
2557 wcmd "freepage %s" opaque
;
2559 Hashtbl.clear
state.pagemap
;
2563 match state.throttle
with
2565 let zoom = max
0.01 zoom in
2566 if zoom <> conf.zoom
2568 state.prevzoom
<- conf.zoom;
2570 reshape conf.winw
conf.winh
;
2571 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2574 | Some
(layout, y, started
) ->
2576 match conf.maxwait
with
2580 let dt = now () -. started
in
2588 let setcolumns mode columns coverA coverB
=
2589 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2593 then showtext '
!'
"split mode doesn't work in bird's eye"
2595 conf.columns
<- Csplit
(-columns
, [||]);
2603 conf.columns
<- Csingle
[||];
2608 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2612 reshape conf.winw
conf.winh
;
2615 let enterbirdseye () =
2616 let zoom = float conf.thumbw
/. float conf.winw
in
2617 let birdseyepageno =
2618 let cy = conf.winh
/ 2 in
2622 let rec fold best
= function
2625 let d = cy - (l.pagedispy + l.pagevh/2)
2626 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2627 if abs
d < abs dbest
2634 state.mode
<- Birdseye
(
2635 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2638 conf.presentation
<- false;
2639 conf.interpagespace
<- 10;
2640 conf.hlinks
<- false;
2642 state.mstate
<- Mnone
;
2643 conf.maxwait
<- None
;
2645 match conf.beyecolumns
with
2648 Cmulti
((c, 0, 0), [||])
2649 | None
-> Csingle
[||]
2651 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2654 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2659 reshape conf.winw
conf.winh
;
2662 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2664 conf.zoom <- c.zoom;
2665 conf.presentation
<- c.presentation
;
2666 conf.interpagespace
<- c.interpagespace
;
2667 conf.maxwait
<- c.maxwait
;
2668 conf.hlinks
<- c.hlinks
;
2669 conf.beyecolumns
<- (
2670 match conf.columns
with
2671 | Cmulti
((c, _, _), _) -> Some
c
2673 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2676 match c.columns
with
2677 | Cmulti
(c, _) -> Cmulti
(c, [||])
2678 | Csingle
_ -> Csingle
[||]
2679 | Csplit
(c, _) -> Csplit
(c, [||])
2684 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2687 reshape conf.winw
conf.winh
;
2688 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2691 let togglebirdseye () =
2692 match state.mode
with
2693 | Birdseye vals
-> leavebirdseye vals
true
2694 | View
-> enterbirdseye ()
2698 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2699 let pageno = max
0 (pageno - incr
) in
2700 let rec loop = function
2701 | [] -> gotopage1 pageno 0
2702 | l :: _ when l.pageno = pageno ->
2703 if l.pagedispy >= 0 && l.pagey = 0
2704 then G.postRedisplay "upbirdseye"
2705 else gotopage1 pageno 0
2706 | _ :: rest
-> loop rest
2709 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2712 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2713 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2714 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2715 let rec loop = function
2717 let y, h = getpageyh pageno in
2718 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2720 | l :: _ when l.pageno = pageno ->
2721 if l.pagevh != l.pageh
2722 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2723 else G.postRedisplay "downbirdseye"
2724 | _ :: rest
-> loop rest
2729 let optentry mode
_ key =
2730 let btos b = if b then "on" else "off" in
2731 if key >= 32 && key < 127
2733 let c = Char.chr
key in
2737 try conf.scrollstep
<- int_of_string
s with exc
->
2738 state.text <- Printf.sprintf
"bad integer `%s': %s"
2739 s (Printexc.to_string exc
)
2741 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2746 conf.autoscrollstep
<- int_of_string
s;
2747 if state.autoscroll
<> None
2748 then state.autoscroll
<- Some
conf.autoscrollstep
2750 state.text <- Printf.sprintf
"bad integer `%s': %s"
2751 s (Printexc.to_string exc
)
2753 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2758 let n, a, b = multicolumns_of_string s in
2759 setcolumns mode
n a b;
2761 state.text <- Printf.sprintf
"bad columns `%s': %s"
2762 s (Printexc.to_string exc
)
2764 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2769 let zoom = float (int_of_string
s) /. 100.0 in
2772 state.text <- Printf.sprintf
"bad integer `%s': %s"
2773 s (Printexc.to_string exc
)
2775 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2780 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2782 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2783 begin match mode
with
2785 leavebirdseye beye
false;
2790 state.text <- Printf.sprintf
"bad integer `%s': %s"
2791 s (Printexc.to_string exc
)
2793 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2798 Some
(int_of_string
s)
2800 state.text <- Printf.sprintf
"bad integer `%s': %s"
2801 s (Printexc.to_string exc
);
2804 | Some angle
-> reqlayout angle
conf.proportional
2807 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2810 conf.icase
<- not
conf.icase
;
2811 TEdone
("case insensitive search " ^
(btos conf.icase
))
2814 conf.preload <- not
conf.preload;
2816 TEdone
("preload " ^
(btos conf.preload))
2819 conf.verbose
<- not
conf.verbose
;
2820 TEdone
("verbose " ^
(btos conf.verbose
))
2823 conf.debug
<- not
conf.debug
;
2824 TEdone
("debug " ^
(btos conf.debug
))
2827 conf.maxhfit
<- not
conf.maxhfit
;
2828 state.maxy
<- calcheight ();
2829 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2832 conf.crophack
<- not
conf.crophack
;
2833 TEdone
("crophack " ^
btos conf.crophack
)
2837 match conf.maxwait
with
2839 conf.maxwait
<- Some infinity
;
2840 "always wait for page to complete"
2842 conf.maxwait
<- None
;
2843 "show placeholder if page is not ready"
2848 conf.underinfo
<- not
conf.underinfo
;
2849 TEdone
("underinfo " ^
btos conf.underinfo
)
2852 conf.savebmarks
<- not
conf.savebmarks
;
2853 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2859 match state.layout with
2864 conf.interpagespace
<- int_of_string
s;
2865 docolumns conf.columns
;
2866 state.maxy
<- calcheight ();
2867 let y = getpagey pageno in
2870 state.text <- Printf.sprintf
"bad integer `%s': %s"
2871 s (Printexc.to_string exc
)
2873 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2876 reqlayout conf.angle
(not
conf.proportional
);
2877 TEdone
("proportional display " ^
btos conf.proportional
)
2880 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2881 TEdone
("trim margins " ^
btos conf.trimmargins
)
2884 conf.invert
<- not
conf.invert
;
2885 TEdone
("invert colors " ^
btos conf.invert
)
2889 cbput state.hists
.sel
s;
2892 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2893 textentry, ondone, true)
2896 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2902 class type lvsource
= object
2903 method getitemcount
: int
2904 method getitem
: int -> (string * int)
2905 method hasaction
: int -> bool
2914 method getactive
: int
2915 method getfirst
: int
2916 method getqsearch
: string
2917 method setqsearch
: string -> unit
2921 class virtual lvsourcebase
= object
2922 val mutable m_active
= 0
2923 val mutable m_first
= 0
2924 val mutable m_qsearch
= ""
2925 val mutable m_pan
= 0
2926 method getactive
= m_active
2927 method getfirst
= m_first
2928 method getqsearch
= m_qsearch
2929 method getpan
= m_pan
2930 method setqsearch
s = m_qsearch
<- s
2933 let withoutlastutf8 s =
2934 let len = String.length
s in
2942 let b = Char.code
s.[pos
] in
2943 if b land 0b110000 = 0b11000000
2948 if Char.code
s.[len-1] land 0x80 = 0
2952 String.sub
s 0 first;
2955 let textentrykeyboard
2956 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2958 state.mode
<- Textentry
(te
, onleave
);
2961 G.postRedisplay "textentrykeyboard enttext";
2963 let histaction cmd
=
2966 | Some
(action, _) ->
2967 state.mode
<- Textentry
(
2968 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2970 G.postRedisplay "textentry histaction"
2973 | 0xff08 -> (* backspace *)
2974 let s = withoutlastutf8 text in
2975 let len = String.length
s in
2976 if cancelonempty
&& len = 0
2979 G.postRedisplay "textentrykeyboard after cancel";
2982 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2988 G.postRedisplay "textentrykeyboard after confirm"
2990 | 0xff52 -> histaction HCprev
2991 | 0xff54 -> histaction HCnext
2992 | 0xff50 -> histaction HCfirst
2993 | 0xff57 -> histaction HClast
2995 | 0xff1b -> (* escape*)
2996 if String.length
text = 0
2998 begin match opthist
with
3000 | Some
(_, onhistcancel
) -> onhistcancel
()
3004 G.postRedisplay "textentrykeyboard after cancel2"
3007 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3010 | 0xff9f | 0xffff -> () (* delete *)
3012 | _ when key != 0 && key land 0xff00 != 0xff00 ->
3013 begin match onkey
text key with
3017 G.postRedisplay "textentrykeyboard after confirm2";
3020 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3024 G.postRedisplay "textentrykeyboard after cancel3"
3027 state.mode
<- Textentry
(te
, onleave
);
3028 G.postRedisplay "textentrykeyboard switch";
3032 vlog "unhandled key %s" (Wsi.keyname
key)
3035 let firstof first active
=
3036 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3037 then max
0 (active
- (fstate.maxrows
/2))
3041 let calcfirst first active
=
3044 let rows = active
- first in
3045 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3049 let scrollph y maxy
=
3050 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3051 let sh = float conf.winh
/. sh in
3052 let sh = max
sh (float conf.scrollh
) in
3057 else float y /. float maxy
3059 let position = (float conf.winh
-. sh) *. percent in
3062 if position +. sh > float conf.winh
3063 then float conf.winh
-. sh
3069 let coe s = (s :> uioh
);;
3071 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3073 val m_pan
= source#getpan
3074 val m_first
= source#getfirst
3075 val m_active
= source#getactive
3076 val m_qsearch
= source#getqsearch
3077 val m_prev_uioh
= state.uioh
3079 method private elemunder
y =
3080 let n = y / (fstate.fontsize
+1) in
3081 if m_first
+ n < source#getitemcount
3083 if source#hasaction
(m_first
+ n)
3084 then Some
(m_first
+ n)
3091 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3092 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3093 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3094 GlDraw.color
(1., 1., 1.);
3095 Gl.enable `texture_2d
;
3096 let fs = fstate.fontsize
in
3098 let ww = fstate.wwidth
in
3099 let tabw = 30.0*.ww in
3100 let itemcount = source#getitemcount
in
3102 if (row - m_first
) * nfs > conf.winh
3105 if row >= 0 && row < itemcount
3107 let (s, level
) = source#getitem
row in
3108 let y = (row - m_first
) * nfs in
3109 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3112 Gl.disable `texture_2d
;
3113 GlDraw.polygon_mode `both `line
;
3114 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3115 GlDraw.rect (1., float (y + 1))
3116 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3117 GlDraw.polygon_mode `both `fill
;
3118 GlDraw.color
(1., 1., 1.);
3119 Gl.enable `texture_2d
;
3122 let drawtabularstring s =
3123 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3126 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3129 let len = String.length
s - tabpos - 1 in
3130 let s1 = String.sub
s 0 tabpos
3131 and s2
= String.sub
s (tabpos + 1) len in
3132 let nx = drawstr x s1 in
3134 let x = x +. (max
tabw sw) in
3141 let _ = drawtabularstring s in
3148 Gl.disable `texture_2d
;
3150 method updownlevel incr
=
3151 let len = source#getitemcount
in
3153 if m_active
>= 0 && m_active
< len
3154 then snd
(source#getitem m_active
)
3158 if i
= len then i
-1 else if i
= -1 then 0 else
3159 let _, l = source#getitem i
in
3160 if l != curlevel then i
else flow (i
+incr
)
3162 let active = flow m_active
in
3163 let first = calcfirst m_first
active in
3164 G.postRedisplay "outline updownlevel";
3165 {< m_active
= active; m_first
= first >}
3167 method private key1
key mask
=
3168 let set1 active first qsearch
=
3169 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3171 let search active pattern incr
=
3174 if n >= 0 && n < source#getitemcount
3176 let s, _ = source#getitem
n in
3178 (try ignore
(Str.search_forward
re s 0); true
3179 with Not_found
-> false)
3181 else loop (n + incr
)
3188 let re = Str.regexp_case_fold pattern
in
3194 let itemcount = source#getitemcount
in
3195 let find start incr
=
3197 if i
= -1 || i
= itemcount
3200 if source#hasaction i
3202 else find (i
+ incr
)
3207 let set active first =
3208 let first = bound first 0 (itemcount - fstate.maxrows
) in
3210 coe {< m_active
= active; m_first
= first >}
3213 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3215 let incr1 = if incr
> 0 then 1 else -1 in
3216 if isvisible m_first m_active
3219 let next = m_active
+ incr
in
3221 if next < 0 || next >= itemcount
3223 else find next incr1
3225 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3231 let first = m_first
+ incr
in
3232 let first = bound first 0 (itemcount - 1) in
3234 let next = m_active
+ incr
in
3235 let next = bound next 0 (itemcount - 1) in
3238 let active = if next = -1 then m_active
else next in
3241 let first = min
next m_first
in
3243 if abs
(next - first) > fstate.maxrows
3249 let first = m_first
+ incr
in
3250 let first = bound first 0 (itemcount - 1) in
3252 let next = m_active
+ incr
in
3253 let next = bound next 0 (itemcount - 1) in
3254 let next = find next incr1 in
3256 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3258 let active = if m_active
= -1 then next else m_active
in
3263 if isvisible first active
3269 G.postRedisplay "listview navigate";
3273 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3274 let incr = if key = 0x72 then -1 else 1 in
3276 match search (m_active
+ incr) m_qsearch
incr with
3278 state.text <- m_qsearch ^
" [not found]";
3281 state.text <- m_qsearch
;
3282 active, firstof m_first
active
3284 G.postRedisplay "listview ctrl-r/s";
3285 set1 active first m_qsearch
;
3287 | 0xff08 -> (* backspace *)
3288 if String.length m_qsearch
= 0
3291 let qsearch = withoutlastutf8 m_qsearch
in
3292 let len = String.length
qsearch in
3296 G.postRedisplay "listview empty qsearch";
3297 set1 m_active m_first
"";
3301 match search m_active
qsearch ~
-1 with
3303 state.text <- qsearch ^
" [not found]";
3306 state.text <- qsearch;
3307 active, firstof m_first
active
3309 G.postRedisplay "listview backspace qsearch";
3310 set1 active first qsearch
3313 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3314 let pattern = m_qsearch ^
Wsi.toutf8
key in
3316 match search m_active
pattern 1 with
3318 state.text <- pattern ^
" [not found]";
3321 state.text <- pattern;
3322 active, firstof m_first
active
3324 G.postRedisplay "listview qsearch add";
3325 set1 active first pattern;
3327 | 0xff1b -> (* escape *)
3329 if String.length m_qsearch
= 0
3331 G.postRedisplay "list view escape";
3334 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3336 | None
-> m_prev_uioh
3341 G.postRedisplay "list view kill qsearch";
3342 source#setqsearch
"";
3343 coe {< m_qsearch
= "" >}
3346 | 0xff0d -> (* return *)
3348 let self = {< m_qsearch
= "" >} in
3349 source#setqsearch
"";
3351 G.postRedisplay "listview enter";
3352 if m_active
>= 0 && m_active
< source#getitemcount
3354 source#exit
(coe self) false m_active m_first m_pan
"";
3357 source#exit
(coe self) true m_active m_first m_pan
"";
3360 begin match opt with
3361 | None
-> m_prev_uioh
3365 | 0xff9f | 0xffff -> (* delete *)
3368 | 0xff52 -> navigate ~
-1 (* up *)
3369 | 0xff54 -> navigate 1 (* down *)
3370 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3371 | 0xff56 -> navigate fstate.maxrows
(* next *)
3373 | 0xff53 -> (* right *)
3375 G.postRedisplay "listview right";
3376 coe {< m_pan
= m_pan
- 1 >}
3378 | 0xff51 -> (* left *)
3380 G.postRedisplay "listview left";
3381 coe {< m_pan
= m_pan
+ 1 >}
3383 | 0xff50 -> (* home *)
3384 let active = find 0 1 in
3385 G.postRedisplay "listview home";
3388 | 0xff57 -> (* end *)
3389 let first = max
0 (itemcount - fstate.maxrows
) in
3390 let active = find (itemcount - 1) ~
-1 in
3391 G.postRedisplay "listview end";
3394 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3398 dolog "listview unknown key %#x" key; coe self
3400 method key key mask
=
3401 match state.mode
with
3402 | Textentry te
-> textentrykeyboard key mask te
; coe self
3403 | _ -> self#key1
key mask
3405 method button button down
x y _ =
3408 | 1 when x > conf.winw
- conf.scrollbw
->
3409 G.postRedisplay "listview scroll";
3412 let _, position, sh = self#
scrollph in
3413 if y > truncate
position && y < truncate
(position +. sh)
3415 state.mstate
<- Mscrolly
;
3419 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3420 let first = truncate
(s *. float source#getitemcount
) in
3421 let first = min source#getitemcount
first in
3422 Some
(coe {< m_first
= first; m_active
= first >})
3424 state.mstate
<- Mnone
;
3427 | 1 when not down
->
3428 begin match self#elemunder
y with
3430 G.postRedisplay "listview click";
3432 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3436 | n when (n == 4 || n == 5) && not down
->
3437 let len = source#getitemcount
in
3439 if n = 5 && m_first
+ fstate.maxrows
>= len
3443 let first = m_first
+ (if n == 4 then -1 else 1) in
3444 bound first 0 (len - 1)
3446 G.postRedisplay "listview wheel";
3447 Some
(coe {< m_first
= first >})
3448 | n when (n = 6 || n = 7) && not down
->
3449 let inc = m_first
+ (if n = 7 then -1 else 1) in
3450 G.postRedisplay "listview hwheel";
3451 Some
(coe {< m_pan
= m_pan
+ inc >})
3456 | None
-> m_prev_uioh
3460 match state.mstate
with
3462 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3463 let first = truncate
(s *. float source#getitemcount
) in
3464 let first = min source#getitemcount
first in
3465 G.postRedisplay "listview motion";
3466 coe {< m_first
= first; m_active
= first >}
3469 method pmotion
x y =
3470 if x < conf.winw
- conf.scrollbw
3473 match self#elemunder
y with
3474 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3475 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3479 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3484 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3488 method infochanged
_ = ()
3490 method scrollpw
= (0, 0.0, 0.0)
3492 let nfs = fstate.fontsize
+ 1 in
3493 let y = m_first
* nfs in
3494 let itemcount = source#getitemcount
in
3495 let maxi = max
0 (itemcount - fstate.maxrows
) in
3496 let maxy = maxi * nfs in
3497 let p, h = scrollph y maxy in
3500 method modehash
= modehash
3503 class outlinelistview ~source
=
3506 ~source
:(source
:> lvsource
)
3508 ~modehash
:(findkeyhash conf "outline")
3511 method key key mask
=
3512 let calcfirst first active =
3515 let rows = active - first in
3517 if String.length
state.text = 0
3519 else fstate.maxrows - 2
3521 if rows > maxrows then active - maxrows else first
3525 let active = m_active
+ incr in
3526 let active = bound active 0 (source#getitemcount
- 1) in
3527 let first = calcfirst m_first
active in
3528 G.postRedisplay "outline navigate";
3529 coe {< m_active
= active; m_first
= first >}
3531 let ctrl = Wsi.withctrl mask
in
3533 | 110 when ctrl -> (* ctrl-n *)
3534 source#narrow m_qsearch
;
3535 G.postRedisplay "outline ctrl-n";
3536 coe {< m_first
= 0; m_active
= 0 >}
3538 | 117 when ctrl -> (* ctrl-u *)
3540 G.postRedisplay "outline ctrl-u";
3542 coe {< m_first
= 0; m_active
= 0 >}
3544 | 108 when ctrl -> (* ctrl-l *)
3545 let first = m_active
- (fstate.maxrows / 2) in
3546 G.postRedisplay "outline ctrl-l";
3547 coe {< m_first
= first >}
3549 | 0xff9f | 0xffff -> (* delete *)
3550 source#remove m_active
;
3551 G.postRedisplay "outline delete";
3552 let active = max
0 (m_active
-1) in
3553 coe {< m_first
= firstof m_first
active;
3554 m_active
= active >}
3556 | 0xff52 -> navigate ~
-1 (* up *)
3557 | 0xff54 -> navigate 1 (* down *)
3558 | 0xff55 -> (* prior *)
3559 navigate ~
-(fstate.maxrows)
3560 | 0xff56 -> (* next *)
3561 navigate fstate.maxrows
3563 | 0xff53 -> (* [ctrl-]right *)
3567 G.postRedisplay "outline ctrl right";
3568 {< m_pan
= m_pan
+ 1 >}
3570 else self#updownlevel
1
3574 | 0xff51 -> (* [ctrl-]left *)
3578 G.postRedisplay "outline ctrl left";
3579 {< m_pan
= m_pan
- 1 >}
3581 else self#updownlevel ~
-1
3585 | 0xff50 -> (* home *)
3586 G.postRedisplay "outline home";
3587 coe {< m_first
= 0; m_active
= 0 >}
3589 | 0xff57 -> (* end *)
3590 let active = source#getitemcount
- 1 in
3591 let first = max
0 (active - fstate.maxrows) in
3592 G.postRedisplay "outline end";
3593 coe {< m_active
= active; m_first
= first >}
3595 | _ -> super#
key key mask
3598 let outlinesource usebookmarks
=
3601 inherit lvsourcebase
3602 val mutable m_items
= empty
3603 val mutable m_orig_items
= empty
3604 val mutable m_prev_items
= empty
3605 val mutable m_narrow_pattern
= ""
3606 val mutable m_hadremovals
= false
3608 method getitemcount
=
3609 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3612 if n == Array.length m_items
&& m_hadremovals
3614 ("[Confirm removal]", 0)
3616 let s, n, _ = m_items
.(n) in
3619 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3620 ignore
(uioh
, first, qsearch);
3621 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3623 if String.length m_narrow_pattern
= 0
3629 if not
confrimremoval
3631 let _, _, anchor = m_items
.(active) in
3636 state.bookmarks
<- Array.to_list m_items
;
3637 m_orig_items
<- m_items
;
3640 else m_items
<- items;
3644 method hasaction
_ = true
3647 if Array.length m_items
!= Array.length m_orig_items
3648 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3651 method narrow
pattern =
3652 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3656 let rec loop accu n =
3659 m_narrow_pattern
<- pattern;
3660 m_items
<- Array.of_list
accu
3663 let (s, _, _) as o = m_items
.(n) in
3665 if (try ignore
(Str.search_forward
re s 0); true
3666 with Not_found
-> false)
3672 loop [] (Array.length m_items
- 1)
3677 then Array.of_list
state.bookmarks
3680 m_items
<- m_orig_items
3685 if m >= 0 && m < Array.length m_items
3687 m_hadremovals
<- true;
3688 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3689 let n = if n >= m then n+1 else n in
3694 method reset
anchor items =
3695 m_hadremovals
<- false;
3696 if m_orig_items
== empty || m_prev_items
!= items
3698 m_orig_items
<- items;
3699 if String.length m_narrow_pattern
= 0
3700 then m_items
<- items;
3702 m_prev_items
<- items;
3703 let rely = getanchory anchor in
3705 let rec loop n best bestd
=
3706 if n = Array.length m_items
3709 let (_, _, anchor) = m_items
.(n) in
3710 let orely = getanchory anchor in
3711 let d = abs
(orely - rely) in
3714 else loop (n+1) best bestd
3719 m_first
<- firstof m_first
active
3723 let enterselector usebookmarks
=
3724 let source = outlinesource usebookmarks
in
3728 then Array.of_list
state.bookmarks
3731 if Array.length
outlines = 0
3733 showtext ' ' errmsg
;
3736 state.text <- source#greetmsg
;
3737 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3738 let anchor = getanchor () in
3739 source#reset
anchor outlines;
3740 state.uioh
<- coe (new outlinelistview ~
source);
3741 G.postRedisplay "enter selector";
3745 let enteroutlinemode =
3746 let f = enterselector false in
3747 fun ()-> f "Document has no outline";
3750 let enterbookmarkmode =
3751 let f = enterselector true in
3752 fun () -> f "Document has no bookmarks (yet)";
3755 let color_of_string s =
3756 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3757 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3761 let color_to_string (r, g
, b) =
3762 let r = truncate
(r *. 256.0)
3763 and g
= truncate
(g
*. 256.0)
3764 and b = truncate
(b *. 256.0) in
3765 Printf.sprintf
"%d/%d/%d" r g
b
3768 let irect_of_string s =
3769 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3772 let irect_to_string (x0,y0,x1,y1) =
3773 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3776 let makecheckers () =
3777 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3779 converted by Issac Trotts. July 25, 2002 *)
3780 let image_height = 64
3781 and image_width
= 64 in
3785 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3787 for i
= 0 to image_width
- 1 do
3788 for j
= 0 to image_height - 1 do
3789 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3790 (if (i
land 8 ) lxor (j
land 8) = 0
3791 then [|255;255;255|] else [|200;200;200|])
3796 let image = make_image () in
3797 let id = GlTex.gen_texture
() in
3798 GlTex.bind_texture `texture_2d
id;
3799 GlPix.store
(`unpack_alignment
1);
3800 GlTex.image2d
image;
3801 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3804 `mag_filter `nearest
;
3805 `min_filter `nearest
];
3809 let setcheckers enabled
=
3810 match state.texid
with
3812 if enabled
then state.texid
<- Some
(makecheckers ())
3817 GlTex.delete_texture texid
;
3818 state.texid
<- None
;
3822 let int_of_string_with_suffix s =
3823 let l = String.length
s in
3827 let suffix = Char.lowercase
s.[l-1] in
3829 | 'k'
-> String.sub
s 0 (l-1), 10
3830 | '
m'
-> String.sub
s 0 (l-1), 20
3831 | 'g'
-> String.sub
s 0 (l-1), 30
3835 let n = int_of_string
s1 in
3836 let m = n lsl shift
in
3838 then raise
(Failure
"value too large")
3842 let string_with_suffix_of_int n =
3847 if n land ((1 lsl 20) - 1) = 0
3850 if n land ((1 lsl 10) - 1) = 0
3856 let h = n mod 1000 in
3859 then string_of_int
h ^
s
3861 let s = Printf.sprintf
"_%03d%s" h s in
3868 let defghyllscroll = (40, 8, 32);;
3869 let ghyllscroll_of_string s =
3870 let (n, a, b) as nab
=
3873 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3875 if n <= a || n <= b || a >= b
3876 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3880 let ghyllscroll_to_string ((n, a, b) as nab
) =
3881 if nab
= defghyllscroll
3883 else Printf.sprintf
"%d,%d,%d" n a b;
3886 let describe_location () =
3888 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3890 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3891 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3895 else (100. *. (float state.y /. float maxy))
3899 Printf.sprintf
"page %d of %d [%.2f%%]"
3900 (fn+1) state.pagecount
percent
3903 "pages %d-%d of %d [%.2f%%]"
3904 (fn+1) (ln
+1) state.pagecount
percent
3907 let setpresentationmode v
=
3908 let (n, _, _) = getanchor () in
3909 let _, h = getpageyh n in
3910 state.anchor <- (n, 0.0, float (calcips h));
3911 conf.presentation
<- v
;
3912 if conf.presentation
3914 if not
conf.scrollbarinpm
3915 then state.scrollw
<- 0;
3917 else state.scrollw
<- conf.scrollbw
;
3922 let btos b = if b then "\xe2\x88\x9a" else "" in
3923 let showextended = ref false in
3924 let leave mode
= function
3925 | Confirm
-> state.mode
<- mode
3926 | Cancel
-> state.mode
<- mode
in
3929 val mutable m_first_time
= true
3930 val mutable m_l
= []
3931 val mutable m_a
= [||]
3932 val mutable m_prev_uioh
= nouioh
3933 val mutable m_prev_mode
= View
3935 inherit lvsourcebase
3937 method reset prev_mode prev_uioh
=
3938 m_a
<- Array.of_list
(List.rev m_l
);
3940 m_prev_mode
<- prev_mode
;
3941 m_prev_uioh
<- prev_uioh
;
3945 if n >= Array.length m_a
3949 | _, _, _, Action
_ -> m_active
<- n
3953 m_first_time
<- false;
3956 method int name get
set =
3958 (name
, `
int get
, 1, Action
(
3961 try set (int_of_string
s)
3963 state.text <- Printf.sprintf
"bad integer `%s': %s"
3964 s (Printexc.to_string exn
)
3967 let te = name ^
": ", "", None
, intentry, ondone, true in
3968 state.mode
<- Textentry
(te, leave m_prev_mode
);
3972 method int_with_suffix name get
set =
3974 (name
, `intws get
, 1, Action
(
3977 try set (int_of_string_with_suffix s)
3979 state.text <- Printf.sprintf
"bad integer `%s': %s"
3980 s (Printexc.to_string exn
)
3984 name ^
": ", "", None
, intentry_with_suffix, ondone, true
3986 state.mode
<- Textentry
(te, leave m_prev_mode
);
3990 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3992 (name
, `
bool (btos, get
), offset
, Action
(
3999 method color name get
set =
4001 (name
, `color get
, 1, Action
(
4003 let invalid = (nan
, nan
, nan
) in
4006 try color_of_string s
4008 state.text <- Printf.sprintf
"bad color `%s': %s"
4009 s (Printexc.to_string exn
);
4015 let te = name ^
": ", "", None
, textentry, ondone, true in
4016 state.text <- color_to_string (get
());
4017 state.mode
<- Textentry
(te, leave m_prev_mode
);
4021 method string name get
set =
4023 (name
, `
string get
, 1, Action
(
4025 let ondone s = set s in
4026 let te = name ^
": ", "", None
, textentry, ondone, true in
4027 state.mode
<- Textentry
(te, leave m_prev_mode
);
4031 method colorspace name get
set =
4033 (name
, `
string get
, 1, Action
(
4036 let vals = [| "rgb"; "bgr"; "gray" |] in
4038 inherit lvsourcebase
4041 m_active
<- int_of_colorspace conf.colorspace
;
4044 method getitemcount
= Array.length
vals
4045 method getitem
n = (vals.(n), 0)
4046 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4047 ignore
(uioh
, first, pan
, qsearch);
4048 if not cancel
then set active;
4050 method hasaction
_ = true
4054 let modehash = findkeyhash conf "info" in
4055 coe (new listview ~
source ~trusted
:true ~
modehash)
4058 method caption
s offset
=
4059 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4061 method caption2
s f offset
=
4062 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4064 method getitemcount
= Array.length m_a
4067 let tostr = function
4068 | `
int f -> string_of_int
(f ())
4069 | `intws
f -> string_with_suffix_of_int (f ())
4071 | `color
f -> color_to_string (f ())
4072 | `
bool (btos, f) -> btos (f ())
4075 let name, t
, offset
, _ = m_a
.(n) in
4076 ((let s = tostr t
in
4077 if String.length
s > 0
4078 then Printf.sprintf
"%s\t%s" name s
4082 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4086 m_qsearch
<- qsearch;
4088 match m_a
.(active) with
4089 | _, _, _, Action
f -> f uioh
4101 method hasaction
n =
4103 | _, _, _, Action
_ -> true
4107 let rec fillsrc prevmode prevuioh
=
4108 let sep () = src#caption
"" 0 in
4109 let colorp name get
set =
4111 (fun () -> color_to_string (get
()))
4114 let c = color_of_string v in
4117 state.text <- Printf.sprintf
"bad color `%s': %s"
4118 v (Printexc.to_string exn
);
4121 let oldmode = state.mode
in
4122 let birdseye = isbirdseye state.mode
in
4124 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4126 src#
bool "presentation mode"
4127 (fun () -> conf.presentation
)
4128 (fun v -> setpresentationmode v);
4130 src#
bool "ignore case in searches"
4131 (fun () -> conf.icase
)
4132 (fun v -> conf.icase
<- v);
4135 (fun () -> conf.preload)
4136 (fun v -> conf.preload <- v);
4138 src#
bool "highlight links"
4139 (fun () -> conf.hlinks
)
4140 (fun v -> conf.hlinks
<- v);
4142 src#
bool "under info"
4143 (fun () -> conf.underinfo
)
4144 (fun v -> conf.underinfo
<- v);
4146 src#
bool "persistent bookmarks"
4147 (fun () -> conf.savebmarks
)
4148 (fun v -> conf.savebmarks
<- v);
4150 src#
bool "proportional display"
4151 (fun () -> conf.proportional
)
4152 (fun v -> reqlayout conf.angle
v);
4154 src#
bool "trim margins"
4155 (fun () -> conf.trimmargins
)
4156 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4158 src#
bool "persistent location"
4159 (fun () -> conf.jumpback
)
4160 (fun v -> conf.jumpback
<- v);
4163 src#
int "inter-page space"
4164 (fun () -> conf.interpagespace
)
4166 conf.interpagespace
<- n;
4167 docolumns conf.columns
;
4169 match state.layout with
4174 state.maxy <- calcheight ();
4175 let y = getpagey pageno in
4180 (fun () -> conf.pagebias
)
4181 (fun v -> conf.pagebias
<- v);
4183 src#
int "scroll step"
4184 (fun () -> conf.scrollstep
)
4185 (fun n -> conf.scrollstep
<- n);
4187 src#
int "horizontal scroll step"
4188 (fun () -> conf.hscrollstep
)
4189 (fun v -> conf.hscrollstep
<- v);
4191 src#
int "auto scroll step"
4193 match state.autoscroll
with
4195 | _ -> conf.autoscrollstep
)
4197 if state.autoscroll
<> None
4198 then state.autoscroll
<- Some
n;
4199 conf.autoscrollstep
<- n);
4202 (fun () -> truncate
(conf.zoom *. 100.))
4203 (fun v -> setzoom ((float v) /. 100.));
4206 (fun () -> conf.angle
)
4207 (fun v -> reqlayout v conf.proportional
);
4209 src#
int "scroll bar width"
4210 (fun () -> state.scrollw
)
4214 reshape conf.winw
conf.winh
;
4217 src#
int "scroll handle height"
4218 (fun () -> conf.scrollh
)
4219 (fun v -> conf.scrollh
<- v;);
4221 src#
int "thumbnail width"
4222 (fun () -> conf.thumbw
)
4224 conf.thumbw
<- min
4096 v;
4227 leavebirdseye beye
false;
4232 let mode = state.mode in
4233 src#
string "columns"
4235 match conf.columns
with
4237 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4238 | Csplit
(count
, _) -> "-" ^ string_of_int count
4241 let n, a, b = multicolumns_of_string v in
4242 setcolumns mode n a b);
4245 src#caption
"Presentation mode" 0;
4246 src#
bool "scrollbar visible"
4247 (fun () -> conf.scrollbarinpm
)
4249 if v != conf.scrollbarinpm
4251 conf.scrollbarinpm
<- v;
4252 if conf.presentation
4254 state.scrollw
<- if v then conf.scrollbw
else 0;
4255 reshape conf.winw
conf.winh
;
4261 src#caption
"Pixmap cache" 0;
4262 src#int_with_suffix
"size (advisory)"
4263 (fun () -> conf.memlimit
)
4264 (fun v -> conf.memlimit
<- v);
4267 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4268 (string_with_suffix_of_int state.memused
)
4269 (Hashtbl.length
state.tilemap
)) 1;
4272 src#caption
"Layout" 0;
4273 src#caption2
"Dimension"
4275 Printf.sprintf
"%dx%d (virtual %dx%d)"
4281 src#caption2
"Position" (fun () ->
4282 Printf.sprintf
"%dx%d" state.x state.y
4285 src#caption2
"Visible" (fun () -> describe_location ()) 1
4289 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4290 "Save these parameters as global defaults at exit"
4291 (fun () -> conf.bedefault
)
4292 (fun v -> conf.bedefault
<- v)
4296 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4297 src#
bool ~offset
:0 ~
btos "Extended parameters"
4298 (fun () -> !showextended)
4299 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4303 (fun () -> conf.checkers
)
4304 (fun v -> conf.checkers
<- v; setcheckers v);
4305 src#
bool "update cursor"
4306 (fun () -> conf.updatecurs
)
4307 (fun v -> conf.updatecurs
<- v);
4309 (fun () -> conf.verbose
)
4310 (fun v -> conf.verbose
<- v);
4311 src#
bool "invert colors"
4312 (fun () -> conf.invert
)
4313 (fun v -> conf.invert
<- v);
4315 (fun () -> conf.maxhfit
)
4316 (fun v -> conf.maxhfit
<- v);
4317 src#
bool "redirect stderr"
4318 (fun () -> conf.redirectstderr)
4319 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4320 src#
string "uri launcher"
4321 (fun () -> conf.urilauncher
)
4322 (fun v -> conf.urilauncher
<- v);
4323 src#
string "path launcher"
4324 (fun () -> conf.pathlauncher
)
4325 (fun v -> conf.pathlauncher
<- v);
4326 src#
string "tile size"
4327 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4330 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4331 conf.tilew
<- max
64 w;
4332 conf.tileh
<- max
64 h;
4335 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4336 v (Printexc.to_string exn
));
4337 src#
int "texture count"
4338 (fun () -> conf.texcount
)
4341 then conf.texcount
<- v
4342 else showtext '
!'
" Failed to set texture count please retry later"
4344 src#
int "slice height"
4345 (fun () -> conf.sliceheight
)
4347 conf.sliceheight
<- v;
4348 wcmd "sliceh %d" conf.sliceheight
;
4350 src#
int "anti-aliasing level"
4351 (fun () -> conf.aalevel
)
4353 conf.aalevel
<- bound v 0 8;
4354 state.anchor <- getanchor ();
4355 opendoc state.path
state.password
;
4357 src#
string "page scroll scaling factor"
4358 (fun () -> string_of_float
conf.pgscale)
4361 let s = float_of_string
v in
4364 state.text <- Printf.sprintf
4365 "bad page scroll scaling factor `%s': %s"
4366 v (Printexc.to_string exn
)
4369 src#
int "ui font size"
4370 (fun () -> fstate.fontsize
)
4371 (fun v -> setfontsize (bound v 5 100));
4372 src#
int "hint font size"
4373 (fun () -> conf.hfsize
)
4374 (fun v -> conf.hfsize
<- bound v 5 100);
4375 colorp "background color"
4376 (fun () -> conf.bgcolor
)
4377 (fun v -> conf.bgcolor
<- v);
4378 src#
bool "crop hack"
4379 (fun () -> conf.crophack
)
4380 (fun v -> conf.crophack
<- v);
4381 src#
bool "multi column centering"
4382 (fun () -> conf.multicenter
)
4383 (fun v -> conf.multicenter
<- v; represent ());
4384 src#
string "trim fuzz"
4385 (fun () -> irect_to_string conf.trimfuzz
)
4388 conf.trimfuzz
<- irect_of_string v;
4390 then settrim true conf.trimfuzz
;
4392 state.text <- Printf.sprintf
"bad irect `%s': %s"
4393 v (Printexc.to_string exn
)
4395 src#
string "throttle"
4397 match conf.maxwait
with
4398 | None
-> "show place holder if page is not ready"
4401 then "wait for page to fully render"
4403 "wait " ^ string_of_float
time
4404 ^
" seconds before showing placeholder"
4408 let f = float_of_string
v in
4410 then conf.maxwait
<- None
4411 else conf.maxwait
<- Some
f
4413 state.text <- Printf.sprintf
"bad time `%s': %s"
4414 v (Printexc.to_string exn
)
4416 src#
string "ghyll scroll"
4418 match conf.ghyllscroll
with
4420 | Some nab
-> ghyllscroll_to_string nab
4425 if String.length
v = 0
4427 else Some
(ghyllscroll_of_string v)
4429 conf.ghyllscroll
<- gs
4431 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4432 v (Printexc.to_string exn
)
4434 src#
string "selection command"
4435 (fun () -> conf.selcmd
)
4436 (fun v -> conf.selcmd
<- v);
4437 src#colorspace
"color space"
4438 (fun () -> colorspace_to_string conf.colorspace
)
4440 conf.colorspace
<- colorspace_of_int v;
4447 src#caption
"Document" 0;
4448 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4449 src#caption2
"Pages"
4450 (fun () -> string_of_int
state.pagecount
) 1;
4451 src#caption2
"Dimensions"
4452 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4456 src#caption
"Trimmed margins" 0;
4457 src#caption2
"Dimensions"
4458 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4462 src#caption
"OpenGL" 0;
4463 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4464 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4465 src#reset prevmode prevuioh
;
4469 let prevmode = state.mode
4470 and prevuioh
= state.uioh in
4471 fillsrc prevmode prevuioh
;
4472 let source = (src :> lvsource
) in
4473 let modehash = findkeyhash conf "info" in
4474 state.uioh <- coe (object (self)
4475 inherit listview ~
source ~trusted
:true ~
modehash as super
4476 val mutable m_prevmemused
= 0
4477 method infochanged
= function
4479 if m_prevmemused
!= state.memused
4481 m_prevmemused
<- state.memused
;
4482 G.postRedisplay "memusedchanged";
4484 | Pdim
-> G.postRedisplay "pdimchanged"
4485 | Docinfo
-> fillsrc prevmode prevuioh
4487 method key key mask
=
4488 if not
(Wsi.withctrl mask
)
4491 | 0xff51 -> coe (self#updownlevel ~
-1)
4492 | 0xff53 -> coe (self#updownlevel
1)
4493 | _ -> super#
key key mask
4494 else super#
key key mask
4496 G.postRedisplay "info";
4502 inherit lvsourcebase
4503 method getitemcount
= Array.length
state.help
4505 let s, n, _ = state.help
.(n) in
4508 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4512 m_qsearch
<- qsearch;
4513 match state.help
.(active) with
4514 | _, _, Action
f -> Some
(f uioh)
4524 method hasaction
n =
4525 match state.help
.(n) with
4526 | _, _, Action
_ -> true
4533 let modehash = findkeyhash conf "help" in
4534 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4535 G.postRedisplay "help";
4540 let re = Str.regexp
"[\r\n]" in
4542 inherit lvsourcebase
4543 val mutable m_items
= [||]
4545 method getitemcount
= 1 + Array.length m_items
4550 else m_items
.(n-1), 0
4552 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4557 then Buffer.clear
state.errmsgs
;
4558 m_qsearch
<- qsearch;
4565 method hasaction
n =
4569 state.newerrmsgs
<- false;
4570 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4571 m_items
<- Array.of_list
l
4579 let source = (msgsource :> lvsource
) in
4580 let modehash = findkeyhash conf "listview" in
4581 state.uioh <- coe (object
4582 inherit listview ~
source ~trusted
:false ~
modehash as super
4585 then msgsource#reset
;
4588 G.postRedisplay "msgs";
4591 let quickbookmark ?title
() =
4592 match state.layout with
4598 let sec = Unix.gettimeofday
() in
4599 let tm = Unix.localtime
sec in
4600 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4604 (tm.Unix.tm_year
+ 1900)
4607 | Some
title -> title
4609 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4613 state.fullscreen
<- None
;
4617 let setautoscrollspeed step goingdown
=
4618 let incr = max
1 ((abs step
) / 2) in
4619 let incr = if goingdown
then incr else -incr in
4620 let astep = step
+ incr in
4621 state.autoscroll
<- Some
astep;
4624 let gotounder = function
4625 | Ulinkgoto
(pageno, top) ->
4629 gotopage1 pageno top;
4635 | Uremote
(filename
, pageno) ->
4637 if Sys.file_exists filename
4640 let dir = Filename.dirname
state.path in
4641 let path = Filename.concat
dir filename
in
4642 if Sys.file_exists
path
4646 if String.length
path > 0
4648 let anchor = getanchor () in
4649 let ranchor = state.path, state.password
, anchor in
4650 state.anchor <- (pageno, 0.0, 0.0);
4651 state.ranchors
<- ranchor :: state.ranchors
;
4654 else showtext '
!'
("Could not find " ^ filename
)
4656 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4660 match conf.columns
with
4662 | _ -> conf.zoom > 1.0
4665 let viewkeyboard key mask
=
4667 let mode = state.mode in
4668 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4671 G.postRedisplay "view:enttext"
4673 let ctrl = Wsi.withctrl mask
in
4678 | 0xff63 -> (* insert *)
4679 if conf.angle
mod 360 = 0
4681 state.mode <- LinkNav
(Ltgendir
0);
4684 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4686 | 0xff1b | 113 -> (* escape / q *)
4687 begin match state.mstate
with
4689 state.mstate
<- Mnone
;
4690 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4691 G.postRedisplay "kill zoom rect";
4693 match state.ranchors
with
4695 | (path, password
, anchor) :: rest
->
4696 state.ranchors
<- rest
;
4697 state.anchor <- anchor;
4698 opendoc path password
4701 | 0xff08 -> (* backspace *)
4702 let y = getnav ~
-1 in
4703 gotoy_and_clear_text y
4711 G.postRedisplay "dehighlight";
4713 | 47 | 63 -> (* / ? *)
4714 let ondone isforw
s =
4715 cbput state.hists
.pat
s;
4716 state.searchpattern
<- s;
4719 let s = String.create
1 in
4720 s.[0] <- Char.chr
key;
4721 enttext (s, "", Some
(onhist state.hists
.pat
),
4722 textentry, ondone (key = 47), true)
4724 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4725 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4726 setzoom (conf.zoom +. incr)
4728 | 43 | 0xffab -> (* + *)
4731 try int_of_string
s with exc
->
4732 state.text <- Printf.sprintf
"bad integer `%s': %s"
4733 s (Printexc.to_string exc
);
4739 state.text <- "page bias is now " ^ string_of_int
n;
4742 enttext ("page bias: ", "", None
, intentry, ondone, true)
4744 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4745 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4746 setzoom (max
0.01 (conf.zoom -. decr))
4748 | 45 | 0xffad -> (* - *)
4749 let ondone msg
= state.text <- msg
in
4751 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4752 optentry state.mode, ondone, true
4755 | 48 when ctrl -> (* ctrl-0 *)
4758 | 49 when ctrl -> (* ctrl-1 *)
4760 match conf.columns
with
4761 | Csingle
_ | Cmulti
_ -> 1
4762 | Csplit
(n, _) -> n
4764 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4768 | 0xffc6 -> (* f9 *)
4771 | 57 when ctrl -> (* ctrl-9 *)
4774 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4775 when not
ctrl -> (* 0..9 *)
4778 try int_of_string
s with exc
->
4779 state.text <- Printf.sprintf
"bad integer `%s': %s"
4780 s (Printexc.to_string exc
);
4786 cbput state.hists
.pag
(string_of_int
n);
4787 gotopage1 (n + conf.pagebias
- 1) 0;
4790 let pageentry text key =
4791 match Char.unsafe_chr
key with
4792 | 'g'
-> TEdone
text
4793 | _ -> intentry text key
4795 let text = "x" in text.[0] <- Char.chr
key;
4796 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4799 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4800 reshape conf.winw
conf.winh
;
4803 conf.hlinks
<- not
conf.hlinks
;
4804 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4805 G.postRedisplay "toggle highlightlinks";
4808 state.glinks
<- true;
4809 let mode = state.mode in
4810 state.mode <- Textentry
(
4811 (":", "", None
, linknentry, linkndone (fun under ->
4816 state.glinks
<- false;
4820 G.postRedisplay "view:linkent(F)"
4823 state.glinks
<- true;
4824 let mode = state.mode in
4825 state.mode <- Textentry
(
4826 (":", "", None
, linknentry, linkndone (fun under ->
4827 match Ne.pipe () with
4829 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4830 (Printexc.to_string exn
));
4833 try popen conf.selcmd
[r, 0; w, -1]; true
4836 (Printf.sprintf
"failed to execute %s: %s"
4837 conf.selcmd
(Printexc.to_string exn
));
4841 Ne.clo fd
(fun msg
->
4842 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4845 let s = undertext under in
4849 let l = String.length
s in
4850 let n = Unix.write
w s 0 l in
4855 "failed to write %d characters to sel pipe, wrote %d"
4860 (Printf.sprintf
"failed to write to sel pipe: %s"
4861 (Printexc.to_string exn
)
4870 state.glinks
<- false;
4874 G.postRedisplay "view:linkent"
4877 begin match state.autoscroll
with
4879 conf.autoscrollstep
<- step
;
4880 state.autoscroll
<- None
4882 if conf.autoscrollstep
= 0
4883 then state.autoscroll
<- Some
1
4884 else state.autoscroll
<- Some
conf.autoscrollstep
4887 | 112 when ctrl -> (* ctrl-p *)
4891 setpresentationmode (not
conf.presentation
);
4892 showtext ' '
("presentation mode " ^
4893 if conf.presentation
then "on" else "off");
4896 begin match state.fullscreen
with
4898 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4901 state.fullscreen
<- None
;
4906 gotoy_and_clear_text 0
4909 gotopage1 (state.pagecount
- 1) 0
4911 | 112 | 78 -> (* p|N *)
4912 search state.searchpattern
false
4914 | 110 | 0xffc0 -> (* n|F3 *)
4915 search state.searchpattern
true
4918 begin match state.layout with
4921 gotoy_and_clear_text (getpagey l.pageno)
4925 begin match state.layout with
4928 match conf.columns
with
4929 | Csingle
_ | Cmulti
_ ->
4930 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4932 let y = clamp (pgscale conf.winh
) in
4933 gotoy_and_clear_text y
4935 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4936 gotoy_and_clear_text (getpagey pageno)
4938 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4940 let pagey, pageh
= getpageyh l.pageno in
4941 let pagey = pagey + pageh
* l.pagecol
in
4942 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4943 gotoy_and_clear_text (pagey + pageh
+ ips)
4946 | 0xff9f | 0xffff -> (* delete *)
4947 begin match state.layout with
4950 match conf.columns
with
4951 | Csingle
_ | Cmulti
_ ->
4952 if conf.presentation
&& l.pagey != 0
4954 gotoy_and_clear_text (clamp (pgscale ~
-(conf.winh
)))
4956 let pageno = max
0 (l.pageno-1) in
4957 gotoy_and_clear_text (getpagey pageno)
4965 let pageno = max
0 (l.pageno-1) in
4966 let pagey, pageh
= getpageyh pageno in
4969 let pagey, pageh
= getpageyh l.pageno in
4970 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4972 gotoy_and_clear_text y
4976 showtext ' '
(describe_location ());
4979 begin match state.layout with
4982 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4987 enterbookmarkmode ()
4989 | 104 | 0xffbe -> (* h|F1 *)
4995 | 101 when conf.redirectstderr -> (* e *)
5000 match state.layout with
5001 | l :: _ -> state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5004 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5008 showtext ' '
"Quick bookmark added";
5011 begin match state.layout with
5013 let rect = getpdimrect
l.pagedimno
in
5017 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5018 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5020 (truncate
(rect.(1) -. rect.(0)),
5021 truncate
(rect.(3) -. rect.(0)))
5023 let w = truncate
((float w)*.conf.zoom)
5024 and h = truncate
((float h)*.conf.zoom) in
5027 state.anchor <- getanchor ();
5028 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5030 G.postRedisplay "z";
5035 | 50 when ctrl -> (* ctrl-2 *)
5036 let maxw = getmaxw
() in
5038 then setzoom (maxw /. float conf.winw
)
5040 | 60 | 62 -> (* < > *)
5041 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5043 | 91 | 93 -> (* [ ] *)
5045 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5047 G.postRedisplay "brightness";
5049 | 99 when state.mode = View
-> (* c *)
5051 match state.prevcolumns
with
5052 | None
-> (1, 0, 0), 1.0
5053 | Some
(columns
, z
) ->
5056 | Csplit
(c, _) -> -c, 0, 0
5057 | Cmulti
((c, a, b), _) -> c, a, b
5058 | Csingle
_ -> 1, 0, 0
5062 setcolumns View
c a b;
5065 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5066 setzoom state.prevzoom
5068 | 107 | 0xff52 -> (* k up *)
5069 begin match state.autoscroll
with
5071 begin match state.mode with
5072 | Birdseye beye
-> upbirdseye 1 beye
5075 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5076 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5079 setautoscrollspeed n false
5082 | 106 | 0xff54 -> (* j down *)
5083 begin match state.autoscroll
with
5085 begin match state.mode with
5086 | Birdseye beye
-> downbirdseye 1 beye
5089 then gotoy_and_clear_text (clamp (conf.winh
/2))
5090 else gotoy_and_clear_text (clamp conf.scrollstep
)
5093 setautoscrollspeed n true
5096 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5104 let dx = if key = 0xff51 then dx else -dx in
5105 state.x <- state.x + dx;
5106 gotoy_and_clear_text state.y
5109 G.postRedisplay "lef/right"
5112 | 0xff55 -> (* prior *)
5116 match state.layout with
5118 | l :: _ -> state.y - l.pagey
5120 clamp (pgscale (-conf.winh
))
5124 | 0xff56 -> (* next *)
5128 match List.rev
state.layout with
5130 | l :: _ -> getpagey l.pageno
5132 clamp (pgscale conf.winh
)
5136 | 0xff50 -> (* home *)
5138 | 0xff57 -> (* end *)
5139 gotoghyll (clamp state.maxy)
5140 | 0xff53 when Wsi.withalt mask
-> (* right *)
5141 gotoghyll (getnav ~
-1)
5142 | 0xff51 when Wsi.withalt mask
-> (* left *)
5143 gotoghyll (getnav 1)
5146 state.anchor <- getanchor ();
5147 opendoc state.path state.password
5149 | 118 when conf.debug
-> (* v *)
5152 match getopaque l.pageno with
5155 let x0, y0, x1, y1 = pagebbox opaque
in
5156 let a,b = float x0, float y0 in
5157 let c,d = float x1, float y0 in
5158 let e,f = float x1, float y1 in
5159 let h,j
= float x0, float y1 in
5160 let rect = (a,b,c,d,e,f,h,j
) in
5162 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5164 G.postRedisplay "v";
5167 vlog "huh? %s" (Wsi.keyname
key)
5170 let linknavkeyboard key mask
linknav =
5171 let getpage pageno =
5172 let rec loop = function
5174 | l :: _ when l.pageno = pageno -> Some
l
5175 | _ :: rest
-> loop rest
5176 in loop state.layout
5178 let doexact (pageno, n) =
5179 match getopaque pageno, getpage pageno with
5180 | Some opaque
, Some
l ->
5183 let under = getlink opaque
n in
5184 G.postRedisplay "link gotounder";
5190 | 0xff50 -> (* home *)
5191 Some
(findlink opaque LDfirst
), -1
5193 | 0xff57 -> (* end *)
5194 Some
(findlink opaque LDlast
), 1
5196 | 0xff51 -> (* left *)
5197 Some
(findlink opaque
(LDleft
n)), -1
5199 | 0xff53 -> (* right *)
5200 Some
(findlink opaque
(LDright
n)), 1
5202 | 0xff52 -> (* up *)
5203 Some
(findlink opaque
(LDup
n)), -1
5205 | 0xff54 -> (* down *)
5206 Some
(findlink opaque
(LDdown
n)), 1
5211 begin match findpwl
l.pageno dir with
5215 state.mode <- LinkNav
(Ltgendir
dir);
5216 let y, h = getpageyh pageno in
5219 then y + h - conf.winh
5224 begin match getopaque pageno, getpage pageno with
5225 | Some opaque
, Some
_ ->
5227 let ld = if dir > 0 then LDfirst
else LDlast
in
5230 begin match link with
5232 showlinktype (getlink opaque
m);
5233 state.mode <- LinkNav
(Ltexact
(pageno, m));
5234 G.postRedisplay "linknav jpage";
5241 begin match opt with
5242 | Some Lnotfound
-> pwl l dir;
5243 | Some
(Lfound
m) ->
5247 let _, y0, _, y1 = getlinkrect opaque
m in
5249 then gotopage1 l.pageno y0
5251 let d = fstate.fontsize
+ 1 in
5252 if y1 - l.pagey > l.pagevh - d
5253 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5254 else G.postRedisplay "linknav";
5256 showlinktype (getlink opaque
m);
5257 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5260 | None
-> viewkeyboard key mask
5262 | _ -> viewkeyboard key mask
5267 G.postRedisplay "leave linknav"
5271 | Ltgendir
_ -> viewkeyboard key mask
5272 | Ltexact exact
-> doexact exact
5275 let keyboard key mask
=
5276 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5277 then wcmd "interrupt"
5278 else state.uioh <- state.uioh#
key key mask
5281 let birdseyekeyboard key mask
5282 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5284 match conf.columns
with
5286 | Cmulti
((c, _, _), _) -> c
5287 | Csplit
_ -> failwith
"bird's eye split mode"
5289 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5291 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5292 let y, h = getpageyh pageno in
5293 let top = (conf.winh
- h) / 2 in
5294 gotoy (max
0 (y - top))
5295 | 0xff0d -> leavebirdseye beye
false
5296 | 0xff1b -> leavebirdseye beye
true (* escape *)
5297 | 0xff52 -> upbirdseye incr beye
(* up *)
5298 | 0xff54 -> downbirdseye incr beye
(* down *)
5299 | 0xff51 -> upbirdseye 1 beye
(* left *)
5300 | 0xff53 -> downbirdseye 1 beye
(* right *)
5302 | 0xff55 -> (* prior *)
5303 begin match state.layout with
5307 state.mode <- Birdseye
(
5308 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5310 gotopage1 l.pageno 0;
5313 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5315 | [] -> gotoy (clamp (-conf.winh
))
5317 state.mode <- Birdseye
(
5318 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5320 gotopage1 l.pageno 0
5323 | [] -> gotoy (clamp (-conf.winh
))
5326 | 0xff56 -> (* next *)
5327 begin match List.rev
state.layout with
5329 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5330 begin match layout with
5332 let incr = l.pageh
- l.pagevh in
5337 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5339 G.postRedisplay "birdseye pagedown";
5341 else gotoy (clamp (incr + conf.interpagespace
*2));
5345 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5346 gotopage1 l.pageno 0;
5349 | [] -> gotoy (clamp conf.winh
)
5352 | 0xff50 -> (* home *)
5353 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5356 | 0xff57 -> (* end *)
5357 let pageno = state.pagecount
- 1 in
5358 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5359 if not
(pagevisible state.layout pageno)
5362 match List.rev
state.pdims
with
5364 | (_, _, h, _) :: _ -> h
5366 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5367 else G.postRedisplay "birdseye end";
5368 | _ -> viewkeyboard key mask
5371 let drawpage l linkindexbase
=
5373 match state.mode with
5374 | Textentry
_ -> scalecolor 0.4
5376 | View
-> scalecolor 1.0
5377 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5378 if l.pageno = hooverpageno
5381 if l.pageno = pageno
5387 begin match getopaque l.pageno with
5389 if tileready l l.pagex
l.pagey
5391 let x = l.pagedispx - l.pagex
5392 and y = l.pagedispy - l.pagey in
5394 match conf.columns
with
5395 | Csingle
_ | Cmulti
_ ->
5396 (if conf.hlinks
then 1 else 0)
5398 && not
(isbirdseye state.mode) then 2 else 0)
5402 match state.mode with
5403 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5406 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5413 let scrollindicator () =
5414 let sbw, ph
, sh = state.uioh#
scrollph in
5415 let sbh, pw, sw = state.uioh#scrollpw
in
5417 GlDraw.color (0.64, 0.64, 0.64);
5419 (float (conf.winw
- sbw), 0.)
5420 (float conf.winw
, float conf.winh
)
5423 (0., float (conf.winh
- sbh))
5424 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5426 GlDraw.color (0.0, 0.0, 0.0);
5429 (float (conf.winw
- sbw), ph
)
5430 (float conf.winw
, ph
+. sh)
5433 (pw, float (conf.winh
- sbh))
5434 (pw +. sw, float conf.winh
)
5439 match state.mstate
with
5440 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5443 | Msel
((x0, y0), (x1, y1)) ->
5444 let rec loop = function
5446 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5447 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5448 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5449 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5451 match getopaque l.pageno with
5453 let x0, y0 = pagetranslatepoint l x0 y0 in
5454 let x1, y1 = pagetranslatepoint l x1 y1 in
5455 seltext opaque
(x0, y0, x1, y1);
5463 let showrects rects
=
5465 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5466 GlDraw.polygon_mode `both `fill
;
5467 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5469 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5471 if l.pageno = pageno
5473 let dx = float (l.pagedispx - l.pagex
) in
5474 let dy = float (l.pagedispy - l.pagey) in
5475 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5476 GlDraw.begins `quads
;
5478 GlDraw.vertex2
(x0+.dx, y0+.dy);
5479 GlDraw.vertex2
(x1+.dx, y1+.dy);
5480 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5481 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5492 GlClear.color (scalecolor2 conf.bgcolor
);
5493 GlClear.clear
[`
color];
5494 let rec loop linkindexbase
= function
5496 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5497 loop linkindexbase rest
5500 loop 0 state.layout;
5502 match state.mode with
5503 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5504 begin match getopaque pageno with
5506 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5513 | None
-> state.rects
5520 begin match state.mstate
with
5521 | Mzoomrect
((x0, y0), (x1, y1)) ->
5523 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5524 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5525 GlDraw.rect (float x0, float y0)
5526 (float x1, float y1);
5535 let zoomrect x y x1 y1 =
5538 and y0 = min
y y1 in
5539 gotoy (state.y + y0);
5540 state.anchor <- getanchor ();
5541 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5543 if state.w < conf.winw
- state.scrollw
5544 then (conf.winw
- state.scrollw
- state.w) / 2
5547 state.x <- (state.x + margin) - x0;
5549 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5550 state.mstate
<- Mnone
;
5554 let winw = conf.winw - state.scrollw
- 1 in
5555 let s = float x /. float winw in
5556 let destx = truncate
(float (state.w + winw) *. s) in
5557 state.x <- winw - destx;
5558 gotoy_and_clear_text state.y;
5559 state.mstate
<- Mscrollx
;
5563 let s = float y /. float conf.winh
in
5564 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5565 gotoy_and_clear_text desty;
5566 state.mstate
<- Mscrolly
;
5569 let viewmouse button down
x y mask
=
5571 | n when (n == 4 || n == 5) && not down
->
5572 if Wsi.withctrl mask
5574 match state.mstate
with
5575 | Mzoom
(oldn
, i
) ->
5583 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5585 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5587 let zoom = conf.zoom -. incr in
5589 state.mstate
<- Mzoom
(n, 0);
5591 state.mstate
<- Mzoom
(n, i
+1);
5593 else state.mstate
<- Mzoom
(n, 0)
5595 | _ -> state.mstate
<- Mzoom
(n, 0)
5598 match state.autoscroll
with
5599 | Some step
-> setautoscrollspeed step
(n=4)
5603 then -conf.scrollstep
5604 else conf.scrollstep
5606 let incr = incr * 2 in
5607 let y = clamp incr in
5608 gotoy_and_clear_text y
5611 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5612 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5613 gotoy_and_clear_text state.y
5615 | 1 when Wsi.withctrl mask
->
5618 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5619 state.mstate
<- Mpan
(x, y)
5622 state.mstate
<- Mnone
5627 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5629 state.mstate
<- Mzoomrect
(p, p)
5632 match state.mstate
with
5633 | Mzoomrect
((x0, y0), _) ->
5634 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5635 then zoomrect x0 y0 x y
5637 state.mstate
<- Mnone
;
5638 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5639 G.postRedisplay "kill accidental zoom rect";
5642 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5643 state.mstate
<- Mnone
5646 | 1 when x > conf.winw - state.scrollw
->
5649 let _, position, sh = state.uioh#
scrollph in
5650 if y > truncate
position && y < truncate
(position +. sh)
5651 then state.mstate
<- Mscrolly
5654 state.mstate
<- Mnone
5656 | 1 when y > conf.winh
- state.hscrollh ->
5659 let _, position, sw = state.uioh#scrollpw
in
5660 if x > truncate
position && x < truncate
(position +. sw)
5661 then state.mstate
<- Mscrollx
5664 state.mstate
<- Mnone
5667 let dest = if down
then getunder x y else Unone
in
5668 begin match dest with
5672 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5675 | Unone
when down
->
5676 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5677 state.mstate
<- Mpan
(x, y);
5679 | Unone
| Utext
_ ->
5682 if conf.angle
mod 360 = 0
5684 state.mstate
<- Msel
((x, y), (x, y));
5685 G.postRedisplay "mouse select";
5689 match state.mstate
with
5692 | Mzoom
_ | Mscrollx
| Mscrolly
->
5693 state.mstate
<- Mnone
5695 | Mzoomrect
((x0, y0), _) ->
5699 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5700 state.mstate
<- Mnone
5702 | Msel
((_, y0), (_, y1)) ->
5703 let rec loop = function
5706 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5707 || ((y1 >= l.pagedispy
5708 && y1 <= (l.pagedispy + l.pagevh)))
5710 match getopaque l.pageno with
5713 match Ne.pipe () with
5717 "can not create sel pipe: %s"
5718 (Printexc.to_string exn
));
5720 let doclose what fd
=
5721 Ne.clo fd
(fun msg
->
5722 dolog "%s close failed: %s" what msg
)
5725 popen conf.selcmd
[r, 0; w, -1];
5728 G.postRedisplay "copysel";
5730 dolog "can not execute %S: %s"
5731 conf.selcmd
(Printexc.to_string exn
);
5739 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5740 state.mstate
<- Mnone
;
5747 let birdseyemouse button down
x y mask
5748 (conf, leftx
, _, hooverpageno
, anchor) =
5751 let rec loop = function
5754 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5755 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5757 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5763 | _ -> viewmouse button down
x y mask
5766 let mouse button down
x y mask
=
5767 state.uioh <- state.uioh#button button down
x y mask
;
5771 state.uioh <- state.uioh#
motion x y
5775 state.uioh <- state.uioh#
pmotion x y;
5781 method key key mask
=
5782 begin match state.mode with
5783 | Textentry
textentry -> textentrykeyboard key mask
textentry
5784 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5785 | View
-> viewkeyboard key mask
5786 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5790 method button button bstate
x y mask
=
5791 begin match state.mode with
5793 | View
-> viewmouse button bstate
x y mask
5794 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5800 begin match state.mode with
5802 | View
| Birdseye
_ | LinkNav
_ ->
5803 match state.mstate
with
5804 | Mzoom
_ | Mnone
-> ()
5809 state.mstate
<- Mpan
(x, y);
5811 then state.x <- state.x + dx;
5813 gotoy_and_clear_text y
5816 state.mstate
<- Msel
(a, (x, y));
5817 G.postRedisplay "motion select";
5820 let y = min
conf.winh
(max
0 y) in
5824 let x = min
conf.winw (max
0 x) in
5827 | Mzoomrect
(p0
, _) ->
5828 state.mstate
<- Mzoomrect
(p0
, (x, y));
5829 G.postRedisplay "motion zoomrect";
5833 method pmotion x y =
5834 begin match state.mode with
5835 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5836 let rec loop = function
5838 if hooverpageno
!= -1
5840 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5841 G.postRedisplay "pmotion birdseye no hoover";
5844 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5845 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5847 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5848 G.postRedisplay "pmotion birdseye hoover";
5858 match state.mstate
with
5859 | Mnone
-> updateunder x y
5860 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5865 method infochanged
_ = ()
5868 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5869 let p, h = scrollph state.y maxy in
5873 let winw = conf.winw - state.scrollw
- 1 in
5874 let fwinw = float winw in
5876 let sw = fwinw /. float state.w in
5877 let sw = fwinw *. sw in
5878 max
sw (float conf.scrollh
)
5881 let f = state.w+winw in
5882 let r = float (winw-state.x) /. float f in
5883 let p = fwinw *. r in
5887 if position +. sw > fwinw
5888 then fwinw -. position
5891 state.hscrollh, position, sw
5895 match state.mode with
5896 | LinkNav
_ -> "links"
5897 | Textentry
_ -> "textentry"
5898 | Birdseye
_ -> "birdseye"
5901 findkeyhash conf modename
5908 let fontpath = ref "";;
5911 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5914 let l = String.length
s in
5915 let b = Buffer.create
l in
5921 try Sys.getenv
"HOME"
5924 ("Can not determine home directory location: " ^
5925 Printexc.to_string exn
);
5929 let modifier_of_string = function
5930 | "alt" -> Wsi.altmask
5931 | "shift" -> Wsi.shiftmask
5932 | "ctrl" | "control" -> Wsi.ctrlmask
5933 | "meta" -> Wsi.metamask
5938 let r = Str.regexp
"-" in
5940 let elems = Str.full_split
r s in
5943 let m1 = modifier_of_string s in
5945 then (Wsi.namekey
s, m)
5948 | Str.Delim
s when n land 1 = 0 -> g s
5950 | Str.Delim
_ -> (k
, m)
5952 let rec loop n k
m = function
5955 let k, m = f n k m x in
5961 let keys_of_string =
5962 let r = Str.regexp
"[ \t]" in
5964 let elems = Str.split
r s in
5965 List.map
key_of_string elems
5968 let copykeyhashes c =
5969 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5972 let config_of c attrs
=
5976 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5977 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5978 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5979 | "preload" -> { c with preload = bool_of_string
v }
5980 | "page-bias" -> { c with pagebias
= int_of_string
v }
5981 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5982 | "horizontal-scroll-step" ->
5983 { c with hscrollstep
= max
(int_of_string
v) 1 }
5984 | "auto-scroll-step" ->
5985 { c with autoscrollstep
= max
0 (int_of_string
v) }
5986 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5987 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5990 match String.lowercase
v with
5991 | "true" -> Some infinity
5993 | f -> Some
(float_of_string
f)
5995 { c with maxwait
= mw}
5996 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5997 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5998 | "vertical-margin" ->
5999 { c with interpagespace
= max
0 (int_of_string
v) }
6001 let zoom = float_of_string
v /. 100. in
6002 let zoom = max
zoom 0.0 in
6003 { c with zoom = zoom }
6004 | "presentation" -> { c with presentation
= bool_of_string
v }
6005 | "rotation-angle" -> { c with angle
= int_of_string
v }
6006 | "width" -> { c with winw = max
20 (int_of_string
v) }
6007 | "height" -> { c with winh
= max
20 (int_of_string
v) }
6008 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6009 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6010 | "pixmap-cache-size" ->
6011 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6012 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6013 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6014 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6015 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6016 | "background-color" -> { c with bgcolor
= color_of_string v }
6017 | "scrollbar-in-presentation" ->
6018 { c with scrollbarinpm
= bool_of_string
v }
6019 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6020 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6021 | "mupdf-store-size" ->
6022 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6023 | "checkers" -> { c with checkers
= bool_of_string
v }
6024 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6025 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6026 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6027 | "uri-launcher" -> { c with urilauncher
= unent v }
6028 | "path-launcher" -> { c with pathlauncher
= unent v }
6029 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6030 | "invert-colors" -> { c with invert
= bool_of_string
v }
6031 | "brightness" -> { c with colorscale
= float_of_string
v }
6032 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6034 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6036 let (n, _, _) as nab
= multicolumns_of_string v in
6038 then { c with columns
= Csplit
(-n, [||]) }
6039 else { c with columns
= Cmulti
(nab
, [||]) }
6040 | "birds-eye-columns" ->
6041 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6042 | "selection-command" -> { c with selcmd
= unent v }
6043 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6044 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6045 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6046 | "multi-column-centering" -> { c with multicenter
= bool_of_string
v }
6049 prerr_endline
("Error processing attribute (`" ^
6050 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6053 let rec fold c = function
6056 let c = apply c k v in
6059 fold { c with keyhashes
= copykeyhashes c } attrs
;
6062 let fromstring f pos
n v d =
6065 dolog "Error processing attribute (%S=%S) at %d\n%s"
6066 n v pos
(Printexc.to_string exn
)
6071 let bookmark_of attrs
=
6072 let rec fold title page
rely visy
= function
6073 | ("title", v) :: rest
-> fold v page
rely visy rest
6074 | ("page", v) :: rest
-> fold title v rely visy rest
6075 | ("rely", v) :: rest
-> fold title page
v visy rest
6076 | ("visy", v) :: rest
-> fold title page
rely v rest
6077 | _ :: rest
-> fold title page
rely visy rest
6078 | [] -> title, page
, rely, visy
6080 fold "invalid" "0" "0" "0" attrs
6084 let rec fold path page
rely pan visy
= function
6085 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6086 | ("page", v) :: rest
-> fold path v rely pan visy rest
6087 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6088 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6089 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6090 | _ :: rest
-> fold path page
rely pan visy rest
6091 | [] -> path, page
, rely, pan
, visy
6093 fold "" "0" "0" "0" "0" attrs
6097 let rec fold rs ls
= function
6098 | ("out", v) :: rest
-> fold v ls rest
6099 | ("in", v) :: rest
-> fold rs
v rest
6100 | _ :: rest
-> fold ls rs rest
6106 let setconf dst
src =
6107 dst
.scrollbw
<- src.scrollbw
;
6108 dst
.scrollh
<- src.scrollh
;
6109 dst
.icase
<- src.icase
;
6110 dst
.preload <- src.preload;
6111 dst
.pagebias
<- src.pagebias
;
6112 dst
.verbose
<- src.verbose
;
6113 dst
.scrollstep
<- src.scrollstep
;
6114 dst
.maxhfit
<- src.maxhfit
;
6115 dst
.crophack
<- src.crophack
;
6116 dst
.autoscrollstep
<- src.autoscrollstep
;
6117 dst
.maxwait
<- src.maxwait
;
6118 dst
.hlinks
<- src.hlinks
;
6119 dst
.underinfo
<- src.underinfo
;
6120 dst
.interpagespace
<- src.interpagespace
;
6121 dst
.zoom <- src.zoom;
6122 dst
.presentation
<- src.presentation
;
6123 dst
.angle
<- src.angle
;
6124 dst
.winw <- src.winw;
6125 dst
.winh
<- src.winh
;
6126 dst
.savebmarks
<- src.savebmarks
;
6127 dst
.memlimit
<- src.memlimit
;
6128 dst
.proportional
<- src.proportional
;
6129 dst
.texcount
<- src.texcount
;
6130 dst
.sliceheight
<- src.sliceheight
;
6131 dst
.thumbw
<- src.thumbw
;
6132 dst
.jumpback
<- src.jumpback
;
6133 dst
.bgcolor
<- src.bgcolor
;
6134 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6135 dst
.tilew
<- src.tilew
;
6136 dst
.tileh
<- src.tileh
;
6137 dst
.mustoresize
<- src.mustoresize
;
6138 dst
.checkers
<- src.checkers
;
6139 dst
.aalevel
<- src.aalevel
;
6140 dst
.trimmargins
<- src.trimmargins
;
6141 dst
.trimfuzz
<- src.trimfuzz
;
6142 dst
.urilauncher
<- src.urilauncher
;
6143 dst
.colorspace
<- src.colorspace
;
6144 dst
.invert
<- src.invert
;
6145 dst
.colorscale
<- src.colorscale
;
6146 dst
.redirectstderr <- src.redirectstderr;
6147 dst
.ghyllscroll
<- src.ghyllscroll
;
6148 dst
.columns
<- src.columns
;
6149 dst
.beyecolumns
<- src.beyecolumns
;
6150 dst
.selcmd
<- src.selcmd
;
6151 dst
.updatecurs
<- src.updatecurs
;
6152 dst
.pathlauncher
<- src.pathlauncher
;
6153 dst
.keyhashes
<- copykeyhashes src;
6154 dst
.hfsize
<- src.hfsize
;
6155 dst
.hscrollstep
<- src.hscrollstep
;
6156 dst
.pgscale <- src.pgscale;
6157 dst
.multicenter
<- src.multicenter
;
6161 let h = Hashtbl.create
10 in
6162 let dc = { defconf with angle
= defconf.angle
} in
6163 let rec toplevel v t spos
_ =
6165 | Vdata
| Vcdata
| Vend
-> v
6166 | Vopen
("llppconfig", _, closed
) ->
6169 else { v with f = llppconfig
}
6171 error
"unexpected subelement at top level" s spos
6172 | Vclose
_ -> error
"unexpected close at top level" s spos
6174 and llppconfig
v t spos
_ =
6176 | Vdata
| Vcdata
-> v
6177 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6178 | Vopen
("defaults", attrs
, closed
) ->
6179 let c = config_of dc attrs
in
6183 else { v with f = defaults
}
6185 | Vopen
("ui-font", attrs
, closed
) ->
6186 let rec getsize size
= function
6188 | ("size", v) :: rest
->
6190 fromstring int_of_string spos
"size" v fstate.fontsize
in
6192 | l -> getsize size l
6194 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6197 else { v with f = uifont
(Buffer.create
10) }
6199 | Vopen
("doc", attrs
, closed
) ->
6200 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6201 let path = unent pathent
6202 and pageno = fromstring int_of_string spos
"page" spage
0
6203 and rely = fromstring float_of_string spos
"rely" srely
0.0
6204 and pan
= fromstring int_of_string spos
"pan" span
0
6205 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6206 let c = config_of dc attrs
in
6207 let anchor = (pageno, rely, visy
) in
6209 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6210 else { v with f = doc
path pan
anchor c [] }
6213 error
"unexpected subelement in llppconfig" s spos
6215 | Vclose
"llppconfig" -> { v with f = toplevel }
6216 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6218 and defaults
v t spos
_ =
6220 | Vdata
| Vcdata
-> v
6221 | Vend
-> error
"unexpected end of input in defaults" s spos
6222 | Vopen
("keymap", attrs
, closed
) ->
6224 try List.assoc
"mode" attrs
6225 with Not_found
-> "global" in
6230 let h = findkeyhash dc modename in
6231 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6234 { v with f = pkeymap
ret KeyMap.empty }
6236 | Vopen
(_, _, _) ->
6237 error
"unexpected subelement in defaults" s spos
6239 | Vclose
"defaults" ->
6240 { v with f = llppconfig
}
6242 | Vclose
_ -> error
"unexpected close in defaults" s spos
6244 and uifont
b v t spos
epos =
6247 Buffer.add_substring
b s spos
(epos - spos
);
6249 | Vopen
(_, _, _) ->
6250 error
"unexpected subelement in ui-font" s spos
6251 | Vclose
"ui-font" ->
6252 if String.length
!fontpath = 0
6253 then fontpath := Buffer.contents
b;
6254 { v with f = llppconfig
}
6255 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6256 | Vend
-> error
"unexpected end of input in ui-font" s spos
6258 and doc
path pan
anchor c bookmarks
v t spos
_ =
6260 | Vdata
| Vcdata
-> v
6261 | Vend
-> error
"unexpected end of input in doc" s spos
6262 | Vopen
("bookmarks", _, closed
) ->
6265 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6267 | Vopen
("keymap", attrs
, closed
) ->
6269 try List.assoc
"mode" attrs
6270 with Not_found
-> "global"
6276 let h = findkeyhash c modename in
6277 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6278 doc
path pan
anchor c bookmarks
6280 { v with f = pkeymap
ret KeyMap.empty }
6282 | Vopen
(_, _, _) ->
6283 error
"unexpected subelement in doc" s spos
6286 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6287 { v with f = llppconfig
}
6289 | Vclose
_ -> error
"unexpected close in doc" s spos
6291 and pkeymap
ret keymap
v t spos
_ =
6293 | Vdata
| Vcdata
-> v
6294 | Vend
-> error
"unexpected end of input in keymap" s spos
6295 | Vopen
("map", attrs
, closed
) ->
6296 let r, l = map_of attrs
in
6297 let kss = fromstring keys_of_string spos
"in" r [] in
6298 let lss = fromstring keys_of_string spos
"out" l [] in
6302 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6303 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6306 then { v with f = pkeymap
ret keymap }
6309 { v with f = skip
"map" f }
6312 error
"unexpected subelement in keymap" s spos
6314 | Vclose
"keymap" ->
6315 { v with f = ret keymap }
6317 | Vclose
_ -> error
"unexpected close in keymap" s spos
6319 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6321 | Vdata
| Vcdata
-> v
6322 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6323 | Vopen
("item", attrs
, closed
) ->
6324 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6325 let page = fromstring int_of_string spos
"page" spage
0
6326 and rely = fromstring float_of_string spos
"rely" srely
0.0
6327 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6329 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6332 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6335 { v with f = skip
"item" f }
6338 error
"unexpected subelement in bookmarks" s spos
6340 | Vclose
"bookmarks" ->
6341 { v with f = doc
path pan
anchor c bookmarks }
6343 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6345 and skip tag
f v t spos
_ =
6347 | Vdata
| Vcdata
-> v
6349 error
("unexpected end of input in skipped " ^ tag
) s spos
6350 | Vopen
(tag'
, _, closed
) ->
6354 let f'
() = { v with f = skip tag
f } in
6355 { v with f = skip tag'
f'
}
6359 else error
("unexpected close in skipped " ^ tag
) s spos
6362 parse
{ f = toplevel; accu = () } s;
6368 let len = in_channel_length ic
in
6369 let s = String.create
len in
6370 really_input ic
s 0 len;
6373 | Parse_error
(msg
, s, pos
) ->
6374 let subs = subs s pos
in
6375 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6376 failwith
("parse error: " ^
s)
6379 failwith
("config load error: " ^
Printexc.to_string exn
)
6385 let dir = Filename.concat
home ".config" in
6386 if Sys.is_directory
dir then dir else home
6389 Filename.concat
dir "llpp.conf"
6392 let confpath = ref defconfpath;;
6395 if Sys.file_exists
!confpath
6398 (try Some
(open_in_bin
!confpath)
6401 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6402 Printexc.to_string exn
);
6412 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6413 Printexc.to_string exn
);
6421 f (Hashtbl.create
0, defconf)
6426 let pc, pb
, px, pa
=
6428 Hashtbl.find h (Filename.basename
state.path)
6429 with Not_found
-> dc, [], 0, emptyanchor
6433 state.bookmarks <- pb
;
6435 state.scrollw
<- conf.scrollbw
;
6437 then state.anchor <- pa
;
6438 cbput state.hists
.nav pa
;
6444 let add_attrs bb always
dc c =
6447 then Printf.bprintf bb
"\n %s='%b'" s a
6450 then Printf.bprintf bb
"\n %s='%d'" s a
6453 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6456 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6459 then Printf.bprintf bb
"\n %s='%f'" s a
6463 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6467 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6471 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6475 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6481 | Some
(_N
, _A
, _B
) ->
6482 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6492 else string_of_float
f
6494 Printf.bprintf bb
"\n %s='%s'" s v
6499 | Cmulti
((n, a, b), _) when n > 1 ->
6500 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6501 | Csplit
(n, _) when n > 1 ->
6502 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6508 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6513 then dc.winw, dc.winh
6515 match state.fullscreen
with
6517 | None
-> c.winw, c.winh
6519 oi
"width" w dc.winw;
6520 oi
"height" h dc.winh
;
6521 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6522 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6523 ob "case-insensitive-search" c.icase
dc.icase
;
6524 ob "preload" c.preload dc.preload;
6525 oi
"page-bias" c.pagebias
dc.pagebias
;
6526 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6527 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6528 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6529 ob "crop-hack" c.crophack
dc.crophack
;
6530 oW
"throttle" c.maxwait
dc.maxwait
;
6531 ob "highlight-links" c.hlinks
dc.hlinks
;
6532 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6533 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6534 oz
"zoom" c.zoom dc.zoom;
6535 ob "presentation" c.presentation
dc.presentation
;
6536 oi
"rotation-angle" c.angle
dc.angle
;
6537 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6538 ob "proportional-display" c.proportional
dc.proportional
;
6539 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6540 oi
"tex-count" c.texcount
dc.texcount
;
6541 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6542 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6543 ob "persistent-location" c.jumpback
dc.jumpback
;
6544 oc
"background-color" c.bgcolor
dc.bgcolor
;
6545 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6546 oi
"tile-width" c.tilew
dc.tilew
;
6547 oi
"tile-height" c.tileh
dc.tileh
;
6548 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6549 ob "checkers" c.checkers
dc.checkers
;
6550 oi
"aalevel" c.aalevel
dc.aalevel
;
6551 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6552 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6553 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6554 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6555 oC
"color-space" c.colorspace
dc.colorspace
;
6556 ob "invert-colors" c.invert
dc.invert
;
6557 oF
"brightness" c.colorscale
dc.colorscale
;
6558 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6559 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6560 oco
"columns" c.columns
dc.columns
;
6561 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6562 os
"selection-command" c.selcmd
dc.selcmd
;
6563 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6564 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6565 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6566 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6567 ob "multi-column-centering" c.multicenter
dc.multicenter
;
6570 let keymapsbuf always
dc c =
6571 let bb = Buffer.create
16 in
6572 let rec loop = function
6574 | (modename, h) :: rest
->
6575 let dh = findkeyhash dc modename in
6576 if always
|| h <> dh
6578 if Hashtbl.length
h > 0
6580 if Buffer.length
bb > 0
6581 then Buffer.add_char
bb '
\n'
;
6582 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6583 Hashtbl.iter
(fun i
o ->
6584 let isdifferent = always
||
6586 let dO = Hashtbl.find dh i
in
6588 with Not_found
-> true
6593 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6594 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6595 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6596 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6597 Buffer.add_string
bb (Wsi.keyname
k);
6600 let rec loop = function
6602 | km
:: [] -> addkm km
6603 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6607 Buffer.add_string
bb "<map in='";
6611 Buffer.add_string
bb "' out='";
6613 Buffer.add_string
bb "'/>\n"
6616 Buffer.add_string
bb "' out='";
6618 Buffer.add_string
bb "'/>\n"
6620 | KMmulti
(ins, kms
) ->
6621 Buffer.add_char
bb ' '
;
6623 Buffer.add_string
bb "' out='";
6625 Buffer.add_string
bb "'/>\n"
6627 Buffer.add_string
bb "</keymap>";
6637 let uifontsize = fstate.fontsize
in
6638 let bb = Buffer.create
32768 in
6640 let dc = if conf.bedefault
then conf else dc in
6641 Buffer.add_string
bb "<llppconfig>\n";
6643 if String.length
!fontpath > 0
6645 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6651 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6654 Buffer.add_string
bb "<defaults ";
6655 add_attrs bb true dc dc;
6656 let kb = keymapsbuf true dc dc in
6657 if Buffer.length
kb > 0
6659 Buffer.add_string
bb ">\n";
6660 Buffer.add_buffer
bb kb;
6661 Buffer.add_string
bb "\n</defaults>\n";
6663 else Buffer.add_string
bb "/>\n";
6665 let adddoc path pan
anchor c bookmarks =
6666 if bookmarks == [] && c = dc && anchor = emptyanchor
6669 Printf.bprintf
bb "<doc path='%s'"
6670 (enent
path 0 (String.length
path));
6672 if anchor <> emptyanchor
6674 let n, rely, visy
= anchor in
6675 Printf.bprintf
bb " page='%d'" n;
6678 Printf.bprintf
bb " rely='%f'" rely
6680 if abs_float visy
> 1e-6
6682 Printf.bprintf
bb " visy='%f'" visy
6687 then Printf.bprintf
bb " pan='%d'" pan
;
6689 add_attrs bb false dc c;
6690 let kb = keymapsbuf false dc c in
6692 begin match bookmarks with
6694 if Buffer.length
kb > 0
6696 Buffer.add_string
bb ">\n";
6697 Buffer.add_buffer
bb kb;
6698 Buffer.add_string
bb "\n</doc>\n";
6700 else Buffer.add_string
bb "/>\n"
6702 Buffer.add_string
bb ">\n<bookmarks>\n";
6703 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6705 "<item title='%s' page='%d'"
6706 (enent
title 0 (String.length
title))
6711 Printf.bprintf
bb " rely='%f'" rely
6713 if abs_float visy
> 1e-6
6715 Printf.bprintf
bb " visy='%f'" visy
6717 Buffer.add_string
bb "/>\n";
6719 Buffer.add_string
bb "</bookmarks>";
6720 if Buffer.length
kb > 0
6722 Buffer.add_string
bb "\n";
6723 Buffer.add_buffer
bb kb;
6725 Buffer.add_string
bb "\n</doc>\n";
6731 match state.mode with
6732 | Birdseye
(c, pan, _, _, _) ->
6734 match conf.columns
with
6735 | Cmulti
((c, _, _), _) -> Some
c
6739 match c.columns
with
6740 | Cmulti
(c, _) -> Cmulti
(c, [||])
6741 | Csingle
_ -> Csingle
[||]
6742 | Csplit
_ -> failwith
"quit from bird's eye while split"
6744 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6745 | _ -> state.x, conf
6747 let basename = Filename.basename state.path in
6748 adddoc basename pan (getanchor ())
6750 let autoscrollstep =
6751 match state.autoscroll
with
6753 | None
-> conf.autoscrollstep
6755 match state.mode with
6756 | Birdseye
(bc
, _, _, _, _) ->
6759 presentation
= bc
.presentation
;
6760 interpagespace
= bc
.interpagespace
;
6761 maxwait
= bc
.maxwait
;
6762 autoscrollstep = autoscrollstep }
6763 | _ -> { conf with autoscrollstep = autoscrollstep }
6765 (if conf.savebmarks
then state.bookmarks else []);
6767 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6769 then adddoc path x anchor c bookmarks
6771 Buffer.add_string
bb "</llppconfig>\n";
6774 if load1 f && Buffer.length
bb > 0
6777 let tmp = !confpath ^
".tmp" in
6778 let oc = open_out_bin
tmp in
6779 Buffer.output_buffer
oc bb;
6781 Unix.rename
tmp !confpath;
6784 ("error while saving configuration: " ^
Printexc.to_string exn
)
6789 let trimcachepath = ref "" in
6792 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6793 "<password> Set password");
6795 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6796 "<path> Set path to the user interface font");
6798 ("-c", Arg.String
(fun s -> Config.confpath := s),
6799 "<path> Set path to the configuration file");
6801 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6802 "<path> Set path to the trim cache file");
6804 ("-v", Arg.Unit
(fun () ->
6806 "%s\nconfiguration path: %s\n"
6810 exit
0), " Print version and exit");
6813 (fun s -> state.path <- s)
6814 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6816 if String.length
state.path = 0
6817 then (prerr_endline
"file name missing"; exit
1);
6819 if not
(Config.load ())
6820 then prerr_endline
"failed to load configuration";
6822 let globalkeyhash = findkeyhash conf "global" in
6823 let wsfd, winw, winh
= Wsi.init
(object
6825 if nogeomcmds state.geomcmds
|| platform == Posx
6828 GlClear.color (scalecolor2 conf.bgcolor
);
6829 GlClear.clear
[`
color];
6831 method display = display ()
6832 method reshape w h = reshape w h
6833 method mouse b d x y m = mouse b d x y m
6834 method motion x y = state.mpos
<- (x, y); motion x y
6835 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6837 let mascm = m land (
6838 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6840 match state.keystate
with
6842 let km = k, mascm in
6845 let modehash = state.uioh#
modehash in
6846 try Hashtbl.find modehash km
6848 try Hashtbl.find globalkeyhash km
6849 with Not_found
-> KMinsrt
(k, m)
6851 | KMinsrt
(k, m) -> keyboard k m
6852 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6853 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6855 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6856 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6857 state.keystate
<- KSnone
6858 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6859 state.keystate
<- KSinto
(keys
, insrt
)
6861 state.keystate
<- KSnone
6863 method enter
x y = state.mpos
<- (x, y); pmotion x y
6864 method leave = state.mpos
<- (-1, -1)
6865 method quit
= raise Quit
6866 end) conf.winw conf.winh
(platform = Posx
) in
6871 List.exists
GlMisc.check_extension
6872 [ "GL_ARB_texture_rectangle"
6873 ; "GL_EXT_texture_recangle"
6874 ; "GL_NV_texture_rectangle" ]
6876 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6879 match Ne.pipe () with
6881 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6885 match Ne.pipe () with
6887 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6897 setcheckers conf.checkers
;
6901 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6902 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6903 !Config.fontpath, !trimcachepath
6907 state.text <- "Opening " ^
state.path;
6909 opendoc state.path state.password
;
6912 let rec loop deadline
=
6914 match state.errfd
with
6915 | None
-> [state.sr
; state.wsfd]
6916 | Some fd
-> [state.sr
; state.wsfd; fd
]
6920 state.redisplay
<- false;
6927 if deadline
= infinity
6929 else max
0.0 (deadline
-. now)
6934 try Unix.select
r [] [] timeout
6935 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6941 if state.ghyll
== noghyll
6943 match state.autoscroll
with
6944 | Some step
when step
!= 0 ->
6945 let y = state.y + step
in
6949 else if y >= state.maxy then 0 else y
6952 if state.mode = View
6953 then state.text <- "";
6956 else deadline
+. 0.01
6961 let rec checkfds = function
6963 | fd
:: rest
when fd
= state.sr
->
6964 let cmd = readcmd state.sr
in
6968 | fd
:: rest
when fd
= state.wsfd ->
6973 let s = String.create
80 in
6974 let n = Unix.read fd
s 0 80 in
6975 if conf.redirectstderr
6977 Buffer.add_substring
state.errmsgs
s 0 n;
6978 state.newerrmsgs
<- true;
6979 state.redisplay
<- true;
6982 prerr_string
(String.sub
s 0 n);
6990 if deadline
= infinity
6994 match state.autoscroll
with
6995 | Some step
when step
!= 0 -> deadline1
6996 | _ -> if state.ghyll
== noghyll then infinity
else deadline1