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
341 | Csingle
of singlecolumn
342 | Cmulti
of multicolumns
343 | Csplit
of splitcolumns
346 type anchor
= pageno
* top
* dtop
;;
348 type outline
= string * int * anchor
;;
350 type rect
= float * float * float * float * float * float * float * float;;
352 type tile
= opaque
* pixmapsize
* elapsed
353 and elapsed
= float;;
354 type pagemapkey
= pageno
* gen
;;
355 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
359 let emptyanchor = (0, 0.0, 0.0);;
361 type infochange
= | Memused
| Docinfo
| Pdim
;;
363 class type uioh
= object
364 method display
: unit
365 method key
: int -> int -> uioh
366 method button
: int -> bool -> int -> int -> int -> uioh
367 method motion
: int -> int -> uioh
368 method pmotion
: int -> int -> uioh
369 method infochanged
: infochange
-> unit
370 method scrollpw
: (int * float * float)
371 method scrollph
: (int * float * float)
372 method modehash
: keyhash
376 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
377 | Textentry
of (textentry
* onleave
)
379 | LinkNav
of linktarget
380 and onleave
= leavetextentrystatus
-> unit
381 and leavetextentrystatus
= | Cancel
| Confirm
382 and helpitem
= string * int * action
385 | Action
of (uioh
-> uioh
)
387 | Ltexact
of (pageno
* int)
391 let isbirdseye = function Birdseye _
-> true | _
-> false;;
392 let istextentry = function Textentry _
-> true | _
-> false;;
396 | Loading
of (page
* gen
)
398 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
400 | Outlining
of outline list
403 let emptykeyhash = Hashtbl.create
0;;
404 let nouioh : uioh
= object (self
)
406 method key _ _
= self
407 method button _ _ _ _ _
= self
408 method motion _ _
= self
409 method pmotion _ _
= self
410 method infochanged _
= ()
411 method scrollpw
= (0, nan
, nan
)
412 method scrollph
= (0, nan
, nan
)
413 method modehash
= emptykeyhash
417 { mutable sr
: Unix.file_descr
418 ; mutable sw
: Unix.file_descr
419 ; mutable wsfd
: Unix.file_descr
420 ; mutable errfd
: Unix.file_descr
option
421 ; mutable stderr
: Unix.file_descr
422 ; mutable errmsgs
: Buffer.t
423 ; mutable newerrmsgs
: bool
427 ; mutable scrollw
: int
428 ; mutable hscrollh
: int
429 ; mutable anchor
: anchor
430 ; mutable ranchors
: (string * string * anchor
) list
432 ; mutable layout
: page list
433 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
434 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
435 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
436 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
437 ; mutable pagecount
: int
438 ; mutable currently
: currently
439 ; mutable mstate
: mstate
440 ; mutable searchpattern
: string
441 ; mutable rects
: (pageno
* recttype
* rect
) list
442 ; mutable rects1
: (pageno
* recttype
* rect
) list
443 ; mutable text
: string
444 ; mutable fullscreen
: (width
* height
) option
445 ; mutable mode
: mode
446 ; mutable uioh
: uioh
447 ; mutable outlines
: outline array
448 ; mutable bookmarks
: outline list
449 ; mutable path
: string
450 ; mutable password
: string
451 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
452 ; mutable memused
: memsize
454 ; mutable throttle
: (page list
* int * float) option
455 ; mutable autoscroll
: int option
456 ; mutable ghyll
: (int option -> unit)
457 ; mutable help
: helpitem array
458 ; mutable docinfo
: (int * string) list
459 ; mutable texid
: GlTex.texture_id
option
461 ; mutable prevzoom
: float
462 ; mutable progress
: float
463 ; mutable redisplay
: bool
464 ; mutable mpos
: mpos
465 ; mutable keystate
: keystate
466 ; mutable glinks
: bool
467 ; mutable prevcolumns
: (columns
* float) option
470 { pat
: string circbuf
471 ; pag
: string circbuf
472 ; nav
: anchor circbuf
473 ; sel
: string circbuf
495 ; presentation
= false
500 ; proportional
= true
501 ; trimmargins
= false
502 ; trimfuzz
= (0,0,0,0)
503 ; memlimit
= 32 lsl 20
508 ; bgcolor
= (0.5, 0.5, 0.5)
510 ; scrollbarinpm
= true
513 ; mustoresize
= 256 lsl 20
518 | Plinux
| Pfreebsd
| Pdragonflybsd
519 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
520 | Posx
-> "open \"%s\""
521 | Pcygwin
-> "cygstart \"%s\""
522 | Punknown
-> "echo %s")
523 ; pathlauncher
= "lp \"%s\""
526 | Plinux
| Pfreebsd
| Pdragonflybsd
527 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
534 ; redirectstderr
= false
536 ; columns
= Csingle
[||]
542 let mk n
= (n
, Hashtbl.create
1) in
556 let findkeyhash c name
=
557 try List.assoc name c
.keyhashes
558 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
561 let conf = { defconf with angle
= defconf.angle
};;
563 let pgscale h
= truncate
(float h
*. conf.pgscale);;
566 { mutable fontsize
: int
567 ; mutable wwidth
: float
568 ; mutable maxrows
: int
580 fstate.fontsize
<- n
;
581 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
582 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
586 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
587 let len = String.length s
in
588 if colonpos >= 0 && colonpos + 3 < len
590 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
593 try String.rindex_from s
colonpos ' '
597 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
600 | "http" | "ftp" | "mailto" ->
602 try String.index_from s
colonpos ' '
603 with Not_found
-> len
605 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
613 if String.length
conf.urilauncher
= 0
614 then print_endline uri
616 let url = geturl uri
in
617 if String.length
url = 0
618 then print_endline uri
620 let re = Str.regexp
"%s" in
621 let command = Str.global_replace
re url conf.urilauncher
in
625 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
631 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
632 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
636 let strings = version () :: "" :: Help.keys
in
639 let url = geturl s
in
640 if String.length
url > 0
641 then (s
, 0, Action
(fun u
-> gotouri url; u
))
642 else (s
, 0, Noaction
)
647 let firstgeomcmds = "", [];;
654 ; stderr
= Unix.stderr
655 ; errmsgs
= Buffer.create
0
662 ; anchor
= emptyanchor
666 ; tilelru
= Queue.create
()
667 ; pagemap
= Hashtbl.create
10
668 ; tilemap
= Hashtbl.create
10
683 ; geomcmds
= firstgeomcmds
685 { nav
= cbnew 10 emptyanchor
712 Printf.kprintf prerr_endline fmt
714 Printf.kprintf ignore fmt
718 if String.length
conf.pathlauncher
= 0
719 then print_endline
state.path
721 let re = Str.regexp
"%s" in
722 let command = Str.global_replace
re state.path
conf.pathlauncher
in
726 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
732 type 'a t
= | Res
of 'a
| Exn
of exn
;;
735 try Res
(Unix.pipe ())
741 with exn
-> f
(Printexc.to_string exn
)
745 try Res
(Unix.dup fd
)
750 try Res
(Unix.dup2 fd1 fd2
)
755 let redirectstderr () =
756 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
757 if conf.redirectstderr
759 match Ne.pipe () with
761 dolog "failed to create stderr redirection pipes: %s"
762 (Printexc.to_string exn
)
765 begin match Ne.dup Unix.stderr
with
767 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
768 Ne.clo r
(clofail "pipe/r");
769 Ne.clo w
(clofail "pipe/w");
771 | Ne.Res dupstderr
->
772 begin match Ne.dup2 w
Unix.stderr
with
774 dolog "failed to dup2 to stderr: %s"
775 (Printexc.to_string exn
);
776 Ne.clo dupstderr
(clofail "stderr duplicate");
777 Ne.clo r
(clofail "redir pipe/r");
778 Ne.clo w
(clofail "redir pipe/w");
781 state.stderr
<- dupstderr
;
782 state.errfd
<- Some r
;
786 state.newerrmsgs
<- false;
787 begin match state.errfd
with
789 begin match Ne.dup2 state.stderr
Unix.stderr
with
791 dolog "failed to dup2 original stderr: %s"
792 (Printexc.to_string exn
)
794 Ne.clo fd
(clofail "dup of stderr");
795 Unix.dup2 state.stderr
Unix.stderr
;
800 prerr_string
(Buffer.contents
state.errmsgs
);
802 Buffer.clear
state.errmsgs
;
808 let postRedisplay who
=
810 then prerr_endline
("redisplay for " ^ who
);
811 state.redisplay
<- true;
815 let getopaque pageno
=
816 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
817 with Not_found
-> None
820 let putopaque pageno opaque
=
821 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
824 let pagetranslatepoint l x y
=
825 let dy = y
- l
.pagedispy
in
826 let y = dy + l
.pagey
in
827 let dx = x
- l
.pagedispx
in
828 let x = dx + l
.pagex
in
835 begin match getopaque l
.pageno
with
837 let x0 = l
.pagedispx
in
838 let x1 = x0 + l
.pagevw
in
839 let y0 = l
.pagedispy
in
840 let y1 = y0 + l
.pagevh
in
841 if y >= y0 && y <= y1 && x >= x0 && x <= x1
843 let px, py
= pagetranslatepoint l
x y in
844 match whatsunder opaque
px py
with
857 state.text
<- Printf.sprintf
"%c%s" c s
;
858 G.postRedisplay "showtext";
861 let undertext = function
864 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
865 | Utext s
-> "font: " ^ s
866 | Uunexpected s
-> "unexpected: " ^ s
867 | Ulaunch s
-> "launch: " ^ s
868 | Unamed s
-> "named: " ^ s
869 | Uremote
(filename
, pageno
) ->
870 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
873 let updateunder x y =
874 match getunder x y with
875 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
877 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
878 Wsi.setcursor
Wsi.CURSOR_INFO
879 | Ulinkgoto
(pageno
, _
) ->
881 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
882 Wsi.setcursor
Wsi.CURSOR_INFO
884 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
885 Wsi.setcursor
Wsi.CURSOR_TEXT
887 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
888 Wsi.setcursor
Wsi.CURSOR_INHERIT
890 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
891 Wsi.setcursor
Wsi.CURSOR_INHERIT
893 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
894 Wsi.setcursor
Wsi.CURSOR_INHERIT
895 | Uremote
(filename
, pageno
) ->
896 if conf.underinfo
then showtext 'r'
897 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
898 Wsi.setcursor
Wsi.CURSOR_INFO
901 let showlinktype under
=
907 let s = undertext under
in
912 let b = Buffer.create
(String.length
s + 1) in
913 Buffer.add_string
b s;
918 let colorspace_of_string s =
919 match String.lowercase
s with
923 | _
-> failwith
"invalid colorspace"
926 let int_of_colorspace = function
932 let colorspace_of_int = function
936 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
939 let colorspace_to_string = function
945 let intentry_with_suffix text key
=
947 if key
>= 32 && key
< 127
951 match Char.lowercase
c with
953 let text = addchar text c in
957 let text = addchar text c in
961 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
965 let multicolumns_to_string (n
, a
, b) =
967 then Printf.sprintf
"%d" n
968 else Printf.sprintf
"%d,%d,%d" n a
b;
971 let multicolumns_of_string s =
973 (int_of_string
s, 0, 0)
975 Scanf.sscanf
s "%u,%u,%u" (fun n a
b -> (n
, a
, b));
980 let n = Unix.read fd
s 0 4 in
981 if n != 4 then failwith
"incomplete read(len)";
983 lor (Char.code
s.[0] lsl 24)
984 lor (Char.code
s.[1] lsl 16)
985 lor (Char.code
s.[2] lsl 8)
986 lor (Char.code
s.[3] lsl 0)
988 let s = String.create
len in
989 let n = Unix.read fd
s 0 len in
990 if n != len then failwith
"incomplete read(data)";
994 let btod b = if b then 1 else 0;;
997 let b = Buffer.create
16 in
998 Buffer.add_string
b "llll";
1001 let s = Buffer.contents
b in
1002 let n = String.length
s in
1004 (* dolog "wcmd %S" (String.sub s 4 len); *)
1005 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1006 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1007 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1008 s.[3] <- Char.chr
(len land 0xff);
1009 let n'
= Unix.write
state.sw
s 0 n in
1010 if n'
!= n then failwith
"write failed";
1015 if conf.presentation
1017 let d = conf.winh
- h
in
1018 max
conf.interpagespace
((d + 1) / 2)
1024 match conf.columns
with
1025 | Cmulti
((c, _
, _
), b) ->
1026 let rec loop y h
n =
1030 if n = Array.length
b
1033 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
1039 loop max_int
0 (((Array.length
b - 1) / c) * c)
1041 if Array.length
b > 0
1043 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1044 y + h
+ (if conf.presentation
then calcips h
else 0)
1047 if Array.length
b > 0
1049 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1054 let getpageyh pageno
=
1055 let pageno = bound pageno 0 (state.pagecount
-1) in
1056 match conf.columns
with
1058 let (_
, _
, y, (_
, _
, h
, _
)) = b.(pageno) in
1060 if conf.presentation
1066 let (_
, _
, y, (_
, _
, h
, _
)) = b.(pageno) in
1070 let (_
, _
, y, (_
, _
, h
, _
)) = b.(n) in
1074 let getpagedim pageno =
1077 | (n, _
, _
, _
) as pdim
:: rest
->
1079 then (if n = pageno then pdim
else ppdim
)
1084 f (-1, -1, -1, -1) state.pdims
1087 let getpagey pageno = fst
(getpageyh pageno);;
1089 let nogeomcmds cmds
=
1091 | s, [] -> String.length
s = 0
1095 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1096 let sh = sh - state.hscrollh
in
1097 let rec fold accu
n =
1098 if n = Array.length
b
1101 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
1104 || n = state.pagecount
- coverB
1105 || (n - coverA
) mod columns
= columns
- 1)
1111 let pagey = max
0 (y - vy
) in
1112 let pagedispy = if pagey > 0 then 0 else vy
- y in
1113 let pagedispx, pagex
=
1115 if n = coverA
- 1 || n = state.pagecount
- coverB
1116 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1117 else dx + xoff
+ state.x
1124 let vw = conf.winw
- state.scrollw
- pagedispx in
1125 let pw = w
- pagex
in
1128 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1129 if pagevw > 0 && pagevh > 0
1133 ; pagedimno
= pdimno
1140 ; pagedispx = pagedispx
1141 ; pagedispy = pagedispy
1153 List.rev
(fold [] 0)
1156 let layoutS (columns
, b) y sh =
1157 let sh = sh - state.hscrollh
in
1158 let rec fold accu n =
1159 if n = Array.length
b
1162 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
1169 let x = xoff
+ state.x in
1170 let pagey = max
0 (y - vy
) in
1171 let pagedispy = if pagey > 0 then 0 else vy
- y in
1172 let pagedispx, pagex
=
1186 let pagecolw = pagew
/columns
in
1188 if pagecolw < conf.winw
1189 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1193 let vw = conf.winw
- pagedispx - state.scrollw
in
1194 let pw = pagew
- pagex
in
1197 let pagevw = min
pagevw pagecolw in
1198 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1199 if pagevw > 0 && pagevh > 0
1202 { pageno = n/columns
1203 ; pagedimno
= pdimno
1210 ; pagedispx = pagedispx
1211 ; pagedispy = pagedispy
1212 ; pagecol
= n mod columns
1223 List.rev
(fold [] 0)
1227 if nogeomcmds state.geomcmds
1229 match conf.columns
with
1230 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1231 | Cmulti
c -> layoutN c y sh
1232 | Csplit
s -> layoutS s y sh
1237 let y = state.y + incr
in
1239 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1244 let tilex = l
.pagex
mod conf.tilew
in
1245 let tiley = l
.pagey mod conf.tileh
in
1247 let col = l
.pagex
/ conf.tilew
in
1248 let row = l
.pagey / conf.tileh
in
1250 let rec rowloop row y0 dispy h
=
1254 let dh = conf.tileh
- y0 in
1255 let dh = min h
dh in
1256 let rec colloop col x0 dispx w
=
1260 let dw = conf.tilew
- x0 in
1261 let dw = min w
dw in
1263 f col row dispx dispy
x0 y0 dw dh;
1264 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1267 colloop col tilex l
.pagedispx l
.pagevw;
1268 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1271 if l
.pagevw > 0 && l
.pagevh > 0
1272 then rowloop row tiley l
.pagedispy l
.pagevh;
1275 let gettileopaque l
col row =
1277 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1279 try Some
(Hashtbl.find
state.tilemap
key)
1280 with Not_found
-> None
1283 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1284 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1285 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1288 let drawtiles l color
=
1290 let f col row x y tilex tiley w h
=
1291 match gettileopaque l
col row with
1292 | Some
(opaque
, _
, t
) ->
1293 let params = x, y, w
, h
, tilex, tiley in
1297 GlFunc.blend_func `zero `one_minus_src_color
;
1299 drawtile
params opaque
;
1301 then Gl.disable `blend
;
1304 let s = Printf.sprintf
1308 let w = measurestr
fstate.fontsize
s in
1309 GlMisc.push_attrib
[`current
];
1310 GlDraw.color
(0.0, 0.0, 0.0);
1312 (float (x-2), float (y-2))
1313 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1314 GlDraw.color
(1.0, 1.0, 1.0);
1315 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1316 GlMisc.pop_attrib
();
1321 let lw = conf.winw
- state.scrollw
- x in
1324 let lh = conf.winh
- y in
1327 begin match state.texid
with
1329 Gl.enable `texture_2d
;
1330 GlTex.bind_texture `texture_2d id
;
1333 and x1 = float (x+w)
1334 and y1 = float (y+h
) in
1336 let tw = float w /. 64.0
1337 and th
= float h
/. 64.0 in
1338 let tx0 = float tilex /. 64.0
1339 and ty0
= float tiley /. 64.0 in
1341 and ty1
= ty0
+. th
in
1342 GlDraw.begins `quads
;
1343 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1344 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1345 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1346 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1349 Gl.disable `texture_2d
;
1351 GlDraw.color
(1.0, 1.0, 1.0);
1354 (float (x+w), float (y+h
));
1356 if w > 128 && h
> fstate.fontsize
+ 10
1358 GlDraw.color
(0.0, 0.0, 0.0);
1361 then (col*conf.tilew
, row*conf.tileh
)
1364 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r
;
1371 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1373 let tilevisible1 l
x y =
1375 and ax1
= l
.pagex
+ l
.pagevw
1377 and ay1
= l
.pagey + l
.pagevh in
1381 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1382 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1384 let rx0 = max
ax0 bx0
1385 and ry0
= max ay0 by0
1386 and rx1
= min ax1
bx1
1387 and ry1
= min ay1 by1
in
1389 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1390 nonemptyintersection
1393 let tilevisible layout n x y =
1394 let rec findpageinlayout m
= function
1395 | l
:: rest
when l
.pageno = n ->
1396 tilevisible1 l
x y || (
1397 match conf.columns
with
1398 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1401 | _
:: rest
-> findpageinlayout 0 rest
1404 findpageinlayout 0 layout;
1407 let tileready l
x y =
1408 tilevisible1 l
x y &&
1409 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1412 let tilepage n p
layout =
1413 let rec loop = function
1417 let f col row _ _ _ _ _ _
=
1418 if state.currently
= Idle
1420 match gettileopaque l
col row with
1423 let x = col*conf.tilew
1424 and y = row*conf.tileh
in
1426 let w = l
.pagew
- x in
1430 let h = l
.pageh
- y in
1433 wcmd "tile %s %d %d %d %d" p
x y w h;
1436 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1437 conf.tilew
, conf.tileh
1446 if nogeomcmds state.geomcmds
1452 match conf.columns
with
1454 | Cmulti
(_
, b) -> b
1455 | Csplit
(_
, b) -> b
1457 let rec bsearch nmin nmax
=
1461 let n = (nmax
+ nmin
) / 2 in
1462 let _, _, vy
, (_, h, _, _) = b.(n) in
1464 if conf.presentation
1466 let ips = calcips h in
1467 let y0 = vy
- ips in
1468 let y1 = vy
+ h + ips in
1472 then 0, vy
+ h + conf.interpagespace
1474 let y0 = vy
- conf.interpagespace
in
1478 if y >= y0 && y < y1
1482 then bsearch (n+1) nmax
1483 else bsearch nmin
(n-1)
1486 let r = bsearch 0 (state.pagecount
-1) in
1490 let preloadlayout _ =
1491 let y = if state.y < conf.winh
then 0 else state.y - conf.winh
in
1492 let h = conf.winh
*3 in
1497 let rec loop pages
=
1498 if state.currently
!= Idle
1503 begin match getopaque l
.pageno with
1505 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1506 state.currently
<- Loading
(l
, state.gen
);
1508 tilepage l
.pageno opaque pages
;
1513 if nogeomcmds state.geomcmds
1519 if conf.preload && state.currently
= Idle
1520 then load (preloadlayout pages
);
1523 let layoutready layout =
1524 let rec fold all ls
=
1525 all
&& match ls
with
1527 let seen = ref false in
1528 let allvisible = ref true in
1529 let foo col row _ _ _ _ _ _ =
1531 allvisible := !allvisible &&
1532 begin match gettileopaque l
col row with
1538 fold (!seen && !allvisible) rest
1541 let alltilesvisible = fold true layout in
1546 let y = bound y 0 state.maxy
in
1547 let y, layout, proceed
=
1548 match conf.maxwait
with
1549 | Some time
when state.ghyll
== noghyll ->
1550 begin match state.throttle
with
1552 let layout = layout y conf.winh
in
1553 let ready = layoutready layout in
1557 state.throttle
<- Some
(layout, y, now ());
1559 else G.postRedisplay "gotoy showall (None)";
1561 | Some
(_, _, started
) ->
1562 let dt = now () -. started
in
1565 state.throttle
<- None
;
1566 let layout = layout y conf.winh
in
1568 G.postRedisplay "maxwait";
1575 let layout = layout y conf.winh
in
1576 if true || layoutready layout
1577 then G.postRedisplay "gotoy ready";
1583 state.layout <- layout;
1584 begin match state.mode
with
1585 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1586 let rec loop = function
1588 state.mode
<- LinkNav
(Ltgendir
0)
1589 | l
:: _ when l
.pageno = pageno ->
1590 begin match getopaque pageno with
1592 state.mode
<- LinkNav
(Ltgendir
0)
1594 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1595 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1596 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1597 then state.mode
<- LinkNav
(Ltgendir
0)
1599 | _ :: rest
-> loop rest
1604 begin match state.mode
with
1605 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1606 if not
(pagevisible layout pageno)
1608 match state.layout with
1611 state.mode
<- Birdseye
(
1612 conf, leftx
, l
.pageno, hooverpageno
, anchor
1615 | LinkNav
(Ltgendir dir
as lt
) ->
1617 let rec loop = function
1620 match getopaque l
.pageno with
1626 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1628 if dir
> 0 then LDfirst
else LDlast
1634 | Lnotfound
-> loop rest
1636 showlinktype (getlink opaque
n);
1637 Ltexact
(l
.pageno, n)
1641 state.mode
<- LinkNav
linknav
1646 state.ghyll
<- noghyll;
1649 let mx, my
= state.mpos
in
1654 let conttiling pageno opaque
=
1655 tilepage pageno opaque
1656 (if conf.preload then preloadlayout state.layout else state.layout)
1659 let gotoy_and_clear_text y =
1660 if not
conf.verbose
then state.text <- "";
1666 let coloff = l
.pagecol
* l
.pageh
in
1667 float (l
.pagey + coloff) /. float l
.pageh
1674 if conf.presentation
1675 then float l
.pagedispy /. float (calcips l
.pageh
)
1676 else float l
.pagedispy /. float conf.interpagespace
1678 (l
.pageno, top, dtop)
1682 match state.layout with
1683 | l
:: _ -> getanchor1 l
1685 let n = page_of_y state.y in
1686 let y, h = getpageyh n in
1687 let dy = y - state.y in
1689 if conf.presentation
1691 let ips = calcips h in
1692 float (dy + ips) /. float ips
1694 float dy /. float conf.interpagespace
1699 let getanchory (n, top, dtop) =
1700 let y, h = getpageyh n in
1701 if conf.presentation
1703 let ips = calcips h in
1704 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1706 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1709 let gotoanchor anchor
=
1710 gotoy (getanchory anchor
);
1714 cbput state.hists
.nav
(getanchor ());
1718 let anchor = cbgetc state.hists
.nav dir
in
1723 let scroll f n a
b =
1724 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1726 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1728 then s (float f /. float a
)
1731 then 1.0 -. s ((float (f-b) /. float (n-b)))
1738 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1739 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1741 let ins = float a
*. iv1
1742 and outs
= float (n-b) *. iv1 in
1744 ins +. outs
+. float ones
1746 let rec set (_N
, _A
, _B
) y sy
=
1747 let sum = summa
1.0 _N _A _B
in
1748 let dy = float (y - sy
) in
1752 then state.ghyll
<- noghyll
1755 let s = scroll n _N _A _B
in
1756 let y1 = y1 +. ((s *. dy) /. sum) in
1757 gotoy_and_clear_text (truncate
y1);
1758 state.ghyll
<- gf (n+1) y1;
1762 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1764 gf 0 (float state.y)
1767 match conf.ghyllscroll
with
1769 gotoy_and_clear_text y
1771 if state.ghyll
== noghyll
1772 then set nab
y state.y
1773 else state.ghyll
(Some
y)
1776 let gotopage n top =
1777 let y, h = getpageyh n in
1778 let y = y + (truncate
(top *. float h)) in
1782 let gotopage1 n top =
1783 let y = getpagey n in
1788 let invalidate s f =
1793 match state.geomcmds
with
1794 | ps
, [] when String.length ps
= 0 ->
1796 state.geomcmds
<- s, [];
1799 state.geomcmds
<- ps
, [s, f];
1801 | ps
, (s'
, _) :: rest
when s'
= s ->
1802 state.geomcmds
<- ps
, ((s, f) :: rest
);
1805 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1808 let opendoc path password
=
1810 state.password
<- password
;
1811 state.gen
<- state.gen
+ 1;
1812 state.docinfo
<- [];
1814 setaalevel
conf.aalevel
;
1815 Wsi.settitle
("llpp " ^
Filename.basename path
);
1816 wcmd "open %s\000%s\000" path password
;
1817 invalidate "reqlayout"
1819 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1823 let c = c *. conf.colorscale
in
1827 let scalecolor2 (r, g
, b) =
1828 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1831 let docolumns = function
1833 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1834 let rec loop pageno pdimno pdim
y ph pdims
=
1835 if pageno = state.pagecount
1838 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1840 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1841 pdimno+1, pdim
, rest
1845 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1847 (if conf.presentation
1848 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1849 else (if pageno = 0 then 0 else calcips h)
1852 a.(pageno) <- (pdimno, x, y, pdim
);
1853 loop (pageno+1) pdimno pdim
(y + h) h pdims
1855 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1856 conf.columns
<- Csingle
a;
1858 | Cmulti
((columns
, coverA
, coverB
), _) ->
1859 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1860 let rec loop pageno pdimno pdim
x y rowh pdims
=
1861 let rec fixrow m
= if m
= pageno then () else
1862 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1865 let y = y + (rowh
- h) / 2 in
1866 a.(m
) <- (pdimno, x, y, pdim
);
1870 if pageno = state.pagecount
1871 then fixrow (((pageno - 1) / columns
) * columns
)
1873 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1875 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1876 pdimno+1, pdim
, rest
1881 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1883 (conf.winw
- state.scrollw
- w) / 2,
1884 y + rowh
+ conf.interpagespace
, h
1887 if (pageno - coverA
) mod columns
= 0
1889 (conf.winw
- state.scrollw
- state.w) / 2,
1890 y + rowh
+ (if pageno = 0 then 0 else conf.interpagespace
), h
1892 else x, y, max rowh
h
1895 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1896 then fixrow (pageno - columns
);
1897 a.(pageno) <- (pdimno, x, y, pdim
);
1898 let x = x + w + xoff
*2 + conf.interpagespace
in
1899 loop (pageno+1) pdimno pdim
x y rowh' pdims
1901 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1902 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1905 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1906 let rec loop pageno pdimno pdim
y pdims
=
1907 if pageno = state.pagecount
1910 let pdimno, ((_, w, h, _) as pdim
), pdims
=
1912 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1913 pdimno+1, pdim
, rest
1918 let rec loop1 n x y =
1919 if n = c then y else (
1920 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
1921 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
1924 let y = loop1 0 0 y in
1925 loop (pageno+1) pdimno pdim
y pdims
1927 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1928 conf.columns
<- Csplit
(c, a);
1932 docolumns conf.columns
;
1933 state.maxy
<- calcheight ();
1935 if state.w <= conf.winw
- state.scrollw
1939 match state.mode
with
1940 | Birdseye
(_, _, pageno, _, _) ->
1941 let y, h = getpageyh pageno in
1942 let top = (conf.winh
- h) / 2 in
1943 gotoy (max
0 (y - top))
1944 | _ -> gotoanchor state.anchor
1948 GlDraw.viewport
0 0 w h;
1949 let firsttime = state.geomcmds
== firstgeomcmds in
1950 if not
firsttime && nogeomcmds state.geomcmds
1951 then state.anchor <- getanchor ();
1954 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1957 setfontsize fstate.fontsize
;
1958 GlMat.mode `modelview
;
1959 GlMat.load_identity
();
1961 GlMat.mode `projection
;
1962 GlMat.load_identity
();
1963 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1964 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1965 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1970 else float state.x /. float state.w
1972 invalidate "geometry"
1976 then state.x <- truncate
(relx *. float w);
1978 match conf.columns
with
1980 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
1981 | Csplit
(c, _) -> w * c
1983 wcmd "geometry %d %d" w h);
1987 let len = String.length
state.text in
1990 match state.mode
with
1993 let h, _, _ = state.uioh#scrollpw
in
1999 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2000 (x+.w, float (conf.winh
- hscrollh))
2003 let w = float (conf.winw
- state.scrollw
- 1) in
2004 if state.progress
>= 0.0 && state.progress
< 1.0
2006 GlDraw.color
(0.3, 0.3, 0.3);
2007 let w1 = w *. state.progress
in
2009 GlDraw.color
(0.0, 0.0, 0.0);
2013 GlDraw.color
(0.0, 0.0, 0.0);
2017 GlDraw.color
(1.0, 1.0, 1.0);
2018 drawstring fstate.fontsize
2019 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2022 match state.mode
with
2023 | Textentry
((prefix
, text, _, _, _, _), _) ->
2027 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2029 Printf.sprintf
"%s%s_" prefix
text
2038 if not
(istextentry state.mode
)
2040 let s1 = "(press 'e' to review error messasges)" in
2041 if String.length
s > 0 then s ^
" " ^
s1 else s1
2046 if String.length
s > 0
2051 let len = Queue.length
state.tilelru
in
2053 match state.throttle
with
2056 then preloadlayout state.layout
2058 | Some
(layout, _, _) ->
2062 if state.memused
<= conf.memlimit
2067 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2068 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2069 let (_, pw, ph
, _) = getpagedim n in
2072 && colorspace
= conf.colorspace
2073 && angle
= conf.angle
2077 let x = col*conf.tilew
2078 and y = row*conf.tileh
in
2079 tilevisible (Lazy.force_val
layout) n x y
2081 then Queue.push lruitem
state.tilelru
2083 wcmd "freetile %s" p
;
2084 state.memused
<- state.memused
- s;
2085 state.uioh#infochanged Memused
;
2086 Hashtbl.remove
state.tilemap k
;
2095 Queue.iter
(fun (k
, p
, s) ->
2096 wcmd "freetile %s" p
;
2097 state.memused
<- state.memused
- s;
2098 state.uioh#infochanged Memused
;
2099 Hashtbl.remove
state.tilemap k
;
2101 Queue.clear
state.tilelru
;
2105 let logcurrently = function
2106 | Idle
-> dolog "Idle"
2107 | Loading
(l
, gen
) ->
2108 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2109 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2111 "Tiling %d[%d,%d] page=%s cs=%s angle"
2112 l
.pageno col row pageopaque
2113 (colorspace_to_string colorspace
)
2115 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2116 angle gen
conf.angle
state.gen
2118 conf.tilew
conf.tileh
2125 (* dolog "%S" cmds; *)
2128 try String.index cmds ' '
2129 with Not_found
-> -1
2134 let l = String.length cmds
in
2135 let op = String.sub cmds
0 spacepos in
2137 if l - spacepos < 2 then ""
2138 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2143 state.uioh#infochanged Pdim
;
2147 state.rects
<- state.rects1
;
2148 G.postRedisplay "clearrects";
2152 try Scanf.sscanf
args "%u" (fun n -> n)
2154 dolog "error processing 'continue' %S: %s"
2155 cmds
(Printexc.to_string exn
);
2158 state.pagecount
<- n;
2159 begin match state.currently
with
2161 state.currently
<- Idle
;
2162 state.outlines
<- Array.of_list
(List.rev
l)
2166 let cur, cmds
= state.geomcmds
in
2167 if String.length
cur = 0
2168 then failwith
"umpossible";
2170 begin match List.rev cmds
with
2172 state.geomcmds
<- "", [];
2176 state.geomcmds
<- s, List.rev rest
;
2178 if conf.maxwait
= None
2179 then G.postRedisplay "continue";
2189 then showtext ' '
args
2192 let progress, text =
2194 Scanf.sscanf
args "%f %n"
2196 f, String.sub
args pos
(String.length
args - pos
))
2198 dolog "error processing 'progress' %S: %s"
2199 cmds
(Printexc.to_string exn
);
2203 state.progress <- progress;
2204 G.postRedisplay "progress"
2207 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2209 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2210 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2211 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2213 dolog "error processing 'firstmatch' %S: %s"
2214 cmds
(Printexc.to_string exn
);
2217 let y = (getpagey pageno) + truncate
y0 in
2220 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2223 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2225 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2226 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2227 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2229 dolog "error processing 'match' %S: %s"
2230 cmds
(Printexc.to_string exn
);
2234 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2239 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2241 dolog "error processing 'page' %S: %s"
2242 cmds
(Printexc.to_string exn
);
2245 begin match state.currently
with
2246 | Loading
(l, gen
) ->
2247 vlog "page %d took %f sec" l.pageno t
;
2248 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2249 begin match state.throttle
with
2251 let preloadedpages =
2253 then preloadlayout state.layout
2258 Set.Make
(struct type t
= int let compare = (-) end) in
2260 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2261 IntSet.empty
preloadedpages
2264 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2265 if not
(IntSet.mem
pageno set)
2267 wcmd "freepage %s" opaque
;
2273 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2276 state.currently
<- Idle
;
2279 tilepage l.pageno pageopaque state.layout;
2281 load preloadedpages;
2282 if pagevisible state.layout l.pageno
2283 && layoutready state.layout
2284 then G.postRedisplay "page";
2287 | Some
(layout, _, _) ->
2288 state.currently
<- Idle
;
2289 tilepage l.pageno pageopaque layout;
2294 dolog "Inconsistent loading state";
2295 logcurrently state.currently
;
2300 let (x, y, opaque
, size
, t
) =
2302 Scanf.sscanf
args "%u %u %s %u %f"
2303 (fun x y p size t
-> (x, y, p
, size
, t
))
2305 dolog "error processing 'tile' %S: %s"
2306 cmds
(Printexc.to_string exn
);
2309 begin match state.currently
with
2310 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2311 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2313 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2315 wcmd "freetile %s" opaque
;
2316 state.currently
<- Idle
;
2320 puttileopaque l col row gen cs angle opaque size t
;
2321 state.memused
<- state.memused
+ size
;
2322 state.uioh#infochanged Memused
;
2324 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2325 opaque
, size
) state.tilelru
;
2328 match state.throttle
with
2329 | None
-> state.layout
2330 | Some
(layout, _, _) -> layout
2333 state.currently
<- Idle
;
2335 && conf.colorspace
= cs
2336 && conf.angle
= angle
2337 && tilevisible layout l.pageno x y
2338 then conttiling l.pageno pageopaque;
2340 begin match state.throttle
with
2342 preload state.layout;
2344 && conf.colorspace
= cs
2345 && conf.angle
= angle
2346 && tilevisible state.layout l.pageno x y
2347 then G.postRedisplay "tile nothrottle";
2349 | Some
(layout, y, _) ->
2350 let ready = layoutready layout in
2354 state.layout <- layout;
2355 state.throttle
<- None
;
2356 G.postRedisplay "throttle";
2363 dolog "Inconsistent tiling state";
2364 logcurrently state.currently
;
2371 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2373 dolog "error processing 'pdim' %S: %s"
2374 cmds
(Printexc.to_string exn
);
2377 state.uioh#infochanged Pdim
;
2378 state.pdims
<- pdim :: state.pdims
2381 let (l, n, t
, h, pos
) =
2383 Scanf.sscanf
args "%u %u %d %u %n"
2384 (fun l n t
h pos
-> l, n, t
, h, pos
)
2386 dolog "error processing 'o' %S: %s"
2387 cmds
(Printexc.to_string exn
);
2390 let s = String.sub
args pos
(String.length
args - pos
) in
2391 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2392 begin match state.currently
with
2393 | Outlining outlines
->
2394 state.currently
<- Outlining
(outline :: outlines
)
2396 state.currently
<- Outlining
[outline]
2398 dolog "invalid outlining state";
2399 logcurrently currently
2403 state.docinfo
<- (1, args) :: state.docinfo
2406 state.uioh#infochanged Docinfo
;
2407 state.docinfo
<- List.rev
state.docinfo
2410 dolog "unknown cmd `%S'" cmds
2415 let action = function
2416 | HCprev
-> cbget cb ~
-1
2417 | HCnext
-> cbget cb
1
2418 | HCfirst
-> cbget cb ~
-(cb
.rc)
2419 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2420 and cancel
() = cb
.rc <- rc
2424 let search pattern forward
=
2425 if String.length pattern
> 0
2428 match state.layout with
2431 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2433 wcmd "search %d %d %d %d,%s\000"
2434 (btod conf.icase
) pn py
(btod forward
) pattern
;
2437 let intentry text key =
2439 if key >= 32 && key < 127
2445 let text = addchar text c in
2449 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2453 let linknentry text key =
2455 if key >= 32 && key < 127
2461 let text = addchar text c in
2465 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2470 if String.length
s > 0
2473 let l = String.length
s in
2474 let rec loop pos
n = if pos
= l then n else
2475 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2476 loop (pos
+1) (n*26 + m)
2479 let rec loop n = function
2482 match getopaque l.pageno with
2483 | None
-> loop n rest
2485 let m = getlinkcount opaque
in
2488 let under = getlink opaque
n in
2491 else loop (n-m) rest
2493 loop n state.layout;
2497 let textentry text key =
2498 if key land 0xff00 = 0xff00
2500 else TEcont
(text ^
Wsi.toutf8
key)
2503 let reqlayout angle proportional
=
2504 match state.throttle
with
2506 if nogeomcmds state.geomcmds
2507 then state.anchor <- getanchor ();
2508 conf.angle
<- angle
mod 360;
2511 match state.mode
with
2512 | LinkNav
_ -> state.mode
<- View
2515 conf.proportional
<- proportional
;
2516 invalidate "reqlayout"
2517 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2521 let settrim trimmargins trimfuzz
=
2522 if nogeomcmds state.geomcmds
2523 then state.anchor <- getanchor ();
2524 conf.trimmargins
<- trimmargins
;
2525 conf.trimfuzz
<- trimfuzz
;
2526 let x0, y0, x1, y1 = trimfuzz
in
2527 invalidate "settrim"
2529 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2530 Hashtbl.iter
(fun _ opaque
->
2531 wcmd "freepage %s" opaque
;
2533 Hashtbl.clear
state.pagemap
;
2537 match state.throttle
with
2539 let zoom = max
0.01 zoom in
2540 if zoom <> conf.zoom
2542 state.prevzoom
<- conf.zoom;
2544 reshape conf.winw
conf.winh
;
2545 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2548 | Some
(layout, y, started
) ->
2550 match conf.maxwait
with
2554 let dt = now () -. started
in
2562 let setcolumns mode columns coverA coverB
=
2563 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2567 then showtext '
!'
"split mode doesn't work in bird's eye"
2569 conf.columns
<- Csplit
(-columns
, [||]);
2577 conf.columns
<- Csingle
[||];
2582 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2586 reshape conf.winw
conf.winh
;
2589 let enterbirdseye () =
2590 let zoom = float conf.thumbw
/. float conf.winw
in
2591 let birdseyepageno =
2592 let cy = conf.winh
/ 2 in
2596 let rec fold best
= function
2599 let d = cy - (l.pagedispy + l.pagevh/2)
2600 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2601 if abs
d < abs dbest
2608 state.mode
<- Birdseye
(
2609 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2612 conf.presentation
<- false;
2613 conf.interpagespace
<- 10;
2614 conf.hlinks
<- false;
2616 state.mstate
<- Mnone
;
2617 conf.maxwait
<- None
;
2619 match conf.beyecolumns
with
2622 Cmulti
((c, 0, 0), [||])
2623 | None
-> Csingle
[||]
2625 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2628 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2633 reshape conf.winw
conf.winh
;
2636 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2638 conf.zoom <- c.zoom;
2639 conf.presentation
<- c.presentation
;
2640 conf.interpagespace
<- c.interpagespace
;
2641 conf.maxwait
<- c.maxwait
;
2642 conf.hlinks
<- c.hlinks
;
2643 conf.beyecolumns
<- (
2644 match conf.columns
with
2645 | Cmulti
((c, _, _), _) -> Some
c
2647 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2650 match c.columns
with
2651 | Cmulti
(c, _) -> Cmulti
(c, [||])
2652 | Csingle
_ -> Csingle
[||]
2653 | Csplit
(c, _) -> Csplit
(c, [||])
2658 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2661 reshape conf.winw
conf.winh
;
2662 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2665 let togglebirdseye () =
2666 match state.mode
with
2667 | Birdseye vals
-> leavebirdseye vals
true
2668 | View
-> enterbirdseye ()
2672 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2673 let pageno = max
0 (pageno - incr
) in
2674 let rec loop = function
2675 | [] -> gotopage1 pageno 0
2676 | l :: _ when l.pageno = pageno ->
2677 if l.pagedispy >= 0 && l.pagey = 0
2678 then G.postRedisplay "upbirdseye"
2679 else gotopage1 pageno 0
2680 | _ :: rest
-> loop rest
2683 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2686 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2687 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2688 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2689 let rec loop = function
2691 let y, h = getpageyh pageno in
2692 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2694 | l :: _ when l.pageno = pageno ->
2695 if l.pagevh != l.pageh
2696 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2697 else G.postRedisplay "downbirdseye"
2698 | _ :: rest
-> loop rest
2703 let optentry mode
_ key =
2704 let btos b = if b then "on" else "off" in
2705 if key >= 32 && key < 127
2707 let c = Char.chr
key in
2711 try conf.scrollstep
<- int_of_string
s with exc
->
2712 state.text <- Printf.sprintf
"bad integer `%s': %s"
2713 s (Printexc.to_string exc
)
2715 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2720 conf.autoscrollstep
<- int_of_string
s;
2721 if state.autoscroll
<> None
2722 then state.autoscroll
<- Some
conf.autoscrollstep
2724 state.text <- Printf.sprintf
"bad integer `%s': %s"
2725 s (Printexc.to_string exc
)
2727 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2732 let n, a, b = multicolumns_of_string s in
2733 setcolumns mode
n a b;
2735 state.text <- Printf.sprintf
"bad columns `%s': %s"
2736 s (Printexc.to_string exc
)
2738 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2743 let zoom = float (int_of_string
s) /. 100.0 in
2746 state.text <- Printf.sprintf
"bad integer `%s': %s"
2747 s (Printexc.to_string exc
)
2749 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2754 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2756 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2757 begin match mode
with
2759 leavebirdseye beye
false;
2764 state.text <- Printf.sprintf
"bad integer `%s': %s"
2765 s (Printexc.to_string exc
)
2767 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2772 Some
(int_of_string
s)
2774 state.text <- Printf.sprintf
"bad integer `%s': %s"
2775 s (Printexc.to_string exc
);
2778 | Some angle
-> reqlayout angle
conf.proportional
2781 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2784 conf.icase
<- not
conf.icase
;
2785 TEdone
("case insensitive search " ^
(btos conf.icase
))
2788 conf.preload <- not
conf.preload;
2790 TEdone
("preload " ^
(btos conf.preload))
2793 conf.verbose
<- not
conf.verbose
;
2794 TEdone
("verbose " ^
(btos conf.verbose
))
2797 conf.debug
<- not
conf.debug
;
2798 TEdone
("debug " ^
(btos conf.debug
))
2801 conf.maxhfit
<- not
conf.maxhfit
;
2802 state.maxy
<- calcheight ();
2803 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2806 conf.crophack
<- not
conf.crophack
;
2807 TEdone
("crophack " ^
btos conf.crophack
)
2811 match conf.maxwait
with
2813 conf.maxwait
<- Some infinity
;
2814 "always wait for page to complete"
2816 conf.maxwait
<- None
;
2817 "show placeholder if page is not ready"
2822 conf.underinfo
<- not
conf.underinfo
;
2823 TEdone
("underinfo " ^
btos conf.underinfo
)
2826 conf.savebmarks
<- not
conf.savebmarks
;
2827 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2833 match state.layout with
2838 conf.interpagespace
<- int_of_string
s;
2839 docolumns conf.columns
;
2840 state.maxy
<- calcheight ();
2841 let y = getpagey pageno in
2844 state.text <- Printf.sprintf
"bad integer `%s': %s"
2845 s (Printexc.to_string exc
)
2847 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2850 reqlayout conf.angle
(not
conf.proportional
);
2851 TEdone
("proportional display " ^
btos conf.proportional
)
2854 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2855 TEdone
("trim margins " ^
btos conf.trimmargins
)
2858 conf.invert
<- not
conf.invert
;
2859 TEdone
("invert colors " ^
btos conf.invert
)
2863 cbput state.hists
.sel
s;
2866 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2867 textentry, ondone, true)
2870 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2876 class type lvsource
= object
2877 method getitemcount
: int
2878 method getitem
: int -> (string * int)
2879 method hasaction
: int -> bool
2888 method getactive
: int
2889 method getfirst
: int
2890 method getqsearch
: string
2891 method setqsearch
: string -> unit
2895 class virtual lvsourcebase
= object
2896 val mutable m_active
= 0
2897 val mutable m_first
= 0
2898 val mutable m_qsearch
= ""
2899 val mutable m_pan
= 0
2900 method getactive
= m_active
2901 method getfirst
= m_first
2902 method getqsearch
= m_qsearch
2903 method getpan
= m_pan
2904 method setqsearch
s = m_qsearch
<- s
2907 let withoutlastutf8 s =
2908 let len = String.length
s in
2916 let b = Char.code
s.[pos
] in
2917 if b land 0b110000 = 0b11000000
2922 if Char.code
s.[len-1] land 0x80 = 0
2926 String.sub
s 0 first;
2929 let textentrykeyboard
2930 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2932 state.mode
<- Textentry
(te
, onleave
);
2935 G.postRedisplay "textentrykeyboard enttext";
2937 let histaction cmd
=
2940 | Some
(action, _) ->
2941 state.mode
<- Textentry
(
2942 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2944 G.postRedisplay "textentry histaction"
2947 | 0xff08 -> (* backspace *)
2948 let s = withoutlastutf8 text in
2949 let len = String.length
s in
2950 if cancelonempty
&& len = 0
2953 G.postRedisplay "textentrykeyboard after cancel";
2956 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2962 G.postRedisplay "textentrykeyboard after confirm"
2964 | 0xff52 -> histaction HCprev
2965 | 0xff54 -> histaction HCnext
2966 | 0xff50 -> histaction HCfirst
2967 | 0xff57 -> histaction HClast
2969 | 0xff1b -> (* escape*)
2970 if String.length
text = 0
2972 begin match opthist
with
2974 | Some
(_, onhistcancel
) -> onhistcancel
()
2978 G.postRedisplay "textentrykeyboard after cancel2"
2981 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
2984 | 0xff9f | 0xffff -> () (* delete *)
2986 | _ when key != 0 && key land 0xff00 != 0xff00 ->
2987 begin match onkey
text key with
2991 G.postRedisplay "textentrykeyboard after confirm2";
2994 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2998 G.postRedisplay "textentrykeyboard after cancel3"
3001 state.mode
<- Textentry
(te
, onleave
);
3002 G.postRedisplay "textentrykeyboard switch";
3006 vlog "unhandled key %s" (Wsi.keyname
key)
3009 let firstof first active
=
3010 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3011 then max
0 (active
- (fstate.maxrows
/2))
3015 let calcfirst first active
=
3018 let rows = active
- first in
3019 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3023 let scrollph y maxy
=
3024 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3025 let sh = float conf.winh
/. sh in
3026 let sh = max
sh (float conf.scrollh
) in
3031 else float y /. float maxy
3033 let position = (float conf.winh
-. sh) *. percent in
3036 if position +. sh > float conf.winh
3037 then float conf.winh
-. sh
3043 let coe s = (s :> uioh
);;
3045 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3047 val m_pan
= source#getpan
3048 val m_first
= source#getfirst
3049 val m_active
= source#getactive
3050 val m_qsearch
= source#getqsearch
3051 val m_prev_uioh
= state.uioh
3053 method private elemunder
y =
3054 let n = y / (fstate.fontsize
+1) in
3055 if m_first
+ n < source#getitemcount
3057 if source#hasaction
(m_first
+ n)
3058 then Some
(m_first
+ n)
3065 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3066 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3067 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3068 GlDraw.color
(1., 1., 1.);
3069 Gl.enable `texture_2d
;
3070 let fs = fstate.fontsize
in
3072 let ww = fstate.wwidth
in
3073 let tabw = 30.0*.ww in
3074 let itemcount = source#getitemcount
in
3076 if (row - m_first
) * nfs > conf.winh
3079 if row >= 0 && row < itemcount
3081 let (s, level
) = source#getitem
row in
3082 let y = (row - m_first
) * nfs in
3083 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3086 Gl.disable `texture_2d
;
3087 GlDraw.polygon_mode `both `line
;
3088 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3089 GlDraw.rect (1., float (y + 1))
3090 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3091 GlDraw.polygon_mode `both `fill
;
3092 GlDraw.color
(1., 1., 1.);
3093 Gl.enable `texture_2d
;
3096 let drawtabularstring s =
3097 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3100 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3103 let len = String.length
s - tabpos - 1 in
3104 let s1 = String.sub
s 0 tabpos
3105 and s2
= String.sub
s (tabpos + 1) len in
3106 let nx = drawstr x s1 in
3108 let x = x +. (max
tabw sw) in
3115 let _ = drawtabularstring s in
3122 Gl.disable `texture_2d
;
3124 method updownlevel incr
=
3125 let len = source#getitemcount
in
3127 if m_active
>= 0 && m_active
< len
3128 then snd
(source#getitem m_active
)
3132 if i
= len then i
-1 else if i
= -1 then 0 else
3133 let _, l = source#getitem i
in
3134 if l != curlevel then i
else flow (i
+incr
)
3136 let active = flow m_active
in
3137 let first = calcfirst m_first
active in
3138 G.postRedisplay "outline updownlevel";
3139 {< m_active
= active; m_first
= first >}
3141 method private key1
key mask
=
3142 let set1 active first qsearch
=
3143 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3145 let search active pattern incr
=
3148 if n >= 0 && n < source#getitemcount
3150 let s, _ = source#getitem
n in
3152 (try ignore
(Str.search_forward
re s 0); true
3153 with Not_found
-> false)
3155 else loop (n + incr
)
3162 let re = Str.regexp_case_fold pattern
in
3168 let itemcount = source#getitemcount
in
3169 let find start incr
=
3171 if i
= -1 || i
= itemcount
3174 if source#hasaction i
3176 else find (i
+ incr
)
3181 let set active first =
3182 let first = bound first 0 (itemcount - fstate.maxrows
) in
3184 coe {< m_active
= active; m_first
= first >}
3187 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3189 let incr1 = if incr
> 0 then 1 else -1 in
3190 if isvisible m_first m_active
3193 let next = m_active
+ incr
in
3195 if next < 0 || next >= itemcount
3197 else find next incr1
3199 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3205 let first = m_first
+ incr
in
3206 let first = bound first 0 (itemcount - 1) in
3208 let next = m_active
+ incr
in
3209 let next = bound next 0 (itemcount - 1) in
3212 let active = if next = -1 then m_active
else next in
3215 let first = min
next m_first
in
3217 if abs
(next - first) > fstate.maxrows
3223 let first = m_first
+ incr
in
3224 let first = bound first 0 (itemcount - 1) in
3226 let next = m_active
+ incr
in
3227 let next = bound next 0 (itemcount - 1) in
3228 let next = find next incr1 in
3230 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3232 let active = if m_active
= -1 then next else m_active
in
3237 if isvisible first active
3243 G.postRedisplay "listview navigate";
3247 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3248 let incr = if key = 0x72 then -1 else 1 in
3250 match search (m_active
+ incr) m_qsearch
incr with
3252 state.text <- m_qsearch ^
" [not found]";
3255 state.text <- m_qsearch
;
3256 active, firstof m_first
active
3258 G.postRedisplay "listview ctrl-r/s";
3259 set1 active first m_qsearch
;
3261 | 0xff08 -> (* backspace *)
3262 if String.length m_qsearch
= 0
3265 let qsearch = withoutlastutf8 m_qsearch
in
3266 let len = String.length
qsearch in
3270 G.postRedisplay "listview empty qsearch";
3271 set1 m_active m_first
"";
3275 match search m_active
qsearch ~
-1 with
3277 state.text <- qsearch ^
" [not found]";
3280 state.text <- qsearch;
3281 active, firstof m_first
active
3283 G.postRedisplay "listview backspace qsearch";
3284 set1 active first qsearch
3287 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3288 let pattern = m_qsearch ^
Wsi.toutf8
key in
3290 match search m_active
pattern 1 with
3292 state.text <- pattern ^
" [not found]";
3295 state.text <- pattern;
3296 active, firstof m_first
active
3298 G.postRedisplay "listview qsearch add";
3299 set1 active first pattern;
3301 | 0xff1b -> (* escape *)
3303 if String.length m_qsearch
= 0
3305 G.postRedisplay "list view escape";
3308 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3310 | None
-> m_prev_uioh
3315 G.postRedisplay "list view kill qsearch";
3316 source#setqsearch
"";
3317 coe {< m_qsearch
= "" >}
3320 | 0xff0d -> (* return *)
3322 let self = {< m_qsearch
= "" >} in
3323 source#setqsearch
"";
3325 G.postRedisplay "listview enter";
3326 if m_active
>= 0 && m_active
< source#getitemcount
3328 source#exit
(coe self) false m_active m_first m_pan
"";
3331 source#exit
(coe self) true m_active m_first m_pan
"";
3334 begin match opt with
3335 | None
-> m_prev_uioh
3339 | 0xff9f | 0xffff -> (* delete *)
3342 | 0xff52 -> navigate ~
-1 (* up *)
3343 | 0xff54 -> navigate 1 (* down *)
3344 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3345 | 0xff56 -> navigate fstate.maxrows
(* next *)
3347 | 0xff53 -> (* right *)
3349 G.postRedisplay "listview right";
3350 coe {< m_pan
= m_pan
- 1 >}
3352 | 0xff51 -> (* left *)
3354 G.postRedisplay "listview left";
3355 coe {< m_pan
= m_pan
+ 1 >}
3357 | 0xff50 -> (* home *)
3358 let active = find 0 1 in
3359 G.postRedisplay "listview home";
3362 | 0xff57 -> (* end *)
3363 let first = max
0 (itemcount - fstate.maxrows
) in
3364 let active = find (itemcount - 1) ~
-1 in
3365 G.postRedisplay "listview end";
3368 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3372 dolog "listview unknown key %#x" key; coe self
3374 method key key mask
=
3375 match state.mode
with
3376 | Textentry te
-> textentrykeyboard key mask te
; coe self
3377 | _ -> self#key1
key mask
3379 method button button down
x y _ =
3382 | 1 when x > conf.winw
- conf.scrollbw
->
3383 G.postRedisplay "listview scroll";
3386 let _, position, sh = self#
scrollph in
3387 if y > truncate
position && y < truncate
(position +. sh)
3389 state.mstate
<- Mscrolly
;
3393 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3394 let first = truncate
(s *. float source#getitemcount
) in
3395 let first = min source#getitemcount
first in
3396 Some
(coe {< m_first
= first; m_active
= first >})
3398 state.mstate
<- Mnone
;
3401 | 1 when not down
->
3402 begin match self#elemunder
y with
3404 G.postRedisplay "listview click";
3406 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3410 | n when (n == 4 || n == 5) && not down
->
3411 let len = source#getitemcount
in
3413 if n = 5 && m_first
+ fstate.maxrows
>= len
3417 let first = m_first
+ (if n == 4 then -1 else 1) in
3418 bound first 0 (len - 1)
3420 G.postRedisplay "listview wheel";
3421 Some
(coe {< m_first
= first >})
3422 | n when (n = 6 || n = 7) && not down
->
3423 let inc = m_first
+ (if n = 7 then -1 else 1) in
3424 G.postRedisplay "listview hwheel";
3425 Some
(coe {< m_pan
= m_pan
+ inc >})
3430 | None
-> m_prev_uioh
3434 match state.mstate
with
3436 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3437 let first = truncate
(s *. float source#getitemcount
) in
3438 let first = min source#getitemcount
first in
3439 G.postRedisplay "listview motion";
3440 coe {< m_first
= first; m_active
= first >}
3443 method pmotion
x y =
3444 if x < conf.winw
- conf.scrollbw
3447 match self#elemunder
y with
3448 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3449 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3453 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3458 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3462 method infochanged
_ = ()
3464 method scrollpw
= (0, 0.0, 0.0)
3466 let nfs = fstate.fontsize
+ 1 in
3467 let y = m_first
* nfs in
3468 let itemcount = source#getitemcount
in
3469 let maxi = max
0 (itemcount - fstate.maxrows
) in
3470 let maxy = maxi * nfs in
3471 let p, h = scrollph y maxy in
3474 method modehash
= modehash
3477 class outlinelistview ~source
=
3480 ~source
:(source
:> lvsource
)
3482 ~modehash
:(findkeyhash conf "outline")
3485 method key key mask
=
3486 let calcfirst first active =
3489 let rows = active - first in
3491 if String.length
state.text = 0
3493 else fstate.maxrows - 2
3495 if rows > maxrows then active - maxrows else first
3499 let active = m_active
+ incr in
3500 let active = bound active 0 (source#getitemcount
- 1) in
3501 let first = calcfirst m_first
active in
3502 G.postRedisplay "outline navigate";
3503 coe {< m_active
= active; m_first
= first >}
3505 let ctrl = Wsi.withctrl mask
in
3507 | 110 when ctrl -> (* ctrl-n *)
3508 source#narrow m_qsearch
;
3509 G.postRedisplay "outline ctrl-n";
3510 coe {< m_first
= 0; m_active
= 0 >}
3512 | 117 when ctrl -> (* ctrl-u *)
3514 G.postRedisplay "outline ctrl-u";
3516 coe {< m_first
= 0; m_active
= 0 >}
3518 | 108 when ctrl -> (* ctrl-l *)
3519 let first = m_active
- (fstate.maxrows / 2) in
3520 G.postRedisplay "outline ctrl-l";
3521 coe {< m_first
= first >}
3523 | 0xff9f | 0xffff -> (* delete *)
3524 source#remove m_active
;
3525 G.postRedisplay "outline delete";
3526 let active = max
0 (m_active
-1) in
3527 coe {< m_first
= firstof m_first
active;
3528 m_active
= active >}
3530 | 0xff52 -> navigate ~
-1 (* up *)
3531 | 0xff54 -> navigate 1 (* down *)
3532 | 0xff55 -> (* prior *)
3533 navigate ~
-(fstate.maxrows)
3534 | 0xff56 -> (* next *)
3535 navigate fstate.maxrows
3537 | 0xff53 -> (* [ctrl-]right *)
3541 G.postRedisplay "outline ctrl right";
3542 {< m_pan
= m_pan
+ 1 >}
3544 else self#updownlevel
1
3548 | 0xff51 -> (* [ctrl-]left *)
3552 G.postRedisplay "outline ctrl left";
3553 {< m_pan
= m_pan
- 1 >}
3555 else self#updownlevel ~
-1
3559 | 0xff50 -> (* home *)
3560 G.postRedisplay "outline home";
3561 coe {< m_first
= 0; m_active
= 0 >}
3563 | 0xff57 -> (* end *)
3564 let active = source#getitemcount
- 1 in
3565 let first = max
0 (active - fstate.maxrows) in
3566 G.postRedisplay "outline end";
3567 coe {< m_active
= active; m_first
= first >}
3569 | _ -> super#
key key mask
3572 let outlinesource usebookmarks
=
3575 inherit lvsourcebase
3576 val mutable m_items
= empty
3577 val mutable m_orig_items
= empty
3578 val mutable m_prev_items
= empty
3579 val mutable m_narrow_pattern
= ""
3580 val mutable m_hadremovals
= false
3582 method getitemcount
=
3583 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3586 if n == Array.length m_items
&& m_hadremovals
3588 ("[Confirm removal]", 0)
3590 let s, n, _ = m_items
.(n) in
3593 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3594 ignore
(uioh
, first, qsearch);
3595 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3597 if String.length m_narrow_pattern
= 0
3603 if not
confrimremoval
3605 let _, _, anchor = m_items
.(active) in
3610 state.bookmarks
<- Array.to_list m_items
;
3611 m_orig_items
<- m_items
;
3614 else m_items
<- items;
3618 method hasaction
_ = true
3621 if Array.length m_items
!= Array.length m_orig_items
3622 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3625 method narrow
pattern =
3626 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3630 let rec loop accu n =
3633 m_narrow_pattern
<- pattern;
3634 m_items
<- Array.of_list
accu
3637 let (s, _, _) as o = m_items
.(n) in
3639 if (try ignore
(Str.search_forward
re s 0); true
3640 with Not_found
-> false)
3646 loop [] (Array.length m_items
- 1)
3651 then Array.of_list
state.bookmarks
3654 m_items
<- m_orig_items
3659 if m >= 0 && m < Array.length m_items
3661 m_hadremovals
<- true;
3662 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3663 let n = if n >= m then n+1 else n in
3668 method reset
anchor items =
3669 m_hadremovals
<- false;
3670 if m_orig_items
== empty || m_prev_items
!= items
3672 m_orig_items
<- items;
3673 if String.length m_narrow_pattern
= 0
3674 then m_items
<- items;
3676 m_prev_items
<- items;
3677 let rely = getanchory anchor in
3679 let rec loop n best bestd
=
3680 if n = Array.length m_items
3683 let (_, _, anchor) = m_items
.(n) in
3684 let orely = getanchory anchor in
3685 let d = abs
(orely - rely) in
3688 else loop (n+1) best bestd
3693 m_first
<- firstof m_first
active
3697 let enterselector usebookmarks
=
3698 let source = outlinesource usebookmarks
in
3702 then Array.of_list
state.bookmarks
3705 if Array.length
outlines = 0
3707 showtext ' ' errmsg
;
3710 state.text <- source#greetmsg
;
3711 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3712 let anchor = getanchor () in
3713 source#reset
anchor outlines;
3714 state.uioh
<- coe (new outlinelistview ~
source);
3715 G.postRedisplay "enter selector";
3719 let enteroutlinemode =
3720 let f = enterselector false in
3721 fun ()-> f "Document has no outline";
3724 let enterbookmarkmode =
3725 let f = enterselector true in
3726 fun () -> f "Document has no bookmarks (yet)";
3729 let color_of_string s =
3730 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3731 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3735 let color_to_string (r, g
, b) =
3736 let r = truncate
(r *. 256.0)
3737 and g
= truncate
(g
*. 256.0)
3738 and b = truncate
(b *. 256.0) in
3739 Printf.sprintf
"%d/%d/%d" r g
b
3742 let irect_of_string s =
3743 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3746 let irect_to_string (x0,y0,x1,y1) =
3747 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3750 let makecheckers () =
3751 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3753 converted by Issac Trotts. July 25, 2002 *)
3754 let image_height = 64
3755 and image_width
= 64 in
3759 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3761 for i
= 0 to image_width
- 1 do
3762 for j
= 0 to image_height - 1 do
3763 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3764 (if (i
land 8 ) lxor (j
land 8) = 0
3765 then [|255;255;255|] else [|200;200;200|])
3770 let image = make_image () in
3771 let id = GlTex.gen_texture
() in
3772 GlTex.bind_texture `texture_2d
id;
3773 GlPix.store
(`unpack_alignment
1);
3774 GlTex.image2d
image;
3775 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3778 `mag_filter `nearest
;
3779 `min_filter `nearest
];
3783 let setcheckers enabled
=
3784 match state.texid
with
3786 if enabled
then state.texid
<- Some
(makecheckers ())
3791 GlTex.delete_texture texid
;
3792 state.texid
<- None
;
3796 let int_of_string_with_suffix s =
3797 let l = String.length
s in
3801 let suffix = Char.lowercase
s.[l-1] in
3803 | 'k'
-> String.sub
s 0 (l-1), 10
3804 | '
m'
-> String.sub
s 0 (l-1), 20
3805 | 'g'
-> String.sub
s 0 (l-1), 30
3809 let n = int_of_string
s1 in
3810 let m = n lsl shift
in
3812 then raise
(Failure
"value too large")
3816 let string_with_suffix_of_int n =
3821 if n land ((1 lsl 20) - 1) = 0
3824 if n land ((1 lsl 10) - 1) = 0
3830 let h = n mod 1000 in
3833 then string_of_int
h ^
s
3835 let s = Printf.sprintf
"_%03d%s" h s in
3842 let defghyllscroll = (40, 8, 32);;
3843 let ghyllscroll_of_string s =
3844 let (n, a, b) as nab
=
3847 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3849 if n <= a || n <= b || a >= b
3850 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3854 let ghyllscroll_to_string ((n, a, b) as nab
) =
3855 if nab
= defghyllscroll
3857 else Printf.sprintf
"%d,%d,%d" n a b;
3860 let describe_location () =
3862 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3864 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3865 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3869 else (100. *. (float state.y /. float maxy))
3873 Printf.sprintf
"page %d of %d [%.2f%%]"
3874 (fn+1) state.pagecount
percent
3877 "pages %d-%d of %d [%.2f%%]"
3878 (fn+1) (ln
+1) state.pagecount
percent
3882 let btos b = if b then "\xe2\x88\x9a" else "" in
3883 let showextended = ref false in
3884 let leave mode
= function
3885 | Confirm
-> state.mode
<- mode
3886 | Cancel
-> state.mode
<- mode
in
3889 val mutable m_first_time
= true
3890 val mutable m_l
= []
3891 val mutable m_a
= [||]
3892 val mutable m_prev_uioh
= nouioh
3893 val mutable m_prev_mode
= View
3895 inherit lvsourcebase
3897 method reset prev_mode prev_uioh
=
3898 m_a
<- Array.of_list
(List.rev m_l
);
3900 m_prev_mode
<- prev_mode
;
3901 m_prev_uioh
<- prev_uioh
;
3905 if n >= Array.length m_a
3909 | _, _, _, Action
_ -> m_active
<- n
3913 m_first_time
<- false;
3916 method int name get
set =
3918 (name
, `
int get
, 1, Action
(
3921 try set (int_of_string
s)
3923 state.text <- Printf.sprintf
"bad integer `%s': %s"
3924 s (Printexc.to_string exn
)
3927 let te = name ^
": ", "", None
, intentry, ondone, true in
3928 state.mode
<- Textentry
(te, leave m_prev_mode
);
3932 method int_with_suffix name get
set =
3934 (name
, `intws get
, 1, Action
(
3937 try set (int_of_string_with_suffix s)
3939 state.text <- Printf.sprintf
"bad integer `%s': %s"
3940 s (Printexc.to_string exn
)
3944 name ^
": ", "", None
, intentry_with_suffix, ondone, true
3946 state.mode
<- Textentry
(te, leave m_prev_mode
);
3950 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3952 (name
, `
bool (btos, get
), offset
, Action
(
3959 method color name get
set =
3961 (name
, `color get
, 1, Action
(
3963 let invalid = (nan
, nan
, nan
) in
3966 try color_of_string s
3968 state.text <- Printf.sprintf
"bad color `%s': %s"
3969 s (Printexc.to_string exn
);
3975 let te = name ^
": ", "", None
, textentry, ondone, true in
3976 state.text <- color_to_string (get
());
3977 state.mode
<- Textentry
(te, leave m_prev_mode
);
3981 method string name get
set =
3983 (name
, `
string get
, 1, Action
(
3985 let ondone s = set s in
3986 let te = name ^
": ", "", None
, textentry, ondone, true in
3987 state.mode
<- Textentry
(te, leave m_prev_mode
);
3991 method colorspace name get
set =
3993 (name
, `
string get
, 1, Action
(
3996 let vals = [| "rgb"; "bgr"; "gray" |] in
3998 inherit lvsourcebase
4001 m_active
<- int_of_colorspace conf.colorspace
;
4004 method getitemcount
= Array.length
vals
4005 method getitem
n = (vals.(n), 0)
4006 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4007 ignore
(uioh
, first, pan
, qsearch);
4008 if not cancel
then set active;
4010 method hasaction
_ = true
4014 let modehash = findkeyhash conf "info" in
4015 coe (new listview ~
source ~trusted
:true ~
modehash)
4018 method caption
s offset
=
4019 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4021 method caption2
s f offset
=
4022 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4024 method getitemcount
= Array.length m_a
4027 let tostr = function
4028 | `
int f -> string_of_int
(f ())
4029 | `intws
f -> string_with_suffix_of_int (f ())
4031 | `color
f -> color_to_string (f ())
4032 | `
bool (btos, f) -> btos (f ())
4035 let name, t
, offset
, _ = m_a
.(n) in
4036 ((let s = tostr t
in
4037 if String.length
s > 0
4038 then Printf.sprintf
"%s\t%s" name s
4042 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4046 m_qsearch
<- qsearch;
4048 match m_a
.(active) with
4049 | _, _, _, Action
f -> f uioh
4061 method hasaction
n =
4063 | _, _, _, Action
_ -> true
4067 let rec fillsrc prevmode prevuioh
=
4068 let sep () = src#caption
"" 0 in
4069 let colorp name get
set =
4071 (fun () -> color_to_string (get
()))
4074 let c = color_of_string v in
4077 state.text <- Printf.sprintf
"bad color `%s': %s"
4078 v (Printexc.to_string exn
);
4081 let oldmode = state.mode
in
4082 let birdseye = isbirdseye state.mode
in
4084 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4086 src#
bool "presentation mode"
4087 (fun () -> conf.presentation
)
4089 conf.presentation
<- v;
4090 state.anchor <- getanchor ();
4093 src#
bool "ignore case in searches"
4094 (fun () -> conf.icase
)
4095 (fun v -> conf.icase
<- v);
4098 (fun () -> conf.preload)
4099 (fun v -> conf.preload <- v);
4101 src#
bool "highlight links"
4102 (fun () -> conf.hlinks
)
4103 (fun v -> conf.hlinks
<- v);
4105 src#
bool "under info"
4106 (fun () -> conf.underinfo
)
4107 (fun v -> conf.underinfo
<- v);
4109 src#
bool "persistent bookmarks"
4110 (fun () -> conf.savebmarks
)
4111 (fun v -> conf.savebmarks
<- v);
4113 src#
bool "proportional display"
4114 (fun () -> conf.proportional
)
4115 (fun v -> reqlayout conf.angle
v);
4117 src#
bool "trim margins"
4118 (fun () -> conf.trimmargins
)
4119 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4121 src#
bool "persistent location"
4122 (fun () -> conf.jumpback
)
4123 (fun v -> conf.jumpback
<- v);
4126 src#
int "inter-page space"
4127 (fun () -> conf.interpagespace
)
4129 conf.interpagespace
<- n;
4130 docolumns conf.columns
;
4132 match state.layout with
4137 state.maxy <- calcheight ();
4138 let y = getpagey pageno in
4143 (fun () -> conf.pagebias
)
4144 (fun v -> conf.pagebias
<- v);
4146 src#
int "scroll step"
4147 (fun () -> conf.scrollstep
)
4148 (fun n -> conf.scrollstep
<- n);
4150 src#
int "horizontal scroll step"
4151 (fun () -> conf.hscrollstep
)
4152 (fun v -> conf.hscrollstep
<- v);
4154 src#
int "auto scroll step"
4156 match state.autoscroll
with
4158 | _ -> conf.autoscrollstep
)
4160 if state.autoscroll
<> None
4161 then state.autoscroll
<- Some
n;
4162 conf.autoscrollstep
<- n);
4165 (fun () -> truncate
(conf.zoom *. 100.))
4166 (fun v -> setzoom ((float v) /. 100.));
4169 (fun () -> conf.angle
)
4170 (fun v -> reqlayout v conf.proportional
);
4172 src#
int "scroll bar width"
4173 (fun () -> state.scrollw
)
4177 reshape conf.winw
conf.winh
;
4180 src#
int "scroll handle height"
4181 (fun () -> conf.scrollh
)
4182 (fun v -> conf.scrollh
<- v;);
4184 src#
int "thumbnail width"
4185 (fun () -> conf.thumbw
)
4187 conf.thumbw
<- min
4096 v;
4190 leavebirdseye beye
false;
4195 let mode = state.mode in
4196 src#
string "columns"
4198 match conf.columns
with
4200 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4201 | Csplit
(count
, _) -> "-" ^ string_of_int count
4204 let n, a, b = multicolumns_of_string v in
4205 setcolumns mode n a b);
4208 src#caption
"Presentation mode" 0;
4209 src#
bool "scrollbar visible"
4210 (fun () -> conf.scrollbarinpm
)
4212 if v != conf.scrollbarinpm
4214 conf.scrollbarinpm
<- v;
4215 if conf.presentation
4217 state.scrollw
<- if v then conf.scrollbw
else 0;
4218 reshape conf.winw
conf.winh
;
4224 src#caption
"Pixmap cache" 0;
4225 src#int_with_suffix
"size (advisory)"
4226 (fun () -> conf.memlimit
)
4227 (fun v -> conf.memlimit
<- v);
4230 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4231 (string_with_suffix_of_int state.memused
)
4232 (Hashtbl.length
state.tilemap
)) 1;
4235 src#caption
"Layout" 0;
4236 src#caption2
"Dimension"
4238 Printf.sprintf
"%dx%d (virtual %dx%d)"
4244 src#caption2
"Position" (fun () ->
4245 Printf.sprintf
"%dx%d" state.x state.y
4248 src#caption2
"Visible" (fun () -> describe_location ()) 1
4252 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4253 "Save these parameters as global defaults at exit"
4254 (fun () -> conf.bedefault
)
4255 (fun v -> conf.bedefault
<- v)
4259 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4260 src#
bool ~offset
:0 ~
btos "Extended parameters"
4261 (fun () -> !showextended)
4262 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4266 (fun () -> conf.checkers
)
4267 (fun v -> conf.checkers
<- v; setcheckers v);
4268 src#
bool "update cursor"
4269 (fun () -> conf.updatecurs
)
4270 (fun v -> conf.updatecurs
<- v);
4272 (fun () -> conf.verbose
)
4273 (fun v -> conf.verbose
<- v);
4274 src#
bool "invert colors"
4275 (fun () -> conf.invert
)
4276 (fun v -> conf.invert
<- v);
4278 (fun () -> conf.maxhfit
)
4279 (fun v -> conf.maxhfit
<- v);
4280 src#
bool "redirect stderr"
4281 (fun () -> conf.redirectstderr)
4282 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4283 src#
string "uri launcher"
4284 (fun () -> conf.urilauncher
)
4285 (fun v -> conf.urilauncher
<- v);
4286 src#
string "path launcher"
4287 (fun () -> conf.pathlauncher
)
4288 (fun v -> conf.pathlauncher
<- v);
4289 src#
string "tile size"
4290 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4293 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4294 conf.tilew
<- max
64 w;
4295 conf.tileh
<- max
64 h;
4298 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4299 v (Printexc.to_string exn
));
4300 src#
int "texture count"
4301 (fun () -> conf.texcount
)
4304 then conf.texcount
<- v
4305 else showtext '
!'
" Failed to set texture count please retry later"
4307 src#
int "slice height"
4308 (fun () -> conf.sliceheight
)
4310 conf.sliceheight
<- v;
4311 wcmd "sliceh %d" conf.sliceheight
;
4313 src#
int "anti-aliasing level"
4314 (fun () -> conf.aalevel
)
4316 conf.aalevel
<- bound v 0 8;
4317 state.anchor <- getanchor ();
4318 opendoc state.path
state.password
;
4320 src#
string "page scroll scaling factor"
4321 (fun () -> string_of_float
conf.pgscale)
4324 let s = float_of_string
v in
4327 state.text <- Printf.sprintf
4328 "bad page scroll scaling factor `%s': %s"
4329 v (Printexc.to_string exn
)
4332 src#
int "ui font size"
4333 (fun () -> fstate.fontsize
)
4334 (fun v -> setfontsize (bound v 5 100));
4335 src#
int "hint font size"
4336 (fun () -> conf.hfsize
)
4337 (fun v -> conf.hfsize
<- bound v 5 100);
4338 colorp "background color"
4339 (fun () -> conf.bgcolor
)
4340 (fun v -> conf.bgcolor
<- v);
4341 src#
bool "crop hack"
4342 (fun () -> conf.crophack
)
4343 (fun v -> conf.crophack
<- v);
4344 src#
string "trim fuzz"
4345 (fun () -> irect_to_string conf.trimfuzz
)
4348 conf.trimfuzz
<- irect_of_string v;
4350 then settrim true conf.trimfuzz
;
4352 state.text <- Printf.sprintf
"bad irect `%s': %s"
4353 v (Printexc.to_string exn
)
4355 src#
string "throttle"
4357 match conf.maxwait
with
4358 | None
-> "show place holder if page is not ready"
4361 then "wait for page to fully render"
4363 "wait " ^ string_of_float
time
4364 ^
" seconds before showing placeholder"
4368 let f = float_of_string
v in
4370 then conf.maxwait
<- None
4371 else conf.maxwait
<- Some
f
4373 state.text <- Printf.sprintf
"bad time `%s': %s"
4374 v (Printexc.to_string exn
)
4376 src#
string "ghyll scroll"
4378 match conf.ghyllscroll
with
4380 | Some nab
-> ghyllscroll_to_string nab
4385 if String.length
v = 0
4387 else Some
(ghyllscroll_of_string v)
4389 conf.ghyllscroll
<- gs
4391 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4392 v (Printexc.to_string exn
)
4394 src#
string "selection command"
4395 (fun () -> conf.selcmd
)
4396 (fun v -> conf.selcmd
<- v);
4397 src#colorspace
"color space"
4398 (fun () -> colorspace_to_string conf.colorspace
)
4400 conf.colorspace
<- colorspace_of_int v;
4407 src#caption
"Document" 0;
4408 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4409 src#caption2
"Pages"
4410 (fun () -> string_of_int
state.pagecount
) 1;
4411 src#caption2
"Dimensions"
4412 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4416 src#caption
"Trimmed margins" 0;
4417 src#caption2
"Dimensions"
4418 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4422 src#caption
"OpenGL" 0;
4423 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4424 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4425 src#reset prevmode prevuioh
;
4429 let prevmode = state.mode
4430 and prevuioh
= state.uioh in
4431 fillsrc prevmode prevuioh
;
4432 let source = (src :> lvsource
) in
4433 let modehash = findkeyhash conf "info" in
4434 state.uioh <- coe (object (self)
4435 inherit listview ~
source ~trusted
:true ~
modehash as super
4436 val mutable m_prevmemused
= 0
4437 method infochanged
= function
4439 if m_prevmemused
!= state.memused
4441 m_prevmemused
<- state.memused
;
4442 G.postRedisplay "memusedchanged";
4444 | Pdim
-> G.postRedisplay "pdimchanged"
4445 | Docinfo
-> fillsrc prevmode prevuioh
4447 method key key mask
=
4448 if not
(Wsi.withctrl mask
)
4451 | 0xff51 -> coe (self#updownlevel ~
-1)
4452 | 0xff53 -> coe (self#updownlevel
1)
4453 | _ -> super#
key key mask
4454 else super#
key key mask
4456 G.postRedisplay "info";
4462 inherit lvsourcebase
4463 method getitemcount
= Array.length
state.help
4465 let s, n, _ = state.help
.(n) in
4468 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4472 m_qsearch
<- qsearch;
4473 match state.help
.(active) with
4474 | _, _, Action
f -> Some
(f uioh)
4484 method hasaction
n =
4485 match state.help
.(n) with
4486 | _, _, Action
_ -> true
4493 let modehash = findkeyhash conf "help" in
4494 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4495 G.postRedisplay "help";
4500 let re = Str.regexp
"[\r\n]" in
4502 inherit lvsourcebase
4503 val mutable m_items
= [||]
4505 method getitemcount
= 1 + Array.length m_items
4510 else m_items
.(n-1), 0
4512 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4517 then Buffer.clear
state.errmsgs
;
4518 m_qsearch
<- qsearch;
4525 method hasaction
n =
4529 state.newerrmsgs
<- false;
4530 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4531 m_items
<- Array.of_list
l
4539 let source = (msgsource :> lvsource
) in
4540 let modehash = findkeyhash conf "listview" in
4541 state.uioh <- coe (object
4542 inherit listview ~
source ~trusted
:false ~
modehash as super
4545 then msgsource#reset
;
4548 G.postRedisplay "msgs";
4551 let quickbookmark ?title
() =
4552 match state.layout with
4558 let sec = Unix.gettimeofday
() in
4559 let tm = Unix.localtime
sec in
4560 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4564 (tm.Unix.tm_year
+ 1900)
4567 | Some
title -> title
4569 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4573 state.fullscreen
<- None
;
4577 let setautoscrollspeed step goingdown
=
4578 let incr = max
1 ((abs step
) / 2) in
4579 let incr = if goingdown
then incr else -incr in
4580 let astep = step
+ incr in
4581 state.autoscroll
<- Some
astep;
4584 let gotounder = function
4585 | Ulinkgoto
(pageno, top) ->
4589 gotopage1 pageno top;
4595 | Uremote
(filename
, pageno) ->
4597 if Sys.file_exists filename
4600 let dir = Filename.dirname
state.path in
4601 let path = Filename.concat
dir filename
in
4602 if Sys.file_exists
path
4606 if String.length
path > 0
4608 let anchor = getanchor () in
4609 let ranchor = state.path, state.password
, anchor in
4610 state.anchor <- (pageno, 0.0, 0.0);
4611 state.ranchors
<- ranchor :: state.ranchors
;
4614 else showtext '
!'
("Could not find " ^ filename
)
4616 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4620 match conf.columns
with
4622 | _ -> conf.zoom > 1.0
4625 let viewkeyboard key mask
=
4627 let mode = state.mode in
4628 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4631 G.postRedisplay "view:enttext"
4633 let ctrl = Wsi.withctrl mask
in
4638 | 0xff63 -> (* insert *)
4639 if conf.angle
mod 360 = 0
4641 state.mode <- LinkNav
(Ltgendir
0);
4644 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4646 | 0xff1b | 113 -> (* escape / q *)
4647 begin match state.mstate
with
4649 state.mstate
<- Mnone
;
4650 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4651 G.postRedisplay "kill zoom rect";
4653 match state.ranchors
with
4655 | (path, password
, anchor) :: rest
->
4656 state.ranchors
<- rest
;
4657 state.anchor <- anchor;
4658 opendoc path password
4661 | 0xff08 -> (* backspace *)
4662 let y = getnav ~
-1 in
4663 gotoy_and_clear_text y
4671 G.postRedisplay "dehighlight";
4673 | 47 | 63 -> (* / ? *)
4674 let ondone isforw
s =
4675 cbput state.hists
.pat
s;
4676 state.searchpattern
<- s;
4679 let s = String.create
1 in
4680 s.[0] <- Char.chr
key;
4681 enttext (s, "", Some
(onhist state.hists
.pat
),
4682 textentry, ondone (key = 47), true)
4684 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4685 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4686 setzoom (conf.zoom +. incr)
4688 | 43 | 0xffab -> (* + *)
4691 try int_of_string
s with exc
->
4692 state.text <- Printf.sprintf
"bad integer `%s': %s"
4693 s (Printexc.to_string exc
);
4699 state.text <- "page bias is now " ^ string_of_int
n;
4702 enttext ("page bias: ", "", None
, intentry, ondone, true)
4704 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4705 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4706 setzoom (max
0.01 (conf.zoom -. decr))
4708 | 45 | 0xffad -> (* - *)
4709 let ondone msg
= state.text <- msg
in
4711 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4712 optentry state.mode, ondone, true
4715 | 48 when ctrl -> (* ctrl-0 *)
4718 | 49 when ctrl -> (* ctrl-1 *)
4720 match conf.columns
with
4721 | Csingle
_ | Cmulti
_ -> 1
4722 | Csplit
(n, _) -> n
4724 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4728 | 0xffc6 -> (* f9 *)
4731 | 57 when ctrl -> (* ctrl-9 *)
4734 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4735 when not
ctrl -> (* 0..9 *)
4738 try int_of_string
s with exc
->
4739 state.text <- Printf.sprintf
"bad integer `%s': %s"
4740 s (Printexc.to_string exc
);
4746 cbput state.hists
.pag
(string_of_int
n);
4747 gotopage1 (n + conf.pagebias
- 1) 0;
4750 let pageentry text key =
4751 match Char.unsafe_chr
key with
4752 | 'g'
-> TEdone
text
4753 | _ -> intentry text key
4755 let text = "x" in text.[0] <- Char.chr
key;
4756 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4759 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4760 reshape conf.winw
conf.winh
;
4763 conf.hlinks
<- not
conf.hlinks
;
4764 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4765 G.postRedisplay "toggle highlightlinks";
4768 state.glinks
<- true;
4769 let mode = state.mode in
4770 state.mode <- Textentry
(
4771 (":", "", None
, linknentry, linkndone (fun under ->
4776 state.glinks
<- false;
4780 G.postRedisplay "view:linkent(F)"
4783 state.glinks
<- true;
4784 let mode = state.mode in
4785 state.mode <- Textentry
(
4786 (":", "", None
, linknentry, linkndone (fun under ->
4787 match Ne.pipe () with
4789 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4790 (Printexc.to_string exn
));
4793 try popen conf.selcmd
[r, 0; w, -1]; true
4796 (Printf.sprintf
"failed to execute %s: %s"
4797 conf.selcmd
(Printexc.to_string exn
));
4801 Ne.clo fd
(fun msg
->
4802 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4805 let s = undertext under in
4809 let l = String.length
s in
4810 let n = Unix.write
w s 0 l in
4815 "failed to write %d characters to sel pipe, wrote %d"
4820 (Printf.sprintf
"failed to write to sel pipe: %s"
4821 (Printexc.to_string exn
)
4830 state.glinks
<- false;
4834 G.postRedisplay "view:linkent"
4837 begin match state.autoscroll
with
4839 conf.autoscrollstep
<- step
;
4840 state.autoscroll
<- None
4842 if conf.autoscrollstep
= 0
4843 then state.autoscroll
<- Some
1
4844 else state.autoscroll
<- Some
conf.autoscrollstep
4847 | 112 when ctrl -> (* ctrl-p *)
4851 conf.presentation
<- not
conf.presentation
;
4852 if conf.presentation
4854 if not
conf.scrollbarinpm
4855 then state.scrollw
<- 0;
4858 state.scrollw
<- conf.scrollbw
;
4860 showtext ' '
("presentation mode " ^
4861 if conf.presentation
then "on" else "off");
4862 state.anchor <- getanchor ();
4866 begin match state.fullscreen
with
4868 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4871 state.fullscreen
<- None
;
4876 gotoy_and_clear_text 0
4879 gotopage1 (state.pagecount
- 1) 0
4881 | 112 | 78 -> (* p|N *)
4882 search state.searchpattern
false
4884 | 110 | 0xffc0 -> (* n|F3 *)
4885 search state.searchpattern
true
4888 begin match state.layout with
4891 gotoy_and_clear_text (getpagey l.pageno)
4895 begin match state.layout with
4898 match conf.columns
with
4899 | Csingle
_ | Cmulti
_ ->
4900 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4902 let y = clamp (pgscale conf.winh
) in
4903 gotoy_and_clear_text y
4905 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4906 gotoy_and_clear_text (getpagey pageno)
4908 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4910 let pagey, pageh
= getpageyh l.pageno in
4911 let pagey = pagey + pageh
* l.pagecol
in
4912 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4913 gotoy_and_clear_text (pagey + pageh
+ ips)
4916 | 0xff9f | 0xffff -> (* delete *)
4917 begin match state.layout with
4920 match conf.columns
with
4921 | Csingle
_ | Cmulti
_ ->
4922 if conf.presentation
&& l.pagey != 0
4924 gotoy_and_clear_text (clamp (pgscale ~
-(conf.winh
)))
4926 let pageno = max
0 (l.pageno-1) in
4927 gotoy_and_clear_text (getpagey pageno)
4935 let pageno = max
0 (l.pageno-1) in
4936 let pagey, pageh
= getpageyh pageno in
4939 let pagey, pageh
= getpageyh l.pageno in
4940 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4942 gotoy_and_clear_text y
4946 showtext ' '
(describe_location ());
4949 begin match state.layout with
4952 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4957 enterbookmarkmode ()
4959 | 104 | 0xffbe -> (* h|F1 *)
4965 | 101 when conf.redirectstderr -> (* e *)
4970 match state.layout with
4971 | l :: _ -> state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
4974 enttext ("bookmark: ", "", None
, textentry, ondone, true)
4978 showtext ' '
"Quick bookmark added";
4981 begin match state.layout with
4983 let rect = getpdimrect
l.pagedimno
in
4987 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4988 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4990 (truncate
(rect.(1) -. rect.(0)),
4991 truncate
(rect.(3) -. rect.(0)))
4993 let w = truncate
((float w)*.conf.zoom)
4994 and h = truncate
((float h)*.conf.zoom) in
4997 state.anchor <- getanchor ();
4998 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5000 G.postRedisplay "z";
5005 | 50 when ctrl -> (* ctrl-2 *)
5006 let maxw = getmaxw
() in
5008 then setzoom (maxw /. float conf.winw
)
5010 | 60 | 62 -> (* < > *)
5011 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5013 | 91 | 93 -> (* [ ] *)
5015 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5017 G.postRedisplay "brightness";
5019 | 99 when state.mode = View
-> (* c *)
5021 match state.prevcolumns
with
5022 | None
-> (1, 0, 0), 1.0
5023 | Some
(columns
, z
) ->
5026 | Csplit
(c, _) -> -c, 0, 0
5027 | Cmulti
((c, a, b), _) -> c, a, b
5028 | Csingle
_ -> 1, 0, 0
5032 setcolumns View
c a b;
5035 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5036 setzoom state.prevzoom
5038 | 107 | 0xff52 -> (* k up *)
5039 begin match state.autoscroll
with
5041 begin match state.mode with
5042 | Birdseye beye
-> upbirdseye 1 beye
5045 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5046 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5049 setautoscrollspeed n false
5052 | 106 | 0xff54 -> (* j down *)
5053 begin match state.autoscroll
with
5055 begin match state.mode with
5056 | Birdseye beye
-> downbirdseye 1 beye
5059 then gotoy_and_clear_text (clamp (conf.winh
/2))
5060 else gotoy_and_clear_text (clamp conf.scrollstep
)
5063 setautoscrollspeed n true
5066 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5074 let dx = if key = 0xff51 then dx else -dx in
5075 state.x <- state.x + dx;
5076 gotoy_and_clear_text state.y
5079 G.postRedisplay "lef/right"
5082 | 0xff55 -> (* prior *)
5086 match state.layout with
5088 | l :: _ -> state.y - l.pagey
5090 clamp (pgscale (-conf.winh
))
5094 | 0xff56 -> (* next *)
5098 match List.rev
state.layout with
5100 | l :: _ -> getpagey l.pageno
5102 clamp (pgscale conf.winh
)
5106 | 0xff50 -> (* home *)
5108 | 0xff57 -> (* end *)
5109 gotoghyll (clamp state.maxy)
5110 | 0xff53 when Wsi.withalt mask
-> (* right *)
5111 gotoghyll (getnav ~
-1)
5112 | 0xff51 when Wsi.withalt mask
-> (* left *)
5113 gotoghyll (getnav 1)
5116 state.anchor <- getanchor ();
5117 opendoc state.path state.password
5119 | 118 when conf.debug
-> (* v *)
5122 match getopaque l.pageno with
5125 let x0, y0, x1, y1 = pagebbox opaque
in
5126 let a,b = float x0, float y0 in
5127 let c,d = float x1, float y0 in
5128 let e,f = float x1, float y1 in
5129 let h,j
= float x0, float y1 in
5130 let rect = (a,b,c,d,e,f,h,j
) in
5132 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5134 G.postRedisplay "v";
5137 vlog "huh? %s" (Wsi.keyname
key)
5140 let linknavkeyboard key mask
linknav =
5141 let getpage pageno =
5142 let rec loop = function
5144 | l :: _ when l.pageno = pageno -> Some
l
5145 | _ :: rest
-> loop rest
5146 in loop state.layout
5148 let doexact (pageno, n) =
5149 match getopaque pageno, getpage pageno with
5150 | Some opaque
, Some
l ->
5153 let under = getlink opaque
n in
5154 G.postRedisplay "link gotounder";
5160 | 0xff50 -> (* home *)
5161 Some
(findlink opaque LDfirst
), -1
5163 | 0xff57 -> (* end *)
5164 Some
(findlink opaque LDlast
), 1
5166 | 0xff51 -> (* left *)
5167 Some
(findlink opaque
(LDleft
n)), -1
5169 | 0xff53 -> (* right *)
5170 Some
(findlink opaque
(LDright
n)), 1
5172 | 0xff52 -> (* up *)
5173 Some
(findlink opaque
(LDup
n)), -1
5175 | 0xff54 -> (* down *)
5176 Some
(findlink opaque
(LDdown
n)), 1
5181 begin match findpwl
l.pageno dir with
5185 state.mode <- LinkNav
(Ltgendir
dir);
5186 let y, h = getpageyh pageno in
5189 then y + h - conf.winh
5194 begin match getopaque pageno, getpage pageno with
5195 | Some opaque
, Some
_ ->
5197 let ld = if dir > 0 then LDfirst
else LDlast
in
5200 begin match link with
5202 showlinktype (getlink opaque
m);
5203 state.mode <- LinkNav
(Ltexact
(pageno, m));
5204 G.postRedisplay "linknav jpage";
5211 begin match opt with
5212 | Some Lnotfound
-> pwl l dir;
5213 | Some
(Lfound
m) ->
5217 let _, y0, _, y1 = getlinkrect opaque
m in
5219 then gotopage1 l.pageno y0
5221 let d = fstate.fontsize
+ 1 in
5222 if y1 - l.pagey > l.pagevh - d
5223 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5224 else G.postRedisplay "linknav";
5226 showlinktype (getlink opaque
m);
5227 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5230 | None
-> viewkeyboard key mask
5232 | _ -> viewkeyboard key mask
5237 G.postRedisplay "leave linknav"
5241 | Ltgendir
_ -> viewkeyboard key mask
5242 | Ltexact exact
-> doexact exact
5245 let keyboard key mask
=
5246 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5247 then wcmd "interrupt"
5248 else state.uioh <- state.uioh#
key key mask
5251 let birdseyekeyboard key mask
5252 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5254 match conf.columns
with
5256 | Cmulti
((c, _, _), _) -> c
5257 | Csplit
_ -> failwith
"bird's eye split mode"
5259 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5261 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5262 let y, h = getpageyh pageno in
5263 let top = (conf.winh
- h) / 2 in
5264 gotoy (max
0 (y - top))
5265 | 0xff0d -> leavebirdseye beye
false
5266 | 0xff1b -> leavebirdseye beye
true (* escape *)
5267 | 0xff52 -> upbirdseye incr beye
(* up *)
5268 | 0xff54 -> downbirdseye incr beye
(* down *)
5269 | 0xff51 -> upbirdseye 1 beye
(* left *)
5270 | 0xff53 -> downbirdseye 1 beye
(* right *)
5272 | 0xff55 -> (* prior *)
5273 begin match state.layout with
5277 state.mode <- Birdseye
(
5278 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5280 gotopage1 l.pageno 0;
5283 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5285 | [] -> gotoy (clamp (-conf.winh
))
5287 state.mode <- Birdseye
(
5288 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5290 gotopage1 l.pageno 0
5293 | [] -> gotoy (clamp (-conf.winh
))
5296 | 0xff56 -> (* next *)
5297 begin match List.rev
state.layout with
5299 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5300 begin match layout with
5302 let incr = l.pageh
- l.pagevh in
5307 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5309 G.postRedisplay "birdseye pagedown";
5311 else gotoy (clamp (incr + conf.interpagespace
*2));
5315 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5316 gotopage1 l.pageno 0;
5319 | [] -> gotoy (clamp conf.winh
)
5322 | 0xff50 -> (* home *)
5323 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5326 | 0xff57 -> (* end *)
5327 let pageno = state.pagecount
- 1 in
5328 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5329 if not
(pagevisible state.layout pageno)
5332 match List.rev
state.pdims
with
5334 | (_, _, h, _) :: _ -> h
5336 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5337 else G.postRedisplay "birdseye end";
5338 | _ -> viewkeyboard key mask
5341 let drawpage l linkindexbase
=
5343 match state.mode with
5344 | Textentry
_ -> scalecolor 0.4
5346 | View
-> scalecolor 1.0
5347 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5348 if l.pageno = hooverpageno
5351 if l.pageno = pageno
5357 begin match getopaque l.pageno with
5359 if tileready l l.pagex
l.pagey
5361 let x = l.pagedispx - l.pagex
5362 and y = l.pagedispy - l.pagey in
5364 match conf.columns
with
5365 | Csingle
_ | Cmulti
_ ->
5366 (if conf.hlinks
then 1 else 0)
5368 && not
(isbirdseye state.mode) then 2 else 0)
5372 match state.mode with
5373 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5376 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5383 let scrollindicator () =
5384 let sbw, ph
, sh = state.uioh#
scrollph in
5385 let sbh, pw, sw = state.uioh#scrollpw
in
5387 GlDraw.color (0.64, 0.64, 0.64);
5389 (float (conf.winw
- sbw), 0.)
5390 (float conf.winw
, float conf.winh
)
5393 (0., float (conf.winh
- sbh))
5394 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5396 GlDraw.color (0.0, 0.0, 0.0);
5399 (float (conf.winw
- sbw), ph
)
5400 (float conf.winw
, ph
+. sh)
5403 (pw, float (conf.winh
- sbh))
5404 (pw +. sw, float conf.winh
)
5409 match state.mstate
with
5410 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5413 | Msel
((x0, y0), (x1, y1)) ->
5414 let rec loop = function
5416 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5417 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5418 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5419 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5421 match getopaque l.pageno with
5423 let x0, y0 = pagetranslatepoint l x0 y0 in
5424 let x1, y1 = pagetranslatepoint l x1 y1 in
5425 seltext opaque
(x0, y0, x1, y1);
5433 let showrects rects
=
5435 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5436 GlDraw.polygon_mode `both `fill
;
5437 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5439 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5441 if l.pageno = pageno
5443 let dx = float (l.pagedispx - l.pagex
) in
5444 let dy = float (l.pagedispy - l.pagey) in
5445 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5446 GlDraw.begins `quads
;
5448 GlDraw.vertex2
(x0+.dx, y0+.dy);
5449 GlDraw.vertex2
(x1+.dx, y1+.dy);
5450 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5451 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5462 GlClear.color (scalecolor2 conf.bgcolor
);
5463 GlClear.clear
[`
color];
5464 let rec loop linkindexbase
= function
5466 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5467 loop linkindexbase rest
5470 loop 0 state.layout;
5472 match state.mode with
5473 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5474 begin match getopaque pageno with
5476 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5483 | None
-> state.rects
5490 begin match state.mstate
with
5491 | Mzoomrect
((x0, y0), (x1, y1)) ->
5493 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5494 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5495 GlDraw.rect (float x0, float y0)
5496 (float x1, float y1);
5505 let zoomrect x y x1 y1 =
5508 and y0 = min
y y1 in
5509 gotoy (state.y + y0);
5510 state.anchor <- getanchor ();
5511 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5513 if state.w < conf.winw
- state.scrollw
5514 then (conf.winw
- state.scrollw
- state.w) / 2
5517 state.x <- (state.x + margin) - x0;
5519 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5520 state.mstate
<- Mnone
;
5524 let winw = conf.winw - state.scrollw
- 1 in
5525 let s = float x /. float winw in
5526 let destx = truncate
(float (state.w + winw) *. s) in
5527 state.x <- winw - destx;
5528 gotoy_and_clear_text state.y;
5529 state.mstate
<- Mscrollx
;
5533 let s = float y /. float conf.winh
in
5534 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5535 gotoy_and_clear_text desty;
5536 state.mstate
<- Mscrolly
;
5539 let viewmouse button down
x y mask
=
5541 | n when (n == 4 || n == 5) && not down
->
5542 if Wsi.withctrl mask
5544 match state.mstate
with
5545 | Mzoom
(oldn
, i
) ->
5553 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5555 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5557 let zoom = conf.zoom -. incr in
5559 state.mstate
<- Mzoom
(n, 0);
5561 state.mstate
<- Mzoom
(n, i
+1);
5563 else state.mstate
<- Mzoom
(n, 0)
5565 | _ -> state.mstate
<- Mzoom
(n, 0)
5568 match state.autoscroll
with
5569 | Some step
-> setautoscrollspeed step
(n=4)
5573 then -conf.scrollstep
5574 else conf.scrollstep
5576 let incr = incr * 2 in
5577 let y = clamp incr in
5578 gotoy_and_clear_text y
5581 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5582 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5583 gotoy_and_clear_text state.y
5585 | 1 when Wsi.withctrl mask
->
5588 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5589 state.mstate
<- Mpan
(x, y)
5592 state.mstate
<- Mnone
5597 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5599 state.mstate
<- Mzoomrect
(p, p)
5602 match state.mstate
with
5603 | Mzoomrect
((x0, y0), _) ->
5604 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5605 then zoomrect x0 y0 x y
5607 state.mstate
<- Mnone
;
5608 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5609 G.postRedisplay "kill accidental zoom rect";
5612 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5613 state.mstate
<- Mnone
5616 | 1 when x > conf.winw - state.scrollw
->
5619 let _, position, sh = state.uioh#
scrollph in
5620 if y > truncate
position && y < truncate
(position +. sh)
5621 then state.mstate
<- Mscrolly
5624 state.mstate
<- Mnone
5626 | 1 when y > conf.winh
- state.hscrollh ->
5629 let _, position, sw = state.uioh#scrollpw
in
5630 if x > truncate
position && x < truncate
(position +. sw)
5631 then state.mstate
<- Mscrollx
5634 state.mstate
<- Mnone
5637 let dest = if down
then getunder x y else Unone
in
5638 begin match dest with
5642 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5645 | Unone
when down
->
5646 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5647 state.mstate
<- Mpan
(x, y);
5649 | Unone
| Utext
_ ->
5652 if conf.angle
mod 360 = 0
5654 state.mstate
<- Msel
((x, y), (x, y));
5655 G.postRedisplay "mouse select";
5659 match state.mstate
with
5662 | Mzoom
_ | Mscrollx
| Mscrolly
->
5663 state.mstate
<- Mnone
5665 | Mzoomrect
((x0, y0), _) ->
5669 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5670 state.mstate
<- Mnone
5672 | Msel
((_, y0), (_, y1)) ->
5673 let rec loop = function
5676 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5677 || ((y1 >= l.pagedispy
5678 && y1 <= (l.pagedispy + l.pagevh)))
5680 match getopaque l.pageno with
5683 match Ne.pipe () with
5687 "can not create sel pipe: %s"
5688 (Printexc.to_string exn
));
5690 let doclose what fd
=
5691 Ne.clo fd
(fun msg
->
5692 dolog "%s close failed: %s" what msg
)
5695 popen conf.selcmd
[r, 0; w, -1];
5698 G.postRedisplay "copysel";
5700 dolog "can not execute %S: %s"
5701 conf.selcmd
(Printexc.to_string exn
);
5709 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5710 state.mstate
<- Mnone
;
5717 let birdseyemouse button down
x y mask
5718 (conf, leftx
, _, hooverpageno
, anchor) =
5721 let rec loop = function
5724 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5725 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5727 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5733 | _ -> viewmouse button down
x y mask
5736 let mouse button down
x y mask
=
5737 state.uioh <- state.uioh#button button down
x y mask
;
5741 state.uioh <- state.uioh#
motion x y
5745 state.uioh <- state.uioh#
pmotion x y;
5751 method key key mask
=
5752 begin match state.mode with
5753 | Textentry
textentry -> textentrykeyboard key mask
textentry
5754 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5755 | View
-> viewkeyboard key mask
5756 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5760 method button button bstate
x y mask
=
5761 begin match state.mode with
5763 | View
-> viewmouse button bstate
x y mask
5764 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5770 begin match state.mode with
5772 | View
| Birdseye
_ | LinkNav
_ ->
5773 match state.mstate
with
5774 | Mzoom
_ | Mnone
-> ()
5779 state.mstate
<- Mpan
(x, y);
5781 then state.x <- state.x + dx;
5783 gotoy_and_clear_text y
5786 state.mstate
<- Msel
(a, (x, y));
5787 G.postRedisplay "motion select";
5790 let y = min
conf.winh
(max
0 y) in
5794 let x = min
conf.winw (max
0 x) in
5797 | Mzoomrect
(p0
, _) ->
5798 state.mstate
<- Mzoomrect
(p0
, (x, y));
5799 G.postRedisplay "motion zoomrect";
5803 method pmotion x y =
5804 begin match state.mode with
5805 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5806 let rec loop = function
5808 if hooverpageno
!= -1
5810 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5811 G.postRedisplay "pmotion birdseye no hoover";
5814 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5815 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5817 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5818 G.postRedisplay "pmotion birdseye hoover";
5828 match state.mstate
with
5829 | Mnone
-> updateunder x y
5830 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5835 method infochanged
_ = ()
5838 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5839 let p, h = scrollph state.y maxy in
5843 let winw = conf.winw - state.scrollw
- 1 in
5844 let fwinw = float winw in
5846 let sw = fwinw /. float state.w in
5847 let sw = fwinw *. sw in
5848 max
sw (float conf.scrollh
)
5851 let f = state.w+winw in
5852 let r = float (winw-state.x) /. float f in
5853 let p = fwinw *. r in
5857 if position +. sw > fwinw
5858 then fwinw -. position
5861 state.hscrollh, position, sw
5865 match state.mode with
5866 | LinkNav
_ -> "links"
5867 | Textentry
_ -> "textentry"
5868 | Birdseye
_ -> "birdseye"
5871 findkeyhash conf modename
5878 let fontpath = ref "";;
5881 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5884 let l = String.length
s in
5885 let b = Buffer.create
l in
5891 try Sys.getenv
"HOME"
5894 ("Can not determine home directory location: " ^
5895 Printexc.to_string exn
);
5899 let modifier_of_string = function
5900 | "alt" -> Wsi.altmask
5901 | "shift" -> Wsi.shiftmask
5902 | "ctrl" | "control" -> Wsi.ctrlmask
5903 | "meta" -> Wsi.metamask
5908 let r = Str.regexp
"-" in
5910 let elems = Str.full_split
r s in
5913 let m1 = modifier_of_string s in
5915 then (Wsi.namekey
s, m)
5918 | Str.Delim
s when n land 1 = 0 -> g s
5920 | Str.Delim
_ -> (k
, m)
5922 let rec loop n k
m = function
5925 let k, m = f n k m x in
5931 let keys_of_string =
5932 let r = Str.regexp
"[ \t]" in
5934 let elems = Str.split
r s in
5935 List.map
key_of_string elems
5938 let copykeyhashes c =
5939 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5942 let config_of c attrs
=
5946 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5947 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5948 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5949 | "preload" -> { c with preload = bool_of_string
v }
5950 | "page-bias" -> { c with pagebias
= int_of_string
v }
5951 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5952 | "horizontal-scroll-step" ->
5953 { c with hscrollstep
= max
(int_of_string
v) 1 }
5954 | "auto-scroll-step" ->
5955 { c with autoscrollstep
= max
0 (int_of_string
v) }
5956 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5957 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5960 match String.lowercase
v with
5961 | "true" -> Some infinity
5963 | f -> Some
(float_of_string
f)
5965 { c with maxwait
= mw}
5966 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5967 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5968 | "vertical-margin" ->
5969 { c with interpagespace
= max
0 (int_of_string
v) }
5971 let zoom = float_of_string
v /. 100. in
5972 let zoom = max
zoom 0.0 in
5973 { c with zoom = zoom }
5974 | "presentation" -> { c with presentation
= bool_of_string
v }
5975 | "rotation-angle" -> { c with angle
= int_of_string
v }
5976 | "width" -> { c with winw = max
20 (int_of_string
v) }
5977 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5978 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5979 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5980 | "pixmap-cache-size" ->
5981 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5982 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5983 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5984 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5985 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5986 | "background-color" -> { c with bgcolor
= color_of_string v }
5987 | "scrollbar-in-presentation" ->
5988 { c with scrollbarinpm
= bool_of_string
v }
5989 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5990 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5991 | "mupdf-store-size" ->
5992 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5993 | "checkers" -> { c with checkers
= bool_of_string
v }
5994 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5995 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5996 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5997 | "uri-launcher" -> { c with urilauncher
= unent v }
5998 | "path-launcher" -> { c with pathlauncher
= unent v }
5999 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6000 | "invert-colors" -> { c with invert
= bool_of_string
v }
6001 | "brightness" -> { c with colorscale
= float_of_string
v }
6002 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6004 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6006 let (n, _, _) as nab
= multicolumns_of_string v in
6008 then { c with columns
= Csplit
(-n, [||]) }
6009 else { c with columns
= Cmulti
(nab
, [||]) }
6010 | "birds-eye-columns" ->
6011 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6012 | "selection-command" -> { c with selcmd
= unent v }
6013 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6014 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6015 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6018 prerr_endline
("Error processing attribute (`" ^
6019 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6022 let rec fold c = function
6025 let c = apply c k v in
6028 fold { c with keyhashes
= copykeyhashes c } attrs
;
6031 let fromstring f pos
n v d =
6034 dolog "Error processing attribute (%S=%S) at %d\n%s"
6035 n v pos
(Printexc.to_string exn
)
6040 let bookmark_of attrs
=
6041 let rec fold title page
rely visy
= function
6042 | ("title", v) :: rest
-> fold v page
rely visy rest
6043 | ("page", v) :: rest
-> fold title v rely visy rest
6044 | ("rely", v) :: rest
-> fold title page
v visy rest
6045 | ("visy", v) :: rest
-> fold title page
rely v rest
6046 | _ :: rest
-> fold title page
rely visy rest
6047 | [] -> title, page
, rely, visy
6049 fold "invalid" "0" "0" "0" attrs
6053 let rec fold path page
rely pan visy
= function
6054 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6055 | ("page", v) :: rest
-> fold path v rely pan visy rest
6056 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6057 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6058 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6059 | _ :: rest
-> fold path page
rely pan visy rest
6060 | [] -> path, page
, rely, pan
, visy
6062 fold "" "0" "0" "0" "0" attrs
6066 let rec fold rs ls
= function
6067 | ("out", v) :: rest
-> fold v ls rest
6068 | ("in", v) :: rest
-> fold rs
v rest
6069 | _ :: rest
-> fold ls rs rest
6075 let setconf dst
src =
6076 dst
.scrollbw
<- src.scrollbw
;
6077 dst
.scrollh
<- src.scrollh
;
6078 dst
.icase
<- src.icase
;
6079 dst
.preload <- src.preload;
6080 dst
.pagebias
<- src.pagebias
;
6081 dst
.verbose
<- src.verbose
;
6082 dst
.scrollstep
<- src.scrollstep
;
6083 dst
.maxhfit
<- src.maxhfit
;
6084 dst
.crophack
<- src.crophack
;
6085 dst
.autoscrollstep
<- src.autoscrollstep
;
6086 dst
.maxwait
<- src.maxwait
;
6087 dst
.hlinks
<- src.hlinks
;
6088 dst
.underinfo
<- src.underinfo
;
6089 dst
.interpagespace
<- src.interpagespace
;
6090 dst
.zoom <- src.zoom;
6091 dst
.presentation
<- src.presentation
;
6092 dst
.angle
<- src.angle
;
6093 dst
.winw <- src.winw;
6094 dst
.winh
<- src.winh
;
6095 dst
.savebmarks
<- src.savebmarks
;
6096 dst
.memlimit
<- src.memlimit
;
6097 dst
.proportional
<- src.proportional
;
6098 dst
.texcount
<- src.texcount
;
6099 dst
.sliceheight
<- src.sliceheight
;
6100 dst
.thumbw
<- src.thumbw
;
6101 dst
.jumpback
<- src.jumpback
;
6102 dst
.bgcolor
<- src.bgcolor
;
6103 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6104 dst
.tilew
<- src.tilew
;
6105 dst
.tileh
<- src.tileh
;
6106 dst
.mustoresize
<- src.mustoresize
;
6107 dst
.checkers
<- src.checkers
;
6108 dst
.aalevel
<- src.aalevel
;
6109 dst
.trimmargins
<- src.trimmargins
;
6110 dst
.trimfuzz
<- src.trimfuzz
;
6111 dst
.urilauncher
<- src.urilauncher
;
6112 dst
.colorspace
<- src.colorspace
;
6113 dst
.invert
<- src.invert
;
6114 dst
.colorscale
<- src.colorscale
;
6115 dst
.redirectstderr <- src.redirectstderr;
6116 dst
.ghyllscroll
<- src.ghyllscroll
;
6117 dst
.columns
<- src.columns
;
6118 dst
.beyecolumns
<- src.beyecolumns
;
6119 dst
.selcmd
<- src.selcmd
;
6120 dst
.updatecurs
<- src.updatecurs
;
6121 dst
.pathlauncher
<- src.pathlauncher
;
6122 dst
.keyhashes
<- copykeyhashes src;
6123 dst
.hfsize
<- src.hfsize
;
6124 dst
.hscrollstep
<- src.hscrollstep
;
6125 dst
.pgscale <- src.pgscale;
6129 let h = Hashtbl.create
10 in
6130 let dc = { defconf with angle
= defconf.angle
} in
6131 let rec toplevel v t spos
_ =
6133 | Vdata
| Vcdata
| Vend
-> v
6134 | Vopen
("llppconfig", _, closed
) ->
6137 else { v with f = llppconfig
}
6139 error
"unexpected subelement at top level" s spos
6140 | Vclose
_ -> error
"unexpected close at top level" s spos
6142 and llppconfig
v t spos
_ =
6144 | Vdata
| Vcdata
-> v
6145 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6146 | Vopen
("defaults", attrs
, closed
) ->
6147 let c = config_of dc attrs
in
6151 else { v with f = defaults
}
6153 | Vopen
("ui-font", attrs
, closed
) ->
6154 let rec getsize size
= function
6156 | ("size", v) :: rest
->
6158 fromstring int_of_string spos
"size" v fstate.fontsize
in
6160 | l -> getsize size l
6162 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6165 else { v with f = uifont
(Buffer.create
10) }
6167 | Vopen
("doc", attrs
, closed
) ->
6168 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6169 let path = unent pathent
6170 and pageno = fromstring int_of_string spos
"page" spage
0
6171 and rely = fromstring float_of_string spos
"rely" srely
0.0
6172 and pan
= fromstring int_of_string spos
"pan" span
0
6173 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6174 let c = config_of dc attrs
in
6175 let anchor = (pageno, rely, visy
) in
6177 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6178 else { v with f = doc
path pan
anchor c [] }
6181 error
"unexpected subelement in llppconfig" s spos
6183 | Vclose
"llppconfig" -> { v with f = toplevel }
6184 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6186 and defaults
v t spos
_ =
6188 | Vdata
| Vcdata
-> v
6189 | Vend
-> error
"unexpected end of input in defaults" s spos
6190 | Vopen
("keymap", attrs
, closed
) ->
6192 try List.assoc
"mode" attrs
6193 with Not_found
-> "global" in
6198 let h = findkeyhash dc modename in
6199 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6202 { v with f = pkeymap
ret KeyMap.empty }
6204 | Vopen
(_, _, _) ->
6205 error
"unexpected subelement in defaults" s spos
6207 | Vclose
"defaults" ->
6208 { v with f = llppconfig
}
6210 | Vclose
_ -> error
"unexpected close in defaults" s spos
6212 and uifont
b v t spos
epos =
6215 Buffer.add_substring
b s spos
(epos - spos
);
6217 | Vopen
(_, _, _) ->
6218 error
"unexpected subelement in ui-font" s spos
6219 | Vclose
"ui-font" ->
6220 if String.length
!fontpath = 0
6221 then fontpath := Buffer.contents
b;
6222 { v with f = llppconfig
}
6223 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6224 | Vend
-> error
"unexpected end of input in ui-font" s spos
6226 and doc
path pan
anchor c bookmarks
v t spos
_ =
6228 | Vdata
| Vcdata
-> v
6229 | Vend
-> error
"unexpected end of input in doc" s spos
6230 | Vopen
("bookmarks", _, closed
) ->
6233 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6235 | Vopen
("keymap", attrs
, closed
) ->
6237 try List.assoc
"mode" attrs
6238 with Not_found
-> "global"
6244 let h = findkeyhash c modename in
6245 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6246 doc
path pan
anchor c bookmarks
6248 { v with f = pkeymap
ret KeyMap.empty }
6250 | Vopen
(_, _, _) ->
6251 error
"unexpected subelement in doc" s spos
6254 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6255 { v with f = llppconfig
}
6257 | Vclose
_ -> error
"unexpected close in doc" s spos
6259 and pkeymap
ret keymap
v t spos
_ =
6261 | Vdata
| Vcdata
-> v
6262 | Vend
-> error
"unexpected end of input in keymap" s spos
6263 | Vopen
("map", attrs
, closed
) ->
6264 let r, l = map_of attrs
in
6265 let kss = fromstring keys_of_string spos
"in" r [] in
6266 let lss = fromstring keys_of_string spos
"out" l [] in
6270 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6271 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6274 then { v with f = pkeymap
ret keymap }
6277 { v with f = skip
"map" f }
6280 error
"unexpected subelement in keymap" s spos
6282 | Vclose
"keymap" ->
6283 { v with f = ret keymap }
6285 | Vclose
_ -> error
"unexpected close in keymap" s spos
6287 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6289 | Vdata
| Vcdata
-> v
6290 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6291 | Vopen
("item", attrs
, closed
) ->
6292 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6293 let page = fromstring int_of_string spos
"page" spage
0
6294 and rely = fromstring float_of_string spos
"rely" srely
0.0
6295 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6297 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6300 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6303 { v with f = skip
"item" f }
6306 error
"unexpected subelement in bookmarks" s spos
6308 | Vclose
"bookmarks" ->
6309 { v with f = doc
path pan
anchor c bookmarks }
6311 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6313 and skip tag
f v t spos
_ =
6315 | Vdata
| Vcdata
-> v
6317 error
("unexpected end of input in skipped " ^ tag
) s spos
6318 | Vopen
(tag'
, _, closed
) ->
6322 let f'
() = { v with f = skip tag
f } in
6323 { v with f = skip tag'
f'
}
6327 else error
("unexpected close in skipped " ^ tag
) s spos
6330 parse
{ f = toplevel; accu = () } s;
6336 let len = in_channel_length ic
in
6337 let s = String.create
len in
6338 really_input ic
s 0 len;
6341 | Parse_error
(msg
, s, pos
) ->
6342 let subs = subs s pos
in
6343 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6344 failwith
("parse error: " ^
s)
6347 failwith
("config load error: " ^
Printexc.to_string exn
)
6353 let dir = Filename.concat
home ".config" in
6354 if Sys.is_directory
dir then dir else home
6357 Filename.concat
dir "llpp.conf"
6360 let confpath = ref defconfpath;;
6363 if Sys.file_exists
!confpath
6366 (try Some
(open_in_bin
!confpath)
6369 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6370 Printexc.to_string exn
);
6379 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6380 Printexc.to_string exn
);
6386 f (Hashtbl.create
0, defconf)
6391 let pc, pb
, px, pa
=
6393 Hashtbl.find h (Filename.basename
state.path)
6394 with Not_found
-> dc, [], 0, emptyanchor
6398 state.bookmarks <- pb
;
6400 state.scrollw
<- conf.scrollbw
;
6402 then state.anchor <- pa
;
6403 cbput state.hists
.nav pa
;
6408 let add_attrs bb always
dc c =
6411 then Printf.bprintf bb
"\n %s='%b'" s a
6414 then Printf.bprintf bb
"\n %s='%d'" s a
6417 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6420 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6423 then Printf.bprintf bb
"\n %s='%f'" s a
6427 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6431 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6435 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6439 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6445 | Some
(_N
, _A
, _B
) ->
6446 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6456 else string_of_float
f
6458 Printf.bprintf bb
"\n %s='%s'" s v
6463 | Cmulti
((n, a, b), _) when n > 1 ->
6464 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6465 | Csplit
(n, _) when n > 1 ->
6466 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6472 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6477 then dc.winw, dc.winh
6479 match state.fullscreen
with
6481 | None
-> c.winw, c.winh
6483 oi
"width" w dc.winw;
6484 oi
"height" h dc.winh
;
6485 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6486 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6487 ob "case-insensitive-search" c.icase
dc.icase
;
6488 ob "preload" c.preload dc.preload;
6489 oi
"page-bias" c.pagebias
dc.pagebias
;
6490 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6491 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6492 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6493 ob "crop-hack" c.crophack
dc.crophack
;
6494 oW
"throttle" c.maxwait
dc.maxwait
;
6495 ob "highlight-links" c.hlinks
dc.hlinks
;
6496 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6497 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6498 oz
"zoom" c.zoom dc.zoom;
6499 ob "presentation" c.presentation
dc.presentation
;
6500 oi
"rotation-angle" c.angle
dc.angle
;
6501 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6502 ob "proportional-display" c.proportional
dc.proportional
;
6503 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6504 oi
"tex-count" c.texcount
dc.texcount
;
6505 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6506 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6507 ob "persistent-location" c.jumpback
dc.jumpback
;
6508 oc
"background-color" c.bgcolor
dc.bgcolor
;
6509 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6510 oi
"tile-width" c.tilew
dc.tilew
;
6511 oi
"tile-height" c.tileh
dc.tileh
;
6512 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6513 ob "checkers" c.checkers
dc.checkers
;
6514 oi
"aalevel" c.aalevel
dc.aalevel
;
6515 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6516 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6517 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6518 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6519 oC
"color-space" c.colorspace
dc.colorspace
;
6520 ob "invert-colors" c.invert
dc.invert
;
6521 oF
"brightness" c.colorscale
dc.colorscale
;
6522 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6523 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6524 oco
"columns" c.columns
dc.columns
;
6525 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6526 os
"selection-command" c.selcmd
dc.selcmd
;
6527 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6528 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6529 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6530 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6533 let keymapsbuf always
dc c =
6534 let bb = Buffer.create
16 in
6535 let rec loop = function
6537 | (modename, h) :: rest
->
6538 let dh = findkeyhash dc modename in
6539 if always
|| h <> dh
6541 if Hashtbl.length
h > 0
6543 if Buffer.length
bb > 0
6544 then Buffer.add_char
bb '
\n'
;
6545 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6546 Hashtbl.iter
(fun i
o ->
6547 let isdifferent = always
||
6549 let dO = Hashtbl.find dh i
in
6551 with Not_found
-> true
6556 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6557 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6558 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6559 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6560 Buffer.add_string
bb (Wsi.keyname
k);
6563 let rec loop = function
6565 | km
:: [] -> addkm km
6566 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6570 Buffer.add_string
bb "<map in='";
6574 Buffer.add_string
bb "' out='";
6576 Buffer.add_string
bb "'/>\n"
6579 Buffer.add_string
bb "' out='";
6581 Buffer.add_string
bb "'/>\n"
6583 | KMmulti
(ins, kms
) ->
6584 Buffer.add_char
bb ' '
;
6586 Buffer.add_string
bb "' out='";
6588 Buffer.add_string
bb "'/>\n"
6590 Buffer.add_string
bb "</keymap>";
6600 let uifontsize = fstate.fontsize
in
6601 let bb = Buffer.create
32768 in
6603 let dc = if conf.bedefault
then conf else dc in
6604 Buffer.add_string
bb "<llppconfig>\n";
6606 if String.length
!fontpath > 0
6608 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6614 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6617 Buffer.add_string
bb "<defaults ";
6618 add_attrs bb true dc dc;
6619 let kb = keymapsbuf true dc dc in
6620 if Buffer.length
kb > 0
6622 Buffer.add_string
bb ">\n";
6623 Buffer.add_buffer
bb kb;
6624 Buffer.add_string
bb "\n</defaults>\n";
6626 else Buffer.add_string
bb "/>\n";
6628 let adddoc path pan
anchor c bookmarks =
6629 if bookmarks == [] && c = dc && anchor = emptyanchor
6632 Printf.bprintf
bb "<doc path='%s'"
6633 (enent
path 0 (String.length
path));
6635 if anchor <> emptyanchor
6637 let n, rely, visy
= anchor in
6638 Printf.bprintf
bb " page='%d'" n;
6641 Printf.bprintf
bb " rely='%f'" rely
6643 if abs_float visy
> 1e-6
6645 Printf.bprintf
bb " visy='%f'" visy
6650 then Printf.bprintf
bb " pan='%d'" pan
;
6652 add_attrs bb false dc c;
6653 let kb = keymapsbuf false dc c in
6655 begin match bookmarks with
6657 if Buffer.length
kb > 0
6659 Buffer.add_string
bb ">\n";
6660 Buffer.add_buffer
bb kb;
6661 Buffer.add_string
bb "\n</doc>\n";
6663 else Buffer.add_string
bb "/>\n"
6665 Buffer.add_string
bb ">\n<bookmarks>\n";
6666 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6668 "<item title='%s' page='%d'"
6669 (enent
title 0 (String.length
title))
6674 Printf.bprintf
bb " rely='%f'" rely
6676 if abs_float visy
> 1e-6
6678 Printf.bprintf
bb " visy='%f'" visy
6680 Buffer.add_string
bb "/>\n";
6682 Buffer.add_string
bb "</bookmarks>";
6683 if Buffer.length
kb > 0
6685 Buffer.add_string
bb "\n";
6686 Buffer.add_buffer
bb kb;
6688 Buffer.add_string
bb "\n</doc>\n";
6694 match state.mode with
6695 | Birdseye
(c, pan, _, _, _) ->
6697 match conf.columns
with
6698 | Cmulti
((c, _, _), _) -> Some
c
6702 match c.columns
with
6703 | Cmulti
(c, _) -> Cmulti
(c, [||])
6704 | Csingle
_ -> Csingle
[||]
6705 | Csplit
_ -> failwith
"quit from bird's eye while split"
6707 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6708 | _ -> state.x, conf
6710 let basename = Filename.basename state.path in
6711 adddoc basename pan (getanchor ())
6713 let autoscrollstep =
6714 match state.autoscroll
with
6716 | None
-> conf.autoscrollstep
6718 match state.mode with
6719 | Birdseye
(bc
, _, _, _, _) ->
6722 presentation
= bc
.presentation
;
6723 interpagespace
= bc
.interpagespace
;
6724 maxwait
= bc
.maxwait
;
6725 autoscrollstep = autoscrollstep }
6726 | _ -> { conf with autoscrollstep = autoscrollstep }
6728 (if conf.savebmarks
then state.bookmarks else []);
6730 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6732 then adddoc path x anchor c bookmarks
6734 Buffer.add_string
bb "</llppconfig>";
6737 if Buffer.length
bb > 0
6740 let tmp = !confpath ^
".tmp" in
6741 let oc = open_out_bin
tmp in
6742 Buffer.output_buffer
oc bb;
6744 Unix.rename
tmp !confpath;
6747 ("error while saving configuration: " ^
Printexc.to_string exn
)
6752 let trimcachepath = ref "" in
6755 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6756 "<password> Set password");
6758 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6759 "<path> Set path to the user interface font");
6761 ("-c", Arg.String
(fun s -> Config.confpath := s),
6762 "<path> Set path to the configuration file");
6764 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6765 "<path> Set path to the trim cache file");
6767 ("-v", Arg.Unit
(fun () ->
6769 "%s\nconfiguration path: %s\n"
6773 exit
0), " Print version and exit");
6776 (fun s -> state.path <- s)
6777 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6779 if String.length
state.path = 0
6780 then (prerr_endline
"file name missing"; exit
1);
6784 let globalkeyhash = findkeyhash conf "global" in
6785 let wsfd, winw, winh
= Wsi.init
(object
6787 if nogeomcmds state.geomcmds
|| platform == Posx
6790 GlClear.color (scalecolor2 conf.bgcolor
);
6791 GlClear.clear
[`
color];
6793 method display = display ()
6794 method reshape w h = reshape w h
6795 method mouse b d x y m = mouse b d x y m
6796 method motion x y = state.mpos
<- (x, y); motion x y
6797 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6799 let mascm = m land (
6800 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6802 match state.keystate
with
6804 let km = k, mascm in
6807 let modehash = state.uioh#
modehash in
6808 try Hashtbl.find modehash km
6810 try Hashtbl.find globalkeyhash km
6811 with Not_found
-> KMinsrt
(k, m)
6813 | KMinsrt
(k, m) -> keyboard k m
6814 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6815 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6817 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6818 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6819 state.keystate
<- KSnone
6820 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6821 state.keystate
<- KSinto
(keys
, insrt
)
6823 state.keystate
<- KSnone
6825 method enter
x y = state.mpos
<- (x, y); pmotion x y
6826 method leave = state.mpos
<- (-1, -1)
6827 method quit
= raise Quit
6828 end) conf.winw conf.winh
(platform = Posx
) in
6833 List.exists
GlMisc.check_extension
6834 [ "GL_ARB_texture_rectangle"
6835 ; "GL_EXT_texture_recangle"
6836 ; "GL_NV_texture_rectangle" ]
6838 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6841 match Ne.pipe () with
6843 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6847 match Ne.pipe () with
6849 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6859 setcheckers conf.checkers
;
6863 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6864 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6865 !Config.fontpath, !trimcachepath
6869 state.text <- "Opening " ^
state.path;
6871 opendoc state.path state.password
;
6874 let rec loop deadline
=
6876 match state.errfd
with
6877 | None
-> [state.sr
; state.wsfd]
6878 | Some fd
-> [state.sr
; state.wsfd; fd
]
6882 state.redisplay
<- false;
6889 if deadline
= infinity
6891 else max
0.0 (deadline
-. now)
6896 try Unix.select
r [] [] timeout
6897 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6903 if state.ghyll
== noghyll
6905 match state.autoscroll
with
6906 | Some step
when step
!= 0 ->
6907 let y = state.y + step
in
6911 else if y >= state.maxy then 0 else y
6914 if state.mode = View
6915 then state.text <- "";
6918 else deadline
+. 0.01
6923 let rec checkfds = function
6925 | fd
:: rest
when fd
= state.sr
->
6926 let cmd = readcmd state.sr
in
6930 | fd
:: rest
when fd
= state.wsfd ->
6935 let s = String.create
80 in
6936 let n = Unix.read fd
s 0 80 in
6937 if conf.redirectstderr
6939 Buffer.add_substring
state.errmsgs
s 0 n;
6940 state.newerrmsgs
<- true;
6941 state.redisplay
<- true;
6944 prerr_string
(String.sub
s 0 n);
6952 if deadline
= infinity
6956 match state.autoscroll
with
6957 | Some step
when step
!= 0 -> deadline1
6958 | _ -> if state.ghyll
== noghyll then infinity
else deadline1