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 cbcap b
= Array.length b
.store
;;
194 b
.wc
<- (b
.wc
+ 1) mod cap;
196 b
.len
<- min
(b
.len
+ 1) cap;
199 let cbempty b
= b
.len
= 0;;
201 let cbgetg b circular dir
=
205 let rc = b
.rc + dir
in
217 else bound rc 0 (b
.len
-1)
223 let cbget b
= cbgetg b
false;;
224 let cbgetc b
= cbgetg b
true;;
226 let drawstring size x y s
=
228 Gl.enable `texture_2d
;
229 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
230 ignore
(drawstr size x y s
);
232 Gl.disable `texture_2d
;
235 let drawstring1 size x y s
=
239 let drawstring2 size x y fmt
=
240 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
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
341 | Csingle
of singlecolumn
342 | Cmulti
of multicolumns
343 | Csplit
of splitcolumns
346 type anchor
= pageno
* top
* dtop
;;
348 type outline
= string * int * anchor
;;
350 type rect
= float * float * float * float * float * float * float * float;;
352 type tile
= opaque
* pixmapsize
* elapsed
353 and elapsed
= float;;
354 type pagemapkey
= pageno
* gen
;;
355 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
359 let emptyanchor = (0, 0.0, 0.0);;
361 type infochange
= | Memused
| Docinfo
| Pdim
;;
363 class type uioh
= object
364 method display
: unit
365 method key
: int -> int -> uioh
366 method button
: int -> bool -> int -> int -> int -> uioh
367 method motion
: int -> int -> uioh
368 method pmotion
: int -> int -> uioh
369 method infochanged
: infochange
-> unit
370 method scrollpw
: (int * float * float)
371 method scrollph
: (int * float * float)
372 method modehash
: keyhash
376 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
377 | Textentry
of (textentry
* onleave
)
379 | LinkNav
of linktarget
380 and onleave
= leavetextentrystatus
-> unit
381 and leavetextentrystatus
= | Cancel
| Confirm
382 and helpitem
= string * int * action
385 | Action
of (uioh
-> uioh
)
387 | Ltexact
of (pageno
* int)
391 let isbirdseye = function Birdseye _
-> true | _
-> false;;
392 let istextentry = function Textentry _
-> true | _
-> false;;
396 | Loading
of (page
* gen
)
398 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
400 | Outlining
of outline list
403 let emptykeyhash = Hashtbl.create
0;;
404 let nouioh : uioh
= object (self
)
406 method key _ _
= self
407 method button _ _ _ _ _
= self
408 method motion _ _
= self
409 method pmotion _ _
= self
410 method infochanged _
= ()
411 method scrollpw
= (0, nan
, nan
)
412 method scrollph
= (0, nan
, nan
)
413 method modehash
= emptykeyhash
417 { mutable sr
: Unix.file_descr
418 ; mutable sw
: Unix.file_descr
419 ; mutable wsfd
: Unix.file_descr
420 ; mutable errfd
: Unix.file_descr
option
421 ; mutable stderr
: Unix.file_descr
422 ; mutable errmsgs
: Buffer.t
423 ; mutable newerrmsgs
: bool
427 ; mutable scrollw
: int
428 ; mutable hscrollh
: int
429 ; mutable anchor
: anchor
430 ; mutable ranchors
: (string * string * anchor
) list
432 ; mutable layout
: page list
433 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
434 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
435 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
436 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
437 ; mutable pagecount
: int
438 ; mutable currently
: currently
439 ; mutable mstate
: mstate
440 ; mutable searchpattern
: string
441 ; mutable rects
: (pageno
* recttype
* rect
) list
442 ; mutable rects1
: (pageno
* recttype
* rect
) list
443 ; mutable text
: string
444 ; mutable fullscreen
: (width
* height
) option
445 ; mutable mode
: mode
446 ; mutable uioh
: uioh
447 ; mutable outlines
: outline array
448 ; mutable bookmarks
: outline list
449 ; mutable path
: string
450 ; mutable password
: string
451 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
452 ; mutable memused
: memsize
454 ; mutable throttle
: (page list
* int * float) option
455 ; mutable autoscroll
: int option
456 ; mutable ghyll
: (int option -> unit)
457 ; mutable help
: helpitem array
458 ; mutable docinfo
: (int * string) list
459 ; mutable texid
: GlTex.texture_id
option
461 ; mutable prevzoom
: float
462 ; mutable progress
: float
463 ; mutable redisplay
: bool
464 ; mutable mpos
: mpos
465 ; mutable keystate
: keystate
466 ; mutable glinks
: bool
467 ; mutable prevcolumns
: (columns
* float) option
470 { pat
: string circbuf
471 ; pag
: string circbuf
472 ; nav
: anchor circbuf
473 ; sel
: string circbuf
495 ; presentation
= false
500 ; proportional
= true
501 ; trimmargins
= false
502 ; trimfuzz
= (0,0,0,0)
503 ; memlimit
= 32 lsl 20
508 ; bgcolor
= (0.5, 0.5, 0.5)
510 ; scrollbarinpm
= true
513 ; mustoresize
= 256 lsl 20
518 | Plinux
| Pfreebsd
| Pdragonflybsd
519 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
520 | Posx
-> "open \"%s\""
521 | Pcygwin
-> "cygstart \"%s\""
522 | Punknown
-> "echo %s")
523 ; pathlauncher
= "lp \"%s\""
526 | Plinux
| Pfreebsd
| Pdragonflybsd
527 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
534 ; redirectstderr
= false
536 ; columns
= Csingle
[||]
542 let mk n
= (n
, Hashtbl.create
1) in
556 let findkeyhash c name
=
557 try List.assoc name c
.keyhashes
558 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
561 let conf = { defconf with angle
= defconf.angle
};;
563 let pgscale h
= truncate
(float h
*. conf.pgscale);;
566 { mutable fontsize
: int
567 ; mutable wwidth
: float
568 ; mutable maxrows
: int
580 fstate.fontsize
<- n
;
581 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
582 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
586 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
587 let len = String.length s
in
588 if colonpos >= 0 && colonpos + 3 < len
590 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
593 try String.rindex_from s
colonpos ' '
597 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
600 | "http" | "ftp" | "mailto" ->
602 try String.index_from s
colonpos ' '
603 with Not_found
-> len
605 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
613 if String.length
conf.urilauncher
= 0
614 then print_endline uri
616 let url = geturl uri
in
617 if String.length
url = 0
618 then print_endline uri
620 let re = Str.regexp
"%s" in
621 let command = Str.global_replace
re url conf.urilauncher
in
625 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
631 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
632 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
636 let strings = version () :: "" :: Help.keys
in
639 let url = geturl s
in
640 if String.length
url > 0
641 then (s
, 0, Action
(fun u
-> gotouri url; u
))
642 else (s
, 0, Noaction
)
647 let firstgeomcmds = "", [];;
654 ; stderr
= Unix.stderr
655 ; errmsgs
= Buffer.create
0
662 ; anchor
= emptyanchor
666 ; tilelru
= Queue.create
()
667 ; pagemap
= Hashtbl.create
10
668 ; tilemap
= Hashtbl.create
10
683 ; geomcmds
= firstgeomcmds
685 { nav
= cbnew 10 emptyanchor
712 Printf.kprintf prerr_endline fmt
714 Printf.kprintf ignore fmt
718 if String.length
conf.pathlauncher
= 0
719 then print_endline
state.path
721 let re = Str.regexp
"%s" in
722 let command = Str.global_replace
re state.path
conf.pathlauncher
in
726 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
732 type 'a t
= | Res
of 'a
| Exn
of exn
;;
735 try Res
(Unix.pipe ())
741 with exn
-> f
(Printexc.to_string exn
)
745 try Res
(Unix.dup fd
)
750 try Res
(Unix.dup2 fd1 fd2
)
755 let redirectstderr () =
756 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
757 if conf.redirectstderr
759 match Ne.pipe () with
761 dolog "failed to create stderr redirection pipes: %s"
762 (Printexc.to_string exn
)
765 begin match Ne.dup Unix.stderr
with
767 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
768 Ne.clo r
(clofail "pipe/r");
769 Ne.clo w
(clofail "pipe/w");
771 | Ne.Res dupstderr
->
772 begin match Ne.dup2 w
Unix.stderr
with
774 dolog "failed to dup2 to stderr: %s"
775 (Printexc.to_string exn
);
776 Ne.clo dupstderr
(clofail "stderr duplicate");
777 Ne.clo r
(clofail "redir pipe/r");
778 Ne.clo w
(clofail "redir pipe/w");
781 state.stderr
<- dupstderr
;
782 state.errfd
<- Some r
;
786 state.newerrmsgs
<- false;
787 begin match state.errfd
with
789 begin match Ne.dup2 state.stderr
Unix.stderr
with
791 dolog "failed to dup2 original stderr: %s"
792 (Printexc.to_string exn
)
794 Ne.clo fd
(clofail "dup of stderr");
795 Unix.dup2 state.stderr
Unix.stderr
;
800 prerr_string
(Buffer.contents
state.errmsgs
);
802 Buffer.clear
state.errmsgs
;
808 let postRedisplay who
=
810 then prerr_endline
("redisplay for " ^ who
);
811 state.redisplay
<- true;
815 let getopaque pageno
=
816 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
817 with Not_found
-> None
820 let putopaque pageno opaque
=
821 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
824 let pagetranslatepoint l x y
=
825 let dy = y
- l
.pagedispy
in
826 let y = dy + l
.pagey
in
827 let dx = x
- l
.pagedispx
in
828 let x = dx + l
.pagex
in
835 begin match getopaque l
.pageno
with
837 let x0 = l
.pagedispx
in
838 let x1 = x0 + l
.pagevw
in
839 let y0 = l
.pagedispy
in
840 let y1 = y0 + l
.pagevh
in
841 if y >= y0 && y <= y1 && x >= x0 && x <= x1
843 let px, py
= pagetranslatepoint l
x y in
844 match whatsunder opaque
px py
with
857 state.text
<- Printf.sprintf
"%c%s" c s
;
858 G.postRedisplay "showtext";
861 let undertext = function
864 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
865 | Utext s
-> "font: " ^ s
866 | Uunexpected s
-> "unexpected: " ^ s
867 | Ulaunch s
-> "launch: " ^ s
868 | Unamed s
-> "named: " ^ s
869 | Uremote
(filename
, pageno
) ->
870 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
873 let updateunder x y =
874 match getunder x y with
875 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
877 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
878 Wsi.setcursor
Wsi.CURSOR_INFO
879 | Ulinkgoto
(pageno
, _
) ->
881 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
882 Wsi.setcursor
Wsi.CURSOR_INFO
884 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
885 Wsi.setcursor
Wsi.CURSOR_TEXT
887 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
888 Wsi.setcursor
Wsi.CURSOR_INHERIT
890 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
891 Wsi.setcursor
Wsi.CURSOR_INHERIT
893 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
894 Wsi.setcursor
Wsi.CURSOR_INHERIT
895 | Uremote
(filename
, pageno
) ->
896 if conf.underinfo
then showtext 'r'
897 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
898 Wsi.setcursor
Wsi.CURSOR_INFO
901 let showlinktype under
=
907 let s = undertext under
in
912 let b = Buffer.create
(String.length
s + 1) in
913 Buffer.add_string
b s;
918 let colorspace_of_string s =
919 match String.lowercase
s with
923 | _
-> failwith
"invalid colorspace"
926 let int_of_colorspace = function
932 let colorspace_of_int = function
936 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
939 let colorspace_to_string = function
945 let intentry_with_suffix text key
=
947 if key
>= 32 && key
< 127
951 match Char.lowercase
c with
953 let text = addchar text c in
957 let text = addchar text c in
961 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
965 let multicolumns_to_string (n
, a
, b) =
967 then Printf.sprintf
"%d" n
968 else Printf.sprintf
"%d,%d,%d" n a
b;
971 let multicolumns_of_string s =
973 (int_of_string
s, 0, 0)
975 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
977 then failwith
"subtly broken"; (n
, a
, b)
983 let n = Unix.read fd
s 0 4 in
984 if n != 4 then failwith
"incomplete read(len)";
986 lor (Char.code
s.[0] lsl 24)
987 lor (Char.code
s.[1] lsl 16)
988 lor (Char.code
s.[2] lsl 8)
989 lor (Char.code
s.[3] lsl 0)
991 let s = String.create
len in
992 let n = Unix.read fd
s 0 len in
993 if n != len then failwith
"incomplete read(data)";
997 let btod b = if b then 1 else 0;;
1000 let b = Buffer.create
16 in
1001 Buffer.add_string
b "llll";
1004 let s = Buffer.contents
b in
1005 let n = String.length
s in
1007 (* dolog "wcmd %S" (String.sub s 4 len); *)
1008 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1009 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1010 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1011 s.[3] <- Char.chr
(len land 0xff);
1012 let n'
= Unix.write
state.sw
s 0 n in
1013 if n'
!= n then failwith
"write failed";
1018 let d = conf.winh
- h
in
1019 max
conf.interpagespace
((d + 1) / 2)
1022 let rowyh (c, coverA
, coverB
) b n =
1023 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1025 let _, _, vy
, (_, _, h
, _) = b.(n) in
1028 let n'
= n - coverA
in
1031 let e = min
state.pagecount
(s + c) in
1032 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1033 let _, _, y, (_, _, h
, _) = b.(m
) in
1034 let miny = min
miny y in
1035 let maxh = max
maxh h
in
1036 find (m
+1) miny maxh
1041 match conf.columns
with
1042 | Cmulti
((_, _, _) as cl
, b) ->
1043 if Array.length
b > 0
1045 let y, h
= rowyh cl
b (Array.length
b - 1) in
1046 y + h
+ (if conf.presentation
then calcips h
else 0)
1049 if Array.length
b > 0
1051 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1052 y + h
+ (if conf.presentation
then calcips h
else 0)
1055 if Array.length
b > 0
1057 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1062 let getpageyh pageno
=
1063 let pageno = bound pageno 0 (state.pagecount
-1) in
1064 match conf.columns
with
1066 if Array.length
b = 0
1069 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1071 if conf.presentation
1077 if Array.length
b = 0
1080 let y, h
= rowyh cl
b pageno in
1082 if conf.presentation
1088 if Array.length
b = 0
1092 let (_, _, y, (_, _, h
, _)) = b.(n) in
1096 let getpagedim pageno =
1099 | (n, _, _, _) as pdim
:: rest
->
1101 then (if n = pageno then pdim
else ppdim
)
1106 f (-1, -1, -1, -1) state.pdims
1109 let getpagey pageno = fst
(getpageyh pageno);;
1111 let nogeomcmds cmds
=
1113 | s, [] -> String.length
s = 0
1118 let ((c, coverA
, coverB
) as cl
), b =
1119 match conf.columns
with
1120 | Csingle
b -> (1, 0, 0), b
1121 | Cmulti
(c, b) -> c, b
1122 | Csplit
(_, b) -> (1, 0, 0), b
1124 let rec bsearch nmin nmax
=
1126 then bound nmin
0 (state.pagecount
-1)
1128 let n = (nmax
+ nmin
) / 2 in
1129 let vy, h
= rowyh cl
b n in
1131 if conf.presentation
1133 let ips = calcips h
in
1134 let y0 = vy - ips in
1135 let y1 = vy + h
+ ips in
1139 then 0, vy + h
+ conf.interpagespace
1141 let y0 = vy - conf.interpagespace
in
1142 y0, y0 + h
+ conf.interpagespace
1145 if y >= y0 && y < y1
1152 if n < state.pagecount
- coverB
1153 then ((n-coverA
)/c)*c + coverA
1160 then bsearch (n+1) nmax
1161 else bsearch nmin
(n-1)
1164 let r = bsearch 0 (state.pagecount
-1) in
1168 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1169 let sh = sh - state.hscrollh
in
1170 let rec fold accu
n =
1171 if n = Array.length
b
1174 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1177 || n = state.pagecount
- coverB
1178 || (n - coverA
) mod columns
= columns
- 1)
1184 let pagey = max
0 (y - vy) in
1185 let pagedispy = if pagey > 0 then 0 else vy - y in
1186 let pagedispx, pagex
=
1188 if n = coverA
- 1 || n = state.pagecount
- coverB
1189 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1190 else dx + xoff
+ state.x
1197 let vw = conf.winw
- state.scrollw
- pagedispx in
1198 let pw = w
- pagex
in
1201 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1202 if pagevw > 0 && pagevh > 0
1206 ; pagedimno
= pdimno
1213 ; pagedispx = pagedispx
1214 ; pagedispy = pagedispy
1226 List.rev
(fold [] (page_of_y y));
1229 let layoutS (columns
, b) y sh =
1230 let sh = sh - state.hscrollh
in
1231 let rec fold accu n =
1232 if n = Array.length
b
1235 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1242 let x = xoff
+ state.x in
1243 let pagey = max
0 (y - vy) in
1244 let pagedispy = if pagey > 0 then 0 else vy - y in
1245 let pagedispx, pagex
=
1259 let pagecolw = pagew
/columns
in
1261 if pagecolw < conf.winw
1262 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1266 let vw = conf.winw
- pagedispx - state.scrollw
in
1267 let pw = pagew
- pagex
in
1270 let pagevw = min
pagevw pagecolw in
1271 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1272 if pagevw > 0 && pagevh > 0
1275 { pageno = n/columns
1276 ; pagedimno
= pdimno
1283 ; pagedispx = pagedispx
1284 ; pagedispy = pagedispy
1285 ; pagecol
= n mod columns
1296 List.rev
(fold [] 0)
1300 if nogeomcmds state.geomcmds
1302 match conf.columns
with
1303 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1304 | Cmulti
c -> layoutN c y sh
1305 | Csplit
s -> layoutS s y sh
1310 let y = state.y + incr
in
1312 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1317 let tilex = l
.pagex
mod conf.tilew
in
1318 let tiley = l
.pagey mod conf.tileh
in
1320 let col = l
.pagex
/ conf.tilew
in
1321 let row = l
.pagey / conf.tileh
in
1323 let rec rowloop row y0 dispy h
=
1327 let dh = conf.tileh
- y0 in
1328 let dh = min h
dh in
1329 let rec colloop col x0 dispx w
=
1333 let dw = conf.tilew
- x0 in
1334 let dw = min w
dw in
1336 f col row dispx dispy
x0 y0 dw dh;
1337 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1340 colloop col tilex l
.pagedispx l
.pagevw;
1341 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1344 if l
.pagevw > 0 && l
.pagevh > 0
1345 then rowloop row tiley l
.pagedispy l
.pagevh;
1348 let gettileopaque l
col row =
1350 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1352 try Some
(Hashtbl.find state.tilemap
key)
1353 with Not_found
-> None
1356 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1357 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1358 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1361 let drawtiles l color
=
1363 let f col row x y tilex tiley w h
=
1364 match gettileopaque l
col row with
1365 | Some
(opaque
, _, t
) ->
1366 let params = x, y, w
, h
, tilex, tiley in
1370 GlFunc.blend_func `zero `one_minus_src_color
;
1372 drawtile
params opaque
;
1374 then Gl.disable `blend
;
1377 let s = Printf.sprintf
1381 let w = measurestr
fstate.fontsize
s in
1382 GlMisc.push_attrib
[`current
];
1383 GlDraw.color
(0.0, 0.0, 0.0);
1385 (float (x-2), float (y-2))
1386 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1387 GlDraw.color
(1.0, 1.0, 1.0);
1388 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1389 GlMisc.pop_attrib
();
1394 let lw = conf.winw
- state.scrollw
- x in
1397 let lh = conf.winh
- y in
1400 begin match state.texid
with
1402 Gl.enable `texture_2d
;
1403 GlTex.bind_texture `texture_2d id
;
1406 and x1 = float (x+w)
1407 and y1 = float (y+h
) in
1409 let tw = float w /. 16.0
1410 and th
= float h
/. 16.0 in
1411 let tx0 = float tilex /. 16.0
1412 and ty0
= float tiley /. 16.0 in
1414 and ty1
= ty0
+. th
in
1415 GlDraw.begins `quads
;
1416 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1417 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1418 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1419 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1422 Gl.disable `texture_2d
;
1424 GlDraw.color
(1.0, 1.0, 1.0);
1427 (float (x+w), float (y+h
));
1429 if w > 128 && h
> fstate.fontsize
+ 10
1431 GlDraw.color
(0.0, 0.0, 0.0);
1434 then (col*conf.tilew
, row*conf.tileh
)
1437 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1444 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1446 let tilevisible1 l
x y =
1448 and ax1
= l
.pagex
+ l
.pagevw
1450 and ay1
= l
.pagey + l
.pagevh in
1454 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1455 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1457 let rx0 = max
ax0 bx0
1458 and ry0
= max ay0 by0
1459 and rx1
= min ax1
bx1
1460 and ry1
= min ay1 by1
in
1462 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1463 nonemptyintersection
1466 let tilevisible layout n x y =
1467 let rec findpageinlayout m
= function
1468 | l
:: rest
when l
.pageno = n ->
1469 tilevisible1 l
x y || (
1470 match conf.columns
with
1471 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1474 | _ :: rest
-> findpageinlayout 0 rest
1477 findpageinlayout 0 layout;
1480 let tileready l
x y =
1481 tilevisible1 l
x y &&
1482 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1485 let tilepage n p
layout =
1486 let rec loop = function
1490 let f col row _ _ _ _ _ _ =
1491 if state.currently
= Idle
1493 match gettileopaque l
col row with
1496 let x = col*conf.tilew
1497 and y = row*conf.tileh
in
1499 let w = l
.pagew
- x in
1503 let h = l
.pageh
- y in
1506 wcmd "tile %s %d %d %d %d" p
x y w h;
1509 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1510 conf.tilew
, conf.tileh
1519 if nogeomcmds state.geomcmds
1523 let preloadlayout y =
1524 let y = if y < conf.winh
then 0 else y - conf.winh
in
1525 let h = conf.winh
*3 in
1530 let rec loop pages
=
1531 if state.currently
!= Idle
1536 begin match getopaque l
.pageno with
1538 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1539 state.currently
<- Loading
(l
, state.gen
);
1541 tilepage l
.pageno opaque pages
;
1546 if nogeomcmds state.geomcmds
1552 if conf.preload && state.currently
= Idle
1553 then load (preloadlayout state.y);
1556 let layoutready layout =
1557 let rec fold all ls
=
1558 all
&& match ls
with
1560 let seen = ref false in
1561 let allvisible = ref true in
1562 let foo col row _ _ _ _ _ _ =
1564 allvisible := !allvisible &&
1565 begin match gettileopaque l
col row with
1571 fold (!seen && !allvisible) rest
1574 let alltilesvisible = fold true layout in
1579 let y = bound y 0 state.maxy
in
1580 let y, layout, proceed
=
1581 match conf.maxwait
with
1582 | Some time
when state.ghyll
== noghyll ->
1583 begin match state.throttle
with
1585 let layout = layout y conf.winh
in
1586 let ready = layoutready layout in
1590 state.throttle
<- Some
(layout, y, now ());
1592 else G.postRedisplay "gotoy showall (None)";
1594 | Some
(_, _, started
) ->
1595 let dt = now () -. started
in
1598 state.throttle
<- None
;
1599 let layout = layout y conf.winh
in
1601 G.postRedisplay "maxwait";
1608 let layout = layout y conf.winh
in
1609 if true || layoutready layout
1610 then G.postRedisplay "gotoy ready";
1616 state.layout <- layout;
1617 begin match state.mode
with
1618 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1619 let rec loop = function
1621 state.mode
<- LinkNav
(Ltgendir
0)
1622 | l
:: _ when l
.pageno = pageno ->
1623 begin match getopaque pageno with
1625 state.mode
<- LinkNav
(Ltgendir
0)
1627 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1628 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1629 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1630 then state.mode
<- LinkNav
(Ltgendir
0)
1632 | _ :: rest
-> loop rest
1637 begin match state.mode
with
1638 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1639 if not
(pagevisible layout pageno)
1641 match state.layout with
1644 state.mode
<- Birdseye
(
1645 conf, leftx
, l
.pageno, hooverpageno
, anchor
1648 | LinkNav
(Ltgendir dir
as lt
) ->
1650 let rec loop = function
1653 match getopaque l
.pageno with
1659 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1661 if dir
> 0 then LDfirst
else LDlast
1667 | Lnotfound
-> loop rest
1669 showlinktype (getlink opaque
n);
1670 Ltexact
(l
.pageno, n)
1674 state.mode
<- LinkNav
linknav
1679 state.ghyll
<- noghyll;
1682 let mx, my
= state.mpos
in
1687 let conttiling pageno opaque
=
1688 tilepage pageno opaque
1689 (if conf.preload then preloadlayout state.y else state.layout)
1692 let gotoy_and_clear_text y =
1693 if not
conf.verbose
then state.text <- "";
1699 let coloff = l
.pagecol
* l
.pageh
in
1700 float (l
.pagey + coloff) /. float l
.pageh
1707 if conf.presentation
1708 then float l
.pagedispy /. float (calcips l
.pageh
)
1709 else float l
.pagedispy /. float conf.interpagespace
1711 (l
.pageno, top, dtop)
1715 match state.layout with
1716 | l
:: _ -> getanchor1 l
1718 let n = page_of_y state.y in
1719 let y, h = getpageyh n in
1720 let dy = y - state.y in
1722 if conf.presentation
1724 let ips = calcips h in
1725 float (dy + ips) /. float ips
1727 float dy /. float conf.interpagespace
1732 let getanchory (n, top, dtop) =
1733 let y, h = getpageyh n in
1734 if conf.presentation
1736 let ips = calcips h in
1737 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1739 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1742 let gotoanchor anchor
=
1743 gotoy (getanchory anchor
);
1747 cbput state.hists
.nav
(getanchor ());
1751 let anchor = cbgetc state.hists
.nav dir
in
1756 let scroll f n a
b =
1757 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1759 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1761 then s (float f /. float a
)
1764 then 1.0 -. s ((float (f-b) /. float (n-b)))
1771 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1772 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1774 let ins = float a
*. iv1
1775 and outs
= float (n-b) *. iv1 in
1777 ins +. outs
+. float ones
1779 let rec set (_N
, _A
, _B
) y sy
=
1780 let sum = summa
1.0 _N _A _B
in
1781 let dy = float (y - sy
) in
1785 then state.ghyll
<- noghyll
1788 let s = scroll n _N _A _B
in
1789 let y1 = y1 +. ((s *. dy) /. sum) in
1790 gotoy_and_clear_text (truncate
y1);
1791 state.ghyll
<- gf (n+1) y1;
1795 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1797 gf 0 (float state.y)
1800 match conf.ghyllscroll
with
1802 gotoy_and_clear_text y
1804 if state.ghyll
== noghyll
1805 then set nab
y state.y
1806 else state.ghyll
(Some
y)
1809 let gotopage n top =
1810 let y, h = getpageyh n in
1811 let y = y + (truncate
(top *. float h)) in
1815 let gotopage1 n top =
1816 let y = getpagey n in
1821 let invalidate s f =
1826 match state.geomcmds
with
1827 | ps
, [] when String.length ps
= 0 ->
1829 state.geomcmds
<- s, [];
1832 state.geomcmds
<- ps
, [s, f];
1834 | ps
, (s'
, _) :: rest
when s'
= s ->
1835 state.geomcmds
<- ps
, ((s, f) :: rest
);
1838 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1841 let opendoc path password
=
1843 state.password
<- password
;
1844 state.gen
<- state.gen
+ 1;
1845 state.docinfo
<- [];
1847 setaalevel
conf.aalevel
;
1848 Wsi.settitle
("llpp " ^
Filename.basename path
);
1849 wcmd "open %s\000%s\000" path password
;
1850 invalidate "reqlayout"
1852 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1856 let c = c *. conf.colorscale
in
1860 let scalecolor2 (r, g
, b) =
1861 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1864 let docolumns = function
1866 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1867 let rec loop pageno pdimno pdim
y ph pdims
=
1868 if pageno = state.pagecount
1871 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1873 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1874 pdimno+1, pdim
, rest
1878 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1880 (if conf.presentation
1881 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1882 else (if pageno = 0 then 0 else conf.interpagespace
)
1885 a.(pageno) <- (pdimno, x, y, pdim
);
1886 loop (pageno+1) pdimno pdim
(y + h) h pdims
1888 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1889 conf.columns
<- Csingle
a;
1891 | Cmulti
((columns
, coverA
, coverB
), _) ->
1892 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1893 let rec loop pageno pdimno pdim
x y rowh pdims
=
1894 let rec fixrow m
= if m
= pageno then () else
1895 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1898 let y = y + (rowh
- h) / 2 in
1899 a.(m
) <- (pdimno, x, y, pdim
);
1903 if pageno = state.pagecount
1904 then fixrow (((pageno - 1) / columns
) * columns
)
1906 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1908 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1909 pdimno+1, pdim
, rest
1914 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1916 let x = (conf.winw
- state.scrollw
- w) / 2 in
1918 if conf.presentation
then calcips h else conf.interpagespace
in
1919 x, y + ips + rowh
, h
1922 if (pageno - coverA
) mod columns
= 0
1924 let x = max
0 (conf.winw
- state.scrollw
- state.w) / 2 in
1926 if conf.presentation
1928 let ips = calcips h in
1929 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
1931 y + (if pageno = 0 then 0 else conf.interpagespace
)
1935 else x, y, max rowh
h
1939 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1942 if pageno = columns
&& conf.presentation
1944 let ips = calcips rowh
in
1945 for i
= 0 to pred columns
1947 let (pdimno, x, y, pdim
) = a.(i
) in
1948 a.(i
) <- (pdimno, x, y+ips, pdim
)
1954 fixrow (pageno - columns
);
1959 a.(pageno) <- (pdimno, x, y, pdim
);
1960 let x = x + w + xoff
*2 + conf.interpagespace
in
1961 loop (pageno+1) pdimno pdim
x y rowh' pdims
1963 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1964 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1967 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1968 let rec loop pageno pdimno pdim
y pdims
=
1969 if pageno = state.pagecount
1972 let pdimno, ((_, w, h, _) as pdim
), pdims
=
1974 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1975 pdimno+1, pdim
, rest
1980 let rec loop1 n x y =
1981 if n = c then y else (
1982 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
1983 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
1986 let y = loop1 0 0 y in
1987 loop (pageno+1) pdimno pdim
y pdims
1989 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1990 conf.columns
<- Csplit
(c, a);
1994 docolumns conf.columns
;
1995 state.maxy
<- calcheight ();
1997 if state.w <= conf.winw
- state.scrollw
2001 match state.mode
with
2002 | Birdseye
(_, _, pageno, _, _) ->
2003 let y, h = getpageyh pageno in
2004 let top = (conf.winh
- h) / 2 in
2005 gotoy (max
0 (y - top))
2006 | _ -> gotoanchor state.anchor
2010 GlDraw.viewport
0 0 w h;
2011 let firsttime = state.geomcmds
== firstgeomcmds in
2012 if not
firsttime && nogeomcmds state.geomcmds
2013 then state.anchor <- getanchor ();
2016 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2019 setfontsize fstate.fontsize
;
2020 GlMat.mode `modelview
;
2021 GlMat.load_identity
();
2023 GlMat.mode `projection
;
2024 GlMat.load_identity
();
2025 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2026 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2027 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2032 else float state.x /. float state.w
2034 invalidate "geometry"
2038 then state.x <- truncate
(relx *. float w);
2040 match conf.columns
with
2042 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2043 | Csplit
(c, _) -> w * c
2045 wcmd "geometry %d %d" w h);
2049 let len = String.length
state.text in
2052 match state.mode
with
2055 let h, _, _ = state.uioh#scrollpw
in
2061 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2062 (x+.w, float (conf.winh
- hscrollh))
2065 let w = float (conf.winw
- state.scrollw
- 1) in
2066 if state.progress
>= 0.0 && state.progress
< 1.0
2068 GlDraw.color
(0.3, 0.3, 0.3);
2069 let w1 = w *. state.progress
in
2071 GlDraw.color
(0.0, 0.0, 0.0);
2075 GlDraw.color
(0.0, 0.0, 0.0);
2079 GlDraw.color
(1.0, 1.0, 1.0);
2080 drawstring fstate.fontsize
2081 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2084 match state.mode
with
2085 | Textentry
((prefix
, text, _, _, _, _), _) ->
2089 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2091 Printf.sprintf
"%s%s_" prefix
text
2100 if not
(istextentry state.mode
)
2102 let s1 = "(press 'e' to review error messasges)" in
2103 if String.length
s > 0 then s ^
" " ^
s1 else s1
2108 if String.length
s > 0
2113 let len = Queue.length
state.tilelru
in
2115 match state.throttle
with
2118 then preloadlayout state.y
2120 | Some
(layout, _, _) ->
2124 if state.memused
<= conf.memlimit
2129 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2130 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2131 let (_, pw, ph
, _) = getpagedim n in
2134 && colorspace
= conf.colorspace
2135 && angle
= conf.angle
2139 let x = col*conf.tilew
2140 and y = row*conf.tileh
in
2141 tilevisible (Lazy.force_val
layout) n x y
2143 then Queue.push lruitem
state.tilelru
2145 wcmd "freetile %s" p
;
2146 state.memused
<- state.memused
- s;
2147 state.uioh#infochanged Memused
;
2148 Hashtbl.remove
state.tilemap k
;
2157 Queue.iter
(fun (k
, p
, s) ->
2158 wcmd "freetile %s" p
;
2159 state.memused
<- state.memused
- s;
2160 state.uioh#infochanged Memused
;
2161 Hashtbl.remove
state.tilemap k
;
2163 Queue.clear
state.tilelru
;
2167 let logcurrently = function
2168 | Idle
-> dolog "Idle"
2169 | Loading
(l
, gen
) ->
2170 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2171 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2173 "Tiling %d[%d,%d] page=%s cs=%s angle"
2174 l
.pageno col row pageopaque
2175 (colorspace_to_string colorspace
)
2177 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2178 angle gen
conf.angle
state.gen
2180 conf.tilew
conf.tileh
2187 (* dolog "%S" cmds; *)
2190 try String.index cmds ' '
2191 with Not_found
-> -1
2196 let l = String.length cmds
in
2197 let op = String.sub cmds
0 spacepos in
2199 if l - spacepos < 2 then ""
2200 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2205 state.uioh#infochanged Pdim
;
2209 state.rects
<- state.rects1
;
2210 G.postRedisplay "clearrects";
2214 try Scanf.sscanf
args "%u" (fun n -> n)
2216 dolog "error processing 'continue' %S: %s"
2217 cmds
(Printexc.to_string exn
);
2220 state.pagecount
<- n;
2221 begin match state.currently
with
2223 state.currently
<- Idle
;
2224 state.outlines
<- Array.of_list
(List.rev
l)
2228 let cur, cmds
= state.geomcmds
in
2229 if String.length
cur = 0
2230 then failwith
"umpossible";
2232 begin match List.rev cmds
with
2234 state.geomcmds
<- "", [];
2238 state.geomcmds
<- s, List.rev rest
;
2240 if conf.maxwait
= None
2241 then G.postRedisplay "continue";
2251 then showtext ' '
args
2254 let progress, text =
2256 Scanf.sscanf
args "%f %n"
2258 f, String.sub
args pos
(String.length
args - pos
))
2260 dolog "error processing 'progress' %S: %s"
2261 cmds
(Printexc.to_string exn
);
2265 state.progress <- progress;
2266 G.postRedisplay "progress"
2269 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2271 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2272 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2273 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2275 dolog "error processing 'firstmatch' %S: %s"
2276 cmds
(Printexc.to_string exn
);
2279 let y = (getpagey pageno) + truncate
y0 in
2282 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2285 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2287 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2288 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2289 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2291 dolog "error processing 'match' %S: %s"
2292 cmds
(Printexc.to_string exn
);
2296 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2301 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2303 dolog "error processing 'page' %S: %s"
2304 cmds
(Printexc.to_string exn
);
2307 begin match state.currently
with
2308 | Loading
(l, gen
) ->
2309 vlog "page %d took %f sec" l.pageno t
;
2310 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2311 begin match state.throttle
with
2313 let preloadedpages =
2315 then preloadlayout state.y
2320 Set.Make
(struct type t
= int let compare = (-) end) in
2322 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2323 IntSet.empty
preloadedpages
2326 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2327 if not
(IntSet.mem
pageno set)
2329 wcmd "freepage %s" opaque
;
2335 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2338 state.currently
<- Idle
;
2341 tilepage l.pageno pageopaque state.layout;
2343 load preloadedpages;
2344 if pagevisible state.layout l.pageno
2345 && layoutready state.layout
2346 then G.postRedisplay "page";
2349 | Some
(layout, _, _) ->
2350 state.currently
<- Idle
;
2351 tilepage l.pageno pageopaque layout;
2356 dolog "Inconsistent loading state";
2357 logcurrently state.currently
;
2362 let (x, y, opaque
, size
, t
) =
2364 Scanf.sscanf
args "%u %u %s %u %f"
2365 (fun x y p size t
-> (x, y, p
, size
, t
))
2367 dolog "error processing 'tile' %S: %s"
2368 cmds
(Printexc.to_string exn
);
2371 begin match state.currently
with
2372 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2373 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2375 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2377 wcmd "freetile %s" opaque
;
2378 state.currently
<- Idle
;
2382 puttileopaque l col row gen cs angle opaque size t
;
2383 state.memused
<- state.memused
+ size
;
2384 state.uioh#infochanged Memused
;
2386 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2387 opaque
, size
) state.tilelru
;
2390 match state.throttle
with
2391 | None
-> state.layout
2392 | Some
(layout, _, _) -> layout
2395 state.currently
<- Idle
;
2397 && conf.colorspace
= cs
2398 && conf.angle
= angle
2399 && tilevisible layout l.pageno x y
2400 then conttiling l.pageno pageopaque;
2402 begin match state.throttle
with
2404 preload state.layout;
2406 && conf.colorspace
= cs
2407 && conf.angle
= angle
2408 && tilevisible state.layout l.pageno x y
2409 then G.postRedisplay "tile nothrottle";
2411 | Some
(layout, y, _) ->
2412 let ready = layoutready layout in
2416 state.layout <- layout;
2417 state.throttle
<- None
;
2418 G.postRedisplay "throttle";
2425 dolog "Inconsistent tiling state";
2426 logcurrently state.currently
;
2433 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2435 dolog "error processing 'pdim' %S: %s"
2436 cmds
(Printexc.to_string exn
);
2439 state.uioh#infochanged Pdim
;
2440 state.pdims
<- pdim :: state.pdims
2443 let (l, n, t
, h, pos
) =
2445 Scanf.sscanf
args "%u %u %d %u %n"
2446 (fun l n t
h pos
-> l, n, t
, h, pos
)
2448 dolog "error processing 'o' %S: %s"
2449 cmds
(Printexc.to_string exn
);
2452 let s = String.sub
args pos
(String.length
args - pos
) in
2453 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2454 begin match state.currently
with
2455 | Outlining outlines
->
2456 state.currently
<- Outlining
(outline :: outlines
)
2458 state.currently
<- Outlining
[outline]
2460 dolog "invalid outlining state";
2461 logcurrently currently
2465 state.docinfo
<- (1, args) :: state.docinfo
2468 state.uioh#infochanged Docinfo
;
2469 state.docinfo
<- List.rev
state.docinfo
2472 dolog "unknown cmd `%S'" cmds
2477 let action = function
2478 | HCprev
-> cbget cb ~
-1
2479 | HCnext
-> cbget cb
1
2480 | HCfirst
-> cbget cb ~
-(cb
.rc)
2481 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2482 and cancel
() = cb
.rc <- rc
2486 let search pattern forward
=
2487 if String.length pattern
> 0
2490 match state.layout with
2493 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2495 wcmd "search %d %d %d %d,%s\000"
2496 (btod conf.icase
) pn py
(btod forward
) pattern
;
2499 let intentry text key =
2501 if key >= 32 && key < 127
2507 let text = addchar text c in
2511 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2515 let linknentry text key =
2517 if key >= 32 && key < 127
2523 let text = addchar text c in
2527 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2532 if String.length
s > 0
2535 let l = String.length
s in
2536 let rec loop pos
n = if pos
= l then n else
2537 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2538 loop (pos
+1) (n*26 + m)
2541 let rec loop n = function
2544 match getopaque l.pageno with
2545 | None
-> loop n rest
2547 let m = getlinkcount opaque
in
2550 let under = getlink opaque
n in
2553 else loop (n-m) rest
2555 loop n state.layout;
2559 let textentry text key =
2560 if key land 0xff00 = 0xff00
2562 else TEcont
(text ^
Wsi.toutf8
key)
2565 let reqlayout angle proportional
=
2566 match state.throttle
with
2568 if nogeomcmds state.geomcmds
2569 then state.anchor <- getanchor ();
2570 conf.angle
<- angle
mod 360;
2573 match state.mode
with
2574 | LinkNav
_ -> state.mode
<- View
2577 conf.proportional
<- proportional
;
2578 invalidate "reqlayout"
2579 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2583 let settrim trimmargins trimfuzz
=
2584 if nogeomcmds state.geomcmds
2585 then state.anchor <- getanchor ();
2586 conf.trimmargins
<- trimmargins
;
2587 conf.trimfuzz
<- trimfuzz
;
2588 let x0, y0, x1, y1 = trimfuzz
in
2589 invalidate "settrim"
2591 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2592 Hashtbl.iter
(fun _ opaque
->
2593 wcmd "freepage %s" opaque
;
2595 Hashtbl.clear
state.pagemap
;
2599 match state.throttle
with
2601 let zoom = max
0.01 zoom in
2602 if zoom <> conf.zoom
2604 state.prevzoom
<- conf.zoom;
2606 reshape conf.winw
conf.winh
;
2607 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2610 | Some
(layout, y, started
) ->
2612 match conf.maxwait
with
2616 let dt = now () -. started
in
2624 let setcolumns mode columns coverA coverB
=
2625 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2629 then showtext '
!'
"split mode doesn't work in bird's eye"
2631 conf.columns
<- Csplit
(-columns
, [||]);
2639 conf.columns
<- Csingle
[||];
2644 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2648 reshape conf.winw
conf.winh
;
2651 let enterbirdseye () =
2652 let zoom = float conf.thumbw
/. float conf.winw
in
2653 let birdseyepageno =
2654 let cy = conf.winh
/ 2 in
2658 let rec fold best
= function
2661 let d = cy - (l.pagedispy + l.pagevh/2)
2662 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2663 if abs
d < abs dbest
2670 state.mode
<- Birdseye
(
2671 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2674 conf.presentation
<- false;
2675 conf.interpagespace
<- 10;
2676 conf.hlinks
<- false;
2678 state.mstate
<- Mnone
;
2679 conf.maxwait
<- None
;
2681 match conf.beyecolumns
with
2684 Cmulti
((c, 0, 0), [||])
2685 | None
-> Csingle
[||]
2687 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2690 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2695 reshape conf.winw
conf.winh
;
2698 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2700 conf.zoom <- c.zoom;
2701 conf.presentation
<- c.presentation
;
2702 conf.interpagespace
<- c.interpagespace
;
2703 conf.maxwait
<- c.maxwait
;
2704 conf.hlinks
<- c.hlinks
;
2705 conf.beyecolumns
<- (
2706 match conf.columns
with
2707 | Cmulti
((c, _, _), _) -> Some
c
2709 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2712 match c.columns
with
2713 | Cmulti
(c, _) -> Cmulti
(c, [||])
2714 | Csingle
_ -> Csingle
[||]
2715 | Csplit
(c, _) -> Csplit
(c, [||])
2720 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2723 reshape conf.winw
conf.winh
;
2724 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2727 let togglebirdseye () =
2728 match state.mode
with
2729 | Birdseye vals
-> leavebirdseye vals
true
2730 | View
-> enterbirdseye ()
2734 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2735 let pageno = max
0 (pageno - incr
) in
2736 let rec loop = function
2737 | [] -> gotopage1 pageno 0
2738 | l :: _ when l.pageno = pageno ->
2739 if l.pagedispy >= 0 && l.pagey = 0
2740 then G.postRedisplay "upbirdseye"
2741 else gotopage1 pageno 0
2742 | _ :: rest
-> loop rest
2745 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2748 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2749 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2750 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2751 let rec loop = function
2753 let y, h = getpageyh pageno in
2754 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2756 | l :: _ when l.pageno = pageno ->
2757 if l.pagevh != l.pageh
2758 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2759 else G.postRedisplay "downbirdseye"
2760 | _ :: rest
-> loop rest
2765 let optentry mode
_ key =
2766 let btos b = if b then "on" else "off" in
2767 if key >= 32 && key < 127
2769 let c = Char.chr
key in
2773 try conf.scrollstep
<- int_of_string
s with exc
->
2774 state.text <- Printf.sprintf
"bad integer `%s': %s"
2775 s (Printexc.to_string exc
)
2777 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2782 conf.autoscrollstep
<- int_of_string
s;
2783 if state.autoscroll
<> None
2784 then state.autoscroll
<- Some
conf.autoscrollstep
2786 state.text <- Printf.sprintf
"bad integer `%s': %s"
2787 s (Printexc.to_string exc
)
2789 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2794 let n, a, b = multicolumns_of_string s in
2795 setcolumns mode
n a b;
2797 state.text <- Printf.sprintf
"bad columns `%s': %s"
2798 s (Printexc.to_string exc
)
2800 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2805 let zoom = float (int_of_string
s) /. 100.0 in
2808 state.text <- Printf.sprintf
"bad integer `%s': %s"
2809 s (Printexc.to_string exc
)
2811 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2816 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2818 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2819 begin match mode
with
2821 leavebirdseye beye
false;
2826 state.text <- Printf.sprintf
"bad integer `%s': %s"
2827 s (Printexc.to_string exc
)
2829 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2834 Some
(int_of_string
s)
2836 state.text <- Printf.sprintf
"bad integer `%s': %s"
2837 s (Printexc.to_string exc
);
2840 | Some angle
-> reqlayout angle
conf.proportional
2843 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2846 conf.icase
<- not
conf.icase
;
2847 TEdone
("case insensitive search " ^
(btos conf.icase
))
2850 conf.preload <- not
conf.preload;
2852 TEdone
("preload " ^
(btos conf.preload))
2855 conf.verbose
<- not
conf.verbose
;
2856 TEdone
("verbose " ^
(btos conf.verbose
))
2859 conf.debug
<- not
conf.debug
;
2860 TEdone
("debug " ^
(btos conf.debug
))
2863 conf.maxhfit
<- not
conf.maxhfit
;
2864 state.maxy
<- calcheight ();
2865 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2868 conf.crophack
<- not
conf.crophack
;
2869 TEdone
("crophack " ^
btos conf.crophack
)
2873 match conf.maxwait
with
2875 conf.maxwait
<- Some infinity
;
2876 "always wait for page to complete"
2878 conf.maxwait
<- None
;
2879 "show placeholder if page is not ready"
2884 conf.underinfo
<- not
conf.underinfo
;
2885 TEdone
("underinfo " ^
btos conf.underinfo
)
2888 conf.savebmarks
<- not
conf.savebmarks
;
2889 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2895 match state.layout with
2900 conf.interpagespace
<- int_of_string
s;
2901 docolumns conf.columns
;
2902 state.maxy
<- calcheight ();
2903 let y = getpagey pageno in
2906 state.text <- Printf.sprintf
"bad integer `%s': %s"
2907 s (Printexc.to_string exc
)
2909 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2912 reqlayout conf.angle
(not
conf.proportional
);
2913 TEdone
("proportional display " ^
btos conf.proportional
)
2916 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2917 TEdone
("trim margins " ^
btos conf.trimmargins
)
2920 conf.invert
<- not
conf.invert
;
2921 TEdone
("invert colors " ^
btos conf.invert
)
2925 cbput state.hists
.sel
s;
2928 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2929 textentry, ondone, true)
2932 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2938 class type lvsource
= object
2939 method getitemcount
: int
2940 method getitem
: int -> (string * int)
2941 method hasaction
: int -> bool
2950 method getactive
: int
2951 method getfirst
: int
2952 method getqsearch
: string
2953 method setqsearch
: string -> unit
2957 class virtual lvsourcebase
= object
2958 val mutable m_active
= 0
2959 val mutable m_first
= 0
2960 val mutable m_qsearch
= ""
2961 val mutable m_pan
= 0
2962 method getactive
= m_active
2963 method getfirst
= m_first
2964 method getqsearch
= m_qsearch
2965 method getpan
= m_pan
2966 method setqsearch
s = m_qsearch
<- s
2969 let withoutlastutf8 s =
2970 let len = String.length
s in
2978 let b = Char.code
s.[pos
] in
2979 if b land 0b110000 = 0b11000000
2984 if Char.code
s.[len-1] land 0x80 = 0
2988 String.sub
s 0 first;
2991 let textentrykeyboard
2992 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2994 state.mode
<- Textentry
(te
, onleave
);
2997 G.postRedisplay "textentrykeyboard enttext";
2999 let histaction cmd
=
3002 | Some
(action, _) ->
3003 state.mode
<- Textentry
(
3004 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3006 G.postRedisplay "textentry histaction"
3009 | 0xff08 -> (* backspace *)
3010 let s = withoutlastutf8 text in
3011 let len = String.length
s in
3012 if cancelonempty
&& len = 0
3015 G.postRedisplay "textentrykeyboard after cancel";
3018 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3024 G.postRedisplay "textentrykeyboard after confirm"
3026 | 0xff52 -> histaction HCprev
3027 | 0xff54 -> histaction HCnext
3028 | 0xff50 -> histaction HCfirst
3029 | 0xff57 -> histaction HClast
3031 | 0xff1b -> (* escape*)
3032 if String.length
text = 0
3034 begin match opthist
with
3036 | Some
(_, onhistcancel
) -> onhistcancel
()
3040 G.postRedisplay "textentrykeyboard after cancel2"
3043 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3046 | 0xff9f | 0xffff -> () (* delete *)
3048 | _ when key != 0 && key land 0xff00 != 0xff00 ->
3049 begin match onkey
text key with
3053 G.postRedisplay "textentrykeyboard after confirm2";
3056 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3060 G.postRedisplay "textentrykeyboard after cancel3"
3063 state.mode
<- Textentry
(te
, onleave
);
3064 G.postRedisplay "textentrykeyboard switch";
3068 vlog "unhandled key %s" (Wsi.keyname
key)
3071 let firstof first active
=
3072 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3073 then max
0 (active
- (fstate.maxrows
/2))
3077 let calcfirst first active
=
3080 let rows = active
- first in
3081 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3085 let scrollph y maxy
=
3086 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3087 let sh = float conf.winh
/. sh in
3088 let sh = max
sh (float conf.scrollh
) in
3093 else float y /. float maxy
3095 let position = (float conf.winh
-. sh) *. percent in
3098 if position +. sh > float conf.winh
3099 then float conf.winh
-. sh
3105 let coe s = (s :> uioh
);;
3107 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3109 val m_pan
= source#getpan
3110 val m_first
= source#getfirst
3111 val m_active
= source#getactive
3112 val m_qsearch
= source#getqsearch
3113 val m_prev_uioh
= state.uioh
3115 method private elemunder
y =
3116 let n = y / (fstate.fontsize
+1) in
3117 if m_first
+ n < source#getitemcount
3119 if source#hasaction
(m_first
+ n)
3120 then Some
(m_first
+ n)
3127 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3128 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3129 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3130 GlDraw.color
(1., 1., 1.);
3131 Gl.enable `texture_2d
;
3132 let fs = fstate.fontsize
in
3134 let ww = fstate.wwidth
in
3135 let tabw = 30.0*.ww in
3136 let itemcount = source#getitemcount
in
3138 if (row - m_first
) > fstate.maxrows
3141 if row >= 0 && row < itemcount
3143 let (s, level
) = source#getitem
row in
3144 let y = (row - m_first
) * nfs in
3145 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3148 Gl.disable `texture_2d
;
3149 GlDraw.polygon_mode `both `line
;
3150 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3151 GlDraw.rect (1., float (y + 1))
3152 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3153 GlDraw.polygon_mode `both `fill
;
3154 GlDraw.color
(1., 1., 1.);
3155 Gl.enable `texture_2d
;
3158 let drawtabularstring s =
3159 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3162 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3165 let len = String.length
s - tabpos - 1 in
3166 let s1 = String.sub
s 0 tabpos
3167 and s2
= String.sub
s (tabpos + 1) len in
3168 let nx = drawstr x s1 in
3170 let x = x +. (max
tabw sw) in
3177 let _ = drawtabularstring s in
3184 Gl.disable `texture_2d
;
3186 method updownlevel incr
=
3187 let len = source#getitemcount
in
3189 if m_active
>= 0 && m_active
< len
3190 then snd
(source#getitem m_active
)
3194 if i
= len then i
-1 else if i
= -1 then 0 else
3195 let _, l = source#getitem i
in
3196 if l != curlevel then i
else flow (i
+incr
)
3198 let active = flow m_active
in
3199 let first = calcfirst m_first
active in
3200 G.postRedisplay "outline updownlevel";
3201 {< m_active
= active; m_first
= first >}
3203 method private key1
key mask
=
3204 let set1 active first qsearch
=
3205 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3207 let search active pattern incr
=
3210 if n >= 0 && n < source#getitemcount
3212 let s, _ = source#getitem
n in
3214 (try ignore
(Str.search_forward
re s 0); true
3215 with Not_found
-> false)
3217 else loop (n + incr
)
3224 let re = Str.regexp_case_fold pattern
in
3230 let itemcount = source#getitemcount
in
3231 let find start incr
=
3233 if i
= -1 || i
= itemcount
3236 if source#hasaction i
3238 else find (i
+ incr
)
3243 let set active first =
3244 let first = bound first 0 (itemcount - fstate.maxrows
) in
3246 coe {< m_active
= active; m_first
= first >}
3249 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3251 let incr1 = if incr
> 0 then 1 else -1 in
3252 if isvisible m_first m_active
3255 let next = m_active
+ incr
in
3257 if next < 0 || next >= itemcount
3259 else find next incr1
3261 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3267 let first = m_first
+ incr
in
3268 let first = bound first 0 (itemcount - 1) in
3270 let next = m_active
+ incr
in
3271 let next = bound next 0 (itemcount - 1) in
3274 let active = if next = -1 then m_active
else next in
3277 let first = min
next m_first
in
3279 if abs
(next - first) > fstate.maxrows
3285 let first = m_first
+ incr
in
3286 let first = bound first 0 (itemcount - 1) in
3288 let next = m_active
+ incr
in
3289 let next = bound next 0 (itemcount - 1) in
3290 let next = find next incr1 in
3292 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3294 let active = if m_active
= -1 then next else m_active
in
3299 if isvisible first active
3305 G.postRedisplay "listview navigate";
3309 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3310 let incr = if key = 0x72 then -1 else 1 in
3312 match search (m_active
+ incr) m_qsearch
incr with
3314 state.text <- m_qsearch ^
" [not found]";
3317 state.text <- m_qsearch
;
3318 active, firstof m_first
active
3320 G.postRedisplay "listview ctrl-r/s";
3321 set1 active first m_qsearch
;
3323 | 0xff08 -> (* backspace *)
3324 if String.length m_qsearch
= 0
3327 let qsearch = withoutlastutf8 m_qsearch
in
3328 let len = String.length
qsearch in
3332 G.postRedisplay "listview empty qsearch";
3333 set1 m_active m_first
"";
3337 match search m_active
qsearch ~
-1 with
3339 state.text <- qsearch ^
" [not found]";
3342 state.text <- qsearch;
3343 active, firstof m_first
active
3345 G.postRedisplay "listview backspace qsearch";
3346 set1 active first qsearch
3349 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3350 let pattern = m_qsearch ^
Wsi.toutf8
key in
3352 match search m_active
pattern 1 with
3354 state.text <- pattern ^
" [not found]";
3357 state.text <- pattern;
3358 active, firstof m_first
active
3360 G.postRedisplay "listview qsearch add";
3361 set1 active first pattern;
3363 | 0xff1b -> (* escape *)
3365 if String.length m_qsearch
= 0
3367 G.postRedisplay "list view escape";
3370 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3372 | None
-> m_prev_uioh
3377 G.postRedisplay "list view kill qsearch";
3378 source#setqsearch
"";
3379 coe {< m_qsearch
= "" >}
3382 | 0xff0d -> (* return *)
3384 let self = {< m_qsearch
= "" >} in
3385 source#setqsearch
"";
3387 G.postRedisplay "listview enter";
3388 if m_active
>= 0 && m_active
< source#getitemcount
3390 source#exit
(coe self) false m_active m_first m_pan
"";
3393 source#exit
(coe self) true m_active m_first m_pan
"";
3396 begin match opt with
3397 | None
-> m_prev_uioh
3401 | 0xff9f | 0xffff -> (* delete *)
3404 | 0xff52 -> navigate ~
-1 (* up *)
3405 | 0xff54 -> navigate 1 (* down *)
3406 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3407 | 0xff56 -> navigate fstate.maxrows
(* next *)
3409 | 0xff53 -> (* right *)
3411 G.postRedisplay "listview right";
3412 coe {< m_pan
= m_pan
- 1 >}
3414 | 0xff51 -> (* left *)
3416 G.postRedisplay "listview left";
3417 coe {< m_pan
= m_pan
+ 1 >}
3419 | 0xff50 -> (* home *)
3420 let active = find 0 1 in
3421 G.postRedisplay "listview home";
3424 | 0xff57 -> (* end *)
3425 let first = max
0 (itemcount - fstate.maxrows
) in
3426 let active = find (itemcount - 1) ~
-1 in
3427 G.postRedisplay "listview end";
3430 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3434 dolog "listview unknown key %#x" key; coe self
3436 method key key mask
=
3437 match state.mode
with
3438 | Textentry te
-> textentrykeyboard key mask te
; coe self
3439 | _ -> self#key1
key mask
3441 method button button down
x y _ =
3444 | 1 when x > conf.winw
- conf.scrollbw
->
3445 G.postRedisplay "listview scroll";
3448 let _, position, sh = self#
scrollph in
3449 if y > truncate
position && y < truncate
(position +. sh)
3451 state.mstate
<- Mscrolly
;
3455 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3456 let first = truncate
(s *. float source#getitemcount
) in
3457 let first = min source#getitemcount
first in
3458 Some
(coe {< m_first
= first; m_active
= first >})
3460 state.mstate
<- Mnone
;
3463 | 1 when not down
->
3464 begin match self#elemunder
y with
3466 G.postRedisplay "listview click";
3468 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3472 | n when (n == 4 || n == 5) && not down
->
3473 let len = source#getitemcount
in
3475 if n = 5 && m_first
+ fstate.maxrows
>= len
3479 let first = m_first
+ (if n == 4 then -1 else 1) in
3480 bound first 0 (len - 1)
3482 G.postRedisplay "listview wheel";
3483 Some
(coe {< m_first
= first >})
3484 | n when (n = 6 || n = 7) && not down
->
3485 let inc = m_first
+ (if n = 7 then -1 else 1) in
3486 G.postRedisplay "listview hwheel";
3487 Some
(coe {< m_pan
= m_pan
+ inc >})
3492 | None
-> m_prev_uioh
3496 match state.mstate
with
3498 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3499 let first = truncate
(s *. float source#getitemcount
) in
3500 let first = min source#getitemcount
first in
3501 G.postRedisplay "listview motion";
3502 coe {< m_first
= first; m_active
= first >}
3505 method pmotion
x y =
3506 if x < conf.winw
- conf.scrollbw
3509 match self#elemunder
y with
3510 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3511 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3515 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3520 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3524 method infochanged
_ = ()
3526 method scrollpw
= (0, 0.0, 0.0)
3528 let nfs = fstate.fontsize
+ 1 in
3529 let y = m_first
* nfs in
3530 let itemcount = source#getitemcount
in
3531 let maxi = max
0 (itemcount - fstate.maxrows
) in
3532 let maxy = maxi * nfs in
3533 let p, h = scrollph y maxy in
3536 method modehash
= modehash
3539 class outlinelistview ~source
=
3542 ~source
:(source
:> lvsource
)
3544 ~modehash
:(findkeyhash conf "outline")
3547 method key key mask
=
3548 let calcfirst first active =
3551 let rows = active - first in
3553 if String.length
state.text = 0
3555 else fstate.maxrows - 2
3557 if rows > maxrows then active - maxrows else first
3561 let active = m_active
+ incr in
3562 let active = bound active 0 (source#getitemcount
- 1) in
3563 let first = calcfirst m_first
active in
3564 G.postRedisplay "outline navigate";
3565 coe {< m_active
= active; m_first
= first >}
3567 let ctrl = Wsi.withctrl mask
in
3569 | 110 when ctrl -> (* ctrl-n *)
3570 source#narrow m_qsearch
;
3571 G.postRedisplay "outline ctrl-n";
3572 coe {< m_first
= 0; m_active
= 0 >}
3574 | 117 when ctrl -> (* ctrl-u *)
3576 G.postRedisplay "outline ctrl-u";
3578 coe {< m_first
= 0; m_active
= 0 >}
3580 | 108 when ctrl -> (* ctrl-l *)
3581 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3582 G.postRedisplay "outline ctrl-l";
3583 coe {< m_first
= first >}
3585 | 0xff9f | 0xffff -> (* delete *)
3586 source#remove m_active
;
3587 G.postRedisplay "outline delete";
3588 let active = max
0 (m_active
-1) in
3589 coe {< m_first
= firstof m_first
active;
3590 m_active
= active >}
3592 | 0xff52 -> navigate ~
-1 (* up *)
3593 | 0xff54 -> navigate 1 (* down *)
3594 | 0xff55 -> (* prior *)
3595 navigate ~
-(fstate.maxrows)
3596 | 0xff56 -> (* next *)
3597 navigate fstate.maxrows
3599 | 0xff53 -> (* [ctrl-]right *)
3603 G.postRedisplay "outline ctrl right";
3604 {< m_pan
= m_pan
+ 1 >}
3606 else self#updownlevel
1
3610 | 0xff51 -> (* [ctrl-]left *)
3614 G.postRedisplay "outline ctrl left";
3615 {< m_pan
= m_pan
- 1 >}
3617 else self#updownlevel ~
-1
3621 | 0xff50 -> (* home *)
3622 G.postRedisplay "outline home";
3623 coe {< m_first
= 0; m_active
= 0 >}
3625 | 0xff57 -> (* end *)
3626 let active = source#getitemcount
- 1 in
3627 let first = max
0 (active - fstate.maxrows) in
3628 G.postRedisplay "outline end";
3629 coe {< m_active
= active; m_first
= first >}
3631 | _ -> super#
key key mask
3634 let outlinesource usebookmarks
=
3637 inherit lvsourcebase
3638 val mutable m_items
= empty
3639 val mutable m_orig_items
= empty
3640 val mutable m_prev_items
= empty
3641 val mutable m_narrow_pattern
= ""
3642 val mutable m_hadremovals
= false
3644 method getitemcount
=
3645 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3648 if n == Array.length m_items
&& m_hadremovals
3650 ("[Confirm removal]", 0)
3652 let s, n, _ = m_items
.(n) in
3655 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3656 ignore
(uioh
, first, qsearch);
3657 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3659 if String.length m_narrow_pattern
= 0
3665 if not
confrimremoval
3667 let _, _, anchor = m_items
.(active) in
3668 gotoghyll (getanchory anchor);
3672 state.bookmarks
<- Array.to_list m_items
;
3673 m_orig_items
<- m_items
;
3676 else m_items
<- items;
3680 method hasaction
_ = true
3683 if Array.length m_items
!= Array.length m_orig_items
3684 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3687 method narrow
pattern =
3688 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3692 let rec loop accu n =
3695 m_narrow_pattern
<- pattern;
3696 m_items
<- Array.of_list
accu
3699 let (s, _, _) as o = m_items
.(n) in
3701 if (try ignore
(Str.search_forward
re s 0); true
3702 with Not_found
-> false)
3708 loop [] (Array.length m_items
- 1)
3713 then Array.of_list
state.bookmarks
3716 m_items
<- m_orig_items
3721 if m >= 0 && m < Array.length m_items
3723 m_hadremovals
<- true;
3724 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3725 let n = if n >= m then n+1 else n in
3730 method reset
anchor items =
3731 m_hadremovals
<- false;
3732 if m_orig_items
== empty || m_prev_items
!= items
3734 m_orig_items
<- items;
3735 if String.length m_narrow_pattern
= 0
3736 then m_items
<- items;
3738 m_prev_items
<- items;
3739 let rely = getanchory anchor in
3741 let rec loop n best bestd
=
3742 if n = Array.length m_items
3745 let (_, _, anchor) = m_items
.(n) in
3746 let orely = getanchory anchor in
3747 let d = abs
(orely - rely) in
3750 else loop (n+1) best bestd
3755 m_first
<- firstof m_first
active
3759 let enterselector usebookmarks
=
3760 let source = outlinesource usebookmarks
in
3764 then Array.of_list
state.bookmarks
3767 if Array.length
outlines = 0
3769 showtext ' ' errmsg
;
3772 state.text <- source#greetmsg
;
3773 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3774 let anchor = getanchor () in
3775 source#reset
anchor outlines;
3776 state.uioh
<- coe (new outlinelistview ~
source);
3777 G.postRedisplay "enter selector";
3781 let enteroutlinemode =
3782 let f = enterselector false in
3783 fun ()-> f "Document has no outline";
3786 let enterbookmarkmode =
3787 let f = enterselector true in
3788 fun () -> f "Document has no bookmarks (yet)";
3791 let color_of_string s =
3792 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3793 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3797 let color_to_string (r, g
, b) =
3798 let r = truncate
(r *. 256.0)
3799 and g
= truncate
(g
*. 256.0)
3800 and b = truncate
(b *. 256.0) in
3801 Printf.sprintf
"%d/%d/%d" r g
b
3804 let irect_of_string s =
3805 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3808 let irect_to_string (x0,y0,x1,y1) =
3809 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3812 let makecheckers () =
3813 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3815 converted by Issac Trotts. July 25, 2002 *)
3816 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3817 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3818 let id = GlTex.gen_texture
() in
3819 GlTex.bind_texture `texture_2d
id;
3820 GlPix.store
(`unpack_alignment
1);
3821 GlTex.image2d
image;
3822 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3825 `mag_filter `nearest
;
3826 `min_filter `nearest
];
3830 let setcheckers enabled
=
3831 match state.texid
with
3833 if enabled
then state.texid
<- Some
(makecheckers ())
3838 GlTex.delete_texture texid
;
3839 state.texid
<- None
;
3843 let int_of_string_with_suffix s =
3844 let l = String.length
s in
3848 let suffix = Char.lowercase
s.[l-1] in
3850 | 'k'
-> String.sub
s 0 (l-1), 10
3851 | '
m'
-> String.sub
s 0 (l-1), 20
3852 | 'g'
-> String.sub
s 0 (l-1), 30
3856 let n = int_of_string
s1 in
3857 let m = n lsl shift
in
3859 then raise
(Failure
"value too large")
3863 let string_with_suffix_of_int n =
3868 if n land ((1 lsl 20) - 1) = 0
3871 if n land ((1 lsl 10) - 1) = 0
3877 let h = n mod 1000 in
3880 then string_of_int
h ^
s
3882 let s = Printf.sprintf
"_%03d%s" h s in
3889 let defghyllscroll = (40, 8, 32);;
3890 let ghyllscroll_of_string s =
3891 let (n, a, b) as nab
=
3894 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3896 if n <= a || n <= b || a >= b
3897 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3901 let ghyllscroll_to_string ((n, a, b) as nab
) =
3902 if nab
= defghyllscroll
3904 else Printf.sprintf
"%d,%d,%d" n a b;
3907 let describe_location () =
3909 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3911 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3912 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3916 else (100. *. (float state.y /. float maxy))
3920 Printf.sprintf
"page %d of %d [%.2f%%]"
3921 (fn+1) state.pagecount
percent
3924 "pages %d-%d of %d [%.2f%%]"
3925 (fn+1) (ln
+1) state.pagecount
percent
3928 let setpresentationmode v
=
3929 let (n, _, _) = getanchor () in
3930 let _, h = getpageyh n in
3931 let ips = if conf.presentation
then calcips h else conf.interpagespace
in
3932 state.anchor <- (n, 0.0, float ips);
3933 conf.presentation
<- v
;
3934 if conf.presentation
3936 if not
conf.scrollbarinpm
3937 then state.scrollw
<- 0;
3939 else state.scrollw
<- conf.scrollbw
;
3944 let btos b = if b then "\xe2\x88\x9a" else "" in
3945 let showextended = ref false in
3946 let leave mode
= function
3947 | Confirm
-> state.mode
<- mode
3948 | Cancel
-> state.mode
<- mode
in
3951 val mutable m_first_time
= true
3952 val mutable m_l
= []
3953 val mutable m_a
= [||]
3954 val mutable m_prev_uioh
= nouioh
3955 val mutable m_prev_mode
= View
3957 inherit lvsourcebase
3959 method reset prev_mode prev_uioh
=
3960 m_a
<- Array.of_list
(List.rev m_l
);
3962 m_prev_mode
<- prev_mode
;
3963 m_prev_uioh
<- prev_uioh
;
3967 if n >= Array.length m_a
3971 | _, _, _, Action
_ -> m_active
<- n
3975 m_first_time
<- false;
3978 method int name get
set =
3980 (name
, `
int get
, 1, Action
(
3983 try set (int_of_string
s)
3985 state.text <- Printf.sprintf
"bad integer `%s': %s"
3986 s (Printexc.to_string exn
)
3989 let te = name ^
": ", "", None
, intentry, ondone, true in
3990 state.mode
<- Textentry
(te, leave m_prev_mode
);
3994 method int_with_suffix name get
set =
3996 (name
, `intws get
, 1, Action
(
3999 try set (int_of_string_with_suffix s)
4001 state.text <- Printf.sprintf
"bad integer `%s': %s"
4002 s (Printexc.to_string exn
)
4006 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4008 state.mode
<- Textentry
(te, leave m_prev_mode
);
4012 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4014 (name
, `
bool (btos, get
), offset
, Action
(
4021 method color name get
set =
4023 (name
, `color get
, 1, Action
(
4025 let invalid = (nan
, nan
, nan
) in
4028 try color_of_string s
4030 state.text <- Printf.sprintf
"bad color `%s': %s"
4031 s (Printexc.to_string exn
);
4037 let te = name ^
": ", "", None
, textentry, ondone, true in
4038 state.text <- color_to_string (get
());
4039 state.mode
<- Textentry
(te, leave m_prev_mode
);
4043 method string name get
set =
4045 (name
, `
string get
, 1, Action
(
4047 let ondone s = set s in
4048 let te = name ^
": ", "", None
, textentry, ondone, true in
4049 state.mode
<- Textentry
(te, leave m_prev_mode
);
4053 method colorspace name get
set =
4055 (name
, `
string get
, 1, Action
(
4058 let vals = [| "rgb"; "bgr"; "gray" |] in
4060 inherit lvsourcebase
4063 m_active
<- int_of_colorspace conf.colorspace
;
4066 method getitemcount
= Array.length
vals
4067 method getitem
n = (vals.(n), 0)
4068 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4069 ignore
(uioh
, first, pan
, qsearch);
4070 if not cancel
then set active;
4072 method hasaction
_ = true
4076 let modehash = findkeyhash conf "info" in
4077 coe (new listview ~
source ~trusted
:true ~
modehash)
4080 method caption
s offset
=
4081 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4083 method caption2
s f offset
=
4084 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4086 method getitemcount
= Array.length m_a
4089 let tostr = function
4090 | `
int f -> string_of_int
(f ())
4091 | `intws
f -> string_with_suffix_of_int (f ())
4093 | `color
f -> color_to_string (f ())
4094 | `
bool (btos, f) -> btos (f ())
4097 let name, t
, offset
, _ = m_a
.(n) in
4098 ((let s = tostr t
in
4099 if String.length
s > 0
4100 then Printf.sprintf
"%s\t%s" name s
4104 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4108 m_qsearch
<- qsearch;
4110 match m_a
.(active) with
4111 | _, _, _, Action
f -> f uioh
4123 method hasaction
n =
4125 | _, _, _, Action
_ -> true
4129 let rec fillsrc prevmode prevuioh
=
4130 let sep () = src#caption
"" 0 in
4131 let colorp name get
set =
4133 (fun () -> color_to_string (get
()))
4136 let c = color_of_string v in
4139 state.text <- Printf.sprintf
"bad color `%s': %s"
4140 v (Printexc.to_string exn
);
4143 let oldmode = state.mode
in
4144 let birdseye = isbirdseye state.mode
in
4146 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4148 src#
bool "presentation mode"
4149 (fun () -> conf.presentation
)
4150 (fun v -> setpresentationmode v);
4152 src#
bool "ignore case in searches"
4153 (fun () -> conf.icase
)
4154 (fun v -> conf.icase
<- v);
4157 (fun () -> conf.preload)
4158 (fun v -> conf.preload <- v);
4160 src#
bool "highlight links"
4161 (fun () -> conf.hlinks
)
4162 (fun v -> conf.hlinks
<- v);
4164 src#
bool "under info"
4165 (fun () -> conf.underinfo
)
4166 (fun v -> conf.underinfo
<- v);
4168 src#
bool "persistent bookmarks"
4169 (fun () -> conf.savebmarks
)
4170 (fun v -> conf.savebmarks
<- v);
4172 src#
bool "proportional display"
4173 (fun () -> conf.proportional
)
4174 (fun v -> reqlayout conf.angle
v);
4176 src#
bool "trim margins"
4177 (fun () -> conf.trimmargins
)
4178 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4180 src#
bool "persistent location"
4181 (fun () -> conf.jumpback
)
4182 (fun v -> conf.jumpback
<- v);
4185 src#
int "inter-page space"
4186 (fun () -> conf.interpagespace
)
4188 conf.interpagespace
<- n;
4189 docolumns conf.columns
;
4191 match state.layout with
4196 state.maxy <- calcheight ();
4197 let y = getpagey pageno in
4202 (fun () -> conf.pagebias
)
4203 (fun v -> conf.pagebias
<- v);
4205 src#
int "scroll step"
4206 (fun () -> conf.scrollstep
)
4207 (fun n -> conf.scrollstep
<- n);
4209 src#
int "horizontal scroll step"
4210 (fun () -> conf.hscrollstep
)
4211 (fun v -> conf.hscrollstep
<- v);
4213 src#
int "auto scroll step"
4215 match state.autoscroll
with
4217 | _ -> conf.autoscrollstep
)
4219 if state.autoscroll
<> None
4220 then state.autoscroll
<- Some
n;
4221 conf.autoscrollstep
<- n);
4224 (fun () -> truncate
(conf.zoom *. 100.))
4225 (fun v -> setzoom ((float v) /. 100.));
4228 (fun () -> conf.angle
)
4229 (fun v -> reqlayout v conf.proportional
);
4231 src#
int "scroll bar width"
4232 (fun () -> state.scrollw
)
4236 reshape conf.winw
conf.winh
;
4239 src#
int "scroll handle height"
4240 (fun () -> conf.scrollh
)
4241 (fun v -> conf.scrollh
<- v;);
4243 src#
int "thumbnail width"
4244 (fun () -> conf.thumbw
)
4246 conf.thumbw
<- min
4096 v;
4249 leavebirdseye beye
false;
4254 let mode = state.mode in
4255 src#
string "columns"
4257 match conf.columns
with
4259 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4260 | Csplit
(count
, _) -> "-" ^ string_of_int count
4263 let n, a, b = multicolumns_of_string v in
4264 setcolumns mode n a b);
4267 src#caption
"Presentation mode" 0;
4268 src#
bool "scrollbar visible"
4269 (fun () -> conf.scrollbarinpm
)
4271 if v != conf.scrollbarinpm
4273 conf.scrollbarinpm
<- v;
4274 if conf.presentation
4276 state.scrollw
<- if v then conf.scrollbw
else 0;
4277 reshape conf.winw
conf.winh
;
4283 src#caption
"Pixmap cache" 0;
4284 src#int_with_suffix
"size (advisory)"
4285 (fun () -> conf.memlimit
)
4286 (fun v -> conf.memlimit
<- v);
4289 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4290 (string_with_suffix_of_int state.memused
)
4291 (Hashtbl.length
state.tilemap
)) 1;
4294 src#caption
"Layout" 0;
4295 src#caption2
"Dimension"
4297 Printf.sprintf
"%dx%d (virtual %dx%d)"
4303 src#caption2
"Position" (fun () ->
4304 Printf.sprintf
"%dx%d" state.x state.y
4307 src#caption2
"Visible" (fun () -> describe_location ()) 1
4311 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4312 "Save these parameters as global defaults at exit"
4313 (fun () -> conf.bedefault
)
4314 (fun v -> conf.bedefault
<- v)
4318 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4319 src#
bool ~offset
:0 ~
btos "Extended parameters"
4320 (fun () -> !showextended)
4321 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4325 (fun () -> conf.checkers
)
4326 (fun v -> conf.checkers
<- v; setcheckers v);
4327 src#
bool "update cursor"
4328 (fun () -> conf.updatecurs
)
4329 (fun v -> conf.updatecurs
<- v);
4331 (fun () -> conf.verbose
)
4332 (fun v -> conf.verbose
<- v);
4333 src#
bool "invert colors"
4334 (fun () -> conf.invert
)
4335 (fun v -> conf.invert
<- v);
4337 (fun () -> conf.maxhfit
)
4338 (fun v -> conf.maxhfit
<- v);
4339 src#
bool "redirect stderr"
4340 (fun () -> conf.redirectstderr)
4341 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4342 src#
string "uri launcher"
4343 (fun () -> conf.urilauncher
)
4344 (fun v -> conf.urilauncher
<- v);
4345 src#
string "path launcher"
4346 (fun () -> conf.pathlauncher
)
4347 (fun v -> conf.pathlauncher
<- v);
4348 src#
string "tile size"
4349 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4352 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4353 conf.tilew
<- max
64 w;
4354 conf.tileh
<- max
64 h;
4357 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4358 v (Printexc.to_string exn
));
4359 src#
int "texture count"
4360 (fun () -> conf.texcount
)
4363 then conf.texcount
<- v
4364 else showtext '
!'
" Failed to set texture count please retry later"
4366 src#
int "slice height"
4367 (fun () -> conf.sliceheight
)
4369 conf.sliceheight
<- v;
4370 wcmd "sliceh %d" conf.sliceheight
;
4372 src#
int "anti-aliasing level"
4373 (fun () -> conf.aalevel
)
4375 conf.aalevel
<- bound v 0 8;
4376 state.anchor <- getanchor ();
4377 opendoc state.path
state.password
;
4379 src#
string "page scroll scaling factor"
4380 (fun () -> string_of_float
conf.pgscale)
4383 let s = float_of_string
v in
4386 state.text <- Printf.sprintf
4387 "bad page scroll scaling factor `%s': %s"
4388 v (Printexc.to_string exn
)
4391 src#
int "ui font size"
4392 (fun () -> fstate.fontsize
)
4393 (fun v -> setfontsize (bound v 5 100));
4394 src#
int "hint font size"
4395 (fun () -> conf.hfsize
)
4396 (fun v -> conf.hfsize
<- bound v 5 100);
4397 colorp "background color"
4398 (fun () -> conf.bgcolor
)
4399 (fun v -> conf.bgcolor
<- v);
4400 src#
bool "crop hack"
4401 (fun () -> conf.crophack
)
4402 (fun v -> conf.crophack
<- v);
4403 src#
string "trim fuzz"
4404 (fun () -> irect_to_string conf.trimfuzz
)
4407 conf.trimfuzz
<- irect_of_string v;
4409 then settrim true conf.trimfuzz
;
4411 state.text <- Printf.sprintf
"bad irect `%s': %s"
4412 v (Printexc.to_string exn
)
4414 src#
string "throttle"
4416 match conf.maxwait
with
4417 | None
-> "show place holder if page is not ready"
4420 then "wait for page to fully render"
4422 "wait " ^ string_of_float
time
4423 ^
" seconds before showing placeholder"
4427 let f = float_of_string
v in
4429 then conf.maxwait
<- None
4430 else conf.maxwait
<- Some
f
4432 state.text <- Printf.sprintf
"bad time `%s': %s"
4433 v (Printexc.to_string exn
)
4435 src#
string "ghyll scroll"
4437 match conf.ghyllscroll
with
4439 | Some nab
-> ghyllscroll_to_string nab
4444 if String.length
v = 0
4446 else Some
(ghyllscroll_of_string v)
4448 conf.ghyllscroll
<- gs
4450 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4451 v (Printexc.to_string exn
)
4453 src#
string "selection command"
4454 (fun () -> conf.selcmd
)
4455 (fun v -> conf.selcmd
<- v);
4456 src#colorspace
"color space"
4457 (fun () -> colorspace_to_string conf.colorspace
)
4459 conf.colorspace
<- colorspace_of_int v;
4466 src#caption
"Document" 0;
4467 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4468 src#caption2
"Pages"
4469 (fun () -> string_of_int
state.pagecount
) 1;
4470 src#caption2
"Dimensions"
4471 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4475 src#caption
"Trimmed margins" 0;
4476 src#caption2
"Dimensions"
4477 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4481 src#caption
"OpenGL" 0;
4482 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4483 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4484 src#reset prevmode prevuioh
;
4488 let prevmode = state.mode
4489 and prevuioh
= state.uioh in
4490 fillsrc prevmode prevuioh
;
4491 let source = (src :> lvsource
) in
4492 let modehash = findkeyhash conf "info" in
4493 state.uioh <- coe (object (self)
4494 inherit listview ~
source ~trusted
:true ~
modehash as super
4495 val mutable m_prevmemused
= 0
4496 method infochanged
= function
4498 if m_prevmemused
!= state.memused
4500 m_prevmemused
<- state.memused
;
4501 G.postRedisplay "memusedchanged";
4503 | Pdim
-> G.postRedisplay "pdimchanged"
4504 | Docinfo
-> fillsrc prevmode prevuioh
4506 method key key mask
=
4507 if not
(Wsi.withctrl mask
)
4510 | 0xff51 -> coe (self#updownlevel ~
-1)
4511 | 0xff53 -> coe (self#updownlevel
1)
4512 | _ -> super#
key key mask
4513 else super#
key key mask
4515 G.postRedisplay "info";
4521 inherit lvsourcebase
4522 method getitemcount
= Array.length
state.help
4524 let s, l, _ = state.help
.(n) in
4527 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4531 m_qsearch
<- qsearch;
4532 match state.help
.(active) with
4533 | _, _, Action
f -> Some
(f uioh)
4543 method hasaction
n =
4544 match state.help
.(n) with
4545 | _, _, Action
_ -> true
4552 let modehash = findkeyhash conf "help" in
4553 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4554 G.postRedisplay "help";
4559 let re = Str.regexp
"[\r\n]" in
4561 inherit lvsourcebase
4562 val mutable m_items
= [||]
4564 method getitemcount
= 1 + Array.length m_items
4569 else m_items
.(n-1), 0
4571 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4576 then Buffer.clear
state.errmsgs
;
4577 m_qsearch
<- qsearch;
4584 method hasaction
n =
4588 state.newerrmsgs
<- false;
4589 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4590 m_items
<- Array.of_list
l
4598 let source = (msgsource :> lvsource
) in
4599 let modehash = findkeyhash conf "listview" in
4600 state.uioh <- coe (object
4601 inherit listview ~
source ~trusted
:false ~
modehash as super
4604 then msgsource#reset
;
4607 G.postRedisplay "msgs";
4610 let quickbookmark ?title
() =
4611 match state.layout with
4617 let sec = Unix.gettimeofday
() in
4618 let tm = Unix.localtime
sec in
4619 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4623 (tm.Unix.tm_year
+ 1900)
4626 | Some
title -> title
4628 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4632 state.fullscreen
<- None
;
4636 let setautoscrollspeed step goingdown
=
4637 let incr = max
1 ((abs step
) / 2) in
4638 let incr = if goingdown
then incr else -incr in
4639 let astep = step
+ incr in
4640 state.autoscroll
<- Some
astep;
4643 let gotounder = function
4644 | Ulinkgoto
(pageno, top) ->
4648 gotopage1 pageno top;
4654 | Uremote
(filename
, pageno) ->
4656 if Sys.file_exists filename
4659 let dir = Filename.dirname
state.path in
4660 let path = Filename.concat
dir filename
in
4661 if Sys.file_exists
path
4665 if String.length
path > 0
4667 let anchor = getanchor () in
4668 let ranchor = state.path, state.password
, anchor in
4669 state.anchor <- (pageno, 0.0, 0.0);
4670 state.ranchors
<- ranchor :: state.ranchors
;
4673 else showtext '
!'
("Could not find " ^ filename
)
4675 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4679 match conf.columns
with
4681 | _ -> conf.zoom > 1.0
4684 let viewkeyboard key mask
=
4686 let mode = state.mode in
4687 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4690 G.postRedisplay "view:enttext"
4692 let ctrl = Wsi.withctrl mask
in
4693 let existsinrow pageno (columns
, coverA
, coverB
) p =
4694 let last = ((pageno - coverA
) mod columns
) + columns
in
4695 let rec any = function
4698 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4702 then (if l.pageno = last then false else any rest
)
4712 | 0xff63 -> (* insert *)
4713 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4715 state.mode <- LinkNav
(Ltgendir
0);
4718 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4720 | 0xff1b | 113 -> (* escape / q *)
4721 begin match state.mstate
with
4723 state.mstate
<- Mnone
;
4724 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4725 G.postRedisplay "kill zoom rect";
4727 match state.ranchors
with
4729 | (path, password
, anchor) :: rest
->
4730 state.ranchors
<- rest
;
4731 state.anchor <- anchor;
4732 opendoc path password
4735 | 0xff08 -> (* backspace *)
4736 gotoghyll (getnav ~
-1)
4744 G.postRedisplay "dehighlight";
4746 | 47 | 63 -> (* / ? *)
4747 let ondone isforw
s =
4748 cbput state.hists
.pat
s;
4749 state.searchpattern
<- s;
4752 let s = String.create
1 in
4753 s.[0] <- Char.chr
key;
4754 enttext (s, "", Some
(onhist state.hists
.pat
),
4755 textentry, ondone (key = 47), true)
4757 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4758 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4759 setzoom (conf.zoom +. incr)
4761 | 43 | 0xffab -> (* + *)
4764 try int_of_string
s with exc
->
4765 state.text <- Printf.sprintf
"bad integer `%s': %s"
4766 s (Printexc.to_string exc
);
4772 state.text <- "page bias is now " ^ string_of_int
n;
4775 enttext ("page bias: ", "", None
, intentry, ondone, true)
4777 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4778 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4779 setzoom (max
0.01 (conf.zoom -. decr))
4781 | 45 | 0xffad -> (* - *)
4782 let ondone msg
= state.text <- msg
in
4784 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4785 optentry state.mode, ondone, true
4788 | 48 when ctrl -> (* ctrl-0 *)
4791 | 49 when ctrl -> (* ctrl-1 *)
4793 match conf.columns
with
4794 | Csingle
_ | Cmulti
_ -> 1
4795 | Csplit
(n, _) -> n
4797 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4801 | 0xffc6 -> (* f9 *)
4804 | 57 when ctrl -> (* ctrl-9 *)
4807 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4808 when not
ctrl -> (* 0..9 *)
4811 try int_of_string
s with exc
->
4812 state.text <- Printf.sprintf
"bad integer `%s': %s"
4813 s (Printexc.to_string exc
);
4819 cbput state.hists
.pag
(string_of_int
n);
4820 gotopage1 (n + conf.pagebias
- 1) 0;
4823 let pageentry text key =
4824 match Char.unsafe_chr
key with
4825 | 'g'
-> TEdone
text
4826 | _ -> intentry text key
4828 let text = "x" in text.[0] <- Char.chr
key;
4829 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4832 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4833 reshape conf.winw
conf.winh
;
4836 conf.hlinks
<- not
conf.hlinks
;
4837 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4838 G.postRedisplay "toggle highlightlinks";
4841 state.glinks
<- true;
4842 let mode = state.mode in
4843 state.mode <- Textentry
(
4845 ":", "", None
, linknentry, linkndone (fun under -> gotounder under),
4848 state.glinks
<- false;
4852 G.postRedisplay "view:linkent(F)"
4855 state.glinks
<- true;
4856 let mode = state.mode in
4857 state.mode <- Textentry
(
4858 (":", "", None
, linknentry, linkndone (fun under ->
4859 match Ne.pipe () with
4861 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4862 (Printexc.to_string exn
));
4865 try popen conf.selcmd
[r, 0; w, -1]; true
4868 (Printf.sprintf
"failed to execute %s: %s"
4869 conf.selcmd
(Printexc.to_string exn
));
4873 Ne.clo fd
(fun msg
->
4874 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4877 let s = undertext under in
4881 let l = String.length
s in
4882 let n = Unix.write
w s 0 l in
4887 "failed to write %d characters to sel pipe, wrote %d"
4892 (Printf.sprintf
"failed to write to sel pipe: %s"
4893 (Printexc.to_string exn
)
4902 state.glinks
<- false;
4906 G.postRedisplay "view:linkent"
4909 begin match state.autoscroll
with
4911 conf.autoscrollstep
<- step
;
4912 state.autoscroll
<- None
4914 if conf.autoscrollstep
= 0
4915 then state.autoscroll
<- Some
1
4916 else state.autoscroll
<- Some
conf.autoscrollstep
4919 | 112 when ctrl -> (* ctrl-p *)
4923 setpresentationmode (not
conf.presentation
);
4924 showtext ' '
("presentation mode " ^
4925 if conf.presentation
then "on" else "off");
4928 begin match state.fullscreen
with
4930 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4933 state.fullscreen
<- None
;
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
4961 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4962 gotoghyll (getpagey pageno)
4963 | Cmulti
((c, _, _) as cl
, _) ->
4964 if conf.presentation
4965 && (existsinrow l.pageno cl
4966 (fun l -> l.pageh
> l.pagey + l.pagevh))
4968 let y = clamp (pgscale conf.winh
) in
4971 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4972 gotoghyll (getpagey pageno)
4974 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4976 let pagey, pageh
= getpageyh l.pageno in
4977 let pagey = pagey + pageh
* l.pagecol
in
4978 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4979 gotoghyll (pagey + pageh
+ ips)
4982 | 0xff9f | 0xffff -> (* delete *)
4983 begin match state.layout with
4986 match conf.columns
with
4988 if conf.presentation
&& l.pagey != 0
4990 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
4992 let pageno = max
0 (l.pageno-1) in
4993 gotoghyll (getpagey pageno)
4994 | Cmulti
((c, _, coverB
) as cl
, _) ->
4995 if conf.presentation
&&
4996 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4998 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
5001 if l.pageno = state.pagecount
- coverB
5005 let pageno = max
0 (l.pageno-decr) in
5006 gotoghyll (getpagey pageno)
5014 let pageno = max
0 (l.pageno-1) in
5015 let pagey, pageh
= getpageyh pageno in
5018 let pagey, pageh
= getpageyh l.pageno in
5019 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5025 showtext ' '
(describe_location ());
5028 begin match state.layout with
5031 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5036 enterbookmarkmode ()
5038 | 104 | 0xffbe -> (* h|F1 *)
5044 | 101 when conf.redirectstderr -> (* e *)
5049 match state.layout with
5050 | l :: _ -> state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5053 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5057 showtext ' '
"Quick bookmark added";
5060 begin match state.layout with
5062 let rect = getpdimrect
l.pagedimno
in
5066 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5067 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5069 (truncate
(rect.(1) -. rect.(0)),
5070 truncate
(rect.(3) -. rect.(0)))
5072 let w = truncate
((float w)*.conf.zoom)
5073 and h = truncate
((float h)*.conf.zoom) in
5076 state.anchor <- getanchor ();
5077 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5079 G.postRedisplay "z";
5084 | 50 when ctrl -> (* ctrl-2 *)
5085 let maxw = getmaxw
() in
5087 then setzoom (maxw /. float conf.winw
)
5089 | 60 | 62 -> (* < > *)
5090 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5092 | 91 | 93 -> (* [ ] *)
5094 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5096 G.postRedisplay "brightness";
5098 | 99 when state.mode = View
-> (* c *)
5100 match state.prevcolumns
with
5101 | None
-> (1, 0, 0), 1.0
5102 | Some
(columns
, z
) ->
5105 | Csplit
(c, _) -> -c, 0, 0
5106 | Cmulti
((c, a, b), _) -> c, a, b
5107 | Csingle
_ -> 1, 0, 0
5111 setcolumns View
c a b;
5114 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5115 setzoom state.prevzoom
5117 | 107 | 0xff52 -> (* k up *)
5118 begin match state.autoscroll
with
5120 begin match state.mode with
5121 | Birdseye beye
-> upbirdseye 1 beye
5124 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5125 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5128 setautoscrollspeed n false
5131 | 106 | 0xff54 -> (* j down *)
5132 begin match state.autoscroll
with
5134 begin match state.mode with
5135 | Birdseye beye
-> downbirdseye 1 beye
5138 then gotoy_and_clear_text (clamp (conf.winh
/2))
5139 else gotoy_and_clear_text (clamp conf.scrollstep
)
5142 setautoscrollspeed n true
5145 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5151 else conf.hscrollstep
5153 let dx = if key = 0xff51 then dx else -dx in
5154 state.x <- state.x + dx;
5155 gotoy_and_clear_text state.y
5158 G.postRedisplay "lef/right"
5161 | 0xff55 -> (* prior *)
5165 match state.layout with
5167 | l :: _ -> state.y - l.pagey
5169 clamp (pgscale (-conf.winh
))
5173 | 0xff56 -> (* next *)
5177 match List.rev
state.layout with
5179 | l :: _ -> getpagey l.pageno
5181 clamp (pgscale conf.winh
)
5185 | 103 | 0xff50 -> (* g home *)
5187 | 71 | 0xff57 -> (* G end *)
5188 gotoghyll (clamp state.maxy)
5190 | 0xff53 when Wsi.withalt mask
-> (* alt-right *)
5191 gotoghyll (getnav 1)
5192 | 0xff51 when Wsi.withalt mask
-> (* alt-left *)
5193 gotoghyll (getnav ~
-1)
5196 state.anchor <- getanchor ();
5197 opendoc state.path state.password
5199 | 118 when conf.debug
-> (* v *)
5202 match getopaque l.pageno with
5205 let x0, y0, x1, y1 = pagebbox opaque
in
5206 let a,b = float x0, float y0 in
5207 let c,d = float x1, float y0 in
5208 let e,f = float x1, float y1 in
5209 let h,j
= float x0, float y1 in
5210 let rect = (a,b,c,d,e,f,h,j
) in
5212 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5214 G.postRedisplay "v";
5217 vlog "huh? %s" (Wsi.keyname
key)
5220 let linknavkeyboard key mask
linknav =
5221 let getpage pageno =
5222 let rec loop = function
5224 | l :: _ when l.pageno = pageno -> Some
l
5225 | _ :: rest
-> loop rest
5226 in loop state.layout
5228 let doexact (pageno, n) =
5229 match getopaque pageno, getpage pageno with
5230 | Some opaque
, Some
l ->
5233 let under = getlink opaque
n in
5234 G.postRedisplay "link gotounder";
5240 | 0xff50 -> (* home *)
5241 Some
(findlink opaque LDfirst
), -1
5243 | 0xff57 -> (* end *)
5244 Some
(findlink opaque LDlast
), 1
5246 | 0xff51 -> (* left *)
5247 Some
(findlink opaque
(LDleft
n)), -1
5249 | 0xff53 -> (* right *)
5250 Some
(findlink opaque
(LDright
n)), 1
5252 | 0xff52 -> (* up *)
5253 Some
(findlink opaque
(LDup
n)), -1
5255 | 0xff54 -> (* down *)
5256 Some
(findlink opaque
(LDdown
n)), 1
5261 begin match findpwl
l.pageno dir with
5265 state.mode <- LinkNav
(Ltgendir
dir);
5266 let y, h = getpageyh pageno in
5269 then y + h - conf.winh
5274 begin match getopaque pageno, getpage pageno with
5275 | Some opaque
, Some
_ ->
5277 let ld = if dir > 0 then LDfirst
else LDlast
in
5280 begin match link with
5282 showlinktype (getlink opaque
m);
5283 state.mode <- LinkNav
(Ltexact
(pageno, m));
5284 G.postRedisplay "linknav jpage";
5291 begin match opt with
5292 | Some Lnotfound
-> pwl l dir;
5293 | Some
(Lfound
m) ->
5297 let _, y0, _, y1 = getlinkrect opaque
m in
5299 then gotopage1 l.pageno y0
5301 let d = fstate.fontsize
+ 1 in
5302 if y1 - l.pagey > l.pagevh - d
5303 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5304 else G.postRedisplay "linknav";
5306 showlinktype (getlink opaque
m);
5307 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5310 | None
-> viewkeyboard key mask
5312 | _ -> viewkeyboard key mask
5317 G.postRedisplay "leave linknav"
5321 | Ltgendir
_ -> viewkeyboard key mask
5322 | Ltexact exact
-> doexact exact
5325 let keyboard key mask
=
5326 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5327 then wcmd "interrupt"
5328 else state.uioh <- state.uioh#
key key mask
5331 let birdseyekeyboard key mask
5332 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5334 match conf.columns
with
5336 | Cmulti
((c, _, _), _) -> c
5337 | Csplit
_ -> failwith
"bird's eye split mode"
5339 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5341 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5342 let y, h = getpageyh pageno in
5343 let top = (conf.winh
- h) / 2 in
5344 gotoy (max
0 (y - top))
5345 | 0xff0d -> leavebirdseye beye
false
5346 | 0xff1b -> leavebirdseye beye
true (* escape *)
5347 | 0xff52 -> upbirdseye incr beye
(* up *)
5348 | 0xff54 -> downbirdseye incr beye
(* down *)
5349 | 0xff51 -> upbirdseye 1 beye
(* left *)
5350 | 0xff53 -> downbirdseye 1 beye
(* right *)
5352 | 0xff55 -> (* prior *)
5353 begin match state.layout with
5357 state.mode <- Birdseye
(
5358 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5360 gotopage1 l.pageno 0;
5363 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5365 | [] -> gotoy (clamp (-conf.winh
))
5367 state.mode <- Birdseye
(
5368 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5370 gotopage1 l.pageno 0
5373 | [] -> gotoy (clamp (-conf.winh
))
5376 | 0xff56 -> (* next *)
5377 begin match List.rev
state.layout with
5379 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5380 begin match layout with
5382 let incr = l.pageh
- l.pagevh in
5387 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5389 G.postRedisplay "birdseye pagedown";
5391 else gotoy (clamp (incr + conf.interpagespace
*2));
5395 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5396 gotopage1 l.pageno 0;
5399 | [] -> gotoy (clamp conf.winh
)
5402 | 0xff50 -> (* home *)
5403 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5406 | 0xff57 -> (* end *)
5407 let pageno = state.pagecount
- 1 in
5408 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5409 if not
(pagevisible state.layout pageno)
5412 match List.rev
state.pdims
with
5414 | (_, _, h, _) :: _ -> h
5416 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5417 else G.postRedisplay "birdseye end";
5418 | _ -> viewkeyboard key mask
5421 let drawpage l linkindexbase
=
5423 match state.mode with
5424 | Textentry
_ -> scalecolor 0.4
5426 | View
-> scalecolor 1.0
5427 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5428 if l.pageno = hooverpageno
5431 if l.pageno = pageno
5437 begin match getopaque l.pageno with
5439 if tileready l l.pagex
l.pagey
5441 let x = l.pagedispx - l.pagex
5442 and y = l.pagedispy - l.pagey in
5444 match conf.columns
with
5445 | Csingle
_ | Cmulti
_ ->
5446 (if conf.hlinks
then 1 else 0)
5448 && not
(isbirdseye state.mode) then 2 else 0)
5452 match state.mode with
5453 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5456 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5463 let scrollindicator () =
5464 let sbw, ph
, sh = state.uioh#
scrollph in
5465 let sbh, pw, sw = state.uioh#scrollpw
in
5467 GlDraw.color (0.64, 0.64, 0.64);
5469 (float (conf.winw
- sbw), 0.)
5470 (float conf.winw
, float conf.winh
)
5473 (0., float (conf.winh
- sbh))
5474 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5476 GlDraw.color (0.0, 0.0, 0.0);
5479 (float (conf.winw
- sbw), ph
)
5480 (float conf.winw
, ph
+. sh)
5483 (pw, float (conf.winh
- sbh))
5484 (pw +. sw, float conf.winh
)
5489 match state.mstate
with
5490 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5493 | Msel
((x0, y0), (x1, y1)) ->
5494 let rec loop = function
5496 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5497 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5498 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5499 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5501 match getopaque l.pageno with
5503 let x0, y0 = pagetranslatepoint l x0 y0 in
5504 let x1, y1 = pagetranslatepoint l x1 y1 in
5505 seltext opaque
(x0, y0, x1, y1);
5513 let showrects rects
=
5515 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5516 GlDraw.polygon_mode `both `fill
;
5517 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5519 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5521 if l.pageno = pageno
5523 let dx = float (l.pagedispx - l.pagex
) in
5524 let dy = float (l.pagedispy - l.pagey) in
5525 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5526 GlDraw.begins `quads
;
5528 GlDraw.vertex2
(x0+.dx, y0+.dy);
5529 GlDraw.vertex2
(x1+.dx, y1+.dy);
5530 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5531 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5542 GlClear.color (scalecolor2 conf.bgcolor
);
5543 GlClear.clear
[`
color];
5544 let rec loop linkindexbase
= function
5546 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5547 loop linkindexbase rest
5550 loop 0 state.layout;
5552 match state.mode with
5553 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5554 begin match getopaque pageno with
5556 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5563 | None
-> state.rects
5570 begin match state.mstate
with
5571 | Mzoomrect
((x0, y0), (x1, y1)) ->
5573 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5574 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5575 GlDraw.rect (float x0, float y0)
5576 (float x1, float y1);
5585 let zoomrect x y x1 y1 =
5588 and y0 = min
y y1 in
5589 gotoy (state.y + y0);
5590 state.anchor <- getanchor ();
5591 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5593 if state.w < conf.winw
- state.scrollw
5594 then (conf.winw
- state.scrollw
- state.w) / 2
5597 state.x <- (state.x + margin) - x0;
5599 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5600 state.mstate
<- Mnone
;
5604 let winw = conf.winw - state.scrollw
- 1 in
5605 let s = float x /. float winw in
5606 let destx = truncate
(float (state.w + winw) *. s) in
5607 state.x <- winw - destx;
5608 gotoy_and_clear_text state.y;
5609 state.mstate
<- Mscrollx
;
5613 let s = float y /. float conf.winh
in
5614 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5615 gotoy_and_clear_text desty;
5616 state.mstate
<- Mscrolly
;
5619 let viewmouse button down
x y mask
=
5621 | n when (n == 4 || n == 5) && not down
->
5622 if Wsi.withctrl mask
5624 match state.mstate
with
5625 | Mzoom
(oldn
, i
) ->
5633 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5635 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5637 let zoom = conf.zoom -. incr in
5639 state.mstate
<- Mzoom
(n, 0);
5641 state.mstate
<- Mzoom
(n, i
+1);
5643 else state.mstate
<- Mzoom
(n, 0)
5645 | _ -> state.mstate
<- Mzoom
(n, 0)
5648 match state.autoscroll
with
5649 | Some step
-> setautoscrollspeed step
(n=4)
5653 then -conf.scrollstep
5654 else conf.scrollstep
5656 let incr = incr * 2 in
5657 let y = clamp incr in
5658 gotoy_and_clear_text y
5661 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5662 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5663 gotoy_and_clear_text state.y
5665 | 1 when Wsi.withctrl mask
->
5668 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5669 state.mstate
<- Mpan
(x, y)
5672 state.mstate
<- Mnone
5677 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5679 state.mstate
<- Mzoomrect
(p, p)
5682 match state.mstate
with
5683 | Mzoomrect
((x0, y0), _) ->
5684 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5685 then zoomrect x0 y0 x y
5687 state.mstate
<- Mnone
;
5688 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5689 G.postRedisplay "kill accidental zoom rect";
5692 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5693 state.mstate
<- Mnone
5696 | 1 when x > conf.winw - state.scrollw
->
5699 let _, position, sh = state.uioh#
scrollph in
5700 if y > truncate
position && y < truncate
(position +. sh)
5701 then state.mstate
<- Mscrolly
5704 state.mstate
<- Mnone
5706 | 1 when y > conf.winh
- state.hscrollh ->
5709 let _, position, sw = state.uioh#scrollpw
in
5710 if x > truncate
position && x < truncate
(position +. sw)
5711 then state.mstate
<- Mscrollx
5714 state.mstate
<- Mnone
5717 let dest = if down
then getunder x y else Unone
in
5718 begin match dest with
5722 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5725 | Unone
when down
->
5726 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5727 state.mstate
<- Mpan
(x, y);
5729 | Unone
| Utext
_ ->
5732 if conf.angle
mod 360 = 0
5734 state.mstate
<- Msel
((x, y), (x, y));
5735 G.postRedisplay "mouse select";
5739 match state.mstate
with
5742 | Mzoom
_ | Mscrollx
| Mscrolly
->
5743 state.mstate
<- Mnone
5745 | Mzoomrect
((x0, y0), _) ->
5749 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5750 state.mstate
<- Mnone
5752 | Msel
((x0, y0), (x1, y1)) ->
5753 let rec loop = function
5757 let a0 = l.pagedispy in
5758 let a1 = a0 + l.pagevh in
5759 let b0 = l.pagedispx in
5760 let b1 = b0 + l.pagevw in
5761 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5762 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5766 match getopaque l.pageno with
5769 match Ne.pipe () with
5773 "can not create sel pipe: %s"
5774 (Printexc.to_string exn
));
5776 let doclose what fd
=
5777 Ne.clo fd
(fun msg
->
5778 dolog "%s close failed: %s" what msg
)
5781 popen conf.selcmd
[r, 0; w, -1];
5784 G.postRedisplay "copysel";
5786 dolog "can not execute %S: %s"
5787 conf.selcmd
(Printexc.to_string exn
);
5795 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5796 state.mstate
<- Mnone
;
5803 let birdseyemouse button down
x y mask
5804 (conf, leftx
, _, hooverpageno
, anchor) =
5807 let rec loop = function
5810 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5811 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5813 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5819 | _ -> viewmouse button down
x y mask
5822 let mouse button down
x y mask
=
5823 state.uioh <- state.uioh#button button down
x y mask
;
5827 state.uioh <- state.uioh#
motion x y
5831 state.uioh <- state.uioh#
pmotion x y;
5837 method key key mask
=
5838 begin match state.mode with
5839 | Textentry
textentry -> textentrykeyboard key mask
textentry
5840 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5841 | View
-> viewkeyboard key mask
5842 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5846 method button button bstate
x y mask
=
5847 begin match state.mode with
5849 | View
-> viewmouse button bstate
x y mask
5850 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5856 begin match state.mode with
5858 | View
| Birdseye
_ | LinkNav
_ ->
5859 match state.mstate
with
5860 | Mzoom
_ | Mnone
-> ()
5865 state.mstate
<- Mpan
(x, y);
5867 then state.x <- state.x + dx;
5869 gotoy_and_clear_text y
5872 state.mstate
<- Msel
(a, (x, y));
5873 G.postRedisplay "motion select";
5876 let y = min
conf.winh
(max
0 y) in
5880 let x = min
conf.winw (max
0 x) in
5883 | Mzoomrect
(p0
, _) ->
5884 state.mstate
<- Mzoomrect
(p0
, (x, y));
5885 G.postRedisplay "motion zoomrect";
5889 method pmotion x y =
5890 begin match state.mode with
5891 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5892 let rec loop = function
5894 if hooverpageno
!= -1
5896 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5897 G.postRedisplay "pmotion birdseye no hoover";
5900 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5901 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5903 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5904 G.postRedisplay "pmotion birdseye hoover";
5914 match state.mstate
with
5915 | Mnone
-> updateunder x y
5916 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5921 method infochanged
_ = ()
5924 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5925 let p, h = scrollph state.y maxy in
5929 let winw = conf.winw - state.scrollw
- 1 in
5930 let fwinw = float winw in
5932 let sw = fwinw /. float state.w in
5933 let sw = fwinw *. sw in
5934 max
sw (float conf.scrollh
)
5937 let f = state.w+winw in
5938 let r = float (winw-state.x) /. float f in
5939 let p = fwinw *. r in
5943 if position +. sw > fwinw
5944 then fwinw -. position
5947 state.hscrollh, position, sw
5951 match state.mode with
5952 | LinkNav
_ -> "links"
5953 | Textentry
_ -> "textentry"
5954 | Birdseye
_ -> "birdseye"
5957 findkeyhash conf modename
5964 let fontpath = ref "";;
5967 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5970 let l = String.length
s in
5971 let b = Buffer.create
l in
5977 try Sys.getenv
"HOME"
5980 ("Can not determine home directory location: " ^
5981 Printexc.to_string exn
);
5985 let modifier_of_string = function
5986 | "alt" -> Wsi.altmask
5987 | "shift" -> Wsi.shiftmask
5988 | "ctrl" | "control" -> Wsi.ctrlmask
5989 | "meta" -> Wsi.metamask
5994 let r = Str.regexp
"-" in
5996 let elems = Str.full_split
r s in
5999 let m1 = modifier_of_string s in
6001 then (Wsi.namekey
s, m)
6004 | Str.Delim
s when n land 1 = 0 -> g s
6006 | Str.Delim
_ -> (k
, m)
6008 let rec loop n k
m = function
6011 let k, m = f n k m x in
6017 let keys_of_string =
6018 let r = Str.regexp
"[ \t]" in
6020 let elems = Str.split
r s in
6021 List.map
key_of_string elems
6024 let copykeyhashes c =
6025 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6028 let config_of c attrs
=
6032 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6033 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6034 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6035 | "preload" -> { c with preload = bool_of_string
v }
6036 | "page-bias" -> { c with pagebias
= int_of_string
v }
6037 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6038 | "horizontal-scroll-step" ->
6039 { c with hscrollstep
= max
(int_of_string
v) 1 }
6040 | "auto-scroll-step" ->
6041 { c with autoscrollstep
= max
0 (int_of_string
v) }
6042 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6043 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6046 match String.lowercase
v with
6047 | "true" -> Some infinity
6049 | f -> Some
(float_of_string
f)
6051 { c with maxwait
= mw}
6052 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6053 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6054 | "vertical-margin" ->
6055 { c with interpagespace
= max
0 (int_of_string
v) }
6057 let zoom = float_of_string
v /. 100. in
6058 let zoom = max
zoom 0.0 in
6059 { c with zoom = zoom }
6060 | "presentation" -> { c with presentation
= bool_of_string
v }
6061 | "rotation-angle" -> { c with angle
= int_of_string
v }
6062 | "width" -> { c with winw = max
20 (int_of_string
v) }
6063 | "height" -> { c with winh
= max
20 (int_of_string
v) }
6064 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6065 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6066 | "pixmap-cache-size" ->
6067 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6068 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6069 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6070 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6071 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6072 | "background-color" -> { c with bgcolor
= color_of_string v }
6073 | "scrollbar-in-presentation" ->
6074 { c with scrollbarinpm
= bool_of_string
v }
6075 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6076 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6077 | "mupdf-store-size" ->
6078 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6079 | "checkers" -> { c with checkers
= bool_of_string
v }
6080 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6081 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6082 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6083 | "uri-launcher" -> { c with urilauncher
= unent v }
6084 | "path-launcher" -> { c with pathlauncher
= unent v }
6085 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6086 | "invert-colors" -> { c with invert
= bool_of_string
v }
6087 | "brightness" -> { c with colorscale
= float_of_string
v }
6088 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6090 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6092 let (n, _, _) as nab
= multicolumns_of_string v in
6094 then { c with columns
= Csplit
(-n, [||]) }
6095 else { c with columns
= Cmulti
(nab
, [||]) }
6096 | "birds-eye-columns" ->
6097 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6098 | "selection-command" -> { c with selcmd
= unent v }
6099 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6100 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6101 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6104 prerr_endline
("Error processing attribute (`" ^
6105 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6108 let rec fold c = function
6111 let c = apply c k v in
6114 fold { c with keyhashes
= copykeyhashes c } attrs
;
6117 let fromstring f pos
n v d =
6120 dolog "Error processing attribute (%S=%S) at %d\n%s"
6121 n v pos
(Printexc.to_string exn
)
6126 let bookmark_of attrs
=
6127 let rec fold title page
rely visy
= function
6128 | ("title", v) :: rest
-> fold v page
rely visy rest
6129 | ("page", v) :: rest
-> fold title v rely visy rest
6130 | ("rely", v) :: rest
-> fold title page
v visy rest
6131 | ("visy", v) :: rest
-> fold title page
rely v rest
6132 | _ :: rest
-> fold title page
rely visy rest
6133 | [] -> title, page
, rely, visy
6135 fold "invalid" "0" "0" "0" attrs
6139 let rec fold path page
rely pan visy
= function
6140 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6141 | ("page", v) :: rest
-> fold path v rely pan visy rest
6142 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6143 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6144 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6145 | _ :: rest
-> fold path page
rely pan visy rest
6146 | [] -> path, page
, rely, pan
, visy
6148 fold "" "0" "0" "0" "0" attrs
6152 let rec fold rs ls
= function
6153 | ("out", v) :: rest
-> fold v ls rest
6154 | ("in", v) :: rest
-> fold rs
v rest
6155 | _ :: rest
-> fold ls rs rest
6161 let setconf dst
src =
6162 dst
.scrollbw
<- src.scrollbw
;
6163 dst
.scrollh
<- src.scrollh
;
6164 dst
.icase
<- src.icase
;
6165 dst
.preload <- src.preload;
6166 dst
.pagebias
<- src.pagebias
;
6167 dst
.verbose
<- src.verbose
;
6168 dst
.scrollstep
<- src.scrollstep
;
6169 dst
.maxhfit
<- src.maxhfit
;
6170 dst
.crophack
<- src.crophack
;
6171 dst
.autoscrollstep
<- src.autoscrollstep
;
6172 dst
.maxwait
<- src.maxwait
;
6173 dst
.hlinks
<- src.hlinks
;
6174 dst
.underinfo
<- src.underinfo
;
6175 dst
.interpagespace
<- src.interpagespace
;
6176 dst
.zoom <- src.zoom;
6177 dst
.presentation
<- src.presentation
;
6178 dst
.angle
<- src.angle
;
6179 dst
.winw <- src.winw;
6180 dst
.winh
<- src.winh
;
6181 dst
.savebmarks
<- src.savebmarks
;
6182 dst
.memlimit
<- src.memlimit
;
6183 dst
.proportional
<- src.proportional
;
6184 dst
.texcount
<- src.texcount
;
6185 dst
.sliceheight
<- src.sliceheight
;
6186 dst
.thumbw
<- src.thumbw
;
6187 dst
.jumpback
<- src.jumpback
;
6188 dst
.bgcolor
<- src.bgcolor
;
6189 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6190 dst
.tilew
<- src.tilew
;
6191 dst
.tileh
<- src.tileh
;
6192 dst
.mustoresize
<- src.mustoresize
;
6193 dst
.checkers
<- src.checkers
;
6194 dst
.aalevel
<- src.aalevel
;
6195 dst
.trimmargins
<- src.trimmargins
;
6196 dst
.trimfuzz
<- src.trimfuzz
;
6197 dst
.urilauncher
<- src.urilauncher
;
6198 dst
.colorspace
<- src.colorspace
;
6199 dst
.invert
<- src.invert
;
6200 dst
.colorscale
<- src.colorscale
;
6201 dst
.redirectstderr <- src.redirectstderr;
6202 dst
.ghyllscroll
<- src.ghyllscroll
;
6203 dst
.columns
<- src.columns
;
6204 dst
.beyecolumns
<- src.beyecolumns
;
6205 dst
.selcmd
<- src.selcmd
;
6206 dst
.updatecurs
<- src.updatecurs
;
6207 dst
.pathlauncher
<- src.pathlauncher
;
6208 dst
.keyhashes
<- copykeyhashes src;
6209 dst
.hfsize
<- src.hfsize
;
6210 dst
.hscrollstep
<- src.hscrollstep
;
6211 dst
.pgscale <- src.pgscale;
6215 let h = Hashtbl.create
10 in
6216 let dc = { defconf with angle
= defconf.angle
} in
6217 let rec toplevel v t spos
_ =
6219 | Vdata
| Vcdata
| Vend
-> v
6220 | Vopen
("llppconfig", _, closed
) ->
6223 else { v with f = llppconfig
}
6225 error
"unexpected subelement at top level" s spos
6226 | Vclose
_ -> error
"unexpected close at top level" s spos
6228 and llppconfig
v t spos
_ =
6230 | Vdata
| Vcdata
-> v
6231 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6232 | Vopen
("defaults", attrs
, closed
) ->
6233 let c = config_of dc attrs
in
6237 else { v with f = defaults
}
6239 | Vopen
("ui-font", attrs
, closed
) ->
6240 let rec getsize size
= function
6242 | ("size", v) :: rest
->
6244 fromstring int_of_string spos
"size" v fstate.fontsize
in
6246 | l -> getsize size l
6248 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6251 else { v with f = uifont
(Buffer.create
10) }
6253 | Vopen
("doc", attrs
, closed
) ->
6254 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6255 let path = unent pathent
6256 and pageno = fromstring int_of_string spos
"page" spage
0
6257 and rely = fromstring float_of_string spos
"rely" srely
0.0
6258 and pan
= fromstring int_of_string spos
"pan" span
0
6259 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6260 let c = config_of dc attrs
in
6261 let anchor = (pageno, rely, visy
) in
6263 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6264 else { v with f = doc
path pan
anchor c [] }
6267 error
"unexpected subelement in llppconfig" s spos
6269 | Vclose
"llppconfig" -> { v with f = toplevel }
6270 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6272 and defaults
v t spos
_ =
6274 | Vdata
| Vcdata
-> v
6275 | Vend
-> error
"unexpected end of input in defaults" s spos
6276 | Vopen
("keymap", attrs
, closed
) ->
6278 try List.assoc
"mode" attrs
6279 with Not_found
-> "global" in
6284 let h = findkeyhash dc modename in
6285 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6288 { v with f = pkeymap
ret KeyMap.empty }
6290 | Vopen
(_, _, _) ->
6291 error
"unexpected subelement in defaults" s spos
6293 | Vclose
"defaults" ->
6294 { v with f = llppconfig
}
6296 | Vclose
_ -> error
"unexpected close in defaults" s spos
6298 and uifont
b v t spos
epos =
6301 Buffer.add_substring
b s spos
(epos - spos
);
6303 | Vopen
(_, _, _) ->
6304 error
"unexpected subelement in ui-font" s spos
6305 | Vclose
"ui-font" ->
6306 if String.length
!fontpath = 0
6307 then fontpath := Buffer.contents
b;
6308 { v with f = llppconfig
}
6309 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6310 | Vend
-> error
"unexpected end of input in ui-font" s spos
6312 and doc
path pan
anchor c bookmarks
v t spos
_ =
6314 | Vdata
| Vcdata
-> v
6315 | Vend
-> error
"unexpected end of input in doc" s spos
6316 | Vopen
("bookmarks", _, closed
) ->
6319 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6321 | Vopen
("keymap", attrs
, closed
) ->
6323 try List.assoc
"mode" attrs
6324 with Not_found
-> "global"
6330 let h = findkeyhash c modename in
6331 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6332 doc
path pan
anchor c bookmarks
6334 { v with f = pkeymap
ret KeyMap.empty }
6336 | Vopen
(_, _, _) ->
6337 error
"unexpected subelement in doc" s spos
6340 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6341 { v with f = llppconfig
}
6343 | Vclose
_ -> error
"unexpected close in doc" s spos
6345 and pkeymap
ret keymap
v t spos
_ =
6347 | Vdata
| Vcdata
-> v
6348 | Vend
-> error
"unexpected end of input in keymap" s spos
6349 | Vopen
("map", attrs
, closed
) ->
6350 let r, l = map_of attrs
in
6351 let kss = fromstring keys_of_string spos
"in" r [] in
6352 let lss = fromstring keys_of_string spos
"out" l [] in
6356 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6357 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6360 then { v with f = pkeymap
ret keymap }
6363 { v with f = skip
"map" f }
6366 error
"unexpected subelement in keymap" s spos
6368 | Vclose
"keymap" ->
6369 { v with f = ret keymap }
6371 | Vclose
_ -> error
"unexpected close in keymap" s spos
6373 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6375 | Vdata
| Vcdata
-> v
6376 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6377 | Vopen
("item", attrs
, closed
) ->
6378 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6379 let page = fromstring int_of_string spos
"page" spage
0
6380 and rely = fromstring float_of_string spos
"rely" srely
0.0
6381 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6383 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6386 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6389 { v with f = skip
"item" f }
6392 error
"unexpected subelement in bookmarks" s spos
6394 | Vclose
"bookmarks" ->
6395 { v with f = doc
path pan
anchor c bookmarks }
6397 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6399 and skip tag
f v t spos
_ =
6401 | Vdata
| Vcdata
-> v
6403 error
("unexpected end of input in skipped " ^ tag
) s spos
6404 | Vopen
(tag'
, _, closed
) ->
6408 let f'
() = { v with f = skip tag
f } in
6409 { v with f = skip tag'
f'
}
6413 else error
("unexpected close in skipped " ^ tag
) s spos
6416 parse
{ f = toplevel; accu = () } s;
6422 let len = in_channel_length ic
in
6423 let s = String.create
len in
6424 really_input ic
s 0 len;
6427 | Parse_error
(msg
, s, pos
) ->
6428 let subs = subs s pos
in
6429 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6430 failwith
("parse error: " ^
s)
6433 failwith
("config load error: " ^
Printexc.to_string exn
)
6439 let dir = Filename.concat
home ".config" in
6440 if Sys.is_directory
dir then dir else home
6443 Filename.concat
dir "llpp.conf"
6446 let confpath = ref defconfpath;;
6449 if Sys.file_exists
!confpath
6452 (try Some
(open_in_bin
!confpath)
6455 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6456 Printexc.to_string exn
);
6466 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6467 Printexc.to_string exn
);
6475 f (Hashtbl.create
0, defconf)
6480 let pc, pb
, px, pa
=
6482 Hashtbl.find h (Filename.basename
state.path)
6483 with Not_found
-> dc, [], 0, emptyanchor
6487 state.bookmarks <- pb
;
6489 state.scrollw
<- conf.scrollbw
;
6491 then state.anchor <- pa
;
6492 cbput state.hists
.nav pa
;
6498 let add_attrs bb always
dc c =
6501 then Printf.bprintf bb
"\n %s='%b'" s a
6504 then Printf.bprintf bb
"\n %s='%d'" s a
6507 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6510 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6513 then Printf.bprintf bb
"\n %s='%f'" s a
6517 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6521 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6525 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6529 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6535 | Some
(_N
, _A
, _B
) ->
6536 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6546 else string_of_float
f
6548 Printf.bprintf bb
"\n %s='%s'" s v
6553 | Cmulti
((n, a, b), _) when n > 1 ->
6554 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6555 | Csplit
(n, _) when n > 1 ->
6556 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6562 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6567 then dc.winw, dc.winh
6569 match state.fullscreen
with
6571 | None
-> c.winw, c.winh
6573 oi
"width" w dc.winw;
6574 oi
"height" h dc.winh
;
6575 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6576 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6577 ob "case-insensitive-search" c.icase
dc.icase
;
6578 ob "preload" c.preload dc.preload;
6579 oi
"page-bias" c.pagebias
dc.pagebias
;
6580 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6581 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6582 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6583 ob "crop-hack" c.crophack
dc.crophack
;
6584 oW
"throttle" c.maxwait
dc.maxwait
;
6585 ob "highlight-links" c.hlinks
dc.hlinks
;
6586 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6587 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6588 oz
"zoom" c.zoom dc.zoom;
6589 ob "presentation" c.presentation
dc.presentation
;
6590 oi
"rotation-angle" c.angle
dc.angle
;
6591 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6592 ob "proportional-display" c.proportional
dc.proportional
;
6593 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6594 oi
"tex-count" c.texcount
dc.texcount
;
6595 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6596 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6597 ob "persistent-location" c.jumpback
dc.jumpback
;
6598 oc
"background-color" c.bgcolor
dc.bgcolor
;
6599 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6600 oi
"tile-width" c.tilew
dc.tilew
;
6601 oi
"tile-height" c.tileh
dc.tileh
;
6602 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6603 ob "checkers" c.checkers
dc.checkers
;
6604 oi
"aalevel" c.aalevel
dc.aalevel
;
6605 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6606 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6607 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6608 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6609 oC
"color-space" c.colorspace
dc.colorspace
;
6610 ob "invert-colors" c.invert
dc.invert
;
6611 oF
"brightness" c.colorscale
dc.colorscale
;
6612 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6613 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6614 oco
"columns" c.columns
dc.columns
;
6615 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6616 os
"selection-command" c.selcmd
dc.selcmd
;
6617 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6618 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6619 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6620 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6623 let keymapsbuf always
dc c =
6624 let bb = Buffer.create
16 in
6625 let rec loop = function
6627 | (modename, h) :: rest
->
6628 let dh = findkeyhash dc modename in
6629 if always
|| h <> dh
6631 if Hashtbl.length
h > 0
6633 if Buffer.length
bb > 0
6634 then Buffer.add_char
bb '
\n'
;
6635 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6636 Hashtbl.iter
(fun i
o ->
6637 let isdifferent = always
||
6639 let dO = Hashtbl.find dh i
in
6641 with Not_found
-> true
6646 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6647 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6648 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6649 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6650 Buffer.add_string
bb (Wsi.keyname
k);
6653 let rec loop = function
6655 | km
:: [] -> addkm km
6656 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6660 Buffer.add_string
bb "<map in='";
6664 Buffer.add_string
bb "' out='";
6666 Buffer.add_string
bb "'/>\n"
6669 Buffer.add_string
bb "' out='";
6671 Buffer.add_string
bb "'/>\n"
6673 | KMmulti
(ins, kms
) ->
6674 Buffer.add_char
bb ' '
;
6676 Buffer.add_string
bb "' out='";
6678 Buffer.add_string
bb "'/>\n"
6680 Buffer.add_string
bb "</keymap>";
6690 let uifontsize = fstate.fontsize
in
6691 let bb = Buffer.create
32768 in
6693 let dc = if conf.bedefault
then conf else dc in
6694 Buffer.add_string
bb "<llppconfig>\n";
6696 if String.length
!fontpath > 0
6698 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6704 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6707 Buffer.add_string
bb "<defaults ";
6708 add_attrs bb true dc dc;
6709 let kb = keymapsbuf true dc dc in
6710 if Buffer.length
kb > 0
6712 Buffer.add_string
bb ">\n";
6713 Buffer.add_buffer
bb kb;
6714 Buffer.add_string
bb "\n</defaults>\n";
6716 else Buffer.add_string
bb "/>\n";
6718 let adddoc path pan
anchor c bookmarks =
6719 if bookmarks == [] && c = dc && anchor = emptyanchor
6722 Printf.bprintf
bb "<doc path='%s'"
6723 (enent
path 0 (String.length
path));
6725 if anchor <> emptyanchor
6727 let n, rely, visy
= anchor in
6728 Printf.bprintf
bb " page='%d'" n;
6731 Printf.bprintf
bb " rely='%f'" rely
6733 if abs_float visy
> 1e-6
6735 Printf.bprintf
bb " visy='%f'" visy
6740 then Printf.bprintf
bb " pan='%d'" pan
;
6742 add_attrs bb false dc c;
6743 let kb = keymapsbuf false dc c in
6745 begin match bookmarks with
6747 if Buffer.length
kb > 0
6749 Buffer.add_string
bb ">\n";
6750 Buffer.add_buffer
bb kb;
6751 Buffer.add_string
bb "\n</doc>\n";
6753 else Buffer.add_string
bb "/>\n"
6755 Buffer.add_string
bb ">\n<bookmarks>\n";
6756 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6758 "<item title='%s' page='%d'"
6759 (enent
title 0 (String.length
title))
6764 Printf.bprintf
bb " rely='%f'" rely
6766 if abs_float visy
> 1e-6
6768 Printf.bprintf
bb " visy='%f'" visy
6770 Buffer.add_string
bb "/>\n";
6772 Buffer.add_string
bb "</bookmarks>";
6773 if Buffer.length
kb > 0
6775 Buffer.add_string
bb "\n";
6776 Buffer.add_buffer
bb kb;
6778 Buffer.add_string
bb "\n</doc>\n";
6784 match state.mode with
6785 | Birdseye
(c, pan, _, _, _) ->
6787 match conf.columns
with
6788 | Cmulti
((c, _, _), _) -> Some
c
6792 match c.columns
with
6793 | Cmulti
(c, _) -> Cmulti
(c, [||])
6794 | Csingle
_ -> Csingle
[||]
6795 | Csplit
_ -> failwith
"quit from bird's eye while split"
6797 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6798 | _ -> state.x, conf
6800 let basename = Filename.basename state.path in
6801 adddoc basename pan (getanchor ())
6803 let autoscrollstep =
6804 match state.autoscroll
with
6806 | None
-> conf.autoscrollstep
6808 match state.mode with
6809 | Birdseye
(bc
, _, _, _, _) ->
6812 presentation
= bc
.presentation
;
6813 interpagespace
= bc
.interpagespace
;
6814 maxwait
= bc
.maxwait
;
6815 autoscrollstep = autoscrollstep }
6816 | _ -> { conf with autoscrollstep = autoscrollstep }
6818 (if conf.savebmarks
then state.bookmarks else []);
6820 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6822 then adddoc path x anchor c bookmarks
6824 Buffer.add_string
bb "</llppconfig>\n";
6827 if load1 f && Buffer.length
bb > 0
6830 let tmp = !confpath ^
".tmp" in
6831 let oc = open_out_bin
tmp in
6832 Buffer.output_buffer
oc bb;
6834 Unix.rename
tmp !confpath;
6837 ("error while saving configuration: " ^
Printexc.to_string exn
)
6842 let trimcachepath = ref "" in
6845 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6846 "<password> Set password");
6848 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6849 "<path> Set path to the user interface font");
6851 ("-c", Arg.String
(fun s -> Config.confpath := s),
6852 "<path> Set path to the configuration file");
6854 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6855 "<path> Set path to the trim cache file");
6857 ("-v", Arg.Unit
(fun () ->
6859 "%s\nconfiguration path: %s\n"
6863 exit
0), " Print version and exit");
6866 (fun s -> state.path <- s)
6867 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6869 if String.length
state.path = 0
6870 then (prerr_endline
"file name missing"; exit
1);
6872 if not
(Config.load ())
6873 then prerr_endline
"failed to load configuration";
6875 let globalkeyhash = findkeyhash conf "global" in
6876 let wsfd, winw, winh
= Wsi.init
(object
6878 if nogeomcmds state.geomcmds
|| platform == Posx
6881 GlClear.color (scalecolor2 conf.bgcolor
);
6882 GlClear.clear
[`
color];
6884 method display = display ()
6885 method reshape w h = reshape w h
6886 method mouse b d x y m = mouse b d x y m
6887 method motion x y = state.mpos
<- (x, y); motion x y
6888 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6890 let mascm = m land (
6891 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6893 match state.keystate
with
6895 let km = k, mascm in
6898 let modehash = state.uioh#
modehash in
6899 try Hashtbl.find modehash km
6901 try Hashtbl.find globalkeyhash km
6902 with Not_found
-> KMinsrt
(k, m)
6904 | KMinsrt
(k, m) -> keyboard k m
6905 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6906 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6908 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6909 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6910 state.keystate
<- KSnone
6911 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6912 state.keystate
<- KSinto
(keys
, insrt
)
6914 state.keystate
<- KSnone
6916 method enter
x y = state.mpos
<- (x, y); pmotion x y
6917 method leave = state.mpos
<- (-1, -1)
6918 method quit
= raise Quit
6919 end) conf.winw conf.winh
(platform = Posx
) in
6924 List.exists
GlMisc.check_extension
6925 [ "GL_ARB_texture_rectangle"
6926 ; "GL_EXT_texture_recangle"
6927 ; "GL_NV_texture_rectangle" ]
6929 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6932 match Ne.pipe () with
6934 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6938 match Ne.pipe () with
6940 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6950 setcheckers conf.checkers
;
6954 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6955 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6956 !Config.fontpath, !trimcachepath
6960 state.text <- "Opening " ^
state.path;
6962 opendoc state.path state.password
;
6965 let rec loop deadline
=
6967 match state.errfd
with
6968 | None
-> [state.sr
; state.wsfd]
6969 | Some fd
-> [state.sr
; state.wsfd; fd
]
6973 state.redisplay
<- false;
6980 if deadline
= infinity
6982 else max
0.0 (deadline
-. now)
6987 try Unix.select
r [] [] timeout
6988 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6994 if state.ghyll
== noghyll
6996 match state.autoscroll
with
6997 | Some step
when step
!= 0 ->
6998 let y = state.y + step
in
7002 else if y >= state.maxy then 0 else y
7005 if state.mode = View
7006 then state.text <- "";
7009 else deadline
+. 0.01
7014 let rec checkfds = function
7016 | fd
:: rest
when fd
= state.sr
->
7017 let cmd = readcmd state.sr
in
7021 | fd
:: rest
when fd
= state.wsfd ->
7026 let s = String.create
80 in
7027 let n = Unix.read fd
s 0 80 in
7028 if conf.redirectstderr
7030 Buffer.add_substring
state.errmsgs
s 0 n;
7031 state.newerrmsgs
<- true;
7032 state.redisplay
<- true;
7035 prerr_string
(String.sub
s 0 n);
7043 if deadline
= infinity
7047 match state.autoscroll
with
7048 | Some step
when step
!= 0 -> deadline1
7049 | _ -> if state.ghyll
== noghyll then infinity
else deadline1