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, _
, coverB
), b) ->
1033 if Array.length
b > 0
1035 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1039 let rec loop y h
n =
1043 if n = Array.length
b
1046 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
1052 loop max_int
0 (((Array.length
b - 1) / c) * c)
1054 if Array.length
b > 0
1056 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1057 y + h
+ (if conf.presentation
then calcips h
else 0)
1060 if Array.length
b > 0
1062 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1067 let rowyh (c, coverA
, coverB
) b n =
1068 if c = 1 || (n < coverA
|| n > state.pagecount
- coverB
)
1070 let _, _, vy
, (_, _, h
, _) = b.(n) in
1073 let n'
= n - coverA
in
1077 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1078 let _, _, y, (_, _, h
, _) = b.(m
) in
1079 let miny = min
miny y in
1080 let maxh = max
maxh h
in
1081 find (m
+1) miny maxh
1085 let getpageyh pageno
=
1086 let pageno = bound pageno 0 (state.pagecount
-1) in
1087 match conf.columns
with
1089 if Array.length
b = 0
1092 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1094 if conf.presentation
1100 if Array.length
b = 0
1102 else rowyh cl
b pageno
1104 if Array.length
b = 0
1108 let (_, _, y, (_, _, h
, _)) = b.(n) in
1112 let getpagedim pageno =
1115 | (n, _, _, _) as pdim
:: rest
->
1117 then (if n = pageno then pdim
else ppdim
)
1122 f (-1, -1, -1, -1) state.pdims
1125 let getpagey pageno = fst
(getpageyh pageno);;
1127 let nogeomcmds cmds
=
1129 | s, [] -> String.length
s = 0
1134 let ((c, coverA
, coverB
) as cl
), b =
1135 match conf.columns
with
1136 | Csingle
b -> (1, 0, 0), b
1137 | Cmulti
(c, b) -> c, b
1138 | Csplit
(_, b) -> (1, 0, 0), b
1140 let rec bsearch nmin nmax
=
1142 then bound nmin
0 (state.pagecount
-1)
1144 let n = (nmax
+ nmin
) / 2 in
1145 let vy, h
= rowyh cl
b n in
1147 if c = 1 && conf.presentation
1149 let ips = calcips h
in
1150 let y0 = vy - ips in
1151 let y1 = vy + h
+ ips in
1155 then 0, vy + h
+ conf.interpagespace
1157 let y0 = vy - conf.interpagespace
in
1158 y0, y0 + h
+ conf.interpagespace
1161 if y >= y0 && y < y1
1168 if n < state.pagecount
- coverB
1169 then ((n-coverA
)/c)*c + coverA
1176 then bsearch (n+1) nmax
1177 else bsearch nmin
(n-1)
1180 let r = bsearch 0 (state.pagecount
-1) in
1184 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1185 let sh = sh - state.hscrollh
in
1186 let rec fold accu
n =
1187 if n = Array.length
b
1190 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1193 || n = state.pagecount
- coverB
1194 || (n - coverA
) mod columns
= columns
- 1)
1200 let pagey = max
0 (y - vy) in
1201 let pagedispy = if pagey > 0 then 0 else vy - y in
1202 let pagedispx, pagex
=
1204 if n = coverA
- 1 || n = state.pagecount
- coverB
1205 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1206 else dx + xoff
+ state.x
1213 let vw = conf.winw
- state.scrollw
- pagedispx in
1214 let pw = w
- pagex
in
1217 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1218 if pagevw > 0 && pagevh > 0
1222 ; pagedimno
= pdimno
1229 ; pagedispx = pagedispx
1230 ; pagedispy = pagedispy
1242 List.rev
(fold [] (page_of_y y));
1245 let layoutS (columns
, b) y sh =
1246 let sh = sh - state.hscrollh
in
1247 let rec fold accu n =
1248 if n = Array.length
b
1251 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1258 let x = xoff
+ state.x in
1259 let pagey = max
0 (y - vy) in
1260 let pagedispy = if pagey > 0 then 0 else vy - y in
1261 let pagedispx, pagex
=
1275 let pagecolw = pagew
/columns
in
1277 if pagecolw < conf.winw
1278 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1282 let vw = conf.winw
- pagedispx - state.scrollw
in
1283 let pw = pagew
- pagex
in
1286 let pagevw = min
pagevw pagecolw in
1287 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1288 if pagevw > 0 && pagevh > 0
1291 { pageno = n/columns
1292 ; pagedimno
= pdimno
1299 ; pagedispx = pagedispx
1300 ; pagedispy = pagedispy
1301 ; pagecol
= n mod columns
1312 List.rev
(fold [] 0)
1316 if nogeomcmds state.geomcmds
1318 match conf.columns
with
1319 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1320 | Cmulti
c -> layoutN c y sh
1321 | Csplit
s -> layoutS s y sh
1326 let y = state.y + incr
in
1328 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1333 let tilex = l
.pagex
mod conf.tilew
in
1334 let tiley = l
.pagey mod conf.tileh
in
1336 let col = l
.pagex
/ conf.tilew
in
1337 let row = l
.pagey / conf.tileh
in
1339 let rec rowloop row y0 dispy h
=
1343 let dh = conf.tileh
- y0 in
1344 let dh = min h
dh in
1345 let rec colloop col x0 dispx w
=
1349 let dw = conf.tilew
- x0 in
1350 let dw = min w
dw in
1352 f col row dispx dispy
x0 y0 dw dh;
1353 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1356 colloop col tilex l
.pagedispx l
.pagevw;
1357 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1360 if l
.pagevw > 0 && l
.pagevh > 0
1361 then rowloop row tiley l
.pagedispy l
.pagevh;
1364 let gettileopaque l
col row =
1366 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1368 try Some
(Hashtbl.find state.tilemap
key)
1369 with Not_found
-> None
1372 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1373 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1374 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1377 let drawtiles l color
=
1379 let f col row x y tilex tiley w h
=
1380 match gettileopaque l
col row with
1381 | Some
(opaque
, _, t
) ->
1382 let params = x, y, w
, h
, tilex, tiley in
1386 GlFunc.blend_func `zero `one_minus_src_color
;
1388 drawtile
params opaque
;
1390 then Gl.disable `blend
;
1393 let s = Printf.sprintf
1397 let w = measurestr
fstate.fontsize
s in
1398 GlMisc.push_attrib
[`current
];
1399 GlDraw.color
(0.0, 0.0, 0.0);
1401 (float (x-2), float (y-2))
1402 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1403 GlDraw.color
(1.0, 1.0, 1.0);
1404 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1405 GlMisc.pop_attrib
();
1410 let lw = conf.winw
- state.scrollw
- x in
1413 let lh = conf.winh
- y in
1416 begin match state.texid
with
1418 Gl.enable `texture_2d
;
1419 GlTex.bind_texture `texture_2d id
;
1422 and x1 = float (x+w)
1423 and y1 = float (y+h
) in
1425 let tw = float w /. 64.0
1426 and th
= float h
/. 64.0 in
1427 let tx0 = float tilex /. 64.0
1428 and ty0
= float tiley /. 64.0 in
1430 and ty1
= ty0
+. th
in
1431 GlDraw.begins `quads
;
1432 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1433 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1434 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1435 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1438 Gl.disable `texture_2d
;
1440 GlDraw.color
(1.0, 1.0, 1.0);
1443 (float (x+w), float (y+h
));
1445 if w > 128 && h
> fstate.fontsize
+ 10
1447 GlDraw.color
(0.0, 0.0, 0.0);
1450 then (col*conf.tilew
, row*conf.tileh
)
1453 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1460 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1462 let tilevisible1 l
x y =
1464 and ax1
= l
.pagex
+ l
.pagevw
1466 and ay1
= l
.pagey + l
.pagevh in
1470 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1471 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1473 let rx0 = max
ax0 bx0
1474 and ry0
= max ay0 by0
1475 and rx1
= min ax1
bx1
1476 and ry1
= min ay1 by1
in
1478 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1479 nonemptyintersection
1482 let tilevisible layout n x y =
1483 let rec findpageinlayout m
= function
1484 | l
:: rest
when l
.pageno = n ->
1485 tilevisible1 l
x y || (
1486 match conf.columns
with
1487 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1490 | _ :: rest
-> findpageinlayout 0 rest
1493 findpageinlayout 0 layout;
1496 let tileready l
x y =
1497 tilevisible1 l
x y &&
1498 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1501 let tilepage n p
layout =
1502 let rec loop = function
1506 let f col row _ _ _ _ _ _ =
1507 if state.currently
= Idle
1509 match gettileopaque l
col row with
1512 let x = col*conf.tilew
1513 and y = row*conf.tileh
in
1515 let w = l
.pagew
- x in
1519 let h = l
.pageh
- y in
1522 wcmd "tile %s %d %d %d %d" p
x y w h;
1525 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1526 conf.tilew
, conf.tileh
1535 if nogeomcmds state.geomcmds
1539 let preloadlayout y =
1540 let y = if y < conf.winh
then 0 else y - conf.winh
in
1541 let h = conf.winh
*3 in
1546 let rec loop pages
=
1547 if state.currently
!= Idle
1552 begin match getopaque l
.pageno with
1554 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1555 state.currently
<- Loading
(l
, state.gen
);
1557 tilepage l
.pageno opaque pages
;
1562 if nogeomcmds state.geomcmds
1568 if conf.preload && state.currently
= Idle
1569 then load (preloadlayout state.y);
1572 let layoutready layout =
1573 let rec fold all ls
=
1574 all
&& match ls
with
1576 let seen = ref false in
1577 let allvisible = ref true in
1578 let foo col row _ _ _ _ _ _ =
1580 allvisible := !allvisible &&
1581 begin match gettileopaque l
col row with
1587 fold (!seen && !allvisible) rest
1590 let alltilesvisible = fold true layout in
1595 let y = bound y 0 state.maxy
in
1596 let y, layout, proceed
=
1597 match conf.maxwait
with
1598 | Some time
when state.ghyll
== noghyll ->
1599 begin match state.throttle
with
1601 let layout = layout y conf.winh
in
1602 let ready = layoutready layout in
1606 state.throttle
<- Some
(layout, y, now ());
1608 else G.postRedisplay "gotoy showall (None)";
1610 | Some
(_, _, started
) ->
1611 let dt = now () -. started
in
1614 state.throttle
<- None
;
1615 let layout = layout y conf.winh
in
1617 G.postRedisplay "maxwait";
1624 let layout = layout y conf.winh
in
1625 if true || layoutready layout
1626 then G.postRedisplay "gotoy ready";
1632 state.layout <- layout;
1633 begin match state.mode
with
1634 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1635 let rec loop = function
1637 state.mode
<- LinkNav
(Ltgendir
0)
1638 | l
:: _ when l
.pageno = pageno ->
1639 begin match getopaque pageno with
1641 state.mode
<- LinkNav
(Ltgendir
0)
1643 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1644 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1645 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1646 then state.mode
<- LinkNav
(Ltgendir
0)
1648 | _ :: rest
-> loop rest
1653 begin match state.mode
with
1654 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1655 if not
(pagevisible layout pageno)
1657 match state.layout with
1660 state.mode
<- Birdseye
(
1661 conf, leftx
, l
.pageno, hooverpageno
, anchor
1664 | LinkNav
(Ltgendir dir
as lt
) ->
1666 let rec loop = function
1669 match getopaque l
.pageno with
1675 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1677 if dir
> 0 then LDfirst
else LDlast
1683 | Lnotfound
-> loop rest
1685 showlinktype (getlink opaque
n);
1686 Ltexact
(l
.pageno, n)
1690 state.mode
<- LinkNav
linknav
1695 state.ghyll
<- noghyll;
1698 let mx, my
= state.mpos
in
1703 let conttiling pageno opaque
=
1704 tilepage pageno opaque
1705 (if conf.preload then preloadlayout state.y else state.layout)
1708 let gotoy_and_clear_text y =
1709 if not
conf.verbose
then state.text <- "";
1715 let coloff = l
.pagecol
* l
.pageh
in
1716 float (l
.pagey + coloff) /. float l
.pageh
1723 if conf.presentation
1724 then float l
.pagedispy /. float (calcips l
.pageh
)
1725 else float l
.pagedispy /. float conf.interpagespace
1727 (l
.pageno, top, dtop)
1731 match state.layout with
1732 | l
:: _ -> getanchor1 l
1734 let n = page_of_y state.y in
1735 let y, h = getpageyh n in
1736 let dy = y - state.y in
1738 if conf.presentation
1740 let ips = calcips h in
1741 float (dy + ips) /. float ips
1743 float dy /. float conf.interpagespace
1748 let getanchory (n, top, dtop) =
1749 let y, h = getpageyh n in
1750 if conf.presentation
1752 let ips = calcips h in
1753 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1755 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1758 let gotoanchor anchor
=
1759 gotoy (getanchory anchor
);
1763 cbput state.hists
.nav
(getanchor ());
1767 let anchor = cbgetc state.hists
.nav dir
in
1772 let scroll f n a
b =
1773 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1775 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1777 then s (float f /. float a
)
1780 then 1.0 -. s ((float (f-b) /. float (n-b)))
1787 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1788 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1790 let ins = float a
*. iv1
1791 and outs
= float (n-b) *. iv1 in
1793 ins +. outs
+. float ones
1795 let rec set (_N
, _A
, _B
) y sy
=
1796 let sum = summa
1.0 _N _A _B
in
1797 let dy = float (y - sy
) in
1801 then state.ghyll
<- noghyll
1804 let s = scroll n _N _A _B
in
1805 let y1 = y1 +. ((s *. dy) /. sum) in
1806 gotoy_and_clear_text (truncate
y1);
1807 state.ghyll
<- gf (n+1) y1;
1811 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1813 gf 0 (float state.y)
1816 match conf.ghyllscroll
with
1818 gotoy_and_clear_text y
1820 if state.ghyll
== noghyll
1821 then set nab
y state.y
1822 else state.ghyll
(Some
y)
1825 let gotopage n top =
1826 let y, h = getpageyh n in
1827 let y = y + (truncate
(top *. float h)) in
1831 let gotopage1 n top =
1832 let y = getpagey n in
1837 let invalidate s f =
1842 match state.geomcmds
with
1843 | ps
, [] when String.length ps
= 0 ->
1845 state.geomcmds
<- s, [];
1848 state.geomcmds
<- ps
, [s, f];
1850 | ps
, (s'
, _) :: rest
when s'
= s ->
1851 state.geomcmds
<- ps
, ((s, f) :: rest
);
1854 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1857 let opendoc path password
=
1859 state.password
<- password
;
1860 state.gen
<- state.gen
+ 1;
1861 state.docinfo
<- [];
1863 setaalevel
conf.aalevel
;
1864 Wsi.settitle
("llpp " ^
Filename.basename path
);
1865 wcmd "open %s\000%s\000" path password
;
1866 invalidate "reqlayout"
1868 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1872 let c = c *. conf.colorscale
in
1876 let scalecolor2 (r, g
, b) =
1877 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1880 let docolumns = function
1882 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1883 let rec loop pageno pdimno pdim
y ph pdims
=
1884 if pageno = state.pagecount
1887 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1889 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1890 pdimno+1, pdim
, rest
1894 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1896 (if conf.presentation
1897 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1898 else (if pageno = 0 then 0 else calcips h)
1901 a.(pageno) <- (pdimno, x, y, pdim
);
1902 loop (pageno+1) pdimno pdim
(y + h) h pdims
1904 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1905 conf.columns
<- Csingle
a;
1907 | Cmulti
((columns
, coverA
, coverB
), _) ->
1908 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1909 let rec loop pageno pdimno pdim
x y rowh pdims
=
1910 let rec fixrow m
= if m
= pageno then () else
1911 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1914 let y = y + (rowh
- h) / 2 in
1915 a.(m
) <- (pdimno, x, y, pdim
);
1919 if pageno = state.pagecount
1920 then fixrow (((pageno - 1) / columns
) * columns
)
1922 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1924 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1925 pdimno+1, pdim
, rest
1930 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1932 (conf.winw
- state.scrollw
- w) / 2,
1933 y + rowh
+ conf.interpagespace
, h
1936 if (pageno - coverA
) mod columns
= 0
1938 (if conf.multicenter
then
1939 (conf.winw
- state.scrollw
- state.w) / 2 else 0),
1940 y + rowh
+ (if pageno = 0 then 0 else conf.interpagespace
), h
1942 else x, y, max rowh
h
1945 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1946 then fixrow (pageno - columns
);
1947 a.(pageno) <- (pdimno, x, y, pdim
);
1948 let x = x + w + xoff
*2 + conf.interpagespace
in
1949 loop (pageno+1) pdimno pdim
x y rowh' pdims
1951 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1952 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1955 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1956 let rec loop pageno pdimno pdim
y pdims
=
1957 if pageno = state.pagecount
1960 let pdimno, ((_, w, h, _) as pdim
), pdims
=
1962 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1963 pdimno+1, pdim
, rest
1968 let rec loop1 n x y =
1969 if n = c then y else (
1970 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
1971 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
1974 let y = loop1 0 0 y in
1975 loop (pageno+1) pdimno pdim
y pdims
1977 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1978 conf.columns
<- Csplit
(c, a);
1982 docolumns conf.columns
;
1983 state.maxy
<- calcheight ();
1985 if state.w <= conf.winw
- state.scrollw
1989 match state.mode
with
1990 | Birdseye
(_, _, pageno, _, _) ->
1991 let y, h = getpageyh pageno in
1992 let top = (conf.winh
- h) / 2 in
1993 gotoy (max
0 (y - top))
1994 | _ -> gotoanchor state.anchor
1998 GlDraw.viewport
0 0 w h;
1999 let firsttime = state.geomcmds
== firstgeomcmds in
2000 if not
firsttime && nogeomcmds state.geomcmds
2001 then state.anchor <- getanchor ();
2004 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2007 setfontsize fstate.fontsize
;
2008 GlMat.mode `modelview
;
2009 GlMat.load_identity
();
2011 GlMat.mode `projection
;
2012 GlMat.load_identity
();
2013 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2014 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2015 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2020 else float state.x /. float state.w
2022 invalidate "geometry"
2026 then state.x <- truncate
(relx *. float w);
2028 match conf.columns
with
2030 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2031 | Csplit
(c, _) -> w * c
2033 wcmd "geometry %d %d" w h);
2037 let len = String.length
state.text in
2040 match state.mode
with
2043 let h, _, _ = state.uioh#scrollpw
in
2049 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2050 (x+.w, float (conf.winh
- hscrollh))
2053 let w = float (conf.winw
- state.scrollw
- 1) in
2054 if state.progress
>= 0.0 && state.progress
< 1.0
2056 GlDraw.color
(0.3, 0.3, 0.3);
2057 let w1 = w *. state.progress
in
2059 GlDraw.color
(0.0, 0.0, 0.0);
2063 GlDraw.color
(0.0, 0.0, 0.0);
2067 GlDraw.color
(1.0, 1.0, 1.0);
2068 drawstring fstate.fontsize
2069 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2072 match state.mode
with
2073 | Textentry
((prefix
, text, _, _, _, _), _) ->
2077 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2079 Printf.sprintf
"%s%s_" prefix
text
2088 if not
(istextentry state.mode
)
2090 let s1 = "(press 'e' to review error messasges)" in
2091 if String.length
s > 0 then s ^
" " ^
s1 else s1
2096 if String.length
s > 0
2101 let len = Queue.length
state.tilelru
in
2103 match state.throttle
with
2106 then preloadlayout state.y
2108 | Some
(layout, _, _) ->
2112 if state.memused
<= conf.memlimit
2117 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2118 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2119 let (_, pw, ph
, _) = getpagedim n in
2122 && colorspace
= conf.colorspace
2123 && angle
= conf.angle
2127 let x = col*conf.tilew
2128 and y = row*conf.tileh
in
2129 tilevisible (Lazy.force_val
layout) n x y
2131 then Queue.push lruitem
state.tilelru
2133 wcmd "freetile %s" p
;
2134 state.memused
<- state.memused
- s;
2135 state.uioh#infochanged Memused
;
2136 Hashtbl.remove
state.tilemap k
;
2145 Queue.iter
(fun (k
, p
, s) ->
2146 wcmd "freetile %s" p
;
2147 state.memused
<- state.memused
- s;
2148 state.uioh#infochanged Memused
;
2149 Hashtbl.remove
state.tilemap k
;
2151 Queue.clear
state.tilelru
;
2155 let logcurrently = function
2156 | Idle
-> dolog "Idle"
2157 | Loading
(l
, gen
) ->
2158 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2159 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2161 "Tiling %d[%d,%d] page=%s cs=%s angle"
2162 l
.pageno col row pageopaque
2163 (colorspace_to_string colorspace
)
2165 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2166 angle gen
conf.angle
state.gen
2168 conf.tilew
conf.tileh
2175 (* dolog "%S" cmds; *)
2178 try String.index cmds ' '
2179 with Not_found
-> -1
2184 let l = String.length cmds
in
2185 let op = String.sub cmds
0 spacepos in
2187 if l - spacepos < 2 then ""
2188 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2193 state.uioh#infochanged Pdim
;
2197 state.rects
<- state.rects1
;
2198 G.postRedisplay "clearrects";
2202 try Scanf.sscanf
args "%u" (fun n -> n)
2204 dolog "error processing 'continue' %S: %s"
2205 cmds
(Printexc.to_string exn
);
2208 state.pagecount
<- n;
2209 begin match state.currently
with
2211 state.currently
<- Idle
;
2212 state.outlines
<- Array.of_list
(List.rev
l)
2216 let cur, cmds
= state.geomcmds
in
2217 if String.length
cur = 0
2218 then failwith
"umpossible";
2220 begin match List.rev cmds
with
2222 state.geomcmds
<- "", [];
2226 state.geomcmds
<- s, List.rev rest
;
2228 if conf.maxwait
= None
2229 then G.postRedisplay "continue";
2239 then showtext ' '
args
2242 let progress, text =
2244 Scanf.sscanf
args "%f %n"
2246 f, String.sub
args pos
(String.length
args - pos
))
2248 dolog "error processing 'progress' %S: %s"
2249 cmds
(Printexc.to_string exn
);
2253 state.progress <- progress;
2254 G.postRedisplay "progress"
2257 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2259 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2260 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2261 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2263 dolog "error processing 'firstmatch' %S: %s"
2264 cmds
(Printexc.to_string exn
);
2267 let y = (getpagey pageno) + truncate
y0 in
2270 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2273 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2275 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2276 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2277 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2279 dolog "error processing 'match' %S: %s"
2280 cmds
(Printexc.to_string exn
);
2284 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2289 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2291 dolog "error processing 'page' %S: %s"
2292 cmds
(Printexc.to_string exn
);
2295 begin match state.currently
with
2296 | Loading
(l, gen
) ->
2297 vlog "page %d took %f sec" l.pageno t
;
2298 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2299 begin match state.throttle
with
2301 let preloadedpages =
2303 then preloadlayout state.y
2308 Set.Make
(struct type t
= int let compare = (-) end) in
2310 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2311 IntSet.empty
preloadedpages
2314 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2315 if not
(IntSet.mem
pageno set)
2317 wcmd "freepage %s" opaque
;
2323 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2326 state.currently
<- Idle
;
2329 tilepage l.pageno pageopaque state.layout;
2331 load preloadedpages;
2332 if pagevisible state.layout l.pageno
2333 && layoutready state.layout
2334 then G.postRedisplay "page";
2337 | Some
(layout, _, _) ->
2338 state.currently
<- Idle
;
2339 tilepage l.pageno pageopaque layout;
2344 dolog "Inconsistent loading state";
2345 logcurrently state.currently
;
2350 let (x, y, opaque
, size
, t
) =
2352 Scanf.sscanf
args "%u %u %s %u %f"
2353 (fun x y p size t
-> (x, y, p
, size
, t
))
2355 dolog "error processing 'tile' %S: %s"
2356 cmds
(Printexc.to_string exn
);
2359 begin match state.currently
with
2360 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2361 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2363 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2365 wcmd "freetile %s" opaque
;
2366 state.currently
<- Idle
;
2370 puttileopaque l col row gen cs angle opaque size t
;
2371 state.memused
<- state.memused
+ size
;
2372 state.uioh#infochanged Memused
;
2374 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2375 opaque
, size
) state.tilelru
;
2378 match state.throttle
with
2379 | None
-> state.layout
2380 | Some
(layout, _, _) -> layout
2383 state.currently
<- Idle
;
2385 && conf.colorspace
= cs
2386 && conf.angle
= angle
2387 && tilevisible layout l.pageno x y
2388 then conttiling l.pageno pageopaque;
2390 begin match state.throttle
with
2392 preload state.layout;
2394 && conf.colorspace
= cs
2395 && conf.angle
= angle
2396 && tilevisible state.layout l.pageno x y
2397 then G.postRedisplay "tile nothrottle";
2399 | Some
(layout, y, _) ->
2400 let ready = layoutready layout in
2404 state.layout <- layout;
2405 state.throttle
<- None
;
2406 G.postRedisplay "throttle";
2413 dolog "Inconsistent tiling state";
2414 logcurrently state.currently
;
2421 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2423 dolog "error processing 'pdim' %S: %s"
2424 cmds
(Printexc.to_string exn
);
2427 state.uioh#infochanged Pdim
;
2428 state.pdims
<- pdim :: state.pdims
2431 let (l, n, t
, h, pos
) =
2433 Scanf.sscanf
args "%u %u %d %u %n"
2434 (fun l n t
h pos
-> l, n, t
, h, pos
)
2436 dolog "error processing 'o' %S: %s"
2437 cmds
(Printexc.to_string exn
);
2440 let s = String.sub
args pos
(String.length
args - pos
) in
2441 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2442 begin match state.currently
with
2443 | Outlining outlines
->
2444 state.currently
<- Outlining
(outline :: outlines
)
2446 state.currently
<- Outlining
[outline]
2448 dolog "invalid outlining state";
2449 logcurrently currently
2453 state.docinfo
<- (1, args) :: state.docinfo
2456 state.uioh#infochanged Docinfo
;
2457 state.docinfo
<- List.rev
state.docinfo
2460 dolog "unknown cmd `%S'" cmds
2465 let action = function
2466 | HCprev
-> cbget cb ~
-1
2467 | HCnext
-> cbget cb
1
2468 | HCfirst
-> cbget cb ~
-(cb
.rc)
2469 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2470 and cancel
() = cb
.rc <- rc
2474 let search pattern forward
=
2475 if String.length pattern
> 0
2478 match state.layout with
2481 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2483 wcmd "search %d %d %d %d,%s\000"
2484 (btod conf.icase
) pn py
(btod forward
) pattern
;
2487 let intentry text key =
2489 if key >= 32 && key < 127
2495 let text = addchar text c in
2499 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2503 let linknentry text key =
2505 if key >= 32 && key < 127
2511 let text = addchar text c in
2515 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2520 if String.length
s > 0
2523 let l = String.length
s in
2524 let rec loop pos
n = if pos
= l then n else
2525 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2526 loop (pos
+1) (n*26 + m)
2529 let rec loop n = function
2532 match getopaque l.pageno with
2533 | None
-> loop n rest
2535 let m = getlinkcount opaque
in
2538 let under = getlink opaque
n in
2541 else loop (n-m) rest
2543 loop n state.layout;
2547 let textentry text key =
2548 if key land 0xff00 = 0xff00
2550 else TEcont
(text ^
Wsi.toutf8
key)
2553 let reqlayout angle proportional
=
2554 match state.throttle
with
2556 if nogeomcmds state.geomcmds
2557 then state.anchor <- getanchor ();
2558 conf.angle
<- angle
mod 360;
2561 match state.mode
with
2562 | LinkNav
_ -> state.mode
<- View
2565 conf.proportional
<- proportional
;
2566 invalidate "reqlayout"
2567 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2571 let settrim trimmargins trimfuzz
=
2572 if nogeomcmds state.geomcmds
2573 then state.anchor <- getanchor ();
2574 conf.trimmargins
<- trimmargins
;
2575 conf.trimfuzz
<- trimfuzz
;
2576 let x0, y0, x1, y1 = trimfuzz
in
2577 invalidate "settrim"
2579 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2580 Hashtbl.iter
(fun _ opaque
->
2581 wcmd "freepage %s" opaque
;
2583 Hashtbl.clear
state.pagemap
;
2587 match state.throttle
with
2589 let zoom = max
0.01 zoom in
2590 if zoom <> conf.zoom
2592 state.prevzoom
<- conf.zoom;
2594 reshape conf.winw
conf.winh
;
2595 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2598 | Some
(layout, y, started
) ->
2600 match conf.maxwait
with
2604 let dt = now () -. started
in
2612 let setcolumns mode columns coverA coverB
=
2613 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2617 then showtext '
!'
"split mode doesn't work in bird's eye"
2619 conf.columns
<- Csplit
(-columns
, [||]);
2627 conf.columns
<- Csingle
[||];
2632 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2636 reshape conf.winw
conf.winh
;
2639 let enterbirdseye () =
2640 let zoom = float conf.thumbw
/. float conf.winw
in
2641 let birdseyepageno =
2642 let cy = conf.winh
/ 2 in
2646 let rec fold best
= function
2649 let d = cy - (l.pagedispy + l.pagevh/2)
2650 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2651 if abs
d < abs dbest
2658 state.mode
<- Birdseye
(
2659 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2662 conf.presentation
<- false;
2663 conf.interpagespace
<- 10;
2664 conf.hlinks
<- false;
2666 state.mstate
<- Mnone
;
2667 conf.maxwait
<- None
;
2669 match conf.beyecolumns
with
2672 Cmulti
((c, 0, 0), [||])
2673 | None
-> Csingle
[||]
2675 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2678 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2683 reshape conf.winw
conf.winh
;
2686 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2688 conf.zoom <- c.zoom;
2689 conf.presentation
<- c.presentation
;
2690 conf.interpagespace
<- c.interpagespace
;
2691 conf.maxwait
<- c.maxwait
;
2692 conf.hlinks
<- c.hlinks
;
2693 conf.beyecolumns
<- (
2694 match conf.columns
with
2695 | Cmulti
((c, _, _), _) -> Some
c
2697 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2700 match c.columns
with
2701 | Cmulti
(c, _) -> Cmulti
(c, [||])
2702 | Csingle
_ -> Csingle
[||]
2703 | Csplit
(c, _) -> Csplit
(c, [||])
2708 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2711 reshape conf.winw
conf.winh
;
2712 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2715 let togglebirdseye () =
2716 match state.mode
with
2717 | Birdseye vals
-> leavebirdseye vals
true
2718 | View
-> enterbirdseye ()
2722 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2723 let pageno = max
0 (pageno - incr
) in
2724 let rec loop = function
2725 | [] -> gotopage1 pageno 0
2726 | l :: _ when l.pageno = pageno ->
2727 if l.pagedispy >= 0 && l.pagey = 0
2728 then G.postRedisplay "upbirdseye"
2729 else gotopage1 pageno 0
2730 | _ :: rest
-> loop rest
2733 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2736 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2737 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2738 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2739 let rec loop = function
2741 let y, h = getpageyh pageno in
2742 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2744 | l :: _ when l.pageno = pageno ->
2745 if l.pagevh != l.pageh
2746 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2747 else G.postRedisplay "downbirdseye"
2748 | _ :: rest
-> loop rest
2753 let optentry mode
_ key =
2754 let btos b = if b then "on" else "off" in
2755 if key >= 32 && key < 127
2757 let c = Char.chr
key in
2761 try conf.scrollstep
<- int_of_string
s with exc
->
2762 state.text <- Printf.sprintf
"bad integer `%s': %s"
2763 s (Printexc.to_string exc
)
2765 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2770 conf.autoscrollstep
<- int_of_string
s;
2771 if state.autoscroll
<> None
2772 then state.autoscroll
<- Some
conf.autoscrollstep
2774 state.text <- Printf.sprintf
"bad integer `%s': %s"
2775 s (Printexc.to_string exc
)
2777 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2782 let n, a, b = multicolumns_of_string s in
2783 setcolumns mode
n a b;
2785 state.text <- Printf.sprintf
"bad columns `%s': %s"
2786 s (Printexc.to_string exc
)
2788 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2793 let zoom = float (int_of_string
s) /. 100.0 in
2796 state.text <- Printf.sprintf
"bad integer `%s': %s"
2797 s (Printexc.to_string exc
)
2799 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2804 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2806 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2807 begin match mode
with
2809 leavebirdseye beye
false;
2814 state.text <- Printf.sprintf
"bad integer `%s': %s"
2815 s (Printexc.to_string exc
)
2817 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2822 Some
(int_of_string
s)
2824 state.text <- Printf.sprintf
"bad integer `%s': %s"
2825 s (Printexc.to_string exc
);
2828 | Some angle
-> reqlayout angle
conf.proportional
2831 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2834 conf.icase
<- not
conf.icase
;
2835 TEdone
("case insensitive search " ^
(btos conf.icase
))
2838 conf.preload <- not
conf.preload;
2840 TEdone
("preload " ^
(btos conf.preload))
2843 conf.verbose
<- not
conf.verbose
;
2844 TEdone
("verbose " ^
(btos conf.verbose
))
2847 conf.debug
<- not
conf.debug
;
2848 TEdone
("debug " ^
(btos conf.debug
))
2851 conf.maxhfit
<- not
conf.maxhfit
;
2852 state.maxy
<- calcheight ();
2853 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2856 conf.crophack
<- not
conf.crophack
;
2857 TEdone
("crophack " ^
btos conf.crophack
)
2861 match conf.maxwait
with
2863 conf.maxwait
<- Some infinity
;
2864 "always wait for page to complete"
2866 conf.maxwait
<- None
;
2867 "show placeholder if page is not ready"
2872 conf.underinfo
<- not
conf.underinfo
;
2873 TEdone
("underinfo " ^
btos conf.underinfo
)
2876 conf.savebmarks
<- not
conf.savebmarks
;
2877 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2883 match state.layout with
2888 conf.interpagespace
<- int_of_string
s;
2889 docolumns conf.columns
;
2890 state.maxy
<- calcheight ();
2891 let y = getpagey pageno in
2894 state.text <- Printf.sprintf
"bad integer `%s': %s"
2895 s (Printexc.to_string exc
)
2897 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2900 reqlayout conf.angle
(not
conf.proportional
);
2901 TEdone
("proportional display " ^
btos conf.proportional
)
2904 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2905 TEdone
("trim margins " ^
btos conf.trimmargins
)
2908 conf.invert
<- not
conf.invert
;
2909 TEdone
("invert colors " ^
btos conf.invert
)
2913 cbput state.hists
.sel
s;
2916 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2917 textentry, ondone, true)
2920 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2926 class type lvsource
= object
2927 method getitemcount
: int
2928 method getitem
: int -> (string * int)
2929 method hasaction
: int -> bool
2938 method getactive
: int
2939 method getfirst
: int
2940 method getqsearch
: string
2941 method setqsearch
: string -> unit
2945 class virtual lvsourcebase
= object
2946 val mutable m_active
= 0
2947 val mutable m_first
= 0
2948 val mutable m_qsearch
= ""
2949 val mutable m_pan
= 0
2950 method getactive
= m_active
2951 method getfirst
= m_first
2952 method getqsearch
= m_qsearch
2953 method getpan
= m_pan
2954 method setqsearch
s = m_qsearch
<- s
2957 let withoutlastutf8 s =
2958 let len = String.length
s in
2966 let b = Char.code
s.[pos
] in
2967 if b land 0b110000 = 0b11000000
2972 if Char.code
s.[len-1] land 0x80 = 0
2976 String.sub
s 0 first;
2979 let textentrykeyboard
2980 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2982 state.mode
<- Textentry
(te
, onleave
);
2985 G.postRedisplay "textentrykeyboard enttext";
2987 let histaction cmd
=
2990 | Some
(action, _) ->
2991 state.mode
<- Textentry
(
2992 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2994 G.postRedisplay "textentry histaction"
2997 | 0xff08 -> (* backspace *)
2998 let s = withoutlastutf8 text in
2999 let len = String.length
s in
3000 if cancelonempty
&& len = 0
3003 G.postRedisplay "textentrykeyboard after cancel";
3006 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3012 G.postRedisplay "textentrykeyboard after confirm"
3014 | 0xff52 -> histaction HCprev
3015 | 0xff54 -> histaction HCnext
3016 | 0xff50 -> histaction HCfirst
3017 | 0xff57 -> histaction HClast
3019 | 0xff1b -> (* escape*)
3020 if String.length
text = 0
3022 begin match opthist
with
3024 | Some
(_, onhistcancel
) -> onhistcancel
()
3028 G.postRedisplay "textentrykeyboard after cancel2"
3031 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3034 | 0xff9f | 0xffff -> () (* delete *)
3036 | _ when key != 0 && key land 0xff00 != 0xff00 ->
3037 begin match onkey
text key with
3041 G.postRedisplay "textentrykeyboard after confirm2";
3044 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3048 G.postRedisplay "textentrykeyboard after cancel3"
3051 state.mode
<- Textentry
(te
, onleave
);
3052 G.postRedisplay "textentrykeyboard switch";
3056 vlog "unhandled key %s" (Wsi.keyname
key)
3059 let firstof first active
=
3060 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3061 then max
0 (active
- (fstate.maxrows
/2))
3065 let calcfirst first active
=
3068 let rows = active
- first in
3069 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3073 let scrollph y maxy
=
3074 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3075 let sh = float conf.winh
/. sh in
3076 let sh = max
sh (float conf.scrollh
) in
3081 else float y /. float maxy
3083 let position = (float conf.winh
-. sh) *. percent in
3086 if position +. sh > float conf.winh
3087 then float conf.winh
-. sh
3093 let coe s = (s :> uioh
);;
3095 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3097 val m_pan
= source#getpan
3098 val m_first
= source#getfirst
3099 val m_active
= source#getactive
3100 val m_qsearch
= source#getqsearch
3101 val m_prev_uioh
= state.uioh
3103 method private elemunder
y =
3104 let n = y / (fstate.fontsize
+1) in
3105 if m_first
+ n < source#getitemcount
3107 if source#hasaction
(m_first
+ n)
3108 then Some
(m_first
+ n)
3115 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3116 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3117 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3118 GlDraw.color
(1., 1., 1.);
3119 Gl.enable `texture_2d
;
3120 let fs = fstate.fontsize
in
3122 let ww = fstate.wwidth
in
3123 let tabw = 30.0*.ww in
3124 let itemcount = source#getitemcount
in
3126 if (row - m_first
) * nfs > conf.winh
3129 if row >= 0 && row < itemcount
3131 let (s, level
) = source#getitem
row in
3132 let y = (row - m_first
) * nfs in
3133 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3136 Gl.disable `texture_2d
;
3137 GlDraw.polygon_mode `both `line
;
3138 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3139 GlDraw.rect (1., float (y + 1))
3140 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3141 GlDraw.polygon_mode `both `fill
;
3142 GlDraw.color
(1., 1., 1.);
3143 Gl.enable `texture_2d
;
3146 let drawtabularstring s =
3147 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3150 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3153 let len = String.length
s - tabpos - 1 in
3154 let s1 = String.sub
s 0 tabpos
3155 and s2
= String.sub
s (tabpos + 1) len in
3156 let nx = drawstr x s1 in
3158 let x = x +. (max
tabw sw) in
3165 let _ = drawtabularstring s in
3172 Gl.disable `texture_2d
;
3174 method updownlevel incr
=
3175 let len = source#getitemcount
in
3177 if m_active
>= 0 && m_active
< len
3178 then snd
(source#getitem m_active
)
3182 if i
= len then i
-1 else if i
= -1 then 0 else
3183 let _, l = source#getitem i
in
3184 if l != curlevel then i
else flow (i
+incr
)
3186 let active = flow m_active
in
3187 let first = calcfirst m_first
active in
3188 G.postRedisplay "outline updownlevel";
3189 {< m_active
= active; m_first
= first >}
3191 method private key1
key mask
=
3192 let set1 active first qsearch
=
3193 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3195 let search active pattern incr
=
3198 if n >= 0 && n < source#getitemcount
3200 let s, _ = source#getitem
n in
3202 (try ignore
(Str.search_forward
re s 0); true
3203 with Not_found
-> false)
3205 else loop (n + incr
)
3212 let re = Str.regexp_case_fold pattern
in
3218 let itemcount = source#getitemcount
in
3219 let find start incr
=
3221 if i
= -1 || i
= itemcount
3224 if source#hasaction i
3226 else find (i
+ incr
)
3231 let set active first =
3232 let first = bound first 0 (itemcount - fstate.maxrows
) in
3234 coe {< m_active
= active; m_first
= first >}
3237 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3239 let incr1 = if incr
> 0 then 1 else -1 in
3240 if isvisible m_first m_active
3243 let next = m_active
+ incr
in
3245 if next < 0 || next >= itemcount
3247 else find next incr1
3249 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3255 let first = m_first
+ incr
in
3256 let first = bound first 0 (itemcount - 1) in
3258 let next = m_active
+ incr
in
3259 let next = bound next 0 (itemcount - 1) in
3262 let active = if next = -1 then m_active
else next in
3265 let first = min
next m_first
in
3267 if abs
(next - first) > fstate.maxrows
3273 let first = m_first
+ incr
in
3274 let first = bound first 0 (itemcount - 1) in
3276 let next = m_active
+ incr
in
3277 let next = bound next 0 (itemcount - 1) in
3278 let next = find next incr1 in
3280 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3282 let active = if m_active
= -1 then next else m_active
in
3287 if isvisible first active
3293 G.postRedisplay "listview navigate";
3297 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3298 let incr = if key = 0x72 then -1 else 1 in
3300 match search (m_active
+ incr) m_qsearch
incr with
3302 state.text <- m_qsearch ^
" [not found]";
3305 state.text <- m_qsearch
;
3306 active, firstof m_first
active
3308 G.postRedisplay "listview ctrl-r/s";
3309 set1 active first m_qsearch
;
3311 | 0xff08 -> (* backspace *)
3312 if String.length m_qsearch
= 0
3315 let qsearch = withoutlastutf8 m_qsearch
in
3316 let len = String.length
qsearch in
3320 G.postRedisplay "listview empty qsearch";
3321 set1 m_active m_first
"";
3325 match search m_active
qsearch ~
-1 with
3327 state.text <- qsearch ^
" [not found]";
3330 state.text <- qsearch;
3331 active, firstof m_first
active
3333 G.postRedisplay "listview backspace qsearch";
3334 set1 active first qsearch
3337 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3338 let pattern = m_qsearch ^
Wsi.toutf8
key in
3340 match search m_active
pattern 1 with
3342 state.text <- pattern ^
" [not found]";
3345 state.text <- pattern;
3346 active, firstof m_first
active
3348 G.postRedisplay "listview qsearch add";
3349 set1 active first pattern;
3351 | 0xff1b -> (* escape *)
3353 if String.length m_qsearch
= 0
3355 G.postRedisplay "list view escape";
3358 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3360 | None
-> m_prev_uioh
3365 G.postRedisplay "list view kill qsearch";
3366 source#setqsearch
"";
3367 coe {< m_qsearch
= "" >}
3370 | 0xff0d -> (* return *)
3372 let self = {< m_qsearch
= "" >} in
3373 source#setqsearch
"";
3375 G.postRedisplay "listview enter";
3376 if m_active
>= 0 && m_active
< source#getitemcount
3378 source#exit
(coe self) false m_active m_first m_pan
"";
3381 source#exit
(coe self) true m_active m_first m_pan
"";
3384 begin match opt with
3385 | None
-> m_prev_uioh
3389 | 0xff9f | 0xffff -> (* delete *)
3392 | 0xff52 -> navigate ~
-1 (* up *)
3393 | 0xff54 -> navigate 1 (* down *)
3394 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3395 | 0xff56 -> navigate fstate.maxrows
(* next *)
3397 | 0xff53 -> (* right *)
3399 G.postRedisplay "listview right";
3400 coe {< m_pan
= m_pan
- 1 >}
3402 | 0xff51 -> (* left *)
3404 G.postRedisplay "listview left";
3405 coe {< m_pan
= m_pan
+ 1 >}
3407 | 0xff50 -> (* home *)
3408 let active = find 0 1 in
3409 G.postRedisplay "listview home";
3412 | 0xff57 -> (* end *)
3413 let first = max
0 (itemcount - fstate.maxrows
) in
3414 let active = find (itemcount - 1) ~
-1 in
3415 G.postRedisplay "listview end";
3418 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3422 dolog "listview unknown key %#x" key; coe self
3424 method key key mask
=
3425 match state.mode
with
3426 | Textentry te
-> textentrykeyboard key mask te
; coe self
3427 | _ -> self#key1
key mask
3429 method button button down
x y _ =
3432 | 1 when x > conf.winw
- conf.scrollbw
->
3433 G.postRedisplay "listview scroll";
3436 let _, position, sh = self#
scrollph in
3437 if y > truncate
position && y < truncate
(position +. sh)
3439 state.mstate
<- Mscrolly
;
3443 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3444 let first = truncate
(s *. float source#getitemcount
) in
3445 let first = min source#getitemcount
first in
3446 Some
(coe {< m_first
= first; m_active
= first >})
3448 state.mstate
<- Mnone
;
3451 | 1 when not down
->
3452 begin match self#elemunder
y with
3454 G.postRedisplay "listview click";
3456 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3460 | n when (n == 4 || n == 5) && not down
->
3461 let len = source#getitemcount
in
3463 if n = 5 && m_first
+ fstate.maxrows
>= len
3467 let first = m_first
+ (if n == 4 then -1 else 1) in
3468 bound first 0 (len - 1)
3470 G.postRedisplay "listview wheel";
3471 Some
(coe {< m_first
= first >})
3472 | n when (n = 6 || n = 7) && not down
->
3473 let inc = m_first
+ (if n = 7 then -1 else 1) in
3474 G.postRedisplay "listview hwheel";
3475 Some
(coe {< m_pan
= m_pan
+ inc >})
3480 | None
-> m_prev_uioh
3484 match state.mstate
with
3486 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3487 let first = truncate
(s *. float source#getitemcount
) in
3488 let first = min source#getitemcount
first in
3489 G.postRedisplay "listview motion";
3490 coe {< m_first
= first; m_active
= first >}
3493 method pmotion
x y =
3494 if x < conf.winw
- conf.scrollbw
3497 match self#elemunder
y with
3498 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3499 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3503 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3508 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3512 method infochanged
_ = ()
3514 method scrollpw
= (0, 0.0, 0.0)
3516 let nfs = fstate.fontsize
+ 1 in
3517 let y = m_first
* nfs in
3518 let itemcount = source#getitemcount
in
3519 let maxi = max
0 (itemcount - fstate.maxrows
) in
3520 let maxy = maxi * nfs in
3521 let p, h = scrollph y maxy in
3524 method modehash
= modehash
3527 class outlinelistview ~source
=
3530 ~source
:(source
:> lvsource
)
3532 ~modehash
:(findkeyhash conf "outline")
3535 method key key mask
=
3536 let calcfirst first active =
3539 let rows = active - first in
3541 if String.length
state.text = 0
3543 else fstate.maxrows - 2
3545 if rows > maxrows then active - maxrows else first
3549 let active = m_active
+ incr in
3550 let active = bound active 0 (source#getitemcount
- 1) in
3551 let first = calcfirst m_first
active in
3552 G.postRedisplay "outline navigate";
3553 coe {< m_active
= active; m_first
= first >}
3555 let ctrl = Wsi.withctrl mask
in
3557 | 110 when ctrl -> (* ctrl-n *)
3558 source#narrow m_qsearch
;
3559 G.postRedisplay "outline ctrl-n";
3560 coe {< m_first
= 0; m_active
= 0 >}
3562 | 117 when ctrl -> (* ctrl-u *)
3564 G.postRedisplay "outline ctrl-u";
3566 coe {< m_first
= 0; m_active
= 0 >}
3568 | 108 when ctrl -> (* ctrl-l *)
3569 let first = m_active
- (fstate.maxrows / 2) in
3570 G.postRedisplay "outline ctrl-l";
3571 coe {< m_first
= first >}
3573 | 0xff9f | 0xffff -> (* delete *)
3574 source#remove m_active
;
3575 G.postRedisplay "outline delete";
3576 let active = max
0 (m_active
-1) in
3577 coe {< m_first
= firstof m_first
active;
3578 m_active
= active >}
3580 | 0xff52 -> navigate ~
-1 (* up *)
3581 | 0xff54 -> navigate 1 (* down *)
3582 | 0xff55 -> (* prior *)
3583 navigate ~
-(fstate.maxrows)
3584 | 0xff56 -> (* next *)
3585 navigate fstate.maxrows
3587 | 0xff53 -> (* [ctrl-]right *)
3591 G.postRedisplay "outline ctrl right";
3592 {< m_pan
= m_pan
+ 1 >}
3594 else self#updownlevel
1
3598 | 0xff51 -> (* [ctrl-]left *)
3602 G.postRedisplay "outline ctrl left";
3603 {< m_pan
= m_pan
- 1 >}
3605 else self#updownlevel ~
-1
3609 | 0xff50 -> (* home *)
3610 G.postRedisplay "outline home";
3611 coe {< m_first
= 0; m_active
= 0 >}
3613 | 0xff57 -> (* end *)
3614 let active = source#getitemcount
- 1 in
3615 let first = max
0 (active - fstate.maxrows) in
3616 G.postRedisplay "outline end";
3617 coe {< m_active
= active; m_first
= first >}
3619 | _ -> super#
key key mask
3622 let outlinesource usebookmarks
=
3625 inherit lvsourcebase
3626 val mutable m_items
= empty
3627 val mutable m_orig_items
= empty
3628 val mutable m_prev_items
= empty
3629 val mutable m_narrow_pattern
= ""
3630 val mutable m_hadremovals
= false
3632 method getitemcount
=
3633 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3636 if n == Array.length m_items
&& m_hadremovals
3638 ("[Confirm removal]", 0)
3640 let s, n, _ = m_items
.(n) in
3643 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3644 ignore
(uioh
, first, qsearch);
3645 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3647 if String.length m_narrow_pattern
= 0
3653 if not
confrimremoval
3655 let _, _, anchor = m_items
.(active) in
3660 state.bookmarks
<- Array.to_list m_items
;
3661 m_orig_items
<- m_items
;
3664 else m_items
<- items;
3668 method hasaction
_ = true
3671 if Array.length m_items
!= Array.length m_orig_items
3672 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3675 method narrow
pattern =
3676 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3680 let rec loop accu n =
3683 m_narrow_pattern
<- pattern;
3684 m_items
<- Array.of_list
accu
3687 let (s, _, _) as o = m_items
.(n) in
3689 if (try ignore
(Str.search_forward
re s 0); true
3690 with Not_found
-> false)
3696 loop [] (Array.length m_items
- 1)
3701 then Array.of_list
state.bookmarks
3704 m_items
<- m_orig_items
3709 if m >= 0 && m < Array.length m_items
3711 m_hadremovals
<- true;
3712 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3713 let n = if n >= m then n+1 else n in
3718 method reset
anchor items =
3719 m_hadremovals
<- false;
3720 if m_orig_items
== empty || m_prev_items
!= items
3722 m_orig_items
<- items;
3723 if String.length m_narrow_pattern
= 0
3724 then m_items
<- items;
3726 m_prev_items
<- items;
3727 let rely = getanchory anchor in
3729 let rec loop n best bestd
=
3730 if n = Array.length m_items
3733 let (_, _, anchor) = m_items
.(n) in
3734 let orely = getanchory anchor in
3735 let d = abs
(orely - rely) in
3738 else loop (n+1) best bestd
3743 m_first
<- firstof m_first
active
3747 let enterselector usebookmarks
=
3748 let source = outlinesource usebookmarks
in
3752 then Array.of_list
state.bookmarks
3755 if Array.length
outlines = 0
3757 showtext ' ' errmsg
;
3760 state.text <- source#greetmsg
;
3761 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3762 let anchor = getanchor () in
3763 source#reset
anchor outlines;
3764 state.uioh
<- coe (new outlinelistview ~
source);
3765 G.postRedisplay "enter selector";
3769 let enteroutlinemode =
3770 let f = enterselector false in
3771 fun ()-> f "Document has no outline";
3774 let enterbookmarkmode =
3775 let f = enterselector true in
3776 fun () -> f "Document has no bookmarks (yet)";
3779 let color_of_string s =
3780 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3781 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3785 let color_to_string (r, g
, b) =
3786 let r = truncate
(r *. 256.0)
3787 and g
= truncate
(g
*. 256.0)
3788 and b = truncate
(b *. 256.0) in
3789 Printf.sprintf
"%d/%d/%d" r g
b
3792 let irect_of_string s =
3793 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3796 let irect_to_string (x0,y0,x1,y1) =
3797 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3800 let makecheckers () =
3801 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3803 converted by Issac Trotts. July 25, 2002 *)
3804 let image_height = 64
3805 and image_width
= 64 in
3809 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3811 for i
= 0 to image_width
- 1 do
3812 for j
= 0 to image_height - 1 do
3813 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3814 (if (i
land 8 ) lxor (j
land 8) = 0
3815 then [|255;255;255|] else [|200;200;200|])
3820 let image = make_image () in
3821 let id = GlTex.gen_texture
() in
3822 GlTex.bind_texture `texture_2d
id;
3823 GlPix.store
(`unpack_alignment
1);
3824 GlTex.image2d
image;
3825 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3828 `mag_filter `nearest
;
3829 `min_filter `nearest
];
3833 let setcheckers enabled
=
3834 match state.texid
with
3836 if enabled
then state.texid
<- Some
(makecheckers ())
3841 GlTex.delete_texture texid
;
3842 state.texid
<- None
;
3846 let int_of_string_with_suffix s =
3847 let l = String.length
s in
3851 let suffix = Char.lowercase
s.[l-1] in
3853 | 'k'
-> String.sub
s 0 (l-1), 10
3854 | '
m'
-> String.sub
s 0 (l-1), 20
3855 | 'g'
-> String.sub
s 0 (l-1), 30
3859 let n = int_of_string
s1 in
3860 let m = n lsl shift
in
3862 then raise
(Failure
"value too large")
3866 let string_with_suffix_of_int n =
3871 if n land ((1 lsl 20) - 1) = 0
3874 if n land ((1 lsl 10) - 1) = 0
3880 let h = n mod 1000 in
3883 then string_of_int
h ^
s
3885 let s = Printf.sprintf
"_%03d%s" h s in
3892 let defghyllscroll = (40, 8, 32);;
3893 let ghyllscroll_of_string s =
3894 let (n, a, b) as nab
=
3897 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3899 if n <= a || n <= b || a >= b
3900 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3904 let ghyllscroll_to_string ((n, a, b) as nab
) =
3905 if nab
= defghyllscroll
3907 else Printf.sprintf
"%d,%d,%d" n a b;
3910 let describe_location () =
3912 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3914 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3915 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3919 else (100. *. (float state.y /. float maxy))
3923 Printf.sprintf
"page %d of %d [%.2f%%]"
3924 (fn+1) state.pagecount
percent
3927 "pages %d-%d of %d [%.2f%%]"
3928 (fn+1) (ln
+1) state.pagecount
percent
3931 let setpresentationmode v
=
3932 let (n, _, _) = getanchor () in
3933 let _, h = getpageyh n in
3934 state.anchor <- (n, 0.0, float (calcips h));
3935 conf.presentation
<- v
;
3936 if conf.presentation
3938 if not
conf.scrollbarinpm
3939 then state.scrollw
<- 0;
3941 else state.scrollw
<- conf.scrollbw
;
3946 let btos b = if b then "\xe2\x88\x9a" else "" in
3947 let showextended = ref false in
3948 let leave mode
= function
3949 | Confirm
-> state.mode
<- mode
3950 | Cancel
-> state.mode
<- mode
in
3953 val mutable m_first_time
= true
3954 val mutable m_l
= []
3955 val mutable m_a
= [||]
3956 val mutable m_prev_uioh
= nouioh
3957 val mutable m_prev_mode
= View
3959 inherit lvsourcebase
3961 method reset prev_mode prev_uioh
=
3962 m_a
<- Array.of_list
(List.rev m_l
);
3964 m_prev_mode
<- prev_mode
;
3965 m_prev_uioh
<- prev_uioh
;
3969 if n >= Array.length m_a
3973 | _, _, _, Action
_ -> m_active
<- n
3977 m_first_time
<- false;
3980 method int name get
set =
3982 (name
, `
int get
, 1, Action
(
3985 try set (int_of_string
s)
3987 state.text <- Printf.sprintf
"bad integer `%s': %s"
3988 s (Printexc.to_string exn
)
3991 let te = name ^
": ", "", None
, intentry, ondone, true in
3992 state.mode
<- Textentry
(te, leave m_prev_mode
);
3996 method int_with_suffix name get
set =
3998 (name
, `intws get
, 1, Action
(
4001 try set (int_of_string_with_suffix s)
4003 state.text <- Printf.sprintf
"bad integer `%s': %s"
4004 s (Printexc.to_string exn
)
4008 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4010 state.mode
<- Textentry
(te, leave m_prev_mode
);
4014 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4016 (name
, `
bool (btos, get
), offset
, Action
(
4023 method color name get
set =
4025 (name
, `color get
, 1, Action
(
4027 let invalid = (nan
, nan
, nan
) in
4030 try color_of_string s
4032 state.text <- Printf.sprintf
"bad color `%s': %s"
4033 s (Printexc.to_string exn
);
4039 let te = name ^
": ", "", None
, textentry, ondone, true in
4040 state.text <- color_to_string (get
());
4041 state.mode
<- Textentry
(te, leave m_prev_mode
);
4045 method string name get
set =
4047 (name
, `
string get
, 1, Action
(
4049 let ondone s = set s in
4050 let te = name ^
": ", "", None
, textentry, ondone, true in
4051 state.mode
<- Textentry
(te, leave m_prev_mode
);
4055 method colorspace name get
set =
4057 (name
, `
string get
, 1, Action
(
4060 let vals = [| "rgb"; "bgr"; "gray" |] in
4062 inherit lvsourcebase
4065 m_active
<- int_of_colorspace conf.colorspace
;
4068 method getitemcount
= Array.length
vals
4069 method getitem
n = (vals.(n), 0)
4070 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4071 ignore
(uioh
, first, pan
, qsearch);
4072 if not cancel
then set active;
4074 method hasaction
_ = true
4078 let modehash = findkeyhash conf "info" in
4079 coe (new listview ~
source ~trusted
:true ~
modehash)
4082 method caption
s offset
=
4083 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4085 method caption2
s f offset
=
4086 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4088 method getitemcount
= Array.length m_a
4091 let tostr = function
4092 | `
int f -> string_of_int
(f ())
4093 | `intws
f -> string_with_suffix_of_int (f ())
4095 | `color
f -> color_to_string (f ())
4096 | `
bool (btos, f) -> btos (f ())
4099 let name, t
, offset
, _ = m_a
.(n) in
4100 ((let s = tostr t
in
4101 if String.length
s > 0
4102 then Printf.sprintf
"%s\t%s" name s
4106 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4110 m_qsearch
<- qsearch;
4112 match m_a
.(active) with
4113 | _, _, _, Action
f -> f uioh
4125 method hasaction
n =
4127 | _, _, _, Action
_ -> true
4131 let rec fillsrc prevmode prevuioh
=
4132 let sep () = src#caption
"" 0 in
4133 let colorp name get
set =
4135 (fun () -> color_to_string (get
()))
4138 let c = color_of_string v in
4141 state.text <- Printf.sprintf
"bad color `%s': %s"
4142 v (Printexc.to_string exn
);
4145 let oldmode = state.mode
in
4146 let birdseye = isbirdseye state.mode
in
4148 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4150 src#
bool "presentation mode"
4151 (fun () -> conf.presentation
)
4152 (fun v -> setpresentationmode v);
4154 src#
bool "ignore case in searches"
4155 (fun () -> conf.icase
)
4156 (fun v -> conf.icase
<- v);
4159 (fun () -> conf.preload)
4160 (fun v -> conf.preload <- v);
4162 src#
bool "highlight links"
4163 (fun () -> conf.hlinks
)
4164 (fun v -> conf.hlinks
<- v);
4166 src#
bool "under info"
4167 (fun () -> conf.underinfo
)
4168 (fun v -> conf.underinfo
<- v);
4170 src#
bool "persistent bookmarks"
4171 (fun () -> conf.savebmarks
)
4172 (fun v -> conf.savebmarks
<- v);
4174 src#
bool "proportional display"
4175 (fun () -> conf.proportional
)
4176 (fun v -> reqlayout conf.angle
v);
4178 src#
bool "trim margins"
4179 (fun () -> conf.trimmargins
)
4180 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4182 src#
bool "persistent location"
4183 (fun () -> conf.jumpback
)
4184 (fun v -> conf.jumpback
<- v);
4187 src#
int "inter-page space"
4188 (fun () -> conf.interpagespace
)
4190 conf.interpagespace
<- n;
4191 docolumns conf.columns
;
4193 match state.layout with
4198 state.maxy <- calcheight ();
4199 let y = getpagey pageno in
4204 (fun () -> conf.pagebias
)
4205 (fun v -> conf.pagebias
<- v);
4207 src#
int "scroll step"
4208 (fun () -> conf.scrollstep
)
4209 (fun n -> conf.scrollstep
<- n);
4211 src#
int "horizontal scroll step"
4212 (fun () -> conf.hscrollstep
)
4213 (fun v -> conf.hscrollstep
<- v);
4215 src#
int "auto scroll step"
4217 match state.autoscroll
with
4219 | _ -> conf.autoscrollstep
)
4221 if state.autoscroll
<> None
4222 then state.autoscroll
<- Some
n;
4223 conf.autoscrollstep
<- n);
4226 (fun () -> truncate
(conf.zoom *. 100.))
4227 (fun v -> setzoom ((float v) /. 100.));
4230 (fun () -> conf.angle
)
4231 (fun v -> reqlayout v conf.proportional
);
4233 src#
int "scroll bar width"
4234 (fun () -> state.scrollw
)
4238 reshape conf.winw
conf.winh
;
4241 src#
int "scroll handle height"
4242 (fun () -> conf.scrollh
)
4243 (fun v -> conf.scrollh
<- v;);
4245 src#
int "thumbnail width"
4246 (fun () -> conf.thumbw
)
4248 conf.thumbw
<- min
4096 v;
4251 leavebirdseye beye
false;
4256 let mode = state.mode in
4257 src#
string "columns"
4259 match conf.columns
with
4261 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4262 | Csplit
(count
, _) -> "-" ^ string_of_int count
4265 let n, a, b = multicolumns_of_string v in
4266 setcolumns mode n a b);
4269 src#caption
"Presentation mode" 0;
4270 src#
bool "scrollbar visible"
4271 (fun () -> conf.scrollbarinpm
)
4273 if v != conf.scrollbarinpm
4275 conf.scrollbarinpm
<- v;
4276 if conf.presentation
4278 state.scrollw
<- if v then conf.scrollbw
else 0;
4279 reshape conf.winw
conf.winh
;
4285 src#caption
"Pixmap cache" 0;
4286 src#int_with_suffix
"size (advisory)"
4287 (fun () -> conf.memlimit
)
4288 (fun v -> conf.memlimit
<- v);
4291 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4292 (string_with_suffix_of_int state.memused
)
4293 (Hashtbl.length
state.tilemap
)) 1;
4296 src#caption
"Layout" 0;
4297 src#caption2
"Dimension"
4299 Printf.sprintf
"%dx%d (virtual %dx%d)"
4305 src#caption2
"Position" (fun () ->
4306 Printf.sprintf
"%dx%d" state.x state.y
4309 src#caption2
"Visible" (fun () -> describe_location ()) 1
4313 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4314 "Save these parameters as global defaults at exit"
4315 (fun () -> conf.bedefault
)
4316 (fun v -> conf.bedefault
<- v)
4320 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4321 src#
bool ~offset
:0 ~
btos "Extended parameters"
4322 (fun () -> !showextended)
4323 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4327 (fun () -> conf.checkers
)
4328 (fun v -> conf.checkers
<- v; setcheckers v);
4329 src#
bool "update cursor"
4330 (fun () -> conf.updatecurs
)
4331 (fun v -> conf.updatecurs
<- v);
4333 (fun () -> conf.verbose
)
4334 (fun v -> conf.verbose
<- v);
4335 src#
bool "invert colors"
4336 (fun () -> conf.invert
)
4337 (fun v -> conf.invert
<- v);
4339 (fun () -> conf.maxhfit
)
4340 (fun v -> conf.maxhfit
<- v);
4341 src#
bool "redirect stderr"
4342 (fun () -> conf.redirectstderr)
4343 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4344 src#
string "uri launcher"
4345 (fun () -> conf.urilauncher
)
4346 (fun v -> conf.urilauncher
<- v);
4347 src#
string "path launcher"
4348 (fun () -> conf.pathlauncher
)
4349 (fun v -> conf.pathlauncher
<- v);
4350 src#
string "tile size"
4351 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4354 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4355 conf.tilew
<- max
64 w;
4356 conf.tileh
<- max
64 h;
4359 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4360 v (Printexc.to_string exn
));
4361 src#
int "texture count"
4362 (fun () -> conf.texcount
)
4365 then conf.texcount
<- v
4366 else showtext '
!'
" Failed to set texture count please retry later"
4368 src#
int "slice height"
4369 (fun () -> conf.sliceheight
)
4371 conf.sliceheight
<- v;
4372 wcmd "sliceh %d" conf.sliceheight
;
4374 src#
int "anti-aliasing level"
4375 (fun () -> conf.aalevel
)
4377 conf.aalevel
<- bound v 0 8;
4378 state.anchor <- getanchor ();
4379 opendoc state.path
state.password
;
4381 src#
string "page scroll scaling factor"
4382 (fun () -> string_of_float
conf.pgscale)
4385 let s = float_of_string
v in
4388 state.text <- Printf.sprintf
4389 "bad page scroll scaling factor `%s': %s"
4390 v (Printexc.to_string exn
)
4393 src#
int "ui font size"
4394 (fun () -> fstate.fontsize
)
4395 (fun v -> setfontsize (bound v 5 100));
4396 src#
int "hint font size"
4397 (fun () -> conf.hfsize
)
4398 (fun v -> conf.hfsize
<- bound v 5 100);
4399 colorp "background color"
4400 (fun () -> conf.bgcolor
)
4401 (fun v -> conf.bgcolor
<- v);
4402 src#
bool "crop hack"
4403 (fun () -> conf.crophack
)
4404 (fun v -> conf.crophack
<- v);
4405 src#
bool "multi column centering"
4406 (fun () -> conf.multicenter
)
4407 (fun v -> conf.multicenter
<- v; represent ());
4408 src#
string "trim fuzz"
4409 (fun () -> irect_to_string conf.trimfuzz
)
4412 conf.trimfuzz
<- irect_of_string v;
4414 then settrim true conf.trimfuzz
;
4416 state.text <- Printf.sprintf
"bad irect `%s': %s"
4417 v (Printexc.to_string exn
)
4419 src#
string "throttle"
4421 match conf.maxwait
with
4422 | None
-> "show place holder if page is not ready"
4425 then "wait for page to fully render"
4427 "wait " ^ string_of_float
time
4428 ^
" seconds before showing placeholder"
4432 let f = float_of_string
v in
4434 then conf.maxwait
<- None
4435 else conf.maxwait
<- Some
f
4437 state.text <- Printf.sprintf
"bad time `%s': %s"
4438 v (Printexc.to_string exn
)
4440 src#
string "ghyll scroll"
4442 match conf.ghyllscroll
with
4444 | Some nab
-> ghyllscroll_to_string nab
4449 if String.length
v = 0
4451 else Some
(ghyllscroll_of_string v)
4453 conf.ghyllscroll
<- gs
4455 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4456 v (Printexc.to_string exn
)
4458 src#
string "selection command"
4459 (fun () -> conf.selcmd
)
4460 (fun v -> conf.selcmd
<- v);
4461 src#colorspace
"color space"
4462 (fun () -> colorspace_to_string conf.colorspace
)
4464 conf.colorspace
<- colorspace_of_int v;
4471 src#caption
"Document" 0;
4472 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4473 src#caption2
"Pages"
4474 (fun () -> string_of_int
state.pagecount
) 1;
4475 src#caption2
"Dimensions"
4476 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4480 src#caption
"Trimmed margins" 0;
4481 src#caption2
"Dimensions"
4482 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4486 src#caption
"OpenGL" 0;
4487 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4488 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4489 src#reset prevmode prevuioh
;
4493 let prevmode = state.mode
4494 and prevuioh
= state.uioh in
4495 fillsrc prevmode prevuioh
;
4496 let source = (src :> lvsource
) in
4497 let modehash = findkeyhash conf "info" in
4498 state.uioh <- coe (object (self)
4499 inherit listview ~
source ~trusted
:true ~
modehash as super
4500 val mutable m_prevmemused
= 0
4501 method infochanged
= function
4503 if m_prevmemused
!= state.memused
4505 m_prevmemused
<- state.memused
;
4506 G.postRedisplay "memusedchanged";
4508 | Pdim
-> G.postRedisplay "pdimchanged"
4509 | Docinfo
-> fillsrc prevmode prevuioh
4511 method key key mask
=
4512 if not
(Wsi.withctrl mask
)
4515 | 0xff51 -> coe (self#updownlevel ~
-1)
4516 | 0xff53 -> coe (self#updownlevel
1)
4517 | _ -> super#
key key mask
4518 else super#
key key mask
4520 G.postRedisplay "info";
4526 inherit lvsourcebase
4527 method getitemcount
= Array.length
state.help
4529 let s, n, _ = state.help
.(n) in
4532 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4536 m_qsearch
<- qsearch;
4537 match state.help
.(active) with
4538 | _, _, Action
f -> Some
(f uioh)
4548 method hasaction
n =
4549 match state.help
.(n) with
4550 | _, _, Action
_ -> true
4557 let modehash = findkeyhash conf "help" in
4558 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4559 G.postRedisplay "help";
4564 let re = Str.regexp
"[\r\n]" in
4566 inherit lvsourcebase
4567 val mutable m_items
= [||]
4569 method getitemcount
= 1 + Array.length m_items
4574 else m_items
.(n-1), 0
4576 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4581 then Buffer.clear
state.errmsgs
;
4582 m_qsearch
<- qsearch;
4589 method hasaction
n =
4593 state.newerrmsgs
<- false;
4594 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4595 m_items
<- Array.of_list
l
4603 let source = (msgsource :> lvsource
) in
4604 let modehash = findkeyhash conf "listview" in
4605 state.uioh <- coe (object
4606 inherit listview ~
source ~trusted
:false ~
modehash as super
4609 then msgsource#reset
;
4612 G.postRedisplay "msgs";
4615 let quickbookmark ?title
() =
4616 match state.layout with
4622 let sec = Unix.gettimeofday
() in
4623 let tm = Unix.localtime
sec in
4624 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4628 (tm.Unix.tm_year
+ 1900)
4631 | Some
title -> title
4633 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4637 state.fullscreen
<- None
;
4641 let setautoscrollspeed step goingdown
=
4642 let incr = max
1 ((abs step
) / 2) in
4643 let incr = if goingdown
then incr else -incr in
4644 let astep = step
+ incr in
4645 state.autoscroll
<- Some
astep;
4648 let gotounder = function
4649 | Ulinkgoto
(pageno, top) ->
4653 gotopage1 pageno top;
4659 | Uremote
(filename
, pageno) ->
4661 if Sys.file_exists filename
4664 let dir = Filename.dirname
state.path in
4665 let path = Filename.concat
dir filename
in
4666 if Sys.file_exists
path
4670 if String.length
path > 0
4672 let anchor = getanchor () in
4673 let ranchor = state.path, state.password
, anchor in
4674 state.anchor <- (pageno, 0.0, 0.0);
4675 state.ranchors
<- ranchor :: state.ranchors
;
4678 else showtext '
!'
("Could not find " ^ filename
)
4680 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4684 match conf.columns
with
4686 | _ -> conf.zoom > 1.0
4689 let viewkeyboard key mask
=
4691 let mode = state.mode in
4692 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4695 G.postRedisplay "view:enttext"
4697 let ctrl = Wsi.withctrl mask
in
4702 | 0xff63 -> (* insert *)
4703 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4705 state.mode <- LinkNav
(Ltgendir
0);
4708 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4710 | 0xff1b | 113 -> (* escape / q *)
4711 begin match state.mstate
with
4713 state.mstate
<- Mnone
;
4714 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4715 G.postRedisplay "kill zoom rect";
4717 match state.ranchors
with
4719 | (path, password
, anchor) :: rest
->
4720 state.ranchors
<- rest
;
4721 state.anchor <- anchor;
4722 opendoc path password
4725 | 0xff08 -> (* backspace *)
4726 let y = getnav ~
-1 in
4727 gotoy_and_clear_text y
4735 G.postRedisplay "dehighlight";
4737 | 47 | 63 -> (* / ? *)
4738 let ondone isforw
s =
4739 cbput state.hists
.pat
s;
4740 state.searchpattern
<- s;
4743 let s = String.create
1 in
4744 s.[0] <- Char.chr
key;
4745 enttext (s, "", Some
(onhist state.hists
.pat
),
4746 textentry, ondone (key = 47), true)
4748 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4749 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4750 setzoom (conf.zoom +. incr)
4752 | 43 | 0xffab -> (* + *)
4755 try int_of_string
s with exc
->
4756 state.text <- Printf.sprintf
"bad integer `%s': %s"
4757 s (Printexc.to_string exc
);
4763 state.text <- "page bias is now " ^ string_of_int
n;
4766 enttext ("page bias: ", "", None
, intentry, ondone, true)
4768 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4769 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4770 setzoom (max
0.01 (conf.zoom -. decr))
4772 | 45 | 0xffad -> (* - *)
4773 let ondone msg
= state.text <- msg
in
4775 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4776 optentry state.mode, ondone, true
4779 | 48 when ctrl -> (* ctrl-0 *)
4782 | 49 when ctrl -> (* ctrl-1 *)
4784 match conf.columns
with
4785 | Csingle
_ | Cmulti
_ -> 1
4786 | Csplit
(n, _) -> n
4788 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4792 | 0xffc6 -> (* f9 *)
4795 | 57 when ctrl -> (* ctrl-9 *)
4798 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4799 when not
ctrl -> (* 0..9 *)
4802 try int_of_string
s with exc
->
4803 state.text <- Printf.sprintf
"bad integer `%s': %s"
4804 s (Printexc.to_string exc
);
4810 cbput state.hists
.pag
(string_of_int
n);
4811 gotopage1 (n + conf.pagebias
- 1) 0;
4814 let pageentry text key =
4815 match Char.unsafe_chr
key with
4816 | 'g'
-> TEdone
text
4817 | _ -> intentry text key
4819 let text = "x" in text.[0] <- Char.chr
key;
4820 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4823 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4824 reshape conf.winw
conf.winh
;
4827 conf.hlinks
<- not
conf.hlinks
;
4828 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4829 G.postRedisplay "toggle highlightlinks";
4832 state.glinks
<- true;
4833 let mode = state.mode in
4834 state.mode <- Textentry
(
4835 (":", "", None
, linknentry, linkndone (fun under ->
4840 state.glinks
<- false;
4844 G.postRedisplay "view:linkent(F)"
4847 state.glinks
<- true;
4848 let mode = state.mode in
4849 state.mode <- Textentry
(
4850 (":", "", None
, linknentry, linkndone (fun under ->
4851 match Ne.pipe () with
4853 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4854 (Printexc.to_string exn
));
4857 try popen conf.selcmd
[r, 0; w, -1]; true
4860 (Printf.sprintf
"failed to execute %s: %s"
4861 conf.selcmd
(Printexc.to_string exn
));
4865 Ne.clo fd
(fun msg
->
4866 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4869 let s = undertext under in
4873 let l = String.length
s in
4874 let n = Unix.write
w s 0 l in
4879 "failed to write %d characters to sel pipe, wrote %d"
4884 (Printf.sprintf
"failed to write to sel pipe: %s"
4885 (Printexc.to_string exn
)
4894 state.glinks
<- false;
4898 G.postRedisplay "view:linkent"
4901 begin match state.autoscroll
with
4903 conf.autoscrollstep
<- step
;
4904 state.autoscroll
<- None
4906 if conf.autoscrollstep
= 0
4907 then state.autoscroll
<- Some
1
4908 else state.autoscroll
<- Some
conf.autoscrollstep
4911 | 112 when ctrl -> (* ctrl-p *)
4915 setpresentationmode (not
conf.presentation
);
4916 showtext ' '
("presentation mode " ^
4917 if conf.presentation
then "on" else "off");
4920 begin match state.fullscreen
with
4922 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4925 state.fullscreen
<- None
;
4930 gotoy_and_clear_text 0
4933 gotopage1 (state.pagecount
- 1) 0
4935 | 112 | 78 -> (* p|N *)
4936 search state.searchpattern
false
4938 | 110 | 0xffc0 -> (* n|F3 *)
4939 search state.searchpattern
true
4942 begin match state.layout with
4945 gotoy_and_clear_text (getpagey l.pageno)
4949 begin match state.layout with
4952 match conf.columns
with
4954 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4956 let y = clamp (pgscale conf.winh
) in
4957 gotoy_and_clear_text y
4959 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4960 gotoy_and_clear_text (getpagey pageno)
4961 | Cmulti
((c, _, _), _) ->
4962 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4963 gotoy_and_clear_text (getpagey pageno)
4965 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4967 let pagey, pageh
= getpageyh l.pageno in
4968 let pagey = pagey + pageh
* l.pagecol
in
4969 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4970 gotoy_and_clear_text (pagey + pageh
+ ips)
4973 | 0xff9f | 0xffff -> (* delete *)
4974 begin match state.layout with
4977 match conf.columns
with
4979 if conf.presentation
&& l.pagey != 0
4981 gotoy_and_clear_text (clamp (pgscale ~
-(conf.winh
)))
4983 let pageno = max
0 (l.pageno-1) in
4984 gotoy_and_clear_text (getpagey pageno)
4985 | Cmulti
((c, _, _), _) ->
4986 let pageno = max
0 (l.pageno-c) in
4987 gotoy_and_clear_text (getpagey pageno)
4995 let pageno = max
0 (l.pageno-1) in
4996 let pagey, pageh
= getpageyh pageno in
4999 let pagey, pageh
= getpageyh l.pageno in
5000 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5002 gotoy_and_clear_text y
5006 showtext ' '
(describe_location ());
5009 begin match state.layout with
5012 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5017 enterbookmarkmode ()
5019 | 104 | 0xffbe -> (* h|F1 *)
5025 | 101 when conf.redirectstderr -> (* e *)
5030 match state.layout with
5031 | l :: _ -> state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5034 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5038 showtext ' '
"Quick bookmark added";
5041 begin match state.layout with
5043 let rect = getpdimrect
l.pagedimno
in
5047 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5048 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5050 (truncate
(rect.(1) -. rect.(0)),
5051 truncate
(rect.(3) -. rect.(0)))
5053 let w = truncate
((float w)*.conf.zoom)
5054 and h = truncate
((float h)*.conf.zoom) in
5057 state.anchor <- getanchor ();
5058 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5060 G.postRedisplay "z";
5065 | 50 when ctrl -> (* ctrl-2 *)
5066 let maxw = getmaxw
() in
5068 then setzoom (maxw /. float conf.winw
)
5070 | 60 | 62 -> (* < > *)
5071 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5073 | 91 | 93 -> (* [ ] *)
5075 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5077 G.postRedisplay "brightness";
5079 | 99 when state.mode = View
-> (* c *)
5081 match state.prevcolumns
with
5082 | None
-> (1, 0, 0), 1.0
5083 | Some
(columns
, z
) ->
5086 | Csplit
(c, _) -> -c, 0, 0
5087 | Cmulti
((c, a, b), _) -> c, a, b
5088 | Csingle
_ -> 1, 0, 0
5092 setcolumns View
c a b;
5095 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5096 setzoom state.prevzoom
5098 | 107 | 0xff52 -> (* k up *)
5099 begin match state.autoscroll
with
5101 begin match state.mode with
5102 | Birdseye beye
-> upbirdseye 1 beye
5105 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5106 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5109 setautoscrollspeed n false
5112 | 106 | 0xff54 -> (* j down *)
5113 begin match state.autoscroll
with
5115 begin match state.mode with
5116 | Birdseye beye
-> downbirdseye 1 beye
5119 then gotoy_and_clear_text (clamp (conf.winh
/2))
5120 else gotoy_and_clear_text (clamp conf.scrollstep
)
5123 setautoscrollspeed n true
5126 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5134 let dx = if key = 0xff51 then dx else -dx in
5135 state.x <- state.x + dx;
5136 gotoy_and_clear_text state.y
5139 G.postRedisplay "lef/right"
5142 | 0xff55 -> (* prior *)
5146 match state.layout with
5148 | l :: _ -> state.y - l.pagey
5150 clamp (pgscale (-conf.winh
))
5154 | 0xff56 -> (* next *)
5158 match List.rev
state.layout with
5160 | l :: _ -> getpagey l.pageno
5162 clamp (pgscale conf.winh
)
5166 | 0xff50 -> (* home *)
5168 | 0xff57 -> (* end *)
5169 gotoghyll (clamp state.maxy)
5170 | 0xff53 when Wsi.withalt mask
-> (* right *)
5171 gotoghyll (getnav ~
-1)
5172 | 0xff51 when Wsi.withalt mask
-> (* left *)
5173 gotoghyll (getnav 1)
5176 state.anchor <- getanchor ();
5177 opendoc state.path state.password
5179 | 118 when conf.debug
-> (* v *)
5182 match getopaque l.pageno with
5185 let x0, y0, x1, y1 = pagebbox opaque
in
5186 let a,b = float x0, float y0 in
5187 let c,d = float x1, float y0 in
5188 let e,f = float x1, float y1 in
5189 let h,j
= float x0, float y1 in
5190 let rect = (a,b,c,d,e,f,h,j
) in
5192 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5194 G.postRedisplay "v";
5197 vlog "huh? %s" (Wsi.keyname
key)
5200 let linknavkeyboard key mask
linknav =
5201 let getpage pageno =
5202 let rec loop = function
5204 | l :: _ when l.pageno = pageno -> Some
l
5205 | _ :: rest
-> loop rest
5206 in loop state.layout
5208 let doexact (pageno, n) =
5209 match getopaque pageno, getpage pageno with
5210 | Some opaque
, Some
l ->
5213 let under = getlink opaque
n in
5214 G.postRedisplay "link gotounder";
5220 | 0xff50 -> (* home *)
5221 Some
(findlink opaque LDfirst
), -1
5223 | 0xff57 -> (* end *)
5224 Some
(findlink opaque LDlast
), 1
5226 | 0xff51 -> (* left *)
5227 Some
(findlink opaque
(LDleft
n)), -1
5229 | 0xff53 -> (* right *)
5230 Some
(findlink opaque
(LDright
n)), 1
5232 | 0xff52 -> (* up *)
5233 Some
(findlink opaque
(LDup
n)), -1
5235 | 0xff54 -> (* down *)
5236 Some
(findlink opaque
(LDdown
n)), 1
5241 begin match findpwl
l.pageno dir with
5245 state.mode <- LinkNav
(Ltgendir
dir);
5246 let y, h = getpageyh pageno in
5249 then y + h - conf.winh
5254 begin match getopaque pageno, getpage pageno with
5255 | Some opaque
, Some
_ ->
5257 let ld = if dir > 0 then LDfirst
else LDlast
in
5260 begin match link with
5262 showlinktype (getlink opaque
m);
5263 state.mode <- LinkNav
(Ltexact
(pageno, m));
5264 G.postRedisplay "linknav jpage";
5271 begin match opt with
5272 | Some Lnotfound
-> pwl l dir;
5273 | Some
(Lfound
m) ->
5277 let _, y0, _, y1 = getlinkrect opaque
m in
5279 then gotopage1 l.pageno y0
5281 let d = fstate.fontsize
+ 1 in
5282 if y1 - l.pagey > l.pagevh - d
5283 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5284 else G.postRedisplay "linknav";
5286 showlinktype (getlink opaque
m);
5287 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5290 | None
-> viewkeyboard key mask
5292 | _ -> viewkeyboard key mask
5297 G.postRedisplay "leave linknav"
5301 | Ltgendir
_ -> viewkeyboard key mask
5302 | Ltexact exact
-> doexact exact
5305 let keyboard key mask
=
5306 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5307 then wcmd "interrupt"
5308 else state.uioh <- state.uioh#
key key mask
5311 let birdseyekeyboard key mask
5312 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5314 match conf.columns
with
5316 | Cmulti
((c, _, _), _) -> c
5317 | Csplit
_ -> failwith
"bird's eye split mode"
5319 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5321 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5322 let y, h = getpageyh pageno in
5323 let top = (conf.winh
- h) / 2 in
5324 gotoy (max
0 (y - top))
5325 | 0xff0d -> leavebirdseye beye
false
5326 | 0xff1b -> leavebirdseye beye
true (* escape *)
5327 | 0xff52 -> upbirdseye incr beye
(* up *)
5328 | 0xff54 -> downbirdseye incr beye
(* down *)
5329 | 0xff51 -> upbirdseye 1 beye
(* left *)
5330 | 0xff53 -> downbirdseye 1 beye
(* right *)
5332 | 0xff55 -> (* prior *)
5333 begin match state.layout with
5337 state.mode <- Birdseye
(
5338 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5340 gotopage1 l.pageno 0;
5343 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5345 | [] -> gotoy (clamp (-conf.winh
))
5347 state.mode <- Birdseye
(
5348 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5350 gotopage1 l.pageno 0
5353 | [] -> gotoy (clamp (-conf.winh
))
5356 | 0xff56 -> (* next *)
5357 begin match List.rev
state.layout with
5359 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5360 begin match layout with
5362 let incr = l.pageh
- l.pagevh in
5367 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5369 G.postRedisplay "birdseye pagedown";
5371 else gotoy (clamp (incr + conf.interpagespace
*2));
5375 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5376 gotopage1 l.pageno 0;
5379 | [] -> gotoy (clamp conf.winh
)
5382 | 0xff50 -> (* home *)
5383 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5386 | 0xff57 -> (* end *)
5387 let pageno = state.pagecount
- 1 in
5388 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5389 if not
(pagevisible state.layout pageno)
5392 match List.rev
state.pdims
with
5394 | (_, _, h, _) :: _ -> h
5396 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5397 else G.postRedisplay "birdseye end";
5398 | _ -> viewkeyboard key mask
5401 let drawpage l linkindexbase
=
5403 match state.mode with
5404 | Textentry
_ -> scalecolor 0.4
5406 | View
-> scalecolor 1.0
5407 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5408 if l.pageno = hooverpageno
5411 if l.pageno = pageno
5417 begin match getopaque l.pageno with
5419 if tileready l l.pagex
l.pagey
5421 let x = l.pagedispx - l.pagex
5422 and y = l.pagedispy - l.pagey in
5424 match conf.columns
with
5425 | Csingle
_ | Cmulti
_ ->
5426 (if conf.hlinks
then 1 else 0)
5428 && not
(isbirdseye state.mode) then 2 else 0)
5432 match state.mode with
5433 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5436 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5443 let scrollindicator () =
5444 let sbw, ph
, sh = state.uioh#
scrollph in
5445 let sbh, pw, sw = state.uioh#scrollpw
in
5447 GlDraw.color (0.64, 0.64, 0.64);
5449 (float (conf.winw
- sbw), 0.)
5450 (float conf.winw
, float conf.winh
)
5453 (0., float (conf.winh
- sbh))
5454 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5456 GlDraw.color (0.0, 0.0, 0.0);
5459 (float (conf.winw
- sbw), ph
)
5460 (float conf.winw
, ph
+. sh)
5463 (pw, float (conf.winh
- sbh))
5464 (pw +. sw, float conf.winh
)
5469 match state.mstate
with
5470 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5473 | Msel
((x0, y0), (x1, y1)) ->
5474 let rec loop = function
5476 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5477 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5478 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5479 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5481 match getopaque l.pageno with
5483 let x0, y0 = pagetranslatepoint l x0 y0 in
5484 let x1, y1 = pagetranslatepoint l x1 y1 in
5485 seltext opaque
(x0, y0, x1, y1);
5493 let showrects rects
=
5495 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5496 GlDraw.polygon_mode `both `fill
;
5497 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5499 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5501 if l.pageno = pageno
5503 let dx = float (l.pagedispx - l.pagex
) in
5504 let dy = float (l.pagedispy - l.pagey) in
5505 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5506 GlDraw.begins `quads
;
5508 GlDraw.vertex2
(x0+.dx, y0+.dy);
5509 GlDraw.vertex2
(x1+.dx, y1+.dy);
5510 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5511 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5522 GlClear.color (scalecolor2 conf.bgcolor
);
5523 GlClear.clear
[`
color];
5524 let rec loop linkindexbase
= function
5526 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5527 loop linkindexbase rest
5530 loop 0 state.layout;
5532 match state.mode with
5533 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5534 begin match getopaque pageno with
5536 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5543 | None
-> state.rects
5550 begin match state.mstate
with
5551 | Mzoomrect
((x0, y0), (x1, y1)) ->
5553 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5554 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5555 GlDraw.rect (float x0, float y0)
5556 (float x1, float y1);
5565 let zoomrect x y x1 y1 =
5568 and y0 = min
y y1 in
5569 gotoy (state.y + y0);
5570 state.anchor <- getanchor ();
5571 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5573 if state.w < conf.winw
- state.scrollw
5574 then (conf.winw
- state.scrollw
- state.w) / 2
5577 state.x <- (state.x + margin) - x0;
5579 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5580 state.mstate
<- Mnone
;
5584 let winw = conf.winw - state.scrollw
- 1 in
5585 let s = float x /. float winw in
5586 let destx = truncate
(float (state.w + winw) *. s) in
5587 state.x <- winw - destx;
5588 gotoy_and_clear_text state.y;
5589 state.mstate
<- Mscrollx
;
5593 let s = float y /. float conf.winh
in
5594 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5595 gotoy_and_clear_text desty;
5596 state.mstate
<- Mscrolly
;
5599 let viewmouse button down
x y mask
=
5601 | n when (n == 4 || n == 5) && not down
->
5602 if Wsi.withctrl mask
5604 match state.mstate
with
5605 | Mzoom
(oldn
, i
) ->
5613 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5615 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5617 let zoom = conf.zoom -. incr in
5619 state.mstate
<- Mzoom
(n, 0);
5621 state.mstate
<- Mzoom
(n, i
+1);
5623 else state.mstate
<- Mzoom
(n, 0)
5625 | _ -> state.mstate
<- Mzoom
(n, 0)
5628 match state.autoscroll
with
5629 | Some step
-> setautoscrollspeed step
(n=4)
5633 then -conf.scrollstep
5634 else conf.scrollstep
5636 let incr = incr * 2 in
5637 let y = clamp incr in
5638 gotoy_and_clear_text y
5641 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5642 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5643 gotoy_and_clear_text state.y
5645 | 1 when Wsi.withctrl mask
->
5648 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5649 state.mstate
<- Mpan
(x, y)
5652 state.mstate
<- Mnone
5657 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5659 state.mstate
<- Mzoomrect
(p, p)
5662 match state.mstate
with
5663 | Mzoomrect
((x0, y0), _) ->
5664 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5665 then zoomrect x0 y0 x y
5667 state.mstate
<- Mnone
;
5668 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5669 G.postRedisplay "kill accidental zoom rect";
5672 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5673 state.mstate
<- Mnone
5676 | 1 when x > conf.winw - state.scrollw
->
5679 let _, position, sh = state.uioh#
scrollph in
5680 if y > truncate
position && y < truncate
(position +. sh)
5681 then state.mstate
<- Mscrolly
5684 state.mstate
<- Mnone
5686 | 1 when y > conf.winh
- state.hscrollh ->
5689 let _, position, sw = state.uioh#scrollpw
in
5690 if x > truncate
position && x < truncate
(position +. sw)
5691 then state.mstate
<- Mscrollx
5694 state.mstate
<- Mnone
5697 let dest = if down
then getunder x y else Unone
in
5698 begin match dest with
5702 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5705 | Unone
when down
->
5706 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5707 state.mstate
<- Mpan
(x, y);
5709 | Unone
| Utext
_ ->
5712 if conf.angle
mod 360 = 0
5714 state.mstate
<- Msel
((x, y), (x, y));
5715 G.postRedisplay "mouse select";
5719 match state.mstate
with
5722 | Mzoom
_ | Mscrollx
| Mscrolly
->
5723 state.mstate
<- Mnone
5725 | Mzoomrect
((x0, y0), _) ->
5729 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5730 state.mstate
<- Mnone
5732 | Msel
((_, y0), (_, y1)) ->
5733 let rec loop = function
5736 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5737 || ((y1 >= l.pagedispy
5738 && y1 <= (l.pagedispy + l.pagevh)))
5740 match getopaque l.pageno with
5743 match Ne.pipe () with
5747 "can not create sel pipe: %s"
5748 (Printexc.to_string exn
));
5750 let doclose what fd
=
5751 Ne.clo fd
(fun msg
->
5752 dolog "%s close failed: %s" what msg
)
5755 popen conf.selcmd
[r, 0; w, -1];
5758 G.postRedisplay "copysel";
5760 dolog "can not execute %S: %s"
5761 conf.selcmd
(Printexc.to_string exn
);
5769 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5770 state.mstate
<- Mnone
;
5777 let birdseyemouse button down
x y mask
5778 (conf, leftx
, _, hooverpageno
, anchor) =
5781 let rec loop = function
5784 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5785 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5787 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5793 | _ -> viewmouse button down
x y mask
5796 let mouse button down
x y mask
=
5797 state.uioh <- state.uioh#button button down
x y mask
;
5801 state.uioh <- state.uioh#
motion x y
5805 state.uioh <- state.uioh#
pmotion x y;
5811 method key key mask
=
5812 begin match state.mode with
5813 | Textentry
textentry -> textentrykeyboard key mask
textentry
5814 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5815 | View
-> viewkeyboard key mask
5816 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5820 method button button bstate
x y mask
=
5821 begin match state.mode with
5823 | View
-> viewmouse button bstate
x y mask
5824 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5830 begin match state.mode with
5832 | View
| Birdseye
_ | LinkNav
_ ->
5833 match state.mstate
with
5834 | Mzoom
_ | Mnone
-> ()
5839 state.mstate
<- Mpan
(x, y);
5841 then state.x <- state.x + dx;
5843 gotoy_and_clear_text y
5846 state.mstate
<- Msel
(a, (x, y));
5847 G.postRedisplay "motion select";
5850 let y = min
conf.winh
(max
0 y) in
5854 let x = min
conf.winw (max
0 x) in
5857 | Mzoomrect
(p0
, _) ->
5858 state.mstate
<- Mzoomrect
(p0
, (x, y));
5859 G.postRedisplay "motion zoomrect";
5863 method pmotion x y =
5864 begin match state.mode with
5865 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5866 let rec loop = function
5868 if hooverpageno
!= -1
5870 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5871 G.postRedisplay "pmotion birdseye no hoover";
5874 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5875 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5877 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5878 G.postRedisplay "pmotion birdseye hoover";
5888 match state.mstate
with
5889 | Mnone
-> updateunder x y
5890 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5895 method infochanged
_ = ()
5898 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5899 let p, h = scrollph state.y maxy in
5903 let winw = conf.winw - state.scrollw
- 1 in
5904 let fwinw = float winw in
5906 let sw = fwinw /. float state.w in
5907 let sw = fwinw *. sw in
5908 max
sw (float conf.scrollh
)
5911 let f = state.w+winw in
5912 let r = float (winw-state.x) /. float f in
5913 let p = fwinw *. r in
5917 if position +. sw > fwinw
5918 then fwinw -. position
5921 state.hscrollh, position, sw
5925 match state.mode with
5926 | LinkNav
_ -> "links"
5927 | Textentry
_ -> "textentry"
5928 | Birdseye
_ -> "birdseye"
5931 findkeyhash conf modename
5938 let fontpath = ref "";;
5941 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5944 let l = String.length
s in
5945 let b = Buffer.create
l in
5951 try Sys.getenv
"HOME"
5954 ("Can not determine home directory location: " ^
5955 Printexc.to_string exn
);
5959 let modifier_of_string = function
5960 | "alt" -> Wsi.altmask
5961 | "shift" -> Wsi.shiftmask
5962 | "ctrl" | "control" -> Wsi.ctrlmask
5963 | "meta" -> Wsi.metamask
5968 let r = Str.regexp
"-" in
5970 let elems = Str.full_split
r s in
5973 let m1 = modifier_of_string s in
5975 then (Wsi.namekey
s, m)
5978 | Str.Delim
s when n land 1 = 0 -> g s
5980 | Str.Delim
_ -> (k
, m)
5982 let rec loop n k
m = function
5985 let k, m = f n k m x in
5991 let keys_of_string =
5992 let r = Str.regexp
"[ \t]" in
5994 let elems = Str.split
r s in
5995 List.map
key_of_string elems
5998 let copykeyhashes c =
5999 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6002 let config_of c attrs
=
6006 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6007 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6008 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6009 | "preload" -> { c with preload = bool_of_string
v }
6010 | "page-bias" -> { c with pagebias
= int_of_string
v }
6011 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6012 | "horizontal-scroll-step" ->
6013 { c with hscrollstep
= max
(int_of_string
v) 1 }
6014 | "auto-scroll-step" ->
6015 { c with autoscrollstep
= max
0 (int_of_string
v) }
6016 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6017 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6020 match String.lowercase
v with
6021 | "true" -> Some infinity
6023 | f -> Some
(float_of_string
f)
6025 { c with maxwait
= mw}
6026 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6027 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6028 | "vertical-margin" ->
6029 { c with interpagespace
= max
0 (int_of_string
v) }
6031 let zoom = float_of_string
v /. 100. in
6032 let zoom = max
zoom 0.0 in
6033 { c with zoom = zoom }
6034 | "presentation" -> { c with presentation
= bool_of_string
v }
6035 | "rotation-angle" -> { c with angle
= int_of_string
v }
6036 | "width" -> { c with winw = max
20 (int_of_string
v) }
6037 | "height" -> { c with winh
= max
20 (int_of_string
v) }
6038 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6039 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6040 | "pixmap-cache-size" ->
6041 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6042 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6043 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6044 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6045 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6046 | "background-color" -> { c with bgcolor
= color_of_string v }
6047 | "scrollbar-in-presentation" ->
6048 { c with scrollbarinpm
= bool_of_string
v }
6049 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6050 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6051 | "mupdf-store-size" ->
6052 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6053 | "checkers" -> { c with checkers
= bool_of_string
v }
6054 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6055 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6056 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6057 | "uri-launcher" -> { c with urilauncher
= unent v }
6058 | "path-launcher" -> { c with pathlauncher
= unent v }
6059 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6060 | "invert-colors" -> { c with invert
= bool_of_string
v }
6061 | "brightness" -> { c with colorscale
= float_of_string
v }
6062 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6064 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6066 let (n, _, _) as nab
= multicolumns_of_string v in
6068 then { c with columns
= Csplit
(-n, [||]) }
6069 else { c with columns
= Cmulti
(nab
, [||]) }
6070 | "birds-eye-columns" ->
6071 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6072 | "selection-command" -> { c with selcmd
= unent v }
6073 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6074 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6075 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6076 | "multi-column-centering" -> { c with multicenter
= bool_of_string
v }
6079 prerr_endline
("Error processing attribute (`" ^
6080 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6083 let rec fold c = function
6086 let c = apply c k v in
6089 fold { c with keyhashes
= copykeyhashes c } attrs
;
6092 let fromstring f pos
n v d =
6095 dolog "Error processing attribute (%S=%S) at %d\n%s"
6096 n v pos
(Printexc.to_string exn
)
6101 let bookmark_of attrs
=
6102 let rec fold title page
rely visy
= function
6103 | ("title", v) :: rest
-> fold v page
rely visy rest
6104 | ("page", v) :: rest
-> fold title v rely visy rest
6105 | ("rely", v) :: rest
-> fold title page
v visy rest
6106 | ("visy", v) :: rest
-> fold title page
rely v rest
6107 | _ :: rest
-> fold title page
rely visy rest
6108 | [] -> title, page
, rely, visy
6110 fold "invalid" "0" "0" "0" attrs
6114 let rec fold path page
rely pan visy
= function
6115 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6116 | ("page", v) :: rest
-> fold path v rely pan visy rest
6117 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6118 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6119 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6120 | _ :: rest
-> fold path page
rely pan visy rest
6121 | [] -> path, page
, rely, pan
, visy
6123 fold "" "0" "0" "0" "0" attrs
6127 let rec fold rs ls
= function
6128 | ("out", v) :: rest
-> fold v ls rest
6129 | ("in", v) :: rest
-> fold rs
v rest
6130 | _ :: rest
-> fold ls rs rest
6136 let setconf dst
src =
6137 dst
.scrollbw
<- src.scrollbw
;
6138 dst
.scrollh
<- src.scrollh
;
6139 dst
.icase
<- src.icase
;
6140 dst
.preload <- src.preload;
6141 dst
.pagebias
<- src.pagebias
;
6142 dst
.verbose
<- src.verbose
;
6143 dst
.scrollstep
<- src.scrollstep
;
6144 dst
.maxhfit
<- src.maxhfit
;
6145 dst
.crophack
<- src.crophack
;
6146 dst
.autoscrollstep
<- src.autoscrollstep
;
6147 dst
.maxwait
<- src.maxwait
;
6148 dst
.hlinks
<- src.hlinks
;
6149 dst
.underinfo
<- src.underinfo
;
6150 dst
.interpagespace
<- src.interpagespace
;
6151 dst
.zoom <- src.zoom;
6152 dst
.presentation
<- src.presentation
;
6153 dst
.angle
<- src.angle
;
6154 dst
.winw <- src.winw;
6155 dst
.winh
<- src.winh
;
6156 dst
.savebmarks
<- src.savebmarks
;
6157 dst
.memlimit
<- src.memlimit
;
6158 dst
.proportional
<- src.proportional
;
6159 dst
.texcount
<- src.texcount
;
6160 dst
.sliceheight
<- src.sliceheight
;
6161 dst
.thumbw
<- src.thumbw
;
6162 dst
.jumpback
<- src.jumpback
;
6163 dst
.bgcolor
<- src.bgcolor
;
6164 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6165 dst
.tilew
<- src.tilew
;
6166 dst
.tileh
<- src.tileh
;
6167 dst
.mustoresize
<- src.mustoresize
;
6168 dst
.checkers
<- src.checkers
;
6169 dst
.aalevel
<- src.aalevel
;
6170 dst
.trimmargins
<- src.trimmargins
;
6171 dst
.trimfuzz
<- src.trimfuzz
;
6172 dst
.urilauncher
<- src.urilauncher
;
6173 dst
.colorspace
<- src.colorspace
;
6174 dst
.invert
<- src.invert
;
6175 dst
.colorscale
<- src.colorscale
;
6176 dst
.redirectstderr <- src.redirectstderr;
6177 dst
.ghyllscroll
<- src.ghyllscroll
;
6178 dst
.columns
<- src.columns
;
6179 dst
.beyecolumns
<- src.beyecolumns
;
6180 dst
.selcmd
<- src.selcmd
;
6181 dst
.updatecurs
<- src.updatecurs
;
6182 dst
.pathlauncher
<- src.pathlauncher
;
6183 dst
.keyhashes
<- copykeyhashes src;
6184 dst
.hfsize
<- src.hfsize
;
6185 dst
.hscrollstep
<- src.hscrollstep
;
6186 dst
.pgscale <- src.pgscale;
6187 dst
.multicenter
<- src.multicenter
;
6191 let h = Hashtbl.create
10 in
6192 let dc = { defconf with angle
= defconf.angle
} in
6193 let rec toplevel v t spos
_ =
6195 | Vdata
| Vcdata
| Vend
-> v
6196 | Vopen
("llppconfig", _, closed
) ->
6199 else { v with f = llppconfig
}
6201 error
"unexpected subelement at top level" s spos
6202 | Vclose
_ -> error
"unexpected close at top level" s spos
6204 and llppconfig
v t spos
_ =
6206 | Vdata
| Vcdata
-> v
6207 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6208 | Vopen
("defaults", attrs
, closed
) ->
6209 let c = config_of dc attrs
in
6213 else { v with f = defaults
}
6215 | Vopen
("ui-font", attrs
, closed
) ->
6216 let rec getsize size
= function
6218 | ("size", v) :: rest
->
6220 fromstring int_of_string spos
"size" v fstate.fontsize
in
6222 | l -> getsize size l
6224 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6227 else { v with f = uifont
(Buffer.create
10) }
6229 | Vopen
("doc", attrs
, closed
) ->
6230 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6231 let path = unent pathent
6232 and pageno = fromstring int_of_string spos
"page" spage
0
6233 and rely = fromstring float_of_string spos
"rely" srely
0.0
6234 and pan
= fromstring int_of_string spos
"pan" span
0
6235 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6236 let c = config_of dc attrs
in
6237 let anchor = (pageno, rely, visy
) in
6239 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6240 else { v with f = doc
path pan
anchor c [] }
6243 error
"unexpected subelement in llppconfig" s spos
6245 | Vclose
"llppconfig" -> { v with f = toplevel }
6246 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6248 and defaults
v t spos
_ =
6250 | Vdata
| Vcdata
-> v
6251 | Vend
-> error
"unexpected end of input in defaults" s spos
6252 | Vopen
("keymap", attrs
, closed
) ->
6254 try List.assoc
"mode" attrs
6255 with Not_found
-> "global" in
6260 let h = findkeyhash dc modename in
6261 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6264 { v with f = pkeymap
ret KeyMap.empty }
6266 | Vopen
(_, _, _) ->
6267 error
"unexpected subelement in defaults" s spos
6269 | Vclose
"defaults" ->
6270 { v with f = llppconfig
}
6272 | Vclose
_ -> error
"unexpected close in defaults" s spos
6274 and uifont
b v t spos
epos =
6277 Buffer.add_substring
b s spos
(epos - spos
);
6279 | Vopen
(_, _, _) ->
6280 error
"unexpected subelement in ui-font" s spos
6281 | Vclose
"ui-font" ->
6282 if String.length
!fontpath = 0
6283 then fontpath := Buffer.contents
b;
6284 { v with f = llppconfig
}
6285 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6286 | Vend
-> error
"unexpected end of input in ui-font" s spos
6288 and doc
path pan
anchor c bookmarks
v t spos
_ =
6290 | Vdata
| Vcdata
-> v
6291 | Vend
-> error
"unexpected end of input in doc" s spos
6292 | Vopen
("bookmarks", _, closed
) ->
6295 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6297 | Vopen
("keymap", attrs
, closed
) ->
6299 try List.assoc
"mode" attrs
6300 with Not_found
-> "global"
6306 let h = findkeyhash c modename in
6307 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6308 doc
path pan
anchor c bookmarks
6310 { v with f = pkeymap
ret KeyMap.empty }
6312 | Vopen
(_, _, _) ->
6313 error
"unexpected subelement in doc" s spos
6316 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6317 { v with f = llppconfig
}
6319 | Vclose
_ -> error
"unexpected close in doc" s spos
6321 and pkeymap
ret keymap
v t spos
_ =
6323 | Vdata
| Vcdata
-> v
6324 | Vend
-> error
"unexpected end of input in keymap" s spos
6325 | Vopen
("map", attrs
, closed
) ->
6326 let r, l = map_of attrs
in
6327 let kss = fromstring keys_of_string spos
"in" r [] in
6328 let lss = fromstring keys_of_string spos
"out" l [] in
6332 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6333 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6336 then { v with f = pkeymap
ret keymap }
6339 { v with f = skip
"map" f }
6342 error
"unexpected subelement in keymap" s spos
6344 | Vclose
"keymap" ->
6345 { v with f = ret keymap }
6347 | Vclose
_ -> error
"unexpected close in keymap" s spos
6349 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6351 | Vdata
| Vcdata
-> v
6352 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6353 | Vopen
("item", attrs
, closed
) ->
6354 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6355 let page = fromstring int_of_string spos
"page" spage
0
6356 and rely = fromstring float_of_string spos
"rely" srely
0.0
6357 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6359 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6362 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6365 { v with f = skip
"item" f }
6368 error
"unexpected subelement in bookmarks" s spos
6370 | Vclose
"bookmarks" ->
6371 { v with f = doc
path pan
anchor c bookmarks }
6373 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6375 and skip tag
f v t spos
_ =
6377 | Vdata
| Vcdata
-> v
6379 error
("unexpected end of input in skipped " ^ tag
) s spos
6380 | Vopen
(tag'
, _, closed
) ->
6384 let f'
() = { v with f = skip tag
f } in
6385 { v with f = skip tag'
f'
}
6389 else error
("unexpected close in skipped " ^ tag
) s spos
6392 parse
{ f = toplevel; accu = () } s;
6398 let len = in_channel_length ic
in
6399 let s = String.create
len in
6400 really_input ic
s 0 len;
6403 | Parse_error
(msg
, s, pos
) ->
6404 let subs = subs s pos
in
6405 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6406 failwith
("parse error: " ^
s)
6409 failwith
("config load error: " ^
Printexc.to_string exn
)
6415 let dir = Filename.concat
home ".config" in
6416 if Sys.is_directory
dir then dir else home
6419 Filename.concat
dir "llpp.conf"
6422 let confpath = ref defconfpath;;
6425 if Sys.file_exists
!confpath
6428 (try Some
(open_in_bin
!confpath)
6431 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6432 Printexc.to_string exn
);
6442 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6443 Printexc.to_string exn
);
6451 f (Hashtbl.create
0, defconf)
6456 let pc, pb
, px, pa
=
6458 Hashtbl.find h (Filename.basename
state.path)
6459 with Not_found
-> dc, [], 0, emptyanchor
6463 state.bookmarks <- pb
;
6465 state.scrollw
<- conf.scrollbw
;
6467 then state.anchor <- pa
;
6468 cbput state.hists
.nav pa
;
6474 let add_attrs bb always
dc c =
6477 then Printf.bprintf bb
"\n %s='%b'" s a
6480 then Printf.bprintf bb
"\n %s='%d'" s a
6483 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6486 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6489 then Printf.bprintf bb
"\n %s='%f'" s a
6493 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6497 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6501 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6505 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6511 | Some
(_N
, _A
, _B
) ->
6512 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6522 else string_of_float
f
6524 Printf.bprintf bb
"\n %s='%s'" s v
6529 | Cmulti
((n, a, b), _) when n > 1 ->
6530 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6531 | Csplit
(n, _) when n > 1 ->
6532 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6538 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6543 then dc.winw, dc.winh
6545 match state.fullscreen
with
6547 | None
-> c.winw, c.winh
6549 oi
"width" w dc.winw;
6550 oi
"height" h dc.winh
;
6551 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6552 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6553 ob "case-insensitive-search" c.icase
dc.icase
;
6554 ob "preload" c.preload dc.preload;
6555 oi
"page-bias" c.pagebias
dc.pagebias
;
6556 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6557 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6558 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6559 ob "crop-hack" c.crophack
dc.crophack
;
6560 oW
"throttle" c.maxwait
dc.maxwait
;
6561 ob "highlight-links" c.hlinks
dc.hlinks
;
6562 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6563 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6564 oz
"zoom" c.zoom dc.zoom;
6565 ob "presentation" c.presentation
dc.presentation
;
6566 oi
"rotation-angle" c.angle
dc.angle
;
6567 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6568 ob "proportional-display" c.proportional
dc.proportional
;
6569 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6570 oi
"tex-count" c.texcount
dc.texcount
;
6571 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6572 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6573 ob "persistent-location" c.jumpback
dc.jumpback
;
6574 oc
"background-color" c.bgcolor
dc.bgcolor
;
6575 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6576 oi
"tile-width" c.tilew
dc.tilew
;
6577 oi
"tile-height" c.tileh
dc.tileh
;
6578 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6579 ob "checkers" c.checkers
dc.checkers
;
6580 oi
"aalevel" c.aalevel
dc.aalevel
;
6581 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6582 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6583 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6584 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6585 oC
"color-space" c.colorspace
dc.colorspace
;
6586 ob "invert-colors" c.invert
dc.invert
;
6587 oF
"brightness" c.colorscale
dc.colorscale
;
6588 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6589 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6590 oco
"columns" c.columns
dc.columns
;
6591 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6592 os
"selection-command" c.selcmd
dc.selcmd
;
6593 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6594 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6595 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6596 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6597 ob "multi-column-centering" c.multicenter
dc.multicenter
;
6600 let keymapsbuf always
dc c =
6601 let bb = Buffer.create
16 in
6602 let rec loop = function
6604 | (modename, h) :: rest
->
6605 let dh = findkeyhash dc modename in
6606 if always
|| h <> dh
6608 if Hashtbl.length
h > 0
6610 if Buffer.length
bb > 0
6611 then Buffer.add_char
bb '
\n'
;
6612 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6613 Hashtbl.iter
(fun i
o ->
6614 let isdifferent = always
||
6616 let dO = Hashtbl.find dh i
in
6618 with Not_found
-> true
6623 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6624 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6625 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6626 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6627 Buffer.add_string
bb (Wsi.keyname
k);
6630 let rec loop = function
6632 | km
:: [] -> addkm km
6633 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6637 Buffer.add_string
bb "<map in='";
6641 Buffer.add_string
bb "' out='";
6643 Buffer.add_string
bb "'/>\n"
6646 Buffer.add_string
bb "' out='";
6648 Buffer.add_string
bb "'/>\n"
6650 | KMmulti
(ins, kms
) ->
6651 Buffer.add_char
bb ' '
;
6653 Buffer.add_string
bb "' out='";
6655 Buffer.add_string
bb "'/>\n"
6657 Buffer.add_string
bb "</keymap>";
6667 let uifontsize = fstate.fontsize
in
6668 let bb = Buffer.create
32768 in
6670 let dc = if conf.bedefault
then conf else dc in
6671 Buffer.add_string
bb "<llppconfig>\n";
6673 if String.length
!fontpath > 0
6675 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6681 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6684 Buffer.add_string
bb "<defaults ";
6685 add_attrs bb true dc dc;
6686 let kb = keymapsbuf true dc dc in
6687 if Buffer.length
kb > 0
6689 Buffer.add_string
bb ">\n";
6690 Buffer.add_buffer
bb kb;
6691 Buffer.add_string
bb "\n</defaults>\n";
6693 else Buffer.add_string
bb "/>\n";
6695 let adddoc path pan
anchor c bookmarks =
6696 if bookmarks == [] && c = dc && anchor = emptyanchor
6699 Printf.bprintf
bb "<doc path='%s'"
6700 (enent
path 0 (String.length
path));
6702 if anchor <> emptyanchor
6704 let n, rely, visy
= anchor in
6705 Printf.bprintf
bb " page='%d'" n;
6708 Printf.bprintf
bb " rely='%f'" rely
6710 if abs_float visy
> 1e-6
6712 Printf.bprintf
bb " visy='%f'" visy
6717 then Printf.bprintf
bb " pan='%d'" pan
;
6719 add_attrs bb false dc c;
6720 let kb = keymapsbuf false dc c in
6722 begin match bookmarks with
6724 if Buffer.length
kb > 0
6726 Buffer.add_string
bb ">\n";
6727 Buffer.add_buffer
bb kb;
6728 Buffer.add_string
bb "\n</doc>\n";
6730 else Buffer.add_string
bb "/>\n"
6732 Buffer.add_string
bb ">\n<bookmarks>\n";
6733 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6735 "<item title='%s' page='%d'"
6736 (enent
title 0 (String.length
title))
6741 Printf.bprintf
bb " rely='%f'" rely
6743 if abs_float visy
> 1e-6
6745 Printf.bprintf
bb " visy='%f'" visy
6747 Buffer.add_string
bb "/>\n";
6749 Buffer.add_string
bb "</bookmarks>";
6750 if Buffer.length
kb > 0
6752 Buffer.add_string
bb "\n";
6753 Buffer.add_buffer
bb kb;
6755 Buffer.add_string
bb "\n</doc>\n";
6761 match state.mode with
6762 | Birdseye
(c, pan, _, _, _) ->
6764 match conf.columns
with
6765 | Cmulti
((c, _, _), _) -> Some
c
6769 match c.columns
with
6770 | Cmulti
(c, _) -> Cmulti
(c, [||])
6771 | Csingle
_ -> Csingle
[||]
6772 | Csplit
_ -> failwith
"quit from bird's eye while split"
6774 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6775 | _ -> state.x, conf
6777 let basename = Filename.basename state.path in
6778 adddoc basename pan (getanchor ())
6780 let autoscrollstep =
6781 match state.autoscroll
with
6783 | None
-> conf.autoscrollstep
6785 match state.mode with
6786 | Birdseye
(bc
, _, _, _, _) ->
6789 presentation
= bc
.presentation
;
6790 interpagespace
= bc
.interpagespace
;
6791 maxwait
= bc
.maxwait
;
6792 autoscrollstep = autoscrollstep }
6793 | _ -> { conf with autoscrollstep = autoscrollstep }
6795 (if conf.savebmarks
then state.bookmarks else []);
6797 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6799 then adddoc path x anchor c bookmarks
6801 Buffer.add_string
bb "</llppconfig>\n";
6804 if load1 f && Buffer.length
bb > 0
6807 let tmp = !confpath ^
".tmp" in
6808 let oc = open_out_bin
tmp in
6809 Buffer.output_buffer
oc bb;
6811 Unix.rename
tmp !confpath;
6814 ("error while saving configuration: " ^
Printexc.to_string exn
)
6819 let trimcachepath = ref "" in
6822 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6823 "<password> Set password");
6825 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6826 "<path> Set path to the user interface font");
6828 ("-c", Arg.String
(fun s -> Config.confpath := s),
6829 "<path> Set path to the configuration file");
6831 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6832 "<path> Set path to the trim cache file");
6834 ("-v", Arg.Unit
(fun () ->
6836 "%s\nconfiguration path: %s\n"
6840 exit
0), " Print version and exit");
6843 (fun s -> state.path <- s)
6844 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6846 if String.length
state.path = 0
6847 then (prerr_endline
"file name missing"; exit
1);
6849 if not
(Config.load ())
6850 then prerr_endline
"failed to load configuration";
6852 let globalkeyhash = findkeyhash conf "global" in
6853 let wsfd, winw, winh
= Wsi.init
(object
6855 if nogeomcmds state.geomcmds
|| platform == Posx
6858 GlClear.color (scalecolor2 conf.bgcolor
);
6859 GlClear.clear
[`
color];
6861 method display = display ()
6862 method reshape w h = reshape w h
6863 method mouse b d x y m = mouse b d x y m
6864 method motion x y = state.mpos
<- (x, y); motion x y
6865 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6867 let mascm = m land (
6868 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6870 match state.keystate
with
6872 let km = k, mascm in
6875 let modehash = state.uioh#
modehash in
6876 try Hashtbl.find modehash km
6878 try Hashtbl.find globalkeyhash km
6879 with Not_found
-> KMinsrt
(k, m)
6881 | KMinsrt
(k, m) -> keyboard k m
6882 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6883 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6885 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6886 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6887 state.keystate
<- KSnone
6888 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6889 state.keystate
<- KSinto
(keys
, insrt
)
6891 state.keystate
<- KSnone
6893 method enter
x y = state.mpos
<- (x, y); pmotion x y
6894 method leave = state.mpos
<- (-1, -1)
6895 method quit
= raise Quit
6896 end) conf.winw conf.winh
(platform = Posx
) in
6901 List.exists
GlMisc.check_extension
6902 [ "GL_ARB_texture_rectangle"
6903 ; "GL_EXT_texture_recangle"
6904 ; "GL_NV_texture_rectangle" ]
6906 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6909 match Ne.pipe () with
6911 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6915 match Ne.pipe () with
6917 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6927 setcheckers conf.checkers
;
6931 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6932 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6933 !Config.fontpath, !trimcachepath
6937 state.text <- "Opening " ^
state.path;
6939 opendoc state.path state.password
;
6942 let rec loop deadline
=
6944 match state.errfd
with
6945 | None
-> [state.sr
; state.wsfd]
6946 | Some fd
-> [state.sr
; state.wsfd; fd
]
6950 state.redisplay
<- false;
6957 if deadline
= infinity
6959 else max
0.0 (deadline
-. now)
6964 try Unix.select
r [] [] timeout
6965 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6971 if state.ghyll
== noghyll
6973 match state.autoscroll
with
6974 | Some step
when step
!= 0 ->
6975 let y = state.y + step
in
6979 else if y >= state.maxy then 0 else y
6982 if state.mode = View
6983 then state.text <- "";
6986 else deadline
+. 0.01
6991 let rec checkfds = function
6993 | fd
:: rest
when fd
= state.sr
->
6994 let cmd = readcmd state.sr
in
6998 | fd
:: rest
when fd
= state.wsfd ->
7003 let s = String.create
80 in
7004 let n = Unix.read fd
s 0 80 in
7005 if conf.redirectstderr
7007 Buffer.add_substring
state.errmsgs
s 0 n;
7008 state.newerrmsgs
<- true;
7009 state.redisplay
<- true;
7012 prerr_string
(String.sub
s 0 n);
7020 if deadline
= infinity
7024 match state.autoscroll
with
7025 | Some step
when step
!= 0 -> deadline1
7026 | _ -> if state.ghyll
== noghyll then infinity
else deadline1