6 | Ulinkgoto
of (int * int)
8 | Uunexpected
of string
11 | Uremote
of (string * int)
12 and facename
= string;;
14 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
15 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* fontpath
* trimcachepath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
37 and trimcachepath
= string
40 and irect
= (int * int * int * int)
41 and trimparams
= (trimmargins
* irect
)
42 and colorspace
= | Rgb
| Bgr
| Gray
51 | LDfirstvisible
of (int * int * int)
66 | KMmulti
of key list
* key list
68 and keyhash
= (key
, keymap
) Hashtbl.t
71 | KSinto
of (key list
* key list
)
74 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
75 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
77 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
79 external init
: pipe
-> params
-> unit = "ml_init";;
80 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
81 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
82 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
83 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
84 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
85 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
86 external measurestr
: int -> string -> float = "ml_measure_string";;
87 external getmaxw
: unit -> float = "ml_getmaxw";;
88 external postprocess
:
89 opaque
-> int -> int -> int -> (int * string * int) -> int = "ml_postprocess";;
90 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
91 external platform
: unit -> platform
= "ml_platform";;
92 external setaalevel
: int -> unit = "ml_setaalevel";;
93 external realloctexts
: int -> bool = "ml_realloctexts";;
94 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
95 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
96 external getlink
: opaque
-> int -> under
= "ml_getlink";;
97 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
98 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
99 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
100 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
102 let platform_to_string = function
103 | Punknown
-> "unknown"
107 | Pfreebsd
-> "FreeBSD"
108 | Pdragonflybsd
-> "DragonflyBSD"
109 | Popenbsd
-> "OpenBSD"
110 | Pnetbsd
-> "NetBSD"
111 | Pcygwin
-> "Cygwin"
114 let platform = platform ();;
117 if platform = Pcygwin
119 let sh = "/bin/sh" in
120 let args = [|sh; "-c"; cmd
|] in
121 let rec std si so se
= function
123 | (fd
, 0) :: rest
-> std fd so se rest
124 | (fd
, -1) :: rest
->
125 Unix.set_close_on_exec fd
;
128 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
130 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
131 ignore
(Unix.create_process
sh args si so se
)
140 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
143 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
145 type mpos
= int * int
147 | Msel
of (mpos
* mpos
)
149 | Mscrolly
| Mscrollx
150 | Mzoom
of (int * int)
151 | Mzoomrect
of (mpos
* mpos
)
155 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
156 and onkey
= string -> int -> te
157 and ondone
= string -> unit
158 and histcancel
= unit -> unit
159 and onhist
= ((histcmd
-> string) * histcancel
)
160 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
161 and cancelonempty
= bool
166 | TEswitch
of textentry
177 let bound v minv maxv
=
178 max minv
(min maxv v
);
182 { store
= Array.create n v
189 let drawstring size x y s
=
191 Gl.enable `texture_2d
;
192 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
193 ignore
(drawstr size x y s
);
195 Gl.disable `texture_2d
;
198 let drawstring1 size x y s
=
202 let drawstring2 size x y fmt
=
203 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
206 let cbcap b
= Array.length b
.store
;;
211 b
.wc
<- (b
.wc
+ 1) mod cap;
213 b
.len
<- min
(b
.len
+ 1) cap;
216 let cbempty b
= b
.len
= 0;;
218 let cbgetg b circular dir
=
222 let rc = b
.rc + dir
in
234 else max
0 (min
rc (b
.len
-1))
240 let cbget b
= cbgetg b
false;;
241 let cbgetc b
= cbgetg b
true;;
259 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
260 dolog " WxH %dx%d" l
.pagew l
.pageh
;
261 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
262 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
263 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
264 dolog " column %d" l
.pagecol
;
268 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
270 dolog " x0,y0=(% f, % f)" x0 y0
;
271 dolog " x1,y1=(% f, % f)" x1 y1
;
272 dolog " x2,y2=(% f, % f)" x2 y2
;
273 dolog " x3,y3=(% f, % f)" x3 y3
;
277 type multicolumns
= multicol
* pagegeom
278 and singlecolumn
= pagegeom
279 and splitcolumns
= columncount
* pagegeom
280 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
281 and multicol
= columncount
* covercount
* covercount
283 and columncount
= int
284 and covercount
= int;;
287 { mutable scrollbw
: int
288 ; mutable scrollh
: int
289 ; mutable icase
: bool
290 ; mutable preload
: bool
291 ; mutable pagebias
: int
292 ; mutable verbose
: bool
293 ; mutable debug
: bool
294 ; mutable scrollstep
: int
295 ; mutable hscrollstep
: int
296 ; mutable maxhfit
: bool
297 ; mutable crophack
: bool
298 ; mutable autoscrollstep
: int
299 ; mutable maxwait
: float option
300 ; mutable hlinks
: bool
301 ; mutable underinfo
: bool
302 ; mutable interpagespace
: interpagespace
303 ; mutable zoom
: float
304 ; mutable presentation
: bool
305 ; mutable angle
: angle
308 ; mutable savebmarks
: bool
309 ; mutable proportional
: proportional
310 ; mutable trimmargins
: trimmargins
311 ; mutable trimfuzz
: irect
312 ; mutable memlimit
: memsize
313 ; mutable texcount
: texcount
314 ; mutable sliceheight
: sliceheight
315 ; mutable thumbw
: width
316 ; mutable jumpback
: bool
317 ; mutable bgcolor
: float * float * float
318 ; mutable bedefault
: bool
319 ; mutable scrollbarinpm
: bool
320 ; mutable tilew
: int
321 ; mutable tileh
: int
322 ; mutable mustoresize
: memsize
323 ; mutable checkers
: bool
324 ; mutable aalevel
: int
325 ; mutable urilauncher
: string
326 ; mutable pathlauncher
: string
327 ; mutable colorspace
: colorspace
328 ; mutable invert
: bool
329 ; mutable colorscale
: float
330 ; mutable redirectstderr
: bool
331 ; mutable ghyllscroll
: (int * int * int) option
332 ; mutable columns
: columns
333 ; mutable beyecolumns
: columncount
option
334 ; mutable selcmd
: string
335 ; mutable updatecurs
: bool
336 ; mutable keyhashes
: (string * keyhash
) list
337 ; mutable hfsize
: int
338 ; mutable pgscale
: float
339 ; mutable multicenter
: bool
342 | Csingle
of singlecolumn
343 | Cmulti
of multicolumns
344 | Csplit
of splitcolumns
347 type anchor
= pageno
* top
* dtop
;;
349 type outline
= string * int * anchor
;;
351 type rect
= float * float * float * float * float * float * float * float;;
353 type tile
= opaque
* pixmapsize
* elapsed
354 and elapsed
= float;;
355 type pagemapkey
= pageno
* gen
;;
356 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
360 let emptyanchor = (0, 0.0, 0.0);;
362 type infochange
= | Memused
| Docinfo
| Pdim
;;
364 class type uioh
= object
365 method display
: unit
366 method key
: int -> int -> uioh
367 method button
: int -> bool -> int -> int -> int -> uioh
368 method motion
: int -> int -> uioh
369 method pmotion
: int -> int -> uioh
370 method infochanged
: infochange
-> unit
371 method scrollpw
: (int * float * float)
372 method scrollph
: (int * float * float)
373 method modehash
: keyhash
377 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
378 | Textentry
of (textentry
* onleave
)
380 | LinkNav
of linktarget
381 and onleave
= leavetextentrystatus
-> unit
382 and leavetextentrystatus
= | Cancel
| Confirm
383 and helpitem
= string * int * action
386 | Action
of (uioh
-> uioh
)
388 | Ltexact
of (pageno
* int)
392 let isbirdseye = function Birdseye _
-> true | _
-> false;;
393 let istextentry = function Textentry _
-> true | _
-> false;;
397 | Loading
of (page
* gen
)
399 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
401 | Outlining
of outline list
404 let emptykeyhash = Hashtbl.create
0;;
405 let nouioh : uioh
= object (self
)
407 method key _ _
= self
408 method button _ _ _ _ _
= self
409 method motion _ _
= self
410 method pmotion _ _
= self
411 method infochanged _
= ()
412 method scrollpw
= (0, nan
, nan
)
413 method scrollph
= (0, nan
, nan
)
414 method modehash
= emptykeyhash
418 { mutable sr
: Unix.file_descr
419 ; mutable sw
: Unix.file_descr
420 ; mutable wsfd
: Unix.file_descr
421 ; mutable errfd
: Unix.file_descr
option
422 ; mutable stderr
: Unix.file_descr
423 ; mutable errmsgs
: Buffer.t
424 ; mutable newerrmsgs
: bool
428 ; mutable scrollw
: int
429 ; mutable hscrollh
: int
430 ; mutable anchor
: anchor
431 ; mutable ranchors
: (string * string * anchor
) list
433 ; mutable layout
: page list
434 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
435 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
436 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
437 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
438 ; mutable pagecount
: int
439 ; mutable currently
: currently
440 ; mutable mstate
: mstate
441 ; mutable searchpattern
: string
442 ; mutable rects
: (pageno
* recttype
* rect
) list
443 ; mutable rects1
: (pageno
* recttype
* rect
) list
444 ; mutable text
: string
445 ; mutable fullscreen
: (width
* height
) option
446 ; mutable mode
: mode
447 ; mutable uioh
: uioh
448 ; mutable outlines
: outline array
449 ; mutable bookmarks
: outline list
450 ; mutable path
: string
451 ; mutable password
: string
452 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
453 ; mutable memused
: memsize
455 ; mutable throttle
: (page list
* int * float) option
456 ; mutable autoscroll
: int option
457 ; mutable ghyll
: (int option -> unit)
458 ; mutable help
: helpitem array
459 ; mutable docinfo
: (int * string) list
460 ; mutable texid
: GlTex.texture_id
option
462 ; mutable prevzoom
: float
463 ; mutable progress
: float
464 ; mutable redisplay
: bool
465 ; mutable mpos
: mpos
466 ; mutable keystate
: keystate
467 ; mutable glinks
: bool
468 ; mutable prevcolumns
: (columns
* float) option
471 { pat
: string circbuf
472 ; pag
: string circbuf
473 ; nav
: anchor circbuf
474 ; sel
: string circbuf
496 ; presentation
= false
501 ; proportional
= true
502 ; trimmargins
= false
503 ; trimfuzz
= (0,0,0,0)
504 ; memlimit
= 32 lsl 20
509 ; bgcolor
= (0.5, 0.5, 0.5)
511 ; scrollbarinpm
= true
514 ; mustoresize
= 256 lsl 20
519 | Plinux
| Pfreebsd
| Pdragonflybsd
520 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
521 | Posx
-> "open \"%s\""
522 | Pcygwin
-> "cygstart \"%s\""
523 | Punknown
-> "echo %s")
524 ; pathlauncher
= "lp \"%s\""
527 | Plinux
| Pfreebsd
| Pdragonflybsd
528 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
535 ; redirectstderr
= false
537 ; columns
= Csingle
[||]
542 ; multicenter
= false
544 let mk n
= (n
, Hashtbl.create
1) in
558 let findkeyhash c name
=
559 try List.assoc name c
.keyhashes
560 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
563 let conf = { defconf with angle
= defconf.angle
};;
565 let pgscale h
= truncate
(float h
*. conf.pgscale);;
568 { mutable fontsize
: int
569 ; mutable wwidth
: float
570 ; mutable maxrows
: int
582 fstate.fontsize
<- n
;
583 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
584 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
588 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
589 let len = String.length s
in
590 if colonpos >= 0 && colonpos + 3 < len
592 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
595 try String.rindex_from s
colonpos ' '
599 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
602 | "http" | "ftp" | "mailto" ->
604 try String.index_from s
colonpos ' '
605 with Not_found
-> len
607 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
615 if String.length
conf.urilauncher
= 0
616 then print_endline uri
618 let url = geturl uri
in
619 if String.length
url = 0
620 then print_endline uri
622 let re = Str.regexp
"%s" in
623 let command = Str.global_replace
re url conf.urilauncher
in
627 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
633 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
634 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
638 let strings = version () :: "" :: Help.keys
in
641 let url = geturl s
in
642 if String.length
url > 0
643 then (s
, 0, Action
(fun u
-> gotouri url; u
))
644 else (s
, 0, Noaction
)
649 let firstgeomcmds = "", [];;
656 ; stderr
= Unix.stderr
657 ; errmsgs
= Buffer.create
0
664 ; anchor
= emptyanchor
668 ; tilelru
= Queue.create
()
669 ; pagemap
= Hashtbl.create
10
670 ; tilemap
= Hashtbl.create
10
685 ; geomcmds
= firstgeomcmds
687 { nav
= cbnew 10 emptyanchor
714 Printf.kprintf prerr_endline fmt
716 Printf.kprintf ignore fmt
720 if String.length
conf.pathlauncher
= 0
721 then print_endline
state.path
723 let re = Str.regexp
"%s" in
724 let command = Str.global_replace
re state.path
conf.pathlauncher
in
728 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
734 type 'a t
= | Res
of 'a
| Exn
of exn
;;
737 try Res
(Unix.pipe ())
743 with exn
-> f
(Printexc.to_string exn
)
747 try Res
(Unix.dup fd
)
752 try Res
(Unix.dup2 fd1 fd2
)
757 let redirectstderr () =
758 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
759 if conf.redirectstderr
761 match Ne.pipe () with
763 dolog "failed to create stderr redirection pipes: %s"
764 (Printexc.to_string exn
)
767 begin match Ne.dup Unix.stderr
with
769 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
770 Ne.clo r
(clofail "pipe/r");
771 Ne.clo w
(clofail "pipe/w");
773 | Ne.Res dupstderr
->
774 begin match Ne.dup2 w
Unix.stderr
with
776 dolog "failed to dup2 to stderr: %s"
777 (Printexc.to_string exn
);
778 Ne.clo dupstderr
(clofail "stderr duplicate");
779 Ne.clo r
(clofail "redir pipe/r");
780 Ne.clo w
(clofail "redir pipe/w");
783 state.stderr
<- dupstderr
;
784 state.errfd
<- Some r
;
788 state.newerrmsgs
<- false;
789 begin match state.errfd
with
791 begin match Ne.dup2 state.stderr
Unix.stderr
with
793 dolog "failed to dup2 original stderr: %s"
794 (Printexc.to_string exn
)
796 Ne.clo fd
(clofail "dup of stderr");
797 Unix.dup2 state.stderr
Unix.stderr
;
802 prerr_string
(Buffer.contents
state.errmsgs
);
804 Buffer.clear
state.errmsgs
;
810 let postRedisplay who
=
812 then prerr_endline
("redisplay for " ^ who
);
813 state.redisplay
<- true;
817 let getopaque pageno
=
818 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
819 with Not_found
-> None
822 let putopaque pageno opaque
=
823 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
826 let pagetranslatepoint l x y
=
827 let dy = y
- l
.pagedispy
in
828 let y = dy + l
.pagey
in
829 let dx = x
- l
.pagedispx
in
830 let x = dx + l
.pagex
in
837 begin match getopaque l
.pageno
with
839 let x0 = l
.pagedispx
in
840 let x1 = x0 + l
.pagevw
in
841 let y0 = l
.pagedispy
in
842 let y1 = y0 + l
.pagevh
in
843 if y >= y0 && y <= y1 && x >= x0 && x <= x1
845 let px, py
= pagetranslatepoint l
x y in
846 match whatsunder opaque
px py
with
859 state.text
<- Printf.sprintf
"%c%s" c s
;
860 G.postRedisplay "showtext";
863 let undertext = function
866 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
867 | Utext s
-> "font: " ^ s
868 | Uunexpected s
-> "unexpected: " ^ s
869 | Ulaunch s
-> "launch: " ^ s
870 | Unamed s
-> "named: " ^ s
871 | Uremote
(filename
, pageno
) ->
872 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
875 let updateunder x y =
876 match getunder x y with
877 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
879 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
880 Wsi.setcursor
Wsi.CURSOR_INFO
881 | Ulinkgoto
(pageno
, _
) ->
883 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
884 Wsi.setcursor
Wsi.CURSOR_INFO
886 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
887 Wsi.setcursor
Wsi.CURSOR_TEXT
889 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
890 Wsi.setcursor
Wsi.CURSOR_INHERIT
892 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
893 Wsi.setcursor
Wsi.CURSOR_INHERIT
895 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
896 Wsi.setcursor
Wsi.CURSOR_INHERIT
897 | Uremote
(filename
, pageno
) ->
898 if conf.underinfo
then showtext 'r'
899 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
900 Wsi.setcursor
Wsi.CURSOR_INFO
903 let showlinktype under
=
909 let s = undertext under
in
914 let b = Buffer.create
(String.length
s + 1) in
915 Buffer.add_string
b s;
920 let colorspace_of_string s =
921 match String.lowercase
s with
925 | _
-> failwith
"invalid colorspace"
928 let int_of_colorspace = function
934 let colorspace_of_int = function
938 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
941 let colorspace_to_string = function
947 let intentry_with_suffix text key
=
949 if key
>= 32 && key
< 127
953 match Char.lowercase
c with
955 let text = addchar text c in
959 let text = addchar text c in
963 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
967 let multicolumns_to_string (n
, a
, b) =
969 then Printf.sprintf
"%d" n
970 else Printf.sprintf
"%d,%d,%d" n a
b;
973 let multicolumns_of_string s =
975 (int_of_string
s, 0, 0)
977 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
979 then failwith
"subtly broken"; (n
, a
, b)
985 let n = Unix.read fd
s 0 4 in
986 if n != 4 then failwith
"incomplete read(len)";
988 lor (Char.code
s.[0] lsl 24)
989 lor (Char.code
s.[1] lsl 16)
990 lor (Char.code
s.[2] lsl 8)
991 lor (Char.code
s.[3] lsl 0)
993 let s = String.create
len in
994 let n = Unix.read fd
s 0 len in
995 if n != len then failwith
"incomplete read(data)";
999 let btod b = if b then 1 else 0;;
1002 let b = Buffer.create
16 in
1003 Buffer.add_string
b "llll";
1006 let s = Buffer.contents
b in
1007 let n = String.length
s in
1009 (* dolog "wcmd %S" (String.sub s 4 len); *)
1010 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1011 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1012 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1013 s.[3] <- Char.chr
(len land 0xff);
1014 let n'
= Unix.write
state.sw
s 0 n in
1015 if n'
!= n then failwith
"write failed";
1020 let d = conf.winh
- h
in
1021 max
conf.interpagespace
((d + 1) / 2)
1024 let rowyh (c, coverA
, coverB
) b n =
1025 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1027 let _, _, vy
, (_, _, h
, _) = b.(n) in
1030 let n'
= n - coverA
in
1033 let e = min
state.pagecount
(s + c) in
1034 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1035 let _, _, y, (_, _, h
, _) = b.(m
) in
1036 let miny = min
miny y in
1037 let maxh = max
maxh h
in
1038 find (m
+1) miny maxh
1043 match conf.columns
with
1044 | Cmulti
((_, _, _) as cl
, b) ->
1045 if Array.length
b > 0
1047 let y, h
= rowyh cl
b (Array.length
b - 1) in
1048 y + h
+ (if conf.presentation
then calcips h
else 0)
1051 if Array.length
b > 0
1053 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1054 y + h
+ (if conf.presentation
then calcips h
else 0)
1057 if Array.length
b > 0
1059 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1064 let getpageyh pageno
=
1065 let pageno = bound pageno 0 (state.pagecount
-1) in
1066 match conf.columns
with
1068 if Array.length
b = 0
1071 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1073 if conf.presentation
1079 if Array.length
b = 0
1082 let y, h
= rowyh cl
b pageno in
1084 if conf.presentation
1090 if Array.length
b = 0
1094 let (_, _, y, (_, _, h
, _)) = b.(n) in
1098 let getpagedim pageno =
1101 | (n, _, _, _) as pdim
:: rest
->
1103 then (if n = pageno then pdim
else ppdim
)
1108 f (-1, -1, -1, -1) state.pdims
1111 let getpagey pageno = fst
(getpageyh pageno);;
1113 let nogeomcmds cmds
=
1115 | s, [] -> String.length
s = 0
1120 let ((c, coverA
, coverB
) as cl
), b =
1121 match conf.columns
with
1122 | Csingle
b -> (1, 0, 0), b
1123 | Cmulti
(c, b) -> c, b
1124 | Csplit
(_, b) -> (1, 0, 0), b
1126 let rec bsearch nmin nmax
=
1128 then bound nmin
0 (state.pagecount
-1)
1130 let n = (nmax
+ nmin
) / 2 in
1131 let vy, h
= rowyh cl
b n in
1133 if conf.presentation
1135 let ips = calcips h
in
1136 let y0 = vy - ips in
1137 let y1 = vy + h
+ ips in
1141 then 0, vy + h
+ conf.interpagespace
1143 let y0 = vy - conf.interpagespace
in
1144 y0, y0 + h
+ conf.interpagespace
1147 if y >= y0 && y < y1
1154 if n < state.pagecount
- coverB
1155 then ((n-coverA
)/c)*c + coverA
1162 then bsearch (n+1) nmax
1163 else bsearch nmin
(n-1)
1166 let r = bsearch 0 (state.pagecount
-1) in
1170 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1171 let sh = sh - state.hscrollh
in
1172 let rec fold accu
n =
1173 if n = Array.length
b
1176 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1179 || n = state.pagecount
- coverB
1180 || (n - coverA
) mod columns
= columns
- 1)
1186 let pagey = max
0 (y - vy) in
1187 let pagedispy = if pagey > 0 then 0 else vy - y in
1188 let pagedispx, pagex
=
1190 if n = coverA
- 1 || n = state.pagecount
- coverB
1191 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1192 else dx + xoff
+ state.x
1199 let vw = conf.winw
- state.scrollw
- pagedispx in
1200 let pw = w
- pagex
in
1203 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1204 if pagevw > 0 && pagevh > 0
1208 ; pagedimno
= pdimno
1215 ; pagedispx = pagedispx
1216 ; pagedispy = pagedispy
1228 List.rev
(fold [] (page_of_y y));
1231 let layoutS (columns
, b) y sh =
1232 let sh = sh - state.hscrollh
in
1233 let rec fold accu n =
1234 if n = Array.length
b
1237 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1244 let x = xoff
+ state.x in
1245 let pagey = max
0 (y - vy) in
1246 let pagedispy = if pagey > 0 then 0 else vy - y in
1247 let pagedispx, pagex
=
1261 let pagecolw = pagew
/columns
in
1263 if pagecolw < conf.winw
1264 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1268 let vw = conf.winw
- pagedispx - state.scrollw
in
1269 let pw = pagew
- pagex
in
1272 let pagevw = min
pagevw pagecolw in
1273 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1274 if pagevw > 0 && pagevh > 0
1277 { pageno = n/columns
1278 ; pagedimno
= pdimno
1285 ; pagedispx = pagedispx
1286 ; pagedispy = pagedispy
1287 ; pagecol
= n mod columns
1298 List.rev
(fold [] 0)
1302 if nogeomcmds state.geomcmds
1304 match conf.columns
with
1305 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1306 | Cmulti
c -> layoutN c y sh
1307 | Csplit
s -> layoutS s y sh
1312 let y = state.y + incr
in
1314 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1319 let tilex = l
.pagex
mod conf.tilew
in
1320 let tiley = l
.pagey mod conf.tileh
in
1322 let col = l
.pagex
/ conf.tilew
in
1323 let row = l
.pagey / conf.tileh
in
1325 let rec rowloop row y0 dispy h
=
1329 let dh = conf.tileh
- y0 in
1330 let dh = min h
dh in
1331 let rec colloop col x0 dispx w
=
1335 let dw = conf.tilew
- x0 in
1336 let dw = min w
dw in
1338 f col row dispx dispy
x0 y0 dw dh;
1339 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1342 colloop col tilex l
.pagedispx l
.pagevw;
1343 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1346 if l
.pagevw > 0 && l
.pagevh > 0
1347 then rowloop row tiley l
.pagedispy l
.pagevh;
1350 let gettileopaque l
col row =
1352 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1354 try Some
(Hashtbl.find state.tilemap
key)
1355 with Not_found
-> None
1358 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1359 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1360 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1363 let drawtiles l color
=
1365 let f col row x y tilex tiley w h
=
1366 match gettileopaque l
col row with
1367 | Some
(opaque
, _, t
) ->
1368 let params = x, y, w
, h
, tilex, tiley in
1372 GlFunc.blend_func `zero `one_minus_src_color
;
1374 drawtile
params opaque
;
1376 then Gl.disable `blend
;
1379 let s = Printf.sprintf
1383 let w = measurestr
fstate.fontsize
s in
1384 GlMisc.push_attrib
[`current
];
1385 GlDraw.color
(0.0, 0.0, 0.0);
1387 (float (x-2), float (y-2))
1388 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1389 GlDraw.color
(1.0, 1.0, 1.0);
1390 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1391 GlMisc.pop_attrib
();
1396 let lw = conf.winw
- state.scrollw
- x in
1399 let lh = conf.winh
- y in
1402 begin match state.texid
with
1404 Gl.enable `texture_2d
;
1405 GlTex.bind_texture `texture_2d id
;
1408 and x1 = float (x+w)
1409 and y1 = float (y+h
) in
1411 let tw = float w /. 64.0
1412 and th
= float h
/. 64.0 in
1413 let tx0 = float tilex /. 64.0
1414 and ty0
= float tiley /. 64.0 in
1416 and ty1
= ty0
+. th
in
1417 GlDraw.begins `quads
;
1418 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1419 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1420 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1421 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1424 Gl.disable `texture_2d
;
1426 GlDraw.color
(1.0, 1.0, 1.0);
1429 (float (x+w), float (y+h
));
1431 if w > 128 && h
> fstate.fontsize
+ 10
1433 GlDraw.color
(0.0, 0.0, 0.0);
1436 then (col*conf.tilew
, row*conf.tileh
)
1439 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1446 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1448 let tilevisible1 l
x y =
1450 and ax1
= l
.pagex
+ l
.pagevw
1452 and ay1
= l
.pagey + l
.pagevh in
1456 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1457 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1459 let rx0 = max
ax0 bx0
1460 and ry0
= max ay0 by0
1461 and rx1
= min ax1
bx1
1462 and ry1
= min ay1 by1
in
1464 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1465 nonemptyintersection
1468 let tilevisible layout n x y =
1469 let rec findpageinlayout m
= function
1470 | l
:: rest
when l
.pageno = n ->
1471 tilevisible1 l
x y || (
1472 match conf.columns
with
1473 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1476 | _ :: rest
-> findpageinlayout 0 rest
1479 findpageinlayout 0 layout;
1482 let tileready l
x y =
1483 tilevisible1 l
x y &&
1484 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1487 let tilepage n p
layout =
1488 let rec loop = function
1492 let f col row _ _ _ _ _ _ =
1493 if state.currently
= Idle
1495 match gettileopaque l
col row with
1498 let x = col*conf.tilew
1499 and y = row*conf.tileh
in
1501 let w = l
.pagew
- x in
1505 let h = l
.pageh
- y in
1508 wcmd "tile %s %d %d %d %d" p
x y w h;
1511 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1512 conf.tilew
, conf.tileh
1521 if nogeomcmds state.geomcmds
1525 let preloadlayout y =
1526 let y = if y < conf.winh
then 0 else y - conf.winh
in
1527 let h = conf.winh
*3 in
1532 let rec loop pages
=
1533 if state.currently
!= Idle
1538 begin match getopaque l
.pageno with
1540 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1541 state.currently
<- Loading
(l
, state.gen
);
1543 tilepage l
.pageno opaque pages
;
1548 if nogeomcmds state.geomcmds
1554 if conf.preload && state.currently
= Idle
1555 then load (preloadlayout state.y);
1558 let layoutready layout =
1559 let rec fold all ls
=
1560 all
&& match ls
with
1562 let seen = ref false in
1563 let allvisible = ref true in
1564 let foo col row _ _ _ _ _ _ =
1566 allvisible := !allvisible &&
1567 begin match gettileopaque l
col row with
1573 fold (!seen && !allvisible) rest
1576 let alltilesvisible = fold true layout in
1581 let y = bound y 0 state.maxy
in
1582 let y, layout, proceed
=
1583 match conf.maxwait
with
1584 | Some time
when state.ghyll
== noghyll ->
1585 begin match state.throttle
with
1587 let layout = layout y conf.winh
in
1588 let ready = layoutready layout in
1592 state.throttle
<- Some
(layout, y, now ());
1594 else G.postRedisplay "gotoy showall (None)";
1596 | Some
(_, _, started
) ->
1597 let dt = now () -. started
in
1600 state.throttle
<- None
;
1601 let layout = layout y conf.winh
in
1603 G.postRedisplay "maxwait";
1610 let layout = layout y conf.winh
in
1611 if true || layoutready layout
1612 then G.postRedisplay "gotoy ready";
1618 state.layout <- layout;
1619 begin match state.mode
with
1620 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1621 let rec loop = function
1623 state.mode
<- LinkNav
(Ltgendir
0)
1624 | l
:: _ when l
.pageno = pageno ->
1625 begin match getopaque pageno with
1627 state.mode
<- LinkNav
(Ltgendir
0)
1629 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1630 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1631 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1632 then state.mode
<- LinkNav
(Ltgendir
0)
1634 | _ :: rest
-> loop rest
1639 begin match state.mode
with
1640 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1641 if not
(pagevisible layout pageno)
1643 match state.layout with
1646 state.mode
<- Birdseye
(
1647 conf, leftx
, l
.pageno, hooverpageno
, anchor
1650 | LinkNav
(Ltgendir dir
as lt
) ->
1652 let rec loop = function
1655 match getopaque l
.pageno with
1661 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1663 if dir
> 0 then LDfirst
else LDlast
1669 | Lnotfound
-> loop rest
1671 showlinktype (getlink opaque
n);
1672 Ltexact
(l
.pageno, n)
1676 state.mode
<- LinkNav
linknav
1681 state.ghyll
<- noghyll;
1684 let mx, my
= state.mpos
in
1689 let conttiling pageno opaque
=
1690 tilepage pageno opaque
1691 (if conf.preload then preloadlayout state.y else state.layout)
1694 let gotoy_and_clear_text y =
1695 if not
conf.verbose
then state.text <- "";
1701 let coloff = l
.pagecol
* l
.pageh
in
1702 float (l
.pagey + coloff) /. float l
.pageh
1709 if conf.presentation
1710 then float l
.pagedispy /. float (calcips l
.pageh
)
1711 else float l
.pagedispy /. float conf.interpagespace
1713 (l
.pageno, top, dtop)
1717 match state.layout with
1718 | l
:: _ -> getanchor1 l
1720 let n = page_of_y state.y in
1721 let y, h = getpageyh n in
1722 let dy = y - state.y in
1724 if conf.presentation
1726 let ips = calcips h in
1727 float (dy + ips) /. float ips
1729 float dy /. float conf.interpagespace
1734 let getanchory (n, top, dtop) =
1735 let y, h = getpageyh n in
1736 if conf.presentation
1738 let ips = calcips h in
1739 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1741 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1744 let gotoanchor anchor
=
1745 gotoy (getanchory anchor
);
1749 cbput state.hists
.nav
(getanchor ());
1753 let anchor = cbgetc state.hists
.nav dir
in
1758 let scroll f n a
b =
1759 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1761 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1763 then s (float f /. float a
)
1766 then 1.0 -. s ((float (f-b) /. float (n-b)))
1773 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1774 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1776 let ins = float a
*. iv1
1777 and outs
= float (n-b) *. iv1 in
1779 ins +. outs
+. float ones
1781 let rec set (_N
, _A
, _B
) y sy
=
1782 let sum = summa
1.0 _N _A _B
in
1783 let dy = float (y - sy
) in
1787 then state.ghyll
<- noghyll
1790 let s = scroll n _N _A _B
in
1791 let y1 = y1 +. ((s *. dy) /. sum) in
1792 gotoy_and_clear_text (truncate
y1);
1793 state.ghyll
<- gf (n+1) y1;
1797 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1799 gf 0 (float state.y)
1802 match conf.ghyllscroll
with
1804 gotoy_and_clear_text y
1806 if state.ghyll
== noghyll
1807 then set nab
y state.y
1808 else state.ghyll
(Some
y)
1811 let gotopage n top =
1812 let y, h = getpageyh n in
1813 let y = y + (truncate
(top *. float h)) in
1817 let gotopage1 n top =
1818 let y = getpagey n in
1823 let invalidate s f =
1828 match state.geomcmds
with
1829 | ps
, [] when String.length ps
= 0 ->
1831 state.geomcmds
<- s, [];
1834 state.geomcmds
<- ps
, [s, f];
1836 | ps
, (s'
, _) :: rest
when s'
= s ->
1837 state.geomcmds
<- ps
, ((s, f) :: rest
);
1840 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1843 let opendoc path password
=
1845 state.password
<- password
;
1846 state.gen
<- state.gen
+ 1;
1847 state.docinfo
<- [];
1849 setaalevel
conf.aalevel
;
1850 Wsi.settitle
("llpp " ^
Filename.basename path
);
1851 wcmd "open %s\000%s\000" path password
;
1852 invalidate "reqlayout"
1854 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1858 let c = c *. conf.colorscale
in
1862 let scalecolor2 (r, g
, b) =
1863 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1866 let docolumns = function
1868 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1869 let rec loop pageno pdimno pdim
y ph pdims
=
1870 if pageno = state.pagecount
1873 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1875 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1876 pdimno+1, pdim
, rest
1880 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1882 (if conf.presentation
1883 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1884 else (if pageno = 0 then 0 else conf.interpagespace
)
1887 a.(pageno) <- (pdimno, x, y, pdim
);
1888 loop (pageno+1) pdimno pdim
(y + h) h pdims
1890 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1891 conf.columns
<- Csingle
a;
1893 | Cmulti
((columns
, coverA
, coverB
), _) ->
1894 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1895 let rec loop pageno pdimno pdim
x y rowh pdims
=
1896 let rec fixrow m
= if m
= pageno then () else
1897 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1900 let y = y + (rowh
- h) / 2 in
1901 a.(m
) <- (pdimno, x, y, pdim
);
1905 if pageno = state.pagecount
1906 then fixrow (((pageno - 1) / columns
) * columns
)
1908 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1910 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1911 pdimno+1, pdim
, rest
1916 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1918 let x = (conf.winw
- state.scrollw
- w) / 2 in
1920 if conf.presentation
then calcips h else conf.interpagespace
in
1921 x, y + ips + rowh
, h
1924 if (pageno - coverA
) mod columns
= 0
1928 then (conf.winw
- state.scrollw
- state.w) / 2
1932 if conf.presentation
1934 let ips = calcips h in
1937 else y + calcips rowh
+ ips
1939 y + (if pageno = 0 then 0 else conf.interpagespace
)
1943 else x, y, max rowh
h
1946 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1947 then fixrow (pageno - columns
);
1948 a.(pageno) <- (pdimno, x, y, pdim
);
1949 let x = x + w + xoff
*2 + conf.interpagespace
in
1950 loop (pageno+1) pdimno pdim
x y rowh' pdims
1952 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1953 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1956 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1957 let rec loop pageno pdimno pdim
y pdims
=
1958 if pageno = state.pagecount
1961 let pdimno, ((_, w, h, _) as pdim
), pdims
=
1963 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1964 pdimno+1, pdim
, rest
1969 let rec loop1 n x y =
1970 if n = c then y else (
1971 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
1972 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
1975 let y = loop1 0 0 y in
1976 loop (pageno+1) pdimno pdim
y pdims
1978 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1979 conf.columns
<- Csplit
(c, a);
1983 docolumns conf.columns
;
1984 state.maxy
<- calcheight ();
1986 if state.w <= conf.winw
- state.scrollw
1990 match state.mode
with
1991 | Birdseye
(_, _, pageno, _, _) ->
1992 let y, h = getpageyh pageno in
1993 let top = (conf.winh
- h) / 2 in
1994 gotoy (max
0 (y - top))
1995 | _ -> gotoanchor state.anchor
1999 GlDraw.viewport
0 0 w h;
2000 let firsttime = state.geomcmds
== firstgeomcmds in
2001 if not
firsttime && nogeomcmds state.geomcmds
2002 then state.anchor <- getanchor ();
2005 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2008 setfontsize fstate.fontsize
;
2009 GlMat.mode `modelview
;
2010 GlMat.load_identity
();
2012 GlMat.mode `projection
;
2013 GlMat.load_identity
();
2014 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2015 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2016 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2021 else float state.x /. float state.w
2023 invalidate "geometry"
2027 then state.x <- truncate
(relx *. float w);
2029 match conf.columns
with
2031 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2032 | Csplit
(c, _) -> w * c
2034 wcmd "geometry %d %d" w h);
2038 let len = String.length
state.text in
2041 match state.mode
with
2044 let h, _, _ = state.uioh#scrollpw
in
2050 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2051 (x+.w, float (conf.winh
- hscrollh))
2054 let w = float (conf.winw
- state.scrollw
- 1) in
2055 if state.progress
>= 0.0 && state.progress
< 1.0
2057 GlDraw.color
(0.3, 0.3, 0.3);
2058 let w1 = w *. state.progress
in
2060 GlDraw.color
(0.0, 0.0, 0.0);
2064 GlDraw.color
(0.0, 0.0, 0.0);
2068 GlDraw.color
(1.0, 1.0, 1.0);
2069 drawstring fstate.fontsize
2070 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2073 match state.mode
with
2074 | Textentry
((prefix
, text, _, _, _, _), _) ->
2078 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2080 Printf.sprintf
"%s%s_" prefix
text
2089 if not
(istextentry state.mode
)
2091 let s1 = "(press 'e' to review error messasges)" in
2092 if String.length
s > 0 then s ^
" " ^
s1 else s1
2097 if String.length
s > 0
2102 let len = Queue.length
state.tilelru
in
2104 match state.throttle
with
2107 then preloadlayout state.y
2109 | Some
(layout, _, _) ->
2113 if state.memused
<= conf.memlimit
2118 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2119 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2120 let (_, pw, ph
, _) = getpagedim n in
2123 && colorspace
= conf.colorspace
2124 && angle
= conf.angle
2128 let x = col*conf.tilew
2129 and y = row*conf.tileh
in
2130 tilevisible (Lazy.force_val
layout) n x y
2132 then Queue.push lruitem
state.tilelru
2134 wcmd "freetile %s" p
;
2135 state.memused
<- state.memused
- s;
2136 state.uioh#infochanged Memused
;
2137 Hashtbl.remove
state.tilemap k
;
2146 Queue.iter
(fun (k
, p
, s) ->
2147 wcmd "freetile %s" p
;
2148 state.memused
<- state.memused
- s;
2149 state.uioh#infochanged Memused
;
2150 Hashtbl.remove
state.tilemap k
;
2152 Queue.clear
state.tilelru
;
2156 let logcurrently = function
2157 | Idle
-> dolog "Idle"
2158 | Loading
(l
, gen
) ->
2159 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2160 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2162 "Tiling %d[%d,%d] page=%s cs=%s angle"
2163 l
.pageno col row pageopaque
2164 (colorspace_to_string colorspace
)
2166 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2167 angle gen
conf.angle
state.gen
2169 conf.tilew
conf.tileh
2176 (* dolog "%S" cmds; *)
2179 try String.index cmds ' '
2180 with Not_found
-> -1
2185 let l = String.length cmds
in
2186 let op = String.sub cmds
0 spacepos in
2188 if l - spacepos < 2 then ""
2189 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2194 state.uioh#infochanged Pdim
;
2198 state.rects
<- state.rects1
;
2199 G.postRedisplay "clearrects";
2203 try Scanf.sscanf
args "%u" (fun n -> n)
2205 dolog "error processing 'continue' %S: %s"
2206 cmds
(Printexc.to_string exn
);
2209 state.pagecount
<- n;
2210 begin match state.currently
with
2212 state.currently
<- Idle
;
2213 state.outlines
<- Array.of_list
(List.rev
l)
2217 let cur, cmds
= state.geomcmds
in
2218 if String.length
cur = 0
2219 then failwith
"umpossible";
2221 begin match List.rev cmds
with
2223 state.geomcmds
<- "", [];
2227 state.geomcmds
<- s, List.rev rest
;
2229 if conf.maxwait
= None
2230 then G.postRedisplay "continue";
2240 then showtext ' '
args
2243 let progress, text =
2245 Scanf.sscanf
args "%f %n"
2247 f, String.sub
args pos
(String.length
args - pos
))
2249 dolog "error processing 'progress' %S: %s"
2250 cmds
(Printexc.to_string exn
);
2254 state.progress <- progress;
2255 G.postRedisplay "progress"
2258 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2260 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2261 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2262 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2264 dolog "error processing 'firstmatch' %S: %s"
2265 cmds
(Printexc.to_string exn
);
2268 let y = (getpagey pageno) + truncate
y0 in
2271 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2274 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2276 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2277 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2278 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2280 dolog "error processing 'match' %S: %s"
2281 cmds
(Printexc.to_string exn
);
2285 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2290 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2292 dolog "error processing 'page' %S: %s"
2293 cmds
(Printexc.to_string exn
);
2296 begin match state.currently
with
2297 | Loading
(l, gen
) ->
2298 vlog "page %d took %f sec" l.pageno t
;
2299 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2300 begin match state.throttle
with
2302 let preloadedpages =
2304 then preloadlayout state.y
2309 Set.Make
(struct type t
= int let compare = (-) end) in
2311 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2312 IntSet.empty
preloadedpages
2315 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2316 if not
(IntSet.mem
pageno set)
2318 wcmd "freepage %s" opaque
;
2324 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2327 state.currently
<- Idle
;
2330 tilepage l.pageno pageopaque state.layout;
2332 load preloadedpages;
2333 if pagevisible state.layout l.pageno
2334 && layoutready state.layout
2335 then G.postRedisplay "page";
2338 | Some
(layout, _, _) ->
2339 state.currently
<- Idle
;
2340 tilepage l.pageno pageopaque layout;
2345 dolog "Inconsistent loading state";
2346 logcurrently state.currently
;
2351 let (x, y, opaque
, size
, t
) =
2353 Scanf.sscanf
args "%u %u %s %u %f"
2354 (fun x y p size t
-> (x, y, p
, size
, t
))
2356 dolog "error processing 'tile' %S: %s"
2357 cmds
(Printexc.to_string exn
);
2360 begin match state.currently
with
2361 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2362 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2364 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2366 wcmd "freetile %s" opaque
;
2367 state.currently
<- Idle
;
2371 puttileopaque l col row gen cs angle opaque size t
;
2372 state.memused
<- state.memused
+ size
;
2373 state.uioh#infochanged Memused
;
2375 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2376 opaque
, size
) state.tilelru
;
2379 match state.throttle
with
2380 | None
-> state.layout
2381 | Some
(layout, _, _) -> layout
2384 state.currently
<- Idle
;
2386 && conf.colorspace
= cs
2387 && conf.angle
= angle
2388 && tilevisible layout l.pageno x y
2389 then conttiling l.pageno pageopaque;
2391 begin match state.throttle
with
2393 preload state.layout;
2395 && conf.colorspace
= cs
2396 && conf.angle
= angle
2397 && tilevisible state.layout l.pageno x y
2398 then G.postRedisplay "tile nothrottle";
2400 | Some
(layout, y, _) ->
2401 let ready = layoutready layout in
2405 state.layout <- layout;
2406 state.throttle
<- None
;
2407 G.postRedisplay "throttle";
2414 dolog "Inconsistent tiling state";
2415 logcurrently state.currently
;
2422 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2424 dolog "error processing 'pdim' %S: %s"
2425 cmds
(Printexc.to_string exn
);
2428 state.uioh#infochanged Pdim
;
2429 state.pdims
<- pdim :: state.pdims
2432 let (l, n, t
, h, pos
) =
2434 Scanf.sscanf
args "%u %u %d %u %n"
2435 (fun l n t
h pos
-> l, n, t
, h, pos
)
2437 dolog "error processing 'o' %S: %s"
2438 cmds
(Printexc.to_string exn
);
2441 let s = String.sub
args pos
(String.length
args - pos
) in
2442 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2443 begin match state.currently
with
2444 | Outlining outlines
->
2445 state.currently
<- Outlining
(outline :: outlines
)
2447 state.currently
<- Outlining
[outline]
2449 dolog "invalid outlining state";
2450 logcurrently currently
2454 state.docinfo
<- (1, args) :: state.docinfo
2457 state.uioh#infochanged Docinfo
;
2458 state.docinfo
<- List.rev
state.docinfo
2461 dolog "unknown cmd `%S'" cmds
2466 let action = function
2467 | HCprev
-> cbget cb ~
-1
2468 | HCnext
-> cbget cb
1
2469 | HCfirst
-> cbget cb ~
-(cb
.rc)
2470 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2471 and cancel
() = cb
.rc <- rc
2475 let search pattern forward
=
2476 if String.length pattern
> 0
2479 match state.layout with
2482 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2484 wcmd "search %d %d %d %d,%s\000"
2485 (btod conf.icase
) pn py
(btod forward
) pattern
;
2488 let intentry text key =
2490 if key >= 32 && key < 127
2496 let text = addchar text c in
2500 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2504 let linknentry text key =
2506 if key >= 32 && key < 127
2512 let text = addchar text c in
2516 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2521 if String.length
s > 0
2524 let l = String.length
s in
2525 let rec loop pos
n = if pos
= l then n else
2526 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2527 loop (pos
+1) (n*26 + m)
2530 let rec loop n = function
2533 match getopaque l.pageno with
2534 | None
-> loop n rest
2536 let m = getlinkcount opaque
in
2539 let under = getlink opaque
n in
2542 else loop (n-m) rest
2544 loop n state.layout;
2548 let textentry text key =
2549 if key land 0xff00 = 0xff00
2551 else TEcont
(text ^
Wsi.toutf8
key)
2554 let reqlayout angle proportional
=
2555 match state.throttle
with
2557 if nogeomcmds state.geomcmds
2558 then state.anchor <- getanchor ();
2559 conf.angle
<- angle
mod 360;
2562 match state.mode
with
2563 | LinkNav
_ -> state.mode
<- View
2566 conf.proportional
<- proportional
;
2567 invalidate "reqlayout"
2568 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2572 let settrim trimmargins trimfuzz
=
2573 if nogeomcmds state.geomcmds
2574 then state.anchor <- getanchor ();
2575 conf.trimmargins
<- trimmargins
;
2576 conf.trimfuzz
<- trimfuzz
;
2577 let x0, y0, x1, y1 = trimfuzz
in
2578 invalidate "settrim"
2580 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2581 Hashtbl.iter
(fun _ opaque
->
2582 wcmd "freepage %s" opaque
;
2584 Hashtbl.clear
state.pagemap
;
2588 match state.throttle
with
2590 let zoom = max
0.01 zoom in
2591 if zoom <> conf.zoom
2593 state.prevzoom
<- conf.zoom;
2595 reshape conf.winw
conf.winh
;
2596 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2599 | Some
(layout, y, started
) ->
2601 match conf.maxwait
with
2605 let dt = now () -. started
in
2613 let setcolumns mode columns coverA coverB
=
2614 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2618 then showtext '
!'
"split mode doesn't work in bird's eye"
2620 conf.columns
<- Csplit
(-columns
, [||]);
2628 conf.columns
<- Csingle
[||];
2633 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2637 reshape conf.winw
conf.winh
;
2640 let enterbirdseye () =
2641 let zoom = float conf.thumbw
/. float conf.winw
in
2642 let birdseyepageno =
2643 let cy = conf.winh
/ 2 in
2647 let rec fold best
= function
2650 let d = cy - (l.pagedispy + l.pagevh/2)
2651 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2652 if abs
d < abs dbest
2659 state.mode
<- Birdseye
(
2660 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2663 conf.presentation
<- false;
2664 conf.interpagespace
<- 10;
2665 conf.hlinks
<- false;
2667 state.mstate
<- Mnone
;
2668 conf.maxwait
<- None
;
2670 match conf.beyecolumns
with
2673 Cmulti
((c, 0, 0), [||])
2674 | None
-> Csingle
[||]
2676 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2679 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2684 reshape conf.winw
conf.winh
;
2687 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2689 conf.zoom <- c.zoom;
2690 conf.presentation
<- c.presentation
;
2691 conf.interpagespace
<- c.interpagespace
;
2692 conf.maxwait
<- c.maxwait
;
2693 conf.hlinks
<- c.hlinks
;
2694 conf.beyecolumns
<- (
2695 match conf.columns
with
2696 | Cmulti
((c, _, _), _) -> Some
c
2698 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2701 match c.columns
with
2702 | Cmulti
(c, _) -> Cmulti
(c, [||])
2703 | Csingle
_ -> Csingle
[||]
2704 | Csplit
(c, _) -> Csplit
(c, [||])
2709 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2712 reshape conf.winw
conf.winh
;
2713 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2716 let togglebirdseye () =
2717 match state.mode
with
2718 | Birdseye vals
-> leavebirdseye vals
true
2719 | View
-> enterbirdseye ()
2723 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2724 let pageno = max
0 (pageno - incr
) in
2725 let rec loop = function
2726 | [] -> gotopage1 pageno 0
2727 | l :: _ when l.pageno = pageno ->
2728 if l.pagedispy >= 0 && l.pagey = 0
2729 then G.postRedisplay "upbirdseye"
2730 else gotopage1 pageno 0
2731 | _ :: rest
-> loop rest
2734 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2737 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2738 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2739 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2740 let rec loop = function
2742 let y, h = getpageyh pageno in
2743 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2745 | l :: _ when l.pageno = pageno ->
2746 if l.pagevh != l.pageh
2747 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2748 else G.postRedisplay "downbirdseye"
2749 | _ :: rest
-> loop rest
2754 let optentry mode
_ key =
2755 let btos b = if b then "on" else "off" in
2756 if key >= 32 && key < 127
2758 let c = Char.chr
key in
2762 try conf.scrollstep
<- int_of_string
s with exc
->
2763 state.text <- Printf.sprintf
"bad integer `%s': %s"
2764 s (Printexc.to_string exc
)
2766 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2771 conf.autoscrollstep
<- int_of_string
s;
2772 if state.autoscroll
<> None
2773 then state.autoscroll
<- Some
conf.autoscrollstep
2775 state.text <- Printf.sprintf
"bad integer `%s': %s"
2776 s (Printexc.to_string exc
)
2778 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2783 let n, a, b = multicolumns_of_string s in
2784 setcolumns mode
n a b;
2786 state.text <- Printf.sprintf
"bad columns `%s': %s"
2787 s (Printexc.to_string exc
)
2789 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2794 let zoom = float (int_of_string
s) /. 100.0 in
2797 state.text <- Printf.sprintf
"bad integer `%s': %s"
2798 s (Printexc.to_string exc
)
2800 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2805 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2807 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2808 begin match mode
with
2810 leavebirdseye beye
false;
2815 state.text <- Printf.sprintf
"bad integer `%s': %s"
2816 s (Printexc.to_string exc
)
2818 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2823 Some
(int_of_string
s)
2825 state.text <- Printf.sprintf
"bad integer `%s': %s"
2826 s (Printexc.to_string exc
);
2829 | Some angle
-> reqlayout angle
conf.proportional
2832 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2835 conf.icase
<- not
conf.icase
;
2836 TEdone
("case insensitive search " ^
(btos conf.icase
))
2839 conf.preload <- not
conf.preload;
2841 TEdone
("preload " ^
(btos conf.preload))
2844 conf.verbose
<- not
conf.verbose
;
2845 TEdone
("verbose " ^
(btos conf.verbose
))
2848 conf.debug
<- not
conf.debug
;
2849 TEdone
("debug " ^
(btos conf.debug
))
2852 conf.maxhfit
<- not
conf.maxhfit
;
2853 state.maxy
<- calcheight ();
2854 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2857 conf.crophack
<- not
conf.crophack
;
2858 TEdone
("crophack " ^
btos conf.crophack
)
2862 match conf.maxwait
with
2864 conf.maxwait
<- Some infinity
;
2865 "always wait for page to complete"
2867 conf.maxwait
<- None
;
2868 "show placeholder if page is not ready"
2873 conf.underinfo
<- not
conf.underinfo
;
2874 TEdone
("underinfo " ^
btos conf.underinfo
)
2877 conf.savebmarks
<- not
conf.savebmarks
;
2878 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2884 match state.layout with
2889 conf.interpagespace
<- int_of_string
s;
2890 docolumns conf.columns
;
2891 state.maxy
<- calcheight ();
2892 let y = getpagey pageno in
2895 state.text <- Printf.sprintf
"bad integer `%s': %s"
2896 s (Printexc.to_string exc
)
2898 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2901 reqlayout conf.angle
(not
conf.proportional
);
2902 TEdone
("proportional display " ^
btos conf.proportional
)
2905 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2906 TEdone
("trim margins " ^
btos conf.trimmargins
)
2909 conf.invert
<- not
conf.invert
;
2910 TEdone
("invert colors " ^
btos conf.invert
)
2914 cbput state.hists
.sel
s;
2917 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2918 textentry, ondone, true)
2921 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2927 class type lvsource
= object
2928 method getitemcount
: int
2929 method getitem
: int -> (string * int)
2930 method hasaction
: int -> bool
2939 method getactive
: int
2940 method getfirst
: int
2941 method getqsearch
: string
2942 method setqsearch
: string -> unit
2946 class virtual lvsourcebase
= object
2947 val mutable m_active
= 0
2948 val mutable m_first
= 0
2949 val mutable m_qsearch
= ""
2950 val mutable m_pan
= 0
2951 method getactive
= m_active
2952 method getfirst
= m_first
2953 method getqsearch
= m_qsearch
2954 method getpan
= m_pan
2955 method setqsearch
s = m_qsearch
<- s
2958 let withoutlastutf8 s =
2959 let len = String.length
s in
2967 let b = Char.code
s.[pos
] in
2968 if b land 0b110000 = 0b11000000
2973 if Char.code
s.[len-1] land 0x80 = 0
2977 String.sub
s 0 first;
2980 let textentrykeyboard
2981 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2983 state.mode
<- Textentry
(te
, onleave
);
2986 G.postRedisplay "textentrykeyboard enttext";
2988 let histaction cmd
=
2991 | Some
(action, _) ->
2992 state.mode
<- Textentry
(
2993 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2995 G.postRedisplay "textentry histaction"
2998 | 0xff08 -> (* backspace *)
2999 let s = withoutlastutf8 text in
3000 let len = String.length
s in
3001 if cancelonempty
&& len = 0
3004 G.postRedisplay "textentrykeyboard after cancel";
3007 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3013 G.postRedisplay "textentrykeyboard after confirm"
3015 | 0xff52 -> histaction HCprev
3016 | 0xff54 -> histaction HCnext
3017 | 0xff50 -> histaction HCfirst
3018 | 0xff57 -> histaction HClast
3020 | 0xff1b -> (* escape*)
3021 if String.length
text = 0
3023 begin match opthist
with
3025 | Some
(_, onhistcancel
) -> onhistcancel
()
3029 G.postRedisplay "textentrykeyboard after cancel2"
3032 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3035 | 0xff9f | 0xffff -> () (* delete *)
3037 | _ when key != 0 && key land 0xff00 != 0xff00 ->
3038 begin match onkey
text key with
3042 G.postRedisplay "textentrykeyboard after confirm2";
3045 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3049 G.postRedisplay "textentrykeyboard after cancel3"
3052 state.mode
<- Textentry
(te
, onleave
);
3053 G.postRedisplay "textentrykeyboard switch";
3057 vlog "unhandled key %s" (Wsi.keyname
key)
3060 let firstof first active
=
3061 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3062 then max
0 (active
- (fstate.maxrows
/2))
3066 let calcfirst first active
=
3069 let rows = active
- first in
3070 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3074 let scrollph y maxy
=
3075 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3076 let sh = float conf.winh
/. sh in
3077 let sh = max
sh (float conf.scrollh
) in
3082 else float y /. float maxy
3084 let position = (float conf.winh
-. sh) *. percent in
3087 if position +. sh > float conf.winh
3088 then float conf.winh
-. sh
3094 let coe s = (s :> uioh
);;
3096 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3098 val m_pan
= source#getpan
3099 val m_first
= source#getfirst
3100 val m_active
= source#getactive
3101 val m_qsearch
= source#getqsearch
3102 val m_prev_uioh
= state.uioh
3104 method private elemunder
y =
3105 let n = y / (fstate.fontsize
+1) in
3106 if m_first
+ n < source#getitemcount
3108 if source#hasaction
(m_first
+ n)
3109 then Some
(m_first
+ n)
3116 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3117 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3118 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3119 GlDraw.color
(1., 1., 1.);
3120 Gl.enable `texture_2d
;
3121 let fs = fstate.fontsize
in
3123 let ww = fstate.wwidth
in
3124 let tabw = 30.0*.ww in
3125 let itemcount = source#getitemcount
in
3127 if (row - m_first
) * nfs > conf.winh
3130 if row >= 0 && row < itemcount
3132 let (s, level
) = source#getitem
row in
3133 let y = (row - m_first
) * nfs in
3134 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3137 Gl.disable `texture_2d
;
3138 GlDraw.polygon_mode `both `line
;
3139 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3140 GlDraw.rect (1., float (y + 1))
3141 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3142 GlDraw.polygon_mode `both `fill
;
3143 GlDraw.color
(1., 1., 1.);
3144 Gl.enable `texture_2d
;
3147 let drawtabularstring s =
3148 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3151 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3154 let len = String.length
s - tabpos - 1 in
3155 let s1 = String.sub
s 0 tabpos
3156 and s2
= String.sub
s (tabpos + 1) len in
3157 let nx = drawstr x s1 in
3159 let x = x +. (max
tabw sw) in
3166 let _ = drawtabularstring s in
3173 Gl.disable `texture_2d
;
3175 method updownlevel incr
=
3176 let len = source#getitemcount
in
3178 if m_active
>= 0 && m_active
< len
3179 then snd
(source#getitem m_active
)
3183 if i
= len then i
-1 else if i
= -1 then 0 else
3184 let _, l = source#getitem i
in
3185 if l != curlevel then i
else flow (i
+incr
)
3187 let active = flow m_active
in
3188 let first = calcfirst m_first
active in
3189 G.postRedisplay "outline updownlevel";
3190 {< m_active
= active; m_first
= first >}
3192 method private key1
key mask
=
3193 let set1 active first qsearch
=
3194 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3196 let search active pattern incr
=
3199 if n >= 0 && n < source#getitemcount
3201 let s, _ = source#getitem
n in
3203 (try ignore
(Str.search_forward
re s 0); true
3204 with Not_found
-> false)
3206 else loop (n + incr
)
3213 let re = Str.regexp_case_fold pattern
in
3219 let itemcount = source#getitemcount
in
3220 let find start incr
=
3222 if i
= -1 || i
= itemcount
3225 if source#hasaction i
3227 else find (i
+ incr
)
3232 let set active first =
3233 let first = bound first 0 (itemcount - fstate.maxrows
) in
3235 coe {< m_active
= active; m_first
= first >}
3238 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3240 let incr1 = if incr
> 0 then 1 else -1 in
3241 if isvisible m_first m_active
3244 let next = m_active
+ incr
in
3246 if next < 0 || next >= itemcount
3248 else find next incr1
3250 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3256 let first = m_first
+ incr
in
3257 let first = bound first 0 (itemcount - 1) in
3259 let next = m_active
+ incr
in
3260 let next = bound next 0 (itemcount - 1) in
3263 let active = if next = -1 then m_active
else next in
3266 let first = min
next m_first
in
3268 if abs
(next - first) > fstate.maxrows
3274 let first = m_first
+ incr
in
3275 let first = bound first 0 (itemcount - 1) in
3277 let next = m_active
+ incr
in
3278 let next = bound next 0 (itemcount - 1) in
3279 let next = find next incr1 in
3281 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3283 let active = if m_active
= -1 then next else m_active
in
3288 if isvisible first active
3294 G.postRedisplay "listview navigate";
3298 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3299 let incr = if key = 0x72 then -1 else 1 in
3301 match search (m_active
+ incr) m_qsearch
incr with
3303 state.text <- m_qsearch ^
" [not found]";
3306 state.text <- m_qsearch
;
3307 active, firstof m_first
active
3309 G.postRedisplay "listview ctrl-r/s";
3310 set1 active first m_qsearch
;
3312 | 0xff08 -> (* backspace *)
3313 if String.length m_qsearch
= 0
3316 let qsearch = withoutlastutf8 m_qsearch
in
3317 let len = String.length
qsearch in
3321 G.postRedisplay "listview empty qsearch";
3322 set1 m_active m_first
"";
3326 match search m_active
qsearch ~
-1 with
3328 state.text <- qsearch ^
" [not found]";
3331 state.text <- qsearch;
3332 active, firstof m_first
active
3334 G.postRedisplay "listview backspace qsearch";
3335 set1 active first qsearch
3338 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3339 let pattern = m_qsearch ^
Wsi.toutf8
key in
3341 match search m_active
pattern 1 with
3343 state.text <- pattern ^
" [not found]";
3346 state.text <- pattern;
3347 active, firstof m_first
active
3349 G.postRedisplay "listview qsearch add";
3350 set1 active first pattern;
3352 | 0xff1b -> (* escape *)
3354 if String.length m_qsearch
= 0
3356 G.postRedisplay "list view escape";
3359 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3361 | None
-> m_prev_uioh
3366 G.postRedisplay "list view kill qsearch";
3367 source#setqsearch
"";
3368 coe {< m_qsearch
= "" >}
3371 | 0xff0d -> (* return *)
3373 let self = {< m_qsearch
= "" >} in
3374 source#setqsearch
"";
3376 G.postRedisplay "listview enter";
3377 if m_active
>= 0 && m_active
< source#getitemcount
3379 source#exit
(coe self) false m_active m_first m_pan
"";
3382 source#exit
(coe self) true m_active m_first m_pan
"";
3385 begin match opt with
3386 | None
-> m_prev_uioh
3390 | 0xff9f | 0xffff -> (* delete *)
3393 | 0xff52 -> navigate ~
-1 (* up *)
3394 | 0xff54 -> navigate 1 (* down *)
3395 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3396 | 0xff56 -> navigate fstate.maxrows
(* next *)
3398 | 0xff53 -> (* right *)
3400 G.postRedisplay "listview right";
3401 coe {< m_pan
= m_pan
- 1 >}
3403 | 0xff51 -> (* left *)
3405 G.postRedisplay "listview left";
3406 coe {< m_pan
= m_pan
+ 1 >}
3408 | 0xff50 -> (* home *)
3409 let active = find 0 1 in
3410 G.postRedisplay "listview home";
3413 | 0xff57 -> (* end *)
3414 let first = max
0 (itemcount - fstate.maxrows
) in
3415 let active = find (itemcount - 1) ~
-1 in
3416 G.postRedisplay "listview end";
3419 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3423 dolog "listview unknown key %#x" key; coe self
3425 method key key mask
=
3426 match state.mode
with
3427 | Textentry te
-> textentrykeyboard key mask te
; coe self
3428 | _ -> self#key1
key mask
3430 method button button down
x y _ =
3433 | 1 when x > conf.winw
- conf.scrollbw
->
3434 G.postRedisplay "listview scroll";
3437 let _, position, sh = self#
scrollph in
3438 if y > truncate
position && y < truncate
(position +. sh)
3440 state.mstate
<- Mscrolly
;
3444 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3445 let first = truncate
(s *. float source#getitemcount
) in
3446 let first = min source#getitemcount
first in
3447 Some
(coe {< m_first
= first; m_active
= first >})
3449 state.mstate
<- Mnone
;
3452 | 1 when not down
->
3453 begin match self#elemunder
y with
3455 G.postRedisplay "listview click";
3457 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3461 | n when (n == 4 || n == 5) && not down
->
3462 let len = source#getitemcount
in
3464 if n = 5 && m_first
+ fstate.maxrows
>= len
3468 let first = m_first
+ (if n == 4 then -1 else 1) in
3469 bound first 0 (len - 1)
3471 G.postRedisplay "listview wheel";
3472 Some
(coe {< m_first
= first >})
3473 | n when (n = 6 || n = 7) && not down
->
3474 let inc = m_first
+ (if n = 7 then -1 else 1) in
3475 G.postRedisplay "listview hwheel";
3476 Some
(coe {< m_pan
= m_pan
+ inc >})
3481 | None
-> m_prev_uioh
3485 match state.mstate
with
3487 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3488 let first = truncate
(s *. float source#getitemcount
) in
3489 let first = min source#getitemcount
first in
3490 G.postRedisplay "listview motion";
3491 coe {< m_first
= first; m_active
= first >}
3494 method pmotion
x y =
3495 if x < conf.winw
- conf.scrollbw
3498 match self#elemunder
y with
3499 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3500 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3504 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3509 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3513 method infochanged
_ = ()
3515 method scrollpw
= (0, 0.0, 0.0)
3517 let nfs = fstate.fontsize
+ 1 in
3518 let y = m_first
* nfs in
3519 let itemcount = source#getitemcount
in
3520 let maxi = max
0 (itemcount - fstate.maxrows
) in
3521 let maxy = maxi * nfs in
3522 let p, h = scrollph y maxy in
3525 method modehash
= modehash
3528 class outlinelistview ~source
=
3531 ~source
:(source
:> lvsource
)
3533 ~modehash
:(findkeyhash conf "outline")
3536 method key key mask
=
3537 let calcfirst first active =
3540 let rows = active - first in
3542 if String.length
state.text = 0
3544 else fstate.maxrows - 2
3546 if rows > maxrows then active - maxrows else first
3550 let active = m_active
+ incr in
3551 let active = bound active 0 (source#getitemcount
- 1) in
3552 let first = calcfirst m_first
active in
3553 G.postRedisplay "outline navigate";
3554 coe {< m_active
= active; m_first
= first >}
3556 let ctrl = Wsi.withctrl mask
in
3558 | 110 when ctrl -> (* ctrl-n *)
3559 source#narrow m_qsearch
;
3560 G.postRedisplay "outline ctrl-n";
3561 coe {< m_first
= 0; m_active
= 0 >}
3563 | 117 when ctrl -> (* ctrl-u *)
3565 G.postRedisplay "outline ctrl-u";
3567 coe {< m_first
= 0; m_active
= 0 >}
3569 | 108 when ctrl -> (* ctrl-l *)
3570 let first = m_active
- (fstate.maxrows / 2) in
3571 G.postRedisplay "outline ctrl-l";
3572 coe {< m_first
= first >}
3574 | 0xff9f | 0xffff -> (* delete *)
3575 source#remove m_active
;
3576 G.postRedisplay "outline delete";
3577 let active = max
0 (m_active
-1) in
3578 coe {< m_first
= firstof m_first
active;
3579 m_active
= active >}
3581 | 0xff52 -> navigate ~
-1 (* up *)
3582 | 0xff54 -> navigate 1 (* down *)
3583 | 0xff55 -> (* prior *)
3584 navigate ~
-(fstate.maxrows)
3585 | 0xff56 -> (* next *)
3586 navigate fstate.maxrows
3588 | 0xff53 -> (* [ctrl-]right *)
3592 G.postRedisplay "outline ctrl right";
3593 {< m_pan
= m_pan
+ 1 >}
3595 else self#updownlevel
1
3599 | 0xff51 -> (* [ctrl-]left *)
3603 G.postRedisplay "outline ctrl left";
3604 {< m_pan
= m_pan
- 1 >}
3606 else self#updownlevel ~
-1
3610 | 0xff50 -> (* home *)
3611 G.postRedisplay "outline home";
3612 coe {< m_first
= 0; m_active
= 0 >}
3614 | 0xff57 -> (* end *)
3615 let active = source#getitemcount
- 1 in
3616 let first = max
0 (active - fstate.maxrows) in
3617 G.postRedisplay "outline end";
3618 coe {< m_active
= active; m_first
= first >}
3620 | _ -> super#
key key mask
3623 let outlinesource usebookmarks
=
3626 inherit lvsourcebase
3627 val mutable m_items
= empty
3628 val mutable m_orig_items
= empty
3629 val mutable m_prev_items
= empty
3630 val mutable m_narrow_pattern
= ""
3631 val mutable m_hadremovals
= false
3633 method getitemcount
=
3634 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3637 if n == Array.length m_items
&& m_hadremovals
3639 ("[Confirm removal]", 0)
3641 let s, n, _ = m_items
.(n) in
3644 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3645 ignore
(uioh
, first, qsearch);
3646 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3648 if String.length m_narrow_pattern
= 0
3654 if not
confrimremoval
3656 let _, _, anchor = m_items
.(active) in
3661 state.bookmarks
<- Array.to_list m_items
;
3662 m_orig_items
<- m_items
;
3665 else m_items
<- items;
3669 method hasaction
_ = true
3672 if Array.length m_items
!= Array.length m_orig_items
3673 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3676 method narrow
pattern =
3677 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3681 let rec loop accu n =
3684 m_narrow_pattern
<- pattern;
3685 m_items
<- Array.of_list
accu
3688 let (s, _, _) as o = m_items
.(n) in
3690 if (try ignore
(Str.search_forward
re s 0); true
3691 with Not_found
-> false)
3697 loop [] (Array.length m_items
- 1)
3702 then Array.of_list
state.bookmarks
3705 m_items
<- m_orig_items
3710 if m >= 0 && m < Array.length m_items
3712 m_hadremovals
<- true;
3713 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3714 let n = if n >= m then n+1 else n in
3719 method reset
anchor items =
3720 m_hadremovals
<- false;
3721 if m_orig_items
== empty || m_prev_items
!= items
3723 m_orig_items
<- items;
3724 if String.length m_narrow_pattern
= 0
3725 then m_items
<- items;
3727 m_prev_items
<- items;
3728 let rely = getanchory anchor in
3730 let rec loop n best bestd
=
3731 if n = Array.length m_items
3734 let (_, _, anchor) = m_items
.(n) in
3735 let orely = getanchory anchor in
3736 let d = abs
(orely - rely) in
3739 else loop (n+1) best bestd
3744 m_first
<- firstof m_first
active
3748 let enterselector usebookmarks
=
3749 let source = outlinesource usebookmarks
in
3753 then Array.of_list
state.bookmarks
3756 if Array.length
outlines = 0
3758 showtext ' ' errmsg
;
3761 state.text <- source#greetmsg
;
3762 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3763 let anchor = getanchor () in
3764 source#reset
anchor outlines;
3765 state.uioh
<- coe (new outlinelistview ~
source);
3766 G.postRedisplay "enter selector";
3770 let enteroutlinemode =
3771 let f = enterselector false in
3772 fun ()-> f "Document has no outline";
3775 let enterbookmarkmode =
3776 let f = enterselector true in
3777 fun () -> f "Document has no bookmarks (yet)";
3780 let color_of_string s =
3781 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3782 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3786 let color_to_string (r, g
, b) =
3787 let r = truncate
(r *. 256.0)
3788 and g
= truncate
(g
*. 256.0)
3789 and b = truncate
(b *. 256.0) in
3790 Printf.sprintf
"%d/%d/%d" r g
b
3793 let irect_of_string s =
3794 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3797 let irect_to_string (x0,y0,x1,y1) =
3798 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3801 let makecheckers () =
3802 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3804 converted by Issac Trotts. July 25, 2002 *)
3805 let image_height = 64
3806 and image_width
= 64 in
3810 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3812 for i
= 0 to image_width
- 1 do
3813 for j
= 0 to image_height - 1 do
3814 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3815 (if (i
land 8 ) lxor (j
land 8) = 0
3816 then [|255;255;255|] else [|200;200;200|])
3821 let image = make_image () in
3822 let id = GlTex.gen_texture
() in
3823 GlTex.bind_texture `texture_2d
id;
3824 GlPix.store
(`unpack_alignment
1);
3825 GlTex.image2d
image;
3826 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3829 `mag_filter `nearest
;
3830 `min_filter `nearest
];
3834 let setcheckers enabled
=
3835 match state.texid
with
3837 if enabled
then state.texid
<- Some
(makecheckers ())
3842 GlTex.delete_texture texid
;
3843 state.texid
<- None
;
3847 let int_of_string_with_suffix s =
3848 let l = String.length
s in
3852 let suffix = Char.lowercase
s.[l-1] in
3854 | 'k'
-> String.sub
s 0 (l-1), 10
3855 | '
m'
-> String.sub
s 0 (l-1), 20
3856 | 'g'
-> String.sub
s 0 (l-1), 30
3860 let n = int_of_string
s1 in
3861 let m = n lsl shift
in
3863 then raise
(Failure
"value too large")
3867 let string_with_suffix_of_int n =
3872 if n land ((1 lsl 20) - 1) = 0
3875 if n land ((1 lsl 10) - 1) = 0
3881 let h = n mod 1000 in
3884 then string_of_int
h ^
s
3886 let s = Printf.sprintf
"_%03d%s" h s in
3893 let defghyllscroll = (40, 8, 32);;
3894 let ghyllscroll_of_string s =
3895 let (n, a, b) as nab
=
3898 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3900 if n <= a || n <= b || a >= b
3901 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3905 let ghyllscroll_to_string ((n, a, b) as nab
) =
3906 if nab
= defghyllscroll
3908 else Printf.sprintf
"%d,%d,%d" n a b;
3911 let describe_location () =
3913 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3915 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3916 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3920 else (100. *. (float state.y /. float maxy))
3924 Printf.sprintf
"page %d of %d [%.2f%%]"
3925 (fn+1) state.pagecount
percent
3928 "pages %d-%d of %d [%.2f%%]"
3929 (fn+1) (ln
+1) state.pagecount
percent
3932 let setpresentationmode v
=
3933 let (n, _, _) = getanchor () in
3934 let _, h = getpageyh n in
3935 let ips = if conf.presentation
then calcips h else conf.interpagespace
in
3936 state.anchor <- (n, 0.0, float ips);
3937 conf.presentation
<- v
;
3938 if conf.presentation
3940 if not
conf.scrollbarinpm
3941 then state.scrollw
<- 0;
3943 else state.scrollw
<- conf.scrollbw
;
3948 let btos b = if b then "\xe2\x88\x9a" else "" in
3949 let showextended = ref false in
3950 let leave mode
= function
3951 | Confirm
-> state.mode
<- mode
3952 | Cancel
-> state.mode
<- mode
in
3955 val mutable m_first_time
= true
3956 val mutable m_l
= []
3957 val mutable m_a
= [||]
3958 val mutable m_prev_uioh
= nouioh
3959 val mutable m_prev_mode
= View
3961 inherit lvsourcebase
3963 method reset prev_mode prev_uioh
=
3964 m_a
<- Array.of_list
(List.rev m_l
);
3966 m_prev_mode
<- prev_mode
;
3967 m_prev_uioh
<- prev_uioh
;
3971 if n >= Array.length m_a
3975 | _, _, _, Action
_ -> m_active
<- n
3979 m_first_time
<- false;
3982 method int name get
set =
3984 (name
, `
int get
, 1, Action
(
3987 try set (int_of_string
s)
3989 state.text <- Printf.sprintf
"bad integer `%s': %s"
3990 s (Printexc.to_string exn
)
3993 let te = name ^
": ", "", None
, intentry, ondone, true in
3994 state.mode
<- Textentry
(te, leave m_prev_mode
);
3998 method int_with_suffix name get
set =
4000 (name
, `intws get
, 1, Action
(
4003 try set (int_of_string_with_suffix s)
4005 state.text <- Printf.sprintf
"bad integer `%s': %s"
4006 s (Printexc.to_string exn
)
4010 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4012 state.mode
<- Textentry
(te, leave m_prev_mode
);
4016 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4018 (name
, `
bool (btos, get
), offset
, Action
(
4025 method color name get
set =
4027 (name
, `color get
, 1, Action
(
4029 let invalid = (nan
, nan
, nan
) in
4032 try color_of_string s
4034 state.text <- Printf.sprintf
"bad color `%s': %s"
4035 s (Printexc.to_string exn
);
4041 let te = name ^
": ", "", None
, textentry, ondone, true in
4042 state.text <- color_to_string (get
());
4043 state.mode
<- Textentry
(te, leave m_prev_mode
);
4047 method string name get
set =
4049 (name
, `
string get
, 1, Action
(
4051 let ondone s = set s in
4052 let te = name ^
": ", "", None
, textentry, ondone, true in
4053 state.mode
<- Textentry
(te, leave m_prev_mode
);
4057 method colorspace name get
set =
4059 (name
, `
string get
, 1, Action
(
4062 let vals = [| "rgb"; "bgr"; "gray" |] in
4064 inherit lvsourcebase
4067 m_active
<- int_of_colorspace conf.colorspace
;
4070 method getitemcount
= Array.length
vals
4071 method getitem
n = (vals.(n), 0)
4072 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4073 ignore
(uioh
, first, pan
, qsearch);
4074 if not cancel
then set active;
4076 method hasaction
_ = true
4080 let modehash = findkeyhash conf "info" in
4081 coe (new listview ~
source ~trusted
:true ~
modehash)
4084 method caption
s offset
=
4085 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4087 method caption2
s f offset
=
4088 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4090 method getitemcount
= Array.length m_a
4093 let tostr = function
4094 | `
int f -> string_of_int
(f ())
4095 | `intws
f -> string_with_suffix_of_int (f ())
4097 | `color
f -> color_to_string (f ())
4098 | `
bool (btos, f) -> btos (f ())
4101 let name, t
, offset
, _ = m_a
.(n) in
4102 ((let s = tostr t
in
4103 if String.length
s > 0
4104 then Printf.sprintf
"%s\t%s" name s
4108 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4112 m_qsearch
<- qsearch;
4114 match m_a
.(active) with
4115 | _, _, _, Action
f -> f uioh
4127 method hasaction
n =
4129 | _, _, _, Action
_ -> true
4133 let rec fillsrc prevmode prevuioh
=
4134 let sep () = src#caption
"" 0 in
4135 let colorp name get
set =
4137 (fun () -> color_to_string (get
()))
4140 let c = color_of_string v in
4143 state.text <- Printf.sprintf
"bad color `%s': %s"
4144 v (Printexc.to_string exn
);
4147 let oldmode = state.mode
in
4148 let birdseye = isbirdseye state.mode
in
4150 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4152 src#
bool "presentation mode"
4153 (fun () -> conf.presentation
)
4154 (fun v -> setpresentationmode v);
4156 src#
bool "ignore case in searches"
4157 (fun () -> conf.icase
)
4158 (fun v -> conf.icase
<- v);
4161 (fun () -> conf.preload)
4162 (fun v -> conf.preload <- v);
4164 src#
bool "highlight links"
4165 (fun () -> conf.hlinks
)
4166 (fun v -> conf.hlinks
<- v);
4168 src#
bool "under info"
4169 (fun () -> conf.underinfo
)
4170 (fun v -> conf.underinfo
<- v);
4172 src#
bool "persistent bookmarks"
4173 (fun () -> conf.savebmarks
)
4174 (fun v -> conf.savebmarks
<- v);
4176 src#
bool "proportional display"
4177 (fun () -> conf.proportional
)
4178 (fun v -> reqlayout conf.angle
v);
4180 src#
bool "trim margins"
4181 (fun () -> conf.trimmargins
)
4182 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4184 src#
bool "persistent location"
4185 (fun () -> conf.jumpback
)
4186 (fun v -> conf.jumpback
<- v);
4189 src#
int "inter-page space"
4190 (fun () -> conf.interpagespace
)
4192 conf.interpagespace
<- n;
4193 docolumns conf.columns
;
4195 match state.layout with
4200 state.maxy <- calcheight ();
4201 let y = getpagey pageno in
4206 (fun () -> conf.pagebias
)
4207 (fun v -> conf.pagebias
<- v);
4209 src#
int "scroll step"
4210 (fun () -> conf.scrollstep
)
4211 (fun n -> conf.scrollstep
<- n);
4213 src#
int "horizontal scroll step"
4214 (fun () -> conf.hscrollstep
)
4215 (fun v -> conf.hscrollstep
<- v);
4217 src#
int "auto scroll step"
4219 match state.autoscroll
with
4221 | _ -> conf.autoscrollstep
)
4223 if state.autoscroll
<> None
4224 then state.autoscroll
<- Some
n;
4225 conf.autoscrollstep
<- n);
4228 (fun () -> truncate
(conf.zoom *. 100.))
4229 (fun v -> setzoom ((float v) /. 100.));
4232 (fun () -> conf.angle
)
4233 (fun v -> reqlayout v conf.proportional
);
4235 src#
int "scroll bar width"
4236 (fun () -> state.scrollw
)
4240 reshape conf.winw
conf.winh
;
4243 src#
int "scroll handle height"
4244 (fun () -> conf.scrollh
)
4245 (fun v -> conf.scrollh
<- v;);
4247 src#
int "thumbnail width"
4248 (fun () -> conf.thumbw
)
4250 conf.thumbw
<- min
4096 v;
4253 leavebirdseye beye
false;
4258 let mode = state.mode in
4259 src#
string "columns"
4261 match conf.columns
with
4263 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4264 | Csplit
(count
, _) -> "-" ^ string_of_int count
4267 let n, a, b = multicolumns_of_string v in
4268 setcolumns mode n a b);
4271 src#caption
"Presentation mode" 0;
4272 src#
bool "scrollbar visible"
4273 (fun () -> conf.scrollbarinpm
)
4275 if v != conf.scrollbarinpm
4277 conf.scrollbarinpm
<- v;
4278 if conf.presentation
4280 state.scrollw
<- if v then conf.scrollbw
else 0;
4281 reshape conf.winw
conf.winh
;
4287 src#caption
"Pixmap cache" 0;
4288 src#int_with_suffix
"size (advisory)"
4289 (fun () -> conf.memlimit
)
4290 (fun v -> conf.memlimit
<- v);
4293 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4294 (string_with_suffix_of_int state.memused
)
4295 (Hashtbl.length
state.tilemap
)) 1;
4298 src#caption
"Layout" 0;
4299 src#caption2
"Dimension"
4301 Printf.sprintf
"%dx%d (virtual %dx%d)"
4307 src#caption2
"Position" (fun () ->
4308 Printf.sprintf
"%dx%d" state.x state.y
4311 src#caption2
"Visible" (fun () -> describe_location ()) 1
4315 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4316 "Save these parameters as global defaults at exit"
4317 (fun () -> conf.bedefault
)
4318 (fun v -> conf.bedefault
<- v)
4322 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4323 src#
bool ~offset
:0 ~
btos "Extended parameters"
4324 (fun () -> !showextended)
4325 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4329 (fun () -> conf.checkers
)
4330 (fun v -> conf.checkers
<- v; setcheckers v);
4331 src#
bool "update cursor"
4332 (fun () -> conf.updatecurs
)
4333 (fun v -> conf.updatecurs
<- v);
4335 (fun () -> conf.verbose
)
4336 (fun v -> conf.verbose
<- v);
4337 src#
bool "invert colors"
4338 (fun () -> conf.invert
)
4339 (fun v -> conf.invert
<- v);
4341 (fun () -> conf.maxhfit
)
4342 (fun v -> conf.maxhfit
<- v);
4343 src#
bool "redirect stderr"
4344 (fun () -> conf.redirectstderr)
4345 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4346 src#
string "uri launcher"
4347 (fun () -> conf.urilauncher
)
4348 (fun v -> conf.urilauncher
<- v);
4349 src#
string "path launcher"
4350 (fun () -> conf.pathlauncher
)
4351 (fun v -> conf.pathlauncher
<- v);
4352 src#
string "tile size"
4353 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4356 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4357 conf.tilew
<- max
64 w;
4358 conf.tileh
<- max
64 h;
4361 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4362 v (Printexc.to_string exn
));
4363 src#
int "texture count"
4364 (fun () -> conf.texcount
)
4367 then conf.texcount
<- v
4368 else showtext '
!'
" Failed to set texture count please retry later"
4370 src#
int "slice height"
4371 (fun () -> conf.sliceheight
)
4373 conf.sliceheight
<- v;
4374 wcmd "sliceh %d" conf.sliceheight
;
4376 src#
int "anti-aliasing level"
4377 (fun () -> conf.aalevel
)
4379 conf.aalevel
<- bound v 0 8;
4380 state.anchor <- getanchor ();
4381 opendoc state.path
state.password
;
4383 src#
string "page scroll scaling factor"
4384 (fun () -> string_of_float
conf.pgscale)
4387 let s = float_of_string
v in
4390 state.text <- Printf.sprintf
4391 "bad page scroll scaling factor `%s': %s"
4392 v (Printexc.to_string exn
)
4395 src#
int "ui font size"
4396 (fun () -> fstate.fontsize
)
4397 (fun v -> setfontsize (bound v 5 100));
4398 src#
int "hint font size"
4399 (fun () -> conf.hfsize
)
4400 (fun v -> conf.hfsize
<- bound v 5 100);
4401 colorp "background color"
4402 (fun () -> conf.bgcolor
)
4403 (fun v -> conf.bgcolor
<- v);
4404 src#
bool "crop hack"
4405 (fun () -> conf.crophack
)
4406 (fun v -> conf.crophack
<- v);
4407 src#
bool "multi column centering"
4408 (fun () -> conf.multicenter
)
4409 (fun v -> conf.multicenter
<- v; represent ());
4410 src#
string "trim fuzz"
4411 (fun () -> irect_to_string conf.trimfuzz
)
4414 conf.trimfuzz
<- irect_of_string v;
4416 then settrim true conf.trimfuzz
;
4418 state.text <- Printf.sprintf
"bad irect `%s': %s"
4419 v (Printexc.to_string exn
)
4421 src#
string "throttle"
4423 match conf.maxwait
with
4424 | None
-> "show place holder if page is not ready"
4427 then "wait for page to fully render"
4429 "wait " ^ string_of_float
time
4430 ^
" seconds before showing placeholder"
4434 let f = float_of_string
v in
4436 then conf.maxwait
<- None
4437 else conf.maxwait
<- Some
f
4439 state.text <- Printf.sprintf
"bad time `%s': %s"
4440 v (Printexc.to_string exn
)
4442 src#
string "ghyll scroll"
4444 match conf.ghyllscroll
with
4446 | Some nab
-> ghyllscroll_to_string nab
4451 if String.length
v = 0
4453 else Some
(ghyllscroll_of_string v)
4455 conf.ghyllscroll
<- gs
4457 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4458 v (Printexc.to_string exn
)
4460 src#
string "selection command"
4461 (fun () -> conf.selcmd
)
4462 (fun v -> conf.selcmd
<- v);
4463 src#colorspace
"color space"
4464 (fun () -> colorspace_to_string conf.colorspace
)
4466 conf.colorspace
<- colorspace_of_int v;
4473 src#caption
"Document" 0;
4474 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4475 src#caption2
"Pages"
4476 (fun () -> string_of_int
state.pagecount
) 1;
4477 src#caption2
"Dimensions"
4478 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4482 src#caption
"Trimmed margins" 0;
4483 src#caption2
"Dimensions"
4484 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4488 src#caption
"OpenGL" 0;
4489 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4490 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4491 src#reset prevmode prevuioh
;
4495 let prevmode = state.mode
4496 and prevuioh
= state.uioh in
4497 fillsrc prevmode prevuioh
;
4498 let source = (src :> lvsource
) in
4499 let modehash = findkeyhash conf "info" in
4500 state.uioh <- coe (object (self)
4501 inherit listview ~
source ~trusted
:true ~
modehash as super
4502 val mutable m_prevmemused
= 0
4503 method infochanged
= function
4505 if m_prevmemused
!= state.memused
4507 m_prevmemused
<- state.memused
;
4508 G.postRedisplay "memusedchanged";
4510 | Pdim
-> G.postRedisplay "pdimchanged"
4511 | Docinfo
-> fillsrc prevmode prevuioh
4513 method key key mask
=
4514 if not
(Wsi.withctrl mask
)
4517 | 0xff51 -> coe (self#updownlevel ~
-1)
4518 | 0xff53 -> coe (self#updownlevel
1)
4519 | _ -> super#
key key mask
4520 else super#
key key mask
4522 G.postRedisplay "info";
4528 inherit lvsourcebase
4529 method getitemcount
= Array.length
state.help
4531 let s, n, _ = state.help
.(n) in
4534 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4538 m_qsearch
<- qsearch;
4539 match state.help
.(active) with
4540 | _, _, Action
f -> Some
(f uioh)
4550 method hasaction
n =
4551 match state.help
.(n) with
4552 | _, _, Action
_ -> true
4559 let modehash = findkeyhash conf "help" in
4560 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4561 G.postRedisplay "help";
4566 let re = Str.regexp
"[\r\n]" in
4568 inherit lvsourcebase
4569 val mutable m_items
= [||]
4571 method getitemcount
= 1 + Array.length m_items
4576 else m_items
.(n-1), 0
4578 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4583 then Buffer.clear
state.errmsgs
;
4584 m_qsearch
<- qsearch;
4591 method hasaction
n =
4595 state.newerrmsgs
<- false;
4596 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4597 m_items
<- Array.of_list
l
4605 let source = (msgsource :> lvsource
) in
4606 let modehash = findkeyhash conf "listview" in
4607 state.uioh <- coe (object
4608 inherit listview ~
source ~trusted
:false ~
modehash as super
4611 then msgsource#reset
;
4614 G.postRedisplay "msgs";
4617 let quickbookmark ?title
() =
4618 match state.layout with
4624 let sec = Unix.gettimeofday
() in
4625 let tm = Unix.localtime
sec in
4626 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4630 (tm.Unix.tm_year
+ 1900)
4633 | Some
title -> title
4635 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4639 state.fullscreen
<- None
;
4643 let setautoscrollspeed step goingdown
=
4644 let incr = max
1 ((abs step
) / 2) in
4645 let incr = if goingdown
then incr else -incr in
4646 let astep = step
+ incr in
4647 state.autoscroll
<- Some
astep;
4650 let gotounder = function
4651 | Ulinkgoto
(pageno, top) ->
4655 gotopage1 pageno top;
4661 | Uremote
(filename
, pageno) ->
4663 if Sys.file_exists filename
4666 let dir = Filename.dirname
state.path in
4667 let path = Filename.concat
dir filename
in
4668 if Sys.file_exists
path
4672 if String.length
path > 0
4674 let anchor = getanchor () in
4675 let ranchor = state.path, state.password
, anchor in
4676 state.anchor <- (pageno, 0.0, 0.0);
4677 state.ranchors
<- ranchor :: state.ranchors
;
4680 else showtext '
!'
("Could not find " ^ filename
)
4682 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4686 match conf.columns
with
4688 | _ -> conf.zoom > 1.0
4691 let viewkeyboard key mask
=
4693 let mode = state.mode in
4694 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4697 G.postRedisplay "view:enttext"
4699 let ctrl = Wsi.withctrl mask
in
4704 | 0xff63 -> (* insert *)
4705 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4707 state.mode <- LinkNav
(Ltgendir
0);
4710 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4712 | 0xff1b | 113 -> (* escape / q *)
4713 begin match state.mstate
with
4715 state.mstate
<- Mnone
;
4716 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4717 G.postRedisplay "kill zoom rect";
4719 match state.ranchors
with
4721 | (path, password
, anchor) :: rest
->
4722 state.ranchors
<- rest
;
4723 state.anchor <- anchor;
4724 opendoc path password
4727 | 0xff08 -> (* backspace *)
4728 let y = getnav ~
-1 in
4729 gotoy_and_clear_text y
4737 G.postRedisplay "dehighlight";
4739 | 47 | 63 -> (* / ? *)
4740 let ondone isforw
s =
4741 cbput state.hists
.pat
s;
4742 state.searchpattern
<- s;
4745 let s = String.create
1 in
4746 s.[0] <- Char.chr
key;
4747 enttext (s, "", Some
(onhist state.hists
.pat
),
4748 textentry, ondone (key = 47), true)
4750 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4751 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4752 setzoom (conf.zoom +. incr)
4754 | 43 | 0xffab -> (* + *)
4757 try int_of_string
s with exc
->
4758 state.text <- Printf.sprintf
"bad integer `%s': %s"
4759 s (Printexc.to_string exc
);
4765 state.text <- "page bias is now " ^ string_of_int
n;
4768 enttext ("page bias: ", "", None
, intentry, ondone, true)
4770 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4771 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4772 setzoom (max
0.01 (conf.zoom -. decr))
4774 | 45 | 0xffad -> (* - *)
4775 let ondone msg
= state.text <- msg
in
4777 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4778 optentry state.mode, ondone, true
4781 | 48 when ctrl -> (* ctrl-0 *)
4784 | 49 when ctrl -> (* ctrl-1 *)
4786 match conf.columns
with
4787 | Csingle
_ | Cmulti
_ -> 1
4788 | Csplit
(n, _) -> n
4790 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4794 | 0xffc6 -> (* f9 *)
4797 | 57 when ctrl -> (* ctrl-9 *)
4800 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4801 when not
ctrl -> (* 0..9 *)
4804 try int_of_string
s with exc
->
4805 state.text <- Printf.sprintf
"bad integer `%s': %s"
4806 s (Printexc.to_string exc
);
4812 cbput state.hists
.pag
(string_of_int
n);
4813 gotopage1 (n + conf.pagebias
- 1) 0;
4816 let pageentry text key =
4817 match Char.unsafe_chr
key with
4818 | 'g'
-> TEdone
text
4819 | _ -> intentry text key
4821 let text = "x" in text.[0] <- Char.chr
key;
4822 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4825 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4826 reshape conf.winw
conf.winh
;
4829 conf.hlinks
<- not
conf.hlinks
;
4830 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4831 G.postRedisplay "toggle highlightlinks";
4834 state.glinks
<- true;
4835 let mode = state.mode in
4836 state.mode <- Textentry
(
4837 (":", "", None
, linknentry, linkndone (fun under ->
4842 state.glinks
<- false;
4846 G.postRedisplay "view:linkent(F)"
4849 state.glinks
<- true;
4850 let mode = state.mode in
4851 state.mode <- Textentry
(
4852 (":", "", None
, linknentry, linkndone (fun under ->
4853 match Ne.pipe () with
4855 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4856 (Printexc.to_string exn
));
4859 try popen conf.selcmd
[r, 0; w, -1]; true
4862 (Printf.sprintf
"failed to execute %s: %s"
4863 conf.selcmd
(Printexc.to_string exn
));
4867 Ne.clo fd
(fun msg
->
4868 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4871 let s = undertext under in
4875 let l = String.length
s in
4876 let n = Unix.write
w s 0 l in
4881 "failed to write %d characters to sel pipe, wrote %d"
4886 (Printf.sprintf
"failed to write to sel pipe: %s"
4887 (Printexc.to_string exn
)
4896 state.glinks
<- false;
4900 G.postRedisplay "view:linkent"
4903 begin match state.autoscroll
with
4905 conf.autoscrollstep
<- step
;
4906 state.autoscroll
<- None
4908 if conf.autoscrollstep
= 0
4909 then state.autoscroll
<- Some
1
4910 else state.autoscroll
<- Some
conf.autoscrollstep
4913 | 112 when ctrl -> (* ctrl-p *)
4917 setpresentationmode (not
conf.presentation
);
4918 showtext ' '
("presentation mode " ^
4919 if conf.presentation
then "on" else "off");
4922 begin match state.fullscreen
with
4924 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4927 state.fullscreen
<- None
;
4932 gotoy_and_clear_text 0
4935 gotopage1 (state.pagecount
- 1) 0
4937 | 112 | 78 -> (* p|N *)
4938 search state.searchpattern
false
4940 | 110 | 0xffc0 -> (* n|F3 *)
4941 search state.searchpattern
true
4944 begin match state.layout with
4947 gotoy_and_clear_text (getpagey l.pageno)
4951 begin match state.layout with
4954 match conf.columns
with
4956 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4958 let y = clamp (pgscale conf.winh
) in
4959 gotoy_and_clear_text y
4961 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4962 gotoy_and_clear_text (getpagey pageno)
4963 | Cmulti
((c, _, _), _) ->
4964 if conf.presentation
&& l.pageh
> l.pagey + l.pagevh
4966 let y = clamp (pgscale conf.winh
) in
4967 gotoy_and_clear_text y
4969 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4970 gotoy_and_clear_text (getpagey pageno)
4972 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4974 let pagey, pageh
= getpageyh l.pageno in
4975 let pagey = pagey + pageh
* l.pagecol
in
4976 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4977 gotoy_and_clear_text (pagey + pageh
+ ips)
4980 | 0xff9f | 0xffff -> (* delete *)
4981 begin match state.layout with
4984 match conf.columns
with
4986 if conf.presentation
&& l.pagey != 0
4988 gotoy_and_clear_text (clamp (pgscale ~
-(conf.winh
)))
4990 let pageno = max
0 (l.pageno-1) in
4991 gotoy_and_clear_text (getpagey pageno)
4992 | Cmulti
((c, _, coverB
), _) ->
4994 if l.pageno = state.pagecount
- coverB
4998 let pageno = max
0 (l.pageno-decr) in
4999 gotoy_and_clear_text (getpagey pageno)
5007 let pageno = max
0 (l.pageno-1) in
5008 let pagey, pageh
= getpageyh pageno in
5011 let pagey, pageh
= getpageyh l.pageno in
5012 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5014 gotoy_and_clear_text y
5018 showtext ' '
(describe_location ());
5021 begin match state.layout with
5024 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5029 enterbookmarkmode ()
5031 | 104 | 0xffbe -> (* h|F1 *)
5037 | 101 when conf.redirectstderr -> (* e *)
5042 match state.layout with
5043 | l :: _ -> state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5046 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5050 showtext ' '
"Quick bookmark added";
5053 begin match state.layout with
5055 let rect = getpdimrect
l.pagedimno
in
5059 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5060 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5062 (truncate
(rect.(1) -. rect.(0)),
5063 truncate
(rect.(3) -. rect.(0)))
5065 let w = truncate
((float w)*.conf.zoom)
5066 and h = truncate
((float h)*.conf.zoom) in
5069 state.anchor <- getanchor ();
5070 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5072 G.postRedisplay "z";
5077 | 50 when ctrl -> (* ctrl-2 *)
5078 let maxw = getmaxw
() in
5080 then setzoom (maxw /. float conf.winw
)
5082 | 60 | 62 -> (* < > *)
5083 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5085 | 91 | 93 -> (* [ ] *)
5087 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5089 G.postRedisplay "brightness";
5091 | 99 when state.mode = View
-> (* c *)
5093 match state.prevcolumns
with
5094 | None
-> (1, 0, 0), 1.0
5095 | Some
(columns
, z
) ->
5098 | Csplit
(c, _) -> -c, 0, 0
5099 | Cmulti
((c, a, b), _) -> c, a, b
5100 | Csingle
_ -> 1, 0, 0
5104 setcolumns View
c a b;
5107 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5108 setzoom state.prevzoom
5110 | 107 | 0xff52 -> (* k up *)
5111 begin match state.autoscroll
with
5113 begin match state.mode with
5114 | Birdseye beye
-> upbirdseye 1 beye
5117 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5118 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5121 setautoscrollspeed n false
5124 | 106 | 0xff54 -> (* j down *)
5125 begin match state.autoscroll
with
5127 begin match state.mode with
5128 | Birdseye beye
-> downbirdseye 1 beye
5131 then gotoy_and_clear_text (clamp (conf.winh
/2))
5132 else gotoy_and_clear_text (clamp conf.scrollstep
)
5135 setautoscrollspeed n true
5138 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5146 let dx = if key = 0xff51 then dx else -dx in
5147 state.x <- state.x + dx;
5148 gotoy_and_clear_text state.y
5151 G.postRedisplay "lef/right"
5154 | 0xff55 -> (* prior *)
5158 match state.layout with
5160 | l :: _ -> state.y - l.pagey
5162 clamp (pgscale (-conf.winh
))
5166 | 0xff56 -> (* next *)
5170 match List.rev
state.layout with
5172 | l :: _ -> getpagey l.pageno
5174 clamp (pgscale conf.winh
)
5178 | 0xff50 -> (* home *)
5180 | 0xff57 -> (* end *)
5181 gotoghyll (clamp state.maxy)
5182 | 0xff53 when Wsi.withalt mask
-> (* right *)
5183 gotoghyll (getnav ~
-1)
5184 | 0xff51 when Wsi.withalt mask
-> (* left *)
5185 gotoghyll (getnav 1)
5188 state.anchor <- getanchor ();
5189 opendoc state.path state.password
5191 | 118 when conf.debug
-> (* v *)
5194 match getopaque l.pageno with
5197 let x0, y0, x1, y1 = pagebbox opaque
in
5198 let a,b = float x0, float y0 in
5199 let c,d = float x1, float y0 in
5200 let e,f = float x1, float y1 in
5201 let h,j
= float x0, float y1 in
5202 let rect = (a,b,c,d,e,f,h,j
) in
5204 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5206 G.postRedisplay "v";
5209 vlog "huh? %s" (Wsi.keyname
key)
5212 let linknavkeyboard key mask
linknav =
5213 let getpage pageno =
5214 let rec loop = function
5216 | l :: _ when l.pageno = pageno -> Some
l
5217 | _ :: rest
-> loop rest
5218 in loop state.layout
5220 let doexact (pageno, n) =
5221 match getopaque pageno, getpage pageno with
5222 | Some opaque
, Some
l ->
5225 let under = getlink opaque
n in
5226 G.postRedisplay "link gotounder";
5232 | 0xff50 -> (* home *)
5233 Some
(findlink opaque LDfirst
), -1
5235 | 0xff57 -> (* end *)
5236 Some
(findlink opaque LDlast
), 1
5238 | 0xff51 -> (* left *)
5239 Some
(findlink opaque
(LDleft
n)), -1
5241 | 0xff53 -> (* right *)
5242 Some
(findlink opaque
(LDright
n)), 1
5244 | 0xff52 -> (* up *)
5245 Some
(findlink opaque
(LDup
n)), -1
5247 | 0xff54 -> (* down *)
5248 Some
(findlink opaque
(LDdown
n)), 1
5253 begin match findpwl
l.pageno dir with
5257 state.mode <- LinkNav
(Ltgendir
dir);
5258 let y, h = getpageyh pageno in
5261 then y + h - conf.winh
5266 begin match getopaque pageno, getpage pageno with
5267 | Some opaque
, Some
_ ->
5269 let ld = if dir > 0 then LDfirst
else LDlast
in
5272 begin match link with
5274 showlinktype (getlink opaque
m);
5275 state.mode <- LinkNav
(Ltexact
(pageno, m));
5276 G.postRedisplay "linknav jpage";
5283 begin match opt with
5284 | Some Lnotfound
-> pwl l dir;
5285 | Some
(Lfound
m) ->
5289 let _, y0, _, y1 = getlinkrect opaque
m in
5291 then gotopage1 l.pageno y0
5293 let d = fstate.fontsize
+ 1 in
5294 if y1 - l.pagey > l.pagevh - d
5295 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5296 else G.postRedisplay "linknav";
5298 showlinktype (getlink opaque
m);
5299 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5302 | None
-> viewkeyboard key mask
5304 | _ -> viewkeyboard key mask
5309 G.postRedisplay "leave linknav"
5313 | Ltgendir
_ -> viewkeyboard key mask
5314 | Ltexact exact
-> doexact exact
5317 let keyboard key mask
=
5318 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5319 then wcmd "interrupt"
5320 else state.uioh <- state.uioh#
key key mask
5323 let birdseyekeyboard key mask
5324 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5326 match conf.columns
with
5328 | Cmulti
((c, _, _), _) -> c
5329 | Csplit
_ -> failwith
"bird's eye split mode"
5331 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5333 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5334 let y, h = getpageyh pageno in
5335 let top = (conf.winh
- h) / 2 in
5336 gotoy (max
0 (y - top))
5337 | 0xff0d -> leavebirdseye beye
false
5338 | 0xff1b -> leavebirdseye beye
true (* escape *)
5339 | 0xff52 -> upbirdseye incr beye
(* up *)
5340 | 0xff54 -> downbirdseye incr beye
(* down *)
5341 | 0xff51 -> upbirdseye 1 beye
(* left *)
5342 | 0xff53 -> downbirdseye 1 beye
(* right *)
5344 | 0xff55 -> (* prior *)
5345 begin match state.layout with
5349 state.mode <- Birdseye
(
5350 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5352 gotopage1 l.pageno 0;
5355 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5357 | [] -> gotoy (clamp (-conf.winh
))
5359 state.mode <- Birdseye
(
5360 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5362 gotopage1 l.pageno 0
5365 | [] -> gotoy (clamp (-conf.winh
))
5368 | 0xff56 -> (* next *)
5369 begin match List.rev
state.layout with
5371 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5372 begin match layout with
5374 let incr = l.pageh
- l.pagevh in
5379 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5381 G.postRedisplay "birdseye pagedown";
5383 else gotoy (clamp (incr + conf.interpagespace
*2));
5387 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5388 gotopage1 l.pageno 0;
5391 | [] -> gotoy (clamp conf.winh
)
5394 | 0xff50 -> (* home *)
5395 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5398 | 0xff57 -> (* end *)
5399 let pageno = state.pagecount
- 1 in
5400 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5401 if not
(pagevisible state.layout pageno)
5404 match List.rev
state.pdims
with
5406 | (_, _, h, _) :: _ -> h
5408 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5409 else G.postRedisplay "birdseye end";
5410 | _ -> viewkeyboard key mask
5413 let drawpage l linkindexbase
=
5415 match state.mode with
5416 | Textentry
_ -> scalecolor 0.4
5418 | View
-> scalecolor 1.0
5419 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5420 if l.pageno = hooverpageno
5423 if l.pageno = pageno
5429 begin match getopaque l.pageno with
5431 if tileready l l.pagex
l.pagey
5433 let x = l.pagedispx - l.pagex
5434 and y = l.pagedispy - l.pagey in
5436 match conf.columns
with
5437 | Csingle
_ | Cmulti
_ ->
5438 (if conf.hlinks
then 1 else 0)
5440 && not
(isbirdseye state.mode) then 2 else 0)
5444 match state.mode with
5445 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5448 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5455 let scrollindicator () =
5456 let sbw, ph
, sh = state.uioh#
scrollph in
5457 let sbh, pw, sw = state.uioh#scrollpw
in
5459 GlDraw.color (0.64, 0.64, 0.64);
5461 (float (conf.winw
- sbw), 0.)
5462 (float conf.winw
, float conf.winh
)
5465 (0., float (conf.winh
- sbh))
5466 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5468 GlDraw.color (0.0, 0.0, 0.0);
5471 (float (conf.winw
- sbw), ph
)
5472 (float conf.winw
, ph
+. sh)
5475 (pw, float (conf.winh
- sbh))
5476 (pw +. sw, float conf.winh
)
5481 match state.mstate
with
5482 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5485 | Msel
((x0, y0), (x1, y1)) ->
5486 let rec loop = function
5488 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5489 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5490 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5491 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5493 match getopaque l.pageno with
5495 let x0, y0 = pagetranslatepoint l x0 y0 in
5496 let x1, y1 = pagetranslatepoint l x1 y1 in
5497 seltext opaque
(x0, y0, x1, y1);
5505 let showrects rects
=
5507 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5508 GlDraw.polygon_mode `both `fill
;
5509 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5511 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5513 if l.pageno = pageno
5515 let dx = float (l.pagedispx - l.pagex
) in
5516 let dy = float (l.pagedispy - l.pagey) in
5517 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5518 GlDraw.begins `quads
;
5520 GlDraw.vertex2
(x0+.dx, y0+.dy);
5521 GlDraw.vertex2
(x1+.dx, y1+.dy);
5522 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5523 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5534 GlClear.color (scalecolor2 conf.bgcolor
);
5535 GlClear.clear
[`
color];
5536 let rec loop linkindexbase
= function
5538 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5539 loop linkindexbase rest
5542 loop 0 state.layout;
5544 match state.mode with
5545 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5546 begin match getopaque pageno with
5548 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5555 | None
-> state.rects
5562 begin match state.mstate
with
5563 | Mzoomrect
((x0, y0), (x1, y1)) ->
5565 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5566 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5567 GlDraw.rect (float x0, float y0)
5568 (float x1, float y1);
5577 let zoomrect x y x1 y1 =
5580 and y0 = min
y y1 in
5581 gotoy (state.y + y0);
5582 state.anchor <- getanchor ();
5583 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5585 if state.w < conf.winw
- state.scrollw
5586 then (conf.winw
- state.scrollw
- state.w) / 2
5589 state.x <- (state.x + margin) - x0;
5591 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5592 state.mstate
<- Mnone
;
5596 let winw = conf.winw - state.scrollw
- 1 in
5597 let s = float x /. float winw in
5598 let destx = truncate
(float (state.w + winw) *. s) in
5599 state.x <- winw - destx;
5600 gotoy_and_clear_text state.y;
5601 state.mstate
<- Mscrollx
;
5605 let s = float y /. float conf.winh
in
5606 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5607 gotoy_and_clear_text desty;
5608 state.mstate
<- Mscrolly
;
5611 let viewmouse button down
x y mask
=
5613 | n when (n == 4 || n == 5) && not down
->
5614 if Wsi.withctrl mask
5616 match state.mstate
with
5617 | Mzoom
(oldn
, i
) ->
5625 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5627 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5629 let zoom = conf.zoom -. incr in
5631 state.mstate
<- Mzoom
(n, 0);
5633 state.mstate
<- Mzoom
(n, i
+1);
5635 else state.mstate
<- Mzoom
(n, 0)
5637 | _ -> state.mstate
<- Mzoom
(n, 0)
5640 match state.autoscroll
with
5641 | Some step
-> setautoscrollspeed step
(n=4)
5645 then -conf.scrollstep
5646 else conf.scrollstep
5648 let incr = incr * 2 in
5649 let y = clamp incr in
5650 gotoy_and_clear_text y
5653 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5654 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5655 gotoy_and_clear_text state.y
5657 | 1 when Wsi.withctrl mask
->
5660 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5661 state.mstate
<- Mpan
(x, y)
5664 state.mstate
<- Mnone
5669 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5671 state.mstate
<- Mzoomrect
(p, p)
5674 match state.mstate
with
5675 | Mzoomrect
((x0, y0), _) ->
5676 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5677 then zoomrect x0 y0 x y
5679 state.mstate
<- Mnone
;
5680 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5681 G.postRedisplay "kill accidental zoom rect";
5684 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5685 state.mstate
<- Mnone
5688 | 1 when x > conf.winw - state.scrollw
->
5691 let _, position, sh = state.uioh#
scrollph in
5692 if y > truncate
position && y < truncate
(position +. sh)
5693 then state.mstate
<- Mscrolly
5696 state.mstate
<- Mnone
5698 | 1 when y > conf.winh
- state.hscrollh ->
5701 let _, position, sw = state.uioh#scrollpw
in
5702 if x > truncate
position && x < truncate
(position +. sw)
5703 then state.mstate
<- Mscrollx
5706 state.mstate
<- Mnone
5709 let dest = if down
then getunder x y else Unone
in
5710 begin match dest with
5714 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5717 | Unone
when down
->
5718 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5719 state.mstate
<- Mpan
(x, y);
5721 | Unone
| Utext
_ ->
5724 if conf.angle
mod 360 = 0
5726 state.mstate
<- Msel
((x, y), (x, y));
5727 G.postRedisplay "mouse select";
5731 match state.mstate
with
5734 | Mzoom
_ | Mscrollx
| Mscrolly
->
5735 state.mstate
<- Mnone
5737 | Mzoomrect
((x0, y0), _) ->
5741 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5742 state.mstate
<- Mnone
5744 | Msel
((_, y0), (_, y1)) ->
5745 let rec loop = function
5748 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5749 || ((y1 >= l.pagedispy
5750 && y1 <= (l.pagedispy + l.pagevh)))
5752 match getopaque l.pageno with
5755 match Ne.pipe () with
5759 "can not create sel pipe: %s"
5760 (Printexc.to_string exn
));
5762 let doclose what fd
=
5763 Ne.clo fd
(fun msg
->
5764 dolog "%s close failed: %s" what msg
)
5767 popen conf.selcmd
[r, 0; w, -1];
5770 G.postRedisplay "copysel";
5772 dolog "can not execute %S: %s"
5773 conf.selcmd
(Printexc.to_string exn
);
5781 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5782 state.mstate
<- Mnone
;
5789 let birdseyemouse button down
x y mask
5790 (conf, leftx
, _, hooverpageno
, anchor) =
5793 let rec loop = function
5796 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5797 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5799 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5805 | _ -> viewmouse button down
x y mask
5808 let mouse button down
x y mask
=
5809 state.uioh <- state.uioh#button button down
x y mask
;
5813 state.uioh <- state.uioh#
motion x y
5817 state.uioh <- state.uioh#
pmotion x y;
5823 method key key mask
=
5824 begin match state.mode with
5825 | Textentry
textentry -> textentrykeyboard key mask
textentry
5826 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5827 | View
-> viewkeyboard key mask
5828 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5832 method button button bstate
x y mask
=
5833 begin match state.mode with
5835 | View
-> viewmouse button bstate
x y mask
5836 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5842 begin match state.mode with
5844 | View
| Birdseye
_ | LinkNav
_ ->
5845 match state.mstate
with
5846 | Mzoom
_ | Mnone
-> ()
5851 state.mstate
<- Mpan
(x, y);
5853 then state.x <- state.x + dx;
5855 gotoy_and_clear_text y
5858 state.mstate
<- Msel
(a, (x, y));
5859 G.postRedisplay "motion select";
5862 let y = min
conf.winh
(max
0 y) in
5866 let x = min
conf.winw (max
0 x) in
5869 | Mzoomrect
(p0
, _) ->
5870 state.mstate
<- Mzoomrect
(p0
, (x, y));
5871 G.postRedisplay "motion zoomrect";
5875 method pmotion x y =
5876 begin match state.mode with
5877 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5878 let rec loop = function
5880 if hooverpageno
!= -1
5882 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5883 G.postRedisplay "pmotion birdseye no hoover";
5886 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5887 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5889 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5890 G.postRedisplay "pmotion birdseye hoover";
5900 match state.mstate
with
5901 | Mnone
-> updateunder x y
5902 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5907 method infochanged
_ = ()
5910 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5911 let p, h = scrollph state.y maxy in
5915 let winw = conf.winw - state.scrollw
- 1 in
5916 let fwinw = float winw in
5918 let sw = fwinw /. float state.w in
5919 let sw = fwinw *. sw in
5920 max
sw (float conf.scrollh
)
5923 let f = state.w+winw in
5924 let r = float (winw-state.x) /. float f in
5925 let p = fwinw *. r in
5929 if position +. sw > fwinw
5930 then fwinw -. position
5933 state.hscrollh, position, sw
5937 match state.mode with
5938 | LinkNav
_ -> "links"
5939 | Textentry
_ -> "textentry"
5940 | Birdseye
_ -> "birdseye"
5943 findkeyhash conf modename
5950 let fontpath = ref "";;
5953 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5956 let l = String.length
s in
5957 let b = Buffer.create
l in
5963 try Sys.getenv
"HOME"
5966 ("Can not determine home directory location: " ^
5967 Printexc.to_string exn
);
5971 let modifier_of_string = function
5972 | "alt" -> Wsi.altmask
5973 | "shift" -> Wsi.shiftmask
5974 | "ctrl" | "control" -> Wsi.ctrlmask
5975 | "meta" -> Wsi.metamask
5980 let r = Str.regexp
"-" in
5982 let elems = Str.full_split
r s in
5985 let m1 = modifier_of_string s in
5987 then (Wsi.namekey
s, m)
5990 | Str.Delim
s when n land 1 = 0 -> g s
5992 | Str.Delim
_ -> (k
, m)
5994 let rec loop n k
m = function
5997 let k, m = f n k m x in
6003 let keys_of_string =
6004 let r = Str.regexp
"[ \t]" in
6006 let elems = Str.split
r s in
6007 List.map
key_of_string elems
6010 let copykeyhashes c =
6011 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6014 let config_of c attrs
=
6018 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6019 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6020 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6021 | "preload" -> { c with preload = bool_of_string
v }
6022 | "page-bias" -> { c with pagebias
= int_of_string
v }
6023 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6024 | "horizontal-scroll-step" ->
6025 { c with hscrollstep
= max
(int_of_string
v) 1 }
6026 | "auto-scroll-step" ->
6027 { c with autoscrollstep
= max
0 (int_of_string
v) }
6028 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6029 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6032 match String.lowercase
v with
6033 | "true" -> Some infinity
6035 | f -> Some
(float_of_string
f)
6037 { c with maxwait
= mw}
6038 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6039 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6040 | "vertical-margin" ->
6041 { c with interpagespace
= max
0 (int_of_string
v) }
6043 let zoom = float_of_string
v /. 100. in
6044 let zoom = max
zoom 0.0 in
6045 { c with zoom = zoom }
6046 | "presentation" -> { c with presentation
= bool_of_string
v }
6047 | "rotation-angle" -> { c with angle
= int_of_string
v }
6048 | "width" -> { c with winw = max
20 (int_of_string
v) }
6049 | "height" -> { c with winh
= max
20 (int_of_string
v) }
6050 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6051 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6052 | "pixmap-cache-size" ->
6053 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6054 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6055 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6056 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6057 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6058 | "background-color" -> { c with bgcolor
= color_of_string v }
6059 | "scrollbar-in-presentation" ->
6060 { c with scrollbarinpm
= bool_of_string
v }
6061 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6062 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6063 | "mupdf-store-size" ->
6064 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6065 | "checkers" -> { c with checkers
= bool_of_string
v }
6066 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6067 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6068 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6069 | "uri-launcher" -> { c with urilauncher
= unent v }
6070 | "path-launcher" -> { c with pathlauncher
= unent v }
6071 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6072 | "invert-colors" -> { c with invert
= bool_of_string
v }
6073 | "brightness" -> { c with colorscale
= float_of_string
v }
6074 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6076 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6078 let (n, _, _) as nab
= multicolumns_of_string v in
6080 then { c with columns
= Csplit
(-n, [||]) }
6081 else { c with columns
= Cmulti
(nab
, [||]) }
6082 | "birds-eye-columns" ->
6083 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6084 | "selection-command" -> { c with selcmd
= unent v }
6085 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6086 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6087 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6088 | "multi-column-centering" -> { c with multicenter
= bool_of_string
v }
6091 prerr_endline
("Error processing attribute (`" ^
6092 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6095 let rec fold c = function
6098 let c = apply c k v in
6101 fold { c with keyhashes
= copykeyhashes c } attrs
;
6104 let fromstring f pos
n v d =
6107 dolog "Error processing attribute (%S=%S) at %d\n%s"
6108 n v pos
(Printexc.to_string exn
)
6113 let bookmark_of attrs
=
6114 let rec fold title page
rely visy
= function
6115 | ("title", v) :: rest
-> fold v page
rely visy rest
6116 | ("page", v) :: rest
-> fold title v rely visy rest
6117 | ("rely", v) :: rest
-> fold title page
v visy rest
6118 | ("visy", v) :: rest
-> fold title page
rely v rest
6119 | _ :: rest
-> fold title page
rely visy rest
6120 | [] -> title, page
, rely, visy
6122 fold "invalid" "0" "0" "0" attrs
6126 let rec fold path page
rely pan visy
= function
6127 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6128 | ("page", v) :: rest
-> fold path v rely pan visy rest
6129 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6130 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6131 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6132 | _ :: rest
-> fold path page
rely pan visy rest
6133 | [] -> path, page
, rely, pan
, visy
6135 fold "" "0" "0" "0" "0" attrs
6139 let rec fold rs ls
= function
6140 | ("out", v) :: rest
-> fold v ls rest
6141 | ("in", v) :: rest
-> fold rs
v rest
6142 | _ :: rest
-> fold ls rs rest
6148 let setconf dst
src =
6149 dst
.scrollbw
<- src.scrollbw
;
6150 dst
.scrollh
<- src.scrollh
;
6151 dst
.icase
<- src.icase
;
6152 dst
.preload <- src.preload;
6153 dst
.pagebias
<- src.pagebias
;
6154 dst
.verbose
<- src.verbose
;
6155 dst
.scrollstep
<- src.scrollstep
;
6156 dst
.maxhfit
<- src.maxhfit
;
6157 dst
.crophack
<- src.crophack
;
6158 dst
.autoscrollstep
<- src.autoscrollstep
;
6159 dst
.maxwait
<- src.maxwait
;
6160 dst
.hlinks
<- src.hlinks
;
6161 dst
.underinfo
<- src.underinfo
;
6162 dst
.interpagespace
<- src.interpagespace
;
6163 dst
.zoom <- src.zoom;
6164 dst
.presentation
<- src.presentation
;
6165 dst
.angle
<- src.angle
;
6166 dst
.winw <- src.winw;
6167 dst
.winh
<- src.winh
;
6168 dst
.savebmarks
<- src.savebmarks
;
6169 dst
.memlimit
<- src.memlimit
;
6170 dst
.proportional
<- src.proportional
;
6171 dst
.texcount
<- src.texcount
;
6172 dst
.sliceheight
<- src.sliceheight
;
6173 dst
.thumbw
<- src.thumbw
;
6174 dst
.jumpback
<- src.jumpback
;
6175 dst
.bgcolor
<- src.bgcolor
;
6176 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6177 dst
.tilew
<- src.tilew
;
6178 dst
.tileh
<- src.tileh
;
6179 dst
.mustoresize
<- src.mustoresize
;
6180 dst
.checkers
<- src.checkers
;
6181 dst
.aalevel
<- src.aalevel
;
6182 dst
.trimmargins
<- src.trimmargins
;
6183 dst
.trimfuzz
<- src.trimfuzz
;
6184 dst
.urilauncher
<- src.urilauncher
;
6185 dst
.colorspace
<- src.colorspace
;
6186 dst
.invert
<- src.invert
;
6187 dst
.colorscale
<- src.colorscale
;
6188 dst
.redirectstderr <- src.redirectstderr;
6189 dst
.ghyllscroll
<- src.ghyllscroll
;
6190 dst
.columns
<- src.columns
;
6191 dst
.beyecolumns
<- src.beyecolumns
;
6192 dst
.selcmd
<- src.selcmd
;
6193 dst
.updatecurs
<- src.updatecurs
;
6194 dst
.pathlauncher
<- src.pathlauncher
;
6195 dst
.keyhashes
<- copykeyhashes src;
6196 dst
.hfsize
<- src.hfsize
;
6197 dst
.hscrollstep
<- src.hscrollstep
;
6198 dst
.pgscale <- src.pgscale;
6199 dst
.multicenter
<- src.multicenter
;
6203 let h = Hashtbl.create
10 in
6204 let dc = { defconf with angle
= defconf.angle
} in
6205 let rec toplevel v t spos
_ =
6207 | Vdata
| Vcdata
| Vend
-> v
6208 | Vopen
("llppconfig", _, closed
) ->
6211 else { v with f = llppconfig
}
6213 error
"unexpected subelement at top level" s spos
6214 | Vclose
_ -> error
"unexpected close at top level" s spos
6216 and llppconfig
v t spos
_ =
6218 | Vdata
| Vcdata
-> v
6219 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6220 | Vopen
("defaults", attrs
, closed
) ->
6221 let c = config_of dc attrs
in
6225 else { v with f = defaults
}
6227 | Vopen
("ui-font", attrs
, closed
) ->
6228 let rec getsize size
= function
6230 | ("size", v) :: rest
->
6232 fromstring int_of_string spos
"size" v fstate.fontsize
in
6234 | l -> getsize size l
6236 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6239 else { v with f = uifont
(Buffer.create
10) }
6241 | Vopen
("doc", attrs
, closed
) ->
6242 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6243 let path = unent pathent
6244 and pageno = fromstring int_of_string spos
"page" spage
0
6245 and rely = fromstring float_of_string spos
"rely" srely
0.0
6246 and pan
= fromstring int_of_string spos
"pan" span
0
6247 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6248 let c = config_of dc attrs
in
6249 let anchor = (pageno, rely, visy
) in
6251 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6252 else { v with f = doc
path pan
anchor c [] }
6255 error
"unexpected subelement in llppconfig" s spos
6257 | Vclose
"llppconfig" -> { v with f = toplevel }
6258 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6260 and defaults
v t spos
_ =
6262 | Vdata
| Vcdata
-> v
6263 | Vend
-> error
"unexpected end of input in defaults" s spos
6264 | Vopen
("keymap", attrs
, closed
) ->
6266 try List.assoc
"mode" attrs
6267 with Not_found
-> "global" in
6272 let h = findkeyhash dc modename in
6273 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6276 { v with f = pkeymap
ret KeyMap.empty }
6278 | Vopen
(_, _, _) ->
6279 error
"unexpected subelement in defaults" s spos
6281 | Vclose
"defaults" ->
6282 { v with f = llppconfig
}
6284 | Vclose
_ -> error
"unexpected close in defaults" s spos
6286 and uifont
b v t spos
epos =
6289 Buffer.add_substring
b s spos
(epos - spos
);
6291 | Vopen
(_, _, _) ->
6292 error
"unexpected subelement in ui-font" s spos
6293 | Vclose
"ui-font" ->
6294 if String.length
!fontpath = 0
6295 then fontpath := Buffer.contents
b;
6296 { v with f = llppconfig
}
6297 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6298 | Vend
-> error
"unexpected end of input in ui-font" s spos
6300 and doc
path pan
anchor c bookmarks
v t spos
_ =
6302 | Vdata
| Vcdata
-> v
6303 | Vend
-> error
"unexpected end of input in doc" s spos
6304 | Vopen
("bookmarks", _, closed
) ->
6307 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6309 | Vopen
("keymap", attrs
, closed
) ->
6311 try List.assoc
"mode" attrs
6312 with Not_found
-> "global"
6318 let h = findkeyhash c modename in
6319 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6320 doc
path pan
anchor c bookmarks
6322 { v with f = pkeymap
ret KeyMap.empty }
6324 | Vopen
(_, _, _) ->
6325 error
"unexpected subelement in doc" s spos
6328 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6329 { v with f = llppconfig
}
6331 | Vclose
_ -> error
"unexpected close in doc" s spos
6333 and pkeymap
ret keymap
v t spos
_ =
6335 | Vdata
| Vcdata
-> v
6336 | Vend
-> error
"unexpected end of input in keymap" s spos
6337 | Vopen
("map", attrs
, closed
) ->
6338 let r, l = map_of attrs
in
6339 let kss = fromstring keys_of_string spos
"in" r [] in
6340 let lss = fromstring keys_of_string spos
"out" l [] in
6344 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6345 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6348 then { v with f = pkeymap
ret keymap }
6351 { v with f = skip
"map" f }
6354 error
"unexpected subelement in keymap" s spos
6356 | Vclose
"keymap" ->
6357 { v with f = ret keymap }
6359 | Vclose
_ -> error
"unexpected close in keymap" s spos
6361 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6363 | Vdata
| Vcdata
-> v
6364 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6365 | Vopen
("item", attrs
, closed
) ->
6366 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6367 let page = fromstring int_of_string spos
"page" spage
0
6368 and rely = fromstring float_of_string spos
"rely" srely
0.0
6369 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6371 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6374 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6377 { v with f = skip
"item" f }
6380 error
"unexpected subelement in bookmarks" s spos
6382 | Vclose
"bookmarks" ->
6383 { v with f = doc
path pan
anchor c bookmarks }
6385 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6387 and skip tag
f v t spos
_ =
6389 | Vdata
| Vcdata
-> v
6391 error
("unexpected end of input in skipped " ^ tag
) s spos
6392 | Vopen
(tag'
, _, closed
) ->
6396 let f'
() = { v with f = skip tag
f } in
6397 { v with f = skip tag'
f'
}
6401 else error
("unexpected close in skipped " ^ tag
) s spos
6404 parse
{ f = toplevel; accu = () } s;
6410 let len = in_channel_length ic
in
6411 let s = String.create
len in
6412 really_input ic
s 0 len;
6415 | Parse_error
(msg
, s, pos
) ->
6416 let subs = subs s pos
in
6417 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6418 failwith
("parse error: " ^
s)
6421 failwith
("config load error: " ^
Printexc.to_string exn
)
6427 let dir = Filename.concat
home ".config" in
6428 if Sys.is_directory
dir then dir else home
6431 Filename.concat
dir "llpp.conf"
6434 let confpath = ref defconfpath;;
6437 if Sys.file_exists
!confpath
6440 (try Some
(open_in_bin
!confpath)
6443 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6444 Printexc.to_string exn
);
6454 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6455 Printexc.to_string exn
);
6463 f (Hashtbl.create
0, defconf)
6468 let pc, pb
, px, pa
=
6470 Hashtbl.find h (Filename.basename
state.path)
6471 with Not_found
-> dc, [], 0, emptyanchor
6475 state.bookmarks <- pb
;
6477 state.scrollw
<- conf.scrollbw
;
6479 then state.anchor <- pa
;
6480 cbput state.hists
.nav pa
;
6486 let add_attrs bb always
dc c =
6489 then Printf.bprintf bb
"\n %s='%b'" s a
6492 then Printf.bprintf bb
"\n %s='%d'" s a
6495 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6498 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6501 then Printf.bprintf bb
"\n %s='%f'" s a
6505 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6509 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6513 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6517 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6523 | Some
(_N
, _A
, _B
) ->
6524 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6534 else string_of_float
f
6536 Printf.bprintf bb
"\n %s='%s'" s v
6541 | Cmulti
((n, a, b), _) when n > 1 ->
6542 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6543 | Csplit
(n, _) when n > 1 ->
6544 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6550 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6555 then dc.winw, dc.winh
6557 match state.fullscreen
with
6559 | None
-> c.winw, c.winh
6561 oi
"width" w dc.winw;
6562 oi
"height" h dc.winh
;
6563 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6564 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6565 ob "case-insensitive-search" c.icase
dc.icase
;
6566 ob "preload" c.preload dc.preload;
6567 oi
"page-bias" c.pagebias
dc.pagebias
;
6568 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6569 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6570 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6571 ob "crop-hack" c.crophack
dc.crophack
;
6572 oW
"throttle" c.maxwait
dc.maxwait
;
6573 ob "highlight-links" c.hlinks
dc.hlinks
;
6574 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6575 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6576 oz
"zoom" c.zoom dc.zoom;
6577 ob "presentation" c.presentation
dc.presentation
;
6578 oi
"rotation-angle" c.angle
dc.angle
;
6579 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6580 ob "proportional-display" c.proportional
dc.proportional
;
6581 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6582 oi
"tex-count" c.texcount
dc.texcount
;
6583 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6584 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6585 ob "persistent-location" c.jumpback
dc.jumpback
;
6586 oc
"background-color" c.bgcolor
dc.bgcolor
;
6587 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6588 oi
"tile-width" c.tilew
dc.tilew
;
6589 oi
"tile-height" c.tileh
dc.tileh
;
6590 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6591 ob "checkers" c.checkers
dc.checkers
;
6592 oi
"aalevel" c.aalevel
dc.aalevel
;
6593 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6594 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6595 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6596 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6597 oC
"color-space" c.colorspace
dc.colorspace
;
6598 ob "invert-colors" c.invert
dc.invert
;
6599 oF
"brightness" c.colorscale
dc.colorscale
;
6600 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6601 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6602 oco
"columns" c.columns
dc.columns
;
6603 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6604 os
"selection-command" c.selcmd
dc.selcmd
;
6605 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6606 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6607 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6608 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6609 ob "multi-column-centering" c.multicenter
dc.multicenter
;
6612 let keymapsbuf always
dc c =
6613 let bb = Buffer.create
16 in
6614 let rec loop = function
6616 | (modename, h) :: rest
->
6617 let dh = findkeyhash dc modename in
6618 if always
|| h <> dh
6620 if Hashtbl.length
h > 0
6622 if Buffer.length
bb > 0
6623 then Buffer.add_char
bb '
\n'
;
6624 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6625 Hashtbl.iter
(fun i
o ->
6626 let isdifferent = always
||
6628 let dO = Hashtbl.find dh i
in
6630 with Not_found
-> true
6635 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6636 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6637 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6638 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6639 Buffer.add_string
bb (Wsi.keyname
k);
6642 let rec loop = function
6644 | km
:: [] -> addkm km
6645 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6649 Buffer.add_string
bb "<map in='";
6653 Buffer.add_string
bb "' out='";
6655 Buffer.add_string
bb "'/>\n"
6658 Buffer.add_string
bb "' out='";
6660 Buffer.add_string
bb "'/>\n"
6662 | KMmulti
(ins, kms
) ->
6663 Buffer.add_char
bb ' '
;
6665 Buffer.add_string
bb "' out='";
6667 Buffer.add_string
bb "'/>\n"
6669 Buffer.add_string
bb "</keymap>";
6679 let uifontsize = fstate.fontsize
in
6680 let bb = Buffer.create
32768 in
6682 let dc = if conf.bedefault
then conf else dc in
6683 Buffer.add_string
bb "<llppconfig>\n";
6685 if String.length
!fontpath > 0
6687 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6693 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6696 Buffer.add_string
bb "<defaults ";
6697 add_attrs bb true dc dc;
6698 let kb = keymapsbuf true dc dc in
6699 if Buffer.length
kb > 0
6701 Buffer.add_string
bb ">\n";
6702 Buffer.add_buffer
bb kb;
6703 Buffer.add_string
bb "\n</defaults>\n";
6705 else Buffer.add_string
bb "/>\n";
6707 let adddoc path pan
anchor c bookmarks =
6708 if bookmarks == [] && c = dc && anchor = emptyanchor
6711 Printf.bprintf
bb "<doc path='%s'"
6712 (enent
path 0 (String.length
path));
6714 if anchor <> emptyanchor
6716 let n, rely, visy
= anchor in
6717 Printf.bprintf
bb " page='%d'" n;
6720 Printf.bprintf
bb " rely='%f'" rely
6722 if abs_float visy
> 1e-6
6724 Printf.bprintf
bb " visy='%f'" visy
6729 then Printf.bprintf
bb " pan='%d'" pan
;
6731 add_attrs bb false dc c;
6732 let kb = keymapsbuf false dc c in
6734 begin match bookmarks with
6736 if Buffer.length
kb > 0
6738 Buffer.add_string
bb ">\n";
6739 Buffer.add_buffer
bb kb;
6740 Buffer.add_string
bb "\n</doc>\n";
6742 else Buffer.add_string
bb "/>\n"
6744 Buffer.add_string
bb ">\n<bookmarks>\n";
6745 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6747 "<item title='%s' page='%d'"
6748 (enent
title 0 (String.length
title))
6753 Printf.bprintf
bb " rely='%f'" rely
6755 if abs_float visy
> 1e-6
6757 Printf.bprintf
bb " visy='%f'" visy
6759 Buffer.add_string
bb "/>\n";
6761 Buffer.add_string
bb "</bookmarks>";
6762 if Buffer.length
kb > 0
6764 Buffer.add_string
bb "\n";
6765 Buffer.add_buffer
bb kb;
6767 Buffer.add_string
bb "\n</doc>\n";
6773 match state.mode with
6774 | Birdseye
(c, pan, _, _, _) ->
6776 match conf.columns
with
6777 | Cmulti
((c, _, _), _) -> Some
c
6781 match c.columns
with
6782 | Cmulti
(c, _) -> Cmulti
(c, [||])
6783 | Csingle
_ -> Csingle
[||]
6784 | Csplit
_ -> failwith
"quit from bird's eye while split"
6786 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6787 | _ -> state.x, conf
6789 let basename = Filename.basename state.path in
6790 adddoc basename pan (getanchor ())
6792 let autoscrollstep =
6793 match state.autoscroll
with
6795 | None
-> conf.autoscrollstep
6797 match state.mode with
6798 | Birdseye
(bc
, _, _, _, _) ->
6801 presentation
= bc
.presentation
;
6802 interpagespace
= bc
.interpagespace
;
6803 maxwait
= bc
.maxwait
;
6804 autoscrollstep = autoscrollstep }
6805 | _ -> { conf with autoscrollstep = autoscrollstep }
6807 (if conf.savebmarks
then state.bookmarks else []);
6809 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6811 then adddoc path x anchor c bookmarks
6813 Buffer.add_string
bb "</llppconfig>\n";
6816 if load1 f && Buffer.length
bb > 0
6819 let tmp = !confpath ^
".tmp" in
6820 let oc = open_out_bin
tmp in
6821 Buffer.output_buffer
oc bb;
6823 Unix.rename
tmp !confpath;
6826 ("error while saving configuration: " ^
Printexc.to_string exn
)
6831 let trimcachepath = ref "" in
6834 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6835 "<password> Set password");
6837 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6838 "<path> Set path to the user interface font");
6840 ("-c", Arg.String
(fun s -> Config.confpath := s),
6841 "<path> Set path to the configuration file");
6843 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6844 "<path> Set path to the trim cache file");
6846 ("-v", Arg.Unit
(fun () ->
6848 "%s\nconfiguration path: %s\n"
6852 exit
0), " Print version and exit");
6855 (fun s -> state.path <- s)
6856 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6858 if String.length
state.path = 0
6859 then (prerr_endline
"file name missing"; exit
1);
6861 if not
(Config.load ())
6862 then prerr_endline
"failed to load configuration";
6864 let globalkeyhash = findkeyhash conf "global" in
6865 let wsfd, winw, winh
= Wsi.init
(object
6867 if nogeomcmds state.geomcmds
|| platform == Posx
6870 GlClear.color (scalecolor2 conf.bgcolor
);
6871 GlClear.clear
[`
color];
6873 method display = display ()
6874 method reshape w h = reshape w h
6875 method mouse b d x y m = mouse b d x y m
6876 method motion x y = state.mpos
<- (x, y); motion x y
6877 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6879 let mascm = m land (
6880 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6882 match state.keystate
with
6884 let km = k, mascm in
6887 let modehash = state.uioh#
modehash in
6888 try Hashtbl.find modehash km
6890 try Hashtbl.find globalkeyhash km
6891 with Not_found
-> KMinsrt
(k, m)
6893 | KMinsrt
(k, m) -> keyboard k m
6894 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6895 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6897 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6898 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6899 state.keystate
<- KSnone
6900 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6901 state.keystate
<- KSinto
(keys
, insrt
)
6903 state.keystate
<- KSnone
6905 method enter
x y = state.mpos
<- (x, y); pmotion x y
6906 method leave = state.mpos
<- (-1, -1)
6907 method quit
= raise Quit
6908 end) conf.winw conf.winh
(platform = Posx
) in
6913 List.exists
GlMisc.check_extension
6914 [ "GL_ARB_texture_rectangle"
6915 ; "GL_EXT_texture_recangle"
6916 ; "GL_NV_texture_rectangle" ]
6918 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6921 match Ne.pipe () with
6923 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6927 match Ne.pipe () with
6929 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6939 setcheckers conf.checkers
;
6943 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6944 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6945 !Config.fontpath, !trimcachepath
6949 state.text <- "Opening " ^
state.path;
6951 opendoc state.path state.password
;
6954 let rec loop deadline
=
6956 match state.errfd
with
6957 | None
-> [state.sr
; state.wsfd]
6958 | Some fd
-> [state.sr
; state.wsfd; fd
]
6962 state.redisplay
<- false;
6969 if deadline
= infinity
6971 else max
0.0 (deadline
-. now)
6976 try Unix.select
r [] [] timeout
6977 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6983 if state.ghyll
== noghyll
6985 match state.autoscroll
with
6986 | Some step
when step
!= 0 ->
6987 let y = state.y + step
in
6991 else if y >= state.maxy then 0 else y
6994 if state.mode = View
6995 then state.text <- "";
6998 else deadline
+. 0.01
7003 let rec checkfds = function
7005 | fd
:: rest
when fd
= state.sr
->
7006 let cmd = readcmd state.sr
in
7010 | fd
:: rest
when fd
= state.wsfd ->
7015 let s = String.create
80 in
7016 let n = Unix.read fd
s 0 80 in
7017 if conf.redirectstderr
7019 Buffer.add_substring
state.errmsgs
s 0 n;
7020 state.newerrmsgs
<- true;
7021 state.redisplay
<- true;
7024 prerr_string
(String.sub
s 0 n);
7032 if deadline
= infinity
7036 match state.autoscroll
with
7037 | Some step
when step
!= 0 -> deadline1
7038 | _ -> if state.ghyll
== noghyll then infinity
else deadline1