6 | Ulinkgoto
of (int * int)
8 | Uunexpected
of string
11 | Uremote
of (string * int)
12 and facename
= string;;
14 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
15 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* fontpath
* trimcachepath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
37 and trimcachepath
= string
40 and irect
= (int * int * int * int)
41 and trimparams
= (trimmargins
* irect
)
42 and colorspace
= | Rgb
| Bgr
| Gray
51 | LDfirstvisible
of (int * int * int)
66 | KMmulti
of key list
* key list
68 and keyhash
= (key
, keymap
) Hashtbl.t
71 | KSinto
of (key list
* key list
)
74 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
75 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
77 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
79 external init
: pipe
-> params
-> unit = "ml_init";;
80 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
81 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
82 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
83 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
84 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
85 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
86 external measurestr
: int -> string -> float = "ml_measure_string";;
87 external getmaxw
: unit -> float = "ml_getmaxw";;
88 external postprocess
:
89 opaque
-> int -> int -> int -> (int * string * int) -> int = "ml_postprocess";;
90 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
91 external platform
: unit -> platform
= "ml_platform";;
92 external setaalevel
: int -> unit = "ml_setaalevel";;
93 external realloctexts
: int -> bool = "ml_realloctexts";;
94 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
95 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
96 external getlink
: opaque
-> int -> under
= "ml_getlink";;
97 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
98 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
99 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
100 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
102 let platform_to_string = function
103 | Punknown
-> "unknown"
107 | Pfreebsd
-> "FreeBSD"
108 | Pdragonflybsd
-> "DragonflyBSD"
109 | Popenbsd
-> "OpenBSD"
110 | Pnetbsd
-> "NetBSD"
111 | Pcygwin
-> "Cygwin"
114 let platform = platform ();;
117 if platform = Pcygwin
119 let sh = "/bin/sh" in
120 let args = [|sh; "-c"; cmd
|] in
121 let rec std si so se
= function
123 | (fd
, 0) :: rest
-> std fd so se rest
124 | (fd
, -1) :: rest
->
125 Unix.set_close_on_exec fd
;
128 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
130 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
131 ignore
(Unix.create_process
sh args si so se
)
140 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
143 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
145 type mpos
= int * int
147 | Msel
of (mpos
* mpos
)
149 | Mscrolly
| Mscrollx
150 | Mzoom
of (int * int)
151 | Mzoomrect
of (mpos
* mpos
)
155 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
156 and onkey
= string -> int -> te
157 and ondone
= string -> unit
158 and histcancel
= unit -> unit
159 and onhist
= ((histcmd
-> string) * histcancel
)
160 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
161 and cancelonempty
= bool
166 | TEswitch
of textentry
177 let bound v minv maxv
=
178 max minv
(min maxv v
);
182 { store
= Array.create n v
189 let drawstring size x y s
=
191 Gl.enable `texture_2d
;
192 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
193 ignore
(drawstr size x y s
);
195 Gl.disable `texture_2d
;
198 let drawstring1 size x y s
=
202 let drawstring2 size x y fmt
=
203 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
206 let cbcap b
= Array.length b
.store
;;
211 b
.wc
<- (b
.wc
+ 1) mod cap;
213 b
.len
<- min
(b
.len
+ 1) cap;
216 let cbempty b
= b
.len
= 0;;
218 let cbgetg b circular dir
=
222 let rc = b
.rc + dir
in
234 else max
0 (min
rc (b
.len
-1))
240 let cbget b
= cbgetg b
false;;
241 let cbgetc b
= cbgetg b
true;;
259 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
260 dolog " WxH %dx%d" l
.pagew l
.pageh
;
261 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
262 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
263 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
264 dolog " column %d" l
.pagecol
;
268 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
270 dolog " x0,y0=(% f, % f)" x0 y0
;
271 dolog " x1,y1=(% f, % f)" x1 y1
;
272 dolog " x2,y2=(% f, % f)" x2 y2
;
273 dolog " x3,y3=(% f, % f)" x3 y3
;
277 type multicolumns
= multicol
* pagegeom
278 and singlecolumn
= pagegeom
279 and splitcolumns
= columncount
* pagegeom
280 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
281 and multicol
= columncount
* covercount
* covercount
283 and columncount
= int
284 and covercount
= int;;
287 { mutable scrollbw
: int
288 ; mutable scrollh
: int
289 ; mutable icase
: bool
290 ; mutable preload
: bool
291 ; mutable pagebias
: int
292 ; mutable verbose
: bool
293 ; mutable debug
: bool
294 ; mutable scrollstep
: int
295 ; mutable hscrollstep
: int
296 ; mutable maxhfit
: bool
297 ; mutable crophack
: bool
298 ; mutable autoscrollstep
: int
299 ; mutable maxwait
: float option
300 ; mutable hlinks
: bool
301 ; mutable underinfo
: bool
302 ; mutable interpagespace
: interpagespace
303 ; mutable zoom
: float
304 ; mutable presentation
: bool
305 ; mutable angle
: angle
308 ; mutable savebmarks
: bool
309 ; mutable proportional
: proportional
310 ; mutable trimmargins
: trimmargins
311 ; mutable trimfuzz
: irect
312 ; mutable memlimit
: memsize
313 ; mutable texcount
: texcount
314 ; mutable sliceheight
: sliceheight
315 ; mutable thumbw
: width
316 ; mutable jumpback
: bool
317 ; mutable bgcolor
: float * float * float
318 ; mutable bedefault
: bool
319 ; mutable scrollbarinpm
: bool
320 ; mutable tilew
: int
321 ; mutable tileh
: int
322 ; mutable mustoresize
: memsize
323 ; mutable checkers
: bool
324 ; mutable aalevel
: int
325 ; mutable urilauncher
: string
326 ; mutable pathlauncher
: string
327 ; mutable colorspace
: colorspace
328 ; mutable invert
: bool
329 ; mutable colorscale
: float
330 ; mutable redirectstderr
: bool
331 ; mutable ghyllscroll
: (int * int * int) option
332 ; mutable columns
: columns
333 ; mutable beyecolumns
: columncount
option
334 ; mutable selcmd
: string
335 ; mutable updatecurs
: bool
336 ; mutable keyhashes
: (string * keyhash
) list
337 ; mutable hfsize
: int
338 ; mutable pgscale
: float
339 ; mutable multicenter
: bool
342 | Csingle
of singlecolumn
343 | Cmulti
of multicolumns
344 | Csplit
of splitcolumns
347 type anchor
= pageno
* top
* dtop
;;
349 type outline
= string * int * anchor
;;
351 type rect
= float * float * float * float * float * float * float * float;;
353 type tile
= opaque
* pixmapsize
* elapsed
354 and elapsed
= float;;
355 type pagemapkey
= pageno
* gen
;;
356 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
360 let emptyanchor = (0, 0.0, 0.0);;
362 type infochange
= | Memused
| Docinfo
| Pdim
;;
364 class type uioh
= object
365 method display
: unit
366 method key
: int -> int -> uioh
367 method button
: int -> bool -> int -> int -> int -> uioh
368 method motion
: int -> int -> uioh
369 method pmotion
: int -> int -> uioh
370 method infochanged
: infochange
-> unit
371 method scrollpw
: (int * float * float)
372 method scrollph
: (int * float * float)
373 method modehash
: keyhash
377 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
378 | Textentry
of (textentry
* onleave
)
380 | LinkNav
of linktarget
381 and onleave
= leavetextentrystatus
-> unit
382 and leavetextentrystatus
= | Cancel
| Confirm
383 and helpitem
= string * int * action
386 | Action
of (uioh
-> uioh
)
388 | Ltexact
of (pageno
* int)
392 let isbirdseye = function Birdseye _
-> true | _
-> false;;
393 let istextentry = function Textentry _
-> true | _
-> false;;
397 | Loading
of (page
* gen
)
399 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
401 | Outlining
of outline list
404 let emptykeyhash = Hashtbl.create
0;;
405 let nouioh : uioh
= object (self
)
407 method key _ _
= self
408 method button _ _ _ _ _
= self
409 method motion _ _
= self
410 method pmotion _ _
= self
411 method infochanged _
= ()
412 method scrollpw
= (0, nan
, nan
)
413 method scrollph
= (0, nan
, nan
)
414 method modehash
= emptykeyhash
418 { mutable sr
: Unix.file_descr
419 ; mutable sw
: Unix.file_descr
420 ; mutable wsfd
: Unix.file_descr
421 ; mutable errfd
: Unix.file_descr
option
422 ; mutable stderr
: Unix.file_descr
423 ; mutable errmsgs
: Buffer.t
424 ; mutable newerrmsgs
: bool
428 ; mutable scrollw
: int
429 ; mutable hscrollh
: int
430 ; mutable anchor
: anchor
431 ; mutable ranchors
: (string * string * anchor
) list
433 ; mutable layout
: page list
434 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
435 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
436 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
437 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
438 ; mutable pagecount
: int
439 ; mutable currently
: currently
440 ; mutable mstate
: mstate
441 ; mutable searchpattern
: string
442 ; mutable rects
: (pageno
* recttype
* rect
) list
443 ; mutable rects1
: (pageno
* recttype
* rect
) list
444 ; mutable text
: string
445 ; mutable fullscreen
: (width
* height
) option
446 ; mutable mode
: mode
447 ; mutable uioh
: uioh
448 ; mutable outlines
: outline array
449 ; mutable bookmarks
: outline list
450 ; mutable path
: string
451 ; mutable password
: string
452 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
453 ; mutable memused
: memsize
455 ; mutable throttle
: (page list
* int * float) option
456 ; mutable autoscroll
: int option
457 ; mutable ghyll
: (int option -> unit)
458 ; mutable help
: helpitem array
459 ; mutable docinfo
: (int * string) list
460 ; mutable texid
: GlTex.texture_id
option
462 ; mutable prevzoom
: float
463 ; mutable progress
: float
464 ; mutable redisplay
: bool
465 ; mutable mpos
: mpos
466 ; mutable keystate
: keystate
467 ; mutable glinks
: bool
468 ; mutable prevcolumns
: (columns
* float) option
471 { pat
: string circbuf
472 ; pag
: string circbuf
473 ; nav
: anchor circbuf
474 ; sel
: string circbuf
496 ; presentation
= false
501 ; proportional
= true
502 ; trimmargins
= false
503 ; trimfuzz
= (0,0,0,0)
504 ; memlimit
= 32 lsl 20
509 ; bgcolor
= (0.5, 0.5, 0.5)
511 ; scrollbarinpm
= true
514 ; mustoresize
= 256 lsl 20
519 | Plinux
| Pfreebsd
| Pdragonflybsd
520 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
521 | Posx
-> "open \"%s\""
522 | Pcygwin
-> "cygstart \"%s\""
523 | Punknown
-> "echo %s")
524 ; pathlauncher
= "lp \"%s\""
527 | Plinux
| Pfreebsd
| Pdragonflybsd
528 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
535 ; redirectstderr
= false
537 ; columns
= Csingle
[||]
542 ; multicenter
= false
544 let mk n
= (n
, Hashtbl.create
1) in
558 let findkeyhash c name
=
559 try List.assoc name c
.keyhashes
560 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
563 let conf = { defconf with angle
= defconf.angle
};;
565 let pgscale h
= truncate
(float h
*. conf.pgscale);;
568 { mutable fontsize
: int
569 ; mutable wwidth
: float
570 ; mutable maxrows
: int
582 fstate.fontsize
<- n
;
583 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
584 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
588 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
589 let len = String.length s
in
590 if colonpos >= 0 && colonpos + 3 < len
592 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
595 try String.rindex_from s
colonpos ' '
599 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
602 | "http" | "ftp" | "mailto" ->
604 try String.index_from s
colonpos ' '
605 with Not_found
-> len
607 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
615 if String.length
conf.urilauncher
= 0
616 then print_endline uri
618 let url = geturl uri
in
619 if String.length
url = 0
620 then print_endline uri
622 let re = Str.regexp
"%s" in
623 let command = Str.global_replace
re url conf.urilauncher
in
627 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
633 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
634 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
638 let strings = version () :: "" :: Help.keys
in
641 let url = geturl s
in
642 if String.length
url > 0
643 then (s
, 0, Action
(fun u
-> gotouri url; u
))
644 else (s
, 0, Noaction
)
649 let firstgeomcmds = "", [];;
656 ; stderr
= Unix.stderr
657 ; errmsgs
= Buffer.create
0
664 ; anchor
= emptyanchor
668 ; tilelru
= Queue.create
()
669 ; pagemap
= Hashtbl.create
10
670 ; tilemap
= Hashtbl.create
10
685 ; geomcmds
= firstgeomcmds
687 { nav
= cbnew 10 emptyanchor
714 Printf.kprintf prerr_endline fmt
716 Printf.kprintf ignore fmt
720 if String.length
conf.pathlauncher
= 0
721 then print_endline
state.path
723 let re = Str.regexp
"%s" in
724 let command = Str.global_replace
re state.path
conf.pathlauncher
in
728 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
734 type 'a t
= | Res
of 'a
| Exn
of exn
;;
737 try Res
(Unix.pipe ())
743 with exn
-> f
(Printexc.to_string exn
)
747 try Res
(Unix.dup fd
)
752 try Res
(Unix.dup2 fd1 fd2
)
757 let redirectstderr () =
758 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
759 if conf.redirectstderr
761 match Ne.pipe () with
763 dolog "failed to create stderr redirection pipes: %s"
764 (Printexc.to_string exn
)
767 begin match Ne.dup Unix.stderr
with
769 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
770 Ne.clo r
(clofail "pipe/r");
771 Ne.clo w
(clofail "pipe/w");
773 | Ne.Res dupstderr
->
774 begin match Ne.dup2 w
Unix.stderr
with
776 dolog "failed to dup2 to stderr: %s"
777 (Printexc.to_string exn
);
778 Ne.clo dupstderr
(clofail "stderr duplicate");
779 Ne.clo r
(clofail "redir pipe/r");
780 Ne.clo w
(clofail "redir pipe/w");
783 state.stderr
<- dupstderr
;
784 state.errfd
<- Some r
;
788 state.newerrmsgs
<- false;
789 begin match state.errfd
with
791 begin match Ne.dup2 state.stderr
Unix.stderr
with
793 dolog "failed to dup2 original stderr: %s"
794 (Printexc.to_string exn
)
796 Ne.clo fd
(clofail "dup of stderr");
797 Unix.dup2 state.stderr
Unix.stderr
;
802 prerr_string
(Buffer.contents
state.errmsgs
);
804 Buffer.clear
state.errmsgs
;
810 let postRedisplay who
=
812 then prerr_endline
("redisplay for " ^ who
);
813 state.redisplay
<- true;
817 let getopaque pageno
=
818 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
819 with Not_found
-> None
822 let putopaque pageno opaque
=
823 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
826 let pagetranslatepoint l x y
=
827 let dy = y
- l
.pagedispy
in
828 let y = dy + l
.pagey
in
829 let dx = x
- l
.pagedispx
in
830 let x = dx + l
.pagex
in
837 begin match getopaque l
.pageno
with
839 let x0 = l
.pagedispx
in
840 let x1 = x0 + l
.pagevw
in
841 let y0 = l
.pagedispy
in
842 let y1 = y0 + l
.pagevh
in
843 if y >= y0 && y <= y1 && x >= x0 && x <= x1
845 let px, py
= pagetranslatepoint l
x y in
846 match whatsunder opaque
px py
with
859 state.text
<- Printf.sprintf
"%c%s" c s
;
860 G.postRedisplay "showtext";
863 let undertext = function
866 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
867 | Utext s
-> "font: " ^ s
868 | Uunexpected s
-> "unexpected: " ^ s
869 | Ulaunch s
-> "launch: " ^ s
870 | Unamed s
-> "named: " ^ s
871 | Uremote
(filename
, pageno
) ->
872 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
875 let updateunder x y =
876 match getunder x y with
877 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
879 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
880 Wsi.setcursor
Wsi.CURSOR_INFO
881 | Ulinkgoto
(pageno
, _
) ->
883 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
884 Wsi.setcursor
Wsi.CURSOR_INFO
886 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
887 Wsi.setcursor
Wsi.CURSOR_TEXT
889 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
890 Wsi.setcursor
Wsi.CURSOR_INHERIT
892 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
893 Wsi.setcursor
Wsi.CURSOR_INHERIT
895 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
896 Wsi.setcursor
Wsi.CURSOR_INHERIT
897 | Uremote
(filename
, pageno
) ->
898 if conf.underinfo
then showtext 'r'
899 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
900 Wsi.setcursor
Wsi.CURSOR_INFO
903 let showlinktype under
=
909 let s = undertext under
in
914 let b = Buffer.create
(String.length
s + 1) in
915 Buffer.add_string
b s;
920 let colorspace_of_string s =
921 match String.lowercase
s with
925 | _
-> failwith
"invalid colorspace"
928 let int_of_colorspace = function
934 let colorspace_of_int = function
938 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
941 let colorspace_to_string = function
947 let intentry_with_suffix text key
=
949 if key
>= 32 && key
< 127
953 match Char.lowercase
c with
955 let text = addchar text c in
959 let text = addchar text c in
963 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
967 let multicolumns_to_string (n
, a
, b) =
969 then Printf.sprintf
"%d" n
970 else Printf.sprintf
"%d,%d,%d" n a
b;
973 let multicolumns_of_string s =
975 (int_of_string
s, 0, 0)
977 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
979 then failwith
"subtly broken"; (n
, a
, b)
985 let n = Unix.read fd
s 0 4 in
986 if n != 4 then failwith
"incomplete read(len)";
988 lor (Char.code
s.[0] lsl 24)
989 lor (Char.code
s.[1] lsl 16)
990 lor (Char.code
s.[2] lsl 8)
991 lor (Char.code
s.[3] lsl 0)
993 let s = String.create
len in
994 let n = Unix.read fd
s 0 len in
995 if n != len then failwith
"incomplete read(data)";
999 let btod b = if b then 1 else 0;;
1002 let b = Buffer.create
16 in
1003 Buffer.add_string
b "llll";
1006 let s = Buffer.contents
b in
1007 let n = String.length
s in
1009 (* dolog "wcmd %S" (String.sub s 4 len); *)
1010 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1011 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1012 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1013 s.[3] <- Char.chr
(len land 0xff);
1014 let n'
= Unix.write
state.sw
s 0 n in
1015 if n'
!= n then failwith
"write failed";
1020 if conf.presentation
1022 let d = conf.winh
- h
in
1023 max
conf.interpagespace
((d + 1) / 2)
1029 match conf.columns
with
1030 | Cmulti
((c, _
, _
), b) ->
1031 let rec loop y h
n =
1035 if n = Array.length
b
1038 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
1044 loop max_int
0 (((Array.length
b - 1) / c) * c)
1046 if Array.length
b > 0
1048 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1049 y + h
+ (if conf.presentation
then calcips h
else 0)
1052 if Array.length
b > 0
1054 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1059 let getpageyh pageno
=
1060 let pageno = bound pageno 0 (state.pagecount
-1) in
1061 match conf.columns
with
1063 let (_
, _
, y, (_
, _
, h
, _
)) = b.(pageno) in
1065 if conf.presentation
1071 let (_
, _
, y, (_
, _
, h
, _
)) = b.(pageno) in
1075 let (_
, _
, y, (_
, _
, h
, _
)) = b.(n) in
1079 let getpagedim pageno =
1082 | (n, _
, _
, _
) as pdim
:: rest
->
1084 then (if n = pageno then pdim
else ppdim
)
1089 f (-1, -1, -1, -1) state.pdims
1092 let getpagey pageno = fst
(getpageyh pageno);;
1094 let nogeomcmds cmds
=
1096 | s, [] -> String.length
s = 0
1100 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1101 let sh = sh - state.hscrollh
in
1102 let rec fold accu
n =
1103 if n = Array.length
b
1106 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
1109 || n = state.pagecount
- coverB
1110 || (n - coverA
) mod columns
= columns
- 1)
1116 let pagey = max
0 (y - vy
) in
1117 let pagedispy = if pagey > 0 then 0 else vy
- y in
1118 let pagedispx, pagex
=
1120 if n = coverA
- 1 || n = state.pagecount
- coverB
1121 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1122 else dx + xoff
+ state.x
1129 let vw = conf.winw
- state.scrollw
- pagedispx in
1130 let pw = w
- pagex
in
1133 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1134 if pagevw > 0 && pagevh > 0
1138 ; pagedimno
= pdimno
1145 ; pagedispx = pagedispx
1146 ; pagedispy = pagedispy
1158 List.rev
(fold [] 0)
1161 let layoutS (columns
, b) y sh =
1162 let sh = sh - state.hscrollh
in
1163 let rec fold accu n =
1164 if n = Array.length
b
1167 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
1174 let x = xoff
+ state.x in
1175 let pagey = max
0 (y - vy
) in
1176 let pagedispy = if pagey > 0 then 0 else vy
- y in
1177 let pagedispx, pagex
=
1191 let pagecolw = pagew
/columns
in
1193 if pagecolw < conf.winw
1194 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1198 let vw = conf.winw
- pagedispx - state.scrollw
in
1199 let pw = pagew
- pagex
in
1202 let pagevw = min
pagevw pagecolw in
1203 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1204 if pagevw > 0 && pagevh > 0
1207 { pageno = n/columns
1208 ; pagedimno
= pdimno
1215 ; pagedispx = pagedispx
1216 ; pagedispy = pagedispy
1217 ; pagecol
= n mod columns
1228 List.rev
(fold [] 0)
1232 if nogeomcmds state.geomcmds
1234 match conf.columns
with
1235 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1236 | Cmulti
c -> layoutN c y sh
1237 | Csplit
s -> layoutS s y sh
1242 let y = state.y + incr
in
1244 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1249 let tilex = l
.pagex
mod conf.tilew
in
1250 let tiley = l
.pagey mod conf.tileh
in
1252 let col = l
.pagex
/ conf.tilew
in
1253 let row = l
.pagey / conf.tileh
in
1255 let rec rowloop row y0 dispy h
=
1259 let dh = conf.tileh
- y0 in
1260 let dh = min h
dh in
1261 let rec colloop col x0 dispx w
=
1265 let dw = conf.tilew
- x0 in
1266 let dw = min w
dw in
1268 f col row dispx dispy
x0 y0 dw dh;
1269 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1272 colloop col tilex l
.pagedispx l
.pagevw;
1273 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1276 if l
.pagevw > 0 && l
.pagevh > 0
1277 then rowloop row tiley l
.pagedispy l
.pagevh;
1280 let gettileopaque l
col row =
1282 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1284 try Some
(Hashtbl.find
state.tilemap
key)
1285 with Not_found
-> None
1288 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1289 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1290 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1293 let drawtiles l color
=
1295 let f col row x y tilex tiley w h
=
1296 match gettileopaque l
col row with
1297 | Some
(opaque
, _
, t
) ->
1298 let params = x, y, w
, h
, tilex, tiley in
1302 GlFunc.blend_func `zero `one_minus_src_color
;
1304 drawtile
params opaque
;
1306 then Gl.disable `blend
;
1309 let s = Printf.sprintf
1313 let w = measurestr
fstate.fontsize
s in
1314 GlMisc.push_attrib
[`current
];
1315 GlDraw.color
(0.0, 0.0, 0.0);
1317 (float (x-2), float (y-2))
1318 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1319 GlDraw.color
(1.0, 1.0, 1.0);
1320 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1321 GlMisc.pop_attrib
();
1326 let lw = conf.winw
- state.scrollw
- x in
1329 let lh = conf.winh
- y in
1332 begin match state.texid
with
1334 Gl.enable `texture_2d
;
1335 GlTex.bind_texture `texture_2d id
;
1338 and x1 = float (x+w)
1339 and y1 = float (y+h
) in
1341 let tw = float w /. 64.0
1342 and th
= float h
/. 64.0 in
1343 let tx0 = float tilex /. 64.0
1344 and ty0
= float tiley /. 64.0 in
1346 and ty1
= ty0
+. th
in
1347 GlDraw.begins `quads
;
1348 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1349 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1350 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1351 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1354 Gl.disable `texture_2d
;
1356 GlDraw.color
(1.0, 1.0, 1.0);
1359 (float (x+w), float (y+h
));
1361 if w > 128 && h
> fstate.fontsize
+ 10
1363 GlDraw.color
(0.0, 0.0, 0.0);
1366 then (col*conf.tilew
, row*conf.tileh
)
1369 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r
;
1376 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1378 let tilevisible1 l
x y =
1380 and ax1
= l
.pagex
+ l
.pagevw
1382 and ay1
= l
.pagey + l
.pagevh in
1386 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1387 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1389 let rx0 = max
ax0 bx0
1390 and ry0
= max ay0 by0
1391 and rx1
= min ax1
bx1
1392 and ry1
= min ay1 by1
in
1394 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1395 nonemptyintersection
1398 let tilevisible layout n x y =
1399 let rec findpageinlayout m
= function
1400 | l
:: rest
when l
.pageno = n ->
1401 tilevisible1 l
x y || (
1402 match conf.columns
with
1403 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1406 | _
:: rest
-> findpageinlayout 0 rest
1409 findpageinlayout 0 layout;
1412 let tileready l
x y =
1413 tilevisible1 l
x y &&
1414 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1417 let tilepage n p
layout =
1418 let rec loop = function
1422 let f col row _ _ _ _ _ _
=
1423 if state.currently
= Idle
1425 match gettileopaque l
col row with
1428 let x = col*conf.tilew
1429 and y = row*conf.tileh
in
1431 let w = l
.pagew
- x in
1435 let h = l
.pageh
- y in
1438 wcmd "tile %s %d %d %d %d" p
x y w h;
1441 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1442 conf.tilew
, conf.tileh
1451 if nogeomcmds state.geomcmds
1457 match conf.columns
with
1459 | Cmulti
(_
, b) -> b
1460 | Csplit
(_
, b) -> b
1462 let rec bsearch nmin nmax
=
1466 let n = (nmax
+ nmin
) / 2 in
1467 let _, _, vy
, (_, h, _, _) = b.(n) in
1469 if conf.presentation
1471 let ips = calcips h in
1472 let y0 = vy
- ips in
1473 let y1 = vy
+ h + ips in
1477 then 0, vy
+ h + conf.interpagespace
1479 let y0 = vy
- conf.interpagespace
in
1483 if y >= y0 && y < y1
1487 then bsearch (n+1) nmax
1488 else bsearch nmin
(n-1)
1491 let r = bsearch 0 (state.pagecount
-1) in
1495 let preloadlayout y =
1496 let y = if y < conf.winh
then 0 else y - conf.winh
in
1497 let h = conf.winh
*3 in
1502 let rec loop pages
=
1503 if state.currently
!= Idle
1508 begin match getopaque l
.pageno with
1510 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1511 state.currently
<- Loading
(l
, state.gen
);
1513 tilepage l
.pageno opaque pages
;
1518 if nogeomcmds state.geomcmds
1524 if conf.preload && state.currently
= Idle
1525 then load (preloadlayout state.y);
1528 let layoutready layout =
1529 let rec fold all ls
=
1530 all
&& match ls
with
1532 let seen = ref false in
1533 let allvisible = ref true in
1534 let foo col row _ _ _ _ _ _ =
1536 allvisible := !allvisible &&
1537 begin match gettileopaque l
col row with
1543 fold (!seen && !allvisible) rest
1546 let alltilesvisible = fold true layout in
1551 let y = bound y 0 state.maxy
in
1552 let y, layout, proceed
=
1553 match conf.maxwait
with
1554 | Some time
when state.ghyll
== noghyll ->
1555 begin match state.throttle
with
1557 let layout = layout y conf.winh
in
1558 let ready = layoutready layout in
1562 state.throttle
<- Some
(layout, y, now ());
1564 else G.postRedisplay "gotoy showall (None)";
1566 | Some
(_, _, started
) ->
1567 let dt = now () -. started
in
1570 state.throttle
<- None
;
1571 let layout = layout y conf.winh
in
1573 G.postRedisplay "maxwait";
1580 let layout = layout y conf.winh
in
1581 if true || layoutready layout
1582 then G.postRedisplay "gotoy ready";
1588 state.layout <- layout;
1589 begin match state.mode
with
1590 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1591 let rec loop = function
1593 state.mode
<- LinkNav
(Ltgendir
0)
1594 | l
:: _ when l
.pageno = pageno ->
1595 begin match getopaque pageno with
1597 state.mode
<- LinkNav
(Ltgendir
0)
1599 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1600 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1601 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1602 then state.mode
<- LinkNav
(Ltgendir
0)
1604 | _ :: rest
-> loop rest
1609 begin match state.mode
with
1610 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1611 if not
(pagevisible layout pageno)
1613 match state.layout with
1616 state.mode
<- Birdseye
(
1617 conf, leftx
, l
.pageno, hooverpageno
, anchor
1620 | LinkNav
(Ltgendir dir
as lt
) ->
1622 let rec loop = function
1625 match getopaque l
.pageno with
1631 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1633 if dir
> 0 then LDfirst
else LDlast
1639 | Lnotfound
-> loop rest
1641 showlinktype (getlink opaque
n);
1642 Ltexact
(l
.pageno, n)
1646 state.mode
<- LinkNav
linknav
1651 state.ghyll
<- noghyll;
1654 let mx, my
= state.mpos
in
1659 let conttiling pageno opaque
=
1660 tilepage pageno opaque
1661 (if conf.preload then preloadlayout state.y else state.layout)
1664 let gotoy_and_clear_text y =
1665 if not
conf.verbose
then state.text <- "";
1671 let coloff = l
.pagecol
* l
.pageh
in
1672 float (l
.pagey + coloff) /. float l
.pageh
1679 if conf.presentation
1680 then float l
.pagedispy /. float (calcips l
.pageh
)
1681 else float l
.pagedispy /. float conf.interpagespace
1683 (l
.pageno, top, dtop)
1687 match state.layout with
1688 | l
:: _ -> getanchor1 l
1690 let n = page_of_y state.y in
1691 let y, h = getpageyh n in
1692 let dy = y - state.y in
1694 if conf.presentation
1696 let ips = calcips h in
1697 float (dy + ips) /. float ips
1699 float dy /. float conf.interpagespace
1704 let getanchory (n, top, dtop) =
1705 let y, h = getpageyh n in
1706 if conf.presentation
1708 let ips = calcips h in
1709 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1711 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1714 let gotoanchor anchor
=
1715 gotoy (getanchory anchor
);
1719 cbput state.hists
.nav
(getanchor ());
1723 let anchor = cbgetc state.hists
.nav dir
in
1728 let scroll f n a
b =
1729 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1731 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1733 then s (float f /. float a
)
1736 then 1.0 -. s ((float (f-b) /. float (n-b)))
1743 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1744 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1746 let ins = float a
*. iv1
1747 and outs
= float (n-b) *. iv1 in
1749 ins +. outs
+. float ones
1751 let rec set (_N
, _A
, _B
) y sy
=
1752 let sum = summa
1.0 _N _A _B
in
1753 let dy = float (y - sy
) in
1757 then state.ghyll
<- noghyll
1760 let s = scroll n _N _A _B
in
1761 let y1 = y1 +. ((s *. dy) /. sum) in
1762 gotoy_and_clear_text (truncate
y1);
1763 state.ghyll
<- gf (n+1) y1;
1767 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1769 gf 0 (float state.y)
1772 match conf.ghyllscroll
with
1774 gotoy_and_clear_text y
1776 if state.ghyll
== noghyll
1777 then set nab
y state.y
1778 else state.ghyll
(Some
y)
1781 let gotopage n top =
1782 let y, h = getpageyh n in
1783 let y = y + (truncate
(top *. float h)) in
1787 let gotopage1 n top =
1788 let y = getpagey n in
1793 let invalidate s f =
1798 match state.geomcmds
with
1799 | ps
, [] when String.length ps
= 0 ->
1801 state.geomcmds
<- s, [];
1804 state.geomcmds
<- ps
, [s, f];
1806 | ps
, (s'
, _) :: rest
when s'
= s ->
1807 state.geomcmds
<- ps
, ((s, f) :: rest
);
1810 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1813 let opendoc path password
=
1815 state.password
<- password
;
1816 state.gen
<- state.gen
+ 1;
1817 state.docinfo
<- [];
1819 setaalevel
conf.aalevel
;
1820 Wsi.settitle
("llpp " ^
Filename.basename path
);
1821 wcmd "open %s\000%s\000" path password
;
1822 invalidate "reqlayout"
1824 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1828 let c = c *. conf.colorscale
in
1832 let scalecolor2 (r, g
, b) =
1833 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1836 let docolumns = function
1838 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1839 let rec loop pageno pdimno pdim
y ph pdims
=
1840 if pageno = state.pagecount
1843 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1845 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1846 pdimno+1, pdim
, rest
1850 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1852 (if conf.presentation
1853 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1854 else (if pageno = 0 then 0 else calcips h)
1857 a.(pageno) <- (pdimno, x, y, pdim
);
1858 loop (pageno+1) pdimno pdim
(y + h) h pdims
1860 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1861 conf.columns
<- Csingle
a;
1863 | Cmulti
((columns
, coverA
, coverB
), _) ->
1864 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1865 let rec loop pageno pdimno pdim
x y rowh pdims
=
1866 let rec fixrow m
= if m
= pageno then () else
1867 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1870 let y = y + (rowh
- h) / 2 in
1871 a.(m
) <- (pdimno, x, y, pdim
);
1875 if pageno = state.pagecount
1876 then fixrow (((pageno - 1) / columns
) * columns
)
1878 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1880 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1881 pdimno+1, pdim
, rest
1886 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1888 (conf.winw
- state.scrollw
- w) / 2,
1889 y + rowh
+ conf.interpagespace
, h
1892 if (pageno - coverA
) mod columns
= 0
1894 (if conf.multicenter
then
1895 (conf.winw
- state.scrollw
- state.w) / 2 else 0),
1896 y + rowh
+ (if pageno = 0 then 0 else conf.interpagespace
), h
1898 else x, y, max rowh
h
1901 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1902 then fixrow (pageno - columns
);
1903 a.(pageno) <- (pdimno, x, y, pdim
);
1904 let x = x + w + xoff
*2 + conf.interpagespace
in
1905 loop (pageno+1) pdimno pdim
x y rowh' pdims
1907 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1908 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1911 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1912 let rec loop pageno pdimno pdim
y pdims
=
1913 if pageno = state.pagecount
1916 let pdimno, ((_, w, h, _) as pdim
), pdims
=
1918 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1919 pdimno+1, pdim
, rest
1924 let rec loop1 n x y =
1925 if n = c then y else (
1926 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
1927 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
1930 let y = loop1 0 0 y in
1931 loop (pageno+1) pdimno pdim
y pdims
1933 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1934 conf.columns
<- Csplit
(c, a);
1938 docolumns conf.columns
;
1939 state.maxy
<- calcheight ();
1941 if state.w <= conf.winw
- state.scrollw
1945 match state.mode
with
1946 | Birdseye
(_, _, pageno, _, _) ->
1947 let y, h = getpageyh pageno in
1948 let top = (conf.winh
- h) / 2 in
1949 gotoy (max
0 (y - top))
1950 | _ -> gotoanchor state.anchor
1954 GlDraw.viewport
0 0 w h;
1955 let firsttime = state.geomcmds
== firstgeomcmds in
1956 if not
firsttime && nogeomcmds state.geomcmds
1957 then state.anchor <- getanchor ();
1960 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1963 setfontsize fstate.fontsize
;
1964 GlMat.mode `modelview
;
1965 GlMat.load_identity
();
1967 GlMat.mode `projection
;
1968 GlMat.load_identity
();
1969 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1970 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1971 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1976 else float state.x /. float state.w
1978 invalidate "geometry"
1982 then state.x <- truncate
(relx *. float w);
1984 match conf.columns
with
1986 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
1987 | Csplit
(c, _) -> w * c
1989 wcmd "geometry %d %d" w h);
1993 let len = String.length
state.text in
1996 match state.mode
with
1999 let h, _, _ = state.uioh#scrollpw
in
2005 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2006 (x+.w, float (conf.winh
- hscrollh))
2009 let w = float (conf.winw
- state.scrollw
- 1) in
2010 if state.progress
>= 0.0 && state.progress
< 1.0
2012 GlDraw.color
(0.3, 0.3, 0.3);
2013 let w1 = w *. state.progress
in
2015 GlDraw.color
(0.0, 0.0, 0.0);
2019 GlDraw.color
(0.0, 0.0, 0.0);
2023 GlDraw.color
(1.0, 1.0, 1.0);
2024 drawstring fstate.fontsize
2025 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2028 match state.mode
with
2029 | Textentry
((prefix
, text, _, _, _, _), _) ->
2033 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2035 Printf.sprintf
"%s%s_" prefix
text
2044 if not
(istextentry state.mode
)
2046 let s1 = "(press 'e' to review error messasges)" in
2047 if String.length
s > 0 then s ^
" " ^
s1 else s1
2052 if String.length
s > 0
2057 let len = Queue.length
state.tilelru
in
2059 match state.throttle
with
2062 then preloadlayout state.y
2064 | Some
(layout, _, _) ->
2068 if state.memused
<= conf.memlimit
2073 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2074 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2075 let (_, pw, ph
, _) = getpagedim n in
2078 && colorspace
= conf.colorspace
2079 && angle
= conf.angle
2083 let x = col*conf.tilew
2084 and y = row*conf.tileh
in
2085 tilevisible (Lazy.force_val
layout) n x y
2087 then Queue.push lruitem
state.tilelru
2089 wcmd "freetile %s" p
;
2090 state.memused
<- state.memused
- s;
2091 state.uioh#infochanged Memused
;
2092 Hashtbl.remove
state.tilemap k
;
2101 Queue.iter
(fun (k
, p
, s) ->
2102 wcmd "freetile %s" p
;
2103 state.memused
<- state.memused
- s;
2104 state.uioh#infochanged Memused
;
2105 Hashtbl.remove
state.tilemap k
;
2107 Queue.clear
state.tilelru
;
2111 let logcurrently = function
2112 | Idle
-> dolog "Idle"
2113 | Loading
(l
, gen
) ->
2114 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2115 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2117 "Tiling %d[%d,%d] page=%s cs=%s angle"
2118 l
.pageno col row pageopaque
2119 (colorspace_to_string colorspace
)
2121 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2122 angle gen
conf.angle
state.gen
2124 conf.tilew
conf.tileh
2131 (* dolog "%S" cmds; *)
2134 try String.index cmds ' '
2135 with Not_found
-> -1
2140 let l = String.length cmds
in
2141 let op = String.sub cmds
0 spacepos in
2143 if l - spacepos < 2 then ""
2144 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2149 state.uioh#infochanged Pdim
;
2153 state.rects
<- state.rects1
;
2154 G.postRedisplay "clearrects";
2158 try Scanf.sscanf
args "%u" (fun n -> n)
2160 dolog "error processing 'continue' %S: %s"
2161 cmds
(Printexc.to_string exn
);
2164 state.pagecount
<- n;
2165 begin match state.currently
with
2167 state.currently
<- Idle
;
2168 state.outlines
<- Array.of_list
(List.rev
l)
2172 let cur, cmds
= state.geomcmds
in
2173 if String.length
cur = 0
2174 then failwith
"umpossible";
2176 begin match List.rev cmds
with
2178 state.geomcmds
<- "", [];
2182 state.geomcmds
<- s, List.rev rest
;
2184 if conf.maxwait
= None
2185 then G.postRedisplay "continue";
2195 then showtext ' '
args
2198 let progress, text =
2200 Scanf.sscanf
args "%f %n"
2202 f, String.sub
args pos
(String.length
args - pos
))
2204 dolog "error processing 'progress' %S: %s"
2205 cmds
(Printexc.to_string exn
);
2209 state.progress <- progress;
2210 G.postRedisplay "progress"
2213 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2215 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2216 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2217 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2219 dolog "error processing 'firstmatch' %S: %s"
2220 cmds
(Printexc.to_string exn
);
2223 let y = (getpagey pageno) + truncate
y0 in
2226 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2229 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2231 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2232 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2233 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2235 dolog "error processing 'match' %S: %s"
2236 cmds
(Printexc.to_string exn
);
2240 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2245 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2247 dolog "error processing 'page' %S: %s"
2248 cmds
(Printexc.to_string exn
);
2251 begin match state.currently
with
2252 | Loading
(l, gen
) ->
2253 vlog "page %d took %f sec" l.pageno t
;
2254 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2255 begin match state.throttle
with
2257 let preloadedpages =
2259 then preloadlayout state.y
2264 Set.Make
(struct type t
= int let compare = (-) end) in
2266 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2267 IntSet.empty
preloadedpages
2270 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2271 if not
(IntSet.mem
pageno set)
2273 wcmd "freepage %s" opaque
;
2279 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2282 state.currently
<- Idle
;
2285 tilepage l.pageno pageopaque state.layout;
2287 load preloadedpages;
2288 if pagevisible state.layout l.pageno
2289 && layoutready state.layout
2290 then G.postRedisplay "page";
2293 | Some
(layout, _, _) ->
2294 state.currently
<- Idle
;
2295 tilepage l.pageno pageopaque layout;
2300 dolog "Inconsistent loading state";
2301 logcurrently state.currently
;
2306 let (x, y, opaque
, size
, t
) =
2308 Scanf.sscanf
args "%u %u %s %u %f"
2309 (fun x y p size t
-> (x, y, p
, size
, t
))
2311 dolog "error processing 'tile' %S: %s"
2312 cmds
(Printexc.to_string exn
);
2315 begin match state.currently
with
2316 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2317 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2319 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2321 wcmd "freetile %s" opaque
;
2322 state.currently
<- Idle
;
2326 puttileopaque l col row gen cs angle opaque size t
;
2327 state.memused
<- state.memused
+ size
;
2328 state.uioh#infochanged Memused
;
2330 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2331 opaque
, size
) state.tilelru
;
2334 match state.throttle
with
2335 | None
-> state.layout
2336 | Some
(layout, _, _) -> layout
2339 state.currently
<- Idle
;
2341 && conf.colorspace
= cs
2342 && conf.angle
= angle
2343 && tilevisible layout l.pageno x y
2344 then conttiling l.pageno pageopaque;
2346 begin match state.throttle
with
2348 preload state.layout;
2350 && conf.colorspace
= cs
2351 && conf.angle
= angle
2352 && tilevisible state.layout l.pageno x y
2353 then G.postRedisplay "tile nothrottle";
2355 | Some
(layout, y, _) ->
2356 let ready = layoutready layout in
2360 state.layout <- layout;
2361 state.throttle
<- None
;
2362 G.postRedisplay "throttle";
2369 dolog "Inconsistent tiling state";
2370 logcurrently state.currently
;
2377 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2379 dolog "error processing 'pdim' %S: %s"
2380 cmds
(Printexc.to_string exn
);
2383 state.uioh#infochanged Pdim
;
2384 state.pdims
<- pdim :: state.pdims
2387 let (l, n, t
, h, pos
) =
2389 Scanf.sscanf
args "%u %u %d %u %n"
2390 (fun l n t
h pos
-> l, n, t
, h, pos
)
2392 dolog "error processing 'o' %S: %s"
2393 cmds
(Printexc.to_string exn
);
2396 let s = String.sub
args pos
(String.length
args - pos
) in
2397 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2398 begin match state.currently
with
2399 | Outlining outlines
->
2400 state.currently
<- Outlining
(outline :: outlines
)
2402 state.currently
<- Outlining
[outline]
2404 dolog "invalid outlining state";
2405 logcurrently currently
2409 state.docinfo
<- (1, args) :: state.docinfo
2412 state.uioh#infochanged Docinfo
;
2413 state.docinfo
<- List.rev
state.docinfo
2416 dolog "unknown cmd `%S'" cmds
2421 let action = function
2422 | HCprev
-> cbget cb ~
-1
2423 | HCnext
-> cbget cb
1
2424 | HCfirst
-> cbget cb ~
-(cb
.rc)
2425 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2426 and cancel
() = cb
.rc <- rc
2430 let search pattern forward
=
2431 if String.length pattern
> 0
2434 match state.layout with
2437 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2439 wcmd "search %d %d %d %d,%s\000"
2440 (btod conf.icase
) pn py
(btod forward
) pattern
;
2443 let intentry text key =
2445 if key >= 32 && key < 127
2451 let text = addchar text c in
2455 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2459 let linknentry text key =
2461 if key >= 32 && key < 127
2467 let text = addchar text c in
2471 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2476 if String.length
s > 0
2479 let l = String.length
s in
2480 let rec loop pos
n = if pos
= l then n else
2481 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2482 loop (pos
+1) (n*26 + m)
2485 let rec loop n = function
2488 match getopaque l.pageno with
2489 | None
-> loop n rest
2491 let m = getlinkcount opaque
in
2494 let under = getlink opaque
n in
2497 else loop (n-m) rest
2499 loop n state.layout;
2503 let textentry text key =
2504 if key land 0xff00 = 0xff00
2506 else TEcont
(text ^
Wsi.toutf8
key)
2509 let reqlayout angle proportional
=
2510 match state.throttle
with
2512 if nogeomcmds state.geomcmds
2513 then state.anchor <- getanchor ();
2514 conf.angle
<- angle
mod 360;
2517 match state.mode
with
2518 | LinkNav
_ -> state.mode
<- View
2521 conf.proportional
<- proportional
;
2522 invalidate "reqlayout"
2523 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2527 let settrim trimmargins trimfuzz
=
2528 if nogeomcmds state.geomcmds
2529 then state.anchor <- getanchor ();
2530 conf.trimmargins
<- trimmargins
;
2531 conf.trimfuzz
<- trimfuzz
;
2532 let x0, y0, x1, y1 = trimfuzz
in
2533 invalidate "settrim"
2535 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2536 Hashtbl.iter
(fun _ opaque
->
2537 wcmd "freepage %s" opaque
;
2539 Hashtbl.clear
state.pagemap
;
2543 match state.throttle
with
2545 let zoom = max
0.01 zoom in
2546 if zoom <> conf.zoom
2548 state.prevzoom
<- conf.zoom;
2550 reshape conf.winw
conf.winh
;
2551 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2554 | Some
(layout, y, started
) ->
2556 match conf.maxwait
with
2560 let dt = now () -. started
in
2568 let setcolumns mode columns coverA coverB
=
2569 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2573 then showtext '
!'
"split mode doesn't work in bird's eye"
2575 conf.columns
<- Csplit
(-columns
, [||]);
2583 conf.columns
<- Csingle
[||];
2588 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2592 reshape conf.winw
conf.winh
;
2595 let enterbirdseye () =
2596 let zoom = float conf.thumbw
/. float conf.winw
in
2597 let birdseyepageno =
2598 let cy = conf.winh
/ 2 in
2602 let rec fold best
= function
2605 let d = cy - (l.pagedispy + l.pagevh/2)
2606 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2607 if abs
d < abs dbest
2614 state.mode
<- Birdseye
(
2615 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2618 conf.presentation
<- false;
2619 conf.interpagespace
<- 10;
2620 conf.hlinks
<- false;
2622 state.mstate
<- Mnone
;
2623 conf.maxwait
<- None
;
2625 match conf.beyecolumns
with
2628 Cmulti
((c, 0, 0), [||])
2629 | None
-> Csingle
[||]
2631 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2634 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2639 reshape conf.winw
conf.winh
;
2642 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2644 conf.zoom <- c.zoom;
2645 conf.presentation
<- c.presentation
;
2646 conf.interpagespace
<- c.interpagespace
;
2647 conf.maxwait
<- c.maxwait
;
2648 conf.hlinks
<- c.hlinks
;
2649 conf.beyecolumns
<- (
2650 match conf.columns
with
2651 | Cmulti
((c, _, _), _) -> Some
c
2653 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2656 match c.columns
with
2657 | Cmulti
(c, _) -> Cmulti
(c, [||])
2658 | Csingle
_ -> Csingle
[||]
2659 | Csplit
(c, _) -> Csplit
(c, [||])
2664 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2667 reshape conf.winw
conf.winh
;
2668 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2671 let togglebirdseye () =
2672 match state.mode
with
2673 | Birdseye vals
-> leavebirdseye vals
true
2674 | View
-> enterbirdseye ()
2678 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2679 let pageno = max
0 (pageno - incr
) in
2680 let rec loop = function
2681 | [] -> gotopage1 pageno 0
2682 | l :: _ when l.pageno = pageno ->
2683 if l.pagedispy >= 0 && l.pagey = 0
2684 then G.postRedisplay "upbirdseye"
2685 else gotopage1 pageno 0
2686 | _ :: rest
-> loop rest
2689 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2692 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2693 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2694 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2695 let rec loop = function
2697 let y, h = getpageyh pageno in
2698 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2700 | l :: _ when l.pageno = pageno ->
2701 if l.pagevh != l.pageh
2702 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2703 else G.postRedisplay "downbirdseye"
2704 | _ :: rest
-> loop rest
2709 let optentry mode
_ key =
2710 let btos b = if b then "on" else "off" in
2711 if key >= 32 && key < 127
2713 let c = Char.chr
key in
2717 try conf.scrollstep
<- int_of_string
s with exc
->
2718 state.text <- Printf.sprintf
"bad integer `%s': %s"
2719 s (Printexc.to_string exc
)
2721 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2726 conf.autoscrollstep
<- int_of_string
s;
2727 if state.autoscroll
<> None
2728 then state.autoscroll
<- Some
conf.autoscrollstep
2730 state.text <- Printf.sprintf
"bad integer `%s': %s"
2731 s (Printexc.to_string exc
)
2733 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2738 let n, a, b = multicolumns_of_string s in
2739 setcolumns mode
n a b;
2741 state.text <- Printf.sprintf
"bad columns `%s': %s"
2742 s (Printexc.to_string exc
)
2744 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2749 let zoom = float (int_of_string
s) /. 100.0 in
2752 state.text <- Printf.sprintf
"bad integer `%s': %s"
2753 s (Printexc.to_string exc
)
2755 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2760 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2762 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2763 begin match mode
with
2765 leavebirdseye beye
false;
2770 state.text <- Printf.sprintf
"bad integer `%s': %s"
2771 s (Printexc.to_string exc
)
2773 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2778 Some
(int_of_string
s)
2780 state.text <- Printf.sprintf
"bad integer `%s': %s"
2781 s (Printexc.to_string exc
);
2784 | Some angle
-> reqlayout angle
conf.proportional
2787 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2790 conf.icase
<- not
conf.icase
;
2791 TEdone
("case insensitive search " ^
(btos conf.icase
))
2794 conf.preload <- not
conf.preload;
2796 TEdone
("preload " ^
(btos conf.preload))
2799 conf.verbose
<- not
conf.verbose
;
2800 TEdone
("verbose " ^
(btos conf.verbose
))
2803 conf.debug
<- not
conf.debug
;
2804 TEdone
("debug " ^
(btos conf.debug
))
2807 conf.maxhfit
<- not
conf.maxhfit
;
2808 state.maxy
<- calcheight ();
2809 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2812 conf.crophack
<- not
conf.crophack
;
2813 TEdone
("crophack " ^
btos conf.crophack
)
2817 match conf.maxwait
with
2819 conf.maxwait
<- Some infinity
;
2820 "always wait for page to complete"
2822 conf.maxwait
<- None
;
2823 "show placeholder if page is not ready"
2828 conf.underinfo
<- not
conf.underinfo
;
2829 TEdone
("underinfo " ^
btos conf.underinfo
)
2832 conf.savebmarks
<- not
conf.savebmarks
;
2833 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2839 match state.layout with
2844 conf.interpagespace
<- int_of_string
s;
2845 docolumns conf.columns
;
2846 state.maxy
<- calcheight ();
2847 let y = getpagey pageno in
2850 state.text <- Printf.sprintf
"bad integer `%s': %s"
2851 s (Printexc.to_string exc
)
2853 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2856 reqlayout conf.angle
(not
conf.proportional
);
2857 TEdone
("proportional display " ^
btos conf.proportional
)
2860 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2861 TEdone
("trim margins " ^
btos conf.trimmargins
)
2864 conf.invert
<- not
conf.invert
;
2865 TEdone
("invert colors " ^
btos conf.invert
)
2869 cbput state.hists
.sel
s;
2872 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2873 textentry, ondone, true)
2876 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2882 class type lvsource
= object
2883 method getitemcount
: int
2884 method getitem
: int -> (string * int)
2885 method hasaction
: int -> bool
2894 method getactive
: int
2895 method getfirst
: int
2896 method getqsearch
: string
2897 method setqsearch
: string -> unit
2901 class virtual lvsourcebase
= object
2902 val mutable m_active
= 0
2903 val mutable m_first
= 0
2904 val mutable m_qsearch
= ""
2905 val mutable m_pan
= 0
2906 method getactive
= m_active
2907 method getfirst
= m_first
2908 method getqsearch
= m_qsearch
2909 method getpan
= m_pan
2910 method setqsearch
s = m_qsearch
<- s
2913 let withoutlastutf8 s =
2914 let len = String.length
s in
2922 let b = Char.code
s.[pos
] in
2923 if b land 0b110000 = 0b11000000
2928 if Char.code
s.[len-1] land 0x80 = 0
2932 String.sub
s 0 first;
2935 let textentrykeyboard
2936 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2938 state.mode
<- Textentry
(te
, onleave
);
2941 G.postRedisplay "textentrykeyboard enttext";
2943 let histaction cmd
=
2946 | Some
(action, _) ->
2947 state.mode
<- Textentry
(
2948 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2950 G.postRedisplay "textentry histaction"
2953 | 0xff08 -> (* backspace *)
2954 let s = withoutlastutf8 text in
2955 let len = String.length
s in
2956 if cancelonempty
&& len = 0
2959 G.postRedisplay "textentrykeyboard after cancel";
2962 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2968 G.postRedisplay "textentrykeyboard after confirm"
2970 | 0xff52 -> histaction HCprev
2971 | 0xff54 -> histaction HCnext
2972 | 0xff50 -> histaction HCfirst
2973 | 0xff57 -> histaction HClast
2975 | 0xff1b -> (* escape*)
2976 if String.length
text = 0
2978 begin match opthist
with
2980 | Some
(_, onhistcancel
) -> onhistcancel
()
2984 G.postRedisplay "textentrykeyboard after cancel2"
2987 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
2990 | 0xff9f | 0xffff -> () (* delete *)
2992 | _ when key != 0 && key land 0xff00 != 0xff00 ->
2993 begin match onkey
text key with
2997 G.postRedisplay "textentrykeyboard after confirm2";
3000 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3004 G.postRedisplay "textentrykeyboard after cancel3"
3007 state.mode
<- Textentry
(te
, onleave
);
3008 G.postRedisplay "textentrykeyboard switch";
3012 vlog "unhandled key %s" (Wsi.keyname
key)
3015 let firstof first active
=
3016 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3017 then max
0 (active
- (fstate.maxrows
/2))
3021 let calcfirst first active
=
3024 let rows = active
- first in
3025 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3029 let scrollph y maxy
=
3030 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3031 let sh = float conf.winh
/. sh in
3032 let sh = max
sh (float conf.scrollh
) in
3037 else float y /. float maxy
3039 let position = (float conf.winh
-. sh) *. percent in
3042 if position +. sh > float conf.winh
3043 then float conf.winh
-. sh
3049 let coe s = (s :> uioh
);;
3051 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3053 val m_pan
= source#getpan
3054 val m_first
= source#getfirst
3055 val m_active
= source#getactive
3056 val m_qsearch
= source#getqsearch
3057 val m_prev_uioh
= state.uioh
3059 method private elemunder
y =
3060 let n = y / (fstate.fontsize
+1) in
3061 if m_first
+ n < source#getitemcount
3063 if source#hasaction
(m_first
+ n)
3064 then Some
(m_first
+ n)
3071 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3072 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3073 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3074 GlDraw.color
(1., 1., 1.);
3075 Gl.enable `texture_2d
;
3076 let fs = fstate.fontsize
in
3078 let ww = fstate.wwidth
in
3079 let tabw = 30.0*.ww in
3080 let itemcount = source#getitemcount
in
3082 if (row - m_first
) * nfs > conf.winh
3085 if row >= 0 && row < itemcount
3087 let (s, level
) = source#getitem
row in
3088 let y = (row - m_first
) * nfs in
3089 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3092 Gl.disable `texture_2d
;
3093 GlDraw.polygon_mode `both `line
;
3094 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3095 GlDraw.rect (1., float (y + 1))
3096 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3097 GlDraw.polygon_mode `both `fill
;
3098 GlDraw.color
(1., 1., 1.);
3099 Gl.enable `texture_2d
;
3102 let drawtabularstring s =
3103 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3106 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3109 let len = String.length
s - tabpos - 1 in
3110 let s1 = String.sub
s 0 tabpos
3111 and s2
= String.sub
s (tabpos + 1) len in
3112 let nx = drawstr x s1 in
3114 let x = x +. (max
tabw sw) in
3121 let _ = drawtabularstring s in
3128 Gl.disable `texture_2d
;
3130 method updownlevel incr
=
3131 let len = source#getitemcount
in
3133 if m_active
>= 0 && m_active
< len
3134 then snd
(source#getitem m_active
)
3138 if i
= len then i
-1 else if i
= -1 then 0 else
3139 let _, l = source#getitem i
in
3140 if l != curlevel then i
else flow (i
+incr
)
3142 let active = flow m_active
in
3143 let first = calcfirst m_first
active in
3144 G.postRedisplay "outline updownlevel";
3145 {< m_active
= active; m_first
= first >}
3147 method private key1
key mask
=
3148 let set1 active first qsearch
=
3149 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3151 let search active pattern incr
=
3154 if n >= 0 && n < source#getitemcount
3156 let s, _ = source#getitem
n in
3158 (try ignore
(Str.search_forward
re s 0); true
3159 with Not_found
-> false)
3161 else loop (n + incr
)
3168 let re = Str.regexp_case_fold pattern
in
3174 let itemcount = source#getitemcount
in
3175 let find start incr
=
3177 if i
= -1 || i
= itemcount
3180 if source#hasaction i
3182 else find (i
+ incr
)
3187 let set active first =
3188 let first = bound first 0 (itemcount - fstate.maxrows
) in
3190 coe {< m_active
= active; m_first
= first >}
3193 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3195 let incr1 = if incr
> 0 then 1 else -1 in
3196 if isvisible m_first m_active
3199 let next = m_active
+ incr
in
3201 if next < 0 || next >= itemcount
3203 else find next incr1
3205 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3211 let first = m_first
+ incr
in
3212 let first = bound first 0 (itemcount - 1) in
3214 let next = m_active
+ incr
in
3215 let next = bound next 0 (itemcount - 1) in
3218 let active = if next = -1 then m_active
else next in
3221 let first = min
next m_first
in
3223 if abs
(next - first) > fstate.maxrows
3229 let first = m_first
+ incr
in
3230 let first = bound first 0 (itemcount - 1) in
3232 let next = m_active
+ incr
in
3233 let next = bound next 0 (itemcount - 1) in
3234 let next = find next incr1 in
3236 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3238 let active = if m_active
= -1 then next else m_active
in
3243 if isvisible first active
3249 G.postRedisplay "listview navigate";
3253 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3254 let incr = if key = 0x72 then -1 else 1 in
3256 match search (m_active
+ incr) m_qsearch
incr with
3258 state.text <- m_qsearch ^
" [not found]";
3261 state.text <- m_qsearch
;
3262 active, firstof m_first
active
3264 G.postRedisplay "listview ctrl-r/s";
3265 set1 active first m_qsearch
;
3267 | 0xff08 -> (* backspace *)
3268 if String.length m_qsearch
= 0
3271 let qsearch = withoutlastutf8 m_qsearch
in
3272 let len = String.length
qsearch in
3276 G.postRedisplay "listview empty qsearch";
3277 set1 m_active m_first
"";
3281 match search m_active
qsearch ~
-1 with
3283 state.text <- qsearch ^
" [not found]";
3286 state.text <- qsearch;
3287 active, firstof m_first
active
3289 G.postRedisplay "listview backspace qsearch";
3290 set1 active first qsearch
3293 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3294 let pattern = m_qsearch ^
Wsi.toutf8
key in
3296 match search m_active
pattern 1 with
3298 state.text <- pattern ^
" [not found]";
3301 state.text <- pattern;
3302 active, firstof m_first
active
3304 G.postRedisplay "listview qsearch add";
3305 set1 active first pattern;
3307 | 0xff1b -> (* escape *)
3309 if String.length m_qsearch
= 0
3311 G.postRedisplay "list view escape";
3314 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3316 | None
-> m_prev_uioh
3321 G.postRedisplay "list view kill qsearch";
3322 source#setqsearch
"";
3323 coe {< m_qsearch
= "" >}
3326 | 0xff0d -> (* return *)
3328 let self = {< m_qsearch
= "" >} in
3329 source#setqsearch
"";
3331 G.postRedisplay "listview enter";
3332 if m_active
>= 0 && m_active
< source#getitemcount
3334 source#exit
(coe self) false m_active m_first m_pan
"";
3337 source#exit
(coe self) true m_active m_first m_pan
"";
3340 begin match opt with
3341 | None
-> m_prev_uioh
3345 | 0xff9f | 0xffff -> (* delete *)
3348 | 0xff52 -> navigate ~
-1 (* up *)
3349 | 0xff54 -> navigate 1 (* down *)
3350 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3351 | 0xff56 -> navigate fstate.maxrows
(* next *)
3353 | 0xff53 -> (* right *)
3355 G.postRedisplay "listview right";
3356 coe {< m_pan
= m_pan
- 1 >}
3358 | 0xff51 -> (* left *)
3360 G.postRedisplay "listview left";
3361 coe {< m_pan
= m_pan
+ 1 >}
3363 | 0xff50 -> (* home *)
3364 let active = find 0 1 in
3365 G.postRedisplay "listview home";
3368 | 0xff57 -> (* end *)
3369 let first = max
0 (itemcount - fstate.maxrows
) in
3370 let active = find (itemcount - 1) ~
-1 in
3371 G.postRedisplay "listview end";
3374 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3378 dolog "listview unknown key %#x" key; coe self
3380 method key key mask
=
3381 match state.mode
with
3382 | Textentry te
-> textentrykeyboard key mask te
; coe self
3383 | _ -> self#key1
key mask
3385 method button button down
x y _ =
3388 | 1 when x > conf.winw
- conf.scrollbw
->
3389 G.postRedisplay "listview scroll";
3392 let _, position, sh = self#
scrollph in
3393 if y > truncate
position && y < truncate
(position +. sh)
3395 state.mstate
<- Mscrolly
;
3399 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3400 let first = truncate
(s *. float source#getitemcount
) in
3401 let first = min source#getitemcount
first in
3402 Some
(coe {< m_first
= first; m_active
= first >})
3404 state.mstate
<- Mnone
;
3407 | 1 when not down
->
3408 begin match self#elemunder
y with
3410 G.postRedisplay "listview click";
3412 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3416 | n when (n == 4 || n == 5) && not down
->
3417 let len = source#getitemcount
in
3419 if n = 5 && m_first
+ fstate.maxrows
>= len
3423 let first = m_first
+ (if n == 4 then -1 else 1) in
3424 bound first 0 (len - 1)
3426 G.postRedisplay "listview wheel";
3427 Some
(coe {< m_first
= first >})
3428 | n when (n = 6 || n = 7) && not down
->
3429 let inc = m_first
+ (if n = 7 then -1 else 1) in
3430 G.postRedisplay "listview hwheel";
3431 Some
(coe {< m_pan
= m_pan
+ inc >})
3436 | None
-> m_prev_uioh
3440 match state.mstate
with
3442 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3443 let first = truncate
(s *. float source#getitemcount
) in
3444 let first = min source#getitemcount
first in
3445 G.postRedisplay "listview motion";
3446 coe {< m_first
= first; m_active
= first >}
3449 method pmotion
x y =
3450 if x < conf.winw
- conf.scrollbw
3453 match self#elemunder
y with
3454 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3455 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3459 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3464 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3468 method infochanged
_ = ()
3470 method scrollpw
= (0, 0.0, 0.0)
3472 let nfs = fstate.fontsize
+ 1 in
3473 let y = m_first
* nfs in
3474 let itemcount = source#getitemcount
in
3475 let maxi = max
0 (itemcount - fstate.maxrows
) in
3476 let maxy = maxi * nfs in
3477 let p, h = scrollph y maxy in
3480 method modehash
= modehash
3483 class outlinelistview ~source
=
3486 ~source
:(source
:> lvsource
)
3488 ~modehash
:(findkeyhash conf "outline")
3491 method key key mask
=
3492 let calcfirst first active =
3495 let rows = active - first in
3497 if String.length
state.text = 0
3499 else fstate.maxrows - 2
3501 if rows > maxrows then active - maxrows else first
3505 let active = m_active
+ incr in
3506 let active = bound active 0 (source#getitemcount
- 1) in
3507 let first = calcfirst m_first
active in
3508 G.postRedisplay "outline navigate";
3509 coe {< m_active
= active; m_first
= first >}
3511 let ctrl = Wsi.withctrl mask
in
3513 | 110 when ctrl -> (* ctrl-n *)
3514 source#narrow m_qsearch
;
3515 G.postRedisplay "outline ctrl-n";
3516 coe {< m_first
= 0; m_active
= 0 >}
3518 | 117 when ctrl -> (* ctrl-u *)
3520 G.postRedisplay "outline ctrl-u";
3522 coe {< m_first
= 0; m_active
= 0 >}
3524 | 108 when ctrl -> (* ctrl-l *)
3525 let first = m_active
- (fstate.maxrows / 2) in
3526 G.postRedisplay "outline ctrl-l";
3527 coe {< m_first
= first >}
3529 | 0xff9f | 0xffff -> (* delete *)
3530 source#remove m_active
;
3531 G.postRedisplay "outline delete";
3532 let active = max
0 (m_active
-1) in
3533 coe {< m_first
= firstof m_first
active;
3534 m_active
= active >}
3536 | 0xff52 -> navigate ~
-1 (* up *)
3537 | 0xff54 -> navigate 1 (* down *)
3538 | 0xff55 -> (* prior *)
3539 navigate ~
-(fstate.maxrows)
3540 | 0xff56 -> (* next *)
3541 navigate fstate.maxrows
3543 | 0xff53 -> (* [ctrl-]right *)
3547 G.postRedisplay "outline ctrl right";
3548 {< m_pan
= m_pan
+ 1 >}
3550 else self#updownlevel
1
3554 | 0xff51 -> (* [ctrl-]left *)
3558 G.postRedisplay "outline ctrl left";
3559 {< m_pan
= m_pan
- 1 >}
3561 else self#updownlevel ~
-1
3565 | 0xff50 -> (* home *)
3566 G.postRedisplay "outline home";
3567 coe {< m_first
= 0; m_active
= 0 >}
3569 | 0xff57 -> (* end *)
3570 let active = source#getitemcount
- 1 in
3571 let first = max
0 (active - fstate.maxrows) in
3572 G.postRedisplay "outline end";
3573 coe {< m_active
= active; m_first
= first >}
3575 | _ -> super#
key key mask
3578 let outlinesource usebookmarks
=
3581 inherit lvsourcebase
3582 val mutable m_items
= empty
3583 val mutable m_orig_items
= empty
3584 val mutable m_prev_items
= empty
3585 val mutable m_narrow_pattern
= ""
3586 val mutable m_hadremovals
= false
3588 method getitemcount
=
3589 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3592 if n == Array.length m_items
&& m_hadremovals
3594 ("[Confirm removal]", 0)
3596 let s, n, _ = m_items
.(n) in
3599 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3600 ignore
(uioh
, first, qsearch);
3601 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3603 if String.length m_narrow_pattern
= 0
3609 if not
confrimremoval
3611 let _, _, anchor = m_items
.(active) in
3616 state.bookmarks
<- Array.to_list m_items
;
3617 m_orig_items
<- m_items
;
3620 else m_items
<- items;
3624 method hasaction
_ = true
3627 if Array.length m_items
!= Array.length m_orig_items
3628 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3631 method narrow
pattern =
3632 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3636 let rec loop accu n =
3639 m_narrow_pattern
<- pattern;
3640 m_items
<- Array.of_list
accu
3643 let (s, _, _) as o = m_items
.(n) in
3645 if (try ignore
(Str.search_forward
re s 0); true
3646 with Not_found
-> false)
3652 loop [] (Array.length m_items
- 1)
3657 then Array.of_list
state.bookmarks
3660 m_items
<- m_orig_items
3665 if m >= 0 && m < Array.length m_items
3667 m_hadremovals
<- true;
3668 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3669 let n = if n >= m then n+1 else n in
3674 method reset
anchor items =
3675 m_hadremovals
<- false;
3676 if m_orig_items
== empty || m_prev_items
!= items
3678 m_orig_items
<- items;
3679 if String.length m_narrow_pattern
= 0
3680 then m_items
<- items;
3682 m_prev_items
<- items;
3683 let rely = getanchory anchor in
3685 let rec loop n best bestd
=
3686 if n = Array.length m_items
3689 let (_, _, anchor) = m_items
.(n) in
3690 let orely = getanchory anchor in
3691 let d = abs
(orely - rely) in
3694 else loop (n+1) best bestd
3699 m_first
<- firstof m_first
active
3703 let enterselector usebookmarks
=
3704 let source = outlinesource usebookmarks
in
3708 then Array.of_list
state.bookmarks
3711 if Array.length
outlines = 0
3713 showtext ' ' errmsg
;
3716 state.text <- source#greetmsg
;
3717 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3718 let anchor = getanchor () in
3719 source#reset
anchor outlines;
3720 state.uioh
<- coe (new outlinelistview ~
source);
3721 G.postRedisplay "enter selector";
3725 let enteroutlinemode =
3726 let f = enterselector false in
3727 fun ()-> f "Document has no outline";
3730 let enterbookmarkmode =
3731 let f = enterselector true in
3732 fun () -> f "Document has no bookmarks (yet)";
3735 let color_of_string s =
3736 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3737 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3741 let color_to_string (r, g
, b) =
3742 let r = truncate
(r *. 256.0)
3743 and g
= truncate
(g
*. 256.0)
3744 and b = truncate
(b *. 256.0) in
3745 Printf.sprintf
"%d/%d/%d" r g
b
3748 let irect_of_string s =
3749 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3752 let irect_to_string (x0,y0,x1,y1) =
3753 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3756 let makecheckers () =
3757 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3759 converted by Issac Trotts. July 25, 2002 *)
3760 let image_height = 64
3761 and image_width
= 64 in
3765 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3767 for i
= 0 to image_width
- 1 do
3768 for j
= 0 to image_height - 1 do
3769 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3770 (if (i
land 8 ) lxor (j
land 8) = 0
3771 then [|255;255;255|] else [|200;200;200|])
3776 let image = make_image () in
3777 let id = GlTex.gen_texture
() in
3778 GlTex.bind_texture `texture_2d
id;
3779 GlPix.store
(`unpack_alignment
1);
3780 GlTex.image2d
image;
3781 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3784 `mag_filter `nearest
;
3785 `min_filter `nearest
];
3789 let setcheckers enabled
=
3790 match state.texid
with
3792 if enabled
then state.texid
<- Some
(makecheckers ())
3797 GlTex.delete_texture texid
;
3798 state.texid
<- None
;
3802 let int_of_string_with_suffix s =
3803 let l = String.length
s in
3807 let suffix = Char.lowercase
s.[l-1] in
3809 | 'k'
-> String.sub
s 0 (l-1), 10
3810 | '
m'
-> String.sub
s 0 (l-1), 20
3811 | 'g'
-> String.sub
s 0 (l-1), 30
3815 let n = int_of_string
s1 in
3816 let m = n lsl shift
in
3818 then raise
(Failure
"value too large")
3822 let string_with_suffix_of_int n =
3827 if n land ((1 lsl 20) - 1) = 0
3830 if n land ((1 lsl 10) - 1) = 0
3836 let h = n mod 1000 in
3839 then string_of_int
h ^
s
3841 let s = Printf.sprintf
"_%03d%s" h s in
3848 let defghyllscroll = (40, 8, 32);;
3849 let ghyllscroll_of_string s =
3850 let (n, a, b) as nab
=
3853 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3855 if n <= a || n <= b || a >= b
3856 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3860 let ghyllscroll_to_string ((n, a, b) as nab
) =
3861 if nab
= defghyllscroll
3863 else Printf.sprintf
"%d,%d,%d" n a b;
3866 let describe_location () =
3868 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3870 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3871 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3875 else (100. *. (float state.y /. float maxy))
3879 Printf.sprintf
"page %d of %d [%.2f%%]"
3880 (fn+1) state.pagecount
percent
3883 "pages %d-%d of %d [%.2f%%]"
3884 (fn+1) (ln
+1) state.pagecount
percent
3888 let btos b = if b then "\xe2\x88\x9a" else "" in
3889 let showextended = ref false in
3890 let leave mode
= function
3891 | Confirm
-> state.mode
<- mode
3892 | Cancel
-> state.mode
<- mode
in
3895 val mutable m_first_time
= true
3896 val mutable m_l
= []
3897 val mutable m_a
= [||]
3898 val mutable m_prev_uioh
= nouioh
3899 val mutable m_prev_mode
= View
3901 inherit lvsourcebase
3903 method reset prev_mode prev_uioh
=
3904 m_a
<- Array.of_list
(List.rev m_l
);
3906 m_prev_mode
<- prev_mode
;
3907 m_prev_uioh
<- prev_uioh
;
3911 if n >= Array.length m_a
3915 | _, _, _, Action
_ -> m_active
<- n
3919 m_first_time
<- false;
3922 method int name get
set =
3924 (name
, `
int get
, 1, Action
(
3927 try set (int_of_string
s)
3929 state.text <- Printf.sprintf
"bad integer `%s': %s"
3930 s (Printexc.to_string exn
)
3933 let te = name ^
": ", "", None
, intentry, ondone, true in
3934 state.mode
<- Textentry
(te, leave m_prev_mode
);
3938 method int_with_suffix name get
set =
3940 (name
, `intws get
, 1, Action
(
3943 try set (int_of_string_with_suffix s)
3945 state.text <- Printf.sprintf
"bad integer `%s': %s"
3946 s (Printexc.to_string exn
)
3950 name ^
": ", "", None
, intentry_with_suffix, ondone, true
3952 state.mode
<- Textentry
(te, leave m_prev_mode
);
3956 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3958 (name
, `
bool (btos, get
), offset
, Action
(
3965 method color name get
set =
3967 (name
, `color get
, 1, Action
(
3969 let invalid = (nan
, nan
, nan
) in
3972 try color_of_string s
3974 state.text <- Printf.sprintf
"bad color `%s': %s"
3975 s (Printexc.to_string exn
);
3981 let te = name ^
": ", "", None
, textentry, ondone, true in
3982 state.text <- color_to_string (get
());
3983 state.mode
<- Textentry
(te, leave m_prev_mode
);
3987 method string name get
set =
3989 (name
, `
string get
, 1, Action
(
3991 let ondone s = set s in
3992 let te = name ^
": ", "", None
, textentry, ondone, true in
3993 state.mode
<- Textentry
(te, leave m_prev_mode
);
3997 method colorspace name get
set =
3999 (name
, `
string get
, 1, Action
(
4002 let vals = [| "rgb"; "bgr"; "gray" |] in
4004 inherit lvsourcebase
4007 m_active
<- int_of_colorspace conf.colorspace
;
4010 method getitemcount
= Array.length
vals
4011 method getitem
n = (vals.(n), 0)
4012 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4013 ignore
(uioh
, first, pan
, qsearch);
4014 if not cancel
then set active;
4016 method hasaction
_ = true
4020 let modehash = findkeyhash conf "info" in
4021 coe (new listview ~
source ~trusted
:true ~
modehash)
4024 method caption
s offset
=
4025 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4027 method caption2
s f offset
=
4028 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4030 method getitemcount
= Array.length m_a
4033 let tostr = function
4034 | `
int f -> string_of_int
(f ())
4035 | `intws
f -> string_with_suffix_of_int (f ())
4037 | `color
f -> color_to_string (f ())
4038 | `
bool (btos, f) -> btos (f ())
4041 let name, t
, offset
, _ = m_a
.(n) in
4042 ((let s = tostr t
in
4043 if String.length
s > 0
4044 then Printf.sprintf
"%s\t%s" name s
4048 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4052 m_qsearch
<- qsearch;
4054 match m_a
.(active) with
4055 | _, _, _, Action
f -> f uioh
4067 method hasaction
n =
4069 | _, _, _, Action
_ -> true
4073 let rec fillsrc prevmode prevuioh
=
4074 let sep () = src#caption
"" 0 in
4075 let colorp name get
set =
4077 (fun () -> color_to_string (get
()))
4080 let c = color_of_string v in
4083 state.text <- Printf.sprintf
"bad color `%s': %s"
4084 v (Printexc.to_string exn
);
4087 let oldmode = state.mode
in
4088 let birdseye = isbirdseye state.mode
in
4090 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4092 src#
bool "presentation mode"
4093 (fun () -> conf.presentation
)
4095 conf.presentation
<- v;
4096 state.anchor <- getanchor ();
4099 src#
bool "ignore case in searches"
4100 (fun () -> conf.icase
)
4101 (fun v -> conf.icase
<- v);
4104 (fun () -> conf.preload)
4105 (fun v -> conf.preload <- v);
4107 src#
bool "highlight links"
4108 (fun () -> conf.hlinks
)
4109 (fun v -> conf.hlinks
<- v);
4111 src#
bool "under info"
4112 (fun () -> conf.underinfo
)
4113 (fun v -> conf.underinfo
<- v);
4115 src#
bool "persistent bookmarks"
4116 (fun () -> conf.savebmarks
)
4117 (fun v -> conf.savebmarks
<- v);
4119 src#
bool "proportional display"
4120 (fun () -> conf.proportional
)
4121 (fun v -> reqlayout conf.angle
v);
4123 src#
bool "trim margins"
4124 (fun () -> conf.trimmargins
)
4125 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4127 src#
bool "persistent location"
4128 (fun () -> conf.jumpback
)
4129 (fun v -> conf.jumpback
<- v);
4132 src#
int "inter-page space"
4133 (fun () -> conf.interpagespace
)
4135 conf.interpagespace
<- n;
4136 docolumns conf.columns
;
4138 match state.layout with
4143 state.maxy <- calcheight ();
4144 let y = getpagey pageno in
4149 (fun () -> conf.pagebias
)
4150 (fun v -> conf.pagebias
<- v);
4152 src#
int "scroll step"
4153 (fun () -> conf.scrollstep
)
4154 (fun n -> conf.scrollstep
<- n);
4156 src#
int "horizontal scroll step"
4157 (fun () -> conf.hscrollstep
)
4158 (fun v -> conf.hscrollstep
<- v);
4160 src#
int "auto scroll step"
4162 match state.autoscroll
with
4164 | _ -> conf.autoscrollstep
)
4166 if state.autoscroll
<> None
4167 then state.autoscroll
<- Some
n;
4168 conf.autoscrollstep
<- n);
4171 (fun () -> truncate
(conf.zoom *. 100.))
4172 (fun v -> setzoom ((float v) /. 100.));
4175 (fun () -> conf.angle
)
4176 (fun v -> reqlayout v conf.proportional
);
4178 src#
int "scroll bar width"
4179 (fun () -> state.scrollw
)
4183 reshape conf.winw
conf.winh
;
4186 src#
int "scroll handle height"
4187 (fun () -> conf.scrollh
)
4188 (fun v -> conf.scrollh
<- v;);
4190 src#
int "thumbnail width"
4191 (fun () -> conf.thumbw
)
4193 conf.thumbw
<- min
4096 v;
4196 leavebirdseye beye
false;
4201 let mode = state.mode in
4202 src#
string "columns"
4204 match conf.columns
with
4206 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4207 | Csplit
(count
, _) -> "-" ^ string_of_int count
4210 let n, a, b = multicolumns_of_string v in
4211 setcolumns mode n a b);
4214 src#caption
"Presentation mode" 0;
4215 src#
bool "scrollbar visible"
4216 (fun () -> conf.scrollbarinpm
)
4218 if v != conf.scrollbarinpm
4220 conf.scrollbarinpm
<- v;
4221 if conf.presentation
4223 state.scrollw
<- if v then conf.scrollbw
else 0;
4224 reshape conf.winw
conf.winh
;
4230 src#caption
"Pixmap cache" 0;
4231 src#int_with_suffix
"size (advisory)"
4232 (fun () -> conf.memlimit
)
4233 (fun v -> conf.memlimit
<- v);
4236 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4237 (string_with_suffix_of_int state.memused
)
4238 (Hashtbl.length
state.tilemap
)) 1;
4241 src#caption
"Layout" 0;
4242 src#caption2
"Dimension"
4244 Printf.sprintf
"%dx%d (virtual %dx%d)"
4250 src#caption2
"Position" (fun () ->
4251 Printf.sprintf
"%dx%d" state.x state.y
4254 src#caption2
"Visible" (fun () -> describe_location ()) 1
4258 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4259 "Save these parameters as global defaults at exit"
4260 (fun () -> conf.bedefault
)
4261 (fun v -> conf.bedefault
<- v)
4265 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4266 src#
bool ~offset
:0 ~
btos "Extended parameters"
4267 (fun () -> !showextended)
4268 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4272 (fun () -> conf.checkers
)
4273 (fun v -> conf.checkers
<- v; setcheckers v);
4274 src#
bool "update cursor"
4275 (fun () -> conf.updatecurs
)
4276 (fun v -> conf.updatecurs
<- v);
4278 (fun () -> conf.verbose
)
4279 (fun v -> conf.verbose
<- v);
4280 src#
bool "invert colors"
4281 (fun () -> conf.invert
)
4282 (fun v -> conf.invert
<- v);
4284 (fun () -> conf.maxhfit
)
4285 (fun v -> conf.maxhfit
<- v);
4286 src#
bool "redirect stderr"
4287 (fun () -> conf.redirectstderr)
4288 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4289 src#
string "uri launcher"
4290 (fun () -> conf.urilauncher
)
4291 (fun v -> conf.urilauncher
<- v);
4292 src#
string "path launcher"
4293 (fun () -> conf.pathlauncher
)
4294 (fun v -> conf.pathlauncher
<- v);
4295 src#
string "tile size"
4296 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4299 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4300 conf.tilew
<- max
64 w;
4301 conf.tileh
<- max
64 h;
4304 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4305 v (Printexc.to_string exn
));
4306 src#
int "texture count"
4307 (fun () -> conf.texcount
)
4310 then conf.texcount
<- v
4311 else showtext '
!'
" Failed to set texture count please retry later"
4313 src#
int "slice height"
4314 (fun () -> conf.sliceheight
)
4316 conf.sliceheight
<- v;
4317 wcmd "sliceh %d" conf.sliceheight
;
4319 src#
int "anti-aliasing level"
4320 (fun () -> conf.aalevel
)
4322 conf.aalevel
<- bound v 0 8;
4323 state.anchor <- getanchor ();
4324 opendoc state.path
state.password
;
4326 src#
string "page scroll scaling factor"
4327 (fun () -> string_of_float
conf.pgscale)
4330 let s = float_of_string
v in
4333 state.text <- Printf.sprintf
4334 "bad page scroll scaling factor `%s': %s"
4335 v (Printexc.to_string exn
)
4338 src#
int "ui font size"
4339 (fun () -> fstate.fontsize
)
4340 (fun v -> setfontsize (bound v 5 100));
4341 src#
int "hint font size"
4342 (fun () -> conf.hfsize
)
4343 (fun v -> conf.hfsize
<- bound v 5 100);
4344 colorp "background color"
4345 (fun () -> conf.bgcolor
)
4346 (fun v -> conf.bgcolor
<- v);
4347 src#
bool "crop hack"
4348 (fun () -> conf.crophack
)
4349 (fun v -> conf.crophack
<- v);
4350 src#
bool "multi column centering"
4351 (fun () -> conf.multicenter
)
4352 (fun v -> conf.multicenter
<- v; represent ());
4353 src#
string "trim fuzz"
4354 (fun () -> irect_to_string conf.trimfuzz
)
4357 conf.trimfuzz
<- irect_of_string v;
4359 then settrim true conf.trimfuzz
;
4361 state.text <- Printf.sprintf
"bad irect `%s': %s"
4362 v (Printexc.to_string exn
)
4364 src#
string "throttle"
4366 match conf.maxwait
with
4367 | None
-> "show place holder if page is not ready"
4370 then "wait for page to fully render"
4372 "wait " ^ string_of_float
time
4373 ^
" seconds before showing placeholder"
4377 let f = float_of_string
v in
4379 then conf.maxwait
<- None
4380 else conf.maxwait
<- Some
f
4382 state.text <- Printf.sprintf
"bad time `%s': %s"
4383 v (Printexc.to_string exn
)
4385 src#
string "ghyll scroll"
4387 match conf.ghyllscroll
with
4389 | Some nab
-> ghyllscroll_to_string nab
4394 if String.length
v = 0
4396 else Some
(ghyllscroll_of_string v)
4398 conf.ghyllscroll
<- gs
4400 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4401 v (Printexc.to_string exn
)
4403 src#
string "selection command"
4404 (fun () -> conf.selcmd
)
4405 (fun v -> conf.selcmd
<- v);
4406 src#colorspace
"color space"
4407 (fun () -> colorspace_to_string conf.colorspace
)
4409 conf.colorspace
<- colorspace_of_int v;
4416 src#caption
"Document" 0;
4417 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4418 src#caption2
"Pages"
4419 (fun () -> string_of_int
state.pagecount
) 1;
4420 src#caption2
"Dimensions"
4421 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4425 src#caption
"Trimmed margins" 0;
4426 src#caption2
"Dimensions"
4427 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4431 src#caption
"OpenGL" 0;
4432 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4433 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4434 src#reset prevmode prevuioh
;
4438 let prevmode = state.mode
4439 and prevuioh
= state.uioh in
4440 fillsrc prevmode prevuioh
;
4441 let source = (src :> lvsource
) in
4442 let modehash = findkeyhash conf "info" in
4443 state.uioh <- coe (object (self)
4444 inherit listview ~
source ~trusted
:true ~
modehash as super
4445 val mutable m_prevmemused
= 0
4446 method infochanged
= function
4448 if m_prevmemused
!= state.memused
4450 m_prevmemused
<- state.memused
;
4451 G.postRedisplay "memusedchanged";
4453 | Pdim
-> G.postRedisplay "pdimchanged"
4454 | Docinfo
-> fillsrc prevmode prevuioh
4456 method key key mask
=
4457 if not
(Wsi.withctrl mask
)
4460 | 0xff51 -> coe (self#updownlevel ~
-1)
4461 | 0xff53 -> coe (self#updownlevel
1)
4462 | _ -> super#
key key mask
4463 else super#
key key mask
4465 G.postRedisplay "info";
4471 inherit lvsourcebase
4472 method getitemcount
= Array.length
state.help
4474 let s, n, _ = state.help
.(n) in
4477 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4481 m_qsearch
<- qsearch;
4482 match state.help
.(active) with
4483 | _, _, Action
f -> Some
(f uioh)
4493 method hasaction
n =
4494 match state.help
.(n) with
4495 | _, _, Action
_ -> true
4502 let modehash = findkeyhash conf "help" in
4503 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4504 G.postRedisplay "help";
4509 let re = Str.regexp
"[\r\n]" in
4511 inherit lvsourcebase
4512 val mutable m_items
= [||]
4514 method getitemcount
= 1 + Array.length m_items
4519 else m_items
.(n-1), 0
4521 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4526 then Buffer.clear
state.errmsgs
;
4527 m_qsearch
<- qsearch;
4534 method hasaction
n =
4538 state.newerrmsgs
<- false;
4539 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4540 m_items
<- Array.of_list
l
4548 let source = (msgsource :> lvsource
) in
4549 let modehash = findkeyhash conf "listview" in
4550 state.uioh <- coe (object
4551 inherit listview ~
source ~trusted
:false ~
modehash as super
4554 then msgsource#reset
;
4557 G.postRedisplay "msgs";
4560 let quickbookmark ?title
() =
4561 match state.layout with
4567 let sec = Unix.gettimeofday
() in
4568 let tm = Unix.localtime
sec in
4569 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4573 (tm.Unix.tm_year
+ 1900)
4576 | Some
title -> title
4578 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4582 state.fullscreen
<- None
;
4586 let setautoscrollspeed step goingdown
=
4587 let incr = max
1 ((abs step
) / 2) in
4588 let incr = if goingdown
then incr else -incr in
4589 let astep = step
+ incr in
4590 state.autoscroll
<- Some
astep;
4593 let gotounder = function
4594 | Ulinkgoto
(pageno, top) ->
4598 gotopage1 pageno top;
4604 | Uremote
(filename
, pageno) ->
4606 if Sys.file_exists filename
4609 let dir = Filename.dirname
state.path in
4610 let path = Filename.concat
dir filename
in
4611 if Sys.file_exists
path
4615 if String.length
path > 0
4617 let anchor = getanchor () in
4618 let ranchor = state.path, state.password
, anchor in
4619 state.anchor <- (pageno, 0.0, 0.0);
4620 state.ranchors
<- ranchor :: state.ranchors
;
4623 else showtext '
!'
("Could not find " ^ filename
)
4625 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4629 match conf.columns
with
4631 | _ -> conf.zoom > 1.0
4634 let viewkeyboard key mask
=
4636 let mode = state.mode in
4637 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4640 G.postRedisplay "view:enttext"
4642 let ctrl = Wsi.withctrl mask
in
4647 | 0xff63 -> (* insert *)
4648 if conf.angle
mod 360 = 0
4650 state.mode <- LinkNav
(Ltgendir
0);
4653 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4655 | 0xff1b | 113 -> (* escape / q *)
4656 begin match state.mstate
with
4658 state.mstate
<- Mnone
;
4659 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4660 G.postRedisplay "kill zoom rect";
4662 match state.ranchors
with
4664 | (path, password
, anchor) :: rest
->
4665 state.ranchors
<- rest
;
4666 state.anchor <- anchor;
4667 opendoc path password
4670 | 0xff08 -> (* backspace *)
4671 let y = getnav ~
-1 in
4672 gotoy_and_clear_text y
4680 G.postRedisplay "dehighlight";
4682 | 47 | 63 -> (* / ? *)
4683 let ondone isforw
s =
4684 cbput state.hists
.pat
s;
4685 state.searchpattern
<- s;
4688 let s = String.create
1 in
4689 s.[0] <- Char.chr
key;
4690 enttext (s, "", Some
(onhist state.hists
.pat
),
4691 textentry, ondone (key = 47), true)
4693 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4694 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4695 setzoom (conf.zoom +. incr)
4697 | 43 | 0xffab -> (* + *)
4700 try int_of_string
s with exc
->
4701 state.text <- Printf.sprintf
"bad integer `%s': %s"
4702 s (Printexc.to_string exc
);
4708 state.text <- "page bias is now " ^ string_of_int
n;
4711 enttext ("page bias: ", "", None
, intentry, ondone, true)
4713 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4714 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4715 setzoom (max
0.01 (conf.zoom -. decr))
4717 | 45 | 0xffad -> (* - *)
4718 let ondone msg
= state.text <- msg
in
4720 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4721 optentry state.mode, ondone, true
4724 | 48 when ctrl -> (* ctrl-0 *)
4727 | 49 when ctrl -> (* ctrl-1 *)
4729 match conf.columns
with
4730 | Csingle
_ | Cmulti
_ -> 1
4731 | Csplit
(n, _) -> n
4733 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4737 | 0xffc6 -> (* f9 *)
4740 | 57 when ctrl -> (* ctrl-9 *)
4743 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4744 when not
ctrl -> (* 0..9 *)
4747 try int_of_string
s with exc
->
4748 state.text <- Printf.sprintf
"bad integer `%s': %s"
4749 s (Printexc.to_string exc
);
4755 cbput state.hists
.pag
(string_of_int
n);
4756 gotopage1 (n + conf.pagebias
- 1) 0;
4759 let pageentry text key =
4760 match Char.unsafe_chr
key with
4761 | 'g'
-> TEdone
text
4762 | _ -> intentry text key
4764 let text = "x" in text.[0] <- Char.chr
key;
4765 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4768 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4769 reshape conf.winw
conf.winh
;
4772 conf.hlinks
<- not
conf.hlinks
;
4773 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4774 G.postRedisplay "toggle highlightlinks";
4777 state.glinks
<- true;
4778 let mode = state.mode in
4779 state.mode <- Textentry
(
4780 (":", "", None
, linknentry, linkndone (fun under ->
4785 state.glinks
<- false;
4789 G.postRedisplay "view:linkent(F)"
4792 state.glinks
<- true;
4793 let mode = state.mode in
4794 state.mode <- Textentry
(
4795 (":", "", None
, linknentry, linkndone (fun under ->
4796 match Ne.pipe () with
4798 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4799 (Printexc.to_string exn
));
4802 try popen conf.selcmd
[r, 0; w, -1]; true
4805 (Printf.sprintf
"failed to execute %s: %s"
4806 conf.selcmd
(Printexc.to_string exn
));
4810 Ne.clo fd
(fun msg
->
4811 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4814 let s = undertext under in
4818 let l = String.length
s in
4819 let n = Unix.write
w s 0 l in
4824 "failed to write %d characters to sel pipe, wrote %d"
4829 (Printf.sprintf
"failed to write to sel pipe: %s"
4830 (Printexc.to_string exn
)
4839 state.glinks
<- false;
4843 G.postRedisplay "view:linkent"
4846 begin match state.autoscroll
with
4848 conf.autoscrollstep
<- step
;
4849 state.autoscroll
<- None
4851 if conf.autoscrollstep
= 0
4852 then state.autoscroll
<- Some
1
4853 else state.autoscroll
<- Some
conf.autoscrollstep
4856 | 112 when ctrl -> (* ctrl-p *)
4860 conf.presentation
<- not
conf.presentation
;
4861 if conf.presentation
4863 if not
conf.scrollbarinpm
4864 then state.scrollw
<- 0;
4867 state.scrollw
<- conf.scrollbw
;
4869 showtext ' '
("presentation mode " ^
4870 if conf.presentation
then "on" else "off");
4871 state.anchor <- getanchor ();
4875 begin match state.fullscreen
with
4877 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4880 state.fullscreen
<- None
;
4885 gotoy_and_clear_text 0
4888 gotopage1 (state.pagecount
- 1) 0
4890 | 112 | 78 -> (* p|N *)
4891 search state.searchpattern
false
4893 | 110 | 0xffc0 -> (* n|F3 *)
4894 search state.searchpattern
true
4897 begin match state.layout with
4900 gotoy_and_clear_text (getpagey l.pageno)
4904 begin match state.layout with
4907 match conf.columns
with
4908 | Csingle
_ | Cmulti
_ ->
4909 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4911 let y = clamp (pgscale conf.winh
) in
4912 gotoy_and_clear_text y
4914 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4915 gotoy_and_clear_text (getpagey pageno)
4917 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4919 let pagey, pageh
= getpageyh l.pageno in
4920 let pagey = pagey + pageh
* l.pagecol
in
4921 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4922 gotoy_and_clear_text (pagey + pageh
+ ips)
4925 | 0xff9f | 0xffff -> (* delete *)
4926 begin match state.layout with
4929 match conf.columns
with
4930 | Csingle
_ | Cmulti
_ ->
4931 if conf.presentation
&& l.pagey != 0
4933 gotoy_and_clear_text (clamp (pgscale ~
-(conf.winh
)))
4935 let pageno = max
0 (l.pageno-1) in
4936 gotoy_and_clear_text (getpagey pageno)
4944 let pageno = max
0 (l.pageno-1) in
4945 let pagey, pageh
= getpageyh pageno in
4948 let pagey, pageh
= getpageyh l.pageno in
4949 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4951 gotoy_and_clear_text y
4955 showtext ' '
(describe_location ());
4958 begin match state.layout with
4961 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4966 enterbookmarkmode ()
4968 | 104 | 0xffbe -> (* h|F1 *)
4974 | 101 when conf.redirectstderr -> (* e *)
4979 match state.layout with
4980 | l :: _ -> state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
4983 enttext ("bookmark: ", "", None
, textentry, ondone, true)
4987 showtext ' '
"Quick bookmark added";
4990 begin match state.layout with
4992 let rect = getpdimrect
l.pagedimno
in
4996 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4997 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4999 (truncate
(rect.(1) -. rect.(0)),
5000 truncate
(rect.(3) -. rect.(0)))
5002 let w = truncate
((float w)*.conf.zoom)
5003 and h = truncate
((float h)*.conf.zoom) in
5006 state.anchor <- getanchor ();
5007 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5009 G.postRedisplay "z";
5014 | 50 when ctrl -> (* ctrl-2 *)
5015 let maxw = getmaxw
() in
5017 then setzoom (maxw /. float conf.winw
)
5019 | 60 | 62 -> (* < > *)
5020 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5022 | 91 | 93 -> (* [ ] *)
5024 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5026 G.postRedisplay "brightness";
5028 | 99 when state.mode = View
-> (* c *)
5030 match state.prevcolumns
with
5031 | None
-> (1, 0, 0), 1.0
5032 | Some
(columns
, z
) ->
5035 | Csplit
(c, _) -> -c, 0, 0
5036 | Cmulti
((c, a, b), _) -> c, a, b
5037 | Csingle
_ -> 1, 0, 0
5041 setcolumns View
c a b;
5044 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5045 setzoom state.prevzoom
5047 | 107 | 0xff52 -> (* k up *)
5048 begin match state.autoscroll
with
5050 begin match state.mode with
5051 | Birdseye beye
-> upbirdseye 1 beye
5054 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5055 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5058 setautoscrollspeed n false
5061 | 106 | 0xff54 -> (* j down *)
5062 begin match state.autoscroll
with
5064 begin match state.mode with
5065 | Birdseye beye
-> downbirdseye 1 beye
5068 then gotoy_and_clear_text (clamp (conf.winh
/2))
5069 else gotoy_and_clear_text (clamp conf.scrollstep
)
5072 setautoscrollspeed n true
5075 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5083 let dx = if key = 0xff51 then dx else -dx in
5084 state.x <- state.x + dx;
5085 gotoy_and_clear_text state.y
5088 G.postRedisplay "lef/right"
5091 | 0xff55 -> (* prior *)
5095 match state.layout with
5097 | l :: _ -> state.y - l.pagey
5099 clamp (pgscale (-conf.winh
))
5103 | 0xff56 -> (* next *)
5107 match List.rev
state.layout with
5109 | l :: _ -> getpagey l.pageno
5111 clamp (pgscale conf.winh
)
5115 | 0xff50 -> (* home *)
5117 | 0xff57 -> (* end *)
5118 gotoghyll (clamp state.maxy)
5119 | 0xff53 when Wsi.withalt mask
-> (* right *)
5120 gotoghyll (getnav ~
-1)
5121 | 0xff51 when Wsi.withalt mask
-> (* left *)
5122 gotoghyll (getnav 1)
5125 state.anchor <- getanchor ();
5126 opendoc state.path state.password
5128 | 118 when conf.debug
-> (* v *)
5131 match getopaque l.pageno with
5134 let x0, y0, x1, y1 = pagebbox opaque
in
5135 let a,b = float x0, float y0 in
5136 let c,d = float x1, float y0 in
5137 let e,f = float x1, float y1 in
5138 let h,j
= float x0, float y1 in
5139 let rect = (a,b,c,d,e,f,h,j
) in
5141 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5143 G.postRedisplay "v";
5146 vlog "huh? %s" (Wsi.keyname
key)
5149 let linknavkeyboard key mask
linknav =
5150 let getpage pageno =
5151 let rec loop = function
5153 | l :: _ when l.pageno = pageno -> Some
l
5154 | _ :: rest
-> loop rest
5155 in loop state.layout
5157 let doexact (pageno, n) =
5158 match getopaque pageno, getpage pageno with
5159 | Some opaque
, Some
l ->
5162 let under = getlink opaque
n in
5163 G.postRedisplay "link gotounder";
5169 | 0xff50 -> (* home *)
5170 Some
(findlink opaque LDfirst
), -1
5172 | 0xff57 -> (* end *)
5173 Some
(findlink opaque LDlast
), 1
5175 | 0xff51 -> (* left *)
5176 Some
(findlink opaque
(LDleft
n)), -1
5178 | 0xff53 -> (* right *)
5179 Some
(findlink opaque
(LDright
n)), 1
5181 | 0xff52 -> (* up *)
5182 Some
(findlink opaque
(LDup
n)), -1
5184 | 0xff54 -> (* down *)
5185 Some
(findlink opaque
(LDdown
n)), 1
5190 begin match findpwl
l.pageno dir with
5194 state.mode <- LinkNav
(Ltgendir
dir);
5195 let y, h = getpageyh pageno in
5198 then y + h - conf.winh
5203 begin match getopaque pageno, getpage pageno with
5204 | Some opaque
, Some
_ ->
5206 let ld = if dir > 0 then LDfirst
else LDlast
in
5209 begin match link with
5211 showlinktype (getlink opaque
m);
5212 state.mode <- LinkNav
(Ltexact
(pageno, m));
5213 G.postRedisplay "linknav jpage";
5220 begin match opt with
5221 | Some Lnotfound
-> pwl l dir;
5222 | Some
(Lfound
m) ->
5226 let _, y0, _, y1 = getlinkrect opaque
m in
5228 then gotopage1 l.pageno y0
5230 let d = fstate.fontsize
+ 1 in
5231 if y1 - l.pagey > l.pagevh - d
5232 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5233 else G.postRedisplay "linknav";
5235 showlinktype (getlink opaque
m);
5236 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5239 | None
-> viewkeyboard key mask
5241 | _ -> viewkeyboard key mask
5246 G.postRedisplay "leave linknav"
5250 | Ltgendir
_ -> viewkeyboard key mask
5251 | Ltexact exact
-> doexact exact
5254 let keyboard key mask
=
5255 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5256 then wcmd "interrupt"
5257 else state.uioh <- state.uioh#
key key mask
5260 let birdseyekeyboard key mask
5261 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5263 match conf.columns
with
5265 | Cmulti
((c, _, _), _) -> c
5266 | Csplit
_ -> failwith
"bird's eye split mode"
5268 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5270 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5271 let y, h = getpageyh pageno in
5272 let top = (conf.winh
- h) / 2 in
5273 gotoy (max
0 (y - top))
5274 | 0xff0d -> leavebirdseye beye
false
5275 | 0xff1b -> leavebirdseye beye
true (* escape *)
5276 | 0xff52 -> upbirdseye incr beye
(* up *)
5277 | 0xff54 -> downbirdseye incr beye
(* down *)
5278 | 0xff51 -> upbirdseye 1 beye
(* left *)
5279 | 0xff53 -> downbirdseye 1 beye
(* right *)
5281 | 0xff55 -> (* prior *)
5282 begin match state.layout with
5286 state.mode <- Birdseye
(
5287 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5289 gotopage1 l.pageno 0;
5292 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5294 | [] -> gotoy (clamp (-conf.winh
))
5296 state.mode <- Birdseye
(
5297 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5299 gotopage1 l.pageno 0
5302 | [] -> gotoy (clamp (-conf.winh
))
5305 | 0xff56 -> (* next *)
5306 begin match List.rev
state.layout with
5308 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5309 begin match layout with
5311 let incr = l.pageh
- l.pagevh in
5316 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5318 G.postRedisplay "birdseye pagedown";
5320 else gotoy (clamp (incr + conf.interpagespace
*2));
5324 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5325 gotopage1 l.pageno 0;
5328 | [] -> gotoy (clamp conf.winh
)
5331 | 0xff50 -> (* home *)
5332 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5335 | 0xff57 -> (* end *)
5336 let pageno = state.pagecount
- 1 in
5337 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5338 if not
(pagevisible state.layout pageno)
5341 match List.rev
state.pdims
with
5343 | (_, _, h, _) :: _ -> h
5345 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5346 else G.postRedisplay "birdseye end";
5347 | _ -> viewkeyboard key mask
5350 let drawpage l linkindexbase
=
5352 match state.mode with
5353 | Textentry
_ -> scalecolor 0.4
5355 | View
-> scalecolor 1.0
5356 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5357 if l.pageno = hooverpageno
5360 if l.pageno = pageno
5366 begin match getopaque l.pageno with
5368 if tileready l l.pagex
l.pagey
5370 let x = l.pagedispx - l.pagex
5371 and y = l.pagedispy - l.pagey in
5373 match conf.columns
with
5374 | Csingle
_ | Cmulti
_ ->
5375 (if conf.hlinks
then 1 else 0)
5377 && not
(isbirdseye state.mode) then 2 else 0)
5381 match state.mode with
5382 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5385 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5392 let scrollindicator () =
5393 let sbw, ph
, sh = state.uioh#
scrollph in
5394 let sbh, pw, sw = state.uioh#scrollpw
in
5396 GlDraw.color (0.64, 0.64, 0.64);
5398 (float (conf.winw
- sbw), 0.)
5399 (float conf.winw
, float conf.winh
)
5402 (0., float (conf.winh
- sbh))
5403 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5405 GlDraw.color (0.0, 0.0, 0.0);
5408 (float (conf.winw
- sbw), ph
)
5409 (float conf.winw
, ph
+. sh)
5412 (pw, float (conf.winh
- sbh))
5413 (pw +. sw, float conf.winh
)
5418 match state.mstate
with
5419 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5422 | Msel
((x0, y0), (x1, y1)) ->
5423 let rec loop = function
5425 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5426 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5427 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5428 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5430 match getopaque l.pageno with
5432 let x0, y0 = pagetranslatepoint l x0 y0 in
5433 let x1, y1 = pagetranslatepoint l x1 y1 in
5434 seltext opaque
(x0, y0, x1, y1);
5442 let showrects rects
=
5444 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5445 GlDraw.polygon_mode `both `fill
;
5446 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5448 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5450 if l.pageno = pageno
5452 let dx = float (l.pagedispx - l.pagex
) in
5453 let dy = float (l.pagedispy - l.pagey) in
5454 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5455 GlDraw.begins `quads
;
5457 GlDraw.vertex2
(x0+.dx, y0+.dy);
5458 GlDraw.vertex2
(x1+.dx, y1+.dy);
5459 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5460 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5471 GlClear.color (scalecolor2 conf.bgcolor
);
5472 GlClear.clear
[`
color];
5473 let rec loop linkindexbase
= function
5475 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5476 loop linkindexbase rest
5479 loop 0 state.layout;
5481 match state.mode with
5482 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5483 begin match getopaque pageno with
5485 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5492 | None
-> state.rects
5499 begin match state.mstate
with
5500 | Mzoomrect
((x0, y0), (x1, y1)) ->
5502 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5503 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5504 GlDraw.rect (float x0, float y0)
5505 (float x1, float y1);
5514 let zoomrect x y x1 y1 =
5517 and y0 = min
y y1 in
5518 gotoy (state.y + y0);
5519 state.anchor <- getanchor ();
5520 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5522 if state.w < conf.winw
- state.scrollw
5523 then (conf.winw
- state.scrollw
- state.w) / 2
5526 state.x <- (state.x + margin) - x0;
5528 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5529 state.mstate
<- Mnone
;
5533 let winw = conf.winw - state.scrollw
- 1 in
5534 let s = float x /. float winw in
5535 let destx = truncate
(float (state.w + winw) *. s) in
5536 state.x <- winw - destx;
5537 gotoy_and_clear_text state.y;
5538 state.mstate
<- Mscrollx
;
5542 let s = float y /. float conf.winh
in
5543 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5544 gotoy_and_clear_text desty;
5545 state.mstate
<- Mscrolly
;
5548 let viewmouse button down
x y mask
=
5550 | n when (n == 4 || n == 5) && not down
->
5551 if Wsi.withctrl mask
5553 match state.mstate
with
5554 | Mzoom
(oldn
, i
) ->
5562 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5564 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5566 let zoom = conf.zoom -. incr in
5568 state.mstate
<- Mzoom
(n, 0);
5570 state.mstate
<- Mzoom
(n, i
+1);
5572 else state.mstate
<- Mzoom
(n, 0)
5574 | _ -> state.mstate
<- Mzoom
(n, 0)
5577 match state.autoscroll
with
5578 | Some step
-> setautoscrollspeed step
(n=4)
5582 then -conf.scrollstep
5583 else conf.scrollstep
5585 let incr = incr * 2 in
5586 let y = clamp incr in
5587 gotoy_and_clear_text y
5590 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5591 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5592 gotoy_and_clear_text state.y
5594 | 1 when Wsi.withctrl mask
->
5597 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5598 state.mstate
<- Mpan
(x, y)
5601 state.mstate
<- Mnone
5606 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5608 state.mstate
<- Mzoomrect
(p, p)
5611 match state.mstate
with
5612 | Mzoomrect
((x0, y0), _) ->
5613 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5614 then zoomrect x0 y0 x y
5616 state.mstate
<- Mnone
;
5617 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5618 G.postRedisplay "kill accidental zoom rect";
5621 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5622 state.mstate
<- Mnone
5625 | 1 when x > conf.winw - state.scrollw
->
5628 let _, position, sh = state.uioh#
scrollph in
5629 if y > truncate
position && y < truncate
(position +. sh)
5630 then state.mstate
<- Mscrolly
5633 state.mstate
<- Mnone
5635 | 1 when y > conf.winh
- state.hscrollh ->
5638 let _, position, sw = state.uioh#scrollpw
in
5639 if x > truncate
position && x < truncate
(position +. sw)
5640 then state.mstate
<- Mscrollx
5643 state.mstate
<- Mnone
5646 let dest = if down
then getunder x y else Unone
in
5647 begin match dest with
5651 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5654 | Unone
when down
->
5655 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5656 state.mstate
<- Mpan
(x, y);
5658 | Unone
| Utext
_ ->
5661 if conf.angle
mod 360 = 0
5663 state.mstate
<- Msel
((x, y), (x, y));
5664 G.postRedisplay "mouse select";
5668 match state.mstate
with
5671 | Mzoom
_ | Mscrollx
| Mscrolly
->
5672 state.mstate
<- Mnone
5674 | Mzoomrect
((x0, y0), _) ->
5678 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5679 state.mstate
<- Mnone
5681 | Msel
((_, y0), (_, y1)) ->
5682 let rec loop = function
5685 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5686 || ((y1 >= l.pagedispy
5687 && y1 <= (l.pagedispy + l.pagevh)))
5689 match getopaque l.pageno with
5692 match Ne.pipe () with
5696 "can not create sel pipe: %s"
5697 (Printexc.to_string exn
));
5699 let doclose what fd
=
5700 Ne.clo fd
(fun msg
->
5701 dolog "%s close failed: %s" what msg
)
5704 popen conf.selcmd
[r, 0; w, -1];
5707 G.postRedisplay "copysel";
5709 dolog "can not execute %S: %s"
5710 conf.selcmd
(Printexc.to_string exn
);
5718 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5719 state.mstate
<- Mnone
;
5726 let birdseyemouse button down
x y mask
5727 (conf, leftx
, _, hooverpageno
, anchor) =
5730 let rec loop = function
5733 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5734 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5736 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5742 | _ -> viewmouse button down
x y mask
5745 let mouse button down
x y mask
=
5746 state.uioh <- state.uioh#button button down
x y mask
;
5750 state.uioh <- state.uioh#
motion x y
5754 state.uioh <- state.uioh#
pmotion x y;
5760 method key key mask
=
5761 begin match state.mode with
5762 | Textentry
textentry -> textentrykeyboard key mask
textentry
5763 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5764 | View
-> viewkeyboard key mask
5765 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5769 method button button bstate
x y mask
=
5770 begin match state.mode with
5772 | View
-> viewmouse button bstate
x y mask
5773 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5779 begin match state.mode with
5781 | View
| Birdseye
_ | LinkNav
_ ->
5782 match state.mstate
with
5783 | Mzoom
_ | Mnone
-> ()
5788 state.mstate
<- Mpan
(x, y);
5790 then state.x <- state.x + dx;
5792 gotoy_and_clear_text y
5795 state.mstate
<- Msel
(a, (x, y));
5796 G.postRedisplay "motion select";
5799 let y = min
conf.winh
(max
0 y) in
5803 let x = min
conf.winw (max
0 x) in
5806 | Mzoomrect
(p0
, _) ->
5807 state.mstate
<- Mzoomrect
(p0
, (x, y));
5808 G.postRedisplay "motion zoomrect";
5812 method pmotion x y =
5813 begin match state.mode with
5814 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5815 let rec loop = function
5817 if hooverpageno
!= -1
5819 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5820 G.postRedisplay "pmotion birdseye no hoover";
5823 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5824 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5826 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5827 G.postRedisplay "pmotion birdseye hoover";
5837 match state.mstate
with
5838 | Mnone
-> updateunder x y
5839 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5844 method infochanged
_ = ()
5847 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5848 let p, h = scrollph state.y maxy in
5852 let winw = conf.winw - state.scrollw
- 1 in
5853 let fwinw = float winw in
5855 let sw = fwinw /. float state.w in
5856 let sw = fwinw *. sw in
5857 max
sw (float conf.scrollh
)
5860 let f = state.w+winw in
5861 let r = float (winw-state.x) /. float f in
5862 let p = fwinw *. r in
5866 if position +. sw > fwinw
5867 then fwinw -. position
5870 state.hscrollh, position, sw
5874 match state.mode with
5875 | LinkNav
_ -> "links"
5876 | Textentry
_ -> "textentry"
5877 | Birdseye
_ -> "birdseye"
5880 findkeyhash conf modename
5887 let fontpath = ref "";;
5890 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5893 let l = String.length
s in
5894 let b = Buffer.create
l in
5900 try Sys.getenv
"HOME"
5903 ("Can not determine home directory location: " ^
5904 Printexc.to_string exn
);
5908 let modifier_of_string = function
5909 | "alt" -> Wsi.altmask
5910 | "shift" -> Wsi.shiftmask
5911 | "ctrl" | "control" -> Wsi.ctrlmask
5912 | "meta" -> Wsi.metamask
5917 let r = Str.regexp
"-" in
5919 let elems = Str.full_split
r s in
5922 let m1 = modifier_of_string s in
5924 then (Wsi.namekey
s, m)
5927 | Str.Delim
s when n land 1 = 0 -> g s
5929 | Str.Delim
_ -> (k
, m)
5931 let rec loop n k
m = function
5934 let k, m = f n k m x in
5940 let keys_of_string =
5941 let r = Str.regexp
"[ \t]" in
5943 let elems = Str.split
r s in
5944 List.map
key_of_string elems
5947 let copykeyhashes c =
5948 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5951 let config_of c attrs
=
5955 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5956 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5957 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5958 | "preload" -> { c with preload = bool_of_string
v }
5959 | "page-bias" -> { c with pagebias
= int_of_string
v }
5960 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5961 | "horizontal-scroll-step" ->
5962 { c with hscrollstep
= max
(int_of_string
v) 1 }
5963 | "auto-scroll-step" ->
5964 { c with autoscrollstep
= max
0 (int_of_string
v) }
5965 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5966 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5969 match String.lowercase
v with
5970 | "true" -> Some infinity
5972 | f -> Some
(float_of_string
f)
5974 { c with maxwait
= mw}
5975 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5976 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5977 | "vertical-margin" ->
5978 { c with interpagespace
= max
0 (int_of_string
v) }
5980 let zoom = float_of_string
v /. 100. in
5981 let zoom = max
zoom 0.0 in
5982 { c with zoom = zoom }
5983 | "presentation" -> { c with presentation
= bool_of_string
v }
5984 | "rotation-angle" -> { c with angle
= int_of_string
v }
5985 | "width" -> { c with winw = max
20 (int_of_string
v) }
5986 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5987 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5988 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5989 | "pixmap-cache-size" ->
5990 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5991 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5992 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5993 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5994 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5995 | "background-color" -> { c with bgcolor
= color_of_string v }
5996 | "scrollbar-in-presentation" ->
5997 { c with scrollbarinpm
= bool_of_string
v }
5998 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5999 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6000 | "mupdf-store-size" ->
6001 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6002 | "checkers" -> { c with checkers
= bool_of_string
v }
6003 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6004 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6005 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6006 | "uri-launcher" -> { c with urilauncher
= unent v }
6007 | "path-launcher" -> { c with pathlauncher
= unent v }
6008 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6009 | "invert-colors" -> { c with invert
= bool_of_string
v }
6010 | "brightness" -> { c with colorscale
= float_of_string
v }
6011 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6013 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6015 let (n, _, _) as nab
= multicolumns_of_string v in
6017 then { c with columns
= Csplit
(-n, [||]) }
6018 else { c with columns
= Cmulti
(nab
, [||]) }
6019 | "birds-eye-columns" ->
6020 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6021 | "selection-command" -> { c with selcmd
= unent v }
6022 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6023 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6024 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6025 | "multi-column-centering" -> { c with multicenter
= bool_of_string
v }
6028 prerr_endline
("Error processing attribute (`" ^
6029 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6032 let rec fold c = function
6035 let c = apply c k v in
6038 fold { c with keyhashes
= copykeyhashes c } attrs
;
6041 let fromstring f pos
n v d =
6044 dolog "Error processing attribute (%S=%S) at %d\n%s"
6045 n v pos
(Printexc.to_string exn
)
6050 let bookmark_of attrs
=
6051 let rec fold title page
rely visy
= function
6052 | ("title", v) :: rest
-> fold v page
rely visy rest
6053 | ("page", v) :: rest
-> fold title v rely visy rest
6054 | ("rely", v) :: rest
-> fold title page
v visy rest
6055 | ("visy", v) :: rest
-> fold title page
rely v rest
6056 | _ :: rest
-> fold title page
rely visy rest
6057 | [] -> title, page
, rely, visy
6059 fold "invalid" "0" "0" "0" attrs
6063 let rec fold path page
rely pan visy
= function
6064 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6065 | ("page", v) :: rest
-> fold path v rely pan visy rest
6066 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6067 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6068 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6069 | _ :: rest
-> fold path page
rely pan visy rest
6070 | [] -> path, page
, rely, pan
, visy
6072 fold "" "0" "0" "0" "0" attrs
6076 let rec fold rs ls
= function
6077 | ("out", v) :: rest
-> fold v ls rest
6078 | ("in", v) :: rest
-> fold rs
v rest
6079 | _ :: rest
-> fold ls rs rest
6085 let setconf dst
src =
6086 dst
.scrollbw
<- src.scrollbw
;
6087 dst
.scrollh
<- src.scrollh
;
6088 dst
.icase
<- src.icase
;
6089 dst
.preload <- src.preload;
6090 dst
.pagebias
<- src.pagebias
;
6091 dst
.verbose
<- src.verbose
;
6092 dst
.scrollstep
<- src.scrollstep
;
6093 dst
.maxhfit
<- src.maxhfit
;
6094 dst
.crophack
<- src.crophack
;
6095 dst
.autoscrollstep
<- src.autoscrollstep
;
6096 dst
.maxwait
<- src.maxwait
;
6097 dst
.hlinks
<- src.hlinks
;
6098 dst
.underinfo
<- src.underinfo
;
6099 dst
.interpagespace
<- src.interpagespace
;
6100 dst
.zoom <- src.zoom;
6101 dst
.presentation
<- src.presentation
;
6102 dst
.angle
<- src.angle
;
6103 dst
.winw <- src.winw;
6104 dst
.winh
<- src.winh
;
6105 dst
.savebmarks
<- src.savebmarks
;
6106 dst
.memlimit
<- src.memlimit
;
6107 dst
.proportional
<- src.proportional
;
6108 dst
.texcount
<- src.texcount
;
6109 dst
.sliceheight
<- src.sliceheight
;
6110 dst
.thumbw
<- src.thumbw
;
6111 dst
.jumpback
<- src.jumpback
;
6112 dst
.bgcolor
<- src.bgcolor
;
6113 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6114 dst
.tilew
<- src.tilew
;
6115 dst
.tileh
<- src.tileh
;
6116 dst
.mustoresize
<- src.mustoresize
;
6117 dst
.checkers
<- src.checkers
;
6118 dst
.aalevel
<- src.aalevel
;
6119 dst
.trimmargins
<- src.trimmargins
;
6120 dst
.trimfuzz
<- src.trimfuzz
;
6121 dst
.urilauncher
<- src.urilauncher
;
6122 dst
.colorspace
<- src.colorspace
;
6123 dst
.invert
<- src.invert
;
6124 dst
.colorscale
<- src.colorscale
;
6125 dst
.redirectstderr <- src.redirectstderr;
6126 dst
.ghyllscroll
<- src.ghyllscroll
;
6127 dst
.columns
<- src.columns
;
6128 dst
.beyecolumns
<- src.beyecolumns
;
6129 dst
.selcmd
<- src.selcmd
;
6130 dst
.updatecurs
<- src.updatecurs
;
6131 dst
.pathlauncher
<- src.pathlauncher
;
6132 dst
.keyhashes
<- copykeyhashes src;
6133 dst
.hfsize
<- src.hfsize
;
6134 dst
.hscrollstep
<- src.hscrollstep
;
6135 dst
.pgscale <- src.pgscale;
6136 dst
.multicenter
<- src.multicenter
;
6140 let h = Hashtbl.create
10 in
6141 let dc = { defconf with angle
= defconf.angle
} in
6142 let rec toplevel v t spos
_ =
6144 | Vdata
| Vcdata
| Vend
-> v
6145 | Vopen
("llppconfig", _, closed
) ->
6148 else { v with f = llppconfig
}
6150 error
"unexpected subelement at top level" s spos
6151 | Vclose
_ -> error
"unexpected close at top level" s spos
6153 and llppconfig
v t spos
_ =
6155 | Vdata
| Vcdata
-> v
6156 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6157 | Vopen
("defaults", attrs
, closed
) ->
6158 let c = config_of dc attrs
in
6162 else { v with f = defaults
}
6164 | Vopen
("ui-font", attrs
, closed
) ->
6165 let rec getsize size
= function
6167 | ("size", v) :: rest
->
6169 fromstring int_of_string spos
"size" v fstate.fontsize
in
6171 | l -> getsize size l
6173 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6176 else { v with f = uifont
(Buffer.create
10) }
6178 | Vopen
("doc", attrs
, closed
) ->
6179 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6180 let path = unent pathent
6181 and pageno = fromstring int_of_string spos
"page" spage
0
6182 and rely = fromstring float_of_string spos
"rely" srely
0.0
6183 and pan
= fromstring int_of_string spos
"pan" span
0
6184 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6185 let c = config_of dc attrs
in
6186 let anchor = (pageno, rely, visy
) in
6188 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6189 else { v with f = doc
path pan
anchor c [] }
6192 error
"unexpected subelement in llppconfig" s spos
6194 | Vclose
"llppconfig" -> { v with f = toplevel }
6195 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6197 and defaults
v t spos
_ =
6199 | Vdata
| Vcdata
-> v
6200 | Vend
-> error
"unexpected end of input in defaults" s spos
6201 | Vopen
("keymap", attrs
, closed
) ->
6203 try List.assoc
"mode" attrs
6204 with Not_found
-> "global" in
6209 let h = findkeyhash dc modename in
6210 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6213 { v with f = pkeymap
ret KeyMap.empty }
6215 | Vopen
(_, _, _) ->
6216 error
"unexpected subelement in defaults" s spos
6218 | Vclose
"defaults" ->
6219 { v with f = llppconfig
}
6221 | Vclose
_ -> error
"unexpected close in defaults" s spos
6223 and uifont
b v t spos
epos =
6226 Buffer.add_substring
b s spos
(epos - spos
);
6228 | Vopen
(_, _, _) ->
6229 error
"unexpected subelement in ui-font" s spos
6230 | Vclose
"ui-font" ->
6231 if String.length
!fontpath = 0
6232 then fontpath := Buffer.contents
b;
6233 { v with f = llppconfig
}
6234 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6235 | Vend
-> error
"unexpected end of input in ui-font" s spos
6237 and doc
path pan
anchor c bookmarks
v t spos
_ =
6239 | Vdata
| Vcdata
-> v
6240 | Vend
-> error
"unexpected end of input in doc" s spos
6241 | Vopen
("bookmarks", _, closed
) ->
6244 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6246 | Vopen
("keymap", attrs
, closed
) ->
6248 try List.assoc
"mode" attrs
6249 with Not_found
-> "global"
6255 let h = findkeyhash c modename in
6256 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6257 doc
path pan
anchor c bookmarks
6259 { v with f = pkeymap
ret KeyMap.empty }
6261 | Vopen
(_, _, _) ->
6262 error
"unexpected subelement in doc" s spos
6265 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6266 { v with f = llppconfig
}
6268 | Vclose
_ -> error
"unexpected close in doc" s spos
6270 and pkeymap
ret keymap
v t spos
_ =
6272 | Vdata
| Vcdata
-> v
6273 | Vend
-> error
"unexpected end of input in keymap" s spos
6274 | Vopen
("map", attrs
, closed
) ->
6275 let r, l = map_of attrs
in
6276 let kss = fromstring keys_of_string spos
"in" r [] in
6277 let lss = fromstring keys_of_string spos
"out" l [] in
6281 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6282 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6285 then { v with f = pkeymap
ret keymap }
6288 { v with f = skip
"map" f }
6291 error
"unexpected subelement in keymap" s spos
6293 | Vclose
"keymap" ->
6294 { v with f = ret keymap }
6296 | Vclose
_ -> error
"unexpected close in keymap" s spos
6298 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6300 | Vdata
| Vcdata
-> v
6301 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6302 | Vopen
("item", attrs
, closed
) ->
6303 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6304 let page = fromstring int_of_string spos
"page" spage
0
6305 and rely = fromstring float_of_string spos
"rely" srely
0.0
6306 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6308 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6311 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6314 { v with f = skip
"item" f }
6317 error
"unexpected subelement in bookmarks" s spos
6319 | Vclose
"bookmarks" ->
6320 { v with f = doc
path pan
anchor c bookmarks }
6322 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6324 and skip tag
f v t spos
_ =
6326 | Vdata
| Vcdata
-> v
6328 error
("unexpected end of input in skipped " ^ tag
) s spos
6329 | Vopen
(tag'
, _, closed
) ->
6333 let f'
() = { v with f = skip tag
f } in
6334 { v with f = skip tag'
f'
}
6338 else error
("unexpected close in skipped " ^ tag
) s spos
6341 parse
{ f = toplevel; accu = () } s;
6347 let len = in_channel_length ic
in
6348 let s = String.create
len in
6349 really_input ic
s 0 len;
6352 | Parse_error
(msg
, s, pos
) ->
6353 let subs = subs s pos
in
6354 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6355 failwith
("parse error: " ^
s)
6358 failwith
("config load error: " ^
Printexc.to_string exn
)
6364 let dir = Filename.concat
home ".config" in
6365 if Sys.is_directory
dir then dir else home
6368 Filename.concat
dir "llpp.conf"
6371 let confpath = ref defconfpath;;
6374 if Sys.file_exists
!confpath
6377 (try Some
(open_in_bin
!confpath)
6380 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6381 Printexc.to_string exn
);
6390 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6391 Printexc.to_string exn
);
6397 f (Hashtbl.create
0, defconf)
6402 let pc, pb
, px, pa
=
6404 Hashtbl.find h (Filename.basename
state.path)
6405 with Not_found
-> dc, [], 0, emptyanchor
6409 state.bookmarks <- pb
;
6411 state.scrollw
<- conf.scrollbw
;
6413 then state.anchor <- pa
;
6414 cbput state.hists
.nav pa
;
6419 let add_attrs bb always
dc c =
6422 then Printf.bprintf bb
"\n %s='%b'" s a
6425 then Printf.bprintf bb
"\n %s='%d'" s a
6428 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6431 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6434 then Printf.bprintf bb
"\n %s='%f'" s a
6438 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6442 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6446 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6450 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6456 | Some
(_N
, _A
, _B
) ->
6457 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6467 else string_of_float
f
6469 Printf.bprintf bb
"\n %s='%s'" s v
6474 | Cmulti
((n, a, b), _) when n > 1 ->
6475 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6476 | Csplit
(n, _) when n > 1 ->
6477 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6483 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6488 then dc.winw, dc.winh
6490 match state.fullscreen
with
6492 | None
-> c.winw, c.winh
6494 oi
"width" w dc.winw;
6495 oi
"height" h dc.winh
;
6496 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6497 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6498 ob "case-insensitive-search" c.icase
dc.icase
;
6499 ob "preload" c.preload dc.preload;
6500 oi
"page-bias" c.pagebias
dc.pagebias
;
6501 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6502 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6503 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6504 ob "crop-hack" c.crophack
dc.crophack
;
6505 oW
"throttle" c.maxwait
dc.maxwait
;
6506 ob "highlight-links" c.hlinks
dc.hlinks
;
6507 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6508 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6509 oz
"zoom" c.zoom dc.zoom;
6510 ob "presentation" c.presentation
dc.presentation
;
6511 oi
"rotation-angle" c.angle
dc.angle
;
6512 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6513 ob "proportional-display" c.proportional
dc.proportional
;
6514 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6515 oi
"tex-count" c.texcount
dc.texcount
;
6516 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6517 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6518 ob "persistent-location" c.jumpback
dc.jumpback
;
6519 oc
"background-color" c.bgcolor
dc.bgcolor
;
6520 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6521 oi
"tile-width" c.tilew
dc.tilew
;
6522 oi
"tile-height" c.tileh
dc.tileh
;
6523 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6524 ob "checkers" c.checkers
dc.checkers
;
6525 oi
"aalevel" c.aalevel
dc.aalevel
;
6526 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6527 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6528 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6529 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6530 oC
"color-space" c.colorspace
dc.colorspace
;
6531 ob "invert-colors" c.invert
dc.invert
;
6532 oF
"brightness" c.colorscale
dc.colorscale
;
6533 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6534 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6535 oco
"columns" c.columns
dc.columns
;
6536 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6537 os
"selection-command" c.selcmd
dc.selcmd
;
6538 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6539 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6540 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6541 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6542 ob "multi-column-centering" c.multicenter
dc.multicenter
;
6545 let keymapsbuf always
dc c =
6546 let bb = Buffer.create
16 in
6547 let rec loop = function
6549 | (modename, h) :: rest
->
6550 let dh = findkeyhash dc modename in
6551 if always
|| h <> dh
6553 if Hashtbl.length
h > 0
6555 if Buffer.length
bb > 0
6556 then Buffer.add_char
bb '
\n'
;
6557 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6558 Hashtbl.iter
(fun i
o ->
6559 let isdifferent = always
||
6561 let dO = Hashtbl.find dh i
in
6563 with Not_found
-> true
6568 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6569 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6570 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6571 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6572 Buffer.add_string
bb (Wsi.keyname
k);
6575 let rec loop = function
6577 | km
:: [] -> addkm km
6578 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6582 Buffer.add_string
bb "<map in='";
6586 Buffer.add_string
bb "' out='";
6588 Buffer.add_string
bb "'/>\n"
6591 Buffer.add_string
bb "' out='";
6593 Buffer.add_string
bb "'/>\n"
6595 | KMmulti
(ins, kms
) ->
6596 Buffer.add_char
bb ' '
;
6598 Buffer.add_string
bb "' out='";
6600 Buffer.add_string
bb "'/>\n"
6602 Buffer.add_string
bb "</keymap>";
6612 let uifontsize = fstate.fontsize
in
6613 let bb = Buffer.create
32768 in
6615 let dc = if conf.bedefault
then conf else dc in
6616 Buffer.add_string
bb "<llppconfig>\n";
6618 if String.length
!fontpath > 0
6620 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6626 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6629 Buffer.add_string
bb "<defaults ";
6630 add_attrs bb true dc dc;
6631 let kb = keymapsbuf true dc dc in
6632 if Buffer.length
kb > 0
6634 Buffer.add_string
bb ">\n";
6635 Buffer.add_buffer
bb kb;
6636 Buffer.add_string
bb "\n</defaults>\n";
6638 else Buffer.add_string
bb "/>\n";
6640 let adddoc path pan
anchor c bookmarks =
6641 if bookmarks == [] && c = dc && anchor = emptyanchor
6644 Printf.bprintf
bb "<doc path='%s'"
6645 (enent
path 0 (String.length
path));
6647 if anchor <> emptyanchor
6649 let n, rely, visy
= anchor in
6650 Printf.bprintf
bb " page='%d'" n;
6653 Printf.bprintf
bb " rely='%f'" rely
6655 if abs_float visy
> 1e-6
6657 Printf.bprintf
bb " visy='%f'" visy
6662 then Printf.bprintf
bb " pan='%d'" pan
;
6664 add_attrs bb false dc c;
6665 let kb = keymapsbuf false dc c in
6667 begin match bookmarks with
6669 if Buffer.length
kb > 0
6671 Buffer.add_string
bb ">\n";
6672 Buffer.add_buffer
bb kb;
6673 Buffer.add_string
bb "\n</doc>\n";
6675 else Buffer.add_string
bb "/>\n"
6677 Buffer.add_string
bb ">\n<bookmarks>\n";
6678 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6680 "<item title='%s' page='%d'"
6681 (enent
title 0 (String.length
title))
6686 Printf.bprintf
bb " rely='%f'" rely
6688 if abs_float visy
> 1e-6
6690 Printf.bprintf
bb " visy='%f'" visy
6692 Buffer.add_string
bb "/>\n";
6694 Buffer.add_string
bb "</bookmarks>";
6695 if Buffer.length
kb > 0
6697 Buffer.add_string
bb "\n";
6698 Buffer.add_buffer
bb kb;
6700 Buffer.add_string
bb "\n</doc>\n";
6706 match state.mode with
6707 | Birdseye
(c, pan, _, _, _) ->
6709 match conf.columns
with
6710 | Cmulti
((c, _, _), _) -> Some
c
6714 match c.columns
with
6715 | Cmulti
(c, _) -> Cmulti
(c, [||])
6716 | Csingle
_ -> Csingle
[||]
6717 | Csplit
_ -> failwith
"quit from bird's eye while split"
6719 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6720 | _ -> state.x, conf
6722 let basename = Filename.basename state.path in
6723 adddoc basename pan (getanchor ())
6725 let autoscrollstep =
6726 match state.autoscroll
with
6728 | None
-> conf.autoscrollstep
6730 match state.mode with
6731 | Birdseye
(bc
, _, _, _, _) ->
6734 presentation
= bc
.presentation
;
6735 interpagespace
= bc
.interpagespace
;
6736 maxwait
= bc
.maxwait
;
6737 autoscrollstep = autoscrollstep }
6738 | _ -> { conf with autoscrollstep = autoscrollstep }
6740 (if conf.savebmarks
then state.bookmarks else []);
6742 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6744 then adddoc path x anchor c bookmarks
6746 Buffer.add_string
bb "</llppconfig>";
6749 if Buffer.length
bb > 0
6752 let tmp = !confpath ^
".tmp" in
6753 let oc = open_out_bin
tmp in
6754 Buffer.output_buffer
oc bb;
6756 Unix.rename
tmp !confpath;
6759 ("error while saving configuration: " ^
Printexc.to_string exn
)
6764 let trimcachepath = ref "" in
6767 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6768 "<password> Set password");
6770 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6771 "<path> Set path to the user interface font");
6773 ("-c", Arg.String
(fun s -> Config.confpath := s),
6774 "<path> Set path to the configuration file");
6776 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6777 "<path> Set path to the trim cache file");
6779 ("-v", Arg.Unit
(fun () ->
6781 "%s\nconfiguration path: %s\n"
6785 exit
0), " Print version and exit");
6788 (fun s -> state.path <- s)
6789 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6791 if String.length
state.path = 0
6792 then (prerr_endline
"file name missing"; exit
1);
6796 let globalkeyhash = findkeyhash conf "global" in
6797 let wsfd, winw, winh
= Wsi.init
(object
6799 if nogeomcmds state.geomcmds
|| platform == Posx
6802 GlClear.color (scalecolor2 conf.bgcolor
);
6803 GlClear.clear
[`
color];
6805 method display = display ()
6806 method reshape w h = reshape w h
6807 method mouse b d x y m = mouse b d x y m
6808 method motion x y = state.mpos
<- (x, y); motion x y
6809 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6811 let mascm = m land (
6812 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6814 match state.keystate
with
6816 let km = k, mascm in
6819 let modehash = state.uioh#
modehash in
6820 try Hashtbl.find modehash km
6822 try Hashtbl.find globalkeyhash km
6823 with Not_found
-> KMinsrt
(k, m)
6825 | KMinsrt
(k, m) -> keyboard k m
6826 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6827 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6829 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6830 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6831 state.keystate
<- KSnone
6832 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6833 state.keystate
<- KSinto
(keys
, insrt
)
6835 state.keystate
<- KSnone
6837 method enter
x y = state.mpos
<- (x, y); pmotion x y
6838 method leave = state.mpos
<- (-1, -1)
6839 method quit
= raise Quit
6840 end) conf.winw conf.winh
(platform = Posx
) in
6845 List.exists
GlMisc.check_extension
6846 [ "GL_ARB_texture_rectangle"
6847 ; "GL_EXT_texture_recangle"
6848 ; "GL_NV_texture_rectangle" ]
6850 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6853 match Ne.pipe () with
6855 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6859 match Ne.pipe () with
6861 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6871 setcheckers conf.checkers
;
6875 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6876 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6877 !Config.fontpath, !trimcachepath
6881 state.text <- "Opening " ^
state.path;
6883 opendoc state.path state.password
;
6886 let rec loop deadline
=
6888 match state.errfd
with
6889 | None
-> [state.sr
; state.wsfd]
6890 | Some fd
-> [state.sr
; state.wsfd; fd
]
6894 state.redisplay
<- false;
6901 if deadline
= infinity
6903 else max
0.0 (deadline
-. now)
6908 try Unix.select
r [] [] timeout
6909 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6915 if state.ghyll
== noghyll
6917 match state.autoscroll
with
6918 | Some step
when step
!= 0 ->
6919 let y = state.y + step
in
6923 else if y >= state.maxy then 0 else y
6926 if state.mode = View
6927 then state.text <- "";
6930 else deadline
+. 0.01
6935 let rec checkfds = function
6937 | fd
:: rest
when fd
= state.sr
->
6938 let cmd = readcmd state.sr
in
6942 | fd
:: rest
when fd
= state.wsfd ->
6947 let s = String.create
80 in
6948 let n = Unix.read fd
s 0 80 in
6949 if conf.redirectstderr
6951 Buffer.add_substring
state.errmsgs
s 0 n;
6952 state.newerrmsgs
<- true;
6953 state.redisplay
<- true;
6956 prerr_string
(String.sub
s 0 n);
6964 if deadline
= infinity
6968 match state.autoscroll
with
6969 | Some step
when step
!= 0 -> deadline1
6970 | _ -> if state.ghyll
== noghyll then infinity
else deadline1