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
36 and trimcachepath
= string
39 and irect
= (int * int * int * int)
40 and trimparams
= (trimmargins
* irect
)
41 and colorspace
= | Rgb
| Bgr
| Gray
50 | LDfirstvisible
of (int * int * int)
65 | KMmulti
of key list
* key list
67 and keyhash
= (key
, keymap
) Hashtbl.t
70 | KSinto
of (key list
* key list
)
73 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
74 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
76 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
78 external init
: pipe
-> params
-> unit = "ml_init";;
79 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
80 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
81 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
82 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
83 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
84 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
85 external measurestr
: int -> string -> float = "ml_measure_string";;
86 external getmaxw
: unit -> float = "ml_getmaxw";;
87 external postprocess
:
88 opaque
-> int -> int -> int -> (int * string * int) -> int = "ml_postprocess";;
89 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
90 external platform
: unit -> platform
= "ml_platform";;
91 external setaalevel
: int -> unit = "ml_setaalevel";;
92 external realloctexts
: int -> bool = "ml_realloctexts";;
93 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
94 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
95 external getlink
: opaque
-> int -> under
= "ml_getlink";;
96 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
97 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
98 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
99 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
101 let platform_to_string = function
102 | Punknown
-> "unknown"
106 | Pfreebsd
-> "FreeBSD"
107 | Pdragonflybsd
-> "DragonflyBSD"
108 | Popenbsd
-> "OpenBSD"
109 | Pnetbsd
-> "NetBSD"
110 | Pcygwin
-> "Cygwin"
113 let platform = platform ();;
116 if platform = Pcygwin
118 let sh = "/bin/sh" in
119 let args = [|sh; "-c"; cmd
|] in
120 let rec std si so se
= function
122 | (fd
, 0) :: rest
-> std fd so se rest
123 | (fd
, -1) :: rest
->
124 Unix.set_close_on_exec fd
;
127 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
129 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
130 ignore
(Unix.create_process
sh args si so se
)
139 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
142 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
144 type mpos
= int * int
146 | Msel
of (mpos
* mpos
)
148 | Mscrolly
| Mscrollx
149 | Mzoom
of (int * int)
150 | Mzoomrect
of (mpos
* mpos
)
154 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
155 and onkey
= string -> int -> te
156 and ondone
= string -> unit
157 and histcancel
= unit -> unit
158 and onhist
= ((histcmd
-> string) * histcancel
)
159 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
160 and cancelonempty
= bool
165 | TEswitch
of textentry
176 let bound v minv maxv
=
177 max minv
(min maxv v
);
181 { store
= Array.create n v
188 let drawstring size x y s
=
190 Gl.enable `texture_2d
;
191 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
192 ignore
(drawstr size x y s
);
194 Gl.disable `texture_2d
;
197 let drawstring1 size x y s
=
201 let drawstring2 size x y fmt
=
202 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
205 let cbcap b
= Array.length b
.store
;;
210 b
.wc
<- (b
.wc
+ 1) mod cap;
212 b
.len
<- min
(b
.len
+ 1) cap;
215 let cbempty b
= b
.len
= 0;;
217 let cbgetg b circular dir
=
221 let rc = b
.rc + dir
in
233 else max
0 (min
rc (b
.len
-1))
239 let cbget b
= cbgetg b
false;;
240 let cbgetc b
= cbgetg b
true;;
258 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
259 dolog " WxH %dx%d" l
.pagew l
.pageh
;
260 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
261 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
262 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
263 dolog " column %d" l
.pagecol
;
267 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
269 dolog " x0,y0=(% f, % f)" x0 y0
;
270 dolog " x1,y1=(% f, % f)" x1 y1
;
271 dolog " x2,y2=(% f, % f)" x2 y2
;
272 dolog " x3,y3=(% f, % f)" x3 y3
;
276 type multicolumns
= multicol
* pagegeom
277 and singlecolumn
= pagegeom
278 and splitcolumns
= columncount
* pagegeom
279 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
280 and multicol
= columncount
* covercount
* covercount
282 and columncount
= int
283 and covercount
= int;;
286 { mutable scrollbw
: int
287 ; mutable scrollh
: int
288 ; mutable icase
: bool
289 ; mutable preload
: bool
290 ; mutable pagebias
: int
291 ; mutable verbose
: bool
292 ; mutable debug
: bool
293 ; mutable scrollstep
: int
294 ; mutable hscrollstep
: int
295 ; mutable maxhfit
: bool
296 ; mutable crophack
: bool
297 ; mutable autoscrollstep
: int
298 ; mutable maxwait
: float option
299 ; mutable hlinks
: bool
300 ; mutable underinfo
: bool
301 ; mutable interpagespace
: interpagespace
302 ; mutable zoom
: float
303 ; mutable presentation
: bool
304 ; mutable angle
: angle
307 ; mutable savebmarks
: bool
308 ; mutable proportional
: proportional
309 ; mutable trimmargins
: trimmargins
310 ; mutable trimfuzz
: irect
311 ; mutable memlimit
: memsize
312 ; mutable texcount
: texcount
313 ; mutable sliceheight
: sliceheight
314 ; mutable thumbw
: width
315 ; mutable jumpback
: bool
316 ; mutable bgcolor
: float * float * float
317 ; mutable bedefault
: bool
318 ; mutable scrollbarinpm
: bool
319 ; mutable tilew
: int
320 ; mutable tileh
: int
321 ; mutable mustoresize
: memsize
322 ; mutable checkers
: bool
323 ; mutable aalevel
: int
324 ; mutable urilauncher
: string
325 ; mutable pathlauncher
: string
326 ; mutable colorspace
: colorspace
327 ; mutable invert
: bool
328 ; mutable colorscale
: float
329 ; mutable redirectstderr
: bool
330 ; mutable ghyllscroll
: (int * int * int) option
331 ; mutable columns
: columns
332 ; mutable beyecolumns
: columncount
option
333 ; mutable selcmd
: string
334 ; mutable updatecurs
: bool
335 ; mutable keyhashes
: (string * keyhash
) list
336 ; mutable hfsize
: int
337 ; mutable pgscale
: float
340 | Csingle
of singlecolumn
341 | Cmulti
of multicolumns
342 | Csplit
of splitcolumns
345 type anchor
= pageno
* top
;;
347 type outline
= string * int * anchor
;;
349 type rect
= float * float * float * float * float * float * float * float;;
351 type tile
= opaque
* pixmapsize
* elapsed
352 and elapsed
= float;;
353 type pagemapkey
= pageno
* gen
;;
354 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
358 let emptyanchor = (0, 0.0);;
360 type infochange
= | Memused
| Docinfo
| Pdim
;;
362 class type uioh
= object
363 method display
: unit
364 method key
: int -> int -> uioh
365 method button
: int -> bool -> int -> int -> int -> uioh
366 method motion
: int -> int -> uioh
367 method pmotion
: int -> int -> uioh
368 method infochanged
: infochange
-> unit
369 method scrollpw
: (int * float * float)
370 method scrollph
: (int * float * float)
371 method modehash
: keyhash
375 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
376 | Textentry
of (textentry
* onleave
)
378 | LinkNav
of linktarget
379 and onleave
= leavetextentrystatus
-> unit
380 and leavetextentrystatus
= | Cancel
| Confirm
381 and helpitem
= string * int * action
384 | Action
of (uioh
-> uioh
)
386 | Ltexact
of (pageno
* int)
390 let isbirdseye = function Birdseye _
-> true | _
-> false;;
391 let istextentry = function Textentry _
-> true | _
-> false;;
395 | Loading
of (page
* gen
)
397 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
399 | Outlining
of outline list
402 let emptykeyhash = Hashtbl.create
0;;
403 let nouioh : uioh
= object (self
)
405 method key _ _
= self
406 method button _ _ _ _ _
= self
407 method motion _ _
= self
408 method pmotion _ _
= self
409 method infochanged _
= ()
410 method scrollpw
= (0, nan
, nan
)
411 method scrollph
= (0, nan
, nan
)
412 method modehash
= emptykeyhash
416 { mutable sr
: Unix.file_descr
417 ; mutable sw
: Unix.file_descr
418 ; mutable wsfd
: Unix.file_descr
419 ; mutable errfd
: Unix.file_descr
option
420 ; mutable stderr
: Unix.file_descr
421 ; mutable errmsgs
: Buffer.t
422 ; mutable newerrmsgs
: bool
426 ; mutable scrollw
: int
427 ; mutable hscrollh
: int
428 ; mutable anchor
: anchor
429 ; mutable ranchors
: (string * string * anchor
) list
431 ; mutable layout
: page list
432 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
433 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
434 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
435 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
436 ; mutable pagecount
: int
437 ; mutable currently
: currently
438 ; mutable mstate
: mstate
439 ; mutable searchpattern
: string
440 ; mutable rects
: (pageno
* recttype
* rect
) list
441 ; mutable rects1
: (pageno
* recttype
* rect
) list
442 ; mutable text
: string
443 ; mutable fullscreen
: (width
* height
) option
444 ; mutable mode
: mode
445 ; mutable uioh
: uioh
446 ; mutable outlines
: outline array
447 ; mutable bookmarks
: outline list
448 ; mutable path
: string
449 ; mutable password
: string
450 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
451 ; mutable memused
: memsize
453 ; mutable throttle
: (page list
* int * float) option
454 ; mutable autoscroll
: int option
455 ; mutable ghyll
: (int option -> unit)
456 ; mutable help
: helpitem array
457 ; mutable docinfo
: (int * string) list
458 ; mutable texid
: GlTex.texture_id
option
460 ; mutable prevzoom
: float
461 ; mutable progress
: float
462 ; mutable redisplay
: bool
463 ; mutable mpos
: mpos
464 ; mutable keystate
: keystate
465 ; mutable glinks
: bool
466 ; mutable prevcolumns
: (columns
* float) option
469 { pat
: string circbuf
470 ; pag
: string circbuf
471 ; nav
: anchor circbuf
472 ; sel
: string circbuf
494 ; presentation
= false
499 ; proportional
= true
500 ; trimmargins
= false
501 ; trimfuzz
= (0,0,0,0)
502 ; memlimit
= 32 lsl 20
507 ; bgcolor
= (0.5, 0.5, 0.5)
509 ; scrollbarinpm
= true
512 ; mustoresize
= 256 lsl 20
517 | Plinux
| Pfreebsd
| Pdragonflybsd
518 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
519 | Posx
-> "open \"%s\""
520 | Pcygwin
-> "cygstart \"%s\""
521 | Punknown
-> "echo %s")
522 ; pathlauncher
= "lp \"%s\""
525 | Plinux
| Pfreebsd
| Pdragonflybsd
526 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
533 ; redirectstderr
= false
535 ; columns
= Csingle
[||]
541 let mk n
= (n
, Hashtbl.create
1) in
555 let findkeyhash c name
=
556 try List.assoc name c
.keyhashes
557 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
560 let conf = { defconf with angle
= defconf.angle
};;
562 let pgscale h
= truncate
(float h
*. conf.pgscale);;
565 { mutable fontsize
: int
566 ; mutable wwidth
: float
567 ; mutable maxrows
: int
579 fstate.fontsize
<- n
;
580 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
581 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
585 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
586 let len = String.length s
in
587 if colonpos >= 0 && colonpos + 3 < len
589 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
592 try String.rindex_from s
colonpos ' '
596 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
599 | "http" | "ftp" | "mailto" ->
601 try String.index_from s
colonpos ' '
602 with Not_found
-> len
604 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
612 if String.length
conf.urilauncher
= 0
613 then print_endline uri
615 let url = geturl uri
in
616 if String.length
url = 0
617 then print_endline uri
619 let re = Str.regexp
"%s" in
620 let command = Str.global_replace
re url conf.urilauncher
in
624 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
630 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
631 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
635 let strings = version () :: "" :: Help.keys
in
638 let url = geturl s
in
639 if String.length
url > 0
640 then (s
, 0, Action
(fun u
-> gotouri url; u
))
641 else (s
, 0, Noaction
)
646 let firstgeomcmds = "", [];;
653 ; stderr
= Unix.stderr
654 ; errmsgs
= Buffer.create
0
661 ; anchor
= emptyanchor
665 ; tilelru
= Queue.create
()
666 ; pagemap
= Hashtbl.create
10
667 ; tilemap
= Hashtbl.create
10
682 ; geomcmds
= firstgeomcmds
684 { nav
= cbnew 10 (0, 0.0)
711 Printf.kprintf prerr_endline fmt
713 Printf.kprintf ignore fmt
717 if String.length
conf.pathlauncher
= 0
718 then print_endline
state.path
720 let re = Str.regexp
"%s" in
721 let command = Str.global_replace
re state.path
conf.pathlauncher
in
725 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
731 type 'a t
= | Res
of 'a
| Exn
of exn
;;
734 try Res
(Unix.pipe ())
740 with exn
-> f
(Printexc.to_string exn
)
744 try Res
(Unix.dup fd
)
749 try Res
(Unix.dup2 fd1 fd2
)
754 let redirectstderr () =
755 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
756 if conf.redirectstderr
758 match Ne.pipe () with
760 dolog "failed to create stderr redirection pipes: %s"
761 (Printexc.to_string exn
)
764 begin match Ne.dup Unix.stderr
with
766 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
767 Ne.clo r
(clofail "pipe/r");
768 Ne.clo w
(clofail "pipe/w");
770 | Ne.Res dupstderr
->
771 begin match Ne.dup2 w
Unix.stderr
with
773 dolog "failed to dup2 to stderr: %s"
774 (Printexc.to_string exn
);
775 Ne.clo dupstderr
(clofail "stderr duplicate");
776 Ne.clo r
(clofail "redir pipe/r");
777 Ne.clo w
(clofail "redir pipe/w");
780 state.stderr
<- dupstderr
;
781 state.errfd
<- Some r
;
785 state.newerrmsgs
<- false;
786 begin match state.errfd
with
788 begin match Ne.dup2 state.stderr
Unix.stderr
with
790 dolog "failed to dup2 original stderr: %s"
791 (Printexc.to_string exn
)
793 Ne.clo fd
(clofail "dup of stderr");
794 Unix.dup2 state.stderr
Unix.stderr
;
799 prerr_string
(Buffer.contents
state.errmsgs
);
801 Buffer.clear
state.errmsgs
;
807 let postRedisplay who
=
809 then prerr_endline
("redisplay for " ^ who
);
810 state.redisplay
<- true;
814 let getopaque pageno
=
815 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
816 with Not_found
-> None
819 let putopaque pageno opaque
=
820 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
823 let pagetranslatepoint l x y
=
824 let dy = y
- l
.pagedispy
in
825 let y = dy + l
.pagey
in
826 let dx = x
- l
.pagedispx
in
827 let x = dx + l
.pagex
in
834 begin match getopaque l
.pageno
with
836 let x0 = l
.pagedispx
in
837 let x1 = x0 + l
.pagevw
in
838 let y0 = l
.pagedispy
in
839 let y1 = y0 + l
.pagevh
in
840 if y >= y0 && y <= y1 && x >= x0 && x <= x1
842 let px, py
= pagetranslatepoint l
x y in
843 match whatsunder opaque
px py
with
856 state.text
<- Printf.sprintf
"%c%s" c s
;
857 G.postRedisplay "showtext";
860 let undertext = function
863 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
864 | Utext s
-> "font: " ^ s
865 | Uunexpected s
-> "unexpected: " ^ s
866 | Ulaunch s
-> "launch: " ^ s
867 | Unamed s
-> "named: " ^ s
868 | Uremote
(filename
, pageno
) ->
869 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
872 let updateunder x y =
873 match getunder x y with
874 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
876 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
877 Wsi.setcursor
Wsi.CURSOR_INFO
878 | Ulinkgoto
(pageno
, _
) ->
880 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
881 Wsi.setcursor
Wsi.CURSOR_INFO
883 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
884 Wsi.setcursor
Wsi.CURSOR_TEXT
886 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
887 Wsi.setcursor
Wsi.CURSOR_INHERIT
889 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
890 Wsi.setcursor
Wsi.CURSOR_INHERIT
892 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
893 Wsi.setcursor
Wsi.CURSOR_INHERIT
894 | Uremote
(filename
, pageno
) ->
895 if conf.underinfo
then showtext 'r'
896 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
897 Wsi.setcursor
Wsi.CURSOR_INFO
900 let showlinktype under
=
906 let s = undertext under
in
911 let b = Buffer.create
(String.length
s + 1) in
912 Buffer.add_string
b s;
917 let colorspace_of_string s =
918 match String.lowercase
s with
922 | _
-> failwith
"invalid colorspace"
925 let int_of_colorspace = function
931 let colorspace_of_int = function
935 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
938 let colorspace_to_string = function
944 let intentry_with_suffix text key
=
946 if key
>= 32 && key
< 127
950 match Char.lowercase
c with
952 let text = addchar text c in
956 let text = addchar text c in
960 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
964 let multicolumns_to_string (n
, a
, b) =
966 then Printf.sprintf
"%d" n
967 else Printf.sprintf
"%d,%d,%d" n a
b;
970 let multicolumns_of_string s =
972 (int_of_string
s, 0, 0)
974 Scanf.sscanf
s "%u,%u,%u" (fun n a
b -> (n
, a
, b));
979 let n = Unix.read fd
s 0 4 in
980 if n != 4 then failwith
"incomplete read(len)";
982 lor (Char.code
s.[0] lsl 24)
983 lor (Char.code
s.[1] lsl 16)
984 lor (Char.code
s.[2] lsl 8)
985 lor (Char.code
s.[3] lsl 0)
987 let s = String.create
len in
988 let n = Unix.read fd
s 0 len in
989 if n != len then failwith
"incomplete read(data)";
993 let btod b = if b then 1 else 0;;
996 let b = Buffer.create
16 in
997 Buffer.add_string
b "llll";
1000 let s = Buffer.contents
b in
1001 let n = String.length
s in
1003 (* dolog "wcmd %S" (String.sub s 4 len); *)
1004 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1005 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1006 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1007 s.[3] <- Char.chr
(len land 0xff);
1008 let n'
= Unix.write
state.sw
s 0 n in
1009 if n'
!= n then failwith
"write failed";
1014 if conf.presentation
1016 let d = conf.winh
- h
in
1017 max
conf.interpagespace
((d + 1) / 2)
1023 match conf.columns
with
1024 | Cmulti
((c, _
, _
), b) ->
1025 let rec loop y h
n =
1029 if n = Array.length
b
1032 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
1038 loop max_int
0 (((Array.length
b - 1) / c) * c)
1040 if Array.length
b > 0
1042 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1043 y + h
+ (if conf.presentation
then calcips h
else 0)
1046 if Array.length
b > 0
1048 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1053 let getpageyh pageno
=
1054 let pageno = bound pageno 0 state.pagecount
in
1055 match conf.columns
with
1057 let (_
, _
, y, (_
, _
, h
, _
)) = b.(pageno) in
1059 if conf.presentation
1065 let (_
, _
, y, (_
, _
, h
, _
)) = b.(pageno) in
1069 let (_
, _
, y, (_
, _
, h
, _
)) = b.(n) in
1073 let getpagedim pageno =
1076 | (n, _
, _
, _
) as pdim
:: rest
->
1078 then (if n = pageno then pdim
else ppdim
)
1083 f (-1, -1, -1, -1) state.pdims
1086 let getpagey pageno = fst
(getpageyh pageno);;
1088 let nogeomcmds cmds
=
1090 | s, [] -> String.length
s = 0
1094 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1095 let sh = sh - state.hscrollh
in
1096 let rec fold accu
n =
1097 if n = Array.length
b
1100 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
1103 || n = state.pagecount
- coverB
1104 || (n - coverA
) mod columns
= columns
- 1)
1110 let pagey = max
0 (y - vy
) in
1111 let pagedispy = if pagey > 0 then 0 else vy
- y in
1112 let pagedispx, pagex
=
1114 if n = coverA
- 1 || n = state.pagecount
- coverB
1115 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1116 else dx + xoff
+ state.x
1123 let vw = conf.winw
- state.scrollw
- pagedispx in
1124 let pw = w
- pagex
in
1127 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1128 if pagevw > 0 && pagevh > 0
1132 ; pagedimno
= pdimno
1139 ; pagedispx = pagedispx
1140 ; pagedispy = pagedispy
1152 List.rev
(fold [] 0)
1155 let layoutS (columns
, b) y sh =
1156 let sh = sh - state.hscrollh
in
1157 let rec fold accu n =
1158 if n = Array.length
b
1161 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
1168 let x = xoff
+ state.x in
1169 let pagey = max
0 (y - vy
) in
1170 let pagedispy = if pagey > 0 then 0 else vy
- y in
1171 let pagedispx, pagex
=
1185 let pagecolw = pagew
/columns
in
1187 if pagecolw < conf.winw
1188 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1192 let vw = conf.winw
- pagedispx - state.scrollw
in
1193 let pw = pagew
- pagex
in
1196 let pagevw = min
pagevw pagecolw in
1197 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1198 if pagevw > 0 && pagevh > 0
1201 { pageno = n/columns
1202 ; pagedimno
= pdimno
1209 ; pagedispx = pagedispx
1210 ; pagedispy = pagedispy
1211 ; pagecol
= n mod columns
1222 List.rev
(fold [] 0)
1226 if nogeomcmds state.geomcmds
1228 match conf.columns
with
1229 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1230 | Cmulti
c -> layoutN c y sh
1231 | Csplit
s -> layoutS s y sh
1236 let y = state.y + incr
in
1238 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1243 let tilex = l
.pagex
mod conf.tilew
in
1244 let tiley = l
.pagey mod conf.tileh
in
1246 let col = l
.pagex
/ conf.tilew
in
1247 let row = l
.pagey / conf.tileh
in
1249 let rec rowloop row y0 dispy h
=
1253 let dh = conf.tileh
- y0 in
1254 let dh = min h
dh in
1255 let rec colloop col x0 dispx w
=
1259 let dw = conf.tilew
- x0 in
1260 let dw = min w
dw in
1262 f col row dispx dispy
x0 y0 dw dh;
1263 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1266 colloop col tilex l
.pagedispx l
.pagevw;
1267 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1270 if l
.pagevw > 0 && l
.pagevh > 0
1271 then rowloop row tiley l
.pagedispy l
.pagevh;
1274 let gettileopaque l
col row =
1276 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1278 try Some
(Hashtbl.find
state.tilemap
key)
1279 with Not_found
-> None
1282 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1283 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1284 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1287 let drawtiles l color
=
1289 let f col row x y tilex tiley w h
=
1290 match gettileopaque l
col row with
1291 | Some
(opaque
, _
, t
) ->
1292 let params = x, y, w
, h
, tilex, tiley in
1296 GlFunc.blend_func `zero `one_minus_src_color
;
1298 drawtile
params opaque
;
1300 then Gl.disable `blend
;
1303 let s = Printf.sprintf
1307 let w = measurestr
fstate.fontsize
s in
1308 GlMisc.push_attrib
[`current
];
1309 GlDraw.color
(0.0, 0.0, 0.0);
1311 (float (x-2), float (y-2))
1312 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1313 GlDraw.color
(1.0, 1.0, 1.0);
1314 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1315 GlMisc.pop_attrib
();
1320 let lw = conf.winw
- state.scrollw
- x in
1323 let lh = conf.winh
- y in
1326 begin match state.texid
with
1328 Gl.enable `texture_2d
;
1329 GlTex.bind_texture `texture_2d id
;
1332 and x1 = float (x+w)
1333 and y1 = float (y+h
) in
1335 let tw = float w /. 64.0
1336 and th
= float h
/. 64.0 in
1337 let tx0 = float tilex /. 64.0
1338 and ty0
= float tiley /. 64.0 in
1340 and ty1
= ty0
+. th
in
1341 GlDraw.begins `quads
;
1342 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1343 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1344 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1345 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1348 Gl.disable `texture_2d
;
1350 GlDraw.color
(1.0, 1.0, 1.0);
1353 (float (x+w), float (y+h
));
1355 if w > 128 && h
> fstate.fontsize
+ 10
1357 GlDraw.color
(0.0, 0.0, 0.0);
1360 then (col*conf.tilew
, row*conf.tileh
)
1363 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r
;
1370 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1372 let tilevisible1 l
x y =
1374 and ax1
= l
.pagex
+ l
.pagevw
1376 and ay1
= l
.pagey + l
.pagevh in
1380 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1381 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1383 let rx0 = max
ax0 bx0
1384 and ry0
= max ay0 by0
1385 and rx1
= min ax1
bx1
1386 and ry1
= min ay1 by1
in
1388 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1389 nonemptyintersection
1392 let tilevisible layout n x y =
1393 let rec findpageinlayout m
= function
1394 | l
:: rest
when l
.pageno = n ->
1395 tilevisible1 l
x y || (
1396 match conf.columns
with
1397 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1400 | _
:: rest
-> findpageinlayout 0 rest
1403 findpageinlayout 0 layout;
1406 let tileready l
x y =
1407 tilevisible1 l
x y &&
1408 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1411 let tilepage n p
layout =
1412 let rec loop = function
1416 let f col row _ _ _ _ _ _
=
1417 if state.currently
= Idle
1419 match gettileopaque l
col row with
1422 let x = col*conf.tilew
1423 and y = row*conf.tileh
in
1425 let w = l
.pagew
- x in
1429 let h = l
.pageh
- y in
1432 wcmd "tile %s %d %d %d %d" p
x y w h;
1435 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1436 conf.tilew
, conf.tileh
1445 if nogeomcmds state.geomcmds
1449 let preloadlayout visiblepages
=
1450 let presentation = conf.presentation in
1451 let interpagespace = conf.interpagespace in
1452 conf.presentation <- false;
1453 conf.interpagespace <- 0;
1455 match visiblepages
with
1456 | [] -> if state.y >= state.maxy
then state.maxy
else 0
1457 | l
:: _
-> getpagey l
.pageno + (l
.pagey - min
0 l
.pagedispy)
1459 let y = if y < conf.winh
then 0 else y - conf.winh
in
1460 let h = conf.winh
*3 in
1461 let pages = layout y h in
1462 conf.presentation <- presentation;
1463 conf.interpagespace <- interpagespace;
1468 let rec loop pages =
1469 if state.currently
!= Idle
1474 begin match getopaque l
.pageno with
1476 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1477 state.currently
<- Loading
(l
, state.gen
);
1479 tilepage l
.pageno opaque
pages;
1484 if nogeomcmds state.geomcmds
1490 if conf.preload && state.currently
= Idle
1491 then load (preloadlayout pages);
1494 let layoutready layout =
1495 let rec fold all ls
=
1496 all
&& match ls
with
1498 let seen = ref false in
1499 let allvisible = ref true in
1500 let foo col row _ _ _ _ _ _
=
1502 allvisible := !allvisible &&
1503 begin match gettileopaque l
col row with
1509 fold (!seen && !allvisible) rest
1512 let alltilesvisible = fold true layout in
1517 let y = bound y 0 state.maxy
in
1518 let y, layout, proceed
=
1519 match conf.maxwait
with
1520 | Some time
when state.ghyll
== noghyll ->
1521 begin match state.throttle
with
1523 let layout = layout y conf.winh
in
1524 let ready = layoutready layout in
1528 state.throttle
<- Some
(layout, y, now ());
1530 else G.postRedisplay "gotoy showall (None)";
1532 | Some
(_
, _
, started
) ->
1533 let dt = now () -. started
in
1536 state.throttle
<- None
;
1537 let layout = layout y conf.winh
in
1539 G.postRedisplay "maxwait";
1546 let layout = layout y conf.winh
in
1547 if true || layoutready layout
1548 then G.postRedisplay "gotoy ready";
1554 state.layout <- layout;
1555 begin match state.mode
with
1556 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1557 let rec loop = function
1559 state.mode
<- LinkNav
(Ltgendir
0)
1560 | l
:: _
when l
.pageno = pageno ->
1561 begin match getopaque pageno with
1563 state.mode
<- LinkNav
(Ltgendir
0)
1565 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1566 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1567 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1568 then state.mode
<- LinkNav
(Ltgendir
0)
1570 | _
:: rest
-> loop rest
1575 begin match state.mode
with
1576 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1577 if not
(pagevisible layout pageno)
1579 match state.layout with
1582 state.mode
<- Birdseye
(
1583 conf, leftx
, l
.pageno, hooverpageno
, anchor
1586 | LinkNav
(Ltgendir dir
as lt
) ->
1588 let rec loop = function
1591 match getopaque l
.pageno with
1597 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1599 if dir
> 0 then LDfirst
else LDlast
1605 | Lnotfound
-> loop rest
1607 showlinktype (getlink opaque
n);
1608 Ltexact
(l
.pageno, n)
1612 state.mode
<- LinkNav
linknav
1617 state.ghyll
<- noghyll;
1620 let mx, my
= state.mpos
in
1625 let conttiling pageno opaque
=
1626 tilepage pageno opaque
1627 (if conf.preload then preloadlayout state.layout else state.layout)
1630 let gotoy_and_clear_text y =
1631 if not
conf.verbose
then state.text <- "";
1636 match state.layout with
1639 let coloff = l
.pagecol
* l
.pageh
in
1641 (float (l
.pagey - l
.pagedispy) +. float coloff) /. float l
.pageh
)
1644 let getanchory (n, top
) =
1645 let y, h = getpageyh n in
1646 y + (truncate
(top
*. float h));
1649 let gotoanchor anchor
=
1650 gotoy (getanchory anchor
);
1654 cbput state.hists
.nav
(getanchor ());
1658 let anchor = cbgetc state.hists
.nav dir
in
1663 let scroll f n a
b =
1664 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1666 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1668 then s (float f /. float a
)
1671 then 1.0 -. s ((float (f-b) /. float (n-b)))
1678 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1679 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1681 let ins = float a
*. iv1
1682 and outs
= float (n-b) *. iv1 in
1684 ins +. outs
+. float ones
1686 let rec set (_N
, _A
, _B
) y sy
=
1687 let sum = summa
1.0 _N _A _B
in
1688 let dy = float (y - sy
) in
1692 then state.ghyll
<- noghyll
1695 let s = scroll n _N _A _B
in
1696 let y1 = y1 +. ((s *. dy) /. sum) in
1697 gotoy_and_clear_text (truncate
y1);
1698 state.ghyll
<- gf (n+1) y1;
1702 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1704 gf 0 (float state.y)
1707 match conf.ghyllscroll
with
1709 gotoy_and_clear_text y
1711 if state.ghyll
== noghyll
1712 then set nab
y state.y
1713 else state.ghyll
(Some
y)
1716 let gotopage n top
=
1717 let y, h = getpageyh n in
1718 let y = y + (truncate
(top
*. float h)) in
1722 let gotopage1 n top
=
1723 let y = getpagey n in
1728 let invalidate s f =
1733 match state.geomcmds
with
1734 | ps
, [] when String.length ps
= 0 ->
1736 state.geomcmds
<- s, [];
1739 state.geomcmds
<- ps
, [s, f];
1741 | ps
, (s'
, _
) :: rest
when s'
= s ->
1742 state.geomcmds
<- ps
, ((s, f) :: rest
);
1745 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1748 let opendoc path password
=
1750 state.password
<- password
;
1751 state.gen
<- state.gen
+ 1;
1752 state.docinfo
<- [];
1754 setaalevel
conf.aalevel
;
1755 Wsi.settitle
("llpp " ^
Filename.basename path
);
1756 wcmd "open %s\000%s\000" path password
;
1757 invalidate "reqlayout"
1759 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1763 let c = c *. conf.colorscale
in
1767 let scalecolor2 (r
, g
, b) =
1768 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1771 let docolumns = function
1773 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1774 let rec loop pageno pdimno pdim
y ph pdims
=
1775 if pageno = state.pagecount
1778 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1780 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno ->
1781 pdimno+1, pdim
, rest
1786 if isbirdseye state.mode
1787 then (conf.winw
- state.scrollw
- w) / 2 - xoff
1791 (if conf.presentation
1792 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1793 else (if pageno = 0 then 0 else calcips h)
1796 a.(pageno) <- (pdimno, x, y, pdim
);
1797 loop (pageno+1) pdimno pdim
(y + h) h pdims
1799 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1800 conf.columns
<- Csingle
a;
1802 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1803 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1804 let rec loop pageno pdimno pdim
x y rowh pdims
=
1805 let rec fixrow m
= if m
= pageno then () else
1806 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1809 let y = y + (rowh
- h) / 2 in
1810 a.(m
) <- (pdimno, x, y, pdim
);
1814 if pageno = state.pagecount
1815 then fixrow (((pageno - 1) / columns
) * columns
)
1817 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1819 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno ->
1820 pdimno+1, pdim
, rest
1825 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1827 (conf.winw
- state.scrollw
- w) / 2,
1828 y + rowh
+ conf.interpagespace, h
1831 if (pageno - coverA
) mod columns
= 0
1832 then 0, y + rowh
+ conf.interpagespace, h
1833 else x, y, max rowh
h
1836 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1837 then fixrow (pageno - columns
);
1838 a.(pageno) <- (pdimno, x, y, pdim
);
1839 let x = x + w + xoff
*2 + conf.interpagespace in
1840 loop (pageno+1) pdimno pdim
x y rowh' pdims
1842 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1843 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1846 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1847 let rec loop pageno pdimno pdim
y pdims
=
1848 if pageno = state.pagecount
1851 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1853 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno ->
1854 pdimno+1, pdim
, rest
1859 let rec loop1 n x y =
1860 if n = c then y else (
1861 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
1862 loop1 (n+1) (x+cw) (y + h + conf.interpagespace)
1865 let y = loop1 0 0 y in
1866 loop (pageno+1) pdimno pdim
y pdims
1868 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1869 conf.columns
<- Csplit
(c, a);
1873 docolumns conf.columns
;
1874 state.maxy
<- calcheight ();
1876 if state.w <= conf.winw
- state.scrollw
1880 match state.mode
with
1881 | Birdseye
(_
, _
, pageno, _
, _
) ->
1882 let y, h = getpageyh pageno in
1883 let top = (conf.winh
- h) / 2 in
1884 gotoy (max
0 (y - top))
1885 | _
-> gotoanchor state.anchor
1889 GlDraw.viewport
0 0 w h;
1890 let firsttime = state.geomcmds
== firstgeomcmds in
1891 if not
firsttime && nogeomcmds state.geomcmds
1892 then state.anchor <- getanchor ();
1895 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1898 setfontsize fstate.fontsize
;
1899 GlMat.mode `modelview
;
1900 GlMat.load_identity
();
1902 GlMat.mode `projection
;
1903 GlMat.load_identity
();
1904 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1905 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1906 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1911 else float state.x /. float state.w
1913 invalidate "geometry"
1917 then state.x <- truncate
(relx *. float w);
1919 match conf.columns
with
1921 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1922 | Csplit
(c, _
) -> w * c
1924 wcmd "geometry %d %d" w h);
1928 let len = String.length
state.text in
1931 match state.mode
with
1934 let h, _
, _
= state.uioh#scrollpw
in
1940 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1941 (x+.w, float (conf.winh
- hscrollh))
1944 let w = float (conf.winw
- state.scrollw
- 1) in
1945 if state.progress
>= 0.0 && state.progress
< 1.0
1947 GlDraw.color
(0.3, 0.3, 0.3);
1948 let w1 = w *. state.progress
in
1950 GlDraw.color
(0.0, 0.0, 0.0);
1954 GlDraw.color
(0.0, 0.0, 0.0);
1958 GlDraw.color
(1.0, 1.0, 1.0);
1959 drawstring fstate.fontsize
1960 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1963 match state.mode
with
1964 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
1968 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1970 Printf.sprintf
"%s%s_" prefix
text
1979 if not
(istextentry state.mode
)
1981 let s1 = "(press 'e' to review error messasges)" in
1982 if String.length
s > 0 then s ^
" " ^
s1 else s1
1987 if String.length
s > 0
1992 let len = Queue.length
state.tilelru
in
1994 match state.throttle
with
1997 then preloadlayout state.layout
1999 | Some
(layout, _
, _
) ->
2003 if state.memused
<= conf.memlimit
2008 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2009 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2010 let (_
, pw, ph
, _
) = getpagedim n in
2013 && colorspace
= conf.colorspace
2014 && angle
= conf.angle
2018 let x = col*conf.tilew
2019 and y = row*conf.tileh
in
2020 tilevisible (Lazy.force_val
layout) n x y
2022 then Queue.push lruitem
state.tilelru
2024 wcmd "freetile %s" p
;
2025 state.memused
<- state.memused
- s;
2026 state.uioh#infochanged Memused
;
2027 Hashtbl.remove
state.tilemap k
;
2036 Queue.iter
(fun (k
, p
, s) ->
2037 wcmd "freetile %s" p
;
2038 state.memused
<- state.memused
- s;
2039 state.uioh#infochanged Memused
;
2040 Hashtbl.remove
state.tilemap k
;
2042 Queue.clear
state.tilelru
;
2046 let logcurrently = function
2047 | Idle
-> dolog "Idle"
2048 | Loading
(l
, gen
) ->
2049 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2050 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2052 "Tiling %d[%d,%d] page=%s cs=%s angle"
2053 l
.pageno col row pageopaque
2054 (colorspace_to_string colorspace
)
2056 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2057 angle gen
conf.angle
state.gen
2059 conf.tilew
conf.tileh
2066 (* dolog "%S" cmds; *)
2069 try String.index cmds ' '
2070 with Not_found
-> -1
2075 let l = String.length cmds
in
2076 let op = String.sub cmds
0 spacepos in
2078 if l - spacepos < 2 then ""
2079 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2084 state.uioh#infochanged Pdim
;
2088 state.rects
<- state.rects1
;
2089 G.postRedisplay "clearrects";
2093 try Scanf.sscanf
args "%u" (fun n -> n)
2095 dolog "error processing 'continue' %S: %s"
2096 cmds
(Printexc.to_string exn
);
2099 state.pagecount
<- n;
2100 begin match state.currently
with
2102 state.currently
<- Idle
;
2103 state.outlines
<- Array.of_list
(List.rev
l)
2107 let cur, cmds
= state.geomcmds
in
2108 if String.length
cur = 0
2109 then failwith
"umpossible";
2111 begin match List.rev cmds
with
2113 state.geomcmds
<- "", [];
2117 state.geomcmds
<- s, List.rev rest
;
2119 if conf.maxwait
= None
2120 then G.postRedisplay "continue";
2130 then showtext ' '
args
2133 let progress, text =
2135 Scanf.sscanf
args "%f %n"
2137 f, String.sub
args pos
(String.length
args - pos
))
2139 dolog "error processing 'progress' %S: %s"
2140 cmds
(Printexc.to_string exn
);
2144 state.progress <- progress;
2145 G.postRedisplay "progress"
2148 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2150 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2151 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2152 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2154 dolog "error processing 'firstmatch' %S: %s"
2155 cmds
(Printexc.to_string exn
);
2158 let y = (getpagey pageno) + truncate
y0 in
2161 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2164 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2166 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2167 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2168 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2170 dolog "error processing 'match' %S: %s"
2171 cmds
(Printexc.to_string exn
);
2175 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2180 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2182 dolog "error processing 'page' %S: %s"
2183 cmds
(Printexc.to_string exn
);
2186 begin match state.currently
with
2187 | Loading
(l, gen
) ->
2188 vlog "page %d took %f sec" l.pageno t
;
2189 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2190 begin match state.throttle
with
2192 let preloadedpages =
2194 then preloadlayout state.layout
2199 Set.Make
(struct type t
= int let compare = (-) end) in
2201 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2202 IntSet.empty
preloadedpages
2205 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2206 if not
(IntSet.mem
pageno set)
2208 wcmd "freepage %s" opaque
;
2214 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2217 state.currently
<- Idle
;
2220 tilepage l.pageno pageopaque state.layout;
2222 load preloadedpages;
2223 if pagevisible state.layout l.pageno
2224 && layoutready state.layout
2225 then G.postRedisplay "page";
2228 | Some
(layout, _
, _
) ->
2229 state.currently
<- Idle
;
2230 tilepage l.pageno pageopaque layout;
2235 dolog "Inconsistent loading state";
2236 logcurrently state.currently
;
2241 let (x, y, opaque
, size
, t
) =
2243 Scanf.sscanf
args "%u %u %s %u %f"
2244 (fun x y p size t
-> (x, y, p
, size
, t
))
2246 dolog "error processing 'tile' %S: %s"
2247 cmds
(Printexc.to_string exn
);
2250 begin match state.currently
with
2251 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2252 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2254 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2256 wcmd "freetile %s" opaque
;
2257 state.currently
<- Idle
;
2261 puttileopaque l col row gen cs angle opaque size t
;
2262 state.memused
<- state.memused
+ size
;
2263 state.uioh#infochanged Memused
;
2265 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2266 opaque
, size
) state.tilelru
;
2269 match state.throttle
with
2270 | None
-> state.layout
2271 | Some
(layout, _
, _
) -> layout
2274 state.currently
<- Idle
;
2276 && conf.colorspace
= cs
2277 && conf.angle
= angle
2278 && tilevisible layout l.pageno x y
2279 then conttiling l.pageno pageopaque;
2281 begin match state.throttle
with
2283 preload state.layout;
2285 && conf.colorspace
= cs
2286 && conf.angle
= angle
2287 && tilevisible state.layout l.pageno x y
2288 then G.postRedisplay "tile nothrottle";
2290 | Some
(layout, y, _
) ->
2291 let ready = layoutready layout in
2295 state.layout <- layout;
2296 state.throttle
<- None
;
2297 G.postRedisplay "throttle";
2304 dolog "Inconsistent tiling state";
2305 logcurrently state.currently
;
2312 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2314 dolog "error processing 'pdim' %S: %s"
2315 cmds
(Printexc.to_string exn
);
2318 state.uioh#infochanged Pdim
;
2319 state.pdims
<- pdim :: state.pdims
2322 let (l, n, t
, h, pos
) =
2324 Scanf.sscanf
args "%u %u %d %u %n"
2325 (fun l n t
h pos
-> l, n, t
, h, pos
)
2327 dolog "error processing 'o' %S: %s"
2328 cmds
(Printexc.to_string exn
);
2331 let s = String.sub
args pos
(String.length
args - pos
) in
2332 let outline = (s, l, (n, float t
/. float h)) in
2333 begin match state.currently
with
2334 | Outlining outlines
->
2335 state.currently
<- Outlining
(outline :: outlines
)
2337 state.currently
<- Outlining
[outline]
2339 dolog "invalid outlining state";
2340 logcurrently currently
2344 state.docinfo
<- (1, args) :: state.docinfo
2347 state.uioh#infochanged Docinfo
;
2348 state.docinfo
<- List.rev
state.docinfo
2351 dolog "unknown cmd `%S'" cmds
2356 let action = function
2357 | HCprev
-> cbget cb ~
-1
2358 | HCnext
-> cbget cb
1
2359 | HCfirst
-> cbget cb ~
-(cb
.rc)
2360 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2361 and cancel
() = cb
.rc <- rc
2365 let search pattern forward
=
2366 if String.length pattern
> 0
2369 match state.layout with
2372 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2374 wcmd "search %d %d %d %d,%s\000"
2375 (btod conf.icase
) pn py
(btod forward
) pattern
;
2378 let intentry text key =
2380 if key >= 32 && key < 127
2386 let text = addchar text c in
2390 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2394 let linknentry text key =
2396 if key >= 32 && key < 127
2402 let text = addchar text c in
2406 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2411 if String.length
s > 0
2414 let l = String.length
s in
2415 let rec loop pos
n = if pos
= l then n else
2416 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2417 loop (pos
+1) (n*26 + m)
2420 let rec loop n = function
2423 match getopaque l.pageno with
2424 | None
-> loop n rest
2426 let m = getlinkcount opaque
in
2429 let under = getlink opaque
n in
2432 else loop (n-m) rest
2434 loop n state.layout;
2438 let textentry text key =
2439 if key land 0xff00 = 0xff00
2441 else TEcont
(text ^
Wsi.toutf8
key)
2444 let reqlayout angle proportional
=
2445 match state.throttle
with
2447 if nogeomcmds state.geomcmds
2448 then state.anchor <- getanchor ();
2449 conf.angle
<- angle
mod 360;
2452 match state.mode
with
2453 | LinkNav _
-> state.mode
<- View
2456 conf.proportional
<- proportional
;
2457 invalidate "reqlayout"
2458 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2462 let settrim trimmargins trimfuzz
=
2463 if nogeomcmds state.geomcmds
2464 then state.anchor <- getanchor ();
2465 conf.trimmargins
<- trimmargins
;
2466 conf.trimfuzz
<- trimfuzz
;
2467 let x0, y0, x1, y1 = trimfuzz
in
2468 invalidate "settrim"
2470 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2471 Hashtbl.iter
(fun _ opaque
->
2472 wcmd "freepage %s" opaque
;
2474 Hashtbl.clear
state.pagemap
;
2478 match state.throttle
with
2480 let zoom = max
0.01 zoom in
2481 if zoom <> conf.zoom
2483 state.prevzoom
<- conf.zoom;
2485 reshape conf.winw
conf.winh
;
2486 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2489 | Some
(layout, y, started
) ->
2491 match conf.maxwait
with
2495 let dt = now () -. started
in
2503 let setcolumns mode columns coverA coverB
=
2504 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2508 then showtext '
!'
"split mode doesn't work in bird's eye"
2510 conf.columns
<- Csplit
(-columns
, [||]);
2518 conf.columns
<- Csingle
[||];
2523 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2527 reshape conf.winw
conf.winh
;
2530 let enterbirdseye () =
2531 let zoom = float conf.thumbw
/. float conf.winw
in
2532 let birdseyepageno =
2533 let cy = conf.winh
/ 2 in
2537 let rec fold best
= function
2540 let d = cy - (l.pagedispy + l.pagevh/2)
2541 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2542 if abs
d < abs dbest
2549 state.mode
<- Birdseye
(
2550 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2553 conf.presentation <- false;
2554 conf.interpagespace <- 10;
2555 conf.hlinks
<- false;
2557 state.mstate
<- Mnone
;
2558 conf.maxwait
<- None
;
2560 match conf.beyecolumns
with
2563 Cmulti
((c, 0, 0), [||])
2564 | None
-> Csingle
[||]
2566 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2569 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2574 reshape conf.winw
conf.winh
;
2577 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2579 conf.zoom <- c.zoom;
2580 conf.presentation <- c.presentation;
2581 conf.interpagespace <- c.interpagespace;
2582 conf.maxwait
<- c.maxwait
;
2583 conf.hlinks
<- c.hlinks
;
2584 conf.beyecolumns
<- (
2585 match conf.columns
with
2586 | Cmulti
((c, _
, _
), _
) -> Some
c
2588 | Csplit _
-> failwith
"leaving bird's eye split mode"
2591 match c.columns
with
2592 | Cmulti
(c, _
) -> Cmulti
(c, [||])
2593 | Csingle _
-> Csingle
[||]
2594 | Csplit
(c, _
) -> Csplit
(c, [||])
2599 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2602 reshape conf.winw
conf.winh
;
2603 state.anchor <- if goback
then anchor else (pageno, 0.0);
2606 let togglebirdseye () =
2607 match state.mode
with
2608 | Birdseye vals
-> leavebirdseye vals
true
2609 | View
-> enterbirdseye ()
2613 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2614 let pageno = max
0 (pageno - incr
) in
2615 let rec loop = function
2616 | [] -> gotopage1 pageno 0
2617 | l :: _
when l.pageno = pageno ->
2618 if l.pagedispy >= 0 && l.pagey = 0
2619 then G.postRedisplay "upbirdseye"
2620 else gotopage1 pageno 0
2621 | _
:: rest
-> loop rest
2624 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2627 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2628 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2629 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2630 let rec loop = function
2632 let y, h = getpageyh pageno in
2633 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2635 | l :: _
when l.pageno = pageno ->
2636 if l.pagevh != l.pageh
2637 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2638 else G.postRedisplay "downbirdseye"
2639 | _
:: rest
-> loop rest
2644 let optentry mode _
key =
2645 let btos b = if b then "on" else "off" in
2646 if key >= 32 && key < 127
2648 let c = Char.chr
key in
2652 try conf.scrollstep
<- int_of_string
s with exc
->
2653 state.text <- Printf.sprintf
"bad integer `%s': %s"
2654 s (Printexc.to_string exc
)
2656 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2661 conf.autoscrollstep
<- int_of_string
s;
2662 if state.autoscroll
<> None
2663 then state.autoscroll
<- Some
conf.autoscrollstep
2665 state.text <- Printf.sprintf
"bad integer `%s': %s"
2666 s (Printexc.to_string exc
)
2668 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2673 let n, a, b = multicolumns_of_string s in
2674 setcolumns mode
n a b;
2676 state.text <- Printf.sprintf
"bad columns `%s': %s"
2677 s (Printexc.to_string exc
)
2679 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2684 let zoom = float (int_of_string
s) /. 100.0 in
2687 state.text <- Printf.sprintf
"bad integer `%s': %s"
2688 s (Printexc.to_string exc
)
2690 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2695 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2697 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2698 begin match mode
with
2700 leavebirdseye beye
false;
2705 state.text <- Printf.sprintf
"bad integer `%s': %s"
2706 s (Printexc.to_string exc
)
2708 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2713 Some
(int_of_string
s)
2715 state.text <- Printf.sprintf
"bad integer `%s': %s"
2716 s (Printexc.to_string exc
);
2719 | Some angle
-> reqlayout angle
conf.proportional
2722 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2725 conf.icase
<- not
conf.icase
;
2726 TEdone
("case insensitive search " ^
(btos conf.icase
))
2729 conf.preload <- not
conf.preload;
2731 TEdone
("preload " ^
(btos conf.preload))
2734 conf.verbose
<- not
conf.verbose
;
2735 TEdone
("verbose " ^
(btos conf.verbose
))
2738 conf.debug
<- not
conf.debug
;
2739 TEdone
("debug " ^
(btos conf.debug
))
2742 conf.maxhfit
<- not
conf.maxhfit
;
2743 state.maxy
<- calcheight ();
2744 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2747 conf.crophack
<- not
conf.crophack
;
2748 TEdone
("crophack " ^
btos conf.crophack
)
2752 match conf.maxwait
with
2754 conf.maxwait
<- Some infinity
;
2755 "always wait for page to complete"
2757 conf.maxwait
<- None
;
2758 "show placeholder if page is not ready"
2763 conf.underinfo
<- not
conf.underinfo
;
2764 TEdone
("underinfo " ^
btos conf.underinfo
)
2767 conf.savebmarks
<- not
conf.savebmarks
;
2768 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2774 match state.layout with
2779 conf.interpagespace <- int_of_string
s;
2780 docolumns conf.columns
;
2781 state.maxy
<- calcheight ();
2782 let y = getpagey pageno in
2785 state.text <- Printf.sprintf
"bad integer `%s': %s"
2786 s (Printexc.to_string exc
)
2788 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2791 reqlayout conf.angle
(not
conf.proportional
);
2792 TEdone
("proportional display " ^
btos conf.proportional
)
2795 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2796 TEdone
("trim margins " ^
btos conf.trimmargins
)
2799 conf.invert
<- not
conf.invert
;
2800 TEdone
("invert colors " ^
btos conf.invert
)
2804 cbput state.hists
.sel
s;
2807 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2808 textentry, ondone, true)
2811 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2817 class type lvsource
= object
2818 method getitemcount
: int
2819 method getitem
: int -> (string * int)
2820 method hasaction
: int -> bool
2829 method getactive
: int
2830 method getfirst
: int
2831 method getqsearch
: string
2832 method setqsearch
: string -> unit
2836 class virtual lvsourcebase
= object
2837 val mutable m_active
= 0
2838 val mutable m_first
= 0
2839 val mutable m_qsearch
= ""
2840 val mutable m_pan
= 0
2841 method getactive
= m_active
2842 method getfirst
= m_first
2843 method getqsearch
= m_qsearch
2844 method getpan
= m_pan
2845 method setqsearch
s = m_qsearch
<- s
2848 let withoutlastutf8 s =
2849 let len = String.length
s in
2857 let b = Char.code
s.[pos
] in
2858 if b land 0b110000 = 0b11000000
2863 if Char.code
s.[len-1] land 0x80 = 0
2867 String.sub
s 0 first;
2870 let textentrykeyboard
2871 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2873 state.mode
<- Textentry
(te
, onleave
);
2876 G.postRedisplay "textentrykeyboard enttext";
2878 let histaction cmd
=
2881 | Some
(action, _
) ->
2882 state.mode
<- Textentry
(
2883 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2885 G.postRedisplay "textentry histaction"
2888 | 0xff08 -> (* backspace *)
2889 let s = withoutlastutf8 text in
2890 let len = String.length
s in
2891 if cancelonempty
&& len = 0
2894 G.postRedisplay "textentrykeyboard after cancel";
2897 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2903 G.postRedisplay "textentrykeyboard after confirm"
2905 | 0xff52 -> histaction HCprev
2906 | 0xff54 -> histaction HCnext
2907 | 0xff50 -> histaction HCfirst
2908 | 0xff57 -> histaction HClast
2910 | 0xff1b -> (* escape*)
2911 if String.length
text = 0
2913 begin match opthist
with
2915 | Some
(_
, onhistcancel
) -> onhistcancel
()
2919 G.postRedisplay "textentrykeyboard after cancel2"
2922 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
2925 | 0xff9f | 0xffff -> () (* delete *)
2927 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2928 begin match onkey
text key with
2932 G.postRedisplay "textentrykeyboard after confirm2";
2935 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2939 G.postRedisplay "textentrykeyboard after cancel3"
2942 state.mode
<- Textentry
(te
, onleave
);
2943 G.postRedisplay "textentrykeyboard switch";
2947 vlog "unhandled key %s" (Wsi.keyname
key)
2950 let firstof first active
=
2951 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2952 then max
0 (active
- (fstate.maxrows
/2))
2956 let calcfirst first active
=
2959 let rows = active
- first in
2960 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2964 let scrollph y maxy
=
2965 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
2966 let sh = float conf.winh
/. sh in
2967 let sh = max
sh (float conf.scrollh
) in
2972 else float y /. float maxy
2974 let position = (float conf.winh
-. sh) *. percent in
2977 if position +. sh > float conf.winh
2978 then float conf.winh
-. sh
2984 let coe s = (s :> uioh
);;
2986 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
2988 val m_pan
= source#getpan
2989 val m_first
= source#getfirst
2990 val m_active
= source#getactive
2991 val m_qsearch
= source#getqsearch
2992 val m_prev_uioh
= state.uioh
2994 method private elemunder
y =
2995 let n = y / (fstate.fontsize
+1) in
2996 if m_first
+ n < source#getitemcount
2998 if source#hasaction
(m_first
+ n)
2999 then Some
(m_first
+ n)
3006 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3007 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3008 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3009 GlDraw.color
(1., 1., 1.);
3010 Gl.enable `texture_2d
;
3011 let fs = fstate.fontsize
in
3013 let ww = fstate.wwidth
in
3014 let tabw = 30.0*.ww in
3015 let itemcount = source#getitemcount
in
3017 if (row - m_first
) * nfs > conf.winh
3020 if row >= 0 && row < itemcount
3022 let (s, level
) = source#getitem
row in
3023 let y = (row - m_first
) * nfs in
3024 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3027 Gl.disable `texture_2d
;
3028 GlDraw.polygon_mode `both `line
;
3029 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3030 GlDraw.rect (1., float (y + 1))
3031 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3032 GlDraw.polygon_mode `both `fill
;
3033 GlDraw.color
(1., 1., 1.);
3034 Gl.enable `texture_2d
;
3037 let drawtabularstring s =
3038 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3041 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3044 let len = String.length
s - tabpos - 1 in
3045 let s1 = String.sub
s 0 tabpos
3046 and s2
= String.sub
s (tabpos + 1) len in
3047 let nx = drawstr x s1 in
3049 let x = x +. (max
tabw sw) in
3056 let _ = drawtabularstring s in
3063 Gl.disable `texture_2d
;
3065 method updownlevel incr
=
3066 let len = source#getitemcount
in
3068 if m_active
>= 0 && m_active
< len
3069 then snd
(source#getitem m_active
)
3073 if i
= len then i
-1 else if i
= -1 then 0 else
3074 let _, l = source#getitem i
in
3075 if l != curlevel then i
else flow (i
+incr
)
3077 let active = flow m_active
in
3078 let first = calcfirst m_first
active in
3079 G.postRedisplay "outline updownlevel";
3080 {< m_active
= active; m_first
= first >}
3082 method private key1
key mask
=
3083 let set1 active first qsearch
=
3084 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3086 let search active pattern incr
=
3089 if n >= 0 && n < source#getitemcount
3091 let s, _ = source#getitem
n in
3093 (try ignore
(Str.search_forward
re s 0); true
3094 with Not_found
-> false)
3096 else loop (n + incr
)
3103 let re = Str.regexp_case_fold pattern
in
3109 let itemcount = source#getitemcount
in
3110 let find start incr
=
3112 if i
= -1 || i
= itemcount
3115 if source#hasaction i
3117 else find (i
+ incr
)
3122 let set active first =
3123 let first = bound first 0 (itemcount - fstate.maxrows
) in
3125 coe {< m_active
= active; m_first
= first >}
3128 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3130 let incr1 = if incr
> 0 then 1 else -1 in
3131 if isvisible m_first m_active
3134 let next = m_active
+ incr
in
3136 if next < 0 || next >= itemcount
3138 else find next incr1
3140 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3146 let first = m_first
+ incr
in
3147 let first = bound first 0 (itemcount - 1) in
3149 let next = m_active
+ incr
in
3150 let next = bound next 0 (itemcount - 1) in
3153 let active = if next = -1 then m_active
else next in
3156 let first = min
next m_first
in
3158 if abs
(next - first) > fstate.maxrows
3164 let first = m_first
+ incr
in
3165 let first = bound first 0 (itemcount - 1) in
3167 let next = m_active
+ incr
in
3168 let next = bound next 0 (itemcount - 1) in
3169 let next = find next incr1 in
3171 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3173 let active = if m_active
= -1 then next else m_active
in
3178 if isvisible first active
3184 G.postRedisplay "listview navigate";
3188 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3189 let incr = if key = 0x72 then -1 else 1 in
3191 match search (m_active
+ incr) m_qsearch
incr with
3193 state.text <- m_qsearch ^
" [not found]";
3196 state.text <- m_qsearch
;
3197 active, firstof m_first
active
3199 G.postRedisplay "listview ctrl-r/s";
3200 set1 active first m_qsearch
;
3202 | 0xff08 -> (* backspace *)
3203 if String.length m_qsearch
= 0
3206 let qsearch = withoutlastutf8 m_qsearch
in
3207 let len = String.length
qsearch in
3211 G.postRedisplay "listview empty qsearch";
3212 set1 m_active m_first
"";
3216 match search m_active
qsearch ~
-1 with
3218 state.text <- qsearch ^
" [not found]";
3221 state.text <- qsearch;
3222 active, firstof m_first
active
3224 G.postRedisplay "listview backspace qsearch";
3225 set1 active first qsearch
3228 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3229 let pattern = m_qsearch ^
Wsi.toutf8
key in
3231 match search m_active
pattern 1 with
3233 state.text <- pattern ^
" [not found]";
3236 state.text <- pattern;
3237 active, firstof m_first
active
3239 G.postRedisplay "listview qsearch add";
3240 set1 active first pattern;
3242 | 0xff1b -> (* escape *)
3244 if String.length m_qsearch
= 0
3246 G.postRedisplay "list view escape";
3249 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3251 | None
-> m_prev_uioh
3256 G.postRedisplay "list view kill qsearch";
3257 source#setqsearch
"";
3258 coe {< m_qsearch
= "" >}
3261 | 0xff0d -> (* return *)
3263 let self = {< m_qsearch
= "" >} in
3264 source#setqsearch
"";
3266 G.postRedisplay "listview enter";
3267 if m_active
>= 0 && m_active
< source#getitemcount
3269 source#exit
(coe self) false m_active m_first m_pan
"";
3272 source#exit
(coe self) true m_active m_first m_pan
"";
3275 begin match opt with
3276 | None
-> m_prev_uioh
3280 | 0xff9f | 0xffff -> (* delete *)
3283 | 0xff52 -> navigate ~
-1 (* up *)
3284 | 0xff54 -> navigate 1 (* down *)
3285 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3286 | 0xff56 -> navigate fstate.maxrows
(* next *)
3288 | 0xff53 -> (* right *)
3290 G.postRedisplay "listview right";
3291 coe {< m_pan
= m_pan
- 1 >}
3293 | 0xff51 -> (* left *)
3295 G.postRedisplay "listview left";
3296 coe {< m_pan
= m_pan
+ 1 >}
3298 | 0xff50 -> (* home *)
3299 let active = find 0 1 in
3300 G.postRedisplay "listview home";
3303 | 0xff57 -> (* end *)
3304 let first = max
0 (itemcount - fstate.maxrows
) in
3305 let active = find (itemcount - 1) ~
-1 in
3306 G.postRedisplay "listview end";
3309 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3313 dolog "listview unknown key %#x" key; coe self
3315 method key key mask
=
3316 match state.mode
with
3317 | Textentry te
-> textentrykeyboard key mask te
; coe self
3318 | _ -> self#key1
key mask
3320 method button button down
x y _ =
3323 | 1 when x > conf.winw
- conf.scrollbw
->
3324 G.postRedisplay "listview scroll";
3327 let _, position, sh = self#
scrollph in
3328 if y > truncate
position && y < truncate
(position +. sh)
3330 state.mstate
<- Mscrolly
;
3334 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3335 let first = truncate
(s *. float source#getitemcount
) in
3336 let first = min source#getitemcount
first in
3337 Some
(coe {< m_first
= first; m_active
= first >})
3339 state.mstate
<- Mnone
;
3342 | 1 when not down
->
3343 begin match self#elemunder
y with
3345 G.postRedisplay "listview click";
3347 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3351 | n when (n == 4 || n == 5) && not down
->
3352 let len = source#getitemcount
in
3354 if n = 5 && m_first
+ fstate.maxrows
>= len
3358 let first = m_first
+ (if n == 4 then -1 else 1) in
3359 bound first 0 (len - 1)
3361 G.postRedisplay "listview wheel";
3362 Some
(coe {< m_first
= first >})
3363 | n when (n = 6 || n = 7) && not down
->
3364 let inc = m_first
+ (if n = 7 then -1 else 1) in
3365 G.postRedisplay "listview hwheel";
3366 Some
(coe {< m_pan
= m_pan
+ inc >})
3371 | None
-> m_prev_uioh
3375 match state.mstate
with
3377 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3378 let first = truncate
(s *. float source#getitemcount
) in
3379 let first = min source#getitemcount
first in
3380 G.postRedisplay "listview motion";
3381 coe {< m_first
= first; m_active
= first >}
3384 method pmotion
x y =
3385 if x < conf.winw
- conf.scrollbw
3388 match self#elemunder
y with
3389 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3390 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3394 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3399 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3403 method infochanged
_ = ()
3405 method scrollpw
= (0, 0.0, 0.0)
3407 let nfs = fstate.fontsize
+ 1 in
3408 let y = m_first
* nfs in
3409 let itemcount = source#getitemcount
in
3410 let maxi = max
0 (itemcount - fstate.maxrows
) in
3411 let maxy = maxi * nfs in
3412 let p, h = scrollph y maxy in
3415 method modehash
= modehash
3418 class outlinelistview ~source
=
3421 ~source
:(source
:> lvsource
)
3423 ~modehash
:(findkeyhash conf "outline")
3426 method key key mask
=
3427 let calcfirst first active =
3430 let rows = active - first in
3432 if String.length
state.text = 0
3434 else fstate.maxrows - 2
3436 if rows > maxrows then active - maxrows else first
3440 let active = m_active
+ incr in
3441 let active = bound active 0 (source#getitemcount
- 1) in
3442 let first = calcfirst m_first
active in
3443 G.postRedisplay "outline navigate";
3444 coe {< m_active
= active; m_first
= first >}
3446 let ctrl = Wsi.withctrl mask
in
3448 | 110 when ctrl -> (* ctrl-n *)
3449 source#narrow m_qsearch
;
3450 G.postRedisplay "outline ctrl-n";
3451 coe {< m_first
= 0; m_active
= 0 >}
3453 | 117 when ctrl -> (* ctrl-u *)
3455 G.postRedisplay "outline ctrl-u";
3457 coe {< m_first
= 0; m_active
= 0 >}
3459 | 108 when ctrl -> (* ctrl-l *)
3460 let first = m_active
- (fstate.maxrows / 2) in
3461 G.postRedisplay "outline ctrl-l";
3462 coe {< m_first
= first >}
3464 | 0xff9f | 0xffff -> (* delete *)
3465 source#remove m_active
;
3466 G.postRedisplay "outline delete";
3467 let active = max
0 (m_active
-1) in
3468 coe {< m_first
= firstof m_first
active;
3469 m_active
= active >}
3471 | 0xff52 -> navigate ~
-1 (* up *)
3472 | 0xff54 -> navigate 1 (* down *)
3473 | 0xff55 -> (* prior *)
3474 navigate ~
-(fstate.maxrows)
3475 | 0xff56 -> (* next *)
3476 navigate fstate.maxrows
3478 | 0xff53 -> (* [ctrl-]right *)
3482 G.postRedisplay "outline ctrl right";
3483 {< m_pan
= m_pan
+ 1 >}
3485 else self#updownlevel
1
3489 | 0xff51 -> (* [ctrl-]left *)
3493 G.postRedisplay "outline ctrl left";
3494 {< m_pan
= m_pan
- 1 >}
3496 else self#updownlevel ~
-1
3500 | 0xff50 -> (* home *)
3501 G.postRedisplay "outline home";
3502 coe {< m_first
= 0; m_active
= 0 >}
3504 | 0xff57 -> (* end *)
3505 let active = source#getitemcount
- 1 in
3506 let first = max
0 (active - fstate.maxrows) in
3507 G.postRedisplay "outline end";
3508 coe {< m_active
= active; m_first
= first >}
3510 | _ -> super#
key key mask
3513 let outlinesource usebookmarks
=
3516 inherit lvsourcebase
3517 val mutable m_items
= empty
3518 val mutable m_orig_items
= empty
3519 val mutable m_prev_items
= empty
3520 val mutable m_narrow_pattern
= ""
3521 val mutable m_hadremovals
= false
3523 method getitemcount
=
3524 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3527 if n == Array.length m_items
&& m_hadremovals
3529 ("[Confirm removal]", 0)
3531 let s, n, _ = m_items
.(n) in
3534 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3535 ignore
(uioh
, first, qsearch);
3536 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3538 if String.length m_narrow_pattern
= 0
3544 if not
confrimremoval
3546 let _, _, anchor = m_items
.(active) in
3551 state.bookmarks
<- Array.to_list m_items
;
3552 m_orig_items
<- m_items
;
3555 else m_items
<- items;
3559 method hasaction
_ = true
3562 if Array.length m_items
!= Array.length m_orig_items
3563 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3566 method narrow
pattern =
3567 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3571 let rec loop accu n =
3574 m_narrow_pattern
<- pattern;
3575 m_items
<- Array.of_list
accu
3578 let (s, _, _) as o = m_items
.(n) in
3580 if (try ignore
(Str.search_forward
re s 0); true
3581 with Not_found
-> false)
3587 loop [] (Array.length m_items
- 1)
3592 then Array.of_list
state.bookmarks
3595 m_items
<- m_orig_items
3600 if m >= 0 && m < Array.length m_items
3602 m_hadremovals
<- true;
3603 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3604 let n = if n >= m then n+1 else n in
3609 method reset
anchor items =
3610 m_hadremovals
<- false;
3611 if m_orig_items
== empty || m_prev_items
!= items
3613 m_orig_items
<- items;
3614 if String.length m_narrow_pattern
= 0
3615 then m_items
<- items;
3617 m_prev_items
<- items;
3618 let rely = getanchory anchor in
3620 let rec loop n best bestd
=
3621 if n = Array.length m_items
3624 let (_, _, anchor) = m_items
.(n) in
3625 let orely = getanchory anchor in
3626 let d = abs
(orely - rely) in
3629 else loop (n+1) best bestd
3634 m_first
<- firstof m_first
active
3638 let enterselector usebookmarks
=
3639 let source = outlinesource usebookmarks
in
3643 then Array.of_list
state.bookmarks
3646 if Array.length
outlines = 0
3648 showtext ' ' errmsg
;
3651 state.text <- source#greetmsg
;
3652 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3653 let anchor = getanchor () in
3654 source#reset
anchor outlines;
3655 state.uioh
<- coe (new outlinelistview ~
source);
3656 G.postRedisplay "enter selector";
3660 let enteroutlinemode =
3661 let f = enterselector false in
3662 fun ()-> f "Document has no outline";
3665 let enterbookmarkmode =
3666 let f = enterselector true in
3667 fun () -> f "Document has no bookmarks (yet)";
3670 let color_of_string s =
3671 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3672 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3676 let color_to_string (r
, g
, b) =
3677 let r = truncate
(r *. 256.0)
3678 and g
= truncate
(g
*. 256.0)
3679 and b = truncate
(b *. 256.0) in
3680 Printf.sprintf
"%d/%d/%d" r g
b
3683 let irect_of_string s =
3684 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3687 let irect_to_string (x0,y0,x1,y1) =
3688 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3691 let makecheckers () =
3692 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3694 converted by Issac Trotts. July 25, 2002 *)
3695 let image_height = 64
3696 and image_width
= 64 in
3700 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3702 for i
= 0 to image_width
- 1 do
3703 for j
= 0 to image_height - 1 do
3704 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3705 (if (i
land 8 ) lxor (j
land 8) = 0
3706 then [|255;255;255|] else [|200;200;200|])
3711 let image = make_image () in
3712 let id = GlTex.gen_texture
() in
3713 GlTex.bind_texture `texture_2d
id;
3714 GlPix.store
(`unpack_alignment
1);
3715 GlTex.image2d
image;
3716 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3719 `mag_filter `nearest
;
3720 `min_filter `nearest
];
3724 let setcheckers enabled
=
3725 match state.texid
with
3727 if enabled
then state.texid
<- Some
(makecheckers ())
3732 GlTex.delete_texture texid
;
3733 state.texid
<- None
;
3737 let int_of_string_with_suffix s =
3738 let l = String.length
s in
3742 let suffix = Char.lowercase
s.[l-1] in
3744 | 'k'
-> String.sub
s 0 (l-1), 10
3745 | '
m'
-> String.sub
s 0 (l-1), 20
3746 | 'g'
-> String.sub
s 0 (l-1), 30
3750 let n = int_of_string
s1 in
3751 let m = n lsl shift
in
3753 then raise
(Failure
"value too large")
3757 let string_with_suffix_of_int n =
3762 if n land ((1 lsl 20) - 1) = 0
3765 if n land ((1 lsl 10) - 1) = 0
3771 let h = n mod 1000 in
3774 then string_of_int
h ^
s
3776 let s = Printf.sprintf
"_%03d%s" h s in
3783 let defghyllscroll = (40, 8, 32);;
3784 let ghyllscroll_of_string s =
3785 let (n, a, b) as nab
=
3788 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3790 if n <= a || n <= b || a >= b
3791 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3795 let ghyllscroll_to_string ((n, a, b) as nab
) =
3796 if nab
= defghyllscroll
3798 else Printf.sprintf
"%d,%d,%d" n a b;
3801 let describe_location () =
3803 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3805 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3806 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3810 else (100. *. (float state.y /. float maxy))
3814 Printf.sprintf
"page %d of %d [%.2f%%]"
3815 (fn+1) state.pagecount
percent
3818 "pages %d-%d of %d [%.2f%%]"
3819 (fn+1) (ln
+1) state.pagecount
percent
3823 let btos b = if b then "\xe2\x88\x9a" else "" in
3824 let showextended = ref false in
3825 let leave mode
= function
3826 | Confirm
-> state.mode
<- mode
3827 | Cancel
-> state.mode
<- mode
in
3830 val mutable m_first_time
= true
3831 val mutable m_l
= []
3832 val mutable m_a
= [||]
3833 val mutable m_prev_uioh
= nouioh
3834 val mutable m_prev_mode
= View
3836 inherit lvsourcebase
3838 method reset prev_mode prev_uioh
=
3839 m_a
<- Array.of_list
(List.rev m_l
);
3841 m_prev_mode
<- prev_mode
;
3842 m_prev_uioh
<- prev_uioh
;
3846 if n >= Array.length m_a
3850 | _, _, _, Action
_ -> m_active
<- n
3854 m_first_time
<- false;
3857 method int name get
set =
3859 (name
, `
int get
, 1, Action
(
3862 try set (int_of_string
s)
3864 state.text <- Printf.sprintf
"bad integer `%s': %s"
3865 s (Printexc.to_string exn
)
3868 let te = name ^
": ", "", None
, intentry, ondone, true in
3869 state.mode
<- Textentry
(te, leave m_prev_mode
);
3873 method int_with_suffix name get
set =
3875 (name
, `intws get
, 1, Action
(
3878 try set (int_of_string_with_suffix s)
3880 state.text <- Printf.sprintf
"bad integer `%s': %s"
3881 s (Printexc.to_string exn
)
3885 name ^
": ", "", None
, intentry_with_suffix, ondone, true
3887 state.mode
<- Textentry
(te, leave m_prev_mode
);
3891 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3893 (name
, `
bool (btos, get
), offset
, Action
(
3900 method color name get
set =
3902 (name
, `color get
, 1, Action
(
3904 let invalid = (nan
, nan
, nan
) in
3907 try color_of_string s
3909 state.text <- Printf.sprintf
"bad color `%s': %s"
3910 s (Printexc.to_string exn
);
3916 let te = name ^
": ", "", None
, textentry, ondone, true in
3917 state.text <- color_to_string (get
());
3918 state.mode
<- Textentry
(te, leave m_prev_mode
);
3922 method string name get
set =
3924 (name
, `
string get
, 1, Action
(
3926 let ondone s = set s in
3927 let te = name ^
": ", "", None
, textentry, ondone, true in
3928 state.mode
<- Textentry
(te, leave m_prev_mode
);
3932 method colorspace name get
set =
3934 (name
, `
string get
, 1, Action
(
3937 let vals = [| "rgb"; "bgr"; "gray" |] in
3939 inherit lvsourcebase
3942 m_active
<- int_of_colorspace conf.colorspace
;
3945 method getitemcount
= Array.length
vals
3946 method getitem
n = (vals.(n), 0)
3947 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3948 ignore
(uioh
, first, pan
, qsearch);
3949 if not cancel
then set active;
3951 method hasaction
_ = true
3955 let modehash = findkeyhash conf "info" in
3956 coe (new listview ~
source ~trusted
:true ~
modehash)
3959 method caption
s offset
=
3960 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3962 method caption2
s f offset
=
3963 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3965 method getitemcount
= Array.length m_a
3968 let tostr = function
3969 | `
int f -> string_of_int
(f ())
3970 | `intws
f -> string_with_suffix_of_int (f ())
3972 | `color
f -> color_to_string (f ())
3973 | `
bool (btos, f) -> btos (f ())
3976 let name, t
, offset
, _ = m_a
.(n) in
3977 ((let s = tostr t
in
3978 if String.length
s > 0
3979 then Printf.sprintf
"%s\t%s" name s
3983 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3987 m_qsearch
<- qsearch;
3989 match m_a
.(active) with
3990 | _, _, _, Action
f -> f uioh
4002 method hasaction
n =
4004 | _, _, _, Action
_ -> true
4008 let rec fillsrc prevmode prevuioh
=
4009 let sep () = src#caption
"" 0 in
4010 let colorp name get
set =
4012 (fun () -> color_to_string (get
()))
4015 let c = color_of_string v in
4018 state.text <- Printf.sprintf
"bad color `%s': %s"
4019 v (Printexc.to_string exn
);
4022 let oldmode = state.mode
in
4023 let birdseye = isbirdseye state.mode
in
4025 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4027 src#
bool "presentation mode"
4028 (fun () -> conf.presentation)
4030 conf.presentation <- v;
4031 state.anchor <- getanchor ();
4034 src#
bool "ignore case in searches"
4035 (fun () -> conf.icase
)
4036 (fun v -> conf.icase
<- v);
4039 (fun () -> conf.preload)
4040 (fun v -> conf.preload <- v);
4042 src#
bool "highlight links"
4043 (fun () -> conf.hlinks
)
4044 (fun v -> conf.hlinks
<- v);
4046 src#
bool "under info"
4047 (fun () -> conf.underinfo
)
4048 (fun v -> conf.underinfo
<- v);
4050 src#
bool "persistent bookmarks"
4051 (fun () -> conf.savebmarks
)
4052 (fun v -> conf.savebmarks
<- v);
4054 src#
bool "proportional display"
4055 (fun () -> conf.proportional
)
4056 (fun v -> reqlayout conf.angle
v);
4058 src#
bool "trim margins"
4059 (fun () -> conf.trimmargins
)
4060 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4062 src#
bool "persistent location"
4063 (fun () -> conf.jumpback
)
4064 (fun v -> conf.jumpback
<- v);
4067 src#
int "inter-page space"
4068 (fun () -> conf.interpagespace)
4070 conf.interpagespace <- n;
4071 docolumns conf.columns
;
4073 match state.layout with
4078 state.maxy <- calcheight ();
4079 let y = getpagey pageno in
4084 (fun () -> conf.pagebias
)
4085 (fun v -> conf.pagebias
<- v);
4087 src#
int "scroll step"
4088 (fun () -> conf.scrollstep
)
4089 (fun n -> conf.scrollstep
<- n);
4091 src#
int "horizontal scroll step"
4092 (fun () -> conf.hscrollstep
)
4093 (fun v -> conf.hscrollstep
<- v);
4095 src#
int "auto scroll step"
4097 match state.autoscroll
with
4099 | _ -> conf.autoscrollstep
)
4101 if state.autoscroll
<> None
4102 then state.autoscroll
<- Some
n;
4103 conf.autoscrollstep
<- n);
4106 (fun () -> truncate
(conf.zoom *. 100.))
4107 (fun v -> setzoom ((float v) /. 100.));
4110 (fun () -> conf.angle
)
4111 (fun v -> reqlayout v conf.proportional
);
4113 src#
int "scroll bar width"
4114 (fun () -> state.scrollw
)
4118 reshape conf.winw
conf.winh
;
4121 src#
int "scroll handle height"
4122 (fun () -> conf.scrollh
)
4123 (fun v -> conf.scrollh
<- v;);
4125 src#
int "thumbnail width"
4126 (fun () -> conf.thumbw
)
4128 conf.thumbw
<- min
4096 v;
4131 leavebirdseye beye
false;
4136 let mode = state.mode in
4137 src#
string "columns"
4139 match conf.columns
with
4141 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4142 | Csplit
(count
, _) -> "-" ^ string_of_int count
4145 let n, a, b = multicolumns_of_string v in
4146 setcolumns mode n a b);
4149 src#caption
"Presentation mode" 0;
4150 src#
bool "scrollbar visible"
4151 (fun () -> conf.scrollbarinpm
)
4153 if v != conf.scrollbarinpm
4155 conf.scrollbarinpm
<- v;
4156 if conf.presentation
4158 state.scrollw
<- if v then conf.scrollbw
else 0;
4159 reshape conf.winw
conf.winh
;
4165 src#caption
"Pixmap cache" 0;
4166 src#int_with_suffix
"size (advisory)"
4167 (fun () -> conf.memlimit
)
4168 (fun v -> conf.memlimit
<- v);
4171 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4172 (string_with_suffix_of_int state.memused
)
4173 (Hashtbl.length
state.tilemap
)) 1;
4176 src#caption
"Layout" 0;
4177 src#caption2
"Dimension"
4179 Printf.sprintf
"%dx%d (virtual %dx%d) [pos %d]"
4181 state.w state.maxy state.y)
4185 src#caption2
"Position" (fun () ->
4186 Printf.sprintf
"%dx%d" state.x state.y
4189 src#caption2
"Visible" (fun () -> describe_location ()) 1
4193 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4194 "Save these parameters as global defaults at exit"
4195 (fun () -> conf.bedefault
)
4196 (fun v -> conf.bedefault
<- v)
4200 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4201 src#
bool ~offset
:0 ~
btos "Extended parameters"
4202 (fun () -> !showextended)
4203 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4207 (fun () -> conf.checkers
)
4208 (fun v -> conf.checkers
<- v; setcheckers v);
4209 src#
bool "update cursor"
4210 (fun () -> conf.updatecurs
)
4211 (fun v -> conf.updatecurs
<- v);
4213 (fun () -> conf.verbose
)
4214 (fun v -> conf.verbose
<- v);
4215 src#
bool "invert colors"
4216 (fun () -> conf.invert
)
4217 (fun v -> conf.invert
<- v);
4219 (fun () -> conf.maxhfit
)
4220 (fun v -> conf.maxhfit
<- v);
4221 src#
bool "redirect stderr"
4222 (fun () -> conf.redirectstderr)
4223 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4224 src#
string "uri launcher"
4225 (fun () -> conf.urilauncher
)
4226 (fun v -> conf.urilauncher
<- v);
4227 src#
string "path launcher"
4228 (fun () -> conf.pathlauncher
)
4229 (fun v -> conf.pathlauncher
<- v);
4230 src#
string "tile size"
4231 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4234 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4235 conf.tilew
<- max
64 w;
4236 conf.tileh
<- max
64 h;
4239 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4240 v (Printexc.to_string exn
));
4241 src#
int "texture count"
4242 (fun () -> conf.texcount
)
4245 then conf.texcount
<- v
4246 else showtext '
!'
" Failed to set texture count please retry later"
4248 src#
int "slice height"
4249 (fun () -> conf.sliceheight
)
4251 conf.sliceheight
<- v;
4252 wcmd "sliceh %d" conf.sliceheight
;
4254 src#
int "anti-aliasing level"
4255 (fun () -> conf.aalevel
)
4257 conf.aalevel
<- bound v 0 8;
4258 state.anchor <- getanchor ();
4259 opendoc state.path
state.password
;
4261 src#
string "page scroll scaling factor"
4262 (fun () -> string_of_float
conf.pgscale)
4265 let s = float_of_string
v in
4268 state.text <- Printf.sprintf
4269 "bad page scroll scaling factor `%s': %s"
4270 v (Printexc.to_string exn
)
4273 src#
int "ui font size"
4274 (fun () -> fstate.fontsize
)
4275 (fun v -> setfontsize (bound v 5 100));
4276 src#
int "hint font size"
4277 (fun () -> conf.hfsize
)
4278 (fun v -> conf.hfsize
<- bound v 5 100);
4279 colorp "background color"
4280 (fun () -> conf.bgcolor
)
4281 (fun v -> conf.bgcolor
<- v);
4282 src#
bool "crop hack"
4283 (fun () -> conf.crophack
)
4284 (fun v -> conf.crophack
<- v);
4285 src#
string "trim fuzz"
4286 (fun () -> irect_to_string conf.trimfuzz
)
4289 conf.trimfuzz
<- irect_of_string v;
4291 then settrim true conf.trimfuzz
;
4293 state.text <- Printf.sprintf
"bad irect `%s': %s"
4294 v (Printexc.to_string exn
)
4296 src#
string "throttle"
4298 match conf.maxwait
with
4299 | None
-> "show place holder if page is not ready"
4302 then "wait for page to fully render"
4304 "wait " ^ string_of_float
time
4305 ^
" seconds before showing placeholder"
4309 let f = float_of_string
v in
4311 then conf.maxwait
<- None
4312 else conf.maxwait
<- Some
f
4314 state.text <- Printf.sprintf
"bad time `%s': %s"
4315 v (Printexc.to_string exn
)
4317 src#
string "ghyll scroll"
4319 match conf.ghyllscroll
with
4321 | Some nab
-> ghyllscroll_to_string nab
4326 if String.length
v = 0
4328 else Some
(ghyllscroll_of_string v)
4330 conf.ghyllscroll
<- gs
4332 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4333 v (Printexc.to_string exn
)
4335 src#
string "selection command"
4336 (fun () -> conf.selcmd
)
4337 (fun v -> conf.selcmd
<- v);
4338 src#colorspace
"color space"
4339 (fun () -> colorspace_to_string conf.colorspace
)
4341 conf.colorspace
<- colorspace_of_int v;
4348 src#caption
"Document" 0;
4349 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4350 src#caption2
"Pages"
4351 (fun () -> string_of_int
state.pagecount
) 1;
4352 src#caption2
"Dimensions"
4353 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4357 src#caption
"Trimmed margins" 0;
4358 src#caption2
"Dimensions"
4359 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4363 src#caption
"OpenGL" 0;
4364 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4365 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4366 src#reset prevmode prevuioh
;
4370 let prevmode = state.mode
4371 and prevuioh
= state.uioh in
4372 fillsrc prevmode prevuioh
;
4373 let source = (src :> lvsource
) in
4374 let modehash = findkeyhash conf "info" in
4375 state.uioh <- coe (object (self)
4376 inherit listview ~
source ~trusted
:true ~
modehash as super
4377 val mutable m_prevmemused
= 0
4378 method infochanged
= function
4380 if m_prevmemused
!= state.memused
4382 m_prevmemused
<- state.memused
;
4383 G.postRedisplay "memusedchanged";
4385 | Pdim
-> G.postRedisplay "pdimchanged"
4386 | Docinfo
-> fillsrc prevmode prevuioh
4388 method key key mask
=
4389 if not
(Wsi.withctrl mask
)
4392 | 0xff51 -> coe (self#updownlevel ~
-1)
4393 | 0xff53 -> coe (self#updownlevel
1)
4394 | _ -> super#
key key mask
4395 else super#
key key mask
4397 G.postRedisplay "info";
4403 inherit lvsourcebase
4404 method getitemcount
= Array.length
state.help
4406 let s, n, _ = state.help
.(n) in
4409 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4413 m_qsearch
<- qsearch;
4414 match state.help
.(active) with
4415 | _, _, Action
f -> Some
(f uioh)
4425 method hasaction
n =
4426 match state.help
.(n) with
4427 | _, _, Action
_ -> true
4434 let modehash = findkeyhash conf "help" in
4435 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4436 G.postRedisplay "help";
4441 let re = Str.regexp
"[\r\n]" in
4443 inherit lvsourcebase
4444 val mutable m_items
= [||]
4446 method getitemcount
= 1 + Array.length m_items
4451 else m_items
.(n-1), 0
4453 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4458 then Buffer.clear
state.errmsgs
;
4459 m_qsearch
<- qsearch;
4466 method hasaction
n =
4470 state.newerrmsgs
<- false;
4471 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4472 m_items
<- Array.of_list
l
4480 let source = (msgsource :> lvsource
) in
4481 let modehash = findkeyhash conf "listview" in
4482 state.uioh <- coe (object
4483 inherit listview ~
source ~trusted
:false ~
modehash as super
4486 then msgsource#reset
;
4489 G.postRedisplay "msgs";
4492 let quickbookmark ?title
() =
4493 match state.layout with
4499 let sec = Unix.gettimeofday
() in
4500 let tm = Unix.localtime
sec in
4501 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4505 (tm.Unix.tm_year
+ 1900)
4508 | Some
title -> title
4511 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4516 state.fullscreen
<- None
;
4520 let setautoscrollspeed step goingdown
=
4521 let incr = max
1 ((abs step
) / 2) in
4522 let incr = if goingdown
then incr else -incr in
4523 let astep = step
+ incr in
4524 state.autoscroll
<- Some
astep;
4527 let gotounder = function
4528 | Ulinkgoto
(pageno, top) ->
4532 gotopage1 pageno top;
4538 | Uremote
(filename
, pageno) ->
4540 if Sys.file_exists filename
4543 let dir = Filename.dirname
state.path in
4544 let path = Filename.concat
dir filename
in
4545 if Sys.file_exists
path
4549 if String.length
path > 0
4551 let anchor = getanchor () in
4552 let ranchor = state.path, state.password
, anchor in
4553 state.anchor <- (pageno, 0.0);
4554 state.ranchors
<- ranchor :: state.ranchors
;
4557 else showtext '
!'
("Could not find " ^ filename
)
4559 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4563 match conf.columns
with
4565 | _ -> conf.zoom > 1.0
4568 let viewkeyboard key mask
=
4570 let mode = state.mode in
4571 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4574 G.postRedisplay "view:enttext"
4576 let ctrl = Wsi.withctrl mask
in
4581 | 0xff63 -> (* insert *)
4582 if conf.angle
mod 360 = 0
4584 state.mode <- LinkNav
(Ltgendir
0);
4587 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4589 | 0xff1b | 113 -> (* escape / q *)
4590 begin match state.mstate
with
4592 state.mstate
<- Mnone
;
4593 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4594 G.postRedisplay "kill zoom rect";
4596 match state.ranchors
with
4598 | (path, password
, anchor) :: rest
->
4599 state.ranchors
<- rest
;
4600 state.anchor <- anchor;
4601 opendoc path password
4604 | 0xff08 -> (* backspace *)
4605 let y = getnav ~
-1 in
4606 gotoy_and_clear_text y
4614 G.postRedisplay "dehighlight";
4616 | 47 | 63 -> (* / ? *)
4617 let ondone isforw
s =
4618 cbput state.hists
.pat
s;
4619 state.searchpattern
<- s;
4622 let s = String.create
1 in
4623 s.[0] <- Char.chr
key;
4624 enttext (s, "", Some
(onhist state.hists
.pat
),
4625 textentry, ondone (key = 47), true)
4627 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-=*)
4628 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4629 setzoom (conf.zoom +. incr)
4631 | 43 | 0xffab -> (* + *)
4634 try int_of_string
s with exc
->
4635 state.text <- Printf.sprintf
"bad integer `%s': %s"
4636 s (Printexc.to_string exc
);
4642 state.text <- "page bias is now " ^ string_of_int
n;
4645 enttext ("page bias: ", "", None
, intentry, ondone, true)
4647 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4648 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4649 setzoom (max
0.01 (conf.zoom -. decr))
4651 | 45 | 0xffad -> (* - *)
4652 let ondone msg
= state.text <- msg
in
4654 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4655 optentry state.mode, ondone, true
4658 | 48 when ctrl -> (* ctrl-0 *)
4661 | 49 when ctrl -> (* ctrl-1 *)
4663 match conf.columns
with
4664 | Csingle
_ | Cmulti
_ -> 1
4665 | Csplit
(n, _) -> n
4667 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4671 | 0xffc6 -> (* f9 *)
4674 | 57 when ctrl -> (* ctrl-9 *)
4677 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4678 when not
ctrl -> (* 0..9 *)
4681 try int_of_string
s with exc
->
4682 state.text <- Printf.sprintf
"bad integer `%s': %s"
4683 s (Printexc.to_string exc
);
4689 cbput state.hists
.pag
(string_of_int
n);
4690 gotopage1 (n + conf.pagebias
- 1) 0;
4693 let pageentry text key =
4694 match Char.unsafe_chr
key with
4695 | 'g'
-> TEdone
text
4696 | _ -> intentry text key
4698 let text = "x" in text.[0] <- Char.chr
key;
4699 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4702 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4703 reshape conf.winw
conf.winh
;
4706 conf.hlinks
<- not
conf.hlinks
;
4707 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4708 G.postRedisplay "toggle highlightlinks";
4711 state.glinks
<- true;
4712 let mode = state.mode in
4713 state.mode <- Textentry
(
4714 (":", "", None
, linknentry, linkndone (fun under ->
4719 state.glinks
<- false;
4723 G.postRedisplay "view:linkent(F)"
4726 state.glinks
<- true;
4727 let mode = state.mode in
4728 state.mode <- Textentry
(
4729 (":", "", None
, linknentry, linkndone (fun under ->
4730 match Ne.pipe () with
4732 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4733 (Printexc.to_string exn
));
4736 try popen conf.selcmd
[r, 0; w, -1]; true
4739 (Printf.sprintf
"failed to execute %s: %s"
4740 conf.selcmd
(Printexc.to_string exn
));
4744 Ne.clo fd
(fun msg
->
4745 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4748 let s = undertext under in
4752 let l = String.length
s in
4753 let n = Unix.write
w s 0 l in
4758 "failed to write %d characters to sel pipe, wrote %d"
4763 (Printf.sprintf
"failed to write to sel pipe: %s"
4764 (Printexc.to_string exn
)
4773 state.glinks
<- false;
4777 G.postRedisplay "view:linkent"
4780 begin match state.autoscroll
with
4782 conf.autoscrollstep
<- step
;
4783 state.autoscroll
<- None
4785 if conf.autoscrollstep
= 0
4786 then state.autoscroll
<- Some
1
4787 else state.autoscroll
<- Some
conf.autoscrollstep
4790 | 112 when ctrl -> (* ctrl-p *)
4794 conf.presentation <- not
conf.presentation;
4795 if conf.presentation
4797 if not
conf.scrollbarinpm
4798 then state.scrollw
<- 0;
4801 state.scrollw
<- conf.scrollbw
;
4803 showtext ' '
("presentation mode " ^
4804 if conf.presentation then "on" else "off");
4805 state.anchor <- getanchor ();
4809 begin match state.fullscreen
with
4811 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4814 state.fullscreen
<- None
;
4819 gotoy_and_clear_text 0
4822 gotopage1 (state.pagecount
- 1) 0
4824 | 112 | 78 -> (* p|N *)
4825 search state.searchpattern
false
4827 | 110 | 0xffc0 -> (* n|F3 *)
4828 search state.searchpattern
true
4831 begin match state.layout with
4834 gotoy_and_clear_text (getpagey l.pageno)
4838 begin match state.layout with
4841 match conf.columns
with
4842 | Csingle
_ | Cmulti
_ ->
4843 if conf.presentation && rest
== [] && l.pageh
> l.pagey + l.pagevh
4845 let y = clamp (pgscale conf.winh
) in
4846 gotoy_and_clear_text y
4848 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4849 gotoy_and_clear_text (getpagey pageno)
4851 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4853 let pagey, pageh
= getpageyh l.pageno in
4854 let pagey = pagey + pageh
* l.pagecol
in
4855 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace in
4856 gotoy_and_clear_text (pagey + pageh
+ ips)
4859 | 0xff9f | 0xffff -> (* delete *)
4860 begin match state.layout with
4863 match conf.columns
with
4864 | Csingle
_ | Cmulti
_ ->
4865 if conf.presentation && (l.pagey != 0 || l.pagedispy < 0)
4867 gotoy_and_clear_text (clamp (pgscale ~
-(conf.winh
)))
4869 let pageno = max
0 (l.pageno-1) in
4870 gotoy_and_clear_text (getpagey pageno)
4878 let pageno = max
0 (l.pageno-1) in
4879 let pagey, pageh
= getpageyh pageno in
4882 let pagey, pageh
= getpageyh l.pageno in
4883 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4885 gotoy_and_clear_text y
4889 showtext ' '
(describe_location ());
4892 begin match state.layout with
4895 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4900 enterbookmarkmode ()
4902 | 104 | 0xffbe -> (* h|F1 *)
4908 | 101 when conf.redirectstderr -> (* e *)
4913 match state.layout with
4916 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4920 enttext ("bookmark: ", "", None
, textentry, ondone, true)
4924 showtext ' '
"Quick bookmark added";
4927 begin match state.layout with
4929 let rect = getpdimrect
l.pagedimno
in
4933 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4934 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4936 (truncate
(rect.(1) -. rect.(0)),
4937 truncate
(rect.(3) -. rect.(0)))
4939 let w = truncate
((float w)*.conf.zoom)
4940 and h = truncate
((float h)*.conf.zoom) in
4943 state.anchor <- getanchor ();
4944 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4946 G.postRedisplay "z";
4951 | 50 when ctrl -> (* ctrl-2 *)
4952 let maxw = getmaxw
() in
4954 then setzoom (maxw /. float conf.winw
)
4956 | 60 | 62 -> (* < > *)
4957 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4959 | 91 | 93 -> (* [ ] *)
4961 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4963 G.postRedisplay "brightness";
4965 | 99 when state.mode = View
-> (* c *)
4967 match state.prevcolumns
with
4968 | None
-> (1, 0, 0), 1.0
4969 | Some
(columns
, z
) ->
4972 | Csplit
(c, _) -> -c, 0, 0
4973 | Cmulti
((c, a, b), _) -> c, a, b
4974 | Csingle
_ -> 1, 0, 0
4978 setcolumns View
c a b;
4981 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4982 setzoom state.prevzoom
4984 | 107 | 0xff52 -> (* k up *)
4985 begin match state.autoscroll
with
4987 begin match state.mode with
4988 | Birdseye beye
-> upbirdseye 1 beye
4991 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4992 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4995 setautoscrollspeed n false
4998 | 106 | 0xff54 -> (* j down *)
4999 begin match state.autoscroll
with
5001 begin match state.mode with
5002 | Birdseye beye
-> downbirdseye 1 beye
5005 then gotoy_and_clear_text (clamp (conf.winh
/2))
5006 else gotoy_and_clear_text (clamp conf.scrollstep
)
5009 setautoscrollspeed n true
5012 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5020 let dx = if key = 0xff51 then dx else -dx in
5021 state.x <- state.x + dx;
5022 gotoy_and_clear_text state.y
5025 G.postRedisplay "lef/right"
5028 | 0xff55 -> (* prior *)
5032 match state.layout with
5034 | l :: _ -> state.y - l.pagey
5036 clamp (pgscale (-conf.winh
))
5040 | 0xff56 -> (* next *)
5044 match List.rev
state.layout with
5046 | l :: _ -> getpagey l.pageno
5048 clamp (pgscale conf.winh
)
5052 | 0xff50 -> gotoghyll 0
5053 | 0xff57 -> gotoghyll (clamp state.maxy)
5054 | 0xff53 when Wsi.withalt mask
->
5055 gotoghyll (getnav ~
-1)
5056 | 0xff51 when Wsi.withalt mask
->
5057 gotoghyll (getnav 1)
5060 state.anchor <- getanchor ();
5061 opendoc state.path state.password
5063 | 118 when conf.debug
-> (* v *)
5066 match getopaque l.pageno with
5069 let x0, y0, x1, y1 = pagebbox opaque
in
5070 let a,b = float x0, float y0 in
5071 let c,d = float x1, float y0 in
5072 let e,f = float x1, float y1 in
5073 let h,j
= float x0, float y1 in
5074 let rect = (a,b,c,d,e,f,h,j
) in
5076 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5078 G.postRedisplay "v";
5081 vlog "huh? %s" (Wsi.keyname
key)
5084 let linknavkeyboard key mask
linknav =
5085 let getpage pageno =
5086 let rec loop = function
5088 | l :: _ when l.pageno = pageno -> Some
l
5089 | _ :: rest
-> loop rest
5090 in loop state.layout
5092 let doexact (pageno, n) =
5093 match getopaque pageno, getpage pageno with
5094 | Some opaque
, Some
l ->
5097 let under = getlink opaque
n in
5098 G.postRedisplay "link gotounder";
5104 | 0xff50 -> (* home *)
5105 Some
(findlink opaque LDfirst
), -1
5107 | 0xff57 -> (* end *)
5108 Some
(findlink opaque LDlast
), 1
5110 | 0xff51 -> (* left *)
5111 Some
(findlink opaque
(LDleft
n)), -1
5113 | 0xff53 -> (* right *)
5114 Some
(findlink opaque
(LDright
n)), 1
5116 | 0xff52 -> (* up *)
5117 Some
(findlink opaque
(LDup
n)), -1
5119 | 0xff54 -> (* down *)
5120 Some
(findlink opaque
(LDdown
n)), 1
5125 begin match findpwl
l.pageno dir with
5129 state.mode <- LinkNav
(Ltgendir
dir);
5130 let y, h = getpageyh pageno in
5133 then y + h - conf.winh
5138 begin match getopaque pageno, getpage pageno with
5139 | Some opaque
, Some
_ ->
5141 let ld = if dir > 0 then LDfirst
else LDlast
in
5144 begin match link with
5146 showlinktype (getlink opaque
m);
5147 state.mode <- LinkNav
(Ltexact
(pageno, m));
5148 G.postRedisplay "linknav jpage";
5155 begin match opt with
5156 | Some Lnotfound
-> pwl l dir;
5157 | Some
(Lfound
m) ->
5161 let _, y0, _, y1 = getlinkrect opaque
m in
5163 then gotopage1 l.pageno y0
5165 let d = fstate.fontsize
+ 1 in
5166 if y1 - l.pagey > l.pagevh - d
5167 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5168 else G.postRedisplay "linknav";
5170 showlinktype (getlink opaque
m);
5171 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5174 | None
-> viewkeyboard key mask
5176 | _ -> viewkeyboard key mask
5181 G.postRedisplay "leave linknav"
5185 | Ltgendir
_ -> viewkeyboard key mask
5186 | Ltexact exact
-> doexact exact
5189 let keyboard key mask
=
5190 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5191 then wcmd "interrupt"
5192 else state.uioh <- state.uioh#
key key mask
5195 let birdseyekeyboard key mask
5196 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5198 match conf.columns
with
5200 | Cmulti
((c, _, _), _) -> c
5201 | Csplit
_ -> failwith
"bird's eye split mode"
5203 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5205 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5206 let y, h = getpageyh pageno in
5207 let top = (conf.winh
- h) / 2 in
5208 gotoy (max
0 (y - top))
5209 | 0xff0d -> leavebirdseye beye
false
5210 | 0xff1b -> leavebirdseye beye
true (* escape *)
5211 | 0xff52 -> upbirdseye incr beye
(* up *)
5212 | 0xff54 -> downbirdseye incr beye
(* down *)
5213 | 0xff51 -> upbirdseye 1 beye
(* left *)
5214 | 0xff53 -> downbirdseye 1 beye
(* right *)
5216 | 0xff55 -> (* prior *)
5217 begin match state.layout with
5221 state.mode <- Birdseye
(
5222 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5224 gotopage1 l.pageno 0;
5227 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5229 | [] -> gotoy (clamp (-conf.winh
))
5231 state.mode <- Birdseye
(
5232 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5234 gotopage1 l.pageno 0
5237 | [] -> gotoy (clamp (-conf.winh
))
5240 | 0xff56 -> (* next *)
5241 begin match List.rev
state.layout with
5243 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5244 begin match layout with
5246 let incr = l.pageh
- l.pagevh in
5251 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5253 G.postRedisplay "birdseye pagedown";
5255 else gotoy (clamp (incr + conf.interpagespace*2));
5259 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5260 gotopage1 l.pageno 0;
5263 | [] -> gotoy (clamp conf.winh
)
5266 | 0xff50 -> (* home *)
5267 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5270 | 0xff57 -> (* end *)
5271 let pageno = state.pagecount
- 1 in
5272 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5273 if not
(pagevisible state.layout pageno)
5276 match List.rev
state.pdims
with
5278 | (_, _, h, _) :: _ -> h
5280 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5281 else G.postRedisplay "birdseye end";
5282 | _ -> viewkeyboard key mask
5285 let drawpage l linkindexbase
=
5287 match state.mode with
5288 | Textentry
_ -> scalecolor 0.4
5290 | View
-> scalecolor 1.0
5291 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5292 if l.pageno = hooverpageno
5295 if l.pageno = pageno
5301 begin match getopaque l.pageno with
5303 if tileready l l.pagex
l.pagey
5305 let x = l.pagedispx - l.pagex
5306 and y = l.pagedispy - l.pagey in
5308 match conf.columns
with
5309 | Csingle
_ | Cmulti
_ ->
5310 (if conf.hlinks
then 1 else 0)
5312 && not
(isbirdseye state.mode) then 2 else 0)
5316 match state.mode with
5317 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5320 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5327 let scrollindicator () =
5328 let sbw, ph
, sh = state.uioh#
scrollph in
5329 let sbh, pw, sw = state.uioh#scrollpw
in
5331 GlDraw.color (0.64, 0.64, 0.64);
5333 (float (conf.winw
- sbw), 0.)
5334 (float conf.winw
, float conf.winh
)
5337 (0., float (conf.winh
- sbh))
5338 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5340 GlDraw.color (0.0, 0.0, 0.0);
5343 (float (conf.winw
- sbw), ph
)
5344 (float conf.winw
, ph
+. sh)
5347 (pw, float (conf.winh
- sbh))
5348 (pw +. sw, float conf.winh
)
5353 match state.mstate
with
5354 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5357 | Msel
((x0, y0), (x1, y1)) ->
5358 let rec loop = function
5360 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5361 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5362 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5363 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5365 match getopaque l.pageno with
5367 let x0, y0 = pagetranslatepoint l x0 y0 in
5368 let x1, y1 = pagetranslatepoint l x1 y1 in
5369 seltext opaque
(x0, y0, x1, y1);
5377 let showrects rects
=
5379 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5380 GlDraw.polygon_mode `both `fill
;
5381 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5383 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5385 if l.pageno = pageno
5387 let dx = float (l.pagedispx - l.pagex
) in
5388 let dy = float (l.pagedispy - l.pagey) in
5389 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5390 GlDraw.begins `quads
;
5392 GlDraw.vertex2
(x0+.dx, y0+.dy);
5393 GlDraw.vertex2
(x1+.dx, y1+.dy);
5394 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5395 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5406 GlClear.color (scalecolor2 conf.bgcolor
);
5407 GlClear.clear
[`
color];
5408 let rec loop linkindexbase
= function
5410 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5411 loop linkindexbase rest
5414 loop 0 state.layout;
5416 match state.mode with
5417 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5418 begin match getopaque pageno with
5420 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5427 | None
-> state.rects
5434 begin match state.mstate
with
5435 | Mzoomrect
((x0, y0), (x1, y1)) ->
5437 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5438 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5439 GlDraw.rect (float x0, float y0)
5440 (float x1, float y1);
5449 let zoomrect x y x1 y1 =
5452 and y0 = min
y y1 in
5453 gotoy (state.y + y0);
5454 state.anchor <- getanchor ();
5455 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5457 if state.w < conf.winw
- state.scrollw
5458 then (conf.winw
- state.scrollw
- state.w) / 2
5461 state.x <- (state.x + margin) - x0;
5463 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5464 state.mstate
<- Mnone
;
5468 let winw = conf.winw - state.scrollw
- 1 in
5469 let s = float x /. float winw in
5470 let destx = truncate
(float (state.w + winw) *. s) in
5471 state.x <- winw - destx;
5472 gotoy_and_clear_text state.y;
5473 state.mstate
<- Mscrollx
;
5477 let s = float y /. float conf.winh
in
5478 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5479 gotoy_and_clear_text desty;
5480 state.mstate
<- Mscrolly
;
5483 let viewmouse button down
x y mask
=
5485 | n when (n == 4 || n == 5) && not down
->
5486 if Wsi.withctrl mask
5488 match state.mstate
with
5489 | Mzoom
(oldn
, i
) ->
5497 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5499 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5501 let zoom = conf.zoom -. incr in
5503 state.mstate
<- Mzoom
(n, 0);
5505 state.mstate
<- Mzoom
(n, i
+1);
5507 else state.mstate
<- Mzoom
(n, 0)
5509 | _ -> state.mstate
<- Mzoom
(n, 0)
5512 match state.autoscroll
with
5513 | Some step
-> setautoscrollspeed step
(n=4)
5517 then -conf.scrollstep
5518 else conf.scrollstep
5520 let incr = incr * 2 in
5521 let y = clamp incr in
5522 gotoy_and_clear_text y
5525 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5526 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5527 gotoy_and_clear_text state.y
5529 | 1 when Wsi.withctrl mask
->
5532 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5533 state.mstate
<- Mpan
(x, y)
5536 state.mstate
<- Mnone
5541 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5543 state.mstate
<- Mzoomrect
(p, p)
5546 match state.mstate
with
5547 | Mzoomrect
((x0, y0), _) ->
5548 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5549 then zoomrect x0 y0 x y
5551 state.mstate
<- Mnone
;
5552 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5553 G.postRedisplay "kill accidental zoom rect";
5556 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5557 state.mstate
<- Mnone
5560 | 1 when x > conf.winw - state.scrollw
->
5563 let _, position, sh = state.uioh#
scrollph in
5564 if y > truncate
position && y < truncate
(position +. sh)
5565 then state.mstate
<- Mscrolly
5568 state.mstate
<- Mnone
5570 | 1 when y > conf.winh
- state.hscrollh ->
5573 let _, position, sw = state.uioh#scrollpw
in
5574 if x > truncate
position && x < truncate
(position +. sw)
5575 then state.mstate
<- Mscrollx
5578 state.mstate
<- Mnone
5581 let dest = if down
then getunder x y else Unone
in
5582 begin match dest with
5586 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5589 | Unone
when down
->
5590 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5591 state.mstate
<- Mpan
(x, y);
5593 | Unone
| Utext
_ ->
5596 if conf.angle
mod 360 = 0
5598 state.mstate
<- Msel
((x, y), (x, y));
5599 G.postRedisplay "mouse select";
5603 match state.mstate
with
5606 | Mzoom
_ | Mscrollx
| Mscrolly
->
5607 state.mstate
<- Mnone
5609 | Mzoomrect
((x0, y0), _) ->
5613 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5614 state.mstate
<- Mnone
5616 | Msel
((_, y0), (_, y1)) ->
5617 let rec loop = function
5620 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5621 || ((y1 >= l.pagedispy
5622 && y1 <= (l.pagedispy + l.pagevh)))
5624 match getopaque l.pageno with
5627 match Ne.pipe () with
5631 "can not create sel pipe: %s"
5632 (Printexc.to_string exn
));
5634 let doclose what fd
=
5635 Ne.clo fd
(fun msg
->
5636 dolog "%s close failed: %s" what msg
)
5639 popen conf.selcmd
[r, 0; w, -1];
5642 G.postRedisplay "copysel";
5644 dolog "can not execute %S: %s"
5645 conf.selcmd
(Printexc.to_string exn
);
5653 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5654 state.mstate
<- Mnone
;
5661 let birdseyemouse button down
x y mask
5662 (conf, leftx
, _, hooverpageno
, anchor) =
5665 let rec loop = function
5668 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5669 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5671 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5677 | _ -> viewmouse button down
x y mask
5680 let mouse button down
x y mask
=
5681 state.uioh <- state.uioh#button button down
x y mask
;
5685 state.uioh <- state.uioh#
motion x y
5689 state.uioh <- state.uioh#
pmotion x y;
5695 method key key mask
=
5696 begin match state.mode with
5697 | Textentry
textentry -> textentrykeyboard key mask
textentry
5698 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5699 | View
-> viewkeyboard key mask
5700 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5704 method button button bstate
x y mask
=
5705 begin match state.mode with
5707 | View
-> viewmouse button bstate
x y mask
5708 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5714 begin match state.mode with
5716 | View
| Birdseye
_ | LinkNav
_ ->
5717 match state.mstate
with
5718 | Mzoom
_ | Mnone
-> ()
5723 state.mstate
<- Mpan
(x, y);
5725 then state.x <- state.x + dx;
5727 gotoy_and_clear_text y
5730 state.mstate
<- Msel
(a, (x, y));
5731 G.postRedisplay "motion select";
5734 let y = min
conf.winh
(max
0 y) in
5738 let x = min
conf.winw (max
0 x) in
5741 | Mzoomrect
(p0
, _) ->
5742 state.mstate
<- Mzoomrect
(p0
, (x, y));
5743 G.postRedisplay "motion zoomrect";
5747 method pmotion x y =
5748 begin match state.mode with
5749 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5750 let rec loop = function
5752 if hooverpageno
!= -1
5754 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5755 G.postRedisplay "pmotion birdseye no hoover";
5758 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5759 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5761 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5762 G.postRedisplay "pmotion birdseye hoover";
5772 match state.mstate
with
5773 | Mnone
-> updateunder x y
5774 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5779 method infochanged
_ = ()
5782 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5783 let p, h = scrollph state.y maxy in
5787 let winw = conf.winw - state.scrollw
- 1 in
5788 let fwinw = float winw in
5790 let sw = fwinw /. float state.w in
5791 let sw = fwinw *. sw in
5792 max
sw (float conf.scrollh
)
5795 let f = state.w+winw in
5796 let r = float (winw-state.x) /. float f in
5797 let p = fwinw *. r in
5801 if position +. sw > fwinw
5802 then fwinw -. position
5805 state.hscrollh, position, sw
5809 match state.mode with
5810 | LinkNav
_ -> "links"
5811 | Textentry
_ -> "textentry"
5812 | Birdseye
_ -> "birdseye"
5815 findkeyhash conf modename
5822 let fontpath = ref "";;
5825 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5828 let l = String.length
s in
5829 let b = Buffer.create
l in
5835 try Sys.getenv
"HOME"
5838 ("Can not determine home directory location: " ^
5839 Printexc.to_string exn
);
5843 let modifier_of_string = function
5844 | "alt" -> Wsi.altmask
5845 | "shift" -> Wsi.shiftmask
5846 | "ctrl" | "control" -> Wsi.ctrlmask
5847 | "meta" -> Wsi.metamask
5852 let r = Str.regexp
"-" in
5854 let elems = Str.full_split
r s in
5857 let m1 = modifier_of_string s in
5859 then (Wsi.namekey
s, m)
5862 | Str.Delim
s when n land 1 = 0 -> g s
5864 | Str.Delim
_ -> (k
, m)
5866 let rec loop n k
m = function
5869 let k, m = f n k m x in
5875 let keys_of_string =
5876 let r = Str.regexp
"[ \t]" in
5878 let elems = Str.split
r s in
5879 List.map
key_of_string elems
5882 let copykeyhashes c =
5883 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5886 let config_of c attrs
=
5890 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5891 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5892 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5893 | "preload" -> { c with preload = bool_of_string
v }
5894 | "page-bias" -> { c with pagebias
= int_of_string
v }
5895 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5896 | "horizontal-scroll-step" ->
5897 { c with hscrollstep
= max
(int_of_string
v) 1 }
5898 | "auto-scroll-step" ->
5899 { c with autoscrollstep
= max
0 (int_of_string
v) }
5900 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5901 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5904 match String.lowercase
v with
5905 | "true" -> Some infinity
5907 | f -> Some
(float_of_string
f)
5909 { c with maxwait
= mw}
5910 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5911 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5912 | "vertical-margin" ->
5913 { c with interpagespace = max
0 (int_of_string
v) }
5915 let zoom = float_of_string
v /. 100. in
5916 let zoom = max
zoom 0.0 in
5917 { c with zoom = zoom }
5918 | "presentation" -> { c with presentation = bool_of_string
v }
5919 | "rotation-angle" -> { c with angle
= int_of_string
v }
5920 | "width" -> { c with winw = max
20 (int_of_string
v) }
5921 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5922 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5923 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5924 | "pixmap-cache-size" ->
5925 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5926 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5927 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5928 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5929 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5930 | "background-color" -> { c with bgcolor
= color_of_string v }
5931 | "scrollbar-in-presentation" ->
5932 { c with scrollbarinpm
= bool_of_string
v }
5933 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5934 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5935 | "mupdf-store-size" ->
5936 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5937 | "checkers" -> { c with checkers
= bool_of_string
v }
5938 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5939 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5940 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5941 | "uri-launcher" -> { c with urilauncher
= unent v }
5942 | "path-launcher" -> { c with pathlauncher
= unent v }
5943 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5944 | "invert-colors" -> { c with invert
= bool_of_string
v }
5945 | "brightness" -> { c with colorscale
= float_of_string
v }
5946 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5948 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5950 let (n, _, _) as nab
= multicolumns_of_string v in
5952 then { c with columns
= Csplit
(-n, [||]) }
5953 else { c with columns
= Cmulti
(nab
, [||]) }
5954 | "birds-eye-columns" ->
5955 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5956 | "selection-command" -> { c with selcmd
= unent v }
5957 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5958 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
5959 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
5962 prerr_endline
("Error processing attribute (`" ^
5963 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5966 let rec fold c = function
5969 let c = apply c k v in
5972 fold { c with keyhashes
= copykeyhashes c } attrs
;
5975 let fromstring f pos
n v d =
5978 dolog "Error processing attribute (%S=%S) at %d\n%s"
5979 n v pos
(Printexc.to_string exn
)
5984 let bookmark_of attrs
=
5985 let rec fold title page
rely = function
5986 | ("title", v) :: rest
-> fold v page
rely rest
5987 | ("page", v) :: rest
-> fold title v rely rest
5988 | ("rely", v) :: rest
-> fold title page
v rest
5989 | _ :: rest
-> fold title page
rely rest
5990 | [] -> title, page
, rely
5992 fold "invalid" "0" "0" attrs
5996 let rec fold path page
rely pan
= function
5997 | ("path", v) :: rest
-> fold v page
rely pan rest
5998 | ("page", v) :: rest
-> fold path v rely pan rest
5999 | ("rely", v) :: rest
-> fold path page
v pan rest
6000 | ("pan", v) :: rest
-> fold path page
rely v rest
6001 | _ :: rest
-> fold path page
rely pan rest
6002 | [] -> path, page
, rely, pan
6004 fold "" "0" "0" "0" attrs
6008 let rec fold rs ls
= function
6009 | ("out", v) :: rest
-> fold v ls rest
6010 | ("in", v) :: rest
-> fold rs
v rest
6011 | _ :: rest
-> fold ls rs rest
6017 let setconf dst
src =
6018 dst
.scrollbw
<- src.scrollbw
;
6019 dst
.scrollh
<- src.scrollh
;
6020 dst
.icase
<- src.icase
;
6021 dst
.preload <- src.preload;
6022 dst
.pagebias
<- src.pagebias
;
6023 dst
.verbose
<- src.verbose
;
6024 dst
.scrollstep
<- src.scrollstep
;
6025 dst
.maxhfit
<- src.maxhfit
;
6026 dst
.crophack
<- src.crophack
;
6027 dst
.autoscrollstep
<- src.autoscrollstep
;
6028 dst
.maxwait
<- src.maxwait
;
6029 dst
.hlinks
<- src.hlinks
;
6030 dst
.underinfo
<- src.underinfo
;
6031 dst
.interpagespace <- src.interpagespace;
6032 dst
.zoom <- src.zoom;
6033 dst
.presentation <- src.presentation;
6034 dst
.angle
<- src.angle
;
6035 dst
.winw <- src.winw;
6036 dst
.winh
<- src.winh
;
6037 dst
.savebmarks
<- src.savebmarks
;
6038 dst
.memlimit
<- src.memlimit
;
6039 dst
.proportional
<- src.proportional
;
6040 dst
.texcount
<- src.texcount
;
6041 dst
.sliceheight
<- src.sliceheight
;
6042 dst
.thumbw
<- src.thumbw
;
6043 dst
.jumpback
<- src.jumpback
;
6044 dst
.bgcolor
<- src.bgcolor
;
6045 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6046 dst
.tilew
<- src.tilew
;
6047 dst
.tileh
<- src.tileh
;
6048 dst
.mustoresize
<- src.mustoresize
;
6049 dst
.checkers
<- src.checkers
;
6050 dst
.aalevel
<- src.aalevel
;
6051 dst
.trimmargins
<- src.trimmargins
;
6052 dst
.trimfuzz
<- src.trimfuzz
;
6053 dst
.urilauncher
<- src.urilauncher
;
6054 dst
.colorspace
<- src.colorspace
;
6055 dst
.invert
<- src.invert
;
6056 dst
.colorscale
<- src.colorscale
;
6057 dst
.redirectstderr <- src.redirectstderr;
6058 dst
.ghyllscroll
<- src.ghyllscroll
;
6059 dst
.columns
<- src.columns
;
6060 dst
.beyecolumns
<- src.beyecolumns
;
6061 dst
.selcmd
<- src.selcmd
;
6062 dst
.updatecurs
<- src.updatecurs
;
6063 dst
.pathlauncher
<- src.pathlauncher
;
6064 dst
.keyhashes
<- copykeyhashes src;
6065 dst
.hfsize
<- src.hfsize
;
6066 dst
.hscrollstep
<- src.hscrollstep
;
6067 dst
.pgscale <- src.pgscale;
6071 let h = Hashtbl.create
10 in
6072 let dc = { defconf with angle
= defconf.angle
} in
6073 let rec toplevel v t spos
_ =
6075 | Vdata
| Vcdata
| Vend
-> v
6076 | Vopen
("llppconfig", _, closed
) ->
6079 else { v with f = llppconfig
}
6081 error
"unexpected subelement at top level" s spos
6082 | Vclose
_ -> error
"unexpected close at top level" s spos
6084 and llppconfig
v t spos
_ =
6086 | Vdata
| Vcdata
-> v
6087 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6088 | Vopen
("defaults", attrs
, closed
) ->
6089 let c = config_of dc attrs
in
6093 else { v with f = defaults
}
6095 | Vopen
("ui-font", attrs
, closed
) ->
6096 let rec getsize size
= function
6098 | ("size", v) :: rest
->
6100 fromstring int_of_string spos
"size" v fstate.fontsize
in
6102 | l -> getsize size l
6104 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6107 else { v with f = uifont
(Buffer.create
10) }
6109 | Vopen
("doc", attrs
, closed
) ->
6110 let pathent, spage
, srely
, span
= doc_of attrs
in
6111 let path = unent pathent
6112 and pageno = fromstring int_of_string spos
"page" spage
0
6113 and rely = fromstring float_of_string spos
"rely" srely
0.0
6114 and pan
= fromstring int_of_string spos
"pan" span
0 in
6115 let c = config_of dc attrs
in
6116 let anchor = (pageno, rely) in
6118 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6119 else { v with f = doc
path pan
anchor c [] }
6122 error
"unexpected subelement in llppconfig" s spos
6124 | Vclose
"llppconfig" -> { v with f = toplevel }
6125 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6127 and defaults
v t spos
_ =
6129 | Vdata
| Vcdata
-> v
6130 | Vend
-> error
"unexpected end of input in defaults" s spos
6131 | Vopen
("keymap", attrs
, closed
) ->
6133 try List.assoc
"mode" attrs
6134 with Not_found
-> "global" in
6139 let h = findkeyhash dc modename in
6140 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6143 { v with f = pkeymap
ret KeyMap.empty }
6145 | Vopen
(_, _, _) ->
6146 error
"unexpected subelement in defaults" s spos
6148 | Vclose
"defaults" ->
6149 { v with f = llppconfig
}
6151 | Vclose
_ -> error
"unexpected close in defaults" s spos
6153 and uifont
b v t spos
epos =
6156 Buffer.add_substring
b s spos
(epos - spos
);
6158 | Vopen
(_, _, _) ->
6159 error
"unexpected subelement in ui-font" s spos
6160 | Vclose
"ui-font" ->
6161 if String.length
!fontpath = 0
6162 then fontpath := Buffer.contents
b;
6163 { v with f = llppconfig
}
6164 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6165 | Vend
-> error
"unexpected end of input in ui-font" s spos
6167 and doc
path pan
anchor c bookmarks
v t spos
_ =
6169 | Vdata
| Vcdata
-> v
6170 | Vend
-> error
"unexpected end of input in doc" s spos
6171 | Vopen
("bookmarks", _, closed
) ->
6174 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6176 | Vopen
("keymap", attrs
, closed
) ->
6178 try List.assoc
"mode" attrs
6179 with Not_found
-> "global"
6185 let h = findkeyhash c modename in
6186 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6187 doc
path pan
anchor c bookmarks
6189 { v with f = pkeymap
ret KeyMap.empty }
6191 | Vopen
(_, _, _) ->
6192 error
"unexpected subelement in doc" s spos
6195 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6196 { v with f = llppconfig
}
6198 | Vclose
_ -> error
"unexpected close in doc" s spos
6200 and pkeymap
ret keymap
v t spos
_ =
6202 | Vdata
| Vcdata
-> v
6203 | Vend
-> error
"unexpected end of input in keymap" s spos
6204 | Vopen
("map", attrs
, closed
) ->
6205 let r, l = map_of attrs
in
6206 let kss = fromstring keys_of_string spos
"in" r [] in
6207 let lss = fromstring keys_of_string spos
"out" l [] in
6211 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6212 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6215 then { v with f = pkeymap
ret keymap }
6218 { v with f = skip
"map" f }
6221 error
"unexpected subelement in keymap" s spos
6223 | Vclose
"keymap" ->
6224 { v with f = ret keymap }
6226 | Vclose
_ -> error
"unexpected close in keymap" s spos
6228 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6230 | Vdata
| Vcdata
-> v
6231 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6232 | Vopen
("item", attrs
, closed
) ->
6233 let titleent, spage
, srely
= bookmark_of attrs
in
6234 let page = fromstring int_of_string spos
"page" spage
0
6235 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6236 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6238 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6241 { v with f = skip
"item" f }
6244 error
"unexpected subelement in bookmarks" s spos
6246 | Vclose
"bookmarks" ->
6247 { v with f = doc
path pan
anchor c bookmarks }
6249 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6251 and skip tag
f v t spos
_ =
6253 | Vdata
| Vcdata
-> v
6255 error
("unexpected end of input in skipped " ^ tag
) s spos
6256 | Vopen
(tag'
, _, closed
) ->
6260 let f'
() = { v with f = skip tag
f } in
6261 { v with f = skip tag'
f'
}
6265 else error
("unexpected close in skipped " ^ tag
) s spos
6268 parse
{ f = toplevel; accu = () } s;
6274 let len = in_channel_length ic
in
6275 let s = String.create
len in
6276 really_input ic
s 0 len;
6279 | Parse_error
(msg
, s, pos
) ->
6280 let subs = subs s pos
in
6281 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6282 failwith
("parse error: " ^
s)
6285 failwith
("config load error: " ^
Printexc.to_string exn
)
6291 let dir = Filename.concat
home ".config" in
6292 if Sys.is_directory
dir then dir else home
6295 Filename.concat
dir "llpp.conf"
6298 let confpath = ref defconfpath;;
6301 if Sys.file_exists
!confpath
6304 (try Some
(open_in_bin
!confpath)
6307 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6308 Printexc.to_string exn
);
6317 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6318 Printexc.to_string exn
);
6324 f (Hashtbl.create
0, defconf)
6329 let pc, pb
, px, pa
=
6331 Hashtbl.find h (Filename.basename
state.path)
6332 with Not_found
-> dc, [], 0, (0, 0.0)
6336 state.bookmarks <- pb
;
6338 state.scrollw
<- conf.scrollbw
;
6340 then state.anchor <- pa
;
6341 cbput state.hists
.nav pa
;
6346 let add_attrs bb always
dc c =
6349 then Printf.bprintf bb
"\n %s='%b'" s a
6352 then Printf.bprintf bb
"\n %s='%d'" s a
6355 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6358 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6361 then Printf.bprintf bb
"\n %s='%f'" s a
6365 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6369 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6373 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6377 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6383 | Some
(_N
, _A
, _B
) ->
6384 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6394 else string_of_float
f
6396 Printf.bprintf bb
"\n %s='%s'" s v
6401 | Cmulti
((n, a, b), _) when n > 1 ->
6402 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6403 | Csplit
(n, _) when n > 1 ->
6404 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6410 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6415 then dc.winw, dc.winh
6417 match state.fullscreen
with
6419 | None
-> c.winw, c.winh
6421 oi
"width" w dc.winw;
6422 oi
"height" h dc.winh
;
6423 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6424 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6425 ob "case-insensitive-search" c.icase
dc.icase
;
6426 ob "preload" c.preload dc.preload;
6427 oi
"page-bias" c.pagebias
dc.pagebias
;
6428 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6429 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6430 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6431 ob "crop-hack" c.crophack
dc.crophack
;
6432 oW
"throttle" c.maxwait
dc.maxwait
;
6433 ob "highlight-links" c.hlinks
dc.hlinks
;
6434 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6435 oi
"vertical-margin" c.interpagespace dc.interpagespace;
6436 oz
"zoom" c.zoom dc.zoom;
6437 ob "presentation" c.presentation dc.presentation;
6438 oi
"rotation-angle" c.angle
dc.angle
;
6439 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6440 ob "proportional-display" c.proportional
dc.proportional
;
6441 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6442 oi
"tex-count" c.texcount
dc.texcount
;
6443 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6444 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6445 ob "persistent-location" c.jumpback
dc.jumpback
;
6446 oc
"background-color" c.bgcolor
dc.bgcolor
;
6447 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6448 oi
"tile-width" c.tilew
dc.tilew
;
6449 oi
"tile-height" c.tileh
dc.tileh
;
6450 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6451 ob "checkers" c.checkers
dc.checkers
;
6452 oi
"aalevel" c.aalevel
dc.aalevel
;
6453 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6454 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6455 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6456 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6457 oC
"color-space" c.colorspace
dc.colorspace
;
6458 ob "invert-colors" c.invert
dc.invert
;
6459 oF
"brightness" c.colorscale
dc.colorscale
;
6460 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6461 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6462 oco
"columns" c.columns
dc.columns
;
6463 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6464 os
"selection-command" c.selcmd
dc.selcmd
;
6465 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6466 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6467 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6468 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6471 let keymapsbuf always
dc c =
6472 let bb = Buffer.create
16 in
6473 let rec loop = function
6475 | (modename, h) :: rest
->
6476 let dh = findkeyhash dc modename in
6477 if always
|| h <> dh
6479 if Hashtbl.length
h > 0
6481 if Buffer.length
bb > 0
6482 then Buffer.add_char
bb '
\n'
;
6483 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6484 Hashtbl.iter
(fun i
o ->
6485 let isdifferent = always
||
6487 let dO = Hashtbl.find dh i
in
6489 with Not_found
-> true
6494 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6495 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6496 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6497 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6498 Buffer.add_string
bb (Wsi.keyname
k);
6501 let rec loop = function
6503 | km
:: [] -> addkm km
6504 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6508 Buffer.add_string
bb "<map in='";
6512 Buffer.add_string
bb "' out='";
6514 Buffer.add_string
bb "'/>\n"
6517 Buffer.add_string
bb "' out='";
6519 Buffer.add_string
bb "'/>\n"
6521 | KMmulti
(ins, kms
) ->
6522 Buffer.add_char
bb ' '
;
6524 Buffer.add_string
bb "' out='";
6526 Buffer.add_string
bb "'/>\n"
6528 Buffer.add_string
bb "</keymap>";
6538 let uifontsize = fstate.fontsize
in
6539 let bb = Buffer.create
32768 in
6541 let dc = if conf.bedefault
then conf else dc in
6542 Buffer.add_string
bb "<llppconfig>\n";
6544 if String.length
!fontpath > 0
6546 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6552 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6555 Buffer.add_string
bb "<defaults ";
6556 add_attrs bb true dc dc;
6557 let kb = keymapsbuf true dc dc in
6558 if Buffer.length
kb > 0
6560 Buffer.add_string
bb ">\n";
6561 Buffer.add_buffer
bb kb;
6562 Buffer.add_string
bb "\n</defaults>\n";
6564 else Buffer.add_string
bb "/>\n";
6566 let adddoc path pan
anchor c bookmarks =
6567 if bookmarks == [] && c = dc && anchor = emptyanchor
6570 Printf.bprintf
bb "<doc path='%s'"
6571 (enent
path 0 (String.length
path));
6573 if anchor <> emptyanchor
6575 let n, y = anchor in
6576 Printf.bprintf
bb " page='%d'" n;
6579 Printf.bprintf
bb " rely='%f'" y
6584 then Printf.bprintf
bb " pan='%d'" pan
;
6586 add_attrs bb false dc c;
6587 let kb = keymapsbuf false dc c in
6589 begin match bookmarks with
6591 if Buffer.length
kb > 0
6593 Buffer.add_string
bb ">\n";
6594 Buffer.add_buffer
bb kb;
6595 Buffer.add_string
bb "\n</doc>\n";
6597 else Buffer.add_string
bb "/>\n"
6599 Buffer.add_string
bb ">\n<bookmarks>\n";
6600 List.iter
(fun (title, _level
, (page, rely)) ->
6602 "<item title='%s' page='%d'"
6603 (enent
title 0 (String.length
title))
6608 Printf.bprintf
bb " rely='%f'" rely
6610 Buffer.add_string
bb "/>\n";
6612 Buffer.add_string
bb "</bookmarks>";
6613 if Buffer.length
kb > 0
6615 Buffer.add_string
bb "\n";
6616 Buffer.add_buffer
bb kb;
6618 Buffer.add_string
bb "\n</doc>\n";
6624 match state.mode with
6625 | Birdseye
(c, pan, _, _, _) ->
6627 match conf.columns
with
6628 | Cmulti
((c, _, _), _) -> Some
c
6632 match c.columns
with
6633 | Cmulti
(c, _) -> Cmulti
(c, [||])
6634 | Csingle
_ -> Csingle
[||]
6635 | Csplit
_ -> failwith
"quit from bird's eye while split"
6637 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6638 | _ -> state.x, conf
6640 let basename = Filename.basename state.path in
6641 adddoc basename pan (getanchor ())
6643 let autoscrollstep =
6644 match state.autoscroll
with
6646 | None
-> conf.autoscrollstep
6648 match state.mode with
6649 | Birdseye
(bc
, _, _, _, _) ->
6652 presentation = bc
.presentation;
6653 interpagespace = bc
.interpagespace;
6654 maxwait
= bc
.maxwait
;
6655 autoscrollstep = autoscrollstep }
6656 | _ -> { conf with autoscrollstep = autoscrollstep }
6658 (if conf.savebmarks
then state.bookmarks else []);
6660 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6662 then adddoc path x y c bookmarks
6664 Buffer.add_string
bb "</llppconfig>";
6667 if Buffer.length
bb > 0
6670 let tmp = !confpath ^
".tmp" in
6671 let oc = open_out_bin
tmp in
6672 Buffer.output_buffer
oc bb;
6674 Unix.rename
tmp !confpath;
6677 ("error while saving configuration: " ^
Printexc.to_string exn
)
6682 let trimcachepath = ref "" in
6685 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6686 "<password> Set password");
6688 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6689 "<path> Set path to the user interface font");
6691 ("-c", Arg.String
(fun s -> Config.confpath := s),
6692 "<path> Set path to the configuration file");
6694 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6695 "<path> Set path to the trim cache file");
6697 ("-v", Arg.Unit
(fun () ->
6699 "%s\nconfiguration path: %s\n"
6703 exit
0), " Print version and exit");
6706 (fun s -> state.path <- s)
6707 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6709 if String.length
state.path = 0
6710 then (prerr_endline
"file name missing"; exit
1);
6714 let globalkeyhash = findkeyhash conf "global" in
6715 let wsfd, winw, winh
= Wsi.init
(object
6717 if nogeomcmds state.geomcmds
|| platform == Posx
6720 GlClear.color (scalecolor2 conf.bgcolor
);
6721 GlClear.clear
[`
color];
6723 method display = display ()
6724 method reshape w h = reshape w h
6725 method mouse b d x y m = mouse b d x y m
6726 method motion x y = state.mpos
<- (x, y); motion x y
6727 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6729 let mascm = m land (
6730 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6732 match state.keystate
with
6734 let km = k, mascm in
6737 let modehash = state.uioh#
modehash in
6738 try Hashtbl.find modehash km
6740 try Hashtbl.find globalkeyhash km
6741 with Not_found
-> KMinsrt
(k, m)
6743 | KMinsrt
(k, m) -> keyboard k m
6744 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6745 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6747 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6748 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6749 state.keystate
<- KSnone
6750 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6751 state.keystate
<- KSinto
(keys
, insrt
)
6753 state.keystate
<- KSnone
6755 method enter
x y = state.mpos
<- (x, y); pmotion x y
6756 method leave = state.mpos
<- (-1, -1)
6757 method quit
= raise Quit
6758 end) conf.winw conf.winh
(platform = Posx
) in
6763 List.exists
GlMisc.check_extension
6764 [ "GL_ARB_texture_rectangle"
6765 ; "GL_EXT_texture_recangle"
6766 ; "GL_NV_texture_rectangle" ]
6768 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6771 match Ne.pipe () with
6773 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6777 match Ne.pipe () with
6779 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6789 setcheckers conf.checkers
;
6793 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6794 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6795 !Config.fontpath, !trimcachepath
6799 state.text <- "Opening " ^
state.path;
6801 opendoc state.path state.password
;
6804 let rec loop deadline
=
6806 match state.errfd
with
6807 | None
-> [state.sr
; state.wsfd]
6808 | Some fd
-> [state.sr
; state.wsfd; fd
]
6812 state.redisplay
<- false;
6819 if deadline
= infinity
6821 else max
0.0 (deadline
-. now)
6826 try Unix.select
r [] [] timeout
6827 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6833 if state.ghyll
== noghyll
6835 match state.autoscroll
with
6836 | Some step
when step
!= 0 ->
6837 let y = state.y + step
in
6841 else if y >= state.maxy then 0 else y
6844 if state.mode = View
6845 then state.text <- "";
6848 else deadline
+. 0.01
6853 let rec checkfds = function
6855 | fd
:: rest
when fd
= state.sr
->
6856 let cmd = readcmd state.sr
in
6860 | fd
:: rest
when fd
= state.wsfd ->
6865 let s = String.create
80 in
6866 let n = Unix.read fd
s 0 80 in
6867 if conf.redirectstderr
6869 Buffer.add_substring
state.errmsgs
s 0 n;
6870 state.newerrmsgs
<- true;
6871 state.redisplay
<- true;
6874 prerr_string
(String.sub
s 0 n);
6882 if deadline
= infinity
6886 match state.autoscroll
with
6887 | Some step
when step
!= 0 -> deadline1
6888 | _ -> if state.ghyll
== noghyll then infinity
else deadline1