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 -> (n
, a
, b));
982 let n = Unix.read fd
s 0 4 in
983 if n != 4 then failwith
"incomplete read(len)";
985 lor (Char.code
s.[0] lsl 24)
986 lor (Char.code
s.[1] lsl 16)
987 lor (Char.code
s.[2] lsl 8)
988 lor (Char.code
s.[3] lsl 0)
990 let s = String.create
len in
991 let n = Unix.read fd
s 0 len in
992 if n != len then failwith
"incomplete read(data)";
996 let btod b = if b then 1 else 0;;
999 let b = Buffer.create
16 in
1000 Buffer.add_string
b "llll";
1003 let s = Buffer.contents
b in
1004 let n = String.length
s in
1006 (* dolog "wcmd %S" (String.sub s 4 len); *)
1007 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1008 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1009 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1010 s.[3] <- Char.chr
(len land 0xff);
1011 let n'
= Unix.write
state.sw
s 0 n in
1012 if n'
!= n then failwith
"write failed";
1017 if conf.presentation
1019 let d = conf.winh
- h
in
1020 max
conf.interpagespace
((d + 1) / 2)
1026 match conf.columns
with
1027 | Cmulti
((c, _
, _
), b) ->
1028 let rec loop y h
n =
1032 if n = Array.length
b
1035 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
1041 loop max_int
0 (((Array.length
b - 1) / c) * c)
1043 if Array.length
b > 0
1045 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1046 y + h
+ (if conf.presentation
then calcips h
else 0)
1049 if Array.length
b > 0
1051 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1056 let getpageyh pageno
=
1057 let pageno = bound pageno 0 (state.pagecount
-1) in
1058 match conf.columns
with
1060 let (_
, _
, y, (_
, _
, h
, _
)) = b.(pageno) in
1062 if conf.presentation
1068 let (_
, _
, y, (_
, _
, h
, _
)) = b.(pageno) in
1072 let (_
, _
, y, (_
, _
, h
, _
)) = b.(n) in
1076 let getpagedim pageno =
1079 | (n, _
, _
, _
) as pdim
:: rest
->
1081 then (if n = pageno then pdim
else ppdim
)
1086 f (-1, -1, -1, -1) state.pdims
1089 let getpagey pageno = fst
(getpageyh pageno);;
1091 let nogeomcmds cmds
=
1093 | s, [] -> String.length
s = 0
1097 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1098 let sh = sh - state.hscrollh
in
1099 let rec fold accu
n =
1100 if n = Array.length
b
1103 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
1106 || n = state.pagecount
- coverB
1107 || (n - coverA
) mod columns
= columns
- 1)
1113 let pagey = max
0 (y - vy
) in
1114 let pagedispy = if pagey > 0 then 0 else vy
- y in
1115 let pagedispx, pagex
=
1117 if n = coverA
- 1 || n = state.pagecount
- coverB
1118 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1119 else dx + xoff
+ state.x
1126 let vw = conf.winw
- state.scrollw
- pagedispx in
1127 let pw = w
- pagex
in
1130 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1131 if pagevw > 0 && pagevh > 0
1135 ; pagedimno
= pdimno
1142 ; pagedispx = pagedispx
1143 ; pagedispy = pagedispy
1155 List.rev
(fold [] 0)
1158 let layoutS (columns
, b) y sh =
1159 let sh = sh - state.hscrollh
in
1160 let rec fold accu n =
1161 if n = Array.length
b
1164 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
1171 let x = xoff
+ state.x in
1172 let pagey = max
0 (y - vy
) in
1173 let pagedispy = if pagey > 0 then 0 else vy
- y in
1174 let pagedispx, pagex
=
1188 let pagecolw = pagew
/columns
in
1190 if pagecolw < conf.winw
1191 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1195 let vw = conf.winw
- pagedispx - state.scrollw
in
1196 let pw = pagew
- pagex
in
1199 let pagevw = min
pagevw pagecolw in
1200 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1201 if pagevw > 0 && pagevh > 0
1204 { pageno = n/columns
1205 ; pagedimno
= pdimno
1212 ; pagedispx = pagedispx
1213 ; pagedispy = pagedispy
1214 ; pagecol
= n mod columns
1225 List.rev
(fold [] 0)
1229 if nogeomcmds state.geomcmds
1231 match conf.columns
with
1232 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1233 | Cmulti
c -> layoutN c y sh
1234 | Csplit
s -> layoutS s y sh
1239 let y = state.y + incr
in
1241 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1246 let tilex = l
.pagex
mod conf.tilew
in
1247 let tiley = l
.pagey mod conf.tileh
in
1249 let col = l
.pagex
/ conf.tilew
in
1250 let row = l
.pagey / conf.tileh
in
1252 let rec rowloop row y0 dispy h
=
1256 let dh = conf.tileh
- y0 in
1257 let dh = min h
dh in
1258 let rec colloop col x0 dispx w
=
1262 let dw = conf.tilew
- x0 in
1263 let dw = min w
dw in
1265 f col row dispx dispy
x0 y0 dw dh;
1266 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1269 colloop col tilex l
.pagedispx l
.pagevw;
1270 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1273 if l
.pagevw > 0 && l
.pagevh > 0
1274 then rowloop row tiley l
.pagedispy l
.pagevh;
1277 let gettileopaque l
col row =
1279 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1281 try Some
(Hashtbl.find
state.tilemap
key)
1282 with Not_found
-> None
1285 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1286 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1287 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1290 let drawtiles l color
=
1292 let f col row x y tilex tiley w h
=
1293 match gettileopaque l
col row with
1294 | Some
(opaque
, _
, t
) ->
1295 let params = x, y, w
, h
, tilex, tiley in
1299 GlFunc.blend_func `zero `one_minus_src_color
;
1301 drawtile
params opaque
;
1303 then Gl.disable `blend
;
1306 let s = Printf.sprintf
1310 let w = measurestr
fstate.fontsize
s in
1311 GlMisc.push_attrib
[`current
];
1312 GlDraw.color
(0.0, 0.0, 0.0);
1314 (float (x-2), float (y-2))
1315 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1316 GlDraw.color
(1.0, 1.0, 1.0);
1317 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1318 GlMisc.pop_attrib
();
1323 let lw = conf.winw
- state.scrollw
- x in
1326 let lh = conf.winh
- y in
1329 begin match state.texid
with
1331 Gl.enable `texture_2d
;
1332 GlTex.bind_texture `texture_2d id
;
1335 and x1 = float (x+w)
1336 and y1 = float (y+h
) in
1338 let tw = float w /. 64.0
1339 and th
= float h
/. 64.0 in
1340 let tx0 = float tilex /. 64.0
1341 and ty0
= float tiley /. 64.0 in
1343 and ty1
= ty0
+. th
in
1344 GlDraw.begins `quads
;
1345 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1346 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1347 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1348 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1351 Gl.disable `texture_2d
;
1353 GlDraw.color
(1.0, 1.0, 1.0);
1356 (float (x+w), float (y+h
));
1358 if w > 128 && h
> fstate.fontsize
+ 10
1360 GlDraw.color
(0.0, 0.0, 0.0);
1363 then (col*conf.tilew
, row*conf.tileh
)
1366 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r
;
1373 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1375 let tilevisible1 l
x y =
1377 and ax1
= l
.pagex
+ l
.pagevw
1379 and ay1
= l
.pagey + l
.pagevh in
1383 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1384 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1386 let rx0 = max
ax0 bx0
1387 and ry0
= max ay0 by0
1388 and rx1
= min ax1
bx1
1389 and ry1
= min ay1 by1
in
1391 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1392 nonemptyintersection
1395 let tilevisible layout n x y =
1396 let rec findpageinlayout m
= function
1397 | l
:: rest
when l
.pageno = n ->
1398 tilevisible1 l
x y || (
1399 match conf.columns
with
1400 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1403 | _
:: rest
-> findpageinlayout 0 rest
1406 findpageinlayout 0 layout;
1409 let tileready l
x y =
1410 tilevisible1 l
x y &&
1411 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1414 let tilepage n p
layout =
1415 let rec loop = function
1419 let f col row _ _ _ _ _ _
=
1420 if state.currently
= Idle
1422 match gettileopaque l
col row with
1425 let x = col*conf.tilew
1426 and y = row*conf.tileh
in
1428 let w = l
.pagew
- x in
1432 let h = l
.pageh
- y in
1435 wcmd "tile %s %d %d %d %d" p
x y w h;
1438 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1439 conf.tilew
, conf.tileh
1448 if nogeomcmds state.geomcmds
1454 match conf.columns
with
1456 | Cmulti
(_
, b) -> b
1457 | Csplit
(_
, b) -> b
1459 let rec bsearch nmin nmax
=
1463 let n = (nmax
+ nmin
) / 2 in
1464 let _, _, vy
, (_, h, _, _) = b.(n) in
1466 if conf.presentation
1468 let ips = calcips h in
1469 let y0 = vy
- ips in
1470 let y1 = vy
+ h + ips in
1474 then 0, vy
+ h + conf.interpagespace
1476 let y0 = vy
- conf.interpagespace
in
1480 if y >= y0 && y < y1
1484 then bsearch (n+1) nmax
1485 else bsearch nmin
(n-1)
1488 let r = bsearch 0 (state.pagecount
-1) in
1492 let preloadlayout y =
1493 let y = if y < conf.winh
then 0 else y - conf.winh
in
1494 let h = conf.winh
*3 in
1499 let rec loop pages
=
1500 if state.currently
!= Idle
1505 begin match getopaque l
.pageno with
1507 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1508 state.currently
<- Loading
(l
, state.gen
);
1510 tilepage l
.pageno opaque pages
;
1515 if nogeomcmds state.geomcmds
1521 if conf.preload && state.currently
= Idle
1522 then load (preloadlayout state.y);
1525 let layoutready layout =
1526 let rec fold all ls
=
1527 all
&& match ls
with
1529 let seen = ref false in
1530 let allvisible = ref true in
1531 let foo col row _ _ _ _ _ _ =
1533 allvisible := !allvisible &&
1534 begin match gettileopaque l
col row with
1540 fold (!seen && !allvisible) rest
1543 let alltilesvisible = fold true layout in
1548 let y = bound y 0 state.maxy
in
1549 let y, layout, proceed
=
1550 match conf.maxwait
with
1551 | Some time
when state.ghyll
== noghyll ->
1552 begin match state.throttle
with
1554 let layout = layout y conf.winh
in
1555 let ready = layoutready layout in
1559 state.throttle
<- Some
(layout, y, now ());
1561 else G.postRedisplay "gotoy showall (None)";
1563 | Some
(_, _, started
) ->
1564 let dt = now () -. started
in
1567 state.throttle
<- None
;
1568 let layout = layout y conf.winh
in
1570 G.postRedisplay "maxwait";
1577 let layout = layout y conf.winh
in
1578 if true || layoutready layout
1579 then G.postRedisplay "gotoy ready";
1585 state.layout <- layout;
1586 begin match state.mode
with
1587 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1588 let rec loop = function
1590 state.mode
<- LinkNav
(Ltgendir
0)
1591 | l
:: _ when l
.pageno = pageno ->
1592 begin match getopaque pageno with
1594 state.mode
<- LinkNav
(Ltgendir
0)
1596 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1597 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1598 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1599 then state.mode
<- LinkNav
(Ltgendir
0)
1601 | _ :: rest
-> loop rest
1606 begin match state.mode
with
1607 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1608 if not
(pagevisible layout pageno)
1610 match state.layout with
1613 state.mode
<- Birdseye
(
1614 conf, leftx
, l
.pageno, hooverpageno
, anchor
1617 | LinkNav
(Ltgendir dir
as lt
) ->
1619 let rec loop = function
1622 match getopaque l
.pageno with
1628 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1630 if dir
> 0 then LDfirst
else LDlast
1636 | Lnotfound
-> loop rest
1638 showlinktype (getlink opaque
n);
1639 Ltexact
(l
.pageno, n)
1643 state.mode
<- LinkNav
linknav
1648 state.ghyll
<- noghyll;
1651 let mx, my
= state.mpos
in
1656 let conttiling pageno opaque
=
1657 tilepage pageno opaque
1658 (if conf.preload then preloadlayout state.y else state.layout)
1661 let gotoy_and_clear_text y =
1662 if not
conf.verbose
then state.text <- "";
1668 let coloff = l
.pagecol
* l
.pageh
in
1669 float (l
.pagey + coloff) /. float l
.pageh
1676 if conf.presentation
1677 then float l
.pagedispy /. float (calcips l
.pageh
)
1678 else float l
.pagedispy /. float conf.interpagespace
1680 (l
.pageno, top, dtop)
1684 match state.layout with
1685 | l
:: _ -> getanchor1 l
1687 let n = page_of_y state.y in
1688 let y, h = getpageyh n in
1689 let dy = y - state.y in
1691 if conf.presentation
1693 let ips = calcips h in
1694 float (dy + ips) /. float ips
1696 float dy /. float conf.interpagespace
1701 let getanchory (n, top, dtop) =
1702 let y, h = getpageyh n in
1703 if conf.presentation
1705 let ips = calcips h in
1706 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1708 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1711 let gotoanchor anchor
=
1712 gotoy (getanchory anchor
);
1716 cbput state.hists
.nav
(getanchor ());
1720 let anchor = cbgetc state.hists
.nav dir
in
1725 let scroll f n a
b =
1726 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1728 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1730 then s (float f /. float a
)
1733 then 1.0 -. s ((float (f-b) /. float (n-b)))
1740 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1741 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1743 let ins = float a
*. iv1
1744 and outs
= float (n-b) *. iv1 in
1746 ins +. outs
+. float ones
1748 let rec set (_N
, _A
, _B
) y sy
=
1749 let sum = summa
1.0 _N _A _B
in
1750 let dy = float (y - sy
) in
1754 then state.ghyll
<- noghyll
1757 let s = scroll n _N _A _B
in
1758 let y1 = y1 +. ((s *. dy) /. sum) in
1759 gotoy_and_clear_text (truncate
y1);
1760 state.ghyll
<- gf (n+1) y1;
1764 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1766 gf 0 (float state.y)
1769 match conf.ghyllscroll
with
1771 gotoy_and_clear_text y
1773 if state.ghyll
== noghyll
1774 then set nab
y state.y
1775 else state.ghyll
(Some
y)
1778 let gotopage n top =
1779 let y, h = getpageyh n in
1780 let y = y + (truncate
(top *. float h)) in
1784 let gotopage1 n top =
1785 let y = getpagey n in
1790 let invalidate s f =
1795 match state.geomcmds
with
1796 | ps
, [] when String.length ps
= 0 ->
1798 state.geomcmds
<- s, [];
1801 state.geomcmds
<- ps
, [s, f];
1803 | ps
, (s'
, _) :: rest
when s'
= s ->
1804 state.geomcmds
<- ps
, ((s, f) :: rest
);
1807 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1810 let opendoc path password
=
1812 state.password
<- password
;
1813 state.gen
<- state.gen
+ 1;
1814 state.docinfo
<- [];
1816 setaalevel
conf.aalevel
;
1817 Wsi.settitle
("llpp " ^
Filename.basename path
);
1818 wcmd "open %s\000%s\000" path password
;
1819 invalidate "reqlayout"
1821 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1825 let c = c *. conf.colorscale
in
1829 let scalecolor2 (r, g
, b) =
1830 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1833 let docolumns = function
1835 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1836 let rec loop pageno pdimno pdim
y ph pdims
=
1837 if pageno = state.pagecount
1840 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1842 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1843 pdimno+1, pdim
, rest
1847 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1849 (if conf.presentation
1850 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1851 else (if pageno = 0 then 0 else calcips h)
1854 a.(pageno) <- (pdimno, x, y, pdim
);
1855 loop (pageno+1) pdimno pdim
(y + h) h pdims
1857 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1858 conf.columns
<- Csingle
a;
1860 | Cmulti
((columns
, coverA
, coverB
), _) ->
1861 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1862 let rec loop pageno pdimno pdim
x y rowh pdims
=
1863 let rec fixrow m
= if m
= pageno then () else
1864 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1867 let y = y + (rowh
- h) / 2 in
1868 a.(m
) <- (pdimno, x, y, pdim
);
1872 if pageno = state.pagecount
1873 then fixrow (((pageno - 1) / columns
) * columns
)
1875 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1877 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1878 pdimno+1, pdim
, rest
1883 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1885 (conf.winw
- state.scrollw
- w) / 2,
1886 y + rowh
+ conf.interpagespace
, h
1889 if (pageno - coverA
) mod columns
= 0
1891 (if conf.multicenter
then
1892 (conf.winw
- state.scrollw
- state.w) / 2 else 0),
1893 y + rowh
+ (if pageno = 0 then 0 else conf.interpagespace
), h
1895 else x, y, max rowh
h
1898 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1899 then fixrow (pageno - columns
);
1900 a.(pageno) <- (pdimno, x, y, pdim
);
1901 let x = x + w + xoff
*2 + conf.interpagespace
in
1902 loop (pageno+1) pdimno pdim
x y rowh' pdims
1904 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1905 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1908 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1909 let rec loop pageno pdimno pdim
y pdims
=
1910 if pageno = state.pagecount
1913 let pdimno, ((_, w, h, _) as pdim
), pdims
=
1915 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1916 pdimno+1, pdim
, rest
1921 let rec loop1 n x y =
1922 if n = c then y else (
1923 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
1924 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
1927 let y = loop1 0 0 y in
1928 loop (pageno+1) pdimno pdim
y pdims
1930 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1931 conf.columns
<- Csplit
(c, a);
1935 docolumns conf.columns
;
1936 state.maxy
<- calcheight ();
1938 if state.w <= conf.winw
- state.scrollw
1942 match state.mode
with
1943 | Birdseye
(_, _, pageno, _, _) ->
1944 let y, h = getpageyh pageno in
1945 let top = (conf.winh
- h) / 2 in
1946 gotoy (max
0 (y - top))
1947 | _ -> gotoanchor state.anchor
1951 GlDraw.viewport
0 0 w h;
1952 let firsttime = state.geomcmds
== firstgeomcmds in
1953 if not
firsttime && nogeomcmds state.geomcmds
1954 then state.anchor <- getanchor ();
1957 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1960 setfontsize fstate.fontsize
;
1961 GlMat.mode `modelview
;
1962 GlMat.load_identity
();
1964 GlMat.mode `projection
;
1965 GlMat.load_identity
();
1966 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1967 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1968 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1973 else float state.x /. float state.w
1975 invalidate "geometry"
1979 then state.x <- truncate
(relx *. float w);
1981 match conf.columns
with
1983 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
1984 | Csplit
(c, _) -> w * c
1986 wcmd "geometry %d %d" w h);
1990 let len = String.length
state.text in
1993 match state.mode
with
1996 let h, _, _ = state.uioh#scrollpw
in
2002 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2003 (x+.w, float (conf.winh
- hscrollh))
2006 let w = float (conf.winw
- state.scrollw
- 1) in
2007 if state.progress
>= 0.0 && state.progress
< 1.0
2009 GlDraw.color
(0.3, 0.3, 0.3);
2010 let w1 = w *. state.progress
in
2012 GlDraw.color
(0.0, 0.0, 0.0);
2016 GlDraw.color
(0.0, 0.0, 0.0);
2020 GlDraw.color
(1.0, 1.0, 1.0);
2021 drawstring fstate.fontsize
2022 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2025 match state.mode
with
2026 | Textentry
((prefix
, text, _, _, _, _), _) ->
2030 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2032 Printf.sprintf
"%s%s_" prefix
text
2041 if not
(istextentry state.mode
)
2043 let s1 = "(press 'e' to review error messasges)" in
2044 if String.length
s > 0 then s ^
" " ^
s1 else s1
2049 if String.length
s > 0
2054 let len = Queue.length
state.tilelru
in
2056 match state.throttle
with
2059 then preloadlayout state.y
2061 | Some
(layout, _, _) ->
2065 if state.memused
<= conf.memlimit
2070 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2071 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2072 let (_, pw, ph
, _) = getpagedim n in
2075 && colorspace
= conf.colorspace
2076 && angle
= conf.angle
2080 let x = col*conf.tilew
2081 and y = row*conf.tileh
in
2082 tilevisible (Lazy.force_val
layout) n x y
2084 then Queue.push lruitem
state.tilelru
2086 wcmd "freetile %s" p
;
2087 state.memused
<- state.memused
- s;
2088 state.uioh#infochanged Memused
;
2089 Hashtbl.remove
state.tilemap k
;
2098 Queue.iter
(fun (k
, p
, s) ->
2099 wcmd "freetile %s" p
;
2100 state.memused
<- state.memused
- s;
2101 state.uioh#infochanged Memused
;
2102 Hashtbl.remove
state.tilemap k
;
2104 Queue.clear
state.tilelru
;
2108 let logcurrently = function
2109 | Idle
-> dolog "Idle"
2110 | Loading
(l
, gen
) ->
2111 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2112 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2114 "Tiling %d[%d,%d] page=%s cs=%s angle"
2115 l
.pageno col row pageopaque
2116 (colorspace_to_string colorspace
)
2118 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2119 angle gen
conf.angle
state.gen
2121 conf.tilew
conf.tileh
2128 (* dolog "%S" cmds; *)
2131 try String.index cmds ' '
2132 with Not_found
-> -1
2137 let l = String.length cmds
in
2138 let op = String.sub cmds
0 spacepos in
2140 if l - spacepos < 2 then ""
2141 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2146 state.uioh#infochanged Pdim
;
2150 state.rects
<- state.rects1
;
2151 G.postRedisplay "clearrects";
2155 try Scanf.sscanf
args "%u" (fun n -> n)
2157 dolog "error processing 'continue' %S: %s"
2158 cmds
(Printexc.to_string exn
);
2161 state.pagecount
<- n;
2162 begin match state.currently
with
2164 state.currently
<- Idle
;
2165 state.outlines
<- Array.of_list
(List.rev
l)
2169 let cur, cmds
= state.geomcmds
in
2170 if String.length
cur = 0
2171 then failwith
"umpossible";
2173 begin match List.rev cmds
with
2175 state.geomcmds
<- "", [];
2179 state.geomcmds
<- s, List.rev rest
;
2181 if conf.maxwait
= None
2182 then G.postRedisplay "continue";
2192 then showtext ' '
args
2195 let progress, text =
2197 Scanf.sscanf
args "%f %n"
2199 f, String.sub
args pos
(String.length
args - pos
))
2201 dolog "error processing 'progress' %S: %s"
2202 cmds
(Printexc.to_string exn
);
2206 state.progress <- progress;
2207 G.postRedisplay "progress"
2210 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2212 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2213 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2214 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2216 dolog "error processing 'firstmatch' %S: %s"
2217 cmds
(Printexc.to_string exn
);
2220 let y = (getpagey pageno) + truncate
y0 in
2223 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2226 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2228 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2229 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2230 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2232 dolog "error processing 'match' %S: %s"
2233 cmds
(Printexc.to_string exn
);
2237 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2242 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2244 dolog "error processing 'page' %S: %s"
2245 cmds
(Printexc.to_string exn
);
2248 begin match state.currently
with
2249 | Loading
(l, gen
) ->
2250 vlog "page %d took %f sec" l.pageno t
;
2251 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2252 begin match state.throttle
with
2254 let preloadedpages =
2256 then preloadlayout state.y
2261 Set.Make
(struct type t
= int let compare = (-) end) in
2263 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2264 IntSet.empty
preloadedpages
2267 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2268 if not
(IntSet.mem
pageno set)
2270 wcmd "freepage %s" opaque
;
2276 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2279 state.currently
<- Idle
;
2282 tilepage l.pageno pageopaque state.layout;
2284 load preloadedpages;
2285 if pagevisible state.layout l.pageno
2286 && layoutready state.layout
2287 then G.postRedisplay "page";
2290 | Some
(layout, _, _) ->
2291 state.currently
<- Idle
;
2292 tilepage l.pageno pageopaque layout;
2297 dolog "Inconsistent loading state";
2298 logcurrently state.currently
;
2303 let (x, y, opaque
, size
, t
) =
2305 Scanf.sscanf
args "%u %u %s %u %f"
2306 (fun x y p size t
-> (x, y, p
, size
, t
))
2308 dolog "error processing 'tile' %S: %s"
2309 cmds
(Printexc.to_string exn
);
2312 begin match state.currently
with
2313 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2314 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2316 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2318 wcmd "freetile %s" opaque
;
2319 state.currently
<- Idle
;
2323 puttileopaque l col row gen cs angle opaque size t
;
2324 state.memused
<- state.memused
+ size
;
2325 state.uioh#infochanged Memused
;
2327 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2328 opaque
, size
) state.tilelru
;
2331 match state.throttle
with
2332 | None
-> state.layout
2333 | Some
(layout, _, _) -> layout
2336 state.currently
<- Idle
;
2338 && conf.colorspace
= cs
2339 && conf.angle
= angle
2340 && tilevisible layout l.pageno x y
2341 then conttiling l.pageno pageopaque;
2343 begin match state.throttle
with
2345 preload state.layout;
2347 && conf.colorspace
= cs
2348 && conf.angle
= angle
2349 && tilevisible state.layout l.pageno x y
2350 then G.postRedisplay "tile nothrottle";
2352 | Some
(layout, y, _) ->
2353 let ready = layoutready layout in
2357 state.layout <- layout;
2358 state.throttle
<- None
;
2359 G.postRedisplay "throttle";
2366 dolog "Inconsistent tiling state";
2367 logcurrently state.currently
;
2374 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2376 dolog "error processing 'pdim' %S: %s"
2377 cmds
(Printexc.to_string exn
);
2380 state.uioh#infochanged Pdim
;
2381 state.pdims
<- pdim :: state.pdims
2384 let (l, n, t
, h, pos
) =
2386 Scanf.sscanf
args "%u %u %d %u %n"
2387 (fun l n t
h pos
-> l, n, t
, h, pos
)
2389 dolog "error processing 'o' %S: %s"
2390 cmds
(Printexc.to_string exn
);
2393 let s = String.sub
args pos
(String.length
args - pos
) in
2394 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2395 begin match state.currently
with
2396 | Outlining outlines
->
2397 state.currently
<- Outlining
(outline :: outlines
)
2399 state.currently
<- Outlining
[outline]
2401 dolog "invalid outlining state";
2402 logcurrently currently
2406 state.docinfo
<- (1, args) :: state.docinfo
2409 state.uioh#infochanged Docinfo
;
2410 state.docinfo
<- List.rev
state.docinfo
2413 dolog "unknown cmd `%S'" cmds
2418 let action = function
2419 | HCprev
-> cbget cb ~
-1
2420 | HCnext
-> cbget cb
1
2421 | HCfirst
-> cbget cb ~
-(cb
.rc)
2422 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2423 and cancel
() = cb
.rc <- rc
2427 let search pattern forward
=
2428 if String.length pattern
> 0
2431 match state.layout with
2434 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2436 wcmd "search %d %d %d %d,%s\000"
2437 (btod conf.icase
) pn py
(btod forward
) pattern
;
2440 let intentry text key =
2442 if key >= 32 && key < 127
2448 let text = addchar text c in
2452 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2456 let linknentry text key =
2458 if key >= 32 && key < 127
2464 let text = addchar text c in
2468 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2473 if String.length
s > 0
2476 let l = String.length
s in
2477 let rec loop pos
n = if pos
= l then n else
2478 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2479 loop (pos
+1) (n*26 + m)
2482 let rec loop n = function
2485 match getopaque l.pageno with
2486 | None
-> loop n rest
2488 let m = getlinkcount opaque
in
2491 let under = getlink opaque
n in
2494 else loop (n-m) rest
2496 loop n state.layout;
2500 let textentry text key =
2501 if key land 0xff00 = 0xff00
2503 else TEcont
(text ^
Wsi.toutf8
key)
2506 let reqlayout angle proportional
=
2507 match state.throttle
with
2509 if nogeomcmds state.geomcmds
2510 then state.anchor <- getanchor ();
2511 conf.angle
<- angle
mod 360;
2514 match state.mode
with
2515 | LinkNav
_ -> state.mode
<- View
2518 conf.proportional
<- proportional
;
2519 invalidate "reqlayout"
2520 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2524 let settrim trimmargins trimfuzz
=
2525 if nogeomcmds state.geomcmds
2526 then state.anchor <- getanchor ();
2527 conf.trimmargins
<- trimmargins
;
2528 conf.trimfuzz
<- trimfuzz
;
2529 let x0, y0, x1, y1 = trimfuzz
in
2530 invalidate "settrim"
2532 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2533 Hashtbl.iter
(fun _ opaque
->
2534 wcmd "freepage %s" opaque
;
2536 Hashtbl.clear
state.pagemap
;
2540 match state.throttle
with
2542 let zoom = max
0.01 zoom in
2543 if zoom <> conf.zoom
2545 state.prevzoom
<- conf.zoom;
2547 reshape conf.winw
conf.winh
;
2548 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2551 | Some
(layout, y, started
) ->
2553 match conf.maxwait
with
2557 let dt = now () -. started
in
2565 let setcolumns mode columns coverA coverB
=
2566 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2570 then showtext '
!'
"split mode doesn't work in bird's eye"
2572 conf.columns
<- Csplit
(-columns
, [||]);
2580 conf.columns
<- Csingle
[||];
2585 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2589 reshape conf.winw
conf.winh
;
2592 let enterbirdseye () =
2593 let zoom = float conf.thumbw
/. float conf.winw
in
2594 let birdseyepageno =
2595 let cy = conf.winh
/ 2 in
2599 let rec fold best
= function
2602 let d = cy - (l.pagedispy + l.pagevh/2)
2603 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2604 if abs
d < abs dbest
2611 state.mode
<- Birdseye
(
2612 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2615 conf.presentation
<- false;
2616 conf.interpagespace
<- 10;
2617 conf.hlinks
<- false;
2619 state.mstate
<- Mnone
;
2620 conf.maxwait
<- None
;
2622 match conf.beyecolumns
with
2625 Cmulti
((c, 0, 0), [||])
2626 | None
-> Csingle
[||]
2628 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2631 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2636 reshape conf.winw
conf.winh
;
2639 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2641 conf.zoom <- c.zoom;
2642 conf.presentation
<- c.presentation
;
2643 conf.interpagespace
<- c.interpagespace
;
2644 conf.maxwait
<- c.maxwait
;
2645 conf.hlinks
<- c.hlinks
;
2646 conf.beyecolumns
<- (
2647 match conf.columns
with
2648 | Cmulti
((c, _, _), _) -> Some
c
2650 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2653 match c.columns
with
2654 | Cmulti
(c, _) -> Cmulti
(c, [||])
2655 | Csingle
_ -> Csingle
[||]
2656 | Csplit
(c, _) -> Csplit
(c, [||])
2661 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2664 reshape conf.winw
conf.winh
;
2665 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2668 let togglebirdseye () =
2669 match state.mode
with
2670 | Birdseye vals
-> leavebirdseye vals
true
2671 | View
-> enterbirdseye ()
2675 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2676 let pageno = max
0 (pageno - incr
) in
2677 let rec loop = function
2678 | [] -> gotopage1 pageno 0
2679 | l :: _ when l.pageno = pageno ->
2680 if l.pagedispy >= 0 && l.pagey = 0
2681 then G.postRedisplay "upbirdseye"
2682 else gotopage1 pageno 0
2683 | _ :: rest
-> loop rest
2686 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2689 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2690 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2691 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2692 let rec loop = function
2694 let y, h = getpageyh pageno in
2695 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2697 | l :: _ when l.pageno = pageno ->
2698 if l.pagevh != l.pageh
2699 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2700 else G.postRedisplay "downbirdseye"
2701 | _ :: rest
-> loop rest
2706 let optentry mode
_ key =
2707 let btos b = if b then "on" else "off" in
2708 if key >= 32 && key < 127
2710 let c = Char.chr
key in
2714 try conf.scrollstep
<- int_of_string
s with exc
->
2715 state.text <- Printf.sprintf
"bad integer `%s': %s"
2716 s (Printexc.to_string exc
)
2718 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2723 conf.autoscrollstep
<- int_of_string
s;
2724 if state.autoscroll
<> None
2725 then state.autoscroll
<- Some
conf.autoscrollstep
2727 state.text <- Printf.sprintf
"bad integer `%s': %s"
2728 s (Printexc.to_string exc
)
2730 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2735 let n, a, b = multicolumns_of_string s in
2736 setcolumns mode
n a b;
2738 state.text <- Printf.sprintf
"bad columns `%s': %s"
2739 s (Printexc.to_string exc
)
2741 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2746 let zoom = float (int_of_string
s) /. 100.0 in
2749 state.text <- Printf.sprintf
"bad integer `%s': %s"
2750 s (Printexc.to_string exc
)
2752 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2757 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2759 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2760 begin match mode
with
2762 leavebirdseye beye
false;
2767 state.text <- Printf.sprintf
"bad integer `%s': %s"
2768 s (Printexc.to_string exc
)
2770 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2775 Some
(int_of_string
s)
2777 state.text <- Printf.sprintf
"bad integer `%s': %s"
2778 s (Printexc.to_string exc
);
2781 | Some angle
-> reqlayout angle
conf.proportional
2784 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2787 conf.icase
<- not
conf.icase
;
2788 TEdone
("case insensitive search " ^
(btos conf.icase
))
2791 conf.preload <- not
conf.preload;
2793 TEdone
("preload " ^
(btos conf.preload))
2796 conf.verbose
<- not
conf.verbose
;
2797 TEdone
("verbose " ^
(btos conf.verbose
))
2800 conf.debug
<- not
conf.debug
;
2801 TEdone
("debug " ^
(btos conf.debug
))
2804 conf.maxhfit
<- not
conf.maxhfit
;
2805 state.maxy
<- calcheight ();
2806 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2809 conf.crophack
<- not
conf.crophack
;
2810 TEdone
("crophack " ^
btos conf.crophack
)
2814 match conf.maxwait
with
2816 conf.maxwait
<- Some infinity
;
2817 "always wait for page to complete"
2819 conf.maxwait
<- None
;
2820 "show placeholder if page is not ready"
2825 conf.underinfo
<- not
conf.underinfo
;
2826 TEdone
("underinfo " ^
btos conf.underinfo
)
2829 conf.savebmarks
<- not
conf.savebmarks
;
2830 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2836 match state.layout with
2841 conf.interpagespace
<- int_of_string
s;
2842 docolumns conf.columns
;
2843 state.maxy
<- calcheight ();
2844 let y = getpagey pageno in
2847 state.text <- Printf.sprintf
"bad integer `%s': %s"
2848 s (Printexc.to_string exc
)
2850 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2853 reqlayout conf.angle
(not
conf.proportional
);
2854 TEdone
("proportional display " ^
btos conf.proportional
)
2857 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2858 TEdone
("trim margins " ^
btos conf.trimmargins
)
2861 conf.invert
<- not
conf.invert
;
2862 TEdone
("invert colors " ^
btos conf.invert
)
2866 cbput state.hists
.sel
s;
2869 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2870 textentry, ondone, true)
2873 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2879 class type lvsource
= object
2880 method getitemcount
: int
2881 method getitem
: int -> (string * int)
2882 method hasaction
: int -> bool
2891 method getactive
: int
2892 method getfirst
: int
2893 method getqsearch
: string
2894 method setqsearch
: string -> unit
2898 class virtual lvsourcebase
= object
2899 val mutable m_active
= 0
2900 val mutable m_first
= 0
2901 val mutable m_qsearch
= ""
2902 val mutable m_pan
= 0
2903 method getactive
= m_active
2904 method getfirst
= m_first
2905 method getqsearch
= m_qsearch
2906 method getpan
= m_pan
2907 method setqsearch
s = m_qsearch
<- s
2910 let withoutlastutf8 s =
2911 let len = String.length
s in
2919 let b = Char.code
s.[pos
] in
2920 if b land 0b110000 = 0b11000000
2925 if Char.code
s.[len-1] land 0x80 = 0
2929 String.sub
s 0 first;
2932 let textentrykeyboard
2933 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2935 state.mode
<- Textentry
(te
, onleave
);
2938 G.postRedisplay "textentrykeyboard enttext";
2940 let histaction cmd
=
2943 | Some
(action, _) ->
2944 state.mode
<- Textentry
(
2945 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2947 G.postRedisplay "textentry histaction"
2950 | 0xff08 -> (* backspace *)
2951 let s = withoutlastutf8 text in
2952 let len = String.length
s in
2953 if cancelonempty
&& len = 0
2956 G.postRedisplay "textentrykeyboard after cancel";
2959 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2965 G.postRedisplay "textentrykeyboard after confirm"
2967 | 0xff52 -> histaction HCprev
2968 | 0xff54 -> histaction HCnext
2969 | 0xff50 -> histaction HCfirst
2970 | 0xff57 -> histaction HClast
2972 | 0xff1b -> (* escape*)
2973 if String.length
text = 0
2975 begin match opthist
with
2977 | Some
(_, onhistcancel
) -> onhistcancel
()
2981 G.postRedisplay "textentrykeyboard after cancel2"
2984 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
2987 | 0xff9f | 0xffff -> () (* delete *)
2989 | _ when key != 0 && key land 0xff00 != 0xff00 ->
2990 begin match onkey
text key with
2994 G.postRedisplay "textentrykeyboard after confirm2";
2997 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3001 G.postRedisplay "textentrykeyboard after cancel3"
3004 state.mode
<- Textentry
(te
, onleave
);
3005 G.postRedisplay "textentrykeyboard switch";
3009 vlog "unhandled key %s" (Wsi.keyname
key)
3012 let firstof first active
=
3013 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3014 then max
0 (active
- (fstate.maxrows
/2))
3018 let calcfirst first active
=
3021 let rows = active
- first in
3022 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3026 let scrollph y maxy
=
3027 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3028 let sh = float conf.winh
/. sh in
3029 let sh = max
sh (float conf.scrollh
) in
3034 else float y /. float maxy
3036 let position = (float conf.winh
-. sh) *. percent in
3039 if position +. sh > float conf.winh
3040 then float conf.winh
-. sh
3046 let coe s = (s :> uioh
);;
3048 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3050 val m_pan
= source#getpan
3051 val m_first
= source#getfirst
3052 val m_active
= source#getactive
3053 val m_qsearch
= source#getqsearch
3054 val m_prev_uioh
= state.uioh
3056 method private elemunder
y =
3057 let n = y / (fstate.fontsize
+1) in
3058 if m_first
+ n < source#getitemcount
3060 if source#hasaction
(m_first
+ n)
3061 then Some
(m_first
+ n)
3068 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3069 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3070 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3071 GlDraw.color
(1., 1., 1.);
3072 Gl.enable `texture_2d
;
3073 let fs = fstate.fontsize
in
3075 let ww = fstate.wwidth
in
3076 let tabw = 30.0*.ww in
3077 let itemcount = source#getitemcount
in
3079 if (row - m_first
) * nfs > conf.winh
3082 if row >= 0 && row < itemcount
3084 let (s, level
) = source#getitem
row in
3085 let y = (row - m_first
) * nfs in
3086 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3089 Gl.disable `texture_2d
;
3090 GlDraw.polygon_mode `both `line
;
3091 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3092 GlDraw.rect (1., float (y + 1))
3093 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3094 GlDraw.polygon_mode `both `fill
;
3095 GlDraw.color
(1., 1., 1.);
3096 Gl.enable `texture_2d
;
3099 let drawtabularstring s =
3100 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3103 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3106 let len = String.length
s - tabpos - 1 in
3107 let s1 = String.sub
s 0 tabpos
3108 and s2
= String.sub
s (tabpos + 1) len in
3109 let nx = drawstr x s1 in
3111 let x = x +. (max
tabw sw) in
3118 let _ = drawtabularstring s in
3125 Gl.disable `texture_2d
;
3127 method updownlevel incr
=
3128 let len = source#getitemcount
in
3130 if m_active
>= 0 && m_active
< len
3131 then snd
(source#getitem m_active
)
3135 if i
= len then i
-1 else if i
= -1 then 0 else
3136 let _, l = source#getitem i
in
3137 if l != curlevel then i
else flow (i
+incr
)
3139 let active = flow m_active
in
3140 let first = calcfirst m_first
active in
3141 G.postRedisplay "outline updownlevel";
3142 {< m_active
= active; m_first
= first >}
3144 method private key1
key mask
=
3145 let set1 active first qsearch
=
3146 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3148 let search active pattern incr
=
3151 if n >= 0 && n < source#getitemcount
3153 let s, _ = source#getitem
n in
3155 (try ignore
(Str.search_forward
re s 0); true
3156 with Not_found
-> false)
3158 else loop (n + incr
)
3165 let re = Str.regexp_case_fold pattern
in
3171 let itemcount = source#getitemcount
in
3172 let find start incr
=
3174 if i
= -1 || i
= itemcount
3177 if source#hasaction i
3179 else find (i
+ incr
)
3184 let set active first =
3185 let first = bound first 0 (itemcount - fstate.maxrows
) in
3187 coe {< m_active
= active; m_first
= first >}
3190 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3192 let incr1 = if incr
> 0 then 1 else -1 in
3193 if isvisible m_first m_active
3196 let next = m_active
+ incr
in
3198 if next < 0 || next >= itemcount
3200 else find next incr1
3202 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3208 let first = m_first
+ incr
in
3209 let first = bound first 0 (itemcount - 1) in
3211 let next = m_active
+ incr
in
3212 let next = bound next 0 (itemcount - 1) in
3215 let active = if next = -1 then m_active
else next in
3218 let first = min
next m_first
in
3220 if abs
(next - first) > fstate.maxrows
3226 let first = m_first
+ incr
in
3227 let first = bound first 0 (itemcount - 1) in
3229 let next = m_active
+ incr
in
3230 let next = bound next 0 (itemcount - 1) in
3231 let next = find next incr1 in
3233 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3235 let active = if m_active
= -1 then next else m_active
in
3240 if isvisible first active
3246 G.postRedisplay "listview navigate";
3250 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3251 let incr = if key = 0x72 then -1 else 1 in
3253 match search (m_active
+ incr) m_qsearch
incr with
3255 state.text <- m_qsearch ^
" [not found]";
3258 state.text <- m_qsearch
;
3259 active, firstof m_first
active
3261 G.postRedisplay "listview ctrl-r/s";
3262 set1 active first m_qsearch
;
3264 | 0xff08 -> (* backspace *)
3265 if String.length m_qsearch
= 0
3268 let qsearch = withoutlastutf8 m_qsearch
in
3269 let len = String.length
qsearch in
3273 G.postRedisplay "listview empty qsearch";
3274 set1 m_active m_first
"";
3278 match search m_active
qsearch ~
-1 with
3280 state.text <- qsearch ^
" [not found]";
3283 state.text <- qsearch;
3284 active, firstof m_first
active
3286 G.postRedisplay "listview backspace qsearch";
3287 set1 active first qsearch
3290 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3291 let pattern = m_qsearch ^
Wsi.toutf8
key in
3293 match search m_active
pattern 1 with
3295 state.text <- pattern ^
" [not found]";
3298 state.text <- pattern;
3299 active, firstof m_first
active
3301 G.postRedisplay "listview qsearch add";
3302 set1 active first pattern;
3304 | 0xff1b -> (* escape *)
3306 if String.length m_qsearch
= 0
3308 G.postRedisplay "list view escape";
3311 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3313 | None
-> m_prev_uioh
3318 G.postRedisplay "list view kill qsearch";
3319 source#setqsearch
"";
3320 coe {< m_qsearch
= "" >}
3323 | 0xff0d -> (* return *)
3325 let self = {< m_qsearch
= "" >} in
3326 source#setqsearch
"";
3328 G.postRedisplay "listview enter";
3329 if m_active
>= 0 && m_active
< source#getitemcount
3331 source#exit
(coe self) false m_active m_first m_pan
"";
3334 source#exit
(coe self) true m_active m_first m_pan
"";
3337 begin match opt with
3338 | None
-> m_prev_uioh
3342 | 0xff9f | 0xffff -> (* delete *)
3345 | 0xff52 -> navigate ~
-1 (* up *)
3346 | 0xff54 -> navigate 1 (* down *)
3347 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3348 | 0xff56 -> navigate fstate.maxrows
(* next *)
3350 | 0xff53 -> (* right *)
3352 G.postRedisplay "listview right";
3353 coe {< m_pan
= m_pan
- 1 >}
3355 | 0xff51 -> (* left *)
3357 G.postRedisplay "listview left";
3358 coe {< m_pan
= m_pan
+ 1 >}
3360 | 0xff50 -> (* home *)
3361 let active = find 0 1 in
3362 G.postRedisplay "listview home";
3365 | 0xff57 -> (* end *)
3366 let first = max
0 (itemcount - fstate.maxrows
) in
3367 let active = find (itemcount - 1) ~
-1 in
3368 G.postRedisplay "listview end";
3371 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3375 dolog "listview unknown key %#x" key; coe self
3377 method key key mask
=
3378 match state.mode
with
3379 | Textentry te
-> textentrykeyboard key mask te
; coe self
3380 | _ -> self#key1
key mask
3382 method button button down
x y _ =
3385 | 1 when x > conf.winw
- conf.scrollbw
->
3386 G.postRedisplay "listview scroll";
3389 let _, position, sh = self#
scrollph in
3390 if y > truncate
position && y < truncate
(position +. sh)
3392 state.mstate
<- Mscrolly
;
3396 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3397 let first = truncate
(s *. float source#getitemcount
) in
3398 let first = min source#getitemcount
first in
3399 Some
(coe {< m_first
= first; m_active
= first >})
3401 state.mstate
<- Mnone
;
3404 | 1 when not down
->
3405 begin match self#elemunder
y with
3407 G.postRedisplay "listview click";
3409 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3413 | n when (n == 4 || n == 5) && not down
->
3414 let len = source#getitemcount
in
3416 if n = 5 && m_first
+ fstate.maxrows
>= len
3420 let first = m_first
+ (if n == 4 then -1 else 1) in
3421 bound first 0 (len - 1)
3423 G.postRedisplay "listview wheel";
3424 Some
(coe {< m_first
= first >})
3425 | n when (n = 6 || n = 7) && not down
->
3426 let inc = m_first
+ (if n = 7 then -1 else 1) in
3427 G.postRedisplay "listview hwheel";
3428 Some
(coe {< m_pan
= m_pan
+ inc >})
3433 | None
-> m_prev_uioh
3437 match state.mstate
with
3439 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3440 let first = truncate
(s *. float source#getitemcount
) in
3441 let first = min source#getitemcount
first in
3442 G.postRedisplay "listview motion";
3443 coe {< m_first
= first; m_active
= first >}
3446 method pmotion
x y =
3447 if x < conf.winw
- conf.scrollbw
3450 match self#elemunder
y with
3451 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3452 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3456 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3461 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3465 method infochanged
_ = ()
3467 method scrollpw
= (0, 0.0, 0.0)
3469 let nfs = fstate.fontsize
+ 1 in
3470 let y = m_first
* nfs in
3471 let itemcount = source#getitemcount
in
3472 let maxi = max
0 (itemcount - fstate.maxrows
) in
3473 let maxy = maxi * nfs in
3474 let p, h = scrollph y maxy in
3477 method modehash
= modehash
3480 class outlinelistview ~source
=
3483 ~source
:(source
:> lvsource
)
3485 ~modehash
:(findkeyhash conf "outline")
3488 method key key mask
=
3489 let calcfirst first active =
3492 let rows = active - first in
3494 if String.length
state.text = 0
3496 else fstate.maxrows - 2
3498 if rows > maxrows then active - maxrows else first
3502 let active = m_active
+ incr in
3503 let active = bound active 0 (source#getitemcount
- 1) in
3504 let first = calcfirst m_first
active in
3505 G.postRedisplay "outline navigate";
3506 coe {< m_active
= active; m_first
= first >}
3508 let ctrl = Wsi.withctrl mask
in
3510 | 110 when ctrl -> (* ctrl-n *)
3511 source#narrow m_qsearch
;
3512 G.postRedisplay "outline ctrl-n";
3513 coe {< m_first
= 0; m_active
= 0 >}
3515 | 117 when ctrl -> (* ctrl-u *)
3517 G.postRedisplay "outline ctrl-u";
3519 coe {< m_first
= 0; m_active
= 0 >}
3521 | 108 when ctrl -> (* ctrl-l *)
3522 let first = m_active
- (fstate.maxrows / 2) in
3523 G.postRedisplay "outline ctrl-l";
3524 coe {< m_first
= first >}
3526 | 0xff9f | 0xffff -> (* delete *)
3527 source#remove m_active
;
3528 G.postRedisplay "outline delete";
3529 let active = max
0 (m_active
-1) in
3530 coe {< m_first
= firstof m_first
active;
3531 m_active
= active >}
3533 | 0xff52 -> navigate ~
-1 (* up *)
3534 | 0xff54 -> navigate 1 (* down *)
3535 | 0xff55 -> (* prior *)
3536 navigate ~
-(fstate.maxrows)
3537 | 0xff56 -> (* next *)
3538 navigate fstate.maxrows
3540 | 0xff53 -> (* [ctrl-]right *)
3544 G.postRedisplay "outline ctrl right";
3545 {< m_pan
= m_pan
+ 1 >}
3547 else self#updownlevel
1
3551 | 0xff51 -> (* [ctrl-]left *)
3555 G.postRedisplay "outline ctrl left";
3556 {< m_pan
= m_pan
- 1 >}
3558 else self#updownlevel ~
-1
3562 | 0xff50 -> (* home *)
3563 G.postRedisplay "outline home";
3564 coe {< m_first
= 0; m_active
= 0 >}
3566 | 0xff57 -> (* end *)
3567 let active = source#getitemcount
- 1 in
3568 let first = max
0 (active - fstate.maxrows) in
3569 G.postRedisplay "outline end";
3570 coe {< m_active
= active; m_first
= first >}
3572 | _ -> super#
key key mask
3575 let outlinesource usebookmarks
=
3578 inherit lvsourcebase
3579 val mutable m_items
= empty
3580 val mutable m_orig_items
= empty
3581 val mutable m_prev_items
= empty
3582 val mutable m_narrow_pattern
= ""
3583 val mutable m_hadremovals
= false
3585 method getitemcount
=
3586 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3589 if n == Array.length m_items
&& m_hadremovals
3591 ("[Confirm removal]", 0)
3593 let s, n, _ = m_items
.(n) in
3596 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3597 ignore
(uioh
, first, qsearch);
3598 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3600 if String.length m_narrow_pattern
= 0
3606 if not
confrimremoval
3608 let _, _, anchor = m_items
.(active) in
3613 state.bookmarks
<- Array.to_list m_items
;
3614 m_orig_items
<- m_items
;
3617 else m_items
<- items;
3621 method hasaction
_ = true
3624 if Array.length m_items
!= Array.length m_orig_items
3625 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3628 method narrow
pattern =
3629 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3633 let rec loop accu n =
3636 m_narrow_pattern
<- pattern;
3637 m_items
<- Array.of_list
accu
3640 let (s, _, _) as o = m_items
.(n) in
3642 if (try ignore
(Str.search_forward
re s 0); true
3643 with Not_found
-> false)
3649 loop [] (Array.length m_items
- 1)
3654 then Array.of_list
state.bookmarks
3657 m_items
<- m_orig_items
3662 if m >= 0 && m < Array.length m_items
3664 m_hadremovals
<- true;
3665 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3666 let n = if n >= m then n+1 else n in
3671 method reset
anchor items =
3672 m_hadremovals
<- false;
3673 if m_orig_items
== empty || m_prev_items
!= items
3675 m_orig_items
<- items;
3676 if String.length m_narrow_pattern
= 0
3677 then m_items
<- items;
3679 m_prev_items
<- items;
3680 let rely = getanchory anchor in
3682 let rec loop n best bestd
=
3683 if n = Array.length m_items
3686 let (_, _, anchor) = m_items
.(n) in
3687 let orely = getanchory anchor in
3688 let d = abs
(orely - rely) in
3691 else loop (n+1) best bestd
3696 m_first
<- firstof m_first
active
3700 let enterselector usebookmarks
=
3701 let source = outlinesource usebookmarks
in
3705 then Array.of_list
state.bookmarks
3708 if Array.length
outlines = 0
3710 showtext ' ' errmsg
;
3713 state.text <- source#greetmsg
;
3714 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3715 let anchor = getanchor () in
3716 source#reset
anchor outlines;
3717 state.uioh
<- coe (new outlinelistview ~
source);
3718 G.postRedisplay "enter selector";
3722 let enteroutlinemode =
3723 let f = enterselector false in
3724 fun ()-> f "Document has no outline";
3727 let enterbookmarkmode =
3728 let f = enterselector true in
3729 fun () -> f "Document has no bookmarks (yet)";
3732 let color_of_string s =
3733 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3734 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3738 let color_to_string (r, g
, b) =
3739 let r = truncate
(r *. 256.0)
3740 and g
= truncate
(g
*. 256.0)
3741 and b = truncate
(b *. 256.0) in
3742 Printf.sprintf
"%d/%d/%d" r g
b
3745 let irect_of_string s =
3746 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3749 let irect_to_string (x0,y0,x1,y1) =
3750 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3753 let makecheckers () =
3754 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3756 converted by Issac Trotts. July 25, 2002 *)
3757 let image_height = 64
3758 and image_width
= 64 in
3762 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3764 for i
= 0 to image_width
- 1 do
3765 for j
= 0 to image_height - 1 do
3766 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3767 (if (i
land 8 ) lxor (j
land 8) = 0
3768 then [|255;255;255|] else [|200;200;200|])
3773 let image = make_image () in
3774 let id = GlTex.gen_texture
() in
3775 GlTex.bind_texture `texture_2d
id;
3776 GlPix.store
(`unpack_alignment
1);
3777 GlTex.image2d
image;
3778 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3781 `mag_filter `nearest
;
3782 `min_filter `nearest
];
3786 let setcheckers enabled
=
3787 match state.texid
with
3789 if enabled
then state.texid
<- Some
(makecheckers ())
3794 GlTex.delete_texture texid
;
3795 state.texid
<- None
;
3799 let int_of_string_with_suffix s =
3800 let l = String.length
s in
3804 let suffix = Char.lowercase
s.[l-1] in
3806 | 'k'
-> String.sub
s 0 (l-1), 10
3807 | '
m'
-> String.sub
s 0 (l-1), 20
3808 | 'g'
-> String.sub
s 0 (l-1), 30
3812 let n = int_of_string
s1 in
3813 let m = n lsl shift
in
3815 then raise
(Failure
"value too large")
3819 let string_with_suffix_of_int n =
3824 if n land ((1 lsl 20) - 1) = 0
3827 if n land ((1 lsl 10) - 1) = 0
3833 let h = n mod 1000 in
3836 then string_of_int
h ^
s
3838 let s = Printf.sprintf
"_%03d%s" h s in
3845 let defghyllscroll = (40, 8, 32);;
3846 let ghyllscroll_of_string s =
3847 let (n, a, b) as nab
=
3850 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3852 if n <= a || n <= b || a >= b
3853 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3857 let ghyllscroll_to_string ((n, a, b) as nab
) =
3858 if nab
= defghyllscroll
3860 else Printf.sprintf
"%d,%d,%d" n a b;
3863 let describe_location () =
3865 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3867 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3868 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3872 else (100. *. (float state.y /. float maxy))
3876 Printf.sprintf
"page %d of %d [%.2f%%]"
3877 (fn+1) state.pagecount
percent
3880 "pages %d-%d of %d [%.2f%%]"
3881 (fn+1) (ln
+1) state.pagecount
percent
3885 let btos b = if b then "\xe2\x88\x9a" else "" in
3886 let showextended = ref false in
3887 let leave mode
= function
3888 | Confirm
-> state.mode
<- mode
3889 | Cancel
-> state.mode
<- mode
in
3892 val mutable m_first_time
= true
3893 val mutable m_l
= []
3894 val mutable m_a
= [||]
3895 val mutable m_prev_uioh
= nouioh
3896 val mutable m_prev_mode
= View
3898 inherit lvsourcebase
3900 method reset prev_mode prev_uioh
=
3901 m_a
<- Array.of_list
(List.rev m_l
);
3903 m_prev_mode
<- prev_mode
;
3904 m_prev_uioh
<- prev_uioh
;
3908 if n >= Array.length m_a
3912 | _, _, _, Action
_ -> m_active
<- n
3916 m_first_time
<- false;
3919 method int name get
set =
3921 (name
, `
int get
, 1, Action
(
3924 try set (int_of_string
s)
3926 state.text <- Printf.sprintf
"bad integer `%s': %s"
3927 s (Printexc.to_string exn
)
3930 let te = name ^
": ", "", None
, intentry, ondone, true in
3931 state.mode
<- Textentry
(te, leave m_prev_mode
);
3935 method int_with_suffix name get
set =
3937 (name
, `intws get
, 1, Action
(
3940 try set (int_of_string_with_suffix s)
3942 state.text <- Printf.sprintf
"bad integer `%s': %s"
3943 s (Printexc.to_string exn
)
3947 name ^
": ", "", None
, intentry_with_suffix, ondone, true
3949 state.mode
<- Textentry
(te, leave m_prev_mode
);
3953 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3955 (name
, `
bool (btos, get
), offset
, Action
(
3962 method color name get
set =
3964 (name
, `color get
, 1, Action
(
3966 let invalid = (nan
, nan
, nan
) in
3969 try color_of_string s
3971 state.text <- Printf.sprintf
"bad color `%s': %s"
3972 s (Printexc.to_string exn
);
3978 let te = name ^
": ", "", None
, textentry, ondone, true in
3979 state.text <- color_to_string (get
());
3980 state.mode
<- Textentry
(te, leave m_prev_mode
);
3984 method string name get
set =
3986 (name
, `
string get
, 1, Action
(
3988 let ondone s = set s in
3989 let te = name ^
": ", "", None
, textentry, ondone, true in
3990 state.mode
<- Textentry
(te, leave m_prev_mode
);
3994 method colorspace name get
set =
3996 (name
, `
string get
, 1, Action
(
3999 let vals = [| "rgb"; "bgr"; "gray" |] in
4001 inherit lvsourcebase
4004 m_active
<- int_of_colorspace conf.colorspace
;
4007 method getitemcount
= Array.length
vals
4008 method getitem
n = (vals.(n), 0)
4009 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4010 ignore
(uioh
, first, pan
, qsearch);
4011 if not cancel
then set active;
4013 method hasaction
_ = true
4017 let modehash = findkeyhash conf "info" in
4018 coe (new listview ~
source ~trusted
:true ~
modehash)
4021 method caption
s offset
=
4022 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4024 method caption2
s f offset
=
4025 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4027 method getitemcount
= Array.length m_a
4030 let tostr = function
4031 | `
int f -> string_of_int
(f ())
4032 | `intws
f -> string_with_suffix_of_int (f ())
4034 | `color
f -> color_to_string (f ())
4035 | `
bool (btos, f) -> btos (f ())
4038 let name, t
, offset
, _ = m_a
.(n) in
4039 ((let s = tostr t
in
4040 if String.length
s > 0
4041 then Printf.sprintf
"%s\t%s" name s
4045 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4049 m_qsearch
<- qsearch;
4051 match m_a
.(active) with
4052 | _, _, _, Action
f -> f uioh
4064 method hasaction
n =
4066 | _, _, _, Action
_ -> true
4070 let rec fillsrc prevmode prevuioh
=
4071 let sep () = src#caption
"" 0 in
4072 let colorp name get
set =
4074 (fun () -> color_to_string (get
()))
4077 let c = color_of_string v in
4080 state.text <- Printf.sprintf
"bad color `%s': %s"
4081 v (Printexc.to_string exn
);
4084 let oldmode = state.mode
in
4085 let birdseye = isbirdseye state.mode
in
4087 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4089 src#
bool "presentation mode"
4090 (fun () -> conf.presentation
)
4092 conf.presentation
<- v;
4093 state.anchor <- getanchor ();
4096 src#
bool "ignore case in searches"
4097 (fun () -> conf.icase
)
4098 (fun v -> conf.icase
<- v);
4101 (fun () -> conf.preload)
4102 (fun v -> conf.preload <- v);
4104 src#
bool "highlight links"
4105 (fun () -> conf.hlinks
)
4106 (fun v -> conf.hlinks
<- v);
4108 src#
bool "under info"
4109 (fun () -> conf.underinfo
)
4110 (fun v -> conf.underinfo
<- v);
4112 src#
bool "persistent bookmarks"
4113 (fun () -> conf.savebmarks
)
4114 (fun v -> conf.savebmarks
<- v);
4116 src#
bool "proportional display"
4117 (fun () -> conf.proportional
)
4118 (fun v -> reqlayout conf.angle
v);
4120 src#
bool "trim margins"
4121 (fun () -> conf.trimmargins
)
4122 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4124 src#
bool "persistent location"
4125 (fun () -> conf.jumpback
)
4126 (fun v -> conf.jumpback
<- v);
4129 src#
int "inter-page space"
4130 (fun () -> conf.interpagespace
)
4132 conf.interpagespace
<- n;
4133 docolumns conf.columns
;
4135 match state.layout with
4140 state.maxy <- calcheight ();
4141 let y = getpagey pageno in
4146 (fun () -> conf.pagebias
)
4147 (fun v -> conf.pagebias
<- v);
4149 src#
int "scroll step"
4150 (fun () -> conf.scrollstep
)
4151 (fun n -> conf.scrollstep
<- n);
4153 src#
int "horizontal scroll step"
4154 (fun () -> conf.hscrollstep
)
4155 (fun v -> conf.hscrollstep
<- v);
4157 src#
int "auto scroll step"
4159 match state.autoscroll
with
4161 | _ -> conf.autoscrollstep
)
4163 if state.autoscroll
<> None
4164 then state.autoscroll
<- Some
n;
4165 conf.autoscrollstep
<- n);
4168 (fun () -> truncate
(conf.zoom *. 100.))
4169 (fun v -> setzoom ((float v) /. 100.));
4172 (fun () -> conf.angle
)
4173 (fun v -> reqlayout v conf.proportional
);
4175 src#
int "scroll bar width"
4176 (fun () -> state.scrollw
)
4180 reshape conf.winw
conf.winh
;
4183 src#
int "scroll handle height"
4184 (fun () -> conf.scrollh
)
4185 (fun v -> conf.scrollh
<- v;);
4187 src#
int "thumbnail width"
4188 (fun () -> conf.thumbw
)
4190 conf.thumbw
<- min
4096 v;
4193 leavebirdseye beye
false;
4198 let mode = state.mode in
4199 src#
string "columns"
4201 match conf.columns
with
4203 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4204 | Csplit
(count
, _) -> "-" ^ string_of_int count
4207 let n, a, b = multicolumns_of_string v in
4208 setcolumns mode n a b);
4211 src#caption
"Presentation mode" 0;
4212 src#
bool "scrollbar visible"
4213 (fun () -> conf.scrollbarinpm
)
4215 if v != conf.scrollbarinpm
4217 conf.scrollbarinpm
<- v;
4218 if conf.presentation
4220 state.scrollw
<- if v then conf.scrollbw
else 0;
4221 reshape conf.winw
conf.winh
;
4227 src#caption
"Pixmap cache" 0;
4228 src#int_with_suffix
"size (advisory)"
4229 (fun () -> conf.memlimit
)
4230 (fun v -> conf.memlimit
<- v);
4233 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4234 (string_with_suffix_of_int state.memused
)
4235 (Hashtbl.length
state.tilemap
)) 1;
4238 src#caption
"Layout" 0;
4239 src#caption2
"Dimension"
4241 Printf.sprintf
"%dx%d (virtual %dx%d)"
4247 src#caption2
"Position" (fun () ->
4248 Printf.sprintf
"%dx%d" state.x state.y
4251 src#caption2
"Visible" (fun () -> describe_location ()) 1
4255 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4256 "Save these parameters as global defaults at exit"
4257 (fun () -> conf.bedefault
)
4258 (fun v -> conf.bedefault
<- v)
4262 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4263 src#
bool ~offset
:0 ~
btos "Extended parameters"
4264 (fun () -> !showextended)
4265 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4269 (fun () -> conf.checkers
)
4270 (fun v -> conf.checkers
<- v; setcheckers v);
4271 src#
bool "update cursor"
4272 (fun () -> conf.updatecurs
)
4273 (fun v -> conf.updatecurs
<- v);
4275 (fun () -> conf.verbose
)
4276 (fun v -> conf.verbose
<- v);
4277 src#
bool "invert colors"
4278 (fun () -> conf.invert
)
4279 (fun v -> conf.invert
<- v);
4281 (fun () -> conf.maxhfit
)
4282 (fun v -> conf.maxhfit
<- v);
4283 src#
bool "redirect stderr"
4284 (fun () -> conf.redirectstderr)
4285 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4286 src#
string "uri launcher"
4287 (fun () -> conf.urilauncher
)
4288 (fun v -> conf.urilauncher
<- v);
4289 src#
string "path launcher"
4290 (fun () -> conf.pathlauncher
)
4291 (fun v -> conf.pathlauncher
<- v);
4292 src#
string "tile size"
4293 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4296 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4297 conf.tilew
<- max
64 w;
4298 conf.tileh
<- max
64 h;
4301 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4302 v (Printexc.to_string exn
));
4303 src#
int "texture count"
4304 (fun () -> conf.texcount
)
4307 then conf.texcount
<- v
4308 else showtext '
!'
" Failed to set texture count please retry later"
4310 src#
int "slice height"
4311 (fun () -> conf.sliceheight
)
4313 conf.sliceheight
<- v;
4314 wcmd "sliceh %d" conf.sliceheight
;
4316 src#
int "anti-aliasing level"
4317 (fun () -> conf.aalevel
)
4319 conf.aalevel
<- bound v 0 8;
4320 state.anchor <- getanchor ();
4321 opendoc state.path
state.password
;
4323 src#
string "page scroll scaling factor"
4324 (fun () -> string_of_float
conf.pgscale)
4327 let s = float_of_string
v in
4330 state.text <- Printf.sprintf
4331 "bad page scroll scaling factor `%s': %s"
4332 v (Printexc.to_string exn
)
4335 src#
int "ui font size"
4336 (fun () -> fstate.fontsize
)
4337 (fun v -> setfontsize (bound v 5 100));
4338 src#
int "hint font size"
4339 (fun () -> conf.hfsize
)
4340 (fun v -> conf.hfsize
<- bound v 5 100);
4341 colorp "background color"
4342 (fun () -> conf.bgcolor
)
4343 (fun v -> conf.bgcolor
<- v);
4344 src#
bool "crop hack"
4345 (fun () -> conf.crophack
)
4346 (fun v -> conf.crophack
<- v);
4347 src#
bool "multi column centering"
4348 (fun () -> conf.multicenter
)
4349 (fun v -> conf.multicenter
<- v; represent ());
4350 src#
string "trim fuzz"
4351 (fun () -> irect_to_string conf.trimfuzz
)
4354 conf.trimfuzz
<- irect_of_string v;
4356 then settrim true conf.trimfuzz
;
4358 state.text <- Printf.sprintf
"bad irect `%s': %s"
4359 v (Printexc.to_string exn
)
4361 src#
string "throttle"
4363 match conf.maxwait
with
4364 | None
-> "show place holder if page is not ready"
4367 then "wait for page to fully render"
4369 "wait " ^ string_of_float
time
4370 ^
" seconds before showing placeholder"
4374 let f = float_of_string
v in
4376 then conf.maxwait
<- None
4377 else conf.maxwait
<- Some
f
4379 state.text <- Printf.sprintf
"bad time `%s': %s"
4380 v (Printexc.to_string exn
)
4382 src#
string "ghyll scroll"
4384 match conf.ghyllscroll
with
4386 | Some nab
-> ghyllscroll_to_string nab
4391 if String.length
v = 0
4393 else Some
(ghyllscroll_of_string v)
4395 conf.ghyllscroll
<- gs
4397 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4398 v (Printexc.to_string exn
)
4400 src#
string "selection command"
4401 (fun () -> conf.selcmd
)
4402 (fun v -> conf.selcmd
<- v);
4403 src#colorspace
"color space"
4404 (fun () -> colorspace_to_string conf.colorspace
)
4406 conf.colorspace
<- colorspace_of_int v;
4413 src#caption
"Document" 0;
4414 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4415 src#caption2
"Pages"
4416 (fun () -> string_of_int
state.pagecount
) 1;
4417 src#caption2
"Dimensions"
4418 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4422 src#caption
"Trimmed margins" 0;
4423 src#caption2
"Dimensions"
4424 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4428 src#caption
"OpenGL" 0;
4429 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4430 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4431 src#reset prevmode prevuioh
;
4435 let prevmode = state.mode
4436 and prevuioh
= state.uioh in
4437 fillsrc prevmode prevuioh
;
4438 let source = (src :> lvsource
) in
4439 let modehash = findkeyhash conf "info" in
4440 state.uioh <- coe (object (self)
4441 inherit listview ~
source ~trusted
:true ~
modehash as super
4442 val mutable m_prevmemused
= 0
4443 method infochanged
= function
4445 if m_prevmemused
!= state.memused
4447 m_prevmemused
<- state.memused
;
4448 G.postRedisplay "memusedchanged";
4450 | Pdim
-> G.postRedisplay "pdimchanged"
4451 | Docinfo
-> fillsrc prevmode prevuioh
4453 method key key mask
=
4454 if not
(Wsi.withctrl mask
)
4457 | 0xff51 -> coe (self#updownlevel ~
-1)
4458 | 0xff53 -> coe (self#updownlevel
1)
4459 | _ -> super#
key key mask
4460 else super#
key key mask
4462 G.postRedisplay "info";
4468 inherit lvsourcebase
4469 method getitemcount
= Array.length
state.help
4471 let s, n, _ = state.help
.(n) in
4474 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4478 m_qsearch
<- qsearch;
4479 match state.help
.(active) with
4480 | _, _, Action
f -> Some
(f uioh)
4490 method hasaction
n =
4491 match state.help
.(n) with
4492 | _, _, Action
_ -> true
4499 let modehash = findkeyhash conf "help" in
4500 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4501 G.postRedisplay "help";
4506 let re = Str.regexp
"[\r\n]" in
4508 inherit lvsourcebase
4509 val mutable m_items
= [||]
4511 method getitemcount
= 1 + Array.length m_items
4516 else m_items
.(n-1), 0
4518 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4523 then Buffer.clear
state.errmsgs
;
4524 m_qsearch
<- qsearch;
4531 method hasaction
n =
4535 state.newerrmsgs
<- false;
4536 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4537 m_items
<- Array.of_list
l
4545 let source = (msgsource :> lvsource
) in
4546 let modehash = findkeyhash conf "listview" in
4547 state.uioh <- coe (object
4548 inherit listview ~
source ~trusted
:false ~
modehash as super
4551 then msgsource#reset
;
4554 G.postRedisplay "msgs";
4557 let quickbookmark ?title
() =
4558 match state.layout with
4564 let sec = Unix.gettimeofday
() in
4565 let tm = Unix.localtime
sec in
4566 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4570 (tm.Unix.tm_year
+ 1900)
4573 | Some
title -> title
4575 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4579 state.fullscreen
<- None
;
4583 let setautoscrollspeed step goingdown
=
4584 let incr = max
1 ((abs step
) / 2) in
4585 let incr = if goingdown
then incr else -incr in
4586 let astep = step
+ incr in
4587 state.autoscroll
<- Some
astep;
4590 let gotounder = function
4591 | Ulinkgoto
(pageno, top) ->
4595 gotopage1 pageno top;
4601 | Uremote
(filename
, pageno) ->
4603 if Sys.file_exists filename
4606 let dir = Filename.dirname
state.path in
4607 let path = Filename.concat
dir filename
in
4608 if Sys.file_exists
path
4612 if String.length
path > 0
4614 let anchor = getanchor () in
4615 let ranchor = state.path, state.password
, anchor in
4616 state.anchor <- (pageno, 0.0, 0.0);
4617 state.ranchors
<- ranchor :: state.ranchors
;
4620 else showtext '
!'
("Could not find " ^ filename
)
4622 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4626 match conf.columns
with
4628 | _ -> conf.zoom > 1.0
4631 let viewkeyboard key mask
=
4633 let mode = state.mode in
4634 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4637 G.postRedisplay "view:enttext"
4639 let ctrl = Wsi.withctrl mask
in
4644 | 0xff63 -> (* insert *)
4645 if conf.angle
mod 360 = 0
4647 state.mode <- LinkNav
(Ltgendir
0);
4650 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4652 | 0xff1b | 113 -> (* escape / q *)
4653 begin match state.mstate
with
4655 state.mstate
<- Mnone
;
4656 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4657 G.postRedisplay "kill zoom rect";
4659 match state.ranchors
with
4661 | (path, password
, anchor) :: rest
->
4662 state.ranchors
<- rest
;
4663 state.anchor <- anchor;
4664 opendoc path password
4667 | 0xff08 -> (* backspace *)
4668 let y = getnav ~
-1 in
4669 gotoy_and_clear_text y
4677 G.postRedisplay "dehighlight";
4679 | 47 | 63 -> (* / ? *)
4680 let ondone isforw
s =
4681 cbput state.hists
.pat
s;
4682 state.searchpattern
<- s;
4685 let s = String.create
1 in
4686 s.[0] <- Char.chr
key;
4687 enttext (s, "", Some
(onhist state.hists
.pat
),
4688 textentry, ondone (key = 47), true)
4690 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4691 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4692 setzoom (conf.zoom +. incr)
4694 | 43 | 0xffab -> (* + *)
4697 try int_of_string
s with exc
->
4698 state.text <- Printf.sprintf
"bad integer `%s': %s"
4699 s (Printexc.to_string exc
);
4705 state.text <- "page bias is now " ^ string_of_int
n;
4708 enttext ("page bias: ", "", None
, intentry, ondone, true)
4710 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4711 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4712 setzoom (max
0.01 (conf.zoom -. decr))
4714 | 45 | 0xffad -> (* - *)
4715 let ondone msg
= state.text <- msg
in
4717 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4718 optentry state.mode, ondone, true
4721 | 48 when ctrl -> (* ctrl-0 *)
4724 | 49 when ctrl -> (* ctrl-1 *)
4726 match conf.columns
with
4727 | Csingle
_ | Cmulti
_ -> 1
4728 | Csplit
(n, _) -> n
4730 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4734 | 0xffc6 -> (* f9 *)
4737 | 57 when ctrl -> (* ctrl-9 *)
4740 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4741 when not
ctrl -> (* 0..9 *)
4744 try int_of_string
s with exc
->
4745 state.text <- Printf.sprintf
"bad integer `%s': %s"
4746 s (Printexc.to_string exc
);
4752 cbput state.hists
.pag
(string_of_int
n);
4753 gotopage1 (n + conf.pagebias
- 1) 0;
4756 let pageentry text key =
4757 match Char.unsafe_chr
key with
4758 | 'g'
-> TEdone
text
4759 | _ -> intentry text key
4761 let text = "x" in text.[0] <- Char.chr
key;
4762 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4765 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4766 reshape conf.winw
conf.winh
;
4769 conf.hlinks
<- not
conf.hlinks
;
4770 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4771 G.postRedisplay "toggle highlightlinks";
4774 state.glinks
<- true;
4775 let mode = state.mode in
4776 state.mode <- Textentry
(
4777 (":", "", None
, linknentry, linkndone (fun under ->
4782 state.glinks
<- false;
4786 G.postRedisplay "view:linkent(F)"
4789 state.glinks
<- true;
4790 let mode = state.mode in
4791 state.mode <- Textentry
(
4792 (":", "", None
, linknentry, linkndone (fun under ->
4793 match Ne.pipe () with
4795 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4796 (Printexc.to_string exn
));
4799 try popen conf.selcmd
[r, 0; w, -1]; true
4802 (Printf.sprintf
"failed to execute %s: %s"
4803 conf.selcmd
(Printexc.to_string exn
));
4807 Ne.clo fd
(fun msg
->
4808 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4811 let s = undertext under in
4815 let l = String.length
s in
4816 let n = Unix.write
w s 0 l in
4821 "failed to write %d characters to sel pipe, wrote %d"
4826 (Printf.sprintf
"failed to write to sel pipe: %s"
4827 (Printexc.to_string exn
)
4836 state.glinks
<- false;
4840 G.postRedisplay "view:linkent"
4843 begin match state.autoscroll
with
4845 conf.autoscrollstep
<- step
;
4846 state.autoscroll
<- None
4848 if conf.autoscrollstep
= 0
4849 then state.autoscroll
<- Some
1
4850 else state.autoscroll
<- Some
conf.autoscrollstep
4853 | 112 when ctrl -> (* ctrl-p *)
4857 conf.presentation
<- not
conf.presentation
;
4858 if conf.presentation
4860 if not
conf.scrollbarinpm
4861 then state.scrollw
<- 0;
4864 state.scrollw
<- conf.scrollbw
;
4866 showtext ' '
("presentation mode " ^
4867 if conf.presentation
then "on" else "off");
4868 state.anchor <- getanchor ();
4872 begin match state.fullscreen
with
4874 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4877 state.fullscreen
<- None
;
4882 gotoy_and_clear_text 0
4885 gotopage1 (state.pagecount
- 1) 0
4887 | 112 | 78 -> (* p|N *)
4888 search state.searchpattern
false
4890 | 110 | 0xffc0 -> (* n|F3 *)
4891 search state.searchpattern
true
4894 begin match state.layout with
4897 gotoy_and_clear_text (getpagey l.pageno)
4901 begin match state.layout with
4904 match conf.columns
with
4905 | Csingle
_ | Cmulti
_ ->
4906 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4908 let y = clamp (pgscale conf.winh
) in
4909 gotoy_and_clear_text y
4911 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4912 gotoy_and_clear_text (getpagey pageno)
4914 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4916 let pagey, pageh
= getpageyh l.pageno in
4917 let pagey = pagey + pageh
* l.pagecol
in
4918 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4919 gotoy_and_clear_text (pagey + pageh
+ ips)
4922 | 0xff9f | 0xffff -> (* delete *)
4923 begin match state.layout with
4926 match conf.columns
with
4927 | Csingle
_ | Cmulti
_ ->
4928 if conf.presentation
&& l.pagey != 0
4930 gotoy_and_clear_text (clamp (pgscale ~
-(conf.winh
)))
4932 let pageno = max
0 (l.pageno-1) in
4933 gotoy_and_clear_text (getpagey pageno)
4941 let pageno = max
0 (l.pageno-1) in
4942 let pagey, pageh
= getpageyh pageno in
4945 let pagey, pageh
= getpageyh l.pageno in
4946 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4948 gotoy_and_clear_text y
4952 showtext ' '
(describe_location ());
4955 begin match state.layout with
4958 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4963 enterbookmarkmode ()
4965 | 104 | 0xffbe -> (* h|F1 *)
4971 | 101 when conf.redirectstderr -> (* e *)
4976 match state.layout with
4977 | l :: _ -> state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
4980 enttext ("bookmark: ", "", None
, textentry, ondone, true)
4984 showtext ' '
"Quick bookmark added";
4987 begin match state.layout with
4989 let rect = getpdimrect
l.pagedimno
in
4993 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4994 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4996 (truncate
(rect.(1) -. rect.(0)),
4997 truncate
(rect.(3) -. rect.(0)))
4999 let w = truncate
((float w)*.conf.zoom)
5000 and h = truncate
((float h)*.conf.zoom) in
5003 state.anchor <- getanchor ();
5004 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5006 G.postRedisplay "z";
5011 | 50 when ctrl -> (* ctrl-2 *)
5012 let maxw = getmaxw
() in
5014 then setzoom (maxw /. float conf.winw
)
5016 | 60 | 62 -> (* < > *)
5017 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5019 | 91 | 93 -> (* [ ] *)
5021 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5023 G.postRedisplay "brightness";
5025 | 99 when state.mode = View
-> (* c *)
5027 match state.prevcolumns
with
5028 | None
-> (1, 0, 0), 1.0
5029 | Some
(columns
, z
) ->
5032 | Csplit
(c, _) -> -c, 0, 0
5033 | Cmulti
((c, a, b), _) -> c, a, b
5034 | Csingle
_ -> 1, 0, 0
5038 setcolumns View
c a b;
5041 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5042 setzoom state.prevzoom
5044 | 107 | 0xff52 -> (* k up *)
5045 begin match state.autoscroll
with
5047 begin match state.mode with
5048 | Birdseye beye
-> upbirdseye 1 beye
5051 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5052 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5055 setautoscrollspeed n false
5058 | 106 | 0xff54 -> (* j down *)
5059 begin match state.autoscroll
with
5061 begin match state.mode with
5062 | Birdseye beye
-> downbirdseye 1 beye
5065 then gotoy_and_clear_text (clamp (conf.winh
/2))
5066 else gotoy_and_clear_text (clamp conf.scrollstep
)
5069 setautoscrollspeed n true
5072 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5080 let dx = if key = 0xff51 then dx else -dx in
5081 state.x <- state.x + dx;
5082 gotoy_and_clear_text state.y
5085 G.postRedisplay "lef/right"
5088 | 0xff55 -> (* prior *)
5092 match state.layout with
5094 | l :: _ -> state.y - l.pagey
5096 clamp (pgscale (-conf.winh
))
5100 | 0xff56 -> (* next *)
5104 match List.rev
state.layout with
5106 | l :: _ -> getpagey l.pageno
5108 clamp (pgscale conf.winh
)
5112 | 0xff50 -> (* home *)
5114 | 0xff57 -> (* end *)
5115 gotoghyll (clamp state.maxy)
5116 | 0xff53 when Wsi.withalt mask
-> (* right *)
5117 gotoghyll (getnav ~
-1)
5118 | 0xff51 when Wsi.withalt mask
-> (* left *)
5119 gotoghyll (getnav 1)
5122 state.anchor <- getanchor ();
5123 opendoc state.path state.password
5125 | 118 when conf.debug
-> (* v *)
5128 match getopaque l.pageno with
5131 let x0, y0, x1, y1 = pagebbox opaque
in
5132 let a,b = float x0, float y0 in
5133 let c,d = float x1, float y0 in
5134 let e,f = float x1, float y1 in
5135 let h,j
= float x0, float y1 in
5136 let rect = (a,b,c,d,e,f,h,j
) in
5138 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5140 G.postRedisplay "v";
5143 vlog "huh? %s" (Wsi.keyname
key)
5146 let linknavkeyboard key mask
linknav =
5147 let getpage pageno =
5148 let rec loop = function
5150 | l :: _ when l.pageno = pageno -> Some
l
5151 | _ :: rest
-> loop rest
5152 in loop state.layout
5154 let doexact (pageno, n) =
5155 match getopaque pageno, getpage pageno with
5156 | Some opaque
, Some
l ->
5159 let under = getlink opaque
n in
5160 G.postRedisplay "link gotounder";
5166 | 0xff50 -> (* home *)
5167 Some
(findlink opaque LDfirst
), -1
5169 | 0xff57 -> (* end *)
5170 Some
(findlink opaque LDlast
), 1
5172 | 0xff51 -> (* left *)
5173 Some
(findlink opaque
(LDleft
n)), -1
5175 | 0xff53 -> (* right *)
5176 Some
(findlink opaque
(LDright
n)), 1
5178 | 0xff52 -> (* up *)
5179 Some
(findlink opaque
(LDup
n)), -1
5181 | 0xff54 -> (* down *)
5182 Some
(findlink opaque
(LDdown
n)), 1
5187 begin match findpwl
l.pageno dir with
5191 state.mode <- LinkNav
(Ltgendir
dir);
5192 let y, h = getpageyh pageno in
5195 then y + h - conf.winh
5200 begin match getopaque pageno, getpage pageno with
5201 | Some opaque
, Some
_ ->
5203 let ld = if dir > 0 then LDfirst
else LDlast
in
5206 begin match link with
5208 showlinktype (getlink opaque
m);
5209 state.mode <- LinkNav
(Ltexact
(pageno, m));
5210 G.postRedisplay "linknav jpage";
5217 begin match opt with
5218 | Some Lnotfound
-> pwl l dir;
5219 | Some
(Lfound
m) ->
5223 let _, y0, _, y1 = getlinkrect opaque
m in
5225 then gotopage1 l.pageno y0
5227 let d = fstate.fontsize
+ 1 in
5228 if y1 - l.pagey > l.pagevh - d
5229 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5230 else G.postRedisplay "linknav";
5232 showlinktype (getlink opaque
m);
5233 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5236 | None
-> viewkeyboard key mask
5238 | _ -> viewkeyboard key mask
5243 G.postRedisplay "leave linknav"
5247 | Ltgendir
_ -> viewkeyboard key mask
5248 | Ltexact exact
-> doexact exact
5251 let keyboard key mask
=
5252 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5253 then wcmd "interrupt"
5254 else state.uioh <- state.uioh#
key key mask
5257 let birdseyekeyboard key mask
5258 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5260 match conf.columns
with
5262 | Cmulti
((c, _, _), _) -> c
5263 | Csplit
_ -> failwith
"bird's eye split mode"
5265 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5267 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5268 let y, h = getpageyh pageno in
5269 let top = (conf.winh
- h) / 2 in
5270 gotoy (max
0 (y - top))
5271 | 0xff0d -> leavebirdseye beye
false
5272 | 0xff1b -> leavebirdseye beye
true (* escape *)
5273 | 0xff52 -> upbirdseye incr beye
(* up *)
5274 | 0xff54 -> downbirdseye incr beye
(* down *)
5275 | 0xff51 -> upbirdseye 1 beye
(* left *)
5276 | 0xff53 -> downbirdseye 1 beye
(* right *)
5278 | 0xff55 -> (* prior *)
5279 begin match state.layout with
5283 state.mode <- Birdseye
(
5284 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5286 gotopage1 l.pageno 0;
5289 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5291 | [] -> gotoy (clamp (-conf.winh
))
5293 state.mode <- Birdseye
(
5294 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5296 gotopage1 l.pageno 0
5299 | [] -> gotoy (clamp (-conf.winh
))
5302 | 0xff56 -> (* next *)
5303 begin match List.rev
state.layout with
5305 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5306 begin match layout with
5308 let incr = l.pageh
- l.pagevh in
5313 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5315 G.postRedisplay "birdseye pagedown";
5317 else gotoy (clamp (incr + conf.interpagespace
*2));
5321 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5322 gotopage1 l.pageno 0;
5325 | [] -> gotoy (clamp conf.winh
)
5328 | 0xff50 -> (* home *)
5329 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5332 | 0xff57 -> (* end *)
5333 let pageno = state.pagecount
- 1 in
5334 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5335 if not
(pagevisible state.layout pageno)
5338 match List.rev
state.pdims
with
5340 | (_, _, h, _) :: _ -> h
5342 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5343 else G.postRedisplay "birdseye end";
5344 | _ -> viewkeyboard key mask
5347 let drawpage l linkindexbase
=
5349 match state.mode with
5350 | Textentry
_ -> scalecolor 0.4
5352 | View
-> scalecolor 1.0
5353 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5354 if l.pageno = hooverpageno
5357 if l.pageno = pageno
5363 begin match getopaque l.pageno with
5365 if tileready l l.pagex
l.pagey
5367 let x = l.pagedispx - l.pagex
5368 and y = l.pagedispy - l.pagey in
5370 match conf.columns
with
5371 | Csingle
_ | Cmulti
_ ->
5372 (if conf.hlinks
then 1 else 0)
5374 && not
(isbirdseye state.mode) then 2 else 0)
5378 match state.mode with
5379 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5382 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5389 let scrollindicator () =
5390 let sbw, ph
, sh = state.uioh#
scrollph in
5391 let sbh, pw, sw = state.uioh#scrollpw
in
5393 GlDraw.color (0.64, 0.64, 0.64);
5395 (float (conf.winw
- sbw), 0.)
5396 (float conf.winw
, float conf.winh
)
5399 (0., float (conf.winh
- sbh))
5400 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5402 GlDraw.color (0.0, 0.0, 0.0);
5405 (float (conf.winw
- sbw), ph
)
5406 (float conf.winw
, ph
+. sh)
5409 (pw, float (conf.winh
- sbh))
5410 (pw +. sw, float conf.winh
)
5415 match state.mstate
with
5416 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5419 | Msel
((x0, y0), (x1, y1)) ->
5420 let rec loop = function
5422 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5423 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5424 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5425 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5427 match getopaque l.pageno with
5429 let x0, y0 = pagetranslatepoint l x0 y0 in
5430 let x1, y1 = pagetranslatepoint l x1 y1 in
5431 seltext opaque
(x0, y0, x1, y1);
5439 let showrects rects
=
5441 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5442 GlDraw.polygon_mode `both `fill
;
5443 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5445 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5447 if l.pageno = pageno
5449 let dx = float (l.pagedispx - l.pagex
) in
5450 let dy = float (l.pagedispy - l.pagey) in
5451 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5452 GlDraw.begins `quads
;
5454 GlDraw.vertex2
(x0+.dx, y0+.dy);
5455 GlDraw.vertex2
(x1+.dx, y1+.dy);
5456 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5457 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5468 GlClear.color (scalecolor2 conf.bgcolor
);
5469 GlClear.clear
[`
color];
5470 let rec loop linkindexbase
= function
5472 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5473 loop linkindexbase rest
5476 loop 0 state.layout;
5478 match state.mode with
5479 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5480 begin match getopaque pageno with
5482 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5489 | None
-> state.rects
5496 begin match state.mstate
with
5497 | Mzoomrect
((x0, y0), (x1, y1)) ->
5499 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5500 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5501 GlDraw.rect (float x0, float y0)
5502 (float x1, float y1);
5511 let zoomrect x y x1 y1 =
5514 and y0 = min
y y1 in
5515 gotoy (state.y + y0);
5516 state.anchor <- getanchor ();
5517 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5519 if state.w < conf.winw
- state.scrollw
5520 then (conf.winw
- state.scrollw
- state.w) / 2
5523 state.x <- (state.x + margin) - x0;
5525 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5526 state.mstate
<- Mnone
;
5530 let winw = conf.winw - state.scrollw
- 1 in
5531 let s = float x /. float winw in
5532 let destx = truncate
(float (state.w + winw) *. s) in
5533 state.x <- winw - destx;
5534 gotoy_and_clear_text state.y;
5535 state.mstate
<- Mscrollx
;
5539 let s = float y /. float conf.winh
in
5540 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5541 gotoy_and_clear_text desty;
5542 state.mstate
<- Mscrolly
;
5545 let viewmouse button down
x y mask
=
5547 | n when (n == 4 || n == 5) && not down
->
5548 if Wsi.withctrl mask
5550 match state.mstate
with
5551 | Mzoom
(oldn
, i
) ->
5559 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5561 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5563 let zoom = conf.zoom -. incr in
5565 state.mstate
<- Mzoom
(n, 0);
5567 state.mstate
<- Mzoom
(n, i
+1);
5569 else state.mstate
<- Mzoom
(n, 0)
5571 | _ -> state.mstate
<- Mzoom
(n, 0)
5574 match state.autoscroll
with
5575 | Some step
-> setautoscrollspeed step
(n=4)
5579 then -conf.scrollstep
5580 else conf.scrollstep
5582 let incr = incr * 2 in
5583 let y = clamp incr in
5584 gotoy_and_clear_text y
5587 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5588 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5589 gotoy_and_clear_text state.y
5591 | 1 when Wsi.withctrl mask
->
5594 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5595 state.mstate
<- Mpan
(x, y)
5598 state.mstate
<- Mnone
5603 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5605 state.mstate
<- Mzoomrect
(p, p)
5608 match state.mstate
with
5609 | Mzoomrect
((x0, y0), _) ->
5610 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5611 then zoomrect x0 y0 x y
5613 state.mstate
<- Mnone
;
5614 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5615 G.postRedisplay "kill accidental zoom rect";
5618 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5619 state.mstate
<- Mnone
5622 | 1 when x > conf.winw - state.scrollw
->
5625 let _, position, sh = state.uioh#
scrollph in
5626 if y > truncate
position && y < truncate
(position +. sh)
5627 then state.mstate
<- Mscrolly
5630 state.mstate
<- Mnone
5632 | 1 when y > conf.winh
- state.hscrollh ->
5635 let _, position, sw = state.uioh#scrollpw
in
5636 if x > truncate
position && x < truncate
(position +. sw)
5637 then state.mstate
<- Mscrollx
5640 state.mstate
<- Mnone
5643 let dest = if down
then getunder x y else Unone
in
5644 begin match dest with
5648 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5651 | Unone
when down
->
5652 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5653 state.mstate
<- Mpan
(x, y);
5655 | Unone
| Utext
_ ->
5658 if conf.angle
mod 360 = 0
5660 state.mstate
<- Msel
((x, y), (x, y));
5661 G.postRedisplay "mouse select";
5665 match state.mstate
with
5668 | Mzoom
_ | Mscrollx
| Mscrolly
->
5669 state.mstate
<- Mnone
5671 | Mzoomrect
((x0, y0), _) ->
5675 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5676 state.mstate
<- Mnone
5678 | Msel
((_, y0), (_, y1)) ->
5679 let rec loop = function
5682 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5683 || ((y1 >= l.pagedispy
5684 && y1 <= (l.pagedispy + l.pagevh)))
5686 match getopaque l.pageno with
5689 match Ne.pipe () with
5693 "can not create sel pipe: %s"
5694 (Printexc.to_string exn
));
5696 let doclose what fd
=
5697 Ne.clo fd
(fun msg
->
5698 dolog "%s close failed: %s" what msg
)
5701 popen conf.selcmd
[r, 0; w, -1];
5704 G.postRedisplay "copysel";
5706 dolog "can not execute %S: %s"
5707 conf.selcmd
(Printexc.to_string exn
);
5715 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5716 state.mstate
<- Mnone
;
5723 let birdseyemouse button down
x y mask
5724 (conf, leftx
, _, hooverpageno
, anchor) =
5727 let rec loop = function
5730 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5731 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5733 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5739 | _ -> viewmouse button down
x y mask
5742 let mouse button down
x y mask
=
5743 state.uioh <- state.uioh#button button down
x y mask
;
5747 state.uioh <- state.uioh#
motion x y
5751 state.uioh <- state.uioh#
pmotion x y;
5757 method key key mask
=
5758 begin match state.mode with
5759 | Textentry
textentry -> textentrykeyboard key mask
textentry
5760 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5761 | View
-> viewkeyboard key mask
5762 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5766 method button button bstate
x y mask
=
5767 begin match state.mode with
5769 | View
-> viewmouse button bstate
x y mask
5770 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5776 begin match state.mode with
5778 | View
| Birdseye
_ | LinkNav
_ ->
5779 match state.mstate
with
5780 | Mzoom
_ | Mnone
-> ()
5785 state.mstate
<- Mpan
(x, y);
5787 then state.x <- state.x + dx;
5789 gotoy_and_clear_text y
5792 state.mstate
<- Msel
(a, (x, y));
5793 G.postRedisplay "motion select";
5796 let y = min
conf.winh
(max
0 y) in
5800 let x = min
conf.winw (max
0 x) in
5803 | Mzoomrect
(p0
, _) ->
5804 state.mstate
<- Mzoomrect
(p0
, (x, y));
5805 G.postRedisplay "motion zoomrect";
5809 method pmotion x y =
5810 begin match state.mode with
5811 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5812 let rec loop = function
5814 if hooverpageno
!= -1
5816 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5817 G.postRedisplay "pmotion birdseye no hoover";
5820 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5821 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5823 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5824 G.postRedisplay "pmotion birdseye hoover";
5834 match state.mstate
with
5835 | Mnone
-> updateunder x y
5836 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5841 method infochanged
_ = ()
5844 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5845 let p, h = scrollph state.y maxy in
5849 let winw = conf.winw - state.scrollw
- 1 in
5850 let fwinw = float winw in
5852 let sw = fwinw /. float state.w in
5853 let sw = fwinw *. sw in
5854 max
sw (float conf.scrollh
)
5857 let f = state.w+winw in
5858 let r = float (winw-state.x) /. float f in
5859 let p = fwinw *. r in
5863 if position +. sw > fwinw
5864 then fwinw -. position
5867 state.hscrollh, position, sw
5871 match state.mode with
5872 | LinkNav
_ -> "links"
5873 | Textentry
_ -> "textentry"
5874 | Birdseye
_ -> "birdseye"
5877 findkeyhash conf modename
5884 let fontpath = ref "";;
5887 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5890 let l = String.length
s in
5891 let b = Buffer.create
l in
5897 try Sys.getenv
"HOME"
5900 ("Can not determine home directory location: " ^
5901 Printexc.to_string exn
);
5905 let modifier_of_string = function
5906 | "alt" -> Wsi.altmask
5907 | "shift" -> Wsi.shiftmask
5908 | "ctrl" | "control" -> Wsi.ctrlmask
5909 | "meta" -> Wsi.metamask
5914 let r = Str.regexp
"-" in
5916 let elems = Str.full_split
r s in
5919 let m1 = modifier_of_string s in
5921 then (Wsi.namekey
s, m)
5924 | Str.Delim
s when n land 1 = 0 -> g s
5926 | Str.Delim
_ -> (k
, m)
5928 let rec loop n k
m = function
5931 let k, m = f n k m x in
5937 let keys_of_string =
5938 let r = Str.regexp
"[ \t]" in
5940 let elems = Str.split
r s in
5941 List.map
key_of_string elems
5944 let copykeyhashes c =
5945 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5948 let config_of c attrs
=
5952 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5953 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5954 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5955 | "preload" -> { c with preload = bool_of_string
v }
5956 | "page-bias" -> { c with pagebias
= int_of_string
v }
5957 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5958 | "horizontal-scroll-step" ->
5959 { c with hscrollstep
= max
(int_of_string
v) 1 }
5960 | "auto-scroll-step" ->
5961 { c with autoscrollstep
= max
0 (int_of_string
v) }
5962 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5963 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5966 match String.lowercase
v with
5967 | "true" -> Some infinity
5969 | f -> Some
(float_of_string
f)
5971 { c with maxwait
= mw}
5972 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5973 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5974 | "vertical-margin" ->
5975 { c with interpagespace
= max
0 (int_of_string
v) }
5977 let zoom = float_of_string
v /. 100. in
5978 let zoom = max
zoom 0.0 in
5979 { c with zoom = zoom }
5980 | "presentation" -> { c with presentation
= bool_of_string
v }
5981 | "rotation-angle" -> { c with angle
= int_of_string
v }
5982 | "width" -> { c with winw = max
20 (int_of_string
v) }
5983 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5984 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5985 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5986 | "pixmap-cache-size" ->
5987 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5988 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5989 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5990 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5991 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5992 | "background-color" -> { c with bgcolor
= color_of_string v }
5993 | "scrollbar-in-presentation" ->
5994 { c with scrollbarinpm
= bool_of_string
v }
5995 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5996 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5997 | "mupdf-store-size" ->
5998 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5999 | "checkers" -> { c with checkers
= bool_of_string
v }
6000 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6001 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6002 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6003 | "uri-launcher" -> { c with urilauncher
= unent v }
6004 | "path-launcher" -> { c with pathlauncher
= unent v }
6005 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6006 | "invert-colors" -> { c with invert
= bool_of_string
v }
6007 | "brightness" -> { c with colorscale
= float_of_string
v }
6008 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6010 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6012 let (n, _, _) as nab
= multicolumns_of_string v in
6014 then { c with columns
= Csplit
(-n, [||]) }
6015 else { c with columns
= Cmulti
(nab
, [||]) }
6016 | "birds-eye-columns" ->
6017 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6018 | "selection-command" -> { c with selcmd
= unent v }
6019 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6020 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6021 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6022 | "multi-column-centering" -> { c with multicenter
= bool_of_string
v }
6025 prerr_endline
("Error processing attribute (`" ^
6026 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6029 let rec fold c = function
6032 let c = apply c k v in
6035 fold { c with keyhashes
= copykeyhashes c } attrs
;
6038 let fromstring f pos
n v d =
6041 dolog "Error processing attribute (%S=%S) at %d\n%s"
6042 n v pos
(Printexc.to_string exn
)
6047 let bookmark_of attrs
=
6048 let rec fold title page
rely visy
= function
6049 | ("title", v) :: rest
-> fold v page
rely visy rest
6050 | ("page", v) :: rest
-> fold title v rely visy rest
6051 | ("rely", v) :: rest
-> fold title page
v visy rest
6052 | ("visy", v) :: rest
-> fold title page
rely v rest
6053 | _ :: rest
-> fold title page
rely visy rest
6054 | [] -> title, page
, rely, visy
6056 fold "invalid" "0" "0" "0" attrs
6060 let rec fold path page
rely pan visy
= function
6061 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6062 | ("page", v) :: rest
-> fold path v rely pan visy rest
6063 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6064 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6065 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6066 | _ :: rest
-> fold path page
rely pan visy rest
6067 | [] -> path, page
, rely, pan
, visy
6069 fold "" "0" "0" "0" "0" attrs
6073 let rec fold rs ls
= function
6074 | ("out", v) :: rest
-> fold v ls rest
6075 | ("in", v) :: rest
-> fold rs
v rest
6076 | _ :: rest
-> fold ls rs rest
6082 let setconf dst
src =
6083 dst
.scrollbw
<- src.scrollbw
;
6084 dst
.scrollh
<- src.scrollh
;
6085 dst
.icase
<- src.icase
;
6086 dst
.preload <- src.preload;
6087 dst
.pagebias
<- src.pagebias
;
6088 dst
.verbose
<- src.verbose
;
6089 dst
.scrollstep
<- src.scrollstep
;
6090 dst
.maxhfit
<- src.maxhfit
;
6091 dst
.crophack
<- src.crophack
;
6092 dst
.autoscrollstep
<- src.autoscrollstep
;
6093 dst
.maxwait
<- src.maxwait
;
6094 dst
.hlinks
<- src.hlinks
;
6095 dst
.underinfo
<- src.underinfo
;
6096 dst
.interpagespace
<- src.interpagespace
;
6097 dst
.zoom <- src.zoom;
6098 dst
.presentation
<- src.presentation
;
6099 dst
.angle
<- src.angle
;
6100 dst
.winw <- src.winw;
6101 dst
.winh
<- src.winh
;
6102 dst
.savebmarks
<- src.savebmarks
;
6103 dst
.memlimit
<- src.memlimit
;
6104 dst
.proportional
<- src.proportional
;
6105 dst
.texcount
<- src.texcount
;
6106 dst
.sliceheight
<- src.sliceheight
;
6107 dst
.thumbw
<- src.thumbw
;
6108 dst
.jumpback
<- src.jumpback
;
6109 dst
.bgcolor
<- src.bgcolor
;
6110 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6111 dst
.tilew
<- src.tilew
;
6112 dst
.tileh
<- src.tileh
;
6113 dst
.mustoresize
<- src.mustoresize
;
6114 dst
.checkers
<- src.checkers
;
6115 dst
.aalevel
<- src.aalevel
;
6116 dst
.trimmargins
<- src.trimmargins
;
6117 dst
.trimfuzz
<- src.trimfuzz
;
6118 dst
.urilauncher
<- src.urilauncher
;
6119 dst
.colorspace
<- src.colorspace
;
6120 dst
.invert
<- src.invert
;
6121 dst
.colorscale
<- src.colorscale
;
6122 dst
.redirectstderr <- src.redirectstderr;
6123 dst
.ghyllscroll
<- src.ghyllscroll
;
6124 dst
.columns
<- src.columns
;
6125 dst
.beyecolumns
<- src.beyecolumns
;
6126 dst
.selcmd
<- src.selcmd
;
6127 dst
.updatecurs
<- src.updatecurs
;
6128 dst
.pathlauncher
<- src.pathlauncher
;
6129 dst
.keyhashes
<- copykeyhashes src;
6130 dst
.hfsize
<- src.hfsize
;
6131 dst
.hscrollstep
<- src.hscrollstep
;
6132 dst
.pgscale <- src.pgscale;
6133 dst
.multicenter
<- src.multicenter
;
6137 let h = Hashtbl.create
10 in
6138 let dc = { defconf with angle
= defconf.angle
} in
6139 let rec toplevel v t spos
_ =
6141 | Vdata
| Vcdata
| Vend
-> v
6142 | Vopen
("llppconfig", _, closed
) ->
6145 else { v with f = llppconfig
}
6147 error
"unexpected subelement at top level" s spos
6148 | Vclose
_ -> error
"unexpected close at top level" s spos
6150 and llppconfig
v t spos
_ =
6152 | Vdata
| Vcdata
-> v
6153 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6154 | Vopen
("defaults", attrs
, closed
) ->
6155 let c = config_of dc attrs
in
6159 else { v with f = defaults
}
6161 | Vopen
("ui-font", attrs
, closed
) ->
6162 let rec getsize size
= function
6164 | ("size", v) :: rest
->
6166 fromstring int_of_string spos
"size" v fstate.fontsize
in
6168 | l -> getsize size l
6170 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6173 else { v with f = uifont
(Buffer.create
10) }
6175 | Vopen
("doc", attrs
, closed
) ->
6176 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6177 let path = unent pathent
6178 and pageno = fromstring int_of_string spos
"page" spage
0
6179 and rely = fromstring float_of_string spos
"rely" srely
0.0
6180 and pan
= fromstring int_of_string spos
"pan" span
0
6181 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6182 let c = config_of dc attrs
in
6183 let anchor = (pageno, rely, visy
) in
6185 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6186 else { v with f = doc
path pan
anchor c [] }
6189 error
"unexpected subelement in llppconfig" s spos
6191 | Vclose
"llppconfig" -> { v with f = toplevel }
6192 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6194 and defaults
v t spos
_ =
6196 | Vdata
| Vcdata
-> v
6197 | Vend
-> error
"unexpected end of input in defaults" s spos
6198 | Vopen
("keymap", attrs
, closed
) ->
6200 try List.assoc
"mode" attrs
6201 with Not_found
-> "global" in
6206 let h = findkeyhash dc modename in
6207 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6210 { v with f = pkeymap
ret KeyMap.empty }
6212 | Vopen
(_, _, _) ->
6213 error
"unexpected subelement in defaults" s spos
6215 | Vclose
"defaults" ->
6216 { v with f = llppconfig
}
6218 | Vclose
_ -> error
"unexpected close in defaults" s spos
6220 and uifont
b v t spos
epos =
6223 Buffer.add_substring
b s spos
(epos - spos
);
6225 | Vopen
(_, _, _) ->
6226 error
"unexpected subelement in ui-font" s spos
6227 | Vclose
"ui-font" ->
6228 if String.length
!fontpath = 0
6229 then fontpath := Buffer.contents
b;
6230 { v with f = llppconfig
}
6231 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6232 | Vend
-> error
"unexpected end of input in ui-font" s spos
6234 and doc
path pan
anchor c bookmarks
v t spos
_ =
6236 | Vdata
| Vcdata
-> v
6237 | Vend
-> error
"unexpected end of input in doc" s spos
6238 | Vopen
("bookmarks", _, closed
) ->
6241 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6243 | Vopen
("keymap", attrs
, closed
) ->
6245 try List.assoc
"mode" attrs
6246 with Not_found
-> "global"
6252 let h = findkeyhash c modename in
6253 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6254 doc
path pan
anchor c bookmarks
6256 { v with f = pkeymap
ret KeyMap.empty }
6258 | Vopen
(_, _, _) ->
6259 error
"unexpected subelement in doc" s spos
6262 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6263 { v with f = llppconfig
}
6265 | Vclose
_ -> error
"unexpected close in doc" s spos
6267 and pkeymap
ret keymap
v t spos
_ =
6269 | Vdata
| Vcdata
-> v
6270 | Vend
-> error
"unexpected end of input in keymap" s spos
6271 | Vopen
("map", attrs
, closed
) ->
6272 let r, l = map_of attrs
in
6273 let kss = fromstring keys_of_string spos
"in" r [] in
6274 let lss = fromstring keys_of_string spos
"out" l [] in
6278 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6279 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6282 then { v with f = pkeymap
ret keymap }
6285 { v with f = skip
"map" f }
6288 error
"unexpected subelement in keymap" s spos
6290 | Vclose
"keymap" ->
6291 { v with f = ret keymap }
6293 | Vclose
_ -> error
"unexpected close in keymap" s spos
6295 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6297 | Vdata
| Vcdata
-> v
6298 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6299 | Vopen
("item", attrs
, closed
) ->
6300 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6301 let page = fromstring int_of_string spos
"page" spage
0
6302 and rely = fromstring float_of_string spos
"rely" srely
0.0
6303 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6305 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6308 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6311 { v with f = skip
"item" f }
6314 error
"unexpected subelement in bookmarks" s spos
6316 | Vclose
"bookmarks" ->
6317 { v with f = doc
path pan
anchor c bookmarks }
6319 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6321 and skip tag
f v t spos
_ =
6323 | Vdata
| Vcdata
-> v
6325 error
("unexpected end of input in skipped " ^ tag
) s spos
6326 | Vopen
(tag'
, _, closed
) ->
6330 let f'
() = { v with f = skip tag
f } in
6331 { v with f = skip tag'
f'
}
6335 else error
("unexpected close in skipped " ^ tag
) s spos
6338 parse
{ f = toplevel; accu = () } s;
6344 let len = in_channel_length ic
in
6345 let s = String.create
len in
6346 really_input ic
s 0 len;
6349 | Parse_error
(msg
, s, pos
) ->
6350 let subs = subs s pos
in
6351 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6352 failwith
("parse error: " ^
s)
6355 failwith
("config load error: " ^
Printexc.to_string exn
)
6361 let dir = Filename.concat
home ".config" in
6362 if Sys.is_directory
dir then dir else home
6365 Filename.concat
dir "llpp.conf"
6368 let confpath = ref defconfpath;;
6371 if Sys.file_exists
!confpath
6374 (try Some
(open_in_bin
!confpath)
6377 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6378 Printexc.to_string exn
);
6387 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6388 Printexc.to_string exn
);
6394 f (Hashtbl.create
0, defconf)
6399 let pc, pb
, px, pa
=
6401 Hashtbl.find h (Filename.basename
state.path)
6402 with Not_found
-> dc, [], 0, emptyanchor
6406 state.bookmarks <- pb
;
6408 state.scrollw
<- conf.scrollbw
;
6410 then state.anchor <- pa
;
6411 cbput state.hists
.nav pa
;
6416 let add_attrs bb always
dc c =
6419 then Printf.bprintf bb
"\n %s='%b'" s a
6422 then Printf.bprintf bb
"\n %s='%d'" s a
6425 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6428 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6431 then Printf.bprintf bb
"\n %s='%f'" s a
6435 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6439 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6443 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6447 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6453 | Some
(_N
, _A
, _B
) ->
6454 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6464 else string_of_float
f
6466 Printf.bprintf bb
"\n %s='%s'" s v
6471 | Cmulti
((n, a, b), _) when n > 1 ->
6472 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6473 | Csplit
(n, _) when n > 1 ->
6474 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6480 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6485 then dc.winw, dc.winh
6487 match state.fullscreen
with
6489 | None
-> c.winw, c.winh
6491 oi
"width" w dc.winw;
6492 oi
"height" h dc.winh
;
6493 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6494 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6495 ob "case-insensitive-search" c.icase
dc.icase
;
6496 ob "preload" c.preload dc.preload;
6497 oi
"page-bias" c.pagebias
dc.pagebias
;
6498 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6499 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6500 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6501 ob "crop-hack" c.crophack
dc.crophack
;
6502 oW
"throttle" c.maxwait
dc.maxwait
;
6503 ob "highlight-links" c.hlinks
dc.hlinks
;
6504 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6505 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6506 oz
"zoom" c.zoom dc.zoom;
6507 ob "presentation" c.presentation
dc.presentation
;
6508 oi
"rotation-angle" c.angle
dc.angle
;
6509 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6510 ob "proportional-display" c.proportional
dc.proportional
;
6511 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6512 oi
"tex-count" c.texcount
dc.texcount
;
6513 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6514 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6515 ob "persistent-location" c.jumpback
dc.jumpback
;
6516 oc
"background-color" c.bgcolor
dc.bgcolor
;
6517 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6518 oi
"tile-width" c.tilew
dc.tilew
;
6519 oi
"tile-height" c.tileh
dc.tileh
;
6520 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6521 ob "checkers" c.checkers
dc.checkers
;
6522 oi
"aalevel" c.aalevel
dc.aalevel
;
6523 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6524 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6525 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6526 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6527 oC
"color-space" c.colorspace
dc.colorspace
;
6528 ob "invert-colors" c.invert
dc.invert
;
6529 oF
"brightness" c.colorscale
dc.colorscale
;
6530 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6531 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6532 oco
"columns" c.columns
dc.columns
;
6533 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6534 os
"selection-command" c.selcmd
dc.selcmd
;
6535 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6536 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6537 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6538 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6539 ob "multi-column-centering" c.multicenter
dc.multicenter
;
6542 let keymapsbuf always
dc c =
6543 let bb = Buffer.create
16 in
6544 let rec loop = function
6546 | (modename, h) :: rest
->
6547 let dh = findkeyhash dc modename in
6548 if always
|| h <> dh
6550 if Hashtbl.length
h > 0
6552 if Buffer.length
bb > 0
6553 then Buffer.add_char
bb '
\n'
;
6554 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6555 Hashtbl.iter
(fun i
o ->
6556 let isdifferent = always
||
6558 let dO = Hashtbl.find dh i
in
6560 with Not_found
-> true
6565 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6566 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6567 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6568 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6569 Buffer.add_string
bb (Wsi.keyname
k);
6572 let rec loop = function
6574 | km
:: [] -> addkm km
6575 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6579 Buffer.add_string
bb "<map in='";
6583 Buffer.add_string
bb "' out='";
6585 Buffer.add_string
bb "'/>\n"
6588 Buffer.add_string
bb "' out='";
6590 Buffer.add_string
bb "'/>\n"
6592 | KMmulti
(ins, kms
) ->
6593 Buffer.add_char
bb ' '
;
6595 Buffer.add_string
bb "' out='";
6597 Buffer.add_string
bb "'/>\n"
6599 Buffer.add_string
bb "</keymap>";
6609 let uifontsize = fstate.fontsize
in
6610 let bb = Buffer.create
32768 in
6612 let dc = if conf.bedefault
then conf else dc in
6613 Buffer.add_string
bb "<llppconfig>\n";
6615 if String.length
!fontpath > 0
6617 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6623 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6626 Buffer.add_string
bb "<defaults ";
6627 add_attrs bb true dc dc;
6628 let kb = keymapsbuf true dc dc in
6629 if Buffer.length
kb > 0
6631 Buffer.add_string
bb ">\n";
6632 Buffer.add_buffer
bb kb;
6633 Buffer.add_string
bb "\n</defaults>\n";
6635 else Buffer.add_string
bb "/>\n";
6637 let adddoc path pan
anchor c bookmarks =
6638 if bookmarks == [] && c = dc && anchor = emptyanchor
6641 Printf.bprintf
bb "<doc path='%s'"
6642 (enent
path 0 (String.length
path));
6644 if anchor <> emptyanchor
6646 let n, rely, visy
= anchor in
6647 Printf.bprintf
bb " page='%d'" n;
6650 Printf.bprintf
bb " rely='%f'" rely
6652 if abs_float visy
> 1e-6
6654 Printf.bprintf
bb " visy='%f'" visy
6659 then Printf.bprintf
bb " pan='%d'" pan
;
6661 add_attrs bb false dc c;
6662 let kb = keymapsbuf false dc c in
6664 begin match bookmarks with
6666 if Buffer.length
kb > 0
6668 Buffer.add_string
bb ">\n";
6669 Buffer.add_buffer
bb kb;
6670 Buffer.add_string
bb "\n</doc>\n";
6672 else Buffer.add_string
bb "/>\n"
6674 Buffer.add_string
bb ">\n<bookmarks>\n";
6675 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6677 "<item title='%s' page='%d'"
6678 (enent
title 0 (String.length
title))
6683 Printf.bprintf
bb " rely='%f'" rely
6685 if abs_float visy
> 1e-6
6687 Printf.bprintf
bb " visy='%f'" visy
6689 Buffer.add_string
bb "/>\n";
6691 Buffer.add_string
bb "</bookmarks>";
6692 if Buffer.length
kb > 0
6694 Buffer.add_string
bb "\n";
6695 Buffer.add_buffer
bb kb;
6697 Buffer.add_string
bb "\n</doc>\n";
6703 match state.mode with
6704 | Birdseye
(c, pan, _, _, _) ->
6706 match conf.columns
with
6707 | Cmulti
((c, _, _), _) -> Some
c
6711 match c.columns
with
6712 | Cmulti
(c, _) -> Cmulti
(c, [||])
6713 | Csingle
_ -> Csingle
[||]
6714 | Csplit
_ -> failwith
"quit from bird's eye while split"
6716 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6717 | _ -> state.x, conf
6719 let basename = Filename.basename state.path in
6720 adddoc basename pan (getanchor ())
6722 let autoscrollstep =
6723 match state.autoscroll
with
6725 | None
-> conf.autoscrollstep
6727 match state.mode with
6728 | Birdseye
(bc
, _, _, _, _) ->
6731 presentation
= bc
.presentation
;
6732 interpagespace
= bc
.interpagespace
;
6733 maxwait
= bc
.maxwait
;
6734 autoscrollstep = autoscrollstep }
6735 | _ -> { conf with autoscrollstep = autoscrollstep }
6737 (if conf.savebmarks
then state.bookmarks else []);
6739 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6741 then adddoc path x anchor c bookmarks
6743 Buffer.add_string
bb "</llppconfig>";
6746 if Buffer.length
bb > 0
6749 let tmp = !confpath ^
".tmp" in
6750 let oc = open_out_bin
tmp in
6751 Buffer.output_buffer
oc bb;
6753 Unix.rename
tmp !confpath;
6756 ("error while saving configuration: " ^
Printexc.to_string exn
)
6761 let trimcachepath = ref "" in
6764 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6765 "<password> Set password");
6767 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6768 "<path> Set path to the user interface font");
6770 ("-c", Arg.String
(fun s -> Config.confpath := s),
6771 "<path> Set path to the configuration file");
6773 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6774 "<path> Set path to the trim cache file");
6776 ("-v", Arg.Unit
(fun () ->
6778 "%s\nconfiguration path: %s\n"
6782 exit
0), " Print version and exit");
6785 (fun s -> state.path <- s)
6786 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6788 if String.length
state.path = 0
6789 then (prerr_endline
"file name missing"; exit
1);
6793 let globalkeyhash = findkeyhash conf "global" in
6794 let wsfd, winw, winh
= Wsi.init
(object
6796 if nogeomcmds state.geomcmds
|| platform == Posx
6799 GlClear.color (scalecolor2 conf.bgcolor
);
6800 GlClear.clear
[`
color];
6802 method display = display ()
6803 method reshape w h = reshape w h
6804 method mouse b d x y m = mouse b d x y m
6805 method motion x y = state.mpos
<- (x, y); motion x y
6806 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6808 let mascm = m land (
6809 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6811 match state.keystate
with
6813 let km = k, mascm in
6816 let modehash = state.uioh#
modehash in
6817 try Hashtbl.find modehash km
6819 try Hashtbl.find globalkeyhash km
6820 with Not_found
-> KMinsrt
(k, m)
6822 | KMinsrt
(k, m) -> keyboard k m
6823 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6824 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6826 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6827 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6828 state.keystate
<- KSnone
6829 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6830 state.keystate
<- KSinto
(keys
, insrt
)
6832 state.keystate
<- KSnone
6834 method enter
x y = state.mpos
<- (x, y); pmotion x y
6835 method leave = state.mpos
<- (-1, -1)
6836 method quit
= raise Quit
6837 end) conf.winw conf.winh
(platform = Posx
) in
6842 List.exists
GlMisc.check_extension
6843 [ "GL_ARB_texture_rectangle"
6844 ; "GL_EXT_texture_recangle"
6845 ; "GL_NV_texture_rectangle" ]
6847 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6850 match Ne.pipe () with
6852 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6856 match Ne.pipe () with
6858 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6868 setcheckers conf.checkers
;
6872 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6873 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6874 !Config.fontpath, !trimcachepath
6878 state.text <- "Opening " ^
state.path;
6880 opendoc state.path state.password
;
6883 let rec loop deadline
=
6885 match state.errfd
with
6886 | None
-> [state.sr
; state.wsfd]
6887 | Some fd
-> [state.sr
; state.wsfd; fd
]
6891 state.redisplay
<- false;
6898 if deadline
= infinity
6900 else max
0.0 (deadline
-. now)
6905 try Unix.select
r [] [] timeout
6906 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6912 if state.ghyll
== noghyll
6914 match state.autoscroll
with
6915 | Some step
when step
!= 0 ->
6916 let y = state.y + step
in
6920 else if y >= state.maxy then 0 else y
6923 if state.mode = View
6924 then state.text <- "";
6927 else deadline
+. 0.01
6932 let rec checkfds = function
6934 | fd
:: rest
when fd
= state.sr
->
6935 let cmd = readcmd state.sr
in
6939 | fd
:: rest
when fd
= state.wsfd ->
6944 let s = String.create
80 in
6945 let n = Unix.read fd
s 0 80 in
6946 if conf.redirectstderr
6948 Buffer.add_substring
state.errmsgs
s 0 n;
6949 state.newerrmsgs
<- true;
6950 state.redisplay
<- true;
6953 prerr_string
(String.sub
s 0 n);
6961 if deadline
= infinity
6965 match state.autoscroll
with
6966 | Some step
when step
!= 0 -> deadline1
6967 | _ -> if state.ghyll
== noghyll then infinity
else deadline1