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 layout1 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
1107 let pagey = max
0 (y - vy
) in
1108 let pagedispy = if pagey > 0 then 0 else vy
- y in
1109 let pagedispx, pagex
=
1110 let pdx = dx + xoff
+ state.x in
1116 let vw = conf.winw
- state.scrollw
- pagedispx in
1117 let pw = w
- pagex
in
1120 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1121 if pagevw > 0 && pagevh > 0
1125 ; pagedimno
= pdimno
1132 ; pagedispx = pagedispx
1133 ; pagedispy = pagedispy
1145 List.rev
(fold [] 0)
1148 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1149 let sh = sh - state.hscrollh
in
1150 let rec fold accu n =
1151 if n = Array.length
b
1154 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n) in
1157 || n = state.pagecount
- coverB
1158 || (n - coverA
) mod columns
= columns
- 1)
1164 let pagey = max
0 (y - vy
) in
1165 let pagedispy = if pagey > 0 then 0 else vy
- y in
1166 let pagedispx, pagex
=
1168 if n = coverA
- 1 || n = state.pagecount
- coverB
1169 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1170 else dx + xoff
+ state.x
1177 let vw = conf.winw
- state.scrollw
- pagedispx in
1178 let pw = w
- pagex
in
1181 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1182 if pagevw > 0 && pagevh > 0
1186 ; pagedimno
= pdimno
1193 ; pagedispx = pagedispx
1194 ; pagedispy = pagedispy
1206 List.rev
(fold [] 0)
1209 let layoutS (columns
, b) y sh =
1210 let sh = sh - state.hscrollh
in
1211 let rec fold accu n =
1212 if n = Array.length
b
1215 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n) in
1222 let x = xoff
+ state.x in
1223 let pagey = max
0 (y - vy
) in
1224 let pagedispy = if pagey > 0 then 0 else vy
- y in
1225 let pagedispx, pagex
=
1239 let pagecolw = pagew
/columns
in
1241 if pagecolw < conf.winw
1242 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1246 let vw = conf.winw
- pagedispx - state.scrollw
in
1247 let pw = pagew
- pagex
in
1250 let pagevw = min
pagevw pagecolw in
1251 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1252 if pagevw > 0 && pagevh > 0
1255 { pageno = n/columns
1256 ; pagedimno
= pdimno
1263 ; pagedispx = pagedispx
1264 ; pagedispy = pagedispy
1265 ; pagecol
= n mod columns
1276 List.rev
(fold [] 0)
1280 if nogeomcmds state.geomcmds
1282 match conf.columns
with
1283 | Csingle
b -> layout1 b y sh
1284 | Cmulti
c -> layoutN c y sh
1285 | Csplit
s -> layoutS s y sh
1290 let y = state.y + incr
in
1292 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1297 let tilex = l
.pagex
mod conf.tilew
in
1298 let tiley = l
.pagey mod conf.tileh
in
1300 let col = l
.pagex
/ conf.tilew
in
1301 let row = l
.pagey / conf.tileh
in
1303 let rec rowloop row y0 dispy h
=
1307 let dh = conf.tileh
- y0 in
1308 let dh = min h
dh in
1309 let rec colloop col x0 dispx w
=
1313 let dw = conf.tilew
- x0 in
1314 let dw = min w
dw in
1316 f col row dispx dispy
x0 y0 dw dh;
1317 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1320 colloop col tilex l
.pagedispx l
.pagevw;
1321 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1324 if l
.pagevw > 0 && l
.pagevh > 0
1325 then rowloop row tiley l
.pagedispy l
.pagevh;
1328 let gettileopaque l
col row =
1330 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1332 try Some
(Hashtbl.find
state.tilemap
key)
1333 with Not_found
-> None
1336 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1337 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1338 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1341 let drawtiles l color
=
1343 let f col row x y tilex tiley w h
=
1344 match gettileopaque l
col row with
1345 | Some
(opaque
, _
, t
) ->
1346 let params = x, y, w
, h
, tilex, tiley in
1350 GlFunc.blend_func `zero `one_minus_src_color
;
1352 drawtile
params opaque
;
1354 then Gl.disable `blend
;
1357 let s = Printf.sprintf
1361 let w = measurestr
fstate.fontsize
s in
1362 GlMisc.push_attrib
[`current
];
1363 GlDraw.color
(0.0, 0.0, 0.0);
1365 (float (x-2), float (y-2))
1366 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1367 GlDraw.color
(1.0, 1.0, 1.0);
1368 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1369 GlMisc.pop_attrib
();
1374 let lw = conf.winw
- state.scrollw
- x in
1377 let lh = conf.winh
- y in
1380 begin match state.texid
with
1382 Gl.enable `texture_2d
;
1383 GlTex.bind_texture `texture_2d id
;
1386 and x1 = float (x+w)
1387 and y1 = float (y+h
) in
1389 let tw = float w /. 64.0
1390 and th
= float h
/. 64.0 in
1391 let tx0 = float tilex /. 64.0
1392 and ty0
= float tiley /. 64.0 in
1394 and ty1
= ty0
+. th
in
1395 GlDraw.begins `quads
;
1396 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1397 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1398 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1399 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1402 Gl.disable `texture_2d
;
1404 GlDraw.color
(1.0, 1.0, 1.0);
1407 (float (x+w), float (y+h
));
1409 if w > 128 && h
> fstate.fontsize
+ 10
1411 GlDraw.color
(0.0, 0.0, 0.0);
1414 then (col*conf.tilew
, row*conf.tileh
)
1417 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r
;
1424 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1426 let tilevisible1 l
x y =
1428 and ax1
= l
.pagex
+ l
.pagevw
1430 and ay1
= l
.pagey + l
.pagevh in
1434 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1435 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1437 let rx0 = max
ax0 bx0
1438 and ry0
= max ay0 by0
1439 and rx1
= min ax1
bx1
1440 and ry1
= min ay1 by1
in
1442 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1443 nonemptyintersection
1446 let tilevisible layout n x y =
1447 let rec findpageinlayout m
= function
1448 | l
:: rest
when l
.pageno = n ->
1449 tilevisible1 l
x y || (
1450 match conf.columns
with
1451 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1454 | _
:: rest
-> findpageinlayout 0 rest
1457 findpageinlayout 0 layout;
1460 let tileready l
x y =
1461 tilevisible1 l
x y &&
1462 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1465 let tilepage n p
layout =
1466 let rec loop = function
1470 let f col row _ _ _ _ _ _
=
1471 if state.currently
= Idle
1473 match gettileopaque l
col row with
1476 let x = col*conf.tilew
1477 and y = row*conf.tileh
in
1479 let w = l
.pagew
- x in
1483 let h = l
.pageh
- y in
1486 wcmd "tile %s %d %d %d %d" p
x y w h;
1489 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1490 conf.tilew
, conf.tileh
1499 if nogeomcmds state.geomcmds
1503 let preloadlayout visiblepages
=
1504 let presentation = conf.presentation in
1505 let interpagespace = conf.interpagespace in
1506 conf.presentation <- false;
1507 conf.interpagespace <- 0;
1509 match visiblepages
with
1510 | [] -> if state.y >= state.maxy
then state.maxy
else 0
1511 | l
:: _
-> getpagey l
.pageno + (l
.pagey - min
0 l
.pagedispy)
1513 let y = if y < conf.winh
then 0 else y - conf.winh
in
1514 let h = conf.winh
*3 in
1515 let pages = layout y h in
1516 conf.presentation <- presentation;
1517 conf.interpagespace <- interpagespace;
1522 let rec loop pages =
1523 if state.currently
!= Idle
1528 begin match getopaque l
.pageno with
1530 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1531 state.currently
<- Loading
(l
, state.gen
);
1533 tilepage l
.pageno opaque
pages;
1538 if nogeomcmds state.geomcmds
1544 if conf.preload && state.currently
= Idle
1545 then load (preloadlayout pages);
1548 let layoutready layout =
1549 let rec fold all ls
=
1550 all
&& match ls
with
1552 let seen = ref false in
1553 let allvisible = ref true in
1554 let foo col row _ _ _ _ _ _
=
1556 allvisible := !allvisible &&
1557 begin match gettileopaque l
col row with
1563 fold (!seen && !allvisible) rest
1566 let alltilesvisible = fold true layout in
1571 let y = bound y 0 state.maxy
in
1572 let y, layout, proceed
=
1573 match conf.maxwait
with
1574 | Some time
when state.ghyll
== noghyll ->
1575 begin match state.throttle
with
1577 let layout = layout y conf.winh
in
1578 let ready = layoutready layout in
1582 state.throttle
<- Some
(layout, y, now ());
1584 else G.postRedisplay "gotoy showall (None)";
1586 | Some
(_
, _
, started
) ->
1587 let dt = now () -. started
in
1590 state.throttle
<- None
;
1591 let layout = layout y conf.winh
in
1593 G.postRedisplay "maxwait";
1600 let layout = layout y conf.winh
in
1601 if true || layoutready layout
1602 then G.postRedisplay "gotoy ready";
1608 state.layout <- layout;
1609 begin match state.mode
with
1610 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1611 let rec loop = function
1613 state.mode
<- LinkNav
(Ltgendir
0)
1614 | l
:: _
when l
.pageno = pageno ->
1615 begin match getopaque pageno with
1617 state.mode
<- LinkNav
(Ltgendir
0)
1619 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1620 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1621 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1622 then state.mode
<- LinkNav
(Ltgendir
0)
1624 | _
:: rest
-> loop rest
1629 begin match state.mode
with
1630 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1631 if not
(pagevisible layout pageno)
1633 match state.layout with
1636 state.mode
<- Birdseye
(
1637 conf, leftx
, l
.pageno, hooverpageno
, anchor
1640 | LinkNav
(Ltgendir dir
as lt
) ->
1642 let rec loop = function
1645 match getopaque l
.pageno with
1651 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1653 if dir
> 0 then LDfirst
else LDlast
1659 | Lnotfound
-> loop rest
1661 showlinktype (getlink opaque
n);
1662 Ltexact
(l
.pageno, n)
1666 state.mode
<- LinkNav
linknav
1671 state.ghyll
<- noghyll;
1674 let mx, my
= state.mpos
in
1679 let conttiling pageno opaque
=
1680 tilepage pageno opaque
1681 (if conf.preload then preloadlayout state.layout else state.layout)
1684 let gotoy_and_clear_text y =
1685 if not
conf.verbose
then state.text <- "";
1690 match state.layout with
1693 let coloff = l
.pagecol
* l
.pageh
in
1695 (float (l
.pagey - l
.pagedispy) +. float coloff) /. float l
.pageh
)
1698 let getanchory (n, top
) =
1699 let y, h = getpageyh n in
1700 y + (truncate
(top
*. float h));
1703 let gotoanchor anchor
=
1704 gotoy (getanchory anchor
);
1708 cbput state.hists
.nav
(getanchor ());
1712 let anchor = cbgetc state.hists
.nav dir
in
1717 let scroll f n a
b =
1718 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1720 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1722 then s (float f /. float a
)
1725 then 1.0 -. s ((float (f-b) /. float (n-b)))
1732 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1733 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1735 let ins = float a
*. iv1
1736 and outs
= float (n-b) *. iv1 in
1738 ins +. outs
+. float ones
1740 let rec set (_N
, _A
, _B
) y sy
=
1741 let sum = summa
1.0 _N _A _B
in
1742 let dy = float (y - sy
) in
1746 then state.ghyll
<- noghyll
1749 let s = scroll n _N _A _B
in
1750 let y1 = y1 +. ((s *. dy) /. sum) in
1751 gotoy_and_clear_text (truncate
y1);
1752 state.ghyll
<- gf (n+1) y1;
1756 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1758 gf 0 (float state.y)
1761 match conf.ghyllscroll
with
1763 gotoy_and_clear_text y
1765 if state.ghyll
== noghyll
1766 then set nab
y state.y
1767 else state.ghyll
(Some
y)
1770 let gotopage n top
=
1771 let y, h = getpageyh n in
1772 let y = y + (truncate
(top
*. float h)) in
1776 let gotopage1 n top
=
1777 let y = getpagey n in
1782 let invalidate s f =
1787 match state.geomcmds
with
1788 | ps
, [] when String.length ps
= 0 ->
1790 state.geomcmds
<- s, [];
1793 state.geomcmds
<- ps
, [s, f];
1795 | ps
, (s'
, _
) :: rest
when s'
= s ->
1796 state.geomcmds
<- ps
, ((s, f) :: rest
);
1799 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1802 let opendoc path password
=
1804 state.password
<- password
;
1805 state.gen
<- state.gen
+ 1;
1806 state.docinfo
<- [];
1808 setaalevel
conf.aalevel
;
1809 Wsi.settitle
("llpp " ^
Filename.basename path
);
1810 wcmd "open %s\000%s\000" path password
;
1811 invalidate "reqlayout"
1813 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1817 let c = c *. conf.colorscale
in
1821 let scalecolor2 (r
, g
, b) =
1822 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1825 let docolumns = function
1827 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1828 let rec loop pageno pdimno pdim
y ph pdims
=
1829 if pageno = state.pagecount
1832 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1834 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno ->
1835 pdimno+1, pdim
, rest
1839 let x = (conf.winw
- state.scrollw
- w) / 2 - xoff
in
1841 (if conf.presentation
1842 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1843 else (if pageno = 0 then 0 else calcips h)
1846 a.(pageno) <- (pdimno, x, y, pdim
);
1847 loop (pageno+1) pdimno pdim
(y + h) h pdims
1849 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1850 conf.columns
<- Csingle
a;
1852 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1853 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1854 let rec loop pageno pdimno pdim
x y rowh pdims
=
1855 let rec fixrow m
= if m
= pageno then () else
1856 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1859 let y = y + (rowh
- h) / 2 in
1860 a.(m
) <- (pdimno, x, y, pdim
);
1864 if pageno = state.pagecount
1865 then fixrow (((pageno - 1) / columns
) * columns
)
1867 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
1869 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno ->
1870 pdimno+1, pdim
, rest
1875 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1877 (conf.winw
- state.scrollw
- w) / 2,
1878 y + rowh
+ conf.interpagespace, h
1881 if (pageno - coverA
) mod columns
= 0
1882 then 0, y + rowh
+ conf.interpagespace, h
1883 else x, y, max rowh
h
1886 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1887 then fixrow (pageno - columns
);
1888 a.(pageno) <- (pdimno, x, y, pdim
);
1889 let x = x + w + xoff
*2 + conf.interpagespace in
1890 loop (pageno+1) pdimno pdim
x y rowh' pdims
1892 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1893 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1896 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1897 let rec loop pageno pdimno pdim
y pdims
=
1898 if pageno = state.pagecount
1901 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1903 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno ->
1904 pdimno+1, pdim
, rest
1909 let rec loop1 n x y =
1910 if n = c then y else (
1911 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
1912 loop1 (n+1) (x+cw) (y + h + conf.interpagespace)
1915 let y = loop1 0 0 y in
1916 loop (pageno+1) pdimno pdim
y pdims
1918 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1919 conf.columns
<- Csplit
(c, a);
1923 docolumns conf.columns
;
1924 state.maxy
<- calcheight ();
1926 if state.w <= conf.winw
- state.scrollw
1930 match state.mode
with
1931 | Birdseye
(_
, _
, pageno, _
, _
) ->
1932 let y, h = getpageyh pageno in
1933 let top = (conf.winh
- h) / 2 in
1934 gotoy (max
0 (y - top))
1935 | _
-> gotoanchor state.anchor
1939 GlDraw.viewport
0 0 w h;
1940 let firsttime = state.geomcmds
== firstgeomcmds in
1941 if not
firsttime && nogeomcmds state.geomcmds
1942 then state.anchor <- getanchor ();
1945 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1948 setfontsize fstate.fontsize
;
1949 GlMat.mode `modelview
;
1950 GlMat.load_identity
();
1952 GlMat.mode `projection
;
1953 GlMat.load_identity
();
1954 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1955 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1956 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1961 else float state.x /. float state.w
1963 invalidate "geometry"
1967 then state.x <- truncate
(relx *. float w);
1969 match conf.columns
with
1971 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1972 | Csplit
(c, _
) -> w * c
1974 wcmd "geometry %d %d" w h);
1978 let len = String.length
state.text in
1981 match state.mode
with
1984 let h, _
, _
= state.uioh#scrollpw
in
1990 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1991 (x+.w, float (conf.winh
- hscrollh))
1994 let w = float (conf.winw
- state.scrollw
- 1) in
1995 if state.progress
>= 0.0 && state.progress
< 1.0
1997 GlDraw.color
(0.3, 0.3, 0.3);
1998 let w1 = w *. state.progress
in
2000 GlDraw.color
(0.0, 0.0, 0.0);
2004 GlDraw.color
(0.0, 0.0, 0.0);
2008 GlDraw.color
(1.0, 1.0, 1.0);
2009 drawstring fstate.fontsize
2010 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2013 match state.mode
with
2014 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
2018 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2020 Printf.sprintf
"%s%s_" prefix
text
2029 if not
(istextentry state.mode
)
2031 let s1 = "(press 'e' to review error messasges)" in
2032 if String.length
s > 0 then s ^
" " ^
s1 else s1
2037 if String.length
s > 0
2042 let len = Queue.length
state.tilelru
in
2044 match state.throttle
with
2047 then preloadlayout state.layout
2049 | Some
(layout, _
, _
) ->
2053 if state.memused
<= conf.memlimit
2058 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2059 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2060 let (_
, pw, ph
, _
) = getpagedim n in
2063 && colorspace
= conf.colorspace
2064 && angle
= conf.angle
2068 let x = col*conf.tilew
2069 and y = row*conf.tileh
in
2070 tilevisible (Lazy.force_val
layout) n x y
2072 then Queue.push lruitem
state.tilelru
2074 wcmd "freetile %s" p
;
2075 state.memused
<- state.memused
- s;
2076 state.uioh#infochanged Memused
;
2077 Hashtbl.remove
state.tilemap k
;
2086 Queue.iter
(fun (k
, p
, s) ->
2087 wcmd "freetile %s" p
;
2088 state.memused
<- state.memused
- s;
2089 state.uioh#infochanged Memused
;
2090 Hashtbl.remove
state.tilemap k
;
2092 Queue.clear
state.tilelru
;
2096 let logcurrently = function
2097 | Idle
-> dolog "Idle"
2098 | Loading
(l
, gen
) ->
2099 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2100 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2102 "Tiling %d[%d,%d] page=%s cs=%s angle"
2103 l
.pageno col row pageopaque
2104 (colorspace_to_string colorspace
)
2106 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2107 angle gen
conf.angle
state.gen
2109 conf.tilew
conf.tileh
2116 (* dolog "%S" cmds; *)
2119 try String.index cmds ' '
2120 with Not_found
-> -1
2125 let l = String.length cmds
in
2126 let op = String.sub cmds
0 spacepos in
2128 if l - spacepos < 2 then ""
2129 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2134 state.uioh#infochanged Pdim
;
2138 state.rects
<- state.rects1
;
2139 G.postRedisplay "clearrects";
2143 try Scanf.sscanf
args "%u" (fun n -> n)
2145 dolog "error processing 'continue' %S: %s"
2146 cmds
(Printexc.to_string exn
);
2149 state.pagecount
<- n;
2150 begin match state.currently
with
2152 state.currently
<- Idle
;
2153 state.outlines
<- Array.of_list
(List.rev
l)
2157 let cur, cmds
= state.geomcmds
in
2158 if String.length
cur = 0
2159 then failwith
"umpossible";
2161 begin match List.rev cmds
with
2163 state.geomcmds
<- "", [];
2167 state.geomcmds
<- s, List.rev rest
;
2169 if conf.maxwait
= None
2170 then G.postRedisplay "continue";
2180 then showtext ' '
args
2183 let progress, text =
2185 Scanf.sscanf
args "%f %n"
2187 f, String.sub
args pos
(String.length
args - pos
))
2189 dolog "error processing 'progress' %S: %s"
2190 cmds
(Printexc.to_string exn
);
2194 state.progress <- progress;
2195 G.postRedisplay "progress"
2198 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2200 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2201 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2202 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2204 dolog "error processing 'firstmatch' %S: %s"
2205 cmds
(Printexc.to_string exn
);
2208 let y = (getpagey pageno) + truncate
y0 in
2211 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2214 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2216 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2217 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2218 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2220 dolog "error processing 'match' %S: %s"
2221 cmds
(Printexc.to_string exn
);
2225 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2230 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2232 dolog "error processing 'page' %S: %s"
2233 cmds
(Printexc.to_string exn
);
2236 begin match state.currently
with
2237 | Loading
(l, gen
) ->
2238 vlog "page %d took %f sec" l.pageno t
;
2239 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2240 begin match state.throttle
with
2242 let preloadedpages =
2244 then preloadlayout state.layout
2249 Set.Make
(struct type t
= int let compare = (-) end) in
2251 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2252 IntSet.empty
preloadedpages
2255 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2256 if not
(IntSet.mem
pageno set)
2258 wcmd "freepage %s" opaque
;
2264 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2267 state.currently
<- Idle
;
2270 tilepage l.pageno pageopaque state.layout;
2272 load preloadedpages;
2273 if pagevisible state.layout l.pageno
2274 && layoutready state.layout
2275 then G.postRedisplay "page";
2278 | Some
(layout, _
, _
) ->
2279 state.currently
<- Idle
;
2280 tilepage l.pageno pageopaque layout;
2285 dolog "Inconsistent loading state";
2286 logcurrently state.currently
;
2291 let (x, y, opaque
, size
, t
) =
2293 Scanf.sscanf
args "%u %u %s %u %f"
2294 (fun x y p size t
-> (x, y, p
, size
, t
))
2296 dolog "error processing 'tile' %S: %s"
2297 cmds
(Printexc.to_string exn
);
2300 begin match state.currently
with
2301 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2302 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2304 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2306 wcmd "freetile %s" opaque
;
2307 state.currently
<- Idle
;
2311 puttileopaque l col row gen cs angle opaque size t
;
2312 state.memused
<- state.memused
+ size
;
2313 state.uioh#infochanged Memused
;
2315 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2316 opaque
, size
) state.tilelru
;
2319 match state.throttle
with
2320 | None
-> state.layout
2321 | Some
(layout, _
, _
) -> layout
2324 state.currently
<- Idle
;
2326 && conf.colorspace
= cs
2327 && conf.angle
= angle
2328 && tilevisible layout l.pageno x y
2329 then conttiling l.pageno pageopaque;
2331 begin match state.throttle
with
2333 preload state.layout;
2335 && conf.colorspace
= cs
2336 && conf.angle
= angle
2337 && tilevisible state.layout l.pageno x y
2338 then G.postRedisplay "tile nothrottle";
2340 | Some
(layout, y, _
) ->
2341 let ready = layoutready layout in
2345 state.layout <- layout;
2346 state.throttle
<- None
;
2347 G.postRedisplay "throttle";
2354 dolog "Inconsistent tiling state";
2355 logcurrently state.currently
;
2362 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2364 dolog "error processing 'pdim' %S: %s"
2365 cmds
(Printexc.to_string exn
);
2368 state.uioh#infochanged Pdim
;
2369 state.pdims
<- pdim :: state.pdims
2372 let (l, n, t
, h, pos
) =
2374 Scanf.sscanf
args "%u %u %d %u %n"
2375 (fun l n t
h pos
-> l, n, t
, h, pos
)
2377 dolog "error processing 'o' %S: %s"
2378 cmds
(Printexc.to_string exn
);
2381 let s = String.sub
args pos
(String.length
args - pos
) in
2382 let outline = (s, l, (n, float t
/. float h)) in
2383 begin match state.currently
with
2384 | Outlining outlines
->
2385 state.currently
<- Outlining
(outline :: outlines
)
2387 state.currently
<- Outlining
[outline]
2389 dolog "invalid outlining state";
2390 logcurrently currently
2394 state.docinfo
<- (1, args) :: state.docinfo
2397 state.uioh#infochanged Docinfo
;
2398 state.docinfo
<- List.rev
state.docinfo
2401 dolog "unknown cmd `%S'" cmds
2406 let action = function
2407 | HCprev
-> cbget cb ~
-1
2408 | HCnext
-> cbget cb
1
2409 | HCfirst
-> cbget cb ~
-(cb
.rc)
2410 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2411 and cancel
() = cb
.rc <- rc
2415 let search pattern forward
=
2416 if String.length pattern
> 0
2419 match state.layout with
2422 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2424 wcmd "search %d %d %d %d,%s\000"
2425 (btod conf.icase
) pn py
(btod forward
) pattern
;
2428 let intentry text key =
2430 if key >= 32 && key < 127
2436 let text = addchar text c in
2440 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2444 let linknentry text key =
2446 if key >= 32 && key < 127
2452 let text = addchar text c in
2456 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2461 if String.length
s > 0
2464 let l = String.length
s in
2465 let rec loop pos
n = if pos
= l then n else
2466 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2467 loop (pos
+1) (n*26 + m)
2470 let rec loop n = function
2473 match getopaque l.pageno with
2474 | None
-> loop n rest
2476 let m = getlinkcount opaque
in
2479 let under = getlink opaque
n in
2482 else loop (n-m) rest
2484 loop n state.layout;
2488 let textentry text key =
2489 if key land 0xff00 = 0xff00
2491 else TEcont
(text ^
Wsi.toutf8
key)
2494 let reqlayout angle proportional
=
2495 match state.throttle
with
2497 if nogeomcmds state.geomcmds
2498 then state.anchor <- getanchor ();
2499 conf.angle
<- angle
mod 360;
2502 match state.mode
with
2503 | LinkNav _
-> state.mode
<- View
2506 conf.proportional
<- proportional
;
2507 invalidate "reqlayout"
2508 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2512 let settrim trimmargins trimfuzz
=
2513 if nogeomcmds state.geomcmds
2514 then state.anchor <- getanchor ();
2515 conf.trimmargins
<- trimmargins
;
2516 conf.trimfuzz
<- trimfuzz
;
2517 let x0, y0, x1, y1 = trimfuzz
in
2518 invalidate "settrim"
2520 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2521 Hashtbl.iter
(fun _ opaque
->
2522 wcmd "freepage %s" opaque
;
2524 Hashtbl.clear
state.pagemap
;
2528 match state.throttle
with
2530 let zoom = max
0.01 zoom in
2531 if zoom <> conf.zoom
2533 state.prevzoom
<- conf.zoom;
2535 reshape conf.winw
conf.winh
;
2536 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2539 | Some
(layout, y, started
) ->
2541 match conf.maxwait
with
2545 let dt = now () -. started
in
2553 let setcolumns mode columns coverA coverB
=
2554 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2558 then showtext '
!'
"split mode doesn't work in bird's eye"
2560 conf.columns
<- Csplit
(-columns
, [||]);
2568 conf.columns
<- Csingle
[||];
2573 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2577 reshape conf.winw
conf.winh
;
2580 let enterbirdseye () =
2581 let zoom = float conf.thumbw
/. float conf.winw
in
2582 let birdseyepageno =
2583 let cy = conf.winh
/ 2 in
2587 let rec fold best
= function
2590 let d = cy - (l.pagedispy + l.pagevh/2)
2591 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2592 if abs
d < abs dbest
2599 state.mode
<- Birdseye
(
2600 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2603 conf.presentation <- false;
2604 conf.interpagespace <- 10;
2605 conf.hlinks
<- false;
2607 state.mstate
<- Mnone
;
2608 conf.maxwait
<- None
;
2610 match conf.beyecolumns
with
2613 Cmulti
((c, 0, 0), [||])
2614 | None
-> Csingle
[||]
2616 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2619 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2624 reshape conf.winw
conf.winh
;
2627 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2629 conf.zoom <- c.zoom;
2630 conf.presentation <- c.presentation;
2631 conf.interpagespace <- c.interpagespace;
2632 conf.maxwait
<- c.maxwait
;
2633 conf.hlinks
<- c.hlinks
;
2634 conf.beyecolumns
<- (
2635 match conf.columns
with
2636 | Cmulti
((c, _
, _
), _
) -> Some
c
2638 | Csplit _
-> failwith
"leaving bird's eye split mode"
2641 match c.columns
with
2642 | Cmulti
(c, _
) -> Cmulti
(c, [||])
2643 | Csingle _
-> Csingle
[||]
2644 | Csplit
(c, _
) -> Csplit
(c, [||])
2649 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2652 reshape conf.winw
conf.winh
;
2653 state.anchor <- if goback
then anchor else (pageno, 0.0);
2656 let togglebirdseye () =
2657 match state.mode
with
2658 | Birdseye vals
-> leavebirdseye vals
true
2659 | View
-> enterbirdseye ()
2663 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2664 let pageno = max
0 (pageno - incr
) in
2665 let rec loop = function
2666 | [] -> gotopage1 pageno 0
2667 | l :: _
when l.pageno = pageno ->
2668 if l.pagedispy >= 0 && l.pagey = 0
2669 then G.postRedisplay "upbirdseye"
2670 else gotopage1 pageno 0
2671 | _
:: rest
-> loop rest
2674 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2677 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2678 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2679 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2680 let rec loop = function
2682 let y, h = getpageyh pageno in
2683 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2685 | l :: _
when l.pageno = pageno ->
2686 if l.pagevh != l.pageh
2687 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2688 else G.postRedisplay "downbirdseye"
2689 | _
:: rest
-> loop rest
2694 let optentry mode _
key =
2695 let btos b = if b then "on" else "off" in
2696 if key >= 32 && key < 127
2698 let c = Char.chr
key in
2702 try conf.scrollstep
<- int_of_string
s with exc
->
2703 state.text <- Printf.sprintf
"bad integer `%s': %s"
2704 s (Printexc.to_string exc
)
2706 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2711 conf.autoscrollstep
<- int_of_string
s;
2712 if state.autoscroll
<> None
2713 then state.autoscroll
<- Some
conf.autoscrollstep
2715 state.text <- Printf.sprintf
"bad integer `%s': %s"
2716 s (Printexc.to_string exc
)
2718 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2723 let n, a, b = multicolumns_of_string s in
2724 setcolumns mode
n a b;
2726 state.text <- Printf.sprintf
"bad columns `%s': %s"
2727 s (Printexc.to_string exc
)
2729 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2734 let zoom = float (int_of_string
s) /. 100.0 in
2737 state.text <- Printf.sprintf
"bad integer `%s': %s"
2738 s (Printexc.to_string exc
)
2740 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2745 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2747 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2748 begin match mode
with
2750 leavebirdseye beye
false;
2755 state.text <- Printf.sprintf
"bad integer `%s': %s"
2756 s (Printexc.to_string exc
)
2758 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2763 Some
(int_of_string
s)
2765 state.text <- Printf.sprintf
"bad integer `%s': %s"
2766 s (Printexc.to_string exc
);
2769 | Some angle
-> reqlayout angle
conf.proportional
2772 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2775 conf.icase
<- not
conf.icase
;
2776 TEdone
("case insensitive search " ^
(btos conf.icase
))
2779 conf.preload <- not
conf.preload;
2781 TEdone
("preload " ^
(btos conf.preload))
2784 conf.verbose
<- not
conf.verbose
;
2785 TEdone
("verbose " ^
(btos conf.verbose
))
2788 conf.debug
<- not
conf.debug
;
2789 TEdone
("debug " ^
(btos conf.debug
))
2792 conf.maxhfit
<- not
conf.maxhfit
;
2793 state.maxy
<- calcheight ();
2794 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2797 conf.crophack
<- not
conf.crophack
;
2798 TEdone
("crophack " ^
btos conf.crophack
)
2802 match conf.maxwait
with
2804 conf.maxwait
<- Some infinity
;
2805 "always wait for page to complete"
2807 conf.maxwait
<- None
;
2808 "show placeholder if page is not ready"
2813 conf.underinfo
<- not
conf.underinfo
;
2814 TEdone
("underinfo " ^
btos conf.underinfo
)
2817 conf.savebmarks
<- not
conf.savebmarks
;
2818 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2824 match state.layout with
2829 conf.interpagespace <- int_of_string
s;
2830 docolumns conf.columns
;
2831 state.maxy
<- calcheight ();
2832 let y = getpagey pageno in
2835 state.text <- Printf.sprintf
"bad integer `%s': %s"
2836 s (Printexc.to_string exc
)
2838 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2841 reqlayout conf.angle
(not
conf.proportional
);
2842 TEdone
("proportional display " ^
btos conf.proportional
)
2845 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2846 TEdone
("trim margins " ^
btos conf.trimmargins
)
2849 conf.invert
<- not
conf.invert
;
2850 TEdone
("invert colors " ^
btos conf.invert
)
2854 cbput state.hists
.sel
s;
2857 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2858 textentry, ondone, true)
2861 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2867 class type lvsource
= object
2868 method getitemcount
: int
2869 method getitem
: int -> (string * int)
2870 method hasaction
: int -> bool
2879 method getactive
: int
2880 method getfirst
: int
2881 method getqsearch
: string
2882 method setqsearch
: string -> unit
2886 class virtual lvsourcebase
= object
2887 val mutable m_active
= 0
2888 val mutable m_first
= 0
2889 val mutable m_qsearch
= ""
2890 val mutable m_pan
= 0
2891 method getactive
= m_active
2892 method getfirst
= m_first
2893 method getqsearch
= m_qsearch
2894 method getpan
= m_pan
2895 method setqsearch
s = m_qsearch
<- s
2898 let withoutlastutf8 s =
2899 let len = String.length
s in
2907 let b = Char.code
s.[pos
] in
2908 if b land 0b110000 = 0b11000000
2913 if Char.code
s.[len-1] land 0x80 = 0
2917 String.sub
s 0 first;
2920 let textentrykeyboard
2921 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2923 state.mode
<- Textentry
(te
, onleave
);
2926 G.postRedisplay "textentrykeyboard enttext";
2928 let histaction cmd
=
2931 | Some
(action, _
) ->
2932 state.mode
<- Textentry
(
2933 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2935 G.postRedisplay "textentry histaction"
2938 | 0xff08 -> (* backspace *)
2939 let s = withoutlastutf8 text in
2940 let len = String.length
s in
2941 if cancelonempty
&& len = 0
2944 G.postRedisplay "textentrykeyboard after cancel";
2947 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
2953 G.postRedisplay "textentrykeyboard after confirm"
2955 | 0xff52 -> histaction HCprev
2956 | 0xff54 -> histaction HCnext
2957 | 0xff50 -> histaction HCfirst
2958 | 0xff57 -> histaction HClast
2960 | 0xff1b -> (* escape*)
2961 if String.length
text = 0
2963 begin match opthist
with
2965 | Some
(_
, onhistcancel
) -> onhistcancel
()
2969 G.postRedisplay "textentrykeyboard after cancel2"
2972 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
2975 | 0xff9f | 0xffff -> () (* delete *)
2977 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2978 begin match onkey
text key with
2982 G.postRedisplay "textentrykeyboard after confirm2";
2985 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
2989 G.postRedisplay "textentrykeyboard after cancel3"
2992 state.mode
<- Textentry
(te
, onleave
);
2993 G.postRedisplay "textentrykeyboard switch";
2997 vlog "unhandled key %s" (Wsi.keyname
key)
3000 let firstof first active
=
3001 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3002 then max
0 (active
- (fstate.maxrows
/2))
3006 let calcfirst first active
=
3009 let rows = active
- first in
3010 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3014 let scrollph y maxy
=
3015 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3016 let sh = float conf.winh
/. sh in
3017 let sh = max
sh (float conf.scrollh
) in
3022 else float y /. float maxy
3024 let position = (float conf.winh
-. sh) *. percent in
3027 if position +. sh > float conf.winh
3028 then float conf.winh
-. sh
3034 let coe s = (s :> uioh
);;
3036 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3038 val m_pan
= source#getpan
3039 val m_first
= source#getfirst
3040 val m_active
= source#getactive
3041 val m_qsearch
= source#getqsearch
3042 val m_prev_uioh
= state.uioh
3044 method private elemunder
y =
3045 let n = y / (fstate.fontsize
+1) in
3046 if m_first
+ n < source#getitemcount
3048 if source#hasaction
(m_first
+ n)
3049 then Some
(m_first
+ n)
3056 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3057 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3058 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3059 GlDraw.color
(1., 1., 1.);
3060 Gl.enable `texture_2d
;
3061 let fs = fstate.fontsize
in
3063 let ww = fstate.wwidth
in
3064 let tabw = 30.0*.ww in
3065 let itemcount = source#getitemcount
in
3067 if (row - m_first
) * nfs > conf.winh
3070 if row >= 0 && row < itemcount
3072 let (s, level
) = source#getitem
row in
3073 let y = (row - m_first
) * nfs in
3074 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3077 Gl.disable `texture_2d
;
3078 GlDraw.polygon_mode `both `line
;
3079 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3080 GlDraw.rect (1., float (y + 1))
3081 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3082 GlDraw.polygon_mode `both `fill
;
3083 GlDraw.color
(1., 1., 1.);
3084 Gl.enable `texture_2d
;
3087 let drawtabularstring s =
3088 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3091 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3094 let len = String.length
s - tabpos - 1 in
3095 let s1 = String.sub
s 0 tabpos
3096 and s2
= String.sub
s (tabpos + 1) len in
3097 let nx = drawstr x s1 in
3099 let x = x +. (max
tabw sw) in
3106 let _ = drawtabularstring s in
3113 Gl.disable `texture_2d
;
3115 method updownlevel incr
=
3116 let len = source#getitemcount
in
3118 if m_active
>= 0 && m_active
< len
3119 then snd
(source#getitem m_active
)
3123 if i
= len then i
-1 else if i
= -1 then 0 else
3124 let _, l = source#getitem i
in
3125 if l != curlevel then i
else flow (i
+incr
)
3127 let active = flow m_active
in
3128 let first = calcfirst m_first
active in
3129 G.postRedisplay "outline updownlevel";
3130 {< m_active
= active; m_first
= first >}
3132 method private key1
key mask
=
3133 let set1 active first qsearch
=
3134 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3136 let search active pattern incr
=
3139 if n >= 0 && n < source#getitemcount
3141 let s, _ = source#getitem
n in
3143 (try ignore
(Str.search_forward
re s 0); true
3144 with Not_found
-> false)
3146 else loop (n + incr
)
3153 let re = Str.regexp_case_fold pattern
in
3159 let itemcount = source#getitemcount
in
3160 let find start incr
=
3162 if i
= -1 || i
= itemcount
3165 if source#hasaction i
3167 else find (i
+ incr
)
3172 let set active first =
3173 let first = bound first 0 (itemcount - fstate.maxrows
) in
3175 coe {< m_active
= active; m_first
= first >}
3178 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3180 let incr1 = if incr
> 0 then 1 else -1 in
3181 if isvisible m_first m_active
3184 let next = m_active
+ incr
in
3186 if next < 0 || next >= itemcount
3188 else find next incr1
3190 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3196 let first = m_first
+ incr
in
3197 let first = bound first 0 (itemcount - 1) in
3199 let next = m_active
+ incr
in
3200 let next = bound next 0 (itemcount - 1) in
3203 let active = if next = -1 then m_active
else next in
3206 let first = min
next m_first
in
3208 if abs
(next - first) > fstate.maxrows
3214 let first = m_first
+ incr
in
3215 let first = bound first 0 (itemcount - 1) in
3217 let next = m_active
+ incr
in
3218 let next = bound next 0 (itemcount - 1) in
3219 let next = find next incr1 in
3221 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3223 let active = if m_active
= -1 then next else m_active
in
3228 if isvisible first active
3234 G.postRedisplay "listview navigate";
3238 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3239 let incr = if key = 0x72 then -1 else 1 in
3241 match search (m_active
+ incr) m_qsearch
incr with
3243 state.text <- m_qsearch ^
" [not found]";
3246 state.text <- m_qsearch
;
3247 active, firstof m_first
active
3249 G.postRedisplay "listview ctrl-r/s";
3250 set1 active first m_qsearch
;
3252 | 0xff08 -> (* backspace *)
3253 if String.length m_qsearch
= 0
3256 let qsearch = withoutlastutf8 m_qsearch
in
3257 let len = String.length
qsearch in
3261 G.postRedisplay "listview empty qsearch";
3262 set1 m_active m_first
"";
3266 match search m_active
qsearch ~
-1 with
3268 state.text <- qsearch ^
" [not found]";
3271 state.text <- qsearch;
3272 active, firstof m_first
active
3274 G.postRedisplay "listview backspace qsearch";
3275 set1 active first qsearch
3278 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3279 let pattern = m_qsearch ^
Wsi.toutf8
key in
3281 match search m_active
pattern 1 with
3283 state.text <- pattern ^
" [not found]";
3286 state.text <- pattern;
3287 active, firstof m_first
active
3289 G.postRedisplay "listview qsearch add";
3290 set1 active first pattern;
3292 | 0xff1b -> (* escape *)
3294 if String.length m_qsearch
= 0
3296 G.postRedisplay "list view escape";
3299 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3301 | None
-> m_prev_uioh
3306 G.postRedisplay "list view kill qsearch";
3307 source#setqsearch
"";
3308 coe {< m_qsearch
= "" >}
3311 | 0xff0d -> (* return *)
3313 let self = {< m_qsearch
= "" >} in
3314 source#setqsearch
"";
3316 G.postRedisplay "listview enter";
3317 if m_active
>= 0 && m_active
< source#getitemcount
3319 source#exit
(coe self) false m_active m_first m_pan
"";
3322 source#exit
(coe self) true m_active m_first m_pan
"";
3325 begin match opt with
3326 | None
-> m_prev_uioh
3330 | 0xff9f | 0xffff -> (* delete *)
3333 | 0xff52 -> navigate ~
-1 (* up *)
3334 | 0xff54 -> navigate 1 (* down *)
3335 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3336 | 0xff56 -> navigate fstate.maxrows
(* next *)
3338 | 0xff53 -> (* right *)
3340 G.postRedisplay "listview right";
3341 coe {< m_pan
= m_pan
- 1 >}
3343 | 0xff51 -> (* left *)
3345 G.postRedisplay "listview left";
3346 coe {< m_pan
= m_pan
+ 1 >}
3348 | 0xff50 -> (* home *)
3349 let active = find 0 1 in
3350 G.postRedisplay "listview home";
3353 | 0xff57 -> (* end *)
3354 let first = max
0 (itemcount - fstate.maxrows
) in
3355 let active = find (itemcount - 1) ~
-1 in
3356 G.postRedisplay "listview end";
3359 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3363 dolog "listview unknown key %#x" key; coe self
3365 method key key mask
=
3366 match state.mode
with
3367 | Textentry te
-> textentrykeyboard key mask te
; coe self
3368 | _ -> self#key1
key mask
3370 method button button down
x y _ =
3373 | 1 when x > conf.winw
- conf.scrollbw
->
3374 G.postRedisplay "listview scroll";
3377 let _, position, sh = self#
scrollph in
3378 if y > truncate
position && y < truncate
(position +. sh)
3380 state.mstate
<- Mscrolly
;
3384 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3385 let first = truncate
(s *. float source#getitemcount
) in
3386 let first = min source#getitemcount
first in
3387 Some
(coe {< m_first
= first; m_active
= first >})
3389 state.mstate
<- Mnone
;
3392 | 1 when not down
->
3393 begin match self#elemunder
y with
3395 G.postRedisplay "listview click";
3397 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3401 | n when (n == 4 || n == 5) && not down
->
3402 let len = source#getitemcount
in
3404 if n = 5 && m_first
+ fstate.maxrows
>= len
3408 let first = m_first
+ (if n == 4 then -1 else 1) in
3409 bound first 0 (len - 1)
3411 G.postRedisplay "listview wheel";
3412 Some
(coe {< m_first
= first >})
3413 | n when (n = 6 || n = 7) && not down
->
3414 let inc = m_first
+ (if n = 7 then -1 else 1) in
3415 G.postRedisplay "listview hwheel";
3416 Some
(coe {< m_pan
= m_pan
+ inc >})
3421 | None
-> m_prev_uioh
3425 match state.mstate
with
3427 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3428 let first = truncate
(s *. float source#getitemcount
) in
3429 let first = min source#getitemcount
first in
3430 G.postRedisplay "listview motion";
3431 coe {< m_first
= first; m_active
= first >}
3434 method pmotion
x y =
3435 if x < conf.winw
- conf.scrollbw
3438 match self#elemunder
y with
3439 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3440 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3444 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3449 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3453 method infochanged
_ = ()
3455 method scrollpw
= (0, 0.0, 0.0)
3457 let nfs = fstate.fontsize
+ 1 in
3458 let y = m_first
* nfs in
3459 let itemcount = source#getitemcount
in
3460 let maxi = max
0 (itemcount - fstate.maxrows
) in
3461 let maxy = maxi * nfs in
3462 let p, h = scrollph y maxy in
3465 method modehash
= modehash
3468 class outlinelistview ~source
=
3471 ~source
:(source
:> lvsource
)
3473 ~modehash
:(findkeyhash conf "outline")
3476 method key key mask
=
3477 let calcfirst first active =
3480 let rows = active - first in
3482 if String.length
state.text = 0
3484 else fstate.maxrows - 2
3486 if rows > maxrows then active - maxrows else first
3490 let active = m_active
+ incr in
3491 let active = bound active 0 (source#getitemcount
- 1) in
3492 let first = calcfirst m_first
active in
3493 G.postRedisplay "outline navigate";
3494 coe {< m_active
= active; m_first
= first >}
3496 let ctrl = Wsi.withctrl mask
in
3498 | 110 when ctrl -> (* ctrl-n *)
3499 source#narrow m_qsearch
;
3500 G.postRedisplay "outline ctrl-n";
3501 coe {< m_first
= 0; m_active
= 0 >}
3503 | 117 when ctrl -> (* ctrl-u *)
3505 G.postRedisplay "outline ctrl-u";
3507 coe {< m_first
= 0; m_active
= 0 >}
3509 | 108 when ctrl -> (* ctrl-l *)
3510 let first = m_active
- (fstate.maxrows / 2) in
3511 G.postRedisplay "outline ctrl-l";
3512 coe {< m_first
= first >}
3514 | 0xff9f | 0xffff -> (* delete *)
3515 source#remove m_active
;
3516 G.postRedisplay "outline delete";
3517 let active = max
0 (m_active
-1) in
3518 coe {< m_first
= firstof m_first
active;
3519 m_active
= active >}
3521 | 0xff52 -> navigate ~
-1 (* up *)
3522 | 0xff54 -> navigate 1 (* down *)
3523 | 0xff55 -> (* prior *)
3524 navigate ~
-(fstate.maxrows)
3525 | 0xff56 -> (* next *)
3526 navigate fstate.maxrows
3528 | 0xff53 -> (* [ctrl-]right *)
3532 G.postRedisplay "outline ctrl right";
3533 {< m_pan
= m_pan
+ 1 >}
3535 else self#updownlevel
1
3539 | 0xff51 -> (* [ctrl-]left *)
3543 G.postRedisplay "outline ctrl left";
3544 {< m_pan
= m_pan
- 1 >}
3546 else self#updownlevel ~
-1
3550 | 0xff50 -> (* home *)
3551 G.postRedisplay "outline home";
3552 coe {< m_first
= 0; m_active
= 0 >}
3554 | 0xff57 -> (* end *)
3555 let active = source#getitemcount
- 1 in
3556 let first = max
0 (active - fstate.maxrows) in
3557 G.postRedisplay "outline end";
3558 coe {< m_active
= active; m_first
= first >}
3560 | _ -> super#
key key mask
3563 let outlinesource usebookmarks
=
3566 inherit lvsourcebase
3567 val mutable m_items
= empty
3568 val mutable m_orig_items
= empty
3569 val mutable m_prev_items
= empty
3570 val mutable m_narrow_pattern
= ""
3571 val mutable m_hadremovals
= false
3573 method getitemcount
=
3574 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3577 if n == Array.length m_items
&& m_hadremovals
3579 ("[Confirm removal]", 0)
3581 let s, n, _ = m_items
.(n) in
3584 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3585 ignore
(uioh
, first, qsearch);
3586 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3588 if String.length m_narrow_pattern
= 0
3594 if not
confrimremoval
3596 let _, _, anchor = m_items
.(active) in
3601 state.bookmarks
<- Array.to_list m_items
;
3602 m_orig_items
<- m_items
;
3605 else m_items
<- items;
3609 method hasaction
_ = true
3612 if Array.length m_items
!= Array.length m_orig_items
3613 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3616 method narrow
pattern =
3617 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3621 let rec loop accu n =
3624 m_narrow_pattern
<- pattern;
3625 m_items
<- Array.of_list
accu
3628 let (s, _, _) as o = m_items
.(n) in
3630 if (try ignore
(Str.search_forward
re s 0); true
3631 with Not_found
-> false)
3637 loop [] (Array.length m_items
- 1)
3642 then Array.of_list
state.bookmarks
3645 m_items
<- m_orig_items
3650 if m >= 0 && m < Array.length m_items
3652 m_hadremovals
<- true;
3653 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3654 let n = if n >= m then n+1 else n in
3659 method reset
anchor items =
3660 m_hadremovals
<- false;
3661 if m_orig_items
== empty || m_prev_items
!= items
3663 m_orig_items
<- items;
3664 if String.length m_narrow_pattern
= 0
3665 then m_items
<- items;
3667 m_prev_items
<- items;
3668 let rely = getanchory anchor in
3670 let rec loop n best bestd
=
3671 if n = Array.length m_items
3674 let (_, _, anchor) = m_items
.(n) in
3675 let orely = getanchory anchor in
3676 let d = abs
(orely - rely) in
3679 else loop (n+1) best bestd
3684 m_first
<- firstof m_first
active
3688 let enterselector usebookmarks
=
3689 let source = outlinesource usebookmarks
in
3693 then Array.of_list
state.bookmarks
3696 if Array.length
outlines = 0
3698 showtext ' ' errmsg
;
3701 state.text <- source#greetmsg
;
3702 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3703 let anchor = getanchor () in
3704 source#reset
anchor outlines;
3705 state.uioh
<- coe (new outlinelistview ~
source);
3706 G.postRedisplay "enter selector";
3710 let enteroutlinemode =
3711 let f = enterselector false in
3712 fun ()-> f "Document has no outline";
3715 let enterbookmarkmode =
3716 let f = enterselector true in
3717 fun () -> f "Document has no bookmarks (yet)";
3720 let color_of_string s =
3721 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3722 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3726 let color_to_string (r
, g
, b) =
3727 let r = truncate
(r *. 256.0)
3728 and g
= truncate
(g
*. 256.0)
3729 and b = truncate
(b *. 256.0) in
3730 Printf.sprintf
"%d/%d/%d" r g
b
3733 let irect_of_string s =
3734 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3737 let irect_to_string (x0,y0,x1,y1) =
3738 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3741 let makecheckers () =
3742 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3744 converted by Issac Trotts. July 25, 2002 *)
3745 let image_height = 64
3746 and image_width
= 64 in
3750 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3752 for i
= 0 to image_width
- 1 do
3753 for j
= 0 to image_height - 1 do
3754 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3755 (if (i
land 8 ) lxor (j
land 8) = 0
3756 then [|255;255;255|] else [|200;200;200|])
3761 let image = make_image () in
3762 let id = GlTex.gen_texture
() in
3763 GlTex.bind_texture `texture_2d
id;
3764 GlPix.store
(`unpack_alignment
1);
3765 GlTex.image2d
image;
3766 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3769 `mag_filter `nearest
;
3770 `min_filter `nearest
];
3774 let setcheckers enabled
=
3775 match state.texid
with
3777 if enabled
then state.texid
<- Some
(makecheckers ())
3782 GlTex.delete_texture texid
;
3783 state.texid
<- None
;
3787 let int_of_string_with_suffix s =
3788 let l = String.length
s in
3792 let suffix = Char.lowercase
s.[l-1] in
3794 | 'k'
-> String.sub
s 0 (l-1), 10
3795 | '
m'
-> String.sub
s 0 (l-1), 20
3796 | 'g'
-> String.sub
s 0 (l-1), 30
3800 let n = int_of_string
s1 in
3801 let m = n lsl shift
in
3803 then raise
(Failure
"value too large")
3807 let string_with_suffix_of_int n =
3812 if n land ((1 lsl 20) - 1) = 0
3815 if n land ((1 lsl 10) - 1) = 0
3821 let h = n mod 1000 in
3824 then string_of_int
h ^
s
3826 let s = Printf.sprintf
"_%03d%s" h s in
3833 let defghyllscroll = (40, 8, 32);;
3834 let ghyllscroll_of_string s =
3835 let (n, a, b) as nab
=
3838 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3840 if n <= a || n <= b || a >= b
3841 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3845 let ghyllscroll_to_string ((n, a, b) as nab
) =
3846 if nab
= defghyllscroll
3848 else Printf.sprintf
"%d,%d,%d" n a b;
3851 let describe_location () =
3853 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3855 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3856 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3860 else (100. *. (float state.y /. float maxy))
3864 Printf.sprintf
"page %d of %d [%.2f%%]"
3865 (fn+1) state.pagecount
percent
3868 "pages %d-%d of %d [%.2f%%]"
3869 (fn+1) (ln
+1) state.pagecount
percent
3873 let btos b = if b then "\xe2\x88\x9a" else "" in
3874 let showextended = ref false in
3875 let leave mode
= function
3876 | Confirm
-> state.mode
<- mode
3877 | Cancel
-> state.mode
<- mode
in
3880 val mutable m_first_time
= true
3881 val mutable m_l
= []
3882 val mutable m_a
= [||]
3883 val mutable m_prev_uioh
= nouioh
3884 val mutable m_prev_mode
= View
3886 inherit lvsourcebase
3888 method reset prev_mode prev_uioh
=
3889 m_a
<- Array.of_list
(List.rev m_l
);
3891 m_prev_mode
<- prev_mode
;
3892 m_prev_uioh
<- prev_uioh
;
3896 if n >= Array.length m_a
3900 | _, _, _, Action
_ -> m_active
<- n
3904 m_first_time
<- false;
3907 method int name get
set =
3909 (name
, `
int get
, 1, Action
(
3912 try set (int_of_string
s)
3914 state.text <- Printf.sprintf
"bad integer `%s': %s"
3915 s (Printexc.to_string exn
)
3918 let te = name ^
": ", "", None
, intentry, ondone, true in
3919 state.mode
<- Textentry
(te, leave m_prev_mode
);
3923 method int_with_suffix name get
set =
3925 (name
, `intws get
, 1, Action
(
3928 try set (int_of_string_with_suffix s)
3930 state.text <- Printf.sprintf
"bad integer `%s': %s"
3931 s (Printexc.to_string exn
)
3935 name ^
": ", "", None
, intentry_with_suffix, ondone, true
3937 state.mode
<- Textentry
(te, leave m_prev_mode
);
3941 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3943 (name
, `
bool (btos, get
), offset
, Action
(
3950 method color name get
set =
3952 (name
, `color get
, 1, Action
(
3954 let invalid = (nan
, nan
, nan
) in
3957 try color_of_string s
3959 state.text <- Printf.sprintf
"bad color `%s': %s"
3960 s (Printexc.to_string exn
);
3966 let te = name ^
": ", "", None
, textentry, ondone, true in
3967 state.text <- color_to_string (get
());
3968 state.mode
<- Textentry
(te, leave m_prev_mode
);
3972 method string name get
set =
3974 (name
, `
string get
, 1, Action
(
3976 let ondone s = set s in
3977 let te = name ^
": ", "", None
, textentry, ondone, true in
3978 state.mode
<- Textentry
(te, leave m_prev_mode
);
3982 method colorspace name get
set =
3984 (name
, `
string get
, 1, Action
(
3987 let vals = [| "rgb"; "bgr"; "gray" |] in
3989 inherit lvsourcebase
3992 m_active
<- int_of_colorspace conf.colorspace
;
3995 method getitemcount
= Array.length
vals
3996 method getitem
n = (vals.(n), 0)
3997 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3998 ignore
(uioh
, first, pan
, qsearch);
3999 if not cancel
then set active;
4001 method hasaction
_ = true
4005 let modehash = findkeyhash conf "info" in
4006 coe (new listview ~
source ~trusted
:true ~
modehash)
4009 method caption
s offset
=
4010 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4012 method caption2
s f offset
=
4013 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4015 method getitemcount
= Array.length m_a
4018 let tostr = function
4019 | `
int f -> string_of_int
(f ())
4020 | `intws
f -> string_with_suffix_of_int (f ())
4022 | `color
f -> color_to_string (f ())
4023 | `
bool (btos, f) -> btos (f ())
4026 let name, t
, offset
, _ = m_a
.(n) in
4027 ((let s = tostr t
in
4028 if String.length
s > 0
4029 then Printf.sprintf
"%s\t%s" name s
4033 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4037 m_qsearch
<- qsearch;
4039 match m_a
.(active) with
4040 | _, _, _, Action
f -> f uioh
4052 method hasaction
n =
4054 | _, _, _, Action
_ -> true
4058 let rec fillsrc prevmode prevuioh
=
4059 let sep () = src#caption
"" 0 in
4060 let colorp name get
set =
4062 (fun () -> color_to_string (get
()))
4065 let c = color_of_string v in
4068 state.text <- Printf.sprintf
"bad color `%s': %s"
4069 v (Printexc.to_string exn
);
4072 let oldmode = state.mode
in
4073 let birdseye = isbirdseye state.mode
in
4075 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4077 src#
bool "presentation mode"
4078 (fun () -> conf.presentation)
4080 conf.presentation <- v;
4081 state.anchor <- getanchor ();
4084 src#
bool "ignore case in searches"
4085 (fun () -> conf.icase
)
4086 (fun v -> conf.icase
<- v);
4089 (fun () -> conf.preload)
4090 (fun v -> conf.preload <- v);
4092 src#
bool "highlight links"
4093 (fun () -> conf.hlinks
)
4094 (fun v -> conf.hlinks
<- v);
4096 src#
bool "under info"
4097 (fun () -> conf.underinfo
)
4098 (fun v -> conf.underinfo
<- v);
4100 src#
bool "persistent bookmarks"
4101 (fun () -> conf.savebmarks
)
4102 (fun v -> conf.savebmarks
<- v);
4104 src#
bool "proportional display"
4105 (fun () -> conf.proportional
)
4106 (fun v -> reqlayout conf.angle
v);
4108 src#
bool "trim margins"
4109 (fun () -> conf.trimmargins
)
4110 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4112 src#
bool "persistent location"
4113 (fun () -> conf.jumpback
)
4114 (fun v -> conf.jumpback
<- v);
4117 src#
int "inter-page space"
4118 (fun () -> conf.interpagespace)
4120 conf.interpagespace <- n;
4121 docolumns conf.columns
;
4123 match state.layout with
4128 state.maxy <- calcheight ();
4129 let y = getpagey pageno in
4134 (fun () -> conf.pagebias
)
4135 (fun v -> conf.pagebias
<- v);
4137 src#
int "scroll step"
4138 (fun () -> conf.scrollstep
)
4139 (fun n -> conf.scrollstep
<- n);
4141 src#
int "horizontal scroll step"
4142 (fun () -> conf.hscrollstep
)
4143 (fun v -> conf.hscrollstep
<- v);
4145 src#
int "auto scroll step"
4147 match state.autoscroll
with
4149 | _ -> conf.autoscrollstep
)
4151 if state.autoscroll
<> None
4152 then state.autoscroll
<- Some
n;
4153 conf.autoscrollstep
<- n);
4156 (fun () -> truncate
(conf.zoom *. 100.))
4157 (fun v -> setzoom ((float v) /. 100.));
4160 (fun () -> conf.angle
)
4161 (fun v -> reqlayout v conf.proportional
);
4163 src#
int "scroll bar width"
4164 (fun () -> state.scrollw
)
4168 reshape conf.winw
conf.winh
;
4171 src#
int "scroll handle height"
4172 (fun () -> conf.scrollh
)
4173 (fun v -> conf.scrollh
<- v;);
4175 src#
int "thumbnail width"
4176 (fun () -> conf.thumbw
)
4178 conf.thumbw
<- min
4096 v;
4181 leavebirdseye beye
false;
4186 let mode = state.mode in
4187 src#
string "columns"
4189 match conf.columns
with
4191 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4192 | Csplit
(count
, _) -> "-" ^ string_of_int count
4195 let n, a, b = multicolumns_of_string v in
4196 setcolumns mode n a b);
4199 src#caption
"Presentation mode" 0;
4200 src#
bool "scrollbar visible"
4201 (fun () -> conf.scrollbarinpm
)
4203 if v != conf.scrollbarinpm
4205 conf.scrollbarinpm
<- v;
4206 if conf.presentation
4208 state.scrollw
<- if v then conf.scrollbw
else 0;
4209 reshape conf.winw
conf.winh
;
4215 src#caption
"Pixmap cache" 0;
4216 src#int_with_suffix
"size (advisory)"
4217 (fun () -> conf.memlimit
)
4218 (fun v -> conf.memlimit
<- v);
4221 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4222 (string_with_suffix_of_int state.memused
)
4223 (Hashtbl.length
state.tilemap
)) 1;
4226 src#caption
"Layout" 0;
4227 src#caption2
"Dimension"
4229 Printf.sprintf
"%dx%d (virtual %dx%d) [pos %d]"
4231 state.w state.maxy state.y)
4235 src#caption2
"Position" (fun () ->
4236 Printf.sprintf
"%dx%d" state.x state.y
4239 src#caption2
"Visible" (fun () -> describe_location ()) 1
4243 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4244 "Save these parameters as global defaults at exit"
4245 (fun () -> conf.bedefault
)
4246 (fun v -> conf.bedefault
<- v)
4250 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4251 src#
bool ~offset
:0 ~
btos "Extended parameters"
4252 (fun () -> !showextended)
4253 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4257 (fun () -> conf.checkers
)
4258 (fun v -> conf.checkers
<- v; setcheckers v);
4259 src#
bool "update cursor"
4260 (fun () -> conf.updatecurs
)
4261 (fun v -> conf.updatecurs
<- v);
4263 (fun () -> conf.verbose
)
4264 (fun v -> conf.verbose
<- v);
4265 src#
bool "invert colors"
4266 (fun () -> conf.invert
)
4267 (fun v -> conf.invert
<- v);
4269 (fun () -> conf.maxhfit
)
4270 (fun v -> conf.maxhfit
<- v);
4271 src#
bool "redirect stderr"
4272 (fun () -> conf.redirectstderr)
4273 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4274 src#
string "uri launcher"
4275 (fun () -> conf.urilauncher
)
4276 (fun v -> conf.urilauncher
<- v);
4277 src#
string "path launcher"
4278 (fun () -> conf.pathlauncher
)
4279 (fun v -> conf.pathlauncher
<- v);
4280 src#
string "tile size"
4281 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4284 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4285 conf.tilew
<- max
64 w;
4286 conf.tileh
<- max
64 h;
4289 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4290 v (Printexc.to_string exn
));
4291 src#
int "texture count"
4292 (fun () -> conf.texcount
)
4295 then conf.texcount
<- v
4296 else showtext '
!'
" Failed to set texture count please retry later"
4298 src#
int "slice height"
4299 (fun () -> conf.sliceheight
)
4301 conf.sliceheight
<- v;
4302 wcmd "sliceh %d" conf.sliceheight
;
4304 src#
int "anti-aliasing level"
4305 (fun () -> conf.aalevel
)
4307 conf.aalevel
<- bound v 0 8;
4308 state.anchor <- getanchor ();
4309 opendoc state.path
state.password
;
4311 src#
string "page scroll scaling factor"
4312 (fun () -> string_of_float
conf.pgscale)
4315 let s = float_of_string
v in
4318 state.text <- Printf.sprintf
4319 "bad page scroll scaling factor `%s': %s"
4320 v (Printexc.to_string exn
)
4323 src#
int "ui font size"
4324 (fun () -> fstate.fontsize
)
4325 (fun v -> setfontsize (bound v 5 100));
4326 src#
int "hint font size"
4327 (fun () -> conf.hfsize
)
4328 (fun v -> conf.hfsize
<- bound v 5 100);
4329 colorp "background color"
4330 (fun () -> conf.bgcolor
)
4331 (fun v -> conf.bgcolor
<- v);
4332 src#
bool "crop hack"
4333 (fun () -> conf.crophack
)
4334 (fun v -> conf.crophack
<- v);
4335 src#
string "trim fuzz"
4336 (fun () -> irect_to_string conf.trimfuzz
)
4339 conf.trimfuzz
<- irect_of_string v;
4341 then settrim true conf.trimfuzz
;
4343 state.text <- Printf.sprintf
"bad irect `%s': %s"
4344 v (Printexc.to_string exn
)
4346 src#
string "throttle"
4348 match conf.maxwait
with
4349 | None
-> "show place holder if page is not ready"
4352 then "wait for page to fully render"
4354 "wait " ^ string_of_float
time
4355 ^
" seconds before showing placeholder"
4359 let f = float_of_string
v in
4361 then conf.maxwait
<- None
4362 else conf.maxwait
<- Some
f
4364 state.text <- Printf.sprintf
"bad time `%s': %s"
4365 v (Printexc.to_string exn
)
4367 src#
string "ghyll scroll"
4369 match conf.ghyllscroll
with
4371 | Some nab
-> ghyllscroll_to_string nab
4376 if String.length
v = 0
4378 else Some
(ghyllscroll_of_string v)
4380 conf.ghyllscroll
<- gs
4382 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4383 v (Printexc.to_string exn
)
4385 src#
string "selection command"
4386 (fun () -> conf.selcmd
)
4387 (fun v -> conf.selcmd
<- v);
4388 src#colorspace
"color space"
4389 (fun () -> colorspace_to_string conf.colorspace
)
4391 conf.colorspace
<- colorspace_of_int v;
4398 src#caption
"Document" 0;
4399 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4400 src#caption2
"Pages"
4401 (fun () -> string_of_int
state.pagecount
) 1;
4402 src#caption2
"Dimensions"
4403 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4407 src#caption
"Trimmed margins" 0;
4408 src#caption2
"Dimensions"
4409 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4413 src#caption
"OpenGL" 0;
4414 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4415 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4416 src#reset prevmode prevuioh
;
4420 let prevmode = state.mode
4421 and prevuioh
= state.uioh in
4422 fillsrc prevmode prevuioh
;
4423 let source = (src :> lvsource
) in
4424 let modehash = findkeyhash conf "info" in
4425 state.uioh <- coe (object (self)
4426 inherit listview ~
source ~trusted
:true ~
modehash as super
4427 val mutable m_prevmemused
= 0
4428 method infochanged
= function
4430 if m_prevmemused
!= state.memused
4432 m_prevmemused
<- state.memused
;
4433 G.postRedisplay "memusedchanged";
4435 | Pdim
-> G.postRedisplay "pdimchanged"
4436 | Docinfo
-> fillsrc prevmode prevuioh
4438 method key key mask
=
4439 if not
(Wsi.withctrl mask
)
4442 | 0xff51 -> coe (self#updownlevel ~
-1)
4443 | 0xff53 -> coe (self#updownlevel
1)
4444 | _ -> super#
key key mask
4445 else super#
key key mask
4447 G.postRedisplay "info";
4453 inherit lvsourcebase
4454 method getitemcount
= Array.length
state.help
4456 let s, n, _ = state.help
.(n) in
4459 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4463 m_qsearch
<- qsearch;
4464 match state.help
.(active) with
4465 | _, _, Action
f -> Some
(f uioh)
4475 method hasaction
n =
4476 match state.help
.(n) with
4477 | _, _, Action
_ -> true
4484 let modehash = findkeyhash conf "help" in
4485 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4486 G.postRedisplay "help";
4491 let re = Str.regexp
"[\r\n]" in
4493 inherit lvsourcebase
4494 val mutable m_items
= [||]
4496 method getitemcount
= 1 + Array.length m_items
4501 else m_items
.(n-1), 0
4503 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4508 then Buffer.clear
state.errmsgs
;
4509 m_qsearch
<- qsearch;
4516 method hasaction
n =
4520 state.newerrmsgs
<- false;
4521 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4522 m_items
<- Array.of_list
l
4530 let source = (msgsource :> lvsource
) in
4531 let modehash = findkeyhash conf "listview" in
4532 state.uioh <- coe (object
4533 inherit listview ~
source ~trusted
:false ~
modehash as super
4536 then msgsource#reset
;
4539 G.postRedisplay "msgs";
4542 let quickbookmark ?title
() =
4543 match state.layout with
4549 let sec = Unix.gettimeofday
() in
4550 let tm = Unix.localtime
sec in
4551 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4555 (tm.Unix.tm_year
+ 1900)
4558 | Some
title -> title
4561 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4566 state.fullscreen
<- None
;
4570 let setautoscrollspeed step goingdown
=
4571 let incr = max
1 ((abs step
) / 2) in
4572 let incr = if goingdown
then incr else -incr in
4573 let astep = step
+ incr in
4574 state.autoscroll
<- Some
astep;
4577 let gotounder = function
4578 | Ulinkgoto
(pageno, top) ->
4582 gotopage1 pageno top;
4588 | Uremote
(filename
, pageno) ->
4590 if Sys.file_exists filename
4593 let dir = Filename.dirname
state.path in
4594 let path = Filename.concat
dir filename
in
4595 if Sys.file_exists
path
4599 if String.length
path > 0
4601 let anchor = getanchor () in
4602 let ranchor = state.path, state.password
, anchor in
4603 state.anchor <- (pageno, 0.0);
4604 state.ranchors
<- ranchor :: state.ranchors
;
4607 else showtext '
!'
("Could not find " ^ filename
)
4609 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4613 match conf.columns
with
4615 | _ -> conf.zoom > 1.0
4618 let viewkeyboard key mask
=
4620 let mode = state.mode in
4621 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4624 G.postRedisplay "view:enttext"
4626 let ctrl = Wsi.withctrl mask
in
4631 | 0xff63 -> (* insert *)
4632 if conf.angle
mod 360 = 0
4634 state.mode <- LinkNav
(Ltgendir
0);
4637 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4639 | 0xff1b | 113 -> (* escape / q *)
4640 begin match state.mstate
with
4642 state.mstate
<- Mnone
;
4643 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4644 G.postRedisplay "kill zoom rect";
4646 match state.ranchors
with
4648 | (path, password
, anchor) :: rest
->
4649 state.ranchors
<- rest
;
4650 state.anchor <- anchor;
4651 opendoc path password
4654 | 0xff08 -> (* backspace *)
4655 let y = getnav ~
-1 in
4656 gotoy_and_clear_text y
4664 G.postRedisplay "dehighlight";
4666 | 47 | 63 -> (* / ? *)
4667 let ondone isforw
s =
4668 cbput state.hists
.pat
s;
4669 state.searchpattern
<- s;
4672 let s = String.create
1 in
4673 s.[0] <- Char.chr
key;
4674 enttext (s, "", Some
(onhist state.hists
.pat
),
4675 textentry, ondone (key = 47), true)
4677 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-=*)
4678 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4679 setzoom (conf.zoom +. incr)
4681 | 43 | 0xffab -> (* + *)
4684 try int_of_string
s with exc
->
4685 state.text <- Printf.sprintf
"bad integer `%s': %s"
4686 s (Printexc.to_string exc
);
4692 state.text <- "page bias is now " ^ string_of_int
n;
4695 enttext ("page bias: ", "", None
, intentry, ondone, true)
4697 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4698 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4699 setzoom (max
0.01 (conf.zoom -. decr))
4701 | 45 | 0xffad -> (* - *)
4702 let ondone msg
= state.text <- msg
in
4704 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4705 optentry state.mode, ondone, true
4708 | 48 when ctrl -> (* ctrl-0 *)
4711 | 49 when ctrl -> (* ctrl-1 *)
4713 match conf.columns
with
4714 | Csingle
_ | Cmulti
_ -> 1
4715 | Csplit
(n, _) -> n
4717 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4721 | 0xffc6 -> (* f9 *)
4724 | 57 when ctrl -> (* ctrl-9 *)
4727 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4728 when not
ctrl -> (* 0..9 *)
4731 try int_of_string
s with exc
->
4732 state.text <- Printf.sprintf
"bad integer `%s': %s"
4733 s (Printexc.to_string exc
);
4739 cbput state.hists
.pag
(string_of_int
n);
4740 gotopage1 (n + conf.pagebias
- 1) 0;
4743 let pageentry text key =
4744 match Char.unsafe_chr
key with
4745 | 'g'
-> TEdone
text
4746 | _ -> intentry text key
4748 let text = "x" in text.[0] <- Char.chr
key;
4749 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4752 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4753 reshape conf.winw
conf.winh
;
4756 conf.hlinks
<- not
conf.hlinks
;
4757 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4758 G.postRedisplay "toggle highlightlinks";
4761 state.glinks
<- true;
4762 let mode = state.mode in
4763 state.mode <- Textentry
(
4764 (":", "", None
, linknentry, linkndone (fun under ->
4769 state.glinks
<- false;
4773 G.postRedisplay "view:linkent(F)"
4776 state.glinks
<- true;
4777 let mode = state.mode in
4778 state.mode <- Textentry
(
4779 (":", "", None
, linknentry, linkndone (fun under ->
4780 match Ne.pipe () with
4782 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4783 (Printexc.to_string exn
));
4786 try popen conf.selcmd
[r, 0; w, -1]; true
4789 (Printf.sprintf
"failed to execute %s: %s"
4790 conf.selcmd
(Printexc.to_string exn
));
4794 Ne.clo fd
(fun msg
->
4795 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4798 let s = undertext under in
4802 let l = String.length
s in
4803 let n = Unix.write
w s 0 l in
4808 "failed to write %d characters to sel pipe, wrote %d"
4813 (Printf.sprintf
"failed to write to sel pipe: %s"
4814 (Printexc.to_string exn
)
4823 state.glinks
<- false;
4827 G.postRedisplay "view:linkent"
4830 begin match state.autoscroll
with
4832 conf.autoscrollstep
<- step
;
4833 state.autoscroll
<- None
4835 if conf.autoscrollstep
= 0
4836 then state.autoscroll
<- Some
1
4837 else state.autoscroll
<- Some
conf.autoscrollstep
4840 | 112 when ctrl -> (* ctrl-p *)
4844 conf.presentation <- not
conf.presentation;
4845 if conf.presentation
4847 if not
conf.scrollbarinpm
4848 then state.scrollw
<- 0;
4851 state.scrollw
<- conf.scrollbw
;
4853 showtext ' '
("presentation mode " ^
4854 if conf.presentation then "on" else "off");
4855 state.anchor <- getanchor ();
4859 begin match state.fullscreen
with
4861 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4864 state.fullscreen
<- None
;
4869 gotoy_and_clear_text 0
4872 gotopage1 (state.pagecount
- 1) 0
4874 | 112 | 78 -> (* p|N *)
4875 search state.searchpattern
false
4877 | 110 | 0xffc0 -> (* n|F3 *)
4878 search state.searchpattern
true
4881 begin match state.layout with
4884 gotoy_and_clear_text (getpagey l.pageno)
4888 begin match state.layout with
4891 match conf.columns
with
4892 | Csingle
_ | Cmulti
_ ->
4893 if conf.presentation && rest
== [] && l.pageh
> l.pagey + l.pagevh
4895 let y = clamp (pgscale conf.winh
) in
4896 gotoy_and_clear_text y
4898 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4899 gotoy_and_clear_text (getpagey pageno)
4901 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4903 let pagey, pageh
= getpageyh l.pageno in
4904 let pagey = pagey + pageh
* l.pagecol
in
4905 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace in
4906 gotoy_and_clear_text (pagey + pageh
+ ips)
4909 | 0xff9f | 0xffff -> (* delete *)
4910 begin match state.layout with
4913 match conf.columns
with
4914 | Csingle
_ | Cmulti
_ ->
4915 if conf.presentation && (l.pagey != 0 || l.pagedispy < 0)
4917 gotoy_and_clear_text (clamp (pgscale ~
-(conf.winh
)))
4919 let pageno = max
0 (l.pageno-1) in
4920 gotoy_and_clear_text (getpagey pageno)
4928 let pageno = max
0 (l.pageno-1) in
4929 let pagey, pageh
= getpageyh pageno in
4932 let pagey, pageh
= getpageyh l.pageno in
4933 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4935 gotoy_and_clear_text y
4939 showtext ' '
(describe_location ());
4942 begin match state.layout with
4945 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4950 enterbookmarkmode ()
4952 | 104 | 0xffbe -> (* h|F1 *)
4958 | 101 when conf.redirectstderr -> (* e *)
4963 match state.layout with
4966 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4970 enttext ("bookmark: ", "", None
, textentry, ondone, true)
4974 showtext ' '
"Quick bookmark added";
4977 begin match state.layout with
4979 let rect = getpdimrect
l.pagedimno
in
4983 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4984 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4986 (truncate
(rect.(1) -. rect.(0)),
4987 truncate
(rect.(3) -. rect.(0)))
4989 let w = truncate
((float w)*.conf.zoom)
4990 and h = truncate
((float h)*.conf.zoom) in
4993 state.anchor <- getanchor ();
4994 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4996 G.postRedisplay "z";
5001 | 50 when ctrl -> (* ctrl-2 *)
5002 let maxw = getmaxw
() in
5004 then setzoom (maxw /. float conf.winw
)
5006 | 60 | 62 -> (* < > *)
5007 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5009 | 91 | 93 -> (* [ ] *)
5011 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5013 G.postRedisplay "brightness";
5015 | 99 when state.mode = View
-> (* c *)
5017 match state.prevcolumns
with
5018 | None
-> (1, 0, 0), 1.0
5019 | Some
(columns
, z
) ->
5022 | Csplit
(c, _) -> -c, 0, 0
5023 | Cmulti
((c, a, b), _) -> c, a, b
5024 | Csingle
_ -> 1, 0, 0
5028 setcolumns View
c a b;
5031 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5032 setzoom state.prevzoom
5034 | 107 | 0xff52 -> (* k up *)
5035 begin match state.autoscroll
with
5037 begin match state.mode with
5038 | Birdseye beye
-> upbirdseye 1 beye
5041 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5042 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5045 setautoscrollspeed n false
5048 | 106 | 0xff54 -> (* j down *)
5049 begin match state.autoscroll
with
5051 begin match state.mode with
5052 | Birdseye beye
-> downbirdseye 1 beye
5055 then gotoy_and_clear_text (clamp (conf.winh
/2))
5056 else gotoy_and_clear_text (clamp conf.scrollstep
)
5059 setautoscrollspeed n true
5062 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5070 let dx = if key = 0xff51 then dx else -dx in
5071 state.x <- state.x + dx;
5072 gotoy_and_clear_text state.y
5075 G.postRedisplay "lef/right"
5078 | 0xff55 -> (* prior *)
5082 match state.layout with
5084 | l :: _ -> state.y - l.pagey
5086 clamp (pgscale (-conf.winh
))
5090 | 0xff56 -> (* next *)
5094 match List.rev
state.layout with
5096 | l :: _ -> getpagey l.pageno
5098 clamp (pgscale conf.winh
)
5102 | 0xff50 -> gotoghyll 0
5103 | 0xff57 -> gotoghyll (clamp state.maxy)
5104 | 0xff53 when Wsi.withalt mask
->
5105 gotoghyll (getnav ~
-1)
5106 | 0xff51 when Wsi.withalt mask
->
5107 gotoghyll (getnav 1)
5110 state.anchor <- getanchor ();
5111 opendoc state.path state.password
5113 | 118 when conf.debug
-> (* v *)
5116 match getopaque l.pageno with
5119 let x0, y0, x1, y1 = pagebbox opaque
in
5120 let a,b = float x0, float y0 in
5121 let c,d = float x1, float y0 in
5122 let e,f = float x1, float y1 in
5123 let h,j
= float x0, float y1 in
5124 let rect = (a,b,c,d,e,f,h,j
) in
5126 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5128 G.postRedisplay "v";
5131 vlog "huh? %s" (Wsi.keyname
key)
5134 let linknavkeyboard key mask
linknav =
5135 let getpage pageno =
5136 let rec loop = function
5138 | l :: _ when l.pageno = pageno -> Some
l
5139 | _ :: rest
-> loop rest
5140 in loop state.layout
5142 let doexact (pageno, n) =
5143 match getopaque pageno, getpage pageno with
5144 | Some opaque
, Some
l ->
5147 let under = getlink opaque
n in
5148 G.postRedisplay "link gotounder";
5154 | 0xff50 -> (* home *)
5155 Some
(findlink opaque LDfirst
), -1
5157 | 0xff57 -> (* end *)
5158 Some
(findlink opaque LDlast
), 1
5160 | 0xff51 -> (* left *)
5161 Some
(findlink opaque
(LDleft
n)), -1
5163 | 0xff53 -> (* right *)
5164 Some
(findlink opaque
(LDright
n)), 1
5166 | 0xff52 -> (* up *)
5167 Some
(findlink opaque
(LDup
n)), -1
5169 | 0xff54 -> (* down *)
5170 Some
(findlink opaque
(LDdown
n)), 1
5175 begin match findpwl
l.pageno dir with
5179 state.mode <- LinkNav
(Ltgendir
dir);
5180 let y, h = getpageyh pageno in
5183 then y + h - conf.winh
5188 begin match getopaque pageno, getpage pageno with
5189 | Some opaque
, Some
_ ->
5191 let ld = if dir > 0 then LDfirst
else LDlast
in
5194 begin match link with
5196 showlinktype (getlink opaque
m);
5197 state.mode <- LinkNav
(Ltexact
(pageno, m));
5198 G.postRedisplay "linknav jpage";
5205 begin match opt with
5206 | Some Lnotfound
-> pwl l dir;
5207 | Some
(Lfound
m) ->
5211 let _, y0, _, y1 = getlinkrect opaque
m in
5213 then gotopage1 l.pageno y0
5215 let d = fstate.fontsize
+ 1 in
5216 if y1 - l.pagey > l.pagevh - d
5217 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5218 else G.postRedisplay "linknav";
5220 showlinktype (getlink opaque
m);
5221 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5224 | None
-> viewkeyboard key mask
5226 | _ -> viewkeyboard key mask
5231 G.postRedisplay "leave linknav"
5235 | Ltgendir
_ -> viewkeyboard key mask
5236 | Ltexact exact
-> doexact exact
5239 let keyboard key mask
=
5240 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5241 then wcmd "interrupt"
5242 else state.uioh <- state.uioh#
key key mask
5245 let birdseyekeyboard key mask
5246 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5248 match conf.columns
with
5250 | Cmulti
((c, _, _), _) -> c
5251 | Csplit
_ -> failwith
"bird's eye split mode"
5253 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5255 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5256 let y, h = getpageyh pageno in
5257 let top = (conf.winh
- h) / 2 in
5258 gotoy (max
0 (y - top))
5259 | 0xff0d -> leavebirdseye beye
false
5260 | 0xff1b -> leavebirdseye beye
true (* escape *)
5261 | 0xff52 -> upbirdseye incr beye
(* up *)
5262 | 0xff54 -> downbirdseye incr beye
(* down *)
5263 | 0xff51 -> upbirdseye 1 beye
(* left *)
5264 | 0xff53 -> downbirdseye 1 beye
(* right *)
5266 | 0xff55 -> (* prior *)
5267 begin match state.layout with
5271 state.mode <- Birdseye
(
5272 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5274 gotopage1 l.pageno 0;
5277 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5279 | [] -> gotoy (clamp (-conf.winh
))
5281 state.mode <- Birdseye
(
5282 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5284 gotopage1 l.pageno 0
5287 | [] -> gotoy (clamp (-conf.winh
))
5290 | 0xff56 -> (* next *)
5291 begin match List.rev
state.layout with
5293 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5294 begin match layout with
5296 let incr = l.pageh
- l.pagevh in
5301 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5303 G.postRedisplay "birdseye pagedown";
5305 else gotoy (clamp (incr + conf.interpagespace*2));
5309 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5310 gotopage1 l.pageno 0;
5313 | [] -> gotoy (clamp conf.winh
)
5316 | 0xff50 -> (* home *)
5317 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5320 | 0xff57 -> (* end *)
5321 let pageno = state.pagecount
- 1 in
5322 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5323 if not
(pagevisible state.layout pageno)
5326 match List.rev
state.pdims
with
5328 | (_, _, h, _) :: _ -> h
5330 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5331 else G.postRedisplay "birdseye end";
5332 | _ -> viewkeyboard key mask
5335 let drawpage l linkindexbase
=
5337 match state.mode with
5338 | Textentry
_ -> scalecolor 0.4
5340 | View
-> scalecolor 1.0
5341 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5342 if l.pageno = hooverpageno
5345 if l.pageno = pageno
5351 begin match getopaque l.pageno with
5353 if tileready l l.pagex
l.pagey
5355 let x = l.pagedispx - l.pagex
5356 and y = l.pagedispy - l.pagey in
5358 match conf.columns
with
5359 | Csingle
_ | Cmulti
_ ->
5360 (if conf.hlinks
then 1 else 0)
5362 && not
(isbirdseye state.mode) then 2 else 0)
5366 match state.mode with
5367 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5370 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5377 let scrollindicator () =
5378 let sbw, ph
, sh = state.uioh#
scrollph in
5379 let sbh, pw, sw = state.uioh#scrollpw
in
5381 GlDraw.color (0.64, 0.64, 0.64);
5383 (float (conf.winw
- sbw), 0.)
5384 (float conf.winw
, float conf.winh
)
5387 (0., float (conf.winh
- sbh))
5388 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5390 GlDraw.color (0.0, 0.0, 0.0);
5393 (float (conf.winw
- sbw), ph
)
5394 (float conf.winw
, ph
+. sh)
5397 (pw, float (conf.winh
- sbh))
5398 (pw +. sw, float conf.winh
)
5403 match state.mstate
with
5404 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5407 | Msel
((x0, y0), (x1, y1)) ->
5408 let rec loop = function
5410 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5411 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5412 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5413 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5415 match getopaque l.pageno with
5417 let x0, y0 = pagetranslatepoint l x0 y0 in
5418 let x1, y1 = pagetranslatepoint l x1 y1 in
5419 seltext opaque
(x0, y0, x1, y1);
5427 let showrects rects
=
5429 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5430 GlDraw.polygon_mode `both `fill
;
5431 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5433 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5435 if l.pageno = pageno
5437 let dx = float (l.pagedispx - l.pagex
) in
5438 let dy = float (l.pagedispy - l.pagey) in
5439 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5440 GlDraw.begins `quads
;
5442 GlDraw.vertex2
(x0+.dx, y0+.dy);
5443 GlDraw.vertex2
(x1+.dx, y1+.dy);
5444 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5445 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5456 GlClear.color (scalecolor2 conf.bgcolor
);
5457 GlClear.clear
[`
color];
5458 let rec loop linkindexbase
= function
5460 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5461 loop linkindexbase rest
5464 loop 0 state.layout;
5466 match state.mode with
5467 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5468 begin match getopaque pageno with
5470 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5477 | None
-> state.rects
5484 begin match state.mstate
with
5485 | Mzoomrect
((x0, y0), (x1, y1)) ->
5487 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5488 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5489 GlDraw.rect (float x0, float y0)
5490 (float x1, float y1);
5499 let zoomrect x y x1 y1 =
5502 and y0 = min
y y1 in
5503 gotoy (state.y + y0);
5504 state.anchor <- getanchor ();
5505 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5507 if state.w < conf.winw
- state.scrollw
5508 then (conf.winw
- state.scrollw
- state.w) / 2
5511 state.x <- (state.x + margin) - x0;
5513 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5514 state.mstate
<- Mnone
;
5518 let winw = conf.winw - state.scrollw
- 1 in
5519 let s = float x /. float winw in
5520 let destx = truncate
(float (state.w + winw) *. s) in
5521 state.x <- winw - destx;
5522 gotoy_and_clear_text state.y;
5523 state.mstate
<- Mscrollx
;
5527 let s = float y /. float conf.winh
in
5528 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5529 gotoy_and_clear_text desty;
5530 state.mstate
<- Mscrolly
;
5533 let viewmouse button down
x y mask
=
5535 | n when (n == 4 || n == 5) && not down
->
5536 if Wsi.withctrl mask
5538 match state.mstate
with
5539 | Mzoom
(oldn
, i
) ->
5547 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5549 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5551 let zoom = conf.zoom -. incr in
5553 state.mstate
<- Mzoom
(n, 0);
5555 state.mstate
<- Mzoom
(n, i
+1);
5557 else state.mstate
<- Mzoom
(n, 0)
5559 | _ -> state.mstate
<- Mzoom
(n, 0)
5562 match state.autoscroll
with
5563 | Some step
-> setautoscrollspeed step
(n=4)
5567 then -conf.scrollstep
5568 else conf.scrollstep
5570 let incr = incr * 2 in
5571 let y = clamp incr in
5572 gotoy_and_clear_text y
5575 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5576 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5577 gotoy_and_clear_text state.y
5579 | 1 when Wsi.withctrl mask
->
5582 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5583 state.mstate
<- Mpan
(x, y)
5586 state.mstate
<- Mnone
5591 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5593 state.mstate
<- Mzoomrect
(p, p)
5596 match state.mstate
with
5597 | Mzoomrect
((x0, y0), _) ->
5598 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5599 then zoomrect x0 y0 x y
5601 state.mstate
<- Mnone
;
5602 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5603 G.postRedisplay "kill accidental zoom rect";
5606 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5607 state.mstate
<- Mnone
5610 | 1 when x > conf.winw - state.scrollw
->
5613 let _, position, sh = state.uioh#
scrollph in
5614 if y > truncate
position && y < truncate
(position +. sh)
5615 then state.mstate
<- Mscrolly
5618 state.mstate
<- Mnone
5620 | 1 when y > conf.winh
- state.hscrollh ->
5623 let _, position, sw = state.uioh#scrollpw
in
5624 if x > truncate
position && x < truncate
(position +. sw)
5625 then state.mstate
<- Mscrollx
5628 state.mstate
<- Mnone
5631 let dest = if down
then getunder x y else Unone
in
5632 begin match dest with
5636 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5639 | Unone
when down
->
5640 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5641 state.mstate
<- Mpan
(x, y);
5643 | Unone
| Utext
_ ->
5646 if conf.angle
mod 360 = 0
5648 state.mstate
<- Msel
((x, y), (x, y));
5649 G.postRedisplay "mouse select";
5653 match state.mstate
with
5656 | Mzoom
_ | Mscrollx
| Mscrolly
->
5657 state.mstate
<- Mnone
5659 | Mzoomrect
((x0, y0), _) ->
5663 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5664 state.mstate
<- Mnone
5666 | Msel
((_, y0), (_, y1)) ->
5667 let rec loop = function
5670 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5671 || ((y1 >= l.pagedispy
5672 && y1 <= (l.pagedispy + l.pagevh)))
5674 match getopaque l.pageno with
5677 match Ne.pipe () with
5681 "can not create sel pipe: %s"
5682 (Printexc.to_string exn
));
5684 let doclose what fd
=
5685 Ne.clo fd
(fun msg
->
5686 dolog "%s close failed: %s" what msg
)
5689 popen conf.selcmd
[r, 0; w, -1];
5692 G.postRedisplay "copysel";
5694 dolog "can not execute %S: %s"
5695 conf.selcmd
(Printexc.to_string exn
);
5703 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5704 state.mstate
<- Mnone
;
5711 let birdseyemouse button down
x y mask
5712 (conf, leftx
, _, hooverpageno
, anchor) =
5715 let rec loop = function
5718 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5719 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5721 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5727 | _ -> viewmouse button down
x y mask
5730 let mouse button down
x y mask
=
5731 state.uioh <- state.uioh#button button down
x y mask
;
5735 state.uioh <- state.uioh#
motion x y
5739 state.uioh <- state.uioh#
pmotion x y;
5745 method key key mask
=
5746 begin match state.mode with
5747 | Textentry
textentry -> textentrykeyboard key mask
textentry
5748 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5749 | View
-> viewkeyboard key mask
5750 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5754 method button button bstate
x y mask
=
5755 begin match state.mode with
5757 | View
-> viewmouse button bstate
x y mask
5758 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5764 begin match state.mode with
5766 | View
| Birdseye
_ | LinkNav
_ ->
5767 match state.mstate
with
5768 | Mzoom
_ | Mnone
-> ()
5773 state.mstate
<- Mpan
(x, y);
5775 then state.x <- state.x + dx;
5777 gotoy_and_clear_text y
5780 state.mstate
<- Msel
(a, (x, y));
5781 G.postRedisplay "motion select";
5784 let y = min
conf.winh
(max
0 y) in
5788 let x = min
conf.winw (max
0 x) in
5791 | Mzoomrect
(p0
, _) ->
5792 state.mstate
<- Mzoomrect
(p0
, (x, y));
5793 G.postRedisplay "motion zoomrect";
5797 method pmotion x y =
5798 begin match state.mode with
5799 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5800 let rec loop = function
5802 if hooverpageno
!= -1
5804 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5805 G.postRedisplay "pmotion birdseye no hoover";
5808 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5809 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5811 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5812 G.postRedisplay "pmotion birdseye hoover";
5822 match state.mstate
with
5823 | Mnone
-> updateunder x y
5824 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5829 method infochanged
_ = ()
5832 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5833 let p, h = scrollph state.y maxy in
5837 let winw = conf.winw - state.scrollw
- 1 in
5838 let fwinw = float winw in
5840 let sw = fwinw /. float state.w in
5841 let sw = fwinw *. sw in
5842 max
sw (float conf.scrollh
)
5845 let f = state.w+winw in
5846 let r = float (winw-state.x) /. float f in
5847 let p = fwinw *. r in
5851 if position +. sw > fwinw
5852 then fwinw -. position
5855 state.hscrollh, position, sw
5859 match state.mode with
5860 | LinkNav
_ -> "links"
5861 | Textentry
_ -> "textentry"
5862 | Birdseye
_ -> "birdseye"
5865 findkeyhash conf modename
5872 let fontpath = ref "";;
5875 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5878 let l = String.length
s in
5879 let b = Buffer.create
l in
5885 try Sys.getenv
"HOME"
5888 ("Can not determine home directory location: " ^
5889 Printexc.to_string exn
);
5893 let modifier_of_string = function
5894 | "alt" -> Wsi.altmask
5895 | "shift" -> Wsi.shiftmask
5896 | "ctrl" | "control" -> Wsi.ctrlmask
5897 | "meta" -> Wsi.metamask
5902 let r = Str.regexp
"-" in
5904 let elems = Str.full_split
r s in
5907 let m1 = modifier_of_string s in
5909 then (Wsi.namekey
s, m)
5912 | Str.Delim
s when n land 1 = 0 -> g s
5914 | Str.Delim
_ -> (k
, m)
5916 let rec loop n k
m = function
5919 let k, m = f n k m x in
5925 let keys_of_string =
5926 let r = Str.regexp
"[ \t]" in
5928 let elems = Str.split
r s in
5929 List.map
key_of_string elems
5932 let copykeyhashes c =
5933 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5936 let config_of c attrs
=
5940 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5941 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5942 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5943 | "preload" -> { c with preload = bool_of_string
v }
5944 | "page-bias" -> { c with pagebias
= int_of_string
v }
5945 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5946 | "horizontal-scroll-step" ->
5947 { c with hscrollstep
= max
(int_of_string
v) 1 }
5948 | "auto-scroll-step" ->
5949 { c with autoscrollstep
= max
0 (int_of_string
v) }
5950 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5951 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5954 match String.lowercase
v with
5955 | "true" -> Some infinity
5957 | f -> Some
(float_of_string
f)
5959 { c with maxwait
= mw}
5960 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5961 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5962 | "vertical-margin" ->
5963 { c with interpagespace = max
0 (int_of_string
v) }
5965 let zoom = float_of_string
v /. 100. in
5966 let zoom = max
zoom 0.0 in
5967 { c with zoom = zoom }
5968 | "presentation" -> { c with presentation = bool_of_string
v }
5969 | "rotation-angle" -> { c with angle
= int_of_string
v }
5970 | "width" -> { c with winw = max
20 (int_of_string
v) }
5971 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5972 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5973 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5974 | "pixmap-cache-size" ->
5975 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5976 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5977 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5978 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5979 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5980 | "background-color" -> { c with bgcolor
= color_of_string v }
5981 | "scrollbar-in-presentation" ->
5982 { c with scrollbarinpm
= bool_of_string
v }
5983 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5984 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5985 | "mupdf-store-size" ->
5986 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5987 | "checkers" -> { c with checkers
= bool_of_string
v }
5988 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5989 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5990 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5991 | "uri-launcher" -> { c with urilauncher
= unent v }
5992 | "path-launcher" -> { c with pathlauncher
= unent v }
5993 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5994 | "invert-colors" -> { c with invert
= bool_of_string
v }
5995 | "brightness" -> { c with colorscale
= float_of_string
v }
5996 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5998 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6000 let (n, _, _) as nab
= multicolumns_of_string v in
6002 then { c with columns
= Csplit
(-n, [||]) }
6003 else { c with columns
= Cmulti
(nab
, [||]) }
6004 | "birds-eye-columns" ->
6005 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6006 | "selection-command" -> { c with selcmd
= unent v }
6007 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6008 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6009 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6012 prerr_endline
("Error processing attribute (`" ^
6013 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6016 let rec fold c = function
6019 let c = apply c k v in
6022 fold { c with keyhashes
= copykeyhashes c } attrs
;
6025 let fromstring f pos
n v d =
6028 dolog "Error processing attribute (%S=%S) at %d\n%s"
6029 n v pos
(Printexc.to_string exn
)
6034 let bookmark_of attrs
=
6035 let rec fold title page
rely = function
6036 | ("title", v) :: rest
-> fold v page
rely rest
6037 | ("page", v) :: rest
-> fold title v rely rest
6038 | ("rely", v) :: rest
-> fold title page
v rest
6039 | _ :: rest
-> fold title page
rely rest
6040 | [] -> title, page
, rely
6042 fold "invalid" "0" "0" attrs
6046 let rec fold path page
rely pan
= function
6047 | ("path", v) :: rest
-> fold v page
rely pan rest
6048 | ("page", v) :: rest
-> fold path v rely pan rest
6049 | ("rely", v) :: rest
-> fold path page
v pan rest
6050 | ("pan", v) :: rest
-> fold path page
rely v rest
6051 | _ :: rest
-> fold path page
rely pan rest
6052 | [] -> path, page
, rely, pan
6054 fold "" "0" "0" "0" attrs
6058 let rec fold rs ls
= function
6059 | ("out", v) :: rest
-> fold v ls rest
6060 | ("in", v) :: rest
-> fold rs
v rest
6061 | _ :: rest
-> fold ls rs rest
6067 let setconf dst
src =
6068 dst
.scrollbw
<- src.scrollbw
;
6069 dst
.scrollh
<- src.scrollh
;
6070 dst
.icase
<- src.icase
;
6071 dst
.preload <- src.preload;
6072 dst
.pagebias
<- src.pagebias
;
6073 dst
.verbose
<- src.verbose
;
6074 dst
.scrollstep
<- src.scrollstep
;
6075 dst
.maxhfit
<- src.maxhfit
;
6076 dst
.crophack
<- src.crophack
;
6077 dst
.autoscrollstep
<- src.autoscrollstep
;
6078 dst
.maxwait
<- src.maxwait
;
6079 dst
.hlinks
<- src.hlinks
;
6080 dst
.underinfo
<- src.underinfo
;
6081 dst
.interpagespace <- src.interpagespace;
6082 dst
.zoom <- src.zoom;
6083 dst
.presentation <- src.presentation;
6084 dst
.angle
<- src.angle
;
6085 dst
.winw <- src.winw;
6086 dst
.winh
<- src.winh
;
6087 dst
.savebmarks
<- src.savebmarks
;
6088 dst
.memlimit
<- src.memlimit
;
6089 dst
.proportional
<- src.proportional
;
6090 dst
.texcount
<- src.texcount
;
6091 dst
.sliceheight
<- src.sliceheight
;
6092 dst
.thumbw
<- src.thumbw
;
6093 dst
.jumpback
<- src.jumpback
;
6094 dst
.bgcolor
<- src.bgcolor
;
6095 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6096 dst
.tilew
<- src.tilew
;
6097 dst
.tileh
<- src.tileh
;
6098 dst
.mustoresize
<- src.mustoresize
;
6099 dst
.checkers
<- src.checkers
;
6100 dst
.aalevel
<- src.aalevel
;
6101 dst
.trimmargins
<- src.trimmargins
;
6102 dst
.trimfuzz
<- src.trimfuzz
;
6103 dst
.urilauncher
<- src.urilauncher
;
6104 dst
.colorspace
<- src.colorspace
;
6105 dst
.invert
<- src.invert
;
6106 dst
.colorscale
<- src.colorscale
;
6107 dst
.redirectstderr <- src.redirectstderr;
6108 dst
.ghyllscroll
<- src.ghyllscroll
;
6109 dst
.columns
<- src.columns
;
6110 dst
.beyecolumns
<- src.beyecolumns
;
6111 dst
.selcmd
<- src.selcmd
;
6112 dst
.updatecurs
<- src.updatecurs
;
6113 dst
.pathlauncher
<- src.pathlauncher
;
6114 dst
.keyhashes
<- copykeyhashes src;
6115 dst
.hfsize
<- src.hfsize
;
6116 dst
.hscrollstep
<- src.hscrollstep
;
6117 dst
.pgscale <- src.pgscale;
6121 let h = Hashtbl.create
10 in
6122 let dc = { defconf with angle
= defconf.angle
} in
6123 let rec toplevel v t spos
_ =
6125 | Vdata
| Vcdata
| Vend
-> v
6126 | Vopen
("llppconfig", _, closed
) ->
6129 else { v with f = llppconfig
}
6131 error
"unexpected subelement at top level" s spos
6132 | Vclose
_ -> error
"unexpected close at top level" s spos
6134 and llppconfig
v t spos
_ =
6136 | Vdata
| Vcdata
-> v
6137 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6138 | Vopen
("defaults", attrs
, closed
) ->
6139 let c = config_of dc attrs
in
6143 else { v with f = defaults
}
6145 | Vopen
("ui-font", attrs
, closed
) ->
6146 let rec getsize size
= function
6148 | ("size", v) :: rest
->
6150 fromstring int_of_string spos
"size" v fstate.fontsize
in
6152 | l -> getsize size l
6154 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6157 else { v with f = uifont
(Buffer.create
10) }
6159 | Vopen
("doc", attrs
, closed
) ->
6160 let pathent, spage
, srely
, span
= doc_of attrs
in
6161 let path = unent pathent
6162 and pageno = fromstring int_of_string spos
"page" spage
0
6163 and rely = fromstring float_of_string spos
"rely" srely
0.0
6164 and pan
= fromstring int_of_string spos
"pan" span
0 in
6165 let c = config_of dc attrs
in
6166 let anchor = (pageno, rely) in
6168 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6169 else { v with f = doc
path pan
anchor c [] }
6172 error
"unexpected subelement in llppconfig" s spos
6174 | Vclose
"llppconfig" -> { v with f = toplevel }
6175 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6177 and defaults
v t spos
_ =
6179 | Vdata
| Vcdata
-> v
6180 | Vend
-> error
"unexpected end of input in defaults" s spos
6181 | Vopen
("keymap", attrs
, closed
) ->
6183 try List.assoc
"mode" attrs
6184 with Not_found
-> "global" in
6189 let h = findkeyhash dc modename in
6190 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6193 { v with f = pkeymap
ret KeyMap.empty }
6195 | Vopen
(_, _, _) ->
6196 error
"unexpected subelement in defaults" s spos
6198 | Vclose
"defaults" ->
6199 { v with f = llppconfig
}
6201 | Vclose
_ -> error
"unexpected close in defaults" s spos
6203 and uifont
b v t spos
epos =
6206 Buffer.add_substring
b s spos
(epos - spos
);
6208 | Vopen
(_, _, _) ->
6209 error
"unexpected subelement in ui-font" s spos
6210 | Vclose
"ui-font" ->
6211 if String.length
!fontpath = 0
6212 then fontpath := Buffer.contents
b;
6213 { v with f = llppconfig
}
6214 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6215 | Vend
-> error
"unexpected end of input in ui-font" s spos
6217 and doc
path pan
anchor c bookmarks
v t spos
_ =
6219 | Vdata
| Vcdata
-> v
6220 | Vend
-> error
"unexpected end of input in doc" s spos
6221 | Vopen
("bookmarks", _, closed
) ->
6224 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6226 | Vopen
("keymap", attrs
, closed
) ->
6228 try List.assoc
"mode" attrs
6229 with Not_found
-> "global"
6235 let h = findkeyhash c modename in
6236 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6237 doc
path pan
anchor c bookmarks
6239 { v with f = pkeymap
ret KeyMap.empty }
6241 | Vopen
(_, _, _) ->
6242 error
"unexpected subelement in doc" s spos
6245 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6246 { v with f = llppconfig
}
6248 | Vclose
_ -> error
"unexpected close in doc" s spos
6250 and pkeymap
ret keymap
v t spos
_ =
6252 | Vdata
| Vcdata
-> v
6253 | Vend
-> error
"unexpected end of input in keymap" s spos
6254 | Vopen
("map", attrs
, closed
) ->
6255 let r, l = map_of attrs
in
6256 let kss = fromstring keys_of_string spos
"in" r [] in
6257 let lss = fromstring keys_of_string spos
"out" l [] in
6261 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6262 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6265 then { v with f = pkeymap
ret keymap }
6268 { v with f = skip
"map" f }
6271 error
"unexpected subelement in keymap" s spos
6273 | Vclose
"keymap" ->
6274 { v with f = ret keymap }
6276 | Vclose
_ -> error
"unexpected close in keymap" s spos
6278 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6280 | Vdata
| Vcdata
-> v
6281 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6282 | Vopen
("item", attrs
, closed
) ->
6283 let titleent, spage
, srely
= bookmark_of attrs
in
6284 let page = fromstring int_of_string spos
"page" spage
0
6285 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6286 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6288 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6291 { v with f = skip
"item" f }
6294 error
"unexpected subelement in bookmarks" s spos
6296 | Vclose
"bookmarks" ->
6297 { v with f = doc
path pan
anchor c bookmarks }
6299 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6301 and skip tag
f v t spos
_ =
6303 | Vdata
| Vcdata
-> v
6305 error
("unexpected end of input in skipped " ^ tag
) s spos
6306 | Vopen
(tag'
, _, closed
) ->
6310 let f'
() = { v with f = skip tag
f } in
6311 { v with f = skip tag'
f'
}
6315 else error
("unexpected close in skipped " ^ tag
) s spos
6318 parse
{ f = toplevel; accu = () } s;
6324 let len = in_channel_length ic
in
6325 let s = String.create
len in
6326 really_input ic
s 0 len;
6329 | Parse_error
(msg
, s, pos
) ->
6330 let subs = subs s pos
in
6331 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6332 failwith
("parse error: " ^
s)
6335 failwith
("config load error: " ^
Printexc.to_string exn
)
6341 let dir = Filename.concat
home ".config" in
6342 if Sys.is_directory
dir then dir else home
6345 Filename.concat
dir "llpp.conf"
6348 let confpath = ref defconfpath;;
6351 if Sys.file_exists
!confpath
6354 (try Some
(open_in_bin
!confpath)
6357 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6358 Printexc.to_string exn
);
6367 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6368 Printexc.to_string exn
);
6374 f (Hashtbl.create
0, defconf)
6379 let pc, pb
, px, pa
=
6381 Hashtbl.find h (Filename.basename
state.path)
6382 with Not_found
-> dc, [], 0, (0, 0.0)
6386 state.bookmarks <- pb
;
6388 state.scrollw
<- conf.scrollbw
;
6390 then state.anchor <- pa
;
6391 cbput state.hists
.nav pa
;
6396 let add_attrs bb always
dc c =
6399 then Printf.bprintf bb
"\n %s='%b'" s a
6402 then Printf.bprintf bb
"\n %s='%d'" s a
6405 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6408 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6411 then Printf.bprintf bb
"\n %s='%f'" s a
6415 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6419 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6423 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6427 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6433 | Some
(_N
, _A
, _B
) ->
6434 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6444 else string_of_float
f
6446 Printf.bprintf bb
"\n %s='%s'" s v
6451 | Cmulti
((n, a, b), _) when n > 1 ->
6452 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6453 | Csplit
(n, _) when n > 1 ->
6454 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6460 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6465 then dc.winw, dc.winh
6467 match state.fullscreen
with
6469 | None
-> c.winw, c.winh
6471 let zoom, presentation, interpagespace, maxwait
=
6473 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6475 match state.mode with
6476 | Birdseye
(bc
, _, _, _, _) ->
6477 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6478 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6480 oi
"width" w dc.winw;
6481 oi
"height" h dc.winh
;
6482 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6483 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6484 ob "case-insensitive-search" c.icase
dc.icase
;
6485 ob "preload" c.preload dc.preload;
6486 oi
"page-bias" c.pagebias
dc.pagebias
;
6487 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6488 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6489 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6490 ob "crop-hack" c.crophack
dc.crophack
;
6491 oW
"throttle" maxwait
dc.maxwait
;
6492 ob "highlight-links" c.hlinks
dc.hlinks
;
6493 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6494 oi
"vertical-margin" interpagespace dc.interpagespace;
6495 oz
"zoom" zoom dc.zoom;
6496 ob "presentation" presentation dc.presentation;
6497 oi
"rotation-angle" c.angle
dc.angle
;
6498 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6499 ob "proportional-display" c.proportional
dc.proportional
;
6500 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6501 oi
"tex-count" c.texcount
dc.texcount
;
6502 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6503 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6504 ob "persistent-location" c.jumpback
dc.jumpback
;
6505 oc
"background-color" c.bgcolor
dc.bgcolor
;
6506 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6507 oi
"tile-width" c.tilew
dc.tilew
;
6508 oi
"tile-height" c.tileh
dc.tileh
;
6509 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6510 ob "checkers" c.checkers
dc.checkers
;
6511 oi
"aalevel" c.aalevel
dc.aalevel
;
6512 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6513 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6514 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6515 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6516 oC
"color-space" c.colorspace
dc.colorspace
;
6517 ob "invert-colors" c.invert
dc.invert
;
6518 oF
"brightness" c.colorscale
dc.colorscale
;
6519 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6520 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6521 oco
"columns" c.columns
dc.columns
;
6522 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6523 os
"selection-command" c.selcmd
dc.selcmd
;
6524 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6525 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6526 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6527 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6530 let keymapsbuf always
dc c =
6531 let bb = Buffer.create
16 in
6532 let rec loop = function
6534 | (modename, h) :: rest
->
6535 let dh = findkeyhash dc modename in
6536 if always
|| h <> dh
6538 if Hashtbl.length
h > 0
6540 if Buffer.length
bb > 0
6541 then Buffer.add_char
bb '
\n'
;
6542 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6543 Hashtbl.iter
(fun i
o ->
6544 let isdifferent = always
||
6546 let dO = Hashtbl.find dh i
in
6548 with Not_found
-> true
6553 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6554 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6555 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6556 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6557 Buffer.add_string
bb (Wsi.keyname
k);
6560 let rec loop = function
6562 | km
:: [] -> addkm km
6563 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6567 Buffer.add_string
bb "<map in='";
6571 Buffer.add_string
bb "' out='";
6573 Buffer.add_string
bb "'/>\n"
6576 Buffer.add_string
bb "' out='";
6578 Buffer.add_string
bb "'/>\n"
6580 | KMmulti
(ins, kms
) ->
6581 Buffer.add_char
bb ' '
;
6583 Buffer.add_string
bb "' out='";
6585 Buffer.add_string
bb "'/>\n"
6587 Buffer.add_string
bb "</keymap>";
6597 let uifontsize = fstate.fontsize
in
6598 let bb = Buffer.create
32768 in
6600 let dc = if conf.bedefault
then conf else dc in
6601 Buffer.add_string
bb "<llppconfig>\n";
6603 if String.length
!fontpath > 0
6605 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6611 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6614 Buffer.add_string
bb "<defaults ";
6615 add_attrs bb true dc dc;
6616 let kb = keymapsbuf true dc dc in
6617 if Buffer.length
kb > 0
6619 Buffer.add_string
bb ">\n";
6620 Buffer.add_buffer
bb kb;
6621 Buffer.add_string
bb "\n</defaults>\n";
6623 else Buffer.add_string
bb "/>\n";
6625 let adddoc path pan
anchor c bookmarks =
6626 if bookmarks == [] && c = dc && anchor = emptyanchor
6629 Printf.bprintf
bb "<doc path='%s'"
6630 (enent
path 0 (String.length
path));
6632 if anchor <> emptyanchor
6634 let n, y = anchor in
6635 Printf.bprintf
bb " page='%d'" n;
6638 Printf.bprintf
bb " rely='%f'" y
6643 then Printf.bprintf
bb " pan='%d'" pan
;
6645 add_attrs bb false dc c;
6646 let kb = keymapsbuf false dc c in
6648 begin match bookmarks with
6650 if Buffer.length
kb > 0
6652 Buffer.add_string
bb ">\n";
6653 Buffer.add_buffer
bb kb;
6654 Buffer.add_string
bb "\n</doc>\n";
6656 else Buffer.add_string
bb "/>\n"
6658 Buffer.add_string
bb ">\n<bookmarks>\n";
6659 List.iter
(fun (title, _level
, (page, rely)) ->
6661 "<item title='%s' page='%d'"
6662 (enent
title 0 (String.length
title))
6667 Printf.bprintf
bb " rely='%f'" rely
6669 Buffer.add_string
bb "/>\n";
6671 Buffer.add_string
bb "</bookmarks>";
6672 if Buffer.length
kb > 0
6674 Buffer.add_string
bb "\n";
6675 Buffer.add_buffer
bb kb;
6677 Buffer.add_string
bb "\n</doc>\n";
6683 match state.mode with
6684 | Birdseye
(c, pan, _, _, _) ->
6686 match conf.columns
with
6687 | Cmulti
((c, _, _), _) -> Some
c
6691 match c.columns
with
6692 | Cmulti
(c, _) -> Cmulti
(c, [||])
6693 | Csingle
_ -> Csingle
[||]
6694 | Csplit
_ -> failwith
"quit from bird's eye while split"
6696 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6697 | _ -> state.x, conf
6699 let basename = Filename.basename state.path in
6700 adddoc basename pan (getanchor ())
6703 match state.autoscroll
with
6705 | None
-> conf.autoscrollstep
}
6706 (if conf.savebmarks
then state.bookmarks else []);
6708 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6710 then adddoc path x y c bookmarks
6712 Buffer.add_string
bb "</llppconfig>";
6715 if Buffer.length
bb > 0
6718 let tmp = !confpath ^
".tmp" in
6719 let oc = open_out_bin
tmp in
6720 Buffer.output_buffer
oc bb;
6722 Unix.rename
tmp !confpath;
6725 ("error while saving configuration: " ^
Printexc.to_string exn
)
6730 let trimcachepath = ref "" in
6733 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6734 "<password> Set password");
6736 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6737 "<path> Set path to the user interface font");
6739 ("-c", Arg.String
(fun s -> Config.confpath := s),
6740 "<path> Set path to the configuration file");
6742 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6743 "<path> Set path to the trim cache file");
6745 ("-v", Arg.Unit
(fun () ->
6747 "%s\nconfiguration path: %s\n"
6751 exit
0), " Print version and exit");
6754 (fun s -> state.path <- s)
6755 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6757 if String.length
state.path = 0
6758 then (prerr_endline
"file name missing"; exit
1);
6762 let globalkeyhash = findkeyhash conf "global" in
6763 let wsfd, winw, winh
= Wsi.init
(object
6765 if nogeomcmds state.geomcmds
|| platform == Posx
6768 GlClear.color (scalecolor2 conf.bgcolor
);
6769 GlClear.clear
[`
color];
6771 method display = display ()
6772 method reshape w h = reshape w h
6773 method mouse b d x y m = mouse b d x y m
6774 method motion x y = state.mpos
<- (x, y); motion x y
6775 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6777 let mascm = m land (
6778 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6780 match state.keystate
with
6782 let km = k, mascm in
6785 let modehash = state.uioh#
modehash in
6786 try Hashtbl.find modehash km
6788 try Hashtbl.find globalkeyhash km
6789 with Not_found
-> KMinsrt
(k, m)
6791 | KMinsrt
(k, m) -> keyboard k m
6792 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6793 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6795 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6796 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6797 state.keystate
<- KSnone
6798 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6799 state.keystate
<- KSinto
(keys
, insrt
)
6801 state.keystate
<- KSnone
6803 method enter
x y = state.mpos
<- (x, y); pmotion x y
6804 method leave = state.mpos
<- (-1, -1)
6805 method quit
= raise Quit
6806 end) conf.winw conf.winh
(platform = Posx
) in
6811 List.exists
GlMisc.check_extension
6812 [ "GL_ARB_texture_rectangle"
6813 ; "GL_EXT_texture_recangle"
6814 ; "GL_NV_texture_rectangle" ]
6816 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6819 match Ne.pipe () with
6821 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6825 match Ne.pipe () with
6827 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6837 setcheckers conf.checkers
;
6841 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6842 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6843 !Config.fontpath, !trimcachepath
6847 state.text <- "Opening " ^
state.path;
6849 opendoc state.path state.password
;
6852 let rec loop deadline
=
6854 match state.errfd
with
6855 | None
-> [state.sr
; state.wsfd]
6856 | Some fd
-> [state.sr
; state.wsfd; fd
]
6860 state.redisplay
<- false;
6867 if deadline
= infinity
6869 else max
0.0 (deadline
-. now)
6874 try Unix.select
r [] [] timeout
6875 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6881 if state.ghyll
== noghyll
6883 match state.autoscroll
with
6884 | Some step
when step
!= 0 ->
6885 let y = state.y + step
in
6889 else if y >= state.maxy then 0 else y
6892 if state.mode = View
6893 then state.text <- "";
6896 else deadline
+. 0.01
6901 let rec checkfds = function
6903 | fd
:: rest
when fd
= state.sr
->
6904 let cmd = readcmd state.sr
in
6908 | fd
:: rest
when fd
= state.wsfd ->
6913 let s = String.create
80 in
6914 let n = Unix.read fd
s 0 80 in
6915 if conf.redirectstderr
6917 Buffer.add_substring
state.errmsgs
s 0 n;
6918 state.newerrmsgs
<- true;
6919 state.redisplay
<- true;
6922 prerr_string
(String.sub
s 0 n);
6930 if deadline
= infinity
6934 match state.autoscroll
with
6935 | Some step
when step
!= 0 -> deadline1
6936 | _ -> if state.ghyll
== noghyll then infinity
else deadline1